lpfc_init.c 299 KB

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