lpfc_init.c 314 KB

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