lpfc_init.c 288 KB

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