lpfc_init.c 285 KB

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