lpfc_init.c 242 KB

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