lpfc_init.c 314 KB

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