lpfc_init.c 235 KB

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