lpfc_init.c 317 KB

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