lpfc_init.c 270 KB

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