lpfc_init.c 285 KB

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