lpfc_sli.c 399 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include <scsi/fc/fc_fs.h>
  32. #include <linux/aer.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_crtn.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_compat.h"
  44. #include "lpfc_debugfs.h"
  45. #include "lpfc_vport.h"
  46. /* There are only four IOCB completion types. */
  47. typedef enum _lpfc_iocb_type {
  48. LPFC_UNKNOWN_IOCB,
  49. LPFC_UNSOL_IOCB,
  50. LPFC_SOL_IOCB,
  51. LPFC_ABORT_IOCB
  52. } lpfc_iocb_type;
  53. /* Provide function prototypes local to this module. */
  54. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint32_t);
  56. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  57. uint8_t *, uint32_t *);
  58. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  59. struct lpfc_iocbq *);
  60. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  61. struct hbq_dmabuf *);
  62. static IOCB_t *
  63. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  64. {
  65. return &iocbq->iocb;
  66. }
  67. /**
  68. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  69. * @q: The Work Queue to operate on.
  70. * @wqe: The work Queue Entry to put on the Work queue.
  71. *
  72. * This routine will copy the contents of @wqe to the next available entry on
  73. * the @q. This function will then ring the Work Queue Doorbell to signal the
  74. * HBA to start processing the Work Queue Entry. This function returns 0 if
  75. * successful. If no entries are available on @q then this function will return
  76. * -ENOMEM.
  77. * The caller is expected to hold the hbalock when calling this routine.
  78. **/
  79. static uint32_t
  80. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  81. {
  82. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  83. struct lpfc_register doorbell;
  84. uint32_t host_index;
  85. /* If the host has not yet processed the next entry then we are done */
  86. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  87. return -ENOMEM;
  88. /* set consumption flag every once in a while */
  89. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  90. bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
  91. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  92. /* Update the host index before invoking device */
  93. host_index = q->host_index;
  94. q->host_index = ((q->host_index + 1) % q->entry_count);
  95. /* Ring Doorbell */
  96. doorbell.word0 = 0;
  97. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  98. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  99. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  100. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  101. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  102. return 0;
  103. }
  104. /**
  105. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  106. * @q: The Work Queue to operate on.
  107. * @index: The index to advance the hba index to.
  108. *
  109. * This routine will update the HBA index of a queue to reflect consumption of
  110. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  111. * an entry the host calls this function to update the queue's internal
  112. * pointers. This routine returns the number of entries that were consumed by
  113. * the HBA.
  114. **/
  115. static uint32_t
  116. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  117. {
  118. uint32_t released = 0;
  119. if (q->hba_index == index)
  120. return 0;
  121. do {
  122. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  123. released++;
  124. } while (q->hba_index != index);
  125. return released;
  126. }
  127. /**
  128. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  129. * @q: The Mailbox Queue to operate on.
  130. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  131. *
  132. * This routine will copy the contents of @mqe to the next available entry on
  133. * the @q. This function will then ring the Work Queue Doorbell to signal the
  134. * HBA to start processing the Work Queue Entry. This function returns 0 if
  135. * successful. If no entries are available on @q then this function will return
  136. * -ENOMEM.
  137. * The caller is expected to hold the hbalock when calling this routine.
  138. **/
  139. static uint32_t
  140. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  141. {
  142. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  143. struct lpfc_register doorbell;
  144. uint32_t host_index;
  145. /* If the host has not yet processed the next entry then we are done */
  146. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  147. return -ENOMEM;
  148. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  149. /* Save off the mailbox pointer for completion */
  150. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  151. /* Update the host index before invoking device */
  152. host_index = q->host_index;
  153. q->host_index = ((q->host_index + 1) % q->entry_count);
  154. /* Ring Doorbell */
  155. doorbell.word0 = 0;
  156. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  157. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  158. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  159. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  160. return 0;
  161. }
  162. /**
  163. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  164. * @q: The Mailbox Queue to operate on.
  165. *
  166. * This routine will update the HBA index of a queue to reflect consumption of
  167. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  168. * an entry the host calls this function to update the queue's internal
  169. * pointers. This routine returns the number of entries that were consumed by
  170. * the HBA.
  171. **/
  172. static uint32_t
  173. lpfc_sli4_mq_release(struct lpfc_queue *q)
  174. {
  175. /* Clear the mailbox pointer for completion */
  176. q->phba->mbox = NULL;
  177. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  178. return 1;
  179. }
  180. /**
  181. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  182. * @q: The Event Queue to get the first valid EQE from
  183. *
  184. * This routine will get the first valid Event Queue Entry from @q, update
  185. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  186. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  187. * processed, but not popped back to the HBA then this routine will return NULL.
  188. **/
  189. static struct lpfc_eqe *
  190. lpfc_sli4_eq_get(struct lpfc_queue *q)
  191. {
  192. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  193. /* If the next EQE is not valid then we are done */
  194. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  195. return NULL;
  196. /* If the host has not yet processed the next entry then we are done */
  197. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  198. return NULL;
  199. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  200. return eqe;
  201. }
  202. /**
  203. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  204. * @q: The Event Queue that the host has completed processing for.
  205. * @arm: Indicates whether the host wants to arms this CQ.
  206. *
  207. * This routine will mark all Event Queue Entries on @q, from the last
  208. * known completed entry to the last entry that was processed, as completed
  209. * by clearing the valid bit for each completion queue entry. Then it will
  210. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  211. * The internal host index in the @q will be updated by this routine to indicate
  212. * that the host has finished processing the entries. The @arm parameter
  213. * indicates that the queue should be rearmed when ringing the doorbell.
  214. *
  215. * This function will return the number of EQEs that were popped.
  216. **/
  217. uint32_t
  218. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  219. {
  220. uint32_t released = 0;
  221. struct lpfc_eqe *temp_eqe;
  222. struct lpfc_register doorbell;
  223. /* while there are valid entries */
  224. while (q->hba_index != q->host_index) {
  225. temp_eqe = q->qe[q->host_index].eqe;
  226. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  227. released++;
  228. q->host_index = ((q->host_index + 1) % q->entry_count);
  229. }
  230. if (unlikely(released == 0 && !arm))
  231. return 0;
  232. /* ring doorbell for number popped */
  233. doorbell.word0 = 0;
  234. if (arm) {
  235. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  236. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  237. }
  238. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  239. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  240. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  241. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  242. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  243. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  244. readl(q->phba->sli4_hba.EQCQDBregaddr);
  245. return released;
  246. }
  247. /**
  248. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  249. * @q: The Completion Queue to get the first valid CQE from
  250. *
  251. * This routine will get the first valid Completion Queue Entry from @q, update
  252. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  253. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  254. * processed, but not popped back to the HBA then this routine will return NULL.
  255. **/
  256. static struct lpfc_cqe *
  257. lpfc_sli4_cq_get(struct lpfc_queue *q)
  258. {
  259. struct lpfc_cqe *cqe;
  260. /* If the next CQE is not valid then we are done */
  261. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  262. return NULL;
  263. /* If the host has not yet processed the next entry then we are done */
  264. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  265. return NULL;
  266. cqe = q->qe[q->hba_index].cqe;
  267. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  268. return cqe;
  269. }
  270. /**
  271. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  272. * @q: The Completion Queue that the host has completed processing for.
  273. * @arm: Indicates whether the host wants to arms this CQ.
  274. *
  275. * This routine will mark all Completion queue entries on @q, from the last
  276. * known completed entry to the last entry that was processed, as completed
  277. * by clearing the valid bit for each completion queue entry. Then it will
  278. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  279. * The internal host index in the @q will be updated by this routine to indicate
  280. * that the host has finished processing the entries. The @arm parameter
  281. * indicates that the queue should be rearmed when ringing the doorbell.
  282. *
  283. * This function will return the number of CQEs that were released.
  284. **/
  285. uint32_t
  286. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  287. {
  288. uint32_t released = 0;
  289. struct lpfc_cqe *temp_qe;
  290. struct lpfc_register doorbell;
  291. /* while there are valid entries */
  292. while (q->hba_index != q->host_index) {
  293. temp_qe = q->qe[q->host_index].cqe;
  294. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  295. released++;
  296. q->host_index = ((q->host_index + 1) % q->entry_count);
  297. }
  298. if (unlikely(released == 0 && !arm))
  299. return 0;
  300. /* ring doorbell for number popped */
  301. doorbell.word0 = 0;
  302. if (arm)
  303. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  304. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  305. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  306. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  307. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  308. return released;
  309. }
  310. /**
  311. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  312. * @q: The Header Receive Queue to operate on.
  313. * @wqe: The Receive Queue Entry to put on the Receive queue.
  314. *
  315. * This routine will copy the contents of @wqe to the next available entry on
  316. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  317. * HBA to start processing the Receive Queue Entry. This function returns the
  318. * index that the rqe was copied to if successful. If no entries are available
  319. * on @q then this function will return -ENOMEM.
  320. * The caller is expected to hold the hbalock when calling this routine.
  321. **/
  322. static int
  323. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  324. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  325. {
  326. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  327. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  328. struct lpfc_register doorbell;
  329. int put_index = hq->host_index;
  330. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  331. return -EINVAL;
  332. if (hq->host_index != dq->host_index)
  333. return -EINVAL;
  334. /* If the host has not yet processed the next entry then we are done */
  335. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  336. return -EBUSY;
  337. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  338. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  339. /* Update the host index to point to the next slot */
  340. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  341. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  342. /* Ring The Header Receive Queue Doorbell */
  343. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  344. doorbell.word0 = 0;
  345. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  346. LPFC_RQ_POST_BATCH);
  347. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  348. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  349. }
  350. return put_index;
  351. }
  352. /**
  353. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  354. * @q: The Header Receive Queue to operate on.
  355. *
  356. * This routine will update the HBA index of a queue to reflect consumption of
  357. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  358. * consumed an entry the host calls this function to update the queue's
  359. * internal pointers. This routine returns the number of entries that were
  360. * consumed by the HBA.
  361. **/
  362. static uint32_t
  363. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  364. {
  365. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  366. return 0;
  367. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  368. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  369. return 1;
  370. }
  371. /**
  372. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  373. * @phba: Pointer to HBA context object.
  374. * @pring: Pointer to driver SLI ring object.
  375. *
  376. * This function returns pointer to next command iocb entry
  377. * in the command ring. The caller must hold hbalock to prevent
  378. * other threads consume the next command iocb.
  379. * SLI-2/SLI-3 provide different sized iocbs.
  380. **/
  381. static inline IOCB_t *
  382. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  383. {
  384. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  385. pring->cmdidx * phba->iocb_cmd_size);
  386. }
  387. /**
  388. * lpfc_resp_iocb - Get next response iocb entry in the ring
  389. * @phba: Pointer to HBA context object.
  390. * @pring: Pointer to driver SLI ring object.
  391. *
  392. * This function returns pointer to next response iocb entry
  393. * in the response ring. The caller must hold hbalock to make sure
  394. * that no other thread consume the next response iocb.
  395. * SLI-2/SLI-3 provide different sized iocbs.
  396. **/
  397. static inline IOCB_t *
  398. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  399. {
  400. return (IOCB_t *) (((char *) pring->rspringaddr) +
  401. pring->rspidx * phba->iocb_rsp_size);
  402. }
  403. /**
  404. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  405. * @phba: Pointer to HBA context object.
  406. *
  407. * This function is called with hbalock held. This function
  408. * allocates a new driver iocb object from the iocb pool. If the
  409. * allocation is successful, it returns pointer to the newly
  410. * allocated iocb object else it returns NULL.
  411. **/
  412. static struct lpfc_iocbq *
  413. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  414. {
  415. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  416. struct lpfc_iocbq * iocbq = NULL;
  417. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  418. if (iocbq)
  419. phba->iocb_cnt++;
  420. if (phba->iocb_cnt > phba->iocb_max)
  421. phba->iocb_max = phba->iocb_cnt;
  422. return iocbq;
  423. }
  424. /**
  425. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  426. * @phba: Pointer to HBA context object.
  427. * @xritag: XRI value.
  428. *
  429. * This function clears the sglq pointer from the array of acive
  430. * sglq's. The xritag that is passed in is used to index into the
  431. * array. Before the xritag can be used it needs to be adjusted
  432. * by subtracting the xribase.
  433. *
  434. * Returns sglq ponter = success, NULL = Failure.
  435. **/
  436. static struct lpfc_sglq *
  437. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  438. {
  439. uint16_t adj_xri;
  440. struct lpfc_sglq *sglq;
  441. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  442. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  443. return NULL;
  444. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  445. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  446. return sglq;
  447. }
  448. /**
  449. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  450. * @phba: Pointer to HBA context object.
  451. * @xritag: XRI value.
  452. *
  453. * This function returns the sglq pointer from the array of acive
  454. * sglq's. The xritag that is passed in is used to index into the
  455. * array. Before the xritag can be used it needs to be adjusted
  456. * by subtracting the xribase.
  457. *
  458. * Returns sglq ponter = success, NULL = Failure.
  459. **/
  460. struct lpfc_sglq *
  461. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  462. {
  463. uint16_t adj_xri;
  464. struct lpfc_sglq *sglq;
  465. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  466. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  467. return NULL;
  468. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  469. return sglq;
  470. }
  471. /**
  472. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  473. * @phba: Pointer to HBA context object.
  474. *
  475. * This function is called with hbalock held. This function
  476. * Gets a new driver sglq object from the sglq list. If the
  477. * list is not empty then it is successful, it returns pointer to the newly
  478. * allocated sglq object else it returns NULL.
  479. **/
  480. static struct lpfc_sglq *
  481. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  482. {
  483. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  484. struct lpfc_sglq *sglq = NULL;
  485. uint16_t adj_xri;
  486. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  487. if (!sglq)
  488. return NULL;
  489. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  490. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  491. sglq->state = SGL_ALLOCATED;
  492. return sglq;
  493. }
  494. /**
  495. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  496. * @phba: Pointer to HBA context object.
  497. *
  498. * This function is called with no lock held. This function
  499. * allocates a new driver iocb object from the iocb pool. If the
  500. * allocation is successful, it returns pointer to the newly
  501. * allocated iocb object else it returns NULL.
  502. **/
  503. struct lpfc_iocbq *
  504. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  505. {
  506. struct lpfc_iocbq * iocbq = NULL;
  507. unsigned long iflags;
  508. spin_lock_irqsave(&phba->hbalock, iflags);
  509. iocbq = __lpfc_sli_get_iocbq(phba);
  510. spin_unlock_irqrestore(&phba->hbalock, iflags);
  511. return iocbq;
  512. }
  513. /**
  514. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  515. * @phba: Pointer to HBA context object.
  516. * @iocbq: Pointer to driver iocb object.
  517. *
  518. * This function is called with hbalock held to release driver
  519. * iocb object to the iocb pool. The iotag in the iocb object
  520. * does not change for each use of the iocb object. This function
  521. * clears all other fields of the iocb object when it is freed.
  522. * The sqlq structure that holds the xritag and phys and virtual
  523. * mappings for the scatter gather list is retrieved from the
  524. * active array of sglq. The get of the sglq pointer also clears
  525. * the entry in the array. If the status of the IO indiactes that
  526. * this IO was aborted then the sglq entry it put on the
  527. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  528. * IO has good status or fails for any other reason then the sglq
  529. * entry is added to the free list (lpfc_sgl_list).
  530. **/
  531. static void
  532. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  533. {
  534. struct lpfc_sglq *sglq;
  535. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  536. unsigned long iflag = 0;
  537. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  538. if (iocbq->sli4_xritag == NO_XRI)
  539. sglq = NULL;
  540. else
  541. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  542. if (sglq) {
  543. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  544. (sglq->state != SGL_XRI_ABORTED)) {
  545. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  546. iflag);
  547. list_add(&sglq->list,
  548. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  549. spin_unlock_irqrestore(
  550. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  551. } else {
  552. sglq->state = SGL_FREED;
  553. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  554. /* Check if TXQ queue needs to be serviced */
  555. if (pring->txq_cnt)
  556. lpfc_worker_wake_up(phba);
  557. }
  558. }
  559. /*
  560. * Clean all volatile data fields, preserve iotag and node struct.
  561. */
  562. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  563. iocbq->sli4_xritag = NO_XRI;
  564. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  565. }
  566. /**
  567. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  568. * @phba: Pointer to HBA context object.
  569. * @iocbq: Pointer to driver iocb object.
  570. *
  571. * This function is called with hbalock held to release driver
  572. * iocb object to the iocb pool. The iotag in the iocb object
  573. * does not change for each use of the iocb object. This function
  574. * clears all other fields of the iocb object when it is freed.
  575. **/
  576. static void
  577. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  578. {
  579. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  580. /*
  581. * Clean all volatile data fields, preserve iotag and node struct.
  582. */
  583. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  584. iocbq->sli4_xritag = NO_XRI;
  585. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  586. }
  587. /**
  588. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  589. * @phba: Pointer to HBA context object.
  590. * @iocbq: Pointer to driver iocb object.
  591. *
  592. * This function is called with hbalock held to release driver
  593. * iocb object to the iocb pool. The iotag in the iocb object
  594. * does not change for each use of the iocb object. This function
  595. * clears all other fields of the iocb object when it is freed.
  596. **/
  597. static void
  598. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  599. {
  600. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  601. phba->iocb_cnt--;
  602. }
  603. /**
  604. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  605. * @phba: Pointer to HBA context object.
  606. * @iocbq: Pointer to driver iocb object.
  607. *
  608. * This function is called with no lock held to release the iocb to
  609. * iocb pool.
  610. **/
  611. void
  612. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  613. {
  614. unsigned long iflags;
  615. /*
  616. * Clean all volatile data fields, preserve iotag and node struct.
  617. */
  618. spin_lock_irqsave(&phba->hbalock, iflags);
  619. __lpfc_sli_release_iocbq(phba, iocbq);
  620. spin_unlock_irqrestore(&phba->hbalock, iflags);
  621. }
  622. /**
  623. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  624. * @phba: Pointer to HBA context object.
  625. * @iocblist: List of IOCBs.
  626. * @ulpstatus: ULP status in IOCB command field.
  627. * @ulpWord4: ULP word-4 in IOCB command field.
  628. *
  629. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  630. * on the list by invoking the complete callback function associated with the
  631. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  632. * fields.
  633. **/
  634. void
  635. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  636. uint32_t ulpstatus, uint32_t ulpWord4)
  637. {
  638. struct lpfc_iocbq *piocb;
  639. while (!list_empty(iocblist)) {
  640. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  641. if (!piocb->iocb_cmpl)
  642. lpfc_sli_release_iocbq(phba, piocb);
  643. else {
  644. piocb->iocb.ulpStatus = ulpstatus;
  645. piocb->iocb.un.ulpWord[4] = ulpWord4;
  646. (piocb->iocb_cmpl) (phba, piocb, piocb);
  647. }
  648. }
  649. return;
  650. }
  651. /**
  652. * lpfc_sli_iocb_cmd_type - Get the iocb type
  653. * @iocb_cmnd: iocb command code.
  654. *
  655. * This function is called by ring event handler function to get the iocb type.
  656. * This function translates the iocb command to an iocb command type used to
  657. * decide the final disposition of each completed IOCB.
  658. * The function returns
  659. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  660. * LPFC_SOL_IOCB if it is a solicited iocb completion
  661. * LPFC_ABORT_IOCB if it is an abort iocb
  662. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  663. *
  664. * The caller is not required to hold any lock.
  665. **/
  666. static lpfc_iocb_type
  667. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  668. {
  669. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  670. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  671. return 0;
  672. switch (iocb_cmnd) {
  673. case CMD_XMIT_SEQUENCE_CR:
  674. case CMD_XMIT_SEQUENCE_CX:
  675. case CMD_XMIT_BCAST_CN:
  676. case CMD_XMIT_BCAST_CX:
  677. case CMD_ELS_REQUEST_CR:
  678. case CMD_ELS_REQUEST_CX:
  679. case CMD_CREATE_XRI_CR:
  680. case CMD_CREATE_XRI_CX:
  681. case CMD_GET_RPI_CN:
  682. case CMD_XMIT_ELS_RSP_CX:
  683. case CMD_GET_RPI_CR:
  684. case CMD_FCP_IWRITE_CR:
  685. case CMD_FCP_IWRITE_CX:
  686. case CMD_FCP_IREAD_CR:
  687. case CMD_FCP_IREAD_CX:
  688. case CMD_FCP_ICMND_CR:
  689. case CMD_FCP_ICMND_CX:
  690. case CMD_FCP_TSEND_CX:
  691. case CMD_FCP_TRSP_CX:
  692. case CMD_FCP_TRECEIVE_CX:
  693. case CMD_FCP_AUTO_TRSP_CX:
  694. case CMD_ADAPTER_MSG:
  695. case CMD_ADAPTER_DUMP:
  696. case CMD_XMIT_SEQUENCE64_CR:
  697. case CMD_XMIT_SEQUENCE64_CX:
  698. case CMD_XMIT_BCAST64_CN:
  699. case CMD_XMIT_BCAST64_CX:
  700. case CMD_ELS_REQUEST64_CR:
  701. case CMD_ELS_REQUEST64_CX:
  702. case CMD_FCP_IWRITE64_CR:
  703. case CMD_FCP_IWRITE64_CX:
  704. case CMD_FCP_IREAD64_CR:
  705. case CMD_FCP_IREAD64_CX:
  706. case CMD_FCP_ICMND64_CR:
  707. case CMD_FCP_ICMND64_CX:
  708. case CMD_FCP_TSEND64_CX:
  709. case CMD_FCP_TRSP64_CX:
  710. case CMD_FCP_TRECEIVE64_CX:
  711. case CMD_GEN_REQUEST64_CR:
  712. case CMD_GEN_REQUEST64_CX:
  713. case CMD_XMIT_ELS_RSP64_CX:
  714. case DSSCMD_IWRITE64_CR:
  715. case DSSCMD_IWRITE64_CX:
  716. case DSSCMD_IREAD64_CR:
  717. case DSSCMD_IREAD64_CX:
  718. type = LPFC_SOL_IOCB;
  719. break;
  720. case CMD_ABORT_XRI_CN:
  721. case CMD_ABORT_XRI_CX:
  722. case CMD_CLOSE_XRI_CN:
  723. case CMD_CLOSE_XRI_CX:
  724. case CMD_XRI_ABORTED_CX:
  725. case CMD_ABORT_MXRI64_CN:
  726. case CMD_XMIT_BLS_RSP64_CX:
  727. type = LPFC_ABORT_IOCB;
  728. break;
  729. case CMD_RCV_SEQUENCE_CX:
  730. case CMD_RCV_ELS_REQ_CX:
  731. case CMD_RCV_SEQUENCE64_CX:
  732. case CMD_RCV_ELS_REQ64_CX:
  733. case CMD_ASYNC_STATUS:
  734. case CMD_IOCB_RCV_SEQ64_CX:
  735. case CMD_IOCB_RCV_ELS64_CX:
  736. case CMD_IOCB_RCV_CONT64_CX:
  737. case CMD_IOCB_RET_XRI64_CX:
  738. type = LPFC_UNSOL_IOCB;
  739. break;
  740. case CMD_IOCB_XMIT_MSEQ64_CR:
  741. case CMD_IOCB_XMIT_MSEQ64_CX:
  742. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  743. case CMD_IOCB_RCV_ELS_LIST64_CX:
  744. case CMD_IOCB_CLOSE_EXTENDED_CN:
  745. case CMD_IOCB_ABORT_EXTENDED_CN:
  746. case CMD_IOCB_RET_HBQE64_CN:
  747. case CMD_IOCB_FCP_IBIDIR64_CR:
  748. case CMD_IOCB_FCP_IBIDIR64_CX:
  749. case CMD_IOCB_FCP_ITASKMGT64_CX:
  750. case CMD_IOCB_LOGENTRY_CN:
  751. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  752. printk("%s - Unhandled SLI-3 Command x%x\n",
  753. __func__, iocb_cmnd);
  754. type = LPFC_UNKNOWN_IOCB;
  755. break;
  756. default:
  757. type = LPFC_UNKNOWN_IOCB;
  758. break;
  759. }
  760. return type;
  761. }
  762. /**
  763. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  764. * @phba: Pointer to HBA context object.
  765. *
  766. * This function is called from SLI initialization code
  767. * to configure every ring of the HBA's SLI interface. The
  768. * caller is not required to hold any lock. This function issues
  769. * a config_ring mailbox command for each ring.
  770. * This function returns zero if successful else returns a negative
  771. * error code.
  772. **/
  773. static int
  774. lpfc_sli_ring_map(struct lpfc_hba *phba)
  775. {
  776. struct lpfc_sli *psli = &phba->sli;
  777. LPFC_MBOXQ_t *pmb;
  778. MAILBOX_t *pmbox;
  779. int i, rc, ret = 0;
  780. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  781. if (!pmb)
  782. return -ENOMEM;
  783. pmbox = &pmb->u.mb;
  784. phba->link_state = LPFC_INIT_MBX_CMDS;
  785. for (i = 0; i < psli->num_rings; i++) {
  786. lpfc_config_ring(phba, i, pmb);
  787. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  788. if (rc != MBX_SUCCESS) {
  789. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  790. "0446 Adapter failed to init (%d), "
  791. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  792. "ring %d\n",
  793. rc, pmbox->mbxCommand,
  794. pmbox->mbxStatus, i);
  795. phba->link_state = LPFC_HBA_ERROR;
  796. ret = -ENXIO;
  797. break;
  798. }
  799. }
  800. mempool_free(pmb, phba->mbox_mem_pool);
  801. return ret;
  802. }
  803. /**
  804. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  805. * @phba: Pointer to HBA context object.
  806. * @pring: Pointer to driver SLI ring object.
  807. * @piocb: Pointer to the driver iocb object.
  808. *
  809. * This function is called with hbalock held. The function adds the
  810. * new iocb to txcmplq of the given ring. This function always returns
  811. * 0. If this function is called for ELS ring, this function checks if
  812. * there is a vport associated with the ELS command. This function also
  813. * starts els_tmofunc timer if this is an ELS command.
  814. **/
  815. static int
  816. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  817. struct lpfc_iocbq *piocb)
  818. {
  819. list_add_tail(&piocb->list, &pring->txcmplq);
  820. piocb->iocb_flag |= LPFC_IO_ON_Q;
  821. pring->txcmplq_cnt++;
  822. if (pring->txcmplq_cnt > pring->txcmplq_max)
  823. pring->txcmplq_max = pring->txcmplq_cnt;
  824. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  825. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  826. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  827. if (!piocb->vport)
  828. BUG();
  829. else
  830. mod_timer(&piocb->vport->els_tmofunc,
  831. jiffies + HZ * (phba->fc_ratov << 1));
  832. }
  833. return 0;
  834. }
  835. /**
  836. * lpfc_sli_ringtx_get - Get first element of the txq
  837. * @phba: Pointer to HBA context object.
  838. * @pring: Pointer to driver SLI ring object.
  839. *
  840. * This function is called with hbalock held to get next
  841. * iocb in txq of the given ring. If there is any iocb in
  842. * the txq, the function returns first iocb in the list after
  843. * removing the iocb from the list, else it returns NULL.
  844. **/
  845. struct lpfc_iocbq *
  846. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  847. {
  848. struct lpfc_iocbq *cmd_iocb;
  849. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  850. if (cmd_iocb != NULL)
  851. pring->txq_cnt--;
  852. return cmd_iocb;
  853. }
  854. /**
  855. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  856. * @phba: Pointer to HBA context object.
  857. * @pring: Pointer to driver SLI ring object.
  858. *
  859. * This function is called with hbalock held and the caller must post the
  860. * iocb without releasing the lock. If the caller releases the lock,
  861. * iocb slot returned by the function is not guaranteed to be available.
  862. * The function returns pointer to the next available iocb slot if there
  863. * is available slot in the ring, else it returns NULL.
  864. * If the get index of the ring is ahead of the put index, the function
  865. * will post an error attention event to the worker thread to take the
  866. * HBA to offline state.
  867. **/
  868. static IOCB_t *
  869. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  870. {
  871. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  872. uint32_t max_cmd_idx = pring->numCiocb;
  873. if ((pring->next_cmdidx == pring->cmdidx) &&
  874. (++pring->next_cmdidx >= max_cmd_idx))
  875. pring->next_cmdidx = 0;
  876. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  877. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  878. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  879. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  880. "0315 Ring %d issue: portCmdGet %d "
  881. "is bigger than cmd ring %d\n",
  882. pring->ringno,
  883. pring->local_getidx, max_cmd_idx);
  884. phba->link_state = LPFC_HBA_ERROR;
  885. /*
  886. * All error attention handlers are posted to
  887. * worker thread
  888. */
  889. phba->work_ha |= HA_ERATT;
  890. phba->work_hs = HS_FFER3;
  891. lpfc_worker_wake_up(phba);
  892. return NULL;
  893. }
  894. if (pring->local_getidx == pring->next_cmdidx)
  895. return NULL;
  896. }
  897. return lpfc_cmd_iocb(phba, pring);
  898. }
  899. /**
  900. * lpfc_sli_next_iotag - Get an iotag for the iocb
  901. * @phba: Pointer to HBA context object.
  902. * @iocbq: Pointer to driver iocb object.
  903. *
  904. * This function gets an iotag for the iocb. If there is no unused iotag and
  905. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  906. * array and assigns a new iotag.
  907. * The function returns the allocated iotag if successful, else returns zero.
  908. * Zero is not a valid iotag.
  909. * The caller is not required to hold any lock.
  910. **/
  911. uint16_t
  912. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  913. {
  914. struct lpfc_iocbq **new_arr;
  915. struct lpfc_iocbq **old_arr;
  916. size_t new_len;
  917. struct lpfc_sli *psli = &phba->sli;
  918. uint16_t iotag;
  919. spin_lock_irq(&phba->hbalock);
  920. iotag = psli->last_iotag;
  921. if(++iotag < psli->iocbq_lookup_len) {
  922. psli->last_iotag = iotag;
  923. psli->iocbq_lookup[iotag] = iocbq;
  924. spin_unlock_irq(&phba->hbalock);
  925. iocbq->iotag = iotag;
  926. return iotag;
  927. } else if (psli->iocbq_lookup_len < (0xffff
  928. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  929. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  930. spin_unlock_irq(&phba->hbalock);
  931. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  932. GFP_KERNEL);
  933. if (new_arr) {
  934. spin_lock_irq(&phba->hbalock);
  935. old_arr = psli->iocbq_lookup;
  936. if (new_len <= psli->iocbq_lookup_len) {
  937. /* highly unprobable case */
  938. kfree(new_arr);
  939. iotag = psli->last_iotag;
  940. if(++iotag < psli->iocbq_lookup_len) {
  941. psli->last_iotag = iotag;
  942. psli->iocbq_lookup[iotag] = iocbq;
  943. spin_unlock_irq(&phba->hbalock);
  944. iocbq->iotag = iotag;
  945. return iotag;
  946. }
  947. spin_unlock_irq(&phba->hbalock);
  948. return 0;
  949. }
  950. if (psli->iocbq_lookup)
  951. memcpy(new_arr, old_arr,
  952. ((psli->last_iotag + 1) *
  953. sizeof (struct lpfc_iocbq *)));
  954. psli->iocbq_lookup = new_arr;
  955. psli->iocbq_lookup_len = new_len;
  956. psli->last_iotag = iotag;
  957. psli->iocbq_lookup[iotag] = iocbq;
  958. spin_unlock_irq(&phba->hbalock);
  959. iocbq->iotag = iotag;
  960. kfree(old_arr);
  961. return iotag;
  962. }
  963. } else
  964. spin_unlock_irq(&phba->hbalock);
  965. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  966. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  967. psli->last_iotag);
  968. return 0;
  969. }
  970. /**
  971. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  972. * @phba: Pointer to HBA context object.
  973. * @pring: Pointer to driver SLI ring object.
  974. * @iocb: Pointer to iocb slot in the ring.
  975. * @nextiocb: Pointer to driver iocb object which need to be
  976. * posted to firmware.
  977. *
  978. * This function is called with hbalock held to post a new iocb to
  979. * the firmware. This function copies the new iocb to ring iocb slot and
  980. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  981. * a completion call back for this iocb else the function will free the
  982. * iocb object.
  983. **/
  984. static void
  985. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  986. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  987. {
  988. /*
  989. * Set up an iotag
  990. */
  991. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  992. if (pring->ringno == LPFC_ELS_RING) {
  993. lpfc_debugfs_slow_ring_trc(phba,
  994. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  995. *(((uint32_t *) &nextiocb->iocb) + 4),
  996. *(((uint32_t *) &nextiocb->iocb) + 6),
  997. *(((uint32_t *) &nextiocb->iocb) + 7));
  998. }
  999. /*
  1000. * Issue iocb command to adapter
  1001. */
  1002. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1003. wmb();
  1004. pring->stats.iocb_cmd++;
  1005. /*
  1006. * If there is no completion routine to call, we can release the
  1007. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1008. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1009. */
  1010. if (nextiocb->iocb_cmpl)
  1011. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1012. else
  1013. __lpfc_sli_release_iocbq(phba, nextiocb);
  1014. /*
  1015. * Let the HBA know what IOCB slot will be the next one the
  1016. * driver will put a command into.
  1017. */
  1018. pring->cmdidx = pring->next_cmdidx;
  1019. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1020. }
  1021. /**
  1022. * lpfc_sli_update_full_ring - Update the chip attention register
  1023. * @phba: Pointer to HBA context object.
  1024. * @pring: Pointer to driver SLI ring object.
  1025. *
  1026. * The caller is not required to hold any lock for calling this function.
  1027. * This function updates the chip attention bits for the ring to inform firmware
  1028. * that there are pending work to be done for this ring and requests an
  1029. * interrupt when there is space available in the ring. This function is
  1030. * called when the driver is unable to post more iocbs to the ring due
  1031. * to unavailability of space in the ring.
  1032. **/
  1033. static void
  1034. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1035. {
  1036. int ringno = pring->ringno;
  1037. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1038. wmb();
  1039. /*
  1040. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1041. * The HBA will tell us when an IOCB entry is available.
  1042. */
  1043. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1044. readl(phba->CAregaddr); /* flush */
  1045. pring->stats.iocb_cmd_full++;
  1046. }
  1047. /**
  1048. * lpfc_sli_update_ring - Update chip attention register
  1049. * @phba: Pointer to HBA context object.
  1050. * @pring: Pointer to driver SLI ring object.
  1051. *
  1052. * This function updates the chip attention register bit for the
  1053. * given ring to inform HBA that there is more work to be done
  1054. * in this ring. The caller is not required to hold any lock.
  1055. **/
  1056. static void
  1057. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1058. {
  1059. int ringno = pring->ringno;
  1060. /*
  1061. * Tell the HBA that there is work to do in this ring.
  1062. */
  1063. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1064. wmb();
  1065. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1066. readl(phba->CAregaddr); /* flush */
  1067. }
  1068. }
  1069. /**
  1070. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1071. * @phba: Pointer to HBA context object.
  1072. * @pring: Pointer to driver SLI ring object.
  1073. *
  1074. * This function is called with hbalock held to post pending iocbs
  1075. * in the txq to the firmware. This function is called when driver
  1076. * detects space available in the ring.
  1077. **/
  1078. static void
  1079. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1080. {
  1081. IOCB_t *iocb;
  1082. struct lpfc_iocbq *nextiocb;
  1083. /*
  1084. * Check to see if:
  1085. * (a) there is anything on the txq to send
  1086. * (b) link is up
  1087. * (c) link attention events can be processed (fcp ring only)
  1088. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1089. */
  1090. if (pring->txq_cnt &&
  1091. lpfc_is_link_up(phba) &&
  1092. (pring->ringno != phba->sli.fcp_ring ||
  1093. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1094. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1095. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1096. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1097. if (iocb)
  1098. lpfc_sli_update_ring(phba, pring);
  1099. else
  1100. lpfc_sli_update_full_ring(phba, pring);
  1101. }
  1102. return;
  1103. }
  1104. /**
  1105. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1106. * @phba: Pointer to HBA context object.
  1107. * @hbqno: HBQ number.
  1108. *
  1109. * This function is called with hbalock held to get the next
  1110. * available slot for the given HBQ. If there is free slot
  1111. * available for the HBQ it will return pointer to the next available
  1112. * HBQ entry else it will return NULL.
  1113. **/
  1114. static struct lpfc_hbq_entry *
  1115. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1116. {
  1117. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1118. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1119. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1120. hbqp->next_hbqPutIdx = 0;
  1121. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1122. uint32_t raw_index = phba->hbq_get[hbqno];
  1123. uint32_t getidx = le32_to_cpu(raw_index);
  1124. hbqp->local_hbqGetIdx = getidx;
  1125. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1126. lpfc_printf_log(phba, KERN_ERR,
  1127. LOG_SLI | LOG_VPORT,
  1128. "1802 HBQ %d: local_hbqGetIdx "
  1129. "%u is > than hbqp->entry_count %u\n",
  1130. hbqno, hbqp->local_hbqGetIdx,
  1131. hbqp->entry_count);
  1132. phba->link_state = LPFC_HBA_ERROR;
  1133. return NULL;
  1134. }
  1135. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1136. return NULL;
  1137. }
  1138. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1139. hbqp->hbqPutIdx;
  1140. }
  1141. /**
  1142. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1143. * @phba: Pointer to HBA context object.
  1144. *
  1145. * This function is called with no lock held to free all the
  1146. * hbq buffers while uninitializing the SLI interface. It also
  1147. * frees the HBQ buffers returned by the firmware but not yet
  1148. * processed by the upper layers.
  1149. **/
  1150. void
  1151. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1152. {
  1153. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1154. struct hbq_dmabuf *hbq_buf;
  1155. unsigned long flags;
  1156. int i, hbq_count;
  1157. uint32_t hbqno;
  1158. hbq_count = lpfc_sli_hbq_count();
  1159. /* Return all memory used by all HBQs */
  1160. spin_lock_irqsave(&phba->hbalock, flags);
  1161. for (i = 0; i < hbq_count; ++i) {
  1162. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1163. &phba->hbqs[i].hbq_buffer_list, list) {
  1164. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1165. list_del(&hbq_buf->dbuf.list);
  1166. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1167. }
  1168. phba->hbqs[i].buffer_count = 0;
  1169. }
  1170. /* Return all HBQ buffer that are in-fly */
  1171. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1172. list) {
  1173. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1174. list_del(&hbq_buf->dbuf.list);
  1175. if (hbq_buf->tag == -1) {
  1176. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1177. (phba, hbq_buf);
  1178. } else {
  1179. hbqno = hbq_buf->tag >> 16;
  1180. if (hbqno >= LPFC_MAX_HBQS)
  1181. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1182. (phba, hbq_buf);
  1183. else
  1184. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1185. hbq_buf);
  1186. }
  1187. }
  1188. /* Mark the HBQs not in use */
  1189. phba->hbq_in_use = 0;
  1190. spin_unlock_irqrestore(&phba->hbalock, flags);
  1191. }
  1192. /**
  1193. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1194. * @phba: Pointer to HBA context object.
  1195. * @hbqno: HBQ number.
  1196. * @hbq_buf: Pointer to HBQ buffer.
  1197. *
  1198. * This function is called with the hbalock held to post a
  1199. * hbq buffer to the firmware. If the function finds an empty
  1200. * slot in the HBQ, it will post the buffer. The function will return
  1201. * pointer to the hbq entry if it successfully post the buffer
  1202. * else it will return NULL.
  1203. **/
  1204. static int
  1205. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1206. struct hbq_dmabuf *hbq_buf)
  1207. {
  1208. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1209. }
  1210. /**
  1211. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1212. * @phba: Pointer to HBA context object.
  1213. * @hbqno: HBQ number.
  1214. * @hbq_buf: Pointer to HBQ buffer.
  1215. *
  1216. * This function is called with the hbalock held to post a hbq buffer to the
  1217. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1218. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1219. * it successfully post the buffer else it will return an error.
  1220. **/
  1221. static int
  1222. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1223. struct hbq_dmabuf *hbq_buf)
  1224. {
  1225. struct lpfc_hbq_entry *hbqe;
  1226. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1227. /* Get next HBQ entry slot to use */
  1228. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1229. if (hbqe) {
  1230. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1231. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1232. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1233. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1234. hbqe->bde.tus.f.bdeFlags = 0;
  1235. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1236. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1237. /* Sync SLIM */
  1238. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1239. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1240. /* flush */
  1241. readl(phba->hbq_put + hbqno);
  1242. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1243. return 0;
  1244. } else
  1245. return -ENOMEM;
  1246. }
  1247. /**
  1248. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1249. * @phba: Pointer to HBA context object.
  1250. * @hbqno: HBQ number.
  1251. * @hbq_buf: Pointer to HBQ buffer.
  1252. *
  1253. * This function is called with the hbalock held to post an RQE to the SLI4
  1254. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1255. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1256. **/
  1257. static int
  1258. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1259. struct hbq_dmabuf *hbq_buf)
  1260. {
  1261. int rc;
  1262. struct lpfc_rqe hrqe;
  1263. struct lpfc_rqe drqe;
  1264. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1265. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1266. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1267. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1268. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1269. &hrqe, &drqe);
  1270. if (rc < 0)
  1271. return rc;
  1272. hbq_buf->tag = rc;
  1273. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1274. return 0;
  1275. }
  1276. /* HBQ for ELS and CT traffic. */
  1277. static struct lpfc_hbq_init lpfc_els_hbq = {
  1278. .rn = 1,
  1279. .entry_count = 256,
  1280. .mask_count = 0,
  1281. .profile = 0,
  1282. .ring_mask = (1 << LPFC_ELS_RING),
  1283. .buffer_count = 0,
  1284. .init_count = 40,
  1285. .add_count = 40,
  1286. };
  1287. /* HBQ for the extra ring if needed */
  1288. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1289. .rn = 1,
  1290. .entry_count = 200,
  1291. .mask_count = 0,
  1292. .profile = 0,
  1293. .ring_mask = (1 << LPFC_EXTRA_RING),
  1294. .buffer_count = 0,
  1295. .init_count = 0,
  1296. .add_count = 5,
  1297. };
  1298. /* Array of HBQs */
  1299. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1300. &lpfc_els_hbq,
  1301. &lpfc_extra_hbq,
  1302. };
  1303. /**
  1304. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1305. * @phba: Pointer to HBA context object.
  1306. * @hbqno: HBQ number.
  1307. * @count: Number of HBQ buffers to be posted.
  1308. *
  1309. * This function is called with no lock held to post more hbq buffers to the
  1310. * given HBQ. The function returns the number of HBQ buffers successfully
  1311. * posted.
  1312. **/
  1313. static int
  1314. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1315. {
  1316. uint32_t i, posted = 0;
  1317. unsigned long flags;
  1318. struct hbq_dmabuf *hbq_buffer;
  1319. LIST_HEAD(hbq_buf_list);
  1320. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1321. return 0;
  1322. if ((phba->hbqs[hbqno].buffer_count + count) >
  1323. lpfc_hbq_defs[hbqno]->entry_count)
  1324. count = lpfc_hbq_defs[hbqno]->entry_count -
  1325. phba->hbqs[hbqno].buffer_count;
  1326. if (!count)
  1327. return 0;
  1328. /* Allocate HBQ entries */
  1329. for (i = 0; i < count; i++) {
  1330. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1331. if (!hbq_buffer)
  1332. break;
  1333. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1334. }
  1335. /* Check whether HBQ is still in use */
  1336. spin_lock_irqsave(&phba->hbalock, flags);
  1337. if (!phba->hbq_in_use)
  1338. goto err;
  1339. while (!list_empty(&hbq_buf_list)) {
  1340. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1341. dbuf.list);
  1342. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1343. (hbqno << 16));
  1344. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1345. phba->hbqs[hbqno].buffer_count++;
  1346. posted++;
  1347. } else
  1348. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1349. }
  1350. spin_unlock_irqrestore(&phba->hbalock, flags);
  1351. return posted;
  1352. err:
  1353. spin_unlock_irqrestore(&phba->hbalock, flags);
  1354. while (!list_empty(&hbq_buf_list)) {
  1355. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1356. dbuf.list);
  1357. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1358. }
  1359. return 0;
  1360. }
  1361. /**
  1362. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1363. * @phba: Pointer to HBA context object.
  1364. * @qno: HBQ number.
  1365. *
  1366. * This function posts more buffers to the HBQ. This function
  1367. * is called with no lock held. The function returns the number of HBQ entries
  1368. * successfully allocated.
  1369. **/
  1370. int
  1371. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1372. {
  1373. if (phba->sli_rev == LPFC_SLI_REV4)
  1374. return 0;
  1375. else
  1376. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1377. lpfc_hbq_defs[qno]->add_count);
  1378. }
  1379. /**
  1380. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1381. * @phba: Pointer to HBA context object.
  1382. * @qno: HBQ queue number.
  1383. *
  1384. * This function is called from SLI initialization code path with
  1385. * no lock held to post initial HBQ buffers to firmware. The
  1386. * function returns the number of HBQ entries successfully allocated.
  1387. **/
  1388. static int
  1389. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1390. {
  1391. if (phba->sli_rev == LPFC_SLI_REV4)
  1392. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1393. lpfc_hbq_defs[qno]->entry_count);
  1394. else
  1395. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1396. lpfc_hbq_defs[qno]->init_count);
  1397. }
  1398. /**
  1399. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1400. * @phba: Pointer to HBA context object.
  1401. * @hbqno: HBQ number.
  1402. *
  1403. * This function removes the first hbq buffer on an hbq list and returns a
  1404. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1405. **/
  1406. static struct hbq_dmabuf *
  1407. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1408. {
  1409. struct lpfc_dmabuf *d_buf;
  1410. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1411. if (!d_buf)
  1412. return NULL;
  1413. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1414. }
  1415. /**
  1416. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1417. * @phba: Pointer to HBA context object.
  1418. * @tag: Tag of the hbq buffer.
  1419. *
  1420. * This function is called with hbalock held. This function searches
  1421. * for the hbq buffer associated with the given tag in the hbq buffer
  1422. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1423. * it returns NULL.
  1424. **/
  1425. static struct hbq_dmabuf *
  1426. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1427. {
  1428. struct lpfc_dmabuf *d_buf;
  1429. struct hbq_dmabuf *hbq_buf;
  1430. uint32_t hbqno;
  1431. hbqno = tag >> 16;
  1432. if (hbqno >= LPFC_MAX_HBQS)
  1433. return NULL;
  1434. spin_lock_irq(&phba->hbalock);
  1435. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1436. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1437. if (hbq_buf->tag == tag) {
  1438. spin_unlock_irq(&phba->hbalock);
  1439. return hbq_buf;
  1440. }
  1441. }
  1442. spin_unlock_irq(&phba->hbalock);
  1443. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1444. "1803 Bad hbq tag. Data: x%x x%x\n",
  1445. tag, phba->hbqs[tag >> 16].buffer_count);
  1446. return NULL;
  1447. }
  1448. /**
  1449. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1450. * @phba: Pointer to HBA context object.
  1451. * @hbq_buffer: Pointer to HBQ buffer.
  1452. *
  1453. * This function is called with hbalock. This function gives back
  1454. * the hbq buffer to firmware. If the HBQ does not have space to
  1455. * post the buffer, it will free the buffer.
  1456. **/
  1457. void
  1458. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1459. {
  1460. uint32_t hbqno;
  1461. if (hbq_buffer) {
  1462. hbqno = hbq_buffer->tag >> 16;
  1463. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1464. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1465. }
  1466. }
  1467. /**
  1468. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1469. * @mbxCommand: mailbox command code.
  1470. *
  1471. * This function is called by the mailbox event handler function to verify
  1472. * that the completed mailbox command is a legitimate mailbox command. If the
  1473. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1474. * and the mailbox event handler will take the HBA offline.
  1475. **/
  1476. static int
  1477. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1478. {
  1479. uint8_t ret;
  1480. switch (mbxCommand) {
  1481. case MBX_LOAD_SM:
  1482. case MBX_READ_NV:
  1483. case MBX_WRITE_NV:
  1484. case MBX_WRITE_VPARMS:
  1485. case MBX_RUN_BIU_DIAG:
  1486. case MBX_INIT_LINK:
  1487. case MBX_DOWN_LINK:
  1488. case MBX_CONFIG_LINK:
  1489. case MBX_CONFIG_RING:
  1490. case MBX_RESET_RING:
  1491. case MBX_READ_CONFIG:
  1492. case MBX_READ_RCONFIG:
  1493. case MBX_READ_SPARM:
  1494. case MBX_READ_STATUS:
  1495. case MBX_READ_RPI:
  1496. case MBX_READ_XRI:
  1497. case MBX_READ_REV:
  1498. case MBX_READ_LNK_STAT:
  1499. case MBX_REG_LOGIN:
  1500. case MBX_UNREG_LOGIN:
  1501. case MBX_READ_LA:
  1502. case MBX_CLEAR_LA:
  1503. case MBX_DUMP_MEMORY:
  1504. case MBX_DUMP_CONTEXT:
  1505. case MBX_RUN_DIAGS:
  1506. case MBX_RESTART:
  1507. case MBX_UPDATE_CFG:
  1508. case MBX_DOWN_LOAD:
  1509. case MBX_DEL_LD_ENTRY:
  1510. case MBX_RUN_PROGRAM:
  1511. case MBX_SET_MASK:
  1512. case MBX_SET_VARIABLE:
  1513. case MBX_UNREG_D_ID:
  1514. case MBX_KILL_BOARD:
  1515. case MBX_CONFIG_FARP:
  1516. case MBX_BEACON:
  1517. case MBX_LOAD_AREA:
  1518. case MBX_RUN_BIU_DIAG64:
  1519. case MBX_CONFIG_PORT:
  1520. case MBX_READ_SPARM64:
  1521. case MBX_READ_RPI64:
  1522. case MBX_REG_LOGIN64:
  1523. case MBX_READ_LA64:
  1524. case MBX_WRITE_WWN:
  1525. case MBX_SET_DEBUG:
  1526. case MBX_LOAD_EXP_ROM:
  1527. case MBX_ASYNCEVT_ENABLE:
  1528. case MBX_REG_VPI:
  1529. case MBX_UNREG_VPI:
  1530. case MBX_HEARTBEAT:
  1531. case MBX_PORT_CAPABILITIES:
  1532. case MBX_PORT_IOV_CONTROL:
  1533. case MBX_SLI4_CONFIG:
  1534. case MBX_SLI4_REQ_FTRS:
  1535. case MBX_REG_FCFI:
  1536. case MBX_UNREG_FCFI:
  1537. case MBX_REG_VFI:
  1538. case MBX_UNREG_VFI:
  1539. case MBX_INIT_VPI:
  1540. case MBX_INIT_VFI:
  1541. case MBX_RESUME_RPI:
  1542. case MBX_READ_EVENT_LOG_STATUS:
  1543. case MBX_READ_EVENT_LOG:
  1544. ret = mbxCommand;
  1545. break;
  1546. default:
  1547. ret = MBX_SHUTDOWN;
  1548. break;
  1549. }
  1550. return ret;
  1551. }
  1552. /**
  1553. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1554. * @phba: Pointer to HBA context object.
  1555. * @pmboxq: Pointer to mailbox command.
  1556. *
  1557. * This is completion handler function for mailbox commands issued from
  1558. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1559. * mailbox event handler function with no lock held. This function
  1560. * will wake up thread waiting on the wait queue pointed by context1
  1561. * of the mailbox.
  1562. **/
  1563. void
  1564. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1565. {
  1566. wait_queue_head_t *pdone_q;
  1567. unsigned long drvr_flag;
  1568. /*
  1569. * If pdone_q is empty, the driver thread gave up waiting and
  1570. * continued running.
  1571. */
  1572. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1573. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1574. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1575. if (pdone_q)
  1576. wake_up_interruptible(pdone_q);
  1577. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1578. return;
  1579. }
  1580. /**
  1581. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1582. * @phba: Pointer to HBA context object.
  1583. * @pmb: Pointer to mailbox object.
  1584. *
  1585. * This function is the default mailbox completion handler. It
  1586. * frees the memory resources associated with the completed mailbox
  1587. * command. If the completed command is a REG_LOGIN mailbox command,
  1588. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1589. **/
  1590. void
  1591. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1592. {
  1593. struct lpfc_dmabuf *mp;
  1594. uint16_t rpi, vpi;
  1595. int rc;
  1596. struct lpfc_vport *vport = pmb->vport;
  1597. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1598. if (mp) {
  1599. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1600. kfree(mp);
  1601. }
  1602. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1603. (phba->sli_rev == LPFC_SLI_REV4))
  1604. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1605. /*
  1606. * If a REG_LOGIN succeeded after node is destroyed or node
  1607. * is in re-discovery driver need to cleanup the RPI.
  1608. */
  1609. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1610. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1611. !pmb->u.mb.mbxStatus) {
  1612. rpi = pmb->u.mb.un.varWords[0];
  1613. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1614. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1615. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1616. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1617. if (rc != MBX_NOT_FINISHED)
  1618. return;
  1619. }
  1620. /* Unreg VPI, if the REG_VPI succeed after VLink failure */
  1621. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1622. !(phba->pport->load_flag & FC_UNLOADING) &&
  1623. !pmb->u.mb.mbxStatus) {
  1624. lpfc_unreg_vpi(phba, pmb->u.mb.un.varRegVpi.vpi, pmb);
  1625. pmb->vport = vport;
  1626. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1627. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1628. if (rc != MBX_NOT_FINISHED)
  1629. return;
  1630. }
  1631. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1632. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1633. else
  1634. mempool_free(pmb, phba->mbox_mem_pool);
  1635. }
  1636. /**
  1637. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1638. * @phba: Pointer to HBA context object.
  1639. *
  1640. * This function is called with no lock held. This function processes all
  1641. * the completed mailbox commands and gives it to upper layers. The interrupt
  1642. * service routine processes mailbox completion interrupt and adds completed
  1643. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1644. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1645. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1646. * function returns the mailbox commands to the upper layer by calling the
  1647. * completion handler function of each mailbox.
  1648. **/
  1649. int
  1650. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1651. {
  1652. MAILBOX_t *pmbox;
  1653. LPFC_MBOXQ_t *pmb;
  1654. int rc;
  1655. LIST_HEAD(cmplq);
  1656. phba->sli.slistat.mbox_event++;
  1657. /* Get all completed mailboxe buffers into the cmplq */
  1658. spin_lock_irq(&phba->hbalock);
  1659. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1660. spin_unlock_irq(&phba->hbalock);
  1661. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1662. do {
  1663. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1664. if (pmb == NULL)
  1665. break;
  1666. pmbox = &pmb->u.mb;
  1667. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1668. if (pmb->vport) {
  1669. lpfc_debugfs_disc_trc(pmb->vport,
  1670. LPFC_DISC_TRC_MBOX_VPORT,
  1671. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1672. (uint32_t)pmbox->mbxCommand,
  1673. pmbox->un.varWords[0],
  1674. pmbox->un.varWords[1]);
  1675. }
  1676. else {
  1677. lpfc_debugfs_disc_trc(phba->pport,
  1678. LPFC_DISC_TRC_MBOX,
  1679. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1680. (uint32_t)pmbox->mbxCommand,
  1681. pmbox->un.varWords[0],
  1682. pmbox->un.varWords[1]);
  1683. }
  1684. }
  1685. /*
  1686. * It is a fatal error if unknown mbox command completion.
  1687. */
  1688. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1689. MBX_SHUTDOWN) {
  1690. /* Unknown mailbox command compl */
  1691. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1692. "(%d):0323 Unknown Mailbox command "
  1693. "x%x (x%x) Cmpl\n",
  1694. pmb->vport ? pmb->vport->vpi : 0,
  1695. pmbox->mbxCommand,
  1696. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1697. phba->link_state = LPFC_HBA_ERROR;
  1698. phba->work_hs = HS_FFER3;
  1699. lpfc_handle_eratt(phba);
  1700. continue;
  1701. }
  1702. if (pmbox->mbxStatus) {
  1703. phba->sli.slistat.mbox_stat_err++;
  1704. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1705. /* Mbox cmd cmpl error - RETRYing */
  1706. lpfc_printf_log(phba, KERN_INFO,
  1707. LOG_MBOX | LOG_SLI,
  1708. "(%d):0305 Mbox cmd cmpl "
  1709. "error - RETRYing Data: x%x "
  1710. "(x%x) x%x x%x x%x\n",
  1711. pmb->vport ? pmb->vport->vpi :0,
  1712. pmbox->mbxCommand,
  1713. lpfc_sli4_mbox_opcode_get(phba,
  1714. pmb),
  1715. pmbox->mbxStatus,
  1716. pmbox->un.varWords[0],
  1717. pmb->vport->port_state);
  1718. pmbox->mbxStatus = 0;
  1719. pmbox->mbxOwner = OWN_HOST;
  1720. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1721. if (rc != MBX_NOT_FINISHED)
  1722. continue;
  1723. }
  1724. }
  1725. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1726. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1727. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1728. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1729. pmb->vport ? pmb->vport->vpi : 0,
  1730. pmbox->mbxCommand,
  1731. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1732. pmb->mbox_cmpl,
  1733. *((uint32_t *) pmbox),
  1734. pmbox->un.varWords[0],
  1735. pmbox->un.varWords[1],
  1736. pmbox->un.varWords[2],
  1737. pmbox->un.varWords[3],
  1738. pmbox->un.varWords[4],
  1739. pmbox->un.varWords[5],
  1740. pmbox->un.varWords[6],
  1741. pmbox->un.varWords[7]);
  1742. if (pmb->mbox_cmpl)
  1743. pmb->mbox_cmpl(phba,pmb);
  1744. } while (1);
  1745. return 0;
  1746. }
  1747. /**
  1748. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1749. * @phba: Pointer to HBA context object.
  1750. * @pring: Pointer to driver SLI ring object.
  1751. * @tag: buffer tag.
  1752. *
  1753. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1754. * is set in the tag the buffer is posted for a particular exchange,
  1755. * the function will return the buffer without replacing the buffer.
  1756. * If the buffer is for unsolicited ELS or CT traffic, this function
  1757. * returns the buffer and also posts another buffer to the firmware.
  1758. **/
  1759. static struct lpfc_dmabuf *
  1760. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1761. struct lpfc_sli_ring *pring,
  1762. uint32_t tag)
  1763. {
  1764. struct hbq_dmabuf *hbq_entry;
  1765. if (tag & QUE_BUFTAG_BIT)
  1766. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1767. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1768. if (!hbq_entry)
  1769. return NULL;
  1770. return &hbq_entry->dbuf;
  1771. }
  1772. /**
  1773. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1774. * @phba: Pointer to HBA context object.
  1775. * @pring: Pointer to driver SLI ring object.
  1776. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1777. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1778. * @fch_type: the type for the first frame of the sequence.
  1779. *
  1780. * This function is called with no lock held. This function uses the r_ctl and
  1781. * type of the received sequence to find the correct callback function to call
  1782. * to process the sequence.
  1783. **/
  1784. static int
  1785. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1786. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1787. uint32_t fch_type)
  1788. {
  1789. int i;
  1790. /* unSolicited Responses */
  1791. if (pring->prt[0].profile) {
  1792. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1793. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1794. saveq);
  1795. return 1;
  1796. }
  1797. /* We must search, based on rctl / type
  1798. for the right routine */
  1799. for (i = 0; i < pring->num_mask; i++) {
  1800. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1801. (pring->prt[i].type == fch_type)) {
  1802. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1803. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1804. (phba, pring, saveq);
  1805. return 1;
  1806. }
  1807. }
  1808. return 0;
  1809. }
  1810. /**
  1811. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1812. * @phba: Pointer to HBA context object.
  1813. * @pring: Pointer to driver SLI ring object.
  1814. * @saveq: Pointer to the unsolicited iocb.
  1815. *
  1816. * This function is called with no lock held by the ring event handler
  1817. * when there is an unsolicited iocb posted to the response ring by the
  1818. * firmware. This function gets the buffer associated with the iocbs
  1819. * and calls the event handler for the ring. This function handles both
  1820. * qring buffers and hbq buffers.
  1821. * When the function returns 1 the caller can free the iocb object otherwise
  1822. * upper layer functions will free the iocb objects.
  1823. **/
  1824. static int
  1825. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1826. struct lpfc_iocbq *saveq)
  1827. {
  1828. IOCB_t * irsp;
  1829. WORD5 * w5p;
  1830. uint32_t Rctl, Type;
  1831. uint32_t match;
  1832. struct lpfc_iocbq *iocbq;
  1833. struct lpfc_dmabuf *dmzbuf;
  1834. match = 0;
  1835. irsp = &(saveq->iocb);
  1836. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1837. if (pring->lpfc_sli_rcv_async_status)
  1838. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1839. else
  1840. lpfc_printf_log(phba,
  1841. KERN_WARNING,
  1842. LOG_SLI,
  1843. "0316 Ring %d handler: unexpected "
  1844. "ASYNC_STATUS iocb received evt_code "
  1845. "0x%x\n",
  1846. pring->ringno,
  1847. irsp->un.asyncstat.evt_code);
  1848. return 1;
  1849. }
  1850. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1851. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1852. if (irsp->ulpBdeCount > 0) {
  1853. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1854. irsp->un.ulpWord[3]);
  1855. lpfc_in_buf_free(phba, dmzbuf);
  1856. }
  1857. if (irsp->ulpBdeCount > 1) {
  1858. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1859. irsp->unsli3.sli3Words[3]);
  1860. lpfc_in_buf_free(phba, dmzbuf);
  1861. }
  1862. if (irsp->ulpBdeCount > 2) {
  1863. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1864. irsp->unsli3.sli3Words[7]);
  1865. lpfc_in_buf_free(phba, dmzbuf);
  1866. }
  1867. return 1;
  1868. }
  1869. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1870. if (irsp->ulpBdeCount != 0) {
  1871. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1872. irsp->un.ulpWord[3]);
  1873. if (!saveq->context2)
  1874. lpfc_printf_log(phba,
  1875. KERN_ERR,
  1876. LOG_SLI,
  1877. "0341 Ring %d Cannot find buffer for "
  1878. "an unsolicited iocb. tag 0x%x\n",
  1879. pring->ringno,
  1880. irsp->un.ulpWord[3]);
  1881. }
  1882. if (irsp->ulpBdeCount == 2) {
  1883. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1884. irsp->unsli3.sli3Words[7]);
  1885. if (!saveq->context3)
  1886. lpfc_printf_log(phba,
  1887. KERN_ERR,
  1888. LOG_SLI,
  1889. "0342 Ring %d Cannot find buffer for an"
  1890. " unsolicited iocb. tag 0x%x\n",
  1891. pring->ringno,
  1892. irsp->unsli3.sli3Words[7]);
  1893. }
  1894. list_for_each_entry(iocbq, &saveq->list, list) {
  1895. irsp = &(iocbq->iocb);
  1896. if (irsp->ulpBdeCount != 0) {
  1897. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1898. irsp->un.ulpWord[3]);
  1899. if (!iocbq->context2)
  1900. lpfc_printf_log(phba,
  1901. KERN_ERR,
  1902. LOG_SLI,
  1903. "0343 Ring %d Cannot find "
  1904. "buffer for an unsolicited iocb"
  1905. ". tag 0x%x\n", pring->ringno,
  1906. irsp->un.ulpWord[3]);
  1907. }
  1908. if (irsp->ulpBdeCount == 2) {
  1909. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1910. irsp->unsli3.sli3Words[7]);
  1911. if (!iocbq->context3)
  1912. lpfc_printf_log(phba,
  1913. KERN_ERR,
  1914. LOG_SLI,
  1915. "0344 Ring %d Cannot find "
  1916. "buffer for an unsolicited "
  1917. "iocb. tag 0x%x\n",
  1918. pring->ringno,
  1919. irsp->unsli3.sli3Words[7]);
  1920. }
  1921. }
  1922. }
  1923. if (irsp->ulpBdeCount != 0 &&
  1924. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1925. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1926. int found = 0;
  1927. /* search continue save q for same XRI */
  1928. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1929. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1930. list_add_tail(&saveq->list, &iocbq->list);
  1931. found = 1;
  1932. break;
  1933. }
  1934. }
  1935. if (!found)
  1936. list_add_tail(&saveq->clist,
  1937. &pring->iocb_continue_saveq);
  1938. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1939. list_del_init(&iocbq->clist);
  1940. saveq = iocbq;
  1941. irsp = &(saveq->iocb);
  1942. } else
  1943. return 0;
  1944. }
  1945. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1946. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1947. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1948. Rctl = FC_RCTL_ELS_REQ;
  1949. Type = FC_TYPE_ELS;
  1950. } else {
  1951. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1952. Rctl = w5p->hcsw.Rctl;
  1953. Type = w5p->hcsw.Type;
  1954. /* Firmware Workaround */
  1955. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1956. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1957. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1958. Rctl = FC_RCTL_ELS_REQ;
  1959. Type = FC_TYPE_ELS;
  1960. w5p->hcsw.Rctl = Rctl;
  1961. w5p->hcsw.Type = Type;
  1962. }
  1963. }
  1964. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1965. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1966. "0313 Ring %d handler: unexpected Rctl x%x "
  1967. "Type x%x received\n",
  1968. pring->ringno, Rctl, Type);
  1969. return 1;
  1970. }
  1971. /**
  1972. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1973. * @phba: Pointer to HBA context object.
  1974. * @pring: Pointer to driver SLI ring object.
  1975. * @prspiocb: Pointer to response iocb object.
  1976. *
  1977. * This function looks up the iocb_lookup table to get the command iocb
  1978. * corresponding to the given response iocb using the iotag of the
  1979. * response iocb. This function is called with the hbalock held.
  1980. * This function returns the command iocb object if it finds the command
  1981. * iocb else returns NULL.
  1982. **/
  1983. static struct lpfc_iocbq *
  1984. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1985. struct lpfc_sli_ring *pring,
  1986. struct lpfc_iocbq *prspiocb)
  1987. {
  1988. struct lpfc_iocbq *cmd_iocb = NULL;
  1989. uint16_t iotag;
  1990. iotag = prspiocb->iocb.ulpIoTag;
  1991. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1992. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1993. list_del_init(&cmd_iocb->list);
  1994. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  1995. pring->txcmplq_cnt--;
  1996. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  1997. }
  1998. return cmd_iocb;
  1999. }
  2000. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2001. "0317 iotag x%x is out off "
  2002. "range: max iotag x%x wd0 x%x\n",
  2003. iotag, phba->sli.last_iotag,
  2004. *(((uint32_t *) &prspiocb->iocb) + 7));
  2005. return NULL;
  2006. }
  2007. /**
  2008. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2009. * @phba: Pointer to HBA context object.
  2010. * @pring: Pointer to driver SLI ring object.
  2011. * @iotag: IOCB tag.
  2012. *
  2013. * This function looks up the iocb_lookup table to get the command iocb
  2014. * corresponding to the given iotag. This function is called with the
  2015. * hbalock held.
  2016. * This function returns the command iocb object if it finds the command
  2017. * iocb else returns NULL.
  2018. **/
  2019. static struct lpfc_iocbq *
  2020. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2021. struct lpfc_sli_ring *pring, uint16_t iotag)
  2022. {
  2023. struct lpfc_iocbq *cmd_iocb;
  2024. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2025. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2026. list_del_init(&cmd_iocb->list);
  2027. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2028. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2029. pring->txcmplq_cnt--;
  2030. }
  2031. return cmd_iocb;
  2032. }
  2033. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2034. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2035. iotag, phba->sli.last_iotag);
  2036. return NULL;
  2037. }
  2038. /**
  2039. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2040. * @phba: Pointer to HBA context object.
  2041. * @pring: Pointer to driver SLI ring object.
  2042. * @saveq: Pointer to the response iocb to be processed.
  2043. *
  2044. * This function is called by the ring event handler for non-fcp
  2045. * rings when there is a new response iocb in the response ring.
  2046. * The caller is not required to hold any locks. This function
  2047. * gets the command iocb associated with the response iocb and
  2048. * calls the completion handler for the command iocb. If there
  2049. * is no completion handler, the function will free the resources
  2050. * associated with command iocb. If the response iocb is for
  2051. * an already aborted command iocb, the status of the completion
  2052. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2053. * This function always returns 1.
  2054. **/
  2055. static int
  2056. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2057. struct lpfc_iocbq *saveq)
  2058. {
  2059. struct lpfc_iocbq *cmdiocbp;
  2060. int rc = 1;
  2061. unsigned long iflag;
  2062. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2063. spin_lock_irqsave(&phba->hbalock, iflag);
  2064. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2065. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2066. if (cmdiocbp) {
  2067. if (cmdiocbp->iocb_cmpl) {
  2068. /*
  2069. * If an ELS command failed send an event to mgmt
  2070. * application.
  2071. */
  2072. if (saveq->iocb.ulpStatus &&
  2073. (pring->ringno == LPFC_ELS_RING) &&
  2074. (cmdiocbp->iocb.ulpCommand ==
  2075. CMD_ELS_REQUEST64_CR))
  2076. lpfc_send_els_failure_event(phba,
  2077. cmdiocbp, saveq);
  2078. /*
  2079. * Post all ELS completions to the worker thread.
  2080. * All other are passed to the completion callback.
  2081. */
  2082. if (pring->ringno == LPFC_ELS_RING) {
  2083. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2084. (cmdiocbp->iocb_flag &
  2085. LPFC_DRIVER_ABORTED)) {
  2086. spin_lock_irqsave(&phba->hbalock,
  2087. iflag);
  2088. cmdiocbp->iocb_flag &=
  2089. ~LPFC_DRIVER_ABORTED;
  2090. spin_unlock_irqrestore(&phba->hbalock,
  2091. iflag);
  2092. saveq->iocb.ulpStatus =
  2093. IOSTAT_LOCAL_REJECT;
  2094. saveq->iocb.un.ulpWord[4] =
  2095. IOERR_SLI_ABORTED;
  2096. /* Firmware could still be in progress
  2097. * of DMAing payload, so don't free data
  2098. * buffer till after a hbeat.
  2099. */
  2100. spin_lock_irqsave(&phba->hbalock,
  2101. iflag);
  2102. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2103. spin_unlock_irqrestore(&phba->hbalock,
  2104. iflag);
  2105. }
  2106. if (phba->sli_rev == LPFC_SLI_REV4) {
  2107. if (saveq->iocb_flag &
  2108. LPFC_EXCHANGE_BUSY) {
  2109. /* Set cmdiocb flag for the
  2110. * exchange busy so sgl (xri)
  2111. * will not be released until
  2112. * the abort xri is received
  2113. * from hba.
  2114. */
  2115. spin_lock_irqsave(
  2116. &phba->hbalock, iflag);
  2117. cmdiocbp->iocb_flag |=
  2118. LPFC_EXCHANGE_BUSY;
  2119. spin_unlock_irqrestore(
  2120. &phba->hbalock, iflag);
  2121. }
  2122. if (cmdiocbp->iocb_flag &
  2123. LPFC_DRIVER_ABORTED) {
  2124. /*
  2125. * Clear LPFC_DRIVER_ABORTED
  2126. * bit in case it was driver
  2127. * initiated abort.
  2128. */
  2129. spin_lock_irqsave(
  2130. &phba->hbalock, iflag);
  2131. cmdiocbp->iocb_flag &=
  2132. ~LPFC_DRIVER_ABORTED;
  2133. spin_unlock_irqrestore(
  2134. &phba->hbalock, iflag);
  2135. cmdiocbp->iocb.ulpStatus =
  2136. IOSTAT_LOCAL_REJECT;
  2137. cmdiocbp->iocb.un.ulpWord[4] =
  2138. IOERR_ABORT_REQUESTED;
  2139. /*
  2140. * For SLI4, irsiocb contains
  2141. * NO_XRI in sli_xritag, it
  2142. * shall not affect releasing
  2143. * sgl (xri) process.
  2144. */
  2145. saveq->iocb.ulpStatus =
  2146. IOSTAT_LOCAL_REJECT;
  2147. saveq->iocb.un.ulpWord[4] =
  2148. IOERR_SLI_ABORTED;
  2149. spin_lock_irqsave(
  2150. &phba->hbalock, iflag);
  2151. saveq->iocb_flag |=
  2152. LPFC_DELAY_MEM_FREE;
  2153. spin_unlock_irqrestore(
  2154. &phba->hbalock, iflag);
  2155. }
  2156. }
  2157. }
  2158. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2159. } else
  2160. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2161. } else {
  2162. /*
  2163. * Unknown initiating command based on the response iotag.
  2164. * This could be the case on the ELS ring because of
  2165. * lpfc_els_abort().
  2166. */
  2167. if (pring->ringno != LPFC_ELS_RING) {
  2168. /*
  2169. * Ring <ringno> handler: unexpected completion IoTag
  2170. * <IoTag>
  2171. */
  2172. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2173. "0322 Ring %d handler: "
  2174. "unexpected completion IoTag x%x "
  2175. "Data: x%x x%x x%x x%x\n",
  2176. pring->ringno,
  2177. saveq->iocb.ulpIoTag,
  2178. saveq->iocb.ulpStatus,
  2179. saveq->iocb.un.ulpWord[4],
  2180. saveq->iocb.ulpCommand,
  2181. saveq->iocb.ulpContext);
  2182. }
  2183. }
  2184. return rc;
  2185. }
  2186. /**
  2187. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2188. * @phba: Pointer to HBA context object.
  2189. * @pring: Pointer to driver SLI ring object.
  2190. *
  2191. * This function is called from the iocb ring event handlers when
  2192. * put pointer is ahead of the get pointer for a ring. This function signal
  2193. * an error attention condition to the worker thread and the worker
  2194. * thread will transition the HBA to offline state.
  2195. **/
  2196. static void
  2197. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2198. {
  2199. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2200. /*
  2201. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2202. * rsp ring <portRspMax>
  2203. */
  2204. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2205. "0312 Ring %d handler: portRspPut %d "
  2206. "is bigger than rsp ring %d\n",
  2207. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2208. pring->numRiocb);
  2209. phba->link_state = LPFC_HBA_ERROR;
  2210. /*
  2211. * All error attention handlers are posted to
  2212. * worker thread
  2213. */
  2214. phba->work_ha |= HA_ERATT;
  2215. phba->work_hs = HS_FFER3;
  2216. lpfc_worker_wake_up(phba);
  2217. return;
  2218. }
  2219. /**
  2220. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2221. * @ptr: Pointer to address of HBA context object.
  2222. *
  2223. * This function is invoked by the Error Attention polling timer when the
  2224. * timer times out. It will check the SLI Error Attention register for
  2225. * possible attention events. If so, it will post an Error Attention event
  2226. * and wake up worker thread to process it. Otherwise, it will set up the
  2227. * Error Attention polling timer for the next poll.
  2228. **/
  2229. void lpfc_poll_eratt(unsigned long ptr)
  2230. {
  2231. struct lpfc_hba *phba;
  2232. uint32_t eratt = 0;
  2233. phba = (struct lpfc_hba *)ptr;
  2234. /* Check chip HA register for error event */
  2235. eratt = lpfc_sli_check_eratt(phba);
  2236. if (eratt)
  2237. /* Tell the worker thread there is work to do */
  2238. lpfc_worker_wake_up(phba);
  2239. else
  2240. /* Restart the timer for next eratt poll */
  2241. mod_timer(&phba->eratt_poll, jiffies +
  2242. HZ * LPFC_ERATT_POLL_INTERVAL);
  2243. return;
  2244. }
  2245. /**
  2246. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2247. * @phba: Pointer to HBA context object.
  2248. * @pring: Pointer to driver SLI ring object.
  2249. * @mask: Host attention register mask for this ring.
  2250. *
  2251. * This function is called from the interrupt context when there is a ring
  2252. * event for the fcp ring. The caller does not hold any lock.
  2253. * The function processes each response iocb in the response ring until it
  2254. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2255. * LE bit set. The function will call the completion handler of the command iocb
  2256. * if the response iocb indicates a completion for a command iocb or it is
  2257. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2258. * function if this is an unsolicited iocb.
  2259. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2260. * to check it explicitly.
  2261. */
  2262. int
  2263. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2264. struct lpfc_sli_ring *pring, uint32_t mask)
  2265. {
  2266. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2267. IOCB_t *irsp = NULL;
  2268. IOCB_t *entry = NULL;
  2269. struct lpfc_iocbq *cmdiocbq = NULL;
  2270. struct lpfc_iocbq rspiocbq;
  2271. uint32_t status;
  2272. uint32_t portRspPut, portRspMax;
  2273. int rc = 1;
  2274. lpfc_iocb_type type;
  2275. unsigned long iflag;
  2276. uint32_t rsp_cmpl = 0;
  2277. spin_lock_irqsave(&phba->hbalock, iflag);
  2278. pring->stats.iocb_event++;
  2279. /*
  2280. * The next available response entry should never exceed the maximum
  2281. * entries. If it does, treat it as an adapter hardware error.
  2282. */
  2283. portRspMax = pring->numRiocb;
  2284. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2285. if (unlikely(portRspPut >= portRspMax)) {
  2286. lpfc_sli_rsp_pointers_error(phba, pring);
  2287. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2288. return 1;
  2289. }
  2290. if (phba->fcp_ring_in_use) {
  2291. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2292. return 1;
  2293. } else
  2294. phba->fcp_ring_in_use = 1;
  2295. rmb();
  2296. while (pring->rspidx != portRspPut) {
  2297. /*
  2298. * Fetch an entry off the ring and copy it into a local data
  2299. * structure. The copy involves a byte-swap since the
  2300. * network byte order and pci byte orders are different.
  2301. */
  2302. entry = lpfc_resp_iocb(phba, pring);
  2303. phba->last_completion_time = jiffies;
  2304. if (++pring->rspidx >= portRspMax)
  2305. pring->rspidx = 0;
  2306. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2307. (uint32_t *) &rspiocbq.iocb,
  2308. phba->iocb_rsp_size);
  2309. INIT_LIST_HEAD(&(rspiocbq.list));
  2310. irsp = &rspiocbq.iocb;
  2311. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2312. pring->stats.iocb_rsp++;
  2313. rsp_cmpl++;
  2314. if (unlikely(irsp->ulpStatus)) {
  2315. /*
  2316. * If resource errors reported from HBA, reduce
  2317. * queuedepths of the SCSI device.
  2318. */
  2319. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2320. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2321. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2322. phba->lpfc_rampdown_queue_depth(phba);
  2323. spin_lock_irqsave(&phba->hbalock, iflag);
  2324. }
  2325. /* Rsp ring <ringno> error: IOCB */
  2326. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2327. "0336 Rsp Ring %d error: IOCB Data: "
  2328. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2329. pring->ringno,
  2330. irsp->un.ulpWord[0],
  2331. irsp->un.ulpWord[1],
  2332. irsp->un.ulpWord[2],
  2333. irsp->un.ulpWord[3],
  2334. irsp->un.ulpWord[4],
  2335. irsp->un.ulpWord[5],
  2336. *(uint32_t *)&irsp->un1,
  2337. *((uint32_t *)&irsp->un1 + 1));
  2338. }
  2339. switch (type) {
  2340. case LPFC_ABORT_IOCB:
  2341. case LPFC_SOL_IOCB:
  2342. /*
  2343. * Idle exchange closed via ABTS from port. No iocb
  2344. * resources need to be recovered.
  2345. */
  2346. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2347. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2348. "0333 IOCB cmd 0x%x"
  2349. " processed. Skipping"
  2350. " completion\n",
  2351. irsp->ulpCommand);
  2352. break;
  2353. }
  2354. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2355. &rspiocbq);
  2356. if (unlikely(!cmdiocbq))
  2357. break;
  2358. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2359. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2360. if (cmdiocbq->iocb_cmpl) {
  2361. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2362. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2363. &rspiocbq);
  2364. spin_lock_irqsave(&phba->hbalock, iflag);
  2365. }
  2366. break;
  2367. case LPFC_UNSOL_IOCB:
  2368. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2369. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2370. spin_lock_irqsave(&phba->hbalock, iflag);
  2371. break;
  2372. default:
  2373. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2374. char adaptermsg[LPFC_MAX_ADPTMSG];
  2375. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2376. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2377. MAX_MSG_DATA);
  2378. dev_warn(&((phba->pcidev)->dev),
  2379. "lpfc%d: %s\n",
  2380. phba->brd_no, adaptermsg);
  2381. } else {
  2382. /* Unknown IOCB command */
  2383. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2384. "0334 Unknown IOCB command "
  2385. "Data: x%x, x%x x%x x%x x%x\n",
  2386. type, irsp->ulpCommand,
  2387. irsp->ulpStatus,
  2388. irsp->ulpIoTag,
  2389. irsp->ulpContext);
  2390. }
  2391. break;
  2392. }
  2393. /*
  2394. * The response IOCB has been processed. Update the ring
  2395. * pointer in SLIM. If the port response put pointer has not
  2396. * been updated, sync the pgp->rspPutInx and fetch the new port
  2397. * response put pointer.
  2398. */
  2399. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2400. if (pring->rspidx == portRspPut)
  2401. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2402. }
  2403. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2404. pring->stats.iocb_rsp_full++;
  2405. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2406. writel(status, phba->CAregaddr);
  2407. readl(phba->CAregaddr);
  2408. }
  2409. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2410. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2411. pring->stats.iocb_cmd_empty++;
  2412. /* Force update of the local copy of cmdGetInx */
  2413. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2414. lpfc_sli_resume_iocb(phba, pring);
  2415. if ((pring->lpfc_sli_cmd_available))
  2416. (pring->lpfc_sli_cmd_available) (phba, pring);
  2417. }
  2418. phba->fcp_ring_in_use = 0;
  2419. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2420. return rc;
  2421. }
  2422. /**
  2423. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2424. * @phba: Pointer to HBA context object.
  2425. * @pring: Pointer to driver SLI ring object.
  2426. * @rspiocbp: Pointer to driver response IOCB object.
  2427. *
  2428. * This function is called from the worker thread when there is a slow-path
  2429. * response IOCB to process. This function chains all the response iocbs until
  2430. * seeing the iocb with the LE bit set. The function will call
  2431. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2432. * completion of a command iocb. The function will call the
  2433. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2434. * The function frees the resources or calls the completion handler if this
  2435. * iocb is an abort completion. The function returns NULL when the response
  2436. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2437. * this function shall chain the iocb on to the iocb_continueq and return the
  2438. * response iocb passed in.
  2439. **/
  2440. static struct lpfc_iocbq *
  2441. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2442. struct lpfc_iocbq *rspiocbp)
  2443. {
  2444. struct lpfc_iocbq *saveq;
  2445. struct lpfc_iocbq *cmdiocbp;
  2446. struct lpfc_iocbq *next_iocb;
  2447. IOCB_t *irsp = NULL;
  2448. uint32_t free_saveq;
  2449. uint8_t iocb_cmd_type;
  2450. lpfc_iocb_type type;
  2451. unsigned long iflag;
  2452. int rc;
  2453. spin_lock_irqsave(&phba->hbalock, iflag);
  2454. /* First add the response iocb to the countinueq list */
  2455. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2456. pring->iocb_continueq_cnt++;
  2457. /* Now, determine whetehr the list is completed for processing */
  2458. irsp = &rspiocbp->iocb;
  2459. if (irsp->ulpLe) {
  2460. /*
  2461. * By default, the driver expects to free all resources
  2462. * associated with this iocb completion.
  2463. */
  2464. free_saveq = 1;
  2465. saveq = list_get_first(&pring->iocb_continueq,
  2466. struct lpfc_iocbq, list);
  2467. irsp = &(saveq->iocb);
  2468. list_del_init(&pring->iocb_continueq);
  2469. pring->iocb_continueq_cnt = 0;
  2470. pring->stats.iocb_rsp++;
  2471. /*
  2472. * If resource errors reported from HBA, reduce
  2473. * queuedepths of the SCSI device.
  2474. */
  2475. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2476. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2477. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2478. phba->lpfc_rampdown_queue_depth(phba);
  2479. spin_lock_irqsave(&phba->hbalock, iflag);
  2480. }
  2481. if (irsp->ulpStatus) {
  2482. /* Rsp ring <ringno> error: IOCB */
  2483. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2484. "0328 Rsp Ring %d error: "
  2485. "IOCB Data: "
  2486. "x%x x%x x%x x%x "
  2487. "x%x x%x x%x x%x "
  2488. "x%x x%x x%x x%x "
  2489. "x%x x%x x%x x%x\n",
  2490. pring->ringno,
  2491. irsp->un.ulpWord[0],
  2492. irsp->un.ulpWord[1],
  2493. irsp->un.ulpWord[2],
  2494. irsp->un.ulpWord[3],
  2495. irsp->un.ulpWord[4],
  2496. irsp->un.ulpWord[5],
  2497. *(((uint32_t *) irsp) + 6),
  2498. *(((uint32_t *) irsp) + 7),
  2499. *(((uint32_t *) irsp) + 8),
  2500. *(((uint32_t *) irsp) + 9),
  2501. *(((uint32_t *) irsp) + 10),
  2502. *(((uint32_t *) irsp) + 11),
  2503. *(((uint32_t *) irsp) + 12),
  2504. *(((uint32_t *) irsp) + 13),
  2505. *(((uint32_t *) irsp) + 14),
  2506. *(((uint32_t *) irsp) + 15));
  2507. }
  2508. /*
  2509. * Fetch the IOCB command type and call the correct completion
  2510. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2511. * get freed back to the lpfc_iocb_list by the discovery
  2512. * kernel thread.
  2513. */
  2514. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2515. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2516. switch (type) {
  2517. case LPFC_SOL_IOCB:
  2518. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2519. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2520. spin_lock_irqsave(&phba->hbalock, iflag);
  2521. break;
  2522. case LPFC_UNSOL_IOCB:
  2523. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2524. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2525. spin_lock_irqsave(&phba->hbalock, iflag);
  2526. if (!rc)
  2527. free_saveq = 0;
  2528. break;
  2529. case LPFC_ABORT_IOCB:
  2530. cmdiocbp = NULL;
  2531. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2532. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2533. saveq);
  2534. if (cmdiocbp) {
  2535. /* Call the specified completion routine */
  2536. if (cmdiocbp->iocb_cmpl) {
  2537. spin_unlock_irqrestore(&phba->hbalock,
  2538. iflag);
  2539. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2540. saveq);
  2541. spin_lock_irqsave(&phba->hbalock,
  2542. iflag);
  2543. } else
  2544. __lpfc_sli_release_iocbq(phba,
  2545. cmdiocbp);
  2546. }
  2547. break;
  2548. case LPFC_UNKNOWN_IOCB:
  2549. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2550. char adaptermsg[LPFC_MAX_ADPTMSG];
  2551. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2552. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2553. MAX_MSG_DATA);
  2554. dev_warn(&((phba->pcidev)->dev),
  2555. "lpfc%d: %s\n",
  2556. phba->brd_no, adaptermsg);
  2557. } else {
  2558. /* Unknown IOCB command */
  2559. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2560. "0335 Unknown IOCB "
  2561. "command Data: x%x "
  2562. "x%x x%x x%x\n",
  2563. irsp->ulpCommand,
  2564. irsp->ulpStatus,
  2565. irsp->ulpIoTag,
  2566. irsp->ulpContext);
  2567. }
  2568. break;
  2569. }
  2570. if (free_saveq) {
  2571. list_for_each_entry_safe(rspiocbp, next_iocb,
  2572. &saveq->list, list) {
  2573. list_del(&rspiocbp->list);
  2574. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2575. }
  2576. __lpfc_sli_release_iocbq(phba, saveq);
  2577. }
  2578. rspiocbp = NULL;
  2579. }
  2580. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2581. return rspiocbp;
  2582. }
  2583. /**
  2584. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2585. * @phba: Pointer to HBA context object.
  2586. * @pring: Pointer to driver SLI ring object.
  2587. * @mask: Host attention register mask for this ring.
  2588. *
  2589. * This routine wraps the actual slow_ring event process routine from the
  2590. * API jump table function pointer from the lpfc_hba struct.
  2591. **/
  2592. void
  2593. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2594. struct lpfc_sli_ring *pring, uint32_t mask)
  2595. {
  2596. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2597. }
  2598. /**
  2599. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2600. * @phba: Pointer to HBA context object.
  2601. * @pring: Pointer to driver SLI ring object.
  2602. * @mask: Host attention register mask for this ring.
  2603. *
  2604. * This function is called from the worker thread when there is a ring event
  2605. * for non-fcp rings. The caller does not hold any lock. The function will
  2606. * remove each response iocb in the response ring and calls the handle
  2607. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2608. **/
  2609. static void
  2610. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2611. struct lpfc_sli_ring *pring, uint32_t mask)
  2612. {
  2613. struct lpfc_pgp *pgp;
  2614. IOCB_t *entry;
  2615. IOCB_t *irsp = NULL;
  2616. struct lpfc_iocbq *rspiocbp = NULL;
  2617. uint32_t portRspPut, portRspMax;
  2618. unsigned long iflag;
  2619. uint32_t status;
  2620. pgp = &phba->port_gp[pring->ringno];
  2621. spin_lock_irqsave(&phba->hbalock, iflag);
  2622. pring->stats.iocb_event++;
  2623. /*
  2624. * The next available response entry should never exceed the maximum
  2625. * entries. If it does, treat it as an adapter hardware error.
  2626. */
  2627. portRspMax = pring->numRiocb;
  2628. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2629. if (portRspPut >= portRspMax) {
  2630. /*
  2631. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2632. * rsp ring <portRspMax>
  2633. */
  2634. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2635. "0303 Ring %d handler: portRspPut %d "
  2636. "is bigger than rsp ring %d\n",
  2637. pring->ringno, portRspPut, portRspMax);
  2638. phba->link_state = LPFC_HBA_ERROR;
  2639. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2640. phba->work_hs = HS_FFER3;
  2641. lpfc_handle_eratt(phba);
  2642. return;
  2643. }
  2644. rmb();
  2645. while (pring->rspidx != portRspPut) {
  2646. /*
  2647. * Build a completion list and call the appropriate handler.
  2648. * The process is to get the next available response iocb, get
  2649. * a free iocb from the list, copy the response data into the
  2650. * free iocb, insert to the continuation list, and update the
  2651. * next response index to slim. This process makes response
  2652. * iocb's in the ring available to DMA as fast as possible but
  2653. * pays a penalty for a copy operation. Since the iocb is
  2654. * only 32 bytes, this penalty is considered small relative to
  2655. * the PCI reads for register values and a slim write. When
  2656. * the ulpLe field is set, the entire Command has been
  2657. * received.
  2658. */
  2659. entry = lpfc_resp_iocb(phba, pring);
  2660. phba->last_completion_time = jiffies;
  2661. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2662. if (rspiocbp == NULL) {
  2663. printk(KERN_ERR "%s: out of buffers! Failing "
  2664. "completion.\n", __func__);
  2665. break;
  2666. }
  2667. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2668. phba->iocb_rsp_size);
  2669. irsp = &rspiocbp->iocb;
  2670. if (++pring->rspidx >= portRspMax)
  2671. pring->rspidx = 0;
  2672. if (pring->ringno == LPFC_ELS_RING) {
  2673. lpfc_debugfs_slow_ring_trc(phba,
  2674. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2675. *(((uint32_t *) irsp) + 4),
  2676. *(((uint32_t *) irsp) + 6),
  2677. *(((uint32_t *) irsp) + 7));
  2678. }
  2679. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2680. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2681. /* Handle the response IOCB */
  2682. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2683. spin_lock_irqsave(&phba->hbalock, iflag);
  2684. /*
  2685. * If the port response put pointer has not been updated, sync
  2686. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2687. * response put pointer.
  2688. */
  2689. if (pring->rspidx == portRspPut) {
  2690. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2691. }
  2692. } /* while (pring->rspidx != portRspPut) */
  2693. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2694. /* At least one response entry has been freed */
  2695. pring->stats.iocb_rsp_full++;
  2696. /* SET RxRE_RSP in Chip Att register */
  2697. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2698. writel(status, phba->CAregaddr);
  2699. readl(phba->CAregaddr); /* flush */
  2700. }
  2701. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2702. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2703. pring->stats.iocb_cmd_empty++;
  2704. /* Force update of the local copy of cmdGetInx */
  2705. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2706. lpfc_sli_resume_iocb(phba, pring);
  2707. if ((pring->lpfc_sli_cmd_available))
  2708. (pring->lpfc_sli_cmd_available) (phba, pring);
  2709. }
  2710. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2711. return;
  2712. }
  2713. /**
  2714. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2715. * @phba: Pointer to HBA context object.
  2716. * @pring: Pointer to driver SLI ring object.
  2717. * @mask: Host attention register mask for this ring.
  2718. *
  2719. * This function is called from the worker thread when there is a pending
  2720. * ELS response iocb on the driver internal slow-path response iocb worker
  2721. * queue. The caller does not hold any lock. The function will remove each
  2722. * response iocb from the response worker queue and calls the handle
  2723. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2724. **/
  2725. static void
  2726. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2727. struct lpfc_sli_ring *pring, uint32_t mask)
  2728. {
  2729. struct lpfc_iocbq *irspiocbq;
  2730. struct hbq_dmabuf *dmabuf;
  2731. struct lpfc_cq_event *cq_event;
  2732. unsigned long iflag;
  2733. spin_lock_irqsave(&phba->hbalock, iflag);
  2734. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  2735. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2736. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  2737. /* Get the response iocb from the head of work queue */
  2738. spin_lock_irqsave(&phba->hbalock, iflag);
  2739. list_remove_head(&phba->sli4_hba.sp_queue_event,
  2740. cq_event, struct lpfc_cq_event, list);
  2741. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2742. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  2743. case CQE_CODE_COMPL_WQE:
  2744. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  2745. cq_event);
  2746. /* Translate ELS WCQE to response IOCBQ */
  2747. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  2748. irspiocbq);
  2749. if (irspiocbq)
  2750. lpfc_sli_sp_handle_rspiocb(phba, pring,
  2751. irspiocbq);
  2752. break;
  2753. case CQE_CODE_RECEIVE:
  2754. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  2755. cq_event);
  2756. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  2757. break;
  2758. default:
  2759. break;
  2760. }
  2761. }
  2762. }
  2763. /**
  2764. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2765. * @phba: Pointer to HBA context object.
  2766. * @pring: Pointer to driver SLI ring object.
  2767. *
  2768. * This function aborts all iocbs in the given ring and frees all the iocb
  2769. * objects in txq. This function issues an abort iocb for all the iocb commands
  2770. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2771. * the return of this function. The caller is not required to hold any locks.
  2772. **/
  2773. void
  2774. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2775. {
  2776. LIST_HEAD(completions);
  2777. struct lpfc_iocbq *iocb, *next_iocb;
  2778. if (pring->ringno == LPFC_ELS_RING) {
  2779. lpfc_fabric_abort_hba(phba);
  2780. }
  2781. /* Error everything on txq and txcmplq
  2782. * First do the txq.
  2783. */
  2784. spin_lock_irq(&phba->hbalock);
  2785. list_splice_init(&pring->txq, &completions);
  2786. pring->txq_cnt = 0;
  2787. /* Next issue ABTS for everything on the txcmplq */
  2788. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2789. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2790. spin_unlock_irq(&phba->hbalock);
  2791. /* Cancel all the IOCBs from the completions list */
  2792. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2793. IOERR_SLI_ABORTED);
  2794. }
  2795. /**
  2796. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2797. * @phba: Pointer to HBA context object.
  2798. *
  2799. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2800. * objects in txq and txcmplq. This function will not issue abort iocbs
  2801. * for all the iocb commands in txcmplq, they will just be returned with
  2802. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2803. * slot has been permanently disabled.
  2804. **/
  2805. void
  2806. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2807. {
  2808. LIST_HEAD(txq);
  2809. LIST_HEAD(txcmplq);
  2810. struct lpfc_sli *psli = &phba->sli;
  2811. struct lpfc_sli_ring *pring;
  2812. /* Currently, only one fcp ring */
  2813. pring = &psli->ring[psli->fcp_ring];
  2814. spin_lock_irq(&phba->hbalock);
  2815. /* Retrieve everything on txq */
  2816. list_splice_init(&pring->txq, &txq);
  2817. pring->txq_cnt = 0;
  2818. /* Retrieve everything on the txcmplq */
  2819. list_splice_init(&pring->txcmplq, &txcmplq);
  2820. pring->txcmplq_cnt = 0;
  2821. spin_unlock_irq(&phba->hbalock);
  2822. /* Flush the txq */
  2823. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2824. IOERR_SLI_DOWN);
  2825. /* Flush the txcmpq */
  2826. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2827. IOERR_SLI_DOWN);
  2828. }
  2829. /**
  2830. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2831. * @phba: Pointer to HBA context object.
  2832. * @mask: Bit mask to be checked.
  2833. *
  2834. * This function reads the host status register and compares
  2835. * with the provided bit mask to check if HBA completed
  2836. * the restart. This function will wait in a loop for the
  2837. * HBA to complete restart. If the HBA does not restart within
  2838. * 15 iterations, the function will reset the HBA again. The
  2839. * function returns 1 when HBA fail to restart otherwise returns
  2840. * zero.
  2841. **/
  2842. static int
  2843. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2844. {
  2845. uint32_t status;
  2846. int i = 0;
  2847. int retval = 0;
  2848. /* Read the HBA Host Status Register */
  2849. status = readl(phba->HSregaddr);
  2850. /*
  2851. * Check status register every 100ms for 5 retries, then every
  2852. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2853. * every 2.5 sec for 4.
  2854. * Break our of the loop if errors occurred during init.
  2855. */
  2856. while (((status & mask) != mask) &&
  2857. !(status & HS_FFERM) &&
  2858. i++ < 20) {
  2859. if (i <= 5)
  2860. msleep(10);
  2861. else if (i <= 10)
  2862. msleep(500);
  2863. else
  2864. msleep(2500);
  2865. if (i == 15) {
  2866. /* Do post */
  2867. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2868. lpfc_sli_brdrestart(phba);
  2869. }
  2870. /* Read the HBA Host Status Register */
  2871. status = readl(phba->HSregaddr);
  2872. }
  2873. /* Check to see if any errors occurred during init */
  2874. if ((status & HS_FFERM) || (i >= 20)) {
  2875. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2876. "2751 Adapter failed to restart, "
  2877. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  2878. status,
  2879. readl(phba->MBslimaddr + 0xa8),
  2880. readl(phba->MBslimaddr + 0xac));
  2881. phba->link_state = LPFC_HBA_ERROR;
  2882. retval = 1;
  2883. }
  2884. return retval;
  2885. }
  2886. /**
  2887. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2888. * @phba: Pointer to HBA context object.
  2889. * @mask: Bit mask to be checked.
  2890. *
  2891. * This function checks the host status register to check if HBA is
  2892. * ready. This function will wait in a loop for the HBA to be ready
  2893. * If the HBA is not ready , the function will will reset the HBA PCI
  2894. * function again. The function returns 1 when HBA fail to be ready
  2895. * otherwise returns zero.
  2896. **/
  2897. static int
  2898. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2899. {
  2900. uint32_t status;
  2901. int retval = 0;
  2902. /* Read the HBA Host Status Register */
  2903. status = lpfc_sli4_post_status_check(phba);
  2904. if (status) {
  2905. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2906. lpfc_sli_brdrestart(phba);
  2907. status = lpfc_sli4_post_status_check(phba);
  2908. }
  2909. /* Check to see if any errors occurred during init */
  2910. if (status) {
  2911. phba->link_state = LPFC_HBA_ERROR;
  2912. retval = 1;
  2913. } else
  2914. phba->sli4_hba.intr_enable = 0;
  2915. return retval;
  2916. }
  2917. /**
  2918. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2919. * @phba: Pointer to HBA context object.
  2920. * @mask: Bit mask to be checked.
  2921. *
  2922. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2923. * from the API jump table function pointer from the lpfc_hba struct.
  2924. **/
  2925. int
  2926. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2927. {
  2928. return phba->lpfc_sli_brdready(phba, mask);
  2929. }
  2930. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2931. /**
  2932. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2933. * @phba: Pointer to HBA context object.
  2934. *
  2935. * This function is called before resetting an HBA. This
  2936. * function requests HBA to quiesce DMAs before a reset.
  2937. **/
  2938. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2939. {
  2940. uint32_t __iomem *resp_buf;
  2941. uint32_t __iomem *mbox_buf;
  2942. volatile uint32_t mbox;
  2943. uint32_t hc_copy;
  2944. int i;
  2945. uint8_t hdrtype;
  2946. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2947. if (hdrtype != 0x80 ||
  2948. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2949. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2950. return;
  2951. /*
  2952. * Tell the other part of the chip to suspend temporarily all
  2953. * its DMA activity.
  2954. */
  2955. resp_buf = phba->MBslimaddr;
  2956. /* Disable the error attention */
  2957. hc_copy = readl(phba->HCregaddr);
  2958. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2959. readl(phba->HCregaddr); /* flush */
  2960. phba->link_flag |= LS_IGNORE_ERATT;
  2961. if (readl(phba->HAregaddr) & HA_ERATT) {
  2962. /* Clear Chip error bit */
  2963. writel(HA_ERATT, phba->HAregaddr);
  2964. phba->pport->stopped = 1;
  2965. }
  2966. mbox = 0;
  2967. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2968. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2969. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2970. mbox_buf = phba->MBslimaddr;
  2971. writel(mbox, mbox_buf);
  2972. for (i = 0;
  2973. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2974. mdelay(1);
  2975. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2976. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2977. phba->pport->stopped)
  2978. goto restore_hc;
  2979. else
  2980. goto clear_errat;
  2981. }
  2982. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2983. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2984. mdelay(1);
  2985. clear_errat:
  2986. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  2987. mdelay(1);
  2988. if (readl(phba->HAregaddr) & HA_ERATT) {
  2989. writel(HA_ERATT, phba->HAregaddr);
  2990. phba->pport->stopped = 1;
  2991. }
  2992. restore_hc:
  2993. phba->link_flag &= ~LS_IGNORE_ERATT;
  2994. writel(hc_copy, phba->HCregaddr);
  2995. readl(phba->HCregaddr); /* flush */
  2996. }
  2997. /**
  2998. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  2999. * @phba: Pointer to HBA context object.
  3000. *
  3001. * This function issues a kill_board mailbox command and waits for
  3002. * the error attention interrupt. This function is called for stopping
  3003. * the firmware processing. The caller is not required to hold any
  3004. * locks. This function calls lpfc_hba_down_post function to free
  3005. * any pending commands after the kill. The function will return 1 when it
  3006. * fails to kill the board else will return 0.
  3007. **/
  3008. int
  3009. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3010. {
  3011. struct lpfc_sli *psli;
  3012. LPFC_MBOXQ_t *pmb;
  3013. uint32_t status;
  3014. uint32_t ha_copy;
  3015. int retval;
  3016. int i = 0;
  3017. psli = &phba->sli;
  3018. /* Kill HBA */
  3019. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3020. "0329 Kill HBA Data: x%x x%x\n",
  3021. phba->pport->port_state, psli->sli_flag);
  3022. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3023. if (!pmb)
  3024. return 1;
  3025. /* Disable the error attention */
  3026. spin_lock_irq(&phba->hbalock);
  3027. status = readl(phba->HCregaddr);
  3028. status &= ~HC_ERINT_ENA;
  3029. writel(status, phba->HCregaddr);
  3030. readl(phba->HCregaddr); /* flush */
  3031. phba->link_flag |= LS_IGNORE_ERATT;
  3032. spin_unlock_irq(&phba->hbalock);
  3033. lpfc_kill_board(phba, pmb);
  3034. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3035. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3036. if (retval != MBX_SUCCESS) {
  3037. if (retval != MBX_BUSY)
  3038. mempool_free(pmb, phba->mbox_mem_pool);
  3039. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3040. "2752 KILL_BOARD command failed retval %d\n",
  3041. retval);
  3042. spin_lock_irq(&phba->hbalock);
  3043. phba->link_flag &= ~LS_IGNORE_ERATT;
  3044. spin_unlock_irq(&phba->hbalock);
  3045. return 1;
  3046. }
  3047. spin_lock_irq(&phba->hbalock);
  3048. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3049. spin_unlock_irq(&phba->hbalock);
  3050. mempool_free(pmb, phba->mbox_mem_pool);
  3051. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3052. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3053. * 3 seconds we still set HBA_ERROR state because the status of the
  3054. * board is now undefined.
  3055. */
  3056. ha_copy = readl(phba->HAregaddr);
  3057. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3058. mdelay(100);
  3059. ha_copy = readl(phba->HAregaddr);
  3060. }
  3061. del_timer_sync(&psli->mbox_tmo);
  3062. if (ha_copy & HA_ERATT) {
  3063. writel(HA_ERATT, phba->HAregaddr);
  3064. phba->pport->stopped = 1;
  3065. }
  3066. spin_lock_irq(&phba->hbalock);
  3067. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3068. psli->mbox_active = NULL;
  3069. phba->link_flag &= ~LS_IGNORE_ERATT;
  3070. spin_unlock_irq(&phba->hbalock);
  3071. lpfc_hba_down_post(phba);
  3072. phba->link_state = LPFC_HBA_ERROR;
  3073. return ha_copy & HA_ERATT ? 0 : 1;
  3074. }
  3075. /**
  3076. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3077. * @phba: Pointer to HBA context object.
  3078. *
  3079. * This function resets the HBA by writing HC_INITFF to the control
  3080. * register. After the HBA resets, this function resets all the iocb ring
  3081. * indices. This function disables PCI layer parity checking during
  3082. * the reset.
  3083. * This function returns 0 always.
  3084. * The caller is not required to hold any locks.
  3085. **/
  3086. int
  3087. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3088. {
  3089. struct lpfc_sli *psli;
  3090. struct lpfc_sli_ring *pring;
  3091. uint16_t cfg_value;
  3092. int i;
  3093. psli = &phba->sli;
  3094. /* Reset HBA */
  3095. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3096. "0325 Reset HBA Data: x%x x%x\n",
  3097. phba->pport->port_state, psli->sli_flag);
  3098. /* perform board reset */
  3099. phba->fc_eventTag = 0;
  3100. phba->link_events = 0;
  3101. phba->pport->fc_myDID = 0;
  3102. phba->pport->fc_prevDID = 0;
  3103. /* Turn off parity checking and serr during the physical reset */
  3104. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3105. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3106. (cfg_value &
  3107. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3108. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3109. /* Now toggle INITFF bit in the Host Control Register */
  3110. writel(HC_INITFF, phba->HCregaddr);
  3111. mdelay(1);
  3112. readl(phba->HCregaddr); /* flush */
  3113. writel(0, phba->HCregaddr);
  3114. readl(phba->HCregaddr); /* flush */
  3115. /* Restore PCI cmd register */
  3116. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3117. /* Initialize relevant SLI info */
  3118. for (i = 0; i < psli->num_rings; i++) {
  3119. pring = &psli->ring[i];
  3120. pring->flag = 0;
  3121. pring->rspidx = 0;
  3122. pring->next_cmdidx = 0;
  3123. pring->local_getidx = 0;
  3124. pring->cmdidx = 0;
  3125. pring->missbufcnt = 0;
  3126. }
  3127. phba->link_state = LPFC_WARM_START;
  3128. return 0;
  3129. }
  3130. /**
  3131. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3132. * @phba: Pointer to HBA context object.
  3133. *
  3134. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3135. * checking during resets the device. The caller is not required to hold
  3136. * any locks.
  3137. *
  3138. * This function returns 0 always.
  3139. **/
  3140. int
  3141. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3142. {
  3143. struct lpfc_sli *psli = &phba->sli;
  3144. uint16_t cfg_value;
  3145. uint8_t qindx;
  3146. /* Reset HBA */
  3147. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3148. "0295 Reset HBA Data: x%x x%x\n",
  3149. phba->pport->port_state, psli->sli_flag);
  3150. /* perform board reset */
  3151. phba->fc_eventTag = 0;
  3152. phba->link_events = 0;
  3153. phba->pport->fc_myDID = 0;
  3154. phba->pport->fc_prevDID = 0;
  3155. /* Turn off parity checking and serr during the physical reset */
  3156. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3157. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3158. (cfg_value &
  3159. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3160. spin_lock_irq(&phba->hbalock);
  3161. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3162. phba->fcf.fcf_flag = 0;
  3163. /* Clean up the child queue list for the CQs */
  3164. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3165. list_del_init(&phba->sli4_hba.els_wq->list);
  3166. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3167. list_del_init(&phba->sli4_hba.dat_rq->list);
  3168. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3169. list_del_init(&phba->sli4_hba.els_cq->list);
  3170. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3171. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3172. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3173. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3174. spin_unlock_irq(&phba->hbalock);
  3175. /* Now physically reset the device */
  3176. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3177. "0389 Performing PCI function reset!\n");
  3178. /* Perform FCoE PCI function reset */
  3179. lpfc_pci_function_reset(phba);
  3180. return 0;
  3181. }
  3182. /**
  3183. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3184. * @phba: Pointer to HBA context object.
  3185. *
  3186. * This function is called in the SLI initialization code path to
  3187. * restart the HBA. The caller is not required to hold any lock.
  3188. * This function writes MBX_RESTART mailbox command to the SLIM and
  3189. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3190. * function to free any pending commands. The function enables
  3191. * POST only during the first initialization. The function returns zero.
  3192. * The function does not guarantee completion of MBX_RESTART mailbox
  3193. * command before the return of this function.
  3194. **/
  3195. static int
  3196. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3197. {
  3198. MAILBOX_t *mb;
  3199. struct lpfc_sli *psli;
  3200. volatile uint32_t word0;
  3201. void __iomem *to_slim;
  3202. uint32_t hba_aer_enabled;
  3203. spin_lock_irq(&phba->hbalock);
  3204. /* Take PCIe device Advanced Error Reporting (AER) state */
  3205. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3206. psli = &phba->sli;
  3207. /* Restart HBA */
  3208. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3209. "0337 Restart HBA Data: x%x x%x\n",
  3210. phba->pport->port_state, psli->sli_flag);
  3211. word0 = 0;
  3212. mb = (MAILBOX_t *) &word0;
  3213. mb->mbxCommand = MBX_RESTART;
  3214. mb->mbxHc = 1;
  3215. lpfc_reset_barrier(phba);
  3216. to_slim = phba->MBslimaddr;
  3217. writel(*(uint32_t *) mb, to_slim);
  3218. readl(to_slim); /* flush */
  3219. /* Only skip post after fc_ffinit is completed */
  3220. if (phba->pport->port_state)
  3221. word0 = 1; /* This is really setting up word1 */
  3222. else
  3223. word0 = 0; /* This is really setting up word1 */
  3224. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3225. writel(*(uint32_t *) mb, to_slim);
  3226. readl(to_slim); /* flush */
  3227. lpfc_sli_brdreset(phba);
  3228. phba->pport->stopped = 0;
  3229. phba->link_state = LPFC_INIT_START;
  3230. phba->hba_flag = 0;
  3231. spin_unlock_irq(&phba->hbalock);
  3232. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3233. psli->stats_start = get_seconds();
  3234. /* Give the INITFF and Post time to settle. */
  3235. mdelay(100);
  3236. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3237. if (hba_aer_enabled)
  3238. pci_disable_pcie_error_reporting(phba->pcidev);
  3239. lpfc_hba_down_post(phba);
  3240. return 0;
  3241. }
  3242. /**
  3243. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3244. * @phba: Pointer to HBA context object.
  3245. *
  3246. * This function is called in the SLI initialization code path to restart
  3247. * a SLI4 HBA. The caller is not required to hold any lock.
  3248. * At the end of the function, it calls lpfc_hba_down_post function to
  3249. * free any pending commands.
  3250. **/
  3251. static int
  3252. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3253. {
  3254. struct lpfc_sli *psli = &phba->sli;
  3255. uint32_t hba_aer_enabled;
  3256. /* Restart HBA */
  3257. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3258. "0296 Restart HBA Data: x%x x%x\n",
  3259. phba->pport->port_state, psli->sli_flag);
  3260. /* Take PCIe device Advanced Error Reporting (AER) state */
  3261. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3262. lpfc_sli4_brdreset(phba);
  3263. spin_lock_irq(&phba->hbalock);
  3264. phba->pport->stopped = 0;
  3265. phba->link_state = LPFC_INIT_START;
  3266. phba->hba_flag = 0;
  3267. spin_unlock_irq(&phba->hbalock);
  3268. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3269. psli->stats_start = get_seconds();
  3270. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3271. if (hba_aer_enabled)
  3272. pci_disable_pcie_error_reporting(phba->pcidev);
  3273. lpfc_hba_down_post(phba);
  3274. return 0;
  3275. }
  3276. /**
  3277. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3278. * @phba: Pointer to HBA context object.
  3279. *
  3280. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3281. * API jump table function pointer from the lpfc_hba struct.
  3282. **/
  3283. int
  3284. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3285. {
  3286. return phba->lpfc_sli_brdrestart(phba);
  3287. }
  3288. /**
  3289. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3290. * @phba: Pointer to HBA context object.
  3291. *
  3292. * This function is called after a HBA restart to wait for successful
  3293. * restart of the HBA. Successful restart of the HBA is indicated by
  3294. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3295. * iteration, the function will restart the HBA again. The function returns
  3296. * zero if HBA successfully restarted else returns negative error code.
  3297. **/
  3298. static int
  3299. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3300. {
  3301. uint32_t status, i = 0;
  3302. /* Read the HBA Host Status Register */
  3303. status = readl(phba->HSregaddr);
  3304. /* Check status register to see what current state is */
  3305. i = 0;
  3306. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3307. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3308. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3309. * 4.
  3310. */
  3311. if (i++ >= 20) {
  3312. /* Adapter failed to init, timeout, status reg
  3313. <status> */
  3314. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3315. "0436 Adapter failed to init, "
  3316. "timeout, status reg x%x, "
  3317. "FW Data: A8 x%x AC x%x\n", status,
  3318. readl(phba->MBslimaddr + 0xa8),
  3319. readl(phba->MBslimaddr + 0xac));
  3320. phba->link_state = LPFC_HBA_ERROR;
  3321. return -ETIMEDOUT;
  3322. }
  3323. /* Check to see if any errors occurred during init */
  3324. if (status & HS_FFERM) {
  3325. /* ERROR: During chipset initialization */
  3326. /* Adapter failed to init, chipset, status reg
  3327. <status> */
  3328. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3329. "0437 Adapter failed to init, "
  3330. "chipset, status reg x%x, "
  3331. "FW Data: A8 x%x AC x%x\n", status,
  3332. readl(phba->MBslimaddr + 0xa8),
  3333. readl(phba->MBslimaddr + 0xac));
  3334. phba->link_state = LPFC_HBA_ERROR;
  3335. return -EIO;
  3336. }
  3337. if (i <= 5) {
  3338. msleep(10);
  3339. } else if (i <= 10) {
  3340. msleep(500);
  3341. } else {
  3342. msleep(2500);
  3343. }
  3344. if (i == 15) {
  3345. /* Do post */
  3346. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3347. lpfc_sli_brdrestart(phba);
  3348. }
  3349. /* Read the HBA Host Status Register */
  3350. status = readl(phba->HSregaddr);
  3351. }
  3352. /* Check to see if any errors occurred during init */
  3353. if (status & HS_FFERM) {
  3354. /* ERROR: During chipset initialization */
  3355. /* Adapter failed to init, chipset, status reg <status> */
  3356. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3357. "0438 Adapter failed to init, chipset, "
  3358. "status reg x%x, "
  3359. "FW Data: A8 x%x AC x%x\n", status,
  3360. readl(phba->MBslimaddr + 0xa8),
  3361. readl(phba->MBslimaddr + 0xac));
  3362. phba->link_state = LPFC_HBA_ERROR;
  3363. return -EIO;
  3364. }
  3365. /* Clear all interrupt enable conditions */
  3366. writel(0, phba->HCregaddr);
  3367. readl(phba->HCregaddr); /* flush */
  3368. /* setup host attn register */
  3369. writel(0xffffffff, phba->HAregaddr);
  3370. readl(phba->HAregaddr); /* flush */
  3371. return 0;
  3372. }
  3373. /**
  3374. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3375. *
  3376. * This function calculates and returns the number of HBQs required to be
  3377. * configured.
  3378. **/
  3379. int
  3380. lpfc_sli_hbq_count(void)
  3381. {
  3382. return ARRAY_SIZE(lpfc_hbq_defs);
  3383. }
  3384. /**
  3385. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3386. *
  3387. * This function adds the number of hbq entries in every HBQ to get
  3388. * the total number of hbq entries required for the HBA and returns
  3389. * the total count.
  3390. **/
  3391. static int
  3392. lpfc_sli_hbq_entry_count(void)
  3393. {
  3394. int hbq_count = lpfc_sli_hbq_count();
  3395. int count = 0;
  3396. int i;
  3397. for (i = 0; i < hbq_count; ++i)
  3398. count += lpfc_hbq_defs[i]->entry_count;
  3399. return count;
  3400. }
  3401. /**
  3402. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3403. *
  3404. * This function calculates amount of memory required for all hbq entries
  3405. * to be configured and returns the total memory required.
  3406. **/
  3407. int
  3408. lpfc_sli_hbq_size(void)
  3409. {
  3410. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3411. }
  3412. /**
  3413. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3414. * @phba: Pointer to HBA context object.
  3415. *
  3416. * This function is called during the SLI initialization to configure
  3417. * all the HBQs and post buffers to the HBQ. The caller is not
  3418. * required to hold any locks. This function will return zero if successful
  3419. * else it will return negative error code.
  3420. **/
  3421. static int
  3422. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3423. {
  3424. int hbq_count = lpfc_sli_hbq_count();
  3425. LPFC_MBOXQ_t *pmb;
  3426. MAILBOX_t *pmbox;
  3427. uint32_t hbqno;
  3428. uint32_t hbq_entry_index;
  3429. /* Get a Mailbox buffer to setup mailbox
  3430. * commands for HBA initialization
  3431. */
  3432. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3433. if (!pmb)
  3434. return -ENOMEM;
  3435. pmbox = &pmb->u.mb;
  3436. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3437. phba->link_state = LPFC_INIT_MBX_CMDS;
  3438. phba->hbq_in_use = 1;
  3439. hbq_entry_index = 0;
  3440. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3441. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3442. phba->hbqs[hbqno].hbqPutIdx = 0;
  3443. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3444. phba->hbqs[hbqno].entry_count =
  3445. lpfc_hbq_defs[hbqno]->entry_count;
  3446. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3447. hbq_entry_index, pmb);
  3448. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3449. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3450. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3451. mbxStatus <status>, ring <num> */
  3452. lpfc_printf_log(phba, KERN_ERR,
  3453. LOG_SLI | LOG_VPORT,
  3454. "1805 Adapter failed to init. "
  3455. "Data: x%x x%x x%x\n",
  3456. pmbox->mbxCommand,
  3457. pmbox->mbxStatus, hbqno);
  3458. phba->link_state = LPFC_HBA_ERROR;
  3459. mempool_free(pmb, phba->mbox_mem_pool);
  3460. return -ENXIO;
  3461. }
  3462. }
  3463. phba->hbq_count = hbq_count;
  3464. mempool_free(pmb, phba->mbox_mem_pool);
  3465. /* Initially populate or replenish the HBQs */
  3466. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3467. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3468. return 0;
  3469. }
  3470. /**
  3471. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3472. * @phba: Pointer to HBA context object.
  3473. *
  3474. * This function is called during the SLI initialization to configure
  3475. * all the HBQs and post buffers to the HBQ. The caller is not
  3476. * required to hold any locks. This function will return zero if successful
  3477. * else it will return negative error code.
  3478. **/
  3479. static int
  3480. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3481. {
  3482. phba->hbq_in_use = 1;
  3483. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3484. phba->hbq_count = 1;
  3485. /* Initially populate or replenish the HBQs */
  3486. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3487. return 0;
  3488. }
  3489. /**
  3490. * lpfc_sli_config_port - Issue config port mailbox command
  3491. * @phba: Pointer to HBA context object.
  3492. * @sli_mode: sli mode - 2/3
  3493. *
  3494. * This function is called by the sli intialization code path
  3495. * to issue config_port mailbox command. This function restarts the
  3496. * HBA firmware and issues a config_port mailbox command to configure
  3497. * the SLI interface in the sli mode specified by sli_mode
  3498. * variable. The caller is not required to hold any locks.
  3499. * The function returns 0 if successful, else returns negative error
  3500. * code.
  3501. **/
  3502. int
  3503. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3504. {
  3505. LPFC_MBOXQ_t *pmb;
  3506. uint32_t resetcount = 0, rc = 0, done = 0;
  3507. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3508. if (!pmb) {
  3509. phba->link_state = LPFC_HBA_ERROR;
  3510. return -ENOMEM;
  3511. }
  3512. phba->sli_rev = sli_mode;
  3513. while (resetcount < 2 && !done) {
  3514. spin_lock_irq(&phba->hbalock);
  3515. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3516. spin_unlock_irq(&phba->hbalock);
  3517. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3518. lpfc_sli_brdrestart(phba);
  3519. rc = lpfc_sli_chipset_init(phba);
  3520. if (rc)
  3521. break;
  3522. spin_lock_irq(&phba->hbalock);
  3523. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3524. spin_unlock_irq(&phba->hbalock);
  3525. resetcount++;
  3526. /* Call pre CONFIG_PORT mailbox command initialization. A
  3527. * value of 0 means the call was successful. Any other
  3528. * nonzero value is a failure, but if ERESTART is returned,
  3529. * the driver may reset the HBA and try again.
  3530. */
  3531. rc = lpfc_config_port_prep(phba);
  3532. if (rc == -ERESTART) {
  3533. phba->link_state = LPFC_LINK_UNKNOWN;
  3534. continue;
  3535. } else if (rc)
  3536. break;
  3537. phba->link_state = LPFC_INIT_MBX_CMDS;
  3538. lpfc_config_port(phba, pmb);
  3539. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3540. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3541. LPFC_SLI3_HBQ_ENABLED |
  3542. LPFC_SLI3_CRP_ENABLED |
  3543. LPFC_SLI3_BG_ENABLED |
  3544. LPFC_SLI3_DSS_ENABLED);
  3545. if (rc != MBX_SUCCESS) {
  3546. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3547. "0442 Adapter failed to init, mbxCmd x%x "
  3548. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3549. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3550. spin_lock_irq(&phba->hbalock);
  3551. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3552. spin_unlock_irq(&phba->hbalock);
  3553. rc = -ENXIO;
  3554. } else {
  3555. /* Allow asynchronous mailbox command to go through */
  3556. spin_lock_irq(&phba->hbalock);
  3557. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3558. spin_unlock_irq(&phba->hbalock);
  3559. done = 1;
  3560. }
  3561. }
  3562. if (!done) {
  3563. rc = -EINVAL;
  3564. goto do_prep_failed;
  3565. }
  3566. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3567. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3568. rc = -ENXIO;
  3569. goto do_prep_failed;
  3570. }
  3571. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3572. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3573. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3574. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3575. phba->max_vpi : phba->max_vports;
  3576. } else
  3577. phba->max_vpi = 0;
  3578. phba->fips_level = 0;
  3579. phba->fips_spec_rev = 0;
  3580. if (pmb->u.mb.un.varCfgPort.gdss) {
  3581. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3582. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  3583. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  3584. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3585. "2850 Security Crypto Active. FIPS x%d "
  3586. "(Spec Rev: x%d)",
  3587. phba->fips_level, phba->fips_spec_rev);
  3588. }
  3589. if (pmb->u.mb.un.varCfgPort.sec_err) {
  3590. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3591. "2856 Config Port Security Crypto "
  3592. "Error: x%x ",
  3593. pmb->u.mb.un.varCfgPort.sec_err);
  3594. }
  3595. if (pmb->u.mb.un.varCfgPort.gerbm)
  3596. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3597. if (pmb->u.mb.un.varCfgPort.gcrp)
  3598. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3599. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3600. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3601. if (phba->cfg_enable_bg) {
  3602. if (pmb->u.mb.un.varCfgPort.gbg)
  3603. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3604. else
  3605. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3606. "0443 Adapter did not grant "
  3607. "BlockGuard\n");
  3608. }
  3609. } else {
  3610. phba->hbq_get = NULL;
  3611. phba->port_gp = phba->mbox->us.s2.port;
  3612. phba->max_vpi = 0;
  3613. }
  3614. do_prep_failed:
  3615. mempool_free(pmb, phba->mbox_mem_pool);
  3616. return rc;
  3617. }
  3618. /**
  3619. * lpfc_sli_hba_setup - SLI intialization function
  3620. * @phba: Pointer to HBA context object.
  3621. *
  3622. * This function is the main SLI intialization function. This function
  3623. * is called by the HBA intialization code, HBA reset code and HBA
  3624. * error attention handler code. Caller is not required to hold any
  3625. * locks. This function issues config_port mailbox command to configure
  3626. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3627. * calls the config_port_post function to issue init_link mailbox
  3628. * command and to start the discovery. The function will return zero
  3629. * if successful, else it will return negative error code.
  3630. **/
  3631. int
  3632. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3633. {
  3634. uint32_t rc;
  3635. int mode = 3;
  3636. switch (lpfc_sli_mode) {
  3637. case 2:
  3638. if (phba->cfg_enable_npiv) {
  3639. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3640. "1824 NPIV enabled: Override lpfc_sli_mode "
  3641. "parameter (%d) to auto (0).\n",
  3642. lpfc_sli_mode);
  3643. break;
  3644. }
  3645. mode = 2;
  3646. break;
  3647. case 0:
  3648. case 3:
  3649. break;
  3650. default:
  3651. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3652. "1819 Unrecognized lpfc_sli_mode "
  3653. "parameter: %d.\n", lpfc_sli_mode);
  3654. break;
  3655. }
  3656. rc = lpfc_sli_config_port(phba, mode);
  3657. if (rc && lpfc_sli_mode == 3)
  3658. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3659. "1820 Unable to select SLI-3. "
  3660. "Not supported by adapter.\n");
  3661. if (rc && mode != 2)
  3662. rc = lpfc_sli_config_port(phba, 2);
  3663. if (rc)
  3664. goto lpfc_sli_hba_setup_error;
  3665. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  3666. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  3667. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  3668. if (!rc) {
  3669. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3670. "2709 This device supports "
  3671. "Advanced Error Reporting (AER)\n");
  3672. spin_lock_irq(&phba->hbalock);
  3673. phba->hba_flag |= HBA_AER_ENABLED;
  3674. spin_unlock_irq(&phba->hbalock);
  3675. } else {
  3676. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3677. "2708 This device does not support "
  3678. "Advanced Error Reporting (AER)\n");
  3679. phba->cfg_aer_support = 0;
  3680. }
  3681. }
  3682. if (phba->sli_rev == 3) {
  3683. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3684. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3685. } else {
  3686. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3687. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3688. phba->sli3_options = 0;
  3689. }
  3690. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3691. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3692. phba->sli_rev, phba->max_vpi);
  3693. rc = lpfc_sli_ring_map(phba);
  3694. if (rc)
  3695. goto lpfc_sli_hba_setup_error;
  3696. /* Init HBQs */
  3697. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3698. rc = lpfc_sli_hbq_setup(phba);
  3699. if (rc)
  3700. goto lpfc_sli_hba_setup_error;
  3701. }
  3702. spin_lock_irq(&phba->hbalock);
  3703. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3704. spin_unlock_irq(&phba->hbalock);
  3705. rc = lpfc_config_port_post(phba);
  3706. if (rc)
  3707. goto lpfc_sli_hba_setup_error;
  3708. return rc;
  3709. lpfc_sli_hba_setup_error:
  3710. phba->link_state = LPFC_HBA_ERROR;
  3711. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3712. "0445 Firmware initialization failed\n");
  3713. return rc;
  3714. }
  3715. /**
  3716. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3717. * @phba: Pointer to HBA context object.
  3718. * @mboxq: mailbox pointer.
  3719. * This function issue a dump mailbox command to read config region
  3720. * 23 and parse the records in the region and populate driver
  3721. * data structure.
  3722. **/
  3723. static int
  3724. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3725. LPFC_MBOXQ_t *mboxq)
  3726. {
  3727. struct lpfc_dmabuf *mp;
  3728. struct lpfc_mqe *mqe;
  3729. uint32_t data_length;
  3730. int rc;
  3731. /* Program the default value of vlan_id and fc_map */
  3732. phba->valid_vlan = 0;
  3733. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3734. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3735. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3736. mqe = &mboxq->u.mqe;
  3737. if (lpfc_dump_fcoe_param(phba, mboxq))
  3738. return -ENOMEM;
  3739. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3740. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3741. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3742. "(%d):2571 Mailbox cmd x%x Status x%x "
  3743. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3744. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3745. "CQ: x%x x%x x%x x%x\n",
  3746. mboxq->vport ? mboxq->vport->vpi : 0,
  3747. bf_get(lpfc_mqe_command, mqe),
  3748. bf_get(lpfc_mqe_status, mqe),
  3749. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3750. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3751. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3752. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3753. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3754. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3755. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3756. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3757. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3758. mboxq->mcqe.word0,
  3759. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3760. mboxq->mcqe.trailer);
  3761. if (rc) {
  3762. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3763. kfree(mp);
  3764. return -EIO;
  3765. }
  3766. data_length = mqe->un.mb_words[5];
  3767. if (data_length > DMP_RGN23_SIZE) {
  3768. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3769. kfree(mp);
  3770. return -EIO;
  3771. }
  3772. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3773. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3774. kfree(mp);
  3775. return 0;
  3776. }
  3777. /**
  3778. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3779. * @phba: pointer to lpfc hba data structure.
  3780. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3781. * @vpd: pointer to the memory to hold resulting port vpd data.
  3782. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3783. * On output, the number of data bytes in @vpd.
  3784. *
  3785. * This routine executes a READ_REV SLI4 mailbox command. In
  3786. * addition, this routine gets the port vpd data.
  3787. *
  3788. * Return codes
  3789. * 0 - successful
  3790. * ENOMEM - could not allocated memory.
  3791. **/
  3792. static int
  3793. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3794. uint8_t *vpd, uint32_t *vpd_size)
  3795. {
  3796. int rc = 0;
  3797. uint32_t dma_size;
  3798. struct lpfc_dmabuf *dmabuf;
  3799. struct lpfc_mqe *mqe;
  3800. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3801. if (!dmabuf)
  3802. return -ENOMEM;
  3803. /*
  3804. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3805. * mailbox command.
  3806. */
  3807. dma_size = *vpd_size;
  3808. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3809. dma_size,
  3810. &dmabuf->phys,
  3811. GFP_KERNEL);
  3812. if (!dmabuf->virt) {
  3813. kfree(dmabuf);
  3814. return -ENOMEM;
  3815. }
  3816. memset(dmabuf->virt, 0, dma_size);
  3817. /*
  3818. * The SLI4 implementation of READ_REV conflicts at word1,
  3819. * bits 31:16 and SLI4 adds vpd functionality not present
  3820. * in SLI3. This code corrects the conflicts.
  3821. */
  3822. lpfc_read_rev(phba, mboxq);
  3823. mqe = &mboxq->u.mqe;
  3824. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3825. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3826. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3827. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3828. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3829. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3830. if (rc) {
  3831. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3832. dmabuf->virt, dmabuf->phys);
  3833. kfree(dmabuf);
  3834. return -EIO;
  3835. }
  3836. /*
  3837. * The available vpd length cannot be bigger than the
  3838. * DMA buffer passed to the port. Catch the less than
  3839. * case and update the caller's size.
  3840. */
  3841. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3842. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3843. memcpy(vpd, dmabuf->virt, *vpd_size);
  3844. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3845. dmabuf->virt, dmabuf->phys);
  3846. kfree(dmabuf);
  3847. return 0;
  3848. }
  3849. /**
  3850. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3851. * @phba: pointer to lpfc hba data structure.
  3852. *
  3853. * This routine is called to explicitly arm the SLI4 device's completion and
  3854. * event queues
  3855. **/
  3856. static void
  3857. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3858. {
  3859. uint8_t fcp_eqidx;
  3860. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3861. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3862. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3863. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3864. LPFC_QUEUE_REARM);
  3865. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3866. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3867. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3868. LPFC_QUEUE_REARM);
  3869. }
  3870. /**
  3871. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3872. * @phba: Pointer to HBA context object.
  3873. *
  3874. * This function is the main SLI4 device intialization PCI function. This
  3875. * function is called by the HBA intialization code, HBA reset code and
  3876. * HBA error attention handler code. Caller is not required to hold any
  3877. * locks.
  3878. **/
  3879. int
  3880. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3881. {
  3882. int rc;
  3883. LPFC_MBOXQ_t *mboxq;
  3884. struct lpfc_mqe *mqe;
  3885. uint8_t *vpd;
  3886. uint32_t vpd_size;
  3887. uint32_t ftr_rsp = 0;
  3888. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3889. struct lpfc_vport *vport = phba->pport;
  3890. struct lpfc_dmabuf *mp;
  3891. /* Perform a PCI function reset to start from clean */
  3892. rc = lpfc_pci_function_reset(phba);
  3893. if (unlikely(rc))
  3894. return -ENODEV;
  3895. /* Check the HBA Host Status Register for readyness */
  3896. rc = lpfc_sli4_post_status_check(phba);
  3897. if (unlikely(rc))
  3898. return -ENODEV;
  3899. else {
  3900. spin_lock_irq(&phba->hbalock);
  3901. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3902. spin_unlock_irq(&phba->hbalock);
  3903. }
  3904. /*
  3905. * Allocate a single mailbox container for initializing the
  3906. * port.
  3907. */
  3908. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3909. if (!mboxq)
  3910. return -ENOMEM;
  3911. /*
  3912. * Continue initialization with default values even if driver failed
  3913. * to read FCoE param config regions
  3914. */
  3915. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3916. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3917. "2570 Failed to read FCoE parameters\n");
  3918. /* Issue READ_REV to collect vpd and FW information. */
  3919. vpd_size = SLI4_PAGE_SIZE;
  3920. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3921. if (!vpd) {
  3922. rc = -ENOMEM;
  3923. goto out_free_mbox;
  3924. }
  3925. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3926. if (unlikely(rc))
  3927. goto out_free_vpd;
  3928. mqe = &mboxq->u.mqe;
  3929. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3930. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3931. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3932. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  3933. LPFC_DCBX_CEE_MODE)
  3934. phba->hba_flag |= HBA_FIP_SUPPORT;
  3935. else
  3936. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  3937. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3938. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3939. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3940. "0376 READ_REV Error. SLI Level %d "
  3941. "FCoE enabled %d\n",
  3942. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3943. rc = -EIO;
  3944. goto out_free_vpd;
  3945. }
  3946. /*
  3947. * Evaluate the read rev and vpd data. Populate the driver
  3948. * state with the results. If this routine fails, the failure
  3949. * is not fatal as the driver will use generic values.
  3950. */
  3951. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3952. if (unlikely(!rc)) {
  3953. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3954. "0377 Error %d parsing vpd. "
  3955. "Using defaults.\n", rc);
  3956. rc = 0;
  3957. }
  3958. /* Save information as VPD data */
  3959. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3960. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3961. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3962. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3963. &mqe->un.read_rev);
  3964. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3965. &mqe->un.read_rev);
  3966. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3967. &mqe->un.read_rev);
  3968. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3969. &mqe->un.read_rev);
  3970. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3971. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3972. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3973. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3974. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3975. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3976. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3977. "(%d):0380 READ_REV Status x%x "
  3978. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3979. mboxq->vport ? mboxq->vport->vpi : 0,
  3980. bf_get(lpfc_mqe_status, mqe),
  3981. phba->vpd.rev.opFwName,
  3982. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3983. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3984. /*
  3985. * Discover the port's supported feature set and match it against the
  3986. * hosts requests.
  3987. */
  3988. lpfc_request_features(phba, mboxq);
  3989. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3990. if (unlikely(rc)) {
  3991. rc = -EIO;
  3992. goto out_free_vpd;
  3993. }
  3994. /*
  3995. * The port must support FCP initiator mode as this is the
  3996. * only mode running in the host.
  3997. */
  3998. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3999. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4000. "0378 No support for fcpi mode.\n");
  4001. ftr_rsp++;
  4002. }
  4003. /*
  4004. * If the port cannot support the host's requested features
  4005. * then turn off the global config parameters to disable the
  4006. * feature in the driver. This is not a fatal error.
  4007. */
  4008. if ((phba->cfg_enable_bg) &&
  4009. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4010. ftr_rsp++;
  4011. if (phba->max_vpi && phba->cfg_enable_npiv &&
  4012. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4013. ftr_rsp++;
  4014. if (ftr_rsp) {
  4015. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4016. "0379 Feature Mismatch Data: x%08x %08x "
  4017. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  4018. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  4019. phba->cfg_enable_npiv, phba->max_vpi);
  4020. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4021. phba->cfg_enable_bg = 0;
  4022. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4023. phba->cfg_enable_npiv = 0;
  4024. }
  4025. /* These SLI3 features are assumed in SLI4 */
  4026. spin_lock_irq(&phba->hbalock);
  4027. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4028. spin_unlock_irq(&phba->hbalock);
  4029. /* Read the port's service parameters. */
  4030. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4031. if (rc) {
  4032. phba->link_state = LPFC_HBA_ERROR;
  4033. rc = -ENOMEM;
  4034. goto out_free_vpd;
  4035. }
  4036. mboxq->vport = vport;
  4037. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4038. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4039. if (rc == MBX_SUCCESS) {
  4040. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4041. rc = 0;
  4042. }
  4043. /*
  4044. * This memory was allocated by the lpfc_read_sparam routine. Release
  4045. * it to the mbuf pool.
  4046. */
  4047. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4048. kfree(mp);
  4049. mboxq->context1 = NULL;
  4050. if (unlikely(rc)) {
  4051. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4052. "0382 READ_SPARAM command failed "
  4053. "status %d, mbxStatus x%x\n",
  4054. rc, bf_get(lpfc_mqe_status, mqe));
  4055. phba->link_state = LPFC_HBA_ERROR;
  4056. rc = -EIO;
  4057. goto out_free_vpd;
  4058. }
  4059. if (phba->cfg_soft_wwnn)
  4060. u64_to_wwn(phba->cfg_soft_wwnn,
  4061. vport->fc_sparam.nodeName.u.wwn);
  4062. if (phba->cfg_soft_wwpn)
  4063. u64_to_wwn(phba->cfg_soft_wwpn,
  4064. vport->fc_sparam.portName.u.wwn);
  4065. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4066. sizeof(struct lpfc_name));
  4067. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4068. sizeof(struct lpfc_name));
  4069. /* Update the fc_host data structures with new wwn. */
  4070. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4071. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4072. /* Register SGL pool to the device using non-embedded mailbox command */
  4073. rc = lpfc_sli4_post_sgl_list(phba);
  4074. if (unlikely(rc)) {
  4075. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4076. "0582 Error %d during sgl post operation\n",
  4077. rc);
  4078. rc = -ENODEV;
  4079. goto out_free_vpd;
  4080. }
  4081. /* Register SCSI SGL pool to the device */
  4082. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4083. if (unlikely(rc)) {
  4084. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4085. "0383 Error %d during scsi sgl post "
  4086. "operation\n", rc);
  4087. /* Some Scsi buffers were moved to the abort scsi list */
  4088. /* A pci function reset will repost them */
  4089. rc = -ENODEV;
  4090. goto out_free_vpd;
  4091. }
  4092. /* Post the rpi header region to the device. */
  4093. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4094. if (unlikely(rc)) {
  4095. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4096. "0393 Error %d during rpi post operation\n",
  4097. rc);
  4098. rc = -ENODEV;
  4099. goto out_free_vpd;
  4100. }
  4101. /* Set up all the queues to the device */
  4102. rc = lpfc_sli4_queue_setup(phba);
  4103. if (unlikely(rc)) {
  4104. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4105. "0381 Error %d during queue setup.\n ", rc);
  4106. goto out_stop_timers;
  4107. }
  4108. /* Arm the CQs and then EQs on device */
  4109. lpfc_sli4_arm_cqeq_intr(phba);
  4110. /* Indicate device interrupt mode */
  4111. phba->sli4_hba.intr_enable = 1;
  4112. /* Allow asynchronous mailbox command to go through */
  4113. spin_lock_irq(&phba->hbalock);
  4114. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4115. spin_unlock_irq(&phba->hbalock);
  4116. /* Post receive buffers to the device */
  4117. lpfc_sli4_rb_setup(phba);
  4118. /* Reset HBA FCF states after HBA reset */
  4119. phba->fcf.fcf_flag = 0;
  4120. phba->fcf.current_rec.flag = 0;
  4121. /* Start the ELS watchdog timer */
  4122. mod_timer(&vport->els_tmofunc,
  4123. jiffies + HZ * (phba->fc_ratov * 2));
  4124. /* Start heart beat timer */
  4125. mod_timer(&phba->hb_tmofunc,
  4126. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4127. phba->hb_outstanding = 0;
  4128. phba->last_completion_time = jiffies;
  4129. /* Start error attention (ERATT) polling timer */
  4130. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4131. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4132. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4133. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4134. if (!rc) {
  4135. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4136. "2829 This device supports "
  4137. "Advanced Error Reporting (AER)\n");
  4138. spin_lock_irq(&phba->hbalock);
  4139. phba->hba_flag |= HBA_AER_ENABLED;
  4140. spin_unlock_irq(&phba->hbalock);
  4141. } else {
  4142. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4143. "2830 This device does not support "
  4144. "Advanced Error Reporting (AER)\n");
  4145. phba->cfg_aer_support = 0;
  4146. }
  4147. }
  4148. /*
  4149. * The port is ready, set the host's link state to LINK_DOWN
  4150. * in preparation for link interrupts.
  4151. */
  4152. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4153. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4154. lpfc_set_loopback_flag(phba);
  4155. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4156. spin_lock_irq(&phba->hbalock);
  4157. phba->link_state = LPFC_LINK_DOWN;
  4158. spin_unlock_irq(&phba->hbalock);
  4159. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4160. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4161. kfree(vpd);
  4162. return 0;
  4163. } else
  4164. rc = -EIO;
  4165. /* Unset all the queues set up in this routine when error out */
  4166. if (rc)
  4167. lpfc_sli4_queue_unset(phba);
  4168. out_stop_timers:
  4169. if (rc)
  4170. lpfc_stop_hba_timers(phba);
  4171. out_free_vpd:
  4172. kfree(vpd);
  4173. out_free_mbox:
  4174. mempool_free(mboxq, phba->mbox_mem_pool);
  4175. return rc;
  4176. }
  4177. /**
  4178. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4179. * @ptr: context object - pointer to hba structure.
  4180. *
  4181. * This is the callback function for mailbox timer. The mailbox
  4182. * timer is armed when a new mailbox command is issued and the timer
  4183. * is deleted when the mailbox complete. The function is called by
  4184. * the kernel timer code when a mailbox does not complete within
  4185. * expected time. This function wakes up the worker thread to
  4186. * process the mailbox timeout and returns. All the processing is
  4187. * done by the worker thread function lpfc_mbox_timeout_handler.
  4188. **/
  4189. void
  4190. lpfc_mbox_timeout(unsigned long ptr)
  4191. {
  4192. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4193. unsigned long iflag;
  4194. uint32_t tmo_posted;
  4195. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4196. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4197. if (!tmo_posted)
  4198. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4199. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4200. if (!tmo_posted)
  4201. lpfc_worker_wake_up(phba);
  4202. return;
  4203. }
  4204. /**
  4205. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4206. * @phba: Pointer to HBA context object.
  4207. *
  4208. * This function is called from worker thread when a mailbox command times out.
  4209. * The caller is not required to hold any locks. This function will reset the
  4210. * HBA and recover all the pending commands.
  4211. **/
  4212. void
  4213. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4214. {
  4215. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4216. MAILBOX_t *mb = &pmbox->u.mb;
  4217. struct lpfc_sli *psli = &phba->sli;
  4218. struct lpfc_sli_ring *pring;
  4219. /* Check the pmbox pointer first. There is a race condition
  4220. * between the mbox timeout handler getting executed in the
  4221. * worklist and the mailbox actually completing. When this
  4222. * race condition occurs, the mbox_active will be NULL.
  4223. */
  4224. spin_lock_irq(&phba->hbalock);
  4225. if (pmbox == NULL) {
  4226. lpfc_printf_log(phba, KERN_WARNING,
  4227. LOG_MBOX | LOG_SLI,
  4228. "0353 Active Mailbox cleared - mailbox timeout "
  4229. "exiting\n");
  4230. spin_unlock_irq(&phba->hbalock);
  4231. return;
  4232. }
  4233. /* Mbox cmd <mbxCommand> timeout */
  4234. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4235. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4236. mb->mbxCommand,
  4237. phba->pport->port_state,
  4238. phba->sli.sli_flag,
  4239. phba->sli.mbox_active);
  4240. spin_unlock_irq(&phba->hbalock);
  4241. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4242. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4243. * it to fail all oustanding SCSI IO.
  4244. */
  4245. spin_lock_irq(&phba->pport->work_port_lock);
  4246. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4247. spin_unlock_irq(&phba->pport->work_port_lock);
  4248. spin_lock_irq(&phba->hbalock);
  4249. phba->link_state = LPFC_LINK_UNKNOWN;
  4250. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4251. spin_unlock_irq(&phba->hbalock);
  4252. pring = &psli->ring[psli->fcp_ring];
  4253. lpfc_sli_abort_iocb_ring(phba, pring);
  4254. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4255. "0345 Resetting board due to mailbox timeout\n");
  4256. /* Reset the HBA device */
  4257. lpfc_reset_hba(phba);
  4258. }
  4259. /**
  4260. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4261. * @phba: Pointer to HBA context object.
  4262. * @pmbox: Pointer to mailbox object.
  4263. * @flag: Flag indicating how the mailbox need to be processed.
  4264. *
  4265. * This function is called by discovery code and HBA management code
  4266. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4267. * function gets the hbalock to protect the data structures.
  4268. * The mailbox command can be submitted in polling mode, in which case
  4269. * this function will wait in a polling loop for the completion of the
  4270. * mailbox.
  4271. * If the mailbox is submitted in no_wait mode (not polling) the
  4272. * function will submit the command and returns immediately without waiting
  4273. * for the mailbox completion. The no_wait is supported only when HBA
  4274. * is in SLI2/SLI3 mode - interrupts are enabled.
  4275. * The SLI interface allows only one mailbox pending at a time. If the
  4276. * mailbox is issued in polling mode and there is already a mailbox
  4277. * pending, then the function will return an error. If the mailbox is issued
  4278. * in NO_WAIT mode and there is a mailbox pending already, the function
  4279. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4280. * The sli layer owns the mailbox object until the completion of mailbox
  4281. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4282. * return codes the caller owns the mailbox command after the return of
  4283. * the function.
  4284. **/
  4285. static int
  4286. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4287. uint32_t flag)
  4288. {
  4289. MAILBOX_t *mb;
  4290. struct lpfc_sli *psli = &phba->sli;
  4291. uint32_t status, evtctr;
  4292. uint32_t ha_copy;
  4293. int i;
  4294. unsigned long timeout;
  4295. unsigned long drvr_flag = 0;
  4296. uint32_t word0, ldata;
  4297. void __iomem *to_slim;
  4298. int processing_queue = 0;
  4299. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4300. if (!pmbox) {
  4301. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4302. /* processing mbox queue from intr_handler */
  4303. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4304. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4305. return MBX_SUCCESS;
  4306. }
  4307. processing_queue = 1;
  4308. pmbox = lpfc_mbox_get(phba);
  4309. if (!pmbox) {
  4310. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4311. return MBX_SUCCESS;
  4312. }
  4313. }
  4314. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4315. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4316. if(!pmbox->vport) {
  4317. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4318. lpfc_printf_log(phba, KERN_ERR,
  4319. LOG_MBOX | LOG_VPORT,
  4320. "1806 Mbox x%x failed. No vport\n",
  4321. pmbox->u.mb.mbxCommand);
  4322. dump_stack();
  4323. goto out_not_finished;
  4324. }
  4325. }
  4326. /* If the PCI channel is in offline state, do not post mbox. */
  4327. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4328. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4329. goto out_not_finished;
  4330. }
  4331. /* If HBA has a deferred error attention, fail the iocb. */
  4332. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4333. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4334. goto out_not_finished;
  4335. }
  4336. psli = &phba->sli;
  4337. mb = &pmbox->u.mb;
  4338. status = MBX_SUCCESS;
  4339. if (phba->link_state == LPFC_HBA_ERROR) {
  4340. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4341. /* Mbox command <mbxCommand> cannot issue */
  4342. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4343. "(%d):0311 Mailbox command x%x cannot "
  4344. "issue Data: x%x x%x\n",
  4345. pmbox->vport ? pmbox->vport->vpi : 0,
  4346. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4347. goto out_not_finished;
  4348. }
  4349. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4350. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4351. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4352. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4353. "(%d):2528 Mailbox command x%x cannot "
  4354. "issue Data: x%x x%x\n",
  4355. pmbox->vport ? pmbox->vport->vpi : 0,
  4356. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4357. goto out_not_finished;
  4358. }
  4359. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4360. /* Polling for a mbox command when another one is already active
  4361. * is not allowed in SLI. Also, the driver must have established
  4362. * SLI2 mode to queue and process multiple mbox commands.
  4363. */
  4364. if (flag & MBX_POLL) {
  4365. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4366. /* Mbox command <mbxCommand> cannot issue */
  4367. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4368. "(%d):2529 Mailbox command x%x "
  4369. "cannot issue Data: x%x x%x\n",
  4370. pmbox->vport ? pmbox->vport->vpi : 0,
  4371. pmbox->u.mb.mbxCommand,
  4372. psli->sli_flag, flag);
  4373. goto out_not_finished;
  4374. }
  4375. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4376. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4377. /* Mbox command <mbxCommand> cannot issue */
  4378. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4379. "(%d):2530 Mailbox command x%x "
  4380. "cannot issue Data: x%x x%x\n",
  4381. pmbox->vport ? pmbox->vport->vpi : 0,
  4382. pmbox->u.mb.mbxCommand,
  4383. psli->sli_flag, flag);
  4384. goto out_not_finished;
  4385. }
  4386. /* Another mailbox command is still being processed, queue this
  4387. * command to be processed later.
  4388. */
  4389. lpfc_mbox_put(phba, pmbox);
  4390. /* Mbox cmd issue - BUSY */
  4391. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4392. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4393. "x%x x%x x%x x%x\n",
  4394. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4395. mb->mbxCommand, phba->pport->port_state,
  4396. psli->sli_flag, flag);
  4397. psli->slistat.mbox_busy++;
  4398. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4399. if (pmbox->vport) {
  4400. lpfc_debugfs_disc_trc(pmbox->vport,
  4401. LPFC_DISC_TRC_MBOX_VPORT,
  4402. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4403. (uint32_t)mb->mbxCommand,
  4404. mb->un.varWords[0], mb->un.varWords[1]);
  4405. }
  4406. else {
  4407. lpfc_debugfs_disc_trc(phba->pport,
  4408. LPFC_DISC_TRC_MBOX,
  4409. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4410. (uint32_t)mb->mbxCommand,
  4411. mb->un.varWords[0], mb->un.varWords[1]);
  4412. }
  4413. return MBX_BUSY;
  4414. }
  4415. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4416. /* If we are not polling, we MUST be in SLI2 mode */
  4417. if (flag != MBX_POLL) {
  4418. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4419. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4420. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4421. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4422. /* Mbox command <mbxCommand> cannot issue */
  4423. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4424. "(%d):2531 Mailbox command x%x "
  4425. "cannot issue Data: x%x x%x\n",
  4426. pmbox->vport ? pmbox->vport->vpi : 0,
  4427. pmbox->u.mb.mbxCommand,
  4428. psli->sli_flag, flag);
  4429. goto out_not_finished;
  4430. }
  4431. /* timeout active mbox command */
  4432. mod_timer(&psli->mbox_tmo, (jiffies +
  4433. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4434. }
  4435. /* Mailbox cmd <cmd> issue */
  4436. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4437. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4438. "x%x\n",
  4439. pmbox->vport ? pmbox->vport->vpi : 0,
  4440. mb->mbxCommand, phba->pport->port_state,
  4441. psli->sli_flag, flag);
  4442. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4443. if (pmbox->vport) {
  4444. lpfc_debugfs_disc_trc(pmbox->vport,
  4445. LPFC_DISC_TRC_MBOX_VPORT,
  4446. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4447. (uint32_t)mb->mbxCommand,
  4448. mb->un.varWords[0], mb->un.varWords[1]);
  4449. }
  4450. else {
  4451. lpfc_debugfs_disc_trc(phba->pport,
  4452. LPFC_DISC_TRC_MBOX,
  4453. "MBOX Send: cmd:x%x mb:x%x x%x",
  4454. (uint32_t)mb->mbxCommand,
  4455. mb->un.varWords[0], mb->un.varWords[1]);
  4456. }
  4457. }
  4458. psli->slistat.mbox_cmd++;
  4459. evtctr = psli->slistat.mbox_event;
  4460. /* next set own bit for the adapter and copy over command word */
  4461. mb->mbxOwner = OWN_CHIP;
  4462. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4463. /* Populate mbox extension offset word. */
  4464. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  4465. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4466. = (uint8_t *)phba->mbox_ext
  4467. - (uint8_t *)phba->mbox;
  4468. }
  4469. /* Copy the mailbox extension data */
  4470. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4471. lpfc_sli_pcimem_bcopy(pmbox->context2,
  4472. (uint8_t *)phba->mbox_ext,
  4473. pmbox->in_ext_byte_len);
  4474. }
  4475. /* Copy command data to host SLIM area */
  4476. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4477. } else {
  4478. /* Populate mbox extension offset word. */
  4479. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  4480. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4481. = MAILBOX_HBA_EXT_OFFSET;
  4482. /* Copy the mailbox extension data */
  4483. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4484. lpfc_memcpy_to_slim(phba->MBslimaddr +
  4485. MAILBOX_HBA_EXT_OFFSET,
  4486. pmbox->context2, pmbox->in_ext_byte_len);
  4487. }
  4488. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4489. /* copy command data into host mbox for cmpl */
  4490. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4491. }
  4492. /* First copy mbox command data to HBA SLIM, skip past first
  4493. word */
  4494. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4495. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4496. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4497. /* Next copy over first word, with mbxOwner set */
  4498. ldata = *((uint32_t *)mb);
  4499. to_slim = phba->MBslimaddr;
  4500. writel(ldata, to_slim);
  4501. readl(to_slim); /* flush */
  4502. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4503. /* switch over to host mailbox */
  4504. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4505. }
  4506. }
  4507. wmb();
  4508. switch (flag) {
  4509. case MBX_NOWAIT:
  4510. /* Set up reference to mailbox command */
  4511. psli->mbox_active = pmbox;
  4512. /* Interrupt board to do it */
  4513. writel(CA_MBATT, phba->CAregaddr);
  4514. readl(phba->CAregaddr); /* flush */
  4515. /* Don't wait for it to finish, just return */
  4516. break;
  4517. case MBX_POLL:
  4518. /* Set up null reference to mailbox command */
  4519. psli->mbox_active = NULL;
  4520. /* Interrupt board to do it */
  4521. writel(CA_MBATT, phba->CAregaddr);
  4522. readl(phba->CAregaddr); /* flush */
  4523. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4524. /* First read mbox status word */
  4525. word0 = *((uint32_t *)phba->mbox);
  4526. word0 = le32_to_cpu(word0);
  4527. } else {
  4528. /* First read mbox status word */
  4529. word0 = readl(phba->MBslimaddr);
  4530. }
  4531. /* Read the HBA Host Attention Register */
  4532. ha_copy = readl(phba->HAregaddr);
  4533. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4534. mb->mbxCommand) *
  4535. 1000) + jiffies;
  4536. i = 0;
  4537. /* Wait for command to complete */
  4538. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4539. (!(ha_copy & HA_MBATT) &&
  4540. (phba->link_state > LPFC_WARM_START))) {
  4541. if (time_after(jiffies, timeout)) {
  4542. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4543. spin_unlock_irqrestore(&phba->hbalock,
  4544. drvr_flag);
  4545. goto out_not_finished;
  4546. }
  4547. /* Check if we took a mbox interrupt while we were
  4548. polling */
  4549. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4550. && (evtctr != psli->slistat.mbox_event))
  4551. break;
  4552. if (i++ > 10) {
  4553. spin_unlock_irqrestore(&phba->hbalock,
  4554. drvr_flag);
  4555. msleep(1);
  4556. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4557. }
  4558. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4559. /* First copy command data */
  4560. word0 = *((uint32_t *)phba->mbox);
  4561. word0 = le32_to_cpu(word0);
  4562. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4563. MAILBOX_t *slimmb;
  4564. uint32_t slimword0;
  4565. /* Check real SLIM for any errors */
  4566. slimword0 = readl(phba->MBslimaddr);
  4567. slimmb = (MAILBOX_t *) & slimword0;
  4568. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4569. && slimmb->mbxStatus) {
  4570. psli->sli_flag &=
  4571. ~LPFC_SLI_ACTIVE;
  4572. word0 = slimword0;
  4573. }
  4574. }
  4575. } else {
  4576. /* First copy command data */
  4577. word0 = readl(phba->MBslimaddr);
  4578. }
  4579. /* Read the HBA Host Attention Register */
  4580. ha_copy = readl(phba->HAregaddr);
  4581. }
  4582. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4583. /* copy results back to user */
  4584. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4585. /* Copy the mailbox extension data */
  4586. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4587. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  4588. pmbox->context2,
  4589. pmbox->out_ext_byte_len);
  4590. }
  4591. } else {
  4592. /* First copy command data */
  4593. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4594. MAILBOX_CMD_SIZE);
  4595. /* Copy the mailbox extension data */
  4596. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4597. lpfc_memcpy_from_slim(pmbox->context2,
  4598. phba->MBslimaddr +
  4599. MAILBOX_HBA_EXT_OFFSET,
  4600. pmbox->out_ext_byte_len);
  4601. }
  4602. }
  4603. writel(HA_MBATT, phba->HAregaddr);
  4604. readl(phba->HAregaddr); /* flush */
  4605. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4606. status = mb->mbxStatus;
  4607. }
  4608. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4609. return status;
  4610. out_not_finished:
  4611. if (processing_queue) {
  4612. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4613. lpfc_mbox_cmpl_put(phba, pmbox);
  4614. }
  4615. return MBX_NOT_FINISHED;
  4616. }
  4617. /**
  4618. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4619. * @phba: Pointer to HBA context object.
  4620. *
  4621. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4622. * the driver internal pending mailbox queue. It will then try to wait out the
  4623. * possible outstanding mailbox command before return.
  4624. *
  4625. * Returns:
  4626. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4627. * the outstanding mailbox command timed out.
  4628. **/
  4629. static int
  4630. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4631. {
  4632. struct lpfc_sli *psli = &phba->sli;
  4633. uint8_t actcmd = MBX_HEARTBEAT;
  4634. int rc = 0;
  4635. unsigned long timeout;
  4636. /* Mark the asynchronous mailbox command posting as blocked */
  4637. spin_lock_irq(&phba->hbalock);
  4638. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4639. if (phba->sli.mbox_active)
  4640. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4641. spin_unlock_irq(&phba->hbalock);
  4642. /* Determine how long we might wait for the active mailbox
  4643. * command to be gracefully completed by firmware.
  4644. */
  4645. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4646. jiffies;
  4647. /* Wait for the outstnading mailbox command to complete */
  4648. while (phba->sli.mbox_active) {
  4649. /* Check active mailbox complete status every 2ms */
  4650. msleep(2);
  4651. if (time_after(jiffies, timeout)) {
  4652. /* Timeout, marked the outstanding cmd not complete */
  4653. rc = 1;
  4654. break;
  4655. }
  4656. }
  4657. /* Can not cleanly block async mailbox command, fails it */
  4658. if (rc) {
  4659. spin_lock_irq(&phba->hbalock);
  4660. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4661. spin_unlock_irq(&phba->hbalock);
  4662. }
  4663. return rc;
  4664. }
  4665. /**
  4666. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4667. * @phba: Pointer to HBA context object.
  4668. *
  4669. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4670. * commands from the driver internal pending mailbox queue. It makes sure
  4671. * that there is no outstanding mailbox command before resuming posting
  4672. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4673. * mailbox command, it will try to wait it out before resuming asynchronous
  4674. * mailbox command posting.
  4675. **/
  4676. static void
  4677. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4678. {
  4679. struct lpfc_sli *psli = &phba->sli;
  4680. spin_lock_irq(&phba->hbalock);
  4681. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4682. /* Asynchronous mailbox posting is not blocked, do nothing */
  4683. spin_unlock_irq(&phba->hbalock);
  4684. return;
  4685. }
  4686. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4687. * successful or timeout, after timing-out the outstanding mailbox
  4688. * command shall always be removed, so just unblock posting async
  4689. * mailbox command and resume
  4690. */
  4691. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4692. spin_unlock_irq(&phba->hbalock);
  4693. /* wake up worker thread to post asynchronlous mailbox command */
  4694. lpfc_worker_wake_up(phba);
  4695. }
  4696. /**
  4697. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4698. * @phba: Pointer to HBA context object.
  4699. * @mboxq: Pointer to mailbox object.
  4700. *
  4701. * The function posts a mailbox to the port. The mailbox is expected
  4702. * to be comletely filled in and ready for the port to operate on it.
  4703. * This routine executes a synchronous completion operation on the
  4704. * mailbox by polling for its completion.
  4705. *
  4706. * The caller must not be holding any locks when calling this routine.
  4707. *
  4708. * Returns:
  4709. * MBX_SUCCESS - mailbox posted successfully
  4710. * Any of the MBX error values.
  4711. **/
  4712. static int
  4713. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4714. {
  4715. int rc = MBX_SUCCESS;
  4716. unsigned long iflag;
  4717. uint32_t db_ready;
  4718. uint32_t mcqe_status;
  4719. uint32_t mbx_cmnd;
  4720. unsigned long timeout;
  4721. struct lpfc_sli *psli = &phba->sli;
  4722. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4723. struct lpfc_bmbx_create *mbox_rgn;
  4724. struct dma_address *dma_address;
  4725. struct lpfc_register bmbx_reg;
  4726. /*
  4727. * Only one mailbox can be active to the bootstrap mailbox region
  4728. * at a time and there is no queueing provided.
  4729. */
  4730. spin_lock_irqsave(&phba->hbalock, iflag);
  4731. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4732. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4733. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4734. "(%d):2532 Mailbox command x%x (x%x) "
  4735. "cannot issue Data: x%x x%x\n",
  4736. mboxq->vport ? mboxq->vport->vpi : 0,
  4737. mboxq->u.mb.mbxCommand,
  4738. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4739. psli->sli_flag, MBX_POLL);
  4740. return MBXERR_ERROR;
  4741. }
  4742. /* The server grabs the token and owns it until release */
  4743. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4744. phba->sli.mbox_active = mboxq;
  4745. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4746. /*
  4747. * Initialize the bootstrap memory region to avoid stale data areas
  4748. * in the mailbox post. Then copy the caller's mailbox contents to
  4749. * the bmbx mailbox region.
  4750. */
  4751. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4752. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4753. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4754. sizeof(struct lpfc_mqe));
  4755. /* Post the high mailbox dma address to the port and wait for ready. */
  4756. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4757. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4758. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4759. * 1000) + jiffies;
  4760. do {
  4761. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4762. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4763. if (!db_ready)
  4764. msleep(2);
  4765. if (time_after(jiffies, timeout)) {
  4766. rc = MBXERR_ERROR;
  4767. goto exit;
  4768. }
  4769. } while (!db_ready);
  4770. /* Post the low mailbox dma address to the port. */
  4771. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4772. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4773. * 1000) + jiffies;
  4774. do {
  4775. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4776. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4777. if (!db_ready)
  4778. msleep(2);
  4779. if (time_after(jiffies, timeout)) {
  4780. rc = MBXERR_ERROR;
  4781. goto exit;
  4782. }
  4783. } while (!db_ready);
  4784. /*
  4785. * Read the CQ to ensure the mailbox has completed.
  4786. * If so, update the mailbox status so that the upper layers
  4787. * can complete the request normally.
  4788. */
  4789. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4790. sizeof(struct lpfc_mqe));
  4791. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4792. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4793. sizeof(struct lpfc_mcqe));
  4794. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4795. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4796. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4797. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4798. rc = MBXERR_ERROR;
  4799. } else
  4800. lpfc_sli4_swap_str(phba, mboxq);
  4801. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4802. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4803. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4804. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4805. mboxq->vport ? mboxq->vport->vpi : 0,
  4806. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4807. bf_get(lpfc_mqe_status, mb),
  4808. mb->un.mb_words[0], mb->un.mb_words[1],
  4809. mb->un.mb_words[2], mb->un.mb_words[3],
  4810. mb->un.mb_words[4], mb->un.mb_words[5],
  4811. mb->un.mb_words[6], mb->un.mb_words[7],
  4812. mb->un.mb_words[8], mb->un.mb_words[9],
  4813. mb->un.mb_words[10], mb->un.mb_words[11],
  4814. mb->un.mb_words[12], mboxq->mcqe.word0,
  4815. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4816. mboxq->mcqe.trailer);
  4817. exit:
  4818. /* We are holding the token, no needed for lock when release */
  4819. spin_lock_irqsave(&phba->hbalock, iflag);
  4820. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4821. phba->sli.mbox_active = NULL;
  4822. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4823. return rc;
  4824. }
  4825. /**
  4826. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4827. * @phba: Pointer to HBA context object.
  4828. * @pmbox: Pointer to mailbox object.
  4829. * @flag: Flag indicating how the mailbox need to be processed.
  4830. *
  4831. * This function is called by discovery code and HBA management code to submit
  4832. * a mailbox command to firmware with SLI-4 interface spec.
  4833. *
  4834. * Return codes the caller owns the mailbox command after the return of the
  4835. * function.
  4836. **/
  4837. static int
  4838. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4839. uint32_t flag)
  4840. {
  4841. struct lpfc_sli *psli = &phba->sli;
  4842. unsigned long iflags;
  4843. int rc;
  4844. rc = lpfc_mbox_dev_check(phba);
  4845. if (unlikely(rc)) {
  4846. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4847. "(%d):2544 Mailbox command x%x (x%x) "
  4848. "cannot issue Data: x%x x%x\n",
  4849. mboxq->vport ? mboxq->vport->vpi : 0,
  4850. mboxq->u.mb.mbxCommand,
  4851. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4852. psli->sli_flag, flag);
  4853. goto out_not_finished;
  4854. }
  4855. /* Detect polling mode and jump to a handler */
  4856. if (!phba->sli4_hba.intr_enable) {
  4857. if (flag == MBX_POLL)
  4858. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4859. else
  4860. rc = -EIO;
  4861. if (rc != MBX_SUCCESS)
  4862. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4863. "(%d):2541 Mailbox command x%x "
  4864. "(x%x) cannot issue Data: x%x x%x\n",
  4865. mboxq->vport ? mboxq->vport->vpi : 0,
  4866. mboxq->u.mb.mbxCommand,
  4867. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4868. psli->sli_flag, flag);
  4869. return rc;
  4870. } else if (flag == MBX_POLL) {
  4871. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4872. "(%d):2542 Try to issue mailbox command "
  4873. "x%x (x%x) synchronously ahead of async"
  4874. "mailbox command queue: x%x x%x\n",
  4875. mboxq->vport ? mboxq->vport->vpi : 0,
  4876. mboxq->u.mb.mbxCommand,
  4877. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4878. psli->sli_flag, flag);
  4879. /* Try to block the asynchronous mailbox posting */
  4880. rc = lpfc_sli4_async_mbox_block(phba);
  4881. if (!rc) {
  4882. /* Successfully blocked, now issue sync mbox cmd */
  4883. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4884. if (rc != MBX_SUCCESS)
  4885. lpfc_printf_log(phba, KERN_ERR,
  4886. LOG_MBOX | LOG_SLI,
  4887. "(%d):2597 Mailbox command "
  4888. "x%x (x%x) cannot issue "
  4889. "Data: x%x x%x\n",
  4890. mboxq->vport ?
  4891. mboxq->vport->vpi : 0,
  4892. mboxq->u.mb.mbxCommand,
  4893. lpfc_sli4_mbox_opcode_get(phba,
  4894. mboxq),
  4895. psli->sli_flag, flag);
  4896. /* Unblock the async mailbox posting afterward */
  4897. lpfc_sli4_async_mbox_unblock(phba);
  4898. }
  4899. return rc;
  4900. }
  4901. /* Now, interrupt mode asynchrous mailbox command */
  4902. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4903. if (rc) {
  4904. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4905. "(%d):2543 Mailbox command x%x (x%x) "
  4906. "cannot issue Data: x%x x%x\n",
  4907. mboxq->vport ? mboxq->vport->vpi : 0,
  4908. mboxq->u.mb.mbxCommand,
  4909. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4910. psli->sli_flag, flag);
  4911. goto out_not_finished;
  4912. }
  4913. /* Put the mailbox command to the driver internal FIFO */
  4914. psli->slistat.mbox_busy++;
  4915. spin_lock_irqsave(&phba->hbalock, iflags);
  4916. lpfc_mbox_put(phba, mboxq);
  4917. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4918. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4919. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4920. "x%x (x%x) x%x x%x x%x\n",
  4921. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4922. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4923. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4924. phba->pport->port_state,
  4925. psli->sli_flag, MBX_NOWAIT);
  4926. /* Wake up worker thread to transport mailbox command from head */
  4927. lpfc_worker_wake_up(phba);
  4928. return MBX_BUSY;
  4929. out_not_finished:
  4930. return MBX_NOT_FINISHED;
  4931. }
  4932. /**
  4933. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4934. * @phba: Pointer to HBA context object.
  4935. *
  4936. * This function is called by worker thread to send a mailbox command to
  4937. * SLI4 HBA firmware.
  4938. *
  4939. **/
  4940. int
  4941. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4942. {
  4943. struct lpfc_sli *psli = &phba->sli;
  4944. LPFC_MBOXQ_t *mboxq;
  4945. int rc = MBX_SUCCESS;
  4946. unsigned long iflags;
  4947. struct lpfc_mqe *mqe;
  4948. uint32_t mbx_cmnd;
  4949. /* Check interrupt mode before post async mailbox command */
  4950. if (unlikely(!phba->sli4_hba.intr_enable))
  4951. return MBX_NOT_FINISHED;
  4952. /* Check for mailbox command service token */
  4953. spin_lock_irqsave(&phba->hbalock, iflags);
  4954. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4955. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4956. return MBX_NOT_FINISHED;
  4957. }
  4958. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4959. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4960. return MBX_NOT_FINISHED;
  4961. }
  4962. if (unlikely(phba->sli.mbox_active)) {
  4963. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4964. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4965. "0384 There is pending active mailbox cmd\n");
  4966. return MBX_NOT_FINISHED;
  4967. }
  4968. /* Take the mailbox command service token */
  4969. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4970. /* Get the next mailbox command from head of queue */
  4971. mboxq = lpfc_mbox_get(phba);
  4972. /* If no more mailbox command waiting for post, we're done */
  4973. if (!mboxq) {
  4974. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4975. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4976. return MBX_SUCCESS;
  4977. }
  4978. phba->sli.mbox_active = mboxq;
  4979. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4980. /* Check device readiness for posting mailbox command */
  4981. rc = lpfc_mbox_dev_check(phba);
  4982. if (unlikely(rc))
  4983. /* Driver clean routine will clean up pending mailbox */
  4984. goto out_not_finished;
  4985. /* Prepare the mbox command to be posted */
  4986. mqe = &mboxq->u.mqe;
  4987. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4988. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4989. mod_timer(&psli->mbox_tmo, (jiffies +
  4990. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4991. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4992. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4993. "x%x x%x\n",
  4994. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4995. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4996. phba->pport->port_state, psli->sli_flag);
  4997. if (mbx_cmnd != MBX_HEARTBEAT) {
  4998. if (mboxq->vport) {
  4999. lpfc_debugfs_disc_trc(mboxq->vport,
  5000. LPFC_DISC_TRC_MBOX_VPORT,
  5001. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  5002. mbx_cmnd, mqe->un.mb_words[0],
  5003. mqe->un.mb_words[1]);
  5004. } else {
  5005. lpfc_debugfs_disc_trc(phba->pport,
  5006. LPFC_DISC_TRC_MBOX,
  5007. "MBOX Send: cmd:x%x mb:x%x x%x",
  5008. mbx_cmnd, mqe->un.mb_words[0],
  5009. mqe->un.mb_words[1]);
  5010. }
  5011. }
  5012. psli->slistat.mbox_cmd++;
  5013. /* Post the mailbox command to the port */
  5014. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  5015. if (rc != MBX_SUCCESS) {
  5016. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5017. "(%d):2533 Mailbox command x%x (x%x) "
  5018. "cannot issue Data: x%x x%x\n",
  5019. mboxq->vport ? mboxq->vport->vpi : 0,
  5020. mboxq->u.mb.mbxCommand,
  5021. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5022. psli->sli_flag, MBX_NOWAIT);
  5023. goto out_not_finished;
  5024. }
  5025. return rc;
  5026. out_not_finished:
  5027. spin_lock_irqsave(&phba->hbalock, iflags);
  5028. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5029. __lpfc_mbox_cmpl_put(phba, mboxq);
  5030. /* Release the token */
  5031. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5032. phba->sli.mbox_active = NULL;
  5033. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5034. return MBX_NOT_FINISHED;
  5035. }
  5036. /**
  5037. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  5038. * @phba: Pointer to HBA context object.
  5039. * @pmbox: Pointer to mailbox object.
  5040. * @flag: Flag indicating how the mailbox need to be processed.
  5041. *
  5042. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  5043. * the API jump table function pointer from the lpfc_hba struct.
  5044. *
  5045. * Return codes the caller owns the mailbox command after the return of the
  5046. * function.
  5047. **/
  5048. int
  5049. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  5050. {
  5051. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  5052. }
  5053. /**
  5054. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  5055. * @phba: The hba struct for which this call is being executed.
  5056. * @dev_grp: The HBA PCI-Device group number.
  5057. *
  5058. * This routine sets up the mbox interface API function jump table in @phba
  5059. * struct.
  5060. * Returns: 0 - success, -ENODEV - failure.
  5061. **/
  5062. int
  5063. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5064. {
  5065. switch (dev_grp) {
  5066. case LPFC_PCI_DEV_LP:
  5067. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5068. phba->lpfc_sli_handle_slow_ring_event =
  5069. lpfc_sli_handle_slow_ring_event_s3;
  5070. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5071. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5072. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5073. break;
  5074. case LPFC_PCI_DEV_OC:
  5075. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5076. phba->lpfc_sli_handle_slow_ring_event =
  5077. lpfc_sli_handle_slow_ring_event_s4;
  5078. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5079. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5080. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5081. break;
  5082. default:
  5083. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5084. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5085. dev_grp);
  5086. return -ENODEV;
  5087. break;
  5088. }
  5089. return 0;
  5090. }
  5091. /**
  5092. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5093. * @phba: Pointer to HBA context object.
  5094. * @pring: Pointer to driver SLI ring object.
  5095. * @piocb: Pointer to address of newly added command iocb.
  5096. *
  5097. * This function is called with hbalock held to add a command
  5098. * iocb to the txq when SLI layer cannot submit the command iocb
  5099. * to the ring.
  5100. **/
  5101. void
  5102. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5103. struct lpfc_iocbq *piocb)
  5104. {
  5105. /* Insert the caller's iocb in the txq tail for later processing. */
  5106. list_add_tail(&piocb->list, &pring->txq);
  5107. pring->txq_cnt++;
  5108. }
  5109. /**
  5110. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5111. * @phba: Pointer to HBA context object.
  5112. * @pring: Pointer to driver SLI ring object.
  5113. * @piocb: Pointer to address of newly added command iocb.
  5114. *
  5115. * This function is called with hbalock held before a new
  5116. * iocb is submitted to the firmware. This function checks
  5117. * txq to flush the iocbs in txq to Firmware before
  5118. * submitting new iocbs to the Firmware.
  5119. * If there are iocbs in the txq which need to be submitted
  5120. * to firmware, lpfc_sli_next_iocb returns the first element
  5121. * of the txq after dequeuing it from txq.
  5122. * If there is no iocb in the txq then the function will return
  5123. * *piocb and *piocb is set to NULL. Caller needs to check
  5124. * *piocb to find if there are more commands in the txq.
  5125. **/
  5126. static struct lpfc_iocbq *
  5127. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5128. struct lpfc_iocbq **piocb)
  5129. {
  5130. struct lpfc_iocbq * nextiocb;
  5131. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5132. if (!nextiocb) {
  5133. nextiocb = *piocb;
  5134. *piocb = NULL;
  5135. }
  5136. return nextiocb;
  5137. }
  5138. /**
  5139. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5140. * @phba: Pointer to HBA context object.
  5141. * @ring_number: SLI ring number to issue iocb on.
  5142. * @piocb: Pointer to command iocb.
  5143. * @flag: Flag indicating if this command can be put into txq.
  5144. *
  5145. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5146. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5147. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5148. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5149. * this function allows only iocbs for posting buffers. This function finds
  5150. * next available slot in the command ring and posts the command to the
  5151. * available slot and writes the port attention register to request HBA start
  5152. * processing new iocb. If there is no slot available in the ring and
  5153. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5154. * the function returns IOCB_BUSY.
  5155. *
  5156. * This function is called with hbalock held. The function will return success
  5157. * after it successfully submit the iocb to firmware or after adding to the
  5158. * txq.
  5159. **/
  5160. static int
  5161. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5162. struct lpfc_iocbq *piocb, uint32_t flag)
  5163. {
  5164. struct lpfc_iocbq *nextiocb;
  5165. IOCB_t *iocb;
  5166. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5167. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5168. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5169. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5170. lpfc_printf_log(phba, KERN_ERR,
  5171. LOG_SLI | LOG_VPORT,
  5172. "1807 IOCB x%x failed. No vport\n",
  5173. piocb->iocb.ulpCommand);
  5174. dump_stack();
  5175. return IOCB_ERROR;
  5176. }
  5177. /* If the PCI channel is in offline state, do not post iocbs. */
  5178. if (unlikely(pci_channel_offline(phba->pcidev)))
  5179. return IOCB_ERROR;
  5180. /* If HBA has a deferred error attention, fail the iocb. */
  5181. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5182. return IOCB_ERROR;
  5183. /*
  5184. * We should never get an IOCB if we are in a < LINK_DOWN state
  5185. */
  5186. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5187. return IOCB_ERROR;
  5188. /*
  5189. * Check to see if we are blocking IOCB processing because of a
  5190. * outstanding event.
  5191. */
  5192. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5193. goto iocb_busy;
  5194. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5195. /*
  5196. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5197. * can be issued if the link is not up.
  5198. */
  5199. switch (piocb->iocb.ulpCommand) {
  5200. case CMD_GEN_REQUEST64_CR:
  5201. case CMD_GEN_REQUEST64_CX:
  5202. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5203. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5204. FC_RCTL_DD_UNSOL_CMD) ||
  5205. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5206. MENLO_TRANSPORT_TYPE))
  5207. goto iocb_busy;
  5208. break;
  5209. case CMD_QUE_RING_BUF_CN:
  5210. case CMD_QUE_RING_BUF64_CN:
  5211. /*
  5212. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5213. * completion, iocb_cmpl MUST be 0.
  5214. */
  5215. if (piocb->iocb_cmpl)
  5216. piocb->iocb_cmpl = NULL;
  5217. /*FALLTHROUGH*/
  5218. case CMD_CREATE_XRI_CR:
  5219. case CMD_CLOSE_XRI_CN:
  5220. case CMD_CLOSE_XRI_CX:
  5221. break;
  5222. default:
  5223. goto iocb_busy;
  5224. }
  5225. /*
  5226. * For FCP commands, we must be in a state where we can process link
  5227. * attention events.
  5228. */
  5229. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5230. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5231. goto iocb_busy;
  5232. }
  5233. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5234. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5235. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5236. if (iocb)
  5237. lpfc_sli_update_ring(phba, pring);
  5238. else
  5239. lpfc_sli_update_full_ring(phba, pring);
  5240. if (!piocb)
  5241. return IOCB_SUCCESS;
  5242. goto out_busy;
  5243. iocb_busy:
  5244. pring->stats.iocb_cmd_delay++;
  5245. out_busy:
  5246. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5247. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5248. return IOCB_SUCCESS;
  5249. }
  5250. return IOCB_BUSY;
  5251. }
  5252. /**
  5253. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5254. * @phba: Pointer to HBA context object.
  5255. * @piocb: Pointer to command iocb.
  5256. * @sglq: Pointer to the scatter gather queue object.
  5257. *
  5258. * This routine converts the bpl or bde that is in the IOCB
  5259. * to a sgl list for the sli4 hardware. The physical address
  5260. * of the bpl/bde is converted back to a virtual address.
  5261. * If the IOCB contains a BPL then the list of BDE's is
  5262. * converted to sli4_sge's. If the IOCB contains a single
  5263. * BDE then it is converted to a single sli_sge.
  5264. * The IOCB is still in cpu endianess so the contents of
  5265. * the bpl can be used without byte swapping.
  5266. *
  5267. * Returns valid XRI = Success, NO_XRI = Failure.
  5268. **/
  5269. static uint16_t
  5270. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5271. struct lpfc_sglq *sglq)
  5272. {
  5273. uint16_t xritag = NO_XRI;
  5274. struct ulp_bde64 *bpl = NULL;
  5275. struct ulp_bde64 bde;
  5276. struct sli4_sge *sgl = NULL;
  5277. IOCB_t *icmd;
  5278. int numBdes = 0;
  5279. int i = 0;
  5280. if (!piocbq || !sglq)
  5281. return xritag;
  5282. sgl = (struct sli4_sge *)sglq->sgl;
  5283. icmd = &piocbq->iocb;
  5284. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5285. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5286. sizeof(struct ulp_bde64);
  5287. /* The addrHigh and addrLow fields within the IOCB
  5288. * have not been byteswapped yet so there is no
  5289. * need to swap them back.
  5290. */
  5291. bpl = (struct ulp_bde64 *)
  5292. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5293. if (!bpl)
  5294. return xritag;
  5295. for (i = 0; i < numBdes; i++) {
  5296. /* Should already be byte swapped. */
  5297. sgl->addr_hi = bpl->addrHigh;
  5298. sgl->addr_lo = bpl->addrLow;
  5299. if ((i+1) == numBdes)
  5300. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5301. else
  5302. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5303. sgl->word2 = cpu_to_le32(sgl->word2);
  5304. /* swap the size field back to the cpu so we
  5305. * can assign it to the sgl.
  5306. */
  5307. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5308. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5309. bpl++;
  5310. sgl++;
  5311. }
  5312. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5313. /* The addrHigh and addrLow fields of the BDE have not
  5314. * been byteswapped yet so they need to be swapped
  5315. * before putting them in the sgl.
  5316. */
  5317. sgl->addr_hi =
  5318. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5319. sgl->addr_lo =
  5320. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5321. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5322. sgl->word2 = cpu_to_le32(sgl->word2);
  5323. sgl->sge_len =
  5324. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5325. }
  5326. return sglq->sli4_xritag;
  5327. }
  5328. /**
  5329. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5330. * @phba: Pointer to HBA context object.
  5331. *
  5332. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5333. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5334. * held.
  5335. *
  5336. * Return: index into SLI4 fast-path FCP queue index.
  5337. **/
  5338. static uint32_t
  5339. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5340. {
  5341. ++phba->fcp_qidx;
  5342. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5343. phba->fcp_qidx = 0;
  5344. return phba->fcp_qidx;
  5345. }
  5346. /**
  5347. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5348. * @phba: Pointer to HBA context object.
  5349. * @piocb: Pointer to command iocb.
  5350. * @wqe: Pointer to the work queue entry.
  5351. *
  5352. * This routine converts the iocb command to its Work Queue Entry
  5353. * equivalent. The wqe pointer should not have any fields set when
  5354. * this routine is called because it will memcpy over them.
  5355. * This routine does not set the CQ_ID or the WQEC bits in the
  5356. * wqe.
  5357. *
  5358. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5359. **/
  5360. static int
  5361. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5362. union lpfc_wqe *wqe)
  5363. {
  5364. uint32_t xmit_len = 0, total_len = 0;
  5365. uint8_t ct = 0;
  5366. uint32_t fip;
  5367. uint32_t abort_tag;
  5368. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5369. uint8_t cmnd;
  5370. uint16_t xritag;
  5371. struct ulp_bde64 *bpl = NULL;
  5372. uint32_t els_id = ELS_ID_DEFAULT;
  5373. int numBdes, i;
  5374. struct ulp_bde64 bde;
  5375. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5376. /* The fcp commands will set command type */
  5377. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5378. command_type = FCP_COMMAND;
  5379. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5380. command_type = ELS_COMMAND_FIP;
  5381. else
  5382. command_type = ELS_COMMAND_NON_FIP;
  5383. /* Some of the fields are in the right position already */
  5384. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5385. abort_tag = (uint32_t) iocbq->iotag;
  5386. xritag = iocbq->sli4_xritag;
  5387. wqe->words[7] = 0; /* The ct field has moved so reset */
  5388. /* words0-2 bpl convert bde */
  5389. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5390. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5391. sizeof(struct ulp_bde64);
  5392. bpl = (struct ulp_bde64 *)
  5393. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5394. if (!bpl)
  5395. return IOCB_ERROR;
  5396. /* Should already be byte swapped. */
  5397. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5398. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5399. /* swap the size field back to the cpu so we
  5400. * can assign it to the sgl.
  5401. */
  5402. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5403. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5404. total_len = 0;
  5405. for (i = 0; i < numBdes; i++) {
  5406. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5407. total_len += bde.tus.f.bdeSize;
  5408. }
  5409. } else
  5410. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5411. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5412. cmnd = iocbq->iocb.ulpCommand;
  5413. switch (iocbq->iocb.ulpCommand) {
  5414. case CMD_ELS_REQUEST64_CR:
  5415. if (!iocbq->iocb.ulpLe) {
  5416. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5417. "2007 Only Limited Edition cmd Format"
  5418. " supported 0x%x\n",
  5419. iocbq->iocb.ulpCommand);
  5420. return IOCB_ERROR;
  5421. }
  5422. wqe->els_req.payload_len = xmit_len;
  5423. /* Els_reguest64 has a TMO */
  5424. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5425. iocbq->iocb.ulpTimeout);
  5426. /* Need a VF for word 4 set the vf bit*/
  5427. bf_set(els_req64_vf, &wqe->els_req, 0);
  5428. /* And a VFID for word 12 */
  5429. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5430. /*
  5431. * Set ct field to 3, indicates that the context_tag field
  5432. * contains the FCFI and remote N_Port_ID is
  5433. * in word 5.
  5434. */
  5435. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5436. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5437. iocbq->iocb.ulpContext);
  5438. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5439. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5440. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5441. if (command_type == ELS_COMMAND_FIP) {
  5442. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5443. >> LPFC_FIP_ELS_ID_SHIFT);
  5444. }
  5445. bf_set(lpfc_wqe_gen_els_id, &wqe->generic, els_id);
  5446. break;
  5447. case CMD_XMIT_SEQUENCE64_CX:
  5448. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5449. iocbq->iocb.un.ulpWord[3]);
  5450. wqe->generic.word3 = 0;
  5451. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5452. /* The entire sequence is transmitted for this IOCB */
  5453. xmit_len = total_len;
  5454. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5455. case CMD_XMIT_SEQUENCE64_CR:
  5456. /* word3 iocb=io_tag32 wqe=payload_offset */
  5457. /* payload offset used for multilpe outstanding
  5458. * sequences on the same exchange
  5459. */
  5460. wqe->words[3] = 0;
  5461. /* word4 relative_offset memcpy */
  5462. /* word5 r_ctl/df_ctl memcpy */
  5463. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5464. wqe->xmit_sequence.xmit_len = xmit_len;
  5465. command_type = OTHER_COMMAND;
  5466. break;
  5467. case CMD_XMIT_BCAST64_CN:
  5468. /* word3 iocb=iotag32 wqe=payload_len */
  5469. wqe->words[3] = 0; /* no definition for this in wqe */
  5470. /* word4 iocb=rsvd wqe=rsvd */
  5471. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5472. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5473. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5474. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5475. break;
  5476. case CMD_FCP_IWRITE64_CR:
  5477. command_type = FCP_COMMAND_DATA_OUT;
  5478. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5479. * confusing.
  5480. * word3 is payload_len: byte offset to the sgl entry for the
  5481. * fcp_command.
  5482. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5483. * word5 is initial xfer len 0 = wait for xfer-ready
  5484. */
  5485. /* Always wait for xfer-ready before sending data */
  5486. wqe->fcp_iwrite.initial_xfer_len = 0;
  5487. /* word 4 (xfer length) should have been set on the memcpy */
  5488. /* allow write to fall through to read */
  5489. case CMD_FCP_IREAD64_CR:
  5490. /* FCP_CMD is always the 1st sgl entry */
  5491. wqe->fcp_iread.payload_len =
  5492. xmit_len + sizeof(struct fcp_rsp);
  5493. /* word 4 (xfer length) should have been set on the memcpy */
  5494. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5495. iocbq->iocb.ulpFCP2Rcvy);
  5496. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5497. /* The XC bit and the XS bit are similar. The driver never
  5498. * tracked whether or not the exchange was previouslly open.
  5499. * XC = Exchange create, 0 is create. 1 is already open.
  5500. * XS = link cmd: 1 do not close the exchange after command.
  5501. * XS = 0 close exchange when command completes.
  5502. * The only time we would not set the XC bit is when the XS bit
  5503. * is set and we are sending our 2nd or greater command on
  5504. * this exchange.
  5505. */
  5506. /* Always open the exchange */
  5507. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5508. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5509. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5510. break;
  5511. case CMD_FCP_ICMND64_CR:
  5512. /* Always open the exchange */
  5513. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5514. wqe->words[4] = 0;
  5515. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5516. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5517. break;
  5518. case CMD_GEN_REQUEST64_CR:
  5519. /* word3 command length is described as byte offset to the
  5520. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5521. * sgl[0] = cmnd
  5522. * sgl[1] = rsp.
  5523. *
  5524. */
  5525. wqe->gen_req.command_len = xmit_len;
  5526. /* Word4 parameter copied in the memcpy */
  5527. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5528. /* word6 context tag copied in memcpy */
  5529. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5530. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5531. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5532. "2015 Invalid CT %x command 0x%x\n",
  5533. ct, iocbq->iocb.ulpCommand);
  5534. return IOCB_ERROR;
  5535. }
  5536. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5537. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5538. iocbq->iocb.ulpTimeout);
  5539. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5540. command_type = OTHER_COMMAND;
  5541. break;
  5542. case CMD_XMIT_ELS_RSP64_CX:
  5543. /* words0-2 BDE memcpy */
  5544. /* word3 iocb=iotag32 wqe=rsvd */
  5545. wqe->words[3] = 0;
  5546. /* word4 iocb=did wge=rsvd. */
  5547. wqe->words[4] = 0;
  5548. /* word5 iocb=rsvd wge=did */
  5549. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5550. iocbq->iocb.un.elsreq64.remoteID);
  5551. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5552. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5553. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5554. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5555. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5556. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5557. iocbq->vport->vpi + phba->vpi_base);
  5558. command_type = OTHER_COMMAND;
  5559. break;
  5560. case CMD_CLOSE_XRI_CN:
  5561. case CMD_ABORT_XRI_CN:
  5562. case CMD_ABORT_XRI_CX:
  5563. /* words 0-2 memcpy should be 0 rserved */
  5564. /* port will send abts */
  5565. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5566. /*
  5567. * The link is down so the fw does not need to send abts
  5568. * on the wire.
  5569. */
  5570. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5571. else
  5572. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5573. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5574. wqe->words[5] = 0;
  5575. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5576. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5577. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5578. /*
  5579. * The abort handler will send us CMD_ABORT_XRI_CN or
  5580. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5581. */
  5582. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5583. cmnd = CMD_ABORT_XRI_CX;
  5584. command_type = OTHER_COMMAND;
  5585. xritag = 0;
  5586. break;
  5587. case CMD_XMIT_BLS_RSP64_CX:
  5588. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  5589. * we re-construct this WQE here based on information in
  5590. * iocbq from scratch.
  5591. */
  5592. memset(wqe, 0, sizeof(union lpfc_wqe));
  5593. /* OX_ID is invariable to who sent ABTS to CT exchange */
  5594. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  5595. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  5596. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  5597. LPFC_ABTS_UNSOL_INT) {
  5598. /* ABTS sent by initiator to CT exchange, the
  5599. * RX_ID field will be filled with the newly
  5600. * allocated responder XRI.
  5601. */
  5602. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5603. iocbq->sli4_xritag);
  5604. } else {
  5605. /* ABTS sent by responder to CT exchange, the
  5606. * RX_ID field will be filled with the responder
  5607. * RX_ID from ABTS.
  5608. */
  5609. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5610. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  5611. }
  5612. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  5613. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  5614. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  5615. iocbq->iocb.ulpContext);
  5616. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  5617. command_type = OTHER_COMMAND;
  5618. break;
  5619. case CMD_XRI_ABORTED_CX:
  5620. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5621. /* words0-2 are all 0's no bde */
  5622. /* word3 and word4 are rsvrd */
  5623. wqe->words[3] = 0;
  5624. wqe->words[4] = 0;
  5625. /* word5 iocb=rsvd wge=did */
  5626. /* There is no remote port id in the IOCB? */
  5627. /* Let this fall through and fail */
  5628. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5629. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5630. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5631. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5632. default:
  5633. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5634. "2014 Invalid command 0x%x\n",
  5635. iocbq->iocb.ulpCommand);
  5636. return IOCB_ERROR;
  5637. break;
  5638. }
  5639. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5640. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5641. wqe->generic.abort_tag = abort_tag;
  5642. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5643. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5644. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5645. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5646. return 0;
  5647. }
  5648. /**
  5649. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5650. * @phba: Pointer to HBA context object.
  5651. * @ring_number: SLI ring number to issue iocb on.
  5652. * @piocb: Pointer to command iocb.
  5653. * @flag: Flag indicating if this command can be put into txq.
  5654. *
  5655. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5656. * an iocb command to an HBA with SLI-4 interface spec.
  5657. *
  5658. * This function is called with hbalock held. The function will return success
  5659. * after it successfully submit the iocb to firmware or after adding to the
  5660. * txq.
  5661. **/
  5662. static int
  5663. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5664. struct lpfc_iocbq *piocb, uint32_t flag)
  5665. {
  5666. struct lpfc_sglq *sglq;
  5667. union lpfc_wqe wqe;
  5668. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5669. if (piocb->sli4_xritag == NO_XRI) {
  5670. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5671. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5672. sglq = NULL;
  5673. else {
  5674. if (pring->txq_cnt) {
  5675. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5676. __lpfc_sli_ringtx_put(phba,
  5677. pring, piocb);
  5678. return IOCB_SUCCESS;
  5679. } else {
  5680. return IOCB_BUSY;
  5681. }
  5682. } else {
  5683. sglq = __lpfc_sli_get_sglq(phba);
  5684. if (!sglq) {
  5685. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5686. __lpfc_sli_ringtx_put(phba,
  5687. pring,
  5688. piocb);
  5689. return IOCB_SUCCESS;
  5690. } else
  5691. return IOCB_BUSY;
  5692. }
  5693. }
  5694. }
  5695. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5696. sglq = NULL; /* These IO's already have an XRI and
  5697. * a mapped sgl.
  5698. */
  5699. } else {
  5700. /* This is a continuation of a commandi,(CX) so this
  5701. * sglq is on the active list
  5702. */
  5703. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5704. if (!sglq)
  5705. return IOCB_ERROR;
  5706. }
  5707. if (sglq) {
  5708. piocb->sli4_xritag = sglq->sli4_xritag;
  5709. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  5710. return IOCB_ERROR;
  5711. }
  5712. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5713. return IOCB_ERROR;
  5714. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  5715. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  5716. /*
  5717. * For FCP command IOCB, get a new WQ index to distribute
  5718. * WQE across the WQsr. On the other hand, for abort IOCB,
  5719. * it carries the same WQ index to the original command
  5720. * IOCB.
  5721. */
  5722. if (piocb->iocb_flag & LPFC_IO_FCP)
  5723. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5724. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  5725. &wqe))
  5726. return IOCB_ERROR;
  5727. } else {
  5728. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5729. return IOCB_ERROR;
  5730. }
  5731. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5732. return 0;
  5733. }
  5734. /**
  5735. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5736. *
  5737. * This routine wraps the actual lockless version for issusing IOCB function
  5738. * pointer from the lpfc_hba struct.
  5739. *
  5740. * Return codes:
  5741. * IOCB_ERROR - Error
  5742. * IOCB_SUCCESS - Success
  5743. * IOCB_BUSY - Busy
  5744. **/
  5745. int
  5746. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5747. struct lpfc_iocbq *piocb, uint32_t flag)
  5748. {
  5749. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5750. }
  5751. /**
  5752. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5753. * @phba: The hba struct for which this call is being executed.
  5754. * @dev_grp: The HBA PCI-Device group number.
  5755. *
  5756. * This routine sets up the SLI interface API function jump table in @phba
  5757. * struct.
  5758. * Returns: 0 - success, -ENODEV - failure.
  5759. **/
  5760. int
  5761. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5762. {
  5763. switch (dev_grp) {
  5764. case LPFC_PCI_DEV_LP:
  5765. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5766. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5767. break;
  5768. case LPFC_PCI_DEV_OC:
  5769. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5770. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5771. break;
  5772. default:
  5773. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5774. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5775. dev_grp);
  5776. return -ENODEV;
  5777. break;
  5778. }
  5779. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5780. return 0;
  5781. }
  5782. /**
  5783. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5784. * @phba: Pointer to HBA context object.
  5785. * @pring: Pointer to driver SLI ring object.
  5786. * @piocb: Pointer to command iocb.
  5787. * @flag: Flag indicating if this command can be put into txq.
  5788. *
  5789. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5790. * function. This function gets the hbalock and calls
  5791. * __lpfc_sli_issue_iocb function and will return the error returned
  5792. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5793. * functions which do not hold hbalock.
  5794. **/
  5795. int
  5796. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5797. struct lpfc_iocbq *piocb, uint32_t flag)
  5798. {
  5799. unsigned long iflags;
  5800. int rc;
  5801. spin_lock_irqsave(&phba->hbalock, iflags);
  5802. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5803. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5804. return rc;
  5805. }
  5806. /**
  5807. * lpfc_extra_ring_setup - Extra ring setup function
  5808. * @phba: Pointer to HBA context object.
  5809. *
  5810. * This function is called while driver attaches with the
  5811. * HBA to setup the extra ring. The extra ring is used
  5812. * only when driver needs to support target mode functionality
  5813. * or IP over FC functionalities.
  5814. *
  5815. * This function is called with no lock held.
  5816. **/
  5817. static int
  5818. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5819. {
  5820. struct lpfc_sli *psli;
  5821. struct lpfc_sli_ring *pring;
  5822. psli = &phba->sli;
  5823. /* Adjust cmd/rsp ring iocb entries more evenly */
  5824. /* Take some away from the FCP ring */
  5825. pring = &psli->ring[psli->fcp_ring];
  5826. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5827. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5828. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5829. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5830. /* and give them to the extra ring */
  5831. pring = &psli->ring[psli->extra_ring];
  5832. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5833. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5834. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5835. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5836. /* Setup default profile for this ring */
  5837. pring->iotag_max = 4096;
  5838. pring->num_mask = 1;
  5839. pring->prt[0].profile = 0; /* Mask 0 */
  5840. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5841. pring->prt[0].type = phba->cfg_multi_ring_type;
  5842. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5843. return 0;
  5844. }
  5845. /**
  5846. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5847. * @phba: Pointer to HBA context object.
  5848. * @pring: Pointer to driver SLI ring object.
  5849. * @iocbq: Pointer to iocb object.
  5850. *
  5851. * This function is called by the slow ring event handler
  5852. * function when there is an ASYNC event iocb in the ring.
  5853. * This function is called with no lock held.
  5854. * Currently this function handles only temperature related
  5855. * ASYNC events. The function decodes the temperature sensor
  5856. * event message and posts events for the management applications.
  5857. **/
  5858. static void
  5859. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5860. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5861. {
  5862. IOCB_t *icmd;
  5863. uint16_t evt_code;
  5864. uint16_t temp;
  5865. struct temp_event temp_event_data;
  5866. struct Scsi_Host *shost;
  5867. uint32_t *iocb_w;
  5868. icmd = &iocbq->iocb;
  5869. evt_code = icmd->un.asyncstat.evt_code;
  5870. temp = icmd->ulpContext;
  5871. if ((evt_code != ASYNC_TEMP_WARN) &&
  5872. (evt_code != ASYNC_TEMP_SAFE)) {
  5873. iocb_w = (uint32_t *) icmd;
  5874. lpfc_printf_log(phba,
  5875. KERN_ERR,
  5876. LOG_SLI,
  5877. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5878. " evt_code 0x%x\n"
  5879. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5880. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5881. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5882. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5883. pring->ringno,
  5884. icmd->un.asyncstat.evt_code,
  5885. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5886. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5887. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5888. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5889. return;
  5890. }
  5891. temp_event_data.data = (uint32_t)temp;
  5892. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5893. if (evt_code == ASYNC_TEMP_WARN) {
  5894. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5895. lpfc_printf_log(phba,
  5896. KERN_ERR,
  5897. LOG_TEMP,
  5898. "0347 Adapter is very hot, please take "
  5899. "corrective action. temperature : %d Celsius\n",
  5900. temp);
  5901. }
  5902. if (evt_code == ASYNC_TEMP_SAFE) {
  5903. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5904. lpfc_printf_log(phba,
  5905. KERN_ERR,
  5906. LOG_TEMP,
  5907. "0340 Adapter temperature is OK now. "
  5908. "temperature : %d Celsius\n",
  5909. temp);
  5910. }
  5911. /* Send temperature change event to applications */
  5912. shost = lpfc_shost_from_vport(phba->pport);
  5913. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5914. sizeof(temp_event_data), (char *) &temp_event_data,
  5915. LPFC_NL_VENDOR_ID);
  5916. }
  5917. /**
  5918. * lpfc_sli_setup - SLI ring setup function
  5919. * @phba: Pointer to HBA context object.
  5920. *
  5921. * lpfc_sli_setup sets up rings of the SLI interface with
  5922. * number of iocbs per ring and iotags. This function is
  5923. * called while driver attach to the HBA and before the
  5924. * interrupts are enabled. So there is no need for locking.
  5925. *
  5926. * This function always returns 0.
  5927. **/
  5928. int
  5929. lpfc_sli_setup(struct lpfc_hba *phba)
  5930. {
  5931. int i, totiocbsize = 0;
  5932. struct lpfc_sli *psli = &phba->sli;
  5933. struct lpfc_sli_ring *pring;
  5934. psli->num_rings = MAX_CONFIGURED_RINGS;
  5935. psli->sli_flag = 0;
  5936. psli->fcp_ring = LPFC_FCP_RING;
  5937. psli->next_ring = LPFC_FCP_NEXT_RING;
  5938. psli->extra_ring = LPFC_EXTRA_RING;
  5939. psli->iocbq_lookup = NULL;
  5940. psli->iocbq_lookup_len = 0;
  5941. psli->last_iotag = 0;
  5942. for (i = 0; i < psli->num_rings; i++) {
  5943. pring = &psli->ring[i];
  5944. switch (i) {
  5945. case LPFC_FCP_RING: /* ring 0 - FCP */
  5946. /* numCiocb and numRiocb are used in config_port */
  5947. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5948. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5949. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5950. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5951. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5952. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5953. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5954. SLI3_IOCB_CMD_SIZE :
  5955. SLI2_IOCB_CMD_SIZE;
  5956. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5957. SLI3_IOCB_RSP_SIZE :
  5958. SLI2_IOCB_RSP_SIZE;
  5959. pring->iotag_ctr = 0;
  5960. pring->iotag_max =
  5961. (phba->cfg_hba_queue_depth * 2);
  5962. pring->fast_iotag = pring->iotag_max;
  5963. pring->num_mask = 0;
  5964. break;
  5965. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5966. /* numCiocb and numRiocb are used in config_port */
  5967. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5968. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5969. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5970. SLI3_IOCB_CMD_SIZE :
  5971. SLI2_IOCB_CMD_SIZE;
  5972. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5973. SLI3_IOCB_RSP_SIZE :
  5974. SLI2_IOCB_RSP_SIZE;
  5975. pring->iotag_max = phba->cfg_hba_queue_depth;
  5976. pring->num_mask = 0;
  5977. break;
  5978. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5979. /* numCiocb and numRiocb are used in config_port */
  5980. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5981. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5982. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5983. SLI3_IOCB_CMD_SIZE :
  5984. SLI2_IOCB_CMD_SIZE;
  5985. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5986. SLI3_IOCB_RSP_SIZE :
  5987. SLI2_IOCB_RSP_SIZE;
  5988. pring->fast_iotag = 0;
  5989. pring->iotag_ctr = 0;
  5990. pring->iotag_max = 4096;
  5991. pring->lpfc_sli_rcv_async_status =
  5992. lpfc_sli_async_event_handler;
  5993. pring->num_mask = LPFC_MAX_RING_MASK;
  5994. pring->prt[0].profile = 0; /* Mask 0 */
  5995. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  5996. pring->prt[0].type = FC_TYPE_ELS;
  5997. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5998. lpfc_els_unsol_event;
  5999. pring->prt[1].profile = 0; /* Mask 1 */
  6000. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  6001. pring->prt[1].type = FC_TYPE_ELS;
  6002. pring->prt[1].lpfc_sli_rcv_unsol_event =
  6003. lpfc_els_unsol_event;
  6004. pring->prt[2].profile = 0; /* Mask 2 */
  6005. /* NameServer Inquiry */
  6006. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  6007. /* NameServer */
  6008. pring->prt[2].type = FC_TYPE_CT;
  6009. pring->prt[2].lpfc_sli_rcv_unsol_event =
  6010. lpfc_ct_unsol_event;
  6011. pring->prt[3].profile = 0; /* Mask 3 */
  6012. /* NameServer response */
  6013. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  6014. /* NameServer */
  6015. pring->prt[3].type = FC_TYPE_CT;
  6016. pring->prt[3].lpfc_sli_rcv_unsol_event =
  6017. lpfc_ct_unsol_event;
  6018. /* abort unsolicited sequence */
  6019. pring->prt[4].profile = 0; /* Mask 4 */
  6020. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  6021. pring->prt[4].type = FC_TYPE_BLS;
  6022. pring->prt[4].lpfc_sli_rcv_unsol_event =
  6023. lpfc_sli4_ct_abort_unsol_event;
  6024. break;
  6025. }
  6026. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  6027. (pring->numRiocb * pring->sizeRiocb);
  6028. }
  6029. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  6030. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  6031. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  6032. "SLI2 SLIM Data: x%x x%lx\n",
  6033. phba->brd_no, totiocbsize,
  6034. (unsigned long) MAX_SLIM_IOCB_SIZE);
  6035. }
  6036. if (phba->cfg_multi_ring_support == 2)
  6037. lpfc_extra_ring_setup(phba);
  6038. return 0;
  6039. }
  6040. /**
  6041. * lpfc_sli_queue_setup - Queue initialization function
  6042. * @phba: Pointer to HBA context object.
  6043. *
  6044. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  6045. * ring. This function also initializes ring indices of each ring.
  6046. * This function is called during the initialization of the SLI
  6047. * interface of an HBA.
  6048. * This function is called with no lock held and always returns
  6049. * 1.
  6050. **/
  6051. int
  6052. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  6053. {
  6054. struct lpfc_sli *psli;
  6055. struct lpfc_sli_ring *pring;
  6056. int i;
  6057. psli = &phba->sli;
  6058. spin_lock_irq(&phba->hbalock);
  6059. INIT_LIST_HEAD(&psli->mboxq);
  6060. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  6061. /* Initialize list headers for txq and txcmplq as double linked lists */
  6062. for (i = 0; i < psli->num_rings; i++) {
  6063. pring = &psli->ring[i];
  6064. pring->ringno = i;
  6065. pring->next_cmdidx = 0;
  6066. pring->local_getidx = 0;
  6067. pring->cmdidx = 0;
  6068. INIT_LIST_HEAD(&pring->txq);
  6069. INIT_LIST_HEAD(&pring->txcmplq);
  6070. INIT_LIST_HEAD(&pring->iocb_continueq);
  6071. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  6072. INIT_LIST_HEAD(&pring->postbufq);
  6073. }
  6074. spin_unlock_irq(&phba->hbalock);
  6075. return 1;
  6076. }
  6077. /**
  6078. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  6079. * @phba: Pointer to HBA context object.
  6080. *
  6081. * This routine flushes the mailbox command subsystem. It will unconditionally
  6082. * flush all the mailbox commands in the three possible stages in the mailbox
  6083. * command sub-system: pending mailbox command queue; the outstanding mailbox
  6084. * command; and completed mailbox command queue. It is caller's responsibility
  6085. * to make sure that the driver is in the proper state to flush the mailbox
  6086. * command sub-system. Namely, the posting of mailbox commands into the
  6087. * pending mailbox command queue from the various clients must be stopped;
  6088. * either the HBA is in a state that it will never works on the outstanding
  6089. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6090. * mailbox command has been completed.
  6091. **/
  6092. static void
  6093. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6094. {
  6095. LIST_HEAD(completions);
  6096. struct lpfc_sli *psli = &phba->sli;
  6097. LPFC_MBOXQ_t *pmb;
  6098. unsigned long iflag;
  6099. /* Flush all the mailbox commands in the mbox system */
  6100. spin_lock_irqsave(&phba->hbalock, iflag);
  6101. /* The pending mailbox command queue */
  6102. list_splice_init(&phba->sli.mboxq, &completions);
  6103. /* The outstanding active mailbox command */
  6104. if (psli->mbox_active) {
  6105. list_add_tail(&psli->mbox_active->list, &completions);
  6106. psli->mbox_active = NULL;
  6107. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6108. }
  6109. /* The completed mailbox command queue */
  6110. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6111. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6112. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6113. while (!list_empty(&completions)) {
  6114. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6115. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6116. if (pmb->mbox_cmpl)
  6117. pmb->mbox_cmpl(phba, pmb);
  6118. }
  6119. }
  6120. /**
  6121. * lpfc_sli_host_down - Vport cleanup function
  6122. * @vport: Pointer to virtual port object.
  6123. *
  6124. * lpfc_sli_host_down is called to clean up the resources
  6125. * associated with a vport before destroying virtual
  6126. * port data structures.
  6127. * This function does following operations:
  6128. * - Free discovery resources associated with this virtual
  6129. * port.
  6130. * - Free iocbs associated with this virtual port in
  6131. * the txq.
  6132. * - Send abort for all iocb commands associated with this
  6133. * vport in txcmplq.
  6134. *
  6135. * This function is called with no lock held and always returns 1.
  6136. **/
  6137. int
  6138. lpfc_sli_host_down(struct lpfc_vport *vport)
  6139. {
  6140. LIST_HEAD(completions);
  6141. struct lpfc_hba *phba = vport->phba;
  6142. struct lpfc_sli *psli = &phba->sli;
  6143. struct lpfc_sli_ring *pring;
  6144. struct lpfc_iocbq *iocb, *next_iocb;
  6145. int i;
  6146. unsigned long flags = 0;
  6147. uint16_t prev_pring_flag;
  6148. lpfc_cleanup_discovery_resources(vport);
  6149. spin_lock_irqsave(&phba->hbalock, flags);
  6150. for (i = 0; i < psli->num_rings; i++) {
  6151. pring = &psli->ring[i];
  6152. prev_pring_flag = pring->flag;
  6153. /* Only slow rings */
  6154. if (pring->ringno == LPFC_ELS_RING) {
  6155. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6156. /* Set the lpfc data pending flag */
  6157. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6158. }
  6159. /*
  6160. * Error everything on the txq since these iocbs have not been
  6161. * given to the FW yet.
  6162. */
  6163. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6164. if (iocb->vport != vport)
  6165. continue;
  6166. list_move_tail(&iocb->list, &completions);
  6167. pring->txq_cnt--;
  6168. }
  6169. /* Next issue ABTS for everything on the txcmplq */
  6170. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6171. list) {
  6172. if (iocb->vport != vport)
  6173. continue;
  6174. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6175. }
  6176. pring->flag = prev_pring_flag;
  6177. }
  6178. spin_unlock_irqrestore(&phba->hbalock, flags);
  6179. /* Cancel all the IOCBs from the completions list */
  6180. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6181. IOERR_SLI_DOWN);
  6182. return 1;
  6183. }
  6184. /**
  6185. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6186. * @phba: Pointer to HBA context object.
  6187. *
  6188. * This function cleans up all iocb, buffers, mailbox commands
  6189. * while shutting down the HBA. This function is called with no
  6190. * lock held and always returns 1.
  6191. * This function does the following to cleanup driver resources:
  6192. * - Free discovery resources for each virtual port
  6193. * - Cleanup any pending fabric iocbs
  6194. * - Iterate through the iocb txq and free each entry
  6195. * in the list.
  6196. * - Free up any buffer posted to the HBA
  6197. * - Free mailbox commands in the mailbox queue.
  6198. **/
  6199. int
  6200. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6201. {
  6202. LIST_HEAD(completions);
  6203. struct lpfc_sli *psli = &phba->sli;
  6204. struct lpfc_sli_ring *pring;
  6205. struct lpfc_dmabuf *buf_ptr;
  6206. unsigned long flags = 0;
  6207. int i;
  6208. /* Shutdown the mailbox command sub-system */
  6209. lpfc_sli_mbox_sys_shutdown(phba);
  6210. lpfc_hba_down_prep(phba);
  6211. lpfc_fabric_abort_hba(phba);
  6212. spin_lock_irqsave(&phba->hbalock, flags);
  6213. for (i = 0; i < psli->num_rings; i++) {
  6214. pring = &psli->ring[i];
  6215. /* Only slow rings */
  6216. if (pring->ringno == LPFC_ELS_RING) {
  6217. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6218. /* Set the lpfc data pending flag */
  6219. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6220. }
  6221. /*
  6222. * Error everything on the txq since these iocbs have not been
  6223. * given to the FW yet.
  6224. */
  6225. list_splice_init(&pring->txq, &completions);
  6226. pring->txq_cnt = 0;
  6227. }
  6228. spin_unlock_irqrestore(&phba->hbalock, flags);
  6229. /* Cancel all the IOCBs from the completions list */
  6230. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6231. IOERR_SLI_DOWN);
  6232. spin_lock_irqsave(&phba->hbalock, flags);
  6233. list_splice_init(&phba->elsbuf, &completions);
  6234. phba->elsbuf_cnt = 0;
  6235. phba->elsbuf_prev_cnt = 0;
  6236. spin_unlock_irqrestore(&phba->hbalock, flags);
  6237. while (!list_empty(&completions)) {
  6238. list_remove_head(&completions, buf_ptr,
  6239. struct lpfc_dmabuf, list);
  6240. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6241. kfree(buf_ptr);
  6242. }
  6243. /* Return any active mbox cmds */
  6244. del_timer_sync(&psli->mbox_tmo);
  6245. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6246. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6247. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6248. return 1;
  6249. }
  6250. /**
  6251. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6252. * @phba: Pointer to HBA context object.
  6253. *
  6254. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6255. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6256. * lock held and always returns 1.
  6257. *
  6258. * This function does the following to cleanup driver FCoE function resources:
  6259. * - Free discovery resources for each virtual port
  6260. * - Cleanup any pending fabric iocbs
  6261. * - Iterate through the iocb txq and free each entry in the list.
  6262. * - Free up any buffer posted to the HBA.
  6263. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6264. * - Free mailbox commands in the mailbox queue.
  6265. **/
  6266. int
  6267. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6268. {
  6269. /* Stop the SLI4 device port */
  6270. lpfc_stop_port(phba);
  6271. /* Tear down the queues in the HBA */
  6272. lpfc_sli4_queue_unset(phba);
  6273. /* unregister default FCFI from the HBA */
  6274. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6275. return 1;
  6276. }
  6277. /**
  6278. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6279. * @srcp: Source memory pointer.
  6280. * @destp: Destination memory pointer.
  6281. * @cnt: Number of words required to be copied.
  6282. *
  6283. * This function is used for copying data between driver memory
  6284. * and the SLI memory. This function also changes the endianness
  6285. * of each word if native endianness is different from SLI
  6286. * endianness. This function can be called with or without
  6287. * lock.
  6288. **/
  6289. void
  6290. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6291. {
  6292. uint32_t *src = srcp;
  6293. uint32_t *dest = destp;
  6294. uint32_t ldata;
  6295. int i;
  6296. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6297. ldata = *src;
  6298. ldata = le32_to_cpu(ldata);
  6299. *dest = ldata;
  6300. src++;
  6301. dest++;
  6302. }
  6303. }
  6304. /**
  6305. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6306. * @srcp: Source memory pointer.
  6307. * @destp: Destination memory pointer.
  6308. * @cnt: Number of words required to be copied.
  6309. *
  6310. * This function is used for copying data between a data structure
  6311. * with big endian representation to local endianness.
  6312. * This function can be called with or without lock.
  6313. **/
  6314. void
  6315. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6316. {
  6317. uint32_t *src = srcp;
  6318. uint32_t *dest = destp;
  6319. uint32_t ldata;
  6320. int i;
  6321. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6322. ldata = *src;
  6323. ldata = be32_to_cpu(ldata);
  6324. *dest = ldata;
  6325. src++;
  6326. dest++;
  6327. }
  6328. }
  6329. /**
  6330. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6331. * @phba: Pointer to HBA context object.
  6332. * @pring: Pointer to driver SLI ring object.
  6333. * @mp: Pointer to driver buffer object.
  6334. *
  6335. * This function is called with no lock held.
  6336. * It always return zero after adding the buffer to the postbufq
  6337. * buffer list.
  6338. **/
  6339. int
  6340. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6341. struct lpfc_dmabuf *mp)
  6342. {
  6343. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6344. later */
  6345. spin_lock_irq(&phba->hbalock);
  6346. list_add_tail(&mp->list, &pring->postbufq);
  6347. pring->postbufq_cnt++;
  6348. spin_unlock_irq(&phba->hbalock);
  6349. return 0;
  6350. }
  6351. /**
  6352. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6353. * @phba: Pointer to HBA context object.
  6354. *
  6355. * When HBQ is enabled, buffers are searched based on tags. This function
  6356. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6357. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6358. * does not conflict with tags of buffer posted for unsolicited events.
  6359. * The function returns the allocated tag. The function is called with
  6360. * no locks held.
  6361. **/
  6362. uint32_t
  6363. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6364. {
  6365. spin_lock_irq(&phba->hbalock);
  6366. phba->buffer_tag_count++;
  6367. /*
  6368. * Always set the QUE_BUFTAG_BIT to distiguish between
  6369. * a tag assigned by HBQ.
  6370. */
  6371. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6372. spin_unlock_irq(&phba->hbalock);
  6373. return phba->buffer_tag_count;
  6374. }
  6375. /**
  6376. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6377. * @phba: Pointer to HBA context object.
  6378. * @pring: Pointer to driver SLI ring object.
  6379. * @tag: Buffer tag.
  6380. *
  6381. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6382. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6383. * iocb is posted to the response ring with the tag of the buffer.
  6384. * This function searches the pring->postbufq list using the tag
  6385. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6386. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6387. * buffer is returned to the caller else NULL is returned.
  6388. * This function is called with no lock held.
  6389. **/
  6390. struct lpfc_dmabuf *
  6391. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6392. uint32_t tag)
  6393. {
  6394. struct lpfc_dmabuf *mp, *next_mp;
  6395. struct list_head *slp = &pring->postbufq;
  6396. /* Search postbufq, from the begining, looking for a match on tag */
  6397. spin_lock_irq(&phba->hbalock);
  6398. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6399. if (mp->buffer_tag == tag) {
  6400. list_del_init(&mp->list);
  6401. pring->postbufq_cnt--;
  6402. spin_unlock_irq(&phba->hbalock);
  6403. return mp;
  6404. }
  6405. }
  6406. spin_unlock_irq(&phba->hbalock);
  6407. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6408. "0402 Cannot find virtual addr for buffer tag on "
  6409. "ring %d Data x%lx x%p x%p x%x\n",
  6410. pring->ringno, (unsigned long) tag,
  6411. slp->next, slp->prev, pring->postbufq_cnt);
  6412. return NULL;
  6413. }
  6414. /**
  6415. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6416. * @phba: Pointer to HBA context object.
  6417. * @pring: Pointer to driver SLI ring object.
  6418. * @phys: DMA address of the buffer.
  6419. *
  6420. * This function searches the buffer list using the dma_address
  6421. * of unsolicited event to find the driver's lpfc_dmabuf object
  6422. * corresponding to the dma_address. The function returns the
  6423. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6424. * This function is called by the ct and els unsolicited event
  6425. * handlers to get the buffer associated with the unsolicited
  6426. * event.
  6427. *
  6428. * This function is called with no lock held.
  6429. **/
  6430. struct lpfc_dmabuf *
  6431. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6432. dma_addr_t phys)
  6433. {
  6434. struct lpfc_dmabuf *mp, *next_mp;
  6435. struct list_head *slp = &pring->postbufq;
  6436. /* Search postbufq, from the begining, looking for a match on phys */
  6437. spin_lock_irq(&phba->hbalock);
  6438. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6439. if (mp->phys == phys) {
  6440. list_del_init(&mp->list);
  6441. pring->postbufq_cnt--;
  6442. spin_unlock_irq(&phba->hbalock);
  6443. return mp;
  6444. }
  6445. }
  6446. spin_unlock_irq(&phba->hbalock);
  6447. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6448. "0410 Cannot find virtual addr for mapped buf on "
  6449. "ring %d Data x%llx x%p x%p x%x\n",
  6450. pring->ringno, (unsigned long long)phys,
  6451. slp->next, slp->prev, pring->postbufq_cnt);
  6452. return NULL;
  6453. }
  6454. /**
  6455. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6456. * @phba: Pointer to HBA context object.
  6457. * @cmdiocb: Pointer to driver command iocb object.
  6458. * @rspiocb: Pointer to driver response iocb object.
  6459. *
  6460. * This function is the completion handler for the abort iocbs for
  6461. * ELS commands. This function is called from the ELS ring event
  6462. * handler with no lock held. This function frees memory resources
  6463. * associated with the abort iocb.
  6464. **/
  6465. static void
  6466. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6467. struct lpfc_iocbq *rspiocb)
  6468. {
  6469. IOCB_t *irsp = &rspiocb->iocb;
  6470. uint16_t abort_iotag, abort_context;
  6471. struct lpfc_iocbq *abort_iocb;
  6472. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6473. abort_iocb = NULL;
  6474. if (irsp->ulpStatus) {
  6475. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6476. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6477. spin_lock_irq(&phba->hbalock);
  6478. if (phba->sli_rev < LPFC_SLI_REV4) {
  6479. if (abort_iotag != 0 &&
  6480. abort_iotag <= phba->sli.last_iotag)
  6481. abort_iocb =
  6482. phba->sli.iocbq_lookup[abort_iotag];
  6483. } else
  6484. /* For sli4 the abort_tag is the XRI,
  6485. * so the abort routine puts the iotag of the iocb
  6486. * being aborted in the context field of the abort
  6487. * IOCB.
  6488. */
  6489. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6490. /*
  6491. * If the iocb is not found in Firmware queue the iocb
  6492. * might have completed already. Do not free it again.
  6493. */
  6494. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6495. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6496. spin_unlock_irq(&phba->hbalock);
  6497. lpfc_sli_release_iocbq(phba, cmdiocb);
  6498. return;
  6499. }
  6500. /* For SLI4 the ulpContext field for abort IOCB
  6501. * holds the iotag of the IOCB being aborted so
  6502. * the local abort_context needs to be reset to
  6503. * match the aborted IOCBs ulpContext.
  6504. */
  6505. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6506. abort_context = abort_iocb->iocb.ulpContext;
  6507. }
  6508. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  6509. "0327 Cannot abort els iocb %p "
  6510. "with tag %x context %x, abort status %x, "
  6511. "abort code %x\n",
  6512. abort_iocb, abort_iotag, abort_context,
  6513. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6514. /*
  6515. * make sure we have the right iocbq before taking it
  6516. * off the txcmplq and try to call completion routine.
  6517. */
  6518. if (!abort_iocb ||
  6519. abort_iocb->iocb.ulpContext != abort_context ||
  6520. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6521. spin_unlock_irq(&phba->hbalock);
  6522. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6523. /*
  6524. * leave the SLI4 aborted command on the txcmplq
  6525. * list and the command complete WCQE's XB bit
  6526. * will tell whether the SGL (XRI) can be released
  6527. * immediately or to the aborted SGL list for the
  6528. * following abort XRI from the HBA.
  6529. */
  6530. list_del_init(&abort_iocb->list);
  6531. if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) {
  6532. abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  6533. pring->txcmplq_cnt--;
  6534. }
  6535. /* Firmware could still be in progress of DMAing
  6536. * payload, so don't free data buffer till after
  6537. * a hbeat.
  6538. */
  6539. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6540. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6541. spin_unlock_irq(&phba->hbalock);
  6542. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6543. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6544. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6545. } else
  6546. spin_unlock_irq(&phba->hbalock);
  6547. }
  6548. lpfc_sli_release_iocbq(phba, cmdiocb);
  6549. return;
  6550. }
  6551. /**
  6552. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6553. * @phba: Pointer to HBA context object.
  6554. * @cmdiocb: Pointer to driver command iocb object.
  6555. * @rspiocb: Pointer to driver response iocb object.
  6556. *
  6557. * The function is called from SLI ring event handler with no
  6558. * lock held. This function is the completion handler for ELS commands
  6559. * which are aborted. The function frees memory resources used for
  6560. * the aborted ELS commands.
  6561. **/
  6562. static void
  6563. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6564. struct lpfc_iocbq *rspiocb)
  6565. {
  6566. IOCB_t *irsp = &rspiocb->iocb;
  6567. /* ELS cmd tag <ulpIoTag> completes */
  6568. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6569. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6570. "x%x x%x x%x\n",
  6571. irsp->ulpIoTag, irsp->ulpStatus,
  6572. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6573. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6574. lpfc_ct_free_iocb(phba, cmdiocb);
  6575. else
  6576. lpfc_els_free_iocb(phba, cmdiocb);
  6577. return;
  6578. }
  6579. /**
  6580. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6581. * @phba: Pointer to HBA context object.
  6582. * @pring: Pointer to driver SLI ring object.
  6583. * @cmdiocb: Pointer to driver command iocb object.
  6584. *
  6585. * This function issues an abort iocb for the provided command
  6586. * iocb. This function is called with hbalock held.
  6587. * The function returns 0 when it fails due to memory allocation
  6588. * failure or when the command iocb is an abort request.
  6589. **/
  6590. int
  6591. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6592. struct lpfc_iocbq *cmdiocb)
  6593. {
  6594. struct lpfc_vport *vport = cmdiocb->vport;
  6595. struct lpfc_iocbq *abtsiocbp;
  6596. IOCB_t *icmd = NULL;
  6597. IOCB_t *iabt = NULL;
  6598. int retval = IOCB_ERROR;
  6599. /*
  6600. * There are certain command types we don't want to abort. And we
  6601. * don't want to abort commands that are already in the process of
  6602. * being aborted.
  6603. */
  6604. icmd = &cmdiocb->iocb;
  6605. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6606. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6607. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6608. return 0;
  6609. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6610. * callback so that nothing happens when it finishes.
  6611. */
  6612. if ((vport->load_flag & FC_UNLOADING) &&
  6613. (pring->ringno == LPFC_ELS_RING)) {
  6614. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6615. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6616. else
  6617. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6618. goto abort_iotag_exit;
  6619. }
  6620. /* issue ABTS for this IOCB based on iotag */
  6621. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6622. if (abtsiocbp == NULL)
  6623. return 0;
  6624. /* This signals the response to set the correct status
  6625. * before calling the completion handler
  6626. */
  6627. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6628. iabt = &abtsiocbp->iocb;
  6629. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6630. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6631. if (phba->sli_rev == LPFC_SLI_REV4) {
  6632. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6633. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  6634. }
  6635. else
  6636. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6637. iabt->ulpLe = 1;
  6638. iabt->ulpClass = icmd->ulpClass;
  6639. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6640. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  6641. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  6642. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  6643. if (phba->link_state >= LPFC_LINK_UP)
  6644. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6645. else
  6646. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6647. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6648. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6649. "0339 Abort xri x%x, original iotag x%x, "
  6650. "abort cmd iotag x%x\n",
  6651. iabt->un.acxri.abortIoTag,
  6652. iabt->un.acxri.abortContextTag,
  6653. abtsiocbp->iotag);
  6654. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6655. if (retval)
  6656. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6657. abort_iotag_exit:
  6658. /*
  6659. * Caller to this routine should check for IOCB_ERROR
  6660. * and handle it properly. This routine no longer removes
  6661. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6662. */
  6663. return retval;
  6664. }
  6665. /**
  6666. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6667. * @iocbq: Pointer to driver iocb object.
  6668. * @vport: Pointer to driver virtual port object.
  6669. * @tgt_id: SCSI ID of the target.
  6670. * @lun_id: LUN ID of the scsi device.
  6671. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6672. *
  6673. * This function acts as an iocb filter for functions which abort or count
  6674. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6675. * 0 if the filtering criteria is met for the given iocb and will return
  6676. * 1 if the filtering criteria is not met.
  6677. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6678. * given iocb is for the SCSI device specified by vport, tgt_id and
  6679. * lun_id parameter.
  6680. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6681. * given iocb is for the SCSI target specified by vport and tgt_id
  6682. * parameters.
  6683. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6684. * given iocb is for the SCSI host associated with the given vport.
  6685. * This function is called with no locks held.
  6686. **/
  6687. static int
  6688. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6689. uint16_t tgt_id, uint64_t lun_id,
  6690. lpfc_ctx_cmd ctx_cmd)
  6691. {
  6692. struct lpfc_scsi_buf *lpfc_cmd;
  6693. int rc = 1;
  6694. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6695. return rc;
  6696. if (iocbq->vport != vport)
  6697. return rc;
  6698. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6699. if (lpfc_cmd->pCmd == NULL)
  6700. return rc;
  6701. switch (ctx_cmd) {
  6702. case LPFC_CTX_LUN:
  6703. if ((lpfc_cmd->rdata->pnode) &&
  6704. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6705. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6706. rc = 0;
  6707. break;
  6708. case LPFC_CTX_TGT:
  6709. if ((lpfc_cmd->rdata->pnode) &&
  6710. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6711. rc = 0;
  6712. break;
  6713. case LPFC_CTX_HOST:
  6714. rc = 0;
  6715. break;
  6716. default:
  6717. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6718. __func__, ctx_cmd);
  6719. break;
  6720. }
  6721. return rc;
  6722. }
  6723. /**
  6724. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6725. * @vport: Pointer to virtual port.
  6726. * @tgt_id: SCSI ID of the target.
  6727. * @lun_id: LUN ID of the scsi device.
  6728. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6729. *
  6730. * This function returns number of FCP commands pending for the vport.
  6731. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6732. * commands pending on the vport associated with SCSI device specified
  6733. * by tgt_id and lun_id parameters.
  6734. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6735. * commands pending on the vport associated with SCSI target specified
  6736. * by tgt_id parameter.
  6737. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6738. * commands pending on the vport.
  6739. * This function returns the number of iocbs which satisfy the filter.
  6740. * This function is called without any lock held.
  6741. **/
  6742. int
  6743. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6744. lpfc_ctx_cmd ctx_cmd)
  6745. {
  6746. struct lpfc_hba *phba = vport->phba;
  6747. struct lpfc_iocbq *iocbq;
  6748. int sum, i;
  6749. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6750. iocbq = phba->sli.iocbq_lookup[i];
  6751. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6752. ctx_cmd) == 0)
  6753. sum++;
  6754. }
  6755. return sum;
  6756. }
  6757. /**
  6758. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6759. * @phba: Pointer to HBA context object
  6760. * @cmdiocb: Pointer to command iocb object.
  6761. * @rspiocb: Pointer to response iocb object.
  6762. *
  6763. * This function is called when an aborted FCP iocb completes. This
  6764. * function is called by the ring event handler with no lock held.
  6765. * This function frees the iocb.
  6766. **/
  6767. void
  6768. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6769. struct lpfc_iocbq *rspiocb)
  6770. {
  6771. lpfc_sli_release_iocbq(phba, cmdiocb);
  6772. return;
  6773. }
  6774. /**
  6775. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6776. * @vport: Pointer to virtual port.
  6777. * @pring: Pointer to driver SLI ring object.
  6778. * @tgt_id: SCSI ID of the target.
  6779. * @lun_id: LUN ID of the scsi device.
  6780. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6781. *
  6782. * This function sends an abort command for every SCSI command
  6783. * associated with the given virtual port pending on the ring
  6784. * filtered by lpfc_sli_validate_fcp_iocb function.
  6785. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6786. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6787. * parameters
  6788. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6789. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6790. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6791. * FCP iocbs associated with virtual port.
  6792. * This function returns number of iocbs it failed to abort.
  6793. * This function is called with no locks held.
  6794. **/
  6795. int
  6796. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6797. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6798. {
  6799. struct lpfc_hba *phba = vport->phba;
  6800. struct lpfc_iocbq *iocbq;
  6801. struct lpfc_iocbq *abtsiocb;
  6802. IOCB_t *cmd = NULL;
  6803. int errcnt = 0, ret_val = 0;
  6804. int i;
  6805. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6806. iocbq = phba->sli.iocbq_lookup[i];
  6807. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6808. abort_cmd) != 0)
  6809. continue;
  6810. /* issue ABTS for this IOCB based on iotag */
  6811. abtsiocb = lpfc_sli_get_iocbq(phba);
  6812. if (abtsiocb == NULL) {
  6813. errcnt++;
  6814. continue;
  6815. }
  6816. cmd = &iocbq->iocb;
  6817. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6818. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6819. if (phba->sli_rev == LPFC_SLI_REV4)
  6820. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6821. else
  6822. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6823. abtsiocb->iocb.ulpLe = 1;
  6824. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6825. abtsiocb->vport = phba->pport;
  6826. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6827. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  6828. if (iocbq->iocb_flag & LPFC_IO_FCP)
  6829. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  6830. if (lpfc_is_link_up(phba))
  6831. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6832. else
  6833. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6834. /* Setup callback routine and issue the command. */
  6835. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6836. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6837. abtsiocb, 0);
  6838. if (ret_val == IOCB_ERROR) {
  6839. lpfc_sli_release_iocbq(phba, abtsiocb);
  6840. errcnt++;
  6841. continue;
  6842. }
  6843. }
  6844. return errcnt;
  6845. }
  6846. /**
  6847. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6848. * @phba: Pointer to HBA context object.
  6849. * @cmdiocbq: Pointer to command iocb.
  6850. * @rspiocbq: Pointer to response iocb.
  6851. *
  6852. * This function is the completion handler for iocbs issued using
  6853. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6854. * ring event handler function without any lock held. This function
  6855. * can be called from both worker thread context and interrupt
  6856. * context. This function also can be called from other thread which
  6857. * cleans up the SLI layer objects.
  6858. * This function copy the contents of the response iocb to the
  6859. * response iocb memory object provided by the caller of
  6860. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6861. * sleeps for the iocb completion.
  6862. **/
  6863. static void
  6864. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6865. struct lpfc_iocbq *cmdiocbq,
  6866. struct lpfc_iocbq *rspiocbq)
  6867. {
  6868. wait_queue_head_t *pdone_q;
  6869. unsigned long iflags;
  6870. struct lpfc_scsi_buf *lpfc_cmd;
  6871. spin_lock_irqsave(&phba->hbalock, iflags);
  6872. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6873. if (cmdiocbq->context2 && rspiocbq)
  6874. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6875. &rspiocbq->iocb, sizeof(IOCB_t));
  6876. /* Set the exchange busy flag for task management commands */
  6877. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  6878. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  6879. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  6880. cur_iocbq);
  6881. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  6882. }
  6883. pdone_q = cmdiocbq->context_un.wait_queue;
  6884. if (pdone_q)
  6885. wake_up(pdone_q);
  6886. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6887. return;
  6888. }
  6889. /**
  6890. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  6891. * @phba: Pointer to HBA context object..
  6892. * @piocbq: Pointer to command iocb.
  6893. * @flag: Flag to test.
  6894. *
  6895. * This routine grabs the hbalock and then test the iocb_flag to
  6896. * see if the passed in flag is set.
  6897. * Returns:
  6898. * 1 if flag is set.
  6899. * 0 if flag is not set.
  6900. **/
  6901. static int
  6902. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  6903. struct lpfc_iocbq *piocbq, uint32_t flag)
  6904. {
  6905. unsigned long iflags;
  6906. int ret;
  6907. spin_lock_irqsave(&phba->hbalock, iflags);
  6908. ret = piocbq->iocb_flag & flag;
  6909. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6910. return ret;
  6911. }
  6912. /**
  6913. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6914. * @phba: Pointer to HBA context object..
  6915. * @pring: Pointer to sli ring.
  6916. * @piocb: Pointer to command iocb.
  6917. * @prspiocbq: Pointer to response iocb.
  6918. * @timeout: Timeout in number of seconds.
  6919. *
  6920. * This function issues the iocb to firmware and waits for the
  6921. * iocb to complete. If the iocb command is not
  6922. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6923. * Caller should not free the iocb resources if this function
  6924. * returns IOCB_TIMEDOUT.
  6925. * The function waits for the iocb completion using an
  6926. * non-interruptible wait.
  6927. * This function will sleep while waiting for iocb completion.
  6928. * So, this function should not be called from any context which
  6929. * does not allow sleeping. Due to the same reason, this function
  6930. * cannot be called with interrupt disabled.
  6931. * This function assumes that the iocb completions occur while
  6932. * this function sleep. So, this function cannot be called from
  6933. * the thread which process iocb completion for this ring.
  6934. * This function clears the iocb_flag of the iocb object before
  6935. * issuing the iocb and the iocb completion handler sets this
  6936. * flag and wakes this thread when the iocb completes.
  6937. * The contents of the response iocb will be copied to prspiocbq
  6938. * by the completion handler when the command completes.
  6939. * This function returns IOCB_SUCCESS when success.
  6940. * This function is called with no lock held.
  6941. **/
  6942. int
  6943. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6944. uint32_t ring_number,
  6945. struct lpfc_iocbq *piocb,
  6946. struct lpfc_iocbq *prspiocbq,
  6947. uint32_t timeout)
  6948. {
  6949. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6950. long timeleft, timeout_req = 0;
  6951. int retval = IOCB_SUCCESS;
  6952. uint32_t creg_val;
  6953. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6954. /*
  6955. * If the caller has provided a response iocbq buffer, then context2
  6956. * is NULL or its an error.
  6957. */
  6958. if (prspiocbq) {
  6959. if (piocb->context2)
  6960. return IOCB_ERROR;
  6961. piocb->context2 = prspiocbq;
  6962. }
  6963. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6964. piocb->context_un.wait_queue = &done_q;
  6965. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6966. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6967. creg_val = readl(phba->HCregaddr);
  6968. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6969. writel(creg_val, phba->HCregaddr);
  6970. readl(phba->HCregaddr); /* flush */
  6971. }
  6972. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  6973. SLI_IOCB_RET_IOCB);
  6974. if (retval == IOCB_SUCCESS) {
  6975. timeout_req = timeout * HZ;
  6976. timeleft = wait_event_timeout(done_q,
  6977. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  6978. timeout_req);
  6979. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6980. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6981. "0331 IOCB wake signaled\n");
  6982. } else if (timeleft == 0) {
  6983. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6984. "0338 IOCB wait timeout error - no "
  6985. "wake response Data x%x\n", timeout);
  6986. retval = IOCB_TIMEDOUT;
  6987. } else {
  6988. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6989. "0330 IOCB wake NOT set, "
  6990. "Data x%x x%lx\n",
  6991. timeout, (timeleft / jiffies));
  6992. retval = IOCB_TIMEDOUT;
  6993. }
  6994. } else if (retval == IOCB_BUSY) {
  6995. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6996. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  6997. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  6998. return retval;
  6999. } else {
  7000. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7001. "0332 IOCB wait issue failed, Data x%x\n",
  7002. retval);
  7003. retval = IOCB_ERROR;
  7004. }
  7005. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7006. creg_val = readl(phba->HCregaddr);
  7007. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  7008. writel(creg_val, phba->HCregaddr);
  7009. readl(phba->HCregaddr); /* flush */
  7010. }
  7011. if (prspiocbq)
  7012. piocb->context2 = NULL;
  7013. piocb->context_un.wait_queue = NULL;
  7014. piocb->iocb_cmpl = NULL;
  7015. return retval;
  7016. }
  7017. /**
  7018. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  7019. * @phba: Pointer to HBA context object.
  7020. * @pmboxq: Pointer to driver mailbox object.
  7021. * @timeout: Timeout in number of seconds.
  7022. *
  7023. * This function issues the mailbox to firmware and waits for the
  7024. * mailbox command to complete. If the mailbox command is not
  7025. * completed within timeout seconds, it returns MBX_TIMEOUT.
  7026. * The function waits for the mailbox completion using an
  7027. * interruptible wait. If the thread is woken up due to a
  7028. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  7029. * should not free the mailbox resources, if this function returns
  7030. * MBX_TIMEOUT.
  7031. * This function will sleep while waiting for mailbox completion.
  7032. * So, this function should not be called from any context which
  7033. * does not allow sleeping. Due to the same reason, this function
  7034. * cannot be called with interrupt disabled.
  7035. * This function assumes that the mailbox completion occurs while
  7036. * this function sleep. So, this function cannot be called from
  7037. * the worker thread which processes mailbox completion.
  7038. * This function is called in the context of HBA management
  7039. * applications.
  7040. * This function returns MBX_SUCCESS when successful.
  7041. * This function is called with no lock held.
  7042. **/
  7043. int
  7044. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  7045. uint32_t timeout)
  7046. {
  7047. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7048. int retval;
  7049. unsigned long flag;
  7050. /* The caller must leave context1 empty. */
  7051. if (pmboxq->context1)
  7052. return MBX_NOT_FINISHED;
  7053. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  7054. /* setup wake call as IOCB callback */
  7055. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  7056. /* setup context field to pass wait_queue pointer to wake function */
  7057. pmboxq->context1 = &done_q;
  7058. /* now issue the command */
  7059. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  7060. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  7061. wait_event_interruptible_timeout(done_q,
  7062. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  7063. timeout * HZ);
  7064. spin_lock_irqsave(&phba->hbalock, flag);
  7065. pmboxq->context1 = NULL;
  7066. /*
  7067. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  7068. * else do not free the resources.
  7069. */
  7070. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  7071. retval = MBX_SUCCESS;
  7072. lpfc_sli4_swap_str(phba, pmboxq);
  7073. } else {
  7074. retval = MBX_TIMEOUT;
  7075. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7076. }
  7077. spin_unlock_irqrestore(&phba->hbalock, flag);
  7078. }
  7079. return retval;
  7080. }
  7081. /**
  7082. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  7083. * @phba: Pointer to HBA context.
  7084. *
  7085. * This function is called to shutdown the driver's mailbox sub-system.
  7086. * It first marks the mailbox sub-system is in a block state to prevent
  7087. * the asynchronous mailbox command from issued off the pending mailbox
  7088. * command queue. If the mailbox command sub-system shutdown is due to
  7089. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  7090. * the mailbox sub-system flush routine to forcefully bring down the
  7091. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  7092. * as with offline or HBA function reset), this routine will wait for the
  7093. * outstanding mailbox command to complete before invoking the mailbox
  7094. * sub-system flush routine to gracefully bring down mailbox sub-system.
  7095. **/
  7096. void
  7097. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  7098. {
  7099. struct lpfc_sli *psli = &phba->sli;
  7100. uint8_t actcmd = MBX_HEARTBEAT;
  7101. unsigned long timeout;
  7102. spin_lock_irq(&phba->hbalock);
  7103. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7104. spin_unlock_irq(&phba->hbalock);
  7105. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7106. spin_lock_irq(&phba->hbalock);
  7107. if (phba->sli.mbox_active)
  7108. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7109. spin_unlock_irq(&phba->hbalock);
  7110. /* Determine how long we might wait for the active mailbox
  7111. * command to be gracefully completed by firmware.
  7112. */
  7113. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7114. 1000) + jiffies;
  7115. while (phba->sli.mbox_active) {
  7116. /* Check active mailbox complete status every 2ms */
  7117. msleep(2);
  7118. if (time_after(jiffies, timeout))
  7119. /* Timeout, let the mailbox flush routine to
  7120. * forcefully release active mailbox command
  7121. */
  7122. break;
  7123. }
  7124. }
  7125. lpfc_sli_mbox_sys_flush(phba);
  7126. }
  7127. /**
  7128. * lpfc_sli_eratt_read - read sli-3 error attention events
  7129. * @phba: Pointer to HBA context.
  7130. *
  7131. * This function is called to read the SLI3 device error attention registers
  7132. * for possible error attention events. The caller must hold the hostlock
  7133. * with spin_lock_irq().
  7134. *
  7135. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7136. * Register and returns 0 otherwise.
  7137. **/
  7138. static int
  7139. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7140. {
  7141. uint32_t ha_copy;
  7142. /* Read chip Host Attention (HA) register */
  7143. ha_copy = readl(phba->HAregaddr);
  7144. if (ha_copy & HA_ERATT) {
  7145. /* Read host status register to retrieve error event */
  7146. lpfc_sli_read_hs(phba);
  7147. /* Check if there is a deferred error condition is active */
  7148. if ((HS_FFER1 & phba->work_hs) &&
  7149. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7150. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7151. phba->hba_flag |= DEFER_ERATT;
  7152. /* Clear all interrupt enable conditions */
  7153. writel(0, phba->HCregaddr);
  7154. readl(phba->HCregaddr);
  7155. }
  7156. /* Set the driver HA work bitmap */
  7157. phba->work_ha |= HA_ERATT;
  7158. /* Indicate polling handles this ERATT */
  7159. phba->hba_flag |= HBA_ERATT_HANDLED;
  7160. return 1;
  7161. }
  7162. return 0;
  7163. }
  7164. /**
  7165. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7166. * @phba: Pointer to HBA context.
  7167. *
  7168. * This function is called to read the SLI4 device error attention registers
  7169. * for possible error attention events. The caller must hold the hostlock
  7170. * with spin_lock_irq().
  7171. *
  7172. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7173. * Register and returns 0 otherwise.
  7174. **/
  7175. static int
  7176. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7177. {
  7178. uint32_t uerr_sta_hi, uerr_sta_lo;
  7179. /* For now, use the SLI4 device internal unrecoverable error
  7180. * registers for error attention. This can be changed later.
  7181. */
  7182. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  7183. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  7184. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7185. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7186. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7187. "1423 HBA Unrecoverable error: "
  7188. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7189. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  7190. uerr_sta_lo, uerr_sta_hi,
  7191. phba->sli4_hba.ue_mask_lo,
  7192. phba->sli4_hba.ue_mask_hi);
  7193. phba->work_status[0] = uerr_sta_lo;
  7194. phba->work_status[1] = uerr_sta_hi;
  7195. /* Set the driver HA work bitmap */
  7196. phba->work_ha |= HA_ERATT;
  7197. /* Indicate polling handles this ERATT */
  7198. phba->hba_flag |= HBA_ERATT_HANDLED;
  7199. return 1;
  7200. }
  7201. return 0;
  7202. }
  7203. /**
  7204. * lpfc_sli_check_eratt - check error attention events
  7205. * @phba: Pointer to HBA context.
  7206. *
  7207. * This function is called from timer soft interrupt context to check HBA's
  7208. * error attention register bit for error attention events.
  7209. *
  7210. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7211. * Register and returns 0 otherwise.
  7212. **/
  7213. int
  7214. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7215. {
  7216. uint32_t ha_copy;
  7217. /* If somebody is waiting to handle an eratt, don't process it
  7218. * here. The brdkill function will do this.
  7219. */
  7220. if (phba->link_flag & LS_IGNORE_ERATT)
  7221. return 0;
  7222. /* Check if interrupt handler handles this ERATT */
  7223. spin_lock_irq(&phba->hbalock);
  7224. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7225. /* Interrupt handler has handled ERATT */
  7226. spin_unlock_irq(&phba->hbalock);
  7227. return 0;
  7228. }
  7229. /*
  7230. * If there is deferred error attention, do not check for error
  7231. * attention
  7232. */
  7233. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7234. spin_unlock_irq(&phba->hbalock);
  7235. return 0;
  7236. }
  7237. /* If PCI channel is offline, don't process it */
  7238. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7239. spin_unlock_irq(&phba->hbalock);
  7240. return 0;
  7241. }
  7242. switch (phba->sli_rev) {
  7243. case LPFC_SLI_REV2:
  7244. case LPFC_SLI_REV3:
  7245. /* Read chip Host Attention (HA) register */
  7246. ha_copy = lpfc_sli_eratt_read(phba);
  7247. break;
  7248. case LPFC_SLI_REV4:
  7249. /* Read devcie Uncoverable Error (UERR) registers */
  7250. ha_copy = lpfc_sli4_eratt_read(phba);
  7251. break;
  7252. default:
  7253. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7254. "0299 Invalid SLI revision (%d)\n",
  7255. phba->sli_rev);
  7256. ha_copy = 0;
  7257. break;
  7258. }
  7259. spin_unlock_irq(&phba->hbalock);
  7260. return ha_copy;
  7261. }
  7262. /**
  7263. * lpfc_intr_state_check - Check device state for interrupt handling
  7264. * @phba: Pointer to HBA context.
  7265. *
  7266. * This inline routine checks whether a device or its PCI slot is in a state
  7267. * that the interrupt should be handled.
  7268. *
  7269. * This function returns 0 if the device or the PCI slot is in a state that
  7270. * interrupt should be handled, otherwise -EIO.
  7271. */
  7272. static inline int
  7273. lpfc_intr_state_check(struct lpfc_hba *phba)
  7274. {
  7275. /* If the pci channel is offline, ignore all the interrupts */
  7276. if (unlikely(pci_channel_offline(phba->pcidev)))
  7277. return -EIO;
  7278. /* Update device level interrupt statistics */
  7279. phba->sli.slistat.sli_intr++;
  7280. /* Ignore all interrupts during initialization. */
  7281. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7282. return -EIO;
  7283. return 0;
  7284. }
  7285. /**
  7286. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7287. * @irq: Interrupt number.
  7288. * @dev_id: The device context pointer.
  7289. *
  7290. * This function is directly called from the PCI layer as an interrupt
  7291. * service routine when device with SLI-3 interface spec is enabled with
  7292. * MSI-X multi-message interrupt mode and there are slow-path events in
  7293. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7294. * interrupt mode, this function is called as part of the device-level
  7295. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7296. * is undergoing initialization, the interrupt handler will not process
  7297. * the interrupt. The link attention and ELS ring attention events are
  7298. * handled by the worker thread. The interrupt handler signals the worker
  7299. * thread and returns for these events. This function is called without
  7300. * any lock held. It gets the hbalock to access and update SLI data
  7301. * structures.
  7302. *
  7303. * This function returns IRQ_HANDLED when interrupt is handled else it
  7304. * returns IRQ_NONE.
  7305. **/
  7306. irqreturn_t
  7307. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7308. {
  7309. struct lpfc_hba *phba;
  7310. uint32_t ha_copy, hc_copy;
  7311. uint32_t work_ha_copy;
  7312. unsigned long status;
  7313. unsigned long iflag;
  7314. uint32_t control;
  7315. MAILBOX_t *mbox, *pmbox;
  7316. struct lpfc_vport *vport;
  7317. struct lpfc_nodelist *ndlp;
  7318. struct lpfc_dmabuf *mp;
  7319. LPFC_MBOXQ_t *pmb;
  7320. int rc;
  7321. /*
  7322. * Get the driver's phba structure from the dev_id and
  7323. * assume the HBA is not interrupting.
  7324. */
  7325. phba = (struct lpfc_hba *)dev_id;
  7326. if (unlikely(!phba))
  7327. return IRQ_NONE;
  7328. /*
  7329. * Stuff needs to be attented to when this function is invoked as an
  7330. * individual interrupt handler in MSI-X multi-message interrupt mode
  7331. */
  7332. if (phba->intr_type == MSIX) {
  7333. /* Check device state for handling interrupt */
  7334. if (lpfc_intr_state_check(phba))
  7335. return IRQ_NONE;
  7336. /* Need to read HA REG for slow-path events */
  7337. spin_lock_irqsave(&phba->hbalock, iflag);
  7338. ha_copy = readl(phba->HAregaddr);
  7339. /* If somebody is waiting to handle an eratt don't process it
  7340. * here. The brdkill function will do this.
  7341. */
  7342. if (phba->link_flag & LS_IGNORE_ERATT)
  7343. ha_copy &= ~HA_ERATT;
  7344. /* Check the need for handling ERATT in interrupt handler */
  7345. if (ha_copy & HA_ERATT) {
  7346. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7347. /* ERATT polling has handled ERATT */
  7348. ha_copy &= ~HA_ERATT;
  7349. else
  7350. /* Indicate interrupt handler handles ERATT */
  7351. phba->hba_flag |= HBA_ERATT_HANDLED;
  7352. }
  7353. /*
  7354. * If there is deferred error attention, do not check for any
  7355. * interrupt.
  7356. */
  7357. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7358. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7359. return IRQ_NONE;
  7360. }
  7361. /* Clear up only attention source related to slow-path */
  7362. hc_copy = readl(phba->HCregaddr);
  7363. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7364. HC_LAINT_ENA | HC_ERINT_ENA),
  7365. phba->HCregaddr);
  7366. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7367. phba->HAregaddr);
  7368. writel(hc_copy, phba->HCregaddr);
  7369. readl(phba->HAregaddr); /* flush */
  7370. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7371. } else
  7372. ha_copy = phba->ha_copy;
  7373. work_ha_copy = ha_copy & phba->work_ha_mask;
  7374. if (work_ha_copy) {
  7375. if (work_ha_copy & HA_LATT) {
  7376. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7377. /*
  7378. * Turn off Link Attention interrupts
  7379. * until CLEAR_LA done
  7380. */
  7381. spin_lock_irqsave(&phba->hbalock, iflag);
  7382. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7383. control = readl(phba->HCregaddr);
  7384. control &= ~HC_LAINT_ENA;
  7385. writel(control, phba->HCregaddr);
  7386. readl(phba->HCregaddr); /* flush */
  7387. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7388. }
  7389. else
  7390. work_ha_copy &= ~HA_LATT;
  7391. }
  7392. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7393. /*
  7394. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7395. * the only slow ring.
  7396. */
  7397. status = (work_ha_copy &
  7398. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7399. status >>= (4*LPFC_ELS_RING);
  7400. if (status & HA_RXMASK) {
  7401. spin_lock_irqsave(&phba->hbalock, iflag);
  7402. control = readl(phba->HCregaddr);
  7403. lpfc_debugfs_slow_ring_trc(phba,
  7404. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7405. control, status,
  7406. (uint32_t)phba->sli.slistat.sli_intr);
  7407. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7408. lpfc_debugfs_slow_ring_trc(phba,
  7409. "ISR Disable ring:"
  7410. "pwork:x%x hawork:x%x wait:x%x",
  7411. phba->work_ha, work_ha_copy,
  7412. (uint32_t)((unsigned long)
  7413. &phba->work_waitq));
  7414. control &=
  7415. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7416. writel(control, phba->HCregaddr);
  7417. readl(phba->HCregaddr); /* flush */
  7418. }
  7419. else {
  7420. lpfc_debugfs_slow_ring_trc(phba,
  7421. "ISR slow ring: pwork:"
  7422. "x%x hawork:x%x wait:x%x",
  7423. phba->work_ha, work_ha_copy,
  7424. (uint32_t)((unsigned long)
  7425. &phba->work_waitq));
  7426. }
  7427. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7428. }
  7429. }
  7430. spin_lock_irqsave(&phba->hbalock, iflag);
  7431. if (work_ha_copy & HA_ERATT) {
  7432. lpfc_sli_read_hs(phba);
  7433. /*
  7434. * Check if there is a deferred error condition
  7435. * is active
  7436. */
  7437. if ((HS_FFER1 & phba->work_hs) &&
  7438. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7439. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7440. phba->hba_flag |= DEFER_ERATT;
  7441. /* Clear all interrupt enable conditions */
  7442. writel(0, phba->HCregaddr);
  7443. readl(phba->HCregaddr);
  7444. }
  7445. }
  7446. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7447. pmb = phba->sli.mbox_active;
  7448. pmbox = &pmb->u.mb;
  7449. mbox = phba->mbox;
  7450. vport = pmb->vport;
  7451. /* First check out the status word */
  7452. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7453. if (pmbox->mbxOwner != OWN_HOST) {
  7454. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7455. /*
  7456. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7457. * mbxStatus <status>
  7458. */
  7459. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7460. LOG_SLI,
  7461. "(%d):0304 Stray Mailbox "
  7462. "Interrupt mbxCommand x%x "
  7463. "mbxStatus x%x\n",
  7464. (vport ? vport->vpi : 0),
  7465. pmbox->mbxCommand,
  7466. pmbox->mbxStatus);
  7467. /* clear mailbox attention bit */
  7468. work_ha_copy &= ~HA_MBATT;
  7469. } else {
  7470. phba->sli.mbox_active = NULL;
  7471. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7472. phba->last_completion_time = jiffies;
  7473. del_timer(&phba->sli.mbox_tmo);
  7474. if (pmb->mbox_cmpl) {
  7475. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7476. MAILBOX_CMD_SIZE);
  7477. if (pmb->out_ext_byte_len &&
  7478. pmb->context2)
  7479. lpfc_sli_pcimem_bcopy(
  7480. phba->mbox_ext,
  7481. pmb->context2,
  7482. pmb->out_ext_byte_len);
  7483. }
  7484. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7485. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7486. lpfc_debugfs_disc_trc(vport,
  7487. LPFC_DISC_TRC_MBOX_VPORT,
  7488. "MBOX dflt rpi: : "
  7489. "status:x%x rpi:x%x",
  7490. (uint32_t)pmbox->mbxStatus,
  7491. pmbox->un.varWords[0], 0);
  7492. if (!pmbox->mbxStatus) {
  7493. mp = (struct lpfc_dmabuf *)
  7494. (pmb->context1);
  7495. ndlp = (struct lpfc_nodelist *)
  7496. pmb->context2;
  7497. /* Reg_LOGIN of dflt RPI was
  7498. * successful. new lets get
  7499. * rid of the RPI using the
  7500. * same mbox buffer.
  7501. */
  7502. lpfc_unreg_login(phba,
  7503. vport->vpi,
  7504. pmbox->un.varWords[0],
  7505. pmb);
  7506. pmb->mbox_cmpl =
  7507. lpfc_mbx_cmpl_dflt_rpi;
  7508. pmb->context1 = mp;
  7509. pmb->context2 = ndlp;
  7510. pmb->vport = vport;
  7511. rc = lpfc_sli_issue_mbox(phba,
  7512. pmb,
  7513. MBX_NOWAIT);
  7514. if (rc != MBX_BUSY)
  7515. lpfc_printf_log(phba,
  7516. KERN_ERR,
  7517. LOG_MBOX | LOG_SLI,
  7518. "0350 rc should have"
  7519. "been MBX_BUSY\n");
  7520. if (rc != MBX_NOT_FINISHED)
  7521. goto send_current_mbox;
  7522. }
  7523. }
  7524. spin_lock_irqsave(
  7525. &phba->pport->work_port_lock,
  7526. iflag);
  7527. phba->pport->work_port_events &=
  7528. ~WORKER_MBOX_TMO;
  7529. spin_unlock_irqrestore(
  7530. &phba->pport->work_port_lock,
  7531. iflag);
  7532. lpfc_mbox_cmpl_put(phba, pmb);
  7533. }
  7534. } else
  7535. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7536. if ((work_ha_copy & HA_MBATT) &&
  7537. (phba->sli.mbox_active == NULL)) {
  7538. send_current_mbox:
  7539. /* Process next mailbox command if there is one */
  7540. do {
  7541. rc = lpfc_sli_issue_mbox(phba, NULL,
  7542. MBX_NOWAIT);
  7543. } while (rc == MBX_NOT_FINISHED);
  7544. if (rc != MBX_SUCCESS)
  7545. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7546. LOG_SLI, "0349 rc should be "
  7547. "MBX_SUCCESS\n");
  7548. }
  7549. spin_lock_irqsave(&phba->hbalock, iflag);
  7550. phba->work_ha |= work_ha_copy;
  7551. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7552. lpfc_worker_wake_up(phba);
  7553. }
  7554. return IRQ_HANDLED;
  7555. } /* lpfc_sli_sp_intr_handler */
  7556. /**
  7557. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7558. * @irq: Interrupt number.
  7559. * @dev_id: The device context pointer.
  7560. *
  7561. * This function is directly called from the PCI layer as an interrupt
  7562. * service routine when device with SLI-3 interface spec is enabled with
  7563. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7564. * ring event in the HBA. However, when the device is enabled with either
  7565. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7566. * device-level interrupt handler. When the PCI slot is in error recovery
  7567. * or the HBA is undergoing initialization, the interrupt handler will not
  7568. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7569. * the intrrupt context. This function is called without any lock held.
  7570. * It gets the hbalock to access and update SLI data structures.
  7571. *
  7572. * This function returns IRQ_HANDLED when interrupt is handled else it
  7573. * returns IRQ_NONE.
  7574. **/
  7575. irqreturn_t
  7576. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7577. {
  7578. struct lpfc_hba *phba;
  7579. uint32_t ha_copy;
  7580. unsigned long status;
  7581. unsigned long iflag;
  7582. /* Get the driver's phba structure from the dev_id and
  7583. * assume the HBA is not interrupting.
  7584. */
  7585. phba = (struct lpfc_hba *) dev_id;
  7586. if (unlikely(!phba))
  7587. return IRQ_NONE;
  7588. /*
  7589. * Stuff needs to be attented to when this function is invoked as an
  7590. * individual interrupt handler in MSI-X multi-message interrupt mode
  7591. */
  7592. if (phba->intr_type == MSIX) {
  7593. /* Check device state for handling interrupt */
  7594. if (lpfc_intr_state_check(phba))
  7595. return IRQ_NONE;
  7596. /* Need to read HA REG for FCP ring and other ring events */
  7597. ha_copy = readl(phba->HAregaddr);
  7598. /* Clear up only attention source related to fast-path */
  7599. spin_lock_irqsave(&phba->hbalock, iflag);
  7600. /*
  7601. * If there is deferred error attention, do not check for
  7602. * any interrupt.
  7603. */
  7604. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7605. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7606. return IRQ_NONE;
  7607. }
  7608. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7609. phba->HAregaddr);
  7610. readl(phba->HAregaddr); /* flush */
  7611. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7612. } else
  7613. ha_copy = phba->ha_copy;
  7614. /*
  7615. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7616. */
  7617. ha_copy &= ~(phba->work_ha_mask);
  7618. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7619. status >>= (4*LPFC_FCP_RING);
  7620. if (status & HA_RXMASK)
  7621. lpfc_sli_handle_fast_ring_event(phba,
  7622. &phba->sli.ring[LPFC_FCP_RING],
  7623. status);
  7624. if (phba->cfg_multi_ring_support == 2) {
  7625. /*
  7626. * Process all events on extra ring. Take the optimized path
  7627. * for extra ring IO.
  7628. */
  7629. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7630. status >>= (4*LPFC_EXTRA_RING);
  7631. if (status & HA_RXMASK) {
  7632. lpfc_sli_handle_fast_ring_event(phba,
  7633. &phba->sli.ring[LPFC_EXTRA_RING],
  7634. status);
  7635. }
  7636. }
  7637. return IRQ_HANDLED;
  7638. } /* lpfc_sli_fp_intr_handler */
  7639. /**
  7640. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7641. * @irq: Interrupt number.
  7642. * @dev_id: The device context pointer.
  7643. *
  7644. * This function is the HBA device-level interrupt handler to device with
  7645. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7646. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7647. * requires driver attention. This function invokes the slow-path interrupt
  7648. * attention handling function and fast-path interrupt attention handling
  7649. * function in turn to process the relevant HBA attention events. This
  7650. * function is called without any lock held. It gets the hbalock to access
  7651. * and update SLI data structures.
  7652. *
  7653. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7654. * returns IRQ_NONE.
  7655. **/
  7656. irqreturn_t
  7657. lpfc_sli_intr_handler(int irq, void *dev_id)
  7658. {
  7659. struct lpfc_hba *phba;
  7660. irqreturn_t sp_irq_rc, fp_irq_rc;
  7661. unsigned long status1, status2;
  7662. uint32_t hc_copy;
  7663. /*
  7664. * Get the driver's phba structure from the dev_id and
  7665. * assume the HBA is not interrupting.
  7666. */
  7667. phba = (struct lpfc_hba *) dev_id;
  7668. if (unlikely(!phba))
  7669. return IRQ_NONE;
  7670. /* Check device state for handling interrupt */
  7671. if (lpfc_intr_state_check(phba))
  7672. return IRQ_NONE;
  7673. spin_lock(&phba->hbalock);
  7674. phba->ha_copy = readl(phba->HAregaddr);
  7675. if (unlikely(!phba->ha_copy)) {
  7676. spin_unlock(&phba->hbalock);
  7677. return IRQ_NONE;
  7678. } else if (phba->ha_copy & HA_ERATT) {
  7679. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7680. /* ERATT polling has handled ERATT */
  7681. phba->ha_copy &= ~HA_ERATT;
  7682. else
  7683. /* Indicate interrupt handler handles ERATT */
  7684. phba->hba_flag |= HBA_ERATT_HANDLED;
  7685. }
  7686. /*
  7687. * If there is deferred error attention, do not check for any interrupt.
  7688. */
  7689. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7690. spin_unlock_irq(&phba->hbalock);
  7691. return IRQ_NONE;
  7692. }
  7693. /* Clear attention sources except link and error attentions */
  7694. hc_copy = readl(phba->HCregaddr);
  7695. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  7696. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  7697. phba->HCregaddr);
  7698. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7699. writel(hc_copy, phba->HCregaddr);
  7700. readl(phba->HAregaddr); /* flush */
  7701. spin_unlock(&phba->hbalock);
  7702. /*
  7703. * Invokes slow-path host attention interrupt handling as appropriate.
  7704. */
  7705. /* status of events with mailbox and link attention */
  7706. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7707. /* status of events with ELS ring */
  7708. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7709. status2 >>= (4*LPFC_ELS_RING);
  7710. if (status1 || (status2 & HA_RXMASK))
  7711. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7712. else
  7713. sp_irq_rc = IRQ_NONE;
  7714. /*
  7715. * Invoke fast-path host attention interrupt handling as appropriate.
  7716. */
  7717. /* status of events with FCP ring */
  7718. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7719. status1 >>= (4*LPFC_FCP_RING);
  7720. /* status of events with extra ring */
  7721. if (phba->cfg_multi_ring_support == 2) {
  7722. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7723. status2 >>= (4*LPFC_EXTRA_RING);
  7724. } else
  7725. status2 = 0;
  7726. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7727. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7728. else
  7729. fp_irq_rc = IRQ_NONE;
  7730. /* Return device-level interrupt handling status */
  7731. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7732. } /* lpfc_sli_intr_handler */
  7733. /**
  7734. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7735. * @phba: pointer to lpfc hba data structure.
  7736. *
  7737. * This routine is invoked by the worker thread to process all the pending
  7738. * SLI4 FCP abort XRI events.
  7739. **/
  7740. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7741. {
  7742. struct lpfc_cq_event *cq_event;
  7743. /* First, declare the fcp xri abort event has been handled */
  7744. spin_lock_irq(&phba->hbalock);
  7745. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7746. spin_unlock_irq(&phba->hbalock);
  7747. /* Now, handle all the fcp xri abort events */
  7748. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7749. /* Get the first event from the head of the event queue */
  7750. spin_lock_irq(&phba->hbalock);
  7751. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7752. cq_event, struct lpfc_cq_event, list);
  7753. spin_unlock_irq(&phba->hbalock);
  7754. /* Notify aborted XRI for FCP work queue */
  7755. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7756. /* Free the event processed back to the free pool */
  7757. lpfc_sli4_cq_event_release(phba, cq_event);
  7758. }
  7759. }
  7760. /**
  7761. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7762. * @phba: pointer to lpfc hba data structure.
  7763. *
  7764. * This routine is invoked by the worker thread to process all the pending
  7765. * SLI4 els abort xri events.
  7766. **/
  7767. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7768. {
  7769. struct lpfc_cq_event *cq_event;
  7770. /* First, declare the els xri abort event has been handled */
  7771. spin_lock_irq(&phba->hbalock);
  7772. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7773. spin_unlock_irq(&phba->hbalock);
  7774. /* Now, handle all the els xri abort events */
  7775. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7776. /* Get the first event from the head of the event queue */
  7777. spin_lock_irq(&phba->hbalock);
  7778. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7779. cq_event, struct lpfc_cq_event, list);
  7780. spin_unlock_irq(&phba->hbalock);
  7781. /* Notify aborted XRI for ELS work queue */
  7782. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7783. /* Free the event processed back to the free pool */
  7784. lpfc_sli4_cq_event_release(phba, cq_event);
  7785. }
  7786. }
  7787. /**
  7788. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  7789. * @phba: pointer to lpfc hba data structure
  7790. * @pIocbIn: pointer to the rspiocbq
  7791. * @pIocbOut: pointer to the cmdiocbq
  7792. * @wcqe: pointer to the complete wcqe
  7793. *
  7794. * This routine transfers the fields of a command iocbq to a response iocbq
  7795. * by copying all the IOCB fields from command iocbq and transferring the
  7796. * completion status information from the complete wcqe.
  7797. **/
  7798. static void
  7799. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  7800. struct lpfc_iocbq *pIocbIn,
  7801. struct lpfc_iocbq *pIocbOut,
  7802. struct lpfc_wcqe_complete *wcqe)
  7803. {
  7804. unsigned long iflags;
  7805. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7806. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7807. sizeof(struct lpfc_iocbq) - offset);
  7808. /* Map WCQE parameters into irspiocb parameters */
  7809. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7810. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7811. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7812. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7813. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7814. wcqe->total_data_placed;
  7815. else
  7816. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7817. else {
  7818. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7819. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  7820. }
  7821. /* Pick up HBA exchange busy condition */
  7822. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  7823. spin_lock_irqsave(&phba->hbalock, iflags);
  7824. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  7825. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7826. }
  7827. }
  7828. /**
  7829. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  7830. * @phba: Pointer to HBA context object.
  7831. * @wcqe: Pointer to work-queue completion queue entry.
  7832. *
  7833. * This routine handles an ELS work-queue completion event and construct
  7834. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  7835. * discovery engine to handle.
  7836. *
  7837. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  7838. **/
  7839. static struct lpfc_iocbq *
  7840. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  7841. struct lpfc_iocbq *irspiocbq)
  7842. {
  7843. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7844. struct lpfc_iocbq *cmdiocbq;
  7845. struct lpfc_wcqe_complete *wcqe;
  7846. unsigned long iflags;
  7847. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  7848. spin_lock_irqsave(&phba->hbalock, iflags);
  7849. pring->stats.iocb_event++;
  7850. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7851. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7852. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7853. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7854. if (unlikely(!cmdiocbq)) {
  7855. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7856. "0386 ELS complete with no corresponding "
  7857. "cmdiocb: iotag (%d)\n",
  7858. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7859. lpfc_sli_release_iocbq(phba, irspiocbq);
  7860. return NULL;
  7861. }
  7862. /* Fake the irspiocbq and copy necessary response information */
  7863. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  7864. return irspiocbq;
  7865. }
  7866. /**
  7867. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7868. * @phba: Pointer to HBA context object.
  7869. * @cqe: Pointer to mailbox completion queue entry.
  7870. *
  7871. * This routine process a mailbox completion queue entry with asynchrous
  7872. * event.
  7873. *
  7874. * Return: true if work posted to worker thread, otherwise false.
  7875. **/
  7876. static bool
  7877. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7878. {
  7879. struct lpfc_cq_event *cq_event;
  7880. unsigned long iflags;
  7881. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7882. "0392 Async Event: word0:x%x, word1:x%x, "
  7883. "word2:x%x, word3:x%x\n", mcqe->word0,
  7884. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7885. /* Allocate a new internal CQ_EVENT entry */
  7886. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7887. if (!cq_event) {
  7888. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7889. "0394 Failed to allocate CQ_EVENT entry\n");
  7890. return false;
  7891. }
  7892. /* Move the CQE into an asynchronous event entry */
  7893. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7894. spin_lock_irqsave(&phba->hbalock, iflags);
  7895. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7896. /* Set the async event flag */
  7897. phba->hba_flag |= ASYNC_EVENT;
  7898. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7899. return true;
  7900. }
  7901. /**
  7902. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7903. * @phba: Pointer to HBA context object.
  7904. * @cqe: Pointer to mailbox completion queue entry.
  7905. *
  7906. * This routine process a mailbox completion queue entry with mailbox
  7907. * completion event.
  7908. *
  7909. * Return: true if work posted to worker thread, otherwise false.
  7910. **/
  7911. static bool
  7912. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7913. {
  7914. uint32_t mcqe_status;
  7915. MAILBOX_t *mbox, *pmbox;
  7916. struct lpfc_mqe *mqe;
  7917. struct lpfc_vport *vport;
  7918. struct lpfc_nodelist *ndlp;
  7919. struct lpfc_dmabuf *mp;
  7920. unsigned long iflags;
  7921. LPFC_MBOXQ_t *pmb;
  7922. bool workposted = false;
  7923. int rc;
  7924. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7925. if (!bf_get(lpfc_trailer_completed, mcqe))
  7926. goto out_no_mqe_complete;
  7927. /* Get the reference to the active mbox command */
  7928. spin_lock_irqsave(&phba->hbalock, iflags);
  7929. pmb = phba->sli.mbox_active;
  7930. if (unlikely(!pmb)) {
  7931. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7932. "1832 No pending MBOX command to handle\n");
  7933. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7934. goto out_no_mqe_complete;
  7935. }
  7936. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7937. mqe = &pmb->u.mqe;
  7938. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7939. mbox = phba->mbox;
  7940. vport = pmb->vport;
  7941. /* Reset heartbeat timer */
  7942. phba->last_completion_time = jiffies;
  7943. del_timer(&phba->sli.mbox_tmo);
  7944. /* Move mbox data to caller's mailbox region, do endian swapping */
  7945. if (pmb->mbox_cmpl && mbox)
  7946. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7947. /* Set the mailbox status with SLI4 range 0x4000 */
  7948. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7949. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7950. bf_set(lpfc_mqe_status, mqe,
  7951. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7952. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7953. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7954. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7955. "MBOX dflt rpi: status:x%x rpi:x%x",
  7956. mcqe_status,
  7957. pmbox->un.varWords[0], 0);
  7958. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7959. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7960. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7961. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7962. * RID of the PPI using the same mbox buffer.
  7963. */
  7964. lpfc_unreg_login(phba, vport->vpi,
  7965. pmbox->un.varWords[0], pmb);
  7966. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7967. pmb->context1 = mp;
  7968. pmb->context2 = ndlp;
  7969. pmb->vport = vport;
  7970. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7971. if (rc != MBX_BUSY)
  7972. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7973. LOG_SLI, "0385 rc should "
  7974. "have been MBX_BUSY\n");
  7975. if (rc != MBX_NOT_FINISHED)
  7976. goto send_current_mbox;
  7977. }
  7978. }
  7979. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7980. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7981. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7982. /* There is mailbox completion work to do */
  7983. spin_lock_irqsave(&phba->hbalock, iflags);
  7984. __lpfc_mbox_cmpl_put(phba, pmb);
  7985. phba->work_ha |= HA_MBATT;
  7986. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7987. workposted = true;
  7988. send_current_mbox:
  7989. spin_lock_irqsave(&phba->hbalock, iflags);
  7990. /* Release the mailbox command posting token */
  7991. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7992. /* Setting active mailbox pointer need to be in sync to flag clear */
  7993. phba->sli.mbox_active = NULL;
  7994. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7995. /* Wake up worker thread to post the next pending mailbox command */
  7996. lpfc_worker_wake_up(phba);
  7997. out_no_mqe_complete:
  7998. if (bf_get(lpfc_trailer_consumed, mcqe))
  7999. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  8000. return workposted;
  8001. }
  8002. /**
  8003. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  8004. * @phba: Pointer to HBA context object.
  8005. * @cqe: Pointer to mailbox completion queue entry.
  8006. *
  8007. * This routine process a mailbox completion queue entry, it invokes the
  8008. * proper mailbox complete handling or asynchrous event handling routine
  8009. * according to the MCQE's async bit.
  8010. *
  8011. * Return: true if work posted to worker thread, otherwise false.
  8012. **/
  8013. static bool
  8014. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  8015. {
  8016. struct lpfc_mcqe mcqe;
  8017. bool workposted;
  8018. /* Copy the mailbox MCQE and convert endian order as needed */
  8019. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  8020. /* Invoke the proper event handling routine */
  8021. if (!bf_get(lpfc_trailer_async, &mcqe))
  8022. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  8023. else
  8024. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  8025. return workposted;
  8026. }
  8027. /**
  8028. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  8029. * @phba: Pointer to HBA context object.
  8030. * @wcqe: Pointer to work-queue completion queue entry.
  8031. *
  8032. * This routine handles an ELS work-queue completion event.
  8033. *
  8034. * Return: true if work posted to worker thread, otherwise false.
  8035. **/
  8036. static bool
  8037. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  8038. struct lpfc_wcqe_complete *wcqe)
  8039. {
  8040. struct lpfc_iocbq *irspiocbq;
  8041. unsigned long iflags;
  8042. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8043. /* Get an irspiocbq for later ELS response processing use */
  8044. irspiocbq = lpfc_sli_get_iocbq(phba);
  8045. if (!irspiocbq) {
  8046. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8047. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  8048. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  8049. pring->txq_cnt, phba->iocb_cnt,
  8050. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  8051. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  8052. return false;
  8053. }
  8054. /* Save off the slow-path queue event for work thread to process */
  8055. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  8056. spin_lock_irqsave(&phba->hbalock, iflags);
  8057. list_add_tail(&irspiocbq->cq_event.list,
  8058. &phba->sli4_hba.sp_queue_event);
  8059. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8060. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8061. return true;
  8062. }
  8063. /**
  8064. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  8065. * @phba: Pointer to HBA context object.
  8066. * @wcqe: Pointer to work-queue completion queue entry.
  8067. *
  8068. * This routine handles slow-path WQ entry comsumed event by invoking the
  8069. * proper WQ release routine to the slow-path WQ.
  8070. **/
  8071. static void
  8072. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  8073. struct lpfc_wcqe_release *wcqe)
  8074. {
  8075. /* Check for the slow-path ELS work queue */
  8076. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  8077. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  8078. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8079. else
  8080. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8081. "2579 Slow-path wqe consume event carries "
  8082. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  8083. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  8084. phba->sli4_hba.els_wq->queue_id);
  8085. }
  8086. /**
  8087. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  8088. * @phba: Pointer to HBA context object.
  8089. * @cq: Pointer to a WQ completion queue.
  8090. * @wcqe: Pointer to work-queue completion queue entry.
  8091. *
  8092. * This routine handles an XRI abort event.
  8093. *
  8094. * Return: true if work posted to worker thread, otherwise false.
  8095. **/
  8096. static bool
  8097. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  8098. struct lpfc_queue *cq,
  8099. struct sli4_wcqe_xri_aborted *wcqe)
  8100. {
  8101. bool workposted = false;
  8102. struct lpfc_cq_event *cq_event;
  8103. unsigned long iflags;
  8104. /* Allocate a new internal CQ_EVENT entry */
  8105. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8106. if (!cq_event) {
  8107. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8108. "0602 Failed to allocate CQ_EVENT entry\n");
  8109. return false;
  8110. }
  8111. /* Move the CQE into the proper xri abort event list */
  8112. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8113. switch (cq->subtype) {
  8114. case LPFC_FCP:
  8115. spin_lock_irqsave(&phba->hbalock, iflags);
  8116. list_add_tail(&cq_event->list,
  8117. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8118. /* Set the fcp xri abort event flag */
  8119. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8120. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8121. workposted = true;
  8122. break;
  8123. case LPFC_ELS:
  8124. spin_lock_irqsave(&phba->hbalock, iflags);
  8125. list_add_tail(&cq_event->list,
  8126. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8127. /* Set the els xri abort event flag */
  8128. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8129. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8130. workposted = true;
  8131. break;
  8132. default:
  8133. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8134. "0603 Invalid work queue CQE subtype (x%x)\n",
  8135. cq->subtype);
  8136. workposted = false;
  8137. break;
  8138. }
  8139. return workposted;
  8140. }
  8141. /**
  8142. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8143. * @phba: Pointer to HBA context object.
  8144. * @rcqe: Pointer to receive-queue completion queue entry.
  8145. *
  8146. * This routine process a receive-queue completion queue entry.
  8147. *
  8148. * Return: true if work posted to worker thread, otherwise false.
  8149. **/
  8150. static bool
  8151. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8152. {
  8153. bool workposted = false;
  8154. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8155. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8156. struct hbq_dmabuf *dma_buf;
  8157. uint32_t status;
  8158. unsigned long iflags;
  8159. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8160. goto out;
  8161. status = bf_get(lpfc_rcqe_status, rcqe);
  8162. switch (status) {
  8163. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8164. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8165. "2537 Receive Frame Truncated!!\n");
  8166. case FC_STATUS_RQ_SUCCESS:
  8167. lpfc_sli4_rq_release(hrq, drq);
  8168. spin_lock_irqsave(&phba->hbalock, iflags);
  8169. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8170. if (!dma_buf) {
  8171. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8172. goto out;
  8173. }
  8174. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8175. /* save off the frame for the word thread to process */
  8176. list_add_tail(&dma_buf->cq_event.list,
  8177. &phba->sli4_hba.sp_queue_event);
  8178. /* Frame received */
  8179. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8180. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8181. workposted = true;
  8182. break;
  8183. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8184. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8185. /* Post more buffers if possible */
  8186. spin_lock_irqsave(&phba->hbalock, iflags);
  8187. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8188. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8189. workposted = true;
  8190. break;
  8191. }
  8192. out:
  8193. return workposted;
  8194. }
  8195. /**
  8196. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8197. * @phba: Pointer to HBA context object.
  8198. * @cq: Pointer to the completion queue.
  8199. * @wcqe: Pointer to a completion queue entry.
  8200. *
  8201. * This routine process a slow-path work-queue or recieve queue completion queue
  8202. * entry.
  8203. *
  8204. * Return: true if work posted to worker thread, otherwise false.
  8205. **/
  8206. static bool
  8207. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8208. struct lpfc_cqe *cqe)
  8209. {
  8210. struct lpfc_cqe cqevt;
  8211. bool workposted = false;
  8212. /* Copy the work queue CQE and convert endian order if needed */
  8213. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8214. /* Check and process for different type of WCQE and dispatch */
  8215. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8216. case CQE_CODE_COMPL_WQE:
  8217. /* Process the WQ/RQ complete event */
  8218. phba->last_completion_time = jiffies;
  8219. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8220. (struct lpfc_wcqe_complete *)&cqevt);
  8221. break;
  8222. case CQE_CODE_RELEASE_WQE:
  8223. /* Process the WQ release event */
  8224. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8225. (struct lpfc_wcqe_release *)&cqevt);
  8226. break;
  8227. case CQE_CODE_XRI_ABORTED:
  8228. /* Process the WQ XRI abort event */
  8229. phba->last_completion_time = jiffies;
  8230. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8231. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8232. break;
  8233. case CQE_CODE_RECEIVE:
  8234. /* Process the RQ event */
  8235. phba->last_completion_time = jiffies;
  8236. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8237. (struct lpfc_rcqe *)&cqevt);
  8238. break;
  8239. default:
  8240. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8241. "0388 Not a valid WCQE code: x%x\n",
  8242. bf_get(lpfc_cqe_code, &cqevt));
  8243. break;
  8244. }
  8245. return workposted;
  8246. }
  8247. /**
  8248. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8249. * @phba: Pointer to HBA context object.
  8250. * @eqe: Pointer to fast-path event queue entry.
  8251. *
  8252. * This routine process a event queue entry from the slow-path event queue.
  8253. * It will check the MajorCode and MinorCode to determine this is for a
  8254. * completion event on a completion queue, if not, an error shall be logged
  8255. * and just return. Otherwise, it will get to the corresponding completion
  8256. * queue and process all the entries on that completion queue, rearm the
  8257. * completion queue, and then return.
  8258. *
  8259. **/
  8260. static void
  8261. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8262. {
  8263. struct lpfc_queue *cq = NULL, *childq, *speq;
  8264. struct lpfc_cqe *cqe;
  8265. bool workposted = false;
  8266. int ecount = 0;
  8267. uint16_t cqid;
  8268. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  8269. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8270. "0359 Not a valid slow-path completion "
  8271. "event: majorcode=x%x, minorcode=x%x\n",
  8272. bf_get_le32(lpfc_eqe_major_code, eqe),
  8273. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8274. return;
  8275. }
  8276. /* Get the reference to the corresponding CQ */
  8277. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8278. /* Search for completion queue pointer matching this cqid */
  8279. speq = phba->sli4_hba.sp_eq;
  8280. list_for_each_entry(childq, &speq->child_list, list) {
  8281. if (childq->queue_id == cqid) {
  8282. cq = childq;
  8283. break;
  8284. }
  8285. }
  8286. if (unlikely(!cq)) {
  8287. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8288. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8289. "0365 Slow-path CQ identifier "
  8290. "(%d) does not exist\n", cqid);
  8291. return;
  8292. }
  8293. /* Process all the entries to the CQ */
  8294. switch (cq->type) {
  8295. case LPFC_MCQ:
  8296. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8297. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8298. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8299. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8300. }
  8301. break;
  8302. case LPFC_WCQ:
  8303. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8304. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8305. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8306. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8307. }
  8308. break;
  8309. default:
  8310. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8311. "0370 Invalid completion queue type (%d)\n",
  8312. cq->type);
  8313. return;
  8314. }
  8315. /* Catch the no cq entry condition, log an error */
  8316. if (unlikely(ecount == 0))
  8317. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8318. "0371 No entry from the CQ: identifier "
  8319. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8320. /* In any case, flash and re-arm the RCQ */
  8321. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8322. /* wake up worker thread if there are works to be done */
  8323. if (workposted)
  8324. lpfc_worker_wake_up(phba);
  8325. }
  8326. /**
  8327. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8328. * @eqe: Pointer to fast-path completion queue entry.
  8329. *
  8330. * This routine process a fast-path work queue completion entry from fast-path
  8331. * event queue for FCP command response completion.
  8332. **/
  8333. static void
  8334. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8335. struct lpfc_wcqe_complete *wcqe)
  8336. {
  8337. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8338. struct lpfc_iocbq *cmdiocbq;
  8339. struct lpfc_iocbq irspiocbq;
  8340. unsigned long iflags;
  8341. spin_lock_irqsave(&phba->hbalock, iflags);
  8342. pring->stats.iocb_event++;
  8343. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8344. /* Check for response status */
  8345. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8346. /* If resource errors reported from HBA, reduce queue
  8347. * depth of the SCSI device.
  8348. */
  8349. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8350. IOSTAT_LOCAL_REJECT) &&
  8351. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8352. phba->lpfc_rampdown_queue_depth(phba);
  8353. }
  8354. /* Log the error status */
  8355. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8356. "0373 FCP complete error: status=x%x, "
  8357. "hw_status=x%x, total_data_specified=%d, "
  8358. "parameter=x%x, word3=x%x\n",
  8359. bf_get(lpfc_wcqe_c_status, wcqe),
  8360. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8361. wcqe->total_data_placed, wcqe->parameter,
  8362. wcqe->word3);
  8363. }
  8364. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8365. spin_lock_irqsave(&phba->hbalock, iflags);
  8366. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8367. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8368. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8369. if (unlikely(!cmdiocbq)) {
  8370. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8371. "0374 FCP complete with no corresponding "
  8372. "cmdiocb: iotag (%d)\n",
  8373. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8374. return;
  8375. }
  8376. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8377. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8378. "0375 FCP cmdiocb not callback function "
  8379. "iotag: (%d)\n",
  8380. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8381. return;
  8382. }
  8383. /* Fake the irspiocb and copy necessary response information */
  8384. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8385. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  8386. spin_lock_irqsave(&phba->hbalock, iflags);
  8387. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  8388. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8389. }
  8390. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8391. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8392. }
  8393. /**
  8394. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8395. * @phba: Pointer to HBA context object.
  8396. * @cq: Pointer to completion queue.
  8397. * @wcqe: Pointer to work-queue completion queue entry.
  8398. *
  8399. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8400. * proper WQ release routine to the slow-path WQ.
  8401. **/
  8402. static void
  8403. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8404. struct lpfc_wcqe_release *wcqe)
  8405. {
  8406. struct lpfc_queue *childwq;
  8407. bool wqid_matched = false;
  8408. uint16_t fcp_wqid;
  8409. /* Check for fast-path FCP work queue release */
  8410. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8411. list_for_each_entry(childwq, &cq->child_list, list) {
  8412. if (childwq->queue_id == fcp_wqid) {
  8413. lpfc_sli4_wq_release(childwq,
  8414. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8415. wqid_matched = true;
  8416. break;
  8417. }
  8418. }
  8419. /* Report warning log message if no match found */
  8420. if (wqid_matched != true)
  8421. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8422. "2580 Fast-path wqe consume event carries "
  8423. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8424. }
  8425. /**
  8426. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8427. * @cq: Pointer to the completion queue.
  8428. * @eqe: Pointer to fast-path completion queue entry.
  8429. *
  8430. * This routine process a fast-path work queue completion entry from fast-path
  8431. * event queue for FCP command response completion.
  8432. **/
  8433. static int
  8434. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8435. struct lpfc_cqe *cqe)
  8436. {
  8437. struct lpfc_wcqe_release wcqe;
  8438. bool workposted = false;
  8439. /* Copy the work queue CQE and convert endian order if needed */
  8440. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8441. /* Check and process for different type of WCQE and dispatch */
  8442. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8443. case CQE_CODE_COMPL_WQE:
  8444. /* Process the WQ complete event */
  8445. phba->last_completion_time = jiffies;
  8446. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8447. (struct lpfc_wcqe_complete *)&wcqe);
  8448. break;
  8449. case CQE_CODE_RELEASE_WQE:
  8450. /* Process the WQ release event */
  8451. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8452. (struct lpfc_wcqe_release *)&wcqe);
  8453. break;
  8454. case CQE_CODE_XRI_ABORTED:
  8455. /* Process the WQ XRI abort event */
  8456. phba->last_completion_time = jiffies;
  8457. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8458. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8459. break;
  8460. default:
  8461. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8462. "0144 Not a valid WCQE code: x%x\n",
  8463. bf_get(lpfc_wcqe_c_code, &wcqe));
  8464. break;
  8465. }
  8466. return workposted;
  8467. }
  8468. /**
  8469. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8470. * @phba: Pointer to HBA context object.
  8471. * @eqe: Pointer to fast-path event queue entry.
  8472. *
  8473. * This routine process a event queue entry from the fast-path event queue.
  8474. * It will check the MajorCode and MinorCode to determine this is for a
  8475. * completion event on a completion queue, if not, an error shall be logged
  8476. * and just return. Otherwise, it will get to the corresponding completion
  8477. * queue and process all the entries on the completion queue, rearm the
  8478. * completion queue, and then return.
  8479. **/
  8480. static void
  8481. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8482. uint32_t fcp_cqidx)
  8483. {
  8484. struct lpfc_queue *cq;
  8485. struct lpfc_cqe *cqe;
  8486. bool workposted = false;
  8487. uint16_t cqid;
  8488. int ecount = 0;
  8489. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  8490. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8491. "0366 Not a valid fast-path completion "
  8492. "event: majorcode=x%x, minorcode=x%x\n",
  8493. bf_get_le32(lpfc_eqe_major_code, eqe),
  8494. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8495. return;
  8496. }
  8497. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8498. if (unlikely(!cq)) {
  8499. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8500. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8501. "0367 Fast-path completion queue "
  8502. "does not exist\n");
  8503. return;
  8504. }
  8505. /* Get the reference to the corresponding CQ */
  8506. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8507. if (unlikely(cqid != cq->queue_id)) {
  8508. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8509. "0368 Miss-matched fast-path completion "
  8510. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8511. cqid, cq->queue_id);
  8512. return;
  8513. }
  8514. /* Process all the entries to the CQ */
  8515. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8516. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8517. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8518. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8519. }
  8520. /* Catch the no cq entry condition */
  8521. if (unlikely(ecount == 0))
  8522. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8523. "0369 No entry from fast-path completion "
  8524. "queue fcpcqid=%d\n", cq->queue_id);
  8525. /* In any case, flash and re-arm the CQ */
  8526. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8527. /* wake up worker thread if there are works to be done */
  8528. if (workposted)
  8529. lpfc_worker_wake_up(phba);
  8530. }
  8531. static void
  8532. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8533. {
  8534. struct lpfc_eqe *eqe;
  8535. /* walk all the EQ entries and drop on the floor */
  8536. while ((eqe = lpfc_sli4_eq_get(eq)))
  8537. ;
  8538. /* Clear and re-arm the EQ */
  8539. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8540. }
  8541. /**
  8542. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8543. * @irq: Interrupt number.
  8544. * @dev_id: The device context pointer.
  8545. *
  8546. * This function is directly called from the PCI layer as an interrupt
  8547. * service routine when device with SLI-4 interface spec is enabled with
  8548. * MSI-X multi-message interrupt mode and there are slow-path events in
  8549. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8550. * interrupt mode, this function is called as part of the device-level
  8551. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8552. * undergoing initialization, the interrupt handler will not process the
  8553. * interrupt. The link attention and ELS ring attention events are handled
  8554. * by the worker thread. The interrupt handler signals the worker thread
  8555. * and returns for these events. This function is called without any lock
  8556. * held. It gets the hbalock to access and update SLI data structures.
  8557. *
  8558. * This function returns IRQ_HANDLED when interrupt is handled else it
  8559. * returns IRQ_NONE.
  8560. **/
  8561. irqreturn_t
  8562. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8563. {
  8564. struct lpfc_hba *phba;
  8565. struct lpfc_queue *speq;
  8566. struct lpfc_eqe *eqe;
  8567. unsigned long iflag;
  8568. int ecount = 0;
  8569. /*
  8570. * Get the driver's phba structure from the dev_id
  8571. */
  8572. phba = (struct lpfc_hba *)dev_id;
  8573. if (unlikely(!phba))
  8574. return IRQ_NONE;
  8575. /* Get to the EQ struct associated with this vector */
  8576. speq = phba->sli4_hba.sp_eq;
  8577. /* Check device state for handling interrupt */
  8578. if (unlikely(lpfc_intr_state_check(phba))) {
  8579. /* Check again for link_state with lock held */
  8580. spin_lock_irqsave(&phba->hbalock, iflag);
  8581. if (phba->link_state < LPFC_LINK_DOWN)
  8582. /* Flush, clear interrupt, and rearm the EQ */
  8583. lpfc_sli4_eq_flush(phba, speq);
  8584. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8585. return IRQ_NONE;
  8586. }
  8587. /*
  8588. * Process all the event on FCP slow-path EQ
  8589. */
  8590. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8591. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8592. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8593. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8594. }
  8595. /* Always clear and re-arm the slow-path EQ */
  8596. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8597. /* Catch the no cq entry condition */
  8598. if (unlikely(ecount == 0)) {
  8599. if (phba->intr_type == MSIX)
  8600. /* MSI-X treated interrupt served as no EQ share INT */
  8601. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8602. "0357 MSI-X interrupt with no EQE\n");
  8603. else
  8604. /* Non MSI-X treated on interrupt as EQ share INT */
  8605. return IRQ_NONE;
  8606. }
  8607. return IRQ_HANDLED;
  8608. } /* lpfc_sli4_sp_intr_handler */
  8609. /**
  8610. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8611. * @irq: Interrupt number.
  8612. * @dev_id: The device context pointer.
  8613. *
  8614. * This function is directly called from the PCI layer as an interrupt
  8615. * service routine when device with SLI-4 interface spec is enabled with
  8616. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8617. * ring event in the HBA. However, when the device is enabled with either
  8618. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8619. * device-level interrupt handler. When the PCI slot is in error recovery
  8620. * or the HBA is undergoing initialization, the interrupt handler will not
  8621. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8622. * the intrrupt context. This function is called without any lock held.
  8623. * It gets the hbalock to access and update SLI data structures. Note that,
  8624. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8625. * equal to that of FCP CQ index.
  8626. *
  8627. * This function returns IRQ_HANDLED when interrupt is handled else it
  8628. * returns IRQ_NONE.
  8629. **/
  8630. irqreturn_t
  8631. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8632. {
  8633. struct lpfc_hba *phba;
  8634. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8635. struct lpfc_queue *fpeq;
  8636. struct lpfc_eqe *eqe;
  8637. unsigned long iflag;
  8638. int ecount = 0;
  8639. uint32_t fcp_eqidx;
  8640. /* Get the driver's phba structure from the dev_id */
  8641. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8642. phba = fcp_eq_hdl->phba;
  8643. fcp_eqidx = fcp_eq_hdl->idx;
  8644. if (unlikely(!phba))
  8645. return IRQ_NONE;
  8646. /* Get to the EQ struct associated with this vector */
  8647. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8648. /* Check device state for handling interrupt */
  8649. if (unlikely(lpfc_intr_state_check(phba))) {
  8650. /* Check again for link_state with lock held */
  8651. spin_lock_irqsave(&phba->hbalock, iflag);
  8652. if (phba->link_state < LPFC_LINK_DOWN)
  8653. /* Flush, clear interrupt, and rearm the EQ */
  8654. lpfc_sli4_eq_flush(phba, fpeq);
  8655. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8656. return IRQ_NONE;
  8657. }
  8658. /*
  8659. * Process all the event on FCP fast-path EQ
  8660. */
  8661. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8662. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8663. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8664. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8665. }
  8666. /* Always clear and re-arm the fast-path EQ */
  8667. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8668. if (unlikely(ecount == 0)) {
  8669. if (phba->intr_type == MSIX)
  8670. /* MSI-X treated interrupt served as no EQ share INT */
  8671. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8672. "0358 MSI-X interrupt with no EQE\n");
  8673. else
  8674. /* Non MSI-X treated on interrupt as EQ share INT */
  8675. return IRQ_NONE;
  8676. }
  8677. return IRQ_HANDLED;
  8678. } /* lpfc_sli4_fp_intr_handler */
  8679. /**
  8680. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8681. * @irq: Interrupt number.
  8682. * @dev_id: The device context pointer.
  8683. *
  8684. * This function is the device-level interrupt handler to device with SLI-4
  8685. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8686. * interrupt mode is enabled and there is an event in the HBA which requires
  8687. * driver attention. This function invokes the slow-path interrupt attention
  8688. * handling function and fast-path interrupt attention handling function in
  8689. * turn to process the relevant HBA attention events. This function is called
  8690. * without any lock held. It gets the hbalock to access and update SLI data
  8691. * structures.
  8692. *
  8693. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8694. * returns IRQ_NONE.
  8695. **/
  8696. irqreturn_t
  8697. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8698. {
  8699. struct lpfc_hba *phba;
  8700. irqreturn_t sp_irq_rc, fp_irq_rc;
  8701. bool fp_handled = false;
  8702. uint32_t fcp_eqidx;
  8703. /* Get the driver's phba structure from the dev_id */
  8704. phba = (struct lpfc_hba *)dev_id;
  8705. if (unlikely(!phba))
  8706. return IRQ_NONE;
  8707. /*
  8708. * Invokes slow-path host attention interrupt handling as appropriate.
  8709. */
  8710. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8711. /*
  8712. * Invoke fast-path host attention interrupt handling as appropriate.
  8713. */
  8714. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8715. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8716. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8717. if (fp_irq_rc == IRQ_HANDLED)
  8718. fp_handled |= true;
  8719. }
  8720. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8721. } /* lpfc_sli4_intr_handler */
  8722. /**
  8723. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8724. * @queue: The queue structure to free.
  8725. *
  8726. * This function frees a queue structure and the DMAable memeory used for
  8727. * the host resident queue. This function must be called after destroying the
  8728. * queue on the HBA.
  8729. **/
  8730. void
  8731. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8732. {
  8733. struct lpfc_dmabuf *dmabuf;
  8734. if (!queue)
  8735. return;
  8736. while (!list_empty(&queue->page_list)) {
  8737. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8738. list);
  8739. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  8740. dmabuf->virt, dmabuf->phys);
  8741. kfree(dmabuf);
  8742. }
  8743. kfree(queue);
  8744. return;
  8745. }
  8746. /**
  8747. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8748. * @phba: The HBA that this queue is being created on.
  8749. * @entry_size: The size of each queue entry for this queue.
  8750. * @entry count: The number of entries that this queue will handle.
  8751. *
  8752. * This function allocates a queue structure and the DMAable memory used for
  8753. * the host resident queue. This function must be called before creating the
  8754. * queue on the HBA.
  8755. **/
  8756. struct lpfc_queue *
  8757. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8758. uint32_t entry_count)
  8759. {
  8760. struct lpfc_queue *queue;
  8761. struct lpfc_dmabuf *dmabuf;
  8762. int x, total_qe_count;
  8763. void *dma_pointer;
  8764. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8765. if (!phba->sli4_hba.pc_sli4_params.supported)
  8766. hw_page_size = SLI4_PAGE_SIZE;
  8767. queue = kzalloc(sizeof(struct lpfc_queue) +
  8768. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8769. if (!queue)
  8770. return NULL;
  8771. queue->page_count = (ALIGN(entry_size * entry_count,
  8772. hw_page_size))/hw_page_size;
  8773. INIT_LIST_HEAD(&queue->list);
  8774. INIT_LIST_HEAD(&queue->page_list);
  8775. INIT_LIST_HEAD(&queue->child_list);
  8776. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8777. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8778. if (!dmabuf)
  8779. goto out_fail;
  8780. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8781. hw_page_size, &dmabuf->phys,
  8782. GFP_KERNEL);
  8783. if (!dmabuf->virt) {
  8784. kfree(dmabuf);
  8785. goto out_fail;
  8786. }
  8787. memset(dmabuf->virt, 0, hw_page_size);
  8788. dmabuf->buffer_tag = x;
  8789. list_add_tail(&dmabuf->list, &queue->page_list);
  8790. /* initialize queue's entry array */
  8791. dma_pointer = dmabuf->virt;
  8792. for (; total_qe_count < entry_count &&
  8793. dma_pointer < (hw_page_size + dmabuf->virt);
  8794. total_qe_count++, dma_pointer += entry_size) {
  8795. queue->qe[total_qe_count].address = dma_pointer;
  8796. }
  8797. }
  8798. queue->entry_size = entry_size;
  8799. queue->entry_count = entry_count;
  8800. queue->phba = phba;
  8801. return queue;
  8802. out_fail:
  8803. lpfc_sli4_queue_free(queue);
  8804. return NULL;
  8805. }
  8806. /**
  8807. * lpfc_eq_create - Create an Event Queue on the HBA
  8808. * @phba: HBA structure that indicates port to create a queue on.
  8809. * @eq: The queue structure to use to create the event queue.
  8810. * @imax: The maximum interrupt per second limit.
  8811. *
  8812. * This function creates an event queue, as detailed in @eq, on a port,
  8813. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8814. *
  8815. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8816. * is used to get the entry count and entry size that are necessary to
  8817. * determine the number of pages to allocate and use for this queue. This
  8818. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8819. * event queue. This function is asynchronous and will wait for the mailbox
  8820. * command to finish before continuing.
  8821. *
  8822. * On success this function will return a zero. If unable to allocate enough
  8823. * memory this function will return ENOMEM. If the queue create mailbox command
  8824. * fails this function will return ENXIO.
  8825. **/
  8826. uint32_t
  8827. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8828. {
  8829. struct lpfc_mbx_eq_create *eq_create;
  8830. LPFC_MBOXQ_t *mbox;
  8831. int rc, length, status = 0;
  8832. struct lpfc_dmabuf *dmabuf;
  8833. uint32_t shdr_status, shdr_add_status;
  8834. union lpfc_sli4_cfg_shdr *shdr;
  8835. uint16_t dmult;
  8836. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8837. if (!phba->sli4_hba.pc_sli4_params.supported)
  8838. hw_page_size = SLI4_PAGE_SIZE;
  8839. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8840. if (!mbox)
  8841. return -ENOMEM;
  8842. length = (sizeof(struct lpfc_mbx_eq_create) -
  8843. sizeof(struct lpfc_sli4_cfg_mhdr));
  8844. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8845. LPFC_MBOX_OPCODE_EQ_CREATE,
  8846. length, LPFC_SLI4_MBX_EMBED);
  8847. eq_create = &mbox->u.mqe.un.eq_create;
  8848. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8849. eq->page_count);
  8850. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8851. LPFC_EQE_SIZE);
  8852. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8853. /* Calculate delay multiper from maximum interrupt per second */
  8854. dmult = LPFC_DMULT_CONST/imax - 1;
  8855. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8856. dmult);
  8857. switch (eq->entry_count) {
  8858. default:
  8859. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8860. "0360 Unsupported EQ count. (%d)\n",
  8861. eq->entry_count);
  8862. if (eq->entry_count < 256)
  8863. return -EINVAL;
  8864. /* otherwise default to smallest count (drop through) */
  8865. case 256:
  8866. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8867. LPFC_EQ_CNT_256);
  8868. break;
  8869. case 512:
  8870. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8871. LPFC_EQ_CNT_512);
  8872. break;
  8873. case 1024:
  8874. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8875. LPFC_EQ_CNT_1024);
  8876. break;
  8877. case 2048:
  8878. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8879. LPFC_EQ_CNT_2048);
  8880. break;
  8881. case 4096:
  8882. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8883. LPFC_EQ_CNT_4096);
  8884. break;
  8885. }
  8886. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8887. memset(dmabuf->virt, 0, hw_page_size);
  8888. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8889. putPaddrLow(dmabuf->phys);
  8890. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8891. putPaddrHigh(dmabuf->phys);
  8892. }
  8893. mbox->vport = phba->pport;
  8894. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8895. mbox->context1 = NULL;
  8896. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8897. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8898. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8899. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8900. if (shdr_status || shdr_add_status || rc) {
  8901. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8902. "2500 EQ_CREATE mailbox failed with "
  8903. "status x%x add_status x%x, mbx status x%x\n",
  8904. shdr_status, shdr_add_status, rc);
  8905. status = -ENXIO;
  8906. }
  8907. eq->type = LPFC_EQ;
  8908. eq->subtype = LPFC_NONE;
  8909. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8910. if (eq->queue_id == 0xFFFF)
  8911. status = -ENXIO;
  8912. eq->host_index = 0;
  8913. eq->hba_index = 0;
  8914. mempool_free(mbox, phba->mbox_mem_pool);
  8915. return status;
  8916. }
  8917. /**
  8918. * lpfc_cq_create - Create a Completion Queue on the HBA
  8919. * @phba: HBA structure that indicates port to create a queue on.
  8920. * @cq: The queue structure to use to create the completion queue.
  8921. * @eq: The event queue to bind this completion queue to.
  8922. *
  8923. * This function creates a completion queue, as detailed in @wq, on a port,
  8924. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8925. *
  8926. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8927. * is used to get the entry count and entry size that are necessary to
  8928. * determine the number of pages to allocate and use for this queue. The @eq
  8929. * is used to indicate which event queue to bind this completion queue to. This
  8930. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8931. * completion queue. This function is asynchronous and will wait for the mailbox
  8932. * command to finish before continuing.
  8933. *
  8934. * On success this function will return a zero. If unable to allocate enough
  8935. * memory this function will return ENOMEM. If the queue create mailbox command
  8936. * fails this function will return ENXIO.
  8937. **/
  8938. uint32_t
  8939. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8940. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8941. {
  8942. struct lpfc_mbx_cq_create *cq_create;
  8943. struct lpfc_dmabuf *dmabuf;
  8944. LPFC_MBOXQ_t *mbox;
  8945. int rc, length, status = 0;
  8946. uint32_t shdr_status, shdr_add_status;
  8947. union lpfc_sli4_cfg_shdr *shdr;
  8948. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8949. if (!phba->sli4_hba.pc_sli4_params.supported)
  8950. hw_page_size = SLI4_PAGE_SIZE;
  8951. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8952. if (!mbox)
  8953. return -ENOMEM;
  8954. length = (sizeof(struct lpfc_mbx_cq_create) -
  8955. sizeof(struct lpfc_sli4_cfg_mhdr));
  8956. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8957. LPFC_MBOX_OPCODE_CQ_CREATE,
  8958. length, LPFC_SLI4_MBX_EMBED);
  8959. cq_create = &mbox->u.mqe.un.cq_create;
  8960. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8961. cq->page_count);
  8962. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8963. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8964. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8965. switch (cq->entry_count) {
  8966. default:
  8967. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8968. "0361 Unsupported CQ count. (%d)\n",
  8969. cq->entry_count);
  8970. if (cq->entry_count < 256)
  8971. return -EINVAL;
  8972. /* otherwise default to smallest count (drop through) */
  8973. case 256:
  8974. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8975. LPFC_CQ_CNT_256);
  8976. break;
  8977. case 512:
  8978. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8979. LPFC_CQ_CNT_512);
  8980. break;
  8981. case 1024:
  8982. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8983. LPFC_CQ_CNT_1024);
  8984. break;
  8985. }
  8986. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8987. memset(dmabuf->virt, 0, hw_page_size);
  8988. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8989. putPaddrLow(dmabuf->phys);
  8990. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8991. putPaddrHigh(dmabuf->phys);
  8992. }
  8993. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8994. /* The IOCTL status is embedded in the mailbox subheader. */
  8995. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8996. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8997. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8998. if (shdr_status || shdr_add_status || rc) {
  8999. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9000. "2501 CQ_CREATE mailbox failed with "
  9001. "status x%x add_status x%x, mbx status x%x\n",
  9002. shdr_status, shdr_add_status, rc);
  9003. status = -ENXIO;
  9004. goto out;
  9005. }
  9006. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9007. if (cq->queue_id == 0xFFFF) {
  9008. status = -ENXIO;
  9009. goto out;
  9010. }
  9011. /* link the cq onto the parent eq child list */
  9012. list_add_tail(&cq->list, &eq->child_list);
  9013. /* Set up completion queue's type and subtype */
  9014. cq->type = type;
  9015. cq->subtype = subtype;
  9016. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9017. cq->host_index = 0;
  9018. cq->hba_index = 0;
  9019. out:
  9020. mempool_free(mbox, phba->mbox_mem_pool);
  9021. return status;
  9022. }
  9023. /**
  9024. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  9025. * @phba: HBA structure that indicates port to create a queue on.
  9026. * @mq: The queue structure to use to create the mailbox queue.
  9027. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  9028. * @cq: The completion queue to associate with this cq.
  9029. *
  9030. * This function provides failback (fb) functionality when the
  9031. * mq_create_ext fails on older FW generations. It's purpose is identical
  9032. * to mq_create_ext otherwise.
  9033. *
  9034. * This routine cannot fail as all attributes were previously accessed and
  9035. * initialized in mq_create_ext.
  9036. **/
  9037. static void
  9038. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9039. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  9040. {
  9041. struct lpfc_mbx_mq_create *mq_create;
  9042. struct lpfc_dmabuf *dmabuf;
  9043. int length;
  9044. length = (sizeof(struct lpfc_mbx_mq_create) -
  9045. sizeof(struct lpfc_sli4_cfg_mhdr));
  9046. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9047. LPFC_MBOX_OPCODE_MQ_CREATE,
  9048. length, LPFC_SLI4_MBX_EMBED);
  9049. mq_create = &mbox->u.mqe.un.mq_create;
  9050. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  9051. mq->page_count);
  9052. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  9053. cq->queue_id);
  9054. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  9055. switch (mq->entry_count) {
  9056. case 16:
  9057. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9058. LPFC_MQ_CNT_16);
  9059. break;
  9060. case 32:
  9061. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9062. LPFC_MQ_CNT_32);
  9063. break;
  9064. case 64:
  9065. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9066. LPFC_MQ_CNT_64);
  9067. break;
  9068. case 128:
  9069. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9070. LPFC_MQ_CNT_128);
  9071. break;
  9072. }
  9073. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9074. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9075. putPaddrLow(dmabuf->phys);
  9076. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9077. putPaddrHigh(dmabuf->phys);
  9078. }
  9079. }
  9080. /**
  9081. * lpfc_mq_create - Create a mailbox Queue on the HBA
  9082. * @phba: HBA structure that indicates port to create a queue on.
  9083. * @mq: The queue structure to use to create the mailbox queue.
  9084. * @cq: The completion queue to associate with this cq.
  9085. * @subtype: The queue's subtype.
  9086. *
  9087. * This function creates a mailbox queue, as detailed in @mq, on a port,
  9088. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  9089. *
  9090. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9091. * is used to get the entry count and entry size that are necessary to
  9092. * determine the number of pages to allocate and use for this queue. This
  9093. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  9094. * mailbox queue. This function is asynchronous and will wait for the mailbox
  9095. * command to finish before continuing.
  9096. *
  9097. * On success this function will return a zero. If unable to allocate enough
  9098. * memory this function will return ENOMEM. If the queue create mailbox command
  9099. * fails this function will return ENXIO.
  9100. **/
  9101. int32_t
  9102. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9103. struct lpfc_queue *cq, uint32_t subtype)
  9104. {
  9105. struct lpfc_mbx_mq_create *mq_create;
  9106. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  9107. struct lpfc_dmabuf *dmabuf;
  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. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9113. if (!phba->sli4_hba.pc_sli4_params.supported)
  9114. hw_page_size = SLI4_PAGE_SIZE;
  9115. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9116. if (!mbox)
  9117. return -ENOMEM;
  9118. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  9119. sizeof(struct lpfc_sli4_cfg_mhdr));
  9120. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9121. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  9122. length, LPFC_SLI4_MBX_EMBED);
  9123. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  9124. bf_set(lpfc_mbx_mq_create_ext_num_pages, &mq_create_ext->u.request,
  9125. mq->page_count);
  9126. bf_set(lpfc_mbx_mq_create_ext_async_evt_link, &mq_create_ext->u.request,
  9127. 1);
  9128. bf_set(lpfc_mbx_mq_create_ext_async_evt_fcfste,
  9129. &mq_create_ext->u.request, 1);
  9130. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  9131. &mq_create_ext->u.request, 1);
  9132. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  9133. cq->queue_id);
  9134. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  9135. switch (mq->entry_count) {
  9136. default:
  9137. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9138. "0362 Unsupported MQ count. (%d)\n",
  9139. mq->entry_count);
  9140. if (mq->entry_count < 16)
  9141. return -EINVAL;
  9142. /* otherwise default to smallest count (drop through) */
  9143. case 16:
  9144. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9145. LPFC_MQ_CNT_16);
  9146. break;
  9147. case 32:
  9148. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9149. LPFC_MQ_CNT_32);
  9150. break;
  9151. case 64:
  9152. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9153. LPFC_MQ_CNT_64);
  9154. break;
  9155. case 128:
  9156. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9157. LPFC_MQ_CNT_128);
  9158. break;
  9159. }
  9160. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9161. memset(dmabuf->virt, 0, hw_page_size);
  9162. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  9163. putPaddrLow(dmabuf->phys);
  9164. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  9165. putPaddrHigh(dmabuf->phys);
  9166. }
  9167. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9168. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  9169. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9170. &mq_create_ext->u.response);
  9171. if (rc != MBX_SUCCESS) {
  9172. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9173. "2795 MQ_CREATE_EXT failed with "
  9174. "status x%x. Failback to MQ_CREATE.\n",
  9175. rc);
  9176. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  9177. mq_create = &mbox->u.mqe.un.mq_create;
  9178. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9179. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  9180. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9181. &mq_create->u.response);
  9182. }
  9183. /* The IOCTL status is embedded in the mailbox subheader. */
  9184. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9185. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9186. if (shdr_status || shdr_add_status || rc) {
  9187. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9188. "2502 MQ_CREATE mailbox failed with "
  9189. "status x%x add_status x%x, mbx status x%x\n",
  9190. shdr_status, shdr_add_status, rc);
  9191. status = -ENXIO;
  9192. goto out;
  9193. }
  9194. if (mq->queue_id == 0xFFFF) {
  9195. status = -ENXIO;
  9196. goto out;
  9197. }
  9198. mq->type = LPFC_MQ;
  9199. mq->subtype = subtype;
  9200. mq->host_index = 0;
  9201. mq->hba_index = 0;
  9202. /* link the mq onto the parent cq child list */
  9203. list_add_tail(&mq->list, &cq->child_list);
  9204. out:
  9205. mempool_free(mbox, phba->mbox_mem_pool);
  9206. return status;
  9207. }
  9208. /**
  9209. * lpfc_wq_create - Create a Work Queue on the HBA
  9210. * @phba: HBA structure that indicates port to create a queue on.
  9211. * @wq: The queue structure to use to create the work queue.
  9212. * @cq: The completion queue to bind this work queue to.
  9213. * @subtype: The subtype of the work queue indicating its functionality.
  9214. *
  9215. * This function creates a work queue, as detailed in @wq, on a port, described
  9216. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9217. *
  9218. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9219. * is used to get the entry count and entry size that are necessary to
  9220. * determine the number of pages to allocate and use for this queue. The @cq
  9221. * is used to indicate which completion queue to bind this work queue to. This
  9222. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9223. * work queue. This function is asynchronous and will wait for the mailbox
  9224. * command to finish before continuing.
  9225. *
  9226. * On success this function will return a zero. If unable to allocate enough
  9227. * memory this function will return ENOMEM. If the queue create mailbox command
  9228. * fails this function will return ENXIO.
  9229. **/
  9230. uint32_t
  9231. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9232. struct lpfc_queue *cq, uint32_t subtype)
  9233. {
  9234. struct lpfc_mbx_wq_create *wq_create;
  9235. struct lpfc_dmabuf *dmabuf;
  9236. LPFC_MBOXQ_t *mbox;
  9237. int rc, length, status = 0;
  9238. uint32_t shdr_status, shdr_add_status;
  9239. union lpfc_sli4_cfg_shdr *shdr;
  9240. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9241. if (!phba->sli4_hba.pc_sli4_params.supported)
  9242. hw_page_size = SLI4_PAGE_SIZE;
  9243. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9244. if (!mbox)
  9245. return -ENOMEM;
  9246. length = (sizeof(struct lpfc_mbx_wq_create) -
  9247. sizeof(struct lpfc_sli4_cfg_mhdr));
  9248. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9249. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9250. length, LPFC_SLI4_MBX_EMBED);
  9251. wq_create = &mbox->u.mqe.un.wq_create;
  9252. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9253. wq->page_count);
  9254. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9255. cq->queue_id);
  9256. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9257. memset(dmabuf->virt, 0, hw_page_size);
  9258. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9259. putPaddrLow(dmabuf->phys);
  9260. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9261. putPaddrHigh(dmabuf->phys);
  9262. }
  9263. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9264. /* The IOCTL status is embedded in the mailbox subheader. */
  9265. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9266. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9267. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9268. if (shdr_status || shdr_add_status || rc) {
  9269. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9270. "2503 WQ_CREATE mailbox failed with "
  9271. "status x%x add_status x%x, mbx status x%x\n",
  9272. shdr_status, shdr_add_status, rc);
  9273. status = -ENXIO;
  9274. goto out;
  9275. }
  9276. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9277. if (wq->queue_id == 0xFFFF) {
  9278. status = -ENXIO;
  9279. goto out;
  9280. }
  9281. wq->type = LPFC_WQ;
  9282. wq->subtype = subtype;
  9283. wq->host_index = 0;
  9284. wq->hba_index = 0;
  9285. /* link the wq onto the parent cq child list */
  9286. list_add_tail(&wq->list, &cq->child_list);
  9287. out:
  9288. mempool_free(mbox, phba->mbox_mem_pool);
  9289. return status;
  9290. }
  9291. /**
  9292. * lpfc_rq_create - Create a Receive Queue on the HBA
  9293. * @phba: HBA structure that indicates port to create a queue on.
  9294. * @hrq: The queue structure to use to create the header receive queue.
  9295. * @drq: The queue structure to use to create the data receive queue.
  9296. * @cq: The completion queue to bind this work queue to.
  9297. *
  9298. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9299. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9300. * to the HBA.
  9301. *
  9302. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9303. * struct is used to get the entry count that is necessary to determine the
  9304. * number of pages to use for this queue. The @cq is used to indicate which
  9305. * completion queue to bind received buffers that are posted to these queues to.
  9306. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9307. * receive queue pair. This function is asynchronous and will wait for the
  9308. * mailbox command to finish before continuing.
  9309. *
  9310. * On success this function will return a zero. If unable to allocate enough
  9311. * memory this function will return ENOMEM. If the queue create mailbox command
  9312. * fails this function will return ENXIO.
  9313. **/
  9314. uint32_t
  9315. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9316. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9317. {
  9318. struct lpfc_mbx_rq_create *rq_create;
  9319. struct lpfc_dmabuf *dmabuf;
  9320. LPFC_MBOXQ_t *mbox;
  9321. int rc, length, status = 0;
  9322. uint32_t shdr_status, shdr_add_status;
  9323. union lpfc_sli4_cfg_shdr *shdr;
  9324. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9325. if (!phba->sli4_hba.pc_sli4_params.supported)
  9326. hw_page_size = SLI4_PAGE_SIZE;
  9327. if (hrq->entry_count != drq->entry_count)
  9328. return -EINVAL;
  9329. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9330. if (!mbox)
  9331. return -ENOMEM;
  9332. length = (sizeof(struct lpfc_mbx_rq_create) -
  9333. sizeof(struct lpfc_sli4_cfg_mhdr));
  9334. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9335. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9336. length, LPFC_SLI4_MBX_EMBED);
  9337. rq_create = &mbox->u.mqe.un.rq_create;
  9338. switch (hrq->entry_count) {
  9339. default:
  9340. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9341. "2535 Unsupported RQ count. (%d)\n",
  9342. hrq->entry_count);
  9343. if (hrq->entry_count < 512)
  9344. return -EINVAL;
  9345. /* otherwise default to smallest count (drop through) */
  9346. case 512:
  9347. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9348. LPFC_RQ_RING_SIZE_512);
  9349. break;
  9350. case 1024:
  9351. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9352. LPFC_RQ_RING_SIZE_1024);
  9353. break;
  9354. case 2048:
  9355. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9356. LPFC_RQ_RING_SIZE_2048);
  9357. break;
  9358. case 4096:
  9359. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9360. LPFC_RQ_RING_SIZE_4096);
  9361. break;
  9362. }
  9363. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9364. cq->queue_id);
  9365. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9366. hrq->page_count);
  9367. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9368. LPFC_HDR_BUF_SIZE);
  9369. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9370. memset(dmabuf->virt, 0, hw_page_size);
  9371. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9372. putPaddrLow(dmabuf->phys);
  9373. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9374. putPaddrHigh(dmabuf->phys);
  9375. }
  9376. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9377. /* The IOCTL status is embedded in the mailbox subheader. */
  9378. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9379. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9380. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9381. if (shdr_status || shdr_add_status || rc) {
  9382. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9383. "2504 RQ_CREATE mailbox failed with "
  9384. "status x%x add_status x%x, mbx status x%x\n",
  9385. shdr_status, shdr_add_status, rc);
  9386. status = -ENXIO;
  9387. goto out;
  9388. }
  9389. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9390. if (hrq->queue_id == 0xFFFF) {
  9391. status = -ENXIO;
  9392. goto out;
  9393. }
  9394. hrq->type = LPFC_HRQ;
  9395. hrq->subtype = subtype;
  9396. hrq->host_index = 0;
  9397. hrq->hba_index = 0;
  9398. /* now create the data queue */
  9399. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9400. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9401. length, LPFC_SLI4_MBX_EMBED);
  9402. switch (drq->entry_count) {
  9403. default:
  9404. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9405. "2536 Unsupported RQ count. (%d)\n",
  9406. drq->entry_count);
  9407. if (drq->entry_count < 512)
  9408. return -EINVAL;
  9409. /* otherwise default to smallest count (drop through) */
  9410. case 512:
  9411. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9412. LPFC_RQ_RING_SIZE_512);
  9413. break;
  9414. case 1024:
  9415. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9416. LPFC_RQ_RING_SIZE_1024);
  9417. break;
  9418. case 2048:
  9419. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9420. LPFC_RQ_RING_SIZE_2048);
  9421. break;
  9422. case 4096:
  9423. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9424. LPFC_RQ_RING_SIZE_4096);
  9425. break;
  9426. }
  9427. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9428. cq->queue_id);
  9429. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9430. drq->page_count);
  9431. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9432. LPFC_DATA_BUF_SIZE);
  9433. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9434. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9435. putPaddrLow(dmabuf->phys);
  9436. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9437. putPaddrHigh(dmabuf->phys);
  9438. }
  9439. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9440. /* The IOCTL status is embedded in the mailbox subheader. */
  9441. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9442. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9443. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9444. if (shdr_status || shdr_add_status || rc) {
  9445. status = -ENXIO;
  9446. goto out;
  9447. }
  9448. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9449. if (drq->queue_id == 0xFFFF) {
  9450. status = -ENXIO;
  9451. goto out;
  9452. }
  9453. drq->type = LPFC_DRQ;
  9454. drq->subtype = subtype;
  9455. drq->host_index = 0;
  9456. drq->hba_index = 0;
  9457. /* link the header and data RQs onto the parent cq child list */
  9458. list_add_tail(&hrq->list, &cq->child_list);
  9459. list_add_tail(&drq->list, &cq->child_list);
  9460. out:
  9461. mempool_free(mbox, phba->mbox_mem_pool);
  9462. return status;
  9463. }
  9464. /**
  9465. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9466. * @eq: The queue structure associated with the queue to destroy.
  9467. *
  9468. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9469. * command, specific to the type of queue, to the HBA.
  9470. *
  9471. * The @eq struct is used to get the queue ID of the queue to destroy.
  9472. *
  9473. * On success this function will return a zero. If the queue destroy mailbox
  9474. * command fails this function will return ENXIO.
  9475. **/
  9476. uint32_t
  9477. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9478. {
  9479. LPFC_MBOXQ_t *mbox;
  9480. int rc, length, status = 0;
  9481. uint32_t shdr_status, shdr_add_status;
  9482. union lpfc_sli4_cfg_shdr *shdr;
  9483. if (!eq)
  9484. return -ENODEV;
  9485. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9486. if (!mbox)
  9487. return -ENOMEM;
  9488. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9489. sizeof(struct lpfc_sli4_cfg_mhdr));
  9490. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9491. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9492. length, LPFC_SLI4_MBX_EMBED);
  9493. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9494. eq->queue_id);
  9495. mbox->vport = eq->phba->pport;
  9496. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9497. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9498. /* The IOCTL status is embedded in the mailbox subheader. */
  9499. shdr = (union lpfc_sli4_cfg_shdr *)
  9500. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9501. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9502. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9503. if (shdr_status || shdr_add_status || rc) {
  9504. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9505. "2505 EQ_DESTROY mailbox failed with "
  9506. "status x%x add_status x%x, mbx status x%x\n",
  9507. shdr_status, shdr_add_status, rc);
  9508. status = -ENXIO;
  9509. }
  9510. /* Remove eq from any list */
  9511. list_del_init(&eq->list);
  9512. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9513. return status;
  9514. }
  9515. /**
  9516. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9517. * @cq: The queue structure associated with the queue to destroy.
  9518. *
  9519. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9520. * command, specific to the type of queue, to the HBA.
  9521. *
  9522. * The @cq struct is used to get the queue ID of the queue to destroy.
  9523. *
  9524. * On success this function will return a zero. If the queue destroy mailbox
  9525. * command fails this function will return ENXIO.
  9526. **/
  9527. uint32_t
  9528. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9529. {
  9530. LPFC_MBOXQ_t *mbox;
  9531. int rc, length, status = 0;
  9532. uint32_t shdr_status, shdr_add_status;
  9533. union lpfc_sli4_cfg_shdr *shdr;
  9534. if (!cq)
  9535. return -ENODEV;
  9536. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9537. if (!mbox)
  9538. return -ENOMEM;
  9539. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9540. sizeof(struct lpfc_sli4_cfg_mhdr));
  9541. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9542. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9543. length, LPFC_SLI4_MBX_EMBED);
  9544. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9545. cq->queue_id);
  9546. mbox->vport = cq->phba->pport;
  9547. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9548. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9549. /* The IOCTL status is embedded in the mailbox subheader. */
  9550. shdr = (union lpfc_sli4_cfg_shdr *)
  9551. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9552. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9553. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9554. if (shdr_status || shdr_add_status || rc) {
  9555. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9556. "2506 CQ_DESTROY mailbox failed with "
  9557. "status x%x add_status x%x, mbx status x%x\n",
  9558. shdr_status, shdr_add_status, rc);
  9559. status = -ENXIO;
  9560. }
  9561. /* Remove cq from any list */
  9562. list_del_init(&cq->list);
  9563. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9564. return status;
  9565. }
  9566. /**
  9567. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9568. * @qm: The queue structure associated with the queue to destroy.
  9569. *
  9570. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9571. * command, specific to the type of queue, to the HBA.
  9572. *
  9573. * The @mq struct is used to get the queue ID of the queue to destroy.
  9574. *
  9575. * On success this function will return a zero. If the queue destroy mailbox
  9576. * command fails this function will return ENXIO.
  9577. **/
  9578. uint32_t
  9579. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9580. {
  9581. LPFC_MBOXQ_t *mbox;
  9582. int rc, length, status = 0;
  9583. uint32_t shdr_status, shdr_add_status;
  9584. union lpfc_sli4_cfg_shdr *shdr;
  9585. if (!mq)
  9586. return -ENODEV;
  9587. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9588. if (!mbox)
  9589. return -ENOMEM;
  9590. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9591. sizeof(struct lpfc_sli4_cfg_mhdr));
  9592. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9593. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9594. length, LPFC_SLI4_MBX_EMBED);
  9595. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9596. mq->queue_id);
  9597. mbox->vport = mq->phba->pport;
  9598. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9599. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9600. /* The IOCTL status is embedded in the mailbox subheader. */
  9601. shdr = (union lpfc_sli4_cfg_shdr *)
  9602. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9603. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9604. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9605. if (shdr_status || shdr_add_status || rc) {
  9606. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9607. "2507 MQ_DESTROY mailbox failed with "
  9608. "status x%x add_status x%x, mbx status x%x\n",
  9609. shdr_status, shdr_add_status, rc);
  9610. status = -ENXIO;
  9611. }
  9612. /* Remove mq from any list */
  9613. list_del_init(&mq->list);
  9614. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9615. return status;
  9616. }
  9617. /**
  9618. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9619. * @wq: The queue structure associated with the queue to destroy.
  9620. *
  9621. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9622. * command, specific to the type of queue, to the HBA.
  9623. *
  9624. * The @wq struct is used to get the queue ID of the queue to destroy.
  9625. *
  9626. * On success this function will return a zero. If the queue destroy mailbox
  9627. * command fails this function will return ENXIO.
  9628. **/
  9629. uint32_t
  9630. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9631. {
  9632. LPFC_MBOXQ_t *mbox;
  9633. int rc, length, status = 0;
  9634. uint32_t shdr_status, shdr_add_status;
  9635. union lpfc_sli4_cfg_shdr *shdr;
  9636. if (!wq)
  9637. return -ENODEV;
  9638. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9639. if (!mbox)
  9640. return -ENOMEM;
  9641. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9642. sizeof(struct lpfc_sli4_cfg_mhdr));
  9643. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9644. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9645. length, LPFC_SLI4_MBX_EMBED);
  9646. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9647. wq->queue_id);
  9648. mbox->vport = wq->phba->pport;
  9649. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9650. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9651. shdr = (union lpfc_sli4_cfg_shdr *)
  9652. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9653. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9654. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9655. if (shdr_status || shdr_add_status || rc) {
  9656. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9657. "2508 WQ_DESTROY mailbox failed with "
  9658. "status x%x add_status x%x, mbx status x%x\n",
  9659. shdr_status, shdr_add_status, rc);
  9660. status = -ENXIO;
  9661. }
  9662. /* Remove wq from any list */
  9663. list_del_init(&wq->list);
  9664. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9665. return status;
  9666. }
  9667. /**
  9668. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9669. * @rq: The queue structure associated with the queue to destroy.
  9670. *
  9671. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9672. * command, specific to the type of queue, to the HBA.
  9673. *
  9674. * The @rq struct is used to get the queue ID of the queue to destroy.
  9675. *
  9676. * On success this function will return a zero. If the queue destroy mailbox
  9677. * command fails this function will return ENXIO.
  9678. **/
  9679. uint32_t
  9680. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9681. struct lpfc_queue *drq)
  9682. {
  9683. LPFC_MBOXQ_t *mbox;
  9684. int rc, length, status = 0;
  9685. uint32_t shdr_status, shdr_add_status;
  9686. union lpfc_sli4_cfg_shdr *shdr;
  9687. if (!hrq || !drq)
  9688. return -ENODEV;
  9689. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9690. if (!mbox)
  9691. return -ENOMEM;
  9692. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9693. sizeof(struct mbox_header));
  9694. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9695. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9696. length, LPFC_SLI4_MBX_EMBED);
  9697. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9698. hrq->queue_id);
  9699. mbox->vport = hrq->phba->pport;
  9700. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9701. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9702. /* The IOCTL status is embedded in the mailbox subheader. */
  9703. shdr = (union lpfc_sli4_cfg_shdr *)
  9704. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9705. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9706. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9707. if (shdr_status || shdr_add_status || rc) {
  9708. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9709. "2509 RQ_DESTROY mailbox failed with "
  9710. "status x%x add_status x%x, mbx status x%x\n",
  9711. shdr_status, shdr_add_status, rc);
  9712. if (rc != MBX_TIMEOUT)
  9713. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9714. return -ENXIO;
  9715. }
  9716. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9717. drq->queue_id);
  9718. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9719. shdr = (union lpfc_sli4_cfg_shdr *)
  9720. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9721. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9722. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9723. if (shdr_status || shdr_add_status || rc) {
  9724. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9725. "2510 RQ_DESTROY mailbox failed with "
  9726. "status x%x add_status x%x, mbx status x%x\n",
  9727. shdr_status, shdr_add_status, rc);
  9728. status = -ENXIO;
  9729. }
  9730. list_del_init(&hrq->list);
  9731. list_del_init(&drq->list);
  9732. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9733. return status;
  9734. }
  9735. /**
  9736. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9737. * @phba: The virtual port for which this call being executed.
  9738. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9739. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9740. * @xritag: the xritag that ties this io to the SGL pages.
  9741. *
  9742. * This routine will post the sgl pages for the IO that has the xritag
  9743. * that is in the iocbq structure. The xritag is assigned during iocbq
  9744. * creation and persists for as long as the driver is loaded.
  9745. * if the caller has fewer than 256 scatter gather segments to map then
  9746. * pdma_phys_addr1 should be 0.
  9747. * If the caller needs to map more than 256 scatter gather segment then
  9748. * pdma_phys_addr1 should be a valid physical address.
  9749. * physical address for SGLs must be 64 byte aligned.
  9750. * If you are going to map 2 SGL's then the first one must have 256 entries
  9751. * the second sgl can have between 1 and 256 entries.
  9752. *
  9753. * Return codes:
  9754. * 0 - Success
  9755. * -ENXIO, -ENOMEM - Failure
  9756. **/
  9757. int
  9758. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9759. dma_addr_t pdma_phys_addr0,
  9760. dma_addr_t pdma_phys_addr1,
  9761. uint16_t xritag)
  9762. {
  9763. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9764. LPFC_MBOXQ_t *mbox;
  9765. int rc;
  9766. uint32_t shdr_status, shdr_add_status;
  9767. union lpfc_sli4_cfg_shdr *shdr;
  9768. if (xritag == NO_XRI) {
  9769. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9770. "0364 Invalid param:\n");
  9771. return -EINVAL;
  9772. }
  9773. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9774. if (!mbox)
  9775. return -ENOMEM;
  9776. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9777. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9778. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9779. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9780. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9781. &mbox->u.mqe.un.post_sgl_pages;
  9782. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9783. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9784. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9785. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9786. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9787. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9788. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9789. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9790. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9791. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9792. if (!phba->sli4_hba.intr_enable)
  9793. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9794. else
  9795. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9796. /* The IOCTL status is embedded in the mailbox subheader. */
  9797. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9798. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9799. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9800. if (rc != MBX_TIMEOUT)
  9801. mempool_free(mbox, phba->mbox_mem_pool);
  9802. if (shdr_status || shdr_add_status || rc) {
  9803. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9804. "2511 POST_SGL mailbox failed with "
  9805. "status x%x add_status x%x, mbx status x%x\n",
  9806. shdr_status, shdr_add_status, rc);
  9807. rc = -ENXIO;
  9808. }
  9809. return 0;
  9810. }
  9811. /**
  9812. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9813. * @phba: The virtual port for which this call being executed.
  9814. *
  9815. * This routine will remove all of the sgl pages registered with the hba.
  9816. *
  9817. * Return codes:
  9818. * 0 - Success
  9819. * -ENXIO, -ENOMEM - Failure
  9820. **/
  9821. int
  9822. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9823. {
  9824. LPFC_MBOXQ_t *mbox;
  9825. int rc;
  9826. uint32_t shdr_status, shdr_add_status;
  9827. union lpfc_sli4_cfg_shdr *shdr;
  9828. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9829. if (!mbox)
  9830. return -ENOMEM;
  9831. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9832. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9833. LPFC_SLI4_MBX_EMBED);
  9834. if (!phba->sli4_hba.intr_enable)
  9835. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9836. else
  9837. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9838. /* The IOCTL status is embedded in the mailbox subheader. */
  9839. shdr = (union lpfc_sli4_cfg_shdr *)
  9840. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9841. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9842. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9843. if (rc != MBX_TIMEOUT)
  9844. mempool_free(mbox, phba->mbox_mem_pool);
  9845. if (shdr_status || shdr_add_status || rc) {
  9846. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9847. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9848. "status x%x add_status x%x, mbx status x%x\n",
  9849. shdr_status, shdr_add_status, rc);
  9850. rc = -ENXIO;
  9851. }
  9852. return rc;
  9853. }
  9854. /**
  9855. * lpfc_sli4_next_xritag - Get an xritag for the io
  9856. * @phba: Pointer to HBA context object.
  9857. *
  9858. * This function gets an xritag for the iocb. If there is no unused xritag
  9859. * it will return 0xffff.
  9860. * The function returns the allocated xritag if successful, else returns zero.
  9861. * Zero is not a valid xritag.
  9862. * The caller is not required to hold any lock.
  9863. **/
  9864. uint16_t
  9865. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9866. {
  9867. uint16_t xritag;
  9868. spin_lock_irq(&phba->hbalock);
  9869. xritag = phba->sli4_hba.next_xri;
  9870. if ((xritag != (uint16_t) -1) && xritag <
  9871. (phba->sli4_hba.max_cfg_param.max_xri
  9872. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9873. phba->sli4_hba.next_xri++;
  9874. phba->sli4_hba.max_cfg_param.xri_used++;
  9875. spin_unlock_irq(&phba->hbalock);
  9876. return xritag;
  9877. }
  9878. spin_unlock_irq(&phba->hbalock);
  9879. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9880. "2004 Failed to allocate XRI.last XRITAG is %d"
  9881. " Max XRI is %d, Used XRI is %d\n",
  9882. phba->sli4_hba.next_xri,
  9883. phba->sli4_hba.max_cfg_param.max_xri,
  9884. phba->sli4_hba.max_cfg_param.xri_used);
  9885. return -1;
  9886. }
  9887. /**
  9888. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9889. * @phba: pointer to lpfc hba data structure.
  9890. *
  9891. * This routine is invoked to post a block of driver's sgl pages to the
  9892. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9893. * is only called when the driver is loading and after all IO has been
  9894. * stopped.
  9895. **/
  9896. int
  9897. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9898. {
  9899. struct lpfc_sglq *sglq_entry;
  9900. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9901. struct sgl_page_pairs *sgl_pg_pairs;
  9902. void *viraddr;
  9903. LPFC_MBOXQ_t *mbox;
  9904. uint32_t reqlen, alloclen, pg_pairs;
  9905. uint32_t mbox_tmo;
  9906. uint16_t xritag_start = 0;
  9907. int els_xri_cnt, rc = 0;
  9908. uint32_t shdr_status, shdr_add_status;
  9909. union lpfc_sli4_cfg_shdr *shdr;
  9910. /* The number of sgls to be posted */
  9911. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9912. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9913. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9914. if (reqlen > SLI4_PAGE_SIZE) {
  9915. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9916. "2559 Block sgl registration required DMA "
  9917. "size (%d) great than a page\n", reqlen);
  9918. return -ENOMEM;
  9919. }
  9920. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9921. if (!mbox) {
  9922. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9923. "2560 Failed to allocate mbox cmd memory\n");
  9924. return -ENOMEM;
  9925. }
  9926. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9927. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9928. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9929. LPFC_SLI4_MBX_NEMBED);
  9930. if (alloclen < reqlen) {
  9931. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9932. "0285 Allocated DMA memory size (%d) is "
  9933. "less than the requested DMA memory "
  9934. "size (%d)\n", alloclen, reqlen);
  9935. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9936. return -ENOMEM;
  9937. }
  9938. /* Get the first SGE entry from the non-embedded DMA memory */
  9939. viraddr = mbox->sge_array->addr[0];
  9940. /* Set up the SGL pages in the non-embedded DMA pages */
  9941. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9942. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9943. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9944. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9945. /* Set up the sge entry */
  9946. sgl_pg_pairs->sgl_pg0_addr_lo =
  9947. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9948. sgl_pg_pairs->sgl_pg0_addr_hi =
  9949. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9950. sgl_pg_pairs->sgl_pg1_addr_lo =
  9951. cpu_to_le32(putPaddrLow(0));
  9952. sgl_pg_pairs->sgl_pg1_addr_hi =
  9953. cpu_to_le32(putPaddrHigh(0));
  9954. /* Keep the first xritag on the list */
  9955. if (pg_pairs == 0)
  9956. xritag_start = sglq_entry->sli4_xritag;
  9957. sgl_pg_pairs++;
  9958. }
  9959. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9960. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  9961. /* Perform endian conversion if necessary */
  9962. sgl->word0 = cpu_to_le32(sgl->word0);
  9963. if (!phba->sli4_hba.intr_enable)
  9964. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9965. else {
  9966. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9967. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9968. }
  9969. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9970. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9971. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9972. if (rc != MBX_TIMEOUT)
  9973. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9974. if (shdr_status || shdr_add_status || rc) {
  9975. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9976. "2513 POST_SGL_BLOCK mailbox command failed "
  9977. "status x%x add_status x%x mbx status x%x\n",
  9978. shdr_status, shdr_add_status, rc);
  9979. rc = -ENXIO;
  9980. }
  9981. return rc;
  9982. }
  9983. /**
  9984. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9985. * @phba: pointer to lpfc hba data structure.
  9986. * @sblist: pointer to scsi buffer list.
  9987. * @count: number of scsi buffers on the list.
  9988. *
  9989. * This routine is invoked to post a block of @count scsi sgl pages from a
  9990. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9991. * No Lock is held.
  9992. *
  9993. **/
  9994. int
  9995. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9996. int cnt)
  9997. {
  9998. struct lpfc_scsi_buf *psb;
  9999. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10000. struct sgl_page_pairs *sgl_pg_pairs;
  10001. void *viraddr;
  10002. LPFC_MBOXQ_t *mbox;
  10003. uint32_t reqlen, alloclen, pg_pairs;
  10004. uint32_t mbox_tmo;
  10005. uint16_t xritag_start = 0;
  10006. int rc = 0;
  10007. uint32_t shdr_status, shdr_add_status;
  10008. dma_addr_t pdma_phys_bpl1;
  10009. union lpfc_sli4_cfg_shdr *shdr;
  10010. /* Calculate the requested length of the dma memory */
  10011. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  10012. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10013. if (reqlen > SLI4_PAGE_SIZE) {
  10014. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10015. "0217 Block sgl registration required DMA "
  10016. "size (%d) great than a page\n", reqlen);
  10017. return -ENOMEM;
  10018. }
  10019. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10020. if (!mbox) {
  10021. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10022. "0283 Failed to allocate mbox cmd memory\n");
  10023. return -ENOMEM;
  10024. }
  10025. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10026. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10027. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10028. LPFC_SLI4_MBX_NEMBED);
  10029. if (alloclen < reqlen) {
  10030. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10031. "2561 Allocated DMA memory size (%d) is "
  10032. "less than the requested DMA memory "
  10033. "size (%d)\n", alloclen, reqlen);
  10034. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10035. return -ENOMEM;
  10036. }
  10037. /* Get the first SGE entry from the non-embedded DMA memory */
  10038. viraddr = mbox->sge_array->addr[0];
  10039. /* Set up the SGL pages in the non-embedded DMA pages */
  10040. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10041. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10042. pg_pairs = 0;
  10043. list_for_each_entry(psb, sblist, list) {
  10044. /* Set up the sge entry */
  10045. sgl_pg_pairs->sgl_pg0_addr_lo =
  10046. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  10047. sgl_pg_pairs->sgl_pg0_addr_hi =
  10048. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  10049. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  10050. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  10051. else
  10052. pdma_phys_bpl1 = 0;
  10053. sgl_pg_pairs->sgl_pg1_addr_lo =
  10054. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  10055. sgl_pg_pairs->sgl_pg1_addr_hi =
  10056. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  10057. /* Keep the first xritag on the list */
  10058. if (pg_pairs == 0)
  10059. xritag_start = psb->cur_iocbq.sli4_xritag;
  10060. sgl_pg_pairs++;
  10061. pg_pairs++;
  10062. }
  10063. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10064. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  10065. /* Perform endian conversion if necessary */
  10066. sgl->word0 = cpu_to_le32(sgl->word0);
  10067. if (!phba->sli4_hba.intr_enable)
  10068. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10069. else {
  10070. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10071. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10072. }
  10073. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10074. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10075. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10076. if (rc != MBX_TIMEOUT)
  10077. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10078. if (shdr_status || shdr_add_status || rc) {
  10079. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10080. "2564 POST_SGL_BLOCK mailbox command failed "
  10081. "status x%x add_status x%x mbx status x%x\n",
  10082. shdr_status, shdr_add_status, rc);
  10083. rc = -ENXIO;
  10084. }
  10085. return rc;
  10086. }
  10087. /**
  10088. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  10089. * @phba: pointer to lpfc_hba struct that the frame was received on
  10090. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10091. *
  10092. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  10093. * valid type of frame that the LPFC driver will handle. This function will
  10094. * return a zero if the frame is a valid frame or a non zero value when the
  10095. * frame does not pass the check.
  10096. **/
  10097. static int
  10098. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  10099. {
  10100. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  10101. char *type_names[] = FC_TYPE_NAMES_INIT;
  10102. struct fc_vft_header *fc_vft_hdr;
  10103. switch (fc_hdr->fh_r_ctl) {
  10104. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  10105. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  10106. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  10107. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  10108. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  10109. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  10110. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  10111. case FC_RCTL_DD_CMD_STATUS: /* command status */
  10112. case FC_RCTL_ELS_REQ: /* extended link services request */
  10113. case FC_RCTL_ELS_REP: /* extended link services reply */
  10114. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  10115. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  10116. case FC_RCTL_BA_NOP: /* basic link service NOP */
  10117. case FC_RCTL_BA_ABTS: /* basic link service abort */
  10118. case FC_RCTL_BA_RMC: /* remove connection */
  10119. case FC_RCTL_BA_ACC: /* basic accept */
  10120. case FC_RCTL_BA_RJT: /* basic reject */
  10121. case FC_RCTL_BA_PRMT:
  10122. case FC_RCTL_ACK_1: /* acknowledge_1 */
  10123. case FC_RCTL_ACK_0: /* acknowledge_0 */
  10124. case FC_RCTL_P_RJT: /* port reject */
  10125. case FC_RCTL_F_RJT: /* fabric reject */
  10126. case FC_RCTL_P_BSY: /* port busy */
  10127. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  10128. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  10129. case FC_RCTL_LCR: /* link credit reset */
  10130. case FC_RCTL_END: /* end */
  10131. break;
  10132. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  10133. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10134. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  10135. return lpfc_fc_frame_check(phba, fc_hdr);
  10136. default:
  10137. goto drop;
  10138. }
  10139. switch (fc_hdr->fh_type) {
  10140. case FC_TYPE_BLS:
  10141. case FC_TYPE_ELS:
  10142. case FC_TYPE_FCP:
  10143. case FC_TYPE_CT:
  10144. break;
  10145. case FC_TYPE_IP:
  10146. case FC_TYPE_ILS:
  10147. default:
  10148. goto drop;
  10149. }
  10150. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10151. "2538 Received frame rctl:%s type:%s\n",
  10152. rctl_names[fc_hdr->fh_r_ctl],
  10153. type_names[fc_hdr->fh_type]);
  10154. return 0;
  10155. drop:
  10156. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10157. "2539 Dropped frame rctl:%s type:%s\n",
  10158. rctl_names[fc_hdr->fh_r_ctl],
  10159. type_names[fc_hdr->fh_type]);
  10160. return 1;
  10161. }
  10162. /**
  10163. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  10164. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10165. *
  10166. * This function processes the FC header to retrieve the VFI from the VF
  10167. * header, if one exists. This function will return the VFI if one exists
  10168. * or 0 if no VSAN Header exists.
  10169. **/
  10170. static uint32_t
  10171. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  10172. {
  10173. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10174. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  10175. return 0;
  10176. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  10177. }
  10178. /**
  10179. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  10180. * @phba: Pointer to the HBA structure to search for the vport on
  10181. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10182. * @fcfi: The FC Fabric ID that the frame came from
  10183. *
  10184. * This function searches the @phba for a vport that matches the content of the
  10185. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  10186. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  10187. * returns the matching vport pointer or NULL if unable to match frame to a
  10188. * vport.
  10189. **/
  10190. static struct lpfc_vport *
  10191. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  10192. uint16_t fcfi)
  10193. {
  10194. struct lpfc_vport **vports;
  10195. struct lpfc_vport *vport = NULL;
  10196. int i;
  10197. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  10198. fc_hdr->fh_d_id[1] << 8 |
  10199. fc_hdr->fh_d_id[2]);
  10200. vports = lpfc_create_vport_work_array(phba);
  10201. if (vports != NULL)
  10202. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  10203. if (phba->fcf.fcfi == fcfi &&
  10204. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  10205. vports[i]->fc_myDID == did) {
  10206. vport = vports[i];
  10207. break;
  10208. }
  10209. }
  10210. lpfc_destroy_vport_work_array(phba, vports);
  10211. return vport;
  10212. }
  10213. /**
  10214. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  10215. * @vport: The vport to work on.
  10216. *
  10217. * This function updates the receive sequence time stamp for this vport. The
  10218. * receive sequence time stamp indicates the time that the last frame of the
  10219. * the sequence that has been idle for the longest amount of time was received.
  10220. * the driver uses this time stamp to indicate if any received sequences have
  10221. * timed out.
  10222. **/
  10223. void
  10224. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10225. {
  10226. struct lpfc_dmabuf *h_buf;
  10227. struct hbq_dmabuf *dmabuf = NULL;
  10228. /* get the oldest sequence on the rcv list */
  10229. h_buf = list_get_first(&vport->rcv_buffer_list,
  10230. struct lpfc_dmabuf, list);
  10231. if (!h_buf)
  10232. return;
  10233. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10234. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10235. }
  10236. /**
  10237. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10238. * @vport: The vport that the received sequences were sent to.
  10239. *
  10240. * This function cleans up all outstanding received sequences. This is called
  10241. * by the driver when a link event or user action invalidates all the received
  10242. * sequences.
  10243. **/
  10244. void
  10245. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10246. {
  10247. struct lpfc_dmabuf *h_buf, *hnext;
  10248. struct lpfc_dmabuf *d_buf, *dnext;
  10249. struct hbq_dmabuf *dmabuf = NULL;
  10250. /* start with the oldest sequence on the rcv list */
  10251. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10252. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10253. list_del_init(&dmabuf->hbuf.list);
  10254. list_for_each_entry_safe(d_buf, dnext,
  10255. &dmabuf->dbuf.list, list) {
  10256. list_del_init(&d_buf->list);
  10257. lpfc_in_buf_free(vport->phba, d_buf);
  10258. }
  10259. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10260. }
  10261. }
  10262. /**
  10263. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10264. * @vport: The vport that the received sequences were sent to.
  10265. *
  10266. * This function determines whether any received sequences have timed out by
  10267. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10268. * indicates that there is at least one timed out sequence this routine will
  10269. * go through the received sequences one at a time from most inactive to most
  10270. * active to determine which ones need to be cleaned up. Once it has determined
  10271. * that a sequence needs to be cleaned up it will simply free up the resources
  10272. * without sending an abort.
  10273. **/
  10274. void
  10275. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10276. {
  10277. struct lpfc_dmabuf *h_buf, *hnext;
  10278. struct lpfc_dmabuf *d_buf, *dnext;
  10279. struct hbq_dmabuf *dmabuf = NULL;
  10280. unsigned long timeout;
  10281. int abort_count = 0;
  10282. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10283. vport->rcv_buffer_time_stamp);
  10284. if (list_empty(&vport->rcv_buffer_list) ||
  10285. time_before(jiffies, timeout))
  10286. return;
  10287. /* start with the oldest sequence on the rcv list */
  10288. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10289. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10290. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10291. dmabuf->time_stamp);
  10292. if (time_before(jiffies, timeout))
  10293. break;
  10294. abort_count++;
  10295. list_del_init(&dmabuf->hbuf.list);
  10296. list_for_each_entry_safe(d_buf, dnext,
  10297. &dmabuf->dbuf.list, list) {
  10298. list_del_init(&d_buf->list);
  10299. lpfc_in_buf_free(vport->phba, d_buf);
  10300. }
  10301. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10302. }
  10303. if (abort_count)
  10304. lpfc_update_rcv_time_stamp(vport);
  10305. }
  10306. /**
  10307. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10308. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10309. *
  10310. * This function searches through the existing incomplete sequences that have
  10311. * been sent to this @vport. If the frame matches one of the incomplete
  10312. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10313. * make up that sequence. If no sequence is found that matches this frame then
  10314. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10315. * This function returns a pointer to the first dmabuf in the sequence list that
  10316. * the frame was linked to.
  10317. **/
  10318. static struct hbq_dmabuf *
  10319. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10320. {
  10321. struct fc_frame_header *new_hdr;
  10322. struct fc_frame_header *temp_hdr;
  10323. struct lpfc_dmabuf *d_buf;
  10324. struct lpfc_dmabuf *h_buf;
  10325. struct hbq_dmabuf *seq_dmabuf = NULL;
  10326. struct hbq_dmabuf *temp_dmabuf = NULL;
  10327. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10328. dmabuf->time_stamp = jiffies;
  10329. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10330. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10331. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10332. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10333. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10334. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10335. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10336. continue;
  10337. /* found a pending sequence that matches this frame */
  10338. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10339. break;
  10340. }
  10341. if (!seq_dmabuf) {
  10342. /*
  10343. * This indicates first frame received for this sequence.
  10344. * Queue the buffer on the vport's rcv_buffer_list.
  10345. */
  10346. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10347. lpfc_update_rcv_time_stamp(vport);
  10348. return dmabuf;
  10349. }
  10350. temp_hdr = seq_dmabuf->hbuf.virt;
  10351. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10352. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10353. list_del_init(&seq_dmabuf->hbuf.list);
  10354. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10355. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10356. lpfc_update_rcv_time_stamp(vport);
  10357. return dmabuf;
  10358. }
  10359. /* move this sequence to the tail to indicate a young sequence */
  10360. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10361. seq_dmabuf->time_stamp = jiffies;
  10362. lpfc_update_rcv_time_stamp(vport);
  10363. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10364. temp_hdr = dmabuf->hbuf.virt;
  10365. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10366. return seq_dmabuf;
  10367. }
  10368. /* find the correct place in the sequence to insert this frame */
  10369. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10370. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10371. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10372. /*
  10373. * If the frame's sequence count is greater than the frame on
  10374. * the list then insert the frame right after this frame
  10375. */
  10376. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10377. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10378. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10379. return seq_dmabuf;
  10380. }
  10381. }
  10382. return NULL;
  10383. }
  10384. /**
  10385. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10386. * @vport: pointer to a vitural port
  10387. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10388. *
  10389. * This function tries to abort from the partially assembed sequence, described
  10390. * by the information from basic abbort @dmabuf. It checks to see whether such
  10391. * partially assembled sequence held by the driver. If so, it shall free up all
  10392. * the frames from the partially assembled sequence.
  10393. *
  10394. * Return
  10395. * true -- if there is matching partially assembled sequence present and all
  10396. * the frames freed with the sequence;
  10397. * false -- if there is no matching partially assembled sequence present so
  10398. * nothing got aborted in the lower layer driver
  10399. **/
  10400. static bool
  10401. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10402. struct hbq_dmabuf *dmabuf)
  10403. {
  10404. struct fc_frame_header *new_hdr;
  10405. struct fc_frame_header *temp_hdr;
  10406. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10407. struct hbq_dmabuf *seq_dmabuf = NULL;
  10408. /* Use the hdr_buf to find the sequence that matches this frame */
  10409. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10410. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10411. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10412. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10413. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10414. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10415. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10416. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10417. continue;
  10418. /* found a pending sequence that matches this frame */
  10419. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10420. break;
  10421. }
  10422. /* Free up all the frames from the partially assembled sequence */
  10423. if (seq_dmabuf) {
  10424. list_for_each_entry_safe(d_buf, n_buf,
  10425. &seq_dmabuf->dbuf.list, list) {
  10426. list_del_init(&d_buf->list);
  10427. lpfc_in_buf_free(vport->phba, d_buf);
  10428. }
  10429. return true;
  10430. }
  10431. return false;
  10432. }
  10433. /**
  10434. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10435. * @phba: Pointer to HBA context object.
  10436. * @cmd_iocbq: pointer to the command iocbq structure.
  10437. * @rsp_iocbq: pointer to the response iocbq structure.
  10438. *
  10439. * This function handles the sequence abort accept iocb command complete
  10440. * event. It properly releases the memory allocated to the sequence abort
  10441. * accept iocb.
  10442. **/
  10443. static void
  10444. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10445. struct lpfc_iocbq *cmd_iocbq,
  10446. struct lpfc_iocbq *rsp_iocbq)
  10447. {
  10448. if (cmd_iocbq)
  10449. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10450. }
  10451. /**
  10452. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10453. * @phba: Pointer to HBA context object.
  10454. * @fc_hdr: pointer to a FC frame header.
  10455. *
  10456. * This function sends a basic accept to a previous unsol sequence abort
  10457. * event after aborting the sequence handling.
  10458. **/
  10459. static void
  10460. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10461. struct fc_frame_header *fc_hdr)
  10462. {
  10463. struct lpfc_iocbq *ctiocb = NULL;
  10464. struct lpfc_nodelist *ndlp;
  10465. uint16_t oxid, rxid;
  10466. uint32_t sid, fctl;
  10467. IOCB_t *icmd;
  10468. if (!lpfc_is_link_up(phba))
  10469. return;
  10470. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10471. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10472. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10473. ndlp = lpfc_findnode_did(phba->pport, sid);
  10474. if (!ndlp) {
  10475. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10476. "1268 Find ndlp returned NULL for oxid:x%x "
  10477. "SID:x%x\n", oxid, sid);
  10478. return;
  10479. }
  10480. /* Allocate buffer for acc iocb */
  10481. ctiocb = lpfc_sli_get_iocbq(phba);
  10482. if (!ctiocb)
  10483. return;
  10484. /* Extract the F_CTL field from FC_HDR */
  10485. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10486. icmd = &ctiocb->iocb;
  10487. icmd->un.xseq64.bdl.bdeSize = 0;
  10488. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10489. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10490. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10491. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10492. /* Fill in the rest of iocb fields */
  10493. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10494. icmd->ulpBdeCount = 0;
  10495. icmd->ulpLe = 1;
  10496. icmd->ulpClass = CLASS3;
  10497. icmd->ulpContext = ndlp->nlp_rpi;
  10498. ctiocb->iocb_cmpl = NULL;
  10499. ctiocb->vport = phba->pport;
  10500. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10501. if (fctl & FC_FC_EX_CTX) {
  10502. /* ABTS sent by responder to CT exchange, construction
  10503. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10504. * field and RX_ID from ABTS for RX_ID field.
  10505. */
  10506. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10507. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10508. ctiocb->sli4_xritag = oxid;
  10509. } else {
  10510. /* ABTS sent by initiator to CT exchange, construction
  10511. * of BA_ACC will need to allocate a new XRI as for the
  10512. * XRI_TAG and RX_ID fields.
  10513. */
  10514. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  10515. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  10516. ctiocb->sli4_xritag = NO_XRI;
  10517. }
  10518. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  10519. /* Xmit CT abts accept on exchange <xid> */
  10520. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10521. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10522. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10523. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10524. }
  10525. /**
  10526. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10527. * @vport: Pointer to the vport on which this sequence was received
  10528. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10529. *
  10530. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10531. * receive sequence is only partially assembed by the driver, it shall abort
  10532. * the partially assembled frames for the sequence. Otherwise, if the
  10533. * unsolicited receive sequence has been completely assembled and passed to
  10534. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10535. * unsolicited sequence has been aborted. After that, it will issue a basic
  10536. * accept to accept the abort.
  10537. **/
  10538. void
  10539. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10540. struct hbq_dmabuf *dmabuf)
  10541. {
  10542. struct lpfc_hba *phba = vport->phba;
  10543. struct fc_frame_header fc_hdr;
  10544. uint32_t fctl;
  10545. bool abts_par;
  10546. /* Make a copy of fc_hdr before the dmabuf being released */
  10547. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  10548. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  10549. if (fctl & FC_FC_EX_CTX) {
  10550. /*
  10551. * ABTS sent by responder to exchange, just free the buffer
  10552. */
  10553. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10554. } else {
  10555. /*
  10556. * ABTS sent by initiator to exchange, need to do cleanup
  10557. */
  10558. /* Try to abort partially assembled seq */
  10559. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  10560. /* Send abort to ULP if partially seq abort failed */
  10561. if (abts_par == false)
  10562. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  10563. else
  10564. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10565. }
  10566. /* Send basic accept (BA_ACC) to the abort requester */
  10567. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  10568. }
  10569. /**
  10570. * lpfc_seq_complete - Indicates if a sequence is complete
  10571. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10572. *
  10573. * This function checks the sequence, starting with the frame described by
  10574. * @dmabuf, to see if all the frames associated with this sequence are present.
  10575. * the frames associated with this sequence are linked to the @dmabuf using the
  10576. * dbuf list. This function looks for two major things. 1) That the first frame
  10577. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  10578. * set. 3) That there are no holes in the sequence count. The function will
  10579. * return 1 when the sequence is complete, otherwise it will return 0.
  10580. **/
  10581. static int
  10582. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  10583. {
  10584. struct fc_frame_header *hdr;
  10585. struct lpfc_dmabuf *d_buf;
  10586. struct hbq_dmabuf *seq_dmabuf;
  10587. uint32_t fctl;
  10588. int seq_count = 0;
  10589. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10590. /* make sure first fame of sequence has a sequence count of zero */
  10591. if (hdr->fh_seq_cnt != seq_count)
  10592. return 0;
  10593. fctl = (hdr->fh_f_ctl[0] << 16 |
  10594. hdr->fh_f_ctl[1] << 8 |
  10595. hdr->fh_f_ctl[2]);
  10596. /* If last frame of sequence we can return success. */
  10597. if (fctl & FC_FC_END_SEQ)
  10598. return 1;
  10599. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  10600. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10601. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10602. /* If there is a hole in the sequence count then fail. */
  10603. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  10604. return 0;
  10605. fctl = (hdr->fh_f_ctl[0] << 16 |
  10606. hdr->fh_f_ctl[1] << 8 |
  10607. hdr->fh_f_ctl[2]);
  10608. /* If last frame of sequence we can return success. */
  10609. if (fctl & FC_FC_END_SEQ)
  10610. return 1;
  10611. }
  10612. return 0;
  10613. }
  10614. /**
  10615. * lpfc_prep_seq - Prep sequence for ULP processing
  10616. * @vport: Pointer to the vport on which this sequence was received
  10617. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10618. *
  10619. * This function takes a sequence, described by a list of frames, and creates
  10620. * a list of iocbq structures to describe the sequence. This iocbq list will be
  10621. * used to issue to the generic unsolicited sequence handler. This routine
  10622. * returns a pointer to the first iocbq in the list. If the function is unable
  10623. * to allocate an iocbq then it throw out the received frames that were not
  10624. * able to be described and return a pointer to the first iocbq. If unable to
  10625. * allocate any iocbqs (including the first) this function will return NULL.
  10626. **/
  10627. static struct lpfc_iocbq *
  10628. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  10629. {
  10630. struct lpfc_dmabuf *d_buf, *n_buf;
  10631. struct lpfc_iocbq *first_iocbq, *iocbq;
  10632. struct fc_frame_header *fc_hdr;
  10633. uint32_t sid;
  10634. struct ulp_bde64 *pbde;
  10635. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10636. /* remove from receive buffer list */
  10637. list_del_init(&seq_dmabuf->hbuf.list);
  10638. lpfc_update_rcv_time_stamp(vport);
  10639. /* get the Remote Port's SID */
  10640. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10641. /* Get an iocbq struct to fill in. */
  10642. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  10643. if (first_iocbq) {
  10644. /* Initialize the first IOCB. */
  10645. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  10646. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  10647. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  10648. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  10649. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  10650. vport->vpi + vport->phba->vpi_base;
  10651. /* put the first buffer into the first IOCBq */
  10652. first_iocbq->context2 = &seq_dmabuf->dbuf;
  10653. first_iocbq->context3 = NULL;
  10654. first_iocbq->iocb.ulpBdeCount = 1;
  10655. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10656. LPFC_DATA_BUF_SIZE;
  10657. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10658. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10659. bf_get(lpfc_rcqe_length,
  10660. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10661. }
  10662. iocbq = first_iocbq;
  10663. /*
  10664. * Each IOCBq can have two Buffers assigned, so go through the list
  10665. * of buffers for this sequence and save two buffers in each IOCBq
  10666. */
  10667. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10668. if (!iocbq) {
  10669. lpfc_in_buf_free(vport->phba, d_buf);
  10670. continue;
  10671. }
  10672. if (!iocbq->context3) {
  10673. iocbq->context3 = d_buf;
  10674. iocbq->iocb.ulpBdeCount++;
  10675. pbde = (struct ulp_bde64 *)
  10676. &iocbq->iocb.unsli3.sli3Words[4];
  10677. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  10678. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10679. bf_get(lpfc_rcqe_length,
  10680. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10681. } else {
  10682. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10683. if (!iocbq) {
  10684. if (first_iocbq) {
  10685. first_iocbq->iocb.ulpStatus =
  10686. IOSTAT_FCP_RSP_ERROR;
  10687. first_iocbq->iocb.un.ulpWord[4] =
  10688. IOERR_NO_RESOURCES;
  10689. }
  10690. lpfc_in_buf_free(vport->phba, d_buf);
  10691. continue;
  10692. }
  10693. iocbq->context2 = d_buf;
  10694. iocbq->context3 = NULL;
  10695. iocbq->iocb.ulpBdeCount = 1;
  10696. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10697. LPFC_DATA_BUF_SIZE;
  10698. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10699. bf_get(lpfc_rcqe_length,
  10700. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10701. iocbq->iocb.un.rcvels.remoteID = sid;
  10702. list_add_tail(&iocbq->list, &first_iocbq->list);
  10703. }
  10704. }
  10705. return first_iocbq;
  10706. }
  10707. static void
  10708. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  10709. struct hbq_dmabuf *seq_dmabuf)
  10710. {
  10711. struct fc_frame_header *fc_hdr;
  10712. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  10713. struct lpfc_hba *phba = vport->phba;
  10714. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10715. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10716. if (!iocbq) {
  10717. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10718. "2707 Ring %d handler: Failed to allocate "
  10719. "iocb Rctl x%x Type x%x received\n",
  10720. LPFC_ELS_RING,
  10721. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10722. return;
  10723. }
  10724. if (!lpfc_complete_unsol_iocb(phba,
  10725. &phba->sli.ring[LPFC_ELS_RING],
  10726. iocbq, fc_hdr->fh_r_ctl,
  10727. fc_hdr->fh_type))
  10728. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10729. "2540 Ring %d handler: unexpected Rctl "
  10730. "x%x Type x%x received\n",
  10731. LPFC_ELS_RING,
  10732. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10733. /* Free iocb created in lpfc_prep_seq */
  10734. list_for_each_entry_safe(curr_iocb, next_iocb,
  10735. &iocbq->list, list) {
  10736. list_del_init(&curr_iocb->list);
  10737. lpfc_sli_release_iocbq(phba, curr_iocb);
  10738. }
  10739. lpfc_sli_release_iocbq(phba, iocbq);
  10740. }
  10741. /**
  10742. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10743. * @phba: Pointer to HBA context object.
  10744. *
  10745. * This function is called with no lock held. This function processes all
  10746. * the received buffers and gives it to upper layers when a received buffer
  10747. * indicates that it is the final frame in the sequence. The interrupt
  10748. * service routine processes received buffers at interrupt contexts and adds
  10749. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10750. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10751. * appropriate receive function when the final frame in a sequence is received.
  10752. **/
  10753. void
  10754. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10755. struct hbq_dmabuf *dmabuf)
  10756. {
  10757. struct hbq_dmabuf *seq_dmabuf;
  10758. struct fc_frame_header *fc_hdr;
  10759. struct lpfc_vport *vport;
  10760. uint32_t fcfi;
  10761. /* Process each received buffer */
  10762. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10763. /* check to see if this a valid type of frame */
  10764. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10765. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10766. return;
  10767. }
  10768. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10769. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10770. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  10771. /* throw out the frame */
  10772. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10773. return;
  10774. }
  10775. /* Handle the basic abort sequence (BA_ABTS) event */
  10776. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  10777. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  10778. return;
  10779. }
  10780. /* Link this frame */
  10781. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10782. if (!seq_dmabuf) {
  10783. /* unable to add frame to vport - throw it out */
  10784. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10785. return;
  10786. }
  10787. /* If not last frame in sequence continue processing frames. */
  10788. if (!lpfc_seq_complete(seq_dmabuf))
  10789. return;
  10790. /* Send the complete sequence to the upper layer protocol */
  10791. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  10792. }
  10793. /**
  10794. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10795. * @phba: pointer to lpfc hba data structure.
  10796. *
  10797. * This routine is invoked to post rpi header templates to the
  10798. * HBA consistent with the SLI-4 interface spec. This routine
  10799. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  10800. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  10801. *
  10802. * This routine does not require any locks. It's usage is expected
  10803. * to be driver load or reset recovery when the driver is
  10804. * sequential.
  10805. *
  10806. * Return codes
  10807. * 0 - successful
  10808. * EIO - The mailbox failed to complete successfully.
  10809. * When this error occurs, the driver is not guaranteed
  10810. * to have any rpi regions posted to the device and
  10811. * must either attempt to repost the regions or take a
  10812. * fatal error.
  10813. **/
  10814. int
  10815. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10816. {
  10817. struct lpfc_rpi_hdr *rpi_page;
  10818. uint32_t rc = 0;
  10819. /* Post all rpi memory regions to the port. */
  10820. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10821. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10822. if (rc != MBX_SUCCESS) {
  10823. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10824. "2008 Error %d posting all rpi "
  10825. "headers\n", rc);
  10826. rc = -EIO;
  10827. break;
  10828. }
  10829. }
  10830. return rc;
  10831. }
  10832. /**
  10833. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10834. * @phba: pointer to lpfc hba data structure.
  10835. * @rpi_page: pointer to the rpi memory region.
  10836. *
  10837. * This routine is invoked to post a single rpi header to the
  10838. * HBA consistent with the SLI-4 interface spec. This memory region
  10839. * maps up to 64 rpi context regions.
  10840. *
  10841. * Return codes
  10842. * 0 - successful
  10843. * ENOMEM - No available memory
  10844. * EIO - The mailbox failed to complete successfully.
  10845. **/
  10846. int
  10847. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10848. {
  10849. LPFC_MBOXQ_t *mboxq;
  10850. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10851. uint32_t rc = 0;
  10852. uint32_t mbox_tmo;
  10853. uint32_t shdr_status, shdr_add_status;
  10854. union lpfc_sli4_cfg_shdr *shdr;
  10855. /* The port is notified of the header region via a mailbox command. */
  10856. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10857. if (!mboxq) {
  10858. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10859. "2001 Unable to allocate memory for issuing "
  10860. "SLI_CONFIG_SPECIAL mailbox command\n");
  10861. return -ENOMEM;
  10862. }
  10863. /* Post all rpi memory regions to the port. */
  10864. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10865. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10866. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10867. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10868. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10869. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10870. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10871. hdr_tmpl, rpi_page->page_count);
  10872. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10873. rpi_page->start_rpi);
  10874. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10875. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10876. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10877. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10878. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10879. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10880. if (rc != MBX_TIMEOUT)
  10881. mempool_free(mboxq, phba->mbox_mem_pool);
  10882. if (shdr_status || shdr_add_status || rc) {
  10883. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10884. "2514 POST_RPI_HDR mailbox failed with "
  10885. "status x%x add_status x%x, mbx status x%x\n",
  10886. shdr_status, shdr_add_status, rc);
  10887. rc = -ENXIO;
  10888. }
  10889. return rc;
  10890. }
  10891. /**
  10892. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10893. * @phba: pointer to lpfc hba data structure.
  10894. *
  10895. * This routine is invoked to post rpi header templates to the
  10896. * HBA consistent with the SLI-4 interface spec. This routine
  10897. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  10898. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  10899. *
  10900. * Returns
  10901. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  10902. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10903. **/
  10904. int
  10905. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10906. {
  10907. int rpi;
  10908. uint16_t max_rpi, rpi_base, rpi_limit;
  10909. uint16_t rpi_remaining;
  10910. struct lpfc_rpi_hdr *rpi_hdr;
  10911. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10912. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10913. rpi_limit = phba->sli4_hba.next_rpi;
  10914. /*
  10915. * The valid rpi range is not guaranteed to be zero-based. Start
  10916. * the search at the rpi_base as reported by the port.
  10917. */
  10918. spin_lock_irq(&phba->hbalock);
  10919. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10920. if (rpi >= rpi_limit || rpi < rpi_base)
  10921. rpi = LPFC_RPI_ALLOC_ERROR;
  10922. else {
  10923. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10924. phba->sli4_hba.max_cfg_param.rpi_used++;
  10925. phba->sli4_hba.rpi_count++;
  10926. }
  10927. /*
  10928. * Don't try to allocate more rpi header regions if the device limit
  10929. * on available rpis max has been exhausted.
  10930. */
  10931. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10932. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10933. spin_unlock_irq(&phba->hbalock);
  10934. return rpi;
  10935. }
  10936. /*
  10937. * If the driver is running low on rpi resources, allocate another
  10938. * page now. Note that the next_rpi value is used because
  10939. * it represents how many are actually in use whereas max_rpi notes
  10940. * how many are supported max by the device.
  10941. */
  10942. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10943. phba->sli4_hba.rpi_count;
  10944. spin_unlock_irq(&phba->hbalock);
  10945. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10946. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10947. if (!rpi_hdr) {
  10948. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10949. "2002 Error Could not grow rpi "
  10950. "count\n");
  10951. } else {
  10952. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10953. }
  10954. }
  10955. return rpi;
  10956. }
  10957. /**
  10958. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10959. * @phba: pointer to lpfc hba data structure.
  10960. *
  10961. * This routine is invoked to release an rpi to the pool of
  10962. * available rpis maintained by the driver.
  10963. **/
  10964. void
  10965. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10966. {
  10967. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  10968. phba->sli4_hba.rpi_count--;
  10969. phba->sli4_hba.max_cfg_param.rpi_used--;
  10970. }
  10971. }
  10972. /**
  10973. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10974. * @phba: pointer to lpfc hba data structure.
  10975. *
  10976. * This routine is invoked to release an rpi to the pool of
  10977. * available rpis maintained by the driver.
  10978. **/
  10979. void
  10980. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10981. {
  10982. spin_lock_irq(&phba->hbalock);
  10983. __lpfc_sli4_free_rpi(phba, rpi);
  10984. spin_unlock_irq(&phba->hbalock);
  10985. }
  10986. /**
  10987. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10988. * @phba: pointer to lpfc hba data structure.
  10989. *
  10990. * This routine is invoked to remove the memory region that
  10991. * provided rpi via a bitmask.
  10992. **/
  10993. void
  10994. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10995. {
  10996. kfree(phba->sli4_hba.rpi_bmask);
  10997. }
  10998. /**
  10999. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  11000. * @phba: pointer to lpfc hba data structure.
  11001. *
  11002. * This routine is invoked to remove the memory region that
  11003. * provided rpi via a bitmask.
  11004. **/
  11005. int
  11006. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  11007. {
  11008. LPFC_MBOXQ_t *mboxq;
  11009. struct lpfc_hba *phba = ndlp->phba;
  11010. int rc;
  11011. /* The port is notified of the header region via a mailbox command. */
  11012. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11013. if (!mboxq)
  11014. return -ENOMEM;
  11015. /* Post all rpi memory regions to the port. */
  11016. lpfc_resume_rpi(mboxq, ndlp);
  11017. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11018. if (rc == MBX_NOT_FINISHED) {
  11019. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11020. "2010 Resume RPI Mailbox failed "
  11021. "status %d, mbxStatus x%x\n", rc,
  11022. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11023. mempool_free(mboxq, phba->mbox_mem_pool);
  11024. return -EIO;
  11025. }
  11026. return 0;
  11027. }
  11028. /**
  11029. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  11030. * @phba: pointer to lpfc hba data structure.
  11031. * @vpi: vpi value to activate with the port.
  11032. *
  11033. * This routine is invoked to activate a vpi with the
  11034. * port when the host intends to use vports with a
  11035. * nonzero vpi.
  11036. *
  11037. * Returns:
  11038. * 0 success
  11039. * -Evalue otherwise
  11040. **/
  11041. int
  11042. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  11043. {
  11044. LPFC_MBOXQ_t *mboxq;
  11045. int rc = 0;
  11046. int retval = MBX_SUCCESS;
  11047. uint32_t mbox_tmo;
  11048. if (vpi == 0)
  11049. return -EINVAL;
  11050. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11051. if (!mboxq)
  11052. return -ENOMEM;
  11053. lpfc_init_vpi(phba, mboxq, vpi);
  11054. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  11055. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  11056. if (rc != MBX_SUCCESS) {
  11057. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11058. "2022 INIT VPI Mailbox failed "
  11059. "status %d, mbxStatus x%x\n", rc,
  11060. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11061. retval = -EIO;
  11062. }
  11063. if (rc != MBX_TIMEOUT)
  11064. mempool_free(mboxq, phba->mbox_mem_pool);
  11065. return retval;
  11066. }
  11067. /**
  11068. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  11069. * @phba: pointer to lpfc hba data structure.
  11070. * @mboxq: Pointer to mailbox object.
  11071. *
  11072. * This routine is invoked to manually add a single FCF record. The caller
  11073. * must pass a completely initialized FCF_Record. This routine takes
  11074. * care of the nonembedded mailbox operations.
  11075. **/
  11076. static void
  11077. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  11078. {
  11079. void *virt_addr;
  11080. union lpfc_sli4_cfg_shdr *shdr;
  11081. uint32_t shdr_status, shdr_add_status;
  11082. virt_addr = mboxq->sge_array->addr[0];
  11083. /* The IOCTL status is embedded in the mailbox subheader. */
  11084. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  11085. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11086. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11087. if ((shdr_status || shdr_add_status) &&
  11088. (shdr_status != STATUS_FCF_IN_USE))
  11089. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11090. "2558 ADD_FCF_RECORD mailbox failed with "
  11091. "status x%x add_status x%x\n",
  11092. shdr_status, shdr_add_status);
  11093. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11094. }
  11095. /**
  11096. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  11097. * @phba: pointer to lpfc hba data structure.
  11098. * @fcf_record: pointer to the initialized fcf record to add.
  11099. *
  11100. * This routine is invoked to manually add a single FCF record. The caller
  11101. * must pass a completely initialized FCF_Record. This routine takes
  11102. * care of the nonembedded mailbox operations.
  11103. **/
  11104. int
  11105. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  11106. {
  11107. int rc = 0;
  11108. LPFC_MBOXQ_t *mboxq;
  11109. uint8_t *bytep;
  11110. void *virt_addr;
  11111. dma_addr_t phys_addr;
  11112. struct lpfc_mbx_sge sge;
  11113. uint32_t alloc_len, req_len;
  11114. uint32_t fcfindex;
  11115. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11116. if (!mboxq) {
  11117. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11118. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  11119. return -ENOMEM;
  11120. }
  11121. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  11122. sizeof(uint32_t);
  11123. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11124. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11125. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  11126. req_len, LPFC_SLI4_MBX_NEMBED);
  11127. if (alloc_len < req_len) {
  11128. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11129. "2523 Allocated DMA memory size (x%x) is "
  11130. "less than the requested DMA memory "
  11131. "size (x%x)\n", alloc_len, req_len);
  11132. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11133. return -ENOMEM;
  11134. }
  11135. /*
  11136. * Get the first SGE entry from the non-embedded DMA memory. This
  11137. * routine only uses a single SGE.
  11138. */
  11139. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  11140. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  11141. virt_addr = mboxq->sge_array->addr[0];
  11142. /*
  11143. * Configure the FCF record for FCFI 0. This is the driver's
  11144. * hardcoded default and gets used in nonFIP mode.
  11145. */
  11146. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  11147. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  11148. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  11149. /*
  11150. * Copy the fcf_index and the FCF Record Data. The data starts after
  11151. * the FCoE header plus word10. The data copy needs to be endian
  11152. * correct.
  11153. */
  11154. bytep += sizeof(uint32_t);
  11155. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  11156. mboxq->vport = phba->pport;
  11157. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  11158. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11159. if (rc == MBX_NOT_FINISHED) {
  11160. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11161. "2515 ADD_FCF_RECORD mailbox failed with "
  11162. "status 0x%x\n", rc);
  11163. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11164. rc = -EIO;
  11165. } else
  11166. rc = 0;
  11167. return rc;
  11168. }
  11169. /**
  11170. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  11171. * @phba: pointer to lpfc hba data structure.
  11172. * @fcf_record: pointer to the fcf record to write the default data.
  11173. * @fcf_index: FCF table entry index.
  11174. *
  11175. * This routine is invoked to build the driver's default FCF record. The
  11176. * values used are hardcoded. This routine handles memory initialization.
  11177. *
  11178. **/
  11179. void
  11180. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  11181. struct fcf_record *fcf_record,
  11182. uint16_t fcf_index)
  11183. {
  11184. memset(fcf_record, 0, sizeof(struct fcf_record));
  11185. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  11186. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  11187. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  11188. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  11189. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  11190. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  11191. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  11192. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  11193. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  11194. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  11195. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  11196. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  11197. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  11198. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  11199. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  11200. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  11201. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  11202. /* Set the VLAN bit map */
  11203. if (phba->valid_vlan) {
  11204. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  11205. = 1 << (phba->vlan_id % 8);
  11206. }
  11207. }
  11208. /**
  11209. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  11210. * @phba: pointer to lpfc hba data structure.
  11211. * @fcf_index: FCF table entry offset.
  11212. *
  11213. * This routine is invoked to scan the entire FCF table by reading FCF
  11214. * record and processing it one at a time starting from the @fcf_index
  11215. * for initial FCF discovery or fast FCF failover rediscovery.
  11216. *
  11217. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11218. * otherwise.
  11219. **/
  11220. int
  11221. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11222. {
  11223. int rc = 0, error;
  11224. LPFC_MBOXQ_t *mboxq;
  11225. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  11226. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11227. if (!mboxq) {
  11228. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11229. "2000 Failed to allocate mbox for "
  11230. "READ_FCF cmd\n");
  11231. error = -ENOMEM;
  11232. goto fail_fcf_scan;
  11233. }
  11234. /* Construct the read FCF record mailbox command */
  11235. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11236. if (rc) {
  11237. error = -EINVAL;
  11238. goto fail_fcf_scan;
  11239. }
  11240. /* Issue the mailbox command asynchronously */
  11241. mboxq->vport = phba->pport;
  11242. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11243. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11244. if (rc == MBX_NOT_FINISHED)
  11245. error = -EIO;
  11246. else {
  11247. spin_lock_irq(&phba->hbalock);
  11248. phba->hba_flag |= FCF_DISC_INPROGRESS;
  11249. spin_unlock_irq(&phba->hbalock);
  11250. /* Reset eligible FCF count for new scan */
  11251. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  11252. phba->fcf.eligible_fcf_cnt = 0;
  11253. error = 0;
  11254. }
  11255. fail_fcf_scan:
  11256. if (error) {
  11257. if (mboxq)
  11258. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11259. /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
  11260. spin_lock_irq(&phba->hbalock);
  11261. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  11262. spin_unlock_irq(&phba->hbalock);
  11263. }
  11264. return error;
  11265. }
  11266. /**
  11267. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for round robin fcf.
  11268. * @phba: pointer to lpfc hba data structure.
  11269. * @fcf_index: FCF table entry offset.
  11270. *
  11271. * This routine is invoked to read an FCF record indicated by @fcf_index
  11272. * and to use it for FLOGI round robin FCF failover.
  11273. *
  11274. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11275. * otherwise.
  11276. **/
  11277. int
  11278. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11279. {
  11280. int rc = 0, error;
  11281. LPFC_MBOXQ_t *mboxq;
  11282. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11283. if (!mboxq) {
  11284. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11285. "2763 Failed to allocate mbox for "
  11286. "READ_FCF cmd\n");
  11287. error = -ENOMEM;
  11288. goto fail_fcf_read;
  11289. }
  11290. /* Construct the read FCF record mailbox command */
  11291. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11292. if (rc) {
  11293. error = -EINVAL;
  11294. goto fail_fcf_read;
  11295. }
  11296. /* Issue the mailbox command asynchronously */
  11297. mboxq->vport = phba->pport;
  11298. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11299. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11300. if (rc == MBX_NOT_FINISHED)
  11301. error = -EIO;
  11302. else
  11303. error = 0;
  11304. fail_fcf_read:
  11305. if (error && mboxq)
  11306. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11307. return error;
  11308. }
  11309. /**
  11310. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11311. * @phba: pointer to lpfc hba data structure.
  11312. * @fcf_index: FCF table entry offset.
  11313. *
  11314. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11315. * determine whether it's eligible for FLOGI round robin failover list.
  11316. *
  11317. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11318. * otherwise.
  11319. **/
  11320. int
  11321. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11322. {
  11323. int rc = 0, error;
  11324. LPFC_MBOXQ_t *mboxq;
  11325. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11326. if (!mboxq) {
  11327. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11328. "2758 Failed to allocate mbox for "
  11329. "READ_FCF cmd\n");
  11330. error = -ENOMEM;
  11331. goto fail_fcf_read;
  11332. }
  11333. /* Construct the read FCF record mailbox command */
  11334. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11335. if (rc) {
  11336. error = -EINVAL;
  11337. goto fail_fcf_read;
  11338. }
  11339. /* Issue the mailbox command asynchronously */
  11340. mboxq->vport = phba->pport;
  11341. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  11342. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11343. if (rc == MBX_NOT_FINISHED)
  11344. error = -EIO;
  11345. else
  11346. error = 0;
  11347. fail_fcf_read:
  11348. if (error && mboxq)
  11349. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11350. return error;
  11351. }
  11352. /**
  11353. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  11354. * @phba: pointer to lpfc hba data structure.
  11355. *
  11356. * This routine is to get the next eligible FCF record index in a round
  11357. * robin fashion. If the next eligible FCF record index equals to the
  11358. * initial round robin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  11359. * shall be returned, otherwise, the next eligible FCF record's index
  11360. * shall be returned.
  11361. **/
  11362. uint16_t
  11363. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  11364. {
  11365. uint16_t next_fcf_index;
  11366. /* Search start from next bit of currently registered FCF index */
  11367. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  11368. LPFC_SLI4_FCF_TBL_INDX_MAX;
  11369. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11370. LPFC_SLI4_FCF_TBL_INDX_MAX,
  11371. next_fcf_index);
  11372. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  11373. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  11374. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11375. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  11376. /* Check roundrobin failover list empty condition */
  11377. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11378. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  11379. "2844 No roundrobin failover FCF available\n");
  11380. return LPFC_FCOE_FCF_NEXT_NONE;
  11381. }
  11382. /* Check roundrobin failover index bmask stop condition */
  11383. if (next_fcf_index == phba->fcf.fcf_rr_init_indx) {
  11384. if (!(phba->fcf.fcf_flag & FCF_REDISC_RRU)) {
  11385. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  11386. "2847 Round robin failover FCF index "
  11387. "search hit stop condition:x%x\n",
  11388. next_fcf_index);
  11389. return LPFC_FCOE_FCF_NEXT_NONE;
  11390. }
  11391. /* The roundrobin failover index bmask updated, start over */
  11392. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11393. "2848 Round robin failover FCF index bmask "
  11394. "updated, start over\n");
  11395. spin_lock_irq(&phba->hbalock);
  11396. phba->fcf.fcf_flag &= ~FCF_REDISC_RRU;
  11397. spin_unlock_irq(&phba->hbalock);
  11398. return phba->fcf.fcf_rr_init_indx;
  11399. }
  11400. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11401. "2845 Get next round robin failover "
  11402. "FCF index x%x\n", next_fcf_index);
  11403. return next_fcf_index;
  11404. }
  11405. /**
  11406. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  11407. * @phba: pointer to lpfc hba data structure.
  11408. *
  11409. * This routine sets the FCF record index in to the eligible bmask for
  11410. * round robin failover search. It checks to make sure that the index
  11411. * does not go beyond the range of the driver allocated bmask dimension
  11412. * before setting the bit.
  11413. *
  11414. * Returns 0 if the index bit successfully set, otherwise, it returns
  11415. * -EINVAL.
  11416. **/
  11417. int
  11418. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  11419. {
  11420. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11421. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11422. "2610 HBA FCF index reached driver's "
  11423. "book keeping dimension: fcf_index:%d, "
  11424. "driver_bmask_max:%d\n",
  11425. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11426. return -EINVAL;
  11427. }
  11428. /* Set the eligible FCF record index bmask */
  11429. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11430. /* Set the roundrobin index bmask updated */
  11431. spin_lock_irq(&phba->hbalock);
  11432. phba->fcf.fcf_flag |= FCF_REDISC_RRU;
  11433. spin_unlock_irq(&phba->hbalock);
  11434. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11435. "2790 Set FCF index x%x to round robin failover "
  11436. "bmask\n", fcf_index);
  11437. return 0;
  11438. }
  11439. /**
  11440. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  11441. * @phba: pointer to lpfc hba data structure.
  11442. *
  11443. * This routine clears the FCF record index from the eligible bmask for
  11444. * round robin failover search. It checks to make sure that the index
  11445. * does not go beyond the range of the driver allocated bmask dimension
  11446. * before clearing the bit.
  11447. **/
  11448. void
  11449. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  11450. {
  11451. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11452. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11453. "2762 HBA FCF index goes beyond driver's "
  11454. "book keeping dimension: fcf_index:%d, "
  11455. "driver_bmask_max:%d\n",
  11456. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11457. return;
  11458. }
  11459. /* Clear the eligible FCF record index bmask */
  11460. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11461. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11462. "2791 Clear FCF index x%x from round robin failover "
  11463. "bmask\n", fcf_index);
  11464. }
  11465. /**
  11466. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  11467. * @phba: pointer to lpfc hba data structure.
  11468. *
  11469. * This routine is the completion routine for the rediscover FCF table mailbox
  11470. * command. If the mailbox command returned failure, it will try to stop the
  11471. * FCF rediscover wait timer.
  11472. **/
  11473. void
  11474. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  11475. {
  11476. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11477. uint32_t shdr_status, shdr_add_status;
  11478. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11479. shdr_status = bf_get(lpfc_mbox_hdr_status,
  11480. &redisc_fcf->header.cfg_shdr.response);
  11481. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  11482. &redisc_fcf->header.cfg_shdr.response);
  11483. if (shdr_status || shdr_add_status) {
  11484. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11485. "2746 Requesting for FCF rediscovery failed "
  11486. "status x%x add_status x%x\n",
  11487. shdr_status, shdr_add_status);
  11488. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  11489. spin_lock_irq(&phba->hbalock);
  11490. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  11491. spin_unlock_irq(&phba->hbalock);
  11492. /*
  11493. * CVL event triggered FCF rediscover request failed,
  11494. * last resort to re-try current registered FCF entry.
  11495. */
  11496. lpfc_retry_pport_discovery(phba);
  11497. } else {
  11498. spin_lock_irq(&phba->hbalock);
  11499. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  11500. spin_unlock_irq(&phba->hbalock);
  11501. /*
  11502. * DEAD FCF event triggered FCF rediscover request
  11503. * failed, last resort to fail over as a link down
  11504. * to FCF registration.
  11505. */
  11506. lpfc_sli4_fcf_dead_failthrough(phba);
  11507. }
  11508. } else {
  11509. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11510. "2775 Start FCF rediscovery quiescent period "
  11511. "wait timer before scaning FCF table\n");
  11512. /*
  11513. * Start FCF rediscovery wait timer for pending FCF
  11514. * before rescan FCF record table.
  11515. */
  11516. lpfc_fcf_redisc_wait_start_timer(phba);
  11517. }
  11518. mempool_free(mbox, phba->mbox_mem_pool);
  11519. }
  11520. /**
  11521. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  11522. * @phba: pointer to lpfc hba data structure.
  11523. *
  11524. * This routine is invoked to request for rediscovery of the entire FCF table
  11525. * by the port.
  11526. **/
  11527. int
  11528. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11529. {
  11530. LPFC_MBOXQ_t *mbox;
  11531. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11532. int rc, length;
  11533. /* Cancel retry delay timers to all vports before FCF rediscover */
  11534. lpfc_cancel_all_vport_retry_delay_timer(phba);
  11535. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11536. if (!mbox) {
  11537. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11538. "2745 Failed to allocate mbox for "
  11539. "requesting FCF rediscover.\n");
  11540. return -ENOMEM;
  11541. }
  11542. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  11543. sizeof(struct lpfc_sli4_cfg_mhdr));
  11544. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11545. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  11546. length, LPFC_SLI4_MBX_EMBED);
  11547. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11548. /* Set count to 0 for invalidating the entire FCF database */
  11549. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  11550. /* Issue the mailbox command asynchronously */
  11551. mbox->vport = phba->pport;
  11552. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  11553. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  11554. if (rc == MBX_NOT_FINISHED) {
  11555. mempool_free(mbox, phba->mbox_mem_pool);
  11556. return -EIO;
  11557. }
  11558. return 0;
  11559. }
  11560. /**
  11561. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  11562. * @phba: pointer to lpfc hba data structure.
  11563. *
  11564. * This function is the failover routine as a last resort to the FCF DEAD
  11565. * event when driver failed to perform fast FCF failover.
  11566. **/
  11567. void
  11568. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  11569. {
  11570. uint32_t link_state;
  11571. /*
  11572. * Last resort as FCF DEAD event failover will treat this as
  11573. * a link down, but save the link state because we don't want
  11574. * it to be changed to Link Down unless it is already down.
  11575. */
  11576. link_state = phba->link_state;
  11577. lpfc_linkdown(phba);
  11578. phba->link_state = link_state;
  11579. /* Unregister FCF if no devices connected to it */
  11580. lpfc_unregister_unused_fcf(phba);
  11581. }
  11582. /**
  11583. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  11584. * @phba: pointer to lpfc hba data structure.
  11585. *
  11586. * This function read region 23 and parse TLV for port status to
  11587. * decide if the user disaled the port. If the TLV indicates the
  11588. * port is disabled, the hba_flag is set accordingly.
  11589. **/
  11590. void
  11591. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  11592. {
  11593. LPFC_MBOXQ_t *pmb = NULL;
  11594. MAILBOX_t *mb;
  11595. uint8_t *rgn23_data = NULL;
  11596. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  11597. int rc;
  11598. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11599. if (!pmb) {
  11600. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11601. "2600 lpfc_sli_read_serdes_param failed to"
  11602. " allocate mailbox memory\n");
  11603. goto out;
  11604. }
  11605. mb = &pmb->u.mb;
  11606. /* Get adapter Region 23 data */
  11607. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  11608. if (!rgn23_data)
  11609. goto out;
  11610. do {
  11611. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  11612. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  11613. if (rc != MBX_SUCCESS) {
  11614. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11615. "2601 lpfc_sli_read_link_ste failed to"
  11616. " read config region 23 rc 0x%x Status 0x%x\n",
  11617. rc, mb->mbxStatus);
  11618. mb->un.varDmp.word_cnt = 0;
  11619. }
  11620. /*
  11621. * dump mem may return a zero when finished or we got a
  11622. * mailbox error, either way we are done.
  11623. */
  11624. if (mb->un.varDmp.word_cnt == 0)
  11625. break;
  11626. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  11627. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  11628. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  11629. rgn23_data + offset,
  11630. mb->un.varDmp.word_cnt);
  11631. offset += mb->un.varDmp.word_cnt;
  11632. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  11633. data_size = offset;
  11634. offset = 0;
  11635. if (!data_size)
  11636. goto out;
  11637. /* Check the region signature first */
  11638. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  11639. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11640. "2619 Config region 23 has bad signature\n");
  11641. goto out;
  11642. }
  11643. offset += 4;
  11644. /* Check the data structure version */
  11645. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  11646. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11647. "2620 Config region 23 has bad version\n");
  11648. goto out;
  11649. }
  11650. offset += 4;
  11651. /* Parse TLV entries in the region */
  11652. while (offset < data_size) {
  11653. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  11654. break;
  11655. /*
  11656. * If the TLV is not driver specific TLV or driver id is
  11657. * not linux driver id, skip the record.
  11658. */
  11659. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  11660. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  11661. (rgn23_data[offset + 3] != 0)) {
  11662. offset += rgn23_data[offset + 1] * 4 + 4;
  11663. continue;
  11664. }
  11665. /* Driver found a driver specific TLV in the config region */
  11666. sub_tlv_len = rgn23_data[offset + 1] * 4;
  11667. offset += 4;
  11668. tlv_offset = 0;
  11669. /*
  11670. * Search for configured port state sub-TLV.
  11671. */
  11672. while ((offset < data_size) &&
  11673. (tlv_offset < sub_tlv_len)) {
  11674. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  11675. offset += 4;
  11676. tlv_offset += 4;
  11677. break;
  11678. }
  11679. if (rgn23_data[offset] != PORT_STE_TYPE) {
  11680. offset += rgn23_data[offset + 1] * 4 + 4;
  11681. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  11682. continue;
  11683. }
  11684. /* This HBA contains PORT_STE configured */
  11685. if (!rgn23_data[offset + 2])
  11686. phba->hba_flag |= LINK_DISABLED;
  11687. goto out;
  11688. }
  11689. }
  11690. out:
  11691. if (pmb)
  11692. mempool_free(pmb, phba->mbox_mem_pool);
  11693. kfree(rgn23_data);
  11694. return;
  11695. }
  11696. /**
  11697. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  11698. * @vport: pointer to vport data structure.
  11699. *
  11700. * This function iterate through the mailboxq and clean up all REG_LOGIN
  11701. * and REG_VPI mailbox commands associated with the vport. This function
  11702. * is called when driver want to restart discovery of the vport due to
  11703. * a Clear Virtual Link event.
  11704. **/
  11705. void
  11706. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  11707. {
  11708. struct lpfc_hba *phba = vport->phba;
  11709. LPFC_MBOXQ_t *mb, *nextmb;
  11710. struct lpfc_dmabuf *mp;
  11711. struct lpfc_nodelist *ndlp;
  11712. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  11713. spin_lock_irq(&phba->hbalock);
  11714. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  11715. if (mb->vport != vport)
  11716. continue;
  11717. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  11718. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  11719. continue;
  11720. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11721. if (phba->sli_rev == LPFC_SLI_REV4)
  11722. __lpfc_sli4_free_rpi(phba,
  11723. mb->u.mb.un.varRegLogin.rpi);
  11724. mp = (struct lpfc_dmabuf *) (mb->context1);
  11725. if (mp) {
  11726. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  11727. kfree(mp);
  11728. }
  11729. ndlp = (struct lpfc_nodelist *) mb->context2;
  11730. if (ndlp) {
  11731. spin_lock_irq(shost->host_lock);
  11732. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  11733. spin_unlock_irq(shost->host_lock);
  11734. lpfc_nlp_put(ndlp);
  11735. mb->context2 = NULL;
  11736. }
  11737. }
  11738. list_del(&mb->list);
  11739. mempool_free(mb, phba->mbox_mem_pool);
  11740. }
  11741. mb = phba->sli.mbox_active;
  11742. if (mb && (mb->vport == vport)) {
  11743. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  11744. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  11745. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11746. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11747. ndlp = (struct lpfc_nodelist *) mb->context2;
  11748. if (ndlp) {
  11749. spin_lock_irq(shost->host_lock);
  11750. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  11751. spin_unlock_irq(shost->host_lock);
  11752. lpfc_nlp_put(ndlp);
  11753. mb->context2 = NULL;
  11754. }
  11755. /* Unregister the RPI when mailbox complete */
  11756. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  11757. }
  11758. }
  11759. spin_unlock_irq(&phba->hbalock);
  11760. }
  11761. /**
  11762. * lpfc_drain_txq - Drain the txq
  11763. * @phba: Pointer to HBA context object.
  11764. *
  11765. * This function attempt to submit IOCBs on the txq
  11766. * to the adapter. For SLI4 adapters, the txq contains
  11767. * ELS IOCBs that have been deferred because the there
  11768. * are no SGLs. This congestion can occur with large
  11769. * vport counts during node discovery.
  11770. **/
  11771. uint32_t
  11772. lpfc_drain_txq(struct lpfc_hba *phba)
  11773. {
  11774. LIST_HEAD(completions);
  11775. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  11776. struct lpfc_iocbq *piocbq = 0;
  11777. unsigned long iflags = 0;
  11778. char *fail_msg = NULL;
  11779. struct lpfc_sglq *sglq;
  11780. union lpfc_wqe wqe;
  11781. spin_lock_irqsave(&phba->hbalock, iflags);
  11782. if (pring->txq_cnt > pring->txq_max)
  11783. pring->txq_max = pring->txq_cnt;
  11784. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11785. while (pring->txq_cnt) {
  11786. spin_lock_irqsave(&phba->hbalock, iflags);
  11787. sglq = __lpfc_sli_get_sglq(phba);
  11788. if (!sglq) {
  11789. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11790. break;
  11791. } else {
  11792. piocbq = lpfc_sli_ringtx_get(phba, pring);
  11793. if (!piocbq) {
  11794. /* The txq_cnt out of sync. This should
  11795. * never happen
  11796. */
  11797. sglq = __lpfc_clear_active_sglq(phba,
  11798. sglq->sli4_xritag);
  11799. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11800. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11801. "2823 txq empty and txq_cnt is %d\n ",
  11802. pring->txq_cnt);
  11803. break;
  11804. }
  11805. }
  11806. /* The xri and iocb resources secured,
  11807. * attempt to issue request
  11808. */
  11809. piocbq->sli4_xritag = sglq->sli4_xritag;
  11810. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  11811. fail_msg = "to convert bpl to sgl";
  11812. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  11813. fail_msg = "to convert iocb to wqe";
  11814. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  11815. fail_msg = " - Wq is full";
  11816. else
  11817. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  11818. if (fail_msg) {
  11819. /* Failed means we can't issue and need to cancel */
  11820. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11821. "2822 IOCB failed %s iotag 0x%x "
  11822. "xri 0x%x\n",
  11823. fail_msg,
  11824. piocbq->iotag, piocbq->sli4_xritag);
  11825. list_add_tail(&piocbq->list, &completions);
  11826. }
  11827. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11828. }
  11829. /* Cancel all the IOCBs that cannot be issued */
  11830. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  11831. IOERR_SLI_ABORTED);
  11832. return pring->txq_cnt;
  11833. }