lpfc_sli.c 368 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_cmnd.h>
  27. #include <scsi/scsi_device.h>
  28. #include <scsi/scsi_host.h>
  29. #include <scsi/scsi_transport_fc.h>
  30. #include <scsi/fc/fc_fs.h>
  31. #include "lpfc_hw4.h"
  32. #include "lpfc_hw.h"
  33. #include "lpfc_sli.h"
  34. #include "lpfc_sli4.h"
  35. #include "lpfc_nl.h"
  36. #include "lpfc_disc.h"
  37. #include "lpfc_scsi.h"
  38. #include "lpfc.h"
  39. #include "lpfc_crtn.h"
  40. #include "lpfc_logmsg.h"
  41. #include "lpfc_compat.h"
  42. #include "lpfc_debugfs.h"
  43. #include "lpfc_vport.h"
  44. /* There are only four IOCB completion types. */
  45. typedef enum _lpfc_iocb_type {
  46. LPFC_UNKNOWN_IOCB,
  47. LPFC_UNSOL_IOCB,
  48. LPFC_SOL_IOCB,
  49. LPFC_ABORT_IOCB
  50. } lpfc_iocb_type;
  51. /* Provide function prototypes local to this module. */
  52. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  53. uint32_t);
  54. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint8_t *, uint32_t *);
  56. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  57. struct hbq_dmabuf *);
  58. static IOCB_t *
  59. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  60. {
  61. return &iocbq->iocb;
  62. }
  63. /**
  64. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  65. * @q: The Work Queue to operate on.
  66. * @wqe: The work Queue Entry to put on the Work queue.
  67. *
  68. * This routine will copy the contents of @wqe to the next available entry on
  69. * the @q. This function will then ring the Work Queue Doorbell to signal the
  70. * HBA to start processing the Work Queue Entry. This function returns 0 if
  71. * successful. If no entries are available on @q then this function will return
  72. * -ENOMEM.
  73. * The caller is expected to hold the hbalock when calling this routine.
  74. **/
  75. static uint32_t
  76. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  77. {
  78. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  79. struct lpfc_register doorbell;
  80. uint32_t host_index;
  81. /* If the host has not yet processed the next entry then we are done */
  82. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  83. return -ENOMEM;
  84. /* set consumption flag every once in a while */
  85. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  86. bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
  87. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  88. /* Update the host index before invoking device */
  89. host_index = q->host_index;
  90. q->host_index = ((q->host_index + 1) % q->entry_count);
  91. /* Ring Doorbell */
  92. doorbell.word0 = 0;
  93. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  94. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  95. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  96. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  97. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  98. return 0;
  99. }
  100. /**
  101. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  102. * @q: The Work Queue to operate on.
  103. * @index: The index to advance the hba index to.
  104. *
  105. * This routine will update the HBA index of a queue to reflect consumption of
  106. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  107. * an entry the host calls this function to update the queue's internal
  108. * pointers. This routine returns the number of entries that were consumed by
  109. * the HBA.
  110. **/
  111. static uint32_t
  112. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  113. {
  114. uint32_t released = 0;
  115. if (q->hba_index == index)
  116. return 0;
  117. do {
  118. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  119. released++;
  120. } while (q->hba_index != index);
  121. return released;
  122. }
  123. /**
  124. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  125. * @q: The Mailbox Queue to operate on.
  126. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  127. *
  128. * This routine will copy the contents of @mqe to the next available entry on
  129. * the @q. This function will then ring the Work Queue Doorbell to signal the
  130. * HBA to start processing the Work Queue Entry. This function returns 0 if
  131. * successful. If no entries are available on @q then this function will return
  132. * -ENOMEM.
  133. * The caller is expected to hold the hbalock when calling this routine.
  134. **/
  135. static uint32_t
  136. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  137. {
  138. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  139. struct lpfc_register doorbell;
  140. uint32_t host_index;
  141. /* If the host has not yet processed the next entry then we are done */
  142. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  143. return -ENOMEM;
  144. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  145. /* Save off the mailbox pointer for completion */
  146. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  147. /* Update the host index before invoking device */
  148. host_index = q->host_index;
  149. q->host_index = ((q->host_index + 1) % q->entry_count);
  150. /* Ring Doorbell */
  151. doorbell.word0 = 0;
  152. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  153. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  154. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  155. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  156. return 0;
  157. }
  158. /**
  159. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  160. * @q: The Mailbox Queue to operate on.
  161. *
  162. * This routine will update the HBA index of a queue to reflect consumption of
  163. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  164. * an entry the host calls this function to update the queue's internal
  165. * pointers. This routine returns the number of entries that were consumed by
  166. * the HBA.
  167. **/
  168. static uint32_t
  169. lpfc_sli4_mq_release(struct lpfc_queue *q)
  170. {
  171. /* Clear the mailbox pointer for completion */
  172. q->phba->mbox = NULL;
  173. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  174. return 1;
  175. }
  176. /**
  177. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  178. * @q: The Event Queue to get the first valid EQE from
  179. *
  180. * This routine will get the first valid Event Queue Entry from @q, update
  181. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  182. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  183. * processed, but not popped back to the HBA then this routine will return NULL.
  184. **/
  185. static struct lpfc_eqe *
  186. lpfc_sli4_eq_get(struct lpfc_queue *q)
  187. {
  188. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  189. /* If the next EQE is not valid then we are done */
  190. if (!bf_get(lpfc_eqe_valid, eqe))
  191. return NULL;
  192. /* If the host has not yet processed the next entry then we are done */
  193. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  194. return NULL;
  195. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  196. return eqe;
  197. }
  198. /**
  199. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  200. * @q: The Event Queue that the host has completed processing for.
  201. * @arm: Indicates whether the host wants to arms this CQ.
  202. *
  203. * This routine will mark all Event Queue Entries on @q, from the last
  204. * known completed entry to the last entry that was processed, as completed
  205. * by clearing the valid bit for each completion queue entry. Then it will
  206. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  207. * The internal host index in the @q will be updated by this routine to indicate
  208. * that the host has finished processing the entries. The @arm parameter
  209. * indicates that the queue should be rearmed when ringing the doorbell.
  210. *
  211. * This function will return the number of EQEs that were popped.
  212. **/
  213. uint32_t
  214. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  215. {
  216. uint32_t released = 0;
  217. struct lpfc_eqe *temp_eqe;
  218. struct lpfc_register doorbell;
  219. /* while there are valid entries */
  220. while (q->hba_index != q->host_index) {
  221. temp_eqe = q->qe[q->host_index].eqe;
  222. bf_set(lpfc_eqe_valid, temp_eqe, 0);
  223. released++;
  224. q->host_index = ((q->host_index + 1) % q->entry_count);
  225. }
  226. if (unlikely(released == 0 && !arm))
  227. return 0;
  228. /* ring doorbell for number popped */
  229. doorbell.word0 = 0;
  230. if (arm) {
  231. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  232. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  233. }
  234. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  235. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  236. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  237. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  238. return released;
  239. }
  240. /**
  241. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  242. * @q: The Completion Queue to get the first valid CQE from
  243. *
  244. * This routine will get the first valid Completion Queue Entry from @q, update
  245. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  246. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  247. * processed, but not popped back to the HBA then this routine will return NULL.
  248. **/
  249. static struct lpfc_cqe *
  250. lpfc_sli4_cq_get(struct lpfc_queue *q)
  251. {
  252. struct lpfc_cqe *cqe;
  253. /* If the next CQE is not valid then we are done */
  254. if (!bf_get(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  255. return NULL;
  256. /* If the host has not yet processed the next entry then we are done */
  257. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  258. return NULL;
  259. cqe = q->qe[q->hba_index].cqe;
  260. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  261. return cqe;
  262. }
  263. /**
  264. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  265. * @q: The Completion Queue that the host has completed processing for.
  266. * @arm: Indicates whether the host wants to arms this CQ.
  267. *
  268. * This routine will mark all Completion queue entries on @q, from the last
  269. * known completed entry to the last entry that was processed, as completed
  270. * by clearing the valid bit for each completion queue entry. Then it will
  271. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  272. * The internal host index in the @q will be updated by this routine to indicate
  273. * that the host has finished processing the entries. The @arm parameter
  274. * indicates that the queue should be rearmed when ringing the doorbell.
  275. *
  276. * This function will return the number of CQEs that were released.
  277. **/
  278. uint32_t
  279. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  280. {
  281. uint32_t released = 0;
  282. struct lpfc_cqe *temp_qe;
  283. struct lpfc_register doorbell;
  284. /* while there are valid entries */
  285. while (q->hba_index != q->host_index) {
  286. temp_qe = q->qe[q->host_index].cqe;
  287. bf_set(lpfc_cqe_valid, temp_qe, 0);
  288. released++;
  289. q->host_index = ((q->host_index + 1) % q->entry_count);
  290. }
  291. if (unlikely(released == 0 && !arm))
  292. return 0;
  293. /* ring doorbell for number popped */
  294. doorbell.word0 = 0;
  295. if (arm)
  296. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  297. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  298. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  299. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  300. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  301. return released;
  302. }
  303. /**
  304. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  305. * @q: The Header Receive Queue to operate on.
  306. * @wqe: The Receive Queue Entry to put on the Receive queue.
  307. *
  308. * This routine will copy the contents of @wqe to the next available entry on
  309. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  310. * HBA to start processing the Receive Queue Entry. This function returns the
  311. * index that the rqe was copied to if successful. If no entries are available
  312. * on @q then this function will return -ENOMEM.
  313. * The caller is expected to hold the hbalock when calling this routine.
  314. **/
  315. static int
  316. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  317. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  318. {
  319. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  320. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  321. struct lpfc_register doorbell;
  322. int put_index = hq->host_index;
  323. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  324. return -EINVAL;
  325. if (hq->host_index != dq->host_index)
  326. return -EINVAL;
  327. /* If the host has not yet processed the next entry then we are done */
  328. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  329. return -EBUSY;
  330. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  331. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  332. /* Update the host index to point to the next slot */
  333. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  334. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  335. /* Ring The Header Receive Queue Doorbell */
  336. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  337. doorbell.word0 = 0;
  338. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  339. LPFC_RQ_POST_BATCH);
  340. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  341. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  342. }
  343. return put_index;
  344. }
  345. /**
  346. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  347. * @q: The Header Receive Queue to operate on.
  348. *
  349. * This routine will update the HBA index of a queue to reflect consumption of
  350. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  351. * consumed an entry the host calls this function to update the queue's
  352. * internal pointers. This routine returns the number of entries that were
  353. * consumed by the HBA.
  354. **/
  355. static uint32_t
  356. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  357. {
  358. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  359. return 0;
  360. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  361. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  362. return 1;
  363. }
  364. /**
  365. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  366. * @phba: Pointer to HBA context object.
  367. * @pring: Pointer to driver SLI ring object.
  368. *
  369. * This function returns pointer to next command iocb entry
  370. * in the command ring. The caller must hold hbalock to prevent
  371. * other threads consume the next command iocb.
  372. * SLI-2/SLI-3 provide different sized iocbs.
  373. **/
  374. static inline IOCB_t *
  375. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  376. {
  377. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  378. pring->cmdidx * phba->iocb_cmd_size);
  379. }
  380. /**
  381. * lpfc_resp_iocb - Get next response iocb entry in the ring
  382. * @phba: Pointer to HBA context object.
  383. * @pring: Pointer to driver SLI ring object.
  384. *
  385. * This function returns pointer to next response iocb entry
  386. * in the response ring. The caller must hold hbalock to make sure
  387. * that no other thread consume the next response iocb.
  388. * SLI-2/SLI-3 provide different sized iocbs.
  389. **/
  390. static inline IOCB_t *
  391. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  392. {
  393. return (IOCB_t *) (((char *) pring->rspringaddr) +
  394. pring->rspidx * phba->iocb_rsp_size);
  395. }
  396. /**
  397. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  398. * @phba: Pointer to HBA context object.
  399. *
  400. * This function is called with hbalock held. This function
  401. * allocates a new driver iocb object from the iocb pool. If the
  402. * allocation is successful, it returns pointer to the newly
  403. * allocated iocb object else it returns NULL.
  404. **/
  405. static struct lpfc_iocbq *
  406. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  407. {
  408. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  409. struct lpfc_iocbq * iocbq = NULL;
  410. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  411. return iocbq;
  412. }
  413. /**
  414. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  415. * @phba: Pointer to HBA context object.
  416. * @xritag: XRI value.
  417. *
  418. * This function clears the sglq pointer from the array of acive
  419. * sglq's. The xritag that is passed in is used to index into the
  420. * array. Before the xritag can be used it needs to be adjusted
  421. * by subtracting the xribase.
  422. *
  423. * Returns sglq ponter = success, NULL = Failure.
  424. **/
  425. static struct lpfc_sglq *
  426. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  427. {
  428. uint16_t adj_xri;
  429. struct lpfc_sglq *sglq;
  430. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  431. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  432. return NULL;
  433. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  434. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  435. return sglq;
  436. }
  437. /**
  438. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  439. * @phba: Pointer to HBA context object.
  440. * @xritag: XRI value.
  441. *
  442. * This function returns the sglq pointer from the array of acive
  443. * sglq's. The xritag that is passed in is used to index into the
  444. * array. Before the xritag can be used it needs to be adjusted
  445. * by subtracting the xribase.
  446. *
  447. * Returns sglq ponter = success, NULL = Failure.
  448. **/
  449. static struct lpfc_sglq *
  450. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  451. {
  452. uint16_t adj_xri;
  453. struct lpfc_sglq *sglq;
  454. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  455. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  456. return NULL;
  457. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  458. return sglq;
  459. }
  460. /**
  461. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  462. * @phba: Pointer to HBA context object.
  463. *
  464. * This function is called with hbalock held. This function
  465. * Gets a new driver sglq object from the sglq list. If the
  466. * list is not empty then it is successful, it returns pointer to the newly
  467. * allocated sglq object else it returns NULL.
  468. **/
  469. static struct lpfc_sglq *
  470. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  471. {
  472. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  473. struct lpfc_sglq *sglq = NULL;
  474. uint16_t adj_xri;
  475. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  476. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  477. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  478. return sglq;
  479. }
  480. /**
  481. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  482. * @phba: Pointer to HBA context object.
  483. *
  484. * This function is called with no lock held. This function
  485. * allocates a new driver iocb object from the iocb pool. If the
  486. * allocation is successful, it returns pointer to the newly
  487. * allocated iocb object else it returns NULL.
  488. **/
  489. struct lpfc_iocbq *
  490. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  491. {
  492. struct lpfc_iocbq * iocbq = NULL;
  493. unsigned long iflags;
  494. spin_lock_irqsave(&phba->hbalock, iflags);
  495. iocbq = __lpfc_sli_get_iocbq(phba);
  496. spin_unlock_irqrestore(&phba->hbalock, iflags);
  497. return iocbq;
  498. }
  499. /**
  500. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  501. * @phba: Pointer to HBA context object.
  502. * @iocbq: Pointer to driver iocb object.
  503. *
  504. * This function is called with hbalock held to release driver
  505. * iocb object to the iocb pool. The iotag in the iocb object
  506. * does not change for each use of the iocb object. This function
  507. * clears all other fields of the iocb object when it is freed.
  508. * The sqlq structure that holds the xritag and phys and virtual
  509. * mappings for the scatter gather list is retrieved from the
  510. * active array of sglq. The get of the sglq pointer also clears
  511. * the entry in the array. If the status of the IO indiactes that
  512. * this IO was aborted then the sglq entry it put on the
  513. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  514. * IO has good status or fails for any other reason then the sglq
  515. * entry is added to the free list (lpfc_sgl_list).
  516. **/
  517. static void
  518. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  519. {
  520. struct lpfc_sglq *sglq;
  521. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  522. unsigned long iflag;
  523. if (iocbq->sli4_xritag == NO_XRI)
  524. sglq = NULL;
  525. else
  526. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  527. if (sglq) {
  528. if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED
  529. && ((iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  530. && (iocbq->iocb.un.ulpWord[4]
  531. == IOERR_ABORT_REQUESTED))) {
  532. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  533. iflag);
  534. list_add(&sglq->list,
  535. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  536. spin_unlock_irqrestore(
  537. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  538. } else
  539. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  540. }
  541. /*
  542. * Clean all volatile data fields, preserve iotag and node struct.
  543. */
  544. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  545. iocbq->sli4_xritag = NO_XRI;
  546. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  547. }
  548. /**
  549. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  550. * @phba: Pointer to HBA context object.
  551. * @iocbq: Pointer to driver iocb object.
  552. *
  553. * This function is called with hbalock held to release driver
  554. * iocb object to the iocb pool. The iotag in the iocb object
  555. * does not change for each use of the iocb object. This function
  556. * clears all other fields of the iocb object when it is freed.
  557. **/
  558. static void
  559. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  560. {
  561. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  562. /*
  563. * Clean all volatile data fields, preserve iotag and node struct.
  564. */
  565. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  566. iocbq->sli4_xritag = NO_XRI;
  567. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  568. }
  569. /**
  570. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  571. * @phba: Pointer to HBA context object.
  572. * @iocbq: Pointer to driver iocb object.
  573. *
  574. * This function is called with hbalock held to release driver
  575. * iocb object to the iocb pool. The iotag in the iocb object
  576. * does not change for each use of the iocb object. This function
  577. * clears all other fields of the iocb object when it is freed.
  578. **/
  579. static void
  580. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  581. {
  582. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  583. }
  584. /**
  585. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  586. * @phba: Pointer to HBA context object.
  587. * @iocbq: Pointer to driver iocb object.
  588. *
  589. * This function is called with no lock held to release the iocb to
  590. * iocb pool.
  591. **/
  592. void
  593. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  594. {
  595. unsigned long iflags;
  596. /*
  597. * Clean all volatile data fields, preserve iotag and node struct.
  598. */
  599. spin_lock_irqsave(&phba->hbalock, iflags);
  600. __lpfc_sli_release_iocbq(phba, iocbq);
  601. spin_unlock_irqrestore(&phba->hbalock, iflags);
  602. }
  603. /**
  604. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  605. * @phba: Pointer to HBA context object.
  606. * @iocblist: List of IOCBs.
  607. * @ulpstatus: ULP status in IOCB command field.
  608. * @ulpWord4: ULP word-4 in IOCB command field.
  609. *
  610. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  611. * on the list by invoking the complete callback function associated with the
  612. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  613. * fields.
  614. **/
  615. void
  616. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  617. uint32_t ulpstatus, uint32_t ulpWord4)
  618. {
  619. struct lpfc_iocbq *piocb;
  620. while (!list_empty(iocblist)) {
  621. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  622. if (!piocb->iocb_cmpl)
  623. lpfc_sli_release_iocbq(phba, piocb);
  624. else {
  625. piocb->iocb.ulpStatus = ulpstatus;
  626. piocb->iocb.un.ulpWord[4] = ulpWord4;
  627. (piocb->iocb_cmpl) (phba, piocb, piocb);
  628. }
  629. }
  630. return;
  631. }
  632. /**
  633. * lpfc_sli_iocb_cmd_type - Get the iocb type
  634. * @iocb_cmnd: iocb command code.
  635. *
  636. * This function is called by ring event handler function to get the iocb type.
  637. * This function translates the iocb command to an iocb command type used to
  638. * decide the final disposition of each completed IOCB.
  639. * The function returns
  640. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  641. * LPFC_SOL_IOCB if it is a solicited iocb completion
  642. * LPFC_ABORT_IOCB if it is an abort iocb
  643. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  644. *
  645. * The caller is not required to hold any lock.
  646. **/
  647. static lpfc_iocb_type
  648. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  649. {
  650. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  651. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  652. return 0;
  653. switch (iocb_cmnd) {
  654. case CMD_XMIT_SEQUENCE_CR:
  655. case CMD_XMIT_SEQUENCE_CX:
  656. case CMD_XMIT_BCAST_CN:
  657. case CMD_XMIT_BCAST_CX:
  658. case CMD_ELS_REQUEST_CR:
  659. case CMD_ELS_REQUEST_CX:
  660. case CMD_CREATE_XRI_CR:
  661. case CMD_CREATE_XRI_CX:
  662. case CMD_GET_RPI_CN:
  663. case CMD_XMIT_ELS_RSP_CX:
  664. case CMD_GET_RPI_CR:
  665. case CMD_FCP_IWRITE_CR:
  666. case CMD_FCP_IWRITE_CX:
  667. case CMD_FCP_IREAD_CR:
  668. case CMD_FCP_IREAD_CX:
  669. case CMD_FCP_ICMND_CR:
  670. case CMD_FCP_ICMND_CX:
  671. case CMD_FCP_TSEND_CX:
  672. case CMD_FCP_TRSP_CX:
  673. case CMD_FCP_TRECEIVE_CX:
  674. case CMD_FCP_AUTO_TRSP_CX:
  675. case CMD_ADAPTER_MSG:
  676. case CMD_ADAPTER_DUMP:
  677. case CMD_XMIT_SEQUENCE64_CR:
  678. case CMD_XMIT_SEQUENCE64_CX:
  679. case CMD_XMIT_BCAST64_CN:
  680. case CMD_XMIT_BCAST64_CX:
  681. case CMD_ELS_REQUEST64_CR:
  682. case CMD_ELS_REQUEST64_CX:
  683. case CMD_FCP_IWRITE64_CR:
  684. case CMD_FCP_IWRITE64_CX:
  685. case CMD_FCP_IREAD64_CR:
  686. case CMD_FCP_IREAD64_CX:
  687. case CMD_FCP_ICMND64_CR:
  688. case CMD_FCP_ICMND64_CX:
  689. case CMD_FCP_TSEND64_CX:
  690. case CMD_FCP_TRSP64_CX:
  691. case CMD_FCP_TRECEIVE64_CX:
  692. case CMD_GEN_REQUEST64_CR:
  693. case CMD_GEN_REQUEST64_CX:
  694. case CMD_XMIT_ELS_RSP64_CX:
  695. case DSSCMD_IWRITE64_CR:
  696. case DSSCMD_IWRITE64_CX:
  697. case DSSCMD_IREAD64_CR:
  698. case DSSCMD_IREAD64_CX:
  699. case DSSCMD_INVALIDATE_DEK:
  700. case DSSCMD_SET_KEK:
  701. case DSSCMD_GET_KEK_ID:
  702. case DSSCMD_GEN_XFER:
  703. type = LPFC_SOL_IOCB;
  704. break;
  705. case CMD_ABORT_XRI_CN:
  706. case CMD_ABORT_XRI_CX:
  707. case CMD_CLOSE_XRI_CN:
  708. case CMD_CLOSE_XRI_CX:
  709. case CMD_XRI_ABORTED_CX:
  710. case CMD_ABORT_MXRI64_CN:
  711. case CMD_XMIT_BLS_RSP64_CX:
  712. type = LPFC_ABORT_IOCB;
  713. break;
  714. case CMD_RCV_SEQUENCE_CX:
  715. case CMD_RCV_ELS_REQ_CX:
  716. case CMD_RCV_SEQUENCE64_CX:
  717. case CMD_RCV_ELS_REQ64_CX:
  718. case CMD_ASYNC_STATUS:
  719. case CMD_IOCB_RCV_SEQ64_CX:
  720. case CMD_IOCB_RCV_ELS64_CX:
  721. case CMD_IOCB_RCV_CONT64_CX:
  722. case CMD_IOCB_RET_XRI64_CX:
  723. type = LPFC_UNSOL_IOCB;
  724. break;
  725. case CMD_IOCB_XMIT_MSEQ64_CR:
  726. case CMD_IOCB_XMIT_MSEQ64_CX:
  727. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  728. case CMD_IOCB_RCV_ELS_LIST64_CX:
  729. case CMD_IOCB_CLOSE_EXTENDED_CN:
  730. case CMD_IOCB_ABORT_EXTENDED_CN:
  731. case CMD_IOCB_RET_HBQE64_CN:
  732. case CMD_IOCB_FCP_IBIDIR64_CR:
  733. case CMD_IOCB_FCP_IBIDIR64_CX:
  734. case CMD_IOCB_FCP_ITASKMGT64_CX:
  735. case CMD_IOCB_LOGENTRY_CN:
  736. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  737. printk("%s - Unhandled SLI-3 Command x%x\n",
  738. __func__, iocb_cmnd);
  739. type = LPFC_UNKNOWN_IOCB;
  740. break;
  741. default:
  742. type = LPFC_UNKNOWN_IOCB;
  743. break;
  744. }
  745. return type;
  746. }
  747. /**
  748. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  749. * @phba: Pointer to HBA context object.
  750. *
  751. * This function is called from SLI initialization code
  752. * to configure every ring of the HBA's SLI interface. The
  753. * caller is not required to hold any lock. This function issues
  754. * a config_ring mailbox command for each ring.
  755. * This function returns zero if successful else returns a negative
  756. * error code.
  757. **/
  758. static int
  759. lpfc_sli_ring_map(struct lpfc_hba *phba)
  760. {
  761. struct lpfc_sli *psli = &phba->sli;
  762. LPFC_MBOXQ_t *pmb;
  763. MAILBOX_t *pmbox;
  764. int i, rc, ret = 0;
  765. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  766. if (!pmb)
  767. return -ENOMEM;
  768. pmbox = &pmb->u.mb;
  769. phba->link_state = LPFC_INIT_MBX_CMDS;
  770. for (i = 0; i < psli->num_rings; i++) {
  771. lpfc_config_ring(phba, i, pmb);
  772. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  773. if (rc != MBX_SUCCESS) {
  774. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  775. "0446 Adapter failed to init (%d), "
  776. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  777. "ring %d\n",
  778. rc, pmbox->mbxCommand,
  779. pmbox->mbxStatus, i);
  780. phba->link_state = LPFC_HBA_ERROR;
  781. ret = -ENXIO;
  782. break;
  783. }
  784. }
  785. mempool_free(pmb, phba->mbox_mem_pool);
  786. return ret;
  787. }
  788. /**
  789. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  790. * @phba: Pointer to HBA context object.
  791. * @pring: Pointer to driver SLI ring object.
  792. * @piocb: Pointer to the driver iocb object.
  793. *
  794. * This function is called with hbalock held. The function adds the
  795. * new iocb to txcmplq of the given ring. This function always returns
  796. * 0. If this function is called for ELS ring, this function checks if
  797. * there is a vport associated with the ELS command. This function also
  798. * starts els_tmofunc timer if this is an ELS command.
  799. **/
  800. static int
  801. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  802. struct lpfc_iocbq *piocb)
  803. {
  804. list_add_tail(&piocb->list, &pring->txcmplq);
  805. pring->txcmplq_cnt++;
  806. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  807. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  808. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  809. if (!piocb->vport)
  810. BUG();
  811. else
  812. mod_timer(&piocb->vport->els_tmofunc,
  813. jiffies + HZ * (phba->fc_ratov << 1));
  814. }
  815. return 0;
  816. }
  817. /**
  818. * lpfc_sli_ringtx_get - Get first element of the txq
  819. * @phba: Pointer to HBA context object.
  820. * @pring: Pointer to driver SLI ring object.
  821. *
  822. * This function is called with hbalock held to get next
  823. * iocb in txq of the given ring. If there is any iocb in
  824. * the txq, the function returns first iocb in the list after
  825. * removing the iocb from the list, else it returns NULL.
  826. **/
  827. static struct lpfc_iocbq *
  828. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  829. {
  830. struct lpfc_iocbq *cmd_iocb;
  831. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  832. if (cmd_iocb != NULL)
  833. pring->txq_cnt--;
  834. return cmd_iocb;
  835. }
  836. /**
  837. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  838. * @phba: Pointer to HBA context object.
  839. * @pring: Pointer to driver SLI ring object.
  840. *
  841. * This function is called with hbalock held and the caller must post the
  842. * iocb without releasing the lock. If the caller releases the lock,
  843. * iocb slot returned by the function is not guaranteed to be available.
  844. * The function returns pointer to the next available iocb slot if there
  845. * is available slot in the ring, else it returns NULL.
  846. * If the get index of the ring is ahead of the put index, the function
  847. * will post an error attention event to the worker thread to take the
  848. * HBA to offline state.
  849. **/
  850. static IOCB_t *
  851. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  852. {
  853. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  854. uint32_t max_cmd_idx = pring->numCiocb;
  855. if ((pring->next_cmdidx == pring->cmdidx) &&
  856. (++pring->next_cmdidx >= max_cmd_idx))
  857. pring->next_cmdidx = 0;
  858. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  859. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  860. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  861. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  862. "0315 Ring %d issue: portCmdGet %d "
  863. "is bigger than cmd ring %d\n",
  864. pring->ringno,
  865. pring->local_getidx, max_cmd_idx);
  866. phba->link_state = LPFC_HBA_ERROR;
  867. /*
  868. * All error attention handlers are posted to
  869. * worker thread
  870. */
  871. phba->work_ha |= HA_ERATT;
  872. phba->work_hs = HS_FFER3;
  873. lpfc_worker_wake_up(phba);
  874. return NULL;
  875. }
  876. if (pring->local_getidx == pring->next_cmdidx)
  877. return NULL;
  878. }
  879. return lpfc_cmd_iocb(phba, pring);
  880. }
  881. /**
  882. * lpfc_sli_next_iotag - Get an iotag for the iocb
  883. * @phba: Pointer to HBA context object.
  884. * @iocbq: Pointer to driver iocb object.
  885. *
  886. * This function gets an iotag for the iocb. If there is no unused iotag and
  887. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  888. * array and assigns a new iotag.
  889. * The function returns the allocated iotag if successful, else returns zero.
  890. * Zero is not a valid iotag.
  891. * The caller is not required to hold any lock.
  892. **/
  893. uint16_t
  894. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  895. {
  896. struct lpfc_iocbq **new_arr;
  897. struct lpfc_iocbq **old_arr;
  898. size_t new_len;
  899. struct lpfc_sli *psli = &phba->sli;
  900. uint16_t iotag;
  901. spin_lock_irq(&phba->hbalock);
  902. iotag = psli->last_iotag;
  903. if(++iotag < psli->iocbq_lookup_len) {
  904. psli->last_iotag = iotag;
  905. psli->iocbq_lookup[iotag] = iocbq;
  906. spin_unlock_irq(&phba->hbalock);
  907. iocbq->iotag = iotag;
  908. return iotag;
  909. } else if (psli->iocbq_lookup_len < (0xffff
  910. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  911. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  912. spin_unlock_irq(&phba->hbalock);
  913. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  914. GFP_KERNEL);
  915. if (new_arr) {
  916. spin_lock_irq(&phba->hbalock);
  917. old_arr = psli->iocbq_lookup;
  918. if (new_len <= psli->iocbq_lookup_len) {
  919. /* highly unprobable case */
  920. kfree(new_arr);
  921. iotag = psli->last_iotag;
  922. if(++iotag < psli->iocbq_lookup_len) {
  923. psli->last_iotag = iotag;
  924. psli->iocbq_lookup[iotag] = iocbq;
  925. spin_unlock_irq(&phba->hbalock);
  926. iocbq->iotag = iotag;
  927. return iotag;
  928. }
  929. spin_unlock_irq(&phba->hbalock);
  930. return 0;
  931. }
  932. if (psli->iocbq_lookup)
  933. memcpy(new_arr, old_arr,
  934. ((psli->last_iotag + 1) *
  935. sizeof (struct lpfc_iocbq *)));
  936. psli->iocbq_lookup = new_arr;
  937. psli->iocbq_lookup_len = new_len;
  938. psli->last_iotag = iotag;
  939. psli->iocbq_lookup[iotag] = iocbq;
  940. spin_unlock_irq(&phba->hbalock);
  941. iocbq->iotag = iotag;
  942. kfree(old_arr);
  943. return iotag;
  944. }
  945. } else
  946. spin_unlock_irq(&phba->hbalock);
  947. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  948. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  949. psli->last_iotag);
  950. return 0;
  951. }
  952. /**
  953. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  954. * @phba: Pointer to HBA context object.
  955. * @pring: Pointer to driver SLI ring object.
  956. * @iocb: Pointer to iocb slot in the ring.
  957. * @nextiocb: Pointer to driver iocb object which need to be
  958. * posted to firmware.
  959. *
  960. * This function is called with hbalock held to post a new iocb to
  961. * the firmware. This function copies the new iocb to ring iocb slot and
  962. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  963. * a completion call back for this iocb else the function will free the
  964. * iocb object.
  965. **/
  966. static void
  967. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  968. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  969. {
  970. /*
  971. * Set up an iotag
  972. */
  973. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  974. if (pring->ringno == LPFC_ELS_RING) {
  975. lpfc_debugfs_slow_ring_trc(phba,
  976. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  977. *(((uint32_t *) &nextiocb->iocb) + 4),
  978. *(((uint32_t *) &nextiocb->iocb) + 6),
  979. *(((uint32_t *) &nextiocb->iocb) + 7));
  980. }
  981. /*
  982. * Issue iocb command to adapter
  983. */
  984. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  985. wmb();
  986. pring->stats.iocb_cmd++;
  987. /*
  988. * If there is no completion routine to call, we can release the
  989. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  990. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  991. */
  992. if (nextiocb->iocb_cmpl)
  993. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  994. else
  995. __lpfc_sli_release_iocbq(phba, nextiocb);
  996. /*
  997. * Let the HBA know what IOCB slot will be the next one the
  998. * driver will put a command into.
  999. */
  1000. pring->cmdidx = pring->next_cmdidx;
  1001. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1002. }
  1003. /**
  1004. * lpfc_sli_update_full_ring - Update the chip attention register
  1005. * @phba: Pointer to HBA context object.
  1006. * @pring: Pointer to driver SLI ring object.
  1007. *
  1008. * The caller is not required to hold any lock for calling this function.
  1009. * This function updates the chip attention bits for the ring to inform firmware
  1010. * that there are pending work to be done for this ring and requests an
  1011. * interrupt when there is space available in the ring. This function is
  1012. * called when the driver is unable to post more iocbs to the ring due
  1013. * to unavailability of space in the ring.
  1014. **/
  1015. static void
  1016. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1017. {
  1018. int ringno = pring->ringno;
  1019. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1020. wmb();
  1021. /*
  1022. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1023. * The HBA will tell us when an IOCB entry is available.
  1024. */
  1025. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1026. readl(phba->CAregaddr); /* flush */
  1027. pring->stats.iocb_cmd_full++;
  1028. }
  1029. /**
  1030. * lpfc_sli_update_ring - Update chip attention register
  1031. * @phba: Pointer to HBA context object.
  1032. * @pring: Pointer to driver SLI ring object.
  1033. *
  1034. * This function updates the chip attention register bit for the
  1035. * given ring to inform HBA that there is more work to be done
  1036. * in this ring. The caller is not required to hold any lock.
  1037. **/
  1038. static void
  1039. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1040. {
  1041. int ringno = pring->ringno;
  1042. /*
  1043. * Tell the HBA that there is work to do in this ring.
  1044. */
  1045. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1046. wmb();
  1047. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1048. readl(phba->CAregaddr); /* flush */
  1049. }
  1050. }
  1051. /**
  1052. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1053. * @phba: Pointer to HBA context object.
  1054. * @pring: Pointer to driver SLI ring object.
  1055. *
  1056. * This function is called with hbalock held to post pending iocbs
  1057. * in the txq to the firmware. This function is called when driver
  1058. * detects space available in the ring.
  1059. **/
  1060. static void
  1061. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1062. {
  1063. IOCB_t *iocb;
  1064. struct lpfc_iocbq *nextiocb;
  1065. /*
  1066. * Check to see if:
  1067. * (a) there is anything on the txq to send
  1068. * (b) link is up
  1069. * (c) link attention events can be processed (fcp ring only)
  1070. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1071. */
  1072. if (pring->txq_cnt &&
  1073. lpfc_is_link_up(phba) &&
  1074. (pring->ringno != phba->sli.fcp_ring ||
  1075. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1076. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1077. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1078. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1079. if (iocb)
  1080. lpfc_sli_update_ring(phba, pring);
  1081. else
  1082. lpfc_sli_update_full_ring(phba, pring);
  1083. }
  1084. return;
  1085. }
  1086. /**
  1087. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1088. * @phba: Pointer to HBA context object.
  1089. * @hbqno: HBQ number.
  1090. *
  1091. * This function is called with hbalock held to get the next
  1092. * available slot for the given HBQ. If there is free slot
  1093. * available for the HBQ it will return pointer to the next available
  1094. * HBQ entry else it will return NULL.
  1095. **/
  1096. static struct lpfc_hbq_entry *
  1097. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1098. {
  1099. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1100. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1101. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1102. hbqp->next_hbqPutIdx = 0;
  1103. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1104. uint32_t raw_index = phba->hbq_get[hbqno];
  1105. uint32_t getidx = le32_to_cpu(raw_index);
  1106. hbqp->local_hbqGetIdx = getidx;
  1107. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1108. lpfc_printf_log(phba, KERN_ERR,
  1109. LOG_SLI | LOG_VPORT,
  1110. "1802 HBQ %d: local_hbqGetIdx "
  1111. "%u is > than hbqp->entry_count %u\n",
  1112. hbqno, hbqp->local_hbqGetIdx,
  1113. hbqp->entry_count);
  1114. phba->link_state = LPFC_HBA_ERROR;
  1115. return NULL;
  1116. }
  1117. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1118. return NULL;
  1119. }
  1120. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1121. hbqp->hbqPutIdx;
  1122. }
  1123. /**
  1124. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1125. * @phba: Pointer to HBA context object.
  1126. *
  1127. * This function is called with no lock held to free all the
  1128. * hbq buffers while uninitializing the SLI interface. It also
  1129. * frees the HBQ buffers returned by the firmware but not yet
  1130. * processed by the upper layers.
  1131. **/
  1132. void
  1133. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1134. {
  1135. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1136. struct hbq_dmabuf *hbq_buf;
  1137. unsigned long flags;
  1138. int i, hbq_count;
  1139. uint32_t hbqno;
  1140. hbq_count = lpfc_sli_hbq_count();
  1141. /* Return all memory used by all HBQs */
  1142. spin_lock_irqsave(&phba->hbalock, flags);
  1143. for (i = 0; i < hbq_count; ++i) {
  1144. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1145. &phba->hbqs[i].hbq_buffer_list, list) {
  1146. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1147. list_del(&hbq_buf->dbuf.list);
  1148. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1149. }
  1150. phba->hbqs[i].buffer_count = 0;
  1151. }
  1152. /* Return all HBQ buffer that are in-fly */
  1153. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1154. list) {
  1155. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1156. list_del(&hbq_buf->dbuf.list);
  1157. if (hbq_buf->tag == -1) {
  1158. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1159. (phba, hbq_buf);
  1160. } else {
  1161. hbqno = hbq_buf->tag >> 16;
  1162. if (hbqno >= LPFC_MAX_HBQS)
  1163. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1164. (phba, hbq_buf);
  1165. else
  1166. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1167. hbq_buf);
  1168. }
  1169. }
  1170. /* Mark the HBQs not in use */
  1171. phba->hbq_in_use = 0;
  1172. spin_unlock_irqrestore(&phba->hbalock, flags);
  1173. }
  1174. /**
  1175. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1176. * @phba: Pointer to HBA context object.
  1177. * @hbqno: HBQ number.
  1178. * @hbq_buf: Pointer to HBQ buffer.
  1179. *
  1180. * This function is called with the hbalock held to post a
  1181. * hbq buffer to the firmware. If the function finds an empty
  1182. * slot in the HBQ, it will post the buffer. The function will return
  1183. * pointer to the hbq entry if it successfully post the buffer
  1184. * else it will return NULL.
  1185. **/
  1186. static int
  1187. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1188. struct hbq_dmabuf *hbq_buf)
  1189. {
  1190. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1191. }
  1192. /**
  1193. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 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 hbq buffer to the
  1199. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1200. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1201. * it successfully post the buffer else it will return an error.
  1202. **/
  1203. static int
  1204. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1205. struct hbq_dmabuf *hbq_buf)
  1206. {
  1207. struct lpfc_hbq_entry *hbqe;
  1208. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1209. /* Get next HBQ entry slot to use */
  1210. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1211. if (hbqe) {
  1212. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1213. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1214. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1215. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1216. hbqe->bde.tus.f.bdeFlags = 0;
  1217. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1218. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1219. /* Sync SLIM */
  1220. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1221. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1222. /* flush */
  1223. readl(phba->hbq_put + hbqno);
  1224. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1225. return 0;
  1226. } else
  1227. return -ENOMEM;
  1228. }
  1229. /**
  1230. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1231. * @phba: Pointer to HBA context object.
  1232. * @hbqno: HBQ number.
  1233. * @hbq_buf: Pointer to HBQ buffer.
  1234. *
  1235. * This function is called with the hbalock held to post an RQE to the SLI4
  1236. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1237. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1238. **/
  1239. static int
  1240. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1241. struct hbq_dmabuf *hbq_buf)
  1242. {
  1243. int rc;
  1244. struct lpfc_rqe hrqe;
  1245. struct lpfc_rqe drqe;
  1246. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1247. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1248. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1249. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1250. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1251. &hrqe, &drqe);
  1252. if (rc < 0)
  1253. return rc;
  1254. hbq_buf->tag = rc;
  1255. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1256. return 0;
  1257. }
  1258. /* HBQ for ELS and CT traffic. */
  1259. static struct lpfc_hbq_init lpfc_els_hbq = {
  1260. .rn = 1,
  1261. .entry_count = 200,
  1262. .mask_count = 0,
  1263. .profile = 0,
  1264. .ring_mask = (1 << LPFC_ELS_RING),
  1265. .buffer_count = 0,
  1266. .init_count = 40,
  1267. .add_count = 40,
  1268. };
  1269. /* HBQ for the extra ring if needed */
  1270. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1271. .rn = 1,
  1272. .entry_count = 200,
  1273. .mask_count = 0,
  1274. .profile = 0,
  1275. .ring_mask = (1 << LPFC_EXTRA_RING),
  1276. .buffer_count = 0,
  1277. .init_count = 0,
  1278. .add_count = 5,
  1279. };
  1280. /* Array of HBQs */
  1281. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1282. &lpfc_els_hbq,
  1283. &lpfc_extra_hbq,
  1284. };
  1285. /**
  1286. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1287. * @phba: Pointer to HBA context object.
  1288. * @hbqno: HBQ number.
  1289. * @count: Number of HBQ buffers to be posted.
  1290. *
  1291. * This function is called with no lock held to post more hbq buffers to the
  1292. * given HBQ. The function returns the number of HBQ buffers successfully
  1293. * posted.
  1294. **/
  1295. static int
  1296. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1297. {
  1298. uint32_t i, posted = 0;
  1299. unsigned long flags;
  1300. struct hbq_dmabuf *hbq_buffer;
  1301. LIST_HEAD(hbq_buf_list);
  1302. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1303. return 0;
  1304. if ((phba->hbqs[hbqno].buffer_count + count) >
  1305. lpfc_hbq_defs[hbqno]->entry_count)
  1306. count = lpfc_hbq_defs[hbqno]->entry_count -
  1307. phba->hbqs[hbqno].buffer_count;
  1308. if (!count)
  1309. return 0;
  1310. /* Allocate HBQ entries */
  1311. for (i = 0; i < count; i++) {
  1312. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1313. if (!hbq_buffer)
  1314. break;
  1315. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1316. }
  1317. /* Check whether HBQ is still in use */
  1318. spin_lock_irqsave(&phba->hbalock, flags);
  1319. if (!phba->hbq_in_use)
  1320. goto err;
  1321. while (!list_empty(&hbq_buf_list)) {
  1322. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1323. dbuf.list);
  1324. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1325. (hbqno << 16));
  1326. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1327. phba->hbqs[hbqno].buffer_count++;
  1328. posted++;
  1329. } else
  1330. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1331. }
  1332. spin_unlock_irqrestore(&phba->hbalock, flags);
  1333. return posted;
  1334. err:
  1335. spin_unlock_irqrestore(&phba->hbalock, flags);
  1336. while (!list_empty(&hbq_buf_list)) {
  1337. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1338. dbuf.list);
  1339. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1340. }
  1341. return 0;
  1342. }
  1343. /**
  1344. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1345. * @phba: Pointer to HBA context object.
  1346. * @qno: HBQ number.
  1347. *
  1348. * This function posts more buffers to the HBQ. This function
  1349. * is called with no lock held. The function returns the number of HBQ entries
  1350. * successfully allocated.
  1351. **/
  1352. int
  1353. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1354. {
  1355. return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1356. lpfc_hbq_defs[qno]->add_count));
  1357. }
  1358. /**
  1359. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1360. * @phba: Pointer to HBA context object.
  1361. * @qno: HBQ queue number.
  1362. *
  1363. * This function is called from SLI initialization code path with
  1364. * no lock held to post initial HBQ buffers to firmware. The
  1365. * function returns the number of HBQ entries successfully allocated.
  1366. **/
  1367. static int
  1368. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1369. {
  1370. return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1371. lpfc_hbq_defs[qno]->init_count));
  1372. }
  1373. /**
  1374. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1375. * @phba: Pointer to HBA context object.
  1376. * @hbqno: HBQ number.
  1377. *
  1378. * This function removes the first hbq buffer on an hbq list and returns a
  1379. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1380. **/
  1381. static struct hbq_dmabuf *
  1382. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1383. {
  1384. struct lpfc_dmabuf *d_buf;
  1385. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1386. if (!d_buf)
  1387. return NULL;
  1388. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1389. }
  1390. /**
  1391. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1392. * @phba: Pointer to HBA context object.
  1393. * @tag: Tag of the hbq buffer.
  1394. *
  1395. * This function is called with hbalock held. This function searches
  1396. * for the hbq buffer associated with the given tag in the hbq buffer
  1397. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1398. * it returns NULL.
  1399. **/
  1400. static struct hbq_dmabuf *
  1401. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1402. {
  1403. struct lpfc_dmabuf *d_buf;
  1404. struct hbq_dmabuf *hbq_buf;
  1405. uint32_t hbqno;
  1406. hbqno = tag >> 16;
  1407. if (hbqno >= LPFC_MAX_HBQS)
  1408. return NULL;
  1409. spin_lock_irq(&phba->hbalock);
  1410. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1411. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1412. if (hbq_buf->tag == tag) {
  1413. spin_unlock_irq(&phba->hbalock);
  1414. return hbq_buf;
  1415. }
  1416. }
  1417. spin_unlock_irq(&phba->hbalock);
  1418. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1419. "1803 Bad hbq tag. Data: x%x x%x\n",
  1420. tag, phba->hbqs[tag >> 16].buffer_count);
  1421. return NULL;
  1422. }
  1423. /**
  1424. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1425. * @phba: Pointer to HBA context object.
  1426. * @hbq_buffer: Pointer to HBQ buffer.
  1427. *
  1428. * This function is called with hbalock. This function gives back
  1429. * the hbq buffer to firmware. If the HBQ does not have space to
  1430. * post the buffer, it will free the buffer.
  1431. **/
  1432. void
  1433. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1434. {
  1435. uint32_t hbqno;
  1436. if (hbq_buffer) {
  1437. hbqno = hbq_buffer->tag >> 16;
  1438. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1439. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1440. }
  1441. }
  1442. /**
  1443. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1444. * @mbxCommand: mailbox command code.
  1445. *
  1446. * This function is called by the mailbox event handler function to verify
  1447. * that the completed mailbox command is a legitimate mailbox command. If the
  1448. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1449. * and the mailbox event handler will take the HBA offline.
  1450. **/
  1451. static int
  1452. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1453. {
  1454. uint8_t ret;
  1455. switch (mbxCommand) {
  1456. case MBX_LOAD_SM:
  1457. case MBX_READ_NV:
  1458. case MBX_WRITE_NV:
  1459. case MBX_WRITE_VPARMS:
  1460. case MBX_RUN_BIU_DIAG:
  1461. case MBX_INIT_LINK:
  1462. case MBX_DOWN_LINK:
  1463. case MBX_CONFIG_LINK:
  1464. case MBX_CONFIG_RING:
  1465. case MBX_RESET_RING:
  1466. case MBX_READ_CONFIG:
  1467. case MBX_READ_RCONFIG:
  1468. case MBX_READ_SPARM:
  1469. case MBX_READ_STATUS:
  1470. case MBX_READ_RPI:
  1471. case MBX_READ_XRI:
  1472. case MBX_READ_REV:
  1473. case MBX_READ_LNK_STAT:
  1474. case MBX_REG_LOGIN:
  1475. case MBX_UNREG_LOGIN:
  1476. case MBX_READ_LA:
  1477. case MBX_CLEAR_LA:
  1478. case MBX_DUMP_MEMORY:
  1479. case MBX_DUMP_CONTEXT:
  1480. case MBX_RUN_DIAGS:
  1481. case MBX_RESTART:
  1482. case MBX_UPDATE_CFG:
  1483. case MBX_DOWN_LOAD:
  1484. case MBX_DEL_LD_ENTRY:
  1485. case MBX_RUN_PROGRAM:
  1486. case MBX_SET_MASK:
  1487. case MBX_SET_VARIABLE:
  1488. case MBX_UNREG_D_ID:
  1489. case MBX_KILL_BOARD:
  1490. case MBX_CONFIG_FARP:
  1491. case MBX_BEACON:
  1492. case MBX_LOAD_AREA:
  1493. case MBX_RUN_BIU_DIAG64:
  1494. case MBX_CONFIG_PORT:
  1495. case MBX_READ_SPARM64:
  1496. case MBX_READ_RPI64:
  1497. case MBX_REG_LOGIN64:
  1498. case MBX_READ_LA64:
  1499. case MBX_WRITE_WWN:
  1500. case MBX_SET_DEBUG:
  1501. case MBX_LOAD_EXP_ROM:
  1502. case MBX_ASYNCEVT_ENABLE:
  1503. case MBX_REG_VPI:
  1504. case MBX_UNREG_VPI:
  1505. case MBX_HEARTBEAT:
  1506. case MBX_PORT_CAPABILITIES:
  1507. case MBX_PORT_IOV_CONTROL:
  1508. case MBX_SLI4_CONFIG:
  1509. case MBX_SLI4_REQ_FTRS:
  1510. case MBX_REG_FCFI:
  1511. case MBX_UNREG_FCFI:
  1512. case MBX_REG_VFI:
  1513. case MBX_UNREG_VFI:
  1514. case MBX_INIT_VPI:
  1515. case MBX_INIT_VFI:
  1516. case MBX_RESUME_RPI:
  1517. ret = mbxCommand;
  1518. break;
  1519. default:
  1520. ret = MBX_SHUTDOWN;
  1521. break;
  1522. }
  1523. return ret;
  1524. }
  1525. /**
  1526. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1527. * @phba: Pointer to HBA context object.
  1528. * @pmboxq: Pointer to mailbox command.
  1529. *
  1530. * This is completion handler function for mailbox commands issued from
  1531. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1532. * mailbox event handler function with no lock held. This function
  1533. * will wake up thread waiting on the wait queue pointed by context1
  1534. * of the mailbox.
  1535. **/
  1536. void
  1537. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1538. {
  1539. wait_queue_head_t *pdone_q;
  1540. unsigned long drvr_flag;
  1541. /*
  1542. * If pdone_q is empty, the driver thread gave up waiting and
  1543. * continued running.
  1544. */
  1545. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1546. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1547. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1548. if (pdone_q)
  1549. wake_up_interruptible(pdone_q);
  1550. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1551. return;
  1552. }
  1553. /**
  1554. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1555. * @phba: Pointer to HBA context object.
  1556. * @pmb: Pointer to mailbox object.
  1557. *
  1558. * This function is the default mailbox completion handler. It
  1559. * frees the memory resources associated with the completed mailbox
  1560. * command. If the completed command is a REG_LOGIN mailbox command,
  1561. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1562. **/
  1563. void
  1564. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1565. {
  1566. struct lpfc_dmabuf *mp;
  1567. uint16_t rpi, vpi;
  1568. int rc;
  1569. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1570. if (mp) {
  1571. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1572. kfree(mp);
  1573. }
  1574. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1575. (phba->sli_rev == LPFC_SLI_REV4))
  1576. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1577. /*
  1578. * If a REG_LOGIN succeeded after node is destroyed or node
  1579. * is in re-discovery driver need to cleanup the RPI.
  1580. */
  1581. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1582. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1583. !pmb->u.mb.mbxStatus) {
  1584. rpi = pmb->u.mb.un.varWords[0];
  1585. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1586. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1587. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1588. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1589. if (rc != MBX_NOT_FINISHED)
  1590. return;
  1591. }
  1592. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1593. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1594. else
  1595. mempool_free(pmb, phba->mbox_mem_pool);
  1596. }
  1597. /**
  1598. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1599. * @phba: Pointer to HBA context object.
  1600. *
  1601. * This function is called with no lock held. This function processes all
  1602. * the completed mailbox commands and gives it to upper layers. The interrupt
  1603. * service routine processes mailbox completion interrupt and adds completed
  1604. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1605. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1606. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1607. * function returns the mailbox commands to the upper layer by calling the
  1608. * completion handler function of each mailbox.
  1609. **/
  1610. int
  1611. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1612. {
  1613. MAILBOX_t *pmbox;
  1614. LPFC_MBOXQ_t *pmb;
  1615. int rc;
  1616. LIST_HEAD(cmplq);
  1617. phba->sli.slistat.mbox_event++;
  1618. /* Get all completed mailboxe buffers into the cmplq */
  1619. spin_lock_irq(&phba->hbalock);
  1620. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1621. spin_unlock_irq(&phba->hbalock);
  1622. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1623. do {
  1624. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1625. if (pmb == NULL)
  1626. break;
  1627. pmbox = &pmb->u.mb;
  1628. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1629. if (pmb->vport) {
  1630. lpfc_debugfs_disc_trc(pmb->vport,
  1631. LPFC_DISC_TRC_MBOX_VPORT,
  1632. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1633. (uint32_t)pmbox->mbxCommand,
  1634. pmbox->un.varWords[0],
  1635. pmbox->un.varWords[1]);
  1636. }
  1637. else {
  1638. lpfc_debugfs_disc_trc(phba->pport,
  1639. LPFC_DISC_TRC_MBOX,
  1640. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1641. (uint32_t)pmbox->mbxCommand,
  1642. pmbox->un.varWords[0],
  1643. pmbox->un.varWords[1]);
  1644. }
  1645. }
  1646. /*
  1647. * It is a fatal error if unknown mbox command completion.
  1648. */
  1649. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1650. MBX_SHUTDOWN) {
  1651. /* Unknow mailbox command compl */
  1652. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1653. "(%d):0323 Unknown Mailbox command "
  1654. "x%x (x%x) Cmpl\n",
  1655. pmb->vport ? pmb->vport->vpi : 0,
  1656. pmbox->mbxCommand,
  1657. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1658. phba->link_state = LPFC_HBA_ERROR;
  1659. phba->work_hs = HS_FFER3;
  1660. lpfc_handle_eratt(phba);
  1661. continue;
  1662. }
  1663. if (pmbox->mbxStatus) {
  1664. phba->sli.slistat.mbox_stat_err++;
  1665. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1666. /* Mbox cmd cmpl error - RETRYing */
  1667. lpfc_printf_log(phba, KERN_INFO,
  1668. LOG_MBOX | LOG_SLI,
  1669. "(%d):0305 Mbox cmd cmpl "
  1670. "error - RETRYing Data: x%x "
  1671. "(x%x) x%x x%x x%x\n",
  1672. pmb->vport ? pmb->vport->vpi :0,
  1673. pmbox->mbxCommand,
  1674. lpfc_sli4_mbox_opcode_get(phba,
  1675. pmb),
  1676. pmbox->mbxStatus,
  1677. pmbox->un.varWords[0],
  1678. pmb->vport->port_state);
  1679. pmbox->mbxStatus = 0;
  1680. pmbox->mbxOwner = OWN_HOST;
  1681. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1682. if (rc != MBX_NOT_FINISHED)
  1683. continue;
  1684. }
  1685. }
  1686. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1687. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1688. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1689. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1690. pmb->vport ? pmb->vport->vpi : 0,
  1691. pmbox->mbxCommand,
  1692. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1693. pmb->mbox_cmpl,
  1694. *((uint32_t *) pmbox),
  1695. pmbox->un.varWords[0],
  1696. pmbox->un.varWords[1],
  1697. pmbox->un.varWords[2],
  1698. pmbox->un.varWords[3],
  1699. pmbox->un.varWords[4],
  1700. pmbox->un.varWords[5],
  1701. pmbox->un.varWords[6],
  1702. pmbox->un.varWords[7]);
  1703. if (pmb->mbox_cmpl)
  1704. pmb->mbox_cmpl(phba,pmb);
  1705. } while (1);
  1706. return 0;
  1707. }
  1708. /**
  1709. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1710. * @phba: Pointer to HBA context object.
  1711. * @pring: Pointer to driver SLI ring object.
  1712. * @tag: buffer tag.
  1713. *
  1714. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1715. * is set in the tag the buffer is posted for a particular exchange,
  1716. * the function will return the buffer without replacing the buffer.
  1717. * If the buffer is for unsolicited ELS or CT traffic, this function
  1718. * returns the buffer and also posts another buffer to the firmware.
  1719. **/
  1720. static struct lpfc_dmabuf *
  1721. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1722. struct lpfc_sli_ring *pring,
  1723. uint32_t tag)
  1724. {
  1725. struct hbq_dmabuf *hbq_entry;
  1726. if (tag & QUE_BUFTAG_BIT)
  1727. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1728. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1729. if (!hbq_entry)
  1730. return NULL;
  1731. return &hbq_entry->dbuf;
  1732. }
  1733. /**
  1734. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1735. * @phba: Pointer to HBA context object.
  1736. * @pring: Pointer to driver SLI ring object.
  1737. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1738. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1739. * @fch_type: the type for the first frame of the sequence.
  1740. *
  1741. * This function is called with no lock held. This function uses the r_ctl and
  1742. * type of the received sequence to find the correct callback function to call
  1743. * to process the sequence.
  1744. **/
  1745. static int
  1746. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1747. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1748. uint32_t fch_type)
  1749. {
  1750. int i;
  1751. /* unSolicited Responses */
  1752. if (pring->prt[0].profile) {
  1753. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1754. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1755. saveq);
  1756. return 1;
  1757. }
  1758. /* We must search, based on rctl / type
  1759. for the right routine */
  1760. for (i = 0; i < pring->num_mask; i++) {
  1761. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1762. (pring->prt[i].type == fch_type)) {
  1763. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1764. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1765. (phba, pring, saveq);
  1766. return 1;
  1767. }
  1768. }
  1769. return 0;
  1770. }
  1771. /**
  1772. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1773. * @phba: Pointer to HBA context object.
  1774. * @pring: Pointer to driver SLI ring object.
  1775. * @saveq: Pointer to the unsolicited iocb.
  1776. *
  1777. * This function is called with no lock held by the ring event handler
  1778. * when there is an unsolicited iocb posted to the response ring by the
  1779. * firmware. This function gets the buffer associated with the iocbs
  1780. * and calls the event handler for the ring. This function handles both
  1781. * qring buffers and hbq buffers.
  1782. * When the function returns 1 the caller can free the iocb object otherwise
  1783. * upper layer functions will free the iocb objects.
  1784. **/
  1785. static int
  1786. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1787. struct lpfc_iocbq *saveq)
  1788. {
  1789. IOCB_t * irsp;
  1790. WORD5 * w5p;
  1791. uint32_t Rctl, Type;
  1792. uint32_t match;
  1793. struct lpfc_iocbq *iocbq;
  1794. struct lpfc_dmabuf *dmzbuf;
  1795. match = 0;
  1796. irsp = &(saveq->iocb);
  1797. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1798. if (pring->lpfc_sli_rcv_async_status)
  1799. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1800. else
  1801. lpfc_printf_log(phba,
  1802. KERN_WARNING,
  1803. LOG_SLI,
  1804. "0316 Ring %d handler: unexpected "
  1805. "ASYNC_STATUS iocb received evt_code "
  1806. "0x%x\n",
  1807. pring->ringno,
  1808. irsp->un.asyncstat.evt_code);
  1809. return 1;
  1810. }
  1811. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1812. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1813. if (irsp->ulpBdeCount > 0) {
  1814. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1815. irsp->un.ulpWord[3]);
  1816. lpfc_in_buf_free(phba, dmzbuf);
  1817. }
  1818. if (irsp->ulpBdeCount > 1) {
  1819. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1820. irsp->unsli3.sli3Words[3]);
  1821. lpfc_in_buf_free(phba, dmzbuf);
  1822. }
  1823. if (irsp->ulpBdeCount > 2) {
  1824. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1825. irsp->unsli3.sli3Words[7]);
  1826. lpfc_in_buf_free(phba, dmzbuf);
  1827. }
  1828. return 1;
  1829. }
  1830. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1831. if (irsp->ulpBdeCount != 0) {
  1832. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1833. irsp->un.ulpWord[3]);
  1834. if (!saveq->context2)
  1835. lpfc_printf_log(phba,
  1836. KERN_ERR,
  1837. LOG_SLI,
  1838. "0341 Ring %d Cannot find buffer for "
  1839. "an unsolicited iocb. tag 0x%x\n",
  1840. pring->ringno,
  1841. irsp->un.ulpWord[3]);
  1842. }
  1843. if (irsp->ulpBdeCount == 2) {
  1844. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1845. irsp->unsli3.sli3Words[7]);
  1846. if (!saveq->context3)
  1847. lpfc_printf_log(phba,
  1848. KERN_ERR,
  1849. LOG_SLI,
  1850. "0342 Ring %d Cannot find buffer for an"
  1851. " unsolicited iocb. tag 0x%x\n",
  1852. pring->ringno,
  1853. irsp->unsli3.sli3Words[7]);
  1854. }
  1855. list_for_each_entry(iocbq, &saveq->list, list) {
  1856. irsp = &(iocbq->iocb);
  1857. if (irsp->ulpBdeCount != 0) {
  1858. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1859. irsp->un.ulpWord[3]);
  1860. if (!iocbq->context2)
  1861. lpfc_printf_log(phba,
  1862. KERN_ERR,
  1863. LOG_SLI,
  1864. "0343 Ring %d Cannot find "
  1865. "buffer for an unsolicited iocb"
  1866. ". tag 0x%x\n", pring->ringno,
  1867. irsp->un.ulpWord[3]);
  1868. }
  1869. if (irsp->ulpBdeCount == 2) {
  1870. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1871. irsp->unsli3.sli3Words[7]);
  1872. if (!iocbq->context3)
  1873. lpfc_printf_log(phba,
  1874. KERN_ERR,
  1875. LOG_SLI,
  1876. "0344 Ring %d Cannot find "
  1877. "buffer for an unsolicited "
  1878. "iocb. tag 0x%x\n",
  1879. pring->ringno,
  1880. irsp->unsli3.sli3Words[7]);
  1881. }
  1882. }
  1883. }
  1884. if (irsp->ulpBdeCount != 0 &&
  1885. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1886. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1887. int found = 0;
  1888. /* search continue save q for same XRI */
  1889. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1890. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1891. list_add_tail(&saveq->list, &iocbq->list);
  1892. found = 1;
  1893. break;
  1894. }
  1895. }
  1896. if (!found)
  1897. list_add_tail(&saveq->clist,
  1898. &pring->iocb_continue_saveq);
  1899. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1900. list_del_init(&iocbq->clist);
  1901. saveq = iocbq;
  1902. irsp = &(saveq->iocb);
  1903. } else
  1904. return 0;
  1905. }
  1906. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1907. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1908. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1909. Rctl = FC_ELS_REQ;
  1910. Type = FC_ELS_DATA;
  1911. } else {
  1912. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1913. Rctl = w5p->hcsw.Rctl;
  1914. Type = w5p->hcsw.Type;
  1915. /* Firmware Workaround */
  1916. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1917. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1918. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1919. Rctl = FC_ELS_REQ;
  1920. Type = FC_ELS_DATA;
  1921. w5p->hcsw.Rctl = Rctl;
  1922. w5p->hcsw.Type = Type;
  1923. }
  1924. }
  1925. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1926. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1927. "0313 Ring %d handler: unexpected Rctl x%x "
  1928. "Type x%x received\n",
  1929. pring->ringno, Rctl, Type);
  1930. return 1;
  1931. }
  1932. /**
  1933. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1934. * @phba: Pointer to HBA context object.
  1935. * @pring: Pointer to driver SLI ring object.
  1936. * @prspiocb: Pointer to response iocb object.
  1937. *
  1938. * This function looks up the iocb_lookup table to get the command iocb
  1939. * corresponding to the given response iocb using the iotag of the
  1940. * response iocb. This function is called with the hbalock held.
  1941. * This function returns the command iocb object if it finds the command
  1942. * iocb else returns NULL.
  1943. **/
  1944. static struct lpfc_iocbq *
  1945. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1946. struct lpfc_sli_ring *pring,
  1947. struct lpfc_iocbq *prspiocb)
  1948. {
  1949. struct lpfc_iocbq *cmd_iocb = NULL;
  1950. uint16_t iotag;
  1951. iotag = prspiocb->iocb.ulpIoTag;
  1952. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1953. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1954. list_del_init(&cmd_iocb->list);
  1955. pring->txcmplq_cnt--;
  1956. return cmd_iocb;
  1957. }
  1958. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1959. "0317 iotag x%x is out off "
  1960. "range: max iotag x%x wd0 x%x\n",
  1961. iotag, phba->sli.last_iotag,
  1962. *(((uint32_t *) &prspiocb->iocb) + 7));
  1963. return NULL;
  1964. }
  1965. /**
  1966. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  1967. * @phba: Pointer to HBA context object.
  1968. * @pring: Pointer to driver SLI ring object.
  1969. * @iotag: IOCB tag.
  1970. *
  1971. * This function looks up the iocb_lookup table to get the command iocb
  1972. * corresponding to the given iotag. This function is called with the
  1973. * hbalock held.
  1974. * This function returns the command iocb object if it finds the command
  1975. * iocb else returns NULL.
  1976. **/
  1977. static struct lpfc_iocbq *
  1978. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  1979. struct lpfc_sli_ring *pring, uint16_t iotag)
  1980. {
  1981. struct lpfc_iocbq *cmd_iocb;
  1982. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1983. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1984. list_del_init(&cmd_iocb->list);
  1985. pring->txcmplq_cnt--;
  1986. return cmd_iocb;
  1987. }
  1988. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1989. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  1990. iotag, phba->sli.last_iotag);
  1991. return NULL;
  1992. }
  1993. /**
  1994. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  1995. * @phba: Pointer to HBA context object.
  1996. * @pring: Pointer to driver SLI ring object.
  1997. * @saveq: Pointer to the response iocb to be processed.
  1998. *
  1999. * This function is called by the ring event handler for non-fcp
  2000. * rings when there is a new response iocb in the response ring.
  2001. * The caller is not required to hold any locks. This function
  2002. * gets the command iocb associated with the response iocb and
  2003. * calls the completion handler for the command iocb. If there
  2004. * is no completion handler, the function will free the resources
  2005. * associated with command iocb. If the response iocb is for
  2006. * an already aborted command iocb, the status of the completion
  2007. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2008. * This function always returns 1.
  2009. **/
  2010. static int
  2011. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2012. struct lpfc_iocbq *saveq)
  2013. {
  2014. struct lpfc_iocbq *cmdiocbp;
  2015. int rc = 1;
  2016. unsigned long iflag;
  2017. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2018. spin_lock_irqsave(&phba->hbalock, iflag);
  2019. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2020. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2021. if (cmdiocbp) {
  2022. if (cmdiocbp->iocb_cmpl) {
  2023. /*
  2024. * If an ELS command failed send an event to mgmt
  2025. * application.
  2026. */
  2027. if (saveq->iocb.ulpStatus &&
  2028. (pring->ringno == LPFC_ELS_RING) &&
  2029. (cmdiocbp->iocb.ulpCommand ==
  2030. CMD_ELS_REQUEST64_CR))
  2031. lpfc_send_els_failure_event(phba,
  2032. cmdiocbp, saveq);
  2033. /*
  2034. * Post all ELS completions to the worker thread.
  2035. * All other are passed to the completion callback.
  2036. */
  2037. if (pring->ringno == LPFC_ELS_RING) {
  2038. if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
  2039. cmdiocbp->iocb_flag &=
  2040. ~LPFC_DRIVER_ABORTED;
  2041. saveq->iocb.ulpStatus =
  2042. IOSTAT_LOCAL_REJECT;
  2043. saveq->iocb.un.ulpWord[4] =
  2044. IOERR_SLI_ABORTED;
  2045. /* Firmware could still be in progress
  2046. * of DMAing payload, so don't free data
  2047. * buffer till after a hbeat.
  2048. */
  2049. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2050. }
  2051. }
  2052. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2053. } else
  2054. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2055. } else {
  2056. /*
  2057. * Unknown initiating command based on the response iotag.
  2058. * This could be the case on the ELS ring because of
  2059. * lpfc_els_abort().
  2060. */
  2061. if (pring->ringno != LPFC_ELS_RING) {
  2062. /*
  2063. * Ring <ringno> handler: unexpected completion IoTag
  2064. * <IoTag>
  2065. */
  2066. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2067. "0322 Ring %d handler: "
  2068. "unexpected completion IoTag x%x "
  2069. "Data: x%x x%x x%x x%x\n",
  2070. pring->ringno,
  2071. saveq->iocb.ulpIoTag,
  2072. saveq->iocb.ulpStatus,
  2073. saveq->iocb.un.ulpWord[4],
  2074. saveq->iocb.ulpCommand,
  2075. saveq->iocb.ulpContext);
  2076. }
  2077. }
  2078. return rc;
  2079. }
  2080. /**
  2081. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2082. * @phba: Pointer to HBA context object.
  2083. * @pring: Pointer to driver SLI ring object.
  2084. *
  2085. * This function is called from the iocb ring event handlers when
  2086. * put pointer is ahead of the get pointer for a ring. This function signal
  2087. * an error attention condition to the worker thread and the worker
  2088. * thread will transition the HBA to offline state.
  2089. **/
  2090. static void
  2091. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2092. {
  2093. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2094. /*
  2095. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2096. * rsp ring <portRspMax>
  2097. */
  2098. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2099. "0312 Ring %d handler: portRspPut %d "
  2100. "is bigger than rsp ring %d\n",
  2101. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2102. pring->numRiocb);
  2103. phba->link_state = LPFC_HBA_ERROR;
  2104. /*
  2105. * All error attention handlers are posted to
  2106. * worker thread
  2107. */
  2108. phba->work_ha |= HA_ERATT;
  2109. phba->work_hs = HS_FFER3;
  2110. lpfc_worker_wake_up(phba);
  2111. return;
  2112. }
  2113. /**
  2114. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2115. * @ptr: Pointer to address of HBA context object.
  2116. *
  2117. * This function is invoked by the Error Attention polling timer when the
  2118. * timer times out. It will check the SLI Error Attention register for
  2119. * possible attention events. If so, it will post an Error Attention event
  2120. * and wake up worker thread to process it. Otherwise, it will set up the
  2121. * Error Attention polling timer for the next poll.
  2122. **/
  2123. void lpfc_poll_eratt(unsigned long ptr)
  2124. {
  2125. struct lpfc_hba *phba;
  2126. uint32_t eratt = 0;
  2127. phba = (struct lpfc_hba *)ptr;
  2128. /* Check chip HA register for error event */
  2129. eratt = lpfc_sli_check_eratt(phba);
  2130. if (eratt)
  2131. /* Tell the worker thread there is work to do */
  2132. lpfc_worker_wake_up(phba);
  2133. else
  2134. /* Restart the timer for next eratt poll */
  2135. mod_timer(&phba->eratt_poll, jiffies +
  2136. HZ * LPFC_ERATT_POLL_INTERVAL);
  2137. return;
  2138. }
  2139. /**
  2140. * lpfc_sli_poll_fcp_ring - Handle FCP ring completion in polling mode
  2141. * @phba: Pointer to HBA context object.
  2142. *
  2143. * This function is called from lpfc_queuecommand, lpfc_poll_timeout,
  2144. * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING
  2145. * is enabled.
  2146. *
  2147. * The caller does not hold any lock.
  2148. * The function processes each response iocb in the response ring until it
  2149. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2150. * LE bit set. The function will call the completion handler of the command iocb
  2151. * if the response iocb indicates a completion for a command iocb or it is
  2152. * an abort completion.
  2153. **/
  2154. void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
  2155. {
  2156. struct lpfc_sli *psli = &phba->sli;
  2157. struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
  2158. IOCB_t *irsp = NULL;
  2159. IOCB_t *entry = NULL;
  2160. struct lpfc_iocbq *cmdiocbq = NULL;
  2161. struct lpfc_iocbq rspiocbq;
  2162. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2163. uint32_t status;
  2164. uint32_t portRspPut, portRspMax;
  2165. int type;
  2166. uint32_t rsp_cmpl = 0;
  2167. uint32_t ha_copy;
  2168. unsigned long iflags;
  2169. pring->stats.iocb_event++;
  2170. /*
  2171. * The next available response entry should never exceed the maximum
  2172. * entries. If it does, treat it as an adapter hardware error.
  2173. */
  2174. portRspMax = pring->numRiocb;
  2175. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2176. if (unlikely(portRspPut >= portRspMax)) {
  2177. lpfc_sli_rsp_pointers_error(phba, pring);
  2178. return;
  2179. }
  2180. rmb();
  2181. while (pring->rspidx != portRspPut) {
  2182. entry = lpfc_resp_iocb(phba, pring);
  2183. if (++pring->rspidx >= portRspMax)
  2184. pring->rspidx = 0;
  2185. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2186. (uint32_t *) &rspiocbq.iocb,
  2187. phba->iocb_rsp_size);
  2188. irsp = &rspiocbq.iocb;
  2189. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2190. pring->stats.iocb_rsp++;
  2191. rsp_cmpl++;
  2192. if (unlikely(irsp->ulpStatus)) {
  2193. /* Rsp ring <ringno> error: IOCB */
  2194. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2195. "0326 Rsp Ring %d error: IOCB Data: "
  2196. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2197. pring->ringno,
  2198. irsp->un.ulpWord[0],
  2199. irsp->un.ulpWord[1],
  2200. irsp->un.ulpWord[2],
  2201. irsp->un.ulpWord[3],
  2202. irsp->un.ulpWord[4],
  2203. irsp->un.ulpWord[5],
  2204. *(uint32_t *)&irsp->un1,
  2205. *((uint32_t *)&irsp->un1 + 1));
  2206. }
  2207. switch (type) {
  2208. case LPFC_ABORT_IOCB:
  2209. case LPFC_SOL_IOCB:
  2210. /*
  2211. * Idle exchange closed via ABTS from port. No iocb
  2212. * resources need to be recovered.
  2213. */
  2214. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2215. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2216. "0314 IOCB cmd 0x%x "
  2217. "processed. Skipping "
  2218. "completion",
  2219. irsp->ulpCommand);
  2220. break;
  2221. }
  2222. spin_lock_irqsave(&phba->hbalock, iflags);
  2223. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2224. &rspiocbq);
  2225. spin_unlock_irqrestore(&phba->hbalock, iflags);
  2226. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  2227. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2228. &rspiocbq);
  2229. }
  2230. break;
  2231. default:
  2232. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2233. char adaptermsg[LPFC_MAX_ADPTMSG];
  2234. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2235. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2236. MAX_MSG_DATA);
  2237. dev_warn(&((phba->pcidev)->dev),
  2238. "lpfc%d: %s\n",
  2239. phba->brd_no, adaptermsg);
  2240. } else {
  2241. /* Unknown IOCB command */
  2242. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2243. "0321 Unknown IOCB command "
  2244. "Data: x%x, x%x x%x x%x x%x\n",
  2245. type, irsp->ulpCommand,
  2246. irsp->ulpStatus,
  2247. irsp->ulpIoTag,
  2248. irsp->ulpContext);
  2249. }
  2250. break;
  2251. }
  2252. /*
  2253. * The response IOCB has been processed. Update the ring
  2254. * pointer in SLIM. If the port response put pointer has not
  2255. * been updated, sync the pgp->rspPutInx and fetch the new port
  2256. * response put pointer.
  2257. */
  2258. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2259. if (pring->rspidx == portRspPut)
  2260. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2261. }
  2262. ha_copy = readl(phba->HAregaddr);
  2263. ha_copy >>= (LPFC_FCP_RING * 4);
  2264. if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
  2265. spin_lock_irqsave(&phba->hbalock, iflags);
  2266. pring->stats.iocb_rsp_full++;
  2267. status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
  2268. writel(status, phba->CAregaddr);
  2269. readl(phba->CAregaddr);
  2270. spin_unlock_irqrestore(&phba->hbalock, iflags);
  2271. }
  2272. if ((ha_copy & HA_R0CE_RSP) &&
  2273. (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2274. spin_lock_irqsave(&phba->hbalock, iflags);
  2275. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2276. pring->stats.iocb_cmd_empty++;
  2277. /* Force update of the local copy of cmdGetInx */
  2278. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2279. lpfc_sli_resume_iocb(phba, pring);
  2280. if ((pring->lpfc_sli_cmd_available))
  2281. (pring->lpfc_sli_cmd_available) (phba, pring);
  2282. spin_unlock_irqrestore(&phba->hbalock, iflags);
  2283. }
  2284. return;
  2285. }
  2286. /**
  2287. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2288. * @phba: Pointer to HBA context object.
  2289. * @pring: Pointer to driver SLI ring object.
  2290. * @mask: Host attention register mask for this ring.
  2291. *
  2292. * This function is called from the interrupt context when there is a ring
  2293. * event for the fcp ring. The caller does not hold any lock.
  2294. * The function processes each response iocb in the response ring until it
  2295. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2296. * LE bit set. The function will call the completion handler of the command iocb
  2297. * if the response iocb indicates a completion for a command iocb or it is
  2298. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2299. * function if this is an unsolicited iocb.
  2300. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2301. * to check it explicitly. This function always returns 1.
  2302. **/
  2303. static int
  2304. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2305. struct lpfc_sli_ring *pring, uint32_t mask)
  2306. {
  2307. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2308. IOCB_t *irsp = NULL;
  2309. IOCB_t *entry = NULL;
  2310. struct lpfc_iocbq *cmdiocbq = NULL;
  2311. struct lpfc_iocbq rspiocbq;
  2312. uint32_t status;
  2313. uint32_t portRspPut, portRspMax;
  2314. int rc = 1;
  2315. lpfc_iocb_type type;
  2316. unsigned long iflag;
  2317. uint32_t rsp_cmpl = 0;
  2318. spin_lock_irqsave(&phba->hbalock, iflag);
  2319. pring->stats.iocb_event++;
  2320. /*
  2321. * The next available response entry should never exceed the maximum
  2322. * entries. If it does, treat it as an adapter hardware error.
  2323. */
  2324. portRspMax = pring->numRiocb;
  2325. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2326. if (unlikely(portRspPut >= portRspMax)) {
  2327. lpfc_sli_rsp_pointers_error(phba, pring);
  2328. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2329. return 1;
  2330. }
  2331. rmb();
  2332. while (pring->rspidx != portRspPut) {
  2333. /*
  2334. * Fetch an entry off the ring and copy it into a local data
  2335. * structure. The copy involves a byte-swap since the
  2336. * network byte order and pci byte orders are different.
  2337. */
  2338. entry = lpfc_resp_iocb(phba, pring);
  2339. phba->last_completion_time = jiffies;
  2340. if (++pring->rspidx >= portRspMax)
  2341. pring->rspidx = 0;
  2342. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2343. (uint32_t *) &rspiocbq.iocb,
  2344. phba->iocb_rsp_size);
  2345. INIT_LIST_HEAD(&(rspiocbq.list));
  2346. irsp = &rspiocbq.iocb;
  2347. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2348. pring->stats.iocb_rsp++;
  2349. rsp_cmpl++;
  2350. if (unlikely(irsp->ulpStatus)) {
  2351. /*
  2352. * If resource errors reported from HBA, reduce
  2353. * queuedepths of the SCSI device.
  2354. */
  2355. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2356. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2357. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2358. phba->lpfc_rampdown_queue_depth(phba);
  2359. spin_lock_irqsave(&phba->hbalock, iflag);
  2360. }
  2361. /* Rsp ring <ringno> error: IOCB */
  2362. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2363. "0336 Rsp Ring %d error: IOCB Data: "
  2364. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2365. pring->ringno,
  2366. irsp->un.ulpWord[0],
  2367. irsp->un.ulpWord[1],
  2368. irsp->un.ulpWord[2],
  2369. irsp->un.ulpWord[3],
  2370. irsp->un.ulpWord[4],
  2371. irsp->un.ulpWord[5],
  2372. *(uint32_t *)&irsp->un1,
  2373. *((uint32_t *)&irsp->un1 + 1));
  2374. }
  2375. switch (type) {
  2376. case LPFC_ABORT_IOCB:
  2377. case LPFC_SOL_IOCB:
  2378. /*
  2379. * Idle exchange closed via ABTS from port. No iocb
  2380. * resources need to be recovered.
  2381. */
  2382. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2383. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2384. "0333 IOCB cmd 0x%x"
  2385. " processed. Skipping"
  2386. " completion\n",
  2387. irsp->ulpCommand);
  2388. break;
  2389. }
  2390. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2391. &rspiocbq);
  2392. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  2393. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  2394. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2395. &rspiocbq);
  2396. } else {
  2397. spin_unlock_irqrestore(&phba->hbalock,
  2398. iflag);
  2399. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2400. &rspiocbq);
  2401. spin_lock_irqsave(&phba->hbalock,
  2402. iflag);
  2403. }
  2404. }
  2405. break;
  2406. case LPFC_UNSOL_IOCB:
  2407. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2408. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2409. spin_lock_irqsave(&phba->hbalock, iflag);
  2410. break;
  2411. default:
  2412. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2413. char adaptermsg[LPFC_MAX_ADPTMSG];
  2414. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2415. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2416. MAX_MSG_DATA);
  2417. dev_warn(&((phba->pcidev)->dev),
  2418. "lpfc%d: %s\n",
  2419. phba->brd_no, adaptermsg);
  2420. } else {
  2421. /* Unknown IOCB command */
  2422. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2423. "0334 Unknown IOCB command "
  2424. "Data: x%x, x%x x%x x%x x%x\n",
  2425. type, irsp->ulpCommand,
  2426. irsp->ulpStatus,
  2427. irsp->ulpIoTag,
  2428. irsp->ulpContext);
  2429. }
  2430. break;
  2431. }
  2432. /*
  2433. * The response IOCB has been processed. Update the ring
  2434. * pointer in SLIM. If the port response put pointer has not
  2435. * been updated, sync the pgp->rspPutInx and fetch the new port
  2436. * response put pointer.
  2437. */
  2438. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2439. if (pring->rspidx == portRspPut)
  2440. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2441. }
  2442. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2443. pring->stats.iocb_rsp_full++;
  2444. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2445. writel(status, phba->CAregaddr);
  2446. readl(phba->CAregaddr);
  2447. }
  2448. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2449. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2450. pring->stats.iocb_cmd_empty++;
  2451. /* Force update of the local copy of cmdGetInx */
  2452. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2453. lpfc_sli_resume_iocb(phba, pring);
  2454. if ((pring->lpfc_sli_cmd_available))
  2455. (pring->lpfc_sli_cmd_available) (phba, pring);
  2456. }
  2457. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2458. return rc;
  2459. }
  2460. /**
  2461. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2462. * @phba: Pointer to HBA context object.
  2463. * @pring: Pointer to driver SLI ring object.
  2464. * @rspiocbp: Pointer to driver response IOCB object.
  2465. *
  2466. * This function is called from the worker thread when there is a slow-path
  2467. * response IOCB to process. This function chains all the response iocbs until
  2468. * seeing the iocb with the LE bit set. The function will call
  2469. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2470. * completion of a command iocb. The function will call the
  2471. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2472. * The function frees the resources or calls the completion handler if this
  2473. * iocb is an abort completion. The function returns NULL when the response
  2474. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2475. * this function shall chain the iocb on to the iocb_continueq and return the
  2476. * response iocb passed in.
  2477. **/
  2478. static struct lpfc_iocbq *
  2479. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2480. struct lpfc_iocbq *rspiocbp)
  2481. {
  2482. struct lpfc_iocbq *saveq;
  2483. struct lpfc_iocbq *cmdiocbp;
  2484. struct lpfc_iocbq *next_iocb;
  2485. IOCB_t *irsp = NULL;
  2486. uint32_t free_saveq;
  2487. uint8_t iocb_cmd_type;
  2488. lpfc_iocb_type type;
  2489. unsigned long iflag;
  2490. int rc;
  2491. spin_lock_irqsave(&phba->hbalock, iflag);
  2492. /* First add the response iocb to the countinueq list */
  2493. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2494. pring->iocb_continueq_cnt++;
  2495. /* Now, determine whetehr the list is completed for processing */
  2496. irsp = &rspiocbp->iocb;
  2497. if (irsp->ulpLe) {
  2498. /*
  2499. * By default, the driver expects to free all resources
  2500. * associated with this iocb completion.
  2501. */
  2502. free_saveq = 1;
  2503. saveq = list_get_first(&pring->iocb_continueq,
  2504. struct lpfc_iocbq, list);
  2505. irsp = &(saveq->iocb);
  2506. list_del_init(&pring->iocb_continueq);
  2507. pring->iocb_continueq_cnt = 0;
  2508. pring->stats.iocb_rsp++;
  2509. /*
  2510. * If resource errors reported from HBA, reduce
  2511. * queuedepths of the SCSI device.
  2512. */
  2513. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2514. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2515. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2516. phba->lpfc_rampdown_queue_depth(phba);
  2517. spin_lock_irqsave(&phba->hbalock, iflag);
  2518. }
  2519. if (irsp->ulpStatus) {
  2520. /* Rsp ring <ringno> error: IOCB */
  2521. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2522. "0328 Rsp Ring %d error: "
  2523. "IOCB Data: "
  2524. "x%x x%x x%x x%x "
  2525. "x%x x%x x%x x%x "
  2526. "x%x x%x x%x x%x "
  2527. "x%x x%x x%x x%x\n",
  2528. pring->ringno,
  2529. irsp->un.ulpWord[0],
  2530. irsp->un.ulpWord[1],
  2531. irsp->un.ulpWord[2],
  2532. irsp->un.ulpWord[3],
  2533. irsp->un.ulpWord[4],
  2534. irsp->un.ulpWord[5],
  2535. *(((uint32_t *) irsp) + 6),
  2536. *(((uint32_t *) irsp) + 7),
  2537. *(((uint32_t *) irsp) + 8),
  2538. *(((uint32_t *) irsp) + 9),
  2539. *(((uint32_t *) irsp) + 10),
  2540. *(((uint32_t *) irsp) + 11),
  2541. *(((uint32_t *) irsp) + 12),
  2542. *(((uint32_t *) irsp) + 13),
  2543. *(((uint32_t *) irsp) + 14),
  2544. *(((uint32_t *) irsp) + 15));
  2545. }
  2546. /*
  2547. * Fetch the IOCB command type and call the correct completion
  2548. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2549. * get freed back to the lpfc_iocb_list by the discovery
  2550. * kernel thread.
  2551. */
  2552. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2553. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2554. switch (type) {
  2555. case LPFC_SOL_IOCB:
  2556. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2557. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2558. spin_lock_irqsave(&phba->hbalock, iflag);
  2559. break;
  2560. case LPFC_UNSOL_IOCB:
  2561. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2562. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2563. spin_lock_irqsave(&phba->hbalock, iflag);
  2564. if (!rc)
  2565. free_saveq = 0;
  2566. break;
  2567. case LPFC_ABORT_IOCB:
  2568. cmdiocbp = NULL;
  2569. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2570. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2571. saveq);
  2572. if (cmdiocbp) {
  2573. /* Call the specified completion routine */
  2574. if (cmdiocbp->iocb_cmpl) {
  2575. spin_unlock_irqrestore(&phba->hbalock,
  2576. iflag);
  2577. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2578. saveq);
  2579. spin_lock_irqsave(&phba->hbalock,
  2580. iflag);
  2581. } else
  2582. __lpfc_sli_release_iocbq(phba,
  2583. cmdiocbp);
  2584. }
  2585. break;
  2586. case LPFC_UNKNOWN_IOCB:
  2587. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2588. char adaptermsg[LPFC_MAX_ADPTMSG];
  2589. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2590. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2591. MAX_MSG_DATA);
  2592. dev_warn(&((phba->pcidev)->dev),
  2593. "lpfc%d: %s\n",
  2594. phba->brd_no, adaptermsg);
  2595. } else {
  2596. /* Unknown IOCB command */
  2597. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2598. "0335 Unknown IOCB "
  2599. "command Data: x%x "
  2600. "x%x x%x x%x\n",
  2601. irsp->ulpCommand,
  2602. irsp->ulpStatus,
  2603. irsp->ulpIoTag,
  2604. irsp->ulpContext);
  2605. }
  2606. break;
  2607. }
  2608. if (free_saveq) {
  2609. list_for_each_entry_safe(rspiocbp, next_iocb,
  2610. &saveq->list, list) {
  2611. list_del(&rspiocbp->list);
  2612. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2613. }
  2614. __lpfc_sli_release_iocbq(phba, saveq);
  2615. }
  2616. rspiocbp = NULL;
  2617. }
  2618. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2619. return rspiocbp;
  2620. }
  2621. /**
  2622. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2623. * @phba: Pointer to HBA context object.
  2624. * @pring: Pointer to driver SLI ring object.
  2625. * @mask: Host attention register mask for this ring.
  2626. *
  2627. * This routine wraps the actual slow_ring event process routine from the
  2628. * API jump table function pointer from the lpfc_hba struct.
  2629. **/
  2630. void
  2631. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2632. struct lpfc_sli_ring *pring, uint32_t mask)
  2633. {
  2634. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2635. }
  2636. /**
  2637. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2638. * @phba: Pointer to HBA context object.
  2639. * @pring: Pointer to driver SLI ring object.
  2640. * @mask: Host attention register mask for this ring.
  2641. *
  2642. * This function is called from the worker thread when there is a ring event
  2643. * for non-fcp rings. The caller does not hold any lock. The function will
  2644. * remove each response iocb in the response ring and calls the handle
  2645. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2646. **/
  2647. static void
  2648. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2649. struct lpfc_sli_ring *pring, uint32_t mask)
  2650. {
  2651. struct lpfc_pgp *pgp;
  2652. IOCB_t *entry;
  2653. IOCB_t *irsp = NULL;
  2654. struct lpfc_iocbq *rspiocbp = NULL;
  2655. uint32_t portRspPut, portRspMax;
  2656. unsigned long iflag;
  2657. uint32_t status;
  2658. pgp = &phba->port_gp[pring->ringno];
  2659. spin_lock_irqsave(&phba->hbalock, iflag);
  2660. pring->stats.iocb_event++;
  2661. /*
  2662. * The next available response entry should never exceed the maximum
  2663. * entries. If it does, treat it as an adapter hardware error.
  2664. */
  2665. portRspMax = pring->numRiocb;
  2666. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2667. if (portRspPut >= portRspMax) {
  2668. /*
  2669. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2670. * rsp ring <portRspMax>
  2671. */
  2672. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2673. "0303 Ring %d handler: portRspPut %d "
  2674. "is bigger than rsp ring %d\n",
  2675. pring->ringno, portRspPut, portRspMax);
  2676. phba->link_state = LPFC_HBA_ERROR;
  2677. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2678. phba->work_hs = HS_FFER3;
  2679. lpfc_handle_eratt(phba);
  2680. return;
  2681. }
  2682. rmb();
  2683. while (pring->rspidx != portRspPut) {
  2684. /*
  2685. * Build a completion list and call the appropriate handler.
  2686. * The process is to get the next available response iocb, get
  2687. * a free iocb from the list, copy the response data into the
  2688. * free iocb, insert to the continuation list, and update the
  2689. * next response index to slim. This process makes response
  2690. * iocb's in the ring available to DMA as fast as possible but
  2691. * pays a penalty for a copy operation. Since the iocb is
  2692. * only 32 bytes, this penalty is considered small relative to
  2693. * the PCI reads for register values and a slim write. When
  2694. * the ulpLe field is set, the entire Command has been
  2695. * received.
  2696. */
  2697. entry = lpfc_resp_iocb(phba, pring);
  2698. phba->last_completion_time = jiffies;
  2699. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2700. if (rspiocbp == NULL) {
  2701. printk(KERN_ERR "%s: out of buffers! Failing "
  2702. "completion.\n", __func__);
  2703. break;
  2704. }
  2705. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2706. phba->iocb_rsp_size);
  2707. irsp = &rspiocbp->iocb;
  2708. if (++pring->rspidx >= portRspMax)
  2709. pring->rspidx = 0;
  2710. if (pring->ringno == LPFC_ELS_RING) {
  2711. lpfc_debugfs_slow_ring_trc(phba,
  2712. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2713. *(((uint32_t *) irsp) + 4),
  2714. *(((uint32_t *) irsp) + 6),
  2715. *(((uint32_t *) irsp) + 7));
  2716. }
  2717. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2718. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2719. /* Handle the response IOCB */
  2720. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2721. spin_lock_irqsave(&phba->hbalock, iflag);
  2722. /*
  2723. * If the port response put pointer has not been updated, sync
  2724. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2725. * response put pointer.
  2726. */
  2727. if (pring->rspidx == portRspPut) {
  2728. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2729. }
  2730. } /* while (pring->rspidx != portRspPut) */
  2731. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2732. /* At least one response entry has been freed */
  2733. pring->stats.iocb_rsp_full++;
  2734. /* SET RxRE_RSP in Chip Att register */
  2735. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2736. writel(status, phba->CAregaddr);
  2737. readl(phba->CAregaddr); /* flush */
  2738. }
  2739. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2740. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2741. pring->stats.iocb_cmd_empty++;
  2742. /* Force update of the local copy of cmdGetInx */
  2743. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2744. lpfc_sli_resume_iocb(phba, pring);
  2745. if ((pring->lpfc_sli_cmd_available))
  2746. (pring->lpfc_sli_cmd_available) (phba, pring);
  2747. }
  2748. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2749. return;
  2750. }
  2751. /**
  2752. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2753. * @phba: Pointer to HBA context object.
  2754. * @pring: Pointer to driver SLI ring object.
  2755. * @mask: Host attention register mask for this ring.
  2756. *
  2757. * This function is called from the worker thread when there is a pending
  2758. * ELS response iocb on the driver internal slow-path response iocb worker
  2759. * queue. The caller does not hold any lock. The function will remove each
  2760. * response iocb from the response worker queue and calls the handle
  2761. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2762. **/
  2763. static void
  2764. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2765. struct lpfc_sli_ring *pring, uint32_t mask)
  2766. {
  2767. struct lpfc_iocbq *irspiocbq;
  2768. struct hbq_dmabuf *dmabuf;
  2769. struct lpfc_cq_event *cq_event;
  2770. unsigned long iflag;
  2771. while (!list_empty(&phba->sli4_hba.sp_rspiocb_work_queue)) {
  2772. /* Get the response iocb from the head of work queue */
  2773. spin_lock_irqsave(&phba->hbalock, iflag);
  2774. list_remove_head(&phba->sli4_hba.sp_rspiocb_work_queue,
  2775. cq_event, struct lpfc_cq_event, list);
  2776. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2777. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  2778. case CQE_CODE_COMPL_WQE:
  2779. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  2780. cq_event);
  2781. lpfc_sli_sp_handle_rspiocb(phba, pring, irspiocbq);
  2782. break;
  2783. case CQE_CODE_RECEIVE:
  2784. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  2785. cq_event);
  2786. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  2787. break;
  2788. default:
  2789. break;
  2790. }
  2791. }
  2792. }
  2793. /**
  2794. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2795. * @phba: Pointer to HBA context object.
  2796. * @pring: Pointer to driver SLI ring object.
  2797. *
  2798. * This function aborts all iocbs in the given ring and frees all the iocb
  2799. * objects in txq. This function issues an abort iocb for all the iocb commands
  2800. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2801. * the return of this function. The caller is not required to hold any locks.
  2802. **/
  2803. void
  2804. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2805. {
  2806. LIST_HEAD(completions);
  2807. struct lpfc_iocbq *iocb, *next_iocb;
  2808. if (pring->ringno == LPFC_ELS_RING) {
  2809. lpfc_fabric_abort_hba(phba);
  2810. }
  2811. /* Error everything on txq and txcmplq
  2812. * First do the txq.
  2813. */
  2814. spin_lock_irq(&phba->hbalock);
  2815. list_splice_init(&pring->txq, &completions);
  2816. pring->txq_cnt = 0;
  2817. /* Next issue ABTS for everything on the txcmplq */
  2818. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2819. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2820. spin_unlock_irq(&phba->hbalock);
  2821. /* Cancel all the IOCBs from the completions list */
  2822. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2823. IOERR_SLI_ABORTED);
  2824. }
  2825. /**
  2826. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2827. * @phba: Pointer to HBA context object.
  2828. *
  2829. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2830. * objects in txq and txcmplq. This function will not issue abort iocbs
  2831. * for all the iocb commands in txcmplq, they will just be returned with
  2832. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2833. * slot has been permanently disabled.
  2834. **/
  2835. void
  2836. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2837. {
  2838. LIST_HEAD(txq);
  2839. LIST_HEAD(txcmplq);
  2840. struct lpfc_sli *psli = &phba->sli;
  2841. struct lpfc_sli_ring *pring;
  2842. /* Currently, only one fcp ring */
  2843. pring = &psli->ring[psli->fcp_ring];
  2844. spin_lock_irq(&phba->hbalock);
  2845. /* Retrieve everything on txq */
  2846. list_splice_init(&pring->txq, &txq);
  2847. pring->txq_cnt = 0;
  2848. /* Retrieve everything on the txcmplq */
  2849. list_splice_init(&pring->txcmplq, &txcmplq);
  2850. pring->txcmplq_cnt = 0;
  2851. spin_unlock_irq(&phba->hbalock);
  2852. /* Flush the txq */
  2853. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2854. IOERR_SLI_DOWN);
  2855. /* Flush the txcmpq */
  2856. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2857. IOERR_SLI_DOWN);
  2858. }
  2859. /**
  2860. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2861. * @phba: Pointer to HBA context object.
  2862. * @mask: Bit mask to be checked.
  2863. *
  2864. * This function reads the host status register and compares
  2865. * with the provided bit mask to check if HBA completed
  2866. * the restart. This function will wait in a loop for the
  2867. * HBA to complete restart. If the HBA does not restart within
  2868. * 15 iterations, the function will reset the HBA again. The
  2869. * function returns 1 when HBA fail to restart otherwise returns
  2870. * zero.
  2871. **/
  2872. static int
  2873. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2874. {
  2875. uint32_t status;
  2876. int i = 0;
  2877. int retval = 0;
  2878. /* Read the HBA Host Status Register */
  2879. status = readl(phba->HSregaddr);
  2880. /*
  2881. * Check status register every 100ms for 5 retries, then every
  2882. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2883. * every 2.5 sec for 4.
  2884. * Break our of the loop if errors occurred during init.
  2885. */
  2886. while (((status & mask) != mask) &&
  2887. !(status & HS_FFERM) &&
  2888. i++ < 20) {
  2889. if (i <= 5)
  2890. msleep(10);
  2891. else if (i <= 10)
  2892. msleep(500);
  2893. else
  2894. msleep(2500);
  2895. if (i == 15) {
  2896. /* Do post */
  2897. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2898. lpfc_sli_brdrestart(phba);
  2899. }
  2900. /* Read the HBA Host Status Register */
  2901. status = readl(phba->HSregaddr);
  2902. }
  2903. /* Check to see if any errors occurred during init */
  2904. if ((status & HS_FFERM) || (i >= 20)) {
  2905. phba->link_state = LPFC_HBA_ERROR;
  2906. retval = 1;
  2907. }
  2908. return retval;
  2909. }
  2910. /**
  2911. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2912. * @phba: Pointer to HBA context object.
  2913. * @mask: Bit mask to be checked.
  2914. *
  2915. * This function checks the host status register to check if HBA is
  2916. * ready. This function will wait in a loop for the HBA to be ready
  2917. * If the HBA is not ready , the function will will reset the HBA PCI
  2918. * function again. The function returns 1 when HBA fail to be ready
  2919. * otherwise returns zero.
  2920. **/
  2921. static int
  2922. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2923. {
  2924. uint32_t status;
  2925. int retval = 0;
  2926. /* Read the HBA Host Status Register */
  2927. status = lpfc_sli4_post_status_check(phba);
  2928. if (status) {
  2929. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2930. lpfc_sli_brdrestart(phba);
  2931. status = lpfc_sli4_post_status_check(phba);
  2932. }
  2933. /* Check to see if any errors occurred during init */
  2934. if (status) {
  2935. phba->link_state = LPFC_HBA_ERROR;
  2936. retval = 1;
  2937. } else
  2938. phba->sli4_hba.intr_enable = 0;
  2939. return retval;
  2940. }
  2941. /**
  2942. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2943. * @phba: Pointer to HBA context object.
  2944. * @mask: Bit mask to be checked.
  2945. *
  2946. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2947. * from the API jump table function pointer from the lpfc_hba struct.
  2948. **/
  2949. int
  2950. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2951. {
  2952. return phba->lpfc_sli_brdready(phba, mask);
  2953. }
  2954. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2955. /**
  2956. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2957. * @phba: Pointer to HBA context object.
  2958. *
  2959. * This function is called before resetting an HBA. This
  2960. * function requests HBA to quiesce DMAs before a reset.
  2961. **/
  2962. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2963. {
  2964. uint32_t __iomem *resp_buf;
  2965. uint32_t __iomem *mbox_buf;
  2966. volatile uint32_t mbox;
  2967. uint32_t hc_copy;
  2968. int i;
  2969. uint8_t hdrtype;
  2970. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2971. if (hdrtype != 0x80 ||
  2972. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2973. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2974. return;
  2975. /*
  2976. * Tell the other part of the chip to suspend temporarily all
  2977. * its DMA activity.
  2978. */
  2979. resp_buf = phba->MBslimaddr;
  2980. /* Disable the error attention */
  2981. hc_copy = readl(phba->HCregaddr);
  2982. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2983. readl(phba->HCregaddr); /* flush */
  2984. phba->link_flag |= LS_IGNORE_ERATT;
  2985. if (readl(phba->HAregaddr) & HA_ERATT) {
  2986. /* Clear Chip error bit */
  2987. writel(HA_ERATT, phba->HAregaddr);
  2988. phba->pport->stopped = 1;
  2989. }
  2990. mbox = 0;
  2991. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2992. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2993. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2994. mbox_buf = phba->MBslimaddr;
  2995. writel(mbox, mbox_buf);
  2996. for (i = 0;
  2997. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2998. mdelay(1);
  2999. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  3000. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3001. phba->pport->stopped)
  3002. goto restore_hc;
  3003. else
  3004. goto clear_errat;
  3005. }
  3006. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3007. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  3008. mdelay(1);
  3009. clear_errat:
  3010. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  3011. mdelay(1);
  3012. if (readl(phba->HAregaddr) & HA_ERATT) {
  3013. writel(HA_ERATT, phba->HAregaddr);
  3014. phba->pport->stopped = 1;
  3015. }
  3016. restore_hc:
  3017. phba->link_flag &= ~LS_IGNORE_ERATT;
  3018. writel(hc_copy, phba->HCregaddr);
  3019. readl(phba->HCregaddr); /* flush */
  3020. }
  3021. /**
  3022. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3023. * @phba: Pointer to HBA context object.
  3024. *
  3025. * This function issues a kill_board mailbox command and waits for
  3026. * the error attention interrupt. This function is called for stopping
  3027. * the firmware processing. The caller is not required to hold any
  3028. * locks. This function calls lpfc_hba_down_post function to free
  3029. * any pending commands after the kill. The function will return 1 when it
  3030. * fails to kill the board else will return 0.
  3031. **/
  3032. int
  3033. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3034. {
  3035. struct lpfc_sli *psli;
  3036. LPFC_MBOXQ_t *pmb;
  3037. uint32_t status;
  3038. uint32_t ha_copy;
  3039. int retval;
  3040. int i = 0;
  3041. psli = &phba->sli;
  3042. /* Kill HBA */
  3043. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3044. "0329 Kill HBA Data: x%x x%x\n",
  3045. phba->pport->port_state, psli->sli_flag);
  3046. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3047. if (!pmb)
  3048. return 1;
  3049. /* Disable the error attention */
  3050. spin_lock_irq(&phba->hbalock);
  3051. status = readl(phba->HCregaddr);
  3052. status &= ~HC_ERINT_ENA;
  3053. writel(status, phba->HCregaddr);
  3054. readl(phba->HCregaddr); /* flush */
  3055. phba->link_flag |= LS_IGNORE_ERATT;
  3056. spin_unlock_irq(&phba->hbalock);
  3057. lpfc_kill_board(phba, pmb);
  3058. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3059. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3060. if (retval != MBX_SUCCESS) {
  3061. if (retval != MBX_BUSY)
  3062. mempool_free(pmb, phba->mbox_mem_pool);
  3063. spin_lock_irq(&phba->hbalock);
  3064. phba->link_flag &= ~LS_IGNORE_ERATT;
  3065. spin_unlock_irq(&phba->hbalock);
  3066. return 1;
  3067. }
  3068. spin_lock_irq(&phba->hbalock);
  3069. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3070. spin_unlock_irq(&phba->hbalock);
  3071. mempool_free(pmb, phba->mbox_mem_pool);
  3072. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3073. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3074. * 3 seconds we still set HBA_ERROR state because the status of the
  3075. * board is now undefined.
  3076. */
  3077. ha_copy = readl(phba->HAregaddr);
  3078. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3079. mdelay(100);
  3080. ha_copy = readl(phba->HAregaddr);
  3081. }
  3082. del_timer_sync(&psli->mbox_tmo);
  3083. if (ha_copy & HA_ERATT) {
  3084. writel(HA_ERATT, phba->HAregaddr);
  3085. phba->pport->stopped = 1;
  3086. }
  3087. spin_lock_irq(&phba->hbalock);
  3088. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3089. psli->mbox_active = NULL;
  3090. phba->link_flag &= ~LS_IGNORE_ERATT;
  3091. spin_unlock_irq(&phba->hbalock);
  3092. lpfc_hba_down_post(phba);
  3093. phba->link_state = LPFC_HBA_ERROR;
  3094. return ha_copy & HA_ERATT ? 0 : 1;
  3095. }
  3096. /**
  3097. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3098. * @phba: Pointer to HBA context object.
  3099. *
  3100. * This function resets the HBA by writing HC_INITFF to the control
  3101. * register. After the HBA resets, this function resets all the iocb ring
  3102. * indices. This function disables PCI layer parity checking during
  3103. * the reset.
  3104. * This function returns 0 always.
  3105. * The caller is not required to hold any locks.
  3106. **/
  3107. int
  3108. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3109. {
  3110. struct lpfc_sli *psli;
  3111. struct lpfc_sli_ring *pring;
  3112. uint16_t cfg_value;
  3113. int i;
  3114. psli = &phba->sli;
  3115. /* Reset HBA */
  3116. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3117. "0325 Reset HBA Data: x%x x%x\n",
  3118. phba->pport->port_state, psli->sli_flag);
  3119. /* perform board reset */
  3120. phba->fc_eventTag = 0;
  3121. phba->link_events = 0;
  3122. phba->pport->fc_myDID = 0;
  3123. phba->pport->fc_prevDID = 0;
  3124. /* Turn off parity checking and serr during the physical reset */
  3125. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3126. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3127. (cfg_value &
  3128. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3129. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3130. /* Now toggle INITFF bit in the Host Control Register */
  3131. writel(HC_INITFF, phba->HCregaddr);
  3132. mdelay(1);
  3133. readl(phba->HCregaddr); /* flush */
  3134. writel(0, phba->HCregaddr);
  3135. readl(phba->HCregaddr); /* flush */
  3136. /* Restore PCI cmd register */
  3137. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3138. /* Initialize relevant SLI info */
  3139. for (i = 0; i < psli->num_rings; i++) {
  3140. pring = &psli->ring[i];
  3141. pring->flag = 0;
  3142. pring->rspidx = 0;
  3143. pring->next_cmdidx = 0;
  3144. pring->local_getidx = 0;
  3145. pring->cmdidx = 0;
  3146. pring->missbufcnt = 0;
  3147. }
  3148. phba->link_state = LPFC_WARM_START;
  3149. return 0;
  3150. }
  3151. /**
  3152. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3153. * @phba: Pointer to HBA context object.
  3154. *
  3155. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3156. * checking during resets the device. The caller is not required to hold
  3157. * any locks.
  3158. *
  3159. * This function returns 0 always.
  3160. **/
  3161. int
  3162. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3163. {
  3164. struct lpfc_sli *psli = &phba->sli;
  3165. uint16_t cfg_value;
  3166. uint8_t qindx;
  3167. /* Reset HBA */
  3168. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3169. "0295 Reset HBA Data: x%x x%x\n",
  3170. phba->pport->port_state, psli->sli_flag);
  3171. /* perform board reset */
  3172. phba->fc_eventTag = 0;
  3173. phba->link_events = 0;
  3174. phba->pport->fc_myDID = 0;
  3175. phba->pport->fc_prevDID = 0;
  3176. /* Turn off parity checking and serr during the physical reset */
  3177. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3178. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3179. (cfg_value &
  3180. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3181. spin_lock_irq(&phba->hbalock);
  3182. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3183. phba->fcf.fcf_flag = 0;
  3184. /* Clean up the child queue list for the CQs */
  3185. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3186. list_del_init(&phba->sli4_hba.els_wq->list);
  3187. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3188. list_del_init(&phba->sli4_hba.dat_rq->list);
  3189. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3190. list_del_init(&phba->sli4_hba.els_cq->list);
  3191. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3192. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3193. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3194. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3195. spin_unlock_irq(&phba->hbalock);
  3196. /* Now physically reset the device */
  3197. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3198. "0389 Performing PCI function reset!\n");
  3199. /* Perform FCoE PCI function reset */
  3200. lpfc_pci_function_reset(phba);
  3201. return 0;
  3202. }
  3203. /**
  3204. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3205. * @phba: Pointer to HBA context object.
  3206. *
  3207. * This function is called in the SLI initialization code path to
  3208. * restart the HBA. The caller is not required to hold any lock.
  3209. * This function writes MBX_RESTART mailbox command to the SLIM and
  3210. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3211. * function to free any pending commands. The function enables
  3212. * POST only during the first initialization. The function returns zero.
  3213. * The function does not guarantee completion of MBX_RESTART mailbox
  3214. * command before the return of this function.
  3215. **/
  3216. static int
  3217. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3218. {
  3219. MAILBOX_t *mb;
  3220. struct lpfc_sli *psli;
  3221. volatile uint32_t word0;
  3222. void __iomem *to_slim;
  3223. spin_lock_irq(&phba->hbalock);
  3224. psli = &phba->sli;
  3225. /* Restart HBA */
  3226. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3227. "0337 Restart HBA Data: x%x x%x\n",
  3228. phba->pport->port_state, psli->sli_flag);
  3229. word0 = 0;
  3230. mb = (MAILBOX_t *) &word0;
  3231. mb->mbxCommand = MBX_RESTART;
  3232. mb->mbxHc = 1;
  3233. lpfc_reset_barrier(phba);
  3234. to_slim = phba->MBslimaddr;
  3235. writel(*(uint32_t *) mb, to_slim);
  3236. readl(to_slim); /* flush */
  3237. /* Only skip post after fc_ffinit is completed */
  3238. if (phba->pport->port_state)
  3239. word0 = 1; /* This is really setting up word1 */
  3240. else
  3241. word0 = 0; /* This is really setting up word1 */
  3242. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3243. writel(*(uint32_t *) mb, to_slim);
  3244. readl(to_slim); /* flush */
  3245. lpfc_sli_brdreset(phba);
  3246. phba->pport->stopped = 0;
  3247. phba->link_state = LPFC_INIT_START;
  3248. phba->hba_flag = 0;
  3249. spin_unlock_irq(&phba->hbalock);
  3250. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3251. psli->stats_start = get_seconds();
  3252. /* Give the INITFF and Post time to settle. */
  3253. mdelay(100);
  3254. lpfc_hba_down_post(phba);
  3255. return 0;
  3256. }
  3257. /**
  3258. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3259. * @phba: Pointer to HBA context object.
  3260. *
  3261. * This function is called in the SLI initialization code path to restart
  3262. * a SLI4 HBA. The caller is not required to hold any lock.
  3263. * At the end of the function, it calls lpfc_hba_down_post function to
  3264. * free any pending commands.
  3265. **/
  3266. static int
  3267. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3268. {
  3269. struct lpfc_sli *psli = &phba->sli;
  3270. /* Restart HBA */
  3271. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3272. "0296 Restart HBA Data: x%x x%x\n",
  3273. phba->pport->port_state, psli->sli_flag);
  3274. lpfc_sli4_brdreset(phba);
  3275. spin_lock_irq(&phba->hbalock);
  3276. phba->pport->stopped = 0;
  3277. phba->link_state = LPFC_INIT_START;
  3278. phba->hba_flag = 0;
  3279. spin_unlock_irq(&phba->hbalock);
  3280. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3281. psli->stats_start = get_seconds();
  3282. lpfc_hba_down_post(phba);
  3283. return 0;
  3284. }
  3285. /**
  3286. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3287. * @phba: Pointer to HBA context object.
  3288. *
  3289. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3290. * API jump table function pointer from the lpfc_hba struct.
  3291. **/
  3292. int
  3293. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3294. {
  3295. return phba->lpfc_sli_brdrestart(phba);
  3296. }
  3297. /**
  3298. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3299. * @phba: Pointer to HBA context object.
  3300. *
  3301. * This function is called after a HBA restart to wait for successful
  3302. * restart of the HBA. Successful restart of the HBA is indicated by
  3303. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3304. * iteration, the function will restart the HBA again. The function returns
  3305. * zero if HBA successfully restarted else returns negative error code.
  3306. **/
  3307. static int
  3308. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3309. {
  3310. uint32_t status, i = 0;
  3311. /* Read the HBA Host Status Register */
  3312. status = readl(phba->HSregaddr);
  3313. /* Check status register to see what current state is */
  3314. i = 0;
  3315. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3316. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3317. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3318. * 4.
  3319. */
  3320. if (i++ >= 20) {
  3321. /* Adapter failed to init, timeout, status reg
  3322. <status> */
  3323. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3324. "0436 Adapter failed to init, "
  3325. "timeout, status reg x%x, "
  3326. "FW Data: A8 x%x AC x%x\n", status,
  3327. readl(phba->MBslimaddr + 0xa8),
  3328. readl(phba->MBslimaddr + 0xac));
  3329. phba->link_state = LPFC_HBA_ERROR;
  3330. return -ETIMEDOUT;
  3331. }
  3332. /* Check to see if any errors occurred during init */
  3333. if (status & HS_FFERM) {
  3334. /* ERROR: During chipset initialization */
  3335. /* Adapter failed to init, chipset, status reg
  3336. <status> */
  3337. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3338. "0437 Adapter failed to init, "
  3339. "chipset, status reg x%x, "
  3340. "FW Data: A8 x%x AC x%x\n", status,
  3341. readl(phba->MBslimaddr + 0xa8),
  3342. readl(phba->MBslimaddr + 0xac));
  3343. phba->link_state = LPFC_HBA_ERROR;
  3344. return -EIO;
  3345. }
  3346. if (i <= 5) {
  3347. msleep(10);
  3348. } else if (i <= 10) {
  3349. msleep(500);
  3350. } else {
  3351. msleep(2500);
  3352. }
  3353. if (i == 15) {
  3354. /* Do post */
  3355. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3356. lpfc_sli_brdrestart(phba);
  3357. }
  3358. /* Read the HBA Host Status Register */
  3359. status = readl(phba->HSregaddr);
  3360. }
  3361. /* Check to see if any errors occurred during init */
  3362. if (status & HS_FFERM) {
  3363. /* ERROR: During chipset initialization */
  3364. /* Adapter failed to init, chipset, status reg <status> */
  3365. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3366. "0438 Adapter failed to init, chipset, "
  3367. "status reg x%x, "
  3368. "FW Data: A8 x%x AC x%x\n", status,
  3369. readl(phba->MBslimaddr + 0xa8),
  3370. readl(phba->MBslimaddr + 0xac));
  3371. phba->link_state = LPFC_HBA_ERROR;
  3372. return -EIO;
  3373. }
  3374. /* Clear all interrupt enable conditions */
  3375. writel(0, phba->HCregaddr);
  3376. readl(phba->HCregaddr); /* flush */
  3377. /* setup host attn register */
  3378. writel(0xffffffff, phba->HAregaddr);
  3379. readl(phba->HAregaddr); /* flush */
  3380. return 0;
  3381. }
  3382. /**
  3383. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3384. *
  3385. * This function calculates and returns the number of HBQs required to be
  3386. * configured.
  3387. **/
  3388. int
  3389. lpfc_sli_hbq_count(void)
  3390. {
  3391. return ARRAY_SIZE(lpfc_hbq_defs);
  3392. }
  3393. /**
  3394. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3395. *
  3396. * This function adds the number of hbq entries in every HBQ to get
  3397. * the total number of hbq entries required for the HBA and returns
  3398. * the total count.
  3399. **/
  3400. static int
  3401. lpfc_sli_hbq_entry_count(void)
  3402. {
  3403. int hbq_count = lpfc_sli_hbq_count();
  3404. int count = 0;
  3405. int i;
  3406. for (i = 0; i < hbq_count; ++i)
  3407. count += lpfc_hbq_defs[i]->entry_count;
  3408. return count;
  3409. }
  3410. /**
  3411. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3412. *
  3413. * This function calculates amount of memory required for all hbq entries
  3414. * to be configured and returns the total memory required.
  3415. **/
  3416. int
  3417. lpfc_sli_hbq_size(void)
  3418. {
  3419. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3420. }
  3421. /**
  3422. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3423. * @phba: Pointer to HBA context object.
  3424. *
  3425. * This function is called during the SLI initialization to configure
  3426. * all the HBQs and post buffers to the HBQ. The caller is not
  3427. * required to hold any locks. This function will return zero if successful
  3428. * else it will return negative error code.
  3429. **/
  3430. static int
  3431. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3432. {
  3433. int hbq_count = lpfc_sli_hbq_count();
  3434. LPFC_MBOXQ_t *pmb;
  3435. MAILBOX_t *pmbox;
  3436. uint32_t hbqno;
  3437. uint32_t hbq_entry_index;
  3438. /* Get a Mailbox buffer to setup mailbox
  3439. * commands for HBA initialization
  3440. */
  3441. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3442. if (!pmb)
  3443. return -ENOMEM;
  3444. pmbox = &pmb->u.mb;
  3445. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3446. phba->link_state = LPFC_INIT_MBX_CMDS;
  3447. phba->hbq_in_use = 1;
  3448. hbq_entry_index = 0;
  3449. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3450. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3451. phba->hbqs[hbqno].hbqPutIdx = 0;
  3452. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3453. phba->hbqs[hbqno].entry_count =
  3454. lpfc_hbq_defs[hbqno]->entry_count;
  3455. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3456. hbq_entry_index, pmb);
  3457. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3458. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3459. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3460. mbxStatus <status>, ring <num> */
  3461. lpfc_printf_log(phba, KERN_ERR,
  3462. LOG_SLI | LOG_VPORT,
  3463. "1805 Adapter failed to init. "
  3464. "Data: x%x x%x x%x\n",
  3465. pmbox->mbxCommand,
  3466. pmbox->mbxStatus, hbqno);
  3467. phba->link_state = LPFC_HBA_ERROR;
  3468. mempool_free(pmb, phba->mbox_mem_pool);
  3469. return ENXIO;
  3470. }
  3471. }
  3472. phba->hbq_count = hbq_count;
  3473. mempool_free(pmb, phba->mbox_mem_pool);
  3474. /* Initially populate or replenish the HBQs */
  3475. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3476. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3477. return 0;
  3478. }
  3479. /**
  3480. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3481. * @phba: Pointer to HBA context object.
  3482. *
  3483. * This function is called during the SLI initialization to configure
  3484. * all the HBQs and post buffers to the HBQ. The caller is not
  3485. * required to hold any locks. This function will return zero if successful
  3486. * else it will return negative error code.
  3487. **/
  3488. static int
  3489. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3490. {
  3491. phba->hbq_in_use = 1;
  3492. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3493. phba->hbq_count = 1;
  3494. /* Initially populate or replenish the HBQs */
  3495. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3496. return 0;
  3497. }
  3498. /**
  3499. * lpfc_sli_config_port - Issue config port mailbox command
  3500. * @phba: Pointer to HBA context object.
  3501. * @sli_mode: sli mode - 2/3
  3502. *
  3503. * This function is called by the sli intialization code path
  3504. * to issue config_port mailbox command. This function restarts the
  3505. * HBA firmware and issues a config_port mailbox command to configure
  3506. * the SLI interface in the sli mode specified by sli_mode
  3507. * variable. The caller is not required to hold any locks.
  3508. * The function returns 0 if successful, else returns negative error
  3509. * code.
  3510. **/
  3511. int
  3512. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3513. {
  3514. LPFC_MBOXQ_t *pmb;
  3515. uint32_t resetcount = 0, rc = 0, done = 0;
  3516. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3517. if (!pmb) {
  3518. phba->link_state = LPFC_HBA_ERROR;
  3519. return -ENOMEM;
  3520. }
  3521. phba->sli_rev = sli_mode;
  3522. while (resetcount < 2 && !done) {
  3523. spin_lock_irq(&phba->hbalock);
  3524. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3525. spin_unlock_irq(&phba->hbalock);
  3526. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3527. lpfc_sli_brdrestart(phba);
  3528. rc = lpfc_sli_chipset_init(phba);
  3529. if (rc)
  3530. break;
  3531. spin_lock_irq(&phba->hbalock);
  3532. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3533. spin_unlock_irq(&phba->hbalock);
  3534. resetcount++;
  3535. /* Call pre CONFIG_PORT mailbox command initialization. A
  3536. * value of 0 means the call was successful. Any other
  3537. * nonzero value is a failure, but if ERESTART is returned,
  3538. * the driver may reset the HBA and try again.
  3539. */
  3540. rc = lpfc_config_port_prep(phba);
  3541. if (rc == -ERESTART) {
  3542. phba->link_state = LPFC_LINK_UNKNOWN;
  3543. continue;
  3544. } else if (rc)
  3545. break;
  3546. phba->link_state = LPFC_INIT_MBX_CMDS;
  3547. lpfc_config_port(phba, pmb);
  3548. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3549. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3550. LPFC_SLI3_HBQ_ENABLED |
  3551. LPFC_SLI3_CRP_ENABLED |
  3552. LPFC_SLI3_INB_ENABLED |
  3553. LPFC_SLI3_BG_ENABLED);
  3554. if (rc != MBX_SUCCESS) {
  3555. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3556. "0442 Adapter failed to init, mbxCmd x%x "
  3557. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3558. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3559. spin_lock_irq(&phba->hbalock);
  3560. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3561. spin_unlock_irq(&phba->hbalock);
  3562. rc = -ENXIO;
  3563. } else {
  3564. /* Allow asynchronous mailbox command to go through */
  3565. spin_lock_irq(&phba->hbalock);
  3566. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3567. spin_unlock_irq(&phba->hbalock);
  3568. done = 1;
  3569. }
  3570. }
  3571. if (!done) {
  3572. rc = -EINVAL;
  3573. goto do_prep_failed;
  3574. }
  3575. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3576. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3577. rc = -ENXIO;
  3578. goto do_prep_failed;
  3579. }
  3580. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3581. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3582. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3583. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3584. phba->max_vpi : phba->max_vports;
  3585. } else
  3586. phba->max_vpi = 0;
  3587. if (pmb->u.mb.un.varCfgPort.gdss)
  3588. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3589. if (pmb->u.mb.un.varCfgPort.gerbm)
  3590. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3591. if (pmb->u.mb.un.varCfgPort.gcrp)
  3592. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3593. if (pmb->u.mb.un.varCfgPort.ginb) {
  3594. phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
  3595. phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get;
  3596. phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
  3597. phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
  3598. phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
  3599. phba->inb_last_counter =
  3600. phba->mbox->us.s3_inb_pgp.counter;
  3601. } else {
  3602. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3603. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3604. phba->inb_ha_copy = NULL;
  3605. phba->inb_counter = NULL;
  3606. }
  3607. if (phba->cfg_enable_bg) {
  3608. if (pmb->u.mb.un.varCfgPort.gbg)
  3609. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3610. else
  3611. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3612. "0443 Adapter did not grant "
  3613. "BlockGuard\n");
  3614. }
  3615. } else {
  3616. phba->hbq_get = NULL;
  3617. phba->port_gp = phba->mbox->us.s2.port;
  3618. phba->inb_ha_copy = NULL;
  3619. phba->inb_counter = NULL;
  3620. phba->max_vpi = 0;
  3621. }
  3622. do_prep_failed:
  3623. mempool_free(pmb, phba->mbox_mem_pool);
  3624. return rc;
  3625. }
  3626. /**
  3627. * lpfc_sli_hba_setup - SLI intialization function
  3628. * @phba: Pointer to HBA context object.
  3629. *
  3630. * This function is the main SLI intialization function. This function
  3631. * is called by the HBA intialization code, HBA reset code and HBA
  3632. * error attention handler code. Caller is not required to hold any
  3633. * locks. This function issues config_port mailbox command to configure
  3634. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3635. * calls the config_port_post function to issue init_link mailbox
  3636. * command and to start the discovery. The function will return zero
  3637. * if successful, else it will return negative error code.
  3638. **/
  3639. int
  3640. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3641. {
  3642. uint32_t rc;
  3643. int mode = 3;
  3644. switch (lpfc_sli_mode) {
  3645. case 2:
  3646. if (phba->cfg_enable_npiv) {
  3647. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3648. "1824 NPIV enabled: Override lpfc_sli_mode "
  3649. "parameter (%d) to auto (0).\n",
  3650. lpfc_sli_mode);
  3651. break;
  3652. }
  3653. mode = 2;
  3654. break;
  3655. case 0:
  3656. case 3:
  3657. break;
  3658. default:
  3659. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3660. "1819 Unrecognized lpfc_sli_mode "
  3661. "parameter: %d.\n", lpfc_sli_mode);
  3662. break;
  3663. }
  3664. rc = lpfc_sli_config_port(phba, mode);
  3665. if (rc && lpfc_sli_mode == 3)
  3666. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3667. "1820 Unable to select SLI-3. "
  3668. "Not supported by adapter.\n");
  3669. if (rc && mode != 2)
  3670. rc = lpfc_sli_config_port(phba, 2);
  3671. if (rc)
  3672. goto lpfc_sli_hba_setup_error;
  3673. if (phba->sli_rev == 3) {
  3674. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3675. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3676. } else {
  3677. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3678. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3679. phba->sli3_options = 0;
  3680. }
  3681. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3682. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3683. phba->sli_rev, phba->max_vpi);
  3684. rc = lpfc_sli_ring_map(phba);
  3685. if (rc)
  3686. goto lpfc_sli_hba_setup_error;
  3687. /* Init HBQs */
  3688. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3689. rc = lpfc_sli_hbq_setup(phba);
  3690. if (rc)
  3691. goto lpfc_sli_hba_setup_error;
  3692. }
  3693. spin_lock_irq(&phba->hbalock);
  3694. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3695. spin_unlock_irq(&phba->hbalock);
  3696. rc = lpfc_config_port_post(phba);
  3697. if (rc)
  3698. goto lpfc_sli_hba_setup_error;
  3699. return rc;
  3700. lpfc_sli_hba_setup_error:
  3701. phba->link_state = LPFC_HBA_ERROR;
  3702. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3703. "0445 Firmware initialization failed\n");
  3704. return rc;
  3705. }
  3706. /**
  3707. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3708. * @phba: Pointer to HBA context object.
  3709. * @mboxq: mailbox pointer.
  3710. * This function issue a dump mailbox command to read config region
  3711. * 23 and parse the records in the region and populate driver
  3712. * data structure.
  3713. **/
  3714. static int
  3715. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3716. LPFC_MBOXQ_t *mboxq)
  3717. {
  3718. struct lpfc_dmabuf *mp;
  3719. struct lpfc_mqe *mqe;
  3720. uint32_t data_length;
  3721. int rc;
  3722. /* Program the default value of vlan_id and fc_map */
  3723. phba->valid_vlan = 0;
  3724. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3725. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3726. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3727. mqe = &mboxq->u.mqe;
  3728. if (lpfc_dump_fcoe_param(phba, mboxq))
  3729. return -ENOMEM;
  3730. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3731. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3732. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3733. "(%d):2571 Mailbox cmd x%x Status x%x "
  3734. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3735. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3736. "CQ: x%x x%x x%x x%x\n",
  3737. mboxq->vport ? mboxq->vport->vpi : 0,
  3738. bf_get(lpfc_mqe_command, mqe),
  3739. bf_get(lpfc_mqe_status, mqe),
  3740. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3741. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3742. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3743. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3744. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3745. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3746. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3747. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3748. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3749. mboxq->mcqe.word0,
  3750. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3751. mboxq->mcqe.trailer);
  3752. if (rc) {
  3753. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3754. kfree(mp);
  3755. return -EIO;
  3756. }
  3757. data_length = mqe->un.mb_words[5];
  3758. if (data_length > DMP_RGN23_SIZE) {
  3759. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3760. kfree(mp);
  3761. return -EIO;
  3762. }
  3763. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3764. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3765. kfree(mp);
  3766. return 0;
  3767. }
  3768. /**
  3769. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3770. * @phba: pointer to lpfc hba data structure.
  3771. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3772. * @vpd: pointer to the memory to hold resulting port vpd data.
  3773. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3774. * On output, the number of data bytes in @vpd.
  3775. *
  3776. * This routine executes a READ_REV SLI4 mailbox command. In
  3777. * addition, this routine gets the port vpd data.
  3778. *
  3779. * Return codes
  3780. * 0 - sucessful
  3781. * ENOMEM - could not allocated memory.
  3782. **/
  3783. static int
  3784. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3785. uint8_t *vpd, uint32_t *vpd_size)
  3786. {
  3787. int rc = 0;
  3788. uint32_t dma_size;
  3789. struct lpfc_dmabuf *dmabuf;
  3790. struct lpfc_mqe *mqe;
  3791. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3792. if (!dmabuf)
  3793. return -ENOMEM;
  3794. /*
  3795. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3796. * mailbox command.
  3797. */
  3798. dma_size = *vpd_size;
  3799. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3800. dma_size,
  3801. &dmabuf->phys,
  3802. GFP_KERNEL);
  3803. if (!dmabuf->virt) {
  3804. kfree(dmabuf);
  3805. return -ENOMEM;
  3806. }
  3807. memset(dmabuf->virt, 0, dma_size);
  3808. /*
  3809. * The SLI4 implementation of READ_REV conflicts at word1,
  3810. * bits 31:16 and SLI4 adds vpd functionality not present
  3811. * in SLI3. This code corrects the conflicts.
  3812. */
  3813. lpfc_read_rev(phba, mboxq);
  3814. mqe = &mboxq->u.mqe;
  3815. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3816. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3817. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3818. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3819. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3820. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3821. if (rc) {
  3822. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3823. dmabuf->virt, dmabuf->phys);
  3824. return -EIO;
  3825. }
  3826. /*
  3827. * The available vpd length cannot be bigger than the
  3828. * DMA buffer passed to the port. Catch the less than
  3829. * case and update the caller's size.
  3830. */
  3831. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3832. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3833. lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
  3834. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3835. dmabuf->virt, dmabuf->phys);
  3836. kfree(dmabuf);
  3837. return 0;
  3838. }
  3839. /**
  3840. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3841. * @phba: pointer to lpfc hba data structure.
  3842. *
  3843. * This routine is called to explicitly arm the SLI4 device's completion and
  3844. * event queues
  3845. **/
  3846. static void
  3847. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3848. {
  3849. uint8_t fcp_eqidx;
  3850. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3851. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3852. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3853. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3854. LPFC_QUEUE_REARM);
  3855. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3856. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3857. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3858. LPFC_QUEUE_REARM);
  3859. }
  3860. /**
  3861. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3862. * @phba: Pointer to HBA context object.
  3863. *
  3864. * This function is the main SLI4 device intialization PCI function. This
  3865. * function is called by the HBA intialization code, HBA reset code and
  3866. * HBA error attention handler code. Caller is not required to hold any
  3867. * locks.
  3868. **/
  3869. int
  3870. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3871. {
  3872. int rc;
  3873. LPFC_MBOXQ_t *mboxq;
  3874. struct lpfc_mqe *mqe;
  3875. uint8_t *vpd;
  3876. uint32_t vpd_size;
  3877. uint32_t ftr_rsp = 0;
  3878. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3879. struct lpfc_vport *vport = phba->pport;
  3880. struct lpfc_dmabuf *mp;
  3881. /* Perform a PCI function reset to start from clean */
  3882. rc = lpfc_pci_function_reset(phba);
  3883. if (unlikely(rc))
  3884. return -ENODEV;
  3885. /* Check the HBA Host Status Register for readyness */
  3886. rc = lpfc_sli4_post_status_check(phba);
  3887. if (unlikely(rc))
  3888. return -ENODEV;
  3889. else {
  3890. spin_lock_irq(&phba->hbalock);
  3891. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3892. spin_unlock_irq(&phba->hbalock);
  3893. }
  3894. /*
  3895. * Allocate a single mailbox container for initializing the
  3896. * port.
  3897. */
  3898. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3899. if (!mboxq)
  3900. return -ENOMEM;
  3901. /*
  3902. * Continue initialization with default values even if driver failed
  3903. * to read FCoE param config regions
  3904. */
  3905. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3906. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3907. "2570 Failed to read FCoE parameters\n");
  3908. /* Issue READ_REV to collect vpd and FW information. */
  3909. vpd_size = PAGE_SIZE;
  3910. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3911. if (!vpd) {
  3912. rc = -ENOMEM;
  3913. goto out_free_mbox;
  3914. }
  3915. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3916. if (unlikely(rc))
  3917. goto out_free_vpd;
  3918. mqe = &mboxq->u.mqe;
  3919. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3920. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3921. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3922. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3923. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3924. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3925. "0376 READ_REV Error. SLI Level %d "
  3926. "FCoE enabled %d\n",
  3927. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3928. rc = -EIO;
  3929. goto out_free_vpd;
  3930. }
  3931. /*
  3932. * Evaluate the read rev and vpd data. Populate the driver
  3933. * state with the results. If this routine fails, the failure
  3934. * is not fatal as the driver will use generic values.
  3935. */
  3936. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3937. if (unlikely(!rc)) {
  3938. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3939. "0377 Error %d parsing vpd. "
  3940. "Using defaults.\n", rc);
  3941. rc = 0;
  3942. }
  3943. /* Save information as VPD data */
  3944. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3945. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3946. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3947. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3948. &mqe->un.read_rev);
  3949. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3950. &mqe->un.read_rev);
  3951. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3952. &mqe->un.read_rev);
  3953. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3954. &mqe->un.read_rev);
  3955. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3956. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3957. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3958. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3959. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3960. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3961. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3962. "(%d):0380 READ_REV Status x%x "
  3963. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3964. mboxq->vport ? mboxq->vport->vpi : 0,
  3965. bf_get(lpfc_mqe_status, mqe),
  3966. phba->vpd.rev.opFwName,
  3967. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3968. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3969. /*
  3970. * Discover the port's supported feature set and match it against the
  3971. * hosts requests.
  3972. */
  3973. lpfc_request_features(phba, mboxq);
  3974. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3975. if (unlikely(rc)) {
  3976. rc = -EIO;
  3977. goto out_free_vpd;
  3978. }
  3979. /*
  3980. * The port must support FCP initiator mode as this is the
  3981. * only mode running in the host.
  3982. */
  3983. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3984. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3985. "0378 No support for fcpi mode.\n");
  3986. ftr_rsp++;
  3987. }
  3988. /*
  3989. * If the port cannot support the host's requested features
  3990. * then turn off the global config parameters to disable the
  3991. * feature in the driver. This is not a fatal error.
  3992. */
  3993. if ((phba->cfg_enable_bg) &&
  3994. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3995. ftr_rsp++;
  3996. if (phba->max_vpi && phba->cfg_enable_npiv &&
  3997. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3998. ftr_rsp++;
  3999. if (ftr_rsp) {
  4000. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4001. "0379 Feature Mismatch Data: x%08x %08x "
  4002. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  4003. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  4004. phba->cfg_enable_npiv, phba->max_vpi);
  4005. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4006. phba->cfg_enable_bg = 0;
  4007. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4008. phba->cfg_enable_npiv = 0;
  4009. }
  4010. /* These SLI3 features are assumed in SLI4 */
  4011. spin_lock_irq(&phba->hbalock);
  4012. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4013. spin_unlock_irq(&phba->hbalock);
  4014. /* Read the port's service parameters. */
  4015. lpfc_read_sparam(phba, mboxq, vport->vpi);
  4016. mboxq->vport = vport;
  4017. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4018. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4019. if (rc == MBX_SUCCESS) {
  4020. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4021. rc = 0;
  4022. }
  4023. /*
  4024. * This memory was allocated by the lpfc_read_sparam routine. Release
  4025. * it to the mbuf pool.
  4026. */
  4027. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4028. kfree(mp);
  4029. mboxq->context1 = NULL;
  4030. if (unlikely(rc)) {
  4031. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4032. "0382 READ_SPARAM command failed "
  4033. "status %d, mbxStatus x%x\n",
  4034. rc, bf_get(lpfc_mqe_status, mqe));
  4035. phba->link_state = LPFC_HBA_ERROR;
  4036. rc = -EIO;
  4037. goto out_free_vpd;
  4038. }
  4039. if (phba->cfg_soft_wwnn)
  4040. u64_to_wwn(phba->cfg_soft_wwnn,
  4041. vport->fc_sparam.nodeName.u.wwn);
  4042. if (phba->cfg_soft_wwpn)
  4043. u64_to_wwn(phba->cfg_soft_wwpn,
  4044. vport->fc_sparam.portName.u.wwn);
  4045. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4046. sizeof(struct lpfc_name));
  4047. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4048. sizeof(struct lpfc_name));
  4049. /* Update the fc_host data structures with new wwn. */
  4050. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4051. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4052. /* Register SGL pool to the device using non-embedded mailbox command */
  4053. rc = lpfc_sli4_post_sgl_list(phba);
  4054. if (unlikely(rc)) {
  4055. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4056. "0582 Error %d during sgl post operation", rc);
  4057. rc = -ENODEV;
  4058. goto out_free_vpd;
  4059. }
  4060. /* Register SCSI SGL pool to the device */
  4061. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4062. if (unlikely(rc)) {
  4063. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4064. "0383 Error %d during scsi sgl post opeation",
  4065. rc);
  4066. /* Some Scsi buffers were moved to the abort scsi list */
  4067. /* A pci function reset will repost them */
  4068. rc = -ENODEV;
  4069. goto out_free_vpd;
  4070. }
  4071. /* Post the rpi header region to the device. */
  4072. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4073. if (unlikely(rc)) {
  4074. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4075. "0393 Error %d during rpi post operation\n",
  4076. rc);
  4077. rc = -ENODEV;
  4078. goto out_free_vpd;
  4079. }
  4080. if (phba->cfg_enable_fip)
  4081. bf_set(lpfc_fip_flag, &phba->sli4_hba.sli4_flags, 1);
  4082. else
  4083. bf_set(lpfc_fip_flag, &phba->sli4_hba.sli4_flags, 0);
  4084. /* Set up all the queues to the device */
  4085. rc = lpfc_sli4_queue_setup(phba);
  4086. if (unlikely(rc)) {
  4087. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4088. "0381 Error %d during queue setup.\n ", rc);
  4089. goto out_stop_timers;
  4090. }
  4091. /* Arm the CQs and then EQs on device */
  4092. lpfc_sli4_arm_cqeq_intr(phba);
  4093. /* Indicate device interrupt mode */
  4094. phba->sli4_hba.intr_enable = 1;
  4095. /* Allow asynchronous mailbox command to go through */
  4096. spin_lock_irq(&phba->hbalock);
  4097. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4098. spin_unlock_irq(&phba->hbalock);
  4099. /* Post receive buffers to the device */
  4100. lpfc_sli4_rb_setup(phba);
  4101. /* Start the ELS watchdog timer */
  4102. mod_timer(&vport->els_tmofunc,
  4103. jiffies + HZ * (phba->fc_ratov * 2));
  4104. /* Start heart beat timer */
  4105. mod_timer(&phba->hb_tmofunc,
  4106. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4107. phba->hb_outstanding = 0;
  4108. phba->last_completion_time = jiffies;
  4109. /* Start error attention (ERATT) polling timer */
  4110. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4111. /*
  4112. * The port is ready, set the host's link state to LINK_DOWN
  4113. * in preparation for link interrupts.
  4114. */
  4115. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4116. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4117. lpfc_set_loopback_flag(phba);
  4118. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4119. spin_lock_irq(&phba->hbalock);
  4120. phba->link_state = LPFC_LINK_DOWN;
  4121. spin_unlock_irq(&phba->hbalock);
  4122. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4123. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4124. kfree(vpd);
  4125. return 0;
  4126. } else
  4127. rc = -EIO;
  4128. /* Unset all the queues set up in this routine when error out */
  4129. if (rc)
  4130. lpfc_sli4_queue_unset(phba);
  4131. out_stop_timers:
  4132. if (rc)
  4133. lpfc_stop_hba_timers(phba);
  4134. out_free_vpd:
  4135. kfree(vpd);
  4136. out_free_mbox:
  4137. mempool_free(mboxq, phba->mbox_mem_pool);
  4138. return rc;
  4139. }
  4140. /**
  4141. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4142. * @ptr: context object - pointer to hba structure.
  4143. *
  4144. * This is the callback function for mailbox timer. The mailbox
  4145. * timer is armed when a new mailbox command is issued and the timer
  4146. * is deleted when the mailbox complete. The function is called by
  4147. * the kernel timer code when a mailbox does not complete within
  4148. * expected time. This function wakes up the worker thread to
  4149. * process the mailbox timeout and returns. All the processing is
  4150. * done by the worker thread function lpfc_mbox_timeout_handler.
  4151. **/
  4152. void
  4153. lpfc_mbox_timeout(unsigned long ptr)
  4154. {
  4155. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4156. unsigned long iflag;
  4157. uint32_t tmo_posted;
  4158. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4159. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4160. if (!tmo_posted)
  4161. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4162. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4163. if (!tmo_posted)
  4164. lpfc_worker_wake_up(phba);
  4165. return;
  4166. }
  4167. /**
  4168. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4169. * @phba: Pointer to HBA context object.
  4170. *
  4171. * This function is called from worker thread when a mailbox command times out.
  4172. * The caller is not required to hold any locks. This function will reset the
  4173. * HBA and recover all the pending commands.
  4174. **/
  4175. void
  4176. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4177. {
  4178. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4179. MAILBOX_t *mb = &pmbox->u.mb;
  4180. struct lpfc_sli *psli = &phba->sli;
  4181. struct lpfc_sli_ring *pring;
  4182. /* Check the pmbox pointer first. There is a race condition
  4183. * between the mbox timeout handler getting executed in the
  4184. * worklist and the mailbox actually completing. When this
  4185. * race condition occurs, the mbox_active will be NULL.
  4186. */
  4187. spin_lock_irq(&phba->hbalock);
  4188. if (pmbox == NULL) {
  4189. lpfc_printf_log(phba, KERN_WARNING,
  4190. LOG_MBOX | LOG_SLI,
  4191. "0353 Active Mailbox cleared - mailbox timeout "
  4192. "exiting\n");
  4193. spin_unlock_irq(&phba->hbalock);
  4194. return;
  4195. }
  4196. /* Mbox cmd <mbxCommand> timeout */
  4197. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4198. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4199. mb->mbxCommand,
  4200. phba->pport->port_state,
  4201. phba->sli.sli_flag,
  4202. phba->sli.mbox_active);
  4203. spin_unlock_irq(&phba->hbalock);
  4204. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4205. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4206. * it to fail all oustanding SCSI IO.
  4207. */
  4208. spin_lock_irq(&phba->pport->work_port_lock);
  4209. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4210. spin_unlock_irq(&phba->pport->work_port_lock);
  4211. spin_lock_irq(&phba->hbalock);
  4212. phba->link_state = LPFC_LINK_UNKNOWN;
  4213. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4214. spin_unlock_irq(&phba->hbalock);
  4215. pring = &psli->ring[psli->fcp_ring];
  4216. lpfc_sli_abort_iocb_ring(phba, pring);
  4217. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4218. "0345 Resetting board due to mailbox timeout\n");
  4219. /* Reset the HBA device */
  4220. lpfc_reset_hba(phba);
  4221. }
  4222. /**
  4223. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4224. * @phba: Pointer to HBA context object.
  4225. * @pmbox: Pointer to mailbox object.
  4226. * @flag: Flag indicating how the mailbox need to be processed.
  4227. *
  4228. * This function is called by discovery code and HBA management code
  4229. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4230. * function gets the hbalock to protect the data structures.
  4231. * The mailbox command can be submitted in polling mode, in which case
  4232. * this function will wait in a polling loop for the completion of the
  4233. * mailbox.
  4234. * If the mailbox is submitted in no_wait mode (not polling) the
  4235. * function will submit the command and returns immediately without waiting
  4236. * for the mailbox completion. The no_wait is supported only when HBA
  4237. * is in SLI2/SLI3 mode - interrupts are enabled.
  4238. * The SLI interface allows only one mailbox pending at a time. If the
  4239. * mailbox is issued in polling mode and there is already a mailbox
  4240. * pending, then the function will return an error. If the mailbox is issued
  4241. * in NO_WAIT mode and there is a mailbox pending already, the function
  4242. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4243. * The sli layer owns the mailbox object until the completion of mailbox
  4244. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4245. * return codes the caller owns the mailbox command after the return of
  4246. * the function.
  4247. **/
  4248. static int
  4249. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4250. uint32_t flag)
  4251. {
  4252. MAILBOX_t *mb;
  4253. struct lpfc_sli *psli = &phba->sli;
  4254. uint32_t status, evtctr;
  4255. uint32_t ha_copy;
  4256. int i;
  4257. unsigned long timeout;
  4258. unsigned long drvr_flag = 0;
  4259. uint32_t word0, ldata;
  4260. void __iomem *to_slim;
  4261. int processing_queue = 0;
  4262. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4263. if (!pmbox) {
  4264. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4265. /* processing mbox queue from intr_handler */
  4266. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4267. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4268. return MBX_SUCCESS;
  4269. }
  4270. processing_queue = 1;
  4271. pmbox = lpfc_mbox_get(phba);
  4272. if (!pmbox) {
  4273. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4274. return MBX_SUCCESS;
  4275. }
  4276. }
  4277. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4278. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4279. if(!pmbox->vport) {
  4280. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4281. lpfc_printf_log(phba, KERN_ERR,
  4282. LOG_MBOX | LOG_VPORT,
  4283. "1806 Mbox x%x failed. No vport\n",
  4284. pmbox->u.mb.mbxCommand);
  4285. dump_stack();
  4286. goto out_not_finished;
  4287. }
  4288. }
  4289. /* If the PCI channel is in offline state, do not post mbox. */
  4290. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4291. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4292. goto out_not_finished;
  4293. }
  4294. /* If HBA has a deferred error attention, fail the iocb. */
  4295. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4296. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4297. goto out_not_finished;
  4298. }
  4299. psli = &phba->sli;
  4300. mb = &pmbox->u.mb;
  4301. status = MBX_SUCCESS;
  4302. if (phba->link_state == LPFC_HBA_ERROR) {
  4303. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4304. /* Mbox command <mbxCommand> cannot issue */
  4305. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4306. "(%d):0311 Mailbox command x%x cannot "
  4307. "issue Data: x%x x%x\n",
  4308. pmbox->vport ? pmbox->vport->vpi : 0,
  4309. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4310. goto out_not_finished;
  4311. }
  4312. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4313. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4314. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4315. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4316. "(%d):2528 Mailbox command x%x cannot "
  4317. "issue Data: x%x x%x\n",
  4318. pmbox->vport ? pmbox->vport->vpi : 0,
  4319. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4320. goto out_not_finished;
  4321. }
  4322. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4323. /* Polling for a mbox command when another one is already active
  4324. * is not allowed in SLI. Also, the driver must have established
  4325. * SLI2 mode to queue and process multiple mbox commands.
  4326. */
  4327. if (flag & MBX_POLL) {
  4328. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4329. /* Mbox command <mbxCommand> cannot issue */
  4330. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4331. "(%d):2529 Mailbox command x%x "
  4332. "cannot issue Data: x%x x%x\n",
  4333. pmbox->vport ? pmbox->vport->vpi : 0,
  4334. pmbox->u.mb.mbxCommand,
  4335. psli->sli_flag, flag);
  4336. goto out_not_finished;
  4337. }
  4338. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4339. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4340. /* Mbox command <mbxCommand> cannot issue */
  4341. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4342. "(%d):2530 Mailbox command x%x "
  4343. "cannot issue Data: x%x x%x\n",
  4344. pmbox->vport ? pmbox->vport->vpi : 0,
  4345. pmbox->u.mb.mbxCommand,
  4346. psli->sli_flag, flag);
  4347. goto out_not_finished;
  4348. }
  4349. /* Another mailbox command is still being processed, queue this
  4350. * command to be processed later.
  4351. */
  4352. lpfc_mbox_put(phba, pmbox);
  4353. /* Mbox cmd issue - BUSY */
  4354. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4355. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4356. "x%x x%x x%x x%x\n",
  4357. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4358. mb->mbxCommand, phba->pport->port_state,
  4359. psli->sli_flag, flag);
  4360. psli->slistat.mbox_busy++;
  4361. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4362. if (pmbox->vport) {
  4363. lpfc_debugfs_disc_trc(pmbox->vport,
  4364. LPFC_DISC_TRC_MBOX_VPORT,
  4365. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4366. (uint32_t)mb->mbxCommand,
  4367. mb->un.varWords[0], mb->un.varWords[1]);
  4368. }
  4369. else {
  4370. lpfc_debugfs_disc_trc(phba->pport,
  4371. LPFC_DISC_TRC_MBOX,
  4372. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4373. (uint32_t)mb->mbxCommand,
  4374. mb->un.varWords[0], mb->un.varWords[1]);
  4375. }
  4376. return MBX_BUSY;
  4377. }
  4378. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4379. /* If we are not polling, we MUST be in SLI2 mode */
  4380. if (flag != MBX_POLL) {
  4381. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4382. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4383. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4384. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4385. /* Mbox command <mbxCommand> cannot issue */
  4386. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4387. "(%d):2531 Mailbox command x%x "
  4388. "cannot issue Data: x%x x%x\n",
  4389. pmbox->vport ? pmbox->vport->vpi : 0,
  4390. pmbox->u.mb.mbxCommand,
  4391. psli->sli_flag, flag);
  4392. goto out_not_finished;
  4393. }
  4394. /* timeout active mbox command */
  4395. mod_timer(&psli->mbox_tmo, (jiffies +
  4396. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4397. }
  4398. /* Mailbox cmd <cmd> issue */
  4399. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4400. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4401. "x%x\n",
  4402. pmbox->vport ? pmbox->vport->vpi : 0,
  4403. mb->mbxCommand, phba->pport->port_state,
  4404. psli->sli_flag, flag);
  4405. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4406. if (pmbox->vport) {
  4407. lpfc_debugfs_disc_trc(pmbox->vport,
  4408. LPFC_DISC_TRC_MBOX_VPORT,
  4409. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4410. (uint32_t)mb->mbxCommand,
  4411. mb->un.varWords[0], mb->un.varWords[1]);
  4412. }
  4413. else {
  4414. lpfc_debugfs_disc_trc(phba->pport,
  4415. LPFC_DISC_TRC_MBOX,
  4416. "MBOX Send: cmd:x%x mb:x%x x%x",
  4417. (uint32_t)mb->mbxCommand,
  4418. mb->un.varWords[0], mb->un.varWords[1]);
  4419. }
  4420. }
  4421. psli->slistat.mbox_cmd++;
  4422. evtctr = psli->slistat.mbox_event;
  4423. /* next set own bit for the adapter and copy over command word */
  4424. mb->mbxOwner = OWN_CHIP;
  4425. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4426. /* First copy command data to host SLIM area */
  4427. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4428. } else {
  4429. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4430. /* copy command data into host mbox for cmpl */
  4431. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4432. }
  4433. /* First copy mbox command data to HBA SLIM, skip past first
  4434. word */
  4435. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4436. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4437. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4438. /* Next copy over first word, with mbxOwner set */
  4439. ldata = *((uint32_t *)mb);
  4440. to_slim = phba->MBslimaddr;
  4441. writel(ldata, to_slim);
  4442. readl(to_slim); /* flush */
  4443. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4444. /* switch over to host mailbox */
  4445. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4446. }
  4447. }
  4448. wmb();
  4449. switch (flag) {
  4450. case MBX_NOWAIT:
  4451. /* Set up reference to mailbox command */
  4452. psli->mbox_active = pmbox;
  4453. /* Interrupt board to do it */
  4454. writel(CA_MBATT, phba->CAregaddr);
  4455. readl(phba->CAregaddr); /* flush */
  4456. /* Don't wait for it to finish, just return */
  4457. break;
  4458. case MBX_POLL:
  4459. /* Set up null reference to mailbox command */
  4460. psli->mbox_active = NULL;
  4461. /* Interrupt board to do it */
  4462. writel(CA_MBATT, phba->CAregaddr);
  4463. readl(phba->CAregaddr); /* flush */
  4464. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4465. /* First read mbox status word */
  4466. word0 = *((uint32_t *)phba->mbox);
  4467. word0 = le32_to_cpu(word0);
  4468. } else {
  4469. /* First read mbox status word */
  4470. word0 = readl(phba->MBslimaddr);
  4471. }
  4472. /* Read the HBA Host Attention Register */
  4473. ha_copy = readl(phba->HAregaddr);
  4474. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4475. mb->mbxCommand) *
  4476. 1000) + jiffies;
  4477. i = 0;
  4478. /* Wait for command to complete */
  4479. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4480. (!(ha_copy & HA_MBATT) &&
  4481. (phba->link_state > LPFC_WARM_START))) {
  4482. if (time_after(jiffies, timeout)) {
  4483. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4484. spin_unlock_irqrestore(&phba->hbalock,
  4485. drvr_flag);
  4486. goto out_not_finished;
  4487. }
  4488. /* Check if we took a mbox interrupt while we were
  4489. polling */
  4490. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4491. && (evtctr != psli->slistat.mbox_event))
  4492. break;
  4493. if (i++ > 10) {
  4494. spin_unlock_irqrestore(&phba->hbalock,
  4495. drvr_flag);
  4496. msleep(1);
  4497. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4498. }
  4499. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4500. /* First copy command data */
  4501. word0 = *((uint32_t *)phba->mbox);
  4502. word0 = le32_to_cpu(word0);
  4503. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4504. MAILBOX_t *slimmb;
  4505. uint32_t slimword0;
  4506. /* Check real SLIM for any errors */
  4507. slimword0 = readl(phba->MBslimaddr);
  4508. slimmb = (MAILBOX_t *) & slimword0;
  4509. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4510. && slimmb->mbxStatus) {
  4511. psli->sli_flag &=
  4512. ~LPFC_SLI_ACTIVE;
  4513. word0 = slimword0;
  4514. }
  4515. }
  4516. } else {
  4517. /* First copy command data */
  4518. word0 = readl(phba->MBslimaddr);
  4519. }
  4520. /* Read the HBA Host Attention Register */
  4521. ha_copy = readl(phba->HAregaddr);
  4522. }
  4523. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4524. /* copy results back to user */
  4525. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4526. } else {
  4527. /* First copy command data */
  4528. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4529. MAILBOX_CMD_SIZE);
  4530. if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
  4531. pmbox->context2) {
  4532. lpfc_memcpy_from_slim((void *)pmbox->context2,
  4533. phba->MBslimaddr + DMP_RSP_OFFSET,
  4534. mb->un.varDmp.word_cnt);
  4535. }
  4536. }
  4537. writel(HA_MBATT, phba->HAregaddr);
  4538. readl(phba->HAregaddr); /* flush */
  4539. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4540. status = mb->mbxStatus;
  4541. }
  4542. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4543. return status;
  4544. out_not_finished:
  4545. if (processing_queue) {
  4546. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4547. lpfc_mbox_cmpl_put(phba, pmbox);
  4548. }
  4549. return MBX_NOT_FINISHED;
  4550. }
  4551. /**
  4552. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4553. * @phba: Pointer to HBA context object.
  4554. *
  4555. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4556. * the driver internal pending mailbox queue. It will then try to wait out the
  4557. * possible outstanding mailbox command before return.
  4558. *
  4559. * Returns:
  4560. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4561. * the outstanding mailbox command timed out.
  4562. **/
  4563. static int
  4564. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4565. {
  4566. struct lpfc_sli *psli = &phba->sli;
  4567. uint8_t actcmd = MBX_HEARTBEAT;
  4568. int rc = 0;
  4569. unsigned long timeout;
  4570. /* Mark the asynchronous mailbox command posting as blocked */
  4571. spin_lock_irq(&phba->hbalock);
  4572. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4573. if (phba->sli.mbox_active)
  4574. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4575. spin_unlock_irq(&phba->hbalock);
  4576. /* Determine how long we might wait for the active mailbox
  4577. * command to be gracefully completed by firmware.
  4578. */
  4579. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4580. jiffies;
  4581. /* Wait for the outstnading mailbox command to complete */
  4582. while (phba->sli.mbox_active) {
  4583. /* Check active mailbox complete status every 2ms */
  4584. msleep(2);
  4585. if (time_after(jiffies, timeout)) {
  4586. /* Timeout, marked the outstanding cmd not complete */
  4587. rc = 1;
  4588. break;
  4589. }
  4590. }
  4591. /* Can not cleanly block async mailbox command, fails it */
  4592. if (rc) {
  4593. spin_lock_irq(&phba->hbalock);
  4594. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4595. spin_unlock_irq(&phba->hbalock);
  4596. }
  4597. return rc;
  4598. }
  4599. /**
  4600. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4601. * @phba: Pointer to HBA context object.
  4602. *
  4603. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4604. * commands from the driver internal pending mailbox queue. It makes sure
  4605. * that there is no outstanding mailbox command before resuming posting
  4606. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4607. * mailbox command, it will try to wait it out before resuming asynchronous
  4608. * mailbox command posting.
  4609. **/
  4610. static void
  4611. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4612. {
  4613. struct lpfc_sli *psli = &phba->sli;
  4614. spin_lock_irq(&phba->hbalock);
  4615. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4616. /* Asynchronous mailbox posting is not blocked, do nothing */
  4617. spin_unlock_irq(&phba->hbalock);
  4618. return;
  4619. }
  4620. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4621. * successful or timeout, after timing-out the outstanding mailbox
  4622. * command shall always be removed, so just unblock posting async
  4623. * mailbox command and resume
  4624. */
  4625. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4626. spin_unlock_irq(&phba->hbalock);
  4627. /* wake up worker thread to post asynchronlous mailbox command */
  4628. lpfc_worker_wake_up(phba);
  4629. }
  4630. /**
  4631. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4632. * @phba: Pointer to HBA context object.
  4633. * @mboxq: Pointer to mailbox object.
  4634. *
  4635. * The function posts a mailbox to the port. The mailbox is expected
  4636. * to be comletely filled in and ready for the port to operate on it.
  4637. * This routine executes a synchronous completion operation on the
  4638. * mailbox by polling for its completion.
  4639. *
  4640. * The caller must not be holding any locks when calling this routine.
  4641. *
  4642. * Returns:
  4643. * MBX_SUCCESS - mailbox posted successfully
  4644. * Any of the MBX error values.
  4645. **/
  4646. static int
  4647. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4648. {
  4649. int rc = MBX_SUCCESS;
  4650. unsigned long iflag;
  4651. uint32_t db_ready;
  4652. uint32_t mcqe_status;
  4653. uint32_t mbx_cmnd;
  4654. unsigned long timeout;
  4655. struct lpfc_sli *psli = &phba->sli;
  4656. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4657. struct lpfc_bmbx_create *mbox_rgn;
  4658. struct dma_address *dma_address;
  4659. struct lpfc_register bmbx_reg;
  4660. /*
  4661. * Only one mailbox can be active to the bootstrap mailbox region
  4662. * at a time and there is no queueing provided.
  4663. */
  4664. spin_lock_irqsave(&phba->hbalock, iflag);
  4665. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4666. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4667. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4668. "(%d):2532 Mailbox command x%x (x%x) "
  4669. "cannot issue Data: x%x x%x\n",
  4670. mboxq->vport ? mboxq->vport->vpi : 0,
  4671. mboxq->u.mb.mbxCommand,
  4672. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4673. psli->sli_flag, MBX_POLL);
  4674. return MBXERR_ERROR;
  4675. }
  4676. /* The server grabs the token and owns it until release */
  4677. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4678. phba->sli.mbox_active = mboxq;
  4679. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4680. /*
  4681. * Initialize the bootstrap memory region to avoid stale data areas
  4682. * in the mailbox post. Then copy the caller's mailbox contents to
  4683. * the bmbx mailbox region.
  4684. */
  4685. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4686. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4687. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4688. sizeof(struct lpfc_mqe));
  4689. /* Post the high mailbox dma address to the port and wait for ready. */
  4690. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4691. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4692. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4693. * 1000) + jiffies;
  4694. do {
  4695. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4696. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4697. if (!db_ready)
  4698. msleep(2);
  4699. if (time_after(jiffies, timeout)) {
  4700. rc = MBXERR_ERROR;
  4701. goto exit;
  4702. }
  4703. } while (!db_ready);
  4704. /* Post the low mailbox dma address to the port. */
  4705. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4706. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4707. * 1000) + jiffies;
  4708. do {
  4709. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4710. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4711. if (!db_ready)
  4712. msleep(2);
  4713. if (time_after(jiffies, timeout)) {
  4714. rc = MBXERR_ERROR;
  4715. goto exit;
  4716. }
  4717. } while (!db_ready);
  4718. /*
  4719. * Read the CQ to ensure the mailbox has completed.
  4720. * If so, update the mailbox status so that the upper layers
  4721. * can complete the request normally.
  4722. */
  4723. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4724. sizeof(struct lpfc_mqe));
  4725. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4726. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4727. sizeof(struct lpfc_mcqe));
  4728. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4729. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4730. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4731. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4732. rc = MBXERR_ERROR;
  4733. }
  4734. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4735. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4736. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4737. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4738. mboxq->vport ? mboxq->vport->vpi : 0,
  4739. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4740. bf_get(lpfc_mqe_status, mb),
  4741. mb->un.mb_words[0], mb->un.mb_words[1],
  4742. mb->un.mb_words[2], mb->un.mb_words[3],
  4743. mb->un.mb_words[4], mb->un.mb_words[5],
  4744. mb->un.mb_words[6], mb->un.mb_words[7],
  4745. mb->un.mb_words[8], mb->un.mb_words[9],
  4746. mb->un.mb_words[10], mb->un.mb_words[11],
  4747. mb->un.mb_words[12], mboxq->mcqe.word0,
  4748. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4749. mboxq->mcqe.trailer);
  4750. exit:
  4751. /* We are holding the token, no needed for lock when release */
  4752. spin_lock_irqsave(&phba->hbalock, iflag);
  4753. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4754. phba->sli.mbox_active = NULL;
  4755. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4756. return rc;
  4757. }
  4758. /**
  4759. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4760. * @phba: Pointer to HBA context object.
  4761. * @pmbox: Pointer to mailbox object.
  4762. * @flag: Flag indicating how the mailbox need to be processed.
  4763. *
  4764. * This function is called by discovery code and HBA management code to submit
  4765. * a mailbox command to firmware with SLI-4 interface spec.
  4766. *
  4767. * Return codes the caller owns the mailbox command after the return of the
  4768. * function.
  4769. **/
  4770. static int
  4771. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4772. uint32_t flag)
  4773. {
  4774. struct lpfc_sli *psli = &phba->sli;
  4775. unsigned long iflags;
  4776. int rc;
  4777. rc = lpfc_mbox_dev_check(phba);
  4778. if (unlikely(rc)) {
  4779. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4780. "(%d):2544 Mailbox command x%x (x%x) "
  4781. "cannot issue Data: x%x x%x\n",
  4782. mboxq->vport ? mboxq->vport->vpi : 0,
  4783. mboxq->u.mb.mbxCommand,
  4784. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4785. psli->sli_flag, flag);
  4786. goto out_not_finished;
  4787. }
  4788. /* Detect polling mode and jump to a handler */
  4789. if (!phba->sli4_hba.intr_enable) {
  4790. if (flag == MBX_POLL)
  4791. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4792. else
  4793. rc = -EIO;
  4794. if (rc != MBX_SUCCESS)
  4795. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4796. "(%d):2541 Mailbox command x%x "
  4797. "(x%x) cannot issue Data: x%x x%x\n",
  4798. mboxq->vport ? mboxq->vport->vpi : 0,
  4799. mboxq->u.mb.mbxCommand,
  4800. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4801. psli->sli_flag, flag);
  4802. return rc;
  4803. } else if (flag == MBX_POLL) {
  4804. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4805. "(%d):2542 Try to issue mailbox command "
  4806. "x%x (x%x) synchronously ahead of async"
  4807. "mailbox command queue: x%x x%x\n",
  4808. mboxq->vport ? mboxq->vport->vpi : 0,
  4809. mboxq->u.mb.mbxCommand,
  4810. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4811. psli->sli_flag, flag);
  4812. /* Try to block the asynchronous mailbox posting */
  4813. rc = lpfc_sli4_async_mbox_block(phba);
  4814. if (!rc) {
  4815. /* Successfully blocked, now issue sync mbox cmd */
  4816. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4817. if (rc != MBX_SUCCESS)
  4818. lpfc_printf_log(phba, KERN_ERR,
  4819. LOG_MBOX | LOG_SLI,
  4820. "(%d):2597 Mailbox command "
  4821. "x%x (x%x) cannot issue "
  4822. "Data: x%x x%x\n",
  4823. mboxq->vport ?
  4824. mboxq->vport->vpi : 0,
  4825. mboxq->u.mb.mbxCommand,
  4826. lpfc_sli4_mbox_opcode_get(phba,
  4827. mboxq),
  4828. psli->sli_flag, flag);
  4829. /* Unblock the async mailbox posting afterward */
  4830. lpfc_sli4_async_mbox_unblock(phba);
  4831. }
  4832. return rc;
  4833. }
  4834. /* Now, interrupt mode asynchrous mailbox command */
  4835. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4836. if (rc) {
  4837. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4838. "(%d):2543 Mailbox command x%x (x%x) "
  4839. "cannot issue Data: x%x x%x\n",
  4840. mboxq->vport ? mboxq->vport->vpi : 0,
  4841. mboxq->u.mb.mbxCommand,
  4842. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4843. psli->sli_flag, flag);
  4844. goto out_not_finished;
  4845. }
  4846. /* Put the mailbox command to the driver internal FIFO */
  4847. psli->slistat.mbox_busy++;
  4848. spin_lock_irqsave(&phba->hbalock, iflags);
  4849. lpfc_mbox_put(phba, mboxq);
  4850. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4851. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4852. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4853. "x%x (x%x) x%x x%x x%x\n",
  4854. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4855. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4856. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4857. phba->pport->port_state,
  4858. psli->sli_flag, MBX_NOWAIT);
  4859. /* Wake up worker thread to transport mailbox command from head */
  4860. lpfc_worker_wake_up(phba);
  4861. return MBX_BUSY;
  4862. out_not_finished:
  4863. return MBX_NOT_FINISHED;
  4864. }
  4865. /**
  4866. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4867. * @phba: Pointer to HBA context object.
  4868. *
  4869. * This function is called by worker thread to send a mailbox command to
  4870. * SLI4 HBA firmware.
  4871. *
  4872. **/
  4873. int
  4874. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4875. {
  4876. struct lpfc_sli *psli = &phba->sli;
  4877. LPFC_MBOXQ_t *mboxq;
  4878. int rc = MBX_SUCCESS;
  4879. unsigned long iflags;
  4880. struct lpfc_mqe *mqe;
  4881. uint32_t mbx_cmnd;
  4882. /* Check interrupt mode before post async mailbox command */
  4883. if (unlikely(!phba->sli4_hba.intr_enable))
  4884. return MBX_NOT_FINISHED;
  4885. /* Check for mailbox command service token */
  4886. spin_lock_irqsave(&phba->hbalock, iflags);
  4887. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4888. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4889. return MBX_NOT_FINISHED;
  4890. }
  4891. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4892. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4893. return MBX_NOT_FINISHED;
  4894. }
  4895. if (unlikely(phba->sli.mbox_active)) {
  4896. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4897. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4898. "0384 There is pending active mailbox cmd\n");
  4899. return MBX_NOT_FINISHED;
  4900. }
  4901. /* Take the mailbox command service token */
  4902. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4903. /* Get the next mailbox command from head of queue */
  4904. mboxq = lpfc_mbox_get(phba);
  4905. /* If no more mailbox command waiting for post, we're done */
  4906. if (!mboxq) {
  4907. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4908. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4909. return MBX_SUCCESS;
  4910. }
  4911. phba->sli.mbox_active = mboxq;
  4912. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4913. /* Check device readiness for posting mailbox command */
  4914. rc = lpfc_mbox_dev_check(phba);
  4915. if (unlikely(rc))
  4916. /* Driver clean routine will clean up pending mailbox */
  4917. goto out_not_finished;
  4918. /* Prepare the mbox command to be posted */
  4919. mqe = &mboxq->u.mqe;
  4920. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4921. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4922. mod_timer(&psli->mbox_tmo, (jiffies +
  4923. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4924. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4925. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4926. "x%x x%x\n",
  4927. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4928. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4929. phba->pport->port_state, psli->sli_flag);
  4930. if (mbx_cmnd != MBX_HEARTBEAT) {
  4931. if (mboxq->vport) {
  4932. lpfc_debugfs_disc_trc(mboxq->vport,
  4933. LPFC_DISC_TRC_MBOX_VPORT,
  4934. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4935. mbx_cmnd, mqe->un.mb_words[0],
  4936. mqe->un.mb_words[1]);
  4937. } else {
  4938. lpfc_debugfs_disc_trc(phba->pport,
  4939. LPFC_DISC_TRC_MBOX,
  4940. "MBOX Send: cmd:x%x mb:x%x x%x",
  4941. mbx_cmnd, mqe->un.mb_words[0],
  4942. mqe->un.mb_words[1]);
  4943. }
  4944. }
  4945. psli->slistat.mbox_cmd++;
  4946. /* Post the mailbox command to the port */
  4947. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  4948. if (rc != MBX_SUCCESS) {
  4949. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4950. "(%d):2533 Mailbox command x%x (x%x) "
  4951. "cannot issue Data: x%x x%x\n",
  4952. mboxq->vport ? mboxq->vport->vpi : 0,
  4953. mboxq->u.mb.mbxCommand,
  4954. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4955. psli->sli_flag, MBX_NOWAIT);
  4956. goto out_not_finished;
  4957. }
  4958. return rc;
  4959. out_not_finished:
  4960. spin_lock_irqsave(&phba->hbalock, iflags);
  4961. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4962. __lpfc_mbox_cmpl_put(phba, mboxq);
  4963. /* Release the token */
  4964. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4965. phba->sli.mbox_active = NULL;
  4966. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4967. return MBX_NOT_FINISHED;
  4968. }
  4969. /**
  4970. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  4971. * @phba: Pointer to HBA context object.
  4972. * @pmbox: Pointer to mailbox object.
  4973. * @flag: Flag indicating how the mailbox need to be processed.
  4974. *
  4975. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  4976. * the API jump table function pointer from the lpfc_hba struct.
  4977. *
  4978. * Return codes the caller owns the mailbox command after the return of the
  4979. * function.
  4980. **/
  4981. int
  4982. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  4983. {
  4984. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  4985. }
  4986. /**
  4987. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  4988. * @phba: The hba struct for which this call is being executed.
  4989. * @dev_grp: The HBA PCI-Device group number.
  4990. *
  4991. * This routine sets up the mbox interface API function jump table in @phba
  4992. * struct.
  4993. * Returns: 0 - success, -ENODEV - failure.
  4994. **/
  4995. int
  4996. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4997. {
  4998. switch (dev_grp) {
  4999. case LPFC_PCI_DEV_LP:
  5000. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5001. phba->lpfc_sli_handle_slow_ring_event =
  5002. lpfc_sli_handle_slow_ring_event_s3;
  5003. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5004. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5005. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5006. break;
  5007. case LPFC_PCI_DEV_OC:
  5008. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5009. phba->lpfc_sli_handle_slow_ring_event =
  5010. lpfc_sli_handle_slow_ring_event_s4;
  5011. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5012. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5013. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5014. break;
  5015. default:
  5016. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5017. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5018. dev_grp);
  5019. return -ENODEV;
  5020. break;
  5021. }
  5022. return 0;
  5023. }
  5024. /**
  5025. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5026. * @phba: Pointer to HBA context object.
  5027. * @pring: Pointer to driver SLI ring object.
  5028. * @piocb: Pointer to address of newly added command iocb.
  5029. *
  5030. * This function is called with hbalock held to add a command
  5031. * iocb to the txq when SLI layer cannot submit the command iocb
  5032. * to the ring.
  5033. **/
  5034. static void
  5035. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5036. struct lpfc_iocbq *piocb)
  5037. {
  5038. /* Insert the caller's iocb in the txq tail for later processing. */
  5039. list_add_tail(&piocb->list, &pring->txq);
  5040. pring->txq_cnt++;
  5041. }
  5042. /**
  5043. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5044. * @phba: Pointer to HBA context object.
  5045. * @pring: Pointer to driver SLI ring object.
  5046. * @piocb: Pointer to address of newly added command iocb.
  5047. *
  5048. * This function is called with hbalock held before a new
  5049. * iocb is submitted to the firmware. This function checks
  5050. * txq to flush the iocbs in txq to Firmware before
  5051. * submitting new iocbs to the Firmware.
  5052. * If there are iocbs in the txq which need to be submitted
  5053. * to firmware, lpfc_sli_next_iocb returns the first element
  5054. * of the txq after dequeuing it from txq.
  5055. * If there is no iocb in the txq then the function will return
  5056. * *piocb and *piocb is set to NULL. Caller needs to check
  5057. * *piocb to find if there are more commands in the txq.
  5058. **/
  5059. static struct lpfc_iocbq *
  5060. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5061. struct lpfc_iocbq **piocb)
  5062. {
  5063. struct lpfc_iocbq * nextiocb;
  5064. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5065. if (!nextiocb) {
  5066. nextiocb = *piocb;
  5067. *piocb = NULL;
  5068. }
  5069. return nextiocb;
  5070. }
  5071. /**
  5072. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5073. * @phba: Pointer to HBA context object.
  5074. * @ring_number: SLI ring number to issue iocb on.
  5075. * @piocb: Pointer to command iocb.
  5076. * @flag: Flag indicating if this command can be put into txq.
  5077. *
  5078. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5079. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5080. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5081. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5082. * this function allows only iocbs for posting buffers. This function finds
  5083. * next available slot in the command ring and posts the command to the
  5084. * available slot and writes the port attention register to request HBA start
  5085. * processing new iocb. If there is no slot available in the ring and
  5086. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5087. * the function returns IOCB_BUSY.
  5088. *
  5089. * This function is called with hbalock held. The function will return success
  5090. * after it successfully submit the iocb to firmware or after adding to the
  5091. * txq.
  5092. **/
  5093. static int
  5094. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5095. struct lpfc_iocbq *piocb, uint32_t flag)
  5096. {
  5097. struct lpfc_iocbq *nextiocb;
  5098. IOCB_t *iocb;
  5099. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5100. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5101. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5102. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5103. lpfc_printf_log(phba, KERN_ERR,
  5104. LOG_SLI | LOG_VPORT,
  5105. "1807 IOCB x%x failed. No vport\n",
  5106. piocb->iocb.ulpCommand);
  5107. dump_stack();
  5108. return IOCB_ERROR;
  5109. }
  5110. /* If the PCI channel is in offline state, do not post iocbs. */
  5111. if (unlikely(pci_channel_offline(phba->pcidev)))
  5112. return IOCB_ERROR;
  5113. /* If HBA has a deferred error attention, fail the iocb. */
  5114. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5115. return IOCB_ERROR;
  5116. /*
  5117. * We should never get an IOCB if we are in a < LINK_DOWN state
  5118. */
  5119. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5120. return IOCB_ERROR;
  5121. /*
  5122. * Check to see if we are blocking IOCB processing because of a
  5123. * outstanding event.
  5124. */
  5125. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5126. goto iocb_busy;
  5127. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5128. /*
  5129. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5130. * can be issued if the link is not up.
  5131. */
  5132. switch (piocb->iocb.ulpCommand) {
  5133. case CMD_GEN_REQUEST64_CR:
  5134. case CMD_GEN_REQUEST64_CX:
  5135. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5136. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5137. FC_FCP_CMND) ||
  5138. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5139. MENLO_TRANSPORT_TYPE))
  5140. goto iocb_busy;
  5141. break;
  5142. case CMD_QUE_RING_BUF_CN:
  5143. case CMD_QUE_RING_BUF64_CN:
  5144. /*
  5145. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5146. * completion, iocb_cmpl MUST be 0.
  5147. */
  5148. if (piocb->iocb_cmpl)
  5149. piocb->iocb_cmpl = NULL;
  5150. /*FALLTHROUGH*/
  5151. case CMD_CREATE_XRI_CR:
  5152. case CMD_CLOSE_XRI_CN:
  5153. case CMD_CLOSE_XRI_CX:
  5154. break;
  5155. default:
  5156. goto iocb_busy;
  5157. }
  5158. /*
  5159. * For FCP commands, we must be in a state where we can process link
  5160. * attention events.
  5161. */
  5162. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5163. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5164. goto iocb_busy;
  5165. }
  5166. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5167. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5168. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5169. if (iocb)
  5170. lpfc_sli_update_ring(phba, pring);
  5171. else
  5172. lpfc_sli_update_full_ring(phba, pring);
  5173. if (!piocb)
  5174. return IOCB_SUCCESS;
  5175. goto out_busy;
  5176. iocb_busy:
  5177. pring->stats.iocb_cmd_delay++;
  5178. out_busy:
  5179. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5180. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5181. return IOCB_SUCCESS;
  5182. }
  5183. return IOCB_BUSY;
  5184. }
  5185. /**
  5186. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5187. * @phba: Pointer to HBA context object.
  5188. * @piocb: Pointer to command iocb.
  5189. * @sglq: Pointer to the scatter gather queue object.
  5190. *
  5191. * This routine converts the bpl or bde that is in the IOCB
  5192. * to a sgl list for the sli4 hardware. The physical address
  5193. * of the bpl/bde is converted back to a virtual address.
  5194. * If the IOCB contains a BPL then the list of BDE's is
  5195. * converted to sli4_sge's. If the IOCB contains a single
  5196. * BDE then it is converted to a single sli_sge.
  5197. * The IOCB is still in cpu endianess so the contents of
  5198. * the bpl can be used without byte swapping.
  5199. *
  5200. * Returns valid XRI = Success, NO_XRI = Failure.
  5201. **/
  5202. static uint16_t
  5203. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5204. struct lpfc_sglq *sglq)
  5205. {
  5206. uint16_t xritag = NO_XRI;
  5207. struct ulp_bde64 *bpl = NULL;
  5208. struct ulp_bde64 bde;
  5209. struct sli4_sge *sgl = NULL;
  5210. IOCB_t *icmd;
  5211. int numBdes = 0;
  5212. int i = 0;
  5213. if (!piocbq || !sglq)
  5214. return xritag;
  5215. sgl = (struct sli4_sge *)sglq->sgl;
  5216. icmd = &piocbq->iocb;
  5217. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5218. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5219. sizeof(struct ulp_bde64);
  5220. /* The addrHigh and addrLow fields within the IOCB
  5221. * have not been byteswapped yet so there is no
  5222. * need to swap them back.
  5223. */
  5224. bpl = (struct ulp_bde64 *)
  5225. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5226. if (!bpl)
  5227. return xritag;
  5228. for (i = 0; i < numBdes; i++) {
  5229. /* Should already be byte swapped. */
  5230. sgl->addr_hi = bpl->addrHigh;
  5231. sgl->addr_lo = bpl->addrLow;
  5232. /* swap the size field back to the cpu so we
  5233. * can assign it to the sgl.
  5234. */
  5235. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5236. bf_set(lpfc_sli4_sge_len, sgl, bde.tus.f.bdeSize);
  5237. if ((i+1) == numBdes)
  5238. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5239. else
  5240. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5241. sgl->word2 = cpu_to_le32(sgl->word2);
  5242. sgl->word3 = cpu_to_le32(sgl->word3);
  5243. bpl++;
  5244. sgl++;
  5245. }
  5246. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5247. /* The addrHigh and addrLow fields of the BDE have not
  5248. * been byteswapped yet so they need to be swapped
  5249. * before putting them in the sgl.
  5250. */
  5251. sgl->addr_hi =
  5252. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5253. sgl->addr_lo =
  5254. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5255. bf_set(lpfc_sli4_sge_len, sgl,
  5256. icmd->un.genreq64.bdl.bdeSize);
  5257. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5258. sgl->word2 = cpu_to_le32(sgl->word2);
  5259. sgl->word3 = cpu_to_le32(sgl->word3);
  5260. }
  5261. return sglq->sli4_xritag;
  5262. }
  5263. /**
  5264. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5265. * @phba: Pointer to HBA context object.
  5266. *
  5267. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5268. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5269. * held.
  5270. *
  5271. * Return: index into SLI4 fast-path FCP queue index.
  5272. **/
  5273. static uint32_t
  5274. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5275. {
  5276. ++phba->fcp_qidx;
  5277. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5278. phba->fcp_qidx = 0;
  5279. return phba->fcp_qidx;
  5280. }
  5281. /**
  5282. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5283. * @phba: Pointer to HBA context object.
  5284. * @piocb: Pointer to command iocb.
  5285. * @wqe: Pointer to the work queue entry.
  5286. *
  5287. * This routine converts the iocb command to its Work Queue Entry
  5288. * equivalent. The wqe pointer should not have any fields set when
  5289. * this routine is called because it will memcpy over them.
  5290. * This routine does not set the CQ_ID or the WQEC bits in the
  5291. * wqe.
  5292. *
  5293. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5294. **/
  5295. static int
  5296. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5297. union lpfc_wqe *wqe)
  5298. {
  5299. uint32_t payload_len = 0;
  5300. uint8_t ct = 0;
  5301. uint32_t fip;
  5302. uint32_t abort_tag;
  5303. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5304. uint8_t cmnd;
  5305. uint16_t xritag;
  5306. struct ulp_bde64 *bpl = NULL;
  5307. fip = bf_get(lpfc_fip_flag, &phba->sli4_hba.sli4_flags);
  5308. /* The fcp commands will set command type */
  5309. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5310. command_type = FCP_COMMAND;
  5311. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS))
  5312. command_type = ELS_COMMAND_FIP;
  5313. else
  5314. command_type = ELS_COMMAND_NON_FIP;
  5315. /* Some of the fields are in the right position already */
  5316. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5317. abort_tag = (uint32_t) iocbq->iotag;
  5318. xritag = iocbq->sli4_xritag;
  5319. wqe->words[7] = 0; /* The ct field has moved so reset */
  5320. /* words0-2 bpl convert bde */
  5321. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5322. bpl = (struct ulp_bde64 *)
  5323. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5324. if (!bpl)
  5325. return IOCB_ERROR;
  5326. /* Should already be byte swapped. */
  5327. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5328. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5329. /* swap the size field back to the cpu so we
  5330. * can assign it to the sgl.
  5331. */
  5332. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5333. payload_len = wqe->generic.bde.tus.f.bdeSize;
  5334. } else
  5335. payload_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5336. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5337. cmnd = iocbq->iocb.ulpCommand;
  5338. switch (iocbq->iocb.ulpCommand) {
  5339. case CMD_ELS_REQUEST64_CR:
  5340. if (!iocbq->iocb.ulpLe) {
  5341. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5342. "2007 Only Limited Edition cmd Format"
  5343. " supported 0x%x\n",
  5344. iocbq->iocb.ulpCommand);
  5345. return IOCB_ERROR;
  5346. }
  5347. wqe->els_req.payload_len = payload_len;
  5348. /* Els_reguest64 has a TMO */
  5349. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5350. iocbq->iocb.ulpTimeout);
  5351. /* Need a VF for word 4 set the vf bit*/
  5352. bf_set(els_req64_vf, &wqe->els_req, 0);
  5353. /* And a VFID for word 12 */
  5354. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5355. /*
  5356. * Set ct field to 3, indicates that the context_tag field
  5357. * contains the FCFI and remote N_Port_ID is
  5358. * in word 5.
  5359. */
  5360. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5361. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5362. iocbq->iocb.ulpContext);
  5363. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5364. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5365. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5366. break;
  5367. case CMD_XMIT_SEQUENCE64_CR:
  5368. /* word3 iocb=io_tag32 wqe=payload_offset */
  5369. /* payload offset used for multilpe outstanding
  5370. * sequences on the same exchange
  5371. */
  5372. wqe->words[3] = 0;
  5373. /* word4 relative_offset memcpy */
  5374. /* word5 r_ctl/df_ctl memcpy */
  5375. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5376. wqe->xmit_sequence.xmit_len = payload_len;
  5377. break;
  5378. case CMD_XMIT_BCAST64_CN:
  5379. /* word3 iocb=iotag32 wqe=payload_len */
  5380. wqe->words[3] = 0; /* no definition for this in wqe */
  5381. /* word4 iocb=rsvd wqe=rsvd */
  5382. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5383. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5384. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5385. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5386. break;
  5387. case CMD_FCP_IWRITE64_CR:
  5388. command_type = FCP_COMMAND_DATA_OUT;
  5389. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5390. * confusing.
  5391. * word3 is payload_len: byte offset to the sgl entry for the
  5392. * fcp_command.
  5393. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5394. * word5 is initial xfer len 0 = wait for xfer-ready
  5395. */
  5396. /* Always wait for xfer-ready before sending data */
  5397. wqe->fcp_iwrite.initial_xfer_len = 0;
  5398. /* word 4 (xfer length) should have been set on the memcpy */
  5399. /* allow write to fall through to read */
  5400. case CMD_FCP_IREAD64_CR:
  5401. /* FCP_CMD is always the 1st sgl entry */
  5402. wqe->fcp_iread.payload_len =
  5403. payload_len + sizeof(struct fcp_rsp);
  5404. /* word 4 (xfer length) should have been set on the memcpy */
  5405. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5406. iocbq->iocb.ulpFCP2Rcvy);
  5407. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5408. /* The XC bit and the XS bit are similar. The driver never
  5409. * tracked whether or not the exchange was previouslly open.
  5410. * XC = Exchange create, 0 is create. 1 is already open.
  5411. * XS = link cmd: 1 do not close the exchange after command.
  5412. * XS = 0 close exchange when command completes.
  5413. * The only time we would not set the XC bit is when the XS bit
  5414. * is set and we are sending our 2nd or greater command on
  5415. * this exchange.
  5416. */
  5417. /* Always open the exchange */
  5418. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5419. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5420. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5421. break;
  5422. case CMD_FCP_ICMND64_CR:
  5423. /* Always open the exchange */
  5424. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5425. wqe->words[4] = 0;
  5426. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5427. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5428. break;
  5429. case CMD_GEN_REQUEST64_CR:
  5430. /* word3 command length is described as byte offset to the
  5431. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5432. * sgl[0] = cmnd
  5433. * sgl[1] = rsp.
  5434. *
  5435. */
  5436. wqe->gen_req.command_len = payload_len;
  5437. /* Word4 parameter copied in the memcpy */
  5438. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5439. /* word6 context tag copied in memcpy */
  5440. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5441. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5442. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5443. "2015 Invalid CT %x command 0x%x\n",
  5444. ct, iocbq->iocb.ulpCommand);
  5445. return IOCB_ERROR;
  5446. }
  5447. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5448. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5449. iocbq->iocb.ulpTimeout);
  5450. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5451. command_type = OTHER_COMMAND;
  5452. break;
  5453. case CMD_XMIT_ELS_RSP64_CX:
  5454. /* words0-2 BDE memcpy */
  5455. /* word3 iocb=iotag32 wqe=rsvd */
  5456. wqe->words[3] = 0;
  5457. /* word4 iocb=did wge=rsvd. */
  5458. wqe->words[4] = 0;
  5459. /* word5 iocb=rsvd wge=did */
  5460. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5461. iocbq->iocb.un.elsreq64.remoteID);
  5462. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5463. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5464. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5465. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5466. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5467. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5468. iocbq->vport->vpi + phba->vpi_base);
  5469. command_type = OTHER_COMMAND;
  5470. break;
  5471. case CMD_CLOSE_XRI_CN:
  5472. case CMD_ABORT_XRI_CN:
  5473. case CMD_ABORT_XRI_CX:
  5474. /* words 0-2 memcpy should be 0 rserved */
  5475. /* port will send abts */
  5476. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5477. /*
  5478. * The link is down so the fw does not need to send abts
  5479. * on the wire.
  5480. */
  5481. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5482. else
  5483. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5484. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5485. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5486. wqe->words[5] = 0;
  5487. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5488. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5489. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5490. wqe->generic.abort_tag = abort_tag;
  5491. /*
  5492. * The abort handler will send us CMD_ABORT_XRI_CN or
  5493. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5494. */
  5495. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5496. cmnd = CMD_ABORT_XRI_CX;
  5497. command_type = OTHER_COMMAND;
  5498. xritag = 0;
  5499. break;
  5500. case CMD_XMIT_BLS_RSP64_CX:
  5501. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  5502. * we re-construct this WQE here based on information in
  5503. * iocbq from scratch.
  5504. */
  5505. memset(wqe, 0, sizeof(union lpfc_wqe));
  5506. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  5507. iocbq->iocb.un.ulpWord[3]);
  5508. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5509. iocbq->sli4_xritag);
  5510. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  5511. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  5512. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  5513. iocbq->iocb.ulpContext);
  5514. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  5515. command_type = OTHER_COMMAND;
  5516. break;
  5517. case CMD_XRI_ABORTED_CX:
  5518. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5519. /* words0-2 are all 0's no bde */
  5520. /* word3 and word4 are rsvrd */
  5521. wqe->words[3] = 0;
  5522. wqe->words[4] = 0;
  5523. /* word5 iocb=rsvd wge=did */
  5524. /* There is no remote port id in the IOCB? */
  5525. /* Let this fall through and fail */
  5526. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5527. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5528. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5529. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5530. default:
  5531. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5532. "2014 Invalid command 0x%x\n",
  5533. iocbq->iocb.ulpCommand);
  5534. return IOCB_ERROR;
  5535. break;
  5536. }
  5537. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5538. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5539. wqe->generic.abort_tag = abort_tag;
  5540. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5541. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5542. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5543. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5544. return 0;
  5545. }
  5546. /**
  5547. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5548. * @phba: Pointer to HBA context object.
  5549. * @ring_number: SLI ring number to issue iocb on.
  5550. * @piocb: Pointer to command iocb.
  5551. * @flag: Flag indicating if this command can be put into txq.
  5552. *
  5553. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5554. * an iocb command to an HBA with SLI-4 interface spec.
  5555. *
  5556. * This function is called with hbalock held. The function will return success
  5557. * after it successfully submit the iocb to firmware or after adding to the
  5558. * txq.
  5559. **/
  5560. static int
  5561. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5562. struct lpfc_iocbq *piocb, uint32_t flag)
  5563. {
  5564. struct lpfc_sglq *sglq;
  5565. uint16_t xritag;
  5566. union lpfc_wqe wqe;
  5567. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5568. uint32_t fcp_wqidx;
  5569. if (piocb->sli4_xritag == NO_XRI) {
  5570. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5571. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5572. sglq = NULL;
  5573. else {
  5574. sglq = __lpfc_sli_get_sglq(phba);
  5575. if (!sglq)
  5576. return IOCB_ERROR;
  5577. piocb->sli4_xritag = sglq->sli4_xritag;
  5578. }
  5579. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5580. sglq = NULL; /* These IO's already have an XRI and
  5581. * a mapped sgl.
  5582. */
  5583. } else {
  5584. /* This is a continuation of a commandi,(CX) so this
  5585. * sglq is on the active list
  5586. */
  5587. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5588. if (!sglq)
  5589. return IOCB_ERROR;
  5590. }
  5591. if (sglq) {
  5592. xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
  5593. if (xritag != sglq->sli4_xritag)
  5594. return IOCB_ERROR;
  5595. }
  5596. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5597. return IOCB_ERROR;
  5598. if (piocb->iocb_flag & LPFC_IO_FCP) {
  5599. fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5600. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[fcp_wqidx], &wqe))
  5601. return IOCB_ERROR;
  5602. } else {
  5603. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5604. return IOCB_ERROR;
  5605. }
  5606. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5607. return 0;
  5608. }
  5609. /**
  5610. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5611. *
  5612. * This routine wraps the actual lockless version for issusing IOCB function
  5613. * pointer from the lpfc_hba struct.
  5614. *
  5615. * Return codes:
  5616. * IOCB_ERROR - Error
  5617. * IOCB_SUCCESS - Success
  5618. * IOCB_BUSY - Busy
  5619. **/
  5620. static inline int
  5621. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5622. struct lpfc_iocbq *piocb, uint32_t flag)
  5623. {
  5624. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5625. }
  5626. /**
  5627. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5628. * @phba: The hba struct for which this call is being executed.
  5629. * @dev_grp: The HBA PCI-Device group number.
  5630. *
  5631. * This routine sets up the SLI interface API function jump table in @phba
  5632. * struct.
  5633. * Returns: 0 - success, -ENODEV - failure.
  5634. **/
  5635. int
  5636. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5637. {
  5638. switch (dev_grp) {
  5639. case LPFC_PCI_DEV_LP:
  5640. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5641. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5642. break;
  5643. case LPFC_PCI_DEV_OC:
  5644. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5645. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5646. break;
  5647. default:
  5648. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5649. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5650. dev_grp);
  5651. return -ENODEV;
  5652. break;
  5653. }
  5654. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5655. return 0;
  5656. }
  5657. /**
  5658. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5659. * @phba: Pointer to HBA context object.
  5660. * @pring: Pointer to driver SLI ring object.
  5661. * @piocb: Pointer to command iocb.
  5662. * @flag: Flag indicating if this command can be put into txq.
  5663. *
  5664. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5665. * function. This function gets the hbalock and calls
  5666. * __lpfc_sli_issue_iocb function and will return the error returned
  5667. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5668. * functions which do not hold hbalock.
  5669. **/
  5670. int
  5671. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5672. struct lpfc_iocbq *piocb, uint32_t flag)
  5673. {
  5674. unsigned long iflags;
  5675. int rc;
  5676. spin_lock_irqsave(&phba->hbalock, iflags);
  5677. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5678. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5679. return rc;
  5680. }
  5681. /**
  5682. * lpfc_extra_ring_setup - Extra ring setup function
  5683. * @phba: Pointer to HBA context object.
  5684. *
  5685. * This function is called while driver attaches with the
  5686. * HBA to setup the extra ring. The extra ring is used
  5687. * only when driver needs to support target mode functionality
  5688. * or IP over FC functionalities.
  5689. *
  5690. * This function is called with no lock held.
  5691. **/
  5692. static int
  5693. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5694. {
  5695. struct lpfc_sli *psli;
  5696. struct lpfc_sli_ring *pring;
  5697. psli = &phba->sli;
  5698. /* Adjust cmd/rsp ring iocb entries more evenly */
  5699. /* Take some away from the FCP ring */
  5700. pring = &psli->ring[psli->fcp_ring];
  5701. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5702. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5703. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5704. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5705. /* and give them to the extra ring */
  5706. pring = &psli->ring[psli->extra_ring];
  5707. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5708. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5709. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5710. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5711. /* Setup default profile for this ring */
  5712. pring->iotag_max = 4096;
  5713. pring->num_mask = 1;
  5714. pring->prt[0].profile = 0; /* Mask 0 */
  5715. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5716. pring->prt[0].type = phba->cfg_multi_ring_type;
  5717. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5718. return 0;
  5719. }
  5720. /**
  5721. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5722. * @phba: Pointer to HBA context object.
  5723. * @pring: Pointer to driver SLI ring object.
  5724. * @iocbq: Pointer to iocb object.
  5725. *
  5726. * This function is called by the slow ring event handler
  5727. * function when there is an ASYNC event iocb in the ring.
  5728. * This function is called with no lock held.
  5729. * Currently this function handles only temperature related
  5730. * ASYNC events. The function decodes the temperature sensor
  5731. * event message and posts events for the management applications.
  5732. **/
  5733. static void
  5734. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5735. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5736. {
  5737. IOCB_t *icmd;
  5738. uint16_t evt_code;
  5739. uint16_t temp;
  5740. struct temp_event temp_event_data;
  5741. struct Scsi_Host *shost;
  5742. uint32_t *iocb_w;
  5743. icmd = &iocbq->iocb;
  5744. evt_code = icmd->un.asyncstat.evt_code;
  5745. temp = icmd->ulpContext;
  5746. if ((evt_code != ASYNC_TEMP_WARN) &&
  5747. (evt_code != ASYNC_TEMP_SAFE)) {
  5748. iocb_w = (uint32_t *) icmd;
  5749. lpfc_printf_log(phba,
  5750. KERN_ERR,
  5751. LOG_SLI,
  5752. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5753. " evt_code 0x%x\n"
  5754. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5755. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5756. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5757. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5758. pring->ringno,
  5759. icmd->un.asyncstat.evt_code,
  5760. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5761. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5762. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5763. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5764. return;
  5765. }
  5766. temp_event_data.data = (uint32_t)temp;
  5767. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5768. if (evt_code == ASYNC_TEMP_WARN) {
  5769. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5770. lpfc_printf_log(phba,
  5771. KERN_ERR,
  5772. LOG_TEMP,
  5773. "0347 Adapter is very hot, please take "
  5774. "corrective action. temperature : %d Celsius\n",
  5775. temp);
  5776. }
  5777. if (evt_code == ASYNC_TEMP_SAFE) {
  5778. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5779. lpfc_printf_log(phba,
  5780. KERN_ERR,
  5781. LOG_TEMP,
  5782. "0340 Adapter temperature is OK now. "
  5783. "temperature : %d Celsius\n",
  5784. temp);
  5785. }
  5786. /* Send temperature change event to applications */
  5787. shost = lpfc_shost_from_vport(phba->pport);
  5788. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5789. sizeof(temp_event_data), (char *) &temp_event_data,
  5790. LPFC_NL_VENDOR_ID);
  5791. }
  5792. /**
  5793. * lpfc_sli_setup - SLI ring setup function
  5794. * @phba: Pointer to HBA context object.
  5795. *
  5796. * lpfc_sli_setup sets up rings of the SLI interface with
  5797. * number of iocbs per ring and iotags. This function is
  5798. * called while driver attach to the HBA and before the
  5799. * interrupts are enabled. So there is no need for locking.
  5800. *
  5801. * This function always returns 0.
  5802. **/
  5803. int
  5804. lpfc_sli_setup(struct lpfc_hba *phba)
  5805. {
  5806. int i, totiocbsize = 0;
  5807. struct lpfc_sli *psli = &phba->sli;
  5808. struct lpfc_sli_ring *pring;
  5809. psli->num_rings = MAX_CONFIGURED_RINGS;
  5810. psli->sli_flag = 0;
  5811. psli->fcp_ring = LPFC_FCP_RING;
  5812. psli->next_ring = LPFC_FCP_NEXT_RING;
  5813. psli->extra_ring = LPFC_EXTRA_RING;
  5814. psli->iocbq_lookup = NULL;
  5815. psli->iocbq_lookup_len = 0;
  5816. psli->last_iotag = 0;
  5817. for (i = 0; i < psli->num_rings; i++) {
  5818. pring = &psli->ring[i];
  5819. switch (i) {
  5820. case LPFC_FCP_RING: /* ring 0 - FCP */
  5821. /* numCiocb and numRiocb are used in config_port */
  5822. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5823. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5824. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5825. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5826. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5827. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5828. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5829. SLI3_IOCB_CMD_SIZE :
  5830. SLI2_IOCB_CMD_SIZE;
  5831. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5832. SLI3_IOCB_RSP_SIZE :
  5833. SLI2_IOCB_RSP_SIZE;
  5834. pring->iotag_ctr = 0;
  5835. pring->iotag_max =
  5836. (phba->cfg_hba_queue_depth * 2);
  5837. pring->fast_iotag = pring->iotag_max;
  5838. pring->num_mask = 0;
  5839. break;
  5840. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5841. /* numCiocb and numRiocb are used in config_port */
  5842. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5843. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5844. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5845. SLI3_IOCB_CMD_SIZE :
  5846. SLI2_IOCB_CMD_SIZE;
  5847. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5848. SLI3_IOCB_RSP_SIZE :
  5849. SLI2_IOCB_RSP_SIZE;
  5850. pring->iotag_max = phba->cfg_hba_queue_depth;
  5851. pring->num_mask = 0;
  5852. break;
  5853. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5854. /* numCiocb and numRiocb are used in config_port */
  5855. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5856. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5857. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5858. SLI3_IOCB_CMD_SIZE :
  5859. SLI2_IOCB_CMD_SIZE;
  5860. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5861. SLI3_IOCB_RSP_SIZE :
  5862. SLI2_IOCB_RSP_SIZE;
  5863. pring->fast_iotag = 0;
  5864. pring->iotag_ctr = 0;
  5865. pring->iotag_max = 4096;
  5866. pring->lpfc_sli_rcv_async_status =
  5867. lpfc_sli_async_event_handler;
  5868. pring->num_mask = LPFC_MAX_RING_MASK;
  5869. pring->prt[0].profile = 0; /* Mask 0 */
  5870. pring->prt[0].rctl = FC_ELS_REQ;
  5871. pring->prt[0].type = FC_ELS_DATA;
  5872. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5873. lpfc_els_unsol_event;
  5874. pring->prt[1].profile = 0; /* Mask 1 */
  5875. pring->prt[1].rctl = FC_ELS_RSP;
  5876. pring->prt[1].type = FC_ELS_DATA;
  5877. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5878. lpfc_els_unsol_event;
  5879. pring->prt[2].profile = 0; /* Mask 2 */
  5880. /* NameServer Inquiry */
  5881. pring->prt[2].rctl = FC_UNSOL_CTL;
  5882. /* NameServer */
  5883. pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
  5884. pring->prt[2].lpfc_sli_rcv_unsol_event =
  5885. lpfc_ct_unsol_event;
  5886. pring->prt[3].profile = 0; /* Mask 3 */
  5887. /* NameServer response */
  5888. pring->prt[3].rctl = FC_SOL_CTL;
  5889. /* NameServer */
  5890. pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
  5891. pring->prt[3].lpfc_sli_rcv_unsol_event =
  5892. lpfc_ct_unsol_event;
  5893. /* abort unsolicited sequence */
  5894. pring->prt[4].profile = 0; /* Mask 4 */
  5895. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  5896. pring->prt[4].type = FC_TYPE_BLS;
  5897. pring->prt[4].lpfc_sli_rcv_unsol_event =
  5898. lpfc_sli4_ct_abort_unsol_event;
  5899. break;
  5900. }
  5901. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  5902. (pring->numRiocb * pring->sizeRiocb);
  5903. }
  5904. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  5905. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  5906. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  5907. "SLI2 SLIM Data: x%x x%lx\n",
  5908. phba->brd_no, totiocbsize,
  5909. (unsigned long) MAX_SLIM_IOCB_SIZE);
  5910. }
  5911. if (phba->cfg_multi_ring_support == 2)
  5912. lpfc_extra_ring_setup(phba);
  5913. return 0;
  5914. }
  5915. /**
  5916. * lpfc_sli_queue_setup - Queue initialization function
  5917. * @phba: Pointer to HBA context object.
  5918. *
  5919. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  5920. * ring. This function also initializes ring indices of each ring.
  5921. * This function is called during the initialization of the SLI
  5922. * interface of an HBA.
  5923. * This function is called with no lock held and always returns
  5924. * 1.
  5925. **/
  5926. int
  5927. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  5928. {
  5929. struct lpfc_sli *psli;
  5930. struct lpfc_sli_ring *pring;
  5931. int i;
  5932. psli = &phba->sli;
  5933. spin_lock_irq(&phba->hbalock);
  5934. INIT_LIST_HEAD(&psli->mboxq);
  5935. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  5936. /* Initialize list headers for txq and txcmplq as double linked lists */
  5937. for (i = 0; i < psli->num_rings; i++) {
  5938. pring = &psli->ring[i];
  5939. pring->ringno = i;
  5940. pring->next_cmdidx = 0;
  5941. pring->local_getidx = 0;
  5942. pring->cmdidx = 0;
  5943. INIT_LIST_HEAD(&pring->txq);
  5944. INIT_LIST_HEAD(&pring->txcmplq);
  5945. INIT_LIST_HEAD(&pring->iocb_continueq);
  5946. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  5947. INIT_LIST_HEAD(&pring->postbufq);
  5948. }
  5949. spin_unlock_irq(&phba->hbalock);
  5950. return 1;
  5951. }
  5952. /**
  5953. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  5954. * @phba: Pointer to HBA context object.
  5955. *
  5956. * This routine flushes the mailbox command subsystem. It will unconditionally
  5957. * flush all the mailbox commands in the three possible stages in the mailbox
  5958. * command sub-system: pending mailbox command queue; the outstanding mailbox
  5959. * command; and completed mailbox command queue. It is caller's responsibility
  5960. * to make sure that the driver is in the proper state to flush the mailbox
  5961. * command sub-system. Namely, the posting of mailbox commands into the
  5962. * pending mailbox command queue from the various clients must be stopped;
  5963. * either the HBA is in a state that it will never works on the outstanding
  5964. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  5965. * mailbox command has been completed.
  5966. **/
  5967. static void
  5968. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  5969. {
  5970. LIST_HEAD(completions);
  5971. struct lpfc_sli *psli = &phba->sli;
  5972. LPFC_MBOXQ_t *pmb;
  5973. unsigned long iflag;
  5974. /* Flush all the mailbox commands in the mbox system */
  5975. spin_lock_irqsave(&phba->hbalock, iflag);
  5976. /* The pending mailbox command queue */
  5977. list_splice_init(&phba->sli.mboxq, &completions);
  5978. /* The outstanding active mailbox command */
  5979. if (psli->mbox_active) {
  5980. list_add_tail(&psli->mbox_active->list, &completions);
  5981. psli->mbox_active = NULL;
  5982. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5983. }
  5984. /* The completed mailbox command queue */
  5985. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  5986. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5987. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  5988. while (!list_empty(&completions)) {
  5989. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  5990. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5991. if (pmb->mbox_cmpl)
  5992. pmb->mbox_cmpl(phba, pmb);
  5993. }
  5994. }
  5995. /**
  5996. * lpfc_sli_host_down - Vport cleanup function
  5997. * @vport: Pointer to virtual port object.
  5998. *
  5999. * lpfc_sli_host_down is called to clean up the resources
  6000. * associated with a vport before destroying virtual
  6001. * port data structures.
  6002. * This function does following operations:
  6003. * - Free discovery resources associated with this virtual
  6004. * port.
  6005. * - Free iocbs associated with this virtual port in
  6006. * the txq.
  6007. * - Send abort for all iocb commands associated with this
  6008. * vport in txcmplq.
  6009. *
  6010. * This function is called with no lock held and always returns 1.
  6011. **/
  6012. int
  6013. lpfc_sli_host_down(struct lpfc_vport *vport)
  6014. {
  6015. LIST_HEAD(completions);
  6016. struct lpfc_hba *phba = vport->phba;
  6017. struct lpfc_sli *psli = &phba->sli;
  6018. struct lpfc_sli_ring *pring;
  6019. struct lpfc_iocbq *iocb, *next_iocb;
  6020. int i;
  6021. unsigned long flags = 0;
  6022. uint16_t prev_pring_flag;
  6023. lpfc_cleanup_discovery_resources(vport);
  6024. spin_lock_irqsave(&phba->hbalock, flags);
  6025. for (i = 0; i < psli->num_rings; i++) {
  6026. pring = &psli->ring[i];
  6027. prev_pring_flag = pring->flag;
  6028. /* Only slow rings */
  6029. if (pring->ringno == LPFC_ELS_RING) {
  6030. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6031. /* Set the lpfc data pending flag */
  6032. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6033. }
  6034. /*
  6035. * Error everything on the txq since these iocbs have not been
  6036. * given to the FW yet.
  6037. */
  6038. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6039. if (iocb->vport != vport)
  6040. continue;
  6041. list_move_tail(&iocb->list, &completions);
  6042. pring->txq_cnt--;
  6043. }
  6044. /* Next issue ABTS for everything on the txcmplq */
  6045. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6046. list) {
  6047. if (iocb->vport != vport)
  6048. continue;
  6049. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6050. }
  6051. pring->flag = prev_pring_flag;
  6052. }
  6053. spin_unlock_irqrestore(&phba->hbalock, flags);
  6054. /* Cancel all the IOCBs from the completions list */
  6055. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6056. IOERR_SLI_DOWN);
  6057. return 1;
  6058. }
  6059. /**
  6060. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6061. * @phba: Pointer to HBA context object.
  6062. *
  6063. * This function cleans up all iocb, buffers, mailbox commands
  6064. * while shutting down the HBA. This function is called with no
  6065. * lock held and always returns 1.
  6066. * This function does the following to cleanup driver resources:
  6067. * - Free discovery resources for each virtual port
  6068. * - Cleanup any pending fabric iocbs
  6069. * - Iterate through the iocb txq and free each entry
  6070. * in the list.
  6071. * - Free up any buffer posted to the HBA
  6072. * - Free mailbox commands in the mailbox queue.
  6073. **/
  6074. int
  6075. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6076. {
  6077. LIST_HEAD(completions);
  6078. struct lpfc_sli *psli = &phba->sli;
  6079. struct lpfc_sli_ring *pring;
  6080. struct lpfc_dmabuf *buf_ptr;
  6081. unsigned long flags = 0;
  6082. int i;
  6083. /* Shutdown the mailbox command sub-system */
  6084. lpfc_sli_mbox_sys_shutdown(phba);
  6085. lpfc_hba_down_prep(phba);
  6086. lpfc_fabric_abort_hba(phba);
  6087. spin_lock_irqsave(&phba->hbalock, flags);
  6088. for (i = 0; i < psli->num_rings; i++) {
  6089. pring = &psli->ring[i];
  6090. /* Only slow rings */
  6091. if (pring->ringno == LPFC_ELS_RING) {
  6092. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6093. /* Set the lpfc data pending flag */
  6094. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6095. }
  6096. /*
  6097. * Error everything on the txq since these iocbs have not been
  6098. * given to the FW yet.
  6099. */
  6100. list_splice_init(&pring->txq, &completions);
  6101. pring->txq_cnt = 0;
  6102. }
  6103. spin_unlock_irqrestore(&phba->hbalock, flags);
  6104. /* Cancel all the IOCBs from the completions list */
  6105. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6106. IOERR_SLI_DOWN);
  6107. spin_lock_irqsave(&phba->hbalock, flags);
  6108. list_splice_init(&phba->elsbuf, &completions);
  6109. phba->elsbuf_cnt = 0;
  6110. phba->elsbuf_prev_cnt = 0;
  6111. spin_unlock_irqrestore(&phba->hbalock, flags);
  6112. while (!list_empty(&completions)) {
  6113. list_remove_head(&completions, buf_ptr,
  6114. struct lpfc_dmabuf, list);
  6115. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6116. kfree(buf_ptr);
  6117. }
  6118. /* Return any active mbox cmds */
  6119. del_timer_sync(&psli->mbox_tmo);
  6120. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6121. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6122. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6123. return 1;
  6124. }
  6125. /**
  6126. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6127. * @phba: Pointer to HBA context object.
  6128. *
  6129. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6130. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6131. * lock held and always returns 1.
  6132. *
  6133. * This function does the following to cleanup driver FCoE function resources:
  6134. * - Free discovery resources for each virtual port
  6135. * - Cleanup any pending fabric iocbs
  6136. * - Iterate through the iocb txq and free each entry in the list.
  6137. * - Free up any buffer posted to the HBA.
  6138. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6139. * - Free mailbox commands in the mailbox queue.
  6140. **/
  6141. int
  6142. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6143. {
  6144. /* Stop the SLI4 device port */
  6145. lpfc_stop_port(phba);
  6146. /* Tear down the queues in the HBA */
  6147. lpfc_sli4_queue_unset(phba);
  6148. /* unregister default FCFI from the HBA */
  6149. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6150. return 1;
  6151. }
  6152. /**
  6153. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6154. * @srcp: Source memory pointer.
  6155. * @destp: Destination memory pointer.
  6156. * @cnt: Number of words required to be copied.
  6157. *
  6158. * This function is used for copying data between driver memory
  6159. * and the SLI memory. This function also changes the endianness
  6160. * of each word if native endianness is different from SLI
  6161. * endianness. This function can be called with or without
  6162. * lock.
  6163. **/
  6164. void
  6165. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6166. {
  6167. uint32_t *src = srcp;
  6168. uint32_t *dest = destp;
  6169. uint32_t ldata;
  6170. int i;
  6171. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6172. ldata = *src;
  6173. ldata = le32_to_cpu(ldata);
  6174. *dest = ldata;
  6175. src++;
  6176. dest++;
  6177. }
  6178. }
  6179. /**
  6180. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6181. * @srcp: Source memory pointer.
  6182. * @destp: Destination memory pointer.
  6183. * @cnt: Number of words required to be copied.
  6184. *
  6185. * This function is used for copying data between a data structure
  6186. * with big endian representation to local endianness.
  6187. * This function can be called with or without lock.
  6188. **/
  6189. void
  6190. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6191. {
  6192. uint32_t *src = srcp;
  6193. uint32_t *dest = destp;
  6194. uint32_t ldata;
  6195. int i;
  6196. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6197. ldata = *src;
  6198. ldata = be32_to_cpu(ldata);
  6199. *dest = ldata;
  6200. src++;
  6201. dest++;
  6202. }
  6203. }
  6204. /**
  6205. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6206. * @phba: Pointer to HBA context object.
  6207. * @pring: Pointer to driver SLI ring object.
  6208. * @mp: Pointer to driver buffer object.
  6209. *
  6210. * This function is called with no lock held.
  6211. * It always return zero after adding the buffer to the postbufq
  6212. * buffer list.
  6213. **/
  6214. int
  6215. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6216. struct lpfc_dmabuf *mp)
  6217. {
  6218. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6219. later */
  6220. spin_lock_irq(&phba->hbalock);
  6221. list_add_tail(&mp->list, &pring->postbufq);
  6222. pring->postbufq_cnt++;
  6223. spin_unlock_irq(&phba->hbalock);
  6224. return 0;
  6225. }
  6226. /**
  6227. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6228. * @phba: Pointer to HBA context object.
  6229. *
  6230. * When HBQ is enabled, buffers are searched based on tags. This function
  6231. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6232. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6233. * does not conflict with tags of buffer posted for unsolicited events.
  6234. * The function returns the allocated tag. The function is called with
  6235. * no locks held.
  6236. **/
  6237. uint32_t
  6238. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6239. {
  6240. spin_lock_irq(&phba->hbalock);
  6241. phba->buffer_tag_count++;
  6242. /*
  6243. * Always set the QUE_BUFTAG_BIT to distiguish between
  6244. * a tag assigned by HBQ.
  6245. */
  6246. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6247. spin_unlock_irq(&phba->hbalock);
  6248. return phba->buffer_tag_count;
  6249. }
  6250. /**
  6251. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6252. * @phba: Pointer to HBA context object.
  6253. * @pring: Pointer to driver SLI ring object.
  6254. * @tag: Buffer tag.
  6255. *
  6256. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6257. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6258. * iocb is posted to the response ring with the tag of the buffer.
  6259. * This function searches the pring->postbufq list using the tag
  6260. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6261. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6262. * buffer is returned to the caller else NULL is returned.
  6263. * This function is called with no lock held.
  6264. **/
  6265. struct lpfc_dmabuf *
  6266. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6267. uint32_t tag)
  6268. {
  6269. struct lpfc_dmabuf *mp, *next_mp;
  6270. struct list_head *slp = &pring->postbufq;
  6271. /* Search postbufq, from the begining, looking for a match on tag */
  6272. spin_lock_irq(&phba->hbalock);
  6273. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6274. if (mp->buffer_tag == tag) {
  6275. list_del_init(&mp->list);
  6276. pring->postbufq_cnt--;
  6277. spin_unlock_irq(&phba->hbalock);
  6278. return mp;
  6279. }
  6280. }
  6281. spin_unlock_irq(&phba->hbalock);
  6282. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6283. "0402 Cannot find virtual addr for buffer tag on "
  6284. "ring %d Data x%lx x%p x%p x%x\n",
  6285. pring->ringno, (unsigned long) tag,
  6286. slp->next, slp->prev, pring->postbufq_cnt);
  6287. return NULL;
  6288. }
  6289. /**
  6290. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6291. * @phba: Pointer to HBA context object.
  6292. * @pring: Pointer to driver SLI ring object.
  6293. * @phys: DMA address of the buffer.
  6294. *
  6295. * This function searches the buffer list using the dma_address
  6296. * of unsolicited event to find the driver's lpfc_dmabuf object
  6297. * corresponding to the dma_address. The function returns the
  6298. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6299. * This function is called by the ct and els unsolicited event
  6300. * handlers to get the buffer associated with the unsolicited
  6301. * event.
  6302. *
  6303. * This function is called with no lock held.
  6304. **/
  6305. struct lpfc_dmabuf *
  6306. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6307. dma_addr_t phys)
  6308. {
  6309. struct lpfc_dmabuf *mp, *next_mp;
  6310. struct list_head *slp = &pring->postbufq;
  6311. /* Search postbufq, from the begining, looking for a match on phys */
  6312. spin_lock_irq(&phba->hbalock);
  6313. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6314. if (mp->phys == phys) {
  6315. list_del_init(&mp->list);
  6316. pring->postbufq_cnt--;
  6317. spin_unlock_irq(&phba->hbalock);
  6318. return mp;
  6319. }
  6320. }
  6321. spin_unlock_irq(&phba->hbalock);
  6322. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6323. "0410 Cannot find virtual addr for mapped buf on "
  6324. "ring %d Data x%llx x%p x%p x%x\n",
  6325. pring->ringno, (unsigned long long)phys,
  6326. slp->next, slp->prev, pring->postbufq_cnt);
  6327. return NULL;
  6328. }
  6329. /**
  6330. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6331. * @phba: Pointer to HBA context object.
  6332. * @cmdiocb: Pointer to driver command iocb object.
  6333. * @rspiocb: Pointer to driver response iocb object.
  6334. *
  6335. * This function is the completion handler for the abort iocbs for
  6336. * ELS commands. This function is called from the ELS ring event
  6337. * handler with no lock held. This function frees memory resources
  6338. * associated with the abort iocb.
  6339. **/
  6340. static void
  6341. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6342. struct lpfc_iocbq *rspiocb)
  6343. {
  6344. IOCB_t *irsp = &rspiocb->iocb;
  6345. uint16_t abort_iotag, abort_context;
  6346. struct lpfc_iocbq *abort_iocb;
  6347. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6348. abort_iocb = NULL;
  6349. if (irsp->ulpStatus) {
  6350. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6351. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6352. spin_lock_irq(&phba->hbalock);
  6353. if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
  6354. abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
  6355. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
  6356. "0327 Cannot abort els iocb %p "
  6357. "with tag %x context %x, abort status %x, "
  6358. "abort code %x\n",
  6359. abort_iocb, abort_iotag, abort_context,
  6360. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6361. /*
  6362. * If the iocb is not found in Firmware queue the iocb
  6363. * might have completed already. Do not free it again.
  6364. */
  6365. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6366. spin_unlock_irq(&phba->hbalock);
  6367. lpfc_sli_release_iocbq(phba, cmdiocb);
  6368. return;
  6369. }
  6370. /*
  6371. * make sure we have the right iocbq before taking it
  6372. * off the txcmplq and try to call completion routine.
  6373. */
  6374. if (!abort_iocb ||
  6375. abort_iocb->iocb.ulpContext != abort_context ||
  6376. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6377. spin_unlock_irq(&phba->hbalock);
  6378. else {
  6379. list_del_init(&abort_iocb->list);
  6380. pring->txcmplq_cnt--;
  6381. spin_unlock_irq(&phba->hbalock);
  6382. /* Firmware could still be in progress of DMAing
  6383. * payload, so don't free data buffer till after
  6384. * a hbeat.
  6385. */
  6386. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6387. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6388. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6389. abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
  6390. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6391. }
  6392. }
  6393. lpfc_sli_release_iocbq(phba, cmdiocb);
  6394. return;
  6395. }
  6396. /**
  6397. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6398. * @phba: Pointer to HBA context object.
  6399. * @cmdiocb: Pointer to driver command iocb object.
  6400. * @rspiocb: Pointer to driver response iocb object.
  6401. *
  6402. * The function is called from SLI ring event handler with no
  6403. * lock held. This function is the completion handler for ELS commands
  6404. * which are aborted. The function frees memory resources used for
  6405. * the aborted ELS commands.
  6406. **/
  6407. static void
  6408. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6409. struct lpfc_iocbq *rspiocb)
  6410. {
  6411. IOCB_t *irsp = &rspiocb->iocb;
  6412. /* ELS cmd tag <ulpIoTag> completes */
  6413. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6414. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6415. "x%x x%x x%x\n",
  6416. irsp->ulpIoTag, irsp->ulpStatus,
  6417. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6418. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6419. lpfc_ct_free_iocb(phba, cmdiocb);
  6420. else
  6421. lpfc_els_free_iocb(phba, cmdiocb);
  6422. return;
  6423. }
  6424. /**
  6425. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6426. * @phba: Pointer to HBA context object.
  6427. * @pring: Pointer to driver SLI ring object.
  6428. * @cmdiocb: Pointer to driver command iocb object.
  6429. *
  6430. * This function issues an abort iocb for the provided command
  6431. * iocb. This function is called with hbalock held.
  6432. * The function returns 0 when it fails due to memory allocation
  6433. * failure or when the command iocb is an abort request.
  6434. **/
  6435. int
  6436. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6437. struct lpfc_iocbq *cmdiocb)
  6438. {
  6439. struct lpfc_vport *vport = cmdiocb->vport;
  6440. struct lpfc_iocbq *abtsiocbp;
  6441. IOCB_t *icmd = NULL;
  6442. IOCB_t *iabt = NULL;
  6443. int retval = IOCB_ERROR;
  6444. /*
  6445. * There are certain command types we don't want to abort. And we
  6446. * don't want to abort commands that are already in the process of
  6447. * being aborted.
  6448. */
  6449. icmd = &cmdiocb->iocb;
  6450. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6451. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6452. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6453. return 0;
  6454. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6455. * callback so that nothing happens when it finishes.
  6456. */
  6457. if ((vport->load_flag & FC_UNLOADING) &&
  6458. (pring->ringno == LPFC_ELS_RING)) {
  6459. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6460. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6461. else
  6462. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6463. goto abort_iotag_exit;
  6464. }
  6465. /* issue ABTS for this IOCB based on iotag */
  6466. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6467. if (abtsiocbp == NULL)
  6468. return 0;
  6469. /* This signals the response to set the correct status
  6470. * before calling the completion handler.
  6471. */
  6472. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6473. iabt = &abtsiocbp->iocb;
  6474. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6475. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6476. if (phba->sli_rev == LPFC_SLI_REV4)
  6477. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6478. else
  6479. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6480. iabt->ulpLe = 1;
  6481. iabt->ulpClass = icmd->ulpClass;
  6482. if (phba->link_state >= LPFC_LINK_UP)
  6483. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6484. else
  6485. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6486. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6487. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6488. "0339 Abort xri x%x, original iotag x%x, "
  6489. "abort cmd iotag x%x\n",
  6490. iabt->un.acxri.abortContextTag,
  6491. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  6492. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6493. if (retval)
  6494. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6495. abort_iotag_exit:
  6496. /*
  6497. * Caller to this routine should check for IOCB_ERROR
  6498. * and handle it properly. This routine no longer removes
  6499. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6500. */
  6501. return retval;
  6502. }
  6503. /**
  6504. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6505. * @iocbq: Pointer to driver iocb object.
  6506. * @vport: Pointer to driver virtual port object.
  6507. * @tgt_id: SCSI ID of the target.
  6508. * @lun_id: LUN ID of the scsi device.
  6509. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6510. *
  6511. * This function acts as an iocb filter for functions which abort or count
  6512. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6513. * 0 if the filtering criteria is met for the given iocb and will return
  6514. * 1 if the filtering criteria is not met.
  6515. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6516. * given iocb is for the SCSI device specified by vport, tgt_id and
  6517. * lun_id parameter.
  6518. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6519. * given iocb is for the SCSI target specified by vport and tgt_id
  6520. * parameters.
  6521. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6522. * given iocb is for the SCSI host associated with the given vport.
  6523. * This function is called with no locks held.
  6524. **/
  6525. static int
  6526. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6527. uint16_t tgt_id, uint64_t lun_id,
  6528. lpfc_ctx_cmd ctx_cmd)
  6529. {
  6530. struct lpfc_scsi_buf *lpfc_cmd;
  6531. int rc = 1;
  6532. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6533. return rc;
  6534. if (iocbq->vport != vport)
  6535. return rc;
  6536. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6537. if (lpfc_cmd->pCmd == NULL)
  6538. return rc;
  6539. switch (ctx_cmd) {
  6540. case LPFC_CTX_LUN:
  6541. if ((lpfc_cmd->rdata->pnode) &&
  6542. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6543. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6544. rc = 0;
  6545. break;
  6546. case LPFC_CTX_TGT:
  6547. if ((lpfc_cmd->rdata->pnode) &&
  6548. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6549. rc = 0;
  6550. break;
  6551. case LPFC_CTX_HOST:
  6552. rc = 0;
  6553. break;
  6554. default:
  6555. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6556. __func__, ctx_cmd);
  6557. break;
  6558. }
  6559. return rc;
  6560. }
  6561. /**
  6562. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6563. * @vport: Pointer to virtual port.
  6564. * @tgt_id: SCSI ID of the target.
  6565. * @lun_id: LUN ID of the scsi device.
  6566. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6567. *
  6568. * This function returns number of FCP commands pending for the vport.
  6569. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6570. * commands pending on the vport associated with SCSI device specified
  6571. * by tgt_id and lun_id parameters.
  6572. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6573. * commands pending on the vport associated with SCSI target specified
  6574. * by tgt_id parameter.
  6575. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6576. * commands pending on the vport.
  6577. * This function returns the number of iocbs which satisfy the filter.
  6578. * This function is called without any lock held.
  6579. **/
  6580. int
  6581. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6582. lpfc_ctx_cmd ctx_cmd)
  6583. {
  6584. struct lpfc_hba *phba = vport->phba;
  6585. struct lpfc_iocbq *iocbq;
  6586. int sum, i;
  6587. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6588. iocbq = phba->sli.iocbq_lookup[i];
  6589. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6590. ctx_cmd) == 0)
  6591. sum++;
  6592. }
  6593. return sum;
  6594. }
  6595. /**
  6596. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6597. * @phba: Pointer to HBA context object
  6598. * @cmdiocb: Pointer to command iocb object.
  6599. * @rspiocb: Pointer to response iocb object.
  6600. *
  6601. * This function is called when an aborted FCP iocb completes. This
  6602. * function is called by the ring event handler with no lock held.
  6603. * This function frees the iocb.
  6604. **/
  6605. void
  6606. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6607. struct lpfc_iocbq *rspiocb)
  6608. {
  6609. lpfc_sli_release_iocbq(phba, cmdiocb);
  6610. return;
  6611. }
  6612. /**
  6613. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6614. * @vport: Pointer to virtual port.
  6615. * @pring: Pointer to driver SLI ring object.
  6616. * @tgt_id: SCSI ID of the target.
  6617. * @lun_id: LUN ID of the scsi device.
  6618. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6619. *
  6620. * This function sends an abort command for every SCSI command
  6621. * associated with the given virtual port pending on the ring
  6622. * filtered by lpfc_sli_validate_fcp_iocb function.
  6623. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6624. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6625. * parameters
  6626. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6627. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6628. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6629. * FCP iocbs associated with virtual port.
  6630. * This function returns number of iocbs it failed to abort.
  6631. * This function is called with no locks held.
  6632. **/
  6633. int
  6634. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6635. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6636. {
  6637. struct lpfc_hba *phba = vport->phba;
  6638. struct lpfc_iocbq *iocbq;
  6639. struct lpfc_iocbq *abtsiocb;
  6640. IOCB_t *cmd = NULL;
  6641. int errcnt = 0, ret_val = 0;
  6642. int i;
  6643. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6644. iocbq = phba->sli.iocbq_lookup[i];
  6645. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6646. abort_cmd) != 0)
  6647. continue;
  6648. /* issue ABTS for this IOCB based on iotag */
  6649. abtsiocb = lpfc_sli_get_iocbq(phba);
  6650. if (abtsiocb == NULL) {
  6651. errcnt++;
  6652. continue;
  6653. }
  6654. cmd = &iocbq->iocb;
  6655. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6656. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6657. if (phba->sli_rev == LPFC_SLI_REV4)
  6658. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6659. else
  6660. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6661. abtsiocb->iocb.ulpLe = 1;
  6662. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6663. abtsiocb->vport = phba->pport;
  6664. if (lpfc_is_link_up(phba))
  6665. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6666. else
  6667. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6668. /* Setup callback routine and issue the command. */
  6669. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6670. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6671. abtsiocb, 0);
  6672. if (ret_val == IOCB_ERROR) {
  6673. lpfc_sli_release_iocbq(phba, abtsiocb);
  6674. errcnt++;
  6675. continue;
  6676. }
  6677. }
  6678. return errcnt;
  6679. }
  6680. /**
  6681. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6682. * @phba: Pointer to HBA context object.
  6683. * @cmdiocbq: Pointer to command iocb.
  6684. * @rspiocbq: Pointer to response iocb.
  6685. *
  6686. * This function is the completion handler for iocbs issued using
  6687. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6688. * ring event handler function without any lock held. This function
  6689. * can be called from both worker thread context and interrupt
  6690. * context. This function also can be called from other thread which
  6691. * cleans up the SLI layer objects.
  6692. * This function copy the contents of the response iocb to the
  6693. * response iocb memory object provided by the caller of
  6694. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6695. * sleeps for the iocb completion.
  6696. **/
  6697. static void
  6698. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6699. struct lpfc_iocbq *cmdiocbq,
  6700. struct lpfc_iocbq *rspiocbq)
  6701. {
  6702. wait_queue_head_t *pdone_q;
  6703. unsigned long iflags;
  6704. spin_lock_irqsave(&phba->hbalock, iflags);
  6705. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6706. if (cmdiocbq->context2 && rspiocbq)
  6707. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6708. &rspiocbq->iocb, sizeof(IOCB_t));
  6709. pdone_q = cmdiocbq->context_un.wait_queue;
  6710. if (pdone_q)
  6711. wake_up(pdone_q);
  6712. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6713. return;
  6714. }
  6715. /**
  6716. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  6717. * @phba: Pointer to HBA context object..
  6718. * @piocbq: Pointer to command iocb.
  6719. * @flag: Flag to test.
  6720. *
  6721. * This routine grabs the hbalock and then test the iocb_flag to
  6722. * see if the passed in flag is set.
  6723. * Returns:
  6724. * 1 if flag is set.
  6725. * 0 if flag is not set.
  6726. **/
  6727. static int
  6728. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  6729. struct lpfc_iocbq *piocbq, uint32_t flag)
  6730. {
  6731. unsigned long iflags;
  6732. int ret;
  6733. spin_lock_irqsave(&phba->hbalock, iflags);
  6734. ret = piocbq->iocb_flag & flag;
  6735. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6736. return ret;
  6737. }
  6738. /**
  6739. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6740. * @phba: Pointer to HBA context object..
  6741. * @pring: Pointer to sli ring.
  6742. * @piocb: Pointer to command iocb.
  6743. * @prspiocbq: Pointer to response iocb.
  6744. * @timeout: Timeout in number of seconds.
  6745. *
  6746. * This function issues the iocb to firmware and waits for the
  6747. * iocb to complete. If the iocb command is not
  6748. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6749. * Caller should not free the iocb resources if this function
  6750. * returns IOCB_TIMEDOUT.
  6751. * The function waits for the iocb completion using an
  6752. * non-interruptible wait.
  6753. * This function will sleep while waiting for iocb completion.
  6754. * So, this function should not be called from any context which
  6755. * does not allow sleeping. Due to the same reason, this function
  6756. * cannot be called with interrupt disabled.
  6757. * This function assumes that the iocb completions occur while
  6758. * this function sleep. So, this function cannot be called from
  6759. * the thread which process iocb completion for this ring.
  6760. * This function clears the iocb_flag of the iocb object before
  6761. * issuing the iocb and the iocb completion handler sets this
  6762. * flag and wakes this thread when the iocb completes.
  6763. * The contents of the response iocb will be copied to prspiocbq
  6764. * by the completion handler when the command completes.
  6765. * This function returns IOCB_SUCCESS when success.
  6766. * This function is called with no lock held.
  6767. **/
  6768. int
  6769. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6770. uint32_t ring_number,
  6771. struct lpfc_iocbq *piocb,
  6772. struct lpfc_iocbq *prspiocbq,
  6773. uint32_t timeout)
  6774. {
  6775. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6776. long timeleft, timeout_req = 0;
  6777. int retval = IOCB_SUCCESS;
  6778. uint32_t creg_val;
  6779. /*
  6780. * If the caller has provided a response iocbq buffer, then context2
  6781. * is NULL or its an error.
  6782. */
  6783. if (prspiocbq) {
  6784. if (piocb->context2)
  6785. return IOCB_ERROR;
  6786. piocb->context2 = prspiocbq;
  6787. }
  6788. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6789. piocb->context_un.wait_queue = &done_q;
  6790. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6791. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6792. creg_val = readl(phba->HCregaddr);
  6793. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6794. writel(creg_val, phba->HCregaddr);
  6795. readl(phba->HCregaddr); /* flush */
  6796. }
  6797. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
  6798. if (retval == IOCB_SUCCESS) {
  6799. timeout_req = timeout * HZ;
  6800. timeleft = wait_event_timeout(done_q,
  6801. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  6802. timeout_req);
  6803. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6804. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6805. "0331 IOCB wake signaled\n");
  6806. } else if (timeleft == 0) {
  6807. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6808. "0338 IOCB wait timeout error - no "
  6809. "wake response Data x%x\n", timeout);
  6810. retval = IOCB_TIMEDOUT;
  6811. } else {
  6812. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6813. "0330 IOCB wake NOT set, "
  6814. "Data x%x x%lx\n",
  6815. timeout, (timeleft / jiffies));
  6816. retval = IOCB_TIMEDOUT;
  6817. }
  6818. } else {
  6819. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6820. "0332 IOCB wait issue failed, Data x%x\n",
  6821. retval);
  6822. retval = IOCB_ERROR;
  6823. }
  6824. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6825. creg_val = readl(phba->HCregaddr);
  6826. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6827. writel(creg_val, phba->HCregaddr);
  6828. readl(phba->HCregaddr); /* flush */
  6829. }
  6830. if (prspiocbq)
  6831. piocb->context2 = NULL;
  6832. piocb->context_un.wait_queue = NULL;
  6833. piocb->iocb_cmpl = NULL;
  6834. return retval;
  6835. }
  6836. /**
  6837. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  6838. * @phba: Pointer to HBA context object.
  6839. * @pmboxq: Pointer to driver mailbox object.
  6840. * @timeout: Timeout in number of seconds.
  6841. *
  6842. * This function issues the mailbox to firmware and waits for the
  6843. * mailbox command to complete. If the mailbox command is not
  6844. * completed within timeout seconds, it returns MBX_TIMEOUT.
  6845. * The function waits for the mailbox completion using an
  6846. * interruptible wait. If the thread is woken up due to a
  6847. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  6848. * should not free the mailbox resources, if this function returns
  6849. * MBX_TIMEOUT.
  6850. * This function will sleep while waiting for mailbox completion.
  6851. * So, this function should not be called from any context which
  6852. * does not allow sleeping. Due to the same reason, this function
  6853. * cannot be called with interrupt disabled.
  6854. * This function assumes that the mailbox completion occurs while
  6855. * this function sleep. So, this function cannot be called from
  6856. * the worker thread which processes mailbox completion.
  6857. * This function is called in the context of HBA management
  6858. * applications.
  6859. * This function returns MBX_SUCCESS when successful.
  6860. * This function is called with no lock held.
  6861. **/
  6862. int
  6863. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  6864. uint32_t timeout)
  6865. {
  6866. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6867. int retval;
  6868. unsigned long flag;
  6869. /* The caller must leave context1 empty. */
  6870. if (pmboxq->context1)
  6871. return MBX_NOT_FINISHED;
  6872. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  6873. /* setup wake call as IOCB callback */
  6874. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  6875. /* setup context field to pass wait_queue pointer to wake function */
  6876. pmboxq->context1 = &done_q;
  6877. /* now issue the command */
  6878. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  6879. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  6880. wait_event_interruptible_timeout(done_q,
  6881. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  6882. timeout * HZ);
  6883. spin_lock_irqsave(&phba->hbalock, flag);
  6884. pmboxq->context1 = NULL;
  6885. /*
  6886. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  6887. * else do not free the resources.
  6888. */
  6889. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  6890. retval = MBX_SUCCESS;
  6891. else {
  6892. retval = MBX_TIMEOUT;
  6893. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  6894. }
  6895. spin_unlock_irqrestore(&phba->hbalock, flag);
  6896. }
  6897. return retval;
  6898. }
  6899. /**
  6900. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  6901. * @phba: Pointer to HBA context.
  6902. *
  6903. * This function is called to shutdown the driver's mailbox sub-system.
  6904. * It first marks the mailbox sub-system is in a block state to prevent
  6905. * the asynchronous mailbox command from issued off the pending mailbox
  6906. * command queue. If the mailbox command sub-system shutdown is due to
  6907. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  6908. * the mailbox sub-system flush routine to forcefully bring down the
  6909. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  6910. * as with offline or HBA function reset), this routine will wait for the
  6911. * outstanding mailbox command to complete before invoking the mailbox
  6912. * sub-system flush routine to gracefully bring down mailbox sub-system.
  6913. **/
  6914. void
  6915. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  6916. {
  6917. struct lpfc_sli *psli = &phba->sli;
  6918. uint8_t actcmd = MBX_HEARTBEAT;
  6919. unsigned long timeout;
  6920. spin_lock_irq(&phba->hbalock);
  6921. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6922. spin_unlock_irq(&phba->hbalock);
  6923. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6924. spin_lock_irq(&phba->hbalock);
  6925. if (phba->sli.mbox_active)
  6926. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  6927. spin_unlock_irq(&phba->hbalock);
  6928. /* Determine how long we might wait for the active mailbox
  6929. * command to be gracefully completed by firmware.
  6930. */
  6931. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  6932. 1000) + jiffies;
  6933. while (phba->sli.mbox_active) {
  6934. /* Check active mailbox complete status every 2ms */
  6935. msleep(2);
  6936. if (time_after(jiffies, timeout))
  6937. /* Timeout, let the mailbox flush routine to
  6938. * forcefully release active mailbox command
  6939. */
  6940. break;
  6941. }
  6942. }
  6943. lpfc_sli_mbox_sys_flush(phba);
  6944. }
  6945. /**
  6946. * lpfc_sli_eratt_read - read sli-3 error attention events
  6947. * @phba: Pointer to HBA context.
  6948. *
  6949. * This function is called to read the SLI3 device error attention registers
  6950. * for possible error attention events. The caller must hold the hostlock
  6951. * with spin_lock_irq().
  6952. *
  6953. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6954. * Register and returns 0 otherwise.
  6955. **/
  6956. static int
  6957. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  6958. {
  6959. uint32_t ha_copy;
  6960. /* Read chip Host Attention (HA) register */
  6961. ha_copy = readl(phba->HAregaddr);
  6962. if (ha_copy & HA_ERATT) {
  6963. /* Read host status register to retrieve error event */
  6964. lpfc_sli_read_hs(phba);
  6965. /* Check if there is a deferred error condition is active */
  6966. if ((HS_FFER1 & phba->work_hs) &&
  6967. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  6968. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  6969. phba->hba_flag |= DEFER_ERATT;
  6970. /* Clear all interrupt enable conditions */
  6971. writel(0, phba->HCregaddr);
  6972. readl(phba->HCregaddr);
  6973. }
  6974. /* Set the driver HA work bitmap */
  6975. phba->work_ha |= HA_ERATT;
  6976. /* Indicate polling handles this ERATT */
  6977. phba->hba_flag |= HBA_ERATT_HANDLED;
  6978. return 1;
  6979. }
  6980. return 0;
  6981. }
  6982. /**
  6983. * lpfc_sli4_eratt_read - read sli-4 error attention events
  6984. * @phba: Pointer to HBA context.
  6985. *
  6986. * This function is called to read the SLI4 device error attention registers
  6987. * for possible error attention events. The caller must hold the hostlock
  6988. * with spin_lock_irq().
  6989. *
  6990. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6991. * Register and returns 0 otherwise.
  6992. **/
  6993. static int
  6994. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  6995. {
  6996. uint32_t uerr_sta_hi, uerr_sta_lo;
  6997. uint32_t onlnreg0, onlnreg1;
  6998. /* For now, use the SLI4 device internal unrecoverable error
  6999. * registers for error attention. This can be changed later.
  7000. */
  7001. onlnreg0 = readl(phba->sli4_hba.ONLINE0regaddr);
  7002. onlnreg1 = readl(phba->sli4_hba.ONLINE1regaddr);
  7003. if ((onlnreg0 != LPFC_ONLINE_NERR) || (onlnreg1 != LPFC_ONLINE_NERR)) {
  7004. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  7005. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  7006. if (uerr_sta_lo || uerr_sta_hi) {
  7007. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7008. "1423 HBA Unrecoverable error: "
  7009. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7010. "online0_reg=0x%x, online1_reg=0x%x\n",
  7011. uerr_sta_lo, uerr_sta_hi,
  7012. onlnreg0, onlnreg1);
  7013. phba->work_status[0] = uerr_sta_lo;
  7014. phba->work_status[1] = uerr_sta_hi;
  7015. /* Set the driver HA work bitmap */
  7016. phba->work_ha |= HA_ERATT;
  7017. /* Indicate polling handles this ERATT */
  7018. phba->hba_flag |= HBA_ERATT_HANDLED;
  7019. return 1;
  7020. }
  7021. }
  7022. return 0;
  7023. }
  7024. /**
  7025. * lpfc_sli_check_eratt - check error attention events
  7026. * @phba: Pointer to HBA context.
  7027. *
  7028. * This function is called from timer soft interrupt context to check HBA's
  7029. * error attention register bit for error attention events.
  7030. *
  7031. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7032. * Register and returns 0 otherwise.
  7033. **/
  7034. int
  7035. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7036. {
  7037. uint32_t ha_copy;
  7038. /* If somebody is waiting to handle an eratt, don't process it
  7039. * here. The brdkill function will do this.
  7040. */
  7041. if (phba->link_flag & LS_IGNORE_ERATT)
  7042. return 0;
  7043. /* Check if interrupt handler handles this ERATT */
  7044. spin_lock_irq(&phba->hbalock);
  7045. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7046. /* Interrupt handler has handled ERATT */
  7047. spin_unlock_irq(&phba->hbalock);
  7048. return 0;
  7049. }
  7050. /*
  7051. * If there is deferred error attention, do not check for error
  7052. * attention
  7053. */
  7054. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7055. spin_unlock_irq(&phba->hbalock);
  7056. return 0;
  7057. }
  7058. /* If PCI channel is offline, don't process it */
  7059. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7060. spin_unlock_irq(&phba->hbalock);
  7061. return 0;
  7062. }
  7063. switch (phba->sli_rev) {
  7064. case LPFC_SLI_REV2:
  7065. case LPFC_SLI_REV3:
  7066. /* Read chip Host Attention (HA) register */
  7067. ha_copy = lpfc_sli_eratt_read(phba);
  7068. break;
  7069. case LPFC_SLI_REV4:
  7070. /* Read devcie Uncoverable Error (UERR) registers */
  7071. ha_copy = lpfc_sli4_eratt_read(phba);
  7072. break;
  7073. default:
  7074. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7075. "0299 Invalid SLI revision (%d)\n",
  7076. phba->sli_rev);
  7077. ha_copy = 0;
  7078. break;
  7079. }
  7080. spin_unlock_irq(&phba->hbalock);
  7081. return ha_copy;
  7082. }
  7083. /**
  7084. * lpfc_intr_state_check - Check device state for interrupt handling
  7085. * @phba: Pointer to HBA context.
  7086. *
  7087. * This inline routine checks whether a device or its PCI slot is in a state
  7088. * that the interrupt should be handled.
  7089. *
  7090. * This function returns 0 if the device or the PCI slot is in a state that
  7091. * interrupt should be handled, otherwise -EIO.
  7092. */
  7093. static inline int
  7094. lpfc_intr_state_check(struct lpfc_hba *phba)
  7095. {
  7096. /* If the pci channel is offline, ignore all the interrupts */
  7097. if (unlikely(pci_channel_offline(phba->pcidev)))
  7098. return -EIO;
  7099. /* Update device level interrupt statistics */
  7100. phba->sli.slistat.sli_intr++;
  7101. /* Ignore all interrupts during initialization. */
  7102. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7103. return -EIO;
  7104. return 0;
  7105. }
  7106. /**
  7107. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7108. * @irq: Interrupt number.
  7109. * @dev_id: The device context pointer.
  7110. *
  7111. * This function is directly called from the PCI layer as an interrupt
  7112. * service routine when device with SLI-3 interface spec is enabled with
  7113. * MSI-X multi-message interrupt mode and there are slow-path events in
  7114. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7115. * interrupt mode, this function is called as part of the device-level
  7116. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7117. * is undergoing initialization, the interrupt handler will not process
  7118. * the interrupt. The link attention and ELS ring attention events are
  7119. * handled by the worker thread. The interrupt handler signals the worker
  7120. * thread and returns for these events. This function is called without
  7121. * any lock held. It gets the hbalock to access and update SLI data
  7122. * structures.
  7123. *
  7124. * This function returns IRQ_HANDLED when interrupt is handled else it
  7125. * returns IRQ_NONE.
  7126. **/
  7127. irqreturn_t
  7128. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7129. {
  7130. struct lpfc_hba *phba;
  7131. uint32_t ha_copy;
  7132. uint32_t work_ha_copy;
  7133. unsigned long status;
  7134. unsigned long iflag;
  7135. uint32_t control;
  7136. MAILBOX_t *mbox, *pmbox;
  7137. struct lpfc_vport *vport;
  7138. struct lpfc_nodelist *ndlp;
  7139. struct lpfc_dmabuf *mp;
  7140. LPFC_MBOXQ_t *pmb;
  7141. int rc;
  7142. /*
  7143. * Get the driver's phba structure from the dev_id and
  7144. * assume the HBA is not interrupting.
  7145. */
  7146. phba = (struct lpfc_hba *)dev_id;
  7147. if (unlikely(!phba))
  7148. return IRQ_NONE;
  7149. /*
  7150. * Stuff needs to be attented to when this function is invoked as an
  7151. * individual interrupt handler in MSI-X multi-message interrupt mode
  7152. */
  7153. if (phba->intr_type == MSIX) {
  7154. /* Check device state for handling interrupt */
  7155. if (lpfc_intr_state_check(phba))
  7156. return IRQ_NONE;
  7157. /* Need to read HA REG for slow-path events */
  7158. spin_lock_irqsave(&phba->hbalock, iflag);
  7159. ha_copy = readl(phba->HAregaddr);
  7160. /* If somebody is waiting to handle an eratt don't process it
  7161. * here. The brdkill function will do this.
  7162. */
  7163. if (phba->link_flag & LS_IGNORE_ERATT)
  7164. ha_copy &= ~HA_ERATT;
  7165. /* Check the need for handling ERATT in interrupt handler */
  7166. if (ha_copy & HA_ERATT) {
  7167. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7168. /* ERATT polling has handled ERATT */
  7169. ha_copy &= ~HA_ERATT;
  7170. else
  7171. /* Indicate interrupt handler handles ERATT */
  7172. phba->hba_flag |= HBA_ERATT_HANDLED;
  7173. }
  7174. /*
  7175. * If there is deferred error attention, do not check for any
  7176. * interrupt.
  7177. */
  7178. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7179. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7180. return IRQ_NONE;
  7181. }
  7182. /* Clear up only attention source related to slow-path */
  7183. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7184. phba->HAregaddr);
  7185. readl(phba->HAregaddr); /* flush */
  7186. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7187. } else
  7188. ha_copy = phba->ha_copy;
  7189. work_ha_copy = ha_copy & phba->work_ha_mask;
  7190. if (work_ha_copy) {
  7191. if (work_ha_copy & HA_LATT) {
  7192. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7193. /*
  7194. * Turn off Link Attention interrupts
  7195. * until CLEAR_LA done
  7196. */
  7197. spin_lock_irqsave(&phba->hbalock, iflag);
  7198. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7199. control = readl(phba->HCregaddr);
  7200. control &= ~HC_LAINT_ENA;
  7201. writel(control, phba->HCregaddr);
  7202. readl(phba->HCregaddr); /* flush */
  7203. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7204. }
  7205. else
  7206. work_ha_copy &= ~HA_LATT;
  7207. }
  7208. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7209. /*
  7210. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7211. * the only slow ring.
  7212. */
  7213. status = (work_ha_copy &
  7214. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7215. status >>= (4*LPFC_ELS_RING);
  7216. if (status & HA_RXMASK) {
  7217. spin_lock_irqsave(&phba->hbalock, iflag);
  7218. control = readl(phba->HCregaddr);
  7219. lpfc_debugfs_slow_ring_trc(phba,
  7220. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7221. control, status,
  7222. (uint32_t)phba->sli.slistat.sli_intr);
  7223. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7224. lpfc_debugfs_slow_ring_trc(phba,
  7225. "ISR Disable ring:"
  7226. "pwork:x%x hawork:x%x wait:x%x",
  7227. phba->work_ha, work_ha_copy,
  7228. (uint32_t)((unsigned long)
  7229. &phba->work_waitq));
  7230. control &=
  7231. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7232. writel(control, phba->HCregaddr);
  7233. readl(phba->HCregaddr); /* flush */
  7234. }
  7235. else {
  7236. lpfc_debugfs_slow_ring_trc(phba,
  7237. "ISR slow ring: pwork:"
  7238. "x%x hawork:x%x wait:x%x",
  7239. phba->work_ha, work_ha_copy,
  7240. (uint32_t)((unsigned long)
  7241. &phba->work_waitq));
  7242. }
  7243. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7244. }
  7245. }
  7246. spin_lock_irqsave(&phba->hbalock, iflag);
  7247. if (work_ha_copy & HA_ERATT) {
  7248. lpfc_sli_read_hs(phba);
  7249. /*
  7250. * Check if there is a deferred error condition
  7251. * is active
  7252. */
  7253. if ((HS_FFER1 & phba->work_hs) &&
  7254. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7255. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7256. phba->hba_flag |= DEFER_ERATT;
  7257. /* Clear all interrupt enable conditions */
  7258. writel(0, phba->HCregaddr);
  7259. readl(phba->HCregaddr);
  7260. }
  7261. }
  7262. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7263. pmb = phba->sli.mbox_active;
  7264. pmbox = &pmb->u.mb;
  7265. mbox = phba->mbox;
  7266. vport = pmb->vport;
  7267. /* First check out the status word */
  7268. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7269. if (pmbox->mbxOwner != OWN_HOST) {
  7270. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7271. /*
  7272. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7273. * mbxStatus <status>
  7274. */
  7275. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7276. LOG_SLI,
  7277. "(%d):0304 Stray Mailbox "
  7278. "Interrupt mbxCommand x%x "
  7279. "mbxStatus x%x\n",
  7280. (vport ? vport->vpi : 0),
  7281. pmbox->mbxCommand,
  7282. pmbox->mbxStatus);
  7283. /* clear mailbox attention bit */
  7284. work_ha_copy &= ~HA_MBATT;
  7285. } else {
  7286. phba->sli.mbox_active = NULL;
  7287. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7288. phba->last_completion_time = jiffies;
  7289. del_timer(&phba->sli.mbox_tmo);
  7290. if (pmb->mbox_cmpl) {
  7291. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7292. MAILBOX_CMD_SIZE);
  7293. }
  7294. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7295. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7296. lpfc_debugfs_disc_trc(vport,
  7297. LPFC_DISC_TRC_MBOX_VPORT,
  7298. "MBOX dflt rpi: : "
  7299. "status:x%x rpi:x%x",
  7300. (uint32_t)pmbox->mbxStatus,
  7301. pmbox->un.varWords[0], 0);
  7302. if (!pmbox->mbxStatus) {
  7303. mp = (struct lpfc_dmabuf *)
  7304. (pmb->context1);
  7305. ndlp = (struct lpfc_nodelist *)
  7306. pmb->context2;
  7307. /* Reg_LOGIN of dflt RPI was
  7308. * successful. new lets get
  7309. * rid of the RPI using the
  7310. * same mbox buffer.
  7311. */
  7312. lpfc_unreg_login(phba,
  7313. vport->vpi,
  7314. pmbox->un.varWords[0],
  7315. pmb);
  7316. pmb->mbox_cmpl =
  7317. lpfc_mbx_cmpl_dflt_rpi;
  7318. pmb->context1 = mp;
  7319. pmb->context2 = ndlp;
  7320. pmb->vport = vport;
  7321. rc = lpfc_sli_issue_mbox(phba,
  7322. pmb,
  7323. MBX_NOWAIT);
  7324. if (rc != MBX_BUSY)
  7325. lpfc_printf_log(phba,
  7326. KERN_ERR,
  7327. LOG_MBOX | LOG_SLI,
  7328. "0350 rc should have"
  7329. "been MBX_BUSY");
  7330. if (rc != MBX_NOT_FINISHED)
  7331. goto send_current_mbox;
  7332. }
  7333. }
  7334. spin_lock_irqsave(
  7335. &phba->pport->work_port_lock,
  7336. iflag);
  7337. phba->pport->work_port_events &=
  7338. ~WORKER_MBOX_TMO;
  7339. spin_unlock_irqrestore(
  7340. &phba->pport->work_port_lock,
  7341. iflag);
  7342. lpfc_mbox_cmpl_put(phba, pmb);
  7343. }
  7344. } else
  7345. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7346. if ((work_ha_copy & HA_MBATT) &&
  7347. (phba->sli.mbox_active == NULL)) {
  7348. send_current_mbox:
  7349. /* Process next mailbox command if there is one */
  7350. do {
  7351. rc = lpfc_sli_issue_mbox(phba, NULL,
  7352. MBX_NOWAIT);
  7353. } while (rc == MBX_NOT_FINISHED);
  7354. if (rc != MBX_SUCCESS)
  7355. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7356. LOG_SLI, "0349 rc should be "
  7357. "MBX_SUCCESS");
  7358. }
  7359. spin_lock_irqsave(&phba->hbalock, iflag);
  7360. phba->work_ha |= work_ha_copy;
  7361. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7362. lpfc_worker_wake_up(phba);
  7363. }
  7364. return IRQ_HANDLED;
  7365. } /* lpfc_sli_sp_intr_handler */
  7366. /**
  7367. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7368. * @irq: Interrupt number.
  7369. * @dev_id: The device context pointer.
  7370. *
  7371. * This function is directly called from the PCI layer as an interrupt
  7372. * service routine when device with SLI-3 interface spec is enabled with
  7373. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7374. * ring event in the HBA. However, when the device is enabled with either
  7375. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7376. * device-level interrupt handler. When the PCI slot is in error recovery
  7377. * or the HBA is undergoing initialization, the interrupt handler will not
  7378. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7379. * the intrrupt context. This function is called without any lock held.
  7380. * It gets the hbalock to access and update SLI data structures.
  7381. *
  7382. * This function returns IRQ_HANDLED when interrupt is handled else it
  7383. * returns IRQ_NONE.
  7384. **/
  7385. irqreturn_t
  7386. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7387. {
  7388. struct lpfc_hba *phba;
  7389. uint32_t ha_copy;
  7390. unsigned long status;
  7391. unsigned long iflag;
  7392. /* Get the driver's phba structure from the dev_id and
  7393. * assume the HBA is not interrupting.
  7394. */
  7395. phba = (struct lpfc_hba *) dev_id;
  7396. if (unlikely(!phba))
  7397. return IRQ_NONE;
  7398. /*
  7399. * Stuff needs to be attented to when this function is invoked as an
  7400. * individual interrupt handler in MSI-X multi-message interrupt mode
  7401. */
  7402. if (phba->intr_type == MSIX) {
  7403. /* Check device state for handling interrupt */
  7404. if (lpfc_intr_state_check(phba))
  7405. return IRQ_NONE;
  7406. /* Need to read HA REG for FCP ring and other ring events */
  7407. ha_copy = readl(phba->HAregaddr);
  7408. /* Clear up only attention source related to fast-path */
  7409. spin_lock_irqsave(&phba->hbalock, iflag);
  7410. /*
  7411. * If there is deferred error attention, do not check for
  7412. * any interrupt.
  7413. */
  7414. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7415. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7416. return IRQ_NONE;
  7417. }
  7418. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7419. phba->HAregaddr);
  7420. readl(phba->HAregaddr); /* flush */
  7421. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7422. } else
  7423. ha_copy = phba->ha_copy;
  7424. /*
  7425. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7426. */
  7427. ha_copy &= ~(phba->work_ha_mask);
  7428. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7429. status >>= (4*LPFC_FCP_RING);
  7430. if (status & HA_RXMASK)
  7431. lpfc_sli_handle_fast_ring_event(phba,
  7432. &phba->sli.ring[LPFC_FCP_RING],
  7433. status);
  7434. if (phba->cfg_multi_ring_support == 2) {
  7435. /*
  7436. * Process all events on extra ring. Take the optimized path
  7437. * for extra ring IO.
  7438. */
  7439. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7440. status >>= (4*LPFC_EXTRA_RING);
  7441. if (status & HA_RXMASK) {
  7442. lpfc_sli_handle_fast_ring_event(phba,
  7443. &phba->sli.ring[LPFC_EXTRA_RING],
  7444. status);
  7445. }
  7446. }
  7447. return IRQ_HANDLED;
  7448. } /* lpfc_sli_fp_intr_handler */
  7449. /**
  7450. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7451. * @irq: Interrupt number.
  7452. * @dev_id: The device context pointer.
  7453. *
  7454. * This function is the HBA device-level interrupt handler to device with
  7455. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7456. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7457. * requires driver attention. This function invokes the slow-path interrupt
  7458. * attention handling function and fast-path interrupt attention handling
  7459. * function in turn to process the relevant HBA attention events. This
  7460. * function is called without any lock held. It gets the hbalock to access
  7461. * and update SLI data structures.
  7462. *
  7463. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7464. * returns IRQ_NONE.
  7465. **/
  7466. irqreturn_t
  7467. lpfc_sli_intr_handler(int irq, void *dev_id)
  7468. {
  7469. struct lpfc_hba *phba;
  7470. irqreturn_t sp_irq_rc, fp_irq_rc;
  7471. unsigned long status1, status2;
  7472. /*
  7473. * Get the driver's phba structure from the dev_id and
  7474. * assume the HBA is not interrupting.
  7475. */
  7476. phba = (struct lpfc_hba *) dev_id;
  7477. if (unlikely(!phba))
  7478. return IRQ_NONE;
  7479. /* Check device state for handling interrupt */
  7480. if (lpfc_intr_state_check(phba))
  7481. return IRQ_NONE;
  7482. spin_lock(&phba->hbalock);
  7483. phba->ha_copy = readl(phba->HAregaddr);
  7484. if (unlikely(!phba->ha_copy)) {
  7485. spin_unlock(&phba->hbalock);
  7486. return IRQ_NONE;
  7487. } else if (phba->ha_copy & HA_ERATT) {
  7488. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7489. /* ERATT polling has handled ERATT */
  7490. phba->ha_copy &= ~HA_ERATT;
  7491. else
  7492. /* Indicate interrupt handler handles ERATT */
  7493. phba->hba_flag |= HBA_ERATT_HANDLED;
  7494. }
  7495. /*
  7496. * If there is deferred error attention, do not check for any interrupt.
  7497. */
  7498. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7499. spin_unlock_irq(&phba->hbalock);
  7500. return IRQ_NONE;
  7501. }
  7502. /* Clear attention sources except link and error attentions */
  7503. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7504. readl(phba->HAregaddr); /* flush */
  7505. spin_unlock(&phba->hbalock);
  7506. /*
  7507. * Invokes slow-path host attention interrupt handling as appropriate.
  7508. */
  7509. /* status of events with mailbox and link attention */
  7510. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7511. /* status of events with ELS ring */
  7512. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7513. status2 >>= (4*LPFC_ELS_RING);
  7514. if (status1 || (status2 & HA_RXMASK))
  7515. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7516. else
  7517. sp_irq_rc = IRQ_NONE;
  7518. /*
  7519. * Invoke fast-path host attention interrupt handling as appropriate.
  7520. */
  7521. /* status of events with FCP ring */
  7522. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7523. status1 >>= (4*LPFC_FCP_RING);
  7524. /* status of events with extra ring */
  7525. if (phba->cfg_multi_ring_support == 2) {
  7526. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7527. status2 >>= (4*LPFC_EXTRA_RING);
  7528. } else
  7529. status2 = 0;
  7530. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7531. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7532. else
  7533. fp_irq_rc = IRQ_NONE;
  7534. /* Return device-level interrupt handling status */
  7535. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7536. } /* lpfc_sli_intr_handler */
  7537. /**
  7538. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7539. * @phba: pointer to lpfc hba data structure.
  7540. *
  7541. * This routine is invoked by the worker thread to process all the pending
  7542. * SLI4 FCP abort XRI events.
  7543. **/
  7544. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7545. {
  7546. struct lpfc_cq_event *cq_event;
  7547. /* First, declare the fcp xri abort event has been handled */
  7548. spin_lock_irq(&phba->hbalock);
  7549. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7550. spin_unlock_irq(&phba->hbalock);
  7551. /* Now, handle all the fcp xri abort events */
  7552. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7553. /* Get the first event from the head of the event queue */
  7554. spin_lock_irq(&phba->hbalock);
  7555. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7556. cq_event, struct lpfc_cq_event, list);
  7557. spin_unlock_irq(&phba->hbalock);
  7558. /* Notify aborted XRI for FCP work queue */
  7559. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7560. /* Free the event processed back to the free pool */
  7561. lpfc_sli4_cq_event_release(phba, cq_event);
  7562. }
  7563. }
  7564. /**
  7565. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7566. * @phba: pointer to lpfc hba data structure.
  7567. *
  7568. * This routine is invoked by the worker thread to process all the pending
  7569. * SLI4 els abort xri events.
  7570. **/
  7571. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7572. {
  7573. struct lpfc_cq_event *cq_event;
  7574. /* First, declare the els xri abort event has been handled */
  7575. spin_lock_irq(&phba->hbalock);
  7576. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7577. spin_unlock_irq(&phba->hbalock);
  7578. /* Now, handle all the els xri abort events */
  7579. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7580. /* Get the first event from the head of the event queue */
  7581. spin_lock_irq(&phba->hbalock);
  7582. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7583. cq_event, struct lpfc_cq_event, list);
  7584. spin_unlock_irq(&phba->hbalock);
  7585. /* Notify aborted XRI for ELS work queue */
  7586. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7587. /* Free the event processed back to the free pool */
  7588. lpfc_sli4_cq_event_release(phba, cq_event);
  7589. }
  7590. }
  7591. static void
  7592. lpfc_sli4_iocb_param_transfer(struct lpfc_iocbq *pIocbIn,
  7593. struct lpfc_iocbq *pIocbOut,
  7594. struct lpfc_wcqe_complete *wcqe)
  7595. {
  7596. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7597. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7598. sizeof(struct lpfc_iocbq) - offset);
  7599. pIocbIn->cq_event.cqe.wcqe_cmpl = *wcqe;
  7600. /* Map WCQE parameters into irspiocb parameters */
  7601. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7602. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7603. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7604. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7605. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7606. wcqe->total_data_placed;
  7607. else
  7608. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7609. else
  7610. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7611. }
  7612. /**
  7613. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7614. * @phba: Pointer to HBA context object.
  7615. * @cqe: Pointer to mailbox completion queue entry.
  7616. *
  7617. * This routine process a mailbox completion queue entry with asynchrous
  7618. * event.
  7619. *
  7620. * Return: true if work posted to worker thread, otherwise false.
  7621. **/
  7622. static bool
  7623. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7624. {
  7625. struct lpfc_cq_event *cq_event;
  7626. unsigned long iflags;
  7627. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7628. "0392 Async Event: word0:x%x, word1:x%x, "
  7629. "word2:x%x, word3:x%x\n", mcqe->word0,
  7630. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7631. /* Allocate a new internal CQ_EVENT entry */
  7632. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7633. if (!cq_event) {
  7634. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7635. "0394 Failed to allocate CQ_EVENT entry\n");
  7636. return false;
  7637. }
  7638. /* Move the CQE into an asynchronous event entry */
  7639. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7640. spin_lock_irqsave(&phba->hbalock, iflags);
  7641. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7642. /* Set the async event flag */
  7643. phba->hba_flag |= ASYNC_EVENT;
  7644. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7645. return true;
  7646. }
  7647. /**
  7648. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7649. * @phba: Pointer to HBA context object.
  7650. * @cqe: Pointer to mailbox completion queue entry.
  7651. *
  7652. * This routine process a mailbox completion queue entry with mailbox
  7653. * completion event.
  7654. *
  7655. * Return: true if work posted to worker thread, otherwise false.
  7656. **/
  7657. static bool
  7658. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7659. {
  7660. uint32_t mcqe_status;
  7661. MAILBOX_t *mbox, *pmbox;
  7662. struct lpfc_mqe *mqe;
  7663. struct lpfc_vport *vport;
  7664. struct lpfc_nodelist *ndlp;
  7665. struct lpfc_dmabuf *mp;
  7666. unsigned long iflags;
  7667. LPFC_MBOXQ_t *pmb;
  7668. bool workposted = false;
  7669. int rc;
  7670. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7671. if (!bf_get(lpfc_trailer_completed, mcqe))
  7672. goto out_no_mqe_complete;
  7673. /* Get the reference to the active mbox command */
  7674. spin_lock_irqsave(&phba->hbalock, iflags);
  7675. pmb = phba->sli.mbox_active;
  7676. if (unlikely(!pmb)) {
  7677. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7678. "1832 No pending MBOX command to handle\n");
  7679. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7680. goto out_no_mqe_complete;
  7681. }
  7682. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7683. mqe = &pmb->u.mqe;
  7684. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7685. mbox = phba->mbox;
  7686. vport = pmb->vport;
  7687. /* Reset heartbeat timer */
  7688. phba->last_completion_time = jiffies;
  7689. del_timer(&phba->sli.mbox_tmo);
  7690. /* Move mbox data to caller's mailbox region, do endian swapping */
  7691. if (pmb->mbox_cmpl && mbox)
  7692. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7693. /* Set the mailbox status with SLI4 range 0x4000 */
  7694. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7695. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7696. bf_set(lpfc_mqe_status, mqe,
  7697. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7698. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7699. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7700. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7701. "MBOX dflt rpi: status:x%x rpi:x%x",
  7702. mcqe_status,
  7703. pmbox->un.varWords[0], 0);
  7704. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7705. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7706. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7707. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7708. * RID of the PPI using the same mbox buffer.
  7709. */
  7710. lpfc_unreg_login(phba, vport->vpi,
  7711. pmbox->un.varWords[0], pmb);
  7712. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7713. pmb->context1 = mp;
  7714. pmb->context2 = ndlp;
  7715. pmb->vport = vport;
  7716. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7717. if (rc != MBX_BUSY)
  7718. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7719. LOG_SLI, "0385 rc should "
  7720. "have been MBX_BUSY\n");
  7721. if (rc != MBX_NOT_FINISHED)
  7722. goto send_current_mbox;
  7723. }
  7724. }
  7725. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7726. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7727. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7728. /* There is mailbox completion work to do */
  7729. spin_lock_irqsave(&phba->hbalock, iflags);
  7730. __lpfc_mbox_cmpl_put(phba, pmb);
  7731. phba->work_ha |= HA_MBATT;
  7732. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7733. workposted = true;
  7734. send_current_mbox:
  7735. spin_lock_irqsave(&phba->hbalock, iflags);
  7736. /* Release the mailbox command posting token */
  7737. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7738. /* Setting active mailbox pointer need to be in sync to flag clear */
  7739. phba->sli.mbox_active = NULL;
  7740. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7741. /* Wake up worker thread to post the next pending mailbox command */
  7742. lpfc_worker_wake_up(phba);
  7743. out_no_mqe_complete:
  7744. if (bf_get(lpfc_trailer_consumed, mcqe))
  7745. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7746. return workposted;
  7747. }
  7748. /**
  7749. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7750. * @phba: Pointer to HBA context object.
  7751. * @cqe: Pointer to mailbox completion queue entry.
  7752. *
  7753. * This routine process a mailbox completion queue entry, it invokes the
  7754. * proper mailbox complete handling or asynchrous event handling routine
  7755. * according to the MCQE's async bit.
  7756. *
  7757. * Return: true if work posted to worker thread, otherwise false.
  7758. **/
  7759. static bool
  7760. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7761. {
  7762. struct lpfc_mcqe mcqe;
  7763. bool workposted;
  7764. /* Copy the mailbox MCQE and convert endian order as needed */
  7765. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  7766. /* Invoke the proper event handling routine */
  7767. if (!bf_get(lpfc_trailer_async, &mcqe))
  7768. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  7769. else
  7770. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  7771. return workposted;
  7772. }
  7773. /**
  7774. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  7775. * @phba: Pointer to HBA context object.
  7776. * @wcqe: Pointer to work-queue completion queue entry.
  7777. *
  7778. * This routine handles an ELS work-queue completion event.
  7779. *
  7780. * Return: true if work posted to worker thread, otherwise false.
  7781. **/
  7782. static bool
  7783. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  7784. struct lpfc_wcqe_complete *wcqe)
  7785. {
  7786. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7787. struct lpfc_iocbq *cmdiocbq;
  7788. struct lpfc_iocbq *irspiocbq;
  7789. unsigned long iflags;
  7790. bool workposted = false;
  7791. spin_lock_irqsave(&phba->hbalock, iflags);
  7792. pring->stats.iocb_event++;
  7793. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7794. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7795. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7796. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7797. if (unlikely(!cmdiocbq)) {
  7798. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7799. "0386 ELS complete with no corresponding "
  7800. "cmdiocb: iotag (%d)\n",
  7801. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7802. return workposted;
  7803. }
  7804. /* Fake the irspiocbq and copy necessary response information */
  7805. irspiocbq = lpfc_sli_get_iocbq(phba);
  7806. if (!irspiocbq) {
  7807. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7808. "0387 Failed to allocate an iocbq\n");
  7809. return workposted;
  7810. }
  7811. lpfc_sli4_iocb_param_transfer(irspiocbq, cmdiocbq, wcqe);
  7812. /* Add the irspiocb to the response IOCB work list */
  7813. spin_lock_irqsave(&phba->hbalock, iflags);
  7814. list_add_tail(&irspiocbq->cq_event.list,
  7815. &phba->sli4_hba.sp_rspiocb_work_queue);
  7816. /* Indicate ELS ring attention */
  7817. phba->work_ha |= (HA_R0ATT << (4*LPFC_ELS_RING));
  7818. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7819. workposted = true;
  7820. return workposted;
  7821. }
  7822. /**
  7823. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  7824. * @phba: Pointer to HBA context object.
  7825. * @wcqe: Pointer to work-queue completion queue entry.
  7826. *
  7827. * This routine handles slow-path WQ entry comsumed event by invoking the
  7828. * proper WQ release routine to the slow-path WQ.
  7829. **/
  7830. static void
  7831. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  7832. struct lpfc_wcqe_release *wcqe)
  7833. {
  7834. /* Check for the slow-path ELS work queue */
  7835. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  7836. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  7837. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  7838. else
  7839. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7840. "2579 Slow-path wqe consume event carries "
  7841. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  7842. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  7843. phba->sli4_hba.els_wq->queue_id);
  7844. }
  7845. /**
  7846. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  7847. * @phba: Pointer to HBA context object.
  7848. * @cq: Pointer to a WQ completion queue.
  7849. * @wcqe: Pointer to work-queue completion queue entry.
  7850. *
  7851. * This routine handles an XRI abort event.
  7852. *
  7853. * Return: true if work posted to worker thread, otherwise false.
  7854. **/
  7855. static bool
  7856. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  7857. struct lpfc_queue *cq,
  7858. struct sli4_wcqe_xri_aborted *wcqe)
  7859. {
  7860. bool workposted = false;
  7861. struct lpfc_cq_event *cq_event;
  7862. unsigned long iflags;
  7863. /* Allocate a new internal CQ_EVENT entry */
  7864. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7865. if (!cq_event) {
  7866. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7867. "0602 Failed to allocate CQ_EVENT entry\n");
  7868. return false;
  7869. }
  7870. /* Move the CQE into the proper xri abort event list */
  7871. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  7872. switch (cq->subtype) {
  7873. case LPFC_FCP:
  7874. spin_lock_irqsave(&phba->hbalock, iflags);
  7875. list_add_tail(&cq_event->list,
  7876. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  7877. /* Set the fcp xri abort event flag */
  7878. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  7879. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7880. workposted = true;
  7881. break;
  7882. case LPFC_ELS:
  7883. spin_lock_irqsave(&phba->hbalock, iflags);
  7884. list_add_tail(&cq_event->list,
  7885. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  7886. /* Set the els xri abort event flag */
  7887. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  7888. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7889. workposted = true;
  7890. break;
  7891. default:
  7892. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7893. "0603 Invalid work queue CQE subtype (x%x)\n",
  7894. cq->subtype);
  7895. workposted = false;
  7896. break;
  7897. }
  7898. return workposted;
  7899. }
  7900. /**
  7901. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  7902. * @phba: Pointer to HBA context object.
  7903. * @rcqe: Pointer to receive-queue completion queue entry.
  7904. *
  7905. * This routine process a receive-queue completion queue entry.
  7906. *
  7907. * Return: true if work posted to worker thread, otherwise false.
  7908. **/
  7909. static bool
  7910. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  7911. {
  7912. bool workposted = false;
  7913. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  7914. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  7915. struct hbq_dmabuf *dma_buf;
  7916. uint32_t status;
  7917. unsigned long iflags;
  7918. lpfc_sli4_rq_release(hrq, drq);
  7919. if (bf_get(lpfc_rcqe_code, rcqe) != CQE_CODE_RECEIVE)
  7920. goto out;
  7921. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  7922. goto out;
  7923. status = bf_get(lpfc_rcqe_status, rcqe);
  7924. switch (status) {
  7925. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  7926. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7927. "2537 Receive Frame Truncated!!\n");
  7928. case FC_STATUS_RQ_SUCCESS:
  7929. spin_lock_irqsave(&phba->hbalock, iflags);
  7930. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  7931. if (!dma_buf) {
  7932. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7933. goto out;
  7934. }
  7935. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  7936. /* save off the frame for the word thread to process */
  7937. list_add_tail(&dma_buf->cq_event.list,
  7938. &phba->sli4_hba.sp_rspiocb_work_queue);
  7939. /* Frame received */
  7940. phba->hba_flag |= HBA_RECEIVE_BUFFER;
  7941. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7942. workposted = true;
  7943. break;
  7944. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  7945. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  7946. /* Post more buffers if possible */
  7947. spin_lock_irqsave(&phba->hbalock, iflags);
  7948. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  7949. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7950. workposted = true;
  7951. break;
  7952. }
  7953. out:
  7954. return workposted;
  7955. }
  7956. /**
  7957. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  7958. * @phba: Pointer to HBA context object.
  7959. * @cq: Pointer to the completion queue.
  7960. * @wcqe: Pointer to a completion queue entry.
  7961. *
  7962. * This routine process a slow-path work-queue or recieve queue completion queue
  7963. * entry.
  7964. *
  7965. * Return: true if work posted to worker thread, otherwise false.
  7966. **/
  7967. static bool
  7968. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  7969. struct lpfc_cqe *cqe)
  7970. {
  7971. struct lpfc_wcqe_complete wcqe;
  7972. bool workposted = false;
  7973. /* Copy the work queue CQE and convert endian order if needed */
  7974. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  7975. /* Check and process for different type of WCQE and dispatch */
  7976. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  7977. case CQE_CODE_COMPL_WQE:
  7978. /* Process the WQ complete event */
  7979. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  7980. (struct lpfc_wcqe_complete *)&wcqe);
  7981. break;
  7982. case CQE_CODE_RELEASE_WQE:
  7983. /* Process the WQ release event */
  7984. lpfc_sli4_sp_handle_rel_wcqe(phba,
  7985. (struct lpfc_wcqe_release *)&wcqe);
  7986. break;
  7987. case CQE_CODE_XRI_ABORTED:
  7988. /* Process the WQ XRI abort event */
  7989. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  7990. (struct sli4_wcqe_xri_aborted *)&wcqe);
  7991. break;
  7992. case CQE_CODE_RECEIVE:
  7993. /* Process the RQ event */
  7994. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  7995. (struct lpfc_rcqe *)&wcqe);
  7996. break;
  7997. default:
  7998. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7999. "0388 Not a valid WCQE code: x%x\n",
  8000. bf_get(lpfc_wcqe_c_code, &wcqe));
  8001. break;
  8002. }
  8003. return workposted;
  8004. }
  8005. /**
  8006. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8007. * @phba: Pointer to HBA context object.
  8008. * @eqe: Pointer to fast-path event queue entry.
  8009. *
  8010. * This routine process a event queue entry from the slow-path event queue.
  8011. * It will check the MajorCode and MinorCode to determine this is for a
  8012. * completion event on a completion queue, if not, an error shall be logged
  8013. * and just return. Otherwise, it will get to the corresponding completion
  8014. * queue and process all the entries on that completion queue, rearm the
  8015. * completion queue, and then return.
  8016. *
  8017. **/
  8018. static void
  8019. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8020. {
  8021. struct lpfc_queue *cq = NULL, *childq, *speq;
  8022. struct lpfc_cqe *cqe;
  8023. bool workposted = false;
  8024. int ecount = 0;
  8025. uint16_t cqid;
  8026. if (bf_get(lpfc_eqe_major_code, eqe) != 0 ||
  8027. bf_get(lpfc_eqe_minor_code, eqe) != 0) {
  8028. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8029. "0359 Not a valid slow-path completion "
  8030. "event: majorcode=x%x, minorcode=x%x\n",
  8031. bf_get(lpfc_eqe_major_code, eqe),
  8032. bf_get(lpfc_eqe_minor_code, eqe));
  8033. return;
  8034. }
  8035. /* Get the reference to the corresponding CQ */
  8036. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8037. /* Search for completion queue pointer matching this cqid */
  8038. speq = phba->sli4_hba.sp_eq;
  8039. list_for_each_entry(childq, &speq->child_list, list) {
  8040. if (childq->queue_id == cqid) {
  8041. cq = childq;
  8042. break;
  8043. }
  8044. }
  8045. if (unlikely(!cq)) {
  8046. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8047. "0365 Slow-path CQ identifier (%d) does "
  8048. "not exist\n", cqid);
  8049. return;
  8050. }
  8051. /* Process all the entries to the CQ */
  8052. switch (cq->type) {
  8053. case LPFC_MCQ:
  8054. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8055. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8056. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8057. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8058. }
  8059. break;
  8060. case LPFC_WCQ:
  8061. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8062. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8063. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8064. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8065. }
  8066. break;
  8067. default:
  8068. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8069. "0370 Invalid completion queue type (%d)\n",
  8070. cq->type);
  8071. return;
  8072. }
  8073. /* Catch the no cq entry condition, log an error */
  8074. if (unlikely(ecount == 0))
  8075. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8076. "0371 No entry from the CQ: identifier "
  8077. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8078. /* In any case, flash and re-arm the RCQ */
  8079. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8080. /* wake up worker thread if there are works to be done */
  8081. if (workposted)
  8082. lpfc_worker_wake_up(phba);
  8083. }
  8084. /**
  8085. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8086. * @eqe: Pointer to fast-path completion queue entry.
  8087. *
  8088. * This routine process a fast-path work queue completion entry from fast-path
  8089. * event queue for FCP command response completion.
  8090. **/
  8091. static void
  8092. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8093. struct lpfc_wcqe_complete *wcqe)
  8094. {
  8095. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8096. struct lpfc_iocbq *cmdiocbq;
  8097. struct lpfc_iocbq irspiocbq;
  8098. unsigned long iflags;
  8099. spin_lock_irqsave(&phba->hbalock, iflags);
  8100. pring->stats.iocb_event++;
  8101. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8102. /* Check for response status */
  8103. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8104. /* If resource errors reported from HBA, reduce queue
  8105. * depth of the SCSI device.
  8106. */
  8107. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8108. IOSTAT_LOCAL_REJECT) &&
  8109. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8110. phba->lpfc_rampdown_queue_depth(phba);
  8111. }
  8112. /* Log the error status */
  8113. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8114. "0373 FCP complete error: status=x%x, "
  8115. "hw_status=x%x, total_data_specified=%d, "
  8116. "parameter=x%x, word3=x%x\n",
  8117. bf_get(lpfc_wcqe_c_status, wcqe),
  8118. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8119. wcqe->total_data_placed, wcqe->parameter,
  8120. wcqe->word3);
  8121. }
  8122. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8123. spin_lock_irqsave(&phba->hbalock, iflags);
  8124. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8125. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8126. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8127. if (unlikely(!cmdiocbq)) {
  8128. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8129. "0374 FCP complete with no corresponding "
  8130. "cmdiocb: iotag (%d)\n",
  8131. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8132. return;
  8133. }
  8134. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8135. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8136. "0375 FCP cmdiocb not callback function "
  8137. "iotag: (%d)\n",
  8138. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8139. return;
  8140. }
  8141. /* Fake the irspiocb and copy necessary response information */
  8142. lpfc_sli4_iocb_param_transfer(&irspiocbq, cmdiocbq, wcqe);
  8143. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8144. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8145. }
  8146. /**
  8147. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8148. * @phba: Pointer to HBA context object.
  8149. * @cq: Pointer to completion queue.
  8150. * @wcqe: Pointer to work-queue completion queue entry.
  8151. *
  8152. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8153. * proper WQ release routine to the slow-path WQ.
  8154. **/
  8155. static void
  8156. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8157. struct lpfc_wcqe_release *wcqe)
  8158. {
  8159. struct lpfc_queue *childwq;
  8160. bool wqid_matched = false;
  8161. uint16_t fcp_wqid;
  8162. /* Check for fast-path FCP work queue release */
  8163. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8164. list_for_each_entry(childwq, &cq->child_list, list) {
  8165. if (childwq->queue_id == fcp_wqid) {
  8166. lpfc_sli4_wq_release(childwq,
  8167. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8168. wqid_matched = true;
  8169. break;
  8170. }
  8171. }
  8172. /* Report warning log message if no match found */
  8173. if (wqid_matched != true)
  8174. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8175. "2580 Fast-path wqe consume event carries "
  8176. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8177. }
  8178. /**
  8179. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8180. * @cq: Pointer to the completion queue.
  8181. * @eqe: Pointer to fast-path completion queue entry.
  8182. *
  8183. * This routine process a fast-path work queue completion entry from fast-path
  8184. * event queue for FCP command response completion.
  8185. **/
  8186. static int
  8187. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8188. struct lpfc_cqe *cqe)
  8189. {
  8190. struct lpfc_wcqe_release wcqe;
  8191. bool workposted = false;
  8192. /* Copy the work queue CQE and convert endian order if needed */
  8193. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8194. /* Check and process for different type of WCQE and dispatch */
  8195. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8196. case CQE_CODE_COMPL_WQE:
  8197. /* Process the WQ complete event */
  8198. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8199. (struct lpfc_wcqe_complete *)&wcqe);
  8200. break;
  8201. case CQE_CODE_RELEASE_WQE:
  8202. /* Process the WQ release event */
  8203. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8204. (struct lpfc_wcqe_release *)&wcqe);
  8205. break;
  8206. case CQE_CODE_XRI_ABORTED:
  8207. /* Process the WQ XRI abort event */
  8208. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8209. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8210. break;
  8211. default:
  8212. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8213. "0144 Not a valid WCQE code: x%x\n",
  8214. bf_get(lpfc_wcqe_c_code, &wcqe));
  8215. break;
  8216. }
  8217. return workposted;
  8218. }
  8219. /**
  8220. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8221. * @phba: Pointer to HBA context object.
  8222. * @eqe: Pointer to fast-path event queue entry.
  8223. *
  8224. * This routine process a event queue entry from the fast-path event queue.
  8225. * It will check the MajorCode and MinorCode to determine this is for a
  8226. * completion event on a completion queue, if not, an error shall be logged
  8227. * and just return. Otherwise, it will get to the corresponding completion
  8228. * queue and process all the entries on the completion queue, rearm the
  8229. * completion queue, and then return.
  8230. **/
  8231. static void
  8232. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8233. uint32_t fcp_cqidx)
  8234. {
  8235. struct lpfc_queue *cq;
  8236. struct lpfc_cqe *cqe;
  8237. bool workposted = false;
  8238. uint16_t cqid;
  8239. int ecount = 0;
  8240. if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0) ||
  8241. unlikely(bf_get(lpfc_eqe_minor_code, eqe) != 0)) {
  8242. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8243. "0366 Not a valid fast-path completion "
  8244. "event: majorcode=x%x, minorcode=x%x\n",
  8245. bf_get(lpfc_eqe_major_code, eqe),
  8246. bf_get(lpfc_eqe_minor_code, eqe));
  8247. return;
  8248. }
  8249. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8250. if (unlikely(!cq)) {
  8251. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8252. "0367 Fast-path completion queue does not "
  8253. "exist\n");
  8254. return;
  8255. }
  8256. /* Get the reference to the corresponding CQ */
  8257. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8258. if (unlikely(cqid != cq->queue_id)) {
  8259. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8260. "0368 Miss-matched fast-path completion "
  8261. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8262. cqid, cq->queue_id);
  8263. return;
  8264. }
  8265. /* Process all the entries to the CQ */
  8266. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8267. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8268. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8269. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8270. }
  8271. /* Catch the no cq entry condition */
  8272. if (unlikely(ecount == 0))
  8273. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8274. "0369 No entry from fast-path completion "
  8275. "queue fcpcqid=%d\n", cq->queue_id);
  8276. /* In any case, flash and re-arm the CQ */
  8277. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8278. /* wake up worker thread if there are works to be done */
  8279. if (workposted)
  8280. lpfc_worker_wake_up(phba);
  8281. }
  8282. static void
  8283. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8284. {
  8285. struct lpfc_eqe *eqe;
  8286. /* walk all the EQ entries and drop on the floor */
  8287. while ((eqe = lpfc_sli4_eq_get(eq)))
  8288. ;
  8289. /* Clear and re-arm the EQ */
  8290. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8291. }
  8292. /**
  8293. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8294. * @irq: Interrupt number.
  8295. * @dev_id: The device context pointer.
  8296. *
  8297. * This function is directly called from the PCI layer as an interrupt
  8298. * service routine when device with SLI-4 interface spec is enabled with
  8299. * MSI-X multi-message interrupt mode and there are slow-path events in
  8300. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8301. * interrupt mode, this function is called as part of the device-level
  8302. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8303. * undergoing initialization, the interrupt handler will not process the
  8304. * interrupt. The link attention and ELS ring attention events are handled
  8305. * by the worker thread. The interrupt handler signals the worker thread
  8306. * and returns for these events. This function is called without any lock
  8307. * held. It gets the hbalock to access and update SLI data structures.
  8308. *
  8309. * This function returns IRQ_HANDLED when interrupt is handled else it
  8310. * returns IRQ_NONE.
  8311. **/
  8312. irqreturn_t
  8313. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8314. {
  8315. struct lpfc_hba *phba;
  8316. struct lpfc_queue *speq;
  8317. struct lpfc_eqe *eqe;
  8318. unsigned long iflag;
  8319. int ecount = 0;
  8320. /*
  8321. * Get the driver's phba structure from the dev_id
  8322. */
  8323. phba = (struct lpfc_hba *)dev_id;
  8324. if (unlikely(!phba))
  8325. return IRQ_NONE;
  8326. /* Get to the EQ struct associated with this vector */
  8327. speq = phba->sli4_hba.sp_eq;
  8328. /* Check device state for handling interrupt */
  8329. if (unlikely(lpfc_intr_state_check(phba))) {
  8330. /* Check again for link_state with lock held */
  8331. spin_lock_irqsave(&phba->hbalock, iflag);
  8332. if (phba->link_state < LPFC_LINK_DOWN)
  8333. /* Flush, clear interrupt, and rearm the EQ */
  8334. lpfc_sli4_eq_flush(phba, speq);
  8335. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8336. return IRQ_NONE;
  8337. }
  8338. /*
  8339. * Process all the event on FCP slow-path EQ
  8340. */
  8341. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8342. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8343. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8344. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8345. }
  8346. /* Always clear and re-arm the slow-path EQ */
  8347. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8348. /* Catch the no cq entry condition */
  8349. if (unlikely(ecount == 0)) {
  8350. if (phba->intr_type == MSIX)
  8351. /* MSI-X treated interrupt served as no EQ share INT */
  8352. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8353. "0357 MSI-X interrupt with no EQE\n");
  8354. else
  8355. /* Non MSI-X treated on interrupt as EQ share INT */
  8356. return IRQ_NONE;
  8357. }
  8358. return IRQ_HANDLED;
  8359. } /* lpfc_sli4_sp_intr_handler */
  8360. /**
  8361. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8362. * @irq: Interrupt number.
  8363. * @dev_id: The device context pointer.
  8364. *
  8365. * This function is directly called from the PCI layer as an interrupt
  8366. * service routine when device with SLI-4 interface spec is enabled with
  8367. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8368. * ring event in the HBA. However, when the device is enabled with either
  8369. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8370. * device-level interrupt handler. When the PCI slot is in error recovery
  8371. * or the HBA is undergoing initialization, the interrupt handler will not
  8372. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8373. * the intrrupt context. This function is called without any lock held.
  8374. * It gets the hbalock to access and update SLI data structures. Note that,
  8375. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8376. * equal to that of FCP CQ index.
  8377. *
  8378. * This function returns IRQ_HANDLED when interrupt is handled else it
  8379. * returns IRQ_NONE.
  8380. **/
  8381. irqreturn_t
  8382. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8383. {
  8384. struct lpfc_hba *phba;
  8385. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8386. struct lpfc_queue *fpeq;
  8387. struct lpfc_eqe *eqe;
  8388. unsigned long iflag;
  8389. int ecount = 0;
  8390. uint32_t fcp_eqidx;
  8391. /* Get the driver's phba structure from the dev_id */
  8392. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8393. phba = fcp_eq_hdl->phba;
  8394. fcp_eqidx = fcp_eq_hdl->idx;
  8395. if (unlikely(!phba))
  8396. return IRQ_NONE;
  8397. /* Get to the EQ struct associated with this vector */
  8398. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8399. /* Check device state for handling interrupt */
  8400. if (unlikely(lpfc_intr_state_check(phba))) {
  8401. /* Check again for link_state with lock held */
  8402. spin_lock_irqsave(&phba->hbalock, iflag);
  8403. if (phba->link_state < LPFC_LINK_DOWN)
  8404. /* Flush, clear interrupt, and rearm the EQ */
  8405. lpfc_sli4_eq_flush(phba, fpeq);
  8406. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8407. return IRQ_NONE;
  8408. }
  8409. /*
  8410. * Process all the event on FCP fast-path EQ
  8411. */
  8412. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8413. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8414. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8415. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8416. }
  8417. /* Always clear and re-arm the fast-path EQ */
  8418. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8419. if (unlikely(ecount == 0)) {
  8420. if (phba->intr_type == MSIX)
  8421. /* MSI-X treated interrupt served as no EQ share INT */
  8422. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8423. "0358 MSI-X interrupt with no EQE\n");
  8424. else
  8425. /* Non MSI-X treated on interrupt as EQ share INT */
  8426. return IRQ_NONE;
  8427. }
  8428. return IRQ_HANDLED;
  8429. } /* lpfc_sli4_fp_intr_handler */
  8430. /**
  8431. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8432. * @irq: Interrupt number.
  8433. * @dev_id: The device context pointer.
  8434. *
  8435. * This function is the device-level interrupt handler to device with SLI-4
  8436. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8437. * interrupt mode is enabled and there is an event in the HBA which requires
  8438. * driver attention. This function invokes the slow-path interrupt attention
  8439. * handling function and fast-path interrupt attention handling function in
  8440. * turn to process the relevant HBA attention events. This function is called
  8441. * without any lock held. It gets the hbalock to access and update SLI data
  8442. * structures.
  8443. *
  8444. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8445. * returns IRQ_NONE.
  8446. **/
  8447. irqreturn_t
  8448. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8449. {
  8450. struct lpfc_hba *phba;
  8451. irqreturn_t sp_irq_rc, fp_irq_rc;
  8452. bool fp_handled = false;
  8453. uint32_t fcp_eqidx;
  8454. /* Get the driver's phba structure from the dev_id */
  8455. phba = (struct lpfc_hba *)dev_id;
  8456. if (unlikely(!phba))
  8457. return IRQ_NONE;
  8458. /*
  8459. * Invokes slow-path host attention interrupt handling as appropriate.
  8460. */
  8461. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8462. /*
  8463. * Invoke fast-path host attention interrupt handling as appropriate.
  8464. */
  8465. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8466. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8467. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8468. if (fp_irq_rc == IRQ_HANDLED)
  8469. fp_handled |= true;
  8470. }
  8471. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8472. } /* lpfc_sli4_intr_handler */
  8473. /**
  8474. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8475. * @queue: The queue structure to free.
  8476. *
  8477. * This function frees a queue structure and the DMAable memeory used for
  8478. * the host resident queue. This function must be called after destroying the
  8479. * queue on the HBA.
  8480. **/
  8481. void
  8482. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8483. {
  8484. struct lpfc_dmabuf *dmabuf;
  8485. if (!queue)
  8486. return;
  8487. while (!list_empty(&queue->page_list)) {
  8488. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8489. list);
  8490. dma_free_coherent(&queue->phba->pcidev->dev, PAGE_SIZE,
  8491. dmabuf->virt, dmabuf->phys);
  8492. kfree(dmabuf);
  8493. }
  8494. kfree(queue);
  8495. return;
  8496. }
  8497. /**
  8498. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8499. * @phba: The HBA that this queue is being created on.
  8500. * @entry_size: The size of each queue entry for this queue.
  8501. * @entry count: The number of entries that this queue will handle.
  8502. *
  8503. * This function allocates a queue structure and the DMAable memory used for
  8504. * the host resident queue. This function must be called before creating the
  8505. * queue on the HBA.
  8506. **/
  8507. struct lpfc_queue *
  8508. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8509. uint32_t entry_count)
  8510. {
  8511. struct lpfc_queue *queue;
  8512. struct lpfc_dmabuf *dmabuf;
  8513. int x, total_qe_count;
  8514. void *dma_pointer;
  8515. queue = kzalloc(sizeof(struct lpfc_queue) +
  8516. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8517. if (!queue)
  8518. return NULL;
  8519. queue->page_count = (PAGE_ALIGN(entry_size * entry_count))/PAGE_SIZE;
  8520. INIT_LIST_HEAD(&queue->list);
  8521. INIT_LIST_HEAD(&queue->page_list);
  8522. INIT_LIST_HEAD(&queue->child_list);
  8523. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8524. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8525. if (!dmabuf)
  8526. goto out_fail;
  8527. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8528. PAGE_SIZE, &dmabuf->phys,
  8529. GFP_KERNEL);
  8530. if (!dmabuf->virt) {
  8531. kfree(dmabuf);
  8532. goto out_fail;
  8533. }
  8534. memset(dmabuf->virt, 0, PAGE_SIZE);
  8535. dmabuf->buffer_tag = x;
  8536. list_add_tail(&dmabuf->list, &queue->page_list);
  8537. /* initialize queue's entry array */
  8538. dma_pointer = dmabuf->virt;
  8539. for (; total_qe_count < entry_count &&
  8540. dma_pointer < (PAGE_SIZE + dmabuf->virt);
  8541. total_qe_count++, dma_pointer += entry_size) {
  8542. queue->qe[total_qe_count].address = dma_pointer;
  8543. }
  8544. }
  8545. queue->entry_size = entry_size;
  8546. queue->entry_count = entry_count;
  8547. queue->phba = phba;
  8548. return queue;
  8549. out_fail:
  8550. lpfc_sli4_queue_free(queue);
  8551. return NULL;
  8552. }
  8553. /**
  8554. * lpfc_eq_create - Create an Event Queue on the HBA
  8555. * @phba: HBA structure that indicates port to create a queue on.
  8556. * @eq: The queue structure to use to create the event queue.
  8557. * @imax: The maximum interrupt per second limit.
  8558. *
  8559. * This function creates an event queue, as detailed in @eq, on a port,
  8560. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8561. *
  8562. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8563. * is used to get the entry count and entry size that are necessary to
  8564. * determine the number of pages to allocate and use for this queue. This
  8565. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8566. * event queue. This function is asynchronous and will wait for the mailbox
  8567. * command to finish before continuing.
  8568. *
  8569. * On success this function will return a zero. If unable to allocate enough
  8570. * memory this function will return ENOMEM. If the queue create mailbox command
  8571. * fails this function will return ENXIO.
  8572. **/
  8573. uint32_t
  8574. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8575. {
  8576. struct lpfc_mbx_eq_create *eq_create;
  8577. LPFC_MBOXQ_t *mbox;
  8578. int rc, length, status = 0;
  8579. struct lpfc_dmabuf *dmabuf;
  8580. uint32_t shdr_status, shdr_add_status;
  8581. union lpfc_sli4_cfg_shdr *shdr;
  8582. uint16_t dmult;
  8583. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8584. if (!mbox)
  8585. return -ENOMEM;
  8586. length = (sizeof(struct lpfc_mbx_eq_create) -
  8587. sizeof(struct lpfc_sli4_cfg_mhdr));
  8588. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8589. LPFC_MBOX_OPCODE_EQ_CREATE,
  8590. length, LPFC_SLI4_MBX_EMBED);
  8591. eq_create = &mbox->u.mqe.un.eq_create;
  8592. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8593. eq->page_count);
  8594. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8595. LPFC_EQE_SIZE);
  8596. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8597. /* Calculate delay multiper from maximum interrupt per second */
  8598. dmult = LPFC_DMULT_CONST/imax - 1;
  8599. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8600. dmult);
  8601. switch (eq->entry_count) {
  8602. default:
  8603. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8604. "0360 Unsupported EQ count. (%d)\n",
  8605. eq->entry_count);
  8606. if (eq->entry_count < 256)
  8607. return -EINVAL;
  8608. /* otherwise default to smallest count (drop through) */
  8609. case 256:
  8610. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8611. LPFC_EQ_CNT_256);
  8612. break;
  8613. case 512:
  8614. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8615. LPFC_EQ_CNT_512);
  8616. break;
  8617. case 1024:
  8618. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8619. LPFC_EQ_CNT_1024);
  8620. break;
  8621. case 2048:
  8622. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8623. LPFC_EQ_CNT_2048);
  8624. break;
  8625. case 4096:
  8626. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8627. LPFC_EQ_CNT_4096);
  8628. break;
  8629. }
  8630. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8631. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8632. putPaddrLow(dmabuf->phys);
  8633. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8634. putPaddrHigh(dmabuf->phys);
  8635. }
  8636. mbox->vport = phba->pport;
  8637. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8638. mbox->context1 = NULL;
  8639. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8640. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8641. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8642. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8643. if (shdr_status || shdr_add_status || rc) {
  8644. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8645. "2500 EQ_CREATE mailbox failed with "
  8646. "status x%x add_status x%x, mbx status x%x\n",
  8647. shdr_status, shdr_add_status, rc);
  8648. status = -ENXIO;
  8649. }
  8650. eq->type = LPFC_EQ;
  8651. eq->subtype = LPFC_NONE;
  8652. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8653. if (eq->queue_id == 0xFFFF)
  8654. status = -ENXIO;
  8655. eq->host_index = 0;
  8656. eq->hba_index = 0;
  8657. mempool_free(mbox, phba->mbox_mem_pool);
  8658. return status;
  8659. }
  8660. /**
  8661. * lpfc_cq_create - Create a Completion Queue on the HBA
  8662. * @phba: HBA structure that indicates port to create a queue on.
  8663. * @cq: The queue structure to use to create the completion queue.
  8664. * @eq: The event queue to bind this completion queue to.
  8665. *
  8666. * This function creates a completion queue, as detailed in @wq, on a port,
  8667. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8668. *
  8669. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8670. * is used to get the entry count and entry size that are necessary to
  8671. * determine the number of pages to allocate and use for this queue. The @eq
  8672. * is used to indicate which event queue to bind this completion queue to. This
  8673. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8674. * completion queue. This function is asynchronous and will wait for the mailbox
  8675. * command to finish before continuing.
  8676. *
  8677. * On success this function will return a zero. If unable to allocate enough
  8678. * memory this function will return ENOMEM. If the queue create mailbox command
  8679. * fails this function will return ENXIO.
  8680. **/
  8681. uint32_t
  8682. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8683. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8684. {
  8685. struct lpfc_mbx_cq_create *cq_create;
  8686. struct lpfc_dmabuf *dmabuf;
  8687. LPFC_MBOXQ_t *mbox;
  8688. int rc, length, status = 0;
  8689. uint32_t shdr_status, shdr_add_status;
  8690. union lpfc_sli4_cfg_shdr *shdr;
  8691. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8692. if (!mbox)
  8693. return -ENOMEM;
  8694. length = (sizeof(struct lpfc_mbx_cq_create) -
  8695. sizeof(struct lpfc_sli4_cfg_mhdr));
  8696. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8697. LPFC_MBOX_OPCODE_CQ_CREATE,
  8698. length, LPFC_SLI4_MBX_EMBED);
  8699. cq_create = &mbox->u.mqe.un.cq_create;
  8700. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8701. cq->page_count);
  8702. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8703. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8704. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8705. switch (cq->entry_count) {
  8706. default:
  8707. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8708. "0361 Unsupported CQ count. (%d)\n",
  8709. cq->entry_count);
  8710. if (cq->entry_count < 256)
  8711. return -EINVAL;
  8712. /* otherwise default to smallest count (drop through) */
  8713. case 256:
  8714. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8715. LPFC_CQ_CNT_256);
  8716. break;
  8717. case 512:
  8718. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8719. LPFC_CQ_CNT_512);
  8720. break;
  8721. case 1024:
  8722. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8723. LPFC_CQ_CNT_1024);
  8724. break;
  8725. }
  8726. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8727. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8728. putPaddrLow(dmabuf->phys);
  8729. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8730. putPaddrHigh(dmabuf->phys);
  8731. }
  8732. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8733. /* The IOCTL status is embedded in the mailbox subheader. */
  8734. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8735. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8736. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8737. if (shdr_status || shdr_add_status || rc) {
  8738. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8739. "2501 CQ_CREATE mailbox failed with "
  8740. "status x%x add_status x%x, mbx status x%x\n",
  8741. shdr_status, shdr_add_status, rc);
  8742. status = -ENXIO;
  8743. goto out;
  8744. }
  8745. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8746. if (cq->queue_id == 0xFFFF) {
  8747. status = -ENXIO;
  8748. goto out;
  8749. }
  8750. /* link the cq onto the parent eq child list */
  8751. list_add_tail(&cq->list, &eq->child_list);
  8752. /* Set up completion queue's type and subtype */
  8753. cq->type = type;
  8754. cq->subtype = subtype;
  8755. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8756. cq->host_index = 0;
  8757. cq->hba_index = 0;
  8758. out:
  8759. mempool_free(mbox, phba->mbox_mem_pool);
  8760. return status;
  8761. }
  8762. /**
  8763. * lpfc_mq_create - Create a mailbox Queue on the HBA
  8764. * @phba: HBA structure that indicates port to create a queue on.
  8765. * @mq: The queue structure to use to create the mailbox queue.
  8766. *
  8767. * This function creates a mailbox queue, as detailed in @mq, on a port,
  8768. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  8769. *
  8770. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8771. * is used to get the entry count and entry size that are necessary to
  8772. * determine the number of pages to allocate and use for this queue. This
  8773. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  8774. * mailbox queue. This function is asynchronous and will wait for the mailbox
  8775. * command to finish before continuing.
  8776. *
  8777. * On success this function will return a zero. If unable to allocate enough
  8778. * memory this function will return ENOMEM. If the queue create mailbox command
  8779. * fails this function will return ENXIO.
  8780. **/
  8781. uint32_t
  8782. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  8783. struct lpfc_queue *cq, uint32_t subtype)
  8784. {
  8785. struct lpfc_mbx_mq_create *mq_create;
  8786. struct lpfc_dmabuf *dmabuf;
  8787. LPFC_MBOXQ_t *mbox;
  8788. int rc, length, status = 0;
  8789. uint32_t shdr_status, shdr_add_status;
  8790. union lpfc_sli4_cfg_shdr *shdr;
  8791. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8792. if (!mbox)
  8793. return -ENOMEM;
  8794. length = (sizeof(struct lpfc_mbx_mq_create) -
  8795. sizeof(struct lpfc_sli4_cfg_mhdr));
  8796. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8797. LPFC_MBOX_OPCODE_MQ_CREATE,
  8798. length, LPFC_SLI4_MBX_EMBED);
  8799. mq_create = &mbox->u.mqe.un.mq_create;
  8800. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  8801. mq->page_count);
  8802. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  8803. cq->queue_id);
  8804. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  8805. switch (mq->entry_count) {
  8806. default:
  8807. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8808. "0362 Unsupported MQ count. (%d)\n",
  8809. mq->entry_count);
  8810. if (mq->entry_count < 16)
  8811. return -EINVAL;
  8812. /* otherwise default to smallest count (drop through) */
  8813. case 16:
  8814. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8815. LPFC_MQ_CNT_16);
  8816. break;
  8817. case 32:
  8818. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8819. LPFC_MQ_CNT_32);
  8820. break;
  8821. case 64:
  8822. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8823. LPFC_MQ_CNT_64);
  8824. break;
  8825. case 128:
  8826. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8827. LPFC_MQ_CNT_128);
  8828. break;
  8829. }
  8830. list_for_each_entry(dmabuf, &mq->page_list, list) {
  8831. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8832. putPaddrLow(dmabuf->phys);
  8833. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8834. putPaddrHigh(dmabuf->phys);
  8835. }
  8836. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8837. /* The IOCTL status is embedded in the mailbox subheader. */
  8838. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  8839. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8840. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8841. if (shdr_status || shdr_add_status || rc) {
  8842. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8843. "2502 MQ_CREATE mailbox failed with "
  8844. "status x%x add_status x%x, mbx status x%x\n",
  8845. shdr_status, shdr_add_status, rc);
  8846. status = -ENXIO;
  8847. goto out;
  8848. }
  8849. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, &mq_create->u.response);
  8850. if (mq->queue_id == 0xFFFF) {
  8851. status = -ENXIO;
  8852. goto out;
  8853. }
  8854. mq->type = LPFC_MQ;
  8855. mq->subtype = subtype;
  8856. mq->host_index = 0;
  8857. mq->hba_index = 0;
  8858. /* link the mq onto the parent cq child list */
  8859. list_add_tail(&mq->list, &cq->child_list);
  8860. out:
  8861. mempool_free(mbox, phba->mbox_mem_pool);
  8862. return status;
  8863. }
  8864. /**
  8865. * lpfc_wq_create - Create a Work Queue on the HBA
  8866. * @phba: HBA structure that indicates port to create a queue on.
  8867. * @wq: The queue structure to use to create the work queue.
  8868. * @cq: The completion queue to bind this work queue to.
  8869. * @subtype: The subtype of the work queue indicating its functionality.
  8870. *
  8871. * This function creates a work queue, as detailed in @wq, on a port, described
  8872. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  8873. *
  8874. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  8875. * is used to get the entry count and entry size that are necessary to
  8876. * determine the number of pages to allocate and use for this queue. The @cq
  8877. * is used to indicate which completion queue to bind this work queue to. This
  8878. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  8879. * work queue. This function is asynchronous and will wait for the mailbox
  8880. * command to finish before continuing.
  8881. *
  8882. * On success this function will return a zero. If unable to allocate enough
  8883. * memory this function will return ENOMEM. If the queue create mailbox command
  8884. * fails this function will return ENXIO.
  8885. **/
  8886. uint32_t
  8887. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  8888. struct lpfc_queue *cq, uint32_t subtype)
  8889. {
  8890. struct lpfc_mbx_wq_create *wq_create;
  8891. struct lpfc_dmabuf *dmabuf;
  8892. LPFC_MBOXQ_t *mbox;
  8893. int rc, length, status = 0;
  8894. uint32_t shdr_status, shdr_add_status;
  8895. union lpfc_sli4_cfg_shdr *shdr;
  8896. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8897. if (!mbox)
  8898. return -ENOMEM;
  8899. length = (sizeof(struct lpfc_mbx_wq_create) -
  8900. sizeof(struct lpfc_sli4_cfg_mhdr));
  8901. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8902. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  8903. length, LPFC_SLI4_MBX_EMBED);
  8904. wq_create = &mbox->u.mqe.un.wq_create;
  8905. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  8906. wq->page_count);
  8907. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  8908. cq->queue_id);
  8909. list_for_each_entry(dmabuf, &wq->page_list, list) {
  8910. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8911. putPaddrLow(dmabuf->phys);
  8912. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8913. putPaddrHigh(dmabuf->phys);
  8914. }
  8915. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8916. /* The IOCTL status is embedded in the mailbox subheader. */
  8917. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  8918. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8919. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8920. if (shdr_status || shdr_add_status || rc) {
  8921. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8922. "2503 WQ_CREATE mailbox failed with "
  8923. "status x%x add_status x%x, mbx status x%x\n",
  8924. shdr_status, shdr_add_status, rc);
  8925. status = -ENXIO;
  8926. goto out;
  8927. }
  8928. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  8929. if (wq->queue_id == 0xFFFF) {
  8930. status = -ENXIO;
  8931. goto out;
  8932. }
  8933. wq->type = LPFC_WQ;
  8934. wq->subtype = subtype;
  8935. wq->host_index = 0;
  8936. wq->hba_index = 0;
  8937. /* link the wq onto the parent cq child list */
  8938. list_add_tail(&wq->list, &cq->child_list);
  8939. out:
  8940. mempool_free(mbox, phba->mbox_mem_pool);
  8941. return status;
  8942. }
  8943. /**
  8944. * lpfc_rq_create - Create a Receive Queue on the HBA
  8945. * @phba: HBA structure that indicates port to create a queue on.
  8946. * @hrq: The queue structure to use to create the header receive queue.
  8947. * @drq: The queue structure to use to create the data receive queue.
  8948. * @cq: The completion queue to bind this work queue to.
  8949. *
  8950. * This function creates a receive buffer queue pair , as detailed in @hrq and
  8951. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  8952. * to the HBA.
  8953. *
  8954. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  8955. * struct is used to get the entry count that is necessary to determine the
  8956. * number of pages to use for this queue. The @cq is used to indicate which
  8957. * completion queue to bind received buffers that are posted to these queues to.
  8958. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  8959. * receive queue pair. This function is asynchronous and will wait for the
  8960. * mailbox command to finish before continuing.
  8961. *
  8962. * On success this function will return a zero. If unable to allocate enough
  8963. * memory this function will return ENOMEM. If the queue create mailbox command
  8964. * fails this function will return ENXIO.
  8965. **/
  8966. uint32_t
  8967. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  8968. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  8969. {
  8970. struct lpfc_mbx_rq_create *rq_create;
  8971. struct lpfc_dmabuf *dmabuf;
  8972. LPFC_MBOXQ_t *mbox;
  8973. int rc, length, status = 0;
  8974. uint32_t shdr_status, shdr_add_status;
  8975. union lpfc_sli4_cfg_shdr *shdr;
  8976. if (hrq->entry_count != drq->entry_count)
  8977. return -EINVAL;
  8978. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8979. if (!mbox)
  8980. return -ENOMEM;
  8981. length = (sizeof(struct lpfc_mbx_rq_create) -
  8982. sizeof(struct lpfc_sli4_cfg_mhdr));
  8983. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8984. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  8985. length, LPFC_SLI4_MBX_EMBED);
  8986. rq_create = &mbox->u.mqe.un.rq_create;
  8987. switch (hrq->entry_count) {
  8988. default:
  8989. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8990. "2535 Unsupported RQ count. (%d)\n",
  8991. hrq->entry_count);
  8992. if (hrq->entry_count < 512)
  8993. return -EINVAL;
  8994. /* otherwise default to smallest count (drop through) */
  8995. case 512:
  8996. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8997. LPFC_RQ_RING_SIZE_512);
  8998. break;
  8999. case 1024:
  9000. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9001. LPFC_RQ_RING_SIZE_1024);
  9002. break;
  9003. case 2048:
  9004. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9005. LPFC_RQ_RING_SIZE_2048);
  9006. break;
  9007. case 4096:
  9008. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9009. LPFC_RQ_RING_SIZE_4096);
  9010. break;
  9011. }
  9012. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9013. cq->queue_id);
  9014. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9015. hrq->page_count);
  9016. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9017. LPFC_HDR_BUF_SIZE);
  9018. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9019. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9020. putPaddrLow(dmabuf->phys);
  9021. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9022. putPaddrHigh(dmabuf->phys);
  9023. }
  9024. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9025. /* The IOCTL status is embedded in the mailbox subheader. */
  9026. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9027. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9028. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9029. if (shdr_status || shdr_add_status || rc) {
  9030. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9031. "2504 RQ_CREATE mailbox failed with "
  9032. "status x%x add_status x%x, mbx status x%x\n",
  9033. shdr_status, shdr_add_status, rc);
  9034. status = -ENXIO;
  9035. goto out;
  9036. }
  9037. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9038. if (hrq->queue_id == 0xFFFF) {
  9039. status = -ENXIO;
  9040. goto out;
  9041. }
  9042. hrq->type = LPFC_HRQ;
  9043. hrq->subtype = subtype;
  9044. hrq->host_index = 0;
  9045. hrq->hba_index = 0;
  9046. /* now create the data queue */
  9047. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9048. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9049. length, LPFC_SLI4_MBX_EMBED);
  9050. switch (drq->entry_count) {
  9051. default:
  9052. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9053. "2536 Unsupported RQ count. (%d)\n",
  9054. drq->entry_count);
  9055. if (drq->entry_count < 512)
  9056. return -EINVAL;
  9057. /* otherwise default to smallest count (drop through) */
  9058. case 512:
  9059. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9060. LPFC_RQ_RING_SIZE_512);
  9061. break;
  9062. case 1024:
  9063. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9064. LPFC_RQ_RING_SIZE_1024);
  9065. break;
  9066. case 2048:
  9067. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9068. LPFC_RQ_RING_SIZE_2048);
  9069. break;
  9070. case 4096:
  9071. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9072. LPFC_RQ_RING_SIZE_4096);
  9073. break;
  9074. }
  9075. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9076. cq->queue_id);
  9077. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9078. drq->page_count);
  9079. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9080. LPFC_DATA_BUF_SIZE);
  9081. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9082. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9083. putPaddrLow(dmabuf->phys);
  9084. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9085. putPaddrHigh(dmabuf->phys);
  9086. }
  9087. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9088. /* The IOCTL status is embedded in the mailbox subheader. */
  9089. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9090. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9091. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9092. if (shdr_status || shdr_add_status || rc) {
  9093. status = -ENXIO;
  9094. goto out;
  9095. }
  9096. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9097. if (drq->queue_id == 0xFFFF) {
  9098. status = -ENXIO;
  9099. goto out;
  9100. }
  9101. drq->type = LPFC_DRQ;
  9102. drq->subtype = subtype;
  9103. drq->host_index = 0;
  9104. drq->hba_index = 0;
  9105. /* link the header and data RQs onto the parent cq child list */
  9106. list_add_tail(&hrq->list, &cq->child_list);
  9107. list_add_tail(&drq->list, &cq->child_list);
  9108. out:
  9109. mempool_free(mbox, phba->mbox_mem_pool);
  9110. return status;
  9111. }
  9112. /**
  9113. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9114. * @eq: The queue structure associated with the queue to destroy.
  9115. *
  9116. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9117. * command, specific to the type of queue, to the HBA.
  9118. *
  9119. * The @eq struct is used to get the queue ID of the queue to destroy.
  9120. *
  9121. * On success this function will return a zero. If the queue destroy mailbox
  9122. * command fails this function will return ENXIO.
  9123. **/
  9124. uint32_t
  9125. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9126. {
  9127. LPFC_MBOXQ_t *mbox;
  9128. int rc, length, status = 0;
  9129. uint32_t shdr_status, shdr_add_status;
  9130. union lpfc_sli4_cfg_shdr *shdr;
  9131. if (!eq)
  9132. return -ENODEV;
  9133. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9134. if (!mbox)
  9135. return -ENOMEM;
  9136. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9137. sizeof(struct lpfc_sli4_cfg_mhdr));
  9138. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9139. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9140. length, LPFC_SLI4_MBX_EMBED);
  9141. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9142. eq->queue_id);
  9143. mbox->vport = eq->phba->pport;
  9144. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9145. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9146. /* The IOCTL status is embedded in the mailbox subheader. */
  9147. shdr = (union lpfc_sli4_cfg_shdr *)
  9148. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9149. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9150. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9151. if (shdr_status || shdr_add_status || rc) {
  9152. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9153. "2505 EQ_DESTROY mailbox failed with "
  9154. "status x%x add_status x%x, mbx status x%x\n",
  9155. shdr_status, shdr_add_status, rc);
  9156. status = -ENXIO;
  9157. }
  9158. /* Remove eq from any list */
  9159. list_del_init(&eq->list);
  9160. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9161. return status;
  9162. }
  9163. /**
  9164. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9165. * @cq: The queue structure associated with the queue to destroy.
  9166. *
  9167. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9168. * command, specific to the type of queue, to the HBA.
  9169. *
  9170. * The @cq struct is used to get the queue ID of the queue to destroy.
  9171. *
  9172. * On success this function will return a zero. If the queue destroy mailbox
  9173. * command fails this function will return ENXIO.
  9174. **/
  9175. uint32_t
  9176. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9177. {
  9178. LPFC_MBOXQ_t *mbox;
  9179. int rc, length, status = 0;
  9180. uint32_t shdr_status, shdr_add_status;
  9181. union lpfc_sli4_cfg_shdr *shdr;
  9182. if (!cq)
  9183. return -ENODEV;
  9184. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9185. if (!mbox)
  9186. return -ENOMEM;
  9187. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9188. sizeof(struct lpfc_sli4_cfg_mhdr));
  9189. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9190. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9191. length, LPFC_SLI4_MBX_EMBED);
  9192. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9193. cq->queue_id);
  9194. mbox->vport = cq->phba->pport;
  9195. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9196. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9197. /* The IOCTL status is embedded in the mailbox subheader. */
  9198. shdr = (union lpfc_sli4_cfg_shdr *)
  9199. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9200. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9201. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9202. if (shdr_status || shdr_add_status || rc) {
  9203. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9204. "2506 CQ_DESTROY mailbox failed with "
  9205. "status x%x add_status x%x, mbx status x%x\n",
  9206. shdr_status, shdr_add_status, rc);
  9207. status = -ENXIO;
  9208. }
  9209. /* Remove cq from any list */
  9210. list_del_init(&cq->list);
  9211. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9212. return status;
  9213. }
  9214. /**
  9215. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9216. * @qm: The queue structure associated with the queue to destroy.
  9217. *
  9218. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9219. * command, specific to the type of queue, to the HBA.
  9220. *
  9221. * The @mq struct is used to get the queue ID of the queue to destroy.
  9222. *
  9223. * On success this function will return a zero. If the queue destroy mailbox
  9224. * command fails this function will return ENXIO.
  9225. **/
  9226. uint32_t
  9227. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9228. {
  9229. LPFC_MBOXQ_t *mbox;
  9230. int rc, length, status = 0;
  9231. uint32_t shdr_status, shdr_add_status;
  9232. union lpfc_sli4_cfg_shdr *shdr;
  9233. if (!mq)
  9234. return -ENODEV;
  9235. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9236. if (!mbox)
  9237. return -ENOMEM;
  9238. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9239. sizeof(struct lpfc_sli4_cfg_mhdr));
  9240. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9241. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9242. length, LPFC_SLI4_MBX_EMBED);
  9243. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9244. mq->queue_id);
  9245. mbox->vport = mq->phba->pport;
  9246. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9247. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9248. /* The IOCTL status is embedded in the mailbox subheader. */
  9249. shdr = (union lpfc_sli4_cfg_shdr *)
  9250. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9251. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9252. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9253. if (shdr_status || shdr_add_status || rc) {
  9254. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9255. "2507 MQ_DESTROY mailbox failed with "
  9256. "status x%x add_status x%x, mbx status x%x\n",
  9257. shdr_status, shdr_add_status, rc);
  9258. status = -ENXIO;
  9259. }
  9260. /* Remove mq from any list */
  9261. list_del_init(&mq->list);
  9262. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9263. return status;
  9264. }
  9265. /**
  9266. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9267. * @wq: The queue structure associated with the queue to destroy.
  9268. *
  9269. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9270. * command, specific to the type of queue, to the HBA.
  9271. *
  9272. * The @wq struct is used to get the queue ID of the queue to destroy.
  9273. *
  9274. * On success this function will return a zero. If the queue destroy mailbox
  9275. * command fails this function will return ENXIO.
  9276. **/
  9277. uint32_t
  9278. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9279. {
  9280. LPFC_MBOXQ_t *mbox;
  9281. int rc, length, status = 0;
  9282. uint32_t shdr_status, shdr_add_status;
  9283. union lpfc_sli4_cfg_shdr *shdr;
  9284. if (!wq)
  9285. return -ENODEV;
  9286. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9287. if (!mbox)
  9288. return -ENOMEM;
  9289. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9290. sizeof(struct lpfc_sli4_cfg_mhdr));
  9291. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9292. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9293. length, LPFC_SLI4_MBX_EMBED);
  9294. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9295. wq->queue_id);
  9296. mbox->vport = wq->phba->pport;
  9297. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9298. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9299. shdr = (union lpfc_sli4_cfg_shdr *)
  9300. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9301. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9302. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9303. if (shdr_status || shdr_add_status || rc) {
  9304. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9305. "2508 WQ_DESTROY mailbox failed with "
  9306. "status x%x add_status x%x, mbx status x%x\n",
  9307. shdr_status, shdr_add_status, rc);
  9308. status = -ENXIO;
  9309. }
  9310. /* Remove wq from any list */
  9311. list_del_init(&wq->list);
  9312. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9313. return status;
  9314. }
  9315. /**
  9316. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9317. * @rq: The queue structure associated with the queue to destroy.
  9318. *
  9319. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9320. * command, specific to the type of queue, to the HBA.
  9321. *
  9322. * The @rq struct is used to get the queue ID of the queue to destroy.
  9323. *
  9324. * On success this function will return a zero. If the queue destroy mailbox
  9325. * command fails this function will return ENXIO.
  9326. **/
  9327. uint32_t
  9328. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9329. struct lpfc_queue *drq)
  9330. {
  9331. LPFC_MBOXQ_t *mbox;
  9332. int rc, length, status = 0;
  9333. uint32_t shdr_status, shdr_add_status;
  9334. union lpfc_sli4_cfg_shdr *shdr;
  9335. if (!hrq || !drq)
  9336. return -ENODEV;
  9337. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9338. if (!mbox)
  9339. return -ENOMEM;
  9340. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9341. sizeof(struct mbox_header));
  9342. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9343. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9344. length, LPFC_SLI4_MBX_EMBED);
  9345. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9346. hrq->queue_id);
  9347. mbox->vport = hrq->phba->pport;
  9348. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9349. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9350. /* The IOCTL status is embedded in the mailbox subheader. */
  9351. shdr = (union lpfc_sli4_cfg_shdr *)
  9352. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9353. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9354. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9355. if (shdr_status || shdr_add_status || rc) {
  9356. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9357. "2509 RQ_DESTROY mailbox failed with "
  9358. "status x%x add_status x%x, mbx status x%x\n",
  9359. shdr_status, shdr_add_status, rc);
  9360. if (rc != MBX_TIMEOUT)
  9361. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9362. return -ENXIO;
  9363. }
  9364. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9365. drq->queue_id);
  9366. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9367. shdr = (union lpfc_sli4_cfg_shdr *)
  9368. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9369. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9370. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9371. if (shdr_status || shdr_add_status || rc) {
  9372. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9373. "2510 RQ_DESTROY mailbox failed with "
  9374. "status x%x add_status x%x, mbx status x%x\n",
  9375. shdr_status, shdr_add_status, rc);
  9376. status = -ENXIO;
  9377. }
  9378. list_del_init(&hrq->list);
  9379. list_del_init(&drq->list);
  9380. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9381. return status;
  9382. }
  9383. /**
  9384. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9385. * @phba: The virtual port for which this call being executed.
  9386. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9387. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9388. * @xritag: the xritag that ties this io to the SGL pages.
  9389. *
  9390. * This routine will post the sgl pages for the IO that has the xritag
  9391. * that is in the iocbq structure. The xritag is assigned during iocbq
  9392. * creation and persists for as long as the driver is loaded.
  9393. * if the caller has fewer than 256 scatter gather segments to map then
  9394. * pdma_phys_addr1 should be 0.
  9395. * If the caller needs to map more than 256 scatter gather segment then
  9396. * pdma_phys_addr1 should be a valid physical address.
  9397. * physical address for SGLs must be 64 byte aligned.
  9398. * If you are going to map 2 SGL's then the first one must have 256 entries
  9399. * the second sgl can have between 1 and 256 entries.
  9400. *
  9401. * Return codes:
  9402. * 0 - Success
  9403. * -ENXIO, -ENOMEM - Failure
  9404. **/
  9405. int
  9406. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9407. dma_addr_t pdma_phys_addr0,
  9408. dma_addr_t pdma_phys_addr1,
  9409. uint16_t xritag)
  9410. {
  9411. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9412. LPFC_MBOXQ_t *mbox;
  9413. int rc;
  9414. uint32_t shdr_status, shdr_add_status;
  9415. union lpfc_sli4_cfg_shdr *shdr;
  9416. if (xritag == NO_XRI) {
  9417. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9418. "0364 Invalid param:\n");
  9419. return -EINVAL;
  9420. }
  9421. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9422. if (!mbox)
  9423. return -ENOMEM;
  9424. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9425. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9426. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9427. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9428. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9429. &mbox->u.mqe.un.post_sgl_pages;
  9430. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9431. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9432. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9433. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9434. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9435. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9436. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9437. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9438. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9439. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9440. if (!phba->sli4_hba.intr_enable)
  9441. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9442. else
  9443. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9444. /* The IOCTL status is embedded in the mailbox subheader. */
  9445. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9446. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9447. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9448. if (rc != MBX_TIMEOUT)
  9449. mempool_free(mbox, phba->mbox_mem_pool);
  9450. if (shdr_status || shdr_add_status || rc) {
  9451. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9452. "2511 POST_SGL mailbox failed with "
  9453. "status x%x add_status x%x, mbx status x%x\n",
  9454. shdr_status, shdr_add_status, rc);
  9455. rc = -ENXIO;
  9456. }
  9457. return 0;
  9458. }
  9459. /**
  9460. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9461. * @phba: The virtual port for which this call being executed.
  9462. *
  9463. * This routine will remove all of the sgl pages registered with the hba.
  9464. *
  9465. * Return codes:
  9466. * 0 - Success
  9467. * -ENXIO, -ENOMEM - Failure
  9468. **/
  9469. int
  9470. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9471. {
  9472. LPFC_MBOXQ_t *mbox;
  9473. int rc;
  9474. uint32_t shdr_status, shdr_add_status;
  9475. union lpfc_sli4_cfg_shdr *shdr;
  9476. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9477. if (!mbox)
  9478. return -ENOMEM;
  9479. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9480. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9481. LPFC_SLI4_MBX_EMBED);
  9482. if (!phba->sli4_hba.intr_enable)
  9483. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9484. else
  9485. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9486. /* The IOCTL status is embedded in the mailbox subheader. */
  9487. shdr = (union lpfc_sli4_cfg_shdr *)
  9488. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9489. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9490. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9491. if (rc != MBX_TIMEOUT)
  9492. mempool_free(mbox, phba->mbox_mem_pool);
  9493. if (shdr_status || shdr_add_status || rc) {
  9494. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9495. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9496. "status x%x add_status x%x, mbx status x%x\n",
  9497. shdr_status, shdr_add_status, rc);
  9498. rc = -ENXIO;
  9499. }
  9500. return rc;
  9501. }
  9502. /**
  9503. * lpfc_sli4_next_xritag - Get an xritag for the io
  9504. * @phba: Pointer to HBA context object.
  9505. *
  9506. * This function gets an xritag for the iocb. If there is no unused xritag
  9507. * it will return 0xffff.
  9508. * The function returns the allocated xritag if successful, else returns zero.
  9509. * Zero is not a valid xritag.
  9510. * The caller is not required to hold any lock.
  9511. **/
  9512. uint16_t
  9513. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9514. {
  9515. uint16_t xritag;
  9516. spin_lock_irq(&phba->hbalock);
  9517. xritag = phba->sli4_hba.next_xri;
  9518. if ((xritag != (uint16_t) -1) && xritag <
  9519. (phba->sli4_hba.max_cfg_param.max_xri
  9520. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9521. phba->sli4_hba.next_xri++;
  9522. phba->sli4_hba.max_cfg_param.xri_used++;
  9523. spin_unlock_irq(&phba->hbalock);
  9524. return xritag;
  9525. }
  9526. spin_unlock_irq(&phba->hbalock);
  9527. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9528. "2004 Failed to allocate XRI.last XRITAG is %d"
  9529. " Max XRI is %d, Used XRI is %d\n",
  9530. phba->sli4_hba.next_xri,
  9531. phba->sli4_hba.max_cfg_param.max_xri,
  9532. phba->sli4_hba.max_cfg_param.xri_used);
  9533. return -1;
  9534. }
  9535. /**
  9536. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9537. * @phba: pointer to lpfc hba data structure.
  9538. *
  9539. * This routine is invoked to post a block of driver's sgl pages to the
  9540. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9541. * is only called when the driver is loading and after all IO has been
  9542. * stopped.
  9543. **/
  9544. int
  9545. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9546. {
  9547. struct lpfc_sglq *sglq_entry;
  9548. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9549. struct sgl_page_pairs *sgl_pg_pairs;
  9550. void *viraddr;
  9551. LPFC_MBOXQ_t *mbox;
  9552. uint32_t reqlen, alloclen, pg_pairs;
  9553. uint32_t mbox_tmo;
  9554. uint16_t xritag_start = 0;
  9555. int els_xri_cnt, rc = 0;
  9556. uint32_t shdr_status, shdr_add_status;
  9557. union lpfc_sli4_cfg_shdr *shdr;
  9558. /* The number of sgls to be posted */
  9559. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9560. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9561. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9562. if (reqlen > PAGE_SIZE) {
  9563. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9564. "2559 Block sgl registration required DMA "
  9565. "size (%d) great than a page\n", reqlen);
  9566. return -ENOMEM;
  9567. }
  9568. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9569. if (!mbox) {
  9570. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9571. "2560 Failed to allocate mbox cmd memory\n");
  9572. return -ENOMEM;
  9573. }
  9574. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9575. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9576. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9577. LPFC_SLI4_MBX_NEMBED);
  9578. if (alloclen < reqlen) {
  9579. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9580. "0285 Allocated DMA memory size (%d) is "
  9581. "less than the requested DMA memory "
  9582. "size (%d)\n", alloclen, reqlen);
  9583. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9584. return -ENOMEM;
  9585. }
  9586. /* Get the first SGE entry from the non-embedded DMA memory */
  9587. if (unlikely(!mbox->sge_array)) {
  9588. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  9589. "2525 Failed to get the non-embedded SGE "
  9590. "virtual address\n");
  9591. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9592. return -ENOMEM;
  9593. }
  9594. viraddr = mbox->sge_array->addr[0];
  9595. /* Set up the SGL pages in the non-embedded DMA pages */
  9596. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9597. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9598. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9599. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9600. /* Set up the sge entry */
  9601. sgl_pg_pairs->sgl_pg0_addr_lo =
  9602. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9603. sgl_pg_pairs->sgl_pg0_addr_hi =
  9604. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9605. sgl_pg_pairs->sgl_pg1_addr_lo =
  9606. cpu_to_le32(putPaddrLow(0));
  9607. sgl_pg_pairs->sgl_pg1_addr_hi =
  9608. cpu_to_le32(putPaddrHigh(0));
  9609. /* Keep the first xritag on the list */
  9610. if (pg_pairs == 0)
  9611. xritag_start = sglq_entry->sli4_xritag;
  9612. sgl_pg_pairs++;
  9613. }
  9614. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9615. pg_pairs = (pg_pairs > 0) ? (pg_pairs - 1) : pg_pairs;
  9616. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9617. /* Perform endian conversion if necessary */
  9618. sgl->word0 = cpu_to_le32(sgl->word0);
  9619. if (!phba->sli4_hba.intr_enable)
  9620. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9621. else {
  9622. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9623. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9624. }
  9625. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9626. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9627. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9628. if (rc != MBX_TIMEOUT)
  9629. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9630. if (shdr_status || shdr_add_status || rc) {
  9631. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9632. "2513 POST_SGL_BLOCK mailbox command failed "
  9633. "status x%x add_status x%x mbx status x%x\n",
  9634. shdr_status, shdr_add_status, rc);
  9635. rc = -ENXIO;
  9636. }
  9637. return rc;
  9638. }
  9639. /**
  9640. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9641. * @phba: pointer to lpfc hba data structure.
  9642. * @sblist: pointer to scsi buffer list.
  9643. * @count: number of scsi buffers on the list.
  9644. *
  9645. * This routine is invoked to post a block of @count scsi sgl pages from a
  9646. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9647. * No Lock is held.
  9648. *
  9649. **/
  9650. int
  9651. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9652. int cnt)
  9653. {
  9654. struct lpfc_scsi_buf *psb;
  9655. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9656. struct sgl_page_pairs *sgl_pg_pairs;
  9657. void *viraddr;
  9658. LPFC_MBOXQ_t *mbox;
  9659. uint32_t reqlen, alloclen, pg_pairs;
  9660. uint32_t mbox_tmo;
  9661. uint16_t xritag_start = 0;
  9662. int rc = 0;
  9663. uint32_t shdr_status, shdr_add_status;
  9664. dma_addr_t pdma_phys_bpl1;
  9665. union lpfc_sli4_cfg_shdr *shdr;
  9666. /* Calculate the requested length of the dma memory */
  9667. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  9668. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9669. if (reqlen > PAGE_SIZE) {
  9670. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9671. "0217 Block sgl registration required DMA "
  9672. "size (%d) great than a page\n", reqlen);
  9673. return -ENOMEM;
  9674. }
  9675. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9676. if (!mbox) {
  9677. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9678. "0283 Failed to allocate mbox cmd memory\n");
  9679. return -ENOMEM;
  9680. }
  9681. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9682. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9683. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9684. LPFC_SLI4_MBX_NEMBED);
  9685. if (alloclen < reqlen) {
  9686. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9687. "2561 Allocated DMA memory size (%d) is "
  9688. "less than the requested DMA memory "
  9689. "size (%d)\n", alloclen, reqlen);
  9690. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9691. return -ENOMEM;
  9692. }
  9693. /* Get the first SGE entry from the non-embedded DMA memory */
  9694. if (unlikely(!mbox->sge_array)) {
  9695. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  9696. "2565 Failed to get the non-embedded SGE "
  9697. "virtual address\n");
  9698. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9699. return -ENOMEM;
  9700. }
  9701. viraddr = mbox->sge_array->addr[0];
  9702. /* Set up the SGL pages in the non-embedded DMA pages */
  9703. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9704. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9705. pg_pairs = 0;
  9706. list_for_each_entry(psb, sblist, list) {
  9707. /* Set up the sge entry */
  9708. sgl_pg_pairs->sgl_pg0_addr_lo =
  9709. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  9710. sgl_pg_pairs->sgl_pg0_addr_hi =
  9711. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  9712. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  9713. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  9714. else
  9715. pdma_phys_bpl1 = 0;
  9716. sgl_pg_pairs->sgl_pg1_addr_lo =
  9717. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  9718. sgl_pg_pairs->sgl_pg1_addr_hi =
  9719. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  9720. /* Keep the first xritag on the list */
  9721. if (pg_pairs == 0)
  9722. xritag_start = psb->cur_iocbq.sli4_xritag;
  9723. sgl_pg_pairs++;
  9724. pg_pairs++;
  9725. }
  9726. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9727. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9728. /* Perform endian conversion if necessary */
  9729. sgl->word0 = cpu_to_le32(sgl->word0);
  9730. if (!phba->sli4_hba.intr_enable)
  9731. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9732. else {
  9733. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9734. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9735. }
  9736. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9737. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9738. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9739. if (rc != MBX_TIMEOUT)
  9740. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9741. if (shdr_status || shdr_add_status || rc) {
  9742. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9743. "2564 POST_SGL_BLOCK mailbox command failed "
  9744. "status x%x add_status x%x mbx status x%x\n",
  9745. shdr_status, shdr_add_status, rc);
  9746. rc = -ENXIO;
  9747. }
  9748. return rc;
  9749. }
  9750. /**
  9751. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  9752. * @phba: pointer to lpfc_hba struct that the frame was received on
  9753. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9754. *
  9755. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  9756. * valid type of frame that the LPFC driver will handle. This function will
  9757. * return a zero if the frame is a valid frame or a non zero value when the
  9758. * frame does not pass the check.
  9759. **/
  9760. static int
  9761. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  9762. {
  9763. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  9764. char *type_names[] = FC_TYPE_NAMES_INIT;
  9765. struct fc_vft_header *fc_vft_hdr;
  9766. switch (fc_hdr->fh_r_ctl) {
  9767. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  9768. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  9769. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  9770. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  9771. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  9772. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  9773. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  9774. case FC_RCTL_DD_CMD_STATUS: /* command status */
  9775. case FC_RCTL_ELS_REQ: /* extended link services request */
  9776. case FC_RCTL_ELS_REP: /* extended link services reply */
  9777. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  9778. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  9779. case FC_RCTL_BA_NOP: /* basic link service NOP */
  9780. case FC_RCTL_BA_ABTS: /* basic link service abort */
  9781. case FC_RCTL_BA_RMC: /* remove connection */
  9782. case FC_RCTL_BA_ACC: /* basic accept */
  9783. case FC_RCTL_BA_RJT: /* basic reject */
  9784. case FC_RCTL_BA_PRMT:
  9785. case FC_RCTL_ACK_1: /* acknowledge_1 */
  9786. case FC_RCTL_ACK_0: /* acknowledge_0 */
  9787. case FC_RCTL_P_RJT: /* port reject */
  9788. case FC_RCTL_F_RJT: /* fabric reject */
  9789. case FC_RCTL_P_BSY: /* port busy */
  9790. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  9791. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  9792. case FC_RCTL_LCR: /* link credit reset */
  9793. case FC_RCTL_END: /* end */
  9794. break;
  9795. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  9796. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9797. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  9798. return lpfc_fc_frame_check(phba, fc_hdr);
  9799. default:
  9800. goto drop;
  9801. }
  9802. switch (fc_hdr->fh_type) {
  9803. case FC_TYPE_BLS:
  9804. case FC_TYPE_ELS:
  9805. case FC_TYPE_FCP:
  9806. case FC_TYPE_CT:
  9807. break;
  9808. case FC_TYPE_IP:
  9809. case FC_TYPE_ILS:
  9810. default:
  9811. goto drop;
  9812. }
  9813. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  9814. "2538 Received frame rctl:%s type:%s\n",
  9815. rctl_names[fc_hdr->fh_r_ctl],
  9816. type_names[fc_hdr->fh_type]);
  9817. return 0;
  9818. drop:
  9819. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  9820. "2539 Dropped frame rctl:%s type:%s\n",
  9821. rctl_names[fc_hdr->fh_r_ctl],
  9822. type_names[fc_hdr->fh_type]);
  9823. return 1;
  9824. }
  9825. /**
  9826. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  9827. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9828. *
  9829. * This function processes the FC header to retrieve the VFI from the VF
  9830. * header, if one exists. This function will return the VFI if one exists
  9831. * or 0 if no VSAN Header exists.
  9832. **/
  9833. static uint32_t
  9834. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  9835. {
  9836. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9837. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  9838. return 0;
  9839. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  9840. }
  9841. /**
  9842. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  9843. * @phba: Pointer to the HBA structure to search for the vport on
  9844. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9845. * @fcfi: The FC Fabric ID that the frame came from
  9846. *
  9847. * This function searches the @phba for a vport that matches the content of the
  9848. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  9849. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  9850. * returns the matching vport pointer or NULL if unable to match frame to a
  9851. * vport.
  9852. **/
  9853. static struct lpfc_vport *
  9854. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  9855. uint16_t fcfi)
  9856. {
  9857. struct lpfc_vport **vports;
  9858. struct lpfc_vport *vport = NULL;
  9859. int i;
  9860. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  9861. fc_hdr->fh_d_id[1] << 8 |
  9862. fc_hdr->fh_d_id[2]);
  9863. vports = lpfc_create_vport_work_array(phba);
  9864. if (vports != NULL)
  9865. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  9866. if (phba->fcf.fcfi == fcfi &&
  9867. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  9868. vports[i]->fc_myDID == did) {
  9869. vport = vports[i];
  9870. break;
  9871. }
  9872. }
  9873. lpfc_destroy_vport_work_array(phba, vports);
  9874. return vport;
  9875. }
  9876. /**
  9877. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  9878. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  9879. *
  9880. * This function searches through the existing incomplete sequences that have
  9881. * been sent to this @vport. If the frame matches one of the incomplete
  9882. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  9883. * make up that sequence. If no sequence is found that matches this frame then
  9884. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  9885. * This function returns a pointer to the first dmabuf in the sequence list that
  9886. * the frame was linked to.
  9887. **/
  9888. static struct hbq_dmabuf *
  9889. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  9890. {
  9891. struct fc_frame_header *new_hdr;
  9892. struct fc_frame_header *temp_hdr;
  9893. struct lpfc_dmabuf *d_buf;
  9894. struct lpfc_dmabuf *h_buf;
  9895. struct hbq_dmabuf *seq_dmabuf = NULL;
  9896. struct hbq_dmabuf *temp_dmabuf = NULL;
  9897. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  9898. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  9899. /* Use the hdr_buf to find the sequence that this frame belongs to */
  9900. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  9901. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  9902. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  9903. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  9904. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  9905. continue;
  9906. /* found a pending sequence that matches this frame */
  9907. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9908. break;
  9909. }
  9910. if (!seq_dmabuf) {
  9911. /*
  9912. * This indicates first frame received for this sequence.
  9913. * Queue the buffer on the vport's rcv_buffer_list.
  9914. */
  9915. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  9916. return dmabuf;
  9917. }
  9918. temp_hdr = seq_dmabuf->hbuf.virt;
  9919. if (new_hdr->fh_seq_cnt < temp_hdr->fh_seq_cnt) {
  9920. list_del_init(&seq_dmabuf->hbuf.list);
  9921. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  9922. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  9923. return dmabuf;
  9924. }
  9925. /* find the correct place in the sequence to insert this frame */
  9926. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  9927. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  9928. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  9929. /*
  9930. * If the frame's sequence count is greater than the frame on
  9931. * the list then insert the frame right after this frame
  9932. */
  9933. if (new_hdr->fh_seq_cnt > temp_hdr->fh_seq_cnt) {
  9934. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  9935. return seq_dmabuf;
  9936. }
  9937. }
  9938. return NULL;
  9939. }
  9940. /**
  9941. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  9942. * @vport: pointer to a vitural port
  9943. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  9944. *
  9945. * This function tries to abort from the partially assembed sequence, described
  9946. * by the information from basic abbort @dmabuf. It checks to see whether such
  9947. * partially assembled sequence held by the driver. If so, it shall free up all
  9948. * the frames from the partially assembled sequence.
  9949. *
  9950. * Return
  9951. * true -- if there is matching partially assembled sequence present and all
  9952. * the frames freed with the sequence;
  9953. * false -- if there is no matching partially assembled sequence present so
  9954. * nothing got aborted in the lower layer driver
  9955. **/
  9956. static bool
  9957. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  9958. struct hbq_dmabuf *dmabuf)
  9959. {
  9960. struct fc_frame_header *new_hdr;
  9961. struct fc_frame_header *temp_hdr;
  9962. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  9963. struct hbq_dmabuf *seq_dmabuf = NULL;
  9964. /* Use the hdr_buf to find the sequence that matches this frame */
  9965. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  9966. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  9967. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  9968. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  9969. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  9970. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  9971. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  9972. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  9973. continue;
  9974. /* found a pending sequence that matches this frame */
  9975. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9976. break;
  9977. }
  9978. /* Free up all the frames from the partially assembled sequence */
  9979. if (seq_dmabuf) {
  9980. list_for_each_entry_safe(d_buf, n_buf,
  9981. &seq_dmabuf->dbuf.list, list) {
  9982. list_del_init(&d_buf->list);
  9983. lpfc_in_buf_free(vport->phba, d_buf);
  9984. }
  9985. return true;
  9986. }
  9987. return false;
  9988. }
  9989. /**
  9990. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  9991. * @phba: Pointer to HBA context object.
  9992. * @cmd_iocbq: pointer to the command iocbq structure.
  9993. * @rsp_iocbq: pointer to the response iocbq structure.
  9994. *
  9995. * This function handles the sequence abort accept iocb command complete
  9996. * event. It properly releases the memory allocated to the sequence abort
  9997. * accept iocb.
  9998. **/
  9999. static void
  10000. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10001. struct lpfc_iocbq *cmd_iocbq,
  10002. struct lpfc_iocbq *rsp_iocbq)
  10003. {
  10004. if (cmd_iocbq)
  10005. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10006. }
  10007. /**
  10008. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10009. * @phba: Pointer to HBA context object.
  10010. * @fc_hdr: pointer to a FC frame header.
  10011. *
  10012. * This function sends a basic accept to a previous unsol sequence abort
  10013. * event after aborting the sequence handling.
  10014. **/
  10015. static void
  10016. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10017. struct fc_frame_header *fc_hdr)
  10018. {
  10019. struct lpfc_iocbq *ctiocb = NULL;
  10020. struct lpfc_nodelist *ndlp;
  10021. uint16_t oxid;
  10022. uint32_t sid;
  10023. IOCB_t *icmd;
  10024. if (!lpfc_is_link_up(phba))
  10025. return;
  10026. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10027. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10028. ndlp = lpfc_findnode_did(phba->pport, sid);
  10029. if (!ndlp) {
  10030. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10031. "1268 Find ndlp returned NULL for oxid:x%x "
  10032. "SID:x%x\n", oxid, sid);
  10033. return;
  10034. }
  10035. /* Allocate buffer for acc iocb */
  10036. ctiocb = lpfc_sli_get_iocbq(phba);
  10037. if (!ctiocb)
  10038. return;
  10039. icmd = &ctiocb->iocb;
  10040. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10041. icmd->un.xseq64.bdl.bdeSize = 0;
  10042. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10043. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10044. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10045. /* Fill in the rest of iocb fields */
  10046. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10047. icmd->ulpBdeCount = 0;
  10048. icmd->ulpLe = 1;
  10049. icmd->ulpClass = CLASS3;
  10050. icmd->ulpContext = ndlp->nlp_rpi;
  10051. icmd->un.ulpWord[3] = oxid;
  10052. ctiocb->sli4_xritag = NO_XRI;
  10053. ctiocb->iocb_cmpl = NULL;
  10054. ctiocb->vport = phba->pport;
  10055. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10056. /* Xmit CT abts accept on exchange <xid> */
  10057. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10058. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10059. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10060. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10061. }
  10062. /**
  10063. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10064. * @vport: Pointer to the vport on which this sequence was received
  10065. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10066. *
  10067. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10068. * receive sequence is only partially assembed by the driver, it shall abort
  10069. * the partially assembled frames for the sequence. Otherwise, if the
  10070. * unsolicited receive sequence has been completely assembled and passed to
  10071. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10072. * unsolicited sequence has been aborted. After that, it will issue a basic
  10073. * accept to accept the abort.
  10074. **/
  10075. void
  10076. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10077. struct hbq_dmabuf *dmabuf)
  10078. {
  10079. struct lpfc_hba *phba = vport->phba;
  10080. struct fc_frame_header fc_hdr;
  10081. bool abts_par;
  10082. /* Try to abort partially assembled seq */
  10083. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  10084. /* Make a copy of fc_hdr before the dmabuf being released */
  10085. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  10086. /* Send abort to ULP if partially seq abort failed */
  10087. if (abts_par == false)
  10088. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  10089. else
  10090. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10091. /* Send basic accept (BA_ACC) to the abort requester */
  10092. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  10093. }
  10094. /**
  10095. * lpfc_seq_complete - Indicates if a sequence is complete
  10096. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10097. *
  10098. * This function checks the sequence, starting with the frame described by
  10099. * @dmabuf, to see if all the frames associated with this sequence are present.
  10100. * the frames associated with this sequence are linked to the @dmabuf using the
  10101. * dbuf list. This function looks for two major things. 1) That the first frame
  10102. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  10103. * set. 3) That there are no holes in the sequence count. The function will
  10104. * return 1 when the sequence is complete, otherwise it will return 0.
  10105. **/
  10106. static int
  10107. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  10108. {
  10109. struct fc_frame_header *hdr;
  10110. struct lpfc_dmabuf *d_buf;
  10111. struct hbq_dmabuf *seq_dmabuf;
  10112. uint32_t fctl;
  10113. int seq_count = 0;
  10114. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10115. /* make sure first fame of sequence has a sequence count of zero */
  10116. if (hdr->fh_seq_cnt != seq_count)
  10117. return 0;
  10118. fctl = (hdr->fh_f_ctl[0] << 16 |
  10119. hdr->fh_f_ctl[1] << 8 |
  10120. hdr->fh_f_ctl[2]);
  10121. /* If last frame of sequence we can return success. */
  10122. if (fctl & FC_FC_END_SEQ)
  10123. return 1;
  10124. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  10125. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10126. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10127. /* If there is a hole in the sequence count then fail. */
  10128. if (++seq_count != hdr->fh_seq_cnt)
  10129. return 0;
  10130. fctl = (hdr->fh_f_ctl[0] << 16 |
  10131. hdr->fh_f_ctl[1] << 8 |
  10132. hdr->fh_f_ctl[2]);
  10133. /* If last frame of sequence we can return success. */
  10134. if (fctl & FC_FC_END_SEQ)
  10135. return 1;
  10136. }
  10137. return 0;
  10138. }
  10139. /**
  10140. * lpfc_prep_seq - Prep sequence for ULP processing
  10141. * @vport: Pointer to the vport on which this sequence was received
  10142. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10143. *
  10144. * This function takes a sequence, described by a list of frames, and creates
  10145. * a list of iocbq structures to describe the sequence. This iocbq list will be
  10146. * used to issue to the generic unsolicited sequence handler. This routine
  10147. * returns a pointer to the first iocbq in the list. If the function is unable
  10148. * to allocate an iocbq then it throw out the received frames that were not
  10149. * able to be described and return a pointer to the first iocbq. If unable to
  10150. * allocate any iocbqs (including the first) this function will return NULL.
  10151. **/
  10152. static struct lpfc_iocbq *
  10153. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  10154. {
  10155. struct lpfc_dmabuf *d_buf, *n_buf;
  10156. struct lpfc_iocbq *first_iocbq, *iocbq;
  10157. struct fc_frame_header *fc_hdr;
  10158. uint32_t sid;
  10159. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10160. /* remove from receive buffer list */
  10161. list_del_init(&seq_dmabuf->hbuf.list);
  10162. /* get the Remote Port's SID */
  10163. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10164. /* Get an iocbq struct to fill in. */
  10165. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  10166. if (first_iocbq) {
  10167. /* Initialize the first IOCB. */
  10168. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  10169. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  10170. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  10171. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  10172. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  10173. vport->vpi + vport->phba->vpi_base;
  10174. /* put the first buffer into the first IOCBq */
  10175. first_iocbq->context2 = &seq_dmabuf->dbuf;
  10176. first_iocbq->context3 = NULL;
  10177. first_iocbq->iocb.ulpBdeCount = 1;
  10178. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10179. LPFC_DATA_BUF_SIZE;
  10180. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10181. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10182. bf_get(lpfc_rcqe_length,
  10183. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10184. }
  10185. iocbq = first_iocbq;
  10186. /*
  10187. * Each IOCBq can have two Buffers assigned, so go through the list
  10188. * of buffers for this sequence and save two buffers in each IOCBq
  10189. */
  10190. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10191. if (!iocbq) {
  10192. lpfc_in_buf_free(vport->phba, d_buf);
  10193. continue;
  10194. }
  10195. if (!iocbq->context3) {
  10196. iocbq->context3 = d_buf;
  10197. iocbq->iocb.ulpBdeCount++;
  10198. iocbq->iocb.unsli3.rcvsli3.bde2.tus.f.bdeSize =
  10199. LPFC_DATA_BUF_SIZE;
  10200. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10201. bf_get(lpfc_rcqe_length,
  10202. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10203. } else {
  10204. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10205. if (!iocbq) {
  10206. if (first_iocbq) {
  10207. first_iocbq->iocb.ulpStatus =
  10208. IOSTAT_FCP_RSP_ERROR;
  10209. first_iocbq->iocb.un.ulpWord[4] =
  10210. IOERR_NO_RESOURCES;
  10211. }
  10212. lpfc_in_buf_free(vport->phba, d_buf);
  10213. continue;
  10214. }
  10215. iocbq->context2 = d_buf;
  10216. iocbq->context3 = NULL;
  10217. iocbq->iocb.ulpBdeCount = 1;
  10218. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10219. LPFC_DATA_BUF_SIZE;
  10220. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10221. bf_get(lpfc_rcqe_length,
  10222. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10223. iocbq->iocb.un.rcvels.remoteID = sid;
  10224. list_add_tail(&iocbq->list, &first_iocbq->list);
  10225. }
  10226. }
  10227. return first_iocbq;
  10228. }
  10229. static void
  10230. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  10231. struct hbq_dmabuf *seq_dmabuf)
  10232. {
  10233. struct fc_frame_header *fc_hdr;
  10234. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  10235. struct lpfc_hba *phba = vport->phba;
  10236. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10237. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10238. if (!iocbq) {
  10239. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10240. "2707 Ring %d handler: Failed to allocate "
  10241. "iocb Rctl x%x Type x%x received\n",
  10242. LPFC_ELS_RING,
  10243. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10244. return;
  10245. }
  10246. if (!lpfc_complete_unsol_iocb(phba,
  10247. &phba->sli.ring[LPFC_ELS_RING],
  10248. iocbq, fc_hdr->fh_r_ctl,
  10249. fc_hdr->fh_type))
  10250. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10251. "2540 Ring %d handler: unexpected Rctl "
  10252. "x%x Type x%x received\n",
  10253. LPFC_ELS_RING,
  10254. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10255. /* Free iocb created in lpfc_prep_seq */
  10256. list_for_each_entry_safe(curr_iocb, next_iocb,
  10257. &iocbq->list, list) {
  10258. list_del_init(&curr_iocb->list);
  10259. lpfc_sli_release_iocbq(phba, curr_iocb);
  10260. }
  10261. lpfc_sli_release_iocbq(phba, iocbq);
  10262. }
  10263. /**
  10264. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10265. * @phba: Pointer to HBA context object.
  10266. *
  10267. * This function is called with no lock held. This function processes all
  10268. * the received buffers and gives it to upper layers when a received buffer
  10269. * indicates that it is the final frame in the sequence. The interrupt
  10270. * service routine processes received buffers at interrupt contexts and adds
  10271. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10272. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10273. * appropriate receive function when the final frame in a sequence is received.
  10274. **/
  10275. void
  10276. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10277. struct hbq_dmabuf *dmabuf)
  10278. {
  10279. struct hbq_dmabuf *seq_dmabuf;
  10280. struct fc_frame_header *fc_hdr;
  10281. struct lpfc_vport *vport;
  10282. uint32_t fcfi;
  10283. /* Clear hba flag and get all received buffers into the cmplq */
  10284. spin_lock_irq(&phba->hbalock);
  10285. phba->hba_flag &= ~HBA_RECEIVE_BUFFER;
  10286. spin_unlock_irq(&phba->hbalock);
  10287. /* Process each received buffer */
  10288. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10289. /* check to see if this a valid type of frame */
  10290. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10291. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10292. return;
  10293. }
  10294. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10295. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10296. if (!vport) {
  10297. /* throw out the frame */
  10298. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10299. return;
  10300. }
  10301. /* Handle the basic abort sequence (BA_ABTS) event */
  10302. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  10303. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  10304. return;
  10305. }
  10306. /* Link this frame */
  10307. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10308. if (!seq_dmabuf) {
  10309. /* unable to add frame to vport - throw it out */
  10310. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10311. return;
  10312. }
  10313. /* If not last frame in sequence continue processing frames. */
  10314. if (!lpfc_seq_complete(seq_dmabuf)) {
  10315. /*
  10316. * When saving off frames post a new one and mark this
  10317. * frame to be freed when it is finished.
  10318. **/
  10319. lpfc_sli_hbqbuf_fill_hbqs(phba, LPFC_ELS_HBQ, 1);
  10320. dmabuf->tag = -1;
  10321. return;
  10322. }
  10323. /* Send the complete sequence to the upper layer protocol */
  10324. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  10325. }
  10326. /**
  10327. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10328. * @phba: pointer to lpfc hba data structure.
  10329. *
  10330. * This routine is invoked to post rpi header templates to the
  10331. * HBA consistent with the SLI-4 interface spec. This routine
  10332. * posts a PAGE_SIZE memory region to the port to hold up to
  10333. * PAGE_SIZE modulo 64 rpi context headers.
  10334. *
  10335. * This routine does not require any locks. It's usage is expected
  10336. * to be driver load or reset recovery when the driver is
  10337. * sequential.
  10338. *
  10339. * Return codes
  10340. * 0 - sucessful
  10341. * EIO - The mailbox failed to complete successfully.
  10342. * When this error occurs, the driver is not guaranteed
  10343. * to have any rpi regions posted to the device and
  10344. * must either attempt to repost the regions or take a
  10345. * fatal error.
  10346. **/
  10347. int
  10348. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10349. {
  10350. struct lpfc_rpi_hdr *rpi_page;
  10351. uint32_t rc = 0;
  10352. /* Post all rpi memory regions to the port. */
  10353. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10354. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10355. if (rc != MBX_SUCCESS) {
  10356. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10357. "2008 Error %d posting all rpi "
  10358. "headers\n", rc);
  10359. rc = -EIO;
  10360. break;
  10361. }
  10362. }
  10363. return rc;
  10364. }
  10365. /**
  10366. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10367. * @phba: pointer to lpfc hba data structure.
  10368. * @rpi_page: pointer to the rpi memory region.
  10369. *
  10370. * This routine is invoked to post a single rpi header to the
  10371. * HBA consistent with the SLI-4 interface spec. This memory region
  10372. * maps up to 64 rpi context regions.
  10373. *
  10374. * Return codes
  10375. * 0 - sucessful
  10376. * ENOMEM - No available memory
  10377. * EIO - The mailbox failed to complete successfully.
  10378. **/
  10379. int
  10380. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10381. {
  10382. LPFC_MBOXQ_t *mboxq;
  10383. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10384. uint32_t rc = 0;
  10385. uint32_t mbox_tmo;
  10386. uint32_t shdr_status, shdr_add_status;
  10387. union lpfc_sli4_cfg_shdr *shdr;
  10388. /* The port is notified of the header region via a mailbox command. */
  10389. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10390. if (!mboxq) {
  10391. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10392. "2001 Unable to allocate memory for issuing "
  10393. "SLI_CONFIG_SPECIAL mailbox command\n");
  10394. return -ENOMEM;
  10395. }
  10396. /* Post all rpi memory regions to the port. */
  10397. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10398. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10399. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10400. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10401. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10402. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10403. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10404. hdr_tmpl, rpi_page->page_count);
  10405. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10406. rpi_page->start_rpi);
  10407. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10408. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10409. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10410. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10411. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10412. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10413. if (rc != MBX_TIMEOUT)
  10414. mempool_free(mboxq, phba->mbox_mem_pool);
  10415. if (shdr_status || shdr_add_status || rc) {
  10416. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10417. "2514 POST_RPI_HDR mailbox failed with "
  10418. "status x%x add_status x%x, mbx status x%x\n",
  10419. shdr_status, shdr_add_status, rc);
  10420. rc = -ENXIO;
  10421. }
  10422. return rc;
  10423. }
  10424. /**
  10425. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10426. * @phba: pointer to lpfc hba data structure.
  10427. *
  10428. * This routine is invoked to post rpi header templates to the
  10429. * HBA consistent with the SLI-4 interface spec. This routine
  10430. * posts a PAGE_SIZE memory region to the port to hold up to
  10431. * PAGE_SIZE modulo 64 rpi context headers.
  10432. *
  10433. * Returns
  10434. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if sucessful
  10435. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10436. **/
  10437. int
  10438. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10439. {
  10440. int rpi;
  10441. uint16_t max_rpi, rpi_base, rpi_limit;
  10442. uint16_t rpi_remaining;
  10443. struct lpfc_rpi_hdr *rpi_hdr;
  10444. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10445. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10446. rpi_limit = phba->sli4_hba.next_rpi;
  10447. /*
  10448. * The valid rpi range is not guaranteed to be zero-based. Start
  10449. * the search at the rpi_base as reported by the port.
  10450. */
  10451. spin_lock_irq(&phba->hbalock);
  10452. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10453. if (rpi >= rpi_limit || rpi < rpi_base)
  10454. rpi = LPFC_RPI_ALLOC_ERROR;
  10455. else {
  10456. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10457. phba->sli4_hba.max_cfg_param.rpi_used++;
  10458. phba->sli4_hba.rpi_count++;
  10459. }
  10460. /*
  10461. * Don't try to allocate more rpi header regions if the device limit
  10462. * on available rpis max has been exhausted.
  10463. */
  10464. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10465. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10466. spin_unlock_irq(&phba->hbalock);
  10467. return rpi;
  10468. }
  10469. /*
  10470. * If the driver is running low on rpi resources, allocate another
  10471. * page now. Note that the next_rpi value is used because
  10472. * it represents how many are actually in use whereas max_rpi notes
  10473. * how many are supported max by the device.
  10474. */
  10475. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10476. phba->sli4_hba.rpi_count;
  10477. spin_unlock_irq(&phba->hbalock);
  10478. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10479. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10480. if (!rpi_hdr) {
  10481. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10482. "2002 Error Could not grow rpi "
  10483. "count\n");
  10484. } else {
  10485. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10486. }
  10487. }
  10488. return rpi;
  10489. }
  10490. /**
  10491. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10492. * @phba: pointer to lpfc hba data structure.
  10493. *
  10494. * This routine is invoked to release an rpi to the pool of
  10495. * available rpis maintained by the driver.
  10496. **/
  10497. void
  10498. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10499. {
  10500. spin_lock_irq(&phba->hbalock);
  10501. clear_bit(rpi, phba->sli4_hba.rpi_bmask);
  10502. phba->sli4_hba.rpi_count--;
  10503. phba->sli4_hba.max_cfg_param.rpi_used--;
  10504. spin_unlock_irq(&phba->hbalock);
  10505. }
  10506. /**
  10507. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10508. * @phba: pointer to lpfc hba data structure.
  10509. *
  10510. * This routine is invoked to remove the memory region that
  10511. * provided rpi via a bitmask.
  10512. **/
  10513. void
  10514. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10515. {
  10516. kfree(phba->sli4_hba.rpi_bmask);
  10517. }
  10518. /**
  10519. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10520. * @phba: pointer to lpfc hba data structure.
  10521. *
  10522. * This routine is invoked to remove the memory region that
  10523. * provided rpi via a bitmask.
  10524. **/
  10525. int
  10526. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10527. {
  10528. LPFC_MBOXQ_t *mboxq;
  10529. struct lpfc_hba *phba = ndlp->phba;
  10530. int rc;
  10531. /* The port is notified of the header region via a mailbox command. */
  10532. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10533. if (!mboxq)
  10534. return -ENOMEM;
  10535. /* Post all rpi memory regions to the port. */
  10536. lpfc_resume_rpi(mboxq, ndlp);
  10537. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10538. if (rc == MBX_NOT_FINISHED) {
  10539. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10540. "2010 Resume RPI Mailbox failed "
  10541. "status %d, mbxStatus x%x\n", rc,
  10542. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10543. mempool_free(mboxq, phba->mbox_mem_pool);
  10544. return -EIO;
  10545. }
  10546. return 0;
  10547. }
  10548. /**
  10549. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  10550. * @phba: pointer to lpfc hba data structure.
  10551. * @vpi: vpi value to activate with the port.
  10552. *
  10553. * This routine is invoked to activate a vpi with the
  10554. * port when the host intends to use vports with a
  10555. * nonzero vpi.
  10556. *
  10557. * Returns:
  10558. * 0 success
  10559. * -Evalue otherwise
  10560. **/
  10561. int
  10562. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  10563. {
  10564. LPFC_MBOXQ_t *mboxq;
  10565. int rc = 0;
  10566. uint32_t mbox_tmo;
  10567. if (vpi == 0)
  10568. return -EINVAL;
  10569. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10570. if (!mboxq)
  10571. return -ENOMEM;
  10572. lpfc_init_vpi(phba, mboxq, vpi);
  10573. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  10574. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  10575. if (rc != MBX_TIMEOUT)
  10576. mempool_free(mboxq, phba->mbox_mem_pool);
  10577. if (rc != MBX_SUCCESS) {
  10578. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10579. "2022 INIT VPI Mailbox failed "
  10580. "status %d, mbxStatus x%x\n", rc,
  10581. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10582. rc = -EIO;
  10583. }
  10584. return rc;
  10585. }
  10586. /**
  10587. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  10588. * @phba: pointer to lpfc hba data structure.
  10589. * @mboxq: Pointer to mailbox object.
  10590. *
  10591. * This routine is invoked to manually add a single FCF record. The caller
  10592. * must pass a completely initialized FCF_Record. This routine takes
  10593. * care of the nonembedded mailbox operations.
  10594. **/
  10595. static void
  10596. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  10597. {
  10598. void *virt_addr;
  10599. union lpfc_sli4_cfg_shdr *shdr;
  10600. uint32_t shdr_status, shdr_add_status;
  10601. virt_addr = mboxq->sge_array->addr[0];
  10602. /* The IOCTL status is embedded in the mailbox subheader. */
  10603. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  10604. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10605. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10606. if ((shdr_status || shdr_add_status) &&
  10607. (shdr_status != STATUS_FCF_IN_USE))
  10608. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10609. "2558 ADD_FCF_RECORD mailbox failed with "
  10610. "status x%x add_status x%x\n",
  10611. shdr_status, shdr_add_status);
  10612. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10613. }
  10614. /**
  10615. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  10616. * @phba: pointer to lpfc hba data structure.
  10617. * @fcf_record: pointer to the initialized fcf record to add.
  10618. *
  10619. * This routine is invoked to manually add a single FCF record. The caller
  10620. * must pass a completely initialized FCF_Record. This routine takes
  10621. * care of the nonembedded mailbox operations.
  10622. **/
  10623. int
  10624. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  10625. {
  10626. int rc = 0;
  10627. LPFC_MBOXQ_t *mboxq;
  10628. uint8_t *bytep;
  10629. void *virt_addr;
  10630. dma_addr_t phys_addr;
  10631. struct lpfc_mbx_sge sge;
  10632. uint32_t alloc_len, req_len;
  10633. uint32_t fcfindex;
  10634. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10635. if (!mboxq) {
  10636. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10637. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  10638. return -ENOMEM;
  10639. }
  10640. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  10641. sizeof(uint32_t);
  10642. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10643. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10644. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  10645. req_len, LPFC_SLI4_MBX_NEMBED);
  10646. if (alloc_len < req_len) {
  10647. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10648. "2523 Allocated DMA memory size (x%x) is "
  10649. "less than the requested DMA memory "
  10650. "size (x%x)\n", alloc_len, req_len);
  10651. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10652. return -ENOMEM;
  10653. }
  10654. /*
  10655. * Get the first SGE entry from the non-embedded DMA memory. This
  10656. * routine only uses a single SGE.
  10657. */
  10658. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10659. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10660. if (unlikely(!mboxq->sge_array)) {
  10661. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10662. "2526 Failed to get the non-embedded SGE "
  10663. "virtual address\n");
  10664. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10665. return -ENOMEM;
  10666. }
  10667. virt_addr = mboxq->sge_array->addr[0];
  10668. /*
  10669. * Configure the FCF record for FCFI 0. This is the driver's
  10670. * hardcoded default and gets used in nonFIP mode.
  10671. */
  10672. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  10673. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10674. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  10675. /*
  10676. * Copy the fcf_index and the FCF Record Data. The data starts after
  10677. * the FCoE header plus word10. The data copy needs to be endian
  10678. * correct.
  10679. */
  10680. bytep += sizeof(uint32_t);
  10681. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  10682. mboxq->vport = phba->pport;
  10683. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  10684. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10685. if (rc == MBX_NOT_FINISHED) {
  10686. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10687. "2515 ADD_FCF_RECORD mailbox failed with "
  10688. "status 0x%x\n", rc);
  10689. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10690. rc = -EIO;
  10691. } else
  10692. rc = 0;
  10693. return rc;
  10694. }
  10695. /**
  10696. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  10697. * @phba: pointer to lpfc hba data structure.
  10698. * @fcf_record: pointer to the fcf record to write the default data.
  10699. * @fcf_index: FCF table entry index.
  10700. *
  10701. * This routine is invoked to build the driver's default FCF record. The
  10702. * values used are hardcoded. This routine handles memory initialization.
  10703. *
  10704. **/
  10705. void
  10706. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  10707. struct fcf_record *fcf_record,
  10708. uint16_t fcf_index)
  10709. {
  10710. memset(fcf_record, 0, sizeof(struct fcf_record));
  10711. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  10712. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  10713. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  10714. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  10715. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  10716. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  10717. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  10718. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  10719. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  10720. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  10721. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  10722. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  10723. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  10724. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  10725. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  10726. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  10727. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  10728. /* Set the VLAN bit map */
  10729. if (phba->valid_vlan) {
  10730. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  10731. = 1 << (phba->vlan_id % 8);
  10732. }
  10733. }
  10734. /**
  10735. * lpfc_sli4_read_fcf_record - Read the driver's default FCF Record.
  10736. * @phba: pointer to lpfc hba data structure.
  10737. * @fcf_index: FCF table entry offset.
  10738. *
  10739. * This routine is invoked to read up to @fcf_num of FCF record from the
  10740. * device starting with the given @fcf_index.
  10741. **/
  10742. int
  10743. lpfc_sli4_read_fcf_record(struct lpfc_hba *phba, uint16_t fcf_index)
  10744. {
  10745. int rc = 0, error;
  10746. LPFC_MBOXQ_t *mboxq;
  10747. void *virt_addr;
  10748. dma_addr_t phys_addr;
  10749. uint8_t *bytep;
  10750. struct lpfc_mbx_sge sge;
  10751. uint32_t alloc_len, req_len;
  10752. struct lpfc_mbx_read_fcf_tbl *read_fcf;
  10753. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  10754. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10755. if (!mboxq) {
  10756. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10757. "2000 Failed to allocate mbox for "
  10758. "READ_FCF cmd\n");
  10759. error = -ENOMEM;
  10760. goto fail_fcfscan;
  10761. }
  10762. req_len = sizeof(struct fcf_record) +
  10763. sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
  10764. /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
  10765. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10766. LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
  10767. LPFC_SLI4_MBX_NEMBED);
  10768. if (alloc_len < req_len) {
  10769. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10770. "0291 Allocated DMA memory size (x%x) is "
  10771. "less than the requested DMA memory "
  10772. "size (x%x)\n", alloc_len, req_len);
  10773. error = -ENOMEM;
  10774. goto fail_fcfscan;
  10775. }
  10776. /* Get the first SGE entry from the non-embedded DMA memory. This
  10777. * routine only uses a single SGE.
  10778. */
  10779. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10780. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10781. if (unlikely(!mboxq->sge_array)) {
  10782. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10783. "2527 Failed to get the non-embedded SGE "
  10784. "virtual address\n");
  10785. error = -ENOMEM;
  10786. goto fail_fcfscan;
  10787. }
  10788. virt_addr = mboxq->sge_array->addr[0];
  10789. read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
  10790. /* Set up command fields */
  10791. bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
  10792. /* Perform necessary endian conversion */
  10793. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10794. lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
  10795. mboxq->vport = phba->pport;
  10796. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_record;
  10797. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10798. if (rc == MBX_NOT_FINISHED) {
  10799. error = -EIO;
  10800. } else {
  10801. spin_lock_irq(&phba->hbalock);
  10802. phba->hba_flag |= FCF_DISC_INPROGRESS;
  10803. spin_unlock_irq(&phba->hbalock);
  10804. error = 0;
  10805. }
  10806. fail_fcfscan:
  10807. if (error) {
  10808. if (mboxq)
  10809. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10810. /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
  10811. spin_lock_irq(&phba->hbalock);
  10812. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  10813. spin_unlock_irq(&phba->hbalock);
  10814. }
  10815. return error;
  10816. }
  10817. /**
  10818. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  10819. * @phba: pointer to lpfc hba data structure.
  10820. *
  10821. * This function read region 23 and parse TLV for port status to
  10822. * decide if the user disaled the port. If the TLV indicates the
  10823. * port is disabled, the hba_flag is set accordingly.
  10824. **/
  10825. void
  10826. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  10827. {
  10828. LPFC_MBOXQ_t *pmb = NULL;
  10829. MAILBOX_t *mb;
  10830. uint8_t *rgn23_data = NULL;
  10831. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  10832. int rc;
  10833. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10834. if (!pmb) {
  10835. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10836. "2600 lpfc_sli_read_serdes_param failed to"
  10837. " allocate mailbox memory\n");
  10838. goto out;
  10839. }
  10840. mb = &pmb->u.mb;
  10841. /* Get adapter Region 23 data */
  10842. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  10843. if (!rgn23_data)
  10844. goto out;
  10845. do {
  10846. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  10847. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  10848. if (rc != MBX_SUCCESS) {
  10849. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  10850. "2601 lpfc_sli_read_link_ste failed to"
  10851. " read config region 23 rc 0x%x Status 0x%x\n",
  10852. rc, mb->mbxStatus);
  10853. mb->un.varDmp.word_cnt = 0;
  10854. }
  10855. /*
  10856. * dump mem may return a zero when finished or we got a
  10857. * mailbox error, either way we are done.
  10858. */
  10859. if (mb->un.varDmp.word_cnt == 0)
  10860. break;
  10861. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  10862. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  10863. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  10864. rgn23_data + offset,
  10865. mb->un.varDmp.word_cnt);
  10866. offset += mb->un.varDmp.word_cnt;
  10867. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  10868. data_size = offset;
  10869. offset = 0;
  10870. if (!data_size)
  10871. goto out;
  10872. /* Check the region signature first */
  10873. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  10874. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10875. "2619 Config region 23 has bad signature\n");
  10876. goto out;
  10877. }
  10878. offset += 4;
  10879. /* Check the data structure version */
  10880. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  10881. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10882. "2620 Config region 23 has bad version\n");
  10883. goto out;
  10884. }
  10885. offset += 4;
  10886. /* Parse TLV entries in the region */
  10887. while (offset < data_size) {
  10888. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  10889. break;
  10890. /*
  10891. * If the TLV is not driver specific TLV or driver id is
  10892. * not linux driver id, skip the record.
  10893. */
  10894. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  10895. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  10896. (rgn23_data[offset + 3] != 0)) {
  10897. offset += rgn23_data[offset + 1] * 4 + 4;
  10898. continue;
  10899. }
  10900. /* Driver found a driver specific TLV in the config region */
  10901. sub_tlv_len = rgn23_data[offset + 1] * 4;
  10902. offset += 4;
  10903. tlv_offset = 0;
  10904. /*
  10905. * Search for configured port state sub-TLV.
  10906. */
  10907. while ((offset < data_size) &&
  10908. (tlv_offset < sub_tlv_len)) {
  10909. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  10910. offset += 4;
  10911. tlv_offset += 4;
  10912. break;
  10913. }
  10914. if (rgn23_data[offset] != PORT_STE_TYPE) {
  10915. offset += rgn23_data[offset + 1] * 4 + 4;
  10916. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  10917. continue;
  10918. }
  10919. /* This HBA contains PORT_STE configured */
  10920. if (!rgn23_data[offset + 2])
  10921. phba->hba_flag |= LINK_DISABLED;
  10922. goto out;
  10923. }
  10924. }
  10925. out:
  10926. if (pmb)
  10927. mempool_free(pmb, phba->mbox_mem_pool);
  10928. kfree(rgn23_data);
  10929. return;
  10930. }