lpfc_sli.c 386 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_cmnd.h>
  27. #include <scsi/scsi_device.h>
  28. #include <scsi/scsi_host.h>
  29. #include <scsi/scsi_transport_fc.h>
  30. #include <scsi/fc/fc_fs.h>
  31. #include <linux/aer.h>
  32. #include "lpfc_hw4.h"
  33. #include "lpfc_hw.h"
  34. #include "lpfc_sli.h"
  35. #include "lpfc_sli4.h"
  36. #include "lpfc_nl.h"
  37. #include "lpfc_disc.h"
  38. #include "lpfc_scsi.h"
  39. #include "lpfc.h"
  40. #include "lpfc_crtn.h"
  41. #include "lpfc_logmsg.h"
  42. #include "lpfc_compat.h"
  43. #include "lpfc_debugfs.h"
  44. #include "lpfc_vport.h"
  45. /* There are only four IOCB completion types. */
  46. typedef enum _lpfc_iocb_type {
  47. LPFC_UNKNOWN_IOCB,
  48. LPFC_UNSOL_IOCB,
  49. LPFC_SOL_IOCB,
  50. LPFC_ABORT_IOCB
  51. } lpfc_iocb_type;
  52. /* Provide function prototypes local to this module. */
  53. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  54. uint32_t);
  55. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  56. uint8_t *, uint32_t *);
  57. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  58. struct lpfc_iocbq *);
  59. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  60. struct hbq_dmabuf *);
  61. static IOCB_t *
  62. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  63. {
  64. return &iocbq->iocb;
  65. }
  66. /**
  67. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  68. * @q: The Work Queue to operate on.
  69. * @wqe: The work Queue Entry to put on the Work queue.
  70. *
  71. * This routine will copy the contents of @wqe to the next available entry on
  72. * the @q. This function will then ring the Work Queue Doorbell to signal the
  73. * HBA to start processing the Work Queue Entry. This function returns 0 if
  74. * successful. If no entries are available on @q then this function will return
  75. * -ENOMEM.
  76. * The caller is expected to hold the hbalock when calling this routine.
  77. **/
  78. static uint32_t
  79. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  80. {
  81. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  82. struct lpfc_register doorbell;
  83. uint32_t host_index;
  84. /* If the host has not yet processed the next entry then we are done */
  85. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  86. return -ENOMEM;
  87. /* set consumption flag every once in a while */
  88. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  89. bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
  90. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  91. /* Update the host index before invoking device */
  92. host_index = q->host_index;
  93. q->host_index = ((q->host_index + 1) % q->entry_count);
  94. /* Ring Doorbell */
  95. doorbell.word0 = 0;
  96. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  97. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  98. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  99. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  100. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  101. return 0;
  102. }
  103. /**
  104. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  105. * @q: The Work Queue to operate on.
  106. * @index: The index to advance the hba index to.
  107. *
  108. * This routine will update the HBA index of a queue to reflect consumption of
  109. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  110. * an entry the host calls this function to update the queue's internal
  111. * pointers. This routine returns the number of entries that were consumed by
  112. * the HBA.
  113. **/
  114. static uint32_t
  115. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  116. {
  117. uint32_t released = 0;
  118. if (q->hba_index == index)
  119. return 0;
  120. do {
  121. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  122. released++;
  123. } while (q->hba_index != index);
  124. return released;
  125. }
  126. /**
  127. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  128. * @q: The Mailbox Queue to operate on.
  129. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  130. *
  131. * This routine will copy the contents of @mqe to the next available entry on
  132. * the @q. This function will then ring the Work Queue Doorbell to signal the
  133. * HBA to start processing the Work Queue Entry. This function returns 0 if
  134. * successful. If no entries are available on @q then this function will return
  135. * -ENOMEM.
  136. * The caller is expected to hold the hbalock when calling this routine.
  137. **/
  138. static uint32_t
  139. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  140. {
  141. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  142. struct lpfc_register doorbell;
  143. uint32_t host_index;
  144. /* If the host has not yet processed the next entry then we are done */
  145. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  146. return -ENOMEM;
  147. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  148. /* Save off the mailbox pointer for completion */
  149. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  150. /* Update the host index before invoking device */
  151. host_index = q->host_index;
  152. q->host_index = ((q->host_index + 1) % q->entry_count);
  153. /* Ring Doorbell */
  154. doorbell.word0 = 0;
  155. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  156. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  157. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  158. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  159. return 0;
  160. }
  161. /**
  162. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  163. * @q: The Mailbox Queue to operate on.
  164. *
  165. * This routine will update the HBA index of a queue to reflect consumption of
  166. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  167. * an entry the host calls this function to update the queue's internal
  168. * pointers. This routine returns the number of entries that were consumed by
  169. * the HBA.
  170. **/
  171. static uint32_t
  172. lpfc_sli4_mq_release(struct lpfc_queue *q)
  173. {
  174. /* Clear the mailbox pointer for completion */
  175. q->phba->mbox = NULL;
  176. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  177. return 1;
  178. }
  179. /**
  180. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  181. * @q: The Event Queue to get the first valid EQE from
  182. *
  183. * This routine will get the first valid Event Queue Entry from @q, update
  184. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  185. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  186. * processed, but not popped back to the HBA then this routine will return NULL.
  187. **/
  188. static struct lpfc_eqe *
  189. lpfc_sli4_eq_get(struct lpfc_queue *q)
  190. {
  191. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  192. /* If the next EQE is not valid then we are done */
  193. if (!bf_get(lpfc_eqe_valid, eqe))
  194. return NULL;
  195. /* If the host has not yet processed the next entry then we are done */
  196. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  197. return NULL;
  198. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  199. return eqe;
  200. }
  201. /**
  202. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  203. * @q: The Event Queue that the host has completed processing for.
  204. * @arm: Indicates whether the host wants to arms this CQ.
  205. *
  206. * This routine will mark all Event Queue Entries on @q, from the last
  207. * known completed entry to the last entry that was processed, as completed
  208. * by clearing the valid bit for each completion queue entry. Then it will
  209. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  210. * The internal host index in the @q will be updated by this routine to indicate
  211. * that the host has finished processing the entries. The @arm parameter
  212. * indicates that the queue should be rearmed when ringing the doorbell.
  213. *
  214. * This function will return the number of EQEs that were popped.
  215. **/
  216. uint32_t
  217. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  218. {
  219. uint32_t released = 0;
  220. struct lpfc_eqe *temp_eqe;
  221. struct lpfc_register doorbell;
  222. /* while there are valid entries */
  223. while (q->hba_index != q->host_index) {
  224. temp_eqe = q->qe[q->host_index].eqe;
  225. bf_set(lpfc_eqe_valid, temp_eqe, 0);
  226. released++;
  227. q->host_index = ((q->host_index + 1) % q->entry_count);
  228. }
  229. if (unlikely(released == 0 && !arm))
  230. return 0;
  231. /* ring doorbell for number popped */
  232. doorbell.word0 = 0;
  233. if (arm) {
  234. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  235. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  236. }
  237. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  238. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  239. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  240. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  241. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  242. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  243. readl(q->phba->sli4_hba.EQCQDBregaddr);
  244. return released;
  245. }
  246. /**
  247. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  248. * @q: The Completion Queue to get the first valid CQE from
  249. *
  250. * This routine will get the first valid Completion Queue Entry from @q, update
  251. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  252. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  253. * processed, but not popped back to the HBA then this routine will return NULL.
  254. **/
  255. static struct lpfc_cqe *
  256. lpfc_sli4_cq_get(struct lpfc_queue *q)
  257. {
  258. struct lpfc_cqe *cqe;
  259. /* If the next CQE is not valid then we are done */
  260. if (!bf_get(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  261. return NULL;
  262. /* If the host has not yet processed the next entry then we are done */
  263. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  264. return NULL;
  265. cqe = q->qe[q->hba_index].cqe;
  266. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  267. return cqe;
  268. }
  269. /**
  270. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  271. * @q: The Completion Queue that the host has completed processing for.
  272. * @arm: Indicates whether the host wants to arms this CQ.
  273. *
  274. * This routine will mark all Completion queue entries on @q, from the last
  275. * known completed entry to the last entry that was processed, as completed
  276. * by clearing the valid bit for each completion queue entry. Then it will
  277. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  278. * The internal host index in the @q will be updated by this routine to indicate
  279. * that the host has finished processing the entries. The @arm parameter
  280. * indicates that the queue should be rearmed when ringing the doorbell.
  281. *
  282. * This function will return the number of CQEs that were released.
  283. **/
  284. uint32_t
  285. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  286. {
  287. uint32_t released = 0;
  288. struct lpfc_cqe *temp_qe;
  289. struct lpfc_register doorbell;
  290. /* while there are valid entries */
  291. while (q->hba_index != q->host_index) {
  292. temp_qe = q->qe[q->host_index].cqe;
  293. bf_set(lpfc_cqe_valid, temp_qe, 0);
  294. released++;
  295. q->host_index = ((q->host_index + 1) % q->entry_count);
  296. }
  297. if (unlikely(released == 0 && !arm))
  298. return 0;
  299. /* ring doorbell for number popped */
  300. doorbell.word0 = 0;
  301. if (arm)
  302. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  303. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  304. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  305. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  306. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  307. return released;
  308. }
  309. /**
  310. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  311. * @q: The Header Receive Queue to operate on.
  312. * @wqe: The Receive Queue Entry to put on the Receive queue.
  313. *
  314. * This routine will copy the contents of @wqe to the next available entry on
  315. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  316. * HBA to start processing the Receive Queue Entry. This function returns the
  317. * index that the rqe was copied to if successful. If no entries are available
  318. * on @q then this function will return -ENOMEM.
  319. * The caller is expected to hold the hbalock when calling this routine.
  320. **/
  321. static int
  322. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  323. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  324. {
  325. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  326. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  327. struct lpfc_register doorbell;
  328. int put_index = hq->host_index;
  329. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  330. return -EINVAL;
  331. if (hq->host_index != dq->host_index)
  332. return -EINVAL;
  333. /* If the host has not yet processed the next entry then we are done */
  334. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  335. return -EBUSY;
  336. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  337. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  338. /* Update the host index to point to the next slot */
  339. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  340. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  341. /* Ring The Header Receive Queue Doorbell */
  342. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  343. doorbell.word0 = 0;
  344. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  345. LPFC_RQ_POST_BATCH);
  346. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  347. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  348. }
  349. return put_index;
  350. }
  351. /**
  352. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  353. * @q: The Header Receive Queue to operate on.
  354. *
  355. * This routine will update the HBA index of a queue to reflect consumption of
  356. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  357. * consumed an entry the host calls this function to update the queue's
  358. * internal pointers. This routine returns the number of entries that were
  359. * consumed by the HBA.
  360. **/
  361. static uint32_t
  362. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  363. {
  364. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  365. return 0;
  366. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  367. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  368. return 1;
  369. }
  370. /**
  371. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  372. * @phba: Pointer to HBA context object.
  373. * @pring: Pointer to driver SLI ring object.
  374. *
  375. * This function returns pointer to next command iocb entry
  376. * in the command ring. The caller must hold hbalock to prevent
  377. * other threads consume the next command iocb.
  378. * SLI-2/SLI-3 provide different sized iocbs.
  379. **/
  380. static inline IOCB_t *
  381. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  382. {
  383. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  384. pring->cmdidx * phba->iocb_cmd_size);
  385. }
  386. /**
  387. * lpfc_resp_iocb - Get next response iocb entry in the ring
  388. * @phba: Pointer to HBA context object.
  389. * @pring: Pointer to driver SLI ring object.
  390. *
  391. * This function returns pointer to next response iocb entry
  392. * in the response ring. The caller must hold hbalock to make sure
  393. * that no other thread consume the next response iocb.
  394. * SLI-2/SLI-3 provide different sized iocbs.
  395. **/
  396. static inline IOCB_t *
  397. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  398. {
  399. return (IOCB_t *) (((char *) pring->rspringaddr) +
  400. pring->rspidx * phba->iocb_rsp_size);
  401. }
  402. /**
  403. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  404. * @phba: Pointer to HBA context object.
  405. *
  406. * This function is called with hbalock held. This function
  407. * allocates a new driver iocb object from the iocb pool. If the
  408. * allocation is successful, it returns pointer to the newly
  409. * allocated iocb object else it returns NULL.
  410. **/
  411. static struct lpfc_iocbq *
  412. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  413. {
  414. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  415. struct lpfc_iocbq * iocbq = NULL;
  416. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  417. return iocbq;
  418. }
  419. /**
  420. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  421. * @phba: Pointer to HBA context object.
  422. * @xritag: XRI value.
  423. *
  424. * This function clears the sglq pointer from the array of acive
  425. * sglq's. The xritag that is passed in is used to index into the
  426. * array. Before the xritag can be used it needs to be adjusted
  427. * by subtracting the xribase.
  428. *
  429. * Returns sglq ponter = success, NULL = Failure.
  430. **/
  431. static struct lpfc_sglq *
  432. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  433. {
  434. uint16_t adj_xri;
  435. struct lpfc_sglq *sglq;
  436. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  437. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  438. return NULL;
  439. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  440. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  441. return sglq;
  442. }
  443. /**
  444. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  445. * @phba: Pointer to HBA context object.
  446. * @xritag: XRI value.
  447. *
  448. * This function returns the sglq pointer from the array of acive
  449. * sglq's. The xritag that is passed in is used to index into the
  450. * array. Before the xritag can be used it needs to be adjusted
  451. * by subtracting the xribase.
  452. *
  453. * Returns sglq ponter = success, NULL = Failure.
  454. **/
  455. struct lpfc_sglq *
  456. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  457. {
  458. uint16_t adj_xri;
  459. struct lpfc_sglq *sglq;
  460. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  461. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  462. return NULL;
  463. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  464. return sglq;
  465. }
  466. /**
  467. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  468. * @phba: Pointer to HBA context object.
  469. *
  470. * This function is called with hbalock held. This function
  471. * Gets a new driver sglq object from the sglq list. If the
  472. * list is not empty then it is successful, it returns pointer to the newly
  473. * allocated sglq object else it returns NULL.
  474. **/
  475. static struct lpfc_sglq *
  476. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  477. {
  478. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  479. struct lpfc_sglq *sglq = NULL;
  480. uint16_t adj_xri;
  481. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  482. if (!sglq)
  483. return NULL;
  484. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  485. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  486. sglq->state = SGL_ALLOCATED;
  487. return sglq;
  488. }
  489. /**
  490. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  491. * @phba: Pointer to HBA context object.
  492. *
  493. * This function is called with no lock held. This function
  494. * allocates a new driver iocb object from the iocb pool. If the
  495. * allocation is successful, it returns pointer to the newly
  496. * allocated iocb object else it returns NULL.
  497. **/
  498. struct lpfc_iocbq *
  499. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  500. {
  501. struct lpfc_iocbq * iocbq = NULL;
  502. unsigned long iflags;
  503. spin_lock_irqsave(&phba->hbalock, iflags);
  504. iocbq = __lpfc_sli_get_iocbq(phba);
  505. spin_unlock_irqrestore(&phba->hbalock, iflags);
  506. return iocbq;
  507. }
  508. /**
  509. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  510. * @phba: Pointer to HBA context object.
  511. * @iocbq: Pointer to driver iocb object.
  512. *
  513. * This function is called with hbalock held to release driver
  514. * iocb object to the iocb pool. The iotag in the iocb object
  515. * does not change for each use of the iocb object. This function
  516. * clears all other fields of the iocb object when it is freed.
  517. * The sqlq structure that holds the xritag and phys and virtual
  518. * mappings for the scatter gather list is retrieved from the
  519. * active array of sglq. The get of the sglq pointer also clears
  520. * the entry in the array. If the status of the IO indiactes that
  521. * this IO was aborted then the sglq entry it put on the
  522. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  523. * IO has good status or fails for any other reason then the sglq
  524. * entry is added to the free list (lpfc_sgl_list).
  525. **/
  526. static void
  527. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  528. {
  529. struct lpfc_sglq *sglq;
  530. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  531. unsigned long iflag;
  532. if (iocbq->sli4_xritag == NO_XRI)
  533. sglq = NULL;
  534. else
  535. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  536. if (sglq) {
  537. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  538. (sglq->state != SGL_XRI_ABORTED)) {
  539. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  540. iflag);
  541. list_add(&sglq->list,
  542. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  543. spin_unlock_irqrestore(
  544. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  545. } else {
  546. sglq->state = SGL_FREED;
  547. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  548. }
  549. }
  550. /*
  551. * Clean all volatile data fields, preserve iotag and node struct.
  552. */
  553. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  554. iocbq->sli4_xritag = NO_XRI;
  555. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  556. }
  557. /**
  558. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  559. * @phba: Pointer to HBA context object.
  560. * @iocbq: Pointer to driver iocb object.
  561. *
  562. * This function is called with hbalock held to release driver
  563. * iocb object to the iocb pool. The iotag in the iocb object
  564. * does not change for each use of the iocb object. This function
  565. * clears all other fields of the iocb object when it is freed.
  566. **/
  567. static void
  568. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  569. {
  570. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  571. /*
  572. * Clean all volatile data fields, preserve iotag and node struct.
  573. */
  574. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  575. iocbq->sli4_xritag = NO_XRI;
  576. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  577. }
  578. /**
  579. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  580. * @phba: Pointer to HBA context object.
  581. * @iocbq: Pointer to driver iocb object.
  582. *
  583. * This function is called with hbalock held to release driver
  584. * iocb object to the iocb pool. The iotag in the iocb object
  585. * does not change for each use of the iocb object. This function
  586. * clears all other fields of the iocb object when it is freed.
  587. **/
  588. static void
  589. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  590. {
  591. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  592. }
  593. /**
  594. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  595. * @phba: Pointer to HBA context object.
  596. * @iocbq: Pointer to driver iocb object.
  597. *
  598. * This function is called with no lock held to release the iocb to
  599. * iocb pool.
  600. **/
  601. void
  602. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  603. {
  604. unsigned long iflags;
  605. /*
  606. * Clean all volatile data fields, preserve iotag and node struct.
  607. */
  608. spin_lock_irqsave(&phba->hbalock, iflags);
  609. __lpfc_sli_release_iocbq(phba, iocbq);
  610. spin_unlock_irqrestore(&phba->hbalock, iflags);
  611. }
  612. /**
  613. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  614. * @phba: Pointer to HBA context object.
  615. * @iocblist: List of IOCBs.
  616. * @ulpstatus: ULP status in IOCB command field.
  617. * @ulpWord4: ULP word-4 in IOCB command field.
  618. *
  619. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  620. * on the list by invoking the complete callback function associated with the
  621. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  622. * fields.
  623. **/
  624. void
  625. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  626. uint32_t ulpstatus, uint32_t ulpWord4)
  627. {
  628. struct lpfc_iocbq *piocb;
  629. while (!list_empty(iocblist)) {
  630. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  631. if (!piocb->iocb_cmpl)
  632. lpfc_sli_release_iocbq(phba, piocb);
  633. else {
  634. piocb->iocb.ulpStatus = ulpstatus;
  635. piocb->iocb.un.ulpWord[4] = ulpWord4;
  636. (piocb->iocb_cmpl) (phba, piocb, piocb);
  637. }
  638. }
  639. return;
  640. }
  641. /**
  642. * lpfc_sli_iocb_cmd_type - Get the iocb type
  643. * @iocb_cmnd: iocb command code.
  644. *
  645. * This function is called by ring event handler function to get the iocb type.
  646. * This function translates the iocb command to an iocb command type used to
  647. * decide the final disposition of each completed IOCB.
  648. * The function returns
  649. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  650. * LPFC_SOL_IOCB if it is a solicited iocb completion
  651. * LPFC_ABORT_IOCB if it is an abort iocb
  652. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  653. *
  654. * The caller is not required to hold any lock.
  655. **/
  656. static lpfc_iocb_type
  657. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  658. {
  659. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  660. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  661. return 0;
  662. switch (iocb_cmnd) {
  663. case CMD_XMIT_SEQUENCE_CR:
  664. case CMD_XMIT_SEQUENCE_CX:
  665. case CMD_XMIT_BCAST_CN:
  666. case CMD_XMIT_BCAST_CX:
  667. case CMD_ELS_REQUEST_CR:
  668. case CMD_ELS_REQUEST_CX:
  669. case CMD_CREATE_XRI_CR:
  670. case CMD_CREATE_XRI_CX:
  671. case CMD_GET_RPI_CN:
  672. case CMD_XMIT_ELS_RSP_CX:
  673. case CMD_GET_RPI_CR:
  674. case CMD_FCP_IWRITE_CR:
  675. case CMD_FCP_IWRITE_CX:
  676. case CMD_FCP_IREAD_CR:
  677. case CMD_FCP_IREAD_CX:
  678. case CMD_FCP_ICMND_CR:
  679. case CMD_FCP_ICMND_CX:
  680. case CMD_FCP_TSEND_CX:
  681. case CMD_FCP_TRSP_CX:
  682. case CMD_FCP_TRECEIVE_CX:
  683. case CMD_FCP_AUTO_TRSP_CX:
  684. case CMD_ADAPTER_MSG:
  685. case CMD_ADAPTER_DUMP:
  686. case CMD_XMIT_SEQUENCE64_CR:
  687. case CMD_XMIT_SEQUENCE64_CX:
  688. case CMD_XMIT_BCAST64_CN:
  689. case CMD_XMIT_BCAST64_CX:
  690. case CMD_ELS_REQUEST64_CR:
  691. case CMD_ELS_REQUEST64_CX:
  692. case CMD_FCP_IWRITE64_CR:
  693. case CMD_FCP_IWRITE64_CX:
  694. case CMD_FCP_IREAD64_CR:
  695. case CMD_FCP_IREAD64_CX:
  696. case CMD_FCP_ICMND64_CR:
  697. case CMD_FCP_ICMND64_CX:
  698. case CMD_FCP_TSEND64_CX:
  699. case CMD_FCP_TRSP64_CX:
  700. case CMD_FCP_TRECEIVE64_CX:
  701. case CMD_GEN_REQUEST64_CR:
  702. case CMD_GEN_REQUEST64_CX:
  703. case CMD_XMIT_ELS_RSP64_CX:
  704. case DSSCMD_IWRITE64_CR:
  705. case DSSCMD_IWRITE64_CX:
  706. case DSSCMD_IREAD64_CR:
  707. case DSSCMD_IREAD64_CX:
  708. type = LPFC_SOL_IOCB;
  709. break;
  710. case CMD_ABORT_XRI_CN:
  711. case CMD_ABORT_XRI_CX:
  712. case CMD_CLOSE_XRI_CN:
  713. case CMD_CLOSE_XRI_CX:
  714. case CMD_XRI_ABORTED_CX:
  715. case CMD_ABORT_MXRI64_CN:
  716. case CMD_XMIT_BLS_RSP64_CX:
  717. type = LPFC_ABORT_IOCB;
  718. break;
  719. case CMD_RCV_SEQUENCE_CX:
  720. case CMD_RCV_ELS_REQ_CX:
  721. case CMD_RCV_SEQUENCE64_CX:
  722. case CMD_RCV_ELS_REQ64_CX:
  723. case CMD_ASYNC_STATUS:
  724. case CMD_IOCB_RCV_SEQ64_CX:
  725. case CMD_IOCB_RCV_ELS64_CX:
  726. case CMD_IOCB_RCV_CONT64_CX:
  727. case CMD_IOCB_RET_XRI64_CX:
  728. type = LPFC_UNSOL_IOCB;
  729. break;
  730. case CMD_IOCB_XMIT_MSEQ64_CR:
  731. case CMD_IOCB_XMIT_MSEQ64_CX:
  732. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  733. case CMD_IOCB_RCV_ELS_LIST64_CX:
  734. case CMD_IOCB_CLOSE_EXTENDED_CN:
  735. case CMD_IOCB_ABORT_EXTENDED_CN:
  736. case CMD_IOCB_RET_HBQE64_CN:
  737. case CMD_IOCB_FCP_IBIDIR64_CR:
  738. case CMD_IOCB_FCP_IBIDIR64_CX:
  739. case CMD_IOCB_FCP_ITASKMGT64_CX:
  740. case CMD_IOCB_LOGENTRY_CN:
  741. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  742. printk("%s - Unhandled SLI-3 Command x%x\n",
  743. __func__, iocb_cmnd);
  744. type = LPFC_UNKNOWN_IOCB;
  745. break;
  746. default:
  747. type = LPFC_UNKNOWN_IOCB;
  748. break;
  749. }
  750. return type;
  751. }
  752. /**
  753. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  754. * @phba: Pointer to HBA context object.
  755. *
  756. * This function is called from SLI initialization code
  757. * to configure every ring of the HBA's SLI interface. The
  758. * caller is not required to hold any lock. This function issues
  759. * a config_ring mailbox command for each ring.
  760. * This function returns zero if successful else returns a negative
  761. * error code.
  762. **/
  763. static int
  764. lpfc_sli_ring_map(struct lpfc_hba *phba)
  765. {
  766. struct lpfc_sli *psli = &phba->sli;
  767. LPFC_MBOXQ_t *pmb;
  768. MAILBOX_t *pmbox;
  769. int i, rc, ret = 0;
  770. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  771. if (!pmb)
  772. return -ENOMEM;
  773. pmbox = &pmb->u.mb;
  774. phba->link_state = LPFC_INIT_MBX_CMDS;
  775. for (i = 0; i < psli->num_rings; i++) {
  776. lpfc_config_ring(phba, i, pmb);
  777. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  778. if (rc != MBX_SUCCESS) {
  779. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  780. "0446 Adapter failed to init (%d), "
  781. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  782. "ring %d\n",
  783. rc, pmbox->mbxCommand,
  784. pmbox->mbxStatus, i);
  785. phba->link_state = LPFC_HBA_ERROR;
  786. ret = -ENXIO;
  787. break;
  788. }
  789. }
  790. mempool_free(pmb, phba->mbox_mem_pool);
  791. return ret;
  792. }
  793. /**
  794. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  795. * @phba: Pointer to HBA context object.
  796. * @pring: Pointer to driver SLI ring object.
  797. * @piocb: Pointer to the driver iocb object.
  798. *
  799. * This function is called with hbalock held. The function adds the
  800. * new iocb to txcmplq of the given ring. This function always returns
  801. * 0. If this function is called for ELS ring, this function checks if
  802. * there is a vport associated with the ELS command. This function also
  803. * starts els_tmofunc timer if this is an ELS command.
  804. **/
  805. static int
  806. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  807. struct lpfc_iocbq *piocb)
  808. {
  809. list_add_tail(&piocb->list, &pring->txcmplq);
  810. pring->txcmplq_cnt++;
  811. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  812. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  813. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  814. if (!piocb->vport)
  815. BUG();
  816. else
  817. mod_timer(&piocb->vport->els_tmofunc,
  818. jiffies + HZ * (phba->fc_ratov << 1));
  819. }
  820. return 0;
  821. }
  822. /**
  823. * lpfc_sli_ringtx_get - Get first element of the txq
  824. * @phba: Pointer to HBA context object.
  825. * @pring: Pointer to driver SLI ring object.
  826. *
  827. * This function is called with hbalock held to get next
  828. * iocb in txq of the given ring. If there is any iocb in
  829. * the txq, the function returns first iocb in the list after
  830. * removing the iocb from the list, else it returns NULL.
  831. **/
  832. static struct lpfc_iocbq *
  833. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  834. {
  835. struct lpfc_iocbq *cmd_iocb;
  836. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  837. if (cmd_iocb != NULL)
  838. pring->txq_cnt--;
  839. return cmd_iocb;
  840. }
  841. /**
  842. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  843. * @phba: Pointer to HBA context object.
  844. * @pring: Pointer to driver SLI ring object.
  845. *
  846. * This function is called with hbalock held and the caller must post the
  847. * iocb without releasing the lock. If the caller releases the lock,
  848. * iocb slot returned by the function is not guaranteed to be available.
  849. * The function returns pointer to the next available iocb slot if there
  850. * is available slot in the ring, else it returns NULL.
  851. * If the get index of the ring is ahead of the put index, the function
  852. * will post an error attention event to the worker thread to take the
  853. * HBA to offline state.
  854. **/
  855. static IOCB_t *
  856. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  857. {
  858. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  859. uint32_t max_cmd_idx = pring->numCiocb;
  860. if ((pring->next_cmdidx == pring->cmdidx) &&
  861. (++pring->next_cmdidx >= max_cmd_idx))
  862. pring->next_cmdidx = 0;
  863. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  864. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  865. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  866. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  867. "0315 Ring %d issue: portCmdGet %d "
  868. "is bigger than cmd ring %d\n",
  869. pring->ringno,
  870. pring->local_getidx, max_cmd_idx);
  871. phba->link_state = LPFC_HBA_ERROR;
  872. /*
  873. * All error attention handlers are posted to
  874. * worker thread
  875. */
  876. phba->work_ha |= HA_ERATT;
  877. phba->work_hs = HS_FFER3;
  878. lpfc_worker_wake_up(phba);
  879. return NULL;
  880. }
  881. if (pring->local_getidx == pring->next_cmdidx)
  882. return NULL;
  883. }
  884. return lpfc_cmd_iocb(phba, pring);
  885. }
  886. /**
  887. * lpfc_sli_next_iotag - Get an iotag for the iocb
  888. * @phba: Pointer to HBA context object.
  889. * @iocbq: Pointer to driver iocb object.
  890. *
  891. * This function gets an iotag for the iocb. If there is no unused iotag and
  892. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  893. * array and assigns a new iotag.
  894. * The function returns the allocated iotag if successful, else returns zero.
  895. * Zero is not a valid iotag.
  896. * The caller is not required to hold any lock.
  897. **/
  898. uint16_t
  899. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  900. {
  901. struct lpfc_iocbq **new_arr;
  902. struct lpfc_iocbq **old_arr;
  903. size_t new_len;
  904. struct lpfc_sli *psli = &phba->sli;
  905. uint16_t iotag;
  906. spin_lock_irq(&phba->hbalock);
  907. iotag = psli->last_iotag;
  908. if(++iotag < psli->iocbq_lookup_len) {
  909. psli->last_iotag = iotag;
  910. psli->iocbq_lookup[iotag] = iocbq;
  911. spin_unlock_irq(&phba->hbalock);
  912. iocbq->iotag = iotag;
  913. return iotag;
  914. } else if (psli->iocbq_lookup_len < (0xffff
  915. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  916. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  917. spin_unlock_irq(&phba->hbalock);
  918. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  919. GFP_KERNEL);
  920. if (new_arr) {
  921. spin_lock_irq(&phba->hbalock);
  922. old_arr = psli->iocbq_lookup;
  923. if (new_len <= psli->iocbq_lookup_len) {
  924. /* highly unprobable case */
  925. kfree(new_arr);
  926. iotag = psli->last_iotag;
  927. if(++iotag < psli->iocbq_lookup_len) {
  928. psli->last_iotag = iotag;
  929. psli->iocbq_lookup[iotag] = iocbq;
  930. spin_unlock_irq(&phba->hbalock);
  931. iocbq->iotag = iotag;
  932. return iotag;
  933. }
  934. spin_unlock_irq(&phba->hbalock);
  935. return 0;
  936. }
  937. if (psli->iocbq_lookup)
  938. memcpy(new_arr, old_arr,
  939. ((psli->last_iotag + 1) *
  940. sizeof (struct lpfc_iocbq *)));
  941. psli->iocbq_lookup = new_arr;
  942. psli->iocbq_lookup_len = new_len;
  943. psli->last_iotag = iotag;
  944. psli->iocbq_lookup[iotag] = iocbq;
  945. spin_unlock_irq(&phba->hbalock);
  946. iocbq->iotag = iotag;
  947. kfree(old_arr);
  948. return iotag;
  949. }
  950. } else
  951. spin_unlock_irq(&phba->hbalock);
  952. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  953. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  954. psli->last_iotag);
  955. return 0;
  956. }
  957. /**
  958. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  959. * @phba: Pointer to HBA context object.
  960. * @pring: Pointer to driver SLI ring object.
  961. * @iocb: Pointer to iocb slot in the ring.
  962. * @nextiocb: Pointer to driver iocb object which need to be
  963. * posted to firmware.
  964. *
  965. * This function is called with hbalock held to post a new iocb to
  966. * the firmware. This function copies the new iocb to ring iocb slot and
  967. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  968. * a completion call back for this iocb else the function will free the
  969. * iocb object.
  970. **/
  971. static void
  972. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  973. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  974. {
  975. /*
  976. * Set up an iotag
  977. */
  978. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  979. if (pring->ringno == LPFC_ELS_RING) {
  980. lpfc_debugfs_slow_ring_trc(phba,
  981. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  982. *(((uint32_t *) &nextiocb->iocb) + 4),
  983. *(((uint32_t *) &nextiocb->iocb) + 6),
  984. *(((uint32_t *) &nextiocb->iocb) + 7));
  985. }
  986. /*
  987. * Issue iocb command to adapter
  988. */
  989. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  990. wmb();
  991. pring->stats.iocb_cmd++;
  992. /*
  993. * If there is no completion routine to call, we can release the
  994. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  995. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  996. */
  997. if (nextiocb->iocb_cmpl)
  998. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  999. else
  1000. __lpfc_sli_release_iocbq(phba, nextiocb);
  1001. /*
  1002. * Let the HBA know what IOCB slot will be the next one the
  1003. * driver will put a command into.
  1004. */
  1005. pring->cmdidx = pring->next_cmdidx;
  1006. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1007. }
  1008. /**
  1009. * lpfc_sli_update_full_ring - Update the chip attention register
  1010. * @phba: Pointer to HBA context object.
  1011. * @pring: Pointer to driver SLI ring object.
  1012. *
  1013. * The caller is not required to hold any lock for calling this function.
  1014. * This function updates the chip attention bits for the ring to inform firmware
  1015. * that there are pending work to be done for this ring and requests an
  1016. * interrupt when there is space available in the ring. This function is
  1017. * called when the driver is unable to post more iocbs to the ring due
  1018. * to unavailability of space in the ring.
  1019. **/
  1020. static void
  1021. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1022. {
  1023. int ringno = pring->ringno;
  1024. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1025. wmb();
  1026. /*
  1027. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1028. * The HBA will tell us when an IOCB entry is available.
  1029. */
  1030. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1031. readl(phba->CAregaddr); /* flush */
  1032. pring->stats.iocb_cmd_full++;
  1033. }
  1034. /**
  1035. * lpfc_sli_update_ring - Update chip attention register
  1036. * @phba: Pointer to HBA context object.
  1037. * @pring: Pointer to driver SLI ring object.
  1038. *
  1039. * This function updates the chip attention register bit for the
  1040. * given ring to inform HBA that there is more work to be done
  1041. * in this ring. The caller is not required to hold any lock.
  1042. **/
  1043. static void
  1044. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1045. {
  1046. int ringno = pring->ringno;
  1047. /*
  1048. * Tell the HBA that there is work to do in this ring.
  1049. */
  1050. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1051. wmb();
  1052. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1053. readl(phba->CAregaddr); /* flush */
  1054. }
  1055. }
  1056. /**
  1057. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1058. * @phba: Pointer to HBA context object.
  1059. * @pring: Pointer to driver SLI ring object.
  1060. *
  1061. * This function is called with hbalock held to post pending iocbs
  1062. * in the txq to the firmware. This function is called when driver
  1063. * detects space available in the ring.
  1064. **/
  1065. static void
  1066. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1067. {
  1068. IOCB_t *iocb;
  1069. struct lpfc_iocbq *nextiocb;
  1070. /*
  1071. * Check to see if:
  1072. * (a) there is anything on the txq to send
  1073. * (b) link is up
  1074. * (c) link attention events can be processed (fcp ring only)
  1075. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1076. */
  1077. if (pring->txq_cnt &&
  1078. lpfc_is_link_up(phba) &&
  1079. (pring->ringno != phba->sli.fcp_ring ||
  1080. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1081. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1082. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1083. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1084. if (iocb)
  1085. lpfc_sli_update_ring(phba, pring);
  1086. else
  1087. lpfc_sli_update_full_ring(phba, pring);
  1088. }
  1089. return;
  1090. }
  1091. /**
  1092. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1093. * @phba: Pointer to HBA context object.
  1094. * @hbqno: HBQ number.
  1095. *
  1096. * This function is called with hbalock held to get the next
  1097. * available slot for the given HBQ. If there is free slot
  1098. * available for the HBQ it will return pointer to the next available
  1099. * HBQ entry else it will return NULL.
  1100. **/
  1101. static struct lpfc_hbq_entry *
  1102. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1103. {
  1104. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1105. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1106. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1107. hbqp->next_hbqPutIdx = 0;
  1108. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1109. uint32_t raw_index = phba->hbq_get[hbqno];
  1110. uint32_t getidx = le32_to_cpu(raw_index);
  1111. hbqp->local_hbqGetIdx = getidx;
  1112. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1113. lpfc_printf_log(phba, KERN_ERR,
  1114. LOG_SLI | LOG_VPORT,
  1115. "1802 HBQ %d: local_hbqGetIdx "
  1116. "%u is > than hbqp->entry_count %u\n",
  1117. hbqno, hbqp->local_hbqGetIdx,
  1118. hbqp->entry_count);
  1119. phba->link_state = LPFC_HBA_ERROR;
  1120. return NULL;
  1121. }
  1122. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1123. return NULL;
  1124. }
  1125. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1126. hbqp->hbqPutIdx;
  1127. }
  1128. /**
  1129. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1130. * @phba: Pointer to HBA context object.
  1131. *
  1132. * This function is called with no lock held to free all the
  1133. * hbq buffers while uninitializing the SLI interface. It also
  1134. * frees the HBQ buffers returned by the firmware but not yet
  1135. * processed by the upper layers.
  1136. **/
  1137. void
  1138. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1139. {
  1140. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1141. struct hbq_dmabuf *hbq_buf;
  1142. unsigned long flags;
  1143. int i, hbq_count;
  1144. uint32_t hbqno;
  1145. hbq_count = lpfc_sli_hbq_count();
  1146. /* Return all memory used by all HBQs */
  1147. spin_lock_irqsave(&phba->hbalock, flags);
  1148. for (i = 0; i < hbq_count; ++i) {
  1149. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1150. &phba->hbqs[i].hbq_buffer_list, list) {
  1151. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1152. list_del(&hbq_buf->dbuf.list);
  1153. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1154. }
  1155. phba->hbqs[i].buffer_count = 0;
  1156. }
  1157. /* Return all HBQ buffer that are in-fly */
  1158. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1159. list) {
  1160. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1161. list_del(&hbq_buf->dbuf.list);
  1162. if (hbq_buf->tag == -1) {
  1163. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1164. (phba, hbq_buf);
  1165. } else {
  1166. hbqno = hbq_buf->tag >> 16;
  1167. if (hbqno >= LPFC_MAX_HBQS)
  1168. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1169. (phba, hbq_buf);
  1170. else
  1171. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1172. hbq_buf);
  1173. }
  1174. }
  1175. /* Mark the HBQs not in use */
  1176. phba->hbq_in_use = 0;
  1177. spin_unlock_irqrestore(&phba->hbalock, flags);
  1178. }
  1179. /**
  1180. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1181. * @phba: Pointer to HBA context object.
  1182. * @hbqno: HBQ number.
  1183. * @hbq_buf: Pointer to HBQ buffer.
  1184. *
  1185. * This function is called with the hbalock held to post a
  1186. * hbq buffer to the firmware. If the function finds an empty
  1187. * slot in the HBQ, it will post the buffer. The function will return
  1188. * pointer to the hbq entry if it successfully post the buffer
  1189. * else it will return NULL.
  1190. **/
  1191. static int
  1192. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1193. struct hbq_dmabuf *hbq_buf)
  1194. {
  1195. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1196. }
  1197. /**
  1198. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1199. * @phba: Pointer to HBA context object.
  1200. * @hbqno: HBQ number.
  1201. * @hbq_buf: Pointer to HBQ buffer.
  1202. *
  1203. * This function is called with the hbalock held to post a hbq buffer to the
  1204. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1205. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1206. * it successfully post the buffer else it will return an error.
  1207. **/
  1208. static int
  1209. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1210. struct hbq_dmabuf *hbq_buf)
  1211. {
  1212. struct lpfc_hbq_entry *hbqe;
  1213. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1214. /* Get next HBQ entry slot to use */
  1215. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1216. if (hbqe) {
  1217. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1218. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1219. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1220. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1221. hbqe->bde.tus.f.bdeFlags = 0;
  1222. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1223. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1224. /* Sync SLIM */
  1225. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1226. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1227. /* flush */
  1228. readl(phba->hbq_put + hbqno);
  1229. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1230. return 0;
  1231. } else
  1232. return -ENOMEM;
  1233. }
  1234. /**
  1235. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1236. * @phba: Pointer to HBA context object.
  1237. * @hbqno: HBQ number.
  1238. * @hbq_buf: Pointer to HBQ buffer.
  1239. *
  1240. * This function is called with the hbalock held to post an RQE to the SLI4
  1241. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1242. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1243. **/
  1244. static int
  1245. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1246. struct hbq_dmabuf *hbq_buf)
  1247. {
  1248. int rc;
  1249. struct lpfc_rqe hrqe;
  1250. struct lpfc_rqe drqe;
  1251. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1252. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1253. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1254. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1255. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1256. &hrqe, &drqe);
  1257. if (rc < 0)
  1258. return rc;
  1259. hbq_buf->tag = rc;
  1260. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1261. return 0;
  1262. }
  1263. /* HBQ for ELS and CT traffic. */
  1264. static struct lpfc_hbq_init lpfc_els_hbq = {
  1265. .rn = 1,
  1266. .entry_count = 256,
  1267. .mask_count = 0,
  1268. .profile = 0,
  1269. .ring_mask = (1 << LPFC_ELS_RING),
  1270. .buffer_count = 0,
  1271. .init_count = 40,
  1272. .add_count = 40,
  1273. };
  1274. /* HBQ for the extra ring if needed */
  1275. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1276. .rn = 1,
  1277. .entry_count = 200,
  1278. .mask_count = 0,
  1279. .profile = 0,
  1280. .ring_mask = (1 << LPFC_EXTRA_RING),
  1281. .buffer_count = 0,
  1282. .init_count = 0,
  1283. .add_count = 5,
  1284. };
  1285. /* Array of HBQs */
  1286. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1287. &lpfc_els_hbq,
  1288. &lpfc_extra_hbq,
  1289. };
  1290. /**
  1291. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1292. * @phba: Pointer to HBA context object.
  1293. * @hbqno: HBQ number.
  1294. * @count: Number of HBQ buffers to be posted.
  1295. *
  1296. * This function is called with no lock held to post more hbq buffers to the
  1297. * given HBQ. The function returns the number of HBQ buffers successfully
  1298. * posted.
  1299. **/
  1300. static int
  1301. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1302. {
  1303. uint32_t i, posted = 0;
  1304. unsigned long flags;
  1305. struct hbq_dmabuf *hbq_buffer;
  1306. LIST_HEAD(hbq_buf_list);
  1307. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1308. return 0;
  1309. if ((phba->hbqs[hbqno].buffer_count + count) >
  1310. lpfc_hbq_defs[hbqno]->entry_count)
  1311. count = lpfc_hbq_defs[hbqno]->entry_count -
  1312. phba->hbqs[hbqno].buffer_count;
  1313. if (!count)
  1314. return 0;
  1315. /* Allocate HBQ entries */
  1316. for (i = 0; i < count; i++) {
  1317. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1318. if (!hbq_buffer)
  1319. break;
  1320. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1321. }
  1322. /* Check whether HBQ is still in use */
  1323. spin_lock_irqsave(&phba->hbalock, flags);
  1324. if (!phba->hbq_in_use)
  1325. goto err;
  1326. while (!list_empty(&hbq_buf_list)) {
  1327. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1328. dbuf.list);
  1329. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1330. (hbqno << 16));
  1331. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1332. phba->hbqs[hbqno].buffer_count++;
  1333. posted++;
  1334. } else
  1335. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1336. }
  1337. spin_unlock_irqrestore(&phba->hbalock, flags);
  1338. return posted;
  1339. err:
  1340. spin_unlock_irqrestore(&phba->hbalock, flags);
  1341. while (!list_empty(&hbq_buf_list)) {
  1342. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1343. dbuf.list);
  1344. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1345. }
  1346. return 0;
  1347. }
  1348. /**
  1349. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1350. * @phba: Pointer to HBA context object.
  1351. * @qno: HBQ number.
  1352. *
  1353. * This function posts more buffers to the HBQ. This function
  1354. * is called with no lock held. The function returns the number of HBQ entries
  1355. * successfully allocated.
  1356. **/
  1357. int
  1358. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1359. {
  1360. if (phba->sli_rev == LPFC_SLI_REV4)
  1361. return 0;
  1362. else
  1363. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1364. lpfc_hbq_defs[qno]->add_count);
  1365. }
  1366. /**
  1367. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1368. * @phba: Pointer to HBA context object.
  1369. * @qno: HBQ queue number.
  1370. *
  1371. * This function is called from SLI initialization code path with
  1372. * no lock held to post initial HBQ buffers to firmware. The
  1373. * function returns the number of HBQ entries successfully allocated.
  1374. **/
  1375. static int
  1376. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1377. {
  1378. if (phba->sli_rev == LPFC_SLI_REV4)
  1379. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1380. lpfc_hbq_defs[qno]->entry_count);
  1381. else
  1382. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1383. lpfc_hbq_defs[qno]->init_count);
  1384. }
  1385. /**
  1386. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1387. * @phba: Pointer to HBA context object.
  1388. * @hbqno: HBQ number.
  1389. *
  1390. * This function removes the first hbq buffer on an hbq list and returns a
  1391. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1392. **/
  1393. static struct hbq_dmabuf *
  1394. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1395. {
  1396. struct lpfc_dmabuf *d_buf;
  1397. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1398. if (!d_buf)
  1399. return NULL;
  1400. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1401. }
  1402. /**
  1403. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1404. * @phba: Pointer to HBA context object.
  1405. * @tag: Tag of the hbq buffer.
  1406. *
  1407. * This function is called with hbalock held. This function searches
  1408. * for the hbq buffer associated with the given tag in the hbq buffer
  1409. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1410. * it returns NULL.
  1411. **/
  1412. static struct hbq_dmabuf *
  1413. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1414. {
  1415. struct lpfc_dmabuf *d_buf;
  1416. struct hbq_dmabuf *hbq_buf;
  1417. uint32_t hbqno;
  1418. hbqno = tag >> 16;
  1419. if (hbqno >= LPFC_MAX_HBQS)
  1420. return NULL;
  1421. spin_lock_irq(&phba->hbalock);
  1422. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1423. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1424. if (hbq_buf->tag == tag) {
  1425. spin_unlock_irq(&phba->hbalock);
  1426. return hbq_buf;
  1427. }
  1428. }
  1429. spin_unlock_irq(&phba->hbalock);
  1430. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1431. "1803 Bad hbq tag. Data: x%x x%x\n",
  1432. tag, phba->hbqs[tag >> 16].buffer_count);
  1433. return NULL;
  1434. }
  1435. /**
  1436. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1437. * @phba: Pointer to HBA context object.
  1438. * @hbq_buffer: Pointer to HBQ buffer.
  1439. *
  1440. * This function is called with hbalock. This function gives back
  1441. * the hbq buffer to firmware. If the HBQ does not have space to
  1442. * post the buffer, it will free the buffer.
  1443. **/
  1444. void
  1445. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1446. {
  1447. uint32_t hbqno;
  1448. if (hbq_buffer) {
  1449. hbqno = hbq_buffer->tag >> 16;
  1450. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1451. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1452. }
  1453. }
  1454. /**
  1455. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1456. * @mbxCommand: mailbox command code.
  1457. *
  1458. * This function is called by the mailbox event handler function to verify
  1459. * that the completed mailbox command is a legitimate mailbox command. If the
  1460. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1461. * and the mailbox event handler will take the HBA offline.
  1462. **/
  1463. static int
  1464. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1465. {
  1466. uint8_t ret;
  1467. switch (mbxCommand) {
  1468. case MBX_LOAD_SM:
  1469. case MBX_READ_NV:
  1470. case MBX_WRITE_NV:
  1471. case MBX_WRITE_VPARMS:
  1472. case MBX_RUN_BIU_DIAG:
  1473. case MBX_INIT_LINK:
  1474. case MBX_DOWN_LINK:
  1475. case MBX_CONFIG_LINK:
  1476. case MBX_CONFIG_RING:
  1477. case MBX_RESET_RING:
  1478. case MBX_READ_CONFIG:
  1479. case MBX_READ_RCONFIG:
  1480. case MBX_READ_SPARM:
  1481. case MBX_READ_STATUS:
  1482. case MBX_READ_RPI:
  1483. case MBX_READ_XRI:
  1484. case MBX_READ_REV:
  1485. case MBX_READ_LNK_STAT:
  1486. case MBX_REG_LOGIN:
  1487. case MBX_UNREG_LOGIN:
  1488. case MBX_READ_LA:
  1489. case MBX_CLEAR_LA:
  1490. case MBX_DUMP_MEMORY:
  1491. case MBX_DUMP_CONTEXT:
  1492. case MBX_RUN_DIAGS:
  1493. case MBX_RESTART:
  1494. case MBX_UPDATE_CFG:
  1495. case MBX_DOWN_LOAD:
  1496. case MBX_DEL_LD_ENTRY:
  1497. case MBX_RUN_PROGRAM:
  1498. case MBX_SET_MASK:
  1499. case MBX_SET_VARIABLE:
  1500. case MBX_UNREG_D_ID:
  1501. case MBX_KILL_BOARD:
  1502. case MBX_CONFIG_FARP:
  1503. case MBX_BEACON:
  1504. case MBX_LOAD_AREA:
  1505. case MBX_RUN_BIU_DIAG64:
  1506. case MBX_CONFIG_PORT:
  1507. case MBX_READ_SPARM64:
  1508. case MBX_READ_RPI64:
  1509. case MBX_REG_LOGIN64:
  1510. case MBX_READ_LA64:
  1511. case MBX_WRITE_WWN:
  1512. case MBX_SET_DEBUG:
  1513. case MBX_LOAD_EXP_ROM:
  1514. case MBX_ASYNCEVT_ENABLE:
  1515. case MBX_REG_VPI:
  1516. case MBX_UNREG_VPI:
  1517. case MBX_HEARTBEAT:
  1518. case MBX_PORT_CAPABILITIES:
  1519. case MBX_PORT_IOV_CONTROL:
  1520. case MBX_SLI4_CONFIG:
  1521. case MBX_SLI4_REQ_FTRS:
  1522. case MBX_REG_FCFI:
  1523. case MBX_UNREG_FCFI:
  1524. case MBX_REG_VFI:
  1525. case MBX_UNREG_VFI:
  1526. case MBX_INIT_VPI:
  1527. case MBX_INIT_VFI:
  1528. case MBX_RESUME_RPI:
  1529. ret = mbxCommand;
  1530. break;
  1531. default:
  1532. ret = MBX_SHUTDOWN;
  1533. break;
  1534. }
  1535. return ret;
  1536. }
  1537. /**
  1538. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1539. * @phba: Pointer to HBA context object.
  1540. * @pmboxq: Pointer to mailbox command.
  1541. *
  1542. * This is completion handler function for mailbox commands issued from
  1543. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1544. * mailbox event handler function with no lock held. This function
  1545. * will wake up thread waiting on the wait queue pointed by context1
  1546. * of the mailbox.
  1547. **/
  1548. void
  1549. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1550. {
  1551. wait_queue_head_t *pdone_q;
  1552. unsigned long drvr_flag;
  1553. /*
  1554. * If pdone_q is empty, the driver thread gave up waiting and
  1555. * continued running.
  1556. */
  1557. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1558. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1559. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1560. if (pdone_q)
  1561. wake_up_interruptible(pdone_q);
  1562. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1563. return;
  1564. }
  1565. /**
  1566. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1567. * @phba: Pointer to HBA context object.
  1568. * @pmb: Pointer to mailbox object.
  1569. *
  1570. * This function is the default mailbox completion handler. It
  1571. * frees the memory resources associated with the completed mailbox
  1572. * command. If the completed command is a REG_LOGIN mailbox command,
  1573. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1574. **/
  1575. void
  1576. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1577. {
  1578. struct lpfc_dmabuf *mp;
  1579. uint16_t rpi, vpi;
  1580. int rc;
  1581. struct lpfc_vport *vport = pmb->vport;
  1582. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1583. if (mp) {
  1584. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1585. kfree(mp);
  1586. }
  1587. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1588. (phba->sli_rev == LPFC_SLI_REV4))
  1589. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1590. /*
  1591. * If a REG_LOGIN succeeded after node is destroyed or node
  1592. * is in re-discovery driver need to cleanup the RPI.
  1593. */
  1594. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1595. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1596. !pmb->u.mb.mbxStatus) {
  1597. rpi = pmb->u.mb.un.varWords[0];
  1598. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1599. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1600. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1601. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1602. if (rc != MBX_NOT_FINISHED)
  1603. return;
  1604. }
  1605. /* Unreg VPI, if the REG_VPI succeed after VLink failure */
  1606. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1607. !(phba->pport->load_flag & FC_UNLOADING) &&
  1608. !pmb->u.mb.mbxStatus) {
  1609. lpfc_unreg_vpi(phba, pmb->u.mb.un.varRegVpi.vpi, pmb);
  1610. pmb->vport = vport;
  1611. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1612. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1613. if (rc != MBX_NOT_FINISHED)
  1614. return;
  1615. }
  1616. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1617. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1618. else
  1619. mempool_free(pmb, phba->mbox_mem_pool);
  1620. }
  1621. /**
  1622. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1623. * @phba: Pointer to HBA context object.
  1624. *
  1625. * This function is called with no lock held. This function processes all
  1626. * the completed mailbox commands and gives it to upper layers. The interrupt
  1627. * service routine processes mailbox completion interrupt and adds completed
  1628. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1629. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1630. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1631. * function returns the mailbox commands to the upper layer by calling the
  1632. * completion handler function of each mailbox.
  1633. **/
  1634. int
  1635. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1636. {
  1637. MAILBOX_t *pmbox;
  1638. LPFC_MBOXQ_t *pmb;
  1639. int rc;
  1640. LIST_HEAD(cmplq);
  1641. phba->sli.slistat.mbox_event++;
  1642. /* Get all completed mailboxe buffers into the cmplq */
  1643. spin_lock_irq(&phba->hbalock);
  1644. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1645. spin_unlock_irq(&phba->hbalock);
  1646. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1647. do {
  1648. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1649. if (pmb == NULL)
  1650. break;
  1651. pmbox = &pmb->u.mb;
  1652. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1653. if (pmb->vport) {
  1654. lpfc_debugfs_disc_trc(pmb->vport,
  1655. LPFC_DISC_TRC_MBOX_VPORT,
  1656. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1657. (uint32_t)pmbox->mbxCommand,
  1658. pmbox->un.varWords[0],
  1659. pmbox->un.varWords[1]);
  1660. }
  1661. else {
  1662. lpfc_debugfs_disc_trc(phba->pport,
  1663. LPFC_DISC_TRC_MBOX,
  1664. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1665. (uint32_t)pmbox->mbxCommand,
  1666. pmbox->un.varWords[0],
  1667. pmbox->un.varWords[1]);
  1668. }
  1669. }
  1670. /*
  1671. * It is a fatal error if unknown mbox command completion.
  1672. */
  1673. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1674. MBX_SHUTDOWN) {
  1675. /* Unknown mailbox command compl */
  1676. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1677. "(%d):0323 Unknown Mailbox command "
  1678. "x%x (x%x) Cmpl\n",
  1679. pmb->vport ? pmb->vport->vpi : 0,
  1680. pmbox->mbxCommand,
  1681. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1682. phba->link_state = LPFC_HBA_ERROR;
  1683. phba->work_hs = HS_FFER3;
  1684. lpfc_handle_eratt(phba);
  1685. continue;
  1686. }
  1687. if (pmbox->mbxStatus) {
  1688. phba->sli.slistat.mbox_stat_err++;
  1689. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1690. /* Mbox cmd cmpl error - RETRYing */
  1691. lpfc_printf_log(phba, KERN_INFO,
  1692. LOG_MBOX | LOG_SLI,
  1693. "(%d):0305 Mbox cmd cmpl "
  1694. "error - RETRYing Data: x%x "
  1695. "(x%x) x%x x%x x%x\n",
  1696. pmb->vport ? pmb->vport->vpi :0,
  1697. pmbox->mbxCommand,
  1698. lpfc_sli4_mbox_opcode_get(phba,
  1699. pmb),
  1700. pmbox->mbxStatus,
  1701. pmbox->un.varWords[0],
  1702. pmb->vport->port_state);
  1703. pmbox->mbxStatus = 0;
  1704. pmbox->mbxOwner = OWN_HOST;
  1705. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1706. if (rc != MBX_NOT_FINISHED)
  1707. continue;
  1708. }
  1709. }
  1710. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1711. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1712. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1713. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1714. pmb->vport ? pmb->vport->vpi : 0,
  1715. pmbox->mbxCommand,
  1716. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1717. pmb->mbox_cmpl,
  1718. *((uint32_t *) pmbox),
  1719. pmbox->un.varWords[0],
  1720. pmbox->un.varWords[1],
  1721. pmbox->un.varWords[2],
  1722. pmbox->un.varWords[3],
  1723. pmbox->un.varWords[4],
  1724. pmbox->un.varWords[5],
  1725. pmbox->un.varWords[6],
  1726. pmbox->un.varWords[7]);
  1727. if (pmb->mbox_cmpl)
  1728. pmb->mbox_cmpl(phba,pmb);
  1729. } while (1);
  1730. return 0;
  1731. }
  1732. /**
  1733. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1734. * @phba: Pointer to HBA context object.
  1735. * @pring: Pointer to driver SLI ring object.
  1736. * @tag: buffer tag.
  1737. *
  1738. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1739. * is set in the tag the buffer is posted for a particular exchange,
  1740. * the function will return the buffer without replacing the buffer.
  1741. * If the buffer is for unsolicited ELS or CT traffic, this function
  1742. * returns the buffer and also posts another buffer to the firmware.
  1743. **/
  1744. static struct lpfc_dmabuf *
  1745. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1746. struct lpfc_sli_ring *pring,
  1747. uint32_t tag)
  1748. {
  1749. struct hbq_dmabuf *hbq_entry;
  1750. if (tag & QUE_BUFTAG_BIT)
  1751. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1752. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1753. if (!hbq_entry)
  1754. return NULL;
  1755. return &hbq_entry->dbuf;
  1756. }
  1757. /**
  1758. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1759. * @phba: Pointer to HBA context object.
  1760. * @pring: Pointer to driver SLI ring object.
  1761. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1762. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1763. * @fch_type: the type for the first frame of the sequence.
  1764. *
  1765. * This function is called with no lock held. This function uses the r_ctl and
  1766. * type of the received sequence to find the correct callback function to call
  1767. * to process the sequence.
  1768. **/
  1769. static int
  1770. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1771. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1772. uint32_t fch_type)
  1773. {
  1774. int i;
  1775. /* unSolicited Responses */
  1776. if (pring->prt[0].profile) {
  1777. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1778. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1779. saveq);
  1780. return 1;
  1781. }
  1782. /* We must search, based on rctl / type
  1783. for the right routine */
  1784. for (i = 0; i < pring->num_mask; i++) {
  1785. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1786. (pring->prt[i].type == fch_type)) {
  1787. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1788. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1789. (phba, pring, saveq);
  1790. return 1;
  1791. }
  1792. }
  1793. return 0;
  1794. }
  1795. /**
  1796. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1797. * @phba: Pointer to HBA context object.
  1798. * @pring: Pointer to driver SLI ring object.
  1799. * @saveq: Pointer to the unsolicited iocb.
  1800. *
  1801. * This function is called with no lock held by the ring event handler
  1802. * when there is an unsolicited iocb posted to the response ring by the
  1803. * firmware. This function gets the buffer associated with the iocbs
  1804. * and calls the event handler for the ring. This function handles both
  1805. * qring buffers and hbq buffers.
  1806. * When the function returns 1 the caller can free the iocb object otherwise
  1807. * upper layer functions will free the iocb objects.
  1808. **/
  1809. static int
  1810. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1811. struct lpfc_iocbq *saveq)
  1812. {
  1813. IOCB_t * irsp;
  1814. WORD5 * w5p;
  1815. uint32_t Rctl, Type;
  1816. uint32_t match;
  1817. struct lpfc_iocbq *iocbq;
  1818. struct lpfc_dmabuf *dmzbuf;
  1819. match = 0;
  1820. irsp = &(saveq->iocb);
  1821. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1822. if (pring->lpfc_sli_rcv_async_status)
  1823. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1824. else
  1825. lpfc_printf_log(phba,
  1826. KERN_WARNING,
  1827. LOG_SLI,
  1828. "0316 Ring %d handler: unexpected "
  1829. "ASYNC_STATUS iocb received evt_code "
  1830. "0x%x\n",
  1831. pring->ringno,
  1832. irsp->un.asyncstat.evt_code);
  1833. return 1;
  1834. }
  1835. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1836. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1837. if (irsp->ulpBdeCount > 0) {
  1838. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1839. irsp->un.ulpWord[3]);
  1840. lpfc_in_buf_free(phba, dmzbuf);
  1841. }
  1842. if (irsp->ulpBdeCount > 1) {
  1843. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1844. irsp->unsli3.sli3Words[3]);
  1845. lpfc_in_buf_free(phba, dmzbuf);
  1846. }
  1847. if (irsp->ulpBdeCount > 2) {
  1848. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1849. irsp->unsli3.sli3Words[7]);
  1850. lpfc_in_buf_free(phba, dmzbuf);
  1851. }
  1852. return 1;
  1853. }
  1854. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1855. if (irsp->ulpBdeCount != 0) {
  1856. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1857. irsp->un.ulpWord[3]);
  1858. if (!saveq->context2)
  1859. lpfc_printf_log(phba,
  1860. KERN_ERR,
  1861. LOG_SLI,
  1862. "0341 Ring %d Cannot find buffer for "
  1863. "an unsolicited iocb. tag 0x%x\n",
  1864. pring->ringno,
  1865. irsp->un.ulpWord[3]);
  1866. }
  1867. if (irsp->ulpBdeCount == 2) {
  1868. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1869. irsp->unsli3.sli3Words[7]);
  1870. if (!saveq->context3)
  1871. lpfc_printf_log(phba,
  1872. KERN_ERR,
  1873. LOG_SLI,
  1874. "0342 Ring %d Cannot find buffer for an"
  1875. " unsolicited iocb. tag 0x%x\n",
  1876. pring->ringno,
  1877. irsp->unsli3.sli3Words[7]);
  1878. }
  1879. list_for_each_entry(iocbq, &saveq->list, list) {
  1880. irsp = &(iocbq->iocb);
  1881. if (irsp->ulpBdeCount != 0) {
  1882. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1883. irsp->un.ulpWord[3]);
  1884. if (!iocbq->context2)
  1885. lpfc_printf_log(phba,
  1886. KERN_ERR,
  1887. LOG_SLI,
  1888. "0343 Ring %d Cannot find "
  1889. "buffer for an unsolicited iocb"
  1890. ". tag 0x%x\n", pring->ringno,
  1891. irsp->un.ulpWord[3]);
  1892. }
  1893. if (irsp->ulpBdeCount == 2) {
  1894. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1895. irsp->unsli3.sli3Words[7]);
  1896. if (!iocbq->context3)
  1897. lpfc_printf_log(phba,
  1898. KERN_ERR,
  1899. LOG_SLI,
  1900. "0344 Ring %d Cannot find "
  1901. "buffer for an unsolicited "
  1902. "iocb. tag 0x%x\n",
  1903. pring->ringno,
  1904. irsp->unsli3.sli3Words[7]);
  1905. }
  1906. }
  1907. }
  1908. if (irsp->ulpBdeCount != 0 &&
  1909. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1910. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1911. int found = 0;
  1912. /* search continue save q for same XRI */
  1913. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1914. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1915. list_add_tail(&saveq->list, &iocbq->list);
  1916. found = 1;
  1917. break;
  1918. }
  1919. }
  1920. if (!found)
  1921. list_add_tail(&saveq->clist,
  1922. &pring->iocb_continue_saveq);
  1923. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1924. list_del_init(&iocbq->clist);
  1925. saveq = iocbq;
  1926. irsp = &(saveq->iocb);
  1927. } else
  1928. return 0;
  1929. }
  1930. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1931. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1932. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1933. Rctl = FC_RCTL_ELS_REQ;
  1934. Type = FC_TYPE_ELS;
  1935. } else {
  1936. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1937. Rctl = w5p->hcsw.Rctl;
  1938. Type = w5p->hcsw.Type;
  1939. /* Firmware Workaround */
  1940. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1941. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1942. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1943. Rctl = FC_RCTL_ELS_REQ;
  1944. Type = FC_TYPE_ELS;
  1945. w5p->hcsw.Rctl = Rctl;
  1946. w5p->hcsw.Type = Type;
  1947. }
  1948. }
  1949. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1950. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1951. "0313 Ring %d handler: unexpected Rctl x%x "
  1952. "Type x%x received\n",
  1953. pring->ringno, Rctl, Type);
  1954. return 1;
  1955. }
  1956. /**
  1957. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1958. * @phba: Pointer to HBA context object.
  1959. * @pring: Pointer to driver SLI ring object.
  1960. * @prspiocb: Pointer to response iocb object.
  1961. *
  1962. * This function looks up the iocb_lookup table to get the command iocb
  1963. * corresponding to the given response iocb using the iotag of the
  1964. * response iocb. This function is called with the hbalock held.
  1965. * This function returns the command iocb object if it finds the command
  1966. * iocb else returns NULL.
  1967. **/
  1968. static struct lpfc_iocbq *
  1969. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1970. struct lpfc_sli_ring *pring,
  1971. struct lpfc_iocbq *prspiocb)
  1972. {
  1973. struct lpfc_iocbq *cmd_iocb = NULL;
  1974. uint16_t iotag;
  1975. iotag = prspiocb->iocb.ulpIoTag;
  1976. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1977. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1978. list_del_init(&cmd_iocb->list);
  1979. pring->txcmplq_cnt--;
  1980. return cmd_iocb;
  1981. }
  1982. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1983. "0317 iotag x%x is out off "
  1984. "range: max iotag x%x wd0 x%x\n",
  1985. iotag, phba->sli.last_iotag,
  1986. *(((uint32_t *) &prspiocb->iocb) + 7));
  1987. return NULL;
  1988. }
  1989. /**
  1990. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  1991. * @phba: Pointer to HBA context object.
  1992. * @pring: Pointer to driver SLI ring object.
  1993. * @iotag: IOCB tag.
  1994. *
  1995. * This function looks up the iocb_lookup table to get the command iocb
  1996. * corresponding to the given iotag. This function is called with the
  1997. * hbalock held.
  1998. * This function returns the command iocb object if it finds the command
  1999. * iocb else returns NULL.
  2000. **/
  2001. static struct lpfc_iocbq *
  2002. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2003. struct lpfc_sli_ring *pring, uint16_t iotag)
  2004. {
  2005. struct lpfc_iocbq *cmd_iocb;
  2006. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2007. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2008. list_del_init(&cmd_iocb->list);
  2009. pring->txcmplq_cnt--;
  2010. return cmd_iocb;
  2011. }
  2012. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2013. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2014. iotag, phba->sli.last_iotag);
  2015. return NULL;
  2016. }
  2017. /**
  2018. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2019. * @phba: Pointer to HBA context object.
  2020. * @pring: Pointer to driver SLI ring object.
  2021. * @saveq: Pointer to the response iocb to be processed.
  2022. *
  2023. * This function is called by the ring event handler for non-fcp
  2024. * rings when there is a new response iocb in the response ring.
  2025. * The caller is not required to hold any locks. This function
  2026. * gets the command iocb associated with the response iocb and
  2027. * calls the completion handler for the command iocb. If there
  2028. * is no completion handler, the function will free the resources
  2029. * associated with command iocb. If the response iocb is for
  2030. * an already aborted command iocb, the status of the completion
  2031. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2032. * This function always returns 1.
  2033. **/
  2034. static int
  2035. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2036. struct lpfc_iocbq *saveq)
  2037. {
  2038. struct lpfc_iocbq *cmdiocbp;
  2039. int rc = 1;
  2040. unsigned long iflag;
  2041. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2042. spin_lock_irqsave(&phba->hbalock, iflag);
  2043. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2044. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2045. if (cmdiocbp) {
  2046. if (cmdiocbp->iocb_cmpl) {
  2047. /*
  2048. * If an ELS command failed send an event to mgmt
  2049. * application.
  2050. */
  2051. if (saveq->iocb.ulpStatus &&
  2052. (pring->ringno == LPFC_ELS_RING) &&
  2053. (cmdiocbp->iocb.ulpCommand ==
  2054. CMD_ELS_REQUEST64_CR))
  2055. lpfc_send_els_failure_event(phba,
  2056. cmdiocbp, saveq);
  2057. /*
  2058. * Post all ELS completions to the worker thread.
  2059. * All other are passed to the completion callback.
  2060. */
  2061. if (pring->ringno == LPFC_ELS_RING) {
  2062. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2063. (cmdiocbp->iocb_flag &
  2064. LPFC_DRIVER_ABORTED)) {
  2065. spin_lock_irqsave(&phba->hbalock,
  2066. iflag);
  2067. cmdiocbp->iocb_flag &=
  2068. ~LPFC_DRIVER_ABORTED;
  2069. spin_unlock_irqrestore(&phba->hbalock,
  2070. iflag);
  2071. saveq->iocb.ulpStatus =
  2072. IOSTAT_LOCAL_REJECT;
  2073. saveq->iocb.un.ulpWord[4] =
  2074. IOERR_SLI_ABORTED;
  2075. /* Firmware could still be in progress
  2076. * of DMAing payload, so don't free data
  2077. * buffer till after a hbeat.
  2078. */
  2079. spin_lock_irqsave(&phba->hbalock,
  2080. iflag);
  2081. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2082. spin_unlock_irqrestore(&phba->hbalock,
  2083. iflag);
  2084. }
  2085. if (phba->sli_rev == LPFC_SLI_REV4) {
  2086. if (saveq->iocb_flag &
  2087. LPFC_EXCHANGE_BUSY) {
  2088. /* Set cmdiocb flag for the
  2089. * exchange busy so sgl (xri)
  2090. * will not be released until
  2091. * the abort xri is received
  2092. * from hba.
  2093. */
  2094. spin_lock_irqsave(
  2095. &phba->hbalock, iflag);
  2096. cmdiocbp->iocb_flag |=
  2097. LPFC_EXCHANGE_BUSY;
  2098. spin_unlock_irqrestore(
  2099. &phba->hbalock, iflag);
  2100. }
  2101. if (cmdiocbp->iocb_flag &
  2102. LPFC_DRIVER_ABORTED) {
  2103. /*
  2104. * Clear LPFC_DRIVER_ABORTED
  2105. * bit in case it was driver
  2106. * initiated abort.
  2107. */
  2108. spin_lock_irqsave(
  2109. &phba->hbalock, iflag);
  2110. cmdiocbp->iocb_flag &=
  2111. ~LPFC_DRIVER_ABORTED;
  2112. spin_unlock_irqrestore(
  2113. &phba->hbalock, iflag);
  2114. cmdiocbp->iocb.ulpStatus =
  2115. IOSTAT_LOCAL_REJECT;
  2116. cmdiocbp->iocb.un.ulpWord[4] =
  2117. IOERR_ABORT_REQUESTED;
  2118. /*
  2119. * For SLI4, irsiocb contains
  2120. * NO_XRI in sli_xritag, it
  2121. * shall not affect releasing
  2122. * sgl (xri) process.
  2123. */
  2124. saveq->iocb.ulpStatus =
  2125. IOSTAT_LOCAL_REJECT;
  2126. saveq->iocb.un.ulpWord[4] =
  2127. IOERR_SLI_ABORTED;
  2128. spin_lock_irqsave(
  2129. &phba->hbalock, iflag);
  2130. saveq->iocb_flag |=
  2131. LPFC_DELAY_MEM_FREE;
  2132. spin_unlock_irqrestore(
  2133. &phba->hbalock, iflag);
  2134. }
  2135. }
  2136. }
  2137. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2138. } else
  2139. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2140. } else {
  2141. /*
  2142. * Unknown initiating command based on the response iotag.
  2143. * This could be the case on the ELS ring because of
  2144. * lpfc_els_abort().
  2145. */
  2146. if (pring->ringno != LPFC_ELS_RING) {
  2147. /*
  2148. * Ring <ringno> handler: unexpected completion IoTag
  2149. * <IoTag>
  2150. */
  2151. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2152. "0322 Ring %d handler: "
  2153. "unexpected completion IoTag x%x "
  2154. "Data: x%x x%x x%x x%x\n",
  2155. pring->ringno,
  2156. saveq->iocb.ulpIoTag,
  2157. saveq->iocb.ulpStatus,
  2158. saveq->iocb.un.ulpWord[4],
  2159. saveq->iocb.ulpCommand,
  2160. saveq->iocb.ulpContext);
  2161. }
  2162. }
  2163. return rc;
  2164. }
  2165. /**
  2166. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2167. * @phba: Pointer to HBA context object.
  2168. * @pring: Pointer to driver SLI ring object.
  2169. *
  2170. * This function is called from the iocb ring event handlers when
  2171. * put pointer is ahead of the get pointer for a ring. This function signal
  2172. * an error attention condition to the worker thread and the worker
  2173. * thread will transition the HBA to offline state.
  2174. **/
  2175. static void
  2176. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2177. {
  2178. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2179. /*
  2180. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2181. * rsp ring <portRspMax>
  2182. */
  2183. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2184. "0312 Ring %d handler: portRspPut %d "
  2185. "is bigger than rsp ring %d\n",
  2186. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2187. pring->numRiocb);
  2188. phba->link_state = LPFC_HBA_ERROR;
  2189. /*
  2190. * All error attention handlers are posted to
  2191. * worker thread
  2192. */
  2193. phba->work_ha |= HA_ERATT;
  2194. phba->work_hs = HS_FFER3;
  2195. lpfc_worker_wake_up(phba);
  2196. return;
  2197. }
  2198. /**
  2199. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2200. * @ptr: Pointer to address of HBA context object.
  2201. *
  2202. * This function is invoked by the Error Attention polling timer when the
  2203. * timer times out. It will check the SLI Error Attention register for
  2204. * possible attention events. If so, it will post an Error Attention event
  2205. * and wake up worker thread to process it. Otherwise, it will set up the
  2206. * Error Attention polling timer for the next poll.
  2207. **/
  2208. void lpfc_poll_eratt(unsigned long ptr)
  2209. {
  2210. struct lpfc_hba *phba;
  2211. uint32_t eratt = 0;
  2212. phba = (struct lpfc_hba *)ptr;
  2213. /* Check chip HA register for error event */
  2214. eratt = lpfc_sli_check_eratt(phba);
  2215. if (eratt)
  2216. /* Tell the worker thread there is work to do */
  2217. lpfc_worker_wake_up(phba);
  2218. else
  2219. /* Restart the timer for next eratt poll */
  2220. mod_timer(&phba->eratt_poll, jiffies +
  2221. HZ * LPFC_ERATT_POLL_INTERVAL);
  2222. return;
  2223. }
  2224. /**
  2225. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2226. * @phba: Pointer to HBA context object.
  2227. * @pring: Pointer to driver SLI ring object.
  2228. * @mask: Host attention register mask for this ring.
  2229. *
  2230. * This function is called from the interrupt context when there is a ring
  2231. * event for the fcp ring. The caller does not hold any lock.
  2232. * The function processes each response iocb in the response ring until it
  2233. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2234. * LE bit set. The function will call the completion handler of the command iocb
  2235. * if the response iocb indicates a completion for a command iocb or it is
  2236. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2237. * function if this is an unsolicited iocb.
  2238. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2239. * to check it explicitly.
  2240. */
  2241. int
  2242. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2243. struct lpfc_sli_ring *pring, uint32_t mask)
  2244. {
  2245. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2246. IOCB_t *irsp = NULL;
  2247. IOCB_t *entry = NULL;
  2248. struct lpfc_iocbq *cmdiocbq = NULL;
  2249. struct lpfc_iocbq rspiocbq;
  2250. uint32_t status;
  2251. uint32_t portRspPut, portRspMax;
  2252. int rc = 1;
  2253. lpfc_iocb_type type;
  2254. unsigned long iflag;
  2255. uint32_t rsp_cmpl = 0;
  2256. spin_lock_irqsave(&phba->hbalock, iflag);
  2257. pring->stats.iocb_event++;
  2258. /*
  2259. * The next available response entry should never exceed the maximum
  2260. * entries. If it does, treat it as an adapter hardware error.
  2261. */
  2262. portRspMax = pring->numRiocb;
  2263. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2264. if (unlikely(portRspPut >= portRspMax)) {
  2265. lpfc_sli_rsp_pointers_error(phba, pring);
  2266. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2267. return 1;
  2268. }
  2269. if (phba->fcp_ring_in_use) {
  2270. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2271. return 1;
  2272. } else
  2273. phba->fcp_ring_in_use = 1;
  2274. rmb();
  2275. while (pring->rspidx != portRspPut) {
  2276. /*
  2277. * Fetch an entry off the ring and copy it into a local data
  2278. * structure. The copy involves a byte-swap since the
  2279. * network byte order and pci byte orders are different.
  2280. */
  2281. entry = lpfc_resp_iocb(phba, pring);
  2282. phba->last_completion_time = jiffies;
  2283. if (++pring->rspidx >= portRspMax)
  2284. pring->rspidx = 0;
  2285. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2286. (uint32_t *) &rspiocbq.iocb,
  2287. phba->iocb_rsp_size);
  2288. INIT_LIST_HEAD(&(rspiocbq.list));
  2289. irsp = &rspiocbq.iocb;
  2290. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2291. pring->stats.iocb_rsp++;
  2292. rsp_cmpl++;
  2293. if (unlikely(irsp->ulpStatus)) {
  2294. /*
  2295. * If resource errors reported from HBA, reduce
  2296. * queuedepths of the SCSI device.
  2297. */
  2298. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2299. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2300. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2301. phba->lpfc_rampdown_queue_depth(phba);
  2302. spin_lock_irqsave(&phba->hbalock, iflag);
  2303. }
  2304. /* Rsp ring <ringno> error: IOCB */
  2305. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2306. "0336 Rsp Ring %d error: IOCB Data: "
  2307. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2308. pring->ringno,
  2309. irsp->un.ulpWord[0],
  2310. irsp->un.ulpWord[1],
  2311. irsp->un.ulpWord[2],
  2312. irsp->un.ulpWord[3],
  2313. irsp->un.ulpWord[4],
  2314. irsp->un.ulpWord[5],
  2315. *(uint32_t *)&irsp->un1,
  2316. *((uint32_t *)&irsp->un1 + 1));
  2317. }
  2318. switch (type) {
  2319. case LPFC_ABORT_IOCB:
  2320. case LPFC_SOL_IOCB:
  2321. /*
  2322. * Idle exchange closed via ABTS from port. No iocb
  2323. * resources need to be recovered.
  2324. */
  2325. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2326. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2327. "0333 IOCB cmd 0x%x"
  2328. " processed. Skipping"
  2329. " completion\n",
  2330. irsp->ulpCommand);
  2331. break;
  2332. }
  2333. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2334. &rspiocbq);
  2335. if (unlikely(!cmdiocbq))
  2336. break;
  2337. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2338. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2339. if (cmdiocbq->iocb_cmpl) {
  2340. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2341. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2342. &rspiocbq);
  2343. spin_lock_irqsave(&phba->hbalock, iflag);
  2344. }
  2345. break;
  2346. case LPFC_UNSOL_IOCB:
  2347. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2348. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2349. spin_lock_irqsave(&phba->hbalock, iflag);
  2350. break;
  2351. default:
  2352. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2353. char adaptermsg[LPFC_MAX_ADPTMSG];
  2354. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2355. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2356. MAX_MSG_DATA);
  2357. dev_warn(&((phba->pcidev)->dev),
  2358. "lpfc%d: %s\n",
  2359. phba->brd_no, adaptermsg);
  2360. } else {
  2361. /* Unknown IOCB command */
  2362. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2363. "0334 Unknown IOCB command "
  2364. "Data: x%x, x%x x%x x%x x%x\n",
  2365. type, irsp->ulpCommand,
  2366. irsp->ulpStatus,
  2367. irsp->ulpIoTag,
  2368. irsp->ulpContext);
  2369. }
  2370. break;
  2371. }
  2372. /*
  2373. * The response IOCB has been processed. Update the ring
  2374. * pointer in SLIM. If the port response put pointer has not
  2375. * been updated, sync the pgp->rspPutInx and fetch the new port
  2376. * response put pointer.
  2377. */
  2378. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2379. if (pring->rspidx == portRspPut)
  2380. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2381. }
  2382. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2383. pring->stats.iocb_rsp_full++;
  2384. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2385. writel(status, phba->CAregaddr);
  2386. readl(phba->CAregaddr);
  2387. }
  2388. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2389. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2390. pring->stats.iocb_cmd_empty++;
  2391. /* Force update of the local copy of cmdGetInx */
  2392. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2393. lpfc_sli_resume_iocb(phba, pring);
  2394. if ((pring->lpfc_sli_cmd_available))
  2395. (pring->lpfc_sli_cmd_available) (phba, pring);
  2396. }
  2397. phba->fcp_ring_in_use = 0;
  2398. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2399. return rc;
  2400. }
  2401. /**
  2402. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2403. * @phba: Pointer to HBA context object.
  2404. * @pring: Pointer to driver SLI ring object.
  2405. * @rspiocbp: Pointer to driver response IOCB object.
  2406. *
  2407. * This function is called from the worker thread when there is a slow-path
  2408. * response IOCB to process. This function chains all the response iocbs until
  2409. * seeing the iocb with the LE bit set. The function will call
  2410. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2411. * completion of a command iocb. The function will call the
  2412. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2413. * The function frees the resources or calls the completion handler if this
  2414. * iocb is an abort completion. The function returns NULL when the response
  2415. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2416. * this function shall chain the iocb on to the iocb_continueq and return the
  2417. * response iocb passed in.
  2418. **/
  2419. static struct lpfc_iocbq *
  2420. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2421. struct lpfc_iocbq *rspiocbp)
  2422. {
  2423. struct lpfc_iocbq *saveq;
  2424. struct lpfc_iocbq *cmdiocbp;
  2425. struct lpfc_iocbq *next_iocb;
  2426. IOCB_t *irsp = NULL;
  2427. uint32_t free_saveq;
  2428. uint8_t iocb_cmd_type;
  2429. lpfc_iocb_type type;
  2430. unsigned long iflag;
  2431. int rc;
  2432. spin_lock_irqsave(&phba->hbalock, iflag);
  2433. /* First add the response iocb to the countinueq list */
  2434. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2435. pring->iocb_continueq_cnt++;
  2436. /* Now, determine whetehr the list is completed for processing */
  2437. irsp = &rspiocbp->iocb;
  2438. if (irsp->ulpLe) {
  2439. /*
  2440. * By default, the driver expects to free all resources
  2441. * associated with this iocb completion.
  2442. */
  2443. free_saveq = 1;
  2444. saveq = list_get_first(&pring->iocb_continueq,
  2445. struct lpfc_iocbq, list);
  2446. irsp = &(saveq->iocb);
  2447. list_del_init(&pring->iocb_continueq);
  2448. pring->iocb_continueq_cnt = 0;
  2449. pring->stats.iocb_rsp++;
  2450. /*
  2451. * If resource errors reported from HBA, reduce
  2452. * queuedepths of the SCSI device.
  2453. */
  2454. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2455. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2456. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2457. phba->lpfc_rampdown_queue_depth(phba);
  2458. spin_lock_irqsave(&phba->hbalock, iflag);
  2459. }
  2460. if (irsp->ulpStatus) {
  2461. /* Rsp ring <ringno> error: IOCB */
  2462. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2463. "0328 Rsp Ring %d error: "
  2464. "IOCB Data: "
  2465. "x%x x%x x%x x%x "
  2466. "x%x x%x x%x x%x "
  2467. "x%x x%x x%x x%x "
  2468. "x%x x%x x%x x%x\n",
  2469. pring->ringno,
  2470. irsp->un.ulpWord[0],
  2471. irsp->un.ulpWord[1],
  2472. irsp->un.ulpWord[2],
  2473. irsp->un.ulpWord[3],
  2474. irsp->un.ulpWord[4],
  2475. irsp->un.ulpWord[5],
  2476. *(((uint32_t *) irsp) + 6),
  2477. *(((uint32_t *) irsp) + 7),
  2478. *(((uint32_t *) irsp) + 8),
  2479. *(((uint32_t *) irsp) + 9),
  2480. *(((uint32_t *) irsp) + 10),
  2481. *(((uint32_t *) irsp) + 11),
  2482. *(((uint32_t *) irsp) + 12),
  2483. *(((uint32_t *) irsp) + 13),
  2484. *(((uint32_t *) irsp) + 14),
  2485. *(((uint32_t *) irsp) + 15));
  2486. }
  2487. /*
  2488. * Fetch the IOCB command type and call the correct completion
  2489. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2490. * get freed back to the lpfc_iocb_list by the discovery
  2491. * kernel thread.
  2492. */
  2493. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2494. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2495. switch (type) {
  2496. case LPFC_SOL_IOCB:
  2497. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2498. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2499. spin_lock_irqsave(&phba->hbalock, iflag);
  2500. break;
  2501. case LPFC_UNSOL_IOCB:
  2502. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2503. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2504. spin_lock_irqsave(&phba->hbalock, iflag);
  2505. if (!rc)
  2506. free_saveq = 0;
  2507. break;
  2508. case LPFC_ABORT_IOCB:
  2509. cmdiocbp = NULL;
  2510. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2511. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2512. saveq);
  2513. if (cmdiocbp) {
  2514. /* Call the specified completion routine */
  2515. if (cmdiocbp->iocb_cmpl) {
  2516. spin_unlock_irqrestore(&phba->hbalock,
  2517. iflag);
  2518. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2519. saveq);
  2520. spin_lock_irqsave(&phba->hbalock,
  2521. iflag);
  2522. } else
  2523. __lpfc_sli_release_iocbq(phba,
  2524. cmdiocbp);
  2525. }
  2526. break;
  2527. case LPFC_UNKNOWN_IOCB:
  2528. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2529. char adaptermsg[LPFC_MAX_ADPTMSG];
  2530. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2531. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2532. MAX_MSG_DATA);
  2533. dev_warn(&((phba->pcidev)->dev),
  2534. "lpfc%d: %s\n",
  2535. phba->brd_no, adaptermsg);
  2536. } else {
  2537. /* Unknown IOCB command */
  2538. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2539. "0335 Unknown IOCB "
  2540. "command Data: x%x "
  2541. "x%x x%x x%x\n",
  2542. irsp->ulpCommand,
  2543. irsp->ulpStatus,
  2544. irsp->ulpIoTag,
  2545. irsp->ulpContext);
  2546. }
  2547. break;
  2548. }
  2549. if (free_saveq) {
  2550. list_for_each_entry_safe(rspiocbp, next_iocb,
  2551. &saveq->list, list) {
  2552. list_del(&rspiocbp->list);
  2553. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2554. }
  2555. __lpfc_sli_release_iocbq(phba, saveq);
  2556. }
  2557. rspiocbp = NULL;
  2558. }
  2559. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2560. return rspiocbp;
  2561. }
  2562. /**
  2563. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2564. * @phba: Pointer to HBA context object.
  2565. * @pring: Pointer to driver SLI ring object.
  2566. * @mask: Host attention register mask for this ring.
  2567. *
  2568. * This routine wraps the actual slow_ring event process routine from the
  2569. * API jump table function pointer from the lpfc_hba struct.
  2570. **/
  2571. void
  2572. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2573. struct lpfc_sli_ring *pring, uint32_t mask)
  2574. {
  2575. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2576. }
  2577. /**
  2578. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2579. * @phba: Pointer to HBA context object.
  2580. * @pring: Pointer to driver SLI ring object.
  2581. * @mask: Host attention register mask for this ring.
  2582. *
  2583. * This function is called from the worker thread when there is a ring event
  2584. * for non-fcp rings. The caller does not hold any lock. The function will
  2585. * remove each response iocb in the response ring and calls the handle
  2586. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2587. **/
  2588. static void
  2589. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2590. struct lpfc_sli_ring *pring, uint32_t mask)
  2591. {
  2592. struct lpfc_pgp *pgp;
  2593. IOCB_t *entry;
  2594. IOCB_t *irsp = NULL;
  2595. struct lpfc_iocbq *rspiocbp = NULL;
  2596. uint32_t portRspPut, portRspMax;
  2597. unsigned long iflag;
  2598. uint32_t status;
  2599. pgp = &phba->port_gp[pring->ringno];
  2600. spin_lock_irqsave(&phba->hbalock, iflag);
  2601. pring->stats.iocb_event++;
  2602. /*
  2603. * The next available response entry should never exceed the maximum
  2604. * entries. If it does, treat it as an adapter hardware error.
  2605. */
  2606. portRspMax = pring->numRiocb;
  2607. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2608. if (portRspPut >= portRspMax) {
  2609. /*
  2610. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2611. * rsp ring <portRspMax>
  2612. */
  2613. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2614. "0303 Ring %d handler: portRspPut %d "
  2615. "is bigger than rsp ring %d\n",
  2616. pring->ringno, portRspPut, portRspMax);
  2617. phba->link_state = LPFC_HBA_ERROR;
  2618. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2619. phba->work_hs = HS_FFER3;
  2620. lpfc_handle_eratt(phba);
  2621. return;
  2622. }
  2623. rmb();
  2624. while (pring->rspidx != portRspPut) {
  2625. /*
  2626. * Build a completion list and call the appropriate handler.
  2627. * The process is to get the next available response iocb, get
  2628. * a free iocb from the list, copy the response data into the
  2629. * free iocb, insert to the continuation list, and update the
  2630. * next response index to slim. This process makes response
  2631. * iocb's in the ring available to DMA as fast as possible but
  2632. * pays a penalty for a copy operation. Since the iocb is
  2633. * only 32 bytes, this penalty is considered small relative to
  2634. * the PCI reads for register values and a slim write. When
  2635. * the ulpLe field is set, the entire Command has been
  2636. * received.
  2637. */
  2638. entry = lpfc_resp_iocb(phba, pring);
  2639. phba->last_completion_time = jiffies;
  2640. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2641. if (rspiocbp == NULL) {
  2642. printk(KERN_ERR "%s: out of buffers! Failing "
  2643. "completion.\n", __func__);
  2644. break;
  2645. }
  2646. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2647. phba->iocb_rsp_size);
  2648. irsp = &rspiocbp->iocb;
  2649. if (++pring->rspidx >= portRspMax)
  2650. pring->rspidx = 0;
  2651. if (pring->ringno == LPFC_ELS_RING) {
  2652. lpfc_debugfs_slow_ring_trc(phba,
  2653. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2654. *(((uint32_t *) irsp) + 4),
  2655. *(((uint32_t *) irsp) + 6),
  2656. *(((uint32_t *) irsp) + 7));
  2657. }
  2658. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2659. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2660. /* Handle the response IOCB */
  2661. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2662. spin_lock_irqsave(&phba->hbalock, iflag);
  2663. /*
  2664. * If the port response put pointer has not been updated, sync
  2665. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2666. * response put pointer.
  2667. */
  2668. if (pring->rspidx == portRspPut) {
  2669. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2670. }
  2671. } /* while (pring->rspidx != portRspPut) */
  2672. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2673. /* At least one response entry has been freed */
  2674. pring->stats.iocb_rsp_full++;
  2675. /* SET RxRE_RSP in Chip Att register */
  2676. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2677. writel(status, phba->CAregaddr);
  2678. readl(phba->CAregaddr); /* flush */
  2679. }
  2680. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2681. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2682. pring->stats.iocb_cmd_empty++;
  2683. /* Force update of the local copy of cmdGetInx */
  2684. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2685. lpfc_sli_resume_iocb(phba, pring);
  2686. if ((pring->lpfc_sli_cmd_available))
  2687. (pring->lpfc_sli_cmd_available) (phba, pring);
  2688. }
  2689. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2690. return;
  2691. }
  2692. /**
  2693. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2694. * @phba: Pointer to HBA context object.
  2695. * @pring: Pointer to driver SLI ring object.
  2696. * @mask: Host attention register mask for this ring.
  2697. *
  2698. * This function is called from the worker thread when there is a pending
  2699. * ELS response iocb on the driver internal slow-path response iocb worker
  2700. * queue. The caller does not hold any lock. The function will remove each
  2701. * response iocb from the response worker queue and calls the handle
  2702. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2703. **/
  2704. static void
  2705. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2706. struct lpfc_sli_ring *pring, uint32_t mask)
  2707. {
  2708. struct lpfc_iocbq *irspiocbq;
  2709. struct hbq_dmabuf *dmabuf;
  2710. struct lpfc_cq_event *cq_event;
  2711. unsigned long iflag;
  2712. spin_lock_irqsave(&phba->hbalock, iflag);
  2713. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  2714. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2715. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  2716. /* Get the response iocb from the head of work queue */
  2717. spin_lock_irqsave(&phba->hbalock, iflag);
  2718. list_remove_head(&phba->sli4_hba.sp_queue_event,
  2719. cq_event, struct lpfc_cq_event, list);
  2720. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2721. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  2722. case CQE_CODE_COMPL_WQE:
  2723. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  2724. cq_event);
  2725. /* Translate ELS WCQE to response IOCBQ */
  2726. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  2727. irspiocbq);
  2728. if (irspiocbq)
  2729. lpfc_sli_sp_handle_rspiocb(phba, pring,
  2730. irspiocbq);
  2731. break;
  2732. case CQE_CODE_RECEIVE:
  2733. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  2734. cq_event);
  2735. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  2736. break;
  2737. default:
  2738. break;
  2739. }
  2740. }
  2741. }
  2742. /**
  2743. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2744. * @phba: Pointer to HBA context object.
  2745. * @pring: Pointer to driver SLI ring object.
  2746. *
  2747. * This function aborts all iocbs in the given ring and frees all the iocb
  2748. * objects in txq. This function issues an abort iocb for all the iocb commands
  2749. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2750. * the return of this function. The caller is not required to hold any locks.
  2751. **/
  2752. void
  2753. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2754. {
  2755. LIST_HEAD(completions);
  2756. struct lpfc_iocbq *iocb, *next_iocb;
  2757. if (pring->ringno == LPFC_ELS_RING) {
  2758. lpfc_fabric_abort_hba(phba);
  2759. }
  2760. /* Error everything on txq and txcmplq
  2761. * First do the txq.
  2762. */
  2763. spin_lock_irq(&phba->hbalock);
  2764. list_splice_init(&pring->txq, &completions);
  2765. pring->txq_cnt = 0;
  2766. /* Next issue ABTS for everything on the txcmplq */
  2767. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2768. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2769. spin_unlock_irq(&phba->hbalock);
  2770. /* Cancel all the IOCBs from the completions list */
  2771. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2772. IOERR_SLI_ABORTED);
  2773. }
  2774. /**
  2775. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2776. * @phba: Pointer to HBA context object.
  2777. *
  2778. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2779. * objects in txq and txcmplq. This function will not issue abort iocbs
  2780. * for all the iocb commands in txcmplq, they will just be returned with
  2781. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2782. * slot has been permanently disabled.
  2783. **/
  2784. void
  2785. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2786. {
  2787. LIST_HEAD(txq);
  2788. LIST_HEAD(txcmplq);
  2789. struct lpfc_sli *psli = &phba->sli;
  2790. struct lpfc_sli_ring *pring;
  2791. /* Currently, only one fcp ring */
  2792. pring = &psli->ring[psli->fcp_ring];
  2793. spin_lock_irq(&phba->hbalock);
  2794. /* Retrieve everything on txq */
  2795. list_splice_init(&pring->txq, &txq);
  2796. pring->txq_cnt = 0;
  2797. /* Retrieve everything on the txcmplq */
  2798. list_splice_init(&pring->txcmplq, &txcmplq);
  2799. pring->txcmplq_cnt = 0;
  2800. spin_unlock_irq(&phba->hbalock);
  2801. /* Flush the txq */
  2802. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2803. IOERR_SLI_DOWN);
  2804. /* Flush the txcmpq */
  2805. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2806. IOERR_SLI_DOWN);
  2807. }
  2808. /**
  2809. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2810. * @phba: Pointer to HBA context object.
  2811. * @mask: Bit mask to be checked.
  2812. *
  2813. * This function reads the host status register and compares
  2814. * with the provided bit mask to check if HBA completed
  2815. * the restart. This function will wait in a loop for the
  2816. * HBA to complete restart. If the HBA does not restart within
  2817. * 15 iterations, the function will reset the HBA again. The
  2818. * function returns 1 when HBA fail to restart otherwise returns
  2819. * zero.
  2820. **/
  2821. static int
  2822. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2823. {
  2824. uint32_t status;
  2825. int i = 0;
  2826. int retval = 0;
  2827. /* Read the HBA Host Status Register */
  2828. status = readl(phba->HSregaddr);
  2829. /*
  2830. * Check status register every 100ms for 5 retries, then every
  2831. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2832. * every 2.5 sec for 4.
  2833. * Break our of the loop if errors occurred during init.
  2834. */
  2835. while (((status & mask) != mask) &&
  2836. !(status & HS_FFERM) &&
  2837. i++ < 20) {
  2838. if (i <= 5)
  2839. msleep(10);
  2840. else if (i <= 10)
  2841. msleep(500);
  2842. else
  2843. msleep(2500);
  2844. if (i == 15) {
  2845. /* Do post */
  2846. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2847. lpfc_sli_brdrestart(phba);
  2848. }
  2849. /* Read the HBA Host Status Register */
  2850. status = readl(phba->HSregaddr);
  2851. }
  2852. /* Check to see if any errors occurred during init */
  2853. if ((status & HS_FFERM) || (i >= 20)) {
  2854. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2855. "2751 Adapter failed to restart, "
  2856. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  2857. status,
  2858. readl(phba->MBslimaddr + 0xa8),
  2859. readl(phba->MBslimaddr + 0xac));
  2860. phba->link_state = LPFC_HBA_ERROR;
  2861. retval = 1;
  2862. }
  2863. return retval;
  2864. }
  2865. /**
  2866. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2867. * @phba: Pointer to HBA context object.
  2868. * @mask: Bit mask to be checked.
  2869. *
  2870. * This function checks the host status register to check if HBA is
  2871. * ready. This function will wait in a loop for the HBA to be ready
  2872. * If the HBA is not ready , the function will will reset the HBA PCI
  2873. * function again. The function returns 1 when HBA fail to be ready
  2874. * otherwise returns zero.
  2875. **/
  2876. static int
  2877. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2878. {
  2879. uint32_t status;
  2880. int retval = 0;
  2881. /* Read the HBA Host Status Register */
  2882. status = lpfc_sli4_post_status_check(phba);
  2883. if (status) {
  2884. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2885. lpfc_sli_brdrestart(phba);
  2886. status = lpfc_sli4_post_status_check(phba);
  2887. }
  2888. /* Check to see if any errors occurred during init */
  2889. if (status) {
  2890. phba->link_state = LPFC_HBA_ERROR;
  2891. retval = 1;
  2892. } else
  2893. phba->sli4_hba.intr_enable = 0;
  2894. return retval;
  2895. }
  2896. /**
  2897. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2898. * @phba: Pointer to HBA context object.
  2899. * @mask: Bit mask to be checked.
  2900. *
  2901. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2902. * from the API jump table function pointer from the lpfc_hba struct.
  2903. **/
  2904. int
  2905. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2906. {
  2907. return phba->lpfc_sli_brdready(phba, mask);
  2908. }
  2909. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2910. /**
  2911. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2912. * @phba: Pointer to HBA context object.
  2913. *
  2914. * This function is called before resetting an HBA. This
  2915. * function requests HBA to quiesce DMAs before a reset.
  2916. **/
  2917. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2918. {
  2919. uint32_t __iomem *resp_buf;
  2920. uint32_t __iomem *mbox_buf;
  2921. volatile uint32_t mbox;
  2922. uint32_t hc_copy;
  2923. int i;
  2924. uint8_t hdrtype;
  2925. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2926. if (hdrtype != 0x80 ||
  2927. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2928. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2929. return;
  2930. /*
  2931. * Tell the other part of the chip to suspend temporarily all
  2932. * its DMA activity.
  2933. */
  2934. resp_buf = phba->MBslimaddr;
  2935. /* Disable the error attention */
  2936. hc_copy = readl(phba->HCregaddr);
  2937. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2938. readl(phba->HCregaddr); /* flush */
  2939. phba->link_flag |= LS_IGNORE_ERATT;
  2940. if (readl(phba->HAregaddr) & HA_ERATT) {
  2941. /* Clear Chip error bit */
  2942. writel(HA_ERATT, phba->HAregaddr);
  2943. phba->pport->stopped = 1;
  2944. }
  2945. mbox = 0;
  2946. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2947. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2948. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2949. mbox_buf = phba->MBslimaddr;
  2950. writel(mbox, mbox_buf);
  2951. for (i = 0;
  2952. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2953. mdelay(1);
  2954. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2955. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2956. phba->pport->stopped)
  2957. goto restore_hc;
  2958. else
  2959. goto clear_errat;
  2960. }
  2961. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2962. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2963. mdelay(1);
  2964. clear_errat:
  2965. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  2966. mdelay(1);
  2967. if (readl(phba->HAregaddr) & HA_ERATT) {
  2968. writel(HA_ERATT, phba->HAregaddr);
  2969. phba->pport->stopped = 1;
  2970. }
  2971. restore_hc:
  2972. phba->link_flag &= ~LS_IGNORE_ERATT;
  2973. writel(hc_copy, phba->HCregaddr);
  2974. readl(phba->HCregaddr); /* flush */
  2975. }
  2976. /**
  2977. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  2978. * @phba: Pointer to HBA context object.
  2979. *
  2980. * This function issues a kill_board mailbox command and waits for
  2981. * the error attention interrupt. This function is called for stopping
  2982. * the firmware processing. The caller is not required to hold any
  2983. * locks. This function calls lpfc_hba_down_post function to free
  2984. * any pending commands after the kill. The function will return 1 when it
  2985. * fails to kill the board else will return 0.
  2986. **/
  2987. int
  2988. lpfc_sli_brdkill(struct lpfc_hba *phba)
  2989. {
  2990. struct lpfc_sli *psli;
  2991. LPFC_MBOXQ_t *pmb;
  2992. uint32_t status;
  2993. uint32_t ha_copy;
  2994. int retval;
  2995. int i = 0;
  2996. psli = &phba->sli;
  2997. /* Kill HBA */
  2998. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2999. "0329 Kill HBA Data: x%x x%x\n",
  3000. phba->pport->port_state, psli->sli_flag);
  3001. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3002. if (!pmb)
  3003. return 1;
  3004. /* Disable the error attention */
  3005. spin_lock_irq(&phba->hbalock);
  3006. status = readl(phba->HCregaddr);
  3007. status &= ~HC_ERINT_ENA;
  3008. writel(status, phba->HCregaddr);
  3009. readl(phba->HCregaddr); /* flush */
  3010. phba->link_flag |= LS_IGNORE_ERATT;
  3011. spin_unlock_irq(&phba->hbalock);
  3012. lpfc_kill_board(phba, pmb);
  3013. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3014. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3015. if (retval != MBX_SUCCESS) {
  3016. if (retval != MBX_BUSY)
  3017. mempool_free(pmb, phba->mbox_mem_pool);
  3018. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3019. "2752 KILL_BOARD command failed retval %d\n",
  3020. retval);
  3021. spin_lock_irq(&phba->hbalock);
  3022. phba->link_flag &= ~LS_IGNORE_ERATT;
  3023. spin_unlock_irq(&phba->hbalock);
  3024. return 1;
  3025. }
  3026. spin_lock_irq(&phba->hbalock);
  3027. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3028. spin_unlock_irq(&phba->hbalock);
  3029. mempool_free(pmb, phba->mbox_mem_pool);
  3030. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3031. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3032. * 3 seconds we still set HBA_ERROR state because the status of the
  3033. * board is now undefined.
  3034. */
  3035. ha_copy = readl(phba->HAregaddr);
  3036. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3037. mdelay(100);
  3038. ha_copy = readl(phba->HAregaddr);
  3039. }
  3040. del_timer_sync(&psli->mbox_tmo);
  3041. if (ha_copy & HA_ERATT) {
  3042. writel(HA_ERATT, phba->HAregaddr);
  3043. phba->pport->stopped = 1;
  3044. }
  3045. spin_lock_irq(&phba->hbalock);
  3046. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3047. psli->mbox_active = NULL;
  3048. phba->link_flag &= ~LS_IGNORE_ERATT;
  3049. spin_unlock_irq(&phba->hbalock);
  3050. lpfc_hba_down_post(phba);
  3051. phba->link_state = LPFC_HBA_ERROR;
  3052. return ha_copy & HA_ERATT ? 0 : 1;
  3053. }
  3054. /**
  3055. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3056. * @phba: Pointer to HBA context object.
  3057. *
  3058. * This function resets the HBA by writing HC_INITFF to the control
  3059. * register. After the HBA resets, this function resets all the iocb ring
  3060. * indices. This function disables PCI layer parity checking during
  3061. * the reset.
  3062. * This function returns 0 always.
  3063. * The caller is not required to hold any locks.
  3064. **/
  3065. int
  3066. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3067. {
  3068. struct lpfc_sli *psli;
  3069. struct lpfc_sli_ring *pring;
  3070. uint16_t cfg_value;
  3071. int i;
  3072. psli = &phba->sli;
  3073. /* Reset HBA */
  3074. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3075. "0325 Reset HBA Data: x%x x%x\n",
  3076. phba->pport->port_state, psli->sli_flag);
  3077. /* perform board reset */
  3078. phba->fc_eventTag = 0;
  3079. phba->link_events = 0;
  3080. phba->pport->fc_myDID = 0;
  3081. phba->pport->fc_prevDID = 0;
  3082. /* Turn off parity checking and serr during the physical reset */
  3083. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3084. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3085. (cfg_value &
  3086. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3087. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3088. /* Now toggle INITFF bit in the Host Control Register */
  3089. writel(HC_INITFF, phba->HCregaddr);
  3090. mdelay(1);
  3091. readl(phba->HCregaddr); /* flush */
  3092. writel(0, phba->HCregaddr);
  3093. readl(phba->HCregaddr); /* flush */
  3094. /* Restore PCI cmd register */
  3095. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3096. /* Initialize relevant SLI info */
  3097. for (i = 0; i < psli->num_rings; i++) {
  3098. pring = &psli->ring[i];
  3099. pring->flag = 0;
  3100. pring->rspidx = 0;
  3101. pring->next_cmdidx = 0;
  3102. pring->local_getidx = 0;
  3103. pring->cmdidx = 0;
  3104. pring->missbufcnt = 0;
  3105. }
  3106. phba->link_state = LPFC_WARM_START;
  3107. return 0;
  3108. }
  3109. /**
  3110. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3111. * @phba: Pointer to HBA context object.
  3112. *
  3113. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3114. * checking during resets the device. The caller is not required to hold
  3115. * any locks.
  3116. *
  3117. * This function returns 0 always.
  3118. **/
  3119. int
  3120. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3121. {
  3122. struct lpfc_sli *psli = &phba->sli;
  3123. uint16_t cfg_value;
  3124. uint8_t qindx;
  3125. /* Reset HBA */
  3126. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3127. "0295 Reset HBA Data: x%x x%x\n",
  3128. phba->pport->port_state, psli->sli_flag);
  3129. /* perform board reset */
  3130. phba->fc_eventTag = 0;
  3131. phba->link_events = 0;
  3132. phba->pport->fc_myDID = 0;
  3133. phba->pport->fc_prevDID = 0;
  3134. /* Turn off parity checking and serr during the physical reset */
  3135. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3136. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3137. (cfg_value &
  3138. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3139. spin_lock_irq(&phba->hbalock);
  3140. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3141. phba->fcf.fcf_flag = 0;
  3142. /* Clean up the child queue list for the CQs */
  3143. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3144. list_del_init(&phba->sli4_hba.els_wq->list);
  3145. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3146. list_del_init(&phba->sli4_hba.dat_rq->list);
  3147. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3148. list_del_init(&phba->sli4_hba.els_cq->list);
  3149. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3150. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3151. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3152. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3153. spin_unlock_irq(&phba->hbalock);
  3154. /* Now physically reset the device */
  3155. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3156. "0389 Performing PCI function reset!\n");
  3157. /* Perform FCoE PCI function reset */
  3158. lpfc_pci_function_reset(phba);
  3159. return 0;
  3160. }
  3161. /**
  3162. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3163. * @phba: Pointer to HBA context object.
  3164. *
  3165. * This function is called in the SLI initialization code path to
  3166. * restart the HBA. The caller is not required to hold any lock.
  3167. * This function writes MBX_RESTART mailbox command to the SLIM and
  3168. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3169. * function to free any pending commands. The function enables
  3170. * POST only during the first initialization. The function returns zero.
  3171. * The function does not guarantee completion of MBX_RESTART mailbox
  3172. * command before the return of this function.
  3173. **/
  3174. static int
  3175. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3176. {
  3177. MAILBOX_t *mb;
  3178. struct lpfc_sli *psli;
  3179. volatile uint32_t word0;
  3180. void __iomem *to_slim;
  3181. uint32_t hba_aer_enabled;
  3182. spin_lock_irq(&phba->hbalock);
  3183. /* Take PCIe device Advanced Error Reporting (AER) state */
  3184. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3185. psli = &phba->sli;
  3186. /* Restart HBA */
  3187. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3188. "0337 Restart HBA Data: x%x x%x\n",
  3189. phba->pport->port_state, psli->sli_flag);
  3190. word0 = 0;
  3191. mb = (MAILBOX_t *) &word0;
  3192. mb->mbxCommand = MBX_RESTART;
  3193. mb->mbxHc = 1;
  3194. lpfc_reset_barrier(phba);
  3195. to_slim = phba->MBslimaddr;
  3196. writel(*(uint32_t *) mb, to_slim);
  3197. readl(to_slim); /* flush */
  3198. /* Only skip post after fc_ffinit is completed */
  3199. if (phba->pport->port_state)
  3200. word0 = 1; /* This is really setting up word1 */
  3201. else
  3202. word0 = 0; /* This is really setting up word1 */
  3203. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3204. writel(*(uint32_t *) mb, to_slim);
  3205. readl(to_slim); /* flush */
  3206. lpfc_sli_brdreset(phba);
  3207. phba->pport->stopped = 0;
  3208. phba->link_state = LPFC_INIT_START;
  3209. phba->hba_flag = 0;
  3210. spin_unlock_irq(&phba->hbalock);
  3211. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3212. psli->stats_start = get_seconds();
  3213. /* Give the INITFF and Post time to settle. */
  3214. mdelay(100);
  3215. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3216. if (hba_aer_enabled)
  3217. pci_disable_pcie_error_reporting(phba->pcidev);
  3218. lpfc_hba_down_post(phba);
  3219. return 0;
  3220. }
  3221. /**
  3222. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3223. * @phba: Pointer to HBA context object.
  3224. *
  3225. * This function is called in the SLI initialization code path to restart
  3226. * a SLI4 HBA. The caller is not required to hold any lock.
  3227. * At the end of the function, it calls lpfc_hba_down_post function to
  3228. * free any pending commands.
  3229. **/
  3230. static int
  3231. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3232. {
  3233. struct lpfc_sli *psli = &phba->sli;
  3234. /* Restart HBA */
  3235. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3236. "0296 Restart HBA Data: x%x x%x\n",
  3237. phba->pport->port_state, psli->sli_flag);
  3238. lpfc_sli4_brdreset(phba);
  3239. spin_lock_irq(&phba->hbalock);
  3240. phba->pport->stopped = 0;
  3241. phba->link_state = LPFC_INIT_START;
  3242. phba->hba_flag = 0;
  3243. spin_unlock_irq(&phba->hbalock);
  3244. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3245. psli->stats_start = get_seconds();
  3246. lpfc_hba_down_post(phba);
  3247. return 0;
  3248. }
  3249. /**
  3250. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3251. * @phba: Pointer to HBA context object.
  3252. *
  3253. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3254. * API jump table function pointer from the lpfc_hba struct.
  3255. **/
  3256. int
  3257. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3258. {
  3259. return phba->lpfc_sli_brdrestart(phba);
  3260. }
  3261. /**
  3262. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3263. * @phba: Pointer to HBA context object.
  3264. *
  3265. * This function is called after a HBA restart to wait for successful
  3266. * restart of the HBA. Successful restart of the HBA is indicated by
  3267. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3268. * iteration, the function will restart the HBA again. The function returns
  3269. * zero if HBA successfully restarted else returns negative error code.
  3270. **/
  3271. static int
  3272. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3273. {
  3274. uint32_t status, i = 0;
  3275. /* Read the HBA Host Status Register */
  3276. status = readl(phba->HSregaddr);
  3277. /* Check status register to see what current state is */
  3278. i = 0;
  3279. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3280. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3281. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3282. * 4.
  3283. */
  3284. if (i++ >= 20) {
  3285. /* Adapter failed to init, timeout, status reg
  3286. <status> */
  3287. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3288. "0436 Adapter failed to init, "
  3289. "timeout, status reg x%x, "
  3290. "FW Data: A8 x%x AC x%x\n", status,
  3291. readl(phba->MBslimaddr + 0xa8),
  3292. readl(phba->MBslimaddr + 0xac));
  3293. phba->link_state = LPFC_HBA_ERROR;
  3294. return -ETIMEDOUT;
  3295. }
  3296. /* Check to see if any errors occurred during init */
  3297. if (status & HS_FFERM) {
  3298. /* ERROR: During chipset initialization */
  3299. /* Adapter failed to init, chipset, status reg
  3300. <status> */
  3301. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3302. "0437 Adapter failed to init, "
  3303. "chipset, status reg x%x, "
  3304. "FW Data: A8 x%x AC x%x\n", status,
  3305. readl(phba->MBslimaddr + 0xa8),
  3306. readl(phba->MBslimaddr + 0xac));
  3307. phba->link_state = LPFC_HBA_ERROR;
  3308. return -EIO;
  3309. }
  3310. if (i <= 5) {
  3311. msleep(10);
  3312. } else if (i <= 10) {
  3313. msleep(500);
  3314. } else {
  3315. msleep(2500);
  3316. }
  3317. if (i == 15) {
  3318. /* Do post */
  3319. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3320. lpfc_sli_brdrestart(phba);
  3321. }
  3322. /* Read the HBA Host Status Register */
  3323. status = readl(phba->HSregaddr);
  3324. }
  3325. /* Check to see if any errors occurred during init */
  3326. if (status & HS_FFERM) {
  3327. /* ERROR: During chipset initialization */
  3328. /* Adapter failed to init, chipset, status reg <status> */
  3329. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3330. "0438 Adapter failed to init, chipset, "
  3331. "status reg x%x, "
  3332. "FW Data: A8 x%x AC x%x\n", status,
  3333. readl(phba->MBslimaddr + 0xa8),
  3334. readl(phba->MBslimaddr + 0xac));
  3335. phba->link_state = LPFC_HBA_ERROR;
  3336. return -EIO;
  3337. }
  3338. /* Clear all interrupt enable conditions */
  3339. writel(0, phba->HCregaddr);
  3340. readl(phba->HCregaddr); /* flush */
  3341. /* setup host attn register */
  3342. writel(0xffffffff, phba->HAregaddr);
  3343. readl(phba->HAregaddr); /* flush */
  3344. return 0;
  3345. }
  3346. /**
  3347. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3348. *
  3349. * This function calculates and returns the number of HBQs required to be
  3350. * configured.
  3351. **/
  3352. int
  3353. lpfc_sli_hbq_count(void)
  3354. {
  3355. return ARRAY_SIZE(lpfc_hbq_defs);
  3356. }
  3357. /**
  3358. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3359. *
  3360. * This function adds the number of hbq entries in every HBQ to get
  3361. * the total number of hbq entries required for the HBA and returns
  3362. * the total count.
  3363. **/
  3364. static int
  3365. lpfc_sli_hbq_entry_count(void)
  3366. {
  3367. int hbq_count = lpfc_sli_hbq_count();
  3368. int count = 0;
  3369. int i;
  3370. for (i = 0; i < hbq_count; ++i)
  3371. count += lpfc_hbq_defs[i]->entry_count;
  3372. return count;
  3373. }
  3374. /**
  3375. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3376. *
  3377. * This function calculates amount of memory required for all hbq entries
  3378. * to be configured and returns the total memory required.
  3379. **/
  3380. int
  3381. lpfc_sli_hbq_size(void)
  3382. {
  3383. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3384. }
  3385. /**
  3386. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3387. * @phba: Pointer to HBA context object.
  3388. *
  3389. * This function is called during the SLI initialization to configure
  3390. * all the HBQs and post buffers to the HBQ. The caller is not
  3391. * required to hold any locks. This function will return zero if successful
  3392. * else it will return negative error code.
  3393. **/
  3394. static int
  3395. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3396. {
  3397. int hbq_count = lpfc_sli_hbq_count();
  3398. LPFC_MBOXQ_t *pmb;
  3399. MAILBOX_t *pmbox;
  3400. uint32_t hbqno;
  3401. uint32_t hbq_entry_index;
  3402. /* Get a Mailbox buffer to setup mailbox
  3403. * commands for HBA initialization
  3404. */
  3405. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3406. if (!pmb)
  3407. return -ENOMEM;
  3408. pmbox = &pmb->u.mb;
  3409. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3410. phba->link_state = LPFC_INIT_MBX_CMDS;
  3411. phba->hbq_in_use = 1;
  3412. hbq_entry_index = 0;
  3413. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3414. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3415. phba->hbqs[hbqno].hbqPutIdx = 0;
  3416. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3417. phba->hbqs[hbqno].entry_count =
  3418. lpfc_hbq_defs[hbqno]->entry_count;
  3419. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3420. hbq_entry_index, pmb);
  3421. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3422. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3423. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3424. mbxStatus <status>, ring <num> */
  3425. lpfc_printf_log(phba, KERN_ERR,
  3426. LOG_SLI | LOG_VPORT,
  3427. "1805 Adapter failed to init. "
  3428. "Data: x%x x%x x%x\n",
  3429. pmbox->mbxCommand,
  3430. pmbox->mbxStatus, hbqno);
  3431. phba->link_state = LPFC_HBA_ERROR;
  3432. mempool_free(pmb, phba->mbox_mem_pool);
  3433. return ENXIO;
  3434. }
  3435. }
  3436. phba->hbq_count = hbq_count;
  3437. mempool_free(pmb, phba->mbox_mem_pool);
  3438. /* Initially populate or replenish the HBQs */
  3439. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3440. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3441. return 0;
  3442. }
  3443. /**
  3444. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3445. * @phba: Pointer to HBA context object.
  3446. *
  3447. * This function is called during the SLI initialization to configure
  3448. * all the HBQs and post buffers to the HBQ. The caller is not
  3449. * required to hold any locks. This function will return zero if successful
  3450. * else it will return negative error code.
  3451. **/
  3452. static int
  3453. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3454. {
  3455. phba->hbq_in_use = 1;
  3456. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3457. phba->hbq_count = 1;
  3458. /* Initially populate or replenish the HBQs */
  3459. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3460. return 0;
  3461. }
  3462. /**
  3463. * lpfc_sli_config_port - Issue config port mailbox command
  3464. * @phba: Pointer to HBA context object.
  3465. * @sli_mode: sli mode - 2/3
  3466. *
  3467. * This function is called by the sli intialization code path
  3468. * to issue config_port mailbox command. This function restarts the
  3469. * HBA firmware and issues a config_port mailbox command to configure
  3470. * the SLI interface in the sli mode specified by sli_mode
  3471. * variable. The caller is not required to hold any locks.
  3472. * The function returns 0 if successful, else returns negative error
  3473. * code.
  3474. **/
  3475. int
  3476. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3477. {
  3478. LPFC_MBOXQ_t *pmb;
  3479. uint32_t resetcount = 0, rc = 0, done = 0;
  3480. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3481. if (!pmb) {
  3482. phba->link_state = LPFC_HBA_ERROR;
  3483. return -ENOMEM;
  3484. }
  3485. phba->sli_rev = sli_mode;
  3486. while (resetcount < 2 && !done) {
  3487. spin_lock_irq(&phba->hbalock);
  3488. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3489. spin_unlock_irq(&phba->hbalock);
  3490. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3491. lpfc_sli_brdrestart(phba);
  3492. rc = lpfc_sli_chipset_init(phba);
  3493. if (rc)
  3494. break;
  3495. spin_lock_irq(&phba->hbalock);
  3496. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3497. spin_unlock_irq(&phba->hbalock);
  3498. resetcount++;
  3499. /* Call pre CONFIG_PORT mailbox command initialization. A
  3500. * value of 0 means the call was successful. Any other
  3501. * nonzero value is a failure, but if ERESTART is returned,
  3502. * the driver may reset the HBA and try again.
  3503. */
  3504. rc = lpfc_config_port_prep(phba);
  3505. if (rc == -ERESTART) {
  3506. phba->link_state = LPFC_LINK_UNKNOWN;
  3507. continue;
  3508. } else if (rc)
  3509. break;
  3510. phba->link_state = LPFC_INIT_MBX_CMDS;
  3511. lpfc_config_port(phba, pmb);
  3512. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3513. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3514. LPFC_SLI3_HBQ_ENABLED |
  3515. LPFC_SLI3_CRP_ENABLED |
  3516. LPFC_SLI3_INB_ENABLED |
  3517. LPFC_SLI3_BG_ENABLED);
  3518. if (rc != MBX_SUCCESS) {
  3519. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3520. "0442 Adapter failed to init, mbxCmd x%x "
  3521. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3522. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3523. spin_lock_irq(&phba->hbalock);
  3524. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3525. spin_unlock_irq(&phba->hbalock);
  3526. rc = -ENXIO;
  3527. } else {
  3528. /* Allow asynchronous mailbox command to go through */
  3529. spin_lock_irq(&phba->hbalock);
  3530. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3531. spin_unlock_irq(&phba->hbalock);
  3532. done = 1;
  3533. }
  3534. }
  3535. if (!done) {
  3536. rc = -EINVAL;
  3537. goto do_prep_failed;
  3538. }
  3539. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3540. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3541. rc = -ENXIO;
  3542. goto do_prep_failed;
  3543. }
  3544. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3545. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3546. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3547. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3548. phba->max_vpi : phba->max_vports;
  3549. } else
  3550. phba->max_vpi = 0;
  3551. if (pmb->u.mb.un.varCfgPort.gdss)
  3552. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3553. if (pmb->u.mb.un.varCfgPort.gerbm)
  3554. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3555. if (pmb->u.mb.un.varCfgPort.gcrp)
  3556. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3557. if (pmb->u.mb.un.varCfgPort.ginb) {
  3558. phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
  3559. phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get;
  3560. phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
  3561. phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
  3562. phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
  3563. phba->inb_last_counter =
  3564. phba->mbox->us.s3_inb_pgp.counter;
  3565. } else {
  3566. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3567. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3568. phba->inb_ha_copy = NULL;
  3569. phba->inb_counter = NULL;
  3570. }
  3571. if (phba->cfg_enable_bg) {
  3572. if (pmb->u.mb.un.varCfgPort.gbg)
  3573. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3574. else
  3575. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3576. "0443 Adapter did not grant "
  3577. "BlockGuard\n");
  3578. }
  3579. } else {
  3580. phba->hbq_get = NULL;
  3581. phba->port_gp = phba->mbox->us.s2.port;
  3582. phba->inb_ha_copy = NULL;
  3583. phba->inb_counter = NULL;
  3584. phba->max_vpi = 0;
  3585. }
  3586. do_prep_failed:
  3587. mempool_free(pmb, phba->mbox_mem_pool);
  3588. return rc;
  3589. }
  3590. /**
  3591. * lpfc_sli_hba_setup - SLI intialization function
  3592. * @phba: Pointer to HBA context object.
  3593. *
  3594. * This function is the main SLI intialization function. This function
  3595. * is called by the HBA intialization code, HBA reset code and HBA
  3596. * error attention handler code. Caller is not required to hold any
  3597. * locks. This function issues config_port mailbox command to configure
  3598. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3599. * calls the config_port_post function to issue init_link mailbox
  3600. * command and to start the discovery. The function will return zero
  3601. * if successful, else it will return negative error code.
  3602. **/
  3603. int
  3604. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3605. {
  3606. uint32_t rc;
  3607. int mode = 3;
  3608. switch (lpfc_sli_mode) {
  3609. case 2:
  3610. if (phba->cfg_enable_npiv) {
  3611. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3612. "1824 NPIV enabled: Override lpfc_sli_mode "
  3613. "parameter (%d) to auto (0).\n",
  3614. lpfc_sli_mode);
  3615. break;
  3616. }
  3617. mode = 2;
  3618. break;
  3619. case 0:
  3620. case 3:
  3621. break;
  3622. default:
  3623. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3624. "1819 Unrecognized lpfc_sli_mode "
  3625. "parameter: %d.\n", lpfc_sli_mode);
  3626. break;
  3627. }
  3628. rc = lpfc_sli_config_port(phba, mode);
  3629. if (rc && lpfc_sli_mode == 3)
  3630. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3631. "1820 Unable to select SLI-3. "
  3632. "Not supported by adapter.\n");
  3633. if (rc && mode != 2)
  3634. rc = lpfc_sli_config_port(phba, 2);
  3635. if (rc)
  3636. goto lpfc_sli_hba_setup_error;
  3637. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  3638. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  3639. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  3640. if (!rc) {
  3641. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3642. "2709 This device supports "
  3643. "Advanced Error Reporting (AER)\n");
  3644. spin_lock_irq(&phba->hbalock);
  3645. phba->hba_flag |= HBA_AER_ENABLED;
  3646. spin_unlock_irq(&phba->hbalock);
  3647. } else {
  3648. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3649. "2708 This device does not support "
  3650. "Advanced Error Reporting (AER)\n");
  3651. phba->cfg_aer_support = 0;
  3652. }
  3653. }
  3654. if (phba->sli_rev == 3) {
  3655. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3656. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3657. } else {
  3658. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3659. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3660. phba->sli3_options = 0;
  3661. }
  3662. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3663. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3664. phba->sli_rev, phba->max_vpi);
  3665. rc = lpfc_sli_ring_map(phba);
  3666. if (rc)
  3667. goto lpfc_sli_hba_setup_error;
  3668. /* Init HBQs */
  3669. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3670. rc = lpfc_sli_hbq_setup(phba);
  3671. if (rc)
  3672. goto lpfc_sli_hba_setup_error;
  3673. }
  3674. spin_lock_irq(&phba->hbalock);
  3675. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3676. spin_unlock_irq(&phba->hbalock);
  3677. rc = lpfc_config_port_post(phba);
  3678. if (rc)
  3679. goto lpfc_sli_hba_setup_error;
  3680. return rc;
  3681. lpfc_sli_hba_setup_error:
  3682. phba->link_state = LPFC_HBA_ERROR;
  3683. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3684. "0445 Firmware initialization failed\n");
  3685. return rc;
  3686. }
  3687. /**
  3688. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3689. * @phba: Pointer to HBA context object.
  3690. * @mboxq: mailbox pointer.
  3691. * This function issue a dump mailbox command to read config region
  3692. * 23 and parse the records in the region and populate driver
  3693. * data structure.
  3694. **/
  3695. static int
  3696. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3697. LPFC_MBOXQ_t *mboxq)
  3698. {
  3699. struct lpfc_dmabuf *mp;
  3700. struct lpfc_mqe *mqe;
  3701. uint32_t data_length;
  3702. int rc;
  3703. /* Program the default value of vlan_id and fc_map */
  3704. phba->valid_vlan = 0;
  3705. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3706. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3707. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3708. mqe = &mboxq->u.mqe;
  3709. if (lpfc_dump_fcoe_param(phba, mboxq))
  3710. return -ENOMEM;
  3711. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3712. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3713. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3714. "(%d):2571 Mailbox cmd x%x Status x%x "
  3715. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3716. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3717. "CQ: x%x x%x x%x x%x\n",
  3718. mboxq->vport ? mboxq->vport->vpi : 0,
  3719. bf_get(lpfc_mqe_command, mqe),
  3720. bf_get(lpfc_mqe_status, mqe),
  3721. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3722. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3723. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3724. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3725. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3726. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3727. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3728. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3729. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3730. mboxq->mcqe.word0,
  3731. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3732. mboxq->mcqe.trailer);
  3733. if (rc) {
  3734. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3735. kfree(mp);
  3736. return -EIO;
  3737. }
  3738. data_length = mqe->un.mb_words[5];
  3739. if (data_length > DMP_RGN23_SIZE) {
  3740. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3741. kfree(mp);
  3742. return -EIO;
  3743. }
  3744. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3745. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3746. kfree(mp);
  3747. return 0;
  3748. }
  3749. /**
  3750. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3751. * @phba: pointer to lpfc hba data structure.
  3752. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3753. * @vpd: pointer to the memory to hold resulting port vpd data.
  3754. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3755. * On output, the number of data bytes in @vpd.
  3756. *
  3757. * This routine executes a READ_REV SLI4 mailbox command. In
  3758. * addition, this routine gets the port vpd data.
  3759. *
  3760. * Return codes
  3761. * 0 - successful
  3762. * ENOMEM - could not allocated memory.
  3763. **/
  3764. static int
  3765. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3766. uint8_t *vpd, uint32_t *vpd_size)
  3767. {
  3768. int rc = 0;
  3769. uint32_t dma_size;
  3770. struct lpfc_dmabuf *dmabuf;
  3771. struct lpfc_mqe *mqe;
  3772. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3773. if (!dmabuf)
  3774. return -ENOMEM;
  3775. /*
  3776. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3777. * mailbox command.
  3778. */
  3779. dma_size = *vpd_size;
  3780. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3781. dma_size,
  3782. &dmabuf->phys,
  3783. GFP_KERNEL);
  3784. if (!dmabuf->virt) {
  3785. kfree(dmabuf);
  3786. return -ENOMEM;
  3787. }
  3788. memset(dmabuf->virt, 0, dma_size);
  3789. /*
  3790. * The SLI4 implementation of READ_REV conflicts at word1,
  3791. * bits 31:16 and SLI4 adds vpd functionality not present
  3792. * in SLI3. This code corrects the conflicts.
  3793. */
  3794. lpfc_read_rev(phba, mboxq);
  3795. mqe = &mboxq->u.mqe;
  3796. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3797. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3798. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3799. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3800. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3801. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3802. if (rc) {
  3803. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3804. dmabuf->virt, dmabuf->phys);
  3805. kfree(dmabuf);
  3806. return -EIO;
  3807. }
  3808. /*
  3809. * The available vpd length cannot be bigger than the
  3810. * DMA buffer passed to the port. Catch the less than
  3811. * case and update the caller's size.
  3812. */
  3813. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3814. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3815. lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
  3816. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3817. dmabuf->virt, dmabuf->phys);
  3818. kfree(dmabuf);
  3819. return 0;
  3820. }
  3821. /**
  3822. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3823. * @phba: pointer to lpfc hba data structure.
  3824. *
  3825. * This routine is called to explicitly arm the SLI4 device's completion and
  3826. * event queues
  3827. **/
  3828. static void
  3829. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3830. {
  3831. uint8_t fcp_eqidx;
  3832. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3833. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3834. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3835. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3836. LPFC_QUEUE_REARM);
  3837. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3838. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3839. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3840. LPFC_QUEUE_REARM);
  3841. }
  3842. /**
  3843. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3844. * @phba: Pointer to HBA context object.
  3845. *
  3846. * This function is the main SLI4 device intialization PCI function. This
  3847. * function is called by the HBA intialization code, HBA reset code and
  3848. * HBA error attention handler code. Caller is not required to hold any
  3849. * locks.
  3850. **/
  3851. int
  3852. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3853. {
  3854. int rc;
  3855. LPFC_MBOXQ_t *mboxq;
  3856. struct lpfc_mqe *mqe;
  3857. uint8_t *vpd;
  3858. uint32_t vpd_size;
  3859. uint32_t ftr_rsp = 0;
  3860. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3861. struct lpfc_vport *vport = phba->pport;
  3862. struct lpfc_dmabuf *mp;
  3863. /* Perform a PCI function reset to start from clean */
  3864. rc = lpfc_pci_function_reset(phba);
  3865. if (unlikely(rc))
  3866. return -ENODEV;
  3867. /* Check the HBA Host Status Register for readyness */
  3868. rc = lpfc_sli4_post_status_check(phba);
  3869. if (unlikely(rc))
  3870. return -ENODEV;
  3871. else {
  3872. spin_lock_irq(&phba->hbalock);
  3873. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3874. spin_unlock_irq(&phba->hbalock);
  3875. }
  3876. /*
  3877. * Allocate a single mailbox container for initializing the
  3878. * port.
  3879. */
  3880. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3881. if (!mboxq)
  3882. return -ENOMEM;
  3883. /*
  3884. * Continue initialization with default values even if driver failed
  3885. * to read FCoE param config regions
  3886. */
  3887. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3888. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3889. "2570 Failed to read FCoE parameters\n");
  3890. /* Issue READ_REV to collect vpd and FW information. */
  3891. vpd_size = PAGE_SIZE;
  3892. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3893. if (!vpd) {
  3894. rc = -ENOMEM;
  3895. goto out_free_mbox;
  3896. }
  3897. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3898. if (unlikely(rc))
  3899. goto out_free_vpd;
  3900. mqe = &mboxq->u.mqe;
  3901. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3902. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3903. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3904. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  3905. LPFC_DCBX_CEE_MODE)
  3906. phba->hba_flag |= HBA_FIP_SUPPORT;
  3907. else
  3908. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  3909. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3910. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3911. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3912. "0376 READ_REV Error. SLI Level %d "
  3913. "FCoE enabled %d\n",
  3914. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3915. rc = -EIO;
  3916. goto out_free_vpd;
  3917. }
  3918. /*
  3919. * Evaluate the read rev and vpd data. Populate the driver
  3920. * state with the results. If this routine fails, the failure
  3921. * is not fatal as the driver will use generic values.
  3922. */
  3923. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3924. if (unlikely(!rc)) {
  3925. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3926. "0377 Error %d parsing vpd. "
  3927. "Using defaults.\n", rc);
  3928. rc = 0;
  3929. }
  3930. /* Save information as VPD data */
  3931. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3932. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3933. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3934. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3935. &mqe->un.read_rev);
  3936. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3937. &mqe->un.read_rev);
  3938. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3939. &mqe->un.read_rev);
  3940. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3941. &mqe->un.read_rev);
  3942. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3943. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3944. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3945. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3946. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3947. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3948. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3949. "(%d):0380 READ_REV Status x%x "
  3950. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3951. mboxq->vport ? mboxq->vport->vpi : 0,
  3952. bf_get(lpfc_mqe_status, mqe),
  3953. phba->vpd.rev.opFwName,
  3954. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3955. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3956. /*
  3957. * Discover the port's supported feature set and match it against the
  3958. * hosts requests.
  3959. */
  3960. lpfc_request_features(phba, mboxq);
  3961. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3962. if (unlikely(rc)) {
  3963. rc = -EIO;
  3964. goto out_free_vpd;
  3965. }
  3966. /*
  3967. * The port must support FCP initiator mode as this is the
  3968. * only mode running in the host.
  3969. */
  3970. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3971. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3972. "0378 No support for fcpi mode.\n");
  3973. ftr_rsp++;
  3974. }
  3975. /*
  3976. * If the port cannot support the host's requested features
  3977. * then turn off the global config parameters to disable the
  3978. * feature in the driver. This is not a fatal error.
  3979. */
  3980. if ((phba->cfg_enable_bg) &&
  3981. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3982. ftr_rsp++;
  3983. if (phba->max_vpi && phba->cfg_enable_npiv &&
  3984. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3985. ftr_rsp++;
  3986. if (ftr_rsp) {
  3987. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3988. "0379 Feature Mismatch Data: x%08x %08x "
  3989. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  3990. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  3991. phba->cfg_enable_npiv, phba->max_vpi);
  3992. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3993. phba->cfg_enable_bg = 0;
  3994. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3995. phba->cfg_enable_npiv = 0;
  3996. }
  3997. /* These SLI3 features are assumed in SLI4 */
  3998. spin_lock_irq(&phba->hbalock);
  3999. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4000. spin_unlock_irq(&phba->hbalock);
  4001. /* Read the port's service parameters. */
  4002. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4003. if (rc) {
  4004. phba->link_state = LPFC_HBA_ERROR;
  4005. rc = -ENOMEM;
  4006. goto out_free_vpd;
  4007. }
  4008. mboxq->vport = vport;
  4009. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4010. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4011. if (rc == MBX_SUCCESS) {
  4012. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4013. rc = 0;
  4014. }
  4015. /*
  4016. * This memory was allocated by the lpfc_read_sparam routine. Release
  4017. * it to the mbuf pool.
  4018. */
  4019. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4020. kfree(mp);
  4021. mboxq->context1 = NULL;
  4022. if (unlikely(rc)) {
  4023. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4024. "0382 READ_SPARAM command failed "
  4025. "status %d, mbxStatus x%x\n",
  4026. rc, bf_get(lpfc_mqe_status, mqe));
  4027. phba->link_state = LPFC_HBA_ERROR;
  4028. rc = -EIO;
  4029. goto out_free_vpd;
  4030. }
  4031. if (phba->cfg_soft_wwnn)
  4032. u64_to_wwn(phba->cfg_soft_wwnn,
  4033. vport->fc_sparam.nodeName.u.wwn);
  4034. if (phba->cfg_soft_wwpn)
  4035. u64_to_wwn(phba->cfg_soft_wwpn,
  4036. vport->fc_sparam.portName.u.wwn);
  4037. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4038. sizeof(struct lpfc_name));
  4039. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4040. sizeof(struct lpfc_name));
  4041. /* Update the fc_host data structures with new wwn. */
  4042. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4043. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4044. /* Register SGL pool to the device using non-embedded mailbox command */
  4045. rc = lpfc_sli4_post_sgl_list(phba);
  4046. if (unlikely(rc)) {
  4047. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4048. "0582 Error %d during sgl post operation\n",
  4049. rc);
  4050. rc = -ENODEV;
  4051. goto out_free_vpd;
  4052. }
  4053. /* Register SCSI SGL pool to the device */
  4054. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4055. if (unlikely(rc)) {
  4056. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4057. "0383 Error %d during scsi sgl post "
  4058. "operation\n", rc);
  4059. /* Some Scsi buffers were moved to the abort scsi list */
  4060. /* A pci function reset will repost them */
  4061. rc = -ENODEV;
  4062. goto out_free_vpd;
  4063. }
  4064. /* Post the rpi header region to the device. */
  4065. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4066. if (unlikely(rc)) {
  4067. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4068. "0393 Error %d during rpi post operation\n",
  4069. rc);
  4070. rc = -ENODEV;
  4071. goto out_free_vpd;
  4072. }
  4073. /* Set up all the queues to the device */
  4074. rc = lpfc_sli4_queue_setup(phba);
  4075. if (unlikely(rc)) {
  4076. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4077. "0381 Error %d during queue setup.\n ", rc);
  4078. goto out_stop_timers;
  4079. }
  4080. /* Arm the CQs and then EQs on device */
  4081. lpfc_sli4_arm_cqeq_intr(phba);
  4082. /* Indicate device interrupt mode */
  4083. phba->sli4_hba.intr_enable = 1;
  4084. /* Allow asynchronous mailbox command to go through */
  4085. spin_lock_irq(&phba->hbalock);
  4086. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4087. spin_unlock_irq(&phba->hbalock);
  4088. /* Post receive buffers to the device */
  4089. lpfc_sli4_rb_setup(phba);
  4090. /* Reset HBA FCF states after HBA reset */
  4091. phba->fcf.fcf_flag = 0;
  4092. phba->fcf.current_rec.flag = 0;
  4093. /* Start the ELS watchdog timer */
  4094. mod_timer(&vport->els_tmofunc,
  4095. jiffies + HZ * (phba->fc_ratov * 2));
  4096. /* Start heart beat timer */
  4097. mod_timer(&phba->hb_tmofunc,
  4098. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4099. phba->hb_outstanding = 0;
  4100. phba->last_completion_time = jiffies;
  4101. /* Start error attention (ERATT) polling timer */
  4102. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4103. /*
  4104. * The port is ready, set the host's link state to LINK_DOWN
  4105. * in preparation for link interrupts.
  4106. */
  4107. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4108. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4109. lpfc_set_loopback_flag(phba);
  4110. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4111. spin_lock_irq(&phba->hbalock);
  4112. phba->link_state = LPFC_LINK_DOWN;
  4113. spin_unlock_irq(&phba->hbalock);
  4114. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4115. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4116. kfree(vpd);
  4117. return 0;
  4118. } else
  4119. rc = -EIO;
  4120. /* Unset all the queues set up in this routine when error out */
  4121. if (rc)
  4122. lpfc_sli4_queue_unset(phba);
  4123. out_stop_timers:
  4124. if (rc)
  4125. lpfc_stop_hba_timers(phba);
  4126. out_free_vpd:
  4127. kfree(vpd);
  4128. out_free_mbox:
  4129. mempool_free(mboxq, phba->mbox_mem_pool);
  4130. return rc;
  4131. }
  4132. /**
  4133. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4134. * @ptr: context object - pointer to hba structure.
  4135. *
  4136. * This is the callback function for mailbox timer. The mailbox
  4137. * timer is armed when a new mailbox command is issued and the timer
  4138. * is deleted when the mailbox complete. The function is called by
  4139. * the kernel timer code when a mailbox does not complete within
  4140. * expected time. This function wakes up the worker thread to
  4141. * process the mailbox timeout and returns. All the processing is
  4142. * done by the worker thread function lpfc_mbox_timeout_handler.
  4143. **/
  4144. void
  4145. lpfc_mbox_timeout(unsigned long ptr)
  4146. {
  4147. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4148. unsigned long iflag;
  4149. uint32_t tmo_posted;
  4150. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4151. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4152. if (!tmo_posted)
  4153. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4154. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4155. if (!tmo_posted)
  4156. lpfc_worker_wake_up(phba);
  4157. return;
  4158. }
  4159. /**
  4160. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4161. * @phba: Pointer to HBA context object.
  4162. *
  4163. * This function is called from worker thread when a mailbox command times out.
  4164. * The caller is not required to hold any locks. This function will reset the
  4165. * HBA and recover all the pending commands.
  4166. **/
  4167. void
  4168. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4169. {
  4170. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4171. MAILBOX_t *mb = &pmbox->u.mb;
  4172. struct lpfc_sli *psli = &phba->sli;
  4173. struct lpfc_sli_ring *pring;
  4174. /* Check the pmbox pointer first. There is a race condition
  4175. * between the mbox timeout handler getting executed in the
  4176. * worklist and the mailbox actually completing. When this
  4177. * race condition occurs, the mbox_active will be NULL.
  4178. */
  4179. spin_lock_irq(&phba->hbalock);
  4180. if (pmbox == NULL) {
  4181. lpfc_printf_log(phba, KERN_WARNING,
  4182. LOG_MBOX | LOG_SLI,
  4183. "0353 Active Mailbox cleared - mailbox timeout "
  4184. "exiting\n");
  4185. spin_unlock_irq(&phba->hbalock);
  4186. return;
  4187. }
  4188. /* Mbox cmd <mbxCommand> timeout */
  4189. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4190. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4191. mb->mbxCommand,
  4192. phba->pport->port_state,
  4193. phba->sli.sli_flag,
  4194. phba->sli.mbox_active);
  4195. spin_unlock_irq(&phba->hbalock);
  4196. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4197. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4198. * it to fail all oustanding SCSI IO.
  4199. */
  4200. spin_lock_irq(&phba->pport->work_port_lock);
  4201. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4202. spin_unlock_irq(&phba->pport->work_port_lock);
  4203. spin_lock_irq(&phba->hbalock);
  4204. phba->link_state = LPFC_LINK_UNKNOWN;
  4205. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4206. spin_unlock_irq(&phba->hbalock);
  4207. pring = &psli->ring[psli->fcp_ring];
  4208. lpfc_sli_abort_iocb_ring(phba, pring);
  4209. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4210. "0345 Resetting board due to mailbox timeout\n");
  4211. /* Reset the HBA device */
  4212. lpfc_reset_hba(phba);
  4213. }
  4214. /**
  4215. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4216. * @phba: Pointer to HBA context object.
  4217. * @pmbox: Pointer to mailbox object.
  4218. * @flag: Flag indicating how the mailbox need to be processed.
  4219. *
  4220. * This function is called by discovery code and HBA management code
  4221. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4222. * function gets the hbalock to protect the data structures.
  4223. * The mailbox command can be submitted in polling mode, in which case
  4224. * this function will wait in a polling loop for the completion of the
  4225. * mailbox.
  4226. * If the mailbox is submitted in no_wait mode (not polling) the
  4227. * function will submit the command and returns immediately without waiting
  4228. * for the mailbox completion. The no_wait is supported only when HBA
  4229. * is in SLI2/SLI3 mode - interrupts are enabled.
  4230. * The SLI interface allows only one mailbox pending at a time. If the
  4231. * mailbox is issued in polling mode and there is already a mailbox
  4232. * pending, then the function will return an error. If the mailbox is issued
  4233. * in NO_WAIT mode and there is a mailbox pending already, the function
  4234. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4235. * The sli layer owns the mailbox object until the completion of mailbox
  4236. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4237. * return codes the caller owns the mailbox command after the return of
  4238. * the function.
  4239. **/
  4240. static int
  4241. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4242. uint32_t flag)
  4243. {
  4244. MAILBOX_t *mb;
  4245. struct lpfc_sli *psli = &phba->sli;
  4246. uint32_t status, evtctr;
  4247. uint32_t ha_copy;
  4248. int i;
  4249. unsigned long timeout;
  4250. unsigned long drvr_flag = 0;
  4251. uint32_t word0, ldata;
  4252. void __iomem *to_slim;
  4253. int processing_queue = 0;
  4254. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4255. if (!pmbox) {
  4256. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4257. /* processing mbox queue from intr_handler */
  4258. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4259. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4260. return MBX_SUCCESS;
  4261. }
  4262. processing_queue = 1;
  4263. pmbox = lpfc_mbox_get(phba);
  4264. if (!pmbox) {
  4265. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4266. return MBX_SUCCESS;
  4267. }
  4268. }
  4269. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4270. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4271. if(!pmbox->vport) {
  4272. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4273. lpfc_printf_log(phba, KERN_ERR,
  4274. LOG_MBOX | LOG_VPORT,
  4275. "1806 Mbox x%x failed. No vport\n",
  4276. pmbox->u.mb.mbxCommand);
  4277. dump_stack();
  4278. goto out_not_finished;
  4279. }
  4280. }
  4281. /* If the PCI channel is in offline state, do not post mbox. */
  4282. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4283. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4284. goto out_not_finished;
  4285. }
  4286. /* If HBA has a deferred error attention, fail the iocb. */
  4287. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4288. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4289. goto out_not_finished;
  4290. }
  4291. psli = &phba->sli;
  4292. mb = &pmbox->u.mb;
  4293. status = MBX_SUCCESS;
  4294. if (phba->link_state == LPFC_HBA_ERROR) {
  4295. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4296. /* Mbox command <mbxCommand> cannot issue */
  4297. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4298. "(%d):0311 Mailbox command x%x cannot "
  4299. "issue Data: x%x x%x\n",
  4300. pmbox->vport ? pmbox->vport->vpi : 0,
  4301. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4302. goto out_not_finished;
  4303. }
  4304. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4305. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4306. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4307. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4308. "(%d):2528 Mailbox command x%x cannot "
  4309. "issue Data: x%x x%x\n",
  4310. pmbox->vport ? pmbox->vport->vpi : 0,
  4311. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4312. goto out_not_finished;
  4313. }
  4314. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4315. /* Polling for a mbox command when another one is already active
  4316. * is not allowed in SLI. Also, the driver must have established
  4317. * SLI2 mode to queue and process multiple mbox commands.
  4318. */
  4319. if (flag & MBX_POLL) {
  4320. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4321. /* Mbox command <mbxCommand> cannot issue */
  4322. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4323. "(%d):2529 Mailbox command x%x "
  4324. "cannot issue Data: x%x x%x\n",
  4325. pmbox->vport ? pmbox->vport->vpi : 0,
  4326. pmbox->u.mb.mbxCommand,
  4327. psli->sli_flag, flag);
  4328. goto out_not_finished;
  4329. }
  4330. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4331. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4332. /* Mbox command <mbxCommand> cannot issue */
  4333. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4334. "(%d):2530 Mailbox command x%x "
  4335. "cannot issue Data: x%x x%x\n",
  4336. pmbox->vport ? pmbox->vport->vpi : 0,
  4337. pmbox->u.mb.mbxCommand,
  4338. psli->sli_flag, flag);
  4339. goto out_not_finished;
  4340. }
  4341. /* Another mailbox command is still being processed, queue this
  4342. * command to be processed later.
  4343. */
  4344. lpfc_mbox_put(phba, pmbox);
  4345. /* Mbox cmd issue - BUSY */
  4346. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4347. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4348. "x%x x%x x%x x%x\n",
  4349. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4350. mb->mbxCommand, phba->pport->port_state,
  4351. psli->sli_flag, flag);
  4352. psli->slistat.mbox_busy++;
  4353. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4354. if (pmbox->vport) {
  4355. lpfc_debugfs_disc_trc(pmbox->vport,
  4356. LPFC_DISC_TRC_MBOX_VPORT,
  4357. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4358. (uint32_t)mb->mbxCommand,
  4359. mb->un.varWords[0], mb->un.varWords[1]);
  4360. }
  4361. else {
  4362. lpfc_debugfs_disc_trc(phba->pport,
  4363. LPFC_DISC_TRC_MBOX,
  4364. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4365. (uint32_t)mb->mbxCommand,
  4366. mb->un.varWords[0], mb->un.varWords[1]);
  4367. }
  4368. return MBX_BUSY;
  4369. }
  4370. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4371. /* If we are not polling, we MUST be in SLI2 mode */
  4372. if (flag != MBX_POLL) {
  4373. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4374. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4375. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4376. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4377. /* Mbox command <mbxCommand> cannot issue */
  4378. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4379. "(%d):2531 Mailbox command x%x "
  4380. "cannot issue Data: x%x x%x\n",
  4381. pmbox->vport ? pmbox->vport->vpi : 0,
  4382. pmbox->u.mb.mbxCommand,
  4383. psli->sli_flag, flag);
  4384. goto out_not_finished;
  4385. }
  4386. /* timeout active mbox command */
  4387. mod_timer(&psli->mbox_tmo, (jiffies +
  4388. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4389. }
  4390. /* Mailbox cmd <cmd> issue */
  4391. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4392. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4393. "x%x\n",
  4394. pmbox->vport ? pmbox->vport->vpi : 0,
  4395. mb->mbxCommand, phba->pport->port_state,
  4396. psli->sli_flag, flag);
  4397. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4398. if (pmbox->vport) {
  4399. lpfc_debugfs_disc_trc(pmbox->vport,
  4400. LPFC_DISC_TRC_MBOX_VPORT,
  4401. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4402. (uint32_t)mb->mbxCommand,
  4403. mb->un.varWords[0], mb->un.varWords[1]);
  4404. }
  4405. else {
  4406. lpfc_debugfs_disc_trc(phba->pport,
  4407. LPFC_DISC_TRC_MBOX,
  4408. "MBOX Send: cmd:x%x mb:x%x x%x",
  4409. (uint32_t)mb->mbxCommand,
  4410. mb->un.varWords[0], mb->un.varWords[1]);
  4411. }
  4412. }
  4413. psli->slistat.mbox_cmd++;
  4414. evtctr = psli->slistat.mbox_event;
  4415. /* next set own bit for the adapter and copy over command word */
  4416. mb->mbxOwner = OWN_CHIP;
  4417. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4418. /* First copy command data to host SLIM area */
  4419. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4420. } else {
  4421. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4422. /* copy command data into host mbox for cmpl */
  4423. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4424. }
  4425. /* First copy mbox command data to HBA SLIM, skip past first
  4426. word */
  4427. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4428. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4429. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4430. /* Next copy over first word, with mbxOwner set */
  4431. ldata = *((uint32_t *)mb);
  4432. to_slim = phba->MBslimaddr;
  4433. writel(ldata, to_slim);
  4434. readl(to_slim); /* flush */
  4435. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4436. /* switch over to host mailbox */
  4437. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4438. }
  4439. }
  4440. wmb();
  4441. switch (flag) {
  4442. case MBX_NOWAIT:
  4443. /* Set up reference to mailbox command */
  4444. psli->mbox_active = pmbox;
  4445. /* Interrupt board to do it */
  4446. writel(CA_MBATT, phba->CAregaddr);
  4447. readl(phba->CAregaddr); /* flush */
  4448. /* Don't wait for it to finish, just return */
  4449. break;
  4450. case MBX_POLL:
  4451. /* Set up null reference to mailbox command */
  4452. psli->mbox_active = NULL;
  4453. /* Interrupt board to do it */
  4454. writel(CA_MBATT, phba->CAregaddr);
  4455. readl(phba->CAregaddr); /* flush */
  4456. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4457. /* First read mbox status word */
  4458. word0 = *((uint32_t *)phba->mbox);
  4459. word0 = le32_to_cpu(word0);
  4460. } else {
  4461. /* First read mbox status word */
  4462. word0 = readl(phba->MBslimaddr);
  4463. }
  4464. /* Read the HBA Host Attention Register */
  4465. ha_copy = readl(phba->HAregaddr);
  4466. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4467. mb->mbxCommand) *
  4468. 1000) + jiffies;
  4469. i = 0;
  4470. /* Wait for command to complete */
  4471. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4472. (!(ha_copy & HA_MBATT) &&
  4473. (phba->link_state > LPFC_WARM_START))) {
  4474. if (time_after(jiffies, timeout)) {
  4475. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4476. spin_unlock_irqrestore(&phba->hbalock,
  4477. drvr_flag);
  4478. goto out_not_finished;
  4479. }
  4480. /* Check if we took a mbox interrupt while we were
  4481. polling */
  4482. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4483. && (evtctr != psli->slistat.mbox_event))
  4484. break;
  4485. if (i++ > 10) {
  4486. spin_unlock_irqrestore(&phba->hbalock,
  4487. drvr_flag);
  4488. msleep(1);
  4489. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4490. }
  4491. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4492. /* First copy command data */
  4493. word0 = *((uint32_t *)phba->mbox);
  4494. word0 = le32_to_cpu(word0);
  4495. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4496. MAILBOX_t *slimmb;
  4497. uint32_t slimword0;
  4498. /* Check real SLIM for any errors */
  4499. slimword0 = readl(phba->MBslimaddr);
  4500. slimmb = (MAILBOX_t *) & slimword0;
  4501. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4502. && slimmb->mbxStatus) {
  4503. psli->sli_flag &=
  4504. ~LPFC_SLI_ACTIVE;
  4505. word0 = slimword0;
  4506. }
  4507. }
  4508. } else {
  4509. /* First copy command data */
  4510. word0 = readl(phba->MBslimaddr);
  4511. }
  4512. /* Read the HBA Host Attention Register */
  4513. ha_copy = readl(phba->HAregaddr);
  4514. }
  4515. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4516. /* copy results back to user */
  4517. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4518. } else {
  4519. /* First copy command data */
  4520. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4521. MAILBOX_CMD_SIZE);
  4522. if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
  4523. pmbox->context2) {
  4524. lpfc_memcpy_from_slim((void *)pmbox->context2,
  4525. phba->MBslimaddr + DMP_RSP_OFFSET,
  4526. mb->un.varDmp.word_cnt);
  4527. }
  4528. }
  4529. writel(HA_MBATT, phba->HAregaddr);
  4530. readl(phba->HAregaddr); /* flush */
  4531. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4532. status = mb->mbxStatus;
  4533. }
  4534. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4535. return status;
  4536. out_not_finished:
  4537. if (processing_queue) {
  4538. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4539. lpfc_mbox_cmpl_put(phba, pmbox);
  4540. }
  4541. return MBX_NOT_FINISHED;
  4542. }
  4543. /**
  4544. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4545. * @phba: Pointer to HBA context object.
  4546. *
  4547. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4548. * the driver internal pending mailbox queue. It will then try to wait out the
  4549. * possible outstanding mailbox command before return.
  4550. *
  4551. * Returns:
  4552. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4553. * the outstanding mailbox command timed out.
  4554. **/
  4555. static int
  4556. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4557. {
  4558. struct lpfc_sli *psli = &phba->sli;
  4559. uint8_t actcmd = MBX_HEARTBEAT;
  4560. int rc = 0;
  4561. unsigned long timeout;
  4562. /* Mark the asynchronous mailbox command posting as blocked */
  4563. spin_lock_irq(&phba->hbalock);
  4564. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4565. if (phba->sli.mbox_active)
  4566. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4567. spin_unlock_irq(&phba->hbalock);
  4568. /* Determine how long we might wait for the active mailbox
  4569. * command to be gracefully completed by firmware.
  4570. */
  4571. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4572. jiffies;
  4573. /* Wait for the outstnading mailbox command to complete */
  4574. while (phba->sli.mbox_active) {
  4575. /* Check active mailbox complete status every 2ms */
  4576. msleep(2);
  4577. if (time_after(jiffies, timeout)) {
  4578. /* Timeout, marked the outstanding cmd not complete */
  4579. rc = 1;
  4580. break;
  4581. }
  4582. }
  4583. /* Can not cleanly block async mailbox command, fails it */
  4584. if (rc) {
  4585. spin_lock_irq(&phba->hbalock);
  4586. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4587. spin_unlock_irq(&phba->hbalock);
  4588. }
  4589. return rc;
  4590. }
  4591. /**
  4592. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4593. * @phba: Pointer to HBA context object.
  4594. *
  4595. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4596. * commands from the driver internal pending mailbox queue. It makes sure
  4597. * that there is no outstanding mailbox command before resuming posting
  4598. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4599. * mailbox command, it will try to wait it out before resuming asynchronous
  4600. * mailbox command posting.
  4601. **/
  4602. static void
  4603. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4604. {
  4605. struct lpfc_sli *psli = &phba->sli;
  4606. spin_lock_irq(&phba->hbalock);
  4607. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4608. /* Asynchronous mailbox posting is not blocked, do nothing */
  4609. spin_unlock_irq(&phba->hbalock);
  4610. return;
  4611. }
  4612. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4613. * successful or timeout, after timing-out the outstanding mailbox
  4614. * command shall always be removed, so just unblock posting async
  4615. * mailbox command and resume
  4616. */
  4617. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4618. spin_unlock_irq(&phba->hbalock);
  4619. /* wake up worker thread to post asynchronlous mailbox command */
  4620. lpfc_worker_wake_up(phba);
  4621. }
  4622. /**
  4623. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4624. * @phba: Pointer to HBA context object.
  4625. * @mboxq: Pointer to mailbox object.
  4626. *
  4627. * The function posts a mailbox to the port. The mailbox is expected
  4628. * to be comletely filled in and ready for the port to operate on it.
  4629. * This routine executes a synchronous completion operation on the
  4630. * mailbox by polling for its completion.
  4631. *
  4632. * The caller must not be holding any locks when calling this routine.
  4633. *
  4634. * Returns:
  4635. * MBX_SUCCESS - mailbox posted successfully
  4636. * Any of the MBX error values.
  4637. **/
  4638. static int
  4639. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4640. {
  4641. int rc = MBX_SUCCESS;
  4642. unsigned long iflag;
  4643. uint32_t db_ready;
  4644. uint32_t mcqe_status;
  4645. uint32_t mbx_cmnd;
  4646. unsigned long timeout;
  4647. struct lpfc_sli *psli = &phba->sli;
  4648. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4649. struct lpfc_bmbx_create *mbox_rgn;
  4650. struct dma_address *dma_address;
  4651. struct lpfc_register bmbx_reg;
  4652. /*
  4653. * Only one mailbox can be active to the bootstrap mailbox region
  4654. * at a time and there is no queueing provided.
  4655. */
  4656. spin_lock_irqsave(&phba->hbalock, iflag);
  4657. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4658. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4659. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4660. "(%d):2532 Mailbox command x%x (x%x) "
  4661. "cannot issue Data: x%x x%x\n",
  4662. mboxq->vport ? mboxq->vport->vpi : 0,
  4663. mboxq->u.mb.mbxCommand,
  4664. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4665. psli->sli_flag, MBX_POLL);
  4666. return MBXERR_ERROR;
  4667. }
  4668. /* The server grabs the token and owns it until release */
  4669. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4670. phba->sli.mbox_active = mboxq;
  4671. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4672. /*
  4673. * Initialize the bootstrap memory region to avoid stale data areas
  4674. * in the mailbox post. Then copy the caller's mailbox contents to
  4675. * the bmbx mailbox region.
  4676. */
  4677. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4678. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4679. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4680. sizeof(struct lpfc_mqe));
  4681. /* Post the high mailbox dma address to the port and wait for ready. */
  4682. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4683. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4684. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4685. * 1000) + jiffies;
  4686. do {
  4687. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4688. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4689. if (!db_ready)
  4690. msleep(2);
  4691. if (time_after(jiffies, timeout)) {
  4692. rc = MBXERR_ERROR;
  4693. goto exit;
  4694. }
  4695. } while (!db_ready);
  4696. /* Post the low mailbox dma address to the port. */
  4697. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4698. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4699. * 1000) + jiffies;
  4700. do {
  4701. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4702. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4703. if (!db_ready)
  4704. msleep(2);
  4705. if (time_after(jiffies, timeout)) {
  4706. rc = MBXERR_ERROR;
  4707. goto exit;
  4708. }
  4709. } while (!db_ready);
  4710. /*
  4711. * Read the CQ to ensure the mailbox has completed.
  4712. * If so, update the mailbox status so that the upper layers
  4713. * can complete the request normally.
  4714. */
  4715. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4716. sizeof(struct lpfc_mqe));
  4717. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4718. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4719. sizeof(struct lpfc_mcqe));
  4720. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4721. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4722. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4723. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4724. rc = MBXERR_ERROR;
  4725. }
  4726. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4727. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4728. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4729. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4730. mboxq->vport ? mboxq->vport->vpi : 0,
  4731. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4732. bf_get(lpfc_mqe_status, mb),
  4733. mb->un.mb_words[0], mb->un.mb_words[1],
  4734. mb->un.mb_words[2], mb->un.mb_words[3],
  4735. mb->un.mb_words[4], mb->un.mb_words[5],
  4736. mb->un.mb_words[6], mb->un.mb_words[7],
  4737. mb->un.mb_words[8], mb->un.mb_words[9],
  4738. mb->un.mb_words[10], mb->un.mb_words[11],
  4739. mb->un.mb_words[12], mboxq->mcqe.word0,
  4740. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4741. mboxq->mcqe.trailer);
  4742. exit:
  4743. /* We are holding the token, no needed for lock when release */
  4744. spin_lock_irqsave(&phba->hbalock, iflag);
  4745. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4746. phba->sli.mbox_active = NULL;
  4747. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4748. return rc;
  4749. }
  4750. /**
  4751. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4752. * @phba: Pointer to HBA context object.
  4753. * @pmbox: Pointer to mailbox object.
  4754. * @flag: Flag indicating how the mailbox need to be processed.
  4755. *
  4756. * This function is called by discovery code and HBA management code to submit
  4757. * a mailbox command to firmware with SLI-4 interface spec.
  4758. *
  4759. * Return codes the caller owns the mailbox command after the return of the
  4760. * function.
  4761. **/
  4762. static int
  4763. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4764. uint32_t flag)
  4765. {
  4766. struct lpfc_sli *psli = &phba->sli;
  4767. unsigned long iflags;
  4768. int rc;
  4769. rc = lpfc_mbox_dev_check(phba);
  4770. if (unlikely(rc)) {
  4771. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4772. "(%d):2544 Mailbox command x%x (x%x) "
  4773. "cannot issue Data: x%x x%x\n",
  4774. mboxq->vport ? mboxq->vport->vpi : 0,
  4775. mboxq->u.mb.mbxCommand,
  4776. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4777. psli->sli_flag, flag);
  4778. goto out_not_finished;
  4779. }
  4780. /* Detect polling mode and jump to a handler */
  4781. if (!phba->sli4_hba.intr_enable) {
  4782. if (flag == MBX_POLL)
  4783. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4784. else
  4785. rc = -EIO;
  4786. if (rc != MBX_SUCCESS)
  4787. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4788. "(%d):2541 Mailbox command x%x "
  4789. "(x%x) cannot issue Data: x%x x%x\n",
  4790. mboxq->vport ? mboxq->vport->vpi : 0,
  4791. mboxq->u.mb.mbxCommand,
  4792. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4793. psli->sli_flag, flag);
  4794. return rc;
  4795. } else if (flag == MBX_POLL) {
  4796. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4797. "(%d):2542 Try to issue mailbox command "
  4798. "x%x (x%x) synchronously ahead of async"
  4799. "mailbox command queue: x%x x%x\n",
  4800. mboxq->vport ? mboxq->vport->vpi : 0,
  4801. mboxq->u.mb.mbxCommand,
  4802. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4803. psli->sli_flag, flag);
  4804. /* Try to block the asynchronous mailbox posting */
  4805. rc = lpfc_sli4_async_mbox_block(phba);
  4806. if (!rc) {
  4807. /* Successfully blocked, now issue sync mbox cmd */
  4808. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4809. if (rc != MBX_SUCCESS)
  4810. lpfc_printf_log(phba, KERN_ERR,
  4811. LOG_MBOX | LOG_SLI,
  4812. "(%d):2597 Mailbox command "
  4813. "x%x (x%x) cannot issue "
  4814. "Data: x%x x%x\n",
  4815. mboxq->vport ?
  4816. mboxq->vport->vpi : 0,
  4817. mboxq->u.mb.mbxCommand,
  4818. lpfc_sli4_mbox_opcode_get(phba,
  4819. mboxq),
  4820. psli->sli_flag, flag);
  4821. /* Unblock the async mailbox posting afterward */
  4822. lpfc_sli4_async_mbox_unblock(phba);
  4823. }
  4824. return rc;
  4825. }
  4826. /* Now, interrupt mode asynchrous mailbox command */
  4827. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4828. if (rc) {
  4829. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4830. "(%d):2543 Mailbox command x%x (x%x) "
  4831. "cannot issue Data: x%x x%x\n",
  4832. mboxq->vport ? mboxq->vport->vpi : 0,
  4833. mboxq->u.mb.mbxCommand,
  4834. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4835. psli->sli_flag, flag);
  4836. goto out_not_finished;
  4837. }
  4838. /* Put the mailbox command to the driver internal FIFO */
  4839. psli->slistat.mbox_busy++;
  4840. spin_lock_irqsave(&phba->hbalock, iflags);
  4841. lpfc_mbox_put(phba, mboxq);
  4842. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4843. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4844. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4845. "x%x (x%x) x%x x%x x%x\n",
  4846. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4847. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4848. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4849. phba->pport->port_state,
  4850. psli->sli_flag, MBX_NOWAIT);
  4851. /* Wake up worker thread to transport mailbox command from head */
  4852. lpfc_worker_wake_up(phba);
  4853. return MBX_BUSY;
  4854. out_not_finished:
  4855. return MBX_NOT_FINISHED;
  4856. }
  4857. /**
  4858. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4859. * @phba: Pointer to HBA context object.
  4860. *
  4861. * This function is called by worker thread to send a mailbox command to
  4862. * SLI4 HBA firmware.
  4863. *
  4864. **/
  4865. int
  4866. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4867. {
  4868. struct lpfc_sli *psli = &phba->sli;
  4869. LPFC_MBOXQ_t *mboxq;
  4870. int rc = MBX_SUCCESS;
  4871. unsigned long iflags;
  4872. struct lpfc_mqe *mqe;
  4873. uint32_t mbx_cmnd;
  4874. /* Check interrupt mode before post async mailbox command */
  4875. if (unlikely(!phba->sli4_hba.intr_enable))
  4876. return MBX_NOT_FINISHED;
  4877. /* Check for mailbox command service token */
  4878. spin_lock_irqsave(&phba->hbalock, iflags);
  4879. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4880. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4881. return MBX_NOT_FINISHED;
  4882. }
  4883. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4884. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4885. return MBX_NOT_FINISHED;
  4886. }
  4887. if (unlikely(phba->sli.mbox_active)) {
  4888. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4889. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4890. "0384 There is pending active mailbox cmd\n");
  4891. return MBX_NOT_FINISHED;
  4892. }
  4893. /* Take the mailbox command service token */
  4894. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4895. /* Get the next mailbox command from head of queue */
  4896. mboxq = lpfc_mbox_get(phba);
  4897. /* If no more mailbox command waiting for post, we're done */
  4898. if (!mboxq) {
  4899. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4900. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4901. return MBX_SUCCESS;
  4902. }
  4903. phba->sli.mbox_active = mboxq;
  4904. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4905. /* Check device readiness for posting mailbox command */
  4906. rc = lpfc_mbox_dev_check(phba);
  4907. if (unlikely(rc))
  4908. /* Driver clean routine will clean up pending mailbox */
  4909. goto out_not_finished;
  4910. /* Prepare the mbox command to be posted */
  4911. mqe = &mboxq->u.mqe;
  4912. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4913. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4914. mod_timer(&psli->mbox_tmo, (jiffies +
  4915. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4916. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4917. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4918. "x%x x%x\n",
  4919. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4920. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4921. phba->pport->port_state, psli->sli_flag);
  4922. if (mbx_cmnd != MBX_HEARTBEAT) {
  4923. if (mboxq->vport) {
  4924. lpfc_debugfs_disc_trc(mboxq->vport,
  4925. LPFC_DISC_TRC_MBOX_VPORT,
  4926. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4927. mbx_cmnd, mqe->un.mb_words[0],
  4928. mqe->un.mb_words[1]);
  4929. } else {
  4930. lpfc_debugfs_disc_trc(phba->pport,
  4931. LPFC_DISC_TRC_MBOX,
  4932. "MBOX Send: cmd:x%x mb:x%x x%x",
  4933. mbx_cmnd, mqe->un.mb_words[0],
  4934. mqe->un.mb_words[1]);
  4935. }
  4936. }
  4937. psli->slistat.mbox_cmd++;
  4938. /* Post the mailbox command to the port */
  4939. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  4940. if (rc != MBX_SUCCESS) {
  4941. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4942. "(%d):2533 Mailbox command x%x (x%x) "
  4943. "cannot issue Data: x%x x%x\n",
  4944. mboxq->vport ? mboxq->vport->vpi : 0,
  4945. mboxq->u.mb.mbxCommand,
  4946. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4947. psli->sli_flag, MBX_NOWAIT);
  4948. goto out_not_finished;
  4949. }
  4950. return rc;
  4951. out_not_finished:
  4952. spin_lock_irqsave(&phba->hbalock, iflags);
  4953. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4954. __lpfc_mbox_cmpl_put(phba, mboxq);
  4955. /* Release the token */
  4956. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4957. phba->sli.mbox_active = NULL;
  4958. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4959. return MBX_NOT_FINISHED;
  4960. }
  4961. /**
  4962. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  4963. * @phba: Pointer to HBA context object.
  4964. * @pmbox: Pointer to mailbox object.
  4965. * @flag: Flag indicating how the mailbox need to be processed.
  4966. *
  4967. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  4968. * the API jump table function pointer from the lpfc_hba struct.
  4969. *
  4970. * Return codes the caller owns the mailbox command after the return of the
  4971. * function.
  4972. **/
  4973. int
  4974. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  4975. {
  4976. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  4977. }
  4978. /**
  4979. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  4980. * @phba: The hba struct for which this call is being executed.
  4981. * @dev_grp: The HBA PCI-Device group number.
  4982. *
  4983. * This routine sets up the mbox interface API function jump table in @phba
  4984. * struct.
  4985. * Returns: 0 - success, -ENODEV - failure.
  4986. **/
  4987. int
  4988. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4989. {
  4990. switch (dev_grp) {
  4991. case LPFC_PCI_DEV_LP:
  4992. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  4993. phba->lpfc_sli_handle_slow_ring_event =
  4994. lpfc_sli_handle_slow_ring_event_s3;
  4995. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  4996. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  4997. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  4998. break;
  4999. case LPFC_PCI_DEV_OC:
  5000. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5001. phba->lpfc_sli_handle_slow_ring_event =
  5002. lpfc_sli_handle_slow_ring_event_s4;
  5003. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5004. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5005. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5006. break;
  5007. default:
  5008. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5009. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5010. dev_grp);
  5011. return -ENODEV;
  5012. break;
  5013. }
  5014. return 0;
  5015. }
  5016. /**
  5017. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5018. * @phba: Pointer to HBA context object.
  5019. * @pring: Pointer to driver SLI ring object.
  5020. * @piocb: Pointer to address of newly added command iocb.
  5021. *
  5022. * This function is called with hbalock held to add a command
  5023. * iocb to the txq when SLI layer cannot submit the command iocb
  5024. * to the ring.
  5025. **/
  5026. static void
  5027. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5028. struct lpfc_iocbq *piocb)
  5029. {
  5030. /* Insert the caller's iocb in the txq tail for later processing. */
  5031. list_add_tail(&piocb->list, &pring->txq);
  5032. pring->txq_cnt++;
  5033. }
  5034. /**
  5035. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5036. * @phba: Pointer to HBA context object.
  5037. * @pring: Pointer to driver SLI ring object.
  5038. * @piocb: Pointer to address of newly added command iocb.
  5039. *
  5040. * This function is called with hbalock held before a new
  5041. * iocb is submitted to the firmware. This function checks
  5042. * txq to flush the iocbs in txq to Firmware before
  5043. * submitting new iocbs to the Firmware.
  5044. * If there are iocbs in the txq which need to be submitted
  5045. * to firmware, lpfc_sli_next_iocb returns the first element
  5046. * of the txq after dequeuing it from txq.
  5047. * If there is no iocb in the txq then the function will return
  5048. * *piocb and *piocb is set to NULL. Caller needs to check
  5049. * *piocb to find if there are more commands in the txq.
  5050. **/
  5051. static struct lpfc_iocbq *
  5052. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5053. struct lpfc_iocbq **piocb)
  5054. {
  5055. struct lpfc_iocbq * nextiocb;
  5056. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5057. if (!nextiocb) {
  5058. nextiocb = *piocb;
  5059. *piocb = NULL;
  5060. }
  5061. return nextiocb;
  5062. }
  5063. /**
  5064. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5065. * @phba: Pointer to HBA context object.
  5066. * @ring_number: SLI ring number to issue iocb on.
  5067. * @piocb: Pointer to command iocb.
  5068. * @flag: Flag indicating if this command can be put into txq.
  5069. *
  5070. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5071. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5072. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5073. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5074. * this function allows only iocbs for posting buffers. This function finds
  5075. * next available slot in the command ring and posts the command to the
  5076. * available slot and writes the port attention register to request HBA start
  5077. * processing new iocb. If there is no slot available in the ring and
  5078. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5079. * the function returns IOCB_BUSY.
  5080. *
  5081. * This function is called with hbalock held. The function will return success
  5082. * after it successfully submit the iocb to firmware or after adding to the
  5083. * txq.
  5084. **/
  5085. static int
  5086. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5087. struct lpfc_iocbq *piocb, uint32_t flag)
  5088. {
  5089. struct lpfc_iocbq *nextiocb;
  5090. IOCB_t *iocb;
  5091. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5092. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5093. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5094. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5095. lpfc_printf_log(phba, KERN_ERR,
  5096. LOG_SLI | LOG_VPORT,
  5097. "1807 IOCB x%x failed. No vport\n",
  5098. piocb->iocb.ulpCommand);
  5099. dump_stack();
  5100. return IOCB_ERROR;
  5101. }
  5102. /* If the PCI channel is in offline state, do not post iocbs. */
  5103. if (unlikely(pci_channel_offline(phba->pcidev)))
  5104. return IOCB_ERROR;
  5105. /* If HBA has a deferred error attention, fail the iocb. */
  5106. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5107. return IOCB_ERROR;
  5108. /*
  5109. * We should never get an IOCB if we are in a < LINK_DOWN state
  5110. */
  5111. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5112. return IOCB_ERROR;
  5113. /*
  5114. * Check to see if we are blocking IOCB processing because of a
  5115. * outstanding event.
  5116. */
  5117. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5118. goto iocb_busy;
  5119. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5120. /*
  5121. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5122. * can be issued if the link is not up.
  5123. */
  5124. switch (piocb->iocb.ulpCommand) {
  5125. case CMD_GEN_REQUEST64_CR:
  5126. case CMD_GEN_REQUEST64_CX:
  5127. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5128. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5129. FC_RCTL_DD_UNSOL_CMD) ||
  5130. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5131. MENLO_TRANSPORT_TYPE))
  5132. goto iocb_busy;
  5133. break;
  5134. case CMD_QUE_RING_BUF_CN:
  5135. case CMD_QUE_RING_BUF64_CN:
  5136. /*
  5137. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5138. * completion, iocb_cmpl MUST be 0.
  5139. */
  5140. if (piocb->iocb_cmpl)
  5141. piocb->iocb_cmpl = NULL;
  5142. /*FALLTHROUGH*/
  5143. case CMD_CREATE_XRI_CR:
  5144. case CMD_CLOSE_XRI_CN:
  5145. case CMD_CLOSE_XRI_CX:
  5146. break;
  5147. default:
  5148. goto iocb_busy;
  5149. }
  5150. /*
  5151. * For FCP commands, we must be in a state where we can process link
  5152. * attention events.
  5153. */
  5154. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5155. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5156. goto iocb_busy;
  5157. }
  5158. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5159. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5160. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5161. if (iocb)
  5162. lpfc_sli_update_ring(phba, pring);
  5163. else
  5164. lpfc_sli_update_full_ring(phba, pring);
  5165. if (!piocb)
  5166. return IOCB_SUCCESS;
  5167. goto out_busy;
  5168. iocb_busy:
  5169. pring->stats.iocb_cmd_delay++;
  5170. out_busy:
  5171. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5172. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5173. return IOCB_SUCCESS;
  5174. }
  5175. return IOCB_BUSY;
  5176. }
  5177. /**
  5178. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5179. * @phba: Pointer to HBA context object.
  5180. * @piocb: Pointer to command iocb.
  5181. * @sglq: Pointer to the scatter gather queue object.
  5182. *
  5183. * This routine converts the bpl or bde that is in the IOCB
  5184. * to a sgl list for the sli4 hardware. The physical address
  5185. * of the bpl/bde is converted back to a virtual address.
  5186. * If the IOCB contains a BPL then the list of BDE's is
  5187. * converted to sli4_sge's. If the IOCB contains a single
  5188. * BDE then it is converted to a single sli_sge.
  5189. * The IOCB is still in cpu endianess so the contents of
  5190. * the bpl can be used without byte swapping.
  5191. *
  5192. * Returns valid XRI = Success, NO_XRI = Failure.
  5193. **/
  5194. static uint16_t
  5195. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5196. struct lpfc_sglq *sglq)
  5197. {
  5198. uint16_t xritag = NO_XRI;
  5199. struct ulp_bde64 *bpl = NULL;
  5200. struct ulp_bde64 bde;
  5201. struct sli4_sge *sgl = NULL;
  5202. IOCB_t *icmd;
  5203. int numBdes = 0;
  5204. int i = 0;
  5205. if (!piocbq || !sglq)
  5206. return xritag;
  5207. sgl = (struct sli4_sge *)sglq->sgl;
  5208. icmd = &piocbq->iocb;
  5209. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5210. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5211. sizeof(struct ulp_bde64);
  5212. /* The addrHigh and addrLow fields within the IOCB
  5213. * have not been byteswapped yet so there is no
  5214. * need to swap them back.
  5215. */
  5216. bpl = (struct ulp_bde64 *)
  5217. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5218. if (!bpl)
  5219. return xritag;
  5220. for (i = 0; i < numBdes; i++) {
  5221. /* Should already be byte swapped. */
  5222. sgl->addr_hi = bpl->addrHigh;
  5223. sgl->addr_lo = bpl->addrLow;
  5224. if ((i+1) == numBdes)
  5225. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5226. else
  5227. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5228. sgl->word2 = cpu_to_le32(sgl->word2);
  5229. /* swap the size field back to the cpu so we
  5230. * can assign it to the sgl.
  5231. */
  5232. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5233. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5234. bpl++;
  5235. sgl++;
  5236. }
  5237. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5238. /* The addrHigh and addrLow fields of the BDE have not
  5239. * been byteswapped yet so they need to be swapped
  5240. * before putting them in the sgl.
  5241. */
  5242. sgl->addr_hi =
  5243. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5244. sgl->addr_lo =
  5245. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5246. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5247. sgl->word2 = cpu_to_le32(sgl->word2);
  5248. sgl->sge_len =
  5249. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5250. }
  5251. return sglq->sli4_xritag;
  5252. }
  5253. /**
  5254. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5255. * @phba: Pointer to HBA context object.
  5256. *
  5257. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5258. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5259. * held.
  5260. *
  5261. * Return: index into SLI4 fast-path FCP queue index.
  5262. **/
  5263. static uint32_t
  5264. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5265. {
  5266. ++phba->fcp_qidx;
  5267. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5268. phba->fcp_qidx = 0;
  5269. return phba->fcp_qidx;
  5270. }
  5271. /**
  5272. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5273. * @phba: Pointer to HBA context object.
  5274. * @piocb: Pointer to command iocb.
  5275. * @wqe: Pointer to the work queue entry.
  5276. *
  5277. * This routine converts the iocb command to its Work Queue Entry
  5278. * equivalent. The wqe pointer should not have any fields set when
  5279. * this routine is called because it will memcpy over them.
  5280. * This routine does not set the CQ_ID or the WQEC bits in the
  5281. * wqe.
  5282. *
  5283. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5284. **/
  5285. static int
  5286. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5287. union lpfc_wqe *wqe)
  5288. {
  5289. uint32_t xmit_len = 0, total_len = 0;
  5290. uint8_t ct = 0;
  5291. uint32_t fip;
  5292. uint32_t abort_tag;
  5293. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5294. uint8_t cmnd;
  5295. uint16_t xritag;
  5296. struct ulp_bde64 *bpl = NULL;
  5297. uint32_t els_id = ELS_ID_DEFAULT;
  5298. int numBdes, i;
  5299. struct ulp_bde64 bde;
  5300. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5301. /* The fcp commands will set command type */
  5302. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5303. command_type = FCP_COMMAND;
  5304. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5305. command_type = ELS_COMMAND_FIP;
  5306. else
  5307. command_type = ELS_COMMAND_NON_FIP;
  5308. /* Some of the fields are in the right position already */
  5309. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5310. abort_tag = (uint32_t) iocbq->iotag;
  5311. xritag = iocbq->sli4_xritag;
  5312. wqe->words[7] = 0; /* The ct field has moved so reset */
  5313. /* words0-2 bpl convert bde */
  5314. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5315. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5316. sizeof(struct ulp_bde64);
  5317. bpl = (struct ulp_bde64 *)
  5318. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5319. if (!bpl)
  5320. return IOCB_ERROR;
  5321. /* Should already be byte swapped. */
  5322. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5323. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5324. /* swap the size field back to the cpu so we
  5325. * can assign it to the sgl.
  5326. */
  5327. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5328. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5329. total_len = 0;
  5330. for (i = 0; i < numBdes; i++) {
  5331. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5332. total_len += bde.tus.f.bdeSize;
  5333. }
  5334. } else
  5335. xmit_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 = xmit_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. if (command_type == ELS_COMMAND_FIP) {
  5367. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5368. >> LPFC_FIP_ELS_ID_SHIFT);
  5369. }
  5370. bf_set(lpfc_wqe_gen_els_id, &wqe->generic, els_id);
  5371. break;
  5372. case CMD_XMIT_SEQUENCE64_CX:
  5373. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5374. iocbq->iocb.un.ulpWord[3]);
  5375. wqe->generic.word3 = 0;
  5376. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5377. /* The entire sequence is transmitted for this IOCB */
  5378. xmit_len = total_len;
  5379. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5380. case CMD_XMIT_SEQUENCE64_CR:
  5381. /* word3 iocb=io_tag32 wqe=payload_offset */
  5382. /* payload offset used for multilpe outstanding
  5383. * sequences on the same exchange
  5384. */
  5385. wqe->words[3] = 0;
  5386. /* word4 relative_offset memcpy */
  5387. /* word5 r_ctl/df_ctl memcpy */
  5388. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5389. wqe->xmit_sequence.xmit_len = xmit_len;
  5390. command_type = OTHER_COMMAND;
  5391. break;
  5392. case CMD_XMIT_BCAST64_CN:
  5393. /* word3 iocb=iotag32 wqe=payload_len */
  5394. wqe->words[3] = 0; /* no definition for this in wqe */
  5395. /* word4 iocb=rsvd wqe=rsvd */
  5396. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5397. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5398. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5399. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5400. break;
  5401. case CMD_FCP_IWRITE64_CR:
  5402. command_type = FCP_COMMAND_DATA_OUT;
  5403. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5404. * confusing.
  5405. * word3 is payload_len: byte offset to the sgl entry for the
  5406. * fcp_command.
  5407. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5408. * word5 is initial xfer len 0 = wait for xfer-ready
  5409. */
  5410. /* Always wait for xfer-ready before sending data */
  5411. wqe->fcp_iwrite.initial_xfer_len = 0;
  5412. /* word 4 (xfer length) should have been set on the memcpy */
  5413. /* allow write to fall through to read */
  5414. case CMD_FCP_IREAD64_CR:
  5415. /* FCP_CMD is always the 1st sgl entry */
  5416. wqe->fcp_iread.payload_len =
  5417. xmit_len + sizeof(struct fcp_rsp);
  5418. /* word 4 (xfer length) should have been set on the memcpy */
  5419. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5420. iocbq->iocb.ulpFCP2Rcvy);
  5421. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5422. /* The XC bit and the XS bit are similar. The driver never
  5423. * tracked whether or not the exchange was previouslly open.
  5424. * XC = Exchange create, 0 is create. 1 is already open.
  5425. * XS = link cmd: 1 do not close the exchange after command.
  5426. * XS = 0 close exchange when command completes.
  5427. * The only time we would not set the XC bit is when the XS bit
  5428. * is set and we are sending our 2nd or greater command on
  5429. * this exchange.
  5430. */
  5431. /* Always open the exchange */
  5432. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5433. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5434. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5435. break;
  5436. case CMD_FCP_ICMND64_CR:
  5437. /* Always open the exchange */
  5438. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5439. wqe->words[4] = 0;
  5440. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5441. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5442. break;
  5443. case CMD_GEN_REQUEST64_CR:
  5444. /* word3 command length is described as byte offset to the
  5445. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5446. * sgl[0] = cmnd
  5447. * sgl[1] = rsp.
  5448. *
  5449. */
  5450. wqe->gen_req.command_len = xmit_len;
  5451. /* Word4 parameter copied in the memcpy */
  5452. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5453. /* word6 context tag copied in memcpy */
  5454. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5455. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5456. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5457. "2015 Invalid CT %x command 0x%x\n",
  5458. ct, iocbq->iocb.ulpCommand);
  5459. return IOCB_ERROR;
  5460. }
  5461. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5462. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5463. iocbq->iocb.ulpTimeout);
  5464. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5465. command_type = OTHER_COMMAND;
  5466. break;
  5467. case CMD_XMIT_ELS_RSP64_CX:
  5468. /* words0-2 BDE memcpy */
  5469. /* word3 iocb=iotag32 wqe=rsvd */
  5470. wqe->words[3] = 0;
  5471. /* word4 iocb=did wge=rsvd. */
  5472. wqe->words[4] = 0;
  5473. /* word5 iocb=rsvd wge=did */
  5474. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5475. iocbq->iocb.un.elsreq64.remoteID);
  5476. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5477. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5478. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5479. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5480. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5481. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5482. iocbq->vport->vpi + phba->vpi_base);
  5483. command_type = OTHER_COMMAND;
  5484. break;
  5485. case CMD_CLOSE_XRI_CN:
  5486. case CMD_ABORT_XRI_CN:
  5487. case CMD_ABORT_XRI_CX:
  5488. /* words 0-2 memcpy should be 0 rserved */
  5489. /* port will send abts */
  5490. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5491. /*
  5492. * The link is down so the fw does not need to send abts
  5493. * on the wire.
  5494. */
  5495. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5496. else
  5497. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5498. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5499. wqe->words[5] = 0;
  5500. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5501. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5502. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5503. /*
  5504. * The abort handler will send us CMD_ABORT_XRI_CN or
  5505. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5506. */
  5507. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5508. cmnd = CMD_ABORT_XRI_CX;
  5509. command_type = OTHER_COMMAND;
  5510. xritag = 0;
  5511. break;
  5512. case CMD_XMIT_BLS_RSP64_CX:
  5513. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  5514. * we re-construct this WQE here based on information in
  5515. * iocbq from scratch.
  5516. */
  5517. memset(wqe, 0, sizeof(union lpfc_wqe));
  5518. /* OX_ID is invariable to who sent ABTS to CT exchange */
  5519. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  5520. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  5521. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  5522. LPFC_ABTS_UNSOL_INT) {
  5523. /* ABTS sent by initiator to CT exchange, the
  5524. * RX_ID field will be filled with the newly
  5525. * allocated responder XRI.
  5526. */
  5527. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5528. iocbq->sli4_xritag);
  5529. } else {
  5530. /* ABTS sent by responder to CT exchange, the
  5531. * RX_ID field will be filled with the responder
  5532. * RX_ID from ABTS.
  5533. */
  5534. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5535. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  5536. }
  5537. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  5538. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  5539. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  5540. iocbq->iocb.ulpContext);
  5541. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  5542. command_type = OTHER_COMMAND;
  5543. break;
  5544. case CMD_XRI_ABORTED_CX:
  5545. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5546. /* words0-2 are all 0's no bde */
  5547. /* word3 and word4 are rsvrd */
  5548. wqe->words[3] = 0;
  5549. wqe->words[4] = 0;
  5550. /* word5 iocb=rsvd wge=did */
  5551. /* There is no remote port id in the IOCB? */
  5552. /* Let this fall through and fail */
  5553. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5554. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5555. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5556. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5557. default:
  5558. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5559. "2014 Invalid command 0x%x\n",
  5560. iocbq->iocb.ulpCommand);
  5561. return IOCB_ERROR;
  5562. break;
  5563. }
  5564. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5565. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5566. wqe->generic.abort_tag = abort_tag;
  5567. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5568. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5569. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5570. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5571. return 0;
  5572. }
  5573. /**
  5574. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5575. * @phba: Pointer to HBA context object.
  5576. * @ring_number: SLI ring number to issue iocb on.
  5577. * @piocb: Pointer to command iocb.
  5578. * @flag: Flag indicating if this command can be put into txq.
  5579. *
  5580. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5581. * an iocb command to an HBA with SLI-4 interface spec.
  5582. *
  5583. * This function is called with hbalock held. The function will return success
  5584. * after it successfully submit the iocb to firmware or after adding to the
  5585. * txq.
  5586. **/
  5587. static int
  5588. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5589. struct lpfc_iocbq *piocb, uint32_t flag)
  5590. {
  5591. struct lpfc_sglq *sglq;
  5592. uint16_t xritag;
  5593. union lpfc_wqe wqe;
  5594. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5595. if (piocb->sli4_xritag == NO_XRI) {
  5596. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5597. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5598. sglq = NULL;
  5599. else {
  5600. sglq = __lpfc_sli_get_sglq(phba);
  5601. if (!sglq)
  5602. return IOCB_ERROR;
  5603. piocb->sli4_xritag = sglq->sli4_xritag;
  5604. }
  5605. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5606. sglq = NULL; /* These IO's already have an XRI and
  5607. * a mapped sgl.
  5608. */
  5609. } else {
  5610. /* This is a continuation of a commandi,(CX) so this
  5611. * sglq is on the active list
  5612. */
  5613. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5614. if (!sglq)
  5615. return IOCB_ERROR;
  5616. }
  5617. if (sglq) {
  5618. xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
  5619. if (xritag != sglq->sli4_xritag)
  5620. return IOCB_ERROR;
  5621. }
  5622. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5623. return IOCB_ERROR;
  5624. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  5625. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  5626. /*
  5627. * For FCP command IOCB, get a new WQ index to distribute
  5628. * WQE across the WQsr. On the other hand, for abort IOCB,
  5629. * it carries the same WQ index to the original command
  5630. * IOCB.
  5631. */
  5632. if (piocb->iocb_flag & LPFC_IO_FCP)
  5633. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5634. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  5635. &wqe))
  5636. return IOCB_ERROR;
  5637. } else {
  5638. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5639. return IOCB_ERROR;
  5640. }
  5641. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5642. return 0;
  5643. }
  5644. /**
  5645. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5646. *
  5647. * This routine wraps the actual lockless version for issusing IOCB function
  5648. * pointer from the lpfc_hba struct.
  5649. *
  5650. * Return codes:
  5651. * IOCB_ERROR - Error
  5652. * IOCB_SUCCESS - Success
  5653. * IOCB_BUSY - Busy
  5654. **/
  5655. static inline int
  5656. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5657. struct lpfc_iocbq *piocb, uint32_t flag)
  5658. {
  5659. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5660. }
  5661. /**
  5662. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5663. * @phba: The hba struct for which this call is being executed.
  5664. * @dev_grp: The HBA PCI-Device group number.
  5665. *
  5666. * This routine sets up the SLI interface API function jump table in @phba
  5667. * struct.
  5668. * Returns: 0 - success, -ENODEV - failure.
  5669. **/
  5670. int
  5671. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5672. {
  5673. switch (dev_grp) {
  5674. case LPFC_PCI_DEV_LP:
  5675. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5676. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5677. break;
  5678. case LPFC_PCI_DEV_OC:
  5679. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5680. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5681. break;
  5682. default:
  5683. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5684. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5685. dev_grp);
  5686. return -ENODEV;
  5687. break;
  5688. }
  5689. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5690. return 0;
  5691. }
  5692. /**
  5693. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5694. * @phba: Pointer to HBA context object.
  5695. * @pring: Pointer to driver SLI ring object.
  5696. * @piocb: Pointer to command iocb.
  5697. * @flag: Flag indicating if this command can be put into txq.
  5698. *
  5699. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5700. * function. This function gets the hbalock and calls
  5701. * __lpfc_sli_issue_iocb function and will return the error returned
  5702. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5703. * functions which do not hold hbalock.
  5704. **/
  5705. int
  5706. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5707. struct lpfc_iocbq *piocb, uint32_t flag)
  5708. {
  5709. unsigned long iflags;
  5710. int rc;
  5711. spin_lock_irqsave(&phba->hbalock, iflags);
  5712. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5713. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5714. return rc;
  5715. }
  5716. /**
  5717. * lpfc_extra_ring_setup - Extra ring setup function
  5718. * @phba: Pointer to HBA context object.
  5719. *
  5720. * This function is called while driver attaches with the
  5721. * HBA to setup the extra ring. The extra ring is used
  5722. * only when driver needs to support target mode functionality
  5723. * or IP over FC functionalities.
  5724. *
  5725. * This function is called with no lock held.
  5726. **/
  5727. static int
  5728. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5729. {
  5730. struct lpfc_sli *psli;
  5731. struct lpfc_sli_ring *pring;
  5732. psli = &phba->sli;
  5733. /* Adjust cmd/rsp ring iocb entries more evenly */
  5734. /* Take some away from the FCP ring */
  5735. pring = &psli->ring[psli->fcp_ring];
  5736. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5737. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5738. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5739. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5740. /* and give them to the extra ring */
  5741. pring = &psli->ring[psli->extra_ring];
  5742. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5743. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5744. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5745. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5746. /* Setup default profile for this ring */
  5747. pring->iotag_max = 4096;
  5748. pring->num_mask = 1;
  5749. pring->prt[0].profile = 0; /* Mask 0 */
  5750. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5751. pring->prt[0].type = phba->cfg_multi_ring_type;
  5752. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5753. return 0;
  5754. }
  5755. /**
  5756. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5757. * @phba: Pointer to HBA context object.
  5758. * @pring: Pointer to driver SLI ring object.
  5759. * @iocbq: Pointer to iocb object.
  5760. *
  5761. * This function is called by the slow ring event handler
  5762. * function when there is an ASYNC event iocb in the ring.
  5763. * This function is called with no lock held.
  5764. * Currently this function handles only temperature related
  5765. * ASYNC events. The function decodes the temperature sensor
  5766. * event message and posts events for the management applications.
  5767. **/
  5768. static void
  5769. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5770. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5771. {
  5772. IOCB_t *icmd;
  5773. uint16_t evt_code;
  5774. uint16_t temp;
  5775. struct temp_event temp_event_data;
  5776. struct Scsi_Host *shost;
  5777. uint32_t *iocb_w;
  5778. icmd = &iocbq->iocb;
  5779. evt_code = icmd->un.asyncstat.evt_code;
  5780. temp = icmd->ulpContext;
  5781. if ((evt_code != ASYNC_TEMP_WARN) &&
  5782. (evt_code != ASYNC_TEMP_SAFE)) {
  5783. iocb_w = (uint32_t *) icmd;
  5784. lpfc_printf_log(phba,
  5785. KERN_ERR,
  5786. LOG_SLI,
  5787. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5788. " evt_code 0x%x\n"
  5789. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5790. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5791. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5792. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5793. pring->ringno,
  5794. icmd->un.asyncstat.evt_code,
  5795. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5796. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5797. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5798. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5799. return;
  5800. }
  5801. temp_event_data.data = (uint32_t)temp;
  5802. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5803. if (evt_code == ASYNC_TEMP_WARN) {
  5804. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5805. lpfc_printf_log(phba,
  5806. KERN_ERR,
  5807. LOG_TEMP,
  5808. "0347 Adapter is very hot, please take "
  5809. "corrective action. temperature : %d Celsius\n",
  5810. temp);
  5811. }
  5812. if (evt_code == ASYNC_TEMP_SAFE) {
  5813. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5814. lpfc_printf_log(phba,
  5815. KERN_ERR,
  5816. LOG_TEMP,
  5817. "0340 Adapter temperature is OK now. "
  5818. "temperature : %d Celsius\n",
  5819. temp);
  5820. }
  5821. /* Send temperature change event to applications */
  5822. shost = lpfc_shost_from_vport(phba->pport);
  5823. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5824. sizeof(temp_event_data), (char *) &temp_event_data,
  5825. LPFC_NL_VENDOR_ID);
  5826. }
  5827. /**
  5828. * lpfc_sli_setup - SLI ring setup function
  5829. * @phba: Pointer to HBA context object.
  5830. *
  5831. * lpfc_sli_setup sets up rings of the SLI interface with
  5832. * number of iocbs per ring and iotags. This function is
  5833. * called while driver attach to the HBA and before the
  5834. * interrupts are enabled. So there is no need for locking.
  5835. *
  5836. * This function always returns 0.
  5837. **/
  5838. int
  5839. lpfc_sli_setup(struct lpfc_hba *phba)
  5840. {
  5841. int i, totiocbsize = 0;
  5842. struct lpfc_sli *psli = &phba->sli;
  5843. struct lpfc_sli_ring *pring;
  5844. psli->num_rings = MAX_CONFIGURED_RINGS;
  5845. psli->sli_flag = 0;
  5846. psli->fcp_ring = LPFC_FCP_RING;
  5847. psli->next_ring = LPFC_FCP_NEXT_RING;
  5848. psli->extra_ring = LPFC_EXTRA_RING;
  5849. psli->iocbq_lookup = NULL;
  5850. psli->iocbq_lookup_len = 0;
  5851. psli->last_iotag = 0;
  5852. for (i = 0; i < psli->num_rings; i++) {
  5853. pring = &psli->ring[i];
  5854. switch (i) {
  5855. case LPFC_FCP_RING: /* ring 0 - FCP */
  5856. /* numCiocb and numRiocb are used in config_port */
  5857. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5858. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5859. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5860. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5861. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5862. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5863. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5864. SLI3_IOCB_CMD_SIZE :
  5865. SLI2_IOCB_CMD_SIZE;
  5866. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5867. SLI3_IOCB_RSP_SIZE :
  5868. SLI2_IOCB_RSP_SIZE;
  5869. pring->iotag_ctr = 0;
  5870. pring->iotag_max =
  5871. (phba->cfg_hba_queue_depth * 2);
  5872. pring->fast_iotag = pring->iotag_max;
  5873. pring->num_mask = 0;
  5874. break;
  5875. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5876. /* numCiocb and numRiocb are used in config_port */
  5877. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5878. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5879. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5880. SLI3_IOCB_CMD_SIZE :
  5881. SLI2_IOCB_CMD_SIZE;
  5882. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5883. SLI3_IOCB_RSP_SIZE :
  5884. SLI2_IOCB_RSP_SIZE;
  5885. pring->iotag_max = phba->cfg_hba_queue_depth;
  5886. pring->num_mask = 0;
  5887. break;
  5888. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5889. /* numCiocb and numRiocb are used in config_port */
  5890. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5891. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5892. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5893. SLI3_IOCB_CMD_SIZE :
  5894. SLI2_IOCB_CMD_SIZE;
  5895. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5896. SLI3_IOCB_RSP_SIZE :
  5897. SLI2_IOCB_RSP_SIZE;
  5898. pring->fast_iotag = 0;
  5899. pring->iotag_ctr = 0;
  5900. pring->iotag_max = 4096;
  5901. pring->lpfc_sli_rcv_async_status =
  5902. lpfc_sli_async_event_handler;
  5903. pring->num_mask = LPFC_MAX_RING_MASK;
  5904. pring->prt[0].profile = 0; /* Mask 0 */
  5905. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  5906. pring->prt[0].type = FC_TYPE_ELS;
  5907. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5908. lpfc_els_unsol_event;
  5909. pring->prt[1].profile = 0; /* Mask 1 */
  5910. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  5911. pring->prt[1].type = FC_TYPE_ELS;
  5912. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5913. lpfc_els_unsol_event;
  5914. pring->prt[2].profile = 0; /* Mask 2 */
  5915. /* NameServer Inquiry */
  5916. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  5917. /* NameServer */
  5918. pring->prt[2].type = FC_TYPE_CT;
  5919. pring->prt[2].lpfc_sli_rcv_unsol_event =
  5920. lpfc_ct_unsol_event;
  5921. pring->prt[3].profile = 0; /* Mask 3 */
  5922. /* NameServer response */
  5923. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  5924. /* NameServer */
  5925. pring->prt[3].type = FC_TYPE_CT;
  5926. pring->prt[3].lpfc_sli_rcv_unsol_event =
  5927. lpfc_ct_unsol_event;
  5928. /* abort unsolicited sequence */
  5929. pring->prt[4].profile = 0; /* Mask 4 */
  5930. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  5931. pring->prt[4].type = FC_TYPE_BLS;
  5932. pring->prt[4].lpfc_sli_rcv_unsol_event =
  5933. lpfc_sli4_ct_abort_unsol_event;
  5934. break;
  5935. }
  5936. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  5937. (pring->numRiocb * pring->sizeRiocb);
  5938. }
  5939. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  5940. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  5941. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  5942. "SLI2 SLIM Data: x%x x%lx\n",
  5943. phba->brd_no, totiocbsize,
  5944. (unsigned long) MAX_SLIM_IOCB_SIZE);
  5945. }
  5946. if (phba->cfg_multi_ring_support == 2)
  5947. lpfc_extra_ring_setup(phba);
  5948. return 0;
  5949. }
  5950. /**
  5951. * lpfc_sli_queue_setup - Queue initialization function
  5952. * @phba: Pointer to HBA context object.
  5953. *
  5954. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  5955. * ring. This function also initializes ring indices of each ring.
  5956. * This function is called during the initialization of the SLI
  5957. * interface of an HBA.
  5958. * This function is called with no lock held and always returns
  5959. * 1.
  5960. **/
  5961. int
  5962. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  5963. {
  5964. struct lpfc_sli *psli;
  5965. struct lpfc_sli_ring *pring;
  5966. int i;
  5967. psli = &phba->sli;
  5968. spin_lock_irq(&phba->hbalock);
  5969. INIT_LIST_HEAD(&psli->mboxq);
  5970. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  5971. /* Initialize list headers for txq and txcmplq as double linked lists */
  5972. for (i = 0; i < psli->num_rings; i++) {
  5973. pring = &psli->ring[i];
  5974. pring->ringno = i;
  5975. pring->next_cmdidx = 0;
  5976. pring->local_getidx = 0;
  5977. pring->cmdidx = 0;
  5978. INIT_LIST_HEAD(&pring->txq);
  5979. INIT_LIST_HEAD(&pring->txcmplq);
  5980. INIT_LIST_HEAD(&pring->iocb_continueq);
  5981. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  5982. INIT_LIST_HEAD(&pring->postbufq);
  5983. }
  5984. spin_unlock_irq(&phba->hbalock);
  5985. return 1;
  5986. }
  5987. /**
  5988. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  5989. * @phba: Pointer to HBA context object.
  5990. *
  5991. * This routine flushes the mailbox command subsystem. It will unconditionally
  5992. * flush all the mailbox commands in the three possible stages in the mailbox
  5993. * command sub-system: pending mailbox command queue; the outstanding mailbox
  5994. * command; and completed mailbox command queue. It is caller's responsibility
  5995. * to make sure that the driver is in the proper state to flush the mailbox
  5996. * command sub-system. Namely, the posting of mailbox commands into the
  5997. * pending mailbox command queue from the various clients must be stopped;
  5998. * either the HBA is in a state that it will never works on the outstanding
  5999. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6000. * mailbox command has been completed.
  6001. **/
  6002. static void
  6003. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6004. {
  6005. LIST_HEAD(completions);
  6006. struct lpfc_sli *psli = &phba->sli;
  6007. LPFC_MBOXQ_t *pmb;
  6008. unsigned long iflag;
  6009. /* Flush all the mailbox commands in the mbox system */
  6010. spin_lock_irqsave(&phba->hbalock, iflag);
  6011. /* The pending mailbox command queue */
  6012. list_splice_init(&phba->sli.mboxq, &completions);
  6013. /* The outstanding active mailbox command */
  6014. if (psli->mbox_active) {
  6015. list_add_tail(&psli->mbox_active->list, &completions);
  6016. psli->mbox_active = NULL;
  6017. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6018. }
  6019. /* The completed mailbox command queue */
  6020. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6021. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6022. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6023. while (!list_empty(&completions)) {
  6024. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6025. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6026. if (pmb->mbox_cmpl)
  6027. pmb->mbox_cmpl(phba, pmb);
  6028. }
  6029. }
  6030. /**
  6031. * lpfc_sli_host_down - Vport cleanup function
  6032. * @vport: Pointer to virtual port object.
  6033. *
  6034. * lpfc_sli_host_down is called to clean up the resources
  6035. * associated with a vport before destroying virtual
  6036. * port data structures.
  6037. * This function does following operations:
  6038. * - Free discovery resources associated with this virtual
  6039. * port.
  6040. * - Free iocbs associated with this virtual port in
  6041. * the txq.
  6042. * - Send abort for all iocb commands associated with this
  6043. * vport in txcmplq.
  6044. *
  6045. * This function is called with no lock held and always returns 1.
  6046. **/
  6047. int
  6048. lpfc_sli_host_down(struct lpfc_vport *vport)
  6049. {
  6050. LIST_HEAD(completions);
  6051. struct lpfc_hba *phba = vport->phba;
  6052. struct lpfc_sli *psli = &phba->sli;
  6053. struct lpfc_sli_ring *pring;
  6054. struct lpfc_iocbq *iocb, *next_iocb;
  6055. int i;
  6056. unsigned long flags = 0;
  6057. uint16_t prev_pring_flag;
  6058. lpfc_cleanup_discovery_resources(vport);
  6059. spin_lock_irqsave(&phba->hbalock, flags);
  6060. for (i = 0; i < psli->num_rings; i++) {
  6061. pring = &psli->ring[i];
  6062. prev_pring_flag = pring->flag;
  6063. /* Only slow rings */
  6064. if (pring->ringno == LPFC_ELS_RING) {
  6065. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6066. /* Set the lpfc data pending flag */
  6067. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6068. }
  6069. /*
  6070. * Error everything on the txq since these iocbs have not been
  6071. * given to the FW yet.
  6072. */
  6073. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6074. if (iocb->vport != vport)
  6075. continue;
  6076. list_move_tail(&iocb->list, &completions);
  6077. pring->txq_cnt--;
  6078. }
  6079. /* Next issue ABTS for everything on the txcmplq */
  6080. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6081. list) {
  6082. if (iocb->vport != vport)
  6083. continue;
  6084. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6085. }
  6086. pring->flag = prev_pring_flag;
  6087. }
  6088. spin_unlock_irqrestore(&phba->hbalock, flags);
  6089. /* Cancel all the IOCBs from the completions list */
  6090. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6091. IOERR_SLI_DOWN);
  6092. return 1;
  6093. }
  6094. /**
  6095. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6096. * @phba: Pointer to HBA context object.
  6097. *
  6098. * This function cleans up all iocb, buffers, mailbox commands
  6099. * while shutting down the HBA. This function is called with no
  6100. * lock held and always returns 1.
  6101. * This function does the following to cleanup driver resources:
  6102. * - Free discovery resources for each virtual port
  6103. * - Cleanup any pending fabric iocbs
  6104. * - Iterate through the iocb txq and free each entry
  6105. * in the list.
  6106. * - Free up any buffer posted to the HBA
  6107. * - Free mailbox commands in the mailbox queue.
  6108. **/
  6109. int
  6110. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6111. {
  6112. LIST_HEAD(completions);
  6113. struct lpfc_sli *psli = &phba->sli;
  6114. struct lpfc_sli_ring *pring;
  6115. struct lpfc_dmabuf *buf_ptr;
  6116. unsigned long flags = 0;
  6117. int i;
  6118. /* Shutdown the mailbox command sub-system */
  6119. lpfc_sli_mbox_sys_shutdown(phba);
  6120. lpfc_hba_down_prep(phba);
  6121. lpfc_fabric_abort_hba(phba);
  6122. spin_lock_irqsave(&phba->hbalock, flags);
  6123. for (i = 0; i < psli->num_rings; i++) {
  6124. pring = &psli->ring[i];
  6125. /* Only slow rings */
  6126. if (pring->ringno == LPFC_ELS_RING) {
  6127. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6128. /* Set the lpfc data pending flag */
  6129. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6130. }
  6131. /*
  6132. * Error everything on the txq since these iocbs have not been
  6133. * given to the FW yet.
  6134. */
  6135. list_splice_init(&pring->txq, &completions);
  6136. pring->txq_cnt = 0;
  6137. }
  6138. spin_unlock_irqrestore(&phba->hbalock, flags);
  6139. /* Cancel all the IOCBs from the completions list */
  6140. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6141. IOERR_SLI_DOWN);
  6142. spin_lock_irqsave(&phba->hbalock, flags);
  6143. list_splice_init(&phba->elsbuf, &completions);
  6144. phba->elsbuf_cnt = 0;
  6145. phba->elsbuf_prev_cnt = 0;
  6146. spin_unlock_irqrestore(&phba->hbalock, flags);
  6147. while (!list_empty(&completions)) {
  6148. list_remove_head(&completions, buf_ptr,
  6149. struct lpfc_dmabuf, list);
  6150. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6151. kfree(buf_ptr);
  6152. }
  6153. /* Return any active mbox cmds */
  6154. del_timer_sync(&psli->mbox_tmo);
  6155. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6156. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6157. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6158. return 1;
  6159. }
  6160. /**
  6161. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6162. * @phba: Pointer to HBA context object.
  6163. *
  6164. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6165. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6166. * lock held and always returns 1.
  6167. *
  6168. * This function does the following to cleanup driver FCoE function resources:
  6169. * - Free discovery resources for each virtual port
  6170. * - Cleanup any pending fabric iocbs
  6171. * - Iterate through the iocb txq and free each entry in the list.
  6172. * - Free up any buffer posted to the HBA.
  6173. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6174. * - Free mailbox commands in the mailbox queue.
  6175. **/
  6176. int
  6177. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6178. {
  6179. /* Stop the SLI4 device port */
  6180. lpfc_stop_port(phba);
  6181. /* Tear down the queues in the HBA */
  6182. lpfc_sli4_queue_unset(phba);
  6183. /* unregister default FCFI from the HBA */
  6184. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6185. return 1;
  6186. }
  6187. /**
  6188. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6189. * @srcp: Source memory pointer.
  6190. * @destp: Destination memory pointer.
  6191. * @cnt: Number of words required to be copied.
  6192. *
  6193. * This function is used for copying data between driver memory
  6194. * and the SLI memory. This function also changes the endianness
  6195. * of each word if native endianness is different from SLI
  6196. * endianness. This function can be called with or without
  6197. * lock.
  6198. **/
  6199. void
  6200. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6201. {
  6202. uint32_t *src = srcp;
  6203. uint32_t *dest = destp;
  6204. uint32_t ldata;
  6205. int i;
  6206. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6207. ldata = *src;
  6208. ldata = le32_to_cpu(ldata);
  6209. *dest = ldata;
  6210. src++;
  6211. dest++;
  6212. }
  6213. }
  6214. /**
  6215. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6216. * @srcp: Source memory pointer.
  6217. * @destp: Destination memory pointer.
  6218. * @cnt: Number of words required to be copied.
  6219. *
  6220. * This function is used for copying data between a data structure
  6221. * with big endian representation to local endianness.
  6222. * This function can be called with or without lock.
  6223. **/
  6224. void
  6225. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6226. {
  6227. uint32_t *src = srcp;
  6228. uint32_t *dest = destp;
  6229. uint32_t ldata;
  6230. int i;
  6231. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6232. ldata = *src;
  6233. ldata = be32_to_cpu(ldata);
  6234. *dest = ldata;
  6235. src++;
  6236. dest++;
  6237. }
  6238. }
  6239. /**
  6240. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6241. * @phba: Pointer to HBA context object.
  6242. * @pring: Pointer to driver SLI ring object.
  6243. * @mp: Pointer to driver buffer object.
  6244. *
  6245. * This function is called with no lock held.
  6246. * It always return zero after adding the buffer to the postbufq
  6247. * buffer list.
  6248. **/
  6249. int
  6250. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6251. struct lpfc_dmabuf *mp)
  6252. {
  6253. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6254. later */
  6255. spin_lock_irq(&phba->hbalock);
  6256. list_add_tail(&mp->list, &pring->postbufq);
  6257. pring->postbufq_cnt++;
  6258. spin_unlock_irq(&phba->hbalock);
  6259. return 0;
  6260. }
  6261. /**
  6262. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6263. * @phba: Pointer to HBA context object.
  6264. *
  6265. * When HBQ is enabled, buffers are searched based on tags. This function
  6266. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6267. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6268. * does not conflict with tags of buffer posted for unsolicited events.
  6269. * The function returns the allocated tag. The function is called with
  6270. * no locks held.
  6271. **/
  6272. uint32_t
  6273. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6274. {
  6275. spin_lock_irq(&phba->hbalock);
  6276. phba->buffer_tag_count++;
  6277. /*
  6278. * Always set the QUE_BUFTAG_BIT to distiguish between
  6279. * a tag assigned by HBQ.
  6280. */
  6281. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6282. spin_unlock_irq(&phba->hbalock);
  6283. return phba->buffer_tag_count;
  6284. }
  6285. /**
  6286. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6287. * @phba: Pointer to HBA context object.
  6288. * @pring: Pointer to driver SLI ring object.
  6289. * @tag: Buffer tag.
  6290. *
  6291. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6292. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6293. * iocb is posted to the response ring with the tag of the buffer.
  6294. * This function searches the pring->postbufq list using the tag
  6295. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6296. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6297. * buffer is returned to the caller else NULL is returned.
  6298. * This function is called with no lock held.
  6299. **/
  6300. struct lpfc_dmabuf *
  6301. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6302. uint32_t tag)
  6303. {
  6304. struct lpfc_dmabuf *mp, *next_mp;
  6305. struct list_head *slp = &pring->postbufq;
  6306. /* Search postbufq, from the begining, looking for a match on tag */
  6307. spin_lock_irq(&phba->hbalock);
  6308. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6309. if (mp->buffer_tag == tag) {
  6310. list_del_init(&mp->list);
  6311. pring->postbufq_cnt--;
  6312. spin_unlock_irq(&phba->hbalock);
  6313. return mp;
  6314. }
  6315. }
  6316. spin_unlock_irq(&phba->hbalock);
  6317. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6318. "0402 Cannot find virtual addr for buffer tag on "
  6319. "ring %d Data x%lx x%p x%p x%x\n",
  6320. pring->ringno, (unsigned long) tag,
  6321. slp->next, slp->prev, pring->postbufq_cnt);
  6322. return NULL;
  6323. }
  6324. /**
  6325. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6326. * @phba: Pointer to HBA context object.
  6327. * @pring: Pointer to driver SLI ring object.
  6328. * @phys: DMA address of the buffer.
  6329. *
  6330. * This function searches the buffer list using the dma_address
  6331. * of unsolicited event to find the driver's lpfc_dmabuf object
  6332. * corresponding to the dma_address. The function returns the
  6333. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6334. * This function is called by the ct and els unsolicited event
  6335. * handlers to get the buffer associated with the unsolicited
  6336. * event.
  6337. *
  6338. * This function is called with no lock held.
  6339. **/
  6340. struct lpfc_dmabuf *
  6341. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6342. dma_addr_t phys)
  6343. {
  6344. struct lpfc_dmabuf *mp, *next_mp;
  6345. struct list_head *slp = &pring->postbufq;
  6346. /* Search postbufq, from the begining, looking for a match on phys */
  6347. spin_lock_irq(&phba->hbalock);
  6348. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6349. if (mp->phys == phys) {
  6350. list_del_init(&mp->list);
  6351. pring->postbufq_cnt--;
  6352. spin_unlock_irq(&phba->hbalock);
  6353. return mp;
  6354. }
  6355. }
  6356. spin_unlock_irq(&phba->hbalock);
  6357. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6358. "0410 Cannot find virtual addr for mapped buf on "
  6359. "ring %d Data x%llx x%p x%p x%x\n",
  6360. pring->ringno, (unsigned long long)phys,
  6361. slp->next, slp->prev, pring->postbufq_cnt);
  6362. return NULL;
  6363. }
  6364. /**
  6365. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6366. * @phba: Pointer to HBA context object.
  6367. * @cmdiocb: Pointer to driver command iocb object.
  6368. * @rspiocb: Pointer to driver response iocb object.
  6369. *
  6370. * This function is the completion handler for the abort iocbs for
  6371. * ELS commands. This function is called from the ELS ring event
  6372. * handler with no lock held. This function frees memory resources
  6373. * associated with the abort iocb.
  6374. **/
  6375. static void
  6376. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6377. struct lpfc_iocbq *rspiocb)
  6378. {
  6379. IOCB_t *irsp = &rspiocb->iocb;
  6380. uint16_t abort_iotag, abort_context;
  6381. struct lpfc_iocbq *abort_iocb;
  6382. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6383. abort_iocb = NULL;
  6384. if (irsp->ulpStatus) {
  6385. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6386. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6387. spin_lock_irq(&phba->hbalock);
  6388. if (phba->sli_rev < LPFC_SLI_REV4) {
  6389. if (abort_iotag != 0 &&
  6390. abort_iotag <= phba->sli.last_iotag)
  6391. abort_iocb =
  6392. phba->sli.iocbq_lookup[abort_iotag];
  6393. } else
  6394. /* For sli4 the abort_tag is the XRI,
  6395. * so the abort routine puts the iotag of the iocb
  6396. * being aborted in the context field of the abort
  6397. * IOCB.
  6398. */
  6399. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6400. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
  6401. "0327 Cannot abort els iocb %p "
  6402. "with tag %x context %x, abort status %x, "
  6403. "abort code %x\n",
  6404. abort_iocb, abort_iotag, abort_context,
  6405. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6406. /*
  6407. * If the iocb is not found in Firmware queue the iocb
  6408. * might have completed already. Do not free it again.
  6409. */
  6410. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6411. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6412. spin_unlock_irq(&phba->hbalock);
  6413. lpfc_sli_release_iocbq(phba, cmdiocb);
  6414. return;
  6415. }
  6416. /* For SLI4 the ulpContext field for abort IOCB
  6417. * holds the iotag of the IOCB being aborted so
  6418. * the local abort_context needs to be reset to
  6419. * match the aborted IOCBs ulpContext.
  6420. */
  6421. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6422. abort_context = abort_iocb->iocb.ulpContext;
  6423. }
  6424. /*
  6425. * make sure we have the right iocbq before taking it
  6426. * off the txcmplq and try to call completion routine.
  6427. */
  6428. if (!abort_iocb ||
  6429. abort_iocb->iocb.ulpContext != abort_context ||
  6430. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6431. spin_unlock_irq(&phba->hbalock);
  6432. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6433. /*
  6434. * leave the SLI4 aborted command on the txcmplq
  6435. * list and the command complete WCQE's XB bit
  6436. * will tell whether the SGL (XRI) can be released
  6437. * immediately or to the aborted SGL list for the
  6438. * following abort XRI from the HBA.
  6439. */
  6440. list_del_init(&abort_iocb->list);
  6441. pring->txcmplq_cnt--;
  6442. spin_unlock_irq(&phba->hbalock);
  6443. /* Firmware could still be in progress of DMAing
  6444. * payload, so don't free data buffer till after
  6445. * a hbeat.
  6446. */
  6447. spin_lock_irq(&phba->hbalock);
  6448. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6449. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6450. spin_unlock_irq(&phba->hbalock);
  6451. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6452. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6453. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6454. }
  6455. }
  6456. lpfc_sli_release_iocbq(phba, cmdiocb);
  6457. return;
  6458. }
  6459. /**
  6460. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6461. * @phba: Pointer to HBA context object.
  6462. * @cmdiocb: Pointer to driver command iocb object.
  6463. * @rspiocb: Pointer to driver response iocb object.
  6464. *
  6465. * The function is called from SLI ring event handler with no
  6466. * lock held. This function is the completion handler for ELS commands
  6467. * which are aborted. The function frees memory resources used for
  6468. * the aborted ELS commands.
  6469. **/
  6470. static void
  6471. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6472. struct lpfc_iocbq *rspiocb)
  6473. {
  6474. IOCB_t *irsp = &rspiocb->iocb;
  6475. /* ELS cmd tag <ulpIoTag> completes */
  6476. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6477. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6478. "x%x x%x x%x\n",
  6479. irsp->ulpIoTag, irsp->ulpStatus,
  6480. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6481. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6482. lpfc_ct_free_iocb(phba, cmdiocb);
  6483. else
  6484. lpfc_els_free_iocb(phba, cmdiocb);
  6485. return;
  6486. }
  6487. /**
  6488. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6489. * @phba: Pointer to HBA context object.
  6490. * @pring: Pointer to driver SLI ring object.
  6491. * @cmdiocb: Pointer to driver command iocb object.
  6492. *
  6493. * This function issues an abort iocb for the provided command
  6494. * iocb. This function is called with hbalock held.
  6495. * The function returns 0 when it fails due to memory allocation
  6496. * failure or when the command iocb is an abort request.
  6497. **/
  6498. int
  6499. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6500. struct lpfc_iocbq *cmdiocb)
  6501. {
  6502. struct lpfc_vport *vport = cmdiocb->vport;
  6503. struct lpfc_iocbq *abtsiocbp;
  6504. IOCB_t *icmd = NULL;
  6505. IOCB_t *iabt = NULL;
  6506. int retval = IOCB_ERROR;
  6507. /*
  6508. * There are certain command types we don't want to abort. And we
  6509. * don't want to abort commands that are already in the process of
  6510. * being aborted.
  6511. */
  6512. icmd = &cmdiocb->iocb;
  6513. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6514. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6515. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6516. return 0;
  6517. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6518. * callback so that nothing happens when it finishes.
  6519. */
  6520. if ((vport->load_flag & FC_UNLOADING) &&
  6521. (pring->ringno == LPFC_ELS_RING)) {
  6522. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6523. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6524. else
  6525. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6526. goto abort_iotag_exit;
  6527. }
  6528. /* issue ABTS for this IOCB based on iotag */
  6529. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6530. if (abtsiocbp == NULL)
  6531. return 0;
  6532. /* This signals the response to set the correct status
  6533. * before calling the completion handler
  6534. */
  6535. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6536. iabt = &abtsiocbp->iocb;
  6537. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6538. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6539. if (phba->sli_rev == LPFC_SLI_REV4) {
  6540. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6541. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  6542. }
  6543. else
  6544. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6545. iabt->ulpLe = 1;
  6546. iabt->ulpClass = icmd->ulpClass;
  6547. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6548. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  6549. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  6550. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  6551. if (phba->link_state >= LPFC_LINK_UP)
  6552. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6553. else
  6554. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6555. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6556. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6557. "0339 Abort xri x%x, original iotag x%x, "
  6558. "abort cmd iotag x%x\n",
  6559. iabt->un.acxri.abortContextTag,
  6560. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  6561. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6562. if (retval)
  6563. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6564. abort_iotag_exit:
  6565. /*
  6566. * Caller to this routine should check for IOCB_ERROR
  6567. * and handle it properly. This routine no longer removes
  6568. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6569. */
  6570. return retval;
  6571. }
  6572. /**
  6573. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6574. * @iocbq: Pointer to driver iocb object.
  6575. * @vport: Pointer to driver virtual port object.
  6576. * @tgt_id: SCSI ID of the target.
  6577. * @lun_id: LUN ID of the scsi device.
  6578. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6579. *
  6580. * This function acts as an iocb filter for functions which abort or count
  6581. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6582. * 0 if the filtering criteria is met for the given iocb and will return
  6583. * 1 if the filtering criteria is not met.
  6584. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6585. * given iocb is for the SCSI device specified by vport, tgt_id and
  6586. * lun_id parameter.
  6587. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6588. * given iocb is for the SCSI target specified by vport and tgt_id
  6589. * parameters.
  6590. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6591. * given iocb is for the SCSI host associated with the given vport.
  6592. * This function is called with no locks held.
  6593. **/
  6594. static int
  6595. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6596. uint16_t tgt_id, uint64_t lun_id,
  6597. lpfc_ctx_cmd ctx_cmd)
  6598. {
  6599. struct lpfc_scsi_buf *lpfc_cmd;
  6600. int rc = 1;
  6601. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6602. return rc;
  6603. if (iocbq->vport != vport)
  6604. return rc;
  6605. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6606. if (lpfc_cmd->pCmd == NULL)
  6607. return rc;
  6608. switch (ctx_cmd) {
  6609. case LPFC_CTX_LUN:
  6610. if ((lpfc_cmd->rdata->pnode) &&
  6611. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6612. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6613. rc = 0;
  6614. break;
  6615. case LPFC_CTX_TGT:
  6616. if ((lpfc_cmd->rdata->pnode) &&
  6617. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6618. rc = 0;
  6619. break;
  6620. case LPFC_CTX_HOST:
  6621. rc = 0;
  6622. break;
  6623. default:
  6624. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6625. __func__, ctx_cmd);
  6626. break;
  6627. }
  6628. return rc;
  6629. }
  6630. /**
  6631. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6632. * @vport: Pointer to virtual port.
  6633. * @tgt_id: SCSI ID of the target.
  6634. * @lun_id: LUN ID of the scsi device.
  6635. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6636. *
  6637. * This function returns number of FCP commands pending for the vport.
  6638. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6639. * commands pending on the vport associated with SCSI device specified
  6640. * by tgt_id and lun_id parameters.
  6641. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6642. * commands pending on the vport associated with SCSI target specified
  6643. * by tgt_id parameter.
  6644. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6645. * commands pending on the vport.
  6646. * This function returns the number of iocbs which satisfy the filter.
  6647. * This function is called without any lock held.
  6648. **/
  6649. int
  6650. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6651. lpfc_ctx_cmd ctx_cmd)
  6652. {
  6653. struct lpfc_hba *phba = vport->phba;
  6654. struct lpfc_iocbq *iocbq;
  6655. int sum, i;
  6656. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6657. iocbq = phba->sli.iocbq_lookup[i];
  6658. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6659. ctx_cmd) == 0)
  6660. sum++;
  6661. }
  6662. return sum;
  6663. }
  6664. /**
  6665. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6666. * @phba: Pointer to HBA context object
  6667. * @cmdiocb: Pointer to command iocb object.
  6668. * @rspiocb: Pointer to response iocb object.
  6669. *
  6670. * This function is called when an aborted FCP iocb completes. This
  6671. * function is called by the ring event handler with no lock held.
  6672. * This function frees the iocb.
  6673. **/
  6674. void
  6675. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6676. struct lpfc_iocbq *rspiocb)
  6677. {
  6678. lpfc_sli_release_iocbq(phba, cmdiocb);
  6679. return;
  6680. }
  6681. /**
  6682. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6683. * @vport: Pointer to virtual port.
  6684. * @pring: Pointer to driver SLI ring object.
  6685. * @tgt_id: SCSI ID of the target.
  6686. * @lun_id: LUN ID of the scsi device.
  6687. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6688. *
  6689. * This function sends an abort command for every SCSI command
  6690. * associated with the given virtual port pending on the ring
  6691. * filtered by lpfc_sli_validate_fcp_iocb function.
  6692. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6693. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6694. * parameters
  6695. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6696. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6697. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6698. * FCP iocbs associated with virtual port.
  6699. * This function returns number of iocbs it failed to abort.
  6700. * This function is called with no locks held.
  6701. **/
  6702. int
  6703. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6704. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6705. {
  6706. struct lpfc_hba *phba = vport->phba;
  6707. struct lpfc_iocbq *iocbq;
  6708. struct lpfc_iocbq *abtsiocb;
  6709. IOCB_t *cmd = NULL;
  6710. int errcnt = 0, ret_val = 0;
  6711. int i;
  6712. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6713. iocbq = phba->sli.iocbq_lookup[i];
  6714. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6715. abort_cmd) != 0)
  6716. continue;
  6717. /* issue ABTS for this IOCB based on iotag */
  6718. abtsiocb = lpfc_sli_get_iocbq(phba);
  6719. if (abtsiocb == NULL) {
  6720. errcnt++;
  6721. continue;
  6722. }
  6723. cmd = &iocbq->iocb;
  6724. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6725. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6726. if (phba->sli_rev == LPFC_SLI_REV4)
  6727. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6728. else
  6729. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6730. abtsiocb->iocb.ulpLe = 1;
  6731. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6732. abtsiocb->vport = phba->pport;
  6733. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6734. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  6735. if (iocbq->iocb_flag & LPFC_IO_FCP)
  6736. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  6737. if (lpfc_is_link_up(phba))
  6738. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6739. else
  6740. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6741. /* Setup callback routine and issue the command. */
  6742. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6743. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6744. abtsiocb, 0);
  6745. if (ret_val == IOCB_ERROR) {
  6746. lpfc_sli_release_iocbq(phba, abtsiocb);
  6747. errcnt++;
  6748. continue;
  6749. }
  6750. }
  6751. return errcnt;
  6752. }
  6753. /**
  6754. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6755. * @phba: Pointer to HBA context object.
  6756. * @cmdiocbq: Pointer to command iocb.
  6757. * @rspiocbq: Pointer to response iocb.
  6758. *
  6759. * This function is the completion handler for iocbs issued using
  6760. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6761. * ring event handler function without any lock held. This function
  6762. * can be called from both worker thread context and interrupt
  6763. * context. This function also can be called from other thread which
  6764. * cleans up the SLI layer objects.
  6765. * This function copy the contents of the response iocb to the
  6766. * response iocb memory object provided by the caller of
  6767. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6768. * sleeps for the iocb completion.
  6769. **/
  6770. static void
  6771. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6772. struct lpfc_iocbq *cmdiocbq,
  6773. struct lpfc_iocbq *rspiocbq)
  6774. {
  6775. wait_queue_head_t *pdone_q;
  6776. unsigned long iflags;
  6777. struct lpfc_scsi_buf *lpfc_cmd;
  6778. spin_lock_irqsave(&phba->hbalock, iflags);
  6779. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6780. if (cmdiocbq->context2 && rspiocbq)
  6781. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6782. &rspiocbq->iocb, sizeof(IOCB_t));
  6783. /* Set the exchange busy flag for task management commands */
  6784. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  6785. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  6786. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  6787. cur_iocbq);
  6788. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  6789. }
  6790. pdone_q = cmdiocbq->context_un.wait_queue;
  6791. if (pdone_q)
  6792. wake_up(pdone_q);
  6793. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6794. return;
  6795. }
  6796. /**
  6797. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  6798. * @phba: Pointer to HBA context object..
  6799. * @piocbq: Pointer to command iocb.
  6800. * @flag: Flag to test.
  6801. *
  6802. * This routine grabs the hbalock and then test the iocb_flag to
  6803. * see if the passed in flag is set.
  6804. * Returns:
  6805. * 1 if flag is set.
  6806. * 0 if flag is not set.
  6807. **/
  6808. static int
  6809. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  6810. struct lpfc_iocbq *piocbq, uint32_t flag)
  6811. {
  6812. unsigned long iflags;
  6813. int ret;
  6814. spin_lock_irqsave(&phba->hbalock, iflags);
  6815. ret = piocbq->iocb_flag & flag;
  6816. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6817. return ret;
  6818. }
  6819. /**
  6820. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6821. * @phba: Pointer to HBA context object..
  6822. * @pring: Pointer to sli ring.
  6823. * @piocb: Pointer to command iocb.
  6824. * @prspiocbq: Pointer to response iocb.
  6825. * @timeout: Timeout in number of seconds.
  6826. *
  6827. * This function issues the iocb to firmware and waits for the
  6828. * iocb to complete. If the iocb command is not
  6829. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6830. * Caller should not free the iocb resources if this function
  6831. * returns IOCB_TIMEDOUT.
  6832. * The function waits for the iocb completion using an
  6833. * non-interruptible wait.
  6834. * This function will sleep while waiting for iocb completion.
  6835. * So, this function should not be called from any context which
  6836. * does not allow sleeping. Due to the same reason, this function
  6837. * cannot be called with interrupt disabled.
  6838. * This function assumes that the iocb completions occur while
  6839. * this function sleep. So, this function cannot be called from
  6840. * the thread which process iocb completion for this ring.
  6841. * This function clears the iocb_flag of the iocb object before
  6842. * issuing the iocb and the iocb completion handler sets this
  6843. * flag and wakes this thread when the iocb completes.
  6844. * The contents of the response iocb will be copied to prspiocbq
  6845. * by the completion handler when the command completes.
  6846. * This function returns IOCB_SUCCESS when success.
  6847. * This function is called with no lock held.
  6848. **/
  6849. int
  6850. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6851. uint32_t ring_number,
  6852. struct lpfc_iocbq *piocb,
  6853. struct lpfc_iocbq *prspiocbq,
  6854. uint32_t timeout)
  6855. {
  6856. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6857. long timeleft, timeout_req = 0;
  6858. int retval = IOCB_SUCCESS;
  6859. uint32_t creg_val;
  6860. /*
  6861. * If the caller has provided a response iocbq buffer, then context2
  6862. * is NULL or its an error.
  6863. */
  6864. if (prspiocbq) {
  6865. if (piocb->context2)
  6866. return IOCB_ERROR;
  6867. piocb->context2 = prspiocbq;
  6868. }
  6869. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6870. piocb->context_un.wait_queue = &done_q;
  6871. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6872. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6873. creg_val = readl(phba->HCregaddr);
  6874. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6875. writel(creg_val, phba->HCregaddr);
  6876. readl(phba->HCregaddr); /* flush */
  6877. }
  6878. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
  6879. if (retval == IOCB_SUCCESS) {
  6880. timeout_req = timeout * HZ;
  6881. timeleft = wait_event_timeout(done_q,
  6882. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  6883. timeout_req);
  6884. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6885. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6886. "0331 IOCB wake signaled\n");
  6887. } else if (timeleft == 0) {
  6888. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6889. "0338 IOCB wait timeout error - no "
  6890. "wake response Data x%x\n", timeout);
  6891. retval = IOCB_TIMEDOUT;
  6892. } else {
  6893. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6894. "0330 IOCB wake NOT set, "
  6895. "Data x%x x%lx\n",
  6896. timeout, (timeleft / jiffies));
  6897. retval = IOCB_TIMEDOUT;
  6898. }
  6899. } else {
  6900. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6901. "0332 IOCB wait issue failed, Data x%x\n",
  6902. retval);
  6903. retval = IOCB_ERROR;
  6904. }
  6905. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6906. creg_val = readl(phba->HCregaddr);
  6907. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6908. writel(creg_val, phba->HCregaddr);
  6909. readl(phba->HCregaddr); /* flush */
  6910. }
  6911. if (prspiocbq)
  6912. piocb->context2 = NULL;
  6913. piocb->context_un.wait_queue = NULL;
  6914. piocb->iocb_cmpl = NULL;
  6915. return retval;
  6916. }
  6917. /**
  6918. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  6919. * @phba: Pointer to HBA context object.
  6920. * @pmboxq: Pointer to driver mailbox object.
  6921. * @timeout: Timeout in number of seconds.
  6922. *
  6923. * This function issues the mailbox to firmware and waits for the
  6924. * mailbox command to complete. If the mailbox command is not
  6925. * completed within timeout seconds, it returns MBX_TIMEOUT.
  6926. * The function waits for the mailbox completion using an
  6927. * interruptible wait. If the thread is woken up due to a
  6928. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  6929. * should not free the mailbox resources, if this function returns
  6930. * MBX_TIMEOUT.
  6931. * This function will sleep while waiting for mailbox completion.
  6932. * So, this function should not be called from any context which
  6933. * does not allow sleeping. Due to the same reason, this function
  6934. * cannot be called with interrupt disabled.
  6935. * This function assumes that the mailbox completion occurs while
  6936. * this function sleep. So, this function cannot be called from
  6937. * the worker thread which processes mailbox completion.
  6938. * This function is called in the context of HBA management
  6939. * applications.
  6940. * This function returns MBX_SUCCESS when successful.
  6941. * This function is called with no lock held.
  6942. **/
  6943. int
  6944. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  6945. uint32_t timeout)
  6946. {
  6947. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6948. int retval;
  6949. unsigned long flag;
  6950. /* The caller must leave context1 empty. */
  6951. if (pmboxq->context1)
  6952. return MBX_NOT_FINISHED;
  6953. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  6954. /* setup wake call as IOCB callback */
  6955. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  6956. /* setup context field to pass wait_queue pointer to wake function */
  6957. pmboxq->context1 = &done_q;
  6958. /* now issue the command */
  6959. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  6960. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  6961. wait_event_interruptible_timeout(done_q,
  6962. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  6963. timeout * HZ);
  6964. spin_lock_irqsave(&phba->hbalock, flag);
  6965. pmboxq->context1 = NULL;
  6966. /*
  6967. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  6968. * else do not free the resources.
  6969. */
  6970. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  6971. retval = MBX_SUCCESS;
  6972. else {
  6973. retval = MBX_TIMEOUT;
  6974. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  6975. }
  6976. spin_unlock_irqrestore(&phba->hbalock, flag);
  6977. }
  6978. return retval;
  6979. }
  6980. /**
  6981. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  6982. * @phba: Pointer to HBA context.
  6983. *
  6984. * This function is called to shutdown the driver's mailbox sub-system.
  6985. * It first marks the mailbox sub-system is in a block state to prevent
  6986. * the asynchronous mailbox command from issued off the pending mailbox
  6987. * command queue. If the mailbox command sub-system shutdown is due to
  6988. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  6989. * the mailbox sub-system flush routine to forcefully bring down the
  6990. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  6991. * as with offline or HBA function reset), this routine will wait for the
  6992. * outstanding mailbox command to complete before invoking the mailbox
  6993. * sub-system flush routine to gracefully bring down mailbox sub-system.
  6994. **/
  6995. void
  6996. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  6997. {
  6998. struct lpfc_sli *psli = &phba->sli;
  6999. uint8_t actcmd = MBX_HEARTBEAT;
  7000. unsigned long timeout;
  7001. spin_lock_irq(&phba->hbalock);
  7002. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7003. spin_unlock_irq(&phba->hbalock);
  7004. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7005. spin_lock_irq(&phba->hbalock);
  7006. if (phba->sli.mbox_active)
  7007. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7008. spin_unlock_irq(&phba->hbalock);
  7009. /* Determine how long we might wait for the active mailbox
  7010. * command to be gracefully completed by firmware.
  7011. */
  7012. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7013. 1000) + jiffies;
  7014. while (phba->sli.mbox_active) {
  7015. /* Check active mailbox complete status every 2ms */
  7016. msleep(2);
  7017. if (time_after(jiffies, timeout))
  7018. /* Timeout, let the mailbox flush routine to
  7019. * forcefully release active mailbox command
  7020. */
  7021. break;
  7022. }
  7023. }
  7024. lpfc_sli_mbox_sys_flush(phba);
  7025. }
  7026. /**
  7027. * lpfc_sli_eratt_read - read sli-3 error attention events
  7028. * @phba: Pointer to HBA context.
  7029. *
  7030. * This function is called to read the SLI3 device error attention registers
  7031. * for possible error attention events. The caller must hold the hostlock
  7032. * with spin_lock_irq().
  7033. *
  7034. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7035. * Register and returns 0 otherwise.
  7036. **/
  7037. static int
  7038. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7039. {
  7040. uint32_t ha_copy;
  7041. /* Read chip Host Attention (HA) register */
  7042. ha_copy = readl(phba->HAregaddr);
  7043. if (ha_copy & HA_ERATT) {
  7044. /* Read host status register to retrieve error event */
  7045. lpfc_sli_read_hs(phba);
  7046. /* Check if there is a deferred error condition is active */
  7047. if ((HS_FFER1 & phba->work_hs) &&
  7048. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7049. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7050. phba->hba_flag |= DEFER_ERATT;
  7051. /* Clear all interrupt enable conditions */
  7052. writel(0, phba->HCregaddr);
  7053. readl(phba->HCregaddr);
  7054. }
  7055. /* Set the driver HA work bitmap */
  7056. phba->work_ha |= HA_ERATT;
  7057. /* Indicate polling handles this ERATT */
  7058. phba->hba_flag |= HBA_ERATT_HANDLED;
  7059. return 1;
  7060. }
  7061. return 0;
  7062. }
  7063. /**
  7064. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7065. * @phba: Pointer to HBA context.
  7066. *
  7067. * This function is called to read the SLI4 device error attention registers
  7068. * for possible error attention events. The caller must hold the hostlock
  7069. * with spin_lock_irq().
  7070. *
  7071. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7072. * Register and returns 0 otherwise.
  7073. **/
  7074. static int
  7075. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7076. {
  7077. uint32_t uerr_sta_hi, uerr_sta_lo;
  7078. /* For now, use the SLI4 device internal unrecoverable error
  7079. * registers for error attention. This can be changed later.
  7080. */
  7081. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  7082. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  7083. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7084. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7085. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7086. "1423 HBA Unrecoverable error: "
  7087. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7088. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  7089. uerr_sta_lo, uerr_sta_hi,
  7090. phba->sli4_hba.ue_mask_lo,
  7091. phba->sli4_hba.ue_mask_hi);
  7092. phba->work_status[0] = uerr_sta_lo;
  7093. phba->work_status[1] = uerr_sta_hi;
  7094. /* Set the driver HA work bitmap */
  7095. phba->work_ha |= HA_ERATT;
  7096. /* Indicate polling handles this ERATT */
  7097. phba->hba_flag |= HBA_ERATT_HANDLED;
  7098. return 1;
  7099. }
  7100. return 0;
  7101. }
  7102. /**
  7103. * lpfc_sli_check_eratt - check error attention events
  7104. * @phba: Pointer to HBA context.
  7105. *
  7106. * This function is called from timer soft interrupt context to check HBA's
  7107. * error attention register bit for error attention events.
  7108. *
  7109. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7110. * Register and returns 0 otherwise.
  7111. **/
  7112. int
  7113. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7114. {
  7115. uint32_t ha_copy;
  7116. /* If somebody is waiting to handle an eratt, don't process it
  7117. * here. The brdkill function will do this.
  7118. */
  7119. if (phba->link_flag & LS_IGNORE_ERATT)
  7120. return 0;
  7121. /* Check if interrupt handler handles this ERATT */
  7122. spin_lock_irq(&phba->hbalock);
  7123. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7124. /* Interrupt handler has handled ERATT */
  7125. spin_unlock_irq(&phba->hbalock);
  7126. return 0;
  7127. }
  7128. /*
  7129. * If there is deferred error attention, do not check for error
  7130. * attention
  7131. */
  7132. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7133. spin_unlock_irq(&phba->hbalock);
  7134. return 0;
  7135. }
  7136. /* If PCI channel is offline, don't process it */
  7137. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7138. spin_unlock_irq(&phba->hbalock);
  7139. return 0;
  7140. }
  7141. switch (phba->sli_rev) {
  7142. case LPFC_SLI_REV2:
  7143. case LPFC_SLI_REV3:
  7144. /* Read chip Host Attention (HA) register */
  7145. ha_copy = lpfc_sli_eratt_read(phba);
  7146. break;
  7147. case LPFC_SLI_REV4:
  7148. /* Read devcie Uncoverable Error (UERR) registers */
  7149. ha_copy = lpfc_sli4_eratt_read(phba);
  7150. break;
  7151. default:
  7152. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7153. "0299 Invalid SLI revision (%d)\n",
  7154. phba->sli_rev);
  7155. ha_copy = 0;
  7156. break;
  7157. }
  7158. spin_unlock_irq(&phba->hbalock);
  7159. return ha_copy;
  7160. }
  7161. /**
  7162. * lpfc_intr_state_check - Check device state for interrupt handling
  7163. * @phba: Pointer to HBA context.
  7164. *
  7165. * This inline routine checks whether a device or its PCI slot is in a state
  7166. * that the interrupt should be handled.
  7167. *
  7168. * This function returns 0 if the device or the PCI slot is in a state that
  7169. * interrupt should be handled, otherwise -EIO.
  7170. */
  7171. static inline int
  7172. lpfc_intr_state_check(struct lpfc_hba *phba)
  7173. {
  7174. /* If the pci channel is offline, ignore all the interrupts */
  7175. if (unlikely(pci_channel_offline(phba->pcidev)))
  7176. return -EIO;
  7177. /* Update device level interrupt statistics */
  7178. phba->sli.slistat.sli_intr++;
  7179. /* Ignore all interrupts during initialization. */
  7180. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7181. return -EIO;
  7182. return 0;
  7183. }
  7184. /**
  7185. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7186. * @irq: Interrupt number.
  7187. * @dev_id: The device context pointer.
  7188. *
  7189. * This function is directly called from the PCI layer as an interrupt
  7190. * service routine when device with SLI-3 interface spec is enabled with
  7191. * MSI-X multi-message interrupt mode and there are slow-path events in
  7192. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7193. * interrupt mode, this function is called as part of the device-level
  7194. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7195. * is undergoing initialization, the interrupt handler will not process
  7196. * the interrupt. The link attention and ELS ring attention events are
  7197. * handled by the worker thread. The interrupt handler signals the worker
  7198. * thread and returns for these events. This function is called without
  7199. * any lock held. It gets the hbalock to access and update SLI data
  7200. * structures.
  7201. *
  7202. * This function returns IRQ_HANDLED when interrupt is handled else it
  7203. * returns IRQ_NONE.
  7204. **/
  7205. irqreturn_t
  7206. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7207. {
  7208. struct lpfc_hba *phba;
  7209. uint32_t ha_copy, hc_copy;
  7210. uint32_t work_ha_copy;
  7211. unsigned long status;
  7212. unsigned long iflag;
  7213. uint32_t control;
  7214. MAILBOX_t *mbox, *pmbox;
  7215. struct lpfc_vport *vport;
  7216. struct lpfc_nodelist *ndlp;
  7217. struct lpfc_dmabuf *mp;
  7218. LPFC_MBOXQ_t *pmb;
  7219. int rc;
  7220. /*
  7221. * Get the driver's phba structure from the dev_id and
  7222. * assume the HBA is not interrupting.
  7223. */
  7224. phba = (struct lpfc_hba *)dev_id;
  7225. if (unlikely(!phba))
  7226. return IRQ_NONE;
  7227. /*
  7228. * Stuff needs to be attented to when this function is invoked as an
  7229. * individual interrupt handler in MSI-X multi-message interrupt mode
  7230. */
  7231. if (phba->intr_type == MSIX) {
  7232. /* Check device state for handling interrupt */
  7233. if (lpfc_intr_state_check(phba))
  7234. return IRQ_NONE;
  7235. /* Need to read HA REG for slow-path events */
  7236. spin_lock_irqsave(&phba->hbalock, iflag);
  7237. ha_copy = readl(phba->HAregaddr);
  7238. /* If somebody is waiting to handle an eratt don't process it
  7239. * here. The brdkill function will do this.
  7240. */
  7241. if (phba->link_flag & LS_IGNORE_ERATT)
  7242. ha_copy &= ~HA_ERATT;
  7243. /* Check the need for handling ERATT in interrupt handler */
  7244. if (ha_copy & HA_ERATT) {
  7245. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7246. /* ERATT polling has handled ERATT */
  7247. ha_copy &= ~HA_ERATT;
  7248. else
  7249. /* Indicate interrupt handler handles ERATT */
  7250. phba->hba_flag |= HBA_ERATT_HANDLED;
  7251. }
  7252. /*
  7253. * If there is deferred error attention, do not check for any
  7254. * interrupt.
  7255. */
  7256. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7257. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7258. return IRQ_NONE;
  7259. }
  7260. /* Clear up only attention source related to slow-path */
  7261. hc_copy = readl(phba->HCregaddr);
  7262. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7263. HC_LAINT_ENA | HC_ERINT_ENA),
  7264. phba->HCregaddr);
  7265. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7266. phba->HAregaddr);
  7267. writel(hc_copy, phba->HCregaddr);
  7268. readl(phba->HAregaddr); /* flush */
  7269. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7270. } else
  7271. ha_copy = phba->ha_copy;
  7272. work_ha_copy = ha_copy & phba->work_ha_mask;
  7273. if (work_ha_copy) {
  7274. if (work_ha_copy & HA_LATT) {
  7275. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7276. /*
  7277. * Turn off Link Attention interrupts
  7278. * until CLEAR_LA done
  7279. */
  7280. spin_lock_irqsave(&phba->hbalock, iflag);
  7281. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7282. control = readl(phba->HCregaddr);
  7283. control &= ~HC_LAINT_ENA;
  7284. writel(control, phba->HCregaddr);
  7285. readl(phba->HCregaddr); /* flush */
  7286. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7287. }
  7288. else
  7289. work_ha_copy &= ~HA_LATT;
  7290. }
  7291. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7292. /*
  7293. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7294. * the only slow ring.
  7295. */
  7296. status = (work_ha_copy &
  7297. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7298. status >>= (4*LPFC_ELS_RING);
  7299. if (status & HA_RXMASK) {
  7300. spin_lock_irqsave(&phba->hbalock, iflag);
  7301. control = readl(phba->HCregaddr);
  7302. lpfc_debugfs_slow_ring_trc(phba,
  7303. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7304. control, status,
  7305. (uint32_t)phba->sli.slistat.sli_intr);
  7306. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7307. lpfc_debugfs_slow_ring_trc(phba,
  7308. "ISR Disable ring:"
  7309. "pwork:x%x hawork:x%x wait:x%x",
  7310. phba->work_ha, work_ha_copy,
  7311. (uint32_t)((unsigned long)
  7312. &phba->work_waitq));
  7313. control &=
  7314. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7315. writel(control, phba->HCregaddr);
  7316. readl(phba->HCregaddr); /* flush */
  7317. }
  7318. else {
  7319. lpfc_debugfs_slow_ring_trc(phba,
  7320. "ISR slow ring: pwork:"
  7321. "x%x hawork:x%x wait:x%x",
  7322. phba->work_ha, work_ha_copy,
  7323. (uint32_t)((unsigned long)
  7324. &phba->work_waitq));
  7325. }
  7326. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7327. }
  7328. }
  7329. spin_lock_irqsave(&phba->hbalock, iflag);
  7330. if (work_ha_copy & HA_ERATT) {
  7331. lpfc_sli_read_hs(phba);
  7332. /*
  7333. * Check if there is a deferred error condition
  7334. * is active
  7335. */
  7336. if ((HS_FFER1 & phba->work_hs) &&
  7337. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7338. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7339. phba->hba_flag |= DEFER_ERATT;
  7340. /* Clear all interrupt enable conditions */
  7341. writel(0, phba->HCregaddr);
  7342. readl(phba->HCregaddr);
  7343. }
  7344. }
  7345. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7346. pmb = phba->sli.mbox_active;
  7347. pmbox = &pmb->u.mb;
  7348. mbox = phba->mbox;
  7349. vport = pmb->vport;
  7350. /* First check out the status word */
  7351. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7352. if (pmbox->mbxOwner != OWN_HOST) {
  7353. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7354. /*
  7355. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7356. * mbxStatus <status>
  7357. */
  7358. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7359. LOG_SLI,
  7360. "(%d):0304 Stray Mailbox "
  7361. "Interrupt mbxCommand x%x "
  7362. "mbxStatus x%x\n",
  7363. (vport ? vport->vpi : 0),
  7364. pmbox->mbxCommand,
  7365. pmbox->mbxStatus);
  7366. /* clear mailbox attention bit */
  7367. work_ha_copy &= ~HA_MBATT;
  7368. } else {
  7369. phba->sli.mbox_active = NULL;
  7370. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7371. phba->last_completion_time = jiffies;
  7372. del_timer(&phba->sli.mbox_tmo);
  7373. if (pmb->mbox_cmpl) {
  7374. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7375. MAILBOX_CMD_SIZE);
  7376. }
  7377. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7378. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7379. lpfc_debugfs_disc_trc(vport,
  7380. LPFC_DISC_TRC_MBOX_VPORT,
  7381. "MBOX dflt rpi: : "
  7382. "status:x%x rpi:x%x",
  7383. (uint32_t)pmbox->mbxStatus,
  7384. pmbox->un.varWords[0], 0);
  7385. if (!pmbox->mbxStatus) {
  7386. mp = (struct lpfc_dmabuf *)
  7387. (pmb->context1);
  7388. ndlp = (struct lpfc_nodelist *)
  7389. pmb->context2;
  7390. /* Reg_LOGIN of dflt RPI was
  7391. * successful. new lets get
  7392. * rid of the RPI using the
  7393. * same mbox buffer.
  7394. */
  7395. lpfc_unreg_login(phba,
  7396. vport->vpi,
  7397. pmbox->un.varWords[0],
  7398. pmb);
  7399. pmb->mbox_cmpl =
  7400. lpfc_mbx_cmpl_dflt_rpi;
  7401. pmb->context1 = mp;
  7402. pmb->context2 = ndlp;
  7403. pmb->vport = vport;
  7404. rc = lpfc_sli_issue_mbox(phba,
  7405. pmb,
  7406. MBX_NOWAIT);
  7407. if (rc != MBX_BUSY)
  7408. lpfc_printf_log(phba,
  7409. KERN_ERR,
  7410. LOG_MBOX | LOG_SLI,
  7411. "0350 rc should have"
  7412. "been MBX_BUSY\n");
  7413. if (rc != MBX_NOT_FINISHED)
  7414. goto send_current_mbox;
  7415. }
  7416. }
  7417. spin_lock_irqsave(
  7418. &phba->pport->work_port_lock,
  7419. iflag);
  7420. phba->pport->work_port_events &=
  7421. ~WORKER_MBOX_TMO;
  7422. spin_unlock_irqrestore(
  7423. &phba->pport->work_port_lock,
  7424. iflag);
  7425. lpfc_mbox_cmpl_put(phba, pmb);
  7426. }
  7427. } else
  7428. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7429. if ((work_ha_copy & HA_MBATT) &&
  7430. (phba->sli.mbox_active == NULL)) {
  7431. send_current_mbox:
  7432. /* Process next mailbox command if there is one */
  7433. do {
  7434. rc = lpfc_sli_issue_mbox(phba, NULL,
  7435. MBX_NOWAIT);
  7436. } while (rc == MBX_NOT_FINISHED);
  7437. if (rc != MBX_SUCCESS)
  7438. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7439. LOG_SLI, "0349 rc should be "
  7440. "MBX_SUCCESS\n");
  7441. }
  7442. spin_lock_irqsave(&phba->hbalock, iflag);
  7443. phba->work_ha |= work_ha_copy;
  7444. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7445. lpfc_worker_wake_up(phba);
  7446. }
  7447. return IRQ_HANDLED;
  7448. } /* lpfc_sli_sp_intr_handler */
  7449. /**
  7450. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7451. * @irq: Interrupt number.
  7452. * @dev_id: The device context pointer.
  7453. *
  7454. * This function is directly called from the PCI layer as an interrupt
  7455. * service routine when device with SLI-3 interface spec is enabled with
  7456. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7457. * ring event in the HBA. However, when the device is enabled with either
  7458. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7459. * device-level interrupt handler. When the PCI slot is in error recovery
  7460. * or the HBA is undergoing initialization, the interrupt handler will not
  7461. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7462. * the intrrupt context. This function is called without any lock held.
  7463. * It gets the hbalock to access and update SLI data structures.
  7464. *
  7465. * This function returns IRQ_HANDLED when interrupt is handled else it
  7466. * returns IRQ_NONE.
  7467. **/
  7468. irqreturn_t
  7469. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7470. {
  7471. struct lpfc_hba *phba;
  7472. uint32_t ha_copy;
  7473. unsigned long status;
  7474. unsigned long iflag;
  7475. /* Get the driver's phba structure from the dev_id and
  7476. * assume the HBA is not interrupting.
  7477. */
  7478. phba = (struct lpfc_hba *) dev_id;
  7479. if (unlikely(!phba))
  7480. return IRQ_NONE;
  7481. /*
  7482. * Stuff needs to be attented to when this function is invoked as an
  7483. * individual interrupt handler in MSI-X multi-message interrupt mode
  7484. */
  7485. if (phba->intr_type == MSIX) {
  7486. /* Check device state for handling interrupt */
  7487. if (lpfc_intr_state_check(phba))
  7488. return IRQ_NONE;
  7489. /* Need to read HA REG for FCP ring and other ring events */
  7490. ha_copy = readl(phba->HAregaddr);
  7491. /* Clear up only attention source related to fast-path */
  7492. spin_lock_irqsave(&phba->hbalock, iflag);
  7493. /*
  7494. * If there is deferred error attention, do not check for
  7495. * any interrupt.
  7496. */
  7497. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7498. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7499. return IRQ_NONE;
  7500. }
  7501. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7502. phba->HAregaddr);
  7503. readl(phba->HAregaddr); /* flush */
  7504. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7505. } else
  7506. ha_copy = phba->ha_copy;
  7507. /*
  7508. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7509. */
  7510. ha_copy &= ~(phba->work_ha_mask);
  7511. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7512. status >>= (4*LPFC_FCP_RING);
  7513. if (status & HA_RXMASK)
  7514. lpfc_sli_handle_fast_ring_event(phba,
  7515. &phba->sli.ring[LPFC_FCP_RING],
  7516. status);
  7517. if (phba->cfg_multi_ring_support == 2) {
  7518. /*
  7519. * Process all events on extra ring. Take the optimized path
  7520. * for extra ring IO.
  7521. */
  7522. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7523. status >>= (4*LPFC_EXTRA_RING);
  7524. if (status & HA_RXMASK) {
  7525. lpfc_sli_handle_fast_ring_event(phba,
  7526. &phba->sli.ring[LPFC_EXTRA_RING],
  7527. status);
  7528. }
  7529. }
  7530. return IRQ_HANDLED;
  7531. } /* lpfc_sli_fp_intr_handler */
  7532. /**
  7533. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7534. * @irq: Interrupt number.
  7535. * @dev_id: The device context pointer.
  7536. *
  7537. * This function is the HBA device-level interrupt handler to device with
  7538. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7539. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7540. * requires driver attention. This function invokes the slow-path interrupt
  7541. * attention handling function and fast-path interrupt attention handling
  7542. * function in turn to process the relevant HBA attention events. This
  7543. * function is called without any lock held. It gets the hbalock to access
  7544. * and update SLI data structures.
  7545. *
  7546. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7547. * returns IRQ_NONE.
  7548. **/
  7549. irqreturn_t
  7550. lpfc_sli_intr_handler(int irq, void *dev_id)
  7551. {
  7552. struct lpfc_hba *phba;
  7553. irqreturn_t sp_irq_rc, fp_irq_rc;
  7554. unsigned long status1, status2;
  7555. uint32_t hc_copy;
  7556. /*
  7557. * Get the driver's phba structure from the dev_id and
  7558. * assume the HBA is not interrupting.
  7559. */
  7560. phba = (struct lpfc_hba *) dev_id;
  7561. if (unlikely(!phba))
  7562. return IRQ_NONE;
  7563. /* Check device state for handling interrupt */
  7564. if (lpfc_intr_state_check(phba))
  7565. return IRQ_NONE;
  7566. spin_lock(&phba->hbalock);
  7567. phba->ha_copy = readl(phba->HAregaddr);
  7568. if (unlikely(!phba->ha_copy)) {
  7569. spin_unlock(&phba->hbalock);
  7570. return IRQ_NONE;
  7571. } else if (phba->ha_copy & HA_ERATT) {
  7572. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7573. /* ERATT polling has handled ERATT */
  7574. phba->ha_copy &= ~HA_ERATT;
  7575. else
  7576. /* Indicate interrupt handler handles ERATT */
  7577. phba->hba_flag |= HBA_ERATT_HANDLED;
  7578. }
  7579. /*
  7580. * If there is deferred error attention, do not check for any interrupt.
  7581. */
  7582. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7583. spin_unlock_irq(&phba->hbalock);
  7584. return IRQ_NONE;
  7585. }
  7586. /* Clear attention sources except link and error attentions */
  7587. hc_copy = readl(phba->HCregaddr);
  7588. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  7589. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  7590. phba->HCregaddr);
  7591. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7592. writel(hc_copy, phba->HCregaddr);
  7593. readl(phba->HAregaddr); /* flush */
  7594. spin_unlock(&phba->hbalock);
  7595. /*
  7596. * Invokes slow-path host attention interrupt handling as appropriate.
  7597. */
  7598. /* status of events with mailbox and link attention */
  7599. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7600. /* status of events with ELS ring */
  7601. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7602. status2 >>= (4*LPFC_ELS_RING);
  7603. if (status1 || (status2 & HA_RXMASK))
  7604. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7605. else
  7606. sp_irq_rc = IRQ_NONE;
  7607. /*
  7608. * Invoke fast-path host attention interrupt handling as appropriate.
  7609. */
  7610. /* status of events with FCP ring */
  7611. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7612. status1 >>= (4*LPFC_FCP_RING);
  7613. /* status of events with extra ring */
  7614. if (phba->cfg_multi_ring_support == 2) {
  7615. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7616. status2 >>= (4*LPFC_EXTRA_RING);
  7617. } else
  7618. status2 = 0;
  7619. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7620. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7621. else
  7622. fp_irq_rc = IRQ_NONE;
  7623. /* Return device-level interrupt handling status */
  7624. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7625. } /* lpfc_sli_intr_handler */
  7626. /**
  7627. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7628. * @phba: pointer to lpfc hba data structure.
  7629. *
  7630. * This routine is invoked by the worker thread to process all the pending
  7631. * SLI4 FCP abort XRI events.
  7632. **/
  7633. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7634. {
  7635. struct lpfc_cq_event *cq_event;
  7636. /* First, declare the fcp xri abort event has been handled */
  7637. spin_lock_irq(&phba->hbalock);
  7638. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7639. spin_unlock_irq(&phba->hbalock);
  7640. /* Now, handle all the fcp xri abort events */
  7641. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7642. /* Get the first event from the head of the event queue */
  7643. spin_lock_irq(&phba->hbalock);
  7644. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7645. cq_event, struct lpfc_cq_event, list);
  7646. spin_unlock_irq(&phba->hbalock);
  7647. /* Notify aborted XRI for FCP work queue */
  7648. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7649. /* Free the event processed back to the free pool */
  7650. lpfc_sli4_cq_event_release(phba, cq_event);
  7651. }
  7652. }
  7653. /**
  7654. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7655. * @phba: pointer to lpfc hba data structure.
  7656. *
  7657. * This routine is invoked by the worker thread to process all the pending
  7658. * SLI4 els abort xri events.
  7659. **/
  7660. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7661. {
  7662. struct lpfc_cq_event *cq_event;
  7663. /* First, declare the els xri abort event has been handled */
  7664. spin_lock_irq(&phba->hbalock);
  7665. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7666. spin_unlock_irq(&phba->hbalock);
  7667. /* Now, handle all the els xri abort events */
  7668. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7669. /* Get the first event from the head of the event queue */
  7670. spin_lock_irq(&phba->hbalock);
  7671. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7672. cq_event, struct lpfc_cq_event, list);
  7673. spin_unlock_irq(&phba->hbalock);
  7674. /* Notify aborted XRI for ELS work queue */
  7675. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7676. /* Free the event processed back to the free pool */
  7677. lpfc_sli4_cq_event_release(phba, cq_event);
  7678. }
  7679. }
  7680. /**
  7681. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  7682. * @phba: pointer to lpfc hba data structure
  7683. * @pIocbIn: pointer to the rspiocbq
  7684. * @pIocbOut: pointer to the cmdiocbq
  7685. * @wcqe: pointer to the complete wcqe
  7686. *
  7687. * This routine transfers the fields of a command iocbq to a response iocbq
  7688. * by copying all the IOCB fields from command iocbq and transferring the
  7689. * completion status information from the complete wcqe.
  7690. **/
  7691. static void
  7692. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  7693. struct lpfc_iocbq *pIocbIn,
  7694. struct lpfc_iocbq *pIocbOut,
  7695. struct lpfc_wcqe_complete *wcqe)
  7696. {
  7697. unsigned long iflags;
  7698. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7699. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7700. sizeof(struct lpfc_iocbq) - offset);
  7701. /* Map WCQE parameters into irspiocb parameters */
  7702. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7703. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7704. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7705. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7706. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7707. wcqe->total_data_placed;
  7708. else
  7709. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7710. else {
  7711. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7712. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  7713. }
  7714. /* Pick up HBA exchange busy condition */
  7715. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  7716. spin_lock_irqsave(&phba->hbalock, iflags);
  7717. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  7718. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7719. }
  7720. }
  7721. /**
  7722. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  7723. * @phba: Pointer to HBA context object.
  7724. * @wcqe: Pointer to work-queue completion queue entry.
  7725. *
  7726. * This routine handles an ELS work-queue completion event and construct
  7727. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  7728. * discovery engine to handle.
  7729. *
  7730. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  7731. **/
  7732. static struct lpfc_iocbq *
  7733. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  7734. struct lpfc_iocbq *irspiocbq)
  7735. {
  7736. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7737. struct lpfc_iocbq *cmdiocbq;
  7738. struct lpfc_wcqe_complete *wcqe;
  7739. unsigned long iflags;
  7740. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  7741. spin_lock_irqsave(&phba->hbalock, iflags);
  7742. pring->stats.iocb_event++;
  7743. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7744. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7745. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7746. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7747. if (unlikely(!cmdiocbq)) {
  7748. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7749. "0386 ELS complete with no corresponding "
  7750. "cmdiocb: iotag (%d)\n",
  7751. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7752. lpfc_sli_release_iocbq(phba, irspiocbq);
  7753. return NULL;
  7754. }
  7755. /* Fake the irspiocbq and copy necessary response information */
  7756. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  7757. return irspiocbq;
  7758. }
  7759. /**
  7760. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7761. * @phba: Pointer to HBA context object.
  7762. * @cqe: Pointer to mailbox completion queue entry.
  7763. *
  7764. * This routine process a mailbox completion queue entry with asynchrous
  7765. * event.
  7766. *
  7767. * Return: true if work posted to worker thread, otherwise false.
  7768. **/
  7769. static bool
  7770. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7771. {
  7772. struct lpfc_cq_event *cq_event;
  7773. unsigned long iflags;
  7774. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7775. "0392 Async Event: word0:x%x, word1:x%x, "
  7776. "word2:x%x, word3:x%x\n", mcqe->word0,
  7777. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7778. /* Allocate a new internal CQ_EVENT entry */
  7779. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7780. if (!cq_event) {
  7781. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7782. "0394 Failed to allocate CQ_EVENT entry\n");
  7783. return false;
  7784. }
  7785. /* Move the CQE into an asynchronous event entry */
  7786. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7787. spin_lock_irqsave(&phba->hbalock, iflags);
  7788. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7789. /* Set the async event flag */
  7790. phba->hba_flag |= ASYNC_EVENT;
  7791. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7792. return true;
  7793. }
  7794. /**
  7795. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7796. * @phba: Pointer to HBA context object.
  7797. * @cqe: Pointer to mailbox completion queue entry.
  7798. *
  7799. * This routine process a mailbox completion queue entry with mailbox
  7800. * completion event.
  7801. *
  7802. * Return: true if work posted to worker thread, otherwise false.
  7803. **/
  7804. static bool
  7805. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7806. {
  7807. uint32_t mcqe_status;
  7808. MAILBOX_t *mbox, *pmbox;
  7809. struct lpfc_mqe *mqe;
  7810. struct lpfc_vport *vport;
  7811. struct lpfc_nodelist *ndlp;
  7812. struct lpfc_dmabuf *mp;
  7813. unsigned long iflags;
  7814. LPFC_MBOXQ_t *pmb;
  7815. bool workposted = false;
  7816. int rc;
  7817. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7818. if (!bf_get(lpfc_trailer_completed, mcqe))
  7819. goto out_no_mqe_complete;
  7820. /* Get the reference to the active mbox command */
  7821. spin_lock_irqsave(&phba->hbalock, iflags);
  7822. pmb = phba->sli.mbox_active;
  7823. if (unlikely(!pmb)) {
  7824. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7825. "1832 No pending MBOX command to handle\n");
  7826. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7827. goto out_no_mqe_complete;
  7828. }
  7829. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7830. mqe = &pmb->u.mqe;
  7831. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7832. mbox = phba->mbox;
  7833. vport = pmb->vport;
  7834. /* Reset heartbeat timer */
  7835. phba->last_completion_time = jiffies;
  7836. del_timer(&phba->sli.mbox_tmo);
  7837. /* Move mbox data to caller's mailbox region, do endian swapping */
  7838. if (pmb->mbox_cmpl && mbox)
  7839. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7840. /* Set the mailbox status with SLI4 range 0x4000 */
  7841. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7842. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7843. bf_set(lpfc_mqe_status, mqe,
  7844. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7845. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7846. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7847. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7848. "MBOX dflt rpi: status:x%x rpi:x%x",
  7849. mcqe_status,
  7850. pmbox->un.varWords[0], 0);
  7851. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7852. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7853. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7854. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7855. * RID of the PPI using the same mbox buffer.
  7856. */
  7857. lpfc_unreg_login(phba, vport->vpi,
  7858. pmbox->un.varWords[0], pmb);
  7859. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7860. pmb->context1 = mp;
  7861. pmb->context2 = ndlp;
  7862. pmb->vport = vport;
  7863. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7864. if (rc != MBX_BUSY)
  7865. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7866. LOG_SLI, "0385 rc should "
  7867. "have been MBX_BUSY\n");
  7868. if (rc != MBX_NOT_FINISHED)
  7869. goto send_current_mbox;
  7870. }
  7871. }
  7872. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7873. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7874. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7875. /* There is mailbox completion work to do */
  7876. spin_lock_irqsave(&phba->hbalock, iflags);
  7877. __lpfc_mbox_cmpl_put(phba, pmb);
  7878. phba->work_ha |= HA_MBATT;
  7879. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7880. workposted = true;
  7881. send_current_mbox:
  7882. spin_lock_irqsave(&phba->hbalock, iflags);
  7883. /* Release the mailbox command posting token */
  7884. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7885. /* Setting active mailbox pointer need to be in sync to flag clear */
  7886. phba->sli.mbox_active = NULL;
  7887. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7888. /* Wake up worker thread to post the next pending mailbox command */
  7889. lpfc_worker_wake_up(phba);
  7890. out_no_mqe_complete:
  7891. if (bf_get(lpfc_trailer_consumed, mcqe))
  7892. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7893. return workposted;
  7894. }
  7895. /**
  7896. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7897. * @phba: Pointer to HBA context object.
  7898. * @cqe: Pointer to mailbox completion queue entry.
  7899. *
  7900. * This routine process a mailbox completion queue entry, it invokes the
  7901. * proper mailbox complete handling or asynchrous event handling routine
  7902. * according to the MCQE's async bit.
  7903. *
  7904. * Return: true if work posted to worker thread, otherwise false.
  7905. **/
  7906. static bool
  7907. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7908. {
  7909. struct lpfc_mcqe mcqe;
  7910. bool workposted;
  7911. /* Copy the mailbox MCQE and convert endian order as needed */
  7912. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  7913. /* Invoke the proper event handling routine */
  7914. if (!bf_get(lpfc_trailer_async, &mcqe))
  7915. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  7916. else
  7917. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  7918. return workposted;
  7919. }
  7920. /**
  7921. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  7922. * @phba: Pointer to HBA context object.
  7923. * @wcqe: Pointer to work-queue completion queue entry.
  7924. *
  7925. * This routine handles an ELS work-queue completion event.
  7926. *
  7927. * Return: true if work posted to worker thread, otherwise false.
  7928. **/
  7929. static bool
  7930. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  7931. struct lpfc_wcqe_complete *wcqe)
  7932. {
  7933. struct lpfc_iocbq *irspiocbq;
  7934. unsigned long iflags;
  7935. /* Get an irspiocbq for later ELS response processing use */
  7936. irspiocbq = lpfc_sli_get_iocbq(phba);
  7937. if (!irspiocbq) {
  7938. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7939. "0387 Failed to allocate an iocbq\n");
  7940. return false;
  7941. }
  7942. /* Save off the slow-path queue event for work thread to process */
  7943. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  7944. spin_lock_irqsave(&phba->hbalock, iflags);
  7945. list_add_tail(&irspiocbq->cq_event.list,
  7946. &phba->sli4_hba.sp_queue_event);
  7947. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  7948. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7949. return true;
  7950. }
  7951. /**
  7952. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  7953. * @phba: Pointer to HBA context object.
  7954. * @wcqe: Pointer to work-queue completion queue entry.
  7955. *
  7956. * This routine handles slow-path WQ entry comsumed event by invoking the
  7957. * proper WQ release routine to the slow-path WQ.
  7958. **/
  7959. static void
  7960. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  7961. struct lpfc_wcqe_release *wcqe)
  7962. {
  7963. /* Check for the slow-path ELS work queue */
  7964. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  7965. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  7966. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  7967. else
  7968. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7969. "2579 Slow-path wqe consume event carries "
  7970. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  7971. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  7972. phba->sli4_hba.els_wq->queue_id);
  7973. }
  7974. /**
  7975. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  7976. * @phba: Pointer to HBA context object.
  7977. * @cq: Pointer to a WQ completion queue.
  7978. * @wcqe: Pointer to work-queue completion queue entry.
  7979. *
  7980. * This routine handles an XRI abort event.
  7981. *
  7982. * Return: true if work posted to worker thread, otherwise false.
  7983. **/
  7984. static bool
  7985. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  7986. struct lpfc_queue *cq,
  7987. struct sli4_wcqe_xri_aborted *wcqe)
  7988. {
  7989. bool workposted = false;
  7990. struct lpfc_cq_event *cq_event;
  7991. unsigned long iflags;
  7992. /* Allocate a new internal CQ_EVENT entry */
  7993. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7994. if (!cq_event) {
  7995. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7996. "0602 Failed to allocate CQ_EVENT entry\n");
  7997. return false;
  7998. }
  7999. /* Move the CQE into the proper xri abort event list */
  8000. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8001. switch (cq->subtype) {
  8002. case LPFC_FCP:
  8003. spin_lock_irqsave(&phba->hbalock, iflags);
  8004. list_add_tail(&cq_event->list,
  8005. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8006. /* Set the fcp xri abort event flag */
  8007. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8008. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8009. workposted = true;
  8010. break;
  8011. case LPFC_ELS:
  8012. spin_lock_irqsave(&phba->hbalock, iflags);
  8013. list_add_tail(&cq_event->list,
  8014. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8015. /* Set the els xri abort event flag */
  8016. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8017. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8018. workposted = true;
  8019. break;
  8020. default:
  8021. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8022. "0603 Invalid work queue CQE subtype (x%x)\n",
  8023. cq->subtype);
  8024. workposted = false;
  8025. break;
  8026. }
  8027. return workposted;
  8028. }
  8029. /**
  8030. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8031. * @phba: Pointer to HBA context object.
  8032. * @rcqe: Pointer to receive-queue completion queue entry.
  8033. *
  8034. * This routine process a receive-queue completion queue entry.
  8035. *
  8036. * Return: true if work posted to worker thread, otherwise false.
  8037. **/
  8038. static bool
  8039. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8040. {
  8041. bool workposted = false;
  8042. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8043. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8044. struct hbq_dmabuf *dma_buf;
  8045. uint32_t status;
  8046. unsigned long iflags;
  8047. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8048. goto out;
  8049. status = bf_get(lpfc_rcqe_status, rcqe);
  8050. switch (status) {
  8051. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8052. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8053. "2537 Receive Frame Truncated!!\n");
  8054. case FC_STATUS_RQ_SUCCESS:
  8055. lpfc_sli4_rq_release(hrq, drq);
  8056. spin_lock_irqsave(&phba->hbalock, iflags);
  8057. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8058. if (!dma_buf) {
  8059. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8060. goto out;
  8061. }
  8062. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8063. /* save off the frame for the word thread to process */
  8064. list_add_tail(&dma_buf->cq_event.list,
  8065. &phba->sli4_hba.sp_queue_event);
  8066. /* Frame received */
  8067. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8068. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8069. workposted = true;
  8070. break;
  8071. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8072. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8073. /* Post more buffers if possible */
  8074. spin_lock_irqsave(&phba->hbalock, iflags);
  8075. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8076. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8077. workposted = true;
  8078. break;
  8079. }
  8080. out:
  8081. return workposted;
  8082. }
  8083. /**
  8084. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8085. * @phba: Pointer to HBA context object.
  8086. * @cq: Pointer to the completion queue.
  8087. * @wcqe: Pointer to a completion queue entry.
  8088. *
  8089. * This routine process a slow-path work-queue or recieve queue completion queue
  8090. * entry.
  8091. *
  8092. * Return: true if work posted to worker thread, otherwise false.
  8093. **/
  8094. static bool
  8095. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8096. struct lpfc_cqe *cqe)
  8097. {
  8098. struct lpfc_cqe cqevt;
  8099. bool workposted = false;
  8100. /* Copy the work queue CQE and convert endian order if needed */
  8101. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8102. /* Check and process for different type of WCQE and dispatch */
  8103. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8104. case CQE_CODE_COMPL_WQE:
  8105. /* Process the WQ/RQ complete event */
  8106. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8107. (struct lpfc_wcqe_complete *)&cqevt);
  8108. break;
  8109. case CQE_CODE_RELEASE_WQE:
  8110. /* Process the WQ release event */
  8111. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8112. (struct lpfc_wcqe_release *)&cqevt);
  8113. break;
  8114. case CQE_CODE_XRI_ABORTED:
  8115. /* Process the WQ XRI abort event */
  8116. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8117. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8118. break;
  8119. case CQE_CODE_RECEIVE:
  8120. /* Process the RQ event */
  8121. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8122. (struct lpfc_rcqe *)&cqevt);
  8123. break;
  8124. default:
  8125. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8126. "0388 Not a valid WCQE code: x%x\n",
  8127. bf_get(lpfc_cqe_code, &cqevt));
  8128. break;
  8129. }
  8130. return workposted;
  8131. }
  8132. /**
  8133. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8134. * @phba: Pointer to HBA context object.
  8135. * @eqe: Pointer to fast-path event queue entry.
  8136. *
  8137. * This routine process a event queue entry from the slow-path event queue.
  8138. * It will check the MajorCode and MinorCode to determine this is for a
  8139. * completion event on a completion queue, if not, an error shall be logged
  8140. * and just return. Otherwise, it will get to the corresponding completion
  8141. * queue and process all the entries on that completion queue, rearm the
  8142. * completion queue, and then return.
  8143. *
  8144. **/
  8145. static void
  8146. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8147. {
  8148. struct lpfc_queue *cq = NULL, *childq, *speq;
  8149. struct lpfc_cqe *cqe;
  8150. bool workposted = false;
  8151. int ecount = 0;
  8152. uint16_t cqid;
  8153. if (bf_get(lpfc_eqe_major_code, eqe) != 0) {
  8154. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8155. "0359 Not a valid slow-path completion "
  8156. "event: majorcode=x%x, minorcode=x%x\n",
  8157. bf_get(lpfc_eqe_major_code, eqe),
  8158. bf_get(lpfc_eqe_minor_code, eqe));
  8159. return;
  8160. }
  8161. /* Get the reference to the corresponding CQ */
  8162. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8163. /* Search for completion queue pointer matching this cqid */
  8164. speq = phba->sli4_hba.sp_eq;
  8165. list_for_each_entry(childq, &speq->child_list, list) {
  8166. if (childq->queue_id == cqid) {
  8167. cq = childq;
  8168. break;
  8169. }
  8170. }
  8171. if (unlikely(!cq)) {
  8172. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8173. "0365 Slow-path CQ identifier (%d) does "
  8174. "not exist\n", cqid);
  8175. return;
  8176. }
  8177. /* Process all the entries to the CQ */
  8178. switch (cq->type) {
  8179. case LPFC_MCQ:
  8180. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8181. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8182. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8183. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8184. }
  8185. break;
  8186. case LPFC_WCQ:
  8187. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8188. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8189. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8190. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8191. }
  8192. break;
  8193. default:
  8194. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8195. "0370 Invalid completion queue type (%d)\n",
  8196. cq->type);
  8197. return;
  8198. }
  8199. /* Catch the no cq entry condition, log an error */
  8200. if (unlikely(ecount == 0))
  8201. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8202. "0371 No entry from the CQ: identifier "
  8203. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8204. /* In any case, flash and re-arm the RCQ */
  8205. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8206. /* wake up worker thread if there are works to be done */
  8207. if (workposted)
  8208. lpfc_worker_wake_up(phba);
  8209. }
  8210. /**
  8211. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8212. * @eqe: Pointer to fast-path completion queue entry.
  8213. *
  8214. * This routine process a fast-path work queue completion entry from fast-path
  8215. * event queue for FCP command response completion.
  8216. **/
  8217. static void
  8218. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8219. struct lpfc_wcqe_complete *wcqe)
  8220. {
  8221. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8222. struct lpfc_iocbq *cmdiocbq;
  8223. struct lpfc_iocbq irspiocbq;
  8224. unsigned long iflags;
  8225. spin_lock_irqsave(&phba->hbalock, iflags);
  8226. pring->stats.iocb_event++;
  8227. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8228. /* Check for response status */
  8229. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8230. /* If resource errors reported from HBA, reduce queue
  8231. * depth of the SCSI device.
  8232. */
  8233. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8234. IOSTAT_LOCAL_REJECT) &&
  8235. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8236. phba->lpfc_rampdown_queue_depth(phba);
  8237. }
  8238. /* Log the error status */
  8239. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8240. "0373 FCP complete error: status=x%x, "
  8241. "hw_status=x%x, total_data_specified=%d, "
  8242. "parameter=x%x, word3=x%x\n",
  8243. bf_get(lpfc_wcqe_c_status, wcqe),
  8244. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8245. wcqe->total_data_placed, wcqe->parameter,
  8246. wcqe->word3);
  8247. }
  8248. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8249. spin_lock_irqsave(&phba->hbalock, iflags);
  8250. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8251. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8252. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8253. if (unlikely(!cmdiocbq)) {
  8254. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8255. "0374 FCP complete with no corresponding "
  8256. "cmdiocb: iotag (%d)\n",
  8257. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8258. return;
  8259. }
  8260. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8261. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8262. "0375 FCP cmdiocb not callback function "
  8263. "iotag: (%d)\n",
  8264. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8265. return;
  8266. }
  8267. /* Fake the irspiocb and copy necessary response information */
  8268. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8269. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  8270. spin_lock_irqsave(&phba->hbalock, iflags);
  8271. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  8272. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8273. }
  8274. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8275. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8276. }
  8277. /**
  8278. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8279. * @phba: Pointer to HBA context object.
  8280. * @cq: Pointer to completion queue.
  8281. * @wcqe: Pointer to work-queue completion queue entry.
  8282. *
  8283. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8284. * proper WQ release routine to the slow-path WQ.
  8285. **/
  8286. static void
  8287. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8288. struct lpfc_wcqe_release *wcqe)
  8289. {
  8290. struct lpfc_queue *childwq;
  8291. bool wqid_matched = false;
  8292. uint16_t fcp_wqid;
  8293. /* Check for fast-path FCP work queue release */
  8294. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8295. list_for_each_entry(childwq, &cq->child_list, list) {
  8296. if (childwq->queue_id == fcp_wqid) {
  8297. lpfc_sli4_wq_release(childwq,
  8298. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8299. wqid_matched = true;
  8300. break;
  8301. }
  8302. }
  8303. /* Report warning log message if no match found */
  8304. if (wqid_matched != true)
  8305. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8306. "2580 Fast-path wqe consume event carries "
  8307. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8308. }
  8309. /**
  8310. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8311. * @cq: Pointer to the completion queue.
  8312. * @eqe: Pointer to fast-path completion queue entry.
  8313. *
  8314. * This routine process a fast-path work queue completion entry from fast-path
  8315. * event queue for FCP command response completion.
  8316. **/
  8317. static int
  8318. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8319. struct lpfc_cqe *cqe)
  8320. {
  8321. struct lpfc_wcqe_release wcqe;
  8322. bool workposted = false;
  8323. /* Copy the work queue CQE and convert endian order if needed */
  8324. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8325. /* Check and process for different type of WCQE and dispatch */
  8326. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8327. case CQE_CODE_COMPL_WQE:
  8328. /* Process the WQ complete event */
  8329. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8330. (struct lpfc_wcqe_complete *)&wcqe);
  8331. break;
  8332. case CQE_CODE_RELEASE_WQE:
  8333. /* Process the WQ release event */
  8334. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8335. (struct lpfc_wcqe_release *)&wcqe);
  8336. break;
  8337. case CQE_CODE_XRI_ABORTED:
  8338. /* Process the WQ XRI abort event */
  8339. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8340. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8341. break;
  8342. default:
  8343. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8344. "0144 Not a valid WCQE code: x%x\n",
  8345. bf_get(lpfc_wcqe_c_code, &wcqe));
  8346. break;
  8347. }
  8348. return workposted;
  8349. }
  8350. /**
  8351. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8352. * @phba: Pointer to HBA context object.
  8353. * @eqe: Pointer to fast-path event queue entry.
  8354. *
  8355. * This routine process a event queue entry from the fast-path event queue.
  8356. * It will check the MajorCode and MinorCode to determine this is for a
  8357. * completion event on a completion queue, if not, an error shall be logged
  8358. * and just return. Otherwise, it will get to the corresponding completion
  8359. * queue and process all the entries on the completion queue, rearm the
  8360. * completion queue, and then return.
  8361. **/
  8362. static void
  8363. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8364. uint32_t fcp_cqidx)
  8365. {
  8366. struct lpfc_queue *cq;
  8367. struct lpfc_cqe *cqe;
  8368. bool workposted = false;
  8369. uint16_t cqid;
  8370. int ecount = 0;
  8371. if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0)) {
  8372. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8373. "0366 Not a valid fast-path completion "
  8374. "event: majorcode=x%x, minorcode=x%x\n",
  8375. bf_get(lpfc_eqe_major_code, eqe),
  8376. bf_get(lpfc_eqe_minor_code, eqe));
  8377. return;
  8378. }
  8379. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8380. if (unlikely(!cq)) {
  8381. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8382. "0367 Fast-path completion queue does not "
  8383. "exist\n");
  8384. return;
  8385. }
  8386. /* Get the reference to the corresponding CQ */
  8387. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8388. if (unlikely(cqid != cq->queue_id)) {
  8389. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8390. "0368 Miss-matched fast-path completion "
  8391. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8392. cqid, cq->queue_id);
  8393. return;
  8394. }
  8395. /* Process all the entries to the CQ */
  8396. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8397. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8398. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8399. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8400. }
  8401. /* Catch the no cq entry condition */
  8402. if (unlikely(ecount == 0))
  8403. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8404. "0369 No entry from fast-path completion "
  8405. "queue fcpcqid=%d\n", cq->queue_id);
  8406. /* In any case, flash and re-arm the CQ */
  8407. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8408. /* wake up worker thread if there are works to be done */
  8409. if (workposted)
  8410. lpfc_worker_wake_up(phba);
  8411. }
  8412. static void
  8413. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8414. {
  8415. struct lpfc_eqe *eqe;
  8416. /* walk all the EQ entries and drop on the floor */
  8417. while ((eqe = lpfc_sli4_eq_get(eq)))
  8418. ;
  8419. /* Clear and re-arm the EQ */
  8420. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8421. }
  8422. /**
  8423. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8424. * @irq: Interrupt number.
  8425. * @dev_id: The device context pointer.
  8426. *
  8427. * This function is directly called from the PCI layer as an interrupt
  8428. * service routine when device with SLI-4 interface spec is enabled with
  8429. * MSI-X multi-message interrupt mode and there are slow-path events in
  8430. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8431. * interrupt mode, this function is called as part of the device-level
  8432. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8433. * undergoing initialization, the interrupt handler will not process the
  8434. * interrupt. The link attention and ELS ring attention events are handled
  8435. * by the worker thread. The interrupt handler signals the worker thread
  8436. * and returns for these events. This function is called without any lock
  8437. * held. It gets the hbalock to access and update SLI data structures.
  8438. *
  8439. * This function returns IRQ_HANDLED when interrupt is handled else it
  8440. * returns IRQ_NONE.
  8441. **/
  8442. irqreturn_t
  8443. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8444. {
  8445. struct lpfc_hba *phba;
  8446. struct lpfc_queue *speq;
  8447. struct lpfc_eqe *eqe;
  8448. unsigned long iflag;
  8449. int ecount = 0;
  8450. /*
  8451. * Get the driver's phba structure from the dev_id
  8452. */
  8453. phba = (struct lpfc_hba *)dev_id;
  8454. if (unlikely(!phba))
  8455. return IRQ_NONE;
  8456. /* Get to the EQ struct associated with this vector */
  8457. speq = phba->sli4_hba.sp_eq;
  8458. /* Check device state for handling interrupt */
  8459. if (unlikely(lpfc_intr_state_check(phba))) {
  8460. /* Check again for link_state with lock held */
  8461. spin_lock_irqsave(&phba->hbalock, iflag);
  8462. if (phba->link_state < LPFC_LINK_DOWN)
  8463. /* Flush, clear interrupt, and rearm the EQ */
  8464. lpfc_sli4_eq_flush(phba, speq);
  8465. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8466. return IRQ_NONE;
  8467. }
  8468. /*
  8469. * Process all the event on FCP slow-path EQ
  8470. */
  8471. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8472. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8473. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8474. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8475. }
  8476. /* Always clear and re-arm the slow-path EQ */
  8477. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8478. /* Catch the no cq entry condition */
  8479. if (unlikely(ecount == 0)) {
  8480. if (phba->intr_type == MSIX)
  8481. /* MSI-X treated interrupt served as no EQ share INT */
  8482. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8483. "0357 MSI-X interrupt with no EQE\n");
  8484. else
  8485. /* Non MSI-X treated on interrupt as EQ share INT */
  8486. return IRQ_NONE;
  8487. }
  8488. return IRQ_HANDLED;
  8489. } /* lpfc_sli4_sp_intr_handler */
  8490. /**
  8491. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8492. * @irq: Interrupt number.
  8493. * @dev_id: The device context pointer.
  8494. *
  8495. * This function is directly called from the PCI layer as an interrupt
  8496. * service routine when device with SLI-4 interface spec is enabled with
  8497. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8498. * ring event in the HBA. However, when the device is enabled with either
  8499. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8500. * device-level interrupt handler. When the PCI slot is in error recovery
  8501. * or the HBA is undergoing initialization, the interrupt handler will not
  8502. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8503. * the intrrupt context. This function is called without any lock held.
  8504. * It gets the hbalock to access and update SLI data structures. Note that,
  8505. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8506. * equal to that of FCP CQ index.
  8507. *
  8508. * This function returns IRQ_HANDLED when interrupt is handled else it
  8509. * returns IRQ_NONE.
  8510. **/
  8511. irqreturn_t
  8512. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8513. {
  8514. struct lpfc_hba *phba;
  8515. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8516. struct lpfc_queue *fpeq;
  8517. struct lpfc_eqe *eqe;
  8518. unsigned long iflag;
  8519. int ecount = 0;
  8520. uint32_t fcp_eqidx;
  8521. /* Get the driver's phba structure from the dev_id */
  8522. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8523. phba = fcp_eq_hdl->phba;
  8524. fcp_eqidx = fcp_eq_hdl->idx;
  8525. if (unlikely(!phba))
  8526. return IRQ_NONE;
  8527. /* Get to the EQ struct associated with this vector */
  8528. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8529. /* Check device state for handling interrupt */
  8530. if (unlikely(lpfc_intr_state_check(phba))) {
  8531. /* Check again for link_state with lock held */
  8532. spin_lock_irqsave(&phba->hbalock, iflag);
  8533. if (phba->link_state < LPFC_LINK_DOWN)
  8534. /* Flush, clear interrupt, and rearm the EQ */
  8535. lpfc_sli4_eq_flush(phba, fpeq);
  8536. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8537. return IRQ_NONE;
  8538. }
  8539. /*
  8540. * Process all the event on FCP fast-path EQ
  8541. */
  8542. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8543. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8544. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8545. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8546. }
  8547. /* Always clear and re-arm the fast-path EQ */
  8548. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8549. if (unlikely(ecount == 0)) {
  8550. if (phba->intr_type == MSIX)
  8551. /* MSI-X treated interrupt served as no EQ share INT */
  8552. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8553. "0358 MSI-X interrupt with no EQE\n");
  8554. else
  8555. /* Non MSI-X treated on interrupt as EQ share INT */
  8556. return IRQ_NONE;
  8557. }
  8558. return IRQ_HANDLED;
  8559. } /* lpfc_sli4_fp_intr_handler */
  8560. /**
  8561. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8562. * @irq: Interrupt number.
  8563. * @dev_id: The device context pointer.
  8564. *
  8565. * This function is the device-level interrupt handler to device with SLI-4
  8566. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8567. * interrupt mode is enabled and there is an event in the HBA which requires
  8568. * driver attention. This function invokes the slow-path interrupt attention
  8569. * handling function and fast-path interrupt attention handling function in
  8570. * turn to process the relevant HBA attention events. This function is called
  8571. * without any lock held. It gets the hbalock to access and update SLI data
  8572. * structures.
  8573. *
  8574. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8575. * returns IRQ_NONE.
  8576. **/
  8577. irqreturn_t
  8578. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8579. {
  8580. struct lpfc_hba *phba;
  8581. irqreturn_t sp_irq_rc, fp_irq_rc;
  8582. bool fp_handled = false;
  8583. uint32_t fcp_eqidx;
  8584. /* Get the driver's phba structure from the dev_id */
  8585. phba = (struct lpfc_hba *)dev_id;
  8586. if (unlikely(!phba))
  8587. return IRQ_NONE;
  8588. /*
  8589. * Invokes slow-path host attention interrupt handling as appropriate.
  8590. */
  8591. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8592. /*
  8593. * Invoke fast-path host attention interrupt handling as appropriate.
  8594. */
  8595. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8596. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8597. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8598. if (fp_irq_rc == IRQ_HANDLED)
  8599. fp_handled |= true;
  8600. }
  8601. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8602. } /* lpfc_sli4_intr_handler */
  8603. /**
  8604. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8605. * @queue: The queue structure to free.
  8606. *
  8607. * This function frees a queue structure and the DMAable memeory used for
  8608. * the host resident queue. This function must be called after destroying the
  8609. * queue on the HBA.
  8610. **/
  8611. void
  8612. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8613. {
  8614. struct lpfc_dmabuf *dmabuf;
  8615. if (!queue)
  8616. return;
  8617. while (!list_empty(&queue->page_list)) {
  8618. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8619. list);
  8620. dma_free_coherent(&queue->phba->pcidev->dev, PAGE_SIZE,
  8621. dmabuf->virt, dmabuf->phys);
  8622. kfree(dmabuf);
  8623. }
  8624. kfree(queue);
  8625. return;
  8626. }
  8627. /**
  8628. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8629. * @phba: The HBA that this queue is being created on.
  8630. * @entry_size: The size of each queue entry for this queue.
  8631. * @entry count: The number of entries that this queue will handle.
  8632. *
  8633. * This function allocates a queue structure and the DMAable memory used for
  8634. * the host resident queue. This function must be called before creating the
  8635. * queue on the HBA.
  8636. **/
  8637. struct lpfc_queue *
  8638. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8639. uint32_t entry_count)
  8640. {
  8641. struct lpfc_queue *queue;
  8642. struct lpfc_dmabuf *dmabuf;
  8643. int x, total_qe_count;
  8644. void *dma_pointer;
  8645. queue = kzalloc(sizeof(struct lpfc_queue) +
  8646. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8647. if (!queue)
  8648. return NULL;
  8649. queue->page_count = (PAGE_ALIGN(entry_size * entry_count))/PAGE_SIZE;
  8650. INIT_LIST_HEAD(&queue->list);
  8651. INIT_LIST_HEAD(&queue->page_list);
  8652. INIT_LIST_HEAD(&queue->child_list);
  8653. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8654. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8655. if (!dmabuf)
  8656. goto out_fail;
  8657. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8658. PAGE_SIZE, &dmabuf->phys,
  8659. GFP_KERNEL);
  8660. if (!dmabuf->virt) {
  8661. kfree(dmabuf);
  8662. goto out_fail;
  8663. }
  8664. memset(dmabuf->virt, 0, PAGE_SIZE);
  8665. dmabuf->buffer_tag = x;
  8666. list_add_tail(&dmabuf->list, &queue->page_list);
  8667. /* initialize queue's entry array */
  8668. dma_pointer = dmabuf->virt;
  8669. for (; total_qe_count < entry_count &&
  8670. dma_pointer < (PAGE_SIZE + dmabuf->virt);
  8671. total_qe_count++, dma_pointer += entry_size) {
  8672. queue->qe[total_qe_count].address = dma_pointer;
  8673. }
  8674. }
  8675. queue->entry_size = entry_size;
  8676. queue->entry_count = entry_count;
  8677. queue->phba = phba;
  8678. return queue;
  8679. out_fail:
  8680. lpfc_sli4_queue_free(queue);
  8681. return NULL;
  8682. }
  8683. /**
  8684. * lpfc_eq_create - Create an Event Queue on the HBA
  8685. * @phba: HBA structure that indicates port to create a queue on.
  8686. * @eq: The queue structure to use to create the event queue.
  8687. * @imax: The maximum interrupt per second limit.
  8688. *
  8689. * This function creates an event queue, as detailed in @eq, on a port,
  8690. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8691. *
  8692. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8693. * is used to get the entry count and entry size that are necessary to
  8694. * determine the number of pages to allocate and use for this queue. This
  8695. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8696. * event queue. This function is asynchronous and will wait for the mailbox
  8697. * command to finish before continuing.
  8698. *
  8699. * On success this function will return a zero. If unable to allocate enough
  8700. * memory this function will return ENOMEM. If the queue create mailbox command
  8701. * fails this function will return ENXIO.
  8702. **/
  8703. uint32_t
  8704. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8705. {
  8706. struct lpfc_mbx_eq_create *eq_create;
  8707. LPFC_MBOXQ_t *mbox;
  8708. int rc, length, status = 0;
  8709. struct lpfc_dmabuf *dmabuf;
  8710. uint32_t shdr_status, shdr_add_status;
  8711. union lpfc_sli4_cfg_shdr *shdr;
  8712. uint16_t dmult;
  8713. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8714. if (!mbox)
  8715. return -ENOMEM;
  8716. length = (sizeof(struct lpfc_mbx_eq_create) -
  8717. sizeof(struct lpfc_sli4_cfg_mhdr));
  8718. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8719. LPFC_MBOX_OPCODE_EQ_CREATE,
  8720. length, LPFC_SLI4_MBX_EMBED);
  8721. eq_create = &mbox->u.mqe.un.eq_create;
  8722. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8723. eq->page_count);
  8724. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8725. LPFC_EQE_SIZE);
  8726. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8727. /* Calculate delay multiper from maximum interrupt per second */
  8728. dmult = LPFC_DMULT_CONST/imax - 1;
  8729. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8730. dmult);
  8731. switch (eq->entry_count) {
  8732. default:
  8733. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8734. "0360 Unsupported EQ count. (%d)\n",
  8735. eq->entry_count);
  8736. if (eq->entry_count < 256)
  8737. return -EINVAL;
  8738. /* otherwise default to smallest count (drop through) */
  8739. case 256:
  8740. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8741. LPFC_EQ_CNT_256);
  8742. break;
  8743. case 512:
  8744. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8745. LPFC_EQ_CNT_512);
  8746. break;
  8747. case 1024:
  8748. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8749. LPFC_EQ_CNT_1024);
  8750. break;
  8751. case 2048:
  8752. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8753. LPFC_EQ_CNT_2048);
  8754. break;
  8755. case 4096:
  8756. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8757. LPFC_EQ_CNT_4096);
  8758. break;
  8759. }
  8760. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8761. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8762. putPaddrLow(dmabuf->phys);
  8763. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8764. putPaddrHigh(dmabuf->phys);
  8765. }
  8766. mbox->vport = phba->pport;
  8767. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8768. mbox->context1 = NULL;
  8769. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8770. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8771. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8772. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8773. if (shdr_status || shdr_add_status || rc) {
  8774. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8775. "2500 EQ_CREATE mailbox failed with "
  8776. "status x%x add_status x%x, mbx status x%x\n",
  8777. shdr_status, shdr_add_status, rc);
  8778. status = -ENXIO;
  8779. }
  8780. eq->type = LPFC_EQ;
  8781. eq->subtype = LPFC_NONE;
  8782. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8783. if (eq->queue_id == 0xFFFF)
  8784. status = -ENXIO;
  8785. eq->host_index = 0;
  8786. eq->hba_index = 0;
  8787. mempool_free(mbox, phba->mbox_mem_pool);
  8788. return status;
  8789. }
  8790. /**
  8791. * lpfc_cq_create - Create a Completion Queue on the HBA
  8792. * @phba: HBA structure that indicates port to create a queue on.
  8793. * @cq: The queue structure to use to create the completion queue.
  8794. * @eq: The event queue to bind this completion queue to.
  8795. *
  8796. * This function creates a completion queue, as detailed in @wq, on a port,
  8797. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8798. *
  8799. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8800. * is used to get the entry count and entry size that are necessary to
  8801. * determine the number of pages to allocate and use for this queue. The @eq
  8802. * is used to indicate which event queue to bind this completion queue to. This
  8803. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8804. * completion queue. This function is asynchronous and will wait for the mailbox
  8805. * command to finish before continuing.
  8806. *
  8807. * On success this function will return a zero. If unable to allocate enough
  8808. * memory this function will return ENOMEM. If the queue create mailbox command
  8809. * fails this function will return ENXIO.
  8810. **/
  8811. uint32_t
  8812. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8813. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8814. {
  8815. struct lpfc_mbx_cq_create *cq_create;
  8816. struct lpfc_dmabuf *dmabuf;
  8817. LPFC_MBOXQ_t *mbox;
  8818. int rc, length, status = 0;
  8819. uint32_t shdr_status, shdr_add_status;
  8820. union lpfc_sli4_cfg_shdr *shdr;
  8821. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8822. if (!mbox)
  8823. return -ENOMEM;
  8824. length = (sizeof(struct lpfc_mbx_cq_create) -
  8825. sizeof(struct lpfc_sli4_cfg_mhdr));
  8826. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8827. LPFC_MBOX_OPCODE_CQ_CREATE,
  8828. length, LPFC_SLI4_MBX_EMBED);
  8829. cq_create = &mbox->u.mqe.un.cq_create;
  8830. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8831. cq->page_count);
  8832. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8833. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8834. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8835. switch (cq->entry_count) {
  8836. default:
  8837. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8838. "0361 Unsupported CQ count. (%d)\n",
  8839. cq->entry_count);
  8840. if (cq->entry_count < 256)
  8841. return -EINVAL;
  8842. /* otherwise default to smallest count (drop through) */
  8843. case 256:
  8844. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8845. LPFC_CQ_CNT_256);
  8846. break;
  8847. case 512:
  8848. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8849. LPFC_CQ_CNT_512);
  8850. break;
  8851. case 1024:
  8852. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8853. LPFC_CQ_CNT_1024);
  8854. break;
  8855. }
  8856. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8857. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8858. putPaddrLow(dmabuf->phys);
  8859. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8860. putPaddrHigh(dmabuf->phys);
  8861. }
  8862. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8863. /* The IOCTL status is embedded in the mailbox subheader. */
  8864. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8865. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8866. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8867. if (shdr_status || shdr_add_status || rc) {
  8868. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8869. "2501 CQ_CREATE mailbox failed with "
  8870. "status x%x add_status x%x, mbx status x%x\n",
  8871. shdr_status, shdr_add_status, rc);
  8872. status = -ENXIO;
  8873. goto out;
  8874. }
  8875. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8876. if (cq->queue_id == 0xFFFF) {
  8877. status = -ENXIO;
  8878. goto out;
  8879. }
  8880. /* link the cq onto the parent eq child list */
  8881. list_add_tail(&cq->list, &eq->child_list);
  8882. /* Set up completion queue's type and subtype */
  8883. cq->type = type;
  8884. cq->subtype = subtype;
  8885. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8886. cq->host_index = 0;
  8887. cq->hba_index = 0;
  8888. out:
  8889. mempool_free(mbox, phba->mbox_mem_pool);
  8890. return status;
  8891. }
  8892. /**
  8893. * lpfc_mq_create - Create a mailbox Queue on the HBA
  8894. * @phba: HBA structure that indicates port to create a queue on.
  8895. * @mq: The queue structure to use to create the mailbox queue.
  8896. *
  8897. * This function creates a mailbox queue, as detailed in @mq, on a port,
  8898. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  8899. *
  8900. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8901. * is used to get the entry count and entry size that are necessary to
  8902. * determine the number of pages to allocate and use for this queue. This
  8903. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  8904. * mailbox queue. This function is asynchronous and will wait for the mailbox
  8905. * command to finish before continuing.
  8906. *
  8907. * On success this function will return a zero. If unable to allocate enough
  8908. * memory this function will return ENOMEM. If the queue create mailbox command
  8909. * fails this function will return ENXIO.
  8910. **/
  8911. uint32_t
  8912. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  8913. struct lpfc_queue *cq, uint32_t subtype)
  8914. {
  8915. struct lpfc_mbx_mq_create *mq_create;
  8916. struct lpfc_dmabuf *dmabuf;
  8917. LPFC_MBOXQ_t *mbox;
  8918. int rc, length, status = 0;
  8919. uint32_t shdr_status, shdr_add_status;
  8920. union lpfc_sli4_cfg_shdr *shdr;
  8921. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8922. if (!mbox)
  8923. return -ENOMEM;
  8924. length = (sizeof(struct lpfc_mbx_mq_create) -
  8925. sizeof(struct lpfc_sli4_cfg_mhdr));
  8926. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8927. LPFC_MBOX_OPCODE_MQ_CREATE,
  8928. length, LPFC_SLI4_MBX_EMBED);
  8929. mq_create = &mbox->u.mqe.un.mq_create;
  8930. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  8931. mq->page_count);
  8932. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  8933. cq->queue_id);
  8934. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  8935. switch (mq->entry_count) {
  8936. default:
  8937. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8938. "0362 Unsupported MQ count. (%d)\n",
  8939. mq->entry_count);
  8940. if (mq->entry_count < 16)
  8941. return -EINVAL;
  8942. /* otherwise default to smallest count (drop through) */
  8943. case 16:
  8944. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8945. LPFC_MQ_CNT_16);
  8946. break;
  8947. case 32:
  8948. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8949. LPFC_MQ_CNT_32);
  8950. break;
  8951. case 64:
  8952. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8953. LPFC_MQ_CNT_64);
  8954. break;
  8955. case 128:
  8956. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8957. LPFC_MQ_CNT_128);
  8958. break;
  8959. }
  8960. list_for_each_entry(dmabuf, &mq->page_list, list) {
  8961. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8962. putPaddrLow(dmabuf->phys);
  8963. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8964. putPaddrHigh(dmabuf->phys);
  8965. }
  8966. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8967. /* The IOCTL status is embedded in the mailbox subheader. */
  8968. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  8969. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8970. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8971. if (shdr_status || shdr_add_status || rc) {
  8972. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8973. "2502 MQ_CREATE mailbox failed with "
  8974. "status x%x add_status x%x, mbx status x%x\n",
  8975. shdr_status, shdr_add_status, rc);
  8976. status = -ENXIO;
  8977. goto out;
  8978. }
  8979. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, &mq_create->u.response);
  8980. if (mq->queue_id == 0xFFFF) {
  8981. status = -ENXIO;
  8982. goto out;
  8983. }
  8984. mq->type = LPFC_MQ;
  8985. mq->subtype = subtype;
  8986. mq->host_index = 0;
  8987. mq->hba_index = 0;
  8988. /* link the mq onto the parent cq child list */
  8989. list_add_tail(&mq->list, &cq->child_list);
  8990. out:
  8991. mempool_free(mbox, phba->mbox_mem_pool);
  8992. return status;
  8993. }
  8994. /**
  8995. * lpfc_wq_create - Create a Work Queue on the HBA
  8996. * @phba: HBA structure that indicates port to create a queue on.
  8997. * @wq: The queue structure to use to create the work queue.
  8998. * @cq: The completion queue to bind this work queue to.
  8999. * @subtype: The subtype of the work queue indicating its functionality.
  9000. *
  9001. * This function creates a work queue, as detailed in @wq, on a port, described
  9002. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9003. *
  9004. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9005. * is used to get the entry count and entry size that are necessary to
  9006. * determine the number of pages to allocate and use for this queue. The @cq
  9007. * is used to indicate which completion queue to bind this work queue to. This
  9008. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9009. * work queue. This function is asynchronous and will wait for the mailbox
  9010. * command to finish before continuing.
  9011. *
  9012. * On success this function will return a zero. If unable to allocate enough
  9013. * memory this function will return ENOMEM. If the queue create mailbox command
  9014. * fails this function will return ENXIO.
  9015. **/
  9016. uint32_t
  9017. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9018. struct lpfc_queue *cq, uint32_t subtype)
  9019. {
  9020. struct lpfc_mbx_wq_create *wq_create;
  9021. struct lpfc_dmabuf *dmabuf;
  9022. LPFC_MBOXQ_t *mbox;
  9023. int rc, length, status = 0;
  9024. uint32_t shdr_status, shdr_add_status;
  9025. union lpfc_sli4_cfg_shdr *shdr;
  9026. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9027. if (!mbox)
  9028. return -ENOMEM;
  9029. length = (sizeof(struct lpfc_mbx_wq_create) -
  9030. sizeof(struct lpfc_sli4_cfg_mhdr));
  9031. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9032. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9033. length, LPFC_SLI4_MBX_EMBED);
  9034. wq_create = &mbox->u.mqe.un.wq_create;
  9035. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9036. wq->page_count);
  9037. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9038. cq->queue_id);
  9039. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9040. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9041. putPaddrLow(dmabuf->phys);
  9042. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9043. putPaddrHigh(dmabuf->phys);
  9044. }
  9045. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9046. /* The IOCTL status is embedded in the mailbox subheader. */
  9047. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9048. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9049. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9050. if (shdr_status || shdr_add_status || rc) {
  9051. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9052. "2503 WQ_CREATE mailbox failed with "
  9053. "status x%x add_status x%x, mbx status x%x\n",
  9054. shdr_status, shdr_add_status, rc);
  9055. status = -ENXIO;
  9056. goto out;
  9057. }
  9058. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9059. if (wq->queue_id == 0xFFFF) {
  9060. status = -ENXIO;
  9061. goto out;
  9062. }
  9063. wq->type = LPFC_WQ;
  9064. wq->subtype = subtype;
  9065. wq->host_index = 0;
  9066. wq->hba_index = 0;
  9067. /* link the wq onto the parent cq child list */
  9068. list_add_tail(&wq->list, &cq->child_list);
  9069. out:
  9070. mempool_free(mbox, phba->mbox_mem_pool);
  9071. return status;
  9072. }
  9073. /**
  9074. * lpfc_rq_create - Create a Receive Queue on the HBA
  9075. * @phba: HBA structure that indicates port to create a queue on.
  9076. * @hrq: The queue structure to use to create the header receive queue.
  9077. * @drq: The queue structure to use to create the data receive queue.
  9078. * @cq: The completion queue to bind this work queue to.
  9079. *
  9080. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9081. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9082. * to the HBA.
  9083. *
  9084. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9085. * struct is used to get the entry count that is necessary to determine the
  9086. * number of pages to use for this queue. The @cq is used to indicate which
  9087. * completion queue to bind received buffers that are posted to these queues to.
  9088. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9089. * receive queue pair. This function is asynchronous and will wait for the
  9090. * mailbox command to finish before continuing.
  9091. *
  9092. * On success this function will return a zero. If unable to allocate enough
  9093. * memory this function will return ENOMEM. If the queue create mailbox command
  9094. * fails this function will return ENXIO.
  9095. **/
  9096. uint32_t
  9097. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9098. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9099. {
  9100. struct lpfc_mbx_rq_create *rq_create;
  9101. struct lpfc_dmabuf *dmabuf;
  9102. LPFC_MBOXQ_t *mbox;
  9103. int rc, length, status = 0;
  9104. uint32_t shdr_status, shdr_add_status;
  9105. union lpfc_sli4_cfg_shdr *shdr;
  9106. if (hrq->entry_count != drq->entry_count)
  9107. return -EINVAL;
  9108. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9109. if (!mbox)
  9110. return -ENOMEM;
  9111. length = (sizeof(struct lpfc_mbx_rq_create) -
  9112. sizeof(struct lpfc_sli4_cfg_mhdr));
  9113. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9114. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9115. length, LPFC_SLI4_MBX_EMBED);
  9116. rq_create = &mbox->u.mqe.un.rq_create;
  9117. switch (hrq->entry_count) {
  9118. default:
  9119. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9120. "2535 Unsupported RQ count. (%d)\n",
  9121. hrq->entry_count);
  9122. if (hrq->entry_count < 512)
  9123. return -EINVAL;
  9124. /* otherwise default to smallest count (drop through) */
  9125. case 512:
  9126. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9127. LPFC_RQ_RING_SIZE_512);
  9128. break;
  9129. case 1024:
  9130. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9131. LPFC_RQ_RING_SIZE_1024);
  9132. break;
  9133. case 2048:
  9134. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9135. LPFC_RQ_RING_SIZE_2048);
  9136. break;
  9137. case 4096:
  9138. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9139. LPFC_RQ_RING_SIZE_4096);
  9140. break;
  9141. }
  9142. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9143. cq->queue_id);
  9144. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9145. hrq->page_count);
  9146. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9147. LPFC_HDR_BUF_SIZE);
  9148. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9149. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9150. putPaddrLow(dmabuf->phys);
  9151. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9152. putPaddrHigh(dmabuf->phys);
  9153. }
  9154. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9155. /* The IOCTL status is embedded in the mailbox subheader. */
  9156. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9157. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9158. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9159. if (shdr_status || shdr_add_status || rc) {
  9160. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9161. "2504 RQ_CREATE mailbox failed with "
  9162. "status x%x add_status x%x, mbx status x%x\n",
  9163. shdr_status, shdr_add_status, rc);
  9164. status = -ENXIO;
  9165. goto out;
  9166. }
  9167. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9168. if (hrq->queue_id == 0xFFFF) {
  9169. status = -ENXIO;
  9170. goto out;
  9171. }
  9172. hrq->type = LPFC_HRQ;
  9173. hrq->subtype = subtype;
  9174. hrq->host_index = 0;
  9175. hrq->hba_index = 0;
  9176. /* now create the data queue */
  9177. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9178. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9179. length, LPFC_SLI4_MBX_EMBED);
  9180. switch (drq->entry_count) {
  9181. default:
  9182. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9183. "2536 Unsupported RQ count. (%d)\n",
  9184. drq->entry_count);
  9185. if (drq->entry_count < 512)
  9186. return -EINVAL;
  9187. /* otherwise default to smallest count (drop through) */
  9188. case 512:
  9189. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9190. LPFC_RQ_RING_SIZE_512);
  9191. break;
  9192. case 1024:
  9193. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9194. LPFC_RQ_RING_SIZE_1024);
  9195. break;
  9196. case 2048:
  9197. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9198. LPFC_RQ_RING_SIZE_2048);
  9199. break;
  9200. case 4096:
  9201. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9202. LPFC_RQ_RING_SIZE_4096);
  9203. break;
  9204. }
  9205. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9206. cq->queue_id);
  9207. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9208. drq->page_count);
  9209. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9210. LPFC_DATA_BUF_SIZE);
  9211. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9212. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9213. putPaddrLow(dmabuf->phys);
  9214. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9215. putPaddrHigh(dmabuf->phys);
  9216. }
  9217. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9218. /* The IOCTL status is embedded in the mailbox subheader. */
  9219. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9220. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9221. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9222. if (shdr_status || shdr_add_status || rc) {
  9223. status = -ENXIO;
  9224. goto out;
  9225. }
  9226. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9227. if (drq->queue_id == 0xFFFF) {
  9228. status = -ENXIO;
  9229. goto out;
  9230. }
  9231. drq->type = LPFC_DRQ;
  9232. drq->subtype = subtype;
  9233. drq->host_index = 0;
  9234. drq->hba_index = 0;
  9235. /* link the header and data RQs onto the parent cq child list */
  9236. list_add_tail(&hrq->list, &cq->child_list);
  9237. list_add_tail(&drq->list, &cq->child_list);
  9238. out:
  9239. mempool_free(mbox, phba->mbox_mem_pool);
  9240. return status;
  9241. }
  9242. /**
  9243. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9244. * @eq: The queue structure associated with the queue to destroy.
  9245. *
  9246. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9247. * command, specific to the type of queue, to the HBA.
  9248. *
  9249. * The @eq struct is used to get the queue ID of the queue to destroy.
  9250. *
  9251. * On success this function will return a zero. If the queue destroy mailbox
  9252. * command fails this function will return ENXIO.
  9253. **/
  9254. uint32_t
  9255. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9256. {
  9257. LPFC_MBOXQ_t *mbox;
  9258. int rc, length, status = 0;
  9259. uint32_t shdr_status, shdr_add_status;
  9260. union lpfc_sli4_cfg_shdr *shdr;
  9261. if (!eq)
  9262. return -ENODEV;
  9263. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9264. if (!mbox)
  9265. return -ENOMEM;
  9266. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9267. sizeof(struct lpfc_sli4_cfg_mhdr));
  9268. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9269. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9270. length, LPFC_SLI4_MBX_EMBED);
  9271. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9272. eq->queue_id);
  9273. mbox->vport = eq->phba->pport;
  9274. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9275. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9276. /* The IOCTL status is embedded in the mailbox subheader. */
  9277. shdr = (union lpfc_sli4_cfg_shdr *)
  9278. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9279. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9280. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9281. if (shdr_status || shdr_add_status || rc) {
  9282. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9283. "2505 EQ_DESTROY mailbox failed with "
  9284. "status x%x add_status x%x, mbx status x%x\n",
  9285. shdr_status, shdr_add_status, rc);
  9286. status = -ENXIO;
  9287. }
  9288. /* Remove eq from any list */
  9289. list_del_init(&eq->list);
  9290. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9291. return status;
  9292. }
  9293. /**
  9294. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9295. * @cq: The queue structure associated with the queue to destroy.
  9296. *
  9297. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9298. * command, specific to the type of queue, to the HBA.
  9299. *
  9300. * The @cq struct is used to get the queue ID of the queue to destroy.
  9301. *
  9302. * On success this function will return a zero. If the queue destroy mailbox
  9303. * command fails this function will return ENXIO.
  9304. **/
  9305. uint32_t
  9306. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9307. {
  9308. LPFC_MBOXQ_t *mbox;
  9309. int rc, length, status = 0;
  9310. uint32_t shdr_status, shdr_add_status;
  9311. union lpfc_sli4_cfg_shdr *shdr;
  9312. if (!cq)
  9313. return -ENODEV;
  9314. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9315. if (!mbox)
  9316. return -ENOMEM;
  9317. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9318. sizeof(struct lpfc_sli4_cfg_mhdr));
  9319. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9320. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9321. length, LPFC_SLI4_MBX_EMBED);
  9322. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9323. cq->queue_id);
  9324. mbox->vport = cq->phba->pport;
  9325. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9326. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9327. /* The IOCTL status is embedded in the mailbox subheader. */
  9328. shdr = (union lpfc_sli4_cfg_shdr *)
  9329. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9330. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9331. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9332. if (shdr_status || shdr_add_status || rc) {
  9333. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9334. "2506 CQ_DESTROY mailbox failed with "
  9335. "status x%x add_status x%x, mbx status x%x\n",
  9336. shdr_status, shdr_add_status, rc);
  9337. status = -ENXIO;
  9338. }
  9339. /* Remove cq from any list */
  9340. list_del_init(&cq->list);
  9341. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9342. return status;
  9343. }
  9344. /**
  9345. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9346. * @qm: The queue structure associated with the queue to destroy.
  9347. *
  9348. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9349. * command, specific to the type of queue, to the HBA.
  9350. *
  9351. * The @mq struct is used to get the queue ID of the queue to destroy.
  9352. *
  9353. * On success this function will return a zero. If the queue destroy mailbox
  9354. * command fails this function will return ENXIO.
  9355. **/
  9356. uint32_t
  9357. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9358. {
  9359. LPFC_MBOXQ_t *mbox;
  9360. int rc, length, status = 0;
  9361. uint32_t shdr_status, shdr_add_status;
  9362. union lpfc_sli4_cfg_shdr *shdr;
  9363. if (!mq)
  9364. return -ENODEV;
  9365. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9366. if (!mbox)
  9367. return -ENOMEM;
  9368. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9369. sizeof(struct lpfc_sli4_cfg_mhdr));
  9370. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9371. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9372. length, LPFC_SLI4_MBX_EMBED);
  9373. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9374. mq->queue_id);
  9375. mbox->vport = mq->phba->pport;
  9376. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9377. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9378. /* The IOCTL status is embedded in the mailbox subheader. */
  9379. shdr = (union lpfc_sli4_cfg_shdr *)
  9380. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9381. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9382. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9383. if (shdr_status || shdr_add_status || rc) {
  9384. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9385. "2507 MQ_DESTROY mailbox failed with "
  9386. "status x%x add_status x%x, mbx status x%x\n",
  9387. shdr_status, shdr_add_status, rc);
  9388. status = -ENXIO;
  9389. }
  9390. /* Remove mq from any list */
  9391. list_del_init(&mq->list);
  9392. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9393. return status;
  9394. }
  9395. /**
  9396. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9397. * @wq: The queue structure associated with the queue to destroy.
  9398. *
  9399. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9400. * command, specific to the type of queue, to the HBA.
  9401. *
  9402. * The @wq struct is used to get the queue ID of the queue to destroy.
  9403. *
  9404. * On success this function will return a zero. If the queue destroy mailbox
  9405. * command fails this function will return ENXIO.
  9406. **/
  9407. uint32_t
  9408. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9409. {
  9410. LPFC_MBOXQ_t *mbox;
  9411. int rc, length, status = 0;
  9412. uint32_t shdr_status, shdr_add_status;
  9413. union lpfc_sli4_cfg_shdr *shdr;
  9414. if (!wq)
  9415. return -ENODEV;
  9416. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9417. if (!mbox)
  9418. return -ENOMEM;
  9419. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9420. sizeof(struct lpfc_sli4_cfg_mhdr));
  9421. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9422. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9423. length, LPFC_SLI4_MBX_EMBED);
  9424. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9425. wq->queue_id);
  9426. mbox->vport = wq->phba->pport;
  9427. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9428. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9429. shdr = (union lpfc_sli4_cfg_shdr *)
  9430. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9431. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9432. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9433. if (shdr_status || shdr_add_status || rc) {
  9434. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9435. "2508 WQ_DESTROY mailbox failed with "
  9436. "status x%x add_status x%x, mbx status x%x\n",
  9437. shdr_status, shdr_add_status, rc);
  9438. status = -ENXIO;
  9439. }
  9440. /* Remove wq from any list */
  9441. list_del_init(&wq->list);
  9442. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9443. return status;
  9444. }
  9445. /**
  9446. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9447. * @rq: The queue structure associated with the queue to destroy.
  9448. *
  9449. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9450. * command, specific to the type of queue, to the HBA.
  9451. *
  9452. * The @rq struct is used to get the queue ID of the queue to destroy.
  9453. *
  9454. * On success this function will return a zero. If the queue destroy mailbox
  9455. * command fails this function will return ENXIO.
  9456. **/
  9457. uint32_t
  9458. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9459. struct lpfc_queue *drq)
  9460. {
  9461. LPFC_MBOXQ_t *mbox;
  9462. int rc, length, status = 0;
  9463. uint32_t shdr_status, shdr_add_status;
  9464. union lpfc_sli4_cfg_shdr *shdr;
  9465. if (!hrq || !drq)
  9466. return -ENODEV;
  9467. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9468. if (!mbox)
  9469. return -ENOMEM;
  9470. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9471. sizeof(struct mbox_header));
  9472. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9473. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9474. length, LPFC_SLI4_MBX_EMBED);
  9475. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9476. hrq->queue_id);
  9477. mbox->vport = hrq->phba->pport;
  9478. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9479. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9480. /* The IOCTL status is embedded in the mailbox subheader. */
  9481. shdr = (union lpfc_sli4_cfg_shdr *)
  9482. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9483. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9484. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9485. if (shdr_status || shdr_add_status || rc) {
  9486. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9487. "2509 RQ_DESTROY mailbox failed with "
  9488. "status x%x add_status x%x, mbx status x%x\n",
  9489. shdr_status, shdr_add_status, rc);
  9490. if (rc != MBX_TIMEOUT)
  9491. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9492. return -ENXIO;
  9493. }
  9494. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9495. drq->queue_id);
  9496. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9497. shdr = (union lpfc_sli4_cfg_shdr *)
  9498. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9499. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9500. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9501. if (shdr_status || shdr_add_status || rc) {
  9502. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9503. "2510 RQ_DESTROY mailbox failed with "
  9504. "status x%x add_status x%x, mbx status x%x\n",
  9505. shdr_status, shdr_add_status, rc);
  9506. status = -ENXIO;
  9507. }
  9508. list_del_init(&hrq->list);
  9509. list_del_init(&drq->list);
  9510. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9511. return status;
  9512. }
  9513. /**
  9514. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9515. * @phba: The virtual port for which this call being executed.
  9516. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9517. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9518. * @xritag: the xritag that ties this io to the SGL pages.
  9519. *
  9520. * This routine will post the sgl pages for the IO that has the xritag
  9521. * that is in the iocbq structure. The xritag is assigned during iocbq
  9522. * creation and persists for as long as the driver is loaded.
  9523. * if the caller has fewer than 256 scatter gather segments to map then
  9524. * pdma_phys_addr1 should be 0.
  9525. * If the caller needs to map more than 256 scatter gather segment then
  9526. * pdma_phys_addr1 should be a valid physical address.
  9527. * physical address for SGLs must be 64 byte aligned.
  9528. * If you are going to map 2 SGL's then the first one must have 256 entries
  9529. * the second sgl can have between 1 and 256 entries.
  9530. *
  9531. * Return codes:
  9532. * 0 - Success
  9533. * -ENXIO, -ENOMEM - Failure
  9534. **/
  9535. int
  9536. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9537. dma_addr_t pdma_phys_addr0,
  9538. dma_addr_t pdma_phys_addr1,
  9539. uint16_t xritag)
  9540. {
  9541. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9542. LPFC_MBOXQ_t *mbox;
  9543. int rc;
  9544. uint32_t shdr_status, shdr_add_status;
  9545. union lpfc_sli4_cfg_shdr *shdr;
  9546. if (xritag == NO_XRI) {
  9547. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9548. "0364 Invalid param:\n");
  9549. return -EINVAL;
  9550. }
  9551. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9552. if (!mbox)
  9553. return -ENOMEM;
  9554. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9555. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9556. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9557. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9558. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9559. &mbox->u.mqe.un.post_sgl_pages;
  9560. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9561. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9562. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9563. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9564. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9565. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9566. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9567. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9568. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9569. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9570. if (!phba->sli4_hba.intr_enable)
  9571. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9572. else
  9573. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9574. /* The IOCTL status is embedded in the mailbox subheader. */
  9575. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9576. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9577. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9578. if (rc != MBX_TIMEOUT)
  9579. mempool_free(mbox, phba->mbox_mem_pool);
  9580. if (shdr_status || shdr_add_status || rc) {
  9581. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9582. "2511 POST_SGL mailbox failed with "
  9583. "status x%x add_status x%x, mbx status x%x\n",
  9584. shdr_status, shdr_add_status, rc);
  9585. rc = -ENXIO;
  9586. }
  9587. return 0;
  9588. }
  9589. /**
  9590. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9591. * @phba: The virtual port for which this call being executed.
  9592. *
  9593. * This routine will remove all of the sgl pages registered with the hba.
  9594. *
  9595. * Return codes:
  9596. * 0 - Success
  9597. * -ENXIO, -ENOMEM - Failure
  9598. **/
  9599. int
  9600. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9601. {
  9602. LPFC_MBOXQ_t *mbox;
  9603. int rc;
  9604. uint32_t shdr_status, shdr_add_status;
  9605. union lpfc_sli4_cfg_shdr *shdr;
  9606. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9607. if (!mbox)
  9608. return -ENOMEM;
  9609. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9610. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9611. LPFC_SLI4_MBX_EMBED);
  9612. if (!phba->sli4_hba.intr_enable)
  9613. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9614. else
  9615. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9616. /* The IOCTL status is embedded in the mailbox subheader. */
  9617. shdr = (union lpfc_sli4_cfg_shdr *)
  9618. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9619. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9620. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9621. if (rc != MBX_TIMEOUT)
  9622. mempool_free(mbox, phba->mbox_mem_pool);
  9623. if (shdr_status || shdr_add_status || rc) {
  9624. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9625. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9626. "status x%x add_status x%x, mbx status x%x\n",
  9627. shdr_status, shdr_add_status, rc);
  9628. rc = -ENXIO;
  9629. }
  9630. return rc;
  9631. }
  9632. /**
  9633. * lpfc_sli4_next_xritag - Get an xritag for the io
  9634. * @phba: Pointer to HBA context object.
  9635. *
  9636. * This function gets an xritag for the iocb. If there is no unused xritag
  9637. * it will return 0xffff.
  9638. * The function returns the allocated xritag if successful, else returns zero.
  9639. * Zero is not a valid xritag.
  9640. * The caller is not required to hold any lock.
  9641. **/
  9642. uint16_t
  9643. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9644. {
  9645. uint16_t xritag;
  9646. spin_lock_irq(&phba->hbalock);
  9647. xritag = phba->sli4_hba.next_xri;
  9648. if ((xritag != (uint16_t) -1) && xritag <
  9649. (phba->sli4_hba.max_cfg_param.max_xri
  9650. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9651. phba->sli4_hba.next_xri++;
  9652. phba->sli4_hba.max_cfg_param.xri_used++;
  9653. spin_unlock_irq(&phba->hbalock);
  9654. return xritag;
  9655. }
  9656. spin_unlock_irq(&phba->hbalock);
  9657. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9658. "2004 Failed to allocate XRI.last XRITAG is %d"
  9659. " Max XRI is %d, Used XRI is %d\n",
  9660. phba->sli4_hba.next_xri,
  9661. phba->sli4_hba.max_cfg_param.max_xri,
  9662. phba->sli4_hba.max_cfg_param.xri_used);
  9663. return -1;
  9664. }
  9665. /**
  9666. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9667. * @phba: pointer to lpfc hba data structure.
  9668. *
  9669. * This routine is invoked to post a block of driver's sgl pages to the
  9670. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9671. * is only called when the driver is loading and after all IO has been
  9672. * stopped.
  9673. **/
  9674. int
  9675. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9676. {
  9677. struct lpfc_sglq *sglq_entry;
  9678. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9679. struct sgl_page_pairs *sgl_pg_pairs;
  9680. void *viraddr;
  9681. LPFC_MBOXQ_t *mbox;
  9682. uint32_t reqlen, alloclen, pg_pairs;
  9683. uint32_t mbox_tmo;
  9684. uint16_t xritag_start = 0;
  9685. int els_xri_cnt, rc = 0;
  9686. uint32_t shdr_status, shdr_add_status;
  9687. union lpfc_sli4_cfg_shdr *shdr;
  9688. /* The number of sgls to be posted */
  9689. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9690. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9691. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9692. if (reqlen > PAGE_SIZE) {
  9693. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9694. "2559 Block sgl registration required DMA "
  9695. "size (%d) great than a page\n", reqlen);
  9696. return -ENOMEM;
  9697. }
  9698. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9699. if (!mbox) {
  9700. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9701. "2560 Failed to allocate mbox cmd memory\n");
  9702. return -ENOMEM;
  9703. }
  9704. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9705. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9706. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9707. LPFC_SLI4_MBX_NEMBED);
  9708. if (alloclen < reqlen) {
  9709. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9710. "0285 Allocated DMA memory size (%d) is "
  9711. "less than the requested DMA memory "
  9712. "size (%d)\n", alloclen, reqlen);
  9713. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9714. return -ENOMEM;
  9715. }
  9716. /* Get the first SGE entry from the non-embedded DMA memory */
  9717. viraddr = mbox->sge_array->addr[0];
  9718. /* Set up the SGL pages in the non-embedded DMA pages */
  9719. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9720. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9721. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9722. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9723. /* Set up the sge entry */
  9724. sgl_pg_pairs->sgl_pg0_addr_lo =
  9725. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9726. sgl_pg_pairs->sgl_pg0_addr_hi =
  9727. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9728. sgl_pg_pairs->sgl_pg1_addr_lo =
  9729. cpu_to_le32(putPaddrLow(0));
  9730. sgl_pg_pairs->sgl_pg1_addr_hi =
  9731. cpu_to_le32(putPaddrHigh(0));
  9732. /* Keep the first xritag on the list */
  9733. if (pg_pairs == 0)
  9734. xritag_start = sglq_entry->sli4_xritag;
  9735. sgl_pg_pairs++;
  9736. }
  9737. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9738. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  9739. /* Perform endian conversion if necessary */
  9740. sgl->word0 = cpu_to_le32(sgl->word0);
  9741. if (!phba->sli4_hba.intr_enable)
  9742. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9743. else {
  9744. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9745. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9746. }
  9747. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9748. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9749. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9750. if (rc != MBX_TIMEOUT)
  9751. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9752. if (shdr_status || shdr_add_status || rc) {
  9753. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9754. "2513 POST_SGL_BLOCK mailbox command failed "
  9755. "status x%x add_status x%x mbx status x%x\n",
  9756. shdr_status, shdr_add_status, rc);
  9757. rc = -ENXIO;
  9758. }
  9759. return rc;
  9760. }
  9761. /**
  9762. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9763. * @phba: pointer to lpfc hba data structure.
  9764. * @sblist: pointer to scsi buffer list.
  9765. * @count: number of scsi buffers on the list.
  9766. *
  9767. * This routine is invoked to post a block of @count scsi sgl pages from a
  9768. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9769. * No Lock is held.
  9770. *
  9771. **/
  9772. int
  9773. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9774. int cnt)
  9775. {
  9776. struct lpfc_scsi_buf *psb;
  9777. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9778. struct sgl_page_pairs *sgl_pg_pairs;
  9779. void *viraddr;
  9780. LPFC_MBOXQ_t *mbox;
  9781. uint32_t reqlen, alloclen, pg_pairs;
  9782. uint32_t mbox_tmo;
  9783. uint16_t xritag_start = 0;
  9784. int rc = 0;
  9785. uint32_t shdr_status, shdr_add_status;
  9786. dma_addr_t pdma_phys_bpl1;
  9787. union lpfc_sli4_cfg_shdr *shdr;
  9788. /* Calculate the requested length of the dma memory */
  9789. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  9790. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9791. if (reqlen > PAGE_SIZE) {
  9792. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9793. "0217 Block sgl registration required DMA "
  9794. "size (%d) great than a page\n", reqlen);
  9795. return -ENOMEM;
  9796. }
  9797. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9798. if (!mbox) {
  9799. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9800. "0283 Failed to allocate mbox cmd memory\n");
  9801. return -ENOMEM;
  9802. }
  9803. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9804. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9805. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9806. LPFC_SLI4_MBX_NEMBED);
  9807. if (alloclen < reqlen) {
  9808. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9809. "2561 Allocated DMA memory size (%d) is "
  9810. "less than the requested DMA memory "
  9811. "size (%d)\n", alloclen, reqlen);
  9812. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9813. return -ENOMEM;
  9814. }
  9815. /* Get the first SGE entry from the non-embedded DMA memory */
  9816. viraddr = mbox->sge_array->addr[0];
  9817. /* Set up the SGL pages in the non-embedded DMA pages */
  9818. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9819. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9820. pg_pairs = 0;
  9821. list_for_each_entry(psb, sblist, list) {
  9822. /* Set up the sge entry */
  9823. sgl_pg_pairs->sgl_pg0_addr_lo =
  9824. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  9825. sgl_pg_pairs->sgl_pg0_addr_hi =
  9826. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  9827. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  9828. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  9829. else
  9830. pdma_phys_bpl1 = 0;
  9831. sgl_pg_pairs->sgl_pg1_addr_lo =
  9832. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  9833. sgl_pg_pairs->sgl_pg1_addr_hi =
  9834. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  9835. /* Keep the first xritag on the list */
  9836. if (pg_pairs == 0)
  9837. xritag_start = psb->cur_iocbq.sli4_xritag;
  9838. sgl_pg_pairs++;
  9839. pg_pairs++;
  9840. }
  9841. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9842. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9843. /* Perform endian conversion if necessary */
  9844. sgl->word0 = cpu_to_le32(sgl->word0);
  9845. if (!phba->sli4_hba.intr_enable)
  9846. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9847. else {
  9848. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9849. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9850. }
  9851. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9852. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9853. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9854. if (rc != MBX_TIMEOUT)
  9855. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9856. if (shdr_status || shdr_add_status || rc) {
  9857. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9858. "2564 POST_SGL_BLOCK mailbox command failed "
  9859. "status x%x add_status x%x mbx status x%x\n",
  9860. shdr_status, shdr_add_status, rc);
  9861. rc = -ENXIO;
  9862. }
  9863. return rc;
  9864. }
  9865. /**
  9866. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  9867. * @phba: pointer to lpfc_hba struct that the frame was received on
  9868. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9869. *
  9870. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  9871. * valid type of frame that the LPFC driver will handle. This function will
  9872. * return a zero if the frame is a valid frame or a non zero value when the
  9873. * frame does not pass the check.
  9874. **/
  9875. static int
  9876. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  9877. {
  9878. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  9879. char *type_names[] = FC_TYPE_NAMES_INIT;
  9880. struct fc_vft_header *fc_vft_hdr;
  9881. switch (fc_hdr->fh_r_ctl) {
  9882. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  9883. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  9884. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  9885. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  9886. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  9887. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  9888. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  9889. case FC_RCTL_DD_CMD_STATUS: /* command status */
  9890. case FC_RCTL_ELS_REQ: /* extended link services request */
  9891. case FC_RCTL_ELS_REP: /* extended link services reply */
  9892. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  9893. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  9894. case FC_RCTL_BA_NOP: /* basic link service NOP */
  9895. case FC_RCTL_BA_ABTS: /* basic link service abort */
  9896. case FC_RCTL_BA_RMC: /* remove connection */
  9897. case FC_RCTL_BA_ACC: /* basic accept */
  9898. case FC_RCTL_BA_RJT: /* basic reject */
  9899. case FC_RCTL_BA_PRMT:
  9900. case FC_RCTL_ACK_1: /* acknowledge_1 */
  9901. case FC_RCTL_ACK_0: /* acknowledge_0 */
  9902. case FC_RCTL_P_RJT: /* port reject */
  9903. case FC_RCTL_F_RJT: /* fabric reject */
  9904. case FC_RCTL_P_BSY: /* port busy */
  9905. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  9906. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  9907. case FC_RCTL_LCR: /* link credit reset */
  9908. case FC_RCTL_END: /* end */
  9909. break;
  9910. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  9911. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9912. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  9913. return lpfc_fc_frame_check(phba, fc_hdr);
  9914. default:
  9915. goto drop;
  9916. }
  9917. switch (fc_hdr->fh_type) {
  9918. case FC_TYPE_BLS:
  9919. case FC_TYPE_ELS:
  9920. case FC_TYPE_FCP:
  9921. case FC_TYPE_CT:
  9922. break;
  9923. case FC_TYPE_IP:
  9924. case FC_TYPE_ILS:
  9925. default:
  9926. goto drop;
  9927. }
  9928. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  9929. "2538 Received frame rctl:%s type:%s\n",
  9930. rctl_names[fc_hdr->fh_r_ctl],
  9931. type_names[fc_hdr->fh_type]);
  9932. return 0;
  9933. drop:
  9934. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  9935. "2539 Dropped frame rctl:%s type:%s\n",
  9936. rctl_names[fc_hdr->fh_r_ctl],
  9937. type_names[fc_hdr->fh_type]);
  9938. return 1;
  9939. }
  9940. /**
  9941. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  9942. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9943. *
  9944. * This function processes the FC header to retrieve the VFI from the VF
  9945. * header, if one exists. This function will return the VFI if one exists
  9946. * or 0 if no VSAN Header exists.
  9947. **/
  9948. static uint32_t
  9949. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  9950. {
  9951. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9952. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  9953. return 0;
  9954. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  9955. }
  9956. /**
  9957. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  9958. * @phba: Pointer to the HBA structure to search for the vport on
  9959. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9960. * @fcfi: The FC Fabric ID that the frame came from
  9961. *
  9962. * This function searches the @phba for a vport that matches the content of the
  9963. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  9964. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  9965. * returns the matching vport pointer or NULL if unable to match frame to a
  9966. * vport.
  9967. **/
  9968. static struct lpfc_vport *
  9969. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  9970. uint16_t fcfi)
  9971. {
  9972. struct lpfc_vport **vports;
  9973. struct lpfc_vport *vport = NULL;
  9974. int i;
  9975. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  9976. fc_hdr->fh_d_id[1] << 8 |
  9977. fc_hdr->fh_d_id[2]);
  9978. vports = lpfc_create_vport_work_array(phba);
  9979. if (vports != NULL)
  9980. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  9981. if (phba->fcf.fcfi == fcfi &&
  9982. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  9983. vports[i]->fc_myDID == did) {
  9984. vport = vports[i];
  9985. break;
  9986. }
  9987. }
  9988. lpfc_destroy_vport_work_array(phba, vports);
  9989. return vport;
  9990. }
  9991. /**
  9992. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  9993. * @vport: The vport to work on.
  9994. *
  9995. * This function updates the receive sequence time stamp for this vport. The
  9996. * receive sequence time stamp indicates the time that the last frame of the
  9997. * the sequence that has been idle for the longest amount of time was received.
  9998. * the driver uses this time stamp to indicate if any received sequences have
  9999. * timed out.
  10000. **/
  10001. void
  10002. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10003. {
  10004. struct lpfc_dmabuf *h_buf;
  10005. struct hbq_dmabuf *dmabuf = NULL;
  10006. /* get the oldest sequence on the rcv list */
  10007. h_buf = list_get_first(&vport->rcv_buffer_list,
  10008. struct lpfc_dmabuf, list);
  10009. if (!h_buf)
  10010. return;
  10011. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10012. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10013. }
  10014. /**
  10015. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10016. * @vport: The vport that the received sequences were sent to.
  10017. *
  10018. * This function cleans up all outstanding received sequences. This is called
  10019. * by the driver when a link event or user action invalidates all the received
  10020. * sequences.
  10021. **/
  10022. void
  10023. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10024. {
  10025. struct lpfc_dmabuf *h_buf, *hnext;
  10026. struct lpfc_dmabuf *d_buf, *dnext;
  10027. struct hbq_dmabuf *dmabuf = NULL;
  10028. /* start with the oldest sequence on the rcv list */
  10029. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10030. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10031. list_del_init(&dmabuf->hbuf.list);
  10032. list_for_each_entry_safe(d_buf, dnext,
  10033. &dmabuf->dbuf.list, list) {
  10034. list_del_init(&d_buf->list);
  10035. lpfc_in_buf_free(vport->phba, d_buf);
  10036. }
  10037. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10038. }
  10039. }
  10040. /**
  10041. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10042. * @vport: The vport that the received sequences were sent to.
  10043. *
  10044. * This function determines whether any received sequences have timed out by
  10045. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10046. * indicates that there is at least one timed out sequence this routine will
  10047. * go through the received sequences one at a time from most inactive to most
  10048. * active to determine which ones need to be cleaned up. Once it has determined
  10049. * that a sequence needs to be cleaned up it will simply free up the resources
  10050. * without sending an abort.
  10051. **/
  10052. void
  10053. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10054. {
  10055. struct lpfc_dmabuf *h_buf, *hnext;
  10056. struct lpfc_dmabuf *d_buf, *dnext;
  10057. struct hbq_dmabuf *dmabuf = NULL;
  10058. unsigned long timeout;
  10059. int abort_count = 0;
  10060. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10061. vport->rcv_buffer_time_stamp);
  10062. if (list_empty(&vport->rcv_buffer_list) ||
  10063. time_before(jiffies, timeout))
  10064. return;
  10065. /* start with the oldest sequence on the rcv list */
  10066. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10067. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10068. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10069. dmabuf->time_stamp);
  10070. if (time_before(jiffies, timeout))
  10071. break;
  10072. abort_count++;
  10073. list_del_init(&dmabuf->hbuf.list);
  10074. list_for_each_entry_safe(d_buf, dnext,
  10075. &dmabuf->dbuf.list, list) {
  10076. list_del_init(&d_buf->list);
  10077. lpfc_in_buf_free(vport->phba, d_buf);
  10078. }
  10079. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10080. }
  10081. if (abort_count)
  10082. lpfc_update_rcv_time_stamp(vport);
  10083. }
  10084. /**
  10085. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10086. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10087. *
  10088. * This function searches through the existing incomplete sequences that have
  10089. * been sent to this @vport. If the frame matches one of the incomplete
  10090. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10091. * make up that sequence. If no sequence is found that matches this frame then
  10092. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10093. * This function returns a pointer to the first dmabuf in the sequence list that
  10094. * the frame was linked to.
  10095. **/
  10096. static struct hbq_dmabuf *
  10097. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10098. {
  10099. struct fc_frame_header *new_hdr;
  10100. struct fc_frame_header *temp_hdr;
  10101. struct lpfc_dmabuf *d_buf;
  10102. struct lpfc_dmabuf *h_buf;
  10103. struct hbq_dmabuf *seq_dmabuf = NULL;
  10104. struct hbq_dmabuf *temp_dmabuf = NULL;
  10105. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10106. dmabuf->time_stamp = jiffies;
  10107. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10108. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10109. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10110. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10111. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10112. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10113. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10114. continue;
  10115. /* found a pending sequence that matches this frame */
  10116. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10117. break;
  10118. }
  10119. if (!seq_dmabuf) {
  10120. /*
  10121. * This indicates first frame received for this sequence.
  10122. * Queue the buffer on the vport's rcv_buffer_list.
  10123. */
  10124. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10125. lpfc_update_rcv_time_stamp(vport);
  10126. return dmabuf;
  10127. }
  10128. temp_hdr = seq_dmabuf->hbuf.virt;
  10129. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10130. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10131. list_del_init(&seq_dmabuf->hbuf.list);
  10132. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10133. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10134. lpfc_update_rcv_time_stamp(vport);
  10135. return dmabuf;
  10136. }
  10137. /* move this sequence to the tail to indicate a young sequence */
  10138. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10139. seq_dmabuf->time_stamp = jiffies;
  10140. lpfc_update_rcv_time_stamp(vport);
  10141. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10142. temp_hdr = dmabuf->hbuf.virt;
  10143. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10144. return seq_dmabuf;
  10145. }
  10146. /* find the correct place in the sequence to insert this frame */
  10147. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10148. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10149. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10150. /*
  10151. * If the frame's sequence count is greater than the frame on
  10152. * the list then insert the frame right after this frame
  10153. */
  10154. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10155. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10156. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10157. return seq_dmabuf;
  10158. }
  10159. }
  10160. return NULL;
  10161. }
  10162. /**
  10163. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10164. * @vport: pointer to a vitural port
  10165. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10166. *
  10167. * This function tries to abort from the partially assembed sequence, described
  10168. * by the information from basic abbort @dmabuf. It checks to see whether such
  10169. * partially assembled sequence held by the driver. If so, it shall free up all
  10170. * the frames from the partially assembled sequence.
  10171. *
  10172. * Return
  10173. * true -- if there is matching partially assembled sequence present and all
  10174. * the frames freed with the sequence;
  10175. * false -- if there is no matching partially assembled sequence present so
  10176. * nothing got aborted in the lower layer driver
  10177. **/
  10178. static bool
  10179. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10180. struct hbq_dmabuf *dmabuf)
  10181. {
  10182. struct fc_frame_header *new_hdr;
  10183. struct fc_frame_header *temp_hdr;
  10184. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10185. struct hbq_dmabuf *seq_dmabuf = NULL;
  10186. /* Use the hdr_buf to find the sequence that matches this frame */
  10187. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10188. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10189. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10190. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10191. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10192. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10193. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10194. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10195. continue;
  10196. /* found a pending sequence that matches this frame */
  10197. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10198. break;
  10199. }
  10200. /* Free up all the frames from the partially assembled sequence */
  10201. if (seq_dmabuf) {
  10202. list_for_each_entry_safe(d_buf, n_buf,
  10203. &seq_dmabuf->dbuf.list, list) {
  10204. list_del_init(&d_buf->list);
  10205. lpfc_in_buf_free(vport->phba, d_buf);
  10206. }
  10207. return true;
  10208. }
  10209. return false;
  10210. }
  10211. /**
  10212. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10213. * @phba: Pointer to HBA context object.
  10214. * @cmd_iocbq: pointer to the command iocbq structure.
  10215. * @rsp_iocbq: pointer to the response iocbq structure.
  10216. *
  10217. * This function handles the sequence abort accept iocb command complete
  10218. * event. It properly releases the memory allocated to the sequence abort
  10219. * accept iocb.
  10220. **/
  10221. static void
  10222. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10223. struct lpfc_iocbq *cmd_iocbq,
  10224. struct lpfc_iocbq *rsp_iocbq)
  10225. {
  10226. if (cmd_iocbq)
  10227. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10228. }
  10229. /**
  10230. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10231. * @phba: Pointer to HBA context object.
  10232. * @fc_hdr: pointer to a FC frame header.
  10233. *
  10234. * This function sends a basic accept to a previous unsol sequence abort
  10235. * event after aborting the sequence handling.
  10236. **/
  10237. static void
  10238. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10239. struct fc_frame_header *fc_hdr)
  10240. {
  10241. struct lpfc_iocbq *ctiocb = NULL;
  10242. struct lpfc_nodelist *ndlp;
  10243. uint16_t oxid, rxid;
  10244. uint32_t sid, fctl;
  10245. IOCB_t *icmd;
  10246. if (!lpfc_is_link_up(phba))
  10247. return;
  10248. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10249. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10250. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10251. ndlp = lpfc_findnode_did(phba->pport, sid);
  10252. if (!ndlp) {
  10253. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10254. "1268 Find ndlp returned NULL for oxid:x%x "
  10255. "SID:x%x\n", oxid, sid);
  10256. return;
  10257. }
  10258. /* Allocate buffer for acc iocb */
  10259. ctiocb = lpfc_sli_get_iocbq(phba);
  10260. if (!ctiocb)
  10261. return;
  10262. /* Extract the F_CTL field from FC_HDR */
  10263. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10264. icmd = &ctiocb->iocb;
  10265. icmd->un.xseq64.bdl.bdeSize = 0;
  10266. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10267. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10268. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10269. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10270. /* Fill in the rest of iocb fields */
  10271. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10272. icmd->ulpBdeCount = 0;
  10273. icmd->ulpLe = 1;
  10274. icmd->ulpClass = CLASS3;
  10275. icmd->ulpContext = ndlp->nlp_rpi;
  10276. ctiocb->iocb_cmpl = NULL;
  10277. ctiocb->vport = phba->pport;
  10278. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10279. if (fctl & FC_FC_EX_CTX) {
  10280. /* ABTS sent by responder to CT exchange, construction
  10281. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10282. * field and RX_ID from ABTS for RX_ID field.
  10283. */
  10284. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10285. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10286. ctiocb->sli4_xritag = oxid;
  10287. } else {
  10288. /* ABTS sent by initiator to CT exchange, construction
  10289. * of BA_ACC will need to allocate a new XRI as for the
  10290. * XRI_TAG and RX_ID fields.
  10291. */
  10292. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  10293. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  10294. ctiocb->sli4_xritag = NO_XRI;
  10295. }
  10296. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  10297. /* Xmit CT abts accept on exchange <xid> */
  10298. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10299. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10300. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10301. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10302. }
  10303. /**
  10304. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10305. * @vport: Pointer to the vport on which this sequence was received
  10306. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10307. *
  10308. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10309. * receive sequence is only partially assembed by the driver, it shall abort
  10310. * the partially assembled frames for the sequence. Otherwise, if the
  10311. * unsolicited receive sequence has been completely assembled and passed to
  10312. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10313. * unsolicited sequence has been aborted. After that, it will issue a basic
  10314. * accept to accept the abort.
  10315. **/
  10316. void
  10317. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10318. struct hbq_dmabuf *dmabuf)
  10319. {
  10320. struct lpfc_hba *phba = vport->phba;
  10321. struct fc_frame_header fc_hdr;
  10322. uint32_t fctl;
  10323. bool abts_par;
  10324. /* Make a copy of fc_hdr before the dmabuf being released */
  10325. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  10326. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  10327. if (fctl & FC_FC_EX_CTX) {
  10328. /*
  10329. * ABTS sent by responder to exchange, just free the buffer
  10330. */
  10331. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10332. } else {
  10333. /*
  10334. * ABTS sent by initiator to exchange, need to do cleanup
  10335. */
  10336. /* Try to abort partially assembled seq */
  10337. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  10338. /* Send abort to ULP if partially seq abort failed */
  10339. if (abts_par == false)
  10340. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  10341. else
  10342. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10343. }
  10344. /* Send basic accept (BA_ACC) to the abort requester */
  10345. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  10346. }
  10347. /**
  10348. * lpfc_seq_complete - Indicates if a sequence is complete
  10349. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10350. *
  10351. * This function checks the sequence, starting with the frame described by
  10352. * @dmabuf, to see if all the frames associated with this sequence are present.
  10353. * the frames associated with this sequence are linked to the @dmabuf using the
  10354. * dbuf list. This function looks for two major things. 1) That the first frame
  10355. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  10356. * set. 3) That there are no holes in the sequence count. The function will
  10357. * return 1 when the sequence is complete, otherwise it will return 0.
  10358. **/
  10359. static int
  10360. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  10361. {
  10362. struct fc_frame_header *hdr;
  10363. struct lpfc_dmabuf *d_buf;
  10364. struct hbq_dmabuf *seq_dmabuf;
  10365. uint32_t fctl;
  10366. int seq_count = 0;
  10367. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10368. /* make sure first fame of sequence has a sequence count of zero */
  10369. if (hdr->fh_seq_cnt != seq_count)
  10370. return 0;
  10371. fctl = (hdr->fh_f_ctl[0] << 16 |
  10372. hdr->fh_f_ctl[1] << 8 |
  10373. hdr->fh_f_ctl[2]);
  10374. /* If last frame of sequence we can return success. */
  10375. if (fctl & FC_FC_END_SEQ)
  10376. return 1;
  10377. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  10378. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10379. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10380. /* If there is a hole in the sequence count then fail. */
  10381. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  10382. return 0;
  10383. fctl = (hdr->fh_f_ctl[0] << 16 |
  10384. hdr->fh_f_ctl[1] << 8 |
  10385. hdr->fh_f_ctl[2]);
  10386. /* If last frame of sequence we can return success. */
  10387. if (fctl & FC_FC_END_SEQ)
  10388. return 1;
  10389. }
  10390. return 0;
  10391. }
  10392. /**
  10393. * lpfc_prep_seq - Prep sequence for ULP processing
  10394. * @vport: Pointer to the vport on which this sequence was received
  10395. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10396. *
  10397. * This function takes a sequence, described by a list of frames, and creates
  10398. * a list of iocbq structures to describe the sequence. This iocbq list will be
  10399. * used to issue to the generic unsolicited sequence handler. This routine
  10400. * returns a pointer to the first iocbq in the list. If the function is unable
  10401. * to allocate an iocbq then it throw out the received frames that were not
  10402. * able to be described and return a pointer to the first iocbq. If unable to
  10403. * allocate any iocbqs (including the first) this function will return NULL.
  10404. **/
  10405. static struct lpfc_iocbq *
  10406. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  10407. {
  10408. struct lpfc_dmabuf *d_buf, *n_buf;
  10409. struct lpfc_iocbq *first_iocbq, *iocbq;
  10410. struct fc_frame_header *fc_hdr;
  10411. uint32_t sid;
  10412. struct ulp_bde64 *pbde;
  10413. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10414. /* remove from receive buffer list */
  10415. list_del_init(&seq_dmabuf->hbuf.list);
  10416. lpfc_update_rcv_time_stamp(vport);
  10417. /* get the Remote Port's SID */
  10418. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10419. /* Get an iocbq struct to fill in. */
  10420. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  10421. if (first_iocbq) {
  10422. /* Initialize the first IOCB. */
  10423. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  10424. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  10425. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  10426. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  10427. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  10428. vport->vpi + vport->phba->vpi_base;
  10429. /* put the first buffer into the first IOCBq */
  10430. first_iocbq->context2 = &seq_dmabuf->dbuf;
  10431. first_iocbq->context3 = NULL;
  10432. first_iocbq->iocb.ulpBdeCount = 1;
  10433. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10434. LPFC_DATA_BUF_SIZE;
  10435. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10436. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10437. bf_get(lpfc_rcqe_length,
  10438. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10439. }
  10440. iocbq = first_iocbq;
  10441. /*
  10442. * Each IOCBq can have two Buffers assigned, so go through the list
  10443. * of buffers for this sequence and save two buffers in each IOCBq
  10444. */
  10445. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10446. if (!iocbq) {
  10447. lpfc_in_buf_free(vport->phba, d_buf);
  10448. continue;
  10449. }
  10450. if (!iocbq->context3) {
  10451. iocbq->context3 = d_buf;
  10452. iocbq->iocb.ulpBdeCount++;
  10453. pbde = (struct ulp_bde64 *)
  10454. &iocbq->iocb.unsli3.sli3Words[4];
  10455. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  10456. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10457. bf_get(lpfc_rcqe_length,
  10458. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10459. } else {
  10460. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10461. if (!iocbq) {
  10462. if (first_iocbq) {
  10463. first_iocbq->iocb.ulpStatus =
  10464. IOSTAT_FCP_RSP_ERROR;
  10465. first_iocbq->iocb.un.ulpWord[4] =
  10466. IOERR_NO_RESOURCES;
  10467. }
  10468. lpfc_in_buf_free(vport->phba, d_buf);
  10469. continue;
  10470. }
  10471. iocbq->context2 = d_buf;
  10472. iocbq->context3 = NULL;
  10473. iocbq->iocb.ulpBdeCount = 1;
  10474. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10475. LPFC_DATA_BUF_SIZE;
  10476. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10477. bf_get(lpfc_rcqe_length,
  10478. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10479. iocbq->iocb.un.rcvels.remoteID = sid;
  10480. list_add_tail(&iocbq->list, &first_iocbq->list);
  10481. }
  10482. }
  10483. return first_iocbq;
  10484. }
  10485. static void
  10486. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  10487. struct hbq_dmabuf *seq_dmabuf)
  10488. {
  10489. struct fc_frame_header *fc_hdr;
  10490. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  10491. struct lpfc_hba *phba = vport->phba;
  10492. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10493. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10494. if (!iocbq) {
  10495. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10496. "2707 Ring %d handler: Failed to allocate "
  10497. "iocb Rctl x%x Type x%x received\n",
  10498. LPFC_ELS_RING,
  10499. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10500. return;
  10501. }
  10502. if (!lpfc_complete_unsol_iocb(phba,
  10503. &phba->sli.ring[LPFC_ELS_RING],
  10504. iocbq, fc_hdr->fh_r_ctl,
  10505. fc_hdr->fh_type))
  10506. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10507. "2540 Ring %d handler: unexpected Rctl "
  10508. "x%x Type x%x received\n",
  10509. LPFC_ELS_RING,
  10510. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10511. /* Free iocb created in lpfc_prep_seq */
  10512. list_for_each_entry_safe(curr_iocb, next_iocb,
  10513. &iocbq->list, list) {
  10514. list_del_init(&curr_iocb->list);
  10515. lpfc_sli_release_iocbq(phba, curr_iocb);
  10516. }
  10517. lpfc_sli_release_iocbq(phba, iocbq);
  10518. }
  10519. /**
  10520. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10521. * @phba: Pointer to HBA context object.
  10522. *
  10523. * This function is called with no lock held. This function processes all
  10524. * the received buffers and gives it to upper layers when a received buffer
  10525. * indicates that it is the final frame in the sequence. The interrupt
  10526. * service routine processes received buffers at interrupt contexts and adds
  10527. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10528. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10529. * appropriate receive function when the final frame in a sequence is received.
  10530. **/
  10531. void
  10532. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10533. struct hbq_dmabuf *dmabuf)
  10534. {
  10535. struct hbq_dmabuf *seq_dmabuf;
  10536. struct fc_frame_header *fc_hdr;
  10537. struct lpfc_vport *vport;
  10538. uint32_t fcfi;
  10539. /* Process each received buffer */
  10540. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10541. /* check to see if this a valid type of frame */
  10542. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10543. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10544. return;
  10545. }
  10546. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10547. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10548. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  10549. /* throw out the frame */
  10550. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10551. return;
  10552. }
  10553. /* Handle the basic abort sequence (BA_ABTS) event */
  10554. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  10555. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  10556. return;
  10557. }
  10558. /* Link this frame */
  10559. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10560. if (!seq_dmabuf) {
  10561. /* unable to add frame to vport - throw it out */
  10562. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10563. return;
  10564. }
  10565. /* If not last frame in sequence continue processing frames. */
  10566. if (!lpfc_seq_complete(seq_dmabuf))
  10567. return;
  10568. /* Send the complete sequence to the upper layer protocol */
  10569. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  10570. }
  10571. /**
  10572. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10573. * @phba: pointer to lpfc hba data structure.
  10574. *
  10575. * This routine is invoked to post rpi header templates to the
  10576. * HBA consistent with the SLI-4 interface spec. This routine
  10577. * posts a PAGE_SIZE memory region to the port to hold up to
  10578. * PAGE_SIZE modulo 64 rpi context headers.
  10579. *
  10580. * This routine does not require any locks. It's usage is expected
  10581. * to be driver load or reset recovery when the driver is
  10582. * sequential.
  10583. *
  10584. * Return codes
  10585. * 0 - successful
  10586. * EIO - The mailbox failed to complete successfully.
  10587. * When this error occurs, the driver is not guaranteed
  10588. * to have any rpi regions posted to the device and
  10589. * must either attempt to repost the regions or take a
  10590. * fatal error.
  10591. **/
  10592. int
  10593. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10594. {
  10595. struct lpfc_rpi_hdr *rpi_page;
  10596. uint32_t rc = 0;
  10597. /* Post all rpi memory regions to the port. */
  10598. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10599. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10600. if (rc != MBX_SUCCESS) {
  10601. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10602. "2008 Error %d posting all rpi "
  10603. "headers\n", rc);
  10604. rc = -EIO;
  10605. break;
  10606. }
  10607. }
  10608. return rc;
  10609. }
  10610. /**
  10611. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10612. * @phba: pointer to lpfc hba data structure.
  10613. * @rpi_page: pointer to the rpi memory region.
  10614. *
  10615. * This routine is invoked to post a single rpi header to the
  10616. * HBA consistent with the SLI-4 interface spec. This memory region
  10617. * maps up to 64 rpi context regions.
  10618. *
  10619. * Return codes
  10620. * 0 - successful
  10621. * ENOMEM - No available memory
  10622. * EIO - The mailbox failed to complete successfully.
  10623. **/
  10624. int
  10625. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10626. {
  10627. LPFC_MBOXQ_t *mboxq;
  10628. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10629. uint32_t rc = 0;
  10630. uint32_t mbox_tmo;
  10631. uint32_t shdr_status, shdr_add_status;
  10632. union lpfc_sli4_cfg_shdr *shdr;
  10633. /* The port is notified of the header region via a mailbox command. */
  10634. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10635. if (!mboxq) {
  10636. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10637. "2001 Unable to allocate memory for issuing "
  10638. "SLI_CONFIG_SPECIAL mailbox command\n");
  10639. return -ENOMEM;
  10640. }
  10641. /* Post all rpi memory regions to the port. */
  10642. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10643. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10644. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10645. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10646. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10647. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10648. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10649. hdr_tmpl, rpi_page->page_count);
  10650. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10651. rpi_page->start_rpi);
  10652. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10653. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10654. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10655. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10656. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10657. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10658. if (rc != MBX_TIMEOUT)
  10659. mempool_free(mboxq, phba->mbox_mem_pool);
  10660. if (shdr_status || shdr_add_status || rc) {
  10661. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10662. "2514 POST_RPI_HDR mailbox failed with "
  10663. "status x%x add_status x%x, mbx status x%x\n",
  10664. shdr_status, shdr_add_status, rc);
  10665. rc = -ENXIO;
  10666. }
  10667. return rc;
  10668. }
  10669. /**
  10670. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10671. * @phba: pointer to lpfc hba data structure.
  10672. *
  10673. * This routine is invoked to post rpi header templates to the
  10674. * HBA consistent with the SLI-4 interface spec. This routine
  10675. * posts a PAGE_SIZE memory region to the port to hold up to
  10676. * PAGE_SIZE modulo 64 rpi context headers.
  10677. *
  10678. * Returns
  10679. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  10680. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10681. **/
  10682. int
  10683. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10684. {
  10685. int rpi;
  10686. uint16_t max_rpi, rpi_base, rpi_limit;
  10687. uint16_t rpi_remaining;
  10688. struct lpfc_rpi_hdr *rpi_hdr;
  10689. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10690. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10691. rpi_limit = phba->sli4_hba.next_rpi;
  10692. /*
  10693. * The valid rpi range is not guaranteed to be zero-based. Start
  10694. * the search at the rpi_base as reported by the port.
  10695. */
  10696. spin_lock_irq(&phba->hbalock);
  10697. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10698. if (rpi >= rpi_limit || rpi < rpi_base)
  10699. rpi = LPFC_RPI_ALLOC_ERROR;
  10700. else {
  10701. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10702. phba->sli4_hba.max_cfg_param.rpi_used++;
  10703. phba->sli4_hba.rpi_count++;
  10704. }
  10705. /*
  10706. * Don't try to allocate more rpi header regions if the device limit
  10707. * on available rpis max has been exhausted.
  10708. */
  10709. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10710. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10711. spin_unlock_irq(&phba->hbalock);
  10712. return rpi;
  10713. }
  10714. /*
  10715. * If the driver is running low on rpi resources, allocate another
  10716. * page now. Note that the next_rpi value is used because
  10717. * it represents how many are actually in use whereas max_rpi notes
  10718. * how many are supported max by the device.
  10719. */
  10720. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10721. phba->sli4_hba.rpi_count;
  10722. spin_unlock_irq(&phba->hbalock);
  10723. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10724. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10725. if (!rpi_hdr) {
  10726. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10727. "2002 Error Could not grow rpi "
  10728. "count\n");
  10729. } else {
  10730. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10731. }
  10732. }
  10733. return rpi;
  10734. }
  10735. /**
  10736. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10737. * @phba: pointer to lpfc hba data structure.
  10738. *
  10739. * This routine is invoked to release an rpi to the pool of
  10740. * available rpis maintained by the driver.
  10741. **/
  10742. void
  10743. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10744. {
  10745. spin_lock_irq(&phba->hbalock);
  10746. clear_bit(rpi, phba->sli4_hba.rpi_bmask);
  10747. phba->sli4_hba.rpi_count--;
  10748. phba->sli4_hba.max_cfg_param.rpi_used--;
  10749. spin_unlock_irq(&phba->hbalock);
  10750. }
  10751. /**
  10752. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10753. * @phba: pointer to lpfc hba data structure.
  10754. *
  10755. * This routine is invoked to remove the memory region that
  10756. * provided rpi via a bitmask.
  10757. **/
  10758. void
  10759. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10760. {
  10761. kfree(phba->sli4_hba.rpi_bmask);
  10762. }
  10763. /**
  10764. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10765. * @phba: pointer to lpfc hba data structure.
  10766. *
  10767. * This routine is invoked to remove the memory region that
  10768. * provided rpi via a bitmask.
  10769. **/
  10770. int
  10771. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10772. {
  10773. LPFC_MBOXQ_t *mboxq;
  10774. struct lpfc_hba *phba = ndlp->phba;
  10775. int rc;
  10776. /* The port is notified of the header region via a mailbox command. */
  10777. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10778. if (!mboxq)
  10779. return -ENOMEM;
  10780. /* Post all rpi memory regions to the port. */
  10781. lpfc_resume_rpi(mboxq, ndlp);
  10782. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10783. if (rc == MBX_NOT_FINISHED) {
  10784. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10785. "2010 Resume RPI Mailbox failed "
  10786. "status %d, mbxStatus x%x\n", rc,
  10787. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10788. mempool_free(mboxq, phba->mbox_mem_pool);
  10789. return -EIO;
  10790. }
  10791. return 0;
  10792. }
  10793. /**
  10794. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  10795. * @phba: pointer to lpfc hba data structure.
  10796. * @vpi: vpi value to activate with the port.
  10797. *
  10798. * This routine is invoked to activate a vpi with the
  10799. * port when the host intends to use vports with a
  10800. * nonzero vpi.
  10801. *
  10802. * Returns:
  10803. * 0 success
  10804. * -Evalue otherwise
  10805. **/
  10806. int
  10807. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  10808. {
  10809. LPFC_MBOXQ_t *mboxq;
  10810. int rc = 0;
  10811. int retval = MBX_SUCCESS;
  10812. uint32_t mbox_tmo;
  10813. if (vpi == 0)
  10814. return -EINVAL;
  10815. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10816. if (!mboxq)
  10817. return -ENOMEM;
  10818. lpfc_init_vpi(phba, mboxq, vpi);
  10819. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  10820. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  10821. if (rc != MBX_SUCCESS) {
  10822. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10823. "2022 INIT VPI Mailbox failed "
  10824. "status %d, mbxStatus x%x\n", rc,
  10825. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10826. retval = -EIO;
  10827. }
  10828. if (rc != MBX_TIMEOUT)
  10829. mempool_free(mboxq, phba->mbox_mem_pool);
  10830. return retval;
  10831. }
  10832. /**
  10833. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  10834. * @phba: pointer to lpfc hba data structure.
  10835. * @mboxq: Pointer to mailbox object.
  10836. *
  10837. * This routine is invoked to manually add a single FCF record. The caller
  10838. * must pass a completely initialized FCF_Record. This routine takes
  10839. * care of the nonembedded mailbox operations.
  10840. **/
  10841. static void
  10842. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  10843. {
  10844. void *virt_addr;
  10845. union lpfc_sli4_cfg_shdr *shdr;
  10846. uint32_t shdr_status, shdr_add_status;
  10847. virt_addr = mboxq->sge_array->addr[0];
  10848. /* The IOCTL status is embedded in the mailbox subheader. */
  10849. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  10850. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10851. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10852. if ((shdr_status || shdr_add_status) &&
  10853. (shdr_status != STATUS_FCF_IN_USE))
  10854. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10855. "2558 ADD_FCF_RECORD mailbox failed with "
  10856. "status x%x add_status x%x\n",
  10857. shdr_status, shdr_add_status);
  10858. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10859. }
  10860. /**
  10861. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  10862. * @phba: pointer to lpfc hba data structure.
  10863. * @fcf_record: pointer to the initialized fcf record to add.
  10864. *
  10865. * This routine is invoked to manually add a single FCF record. The caller
  10866. * must pass a completely initialized FCF_Record. This routine takes
  10867. * care of the nonembedded mailbox operations.
  10868. **/
  10869. int
  10870. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  10871. {
  10872. int rc = 0;
  10873. LPFC_MBOXQ_t *mboxq;
  10874. uint8_t *bytep;
  10875. void *virt_addr;
  10876. dma_addr_t phys_addr;
  10877. struct lpfc_mbx_sge sge;
  10878. uint32_t alloc_len, req_len;
  10879. uint32_t fcfindex;
  10880. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10881. if (!mboxq) {
  10882. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10883. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  10884. return -ENOMEM;
  10885. }
  10886. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  10887. sizeof(uint32_t);
  10888. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10889. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10890. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  10891. req_len, LPFC_SLI4_MBX_NEMBED);
  10892. if (alloc_len < req_len) {
  10893. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10894. "2523 Allocated DMA memory size (x%x) is "
  10895. "less than the requested DMA memory "
  10896. "size (x%x)\n", alloc_len, req_len);
  10897. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10898. return -ENOMEM;
  10899. }
  10900. /*
  10901. * Get the first SGE entry from the non-embedded DMA memory. This
  10902. * routine only uses a single SGE.
  10903. */
  10904. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10905. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10906. virt_addr = mboxq->sge_array->addr[0];
  10907. /*
  10908. * Configure the FCF record for FCFI 0. This is the driver's
  10909. * hardcoded default and gets used in nonFIP mode.
  10910. */
  10911. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  10912. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10913. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  10914. /*
  10915. * Copy the fcf_index and the FCF Record Data. The data starts after
  10916. * the FCoE header plus word10. The data copy needs to be endian
  10917. * correct.
  10918. */
  10919. bytep += sizeof(uint32_t);
  10920. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  10921. mboxq->vport = phba->pport;
  10922. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  10923. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10924. if (rc == MBX_NOT_FINISHED) {
  10925. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10926. "2515 ADD_FCF_RECORD mailbox failed with "
  10927. "status 0x%x\n", rc);
  10928. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10929. rc = -EIO;
  10930. } else
  10931. rc = 0;
  10932. return rc;
  10933. }
  10934. /**
  10935. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  10936. * @phba: pointer to lpfc hba data structure.
  10937. * @fcf_record: pointer to the fcf record to write the default data.
  10938. * @fcf_index: FCF table entry index.
  10939. *
  10940. * This routine is invoked to build the driver's default FCF record. The
  10941. * values used are hardcoded. This routine handles memory initialization.
  10942. *
  10943. **/
  10944. void
  10945. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  10946. struct fcf_record *fcf_record,
  10947. uint16_t fcf_index)
  10948. {
  10949. memset(fcf_record, 0, sizeof(struct fcf_record));
  10950. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  10951. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  10952. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  10953. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  10954. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  10955. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  10956. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  10957. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  10958. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  10959. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  10960. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  10961. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  10962. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  10963. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  10964. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  10965. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  10966. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  10967. /* Set the VLAN bit map */
  10968. if (phba->valid_vlan) {
  10969. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  10970. = 1 << (phba->vlan_id % 8);
  10971. }
  10972. }
  10973. /**
  10974. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  10975. * @phba: pointer to lpfc hba data structure.
  10976. * @fcf_index: FCF table entry offset.
  10977. *
  10978. * This routine is invoked to scan the entire FCF table by reading FCF
  10979. * record and processing it one at a time starting from the @fcf_index
  10980. * for initial FCF discovery or fast FCF failover rediscovery.
  10981. *
  10982. * Return 0 if the mailbox command is submitted sucessfully, none 0
  10983. * otherwise.
  10984. **/
  10985. int
  10986. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  10987. {
  10988. int rc = 0, error;
  10989. LPFC_MBOXQ_t *mboxq;
  10990. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  10991. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10992. if (!mboxq) {
  10993. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10994. "2000 Failed to allocate mbox for "
  10995. "READ_FCF cmd\n");
  10996. error = -ENOMEM;
  10997. goto fail_fcf_scan;
  10998. }
  10999. /* Construct the read FCF record mailbox command */
  11000. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11001. if (rc) {
  11002. error = -EINVAL;
  11003. goto fail_fcf_scan;
  11004. }
  11005. /* Issue the mailbox command asynchronously */
  11006. mboxq->vport = phba->pport;
  11007. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11008. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11009. if (rc == MBX_NOT_FINISHED)
  11010. error = -EIO;
  11011. else {
  11012. spin_lock_irq(&phba->hbalock);
  11013. phba->hba_flag |= FCF_DISC_INPROGRESS;
  11014. spin_unlock_irq(&phba->hbalock);
  11015. /* Reset FCF round robin index bmask for new scan */
  11016. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  11017. memset(phba->fcf.fcf_rr_bmask, 0,
  11018. sizeof(*phba->fcf.fcf_rr_bmask));
  11019. error = 0;
  11020. }
  11021. fail_fcf_scan:
  11022. if (error) {
  11023. if (mboxq)
  11024. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11025. /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
  11026. spin_lock_irq(&phba->hbalock);
  11027. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  11028. spin_unlock_irq(&phba->hbalock);
  11029. }
  11030. return error;
  11031. }
  11032. /**
  11033. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for round robin fcf.
  11034. * @phba: pointer to lpfc hba data structure.
  11035. * @fcf_index: FCF table entry offset.
  11036. *
  11037. * This routine is invoked to read an FCF record indicated by @fcf_index
  11038. * and to use it for FLOGI round robin FCF failover.
  11039. *
  11040. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11041. * otherwise.
  11042. **/
  11043. int
  11044. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11045. {
  11046. int rc = 0, error;
  11047. LPFC_MBOXQ_t *mboxq;
  11048. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11049. if (!mboxq) {
  11050. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11051. "2763 Failed to allocate mbox for "
  11052. "READ_FCF cmd\n");
  11053. error = -ENOMEM;
  11054. goto fail_fcf_read;
  11055. }
  11056. /* Construct the read FCF record mailbox command */
  11057. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11058. if (rc) {
  11059. error = -EINVAL;
  11060. goto fail_fcf_read;
  11061. }
  11062. /* Issue the mailbox command asynchronously */
  11063. mboxq->vport = phba->pport;
  11064. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11065. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11066. if (rc == MBX_NOT_FINISHED)
  11067. error = -EIO;
  11068. else
  11069. error = 0;
  11070. fail_fcf_read:
  11071. if (error && mboxq)
  11072. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11073. return error;
  11074. }
  11075. /**
  11076. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11077. * @phba: pointer to lpfc hba data structure.
  11078. * @fcf_index: FCF table entry offset.
  11079. *
  11080. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11081. * determine whether it's eligible for FLOGI round robin failover list.
  11082. *
  11083. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11084. * otherwise.
  11085. **/
  11086. int
  11087. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11088. {
  11089. int rc = 0, error;
  11090. LPFC_MBOXQ_t *mboxq;
  11091. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11092. if (!mboxq) {
  11093. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11094. "2758 Failed to allocate mbox for "
  11095. "READ_FCF cmd\n");
  11096. error = -ENOMEM;
  11097. goto fail_fcf_read;
  11098. }
  11099. /* Construct the read FCF record mailbox command */
  11100. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11101. if (rc) {
  11102. error = -EINVAL;
  11103. goto fail_fcf_read;
  11104. }
  11105. /* Issue the mailbox command asynchronously */
  11106. mboxq->vport = phba->pport;
  11107. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  11108. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11109. if (rc == MBX_NOT_FINISHED)
  11110. error = -EIO;
  11111. else
  11112. error = 0;
  11113. fail_fcf_read:
  11114. if (error && mboxq)
  11115. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11116. return error;
  11117. }
  11118. /**
  11119. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  11120. * @phba: pointer to lpfc hba data structure.
  11121. *
  11122. * This routine is to get the next eligible FCF record index in a round
  11123. * robin fashion. If the next eligible FCF record index equals to the
  11124. * initial round robin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  11125. * shall be returned, otherwise, the next eligible FCF record's index
  11126. * shall be returned.
  11127. **/
  11128. uint16_t
  11129. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  11130. {
  11131. uint16_t next_fcf_index;
  11132. /* Search from the currently registered FCF index */
  11133. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11134. LPFC_SLI4_FCF_TBL_INDX_MAX,
  11135. phba->fcf.current_rec.fcf_indx);
  11136. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  11137. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  11138. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11139. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  11140. /* Round robin failover stop condition */
  11141. if (next_fcf_index == phba->fcf.fcf_rr_init_indx)
  11142. return LPFC_FCOE_FCF_NEXT_NONE;
  11143. return next_fcf_index;
  11144. }
  11145. /**
  11146. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  11147. * @phba: pointer to lpfc hba data structure.
  11148. *
  11149. * This routine sets the FCF record index in to the eligible bmask for
  11150. * round robin failover search. It checks to make sure that the index
  11151. * does not go beyond the range of the driver allocated bmask dimension
  11152. * before setting the bit.
  11153. *
  11154. * Returns 0 if the index bit successfully set, otherwise, it returns
  11155. * -EINVAL.
  11156. **/
  11157. int
  11158. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  11159. {
  11160. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11161. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11162. "2610 HBA FCF index reached driver's "
  11163. "book keeping dimension: fcf_index:%d, "
  11164. "driver_bmask_max:%d\n",
  11165. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11166. return -EINVAL;
  11167. }
  11168. /* Set the eligible FCF record index bmask */
  11169. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11170. return 0;
  11171. }
  11172. /**
  11173. * lpfc_sli4_fcf_rr_index_set - Clear bmask from eligible fcf record index
  11174. * @phba: pointer to lpfc hba data structure.
  11175. *
  11176. * This routine clears the FCF record index from the eligible bmask for
  11177. * round robin failover search. It checks to make sure that the index
  11178. * does not go beyond the range of the driver allocated bmask dimension
  11179. * before clearing the bit.
  11180. **/
  11181. void
  11182. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  11183. {
  11184. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11185. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11186. "2762 HBA FCF index goes beyond driver's "
  11187. "book keeping dimension: fcf_index:%d, "
  11188. "driver_bmask_max:%d\n",
  11189. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11190. return;
  11191. }
  11192. /* Clear the eligible FCF record index bmask */
  11193. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11194. }
  11195. /**
  11196. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  11197. * @phba: pointer to lpfc hba data structure.
  11198. *
  11199. * This routine is the completion routine for the rediscover FCF table mailbox
  11200. * command. If the mailbox command returned failure, it will try to stop the
  11201. * FCF rediscover wait timer.
  11202. **/
  11203. void
  11204. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  11205. {
  11206. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11207. uint32_t shdr_status, shdr_add_status;
  11208. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11209. shdr_status = bf_get(lpfc_mbox_hdr_status,
  11210. &redisc_fcf->header.cfg_shdr.response);
  11211. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  11212. &redisc_fcf->header.cfg_shdr.response);
  11213. if (shdr_status || shdr_add_status) {
  11214. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11215. "2746 Requesting for FCF rediscovery failed "
  11216. "status x%x add_status x%x\n",
  11217. shdr_status, shdr_add_status);
  11218. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  11219. spin_lock_irq(&phba->hbalock);
  11220. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  11221. spin_unlock_irq(&phba->hbalock);
  11222. /*
  11223. * CVL event triggered FCF rediscover request failed,
  11224. * last resort to re-try current registered FCF entry.
  11225. */
  11226. lpfc_retry_pport_discovery(phba);
  11227. } else {
  11228. spin_lock_irq(&phba->hbalock);
  11229. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  11230. spin_unlock_irq(&phba->hbalock);
  11231. /*
  11232. * DEAD FCF event triggered FCF rediscover request
  11233. * failed, last resort to fail over as a link down
  11234. * to FCF registration.
  11235. */
  11236. lpfc_sli4_fcf_dead_failthrough(phba);
  11237. }
  11238. } else {
  11239. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11240. "2775 Start FCF rediscovery quiescent period "
  11241. "wait timer before scaning FCF table\n");
  11242. /*
  11243. * Start FCF rediscovery wait timer for pending FCF
  11244. * before rescan FCF record table.
  11245. */
  11246. lpfc_fcf_redisc_wait_start_timer(phba);
  11247. }
  11248. mempool_free(mbox, phba->mbox_mem_pool);
  11249. }
  11250. /**
  11251. * lpfc_sli4_redisc_all_fcf - Request to rediscover entire FCF table by port.
  11252. * @phba: pointer to lpfc hba data structure.
  11253. *
  11254. * This routine is invoked to request for rediscovery of the entire FCF table
  11255. * by the port.
  11256. **/
  11257. int
  11258. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11259. {
  11260. LPFC_MBOXQ_t *mbox;
  11261. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11262. int rc, length;
  11263. /* Cancel retry delay timers to all vports before FCF rediscover */
  11264. lpfc_cancel_all_vport_retry_delay_timer(phba);
  11265. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11266. if (!mbox) {
  11267. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11268. "2745 Failed to allocate mbox for "
  11269. "requesting FCF rediscover.\n");
  11270. return -ENOMEM;
  11271. }
  11272. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  11273. sizeof(struct lpfc_sli4_cfg_mhdr));
  11274. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11275. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  11276. length, LPFC_SLI4_MBX_EMBED);
  11277. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11278. /* Set count to 0 for invalidating the entire FCF database */
  11279. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  11280. /* Issue the mailbox command asynchronously */
  11281. mbox->vport = phba->pport;
  11282. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  11283. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  11284. if (rc == MBX_NOT_FINISHED) {
  11285. mempool_free(mbox, phba->mbox_mem_pool);
  11286. return -EIO;
  11287. }
  11288. return 0;
  11289. }
  11290. /**
  11291. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  11292. * @phba: pointer to lpfc hba data structure.
  11293. *
  11294. * This function is the failover routine as a last resort to the FCF DEAD
  11295. * event when driver failed to perform fast FCF failover.
  11296. **/
  11297. void
  11298. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  11299. {
  11300. uint32_t link_state;
  11301. /*
  11302. * Last resort as FCF DEAD event failover will treat this as
  11303. * a link down, but save the link state because we don't want
  11304. * it to be changed to Link Down unless it is already down.
  11305. */
  11306. link_state = phba->link_state;
  11307. lpfc_linkdown(phba);
  11308. phba->link_state = link_state;
  11309. /* Unregister FCF if no devices connected to it */
  11310. lpfc_unregister_unused_fcf(phba);
  11311. }
  11312. /**
  11313. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  11314. * @phba: pointer to lpfc hba data structure.
  11315. *
  11316. * This function read region 23 and parse TLV for port status to
  11317. * decide if the user disaled the port. If the TLV indicates the
  11318. * port is disabled, the hba_flag is set accordingly.
  11319. **/
  11320. void
  11321. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  11322. {
  11323. LPFC_MBOXQ_t *pmb = NULL;
  11324. MAILBOX_t *mb;
  11325. uint8_t *rgn23_data = NULL;
  11326. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  11327. int rc;
  11328. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11329. if (!pmb) {
  11330. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11331. "2600 lpfc_sli_read_serdes_param failed to"
  11332. " allocate mailbox memory\n");
  11333. goto out;
  11334. }
  11335. mb = &pmb->u.mb;
  11336. /* Get adapter Region 23 data */
  11337. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  11338. if (!rgn23_data)
  11339. goto out;
  11340. do {
  11341. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  11342. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  11343. if (rc != MBX_SUCCESS) {
  11344. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11345. "2601 lpfc_sli_read_link_ste failed to"
  11346. " read config region 23 rc 0x%x Status 0x%x\n",
  11347. rc, mb->mbxStatus);
  11348. mb->un.varDmp.word_cnt = 0;
  11349. }
  11350. /*
  11351. * dump mem may return a zero when finished or we got a
  11352. * mailbox error, either way we are done.
  11353. */
  11354. if (mb->un.varDmp.word_cnt == 0)
  11355. break;
  11356. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  11357. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  11358. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  11359. rgn23_data + offset,
  11360. mb->un.varDmp.word_cnt);
  11361. offset += mb->un.varDmp.word_cnt;
  11362. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  11363. data_size = offset;
  11364. offset = 0;
  11365. if (!data_size)
  11366. goto out;
  11367. /* Check the region signature first */
  11368. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  11369. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11370. "2619 Config region 23 has bad signature\n");
  11371. goto out;
  11372. }
  11373. offset += 4;
  11374. /* Check the data structure version */
  11375. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  11376. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11377. "2620 Config region 23 has bad version\n");
  11378. goto out;
  11379. }
  11380. offset += 4;
  11381. /* Parse TLV entries in the region */
  11382. while (offset < data_size) {
  11383. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  11384. break;
  11385. /*
  11386. * If the TLV is not driver specific TLV or driver id is
  11387. * not linux driver id, skip the record.
  11388. */
  11389. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  11390. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  11391. (rgn23_data[offset + 3] != 0)) {
  11392. offset += rgn23_data[offset + 1] * 4 + 4;
  11393. continue;
  11394. }
  11395. /* Driver found a driver specific TLV in the config region */
  11396. sub_tlv_len = rgn23_data[offset + 1] * 4;
  11397. offset += 4;
  11398. tlv_offset = 0;
  11399. /*
  11400. * Search for configured port state sub-TLV.
  11401. */
  11402. while ((offset < data_size) &&
  11403. (tlv_offset < sub_tlv_len)) {
  11404. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  11405. offset += 4;
  11406. tlv_offset += 4;
  11407. break;
  11408. }
  11409. if (rgn23_data[offset] != PORT_STE_TYPE) {
  11410. offset += rgn23_data[offset + 1] * 4 + 4;
  11411. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  11412. continue;
  11413. }
  11414. /* This HBA contains PORT_STE configured */
  11415. if (!rgn23_data[offset + 2])
  11416. phba->hba_flag |= LINK_DISABLED;
  11417. goto out;
  11418. }
  11419. }
  11420. out:
  11421. if (pmb)
  11422. mempool_free(pmb, phba->mbox_mem_pool);
  11423. kfree(rgn23_data);
  11424. return;
  11425. }
  11426. /**
  11427. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  11428. * @vport: pointer to vport data structure.
  11429. *
  11430. * This function iterate through the mailboxq and clean up all REG_LOGIN
  11431. * and REG_VPI mailbox commands associated with the vport. This function
  11432. * is called when driver want to restart discovery of the vport due to
  11433. * a Clear Virtual Link event.
  11434. **/
  11435. void
  11436. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  11437. {
  11438. struct lpfc_hba *phba = vport->phba;
  11439. LPFC_MBOXQ_t *mb, *nextmb;
  11440. struct lpfc_dmabuf *mp;
  11441. spin_lock_irq(&phba->hbalock);
  11442. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  11443. if (mb->vport != vport)
  11444. continue;
  11445. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  11446. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  11447. continue;
  11448. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11449. mp = (struct lpfc_dmabuf *) (mb->context1);
  11450. if (mp) {
  11451. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  11452. kfree(mp);
  11453. }
  11454. }
  11455. list_del(&mb->list);
  11456. mempool_free(mb, phba->mbox_mem_pool);
  11457. }
  11458. mb = phba->sli.mbox_active;
  11459. if (mb && (mb->vport == vport)) {
  11460. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  11461. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  11462. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11463. }
  11464. spin_unlock_irq(&phba->hbalock);
  11465. }