lpfc_init.c 306 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2011 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/delay.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/idr.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/module.h>
  27. #include <linux/kthread.h>
  28. #include <linux/pci.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/ctype.h>
  31. #include <linux/aer.h>
  32. #include <linux/slab.h>
  33. #include <linux/firmware.h>
  34. #include <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_sgl_list(struct lpfc_hba *);
  63. static int lpfc_init_sgl_list(struct lpfc_hba *);
  64. static int lpfc_init_active_sgl_array(struct lpfc_hba *);
  65. static void lpfc_free_active_sgl(struct lpfc_hba *);
  66. static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
  67. static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
  68. static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
  69. static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
  70. static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
  71. static struct scsi_transport_template *lpfc_transport_template = NULL;
  72. static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
  73. static DEFINE_IDR(lpfc_hba_index);
  74. /**
  75. * lpfc_config_port_prep - Perform lpfc initialization prior to config port
  76. * @phba: pointer to lpfc hba data structure.
  77. *
  78. * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
  79. * mailbox command. It retrieves the revision information from the HBA and
  80. * collects the Vital Product Data (VPD) about the HBA for preparing the
  81. * configuration of the HBA.
  82. *
  83. * Return codes:
  84. * 0 - success.
  85. * -ERESTART - requests the SLI layer to reset the HBA and try again.
  86. * Any other value - indicates an error.
  87. **/
  88. int
  89. lpfc_config_port_prep(struct lpfc_hba *phba)
  90. {
  91. lpfc_vpd_t *vp = &phba->vpd;
  92. int i = 0, rc;
  93. LPFC_MBOXQ_t *pmb;
  94. MAILBOX_t *mb;
  95. char *lpfc_vpd_data = NULL;
  96. uint16_t offset = 0;
  97. static char licensed[56] =
  98. "key unlock for use with gnu public licensed code only\0";
  99. static int init_key = 1;
  100. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  101. if (!pmb) {
  102. phba->link_state = LPFC_HBA_ERROR;
  103. return -ENOMEM;
  104. }
  105. mb = &pmb->u.mb;
  106. phba->link_state = LPFC_INIT_MBX_CMDS;
  107. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  108. if (init_key) {
  109. uint32_t *ptext = (uint32_t *) licensed;
  110. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  111. *ptext = cpu_to_be32(*ptext);
  112. init_key = 0;
  113. }
  114. lpfc_read_nv(phba, pmb);
  115. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  116. sizeof (mb->un.varRDnvp.rsvd3));
  117. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  118. sizeof (licensed));
  119. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  120. if (rc != MBX_SUCCESS) {
  121. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  122. "0324 Config Port initialization "
  123. "error, mbxCmd x%x READ_NVPARM, "
  124. "mbxStatus x%x\n",
  125. mb->mbxCommand, mb->mbxStatus);
  126. mempool_free(pmb, phba->mbox_mem_pool);
  127. return -ERESTART;
  128. }
  129. memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
  130. sizeof(phba->wwnn));
  131. memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
  132. sizeof(phba->wwpn));
  133. }
  134. phba->sli3_options = 0x0;
  135. /* Setup and issue mailbox READ REV command */
  136. lpfc_read_rev(phba, pmb);
  137. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  138. if (rc != MBX_SUCCESS) {
  139. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  140. "0439 Adapter failed to init, mbxCmd x%x "
  141. "READ_REV, mbxStatus x%x\n",
  142. mb->mbxCommand, mb->mbxStatus);
  143. mempool_free( pmb, phba->mbox_mem_pool);
  144. return -ERESTART;
  145. }
  146. /*
  147. * The value of rr must be 1 since the driver set the cv field to 1.
  148. * This setting requires the FW to set all revision fields.
  149. */
  150. if (mb->un.varRdRev.rr == 0) {
  151. vp->rev.rBit = 0;
  152. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  153. "0440 Adapter failed to init, READ_REV has "
  154. "missing revision information.\n");
  155. mempool_free(pmb, phba->mbox_mem_pool);
  156. return -ERESTART;
  157. }
  158. if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
  159. mempool_free(pmb, phba->mbox_mem_pool);
  160. return -EINVAL;
  161. }
  162. /* Save information as VPD data */
  163. vp->rev.rBit = 1;
  164. memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
  165. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  166. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  167. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  168. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  169. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  170. vp->rev.smRev = mb->un.varRdRev.smRev;
  171. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  172. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  173. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  174. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  175. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  176. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  177. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  178. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  179. /* If the sli feature level is less then 9, we must
  180. * tear down all RPIs and VPIs on link down if NPIV
  181. * is enabled.
  182. */
  183. if (vp->rev.feaLevelHigh < 9)
  184. phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
  185. if (lpfc_is_LC_HBA(phba->pcidev->device))
  186. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  187. sizeof (phba->RandomData));
  188. /* Get adapter VPD information */
  189. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  190. if (!lpfc_vpd_data)
  191. goto out_free_mbox;
  192. do {
  193. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
  194. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  195. if (rc != MBX_SUCCESS) {
  196. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  197. "0441 VPD not present on adapter, "
  198. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  199. mb->mbxCommand, mb->mbxStatus);
  200. mb->un.varDmp.word_cnt = 0;
  201. }
  202. /* dump mem may return a zero when finished or we got a
  203. * mailbox error, either way we are done.
  204. */
  205. if (mb->un.varDmp.word_cnt == 0)
  206. break;
  207. if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
  208. mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
  209. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  210. lpfc_vpd_data + offset,
  211. mb->un.varDmp.word_cnt);
  212. offset += mb->un.varDmp.word_cnt;
  213. } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
  214. lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
  215. kfree(lpfc_vpd_data);
  216. out_free_mbox:
  217. mempool_free(pmb, phba->mbox_mem_pool);
  218. return 0;
  219. }
  220. /**
  221. * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
  222. * @phba: pointer to lpfc hba data structure.
  223. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  224. *
  225. * This is the completion handler for driver's configuring asynchronous event
  226. * mailbox command to the device. If the mailbox command returns successfully,
  227. * it will set internal async event support flag to 1; otherwise, it will
  228. * set internal async event support flag to 0.
  229. **/
  230. static void
  231. lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  232. {
  233. if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
  234. phba->temp_sensor_support = 1;
  235. else
  236. phba->temp_sensor_support = 0;
  237. mempool_free(pmboxq, phba->mbox_mem_pool);
  238. return;
  239. }
  240. /**
  241. * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
  242. * @phba: pointer to lpfc hba data structure.
  243. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  244. *
  245. * This is the completion handler for dump mailbox command for getting
  246. * wake up parameters. When this command complete, the response contain
  247. * Option rom version of the HBA. This function translate the version number
  248. * into a human readable string and store it in OptionROMVersion.
  249. **/
  250. static void
  251. lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  252. {
  253. struct prog_id *prg;
  254. uint32_t prog_id_word;
  255. char dist = ' ';
  256. /* character array used for decoding dist type. */
  257. char dist_char[] = "nabx";
  258. if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
  259. mempool_free(pmboxq, phba->mbox_mem_pool);
  260. return;
  261. }
  262. prg = (struct prog_id *) &prog_id_word;
  263. /* word 7 contain option rom version */
  264. prog_id_word = pmboxq->u.mb.un.varWords[7];
  265. /* Decode the Option rom version word to a readable string */
  266. if (prg->dist < 4)
  267. dist = dist_char[prg->dist];
  268. if ((prg->dist == 3) && (prg->num == 0))
  269. sprintf(phba->OptionROMVersion, "%d.%d%d",
  270. prg->ver, prg->rev, prg->lev);
  271. else
  272. sprintf(phba->OptionROMVersion, "%d.%d%d%c%d",
  273. prg->ver, prg->rev, prg->lev,
  274. dist, prg->num);
  275. mempool_free(pmboxq, phba->mbox_mem_pool);
  276. return;
  277. }
  278. /**
  279. * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
  280. * cfg_soft_wwnn, cfg_soft_wwpn
  281. * @vport: pointer to lpfc vport data structure.
  282. *
  283. *
  284. * Return codes
  285. * None.
  286. **/
  287. void
  288. lpfc_update_vport_wwn(struct lpfc_vport *vport)
  289. {
  290. /* If the soft name exists then update it using the service params */
  291. if (vport->phba->cfg_soft_wwnn)
  292. u64_to_wwn(vport->phba->cfg_soft_wwnn,
  293. vport->fc_sparam.nodeName.u.wwn);
  294. if (vport->phba->cfg_soft_wwpn)
  295. u64_to_wwn(vport->phba->cfg_soft_wwpn,
  296. vport->fc_sparam.portName.u.wwn);
  297. /*
  298. * If the name is empty or there exists a soft name
  299. * then copy the service params name, otherwise use the fc name
  300. */
  301. if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
  302. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  303. sizeof(struct lpfc_name));
  304. else
  305. memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
  306. sizeof(struct lpfc_name));
  307. if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn)
  308. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  309. sizeof(struct lpfc_name));
  310. else
  311. memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
  312. sizeof(struct lpfc_name));
  313. }
  314. /**
  315. * lpfc_config_port_post - Perform lpfc initialization after config port
  316. * @phba: pointer to lpfc hba data structure.
  317. *
  318. * This routine will do LPFC initialization after the CONFIG_PORT mailbox
  319. * command call. It performs all internal resource and state setups on the
  320. * port: post IOCB buffers, enable appropriate host interrupt attentions,
  321. * ELS ring timers, etc.
  322. *
  323. * Return codes
  324. * 0 - success.
  325. * Any other value - error.
  326. **/
  327. int
  328. lpfc_config_port_post(struct lpfc_hba *phba)
  329. {
  330. struct lpfc_vport *vport = phba->pport;
  331. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  332. LPFC_MBOXQ_t *pmb;
  333. MAILBOX_t *mb;
  334. struct lpfc_dmabuf *mp;
  335. struct lpfc_sli *psli = &phba->sli;
  336. uint32_t status, timeout;
  337. int i, j;
  338. int rc;
  339. spin_lock_irq(&phba->hbalock);
  340. /*
  341. * If the Config port completed correctly the HBA is not
  342. * over heated any more.
  343. */
  344. if (phba->over_temp_state == HBA_OVER_TEMP)
  345. phba->over_temp_state = HBA_NORMAL_TEMP;
  346. spin_unlock_irq(&phba->hbalock);
  347. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  348. if (!pmb) {
  349. phba->link_state = LPFC_HBA_ERROR;
  350. return -ENOMEM;
  351. }
  352. mb = &pmb->u.mb;
  353. /* Get login parameters for NID. */
  354. rc = lpfc_read_sparam(phba, pmb, 0);
  355. if (rc) {
  356. mempool_free(pmb, phba->mbox_mem_pool);
  357. return -ENOMEM;
  358. }
  359. pmb->vport = vport;
  360. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  361. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  362. "0448 Adapter failed init, mbxCmd x%x "
  363. "READ_SPARM mbxStatus x%x\n",
  364. mb->mbxCommand, mb->mbxStatus);
  365. phba->link_state = LPFC_HBA_ERROR;
  366. mp = (struct lpfc_dmabuf *) pmb->context1;
  367. mempool_free(pmb, phba->mbox_mem_pool);
  368. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  369. kfree(mp);
  370. return -EIO;
  371. }
  372. mp = (struct lpfc_dmabuf *) pmb->context1;
  373. memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
  374. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  375. kfree(mp);
  376. pmb->context1 = NULL;
  377. lpfc_update_vport_wwn(vport);
  378. /* Update the fc_host data structures with new wwn. */
  379. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  380. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  381. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  382. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  383. /* This should be consolidated into parse_vpd ? - mr */
  384. if (phba->SerialNumber[0] == 0) {
  385. uint8_t *outptr;
  386. outptr = &vport->fc_nodename.u.s.IEEE[0];
  387. for (i = 0; i < 12; i++) {
  388. status = *outptr++;
  389. j = ((status & 0xf0) >> 4);
  390. if (j <= 9)
  391. phba->SerialNumber[i] =
  392. (char)((uint8_t) 0x30 + (uint8_t) j);
  393. else
  394. phba->SerialNumber[i] =
  395. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  396. i++;
  397. j = (status & 0xf);
  398. if (j <= 9)
  399. phba->SerialNumber[i] =
  400. (char)((uint8_t) 0x30 + (uint8_t) j);
  401. else
  402. phba->SerialNumber[i] =
  403. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  404. }
  405. }
  406. lpfc_read_config(phba, pmb);
  407. pmb->vport = vport;
  408. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  409. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  410. "0453 Adapter failed to init, mbxCmd x%x "
  411. "READ_CONFIG, mbxStatus x%x\n",
  412. mb->mbxCommand, mb->mbxStatus);
  413. phba->link_state = LPFC_HBA_ERROR;
  414. mempool_free( pmb, phba->mbox_mem_pool);
  415. return -EIO;
  416. }
  417. /* Check if the port is disabled */
  418. lpfc_sli_read_link_ste(phba);
  419. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  420. if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
  421. phba->cfg_hba_queue_depth =
  422. (mb->un.varRdConfig.max_xri + 1) -
  423. lpfc_sli4_get_els_iocb_cnt(phba);
  424. phba->lmt = mb->un.varRdConfig.lmt;
  425. /* Get the default values for Model Name and Description */
  426. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  427. 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. /*
  2475. * Whenever an SLI4 port goes offline, free the
  2476. * RPI. A new RPI when the adapter port comes
  2477. * back online.
  2478. */
  2479. if (phba->sli_rev == LPFC_SLI_REV4)
  2480. lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
  2481. spin_unlock_irq(shost->host_lock);
  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_buf_update - Update the scsi_buffers that are already allocated.
  2533. * @phba: pointer to lpfc hba data structure.
  2534. *
  2535. * This routine goes through all the scsi buffers in the system and updates the
  2536. * Physical XRIs assigned to the SCSI buffer because these may change after any
  2537. * firmware reset
  2538. *
  2539. * Return codes
  2540. * 0 - successful (for now, it always returns 0)
  2541. **/
  2542. int
  2543. lpfc_scsi_buf_update(struct lpfc_hba *phba)
  2544. {
  2545. struct lpfc_scsi_buf *sb, *sb_next;
  2546. spin_lock_irq(&phba->hbalock);
  2547. spin_lock(&phba->scsi_buf_list_lock);
  2548. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list)
  2549. sb->cur_iocbq.sli4_xritag =
  2550. phba->sli4_hba.xri_ids[sb->cur_iocbq.sli4_lxritag];
  2551. spin_unlock(&phba->scsi_buf_list_lock);
  2552. spin_unlock_irq(&phba->hbalock);
  2553. return 0;
  2554. }
  2555. /**
  2556. * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
  2557. * @phba: pointer to lpfc hba data structure.
  2558. *
  2559. * This routine is to free all the SCSI buffers and IOCBs from the driver
  2560. * list back to kernel. It is called from lpfc_pci_remove_one to free
  2561. * the internal resources before the device is removed from the system.
  2562. *
  2563. * Return codes
  2564. * 0 - successful (for now, it always returns 0)
  2565. **/
  2566. static int
  2567. lpfc_scsi_free(struct lpfc_hba *phba)
  2568. {
  2569. struct lpfc_scsi_buf *sb, *sb_next;
  2570. struct lpfc_iocbq *io, *io_next;
  2571. spin_lock_irq(&phba->hbalock);
  2572. /* Release all the lpfc_scsi_bufs maintained by this host. */
  2573. spin_lock(&phba->scsi_buf_list_lock);
  2574. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
  2575. list_del(&sb->list);
  2576. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  2577. sb->dma_handle);
  2578. kfree(sb);
  2579. phba->total_scsi_bufs--;
  2580. }
  2581. spin_unlock(&phba->scsi_buf_list_lock);
  2582. /* Release all the lpfc_iocbq entries maintained by this host. */
  2583. list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
  2584. list_del(&io->list);
  2585. kfree(io);
  2586. phba->total_iocbq_bufs--;
  2587. }
  2588. spin_unlock_irq(&phba->hbalock);
  2589. return 0;
  2590. }
  2591. /**
  2592. * lpfc_create_port - Create an FC port
  2593. * @phba: pointer to lpfc hba data structure.
  2594. * @instance: a unique integer ID to this FC port.
  2595. * @dev: pointer to the device data structure.
  2596. *
  2597. * This routine creates a FC port for the upper layer protocol. The FC port
  2598. * can be created on top of either a physical port or a virtual port provided
  2599. * by the HBA. This routine also allocates a SCSI host data structure (shost)
  2600. * and associates the FC port created before adding the shost into the SCSI
  2601. * layer.
  2602. *
  2603. * Return codes
  2604. * @vport - pointer to the virtual N_Port data structure.
  2605. * NULL - port create failed.
  2606. **/
  2607. struct lpfc_vport *
  2608. lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
  2609. {
  2610. struct lpfc_vport *vport;
  2611. struct Scsi_Host *shost;
  2612. int error = 0;
  2613. if (dev != &phba->pcidev->dev)
  2614. shost = scsi_host_alloc(&lpfc_vport_template,
  2615. sizeof(struct lpfc_vport));
  2616. else
  2617. shost = scsi_host_alloc(&lpfc_template,
  2618. sizeof(struct lpfc_vport));
  2619. if (!shost)
  2620. goto out;
  2621. vport = (struct lpfc_vport *) shost->hostdata;
  2622. vport->phba = phba;
  2623. vport->load_flag |= FC_LOADING;
  2624. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2625. vport->fc_rscn_flush = 0;
  2626. lpfc_get_vport_cfgparam(vport);
  2627. shost->unique_id = instance;
  2628. shost->max_id = LPFC_MAX_TARGET;
  2629. shost->max_lun = vport->cfg_max_luns;
  2630. shost->this_id = -1;
  2631. shost->max_cmd_len = 16;
  2632. if (phba->sli_rev == LPFC_SLI_REV4) {
  2633. shost->dma_boundary =
  2634. phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
  2635. shost->sg_tablesize = phba->cfg_sg_seg_cnt;
  2636. }
  2637. /*
  2638. * Set initial can_queue value since 0 is no longer supported and
  2639. * scsi_add_host will fail. This will be adjusted later based on the
  2640. * max xri value determined in hba setup.
  2641. */
  2642. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  2643. if (dev != &phba->pcidev->dev) {
  2644. shost->transportt = lpfc_vport_transport_template;
  2645. vport->port_type = LPFC_NPIV_PORT;
  2646. } else {
  2647. shost->transportt = lpfc_transport_template;
  2648. vport->port_type = LPFC_PHYSICAL_PORT;
  2649. }
  2650. /* Initialize all internally managed lists. */
  2651. INIT_LIST_HEAD(&vport->fc_nodes);
  2652. INIT_LIST_HEAD(&vport->rcv_buffer_list);
  2653. spin_lock_init(&vport->work_port_lock);
  2654. init_timer(&vport->fc_disctmo);
  2655. vport->fc_disctmo.function = lpfc_disc_timeout;
  2656. vport->fc_disctmo.data = (unsigned long)vport;
  2657. init_timer(&vport->fc_fdmitmo);
  2658. vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
  2659. vport->fc_fdmitmo.data = (unsigned long)vport;
  2660. init_timer(&vport->els_tmofunc);
  2661. vport->els_tmofunc.function = lpfc_els_timeout;
  2662. vport->els_tmofunc.data = (unsigned long)vport;
  2663. init_timer(&vport->delayed_disc_tmo);
  2664. vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
  2665. vport->delayed_disc_tmo.data = (unsigned long)vport;
  2666. error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
  2667. if (error)
  2668. goto out_put_shost;
  2669. spin_lock_irq(&phba->hbalock);
  2670. list_add_tail(&vport->listentry, &phba->port_list);
  2671. spin_unlock_irq(&phba->hbalock);
  2672. return vport;
  2673. out_put_shost:
  2674. scsi_host_put(shost);
  2675. out:
  2676. return NULL;
  2677. }
  2678. /**
  2679. * destroy_port - destroy an FC port
  2680. * @vport: pointer to an lpfc virtual N_Port data structure.
  2681. *
  2682. * This routine destroys a FC port from the upper layer protocol. All the
  2683. * resources associated with the port are released.
  2684. **/
  2685. void
  2686. destroy_port(struct lpfc_vport *vport)
  2687. {
  2688. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2689. struct lpfc_hba *phba = vport->phba;
  2690. lpfc_debugfs_terminate(vport);
  2691. fc_remove_host(shost);
  2692. scsi_remove_host(shost);
  2693. spin_lock_irq(&phba->hbalock);
  2694. list_del_init(&vport->listentry);
  2695. spin_unlock_irq(&phba->hbalock);
  2696. lpfc_cleanup(vport);
  2697. return;
  2698. }
  2699. /**
  2700. * lpfc_get_instance - Get a unique integer ID
  2701. *
  2702. * This routine allocates a unique integer ID from lpfc_hba_index pool. It
  2703. * uses the kernel idr facility to perform the task.
  2704. *
  2705. * Return codes:
  2706. * instance - a unique integer ID allocated as the new instance.
  2707. * -1 - lpfc get instance failed.
  2708. **/
  2709. int
  2710. lpfc_get_instance(void)
  2711. {
  2712. int instance = 0;
  2713. /* Assign an unused number */
  2714. if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
  2715. return -1;
  2716. if (idr_get_new(&lpfc_hba_index, NULL, &instance))
  2717. return -1;
  2718. return instance;
  2719. }
  2720. /**
  2721. * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
  2722. * @shost: pointer to SCSI host data structure.
  2723. * @time: elapsed time of the scan in jiffies.
  2724. *
  2725. * This routine is called by the SCSI layer with a SCSI host to determine
  2726. * whether the scan host is finished.
  2727. *
  2728. * Note: there is no scan_start function as adapter initialization will have
  2729. * asynchronously kicked off the link initialization.
  2730. *
  2731. * Return codes
  2732. * 0 - SCSI host scan is not over yet.
  2733. * 1 - SCSI host scan is over.
  2734. **/
  2735. int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
  2736. {
  2737. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2738. struct lpfc_hba *phba = vport->phba;
  2739. int stat = 0;
  2740. spin_lock_irq(shost->host_lock);
  2741. if (vport->load_flag & FC_UNLOADING) {
  2742. stat = 1;
  2743. goto finished;
  2744. }
  2745. if (time >= 30 * HZ) {
  2746. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2747. "0461 Scanning longer than 30 "
  2748. "seconds. Continuing initialization\n");
  2749. stat = 1;
  2750. goto finished;
  2751. }
  2752. if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
  2753. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2754. "0465 Link down longer than 15 "
  2755. "seconds. Continuing initialization\n");
  2756. stat = 1;
  2757. goto finished;
  2758. }
  2759. if (vport->port_state != LPFC_VPORT_READY)
  2760. goto finished;
  2761. if (vport->num_disc_nodes || vport->fc_prli_sent)
  2762. goto finished;
  2763. if (vport->fc_map_cnt == 0 && time < 2 * HZ)
  2764. goto finished;
  2765. if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
  2766. goto finished;
  2767. stat = 1;
  2768. finished:
  2769. spin_unlock_irq(shost->host_lock);
  2770. return stat;
  2771. }
  2772. /**
  2773. * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
  2774. * @shost: pointer to SCSI host data structure.
  2775. *
  2776. * This routine initializes a given SCSI host attributes on a FC port. The
  2777. * SCSI host can be either on top of a physical port or a virtual port.
  2778. **/
  2779. void lpfc_host_attrib_init(struct Scsi_Host *shost)
  2780. {
  2781. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2782. struct lpfc_hba *phba = vport->phba;
  2783. /*
  2784. * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
  2785. */
  2786. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  2787. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  2788. fc_host_supported_classes(shost) = FC_COS_CLASS3;
  2789. memset(fc_host_supported_fc4s(shost), 0,
  2790. sizeof(fc_host_supported_fc4s(shost)));
  2791. fc_host_supported_fc4s(shost)[2] = 1;
  2792. fc_host_supported_fc4s(shost)[7] = 1;
  2793. lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
  2794. sizeof fc_host_symbolic_name(shost));
  2795. fc_host_supported_speeds(shost) = 0;
  2796. if (phba->lmt & LMT_16Gb)
  2797. fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
  2798. if (phba->lmt & LMT_10Gb)
  2799. fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
  2800. if (phba->lmt & LMT_8Gb)
  2801. fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
  2802. if (phba->lmt & LMT_4Gb)
  2803. fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
  2804. if (phba->lmt & LMT_2Gb)
  2805. fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
  2806. if (phba->lmt & LMT_1Gb)
  2807. fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
  2808. fc_host_maxframe_size(shost) =
  2809. (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  2810. (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
  2811. fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
  2812. /* This value is also unchanging */
  2813. memset(fc_host_active_fc4s(shost), 0,
  2814. sizeof(fc_host_active_fc4s(shost)));
  2815. fc_host_active_fc4s(shost)[2] = 1;
  2816. fc_host_active_fc4s(shost)[7] = 1;
  2817. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  2818. spin_lock_irq(shost->host_lock);
  2819. vport->load_flag &= ~FC_LOADING;
  2820. spin_unlock_irq(shost->host_lock);
  2821. }
  2822. /**
  2823. * lpfc_stop_port_s3 - Stop SLI3 device port
  2824. * @phba: pointer to lpfc hba data structure.
  2825. *
  2826. * This routine is invoked to stop an SLI3 device port, it stops the device
  2827. * from generating interrupts and stops the device driver's timers for the
  2828. * device.
  2829. **/
  2830. static void
  2831. lpfc_stop_port_s3(struct lpfc_hba *phba)
  2832. {
  2833. /* Clear all interrupt enable conditions */
  2834. writel(0, phba->HCregaddr);
  2835. readl(phba->HCregaddr); /* flush */
  2836. /* Clear all pending interrupts */
  2837. writel(0xffffffff, phba->HAregaddr);
  2838. readl(phba->HAregaddr); /* flush */
  2839. /* Reset some HBA SLI setup states */
  2840. lpfc_stop_hba_timers(phba);
  2841. phba->pport->work_port_events = 0;
  2842. }
  2843. /**
  2844. * lpfc_stop_port_s4 - Stop SLI4 device port
  2845. * @phba: pointer to lpfc hba data structure.
  2846. *
  2847. * This routine is invoked to stop an SLI4 device port, it stops the device
  2848. * from generating interrupts and stops the device driver's timers for the
  2849. * device.
  2850. **/
  2851. static void
  2852. lpfc_stop_port_s4(struct lpfc_hba *phba)
  2853. {
  2854. /* Reset some HBA SLI4 setup states */
  2855. lpfc_stop_hba_timers(phba);
  2856. phba->pport->work_port_events = 0;
  2857. phba->sli4_hba.intr_enable = 0;
  2858. }
  2859. /**
  2860. * lpfc_stop_port - Wrapper function for stopping hba port
  2861. * @phba: Pointer to HBA context object.
  2862. *
  2863. * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
  2864. * the API jump table function pointer from the lpfc_hba struct.
  2865. **/
  2866. void
  2867. lpfc_stop_port(struct lpfc_hba *phba)
  2868. {
  2869. phba->lpfc_stop_port(phba);
  2870. }
  2871. /**
  2872. * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
  2873. * @phba: Pointer to hba for which this call is being executed.
  2874. *
  2875. * This routine starts the timer waiting for the FCF rediscovery to complete.
  2876. **/
  2877. void
  2878. lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
  2879. {
  2880. unsigned long fcf_redisc_wait_tmo =
  2881. (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
  2882. /* Start fcf rediscovery wait period timer */
  2883. mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
  2884. spin_lock_irq(&phba->hbalock);
  2885. /* Allow action to new fcf asynchronous event */
  2886. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
  2887. /* Mark the FCF rediscovery pending state */
  2888. phba->fcf.fcf_flag |= FCF_REDISC_PEND;
  2889. spin_unlock_irq(&phba->hbalock);
  2890. }
  2891. /**
  2892. * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
  2893. * @ptr: Map to lpfc_hba data structure pointer.
  2894. *
  2895. * This routine is invoked when waiting for FCF table rediscover has been
  2896. * timed out. If new FCF record(s) has (have) been discovered during the
  2897. * wait period, a new FCF event shall be added to the FCOE async event
  2898. * list, and then worker thread shall be waked up for processing from the
  2899. * worker thread context.
  2900. **/
  2901. void
  2902. lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
  2903. {
  2904. struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
  2905. /* Don't send FCF rediscovery event if timer cancelled */
  2906. spin_lock_irq(&phba->hbalock);
  2907. if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
  2908. spin_unlock_irq(&phba->hbalock);
  2909. return;
  2910. }
  2911. /* Clear FCF rediscovery timer pending flag */
  2912. phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
  2913. /* FCF rediscovery event to worker thread */
  2914. phba->fcf.fcf_flag |= FCF_REDISC_EVT;
  2915. spin_unlock_irq(&phba->hbalock);
  2916. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2917. "2776 FCF rediscover quiescent timer expired\n");
  2918. /* wake up worker thread */
  2919. lpfc_worker_wake_up(phba);
  2920. }
  2921. /**
  2922. * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
  2923. * @phba: pointer to lpfc hba data structure.
  2924. * @acqe_link: pointer to the async link completion queue entry.
  2925. *
  2926. * This routine is to parse the SLI4 link-attention link fault code and
  2927. * translate it into the base driver's read link attention mailbox command
  2928. * status.
  2929. *
  2930. * Return: Link-attention status in terms of base driver's coding.
  2931. **/
  2932. static uint16_t
  2933. lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
  2934. struct lpfc_acqe_link *acqe_link)
  2935. {
  2936. uint16_t latt_fault;
  2937. switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
  2938. case LPFC_ASYNC_LINK_FAULT_NONE:
  2939. case LPFC_ASYNC_LINK_FAULT_LOCAL:
  2940. case LPFC_ASYNC_LINK_FAULT_REMOTE:
  2941. latt_fault = 0;
  2942. break;
  2943. default:
  2944. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2945. "0398 Invalid link fault code: x%x\n",
  2946. bf_get(lpfc_acqe_link_fault, acqe_link));
  2947. latt_fault = MBXERR_ERROR;
  2948. break;
  2949. }
  2950. return latt_fault;
  2951. }
  2952. /**
  2953. * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
  2954. * @phba: pointer to lpfc hba data structure.
  2955. * @acqe_link: pointer to the async link completion queue entry.
  2956. *
  2957. * This routine is to parse the SLI4 link attention type and translate it
  2958. * into the base driver's link attention type coding.
  2959. *
  2960. * Return: Link attention type in terms of base driver's coding.
  2961. **/
  2962. static uint8_t
  2963. lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
  2964. struct lpfc_acqe_link *acqe_link)
  2965. {
  2966. uint8_t att_type;
  2967. switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
  2968. case LPFC_ASYNC_LINK_STATUS_DOWN:
  2969. case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
  2970. att_type = LPFC_ATT_LINK_DOWN;
  2971. break;
  2972. case LPFC_ASYNC_LINK_STATUS_UP:
  2973. /* Ignore physical link up events - wait for logical link up */
  2974. att_type = LPFC_ATT_RESERVED;
  2975. break;
  2976. case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
  2977. att_type = LPFC_ATT_LINK_UP;
  2978. break;
  2979. default:
  2980. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2981. "0399 Invalid link attention type: x%x\n",
  2982. bf_get(lpfc_acqe_link_status, acqe_link));
  2983. att_type = LPFC_ATT_RESERVED;
  2984. break;
  2985. }
  2986. return att_type;
  2987. }
  2988. /**
  2989. * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
  2990. * @phba: pointer to lpfc hba data structure.
  2991. * @acqe_link: pointer to the async link completion queue entry.
  2992. *
  2993. * This routine is to parse the SLI4 link-attention link speed and translate
  2994. * it into the base driver's link-attention link speed coding.
  2995. *
  2996. * Return: Link-attention link speed in terms of base driver's coding.
  2997. **/
  2998. static uint8_t
  2999. lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
  3000. struct lpfc_acqe_link *acqe_link)
  3001. {
  3002. uint8_t link_speed;
  3003. switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
  3004. case LPFC_ASYNC_LINK_SPEED_ZERO:
  3005. case LPFC_ASYNC_LINK_SPEED_10MBPS:
  3006. case LPFC_ASYNC_LINK_SPEED_100MBPS:
  3007. link_speed = LPFC_LINK_SPEED_UNKNOWN;
  3008. break;
  3009. case LPFC_ASYNC_LINK_SPEED_1GBPS:
  3010. link_speed = LPFC_LINK_SPEED_1GHZ;
  3011. break;
  3012. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  3013. link_speed = LPFC_LINK_SPEED_10GHZ;
  3014. break;
  3015. default:
  3016. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3017. "0483 Invalid link-attention link speed: x%x\n",
  3018. bf_get(lpfc_acqe_link_speed, acqe_link));
  3019. link_speed = LPFC_LINK_SPEED_UNKNOWN;
  3020. break;
  3021. }
  3022. return link_speed;
  3023. }
  3024. /**
  3025. * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
  3026. * @phba: pointer to lpfc hba data structure.
  3027. * @acqe_link: pointer to the async link completion queue entry.
  3028. *
  3029. * This routine is to handle the SLI4 asynchronous FCoE link event.
  3030. **/
  3031. static void
  3032. lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
  3033. struct lpfc_acqe_link *acqe_link)
  3034. {
  3035. struct lpfc_dmabuf *mp;
  3036. LPFC_MBOXQ_t *pmb;
  3037. MAILBOX_t *mb;
  3038. struct lpfc_mbx_read_top *la;
  3039. uint8_t att_type;
  3040. int rc;
  3041. att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
  3042. if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
  3043. return;
  3044. phba->fcoe_eventtag = acqe_link->event_tag;
  3045. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3046. if (!pmb) {
  3047. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3048. "0395 The mboxq allocation failed\n");
  3049. return;
  3050. }
  3051. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3052. if (!mp) {
  3053. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3054. "0396 The lpfc_dmabuf allocation failed\n");
  3055. goto out_free_pmb;
  3056. }
  3057. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  3058. if (!mp->virt) {
  3059. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3060. "0397 The mbuf allocation failed\n");
  3061. goto out_free_dmabuf;
  3062. }
  3063. /* Cleanup any outstanding ELS commands */
  3064. lpfc_els_flush_all_cmd(phba);
  3065. /* Block ELS IOCBs until we have done process link event */
  3066. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  3067. /* Update link event statistics */
  3068. phba->sli.slistat.link_event++;
  3069. /* Create lpfc_handle_latt mailbox command from link ACQE */
  3070. lpfc_read_topology(phba, pmb, mp);
  3071. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  3072. pmb->vport = phba->pport;
  3073. /* Keep the link status for extra SLI4 state machine reference */
  3074. phba->sli4_hba.link_state.speed =
  3075. bf_get(lpfc_acqe_link_speed, acqe_link);
  3076. phba->sli4_hba.link_state.duplex =
  3077. bf_get(lpfc_acqe_link_duplex, acqe_link);
  3078. phba->sli4_hba.link_state.status =
  3079. bf_get(lpfc_acqe_link_status, acqe_link);
  3080. phba->sli4_hba.link_state.type =
  3081. bf_get(lpfc_acqe_link_type, acqe_link);
  3082. phba->sli4_hba.link_state.number =
  3083. bf_get(lpfc_acqe_link_number, acqe_link);
  3084. phba->sli4_hba.link_state.fault =
  3085. bf_get(lpfc_acqe_link_fault, acqe_link);
  3086. phba->sli4_hba.link_state.logical_speed =
  3087. bf_get(lpfc_acqe_logical_link_speed, acqe_link);
  3088. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3089. "2900 Async FC/FCoE Link event - Speed:%dGBit "
  3090. "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
  3091. "Logical speed:%dMbps Fault:%d\n",
  3092. phba->sli4_hba.link_state.speed,
  3093. phba->sli4_hba.link_state.topology,
  3094. phba->sli4_hba.link_state.status,
  3095. phba->sli4_hba.link_state.type,
  3096. phba->sli4_hba.link_state.number,
  3097. phba->sli4_hba.link_state.logical_speed * 10,
  3098. phba->sli4_hba.link_state.fault);
  3099. /*
  3100. * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
  3101. * topology info. Note: Optional for non FC-AL ports.
  3102. */
  3103. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  3104. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3105. if (rc == MBX_NOT_FINISHED)
  3106. goto out_free_dmabuf;
  3107. return;
  3108. }
  3109. /*
  3110. * For FCoE Mode: fill in all the topology information we need and call
  3111. * the READ_TOPOLOGY completion routine to continue without actually
  3112. * sending the READ_TOPOLOGY mailbox command to the port.
  3113. */
  3114. /* Parse and translate status field */
  3115. mb = &pmb->u.mb;
  3116. mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
  3117. /* Parse and translate link attention fields */
  3118. la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
  3119. la->eventTag = acqe_link->event_tag;
  3120. bf_set(lpfc_mbx_read_top_att_type, la, att_type);
  3121. bf_set(lpfc_mbx_read_top_link_spd, la,
  3122. lpfc_sli4_parse_latt_link_speed(phba, acqe_link));
  3123. /* Fake the the following irrelvant fields */
  3124. bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
  3125. bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
  3126. bf_set(lpfc_mbx_read_top_il, la, 0);
  3127. bf_set(lpfc_mbx_read_top_pb, la, 0);
  3128. bf_set(lpfc_mbx_read_top_fa, la, 0);
  3129. bf_set(lpfc_mbx_read_top_mm, la, 0);
  3130. /* Invoke the lpfc_handle_latt mailbox command callback function */
  3131. lpfc_mbx_cmpl_read_topology(phba, pmb);
  3132. return;
  3133. out_free_dmabuf:
  3134. kfree(mp);
  3135. out_free_pmb:
  3136. mempool_free(pmb, phba->mbox_mem_pool);
  3137. }
  3138. /**
  3139. * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
  3140. * @phba: pointer to lpfc hba data structure.
  3141. * @acqe_fc: pointer to the async fc completion queue entry.
  3142. *
  3143. * This routine is to handle the SLI4 asynchronous FC event. It will simply log
  3144. * that the event was received and then issue a read_topology mailbox command so
  3145. * that the rest of the driver will treat it the same as SLI3.
  3146. **/
  3147. static void
  3148. lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
  3149. {
  3150. struct lpfc_dmabuf *mp;
  3151. LPFC_MBOXQ_t *pmb;
  3152. int rc;
  3153. if (bf_get(lpfc_trailer_type, acqe_fc) !=
  3154. LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
  3155. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3156. "2895 Non FC link Event detected.(%d)\n",
  3157. bf_get(lpfc_trailer_type, acqe_fc));
  3158. return;
  3159. }
  3160. /* Keep the link status for extra SLI4 state machine reference */
  3161. phba->sli4_hba.link_state.speed =
  3162. bf_get(lpfc_acqe_fc_la_speed, acqe_fc);
  3163. phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
  3164. phba->sli4_hba.link_state.topology =
  3165. bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
  3166. phba->sli4_hba.link_state.status =
  3167. bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
  3168. phba->sli4_hba.link_state.type =
  3169. bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
  3170. phba->sli4_hba.link_state.number =
  3171. bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
  3172. phba->sli4_hba.link_state.fault =
  3173. bf_get(lpfc_acqe_link_fault, acqe_fc);
  3174. phba->sli4_hba.link_state.logical_speed =
  3175. bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc);
  3176. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3177. "2896 Async FC event - Speed:%dGBaud Topology:x%x "
  3178. "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
  3179. "%dMbps Fault:%d\n",
  3180. phba->sli4_hba.link_state.speed,
  3181. phba->sli4_hba.link_state.topology,
  3182. phba->sli4_hba.link_state.status,
  3183. phba->sli4_hba.link_state.type,
  3184. phba->sli4_hba.link_state.number,
  3185. phba->sli4_hba.link_state.logical_speed * 10,
  3186. phba->sli4_hba.link_state.fault);
  3187. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3188. if (!pmb) {
  3189. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3190. "2897 The mboxq allocation failed\n");
  3191. return;
  3192. }
  3193. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3194. if (!mp) {
  3195. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3196. "2898 The lpfc_dmabuf allocation failed\n");
  3197. goto out_free_pmb;
  3198. }
  3199. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  3200. if (!mp->virt) {
  3201. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3202. "2899 The mbuf allocation failed\n");
  3203. goto out_free_dmabuf;
  3204. }
  3205. /* Cleanup any outstanding ELS commands */
  3206. lpfc_els_flush_all_cmd(phba);
  3207. /* Block ELS IOCBs until we have done process link event */
  3208. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  3209. /* Update link event statistics */
  3210. phba->sli.slistat.link_event++;
  3211. /* Create lpfc_handle_latt mailbox command from link ACQE */
  3212. lpfc_read_topology(phba, pmb, mp);
  3213. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  3214. pmb->vport = phba->pport;
  3215. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3216. if (rc == MBX_NOT_FINISHED)
  3217. goto out_free_dmabuf;
  3218. return;
  3219. out_free_dmabuf:
  3220. kfree(mp);
  3221. out_free_pmb:
  3222. mempool_free(pmb, phba->mbox_mem_pool);
  3223. }
  3224. /**
  3225. * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
  3226. * @phba: pointer to lpfc hba data structure.
  3227. * @acqe_fc: pointer to the async SLI completion queue entry.
  3228. *
  3229. * This routine is to handle the SLI4 asynchronous SLI events.
  3230. **/
  3231. static void
  3232. lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
  3233. {
  3234. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3235. "2901 Async SLI event - Event Data1:x%08x Event Data2:"
  3236. "x%08x SLI Event Type:%d",
  3237. acqe_sli->event_data1, acqe_sli->event_data2,
  3238. bf_get(lpfc_trailer_type, acqe_sli));
  3239. return;
  3240. }
  3241. /**
  3242. * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
  3243. * @vport: pointer to vport data structure.
  3244. *
  3245. * This routine is to perform Clear Virtual Link (CVL) on a vport in
  3246. * response to a CVL event.
  3247. *
  3248. * Return the pointer to the ndlp with the vport if successful, otherwise
  3249. * return NULL.
  3250. **/
  3251. static struct lpfc_nodelist *
  3252. lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
  3253. {
  3254. struct lpfc_nodelist *ndlp;
  3255. struct Scsi_Host *shost;
  3256. struct lpfc_hba *phba;
  3257. if (!vport)
  3258. return NULL;
  3259. phba = vport->phba;
  3260. if (!phba)
  3261. return NULL;
  3262. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  3263. if (!ndlp) {
  3264. /* Cannot find existing Fabric ndlp, so allocate a new one */
  3265. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  3266. if (!ndlp)
  3267. return 0;
  3268. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  3269. /* Set the node type */
  3270. ndlp->nlp_type |= NLP_FABRIC;
  3271. /* Put ndlp onto node list */
  3272. lpfc_enqueue_node(vport, ndlp);
  3273. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  3274. /* re-setup ndlp without removing from node list */
  3275. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  3276. if (!ndlp)
  3277. return 0;
  3278. }
  3279. if ((phba->pport->port_state < LPFC_FLOGI) &&
  3280. (phba->pport->port_state != LPFC_VPORT_FAILED))
  3281. return NULL;
  3282. /* If virtual link is not yet instantiated ignore CVL */
  3283. if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
  3284. && (vport->port_state != LPFC_VPORT_FAILED))
  3285. return NULL;
  3286. shost = lpfc_shost_from_vport(vport);
  3287. if (!shost)
  3288. return NULL;
  3289. lpfc_linkdown_port(vport);
  3290. lpfc_cleanup_pending_mbox(vport);
  3291. spin_lock_irq(shost->host_lock);
  3292. vport->fc_flag |= FC_VPORT_CVL_RCVD;
  3293. spin_unlock_irq(shost->host_lock);
  3294. return ndlp;
  3295. }
  3296. /**
  3297. * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
  3298. * @vport: pointer to lpfc hba data structure.
  3299. *
  3300. * This routine is to perform Clear Virtual Link (CVL) on all vports in
  3301. * response to a FCF dead event.
  3302. **/
  3303. static void
  3304. lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
  3305. {
  3306. struct lpfc_vport **vports;
  3307. int i;
  3308. vports = lpfc_create_vport_work_array(phba);
  3309. if (vports)
  3310. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  3311. lpfc_sli4_perform_vport_cvl(vports[i]);
  3312. lpfc_destroy_vport_work_array(phba, vports);
  3313. }
  3314. /**
  3315. * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
  3316. * @phba: pointer to lpfc hba data structure.
  3317. * @acqe_link: pointer to the async fcoe completion queue entry.
  3318. *
  3319. * This routine is to handle the SLI4 asynchronous fcoe event.
  3320. **/
  3321. static void
  3322. lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
  3323. struct lpfc_acqe_fip *acqe_fip)
  3324. {
  3325. uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
  3326. int rc;
  3327. struct lpfc_vport *vport;
  3328. struct lpfc_nodelist *ndlp;
  3329. struct Scsi_Host *shost;
  3330. int active_vlink_present;
  3331. struct lpfc_vport **vports;
  3332. int i;
  3333. phba->fc_eventTag = acqe_fip->event_tag;
  3334. phba->fcoe_eventtag = acqe_fip->event_tag;
  3335. switch (event_type) {
  3336. case LPFC_FIP_EVENT_TYPE_NEW_FCF:
  3337. case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
  3338. if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
  3339. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  3340. LOG_DISCOVERY,
  3341. "2546 New FCF event, evt_tag:x%x, "
  3342. "index:x%x\n",
  3343. acqe_fip->event_tag,
  3344. acqe_fip->index);
  3345. else
  3346. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
  3347. LOG_DISCOVERY,
  3348. "2788 FCF param modified event, "
  3349. "evt_tag:x%x, index:x%x\n",
  3350. acqe_fip->event_tag,
  3351. acqe_fip->index);
  3352. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3353. /*
  3354. * During period of FCF discovery, read the FCF
  3355. * table record indexed by the event to update
  3356. * FCF roundrobin failover eligible FCF bmask.
  3357. */
  3358. lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
  3359. LOG_DISCOVERY,
  3360. "2779 Read FCF (x%x) for updating "
  3361. "roundrobin FCF failover bmask\n",
  3362. acqe_fip->index);
  3363. rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
  3364. }
  3365. /* If the FCF discovery is in progress, do nothing. */
  3366. spin_lock_irq(&phba->hbalock);
  3367. if (phba->hba_flag & FCF_TS_INPROG) {
  3368. spin_unlock_irq(&phba->hbalock);
  3369. break;
  3370. }
  3371. /* If fast FCF failover rescan event is pending, do nothing */
  3372. if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
  3373. spin_unlock_irq(&phba->hbalock);
  3374. break;
  3375. }
  3376. /* If the FCF has been in discovered state, do nothing. */
  3377. if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
  3378. spin_unlock_irq(&phba->hbalock);
  3379. break;
  3380. }
  3381. spin_unlock_irq(&phba->hbalock);
  3382. /* Otherwise, scan the entire FCF table and re-discover SAN */
  3383. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  3384. "2770 Start FCF table scan per async FCF "
  3385. "event, evt_tag:x%x, index:x%x\n",
  3386. acqe_fip->event_tag, acqe_fip->index);
  3387. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
  3388. LPFC_FCOE_FCF_GET_FIRST);
  3389. if (rc)
  3390. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3391. "2547 Issue FCF scan read FCF mailbox "
  3392. "command failed (x%x)\n", rc);
  3393. break;
  3394. case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
  3395. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3396. "2548 FCF Table full count 0x%x tag 0x%x\n",
  3397. bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
  3398. acqe_fip->event_tag);
  3399. break;
  3400. case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
  3401. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3402. "2549 FCF (x%x) disconnected from network, "
  3403. "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
  3404. /*
  3405. * If we are in the middle of FCF failover process, clear
  3406. * the corresponding FCF bit in the roundrobin bitmap.
  3407. */
  3408. spin_lock_irq(&phba->hbalock);
  3409. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3410. spin_unlock_irq(&phba->hbalock);
  3411. /* Update FLOGI FCF failover eligible FCF bmask */
  3412. lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
  3413. break;
  3414. }
  3415. spin_unlock_irq(&phba->hbalock);
  3416. /* If the event is not for currently used fcf do nothing */
  3417. if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
  3418. break;
  3419. /*
  3420. * Otherwise, request the port to rediscover the entire FCF
  3421. * table for a fast recovery from case that the current FCF
  3422. * is no longer valid as we are not in the middle of FCF
  3423. * failover process already.
  3424. */
  3425. spin_lock_irq(&phba->hbalock);
  3426. /* Mark the fast failover process in progress */
  3427. phba->fcf.fcf_flag |= FCF_DEAD_DISC;
  3428. spin_unlock_irq(&phba->hbalock);
  3429. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  3430. "2771 Start FCF fast failover process due to "
  3431. "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
  3432. "\n", acqe_fip->event_tag, acqe_fip->index);
  3433. rc = lpfc_sli4_redisc_fcf_table(phba);
  3434. if (rc) {
  3435. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  3436. LOG_DISCOVERY,
  3437. "2772 Issue FCF rediscover mabilbox "
  3438. "command failed, fail through to FCF "
  3439. "dead event\n");
  3440. spin_lock_irq(&phba->hbalock);
  3441. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  3442. spin_unlock_irq(&phba->hbalock);
  3443. /*
  3444. * Last resort will fail over by treating this
  3445. * as a link down to FCF registration.
  3446. */
  3447. lpfc_sli4_fcf_dead_failthrough(phba);
  3448. } else {
  3449. /* Reset FCF roundrobin bmask for new discovery */
  3450. lpfc_sli4_clear_fcf_rr_bmask(phba);
  3451. /*
  3452. * Handling fast FCF failover to a DEAD FCF event is
  3453. * considered equalivant to receiving CVL to all vports.
  3454. */
  3455. lpfc_sli4_perform_all_vport_cvl(phba);
  3456. }
  3457. break;
  3458. case LPFC_FIP_EVENT_TYPE_CVL:
  3459. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3460. "2718 Clear Virtual Link Received for VPI 0x%x"
  3461. " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
  3462. vport = lpfc_find_vport_by_vpid(phba,
  3463. acqe_fip->index);
  3464. ndlp = lpfc_sli4_perform_vport_cvl(vport);
  3465. if (!ndlp)
  3466. break;
  3467. active_vlink_present = 0;
  3468. vports = lpfc_create_vport_work_array(phba);
  3469. if (vports) {
  3470. for (i = 0; i <= phba->max_vports && vports[i] != NULL;
  3471. i++) {
  3472. if ((!(vports[i]->fc_flag &
  3473. FC_VPORT_CVL_RCVD)) &&
  3474. (vports[i]->port_state > LPFC_FDISC)) {
  3475. active_vlink_present = 1;
  3476. break;
  3477. }
  3478. }
  3479. lpfc_destroy_vport_work_array(phba, vports);
  3480. }
  3481. if (active_vlink_present) {
  3482. /*
  3483. * If there are other active VLinks present,
  3484. * re-instantiate the Vlink using FDISC.
  3485. */
  3486. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  3487. shost = lpfc_shost_from_vport(vport);
  3488. spin_lock_irq(shost->host_lock);
  3489. ndlp->nlp_flag |= NLP_DELAY_TMO;
  3490. spin_unlock_irq(shost->host_lock);
  3491. ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
  3492. vport->port_state = LPFC_FDISC;
  3493. } else {
  3494. /*
  3495. * Otherwise, we request port to rediscover
  3496. * the entire FCF table for a fast recovery
  3497. * from possible case that the current FCF
  3498. * is no longer valid if we are not already
  3499. * in the FCF failover process.
  3500. */
  3501. spin_lock_irq(&phba->hbalock);
  3502. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3503. spin_unlock_irq(&phba->hbalock);
  3504. break;
  3505. }
  3506. /* Mark the fast failover process in progress */
  3507. phba->fcf.fcf_flag |= FCF_ACVL_DISC;
  3508. spin_unlock_irq(&phba->hbalock);
  3509. lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
  3510. LOG_DISCOVERY,
  3511. "2773 Start FCF failover per CVL, "
  3512. "evt_tag:x%x\n", acqe_fip->event_tag);
  3513. rc = lpfc_sli4_redisc_fcf_table(phba);
  3514. if (rc) {
  3515. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  3516. LOG_DISCOVERY,
  3517. "2774 Issue FCF rediscover "
  3518. "mabilbox command failed, "
  3519. "through to CVL event\n");
  3520. spin_lock_irq(&phba->hbalock);
  3521. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  3522. spin_unlock_irq(&phba->hbalock);
  3523. /*
  3524. * Last resort will be re-try on the
  3525. * the current registered FCF entry.
  3526. */
  3527. lpfc_retry_pport_discovery(phba);
  3528. } else
  3529. /*
  3530. * Reset FCF roundrobin bmask for new
  3531. * discovery.
  3532. */
  3533. lpfc_sli4_clear_fcf_rr_bmask(phba);
  3534. }
  3535. break;
  3536. default:
  3537. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3538. "0288 Unknown FCoE event type 0x%x event tag "
  3539. "0x%x\n", event_type, acqe_fip->event_tag);
  3540. break;
  3541. }
  3542. }
  3543. /**
  3544. * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
  3545. * @phba: pointer to lpfc hba data structure.
  3546. * @acqe_link: pointer to the async dcbx completion queue entry.
  3547. *
  3548. * This routine is to handle the SLI4 asynchronous dcbx event.
  3549. **/
  3550. static void
  3551. lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
  3552. struct lpfc_acqe_dcbx *acqe_dcbx)
  3553. {
  3554. phba->fc_eventTag = acqe_dcbx->event_tag;
  3555. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3556. "0290 The SLI4 DCBX asynchronous event is not "
  3557. "handled yet\n");
  3558. }
  3559. /**
  3560. * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
  3561. * @phba: pointer to lpfc hba data structure.
  3562. * @acqe_link: pointer to the async grp5 completion queue entry.
  3563. *
  3564. * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
  3565. * is an asynchronous notified of a logical link speed change. The Port
  3566. * reports the logical link speed in units of 10Mbps.
  3567. **/
  3568. static void
  3569. lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
  3570. struct lpfc_acqe_grp5 *acqe_grp5)
  3571. {
  3572. uint16_t prev_ll_spd;
  3573. phba->fc_eventTag = acqe_grp5->event_tag;
  3574. phba->fcoe_eventtag = acqe_grp5->event_tag;
  3575. prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
  3576. phba->sli4_hba.link_state.logical_speed =
  3577. (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5));
  3578. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3579. "2789 GRP5 Async Event: Updating logical link speed "
  3580. "from %dMbps to %dMbps\n", (prev_ll_spd * 10),
  3581. (phba->sli4_hba.link_state.logical_speed*10));
  3582. }
  3583. /**
  3584. * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
  3585. * @phba: pointer to lpfc hba data structure.
  3586. *
  3587. * This routine is invoked by the worker thread to process all the pending
  3588. * SLI4 asynchronous events.
  3589. **/
  3590. void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
  3591. {
  3592. struct lpfc_cq_event *cq_event;
  3593. /* First, declare the async event has been handled */
  3594. spin_lock_irq(&phba->hbalock);
  3595. phba->hba_flag &= ~ASYNC_EVENT;
  3596. spin_unlock_irq(&phba->hbalock);
  3597. /* Now, handle all the async events */
  3598. while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
  3599. /* Get the first event from the head of the event queue */
  3600. spin_lock_irq(&phba->hbalock);
  3601. list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
  3602. cq_event, struct lpfc_cq_event, list);
  3603. spin_unlock_irq(&phba->hbalock);
  3604. /* Process the asynchronous event */
  3605. switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
  3606. case LPFC_TRAILER_CODE_LINK:
  3607. lpfc_sli4_async_link_evt(phba,
  3608. &cq_event->cqe.acqe_link);
  3609. break;
  3610. case LPFC_TRAILER_CODE_FCOE:
  3611. lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
  3612. break;
  3613. case LPFC_TRAILER_CODE_DCBX:
  3614. lpfc_sli4_async_dcbx_evt(phba,
  3615. &cq_event->cqe.acqe_dcbx);
  3616. break;
  3617. case LPFC_TRAILER_CODE_GRP5:
  3618. lpfc_sli4_async_grp5_evt(phba,
  3619. &cq_event->cqe.acqe_grp5);
  3620. break;
  3621. case LPFC_TRAILER_CODE_FC:
  3622. lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
  3623. break;
  3624. case LPFC_TRAILER_CODE_SLI:
  3625. lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
  3626. break;
  3627. default:
  3628. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3629. "1804 Invalid asynchrous event code: "
  3630. "x%x\n", bf_get(lpfc_trailer_code,
  3631. &cq_event->cqe.mcqe_cmpl));
  3632. break;
  3633. }
  3634. /* Free the completion event processed to the free pool */
  3635. lpfc_sli4_cq_event_release(phba, cq_event);
  3636. }
  3637. }
  3638. /**
  3639. * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
  3640. * @phba: pointer to lpfc hba data structure.
  3641. *
  3642. * This routine is invoked by the worker thread to process FCF table
  3643. * rediscovery pending completion event.
  3644. **/
  3645. void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
  3646. {
  3647. int rc;
  3648. spin_lock_irq(&phba->hbalock);
  3649. /* Clear FCF rediscovery timeout event */
  3650. phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
  3651. /* Clear driver fast failover FCF record flag */
  3652. phba->fcf.failover_rec.flag = 0;
  3653. /* Set state for FCF fast failover */
  3654. phba->fcf.fcf_flag |= FCF_REDISC_FOV;
  3655. spin_unlock_irq(&phba->hbalock);
  3656. /* Scan FCF table from the first entry to re-discover SAN */
  3657. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  3658. "2777 Start post-quiescent FCF table scan\n");
  3659. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
  3660. if (rc)
  3661. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3662. "2747 Issue FCF scan read FCF mailbox "
  3663. "command failed 0x%x\n", rc);
  3664. }
  3665. /**
  3666. * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
  3667. * @phba: pointer to lpfc hba data structure.
  3668. * @dev_grp: The HBA PCI-Device group number.
  3669. *
  3670. * This routine is invoked to set up the per HBA PCI-Device group function
  3671. * API jump table entries.
  3672. *
  3673. * Return: 0 if success, otherwise -ENODEV
  3674. **/
  3675. int
  3676. lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  3677. {
  3678. int rc;
  3679. /* Set up lpfc PCI-device group */
  3680. phba->pci_dev_grp = dev_grp;
  3681. /* The LPFC_PCI_DEV_OC uses SLI4 */
  3682. if (dev_grp == LPFC_PCI_DEV_OC)
  3683. phba->sli_rev = LPFC_SLI_REV4;
  3684. /* Set up device INIT API function jump table */
  3685. rc = lpfc_init_api_table_setup(phba, dev_grp);
  3686. if (rc)
  3687. return -ENODEV;
  3688. /* Set up SCSI API function jump table */
  3689. rc = lpfc_scsi_api_table_setup(phba, dev_grp);
  3690. if (rc)
  3691. return -ENODEV;
  3692. /* Set up SLI API function jump table */
  3693. rc = lpfc_sli_api_table_setup(phba, dev_grp);
  3694. if (rc)
  3695. return -ENODEV;
  3696. /* Set up MBOX API function jump table */
  3697. rc = lpfc_mbox_api_table_setup(phba, dev_grp);
  3698. if (rc)
  3699. return -ENODEV;
  3700. return 0;
  3701. }
  3702. /**
  3703. * lpfc_log_intr_mode - Log the active interrupt mode
  3704. * @phba: pointer to lpfc hba data structure.
  3705. * @intr_mode: active interrupt mode adopted.
  3706. *
  3707. * This routine it invoked to log the currently used active interrupt mode
  3708. * to the device.
  3709. **/
  3710. static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
  3711. {
  3712. switch (intr_mode) {
  3713. case 0:
  3714. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3715. "0470 Enable INTx interrupt mode.\n");
  3716. break;
  3717. case 1:
  3718. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3719. "0481 Enabled MSI interrupt mode.\n");
  3720. break;
  3721. case 2:
  3722. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3723. "0480 Enabled MSI-X interrupt mode.\n");
  3724. break;
  3725. default:
  3726. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3727. "0482 Illegal interrupt mode.\n");
  3728. break;
  3729. }
  3730. return;
  3731. }
  3732. /**
  3733. * lpfc_enable_pci_dev - Enable a generic PCI device.
  3734. * @phba: pointer to lpfc hba data structure.
  3735. *
  3736. * This routine is invoked to enable the PCI device that is common to all
  3737. * PCI devices.
  3738. *
  3739. * Return codes
  3740. * 0 - successful
  3741. * other values - error
  3742. **/
  3743. static int
  3744. lpfc_enable_pci_dev(struct lpfc_hba *phba)
  3745. {
  3746. struct pci_dev *pdev;
  3747. int bars = 0;
  3748. /* Obtain PCI device reference */
  3749. if (!phba->pcidev)
  3750. goto out_error;
  3751. else
  3752. pdev = phba->pcidev;
  3753. /* Select PCI BARs */
  3754. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  3755. /* Enable PCI device */
  3756. if (pci_enable_device_mem(pdev))
  3757. goto out_error;
  3758. /* Request PCI resource for the device */
  3759. if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
  3760. goto out_disable_device;
  3761. /* Set up device as PCI master and save state for EEH */
  3762. pci_set_master(pdev);
  3763. pci_try_set_mwi(pdev);
  3764. pci_save_state(pdev);
  3765. /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
  3766. if (pci_find_capability(pdev, PCI_CAP_ID_EXP))
  3767. pdev->needs_freset = 1;
  3768. return 0;
  3769. out_disable_device:
  3770. pci_disable_device(pdev);
  3771. out_error:
  3772. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3773. "1401 Failed to enable pci device, bars:x%x\n", bars);
  3774. return -ENODEV;
  3775. }
  3776. /**
  3777. * lpfc_disable_pci_dev - Disable a generic PCI device.
  3778. * @phba: pointer to lpfc hba data structure.
  3779. *
  3780. * This routine is invoked to disable the PCI device that is common to all
  3781. * PCI devices.
  3782. **/
  3783. static void
  3784. lpfc_disable_pci_dev(struct lpfc_hba *phba)
  3785. {
  3786. struct pci_dev *pdev;
  3787. int bars;
  3788. /* Obtain PCI device reference */
  3789. if (!phba->pcidev)
  3790. return;
  3791. else
  3792. pdev = phba->pcidev;
  3793. /* Select PCI BARs */
  3794. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  3795. /* Release PCI resource and disable PCI device */
  3796. pci_release_selected_regions(pdev, bars);
  3797. pci_disable_device(pdev);
  3798. /* Null out PCI private reference to driver */
  3799. pci_set_drvdata(pdev, NULL);
  3800. return;
  3801. }
  3802. /**
  3803. * lpfc_reset_hba - Reset a hba
  3804. * @phba: pointer to lpfc hba data structure.
  3805. *
  3806. * This routine is invoked to reset a hba device. It brings the HBA
  3807. * offline, performs a board restart, and then brings the board back
  3808. * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
  3809. * on outstanding mailbox commands.
  3810. **/
  3811. void
  3812. lpfc_reset_hba(struct lpfc_hba *phba)
  3813. {
  3814. /* If resets are disabled then set error state and return. */
  3815. if (!phba->cfg_enable_hba_reset) {
  3816. phba->link_state = LPFC_HBA_ERROR;
  3817. return;
  3818. }
  3819. lpfc_offline_prep(phba);
  3820. lpfc_offline(phba);
  3821. lpfc_sli_brdrestart(phba);
  3822. lpfc_online(phba);
  3823. lpfc_unblock_mgmt_io(phba);
  3824. }
  3825. /**
  3826. * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
  3827. * @phba: pointer to lpfc hba data structure.
  3828. *
  3829. * This function enables the PCI SR-IOV virtual functions to a physical
  3830. * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
  3831. * enable the number of virtual functions to the physical function. As
  3832. * not all devices support SR-IOV, the return code from the pci_enable_sriov()
  3833. * API call does not considered as an error condition for most of the device.
  3834. **/
  3835. uint16_t
  3836. lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
  3837. {
  3838. struct pci_dev *pdev = phba->pcidev;
  3839. uint16_t nr_virtfn;
  3840. int pos;
  3841. pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
  3842. if (pos == 0)
  3843. return 0;
  3844. pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
  3845. return nr_virtfn;
  3846. }
  3847. /**
  3848. * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
  3849. * @phba: pointer to lpfc hba data structure.
  3850. * @nr_vfn: number of virtual functions to be enabled.
  3851. *
  3852. * This function enables the PCI SR-IOV virtual functions to a physical
  3853. * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
  3854. * enable the number of virtual functions to the physical function. As
  3855. * not all devices support SR-IOV, the return code from the pci_enable_sriov()
  3856. * API call does not considered as an error condition for most of the device.
  3857. **/
  3858. int
  3859. lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
  3860. {
  3861. struct pci_dev *pdev = phba->pcidev;
  3862. uint16_t max_nr_vfn;
  3863. int rc;
  3864. max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
  3865. if (nr_vfn > max_nr_vfn) {
  3866. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3867. "3057 Requested vfs (%d) greater than "
  3868. "supported vfs (%d)", nr_vfn, max_nr_vfn);
  3869. return -EINVAL;
  3870. }
  3871. rc = pci_enable_sriov(pdev, nr_vfn);
  3872. if (rc) {
  3873. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  3874. "2806 Failed to enable sriov on this device "
  3875. "with vfn number nr_vf:%d, rc:%d\n",
  3876. nr_vfn, rc);
  3877. } else
  3878. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  3879. "2807 Successful enable sriov on this device "
  3880. "with vfn number nr_vf:%d\n", nr_vfn);
  3881. return rc;
  3882. }
  3883. /**
  3884. * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
  3885. * @phba: pointer to lpfc hba data structure.
  3886. *
  3887. * This routine is invoked to set up the driver internal resources specific to
  3888. * support the SLI-3 HBA device it attached to.
  3889. *
  3890. * Return codes
  3891. * 0 - successful
  3892. * other values - error
  3893. **/
  3894. static int
  3895. lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
  3896. {
  3897. struct lpfc_sli *psli;
  3898. int rc;
  3899. /*
  3900. * Initialize timers used by driver
  3901. */
  3902. /* Heartbeat timer */
  3903. init_timer(&phba->hb_tmofunc);
  3904. phba->hb_tmofunc.function = lpfc_hb_timeout;
  3905. phba->hb_tmofunc.data = (unsigned long)phba;
  3906. psli = &phba->sli;
  3907. /* MBOX heartbeat timer */
  3908. init_timer(&psli->mbox_tmo);
  3909. psli->mbox_tmo.function = lpfc_mbox_timeout;
  3910. psli->mbox_tmo.data = (unsigned long) phba;
  3911. /* FCP polling mode timer */
  3912. init_timer(&phba->fcp_poll_timer);
  3913. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  3914. phba->fcp_poll_timer.data = (unsigned long) phba;
  3915. /* Fabric block timer */
  3916. init_timer(&phba->fabric_block_timer);
  3917. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  3918. phba->fabric_block_timer.data = (unsigned long) phba;
  3919. /* EA polling mode timer */
  3920. init_timer(&phba->eratt_poll);
  3921. phba->eratt_poll.function = lpfc_poll_eratt;
  3922. phba->eratt_poll.data = (unsigned long) phba;
  3923. /* Host attention work mask setup */
  3924. phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
  3925. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  3926. /* Get all the module params for configuring this host */
  3927. lpfc_get_cfgparam(phba);
  3928. if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
  3929. phba->menlo_flag |= HBA_MENLO_SUPPORT;
  3930. /* check for menlo minimum sg count */
  3931. if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
  3932. phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
  3933. }
  3934. /*
  3935. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  3936. * used to create the sg_dma_buf_pool must be dynamically calculated.
  3937. * 2 segments are added since the IOCB needs a command and response bde.
  3938. */
  3939. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  3940. sizeof(struct fcp_rsp) +
  3941. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
  3942. if (phba->cfg_enable_bg) {
  3943. phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT;
  3944. phba->cfg_sg_dma_buf_size +=
  3945. phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64);
  3946. }
  3947. /* Also reinitialize the host templates with new values. */
  3948. lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  3949. lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  3950. phba->max_vpi = LPFC_MAX_VPI;
  3951. /* This will be set to correct value after config_port mbox */
  3952. phba->max_vports = 0;
  3953. /*
  3954. * Initialize the SLI Layer to run with lpfc HBAs.
  3955. */
  3956. lpfc_sli_setup(phba);
  3957. lpfc_sli_queue_setup(phba);
  3958. /* Allocate device driver memory */
  3959. if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
  3960. return -ENOMEM;
  3961. /*
  3962. * Enable sr-iov virtual functions if supported and configured
  3963. * through the module parameter.
  3964. */
  3965. if (phba->cfg_sriov_nr_virtfn > 0) {
  3966. rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
  3967. phba->cfg_sriov_nr_virtfn);
  3968. if (rc) {
  3969. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  3970. "2808 Requested number of SR-IOV "
  3971. "virtual functions (%d) is not "
  3972. "supported\n",
  3973. phba->cfg_sriov_nr_virtfn);
  3974. phba->cfg_sriov_nr_virtfn = 0;
  3975. }
  3976. }
  3977. return 0;
  3978. }
  3979. /**
  3980. * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
  3981. * @phba: pointer to lpfc hba data structure.
  3982. *
  3983. * This routine is invoked to unset the driver internal resources set up
  3984. * specific for supporting the SLI-3 HBA device it attached to.
  3985. **/
  3986. static void
  3987. lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
  3988. {
  3989. /* Free device driver memory allocated */
  3990. lpfc_mem_free_all(phba);
  3991. return;
  3992. }
  3993. /**
  3994. * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
  3995. * @phba: pointer to lpfc hba data structure.
  3996. *
  3997. * This routine is invoked to set up the driver internal resources specific to
  3998. * support the SLI-4 HBA device it attached to.
  3999. *
  4000. * Return codes
  4001. * 0 - successful
  4002. * other values - error
  4003. **/
  4004. static int
  4005. lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
  4006. {
  4007. struct lpfc_sli *psli;
  4008. LPFC_MBOXQ_t *mboxq;
  4009. int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size;
  4010. uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
  4011. struct lpfc_mqe *mqe;
  4012. int longs, sli_family;
  4013. int sges_per_segment;
  4014. /* Before proceed, wait for POST done and device ready */
  4015. rc = lpfc_sli4_post_status_check(phba);
  4016. if (rc)
  4017. return -ENODEV;
  4018. /*
  4019. * Initialize timers used by driver
  4020. */
  4021. /* Heartbeat timer */
  4022. init_timer(&phba->hb_tmofunc);
  4023. phba->hb_tmofunc.function = lpfc_hb_timeout;
  4024. phba->hb_tmofunc.data = (unsigned long)phba;
  4025. init_timer(&phba->rrq_tmr);
  4026. phba->rrq_tmr.function = lpfc_rrq_timeout;
  4027. phba->rrq_tmr.data = (unsigned long)phba;
  4028. psli = &phba->sli;
  4029. /* MBOX heartbeat timer */
  4030. init_timer(&psli->mbox_tmo);
  4031. psli->mbox_tmo.function = lpfc_mbox_timeout;
  4032. psli->mbox_tmo.data = (unsigned long) phba;
  4033. /* Fabric block timer */
  4034. init_timer(&phba->fabric_block_timer);
  4035. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  4036. phba->fabric_block_timer.data = (unsigned long) phba;
  4037. /* EA polling mode timer */
  4038. init_timer(&phba->eratt_poll);
  4039. phba->eratt_poll.function = lpfc_poll_eratt;
  4040. phba->eratt_poll.data = (unsigned long) phba;
  4041. /* FCF rediscover timer */
  4042. init_timer(&phba->fcf.redisc_wait);
  4043. phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
  4044. phba->fcf.redisc_wait.data = (unsigned long)phba;
  4045. /*
  4046. * Control structure for handling external multi-buffer mailbox
  4047. * command pass-through.
  4048. */
  4049. memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
  4050. sizeof(struct lpfc_mbox_ext_buf_ctx));
  4051. INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
  4052. /*
  4053. * We need to do a READ_CONFIG mailbox command here before
  4054. * calling lpfc_get_cfgparam. For VFs this will report the
  4055. * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
  4056. * All of the resources allocated
  4057. * for this Port are tied to these values.
  4058. */
  4059. /* Get all the module params for configuring this host */
  4060. lpfc_get_cfgparam(phba);
  4061. phba->max_vpi = LPFC_MAX_VPI;
  4062. /* This will be set to correct value after the read_config mbox */
  4063. phba->max_vports = 0;
  4064. /* Program the default value of vlan_id and fc_map */
  4065. phba->valid_vlan = 0;
  4066. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4067. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4068. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4069. /* With BlockGuard we can have multiple SGEs per Data Segemnt */
  4070. sges_per_segment = 1;
  4071. if (phba->cfg_enable_bg)
  4072. sges_per_segment = 2;
  4073. /*
  4074. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  4075. * used to create the sg_dma_buf_pool must be dynamically calculated.
  4076. * 2 segments are added since the IOCB needs a command and response bde.
  4077. * To insure that the scsi sgl does not cross a 4k page boundary only
  4078. * sgl sizes of must be a power of 2.
  4079. */
  4080. buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) +
  4081. (((phba->cfg_sg_seg_cnt * sges_per_segment) + 2) *
  4082. sizeof(struct sli4_sge)));
  4083. sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf);
  4084. max_buf_size = LPFC_SLI4_MAX_BUF_SIZE;
  4085. switch (sli_family) {
  4086. case LPFC_SLI_INTF_FAMILY_BE2:
  4087. case LPFC_SLI_INTF_FAMILY_BE3:
  4088. /* There is a single hint for BE - 2 pages per BPL. */
  4089. if (bf_get(lpfc_sli_intf_sli_hint1, &phba->sli4_hba.sli_intf) ==
  4090. LPFC_SLI_INTF_SLI_HINT1_1)
  4091. max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE;
  4092. break;
  4093. case LPFC_SLI_INTF_FAMILY_LNCR_A0:
  4094. case LPFC_SLI_INTF_FAMILY_LNCR_B0:
  4095. default:
  4096. break;
  4097. }
  4098. for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE;
  4099. dma_buf_size < max_buf_size && buf_size > dma_buf_size;
  4100. dma_buf_size = dma_buf_size << 1)
  4101. ;
  4102. if (dma_buf_size == max_buf_size)
  4103. phba->cfg_sg_seg_cnt = (dma_buf_size -
  4104. sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) -
  4105. (2 * sizeof(struct sli4_sge))) /
  4106. sizeof(struct sli4_sge);
  4107. phba->cfg_sg_dma_buf_size = dma_buf_size;
  4108. /* Initialize buffer queue management fields */
  4109. hbq_count = lpfc_sli_hbq_count();
  4110. for (i = 0; i < hbq_count; ++i)
  4111. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  4112. INIT_LIST_HEAD(&phba->rb_pend_list);
  4113. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
  4114. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
  4115. /*
  4116. * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
  4117. */
  4118. /* Initialize the Abort scsi buffer list used by driver */
  4119. spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
  4120. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  4121. /* This abort list used by worker thread */
  4122. spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
  4123. /*
  4124. * Initialize driver internal slow-path work queues
  4125. */
  4126. /* Driver internel slow-path CQ Event pool */
  4127. INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
  4128. /* Response IOCB work queue list */
  4129. INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
  4130. /* Asynchronous event CQ Event work queue list */
  4131. INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
  4132. /* Fast-path XRI aborted CQ Event work queue list */
  4133. INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  4134. /* Slow-path XRI aborted CQ Event work queue list */
  4135. INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
  4136. /* Receive queue CQ Event work queue list */
  4137. INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
  4138. /* Initialize extent block lists. */
  4139. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
  4140. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
  4141. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
  4142. INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
  4143. /* Initialize the driver internal SLI layer lists. */
  4144. lpfc_sli_setup(phba);
  4145. lpfc_sli_queue_setup(phba);
  4146. /* Allocate device driver memory */
  4147. rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
  4148. if (rc)
  4149. return -ENOMEM;
  4150. /* IF Type 2 ports get initialized now. */
  4151. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  4152. LPFC_SLI_INTF_IF_TYPE_2) {
  4153. rc = lpfc_pci_function_reset(phba);
  4154. if (unlikely(rc))
  4155. return -ENODEV;
  4156. }
  4157. /* Create the bootstrap mailbox command */
  4158. rc = lpfc_create_bootstrap_mbox(phba);
  4159. if (unlikely(rc))
  4160. goto out_free_mem;
  4161. /* Set up the host's endian order with the device. */
  4162. rc = lpfc_setup_endian_order(phba);
  4163. if (unlikely(rc))
  4164. goto out_free_bsmbx;
  4165. /* Set up the hba's configuration parameters. */
  4166. rc = lpfc_sli4_read_config(phba);
  4167. if (unlikely(rc))
  4168. goto out_free_bsmbx;
  4169. /* IF Type 0 ports get initialized now. */
  4170. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  4171. LPFC_SLI_INTF_IF_TYPE_0) {
  4172. rc = lpfc_pci_function_reset(phba);
  4173. if (unlikely(rc))
  4174. goto out_free_bsmbx;
  4175. }
  4176. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  4177. GFP_KERNEL);
  4178. if (!mboxq) {
  4179. rc = -ENOMEM;
  4180. goto out_free_bsmbx;
  4181. }
  4182. /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
  4183. lpfc_supported_pages(mboxq);
  4184. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4185. if (!rc) {
  4186. mqe = &mboxq->u.mqe;
  4187. memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
  4188. LPFC_MAX_SUPPORTED_PAGES);
  4189. for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
  4190. switch (pn_page[i]) {
  4191. case LPFC_SLI4_PARAMETERS:
  4192. phba->sli4_hba.pc_sli4_params.supported = 1;
  4193. break;
  4194. default:
  4195. break;
  4196. }
  4197. }
  4198. /* Read the port's SLI4 Parameters capabilities if supported. */
  4199. if (phba->sli4_hba.pc_sli4_params.supported)
  4200. rc = lpfc_pc_sli4_params_get(phba, mboxq);
  4201. if (rc) {
  4202. mempool_free(mboxq, phba->mbox_mem_pool);
  4203. rc = -EIO;
  4204. goto out_free_bsmbx;
  4205. }
  4206. }
  4207. /*
  4208. * Get sli4 parameters that override parameters from Port capabilities.
  4209. * If this call fails, it isn't critical unless the SLI4 parameters come
  4210. * back in conflict.
  4211. */
  4212. rc = lpfc_get_sli4_parameters(phba, mboxq);
  4213. if (rc) {
  4214. if (phba->sli4_hba.extents_in_use &&
  4215. phba->sli4_hba.rpi_hdrs_in_use) {
  4216. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4217. "2999 Unsupported SLI4 Parameters "
  4218. "Extents and RPI headers enabled.\n");
  4219. goto out_free_bsmbx;
  4220. }
  4221. }
  4222. mempool_free(mboxq, phba->mbox_mem_pool);
  4223. /* Verify all the SLI4 queues */
  4224. rc = lpfc_sli4_queue_verify(phba);
  4225. if (rc)
  4226. goto out_free_bsmbx;
  4227. /* Create driver internal CQE event pool */
  4228. rc = lpfc_sli4_cq_event_pool_create(phba);
  4229. if (rc)
  4230. goto out_free_bsmbx;
  4231. /* Initialize and populate the iocb list per host */
  4232. rc = lpfc_init_sgl_list(phba);
  4233. if (rc) {
  4234. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4235. "1400 Failed to initialize sgl list.\n");
  4236. goto out_destroy_cq_event_pool;
  4237. }
  4238. rc = lpfc_init_active_sgl_array(phba);
  4239. if (rc) {
  4240. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4241. "1430 Failed to initialize sgl list.\n");
  4242. goto out_free_sgl_list;
  4243. }
  4244. rc = lpfc_sli4_init_rpi_hdrs(phba);
  4245. if (rc) {
  4246. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4247. "1432 Failed to initialize rpi headers.\n");
  4248. goto out_free_active_sgl;
  4249. }
  4250. /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
  4251. longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
  4252. phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
  4253. GFP_KERNEL);
  4254. if (!phba->fcf.fcf_rr_bmask) {
  4255. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4256. "2759 Failed allocate memory for FCF round "
  4257. "robin failover bmask\n");
  4258. rc = -ENOMEM;
  4259. goto out_remove_rpi_hdrs;
  4260. }
  4261. /*
  4262. * The cfg_fcp_eq_count can be zero whenever there is exactly one
  4263. * interrupt vector. This is not an error
  4264. */
  4265. if (phba->cfg_fcp_eq_count) {
  4266. phba->sli4_hba.fcp_eq_hdl =
  4267. kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
  4268. phba->cfg_fcp_eq_count), GFP_KERNEL);
  4269. if (!phba->sli4_hba.fcp_eq_hdl) {
  4270. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4271. "2572 Failed allocate memory for "
  4272. "fast-path per-EQ handle array\n");
  4273. rc = -ENOMEM;
  4274. goto out_free_fcf_rr_bmask;
  4275. }
  4276. }
  4277. phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
  4278. phba->sli4_hba.cfg_eqn), GFP_KERNEL);
  4279. if (!phba->sli4_hba.msix_entries) {
  4280. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4281. "2573 Failed allocate memory for msi-x "
  4282. "interrupt vector entries\n");
  4283. rc = -ENOMEM;
  4284. goto out_free_fcp_eq_hdl;
  4285. }
  4286. /*
  4287. * Enable sr-iov virtual functions if supported and configured
  4288. * through the module parameter.
  4289. */
  4290. if (phba->cfg_sriov_nr_virtfn > 0) {
  4291. rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
  4292. phba->cfg_sriov_nr_virtfn);
  4293. if (rc) {
  4294. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4295. "3020 Requested number of SR-IOV "
  4296. "virtual functions (%d) is not "
  4297. "supported\n",
  4298. phba->cfg_sriov_nr_virtfn);
  4299. phba->cfg_sriov_nr_virtfn = 0;
  4300. }
  4301. }
  4302. return 0;
  4303. out_free_fcp_eq_hdl:
  4304. kfree(phba->sli4_hba.fcp_eq_hdl);
  4305. out_free_fcf_rr_bmask:
  4306. kfree(phba->fcf.fcf_rr_bmask);
  4307. out_remove_rpi_hdrs:
  4308. lpfc_sli4_remove_rpi_hdrs(phba);
  4309. out_free_active_sgl:
  4310. lpfc_free_active_sgl(phba);
  4311. out_free_sgl_list:
  4312. lpfc_free_sgl_list(phba);
  4313. out_destroy_cq_event_pool:
  4314. lpfc_sli4_cq_event_pool_destroy(phba);
  4315. out_free_bsmbx:
  4316. lpfc_destroy_bootstrap_mbox(phba);
  4317. out_free_mem:
  4318. lpfc_mem_free(phba);
  4319. return rc;
  4320. }
  4321. /**
  4322. * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
  4323. * @phba: pointer to lpfc hba data structure.
  4324. *
  4325. * This routine is invoked to unset the driver internal resources set up
  4326. * specific for supporting the SLI-4 HBA device it attached to.
  4327. **/
  4328. static void
  4329. lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
  4330. {
  4331. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  4332. /* Free memory allocated for msi-x interrupt vector entries */
  4333. kfree(phba->sli4_hba.msix_entries);
  4334. /* Free memory allocated for fast-path work queue handles */
  4335. kfree(phba->sli4_hba.fcp_eq_hdl);
  4336. /* Free the allocated rpi headers. */
  4337. lpfc_sli4_remove_rpi_hdrs(phba);
  4338. lpfc_sli4_remove_rpis(phba);
  4339. /* Free eligible FCF index bmask */
  4340. kfree(phba->fcf.fcf_rr_bmask);
  4341. /* Free the ELS sgl list */
  4342. lpfc_free_active_sgl(phba);
  4343. lpfc_free_sgl_list(phba);
  4344. /* Free the SCSI sgl management array */
  4345. kfree(phba->sli4_hba.lpfc_scsi_psb_array);
  4346. /* Free the completion queue EQ event pool */
  4347. lpfc_sli4_cq_event_release_all(phba);
  4348. lpfc_sli4_cq_event_pool_destroy(phba);
  4349. /* Release resource identifiers. */
  4350. lpfc_sli4_dealloc_resource_identifiers(phba);
  4351. /* Free the bsmbx region. */
  4352. lpfc_destroy_bootstrap_mbox(phba);
  4353. /* Free the SLI Layer memory with SLI4 HBAs */
  4354. lpfc_mem_free_all(phba);
  4355. /* Free the current connect table */
  4356. list_for_each_entry_safe(conn_entry, next_conn_entry,
  4357. &phba->fcf_conn_rec_list, list) {
  4358. list_del_init(&conn_entry->list);
  4359. kfree(conn_entry);
  4360. }
  4361. return;
  4362. }
  4363. /**
  4364. * lpfc_init_api_table_setup - Set up init api function jump table
  4365. * @phba: The hba struct for which this call is being executed.
  4366. * @dev_grp: The HBA PCI-Device group number.
  4367. *
  4368. * This routine sets up the device INIT interface API function jump table
  4369. * in @phba struct.
  4370. *
  4371. * Returns: 0 - success, -ENODEV - failure.
  4372. **/
  4373. int
  4374. lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4375. {
  4376. phba->lpfc_hba_init_link = lpfc_hba_init_link;
  4377. phba->lpfc_hba_down_link = lpfc_hba_down_link;
  4378. phba->lpfc_selective_reset = lpfc_selective_reset;
  4379. switch (dev_grp) {
  4380. case LPFC_PCI_DEV_LP:
  4381. phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
  4382. phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
  4383. phba->lpfc_stop_port = lpfc_stop_port_s3;
  4384. break;
  4385. case LPFC_PCI_DEV_OC:
  4386. phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
  4387. phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
  4388. phba->lpfc_stop_port = lpfc_stop_port_s4;
  4389. break;
  4390. default:
  4391. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4392. "1431 Invalid HBA PCI-device group: 0x%x\n",
  4393. dev_grp);
  4394. return -ENODEV;
  4395. break;
  4396. }
  4397. return 0;
  4398. }
  4399. /**
  4400. * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
  4401. * @phba: pointer to lpfc hba data structure.
  4402. *
  4403. * This routine is invoked to set up the driver internal resources before the
  4404. * device specific resource setup to support the HBA device it attached to.
  4405. *
  4406. * Return codes
  4407. * 0 - successful
  4408. * other values - error
  4409. **/
  4410. static int
  4411. lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
  4412. {
  4413. /*
  4414. * Driver resources common to all SLI revisions
  4415. */
  4416. atomic_set(&phba->fast_event_count, 0);
  4417. spin_lock_init(&phba->hbalock);
  4418. /* Initialize ndlp management spinlock */
  4419. spin_lock_init(&phba->ndlp_lock);
  4420. INIT_LIST_HEAD(&phba->port_list);
  4421. INIT_LIST_HEAD(&phba->work_list);
  4422. init_waitqueue_head(&phba->wait_4_mlo_m_q);
  4423. /* Initialize the wait queue head for the kernel thread */
  4424. init_waitqueue_head(&phba->work_waitq);
  4425. /* Initialize the scsi buffer list used by driver for scsi IO */
  4426. spin_lock_init(&phba->scsi_buf_list_lock);
  4427. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
  4428. /* Initialize the fabric iocb list */
  4429. INIT_LIST_HEAD(&phba->fabric_iocb_list);
  4430. /* Initialize list to save ELS buffers */
  4431. INIT_LIST_HEAD(&phba->elsbuf);
  4432. /* Initialize FCF connection rec list */
  4433. INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
  4434. return 0;
  4435. }
  4436. /**
  4437. * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
  4438. * @phba: pointer to lpfc hba data structure.
  4439. *
  4440. * This routine is invoked to set up the driver internal resources after the
  4441. * device specific resource setup to support the HBA device it attached to.
  4442. *
  4443. * Return codes
  4444. * 0 - successful
  4445. * other values - error
  4446. **/
  4447. static int
  4448. lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
  4449. {
  4450. int error;
  4451. /* Startup the kernel thread for this host adapter. */
  4452. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  4453. "lpfc_worker_%d", phba->brd_no);
  4454. if (IS_ERR(phba->worker_thread)) {
  4455. error = PTR_ERR(phba->worker_thread);
  4456. return error;
  4457. }
  4458. return 0;
  4459. }
  4460. /**
  4461. * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
  4462. * @phba: pointer to lpfc hba data structure.
  4463. *
  4464. * This routine is invoked to unset the driver internal resources set up after
  4465. * the device specific resource setup for supporting the HBA device it
  4466. * attached to.
  4467. **/
  4468. static void
  4469. lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
  4470. {
  4471. /* Stop kernel worker thread */
  4472. kthread_stop(phba->worker_thread);
  4473. }
  4474. /**
  4475. * lpfc_free_iocb_list - Free iocb list.
  4476. * @phba: pointer to lpfc hba data structure.
  4477. *
  4478. * This routine is invoked to free the driver's IOCB list and memory.
  4479. **/
  4480. static void
  4481. lpfc_free_iocb_list(struct lpfc_hba *phba)
  4482. {
  4483. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  4484. spin_lock_irq(&phba->hbalock);
  4485. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  4486. &phba->lpfc_iocb_list, list) {
  4487. list_del(&iocbq_entry->list);
  4488. kfree(iocbq_entry);
  4489. phba->total_iocbq_bufs--;
  4490. }
  4491. spin_unlock_irq(&phba->hbalock);
  4492. return;
  4493. }
  4494. /**
  4495. * lpfc_init_iocb_list - Allocate and initialize iocb list.
  4496. * @phba: pointer to lpfc hba data structure.
  4497. *
  4498. * This routine is invoked to allocate and initizlize the driver's IOCB
  4499. * list and set up the IOCB tag array accordingly.
  4500. *
  4501. * Return codes
  4502. * 0 - successful
  4503. * other values - error
  4504. **/
  4505. static int
  4506. lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
  4507. {
  4508. struct lpfc_iocbq *iocbq_entry = NULL;
  4509. uint16_t iotag;
  4510. int i;
  4511. /* Initialize and populate the iocb list per host. */
  4512. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  4513. for (i = 0; i < iocb_count; i++) {
  4514. iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  4515. if (iocbq_entry == NULL) {
  4516. printk(KERN_ERR "%s: only allocated %d iocbs of "
  4517. "expected %d count. Unloading driver.\n",
  4518. __func__, i, LPFC_IOCB_LIST_CNT);
  4519. goto out_free_iocbq;
  4520. }
  4521. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  4522. if (iotag == 0) {
  4523. kfree(iocbq_entry);
  4524. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  4525. "Unloading driver.\n", __func__);
  4526. goto out_free_iocbq;
  4527. }
  4528. iocbq_entry->sli4_lxritag = NO_XRI;
  4529. iocbq_entry->sli4_xritag = NO_XRI;
  4530. spin_lock_irq(&phba->hbalock);
  4531. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  4532. phba->total_iocbq_bufs++;
  4533. spin_unlock_irq(&phba->hbalock);
  4534. }
  4535. return 0;
  4536. out_free_iocbq:
  4537. lpfc_free_iocb_list(phba);
  4538. return -ENOMEM;
  4539. }
  4540. /**
  4541. * lpfc_free_sgl_list - Free sgl list.
  4542. * @phba: pointer to lpfc hba data structure.
  4543. *
  4544. * This routine is invoked to free the driver's sgl list and memory.
  4545. **/
  4546. static void
  4547. lpfc_free_sgl_list(struct lpfc_hba *phba)
  4548. {
  4549. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  4550. LIST_HEAD(sglq_list);
  4551. spin_lock_irq(&phba->hbalock);
  4552. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
  4553. spin_unlock_irq(&phba->hbalock);
  4554. list_for_each_entry_safe(sglq_entry, sglq_next,
  4555. &sglq_list, list) {
  4556. list_del(&sglq_entry->list);
  4557. lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
  4558. kfree(sglq_entry);
  4559. phba->sli4_hba.total_sglq_bufs--;
  4560. }
  4561. kfree(phba->sli4_hba.lpfc_els_sgl_array);
  4562. }
  4563. /**
  4564. * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
  4565. * @phba: pointer to lpfc hba data structure.
  4566. *
  4567. * This routine is invoked to allocate the driver's active sgl memory.
  4568. * This array will hold the sglq_entry's for active IOs.
  4569. **/
  4570. static int
  4571. lpfc_init_active_sgl_array(struct lpfc_hba *phba)
  4572. {
  4573. int size;
  4574. size = sizeof(struct lpfc_sglq *);
  4575. size *= phba->sli4_hba.max_cfg_param.max_xri;
  4576. phba->sli4_hba.lpfc_sglq_active_list =
  4577. kzalloc(size, GFP_KERNEL);
  4578. if (!phba->sli4_hba.lpfc_sglq_active_list)
  4579. return -ENOMEM;
  4580. return 0;
  4581. }
  4582. /**
  4583. * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
  4584. * @phba: pointer to lpfc hba data structure.
  4585. *
  4586. * This routine is invoked to walk through the array of active sglq entries
  4587. * and free all of the resources.
  4588. * This is just a place holder for now.
  4589. **/
  4590. static void
  4591. lpfc_free_active_sgl(struct lpfc_hba *phba)
  4592. {
  4593. kfree(phba->sli4_hba.lpfc_sglq_active_list);
  4594. }
  4595. /**
  4596. * lpfc_init_sgl_list - Allocate and initialize sgl list.
  4597. * @phba: pointer to lpfc hba data structure.
  4598. *
  4599. * This routine is invoked to allocate and initizlize the driver's sgl
  4600. * list and set up the sgl xritag tag array accordingly.
  4601. *
  4602. * Return codes
  4603. * 0 - successful
  4604. * other values - error
  4605. **/
  4606. static int
  4607. lpfc_init_sgl_list(struct lpfc_hba *phba)
  4608. {
  4609. struct lpfc_sglq *sglq_entry = NULL;
  4610. int i;
  4611. int els_xri_cnt;
  4612. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  4613. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4614. "2400 ELS XRI count %d.\n",
  4615. els_xri_cnt);
  4616. /* Initialize and populate the sglq list per host/VF. */
  4617. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
  4618. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  4619. /* Sanity check on XRI management */
  4620. if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) {
  4621. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4622. "2562 No room left for SCSI XRI allocation: "
  4623. "max_xri=%d, els_xri=%d\n",
  4624. phba->sli4_hba.max_cfg_param.max_xri,
  4625. els_xri_cnt);
  4626. return -ENOMEM;
  4627. }
  4628. /* Allocate memory for the ELS XRI management array */
  4629. phba->sli4_hba.lpfc_els_sgl_array =
  4630. kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt),
  4631. GFP_KERNEL);
  4632. if (!phba->sli4_hba.lpfc_els_sgl_array) {
  4633. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4634. "2401 Failed to allocate memory for ELS "
  4635. "XRI management array of size %d.\n",
  4636. els_xri_cnt);
  4637. return -ENOMEM;
  4638. }
  4639. /* Keep the SCSI XRI into the XRI management array */
  4640. phba->sli4_hba.scsi_xri_max =
  4641. phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
  4642. phba->sli4_hba.scsi_xri_cnt = 0;
  4643. phba->sli4_hba.lpfc_scsi_psb_array =
  4644. kzalloc((sizeof(struct lpfc_scsi_buf *) *
  4645. phba->sli4_hba.scsi_xri_max), GFP_KERNEL);
  4646. if (!phba->sli4_hba.lpfc_scsi_psb_array) {
  4647. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4648. "2563 Failed to allocate memory for SCSI "
  4649. "XRI management array of size %d.\n",
  4650. phba->sli4_hba.scsi_xri_max);
  4651. kfree(phba->sli4_hba.lpfc_els_sgl_array);
  4652. return -ENOMEM;
  4653. }
  4654. for (i = 0; i < els_xri_cnt; i++) {
  4655. sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL);
  4656. if (sglq_entry == NULL) {
  4657. printk(KERN_ERR "%s: only allocated %d sgls of "
  4658. "expected %d count. Unloading driver.\n",
  4659. __func__, i, els_xri_cnt);
  4660. goto out_free_mem;
  4661. }
  4662. sglq_entry->buff_type = GEN_BUFF_TYPE;
  4663. sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys);
  4664. if (sglq_entry->virt == NULL) {
  4665. kfree(sglq_entry);
  4666. printk(KERN_ERR "%s: failed to allocate mbuf.\n"
  4667. "Unloading driver.\n", __func__);
  4668. goto out_free_mem;
  4669. }
  4670. sglq_entry->sgl = sglq_entry->virt;
  4671. memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
  4672. /* The list order is used by later block SGL registraton */
  4673. spin_lock_irq(&phba->hbalock);
  4674. sglq_entry->state = SGL_FREED;
  4675. list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list);
  4676. phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry;
  4677. phba->sli4_hba.total_sglq_bufs++;
  4678. spin_unlock_irq(&phba->hbalock);
  4679. }
  4680. return 0;
  4681. out_free_mem:
  4682. kfree(phba->sli4_hba.lpfc_scsi_psb_array);
  4683. lpfc_free_sgl_list(phba);
  4684. return -ENOMEM;
  4685. }
  4686. /**
  4687. * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
  4688. * @phba: pointer to lpfc hba data structure.
  4689. *
  4690. * This routine is invoked to post rpi header templates to the
  4691. * port for those SLI4 ports that do not support extents. This routine
  4692. * posts a PAGE_SIZE memory region to the port to hold up to
  4693. * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
  4694. * and should be called only when interrupts are disabled.
  4695. *
  4696. * Return codes
  4697. * 0 - successful
  4698. * -ERROR - otherwise.
  4699. **/
  4700. int
  4701. lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
  4702. {
  4703. int rc = 0;
  4704. struct lpfc_rpi_hdr *rpi_hdr;
  4705. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
  4706. if (!phba->sli4_hba.rpi_hdrs_in_use)
  4707. return rc;
  4708. if (phba->sli4_hba.extents_in_use)
  4709. return -EIO;
  4710. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  4711. if (!rpi_hdr) {
  4712. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4713. "0391 Error during rpi post operation\n");
  4714. lpfc_sli4_remove_rpis(phba);
  4715. rc = -ENODEV;
  4716. }
  4717. return rc;
  4718. }
  4719. /**
  4720. * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
  4721. * @phba: pointer to lpfc hba data structure.
  4722. *
  4723. * This routine is invoked to allocate a single 4KB memory region to
  4724. * support rpis and stores them in the phba. This single region
  4725. * provides support for up to 64 rpis. The region is used globally
  4726. * by the device.
  4727. *
  4728. * Returns:
  4729. * A valid rpi hdr on success.
  4730. * A NULL pointer on any failure.
  4731. **/
  4732. struct lpfc_rpi_hdr *
  4733. lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
  4734. {
  4735. uint16_t rpi_limit, curr_rpi_range;
  4736. struct lpfc_dmabuf *dmabuf;
  4737. struct lpfc_rpi_hdr *rpi_hdr;
  4738. uint32_t rpi_count;
  4739. /*
  4740. * If the SLI4 port supports extents, posting the rpi header isn't
  4741. * required. Set the expected maximum count and let the actual value
  4742. * get set when extents are fully allocated.
  4743. */
  4744. if (!phba->sli4_hba.rpi_hdrs_in_use)
  4745. return NULL;
  4746. if (phba->sli4_hba.extents_in_use)
  4747. return NULL;
  4748. /* The limit on the logical index is just the max_rpi count. */
  4749. rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
  4750. phba->sli4_hba.max_cfg_param.max_rpi - 1;
  4751. spin_lock_irq(&phba->hbalock);
  4752. /*
  4753. * Establish the starting RPI in this header block. The starting
  4754. * rpi is normalized to a zero base because the physical rpi is
  4755. * port based.
  4756. */
  4757. curr_rpi_range = phba->sli4_hba.next_rpi -
  4758. phba->sli4_hba.max_cfg_param.rpi_base;
  4759. spin_unlock_irq(&phba->hbalock);
  4760. /*
  4761. * The port has a limited number of rpis. The increment here
  4762. * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
  4763. * and to allow the full max_rpi range per port.
  4764. */
  4765. if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
  4766. rpi_count = rpi_limit - curr_rpi_range;
  4767. else
  4768. rpi_count = LPFC_RPI_HDR_COUNT;
  4769. if (!rpi_count)
  4770. return NULL;
  4771. /*
  4772. * First allocate the protocol header region for the port. The
  4773. * port expects a 4KB DMA-mapped memory region that is 4K aligned.
  4774. */
  4775. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4776. if (!dmabuf)
  4777. return NULL;
  4778. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4779. LPFC_HDR_TEMPLATE_SIZE,
  4780. &dmabuf->phys,
  4781. GFP_KERNEL);
  4782. if (!dmabuf->virt) {
  4783. rpi_hdr = NULL;
  4784. goto err_free_dmabuf;
  4785. }
  4786. memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
  4787. if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
  4788. rpi_hdr = NULL;
  4789. goto err_free_coherent;
  4790. }
  4791. /* Save the rpi header data for cleanup later. */
  4792. rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
  4793. if (!rpi_hdr)
  4794. goto err_free_coherent;
  4795. rpi_hdr->dmabuf = dmabuf;
  4796. rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
  4797. rpi_hdr->page_count = 1;
  4798. spin_lock_irq(&phba->hbalock);
  4799. /* The rpi_hdr stores the logical index only. */
  4800. rpi_hdr->start_rpi = curr_rpi_range;
  4801. list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
  4802. /*
  4803. * The next_rpi stores the next logical module-64 rpi value used
  4804. * to post physical rpis in subsequent rpi postings.
  4805. */
  4806. phba->sli4_hba.next_rpi += rpi_count;
  4807. spin_unlock_irq(&phba->hbalock);
  4808. return rpi_hdr;
  4809. err_free_coherent:
  4810. dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
  4811. dmabuf->virt, dmabuf->phys);
  4812. err_free_dmabuf:
  4813. kfree(dmabuf);
  4814. return NULL;
  4815. }
  4816. /**
  4817. * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
  4818. * @phba: pointer to lpfc hba data structure.
  4819. *
  4820. * This routine is invoked to remove all memory resources allocated
  4821. * to support rpis for SLI4 ports not supporting extents. This routine
  4822. * presumes the caller has released all rpis consumed by fabric or port
  4823. * logins and is prepared to have the header pages removed.
  4824. **/
  4825. void
  4826. lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
  4827. {
  4828. struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
  4829. if (!phba->sli4_hba.rpi_hdrs_in_use)
  4830. goto exit;
  4831. list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
  4832. &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  4833. list_del(&rpi_hdr->list);
  4834. dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
  4835. rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
  4836. kfree(rpi_hdr->dmabuf);
  4837. kfree(rpi_hdr);
  4838. }
  4839. exit:
  4840. /* There are no rpis available to the port now. */
  4841. phba->sli4_hba.next_rpi = 0;
  4842. }
  4843. /**
  4844. * lpfc_hba_alloc - Allocate driver hba data structure for a device.
  4845. * @pdev: pointer to pci device data structure.
  4846. *
  4847. * This routine is invoked to allocate the driver hba data structure for an
  4848. * HBA device. If the allocation is successful, the phba reference to the
  4849. * PCI device data structure is set.
  4850. *
  4851. * Return codes
  4852. * pointer to @phba - successful
  4853. * NULL - error
  4854. **/
  4855. static struct lpfc_hba *
  4856. lpfc_hba_alloc(struct pci_dev *pdev)
  4857. {
  4858. struct lpfc_hba *phba;
  4859. /* Allocate memory for HBA structure */
  4860. phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
  4861. if (!phba) {
  4862. dev_err(&pdev->dev, "failed to allocate hba struct\n");
  4863. return NULL;
  4864. }
  4865. /* Set reference to PCI device in HBA structure */
  4866. phba->pcidev = pdev;
  4867. /* Assign an unused board number */
  4868. phba->brd_no = lpfc_get_instance();
  4869. if (phba->brd_no < 0) {
  4870. kfree(phba);
  4871. return NULL;
  4872. }
  4873. spin_lock_init(&phba->ct_ev_lock);
  4874. INIT_LIST_HEAD(&phba->ct_ev_waiters);
  4875. return phba;
  4876. }
  4877. /**
  4878. * lpfc_hba_free - Free driver hba data structure with a device.
  4879. * @phba: pointer to lpfc hba data structure.
  4880. *
  4881. * This routine is invoked to free the driver hba data structure with an
  4882. * HBA device.
  4883. **/
  4884. static void
  4885. lpfc_hba_free(struct lpfc_hba *phba)
  4886. {
  4887. /* Release the driver assigned board number */
  4888. idr_remove(&lpfc_hba_index, phba->brd_no);
  4889. kfree(phba);
  4890. return;
  4891. }
  4892. /**
  4893. * lpfc_create_shost - Create hba physical port with associated scsi host.
  4894. * @phba: pointer to lpfc hba data structure.
  4895. *
  4896. * This routine is invoked to create HBA physical port and associate a SCSI
  4897. * host with it.
  4898. *
  4899. * Return codes
  4900. * 0 - successful
  4901. * other values - error
  4902. **/
  4903. static int
  4904. lpfc_create_shost(struct lpfc_hba *phba)
  4905. {
  4906. struct lpfc_vport *vport;
  4907. struct Scsi_Host *shost;
  4908. /* Initialize HBA FC structure */
  4909. phba->fc_edtov = FF_DEF_EDTOV;
  4910. phba->fc_ratov = FF_DEF_RATOV;
  4911. phba->fc_altov = FF_DEF_ALTOV;
  4912. phba->fc_arbtov = FF_DEF_ARBTOV;
  4913. atomic_set(&phba->sdev_cnt, 0);
  4914. vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
  4915. if (!vport)
  4916. return -ENODEV;
  4917. shost = lpfc_shost_from_vport(vport);
  4918. phba->pport = vport;
  4919. lpfc_debugfs_initialize(vport);
  4920. /* Put reference to SCSI host to driver's device private data */
  4921. pci_set_drvdata(phba->pcidev, shost);
  4922. return 0;
  4923. }
  4924. /**
  4925. * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
  4926. * @phba: pointer to lpfc hba data structure.
  4927. *
  4928. * This routine is invoked to destroy HBA physical port and the associated
  4929. * SCSI host.
  4930. **/
  4931. static void
  4932. lpfc_destroy_shost(struct lpfc_hba *phba)
  4933. {
  4934. struct lpfc_vport *vport = phba->pport;
  4935. /* Destroy physical port that associated with the SCSI host */
  4936. destroy_port(vport);
  4937. return;
  4938. }
  4939. /**
  4940. * lpfc_setup_bg - Setup Block guard structures and debug areas.
  4941. * @phba: pointer to lpfc hba data structure.
  4942. * @shost: the shost to be used to detect Block guard settings.
  4943. *
  4944. * This routine sets up the local Block guard protocol settings for @shost.
  4945. * This routine also allocates memory for debugging bg buffers.
  4946. **/
  4947. static void
  4948. lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
  4949. {
  4950. int pagecnt = 10;
  4951. if (lpfc_prot_mask && lpfc_prot_guard) {
  4952. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4953. "1478 Registering BlockGuard with the "
  4954. "SCSI layer\n");
  4955. scsi_host_set_prot(shost, lpfc_prot_mask);
  4956. scsi_host_set_guard(shost, lpfc_prot_guard);
  4957. }
  4958. if (!_dump_buf_data) {
  4959. while (pagecnt) {
  4960. spin_lock_init(&_dump_buf_lock);
  4961. _dump_buf_data =
  4962. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  4963. if (_dump_buf_data) {
  4964. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4965. "9043 BLKGRD: allocated %d pages for "
  4966. "_dump_buf_data at 0x%p\n",
  4967. (1 << pagecnt), _dump_buf_data);
  4968. _dump_buf_data_order = pagecnt;
  4969. memset(_dump_buf_data, 0,
  4970. ((1 << PAGE_SHIFT) << pagecnt));
  4971. break;
  4972. } else
  4973. --pagecnt;
  4974. }
  4975. if (!_dump_buf_data_order)
  4976. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4977. "9044 BLKGRD: ERROR unable to allocate "
  4978. "memory for hexdump\n");
  4979. } else
  4980. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4981. "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
  4982. "\n", _dump_buf_data);
  4983. if (!_dump_buf_dif) {
  4984. while (pagecnt) {
  4985. _dump_buf_dif =
  4986. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  4987. if (_dump_buf_dif) {
  4988. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4989. "9046 BLKGRD: allocated %d pages for "
  4990. "_dump_buf_dif at 0x%p\n",
  4991. (1 << pagecnt), _dump_buf_dif);
  4992. _dump_buf_dif_order = pagecnt;
  4993. memset(_dump_buf_dif, 0,
  4994. ((1 << PAGE_SHIFT) << pagecnt));
  4995. break;
  4996. } else
  4997. --pagecnt;
  4998. }
  4999. if (!_dump_buf_dif_order)
  5000. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5001. "9047 BLKGRD: ERROR unable to allocate "
  5002. "memory for hexdump\n");
  5003. } else
  5004. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5005. "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
  5006. _dump_buf_dif);
  5007. }
  5008. /**
  5009. * lpfc_post_init_setup - Perform necessary device post initialization setup.
  5010. * @phba: pointer to lpfc hba data structure.
  5011. *
  5012. * This routine is invoked to perform all the necessary post initialization
  5013. * setup for the device.
  5014. **/
  5015. static void
  5016. lpfc_post_init_setup(struct lpfc_hba *phba)
  5017. {
  5018. struct Scsi_Host *shost;
  5019. struct lpfc_adapter_event_header adapter_event;
  5020. /* Get the default values for Model Name and Description */
  5021. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  5022. /*
  5023. * hba setup may have changed the hba_queue_depth so we need to
  5024. * adjust the value of can_queue.
  5025. */
  5026. shost = pci_get_drvdata(phba->pcidev);
  5027. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  5028. if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
  5029. lpfc_setup_bg(phba, shost);
  5030. lpfc_host_attrib_init(shost);
  5031. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  5032. spin_lock_irq(shost->host_lock);
  5033. lpfc_poll_start_timer(phba);
  5034. spin_unlock_irq(shost->host_lock);
  5035. }
  5036. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5037. "0428 Perform SCSI scan\n");
  5038. /* Send board arrival event to upper layer */
  5039. adapter_event.event_type = FC_REG_ADAPTER_EVENT;
  5040. adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
  5041. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5042. sizeof(adapter_event),
  5043. (char *) &adapter_event,
  5044. LPFC_NL_VENDOR_ID);
  5045. return;
  5046. }
  5047. /**
  5048. * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
  5049. * @phba: pointer to lpfc hba data structure.
  5050. *
  5051. * This routine is invoked to set up the PCI device memory space for device
  5052. * with SLI-3 interface spec.
  5053. *
  5054. * Return codes
  5055. * 0 - successful
  5056. * other values - error
  5057. **/
  5058. static int
  5059. lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
  5060. {
  5061. struct pci_dev *pdev;
  5062. unsigned long bar0map_len, bar2map_len;
  5063. int i, hbq_count;
  5064. void *ptr;
  5065. int error = -ENODEV;
  5066. /* Obtain PCI device reference */
  5067. if (!phba->pcidev)
  5068. return error;
  5069. else
  5070. pdev = phba->pcidev;
  5071. /* Set the device DMA mask size */
  5072. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
  5073. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
  5074. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
  5075. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
  5076. return error;
  5077. }
  5078. }
  5079. /* Get the bus address of Bar0 and Bar2 and the number of bytes
  5080. * required by each mapping.
  5081. */
  5082. phba->pci_bar0_map = pci_resource_start(pdev, 0);
  5083. bar0map_len = pci_resource_len(pdev, 0);
  5084. phba->pci_bar2_map = pci_resource_start(pdev, 2);
  5085. bar2map_len = pci_resource_len(pdev, 2);
  5086. /* Map HBA SLIM to a kernel virtual address. */
  5087. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  5088. if (!phba->slim_memmap_p) {
  5089. dev_printk(KERN_ERR, &pdev->dev,
  5090. "ioremap failed for SLIM memory.\n");
  5091. goto out;
  5092. }
  5093. /* Map HBA Control Registers to a kernel virtual address. */
  5094. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  5095. if (!phba->ctrl_regs_memmap_p) {
  5096. dev_printk(KERN_ERR, &pdev->dev,
  5097. "ioremap failed for HBA control registers.\n");
  5098. goto out_iounmap_slim;
  5099. }
  5100. /* Allocate memory for SLI-2 structures */
  5101. phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
  5102. SLI2_SLIM_SIZE,
  5103. &phba->slim2p.phys,
  5104. GFP_KERNEL);
  5105. if (!phba->slim2p.virt)
  5106. goto out_iounmap;
  5107. memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
  5108. phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
  5109. phba->mbox_ext = (phba->slim2p.virt +
  5110. offsetof(struct lpfc_sli2_slim, mbx_ext_words));
  5111. phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
  5112. phba->IOCBs = (phba->slim2p.virt +
  5113. offsetof(struct lpfc_sli2_slim, IOCBs));
  5114. phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
  5115. lpfc_sli_hbq_size(),
  5116. &phba->hbqslimp.phys,
  5117. GFP_KERNEL);
  5118. if (!phba->hbqslimp.virt)
  5119. goto out_free_slim;
  5120. hbq_count = lpfc_sli_hbq_count();
  5121. ptr = phba->hbqslimp.virt;
  5122. for (i = 0; i < hbq_count; ++i) {
  5123. phba->hbqs[i].hbq_virt = ptr;
  5124. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  5125. ptr += (lpfc_hbq_defs[i]->entry_count *
  5126. sizeof(struct lpfc_hbq_entry));
  5127. }
  5128. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
  5129. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
  5130. memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
  5131. INIT_LIST_HEAD(&phba->rb_pend_list);
  5132. phba->MBslimaddr = phba->slim_memmap_p;
  5133. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  5134. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  5135. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  5136. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  5137. return 0;
  5138. out_free_slim:
  5139. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  5140. phba->slim2p.virt, phba->slim2p.phys);
  5141. out_iounmap:
  5142. iounmap(phba->ctrl_regs_memmap_p);
  5143. out_iounmap_slim:
  5144. iounmap(phba->slim_memmap_p);
  5145. out:
  5146. return error;
  5147. }
  5148. /**
  5149. * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
  5150. * @phba: pointer to lpfc hba data structure.
  5151. *
  5152. * This routine is invoked to unset the PCI device memory space for device
  5153. * with SLI-3 interface spec.
  5154. **/
  5155. static void
  5156. lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
  5157. {
  5158. struct pci_dev *pdev;
  5159. /* Obtain PCI device reference */
  5160. if (!phba->pcidev)
  5161. return;
  5162. else
  5163. pdev = phba->pcidev;
  5164. /* Free coherent DMA memory allocated */
  5165. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  5166. phba->hbqslimp.virt, phba->hbqslimp.phys);
  5167. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  5168. phba->slim2p.virt, phba->slim2p.phys);
  5169. /* I/O memory unmap */
  5170. iounmap(phba->ctrl_regs_memmap_p);
  5171. iounmap(phba->slim_memmap_p);
  5172. return;
  5173. }
  5174. /**
  5175. * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
  5176. * @phba: pointer to lpfc hba data structure.
  5177. *
  5178. * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
  5179. * done and check status.
  5180. *
  5181. * Return 0 if successful, otherwise -ENODEV.
  5182. **/
  5183. int
  5184. lpfc_sli4_post_status_check(struct lpfc_hba *phba)
  5185. {
  5186. struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
  5187. struct lpfc_register reg_data;
  5188. int i, port_error = 0;
  5189. uint32_t if_type;
  5190. memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
  5191. memset(&reg_data, 0, sizeof(reg_data));
  5192. if (!phba->sli4_hba.PSMPHRregaddr)
  5193. return -ENODEV;
  5194. /* Wait up to 30 seconds for the SLI Port POST done and ready */
  5195. for (i = 0; i < 3000; i++) {
  5196. if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  5197. &portsmphr_reg.word0) ||
  5198. (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
  5199. /* Port has a fatal POST error, break out */
  5200. port_error = -ENODEV;
  5201. break;
  5202. }
  5203. if (LPFC_POST_STAGE_PORT_READY ==
  5204. bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
  5205. break;
  5206. msleep(10);
  5207. }
  5208. /*
  5209. * If there was a port error during POST, then don't proceed with
  5210. * other register reads as the data may not be valid. Just exit.
  5211. */
  5212. if (port_error) {
  5213. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5214. "1408 Port Failed POST - portsmphr=0x%x, "
  5215. "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
  5216. "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
  5217. portsmphr_reg.word0,
  5218. bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
  5219. bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
  5220. bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
  5221. bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
  5222. bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
  5223. bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
  5224. bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
  5225. bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
  5226. } else {
  5227. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5228. "2534 Device Info: SLIFamily=0x%x, "
  5229. "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
  5230. "SLIHint_2=0x%x, FT=0x%x\n",
  5231. bf_get(lpfc_sli_intf_sli_family,
  5232. &phba->sli4_hba.sli_intf),
  5233. bf_get(lpfc_sli_intf_slirev,
  5234. &phba->sli4_hba.sli_intf),
  5235. bf_get(lpfc_sli_intf_if_type,
  5236. &phba->sli4_hba.sli_intf),
  5237. bf_get(lpfc_sli_intf_sli_hint1,
  5238. &phba->sli4_hba.sli_intf),
  5239. bf_get(lpfc_sli_intf_sli_hint2,
  5240. &phba->sli4_hba.sli_intf),
  5241. bf_get(lpfc_sli_intf_func_type,
  5242. &phba->sli4_hba.sli_intf));
  5243. /*
  5244. * Check for other Port errors during the initialization
  5245. * process. Fail the load if the port did not come up
  5246. * correctly.
  5247. */
  5248. if_type = bf_get(lpfc_sli_intf_if_type,
  5249. &phba->sli4_hba.sli_intf);
  5250. switch (if_type) {
  5251. case LPFC_SLI_INTF_IF_TYPE_0:
  5252. phba->sli4_hba.ue_mask_lo =
  5253. readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
  5254. phba->sli4_hba.ue_mask_hi =
  5255. readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
  5256. uerrlo_reg.word0 =
  5257. readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
  5258. uerrhi_reg.word0 =
  5259. readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
  5260. if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
  5261. (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
  5262. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5263. "1422 Unrecoverable Error "
  5264. "Detected during POST "
  5265. "uerr_lo_reg=0x%x, "
  5266. "uerr_hi_reg=0x%x, "
  5267. "ue_mask_lo_reg=0x%x, "
  5268. "ue_mask_hi_reg=0x%x\n",
  5269. uerrlo_reg.word0,
  5270. uerrhi_reg.word0,
  5271. phba->sli4_hba.ue_mask_lo,
  5272. phba->sli4_hba.ue_mask_hi);
  5273. port_error = -ENODEV;
  5274. }
  5275. break;
  5276. case LPFC_SLI_INTF_IF_TYPE_2:
  5277. /* Final checks. The port status should be clean. */
  5278. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  5279. &reg_data.word0) ||
  5280. (bf_get(lpfc_sliport_status_err, &reg_data) &&
  5281. !bf_get(lpfc_sliport_status_rn, &reg_data))) {
  5282. phba->work_status[0] =
  5283. readl(phba->sli4_hba.u.if_type2.
  5284. ERR1regaddr);
  5285. phba->work_status[1] =
  5286. readl(phba->sli4_hba.u.if_type2.
  5287. ERR2regaddr);
  5288. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5289. "2888 Port Error Detected "
  5290. "during POST: "
  5291. "port status reg 0x%x, "
  5292. "port_smphr reg 0x%x, "
  5293. "error 1=0x%x, error 2=0x%x\n",
  5294. reg_data.word0,
  5295. portsmphr_reg.word0,
  5296. phba->work_status[0],
  5297. phba->work_status[1]);
  5298. port_error = -ENODEV;
  5299. }
  5300. break;
  5301. case LPFC_SLI_INTF_IF_TYPE_1:
  5302. default:
  5303. break;
  5304. }
  5305. }
  5306. return port_error;
  5307. }
  5308. /**
  5309. * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
  5310. * @phba: pointer to lpfc hba data structure.
  5311. * @if_type: The SLI4 interface type getting configured.
  5312. *
  5313. * This routine is invoked to set up SLI4 BAR0 PCI config space register
  5314. * memory map.
  5315. **/
  5316. static void
  5317. lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
  5318. {
  5319. switch (if_type) {
  5320. case LPFC_SLI_INTF_IF_TYPE_0:
  5321. phba->sli4_hba.u.if_type0.UERRLOregaddr =
  5322. phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
  5323. phba->sli4_hba.u.if_type0.UERRHIregaddr =
  5324. phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
  5325. phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
  5326. phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
  5327. phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
  5328. phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
  5329. phba->sli4_hba.SLIINTFregaddr =
  5330. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
  5331. break;
  5332. case LPFC_SLI_INTF_IF_TYPE_2:
  5333. phba->sli4_hba.u.if_type2.ERR1regaddr =
  5334. phba->sli4_hba.conf_regs_memmap_p +
  5335. LPFC_CTL_PORT_ER1_OFFSET;
  5336. phba->sli4_hba.u.if_type2.ERR2regaddr =
  5337. phba->sli4_hba.conf_regs_memmap_p +
  5338. LPFC_CTL_PORT_ER2_OFFSET;
  5339. phba->sli4_hba.u.if_type2.CTRLregaddr =
  5340. phba->sli4_hba.conf_regs_memmap_p +
  5341. LPFC_CTL_PORT_CTL_OFFSET;
  5342. phba->sli4_hba.u.if_type2.STATUSregaddr =
  5343. phba->sli4_hba.conf_regs_memmap_p +
  5344. LPFC_CTL_PORT_STA_OFFSET;
  5345. phba->sli4_hba.SLIINTFregaddr =
  5346. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
  5347. phba->sli4_hba.PSMPHRregaddr =
  5348. phba->sli4_hba.conf_regs_memmap_p +
  5349. LPFC_CTL_PORT_SEM_OFFSET;
  5350. phba->sli4_hba.RQDBregaddr =
  5351. phba->sli4_hba.conf_regs_memmap_p + LPFC_RQ_DOORBELL;
  5352. phba->sli4_hba.WQDBregaddr =
  5353. phba->sli4_hba.conf_regs_memmap_p + LPFC_WQ_DOORBELL;
  5354. phba->sli4_hba.EQCQDBregaddr =
  5355. phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
  5356. phba->sli4_hba.MQDBregaddr =
  5357. phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
  5358. phba->sli4_hba.BMBXregaddr =
  5359. phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
  5360. break;
  5361. case LPFC_SLI_INTF_IF_TYPE_1:
  5362. default:
  5363. dev_printk(KERN_ERR, &phba->pcidev->dev,
  5364. "FATAL - unsupported SLI4 interface type - %d\n",
  5365. if_type);
  5366. break;
  5367. }
  5368. }
  5369. /**
  5370. * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
  5371. * @phba: pointer to lpfc hba data structure.
  5372. *
  5373. * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
  5374. * memory map.
  5375. **/
  5376. static void
  5377. lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
  5378. {
  5379. phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5380. LPFC_SLIPORT_IF0_SMPHR;
  5381. phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5382. LPFC_HST_ISR0;
  5383. phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5384. LPFC_HST_IMR0;
  5385. phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5386. LPFC_HST_ISCR0;
  5387. }
  5388. /**
  5389. * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
  5390. * @phba: pointer to lpfc hba data structure.
  5391. * @vf: virtual function number
  5392. *
  5393. * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
  5394. * based on the given viftual function number, @vf.
  5395. *
  5396. * Return 0 if successful, otherwise -ENODEV.
  5397. **/
  5398. static int
  5399. lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
  5400. {
  5401. if (vf > LPFC_VIR_FUNC_MAX)
  5402. return -ENODEV;
  5403. phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5404. vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL);
  5405. phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5406. vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL);
  5407. phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5408. vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
  5409. phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5410. vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
  5411. phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5412. vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
  5413. return 0;
  5414. }
  5415. /**
  5416. * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
  5417. * @phba: pointer to lpfc hba data structure.
  5418. *
  5419. * This routine is invoked to create the bootstrap mailbox
  5420. * region consistent with the SLI-4 interface spec. This
  5421. * routine allocates all memory necessary to communicate
  5422. * mailbox commands to the port and sets up all alignment
  5423. * needs. No locks are expected to be held when calling
  5424. * this routine.
  5425. *
  5426. * Return codes
  5427. * 0 - successful
  5428. * -ENOMEM - could not allocated memory.
  5429. **/
  5430. static int
  5431. lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
  5432. {
  5433. uint32_t bmbx_size;
  5434. struct lpfc_dmabuf *dmabuf;
  5435. struct dma_address *dma_address;
  5436. uint32_t pa_addr;
  5437. uint64_t phys_addr;
  5438. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  5439. if (!dmabuf)
  5440. return -ENOMEM;
  5441. /*
  5442. * The bootstrap mailbox region is comprised of 2 parts
  5443. * plus an alignment restriction of 16 bytes.
  5444. */
  5445. bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
  5446. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  5447. bmbx_size,
  5448. &dmabuf->phys,
  5449. GFP_KERNEL);
  5450. if (!dmabuf->virt) {
  5451. kfree(dmabuf);
  5452. return -ENOMEM;
  5453. }
  5454. memset(dmabuf->virt, 0, bmbx_size);
  5455. /*
  5456. * Initialize the bootstrap mailbox pointers now so that the register
  5457. * operations are simple later. The mailbox dma address is required
  5458. * to be 16-byte aligned. Also align the virtual memory as each
  5459. * maibox is copied into the bmbx mailbox region before issuing the
  5460. * command to the port.
  5461. */
  5462. phba->sli4_hba.bmbx.dmabuf = dmabuf;
  5463. phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
  5464. phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
  5465. LPFC_ALIGN_16_BYTE);
  5466. phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
  5467. LPFC_ALIGN_16_BYTE);
  5468. /*
  5469. * Set the high and low physical addresses now. The SLI4 alignment
  5470. * requirement is 16 bytes and the mailbox is posted to the port
  5471. * as two 30-bit addresses. The other data is a bit marking whether
  5472. * the 30-bit address is the high or low address.
  5473. * Upcast bmbx aphys to 64bits so shift instruction compiles
  5474. * clean on 32 bit machines.
  5475. */
  5476. dma_address = &phba->sli4_hba.bmbx.dma_address;
  5477. phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
  5478. pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
  5479. dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
  5480. LPFC_BMBX_BIT1_ADDR_HI);
  5481. pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
  5482. dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
  5483. LPFC_BMBX_BIT1_ADDR_LO);
  5484. return 0;
  5485. }
  5486. /**
  5487. * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
  5488. * @phba: pointer to lpfc hba data structure.
  5489. *
  5490. * This routine is invoked to teardown the bootstrap mailbox
  5491. * region and release all host resources. This routine requires
  5492. * the caller to ensure all mailbox commands recovered, no
  5493. * additional mailbox comands are sent, and interrupts are disabled
  5494. * before calling this routine.
  5495. *
  5496. **/
  5497. static void
  5498. lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
  5499. {
  5500. dma_free_coherent(&phba->pcidev->dev,
  5501. phba->sli4_hba.bmbx.bmbx_size,
  5502. phba->sli4_hba.bmbx.dmabuf->virt,
  5503. phba->sli4_hba.bmbx.dmabuf->phys);
  5504. kfree(phba->sli4_hba.bmbx.dmabuf);
  5505. memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
  5506. }
  5507. /**
  5508. * lpfc_sli4_read_config - Get the config parameters.
  5509. * @phba: pointer to lpfc hba data structure.
  5510. *
  5511. * This routine is invoked to read the configuration parameters from the HBA.
  5512. * The configuration parameters are used to set the base and maximum values
  5513. * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
  5514. * allocation for the port.
  5515. *
  5516. * Return codes
  5517. * 0 - successful
  5518. * -ENOMEM - No available memory
  5519. * -EIO - The mailbox failed to complete successfully.
  5520. **/
  5521. int
  5522. lpfc_sli4_read_config(struct lpfc_hba *phba)
  5523. {
  5524. LPFC_MBOXQ_t *pmb;
  5525. struct lpfc_mbx_read_config *rd_config;
  5526. union lpfc_sli4_cfg_shdr *shdr;
  5527. uint32_t shdr_status, shdr_add_status;
  5528. struct lpfc_mbx_get_func_cfg *get_func_cfg;
  5529. struct lpfc_rsrc_desc_fcfcoe *desc;
  5530. uint32_t desc_count;
  5531. int length, i, rc = 0;
  5532. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5533. if (!pmb) {
  5534. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5535. "2011 Unable to allocate memory for issuing "
  5536. "SLI_CONFIG_SPECIAL mailbox command\n");
  5537. return -ENOMEM;
  5538. }
  5539. lpfc_read_config(phba, pmb);
  5540. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  5541. if (rc != MBX_SUCCESS) {
  5542. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5543. "2012 Mailbox failed , mbxCmd x%x "
  5544. "READ_CONFIG, mbxStatus x%x\n",
  5545. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  5546. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  5547. rc = -EIO;
  5548. } else {
  5549. rd_config = &pmb->u.mqe.un.rd_config;
  5550. if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
  5551. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  5552. phba->sli4_hba.lnk_info.lnk_tp =
  5553. bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
  5554. phba->sli4_hba.lnk_info.lnk_no =
  5555. bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
  5556. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  5557. "3081 lnk_type:%d, lnk_numb:%d\n",
  5558. phba->sli4_hba.lnk_info.lnk_tp,
  5559. phba->sli4_hba.lnk_info.lnk_no);
  5560. } else
  5561. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  5562. "3082 Mailbox (x%x) returned ldv:x0\n",
  5563. bf_get(lpfc_mqe_command, &pmb->u.mqe));
  5564. phba->sli4_hba.extents_in_use =
  5565. bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
  5566. phba->sli4_hba.max_cfg_param.max_xri =
  5567. bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
  5568. phba->sli4_hba.max_cfg_param.xri_base =
  5569. bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
  5570. phba->sli4_hba.max_cfg_param.max_vpi =
  5571. bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
  5572. phba->sli4_hba.max_cfg_param.vpi_base =
  5573. bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
  5574. phba->sli4_hba.max_cfg_param.max_rpi =
  5575. bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
  5576. phba->sli4_hba.max_cfg_param.rpi_base =
  5577. bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
  5578. phba->sli4_hba.max_cfg_param.max_vfi =
  5579. bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
  5580. phba->sli4_hba.max_cfg_param.vfi_base =
  5581. bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
  5582. phba->sli4_hba.max_cfg_param.max_fcfi =
  5583. bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
  5584. phba->sli4_hba.max_cfg_param.max_eq =
  5585. bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
  5586. phba->sli4_hba.max_cfg_param.max_rq =
  5587. bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
  5588. phba->sli4_hba.max_cfg_param.max_wq =
  5589. bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
  5590. phba->sli4_hba.max_cfg_param.max_cq =
  5591. bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
  5592. phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
  5593. phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
  5594. phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
  5595. phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
  5596. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
  5597. phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
  5598. (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
  5599. phba->max_vports = phba->max_vpi;
  5600. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  5601. "2003 cfg params Extents? %d "
  5602. "XRI(B:%d M:%d), "
  5603. "VPI(B:%d M:%d) "
  5604. "VFI(B:%d M:%d) "
  5605. "RPI(B:%d M:%d) "
  5606. "FCFI(Count:%d)\n",
  5607. phba->sli4_hba.extents_in_use,
  5608. phba->sli4_hba.max_cfg_param.xri_base,
  5609. phba->sli4_hba.max_cfg_param.max_xri,
  5610. phba->sli4_hba.max_cfg_param.vpi_base,
  5611. phba->sli4_hba.max_cfg_param.max_vpi,
  5612. phba->sli4_hba.max_cfg_param.vfi_base,
  5613. phba->sli4_hba.max_cfg_param.max_vfi,
  5614. phba->sli4_hba.max_cfg_param.rpi_base,
  5615. phba->sli4_hba.max_cfg_param.max_rpi,
  5616. phba->sli4_hba.max_cfg_param.max_fcfi);
  5617. }
  5618. if (rc)
  5619. goto read_cfg_out;
  5620. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  5621. if (phba->cfg_hba_queue_depth >
  5622. (phba->sli4_hba.max_cfg_param.max_xri -
  5623. lpfc_sli4_get_els_iocb_cnt(phba)))
  5624. phba->cfg_hba_queue_depth =
  5625. phba->sli4_hba.max_cfg_param.max_xri -
  5626. lpfc_sli4_get_els_iocb_cnt(phba);
  5627. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  5628. LPFC_SLI_INTF_IF_TYPE_2)
  5629. goto read_cfg_out;
  5630. /* get the pf# and vf# for SLI4 if_type 2 port */
  5631. length = (sizeof(struct lpfc_mbx_get_func_cfg) -
  5632. sizeof(struct lpfc_sli4_cfg_mhdr));
  5633. lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
  5634. LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
  5635. length, LPFC_SLI4_MBX_EMBED);
  5636. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  5637. shdr = (union lpfc_sli4_cfg_shdr *)
  5638. &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
  5639. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  5640. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  5641. if (rc || shdr_status || shdr_add_status) {
  5642. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5643. "3026 Mailbox failed , mbxCmd x%x "
  5644. "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
  5645. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  5646. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  5647. rc = -EIO;
  5648. goto read_cfg_out;
  5649. }
  5650. /* search for fc_fcoe resrouce descriptor */
  5651. get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
  5652. desc_count = get_func_cfg->func_cfg.rsrc_desc_count;
  5653. for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
  5654. desc = (struct lpfc_rsrc_desc_fcfcoe *)
  5655. &get_func_cfg->func_cfg.desc[i];
  5656. if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
  5657. bf_get(lpfc_rsrc_desc_pcie_type, desc)) {
  5658. phba->sli4_hba.iov.pf_number =
  5659. bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
  5660. phba->sli4_hba.iov.vf_number =
  5661. bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
  5662. break;
  5663. }
  5664. }
  5665. if (i < LPFC_RSRC_DESC_MAX_NUM)
  5666. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  5667. "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
  5668. "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
  5669. phba->sli4_hba.iov.vf_number);
  5670. else {
  5671. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5672. "3028 GET_FUNCTION_CONFIG: failed to find "
  5673. "Resrouce Descriptor:x%x\n",
  5674. LPFC_RSRC_DESC_TYPE_FCFCOE);
  5675. rc = -EIO;
  5676. }
  5677. read_cfg_out:
  5678. mempool_free(pmb, phba->mbox_mem_pool);
  5679. return rc;
  5680. }
  5681. /**
  5682. * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
  5683. * @phba: pointer to lpfc hba data structure.
  5684. *
  5685. * This routine is invoked to setup the port-side endian order when
  5686. * the port if_type is 0. This routine has no function for other
  5687. * if_types.
  5688. *
  5689. * Return codes
  5690. * 0 - successful
  5691. * -ENOMEM - No available memory
  5692. * -EIO - The mailbox failed to complete successfully.
  5693. **/
  5694. static int
  5695. lpfc_setup_endian_order(struct lpfc_hba *phba)
  5696. {
  5697. LPFC_MBOXQ_t *mboxq;
  5698. uint32_t if_type, rc = 0;
  5699. uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
  5700. HOST_ENDIAN_HIGH_WORD1};
  5701. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  5702. switch (if_type) {
  5703. case LPFC_SLI_INTF_IF_TYPE_0:
  5704. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  5705. GFP_KERNEL);
  5706. if (!mboxq) {
  5707. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5708. "0492 Unable to allocate memory for "
  5709. "issuing SLI_CONFIG_SPECIAL mailbox "
  5710. "command\n");
  5711. return -ENOMEM;
  5712. }
  5713. /*
  5714. * The SLI4_CONFIG_SPECIAL mailbox command requires the first
  5715. * two words to contain special data values and no other data.
  5716. */
  5717. memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
  5718. memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
  5719. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5720. if (rc != MBX_SUCCESS) {
  5721. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5722. "0493 SLI_CONFIG_SPECIAL mailbox "
  5723. "failed with status x%x\n",
  5724. rc);
  5725. rc = -EIO;
  5726. }
  5727. mempool_free(mboxq, phba->mbox_mem_pool);
  5728. break;
  5729. case LPFC_SLI_INTF_IF_TYPE_2:
  5730. case LPFC_SLI_INTF_IF_TYPE_1:
  5731. default:
  5732. break;
  5733. }
  5734. return rc;
  5735. }
  5736. /**
  5737. * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
  5738. * @phba: pointer to lpfc hba data structure.
  5739. *
  5740. * This routine is invoked to check the user settable queue counts for EQs and
  5741. * CQs. after this routine is called the counts will be set to valid values that
  5742. * adhere to the constraints of the system's interrupt vectors and the port's
  5743. * queue resources.
  5744. *
  5745. * Return codes
  5746. * 0 - successful
  5747. * -ENOMEM - No available memory
  5748. **/
  5749. static int
  5750. lpfc_sli4_queue_verify(struct lpfc_hba *phba)
  5751. {
  5752. int cfg_fcp_wq_count;
  5753. int cfg_fcp_eq_count;
  5754. /*
  5755. * Sanity check for confiugred queue parameters against the run-time
  5756. * device parameters
  5757. */
  5758. /* Sanity check on FCP fast-path WQ parameters */
  5759. cfg_fcp_wq_count = phba->cfg_fcp_wq_count;
  5760. if (cfg_fcp_wq_count >
  5761. (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) {
  5762. cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq -
  5763. LPFC_SP_WQN_DEF;
  5764. if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) {
  5765. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5766. "2581 Not enough WQs (%d) from "
  5767. "the pci function for supporting "
  5768. "FCP WQs (%d)\n",
  5769. phba->sli4_hba.max_cfg_param.max_wq,
  5770. phba->cfg_fcp_wq_count);
  5771. goto out_error;
  5772. }
  5773. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5774. "2582 Not enough WQs (%d) from the pci "
  5775. "function for supporting the requested "
  5776. "FCP WQs (%d), the actual FCP WQs can "
  5777. "be supported: %d\n",
  5778. phba->sli4_hba.max_cfg_param.max_wq,
  5779. phba->cfg_fcp_wq_count, cfg_fcp_wq_count);
  5780. }
  5781. /* The actual number of FCP work queues adopted */
  5782. phba->cfg_fcp_wq_count = cfg_fcp_wq_count;
  5783. /* Sanity check on FCP fast-path EQ parameters */
  5784. cfg_fcp_eq_count = phba->cfg_fcp_eq_count;
  5785. if (cfg_fcp_eq_count >
  5786. (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) {
  5787. cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq -
  5788. LPFC_SP_EQN_DEF;
  5789. if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) {
  5790. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5791. "2574 Not enough EQs (%d) from the "
  5792. "pci function for supporting FCP "
  5793. "EQs (%d)\n",
  5794. phba->sli4_hba.max_cfg_param.max_eq,
  5795. phba->cfg_fcp_eq_count);
  5796. goto out_error;
  5797. }
  5798. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5799. "2575 Not enough EQs (%d) from the pci "
  5800. "function for supporting the requested "
  5801. "FCP EQs (%d), the actual FCP EQs can "
  5802. "be supported: %d\n",
  5803. phba->sli4_hba.max_cfg_param.max_eq,
  5804. phba->cfg_fcp_eq_count, cfg_fcp_eq_count);
  5805. }
  5806. /* It does not make sense to have more EQs than WQs */
  5807. if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) {
  5808. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5809. "2593 The FCP EQ count(%d) cannot be greater "
  5810. "than the FCP WQ count(%d), limiting the "
  5811. "FCP EQ count to %d\n", cfg_fcp_eq_count,
  5812. phba->cfg_fcp_wq_count,
  5813. phba->cfg_fcp_wq_count);
  5814. cfg_fcp_eq_count = phba->cfg_fcp_wq_count;
  5815. }
  5816. /* The actual number of FCP event queues adopted */
  5817. phba->cfg_fcp_eq_count = cfg_fcp_eq_count;
  5818. /* The overall number of event queues used */
  5819. phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF;
  5820. /* Get EQ depth from module parameter, fake the default for now */
  5821. phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
  5822. phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
  5823. /* Get CQ depth from module parameter, fake the default for now */
  5824. phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
  5825. phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
  5826. return 0;
  5827. out_error:
  5828. return -ENOMEM;
  5829. }
  5830. /**
  5831. * lpfc_sli4_queue_create - Create all the SLI4 queues
  5832. * @phba: pointer to lpfc hba data structure.
  5833. *
  5834. * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
  5835. * operation. For each SLI4 queue type, the parameters such as queue entry
  5836. * count (queue depth) shall be taken from the module parameter. For now,
  5837. * we just use some constant number as place holder.
  5838. *
  5839. * Return codes
  5840. * 0 - sucessful
  5841. * -ENOMEM - No availble memory
  5842. * -EIO - The mailbox failed to complete successfully.
  5843. **/
  5844. int
  5845. lpfc_sli4_queue_create(struct lpfc_hba *phba)
  5846. {
  5847. struct lpfc_queue *qdesc;
  5848. int fcp_eqidx, fcp_cqidx, fcp_wqidx;
  5849. /*
  5850. * Create Event Queues (EQs)
  5851. */
  5852. /* Create slow path event queue */
  5853. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  5854. phba->sli4_hba.eq_ecount);
  5855. if (!qdesc) {
  5856. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5857. "0496 Failed allocate slow-path EQ\n");
  5858. goto out_error;
  5859. }
  5860. phba->sli4_hba.sp_eq = qdesc;
  5861. /*
  5862. * Create fast-path FCP Event Queue(s). The cfg_fcp_eq_count can be
  5863. * zero whenever there is exactly one interrupt vector. This is not
  5864. * an error.
  5865. */
  5866. if (phba->cfg_fcp_eq_count) {
  5867. phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) *
  5868. phba->cfg_fcp_eq_count), GFP_KERNEL);
  5869. if (!phba->sli4_hba.fp_eq) {
  5870. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5871. "2576 Failed allocate memory for "
  5872. "fast-path EQ record array\n");
  5873. goto out_free_sp_eq;
  5874. }
  5875. }
  5876. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  5877. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  5878. phba->sli4_hba.eq_ecount);
  5879. if (!qdesc) {
  5880. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5881. "0497 Failed allocate fast-path EQ\n");
  5882. goto out_free_fp_eq;
  5883. }
  5884. phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc;
  5885. }
  5886. /*
  5887. * Create Complete Queues (CQs)
  5888. */
  5889. /* Create slow-path Mailbox Command Complete Queue */
  5890. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  5891. phba->sli4_hba.cq_ecount);
  5892. if (!qdesc) {
  5893. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5894. "0500 Failed allocate slow-path mailbox CQ\n");
  5895. goto out_free_fp_eq;
  5896. }
  5897. phba->sli4_hba.mbx_cq = qdesc;
  5898. /* Create slow-path ELS Complete Queue */
  5899. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  5900. phba->sli4_hba.cq_ecount);
  5901. if (!qdesc) {
  5902. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5903. "0501 Failed allocate slow-path ELS CQ\n");
  5904. goto out_free_mbx_cq;
  5905. }
  5906. phba->sli4_hba.els_cq = qdesc;
  5907. /*
  5908. * Create fast-path FCP Completion Queue(s), one-to-one with FCP EQs.
  5909. * If there are no FCP EQs then create exactly one FCP CQ.
  5910. */
  5911. if (phba->cfg_fcp_eq_count)
  5912. phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
  5913. phba->cfg_fcp_eq_count),
  5914. GFP_KERNEL);
  5915. else
  5916. phba->sli4_hba.fcp_cq = kzalloc(sizeof(struct lpfc_queue *),
  5917. GFP_KERNEL);
  5918. if (!phba->sli4_hba.fcp_cq) {
  5919. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5920. "2577 Failed allocate memory for fast-path "
  5921. "CQ record array\n");
  5922. goto out_free_els_cq;
  5923. }
  5924. fcp_cqidx = 0;
  5925. do {
  5926. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  5927. phba->sli4_hba.cq_ecount);
  5928. if (!qdesc) {
  5929. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5930. "0499 Failed allocate fast-path FCP "
  5931. "CQ (%d)\n", fcp_cqidx);
  5932. goto out_free_fcp_cq;
  5933. }
  5934. phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc;
  5935. } while (++fcp_cqidx < phba->cfg_fcp_eq_count);
  5936. /* Create Mailbox Command Queue */
  5937. phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
  5938. phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
  5939. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
  5940. phba->sli4_hba.mq_ecount);
  5941. if (!qdesc) {
  5942. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5943. "0505 Failed allocate slow-path MQ\n");
  5944. goto out_free_fcp_cq;
  5945. }
  5946. phba->sli4_hba.mbx_wq = qdesc;
  5947. /*
  5948. * Create all the Work Queues (WQs)
  5949. */
  5950. phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
  5951. phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
  5952. /* Create slow-path ELS Work Queue */
  5953. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  5954. phba->sli4_hba.wq_ecount);
  5955. if (!qdesc) {
  5956. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5957. "0504 Failed allocate slow-path ELS WQ\n");
  5958. goto out_free_mbx_wq;
  5959. }
  5960. phba->sli4_hba.els_wq = qdesc;
  5961. /* Create fast-path FCP Work Queue(s) */
  5962. phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
  5963. phba->cfg_fcp_wq_count), GFP_KERNEL);
  5964. if (!phba->sli4_hba.fcp_wq) {
  5965. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5966. "2578 Failed allocate memory for fast-path "
  5967. "WQ record array\n");
  5968. goto out_free_els_wq;
  5969. }
  5970. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
  5971. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  5972. phba->sli4_hba.wq_ecount);
  5973. if (!qdesc) {
  5974. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5975. "0503 Failed allocate fast-path FCP "
  5976. "WQ (%d)\n", fcp_wqidx);
  5977. goto out_free_fcp_wq;
  5978. }
  5979. phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc;
  5980. }
  5981. /*
  5982. * Create Receive Queue (RQ)
  5983. */
  5984. phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
  5985. phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
  5986. /* Create Receive Queue for header */
  5987. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  5988. phba->sli4_hba.rq_ecount);
  5989. if (!qdesc) {
  5990. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5991. "0506 Failed allocate receive HRQ\n");
  5992. goto out_free_fcp_wq;
  5993. }
  5994. phba->sli4_hba.hdr_rq = qdesc;
  5995. /* Create Receive Queue for data */
  5996. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  5997. phba->sli4_hba.rq_ecount);
  5998. if (!qdesc) {
  5999. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6000. "0507 Failed allocate receive DRQ\n");
  6001. goto out_free_hdr_rq;
  6002. }
  6003. phba->sli4_hba.dat_rq = qdesc;
  6004. return 0;
  6005. out_free_hdr_rq:
  6006. lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
  6007. phba->sli4_hba.hdr_rq = NULL;
  6008. out_free_fcp_wq:
  6009. for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) {
  6010. lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]);
  6011. phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL;
  6012. }
  6013. kfree(phba->sli4_hba.fcp_wq);
  6014. phba->sli4_hba.fcp_wq = NULL;
  6015. out_free_els_wq:
  6016. lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
  6017. phba->sli4_hba.els_wq = NULL;
  6018. out_free_mbx_wq:
  6019. lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
  6020. phba->sli4_hba.mbx_wq = NULL;
  6021. out_free_fcp_cq:
  6022. for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) {
  6023. lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]);
  6024. phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL;
  6025. }
  6026. kfree(phba->sli4_hba.fcp_cq);
  6027. phba->sli4_hba.fcp_cq = NULL;
  6028. out_free_els_cq:
  6029. lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
  6030. phba->sli4_hba.els_cq = NULL;
  6031. out_free_mbx_cq:
  6032. lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
  6033. phba->sli4_hba.mbx_cq = NULL;
  6034. out_free_fp_eq:
  6035. for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) {
  6036. lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]);
  6037. phba->sli4_hba.fp_eq[fcp_eqidx] = NULL;
  6038. }
  6039. kfree(phba->sli4_hba.fp_eq);
  6040. phba->sli4_hba.fp_eq = NULL;
  6041. out_free_sp_eq:
  6042. lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
  6043. phba->sli4_hba.sp_eq = NULL;
  6044. out_error:
  6045. return -ENOMEM;
  6046. }
  6047. /**
  6048. * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
  6049. * @phba: pointer to lpfc hba data structure.
  6050. *
  6051. * This routine is invoked to release all the SLI4 queues with the FCoE HBA
  6052. * operation.
  6053. *
  6054. * Return codes
  6055. * 0 - successful
  6056. * -ENOMEM - No available memory
  6057. * -EIO - The mailbox failed to complete successfully.
  6058. **/
  6059. void
  6060. lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
  6061. {
  6062. int fcp_qidx;
  6063. /* Release mailbox command work queue */
  6064. lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
  6065. phba->sli4_hba.mbx_wq = NULL;
  6066. /* Release ELS work queue */
  6067. lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
  6068. phba->sli4_hba.els_wq = NULL;
  6069. /* Release FCP work queue */
  6070. if (phba->sli4_hba.fcp_wq != NULL)
  6071. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count;
  6072. fcp_qidx++)
  6073. lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]);
  6074. kfree(phba->sli4_hba.fcp_wq);
  6075. phba->sli4_hba.fcp_wq = NULL;
  6076. /* Release unsolicited receive queue */
  6077. lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
  6078. phba->sli4_hba.hdr_rq = NULL;
  6079. lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
  6080. phba->sli4_hba.dat_rq = NULL;
  6081. /* Release ELS complete queue */
  6082. lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
  6083. phba->sli4_hba.els_cq = NULL;
  6084. /* Release mailbox command complete queue */
  6085. lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
  6086. phba->sli4_hba.mbx_cq = NULL;
  6087. /* Release FCP response complete queue */
  6088. fcp_qidx = 0;
  6089. if (phba->sli4_hba.fcp_cq != NULL)
  6090. do
  6091. lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]);
  6092. while (++fcp_qidx < phba->cfg_fcp_eq_count);
  6093. kfree(phba->sli4_hba.fcp_cq);
  6094. phba->sli4_hba.fcp_cq = NULL;
  6095. /* Release fast-path event queue */
  6096. if (phba->sli4_hba.fp_eq != NULL)
  6097. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count;
  6098. fcp_qidx++)
  6099. lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]);
  6100. kfree(phba->sli4_hba.fp_eq);
  6101. phba->sli4_hba.fp_eq = NULL;
  6102. /* Release slow-path event queue */
  6103. lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
  6104. phba->sli4_hba.sp_eq = NULL;
  6105. return;
  6106. }
  6107. /**
  6108. * lpfc_sli4_queue_setup - Set up all the SLI4 queues
  6109. * @phba: pointer to lpfc hba data structure.
  6110. *
  6111. * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
  6112. * operation.
  6113. *
  6114. * Return codes
  6115. * 0 - successful
  6116. * -ENOMEM - No available memory
  6117. * -EIO - The mailbox failed to complete successfully.
  6118. **/
  6119. int
  6120. lpfc_sli4_queue_setup(struct lpfc_hba *phba)
  6121. {
  6122. int rc = -ENOMEM;
  6123. int fcp_eqidx, fcp_cqidx, fcp_wqidx;
  6124. int fcp_cq_index = 0;
  6125. /*
  6126. * Set up Event Queues (EQs)
  6127. */
  6128. /* Set up slow-path event queue */
  6129. if (!phba->sli4_hba.sp_eq) {
  6130. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6131. "0520 Slow-path EQ not allocated\n");
  6132. goto out_error;
  6133. }
  6134. rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq,
  6135. LPFC_SP_DEF_IMAX);
  6136. if (rc) {
  6137. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6138. "0521 Failed setup of slow-path EQ: "
  6139. "rc = 0x%x\n", rc);
  6140. goto out_error;
  6141. }
  6142. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6143. "2583 Slow-path EQ setup: queue-id=%d\n",
  6144. phba->sli4_hba.sp_eq->queue_id);
  6145. /* Set up fast-path event queue */
  6146. if (phba->cfg_fcp_eq_count && !phba->sli4_hba.fp_eq) {
  6147. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6148. "3147 Fast-path EQs not allocated\n");
  6149. rc = -ENOMEM;
  6150. goto out_destroy_sp_eq;
  6151. }
  6152. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  6153. if (!phba->sli4_hba.fp_eq[fcp_eqidx]) {
  6154. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6155. "0522 Fast-path EQ (%d) not "
  6156. "allocated\n", fcp_eqidx);
  6157. rc = -ENOMEM;
  6158. goto out_destroy_fp_eq;
  6159. }
  6160. rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx],
  6161. phba->cfg_fcp_imax);
  6162. if (rc) {
  6163. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6164. "0523 Failed setup of fast-path EQ "
  6165. "(%d), rc = 0x%x\n", fcp_eqidx, rc);
  6166. goto out_destroy_fp_eq;
  6167. }
  6168. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6169. "2584 Fast-path EQ setup: "
  6170. "queue[%d]-id=%d\n", fcp_eqidx,
  6171. phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id);
  6172. }
  6173. /*
  6174. * Set up Complete Queues (CQs)
  6175. */
  6176. /* Set up slow-path MBOX Complete Queue as the first CQ */
  6177. if (!phba->sli4_hba.mbx_cq) {
  6178. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6179. "0528 Mailbox CQ not allocated\n");
  6180. rc = -ENOMEM;
  6181. goto out_destroy_fp_eq;
  6182. }
  6183. rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq,
  6184. LPFC_MCQ, LPFC_MBOX);
  6185. if (rc) {
  6186. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6187. "0529 Failed setup of slow-path mailbox CQ: "
  6188. "rc = 0x%x\n", rc);
  6189. goto out_destroy_fp_eq;
  6190. }
  6191. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6192. "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
  6193. phba->sli4_hba.mbx_cq->queue_id,
  6194. phba->sli4_hba.sp_eq->queue_id);
  6195. /* Set up slow-path ELS Complete Queue */
  6196. if (!phba->sli4_hba.els_cq) {
  6197. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6198. "0530 ELS CQ not allocated\n");
  6199. rc = -ENOMEM;
  6200. goto out_destroy_mbx_cq;
  6201. }
  6202. rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq,
  6203. LPFC_WCQ, LPFC_ELS);
  6204. if (rc) {
  6205. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6206. "0531 Failed setup of slow-path ELS CQ: "
  6207. "rc = 0x%x\n", rc);
  6208. goto out_destroy_mbx_cq;
  6209. }
  6210. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6211. "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
  6212. phba->sli4_hba.els_cq->queue_id,
  6213. phba->sli4_hba.sp_eq->queue_id);
  6214. /* Set up fast-path FCP Response Complete Queue */
  6215. if (!phba->sli4_hba.fcp_cq) {
  6216. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6217. "3148 Fast-path FCP CQ array not "
  6218. "allocated\n");
  6219. rc = -ENOMEM;
  6220. goto out_destroy_els_cq;
  6221. }
  6222. fcp_cqidx = 0;
  6223. do {
  6224. if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
  6225. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6226. "0526 Fast-path FCP CQ (%d) not "
  6227. "allocated\n", fcp_cqidx);
  6228. rc = -ENOMEM;
  6229. goto out_destroy_fcp_cq;
  6230. }
  6231. if (phba->cfg_fcp_eq_count)
  6232. rc = lpfc_cq_create(phba,
  6233. phba->sli4_hba.fcp_cq[fcp_cqidx],
  6234. phba->sli4_hba.fp_eq[fcp_cqidx],
  6235. LPFC_WCQ, LPFC_FCP);
  6236. else
  6237. rc = lpfc_cq_create(phba,
  6238. phba->sli4_hba.fcp_cq[fcp_cqidx],
  6239. phba->sli4_hba.sp_eq,
  6240. LPFC_WCQ, LPFC_FCP);
  6241. if (rc) {
  6242. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6243. "0527 Failed setup of fast-path FCP "
  6244. "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
  6245. goto out_destroy_fcp_cq;
  6246. }
  6247. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6248. "2588 FCP CQ setup: cq[%d]-id=%d, "
  6249. "parent %seq[%d]-id=%d\n",
  6250. fcp_cqidx,
  6251. phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
  6252. (phba->cfg_fcp_eq_count) ? "" : "sp_",
  6253. fcp_cqidx,
  6254. (phba->cfg_fcp_eq_count) ?
  6255. phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id :
  6256. phba->sli4_hba.sp_eq->queue_id);
  6257. } while (++fcp_cqidx < phba->cfg_fcp_eq_count);
  6258. /*
  6259. * Set up all the Work Queues (WQs)
  6260. */
  6261. /* Set up Mailbox Command Queue */
  6262. if (!phba->sli4_hba.mbx_wq) {
  6263. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6264. "0538 Slow-path MQ not allocated\n");
  6265. rc = -ENOMEM;
  6266. goto out_destroy_fcp_cq;
  6267. }
  6268. rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
  6269. phba->sli4_hba.mbx_cq, LPFC_MBOX);
  6270. if (rc) {
  6271. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6272. "0539 Failed setup of slow-path MQ: "
  6273. "rc = 0x%x\n", rc);
  6274. goto out_destroy_fcp_cq;
  6275. }
  6276. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6277. "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
  6278. phba->sli4_hba.mbx_wq->queue_id,
  6279. phba->sli4_hba.mbx_cq->queue_id);
  6280. /* Set up slow-path ELS Work Queue */
  6281. if (!phba->sli4_hba.els_wq) {
  6282. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6283. "0536 Slow-path ELS WQ not allocated\n");
  6284. rc = -ENOMEM;
  6285. goto out_destroy_mbx_wq;
  6286. }
  6287. rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
  6288. phba->sli4_hba.els_cq, LPFC_ELS);
  6289. if (rc) {
  6290. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6291. "0537 Failed setup of slow-path ELS WQ: "
  6292. "rc = 0x%x\n", rc);
  6293. goto out_destroy_mbx_wq;
  6294. }
  6295. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6296. "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
  6297. phba->sli4_hba.els_wq->queue_id,
  6298. phba->sli4_hba.els_cq->queue_id);
  6299. /* Set up fast-path FCP Work Queue */
  6300. if (!phba->sli4_hba.fcp_wq) {
  6301. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6302. "3149 Fast-path FCP WQ array not "
  6303. "allocated\n");
  6304. rc = -ENOMEM;
  6305. goto out_destroy_els_wq;
  6306. }
  6307. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
  6308. if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
  6309. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6310. "0534 Fast-path FCP WQ (%d) not "
  6311. "allocated\n", fcp_wqidx);
  6312. rc = -ENOMEM;
  6313. goto out_destroy_fcp_wq;
  6314. }
  6315. rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
  6316. phba->sli4_hba.fcp_cq[fcp_cq_index],
  6317. LPFC_FCP);
  6318. if (rc) {
  6319. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6320. "0535 Failed setup of fast-path FCP "
  6321. "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
  6322. goto out_destroy_fcp_wq;
  6323. }
  6324. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6325. "2591 FCP WQ setup: wq[%d]-id=%d, "
  6326. "parent cq[%d]-id=%d\n",
  6327. fcp_wqidx,
  6328. phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
  6329. fcp_cq_index,
  6330. phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id);
  6331. /* Round robin FCP Work Queue's Completion Queue assignment */
  6332. if (phba->cfg_fcp_eq_count)
  6333. fcp_cq_index = ((fcp_cq_index + 1) %
  6334. phba->cfg_fcp_eq_count);
  6335. }
  6336. /*
  6337. * Create Receive Queue (RQ)
  6338. */
  6339. if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
  6340. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6341. "0540 Receive Queue not allocated\n");
  6342. rc = -ENOMEM;
  6343. goto out_destroy_fcp_wq;
  6344. }
  6345. lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
  6346. lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
  6347. rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  6348. phba->sli4_hba.els_cq, LPFC_USOL);
  6349. if (rc) {
  6350. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6351. "0541 Failed setup of Receive Queue: "
  6352. "rc = 0x%x\n", rc);
  6353. goto out_destroy_fcp_wq;
  6354. }
  6355. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6356. "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
  6357. "parent cq-id=%d\n",
  6358. phba->sli4_hba.hdr_rq->queue_id,
  6359. phba->sli4_hba.dat_rq->queue_id,
  6360. phba->sli4_hba.els_cq->queue_id);
  6361. return 0;
  6362. out_destroy_fcp_wq:
  6363. for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
  6364. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
  6365. out_destroy_els_wq:
  6366. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  6367. out_destroy_mbx_wq:
  6368. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  6369. out_destroy_fcp_cq:
  6370. for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
  6371. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
  6372. out_destroy_els_cq:
  6373. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  6374. out_destroy_mbx_cq:
  6375. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  6376. out_destroy_fp_eq:
  6377. for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
  6378. lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]);
  6379. out_destroy_sp_eq:
  6380. lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
  6381. out_error:
  6382. return rc;
  6383. }
  6384. /**
  6385. * lpfc_sli4_queue_unset - Unset all the SLI4 queues
  6386. * @phba: pointer to lpfc hba data structure.
  6387. *
  6388. * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
  6389. * operation.
  6390. *
  6391. * Return codes
  6392. * 0 - successful
  6393. * -ENOMEM - No available memory
  6394. * -EIO - The mailbox failed to complete successfully.
  6395. **/
  6396. void
  6397. lpfc_sli4_queue_unset(struct lpfc_hba *phba)
  6398. {
  6399. int fcp_qidx;
  6400. /* Unset mailbox command work queue */
  6401. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  6402. /* Unset ELS work queue */
  6403. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  6404. /* Unset unsolicited receive queue */
  6405. lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
  6406. /* Unset FCP work queue */
  6407. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
  6408. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
  6409. /* Unset mailbox command complete queue */
  6410. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  6411. /* Unset ELS complete queue */
  6412. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  6413. /* Unset FCP response complete queue */
  6414. if (phba->sli4_hba.fcp_cq) {
  6415. fcp_qidx = 0;
  6416. do {
  6417. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
  6418. } while (++fcp_qidx < phba->cfg_fcp_eq_count);
  6419. }
  6420. /* Unset fast-path event queue */
  6421. if (phba->sli4_hba.fp_eq) {
  6422. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count;
  6423. fcp_qidx++)
  6424. lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]);
  6425. }
  6426. /* Unset slow-path event queue */
  6427. lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
  6428. }
  6429. /**
  6430. * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
  6431. * @phba: pointer to lpfc hba data structure.
  6432. *
  6433. * This routine is invoked to allocate and set up a pool of completion queue
  6434. * events. The body of the completion queue event is a completion queue entry
  6435. * CQE. For now, this pool is used for the interrupt service routine to queue
  6436. * the following HBA completion queue events for the worker thread to process:
  6437. * - Mailbox asynchronous events
  6438. * - Receive queue completion unsolicited events
  6439. * Later, this can be used for all the slow-path events.
  6440. *
  6441. * Return codes
  6442. * 0 - successful
  6443. * -ENOMEM - No available memory
  6444. **/
  6445. static int
  6446. lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
  6447. {
  6448. struct lpfc_cq_event *cq_event;
  6449. int i;
  6450. for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
  6451. cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
  6452. if (!cq_event)
  6453. goto out_pool_create_fail;
  6454. list_add_tail(&cq_event->list,
  6455. &phba->sli4_hba.sp_cqe_event_pool);
  6456. }
  6457. return 0;
  6458. out_pool_create_fail:
  6459. lpfc_sli4_cq_event_pool_destroy(phba);
  6460. return -ENOMEM;
  6461. }
  6462. /**
  6463. * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
  6464. * @phba: pointer to lpfc hba data structure.
  6465. *
  6466. * This routine is invoked to free the pool of completion queue events at
  6467. * driver unload time. Note that, it is the responsibility of the driver
  6468. * cleanup routine to free all the outstanding completion-queue events
  6469. * allocated from this pool back into the pool before invoking this routine
  6470. * to destroy the pool.
  6471. **/
  6472. static void
  6473. lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
  6474. {
  6475. struct lpfc_cq_event *cq_event, *next_cq_event;
  6476. list_for_each_entry_safe(cq_event, next_cq_event,
  6477. &phba->sli4_hba.sp_cqe_event_pool, list) {
  6478. list_del(&cq_event->list);
  6479. kfree(cq_event);
  6480. }
  6481. }
  6482. /**
  6483. * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  6484. * @phba: pointer to lpfc hba data structure.
  6485. *
  6486. * This routine is the lock free version of the API invoked to allocate a
  6487. * completion-queue event from the free pool.
  6488. *
  6489. * Return: Pointer to the newly allocated completion-queue event if successful
  6490. * NULL otherwise.
  6491. **/
  6492. struct lpfc_cq_event *
  6493. __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  6494. {
  6495. struct lpfc_cq_event *cq_event = NULL;
  6496. list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
  6497. struct lpfc_cq_event, list);
  6498. return cq_event;
  6499. }
  6500. /**
  6501. * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  6502. * @phba: pointer to lpfc hba data structure.
  6503. *
  6504. * This routine is the lock version of the API invoked to allocate a
  6505. * completion-queue event from the free pool.
  6506. *
  6507. * Return: Pointer to the newly allocated completion-queue event if successful
  6508. * NULL otherwise.
  6509. **/
  6510. struct lpfc_cq_event *
  6511. lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  6512. {
  6513. struct lpfc_cq_event *cq_event;
  6514. unsigned long iflags;
  6515. spin_lock_irqsave(&phba->hbalock, iflags);
  6516. cq_event = __lpfc_sli4_cq_event_alloc(phba);
  6517. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6518. return cq_event;
  6519. }
  6520. /**
  6521. * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  6522. * @phba: pointer to lpfc hba data structure.
  6523. * @cq_event: pointer to the completion queue event to be freed.
  6524. *
  6525. * This routine is the lock free version of the API invoked to release a
  6526. * completion-queue event back into the free pool.
  6527. **/
  6528. void
  6529. __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  6530. struct lpfc_cq_event *cq_event)
  6531. {
  6532. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
  6533. }
  6534. /**
  6535. * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  6536. * @phba: pointer to lpfc hba data structure.
  6537. * @cq_event: pointer to the completion queue event to be freed.
  6538. *
  6539. * This routine is the lock version of the API invoked to release a
  6540. * completion-queue event back into the free pool.
  6541. **/
  6542. void
  6543. lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  6544. struct lpfc_cq_event *cq_event)
  6545. {
  6546. unsigned long iflags;
  6547. spin_lock_irqsave(&phba->hbalock, iflags);
  6548. __lpfc_sli4_cq_event_release(phba, cq_event);
  6549. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6550. }
  6551. /**
  6552. * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
  6553. * @phba: pointer to lpfc hba data structure.
  6554. *
  6555. * This routine is to free all the pending completion-queue events to the
  6556. * back into the free pool for device reset.
  6557. **/
  6558. static void
  6559. lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
  6560. {
  6561. LIST_HEAD(cqelist);
  6562. struct lpfc_cq_event *cqe;
  6563. unsigned long iflags;
  6564. /* Retrieve all the pending WCQEs from pending WCQE lists */
  6565. spin_lock_irqsave(&phba->hbalock, iflags);
  6566. /* Pending FCP XRI abort events */
  6567. list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  6568. &cqelist);
  6569. /* Pending ELS XRI abort events */
  6570. list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  6571. &cqelist);
  6572. /* Pending asynnc events */
  6573. list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
  6574. &cqelist);
  6575. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6576. while (!list_empty(&cqelist)) {
  6577. list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
  6578. lpfc_sli4_cq_event_release(phba, cqe);
  6579. }
  6580. }
  6581. /**
  6582. * lpfc_pci_function_reset - Reset pci function.
  6583. * @phba: pointer to lpfc hba data structure.
  6584. *
  6585. * This routine is invoked to request a PCI function reset. It will destroys
  6586. * all resources assigned to the PCI function which originates this request.
  6587. *
  6588. * Return codes
  6589. * 0 - successful
  6590. * -ENOMEM - No available memory
  6591. * -EIO - The mailbox failed to complete successfully.
  6592. **/
  6593. int
  6594. lpfc_pci_function_reset(struct lpfc_hba *phba)
  6595. {
  6596. LPFC_MBOXQ_t *mboxq;
  6597. uint32_t rc = 0, if_type;
  6598. uint32_t shdr_status, shdr_add_status;
  6599. uint32_t rdy_chk, num_resets = 0, reset_again = 0;
  6600. union lpfc_sli4_cfg_shdr *shdr;
  6601. struct lpfc_register reg_data;
  6602. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  6603. switch (if_type) {
  6604. case LPFC_SLI_INTF_IF_TYPE_0:
  6605. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  6606. GFP_KERNEL);
  6607. if (!mboxq) {
  6608. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6609. "0494 Unable to allocate memory for "
  6610. "issuing SLI_FUNCTION_RESET mailbox "
  6611. "command\n");
  6612. return -ENOMEM;
  6613. }
  6614. /* Setup PCI function reset mailbox-ioctl command */
  6615. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  6616. LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
  6617. LPFC_SLI4_MBX_EMBED);
  6618. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6619. shdr = (union lpfc_sli4_cfg_shdr *)
  6620. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  6621. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  6622. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  6623. &shdr->response);
  6624. if (rc != MBX_TIMEOUT)
  6625. mempool_free(mboxq, phba->mbox_mem_pool);
  6626. if (shdr_status || shdr_add_status || rc) {
  6627. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6628. "0495 SLI_FUNCTION_RESET mailbox "
  6629. "failed with status x%x add_status x%x,"
  6630. " mbx status x%x\n",
  6631. shdr_status, shdr_add_status, rc);
  6632. rc = -ENXIO;
  6633. }
  6634. break;
  6635. case LPFC_SLI_INTF_IF_TYPE_2:
  6636. for (num_resets = 0;
  6637. num_resets < MAX_IF_TYPE_2_RESETS;
  6638. num_resets++) {
  6639. reg_data.word0 = 0;
  6640. bf_set(lpfc_sliport_ctrl_end, &reg_data,
  6641. LPFC_SLIPORT_LITTLE_ENDIAN);
  6642. bf_set(lpfc_sliport_ctrl_ip, &reg_data,
  6643. LPFC_SLIPORT_INIT_PORT);
  6644. writel(reg_data.word0, phba->sli4_hba.u.if_type2.
  6645. CTRLregaddr);
  6646. /*
  6647. * Poll the Port Status Register and wait for RDY for
  6648. * up to 10 seconds. If the port doesn't respond, treat
  6649. * it as an error. If the port responds with RN, start
  6650. * the loop again.
  6651. */
  6652. for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) {
  6653. msleep(10);
  6654. if (lpfc_readl(phba->sli4_hba.u.if_type2.
  6655. STATUSregaddr, &reg_data.word0)) {
  6656. rc = -ENODEV;
  6657. goto out;
  6658. }
  6659. if (bf_get(lpfc_sliport_status_rn, &reg_data))
  6660. reset_again++;
  6661. if (bf_get(lpfc_sliport_status_rdy, &reg_data))
  6662. break;
  6663. }
  6664. /*
  6665. * If the port responds to the init request with
  6666. * reset needed, delay for a bit and restart the loop.
  6667. */
  6668. if (reset_again && (rdy_chk < 1000)) {
  6669. msleep(10);
  6670. reset_again = 0;
  6671. continue;
  6672. }
  6673. /* Detect any port errors. */
  6674. if ((bf_get(lpfc_sliport_status_err, &reg_data)) ||
  6675. (rdy_chk >= 1000)) {
  6676. phba->work_status[0] = readl(
  6677. phba->sli4_hba.u.if_type2.ERR1regaddr);
  6678. phba->work_status[1] = readl(
  6679. phba->sli4_hba.u.if_type2.ERR2regaddr);
  6680. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6681. "2890 Port Error Detected "
  6682. "during Port Reset: "
  6683. "port status reg 0x%x, "
  6684. "error 1=0x%x, error 2=0x%x\n",
  6685. reg_data.word0,
  6686. phba->work_status[0],
  6687. phba->work_status[1]);
  6688. rc = -ENODEV;
  6689. }
  6690. /*
  6691. * Terminate the outer loop provided the Port indicated
  6692. * ready within 10 seconds.
  6693. */
  6694. if (rdy_chk < 1000)
  6695. break;
  6696. }
  6697. /* delay driver action following IF_TYPE_2 function reset */
  6698. msleep(100);
  6699. break;
  6700. case LPFC_SLI_INTF_IF_TYPE_1:
  6701. default:
  6702. break;
  6703. }
  6704. out:
  6705. /* Catch the not-ready port failure after a port reset. */
  6706. if (num_resets >= MAX_IF_TYPE_2_RESETS)
  6707. rc = -ENODEV;
  6708. return rc;
  6709. }
  6710. /**
  6711. * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
  6712. * @phba: pointer to lpfc hba data structure.
  6713. * @cnt: number of nop mailbox commands to send.
  6714. *
  6715. * This routine is invoked to send a number @cnt of NOP mailbox command and
  6716. * wait for each command to complete.
  6717. *
  6718. * Return: the number of NOP mailbox command completed.
  6719. **/
  6720. static int
  6721. lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt)
  6722. {
  6723. LPFC_MBOXQ_t *mboxq;
  6724. int length, cmdsent;
  6725. uint32_t mbox_tmo;
  6726. uint32_t rc = 0;
  6727. uint32_t shdr_status, shdr_add_status;
  6728. union lpfc_sli4_cfg_shdr *shdr;
  6729. if (cnt == 0) {
  6730. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6731. "2518 Requested to send 0 NOP mailbox cmd\n");
  6732. return cnt;
  6733. }
  6734. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  6735. if (!mboxq) {
  6736. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6737. "2519 Unable to allocate memory for issuing "
  6738. "NOP mailbox command\n");
  6739. return 0;
  6740. }
  6741. /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
  6742. length = (sizeof(struct lpfc_mbx_nop) -
  6743. sizeof(struct lpfc_sli4_cfg_mhdr));
  6744. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  6745. LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED);
  6746. for (cmdsent = 0; cmdsent < cnt; cmdsent++) {
  6747. if (!phba->sli4_hba.intr_enable)
  6748. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6749. else {
  6750. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  6751. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  6752. }
  6753. if (rc == MBX_TIMEOUT)
  6754. break;
  6755. /* Check return status */
  6756. shdr = (union lpfc_sli4_cfg_shdr *)
  6757. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  6758. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  6759. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  6760. &shdr->response);
  6761. if (shdr_status || shdr_add_status || rc) {
  6762. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6763. "2520 NOP mailbox command failed "
  6764. "status x%x add_status x%x mbx "
  6765. "status x%x\n", shdr_status,
  6766. shdr_add_status, rc);
  6767. break;
  6768. }
  6769. }
  6770. if (rc != MBX_TIMEOUT)
  6771. mempool_free(mboxq, phba->mbox_mem_pool);
  6772. return cmdsent;
  6773. }
  6774. /**
  6775. * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
  6776. * @phba: pointer to lpfc hba data structure.
  6777. *
  6778. * This routine is invoked to set up the PCI device memory space for device
  6779. * with SLI-4 interface spec.
  6780. *
  6781. * Return codes
  6782. * 0 - successful
  6783. * other values - error
  6784. **/
  6785. static int
  6786. lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
  6787. {
  6788. struct pci_dev *pdev;
  6789. unsigned long bar0map_len, bar1map_len, bar2map_len;
  6790. int error = -ENODEV;
  6791. uint32_t if_type;
  6792. /* Obtain PCI device reference */
  6793. if (!phba->pcidev)
  6794. return error;
  6795. else
  6796. pdev = phba->pcidev;
  6797. /* Set the device DMA mask size */
  6798. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
  6799. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
  6800. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
  6801. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
  6802. return error;
  6803. }
  6804. }
  6805. /*
  6806. * The BARs and register set definitions and offset locations are
  6807. * dependent on the if_type.
  6808. */
  6809. if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
  6810. &phba->sli4_hba.sli_intf.word0)) {
  6811. return error;
  6812. }
  6813. /* There is no SLI3 failback for SLI4 devices. */
  6814. if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
  6815. LPFC_SLI_INTF_VALID) {
  6816. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6817. "2894 SLI_INTF reg contents invalid "
  6818. "sli_intf reg 0x%x\n",
  6819. phba->sli4_hba.sli_intf.word0);
  6820. return error;
  6821. }
  6822. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  6823. /*
  6824. * Get the bus address of SLI4 device Bar regions and the
  6825. * number of bytes required by each mapping. The mapping of the
  6826. * particular PCI BARs regions is dependent on the type of
  6827. * SLI4 device.
  6828. */
  6829. if (pci_resource_start(pdev, 0)) {
  6830. phba->pci_bar0_map = pci_resource_start(pdev, 0);
  6831. bar0map_len = pci_resource_len(pdev, 0);
  6832. /*
  6833. * Map SLI4 PCI Config Space Register base to a kernel virtual
  6834. * addr
  6835. */
  6836. phba->sli4_hba.conf_regs_memmap_p =
  6837. ioremap(phba->pci_bar0_map, bar0map_len);
  6838. if (!phba->sli4_hba.conf_regs_memmap_p) {
  6839. dev_printk(KERN_ERR, &pdev->dev,
  6840. "ioremap failed for SLI4 PCI config "
  6841. "registers.\n");
  6842. goto out;
  6843. }
  6844. /* Set up BAR0 PCI config space register memory map */
  6845. lpfc_sli4_bar0_register_memmap(phba, if_type);
  6846. } else {
  6847. phba->pci_bar0_map = pci_resource_start(pdev, 1);
  6848. bar0map_len = pci_resource_len(pdev, 1);
  6849. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  6850. dev_printk(KERN_ERR, &pdev->dev,
  6851. "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
  6852. goto out;
  6853. }
  6854. phba->sli4_hba.conf_regs_memmap_p =
  6855. ioremap(phba->pci_bar0_map, bar0map_len);
  6856. if (!phba->sli4_hba.conf_regs_memmap_p) {
  6857. dev_printk(KERN_ERR, &pdev->dev,
  6858. "ioremap failed for SLI4 PCI config "
  6859. "registers.\n");
  6860. goto out;
  6861. }
  6862. lpfc_sli4_bar0_register_memmap(phba, if_type);
  6863. }
  6864. if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
  6865. (pci_resource_start(pdev, 2))) {
  6866. /*
  6867. * Map SLI4 if type 0 HBA Control Register base to a kernel
  6868. * virtual address and setup the registers.
  6869. */
  6870. phba->pci_bar1_map = pci_resource_start(pdev, 2);
  6871. bar1map_len = pci_resource_len(pdev, 2);
  6872. phba->sli4_hba.ctrl_regs_memmap_p =
  6873. ioremap(phba->pci_bar1_map, bar1map_len);
  6874. if (!phba->sli4_hba.ctrl_regs_memmap_p) {
  6875. dev_printk(KERN_ERR, &pdev->dev,
  6876. "ioremap failed for SLI4 HBA control registers.\n");
  6877. goto out_iounmap_conf;
  6878. }
  6879. lpfc_sli4_bar1_register_memmap(phba);
  6880. }
  6881. if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
  6882. (pci_resource_start(pdev, 4))) {
  6883. /*
  6884. * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
  6885. * virtual address and setup the registers.
  6886. */
  6887. phba->pci_bar2_map = pci_resource_start(pdev, 4);
  6888. bar2map_len = pci_resource_len(pdev, 4);
  6889. phba->sli4_hba.drbl_regs_memmap_p =
  6890. ioremap(phba->pci_bar2_map, bar2map_len);
  6891. if (!phba->sli4_hba.drbl_regs_memmap_p) {
  6892. dev_printk(KERN_ERR, &pdev->dev,
  6893. "ioremap failed for SLI4 HBA doorbell registers.\n");
  6894. goto out_iounmap_ctrl;
  6895. }
  6896. error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
  6897. if (error)
  6898. goto out_iounmap_all;
  6899. }
  6900. return 0;
  6901. out_iounmap_all:
  6902. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  6903. out_iounmap_ctrl:
  6904. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  6905. out_iounmap_conf:
  6906. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  6907. out:
  6908. return error;
  6909. }
  6910. /**
  6911. * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
  6912. * @phba: pointer to lpfc hba data structure.
  6913. *
  6914. * This routine is invoked to unset the PCI device memory space for device
  6915. * with SLI-4 interface spec.
  6916. **/
  6917. static void
  6918. lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
  6919. {
  6920. uint32_t if_type;
  6921. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  6922. switch (if_type) {
  6923. case LPFC_SLI_INTF_IF_TYPE_0:
  6924. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  6925. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  6926. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  6927. break;
  6928. case LPFC_SLI_INTF_IF_TYPE_2:
  6929. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  6930. break;
  6931. case LPFC_SLI_INTF_IF_TYPE_1:
  6932. default:
  6933. dev_printk(KERN_ERR, &phba->pcidev->dev,
  6934. "FATAL - unsupported SLI4 interface type - %d\n",
  6935. if_type);
  6936. break;
  6937. }
  6938. }
  6939. /**
  6940. * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
  6941. * @phba: pointer to lpfc hba data structure.
  6942. *
  6943. * This routine is invoked to enable the MSI-X interrupt vectors to device
  6944. * with SLI-3 interface specs. The kernel function pci_enable_msix() is
  6945. * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
  6946. * invoked, enables either all or nothing, depending on the current
  6947. * availability of PCI vector resources. The device driver is responsible
  6948. * for calling the individual request_irq() to register each MSI-X vector
  6949. * with a interrupt handler, which is done in this function. Note that
  6950. * later when device is unloading, the driver should always call free_irq()
  6951. * on all MSI-X vectors it has done request_irq() on before calling
  6952. * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
  6953. * will be left with MSI-X enabled and leaks its vectors.
  6954. *
  6955. * Return codes
  6956. * 0 - successful
  6957. * other values - error
  6958. **/
  6959. static int
  6960. lpfc_sli_enable_msix(struct lpfc_hba *phba)
  6961. {
  6962. int rc, i;
  6963. LPFC_MBOXQ_t *pmb;
  6964. /* Set up MSI-X multi-message vectors */
  6965. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  6966. phba->msix_entries[i].entry = i;
  6967. /* Configure MSI-X capability structure */
  6968. rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
  6969. ARRAY_SIZE(phba->msix_entries));
  6970. if (rc) {
  6971. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6972. "0420 PCI enable MSI-X failed (%d)\n", rc);
  6973. goto msi_fail_out;
  6974. }
  6975. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  6976. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6977. "0477 MSI-X entry[%d]: vector=x%x "
  6978. "message=%d\n", i,
  6979. phba->msix_entries[i].vector,
  6980. phba->msix_entries[i].entry);
  6981. /*
  6982. * Assign MSI-X vectors to interrupt handlers
  6983. */
  6984. /* vector-0 is associated to slow-path handler */
  6985. rc = request_irq(phba->msix_entries[0].vector,
  6986. &lpfc_sli_sp_intr_handler, IRQF_SHARED,
  6987. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  6988. if (rc) {
  6989. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6990. "0421 MSI-X slow-path request_irq failed "
  6991. "(%d)\n", rc);
  6992. goto msi_fail_out;
  6993. }
  6994. /* vector-1 is associated to fast-path handler */
  6995. rc = request_irq(phba->msix_entries[1].vector,
  6996. &lpfc_sli_fp_intr_handler, IRQF_SHARED,
  6997. LPFC_FP_DRIVER_HANDLER_NAME, phba);
  6998. if (rc) {
  6999. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7000. "0429 MSI-X fast-path request_irq failed "
  7001. "(%d)\n", rc);
  7002. goto irq_fail_out;
  7003. }
  7004. /*
  7005. * Configure HBA MSI-X attention conditions to messages
  7006. */
  7007. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  7008. if (!pmb) {
  7009. rc = -ENOMEM;
  7010. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7011. "0474 Unable to allocate memory for issuing "
  7012. "MBOX_CONFIG_MSI command\n");
  7013. goto mem_fail_out;
  7014. }
  7015. rc = lpfc_config_msi(phba, pmb);
  7016. if (rc)
  7017. goto mbx_fail_out;
  7018. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  7019. if (rc != MBX_SUCCESS) {
  7020. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  7021. "0351 Config MSI mailbox command failed, "
  7022. "mbxCmd x%x, mbxStatus x%x\n",
  7023. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
  7024. goto mbx_fail_out;
  7025. }
  7026. /* Free memory allocated for mailbox command */
  7027. mempool_free(pmb, phba->mbox_mem_pool);
  7028. return rc;
  7029. mbx_fail_out:
  7030. /* Free memory allocated for mailbox command */
  7031. mempool_free(pmb, phba->mbox_mem_pool);
  7032. mem_fail_out:
  7033. /* free the irq already requested */
  7034. free_irq(phba->msix_entries[1].vector, phba);
  7035. irq_fail_out:
  7036. /* free the irq already requested */
  7037. free_irq(phba->msix_entries[0].vector, phba);
  7038. msi_fail_out:
  7039. /* Unconfigure MSI-X capability structure */
  7040. pci_disable_msix(phba->pcidev);
  7041. return rc;
  7042. }
  7043. /**
  7044. * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
  7045. * @phba: pointer to lpfc hba data structure.
  7046. *
  7047. * This routine is invoked to release the MSI-X vectors and then disable the
  7048. * MSI-X interrupt mode to device with SLI-3 interface spec.
  7049. **/
  7050. static void
  7051. lpfc_sli_disable_msix(struct lpfc_hba *phba)
  7052. {
  7053. int i;
  7054. /* Free up MSI-X multi-message vectors */
  7055. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  7056. free_irq(phba->msix_entries[i].vector, phba);
  7057. /* Disable MSI-X */
  7058. pci_disable_msix(phba->pcidev);
  7059. return;
  7060. }
  7061. /**
  7062. * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
  7063. * @phba: pointer to lpfc hba data structure.
  7064. *
  7065. * This routine is invoked to enable the MSI interrupt mode to device with
  7066. * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
  7067. * enable the MSI vector. The device driver is responsible for calling the
  7068. * request_irq() to register MSI vector with a interrupt the handler, which
  7069. * is done in this function.
  7070. *
  7071. * Return codes
  7072. * 0 - successful
  7073. * other values - error
  7074. */
  7075. static int
  7076. lpfc_sli_enable_msi(struct lpfc_hba *phba)
  7077. {
  7078. int rc;
  7079. rc = pci_enable_msi(phba->pcidev);
  7080. if (!rc)
  7081. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7082. "0462 PCI enable MSI mode success.\n");
  7083. else {
  7084. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7085. "0471 PCI enable MSI mode failed (%d)\n", rc);
  7086. return rc;
  7087. }
  7088. rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  7089. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  7090. if (rc) {
  7091. pci_disable_msi(phba->pcidev);
  7092. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7093. "0478 MSI request_irq failed (%d)\n", rc);
  7094. }
  7095. return rc;
  7096. }
  7097. /**
  7098. * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
  7099. * @phba: pointer to lpfc hba data structure.
  7100. *
  7101. * This routine is invoked to disable the MSI interrupt mode to device with
  7102. * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
  7103. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  7104. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  7105. * its vector.
  7106. */
  7107. static void
  7108. lpfc_sli_disable_msi(struct lpfc_hba *phba)
  7109. {
  7110. free_irq(phba->pcidev->irq, phba);
  7111. pci_disable_msi(phba->pcidev);
  7112. return;
  7113. }
  7114. /**
  7115. * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
  7116. * @phba: pointer to lpfc hba data structure.
  7117. *
  7118. * This routine is invoked to enable device interrupt and associate driver's
  7119. * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
  7120. * spec. Depends on the interrupt mode configured to the driver, the driver
  7121. * will try to fallback from the configured interrupt mode to an interrupt
  7122. * mode which is supported by the platform, kernel, and device in the order
  7123. * of:
  7124. * MSI-X -> MSI -> IRQ.
  7125. *
  7126. * Return codes
  7127. * 0 - successful
  7128. * other values - error
  7129. **/
  7130. static uint32_t
  7131. lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  7132. {
  7133. uint32_t intr_mode = LPFC_INTR_ERROR;
  7134. int retval;
  7135. if (cfg_mode == 2) {
  7136. /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
  7137. retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
  7138. if (!retval) {
  7139. /* Now, try to enable MSI-X interrupt mode */
  7140. retval = lpfc_sli_enable_msix(phba);
  7141. if (!retval) {
  7142. /* Indicate initialization to MSI-X mode */
  7143. phba->intr_type = MSIX;
  7144. intr_mode = 2;
  7145. }
  7146. }
  7147. }
  7148. /* Fallback to MSI if MSI-X initialization failed */
  7149. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  7150. retval = lpfc_sli_enable_msi(phba);
  7151. if (!retval) {
  7152. /* Indicate initialization to MSI mode */
  7153. phba->intr_type = MSI;
  7154. intr_mode = 1;
  7155. }
  7156. }
  7157. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  7158. if (phba->intr_type == NONE) {
  7159. retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  7160. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  7161. if (!retval) {
  7162. /* Indicate initialization to INTx mode */
  7163. phba->intr_type = INTx;
  7164. intr_mode = 0;
  7165. }
  7166. }
  7167. return intr_mode;
  7168. }
  7169. /**
  7170. * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
  7171. * @phba: pointer to lpfc hba data structure.
  7172. *
  7173. * This routine is invoked to disable device interrupt and disassociate the
  7174. * driver's interrupt handler(s) from interrupt vector(s) to device with
  7175. * SLI-3 interface spec. Depending on the interrupt mode, the driver will
  7176. * release the interrupt vector(s) for the message signaled interrupt.
  7177. **/
  7178. static void
  7179. lpfc_sli_disable_intr(struct lpfc_hba *phba)
  7180. {
  7181. /* Disable the currently initialized interrupt mode */
  7182. if (phba->intr_type == MSIX)
  7183. lpfc_sli_disable_msix(phba);
  7184. else if (phba->intr_type == MSI)
  7185. lpfc_sli_disable_msi(phba);
  7186. else if (phba->intr_type == INTx)
  7187. free_irq(phba->pcidev->irq, phba);
  7188. /* Reset interrupt management states */
  7189. phba->intr_type = NONE;
  7190. phba->sli.slistat.sli_intr = 0;
  7191. return;
  7192. }
  7193. /**
  7194. * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
  7195. * @phba: pointer to lpfc hba data structure.
  7196. *
  7197. * This routine is invoked to enable the MSI-X interrupt vectors to device
  7198. * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
  7199. * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
  7200. * enables either all or nothing, depending on the current availability of
  7201. * PCI vector resources. The device driver is responsible for calling the
  7202. * individual request_irq() to register each MSI-X vector with a interrupt
  7203. * handler, which is done in this function. Note that later when device is
  7204. * unloading, the driver should always call free_irq() on all MSI-X vectors
  7205. * it has done request_irq() on before calling pci_disable_msix(). Failure
  7206. * to do so results in a BUG_ON() and a device will be left with MSI-X
  7207. * enabled and leaks its vectors.
  7208. *
  7209. * Return codes
  7210. * 0 - successful
  7211. * other values - error
  7212. **/
  7213. static int
  7214. lpfc_sli4_enable_msix(struct lpfc_hba *phba)
  7215. {
  7216. int vectors, rc, index;
  7217. /* Set up MSI-X multi-message vectors */
  7218. for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
  7219. phba->sli4_hba.msix_entries[index].entry = index;
  7220. /* Configure MSI-X capability structure */
  7221. vectors = phba->sli4_hba.cfg_eqn;
  7222. enable_msix_vectors:
  7223. rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
  7224. vectors);
  7225. if (rc > 1) {
  7226. vectors = rc;
  7227. goto enable_msix_vectors;
  7228. } else if (rc) {
  7229. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7230. "0484 PCI enable MSI-X failed (%d)\n", rc);
  7231. goto msi_fail_out;
  7232. }
  7233. /* Log MSI-X vector assignment */
  7234. for (index = 0; index < vectors; index++)
  7235. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7236. "0489 MSI-X entry[%d]: vector=x%x "
  7237. "message=%d\n", index,
  7238. phba->sli4_hba.msix_entries[index].vector,
  7239. phba->sli4_hba.msix_entries[index].entry);
  7240. /*
  7241. * Assign MSI-X vectors to interrupt handlers
  7242. */
  7243. if (vectors > 1)
  7244. rc = request_irq(phba->sli4_hba.msix_entries[0].vector,
  7245. &lpfc_sli4_sp_intr_handler, IRQF_SHARED,
  7246. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  7247. else
  7248. /* All Interrupts need to be handled by one EQ */
  7249. rc = request_irq(phba->sli4_hba.msix_entries[0].vector,
  7250. &lpfc_sli4_intr_handler, IRQF_SHARED,
  7251. LPFC_DRIVER_NAME, phba);
  7252. if (rc) {
  7253. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7254. "0485 MSI-X slow-path request_irq failed "
  7255. "(%d)\n", rc);
  7256. goto msi_fail_out;
  7257. }
  7258. /* The rest of the vector(s) are associated to fast-path handler(s) */
  7259. for (index = 1; index < vectors; index++) {
  7260. phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1;
  7261. phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba;
  7262. rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
  7263. &lpfc_sli4_fp_intr_handler, IRQF_SHARED,
  7264. LPFC_FP_DRIVER_HANDLER_NAME,
  7265. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  7266. if (rc) {
  7267. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7268. "0486 MSI-X fast-path (%d) "
  7269. "request_irq failed (%d)\n", index, rc);
  7270. goto cfg_fail_out;
  7271. }
  7272. }
  7273. phba->sli4_hba.msix_vec_nr = vectors;
  7274. return rc;
  7275. cfg_fail_out:
  7276. /* free the irq already requested */
  7277. for (--index; index >= 1; index--)
  7278. free_irq(phba->sli4_hba.msix_entries[index - 1].vector,
  7279. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  7280. /* free the irq already requested */
  7281. free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
  7282. msi_fail_out:
  7283. /* Unconfigure MSI-X capability structure */
  7284. pci_disable_msix(phba->pcidev);
  7285. return rc;
  7286. }
  7287. /**
  7288. * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
  7289. * @phba: pointer to lpfc hba data structure.
  7290. *
  7291. * This routine is invoked to release the MSI-X vectors and then disable the
  7292. * MSI-X interrupt mode to device with SLI-4 interface spec.
  7293. **/
  7294. static void
  7295. lpfc_sli4_disable_msix(struct lpfc_hba *phba)
  7296. {
  7297. int index;
  7298. /* Free up MSI-X multi-message vectors */
  7299. free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
  7300. for (index = 1; index < phba->sli4_hba.msix_vec_nr; index++)
  7301. free_irq(phba->sli4_hba.msix_entries[index].vector,
  7302. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  7303. /* Disable MSI-X */
  7304. pci_disable_msix(phba->pcidev);
  7305. return;
  7306. }
  7307. /**
  7308. * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
  7309. * @phba: pointer to lpfc hba data structure.
  7310. *
  7311. * This routine is invoked to enable the MSI interrupt mode to device with
  7312. * SLI-4 interface spec. The kernel function pci_enable_msi() is called
  7313. * to enable the MSI vector. The device driver is responsible for calling
  7314. * the request_irq() to register MSI vector with a interrupt the handler,
  7315. * which is done in this function.
  7316. *
  7317. * Return codes
  7318. * 0 - successful
  7319. * other values - error
  7320. **/
  7321. static int
  7322. lpfc_sli4_enable_msi(struct lpfc_hba *phba)
  7323. {
  7324. int rc, index;
  7325. rc = pci_enable_msi(phba->pcidev);
  7326. if (!rc)
  7327. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7328. "0487 PCI enable MSI mode success.\n");
  7329. else {
  7330. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7331. "0488 PCI enable MSI mode failed (%d)\n", rc);
  7332. return rc;
  7333. }
  7334. rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  7335. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  7336. if (rc) {
  7337. pci_disable_msi(phba->pcidev);
  7338. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7339. "0490 MSI request_irq failed (%d)\n", rc);
  7340. return rc;
  7341. }
  7342. for (index = 0; index < phba->cfg_fcp_eq_count; index++) {
  7343. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  7344. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  7345. }
  7346. return 0;
  7347. }
  7348. /**
  7349. * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
  7350. * @phba: pointer to lpfc hba data structure.
  7351. *
  7352. * This routine is invoked to disable the MSI interrupt mode to device with
  7353. * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
  7354. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  7355. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  7356. * its vector.
  7357. **/
  7358. static void
  7359. lpfc_sli4_disable_msi(struct lpfc_hba *phba)
  7360. {
  7361. free_irq(phba->pcidev->irq, phba);
  7362. pci_disable_msi(phba->pcidev);
  7363. return;
  7364. }
  7365. /**
  7366. * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
  7367. * @phba: pointer to lpfc hba data structure.
  7368. *
  7369. * This routine is invoked to enable device interrupt and associate driver's
  7370. * interrupt handler(s) to interrupt vector(s) to device with SLI-4
  7371. * interface spec. Depends on the interrupt mode configured to the driver,
  7372. * the driver will try to fallback from the configured interrupt mode to an
  7373. * interrupt mode which is supported by the platform, kernel, and device in
  7374. * the order of:
  7375. * MSI-X -> MSI -> IRQ.
  7376. *
  7377. * Return codes
  7378. * 0 - successful
  7379. * other values - error
  7380. **/
  7381. static uint32_t
  7382. lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  7383. {
  7384. uint32_t intr_mode = LPFC_INTR_ERROR;
  7385. int retval, index;
  7386. if (cfg_mode == 2) {
  7387. /* Preparation before conf_msi mbox cmd */
  7388. retval = 0;
  7389. if (!retval) {
  7390. /* Now, try to enable MSI-X interrupt mode */
  7391. retval = lpfc_sli4_enable_msix(phba);
  7392. if (!retval) {
  7393. /* Indicate initialization to MSI-X mode */
  7394. phba->intr_type = MSIX;
  7395. intr_mode = 2;
  7396. }
  7397. }
  7398. }
  7399. /* Fallback to MSI if MSI-X initialization failed */
  7400. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  7401. retval = lpfc_sli4_enable_msi(phba);
  7402. if (!retval) {
  7403. /* Indicate initialization to MSI mode */
  7404. phba->intr_type = MSI;
  7405. intr_mode = 1;
  7406. }
  7407. }
  7408. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  7409. if (phba->intr_type == NONE) {
  7410. retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  7411. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  7412. if (!retval) {
  7413. /* Indicate initialization to INTx mode */
  7414. phba->intr_type = INTx;
  7415. intr_mode = 0;
  7416. for (index = 0; index < phba->cfg_fcp_eq_count;
  7417. index++) {
  7418. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  7419. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  7420. }
  7421. }
  7422. }
  7423. return intr_mode;
  7424. }
  7425. /**
  7426. * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
  7427. * @phba: pointer to lpfc hba data structure.
  7428. *
  7429. * This routine is invoked to disable device interrupt and disassociate
  7430. * the driver's interrupt handler(s) from interrupt vector(s) to device
  7431. * with SLI-4 interface spec. Depending on the interrupt mode, the driver
  7432. * will release the interrupt vector(s) for the message signaled interrupt.
  7433. **/
  7434. static void
  7435. lpfc_sli4_disable_intr(struct lpfc_hba *phba)
  7436. {
  7437. /* Disable the currently initialized interrupt mode */
  7438. if (phba->intr_type == MSIX)
  7439. lpfc_sli4_disable_msix(phba);
  7440. else if (phba->intr_type == MSI)
  7441. lpfc_sli4_disable_msi(phba);
  7442. else if (phba->intr_type == INTx)
  7443. free_irq(phba->pcidev->irq, phba);
  7444. /* Reset interrupt management states */
  7445. phba->intr_type = NONE;
  7446. phba->sli.slistat.sli_intr = 0;
  7447. return;
  7448. }
  7449. /**
  7450. * lpfc_unset_hba - Unset SLI3 hba device initialization
  7451. * @phba: pointer to lpfc hba data structure.
  7452. *
  7453. * This routine is invoked to unset the HBA device initialization steps to
  7454. * a device with SLI-3 interface spec.
  7455. **/
  7456. static void
  7457. lpfc_unset_hba(struct lpfc_hba *phba)
  7458. {
  7459. struct lpfc_vport *vport = phba->pport;
  7460. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  7461. spin_lock_irq(shost->host_lock);
  7462. vport->load_flag |= FC_UNLOADING;
  7463. spin_unlock_irq(shost->host_lock);
  7464. kfree(phba->vpi_bmask);
  7465. kfree(phba->vpi_ids);
  7466. lpfc_stop_hba_timers(phba);
  7467. phba->pport->work_port_events = 0;
  7468. lpfc_sli_hba_down(phba);
  7469. lpfc_sli_brdrestart(phba);
  7470. lpfc_sli_disable_intr(phba);
  7471. return;
  7472. }
  7473. /**
  7474. * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
  7475. * @phba: pointer to lpfc hba data structure.
  7476. *
  7477. * This routine is invoked to unset the HBA device initialization steps to
  7478. * a device with SLI-4 interface spec.
  7479. **/
  7480. static void
  7481. lpfc_sli4_unset_hba(struct lpfc_hba *phba)
  7482. {
  7483. struct lpfc_vport *vport = phba->pport;
  7484. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  7485. spin_lock_irq(shost->host_lock);
  7486. vport->load_flag |= FC_UNLOADING;
  7487. spin_unlock_irq(shost->host_lock);
  7488. phba->pport->work_port_events = 0;
  7489. /* Stop the SLI4 device port */
  7490. lpfc_stop_port(phba);
  7491. lpfc_sli4_disable_intr(phba);
  7492. /* Reset SLI4 HBA FCoE function */
  7493. lpfc_pci_function_reset(phba);
  7494. lpfc_sli4_queue_destroy(phba);
  7495. return;
  7496. }
  7497. /**
  7498. * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
  7499. * @phba: Pointer to HBA context object.
  7500. *
  7501. * This function is called in the SLI4 code path to wait for completion
  7502. * of device's XRIs exchange busy. It will check the XRI exchange busy
  7503. * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
  7504. * that, it will check the XRI exchange busy on outstanding FCP and ELS
  7505. * I/Os every 30 seconds, log error message, and wait forever. Only when
  7506. * all XRI exchange busy complete, the driver unload shall proceed with
  7507. * invoking the function reset ioctl mailbox command to the CNA and the
  7508. * the rest of the driver unload resource release.
  7509. **/
  7510. static void
  7511. lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
  7512. {
  7513. int wait_time = 0;
  7514. int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  7515. int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  7516. while (!fcp_xri_cmpl || !els_xri_cmpl) {
  7517. if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
  7518. if (!fcp_xri_cmpl)
  7519. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7520. "2877 FCP XRI exchange busy "
  7521. "wait time: %d seconds.\n",
  7522. wait_time/1000);
  7523. if (!els_xri_cmpl)
  7524. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7525. "2878 ELS XRI exchange busy "
  7526. "wait time: %d seconds.\n",
  7527. wait_time/1000);
  7528. msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
  7529. wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
  7530. } else {
  7531. msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
  7532. wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
  7533. }
  7534. fcp_xri_cmpl =
  7535. list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  7536. els_xri_cmpl =
  7537. list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  7538. }
  7539. }
  7540. /**
  7541. * lpfc_sli4_hba_unset - Unset the fcoe hba
  7542. * @phba: Pointer to HBA context object.
  7543. *
  7544. * This function is called in the SLI4 code path to reset the HBA's FCoE
  7545. * function. The caller is not required to hold any lock. This routine
  7546. * issues PCI function reset mailbox command to reset the FCoE function.
  7547. * At the end of the function, it calls lpfc_hba_down_post function to
  7548. * free any pending commands.
  7549. **/
  7550. static void
  7551. lpfc_sli4_hba_unset(struct lpfc_hba *phba)
  7552. {
  7553. int wait_cnt = 0;
  7554. LPFC_MBOXQ_t *mboxq;
  7555. struct pci_dev *pdev = phba->pcidev;
  7556. lpfc_stop_hba_timers(phba);
  7557. phba->sli4_hba.intr_enable = 0;
  7558. /*
  7559. * Gracefully wait out the potential current outstanding asynchronous
  7560. * mailbox command.
  7561. */
  7562. /* First, block any pending async mailbox command from posted */
  7563. spin_lock_irq(&phba->hbalock);
  7564. phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7565. spin_unlock_irq(&phba->hbalock);
  7566. /* Now, trying to wait it out if we can */
  7567. while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  7568. msleep(10);
  7569. if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
  7570. break;
  7571. }
  7572. /* Forcefully release the outstanding mailbox command if timed out */
  7573. if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  7574. spin_lock_irq(&phba->hbalock);
  7575. mboxq = phba->sli.mbox_active;
  7576. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  7577. __lpfc_mbox_cmpl_put(phba, mboxq);
  7578. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7579. phba->sli.mbox_active = NULL;
  7580. spin_unlock_irq(&phba->hbalock);
  7581. }
  7582. /* Abort all iocbs associated with the hba */
  7583. lpfc_sli_hba_iocb_abort(phba);
  7584. /* Wait for completion of device XRI exchange busy */
  7585. lpfc_sli4_xri_exchange_busy_wait(phba);
  7586. /* Disable PCI subsystem interrupt */
  7587. lpfc_sli4_disable_intr(phba);
  7588. /* Disable SR-IOV if enabled */
  7589. if (phba->cfg_sriov_nr_virtfn)
  7590. pci_disable_sriov(pdev);
  7591. /* Stop kthread signal shall trigger work_done one more time */
  7592. kthread_stop(phba->worker_thread);
  7593. /* Reset SLI4 HBA FCoE function */
  7594. lpfc_pci_function_reset(phba);
  7595. lpfc_sli4_queue_destroy(phba);
  7596. /* Stop the SLI4 device port */
  7597. phba->pport->work_port_events = 0;
  7598. }
  7599. /**
  7600. * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
  7601. * @phba: Pointer to HBA context object.
  7602. * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
  7603. *
  7604. * This function is called in the SLI4 code path to read the port's
  7605. * sli4 capabilities.
  7606. *
  7607. * This function may be be called from any context that can block-wait
  7608. * for the completion. The expectation is that this routine is called
  7609. * typically from probe_one or from the online routine.
  7610. **/
  7611. int
  7612. lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  7613. {
  7614. int rc;
  7615. struct lpfc_mqe *mqe;
  7616. struct lpfc_pc_sli4_params *sli4_params;
  7617. uint32_t mbox_tmo;
  7618. rc = 0;
  7619. mqe = &mboxq->u.mqe;
  7620. /* Read the port's SLI4 Parameters port capabilities */
  7621. lpfc_pc_sli4_params(mboxq);
  7622. if (!phba->sli4_hba.intr_enable)
  7623. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7624. else {
  7625. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  7626. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  7627. }
  7628. if (unlikely(rc))
  7629. return 1;
  7630. sli4_params = &phba->sli4_hba.pc_sli4_params;
  7631. sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
  7632. sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
  7633. sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
  7634. sli4_params->featurelevel_1 = bf_get(featurelevel_1,
  7635. &mqe->un.sli4_params);
  7636. sli4_params->featurelevel_2 = bf_get(featurelevel_2,
  7637. &mqe->un.sli4_params);
  7638. sli4_params->proto_types = mqe->un.sli4_params.word3;
  7639. sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
  7640. sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
  7641. sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
  7642. sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
  7643. sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
  7644. sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
  7645. sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
  7646. sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
  7647. sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
  7648. sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
  7649. sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
  7650. sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
  7651. sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
  7652. sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
  7653. sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
  7654. sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
  7655. sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
  7656. sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
  7657. sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
  7658. sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
  7659. /* Make sure that sge_supp_len can be handled by the driver */
  7660. if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
  7661. sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
  7662. return rc;
  7663. }
  7664. /**
  7665. * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
  7666. * @phba: Pointer to HBA context object.
  7667. * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
  7668. *
  7669. * This function is called in the SLI4 code path to read the port's
  7670. * sli4 capabilities.
  7671. *
  7672. * This function may be be called from any context that can block-wait
  7673. * for the completion. The expectation is that this routine is called
  7674. * typically from probe_one or from the online routine.
  7675. **/
  7676. int
  7677. lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  7678. {
  7679. int rc;
  7680. struct lpfc_mqe *mqe = &mboxq->u.mqe;
  7681. struct lpfc_pc_sli4_params *sli4_params;
  7682. uint32_t mbox_tmo;
  7683. int length;
  7684. struct lpfc_sli4_parameters *mbx_sli4_parameters;
  7685. /*
  7686. * By default, the driver assumes the SLI4 port requires RPI
  7687. * header postings. The SLI4_PARAM response will correct this
  7688. * assumption.
  7689. */
  7690. phba->sli4_hba.rpi_hdrs_in_use = 1;
  7691. /* Read the port's SLI4 Config Parameters */
  7692. length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
  7693. sizeof(struct lpfc_sli4_cfg_mhdr));
  7694. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  7695. LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
  7696. length, LPFC_SLI4_MBX_EMBED);
  7697. if (!phba->sli4_hba.intr_enable)
  7698. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7699. else {
  7700. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  7701. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  7702. }
  7703. if (unlikely(rc))
  7704. return rc;
  7705. sli4_params = &phba->sli4_hba.pc_sli4_params;
  7706. mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
  7707. sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
  7708. sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
  7709. sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
  7710. sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
  7711. mbx_sli4_parameters);
  7712. sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
  7713. mbx_sli4_parameters);
  7714. if (bf_get(cfg_phwq, mbx_sli4_parameters))
  7715. phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
  7716. else
  7717. phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
  7718. sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
  7719. sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
  7720. sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
  7721. sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
  7722. sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
  7723. sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
  7724. sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
  7725. mbx_sli4_parameters);
  7726. sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
  7727. mbx_sli4_parameters);
  7728. phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
  7729. phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
  7730. /* Make sure that sge_supp_len can be handled by the driver */
  7731. if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
  7732. sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
  7733. return 0;
  7734. }
  7735. /**
  7736. * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
  7737. * @pdev: pointer to PCI device
  7738. * @pid: pointer to PCI device identifier
  7739. *
  7740. * This routine is to be called to attach a device with SLI-3 interface spec
  7741. * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  7742. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  7743. * information of the device and driver to see if the driver state that it can
  7744. * support this kind of device. If the match is successful, the driver core
  7745. * invokes this routine. If this routine determines it can claim the HBA, it
  7746. * does all the initialization that it needs to do to handle the HBA properly.
  7747. *
  7748. * Return code
  7749. * 0 - driver can claim the device
  7750. * negative value - driver can not claim the device
  7751. **/
  7752. static int __devinit
  7753. lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
  7754. {
  7755. struct lpfc_hba *phba;
  7756. struct lpfc_vport *vport = NULL;
  7757. struct Scsi_Host *shost = NULL;
  7758. int error;
  7759. uint32_t cfg_mode, intr_mode;
  7760. /* Allocate memory for HBA structure */
  7761. phba = lpfc_hba_alloc(pdev);
  7762. if (!phba)
  7763. return -ENOMEM;
  7764. /* Perform generic PCI device enabling operation */
  7765. error = lpfc_enable_pci_dev(phba);
  7766. if (error)
  7767. goto out_free_phba;
  7768. /* Set up SLI API function jump table for PCI-device group-0 HBAs */
  7769. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
  7770. if (error)
  7771. goto out_disable_pci_dev;
  7772. /* Set up SLI-3 specific device PCI memory space */
  7773. error = lpfc_sli_pci_mem_setup(phba);
  7774. if (error) {
  7775. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7776. "1402 Failed to set up pci memory space.\n");
  7777. goto out_disable_pci_dev;
  7778. }
  7779. /* Set up phase-1 common device driver resources */
  7780. error = lpfc_setup_driver_resource_phase1(phba);
  7781. if (error) {
  7782. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7783. "1403 Failed to set up driver resource.\n");
  7784. goto out_unset_pci_mem_s3;
  7785. }
  7786. /* Set up SLI-3 specific device driver resources */
  7787. error = lpfc_sli_driver_resource_setup(phba);
  7788. if (error) {
  7789. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7790. "1404 Failed to set up driver resource.\n");
  7791. goto out_unset_pci_mem_s3;
  7792. }
  7793. /* Initialize and populate the iocb list per host */
  7794. error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
  7795. if (error) {
  7796. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7797. "1405 Failed to initialize iocb list.\n");
  7798. goto out_unset_driver_resource_s3;
  7799. }
  7800. /* Set up common device driver resources */
  7801. error = lpfc_setup_driver_resource_phase2(phba);
  7802. if (error) {
  7803. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7804. "1406 Failed to set up driver resource.\n");
  7805. goto out_free_iocb_list;
  7806. }
  7807. /* Get the default values for Model Name and Description */
  7808. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  7809. /* Create SCSI host to the physical port */
  7810. error = lpfc_create_shost(phba);
  7811. if (error) {
  7812. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7813. "1407 Failed to create scsi host.\n");
  7814. goto out_unset_driver_resource;
  7815. }
  7816. /* Configure sysfs attributes */
  7817. vport = phba->pport;
  7818. error = lpfc_alloc_sysfs_attr(vport);
  7819. if (error) {
  7820. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7821. "1476 Failed to allocate sysfs attr\n");
  7822. goto out_destroy_shost;
  7823. }
  7824. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  7825. /* Now, trying to enable interrupt and bring up the device */
  7826. cfg_mode = phba->cfg_use_msi;
  7827. while (true) {
  7828. /* Put device to a known state before enabling interrupt */
  7829. lpfc_stop_port(phba);
  7830. /* Configure and enable interrupt */
  7831. intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
  7832. if (intr_mode == LPFC_INTR_ERROR) {
  7833. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7834. "0431 Failed to enable interrupt.\n");
  7835. error = -ENODEV;
  7836. goto out_free_sysfs_attr;
  7837. }
  7838. /* SLI-3 HBA setup */
  7839. if (lpfc_sli_hba_setup(phba)) {
  7840. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7841. "1477 Failed to set up hba\n");
  7842. error = -ENODEV;
  7843. goto out_remove_device;
  7844. }
  7845. /* Wait 50ms for the interrupts of previous mailbox commands */
  7846. msleep(50);
  7847. /* Check active interrupts on message signaled interrupts */
  7848. if (intr_mode == 0 ||
  7849. phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
  7850. /* Log the current active interrupt mode */
  7851. phba->intr_mode = intr_mode;
  7852. lpfc_log_intr_mode(phba, intr_mode);
  7853. break;
  7854. } else {
  7855. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7856. "0447 Configure interrupt mode (%d) "
  7857. "failed active interrupt test.\n",
  7858. intr_mode);
  7859. /* Disable the current interrupt mode */
  7860. lpfc_sli_disable_intr(phba);
  7861. /* Try next level of interrupt mode */
  7862. cfg_mode = --intr_mode;
  7863. }
  7864. }
  7865. /* Perform post initialization setup */
  7866. lpfc_post_init_setup(phba);
  7867. /* Check if there are static vports to be created. */
  7868. lpfc_create_static_vport(phba);
  7869. return 0;
  7870. out_remove_device:
  7871. lpfc_unset_hba(phba);
  7872. out_free_sysfs_attr:
  7873. lpfc_free_sysfs_attr(vport);
  7874. out_destroy_shost:
  7875. lpfc_destroy_shost(phba);
  7876. out_unset_driver_resource:
  7877. lpfc_unset_driver_resource_phase2(phba);
  7878. out_free_iocb_list:
  7879. lpfc_free_iocb_list(phba);
  7880. out_unset_driver_resource_s3:
  7881. lpfc_sli_driver_resource_unset(phba);
  7882. out_unset_pci_mem_s3:
  7883. lpfc_sli_pci_mem_unset(phba);
  7884. out_disable_pci_dev:
  7885. lpfc_disable_pci_dev(phba);
  7886. if (shost)
  7887. scsi_host_put(shost);
  7888. out_free_phba:
  7889. lpfc_hba_free(phba);
  7890. return error;
  7891. }
  7892. /**
  7893. * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
  7894. * @pdev: pointer to PCI device
  7895. *
  7896. * This routine is to be called to disattach a device with SLI-3 interface
  7897. * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  7898. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  7899. * device to be removed from the PCI subsystem properly.
  7900. **/
  7901. static void __devexit
  7902. lpfc_pci_remove_one_s3(struct pci_dev *pdev)
  7903. {
  7904. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7905. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  7906. struct lpfc_vport **vports;
  7907. struct lpfc_hba *phba = vport->phba;
  7908. int i;
  7909. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  7910. spin_lock_irq(&phba->hbalock);
  7911. vport->load_flag |= FC_UNLOADING;
  7912. spin_unlock_irq(&phba->hbalock);
  7913. lpfc_free_sysfs_attr(vport);
  7914. /* Release all the vports against this physical port */
  7915. vports = lpfc_create_vport_work_array(phba);
  7916. if (vports != NULL)
  7917. for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
  7918. fc_vport_terminate(vports[i]->fc_vport);
  7919. lpfc_destroy_vport_work_array(phba, vports);
  7920. /* Remove FC host and then SCSI host with the physical port */
  7921. fc_remove_host(shost);
  7922. scsi_remove_host(shost);
  7923. lpfc_cleanup(vport);
  7924. /*
  7925. * Bring down the SLI Layer. This step disable all interrupts,
  7926. * clears the rings, discards all mailbox commands, and resets
  7927. * the HBA.
  7928. */
  7929. /* HBA interrupt will be disabled after this call */
  7930. lpfc_sli_hba_down(phba);
  7931. /* Stop kthread signal shall trigger work_done one more time */
  7932. kthread_stop(phba->worker_thread);
  7933. /* Final cleanup of txcmplq and reset the HBA */
  7934. lpfc_sli_brdrestart(phba);
  7935. kfree(phba->vpi_bmask);
  7936. kfree(phba->vpi_ids);
  7937. lpfc_stop_hba_timers(phba);
  7938. spin_lock_irq(&phba->hbalock);
  7939. list_del_init(&vport->listentry);
  7940. spin_unlock_irq(&phba->hbalock);
  7941. lpfc_debugfs_terminate(vport);
  7942. /* Disable SR-IOV if enabled */
  7943. if (phba->cfg_sriov_nr_virtfn)
  7944. pci_disable_sriov(pdev);
  7945. /* Disable interrupt */
  7946. lpfc_sli_disable_intr(phba);
  7947. pci_set_drvdata(pdev, NULL);
  7948. scsi_host_put(shost);
  7949. /*
  7950. * Call scsi_free before mem_free since scsi bufs are released to their
  7951. * corresponding pools here.
  7952. */
  7953. lpfc_scsi_free(phba);
  7954. lpfc_mem_free_all(phba);
  7955. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  7956. phba->hbqslimp.virt, phba->hbqslimp.phys);
  7957. /* Free resources associated with SLI2 interface */
  7958. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  7959. phba->slim2p.virt, phba->slim2p.phys);
  7960. /* unmap adapter SLIM and Control Registers */
  7961. iounmap(phba->ctrl_regs_memmap_p);
  7962. iounmap(phba->slim_memmap_p);
  7963. lpfc_hba_free(phba);
  7964. pci_release_selected_regions(pdev, bars);
  7965. pci_disable_device(pdev);
  7966. }
  7967. /**
  7968. * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
  7969. * @pdev: pointer to PCI device
  7970. * @msg: power management message
  7971. *
  7972. * This routine is to be called from the kernel's PCI subsystem to support
  7973. * system Power Management (PM) to device with SLI-3 interface spec. When
  7974. * PM invokes this method, it quiesces the device by stopping the driver's
  7975. * worker thread for the device, turning off device's interrupt and DMA,
  7976. * and bring the device offline. Note that as the driver implements the
  7977. * minimum PM requirements to a power-aware driver's PM support for the
  7978. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  7979. * to the suspend() method call will be treated as SUSPEND and the driver will
  7980. * fully reinitialize its device during resume() method call, the driver will
  7981. * set device to PCI_D3hot state in PCI config space instead of setting it
  7982. * according to the @msg provided by the PM.
  7983. *
  7984. * Return code
  7985. * 0 - driver suspended the device
  7986. * Error otherwise
  7987. **/
  7988. static int
  7989. lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
  7990. {
  7991. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7992. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7993. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7994. "0473 PCI device Power Management suspend.\n");
  7995. /* Bring down the device */
  7996. lpfc_offline_prep(phba);
  7997. lpfc_offline(phba);
  7998. kthread_stop(phba->worker_thread);
  7999. /* Disable interrupt from device */
  8000. lpfc_sli_disable_intr(phba);
  8001. /* Save device state to PCI config space */
  8002. pci_save_state(pdev);
  8003. pci_set_power_state(pdev, PCI_D3hot);
  8004. return 0;
  8005. }
  8006. /**
  8007. * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
  8008. * @pdev: pointer to PCI device
  8009. *
  8010. * This routine is to be called from the kernel's PCI subsystem to support
  8011. * system Power Management (PM) to device with SLI-3 interface spec. When PM
  8012. * invokes this method, it restores the device's PCI config space state and
  8013. * fully reinitializes the device and brings it online. Note that as the
  8014. * driver implements the minimum PM requirements to a power-aware driver's
  8015. * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
  8016. * FREEZE) to the suspend() method call will be treated as SUSPEND and the
  8017. * driver will fully reinitialize its device during resume() method call,
  8018. * the device will be set to PCI_D0 directly in PCI config space before
  8019. * restoring the state.
  8020. *
  8021. * Return code
  8022. * 0 - driver suspended the device
  8023. * Error otherwise
  8024. **/
  8025. static int
  8026. lpfc_pci_resume_one_s3(struct pci_dev *pdev)
  8027. {
  8028. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8029. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8030. uint32_t intr_mode;
  8031. int error;
  8032. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8033. "0452 PCI device Power Management resume.\n");
  8034. /* Restore device state from PCI config space */
  8035. pci_set_power_state(pdev, PCI_D0);
  8036. pci_restore_state(pdev);
  8037. /*
  8038. * As the new kernel behavior of pci_restore_state() API call clears
  8039. * device saved_state flag, need to save the restored state again.
  8040. */
  8041. pci_save_state(pdev);
  8042. if (pdev->is_busmaster)
  8043. pci_set_master(pdev);
  8044. /* Startup the kernel thread for this host adapter. */
  8045. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  8046. "lpfc_worker_%d", phba->brd_no);
  8047. if (IS_ERR(phba->worker_thread)) {
  8048. error = PTR_ERR(phba->worker_thread);
  8049. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8050. "0434 PM resume failed to start worker "
  8051. "thread: error=x%x.\n", error);
  8052. return error;
  8053. }
  8054. /* Configure and enable interrupt */
  8055. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  8056. if (intr_mode == LPFC_INTR_ERROR) {
  8057. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8058. "0430 PM resume Failed to enable interrupt\n");
  8059. return -EIO;
  8060. } else
  8061. phba->intr_mode = intr_mode;
  8062. /* Restart HBA and bring it online */
  8063. lpfc_sli_brdrestart(phba);
  8064. lpfc_online(phba);
  8065. /* Log the current active interrupt mode */
  8066. lpfc_log_intr_mode(phba, phba->intr_mode);
  8067. return 0;
  8068. }
  8069. /**
  8070. * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
  8071. * @phba: pointer to lpfc hba data structure.
  8072. *
  8073. * This routine is called to prepare the SLI3 device for PCI slot recover. It
  8074. * aborts all the outstanding SCSI I/Os to the pci device.
  8075. **/
  8076. static void
  8077. lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
  8078. {
  8079. struct lpfc_sli *psli = &phba->sli;
  8080. struct lpfc_sli_ring *pring;
  8081. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8082. "2723 PCI channel I/O abort preparing for recovery\n");
  8083. /*
  8084. * There may be errored I/Os through HBA, abort all I/Os on txcmplq
  8085. * and let the SCSI mid-layer to retry them to recover.
  8086. */
  8087. pring = &psli->ring[psli->fcp_ring];
  8088. lpfc_sli_abort_iocb_ring(phba, pring);
  8089. }
  8090. /**
  8091. * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
  8092. * @phba: pointer to lpfc hba data structure.
  8093. *
  8094. * This routine is called to prepare the SLI3 device for PCI slot reset. It
  8095. * disables the device interrupt and pci device, and aborts the internal FCP
  8096. * pending I/Os.
  8097. **/
  8098. static void
  8099. lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
  8100. {
  8101. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8102. "2710 PCI channel disable preparing for reset\n");
  8103. /* Block any management I/Os to the device */
  8104. lpfc_block_mgmt_io(phba);
  8105. /* Block all SCSI devices' I/Os on the host */
  8106. lpfc_scsi_dev_block(phba);
  8107. /* stop all timers */
  8108. lpfc_stop_hba_timers(phba);
  8109. /* Disable interrupt and pci device */
  8110. lpfc_sli_disable_intr(phba);
  8111. pci_disable_device(phba->pcidev);
  8112. /* Flush all driver's outstanding SCSI I/Os as we are to reset */
  8113. lpfc_sli_flush_fcp_rings(phba);
  8114. }
  8115. /**
  8116. * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
  8117. * @phba: pointer to lpfc hba data structure.
  8118. *
  8119. * This routine is called to prepare the SLI3 device for PCI slot permanently
  8120. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  8121. * pending I/Os.
  8122. **/
  8123. static void
  8124. lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  8125. {
  8126. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8127. "2711 PCI channel permanent disable for failure\n");
  8128. /* Block all SCSI devices' I/Os on the host */
  8129. lpfc_scsi_dev_block(phba);
  8130. /* stop all timers */
  8131. lpfc_stop_hba_timers(phba);
  8132. /* Clean up all driver's outstanding SCSI I/Os */
  8133. lpfc_sli_flush_fcp_rings(phba);
  8134. }
  8135. /**
  8136. * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
  8137. * @pdev: pointer to PCI device.
  8138. * @state: the current PCI connection state.
  8139. *
  8140. * This routine is called from the PCI subsystem for I/O error handling to
  8141. * device with SLI-3 interface spec. This function is called by the PCI
  8142. * subsystem after a PCI bus error affecting this device has been detected.
  8143. * When this function is invoked, it will need to stop all the I/Os and
  8144. * interrupt(s) to the device. Once that is done, it will return
  8145. * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
  8146. * as desired.
  8147. *
  8148. * Return codes
  8149. * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
  8150. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  8151. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  8152. **/
  8153. static pci_ers_result_t
  8154. lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
  8155. {
  8156. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8157. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8158. switch (state) {
  8159. case pci_channel_io_normal:
  8160. /* Non-fatal error, prepare for recovery */
  8161. lpfc_sli_prep_dev_for_recover(phba);
  8162. return PCI_ERS_RESULT_CAN_RECOVER;
  8163. case pci_channel_io_frozen:
  8164. /* Fatal error, prepare for slot reset */
  8165. lpfc_sli_prep_dev_for_reset(phba);
  8166. return PCI_ERS_RESULT_NEED_RESET;
  8167. case pci_channel_io_perm_failure:
  8168. /* Permanent failure, prepare for device down */
  8169. lpfc_sli_prep_dev_for_perm_failure(phba);
  8170. return PCI_ERS_RESULT_DISCONNECT;
  8171. default:
  8172. /* Unknown state, prepare and request slot reset */
  8173. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8174. "0472 Unknown PCI error state: x%x\n", state);
  8175. lpfc_sli_prep_dev_for_reset(phba);
  8176. return PCI_ERS_RESULT_NEED_RESET;
  8177. }
  8178. }
  8179. /**
  8180. * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
  8181. * @pdev: pointer to PCI device.
  8182. *
  8183. * This routine is called from the PCI subsystem for error handling to
  8184. * device with SLI-3 interface spec. This is called after PCI bus has been
  8185. * reset to restart the PCI card from scratch, as if from a cold-boot.
  8186. * During the PCI subsystem error recovery, after driver returns
  8187. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  8188. * recovery and then call this routine before calling the .resume method
  8189. * to recover the device. This function will initialize the HBA device,
  8190. * enable the interrupt, but it will just put the HBA to offline state
  8191. * without passing any I/O traffic.
  8192. *
  8193. * Return codes
  8194. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  8195. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  8196. */
  8197. static pci_ers_result_t
  8198. lpfc_io_slot_reset_s3(struct pci_dev *pdev)
  8199. {
  8200. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8201. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8202. struct lpfc_sli *psli = &phba->sli;
  8203. uint32_t intr_mode;
  8204. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  8205. if (pci_enable_device_mem(pdev)) {
  8206. printk(KERN_ERR "lpfc: Cannot re-enable "
  8207. "PCI device after reset.\n");
  8208. return PCI_ERS_RESULT_DISCONNECT;
  8209. }
  8210. pci_restore_state(pdev);
  8211. /*
  8212. * As the new kernel behavior of pci_restore_state() API call clears
  8213. * device saved_state flag, need to save the restored state again.
  8214. */
  8215. pci_save_state(pdev);
  8216. if (pdev->is_busmaster)
  8217. pci_set_master(pdev);
  8218. spin_lock_irq(&phba->hbalock);
  8219. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  8220. spin_unlock_irq(&phba->hbalock);
  8221. /* Configure and enable interrupt */
  8222. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  8223. if (intr_mode == LPFC_INTR_ERROR) {
  8224. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8225. "0427 Cannot re-enable interrupt after "
  8226. "slot reset.\n");
  8227. return PCI_ERS_RESULT_DISCONNECT;
  8228. } else
  8229. phba->intr_mode = intr_mode;
  8230. /* Take device offline, it will perform cleanup */
  8231. lpfc_offline_prep(phba);
  8232. lpfc_offline(phba);
  8233. lpfc_sli_brdrestart(phba);
  8234. /* Log the current active interrupt mode */
  8235. lpfc_log_intr_mode(phba, phba->intr_mode);
  8236. return PCI_ERS_RESULT_RECOVERED;
  8237. }
  8238. /**
  8239. * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
  8240. * @pdev: pointer to PCI device
  8241. *
  8242. * This routine is called from the PCI subsystem for error handling to device
  8243. * with SLI-3 interface spec. It is called when kernel error recovery tells
  8244. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  8245. * error recovery. After this call, traffic can start to flow from this device
  8246. * again.
  8247. */
  8248. static void
  8249. lpfc_io_resume_s3(struct pci_dev *pdev)
  8250. {
  8251. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8252. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8253. /* Bring device online, it will be no-op for non-fatal error resume */
  8254. lpfc_online(phba);
  8255. /* Clean up Advanced Error Reporting (AER) if needed */
  8256. if (phba->hba_flag & HBA_AER_ENABLED)
  8257. pci_cleanup_aer_uncorrect_error_status(pdev);
  8258. }
  8259. /**
  8260. * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
  8261. * @phba: pointer to lpfc hba data structure.
  8262. *
  8263. * returns the number of ELS/CT IOCBs to reserve
  8264. **/
  8265. int
  8266. lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
  8267. {
  8268. int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
  8269. if (phba->sli_rev == LPFC_SLI_REV4) {
  8270. if (max_xri <= 100)
  8271. return 10;
  8272. else if (max_xri <= 256)
  8273. return 25;
  8274. else if (max_xri <= 512)
  8275. return 50;
  8276. else if (max_xri <= 1024)
  8277. return 100;
  8278. else
  8279. return 150;
  8280. } else
  8281. return 0;
  8282. }
  8283. /**
  8284. * lpfc_write_firmware - attempt to write a firmware image to the port
  8285. * @phba: pointer to lpfc hba data structure.
  8286. * @fw: pointer to firmware image returned from request_firmware.
  8287. *
  8288. * returns the number of bytes written if write is successful.
  8289. * returns a negative error value if there were errors.
  8290. * returns 0 if firmware matches currently active firmware on port.
  8291. **/
  8292. int
  8293. lpfc_write_firmware(struct lpfc_hba *phba, const struct firmware *fw)
  8294. {
  8295. char fwrev[FW_REV_STR_SIZE];
  8296. struct lpfc_grp_hdr *image = (struct lpfc_grp_hdr *)fw->data;
  8297. struct list_head dma_buffer_list;
  8298. int i, rc = 0;
  8299. struct lpfc_dmabuf *dmabuf, *next;
  8300. uint32_t offset = 0, temp_offset = 0;
  8301. INIT_LIST_HEAD(&dma_buffer_list);
  8302. if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
  8303. (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
  8304. LPFC_FILE_TYPE_GROUP) ||
  8305. (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
  8306. (be32_to_cpu(image->size) != fw->size)) {
  8307. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8308. "3022 Invalid FW image found. "
  8309. "Magic:%x Type:%x ID:%x\n",
  8310. be32_to_cpu(image->magic_number),
  8311. bf_get_be32(lpfc_grp_hdr_file_type, image),
  8312. bf_get_be32(lpfc_grp_hdr_id, image));
  8313. return -EINVAL;
  8314. }
  8315. lpfc_decode_firmware_rev(phba, fwrev, 1);
  8316. if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
  8317. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8318. "3023 Updating Firmware. Current Version:%s "
  8319. "New Version:%s\n",
  8320. fwrev, image->revision);
  8321. for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
  8322. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
  8323. GFP_KERNEL);
  8324. if (!dmabuf) {
  8325. rc = -ENOMEM;
  8326. goto out;
  8327. }
  8328. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8329. SLI4_PAGE_SIZE,
  8330. &dmabuf->phys,
  8331. GFP_KERNEL);
  8332. if (!dmabuf->virt) {
  8333. kfree(dmabuf);
  8334. rc = -ENOMEM;
  8335. goto out;
  8336. }
  8337. list_add_tail(&dmabuf->list, &dma_buffer_list);
  8338. }
  8339. while (offset < fw->size) {
  8340. temp_offset = offset;
  8341. list_for_each_entry(dmabuf, &dma_buffer_list, list) {
  8342. if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
  8343. memcpy(dmabuf->virt,
  8344. fw->data + temp_offset,
  8345. fw->size - temp_offset);
  8346. temp_offset = fw->size;
  8347. break;
  8348. }
  8349. memcpy(dmabuf->virt, fw->data + temp_offset,
  8350. SLI4_PAGE_SIZE);
  8351. temp_offset += SLI4_PAGE_SIZE;
  8352. }
  8353. rc = lpfc_wr_object(phba, &dma_buffer_list,
  8354. (fw->size - offset), &offset);
  8355. if (rc) {
  8356. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8357. "3024 Firmware update failed. "
  8358. "%d\n", rc);
  8359. goto out;
  8360. }
  8361. }
  8362. rc = offset;
  8363. }
  8364. out:
  8365. list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
  8366. list_del(&dmabuf->list);
  8367. dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
  8368. dmabuf->virt, dmabuf->phys);
  8369. kfree(dmabuf);
  8370. }
  8371. return rc;
  8372. }
  8373. /**
  8374. * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
  8375. * @pdev: pointer to PCI device
  8376. * @pid: pointer to PCI device identifier
  8377. *
  8378. * This routine is called from the kernel's PCI subsystem to device with
  8379. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  8380. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  8381. * information of the device and driver to see if the driver state that it
  8382. * can support this kind of device. If the match is successful, the driver
  8383. * core invokes this routine. If this routine determines it can claim the HBA,
  8384. * it does all the initialization that it needs to do to handle the HBA
  8385. * properly.
  8386. *
  8387. * Return code
  8388. * 0 - driver can claim the device
  8389. * negative value - driver can not claim the device
  8390. **/
  8391. static int __devinit
  8392. lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
  8393. {
  8394. struct lpfc_hba *phba;
  8395. struct lpfc_vport *vport = NULL;
  8396. struct Scsi_Host *shost = NULL;
  8397. int error;
  8398. uint32_t cfg_mode, intr_mode;
  8399. int mcnt;
  8400. int adjusted_fcp_eq_count;
  8401. const struct firmware *fw;
  8402. uint8_t file_name[16];
  8403. /* Allocate memory for HBA structure */
  8404. phba = lpfc_hba_alloc(pdev);
  8405. if (!phba)
  8406. return -ENOMEM;
  8407. /* Perform generic PCI device enabling operation */
  8408. error = lpfc_enable_pci_dev(phba);
  8409. if (error)
  8410. goto out_free_phba;
  8411. /* Set up SLI API function jump table for PCI-device group-1 HBAs */
  8412. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
  8413. if (error)
  8414. goto out_disable_pci_dev;
  8415. /* Set up SLI-4 specific device PCI memory space */
  8416. error = lpfc_sli4_pci_mem_setup(phba);
  8417. if (error) {
  8418. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8419. "1410 Failed to set up pci memory space.\n");
  8420. goto out_disable_pci_dev;
  8421. }
  8422. /* Set up phase-1 common device driver resources */
  8423. error = lpfc_setup_driver_resource_phase1(phba);
  8424. if (error) {
  8425. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8426. "1411 Failed to set up driver resource.\n");
  8427. goto out_unset_pci_mem_s4;
  8428. }
  8429. /* Set up SLI-4 Specific device driver resources */
  8430. error = lpfc_sli4_driver_resource_setup(phba);
  8431. if (error) {
  8432. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8433. "1412 Failed to set up driver resource.\n");
  8434. goto out_unset_pci_mem_s4;
  8435. }
  8436. /* Initialize and populate the iocb list per host */
  8437. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8438. "2821 initialize iocb list %d.\n",
  8439. phba->cfg_iocb_cnt*1024);
  8440. error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
  8441. if (error) {
  8442. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8443. "1413 Failed to initialize iocb list.\n");
  8444. goto out_unset_driver_resource_s4;
  8445. }
  8446. INIT_LIST_HEAD(&phba->active_rrq_list);
  8447. INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
  8448. /* Set up common device driver resources */
  8449. error = lpfc_setup_driver_resource_phase2(phba);
  8450. if (error) {
  8451. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8452. "1414 Failed to set up driver resource.\n");
  8453. goto out_free_iocb_list;
  8454. }
  8455. /* Get the default values for Model Name and Description */
  8456. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  8457. /* Create SCSI host to the physical port */
  8458. error = lpfc_create_shost(phba);
  8459. if (error) {
  8460. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8461. "1415 Failed to create scsi host.\n");
  8462. goto out_unset_driver_resource;
  8463. }
  8464. /* Configure sysfs attributes */
  8465. vport = phba->pport;
  8466. error = lpfc_alloc_sysfs_attr(vport);
  8467. if (error) {
  8468. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8469. "1416 Failed to allocate sysfs attr\n");
  8470. goto out_destroy_shost;
  8471. }
  8472. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  8473. /* Now, trying to enable interrupt and bring up the device */
  8474. cfg_mode = phba->cfg_use_msi;
  8475. while (true) {
  8476. /* Put device to a known state before enabling interrupt */
  8477. lpfc_stop_port(phba);
  8478. /* Configure and enable interrupt */
  8479. intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
  8480. if (intr_mode == LPFC_INTR_ERROR) {
  8481. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8482. "0426 Failed to enable interrupt.\n");
  8483. error = -ENODEV;
  8484. goto out_free_sysfs_attr;
  8485. }
  8486. /* Default to single EQ for non-MSI-X */
  8487. if (phba->intr_type != MSIX)
  8488. adjusted_fcp_eq_count = 0;
  8489. else if (phba->sli4_hba.msix_vec_nr <
  8490. phba->cfg_fcp_eq_count + 1)
  8491. adjusted_fcp_eq_count = phba->sli4_hba.msix_vec_nr - 1;
  8492. else
  8493. adjusted_fcp_eq_count = phba->cfg_fcp_eq_count;
  8494. phba->cfg_fcp_eq_count = adjusted_fcp_eq_count;
  8495. /* Set up SLI-4 HBA */
  8496. if (lpfc_sli4_hba_setup(phba)) {
  8497. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8498. "1421 Failed to set up hba\n");
  8499. error = -ENODEV;
  8500. goto out_disable_intr;
  8501. }
  8502. /* Send NOP mbx cmds for non-INTx mode active interrupt test */
  8503. if (intr_mode != 0)
  8504. mcnt = lpfc_sli4_send_nop_mbox_cmds(phba,
  8505. LPFC_ACT_INTR_CNT);
  8506. /* Check active interrupts received only for MSI/MSI-X */
  8507. if (intr_mode == 0 ||
  8508. phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) {
  8509. /* Log the current active interrupt mode */
  8510. phba->intr_mode = intr_mode;
  8511. lpfc_log_intr_mode(phba, intr_mode);
  8512. break;
  8513. }
  8514. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8515. "0451 Configure interrupt mode (%d) "
  8516. "failed active interrupt test.\n",
  8517. intr_mode);
  8518. /* Unset the previous SLI-4 HBA setup. */
  8519. /*
  8520. * TODO: Is this operation compatible with IF TYPE 2
  8521. * devices? All port state is deleted and cleared.
  8522. */
  8523. lpfc_sli4_unset_hba(phba);
  8524. /* Try next level of interrupt mode */
  8525. cfg_mode = --intr_mode;
  8526. }
  8527. /* Perform post initialization setup */
  8528. lpfc_post_init_setup(phba);
  8529. /* check for firmware upgrade or downgrade (if_type 2 only) */
  8530. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  8531. LPFC_SLI_INTF_IF_TYPE_2) {
  8532. snprintf(file_name, 16, "%s.grp", phba->ModelName);
  8533. error = request_firmware(&fw, file_name, &phba->pcidev->dev);
  8534. if (!error) {
  8535. lpfc_write_firmware(phba, fw);
  8536. release_firmware(fw);
  8537. }
  8538. }
  8539. /* Check if there are static vports to be created. */
  8540. lpfc_create_static_vport(phba);
  8541. return 0;
  8542. out_disable_intr:
  8543. lpfc_sli4_disable_intr(phba);
  8544. out_free_sysfs_attr:
  8545. lpfc_free_sysfs_attr(vport);
  8546. out_destroy_shost:
  8547. lpfc_destroy_shost(phba);
  8548. out_unset_driver_resource:
  8549. lpfc_unset_driver_resource_phase2(phba);
  8550. out_free_iocb_list:
  8551. lpfc_free_iocb_list(phba);
  8552. out_unset_driver_resource_s4:
  8553. lpfc_sli4_driver_resource_unset(phba);
  8554. out_unset_pci_mem_s4:
  8555. lpfc_sli4_pci_mem_unset(phba);
  8556. out_disable_pci_dev:
  8557. lpfc_disable_pci_dev(phba);
  8558. if (shost)
  8559. scsi_host_put(shost);
  8560. out_free_phba:
  8561. lpfc_hba_free(phba);
  8562. return error;
  8563. }
  8564. /**
  8565. * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
  8566. * @pdev: pointer to PCI device
  8567. *
  8568. * This routine is called from the kernel's PCI subsystem to device with
  8569. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  8570. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  8571. * device to be removed from the PCI subsystem properly.
  8572. **/
  8573. static void __devexit
  8574. lpfc_pci_remove_one_s4(struct pci_dev *pdev)
  8575. {
  8576. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8577. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  8578. struct lpfc_vport **vports;
  8579. struct lpfc_hba *phba = vport->phba;
  8580. int i;
  8581. /* Mark the device unloading flag */
  8582. spin_lock_irq(&phba->hbalock);
  8583. vport->load_flag |= FC_UNLOADING;
  8584. spin_unlock_irq(&phba->hbalock);
  8585. /* Free the HBA sysfs attributes */
  8586. lpfc_free_sysfs_attr(vport);
  8587. /* Release all the vports against this physical port */
  8588. vports = lpfc_create_vport_work_array(phba);
  8589. if (vports != NULL)
  8590. for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
  8591. fc_vport_terminate(vports[i]->fc_vport);
  8592. lpfc_destroy_vport_work_array(phba, vports);
  8593. /* Remove FC host and then SCSI host with the physical port */
  8594. fc_remove_host(shost);
  8595. scsi_remove_host(shost);
  8596. /* Perform cleanup on the physical port */
  8597. lpfc_cleanup(vport);
  8598. /*
  8599. * Bring down the SLI Layer. This step disables all interrupts,
  8600. * clears the rings, discards all mailbox commands, and resets
  8601. * the HBA FCoE function.
  8602. */
  8603. lpfc_debugfs_terminate(vport);
  8604. lpfc_sli4_hba_unset(phba);
  8605. spin_lock_irq(&phba->hbalock);
  8606. list_del_init(&vport->listentry);
  8607. spin_unlock_irq(&phba->hbalock);
  8608. /* Perform scsi free before driver resource_unset since scsi
  8609. * buffers are released to their corresponding pools here.
  8610. */
  8611. lpfc_scsi_free(phba);
  8612. lpfc_sli4_driver_resource_unset(phba);
  8613. /* Unmap adapter Control and Doorbell registers */
  8614. lpfc_sli4_pci_mem_unset(phba);
  8615. /* Release PCI resources and disable device's PCI function */
  8616. scsi_host_put(shost);
  8617. lpfc_disable_pci_dev(phba);
  8618. /* Finally, free the driver's device data structure */
  8619. lpfc_hba_free(phba);
  8620. return;
  8621. }
  8622. /**
  8623. * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
  8624. * @pdev: pointer to PCI device
  8625. * @msg: power management message
  8626. *
  8627. * This routine is called from the kernel's PCI subsystem to support system
  8628. * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
  8629. * this method, it quiesces the device by stopping the driver's worker
  8630. * thread for the device, turning off device's interrupt and DMA, and bring
  8631. * the device offline. Note that as the driver implements the minimum PM
  8632. * requirements to a power-aware driver's PM support for suspend/resume -- all
  8633. * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
  8634. * method call will be treated as SUSPEND and the driver will fully
  8635. * reinitialize its device during resume() method call, the driver will set
  8636. * device to PCI_D3hot state in PCI config space instead of setting it
  8637. * according to the @msg provided by the PM.
  8638. *
  8639. * Return code
  8640. * 0 - driver suspended the device
  8641. * Error otherwise
  8642. **/
  8643. static int
  8644. lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
  8645. {
  8646. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8647. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8648. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8649. "2843 PCI device Power Management suspend.\n");
  8650. /* Bring down the device */
  8651. lpfc_offline_prep(phba);
  8652. lpfc_offline(phba);
  8653. kthread_stop(phba->worker_thread);
  8654. /* Disable interrupt from device */
  8655. lpfc_sli4_disable_intr(phba);
  8656. lpfc_sli4_queue_destroy(phba);
  8657. /* Save device state to PCI config space */
  8658. pci_save_state(pdev);
  8659. pci_set_power_state(pdev, PCI_D3hot);
  8660. return 0;
  8661. }
  8662. /**
  8663. * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
  8664. * @pdev: pointer to PCI device
  8665. *
  8666. * This routine is called from the kernel's PCI subsystem to support system
  8667. * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
  8668. * this method, it restores the device's PCI config space state and fully
  8669. * reinitializes the device and brings it online. Note that as the driver
  8670. * implements the minimum PM requirements to a power-aware driver's PM for
  8671. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  8672. * to the suspend() method call will be treated as SUSPEND and the driver
  8673. * will fully reinitialize its device during resume() method call, the device
  8674. * will be set to PCI_D0 directly in PCI config space before restoring the
  8675. * state.
  8676. *
  8677. * Return code
  8678. * 0 - driver suspended the device
  8679. * Error otherwise
  8680. **/
  8681. static int
  8682. lpfc_pci_resume_one_s4(struct pci_dev *pdev)
  8683. {
  8684. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8685. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8686. uint32_t intr_mode;
  8687. int error;
  8688. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8689. "0292 PCI device Power Management resume.\n");
  8690. /* Restore device state from PCI config space */
  8691. pci_set_power_state(pdev, PCI_D0);
  8692. pci_restore_state(pdev);
  8693. /*
  8694. * As the new kernel behavior of pci_restore_state() API call clears
  8695. * device saved_state flag, need to save the restored state again.
  8696. */
  8697. pci_save_state(pdev);
  8698. if (pdev->is_busmaster)
  8699. pci_set_master(pdev);
  8700. /* Startup the kernel thread for this host adapter. */
  8701. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  8702. "lpfc_worker_%d", phba->brd_no);
  8703. if (IS_ERR(phba->worker_thread)) {
  8704. error = PTR_ERR(phba->worker_thread);
  8705. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8706. "0293 PM resume failed to start worker "
  8707. "thread: error=x%x.\n", error);
  8708. return error;
  8709. }
  8710. /* Configure and enable interrupt */
  8711. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  8712. if (intr_mode == LPFC_INTR_ERROR) {
  8713. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8714. "0294 PM resume Failed to enable interrupt\n");
  8715. return -EIO;
  8716. } else
  8717. phba->intr_mode = intr_mode;
  8718. /* Restart HBA and bring it online */
  8719. lpfc_sli_brdrestart(phba);
  8720. lpfc_online(phba);
  8721. /* Log the current active interrupt mode */
  8722. lpfc_log_intr_mode(phba, phba->intr_mode);
  8723. return 0;
  8724. }
  8725. /**
  8726. * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
  8727. * @phba: pointer to lpfc hba data structure.
  8728. *
  8729. * This routine is called to prepare the SLI4 device for PCI slot recover. It
  8730. * aborts all the outstanding SCSI I/Os to the pci device.
  8731. **/
  8732. static void
  8733. lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
  8734. {
  8735. struct lpfc_sli *psli = &phba->sli;
  8736. struct lpfc_sli_ring *pring;
  8737. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8738. "2828 PCI channel I/O abort preparing for recovery\n");
  8739. /*
  8740. * There may be errored I/Os through HBA, abort all I/Os on txcmplq
  8741. * and let the SCSI mid-layer to retry them to recover.
  8742. */
  8743. pring = &psli->ring[psli->fcp_ring];
  8744. lpfc_sli_abort_iocb_ring(phba, pring);
  8745. }
  8746. /**
  8747. * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
  8748. * @phba: pointer to lpfc hba data structure.
  8749. *
  8750. * This routine is called to prepare the SLI4 device for PCI slot reset. It
  8751. * disables the device interrupt and pci device, and aborts the internal FCP
  8752. * pending I/Os.
  8753. **/
  8754. static void
  8755. lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
  8756. {
  8757. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8758. "2826 PCI channel disable preparing for reset\n");
  8759. /* Block any management I/Os to the device */
  8760. lpfc_block_mgmt_io(phba);
  8761. /* Block all SCSI devices' I/Os on the host */
  8762. lpfc_scsi_dev_block(phba);
  8763. /* stop all timers */
  8764. lpfc_stop_hba_timers(phba);
  8765. /* Disable interrupt and pci device */
  8766. lpfc_sli4_disable_intr(phba);
  8767. lpfc_sli4_queue_destroy(phba);
  8768. pci_disable_device(phba->pcidev);
  8769. /* Flush all driver's outstanding SCSI I/Os as we are to reset */
  8770. lpfc_sli_flush_fcp_rings(phba);
  8771. }
  8772. /**
  8773. * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
  8774. * @phba: pointer to lpfc hba data structure.
  8775. *
  8776. * This routine is called to prepare the SLI4 device for PCI slot permanently
  8777. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  8778. * pending I/Os.
  8779. **/
  8780. static void
  8781. lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  8782. {
  8783. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8784. "2827 PCI channel permanent disable for failure\n");
  8785. /* Block all SCSI devices' I/Os on the host */
  8786. lpfc_scsi_dev_block(phba);
  8787. /* stop all timers */
  8788. lpfc_stop_hba_timers(phba);
  8789. /* Clean up all driver's outstanding SCSI I/Os */
  8790. lpfc_sli_flush_fcp_rings(phba);
  8791. }
  8792. /**
  8793. * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
  8794. * @pdev: pointer to PCI device.
  8795. * @state: the current PCI connection state.
  8796. *
  8797. * This routine is called from the PCI subsystem for error handling to device
  8798. * with SLI-4 interface spec. This function is called by the PCI subsystem
  8799. * after a PCI bus error affecting this device has been detected. When this
  8800. * function is invoked, it will need to stop all the I/Os and interrupt(s)
  8801. * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
  8802. * for the PCI subsystem to perform proper recovery as desired.
  8803. *
  8804. * Return codes
  8805. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  8806. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  8807. **/
  8808. static pci_ers_result_t
  8809. lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
  8810. {
  8811. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8812. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8813. switch (state) {
  8814. case pci_channel_io_normal:
  8815. /* Non-fatal error, prepare for recovery */
  8816. lpfc_sli4_prep_dev_for_recover(phba);
  8817. return PCI_ERS_RESULT_CAN_RECOVER;
  8818. case pci_channel_io_frozen:
  8819. /* Fatal error, prepare for slot reset */
  8820. lpfc_sli4_prep_dev_for_reset(phba);
  8821. return PCI_ERS_RESULT_NEED_RESET;
  8822. case pci_channel_io_perm_failure:
  8823. /* Permanent failure, prepare for device down */
  8824. lpfc_sli4_prep_dev_for_perm_failure(phba);
  8825. return PCI_ERS_RESULT_DISCONNECT;
  8826. default:
  8827. /* Unknown state, prepare and request slot reset */
  8828. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8829. "2825 Unknown PCI error state: x%x\n", state);
  8830. lpfc_sli4_prep_dev_for_reset(phba);
  8831. return PCI_ERS_RESULT_NEED_RESET;
  8832. }
  8833. }
  8834. /**
  8835. * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
  8836. * @pdev: pointer to PCI device.
  8837. *
  8838. * This routine is called from the PCI subsystem for error handling to device
  8839. * with SLI-4 interface spec. It is called after PCI bus has been reset to
  8840. * restart the PCI card from scratch, as if from a cold-boot. During the
  8841. * PCI subsystem error recovery, after the driver returns
  8842. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  8843. * recovery and then call this routine before calling the .resume method to
  8844. * recover the device. This function will initialize the HBA device, enable
  8845. * the interrupt, but it will just put the HBA to offline state without
  8846. * passing any I/O traffic.
  8847. *
  8848. * Return codes
  8849. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  8850. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  8851. */
  8852. static pci_ers_result_t
  8853. lpfc_io_slot_reset_s4(struct pci_dev *pdev)
  8854. {
  8855. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8856. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8857. struct lpfc_sli *psli = &phba->sli;
  8858. uint32_t intr_mode;
  8859. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  8860. if (pci_enable_device_mem(pdev)) {
  8861. printk(KERN_ERR "lpfc: Cannot re-enable "
  8862. "PCI device after reset.\n");
  8863. return PCI_ERS_RESULT_DISCONNECT;
  8864. }
  8865. pci_restore_state(pdev);
  8866. /*
  8867. * As the new kernel behavior of pci_restore_state() API call clears
  8868. * device saved_state flag, need to save the restored state again.
  8869. */
  8870. pci_save_state(pdev);
  8871. if (pdev->is_busmaster)
  8872. pci_set_master(pdev);
  8873. spin_lock_irq(&phba->hbalock);
  8874. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  8875. spin_unlock_irq(&phba->hbalock);
  8876. /* Configure and enable interrupt */
  8877. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  8878. if (intr_mode == LPFC_INTR_ERROR) {
  8879. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8880. "2824 Cannot re-enable interrupt after "
  8881. "slot reset.\n");
  8882. return PCI_ERS_RESULT_DISCONNECT;
  8883. } else
  8884. phba->intr_mode = intr_mode;
  8885. /* Log the current active interrupt mode */
  8886. lpfc_log_intr_mode(phba, phba->intr_mode);
  8887. return PCI_ERS_RESULT_RECOVERED;
  8888. }
  8889. /**
  8890. * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
  8891. * @pdev: pointer to PCI device
  8892. *
  8893. * This routine is called from the PCI subsystem for error handling to device
  8894. * with SLI-4 interface spec. It is called when kernel error recovery tells
  8895. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  8896. * error recovery. After this call, traffic can start to flow from this device
  8897. * again.
  8898. **/
  8899. static void
  8900. lpfc_io_resume_s4(struct pci_dev *pdev)
  8901. {
  8902. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8903. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8904. /*
  8905. * In case of slot reset, as function reset is performed through
  8906. * mailbox command which needs DMA to be enabled, this operation
  8907. * has to be moved to the io resume phase. Taking device offline
  8908. * will perform the necessary cleanup.
  8909. */
  8910. if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
  8911. /* Perform device reset */
  8912. lpfc_offline_prep(phba);
  8913. lpfc_offline(phba);
  8914. lpfc_sli_brdrestart(phba);
  8915. /* Bring the device back online */
  8916. lpfc_online(phba);
  8917. }
  8918. /* Clean up Advanced Error Reporting (AER) if needed */
  8919. if (phba->hba_flag & HBA_AER_ENABLED)
  8920. pci_cleanup_aer_uncorrect_error_status(pdev);
  8921. }
  8922. /**
  8923. * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
  8924. * @pdev: pointer to PCI device
  8925. * @pid: pointer to PCI device identifier
  8926. *
  8927. * This routine is to be registered to the kernel's PCI subsystem. When an
  8928. * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
  8929. * at PCI device-specific information of the device and driver to see if the
  8930. * driver state that it can support this kind of device. If the match is
  8931. * successful, the driver core invokes this routine. This routine dispatches
  8932. * the action to the proper SLI-3 or SLI-4 device probing routine, which will
  8933. * do all the initialization that it needs to do to handle the HBA device
  8934. * properly.
  8935. *
  8936. * Return code
  8937. * 0 - driver can claim the device
  8938. * negative value - driver can not claim the device
  8939. **/
  8940. static int __devinit
  8941. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  8942. {
  8943. int rc;
  8944. struct lpfc_sli_intf intf;
  8945. if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
  8946. return -ENODEV;
  8947. if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
  8948. (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
  8949. rc = lpfc_pci_probe_one_s4(pdev, pid);
  8950. else
  8951. rc = lpfc_pci_probe_one_s3(pdev, pid);
  8952. return rc;
  8953. }
  8954. /**
  8955. * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
  8956. * @pdev: pointer to PCI device
  8957. *
  8958. * This routine is to be registered to the kernel's PCI subsystem. When an
  8959. * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
  8960. * This routine dispatches the action to the proper SLI-3 or SLI-4 device
  8961. * remove routine, which will perform all the necessary cleanup for the
  8962. * device to be removed from the PCI subsystem properly.
  8963. **/
  8964. static void __devexit
  8965. lpfc_pci_remove_one(struct pci_dev *pdev)
  8966. {
  8967. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8968. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8969. switch (phba->pci_dev_grp) {
  8970. case LPFC_PCI_DEV_LP:
  8971. lpfc_pci_remove_one_s3(pdev);
  8972. break;
  8973. case LPFC_PCI_DEV_OC:
  8974. lpfc_pci_remove_one_s4(pdev);
  8975. break;
  8976. default:
  8977. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8978. "1424 Invalid PCI device group: 0x%x\n",
  8979. phba->pci_dev_grp);
  8980. break;
  8981. }
  8982. return;
  8983. }
  8984. /**
  8985. * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
  8986. * @pdev: pointer to PCI device
  8987. * @msg: power management message
  8988. *
  8989. * This routine is to be registered to the kernel's PCI subsystem to support
  8990. * system Power Management (PM). When PM invokes this method, it dispatches
  8991. * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
  8992. * suspend the device.
  8993. *
  8994. * Return code
  8995. * 0 - driver suspended the device
  8996. * Error otherwise
  8997. **/
  8998. static int
  8999. lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
  9000. {
  9001. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9002. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9003. int rc = -ENODEV;
  9004. switch (phba->pci_dev_grp) {
  9005. case LPFC_PCI_DEV_LP:
  9006. rc = lpfc_pci_suspend_one_s3(pdev, msg);
  9007. break;
  9008. case LPFC_PCI_DEV_OC:
  9009. rc = lpfc_pci_suspend_one_s4(pdev, msg);
  9010. break;
  9011. default:
  9012. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9013. "1425 Invalid PCI device group: 0x%x\n",
  9014. phba->pci_dev_grp);
  9015. break;
  9016. }
  9017. return rc;
  9018. }
  9019. /**
  9020. * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
  9021. * @pdev: pointer to PCI device
  9022. *
  9023. * This routine is to be registered to the kernel's PCI subsystem to support
  9024. * system Power Management (PM). When PM invokes this method, it dispatches
  9025. * the action to the proper SLI-3 or SLI-4 device resume routine, which will
  9026. * resume the device.
  9027. *
  9028. * Return code
  9029. * 0 - driver suspended the device
  9030. * Error otherwise
  9031. **/
  9032. static int
  9033. lpfc_pci_resume_one(struct pci_dev *pdev)
  9034. {
  9035. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9036. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9037. int rc = -ENODEV;
  9038. switch (phba->pci_dev_grp) {
  9039. case LPFC_PCI_DEV_LP:
  9040. rc = lpfc_pci_resume_one_s3(pdev);
  9041. break;
  9042. case LPFC_PCI_DEV_OC:
  9043. rc = lpfc_pci_resume_one_s4(pdev);
  9044. break;
  9045. default:
  9046. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9047. "1426 Invalid PCI device group: 0x%x\n",
  9048. phba->pci_dev_grp);
  9049. break;
  9050. }
  9051. return rc;
  9052. }
  9053. /**
  9054. * lpfc_io_error_detected - lpfc method for handling PCI I/O error
  9055. * @pdev: pointer to PCI device.
  9056. * @state: the current PCI connection state.
  9057. *
  9058. * This routine is registered to the PCI subsystem for error handling. This
  9059. * function is called by the PCI subsystem after a PCI bus error affecting
  9060. * this device has been detected. When this routine is invoked, it dispatches
  9061. * the action to the proper SLI-3 or SLI-4 device error detected handling
  9062. * routine, which will perform the proper error detected operation.
  9063. *
  9064. * Return codes
  9065. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  9066. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9067. **/
  9068. static pci_ers_result_t
  9069. lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  9070. {
  9071. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9072. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9073. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  9074. switch (phba->pci_dev_grp) {
  9075. case LPFC_PCI_DEV_LP:
  9076. rc = lpfc_io_error_detected_s3(pdev, state);
  9077. break;
  9078. case LPFC_PCI_DEV_OC:
  9079. rc = lpfc_io_error_detected_s4(pdev, state);
  9080. break;
  9081. default:
  9082. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9083. "1427 Invalid PCI device group: 0x%x\n",
  9084. phba->pci_dev_grp);
  9085. break;
  9086. }
  9087. return rc;
  9088. }
  9089. /**
  9090. * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
  9091. * @pdev: pointer to PCI device.
  9092. *
  9093. * This routine is registered to the PCI subsystem for error handling. This
  9094. * function is called after PCI bus has been reset to restart the PCI card
  9095. * from scratch, as if from a cold-boot. When this routine is invoked, it
  9096. * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
  9097. * routine, which will perform the proper device reset.
  9098. *
  9099. * Return codes
  9100. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  9101. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9102. **/
  9103. static pci_ers_result_t
  9104. lpfc_io_slot_reset(struct pci_dev *pdev)
  9105. {
  9106. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9107. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9108. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  9109. switch (phba->pci_dev_grp) {
  9110. case LPFC_PCI_DEV_LP:
  9111. rc = lpfc_io_slot_reset_s3(pdev);
  9112. break;
  9113. case LPFC_PCI_DEV_OC:
  9114. rc = lpfc_io_slot_reset_s4(pdev);
  9115. break;
  9116. default:
  9117. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9118. "1428 Invalid PCI device group: 0x%x\n",
  9119. phba->pci_dev_grp);
  9120. break;
  9121. }
  9122. return rc;
  9123. }
  9124. /**
  9125. * lpfc_io_resume - lpfc method for resuming PCI I/O operation
  9126. * @pdev: pointer to PCI device
  9127. *
  9128. * This routine is registered to the PCI subsystem for error handling. It
  9129. * is called when kernel error recovery tells the lpfc driver that it is
  9130. * OK to resume normal PCI operation after PCI bus error recovery. When
  9131. * this routine is invoked, it dispatches the action to the proper SLI-3
  9132. * or SLI-4 device io_resume routine, which will resume the device operation.
  9133. **/
  9134. static void
  9135. lpfc_io_resume(struct pci_dev *pdev)
  9136. {
  9137. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9138. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9139. switch (phba->pci_dev_grp) {
  9140. case LPFC_PCI_DEV_LP:
  9141. lpfc_io_resume_s3(pdev);
  9142. break;
  9143. case LPFC_PCI_DEV_OC:
  9144. lpfc_io_resume_s4(pdev);
  9145. break;
  9146. default:
  9147. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9148. "1429 Invalid PCI device group: 0x%x\n",
  9149. phba->pci_dev_grp);
  9150. break;
  9151. }
  9152. return;
  9153. }
  9154. /**
  9155. * lpfc_mgmt_open - method called when 'lpfcmgmt' is opened from userspace
  9156. * @inode: pointer to the inode representing the lpfcmgmt device
  9157. * @filep: pointer to the file representing the open lpfcmgmt device
  9158. *
  9159. * This routine puts a reference count on the lpfc module whenever the
  9160. * character device is opened
  9161. **/
  9162. static int
  9163. lpfc_mgmt_open(struct inode *inode, struct file *filep)
  9164. {
  9165. try_module_get(THIS_MODULE);
  9166. return 0;
  9167. }
  9168. /**
  9169. * lpfc_mgmt_release - method called when 'lpfcmgmt' is closed in userspace
  9170. * @inode: pointer to the inode representing the lpfcmgmt device
  9171. * @filep: pointer to the file representing the open lpfcmgmt device
  9172. *
  9173. * This routine removes a reference count from the lpfc module when the
  9174. * character device is closed
  9175. **/
  9176. static int
  9177. lpfc_mgmt_release(struct inode *inode, struct file *filep)
  9178. {
  9179. module_put(THIS_MODULE);
  9180. return 0;
  9181. }
  9182. static struct pci_device_id lpfc_id_table[] = {
  9183. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  9184. PCI_ANY_ID, PCI_ANY_ID, },
  9185. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  9186. PCI_ANY_ID, PCI_ANY_ID, },
  9187. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  9188. PCI_ANY_ID, PCI_ANY_ID, },
  9189. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  9190. PCI_ANY_ID, PCI_ANY_ID, },
  9191. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  9192. PCI_ANY_ID, PCI_ANY_ID, },
  9193. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  9194. PCI_ANY_ID, PCI_ANY_ID, },
  9195. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  9196. PCI_ANY_ID, PCI_ANY_ID, },
  9197. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  9198. PCI_ANY_ID, PCI_ANY_ID, },
  9199. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  9200. PCI_ANY_ID, PCI_ANY_ID, },
  9201. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  9202. PCI_ANY_ID, PCI_ANY_ID, },
  9203. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  9204. PCI_ANY_ID, PCI_ANY_ID, },
  9205. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  9206. PCI_ANY_ID, PCI_ANY_ID, },
  9207. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  9208. PCI_ANY_ID, PCI_ANY_ID, },
  9209. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  9210. PCI_ANY_ID, PCI_ANY_ID, },
  9211. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  9212. PCI_ANY_ID, PCI_ANY_ID, },
  9213. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  9214. PCI_ANY_ID, PCI_ANY_ID, },
  9215. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  9216. PCI_ANY_ID, PCI_ANY_ID, },
  9217. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  9218. PCI_ANY_ID, PCI_ANY_ID, },
  9219. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
  9220. PCI_ANY_ID, PCI_ANY_ID, },
  9221. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  9222. PCI_ANY_ID, PCI_ANY_ID, },
  9223. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  9224. PCI_ANY_ID, PCI_ANY_ID, },
  9225. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  9226. PCI_ANY_ID, PCI_ANY_ID, },
  9227. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  9228. PCI_ANY_ID, PCI_ANY_ID, },
  9229. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  9230. PCI_ANY_ID, PCI_ANY_ID, },
  9231. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  9232. PCI_ANY_ID, PCI_ANY_ID, },
  9233. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  9234. PCI_ANY_ID, PCI_ANY_ID, },
  9235. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  9236. PCI_ANY_ID, PCI_ANY_ID, },
  9237. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  9238. PCI_ANY_ID, PCI_ANY_ID, },
  9239. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
  9240. PCI_ANY_ID, PCI_ANY_ID, },
  9241. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
  9242. PCI_ANY_ID, PCI_ANY_ID, },
  9243. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
  9244. PCI_ANY_ID, PCI_ANY_ID, },
  9245. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
  9246. PCI_ANY_ID, PCI_ANY_ID, },
  9247. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
  9248. PCI_ANY_ID, PCI_ANY_ID, },
  9249. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
  9250. PCI_ANY_ID, PCI_ANY_ID, },
  9251. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
  9252. PCI_ANY_ID, PCI_ANY_ID, },
  9253. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
  9254. PCI_ANY_ID, PCI_ANY_ID, },
  9255. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
  9256. PCI_ANY_ID, PCI_ANY_ID, },
  9257. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
  9258. PCI_ANY_ID, PCI_ANY_ID, },
  9259. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
  9260. PCI_ANY_ID, PCI_ANY_ID, },
  9261. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
  9262. PCI_ANY_ID, PCI_ANY_ID, },
  9263. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
  9264. PCI_ANY_ID, PCI_ANY_ID, },
  9265. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
  9266. PCI_ANY_ID, PCI_ANY_ID, },
  9267. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
  9268. PCI_ANY_ID, PCI_ANY_ID, },
  9269. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
  9270. PCI_ANY_ID, PCI_ANY_ID, },
  9271. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
  9272. PCI_ANY_ID, PCI_ANY_ID, },
  9273. { 0 }
  9274. };
  9275. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  9276. static struct pci_error_handlers lpfc_err_handler = {
  9277. .error_detected = lpfc_io_error_detected,
  9278. .slot_reset = lpfc_io_slot_reset,
  9279. .resume = lpfc_io_resume,
  9280. };
  9281. static struct pci_driver lpfc_driver = {
  9282. .name = LPFC_DRIVER_NAME,
  9283. .id_table = lpfc_id_table,
  9284. .probe = lpfc_pci_probe_one,
  9285. .remove = __devexit_p(lpfc_pci_remove_one),
  9286. .suspend = lpfc_pci_suspend_one,
  9287. .resume = lpfc_pci_resume_one,
  9288. .err_handler = &lpfc_err_handler,
  9289. };
  9290. static const struct file_operations lpfc_mgmt_fop = {
  9291. .open = lpfc_mgmt_open,
  9292. .release = lpfc_mgmt_release,
  9293. };
  9294. static struct miscdevice lpfc_mgmt_dev = {
  9295. .minor = MISC_DYNAMIC_MINOR,
  9296. .name = "lpfcmgmt",
  9297. .fops = &lpfc_mgmt_fop,
  9298. };
  9299. /**
  9300. * lpfc_init - lpfc module initialization routine
  9301. *
  9302. * This routine is to be invoked when the lpfc module is loaded into the
  9303. * kernel. The special kernel macro module_init() is used to indicate the
  9304. * role of this routine to the kernel as lpfc module entry point.
  9305. *
  9306. * Return codes
  9307. * 0 - successful
  9308. * -ENOMEM - FC attach transport failed
  9309. * all others - failed
  9310. */
  9311. static int __init
  9312. lpfc_init(void)
  9313. {
  9314. int error = 0;
  9315. printk(LPFC_MODULE_DESC "\n");
  9316. printk(LPFC_COPYRIGHT "\n");
  9317. error = misc_register(&lpfc_mgmt_dev);
  9318. if (error)
  9319. printk(KERN_ERR "Could not register lpfcmgmt device, "
  9320. "misc_register returned with status %d", error);
  9321. if (lpfc_enable_npiv) {
  9322. lpfc_transport_functions.vport_create = lpfc_vport_create;
  9323. lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  9324. }
  9325. lpfc_transport_template =
  9326. fc_attach_transport(&lpfc_transport_functions);
  9327. if (lpfc_transport_template == NULL)
  9328. return -ENOMEM;
  9329. if (lpfc_enable_npiv) {
  9330. lpfc_vport_transport_template =
  9331. fc_attach_transport(&lpfc_vport_transport_functions);
  9332. if (lpfc_vport_transport_template == NULL) {
  9333. fc_release_transport(lpfc_transport_template);
  9334. return -ENOMEM;
  9335. }
  9336. }
  9337. error = pci_register_driver(&lpfc_driver);
  9338. if (error) {
  9339. fc_release_transport(lpfc_transport_template);
  9340. if (lpfc_enable_npiv)
  9341. fc_release_transport(lpfc_vport_transport_template);
  9342. }
  9343. return error;
  9344. }
  9345. /**
  9346. * lpfc_exit - lpfc module removal routine
  9347. *
  9348. * This routine is invoked when the lpfc module is removed from the kernel.
  9349. * The special kernel macro module_exit() is used to indicate the role of
  9350. * this routine to the kernel as lpfc module exit point.
  9351. */
  9352. static void __exit
  9353. lpfc_exit(void)
  9354. {
  9355. misc_deregister(&lpfc_mgmt_dev);
  9356. pci_unregister_driver(&lpfc_driver);
  9357. fc_release_transport(lpfc_transport_template);
  9358. if (lpfc_enable_npiv)
  9359. fc_release_transport(lpfc_vport_transport_template);
  9360. if (_dump_buf_data) {
  9361. printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
  9362. "_dump_buf_data at 0x%p\n",
  9363. (1L << _dump_buf_data_order), _dump_buf_data);
  9364. free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
  9365. }
  9366. if (_dump_buf_dif) {
  9367. printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
  9368. "_dump_buf_dif at 0x%p\n",
  9369. (1L << _dump_buf_dif_order), _dump_buf_dif);
  9370. free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
  9371. }
  9372. }
  9373. module_init(lpfc_init);
  9374. module_exit(lpfc_exit);
  9375. MODULE_LICENSE("GPL");
  9376. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  9377. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  9378. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);