lpfc_init.c 262 KB

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