lpfc_init.c 325 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2013 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/delay.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/idr.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/module.h>
  27. #include <linux/kthread.h>
  28. #include <linux/pci.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/ctype.h>
  31. #include <linux/aer.h>
  32. #include <linux/slab.h>
  33. #include <linux/firmware.h>
  34. #include <linux/miscdevice.h>
  35. #include <linux/percpu.h>
  36. #include <scsi/scsi.h>
  37. #include <scsi/scsi_device.h>
  38. #include <scsi/scsi_host.h>
  39. #include <scsi/scsi_transport_fc.h>
  40. #include "lpfc_hw4.h"
  41. #include "lpfc_hw.h"
  42. #include "lpfc_sli.h"
  43. #include "lpfc_sli4.h"
  44. #include "lpfc_nl.h"
  45. #include "lpfc_disc.h"
  46. #include "lpfc_scsi.h"
  47. #include "lpfc.h"
  48. #include "lpfc_logmsg.h"
  49. #include "lpfc_crtn.h"
  50. #include "lpfc_vport.h"
  51. #include "lpfc_version.h"
  52. char *_dump_buf_data;
  53. unsigned long _dump_buf_data_order;
  54. char *_dump_buf_dif;
  55. unsigned long _dump_buf_dif_order;
  56. spinlock_t _dump_buf_lock;
  57. /* Used when mapping IRQ vectors in a driver centric manner */
  58. uint16_t *lpfc_used_cpu;
  59. uint32_t lpfc_present_cpu;
  60. static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
  61. static int lpfc_post_rcv_buf(struct lpfc_hba *);
  62. static int lpfc_sli4_queue_verify(struct lpfc_hba *);
  63. static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
  64. static int lpfc_setup_endian_order(struct lpfc_hba *);
  65. static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
  66. static void lpfc_free_els_sgl_list(struct lpfc_hba *);
  67. static void lpfc_init_sgl_list(struct lpfc_hba *);
  68. static int lpfc_init_active_sgl_array(struct lpfc_hba *);
  69. static void lpfc_free_active_sgl(struct lpfc_hba *);
  70. static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
  71. static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
  72. static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
  73. static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
  74. static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
  75. static void lpfc_sli4_disable_intr(struct lpfc_hba *);
  76. static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
  77. static struct scsi_transport_template *lpfc_transport_template = NULL;
  78. static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
  79. static DEFINE_IDR(lpfc_hba_index);
  80. /**
  81. * lpfc_config_port_prep - Perform lpfc initialization prior to config port
  82. * @phba: pointer to lpfc hba data structure.
  83. *
  84. * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
  85. * mailbox command. It retrieves the revision information from the HBA and
  86. * collects the Vital Product Data (VPD) about the HBA for preparing the
  87. * configuration of the HBA.
  88. *
  89. * Return codes:
  90. * 0 - success.
  91. * -ERESTART - requests the SLI layer to reset the HBA and try again.
  92. * Any other value - indicates an error.
  93. **/
  94. int
  95. lpfc_config_port_prep(struct lpfc_hba *phba)
  96. {
  97. lpfc_vpd_t *vp = &phba->vpd;
  98. int i = 0, rc;
  99. LPFC_MBOXQ_t *pmb;
  100. MAILBOX_t *mb;
  101. char *lpfc_vpd_data = NULL;
  102. uint16_t offset = 0;
  103. static char licensed[56] =
  104. "key unlock for use with gnu public licensed code only\0";
  105. static int init_key = 1;
  106. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  107. if (!pmb) {
  108. phba->link_state = LPFC_HBA_ERROR;
  109. return -ENOMEM;
  110. }
  111. mb = &pmb->u.mb;
  112. phba->link_state = LPFC_INIT_MBX_CMDS;
  113. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  114. if (init_key) {
  115. uint32_t *ptext = (uint32_t *) licensed;
  116. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  117. *ptext = cpu_to_be32(*ptext);
  118. init_key = 0;
  119. }
  120. lpfc_read_nv(phba, pmb);
  121. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  122. sizeof (mb->un.varRDnvp.rsvd3));
  123. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  124. sizeof (licensed));
  125. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  126. if (rc != MBX_SUCCESS) {
  127. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  128. "0324 Config Port initialization "
  129. "error, mbxCmd x%x READ_NVPARM, "
  130. "mbxStatus x%x\n",
  131. mb->mbxCommand, mb->mbxStatus);
  132. mempool_free(pmb, phba->mbox_mem_pool);
  133. return -ERESTART;
  134. }
  135. memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
  136. sizeof(phba->wwnn));
  137. memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
  138. sizeof(phba->wwpn));
  139. }
  140. phba->sli3_options = 0x0;
  141. /* Setup and issue mailbox READ REV command */
  142. lpfc_read_rev(phba, pmb);
  143. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  144. if (rc != MBX_SUCCESS) {
  145. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  146. "0439 Adapter failed to init, mbxCmd x%x "
  147. "READ_REV, mbxStatus x%x\n",
  148. mb->mbxCommand, mb->mbxStatus);
  149. mempool_free( pmb, phba->mbox_mem_pool);
  150. return -ERESTART;
  151. }
  152. /*
  153. * The value of rr must be 1 since the driver set the cv field to 1.
  154. * This setting requires the FW to set all revision fields.
  155. */
  156. if (mb->un.varRdRev.rr == 0) {
  157. vp->rev.rBit = 0;
  158. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  159. "0440 Adapter failed to init, READ_REV has "
  160. "missing revision information.\n");
  161. mempool_free(pmb, phba->mbox_mem_pool);
  162. return -ERESTART;
  163. }
  164. if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
  165. mempool_free(pmb, phba->mbox_mem_pool);
  166. return -EINVAL;
  167. }
  168. /* Save information as VPD data */
  169. vp->rev.rBit = 1;
  170. memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
  171. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  172. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  173. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  174. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  175. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  176. vp->rev.smRev = mb->un.varRdRev.smRev;
  177. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  178. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  179. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  180. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  181. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  182. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  183. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  184. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  185. /* If the sli feature level is less then 9, we must
  186. * tear down all RPIs and VPIs on link down if NPIV
  187. * is enabled.
  188. */
  189. if (vp->rev.feaLevelHigh < 9)
  190. phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
  191. if (lpfc_is_LC_HBA(phba->pcidev->device))
  192. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  193. sizeof (phba->RandomData));
  194. /* Get adapter VPD information */
  195. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  196. if (!lpfc_vpd_data)
  197. goto out_free_mbox;
  198. do {
  199. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
  200. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  201. if (rc != MBX_SUCCESS) {
  202. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  203. "0441 VPD not present on adapter, "
  204. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  205. mb->mbxCommand, mb->mbxStatus);
  206. mb->un.varDmp.word_cnt = 0;
  207. }
  208. /* dump mem may return a zero when finished or we got a
  209. * mailbox error, either way we are done.
  210. */
  211. if (mb->un.varDmp.word_cnt == 0)
  212. break;
  213. if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
  214. mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
  215. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  216. lpfc_vpd_data + offset,
  217. mb->un.varDmp.word_cnt);
  218. offset += mb->un.varDmp.word_cnt;
  219. } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
  220. lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
  221. kfree(lpfc_vpd_data);
  222. out_free_mbox:
  223. mempool_free(pmb, phba->mbox_mem_pool);
  224. return 0;
  225. }
  226. /**
  227. * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
  228. * @phba: pointer to lpfc hba data structure.
  229. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  230. *
  231. * This is the completion handler for driver's configuring asynchronous event
  232. * mailbox command to the device. If the mailbox command returns successfully,
  233. * it will set internal async event support flag to 1; otherwise, it will
  234. * set internal async event support flag to 0.
  235. **/
  236. static void
  237. lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  238. {
  239. if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
  240. phba->temp_sensor_support = 1;
  241. else
  242. phba->temp_sensor_support = 0;
  243. mempool_free(pmboxq, phba->mbox_mem_pool);
  244. return;
  245. }
  246. /**
  247. * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
  248. * @phba: pointer to lpfc hba data structure.
  249. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  250. *
  251. * This is the completion handler for dump mailbox command for getting
  252. * wake up parameters. When this command complete, the response contain
  253. * Option rom version of the HBA. This function translate the version number
  254. * into a human readable string and store it in OptionROMVersion.
  255. **/
  256. static void
  257. lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  258. {
  259. struct prog_id *prg;
  260. uint32_t prog_id_word;
  261. char dist = ' ';
  262. /* character array used for decoding dist type. */
  263. char dist_char[] = "nabx";
  264. if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
  265. mempool_free(pmboxq, phba->mbox_mem_pool);
  266. return;
  267. }
  268. prg = (struct prog_id *) &prog_id_word;
  269. /* word 7 contain option rom version */
  270. prog_id_word = pmboxq->u.mb.un.varWords[7];
  271. /* Decode the Option rom version word to a readable string */
  272. if (prg->dist < 4)
  273. dist = dist_char[prg->dist];
  274. if ((prg->dist == 3) && (prg->num == 0))
  275. sprintf(phba->OptionROMVersion, "%d.%d%d",
  276. prg->ver, prg->rev, prg->lev);
  277. else
  278. sprintf(phba->OptionROMVersion, "%d.%d%d%c%d",
  279. prg->ver, prg->rev, prg->lev,
  280. dist, prg->num);
  281. mempool_free(pmboxq, phba->mbox_mem_pool);
  282. return;
  283. }
  284. /**
  285. * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
  286. * cfg_soft_wwnn, cfg_soft_wwpn
  287. * @vport: pointer to lpfc vport data structure.
  288. *
  289. *
  290. * Return codes
  291. * None.
  292. **/
  293. void
  294. lpfc_update_vport_wwn(struct lpfc_vport *vport)
  295. {
  296. /* If the soft name exists then update it using the service params */
  297. if (vport->phba->cfg_soft_wwnn)
  298. u64_to_wwn(vport->phba->cfg_soft_wwnn,
  299. vport->fc_sparam.nodeName.u.wwn);
  300. if (vport->phba->cfg_soft_wwpn)
  301. u64_to_wwn(vport->phba->cfg_soft_wwpn,
  302. vport->fc_sparam.portName.u.wwn);
  303. /*
  304. * If the name is empty or there exists a soft name
  305. * then copy the service params name, otherwise use the fc name
  306. */
  307. if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
  308. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  309. sizeof(struct lpfc_name));
  310. else
  311. memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
  312. sizeof(struct lpfc_name));
  313. if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn)
  314. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  315. sizeof(struct lpfc_name));
  316. else
  317. memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
  318. sizeof(struct lpfc_name));
  319. }
  320. /**
  321. * lpfc_config_port_post - Perform lpfc initialization after config port
  322. * @phba: pointer to lpfc hba data structure.
  323. *
  324. * This routine will do LPFC initialization after the CONFIG_PORT mailbox
  325. * command call. It performs all internal resource and state setups on the
  326. * port: post IOCB buffers, enable appropriate host interrupt attentions,
  327. * ELS ring timers, etc.
  328. *
  329. * Return codes
  330. * 0 - success.
  331. * Any other value - error.
  332. **/
  333. int
  334. lpfc_config_port_post(struct lpfc_hba *phba)
  335. {
  336. struct lpfc_vport *vport = phba->pport;
  337. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  338. LPFC_MBOXQ_t *pmb;
  339. MAILBOX_t *mb;
  340. struct lpfc_dmabuf *mp;
  341. struct lpfc_sli *psli = &phba->sli;
  342. uint32_t status, timeout;
  343. int i, j;
  344. int rc;
  345. spin_lock_irq(&phba->hbalock);
  346. /*
  347. * If the Config port completed correctly the HBA is not
  348. * over heated any more.
  349. */
  350. if (phba->over_temp_state == HBA_OVER_TEMP)
  351. phba->over_temp_state = HBA_NORMAL_TEMP;
  352. spin_unlock_irq(&phba->hbalock);
  353. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  354. if (!pmb) {
  355. phba->link_state = LPFC_HBA_ERROR;
  356. return -ENOMEM;
  357. }
  358. mb = &pmb->u.mb;
  359. /* Get login parameters for NID. */
  360. rc = lpfc_read_sparam(phba, pmb, 0);
  361. if (rc) {
  362. mempool_free(pmb, phba->mbox_mem_pool);
  363. return -ENOMEM;
  364. }
  365. pmb->vport = vport;
  366. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  367. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  368. "0448 Adapter failed init, mbxCmd x%x "
  369. "READ_SPARM mbxStatus x%x\n",
  370. mb->mbxCommand, mb->mbxStatus);
  371. phba->link_state = LPFC_HBA_ERROR;
  372. mp = (struct lpfc_dmabuf *) pmb->context1;
  373. mempool_free(pmb, phba->mbox_mem_pool);
  374. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  375. kfree(mp);
  376. return -EIO;
  377. }
  378. mp = (struct lpfc_dmabuf *) pmb->context1;
  379. memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
  380. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  381. kfree(mp);
  382. pmb->context1 = NULL;
  383. lpfc_update_vport_wwn(vport);
  384. /* Update the fc_host data structures with new wwn. */
  385. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  386. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  387. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  388. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  389. /* This should be consolidated into parse_vpd ? - mr */
  390. if (phba->SerialNumber[0] == 0) {
  391. uint8_t *outptr;
  392. outptr = &vport->fc_nodename.u.s.IEEE[0];
  393. for (i = 0; i < 12; i++) {
  394. status = *outptr++;
  395. j = ((status & 0xf0) >> 4);
  396. if (j <= 9)
  397. phba->SerialNumber[i] =
  398. (char)((uint8_t) 0x30 + (uint8_t) j);
  399. else
  400. phba->SerialNumber[i] =
  401. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  402. i++;
  403. j = (status & 0xf);
  404. if (j <= 9)
  405. phba->SerialNumber[i] =
  406. (char)((uint8_t) 0x30 + (uint8_t) j);
  407. else
  408. phba->SerialNumber[i] =
  409. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  410. }
  411. }
  412. lpfc_read_config(phba, pmb);
  413. pmb->vport = vport;
  414. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  415. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  416. "0453 Adapter failed to init, mbxCmd x%x "
  417. "READ_CONFIG, mbxStatus x%x\n",
  418. mb->mbxCommand, mb->mbxStatus);
  419. phba->link_state = LPFC_HBA_ERROR;
  420. mempool_free( pmb, phba->mbox_mem_pool);
  421. return -EIO;
  422. }
  423. /* Check if the port is disabled */
  424. lpfc_sli_read_link_ste(phba);
  425. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  426. if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
  427. phba->cfg_hba_queue_depth =
  428. (mb->un.varRdConfig.max_xri + 1) -
  429. lpfc_sli4_get_els_iocb_cnt(phba);
  430. phba->lmt = mb->un.varRdConfig.lmt;
  431. /* Get the default values for Model Name and Description */
  432. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  433. phba->link_state = LPFC_LINK_DOWN;
  434. /* Only process IOCBs on ELS ring till hba_state is READY */
  435. if (psli->ring[psli->extra_ring].sli.sli3.cmdringaddr)
  436. psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
  437. if (psli->ring[psli->fcp_ring].sli.sli3.cmdringaddr)
  438. psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
  439. if (psli->ring[psli->next_ring].sli.sli3.cmdringaddr)
  440. psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
  441. /* Post receive buffers for desired rings */
  442. if (phba->sli_rev != 3)
  443. lpfc_post_rcv_buf(phba);
  444. /*
  445. * Configure HBA MSI-X attention conditions to messages if MSI-X mode
  446. */
  447. if (phba->intr_type == MSIX) {
  448. rc = lpfc_config_msi(phba, pmb);
  449. if (rc) {
  450. mempool_free(pmb, phba->mbox_mem_pool);
  451. return -EIO;
  452. }
  453. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  454. if (rc != MBX_SUCCESS) {
  455. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  456. "0352 Config MSI mailbox command "
  457. "failed, mbxCmd x%x, mbxStatus x%x\n",
  458. pmb->u.mb.mbxCommand,
  459. pmb->u.mb.mbxStatus);
  460. mempool_free(pmb, phba->mbox_mem_pool);
  461. return -EIO;
  462. }
  463. }
  464. spin_lock_irq(&phba->hbalock);
  465. /* Initialize ERATT handling flag */
  466. phba->hba_flag &= ~HBA_ERATT_HANDLED;
  467. /* Enable appropriate host interrupts */
  468. if (lpfc_readl(phba->HCregaddr, &status)) {
  469. spin_unlock_irq(&phba->hbalock);
  470. return -EIO;
  471. }
  472. status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
  473. if (psli->num_rings > 0)
  474. status |= HC_R0INT_ENA;
  475. if (psli->num_rings > 1)
  476. status |= HC_R1INT_ENA;
  477. if (psli->num_rings > 2)
  478. status |= HC_R2INT_ENA;
  479. if (psli->num_rings > 3)
  480. status |= HC_R3INT_ENA;
  481. if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
  482. (phba->cfg_poll & DISABLE_FCP_RING_INT))
  483. status &= ~(HC_R0INT_ENA);
  484. writel(status, phba->HCregaddr);
  485. readl(phba->HCregaddr); /* flush */
  486. spin_unlock_irq(&phba->hbalock);
  487. /* Set up ring-0 (ELS) timer */
  488. timeout = phba->fc_ratov * 2;
  489. mod_timer(&vport->els_tmofunc,
  490. jiffies + msecs_to_jiffies(1000 * timeout));
  491. /* Set up heart beat (HB) timer */
  492. mod_timer(&phba->hb_tmofunc,
  493. jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  494. phba->hb_outstanding = 0;
  495. phba->last_completion_time = jiffies;
  496. /* Set up error attention (ERATT) polling timer */
  497. mod_timer(&phba->eratt_poll,
  498. jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
  499. if (phba->hba_flag & LINK_DISABLED) {
  500. lpfc_printf_log(phba,
  501. KERN_ERR, LOG_INIT,
  502. "2598 Adapter Link is disabled.\n");
  503. lpfc_down_link(phba, pmb);
  504. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  505. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  506. if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
  507. lpfc_printf_log(phba,
  508. KERN_ERR, LOG_INIT,
  509. "2599 Adapter failed to issue DOWN_LINK"
  510. " mbox command rc 0x%x\n", rc);
  511. mempool_free(pmb, phba->mbox_mem_pool);
  512. return -EIO;
  513. }
  514. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  515. mempool_free(pmb, phba->mbox_mem_pool);
  516. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  517. if (rc)
  518. return rc;
  519. }
  520. /* MBOX buffer will be freed in mbox compl */
  521. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  522. if (!pmb) {
  523. phba->link_state = LPFC_HBA_ERROR;
  524. return -ENOMEM;
  525. }
  526. lpfc_config_async(phba, pmb, LPFC_ELS_RING);
  527. pmb->mbox_cmpl = lpfc_config_async_cmpl;
  528. pmb->vport = phba->pport;
  529. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  530. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  531. lpfc_printf_log(phba,
  532. KERN_ERR,
  533. LOG_INIT,
  534. "0456 Adapter failed to issue "
  535. "ASYNCEVT_ENABLE mbox status x%x\n",
  536. rc);
  537. mempool_free(pmb, phba->mbox_mem_pool);
  538. }
  539. /* Get Option rom version */
  540. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  541. if (!pmb) {
  542. phba->link_state = LPFC_HBA_ERROR;
  543. return -ENOMEM;
  544. }
  545. lpfc_dump_wakeup_param(phba, pmb);
  546. pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
  547. pmb->vport = phba->pport;
  548. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  549. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  550. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
  551. "to get Option ROM version status x%x\n", rc);
  552. mempool_free(pmb, phba->mbox_mem_pool);
  553. }
  554. return 0;
  555. }
  556. /**
  557. * lpfc_hba_init_link - Initialize the FC link
  558. * @phba: pointer to lpfc hba data structure.
  559. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  560. *
  561. * This routine will issue the INIT_LINK mailbox command call.
  562. * It is available to other drivers through the lpfc_hba data
  563. * structure for use as a delayed link up mechanism with the
  564. * module parameter lpfc_suppress_link_up.
  565. *
  566. * Return code
  567. * 0 - success
  568. * Any other value - error
  569. **/
  570. int
  571. lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
  572. {
  573. return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
  574. }
  575. /**
  576. * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
  577. * @phba: pointer to lpfc hba data structure.
  578. * @fc_topology: desired fc topology.
  579. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  580. *
  581. * This routine will issue the INIT_LINK mailbox command call.
  582. * It is available to other drivers through the lpfc_hba data
  583. * structure for use as a delayed link up mechanism with the
  584. * module parameter lpfc_suppress_link_up.
  585. *
  586. * Return code
  587. * 0 - success
  588. * Any other value - error
  589. **/
  590. int
  591. lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
  592. uint32_t flag)
  593. {
  594. struct lpfc_vport *vport = phba->pport;
  595. LPFC_MBOXQ_t *pmb;
  596. MAILBOX_t *mb;
  597. int rc;
  598. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  599. if (!pmb) {
  600. phba->link_state = LPFC_HBA_ERROR;
  601. return -ENOMEM;
  602. }
  603. mb = &pmb->u.mb;
  604. pmb->vport = vport;
  605. if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
  606. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
  607. !(phba->lmt & LMT_1Gb)) ||
  608. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
  609. !(phba->lmt & LMT_2Gb)) ||
  610. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
  611. !(phba->lmt & LMT_4Gb)) ||
  612. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
  613. !(phba->lmt & LMT_8Gb)) ||
  614. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
  615. !(phba->lmt & LMT_10Gb)) ||
  616. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
  617. !(phba->lmt & LMT_16Gb))) {
  618. /* Reset link speed to auto */
  619. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  620. "1302 Invalid speed for this board:%d "
  621. "Reset link speed to auto.\n",
  622. phba->cfg_link_speed);
  623. phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
  624. }
  625. lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
  626. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  627. if (phba->sli_rev < LPFC_SLI_REV4)
  628. lpfc_set_loopback_flag(phba);
  629. rc = lpfc_sli_issue_mbox(phba, pmb, flag);
  630. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  631. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  632. "0498 Adapter failed to init, mbxCmd x%x "
  633. "INIT_LINK, mbxStatus x%x\n",
  634. mb->mbxCommand, mb->mbxStatus);
  635. if (phba->sli_rev <= LPFC_SLI_REV3) {
  636. /* Clear all interrupt enable conditions */
  637. writel(0, phba->HCregaddr);
  638. readl(phba->HCregaddr); /* flush */
  639. /* Clear all pending interrupts */
  640. writel(0xffffffff, phba->HAregaddr);
  641. readl(phba->HAregaddr); /* flush */
  642. }
  643. phba->link_state = LPFC_HBA_ERROR;
  644. if (rc != MBX_BUSY || flag == MBX_POLL)
  645. mempool_free(pmb, phba->mbox_mem_pool);
  646. return -EIO;
  647. }
  648. phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
  649. if (flag == MBX_POLL)
  650. mempool_free(pmb, phba->mbox_mem_pool);
  651. return 0;
  652. }
  653. /**
  654. * lpfc_hba_down_link - this routine downs the FC link
  655. * @phba: pointer to lpfc hba data structure.
  656. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  657. *
  658. * This routine will issue the DOWN_LINK mailbox command call.
  659. * It is available to other drivers through the lpfc_hba data
  660. * structure for use to stop the link.
  661. *
  662. * Return code
  663. * 0 - success
  664. * Any other value - error
  665. **/
  666. int
  667. lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
  668. {
  669. LPFC_MBOXQ_t *pmb;
  670. int rc;
  671. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  672. if (!pmb) {
  673. phba->link_state = LPFC_HBA_ERROR;
  674. return -ENOMEM;
  675. }
  676. lpfc_printf_log(phba,
  677. KERN_ERR, LOG_INIT,
  678. "0491 Adapter Link is disabled.\n");
  679. lpfc_down_link(phba, pmb);
  680. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  681. rc = lpfc_sli_issue_mbox(phba, pmb, flag);
  682. if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
  683. lpfc_printf_log(phba,
  684. KERN_ERR, LOG_INIT,
  685. "2522 Adapter failed to issue DOWN_LINK"
  686. " mbox command rc 0x%x\n", rc);
  687. mempool_free(pmb, phba->mbox_mem_pool);
  688. return -EIO;
  689. }
  690. if (flag == MBX_POLL)
  691. mempool_free(pmb, phba->mbox_mem_pool);
  692. return 0;
  693. }
  694. /**
  695. * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
  696. * @phba: pointer to lpfc HBA data structure.
  697. *
  698. * This routine will do LPFC uninitialization before the HBA is reset when
  699. * bringing down the SLI Layer.
  700. *
  701. * Return codes
  702. * 0 - success.
  703. * Any other value - error.
  704. **/
  705. int
  706. lpfc_hba_down_prep(struct lpfc_hba *phba)
  707. {
  708. struct lpfc_vport **vports;
  709. int i;
  710. if (phba->sli_rev <= LPFC_SLI_REV3) {
  711. /* Disable interrupts */
  712. writel(0, phba->HCregaddr);
  713. readl(phba->HCregaddr); /* flush */
  714. }
  715. if (phba->pport->load_flag & FC_UNLOADING)
  716. lpfc_cleanup_discovery_resources(phba->pport);
  717. else {
  718. vports = lpfc_create_vport_work_array(phba);
  719. if (vports != NULL)
  720. for (i = 0; i <= phba->max_vports &&
  721. vports[i] != NULL; i++)
  722. lpfc_cleanup_discovery_resources(vports[i]);
  723. lpfc_destroy_vport_work_array(phba, vports);
  724. }
  725. return 0;
  726. }
  727. /**
  728. * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
  729. * @phba: pointer to lpfc HBA data structure.
  730. *
  731. * This routine will do uninitialization after the HBA is reset when bring
  732. * down the SLI Layer.
  733. *
  734. * Return codes
  735. * 0 - success.
  736. * Any other value - error.
  737. **/
  738. static int
  739. lpfc_hba_down_post_s3(struct lpfc_hba *phba)
  740. {
  741. struct lpfc_sli *psli = &phba->sli;
  742. struct lpfc_sli_ring *pring;
  743. struct lpfc_dmabuf *mp, *next_mp;
  744. LIST_HEAD(completions);
  745. int i;
  746. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
  747. lpfc_sli_hbqbuf_free_all(phba);
  748. else {
  749. /* Cleanup preposted buffers on the ELS ring */
  750. pring = &psli->ring[LPFC_ELS_RING];
  751. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  752. list_del(&mp->list);
  753. pring->postbufq_cnt--;
  754. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  755. kfree(mp);
  756. }
  757. }
  758. spin_lock_irq(&phba->hbalock);
  759. for (i = 0; i < psli->num_rings; i++) {
  760. pring = &psli->ring[i];
  761. /* At this point in time the HBA is either reset or DOA. Either
  762. * way, nothing should be on txcmplq as it will NEVER complete.
  763. */
  764. list_splice_init(&pring->txcmplq, &completions);
  765. spin_unlock_irq(&phba->hbalock);
  766. /* Cancel all the IOCBs from the completions list */
  767. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  768. IOERR_SLI_ABORTED);
  769. lpfc_sli_abort_iocb_ring(phba, pring);
  770. spin_lock_irq(&phba->hbalock);
  771. }
  772. spin_unlock_irq(&phba->hbalock);
  773. return 0;
  774. }
  775. /**
  776. * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
  777. * @phba: pointer to lpfc HBA data structure.
  778. *
  779. * This routine will do uninitialization after the HBA is reset when bring
  780. * down the SLI Layer.
  781. *
  782. * Return codes
  783. * 0 - success.
  784. * Any other value - error.
  785. **/
  786. static int
  787. lpfc_hba_down_post_s4(struct lpfc_hba *phba)
  788. {
  789. struct lpfc_scsi_buf *psb, *psb_next;
  790. LIST_HEAD(aborts);
  791. int ret;
  792. unsigned long iflag = 0;
  793. struct lpfc_sglq *sglq_entry = NULL;
  794. ret = lpfc_hba_down_post_s3(phba);
  795. if (ret)
  796. return ret;
  797. /* At this point in time the HBA is either reset or DOA. Either
  798. * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
  799. * on the lpfc_sgl_list so that it can either be freed if the
  800. * driver is unloading or reposted if the driver is restarting
  801. * the port.
  802. */
  803. spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
  804. /* scsl_buf_list */
  805. /* abts_sgl_list_lock required because worker thread uses this
  806. * list.
  807. */
  808. spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
  809. list_for_each_entry(sglq_entry,
  810. &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
  811. sglq_entry->state = SGL_FREED;
  812. list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
  813. &phba->sli4_hba.lpfc_sgl_list);
  814. spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
  815. /* abts_scsi_buf_list_lock required because worker thread uses this
  816. * list.
  817. */
  818. spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  819. list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
  820. &aborts);
  821. spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  822. spin_unlock_irq(&phba->hbalock);
  823. list_for_each_entry_safe(psb, psb_next, &aborts, list) {
  824. psb->pCmd = NULL;
  825. psb->status = IOSTAT_SUCCESS;
  826. }
  827. spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
  828. list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
  829. spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
  830. return 0;
  831. }
  832. /**
  833. * lpfc_hba_down_post - Wrapper func for hba down post routine
  834. * @phba: pointer to lpfc HBA data structure.
  835. *
  836. * This routine wraps the actual SLI3 or SLI4 routine for performing
  837. * uninitialization after the HBA is reset when bring down the SLI Layer.
  838. *
  839. * Return codes
  840. * 0 - success.
  841. * Any other value - error.
  842. **/
  843. int
  844. lpfc_hba_down_post(struct lpfc_hba *phba)
  845. {
  846. return (*phba->lpfc_hba_down_post)(phba);
  847. }
  848. /**
  849. * lpfc_hb_timeout - The HBA-timer timeout handler
  850. * @ptr: unsigned long holds the pointer to lpfc hba data structure.
  851. *
  852. * This is the HBA-timer timeout handler registered to the lpfc driver. When
  853. * this timer fires, a HBA timeout event shall be posted to the lpfc driver
  854. * work-port-events bitmap and the worker thread is notified. This timeout
  855. * event will be used by the worker thread to invoke the actual timeout
  856. * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
  857. * be performed in the timeout handler and the HBA timeout event bit shall
  858. * be cleared by the worker thread after it has taken the event bitmap out.
  859. **/
  860. static void
  861. lpfc_hb_timeout(unsigned long ptr)
  862. {
  863. struct lpfc_hba *phba;
  864. uint32_t tmo_posted;
  865. unsigned long iflag;
  866. phba = (struct lpfc_hba *)ptr;
  867. /* Check for heart beat timeout conditions */
  868. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  869. tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
  870. if (!tmo_posted)
  871. phba->pport->work_port_events |= WORKER_HB_TMO;
  872. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  873. /* Tell the worker thread there is work to do */
  874. if (!tmo_posted)
  875. lpfc_worker_wake_up(phba);
  876. return;
  877. }
  878. /**
  879. * lpfc_rrq_timeout - The RRQ-timer timeout handler
  880. * @ptr: unsigned long holds the pointer to lpfc hba data structure.
  881. *
  882. * This is the RRQ-timer timeout handler registered to the lpfc driver. When
  883. * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
  884. * work-port-events bitmap and the worker thread is notified. This timeout
  885. * event will be used by the worker thread to invoke the actual timeout
  886. * handler routine, lpfc_rrq_handler. Any periodical operations will
  887. * be performed in the timeout handler and the RRQ timeout event bit shall
  888. * be cleared by the worker thread after it has taken the event bitmap out.
  889. **/
  890. static void
  891. lpfc_rrq_timeout(unsigned long ptr)
  892. {
  893. struct lpfc_hba *phba;
  894. unsigned long iflag;
  895. phba = (struct lpfc_hba *)ptr;
  896. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  897. phba->hba_flag |= HBA_RRQ_ACTIVE;
  898. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  899. lpfc_worker_wake_up(phba);
  900. }
  901. /**
  902. * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
  903. * @phba: pointer to lpfc hba data structure.
  904. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  905. *
  906. * This is the callback function to the lpfc heart-beat mailbox command.
  907. * If configured, the lpfc driver issues the heart-beat mailbox command to
  908. * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
  909. * heart-beat mailbox command is issued, the driver shall set up heart-beat
  910. * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
  911. * heart-beat outstanding state. Once the mailbox command comes back and
  912. * no error conditions detected, the heart-beat mailbox command timer is
  913. * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
  914. * state is cleared for the next heart-beat. If the timer expired with the
  915. * heart-beat outstanding state set, the driver will put the HBA offline.
  916. **/
  917. static void
  918. lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  919. {
  920. unsigned long drvr_flag;
  921. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  922. phba->hb_outstanding = 0;
  923. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  924. /* Check and reset heart-beat timer is necessary */
  925. mempool_free(pmboxq, phba->mbox_mem_pool);
  926. if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
  927. !(phba->link_state == LPFC_HBA_ERROR) &&
  928. !(phba->pport->load_flag & FC_UNLOADING))
  929. mod_timer(&phba->hb_tmofunc,
  930. jiffies +
  931. msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  932. return;
  933. }
  934. /**
  935. * lpfc_hb_timeout_handler - The HBA-timer timeout handler
  936. * @phba: pointer to lpfc hba data structure.
  937. *
  938. * This is the actual HBA-timer timeout handler to be invoked by the worker
  939. * thread whenever the HBA timer fired and HBA-timeout event posted. This
  940. * handler performs any periodic operations needed for the device. If such
  941. * periodic event has already been attended to either in the interrupt handler
  942. * or by processing slow-ring or fast-ring events within the HBA-timer
  943. * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
  944. * the timer for the next timeout period. If lpfc heart-beat mailbox command
  945. * is configured and there is no heart-beat mailbox command outstanding, a
  946. * heart-beat mailbox is issued and timer set properly. Otherwise, if there
  947. * has been a heart-beat mailbox command outstanding, the HBA shall be put
  948. * to offline.
  949. **/
  950. void
  951. lpfc_hb_timeout_handler(struct lpfc_hba *phba)
  952. {
  953. struct lpfc_vport **vports;
  954. LPFC_MBOXQ_t *pmboxq;
  955. struct lpfc_dmabuf *buf_ptr;
  956. int retval, i;
  957. struct lpfc_sli *psli = &phba->sli;
  958. LIST_HEAD(completions);
  959. vports = lpfc_create_vport_work_array(phba);
  960. if (vports != NULL)
  961. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  962. lpfc_rcv_seq_check_edtov(vports[i]);
  963. lpfc_destroy_vport_work_array(phba, vports);
  964. if ((phba->link_state == LPFC_HBA_ERROR) ||
  965. (phba->pport->load_flag & FC_UNLOADING) ||
  966. (phba->pport->fc_flag & FC_OFFLINE_MODE))
  967. return;
  968. spin_lock_irq(&phba->pport->work_port_lock);
  969. if (time_after(phba->last_completion_time +
  970. msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
  971. jiffies)) {
  972. spin_unlock_irq(&phba->pport->work_port_lock);
  973. if (!phba->hb_outstanding)
  974. mod_timer(&phba->hb_tmofunc,
  975. jiffies +
  976. msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  977. else
  978. mod_timer(&phba->hb_tmofunc,
  979. jiffies +
  980. msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
  981. return;
  982. }
  983. spin_unlock_irq(&phba->pport->work_port_lock);
  984. if (phba->elsbuf_cnt &&
  985. (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
  986. spin_lock_irq(&phba->hbalock);
  987. list_splice_init(&phba->elsbuf, &completions);
  988. phba->elsbuf_cnt = 0;
  989. phba->elsbuf_prev_cnt = 0;
  990. spin_unlock_irq(&phba->hbalock);
  991. while (!list_empty(&completions)) {
  992. list_remove_head(&completions, buf_ptr,
  993. struct lpfc_dmabuf, list);
  994. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  995. kfree(buf_ptr);
  996. }
  997. }
  998. phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
  999. /* If there is no heart beat outstanding, issue a heartbeat command */
  1000. if (phba->cfg_enable_hba_heartbeat) {
  1001. if (!phba->hb_outstanding) {
  1002. if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
  1003. (list_empty(&psli->mboxq))) {
  1004. pmboxq = mempool_alloc(phba->mbox_mem_pool,
  1005. GFP_KERNEL);
  1006. if (!pmboxq) {
  1007. mod_timer(&phba->hb_tmofunc,
  1008. jiffies +
  1009. msecs_to_jiffies(1000 *
  1010. LPFC_HB_MBOX_INTERVAL));
  1011. return;
  1012. }
  1013. lpfc_heart_beat(phba, pmboxq);
  1014. pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
  1015. pmboxq->vport = phba->pport;
  1016. retval = lpfc_sli_issue_mbox(phba, pmboxq,
  1017. MBX_NOWAIT);
  1018. if (retval != MBX_BUSY &&
  1019. retval != MBX_SUCCESS) {
  1020. mempool_free(pmboxq,
  1021. phba->mbox_mem_pool);
  1022. mod_timer(&phba->hb_tmofunc,
  1023. jiffies +
  1024. msecs_to_jiffies(1000 *
  1025. LPFC_HB_MBOX_INTERVAL));
  1026. return;
  1027. }
  1028. phba->skipped_hb = 0;
  1029. phba->hb_outstanding = 1;
  1030. } else if (time_before_eq(phba->last_completion_time,
  1031. phba->skipped_hb)) {
  1032. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1033. "2857 Last completion time not "
  1034. " updated in %d ms\n",
  1035. jiffies_to_msecs(jiffies
  1036. - phba->last_completion_time));
  1037. } else
  1038. phba->skipped_hb = jiffies;
  1039. mod_timer(&phba->hb_tmofunc,
  1040. jiffies +
  1041. msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
  1042. return;
  1043. } else {
  1044. /*
  1045. * If heart beat timeout called with hb_outstanding set
  1046. * we need to give the hb mailbox cmd a chance to
  1047. * complete or TMO.
  1048. */
  1049. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1050. "0459 Adapter heartbeat still out"
  1051. "standing:last compl time was %d ms.\n",
  1052. jiffies_to_msecs(jiffies
  1053. - phba->last_completion_time));
  1054. mod_timer(&phba->hb_tmofunc,
  1055. jiffies +
  1056. msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
  1057. }
  1058. }
  1059. }
  1060. /**
  1061. * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
  1062. * @phba: pointer to lpfc hba data structure.
  1063. *
  1064. * This routine is called to bring the HBA offline when HBA hardware error
  1065. * other than Port Error 6 has been detected.
  1066. **/
  1067. static void
  1068. lpfc_offline_eratt(struct lpfc_hba *phba)
  1069. {
  1070. struct lpfc_sli *psli = &phba->sli;
  1071. spin_lock_irq(&phba->hbalock);
  1072. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1073. spin_unlock_irq(&phba->hbalock);
  1074. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  1075. lpfc_offline(phba);
  1076. lpfc_reset_barrier(phba);
  1077. spin_lock_irq(&phba->hbalock);
  1078. lpfc_sli_brdreset(phba);
  1079. spin_unlock_irq(&phba->hbalock);
  1080. lpfc_hba_down_post(phba);
  1081. lpfc_sli_brdready(phba, HS_MBRDY);
  1082. lpfc_unblock_mgmt_io(phba);
  1083. phba->link_state = LPFC_HBA_ERROR;
  1084. return;
  1085. }
  1086. /**
  1087. * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
  1088. * @phba: pointer to lpfc hba data structure.
  1089. *
  1090. * This routine is called to bring a SLI4 HBA offline when HBA hardware error
  1091. * other than Port Error 6 has been detected.
  1092. **/
  1093. void
  1094. lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
  1095. {
  1096. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  1097. lpfc_offline(phba);
  1098. lpfc_sli4_brdreset(phba);
  1099. lpfc_hba_down_post(phba);
  1100. lpfc_sli4_post_status_check(phba);
  1101. lpfc_unblock_mgmt_io(phba);
  1102. phba->link_state = LPFC_HBA_ERROR;
  1103. }
  1104. /**
  1105. * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
  1106. * @phba: pointer to lpfc hba data structure.
  1107. *
  1108. * This routine is invoked to handle the deferred HBA hardware error
  1109. * conditions. This type of error is indicated by HBA by setting ER1
  1110. * and another ER bit in the host status register. The driver will
  1111. * wait until the ER1 bit clears before handling the error condition.
  1112. **/
  1113. static void
  1114. lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
  1115. {
  1116. uint32_t old_host_status = phba->work_hs;
  1117. struct lpfc_sli_ring *pring;
  1118. struct lpfc_sli *psli = &phba->sli;
  1119. /* If the pci channel is offline, ignore possible errors,
  1120. * since we cannot communicate with the pci card anyway.
  1121. */
  1122. if (pci_channel_offline(phba->pcidev)) {
  1123. spin_lock_irq(&phba->hbalock);
  1124. phba->hba_flag &= ~DEFER_ERATT;
  1125. spin_unlock_irq(&phba->hbalock);
  1126. return;
  1127. }
  1128. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1129. "0479 Deferred Adapter Hardware Error "
  1130. "Data: x%x x%x x%x\n",
  1131. phba->work_hs,
  1132. phba->work_status[0], phba->work_status[1]);
  1133. spin_lock_irq(&phba->hbalock);
  1134. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1135. spin_unlock_irq(&phba->hbalock);
  1136. /*
  1137. * Firmware stops when it triggred erratt. That could cause the I/Os
  1138. * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
  1139. * SCSI layer retry it after re-establishing link.
  1140. */
  1141. pring = &psli->ring[psli->fcp_ring];
  1142. lpfc_sli_abort_iocb_ring(phba, pring);
  1143. /*
  1144. * There was a firmware error. Take the hba offline and then
  1145. * attempt to restart it.
  1146. */
  1147. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  1148. lpfc_offline(phba);
  1149. /* Wait for the ER1 bit to clear.*/
  1150. while (phba->work_hs & HS_FFER1) {
  1151. msleep(100);
  1152. if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
  1153. phba->work_hs = UNPLUG_ERR ;
  1154. break;
  1155. }
  1156. /* If driver is unloading let the worker thread continue */
  1157. if (phba->pport->load_flag & FC_UNLOADING) {
  1158. phba->work_hs = 0;
  1159. break;
  1160. }
  1161. }
  1162. /*
  1163. * This is to ptrotect against a race condition in which
  1164. * first write to the host attention register clear the
  1165. * host status register.
  1166. */
  1167. if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
  1168. phba->work_hs = old_host_status & ~HS_FFER1;
  1169. spin_lock_irq(&phba->hbalock);
  1170. phba->hba_flag &= ~DEFER_ERATT;
  1171. spin_unlock_irq(&phba->hbalock);
  1172. phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
  1173. phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
  1174. }
  1175. static void
  1176. lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
  1177. {
  1178. struct lpfc_board_event_header board_event;
  1179. struct Scsi_Host *shost;
  1180. board_event.event_type = FC_REG_BOARD_EVENT;
  1181. board_event.subcategory = LPFC_EVENT_PORTINTERR;
  1182. shost = lpfc_shost_from_vport(phba->pport);
  1183. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1184. sizeof(board_event),
  1185. (char *) &board_event,
  1186. LPFC_NL_VENDOR_ID);
  1187. }
  1188. /**
  1189. * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
  1190. * @phba: pointer to lpfc hba data structure.
  1191. *
  1192. * This routine is invoked to handle the following HBA hardware error
  1193. * conditions:
  1194. * 1 - HBA error attention interrupt
  1195. * 2 - DMA ring index out of range
  1196. * 3 - Mailbox command came back as unknown
  1197. **/
  1198. static void
  1199. lpfc_handle_eratt_s3(struct lpfc_hba *phba)
  1200. {
  1201. struct lpfc_vport *vport = phba->pport;
  1202. struct lpfc_sli *psli = &phba->sli;
  1203. struct lpfc_sli_ring *pring;
  1204. uint32_t event_data;
  1205. unsigned long temperature;
  1206. struct temp_event temp_event_data;
  1207. struct Scsi_Host *shost;
  1208. /* If the pci channel is offline, ignore possible errors,
  1209. * since we cannot communicate with the pci card anyway.
  1210. */
  1211. if (pci_channel_offline(phba->pcidev)) {
  1212. spin_lock_irq(&phba->hbalock);
  1213. phba->hba_flag &= ~DEFER_ERATT;
  1214. spin_unlock_irq(&phba->hbalock);
  1215. return;
  1216. }
  1217. /* If resets are disabled then leave the HBA alone and return */
  1218. if (!phba->cfg_enable_hba_reset)
  1219. return;
  1220. /* Send an internal error event to mgmt application */
  1221. lpfc_board_errevt_to_mgmt(phba);
  1222. if (phba->hba_flag & DEFER_ERATT)
  1223. lpfc_handle_deferred_eratt(phba);
  1224. if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
  1225. if (phba->work_hs & HS_FFER6)
  1226. /* Re-establishing Link */
  1227. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1228. "1301 Re-establishing Link "
  1229. "Data: x%x x%x x%x\n",
  1230. phba->work_hs, phba->work_status[0],
  1231. phba->work_status[1]);
  1232. if (phba->work_hs & HS_FFER8)
  1233. /* Device Zeroization */
  1234. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1235. "2861 Host Authentication device "
  1236. "zeroization Data:x%x x%x x%x\n",
  1237. phba->work_hs, phba->work_status[0],
  1238. phba->work_status[1]);
  1239. spin_lock_irq(&phba->hbalock);
  1240. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1241. spin_unlock_irq(&phba->hbalock);
  1242. /*
  1243. * Firmware stops when it triggled erratt with HS_FFER6.
  1244. * That could cause the I/Os dropped by the firmware.
  1245. * Error iocb (I/O) on txcmplq and let the SCSI layer
  1246. * retry it after re-establishing link.
  1247. */
  1248. pring = &psli->ring[psli->fcp_ring];
  1249. lpfc_sli_abort_iocb_ring(phba, pring);
  1250. /*
  1251. * There was a firmware error. Take the hba offline and then
  1252. * attempt to restart it.
  1253. */
  1254. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  1255. lpfc_offline(phba);
  1256. lpfc_sli_brdrestart(phba);
  1257. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  1258. lpfc_unblock_mgmt_io(phba);
  1259. return;
  1260. }
  1261. lpfc_unblock_mgmt_io(phba);
  1262. } else if (phba->work_hs & HS_CRIT_TEMP) {
  1263. temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
  1264. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  1265. temp_event_data.event_code = LPFC_CRIT_TEMP;
  1266. temp_event_data.data = (uint32_t)temperature;
  1267. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1268. "0406 Adapter maximum temperature exceeded "
  1269. "(%ld), taking this port offline "
  1270. "Data: x%x x%x x%x\n",
  1271. temperature, phba->work_hs,
  1272. phba->work_status[0], phba->work_status[1]);
  1273. shost = lpfc_shost_from_vport(phba->pport);
  1274. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1275. sizeof(temp_event_data),
  1276. (char *) &temp_event_data,
  1277. SCSI_NL_VID_TYPE_PCI
  1278. | PCI_VENDOR_ID_EMULEX);
  1279. spin_lock_irq(&phba->hbalock);
  1280. phba->over_temp_state = HBA_OVER_TEMP;
  1281. spin_unlock_irq(&phba->hbalock);
  1282. lpfc_offline_eratt(phba);
  1283. } else {
  1284. /* The if clause above forces this code path when the status
  1285. * failure is a value other than FFER6. Do not call the offline
  1286. * twice. This is the adapter hardware error path.
  1287. */
  1288. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1289. "0457 Adapter Hardware Error "
  1290. "Data: x%x x%x x%x\n",
  1291. phba->work_hs,
  1292. phba->work_status[0], phba->work_status[1]);
  1293. event_data = FC_REG_DUMP_EVENT;
  1294. shost = lpfc_shost_from_vport(vport);
  1295. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1296. sizeof(event_data), (char *) &event_data,
  1297. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1298. lpfc_offline_eratt(phba);
  1299. }
  1300. return;
  1301. }
  1302. /**
  1303. * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
  1304. * @phba: pointer to lpfc hba data structure.
  1305. * @mbx_action: flag for mailbox shutdown action.
  1306. *
  1307. * This routine is invoked to perform an SLI4 port PCI function reset in
  1308. * response to port status register polling attention. It waits for port
  1309. * status register (ERR, RDY, RN) bits before proceeding with function reset.
  1310. * During this process, interrupt vectors are freed and later requested
  1311. * for handling possible port resource change.
  1312. **/
  1313. static int
  1314. lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action)
  1315. {
  1316. int rc;
  1317. uint32_t intr_mode;
  1318. /*
  1319. * On error status condition, driver need to wait for port
  1320. * ready before performing reset.
  1321. */
  1322. rc = lpfc_sli4_pdev_status_reg_wait(phba);
  1323. if (!rc) {
  1324. /* need reset: attempt for port recovery */
  1325. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1326. "2887 Reset Needed: Attempting Port "
  1327. "Recovery...\n");
  1328. lpfc_offline_prep(phba, mbx_action);
  1329. lpfc_offline(phba);
  1330. /* release interrupt for possible resource change */
  1331. lpfc_sli4_disable_intr(phba);
  1332. lpfc_sli_brdrestart(phba);
  1333. /* request and enable interrupt */
  1334. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  1335. if (intr_mode == LPFC_INTR_ERROR) {
  1336. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1337. "3175 Failed to enable interrupt\n");
  1338. return -EIO;
  1339. } else {
  1340. phba->intr_mode = intr_mode;
  1341. }
  1342. rc = lpfc_online(phba);
  1343. if (rc == 0)
  1344. lpfc_unblock_mgmt_io(phba);
  1345. }
  1346. return rc;
  1347. }
  1348. /**
  1349. * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
  1350. * @phba: pointer to lpfc hba data structure.
  1351. *
  1352. * This routine is invoked to handle the SLI4 HBA hardware error attention
  1353. * conditions.
  1354. **/
  1355. static void
  1356. lpfc_handle_eratt_s4(struct lpfc_hba *phba)
  1357. {
  1358. struct lpfc_vport *vport = phba->pport;
  1359. uint32_t event_data;
  1360. struct Scsi_Host *shost;
  1361. uint32_t if_type;
  1362. struct lpfc_register portstat_reg = {0};
  1363. uint32_t reg_err1, reg_err2;
  1364. uint32_t uerrlo_reg, uemasklo_reg;
  1365. uint32_t pci_rd_rc1, pci_rd_rc2;
  1366. int rc;
  1367. /* If the pci channel is offline, ignore possible errors, since
  1368. * we cannot communicate with the pci card anyway.
  1369. */
  1370. if (pci_channel_offline(phba->pcidev))
  1371. return;
  1372. /* If resets are disabled then leave the HBA alone and return */
  1373. if (!phba->cfg_enable_hba_reset)
  1374. return;
  1375. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  1376. switch (if_type) {
  1377. case LPFC_SLI_INTF_IF_TYPE_0:
  1378. pci_rd_rc1 = lpfc_readl(
  1379. phba->sli4_hba.u.if_type0.UERRLOregaddr,
  1380. &uerrlo_reg);
  1381. pci_rd_rc2 = lpfc_readl(
  1382. phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
  1383. &uemasklo_reg);
  1384. /* consider PCI bus read error as pci_channel_offline */
  1385. if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
  1386. return;
  1387. lpfc_sli4_offline_eratt(phba);
  1388. break;
  1389. case LPFC_SLI_INTF_IF_TYPE_2:
  1390. pci_rd_rc1 = lpfc_readl(
  1391. phba->sli4_hba.u.if_type2.STATUSregaddr,
  1392. &portstat_reg.word0);
  1393. /* consider PCI bus read error as pci_channel_offline */
  1394. if (pci_rd_rc1 == -EIO) {
  1395. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1396. "3151 PCI bus read access failure: x%x\n",
  1397. readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
  1398. return;
  1399. }
  1400. reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  1401. reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  1402. if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
  1403. /* TODO: Register for Overtemp async events. */
  1404. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1405. "2889 Port Overtemperature event, "
  1406. "taking port offline\n");
  1407. spin_lock_irq(&phba->hbalock);
  1408. phba->over_temp_state = HBA_OVER_TEMP;
  1409. spin_unlock_irq(&phba->hbalock);
  1410. lpfc_sli4_offline_eratt(phba);
  1411. break;
  1412. }
  1413. if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
  1414. reg_err2 == SLIPORT_ERR2_REG_FW_RESTART)
  1415. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1416. "3143 Port Down: Firmware Restarted\n");
  1417. else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
  1418. reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
  1419. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1420. "3144 Port Down: Debug Dump\n");
  1421. else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
  1422. reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
  1423. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1424. "3145 Port Down: Provisioning\n");
  1425. /* Check port status register for function reset */
  1426. rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT);
  1427. if (rc == 0) {
  1428. /* don't report event on forced debug dump */
  1429. if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
  1430. reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
  1431. return;
  1432. else
  1433. break;
  1434. }
  1435. /* fall through for not able to recover */
  1436. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1437. "3152 Unrecoverable error, bring the port "
  1438. "offline\n");
  1439. lpfc_sli4_offline_eratt(phba);
  1440. break;
  1441. case LPFC_SLI_INTF_IF_TYPE_1:
  1442. default:
  1443. break;
  1444. }
  1445. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1446. "3123 Report dump event to upper layer\n");
  1447. /* Send an internal error event to mgmt application */
  1448. lpfc_board_errevt_to_mgmt(phba);
  1449. event_data = FC_REG_DUMP_EVENT;
  1450. shost = lpfc_shost_from_vport(vport);
  1451. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1452. sizeof(event_data), (char *) &event_data,
  1453. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1454. }
  1455. /**
  1456. * lpfc_handle_eratt - Wrapper func for handling hba error attention
  1457. * @phba: pointer to lpfc HBA data structure.
  1458. *
  1459. * This routine wraps the actual SLI3 or SLI4 hba error attention handling
  1460. * routine from the API jump table function pointer from the lpfc_hba struct.
  1461. *
  1462. * Return codes
  1463. * 0 - success.
  1464. * Any other value - error.
  1465. **/
  1466. void
  1467. lpfc_handle_eratt(struct lpfc_hba *phba)
  1468. {
  1469. (*phba->lpfc_handle_eratt)(phba);
  1470. }
  1471. /**
  1472. * lpfc_handle_latt - The HBA link event handler
  1473. * @phba: pointer to lpfc hba data structure.
  1474. *
  1475. * This routine is invoked from the worker thread to handle a HBA host
  1476. * attention link event.
  1477. **/
  1478. void
  1479. lpfc_handle_latt(struct lpfc_hba *phba)
  1480. {
  1481. struct lpfc_vport *vport = phba->pport;
  1482. struct lpfc_sli *psli = &phba->sli;
  1483. LPFC_MBOXQ_t *pmb;
  1484. volatile uint32_t control;
  1485. struct lpfc_dmabuf *mp;
  1486. int rc = 0;
  1487. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1488. if (!pmb) {
  1489. rc = 1;
  1490. goto lpfc_handle_latt_err_exit;
  1491. }
  1492. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1493. if (!mp) {
  1494. rc = 2;
  1495. goto lpfc_handle_latt_free_pmb;
  1496. }
  1497. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  1498. if (!mp->virt) {
  1499. rc = 3;
  1500. goto lpfc_handle_latt_free_mp;
  1501. }
  1502. /* Cleanup any outstanding ELS commands */
  1503. lpfc_els_flush_all_cmd(phba);
  1504. psli->slistat.link_event++;
  1505. lpfc_read_topology(phba, pmb, mp);
  1506. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  1507. pmb->vport = vport;
  1508. /* Block ELS IOCBs until we have processed this mbox command */
  1509. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  1510. rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
  1511. if (rc == MBX_NOT_FINISHED) {
  1512. rc = 4;
  1513. goto lpfc_handle_latt_free_mbuf;
  1514. }
  1515. /* Clear Link Attention in HA REG */
  1516. spin_lock_irq(&phba->hbalock);
  1517. writel(HA_LATT, phba->HAregaddr);
  1518. readl(phba->HAregaddr); /* flush */
  1519. spin_unlock_irq(&phba->hbalock);
  1520. return;
  1521. lpfc_handle_latt_free_mbuf:
  1522. phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
  1523. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1524. lpfc_handle_latt_free_mp:
  1525. kfree(mp);
  1526. lpfc_handle_latt_free_pmb:
  1527. mempool_free(pmb, phba->mbox_mem_pool);
  1528. lpfc_handle_latt_err_exit:
  1529. /* Enable Link attention interrupts */
  1530. spin_lock_irq(&phba->hbalock);
  1531. psli->sli_flag |= LPFC_PROCESS_LA;
  1532. control = readl(phba->HCregaddr);
  1533. control |= HC_LAINT_ENA;
  1534. writel(control, phba->HCregaddr);
  1535. readl(phba->HCregaddr); /* flush */
  1536. /* Clear Link Attention in HA REG */
  1537. writel(HA_LATT, phba->HAregaddr);
  1538. readl(phba->HAregaddr); /* flush */
  1539. spin_unlock_irq(&phba->hbalock);
  1540. lpfc_linkdown(phba);
  1541. phba->link_state = LPFC_HBA_ERROR;
  1542. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1543. "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
  1544. return;
  1545. }
  1546. /**
  1547. * lpfc_parse_vpd - Parse VPD (Vital Product Data)
  1548. * @phba: pointer to lpfc hba data structure.
  1549. * @vpd: pointer to the vital product data.
  1550. * @len: length of the vital product data in bytes.
  1551. *
  1552. * This routine parses the Vital Product Data (VPD). The VPD is treated as
  1553. * an array of characters. In this routine, the ModelName, ProgramType, and
  1554. * ModelDesc, etc. fields of the phba data structure will be populated.
  1555. *
  1556. * Return codes
  1557. * 0 - pointer to the VPD passed in is NULL
  1558. * 1 - success
  1559. **/
  1560. int
  1561. lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
  1562. {
  1563. uint8_t lenlo, lenhi;
  1564. int Length;
  1565. int i, j;
  1566. int finished = 0;
  1567. int index = 0;
  1568. if (!vpd)
  1569. return 0;
  1570. /* Vital Product */
  1571. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1572. "0455 Vital Product Data: x%x x%x x%x x%x\n",
  1573. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  1574. (uint32_t) vpd[3]);
  1575. while (!finished && (index < (len - 4))) {
  1576. switch (vpd[index]) {
  1577. case 0x82:
  1578. case 0x91:
  1579. index += 1;
  1580. lenlo = vpd[index];
  1581. index += 1;
  1582. lenhi = vpd[index];
  1583. index += 1;
  1584. i = ((((unsigned short)lenhi) << 8) + lenlo);
  1585. index += i;
  1586. break;
  1587. case 0x90:
  1588. index += 1;
  1589. lenlo = vpd[index];
  1590. index += 1;
  1591. lenhi = vpd[index];
  1592. index += 1;
  1593. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  1594. if (Length > len - index)
  1595. Length = len - index;
  1596. while (Length > 0) {
  1597. /* Look for Serial Number */
  1598. if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
  1599. index += 2;
  1600. i = vpd[index];
  1601. index += 1;
  1602. j = 0;
  1603. Length -= (3+i);
  1604. while(i--) {
  1605. phba->SerialNumber[j++] = vpd[index++];
  1606. if (j == 31)
  1607. break;
  1608. }
  1609. phba->SerialNumber[j] = 0;
  1610. continue;
  1611. }
  1612. else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
  1613. phba->vpd_flag |= VPD_MODEL_DESC;
  1614. index += 2;
  1615. i = vpd[index];
  1616. index += 1;
  1617. j = 0;
  1618. Length -= (3+i);
  1619. while(i--) {
  1620. phba->ModelDesc[j++] = vpd[index++];
  1621. if (j == 255)
  1622. break;
  1623. }
  1624. phba->ModelDesc[j] = 0;
  1625. continue;
  1626. }
  1627. else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
  1628. phba->vpd_flag |= VPD_MODEL_NAME;
  1629. index += 2;
  1630. i = vpd[index];
  1631. index += 1;
  1632. j = 0;
  1633. Length -= (3+i);
  1634. while(i--) {
  1635. phba->ModelName[j++] = vpd[index++];
  1636. if (j == 79)
  1637. break;
  1638. }
  1639. phba->ModelName[j] = 0;
  1640. continue;
  1641. }
  1642. else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
  1643. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  1644. index += 2;
  1645. i = vpd[index];
  1646. index += 1;
  1647. j = 0;
  1648. Length -= (3+i);
  1649. while(i--) {
  1650. phba->ProgramType[j++] = vpd[index++];
  1651. if (j == 255)
  1652. break;
  1653. }
  1654. phba->ProgramType[j] = 0;
  1655. continue;
  1656. }
  1657. else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
  1658. phba->vpd_flag |= VPD_PORT;
  1659. index += 2;
  1660. i = vpd[index];
  1661. index += 1;
  1662. j = 0;
  1663. Length -= (3+i);
  1664. while(i--) {
  1665. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  1666. (phba->sli4_hba.pport_name_sta ==
  1667. LPFC_SLI4_PPNAME_GET)) {
  1668. j++;
  1669. index++;
  1670. } else
  1671. phba->Port[j++] = vpd[index++];
  1672. if (j == 19)
  1673. break;
  1674. }
  1675. if ((phba->sli_rev != LPFC_SLI_REV4) ||
  1676. (phba->sli4_hba.pport_name_sta ==
  1677. LPFC_SLI4_PPNAME_NON))
  1678. phba->Port[j] = 0;
  1679. continue;
  1680. }
  1681. else {
  1682. index += 2;
  1683. i = vpd[index];
  1684. index += 1;
  1685. index += i;
  1686. Length -= (3 + i);
  1687. }
  1688. }
  1689. finished = 0;
  1690. break;
  1691. case 0x78:
  1692. finished = 1;
  1693. break;
  1694. default:
  1695. index ++;
  1696. break;
  1697. }
  1698. }
  1699. return(1);
  1700. }
  1701. /**
  1702. * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
  1703. * @phba: pointer to lpfc hba data structure.
  1704. * @mdp: pointer to the data structure to hold the derived model name.
  1705. * @descp: pointer to the data structure to hold the derived description.
  1706. *
  1707. * This routine retrieves HBA's description based on its registered PCI device
  1708. * ID. The @descp passed into this function points to an array of 256 chars. It
  1709. * shall be returned with the model name, maximum speed, and the host bus type.
  1710. * The @mdp passed into this function points to an array of 80 chars. When the
  1711. * function returns, the @mdp will be filled with the model name.
  1712. **/
  1713. static void
  1714. lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
  1715. {
  1716. lpfc_vpd_t *vp;
  1717. uint16_t dev_id = phba->pcidev->device;
  1718. int max_speed;
  1719. int GE = 0;
  1720. int oneConnect = 0; /* default is not a oneConnect */
  1721. struct {
  1722. char *name;
  1723. char *bus;
  1724. char *function;
  1725. } m = {"<Unknown>", "", ""};
  1726. if (mdp && mdp[0] != '\0'
  1727. && descp && descp[0] != '\0')
  1728. return;
  1729. if (phba->lmt & LMT_16Gb)
  1730. max_speed = 16;
  1731. else if (phba->lmt & LMT_10Gb)
  1732. max_speed = 10;
  1733. else if (phba->lmt & LMT_8Gb)
  1734. max_speed = 8;
  1735. else if (phba->lmt & LMT_4Gb)
  1736. max_speed = 4;
  1737. else if (phba->lmt & LMT_2Gb)
  1738. max_speed = 2;
  1739. else if (phba->lmt & LMT_1Gb)
  1740. max_speed = 1;
  1741. else
  1742. max_speed = 0;
  1743. vp = &phba->vpd;
  1744. switch (dev_id) {
  1745. case PCI_DEVICE_ID_FIREFLY:
  1746. m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"};
  1747. break;
  1748. case PCI_DEVICE_ID_SUPERFLY:
  1749. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  1750. m = (typeof(m)){"LP7000", "PCI",
  1751. "Fibre Channel Adapter"};
  1752. else
  1753. m = (typeof(m)){"LP7000E", "PCI",
  1754. "Fibre Channel Adapter"};
  1755. break;
  1756. case PCI_DEVICE_ID_DRAGONFLY:
  1757. m = (typeof(m)){"LP8000", "PCI",
  1758. "Fibre Channel Adapter"};
  1759. break;
  1760. case PCI_DEVICE_ID_CENTAUR:
  1761. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  1762. m = (typeof(m)){"LP9002", "PCI",
  1763. "Fibre Channel Adapter"};
  1764. else
  1765. m = (typeof(m)){"LP9000", "PCI",
  1766. "Fibre Channel Adapter"};
  1767. break;
  1768. case PCI_DEVICE_ID_RFLY:
  1769. m = (typeof(m)){"LP952", "PCI",
  1770. "Fibre Channel Adapter"};
  1771. break;
  1772. case PCI_DEVICE_ID_PEGASUS:
  1773. m = (typeof(m)){"LP9802", "PCI-X",
  1774. "Fibre Channel Adapter"};
  1775. break;
  1776. case PCI_DEVICE_ID_THOR:
  1777. m = (typeof(m)){"LP10000", "PCI-X",
  1778. "Fibre Channel Adapter"};
  1779. break;
  1780. case PCI_DEVICE_ID_VIPER:
  1781. m = (typeof(m)){"LPX1000", "PCI-X",
  1782. "Fibre Channel Adapter"};
  1783. break;
  1784. case PCI_DEVICE_ID_PFLY:
  1785. m = (typeof(m)){"LP982", "PCI-X",
  1786. "Fibre Channel Adapter"};
  1787. break;
  1788. case PCI_DEVICE_ID_TFLY:
  1789. m = (typeof(m)){"LP1050", "PCI-X",
  1790. "Fibre Channel Adapter"};
  1791. break;
  1792. case PCI_DEVICE_ID_HELIOS:
  1793. m = (typeof(m)){"LP11000", "PCI-X2",
  1794. "Fibre Channel Adapter"};
  1795. break;
  1796. case PCI_DEVICE_ID_HELIOS_SCSP:
  1797. m = (typeof(m)){"LP11000-SP", "PCI-X2",
  1798. "Fibre Channel Adapter"};
  1799. break;
  1800. case PCI_DEVICE_ID_HELIOS_DCSP:
  1801. m = (typeof(m)){"LP11002-SP", "PCI-X2",
  1802. "Fibre Channel Adapter"};
  1803. break;
  1804. case PCI_DEVICE_ID_NEPTUNE:
  1805. m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"};
  1806. break;
  1807. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  1808. m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"};
  1809. break;
  1810. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  1811. m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"};
  1812. break;
  1813. case PCI_DEVICE_ID_BMID:
  1814. m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
  1815. break;
  1816. case PCI_DEVICE_ID_BSMB:
  1817. m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"};
  1818. break;
  1819. case PCI_DEVICE_ID_ZEPHYR:
  1820. m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
  1821. break;
  1822. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  1823. m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
  1824. break;
  1825. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  1826. m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
  1827. GE = 1;
  1828. break;
  1829. case PCI_DEVICE_ID_ZMID:
  1830. m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
  1831. break;
  1832. case PCI_DEVICE_ID_ZSMB:
  1833. m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
  1834. break;
  1835. case PCI_DEVICE_ID_LP101:
  1836. m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"};
  1837. break;
  1838. case PCI_DEVICE_ID_LP10000S:
  1839. m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"};
  1840. break;
  1841. case PCI_DEVICE_ID_LP11000S:
  1842. m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"};
  1843. break;
  1844. case PCI_DEVICE_ID_LPE11000S:
  1845. m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"};
  1846. break;
  1847. case PCI_DEVICE_ID_SAT:
  1848. m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
  1849. break;
  1850. case PCI_DEVICE_ID_SAT_MID:
  1851. m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
  1852. break;
  1853. case PCI_DEVICE_ID_SAT_SMB:
  1854. m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
  1855. break;
  1856. case PCI_DEVICE_ID_SAT_DCSP:
  1857. m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
  1858. break;
  1859. case PCI_DEVICE_ID_SAT_SCSP:
  1860. m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
  1861. break;
  1862. case PCI_DEVICE_ID_SAT_S:
  1863. m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
  1864. break;
  1865. case PCI_DEVICE_ID_HORNET:
  1866. m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"};
  1867. GE = 1;
  1868. break;
  1869. case PCI_DEVICE_ID_PROTEUS_VF:
  1870. m = (typeof(m)){"LPev12000", "PCIe IOV",
  1871. "Fibre Channel Adapter"};
  1872. break;
  1873. case PCI_DEVICE_ID_PROTEUS_PF:
  1874. m = (typeof(m)){"LPev12000", "PCIe IOV",
  1875. "Fibre Channel Adapter"};
  1876. break;
  1877. case PCI_DEVICE_ID_PROTEUS_S:
  1878. m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
  1879. "Fibre Channel Adapter"};
  1880. break;
  1881. case PCI_DEVICE_ID_TIGERSHARK:
  1882. oneConnect = 1;
  1883. m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
  1884. break;
  1885. case PCI_DEVICE_ID_TOMCAT:
  1886. oneConnect = 1;
  1887. m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
  1888. break;
  1889. case PCI_DEVICE_ID_FALCON:
  1890. m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
  1891. "EmulexSecure Fibre"};
  1892. break;
  1893. case PCI_DEVICE_ID_BALIUS:
  1894. m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
  1895. "Fibre Channel Adapter"};
  1896. break;
  1897. case PCI_DEVICE_ID_LANCER_FC:
  1898. case PCI_DEVICE_ID_LANCER_FC_VF:
  1899. m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
  1900. break;
  1901. case PCI_DEVICE_ID_LANCER_FCOE:
  1902. case PCI_DEVICE_ID_LANCER_FCOE_VF:
  1903. oneConnect = 1;
  1904. m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
  1905. break;
  1906. case PCI_DEVICE_ID_SKYHAWK:
  1907. case PCI_DEVICE_ID_SKYHAWK_VF:
  1908. oneConnect = 1;
  1909. m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
  1910. break;
  1911. default:
  1912. m = (typeof(m)){"Unknown", "", ""};
  1913. break;
  1914. }
  1915. if (mdp && mdp[0] == '\0')
  1916. snprintf(mdp, 79,"%s", m.name);
  1917. /*
  1918. * oneConnect hba requires special processing, they are all initiators
  1919. * and we put the port number on the end
  1920. */
  1921. if (descp && descp[0] == '\0') {
  1922. if (oneConnect)
  1923. snprintf(descp, 255,
  1924. "Emulex OneConnect %s, %s Initiator %s",
  1925. m.name, m.function,
  1926. phba->Port);
  1927. else if (max_speed == 0)
  1928. snprintf(descp, 255,
  1929. "Emulex %s %s %s ",
  1930. m.name, m.bus, m.function);
  1931. else
  1932. snprintf(descp, 255,
  1933. "Emulex %s %d%s %s %s",
  1934. m.name, max_speed, (GE) ? "GE" : "Gb",
  1935. m.bus, m.function);
  1936. }
  1937. }
  1938. /**
  1939. * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
  1940. * @phba: pointer to lpfc hba data structure.
  1941. * @pring: pointer to a IOCB ring.
  1942. * @cnt: the number of IOCBs to be posted to the IOCB ring.
  1943. *
  1944. * This routine posts a given number of IOCBs with the associated DMA buffer
  1945. * descriptors specified by the cnt argument to the given IOCB ring.
  1946. *
  1947. * Return codes
  1948. * The number of IOCBs NOT able to be posted to the IOCB ring.
  1949. **/
  1950. int
  1951. lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
  1952. {
  1953. IOCB_t *icmd;
  1954. struct lpfc_iocbq *iocb;
  1955. struct lpfc_dmabuf *mp1, *mp2;
  1956. cnt += pring->missbufcnt;
  1957. /* While there are buffers to post */
  1958. while (cnt > 0) {
  1959. /* Allocate buffer for command iocb */
  1960. iocb = lpfc_sli_get_iocbq(phba);
  1961. if (iocb == NULL) {
  1962. pring->missbufcnt = cnt;
  1963. return cnt;
  1964. }
  1965. icmd = &iocb->iocb;
  1966. /* 2 buffers can be posted per command */
  1967. /* Allocate buffer to post */
  1968. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1969. if (mp1)
  1970. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
  1971. if (!mp1 || !mp1->virt) {
  1972. kfree(mp1);
  1973. lpfc_sli_release_iocbq(phba, iocb);
  1974. pring->missbufcnt = cnt;
  1975. return cnt;
  1976. }
  1977. INIT_LIST_HEAD(&mp1->list);
  1978. /* Allocate buffer to post */
  1979. if (cnt > 1) {
  1980. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1981. if (mp2)
  1982. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  1983. &mp2->phys);
  1984. if (!mp2 || !mp2->virt) {
  1985. kfree(mp2);
  1986. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1987. kfree(mp1);
  1988. lpfc_sli_release_iocbq(phba, iocb);
  1989. pring->missbufcnt = cnt;
  1990. return cnt;
  1991. }
  1992. INIT_LIST_HEAD(&mp2->list);
  1993. } else {
  1994. mp2 = NULL;
  1995. }
  1996. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  1997. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  1998. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  1999. icmd->ulpBdeCount = 1;
  2000. cnt--;
  2001. if (mp2) {
  2002. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  2003. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  2004. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  2005. cnt--;
  2006. icmd->ulpBdeCount = 2;
  2007. }
  2008. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  2009. icmd->ulpLe = 1;
  2010. if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
  2011. IOCB_ERROR) {
  2012. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  2013. kfree(mp1);
  2014. cnt++;
  2015. if (mp2) {
  2016. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  2017. kfree(mp2);
  2018. cnt++;
  2019. }
  2020. lpfc_sli_release_iocbq(phba, iocb);
  2021. pring->missbufcnt = cnt;
  2022. return cnt;
  2023. }
  2024. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  2025. if (mp2)
  2026. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  2027. }
  2028. pring->missbufcnt = 0;
  2029. return 0;
  2030. }
  2031. /**
  2032. * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
  2033. * @phba: pointer to lpfc hba data structure.
  2034. *
  2035. * This routine posts initial receive IOCB buffers to the ELS ring. The
  2036. * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
  2037. * set to 64 IOCBs.
  2038. *
  2039. * Return codes
  2040. * 0 - success (currently always success)
  2041. **/
  2042. static int
  2043. lpfc_post_rcv_buf(struct lpfc_hba *phba)
  2044. {
  2045. struct lpfc_sli *psli = &phba->sli;
  2046. /* Ring 0, ELS / CT buffers */
  2047. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
  2048. /* Ring 2 - FCP no buffers needed */
  2049. return 0;
  2050. }
  2051. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  2052. /**
  2053. * lpfc_sha_init - Set up initial array of hash table entries
  2054. * @HashResultPointer: pointer to an array as hash table.
  2055. *
  2056. * This routine sets up the initial values to the array of hash table entries
  2057. * for the LC HBAs.
  2058. **/
  2059. static void
  2060. lpfc_sha_init(uint32_t * HashResultPointer)
  2061. {
  2062. HashResultPointer[0] = 0x67452301;
  2063. HashResultPointer[1] = 0xEFCDAB89;
  2064. HashResultPointer[2] = 0x98BADCFE;
  2065. HashResultPointer[3] = 0x10325476;
  2066. HashResultPointer[4] = 0xC3D2E1F0;
  2067. }
  2068. /**
  2069. * lpfc_sha_iterate - Iterate initial hash table with the working hash table
  2070. * @HashResultPointer: pointer to an initial/result hash table.
  2071. * @HashWorkingPointer: pointer to an working hash table.
  2072. *
  2073. * This routine iterates an initial hash table pointed by @HashResultPointer
  2074. * with the values from the working hash table pointeed by @HashWorkingPointer.
  2075. * The results are putting back to the initial hash table, returned through
  2076. * the @HashResultPointer as the result hash table.
  2077. **/
  2078. static void
  2079. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  2080. {
  2081. int t;
  2082. uint32_t TEMP;
  2083. uint32_t A, B, C, D, E;
  2084. t = 16;
  2085. do {
  2086. HashWorkingPointer[t] =
  2087. S(1,
  2088. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  2089. 8] ^
  2090. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  2091. } while (++t <= 79);
  2092. t = 0;
  2093. A = HashResultPointer[0];
  2094. B = HashResultPointer[1];
  2095. C = HashResultPointer[2];
  2096. D = HashResultPointer[3];
  2097. E = HashResultPointer[4];
  2098. do {
  2099. if (t < 20) {
  2100. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  2101. } else if (t < 40) {
  2102. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  2103. } else if (t < 60) {
  2104. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  2105. } else {
  2106. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  2107. }
  2108. TEMP += S(5, A) + E + HashWorkingPointer[t];
  2109. E = D;
  2110. D = C;
  2111. C = S(30, B);
  2112. B = A;
  2113. A = TEMP;
  2114. } while (++t <= 79);
  2115. HashResultPointer[0] += A;
  2116. HashResultPointer[1] += B;
  2117. HashResultPointer[2] += C;
  2118. HashResultPointer[3] += D;
  2119. HashResultPointer[4] += E;
  2120. }
  2121. /**
  2122. * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
  2123. * @RandomChallenge: pointer to the entry of host challenge random number array.
  2124. * @HashWorking: pointer to the entry of the working hash array.
  2125. *
  2126. * This routine calculates the working hash array referred by @HashWorking
  2127. * from the challenge random numbers associated with the host, referred by
  2128. * @RandomChallenge. The result is put into the entry of the working hash
  2129. * array and returned by reference through @HashWorking.
  2130. **/
  2131. static void
  2132. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  2133. {
  2134. *HashWorking = (*RandomChallenge ^ *HashWorking);
  2135. }
  2136. /**
  2137. * lpfc_hba_init - Perform special handling for LC HBA initialization
  2138. * @phba: pointer to lpfc hba data structure.
  2139. * @hbainit: pointer to an array of unsigned 32-bit integers.
  2140. *
  2141. * This routine performs the special handling for LC HBA initialization.
  2142. **/
  2143. void
  2144. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  2145. {
  2146. int t;
  2147. uint32_t *HashWorking;
  2148. uint32_t *pwwnn = (uint32_t *) phba->wwnn;
  2149. HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
  2150. if (!HashWorking)
  2151. return;
  2152. HashWorking[0] = HashWorking[78] = *pwwnn++;
  2153. HashWorking[1] = HashWorking[79] = *pwwnn;
  2154. for (t = 0; t < 7; t++)
  2155. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  2156. lpfc_sha_init(hbainit);
  2157. lpfc_sha_iterate(hbainit, HashWorking);
  2158. kfree(HashWorking);
  2159. }
  2160. /**
  2161. * lpfc_cleanup - Performs vport cleanups before deleting a vport
  2162. * @vport: pointer to a virtual N_Port data structure.
  2163. *
  2164. * This routine performs the necessary cleanups before deleting the @vport.
  2165. * It invokes the discovery state machine to perform necessary state
  2166. * transitions and to release the ndlps associated with the @vport. Note,
  2167. * the physical port is treated as @vport 0.
  2168. **/
  2169. void
  2170. lpfc_cleanup(struct lpfc_vport *vport)
  2171. {
  2172. struct lpfc_hba *phba = vport->phba;
  2173. struct lpfc_nodelist *ndlp, *next_ndlp;
  2174. int i = 0;
  2175. if (phba->link_state > LPFC_LINK_DOWN)
  2176. lpfc_port_link_failure(vport);
  2177. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  2178. if (!NLP_CHK_NODE_ACT(ndlp)) {
  2179. ndlp = lpfc_enable_node(vport, ndlp,
  2180. NLP_STE_UNUSED_NODE);
  2181. if (!ndlp)
  2182. continue;
  2183. spin_lock_irq(&phba->ndlp_lock);
  2184. NLP_SET_FREE_REQ(ndlp);
  2185. spin_unlock_irq(&phba->ndlp_lock);
  2186. /* Trigger the release of the ndlp memory */
  2187. lpfc_nlp_put(ndlp);
  2188. continue;
  2189. }
  2190. spin_lock_irq(&phba->ndlp_lock);
  2191. if (NLP_CHK_FREE_REQ(ndlp)) {
  2192. /* The ndlp should not be in memory free mode already */
  2193. spin_unlock_irq(&phba->ndlp_lock);
  2194. continue;
  2195. } else
  2196. /* Indicate request for freeing ndlp memory */
  2197. NLP_SET_FREE_REQ(ndlp);
  2198. spin_unlock_irq(&phba->ndlp_lock);
  2199. if (vport->port_type != LPFC_PHYSICAL_PORT &&
  2200. ndlp->nlp_DID == Fabric_DID) {
  2201. /* Just free up ndlp with Fabric_DID for vports */
  2202. lpfc_nlp_put(ndlp);
  2203. continue;
  2204. }
  2205. /* take care of nodes in unused state before the state
  2206. * machine taking action.
  2207. */
  2208. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
  2209. lpfc_nlp_put(ndlp);
  2210. continue;
  2211. }
  2212. if (ndlp->nlp_type & NLP_FABRIC)
  2213. lpfc_disc_state_machine(vport, ndlp, NULL,
  2214. NLP_EVT_DEVICE_RECOVERY);
  2215. lpfc_disc_state_machine(vport, ndlp, NULL,
  2216. NLP_EVT_DEVICE_RM);
  2217. }
  2218. /* At this point, ALL ndlp's should be gone
  2219. * because of the previous NLP_EVT_DEVICE_RM.
  2220. * Lets wait for this to happen, if needed.
  2221. */
  2222. while (!list_empty(&vport->fc_nodes)) {
  2223. if (i++ > 3000) {
  2224. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2225. "0233 Nodelist not empty\n");
  2226. list_for_each_entry_safe(ndlp, next_ndlp,
  2227. &vport->fc_nodes, nlp_listp) {
  2228. lpfc_printf_vlog(ndlp->vport, KERN_ERR,
  2229. LOG_NODE,
  2230. "0282 did:x%x ndlp:x%p "
  2231. "usgmap:x%x refcnt:%d\n",
  2232. ndlp->nlp_DID, (void *)ndlp,
  2233. ndlp->nlp_usg_map,
  2234. atomic_read(
  2235. &ndlp->kref.refcount));
  2236. }
  2237. break;
  2238. }
  2239. /* Wait for any activity on ndlps to settle */
  2240. msleep(10);
  2241. }
  2242. lpfc_cleanup_vports_rrqs(vport, NULL);
  2243. }
  2244. /**
  2245. * lpfc_stop_vport_timers - Stop all the timers associated with a vport
  2246. * @vport: pointer to a virtual N_Port data structure.
  2247. *
  2248. * This routine stops all the timers associated with a @vport. This function
  2249. * is invoked before disabling or deleting a @vport. Note that the physical
  2250. * port is treated as @vport 0.
  2251. **/
  2252. void
  2253. lpfc_stop_vport_timers(struct lpfc_vport *vport)
  2254. {
  2255. del_timer_sync(&vport->els_tmofunc);
  2256. del_timer_sync(&vport->fc_fdmitmo);
  2257. del_timer_sync(&vport->delayed_disc_tmo);
  2258. lpfc_can_disctmo(vport);
  2259. return;
  2260. }
  2261. /**
  2262. * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
  2263. * @phba: pointer to lpfc hba data structure.
  2264. *
  2265. * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
  2266. * caller of this routine should already hold the host lock.
  2267. **/
  2268. void
  2269. __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
  2270. {
  2271. /* Clear pending FCF rediscovery wait flag */
  2272. phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
  2273. /* Now, try to stop the timer */
  2274. del_timer(&phba->fcf.redisc_wait);
  2275. }
  2276. /**
  2277. * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
  2278. * @phba: pointer to lpfc hba data structure.
  2279. *
  2280. * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
  2281. * checks whether the FCF rediscovery wait timer is pending with the host
  2282. * lock held before proceeding with disabling the timer and clearing the
  2283. * wait timer pendig flag.
  2284. **/
  2285. void
  2286. lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
  2287. {
  2288. spin_lock_irq(&phba->hbalock);
  2289. if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
  2290. /* FCF rediscovery timer already fired or stopped */
  2291. spin_unlock_irq(&phba->hbalock);
  2292. return;
  2293. }
  2294. __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
  2295. /* Clear failover in progress flags */
  2296. phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
  2297. spin_unlock_irq(&phba->hbalock);
  2298. }
  2299. /**
  2300. * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
  2301. * @phba: pointer to lpfc hba data structure.
  2302. *
  2303. * This routine stops all the timers associated with a HBA. This function is
  2304. * invoked before either putting a HBA offline or unloading the driver.
  2305. **/
  2306. void
  2307. lpfc_stop_hba_timers(struct lpfc_hba *phba)
  2308. {
  2309. lpfc_stop_vport_timers(phba->pport);
  2310. del_timer_sync(&phba->sli.mbox_tmo);
  2311. del_timer_sync(&phba->fabric_block_timer);
  2312. del_timer_sync(&phba->eratt_poll);
  2313. del_timer_sync(&phba->hb_tmofunc);
  2314. if (phba->sli_rev == LPFC_SLI_REV4) {
  2315. del_timer_sync(&phba->rrq_tmr);
  2316. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  2317. }
  2318. phba->hb_outstanding = 0;
  2319. switch (phba->pci_dev_grp) {
  2320. case LPFC_PCI_DEV_LP:
  2321. /* Stop any LightPulse device specific driver timers */
  2322. del_timer_sync(&phba->fcp_poll_timer);
  2323. break;
  2324. case LPFC_PCI_DEV_OC:
  2325. /* Stop any OneConnect device sepcific driver timers */
  2326. lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
  2327. break;
  2328. default:
  2329. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2330. "0297 Invalid device group (x%x)\n",
  2331. phba->pci_dev_grp);
  2332. break;
  2333. }
  2334. return;
  2335. }
  2336. /**
  2337. * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
  2338. * @phba: pointer to lpfc hba data structure.
  2339. *
  2340. * This routine marks a HBA's management interface as blocked. Once the HBA's
  2341. * management interface is marked as blocked, all the user space access to
  2342. * the HBA, whether they are from sysfs interface or libdfc interface will
  2343. * all be blocked. The HBA is set to block the management interface when the
  2344. * driver prepares the HBA interface for online or offline.
  2345. **/
  2346. static void
  2347. lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
  2348. {
  2349. unsigned long iflag;
  2350. uint8_t actcmd = MBX_HEARTBEAT;
  2351. unsigned long timeout;
  2352. spin_lock_irqsave(&phba->hbalock, iflag);
  2353. phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
  2354. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2355. if (mbx_action == LPFC_MBX_NO_WAIT)
  2356. return;
  2357. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  2358. spin_lock_irqsave(&phba->hbalock, iflag);
  2359. if (phba->sli.mbox_active) {
  2360. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  2361. /* Determine how long we might wait for the active mailbox
  2362. * command to be gracefully completed by firmware.
  2363. */
  2364. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  2365. phba->sli.mbox_active) * 1000) + jiffies;
  2366. }
  2367. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2368. /* Wait for the outstnading mailbox command to complete */
  2369. while (phba->sli.mbox_active) {
  2370. /* Check active mailbox complete status every 2ms */
  2371. msleep(2);
  2372. if (time_after(jiffies, timeout)) {
  2373. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2374. "2813 Mgmt IO is Blocked %x "
  2375. "- mbox cmd %x still active\n",
  2376. phba->sli.sli_flag, actcmd);
  2377. break;
  2378. }
  2379. }
  2380. }
  2381. /**
  2382. * lpfc_sli4_node_prep - Assign RPIs for active nodes.
  2383. * @phba: pointer to lpfc hba data structure.
  2384. *
  2385. * Allocate RPIs for all active remote nodes. This is needed whenever
  2386. * an SLI4 adapter is reset and the driver is not unloading. Its purpose
  2387. * is to fixup the temporary rpi assignments.
  2388. **/
  2389. void
  2390. lpfc_sli4_node_prep(struct lpfc_hba *phba)
  2391. {
  2392. struct lpfc_nodelist *ndlp, *next_ndlp;
  2393. struct lpfc_vport **vports;
  2394. int i;
  2395. if (phba->sli_rev != LPFC_SLI_REV4)
  2396. return;
  2397. vports = lpfc_create_vport_work_array(phba);
  2398. if (vports != NULL) {
  2399. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2400. if (vports[i]->load_flag & FC_UNLOADING)
  2401. continue;
  2402. list_for_each_entry_safe(ndlp, next_ndlp,
  2403. &vports[i]->fc_nodes,
  2404. nlp_listp) {
  2405. if (NLP_CHK_NODE_ACT(ndlp))
  2406. ndlp->nlp_rpi =
  2407. lpfc_sli4_alloc_rpi(phba);
  2408. }
  2409. }
  2410. }
  2411. lpfc_destroy_vport_work_array(phba, vports);
  2412. }
  2413. /**
  2414. * lpfc_online - Initialize and bring a HBA online
  2415. * @phba: pointer to lpfc hba data structure.
  2416. *
  2417. * This routine initializes the HBA and brings a HBA online. During this
  2418. * process, the management interface is blocked to prevent user space access
  2419. * to the HBA interfering with the driver initialization.
  2420. *
  2421. * Return codes
  2422. * 0 - successful
  2423. * 1 - failed
  2424. **/
  2425. int
  2426. lpfc_online(struct lpfc_hba *phba)
  2427. {
  2428. struct lpfc_vport *vport;
  2429. struct lpfc_vport **vports;
  2430. int i;
  2431. bool vpis_cleared = false;
  2432. if (!phba)
  2433. return 0;
  2434. vport = phba->pport;
  2435. if (!(vport->fc_flag & FC_OFFLINE_MODE))
  2436. return 0;
  2437. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2438. "0458 Bring Adapter online\n");
  2439. lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
  2440. if (!lpfc_sli_queue_setup(phba)) {
  2441. lpfc_unblock_mgmt_io(phba);
  2442. return 1;
  2443. }
  2444. if (phba->sli_rev == LPFC_SLI_REV4) {
  2445. if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
  2446. lpfc_unblock_mgmt_io(phba);
  2447. return 1;
  2448. }
  2449. spin_lock_irq(&phba->hbalock);
  2450. if (!phba->sli4_hba.max_cfg_param.vpi_used)
  2451. vpis_cleared = true;
  2452. spin_unlock_irq(&phba->hbalock);
  2453. } else {
  2454. if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
  2455. lpfc_unblock_mgmt_io(phba);
  2456. return 1;
  2457. }
  2458. }
  2459. vports = lpfc_create_vport_work_array(phba);
  2460. if (vports != NULL)
  2461. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2462. struct Scsi_Host *shost;
  2463. shost = lpfc_shost_from_vport(vports[i]);
  2464. spin_lock_irq(shost->host_lock);
  2465. vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
  2466. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  2467. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2468. if (phba->sli_rev == LPFC_SLI_REV4) {
  2469. vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  2470. if ((vpis_cleared) &&
  2471. (vports[i]->port_type !=
  2472. LPFC_PHYSICAL_PORT))
  2473. vports[i]->vpi = 0;
  2474. }
  2475. spin_unlock_irq(shost->host_lock);
  2476. }
  2477. lpfc_destroy_vport_work_array(phba, vports);
  2478. lpfc_unblock_mgmt_io(phba);
  2479. return 0;
  2480. }
  2481. /**
  2482. * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
  2483. * @phba: pointer to lpfc hba data structure.
  2484. *
  2485. * This routine marks a HBA's management interface as not blocked. Once the
  2486. * HBA's management interface is marked as not blocked, all the user space
  2487. * access to the HBA, whether they are from sysfs interface or libdfc
  2488. * interface will be allowed. The HBA is set to block the management interface
  2489. * when the driver prepares the HBA interface for online or offline and then
  2490. * set to unblock the management interface afterwards.
  2491. **/
  2492. void
  2493. lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
  2494. {
  2495. unsigned long iflag;
  2496. spin_lock_irqsave(&phba->hbalock, iflag);
  2497. phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
  2498. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2499. }
  2500. /**
  2501. * lpfc_offline_prep - Prepare a HBA to be brought offline
  2502. * @phba: pointer to lpfc hba data structure.
  2503. *
  2504. * This routine is invoked to prepare a HBA to be brought offline. It performs
  2505. * unregistration login to all the nodes on all vports and flushes the mailbox
  2506. * queue to make it ready to be brought offline.
  2507. **/
  2508. void
  2509. lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
  2510. {
  2511. struct lpfc_vport *vport = phba->pport;
  2512. struct lpfc_nodelist *ndlp, *next_ndlp;
  2513. struct lpfc_vport **vports;
  2514. struct Scsi_Host *shost;
  2515. int i;
  2516. if (vport->fc_flag & FC_OFFLINE_MODE)
  2517. return;
  2518. lpfc_block_mgmt_io(phba, mbx_action);
  2519. lpfc_linkdown(phba);
  2520. /* Issue an unreg_login to all nodes on all vports */
  2521. vports = lpfc_create_vport_work_array(phba);
  2522. if (vports != NULL) {
  2523. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2524. if (vports[i]->load_flag & FC_UNLOADING)
  2525. continue;
  2526. shost = lpfc_shost_from_vport(vports[i]);
  2527. spin_lock_irq(shost->host_lock);
  2528. vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
  2529. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2530. vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
  2531. spin_unlock_irq(shost->host_lock);
  2532. shost = lpfc_shost_from_vport(vports[i]);
  2533. list_for_each_entry_safe(ndlp, next_ndlp,
  2534. &vports[i]->fc_nodes,
  2535. nlp_listp) {
  2536. if (!NLP_CHK_NODE_ACT(ndlp))
  2537. continue;
  2538. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  2539. continue;
  2540. if (ndlp->nlp_type & NLP_FABRIC) {
  2541. lpfc_disc_state_machine(vports[i], ndlp,
  2542. NULL, NLP_EVT_DEVICE_RECOVERY);
  2543. lpfc_disc_state_machine(vports[i], ndlp,
  2544. NULL, NLP_EVT_DEVICE_RM);
  2545. }
  2546. spin_lock_irq(shost->host_lock);
  2547. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2548. spin_unlock_irq(shost->host_lock);
  2549. /*
  2550. * Whenever an SLI4 port goes offline, free the
  2551. * RPI. Get a new RPI when the adapter port
  2552. * comes back online.
  2553. */
  2554. if (phba->sli_rev == LPFC_SLI_REV4)
  2555. lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
  2556. lpfc_unreg_rpi(vports[i], ndlp);
  2557. }
  2558. }
  2559. }
  2560. lpfc_destroy_vport_work_array(phba, vports);
  2561. lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
  2562. }
  2563. /**
  2564. * lpfc_offline - Bring a HBA offline
  2565. * @phba: pointer to lpfc hba data structure.
  2566. *
  2567. * This routine actually brings a HBA offline. It stops all the timers
  2568. * associated with the HBA, brings down the SLI layer, and eventually
  2569. * marks the HBA as in offline state for the upper layer protocol.
  2570. **/
  2571. void
  2572. lpfc_offline(struct lpfc_hba *phba)
  2573. {
  2574. struct Scsi_Host *shost;
  2575. struct lpfc_vport **vports;
  2576. int i;
  2577. if (phba->pport->fc_flag & FC_OFFLINE_MODE)
  2578. return;
  2579. /* stop port and all timers associated with this hba */
  2580. lpfc_stop_port(phba);
  2581. vports = lpfc_create_vport_work_array(phba);
  2582. if (vports != NULL)
  2583. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  2584. lpfc_stop_vport_timers(vports[i]);
  2585. lpfc_destroy_vport_work_array(phba, vports);
  2586. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2587. "0460 Bring Adapter offline\n");
  2588. /* Bring down the SLI Layer and cleanup. The HBA is offline
  2589. now. */
  2590. lpfc_sli_hba_down(phba);
  2591. spin_lock_irq(&phba->hbalock);
  2592. phba->work_ha = 0;
  2593. spin_unlock_irq(&phba->hbalock);
  2594. vports = lpfc_create_vport_work_array(phba);
  2595. if (vports != NULL)
  2596. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2597. shost = lpfc_shost_from_vport(vports[i]);
  2598. spin_lock_irq(shost->host_lock);
  2599. vports[i]->work_port_events = 0;
  2600. vports[i]->fc_flag |= FC_OFFLINE_MODE;
  2601. spin_unlock_irq(shost->host_lock);
  2602. }
  2603. lpfc_destroy_vport_work_array(phba, vports);
  2604. }
  2605. /**
  2606. * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
  2607. * @phba: pointer to lpfc hba data structure.
  2608. *
  2609. * This routine is to free all the SCSI buffers and IOCBs from the driver
  2610. * list back to kernel. It is called from lpfc_pci_remove_one to free
  2611. * the internal resources before the device is removed from the system.
  2612. **/
  2613. static void
  2614. lpfc_scsi_free(struct lpfc_hba *phba)
  2615. {
  2616. struct lpfc_scsi_buf *sb, *sb_next;
  2617. struct lpfc_iocbq *io, *io_next;
  2618. spin_lock_irq(&phba->hbalock);
  2619. /* Release all the lpfc_scsi_bufs maintained by this host. */
  2620. spin_lock(&phba->scsi_buf_list_put_lock);
  2621. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
  2622. list) {
  2623. list_del(&sb->list);
  2624. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  2625. sb->dma_handle);
  2626. kfree(sb);
  2627. phba->total_scsi_bufs--;
  2628. }
  2629. spin_unlock(&phba->scsi_buf_list_put_lock);
  2630. spin_lock(&phba->scsi_buf_list_get_lock);
  2631. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
  2632. list) {
  2633. list_del(&sb->list);
  2634. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  2635. sb->dma_handle);
  2636. kfree(sb);
  2637. phba->total_scsi_bufs--;
  2638. }
  2639. spin_unlock(&phba->scsi_buf_list_get_lock);
  2640. /* Release all the lpfc_iocbq entries maintained by this host. */
  2641. list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
  2642. list_del(&io->list);
  2643. kfree(io);
  2644. phba->total_iocbq_bufs--;
  2645. }
  2646. spin_unlock_irq(&phba->hbalock);
  2647. }
  2648. /**
  2649. * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
  2650. * @phba: pointer to lpfc hba data structure.
  2651. *
  2652. * This routine first calculates the sizes of the current els and allocated
  2653. * scsi sgl lists, and then goes through all sgls to updates the physical
  2654. * XRIs assigned due to port function reset. During port initialization, the
  2655. * current els and allocated scsi sgl lists are 0s.
  2656. *
  2657. * Return codes
  2658. * 0 - successful (for now, it always returns 0)
  2659. **/
  2660. int
  2661. lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
  2662. {
  2663. struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
  2664. struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL;
  2665. uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt;
  2666. LIST_HEAD(els_sgl_list);
  2667. LIST_HEAD(scsi_sgl_list);
  2668. int rc;
  2669. /*
  2670. * update on pci function's els xri-sgl list
  2671. */
  2672. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  2673. if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
  2674. /* els xri-sgl expanded */
  2675. xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
  2676. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2677. "3157 ELS xri-sgl count increased from "
  2678. "%d to %d\n", phba->sli4_hba.els_xri_cnt,
  2679. els_xri_cnt);
  2680. /* allocate the additional els sgls */
  2681. for (i = 0; i < xri_cnt; i++) {
  2682. sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
  2683. GFP_KERNEL);
  2684. if (sglq_entry == NULL) {
  2685. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2686. "2562 Failure to allocate an "
  2687. "ELS sgl entry:%d\n", i);
  2688. rc = -ENOMEM;
  2689. goto out_free_mem;
  2690. }
  2691. sglq_entry->buff_type = GEN_BUFF_TYPE;
  2692. sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
  2693. &sglq_entry->phys);
  2694. if (sglq_entry->virt == NULL) {
  2695. kfree(sglq_entry);
  2696. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2697. "2563 Failure to allocate an "
  2698. "ELS mbuf:%d\n", i);
  2699. rc = -ENOMEM;
  2700. goto out_free_mem;
  2701. }
  2702. sglq_entry->sgl = sglq_entry->virt;
  2703. memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
  2704. sglq_entry->state = SGL_FREED;
  2705. list_add_tail(&sglq_entry->list, &els_sgl_list);
  2706. }
  2707. spin_lock_irq(&phba->hbalock);
  2708. list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
  2709. spin_unlock_irq(&phba->hbalock);
  2710. } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
  2711. /* els xri-sgl shrinked */
  2712. xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
  2713. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2714. "3158 ELS xri-sgl count decreased from "
  2715. "%d to %d\n", phba->sli4_hba.els_xri_cnt,
  2716. els_xri_cnt);
  2717. spin_lock_irq(&phba->hbalock);
  2718. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list);
  2719. spin_unlock_irq(&phba->hbalock);
  2720. /* release extra els sgls from list */
  2721. for (i = 0; i < xri_cnt; i++) {
  2722. list_remove_head(&els_sgl_list,
  2723. sglq_entry, struct lpfc_sglq, list);
  2724. if (sglq_entry) {
  2725. lpfc_mbuf_free(phba, sglq_entry->virt,
  2726. sglq_entry->phys);
  2727. kfree(sglq_entry);
  2728. }
  2729. }
  2730. spin_lock_irq(&phba->hbalock);
  2731. list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
  2732. spin_unlock_irq(&phba->hbalock);
  2733. } else
  2734. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2735. "3163 ELS xri-sgl count unchanged: %d\n",
  2736. els_xri_cnt);
  2737. phba->sli4_hba.els_xri_cnt = els_xri_cnt;
  2738. /* update xris to els sgls on the list */
  2739. sglq_entry = NULL;
  2740. sglq_entry_next = NULL;
  2741. list_for_each_entry_safe(sglq_entry, sglq_entry_next,
  2742. &phba->sli4_hba.lpfc_sgl_list, list) {
  2743. lxri = lpfc_sli4_next_xritag(phba);
  2744. if (lxri == NO_XRI) {
  2745. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2746. "2400 Failed to allocate xri for "
  2747. "ELS sgl\n");
  2748. rc = -ENOMEM;
  2749. goto out_free_mem;
  2750. }
  2751. sglq_entry->sli4_lxritag = lxri;
  2752. sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
  2753. }
  2754. /*
  2755. * update on pci function's allocated scsi xri-sgl list
  2756. */
  2757. phba->total_scsi_bufs = 0;
  2758. /* maximum number of xris available for scsi buffers */
  2759. phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
  2760. els_xri_cnt;
  2761. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2762. "2401 Current allocated SCSI xri-sgl count:%d, "
  2763. "maximum SCSI xri count:%d\n",
  2764. phba->sli4_hba.scsi_xri_cnt,
  2765. phba->sli4_hba.scsi_xri_max);
  2766. spin_lock_irq(&phba->scsi_buf_list_get_lock);
  2767. spin_lock_irq(&phba->scsi_buf_list_put_lock);
  2768. list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
  2769. list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
  2770. spin_unlock_irq(&phba->scsi_buf_list_put_lock);
  2771. spin_unlock_irq(&phba->scsi_buf_list_get_lock);
  2772. if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
  2773. /* max scsi xri shrinked below the allocated scsi buffers */
  2774. scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
  2775. phba->sli4_hba.scsi_xri_max;
  2776. /* release the extra allocated scsi buffers */
  2777. for (i = 0; i < scsi_xri_cnt; i++) {
  2778. list_remove_head(&scsi_sgl_list, psb,
  2779. struct lpfc_scsi_buf, list);
  2780. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, psb->data,
  2781. psb->dma_handle);
  2782. kfree(psb);
  2783. }
  2784. spin_lock_irq(&phba->scsi_buf_list_get_lock);
  2785. phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
  2786. spin_unlock_irq(&phba->scsi_buf_list_get_lock);
  2787. }
  2788. /* update xris associated to remaining allocated scsi buffers */
  2789. psb = NULL;
  2790. psb_next = NULL;
  2791. list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
  2792. lxri = lpfc_sli4_next_xritag(phba);
  2793. if (lxri == NO_XRI) {
  2794. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2795. "2560 Failed to allocate xri for "
  2796. "scsi buffer\n");
  2797. rc = -ENOMEM;
  2798. goto out_free_mem;
  2799. }
  2800. psb->cur_iocbq.sli4_lxritag = lxri;
  2801. psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
  2802. }
  2803. spin_lock_irq(&phba->scsi_buf_list_get_lock);
  2804. spin_lock_irq(&phba->scsi_buf_list_put_lock);
  2805. list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
  2806. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
  2807. spin_unlock_irq(&phba->scsi_buf_list_put_lock);
  2808. spin_unlock_irq(&phba->scsi_buf_list_get_lock);
  2809. return 0;
  2810. out_free_mem:
  2811. lpfc_free_els_sgl_list(phba);
  2812. lpfc_scsi_free(phba);
  2813. return rc;
  2814. }
  2815. /**
  2816. * lpfc_create_port - Create an FC port
  2817. * @phba: pointer to lpfc hba data structure.
  2818. * @instance: a unique integer ID to this FC port.
  2819. * @dev: pointer to the device data structure.
  2820. *
  2821. * This routine creates a FC port for the upper layer protocol. The FC port
  2822. * can be created on top of either a physical port or a virtual port provided
  2823. * by the HBA. This routine also allocates a SCSI host data structure (shost)
  2824. * and associates the FC port created before adding the shost into the SCSI
  2825. * layer.
  2826. *
  2827. * Return codes
  2828. * @vport - pointer to the virtual N_Port data structure.
  2829. * NULL - port create failed.
  2830. **/
  2831. struct lpfc_vport *
  2832. lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
  2833. {
  2834. struct lpfc_vport *vport;
  2835. struct Scsi_Host *shost;
  2836. int error = 0;
  2837. if (dev != &phba->pcidev->dev)
  2838. shost = scsi_host_alloc(&lpfc_vport_template,
  2839. sizeof(struct lpfc_vport));
  2840. else
  2841. shost = scsi_host_alloc(&lpfc_template,
  2842. sizeof(struct lpfc_vport));
  2843. if (!shost)
  2844. goto out;
  2845. vport = (struct lpfc_vport *) shost->hostdata;
  2846. vport->phba = phba;
  2847. vport->load_flag |= FC_LOADING;
  2848. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2849. vport->fc_rscn_flush = 0;
  2850. lpfc_get_vport_cfgparam(vport);
  2851. shost->unique_id = instance;
  2852. shost->max_id = LPFC_MAX_TARGET;
  2853. shost->max_lun = vport->cfg_max_luns;
  2854. shost->this_id = -1;
  2855. shost->max_cmd_len = 16;
  2856. if (phba->sli_rev == LPFC_SLI_REV4) {
  2857. shost->dma_boundary =
  2858. phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
  2859. shost->sg_tablesize = phba->cfg_sg_seg_cnt;
  2860. }
  2861. /*
  2862. * Set initial can_queue value since 0 is no longer supported and
  2863. * scsi_add_host will fail. This will be adjusted later based on the
  2864. * max xri value determined in hba setup.
  2865. */
  2866. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  2867. if (dev != &phba->pcidev->dev) {
  2868. shost->transportt = lpfc_vport_transport_template;
  2869. vport->port_type = LPFC_NPIV_PORT;
  2870. } else {
  2871. shost->transportt = lpfc_transport_template;
  2872. vport->port_type = LPFC_PHYSICAL_PORT;
  2873. }
  2874. /* Initialize all internally managed lists. */
  2875. INIT_LIST_HEAD(&vport->fc_nodes);
  2876. INIT_LIST_HEAD(&vport->rcv_buffer_list);
  2877. spin_lock_init(&vport->work_port_lock);
  2878. init_timer(&vport->fc_disctmo);
  2879. vport->fc_disctmo.function = lpfc_disc_timeout;
  2880. vport->fc_disctmo.data = (unsigned long)vport;
  2881. init_timer(&vport->fc_fdmitmo);
  2882. vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
  2883. vport->fc_fdmitmo.data = (unsigned long)vport;
  2884. init_timer(&vport->els_tmofunc);
  2885. vport->els_tmofunc.function = lpfc_els_timeout;
  2886. vport->els_tmofunc.data = (unsigned long)vport;
  2887. init_timer(&vport->delayed_disc_tmo);
  2888. vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
  2889. vport->delayed_disc_tmo.data = (unsigned long)vport;
  2890. error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
  2891. if (error)
  2892. goto out_put_shost;
  2893. spin_lock_irq(&phba->hbalock);
  2894. list_add_tail(&vport->listentry, &phba->port_list);
  2895. spin_unlock_irq(&phba->hbalock);
  2896. return vport;
  2897. out_put_shost:
  2898. scsi_host_put(shost);
  2899. out:
  2900. return NULL;
  2901. }
  2902. /**
  2903. * destroy_port - destroy an FC port
  2904. * @vport: pointer to an lpfc virtual N_Port data structure.
  2905. *
  2906. * This routine destroys a FC port from the upper layer protocol. All the
  2907. * resources associated with the port are released.
  2908. **/
  2909. void
  2910. destroy_port(struct lpfc_vport *vport)
  2911. {
  2912. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2913. struct lpfc_hba *phba = vport->phba;
  2914. lpfc_debugfs_terminate(vport);
  2915. fc_remove_host(shost);
  2916. scsi_remove_host(shost);
  2917. spin_lock_irq(&phba->hbalock);
  2918. list_del_init(&vport->listentry);
  2919. spin_unlock_irq(&phba->hbalock);
  2920. lpfc_cleanup(vport);
  2921. return;
  2922. }
  2923. /**
  2924. * lpfc_get_instance - Get a unique integer ID
  2925. *
  2926. * This routine allocates a unique integer ID from lpfc_hba_index pool. It
  2927. * uses the kernel idr facility to perform the task.
  2928. *
  2929. * Return codes:
  2930. * instance - a unique integer ID allocated as the new instance.
  2931. * -1 - lpfc get instance failed.
  2932. **/
  2933. int
  2934. lpfc_get_instance(void)
  2935. {
  2936. int ret;
  2937. ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
  2938. return ret < 0 ? -1 : ret;
  2939. }
  2940. /**
  2941. * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
  2942. * @shost: pointer to SCSI host data structure.
  2943. * @time: elapsed time of the scan in jiffies.
  2944. *
  2945. * This routine is called by the SCSI layer with a SCSI host to determine
  2946. * whether the scan host is finished.
  2947. *
  2948. * Note: there is no scan_start function as adapter initialization will have
  2949. * asynchronously kicked off the link initialization.
  2950. *
  2951. * Return codes
  2952. * 0 - SCSI host scan is not over yet.
  2953. * 1 - SCSI host scan is over.
  2954. **/
  2955. int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
  2956. {
  2957. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2958. struct lpfc_hba *phba = vport->phba;
  2959. int stat = 0;
  2960. spin_lock_irq(shost->host_lock);
  2961. if (vport->load_flag & FC_UNLOADING) {
  2962. stat = 1;
  2963. goto finished;
  2964. }
  2965. if (time >= msecs_to_jiffies(30 * 1000)) {
  2966. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2967. "0461 Scanning longer than 30 "
  2968. "seconds. Continuing initialization\n");
  2969. stat = 1;
  2970. goto finished;
  2971. }
  2972. if (time >= msecs_to_jiffies(15 * 1000) &&
  2973. phba->link_state <= LPFC_LINK_DOWN) {
  2974. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2975. "0465 Link down longer than 15 "
  2976. "seconds. Continuing initialization\n");
  2977. stat = 1;
  2978. goto finished;
  2979. }
  2980. if (vport->port_state != LPFC_VPORT_READY)
  2981. goto finished;
  2982. if (vport->num_disc_nodes || vport->fc_prli_sent)
  2983. goto finished;
  2984. if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
  2985. goto finished;
  2986. if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
  2987. goto finished;
  2988. stat = 1;
  2989. finished:
  2990. spin_unlock_irq(shost->host_lock);
  2991. return stat;
  2992. }
  2993. /**
  2994. * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
  2995. * @shost: pointer to SCSI host data structure.
  2996. *
  2997. * This routine initializes a given SCSI host attributes on a FC port. The
  2998. * SCSI host can be either on top of a physical port or a virtual port.
  2999. **/
  3000. void lpfc_host_attrib_init(struct Scsi_Host *shost)
  3001. {
  3002. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3003. struct lpfc_hba *phba = vport->phba;
  3004. /*
  3005. * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
  3006. */
  3007. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  3008. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  3009. fc_host_supported_classes(shost) = FC_COS_CLASS3;
  3010. memset(fc_host_supported_fc4s(shost), 0,
  3011. sizeof(fc_host_supported_fc4s(shost)));
  3012. fc_host_supported_fc4s(shost)[2] = 1;
  3013. fc_host_supported_fc4s(shost)[7] = 1;
  3014. lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
  3015. sizeof fc_host_symbolic_name(shost));
  3016. fc_host_supported_speeds(shost) = 0;
  3017. if (phba->lmt & LMT_16Gb)
  3018. fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
  3019. if (phba->lmt & LMT_10Gb)
  3020. fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
  3021. if (phba->lmt & LMT_8Gb)
  3022. fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
  3023. if (phba->lmt & LMT_4Gb)
  3024. fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
  3025. if (phba->lmt & LMT_2Gb)
  3026. fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
  3027. if (phba->lmt & LMT_1Gb)
  3028. fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
  3029. fc_host_maxframe_size(shost) =
  3030. (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  3031. (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
  3032. fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
  3033. /* This value is also unchanging */
  3034. memset(fc_host_active_fc4s(shost), 0,
  3035. sizeof(fc_host_active_fc4s(shost)));
  3036. fc_host_active_fc4s(shost)[2] = 1;
  3037. fc_host_active_fc4s(shost)[7] = 1;
  3038. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  3039. spin_lock_irq(shost->host_lock);
  3040. vport->load_flag &= ~FC_LOADING;
  3041. spin_unlock_irq(shost->host_lock);
  3042. }
  3043. /**
  3044. * lpfc_stop_port_s3 - Stop SLI3 device port
  3045. * @phba: pointer to lpfc hba data structure.
  3046. *
  3047. * This routine is invoked to stop an SLI3 device port, it stops the device
  3048. * from generating interrupts and stops the device driver's timers for the
  3049. * device.
  3050. **/
  3051. static void
  3052. lpfc_stop_port_s3(struct lpfc_hba *phba)
  3053. {
  3054. /* Clear all interrupt enable conditions */
  3055. writel(0, phba->HCregaddr);
  3056. readl(phba->HCregaddr); /* flush */
  3057. /* Clear all pending interrupts */
  3058. writel(0xffffffff, phba->HAregaddr);
  3059. readl(phba->HAregaddr); /* flush */
  3060. /* Reset some HBA SLI setup states */
  3061. lpfc_stop_hba_timers(phba);
  3062. phba->pport->work_port_events = 0;
  3063. }
  3064. /**
  3065. * lpfc_stop_port_s4 - Stop SLI4 device port
  3066. * @phba: pointer to lpfc hba data structure.
  3067. *
  3068. * This routine is invoked to stop an SLI4 device port, it stops the device
  3069. * from generating interrupts and stops the device driver's timers for the
  3070. * device.
  3071. **/
  3072. static void
  3073. lpfc_stop_port_s4(struct lpfc_hba *phba)
  3074. {
  3075. /* Reset some HBA SLI4 setup states */
  3076. lpfc_stop_hba_timers(phba);
  3077. phba->pport->work_port_events = 0;
  3078. phba->sli4_hba.intr_enable = 0;
  3079. }
  3080. /**
  3081. * lpfc_stop_port - Wrapper function for stopping hba port
  3082. * @phba: Pointer to HBA context object.
  3083. *
  3084. * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
  3085. * the API jump table function pointer from the lpfc_hba struct.
  3086. **/
  3087. void
  3088. lpfc_stop_port(struct lpfc_hba *phba)
  3089. {
  3090. phba->lpfc_stop_port(phba);
  3091. }
  3092. /**
  3093. * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
  3094. * @phba: Pointer to hba for which this call is being executed.
  3095. *
  3096. * This routine starts the timer waiting for the FCF rediscovery to complete.
  3097. **/
  3098. void
  3099. lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
  3100. {
  3101. unsigned long fcf_redisc_wait_tmo =
  3102. (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
  3103. /* Start fcf rediscovery wait period timer */
  3104. mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
  3105. spin_lock_irq(&phba->hbalock);
  3106. /* Allow action to new fcf asynchronous event */
  3107. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
  3108. /* Mark the FCF rediscovery pending state */
  3109. phba->fcf.fcf_flag |= FCF_REDISC_PEND;
  3110. spin_unlock_irq(&phba->hbalock);
  3111. }
  3112. /**
  3113. * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
  3114. * @ptr: Map to lpfc_hba data structure pointer.
  3115. *
  3116. * This routine is invoked when waiting for FCF table rediscover has been
  3117. * timed out. If new FCF record(s) has (have) been discovered during the
  3118. * wait period, a new FCF event shall be added to the FCOE async event
  3119. * list, and then worker thread shall be waked up for processing from the
  3120. * worker thread context.
  3121. **/
  3122. void
  3123. lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
  3124. {
  3125. struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
  3126. /* Don't send FCF rediscovery event if timer cancelled */
  3127. spin_lock_irq(&phba->hbalock);
  3128. if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
  3129. spin_unlock_irq(&phba->hbalock);
  3130. return;
  3131. }
  3132. /* Clear FCF rediscovery timer pending flag */
  3133. phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
  3134. /* FCF rediscovery event to worker thread */
  3135. phba->fcf.fcf_flag |= FCF_REDISC_EVT;
  3136. spin_unlock_irq(&phba->hbalock);
  3137. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  3138. "2776 FCF rediscover quiescent timer expired\n");
  3139. /* wake up worker thread */
  3140. lpfc_worker_wake_up(phba);
  3141. }
  3142. /**
  3143. * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
  3144. * @phba: pointer to lpfc hba data structure.
  3145. * @acqe_link: pointer to the async link completion queue entry.
  3146. *
  3147. * This routine is to parse the SLI4 link-attention link fault code and
  3148. * translate it into the base driver's read link attention mailbox command
  3149. * status.
  3150. *
  3151. * Return: Link-attention status in terms of base driver's coding.
  3152. **/
  3153. static uint16_t
  3154. lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
  3155. struct lpfc_acqe_link *acqe_link)
  3156. {
  3157. uint16_t latt_fault;
  3158. switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
  3159. case LPFC_ASYNC_LINK_FAULT_NONE:
  3160. case LPFC_ASYNC_LINK_FAULT_LOCAL:
  3161. case LPFC_ASYNC_LINK_FAULT_REMOTE:
  3162. latt_fault = 0;
  3163. break;
  3164. default:
  3165. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3166. "0398 Invalid link fault code: x%x\n",
  3167. bf_get(lpfc_acqe_link_fault, acqe_link));
  3168. latt_fault = MBXERR_ERROR;
  3169. break;
  3170. }
  3171. return latt_fault;
  3172. }
  3173. /**
  3174. * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
  3175. * @phba: pointer to lpfc hba data structure.
  3176. * @acqe_link: pointer to the async link completion queue entry.
  3177. *
  3178. * This routine is to parse the SLI4 link attention type and translate it
  3179. * into the base driver's link attention type coding.
  3180. *
  3181. * Return: Link attention type in terms of base driver's coding.
  3182. **/
  3183. static uint8_t
  3184. lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
  3185. struct lpfc_acqe_link *acqe_link)
  3186. {
  3187. uint8_t att_type;
  3188. switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
  3189. case LPFC_ASYNC_LINK_STATUS_DOWN:
  3190. case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
  3191. att_type = LPFC_ATT_LINK_DOWN;
  3192. break;
  3193. case LPFC_ASYNC_LINK_STATUS_UP:
  3194. /* Ignore physical link up events - wait for logical link up */
  3195. att_type = LPFC_ATT_RESERVED;
  3196. break;
  3197. case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
  3198. att_type = LPFC_ATT_LINK_UP;
  3199. break;
  3200. default:
  3201. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3202. "0399 Invalid link attention type: x%x\n",
  3203. bf_get(lpfc_acqe_link_status, acqe_link));
  3204. att_type = LPFC_ATT_RESERVED;
  3205. break;
  3206. }
  3207. return att_type;
  3208. }
  3209. /**
  3210. * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
  3211. * @phba: pointer to lpfc hba data structure.
  3212. * @acqe_link: pointer to the async link completion queue entry.
  3213. *
  3214. * This routine is to parse the SLI4 link-attention link speed and translate
  3215. * it into the base driver's link-attention link speed coding.
  3216. *
  3217. * Return: Link-attention link speed in terms of base driver's coding.
  3218. **/
  3219. static uint8_t
  3220. lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
  3221. struct lpfc_acqe_link *acqe_link)
  3222. {
  3223. uint8_t link_speed;
  3224. switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
  3225. case LPFC_ASYNC_LINK_SPEED_ZERO:
  3226. case LPFC_ASYNC_LINK_SPEED_10MBPS:
  3227. case LPFC_ASYNC_LINK_SPEED_100MBPS:
  3228. link_speed = LPFC_LINK_SPEED_UNKNOWN;
  3229. break;
  3230. case LPFC_ASYNC_LINK_SPEED_1GBPS:
  3231. link_speed = LPFC_LINK_SPEED_1GHZ;
  3232. break;
  3233. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  3234. link_speed = LPFC_LINK_SPEED_10GHZ;
  3235. break;
  3236. default:
  3237. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3238. "0483 Invalid link-attention link speed: x%x\n",
  3239. bf_get(lpfc_acqe_link_speed, acqe_link));
  3240. link_speed = LPFC_LINK_SPEED_UNKNOWN;
  3241. break;
  3242. }
  3243. return link_speed;
  3244. }
  3245. /**
  3246. * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
  3247. * @phba: pointer to lpfc hba data structure.
  3248. *
  3249. * This routine is to get an SLI3 FC port's link speed in Mbps.
  3250. *
  3251. * Return: link speed in terms of Mbps.
  3252. **/
  3253. uint32_t
  3254. lpfc_sli_port_speed_get(struct lpfc_hba *phba)
  3255. {
  3256. uint32_t link_speed;
  3257. if (!lpfc_is_link_up(phba))
  3258. return 0;
  3259. switch (phba->fc_linkspeed) {
  3260. case LPFC_LINK_SPEED_1GHZ:
  3261. link_speed = 1000;
  3262. break;
  3263. case LPFC_LINK_SPEED_2GHZ:
  3264. link_speed = 2000;
  3265. break;
  3266. case LPFC_LINK_SPEED_4GHZ:
  3267. link_speed = 4000;
  3268. break;
  3269. case LPFC_LINK_SPEED_8GHZ:
  3270. link_speed = 8000;
  3271. break;
  3272. case LPFC_LINK_SPEED_10GHZ:
  3273. link_speed = 10000;
  3274. break;
  3275. case LPFC_LINK_SPEED_16GHZ:
  3276. link_speed = 16000;
  3277. break;
  3278. default:
  3279. link_speed = 0;
  3280. }
  3281. return link_speed;
  3282. }
  3283. /**
  3284. * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
  3285. * @phba: pointer to lpfc hba data structure.
  3286. * @evt_code: asynchronous event code.
  3287. * @speed_code: asynchronous event link speed code.
  3288. *
  3289. * This routine is to parse the giving SLI4 async event link speed code into
  3290. * value of Mbps for the link speed.
  3291. *
  3292. * Return: link speed in terms of Mbps.
  3293. **/
  3294. static uint32_t
  3295. lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
  3296. uint8_t speed_code)
  3297. {
  3298. uint32_t port_speed;
  3299. switch (evt_code) {
  3300. case LPFC_TRAILER_CODE_LINK:
  3301. switch (speed_code) {
  3302. case LPFC_EVT_CODE_LINK_NO_LINK:
  3303. port_speed = 0;
  3304. break;
  3305. case LPFC_EVT_CODE_LINK_10_MBIT:
  3306. port_speed = 10;
  3307. break;
  3308. case LPFC_EVT_CODE_LINK_100_MBIT:
  3309. port_speed = 100;
  3310. break;
  3311. case LPFC_EVT_CODE_LINK_1_GBIT:
  3312. port_speed = 1000;
  3313. break;
  3314. case LPFC_EVT_CODE_LINK_10_GBIT:
  3315. port_speed = 10000;
  3316. break;
  3317. default:
  3318. port_speed = 0;
  3319. }
  3320. break;
  3321. case LPFC_TRAILER_CODE_FC:
  3322. switch (speed_code) {
  3323. case LPFC_EVT_CODE_FC_NO_LINK:
  3324. port_speed = 0;
  3325. break;
  3326. case LPFC_EVT_CODE_FC_1_GBAUD:
  3327. port_speed = 1000;
  3328. break;
  3329. case LPFC_EVT_CODE_FC_2_GBAUD:
  3330. port_speed = 2000;
  3331. break;
  3332. case LPFC_EVT_CODE_FC_4_GBAUD:
  3333. port_speed = 4000;
  3334. break;
  3335. case LPFC_EVT_CODE_FC_8_GBAUD:
  3336. port_speed = 8000;
  3337. break;
  3338. case LPFC_EVT_CODE_FC_10_GBAUD:
  3339. port_speed = 10000;
  3340. break;
  3341. case LPFC_EVT_CODE_FC_16_GBAUD:
  3342. port_speed = 16000;
  3343. break;
  3344. default:
  3345. port_speed = 0;
  3346. }
  3347. break;
  3348. default:
  3349. port_speed = 0;
  3350. }
  3351. return port_speed;
  3352. }
  3353. /**
  3354. * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
  3355. * @phba: pointer to lpfc hba data structure.
  3356. * @acqe_link: pointer to the async link completion queue entry.
  3357. *
  3358. * This routine is to handle the SLI4 asynchronous FCoE link event.
  3359. **/
  3360. static void
  3361. lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
  3362. struct lpfc_acqe_link *acqe_link)
  3363. {
  3364. struct lpfc_dmabuf *mp;
  3365. LPFC_MBOXQ_t *pmb;
  3366. MAILBOX_t *mb;
  3367. struct lpfc_mbx_read_top *la;
  3368. uint8_t att_type;
  3369. int rc;
  3370. att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
  3371. if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
  3372. return;
  3373. phba->fcoe_eventtag = acqe_link->event_tag;
  3374. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3375. if (!pmb) {
  3376. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3377. "0395 The mboxq allocation failed\n");
  3378. return;
  3379. }
  3380. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3381. if (!mp) {
  3382. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3383. "0396 The lpfc_dmabuf allocation failed\n");
  3384. goto out_free_pmb;
  3385. }
  3386. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  3387. if (!mp->virt) {
  3388. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3389. "0397 The mbuf allocation failed\n");
  3390. goto out_free_dmabuf;
  3391. }
  3392. /* Cleanup any outstanding ELS commands */
  3393. lpfc_els_flush_all_cmd(phba);
  3394. /* Block ELS IOCBs until we have done process link event */
  3395. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  3396. /* Update link event statistics */
  3397. phba->sli.slistat.link_event++;
  3398. /* Create lpfc_handle_latt mailbox command from link ACQE */
  3399. lpfc_read_topology(phba, pmb, mp);
  3400. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  3401. pmb->vport = phba->pport;
  3402. /* Keep the link status for extra SLI4 state machine reference */
  3403. phba->sli4_hba.link_state.speed =
  3404. lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
  3405. bf_get(lpfc_acqe_link_speed, acqe_link));
  3406. phba->sli4_hba.link_state.duplex =
  3407. bf_get(lpfc_acqe_link_duplex, acqe_link);
  3408. phba->sli4_hba.link_state.status =
  3409. bf_get(lpfc_acqe_link_status, acqe_link);
  3410. phba->sli4_hba.link_state.type =
  3411. bf_get(lpfc_acqe_link_type, acqe_link);
  3412. phba->sli4_hba.link_state.number =
  3413. bf_get(lpfc_acqe_link_number, acqe_link);
  3414. phba->sli4_hba.link_state.fault =
  3415. bf_get(lpfc_acqe_link_fault, acqe_link);
  3416. phba->sli4_hba.link_state.logical_speed =
  3417. bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
  3418. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3419. "2900 Async FC/FCoE Link event - Speed:%dGBit "
  3420. "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
  3421. "Logical speed:%dMbps Fault:%d\n",
  3422. phba->sli4_hba.link_state.speed,
  3423. phba->sli4_hba.link_state.topology,
  3424. phba->sli4_hba.link_state.status,
  3425. phba->sli4_hba.link_state.type,
  3426. phba->sli4_hba.link_state.number,
  3427. phba->sli4_hba.link_state.logical_speed,
  3428. phba->sli4_hba.link_state.fault);
  3429. /*
  3430. * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
  3431. * topology info. Note: Optional for non FC-AL ports.
  3432. */
  3433. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  3434. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3435. if (rc == MBX_NOT_FINISHED)
  3436. goto out_free_dmabuf;
  3437. return;
  3438. }
  3439. /*
  3440. * For FCoE Mode: fill in all the topology information we need and call
  3441. * the READ_TOPOLOGY completion routine to continue without actually
  3442. * sending the READ_TOPOLOGY mailbox command to the port.
  3443. */
  3444. /* Parse and translate status field */
  3445. mb = &pmb->u.mb;
  3446. mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
  3447. /* Parse and translate link attention fields */
  3448. la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
  3449. la->eventTag = acqe_link->event_tag;
  3450. bf_set(lpfc_mbx_read_top_att_type, la, att_type);
  3451. bf_set(lpfc_mbx_read_top_link_spd, la,
  3452. lpfc_sli4_parse_latt_link_speed(phba, acqe_link));
  3453. /* Fake the the following irrelvant fields */
  3454. bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
  3455. bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
  3456. bf_set(lpfc_mbx_read_top_il, la, 0);
  3457. bf_set(lpfc_mbx_read_top_pb, la, 0);
  3458. bf_set(lpfc_mbx_read_top_fa, la, 0);
  3459. bf_set(lpfc_mbx_read_top_mm, la, 0);
  3460. /* Invoke the lpfc_handle_latt mailbox command callback function */
  3461. lpfc_mbx_cmpl_read_topology(phba, pmb);
  3462. return;
  3463. out_free_dmabuf:
  3464. kfree(mp);
  3465. out_free_pmb:
  3466. mempool_free(pmb, phba->mbox_mem_pool);
  3467. }
  3468. /**
  3469. * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
  3470. * @phba: pointer to lpfc hba data structure.
  3471. * @acqe_fc: pointer to the async fc completion queue entry.
  3472. *
  3473. * This routine is to handle the SLI4 asynchronous FC event. It will simply log
  3474. * that the event was received and then issue a read_topology mailbox command so
  3475. * that the rest of the driver will treat it the same as SLI3.
  3476. **/
  3477. static void
  3478. lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
  3479. {
  3480. struct lpfc_dmabuf *mp;
  3481. LPFC_MBOXQ_t *pmb;
  3482. int rc;
  3483. if (bf_get(lpfc_trailer_type, acqe_fc) !=
  3484. LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
  3485. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3486. "2895 Non FC link Event detected.(%d)\n",
  3487. bf_get(lpfc_trailer_type, acqe_fc));
  3488. return;
  3489. }
  3490. /* Keep the link status for extra SLI4 state machine reference */
  3491. phba->sli4_hba.link_state.speed =
  3492. lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
  3493. bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
  3494. phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
  3495. phba->sli4_hba.link_state.topology =
  3496. bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
  3497. phba->sli4_hba.link_state.status =
  3498. bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
  3499. phba->sli4_hba.link_state.type =
  3500. bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
  3501. phba->sli4_hba.link_state.number =
  3502. bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
  3503. phba->sli4_hba.link_state.fault =
  3504. bf_get(lpfc_acqe_link_fault, acqe_fc);
  3505. phba->sli4_hba.link_state.logical_speed =
  3506. bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
  3507. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3508. "2896 Async FC event - Speed:%dGBaud Topology:x%x "
  3509. "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
  3510. "%dMbps Fault:%d\n",
  3511. phba->sli4_hba.link_state.speed,
  3512. phba->sli4_hba.link_state.topology,
  3513. phba->sli4_hba.link_state.status,
  3514. phba->sli4_hba.link_state.type,
  3515. phba->sli4_hba.link_state.number,
  3516. phba->sli4_hba.link_state.logical_speed,
  3517. phba->sli4_hba.link_state.fault);
  3518. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3519. if (!pmb) {
  3520. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3521. "2897 The mboxq allocation failed\n");
  3522. return;
  3523. }
  3524. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3525. if (!mp) {
  3526. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3527. "2898 The lpfc_dmabuf allocation failed\n");
  3528. goto out_free_pmb;
  3529. }
  3530. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  3531. if (!mp->virt) {
  3532. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3533. "2899 The mbuf allocation failed\n");
  3534. goto out_free_dmabuf;
  3535. }
  3536. /* Cleanup any outstanding ELS commands */
  3537. lpfc_els_flush_all_cmd(phba);
  3538. /* Block ELS IOCBs until we have done process link event */
  3539. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  3540. /* Update link event statistics */
  3541. phba->sli.slistat.link_event++;
  3542. /* Create lpfc_handle_latt mailbox command from link ACQE */
  3543. lpfc_read_topology(phba, pmb, mp);
  3544. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  3545. pmb->vport = phba->pport;
  3546. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3547. if (rc == MBX_NOT_FINISHED)
  3548. goto out_free_dmabuf;
  3549. return;
  3550. out_free_dmabuf:
  3551. kfree(mp);
  3552. out_free_pmb:
  3553. mempool_free(pmb, phba->mbox_mem_pool);
  3554. }
  3555. /**
  3556. * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
  3557. * @phba: pointer to lpfc hba data structure.
  3558. * @acqe_fc: pointer to the async SLI completion queue entry.
  3559. *
  3560. * This routine is to handle the SLI4 asynchronous SLI events.
  3561. **/
  3562. static void
  3563. lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
  3564. {
  3565. char port_name;
  3566. char message[128];
  3567. uint8_t status;
  3568. struct lpfc_acqe_misconfigured_event *misconfigured;
  3569. /* special case misconfigured event as it contains data for all ports */
  3570. if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  3571. LPFC_SLI_INTF_IF_TYPE_2) ||
  3572. (bf_get(lpfc_trailer_type, acqe_sli) !=
  3573. LPFC_SLI_EVENT_TYPE_MISCONFIGURED)) {
  3574. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3575. "2901 Async SLI event - Event Data1:x%08x Event Data2:"
  3576. "x%08x SLI Event Type:%d\n",
  3577. acqe_sli->event_data1, acqe_sli->event_data2,
  3578. bf_get(lpfc_trailer_type, acqe_sli));
  3579. return;
  3580. }
  3581. port_name = phba->Port[0];
  3582. if (port_name == 0x00)
  3583. port_name = '?'; /* get port name is empty */
  3584. misconfigured = (struct lpfc_acqe_misconfigured_event *)
  3585. &acqe_sli->event_data1;
  3586. /* fetch the status for this port */
  3587. switch (phba->sli4_hba.lnk_info.lnk_no) {
  3588. case LPFC_LINK_NUMBER_0:
  3589. status = bf_get(lpfc_sli_misconfigured_port0,
  3590. &misconfigured->theEvent);
  3591. break;
  3592. case LPFC_LINK_NUMBER_1:
  3593. status = bf_get(lpfc_sli_misconfigured_port1,
  3594. &misconfigured->theEvent);
  3595. break;
  3596. case LPFC_LINK_NUMBER_2:
  3597. status = bf_get(lpfc_sli_misconfigured_port2,
  3598. &misconfigured->theEvent);
  3599. break;
  3600. case LPFC_LINK_NUMBER_3:
  3601. status = bf_get(lpfc_sli_misconfigured_port3,
  3602. &misconfigured->theEvent);
  3603. break;
  3604. default:
  3605. status = ~LPFC_SLI_EVENT_STATUS_VALID;
  3606. break;
  3607. }
  3608. switch (status) {
  3609. case LPFC_SLI_EVENT_STATUS_VALID:
  3610. return; /* no message if the sfp is okay */
  3611. case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
  3612. sprintf(message, "Optics faulted/incorrectly installed/not " \
  3613. "installed - Reseat optics, if issue not "
  3614. "resolved, replace.");
  3615. break;
  3616. case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
  3617. sprintf(message,
  3618. "Optics of two types installed - Remove one optic or " \
  3619. "install matching pair of optics.");
  3620. break;
  3621. case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
  3622. sprintf(message, "Incompatible optics - Replace with " \
  3623. "compatible optics for card to function.");
  3624. break;
  3625. default:
  3626. /* firmware is reporting a status we don't know about */
  3627. sprintf(message, "Unknown event status x%02x", status);
  3628. break;
  3629. }
  3630. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3631. "3176 Misconfigured Physical Port - "
  3632. "Port Name %c %s\n", port_name, message);
  3633. }
  3634. /**
  3635. * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
  3636. * @vport: pointer to vport data structure.
  3637. *
  3638. * This routine is to perform Clear Virtual Link (CVL) on a vport in
  3639. * response to a CVL event.
  3640. *
  3641. * Return the pointer to the ndlp with the vport if successful, otherwise
  3642. * return NULL.
  3643. **/
  3644. static struct lpfc_nodelist *
  3645. lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
  3646. {
  3647. struct lpfc_nodelist *ndlp;
  3648. struct Scsi_Host *shost;
  3649. struct lpfc_hba *phba;
  3650. if (!vport)
  3651. return NULL;
  3652. phba = vport->phba;
  3653. if (!phba)
  3654. return NULL;
  3655. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  3656. if (!ndlp) {
  3657. /* Cannot find existing Fabric ndlp, so allocate a new one */
  3658. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  3659. if (!ndlp)
  3660. return 0;
  3661. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  3662. /* Set the node type */
  3663. ndlp->nlp_type |= NLP_FABRIC;
  3664. /* Put ndlp onto node list */
  3665. lpfc_enqueue_node(vport, ndlp);
  3666. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  3667. /* re-setup ndlp without removing from node list */
  3668. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  3669. if (!ndlp)
  3670. return 0;
  3671. }
  3672. if ((phba->pport->port_state < LPFC_FLOGI) &&
  3673. (phba->pport->port_state != LPFC_VPORT_FAILED))
  3674. return NULL;
  3675. /* If virtual link is not yet instantiated ignore CVL */
  3676. if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
  3677. && (vport->port_state != LPFC_VPORT_FAILED))
  3678. return NULL;
  3679. shost = lpfc_shost_from_vport(vport);
  3680. if (!shost)
  3681. return NULL;
  3682. lpfc_linkdown_port(vport);
  3683. lpfc_cleanup_pending_mbox(vport);
  3684. spin_lock_irq(shost->host_lock);
  3685. vport->fc_flag |= FC_VPORT_CVL_RCVD;
  3686. spin_unlock_irq(shost->host_lock);
  3687. return ndlp;
  3688. }
  3689. /**
  3690. * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
  3691. * @vport: pointer to lpfc hba data structure.
  3692. *
  3693. * This routine is to perform Clear Virtual Link (CVL) on all vports in
  3694. * response to a FCF dead event.
  3695. **/
  3696. static void
  3697. lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
  3698. {
  3699. struct lpfc_vport **vports;
  3700. int i;
  3701. vports = lpfc_create_vport_work_array(phba);
  3702. if (vports)
  3703. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  3704. lpfc_sli4_perform_vport_cvl(vports[i]);
  3705. lpfc_destroy_vport_work_array(phba, vports);
  3706. }
  3707. /**
  3708. * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
  3709. * @phba: pointer to lpfc hba data structure.
  3710. * @acqe_link: pointer to the async fcoe completion queue entry.
  3711. *
  3712. * This routine is to handle the SLI4 asynchronous fcoe event.
  3713. **/
  3714. static void
  3715. lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
  3716. struct lpfc_acqe_fip *acqe_fip)
  3717. {
  3718. uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
  3719. int rc;
  3720. struct lpfc_vport *vport;
  3721. struct lpfc_nodelist *ndlp;
  3722. struct Scsi_Host *shost;
  3723. int active_vlink_present;
  3724. struct lpfc_vport **vports;
  3725. int i;
  3726. phba->fc_eventTag = acqe_fip->event_tag;
  3727. phba->fcoe_eventtag = acqe_fip->event_tag;
  3728. switch (event_type) {
  3729. case LPFC_FIP_EVENT_TYPE_NEW_FCF:
  3730. case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
  3731. if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
  3732. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  3733. LOG_DISCOVERY,
  3734. "2546 New FCF event, evt_tag:x%x, "
  3735. "index:x%x\n",
  3736. acqe_fip->event_tag,
  3737. acqe_fip->index);
  3738. else
  3739. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
  3740. LOG_DISCOVERY,
  3741. "2788 FCF param modified event, "
  3742. "evt_tag:x%x, index:x%x\n",
  3743. acqe_fip->event_tag,
  3744. acqe_fip->index);
  3745. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3746. /*
  3747. * During period of FCF discovery, read the FCF
  3748. * table record indexed by the event to update
  3749. * FCF roundrobin failover eligible FCF bmask.
  3750. */
  3751. lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
  3752. LOG_DISCOVERY,
  3753. "2779 Read FCF (x%x) for updating "
  3754. "roundrobin FCF failover bmask\n",
  3755. acqe_fip->index);
  3756. rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
  3757. }
  3758. /* If the FCF discovery is in progress, do nothing. */
  3759. spin_lock_irq(&phba->hbalock);
  3760. if (phba->hba_flag & FCF_TS_INPROG) {
  3761. spin_unlock_irq(&phba->hbalock);
  3762. break;
  3763. }
  3764. /* If fast FCF failover rescan event is pending, do nothing */
  3765. if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
  3766. spin_unlock_irq(&phba->hbalock);
  3767. break;
  3768. }
  3769. /* If the FCF has been in discovered state, do nothing. */
  3770. if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
  3771. spin_unlock_irq(&phba->hbalock);
  3772. break;
  3773. }
  3774. spin_unlock_irq(&phba->hbalock);
  3775. /* Otherwise, scan the entire FCF table and re-discover SAN */
  3776. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  3777. "2770 Start FCF table scan per async FCF "
  3778. "event, evt_tag:x%x, index:x%x\n",
  3779. acqe_fip->event_tag, acqe_fip->index);
  3780. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
  3781. LPFC_FCOE_FCF_GET_FIRST);
  3782. if (rc)
  3783. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3784. "2547 Issue FCF scan read FCF mailbox "
  3785. "command failed (x%x)\n", rc);
  3786. break;
  3787. case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
  3788. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3789. "2548 FCF Table full count 0x%x tag 0x%x\n",
  3790. bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
  3791. acqe_fip->event_tag);
  3792. break;
  3793. case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
  3794. phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
  3795. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3796. "2549 FCF (x%x) disconnected from network, "
  3797. "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
  3798. /*
  3799. * If we are in the middle of FCF failover process, clear
  3800. * the corresponding FCF bit in the roundrobin bitmap.
  3801. */
  3802. spin_lock_irq(&phba->hbalock);
  3803. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3804. spin_unlock_irq(&phba->hbalock);
  3805. /* Update FLOGI FCF failover eligible FCF bmask */
  3806. lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
  3807. break;
  3808. }
  3809. spin_unlock_irq(&phba->hbalock);
  3810. /* If the event is not for currently used fcf do nothing */
  3811. if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
  3812. break;
  3813. /*
  3814. * Otherwise, request the port to rediscover the entire FCF
  3815. * table for a fast recovery from case that the current FCF
  3816. * is no longer valid as we are not in the middle of FCF
  3817. * failover process already.
  3818. */
  3819. spin_lock_irq(&phba->hbalock);
  3820. /* Mark the fast failover process in progress */
  3821. phba->fcf.fcf_flag |= FCF_DEAD_DISC;
  3822. spin_unlock_irq(&phba->hbalock);
  3823. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  3824. "2771 Start FCF fast failover process due to "
  3825. "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
  3826. "\n", acqe_fip->event_tag, acqe_fip->index);
  3827. rc = lpfc_sli4_redisc_fcf_table(phba);
  3828. if (rc) {
  3829. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  3830. LOG_DISCOVERY,
  3831. "2772 Issue FCF rediscover mabilbox "
  3832. "command failed, fail through to FCF "
  3833. "dead event\n");
  3834. spin_lock_irq(&phba->hbalock);
  3835. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  3836. spin_unlock_irq(&phba->hbalock);
  3837. /*
  3838. * Last resort will fail over by treating this
  3839. * as a link down to FCF registration.
  3840. */
  3841. lpfc_sli4_fcf_dead_failthrough(phba);
  3842. } else {
  3843. /* Reset FCF roundrobin bmask for new discovery */
  3844. lpfc_sli4_clear_fcf_rr_bmask(phba);
  3845. /*
  3846. * Handling fast FCF failover to a DEAD FCF event is
  3847. * considered equalivant to receiving CVL to all vports.
  3848. */
  3849. lpfc_sli4_perform_all_vport_cvl(phba);
  3850. }
  3851. break;
  3852. case LPFC_FIP_EVENT_TYPE_CVL:
  3853. phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
  3854. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3855. "2718 Clear Virtual Link Received for VPI 0x%x"
  3856. " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
  3857. vport = lpfc_find_vport_by_vpid(phba,
  3858. acqe_fip->index);
  3859. ndlp = lpfc_sli4_perform_vport_cvl(vport);
  3860. if (!ndlp)
  3861. break;
  3862. active_vlink_present = 0;
  3863. vports = lpfc_create_vport_work_array(phba);
  3864. if (vports) {
  3865. for (i = 0; i <= phba->max_vports && vports[i] != NULL;
  3866. i++) {
  3867. if ((!(vports[i]->fc_flag &
  3868. FC_VPORT_CVL_RCVD)) &&
  3869. (vports[i]->port_state > LPFC_FDISC)) {
  3870. active_vlink_present = 1;
  3871. break;
  3872. }
  3873. }
  3874. lpfc_destroy_vport_work_array(phba, vports);
  3875. }
  3876. if (active_vlink_present) {
  3877. /*
  3878. * If there are other active VLinks present,
  3879. * re-instantiate the Vlink using FDISC.
  3880. */
  3881. mod_timer(&ndlp->nlp_delayfunc,
  3882. jiffies + msecs_to_jiffies(1000));
  3883. shost = lpfc_shost_from_vport(vport);
  3884. spin_lock_irq(shost->host_lock);
  3885. ndlp->nlp_flag |= NLP_DELAY_TMO;
  3886. spin_unlock_irq(shost->host_lock);
  3887. ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
  3888. vport->port_state = LPFC_FDISC;
  3889. } else {
  3890. /*
  3891. * Otherwise, we request port to rediscover
  3892. * the entire FCF table for a fast recovery
  3893. * from possible case that the current FCF
  3894. * is no longer valid if we are not already
  3895. * in the FCF failover process.
  3896. */
  3897. spin_lock_irq(&phba->hbalock);
  3898. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3899. spin_unlock_irq(&phba->hbalock);
  3900. break;
  3901. }
  3902. /* Mark the fast failover process in progress */
  3903. phba->fcf.fcf_flag |= FCF_ACVL_DISC;
  3904. spin_unlock_irq(&phba->hbalock);
  3905. lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
  3906. LOG_DISCOVERY,
  3907. "2773 Start FCF failover per CVL, "
  3908. "evt_tag:x%x\n", acqe_fip->event_tag);
  3909. rc = lpfc_sli4_redisc_fcf_table(phba);
  3910. if (rc) {
  3911. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  3912. LOG_DISCOVERY,
  3913. "2774 Issue FCF rediscover "
  3914. "mabilbox command failed, "
  3915. "through to CVL event\n");
  3916. spin_lock_irq(&phba->hbalock);
  3917. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  3918. spin_unlock_irq(&phba->hbalock);
  3919. /*
  3920. * Last resort will be re-try on the
  3921. * the current registered FCF entry.
  3922. */
  3923. lpfc_retry_pport_discovery(phba);
  3924. } else
  3925. /*
  3926. * Reset FCF roundrobin bmask for new
  3927. * discovery.
  3928. */
  3929. lpfc_sli4_clear_fcf_rr_bmask(phba);
  3930. }
  3931. break;
  3932. default:
  3933. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3934. "0288 Unknown FCoE event type 0x%x event tag "
  3935. "0x%x\n", event_type, acqe_fip->event_tag);
  3936. break;
  3937. }
  3938. }
  3939. /**
  3940. * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
  3941. * @phba: pointer to lpfc hba data structure.
  3942. * @acqe_link: pointer to the async dcbx completion queue entry.
  3943. *
  3944. * This routine is to handle the SLI4 asynchronous dcbx event.
  3945. **/
  3946. static void
  3947. lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
  3948. struct lpfc_acqe_dcbx *acqe_dcbx)
  3949. {
  3950. phba->fc_eventTag = acqe_dcbx->event_tag;
  3951. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3952. "0290 The SLI4 DCBX asynchronous event is not "
  3953. "handled yet\n");
  3954. }
  3955. /**
  3956. * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
  3957. * @phba: pointer to lpfc hba data structure.
  3958. * @acqe_link: pointer to the async grp5 completion queue entry.
  3959. *
  3960. * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
  3961. * is an asynchronous notified of a logical link speed change. The Port
  3962. * reports the logical link speed in units of 10Mbps.
  3963. **/
  3964. static void
  3965. lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
  3966. struct lpfc_acqe_grp5 *acqe_grp5)
  3967. {
  3968. uint16_t prev_ll_spd;
  3969. phba->fc_eventTag = acqe_grp5->event_tag;
  3970. phba->fcoe_eventtag = acqe_grp5->event_tag;
  3971. prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
  3972. phba->sli4_hba.link_state.logical_speed =
  3973. (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
  3974. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3975. "2789 GRP5 Async Event: Updating logical link speed "
  3976. "from %dMbps to %dMbps\n", prev_ll_spd,
  3977. phba->sli4_hba.link_state.logical_speed);
  3978. }
  3979. /**
  3980. * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
  3981. * @phba: pointer to lpfc hba data structure.
  3982. *
  3983. * This routine is invoked by the worker thread to process all the pending
  3984. * SLI4 asynchronous events.
  3985. **/
  3986. void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
  3987. {
  3988. struct lpfc_cq_event *cq_event;
  3989. /* First, declare the async event has been handled */
  3990. spin_lock_irq(&phba->hbalock);
  3991. phba->hba_flag &= ~ASYNC_EVENT;
  3992. spin_unlock_irq(&phba->hbalock);
  3993. /* Now, handle all the async events */
  3994. while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
  3995. /* Get the first event from the head of the event queue */
  3996. spin_lock_irq(&phba->hbalock);
  3997. list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
  3998. cq_event, struct lpfc_cq_event, list);
  3999. spin_unlock_irq(&phba->hbalock);
  4000. /* Process the asynchronous event */
  4001. switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
  4002. case LPFC_TRAILER_CODE_LINK:
  4003. lpfc_sli4_async_link_evt(phba,
  4004. &cq_event->cqe.acqe_link);
  4005. break;
  4006. case LPFC_TRAILER_CODE_FCOE:
  4007. lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
  4008. break;
  4009. case LPFC_TRAILER_CODE_DCBX:
  4010. lpfc_sli4_async_dcbx_evt(phba,
  4011. &cq_event->cqe.acqe_dcbx);
  4012. break;
  4013. case LPFC_TRAILER_CODE_GRP5:
  4014. lpfc_sli4_async_grp5_evt(phba,
  4015. &cq_event->cqe.acqe_grp5);
  4016. break;
  4017. case LPFC_TRAILER_CODE_FC:
  4018. lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
  4019. break;
  4020. case LPFC_TRAILER_CODE_SLI:
  4021. lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
  4022. break;
  4023. default:
  4024. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4025. "1804 Invalid asynchrous event code: "
  4026. "x%x\n", bf_get(lpfc_trailer_code,
  4027. &cq_event->cqe.mcqe_cmpl));
  4028. break;
  4029. }
  4030. /* Free the completion event processed to the free pool */
  4031. lpfc_sli4_cq_event_release(phba, cq_event);
  4032. }
  4033. }
  4034. /**
  4035. * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
  4036. * @phba: pointer to lpfc hba data structure.
  4037. *
  4038. * This routine is invoked by the worker thread to process FCF table
  4039. * rediscovery pending completion event.
  4040. **/
  4041. void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
  4042. {
  4043. int rc;
  4044. spin_lock_irq(&phba->hbalock);
  4045. /* Clear FCF rediscovery timeout event */
  4046. phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
  4047. /* Clear driver fast failover FCF record flag */
  4048. phba->fcf.failover_rec.flag = 0;
  4049. /* Set state for FCF fast failover */
  4050. phba->fcf.fcf_flag |= FCF_REDISC_FOV;
  4051. spin_unlock_irq(&phba->hbalock);
  4052. /* Scan FCF table from the first entry to re-discover SAN */
  4053. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  4054. "2777 Start post-quiescent FCF table scan\n");
  4055. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
  4056. if (rc)
  4057. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  4058. "2747 Issue FCF scan read FCF mailbox "
  4059. "command failed 0x%x\n", rc);
  4060. }
  4061. /**
  4062. * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
  4063. * @phba: pointer to lpfc hba data structure.
  4064. * @dev_grp: The HBA PCI-Device group number.
  4065. *
  4066. * This routine is invoked to set up the per HBA PCI-Device group function
  4067. * API jump table entries.
  4068. *
  4069. * Return: 0 if success, otherwise -ENODEV
  4070. **/
  4071. int
  4072. lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4073. {
  4074. int rc;
  4075. /* Set up lpfc PCI-device group */
  4076. phba->pci_dev_grp = dev_grp;
  4077. /* The LPFC_PCI_DEV_OC uses SLI4 */
  4078. if (dev_grp == LPFC_PCI_DEV_OC)
  4079. phba->sli_rev = LPFC_SLI_REV4;
  4080. /* Set up device INIT API function jump table */
  4081. rc = lpfc_init_api_table_setup(phba, dev_grp);
  4082. if (rc)
  4083. return -ENODEV;
  4084. /* Set up SCSI API function jump table */
  4085. rc = lpfc_scsi_api_table_setup(phba, dev_grp);
  4086. if (rc)
  4087. return -ENODEV;
  4088. /* Set up SLI API function jump table */
  4089. rc = lpfc_sli_api_table_setup(phba, dev_grp);
  4090. if (rc)
  4091. return -ENODEV;
  4092. /* Set up MBOX API function jump table */
  4093. rc = lpfc_mbox_api_table_setup(phba, dev_grp);
  4094. if (rc)
  4095. return -ENODEV;
  4096. return 0;
  4097. }
  4098. /**
  4099. * lpfc_log_intr_mode - Log the active interrupt mode
  4100. * @phba: pointer to lpfc hba data structure.
  4101. * @intr_mode: active interrupt mode adopted.
  4102. *
  4103. * This routine it invoked to log the currently used active interrupt mode
  4104. * to the device.
  4105. **/
  4106. static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
  4107. {
  4108. switch (intr_mode) {
  4109. case 0:
  4110. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4111. "0470 Enable INTx interrupt mode.\n");
  4112. break;
  4113. case 1:
  4114. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4115. "0481 Enabled MSI interrupt mode.\n");
  4116. break;
  4117. case 2:
  4118. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4119. "0480 Enabled MSI-X interrupt mode.\n");
  4120. break;
  4121. default:
  4122. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4123. "0482 Illegal interrupt mode.\n");
  4124. break;
  4125. }
  4126. return;
  4127. }
  4128. /**
  4129. * lpfc_enable_pci_dev - Enable a generic PCI device.
  4130. * @phba: pointer to lpfc hba data structure.
  4131. *
  4132. * This routine is invoked to enable the PCI device that is common to all
  4133. * PCI devices.
  4134. *
  4135. * Return codes
  4136. * 0 - successful
  4137. * other values - error
  4138. **/
  4139. static int
  4140. lpfc_enable_pci_dev(struct lpfc_hba *phba)
  4141. {
  4142. struct pci_dev *pdev;
  4143. int bars = 0;
  4144. /* Obtain PCI device reference */
  4145. if (!phba->pcidev)
  4146. goto out_error;
  4147. else
  4148. pdev = phba->pcidev;
  4149. /* Select PCI BARs */
  4150. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  4151. /* Enable PCI device */
  4152. if (pci_enable_device_mem(pdev))
  4153. goto out_error;
  4154. /* Request PCI resource for the device */
  4155. if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
  4156. goto out_disable_device;
  4157. /* Set up device as PCI master and save state for EEH */
  4158. pci_set_master(pdev);
  4159. pci_try_set_mwi(pdev);
  4160. pci_save_state(pdev);
  4161. /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
  4162. if (pci_find_capability(pdev, PCI_CAP_ID_EXP))
  4163. pdev->needs_freset = 1;
  4164. return 0;
  4165. out_disable_device:
  4166. pci_disable_device(pdev);
  4167. out_error:
  4168. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4169. "1401 Failed to enable pci device, bars:x%x\n", bars);
  4170. return -ENODEV;
  4171. }
  4172. /**
  4173. * lpfc_disable_pci_dev - Disable a generic PCI device.
  4174. * @phba: pointer to lpfc hba data structure.
  4175. *
  4176. * This routine is invoked to disable the PCI device that is common to all
  4177. * PCI devices.
  4178. **/
  4179. static void
  4180. lpfc_disable_pci_dev(struct lpfc_hba *phba)
  4181. {
  4182. struct pci_dev *pdev;
  4183. int bars;
  4184. /* Obtain PCI device reference */
  4185. if (!phba->pcidev)
  4186. return;
  4187. else
  4188. pdev = phba->pcidev;
  4189. /* Select PCI BARs */
  4190. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  4191. /* Release PCI resource and disable PCI device */
  4192. pci_release_selected_regions(pdev, bars);
  4193. pci_disable_device(pdev);
  4194. /* Null out PCI private reference to driver */
  4195. pci_set_drvdata(pdev, NULL);
  4196. return;
  4197. }
  4198. /**
  4199. * lpfc_reset_hba - Reset a hba
  4200. * @phba: pointer to lpfc hba data structure.
  4201. *
  4202. * This routine is invoked to reset a hba device. It brings the HBA
  4203. * offline, performs a board restart, and then brings the board back
  4204. * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
  4205. * on outstanding mailbox commands.
  4206. **/
  4207. void
  4208. lpfc_reset_hba(struct lpfc_hba *phba)
  4209. {
  4210. /* If resets are disabled then set error state and return. */
  4211. if (!phba->cfg_enable_hba_reset) {
  4212. phba->link_state = LPFC_HBA_ERROR;
  4213. return;
  4214. }
  4215. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  4216. lpfc_offline(phba);
  4217. lpfc_sli_brdrestart(phba);
  4218. lpfc_online(phba);
  4219. lpfc_unblock_mgmt_io(phba);
  4220. }
  4221. /**
  4222. * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
  4223. * @phba: pointer to lpfc hba data structure.
  4224. *
  4225. * This function enables the PCI SR-IOV virtual functions to a physical
  4226. * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
  4227. * enable the number of virtual functions to the physical function. As
  4228. * not all devices support SR-IOV, the return code from the pci_enable_sriov()
  4229. * API call does not considered as an error condition for most of the device.
  4230. **/
  4231. uint16_t
  4232. lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
  4233. {
  4234. struct pci_dev *pdev = phba->pcidev;
  4235. uint16_t nr_virtfn;
  4236. int pos;
  4237. pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
  4238. if (pos == 0)
  4239. return 0;
  4240. pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
  4241. return nr_virtfn;
  4242. }
  4243. /**
  4244. * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
  4245. * @phba: pointer to lpfc hba data structure.
  4246. * @nr_vfn: number of virtual functions to be enabled.
  4247. *
  4248. * This function enables the PCI SR-IOV virtual functions to a physical
  4249. * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
  4250. * enable the number of virtual functions to the physical function. As
  4251. * not all devices support SR-IOV, the return code from the pci_enable_sriov()
  4252. * API call does not considered as an error condition for most of the device.
  4253. **/
  4254. int
  4255. lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
  4256. {
  4257. struct pci_dev *pdev = phba->pcidev;
  4258. uint16_t max_nr_vfn;
  4259. int rc;
  4260. max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
  4261. if (nr_vfn > max_nr_vfn) {
  4262. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4263. "3057 Requested vfs (%d) greater than "
  4264. "supported vfs (%d)", nr_vfn, max_nr_vfn);
  4265. return -EINVAL;
  4266. }
  4267. rc = pci_enable_sriov(pdev, nr_vfn);
  4268. if (rc) {
  4269. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4270. "2806 Failed to enable sriov on this device "
  4271. "with vfn number nr_vf:%d, rc:%d\n",
  4272. nr_vfn, rc);
  4273. } else
  4274. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4275. "2807 Successful enable sriov on this device "
  4276. "with vfn number nr_vf:%d\n", nr_vfn);
  4277. return rc;
  4278. }
  4279. /**
  4280. * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
  4281. * @phba: pointer to lpfc hba data structure.
  4282. *
  4283. * This routine is invoked to set up the driver internal resources specific to
  4284. * support the SLI-3 HBA device it attached to.
  4285. *
  4286. * Return codes
  4287. * 0 - successful
  4288. * other values - error
  4289. **/
  4290. static int
  4291. lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
  4292. {
  4293. struct lpfc_sli *psli;
  4294. int rc;
  4295. /*
  4296. * Initialize timers used by driver
  4297. */
  4298. /* Heartbeat timer */
  4299. init_timer(&phba->hb_tmofunc);
  4300. phba->hb_tmofunc.function = lpfc_hb_timeout;
  4301. phba->hb_tmofunc.data = (unsigned long)phba;
  4302. psli = &phba->sli;
  4303. /* MBOX heartbeat timer */
  4304. init_timer(&psli->mbox_tmo);
  4305. psli->mbox_tmo.function = lpfc_mbox_timeout;
  4306. psli->mbox_tmo.data = (unsigned long) phba;
  4307. /* FCP polling mode timer */
  4308. init_timer(&phba->fcp_poll_timer);
  4309. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  4310. phba->fcp_poll_timer.data = (unsigned long) phba;
  4311. /* Fabric block timer */
  4312. init_timer(&phba->fabric_block_timer);
  4313. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  4314. phba->fabric_block_timer.data = (unsigned long) phba;
  4315. /* EA polling mode timer */
  4316. init_timer(&phba->eratt_poll);
  4317. phba->eratt_poll.function = lpfc_poll_eratt;
  4318. phba->eratt_poll.data = (unsigned long) phba;
  4319. /* Host attention work mask setup */
  4320. phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
  4321. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  4322. /* Get all the module params for configuring this host */
  4323. lpfc_get_cfgparam(phba);
  4324. if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
  4325. phba->menlo_flag |= HBA_MENLO_SUPPORT;
  4326. /* check for menlo minimum sg count */
  4327. if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
  4328. phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
  4329. }
  4330. if (!phba->sli.ring)
  4331. phba->sli.ring = (struct lpfc_sli_ring *)
  4332. kzalloc(LPFC_SLI3_MAX_RING *
  4333. sizeof(struct lpfc_sli_ring), GFP_KERNEL);
  4334. if (!phba->sli.ring)
  4335. return -ENOMEM;
  4336. /*
  4337. * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
  4338. * used to create the sg_dma_buf_pool must be dynamically calculated.
  4339. */
  4340. /* Initialize the host templates the configured values. */
  4341. lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  4342. lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  4343. /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
  4344. if (phba->cfg_enable_bg) {
  4345. /*
  4346. * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
  4347. * the FCP rsp, and a BDE for each. Sice we have no control
  4348. * over how many protection data segments the SCSI Layer
  4349. * will hand us (ie: there could be one for every block
  4350. * in the IO), we just allocate enough BDEs to accomidate
  4351. * our max amount and we need to limit lpfc_sg_seg_cnt to
  4352. * minimize the risk of running out.
  4353. */
  4354. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  4355. sizeof(struct fcp_rsp) +
  4356. (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
  4357. if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
  4358. phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
  4359. /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
  4360. phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
  4361. } else {
  4362. /*
  4363. * The scsi_buf for a regular I/O will hold the FCP cmnd,
  4364. * the FCP rsp, a BDE for each, and a BDE for up to
  4365. * cfg_sg_seg_cnt data segments.
  4366. */
  4367. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  4368. sizeof(struct fcp_rsp) +
  4369. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
  4370. /* Total BDEs in BPL for scsi_sg_list */
  4371. phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
  4372. }
  4373. lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
  4374. "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
  4375. phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
  4376. phba->cfg_total_seg_cnt);
  4377. phba->max_vpi = LPFC_MAX_VPI;
  4378. /* This will be set to correct value after config_port mbox */
  4379. phba->max_vports = 0;
  4380. /*
  4381. * Initialize the SLI Layer to run with lpfc HBAs.
  4382. */
  4383. lpfc_sli_setup(phba);
  4384. lpfc_sli_queue_setup(phba);
  4385. /* Allocate device driver memory */
  4386. if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
  4387. return -ENOMEM;
  4388. /*
  4389. * Enable sr-iov virtual functions if supported and configured
  4390. * through the module parameter.
  4391. */
  4392. if (phba->cfg_sriov_nr_virtfn > 0) {
  4393. rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
  4394. phba->cfg_sriov_nr_virtfn);
  4395. if (rc) {
  4396. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4397. "2808 Requested number of SR-IOV "
  4398. "virtual functions (%d) is not "
  4399. "supported\n",
  4400. phba->cfg_sriov_nr_virtfn);
  4401. phba->cfg_sriov_nr_virtfn = 0;
  4402. }
  4403. }
  4404. return 0;
  4405. }
  4406. /**
  4407. * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
  4408. * @phba: pointer to lpfc hba data structure.
  4409. *
  4410. * This routine is invoked to unset the driver internal resources set up
  4411. * specific for supporting the SLI-3 HBA device it attached to.
  4412. **/
  4413. static void
  4414. lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
  4415. {
  4416. /* Free device driver memory allocated */
  4417. lpfc_mem_free_all(phba);
  4418. return;
  4419. }
  4420. /**
  4421. * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
  4422. * @phba: pointer to lpfc hba data structure.
  4423. *
  4424. * This routine is invoked to set up the driver internal resources specific to
  4425. * support the SLI-4 HBA device it attached to.
  4426. *
  4427. * Return codes
  4428. * 0 - successful
  4429. * other values - error
  4430. **/
  4431. static int
  4432. lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
  4433. {
  4434. struct lpfc_vector_map_info *cpup;
  4435. struct lpfc_sli *psli;
  4436. LPFC_MBOXQ_t *mboxq;
  4437. int rc, i, hbq_count, max_buf_size;
  4438. uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
  4439. struct lpfc_mqe *mqe;
  4440. int longs;
  4441. /* Before proceed, wait for POST done and device ready */
  4442. rc = lpfc_sli4_post_status_check(phba);
  4443. if (rc)
  4444. return -ENODEV;
  4445. /*
  4446. * Initialize timers used by driver
  4447. */
  4448. /* Heartbeat timer */
  4449. init_timer(&phba->hb_tmofunc);
  4450. phba->hb_tmofunc.function = lpfc_hb_timeout;
  4451. phba->hb_tmofunc.data = (unsigned long)phba;
  4452. init_timer(&phba->rrq_tmr);
  4453. phba->rrq_tmr.function = lpfc_rrq_timeout;
  4454. phba->rrq_tmr.data = (unsigned long)phba;
  4455. psli = &phba->sli;
  4456. /* MBOX heartbeat timer */
  4457. init_timer(&psli->mbox_tmo);
  4458. psli->mbox_tmo.function = lpfc_mbox_timeout;
  4459. psli->mbox_tmo.data = (unsigned long) phba;
  4460. /* Fabric block timer */
  4461. init_timer(&phba->fabric_block_timer);
  4462. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  4463. phba->fabric_block_timer.data = (unsigned long) phba;
  4464. /* EA polling mode timer */
  4465. init_timer(&phba->eratt_poll);
  4466. phba->eratt_poll.function = lpfc_poll_eratt;
  4467. phba->eratt_poll.data = (unsigned long) phba;
  4468. /* FCF rediscover timer */
  4469. init_timer(&phba->fcf.redisc_wait);
  4470. phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
  4471. phba->fcf.redisc_wait.data = (unsigned long)phba;
  4472. /*
  4473. * Control structure for handling external multi-buffer mailbox
  4474. * command pass-through.
  4475. */
  4476. memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
  4477. sizeof(struct lpfc_mbox_ext_buf_ctx));
  4478. INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
  4479. /*
  4480. * We need to do a READ_CONFIG mailbox command here before
  4481. * calling lpfc_get_cfgparam. For VFs this will report the
  4482. * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
  4483. * All of the resources allocated
  4484. * for this Port are tied to these values.
  4485. */
  4486. /* Get all the module params for configuring this host */
  4487. lpfc_get_cfgparam(phba);
  4488. phba->max_vpi = LPFC_MAX_VPI;
  4489. /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */
  4490. phba->cfg_fcp_io_channel = phba->cfg_fcp_eq_count;
  4491. /* This will be set to correct value after the read_config mbox */
  4492. phba->max_vports = 0;
  4493. /* Program the default value of vlan_id and fc_map */
  4494. phba->valid_vlan = 0;
  4495. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4496. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4497. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4498. /*
  4499. * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
  4500. * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
  4501. */
  4502. if (!phba->sli.ring)
  4503. phba->sli.ring = kzalloc(
  4504. (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) *
  4505. sizeof(struct lpfc_sli_ring), GFP_KERNEL);
  4506. if (!phba->sli.ring)
  4507. return -ENOMEM;
  4508. /*
  4509. * It doesn't matter what family our adapter is in, we are
  4510. * limited to 2 Pages, 512 SGEs, for our SGL.
  4511. * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
  4512. */
  4513. max_buf_size = (2 * SLI4_PAGE_SIZE);
  4514. if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
  4515. phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
  4516. /*
  4517. * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
  4518. * used to create the sg_dma_buf_pool must be dynamically calculated.
  4519. */
  4520. if (phba->cfg_enable_bg) {
  4521. /*
  4522. * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
  4523. * the FCP rsp, and a SGE for each. Sice we have no control
  4524. * over how many protection data segments the SCSI Layer
  4525. * will hand us (ie: there could be one for every block
  4526. * in the IO), we just allocate enough SGEs to accomidate
  4527. * our max amount and we need to limit lpfc_sg_seg_cnt to
  4528. * minimize the risk of running out.
  4529. */
  4530. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  4531. sizeof(struct fcp_rsp) + max_buf_size;
  4532. /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
  4533. phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
  4534. if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
  4535. phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
  4536. } else {
  4537. /*
  4538. * The scsi_buf for a regular I/O will hold the FCP cmnd,
  4539. * the FCP rsp, a SGE for each, and a SGE for up to
  4540. * cfg_sg_seg_cnt data segments.
  4541. */
  4542. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  4543. sizeof(struct fcp_rsp) +
  4544. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
  4545. /* Total SGEs for scsi_sg_list */
  4546. phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
  4547. /*
  4548. * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need
  4549. * to post 1 page for the SGL.
  4550. */
  4551. }
  4552. /* Initialize the host templates with the updated values. */
  4553. lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  4554. lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  4555. if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
  4556. phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
  4557. else
  4558. phba->cfg_sg_dma_buf_size =
  4559. SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
  4560. lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
  4561. "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
  4562. phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
  4563. phba->cfg_total_seg_cnt);
  4564. /* Initialize buffer queue management fields */
  4565. hbq_count = lpfc_sli_hbq_count();
  4566. for (i = 0; i < hbq_count; ++i)
  4567. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  4568. INIT_LIST_HEAD(&phba->rb_pend_list);
  4569. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
  4570. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
  4571. /*
  4572. * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
  4573. */
  4574. /* Initialize the Abort scsi buffer list used by driver */
  4575. spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
  4576. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  4577. /* This abort list used by worker thread */
  4578. spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
  4579. /*
  4580. * Initialize driver internal slow-path work queues
  4581. */
  4582. /* Driver internel slow-path CQ Event pool */
  4583. INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
  4584. /* Response IOCB work queue list */
  4585. INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
  4586. /* Asynchronous event CQ Event work queue list */
  4587. INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
  4588. /* Fast-path XRI aborted CQ Event work queue list */
  4589. INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  4590. /* Slow-path XRI aborted CQ Event work queue list */
  4591. INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
  4592. /* Receive queue CQ Event work queue list */
  4593. INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
  4594. /* Initialize extent block lists. */
  4595. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
  4596. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
  4597. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
  4598. INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
  4599. /* Initialize the driver internal SLI layer lists. */
  4600. lpfc_sli_setup(phba);
  4601. lpfc_sli_queue_setup(phba);
  4602. /* Allocate device driver memory */
  4603. rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
  4604. if (rc)
  4605. return -ENOMEM;
  4606. /* IF Type 2 ports get initialized now. */
  4607. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  4608. LPFC_SLI_INTF_IF_TYPE_2) {
  4609. rc = lpfc_pci_function_reset(phba);
  4610. if (unlikely(rc))
  4611. return -ENODEV;
  4612. }
  4613. /* Create the bootstrap mailbox command */
  4614. rc = lpfc_create_bootstrap_mbox(phba);
  4615. if (unlikely(rc))
  4616. goto out_free_mem;
  4617. /* Set up the host's endian order with the device. */
  4618. rc = lpfc_setup_endian_order(phba);
  4619. if (unlikely(rc))
  4620. goto out_free_bsmbx;
  4621. /* Set up the hba's configuration parameters. */
  4622. rc = lpfc_sli4_read_config(phba);
  4623. if (unlikely(rc))
  4624. goto out_free_bsmbx;
  4625. /* IF Type 0 ports get initialized now. */
  4626. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  4627. LPFC_SLI_INTF_IF_TYPE_0) {
  4628. rc = lpfc_pci_function_reset(phba);
  4629. if (unlikely(rc))
  4630. goto out_free_bsmbx;
  4631. }
  4632. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  4633. GFP_KERNEL);
  4634. if (!mboxq) {
  4635. rc = -ENOMEM;
  4636. goto out_free_bsmbx;
  4637. }
  4638. /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
  4639. lpfc_supported_pages(mboxq);
  4640. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4641. if (!rc) {
  4642. mqe = &mboxq->u.mqe;
  4643. memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
  4644. LPFC_MAX_SUPPORTED_PAGES);
  4645. for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
  4646. switch (pn_page[i]) {
  4647. case LPFC_SLI4_PARAMETERS:
  4648. phba->sli4_hba.pc_sli4_params.supported = 1;
  4649. break;
  4650. default:
  4651. break;
  4652. }
  4653. }
  4654. /* Read the port's SLI4 Parameters capabilities if supported. */
  4655. if (phba->sli4_hba.pc_sli4_params.supported)
  4656. rc = lpfc_pc_sli4_params_get(phba, mboxq);
  4657. if (rc) {
  4658. mempool_free(mboxq, phba->mbox_mem_pool);
  4659. rc = -EIO;
  4660. goto out_free_bsmbx;
  4661. }
  4662. }
  4663. /*
  4664. * Get sli4 parameters that override parameters from Port capabilities.
  4665. * If this call fails, it isn't critical unless the SLI4 parameters come
  4666. * back in conflict.
  4667. */
  4668. rc = lpfc_get_sli4_parameters(phba, mboxq);
  4669. if (rc) {
  4670. if (phba->sli4_hba.extents_in_use &&
  4671. phba->sli4_hba.rpi_hdrs_in_use) {
  4672. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4673. "2999 Unsupported SLI4 Parameters "
  4674. "Extents and RPI headers enabled.\n");
  4675. goto out_free_bsmbx;
  4676. }
  4677. }
  4678. mempool_free(mboxq, phba->mbox_mem_pool);
  4679. /* Verify all the SLI4 queues */
  4680. rc = lpfc_sli4_queue_verify(phba);
  4681. if (rc)
  4682. goto out_free_bsmbx;
  4683. /* Create driver internal CQE event pool */
  4684. rc = lpfc_sli4_cq_event_pool_create(phba);
  4685. if (rc)
  4686. goto out_free_bsmbx;
  4687. /* Initialize sgl lists per host */
  4688. lpfc_init_sgl_list(phba);
  4689. /* Allocate and initialize active sgl array */
  4690. rc = lpfc_init_active_sgl_array(phba);
  4691. if (rc) {
  4692. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4693. "1430 Failed to initialize sgl list.\n");
  4694. goto out_destroy_cq_event_pool;
  4695. }
  4696. rc = lpfc_sli4_init_rpi_hdrs(phba);
  4697. if (rc) {
  4698. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4699. "1432 Failed to initialize rpi headers.\n");
  4700. goto out_free_active_sgl;
  4701. }
  4702. /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
  4703. longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
  4704. phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
  4705. GFP_KERNEL);
  4706. if (!phba->fcf.fcf_rr_bmask) {
  4707. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4708. "2759 Failed allocate memory for FCF round "
  4709. "robin failover bmask\n");
  4710. rc = -ENOMEM;
  4711. goto out_remove_rpi_hdrs;
  4712. }
  4713. phba->sli4_hba.fcp_eq_hdl =
  4714. kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
  4715. phba->cfg_fcp_io_channel), GFP_KERNEL);
  4716. if (!phba->sli4_hba.fcp_eq_hdl) {
  4717. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4718. "2572 Failed allocate memory for "
  4719. "fast-path per-EQ handle array\n");
  4720. rc = -ENOMEM;
  4721. goto out_free_fcf_rr_bmask;
  4722. }
  4723. phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
  4724. phba->cfg_fcp_io_channel), GFP_KERNEL);
  4725. if (!phba->sli4_hba.msix_entries) {
  4726. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4727. "2573 Failed allocate memory for msi-x "
  4728. "interrupt vector entries\n");
  4729. rc = -ENOMEM;
  4730. goto out_free_fcp_eq_hdl;
  4731. }
  4732. phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) *
  4733. phba->sli4_hba.num_present_cpu),
  4734. GFP_KERNEL);
  4735. if (!phba->sli4_hba.cpu_map) {
  4736. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4737. "3327 Failed allocate memory for msi-x "
  4738. "interrupt vector mapping\n");
  4739. rc = -ENOMEM;
  4740. goto out_free_msix;
  4741. }
  4742. if (lpfc_used_cpu == NULL) {
  4743. lpfc_used_cpu = kzalloc((sizeof(uint16_t) * lpfc_present_cpu),
  4744. GFP_KERNEL);
  4745. if (!lpfc_used_cpu) {
  4746. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4747. "3335 Failed allocate memory for msi-x "
  4748. "interrupt vector mapping\n");
  4749. kfree(phba->sli4_hba.cpu_map);
  4750. rc = -ENOMEM;
  4751. goto out_free_msix;
  4752. }
  4753. for (i = 0; i < lpfc_present_cpu; i++)
  4754. lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
  4755. }
  4756. /* Initialize io channels for round robin */
  4757. cpup = phba->sli4_hba.cpu_map;
  4758. rc = 0;
  4759. for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
  4760. cpup->channel_id = rc;
  4761. rc++;
  4762. if (rc >= phba->cfg_fcp_io_channel)
  4763. rc = 0;
  4764. }
  4765. /*
  4766. * Enable sr-iov virtual functions if supported and configured
  4767. * through the module parameter.
  4768. */
  4769. if (phba->cfg_sriov_nr_virtfn > 0) {
  4770. rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
  4771. phba->cfg_sriov_nr_virtfn);
  4772. if (rc) {
  4773. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4774. "3020 Requested number of SR-IOV "
  4775. "virtual functions (%d) is not "
  4776. "supported\n",
  4777. phba->cfg_sriov_nr_virtfn);
  4778. phba->cfg_sriov_nr_virtfn = 0;
  4779. }
  4780. }
  4781. return 0;
  4782. out_free_msix:
  4783. kfree(phba->sli4_hba.msix_entries);
  4784. out_free_fcp_eq_hdl:
  4785. kfree(phba->sli4_hba.fcp_eq_hdl);
  4786. out_free_fcf_rr_bmask:
  4787. kfree(phba->fcf.fcf_rr_bmask);
  4788. out_remove_rpi_hdrs:
  4789. lpfc_sli4_remove_rpi_hdrs(phba);
  4790. out_free_active_sgl:
  4791. lpfc_free_active_sgl(phba);
  4792. out_destroy_cq_event_pool:
  4793. lpfc_sli4_cq_event_pool_destroy(phba);
  4794. out_free_bsmbx:
  4795. lpfc_destroy_bootstrap_mbox(phba);
  4796. out_free_mem:
  4797. lpfc_mem_free(phba);
  4798. return rc;
  4799. }
  4800. /**
  4801. * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
  4802. * @phba: pointer to lpfc hba data structure.
  4803. *
  4804. * This routine is invoked to unset the driver internal resources set up
  4805. * specific for supporting the SLI-4 HBA device it attached to.
  4806. **/
  4807. static void
  4808. lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
  4809. {
  4810. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  4811. /* Free memory allocated for msi-x interrupt vector to CPU mapping */
  4812. kfree(phba->sli4_hba.cpu_map);
  4813. phba->sli4_hba.num_present_cpu = 0;
  4814. phba->sli4_hba.num_online_cpu = 0;
  4815. /* Free memory allocated for msi-x interrupt vector entries */
  4816. kfree(phba->sli4_hba.msix_entries);
  4817. /* Free memory allocated for fast-path work queue handles */
  4818. kfree(phba->sli4_hba.fcp_eq_hdl);
  4819. /* Free the allocated rpi headers. */
  4820. lpfc_sli4_remove_rpi_hdrs(phba);
  4821. lpfc_sli4_remove_rpis(phba);
  4822. /* Free eligible FCF index bmask */
  4823. kfree(phba->fcf.fcf_rr_bmask);
  4824. /* Free the ELS sgl list */
  4825. lpfc_free_active_sgl(phba);
  4826. lpfc_free_els_sgl_list(phba);
  4827. /* Free the completion queue EQ event pool */
  4828. lpfc_sli4_cq_event_release_all(phba);
  4829. lpfc_sli4_cq_event_pool_destroy(phba);
  4830. /* Release resource identifiers. */
  4831. lpfc_sli4_dealloc_resource_identifiers(phba);
  4832. /* Free the bsmbx region. */
  4833. lpfc_destroy_bootstrap_mbox(phba);
  4834. /* Free the SLI Layer memory with SLI4 HBAs */
  4835. lpfc_mem_free_all(phba);
  4836. /* Free the current connect table */
  4837. list_for_each_entry_safe(conn_entry, next_conn_entry,
  4838. &phba->fcf_conn_rec_list, list) {
  4839. list_del_init(&conn_entry->list);
  4840. kfree(conn_entry);
  4841. }
  4842. return;
  4843. }
  4844. /**
  4845. * lpfc_init_api_table_setup - Set up init api function jump table
  4846. * @phba: The hba struct for which this call is being executed.
  4847. * @dev_grp: The HBA PCI-Device group number.
  4848. *
  4849. * This routine sets up the device INIT interface API function jump table
  4850. * in @phba struct.
  4851. *
  4852. * Returns: 0 - success, -ENODEV - failure.
  4853. **/
  4854. int
  4855. lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4856. {
  4857. phba->lpfc_hba_init_link = lpfc_hba_init_link;
  4858. phba->lpfc_hba_down_link = lpfc_hba_down_link;
  4859. phba->lpfc_selective_reset = lpfc_selective_reset;
  4860. switch (dev_grp) {
  4861. case LPFC_PCI_DEV_LP:
  4862. phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
  4863. phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
  4864. phba->lpfc_stop_port = lpfc_stop_port_s3;
  4865. break;
  4866. case LPFC_PCI_DEV_OC:
  4867. phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
  4868. phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
  4869. phba->lpfc_stop_port = lpfc_stop_port_s4;
  4870. break;
  4871. default:
  4872. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4873. "1431 Invalid HBA PCI-device group: 0x%x\n",
  4874. dev_grp);
  4875. return -ENODEV;
  4876. break;
  4877. }
  4878. return 0;
  4879. }
  4880. /**
  4881. * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
  4882. * @phba: pointer to lpfc hba data structure.
  4883. *
  4884. * This routine is invoked to set up the driver internal resources before the
  4885. * device specific resource setup to support the HBA device it attached to.
  4886. *
  4887. * Return codes
  4888. * 0 - successful
  4889. * other values - error
  4890. **/
  4891. static int
  4892. lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
  4893. {
  4894. /*
  4895. * Driver resources common to all SLI revisions
  4896. */
  4897. atomic_set(&phba->fast_event_count, 0);
  4898. spin_lock_init(&phba->hbalock);
  4899. /* Initialize ndlp management spinlock */
  4900. spin_lock_init(&phba->ndlp_lock);
  4901. INIT_LIST_HEAD(&phba->port_list);
  4902. INIT_LIST_HEAD(&phba->work_list);
  4903. init_waitqueue_head(&phba->wait_4_mlo_m_q);
  4904. /* Initialize the wait queue head for the kernel thread */
  4905. init_waitqueue_head(&phba->work_waitq);
  4906. /* Initialize the scsi buffer list used by driver for scsi IO */
  4907. spin_lock_init(&phba->scsi_buf_list_get_lock);
  4908. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
  4909. spin_lock_init(&phba->scsi_buf_list_put_lock);
  4910. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
  4911. /* Initialize the fabric iocb list */
  4912. INIT_LIST_HEAD(&phba->fabric_iocb_list);
  4913. /* Initialize list to save ELS buffers */
  4914. INIT_LIST_HEAD(&phba->elsbuf);
  4915. /* Initialize FCF connection rec list */
  4916. INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
  4917. return 0;
  4918. }
  4919. /**
  4920. * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
  4921. * @phba: pointer to lpfc hba data structure.
  4922. *
  4923. * This routine is invoked to set up the driver internal resources after the
  4924. * device specific resource setup to support the HBA device it attached to.
  4925. *
  4926. * Return codes
  4927. * 0 - successful
  4928. * other values - error
  4929. **/
  4930. static int
  4931. lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
  4932. {
  4933. int error;
  4934. /* Startup the kernel thread for this host adapter. */
  4935. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  4936. "lpfc_worker_%d", phba->brd_no);
  4937. if (IS_ERR(phba->worker_thread)) {
  4938. error = PTR_ERR(phba->worker_thread);
  4939. return error;
  4940. }
  4941. return 0;
  4942. }
  4943. /**
  4944. * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
  4945. * @phba: pointer to lpfc hba data structure.
  4946. *
  4947. * This routine is invoked to unset the driver internal resources set up after
  4948. * the device specific resource setup for supporting the HBA device it
  4949. * attached to.
  4950. **/
  4951. static void
  4952. lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
  4953. {
  4954. /* Stop kernel worker thread */
  4955. kthread_stop(phba->worker_thread);
  4956. }
  4957. /**
  4958. * lpfc_free_iocb_list - Free iocb list.
  4959. * @phba: pointer to lpfc hba data structure.
  4960. *
  4961. * This routine is invoked to free the driver's IOCB list and memory.
  4962. **/
  4963. static void
  4964. lpfc_free_iocb_list(struct lpfc_hba *phba)
  4965. {
  4966. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  4967. spin_lock_irq(&phba->hbalock);
  4968. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  4969. &phba->lpfc_iocb_list, list) {
  4970. list_del(&iocbq_entry->list);
  4971. kfree(iocbq_entry);
  4972. phba->total_iocbq_bufs--;
  4973. }
  4974. spin_unlock_irq(&phba->hbalock);
  4975. return;
  4976. }
  4977. /**
  4978. * lpfc_init_iocb_list - Allocate and initialize iocb list.
  4979. * @phba: pointer to lpfc hba data structure.
  4980. *
  4981. * This routine is invoked to allocate and initizlize the driver's IOCB
  4982. * list and set up the IOCB tag array accordingly.
  4983. *
  4984. * Return codes
  4985. * 0 - successful
  4986. * other values - error
  4987. **/
  4988. static int
  4989. lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
  4990. {
  4991. struct lpfc_iocbq *iocbq_entry = NULL;
  4992. uint16_t iotag;
  4993. int i;
  4994. /* Initialize and populate the iocb list per host. */
  4995. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  4996. for (i = 0; i < iocb_count; i++) {
  4997. iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  4998. if (iocbq_entry == NULL) {
  4999. printk(KERN_ERR "%s: only allocated %d iocbs of "
  5000. "expected %d count. Unloading driver.\n",
  5001. __func__, i, LPFC_IOCB_LIST_CNT);
  5002. goto out_free_iocbq;
  5003. }
  5004. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  5005. if (iotag == 0) {
  5006. kfree(iocbq_entry);
  5007. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  5008. "Unloading driver.\n", __func__);
  5009. goto out_free_iocbq;
  5010. }
  5011. iocbq_entry->sli4_lxritag = NO_XRI;
  5012. iocbq_entry->sli4_xritag = NO_XRI;
  5013. spin_lock_irq(&phba->hbalock);
  5014. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  5015. phba->total_iocbq_bufs++;
  5016. spin_unlock_irq(&phba->hbalock);
  5017. }
  5018. return 0;
  5019. out_free_iocbq:
  5020. lpfc_free_iocb_list(phba);
  5021. return -ENOMEM;
  5022. }
  5023. /**
  5024. * lpfc_free_sgl_list - Free a given sgl list.
  5025. * @phba: pointer to lpfc hba data structure.
  5026. * @sglq_list: pointer to the head of sgl list.
  5027. *
  5028. * This routine is invoked to free a give sgl list and memory.
  5029. **/
  5030. void
  5031. lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
  5032. {
  5033. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  5034. list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
  5035. list_del(&sglq_entry->list);
  5036. lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
  5037. kfree(sglq_entry);
  5038. }
  5039. }
  5040. /**
  5041. * lpfc_free_els_sgl_list - Free els sgl list.
  5042. * @phba: pointer to lpfc hba data structure.
  5043. *
  5044. * This routine is invoked to free the driver's els sgl list and memory.
  5045. **/
  5046. static void
  5047. lpfc_free_els_sgl_list(struct lpfc_hba *phba)
  5048. {
  5049. LIST_HEAD(sglq_list);
  5050. /* Retrieve all els sgls from driver list */
  5051. spin_lock_irq(&phba->hbalock);
  5052. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
  5053. spin_unlock_irq(&phba->hbalock);
  5054. /* Now free the sgl list */
  5055. lpfc_free_sgl_list(phba, &sglq_list);
  5056. }
  5057. /**
  5058. * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
  5059. * @phba: pointer to lpfc hba data structure.
  5060. *
  5061. * This routine is invoked to allocate the driver's active sgl memory.
  5062. * This array will hold the sglq_entry's for active IOs.
  5063. **/
  5064. static int
  5065. lpfc_init_active_sgl_array(struct lpfc_hba *phba)
  5066. {
  5067. int size;
  5068. size = sizeof(struct lpfc_sglq *);
  5069. size *= phba->sli4_hba.max_cfg_param.max_xri;
  5070. phba->sli4_hba.lpfc_sglq_active_list =
  5071. kzalloc(size, GFP_KERNEL);
  5072. if (!phba->sli4_hba.lpfc_sglq_active_list)
  5073. return -ENOMEM;
  5074. return 0;
  5075. }
  5076. /**
  5077. * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
  5078. * @phba: pointer to lpfc hba data structure.
  5079. *
  5080. * This routine is invoked to walk through the array of active sglq entries
  5081. * and free all of the resources.
  5082. * This is just a place holder for now.
  5083. **/
  5084. static void
  5085. lpfc_free_active_sgl(struct lpfc_hba *phba)
  5086. {
  5087. kfree(phba->sli4_hba.lpfc_sglq_active_list);
  5088. }
  5089. /**
  5090. * lpfc_init_sgl_list - Allocate and initialize sgl list.
  5091. * @phba: pointer to lpfc hba data structure.
  5092. *
  5093. * This routine is invoked to allocate and initizlize the driver's sgl
  5094. * list and set up the sgl xritag tag array accordingly.
  5095. *
  5096. **/
  5097. static void
  5098. lpfc_init_sgl_list(struct lpfc_hba *phba)
  5099. {
  5100. /* Initialize and populate the sglq list per host/VF. */
  5101. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
  5102. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  5103. /* els xri-sgl book keeping */
  5104. phba->sli4_hba.els_xri_cnt = 0;
  5105. /* scsi xri-buffer book keeping */
  5106. phba->sli4_hba.scsi_xri_cnt = 0;
  5107. }
  5108. /**
  5109. * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
  5110. * @phba: pointer to lpfc hba data structure.
  5111. *
  5112. * This routine is invoked to post rpi header templates to the
  5113. * port for those SLI4 ports that do not support extents. This routine
  5114. * posts a PAGE_SIZE memory region to the port to hold up to
  5115. * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
  5116. * and should be called only when interrupts are disabled.
  5117. *
  5118. * Return codes
  5119. * 0 - successful
  5120. * -ERROR - otherwise.
  5121. **/
  5122. int
  5123. lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
  5124. {
  5125. int rc = 0;
  5126. struct lpfc_rpi_hdr *rpi_hdr;
  5127. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
  5128. if (!phba->sli4_hba.rpi_hdrs_in_use)
  5129. return rc;
  5130. if (phba->sli4_hba.extents_in_use)
  5131. return -EIO;
  5132. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  5133. if (!rpi_hdr) {
  5134. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5135. "0391 Error during rpi post operation\n");
  5136. lpfc_sli4_remove_rpis(phba);
  5137. rc = -ENODEV;
  5138. }
  5139. return rc;
  5140. }
  5141. /**
  5142. * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
  5143. * @phba: pointer to lpfc hba data structure.
  5144. *
  5145. * This routine is invoked to allocate a single 4KB memory region to
  5146. * support rpis and stores them in the phba. This single region
  5147. * provides support for up to 64 rpis. The region is used globally
  5148. * by the device.
  5149. *
  5150. * Returns:
  5151. * A valid rpi hdr on success.
  5152. * A NULL pointer on any failure.
  5153. **/
  5154. struct lpfc_rpi_hdr *
  5155. lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
  5156. {
  5157. uint16_t rpi_limit, curr_rpi_range;
  5158. struct lpfc_dmabuf *dmabuf;
  5159. struct lpfc_rpi_hdr *rpi_hdr;
  5160. uint32_t rpi_count;
  5161. /*
  5162. * If the SLI4 port supports extents, posting the rpi header isn't
  5163. * required. Set the expected maximum count and let the actual value
  5164. * get set when extents are fully allocated.
  5165. */
  5166. if (!phba->sli4_hba.rpi_hdrs_in_use)
  5167. return NULL;
  5168. if (phba->sli4_hba.extents_in_use)
  5169. return NULL;
  5170. /* The limit on the logical index is just the max_rpi count. */
  5171. rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
  5172. phba->sli4_hba.max_cfg_param.max_rpi - 1;
  5173. spin_lock_irq(&phba->hbalock);
  5174. /*
  5175. * Establish the starting RPI in this header block. The starting
  5176. * rpi is normalized to a zero base because the physical rpi is
  5177. * port based.
  5178. */
  5179. curr_rpi_range = phba->sli4_hba.next_rpi;
  5180. spin_unlock_irq(&phba->hbalock);
  5181. /*
  5182. * The port has a limited number of rpis. The increment here
  5183. * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
  5184. * and to allow the full max_rpi range per port.
  5185. */
  5186. if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
  5187. rpi_count = rpi_limit - curr_rpi_range;
  5188. else
  5189. rpi_count = LPFC_RPI_HDR_COUNT;
  5190. if (!rpi_count)
  5191. return NULL;
  5192. /*
  5193. * First allocate the protocol header region for the port. The
  5194. * port expects a 4KB DMA-mapped memory region that is 4K aligned.
  5195. */
  5196. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  5197. if (!dmabuf)
  5198. return NULL;
  5199. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  5200. LPFC_HDR_TEMPLATE_SIZE,
  5201. &dmabuf->phys,
  5202. GFP_KERNEL);
  5203. if (!dmabuf->virt) {
  5204. rpi_hdr = NULL;
  5205. goto err_free_dmabuf;
  5206. }
  5207. memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
  5208. if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
  5209. rpi_hdr = NULL;
  5210. goto err_free_coherent;
  5211. }
  5212. /* Save the rpi header data for cleanup later. */
  5213. rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
  5214. if (!rpi_hdr)
  5215. goto err_free_coherent;
  5216. rpi_hdr->dmabuf = dmabuf;
  5217. rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
  5218. rpi_hdr->page_count = 1;
  5219. spin_lock_irq(&phba->hbalock);
  5220. /* The rpi_hdr stores the logical index only. */
  5221. rpi_hdr->start_rpi = curr_rpi_range;
  5222. list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
  5223. /*
  5224. * The next_rpi stores the next logical module-64 rpi value used
  5225. * to post physical rpis in subsequent rpi postings.
  5226. */
  5227. phba->sli4_hba.next_rpi += rpi_count;
  5228. spin_unlock_irq(&phba->hbalock);
  5229. return rpi_hdr;
  5230. err_free_coherent:
  5231. dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
  5232. dmabuf->virt, dmabuf->phys);
  5233. err_free_dmabuf:
  5234. kfree(dmabuf);
  5235. return NULL;
  5236. }
  5237. /**
  5238. * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
  5239. * @phba: pointer to lpfc hba data structure.
  5240. *
  5241. * This routine is invoked to remove all memory resources allocated
  5242. * to support rpis for SLI4 ports not supporting extents. This routine
  5243. * presumes the caller has released all rpis consumed by fabric or port
  5244. * logins and is prepared to have the header pages removed.
  5245. **/
  5246. void
  5247. lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
  5248. {
  5249. struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
  5250. if (!phba->sli4_hba.rpi_hdrs_in_use)
  5251. goto exit;
  5252. list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
  5253. &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  5254. list_del(&rpi_hdr->list);
  5255. dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
  5256. rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
  5257. kfree(rpi_hdr->dmabuf);
  5258. kfree(rpi_hdr);
  5259. }
  5260. exit:
  5261. /* There are no rpis available to the port now. */
  5262. phba->sli4_hba.next_rpi = 0;
  5263. }
  5264. /**
  5265. * lpfc_hba_alloc - Allocate driver hba data structure for a device.
  5266. * @pdev: pointer to pci device data structure.
  5267. *
  5268. * This routine is invoked to allocate the driver hba data structure for an
  5269. * HBA device. If the allocation is successful, the phba reference to the
  5270. * PCI device data structure is set.
  5271. *
  5272. * Return codes
  5273. * pointer to @phba - successful
  5274. * NULL - error
  5275. **/
  5276. static struct lpfc_hba *
  5277. lpfc_hba_alloc(struct pci_dev *pdev)
  5278. {
  5279. struct lpfc_hba *phba;
  5280. /* Allocate memory for HBA structure */
  5281. phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
  5282. if (!phba) {
  5283. dev_err(&pdev->dev, "failed to allocate hba struct\n");
  5284. return NULL;
  5285. }
  5286. /* Set reference to PCI device in HBA structure */
  5287. phba->pcidev = pdev;
  5288. /* Assign an unused board number */
  5289. phba->brd_no = lpfc_get_instance();
  5290. if (phba->brd_no < 0) {
  5291. kfree(phba);
  5292. return NULL;
  5293. }
  5294. spin_lock_init(&phba->ct_ev_lock);
  5295. INIT_LIST_HEAD(&phba->ct_ev_waiters);
  5296. return phba;
  5297. }
  5298. /**
  5299. * lpfc_hba_free - Free driver hba data structure with a device.
  5300. * @phba: pointer to lpfc hba data structure.
  5301. *
  5302. * This routine is invoked to free the driver hba data structure with an
  5303. * HBA device.
  5304. **/
  5305. static void
  5306. lpfc_hba_free(struct lpfc_hba *phba)
  5307. {
  5308. /* Release the driver assigned board number */
  5309. idr_remove(&lpfc_hba_index, phba->brd_no);
  5310. /* Free memory allocated with sli rings */
  5311. kfree(phba->sli.ring);
  5312. phba->sli.ring = NULL;
  5313. kfree(phba);
  5314. return;
  5315. }
  5316. /**
  5317. * lpfc_create_shost - Create hba physical port with associated scsi host.
  5318. * @phba: pointer to lpfc hba data structure.
  5319. *
  5320. * This routine is invoked to create HBA physical port and associate a SCSI
  5321. * host with it.
  5322. *
  5323. * Return codes
  5324. * 0 - successful
  5325. * other values - error
  5326. **/
  5327. static int
  5328. lpfc_create_shost(struct lpfc_hba *phba)
  5329. {
  5330. struct lpfc_vport *vport;
  5331. struct Scsi_Host *shost;
  5332. /* Initialize HBA FC structure */
  5333. phba->fc_edtov = FF_DEF_EDTOV;
  5334. phba->fc_ratov = FF_DEF_RATOV;
  5335. phba->fc_altov = FF_DEF_ALTOV;
  5336. phba->fc_arbtov = FF_DEF_ARBTOV;
  5337. atomic_set(&phba->sdev_cnt, 0);
  5338. vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
  5339. if (!vport)
  5340. return -ENODEV;
  5341. shost = lpfc_shost_from_vport(vport);
  5342. phba->pport = vport;
  5343. lpfc_debugfs_initialize(vport);
  5344. /* Put reference to SCSI host to driver's device private data */
  5345. pci_set_drvdata(phba->pcidev, shost);
  5346. return 0;
  5347. }
  5348. /**
  5349. * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
  5350. * @phba: pointer to lpfc hba data structure.
  5351. *
  5352. * This routine is invoked to destroy HBA physical port and the associated
  5353. * SCSI host.
  5354. **/
  5355. static void
  5356. lpfc_destroy_shost(struct lpfc_hba *phba)
  5357. {
  5358. struct lpfc_vport *vport = phba->pport;
  5359. /* Destroy physical port that associated with the SCSI host */
  5360. destroy_port(vport);
  5361. return;
  5362. }
  5363. /**
  5364. * lpfc_setup_bg - Setup Block guard structures and debug areas.
  5365. * @phba: pointer to lpfc hba data structure.
  5366. * @shost: the shost to be used to detect Block guard settings.
  5367. *
  5368. * This routine sets up the local Block guard protocol settings for @shost.
  5369. * This routine also allocates memory for debugging bg buffers.
  5370. **/
  5371. static void
  5372. lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
  5373. {
  5374. uint32_t old_mask;
  5375. uint32_t old_guard;
  5376. int pagecnt = 10;
  5377. if (lpfc_prot_mask && lpfc_prot_guard) {
  5378. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5379. "1478 Registering BlockGuard with the "
  5380. "SCSI layer\n");
  5381. old_mask = lpfc_prot_mask;
  5382. old_guard = lpfc_prot_guard;
  5383. /* Only allow supported values */
  5384. lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
  5385. SHOST_DIX_TYPE0_PROTECTION |
  5386. SHOST_DIX_TYPE1_PROTECTION);
  5387. lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC);
  5388. /* DIF Type 1 protection for profiles AST1/C1 is end to end */
  5389. if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
  5390. lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
  5391. if (lpfc_prot_mask && lpfc_prot_guard) {
  5392. if ((old_mask != lpfc_prot_mask) ||
  5393. (old_guard != lpfc_prot_guard))
  5394. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5395. "1475 Registering BlockGuard with the "
  5396. "SCSI layer: mask %d guard %d\n",
  5397. lpfc_prot_mask, lpfc_prot_guard);
  5398. scsi_host_set_prot(shost, lpfc_prot_mask);
  5399. scsi_host_set_guard(shost, lpfc_prot_guard);
  5400. } else
  5401. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5402. "1479 Not Registering BlockGuard with the SCSI "
  5403. "layer, Bad protection parameters: %d %d\n",
  5404. old_mask, old_guard);
  5405. }
  5406. if (!_dump_buf_data) {
  5407. while (pagecnt) {
  5408. spin_lock_init(&_dump_buf_lock);
  5409. _dump_buf_data =
  5410. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  5411. if (_dump_buf_data) {
  5412. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5413. "9043 BLKGRD: allocated %d pages for "
  5414. "_dump_buf_data at 0x%p\n",
  5415. (1 << pagecnt), _dump_buf_data);
  5416. _dump_buf_data_order = pagecnt;
  5417. memset(_dump_buf_data, 0,
  5418. ((1 << PAGE_SHIFT) << pagecnt));
  5419. break;
  5420. } else
  5421. --pagecnt;
  5422. }
  5423. if (!_dump_buf_data_order)
  5424. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5425. "9044 BLKGRD: ERROR unable to allocate "
  5426. "memory for hexdump\n");
  5427. } else
  5428. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5429. "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
  5430. "\n", _dump_buf_data);
  5431. if (!_dump_buf_dif) {
  5432. while (pagecnt) {
  5433. _dump_buf_dif =
  5434. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  5435. if (_dump_buf_dif) {
  5436. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5437. "9046 BLKGRD: allocated %d pages for "
  5438. "_dump_buf_dif at 0x%p\n",
  5439. (1 << pagecnt), _dump_buf_dif);
  5440. _dump_buf_dif_order = pagecnt;
  5441. memset(_dump_buf_dif, 0,
  5442. ((1 << PAGE_SHIFT) << pagecnt));
  5443. break;
  5444. } else
  5445. --pagecnt;
  5446. }
  5447. if (!_dump_buf_dif_order)
  5448. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5449. "9047 BLKGRD: ERROR unable to allocate "
  5450. "memory for hexdump\n");
  5451. } else
  5452. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5453. "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
  5454. _dump_buf_dif);
  5455. }
  5456. /**
  5457. * lpfc_post_init_setup - Perform necessary device post initialization setup.
  5458. * @phba: pointer to lpfc hba data structure.
  5459. *
  5460. * This routine is invoked to perform all the necessary post initialization
  5461. * setup for the device.
  5462. **/
  5463. static void
  5464. lpfc_post_init_setup(struct lpfc_hba *phba)
  5465. {
  5466. struct Scsi_Host *shost;
  5467. struct lpfc_adapter_event_header adapter_event;
  5468. /* Get the default values for Model Name and Description */
  5469. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  5470. /*
  5471. * hba setup may have changed the hba_queue_depth so we need to
  5472. * adjust the value of can_queue.
  5473. */
  5474. shost = pci_get_drvdata(phba->pcidev);
  5475. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  5476. if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
  5477. lpfc_setup_bg(phba, shost);
  5478. lpfc_host_attrib_init(shost);
  5479. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  5480. spin_lock_irq(shost->host_lock);
  5481. lpfc_poll_start_timer(phba);
  5482. spin_unlock_irq(shost->host_lock);
  5483. }
  5484. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5485. "0428 Perform SCSI scan\n");
  5486. /* Send board arrival event to upper layer */
  5487. adapter_event.event_type = FC_REG_ADAPTER_EVENT;
  5488. adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
  5489. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5490. sizeof(adapter_event),
  5491. (char *) &adapter_event,
  5492. LPFC_NL_VENDOR_ID);
  5493. return;
  5494. }
  5495. /**
  5496. * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
  5497. * @phba: pointer to lpfc hba data structure.
  5498. *
  5499. * This routine is invoked to set up the PCI device memory space for device
  5500. * with SLI-3 interface spec.
  5501. *
  5502. * Return codes
  5503. * 0 - successful
  5504. * other values - error
  5505. **/
  5506. static int
  5507. lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
  5508. {
  5509. struct pci_dev *pdev;
  5510. unsigned long bar0map_len, bar2map_len;
  5511. int i, hbq_count;
  5512. void *ptr;
  5513. int error = -ENODEV;
  5514. /* Obtain PCI device reference */
  5515. if (!phba->pcidev)
  5516. return error;
  5517. else
  5518. pdev = phba->pcidev;
  5519. /* Set the device DMA mask size */
  5520. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
  5521. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
  5522. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
  5523. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
  5524. return error;
  5525. }
  5526. }
  5527. /* Get the bus address of Bar0 and Bar2 and the number of bytes
  5528. * required by each mapping.
  5529. */
  5530. phba->pci_bar0_map = pci_resource_start(pdev, 0);
  5531. bar0map_len = pci_resource_len(pdev, 0);
  5532. phba->pci_bar2_map = pci_resource_start(pdev, 2);
  5533. bar2map_len = pci_resource_len(pdev, 2);
  5534. /* Map HBA SLIM to a kernel virtual address. */
  5535. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  5536. if (!phba->slim_memmap_p) {
  5537. dev_printk(KERN_ERR, &pdev->dev,
  5538. "ioremap failed for SLIM memory.\n");
  5539. goto out;
  5540. }
  5541. /* Map HBA Control Registers to a kernel virtual address. */
  5542. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  5543. if (!phba->ctrl_regs_memmap_p) {
  5544. dev_printk(KERN_ERR, &pdev->dev,
  5545. "ioremap failed for HBA control registers.\n");
  5546. goto out_iounmap_slim;
  5547. }
  5548. /* Allocate memory for SLI-2 structures */
  5549. phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
  5550. SLI2_SLIM_SIZE,
  5551. &phba->slim2p.phys,
  5552. GFP_KERNEL);
  5553. if (!phba->slim2p.virt)
  5554. goto out_iounmap;
  5555. memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
  5556. phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
  5557. phba->mbox_ext = (phba->slim2p.virt +
  5558. offsetof(struct lpfc_sli2_slim, mbx_ext_words));
  5559. phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
  5560. phba->IOCBs = (phba->slim2p.virt +
  5561. offsetof(struct lpfc_sli2_slim, IOCBs));
  5562. phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
  5563. lpfc_sli_hbq_size(),
  5564. &phba->hbqslimp.phys,
  5565. GFP_KERNEL);
  5566. if (!phba->hbqslimp.virt)
  5567. goto out_free_slim;
  5568. hbq_count = lpfc_sli_hbq_count();
  5569. ptr = phba->hbqslimp.virt;
  5570. for (i = 0; i < hbq_count; ++i) {
  5571. phba->hbqs[i].hbq_virt = ptr;
  5572. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  5573. ptr += (lpfc_hbq_defs[i]->entry_count *
  5574. sizeof(struct lpfc_hbq_entry));
  5575. }
  5576. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
  5577. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
  5578. memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
  5579. INIT_LIST_HEAD(&phba->rb_pend_list);
  5580. phba->MBslimaddr = phba->slim_memmap_p;
  5581. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  5582. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  5583. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  5584. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  5585. return 0;
  5586. out_free_slim:
  5587. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  5588. phba->slim2p.virt, phba->slim2p.phys);
  5589. out_iounmap:
  5590. iounmap(phba->ctrl_regs_memmap_p);
  5591. out_iounmap_slim:
  5592. iounmap(phba->slim_memmap_p);
  5593. out:
  5594. return error;
  5595. }
  5596. /**
  5597. * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
  5598. * @phba: pointer to lpfc hba data structure.
  5599. *
  5600. * This routine is invoked to unset the PCI device memory space for device
  5601. * with SLI-3 interface spec.
  5602. **/
  5603. static void
  5604. lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
  5605. {
  5606. struct pci_dev *pdev;
  5607. /* Obtain PCI device reference */
  5608. if (!phba->pcidev)
  5609. return;
  5610. else
  5611. pdev = phba->pcidev;
  5612. /* Free coherent DMA memory allocated */
  5613. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  5614. phba->hbqslimp.virt, phba->hbqslimp.phys);
  5615. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  5616. phba->slim2p.virt, phba->slim2p.phys);
  5617. /* I/O memory unmap */
  5618. iounmap(phba->ctrl_regs_memmap_p);
  5619. iounmap(phba->slim_memmap_p);
  5620. return;
  5621. }
  5622. /**
  5623. * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
  5624. * @phba: pointer to lpfc hba data structure.
  5625. *
  5626. * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
  5627. * done and check status.
  5628. *
  5629. * Return 0 if successful, otherwise -ENODEV.
  5630. **/
  5631. int
  5632. lpfc_sli4_post_status_check(struct lpfc_hba *phba)
  5633. {
  5634. struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
  5635. struct lpfc_register reg_data;
  5636. int i, port_error = 0;
  5637. uint32_t if_type;
  5638. memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
  5639. memset(&reg_data, 0, sizeof(reg_data));
  5640. if (!phba->sli4_hba.PSMPHRregaddr)
  5641. return -ENODEV;
  5642. /* Wait up to 30 seconds for the SLI Port POST done and ready */
  5643. for (i = 0; i < 3000; i++) {
  5644. if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  5645. &portsmphr_reg.word0) ||
  5646. (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
  5647. /* Port has a fatal POST error, break out */
  5648. port_error = -ENODEV;
  5649. break;
  5650. }
  5651. if (LPFC_POST_STAGE_PORT_READY ==
  5652. bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
  5653. break;
  5654. msleep(10);
  5655. }
  5656. /*
  5657. * If there was a port error during POST, then don't proceed with
  5658. * other register reads as the data may not be valid. Just exit.
  5659. */
  5660. if (port_error) {
  5661. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5662. "1408 Port Failed POST - portsmphr=0x%x, "
  5663. "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
  5664. "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
  5665. portsmphr_reg.word0,
  5666. bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
  5667. bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
  5668. bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
  5669. bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
  5670. bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
  5671. bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
  5672. bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
  5673. bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
  5674. } else {
  5675. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5676. "2534 Device Info: SLIFamily=0x%x, "
  5677. "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
  5678. "SLIHint_2=0x%x, FT=0x%x\n",
  5679. bf_get(lpfc_sli_intf_sli_family,
  5680. &phba->sli4_hba.sli_intf),
  5681. bf_get(lpfc_sli_intf_slirev,
  5682. &phba->sli4_hba.sli_intf),
  5683. bf_get(lpfc_sli_intf_if_type,
  5684. &phba->sli4_hba.sli_intf),
  5685. bf_get(lpfc_sli_intf_sli_hint1,
  5686. &phba->sli4_hba.sli_intf),
  5687. bf_get(lpfc_sli_intf_sli_hint2,
  5688. &phba->sli4_hba.sli_intf),
  5689. bf_get(lpfc_sli_intf_func_type,
  5690. &phba->sli4_hba.sli_intf));
  5691. /*
  5692. * Check for other Port errors during the initialization
  5693. * process. Fail the load if the port did not come up
  5694. * correctly.
  5695. */
  5696. if_type = bf_get(lpfc_sli_intf_if_type,
  5697. &phba->sli4_hba.sli_intf);
  5698. switch (if_type) {
  5699. case LPFC_SLI_INTF_IF_TYPE_0:
  5700. phba->sli4_hba.ue_mask_lo =
  5701. readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
  5702. phba->sli4_hba.ue_mask_hi =
  5703. readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
  5704. uerrlo_reg.word0 =
  5705. readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
  5706. uerrhi_reg.word0 =
  5707. readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
  5708. if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
  5709. (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
  5710. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5711. "1422 Unrecoverable Error "
  5712. "Detected during POST "
  5713. "uerr_lo_reg=0x%x, "
  5714. "uerr_hi_reg=0x%x, "
  5715. "ue_mask_lo_reg=0x%x, "
  5716. "ue_mask_hi_reg=0x%x\n",
  5717. uerrlo_reg.word0,
  5718. uerrhi_reg.word0,
  5719. phba->sli4_hba.ue_mask_lo,
  5720. phba->sli4_hba.ue_mask_hi);
  5721. port_error = -ENODEV;
  5722. }
  5723. break;
  5724. case LPFC_SLI_INTF_IF_TYPE_2:
  5725. /* Final checks. The port status should be clean. */
  5726. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  5727. &reg_data.word0) ||
  5728. (bf_get(lpfc_sliport_status_err, &reg_data) &&
  5729. !bf_get(lpfc_sliport_status_rn, &reg_data))) {
  5730. phba->work_status[0] =
  5731. readl(phba->sli4_hba.u.if_type2.
  5732. ERR1regaddr);
  5733. phba->work_status[1] =
  5734. readl(phba->sli4_hba.u.if_type2.
  5735. ERR2regaddr);
  5736. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5737. "2888 Unrecoverable port error "
  5738. "following POST: port status reg "
  5739. "0x%x, port_smphr reg 0x%x, "
  5740. "error 1=0x%x, error 2=0x%x\n",
  5741. reg_data.word0,
  5742. portsmphr_reg.word0,
  5743. phba->work_status[0],
  5744. phba->work_status[1]);
  5745. port_error = -ENODEV;
  5746. }
  5747. break;
  5748. case LPFC_SLI_INTF_IF_TYPE_1:
  5749. default:
  5750. break;
  5751. }
  5752. }
  5753. return port_error;
  5754. }
  5755. /**
  5756. * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
  5757. * @phba: pointer to lpfc hba data structure.
  5758. * @if_type: The SLI4 interface type getting configured.
  5759. *
  5760. * This routine is invoked to set up SLI4 BAR0 PCI config space register
  5761. * memory map.
  5762. **/
  5763. static void
  5764. lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
  5765. {
  5766. switch (if_type) {
  5767. case LPFC_SLI_INTF_IF_TYPE_0:
  5768. phba->sli4_hba.u.if_type0.UERRLOregaddr =
  5769. phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
  5770. phba->sli4_hba.u.if_type0.UERRHIregaddr =
  5771. phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
  5772. phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
  5773. phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
  5774. phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
  5775. phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
  5776. phba->sli4_hba.SLIINTFregaddr =
  5777. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
  5778. break;
  5779. case LPFC_SLI_INTF_IF_TYPE_2:
  5780. phba->sli4_hba.u.if_type2.ERR1regaddr =
  5781. phba->sli4_hba.conf_regs_memmap_p +
  5782. LPFC_CTL_PORT_ER1_OFFSET;
  5783. phba->sli4_hba.u.if_type2.ERR2regaddr =
  5784. phba->sli4_hba.conf_regs_memmap_p +
  5785. LPFC_CTL_PORT_ER2_OFFSET;
  5786. phba->sli4_hba.u.if_type2.CTRLregaddr =
  5787. phba->sli4_hba.conf_regs_memmap_p +
  5788. LPFC_CTL_PORT_CTL_OFFSET;
  5789. phba->sli4_hba.u.if_type2.STATUSregaddr =
  5790. phba->sli4_hba.conf_regs_memmap_p +
  5791. LPFC_CTL_PORT_STA_OFFSET;
  5792. phba->sli4_hba.SLIINTFregaddr =
  5793. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
  5794. phba->sli4_hba.PSMPHRregaddr =
  5795. phba->sli4_hba.conf_regs_memmap_p +
  5796. LPFC_CTL_PORT_SEM_OFFSET;
  5797. phba->sli4_hba.RQDBregaddr =
  5798. phba->sli4_hba.conf_regs_memmap_p +
  5799. LPFC_ULP0_RQ_DOORBELL;
  5800. phba->sli4_hba.WQDBregaddr =
  5801. phba->sli4_hba.conf_regs_memmap_p +
  5802. LPFC_ULP0_WQ_DOORBELL;
  5803. phba->sli4_hba.EQCQDBregaddr =
  5804. phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
  5805. phba->sli4_hba.MQDBregaddr =
  5806. phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
  5807. phba->sli4_hba.BMBXregaddr =
  5808. phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
  5809. break;
  5810. case LPFC_SLI_INTF_IF_TYPE_1:
  5811. default:
  5812. dev_printk(KERN_ERR, &phba->pcidev->dev,
  5813. "FATAL - unsupported SLI4 interface type - %d\n",
  5814. if_type);
  5815. break;
  5816. }
  5817. }
  5818. /**
  5819. * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
  5820. * @phba: pointer to lpfc hba data structure.
  5821. *
  5822. * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
  5823. * memory map.
  5824. **/
  5825. static void
  5826. lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
  5827. {
  5828. phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5829. LPFC_SLIPORT_IF0_SMPHR;
  5830. phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5831. LPFC_HST_ISR0;
  5832. phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5833. LPFC_HST_IMR0;
  5834. phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5835. LPFC_HST_ISCR0;
  5836. }
  5837. /**
  5838. * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
  5839. * @phba: pointer to lpfc hba data structure.
  5840. * @vf: virtual function number
  5841. *
  5842. * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
  5843. * based on the given viftual function number, @vf.
  5844. *
  5845. * Return 0 if successful, otherwise -ENODEV.
  5846. **/
  5847. static int
  5848. lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
  5849. {
  5850. if (vf > LPFC_VIR_FUNC_MAX)
  5851. return -ENODEV;
  5852. phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5853. vf * LPFC_VFR_PAGE_SIZE +
  5854. LPFC_ULP0_RQ_DOORBELL);
  5855. phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5856. vf * LPFC_VFR_PAGE_SIZE +
  5857. LPFC_ULP0_WQ_DOORBELL);
  5858. phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5859. vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
  5860. phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5861. vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
  5862. phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5863. vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
  5864. return 0;
  5865. }
  5866. /**
  5867. * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
  5868. * @phba: pointer to lpfc hba data structure.
  5869. *
  5870. * This routine is invoked to create the bootstrap mailbox
  5871. * region consistent with the SLI-4 interface spec. This
  5872. * routine allocates all memory necessary to communicate
  5873. * mailbox commands to the port and sets up all alignment
  5874. * needs. No locks are expected to be held when calling
  5875. * this routine.
  5876. *
  5877. * Return codes
  5878. * 0 - successful
  5879. * -ENOMEM - could not allocated memory.
  5880. **/
  5881. static int
  5882. lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
  5883. {
  5884. uint32_t bmbx_size;
  5885. struct lpfc_dmabuf *dmabuf;
  5886. struct dma_address *dma_address;
  5887. uint32_t pa_addr;
  5888. uint64_t phys_addr;
  5889. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  5890. if (!dmabuf)
  5891. return -ENOMEM;
  5892. /*
  5893. * The bootstrap mailbox region is comprised of 2 parts
  5894. * plus an alignment restriction of 16 bytes.
  5895. */
  5896. bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
  5897. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  5898. bmbx_size,
  5899. &dmabuf->phys,
  5900. GFP_KERNEL);
  5901. if (!dmabuf->virt) {
  5902. kfree(dmabuf);
  5903. return -ENOMEM;
  5904. }
  5905. memset(dmabuf->virt, 0, bmbx_size);
  5906. /*
  5907. * Initialize the bootstrap mailbox pointers now so that the register
  5908. * operations are simple later. The mailbox dma address is required
  5909. * to be 16-byte aligned. Also align the virtual memory as each
  5910. * maibox is copied into the bmbx mailbox region before issuing the
  5911. * command to the port.
  5912. */
  5913. phba->sli4_hba.bmbx.dmabuf = dmabuf;
  5914. phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
  5915. phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
  5916. LPFC_ALIGN_16_BYTE);
  5917. phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
  5918. LPFC_ALIGN_16_BYTE);
  5919. /*
  5920. * Set the high and low physical addresses now. The SLI4 alignment
  5921. * requirement is 16 bytes and the mailbox is posted to the port
  5922. * as two 30-bit addresses. The other data is a bit marking whether
  5923. * the 30-bit address is the high or low address.
  5924. * Upcast bmbx aphys to 64bits so shift instruction compiles
  5925. * clean on 32 bit machines.
  5926. */
  5927. dma_address = &phba->sli4_hba.bmbx.dma_address;
  5928. phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
  5929. pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
  5930. dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
  5931. LPFC_BMBX_BIT1_ADDR_HI);
  5932. pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
  5933. dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
  5934. LPFC_BMBX_BIT1_ADDR_LO);
  5935. return 0;
  5936. }
  5937. /**
  5938. * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
  5939. * @phba: pointer to lpfc hba data structure.
  5940. *
  5941. * This routine is invoked to teardown the bootstrap mailbox
  5942. * region and release all host resources. This routine requires
  5943. * the caller to ensure all mailbox commands recovered, no
  5944. * additional mailbox comands are sent, and interrupts are disabled
  5945. * before calling this routine.
  5946. *
  5947. **/
  5948. static void
  5949. lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
  5950. {
  5951. dma_free_coherent(&phba->pcidev->dev,
  5952. phba->sli4_hba.bmbx.bmbx_size,
  5953. phba->sli4_hba.bmbx.dmabuf->virt,
  5954. phba->sli4_hba.bmbx.dmabuf->phys);
  5955. kfree(phba->sli4_hba.bmbx.dmabuf);
  5956. memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
  5957. }
  5958. /**
  5959. * lpfc_sli4_read_config - Get the config parameters.
  5960. * @phba: pointer to lpfc hba data structure.
  5961. *
  5962. * This routine is invoked to read the configuration parameters from the HBA.
  5963. * The configuration parameters are used to set the base and maximum values
  5964. * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
  5965. * allocation for the port.
  5966. *
  5967. * Return codes
  5968. * 0 - successful
  5969. * -ENOMEM - No available memory
  5970. * -EIO - The mailbox failed to complete successfully.
  5971. **/
  5972. int
  5973. lpfc_sli4_read_config(struct lpfc_hba *phba)
  5974. {
  5975. LPFC_MBOXQ_t *pmb;
  5976. struct lpfc_mbx_read_config *rd_config;
  5977. union lpfc_sli4_cfg_shdr *shdr;
  5978. uint32_t shdr_status, shdr_add_status;
  5979. struct lpfc_mbx_get_func_cfg *get_func_cfg;
  5980. struct lpfc_rsrc_desc_fcfcoe *desc;
  5981. char *pdesc_0;
  5982. uint32_t desc_count;
  5983. int length, i, rc = 0, rc2;
  5984. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5985. if (!pmb) {
  5986. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5987. "2011 Unable to allocate memory for issuing "
  5988. "SLI_CONFIG_SPECIAL mailbox command\n");
  5989. return -ENOMEM;
  5990. }
  5991. lpfc_read_config(phba, pmb);
  5992. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  5993. if (rc != MBX_SUCCESS) {
  5994. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5995. "2012 Mailbox failed , mbxCmd x%x "
  5996. "READ_CONFIG, mbxStatus x%x\n",
  5997. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  5998. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  5999. rc = -EIO;
  6000. } else {
  6001. rd_config = &pmb->u.mqe.un.rd_config;
  6002. if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
  6003. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  6004. phba->sli4_hba.lnk_info.lnk_tp =
  6005. bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
  6006. phba->sli4_hba.lnk_info.lnk_no =
  6007. bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
  6008. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6009. "3081 lnk_type:%d, lnk_numb:%d\n",
  6010. phba->sli4_hba.lnk_info.lnk_tp,
  6011. phba->sli4_hba.lnk_info.lnk_no);
  6012. } else
  6013. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  6014. "3082 Mailbox (x%x) returned ldv:x0\n",
  6015. bf_get(lpfc_mqe_command, &pmb->u.mqe));
  6016. phba->sli4_hba.extents_in_use =
  6017. bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
  6018. phba->sli4_hba.max_cfg_param.max_xri =
  6019. bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
  6020. phba->sli4_hba.max_cfg_param.xri_base =
  6021. bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
  6022. phba->sli4_hba.max_cfg_param.max_vpi =
  6023. bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
  6024. phba->sli4_hba.max_cfg_param.vpi_base =
  6025. bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
  6026. phba->sli4_hba.max_cfg_param.max_rpi =
  6027. bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
  6028. phba->sli4_hba.max_cfg_param.rpi_base =
  6029. bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
  6030. phba->sli4_hba.max_cfg_param.max_vfi =
  6031. bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
  6032. phba->sli4_hba.max_cfg_param.vfi_base =
  6033. bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
  6034. phba->sli4_hba.max_cfg_param.max_fcfi =
  6035. bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
  6036. phba->sli4_hba.max_cfg_param.max_eq =
  6037. bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
  6038. phba->sli4_hba.max_cfg_param.max_rq =
  6039. bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
  6040. phba->sli4_hba.max_cfg_param.max_wq =
  6041. bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
  6042. phba->sli4_hba.max_cfg_param.max_cq =
  6043. bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
  6044. phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
  6045. phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
  6046. phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
  6047. phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
  6048. phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
  6049. (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
  6050. phba->max_vports = phba->max_vpi;
  6051. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6052. "2003 cfg params Extents? %d "
  6053. "XRI(B:%d M:%d), "
  6054. "VPI(B:%d M:%d) "
  6055. "VFI(B:%d M:%d) "
  6056. "RPI(B:%d M:%d) "
  6057. "FCFI(Count:%d)\n",
  6058. phba->sli4_hba.extents_in_use,
  6059. phba->sli4_hba.max_cfg_param.xri_base,
  6060. phba->sli4_hba.max_cfg_param.max_xri,
  6061. phba->sli4_hba.max_cfg_param.vpi_base,
  6062. phba->sli4_hba.max_cfg_param.max_vpi,
  6063. phba->sli4_hba.max_cfg_param.vfi_base,
  6064. phba->sli4_hba.max_cfg_param.max_vfi,
  6065. phba->sli4_hba.max_cfg_param.rpi_base,
  6066. phba->sli4_hba.max_cfg_param.max_rpi,
  6067. phba->sli4_hba.max_cfg_param.max_fcfi);
  6068. }
  6069. if (rc)
  6070. goto read_cfg_out;
  6071. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  6072. if (phba->cfg_hba_queue_depth >
  6073. (phba->sli4_hba.max_cfg_param.max_xri -
  6074. lpfc_sli4_get_els_iocb_cnt(phba)))
  6075. phba->cfg_hba_queue_depth =
  6076. phba->sli4_hba.max_cfg_param.max_xri -
  6077. lpfc_sli4_get_els_iocb_cnt(phba);
  6078. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  6079. LPFC_SLI_INTF_IF_TYPE_2)
  6080. goto read_cfg_out;
  6081. /* get the pf# and vf# for SLI4 if_type 2 port */
  6082. length = (sizeof(struct lpfc_mbx_get_func_cfg) -
  6083. sizeof(struct lpfc_sli4_cfg_mhdr));
  6084. lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
  6085. LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
  6086. length, LPFC_SLI4_MBX_EMBED);
  6087. rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  6088. shdr = (union lpfc_sli4_cfg_shdr *)
  6089. &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
  6090. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  6091. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  6092. if (rc2 || shdr_status || shdr_add_status) {
  6093. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6094. "3026 Mailbox failed , mbxCmd x%x "
  6095. "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
  6096. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  6097. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  6098. goto read_cfg_out;
  6099. }
  6100. /* search for fc_fcoe resrouce descriptor */
  6101. get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
  6102. desc_count = get_func_cfg->func_cfg.rsrc_desc_count;
  6103. pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
  6104. desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
  6105. length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
  6106. if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
  6107. length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
  6108. else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
  6109. goto read_cfg_out;
  6110. for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
  6111. desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
  6112. if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
  6113. bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
  6114. phba->sli4_hba.iov.pf_number =
  6115. bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
  6116. phba->sli4_hba.iov.vf_number =
  6117. bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
  6118. break;
  6119. }
  6120. }
  6121. if (i < LPFC_RSRC_DESC_MAX_NUM)
  6122. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6123. "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
  6124. "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
  6125. phba->sli4_hba.iov.vf_number);
  6126. else
  6127. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6128. "3028 GET_FUNCTION_CONFIG: failed to find "
  6129. "Resrouce Descriptor:x%x\n",
  6130. LPFC_RSRC_DESC_TYPE_FCFCOE);
  6131. read_cfg_out:
  6132. mempool_free(pmb, phba->mbox_mem_pool);
  6133. return rc;
  6134. }
  6135. /**
  6136. * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
  6137. * @phba: pointer to lpfc hba data structure.
  6138. *
  6139. * This routine is invoked to setup the port-side endian order when
  6140. * the port if_type is 0. This routine has no function for other
  6141. * if_types.
  6142. *
  6143. * Return codes
  6144. * 0 - successful
  6145. * -ENOMEM - No available memory
  6146. * -EIO - The mailbox failed to complete successfully.
  6147. **/
  6148. static int
  6149. lpfc_setup_endian_order(struct lpfc_hba *phba)
  6150. {
  6151. LPFC_MBOXQ_t *mboxq;
  6152. uint32_t if_type, rc = 0;
  6153. uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
  6154. HOST_ENDIAN_HIGH_WORD1};
  6155. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  6156. switch (if_type) {
  6157. case LPFC_SLI_INTF_IF_TYPE_0:
  6158. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  6159. GFP_KERNEL);
  6160. if (!mboxq) {
  6161. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6162. "0492 Unable to allocate memory for "
  6163. "issuing SLI_CONFIG_SPECIAL mailbox "
  6164. "command\n");
  6165. return -ENOMEM;
  6166. }
  6167. /*
  6168. * The SLI4_CONFIG_SPECIAL mailbox command requires the first
  6169. * two words to contain special data values and no other data.
  6170. */
  6171. memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
  6172. memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
  6173. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6174. if (rc != MBX_SUCCESS) {
  6175. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6176. "0493 SLI_CONFIG_SPECIAL mailbox "
  6177. "failed with status x%x\n",
  6178. rc);
  6179. rc = -EIO;
  6180. }
  6181. mempool_free(mboxq, phba->mbox_mem_pool);
  6182. break;
  6183. case LPFC_SLI_INTF_IF_TYPE_2:
  6184. case LPFC_SLI_INTF_IF_TYPE_1:
  6185. default:
  6186. break;
  6187. }
  6188. return rc;
  6189. }
  6190. /**
  6191. * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
  6192. * @phba: pointer to lpfc hba data structure.
  6193. *
  6194. * This routine is invoked to check the user settable queue counts for EQs and
  6195. * CQs. after this routine is called the counts will be set to valid values that
  6196. * adhere to the constraints of the system's interrupt vectors and the port's
  6197. * queue resources.
  6198. *
  6199. * Return codes
  6200. * 0 - successful
  6201. * -ENOMEM - No available memory
  6202. **/
  6203. static int
  6204. lpfc_sli4_queue_verify(struct lpfc_hba *phba)
  6205. {
  6206. int cfg_fcp_io_channel;
  6207. uint32_t cpu;
  6208. uint32_t i = 0;
  6209. /*
  6210. * Sanity check for configured queue parameters against the run-time
  6211. * device parameters
  6212. */
  6213. /* Sanity check on HBA EQ parameters */
  6214. cfg_fcp_io_channel = phba->cfg_fcp_io_channel;
  6215. /* It doesn't make sense to have more io channels then online CPUs */
  6216. for_each_present_cpu(cpu) {
  6217. if (cpu_online(cpu))
  6218. i++;
  6219. }
  6220. phba->sli4_hba.num_online_cpu = i;
  6221. phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
  6222. if (i < cfg_fcp_io_channel) {
  6223. lpfc_printf_log(phba,
  6224. KERN_ERR, LOG_INIT,
  6225. "3188 Reducing IO channels to match number of "
  6226. "online CPUs: from %d to %d\n",
  6227. cfg_fcp_io_channel, i);
  6228. cfg_fcp_io_channel = i;
  6229. }
  6230. if (cfg_fcp_io_channel >
  6231. phba->sli4_hba.max_cfg_param.max_eq) {
  6232. if (phba->sli4_hba.max_cfg_param.max_eq <
  6233. LPFC_FCP_IO_CHAN_MIN) {
  6234. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6235. "2574 Not enough EQs (%d) from the "
  6236. "pci function for supporting FCP "
  6237. "EQs (%d)\n",
  6238. phba->sli4_hba.max_cfg_param.max_eq,
  6239. phba->cfg_fcp_io_channel);
  6240. goto out_error;
  6241. }
  6242. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6243. "2575 Reducing IO channels to match number of "
  6244. "available EQs: from %d to %d\n",
  6245. cfg_fcp_io_channel,
  6246. phba->sli4_hba.max_cfg_param.max_eq);
  6247. cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq;
  6248. }
  6249. /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */
  6250. /* The actual number of FCP event queues adopted */
  6251. phba->cfg_fcp_eq_count = cfg_fcp_io_channel;
  6252. phba->cfg_fcp_wq_count = cfg_fcp_io_channel;
  6253. phba->cfg_fcp_io_channel = cfg_fcp_io_channel;
  6254. /* Get EQ depth from module parameter, fake the default for now */
  6255. phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
  6256. phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
  6257. /* Get CQ depth from module parameter, fake the default for now */
  6258. phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
  6259. phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
  6260. return 0;
  6261. out_error:
  6262. return -ENOMEM;
  6263. }
  6264. /**
  6265. * lpfc_sli4_queue_create - Create all the SLI4 queues
  6266. * @phba: pointer to lpfc hba data structure.
  6267. *
  6268. * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
  6269. * operation. For each SLI4 queue type, the parameters such as queue entry
  6270. * count (queue depth) shall be taken from the module parameter. For now,
  6271. * we just use some constant number as place holder.
  6272. *
  6273. * Return codes
  6274. * 0 - successful
  6275. * -ENOMEM - No availble memory
  6276. * -EIO - The mailbox failed to complete successfully.
  6277. **/
  6278. int
  6279. lpfc_sli4_queue_create(struct lpfc_hba *phba)
  6280. {
  6281. struct lpfc_queue *qdesc;
  6282. int idx;
  6283. /*
  6284. * Create HBA Record arrays.
  6285. */
  6286. if (!phba->cfg_fcp_io_channel)
  6287. return -ERANGE;
  6288. phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
  6289. phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
  6290. phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
  6291. phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
  6292. phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
  6293. phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
  6294. phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) *
  6295. phba->cfg_fcp_io_channel), GFP_KERNEL);
  6296. if (!phba->sli4_hba.hba_eq) {
  6297. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6298. "2576 Failed allocate memory for "
  6299. "fast-path EQ record array\n");
  6300. goto out_error;
  6301. }
  6302. phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
  6303. phba->cfg_fcp_io_channel), GFP_KERNEL);
  6304. if (!phba->sli4_hba.fcp_cq) {
  6305. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6306. "2577 Failed allocate memory for fast-path "
  6307. "CQ record array\n");
  6308. goto out_error;
  6309. }
  6310. phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
  6311. phba->cfg_fcp_io_channel), GFP_KERNEL);
  6312. if (!phba->sli4_hba.fcp_wq) {
  6313. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6314. "2578 Failed allocate memory for fast-path "
  6315. "WQ record array\n");
  6316. goto out_error;
  6317. }
  6318. /*
  6319. * Since the first EQ can have multiple CQs associated with it,
  6320. * this array is used to quickly see if we have a FCP fast-path
  6321. * CQ match.
  6322. */
  6323. phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) *
  6324. phba->cfg_fcp_io_channel), GFP_KERNEL);
  6325. if (!phba->sli4_hba.fcp_cq_map) {
  6326. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6327. "2545 Failed allocate memory for fast-path "
  6328. "CQ map\n");
  6329. goto out_error;
  6330. }
  6331. /*
  6332. * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
  6333. * how many EQs to create.
  6334. */
  6335. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
  6336. /* Create EQs */
  6337. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  6338. phba->sli4_hba.eq_ecount);
  6339. if (!qdesc) {
  6340. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6341. "0497 Failed allocate EQ (%d)\n", idx);
  6342. goto out_error;
  6343. }
  6344. phba->sli4_hba.hba_eq[idx] = qdesc;
  6345. /* Create Fast Path FCP CQs */
  6346. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  6347. phba->sli4_hba.cq_ecount);
  6348. if (!qdesc) {
  6349. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6350. "0499 Failed allocate fast-path FCP "
  6351. "CQ (%d)\n", idx);
  6352. goto out_error;
  6353. }
  6354. phba->sli4_hba.fcp_cq[idx] = qdesc;
  6355. /* Create Fast Path FCP WQs */
  6356. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  6357. phba->sli4_hba.wq_ecount);
  6358. if (!qdesc) {
  6359. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6360. "0503 Failed allocate fast-path FCP "
  6361. "WQ (%d)\n", idx);
  6362. goto out_error;
  6363. }
  6364. phba->sli4_hba.fcp_wq[idx] = qdesc;
  6365. }
  6366. /*
  6367. * Create Slow Path Completion Queues (CQs)
  6368. */
  6369. /* Create slow-path Mailbox Command Complete Queue */
  6370. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  6371. phba->sli4_hba.cq_ecount);
  6372. if (!qdesc) {
  6373. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6374. "0500 Failed allocate slow-path mailbox CQ\n");
  6375. goto out_error;
  6376. }
  6377. phba->sli4_hba.mbx_cq = qdesc;
  6378. /* Create slow-path ELS Complete Queue */
  6379. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  6380. phba->sli4_hba.cq_ecount);
  6381. if (!qdesc) {
  6382. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6383. "0501 Failed allocate slow-path ELS CQ\n");
  6384. goto out_error;
  6385. }
  6386. phba->sli4_hba.els_cq = qdesc;
  6387. /*
  6388. * Create Slow Path Work Queues (WQs)
  6389. */
  6390. /* Create Mailbox Command Queue */
  6391. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
  6392. phba->sli4_hba.mq_ecount);
  6393. if (!qdesc) {
  6394. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6395. "0505 Failed allocate slow-path MQ\n");
  6396. goto out_error;
  6397. }
  6398. phba->sli4_hba.mbx_wq = qdesc;
  6399. /*
  6400. * Create ELS Work Queues
  6401. */
  6402. /* Create slow-path ELS Work Queue */
  6403. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  6404. phba->sli4_hba.wq_ecount);
  6405. if (!qdesc) {
  6406. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6407. "0504 Failed allocate slow-path ELS WQ\n");
  6408. goto out_error;
  6409. }
  6410. phba->sli4_hba.els_wq = qdesc;
  6411. /*
  6412. * Create Receive Queue (RQ)
  6413. */
  6414. /* Create Receive Queue for header */
  6415. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  6416. phba->sli4_hba.rq_ecount);
  6417. if (!qdesc) {
  6418. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6419. "0506 Failed allocate receive HRQ\n");
  6420. goto out_error;
  6421. }
  6422. phba->sli4_hba.hdr_rq = qdesc;
  6423. /* Create Receive Queue for data */
  6424. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  6425. phba->sli4_hba.rq_ecount);
  6426. if (!qdesc) {
  6427. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6428. "0507 Failed allocate receive DRQ\n");
  6429. goto out_error;
  6430. }
  6431. phba->sli4_hba.dat_rq = qdesc;
  6432. return 0;
  6433. out_error:
  6434. lpfc_sli4_queue_destroy(phba);
  6435. return -ENOMEM;
  6436. }
  6437. /**
  6438. * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
  6439. * @phba: pointer to lpfc hba data structure.
  6440. *
  6441. * This routine is invoked to release all the SLI4 queues with the FCoE HBA
  6442. * operation.
  6443. *
  6444. * Return codes
  6445. * 0 - successful
  6446. * -ENOMEM - No available memory
  6447. * -EIO - The mailbox failed to complete successfully.
  6448. **/
  6449. void
  6450. lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
  6451. {
  6452. int idx;
  6453. if (phba->sli4_hba.hba_eq != NULL) {
  6454. /* Release HBA event queue */
  6455. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
  6456. if (phba->sli4_hba.hba_eq[idx] != NULL) {
  6457. lpfc_sli4_queue_free(
  6458. phba->sli4_hba.hba_eq[idx]);
  6459. phba->sli4_hba.hba_eq[idx] = NULL;
  6460. }
  6461. }
  6462. kfree(phba->sli4_hba.hba_eq);
  6463. phba->sli4_hba.hba_eq = NULL;
  6464. }
  6465. if (phba->sli4_hba.fcp_cq != NULL) {
  6466. /* Release FCP completion queue */
  6467. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
  6468. if (phba->sli4_hba.fcp_cq[idx] != NULL) {
  6469. lpfc_sli4_queue_free(
  6470. phba->sli4_hba.fcp_cq[idx]);
  6471. phba->sli4_hba.fcp_cq[idx] = NULL;
  6472. }
  6473. }
  6474. kfree(phba->sli4_hba.fcp_cq);
  6475. phba->sli4_hba.fcp_cq = NULL;
  6476. }
  6477. if (phba->sli4_hba.fcp_wq != NULL) {
  6478. /* Release FCP work queue */
  6479. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
  6480. if (phba->sli4_hba.fcp_wq[idx] != NULL) {
  6481. lpfc_sli4_queue_free(
  6482. phba->sli4_hba.fcp_wq[idx]);
  6483. phba->sli4_hba.fcp_wq[idx] = NULL;
  6484. }
  6485. }
  6486. kfree(phba->sli4_hba.fcp_wq);
  6487. phba->sli4_hba.fcp_wq = NULL;
  6488. }
  6489. if (phba->pci_bar0_memmap_p) {
  6490. iounmap(phba->pci_bar0_memmap_p);
  6491. phba->pci_bar0_memmap_p = NULL;
  6492. }
  6493. if (phba->pci_bar2_memmap_p) {
  6494. iounmap(phba->pci_bar2_memmap_p);
  6495. phba->pci_bar2_memmap_p = NULL;
  6496. }
  6497. if (phba->pci_bar4_memmap_p) {
  6498. iounmap(phba->pci_bar4_memmap_p);
  6499. phba->pci_bar4_memmap_p = NULL;
  6500. }
  6501. /* Release FCP CQ mapping array */
  6502. if (phba->sli4_hba.fcp_cq_map != NULL) {
  6503. kfree(phba->sli4_hba.fcp_cq_map);
  6504. phba->sli4_hba.fcp_cq_map = NULL;
  6505. }
  6506. /* Release mailbox command work queue */
  6507. if (phba->sli4_hba.mbx_wq != NULL) {
  6508. lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
  6509. phba->sli4_hba.mbx_wq = NULL;
  6510. }
  6511. /* Release ELS work queue */
  6512. if (phba->sli4_hba.els_wq != NULL) {
  6513. lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
  6514. phba->sli4_hba.els_wq = NULL;
  6515. }
  6516. /* Release unsolicited receive queue */
  6517. if (phba->sli4_hba.hdr_rq != NULL) {
  6518. lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
  6519. phba->sli4_hba.hdr_rq = NULL;
  6520. }
  6521. if (phba->sli4_hba.dat_rq != NULL) {
  6522. lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
  6523. phba->sli4_hba.dat_rq = NULL;
  6524. }
  6525. /* Release ELS complete queue */
  6526. if (phba->sli4_hba.els_cq != NULL) {
  6527. lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
  6528. phba->sli4_hba.els_cq = NULL;
  6529. }
  6530. /* Release mailbox command complete queue */
  6531. if (phba->sli4_hba.mbx_cq != NULL) {
  6532. lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
  6533. phba->sli4_hba.mbx_cq = NULL;
  6534. }
  6535. return;
  6536. }
  6537. /**
  6538. * lpfc_sli4_queue_setup - Set up all the SLI4 queues
  6539. * @phba: pointer to lpfc hba data structure.
  6540. *
  6541. * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
  6542. * operation.
  6543. *
  6544. * Return codes
  6545. * 0 - successful
  6546. * -ENOMEM - No available memory
  6547. * -EIO - The mailbox failed to complete successfully.
  6548. **/
  6549. int
  6550. lpfc_sli4_queue_setup(struct lpfc_hba *phba)
  6551. {
  6552. struct lpfc_sli *psli = &phba->sli;
  6553. struct lpfc_sli_ring *pring;
  6554. int rc = -ENOMEM;
  6555. int fcp_eqidx, fcp_cqidx, fcp_wqidx;
  6556. int fcp_cq_index = 0;
  6557. uint32_t shdr_status, shdr_add_status;
  6558. union lpfc_sli4_cfg_shdr *shdr;
  6559. LPFC_MBOXQ_t *mboxq;
  6560. uint32_t length;
  6561. /* Check for dual-ULP support */
  6562. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  6563. if (!mboxq) {
  6564. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6565. "3249 Unable to allocate memory for "
  6566. "QUERY_FW_CFG mailbox command\n");
  6567. return -ENOMEM;
  6568. }
  6569. length = (sizeof(struct lpfc_mbx_query_fw_config) -
  6570. sizeof(struct lpfc_sli4_cfg_mhdr));
  6571. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  6572. LPFC_MBOX_OPCODE_QUERY_FW_CFG,
  6573. length, LPFC_SLI4_MBX_EMBED);
  6574. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6575. shdr = (union lpfc_sli4_cfg_shdr *)
  6576. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  6577. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  6578. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  6579. if (shdr_status || shdr_add_status || rc) {
  6580. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6581. "3250 QUERY_FW_CFG mailbox failed with status "
  6582. "x%x add_status x%x, mbx status x%x\n",
  6583. shdr_status, shdr_add_status, rc);
  6584. if (rc != MBX_TIMEOUT)
  6585. mempool_free(mboxq, phba->mbox_mem_pool);
  6586. rc = -ENXIO;
  6587. goto out_error;
  6588. }
  6589. phba->sli4_hba.fw_func_mode =
  6590. mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
  6591. phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
  6592. phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
  6593. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6594. "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
  6595. "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
  6596. phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
  6597. if (rc != MBX_TIMEOUT)
  6598. mempool_free(mboxq, phba->mbox_mem_pool);
  6599. /*
  6600. * Set up HBA Event Queues (EQs)
  6601. */
  6602. /* Set up HBA event queue */
  6603. if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) {
  6604. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6605. "3147 Fast-path EQs not allocated\n");
  6606. rc = -ENOMEM;
  6607. goto out_error;
  6608. }
  6609. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
  6610. if (!phba->sli4_hba.hba_eq[fcp_eqidx]) {
  6611. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6612. "0522 Fast-path EQ (%d) not "
  6613. "allocated\n", fcp_eqidx);
  6614. rc = -ENOMEM;
  6615. goto out_destroy_hba_eq;
  6616. }
  6617. rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx],
  6618. (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel));
  6619. if (rc) {
  6620. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6621. "0523 Failed setup of fast-path EQ "
  6622. "(%d), rc = 0x%x\n", fcp_eqidx, rc);
  6623. goto out_destroy_hba_eq;
  6624. }
  6625. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6626. "2584 HBA EQ setup: "
  6627. "queue[%d]-id=%d\n", fcp_eqidx,
  6628. phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id);
  6629. }
  6630. /* Set up fast-path FCP Response Complete Queue */
  6631. if (!phba->sli4_hba.fcp_cq) {
  6632. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6633. "3148 Fast-path FCP CQ array not "
  6634. "allocated\n");
  6635. rc = -ENOMEM;
  6636. goto out_destroy_hba_eq;
  6637. }
  6638. for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) {
  6639. if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
  6640. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6641. "0526 Fast-path FCP CQ (%d) not "
  6642. "allocated\n", fcp_cqidx);
  6643. rc = -ENOMEM;
  6644. goto out_destroy_fcp_cq;
  6645. }
  6646. rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
  6647. phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP);
  6648. if (rc) {
  6649. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6650. "0527 Failed setup of fast-path FCP "
  6651. "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
  6652. goto out_destroy_fcp_cq;
  6653. }
  6654. /* Setup fcp_cq_map for fast lookup */
  6655. phba->sli4_hba.fcp_cq_map[fcp_cqidx] =
  6656. phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id;
  6657. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6658. "2588 FCP CQ setup: cq[%d]-id=%d, "
  6659. "parent seq[%d]-id=%d\n",
  6660. fcp_cqidx,
  6661. phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
  6662. fcp_cqidx,
  6663. phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id);
  6664. }
  6665. /* Set up fast-path FCP Work Queue */
  6666. if (!phba->sli4_hba.fcp_wq) {
  6667. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6668. "3149 Fast-path FCP WQ array not "
  6669. "allocated\n");
  6670. rc = -ENOMEM;
  6671. goto out_destroy_fcp_cq;
  6672. }
  6673. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) {
  6674. if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
  6675. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6676. "0534 Fast-path FCP WQ (%d) not "
  6677. "allocated\n", fcp_wqidx);
  6678. rc = -ENOMEM;
  6679. goto out_destroy_fcp_wq;
  6680. }
  6681. rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
  6682. phba->sli4_hba.fcp_cq[fcp_wqidx],
  6683. LPFC_FCP);
  6684. if (rc) {
  6685. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6686. "0535 Failed setup of fast-path FCP "
  6687. "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
  6688. goto out_destroy_fcp_wq;
  6689. }
  6690. /* Bind this WQ to the next FCP ring */
  6691. pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx];
  6692. pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx];
  6693. phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring;
  6694. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6695. "2591 FCP WQ setup: wq[%d]-id=%d, "
  6696. "parent cq[%d]-id=%d\n",
  6697. fcp_wqidx,
  6698. phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
  6699. fcp_cq_index,
  6700. phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id);
  6701. }
  6702. /*
  6703. * Set up Complete Queues (CQs)
  6704. */
  6705. /* Set up slow-path MBOX Complete Queue as the first CQ */
  6706. if (!phba->sli4_hba.mbx_cq) {
  6707. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6708. "0528 Mailbox CQ not allocated\n");
  6709. rc = -ENOMEM;
  6710. goto out_destroy_fcp_wq;
  6711. }
  6712. rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq,
  6713. phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX);
  6714. if (rc) {
  6715. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6716. "0529 Failed setup of slow-path mailbox CQ: "
  6717. "rc = 0x%x\n", rc);
  6718. goto out_destroy_fcp_wq;
  6719. }
  6720. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6721. "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
  6722. phba->sli4_hba.mbx_cq->queue_id,
  6723. phba->sli4_hba.hba_eq[0]->queue_id);
  6724. /* Set up slow-path ELS Complete Queue */
  6725. if (!phba->sli4_hba.els_cq) {
  6726. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6727. "0530 ELS CQ not allocated\n");
  6728. rc = -ENOMEM;
  6729. goto out_destroy_mbx_cq;
  6730. }
  6731. rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq,
  6732. phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS);
  6733. if (rc) {
  6734. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6735. "0531 Failed setup of slow-path ELS CQ: "
  6736. "rc = 0x%x\n", rc);
  6737. goto out_destroy_mbx_cq;
  6738. }
  6739. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6740. "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
  6741. phba->sli4_hba.els_cq->queue_id,
  6742. phba->sli4_hba.hba_eq[0]->queue_id);
  6743. /*
  6744. * Set up all the Work Queues (WQs)
  6745. */
  6746. /* Set up Mailbox Command Queue */
  6747. if (!phba->sli4_hba.mbx_wq) {
  6748. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6749. "0538 Slow-path MQ not allocated\n");
  6750. rc = -ENOMEM;
  6751. goto out_destroy_els_cq;
  6752. }
  6753. rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
  6754. phba->sli4_hba.mbx_cq, LPFC_MBOX);
  6755. if (rc) {
  6756. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6757. "0539 Failed setup of slow-path MQ: "
  6758. "rc = 0x%x\n", rc);
  6759. goto out_destroy_els_cq;
  6760. }
  6761. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6762. "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
  6763. phba->sli4_hba.mbx_wq->queue_id,
  6764. phba->sli4_hba.mbx_cq->queue_id);
  6765. /* Set up slow-path ELS Work Queue */
  6766. if (!phba->sli4_hba.els_wq) {
  6767. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6768. "0536 Slow-path ELS WQ not allocated\n");
  6769. rc = -ENOMEM;
  6770. goto out_destroy_mbx_wq;
  6771. }
  6772. rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
  6773. phba->sli4_hba.els_cq, LPFC_ELS);
  6774. if (rc) {
  6775. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6776. "0537 Failed setup of slow-path ELS WQ: "
  6777. "rc = 0x%x\n", rc);
  6778. goto out_destroy_mbx_wq;
  6779. }
  6780. /* Bind this WQ to the ELS ring */
  6781. pring = &psli->ring[LPFC_ELS_RING];
  6782. pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq;
  6783. phba->sli4_hba.els_cq->pring = pring;
  6784. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6785. "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
  6786. phba->sli4_hba.els_wq->queue_id,
  6787. phba->sli4_hba.els_cq->queue_id);
  6788. /*
  6789. * Create Receive Queue (RQ)
  6790. */
  6791. if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
  6792. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6793. "0540 Receive Queue not allocated\n");
  6794. rc = -ENOMEM;
  6795. goto out_destroy_els_wq;
  6796. }
  6797. lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
  6798. lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
  6799. rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  6800. phba->sli4_hba.els_cq, LPFC_USOL);
  6801. if (rc) {
  6802. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6803. "0541 Failed setup of Receive Queue: "
  6804. "rc = 0x%x\n", rc);
  6805. goto out_destroy_fcp_wq;
  6806. }
  6807. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6808. "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
  6809. "parent cq-id=%d\n",
  6810. phba->sli4_hba.hdr_rq->queue_id,
  6811. phba->sli4_hba.dat_rq->queue_id,
  6812. phba->sli4_hba.els_cq->queue_id);
  6813. return 0;
  6814. out_destroy_els_wq:
  6815. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  6816. out_destroy_mbx_wq:
  6817. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  6818. out_destroy_els_cq:
  6819. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  6820. out_destroy_mbx_cq:
  6821. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  6822. out_destroy_fcp_wq:
  6823. for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
  6824. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
  6825. out_destroy_fcp_cq:
  6826. for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
  6827. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
  6828. out_destroy_hba_eq:
  6829. for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
  6830. lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]);
  6831. out_error:
  6832. return rc;
  6833. }
  6834. /**
  6835. * lpfc_sli4_queue_unset - Unset all the SLI4 queues
  6836. * @phba: pointer to lpfc hba data structure.
  6837. *
  6838. * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
  6839. * operation.
  6840. *
  6841. * Return codes
  6842. * 0 - successful
  6843. * -ENOMEM - No available memory
  6844. * -EIO - The mailbox failed to complete successfully.
  6845. **/
  6846. void
  6847. lpfc_sli4_queue_unset(struct lpfc_hba *phba)
  6848. {
  6849. int fcp_qidx;
  6850. /* Unset mailbox command work queue */
  6851. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  6852. /* Unset ELS work queue */
  6853. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  6854. /* Unset unsolicited receive queue */
  6855. lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
  6856. /* Unset FCP work queue */
  6857. if (phba->sli4_hba.fcp_wq) {
  6858. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
  6859. fcp_qidx++)
  6860. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
  6861. }
  6862. /* Unset mailbox command complete queue */
  6863. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  6864. /* Unset ELS complete queue */
  6865. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  6866. /* Unset FCP response complete queue */
  6867. if (phba->sli4_hba.fcp_cq) {
  6868. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
  6869. fcp_qidx++)
  6870. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
  6871. }
  6872. /* Unset fast-path event queue */
  6873. if (phba->sli4_hba.hba_eq) {
  6874. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
  6875. fcp_qidx++)
  6876. lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]);
  6877. }
  6878. }
  6879. /**
  6880. * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
  6881. * @phba: pointer to lpfc hba data structure.
  6882. *
  6883. * This routine is invoked to allocate and set up a pool of completion queue
  6884. * events. The body of the completion queue event is a completion queue entry
  6885. * CQE. For now, this pool is used for the interrupt service routine to queue
  6886. * the following HBA completion queue events for the worker thread to process:
  6887. * - Mailbox asynchronous events
  6888. * - Receive queue completion unsolicited events
  6889. * Later, this can be used for all the slow-path events.
  6890. *
  6891. * Return codes
  6892. * 0 - successful
  6893. * -ENOMEM - No available memory
  6894. **/
  6895. static int
  6896. lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
  6897. {
  6898. struct lpfc_cq_event *cq_event;
  6899. int i;
  6900. for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
  6901. cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
  6902. if (!cq_event)
  6903. goto out_pool_create_fail;
  6904. list_add_tail(&cq_event->list,
  6905. &phba->sli4_hba.sp_cqe_event_pool);
  6906. }
  6907. return 0;
  6908. out_pool_create_fail:
  6909. lpfc_sli4_cq_event_pool_destroy(phba);
  6910. return -ENOMEM;
  6911. }
  6912. /**
  6913. * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
  6914. * @phba: pointer to lpfc hba data structure.
  6915. *
  6916. * This routine is invoked to free the pool of completion queue events at
  6917. * driver unload time. Note that, it is the responsibility of the driver
  6918. * cleanup routine to free all the outstanding completion-queue events
  6919. * allocated from this pool back into the pool before invoking this routine
  6920. * to destroy the pool.
  6921. **/
  6922. static void
  6923. lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
  6924. {
  6925. struct lpfc_cq_event *cq_event, *next_cq_event;
  6926. list_for_each_entry_safe(cq_event, next_cq_event,
  6927. &phba->sli4_hba.sp_cqe_event_pool, list) {
  6928. list_del(&cq_event->list);
  6929. kfree(cq_event);
  6930. }
  6931. }
  6932. /**
  6933. * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  6934. * @phba: pointer to lpfc hba data structure.
  6935. *
  6936. * This routine is the lock free version of the API invoked to allocate a
  6937. * completion-queue event from the free pool.
  6938. *
  6939. * Return: Pointer to the newly allocated completion-queue event if successful
  6940. * NULL otherwise.
  6941. **/
  6942. struct lpfc_cq_event *
  6943. __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  6944. {
  6945. struct lpfc_cq_event *cq_event = NULL;
  6946. list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
  6947. struct lpfc_cq_event, list);
  6948. return cq_event;
  6949. }
  6950. /**
  6951. * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  6952. * @phba: pointer to lpfc hba data structure.
  6953. *
  6954. * This routine is the lock version of the API invoked to allocate a
  6955. * completion-queue event from the free pool.
  6956. *
  6957. * Return: Pointer to the newly allocated completion-queue event if successful
  6958. * NULL otherwise.
  6959. **/
  6960. struct lpfc_cq_event *
  6961. lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  6962. {
  6963. struct lpfc_cq_event *cq_event;
  6964. unsigned long iflags;
  6965. spin_lock_irqsave(&phba->hbalock, iflags);
  6966. cq_event = __lpfc_sli4_cq_event_alloc(phba);
  6967. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6968. return cq_event;
  6969. }
  6970. /**
  6971. * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  6972. * @phba: pointer to lpfc hba data structure.
  6973. * @cq_event: pointer to the completion queue event to be freed.
  6974. *
  6975. * This routine is the lock free version of the API invoked to release a
  6976. * completion-queue event back into the free pool.
  6977. **/
  6978. void
  6979. __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  6980. struct lpfc_cq_event *cq_event)
  6981. {
  6982. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
  6983. }
  6984. /**
  6985. * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  6986. * @phba: pointer to lpfc hba data structure.
  6987. * @cq_event: pointer to the completion queue event to be freed.
  6988. *
  6989. * This routine is the lock version of the API invoked to release a
  6990. * completion-queue event back into the free pool.
  6991. **/
  6992. void
  6993. lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  6994. struct lpfc_cq_event *cq_event)
  6995. {
  6996. unsigned long iflags;
  6997. spin_lock_irqsave(&phba->hbalock, iflags);
  6998. __lpfc_sli4_cq_event_release(phba, cq_event);
  6999. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7000. }
  7001. /**
  7002. * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
  7003. * @phba: pointer to lpfc hba data structure.
  7004. *
  7005. * This routine is to free all the pending completion-queue events to the
  7006. * back into the free pool for device reset.
  7007. **/
  7008. static void
  7009. lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
  7010. {
  7011. LIST_HEAD(cqelist);
  7012. struct lpfc_cq_event *cqe;
  7013. unsigned long iflags;
  7014. /* Retrieve all the pending WCQEs from pending WCQE lists */
  7015. spin_lock_irqsave(&phba->hbalock, iflags);
  7016. /* Pending FCP XRI abort events */
  7017. list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7018. &cqelist);
  7019. /* Pending ELS XRI abort events */
  7020. list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7021. &cqelist);
  7022. /* Pending asynnc events */
  7023. list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
  7024. &cqelist);
  7025. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7026. while (!list_empty(&cqelist)) {
  7027. list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
  7028. lpfc_sli4_cq_event_release(phba, cqe);
  7029. }
  7030. }
  7031. /**
  7032. * lpfc_pci_function_reset - Reset pci function.
  7033. * @phba: pointer to lpfc hba data structure.
  7034. *
  7035. * This routine is invoked to request a PCI function reset. It will destroys
  7036. * all resources assigned to the PCI function which originates this request.
  7037. *
  7038. * Return codes
  7039. * 0 - successful
  7040. * -ENOMEM - No available memory
  7041. * -EIO - The mailbox failed to complete successfully.
  7042. **/
  7043. int
  7044. lpfc_pci_function_reset(struct lpfc_hba *phba)
  7045. {
  7046. LPFC_MBOXQ_t *mboxq;
  7047. uint32_t rc = 0, if_type;
  7048. uint32_t shdr_status, shdr_add_status;
  7049. uint32_t rdy_chk, num_resets = 0, reset_again = 0;
  7050. union lpfc_sli4_cfg_shdr *shdr;
  7051. struct lpfc_register reg_data;
  7052. uint16_t devid;
  7053. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7054. switch (if_type) {
  7055. case LPFC_SLI_INTF_IF_TYPE_0:
  7056. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  7057. GFP_KERNEL);
  7058. if (!mboxq) {
  7059. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7060. "0494 Unable to allocate memory for "
  7061. "issuing SLI_FUNCTION_RESET mailbox "
  7062. "command\n");
  7063. return -ENOMEM;
  7064. }
  7065. /* Setup PCI function reset mailbox-ioctl command */
  7066. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  7067. LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
  7068. LPFC_SLI4_MBX_EMBED);
  7069. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7070. shdr = (union lpfc_sli4_cfg_shdr *)
  7071. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  7072. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  7073. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  7074. &shdr->response);
  7075. if (rc != MBX_TIMEOUT)
  7076. mempool_free(mboxq, phba->mbox_mem_pool);
  7077. if (shdr_status || shdr_add_status || rc) {
  7078. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7079. "0495 SLI_FUNCTION_RESET mailbox "
  7080. "failed with status x%x add_status x%x,"
  7081. " mbx status x%x\n",
  7082. shdr_status, shdr_add_status, rc);
  7083. rc = -ENXIO;
  7084. }
  7085. break;
  7086. case LPFC_SLI_INTF_IF_TYPE_2:
  7087. for (num_resets = 0;
  7088. num_resets < MAX_IF_TYPE_2_RESETS;
  7089. num_resets++) {
  7090. reg_data.word0 = 0;
  7091. bf_set(lpfc_sliport_ctrl_end, &reg_data,
  7092. LPFC_SLIPORT_LITTLE_ENDIAN);
  7093. bf_set(lpfc_sliport_ctrl_ip, &reg_data,
  7094. LPFC_SLIPORT_INIT_PORT);
  7095. writel(reg_data.word0, phba->sli4_hba.u.if_type2.
  7096. CTRLregaddr);
  7097. /* flush */
  7098. pci_read_config_word(phba->pcidev,
  7099. PCI_DEVICE_ID, &devid);
  7100. /*
  7101. * Poll the Port Status Register and wait for RDY for
  7102. * up to 10 seconds. If the port doesn't respond, treat
  7103. * it as an error. If the port responds with RN, start
  7104. * the loop again.
  7105. */
  7106. for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) {
  7107. msleep(10);
  7108. if (lpfc_readl(phba->sli4_hba.u.if_type2.
  7109. STATUSregaddr, &reg_data.word0)) {
  7110. rc = -ENODEV;
  7111. goto out;
  7112. }
  7113. if (bf_get(lpfc_sliport_status_rn, &reg_data))
  7114. reset_again++;
  7115. if (bf_get(lpfc_sliport_status_rdy, &reg_data))
  7116. break;
  7117. }
  7118. /*
  7119. * If the port responds to the init request with
  7120. * reset needed, delay for a bit and restart the loop.
  7121. */
  7122. if (reset_again && (rdy_chk < 1000)) {
  7123. msleep(10);
  7124. reset_again = 0;
  7125. continue;
  7126. }
  7127. /* Detect any port errors. */
  7128. if ((bf_get(lpfc_sliport_status_err, &reg_data)) ||
  7129. (rdy_chk >= 1000)) {
  7130. phba->work_status[0] = readl(
  7131. phba->sli4_hba.u.if_type2.ERR1regaddr);
  7132. phba->work_status[1] = readl(
  7133. phba->sli4_hba.u.if_type2.ERR2regaddr);
  7134. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7135. "2890 Port error detected during port "
  7136. "reset(%d): wait_tmo:%d ms, "
  7137. "port status reg 0x%x, "
  7138. "error 1=0x%x, error 2=0x%x\n",
  7139. num_resets, rdy_chk*10,
  7140. reg_data.word0,
  7141. phba->work_status[0],
  7142. phba->work_status[1]);
  7143. rc = -ENODEV;
  7144. }
  7145. /*
  7146. * Terminate the outer loop provided the Port indicated
  7147. * ready within 10 seconds.
  7148. */
  7149. if (rdy_chk < 1000)
  7150. break;
  7151. }
  7152. /* delay driver action following IF_TYPE_2 function reset */
  7153. msleep(100);
  7154. break;
  7155. case LPFC_SLI_INTF_IF_TYPE_1:
  7156. default:
  7157. break;
  7158. }
  7159. out:
  7160. /* Catch the not-ready port failure after a port reset. */
  7161. if (num_resets >= MAX_IF_TYPE_2_RESETS) {
  7162. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7163. "3317 HBA not functional: IP Reset Failed "
  7164. "after (%d) retries, try: "
  7165. "echo fw_reset > board_mode\n", num_resets);
  7166. rc = -ENODEV;
  7167. }
  7168. return rc;
  7169. }
  7170. /**
  7171. * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
  7172. * @phba: pointer to lpfc hba data structure.
  7173. *
  7174. * This routine is invoked to set up the PCI device memory space for device
  7175. * with SLI-4 interface spec.
  7176. *
  7177. * Return codes
  7178. * 0 - successful
  7179. * other values - error
  7180. **/
  7181. static int
  7182. lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
  7183. {
  7184. struct pci_dev *pdev;
  7185. unsigned long bar0map_len, bar1map_len, bar2map_len;
  7186. int error = -ENODEV;
  7187. uint32_t if_type;
  7188. /* Obtain PCI device reference */
  7189. if (!phba->pcidev)
  7190. return error;
  7191. else
  7192. pdev = phba->pcidev;
  7193. /* Set the device DMA mask size */
  7194. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
  7195. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
  7196. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
  7197. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
  7198. return error;
  7199. }
  7200. }
  7201. /*
  7202. * The BARs and register set definitions and offset locations are
  7203. * dependent on the if_type.
  7204. */
  7205. if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
  7206. &phba->sli4_hba.sli_intf.word0)) {
  7207. return error;
  7208. }
  7209. /* There is no SLI3 failback for SLI4 devices. */
  7210. if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
  7211. LPFC_SLI_INTF_VALID) {
  7212. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7213. "2894 SLI_INTF reg contents invalid "
  7214. "sli_intf reg 0x%x\n",
  7215. phba->sli4_hba.sli_intf.word0);
  7216. return error;
  7217. }
  7218. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7219. /*
  7220. * Get the bus address of SLI4 device Bar regions and the
  7221. * number of bytes required by each mapping. The mapping of the
  7222. * particular PCI BARs regions is dependent on the type of
  7223. * SLI4 device.
  7224. */
  7225. if (pci_resource_start(pdev, 0)) {
  7226. phba->pci_bar0_map = pci_resource_start(pdev, 0);
  7227. bar0map_len = pci_resource_len(pdev, 0);
  7228. /*
  7229. * Map SLI4 PCI Config Space Register base to a kernel virtual
  7230. * addr
  7231. */
  7232. phba->sli4_hba.conf_regs_memmap_p =
  7233. ioremap(phba->pci_bar0_map, bar0map_len);
  7234. if (!phba->sli4_hba.conf_regs_memmap_p) {
  7235. dev_printk(KERN_ERR, &pdev->dev,
  7236. "ioremap failed for SLI4 PCI config "
  7237. "registers.\n");
  7238. goto out;
  7239. }
  7240. /* Set up BAR0 PCI config space register memory map */
  7241. lpfc_sli4_bar0_register_memmap(phba, if_type);
  7242. } else {
  7243. phba->pci_bar0_map = pci_resource_start(pdev, 1);
  7244. bar0map_len = pci_resource_len(pdev, 1);
  7245. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7246. dev_printk(KERN_ERR, &pdev->dev,
  7247. "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
  7248. goto out;
  7249. }
  7250. phba->sli4_hba.conf_regs_memmap_p =
  7251. ioremap(phba->pci_bar0_map, bar0map_len);
  7252. if (!phba->sli4_hba.conf_regs_memmap_p) {
  7253. dev_printk(KERN_ERR, &pdev->dev,
  7254. "ioremap failed for SLI4 PCI config "
  7255. "registers.\n");
  7256. goto out;
  7257. }
  7258. lpfc_sli4_bar0_register_memmap(phba, if_type);
  7259. }
  7260. if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
  7261. (pci_resource_start(pdev, 2))) {
  7262. /*
  7263. * Map SLI4 if type 0 HBA Control Register base to a kernel
  7264. * virtual address and setup the registers.
  7265. */
  7266. phba->pci_bar1_map = pci_resource_start(pdev, 2);
  7267. bar1map_len = pci_resource_len(pdev, 2);
  7268. phba->sli4_hba.ctrl_regs_memmap_p =
  7269. ioremap(phba->pci_bar1_map, bar1map_len);
  7270. if (!phba->sli4_hba.ctrl_regs_memmap_p) {
  7271. dev_printk(KERN_ERR, &pdev->dev,
  7272. "ioremap failed for SLI4 HBA control registers.\n");
  7273. goto out_iounmap_conf;
  7274. }
  7275. lpfc_sli4_bar1_register_memmap(phba);
  7276. }
  7277. if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
  7278. (pci_resource_start(pdev, 4))) {
  7279. /*
  7280. * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
  7281. * virtual address and setup the registers.
  7282. */
  7283. phba->pci_bar2_map = pci_resource_start(pdev, 4);
  7284. bar2map_len = pci_resource_len(pdev, 4);
  7285. phba->sli4_hba.drbl_regs_memmap_p =
  7286. ioremap(phba->pci_bar2_map, bar2map_len);
  7287. if (!phba->sli4_hba.drbl_regs_memmap_p) {
  7288. dev_printk(KERN_ERR, &pdev->dev,
  7289. "ioremap failed for SLI4 HBA doorbell registers.\n");
  7290. goto out_iounmap_ctrl;
  7291. }
  7292. error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
  7293. if (error)
  7294. goto out_iounmap_all;
  7295. }
  7296. return 0;
  7297. out_iounmap_all:
  7298. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  7299. out_iounmap_ctrl:
  7300. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  7301. out_iounmap_conf:
  7302. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  7303. out:
  7304. return error;
  7305. }
  7306. /**
  7307. * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
  7308. * @phba: pointer to lpfc hba data structure.
  7309. *
  7310. * This routine is invoked to unset the PCI device memory space for device
  7311. * with SLI-4 interface spec.
  7312. **/
  7313. static void
  7314. lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
  7315. {
  7316. uint32_t if_type;
  7317. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7318. switch (if_type) {
  7319. case LPFC_SLI_INTF_IF_TYPE_0:
  7320. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  7321. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  7322. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  7323. break;
  7324. case LPFC_SLI_INTF_IF_TYPE_2:
  7325. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  7326. break;
  7327. case LPFC_SLI_INTF_IF_TYPE_1:
  7328. default:
  7329. dev_printk(KERN_ERR, &phba->pcidev->dev,
  7330. "FATAL - unsupported SLI4 interface type - %d\n",
  7331. if_type);
  7332. break;
  7333. }
  7334. }
  7335. /**
  7336. * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
  7337. * @phba: pointer to lpfc hba data structure.
  7338. *
  7339. * This routine is invoked to enable the MSI-X interrupt vectors to device
  7340. * with SLI-3 interface specs. The kernel function pci_enable_msix() is
  7341. * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
  7342. * invoked, enables either all or nothing, depending on the current
  7343. * availability of PCI vector resources. The device driver is responsible
  7344. * for calling the individual request_irq() to register each MSI-X vector
  7345. * with a interrupt handler, which is done in this function. Note that
  7346. * later when device is unloading, the driver should always call free_irq()
  7347. * on all MSI-X vectors it has done request_irq() on before calling
  7348. * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
  7349. * will be left with MSI-X enabled and leaks its vectors.
  7350. *
  7351. * Return codes
  7352. * 0 - successful
  7353. * other values - error
  7354. **/
  7355. static int
  7356. lpfc_sli_enable_msix(struct lpfc_hba *phba)
  7357. {
  7358. int rc, i;
  7359. LPFC_MBOXQ_t *pmb;
  7360. /* Set up MSI-X multi-message vectors */
  7361. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  7362. phba->msix_entries[i].entry = i;
  7363. /* Configure MSI-X capability structure */
  7364. rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
  7365. ARRAY_SIZE(phba->msix_entries));
  7366. if (rc) {
  7367. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7368. "0420 PCI enable MSI-X failed (%d)\n", rc);
  7369. goto msi_fail_out;
  7370. }
  7371. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  7372. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7373. "0477 MSI-X entry[%d]: vector=x%x "
  7374. "message=%d\n", i,
  7375. phba->msix_entries[i].vector,
  7376. phba->msix_entries[i].entry);
  7377. /*
  7378. * Assign MSI-X vectors to interrupt handlers
  7379. */
  7380. /* vector-0 is associated to slow-path handler */
  7381. rc = request_irq(phba->msix_entries[0].vector,
  7382. &lpfc_sli_sp_intr_handler, IRQF_SHARED,
  7383. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  7384. if (rc) {
  7385. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7386. "0421 MSI-X slow-path request_irq failed "
  7387. "(%d)\n", rc);
  7388. goto msi_fail_out;
  7389. }
  7390. /* vector-1 is associated to fast-path handler */
  7391. rc = request_irq(phba->msix_entries[1].vector,
  7392. &lpfc_sli_fp_intr_handler, IRQF_SHARED,
  7393. LPFC_FP_DRIVER_HANDLER_NAME, phba);
  7394. if (rc) {
  7395. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7396. "0429 MSI-X fast-path request_irq failed "
  7397. "(%d)\n", rc);
  7398. goto irq_fail_out;
  7399. }
  7400. /*
  7401. * Configure HBA MSI-X attention conditions to messages
  7402. */
  7403. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  7404. if (!pmb) {
  7405. rc = -ENOMEM;
  7406. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7407. "0474 Unable to allocate memory for issuing "
  7408. "MBOX_CONFIG_MSI command\n");
  7409. goto mem_fail_out;
  7410. }
  7411. rc = lpfc_config_msi(phba, pmb);
  7412. if (rc)
  7413. goto mbx_fail_out;
  7414. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  7415. if (rc != MBX_SUCCESS) {
  7416. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  7417. "0351 Config MSI mailbox command failed, "
  7418. "mbxCmd x%x, mbxStatus x%x\n",
  7419. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
  7420. goto mbx_fail_out;
  7421. }
  7422. /* Free memory allocated for mailbox command */
  7423. mempool_free(pmb, phba->mbox_mem_pool);
  7424. return rc;
  7425. mbx_fail_out:
  7426. /* Free memory allocated for mailbox command */
  7427. mempool_free(pmb, phba->mbox_mem_pool);
  7428. mem_fail_out:
  7429. /* free the irq already requested */
  7430. free_irq(phba->msix_entries[1].vector, phba);
  7431. irq_fail_out:
  7432. /* free the irq already requested */
  7433. free_irq(phba->msix_entries[0].vector, phba);
  7434. msi_fail_out:
  7435. /* Unconfigure MSI-X capability structure */
  7436. pci_disable_msix(phba->pcidev);
  7437. return rc;
  7438. }
  7439. /**
  7440. * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
  7441. * @phba: pointer to lpfc hba data structure.
  7442. *
  7443. * This routine is invoked to release the MSI-X vectors and then disable the
  7444. * MSI-X interrupt mode to device with SLI-3 interface spec.
  7445. **/
  7446. static void
  7447. lpfc_sli_disable_msix(struct lpfc_hba *phba)
  7448. {
  7449. int i;
  7450. /* Free up MSI-X multi-message vectors */
  7451. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  7452. free_irq(phba->msix_entries[i].vector, phba);
  7453. /* Disable MSI-X */
  7454. pci_disable_msix(phba->pcidev);
  7455. return;
  7456. }
  7457. /**
  7458. * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
  7459. * @phba: pointer to lpfc hba data structure.
  7460. *
  7461. * This routine is invoked to enable the MSI interrupt mode to device with
  7462. * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
  7463. * enable the MSI vector. The device driver is responsible for calling the
  7464. * request_irq() to register MSI vector with a interrupt the handler, which
  7465. * is done in this function.
  7466. *
  7467. * Return codes
  7468. * 0 - successful
  7469. * other values - error
  7470. */
  7471. static int
  7472. lpfc_sli_enable_msi(struct lpfc_hba *phba)
  7473. {
  7474. int rc;
  7475. rc = pci_enable_msi(phba->pcidev);
  7476. if (!rc)
  7477. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7478. "0462 PCI enable MSI mode success.\n");
  7479. else {
  7480. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7481. "0471 PCI enable MSI mode failed (%d)\n", rc);
  7482. return rc;
  7483. }
  7484. rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  7485. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  7486. if (rc) {
  7487. pci_disable_msi(phba->pcidev);
  7488. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7489. "0478 MSI request_irq failed (%d)\n", rc);
  7490. }
  7491. return rc;
  7492. }
  7493. /**
  7494. * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
  7495. * @phba: pointer to lpfc hba data structure.
  7496. *
  7497. * This routine is invoked to disable the MSI interrupt mode to device with
  7498. * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
  7499. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  7500. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  7501. * its vector.
  7502. */
  7503. static void
  7504. lpfc_sli_disable_msi(struct lpfc_hba *phba)
  7505. {
  7506. free_irq(phba->pcidev->irq, phba);
  7507. pci_disable_msi(phba->pcidev);
  7508. return;
  7509. }
  7510. /**
  7511. * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
  7512. * @phba: pointer to lpfc hba data structure.
  7513. *
  7514. * This routine is invoked to enable device interrupt and associate driver's
  7515. * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
  7516. * spec. Depends on the interrupt mode configured to the driver, the driver
  7517. * will try to fallback from the configured interrupt mode to an interrupt
  7518. * mode which is supported by the platform, kernel, and device in the order
  7519. * of:
  7520. * MSI-X -> MSI -> IRQ.
  7521. *
  7522. * Return codes
  7523. * 0 - successful
  7524. * other values - error
  7525. **/
  7526. static uint32_t
  7527. lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  7528. {
  7529. uint32_t intr_mode = LPFC_INTR_ERROR;
  7530. int retval;
  7531. if (cfg_mode == 2) {
  7532. /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
  7533. retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
  7534. if (!retval) {
  7535. /* Now, try to enable MSI-X interrupt mode */
  7536. retval = lpfc_sli_enable_msix(phba);
  7537. if (!retval) {
  7538. /* Indicate initialization to MSI-X mode */
  7539. phba->intr_type = MSIX;
  7540. intr_mode = 2;
  7541. }
  7542. }
  7543. }
  7544. /* Fallback to MSI if MSI-X initialization failed */
  7545. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  7546. retval = lpfc_sli_enable_msi(phba);
  7547. if (!retval) {
  7548. /* Indicate initialization to MSI mode */
  7549. phba->intr_type = MSI;
  7550. intr_mode = 1;
  7551. }
  7552. }
  7553. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  7554. if (phba->intr_type == NONE) {
  7555. retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  7556. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  7557. if (!retval) {
  7558. /* Indicate initialization to INTx mode */
  7559. phba->intr_type = INTx;
  7560. intr_mode = 0;
  7561. }
  7562. }
  7563. return intr_mode;
  7564. }
  7565. /**
  7566. * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
  7567. * @phba: pointer to lpfc hba data structure.
  7568. *
  7569. * This routine is invoked to disable device interrupt and disassociate the
  7570. * driver's interrupt handler(s) from interrupt vector(s) to device with
  7571. * SLI-3 interface spec. Depending on the interrupt mode, the driver will
  7572. * release the interrupt vector(s) for the message signaled interrupt.
  7573. **/
  7574. static void
  7575. lpfc_sli_disable_intr(struct lpfc_hba *phba)
  7576. {
  7577. /* Disable the currently initialized interrupt mode */
  7578. if (phba->intr_type == MSIX)
  7579. lpfc_sli_disable_msix(phba);
  7580. else if (phba->intr_type == MSI)
  7581. lpfc_sli_disable_msi(phba);
  7582. else if (phba->intr_type == INTx)
  7583. free_irq(phba->pcidev->irq, phba);
  7584. /* Reset interrupt management states */
  7585. phba->intr_type = NONE;
  7586. phba->sli.slistat.sli_intr = 0;
  7587. return;
  7588. }
  7589. /**
  7590. * lpfc_find_next_cpu - Find next available CPU that matches the phys_id
  7591. * @phba: pointer to lpfc hba data structure.
  7592. *
  7593. * Find next available CPU to use for IRQ to CPU affinity.
  7594. */
  7595. static int
  7596. lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id)
  7597. {
  7598. struct lpfc_vector_map_info *cpup;
  7599. int cpu;
  7600. cpup = phba->sli4_hba.cpu_map;
  7601. for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
  7602. /* CPU must be online */
  7603. if (cpu_online(cpu)) {
  7604. if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
  7605. (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) &&
  7606. (cpup->phys_id == phys_id)) {
  7607. return cpu;
  7608. }
  7609. }
  7610. cpup++;
  7611. }
  7612. /*
  7613. * If we get here, we have used ALL CPUs for the specific
  7614. * phys_id. Now we need to clear out lpfc_used_cpu and start
  7615. * reusing CPUs.
  7616. */
  7617. for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
  7618. if (lpfc_used_cpu[cpu] == phys_id)
  7619. lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY;
  7620. }
  7621. cpup = phba->sli4_hba.cpu_map;
  7622. for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
  7623. /* CPU must be online */
  7624. if (cpu_online(cpu)) {
  7625. if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
  7626. (cpup->phys_id == phys_id)) {
  7627. return cpu;
  7628. }
  7629. }
  7630. cpup++;
  7631. }
  7632. return LPFC_VECTOR_MAP_EMPTY;
  7633. }
  7634. /**
  7635. * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors
  7636. * @phba: pointer to lpfc hba data structure.
  7637. * @vectors: number of HBA vectors
  7638. *
  7639. * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector
  7640. * affinization across multple physical CPUs (numa nodes).
  7641. * In addition, this routine will assign an IO channel for each CPU
  7642. * to use when issuing I/Os.
  7643. */
  7644. static int
  7645. lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors)
  7646. {
  7647. int i, idx, saved_chann, used_chann, cpu, phys_id;
  7648. int max_phys_id, num_io_channel, first_cpu;
  7649. struct lpfc_vector_map_info *cpup;
  7650. #ifdef CONFIG_X86
  7651. struct cpuinfo_x86 *cpuinfo;
  7652. #endif
  7653. struct cpumask *mask;
  7654. uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1];
  7655. /* If there is no mapping, just return */
  7656. if (!phba->cfg_fcp_cpu_map)
  7657. return 1;
  7658. /* Init cpu_map array */
  7659. memset(phba->sli4_hba.cpu_map, 0xff,
  7660. (sizeof(struct lpfc_vector_map_info) *
  7661. phba->sli4_hba.num_present_cpu));
  7662. max_phys_id = 0;
  7663. phys_id = 0;
  7664. num_io_channel = 0;
  7665. first_cpu = LPFC_VECTOR_MAP_EMPTY;
  7666. /* Update CPU map with physical id and core id of each CPU */
  7667. cpup = phba->sli4_hba.cpu_map;
  7668. for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
  7669. #ifdef CONFIG_X86
  7670. cpuinfo = &cpu_data(cpu);
  7671. cpup->phys_id = cpuinfo->phys_proc_id;
  7672. cpup->core_id = cpuinfo->cpu_core_id;
  7673. #else
  7674. /* No distinction between CPUs for other platforms */
  7675. cpup->phys_id = 0;
  7676. cpup->core_id = 0;
  7677. #endif
  7678. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7679. "3328 CPU physid %d coreid %d\n",
  7680. cpup->phys_id, cpup->core_id);
  7681. if (cpup->phys_id > max_phys_id)
  7682. max_phys_id = cpup->phys_id;
  7683. cpup++;
  7684. }
  7685. /* Now associate the HBA vectors with specific CPUs */
  7686. for (idx = 0; idx < vectors; idx++) {
  7687. cpup = phba->sli4_hba.cpu_map;
  7688. cpu = lpfc_find_next_cpu(phba, phys_id);
  7689. if (cpu == LPFC_VECTOR_MAP_EMPTY) {
  7690. /* Try for all phys_id's */
  7691. for (i = 1; i < max_phys_id; i++) {
  7692. phys_id++;
  7693. if (phys_id > max_phys_id)
  7694. phys_id = 0;
  7695. cpu = lpfc_find_next_cpu(phba, phys_id);
  7696. if (cpu == LPFC_VECTOR_MAP_EMPTY)
  7697. continue;
  7698. goto found;
  7699. }
  7700. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7701. "3329 Cannot set affinity:"
  7702. "Error mapping vector %d (%d)\n",
  7703. idx, vectors);
  7704. return 0;
  7705. }
  7706. found:
  7707. cpup += cpu;
  7708. if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP)
  7709. lpfc_used_cpu[cpu] = phys_id;
  7710. /* Associate vector with selected CPU */
  7711. cpup->irq = phba->sli4_hba.msix_entries[idx].vector;
  7712. /* Associate IO channel with selected CPU */
  7713. cpup->channel_id = idx;
  7714. num_io_channel++;
  7715. if (first_cpu == LPFC_VECTOR_MAP_EMPTY)
  7716. first_cpu = cpu;
  7717. /* Now affinitize to the selected CPU */
  7718. mask = &cpup->maskbits;
  7719. cpumask_clear(mask);
  7720. cpumask_set_cpu(cpu, mask);
  7721. i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx].
  7722. vector, mask);
  7723. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7724. "3330 Set Affinity: CPU %d channel %d "
  7725. "irq %d (%x)\n",
  7726. cpu, cpup->channel_id,
  7727. phba->sli4_hba.msix_entries[idx].vector, i);
  7728. /* Spread vector mapping across multple physical CPU nodes */
  7729. phys_id++;
  7730. if (phys_id > max_phys_id)
  7731. phys_id = 0;
  7732. }
  7733. /*
  7734. * Finally fill in the IO channel for any remaining CPUs.
  7735. * At this point, all IO channels have been assigned to a specific
  7736. * MSIx vector, mapped to a specific CPU.
  7737. * Base the remaining IO channel assigned, to IO channels already
  7738. * assigned to other CPUs on the same phys_id.
  7739. */
  7740. for (i = 0; i <= max_phys_id; i++) {
  7741. /*
  7742. * If there are no io channels already mapped to
  7743. * this phys_id, just round robin thru the io_channels.
  7744. * Setup chann[] for round robin.
  7745. */
  7746. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
  7747. chann[idx] = idx;
  7748. saved_chann = 0;
  7749. used_chann = 0;
  7750. /*
  7751. * First build a list of IO channels already assigned
  7752. * to this phys_id before reassigning the same IO
  7753. * channels to the remaining CPUs.
  7754. */
  7755. cpup = phba->sli4_hba.cpu_map;
  7756. cpu = first_cpu;
  7757. cpup += cpu;
  7758. for (idx = 0; idx < phba->sli4_hba.num_present_cpu;
  7759. idx++) {
  7760. if (cpup->phys_id == i) {
  7761. /*
  7762. * Save any IO channels that are
  7763. * already mapped to this phys_id.
  7764. */
  7765. if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) {
  7766. chann[saved_chann] =
  7767. cpup->channel_id;
  7768. saved_chann++;
  7769. goto out;
  7770. }
  7771. /* See if we are using round-robin */
  7772. if (saved_chann == 0)
  7773. saved_chann =
  7774. phba->cfg_fcp_io_channel;
  7775. /* Associate next IO channel with CPU */
  7776. cpup->channel_id = chann[used_chann];
  7777. num_io_channel++;
  7778. used_chann++;
  7779. if (used_chann == saved_chann)
  7780. used_chann = 0;
  7781. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7782. "3331 Set IO_CHANN "
  7783. "CPU %d channel %d\n",
  7784. idx, cpup->channel_id);
  7785. }
  7786. out:
  7787. cpu++;
  7788. if (cpu >= phba->sli4_hba.num_present_cpu) {
  7789. cpup = phba->sli4_hba.cpu_map;
  7790. cpu = 0;
  7791. } else {
  7792. cpup++;
  7793. }
  7794. }
  7795. }
  7796. if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) {
  7797. cpup = phba->sli4_hba.cpu_map;
  7798. for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) {
  7799. if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) {
  7800. cpup->channel_id = 0;
  7801. num_io_channel++;
  7802. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7803. "3332 Assign IO_CHANN "
  7804. "CPU %d channel %d\n",
  7805. idx, cpup->channel_id);
  7806. }
  7807. cpup++;
  7808. }
  7809. }
  7810. /* Sanity check */
  7811. if (num_io_channel != phba->sli4_hba.num_present_cpu)
  7812. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7813. "3333 Set affinity mismatch:"
  7814. "%d chann != %d cpus: %d vactors\n",
  7815. num_io_channel, phba->sli4_hba.num_present_cpu,
  7816. vectors);
  7817. phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU;
  7818. return 1;
  7819. }
  7820. /**
  7821. * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
  7822. * @phba: pointer to lpfc hba data structure.
  7823. *
  7824. * This routine is invoked to enable the MSI-X interrupt vectors to device
  7825. * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
  7826. * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
  7827. * enables either all or nothing, depending on the current availability of
  7828. * PCI vector resources. The device driver is responsible for calling the
  7829. * individual request_irq() to register each MSI-X vector with a interrupt
  7830. * handler, which is done in this function. Note that later when device is
  7831. * unloading, the driver should always call free_irq() on all MSI-X vectors
  7832. * it has done request_irq() on before calling pci_disable_msix(). Failure
  7833. * to do so results in a BUG_ON() and a device will be left with MSI-X
  7834. * enabled and leaks its vectors.
  7835. *
  7836. * Return codes
  7837. * 0 - successful
  7838. * other values - error
  7839. **/
  7840. static int
  7841. lpfc_sli4_enable_msix(struct lpfc_hba *phba)
  7842. {
  7843. int vectors, rc, index;
  7844. /* Set up MSI-X multi-message vectors */
  7845. for (index = 0; index < phba->cfg_fcp_io_channel; index++)
  7846. phba->sli4_hba.msix_entries[index].entry = index;
  7847. /* Configure MSI-X capability structure */
  7848. vectors = phba->cfg_fcp_io_channel;
  7849. enable_msix_vectors:
  7850. rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
  7851. vectors);
  7852. if (rc > 1) {
  7853. vectors = rc;
  7854. goto enable_msix_vectors;
  7855. } else if (rc) {
  7856. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7857. "0484 PCI enable MSI-X failed (%d)\n", rc);
  7858. goto msi_fail_out;
  7859. }
  7860. /* Log MSI-X vector assignment */
  7861. for (index = 0; index < vectors; index++)
  7862. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7863. "0489 MSI-X entry[%d]: vector=x%x "
  7864. "message=%d\n", index,
  7865. phba->sli4_hba.msix_entries[index].vector,
  7866. phba->sli4_hba.msix_entries[index].entry);
  7867. /* Assign MSI-X vectors to interrupt handlers */
  7868. for (index = 0; index < vectors; index++) {
  7869. memset(&phba->sli4_hba.handler_name[index], 0, 16);
  7870. sprintf((char *)&phba->sli4_hba.handler_name[index],
  7871. LPFC_DRIVER_HANDLER_NAME"%d", index);
  7872. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  7873. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  7874. atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1);
  7875. rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
  7876. &lpfc_sli4_hba_intr_handler, IRQF_SHARED,
  7877. (char *)&phba->sli4_hba.handler_name[index],
  7878. &phba->sli4_hba.fcp_eq_hdl[index]);
  7879. if (rc) {
  7880. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7881. "0486 MSI-X fast-path (%d) "
  7882. "request_irq failed (%d)\n", index, rc);
  7883. goto cfg_fail_out;
  7884. }
  7885. }
  7886. if (vectors != phba->cfg_fcp_io_channel) {
  7887. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7888. "3238 Reducing IO channels to match number of "
  7889. "MSI-X vectors, requested %d got %d\n",
  7890. phba->cfg_fcp_io_channel, vectors);
  7891. phba->cfg_fcp_io_channel = vectors;
  7892. }
  7893. lpfc_sli4_set_affinity(phba, vectors);
  7894. return rc;
  7895. cfg_fail_out:
  7896. /* free the irq already requested */
  7897. for (--index; index >= 0; index--)
  7898. free_irq(phba->sli4_hba.msix_entries[index].vector,
  7899. &phba->sli4_hba.fcp_eq_hdl[index]);
  7900. msi_fail_out:
  7901. /* Unconfigure MSI-X capability structure */
  7902. pci_disable_msix(phba->pcidev);
  7903. return rc;
  7904. }
  7905. /**
  7906. * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
  7907. * @phba: pointer to lpfc hba data structure.
  7908. *
  7909. * This routine is invoked to release the MSI-X vectors and then disable the
  7910. * MSI-X interrupt mode to device with SLI-4 interface spec.
  7911. **/
  7912. static void
  7913. lpfc_sli4_disable_msix(struct lpfc_hba *phba)
  7914. {
  7915. int index;
  7916. /* Free up MSI-X multi-message vectors */
  7917. for (index = 0; index < phba->cfg_fcp_io_channel; index++)
  7918. free_irq(phba->sli4_hba.msix_entries[index].vector,
  7919. &phba->sli4_hba.fcp_eq_hdl[index]);
  7920. /* Disable MSI-X */
  7921. pci_disable_msix(phba->pcidev);
  7922. return;
  7923. }
  7924. /**
  7925. * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
  7926. * @phba: pointer to lpfc hba data structure.
  7927. *
  7928. * This routine is invoked to enable the MSI interrupt mode to device with
  7929. * SLI-4 interface spec. The kernel function pci_enable_msi() is called
  7930. * to enable the MSI vector. The device driver is responsible for calling
  7931. * the request_irq() to register MSI vector with a interrupt the handler,
  7932. * which is done in this function.
  7933. *
  7934. * Return codes
  7935. * 0 - successful
  7936. * other values - error
  7937. **/
  7938. static int
  7939. lpfc_sli4_enable_msi(struct lpfc_hba *phba)
  7940. {
  7941. int rc, index;
  7942. rc = pci_enable_msi(phba->pcidev);
  7943. if (!rc)
  7944. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7945. "0487 PCI enable MSI mode success.\n");
  7946. else {
  7947. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7948. "0488 PCI enable MSI mode failed (%d)\n", rc);
  7949. return rc;
  7950. }
  7951. rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  7952. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  7953. if (rc) {
  7954. pci_disable_msi(phba->pcidev);
  7955. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7956. "0490 MSI request_irq failed (%d)\n", rc);
  7957. return rc;
  7958. }
  7959. for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
  7960. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  7961. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  7962. }
  7963. return 0;
  7964. }
  7965. /**
  7966. * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
  7967. * @phba: pointer to lpfc hba data structure.
  7968. *
  7969. * This routine is invoked to disable the MSI interrupt mode to device with
  7970. * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
  7971. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  7972. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  7973. * its vector.
  7974. **/
  7975. static void
  7976. lpfc_sli4_disable_msi(struct lpfc_hba *phba)
  7977. {
  7978. free_irq(phba->pcidev->irq, phba);
  7979. pci_disable_msi(phba->pcidev);
  7980. return;
  7981. }
  7982. /**
  7983. * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
  7984. * @phba: pointer to lpfc hba data structure.
  7985. *
  7986. * This routine is invoked to enable device interrupt and associate driver's
  7987. * interrupt handler(s) to interrupt vector(s) to device with SLI-4
  7988. * interface spec. Depends on the interrupt mode configured to the driver,
  7989. * the driver will try to fallback from the configured interrupt mode to an
  7990. * interrupt mode which is supported by the platform, kernel, and device in
  7991. * the order of:
  7992. * MSI-X -> MSI -> IRQ.
  7993. *
  7994. * Return codes
  7995. * 0 - successful
  7996. * other values - error
  7997. **/
  7998. static uint32_t
  7999. lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  8000. {
  8001. uint32_t intr_mode = LPFC_INTR_ERROR;
  8002. int retval, index;
  8003. if (cfg_mode == 2) {
  8004. /* Preparation before conf_msi mbox cmd */
  8005. retval = 0;
  8006. if (!retval) {
  8007. /* Now, try to enable MSI-X interrupt mode */
  8008. retval = lpfc_sli4_enable_msix(phba);
  8009. if (!retval) {
  8010. /* Indicate initialization to MSI-X mode */
  8011. phba->intr_type = MSIX;
  8012. intr_mode = 2;
  8013. }
  8014. }
  8015. }
  8016. /* Fallback to MSI if MSI-X initialization failed */
  8017. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  8018. retval = lpfc_sli4_enable_msi(phba);
  8019. if (!retval) {
  8020. /* Indicate initialization to MSI mode */
  8021. phba->intr_type = MSI;
  8022. intr_mode = 1;
  8023. }
  8024. }
  8025. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  8026. if (phba->intr_type == NONE) {
  8027. retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  8028. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  8029. if (!retval) {
  8030. /* Indicate initialization to INTx mode */
  8031. phba->intr_type = INTx;
  8032. intr_mode = 0;
  8033. for (index = 0; index < phba->cfg_fcp_io_channel;
  8034. index++) {
  8035. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  8036. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  8037. atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
  8038. fcp_eq_in_use, 1);
  8039. }
  8040. }
  8041. }
  8042. return intr_mode;
  8043. }
  8044. /**
  8045. * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
  8046. * @phba: pointer to lpfc hba data structure.
  8047. *
  8048. * This routine is invoked to disable device interrupt and disassociate
  8049. * the driver's interrupt handler(s) from interrupt vector(s) to device
  8050. * with SLI-4 interface spec. Depending on the interrupt mode, the driver
  8051. * will release the interrupt vector(s) for the message signaled interrupt.
  8052. **/
  8053. static void
  8054. lpfc_sli4_disable_intr(struct lpfc_hba *phba)
  8055. {
  8056. /* Disable the currently initialized interrupt mode */
  8057. if (phba->intr_type == MSIX)
  8058. lpfc_sli4_disable_msix(phba);
  8059. else if (phba->intr_type == MSI)
  8060. lpfc_sli4_disable_msi(phba);
  8061. else if (phba->intr_type == INTx)
  8062. free_irq(phba->pcidev->irq, phba);
  8063. /* Reset interrupt management states */
  8064. phba->intr_type = NONE;
  8065. phba->sli.slistat.sli_intr = 0;
  8066. return;
  8067. }
  8068. /**
  8069. * lpfc_unset_hba - Unset SLI3 hba device initialization
  8070. * @phba: pointer to lpfc hba data structure.
  8071. *
  8072. * This routine is invoked to unset the HBA device initialization steps to
  8073. * a device with SLI-3 interface spec.
  8074. **/
  8075. static void
  8076. lpfc_unset_hba(struct lpfc_hba *phba)
  8077. {
  8078. struct lpfc_vport *vport = phba->pport;
  8079. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  8080. spin_lock_irq(shost->host_lock);
  8081. vport->load_flag |= FC_UNLOADING;
  8082. spin_unlock_irq(shost->host_lock);
  8083. kfree(phba->vpi_bmask);
  8084. kfree(phba->vpi_ids);
  8085. lpfc_stop_hba_timers(phba);
  8086. phba->pport->work_port_events = 0;
  8087. lpfc_sli_hba_down(phba);
  8088. lpfc_sli_brdrestart(phba);
  8089. lpfc_sli_disable_intr(phba);
  8090. return;
  8091. }
  8092. /**
  8093. * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
  8094. * @phba: Pointer to HBA context object.
  8095. *
  8096. * This function is called in the SLI4 code path to wait for completion
  8097. * of device's XRIs exchange busy. It will check the XRI exchange busy
  8098. * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
  8099. * that, it will check the XRI exchange busy on outstanding FCP and ELS
  8100. * I/Os every 30 seconds, log error message, and wait forever. Only when
  8101. * all XRI exchange busy complete, the driver unload shall proceed with
  8102. * invoking the function reset ioctl mailbox command to the CNA and the
  8103. * the rest of the driver unload resource release.
  8104. **/
  8105. static void
  8106. lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
  8107. {
  8108. int wait_time = 0;
  8109. int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  8110. int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  8111. while (!fcp_xri_cmpl || !els_xri_cmpl) {
  8112. if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
  8113. if (!fcp_xri_cmpl)
  8114. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8115. "2877 FCP XRI exchange busy "
  8116. "wait time: %d seconds.\n",
  8117. wait_time/1000);
  8118. if (!els_xri_cmpl)
  8119. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8120. "2878 ELS XRI exchange busy "
  8121. "wait time: %d seconds.\n",
  8122. wait_time/1000);
  8123. msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
  8124. wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
  8125. } else {
  8126. msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
  8127. wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
  8128. }
  8129. fcp_xri_cmpl =
  8130. list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  8131. els_xri_cmpl =
  8132. list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  8133. }
  8134. }
  8135. /**
  8136. * lpfc_sli4_hba_unset - Unset the fcoe hba
  8137. * @phba: Pointer to HBA context object.
  8138. *
  8139. * This function is called in the SLI4 code path to reset the HBA's FCoE
  8140. * function. The caller is not required to hold any lock. This routine
  8141. * issues PCI function reset mailbox command to reset the FCoE function.
  8142. * At the end of the function, it calls lpfc_hba_down_post function to
  8143. * free any pending commands.
  8144. **/
  8145. static void
  8146. lpfc_sli4_hba_unset(struct lpfc_hba *phba)
  8147. {
  8148. int wait_cnt = 0;
  8149. LPFC_MBOXQ_t *mboxq;
  8150. struct pci_dev *pdev = phba->pcidev;
  8151. lpfc_stop_hba_timers(phba);
  8152. phba->sli4_hba.intr_enable = 0;
  8153. /*
  8154. * Gracefully wait out the potential current outstanding asynchronous
  8155. * mailbox command.
  8156. */
  8157. /* First, block any pending async mailbox command from posted */
  8158. spin_lock_irq(&phba->hbalock);
  8159. phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  8160. spin_unlock_irq(&phba->hbalock);
  8161. /* Now, trying to wait it out if we can */
  8162. while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  8163. msleep(10);
  8164. if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
  8165. break;
  8166. }
  8167. /* Forcefully release the outstanding mailbox command if timed out */
  8168. if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  8169. spin_lock_irq(&phba->hbalock);
  8170. mboxq = phba->sli.mbox_active;
  8171. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  8172. __lpfc_mbox_cmpl_put(phba, mboxq);
  8173. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8174. phba->sli.mbox_active = NULL;
  8175. spin_unlock_irq(&phba->hbalock);
  8176. }
  8177. /* Abort all iocbs associated with the hba */
  8178. lpfc_sli_hba_iocb_abort(phba);
  8179. /* Wait for completion of device XRI exchange busy */
  8180. lpfc_sli4_xri_exchange_busy_wait(phba);
  8181. /* Disable PCI subsystem interrupt */
  8182. lpfc_sli4_disable_intr(phba);
  8183. /* Disable SR-IOV if enabled */
  8184. if (phba->cfg_sriov_nr_virtfn)
  8185. pci_disable_sriov(pdev);
  8186. /* Stop kthread signal shall trigger work_done one more time */
  8187. kthread_stop(phba->worker_thread);
  8188. /* Reset SLI4 HBA FCoE function */
  8189. lpfc_pci_function_reset(phba);
  8190. lpfc_sli4_queue_destroy(phba);
  8191. /* Stop the SLI4 device port */
  8192. phba->pport->work_port_events = 0;
  8193. }
  8194. /**
  8195. * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
  8196. * @phba: Pointer to HBA context object.
  8197. * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
  8198. *
  8199. * This function is called in the SLI4 code path to read the port's
  8200. * sli4 capabilities.
  8201. *
  8202. * This function may be be called from any context that can block-wait
  8203. * for the completion. The expectation is that this routine is called
  8204. * typically from probe_one or from the online routine.
  8205. **/
  8206. int
  8207. lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  8208. {
  8209. int rc;
  8210. struct lpfc_mqe *mqe;
  8211. struct lpfc_pc_sli4_params *sli4_params;
  8212. uint32_t mbox_tmo;
  8213. rc = 0;
  8214. mqe = &mboxq->u.mqe;
  8215. /* Read the port's SLI4 Parameters port capabilities */
  8216. lpfc_pc_sli4_params(mboxq);
  8217. if (!phba->sli4_hba.intr_enable)
  8218. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  8219. else {
  8220. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  8221. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  8222. }
  8223. if (unlikely(rc))
  8224. return 1;
  8225. sli4_params = &phba->sli4_hba.pc_sli4_params;
  8226. sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
  8227. sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
  8228. sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
  8229. sli4_params->featurelevel_1 = bf_get(featurelevel_1,
  8230. &mqe->un.sli4_params);
  8231. sli4_params->featurelevel_2 = bf_get(featurelevel_2,
  8232. &mqe->un.sli4_params);
  8233. sli4_params->proto_types = mqe->un.sli4_params.word3;
  8234. sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
  8235. sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
  8236. sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
  8237. sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
  8238. sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
  8239. sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
  8240. sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
  8241. sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
  8242. sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
  8243. sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
  8244. sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
  8245. sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
  8246. sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
  8247. sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
  8248. sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
  8249. sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
  8250. sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
  8251. sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
  8252. sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
  8253. sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
  8254. /* Make sure that sge_supp_len can be handled by the driver */
  8255. if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
  8256. sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
  8257. return rc;
  8258. }
  8259. /**
  8260. * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
  8261. * @phba: Pointer to HBA context object.
  8262. * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
  8263. *
  8264. * This function is called in the SLI4 code path to read the port's
  8265. * sli4 capabilities.
  8266. *
  8267. * This function may be be called from any context that can block-wait
  8268. * for the completion. The expectation is that this routine is called
  8269. * typically from probe_one or from the online routine.
  8270. **/
  8271. int
  8272. lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  8273. {
  8274. int rc;
  8275. struct lpfc_mqe *mqe = &mboxq->u.mqe;
  8276. struct lpfc_pc_sli4_params *sli4_params;
  8277. uint32_t mbox_tmo;
  8278. int length;
  8279. struct lpfc_sli4_parameters *mbx_sli4_parameters;
  8280. /*
  8281. * By default, the driver assumes the SLI4 port requires RPI
  8282. * header postings. The SLI4_PARAM response will correct this
  8283. * assumption.
  8284. */
  8285. phba->sli4_hba.rpi_hdrs_in_use = 1;
  8286. /* Read the port's SLI4 Config Parameters */
  8287. length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
  8288. sizeof(struct lpfc_sli4_cfg_mhdr));
  8289. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  8290. LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
  8291. length, LPFC_SLI4_MBX_EMBED);
  8292. if (!phba->sli4_hba.intr_enable)
  8293. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  8294. else {
  8295. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  8296. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  8297. }
  8298. if (unlikely(rc))
  8299. return rc;
  8300. sli4_params = &phba->sli4_hba.pc_sli4_params;
  8301. mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
  8302. sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
  8303. sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
  8304. sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
  8305. sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
  8306. mbx_sli4_parameters);
  8307. sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
  8308. mbx_sli4_parameters);
  8309. if (bf_get(cfg_phwq, mbx_sli4_parameters))
  8310. phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
  8311. else
  8312. phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
  8313. sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
  8314. sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
  8315. sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
  8316. sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
  8317. sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
  8318. sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
  8319. sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
  8320. mbx_sli4_parameters);
  8321. sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
  8322. mbx_sli4_parameters);
  8323. phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
  8324. phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
  8325. /* Make sure that sge_supp_len can be handled by the driver */
  8326. if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
  8327. sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
  8328. return 0;
  8329. }
  8330. /**
  8331. * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
  8332. * @pdev: pointer to PCI device
  8333. * @pid: pointer to PCI device identifier
  8334. *
  8335. * This routine is to be called to attach a device with SLI-3 interface spec
  8336. * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  8337. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  8338. * information of the device and driver to see if the driver state that it can
  8339. * support this kind of device. If the match is successful, the driver core
  8340. * invokes this routine. If this routine determines it can claim the HBA, it
  8341. * does all the initialization that it needs to do to handle the HBA properly.
  8342. *
  8343. * Return code
  8344. * 0 - driver can claim the device
  8345. * negative value - driver can not claim the device
  8346. **/
  8347. static int
  8348. lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
  8349. {
  8350. struct lpfc_hba *phba;
  8351. struct lpfc_vport *vport = NULL;
  8352. struct Scsi_Host *shost = NULL;
  8353. int error;
  8354. uint32_t cfg_mode, intr_mode;
  8355. /* Allocate memory for HBA structure */
  8356. phba = lpfc_hba_alloc(pdev);
  8357. if (!phba)
  8358. return -ENOMEM;
  8359. /* Perform generic PCI device enabling operation */
  8360. error = lpfc_enable_pci_dev(phba);
  8361. if (error)
  8362. goto out_free_phba;
  8363. /* Set up SLI API function jump table for PCI-device group-0 HBAs */
  8364. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
  8365. if (error)
  8366. goto out_disable_pci_dev;
  8367. /* Set up SLI-3 specific device PCI memory space */
  8368. error = lpfc_sli_pci_mem_setup(phba);
  8369. if (error) {
  8370. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8371. "1402 Failed to set up pci memory space.\n");
  8372. goto out_disable_pci_dev;
  8373. }
  8374. /* Set up phase-1 common device driver resources */
  8375. error = lpfc_setup_driver_resource_phase1(phba);
  8376. if (error) {
  8377. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8378. "1403 Failed to set up driver resource.\n");
  8379. goto out_unset_pci_mem_s3;
  8380. }
  8381. /* Set up SLI-3 specific device driver resources */
  8382. error = lpfc_sli_driver_resource_setup(phba);
  8383. if (error) {
  8384. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8385. "1404 Failed to set up driver resource.\n");
  8386. goto out_unset_pci_mem_s3;
  8387. }
  8388. /* Initialize and populate the iocb list per host */
  8389. error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
  8390. if (error) {
  8391. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8392. "1405 Failed to initialize iocb list.\n");
  8393. goto out_unset_driver_resource_s3;
  8394. }
  8395. /* Set up common device driver resources */
  8396. error = lpfc_setup_driver_resource_phase2(phba);
  8397. if (error) {
  8398. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8399. "1406 Failed to set up driver resource.\n");
  8400. goto out_free_iocb_list;
  8401. }
  8402. /* Get the default values for Model Name and Description */
  8403. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  8404. /* Create SCSI host to the physical port */
  8405. error = lpfc_create_shost(phba);
  8406. if (error) {
  8407. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8408. "1407 Failed to create scsi host.\n");
  8409. goto out_unset_driver_resource;
  8410. }
  8411. /* Configure sysfs attributes */
  8412. vport = phba->pport;
  8413. error = lpfc_alloc_sysfs_attr(vport);
  8414. if (error) {
  8415. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8416. "1476 Failed to allocate sysfs attr\n");
  8417. goto out_destroy_shost;
  8418. }
  8419. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  8420. /* Now, trying to enable interrupt and bring up the device */
  8421. cfg_mode = phba->cfg_use_msi;
  8422. while (true) {
  8423. /* Put device to a known state before enabling interrupt */
  8424. lpfc_stop_port(phba);
  8425. /* Configure and enable interrupt */
  8426. intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
  8427. if (intr_mode == LPFC_INTR_ERROR) {
  8428. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8429. "0431 Failed to enable interrupt.\n");
  8430. error = -ENODEV;
  8431. goto out_free_sysfs_attr;
  8432. }
  8433. /* SLI-3 HBA setup */
  8434. if (lpfc_sli_hba_setup(phba)) {
  8435. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8436. "1477 Failed to set up hba\n");
  8437. error = -ENODEV;
  8438. goto out_remove_device;
  8439. }
  8440. /* Wait 50ms for the interrupts of previous mailbox commands */
  8441. msleep(50);
  8442. /* Check active interrupts on message signaled interrupts */
  8443. if (intr_mode == 0 ||
  8444. phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
  8445. /* Log the current active interrupt mode */
  8446. phba->intr_mode = intr_mode;
  8447. lpfc_log_intr_mode(phba, intr_mode);
  8448. break;
  8449. } else {
  8450. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8451. "0447 Configure interrupt mode (%d) "
  8452. "failed active interrupt test.\n",
  8453. intr_mode);
  8454. /* Disable the current interrupt mode */
  8455. lpfc_sli_disable_intr(phba);
  8456. /* Try next level of interrupt mode */
  8457. cfg_mode = --intr_mode;
  8458. }
  8459. }
  8460. /* Perform post initialization setup */
  8461. lpfc_post_init_setup(phba);
  8462. /* Check if there are static vports to be created. */
  8463. lpfc_create_static_vport(phba);
  8464. return 0;
  8465. out_remove_device:
  8466. lpfc_unset_hba(phba);
  8467. out_free_sysfs_attr:
  8468. lpfc_free_sysfs_attr(vport);
  8469. out_destroy_shost:
  8470. lpfc_destroy_shost(phba);
  8471. out_unset_driver_resource:
  8472. lpfc_unset_driver_resource_phase2(phba);
  8473. out_free_iocb_list:
  8474. lpfc_free_iocb_list(phba);
  8475. out_unset_driver_resource_s3:
  8476. lpfc_sli_driver_resource_unset(phba);
  8477. out_unset_pci_mem_s3:
  8478. lpfc_sli_pci_mem_unset(phba);
  8479. out_disable_pci_dev:
  8480. lpfc_disable_pci_dev(phba);
  8481. if (shost)
  8482. scsi_host_put(shost);
  8483. out_free_phba:
  8484. lpfc_hba_free(phba);
  8485. return error;
  8486. }
  8487. /**
  8488. * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
  8489. * @pdev: pointer to PCI device
  8490. *
  8491. * This routine is to be called to disattach a device with SLI-3 interface
  8492. * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  8493. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  8494. * device to be removed from the PCI subsystem properly.
  8495. **/
  8496. static void
  8497. lpfc_pci_remove_one_s3(struct pci_dev *pdev)
  8498. {
  8499. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8500. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  8501. struct lpfc_vport **vports;
  8502. struct lpfc_hba *phba = vport->phba;
  8503. int i;
  8504. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  8505. spin_lock_irq(&phba->hbalock);
  8506. vport->load_flag |= FC_UNLOADING;
  8507. spin_unlock_irq(&phba->hbalock);
  8508. lpfc_free_sysfs_attr(vport);
  8509. /* Release all the vports against this physical port */
  8510. vports = lpfc_create_vport_work_array(phba);
  8511. if (vports != NULL)
  8512. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  8513. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  8514. continue;
  8515. fc_vport_terminate(vports[i]->fc_vport);
  8516. }
  8517. lpfc_destroy_vport_work_array(phba, vports);
  8518. /* Remove FC host and then SCSI host with the physical port */
  8519. fc_remove_host(shost);
  8520. scsi_remove_host(shost);
  8521. lpfc_cleanup(vport);
  8522. /*
  8523. * Bring down the SLI Layer. This step disable all interrupts,
  8524. * clears the rings, discards all mailbox commands, and resets
  8525. * the HBA.
  8526. */
  8527. /* HBA interrupt will be disabled after this call */
  8528. lpfc_sli_hba_down(phba);
  8529. /* Stop kthread signal shall trigger work_done one more time */
  8530. kthread_stop(phba->worker_thread);
  8531. /* Final cleanup of txcmplq and reset the HBA */
  8532. lpfc_sli_brdrestart(phba);
  8533. kfree(phba->vpi_bmask);
  8534. kfree(phba->vpi_ids);
  8535. lpfc_stop_hba_timers(phba);
  8536. spin_lock_irq(&phba->hbalock);
  8537. list_del_init(&vport->listentry);
  8538. spin_unlock_irq(&phba->hbalock);
  8539. lpfc_debugfs_terminate(vport);
  8540. /* Disable SR-IOV if enabled */
  8541. if (phba->cfg_sriov_nr_virtfn)
  8542. pci_disable_sriov(pdev);
  8543. /* Disable interrupt */
  8544. lpfc_sli_disable_intr(phba);
  8545. pci_set_drvdata(pdev, NULL);
  8546. scsi_host_put(shost);
  8547. /*
  8548. * Call scsi_free before mem_free since scsi bufs are released to their
  8549. * corresponding pools here.
  8550. */
  8551. lpfc_scsi_free(phba);
  8552. lpfc_mem_free_all(phba);
  8553. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  8554. phba->hbqslimp.virt, phba->hbqslimp.phys);
  8555. /* Free resources associated with SLI2 interface */
  8556. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  8557. phba->slim2p.virt, phba->slim2p.phys);
  8558. /* unmap adapter SLIM and Control Registers */
  8559. iounmap(phba->ctrl_regs_memmap_p);
  8560. iounmap(phba->slim_memmap_p);
  8561. lpfc_hba_free(phba);
  8562. pci_release_selected_regions(pdev, bars);
  8563. pci_disable_device(pdev);
  8564. }
  8565. /**
  8566. * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
  8567. * @pdev: pointer to PCI device
  8568. * @msg: power management message
  8569. *
  8570. * This routine is to be called from the kernel's PCI subsystem to support
  8571. * system Power Management (PM) to device with SLI-3 interface spec. When
  8572. * PM invokes this method, it quiesces the device by stopping the driver's
  8573. * worker thread for the device, turning off device's interrupt and DMA,
  8574. * and bring the device offline. Note that as the driver implements the
  8575. * minimum PM requirements to a power-aware driver's PM support for the
  8576. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  8577. * to the suspend() method call will be treated as SUSPEND and the driver will
  8578. * fully reinitialize its device during resume() method call, the driver will
  8579. * set device to PCI_D3hot state in PCI config space instead of setting it
  8580. * according to the @msg provided by the PM.
  8581. *
  8582. * Return code
  8583. * 0 - driver suspended the device
  8584. * Error otherwise
  8585. **/
  8586. static int
  8587. lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
  8588. {
  8589. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8590. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8591. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8592. "0473 PCI device Power Management suspend.\n");
  8593. /* Bring down the device */
  8594. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  8595. lpfc_offline(phba);
  8596. kthread_stop(phba->worker_thread);
  8597. /* Disable interrupt from device */
  8598. lpfc_sli_disable_intr(phba);
  8599. /* Save device state to PCI config space */
  8600. pci_save_state(pdev);
  8601. pci_set_power_state(pdev, PCI_D3hot);
  8602. return 0;
  8603. }
  8604. /**
  8605. * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
  8606. * @pdev: pointer to PCI device
  8607. *
  8608. * This routine is to be called from the kernel's PCI subsystem to support
  8609. * system Power Management (PM) to device with SLI-3 interface spec. When PM
  8610. * invokes this method, it restores the device's PCI config space state and
  8611. * fully reinitializes the device and brings it online. Note that as the
  8612. * driver implements the minimum PM requirements to a power-aware driver's
  8613. * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
  8614. * FREEZE) to the suspend() method call will be treated as SUSPEND and the
  8615. * driver will fully reinitialize its device during resume() method call,
  8616. * the device will be set to PCI_D0 directly in PCI config space before
  8617. * restoring the state.
  8618. *
  8619. * Return code
  8620. * 0 - driver suspended the device
  8621. * Error otherwise
  8622. **/
  8623. static int
  8624. lpfc_pci_resume_one_s3(struct pci_dev *pdev)
  8625. {
  8626. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8627. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8628. uint32_t intr_mode;
  8629. int error;
  8630. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8631. "0452 PCI device Power Management resume.\n");
  8632. /* Restore device state from PCI config space */
  8633. pci_set_power_state(pdev, PCI_D0);
  8634. pci_restore_state(pdev);
  8635. /*
  8636. * As the new kernel behavior of pci_restore_state() API call clears
  8637. * device saved_state flag, need to save the restored state again.
  8638. */
  8639. pci_save_state(pdev);
  8640. if (pdev->is_busmaster)
  8641. pci_set_master(pdev);
  8642. /* Startup the kernel thread for this host adapter. */
  8643. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  8644. "lpfc_worker_%d", phba->brd_no);
  8645. if (IS_ERR(phba->worker_thread)) {
  8646. error = PTR_ERR(phba->worker_thread);
  8647. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8648. "0434 PM resume failed to start worker "
  8649. "thread: error=x%x.\n", error);
  8650. return error;
  8651. }
  8652. /* Configure and enable interrupt */
  8653. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  8654. if (intr_mode == LPFC_INTR_ERROR) {
  8655. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8656. "0430 PM resume Failed to enable interrupt\n");
  8657. return -EIO;
  8658. } else
  8659. phba->intr_mode = intr_mode;
  8660. /* Restart HBA and bring it online */
  8661. lpfc_sli_brdrestart(phba);
  8662. lpfc_online(phba);
  8663. /* Log the current active interrupt mode */
  8664. lpfc_log_intr_mode(phba, phba->intr_mode);
  8665. return 0;
  8666. }
  8667. /**
  8668. * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
  8669. * @phba: pointer to lpfc hba data structure.
  8670. *
  8671. * This routine is called to prepare the SLI3 device for PCI slot recover. It
  8672. * aborts all the outstanding SCSI I/Os to the pci device.
  8673. **/
  8674. static void
  8675. lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
  8676. {
  8677. struct lpfc_sli *psli = &phba->sli;
  8678. struct lpfc_sli_ring *pring;
  8679. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8680. "2723 PCI channel I/O abort preparing for recovery\n");
  8681. /*
  8682. * There may be errored I/Os through HBA, abort all I/Os on txcmplq
  8683. * and let the SCSI mid-layer to retry them to recover.
  8684. */
  8685. pring = &psli->ring[psli->fcp_ring];
  8686. lpfc_sli_abort_iocb_ring(phba, pring);
  8687. }
  8688. /**
  8689. * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
  8690. * @phba: pointer to lpfc hba data structure.
  8691. *
  8692. * This routine is called to prepare the SLI3 device for PCI slot reset. It
  8693. * disables the device interrupt and pci device, and aborts the internal FCP
  8694. * pending I/Os.
  8695. **/
  8696. static void
  8697. lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
  8698. {
  8699. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8700. "2710 PCI channel disable preparing for reset\n");
  8701. /* Block any management I/Os to the device */
  8702. lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
  8703. /* Block all SCSI devices' I/Os on the host */
  8704. lpfc_scsi_dev_block(phba);
  8705. /* Flush all driver's outstanding SCSI I/Os as we are to reset */
  8706. lpfc_sli_flush_fcp_rings(phba);
  8707. /* stop all timers */
  8708. lpfc_stop_hba_timers(phba);
  8709. /* Disable interrupt and pci device */
  8710. lpfc_sli_disable_intr(phba);
  8711. pci_disable_device(phba->pcidev);
  8712. }
  8713. /**
  8714. * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
  8715. * @phba: pointer to lpfc hba data structure.
  8716. *
  8717. * This routine is called to prepare the SLI3 device for PCI slot permanently
  8718. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  8719. * pending I/Os.
  8720. **/
  8721. static void
  8722. lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  8723. {
  8724. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8725. "2711 PCI channel permanent disable for failure\n");
  8726. /* Block all SCSI devices' I/Os on the host */
  8727. lpfc_scsi_dev_block(phba);
  8728. /* stop all timers */
  8729. lpfc_stop_hba_timers(phba);
  8730. /* Clean up all driver's outstanding SCSI I/Os */
  8731. lpfc_sli_flush_fcp_rings(phba);
  8732. }
  8733. /**
  8734. * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
  8735. * @pdev: pointer to PCI device.
  8736. * @state: the current PCI connection state.
  8737. *
  8738. * This routine is called from the PCI subsystem for I/O error handling to
  8739. * device with SLI-3 interface spec. This function is called by the PCI
  8740. * subsystem after a PCI bus error affecting this device has been detected.
  8741. * When this function is invoked, it will need to stop all the I/Os and
  8742. * interrupt(s) to the device. Once that is done, it will return
  8743. * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
  8744. * as desired.
  8745. *
  8746. * Return codes
  8747. * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
  8748. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  8749. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  8750. **/
  8751. static pci_ers_result_t
  8752. lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
  8753. {
  8754. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8755. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8756. switch (state) {
  8757. case pci_channel_io_normal:
  8758. /* Non-fatal error, prepare for recovery */
  8759. lpfc_sli_prep_dev_for_recover(phba);
  8760. return PCI_ERS_RESULT_CAN_RECOVER;
  8761. case pci_channel_io_frozen:
  8762. /* Fatal error, prepare for slot reset */
  8763. lpfc_sli_prep_dev_for_reset(phba);
  8764. return PCI_ERS_RESULT_NEED_RESET;
  8765. case pci_channel_io_perm_failure:
  8766. /* Permanent failure, prepare for device down */
  8767. lpfc_sli_prep_dev_for_perm_failure(phba);
  8768. return PCI_ERS_RESULT_DISCONNECT;
  8769. default:
  8770. /* Unknown state, prepare and request slot reset */
  8771. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8772. "0472 Unknown PCI error state: x%x\n", state);
  8773. lpfc_sli_prep_dev_for_reset(phba);
  8774. return PCI_ERS_RESULT_NEED_RESET;
  8775. }
  8776. }
  8777. /**
  8778. * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
  8779. * @pdev: pointer to PCI device.
  8780. *
  8781. * This routine is called from the PCI subsystem for error handling to
  8782. * device with SLI-3 interface spec. This is called after PCI bus has been
  8783. * reset to restart the PCI card from scratch, as if from a cold-boot.
  8784. * During the PCI subsystem error recovery, after driver returns
  8785. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  8786. * recovery and then call this routine before calling the .resume method
  8787. * to recover the device. This function will initialize the HBA device,
  8788. * enable the interrupt, but it will just put the HBA to offline state
  8789. * without passing any I/O traffic.
  8790. *
  8791. * Return codes
  8792. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  8793. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  8794. */
  8795. static pci_ers_result_t
  8796. lpfc_io_slot_reset_s3(struct pci_dev *pdev)
  8797. {
  8798. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8799. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8800. struct lpfc_sli *psli = &phba->sli;
  8801. uint32_t intr_mode;
  8802. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  8803. if (pci_enable_device_mem(pdev)) {
  8804. printk(KERN_ERR "lpfc: Cannot re-enable "
  8805. "PCI device after reset.\n");
  8806. return PCI_ERS_RESULT_DISCONNECT;
  8807. }
  8808. pci_restore_state(pdev);
  8809. /*
  8810. * As the new kernel behavior of pci_restore_state() API call clears
  8811. * device saved_state flag, need to save the restored state again.
  8812. */
  8813. pci_save_state(pdev);
  8814. if (pdev->is_busmaster)
  8815. pci_set_master(pdev);
  8816. spin_lock_irq(&phba->hbalock);
  8817. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  8818. spin_unlock_irq(&phba->hbalock);
  8819. /* Configure and enable interrupt */
  8820. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  8821. if (intr_mode == LPFC_INTR_ERROR) {
  8822. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8823. "0427 Cannot re-enable interrupt after "
  8824. "slot reset.\n");
  8825. return PCI_ERS_RESULT_DISCONNECT;
  8826. } else
  8827. phba->intr_mode = intr_mode;
  8828. /* Take device offline, it will perform cleanup */
  8829. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  8830. lpfc_offline(phba);
  8831. lpfc_sli_brdrestart(phba);
  8832. /* Log the current active interrupt mode */
  8833. lpfc_log_intr_mode(phba, phba->intr_mode);
  8834. return PCI_ERS_RESULT_RECOVERED;
  8835. }
  8836. /**
  8837. * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
  8838. * @pdev: pointer to PCI device
  8839. *
  8840. * This routine is called from the PCI subsystem for error handling to device
  8841. * with SLI-3 interface spec. It is called when kernel error recovery tells
  8842. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  8843. * error recovery. After this call, traffic can start to flow from this device
  8844. * again.
  8845. */
  8846. static void
  8847. lpfc_io_resume_s3(struct pci_dev *pdev)
  8848. {
  8849. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8850. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8851. /* Bring device online, it will be no-op for non-fatal error resume */
  8852. lpfc_online(phba);
  8853. /* Clean up Advanced Error Reporting (AER) if needed */
  8854. if (phba->hba_flag & HBA_AER_ENABLED)
  8855. pci_cleanup_aer_uncorrect_error_status(pdev);
  8856. }
  8857. /**
  8858. * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
  8859. * @phba: pointer to lpfc hba data structure.
  8860. *
  8861. * returns the number of ELS/CT IOCBs to reserve
  8862. **/
  8863. int
  8864. lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
  8865. {
  8866. int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
  8867. if (phba->sli_rev == LPFC_SLI_REV4) {
  8868. if (max_xri <= 100)
  8869. return 10;
  8870. else if (max_xri <= 256)
  8871. return 25;
  8872. else if (max_xri <= 512)
  8873. return 50;
  8874. else if (max_xri <= 1024)
  8875. return 100;
  8876. else if (max_xri <= 1536)
  8877. return 150;
  8878. else if (max_xri <= 2048)
  8879. return 200;
  8880. else
  8881. return 250;
  8882. } else
  8883. return 0;
  8884. }
  8885. /**
  8886. * lpfc_write_firmware - attempt to write a firmware image to the port
  8887. * @fw: pointer to firmware image returned from request_firmware.
  8888. * @phba: pointer to lpfc hba data structure.
  8889. *
  8890. **/
  8891. static void
  8892. lpfc_write_firmware(const struct firmware *fw, void *context)
  8893. {
  8894. struct lpfc_hba *phba = (struct lpfc_hba *)context;
  8895. char fwrev[FW_REV_STR_SIZE];
  8896. struct lpfc_grp_hdr *image;
  8897. struct list_head dma_buffer_list;
  8898. int i, rc = 0;
  8899. struct lpfc_dmabuf *dmabuf, *next;
  8900. uint32_t offset = 0, temp_offset = 0;
  8901. /* It can be null in no-wait mode, sanity check */
  8902. if (!fw) {
  8903. rc = -ENXIO;
  8904. goto out;
  8905. }
  8906. image = (struct lpfc_grp_hdr *)fw->data;
  8907. INIT_LIST_HEAD(&dma_buffer_list);
  8908. if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
  8909. (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
  8910. LPFC_FILE_TYPE_GROUP) ||
  8911. (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
  8912. (be32_to_cpu(image->size) != fw->size)) {
  8913. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8914. "3022 Invalid FW image found. "
  8915. "Magic:%x Type:%x ID:%x\n",
  8916. be32_to_cpu(image->magic_number),
  8917. bf_get_be32(lpfc_grp_hdr_file_type, image),
  8918. bf_get_be32(lpfc_grp_hdr_id, image));
  8919. rc = -EINVAL;
  8920. goto release_out;
  8921. }
  8922. lpfc_decode_firmware_rev(phba, fwrev, 1);
  8923. if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
  8924. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8925. "3023 Updating Firmware, Current Version:%s "
  8926. "New Version:%s\n",
  8927. fwrev, image->revision);
  8928. for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
  8929. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
  8930. GFP_KERNEL);
  8931. if (!dmabuf) {
  8932. rc = -ENOMEM;
  8933. goto release_out;
  8934. }
  8935. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8936. SLI4_PAGE_SIZE,
  8937. &dmabuf->phys,
  8938. GFP_KERNEL);
  8939. if (!dmabuf->virt) {
  8940. kfree(dmabuf);
  8941. rc = -ENOMEM;
  8942. goto release_out;
  8943. }
  8944. list_add_tail(&dmabuf->list, &dma_buffer_list);
  8945. }
  8946. while (offset < fw->size) {
  8947. temp_offset = offset;
  8948. list_for_each_entry(dmabuf, &dma_buffer_list, list) {
  8949. if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
  8950. memcpy(dmabuf->virt,
  8951. fw->data + temp_offset,
  8952. fw->size - temp_offset);
  8953. temp_offset = fw->size;
  8954. break;
  8955. }
  8956. memcpy(dmabuf->virt, fw->data + temp_offset,
  8957. SLI4_PAGE_SIZE);
  8958. temp_offset += SLI4_PAGE_SIZE;
  8959. }
  8960. rc = lpfc_wr_object(phba, &dma_buffer_list,
  8961. (fw->size - offset), &offset);
  8962. if (rc)
  8963. goto release_out;
  8964. }
  8965. rc = offset;
  8966. }
  8967. release_out:
  8968. list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
  8969. list_del(&dmabuf->list);
  8970. dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
  8971. dmabuf->virt, dmabuf->phys);
  8972. kfree(dmabuf);
  8973. }
  8974. release_firmware(fw);
  8975. out:
  8976. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8977. "3024 Firmware update done: %d.\n", rc);
  8978. return;
  8979. }
  8980. /**
  8981. * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
  8982. * @phba: pointer to lpfc hba data structure.
  8983. *
  8984. * This routine is called to perform Linux generic firmware upgrade on device
  8985. * that supports such feature.
  8986. **/
  8987. int
  8988. lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
  8989. {
  8990. uint8_t file_name[ELX_MODEL_NAME_SIZE];
  8991. int ret;
  8992. const struct firmware *fw;
  8993. /* Only supported on SLI4 interface type 2 for now */
  8994. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  8995. LPFC_SLI_INTF_IF_TYPE_2)
  8996. return -EPERM;
  8997. snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
  8998. if (fw_upgrade == INT_FW_UPGRADE) {
  8999. ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
  9000. file_name, &phba->pcidev->dev,
  9001. GFP_KERNEL, (void *)phba,
  9002. lpfc_write_firmware);
  9003. } else if (fw_upgrade == RUN_FW_UPGRADE) {
  9004. ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
  9005. if (!ret)
  9006. lpfc_write_firmware(fw, (void *)phba);
  9007. } else {
  9008. ret = -EINVAL;
  9009. }
  9010. return ret;
  9011. }
  9012. /**
  9013. * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
  9014. * @pdev: pointer to PCI device
  9015. * @pid: pointer to PCI device identifier
  9016. *
  9017. * This routine is called from the kernel's PCI subsystem to device with
  9018. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  9019. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  9020. * information of the device and driver to see if the driver state that it
  9021. * can support this kind of device. If the match is successful, the driver
  9022. * core invokes this routine. If this routine determines it can claim the HBA,
  9023. * it does all the initialization that it needs to do to handle the HBA
  9024. * properly.
  9025. *
  9026. * Return code
  9027. * 0 - driver can claim the device
  9028. * negative value - driver can not claim the device
  9029. **/
  9030. static int
  9031. lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
  9032. {
  9033. struct lpfc_hba *phba;
  9034. struct lpfc_vport *vport = NULL;
  9035. struct Scsi_Host *shost = NULL;
  9036. int error, ret;
  9037. uint32_t cfg_mode, intr_mode;
  9038. int adjusted_fcp_io_channel;
  9039. /* Allocate memory for HBA structure */
  9040. phba = lpfc_hba_alloc(pdev);
  9041. if (!phba)
  9042. return -ENOMEM;
  9043. /* Perform generic PCI device enabling operation */
  9044. error = lpfc_enable_pci_dev(phba);
  9045. if (error)
  9046. goto out_free_phba;
  9047. /* Set up SLI API function jump table for PCI-device group-1 HBAs */
  9048. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
  9049. if (error)
  9050. goto out_disable_pci_dev;
  9051. /* Set up SLI-4 specific device PCI memory space */
  9052. error = lpfc_sli4_pci_mem_setup(phba);
  9053. if (error) {
  9054. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9055. "1410 Failed to set up pci memory space.\n");
  9056. goto out_disable_pci_dev;
  9057. }
  9058. /* Set up phase-1 common device driver resources */
  9059. error = lpfc_setup_driver_resource_phase1(phba);
  9060. if (error) {
  9061. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9062. "1411 Failed to set up driver resource.\n");
  9063. goto out_unset_pci_mem_s4;
  9064. }
  9065. /* Set up SLI-4 Specific device driver resources */
  9066. error = lpfc_sli4_driver_resource_setup(phba);
  9067. if (error) {
  9068. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9069. "1412 Failed to set up driver resource.\n");
  9070. goto out_unset_pci_mem_s4;
  9071. }
  9072. /* Initialize and populate the iocb list per host */
  9073. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9074. "2821 initialize iocb list %d.\n",
  9075. phba->cfg_iocb_cnt*1024);
  9076. error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
  9077. if (error) {
  9078. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9079. "1413 Failed to initialize iocb list.\n");
  9080. goto out_unset_driver_resource_s4;
  9081. }
  9082. INIT_LIST_HEAD(&phba->active_rrq_list);
  9083. INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
  9084. /* Set up common device driver resources */
  9085. error = lpfc_setup_driver_resource_phase2(phba);
  9086. if (error) {
  9087. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9088. "1414 Failed to set up driver resource.\n");
  9089. goto out_free_iocb_list;
  9090. }
  9091. /* Get the default values for Model Name and Description */
  9092. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  9093. /* Create SCSI host to the physical port */
  9094. error = lpfc_create_shost(phba);
  9095. if (error) {
  9096. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9097. "1415 Failed to create scsi host.\n");
  9098. goto out_unset_driver_resource;
  9099. }
  9100. /* Configure sysfs attributes */
  9101. vport = phba->pport;
  9102. error = lpfc_alloc_sysfs_attr(vport);
  9103. if (error) {
  9104. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9105. "1416 Failed to allocate sysfs attr\n");
  9106. goto out_destroy_shost;
  9107. }
  9108. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  9109. /* Now, trying to enable interrupt and bring up the device */
  9110. cfg_mode = phba->cfg_use_msi;
  9111. /* Put device to a known state before enabling interrupt */
  9112. lpfc_stop_port(phba);
  9113. /* Configure and enable interrupt */
  9114. intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
  9115. if (intr_mode == LPFC_INTR_ERROR) {
  9116. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9117. "0426 Failed to enable interrupt.\n");
  9118. error = -ENODEV;
  9119. goto out_free_sysfs_attr;
  9120. }
  9121. /* Default to single EQ for non-MSI-X */
  9122. if (phba->intr_type != MSIX)
  9123. adjusted_fcp_io_channel = 1;
  9124. else
  9125. adjusted_fcp_io_channel = phba->cfg_fcp_io_channel;
  9126. phba->cfg_fcp_io_channel = adjusted_fcp_io_channel;
  9127. /* Set up SLI-4 HBA */
  9128. if (lpfc_sli4_hba_setup(phba)) {
  9129. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9130. "1421 Failed to set up hba\n");
  9131. error = -ENODEV;
  9132. goto out_disable_intr;
  9133. }
  9134. /* Log the current active interrupt mode */
  9135. phba->intr_mode = intr_mode;
  9136. lpfc_log_intr_mode(phba, intr_mode);
  9137. /* Perform post initialization setup */
  9138. lpfc_post_init_setup(phba);
  9139. /* check for firmware upgrade or downgrade */
  9140. if (phba->cfg_request_firmware_upgrade)
  9141. ret = lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
  9142. /* Check if there are static vports to be created. */
  9143. lpfc_create_static_vport(phba);
  9144. return 0;
  9145. out_disable_intr:
  9146. lpfc_sli4_disable_intr(phba);
  9147. out_free_sysfs_attr:
  9148. lpfc_free_sysfs_attr(vport);
  9149. out_destroy_shost:
  9150. lpfc_destroy_shost(phba);
  9151. out_unset_driver_resource:
  9152. lpfc_unset_driver_resource_phase2(phba);
  9153. out_free_iocb_list:
  9154. lpfc_free_iocb_list(phba);
  9155. out_unset_driver_resource_s4:
  9156. lpfc_sli4_driver_resource_unset(phba);
  9157. out_unset_pci_mem_s4:
  9158. lpfc_sli4_pci_mem_unset(phba);
  9159. out_disable_pci_dev:
  9160. lpfc_disable_pci_dev(phba);
  9161. if (shost)
  9162. scsi_host_put(shost);
  9163. out_free_phba:
  9164. lpfc_hba_free(phba);
  9165. return error;
  9166. }
  9167. /**
  9168. * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
  9169. * @pdev: pointer to PCI device
  9170. *
  9171. * This routine is called from the kernel's PCI subsystem to device with
  9172. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  9173. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  9174. * device to be removed from the PCI subsystem properly.
  9175. **/
  9176. static void
  9177. lpfc_pci_remove_one_s4(struct pci_dev *pdev)
  9178. {
  9179. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9180. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  9181. struct lpfc_vport **vports;
  9182. struct lpfc_hba *phba = vport->phba;
  9183. int i;
  9184. /* Mark the device unloading flag */
  9185. spin_lock_irq(&phba->hbalock);
  9186. vport->load_flag |= FC_UNLOADING;
  9187. spin_unlock_irq(&phba->hbalock);
  9188. /* Free the HBA sysfs attributes */
  9189. lpfc_free_sysfs_attr(vport);
  9190. /* Release all the vports against this physical port */
  9191. vports = lpfc_create_vport_work_array(phba);
  9192. if (vports != NULL)
  9193. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  9194. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  9195. continue;
  9196. fc_vport_terminate(vports[i]->fc_vport);
  9197. }
  9198. lpfc_destroy_vport_work_array(phba, vports);
  9199. /* Remove FC host and then SCSI host with the physical port */
  9200. fc_remove_host(shost);
  9201. scsi_remove_host(shost);
  9202. /* Perform cleanup on the physical port */
  9203. lpfc_cleanup(vport);
  9204. /*
  9205. * Bring down the SLI Layer. This step disables all interrupts,
  9206. * clears the rings, discards all mailbox commands, and resets
  9207. * the HBA FCoE function.
  9208. */
  9209. lpfc_debugfs_terminate(vport);
  9210. lpfc_sli4_hba_unset(phba);
  9211. spin_lock_irq(&phba->hbalock);
  9212. list_del_init(&vport->listentry);
  9213. spin_unlock_irq(&phba->hbalock);
  9214. /* Perform scsi free before driver resource_unset since scsi
  9215. * buffers are released to their corresponding pools here.
  9216. */
  9217. lpfc_scsi_free(phba);
  9218. lpfc_sli4_driver_resource_unset(phba);
  9219. /* Unmap adapter Control and Doorbell registers */
  9220. lpfc_sli4_pci_mem_unset(phba);
  9221. /* Release PCI resources and disable device's PCI function */
  9222. scsi_host_put(shost);
  9223. lpfc_disable_pci_dev(phba);
  9224. /* Finally, free the driver's device data structure */
  9225. lpfc_hba_free(phba);
  9226. return;
  9227. }
  9228. /**
  9229. * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
  9230. * @pdev: pointer to PCI device
  9231. * @msg: power management message
  9232. *
  9233. * This routine is called from the kernel's PCI subsystem to support system
  9234. * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
  9235. * this method, it quiesces the device by stopping the driver's worker
  9236. * thread for the device, turning off device's interrupt and DMA, and bring
  9237. * the device offline. Note that as the driver implements the minimum PM
  9238. * requirements to a power-aware driver's PM support for suspend/resume -- all
  9239. * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
  9240. * method call will be treated as SUSPEND and the driver will fully
  9241. * reinitialize its device during resume() method call, the driver will set
  9242. * device to PCI_D3hot state in PCI config space instead of setting it
  9243. * according to the @msg provided by the PM.
  9244. *
  9245. * Return code
  9246. * 0 - driver suspended the device
  9247. * Error otherwise
  9248. **/
  9249. static int
  9250. lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
  9251. {
  9252. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9253. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9254. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9255. "2843 PCI device Power Management suspend.\n");
  9256. /* Bring down the device */
  9257. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  9258. lpfc_offline(phba);
  9259. kthread_stop(phba->worker_thread);
  9260. /* Disable interrupt from device */
  9261. lpfc_sli4_disable_intr(phba);
  9262. lpfc_sli4_queue_destroy(phba);
  9263. /* Save device state to PCI config space */
  9264. pci_save_state(pdev);
  9265. pci_set_power_state(pdev, PCI_D3hot);
  9266. return 0;
  9267. }
  9268. /**
  9269. * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
  9270. * @pdev: pointer to PCI device
  9271. *
  9272. * This routine is called from the kernel's PCI subsystem to support system
  9273. * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
  9274. * this method, it restores the device's PCI config space state and fully
  9275. * reinitializes the device and brings it online. Note that as the driver
  9276. * implements the minimum PM requirements to a power-aware driver's PM for
  9277. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  9278. * to the suspend() method call will be treated as SUSPEND and the driver
  9279. * will fully reinitialize its device during resume() method call, the device
  9280. * will be set to PCI_D0 directly in PCI config space before restoring the
  9281. * state.
  9282. *
  9283. * Return code
  9284. * 0 - driver suspended the device
  9285. * Error otherwise
  9286. **/
  9287. static int
  9288. lpfc_pci_resume_one_s4(struct pci_dev *pdev)
  9289. {
  9290. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9291. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9292. uint32_t intr_mode;
  9293. int error;
  9294. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9295. "0292 PCI device Power Management resume.\n");
  9296. /* Restore device state from PCI config space */
  9297. pci_set_power_state(pdev, PCI_D0);
  9298. pci_restore_state(pdev);
  9299. /*
  9300. * As the new kernel behavior of pci_restore_state() API call clears
  9301. * device saved_state flag, need to save the restored state again.
  9302. */
  9303. pci_save_state(pdev);
  9304. if (pdev->is_busmaster)
  9305. pci_set_master(pdev);
  9306. /* Startup the kernel thread for this host adapter. */
  9307. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  9308. "lpfc_worker_%d", phba->brd_no);
  9309. if (IS_ERR(phba->worker_thread)) {
  9310. error = PTR_ERR(phba->worker_thread);
  9311. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9312. "0293 PM resume failed to start worker "
  9313. "thread: error=x%x.\n", error);
  9314. return error;
  9315. }
  9316. /* Configure and enable interrupt */
  9317. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  9318. if (intr_mode == LPFC_INTR_ERROR) {
  9319. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9320. "0294 PM resume Failed to enable interrupt\n");
  9321. return -EIO;
  9322. } else
  9323. phba->intr_mode = intr_mode;
  9324. /* Restart HBA and bring it online */
  9325. lpfc_sli_brdrestart(phba);
  9326. lpfc_online(phba);
  9327. /* Log the current active interrupt mode */
  9328. lpfc_log_intr_mode(phba, phba->intr_mode);
  9329. return 0;
  9330. }
  9331. /**
  9332. * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
  9333. * @phba: pointer to lpfc hba data structure.
  9334. *
  9335. * This routine is called to prepare the SLI4 device for PCI slot recover. It
  9336. * aborts all the outstanding SCSI I/Os to the pci device.
  9337. **/
  9338. static void
  9339. lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
  9340. {
  9341. struct lpfc_sli *psli = &phba->sli;
  9342. struct lpfc_sli_ring *pring;
  9343. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9344. "2828 PCI channel I/O abort preparing for recovery\n");
  9345. /*
  9346. * There may be errored I/Os through HBA, abort all I/Os on txcmplq
  9347. * and let the SCSI mid-layer to retry them to recover.
  9348. */
  9349. pring = &psli->ring[psli->fcp_ring];
  9350. lpfc_sli_abort_iocb_ring(phba, pring);
  9351. }
  9352. /**
  9353. * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
  9354. * @phba: pointer to lpfc hba data structure.
  9355. *
  9356. * This routine is called to prepare the SLI4 device for PCI slot reset. It
  9357. * disables the device interrupt and pci device, and aborts the internal FCP
  9358. * pending I/Os.
  9359. **/
  9360. static void
  9361. lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
  9362. {
  9363. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9364. "2826 PCI channel disable preparing for reset\n");
  9365. /* Block any management I/Os to the device */
  9366. lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
  9367. /* Block all SCSI devices' I/Os on the host */
  9368. lpfc_scsi_dev_block(phba);
  9369. /* Flush all driver's outstanding SCSI I/Os as we are to reset */
  9370. lpfc_sli_flush_fcp_rings(phba);
  9371. /* stop all timers */
  9372. lpfc_stop_hba_timers(phba);
  9373. /* Disable interrupt and pci device */
  9374. lpfc_sli4_disable_intr(phba);
  9375. lpfc_sli4_queue_destroy(phba);
  9376. pci_disable_device(phba->pcidev);
  9377. }
  9378. /**
  9379. * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
  9380. * @phba: pointer to lpfc hba data structure.
  9381. *
  9382. * This routine is called to prepare the SLI4 device for PCI slot permanently
  9383. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  9384. * pending I/Os.
  9385. **/
  9386. static void
  9387. lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  9388. {
  9389. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9390. "2827 PCI channel permanent disable for failure\n");
  9391. /* Block all SCSI devices' I/Os on the host */
  9392. lpfc_scsi_dev_block(phba);
  9393. /* stop all timers */
  9394. lpfc_stop_hba_timers(phba);
  9395. /* Clean up all driver's outstanding SCSI I/Os */
  9396. lpfc_sli_flush_fcp_rings(phba);
  9397. }
  9398. /**
  9399. * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
  9400. * @pdev: pointer to PCI device.
  9401. * @state: the current PCI connection state.
  9402. *
  9403. * This routine is called from the PCI subsystem for error handling to device
  9404. * with SLI-4 interface spec. This function is called by the PCI subsystem
  9405. * after a PCI bus error affecting this device has been detected. When this
  9406. * function is invoked, it will need to stop all the I/Os and interrupt(s)
  9407. * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
  9408. * for the PCI subsystem to perform proper recovery as desired.
  9409. *
  9410. * Return codes
  9411. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  9412. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9413. **/
  9414. static pci_ers_result_t
  9415. lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
  9416. {
  9417. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9418. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9419. switch (state) {
  9420. case pci_channel_io_normal:
  9421. /* Non-fatal error, prepare for recovery */
  9422. lpfc_sli4_prep_dev_for_recover(phba);
  9423. return PCI_ERS_RESULT_CAN_RECOVER;
  9424. case pci_channel_io_frozen:
  9425. /* Fatal error, prepare for slot reset */
  9426. lpfc_sli4_prep_dev_for_reset(phba);
  9427. return PCI_ERS_RESULT_NEED_RESET;
  9428. case pci_channel_io_perm_failure:
  9429. /* Permanent failure, prepare for device down */
  9430. lpfc_sli4_prep_dev_for_perm_failure(phba);
  9431. return PCI_ERS_RESULT_DISCONNECT;
  9432. default:
  9433. /* Unknown state, prepare and request slot reset */
  9434. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9435. "2825 Unknown PCI error state: x%x\n", state);
  9436. lpfc_sli4_prep_dev_for_reset(phba);
  9437. return PCI_ERS_RESULT_NEED_RESET;
  9438. }
  9439. }
  9440. /**
  9441. * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
  9442. * @pdev: pointer to PCI device.
  9443. *
  9444. * This routine is called from the PCI subsystem for error handling to device
  9445. * with SLI-4 interface spec. It is called after PCI bus has been reset to
  9446. * restart the PCI card from scratch, as if from a cold-boot. During the
  9447. * PCI subsystem error recovery, after the driver returns
  9448. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  9449. * recovery and then call this routine before calling the .resume method to
  9450. * recover the device. This function will initialize the HBA device, enable
  9451. * the interrupt, but it will just put the HBA to offline state without
  9452. * passing any I/O traffic.
  9453. *
  9454. * Return codes
  9455. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  9456. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9457. */
  9458. static pci_ers_result_t
  9459. lpfc_io_slot_reset_s4(struct pci_dev *pdev)
  9460. {
  9461. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9462. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9463. struct lpfc_sli *psli = &phba->sli;
  9464. uint32_t intr_mode;
  9465. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  9466. if (pci_enable_device_mem(pdev)) {
  9467. printk(KERN_ERR "lpfc: Cannot re-enable "
  9468. "PCI device after reset.\n");
  9469. return PCI_ERS_RESULT_DISCONNECT;
  9470. }
  9471. pci_restore_state(pdev);
  9472. /*
  9473. * As the new kernel behavior of pci_restore_state() API call clears
  9474. * device saved_state flag, need to save the restored state again.
  9475. */
  9476. pci_save_state(pdev);
  9477. if (pdev->is_busmaster)
  9478. pci_set_master(pdev);
  9479. spin_lock_irq(&phba->hbalock);
  9480. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  9481. spin_unlock_irq(&phba->hbalock);
  9482. /* Configure and enable interrupt */
  9483. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  9484. if (intr_mode == LPFC_INTR_ERROR) {
  9485. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9486. "2824 Cannot re-enable interrupt after "
  9487. "slot reset.\n");
  9488. return PCI_ERS_RESULT_DISCONNECT;
  9489. } else
  9490. phba->intr_mode = intr_mode;
  9491. /* Log the current active interrupt mode */
  9492. lpfc_log_intr_mode(phba, phba->intr_mode);
  9493. return PCI_ERS_RESULT_RECOVERED;
  9494. }
  9495. /**
  9496. * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
  9497. * @pdev: pointer to PCI device
  9498. *
  9499. * This routine is called from the PCI subsystem for error handling to device
  9500. * with SLI-4 interface spec. It is called when kernel error recovery tells
  9501. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  9502. * error recovery. After this call, traffic can start to flow from this device
  9503. * again.
  9504. **/
  9505. static void
  9506. lpfc_io_resume_s4(struct pci_dev *pdev)
  9507. {
  9508. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9509. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9510. /*
  9511. * In case of slot reset, as function reset is performed through
  9512. * mailbox command which needs DMA to be enabled, this operation
  9513. * has to be moved to the io resume phase. Taking device offline
  9514. * will perform the necessary cleanup.
  9515. */
  9516. if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
  9517. /* Perform device reset */
  9518. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  9519. lpfc_offline(phba);
  9520. lpfc_sli_brdrestart(phba);
  9521. /* Bring the device back online */
  9522. lpfc_online(phba);
  9523. }
  9524. /* Clean up Advanced Error Reporting (AER) if needed */
  9525. if (phba->hba_flag & HBA_AER_ENABLED)
  9526. pci_cleanup_aer_uncorrect_error_status(pdev);
  9527. }
  9528. /**
  9529. * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
  9530. * @pdev: pointer to PCI device
  9531. * @pid: pointer to PCI device identifier
  9532. *
  9533. * This routine is to be registered to the kernel's PCI subsystem. When an
  9534. * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
  9535. * at PCI device-specific information of the device and driver to see if the
  9536. * driver state that it can support this kind of device. If the match is
  9537. * successful, the driver core invokes this routine. This routine dispatches
  9538. * the action to the proper SLI-3 or SLI-4 device probing routine, which will
  9539. * do all the initialization that it needs to do to handle the HBA device
  9540. * properly.
  9541. *
  9542. * Return code
  9543. * 0 - driver can claim the device
  9544. * negative value - driver can not claim the device
  9545. **/
  9546. static int
  9547. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  9548. {
  9549. int rc;
  9550. struct lpfc_sli_intf intf;
  9551. if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
  9552. return -ENODEV;
  9553. if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
  9554. (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
  9555. rc = lpfc_pci_probe_one_s4(pdev, pid);
  9556. else
  9557. rc = lpfc_pci_probe_one_s3(pdev, pid);
  9558. return rc;
  9559. }
  9560. /**
  9561. * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
  9562. * @pdev: pointer to PCI device
  9563. *
  9564. * This routine is to be registered to the kernel's PCI subsystem. When an
  9565. * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
  9566. * This routine dispatches the action to the proper SLI-3 or SLI-4 device
  9567. * remove routine, which will perform all the necessary cleanup for the
  9568. * device to be removed from the PCI subsystem properly.
  9569. **/
  9570. static void
  9571. lpfc_pci_remove_one(struct pci_dev *pdev)
  9572. {
  9573. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9574. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9575. switch (phba->pci_dev_grp) {
  9576. case LPFC_PCI_DEV_LP:
  9577. lpfc_pci_remove_one_s3(pdev);
  9578. break;
  9579. case LPFC_PCI_DEV_OC:
  9580. lpfc_pci_remove_one_s4(pdev);
  9581. break;
  9582. default:
  9583. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9584. "1424 Invalid PCI device group: 0x%x\n",
  9585. phba->pci_dev_grp);
  9586. break;
  9587. }
  9588. return;
  9589. }
  9590. /**
  9591. * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
  9592. * @pdev: pointer to PCI device
  9593. * @msg: power management message
  9594. *
  9595. * This routine is to be registered to the kernel's PCI subsystem to support
  9596. * system Power Management (PM). When PM invokes this method, it dispatches
  9597. * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
  9598. * suspend the device.
  9599. *
  9600. * Return code
  9601. * 0 - driver suspended the device
  9602. * Error otherwise
  9603. **/
  9604. static int
  9605. lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
  9606. {
  9607. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9608. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9609. int rc = -ENODEV;
  9610. switch (phba->pci_dev_grp) {
  9611. case LPFC_PCI_DEV_LP:
  9612. rc = lpfc_pci_suspend_one_s3(pdev, msg);
  9613. break;
  9614. case LPFC_PCI_DEV_OC:
  9615. rc = lpfc_pci_suspend_one_s4(pdev, msg);
  9616. break;
  9617. default:
  9618. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9619. "1425 Invalid PCI device group: 0x%x\n",
  9620. phba->pci_dev_grp);
  9621. break;
  9622. }
  9623. return rc;
  9624. }
  9625. /**
  9626. * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
  9627. * @pdev: pointer to PCI device
  9628. *
  9629. * This routine is to be registered to the kernel's PCI subsystem to support
  9630. * system Power Management (PM). When PM invokes this method, it dispatches
  9631. * the action to the proper SLI-3 or SLI-4 device resume routine, which will
  9632. * resume the device.
  9633. *
  9634. * Return code
  9635. * 0 - driver suspended the device
  9636. * Error otherwise
  9637. **/
  9638. static int
  9639. lpfc_pci_resume_one(struct pci_dev *pdev)
  9640. {
  9641. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9642. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9643. int rc = -ENODEV;
  9644. switch (phba->pci_dev_grp) {
  9645. case LPFC_PCI_DEV_LP:
  9646. rc = lpfc_pci_resume_one_s3(pdev);
  9647. break;
  9648. case LPFC_PCI_DEV_OC:
  9649. rc = lpfc_pci_resume_one_s4(pdev);
  9650. break;
  9651. default:
  9652. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9653. "1426 Invalid PCI device group: 0x%x\n",
  9654. phba->pci_dev_grp);
  9655. break;
  9656. }
  9657. return rc;
  9658. }
  9659. /**
  9660. * lpfc_io_error_detected - lpfc method for handling PCI I/O error
  9661. * @pdev: pointer to PCI device.
  9662. * @state: the current PCI connection state.
  9663. *
  9664. * This routine is registered to the PCI subsystem for error handling. This
  9665. * function is called by the PCI subsystem after a PCI bus error affecting
  9666. * this device has been detected. When this routine is invoked, it dispatches
  9667. * the action to the proper SLI-3 or SLI-4 device error detected handling
  9668. * routine, which will perform the proper error detected operation.
  9669. *
  9670. * Return codes
  9671. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  9672. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9673. **/
  9674. static pci_ers_result_t
  9675. lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  9676. {
  9677. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9678. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9679. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  9680. switch (phba->pci_dev_grp) {
  9681. case LPFC_PCI_DEV_LP:
  9682. rc = lpfc_io_error_detected_s3(pdev, state);
  9683. break;
  9684. case LPFC_PCI_DEV_OC:
  9685. rc = lpfc_io_error_detected_s4(pdev, state);
  9686. break;
  9687. default:
  9688. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9689. "1427 Invalid PCI device group: 0x%x\n",
  9690. phba->pci_dev_grp);
  9691. break;
  9692. }
  9693. return rc;
  9694. }
  9695. /**
  9696. * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
  9697. * @pdev: pointer to PCI device.
  9698. *
  9699. * This routine is registered to the PCI subsystem for error handling. This
  9700. * function is called after PCI bus has been reset to restart the PCI card
  9701. * from scratch, as if from a cold-boot. When this routine is invoked, it
  9702. * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
  9703. * routine, which will perform the proper device reset.
  9704. *
  9705. * Return codes
  9706. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  9707. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9708. **/
  9709. static pci_ers_result_t
  9710. lpfc_io_slot_reset(struct pci_dev *pdev)
  9711. {
  9712. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9713. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9714. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  9715. switch (phba->pci_dev_grp) {
  9716. case LPFC_PCI_DEV_LP:
  9717. rc = lpfc_io_slot_reset_s3(pdev);
  9718. break;
  9719. case LPFC_PCI_DEV_OC:
  9720. rc = lpfc_io_slot_reset_s4(pdev);
  9721. break;
  9722. default:
  9723. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9724. "1428 Invalid PCI device group: 0x%x\n",
  9725. phba->pci_dev_grp);
  9726. break;
  9727. }
  9728. return rc;
  9729. }
  9730. /**
  9731. * lpfc_io_resume - lpfc method for resuming PCI I/O operation
  9732. * @pdev: pointer to PCI device
  9733. *
  9734. * This routine is registered to the PCI subsystem for error handling. It
  9735. * is called when kernel error recovery tells the lpfc driver that it is
  9736. * OK to resume normal PCI operation after PCI bus error recovery. When
  9737. * this routine is invoked, it dispatches the action to the proper SLI-3
  9738. * or SLI-4 device io_resume routine, which will resume the device operation.
  9739. **/
  9740. static void
  9741. lpfc_io_resume(struct pci_dev *pdev)
  9742. {
  9743. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9744. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9745. switch (phba->pci_dev_grp) {
  9746. case LPFC_PCI_DEV_LP:
  9747. lpfc_io_resume_s3(pdev);
  9748. break;
  9749. case LPFC_PCI_DEV_OC:
  9750. lpfc_io_resume_s4(pdev);
  9751. break;
  9752. default:
  9753. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9754. "1429 Invalid PCI device group: 0x%x\n",
  9755. phba->pci_dev_grp);
  9756. break;
  9757. }
  9758. return;
  9759. }
  9760. static struct pci_device_id lpfc_id_table[] = {
  9761. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  9762. PCI_ANY_ID, PCI_ANY_ID, },
  9763. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  9764. PCI_ANY_ID, PCI_ANY_ID, },
  9765. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  9766. PCI_ANY_ID, PCI_ANY_ID, },
  9767. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  9768. PCI_ANY_ID, PCI_ANY_ID, },
  9769. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  9770. PCI_ANY_ID, PCI_ANY_ID, },
  9771. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  9772. PCI_ANY_ID, PCI_ANY_ID, },
  9773. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  9774. PCI_ANY_ID, PCI_ANY_ID, },
  9775. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  9776. PCI_ANY_ID, PCI_ANY_ID, },
  9777. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  9778. PCI_ANY_ID, PCI_ANY_ID, },
  9779. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  9780. PCI_ANY_ID, PCI_ANY_ID, },
  9781. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  9782. PCI_ANY_ID, PCI_ANY_ID, },
  9783. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  9784. PCI_ANY_ID, PCI_ANY_ID, },
  9785. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  9786. PCI_ANY_ID, PCI_ANY_ID, },
  9787. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  9788. PCI_ANY_ID, PCI_ANY_ID, },
  9789. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  9790. PCI_ANY_ID, PCI_ANY_ID, },
  9791. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  9792. PCI_ANY_ID, PCI_ANY_ID, },
  9793. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  9794. PCI_ANY_ID, PCI_ANY_ID, },
  9795. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  9796. PCI_ANY_ID, PCI_ANY_ID, },
  9797. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
  9798. PCI_ANY_ID, PCI_ANY_ID, },
  9799. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  9800. PCI_ANY_ID, PCI_ANY_ID, },
  9801. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  9802. PCI_ANY_ID, PCI_ANY_ID, },
  9803. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  9804. PCI_ANY_ID, PCI_ANY_ID, },
  9805. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  9806. PCI_ANY_ID, PCI_ANY_ID, },
  9807. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  9808. PCI_ANY_ID, PCI_ANY_ID, },
  9809. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  9810. PCI_ANY_ID, PCI_ANY_ID, },
  9811. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  9812. PCI_ANY_ID, PCI_ANY_ID, },
  9813. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  9814. PCI_ANY_ID, PCI_ANY_ID, },
  9815. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  9816. PCI_ANY_ID, PCI_ANY_ID, },
  9817. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
  9818. PCI_ANY_ID, PCI_ANY_ID, },
  9819. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
  9820. PCI_ANY_ID, PCI_ANY_ID, },
  9821. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
  9822. PCI_ANY_ID, PCI_ANY_ID, },
  9823. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
  9824. PCI_ANY_ID, PCI_ANY_ID, },
  9825. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
  9826. PCI_ANY_ID, PCI_ANY_ID, },
  9827. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
  9828. PCI_ANY_ID, PCI_ANY_ID, },
  9829. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
  9830. PCI_ANY_ID, PCI_ANY_ID, },
  9831. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
  9832. PCI_ANY_ID, PCI_ANY_ID, },
  9833. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
  9834. PCI_ANY_ID, PCI_ANY_ID, },
  9835. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
  9836. PCI_ANY_ID, PCI_ANY_ID, },
  9837. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
  9838. PCI_ANY_ID, PCI_ANY_ID, },
  9839. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
  9840. PCI_ANY_ID, PCI_ANY_ID, },
  9841. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
  9842. PCI_ANY_ID, PCI_ANY_ID, },
  9843. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
  9844. PCI_ANY_ID, PCI_ANY_ID, },
  9845. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
  9846. PCI_ANY_ID, PCI_ANY_ID, },
  9847. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
  9848. PCI_ANY_ID, PCI_ANY_ID, },
  9849. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
  9850. PCI_ANY_ID, PCI_ANY_ID, },
  9851. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK,
  9852. PCI_ANY_ID, PCI_ANY_ID, },
  9853. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF,
  9854. PCI_ANY_ID, PCI_ANY_ID, },
  9855. { 0 }
  9856. };
  9857. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  9858. static const struct pci_error_handlers lpfc_err_handler = {
  9859. .error_detected = lpfc_io_error_detected,
  9860. .slot_reset = lpfc_io_slot_reset,
  9861. .resume = lpfc_io_resume,
  9862. };
  9863. static struct pci_driver lpfc_driver = {
  9864. .name = LPFC_DRIVER_NAME,
  9865. .id_table = lpfc_id_table,
  9866. .probe = lpfc_pci_probe_one,
  9867. .remove = lpfc_pci_remove_one,
  9868. .suspend = lpfc_pci_suspend_one,
  9869. .resume = lpfc_pci_resume_one,
  9870. .err_handler = &lpfc_err_handler,
  9871. };
  9872. static const struct file_operations lpfc_mgmt_fop = {
  9873. .owner = THIS_MODULE,
  9874. };
  9875. static struct miscdevice lpfc_mgmt_dev = {
  9876. .minor = MISC_DYNAMIC_MINOR,
  9877. .name = "lpfcmgmt",
  9878. .fops = &lpfc_mgmt_fop,
  9879. };
  9880. /**
  9881. * lpfc_init - lpfc module initialization routine
  9882. *
  9883. * This routine is to be invoked when the lpfc module is loaded into the
  9884. * kernel. The special kernel macro module_init() is used to indicate the
  9885. * role of this routine to the kernel as lpfc module entry point.
  9886. *
  9887. * Return codes
  9888. * 0 - successful
  9889. * -ENOMEM - FC attach transport failed
  9890. * all others - failed
  9891. */
  9892. static int __init
  9893. lpfc_init(void)
  9894. {
  9895. int cpu;
  9896. int error = 0;
  9897. printk(LPFC_MODULE_DESC "\n");
  9898. printk(LPFC_COPYRIGHT "\n");
  9899. error = misc_register(&lpfc_mgmt_dev);
  9900. if (error)
  9901. printk(KERN_ERR "Could not register lpfcmgmt device, "
  9902. "misc_register returned with status %d", error);
  9903. if (lpfc_enable_npiv) {
  9904. lpfc_transport_functions.vport_create = lpfc_vport_create;
  9905. lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  9906. }
  9907. lpfc_transport_template =
  9908. fc_attach_transport(&lpfc_transport_functions);
  9909. if (lpfc_transport_template == NULL)
  9910. return -ENOMEM;
  9911. if (lpfc_enable_npiv) {
  9912. lpfc_vport_transport_template =
  9913. fc_attach_transport(&lpfc_vport_transport_functions);
  9914. if (lpfc_vport_transport_template == NULL) {
  9915. fc_release_transport(lpfc_transport_template);
  9916. return -ENOMEM;
  9917. }
  9918. }
  9919. /* Initialize in case vector mapping is needed */
  9920. lpfc_used_cpu = NULL;
  9921. lpfc_present_cpu = 0;
  9922. for_each_present_cpu(cpu)
  9923. lpfc_present_cpu++;
  9924. error = pci_register_driver(&lpfc_driver);
  9925. if (error) {
  9926. fc_release_transport(lpfc_transport_template);
  9927. if (lpfc_enable_npiv)
  9928. fc_release_transport(lpfc_vport_transport_template);
  9929. }
  9930. return error;
  9931. }
  9932. /**
  9933. * lpfc_exit - lpfc module removal routine
  9934. *
  9935. * This routine is invoked when the lpfc module is removed from the kernel.
  9936. * The special kernel macro module_exit() is used to indicate the role of
  9937. * this routine to the kernel as lpfc module exit point.
  9938. */
  9939. static void __exit
  9940. lpfc_exit(void)
  9941. {
  9942. misc_deregister(&lpfc_mgmt_dev);
  9943. pci_unregister_driver(&lpfc_driver);
  9944. fc_release_transport(lpfc_transport_template);
  9945. if (lpfc_enable_npiv)
  9946. fc_release_transport(lpfc_vport_transport_template);
  9947. if (_dump_buf_data) {
  9948. printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
  9949. "_dump_buf_data at 0x%p\n",
  9950. (1L << _dump_buf_data_order), _dump_buf_data);
  9951. free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
  9952. }
  9953. if (_dump_buf_dif) {
  9954. printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
  9955. "_dump_buf_dif at 0x%p\n",
  9956. (1L << _dump_buf_dif_order), _dump_buf_dif);
  9957. free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
  9958. }
  9959. kfree(lpfc_used_cpu);
  9960. }
  9961. module_init(lpfc_init);
  9962. module_exit(lpfc_exit);
  9963. MODULE_LICENSE("GPL");
  9964. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  9965. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  9966. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);