lpfc_init.c 302 KB

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