lpfc_init.c 309 KB

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