i40e_main.c 259 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2014 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. /* Local includes */
  27. #include "i40e.h"
  28. #include "i40e_diag.h"
  29. #ifdef CONFIG_I40E_VXLAN
  30. #include <net/vxlan.h>
  31. #endif
  32. const char i40e_driver_name[] = "i40e";
  33. static const char i40e_driver_string[] =
  34. "Intel(R) Ethernet Connection XL710 Network Driver";
  35. #define DRV_KERN "-k"
  36. #define DRV_VERSION_MAJOR 1
  37. #define DRV_VERSION_MINOR 0
  38. #define DRV_VERSION_BUILD 11
  39. #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
  40. __stringify(DRV_VERSION_MINOR) "." \
  41. __stringify(DRV_VERSION_BUILD) DRV_KERN
  42. const char i40e_driver_version_str[] = DRV_VERSION;
  43. static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
  44. /* a bit of forward declarations */
  45. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
  46. static void i40e_handle_reset_warning(struct i40e_pf *pf);
  47. static int i40e_add_vsi(struct i40e_vsi *vsi);
  48. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
  49. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
  50. static int i40e_setup_misc_vector(struct i40e_pf *pf);
  51. static void i40e_determine_queue_usage(struct i40e_pf *pf);
  52. static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
  53. static void i40e_fdir_sb_setup(struct i40e_pf *pf);
  54. static int i40e_veb_get_bw_info(struct i40e_veb *veb);
  55. /* i40e_pci_tbl - PCI Device ID Table
  56. *
  57. * Last entry must be all 0s
  58. *
  59. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  60. * Class, Class Mask, private data (not used) }
  61. */
  62. static const struct pci_device_id i40e_pci_tbl[] = {
  63. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
  64. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
  65. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_A), 0},
  66. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
  67. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
  68. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
  69. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
  70. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
  71. /* required last entry */
  72. {0, }
  73. };
  74. MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
  75. #define I40E_MAX_VF_COUNT 128
  76. static int debug = -1;
  77. module_param(debug, int, 0);
  78. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  79. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  80. MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
  81. MODULE_LICENSE("GPL");
  82. MODULE_VERSION(DRV_VERSION);
  83. /**
  84. * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
  85. * @hw: pointer to the HW structure
  86. * @mem: ptr to mem struct to fill out
  87. * @size: size of memory requested
  88. * @alignment: what to align the allocation to
  89. **/
  90. int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
  91. u64 size, u32 alignment)
  92. {
  93. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  94. mem->size = ALIGN(size, alignment);
  95. mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
  96. &mem->pa, GFP_KERNEL);
  97. if (!mem->va)
  98. return -ENOMEM;
  99. return 0;
  100. }
  101. /**
  102. * i40e_free_dma_mem_d - OS specific memory free for shared code
  103. * @hw: pointer to the HW structure
  104. * @mem: ptr to mem struct to free
  105. **/
  106. int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
  107. {
  108. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  109. dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
  110. mem->va = NULL;
  111. mem->pa = 0;
  112. mem->size = 0;
  113. return 0;
  114. }
  115. /**
  116. * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
  117. * @hw: pointer to the HW structure
  118. * @mem: ptr to mem struct to fill out
  119. * @size: size of memory requested
  120. **/
  121. int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
  122. u32 size)
  123. {
  124. mem->size = size;
  125. mem->va = kzalloc(size, GFP_KERNEL);
  126. if (!mem->va)
  127. return -ENOMEM;
  128. return 0;
  129. }
  130. /**
  131. * i40e_free_virt_mem_d - OS specific memory free for shared code
  132. * @hw: pointer to the HW structure
  133. * @mem: ptr to mem struct to free
  134. **/
  135. int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
  136. {
  137. /* it's ok to kfree a NULL pointer */
  138. kfree(mem->va);
  139. mem->va = NULL;
  140. mem->size = 0;
  141. return 0;
  142. }
  143. /**
  144. * i40e_get_lump - find a lump of free generic resource
  145. * @pf: board private structure
  146. * @pile: the pile of resource to search
  147. * @needed: the number of items needed
  148. * @id: an owner id to stick on the items assigned
  149. *
  150. * Returns the base item index of the lump, or negative for error
  151. *
  152. * The search_hint trick and lack of advanced fit-finding only work
  153. * because we're highly likely to have all the same size lump requests.
  154. * Linear search time and any fragmentation should be minimal.
  155. **/
  156. static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
  157. u16 needed, u16 id)
  158. {
  159. int ret = -ENOMEM;
  160. int i, j;
  161. if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
  162. dev_info(&pf->pdev->dev,
  163. "param err: pile=%p needed=%d id=0x%04x\n",
  164. pile, needed, id);
  165. return -EINVAL;
  166. }
  167. /* start the linear search with an imperfect hint */
  168. i = pile->search_hint;
  169. while (i < pile->num_entries) {
  170. /* skip already allocated entries */
  171. if (pile->list[i] & I40E_PILE_VALID_BIT) {
  172. i++;
  173. continue;
  174. }
  175. /* do we have enough in this lump? */
  176. for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
  177. if (pile->list[i+j] & I40E_PILE_VALID_BIT)
  178. break;
  179. }
  180. if (j == needed) {
  181. /* there was enough, so assign it to the requestor */
  182. for (j = 0; j < needed; j++)
  183. pile->list[i+j] = id | I40E_PILE_VALID_BIT;
  184. ret = i;
  185. pile->search_hint = i + j;
  186. break;
  187. } else {
  188. /* not enough, so skip over it and continue looking */
  189. i += j;
  190. }
  191. }
  192. return ret;
  193. }
  194. /**
  195. * i40e_put_lump - return a lump of generic resource
  196. * @pile: the pile of resource to search
  197. * @index: the base item index
  198. * @id: the owner id of the items assigned
  199. *
  200. * Returns the count of items in the lump
  201. **/
  202. static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
  203. {
  204. int valid_id = (id | I40E_PILE_VALID_BIT);
  205. int count = 0;
  206. int i;
  207. if (!pile || index >= pile->num_entries)
  208. return -EINVAL;
  209. for (i = index;
  210. i < pile->num_entries && pile->list[i] == valid_id;
  211. i++) {
  212. pile->list[i] = 0;
  213. count++;
  214. }
  215. if (count && index < pile->search_hint)
  216. pile->search_hint = index;
  217. return count;
  218. }
  219. /**
  220. * i40e_service_event_schedule - Schedule the service task to wake up
  221. * @pf: board private structure
  222. *
  223. * If not already scheduled, this puts the task into the work queue
  224. **/
  225. static void i40e_service_event_schedule(struct i40e_pf *pf)
  226. {
  227. if (!test_bit(__I40E_DOWN, &pf->state) &&
  228. !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) &&
  229. !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state))
  230. schedule_work(&pf->service_task);
  231. }
  232. /**
  233. * i40e_tx_timeout - Respond to a Tx Hang
  234. * @netdev: network interface device structure
  235. *
  236. * If any port has noticed a Tx timeout, it is likely that the whole
  237. * device is munged, not just the one netdev port, so go for the full
  238. * reset.
  239. **/
  240. #ifdef I40E_FCOE
  241. void i40e_tx_timeout(struct net_device *netdev)
  242. #else
  243. static void i40e_tx_timeout(struct net_device *netdev)
  244. #endif
  245. {
  246. struct i40e_netdev_priv *np = netdev_priv(netdev);
  247. struct i40e_vsi *vsi = np->vsi;
  248. struct i40e_pf *pf = vsi->back;
  249. pf->tx_timeout_count++;
  250. if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
  251. pf->tx_timeout_recovery_level = 1;
  252. pf->tx_timeout_last_recovery = jiffies;
  253. netdev_info(netdev, "tx_timeout recovery level %d\n",
  254. pf->tx_timeout_recovery_level);
  255. switch (pf->tx_timeout_recovery_level) {
  256. case 0:
  257. /* disable and re-enable queues for the VSI */
  258. if (in_interrupt()) {
  259. set_bit(__I40E_REINIT_REQUESTED, &pf->state);
  260. set_bit(__I40E_REINIT_REQUESTED, &vsi->state);
  261. } else {
  262. i40e_vsi_reinit_locked(vsi);
  263. }
  264. break;
  265. case 1:
  266. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  267. break;
  268. case 2:
  269. set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  270. break;
  271. case 3:
  272. set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  273. break;
  274. default:
  275. netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
  276. set_bit(__I40E_DOWN_REQUESTED, &pf->state);
  277. set_bit(__I40E_DOWN_REQUESTED, &vsi->state);
  278. break;
  279. }
  280. i40e_service_event_schedule(pf);
  281. pf->tx_timeout_recovery_level++;
  282. }
  283. /**
  284. * i40e_release_rx_desc - Store the new tail and head values
  285. * @rx_ring: ring to bump
  286. * @val: new head index
  287. **/
  288. static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val)
  289. {
  290. rx_ring->next_to_use = val;
  291. /* Force memory writes to complete before letting h/w
  292. * know there are new descriptors to fetch. (Only
  293. * applicable for weak-ordered memory model archs,
  294. * such as IA-64).
  295. */
  296. wmb();
  297. writel(val, rx_ring->tail);
  298. }
  299. /**
  300. * i40e_get_vsi_stats_struct - Get System Network Statistics
  301. * @vsi: the VSI we care about
  302. *
  303. * Returns the address of the device statistics structure.
  304. * The statistics are actually updated from the service task.
  305. **/
  306. struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
  307. {
  308. return &vsi->net_stats;
  309. }
  310. /**
  311. * i40e_get_netdev_stats_struct - Get statistics for netdev interface
  312. * @netdev: network interface device structure
  313. *
  314. * Returns the address of the device statistics structure.
  315. * The statistics are actually updated from the service task.
  316. **/
  317. #ifdef I40E_FCOE
  318. struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
  319. struct net_device *netdev,
  320. struct rtnl_link_stats64 *stats)
  321. #else
  322. static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
  323. struct net_device *netdev,
  324. struct rtnl_link_stats64 *stats)
  325. #endif
  326. {
  327. struct i40e_netdev_priv *np = netdev_priv(netdev);
  328. struct i40e_ring *tx_ring, *rx_ring;
  329. struct i40e_vsi *vsi = np->vsi;
  330. struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
  331. int i;
  332. if (test_bit(__I40E_DOWN, &vsi->state))
  333. return stats;
  334. if (!vsi->tx_rings)
  335. return stats;
  336. rcu_read_lock();
  337. for (i = 0; i < vsi->num_queue_pairs; i++) {
  338. u64 bytes, packets;
  339. unsigned int start;
  340. tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
  341. if (!tx_ring)
  342. continue;
  343. do {
  344. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  345. packets = tx_ring->stats.packets;
  346. bytes = tx_ring->stats.bytes;
  347. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  348. stats->tx_packets += packets;
  349. stats->tx_bytes += bytes;
  350. rx_ring = &tx_ring[1];
  351. do {
  352. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  353. packets = rx_ring->stats.packets;
  354. bytes = rx_ring->stats.bytes;
  355. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  356. stats->rx_packets += packets;
  357. stats->rx_bytes += bytes;
  358. }
  359. rcu_read_unlock();
  360. /* following stats updated by i40e_watchdog_subtask() */
  361. stats->multicast = vsi_stats->multicast;
  362. stats->tx_errors = vsi_stats->tx_errors;
  363. stats->tx_dropped = vsi_stats->tx_dropped;
  364. stats->rx_errors = vsi_stats->rx_errors;
  365. stats->rx_crc_errors = vsi_stats->rx_crc_errors;
  366. stats->rx_length_errors = vsi_stats->rx_length_errors;
  367. return stats;
  368. }
  369. /**
  370. * i40e_vsi_reset_stats - Resets all stats of the given vsi
  371. * @vsi: the VSI to have its stats reset
  372. **/
  373. void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
  374. {
  375. struct rtnl_link_stats64 *ns;
  376. int i;
  377. if (!vsi)
  378. return;
  379. ns = i40e_get_vsi_stats_struct(vsi);
  380. memset(ns, 0, sizeof(*ns));
  381. memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
  382. memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
  383. memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
  384. if (vsi->rx_rings && vsi->rx_rings[0]) {
  385. for (i = 0; i < vsi->num_queue_pairs; i++) {
  386. memset(&vsi->rx_rings[i]->stats, 0 ,
  387. sizeof(vsi->rx_rings[i]->stats));
  388. memset(&vsi->rx_rings[i]->rx_stats, 0 ,
  389. sizeof(vsi->rx_rings[i]->rx_stats));
  390. memset(&vsi->tx_rings[i]->stats, 0 ,
  391. sizeof(vsi->tx_rings[i]->stats));
  392. memset(&vsi->tx_rings[i]->tx_stats, 0,
  393. sizeof(vsi->tx_rings[i]->tx_stats));
  394. }
  395. }
  396. vsi->stat_offsets_loaded = false;
  397. }
  398. /**
  399. * i40e_pf_reset_stats - Reset all of the stats for the given pf
  400. * @pf: the PF to be reset
  401. **/
  402. void i40e_pf_reset_stats(struct i40e_pf *pf)
  403. {
  404. int i;
  405. memset(&pf->stats, 0, sizeof(pf->stats));
  406. memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
  407. pf->stat_offsets_loaded = false;
  408. for (i = 0; i < I40E_MAX_VEB; i++) {
  409. if (pf->veb[i]) {
  410. memset(&pf->veb[i]->stats, 0,
  411. sizeof(pf->veb[i]->stats));
  412. memset(&pf->veb[i]->stats_offsets, 0,
  413. sizeof(pf->veb[i]->stats_offsets));
  414. pf->veb[i]->stat_offsets_loaded = false;
  415. }
  416. }
  417. }
  418. /**
  419. * i40e_stat_update48 - read and update a 48 bit stat from the chip
  420. * @hw: ptr to the hardware info
  421. * @hireg: the high 32 bit reg to read
  422. * @loreg: the low 32 bit reg to read
  423. * @offset_loaded: has the initial offset been loaded yet
  424. * @offset: ptr to current offset value
  425. * @stat: ptr to the stat
  426. *
  427. * Since the device stats are not reset at PFReset, they likely will not
  428. * be zeroed when the driver starts. We'll save the first values read
  429. * and use them as offsets to be subtracted from the raw values in order
  430. * to report stats that count from zero. In the process, we also manage
  431. * the potential roll-over.
  432. **/
  433. static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
  434. bool offset_loaded, u64 *offset, u64 *stat)
  435. {
  436. u64 new_data;
  437. if (hw->device_id == I40E_DEV_ID_QEMU) {
  438. new_data = rd32(hw, loreg);
  439. new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
  440. } else {
  441. new_data = rd64(hw, loreg);
  442. }
  443. if (!offset_loaded)
  444. *offset = new_data;
  445. if (likely(new_data >= *offset))
  446. *stat = new_data - *offset;
  447. else
  448. *stat = (new_data + ((u64)1 << 48)) - *offset;
  449. *stat &= 0xFFFFFFFFFFFFULL;
  450. }
  451. /**
  452. * i40e_stat_update32 - read and update a 32 bit stat from the chip
  453. * @hw: ptr to the hardware info
  454. * @reg: the hw reg to read
  455. * @offset_loaded: has the initial offset been loaded yet
  456. * @offset: ptr to current offset value
  457. * @stat: ptr to the stat
  458. **/
  459. static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
  460. bool offset_loaded, u64 *offset, u64 *stat)
  461. {
  462. u32 new_data;
  463. new_data = rd32(hw, reg);
  464. if (!offset_loaded)
  465. *offset = new_data;
  466. if (likely(new_data >= *offset))
  467. *stat = (u32)(new_data - *offset);
  468. else
  469. *stat = (u32)((new_data + ((u64)1 << 32)) - *offset);
  470. }
  471. /**
  472. * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
  473. * @vsi: the VSI to be updated
  474. **/
  475. void i40e_update_eth_stats(struct i40e_vsi *vsi)
  476. {
  477. int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
  478. struct i40e_pf *pf = vsi->back;
  479. struct i40e_hw *hw = &pf->hw;
  480. struct i40e_eth_stats *oes;
  481. struct i40e_eth_stats *es; /* device's eth stats */
  482. es = &vsi->eth_stats;
  483. oes = &vsi->eth_stats_offsets;
  484. /* Gather up the stats that the hw collects */
  485. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  486. vsi->stat_offsets_loaded,
  487. &oes->tx_errors, &es->tx_errors);
  488. i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
  489. vsi->stat_offsets_loaded,
  490. &oes->rx_discards, &es->rx_discards);
  491. i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
  492. vsi->stat_offsets_loaded,
  493. &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
  494. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  495. vsi->stat_offsets_loaded,
  496. &oes->tx_errors, &es->tx_errors);
  497. i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
  498. I40E_GLV_GORCL(stat_idx),
  499. vsi->stat_offsets_loaded,
  500. &oes->rx_bytes, &es->rx_bytes);
  501. i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
  502. I40E_GLV_UPRCL(stat_idx),
  503. vsi->stat_offsets_loaded,
  504. &oes->rx_unicast, &es->rx_unicast);
  505. i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
  506. I40E_GLV_MPRCL(stat_idx),
  507. vsi->stat_offsets_loaded,
  508. &oes->rx_multicast, &es->rx_multicast);
  509. i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
  510. I40E_GLV_BPRCL(stat_idx),
  511. vsi->stat_offsets_loaded,
  512. &oes->rx_broadcast, &es->rx_broadcast);
  513. i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
  514. I40E_GLV_GOTCL(stat_idx),
  515. vsi->stat_offsets_loaded,
  516. &oes->tx_bytes, &es->tx_bytes);
  517. i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
  518. I40E_GLV_UPTCL(stat_idx),
  519. vsi->stat_offsets_loaded,
  520. &oes->tx_unicast, &es->tx_unicast);
  521. i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
  522. I40E_GLV_MPTCL(stat_idx),
  523. vsi->stat_offsets_loaded,
  524. &oes->tx_multicast, &es->tx_multicast);
  525. i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
  526. I40E_GLV_BPTCL(stat_idx),
  527. vsi->stat_offsets_loaded,
  528. &oes->tx_broadcast, &es->tx_broadcast);
  529. vsi->stat_offsets_loaded = true;
  530. }
  531. /**
  532. * i40e_update_veb_stats - Update Switch component statistics
  533. * @veb: the VEB being updated
  534. **/
  535. static void i40e_update_veb_stats(struct i40e_veb *veb)
  536. {
  537. struct i40e_pf *pf = veb->pf;
  538. struct i40e_hw *hw = &pf->hw;
  539. struct i40e_eth_stats *oes;
  540. struct i40e_eth_stats *es; /* device's eth stats */
  541. int idx = 0;
  542. idx = veb->stats_idx;
  543. es = &veb->stats;
  544. oes = &veb->stats_offsets;
  545. /* Gather up the stats that the hw collects */
  546. i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
  547. veb->stat_offsets_loaded,
  548. &oes->tx_discards, &es->tx_discards);
  549. if (hw->revision_id > 0)
  550. i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
  551. veb->stat_offsets_loaded,
  552. &oes->rx_unknown_protocol,
  553. &es->rx_unknown_protocol);
  554. i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
  555. veb->stat_offsets_loaded,
  556. &oes->rx_bytes, &es->rx_bytes);
  557. i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
  558. veb->stat_offsets_loaded,
  559. &oes->rx_unicast, &es->rx_unicast);
  560. i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
  561. veb->stat_offsets_loaded,
  562. &oes->rx_multicast, &es->rx_multicast);
  563. i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
  564. veb->stat_offsets_loaded,
  565. &oes->rx_broadcast, &es->rx_broadcast);
  566. i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
  567. veb->stat_offsets_loaded,
  568. &oes->tx_bytes, &es->tx_bytes);
  569. i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
  570. veb->stat_offsets_loaded,
  571. &oes->tx_unicast, &es->tx_unicast);
  572. i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
  573. veb->stat_offsets_loaded,
  574. &oes->tx_multicast, &es->tx_multicast);
  575. i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
  576. veb->stat_offsets_loaded,
  577. &oes->tx_broadcast, &es->tx_broadcast);
  578. veb->stat_offsets_loaded = true;
  579. }
  580. #ifdef I40E_FCOE
  581. /**
  582. * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
  583. * @vsi: the VSI that is capable of doing FCoE
  584. **/
  585. static void i40e_update_fcoe_stats(struct i40e_vsi *vsi)
  586. {
  587. struct i40e_pf *pf = vsi->back;
  588. struct i40e_hw *hw = &pf->hw;
  589. struct i40e_fcoe_stats *ofs;
  590. struct i40e_fcoe_stats *fs; /* device's eth stats */
  591. int idx;
  592. if (vsi->type != I40E_VSI_FCOE)
  593. return;
  594. idx = (pf->pf_seid - I40E_BASE_PF_SEID) + I40E_FCOE_PF_STAT_OFFSET;
  595. fs = &vsi->fcoe_stats;
  596. ofs = &vsi->fcoe_stats_offsets;
  597. i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx),
  598. vsi->fcoe_stat_offsets_loaded,
  599. &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets);
  600. i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx),
  601. vsi->fcoe_stat_offsets_loaded,
  602. &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords);
  603. i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx),
  604. vsi->fcoe_stat_offsets_loaded,
  605. &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped);
  606. i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx),
  607. vsi->fcoe_stat_offsets_loaded,
  608. &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets);
  609. i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx),
  610. vsi->fcoe_stat_offsets_loaded,
  611. &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords);
  612. i40e_stat_update32(hw, I40E_GL_FCOECRC(idx),
  613. vsi->fcoe_stat_offsets_loaded,
  614. &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc);
  615. i40e_stat_update32(hw, I40E_GL_FCOELAST(idx),
  616. vsi->fcoe_stat_offsets_loaded,
  617. &ofs->fcoe_last_error, &fs->fcoe_last_error);
  618. i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx),
  619. vsi->fcoe_stat_offsets_loaded,
  620. &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count);
  621. vsi->fcoe_stat_offsets_loaded = true;
  622. }
  623. #endif
  624. /**
  625. * i40e_update_link_xoff_rx - Update XOFF received in link flow control mode
  626. * @pf: the corresponding PF
  627. *
  628. * Update the Rx XOFF counter (PAUSE frames) in link flow control mode
  629. **/
  630. static void i40e_update_link_xoff_rx(struct i40e_pf *pf)
  631. {
  632. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  633. struct i40e_hw_port_stats *nsd = &pf->stats;
  634. struct i40e_hw *hw = &pf->hw;
  635. u64 xoff = 0;
  636. u16 i, v;
  637. if ((hw->fc.current_mode != I40E_FC_FULL) &&
  638. (hw->fc.current_mode != I40E_FC_RX_PAUSE))
  639. return;
  640. xoff = nsd->link_xoff_rx;
  641. i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
  642. pf->stat_offsets_loaded,
  643. &osd->link_xoff_rx, &nsd->link_xoff_rx);
  644. /* No new LFC xoff rx */
  645. if (!(nsd->link_xoff_rx - xoff))
  646. return;
  647. /* Clear the __I40E_HANG_CHECK_ARMED bit for all Tx rings */
  648. for (v = 0; v < pf->num_alloc_vsi; v++) {
  649. struct i40e_vsi *vsi = pf->vsi[v];
  650. if (!vsi || !vsi->tx_rings[0])
  651. continue;
  652. for (i = 0; i < vsi->num_queue_pairs; i++) {
  653. struct i40e_ring *ring = vsi->tx_rings[i];
  654. clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state);
  655. }
  656. }
  657. }
  658. /**
  659. * i40e_update_prio_xoff_rx - Update XOFF received in PFC mode
  660. * @pf: the corresponding PF
  661. *
  662. * Update the Rx XOFF counter (PAUSE frames) in PFC mode
  663. **/
  664. static void i40e_update_prio_xoff_rx(struct i40e_pf *pf)
  665. {
  666. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  667. struct i40e_hw_port_stats *nsd = &pf->stats;
  668. bool xoff[I40E_MAX_TRAFFIC_CLASS] = {false};
  669. struct i40e_dcbx_config *dcb_cfg;
  670. struct i40e_hw *hw = &pf->hw;
  671. u16 i, v;
  672. u8 tc;
  673. dcb_cfg = &hw->local_dcbx_config;
  674. /* See if DCB enabled with PFC TC */
  675. if (!(pf->flags & I40E_FLAG_DCB_ENABLED) ||
  676. !(dcb_cfg->pfc.pfcenable)) {
  677. i40e_update_link_xoff_rx(pf);
  678. return;
  679. }
  680. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  681. u64 prio_xoff = nsd->priority_xoff_rx[i];
  682. i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
  683. pf->stat_offsets_loaded,
  684. &osd->priority_xoff_rx[i],
  685. &nsd->priority_xoff_rx[i]);
  686. /* No new PFC xoff rx */
  687. if (!(nsd->priority_xoff_rx[i] - prio_xoff))
  688. continue;
  689. /* Get the TC for given priority */
  690. tc = dcb_cfg->etscfg.prioritytable[i];
  691. xoff[tc] = true;
  692. }
  693. /* Clear the __I40E_HANG_CHECK_ARMED bit for Tx rings */
  694. for (v = 0; v < pf->num_alloc_vsi; v++) {
  695. struct i40e_vsi *vsi = pf->vsi[v];
  696. if (!vsi || !vsi->tx_rings[0])
  697. continue;
  698. for (i = 0; i < vsi->num_queue_pairs; i++) {
  699. struct i40e_ring *ring = vsi->tx_rings[i];
  700. tc = ring->dcb_tc;
  701. if (xoff[tc])
  702. clear_bit(__I40E_HANG_CHECK_ARMED,
  703. &ring->state);
  704. }
  705. }
  706. }
  707. /**
  708. * i40e_update_vsi_stats - Update the vsi statistics counters.
  709. * @vsi: the VSI to be updated
  710. *
  711. * There are a few instances where we store the same stat in a
  712. * couple of different structs. This is partly because we have
  713. * the netdev stats that need to be filled out, which is slightly
  714. * different from the "eth_stats" defined by the chip and used in
  715. * VF communications. We sort it out here.
  716. **/
  717. static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
  718. {
  719. struct i40e_pf *pf = vsi->back;
  720. struct rtnl_link_stats64 *ons;
  721. struct rtnl_link_stats64 *ns; /* netdev stats */
  722. struct i40e_eth_stats *oes;
  723. struct i40e_eth_stats *es; /* device's eth stats */
  724. u32 tx_restart, tx_busy;
  725. u32 rx_page, rx_buf;
  726. u64 rx_p, rx_b;
  727. u64 tx_p, tx_b;
  728. u16 q;
  729. if (test_bit(__I40E_DOWN, &vsi->state) ||
  730. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  731. return;
  732. ns = i40e_get_vsi_stats_struct(vsi);
  733. ons = &vsi->net_stats_offsets;
  734. es = &vsi->eth_stats;
  735. oes = &vsi->eth_stats_offsets;
  736. /* Gather up the netdev and vsi stats that the driver collects
  737. * on the fly during packet processing
  738. */
  739. rx_b = rx_p = 0;
  740. tx_b = tx_p = 0;
  741. tx_restart = tx_busy = 0;
  742. rx_page = 0;
  743. rx_buf = 0;
  744. rcu_read_lock();
  745. for (q = 0; q < vsi->num_queue_pairs; q++) {
  746. struct i40e_ring *p;
  747. u64 bytes, packets;
  748. unsigned int start;
  749. /* locate Tx ring */
  750. p = ACCESS_ONCE(vsi->tx_rings[q]);
  751. do {
  752. start = u64_stats_fetch_begin_irq(&p->syncp);
  753. packets = p->stats.packets;
  754. bytes = p->stats.bytes;
  755. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  756. tx_b += bytes;
  757. tx_p += packets;
  758. tx_restart += p->tx_stats.restart_queue;
  759. tx_busy += p->tx_stats.tx_busy;
  760. /* Rx queue is part of the same block as Tx queue */
  761. p = &p[1];
  762. do {
  763. start = u64_stats_fetch_begin_irq(&p->syncp);
  764. packets = p->stats.packets;
  765. bytes = p->stats.bytes;
  766. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  767. rx_b += bytes;
  768. rx_p += packets;
  769. rx_buf += p->rx_stats.alloc_buff_failed;
  770. rx_page += p->rx_stats.alloc_page_failed;
  771. }
  772. rcu_read_unlock();
  773. vsi->tx_restart = tx_restart;
  774. vsi->tx_busy = tx_busy;
  775. vsi->rx_page_failed = rx_page;
  776. vsi->rx_buf_failed = rx_buf;
  777. ns->rx_packets = rx_p;
  778. ns->rx_bytes = rx_b;
  779. ns->tx_packets = tx_p;
  780. ns->tx_bytes = tx_b;
  781. /* update netdev stats from eth stats */
  782. i40e_update_eth_stats(vsi);
  783. ons->tx_errors = oes->tx_errors;
  784. ns->tx_errors = es->tx_errors;
  785. ons->multicast = oes->rx_multicast;
  786. ns->multicast = es->rx_multicast;
  787. ons->rx_dropped = oes->rx_discards;
  788. ns->rx_dropped = es->rx_discards;
  789. ons->tx_dropped = oes->tx_discards;
  790. ns->tx_dropped = es->tx_discards;
  791. /* pull in a couple PF stats if this is the main vsi */
  792. if (vsi == pf->vsi[pf->lan_vsi]) {
  793. ns->rx_crc_errors = pf->stats.crc_errors;
  794. ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
  795. ns->rx_length_errors = pf->stats.rx_length_errors;
  796. }
  797. }
  798. /**
  799. * i40e_update_pf_stats - Update the pf statistics counters.
  800. * @pf: the PF to be updated
  801. **/
  802. static void i40e_update_pf_stats(struct i40e_pf *pf)
  803. {
  804. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  805. struct i40e_hw_port_stats *nsd = &pf->stats;
  806. struct i40e_hw *hw = &pf->hw;
  807. u32 val;
  808. int i;
  809. i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
  810. I40E_GLPRT_GORCL(hw->port),
  811. pf->stat_offsets_loaded,
  812. &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
  813. i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
  814. I40E_GLPRT_GOTCL(hw->port),
  815. pf->stat_offsets_loaded,
  816. &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
  817. i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
  818. pf->stat_offsets_loaded,
  819. &osd->eth.rx_discards,
  820. &nsd->eth.rx_discards);
  821. i40e_stat_update32(hw, I40E_GLPRT_TDPC(hw->port),
  822. pf->stat_offsets_loaded,
  823. &osd->eth.tx_discards,
  824. &nsd->eth.tx_discards);
  825. i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
  826. I40E_GLPRT_UPRCL(hw->port),
  827. pf->stat_offsets_loaded,
  828. &osd->eth.rx_unicast,
  829. &nsd->eth.rx_unicast);
  830. i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
  831. I40E_GLPRT_MPRCL(hw->port),
  832. pf->stat_offsets_loaded,
  833. &osd->eth.rx_multicast,
  834. &nsd->eth.rx_multicast);
  835. i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
  836. I40E_GLPRT_BPRCL(hw->port),
  837. pf->stat_offsets_loaded,
  838. &osd->eth.rx_broadcast,
  839. &nsd->eth.rx_broadcast);
  840. i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
  841. I40E_GLPRT_UPTCL(hw->port),
  842. pf->stat_offsets_loaded,
  843. &osd->eth.tx_unicast,
  844. &nsd->eth.tx_unicast);
  845. i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
  846. I40E_GLPRT_MPTCL(hw->port),
  847. pf->stat_offsets_loaded,
  848. &osd->eth.tx_multicast,
  849. &nsd->eth.tx_multicast);
  850. i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
  851. I40E_GLPRT_BPTCL(hw->port),
  852. pf->stat_offsets_loaded,
  853. &osd->eth.tx_broadcast,
  854. &nsd->eth.tx_broadcast);
  855. i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
  856. pf->stat_offsets_loaded,
  857. &osd->tx_dropped_link_down,
  858. &nsd->tx_dropped_link_down);
  859. i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
  860. pf->stat_offsets_loaded,
  861. &osd->crc_errors, &nsd->crc_errors);
  862. i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
  863. pf->stat_offsets_loaded,
  864. &osd->illegal_bytes, &nsd->illegal_bytes);
  865. i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
  866. pf->stat_offsets_loaded,
  867. &osd->mac_local_faults,
  868. &nsd->mac_local_faults);
  869. i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
  870. pf->stat_offsets_loaded,
  871. &osd->mac_remote_faults,
  872. &nsd->mac_remote_faults);
  873. i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
  874. pf->stat_offsets_loaded,
  875. &osd->rx_length_errors,
  876. &nsd->rx_length_errors);
  877. i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
  878. pf->stat_offsets_loaded,
  879. &osd->link_xon_rx, &nsd->link_xon_rx);
  880. i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
  881. pf->stat_offsets_loaded,
  882. &osd->link_xon_tx, &nsd->link_xon_tx);
  883. i40e_update_prio_xoff_rx(pf); /* handles I40E_GLPRT_LXOFFRXC */
  884. i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
  885. pf->stat_offsets_loaded,
  886. &osd->link_xoff_tx, &nsd->link_xoff_tx);
  887. for (i = 0; i < 8; i++) {
  888. i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
  889. pf->stat_offsets_loaded,
  890. &osd->priority_xon_rx[i],
  891. &nsd->priority_xon_rx[i]);
  892. i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
  893. pf->stat_offsets_loaded,
  894. &osd->priority_xon_tx[i],
  895. &nsd->priority_xon_tx[i]);
  896. i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
  897. pf->stat_offsets_loaded,
  898. &osd->priority_xoff_tx[i],
  899. &nsd->priority_xoff_tx[i]);
  900. i40e_stat_update32(hw,
  901. I40E_GLPRT_RXON2OFFCNT(hw->port, i),
  902. pf->stat_offsets_loaded,
  903. &osd->priority_xon_2_xoff[i],
  904. &nsd->priority_xon_2_xoff[i]);
  905. }
  906. i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
  907. I40E_GLPRT_PRC64L(hw->port),
  908. pf->stat_offsets_loaded,
  909. &osd->rx_size_64, &nsd->rx_size_64);
  910. i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
  911. I40E_GLPRT_PRC127L(hw->port),
  912. pf->stat_offsets_loaded,
  913. &osd->rx_size_127, &nsd->rx_size_127);
  914. i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
  915. I40E_GLPRT_PRC255L(hw->port),
  916. pf->stat_offsets_loaded,
  917. &osd->rx_size_255, &nsd->rx_size_255);
  918. i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
  919. I40E_GLPRT_PRC511L(hw->port),
  920. pf->stat_offsets_loaded,
  921. &osd->rx_size_511, &nsd->rx_size_511);
  922. i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
  923. I40E_GLPRT_PRC1023L(hw->port),
  924. pf->stat_offsets_loaded,
  925. &osd->rx_size_1023, &nsd->rx_size_1023);
  926. i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
  927. I40E_GLPRT_PRC1522L(hw->port),
  928. pf->stat_offsets_loaded,
  929. &osd->rx_size_1522, &nsd->rx_size_1522);
  930. i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
  931. I40E_GLPRT_PRC9522L(hw->port),
  932. pf->stat_offsets_loaded,
  933. &osd->rx_size_big, &nsd->rx_size_big);
  934. i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
  935. I40E_GLPRT_PTC64L(hw->port),
  936. pf->stat_offsets_loaded,
  937. &osd->tx_size_64, &nsd->tx_size_64);
  938. i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
  939. I40E_GLPRT_PTC127L(hw->port),
  940. pf->stat_offsets_loaded,
  941. &osd->tx_size_127, &nsd->tx_size_127);
  942. i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
  943. I40E_GLPRT_PTC255L(hw->port),
  944. pf->stat_offsets_loaded,
  945. &osd->tx_size_255, &nsd->tx_size_255);
  946. i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
  947. I40E_GLPRT_PTC511L(hw->port),
  948. pf->stat_offsets_loaded,
  949. &osd->tx_size_511, &nsd->tx_size_511);
  950. i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
  951. I40E_GLPRT_PTC1023L(hw->port),
  952. pf->stat_offsets_loaded,
  953. &osd->tx_size_1023, &nsd->tx_size_1023);
  954. i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
  955. I40E_GLPRT_PTC1522L(hw->port),
  956. pf->stat_offsets_loaded,
  957. &osd->tx_size_1522, &nsd->tx_size_1522);
  958. i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
  959. I40E_GLPRT_PTC9522L(hw->port),
  960. pf->stat_offsets_loaded,
  961. &osd->tx_size_big, &nsd->tx_size_big);
  962. i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
  963. pf->stat_offsets_loaded,
  964. &osd->rx_undersize, &nsd->rx_undersize);
  965. i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
  966. pf->stat_offsets_loaded,
  967. &osd->rx_fragments, &nsd->rx_fragments);
  968. i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
  969. pf->stat_offsets_loaded,
  970. &osd->rx_oversize, &nsd->rx_oversize);
  971. i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
  972. pf->stat_offsets_loaded,
  973. &osd->rx_jabber, &nsd->rx_jabber);
  974. /* FDIR stats */
  975. i40e_stat_update32(hw, I40E_GLQF_PCNT(pf->fd_atr_cnt_idx),
  976. pf->stat_offsets_loaded,
  977. &osd->fd_atr_match, &nsd->fd_atr_match);
  978. i40e_stat_update32(hw, I40E_GLQF_PCNT(pf->fd_sb_cnt_idx),
  979. pf->stat_offsets_loaded,
  980. &osd->fd_sb_match, &nsd->fd_sb_match);
  981. val = rd32(hw, I40E_PRTPM_EEE_STAT);
  982. nsd->tx_lpi_status =
  983. (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
  984. I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
  985. nsd->rx_lpi_status =
  986. (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
  987. I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
  988. i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
  989. pf->stat_offsets_loaded,
  990. &osd->tx_lpi_count, &nsd->tx_lpi_count);
  991. i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
  992. pf->stat_offsets_loaded,
  993. &osd->rx_lpi_count, &nsd->rx_lpi_count);
  994. pf->stat_offsets_loaded = true;
  995. }
  996. /**
  997. * i40e_update_stats - Update the various statistics counters.
  998. * @vsi: the VSI to be updated
  999. *
  1000. * Update the various stats for this VSI and its related entities.
  1001. **/
  1002. void i40e_update_stats(struct i40e_vsi *vsi)
  1003. {
  1004. struct i40e_pf *pf = vsi->back;
  1005. if (vsi == pf->vsi[pf->lan_vsi])
  1006. i40e_update_pf_stats(pf);
  1007. i40e_update_vsi_stats(vsi);
  1008. #ifdef I40E_FCOE
  1009. i40e_update_fcoe_stats(vsi);
  1010. #endif
  1011. }
  1012. /**
  1013. * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
  1014. * @vsi: the VSI to be searched
  1015. * @macaddr: the MAC address
  1016. * @vlan: the vlan
  1017. * @is_vf: make sure its a vf filter, else doesn't matter
  1018. * @is_netdev: make sure its a netdev filter, else doesn't matter
  1019. *
  1020. * Returns ptr to the filter object or NULL
  1021. **/
  1022. static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
  1023. u8 *macaddr, s16 vlan,
  1024. bool is_vf, bool is_netdev)
  1025. {
  1026. struct i40e_mac_filter *f;
  1027. if (!vsi || !macaddr)
  1028. return NULL;
  1029. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1030. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  1031. (vlan == f->vlan) &&
  1032. (!is_vf || f->is_vf) &&
  1033. (!is_netdev || f->is_netdev))
  1034. return f;
  1035. }
  1036. return NULL;
  1037. }
  1038. /**
  1039. * i40e_find_mac - Find a mac addr in the macvlan filters list
  1040. * @vsi: the VSI to be searched
  1041. * @macaddr: the MAC address we are searching for
  1042. * @is_vf: make sure its a vf filter, else doesn't matter
  1043. * @is_netdev: make sure its a netdev filter, else doesn't matter
  1044. *
  1045. * Returns the first filter with the provided MAC address or NULL if
  1046. * MAC address was not found
  1047. **/
  1048. struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr,
  1049. bool is_vf, bool is_netdev)
  1050. {
  1051. struct i40e_mac_filter *f;
  1052. if (!vsi || !macaddr)
  1053. return NULL;
  1054. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1055. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  1056. (!is_vf || f->is_vf) &&
  1057. (!is_netdev || f->is_netdev))
  1058. return f;
  1059. }
  1060. return NULL;
  1061. }
  1062. /**
  1063. * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
  1064. * @vsi: the VSI to be searched
  1065. *
  1066. * Returns true if VSI is in vlan mode or false otherwise
  1067. **/
  1068. bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
  1069. {
  1070. struct i40e_mac_filter *f;
  1071. /* Only -1 for all the filters denotes not in vlan mode
  1072. * so we have to go through all the list in order to make sure
  1073. */
  1074. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1075. if (f->vlan >= 0)
  1076. return true;
  1077. }
  1078. return false;
  1079. }
  1080. /**
  1081. * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
  1082. * @vsi: the VSI to be searched
  1083. * @macaddr: the mac address to be filtered
  1084. * @is_vf: true if it is a vf
  1085. * @is_netdev: true if it is a netdev
  1086. *
  1087. * Goes through all the macvlan filters and adds a
  1088. * macvlan filter for each unique vlan that already exists
  1089. *
  1090. * Returns first filter found on success, else NULL
  1091. **/
  1092. struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr,
  1093. bool is_vf, bool is_netdev)
  1094. {
  1095. struct i40e_mac_filter *f;
  1096. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1097. if (!i40e_find_filter(vsi, macaddr, f->vlan,
  1098. is_vf, is_netdev)) {
  1099. if (!i40e_add_filter(vsi, macaddr, f->vlan,
  1100. is_vf, is_netdev))
  1101. return NULL;
  1102. }
  1103. }
  1104. return list_first_entry_or_null(&vsi->mac_filter_list,
  1105. struct i40e_mac_filter, list);
  1106. }
  1107. /**
  1108. * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
  1109. * @vsi: the PF Main VSI - inappropriate for any other VSI
  1110. * @macaddr: the MAC address
  1111. *
  1112. * Some older firmware configurations set up a default promiscuous VLAN
  1113. * filter that needs to be removed.
  1114. **/
  1115. static int i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
  1116. {
  1117. struct i40e_aqc_remove_macvlan_element_data element;
  1118. struct i40e_pf *pf = vsi->back;
  1119. i40e_status aq_ret;
  1120. /* Only appropriate for the PF main VSI */
  1121. if (vsi->type != I40E_VSI_MAIN)
  1122. return -EINVAL;
  1123. memset(&element, 0, sizeof(element));
  1124. ether_addr_copy(element.mac_addr, macaddr);
  1125. element.vlan_tag = 0;
  1126. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
  1127. I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  1128. aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1129. if (aq_ret)
  1130. return -ENOENT;
  1131. return 0;
  1132. }
  1133. /**
  1134. * i40e_add_filter - Add a mac/vlan filter to the VSI
  1135. * @vsi: the VSI to be searched
  1136. * @macaddr: the MAC address
  1137. * @vlan: the vlan
  1138. * @is_vf: make sure its a vf filter, else doesn't matter
  1139. * @is_netdev: make sure its a netdev filter, else doesn't matter
  1140. *
  1141. * Returns ptr to the filter object or NULL when no memory available.
  1142. **/
  1143. struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
  1144. u8 *macaddr, s16 vlan,
  1145. bool is_vf, bool is_netdev)
  1146. {
  1147. struct i40e_mac_filter *f;
  1148. if (!vsi || !macaddr)
  1149. return NULL;
  1150. f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
  1151. if (!f) {
  1152. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  1153. if (!f)
  1154. goto add_filter_out;
  1155. ether_addr_copy(f->macaddr, macaddr);
  1156. f->vlan = vlan;
  1157. f->changed = true;
  1158. INIT_LIST_HEAD(&f->list);
  1159. list_add(&f->list, &vsi->mac_filter_list);
  1160. }
  1161. /* increment counter and add a new flag if needed */
  1162. if (is_vf) {
  1163. if (!f->is_vf) {
  1164. f->is_vf = true;
  1165. f->counter++;
  1166. }
  1167. } else if (is_netdev) {
  1168. if (!f->is_netdev) {
  1169. f->is_netdev = true;
  1170. f->counter++;
  1171. }
  1172. } else {
  1173. f->counter++;
  1174. }
  1175. /* changed tells sync_filters_subtask to
  1176. * push the filter down to the firmware
  1177. */
  1178. if (f->changed) {
  1179. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1180. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1181. }
  1182. add_filter_out:
  1183. return f;
  1184. }
  1185. /**
  1186. * i40e_del_filter - Remove a mac/vlan filter from the VSI
  1187. * @vsi: the VSI to be searched
  1188. * @macaddr: the MAC address
  1189. * @vlan: the vlan
  1190. * @is_vf: make sure it's a vf filter, else doesn't matter
  1191. * @is_netdev: make sure it's a netdev filter, else doesn't matter
  1192. **/
  1193. void i40e_del_filter(struct i40e_vsi *vsi,
  1194. u8 *macaddr, s16 vlan,
  1195. bool is_vf, bool is_netdev)
  1196. {
  1197. struct i40e_mac_filter *f;
  1198. if (!vsi || !macaddr)
  1199. return;
  1200. f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
  1201. if (!f || f->counter == 0)
  1202. return;
  1203. if (is_vf) {
  1204. if (f->is_vf) {
  1205. f->is_vf = false;
  1206. f->counter--;
  1207. }
  1208. } else if (is_netdev) {
  1209. if (f->is_netdev) {
  1210. f->is_netdev = false;
  1211. f->counter--;
  1212. }
  1213. } else {
  1214. /* make sure we don't remove a filter in use by vf or netdev */
  1215. int min_f = 0;
  1216. min_f += (f->is_vf ? 1 : 0);
  1217. min_f += (f->is_netdev ? 1 : 0);
  1218. if (f->counter > min_f)
  1219. f->counter--;
  1220. }
  1221. /* counter == 0 tells sync_filters_subtask to
  1222. * remove the filter from the firmware's list
  1223. */
  1224. if (f->counter == 0) {
  1225. f->changed = true;
  1226. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1227. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1228. }
  1229. }
  1230. /**
  1231. * i40e_set_mac - NDO callback to set mac address
  1232. * @netdev: network interface device structure
  1233. * @p: pointer to an address structure
  1234. *
  1235. * Returns 0 on success, negative on failure
  1236. **/
  1237. #ifdef I40E_FCOE
  1238. int i40e_set_mac(struct net_device *netdev, void *p)
  1239. #else
  1240. static int i40e_set_mac(struct net_device *netdev, void *p)
  1241. #endif
  1242. {
  1243. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1244. struct i40e_vsi *vsi = np->vsi;
  1245. struct i40e_pf *pf = vsi->back;
  1246. struct i40e_hw *hw = &pf->hw;
  1247. struct sockaddr *addr = p;
  1248. struct i40e_mac_filter *f;
  1249. if (!is_valid_ether_addr(addr->sa_data))
  1250. return -EADDRNOTAVAIL;
  1251. if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
  1252. netdev_info(netdev, "already using mac address %pM\n",
  1253. addr->sa_data);
  1254. return 0;
  1255. }
  1256. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  1257. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  1258. return -EADDRNOTAVAIL;
  1259. if (ether_addr_equal(hw->mac.addr, addr->sa_data))
  1260. netdev_info(netdev, "returning to hw mac address %pM\n",
  1261. hw->mac.addr);
  1262. else
  1263. netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
  1264. if (vsi->type == I40E_VSI_MAIN) {
  1265. i40e_status ret;
  1266. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  1267. I40E_AQC_WRITE_TYPE_LAA_WOL,
  1268. addr->sa_data, NULL);
  1269. if (ret) {
  1270. netdev_info(netdev,
  1271. "Addr change for Main VSI failed: %d\n",
  1272. ret);
  1273. return -EADDRNOTAVAIL;
  1274. }
  1275. }
  1276. if (ether_addr_equal(netdev->dev_addr, hw->mac.addr)) {
  1277. struct i40e_aqc_remove_macvlan_element_data element;
  1278. memset(&element, 0, sizeof(element));
  1279. ether_addr_copy(element.mac_addr, netdev->dev_addr);
  1280. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1281. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1282. } else {
  1283. i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
  1284. false, false);
  1285. }
  1286. if (ether_addr_equal(addr->sa_data, hw->mac.addr)) {
  1287. struct i40e_aqc_add_macvlan_element_data element;
  1288. memset(&element, 0, sizeof(element));
  1289. ether_addr_copy(element.mac_addr, hw->mac.addr);
  1290. element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
  1291. i40e_aq_add_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1292. } else {
  1293. f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY,
  1294. false, false);
  1295. if (f)
  1296. f->is_laa = true;
  1297. }
  1298. i40e_sync_vsi_filters(vsi);
  1299. ether_addr_copy(netdev->dev_addr, addr->sa_data);
  1300. return 0;
  1301. }
  1302. /**
  1303. * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
  1304. * @vsi: the VSI being setup
  1305. * @ctxt: VSI context structure
  1306. * @enabled_tc: Enabled TCs bitmap
  1307. * @is_add: True if called before Add VSI
  1308. *
  1309. * Setup VSI queue mapping for enabled traffic classes.
  1310. **/
  1311. #ifdef I40E_FCOE
  1312. void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1313. struct i40e_vsi_context *ctxt,
  1314. u8 enabled_tc,
  1315. bool is_add)
  1316. #else
  1317. static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1318. struct i40e_vsi_context *ctxt,
  1319. u8 enabled_tc,
  1320. bool is_add)
  1321. #endif
  1322. {
  1323. struct i40e_pf *pf = vsi->back;
  1324. u16 sections = 0;
  1325. u8 netdev_tc = 0;
  1326. u16 numtc = 0;
  1327. u16 qcount;
  1328. u8 offset;
  1329. u16 qmap;
  1330. int i;
  1331. u16 num_tc_qps = 0;
  1332. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1333. offset = 0;
  1334. if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  1335. /* Find numtc from enabled TC bitmap */
  1336. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1337. if (enabled_tc & (1 << i)) /* TC is enabled */
  1338. numtc++;
  1339. }
  1340. if (!numtc) {
  1341. dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
  1342. numtc = 1;
  1343. }
  1344. } else {
  1345. /* At least TC0 is enabled in case of non-DCB case */
  1346. numtc = 1;
  1347. }
  1348. vsi->tc_config.numtc = numtc;
  1349. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1350. /* Number of queues per enabled TC */
  1351. num_tc_qps = vsi->alloc_queue_pairs/numtc;
  1352. num_tc_qps = min_t(int, num_tc_qps, I40E_MAX_QUEUES_PER_TC);
  1353. /* Setup queue offset/count for all TCs for given VSI */
  1354. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1355. /* See if the given TC is enabled for the given VSI */
  1356. if (vsi->tc_config.enabled_tc & (1 << i)) { /* TC is enabled */
  1357. int pow, num_qps;
  1358. switch (vsi->type) {
  1359. case I40E_VSI_MAIN:
  1360. qcount = min_t(int, pf->rss_size, num_tc_qps);
  1361. break;
  1362. #ifdef I40E_FCOE
  1363. case I40E_VSI_FCOE:
  1364. qcount = num_tc_qps;
  1365. break;
  1366. #endif
  1367. case I40E_VSI_FDIR:
  1368. case I40E_VSI_SRIOV:
  1369. case I40E_VSI_VMDQ2:
  1370. default:
  1371. qcount = num_tc_qps;
  1372. WARN_ON(i != 0);
  1373. break;
  1374. }
  1375. vsi->tc_config.tc_info[i].qoffset = offset;
  1376. vsi->tc_config.tc_info[i].qcount = qcount;
  1377. /* find the power-of-2 of the number of queue pairs */
  1378. num_qps = qcount;
  1379. pow = 0;
  1380. while (num_qps && ((1 << pow) < qcount)) {
  1381. pow++;
  1382. num_qps >>= 1;
  1383. }
  1384. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1385. qmap =
  1386. (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1387. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1388. offset += qcount;
  1389. } else {
  1390. /* TC is not enabled so set the offset to
  1391. * default queue and allocate one queue
  1392. * for the given TC.
  1393. */
  1394. vsi->tc_config.tc_info[i].qoffset = 0;
  1395. vsi->tc_config.tc_info[i].qcount = 1;
  1396. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1397. qmap = 0;
  1398. }
  1399. ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
  1400. }
  1401. /* Set actual Tx/Rx queue pairs */
  1402. vsi->num_queue_pairs = offset;
  1403. /* Scheduler section valid can only be set for ADD VSI */
  1404. if (is_add) {
  1405. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1406. ctxt->info.up_enable_bits = enabled_tc;
  1407. }
  1408. if (vsi->type == I40E_VSI_SRIOV) {
  1409. ctxt->info.mapping_flags |=
  1410. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
  1411. for (i = 0; i < vsi->num_queue_pairs; i++)
  1412. ctxt->info.queue_mapping[i] =
  1413. cpu_to_le16(vsi->base_queue + i);
  1414. } else {
  1415. ctxt->info.mapping_flags |=
  1416. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1417. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1418. }
  1419. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1420. }
  1421. /**
  1422. * i40e_set_rx_mode - NDO callback to set the netdev filters
  1423. * @netdev: network interface device structure
  1424. **/
  1425. #ifdef I40E_FCOE
  1426. void i40e_set_rx_mode(struct net_device *netdev)
  1427. #else
  1428. static void i40e_set_rx_mode(struct net_device *netdev)
  1429. #endif
  1430. {
  1431. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1432. struct i40e_mac_filter *f, *ftmp;
  1433. struct i40e_vsi *vsi = np->vsi;
  1434. struct netdev_hw_addr *uca;
  1435. struct netdev_hw_addr *mca;
  1436. struct netdev_hw_addr *ha;
  1437. /* add addr if not already in the filter list */
  1438. netdev_for_each_uc_addr(uca, netdev) {
  1439. if (!i40e_find_mac(vsi, uca->addr, false, true)) {
  1440. if (i40e_is_vsi_in_vlan(vsi))
  1441. i40e_put_mac_in_vlan(vsi, uca->addr,
  1442. false, true);
  1443. else
  1444. i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY,
  1445. false, true);
  1446. }
  1447. }
  1448. netdev_for_each_mc_addr(mca, netdev) {
  1449. if (!i40e_find_mac(vsi, mca->addr, false, true)) {
  1450. if (i40e_is_vsi_in_vlan(vsi))
  1451. i40e_put_mac_in_vlan(vsi, mca->addr,
  1452. false, true);
  1453. else
  1454. i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY,
  1455. false, true);
  1456. }
  1457. }
  1458. /* remove filter if not in netdev list */
  1459. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1460. bool found = false;
  1461. if (!f->is_netdev)
  1462. continue;
  1463. if (is_multicast_ether_addr(f->macaddr)) {
  1464. netdev_for_each_mc_addr(mca, netdev) {
  1465. if (ether_addr_equal(mca->addr, f->macaddr)) {
  1466. found = true;
  1467. break;
  1468. }
  1469. }
  1470. } else {
  1471. netdev_for_each_uc_addr(uca, netdev) {
  1472. if (ether_addr_equal(uca->addr, f->macaddr)) {
  1473. found = true;
  1474. break;
  1475. }
  1476. }
  1477. for_each_dev_addr(netdev, ha) {
  1478. if (ether_addr_equal(ha->addr, f->macaddr)) {
  1479. found = true;
  1480. break;
  1481. }
  1482. }
  1483. }
  1484. if (!found)
  1485. i40e_del_filter(
  1486. vsi, f->macaddr, I40E_VLAN_ANY, false, true);
  1487. }
  1488. /* check for other flag changes */
  1489. if (vsi->current_netdev_flags != vsi->netdev->flags) {
  1490. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1491. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1492. }
  1493. }
  1494. /**
  1495. * i40e_sync_vsi_filters - Update the VSI filter list to the HW
  1496. * @vsi: ptr to the VSI
  1497. *
  1498. * Push any outstanding VSI filter changes through the AdminQ.
  1499. *
  1500. * Returns 0 or error value
  1501. **/
  1502. int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
  1503. {
  1504. struct i40e_mac_filter *f, *ftmp;
  1505. bool promisc_forced_on = false;
  1506. bool add_happened = false;
  1507. int filter_list_len = 0;
  1508. u32 changed_flags = 0;
  1509. i40e_status aq_ret = 0;
  1510. struct i40e_pf *pf;
  1511. int num_add = 0;
  1512. int num_del = 0;
  1513. u16 cmd_flags;
  1514. /* empty array typed pointers, kcalloc later */
  1515. struct i40e_aqc_add_macvlan_element_data *add_list;
  1516. struct i40e_aqc_remove_macvlan_element_data *del_list;
  1517. while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
  1518. usleep_range(1000, 2000);
  1519. pf = vsi->back;
  1520. if (vsi->netdev) {
  1521. changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
  1522. vsi->current_netdev_flags = vsi->netdev->flags;
  1523. }
  1524. if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
  1525. vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
  1526. filter_list_len = pf->hw.aq.asq_buf_size /
  1527. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  1528. del_list = kcalloc(filter_list_len,
  1529. sizeof(struct i40e_aqc_remove_macvlan_element_data),
  1530. GFP_KERNEL);
  1531. if (!del_list)
  1532. return -ENOMEM;
  1533. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1534. if (!f->changed)
  1535. continue;
  1536. if (f->counter != 0)
  1537. continue;
  1538. f->changed = false;
  1539. cmd_flags = 0;
  1540. /* add to delete list */
  1541. ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
  1542. del_list[num_del].vlan_tag =
  1543. cpu_to_le16((u16)(f->vlan ==
  1544. I40E_VLAN_ANY ? 0 : f->vlan));
  1545. cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1546. del_list[num_del].flags = cmd_flags;
  1547. num_del++;
  1548. /* unlink from filter list */
  1549. list_del(&f->list);
  1550. kfree(f);
  1551. /* flush a full buffer */
  1552. if (num_del == filter_list_len) {
  1553. aq_ret = i40e_aq_remove_macvlan(&pf->hw,
  1554. vsi->seid, del_list, num_del,
  1555. NULL);
  1556. num_del = 0;
  1557. memset(del_list, 0, sizeof(*del_list));
  1558. if (aq_ret &&
  1559. pf->hw.aq.asq_last_status !=
  1560. I40E_AQ_RC_ENOENT)
  1561. dev_info(&pf->pdev->dev,
  1562. "ignoring delete macvlan error, err %d, aq_err %d while flushing a full buffer\n",
  1563. aq_ret,
  1564. pf->hw.aq.asq_last_status);
  1565. }
  1566. }
  1567. if (num_del) {
  1568. aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid,
  1569. del_list, num_del, NULL);
  1570. num_del = 0;
  1571. if (aq_ret &&
  1572. pf->hw.aq.asq_last_status != I40E_AQ_RC_ENOENT)
  1573. dev_info(&pf->pdev->dev,
  1574. "ignoring delete macvlan error, err %d, aq_err %d\n",
  1575. aq_ret, pf->hw.aq.asq_last_status);
  1576. }
  1577. kfree(del_list);
  1578. del_list = NULL;
  1579. /* do all the adds now */
  1580. filter_list_len = pf->hw.aq.asq_buf_size /
  1581. sizeof(struct i40e_aqc_add_macvlan_element_data),
  1582. add_list = kcalloc(filter_list_len,
  1583. sizeof(struct i40e_aqc_add_macvlan_element_data),
  1584. GFP_KERNEL);
  1585. if (!add_list)
  1586. return -ENOMEM;
  1587. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1588. if (!f->changed)
  1589. continue;
  1590. if (f->counter == 0)
  1591. continue;
  1592. f->changed = false;
  1593. add_happened = true;
  1594. cmd_flags = 0;
  1595. /* add to add array */
  1596. ether_addr_copy(add_list[num_add].mac_addr, f->macaddr);
  1597. add_list[num_add].vlan_tag =
  1598. cpu_to_le16(
  1599. (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan));
  1600. add_list[num_add].queue_number = 0;
  1601. cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
  1602. add_list[num_add].flags = cpu_to_le16(cmd_flags);
  1603. num_add++;
  1604. /* flush a full buffer */
  1605. if (num_add == filter_list_len) {
  1606. aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
  1607. add_list, num_add,
  1608. NULL);
  1609. num_add = 0;
  1610. if (aq_ret)
  1611. break;
  1612. memset(add_list, 0, sizeof(*add_list));
  1613. }
  1614. }
  1615. if (num_add) {
  1616. aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
  1617. add_list, num_add, NULL);
  1618. num_add = 0;
  1619. }
  1620. kfree(add_list);
  1621. add_list = NULL;
  1622. if (add_happened && aq_ret &&
  1623. pf->hw.aq.asq_last_status != I40E_AQ_RC_EINVAL) {
  1624. dev_info(&pf->pdev->dev,
  1625. "add filter failed, err %d, aq_err %d\n",
  1626. aq_ret, pf->hw.aq.asq_last_status);
  1627. if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) &&
  1628. !test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1629. &vsi->state)) {
  1630. promisc_forced_on = true;
  1631. set_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1632. &vsi->state);
  1633. dev_info(&pf->pdev->dev, "promiscuous mode forced on\n");
  1634. }
  1635. }
  1636. }
  1637. /* check for changes in promiscuous modes */
  1638. if (changed_flags & IFF_ALLMULTI) {
  1639. bool cur_multipromisc;
  1640. cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
  1641. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
  1642. vsi->seid,
  1643. cur_multipromisc,
  1644. NULL);
  1645. if (aq_ret)
  1646. dev_info(&pf->pdev->dev,
  1647. "set multi promisc failed, err %d, aq_err %d\n",
  1648. aq_ret, pf->hw.aq.asq_last_status);
  1649. }
  1650. if ((changed_flags & IFF_PROMISC) || promisc_forced_on) {
  1651. bool cur_promisc;
  1652. cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
  1653. test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1654. &vsi->state));
  1655. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(&vsi->back->hw,
  1656. vsi->seid,
  1657. cur_promisc, NULL);
  1658. if (aq_ret)
  1659. dev_info(&pf->pdev->dev,
  1660. "set uni promisc failed, err %d, aq_err %d\n",
  1661. aq_ret, pf->hw.aq.asq_last_status);
  1662. aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
  1663. vsi->seid,
  1664. cur_promisc, NULL);
  1665. if (aq_ret)
  1666. dev_info(&pf->pdev->dev,
  1667. "set brdcast promisc failed, err %d, aq_err %d\n",
  1668. aq_ret, pf->hw.aq.asq_last_status);
  1669. }
  1670. clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
  1671. return 0;
  1672. }
  1673. /**
  1674. * i40e_sync_filters_subtask - Sync the VSI filter list with HW
  1675. * @pf: board private structure
  1676. **/
  1677. static void i40e_sync_filters_subtask(struct i40e_pf *pf)
  1678. {
  1679. int v;
  1680. if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
  1681. return;
  1682. pf->flags &= ~I40E_FLAG_FILTER_SYNC;
  1683. for (v = 0; v < pf->num_alloc_vsi; v++) {
  1684. if (pf->vsi[v] &&
  1685. (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED))
  1686. i40e_sync_vsi_filters(pf->vsi[v]);
  1687. }
  1688. }
  1689. /**
  1690. * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  1691. * @netdev: network interface device structure
  1692. * @new_mtu: new value for maximum frame size
  1693. *
  1694. * Returns 0 on success, negative on failure
  1695. **/
  1696. static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
  1697. {
  1698. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1699. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  1700. struct i40e_vsi *vsi = np->vsi;
  1701. /* MTU < 68 is an error and causes problems on some kernels */
  1702. if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
  1703. return -EINVAL;
  1704. netdev_info(netdev, "changing MTU from %d to %d\n",
  1705. netdev->mtu, new_mtu);
  1706. netdev->mtu = new_mtu;
  1707. if (netif_running(netdev))
  1708. i40e_vsi_reinit_locked(vsi);
  1709. return 0;
  1710. }
  1711. /**
  1712. * i40e_ioctl - Access the hwtstamp interface
  1713. * @netdev: network interface device structure
  1714. * @ifr: interface request data
  1715. * @cmd: ioctl command
  1716. **/
  1717. int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  1718. {
  1719. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1720. struct i40e_pf *pf = np->vsi->back;
  1721. switch (cmd) {
  1722. case SIOCGHWTSTAMP:
  1723. return i40e_ptp_get_ts_config(pf, ifr);
  1724. case SIOCSHWTSTAMP:
  1725. return i40e_ptp_set_ts_config(pf, ifr);
  1726. default:
  1727. return -EOPNOTSUPP;
  1728. }
  1729. }
  1730. /**
  1731. * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
  1732. * @vsi: the vsi being adjusted
  1733. **/
  1734. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
  1735. {
  1736. struct i40e_vsi_context ctxt;
  1737. i40e_status ret;
  1738. if ((vsi->info.valid_sections &
  1739. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  1740. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
  1741. return; /* already enabled */
  1742. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  1743. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  1744. I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
  1745. ctxt.seid = vsi->seid;
  1746. memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
  1747. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  1748. if (ret) {
  1749. dev_info(&vsi->back->pdev->dev,
  1750. "%s: update vsi failed, aq_err=%d\n",
  1751. __func__, vsi->back->hw.aq.asq_last_status);
  1752. }
  1753. }
  1754. /**
  1755. * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
  1756. * @vsi: the vsi being adjusted
  1757. **/
  1758. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
  1759. {
  1760. struct i40e_vsi_context ctxt;
  1761. i40e_status ret;
  1762. if ((vsi->info.valid_sections &
  1763. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  1764. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
  1765. I40E_AQ_VSI_PVLAN_EMOD_MASK))
  1766. return; /* already disabled */
  1767. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  1768. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  1769. I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
  1770. ctxt.seid = vsi->seid;
  1771. memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
  1772. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  1773. if (ret) {
  1774. dev_info(&vsi->back->pdev->dev,
  1775. "%s: update vsi failed, aq_err=%d\n",
  1776. __func__, vsi->back->hw.aq.asq_last_status);
  1777. }
  1778. }
  1779. /**
  1780. * i40e_vlan_rx_register - Setup or shutdown vlan offload
  1781. * @netdev: network interface to be adjusted
  1782. * @features: netdev features to test if VLAN offload is enabled or not
  1783. **/
  1784. static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
  1785. {
  1786. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1787. struct i40e_vsi *vsi = np->vsi;
  1788. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  1789. i40e_vlan_stripping_enable(vsi);
  1790. else
  1791. i40e_vlan_stripping_disable(vsi);
  1792. }
  1793. /**
  1794. * i40e_vsi_add_vlan - Add vsi membership for given vlan
  1795. * @vsi: the vsi being configured
  1796. * @vid: vlan id to be added (0 = untagged only , -1 = any)
  1797. **/
  1798. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid)
  1799. {
  1800. struct i40e_mac_filter *f, *add_f;
  1801. bool is_netdev, is_vf;
  1802. is_vf = (vsi->type == I40E_VSI_SRIOV);
  1803. is_netdev = !!(vsi->netdev);
  1804. if (is_netdev) {
  1805. add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid,
  1806. is_vf, is_netdev);
  1807. if (!add_f) {
  1808. dev_info(&vsi->back->pdev->dev,
  1809. "Could not add vlan filter %d for %pM\n",
  1810. vid, vsi->netdev->dev_addr);
  1811. return -ENOMEM;
  1812. }
  1813. }
  1814. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1815. add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
  1816. if (!add_f) {
  1817. dev_info(&vsi->back->pdev->dev,
  1818. "Could not add vlan filter %d for %pM\n",
  1819. vid, f->macaddr);
  1820. return -ENOMEM;
  1821. }
  1822. }
  1823. /* Now if we add a vlan tag, make sure to check if it is the first
  1824. * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
  1825. * with 0, so we now accept untagged and specified tagged traffic
  1826. * (and not any taged and untagged)
  1827. */
  1828. if (vid > 0) {
  1829. if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr,
  1830. I40E_VLAN_ANY,
  1831. is_vf, is_netdev)) {
  1832. i40e_del_filter(vsi, vsi->netdev->dev_addr,
  1833. I40E_VLAN_ANY, is_vf, is_netdev);
  1834. add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0,
  1835. is_vf, is_netdev);
  1836. if (!add_f) {
  1837. dev_info(&vsi->back->pdev->dev,
  1838. "Could not add filter 0 for %pM\n",
  1839. vsi->netdev->dev_addr);
  1840. return -ENOMEM;
  1841. }
  1842. }
  1843. }
  1844. /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
  1845. if (vid > 0 && !vsi->info.pvid) {
  1846. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1847. if (i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  1848. is_vf, is_netdev)) {
  1849. i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  1850. is_vf, is_netdev);
  1851. add_f = i40e_add_filter(vsi, f->macaddr,
  1852. 0, is_vf, is_netdev);
  1853. if (!add_f) {
  1854. dev_info(&vsi->back->pdev->dev,
  1855. "Could not add filter 0 for %pM\n",
  1856. f->macaddr);
  1857. return -ENOMEM;
  1858. }
  1859. }
  1860. }
  1861. }
  1862. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  1863. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  1864. return 0;
  1865. return i40e_sync_vsi_filters(vsi);
  1866. }
  1867. /**
  1868. * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
  1869. * @vsi: the vsi being configured
  1870. * @vid: vlan id to be removed (0 = untagged only , -1 = any)
  1871. *
  1872. * Return: 0 on success or negative otherwise
  1873. **/
  1874. int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid)
  1875. {
  1876. struct net_device *netdev = vsi->netdev;
  1877. struct i40e_mac_filter *f, *add_f;
  1878. bool is_vf, is_netdev;
  1879. int filter_count = 0;
  1880. is_vf = (vsi->type == I40E_VSI_SRIOV);
  1881. is_netdev = !!(netdev);
  1882. if (is_netdev)
  1883. i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev);
  1884. list_for_each_entry(f, &vsi->mac_filter_list, list)
  1885. i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
  1886. /* go through all the filters for this VSI and if there is only
  1887. * vid == 0 it means there are no other filters, so vid 0 must
  1888. * be replaced with -1. This signifies that we should from now
  1889. * on accept any traffic (with any tag present, or untagged)
  1890. */
  1891. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1892. if (is_netdev) {
  1893. if (f->vlan &&
  1894. ether_addr_equal(netdev->dev_addr, f->macaddr))
  1895. filter_count++;
  1896. }
  1897. if (f->vlan)
  1898. filter_count++;
  1899. }
  1900. if (!filter_count && is_netdev) {
  1901. i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev);
  1902. f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
  1903. is_vf, is_netdev);
  1904. if (!f) {
  1905. dev_info(&vsi->back->pdev->dev,
  1906. "Could not add filter %d for %pM\n",
  1907. I40E_VLAN_ANY, netdev->dev_addr);
  1908. return -ENOMEM;
  1909. }
  1910. }
  1911. if (!filter_count) {
  1912. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1913. i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev);
  1914. add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  1915. is_vf, is_netdev);
  1916. if (!add_f) {
  1917. dev_info(&vsi->back->pdev->dev,
  1918. "Could not add filter %d for %pM\n",
  1919. I40E_VLAN_ANY, f->macaddr);
  1920. return -ENOMEM;
  1921. }
  1922. }
  1923. }
  1924. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  1925. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  1926. return 0;
  1927. return i40e_sync_vsi_filters(vsi);
  1928. }
  1929. /**
  1930. * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
  1931. * @netdev: network interface to be adjusted
  1932. * @vid: vlan id to be added
  1933. *
  1934. * net_device_ops implementation for adding vlan ids
  1935. **/
  1936. #ifdef I40E_FCOE
  1937. int i40e_vlan_rx_add_vid(struct net_device *netdev,
  1938. __always_unused __be16 proto, u16 vid)
  1939. #else
  1940. static int i40e_vlan_rx_add_vid(struct net_device *netdev,
  1941. __always_unused __be16 proto, u16 vid)
  1942. #endif
  1943. {
  1944. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1945. struct i40e_vsi *vsi = np->vsi;
  1946. int ret = 0;
  1947. if (vid > 4095)
  1948. return -EINVAL;
  1949. netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid);
  1950. /* If the network stack called us with vid = 0 then
  1951. * it is asking to receive priority tagged packets with
  1952. * vlan id 0. Our HW receives them by default when configured
  1953. * to receive untagged packets so there is no need to add an
  1954. * extra filter for vlan 0 tagged packets.
  1955. */
  1956. if (vid)
  1957. ret = i40e_vsi_add_vlan(vsi, vid);
  1958. if (!ret && (vid < VLAN_N_VID))
  1959. set_bit(vid, vsi->active_vlans);
  1960. return ret;
  1961. }
  1962. /**
  1963. * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
  1964. * @netdev: network interface to be adjusted
  1965. * @vid: vlan id to be removed
  1966. *
  1967. * net_device_ops implementation for removing vlan ids
  1968. **/
  1969. #ifdef I40E_FCOE
  1970. int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  1971. __always_unused __be16 proto, u16 vid)
  1972. #else
  1973. static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  1974. __always_unused __be16 proto, u16 vid)
  1975. #endif
  1976. {
  1977. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1978. struct i40e_vsi *vsi = np->vsi;
  1979. netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid);
  1980. /* return code is ignored as there is nothing a user
  1981. * can do about failure to remove and a log message was
  1982. * already printed from the other function
  1983. */
  1984. i40e_vsi_kill_vlan(vsi, vid);
  1985. clear_bit(vid, vsi->active_vlans);
  1986. return 0;
  1987. }
  1988. /**
  1989. * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
  1990. * @vsi: the vsi being brought back up
  1991. **/
  1992. static void i40e_restore_vlan(struct i40e_vsi *vsi)
  1993. {
  1994. u16 vid;
  1995. if (!vsi->netdev)
  1996. return;
  1997. i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
  1998. for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
  1999. i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
  2000. vid);
  2001. }
  2002. /**
  2003. * i40e_vsi_add_pvid - Add pvid for the VSI
  2004. * @vsi: the vsi being adjusted
  2005. * @vid: the vlan id to set as a PVID
  2006. **/
  2007. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
  2008. {
  2009. struct i40e_vsi_context ctxt;
  2010. i40e_status aq_ret;
  2011. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2012. vsi->info.pvid = cpu_to_le16(vid);
  2013. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
  2014. I40E_AQ_VSI_PVLAN_INSERT_PVID |
  2015. I40E_AQ_VSI_PVLAN_EMOD_STR;
  2016. ctxt.seid = vsi->seid;
  2017. memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
  2018. aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2019. if (aq_ret) {
  2020. dev_info(&vsi->back->pdev->dev,
  2021. "%s: update vsi failed, aq_err=%d\n",
  2022. __func__, vsi->back->hw.aq.asq_last_status);
  2023. return -ENOENT;
  2024. }
  2025. return 0;
  2026. }
  2027. /**
  2028. * i40e_vsi_remove_pvid - Remove the pvid from the VSI
  2029. * @vsi: the vsi being adjusted
  2030. *
  2031. * Just use the vlan_rx_register() service to put it back to normal
  2032. **/
  2033. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
  2034. {
  2035. i40e_vlan_stripping_disable(vsi);
  2036. vsi->info.pvid = 0;
  2037. }
  2038. /**
  2039. * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
  2040. * @vsi: ptr to the VSI
  2041. *
  2042. * If this function returns with an error, then it's possible one or
  2043. * more of the rings is populated (while the rest are not). It is the
  2044. * callers duty to clean those orphaned rings.
  2045. *
  2046. * Return 0 on success, negative on failure
  2047. **/
  2048. static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
  2049. {
  2050. int i, err = 0;
  2051. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2052. err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
  2053. return err;
  2054. }
  2055. /**
  2056. * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
  2057. * @vsi: ptr to the VSI
  2058. *
  2059. * Free VSI's transmit software resources
  2060. **/
  2061. static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
  2062. {
  2063. int i;
  2064. if (!vsi->tx_rings)
  2065. return;
  2066. for (i = 0; i < vsi->num_queue_pairs; i++)
  2067. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
  2068. i40e_free_tx_resources(vsi->tx_rings[i]);
  2069. }
  2070. /**
  2071. * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
  2072. * @vsi: ptr to the VSI
  2073. *
  2074. * If this function returns with an error, then it's possible one or
  2075. * more of the rings is populated (while the rest are not). It is the
  2076. * callers duty to clean those orphaned rings.
  2077. *
  2078. * Return 0 on success, negative on failure
  2079. **/
  2080. static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
  2081. {
  2082. int i, err = 0;
  2083. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2084. err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
  2085. #ifdef I40E_FCOE
  2086. i40e_fcoe_setup_ddp_resources(vsi);
  2087. #endif
  2088. return err;
  2089. }
  2090. /**
  2091. * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
  2092. * @vsi: ptr to the VSI
  2093. *
  2094. * Free all receive software resources
  2095. **/
  2096. static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
  2097. {
  2098. int i;
  2099. if (!vsi->rx_rings)
  2100. return;
  2101. for (i = 0; i < vsi->num_queue_pairs; i++)
  2102. if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
  2103. i40e_free_rx_resources(vsi->rx_rings[i]);
  2104. #ifdef I40E_FCOE
  2105. i40e_fcoe_free_ddp_resources(vsi);
  2106. #endif
  2107. }
  2108. /**
  2109. * i40e_configure_tx_ring - Configure a transmit ring context and rest
  2110. * @ring: The Tx ring to configure
  2111. *
  2112. * Configure the Tx descriptor ring in the HMC context.
  2113. **/
  2114. static int i40e_configure_tx_ring(struct i40e_ring *ring)
  2115. {
  2116. struct i40e_vsi *vsi = ring->vsi;
  2117. u16 pf_q = vsi->base_queue + ring->queue_index;
  2118. struct i40e_hw *hw = &vsi->back->hw;
  2119. struct i40e_hmc_obj_txq tx_ctx;
  2120. i40e_status err = 0;
  2121. u32 qtx_ctl = 0;
  2122. /* some ATR related tx ring init */
  2123. if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
  2124. ring->atr_sample_rate = vsi->back->atr_sample_rate;
  2125. ring->atr_count = 0;
  2126. } else {
  2127. ring->atr_sample_rate = 0;
  2128. }
  2129. /* initialize XPS */
  2130. if (ring->q_vector && ring->netdev &&
  2131. vsi->tc_config.numtc <= 1 &&
  2132. !test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
  2133. netif_set_xps_queue(ring->netdev,
  2134. &ring->q_vector->affinity_mask,
  2135. ring->queue_index);
  2136. /* clear the context structure first */
  2137. memset(&tx_ctx, 0, sizeof(tx_ctx));
  2138. tx_ctx.new_context = 1;
  2139. tx_ctx.base = (ring->dma / 128);
  2140. tx_ctx.qlen = ring->count;
  2141. tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
  2142. I40E_FLAG_FD_ATR_ENABLED));
  2143. #ifdef I40E_FCOE
  2144. tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
  2145. #endif
  2146. tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
  2147. /* FDIR VSI tx ring can still use RS bit and writebacks */
  2148. if (vsi->type != I40E_VSI_FDIR)
  2149. tx_ctx.head_wb_ena = 1;
  2150. tx_ctx.head_wb_addr = ring->dma +
  2151. (ring->count * sizeof(struct i40e_tx_desc));
  2152. /* As part of VSI creation/update, FW allocates certain
  2153. * Tx arbitration queue sets for each TC enabled for
  2154. * the VSI. The FW returns the handles to these queue
  2155. * sets as part of the response buffer to Add VSI,
  2156. * Update VSI, etc. AQ commands. It is expected that
  2157. * these queue set handles be associated with the Tx
  2158. * queues by the driver as part of the TX queue context
  2159. * initialization. This has to be done regardless of
  2160. * DCB as by default everything is mapped to TC0.
  2161. */
  2162. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
  2163. tx_ctx.rdylist_act = 0;
  2164. /* clear the context in the HMC */
  2165. err = i40e_clear_lan_tx_queue_context(hw, pf_q);
  2166. if (err) {
  2167. dev_info(&vsi->back->pdev->dev,
  2168. "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
  2169. ring->queue_index, pf_q, err);
  2170. return -ENOMEM;
  2171. }
  2172. /* set the context in the HMC */
  2173. err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
  2174. if (err) {
  2175. dev_info(&vsi->back->pdev->dev,
  2176. "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
  2177. ring->queue_index, pf_q, err);
  2178. return -ENOMEM;
  2179. }
  2180. /* Now associate this queue with this PCI function */
  2181. if (vsi->type == I40E_VSI_VMDQ2)
  2182. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2183. else
  2184. qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
  2185. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
  2186. I40E_QTX_CTL_PF_INDX_MASK);
  2187. wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
  2188. i40e_flush(hw);
  2189. clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state);
  2190. /* cache tail off for easier writes later */
  2191. ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
  2192. return 0;
  2193. }
  2194. /**
  2195. * i40e_configure_rx_ring - Configure a receive ring context
  2196. * @ring: The Rx ring to configure
  2197. *
  2198. * Configure the Rx descriptor ring in the HMC context.
  2199. **/
  2200. static int i40e_configure_rx_ring(struct i40e_ring *ring)
  2201. {
  2202. struct i40e_vsi *vsi = ring->vsi;
  2203. u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
  2204. u16 pf_q = vsi->base_queue + ring->queue_index;
  2205. struct i40e_hw *hw = &vsi->back->hw;
  2206. struct i40e_hmc_obj_rxq rx_ctx;
  2207. i40e_status err = 0;
  2208. ring->state = 0;
  2209. /* clear the context structure first */
  2210. memset(&rx_ctx, 0, sizeof(rx_ctx));
  2211. ring->rx_buf_len = vsi->rx_buf_len;
  2212. ring->rx_hdr_len = vsi->rx_hdr_len;
  2213. rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
  2214. rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
  2215. rx_ctx.base = (ring->dma / 128);
  2216. rx_ctx.qlen = ring->count;
  2217. if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) {
  2218. set_ring_16byte_desc_enabled(ring);
  2219. rx_ctx.dsize = 0;
  2220. } else {
  2221. rx_ctx.dsize = 1;
  2222. }
  2223. rx_ctx.dtype = vsi->dtype;
  2224. if (vsi->dtype) {
  2225. set_ring_ps_enabled(ring);
  2226. rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
  2227. I40E_RX_SPLIT_IP |
  2228. I40E_RX_SPLIT_TCP_UDP |
  2229. I40E_RX_SPLIT_SCTP;
  2230. } else {
  2231. rx_ctx.hsplit_0 = 0;
  2232. }
  2233. rx_ctx.rxmax = min_t(u16, vsi->max_frame,
  2234. (chain_len * ring->rx_buf_len));
  2235. if (hw->revision_id == 0)
  2236. rx_ctx.lrxqthresh = 0;
  2237. else
  2238. rx_ctx.lrxqthresh = 2;
  2239. rx_ctx.crcstrip = 1;
  2240. rx_ctx.l2tsel = 1;
  2241. rx_ctx.showiv = 1;
  2242. #ifdef I40E_FCOE
  2243. rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
  2244. #endif
  2245. /* set the prefena field to 1 because the manual says to */
  2246. rx_ctx.prefena = 1;
  2247. /* clear the context in the HMC */
  2248. err = i40e_clear_lan_rx_queue_context(hw, pf_q);
  2249. if (err) {
  2250. dev_info(&vsi->back->pdev->dev,
  2251. "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2252. ring->queue_index, pf_q, err);
  2253. return -ENOMEM;
  2254. }
  2255. /* set the context in the HMC */
  2256. err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
  2257. if (err) {
  2258. dev_info(&vsi->back->pdev->dev,
  2259. "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2260. ring->queue_index, pf_q, err);
  2261. return -ENOMEM;
  2262. }
  2263. /* cache tail for quicker writes, and clear the reg before use */
  2264. ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
  2265. writel(0, ring->tail);
  2266. i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
  2267. return 0;
  2268. }
  2269. /**
  2270. * i40e_vsi_configure_tx - Configure the VSI for Tx
  2271. * @vsi: VSI structure describing this set of rings and resources
  2272. *
  2273. * Configure the Tx VSI for operation.
  2274. **/
  2275. static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
  2276. {
  2277. int err = 0;
  2278. u16 i;
  2279. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2280. err = i40e_configure_tx_ring(vsi->tx_rings[i]);
  2281. return err;
  2282. }
  2283. /**
  2284. * i40e_vsi_configure_rx - Configure the VSI for Rx
  2285. * @vsi: the VSI being configured
  2286. *
  2287. * Configure the Rx VSI for operation.
  2288. **/
  2289. static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
  2290. {
  2291. int err = 0;
  2292. u16 i;
  2293. if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
  2294. vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
  2295. + ETH_FCS_LEN + VLAN_HLEN;
  2296. else
  2297. vsi->max_frame = I40E_RXBUFFER_2048;
  2298. /* figure out correct receive buffer length */
  2299. switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED |
  2300. I40E_FLAG_RX_PS_ENABLED)) {
  2301. case I40E_FLAG_RX_1BUF_ENABLED:
  2302. vsi->rx_hdr_len = 0;
  2303. vsi->rx_buf_len = vsi->max_frame;
  2304. vsi->dtype = I40E_RX_DTYPE_NO_SPLIT;
  2305. break;
  2306. case I40E_FLAG_RX_PS_ENABLED:
  2307. vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
  2308. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2309. vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT;
  2310. break;
  2311. default:
  2312. vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
  2313. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2314. vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS;
  2315. break;
  2316. }
  2317. #ifdef I40E_FCOE
  2318. /* setup rx buffer for FCoE */
  2319. if ((vsi->type == I40E_VSI_FCOE) &&
  2320. (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) {
  2321. vsi->rx_hdr_len = 0;
  2322. vsi->rx_buf_len = I40E_RXBUFFER_3072;
  2323. vsi->max_frame = I40E_RXBUFFER_3072;
  2324. vsi->dtype = I40E_RX_DTYPE_NO_SPLIT;
  2325. }
  2326. #endif /* I40E_FCOE */
  2327. /* round up for the chip's needs */
  2328. vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len,
  2329. (1 << I40E_RXQ_CTX_HBUFF_SHIFT));
  2330. vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
  2331. (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
  2332. /* set up individual rings */
  2333. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2334. err = i40e_configure_rx_ring(vsi->rx_rings[i]);
  2335. return err;
  2336. }
  2337. /**
  2338. * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
  2339. * @vsi: ptr to the VSI
  2340. **/
  2341. static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
  2342. {
  2343. struct i40e_ring *tx_ring, *rx_ring;
  2344. u16 qoffset, qcount;
  2345. int i, n;
  2346. if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED))
  2347. return;
  2348. for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
  2349. if (!(vsi->tc_config.enabled_tc & (1 << n)))
  2350. continue;
  2351. qoffset = vsi->tc_config.tc_info[n].qoffset;
  2352. qcount = vsi->tc_config.tc_info[n].qcount;
  2353. for (i = qoffset; i < (qoffset + qcount); i++) {
  2354. rx_ring = vsi->rx_rings[i];
  2355. tx_ring = vsi->tx_rings[i];
  2356. rx_ring->dcb_tc = n;
  2357. tx_ring->dcb_tc = n;
  2358. }
  2359. }
  2360. }
  2361. /**
  2362. * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
  2363. * @vsi: ptr to the VSI
  2364. **/
  2365. static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
  2366. {
  2367. if (vsi->netdev)
  2368. i40e_set_rx_mode(vsi->netdev);
  2369. }
  2370. /**
  2371. * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
  2372. * @vsi: Pointer to the targeted VSI
  2373. *
  2374. * This function replays the hlist on the hw where all the SB Flow Director
  2375. * filters were saved.
  2376. **/
  2377. static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
  2378. {
  2379. struct i40e_fdir_filter *filter;
  2380. struct i40e_pf *pf = vsi->back;
  2381. struct hlist_node *node;
  2382. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  2383. return;
  2384. hlist_for_each_entry_safe(filter, node,
  2385. &pf->fdir_filter_list, fdir_node) {
  2386. i40e_add_del_fdir(vsi, filter, true);
  2387. }
  2388. }
  2389. /**
  2390. * i40e_vsi_configure - Set up the VSI for action
  2391. * @vsi: the VSI being configured
  2392. **/
  2393. static int i40e_vsi_configure(struct i40e_vsi *vsi)
  2394. {
  2395. int err;
  2396. i40e_set_vsi_rx_mode(vsi);
  2397. i40e_restore_vlan(vsi);
  2398. i40e_vsi_config_dcb_rings(vsi);
  2399. err = i40e_vsi_configure_tx(vsi);
  2400. if (!err)
  2401. err = i40e_vsi_configure_rx(vsi);
  2402. return err;
  2403. }
  2404. /**
  2405. * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
  2406. * @vsi: the VSI being configured
  2407. **/
  2408. static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
  2409. {
  2410. struct i40e_pf *pf = vsi->back;
  2411. struct i40e_q_vector *q_vector;
  2412. struct i40e_hw *hw = &pf->hw;
  2413. u16 vector;
  2414. int i, q;
  2415. u32 val;
  2416. u32 qp;
  2417. /* The interrupt indexing is offset by 1 in the PFINT_ITRn
  2418. * and PFINT_LNKLSTn registers, e.g.:
  2419. * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
  2420. */
  2421. qp = vsi->base_queue;
  2422. vector = vsi->base_vector;
  2423. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  2424. q_vector = vsi->q_vectors[i];
  2425. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  2426. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2427. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
  2428. q_vector->rx.itr);
  2429. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  2430. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2431. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
  2432. q_vector->tx.itr);
  2433. /* Linked list for the queuepairs assigned to this vector */
  2434. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
  2435. for (q = 0; q < q_vector->num_ringpairs; q++) {
  2436. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2437. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2438. (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
  2439. (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
  2440. (I40E_QUEUE_TYPE_TX
  2441. << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
  2442. wr32(hw, I40E_QINT_RQCTL(qp), val);
  2443. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2444. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  2445. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  2446. ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
  2447. (I40E_QUEUE_TYPE_RX
  2448. << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2449. /* Terminate the linked list */
  2450. if (q == (q_vector->num_ringpairs - 1))
  2451. val |= (I40E_QUEUE_END_OF_LIST
  2452. << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  2453. wr32(hw, I40E_QINT_TQCTL(qp), val);
  2454. qp++;
  2455. }
  2456. }
  2457. i40e_flush(hw);
  2458. }
  2459. /**
  2460. * i40e_enable_misc_int_causes - enable the non-queue interrupts
  2461. * @hw: ptr to the hardware info
  2462. **/
  2463. static void i40e_enable_misc_int_causes(struct i40e_hw *hw)
  2464. {
  2465. u32 val;
  2466. /* clear things first */
  2467. wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
  2468. rd32(hw, I40E_PFINT_ICR0); /* read to clear */
  2469. val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
  2470. I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
  2471. I40E_PFINT_ICR0_ENA_GRST_MASK |
  2472. I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
  2473. I40E_PFINT_ICR0_ENA_GPIO_MASK |
  2474. I40E_PFINT_ICR0_ENA_TIMESYNC_MASK |
  2475. I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
  2476. I40E_PFINT_ICR0_ENA_VFLR_MASK |
  2477. I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  2478. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  2479. /* SW_ITR_IDX = 0, but don't change INTENA */
  2480. wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
  2481. I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
  2482. /* OTHER_ITR_IDX = 0 */
  2483. wr32(hw, I40E_PFINT_STAT_CTL0, 0);
  2484. }
  2485. /**
  2486. * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
  2487. * @vsi: the VSI being configured
  2488. **/
  2489. static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
  2490. {
  2491. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  2492. struct i40e_pf *pf = vsi->back;
  2493. struct i40e_hw *hw = &pf->hw;
  2494. u32 val;
  2495. /* set the ITR configuration */
  2496. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  2497. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2498. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
  2499. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  2500. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2501. wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
  2502. i40e_enable_misc_int_causes(hw);
  2503. /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
  2504. wr32(hw, I40E_PFINT_LNKLST0, 0);
  2505. /* Associate the queue pair to the vector and enable the queue int */
  2506. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2507. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2508. (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2509. wr32(hw, I40E_QINT_RQCTL(0), val);
  2510. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2511. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  2512. (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  2513. wr32(hw, I40E_QINT_TQCTL(0), val);
  2514. i40e_flush(hw);
  2515. }
  2516. /**
  2517. * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
  2518. * @pf: board private structure
  2519. **/
  2520. void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
  2521. {
  2522. struct i40e_hw *hw = &pf->hw;
  2523. wr32(hw, I40E_PFINT_DYN_CTL0,
  2524. I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  2525. i40e_flush(hw);
  2526. }
  2527. /**
  2528. * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
  2529. * @pf: board private structure
  2530. **/
  2531. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
  2532. {
  2533. struct i40e_hw *hw = &pf->hw;
  2534. u32 val;
  2535. val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
  2536. I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
  2537. (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
  2538. wr32(hw, I40E_PFINT_DYN_CTL0, val);
  2539. i40e_flush(hw);
  2540. }
  2541. /**
  2542. * i40e_irq_dynamic_enable - Enable default interrupt generation settings
  2543. * @vsi: pointer to a vsi
  2544. * @vector: enable a particular Hw Interrupt vector
  2545. **/
  2546. void i40e_irq_dynamic_enable(struct i40e_vsi *vsi, int vector)
  2547. {
  2548. struct i40e_pf *pf = vsi->back;
  2549. struct i40e_hw *hw = &pf->hw;
  2550. u32 val;
  2551. val = I40E_PFINT_DYN_CTLN_INTENA_MASK |
  2552. I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
  2553. (I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  2554. wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val);
  2555. /* skip the flush */
  2556. }
  2557. /**
  2558. * i40e_irq_dynamic_disable - Disable default interrupt generation settings
  2559. * @vsi: pointer to a vsi
  2560. * @vector: enable a particular Hw Interrupt vector
  2561. **/
  2562. void i40e_irq_dynamic_disable(struct i40e_vsi *vsi, int vector)
  2563. {
  2564. struct i40e_pf *pf = vsi->back;
  2565. struct i40e_hw *hw = &pf->hw;
  2566. u32 val;
  2567. val = I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
  2568. wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val);
  2569. i40e_flush(hw);
  2570. }
  2571. /**
  2572. * i40e_msix_clean_rings - MSIX mode Interrupt Handler
  2573. * @irq: interrupt number
  2574. * @data: pointer to a q_vector
  2575. **/
  2576. static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
  2577. {
  2578. struct i40e_q_vector *q_vector = data;
  2579. if (!q_vector->tx.ring && !q_vector->rx.ring)
  2580. return IRQ_HANDLED;
  2581. napi_schedule(&q_vector->napi);
  2582. return IRQ_HANDLED;
  2583. }
  2584. /**
  2585. * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
  2586. * @vsi: the VSI being configured
  2587. * @basename: name for the vector
  2588. *
  2589. * Allocates MSI-X vectors and requests interrupts from the kernel.
  2590. **/
  2591. static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
  2592. {
  2593. int q_vectors = vsi->num_q_vectors;
  2594. struct i40e_pf *pf = vsi->back;
  2595. int base = vsi->base_vector;
  2596. int rx_int_idx = 0;
  2597. int tx_int_idx = 0;
  2598. int vector, err;
  2599. for (vector = 0; vector < q_vectors; vector++) {
  2600. struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
  2601. if (q_vector->tx.ring && q_vector->rx.ring) {
  2602. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2603. "%s-%s-%d", basename, "TxRx", rx_int_idx++);
  2604. tx_int_idx++;
  2605. } else if (q_vector->rx.ring) {
  2606. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2607. "%s-%s-%d", basename, "rx", rx_int_idx++);
  2608. } else if (q_vector->tx.ring) {
  2609. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2610. "%s-%s-%d", basename, "tx", tx_int_idx++);
  2611. } else {
  2612. /* skip this unused q_vector */
  2613. continue;
  2614. }
  2615. err = request_irq(pf->msix_entries[base + vector].vector,
  2616. vsi->irq_handler,
  2617. 0,
  2618. q_vector->name,
  2619. q_vector);
  2620. if (err) {
  2621. dev_info(&pf->pdev->dev,
  2622. "%s: request_irq failed, error: %d\n",
  2623. __func__, err);
  2624. goto free_queue_irqs;
  2625. }
  2626. /* assign the mask for this irq */
  2627. irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
  2628. &q_vector->affinity_mask);
  2629. }
  2630. vsi->irqs_ready = true;
  2631. return 0;
  2632. free_queue_irqs:
  2633. while (vector) {
  2634. vector--;
  2635. irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
  2636. NULL);
  2637. free_irq(pf->msix_entries[base + vector].vector,
  2638. &(vsi->q_vectors[vector]));
  2639. }
  2640. return err;
  2641. }
  2642. /**
  2643. * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
  2644. * @vsi: the VSI being un-configured
  2645. **/
  2646. static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
  2647. {
  2648. struct i40e_pf *pf = vsi->back;
  2649. struct i40e_hw *hw = &pf->hw;
  2650. int base = vsi->base_vector;
  2651. int i;
  2652. for (i = 0; i < vsi->num_queue_pairs; i++) {
  2653. wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
  2654. wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
  2655. }
  2656. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2657. for (i = vsi->base_vector;
  2658. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  2659. wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
  2660. i40e_flush(hw);
  2661. for (i = 0; i < vsi->num_q_vectors; i++)
  2662. synchronize_irq(pf->msix_entries[i + base].vector);
  2663. } else {
  2664. /* Legacy and MSI mode - this stops all interrupt handling */
  2665. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  2666. wr32(hw, I40E_PFINT_DYN_CTL0, 0);
  2667. i40e_flush(hw);
  2668. synchronize_irq(pf->pdev->irq);
  2669. }
  2670. }
  2671. /**
  2672. * i40e_vsi_enable_irq - Enable IRQ for the given VSI
  2673. * @vsi: the VSI being configured
  2674. **/
  2675. static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
  2676. {
  2677. struct i40e_pf *pf = vsi->back;
  2678. int i;
  2679. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2680. for (i = vsi->base_vector;
  2681. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  2682. i40e_irq_dynamic_enable(vsi, i);
  2683. } else {
  2684. i40e_irq_dynamic_enable_icr0(pf);
  2685. }
  2686. i40e_flush(&pf->hw);
  2687. return 0;
  2688. }
  2689. /**
  2690. * i40e_stop_misc_vector - Stop the vector that handles non-queue events
  2691. * @pf: board private structure
  2692. **/
  2693. static void i40e_stop_misc_vector(struct i40e_pf *pf)
  2694. {
  2695. /* Disable ICR 0 */
  2696. wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
  2697. i40e_flush(&pf->hw);
  2698. }
  2699. /**
  2700. * i40e_intr - MSI/Legacy and non-queue interrupt handler
  2701. * @irq: interrupt number
  2702. * @data: pointer to a q_vector
  2703. *
  2704. * This is the handler used for all MSI/Legacy interrupts, and deals
  2705. * with both queue and non-queue interrupts. This is also used in
  2706. * MSIX mode to handle the non-queue interrupts.
  2707. **/
  2708. static irqreturn_t i40e_intr(int irq, void *data)
  2709. {
  2710. struct i40e_pf *pf = (struct i40e_pf *)data;
  2711. struct i40e_hw *hw = &pf->hw;
  2712. irqreturn_t ret = IRQ_NONE;
  2713. u32 icr0, icr0_remaining;
  2714. u32 val, ena_mask;
  2715. icr0 = rd32(hw, I40E_PFINT_ICR0);
  2716. ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
  2717. /* if sharing a legacy IRQ, we might get called w/o an intr pending */
  2718. if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
  2719. goto enable_intr;
  2720. /* if interrupt but no bits showing, must be SWINT */
  2721. if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
  2722. (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
  2723. pf->sw_int_count++;
  2724. /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
  2725. if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
  2726. /* temporarily disable queue cause for NAPI processing */
  2727. u32 qval = rd32(hw, I40E_QINT_RQCTL(0));
  2728. qval &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
  2729. wr32(hw, I40E_QINT_RQCTL(0), qval);
  2730. qval = rd32(hw, I40E_QINT_TQCTL(0));
  2731. qval &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
  2732. wr32(hw, I40E_QINT_TQCTL(0), qval);
  2733. if (!test_bit(__I40E_DOWN, &pf->state))
  2734. napi_schedule(&pf->vsi[pf->lan_vsi]->q_vectors[0]->napi);
  2735. }
  2736. if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
  2737. ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  2738. set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  2739. }
  2740. if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
  2741. ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  2742. set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  2743. }
  2744. if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
  2745. ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
  2746. set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
  2747. }
  2748. if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
  2749. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  2750. set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  2751. ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
  2752. val = rd32(hw, I40E_GLGEN_RSTAT);
  2753. val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
  2754. >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
  2755. if (val == I40E_RESET_CORER) {
  2756. pf->corer_count++;
  2757. } else if (val == I40E_RESET_GLOBR) {
  2758. pf->globr_count++;
  2759. } else if (val == I40E_RESET_EMPR) {
  2760. pf->empr_count++;
  2761. set_bit(__I40E_EMP_RESET_REQUESTED, &pf->state);
  2762. }
  2763. }
  2764. if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
  2765. icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
  2766. dev_info(&pf->pdev->dev, "HMC error interrupt\n");
  2767. }
  2768. if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
  2769. u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
  2770. if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
  2771. icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  2772. i40e_ptp_tx_hwtstamp(pf);
  2773. }
  2774. }
  2775. /* If a critical error is pending we have no choice but to reset the
  2776. * device.
  2777. * Report and mask out any remaining unexpected interrupts.
  2778. */
  2779. icr0_remaining = icr0 & ena_mask;
  2780. if (icr0_remaining) {
  2781. dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
  2782. icr0_remaining);
  2783. if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
  2784. (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
  2785. (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
  2786. dev_info(&pf->pdev->dev, "device will be reset\n");
  2787. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  2788. i40e_service_event_schedule(pf);
  2789. }
  2790. ena_mask &= ~icr0_remaining;
  2791. }
  2792. ret = IRQ_HANDLED;
  2793. enable_intr:
  2794. /* re-enable interrupt causes */
  2795. wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
  2796. if (!test_bit(__I40E_DOWN, &pf->state)) {
  2797. i40e_service_event_schedule(pf);
  2798. i40e_irq_dynamic_enable_icr0(pf);
  2799. }
  2800. return ret;
  2801. }
  2802. /**
  2803. * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
  2804. * @tx_ring: tx ring to clean
  2805. * @budget: how many cleans we're allowed
  2806. *
  2807. * Returns true if there's any budget left (e.g. the clean is finished)
  2808. **/
  2809. static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
  2810. {
  2811. struct i40e_vsi *vsi = tx_ring->vsi;
  2812. u16 i = tx_ring->next_to_clean;
  2813. struct i40e_tx_buffer *tx_buf;
  2814. struct i40e_tx_desc *tx_desc;
  2815. tx_buf = &tx_ring->tx_bi[i];
  2816. tx_desc = I40E_TX_DESC(tx_ring, i);
  2817. i -= tx_ring->count;
  2818. do {
  2819. struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
  2820. /* if next_to_watch is not set then there is no work pending */
  2821. if (!eop_desc)
  2822. break;
  2823. /* prevent any other reads prior to eop_desc */
  2824. read_barrier_depends();
  2825. /* if the descriptor isn't done, no work yet to do */
  2826. if (!(eop_desc->cmd_type_offset_bsz &
  2827. cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
  2828. break;
  2829. /* clear next_to_watch to prevent false hangs */
  2830. tx_buf->next_to_watch = NULL;
  2831. tx_desc->buffer_addr = 0;
  2832. tx_desc->cmd_type_offset_bsz = 0;
  2833. /* move past filter desc */
  2834. tx_buf++;
  2835. tx_desc++;
  2836. i++;
  2837. if (unlikely(!i)) {
  2838. i -= tx_ring->count;
  2839. tx_buf = tx_ring->tx_bi;
  2840. tx_desc = I40E_TX_DESC(tx_ring, 0);
  2841. }
  2842. /* unmap skb header data */
  2843. dma_unmap_single(tx_ring->dev,
  2844. dma_unmap_addr(tx_buf, dma),
  2845. dma_unmap_len(tx_buf, len),
  2846. DMA_TO_DEVICE);
  2847. if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
  2848. kfree(tx_buf->raw_buf);
  2849. tx_buf->raw_buf = NULL;
  2850. tx_buf->tx_flags = 0;
  2851. tx_buf->next_to_watch = NULL;
  2852. dma_unmap_len_set(tx_buf, len, 0);
  2853. tx_desc->buffer_addr = 0;
  2854. tx_desc->cmd_type_offset_bsz = 0;
  2855. /* move us past the eop_desc for start of next FD desc */
  2856. tx_buf++;
  2857. tx_desc++;
  2858. i++;
  2859. if (unlikely(!i)) {
  2860. i -= tx_ring->count;
  2861. tx_buf = tx_ring->tx_bi;
  2862. tx_desc = I40E_TX_DESC(tx_ring, 0);
  2863. }
  2864. /* update budget accounting */
  2865. budget--;
  2866. } while (likely(budget));
  2867. i += tx_ring->count;
  2868. tx_ring->next_to_clean = i;
  2869. if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) {
  2870. i40e_irq_dynamic_enable(vsi,
  2871. tx_ring->q_vector->v_idx + vsi->base_vector);
  2872. }
  2873. return budget > 0;
  2874. }
  2875. /**
  2876. * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
  2877. * @irq: interrupt number
  2878. * @data: pointer to a q_vector
  2879. **/
  2880. static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
  2881. {
  2882. struct i40e_q_vector *q_vector = data;
  2883. struct i40e_vsi *vsi;
  2884. if (!q_vector->tx.ring)
  2885. return IRQ_HANDLED;
  2886. vsi = q_vector->tx.ring->vsi;
  2887. i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
  2888. return IRQ_HANDLED;
  2889. }
  2890. /**
  2891. * i40e_map_vector_to_qp - Assigns the queue pair to the vector
  2892. * @vsi: the VSI being configured
  2893. * @v_idx: vector index
  2894. * @qp_idx: queue pair index
  2895. **/
  2896. static void map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
  2897. {
  2898. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  2899. struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
  2900. struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
  2901. tx_ring->q_vector = q_vector;
  2902. tx_ring->next = q_vector->tx.ring;
  2903. q_vector->tx.ring = tx_ring;
  2904. q_vector->tx.count++;
  2905. rx_ring->q_vector = q_vector;
  2906. rx_ring->next = q_vector->rx.ring;
  2907. q_vector->rx.ring = rx_ring;
  2908. q_vector->rx.count++;
  2909. }
  2910. /**
  2911. * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
  2912. * @vsi: the VSI being configured
  2913. *
  2914. * This function maps descriptor rings to the queue-specific vectors
  2915. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  2916. * one vector per queue pair, but on a constrained vector budget, we
  2917. * group the queue pairs as "efficiently" as possible.
  2918. **/
  2919. static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
  2920. {
  2921. int qp_remaining = vsi->num_queue_pairs;
  2922. int q_vectors = vsi->num_q_vectors;
  2923. int num_ringpairs;
  2924. int v_start = 0;
  2925. int qp_idx = 0;
  2926. /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
  2927. * group them so there are multiple queues per vector.
  2928. * It is also important to go through all the vectors available to be
  2929. * sure that if we don't use all the vectors, that the remaining vectors
  2930. * are cleared. This is especially important when decreasing the
  2931. * number of queues in use.
  2932. */
  2933. for (; v_start < q_vectors; v_start++) {
  2934. struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
  2935. num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
  2936. q_vector->num_ringpairs = num_ringpairs;
  2937. q_vector->rx.count = 0;
  2938. q_vector->tx.count = 0;
  2939. q_vector->rx.ring = NULL;
  2940. q_vector->tx.ring = NULL;
  2941. while (num_ringpairs--) {
  2942. map_vector_to_qp(vsi, v_start, qp_idx);
  2943. qp_idx++;
  2944. qp_remaining--;
  2945. }
  2946. }
  2947. }
  2948. /**
  2949. * i40e_vsi_request_irq - Request IRQ from the OS
  2950. * @vsi: the VSI being configured
  2951. * @basename: name for the vector
  2952. **/
  2953. static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
  2954. {
  2955. struct i40e_pf *pf = vsi->back;
  2956. int err;
  2957. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  2958. err = i40e_vsi_request_irq_msix(vsi, basename);
  2959. else if (pf->flags & I40E_FLAG_MSI_ENABLED)
  2960. err = request_irq(pf->pdev->irq, i40e_intr, 0,
  2961. pf->misc_int_name, pf);
  2962. else
  2963. err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
  2964. pf->misc_int_name, pf);
  2965. if (err)
  2966. dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
  2967. return err;
  2968. }
  2969. #ifdef CONFIG_NET_POLL_CONTROLLER
  2970. /**
  2971. * i40e_netpoll - A Polling 'interrupt'handler
  2972. * @netdev: network interface device structure
  2973. *
  2974. * This is used by netconsole to send skbs without having to re-enable
  2975. * interrupts. It's not called while the normal interrupt routine is executing.
  2976. **/
  2977. #ifdef I40E_FCOE
  2978. void i40e_netpoll(struct net_device *netdev)
  2979. #else
  2980. static void i40e_netpoll(struct net_device *netdev)
  2981. #endif
  2982. {
  2983. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2984. struct i40e_vsi *vsi = np->vsi;
  2985. struct i40e_pf *pf = vsi->back;
  2986. int i;
  2987. /* if interface is down do nothing */
  2988. if (test_bit(__I40E_DOWN, &vsi->state))
  2989. return;
  2990. pf->flags |= I40E_FLAG_IN_NETPOLL;
  2991. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2992. for (i = 0; i < vsi->num_q_vectors; i++)
  2993. i40e_msix_clean_rings(0, vsi->q_vectors[i]);
  2994. } else {
  2995. i40e_intr(pf->pdev->irq, netdev);
  2996. }
  2997. pf->flags &= ~I40E_FLAG_IN_NETPOLL;
  2998. }
  2999. #endif
  3000. /**
  3001. * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
  3002. * @pf: the PF being configured
  3003. * @pf_q: the PF queue
  3004. * @enable: enable or disable state of the queue
  3005. *
  3006. * This routine will wait for the given Tx queue of the PF to reach the
  3007. * enabled or disabled state.
  3008. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3009. * multiple retries; else will return 0 in case of success.
  3010. **/
  3011. static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3012. {
  3013. int i;
  3014. u32 tx_reg;
  3015. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3016. tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
  3017. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3018. break;
  3019. udelay(10);
  3020. }
  3021. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3022. return -ETIMEDOUT;
  3023. return 0;
  3024. }
  3025. /**
  3026. * i40e_vsi_control_tx - Start or stop a VSI's rings
  3027. * @vsi: the VSI being configured
  3028. * @enable: start or stop the rings
  3029. **/
  3030. static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
  3031. {
  3032. struct i40e_pf *pf = vsi->back;
  3033. struct i40e_hw *hw = &pf->hw;
  3034. int i, j, pf_q, ret = 0;
  3035. u32 tx_reg;
  3036. pf_q = vsi->base_queue;
  3037. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3038. /* warn the TX unit of coming changes */
  3039. i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
  3040. if (!enable)
  3041. udelay(10);
  3042. for (j = 0; j < 50; j++) {
  3043. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  3044. if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
  3045. ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
  3046. break;
  3047. usleep_range(1000, 2000);
  3048. }
  3049. /* Skip if the queue is already in the requested state */
  3050. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3051. continue;
  3052. /* turn on/off the queue */
  3053. if (enable) {
  3054. wr32(hw, I40E_QTX_HEAD(pf_q), 0);
  3055. tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
  3056. } else {
  3057. tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
  3058. }
  3059. wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
  3060. /* wait for the change to finish */
  3061. ret = i40e_pf_txq_wait(pf, pf_q, enable);
  3062. if (ret) {
  3063. dev_info(&pf->pdev->dev,
  3064. "%s: VSI seid %d Tx ring %d %sable timeout\n",
  3065. __func__, vsi->seid, pf_q,
  3066. (enable ? "en" : "dis"));
  3067. break;
  3068. }
  3069. }
  3070. if (hw->revision_id == 0)
  3071. mdelay(50);
  3072. return ret;
  3073. }
  3074. /**
  3075. * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
  3076. * @pf: the PF being configured
  3077. * @pf_q: the PF queue
  3078. * @enable: enable or disable state of the queue
  3079. *
  3080. * This routine will wait for the given Rx queue of the PF to reach the
  3081. * enabled or disabled state.
  3082. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3083. * multiple retries; else will return 0 in case of success.
  3084. **/
  3085. static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3086. {
  3087. int i;
  3088. u32 rx_reg;
  3089. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3090. rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
  3091. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3092. break;
  3093. udelay(10);
  3094. }
  3095. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3096. return -ETIMEDOUT;
  3097. return 0;
  3098. }
  3099. /**
  3100. * i40e_vsi_control_rx - Start or stop a VSI's rings
  3101. * @vsi: the VSI being configured
  3102. * @enable: start or stop the rings
  3103. **/
  3104. static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
  3105. {
  3106. struct i40e_pf *pf = vsi->back;
  3107. struct i40e_hw *hw = &pf->hw;
  3108. int i, j, pf_q, ret = 0;
  3109. u32 rx_reg;
  3110. pf_q = vsi->base_queue;
  3111. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3112. for (j = 0; j < 50; j++) {
  3113. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  3114. if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
  3115. ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
  3116. break;
  3117. usleep_range(1000, 2000);
  3118. }
  3119. /* Skip if the queue is already in the requested state */
  3120. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3121. continue;
  3122. /* turn on/off the queue */
  3123. if (enable)
  3124. rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
  3125. else
  3126. rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
  3127. wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
  3128. /* wait for the change to finish */
  3129. ret = i40e_pf_rxq_wait(pf, pf_q, enable);
  3130. if (ret) {
  3131. dev_info(&pf->pdev->dev,
  3132. "%s: VSI seid %d Rx ring %d %sable timeout\n",
  3133. __func__, vsi->seid, pf_q,
  3134. (enable ? "en" : "dis"));
  3135. break;
  3136. }
  3137. }
  3138. return ret;
  3139. }
  3140. /**
  3141. * i40e_vsi_control_rings - Start or stop a VSI's rings
  3142. * @vsi: the VSI being configured
  3143. * @enable: start or stop the rings
  3144. **/
  3145. int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request)
  3146. {
  3147. int ret = 0;
  3148. /* do rx first for enable and last for disable */
  3149. if (request) {
  3150. ret = i40e_vsi_control_rx(vsi, request);
  3151. if (ret)
  3152. return ret;
  3153. ret = i40e_vsi_control_tx(vsi, request);
  3154. } else {
  3155. /* Ignore return value, we need to shutdown whatever we can */
  3156. i40e_vsi_control_tx(vsi, request);
  3157. i40e_vsi_control_rx(vsi, request);
  3158. }
  3159. return ret;
  3160. }
  3161. /**
  3162. * i40e_vsi_free_irq - Free the irq association with the OS
  3163. * @vsi: the VSI being configured
  3164. **/
  3165. static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
  3166. {
  3167. struct i40e_pf *pf = vsi->back;
  3168. struct i40e_hw *hw = &pf->hw;
  3169. int base = vsi->base_vector;
  3170. u32 val, qp;
  3171. int i;
  3172. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3173. if (!vsi->q_vectors)
  3174. return;
  3175. if (!vsi->irqs_ready)
  3176. return;
  3177. vsi->irqs_ready = false;
  3178. for (i = 0; i < vsi->num_q_vectors; i++) {
  3179. u16 vector = i + base;
  3180. /* free only the irqs that were actually requested */
  3181. if (!vsi->q_vectors[i] ||
  3182. !vsi->q_vectors[i]->num_ringpairs)
  3183. continue;
  3184. /* clear the affinity_mask in the IRQ descriptor */
  3185. irq_set_affinity_hint(pf->msix_entries[vector].vector,
  3186. NULL);
  3187. free_irq(pf->msix_entries[vector].vector,
  3188. vsi->q_vectors[i]);
  3189. /* Tear down the interrupt queue link list
  3190. *
  3191. * We know that they come in pairs and always
  3192. * the Rx first, then the Tx. To clear the
  3193. * link list, stick the EOL value into the
  3194. * next_q field of the registers.
  3195. */
  3196. val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
  3197. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3198. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3199. val |= I40E_QUEUE_END_OF_LIST
  3200. << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3201. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
  3202. while (qp != I40E_QUEUE_END_OF_LIST) {
  3203. u32 next;
  3204. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3205. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3206. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3207. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3208. I40E_QINT_RQCTL_INTEVENT_MASK);
  3209. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3210. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3211. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3212. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3213. next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
  3214. >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
  3215. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3216. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3217. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3218. I40E_QINT_TQCTL_INTEVENT_MASK);
  3219. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3220. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3221. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3222. qp = next;
  3223. }
  3224. }
  3225. } else {
  3226. free_irq(pf->pdev->irq, pf);
  3227. val = rd32(hw, I40E_PFINT_LNKLST0);
  3228. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3229. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3230. val |= I40E_QUEUE_END_OF_LIST
  3231. << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  3232. wr32(hw, I40E_PFINT_LNKLST0, val);
  3233. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3234. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3235. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3236. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3237. I40E_QINT_RQCTL_INTEVENT_MASK);
  3238. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3239. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3240. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3241. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3242. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3243. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3244. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3245. I40E_QINT_TQCTL_INTEVENT_MASK);
  3246. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3247. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3248. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3249. }
  3250. }
  3251. /**
  3252. * i40e_free_q_vector - Free memory allocated for specific interrupt vector
  3253. * @vsi: the VSI being configured
  3254. * @v_idx: Index of vector to be freed
  3255. *
  3256. * This function frees the memory allocated to the q_vector. In addition if
  3257. * NAPI is enabled it will delete any references to the NAPI struct prior
  3258. * to freeing the q_vector.
  3259. **/
  3260. static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
  3261. {
  3262. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3263. struct i40e_ring *ring;
  3264. if (!q_vector)
  3265. return;
  3266. /* disassociate q_vector from rings */
  3267. i40e_for_each_ring(ring, q_vector->tx)
  3268. ring->q_vector = NULL;
  3269. i40e_for_each_ring(ring, q_vector->rx)
  3270. ring->q_vector = NULL;
  3271. /* only VSI w/ an associated netdev is set up w/ NAPI */
  3272. if (vsi->netdev)
  3273. netif_napi_del(&q_vector->napi);
  3274. vsi->q_vectors[v_idx] = NULL;
  3275. kfree_rcu(q_vector, rcu);
  3276. }
  3277. /**
  3278. * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
  3279. * @vsi: the VSI being un-configured
  3280. *
  3281. * This frees the memory allocated to the q_vectors and
  3282. * deletes references to the NAPI struct.
  3283. **/
  3284. static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
  3285. {
  3286. int v_idx;
  3287. for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
  3288. i40e_free_q_vector(vsi, v_idx);
  3289. }
  3290. /**
  3291. * i40e_reset_interrupt_capability - Disable interrupt setup in OS
  3292. * @pf: board private structure
  3293. **/
  3294. static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
  3295. {
  3296. /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
  3297. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3298. pci_disable_msix(pf->pdev);
  3299. kfree(pf->msix_entries);
  3300. pf->msix_entries = NULL;
  3301. } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
  3302. pci_disable_msi(pf->pdev);
  3303. }
  3304. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  3305. }
  3306. /**
  3307. * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
  3308. * @pf: board private structure
  3309. *
  3310. * We go through and clear interrupt specific resources and reset the structure
  3311. * to pre-load conditions
  3312. **/
  3313. static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
  3314. {
  3315. int i;
  3316. i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
  3317. for (i = 0; i < pf->num_alloc_vsi; i++)
  3318. if (pf->vsi[i])
  3319. i40e_vsi_free_q_vectors(pf->vsi[i]);
  3320. i40e_reset_interrupt_capability(pf);
  3321. }
  3322. /**
  3323. * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
  3324. * @vsi: the VSI being configured
  3325. **/
  3326. static void i40e_napi_enable_all(struct i40e_vsi *vsi)
  3327. {
  3328. int q_idx;
  3329. if (!vsi->netdev)
  3330. return;
  3331. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
  3332. napi_enable(&vsi->q_vectors[q_idx]->napi);
  3333. }
  3334. /**
  3335. * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
  3336. * @vsi: the VSI being configured
  3337. **/
  3338. static void i40e_napi_disable_all(struct i40e_vsi *vsi)
  3339. {
  3340. int q_idx;
  3341. if (!vsi->netdev)
  3342. return;
  3343. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
  3344. napi_disable(&vsi->q_vectors[q_idx]->napi);
  3345. }
  3346. /**
  3347. * i40e_vsi_close - Shut down a VSI
  3348. * @vsi: the vsi to be quelled
  3349. **/
  3350. static void i40e_vsi_close(struct i40e_vsi *vsi)
  3351. {
  3352. if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
  3353. i40e_down(vsi);
  3354. i40e_vsi_free_irq(vsi);
  3355. i40e_vsi_free_tx_resources(vsi);
  3356. i40e_vsi_free_rx_resources(vsi);
  3357. }
  3358. /**
  3359. * i40e_quiesce_vsi - Pause a given VSI
  3360. * @vsi: the VSI being paused
  3361. **/
  3362. static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
  3363. {
  3364. if (test_bit(__I40E_DOWN, &vsi->state))
  3365. return;
  3366. set_bit(__I40E_NEEDS_RESTART, &vsi->state);
  3367. if (vsi->netdev && netif_running(vsi->netdev)) {
  3368. vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
  3369. } else {
  3370. i40e_vsi_close(vsi);
  3371. }
  3372. }
  3373. /**
  3374. * i40e_unquiesce_vsi - Resume a given VSI
  3375. * @vsi: the VSI being resumed
  3376. **/
  3377. static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
  3378. {
  3379. if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
  3380. return;
  3381. clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
  3382. if (vsi->netdev && netif_running(vsi->netdev))
  3383. vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
  3384. else
  3385. i40e_vsi_open(vsi); /* this clears the DOWN bit */
  3386. }
  3387. /**
  3388. * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
  3389. * @pf: the PF
  3390. **/
  3391. static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
  3392. {
  3393. int v;
  3394. for (v = 0; v < pf->num_alloc_vsi; v++) {
  3395. if (pf->vsi[v])
  3396. i40e_quiesce_vsi(pf->vsi[v]);
  3397. }
  3398. }
  3399. /**
  3400. * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
  3401. * @pf: the PF
  3402. **/
  3403. static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
  3404. {
  3405. int v;
  3406. for (v = 0; v < pf->num_alloc_vsi; v++) {
  3407. if (pf->vsi[v])
  3408. i40e_unquiesce_vsi(pf->vsi[v]);
  3409. }
  3410. }
  3411. /**
  3412. * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
  3413. * @dcbcfg: the corresponding DCBx configuration structure
  3414. *
  3415. * Return the number of TCs from given DCBx configuration
  3416. **/
  3417. static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
  3418. {
  3419. u8 num_tc = 0;
  3420. int i;
  3421. /* Scan the ETS Config Priority Table to find
  3422. * traffic class enabled for a given priority
  3423. * and use the traffic class index to get the
  3424. * number of traffic classes enabled
  3425. */
  3426. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  3427. if (dcbcfg->etscfg.prioritytable[i] > num_tc)
  3428. num_tc = dcbcfg->etscfg.prioritytable[i];
  3429. }
  3430. /* Traffic class index starts from zero so
  3431. * increment to return the actual count
  3432. */
  3433. return num_tc + 1;
  3434. }
  3435. /**
  3436. * i40e_dcb_get_enabled_tc - Get enabled traffic classes
  3437. * @dcbcfg: the corresponding DCBx configuration structure
  3438. *
  3439. * Query the current DCB configuration and return the number of
  3440. * traffic classes enabled from the given DCBX config
  3441. **/
  3442. static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
  3443. {
  3444. u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
  3445. u8 enabled_tc = 1;
  3446. u8 i;
  3447. for (i = 0; i < num_tc; i++)
  3448. enabled_tc |= 1 << i;
  3449. return enabled_tc;
  3450. }
  3451. /**
  3452. * i40e_pf_get_num_tc - Get enabled traffic classes for PF
  3453. * @pf: PF being queried
  3454. *
  3455. * Return number of traffic classes enabled for the given PF
  3456. **/
  3457. static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
  3458. {
  3459. struct i40e_hw *hw = &pf->hw;
  3460. u8 i, enabled_tc;
  3461. u8 num_tc = 0;
  3462. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  3463. /* If DCB is not enabled then always in single TC */
  3464. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  3465. return 1;
  3466. /* MFP mode return count of enabled TCs for this PF */
  3467. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  3468. enabled_tc = pf->hw.func_caps.enabled_tcmap;
  3469. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3470. if (enabled_tc & (1 << i))
  3471. num_tc++;
  3472. }
  3473. return num_tc;
  3474. }
  3475. /* SFP mode will be enabled for all TCs on port */
  3476. return i40e_dcb_get_num_tc(dcbcfg);
  3477. }
  3478. /**
  3479. * i40e_pf_get_default_tc - Get bitmap for first enabled TC
  3480. * @pf: PF being queried
  3481. *
  3482. * Return a bitmap for first enabled traffic class for this PF.
  3483. **/
  3484. static u8 i40e_pf_get_default_tc(struct i40e_pf *pf)
  3485. {
  3486. u8 enabled_tc = pf->hw.func_caps.enabled_tcmap;
  3487. u8 i = 0;
  3488. if (!enabled_tc)
  3489. return 0x1; /* TC0 */
  3490. /* Find the first enabled TC */
  3491. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3492. if (enabled_tc & (1 << i))
  3493. break;
  3494. }
  3495. return 1 << i;
  3496. }
  3497. /**
  3498. * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
  3499. * @pf: PF being queried
  3500. *
  3501. * Return a bitmap for enabled traffic classes for this PF.
  3502. **/
  3503. static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
  3504. {
  3505. /* If DCB is not enabled for this PF then just return default TC */
  3506. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  3507. return i40e_pf_get_default_tc(pf);
  3508. /* MFP mode will have enabled TCs set by FW */
  3509. if (pf->flags & I40E_FLAG_MFP_ENABLED)
  3510. return pf->hw.func_caps.enabled_tcmap;
  3511. /* SFP mode we want PF to be enabled for all TCs */
  3512. return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
  3513. }
  3514. /**
  3515. * i40e_vsi_get_bw_info - Query VSI BW Information
  3516. * @vsi: the VSI being queried
  3517. *
  3518. * Returns 0 on success, negative value on failure
  3519. **/
  3520. static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
  3521. {
  3522. struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
  3523. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  3524. struct i40e_pf *pf = vsi->back;
  3525. struct i40e_hw *hw = &pf->hw;
  3526. i40e_status aq_ret;
  3527. u32 tc_bw_max;
  3528. int i;
  3529. /* Get the VSI level BW configuration */
  3530. aq_ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
  3531. if (aq_ret) {
  3532. dev_info(&pf->pdev->dev,
  3533. "couldn't get pf vsi bw config, err %d, aq_err %d\n",
  3534. aq_ret, pf->hw.aq.asq_last_status);
  3535. return -EINVAL;
  3536. }
  3537. /* Get the VSI level BW configuration per TC */
  3538. aq_ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
  3539. NULL);
  3540. if (aq_ret) {
  3541. dev_info(&pf->pdev->dev,
  3542. "couldn't get pf vsi ets bw config, err %d, aq_err %d\n",
  3543. aq_ret, pf->hw.aq.asq_last_status);
  3544. return -EINVAL;
  3545. }
  3546. if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
  3547. dev_info(&pf->pdev->dev,
  3548. "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
  3549. bw_config.tc_valid_bits,
  3550. bw_ets_config.tc_valid_bits);
  3551. /* Still continuing */
  3552. }
  3553. vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
  3554. vsi->bw_max_quanta = bw_config.max_bw;
  3555. tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
  3556. (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
  3557. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3558. vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
  3559. vsi->bw_ets_limit_credits[i] =
  3560. le16_to_cpu(bw_ets_config.credits[i]);
  3561. /* 3 bits out of 4 for each TC */
  3562. vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
  3563. }
  3564. return 0;
  3565. }
  3566. /**
  3567. * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
  3568. * @vsi: the VSI being configured
  3569. * @enabled_tc: TC bitmap
  3570. * @bw_credits: BW shared credits per TC
  3571. *
  3572. * Returns 0 on success, negative value on failure
  3573. **/
  3574. static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
  3575. u8 *bw_share)
  3576. {
  3577. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  3578. i40e_status aq_ret;
  3579. int i;
  3580. bw_data.tc_valid_bits = enabled_tc;
  3581. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  3582. bw_data.tc_bw_credits[i] = bw_share[i];
  3583. aq_ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
  3584. NULL);
  3585. if (aq_ret) {
  3586. dev_info(&vsi->back->pdev->dev,
  3587. "AQ command Config VSI BW allocation per TC failed = %d\n",
  3588. vsi->back->hw.aq.asq_last_status);
  3589. return -EINVAL;
  3590. }
  3591. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  3592. vsi->info.qs_handle[i] = bw_data.qs_handles[i];
  3593. return 0;
  3594. }
  3595. /**
  3596. * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
  3597. * @vsi: the VSI being configured
  3598. * @enabled_tc: TC map to be enabled
  3599. *
  3600. **/
  3601. static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  3602. {
  3603. struct net_device *netdev = vsi->netdev;
  3604. struct i40e_pf *pf = vsi->back;
  3605. struct i40e_hw *hw = &pf->hw;
  3606. u8 netdev_tc = 0;
  3607. int i;
  3608. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  3609. if (!netdev)
  3610. return;
  3611. if (!enabled_tc) {
  3612. netdev_reset_tc(netdev);
  3613. return;
  3614. }
  3615. /* Set up actual enabled TCs on the VSI */
  3616. if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
  3617. return;
  3618. /* set per TC queues for the VSI */
  3619. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3620. /* Only set TC queues for enabled tcs
  3621. *
  3622. * e.g. For a VSI that has TC0 and TC3 enabled the
  3623. * enabled_tc bitmap would be 0x00001001; the driver
  3624. * will set the numtc for netdev as 2 that will be
  3625. * referenced by the netdev layer as TC 0 and 1.
  3626. */
  3627. if (vsi->tc_config.enabled_tc & (1 << i))
  3628. netdev_set_tc_queue(netdev,
  3629. vsi->tc_config.tc_info[i].netdev_tc,
  3630. vsi->tc_config.tc_info[i].qcount,
  3631. vsi->tc_config.tc_info[i].qoffset);
  3632. }
  3633. /* Assign UP2TC map for the VSI */
  3634. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  3635. /* Get the actual TC# for the UP */
  3636. u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
  3637. /* Get the mapped netdev TC# for the UP */
  3638. netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
  3639. netdev_set_prio_tc_map(netdev, i, netdev_tc);
  3640. }
  3641. }
  3642. /**
  3643. * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
  3644. * @vsi: the VSI being configured
  3645. * @ctxt: the ctxt buffer returned from AQ VSI update param command
  3646. **/
  3647. static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
  3648. struct i40e_vsi_context *ctxt)
  3649. {
  3650. /* copy just the sections touched not the entire info
  3651. * since not all sections are valid as returned by
  3652. * update vsi params
  3653. */
  3654. vsi->info.mapping_flags = ctxt->info.mapping_flags;
  3655. memcpy(&vsi->info.queue_mapping,
  3656. &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
  3657. memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
  3658. sizeof(vsi->info.tc_mapping));
  3659. }
  3660. /**
  3661. * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
  3662. * @vsi: VSI to be configured
  3663. * @enabled_tc: TC bitmap
  3664. *
  3665. * This configures a particular VSI for TCs that are mapped to the
  3666. * given TC bitmap. It uses default bandwidth share for TCs across
  3667. * VSIs to configure TC for a particular VSI.
  3668. *
  3669. * NOTE:
  3670. * It is expected that the VSI queues have been quisced before calling
  3671. * this function.
  3672. **/
  3673. static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  3674. {
  3675. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  3676. struct i40e_vsi_context ctxt;
  3677. int ret = 0;
  3678. int i;
  3679. /* Check if enabled_tc is same as existing or new TCs */
  3680. if (vsi->tc_config.enabled_tc == enabled_tc)
  3681. return ret;
  3682. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  3683. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3684. if (enabled_tc & (1 << i))
  3685. bw_share[i] = 1;
  3686. }
  3687. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  3688. if (ret) {
  3689. dev_info(&vsi->back->pdev->dev,
  3690. "Failed configuring TC map %d for VSI %d\n",
  3691. enabled_tc, vsi->seid);
  3692. goto out;
  3693. }
  3694. /* Update Queue Pairs Mapping for currently enabled UPs */
  3695. ctxt.seid = vsi->seid;
  3696. ctxt.pf_num = vsi->back->hw.pf_id;
  3697. ctxt.vf_num = 0;
  3698. ctxt.uplink_seid = vsi->uplink_seid;
  3699. memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
  3700. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  3701. /* Update the VSI after updating the VSI queue-mapping information */
  3702. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  3703. if (ret) {
  3704. dev_info(&vsi->back->pdev->dev,
  3705. "update vsi failed, aq_err=%d\n",
  3706. vsi->back->hw.aq.asq_last_status);
  3707. goto out;
  3708. }
  3709. /* update the local VSI info with updated queue map */
  3710. i40e_vsi_update_queue_map(vsi, &ctxt);
  3711. vsi->info.valid_sections = 0;
  3712. /* Update current VSI BW information */
  3713. ret = i40e_vsi_get_bw_info(vsi);
  3714. if (ret) {
  3715. dev_info(&vsi->back->pdev->dev,
  3716. "Failed updating vsi bw info, aq_err=%d\n",
  3717. vsi->back->hw.aq.asq_last_status);
  3718. goto out;
  3719. }
  3720. /* Update the netdev TC setup */
  3721. i40e_vsi_config_netdev_tc(vsi, enabled_tc);
  3722. out:
  3723. return ret;
  3724. }
  3725. /**
  3726. * i40e_veb_config_tc - Configure TCs for given VEB
  3727. * @veb: given VEB
  3728. * @enabled_tc: TC bitmap
  3729. *
  3730. * Configures given TC bitmap for VEB (switching) element
  3731. **/
  3732. int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
  3733. {
  3734. struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
  3735. struct i40e_pf *pf = veb->pf;
  3736. int ret = 0;
  3737. int i;
  3738. /* No TCs or already enabled TCs just return */
  3739. if (!enabled_tc || veb->enabled_tc == enabled_tc)
  3740. return ret;
  3741. bw_data.tc_valid_bits = enabled_tc;
  3742. /* bw_data.absolute_credits is not set (relative) */
  3743. /* Enable ETS TCs with equal BW Share for now */
  3744. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3745. if (enabled_tc & (1 << i))
  3746. bw_data.tc_bw_share_credits[i] = 1;
  3747. }
  3748. ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
  3749. &bw_data, NULL);
  3750. if (ret) {
  3751. dev_info(&pf->pdev->dev,
  3752. "veb bw config failed, aq_err=%d\n",
  3753. pf->hw.aq.asq_last_status);
  3754. goto out;
  3755. }
  3756. /* Update the BW information */
  3757. ret = i40e_veb_get_bw_info(veb);
  3758. if (ret) {
  3759. dev_info(&pf->pdev->dev,
  3760. "Failed getting veb bw config, aq_err=%d\n",
  3761. pf->hw.aq.asq_last_status);
  3762. }
  3763. out:
  3764. return ret;
  3765. }
  3766. #ifdef CONFIG_I40E_DCB
  3767. /**
  3768. * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
  3769. * @pf: PF struct
  3770. *
  3771. * Reconfigure VEB/VSIs on a given PF; it is assumed that
  3772. * the caller would've quiesce all the VSIs before calling
  3773. * this function
  3774. **/
  3775. static void i40e_dcb_reconfigure(struct i40e_pf *pf)
  3776. {
  3777. u8 tc_map = 0;
  3778. int ret;
  3779. u8 v;
  3780. /* Enable the TCs available on PF to all VEBs */
  3781. tc_map = i40e_pf_get_tc_map(pf);
  3782. for (v = 0; v < I40E_MAX_VEB; v++) {
  3783. if (!pf->veb[v])
  3784. continue;
  3785. ret = i40e_veb_config_tc(pf->veb[v], tc_map);
  3786. if (ret) {
  3787. dev_info(&pf->pdev->dev,
  3788. "Failed configuring TC for VEB seid=%d\n",
  3789. pf->veb[v]->seid);
  3790. /* Will try to configure as many components */
  3791. }
  3792. }
  3793. /* Update each VSI */
  3794. for (v = 0; v < pf->num_alloc_vsi; v++) {
  3795. if (!pf->vsi[v])
  3796. continue;
  3797. /* - Enable all TCs for the LAN VSI
  3798. #ifdef I40E_FCOE
  3799. * - For FCoE VSI only enable the TC configured
  3800. * as per the APP TLV
  3801. #endif
  3802. * - For all others keep them at TC0 for now
  3803. */
  3804. if (v == pf->lan_vsi)
  3805. tc_map = i40e_pf_get_tc_map(pf);
  3806. else
  3807. tc_map = i40e_pf_get_default_tc(pf);
  3808. #ifdef I40E_FCOE
  3809. if (pf->vsi[v]->type == I40E_VSI_FCOE)
  3810. tc_map = i40e_get_fcoe_tc_map(pf);
  3811. #endif /* #ifdef I40E_FCOE */
  3812. ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
  3813. if (ret) {
  3814. dev_info(&pf->pdev->dev,
  3815. "Failed configuring TC for VSI seid=%d\n",
  3816. pf->vsi[v]->seid);
  3817. /* Will try to configure as many components */
  3818. } else {
  3819. /* Re-configure VSI vectors based on updated TC map */
  3820. i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
  3821. if (pf->vsi[v]->netdev)
  3822. i40e_dcbnl_set_all(pf->vsi[v]);
  3823. }
  3824. }
  3825. }
  3826. /**
  3827. * i40e_init_pf_dcb - Initialize DCB configuration
  3828. * @pf: PF being configured
  3829. *
  3830. * Query the current DCB configuration and cache it
  3831. * in the hardware structure
  3832. **/
  3833. static int i40e_init_pf_dcb(struct i40e_pf *pf)
  3834. {
  3835. struct i40e_hw *hw = &pf->hw;
  3836. int err = 0;
  3837. if (pf->hw.func_caps.npar_enable)
  3838. goto out;
  3839. /* Get the initial DCB configuration */
  3840. err = i40e_init_dcb(hw);
  3841. if (!err) {
  3842. /* Device/Function is not DCBX capable */
  3843. if ((!hw->func_caps.dcb) ||
  3844. (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
  3845. dev_info(&pf->pdev->dev,
  3846. "DCBX offload is not supported or is disabled for this PF.\n");
  3847. if (pf->flags & I40E_FLAG_MFP_ENABLED)
  3848. goto out;
  3849. } else {
  3850. /* When status is not DISABLED then DCBX in FW */
  3851. pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
  3852. DCB_CAP_DCBX_VER_IEEE;
  3853. pf->flags |= I40E_FLAG_DCB_CAPABLE;
  3854. /* Enable DCB tagging only when more than one TC */
  3855. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  3856. pf->flags |= I40E_FLAG_DCB_ENABLED;
  3857. }
  3858. } else {
  3859. dev_info(&pf->pdev->dev, "AQ Querying DCB configuration failed: %d\n",
  3860. pf->hw.aq.asq_last_status);
  3861. }
  3862. out:
  3863. return err;
  3864. }
  3865. #endif /* CONFIG_I40E_DCB */
  3866. #define SPEED_SIZE 14
  3867. #define FC_SIZE 8
  3868. /**
  3869. * i40e_print_link_message - print link up or down
  3870. * @vsi: the VSI for which link needs a message
  3871. */
  3872. static void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
  3873. {
  3874. char speed[SPEED_SIZE] = "Unknown";
  3875. char fc[FC_SIZE] = "RX/TX";
  3876. if (!isup) {
  3877. netdev_info(vsi->netdev, "NIC Link is Down\n");
  3878. return;
  3879. }
  3880. switch (vsi->back->hw.phy.link_info.link_speed) {
  3881. case I40E_LINK_SPEED_40GB:
  3882. strlcpy(speed, "40 Gbps", SPEED_SIZE);
  3883. break;
  3884. case I40E_LINK_SPEED_10GB:
  3885. strlcpy(speed, "10 Gbps", SPEED_SIZE);
  3886. break;
  3887. case I40E_LINK_SPEED_1GB:
  3888. strlcpy(speed, "1000 Mbps", SPEED_SIZE);
  3889. break;
  3890. default:
  3891. break;
  3892. }
  3893. switch (vsi->back->hw.fc.current_mode) {
  3894. case I40E_FC_FULL:
  3895. strlcpy(fc, "RX/TX", FC_SIZE);
  3896. break;
  3897. case I40E_FC_TX_PAUSE:
  3898. strlcpy(fc, "TX", FC_SIZE);
  3899. break;
  3900. case I40E_FC_RX_PAUSE:
  3901. strlcpy(fc, "RX", FC_SIZE);
  3902. break;
  3903. default:
  3904. strlcpy(fc, "None", FC_SIZE);
  3905. break;
  3906. }
  3907. netdev_info(vsi->netdev, "NIC Link is Up %s Full Duplex, Flow Control: %s\n",
  3908. speed, fc);
  3909. }
  3910. /**
  3911. * i40e_up_complete - Finish the last steps of bringing up a connection
  3912. * @vsi: the VSI being configured
  3913. **/
  3914. static int i40e_up_complete(struct i40e_vsi *vsi)
  3915. {
  3916. struct i40e_pf *pf = vsi->back;
  3917. u8 set_fc_aq_fail = 0;
  3918. int err;
  3919. /* force flow control off */
  3920. i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
  3921. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3922. i40e_vsi_configure_msix(vsi);
  3923. else
  3924. i40e_configure_msi_and_legacy(vsi);
  3925. /* start rings */
  3926. err = i40e_vsi_control_rings(vsi, true);
  3927. if (err)
  3928. return err;
  3929. clear_bit(__I40E_DOWN, &vsi->state);
  3930. i40e_napi_enable_all(vsi);
  3931. i40e_vsi_enable_irq(vsi);
  3932. if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
  3933. (vsi->netdev)) {
  3934. i40e_print_link_message(vsi, true);
  3935. netif_tx_start_all_queues(vsi->netdev);
  3936. netif_carrier_on(vsi->netdev);
  3937. } else if (vsi->netdev) {
  3938. i40e_print_link_message(vsi, false);
  3939. /* need to check for qualified module here*/
  3940. if ((pf->hw.phy.link_info.link_info &
  3941. I40E_AQ_MEDIA_AVAILABLE) &&
  3942. (!(pf->hw.phy.link_info.an_info &
  3943. I40E_AQ_QUALIFIED_MODULE)))
  3944. netdev_err(vsi->netdev,
  3945. "the driver failed to link because an unqualified module was detected.");
  3946. }
  3947. /* replay FDIR SB filters */
  3948. if (vsi->type == I40E_VSI_FDIR) {
  3949. /* reset fd counters */
  3950. pf->fd_add_err = pf->fd_atr_cnt = 0;
  3951. if (pf->fd_tcp_rule > 0) {
  3952. pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  3953. dev_info(&pf->pdev->dev, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
  3954. pf->fd_tcp_rule = 0;
  3955. }
  3956. i40e_fdir_filter_restore(vsi);
  3957. }
  3958. i40e_service_event_schedule(pf);
  3959. return 0;
  3960. }
  3961. /**
  3962. * i40e_vsi_reinit_locked - Reset the VSI
  3963. * @vsi: the VSI being configured
  3964. *
  3965. * Rebuild the ring structs after some configuration
  3966. * has changed, e.g. MTU size.
  3967. **/
  3968. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
  3969. {
  3970. struct i40e_pf *pf = vsi->back;
  3971. WARN_ON(in_interrupt());
  3972. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  3973. usleep_range(1000, 2000);
  3974. i40e_down(vsi);
  3975. /* Give a VF some time to respond to the reset. The
  3976. * two second wait is based upon the watchdog cycle in
  3977. * the VF driver.
  3978. */
  3979. if (vsi->type == I40E_VSI_SRIOV)
  3980. msleep(2000);
  3981. i40e_up(vsi);
  3982. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  3983. }
  3984. /**
  3985. * i40e_up - Bring the connection back up after being down
  3986. * @vsi: the VSI being configured
  3987. **/
  3988. int i40e_up(struct i40e_vsi *vsi)
  3989. {
  3990. int err;
  3991. err = i40e_vsi_configure(vsi);
  3992. if (!err)
  3993. err = i40e_up_complete(vsi);
  3994. return err;
  3995. }
  3996. /**
  3997. * i40e_down - Shutdown the connection processing
  3998. * @vsi: the VSI being stopped
  3999. **/
  4000. void i40e_down(struct i40e_vsi *vsi)
  4001. {
  4002. int i;
  4003. /* It is assumed that the caller of this function
  4004. * sets the vsi->state __I40E_DOWN bit.
  4005. */
  4006. if (vsi->netdev) {
  4007. netif_carrier_off(vsi->netdev);
  4008. netif_tx_disable(vsi->netdev);
  4009. }
  4010. i40e_vsi_disable_irq(vsi);
  4011. i40e_vsi_control_rings(vsi, false);
  4012. i40e_napi_disable_all(vsi);
  4013. for (i = 0; i < vsi->num_queue_pairs; i++) {
  4014. i40e_clean_tx_ring(vsi->tx_rings[i]);
  4015. i40e_clean_rx_ring(vsi->rx_rings[i]);
  4016. }
  4017. }
  4018. /**
  4019. * i40e_setup_tc - configure multiple traffic classes
  4020. * @netdev: net device to configure
  4021. * @tc: number of traffic classes to enable
  4022. **/
  4023. #ifdef I40E_FCOE
  4024. int i40e_setup_tc(struct net_device *netdev, u8 tc)
  4025. #else
  4026. static int i40e_setup_tc(struct net_device *netdev, u8 tc)
  4027. #endif
  4028. {
  4029. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4030. struct i40e_vsi *vsi = np->vsi;
  4031. struct i40e_pf *pf = vsi->back;
  4032. u8 enabled_tc = 0;
  4033. int ret = -EINVAL;
  4034. int i;
  4035. /* Check if DCB enabled to continue */
  4036. if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  4037. netdev_info(netdev, "DCB is not enabled for adapter\n");
  4038. goto exit;
  4039. }
  4040. /* Check if MFP enabled */
  4041. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  4042. netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
  4043. goto exit;
  4044. }
  4045. /* Check whether tc count is within enabled limit */
  4046. if (tc > i40e_pf_get_num_tc(pf)) {
  4047. netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
  4048. goto exit;
  4049. }
  4050. /* Generate TC map for number of tc requested */
  4051. for (i = 0; i < tc; i++)
  4052. enabled_tc |= (1 << i);
  4053. /* Requesting same TC configuration as already enabled */
  4054. if (enabled_tc == vsi->tc_config.enabled_tc)
  4055. return 0;
  4056. /* Quiesce VSI queues */
  4057. i40e_quiesce_vsi(vsi);
  4058. /* Configure VSI for enabled TCs */
  4059. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  4060. if (ret) {
  4061. netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
  4062. vsi->seid);
  4063. goto exit;
  4064. }
  4065. /* Unquiesce VSI */
  4066. i40e_unquiesce_vsi(vsi);
  4067. exit:
  4068. return ret;
  4069. }
  4070. /**
  4071. * i40e_open - Called when a network interface is made active
  4072. * @netdev: network interface device structure
  4073. *
  4074. * The open entry point is called when a network interface is made
  4075. * active by the system (IFF_UP). At this point all resources needed
  4076. * for transmit and receive operations are allocated, the interrupt
  4077. * handler is registered with the OS, the netdev watchdog subtask is
  4078. * enabled, and the stack is notified that the interface is ready.
  4079. *
  4080. * Returns 0 on success, negative value on failure
  4081. **/
  4082. #ifdef I40E_FCOE
  4083. int i40e_open(struct net_device *netdev)
  4084. #else
  4085. static int i40e_open(struct net_device *netdev)
  4086. #endif
  4087. {
  4088. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4089. struct i40e_vsi *vsi = np->vsi;
  4090. struct i40e_pf *pf = vsi->back;
  4091. int err;
  4092. /* disallow open during test or if eeprom is broken */
  4093. if (test_bit(__I40E_TESTING, &pf->state) ||
  4094. test_bit(__I40E_BAD_EEPROM, &pf->state))
  4095. return -EBUSY;
  4096. netif_carrier_off(netdev);
  4097. err = i40e_vsi_open(vsi);
  4098. if (err)
  4099. return err;
  4100. /* configure global TSO hardware offload settings */
  4101. wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
  4102. TCP_FLAG_FIN) >> 16);
  4103. wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
  4104. TCP_FLAG_FIN |
  4105. TCP_FLAG_CWR) >> 16);
  4106. wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
  4107. #ifdef CONFIG_I40E_VXLAN
  4108. vxlan_get_rx_port(netdev);
  4109. #endif
  4110. return 0;
  4111. }
  4112. /**
  4113. * i40e_vsi_open -
  4114. * @vsi: the VSI to open
  4115. *
  4116. * Finish initialization of the VSI.
  4117. *
  4118. * Returns 0 on success, negative value on failure
  4119. **/
  4120. int i40e_vsi_open(struct i40e_vsi *vsi)
  4121. {
  4122. struct i40e_pf *pf = vsi->back;
  4123. char int_name[IFNAMSIZ];
  4124. int err;
  4125. /* allocate descriptors */
  4126. err = i40e_vsi_setup_tx_resources(vsi);
  4127. if (err)
  4128. goto err_setup_tx;
  4129. err = i40e_vsi_setup_rx_resources(vsi);
  4130. if (err)
  4131. goto err_setup_rx;
  4132. err = i40e_vsi_configure(vsi);
  4133. if (err)
  4134. goto err_setup_rx;
  4135. if (vsi->netdev) {
  4136. snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
  4137. dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
  4138. err = i40e_vsi_request_irq(vsi, int_name);
  4139. if (err)
  4140. goto err_setup_rx;
  4141. /* Notify the stack of the actual queue counts. */
  4142. err = netif_set_real_num_tx_queues(vsi->netdev,
  4143. vsi->num_queue_pairs);
  4144. if (err)
  4145. goto err_set_queues;
  4146. err = netif_set_real_num_rx_queues(vsi->netdev,
  4147. vsi->num_queue_pairs);
  4148. if (err)
  4149. goto err_set_queues;
  4150. } else if (vsi->type == I40E_VSI_FDIR) {
  4151. snprintf(int_name, sizeof(int_name) - 1, "%s-fdir",
  4152. dev_driver_string(&pf->pdev->dev));
  4153. err = i40e_vsi_request_irq(vsi, int_name);
  4154. } else {
  4155. err = -EINVAL;
  4156. goto err_setup_rx;
  4157. }
  4158. err = i40e_up_complete(vsi);
  4159. if (err)
  4160. goto err_up_complete;
  4161. return 0;
  4162. err_up_complete:
  4163. i40e_down(vsi);
  4164. err_set_queues:
  4165. i40e_vsi_free_irq(vsi);
  4166. err_setup_rx:
  4167. i40e_vsi_free_rx_resources(vsi);
  4168. err_setup_tx:
  4169. i40e_vsi_free_tx_resources(vsi);
  4170. if (vsi == pf->vsi[pf->lan_vsi])
  4171. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  4172. return err;
  4173. }
  4174. /**
  4175. * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
  4176. * @pf: Pointer to pf
  4177. *
  4178. * This function destroys the hlist where all the Flow Director
  4179. * filters were saved.
  4180. **/
  4181. static void i40e_fdir_filter_exit(struct i40e_pf *pf)
  4182. {
  4183. struct i40e_fdir_filter *filter;
  4184. struct hlist_node *node2;
  4185. hlist_for_each_entry_safe(filter, node2,
  4186. &pf->fdir_filter_list, fdir_node) {
  4187. hlist_del(&filter->fdir_node);
  4188. kfree(filter);
  4189. }
  4190. pf->fdir_pf_active_filters = 0;
  4191. }
  4192. /**
  4193. * i40e_close - Disables a network interface
  4194. * @netdev: network interface device structure
  4195. *
  4196. * The close entry point is called when an interface is de-activated
  4197. * by the OS. The hardware is still under the driver's control, but
  4198. * this netdev interface is disabled.
  4199. *
  4200. * Returns 0, this is not allowed to fail
  4201. **/
  4202. #ifdef I40E_FCOE
  4203. int i40e_close(struct net_device *netdev)
  4204. #else
  4205. static int i40e_close(struct net_device *netdev)
  4206. #endif
  4207. {
  4208. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4209. struct i40e_vsi *vsi = np->vsi;
  4210. i40e_vsi_close(vsi);
  4211. return 0;
  4212. }
  4213. /**
  4214. * i40e_do_reset - Start a PF or Core Reset sequence
  4215. * @pf: board private structure
  4216. * @reset_flags: which reset is requested
  4217. *
  4218. * The essential difference in resets is that the PF Reset
  4219. * doesn't clear the packet buffers, doesn't reset the PE
  4220. * firmware, and doesn't bother the other PFs on the chip.
  4221. **/
  4222. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
  4223. {
  4224. u32 val;
  4225. WARN_ON(in_interrupt());
  4226. if (i40e_check_asq_alive(&pf->hw))
  4227. i40e_vc_notify_reset(pf);
  4228. /* do the biggest reset indicated */
  4229. if (reset_flags & (1 << __I40E_GLOBAL_RESET_REQUESTED)) {
  4230. /* Request a Global Reset
  4231. *
  4232. * This will start the chip's countdown to the actual full
  4233. * chip reset event, and a warning interrupt to be sent
  4234. * to all PFs, including the requestor. Our handler
  4235. * for the warning interrupt will deal with the shutdown
  4236. * and recovery of the switch setup.
  4237. */
  4238. dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
  4239. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  4240. val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
  4241. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  4242. } else if (reset_flags & (1 << __I40E_CORE_RESET_REQUESTED)) {
  4243. /* Request a Core Reset
  4244. *
  4245. * Same as Global Reset, except does *not* include the MAC/PHY
  4246. */
  4247. dev_dbg(&pf->pdev->dev, "CoreR requested\n");
  4248. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  4249. val |= I40E_GLGEN_RTRIG_CORER_MASK;
  4250. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  4251. i40e_flush(&pf->hw);
  4252. } else if (reset_flags & (1 << __I40E_EMP_RESET_REQUESTED)) {
  4253. /* Request a Firmware Reset
  4254. *
  4255. * Same as Global reset, plus restarting the
  4256. * embedded firmware engine.
  4257. */
  4258. /* enable EMP Reset */
  4259. val = rd32(&pf->hw, I40E_GLGEN_RSTENA_EMP);
  4260. val |= I40E_GLGEN_RSTENA_EMP_EMP_RST_ENA_MASK;
  4261. wr32(&pf->hw, I40E_GLGEN_RSTENA_EMP, val);
  4262. /* force the reset */
  4263. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  4264. val |= I40E_GLGEN_RTRIG_EMPFWR_MASK;
  4265. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  4266. i40e_flush(&pf->hw);
  4267. } else if (reset_flags & (1 << __I40E_PF_RESET_REQUESTED)) {
  4268. /* Request a PF Reset
  4269. *
  4270. * Resets only the PF-specific registers
  4271. *
  4272. * This goes directly to the tear-down and rebuild of
  4273. * the switch, since we need to do all the recovery as
  4274. * for the Core Reset.
  4275. */
  4276. dev_dbg(&pf->pdev->dev, "PFR requested\n");
  4277. i40e_handle_reset_warning(pf);
  4278. } else if (reset_flags & (1 << __I40E_REINIT_REQUESTED)) {
  4279. int v;
  4280. /* Find the VSI(s) that requested a re-init */
  4281. dev_info(&pf->pdev->dev,
  4282. "VSI reinit requested\n");
  4283. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4284. struct i40e_vsi *vsi = pf->vsi[v];
  4285. if (vsi != NULL &&
  4286. test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
  4287. i40e_vsi_reinit_locked(pf->vsi[v]);
  4288. clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
  4289. }
  4290. }
  4291. /* no further action needed, so return now */
  4292. return;
  4293. } else if (reset_flags & (1 << __I40E_DOWN_REQUESTED)) {
  4294. int v;
  4295. /* Find the VSI(s) that needs to be brought down */
  4296. dev_info(&pf->pdev->dev, "VSI down requested\n");
  4297. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4298. struct i40e_vsi *vsi = pf->vsi[v];
  4299. if (vsi != NULL &&
  4300. test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) {
  4301. set_bit(__I40E_DOWN, &vsi->state);
  4302. i40e_down(vsi);
  4303. clear_bit(__I40E_DOWN_REQUESTED, &vsi->state);
  4304. }
  4305. }
  4306. /* no further action needed, so return now */
  4307. return;
  4308. } else {
  4309. dev_info(&pf->pdev->dev,
  4310. "bad reset request 0x%08x\n", reset_flags);
  4311. return;
  4312. }
  4313. }
  4314. #ifdef CONFIG_I40E_DCB
  4315. /**
  4316. * i40e_dcb_need_reconfig - Check if DCB needs reconfig
  4317. * @pf: board private structure
  4318. * @old_cfg: current DCB config
  4319. * @new_cfg: new DCB config
  4320. **/
  4321. bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
  4322. struct i40e_dcbx_config *old_cfg,
  4323. struct i40e_dcbx_config *new_cfg)
  4324. {
  4325. bool need_reconfig = false;
  4326. /* Check if ETS configuration has changed */
  4327. if (memcmp(&new_cfg->etscfg,
  4328. &old_cfg->etscfg,
  4329. sizeof(new_cfg->etscfg))) {
  4330. /* If Priority Table has changed reconfig is needed */
  4331. if (memcmp(&new_cfg->etscfg.prioritytable,
  4332. &old_cfg->etscfg.prioritytable,
  4333. sizeof(new_cfg->etscfg.prioritytable))) {
  4334. need_reconfig = true;
  4335. dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
  4336. }
  4337. if (memcmp(&new_cfg->etscfg.tcbwtable,
  4338. &old_cfg->etscfg.tcbwtable,
  4339. sizeof(new_cfg->etscfg.tcbwtable)))
  4340. dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
  4341. if (memcmp(&new_cfg->etscfg.tsatable,
  4342. &old_cfg->etscfg.tsatable,
  4343. sizeof(new_cfg->etscfg.tsatable)))
  4344. dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
  4345. }
  4346. /* Check if PFC configuration has changed */
  4347. if (memcmp(&new_cfg->pfc,
  4348. &old_cfg->pfc,
  4349. sizeof(new_cfg->pfc))) {
  4350. need_reconfig = true;
  4351. dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
  4352. }
  4353. /* Check if APP Table has changed */
  4354. if (memcmp(&new_cfg->app,
  4355. &old_cfg->app,
  4356. sizeof(new_cfg->app))) {
  4357. need_reconfig = true;
  4358. dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
  4359. }
  4360. return need_reconfig;
  4361. }
  4362. /**
  4363. * i40e_handle_lldp_event - Handle LLDP Change MIB event
  4364. * @pf: board private structure
  4365. * @e: event info posted on ARQ
  4366. **/
  4367. static int i40e_handle_lldp_event(struct i40e_pf *pf,
  4368. struct i40e_arq_event_info *e)
  4369. {
  4370. struct i40e_aqc_lldp_get_mib *mib =
  4371. (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
  4372. struct i40e_hw *hw = &pf->hw;
  4373. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  4374. struct i40e_dcbx_config tmp_dcbx_cfg;
  4375. bool need_reconfig = false;
  4376. int ret = 0;
  4377. u8 type;
  4378. /* Not DCB capable or capability disabled */
  4379. if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
  4380. return ret;
  4381. /* Ignore if event is not for Nearest Bridge */
  4382. type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
  4383. & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  4384. if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
  4385. return ret;
  4386. /* Check MIB Type and return if event for Remote MIB update */
  4387. type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  4388. if (type == I40E_AQ_LLDP_MIB_REMOTE) {
  4389. /* Update the remote cached instance and return */
  4390. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  4391. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  4392. &hw->remote_dcbx_config);
  4393. goto exit;
  4394. }
  4395. /* Convert/store the DCBX data from LLDPDU temporarily */
  4396. memset(&tmp_dcbx_cfg, 0, sizeof(tmp_dcbx_cfg));
  4397. ret = i40e_lldp_to_dcb_config(e->msg_buf, &tmp_dcbx_cfg);
  4398. if (ret) {
  4399. /* Error in LLDPDU parsing return */
  4400. dev_info(&pf->pdev->dev, "Failed parsing LLDPDU from event buffer\n");
  4401. goto exit;
  4402. }
  4403. /* No change detected in DCBX configs */
  4404. if (!memcmp(&tmp_dcbx_cfg, dcbx_cfg, sizeof(tmp_dcbx_cfg))) {
  4405. dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
  4406. goto exit;
  4407. }
  4408. need_reconfig = i40e_dcb_need_reconfig(pf, dcbx_cfg, &tmp_dcbx_cfg);
  4409. i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg);
  4410. /* Overwrite the new configuration */
  4411. *dcbx_cfg = tmp_dcbx_cfg;
  4412. if (!need_reconfig)
  4413. goto exit;
  4414. /* Enable DCB tagging only when more than one TC */
  4415. if (i40e_dcb_get_num_tc(dcbx_cfg) > 1)
  4416. pf->flags |= I40E_FLAG_DCB_ENABLED;
  4417. else
  4418. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  4419. /* Reconfiguration needed quiesce all VSIs */
  4420. i40e_pf_quiesce_all_vsi(pf);
  4421. /* Changes in configuration update VEB/VSI */
  4422. i40e_dcb_reconfigure(pf);
  4423. i40e_pf_unquiesce_all_vsi(pf);
  4424. exit:
  4425. return ret;
  4426. }
  4427. #endif /* CONFIG_I40E_DCB */
  4428. /**
  4429. * i40e_do_reset_safe - Protected reset path for userland calls.
  4430. * @pf: board private structure
  4431. * @reset_flags: which reset is requested
  4432. *
  4433. **/
  4434. void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
  4435. {
  4436. rtnl_lock();
  4437. i40e_do_reset(pf, reset_flags);
  4438. rtnl_unlock();
  4439. }
  4440. /**
  4441. * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
  4442. * @pf: board private structure
  4443. * @e: event info posted on ARQ
  4444. *
  4445. * Handler for LAN Queue Overflow Event generated by the firmware for PF
  4446. * and VF queues
  4447. **/
  4448. static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
  4449. struct i40e_arq_event_info *e)
  4450. {
  4451. struct i40e_aqc_lan_overflow *data =
  4452. (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
  4453. u32 queue = le32_to_cpu(data->prtdcb_rupto);
  4454. u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
  4455. struct i40e_hw *hw = &pf->hw;
  4456. struct i40e_vf *vf;
  4457. u16 vf_id;
  4458. dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
  4459. queue, qtx_ctl);
  4460. /* Queue belongs to VF, find the VF and issue VF reset */
  4461. if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
  4462. >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
  4463. vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
  4464. >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
  4465. vf_id -= hw->func_caps.vf_base_id;
  4466. vf = &pf->vf[vf_id];
  4467. i40e_vc_notify_vf_reset(vf);
  4468. /* Allow VF to process pending reset notification */
  4469. msleep(20);
  4470. i40e_reset_vf(vf, false);
  4471. }
  4472. }
  4473. /**
  4474. * i40e_service_event_complete - Finish up the service event
  4475. * @pf: board private structure
  4476. **/
  4477. static void i40e_service_event_complete(struct i40e_pf *pf)
  4478. {
  4479. BUG_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state));
  4480. /* flush memory to make sure state is correct before next watchog */
  4481. smp_mb__before_atomic();
  4482. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  4483. }
  4484. /**
  4485. * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
  4486. * @pf: board private structure
  4487. **/
  4488. int i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
  4489. {
  4490. int val, fcnt_prog;
  4491. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  4492. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
  4493. return fcnt_prog;
  4494. }
  4495. /**
  4496. * i40e_get_current_fd_count - Get the count of total FD filters programmed
  4497. * @pf: board private structure
  4498. **/
  4499. int i40e_get_current_fd_count(struct i40e_pf *pf)
  4500. {
  4501. int val, fcnt_prog;
  4502. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  4503. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
  4504. ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
  4505. I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
  4506. return fcnt_prog;
  4507. }
  4508. /**
  4509. * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
  4510. * @pf: board private structure
  4511. **/
  4512. void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
  4513. {
  4514. u32 fcnt_prog, fcnt_avail;
  4515. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  4516. return;
  4517. /* Check if, FD SB or ATR was auto disabled and if there is enough room
  4518. * to re-enable
  4519. */
  4520. fcnt_prog = i40e_get_cur_guaranteed_fd_count(pf);
  4521. fcnt_avail = pf->fdir_pf_filter_count;
  4522. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
  4523. (pf->fd_add_err == 0) ||
  4524. (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
  4525. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  4526. (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) {
  4527. pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
  4528. dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
  4529. }
  4530. }
  4531. /* Wait for some more space to be available to turn on ATR */
  4532. if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) {
  4533. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  4534. (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) {
  4535. pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  4536. dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table now\n");
  4537. }
  4538. }
  4539. }
  4540. #define I40E_MIN_FD_FLUSH_INTERVAL 10
  4541. /**
  4542. * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
  4543. * @pf: board private structure
  4544. **/
  4545. static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
  4546. {
  4547. int flush_wait_retry = 50;
  4548. int reg;
  4549. if (time_after(jiffies, pf->fd_flush_timestamp +
  4550. (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) {
  4551. set_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
  4552. pf->fd_flush_timestamp = jiffies;
  4553. pf->auto_disable_flags |= I40E_FLAG_FD_SB_ENABLED;
  4554. pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  4555. /* flush all filters */
  4556. wr32(&pf->hw, I40E_PFQF_CTL_1,
  4557. I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
  4558. i40e_flush(&pf->hw);
  4559. pf->fd_flush_cnt++;
  4560. pf->fd_add_err = 0;
  4561. do {
  4562. /* Check FD flush status every 5-6msec */
  4563. usleep_range(5000, 6000);
  4564. reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
  4565. if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
  4566. break;
  4567. } while (flush_wait_retry--);
  4568. if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
  4569. dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
  4570. } else {
  4571. /* replay sideband filters */
  4572. i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
  4573. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  4574. pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  4575. pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
  4576. clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
  4577. dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
  4578. }
  4579. }
  4580. }
  4581. /**
  4582. * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
  4583. * @pf: board private structure
  4584. **/
  4585. int i40e_get_current_atr_cnt(struct i40e_pf *pf)
  4586. {
  4587. return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
  4588. }
  4589. /* We can see up to 256 filter programming desc in transit if the filters are
  4590. * being applied really fast; before we see the first
  4591. * filter miss error on Rx queue 0. Accumulating enough error messages before
  4592. * reacting will make sure we don't cause flush too often.
  4593. */
  4594. #define I40E_MAX_FD_PROGRAM_ERROR 256
  4595. /**
  4596. * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
  4597. * @pf: board private structure
  4598. **/
  4599. static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
  4600. {
  4601. /* if interface is down do nothing */
  4602. if (test_bit(__I40E_DOWN, &pf->state))
  4603. return;
  4604. if ((pf->fd_add_err >= I40E_MAX_FD_PROGRAM_ERROR) &&
  4605. (i40e_get_current_atr_cnt(pf) >= pf->fd_atr_cnt) &&
  4606. (i40e_get_current_atr_cnt(pf) > pf->fdir_pf_filter_count))
  4607. i40e_fdir_flush_and_replay(pf);
  4608. i40e_fdir_check_and_reenable(pf);
  4609. }
  4610. /**
  4611. * i40e_vsi_link_event - notify VSI of a link event
  4612. * @vsi: vsi to be notified
  4613. * @link_up: link up or down
  4614. **/
  4615. static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
  4616. {
  4617. if (!vsi || test_bit(__I40E_DOWN, &vsi->state))
  4618. return;
  4619. switch (vsi->type) {
  4620. case I40E_VSI_MAIN:
  4621. #ifdef I40E_FCOE
  4622. case I40E_VSI_FCOE:
  4623. #endif
  4624. if (!vsi->netdev || !vsi->netdev_registered)
  4625. break;
  4626. if (link_up) {
  4627. netif_carrier_on(vsi->netdev);
  4628. netif_tx_wake_all_queues(vsi->netdev);
  4629. } else {
  4630. netif_carrier_off(vsi->netdev);
  4631. netif_tx_stop_all_queues(vsi->netdev);
  4632. }
  4633. break;
  4634. case I40E_VSI_SRIOV:
  4635. break;
  4636. case I40E_VSI_VMDQ2:
  4637. case I40E_VSI_CTRL:
  4638. case I40E_VSI_MIRROR:
  4639. default:
  4640. /* there is no notification for other VSIs */
  4641. break;
  4642. }
  4643. }
  4644. /**
  4645. * i40e_veb_link_event - notify elements on the veb of a link event
  4646. * @veb: veb to be notified
  4647. * @link_up: link up or down
  4648. **/
  4649. static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
  4650. {
  4651. struct i40e_pf *pf;
  4652. int i;
  4653. if (!veb || !veb->pf)
  4654. return;
  4655. pf = veb->pf;
  4656. /* depth first... */
  4657. for (i = 0; i < I40E_MAX_VEB; i++)
  4658. if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
  4659. i40e_veb_link_event(pf->veb[i], link_up);
  4660. /* ... now the local VSIs */
  4661. for (i = 0; i < pf->num_alloc_vsi; i++)
  4662. if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
  4663. i40e_vsi_link_event(pf->vsi[i], link_up);
  4664. }
  4665. /**
  4666. * i40e_link_event - Update netif_carrier status
  4667. * @pf: board private structure
  4668. **/
  4669. static void i40e_link_event(struct i40e_pf *pf)
  4670. {
  4671. bool new_link, old_link;
  4672. new_link = (pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP);
  4673. old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
  4674. if (new_link == old_link)
  4675. return;
  4676. if (!test_bit(__I40E_DOWN, &pf->vsi[pf->lan_vsi]->state))
  4677. i40e_print_link_message(pf->vsi[pf->lan_vsi], new_link);
  4678. /* Notify the base of the switch tree connected to
  4679. * the link. Floating VEBs are not notified.
  4680. */
  4681. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  4682. i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
  4683. else
  4684. i40e_vsi_link_event(pf->vsi[pf->lan_vsi], new_link);
  4685. if (pf->vf)
  4686. i40e_vc_notify_link_state(pf);
  4687. if (pf->flags & I40E_FLAG_PTP)
  4688. i40e_ptp_set_increment(pf);
  4689. }
  4690. /**
  4691. * i40e_check_hang_subtask - Check for hung queues and dropped interrupts
  4692. * @pf: board private structure
  4693. *
  4694. * Set the per-queue flags to request a check for stuck queues in the irq
  4695. * clean functions, then force interrupts to be sure the irq clean is called.
  4696. **/
  4697. static void i40e_check_hang_subtask(struct i40e_pf *pf)
  4698. {
  4699. int i, v;
  4700. /* If we're down or resetting, just bail */
  4701. if (test_bit(__I40E_CONFIG_BUSY, &pf->state))
  4702. return;
  4703. /* for each VSI/netdev
  4704. * for each Tx queue
  4705. * set the check flag
  4706. * for each q_vector
  4707. * force an interrupt
  4708. */
  4709. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4710. struct i40e_vsi *vsi = pf->vsi[v];
  4711. int armed = 0;
  4712. if (!pf->vsi[v] ||
  4713. test_bit(__I40E_DOWN, &vsi->state) ||
  4714. (vsi->netdev && !netif_carrier_ok(vsi->netdev)))
  4715. continue;
  4716. for (i = 0; i < vsi->num_queue_pairs; i++) {
  4717. set_check_for_tx_hang(vsi->tx_rings[i]);
  4718. if (test_bit(__I40E_HANG_CHECK_ARMED,
  4719. &vsi->tx_rings[i]->state))
  4720. armed++;
  4721. }
  4722. if (armed) {
  4723. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  4724. wr32(&vsi->back->hw, I40E_PFINT_DYN_CTL0,
  4725. (I40E_PFINT_DYN_CTL0_INTENA_MASK |
  4726. I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
  4727. } else {
  4728. u16 vec = vsi->base_vector - 1;
  4729. u32 val = (I40E_PFINT_DYN_CTLN_INTENA_MASK |
  4730. I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK);
  4731. for (i = 0; i < vsi->num_q_vectors; i++, vec++)
  4732. wr32(&vsi->back->hw,
  4733. I40E_PFINT_DYN_CTLN(vec), val);
  4734. }
  4735. i40e_flush(&vsi->back->hw);
  4736. }
  4737. }
  4738. }
  4739. /**
  4740. * i40e_watchdog_subtask - Check and bring link up
  4741. * @pf: board private structure
  4742. **/
  4743. static void i40e_watchdog_subtask(struct i40e_pf *pf)
  4744. {
  4745. int i;
  4746. /* if interface is down do nothing */
  4747. if (test_bit(__I40E_DOWN, &pf->state) ||
  4748. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  4749. return;
  4750. /* Update the stats for active netdevs so the network stack
  4751. * can look at updated numbers whenever it cares to
  4752. */
  4753. for (i = 0; i < pf->num_alloc_vsi; i++)
  4754. if (pf->vsi[i] && pf->vsi[i]->netdev)
  4755. i40e_update_stats(pf->vsi[i]);
  4756. /* Update the stats for the active switching components */
  4757. for (i = 0; i < I40E_MAX_VEB; i++)
  4758. if (pf->veb[i])
  4759. i40e_update_veb_stats(pf->veb[i]);
  4760. i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
  4761. }
  4762. /**
  4763. * i40e_reset_subtask - Set up for resetting the device and driver
  4764. * @pf: board private structure
  4765. **/
  4766. static void i40e_reset_subtask(struct i40e_pf *pf)
  4767. {
  4768. u32 reset_flags = 0;
  4769. rtnl_lock();
  4770. if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
  4771. reset_flags |= (1 << __I40E_REINIT_REQUESTED);
  4772. clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
  4773. }
  4774. if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
  4775. reset_flags |= (1 << __I40E_PF_RESET_REQUESTED);
  4776. clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  4777. }
  4778. if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
  4779. reset_flags |= (1 << __I40E_CORE_RESET_REQUESTED);
  4780. clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  4781. }
  4782. if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
  4783. reset_flags |= (1 << __I40E_GLOBAL_RESET_REQUESTED);
  4784. clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  4785. }
  4786. if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) {
  4787. reset_flags |= (1 << __I40E_DOWN_REQUESTED);
  4788. clear_bit(__I40E_DOWN_REQUESTED, &pf->state);
  4789. }
  4790. /* If there's a recovery already waiting, it takes
  4791. * precedence before starting a new reset sequence.
  4792. */
  4793. if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
  4794. i40e_handle_reset_warning(pf);
  4795. goto unlock;
  4796. }
  4797. /* If we're already down or resetting, just bail */
  4798. if (reset_flags &&
  4799. !test_bit(__I40E_DOWN, &pf->state) &&
  4800. !test_bit(__I40E_CONFIG_BUSY, &pf->state))
  4801. i40e_do_reset(pf, reset_flags);
  4802. unlock:
  4803. rtnl_unlock();
  4804. }
  4805. /**
  4806. * i40e_handle_link_event - Handle link event
  4807. * @pf: board private structure
  4808. * @e: event info posted on ARQ
  4809. **/
  4810. static void i40e_handle_link_event(struct i40e_pf *pf,
  4811. struct i40e_arq_event_info *e)
  4812. {
  4813. struct i40e_hw *hw = &pf->hw;
  4814. struct i40e_aqc_get_link_status *status =
  4815. (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
  4816. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  4817. /* save off old link status information */
  4818. memcpy(&pf->hw.phy.link_info_old, hw_link_info,
  4819. sizeof(pf->hw.phy.link_info_old));
  4820. /* check for unqualified module, if link is down */
  4821. if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
  4822. (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
  4823. (!(status->link_info & I40E_AQ_LINK_UP)))
  4824. dev_err(&pf->pdev->dev,
  4825. "The driver failed to link because an unqualified module was detected.\n");
  4826. /* update link status */
  4827. hw_link_info->phy_type = (enum i40e_aq_phy_type)status->phy_type;
  4828. hw_link_info->link_speed = (enum i40e_aq_link_speed)status->link_speed;
  4829. hw_link_info->link_info = status->link_info;
  4830. hw_link_info->an_info = status->an_info;
  4831. hw_link_info->ext_info = status->ext_info;
  4832. hw_link_info->lse_enable =
  4833. le16_to_cpu(status->command_flags) &
  4834. I40E_AQ_LSE_ENABLE;
  4835. /* process the event */
  4836. i40e_link_event(pf);
  4837. /* Do a new status request to re-enable LSE reporting
  4838. * and load new status information into the hw struct,
  4839. * then see if the status changed while processing the
  4840. * initial event.
  4841. */
  4842. i40e_update_link_info(&pf->hw, true);
  4843. i40e_link_event(pf);
  4844. }
  4845. /**
  4846. * i40e_clean_adminq_subtask - Clean the AdminQ rings
  4847. * @pf: board private structure
  4848. **/
  4849. static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
  4850. {
  4851. struct i40e_arq_event_info event;
  4852. struct i40e_hw *hw = &pf->hw;
  4853. u16 pending, i = 0;
  4854. i40e_status ret;
  4855. u16 opcode;
  4856. u32 oldval;
  4857. u32 val;
  4858. /* Do not run clean AQ when PF reset fails */
  4859. if (test_bit(__I40E_RESET_FAILED, &pf->state))
  4860. return;
  4861. /* check for error indications */
  4862. val = rd32(&pf->hw, pf->hw.aq.arq.len);
  4863. oldval = val;
  4864. if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
  4865. dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
  4866. val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
  4867. }
  4868. if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
  4869. dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
  4870. val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
  4871. }
  4872. if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
  4873. dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
  4874. val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
  4875. }
  4876. if (oldval != val)
  4877. wr32(&pf->hw, pf->hw.aq.arq.len, val);
  4878. val = rd32(&pf->hw, pf->hw.aq.asq.len);
  4879. oldval = val;
  4880. if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
  4881. dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
  4882. val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
  4883. }
  4884. if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
  4885. dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
  4886. val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
  4887. }
  4888. if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
  4889. dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
  4890. val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
  4891. }
  4892. if (oldval != val)
  4893. wr32(&pf->hw, pf->hw.aq.asq.len, val);
  4894. event.msg_size = I40E_MAX_AQ_BUF_SIZE;
  4895. event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
  4896. if (!event.msg_buf)
  4897. return;
  4898. do {
  4899. event.msg_size = I40E_MAX_AQ_BUF_SIZE; /* reinit each time */
  4900. ret = i40e_clean_arq_element(hw, &event, &pending);
  4901. if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
  4902. break;
  4903. else if (ret) {
  4904. dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
  4905. break;
  4906. }
  4907. opcode = le16_to_cpu(event.desc.opcode);
  4908. switch (opcode) {
  4909. case i40e_aqc_opc_get_link_status:
  4910. i40e_handle_link_event(pf, &event);
  4911. break;
  4912. case i40e_aqc_opc_send_msg_to_pf:
  4913. ret = i40e_vc_process_vf_msg(pf,
  4914. le16_to_cpu(event.desc.retval),
  4915. le32_to_cpu(event.desc.cookie_high),
  4916. le32_to_cpu(event.desc.cookie_low),
  4917. event.msg_buf,
  4918. event.msg_size);
  4919. break;
  4920. case i40e_aqc_opc_lldp_update_mib:
  4921. dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
  4922. #ifdef CONFIG_I40E_DCB
  4923. rtnl_lock();
  4924. ret = i40e_handle_lldp_event(pf, &event);
  4925. rtnl_unlock();
  4926. #endif /* CONFIG_I40E_DCB */
  4927. break;
  4928. case i40e_aqc_opc_event_lan_overflow:
  4929. dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
  4930. i40e_handle_lan_overflow_event(pf, &event);
  4931. break;
  4932. case i40e_aqc_opc_send_msg_to_peer:
  4933. dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
  4934. break;
  4935. default:
  4936. dev_info(&pf->pdev->dev,
  4937. "ARQ Error: Unknown event 0x%04x received\n",
  4938. opcode);
  4939. break;
  4940. }
  4941. } while (pending && (i++ < pf->adminq_work_limit));
  4942. clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  4943. /* re-enable Admin queue interrupt cause */
  4944. val = rd32(hw, I40E_PFINT_ICR0_ENA);
  4945. val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  4946. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  4947. i40e_flush(hw);
  4948. kfree(event.msg_buf);
  4949. }
  4950. /**
  4951. * i40e_verify_eeprom - make sure eeprom is good to use
  4952. * @pf: board private structure
  4953. **/
  4954. static void i40e_verify_eeprom(struct i40e_pf *pf)
  4955. {
  4956. int err;
  4957. err = i40e_diag_eeprom_test(&pf->hw);
  4958. if (err) {
  4959. /* retry in case of garbage read */
  4960. err = i40e_diag_eeprom_test(&pf->hw);
  4961. if (err) {
  4962. dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
  4963. err);
  4964. set_bit(__I40E_BAD_EEPROM, &pf->state);
  4965. }
  4966. }
  4967. if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  4968. dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
  4969. clear_bit(__I40E_BAD_EEPROM, &pf->state);
  4970. }
  4971. }
  4972. /**
  4973. * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
  4974. * @veb: pointer to the VEB instance
  4975. *
  4976. * This is a recursive function that first builds the attached VSIs then
  4977. * recurses in to build the next layer of VEB. We track the connections
  4978. * through our own index numbers because the seid's from the HW could
  4979. * change across the reset.
  4980. **/
  4981. static int i40e_reconstitute_veb(struct i40e_veb *veb)
  4982. {
  4983. struct i40e_vsi *ctl_vsi = NULL;
  4984. struct i40e_pf *pf = veb->pf;
  4985. int v, veb_idx;
  4986. int ret;
  4987. /* build VSI that owns this VEB, temporarily attached to base VEB */
  4988. for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
  4989. if (pf->vsi[v] &&
  4990. pf->vsi[v]->veb_idx == veb->idx &&
  4991. pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
  4992. ctl_vsi = pf->vsi[v];
  4993. break;
  4994. }
  4995. }
  4996. if (!ctl_vsi) {
  4997. dev_info(&pf->pdev->dev,
  4998. "missing owner VSI for veb_idx %d\n", veb->idx);
  4999. ret = -ENOENT;
  5000. goto end_reconstitute;
  5001. }
  5002. if (ctl_vsi != pf->vsi[pf->lan_vsi])
  5003. ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  5004. ret = i40e_add_vsi(ctl_vsi);
  5005. if (ret) {
  5006. dev_info(&pf->pdev->dev,
  5007. "rebuild of owner VSI failed: %d\n", ret);
  5008. goto end_reconstitute;
  5009. }
  5010. i40e_vsi_reset_stats(ctl_vsi);
  5011. /* create the VEB in the switch and move the VSI onto the VEB */
  5012. ret = i40e_add_veb(veb, ctl_vsi);
  5013. if (ret)
  5014. goto end_reconstitute;
  5015. /* create the remaining VSIs attached to this VEB */
  5016. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5017. if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
  5018. continue;
  5019. if (pf->vsi[v]->veb_idx == veb->idx) {
  5020. struct i40e_vsi *vsi = pf->vsi[v];
  5021. vsi->uplink_seid = veb->seid;
  5022. ret = i40e_add_vsi(vsi);
  5023. if (ret) {
  5024. dev_info(&pf->pdev->dev,
  5025. "rebuild of vsi_idx %d failed: %d\n",
  5026. v, ret);
  5027. goto end_reconstitute;
  5028. }
  5029. i40e_vsi_reset_stats(vsi);
  5030. }
  5031. }
  5032. /* create any VEBs attached to this VEB - RECURSION */
  5033. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  5034. if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
  5035. pf->veb[veb_idx]->uplink_seid = veb->seid;
  5036. ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
  5037. if (ret)
  5038. break;
  5039. }
  5040. }
  5041. end_reconstitute:
  5042. return ret;
  5043. }
  5044. /**
  5045. * i40e_get_capabilities - get info about the HW
  5046. * @pf: the PF struct
  5047. **/
  5048. static int i40e_get_capabilities(struct i40e_pf *pf)
  5049. {
  5050. struct i40e_aqc_list_capabilities_element_resp *cap_buf;
  5051. u16 data_size;
  5052. int buf_len;
  5053. int err;
  5054. buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
  5055. do {
  5056. cap_buf = kzalloc(buf_len, GFP_KERNEL);
  5057. if (!cap_buf)
  5058. return -ENOMEM;
  5059. /* this loads the data into the hw struct for us */
  5060. err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
  5061. &data_size,
  5062. i40e_aqc_opc_list_func_capabilities,
  5063. NULL);
  5064. /* data loaded, buffer no longer needed */
  5065. kfree(cap_buf);
  5066. if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
  5067. /* retry with a larger buffer */
  5068. buf_len = data_size;
  5069. } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
  5070. dev_info(&pf->pdev->dev,
  5071. "capability discovery failed: aq=%d\n",
  5072. pf->hw.aq.asq_last_status);
  5073. return -ENODEV;
  5074. }
  5075. } while (err);
  5076. if (((pf->hw.aq.fw_maj_ver == 2) && (pf->hw.aq.fw_min_ver < 22)) ||
  5077. (pf->hw.aq.fw_maj_ver < 2)) {
  5078. pf->hw.func_caps.num_msix_vectors++;
  5079. pf->hw.func_caps.num_msix_vectors_vf++;
  5080. }
  5081. if (pf->hw.debug_mask & I40E_DEBUG_USER)
  5082. dev_info(&pf->pdev->dev,
  5083. "pf=%d, num_vfs=%d, msix_pf=%d, msix_vf=%d, fd_g=%d, fd_b=%d, pf_max_q=%d num_vsi=%d\n",
  5084. pf->hw.pf_id, pf->hw.func_caps.num_vfs,
  5085. pf->hw.func_caps.num_msix_vectors,
  5086. pf->hw.func_caps.num_msix_vectors_vf,
  5087. pf->hw.func_caps.fd_filters_guaranteed,
  5088. pf->hw.func_caps.fd_filters_best_effort,
  5089. pf->hw.func_caps.num_tx_qp,
  5090. pf->hw.func_caps.num_vsis);
  5091. #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
  5092. + pf->hw.func_caps.num_vfs)
  5093. if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
  5094. dev_info(&pf->pdev->dev,
  5095. "got num_vsis %d, setting num_vsis to %d\n",
  5096. pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
  5097. pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
  5098. }
  5099. return 0;
  5100. }
  5101. static int i40e_vsi_clear(struct i40e_vsi *vsi);
  5102. /**
  5103. * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
  5104. * @pf: board private structure
  5105. **/
  5106. static void i40e_fdir_sb_setup(struct i40e_pf *pf)
  5107. {
  5108. struct i40e_vsi *vsi;
  5109. int i;
  5110. /* quick workaround for an NVM issue that leaves a critical register
  5111. * uninitialized
  5112. */
  5113. if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
  5114. static const u32 hkey[] = {
  5115. 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
  5116. 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
  5117. 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
  5118. 0x95b3a76d};
  5119. for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
  5120. wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
  5121. }
  5122. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  5123. return;
  5124. /* find existing VSI and see if it needs configuring */
  5125. vsi = NULL;
  5126. for (i = 0; i < pf->num_alloc_vsi; i++) {
  5127. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  5128. vsi = pf->vsi[i];
  5129. break;
  5130. }
  5131. }
  5132. /* create a new VSI if none exists */
  5133. if (!vsi) {
  5134. vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
  5135. pf->vsi[pf->lan_vsi]->seid, 0);
  5136. if (!vsi) {
  5137. dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
  5138. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  5139. return;
  5140. }
  5141. }
  5142. i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
  5143. }
  5144. /**
  5145. * i40e_fdir_teardown - release the Flow Director resources
  5146. * @pf: board private structure
  5147. **/
  5148. static void i40e_fdir_teardown(struct i40e_pf *pf)
  5149. {
  5150. int i;
  5151. i40e_fdir_filter_exit(pf);
  5152. for (i = 0; i < pf->num_alloc_vsi; i++) {
  5153. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  5154. i40e_vsi_release(pf->vsi[i]);
  5155. break;
  5156. }
  5157. }
  5158. }
  5159. /**
  5160. * i40e_prep_for_reset - prep for the core to reset
  5161. * @pf: board private structure
  5162. *
  5163. * Close up the VFs and other things in prep for pf Reset.
  5164. **/
  5165. static void i40e_prep_for_reset(struct i40e_pf *pf)
  5166. {
  5167. struct i40e_hw *hw = &pf->hw;
  5168. i40e_status ret = 0;
  5169. u32 v;
  5170. clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  5171. if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  5172. return;
  5173. dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
  5174. /* quiesce the VSIs and their queues that are not already DOWN */
  5175. i40e_pf_quiesce_all_vsi(pf);
  5176. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5177. if (pf->vsi[v])
  5178. pf->vsi[v]->seid = 0;
  5179. }
  5180. i40e_shutdown_adminq(&pf->hw);
  5181. /* call shutdown HMC */
  5182. if (hw->hmc.hmc_obj) {
  5183. ret = i40e_shutdown_lan_hmc(hw);
  5184. if (ret)
  5185. dev_warn(&pf->pdev->dev,
  5186. "shutdown_lan_hmc failed: %d\n", ret);
  5187. }
  5188. }
  5189. /**
  5190. * i40e_send_version - update firmware with driver version
  5191. * @pf: PF struct
  5192. */
  5193. static void i40e_send_version(struct i40e_pf *pf)
  5194. {
  5195. struct i40e_driver_version dv;
  5196. dv.major_version = DRV_VERSION_MAJOR;
  5197. dv.minor_version = DRV_VERSION_MINOR;
  5198. dv.build_version = DRV_VERSION_BUILD;
  5199. dv.subbuild_version = 0;
  5200. strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
  5201. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  5202. }
  5203. /**
  5204. * i40e_reset_and_rebuild - reset and rebuild using a saved config
  5205. * @pf: board private structure
  5206. * @reinit: if the Main VSI needs to re-initialized.
  5207. **/
  5208. static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
  5209. {
  5210. struct i40e_hw *hw = &pf->hw;
  5211. i40e_status ret;
  5212. u32 v;
  5213. /* Now we wait for GRST to settle out.
  5214. * We don't have to delete the VEBs or VSIs from the hw switch
  5215. * because the reset will make them disappear.
  5216. */
  5217. ret = i40e_pf_reset(hw);
  5218. if (ret) {
  5219. dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
  5220. set_bit(__I40E_RESET_FAILED, &pf->state);
  5221. goto clear_recovery;
  5222. }
  5223. pf->pfr_count++;
  5224. if (test_bit(__I40E_DOWN, &pf->state))
  5225. goto clear_recovery;
  5226. dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
  5227. /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
  5228. ret = i40e_init_adminq(&pf->hw);
  5229. if (ret) {
  5230. dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, %d\n", ret);
  5231. goto clear_recovery;
  5232. }
  5233. /* re-verify the eeprom if we just had an EMP reset */
  5234. if (test_bit(__I40E_EMP_RESET_REQUESTED, &pf->state)) {
  5235. clear_bit(__I40E_EMP_RESET_REQUESTED, &pf->state);
  5236. i40e_verify_eeprom(pf);
  5237. }
  5238. i40e_clear_pxe_mode(hw);
  5239. ret = i40e_get_capabilities(pf);
  5240. if (ret) {
  5241. dev_info(&pf->pdev->dev, "i40e_get_capabilities failed, %d\n",
  5242. ret);
  5243. goto end_core_reset;
  5244. }
  5245. ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  5246. hw->func_caps.num_rx_qp,
  5247. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  5248. if (ret) {
  5249. dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
  5250. goto end_core_reset;
  5251. }
  5252. ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  5253. if (ret) {
  5254. dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
  5255. goto end_core_reset;
  5256. }
  5257. #ifdef CONFIG_I40E_DCB
  5258. ret = i40e_init_pf_dcb(pf);
  5259. if (ret) {
  5260. dev_info(&pf->pdev->dev, "init_pf_dcb failed: %d\n", ret);
  5261. goto end_core_reset;
  5262. }
  5263. #endif /* CONFIG_I40E_DCB */
  5264. #ifdef I40E_FCOE
  5265. ret = i40e_init_pf_fcoe(pf);
  5266. if (ret)
  5267. dev_info(&pf->pdev->dev, "init_pf_fcoe failed: %d\n", ret);
  5268. #endif
  5269. /* do basic switch setup */
  5270. ret = i40e_setup_pf_switch(pf, reinit);
  5271. if (ret)
  5272. goto end_core_reset;
  5273. /* Rebuild the VSIs and VEBs that existed before reset.
  5274. * They are still in our local switch element arrays, so only
  5275. * need to rebuild the switch model in the HW.
  5276. *
  5277. * If there were VEBs but the reconstitution failed, we'll try
  5278. * try to recover minimal use by getting the basic PF VSI working.
  5279. */
  5280. if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
  5281. dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
  5282. /* find the one VEB connected to the MAC, and find orphans */
  5283. for (v = 0; v < I40E_MAX_VEB; v++) {
  5284. if (!pf->veb[v])
  5285. continue;
  5286. if (pf->veb[v]->uplink_seid == pf->mac_seid ||
  5287. pf->veb[v]->uplink_seid == 0) {
  5288. ret = i40e_reconstitute_veb(pf->veb[v]);
  5289. if (!ret)
  5290. continue;
  5291. /* If Main VEB failed, we're in deep doodoo,
  5292. * so give up rebuilding the switch and set up
  5293. * for minimal rebuild of PF VSI.
  5294. * If orphan failed, we'll report the error
  5295. * but try to keep going.
  5296. */
  5297. if (pf->veb[v]->uplink_seid == pf->mac_seid) {
  5298. dev_info(&pf->pdev->dev,
  5299. "rebuild of switch failed: %d, will try to set up simple PF connection\n",
  5300. ret);
  5301. pf->vsi[pf->lan_vsi]->uplink_seid
  5302. = pf->mac_seid;
  5303. break;
  5304. } else if (pf->veb[v]->uplink_seid == 0) {
  5305. dev_info(&pf->pdev->dev,
  5306. "rebuild of orphan VEB failed: %d\n",
  5307. ret);
  5308. }
  5309. }
  5310. }
  5311. }
  5312. if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
  5313. dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
  5314. /* no VEB, so rebuild only the Main VSI */
  5315. ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
  5316. if (ret) {
  5317. dev_info(&pf->pdev->dev,
  5318. "rebuild of Main VSI failed: %d\n", ret);
  5319. goto end_core_reset;
  5320. }
  5321. }
  5322. /* reinit the misc interrupt */
  5323. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  5324. ret = i40e_setup_misc_vector(pf);
  5325. /* restart the VSIs that were rebuilt and running before the reset */
  5326. i40e_pf_unquiesce_all_vsi(pf);
  5327. if (pf->num_alloc_vfs) {
  5328. for (v = 0; v < pf->num_alloc_vfs; v++)
  5329. i40e_reset_vf(&pf->vf[v], true);
  5330. }
  5331. /* tell the firmware that we're starting */
  5332. i40e_send_version(pf);
  5333. end_core_reset:
  5334. clear_bit(__I40E_RESET_FAILED, &pf->state);
  5335. clear_recovery:
  5336. clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
  5337. }
  5338. /**
  5339. * i40e_handle_reset_warning - prep for the pf to reset, reset and rebuild
  5340. * @pf: board private structure
  5341. *
  5342. * Close up the VFs and other things in prep for a Core Reset,
  5343. * then get ready to rebuild the world.
  5344. **/
  5345. static void i40e_handle_reset_warning(struct i40e_pf *pf)
  5346. {
  5347. i40e_prep_for_reset(pf);
  5348. i40e_reset_and_rebuild(pf, false);
  5349. }
  5350. /**
  5351. * i40e_handle_mdd_event
  5352. * @pf: pointer to the pf structure
  5353. *
  5354. * Called from the MDD irq handler to identify possibly malicious vfs
  5355. **/
  5356. static void i40e_handle_mdd_event(struct i40e_pf *pf)
  5357. {
  5358. struct i40e_hw *hw = &pf->hw;
  5359. bool mdd_detected = false;
  5360. bool pf_mdd_detected = false;
  5361. struct i40e_vf *vf;
  5362. u32 reg;
  5363. int i;
  5364. if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
  5365. return;
  5366. /* find what triggered the MDD event */
  5367. reg = rd32(hw, I40E_GL_MDET_TX);
  5368. if (reg & I40E_GL_MDET_TX_VALID_MASK) {
  5369. u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
  5370. I40E_GL_MDET_TX_PF_NUM_SHIFT;
  5371. u8 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
  5372. I40E_GL_MDET_TX_VF_NUM_SHIFT;
  5373. u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
  5374. I40E_GL_MDET_TX_EVENT_SHIFT;
  5375. u8 queue = (reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
  5376. I40E_GL_MDET_TX_QUEUE_SHIFT;
  5377. if (netif_msg_tx_err(pf))
  5378. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on TX queue %d pf number 0x%02x vf number 0x%02x\n",
  5379. event, queue, pf_num, vf_num);
  5380. wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
  5381. mdd_detected = true;
  5382. }
  5383. reg = rd32(hw, I40E_GL_MDET_RX);
  5384. if (reg & I40E_GL_MDET_RX_VALID_MASK) {
  5385. u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
  5386. I40E_GL_MDET_RX_FUNCTION_SHIFT;
  5387. u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
  5388. I40E_GL_MDET_RX_EVENT_SHIFT;
  5389. u8 queue = (reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
  5390. I40E_GL_MDET_RX_QUEUE_SHIFT;
  5391. if (netif_msg_rx_err(pf))
  5392. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
  5393. event, queue, func);
  5394. wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
  5395. mdd_detected = true;
  5396. }
  5397. if (mdd_detected) {
  5398. reg = rd32(hw, I40E_PF_MDET_TX);
  5399. if (reg & I40E_PF_MDET_TX_VALID_MASK) {
  5400. wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
  5401. dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
  5402. pf_mdd_detected = true;
  5403. }
  5404. reg = rd32(hw, I40E_PF_MDET_RX);
  5405. if (reg & I40E_PF_MDET_RX_VALID_MASK) {
  5406. wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
  5407. dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
  5408. pf_mdd_detected = true;
  5409. }
  5410. /* Queue belongs to the PF, initiate a reset */
  5411. if (pf_mdd_detected) {
  5412. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  5413. i40e_service_event_schedule(pf);
  5414. }
  5415. }
  5416. /* see if one of the VFs needs its hand slapped */
  5417. for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
  5418. vf = &(pf->vf[i]);
  5419. reg = rd32(hw, I40E_VP_MDET_TX(i));
  5420. if (reg & I40E_VP_MDET_TX_VALID_MASK) {
  5421. wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
  5422. vf->num_mdd_events++;
  5423. dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
  5424. i);
  5425. }
  5426. reg = rd32(hw, I40E_VP_MDET_RX(i));
  5427. if (reg & I40E_VP_MDET_RX_VALID_MASK) {
  5428. wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
  5429. vf->num_mdd_events++;
  5430. dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
  5431. i);
  5432. }
  5433. if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
  5434. dev_info(&pf->pdev->dev,
  5435. "Too many MDD events on VF %d, disabled\n", i);
  5436. dev_info(&pf->pdev->dev,
  5437. "Use PF Control I/F to re-enable the VF\n");
  5438. set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
  5439. }
  5440. }
  5441. /* re-enable mdd interrupt cause */
  5442. clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  5443. reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  5444. reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  5445. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  5446. i40e_flush(hw);
  5447. }
  5448. #ifdef CONFIG_I40E_VXLAN
  5449. /**
  5450. * i40e_sync_vxlan_filters_subtask - Sync the VSI filter list with HW
  5451. * @pf: board private structure
  5452. **/
  5453. static void i40e_sync_vxlan_filters_subtask(struct i40e_pf *pf)
  5454. {
  5455. struct i40e_hw *hw = &pf->hw;
  5456. i40e_status ret;
  5457. u8 filter_index;
  5458. __be16 port;
  5459. int i;
  5460. if (!(pf->flags & I40E_FLAG_VXLAN_FILTER_SYNC))
  5461. return;
  5462. pf->flags &= ~I40E_FLAG_VXLAN_FILTER_SYNC;
  5463. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  5464. if (pf->pending_vxlan_bitmap & (1 << i)) {
  5465. pf->pending_vxlan_bitmap &= ~(1 << i);
  5466. port = pf->vxlan_ports[i];
  5467. ret = port ?
  5468. i40e_aq_add_udp_tunnel(hw, ntohs(port),
  5469. I40E_AQC_TUNNEL_TYPE_VXLAN,
  5470. &filter_index, NULL)
  5471. : i40e_aq_del_udp_tunnel(hw, i, NULL);
  5472. if (ret) {
  5473. dev_info(&pf->pdev->dev, "Failed to execute AQ command for %s port %d with index %d\n",
  5474. port ? "adding" : "deleting",
  5475. ntohs(port), port ? i : i);
  5476. pf->vxlan_ports[i] = 0;
  5477. } else {
  5478. dev_info(&pf->pdev->dev, "%s port %d with AQ command with index %d\n",
  5479. port ? "Added" : "Deleted",
  5480. ntohs(port), port ? i : filter_index);
  5481. }
  5482. }
  5483. }
  5484. }
  5485. #endif
  5486. /**
  5487. * i40e_service_task - Run the driver's async subtasks
  5488. * @work: pointer to work_struct containing our data
  5489. **/
  5490. static void i40e_service_task(struct work_struct *work)
  5491. {
  5492. struct i40e_pf *pf = container_of(work,
  5493. struct i40e_pf,
  5494. service_task);
  5495. unsigned long start_time = jiffies;
  5496. /* don't bother with service tasks if a reset is in progress */
  5497. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
  5498. i40e_service_event_complete(pf);
  5499. return;
  5500. }
  5501. i40e_reset_subtask(pf);
  5502. i40e_handle_mdd_event(pf);
  5503. i40e_vc_process_vflr_event(pf);
  5504. i40e_watchdog_subtask(pf);
  5505. i40e_fdir_reinit_subtask(pf);
  5506. i40e_check_hang_subtask(pf);
  5507. i40e_sync_filters_subtask(pf);
  5508. #ifdef CONFIG_I40E_VXLAN
  5509. i40e_sync_vxlan_filters_subtask(pf);
  5510. #endif
  5511. i40e_clean_adminq_subtask(pf);
  5512. i40e_service_event_complete(pf);
  5513. /* If the tasks have taken longer than one timer cycle or there
  5514. * is more work to be done, reschedule the service task now
  5515. * rather than wait for the timer to tick again.
  5516. */
  5517. if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
  5518. test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
  5519. test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
  5520. test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
  5521. i40e_service_event_schedule(pf);
  5522. }
  5523. /**
  5524. * i40e_service_timer - timer callback
  5525. * @data: pointer to PF struct
  5526. **/
  5527. static void i40e_service_timer(unsigned long data)
  5528. {
  5529. struct i40e_pf *pf = (struct i40e_pf *)data;
  5530. mod_timer(&pf->service_timer,
  5531. round_jiffies(jiffies + pf->service_timer_period));
  5532. i40e_service_event_schedule(pf);
  5533. }
  5534. /**
  5535. * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
  5536. * @vsi: the VSI being configured
  5537. **/
  5538. static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
  5539. {
  5540. struct i40e_pf *pf = vsi->back;
  5541. switch (vsi->type) {
  5542. case I40E_VSI_MAIN:
  5543. vsi->alloc_queue_pairs = pf->num_lan_qps;
  5544. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  5545. I40E_REQ_DESCRIPTOR_MULTIPLE);
  5546. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  5547. vsi->num_q_vectors = pf->num_lan_msix;
  5548. else
  5549. vsi->num_q_vectors = 1;
  5550. break;
  5551. case I40E_VSI_FDIR:
  5552. vsi->alloc_queue_pairs = 1;
  5553. vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
  5554. I40E_REQ_DESCRIPTOR_MULTIPLE);
  5555. vsi->num_q_vectors = 1;
  5556. break;
  5557. case I40E_VSI_VMDQ2:
  5558. vsi->alloc_queue_pairs = pf->num_vmdq_qps;
  5559. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  5560. I40E_REQ_DESCRIPTOR_MULTIPLE);
  5561. vsi->num_q_vectors = pf->num_vmdq_msix;
  5562. break;
  5563. case I40E_VSI_SRIOV:
  5564. vsi->alloc_queue_pairs = pf->num_vf_qps;
  5565. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  5566. I40E_REQ_DESCRIPTOR_MULTIPLE);
  5567. break;
  5568. #ifdef I40E_FCOE
  5569. case I40E_VSI_FCOE:
  5570. vsi->alloc_queue_pairs = pf->num_fcoe_qps;
  5571. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  5572. I40E_REQ_DESCRIPTOR_MULTIPLE);
  5573. vsi->num_q_vectors = pf->num_fcoe_msix;
  5574. break;
  5575. #endif /* I40E_FCOE */
  5576. default:
  5577. WARN_ON(1);
  5578. return -ENODATA;
  5579. }
  5580. return 0;
  5581. }
  5582. /**
  5583. * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
  5584. * @type: VSI pointer
  5585. * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
  5586. *
  5587. * On error: returns error code (negative)
  5588. * On success: returns 0
  5589. **/
  5590. static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
  5591. {
  5592. int size;
  5593. int ret = 0;
  5594. /* allocate memory for both Tx and Rx ring pointers */
  5595. size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
  5596. vsi->tx_rings = kzalloc(size, GFP_KERNEL);
  5597. if (!vsi->tx_rings)
  5598. return -ENOMEM;
  5599. vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
  5600. if (alloc_qvectors) {
  5601. /* allocate memory for q_vector pointers */
  5602. size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
  5603. vsi->q_vectors = kzalloc(size, GFP_KERNEL);
  5604. if (!vsi->q_vectors) {
  5605. ret = -ENOMEM;
  5606. goto err_vectors;
  5607. }
  5608. }
  5609. return ret;
  5610. err_vectors:
  5611. kfree(vsi->tx_rings);
  5612. return ret;
  5613. }
  5614. /**
  5615. * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
  5616. * @pf: board private structure
  5617. * @type: type of VSI
  5618. *
  5619. * On error: returns error code (negative)
  5620. * On success: returns vsi index in PF (positive)
  5621. **/
  5622. static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
  5623. {
  5624. int ret = -ENODEV;
  5625. struct i40e_vsi *vsi;
  5626. int vsi_idx;
  5627. int i;
  5628. /* Need to protect the allocation of the VSIs at the PF level */
  5629. mutex_lock(&pf->switch_mutex);
  5630. /* VSI list may be fragmented if VSI creation/destruction has
  5631. * been happening. We can afford to do a quick scan to look
  5632. * for any free VSIs in the list.
  5633. *
  5634. * find next empty vsi slot, looping back around if necessary
  5635. */
  5636. i = pf->next_vsi;
  5637. while (i < pf->num_alloc_vsi && pf->vsi[i])
  5638. i++;
  5639. if (i >= pf->num_alloc_vsi) {
  5640. i = 0;
  5641. while (i < pf->next_vsi && pf->vsi[i])
  5642. i++;
  5643. }
  5644. if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
  5645. vsi_idx = i; /* Found one! */
  5646. } else {
  5647. ret = -ENODEV;
  5648. goto unlock_pf; /* out of VSI slots! */
  5649. }
  5650. pf->next_vsi = ++i;
  5651. vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
  5652. if (!vsi) {
  5653. ret = -ENOMEM;
  5654. goto unlock_pf;
  5655. }
  5656. vsi->type = type;
  5657. vsi->back = pf;
  5658. set_bit(__I40E_DOWN, &vsi->state);
  5659. vsi->flags = 0;
  5660. vsi->idx = vsi_idx;
  5661. vsi->rx_itr_setting = pf->rx_itr_default;
  5662. vsi->tx_itr_setting = pf->tx_itr_default;
  5663. vsi->netdev_registered = false;
  5664. vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
  5665. INIT_LIST_HEAD(&vsi->mac_filter_list);
  5666. vsi->irqs_ready = false;
  5667. ret = i40e_set_num_rings_in_vsi(vsi);
  5668. if (ret)
  5669. goto err_rings;
  5670. ret = i40e_vsi_alloc_arrays(vsi, true);
  5671. if (ret)
  5672. goto err_rings;
  5673. /* Setup default MSIX irq handler for VSI */
  5674. i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
  5675. pf->vsi[vsi_idx] = vsi;
  5676. ret = vsi_idx;
  5677. goto unlock_pf;
  5678. err_rings:
  5679. pf->next_vsi = i - 1;
  5680. kfree(vsi);
  5681. unlock_pf:
  5682. mutex_unlock(&pf->switch_mutex);
  5683. return ret;
  5684. }
  5685. /**
  5686. * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
  5687. * @type: VSI pointer
  5688. * @free_qvectors: a bool to specify if q_vectors need to be freed.
  5689. *
  5690. * On error: returns error code (negative)
  5691. * On success: returns 0
  5692. **/
  5693. static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
  5694. {
  5695. /* free the ring and vector containers */
  5696. if (free_qvectors) {
  5697. kfree(vsi->q_vectors);
  5698. vsi->q_vectors = NULL;
  5699. }
  5700. kfree(vsi->tx_rings);
  5701. vsi->tx_rings = NULL;
  5702. vsi->rx_rings = NULL;
  5703. }
  5704. /**
  5705. * i40e_vsi_clear - Deallocate the VSI provided
  5706. * @vsi: the VSI being un-configured
  5707. **/
  5708. static int i40e_vsi_clear(struct i40e_vsi *vsi)
  5709. {
  5710. struct i40e_pf *pf;
  5711. if (!vsi)
  5712. return 0;
  5713. if (!vsi->back)
  5714. goto free_vsi;
  5715. pf = vsi->back;
  5716. mutex_lock(&pf->switch_mutex);
  5717. if (!pf->vsi[vsi->idx]) {
  5718. dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
  5719. vsi->idx, vsi->idx, vsi, vsi->type);
  5720. goto unlock_vsi;
  5721. }
  5722. if (pf->vsi[vsi->idx] != vsi) {
  5723. dev_err(&pf->pdev->dev,
  5724. "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
  5725. pf->vsi[vsi->idx]->idx,
  5726. pf->vsi[vsi->idx],
  5727. pf->vsi[vsi->idx]->type,
  5728. vsi->idx, vsi, vsi->type);
  5729. goto unlock_vsi;
  5730. }
  5731. /* updates the pf for this cleared vsi */
  5732. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  5733. i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
  5734. i40e_vsi_free_arrays(vsi, true);
  5735. pf->vsi[vsi->idx] = NULL;
  5736. if (vsi->idx < pf->next_vsi)
  5737. pf->next_vsi = vsi->idx;
  5738. unlock_vsi:
  5739. mutex_unlock(&pf->switch_mutex);
  5740. free_vsi:
  5741. kfree(vsi);
  5742. return 0;
  5743. }
  5744. /**
  5745. * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
  5746. * @vsi: the VSI being cleaned
  5747. **/
  5748. static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
  5749. {
  5750. int i;
  5751. if (vsi->tx_rings && vsi->tx_rings[0]) {
  5752. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  5753. kfree_rcu(vsi->tx_rings[i], rcu);
  5754. vsi->tx_rings[i] = NULL;
  5755. vsi->rx_rings[i] = NULL;
  5756. }
  5757. }
  5758. }
  5759. /**
  5760. * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
  5761. * @vsi: the VSI being configured
  5762. **/
  5763. static int i40e_alloc_rings(struct i40e_vsi *vsi)
  5764. {
  5765. struct i40e_ring *tx_ring, *rx_ring;
  5766. struct i40e_pf *pf = vsi->back;
  5767. int i;
  5768. /* Set basic values in the rings to be used later during open() */
  5769. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  5770. /* allocate space for both Tx and Rx in one shot */
  5771. tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
  5772. if (!tx_ring)
  5773. goto err_out;
  5774. tx_ring->queue_index = i;
  5775. tx_ring->reg_idx = vsi->base_queue + i;
  5776. tx_ring->ring_active = false;
  5777. tx_ring->vsi = vsi;
  5778. tx_ring->netdev = vsi->netdev;
  5779. tx_ring->dev = &pf->pdev->dev;
  5780. tx_ring->count = vsi->num_desc;
  5781. tx_ring->size = 0;
  5782. tx_ring->dcb_tc = 0;
  5783. vsi->tx_rings[i] = tx_ring;
  5784. rx_ring = &tx_ring[1];
  5785. rx_ring->queue_index = i;
  5786. rx_ring->reg_idx = vsi->base_queue + i;
  5787. rx_ring->ring_active = false;
  5788. rx_ring->vsi = vsi;
  5789. rx_ring->netdev = vsi->netdev;
  5790. rx_ring->dev = &pf->pdev->dev;
  5791. rx_ring->count = vsi->num_desc;
  5792. rx_ring->size = 0;
  5793. rx_ring->dcb_tc = 0;
  5794. if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED)
  5795. set_ring_16byte_desc_enabled(rx_ring);
  5796. else
  5797. clear_ring_16byte_desc_enabled(rx_ring);
  5798. vsi->rx_rings[i] = rx_ring;
  5799. }
  5800. return 0;
  5801. err_out:
  5802. i40e_vsi_clear_rings(vsi);
  5803. return -ENOMEM;
  5804. }
  5805. /**
  5806. * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
  5807. * @pf: board private structure
  5808. * @vectors: the number of MSI-X vectors to request
  5809. *
  5810. * Returns the number of vectors reserved, or error
  5811. **/
  5812. static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
  5813. {
  5814. vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
  5815. I40E_MIN_MSIX, vectors);
  5816. if (vectors < 0) {
  5817. dev_info(&pf->pdev->dev,
  5818. "MSI-X vector reservation failed: %d\n", vectors);
  5819. vectors = 0;
  5820. }
  5821. return vectors;
  5822. }
  5823. /**
  5824. * i40e_init_msix - Setup the MSIX capability
  5825. * @pf: board private structure
  5826. *
  5827. * Work with the OS to set up the MSIX vectors needed.
  5828. *
  5829. * Returns 0 on success, negative on failure
  5830. **/
  5831. static int i40e_init_msix(struct i40e_pf *pf)
  5832. {
  5833. i40e_status err = 0;
  5834. struct i40e_hw *hw = &pf->hw;
  5835. int v_budget, i;
  5836. int vec;
  5837. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  5838. return -ENODEV;
  5839. /* The number of vectors we'll request will be comprised of:
  5840. * - Add 1 for "other" cause for Admin Queue events, etc.
  5841. * - The number of LAN queue pairs
  5842. * - Queues being used for RSS.
  5843. * We don't need as many as max_rss_size vectors.
  5844. * use rss_size instead in the calculation since that
  5845. * is governed by number of cpus in the system.
  5846. * - assumes symmetric Tx/Rx pairing
  5847. * - The number of VMDq pairs
  5848. #ifdef I40E_FCOE
  5849. * - The number of FCOE qps.
  5850. #endif
  5851. * Once we count this up, try the request.
  5852. *
  5853. * If we can't get what we want, we'll simplify to nearly nothing
  5854. * and try again. If that still fails, we punt.
  5855. */
  5856. pf->num_lan_msix = pf->num_lan_qps - (pf->rss_size_max - pf->rss_size);
  5857. pf->num_vmdq_msix = pf->num_vmdq_qps;
  5858. v_budget = 1 + pf->num_lan_msix;
  5859. v_budget += (pf->num_vmdq_vsis * pf->num_vmdq_msix);
  5860. if (pf->flags & I40E_FLAG_FD_SB_ENABLED)
  5861. v_budget++;
  5862. #ifdef I40E_FCOE
  5863. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  5864. pf->num_fcoe_msix = pf->num_fcoe_qps;
  5865. v_budget += pf->num_fcoe_msix;
  5866. }
  5867. #endif
  5868. /* Scale down if necessary, and the rings will share vectors */
  5869. v_budget = min_t(int, v_budget, hw->func_caps.num_msix_vectors);
  5870. pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
  5871. GFP_KERNEL);
  5872. if (!pf->msix_entries)
  5873. return -ENOMEM;
  5874. for (i = 0; i < v_budget; i++)
  5875. pf->msix_entries[i].entry = i;
  5876. vec = i40e_reserve_msix_vectors(pf, v_budget);
  5877. if (vec != v_budget) {
  5878. /* If we have limited resources, we will start with no vectors
  5879. * for the special features and then allocate vectors to some
  5880. * of these features based on the policy and at the end disable
  5881. * the features that did not get any vectors.
  5882. */
  5883. #ifdef I40E_FCOE
  5884. pf->num_fcoe_qps = 0;
  5885. pf->num_fcoe_msix = 0;
  5886. #endif
  5887. pf->num_vmdq_msix = 0;
  5888. }
  5889. if (vec < I40E_MIN_MSIX) {
  5890. pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
  5891. kfree(pf->msix_entries);
  5892. pf->msix_entries = NULL;
  5893. return -ENODEV;
  5894. } else if (vec == I40E_MIN_MSIX) {
  5895. /* Adjust for minimal MSIX use */
  5896. pf->num_vmdq_vsis = 0;
  5897. pf->num_vmdq_qps = 0;
  5898. pf->num_lan_qps = 1;
  5899. pf->num_lan_msix = 1;
  5900. } else if (vec != v_budget) {
  5901. /* reserve the misc vector */
  5902. vec--;
  5903. /* Scale vector usage down */
  5904. pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
  5905. pf->num_vmdq_vsis = 1;
  5906. /* partition out the remaining vectors */
  5907. switch (vec) {
  5908. case 2:
  5909. pf->num_lan_msix = 1;
  5910. break;
  5911. case 3:
  5912. #ifdef I40E_FCOE
  5913. /* give one vector to FCoE */
  5914. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  5915. pf->num_lan_msix = 1;
  5916. pf->num_fcoe_msix = 1;
  5917. }
  5918. #else
  5919. pf->num_lan_msix = 2;
  5920. #endif
  5921. break;
  5922. default:
  5923. #ifdef I40E_FCOE
  5924. /* give one vector to FCoE */
  5925. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  5926. pf->num_fcoe_msix = 1;
  5927. vec--;
  5928. }
  5929. #endif
  5930. pf->num_lan_msix = min_t(int, (vec / 2),
  5931. pf->num_lan_qps);
  5932. pf->num_vmdq_vsis = min_t(int, (vec - pf->num_lan_msix),
  5933. I40E_DEFAULT_NUM_VMDQ_VSI);
  5934. break;
  5935. }
  5936. }
  5937. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  5938. (pf->num_vmdq_msix == 0)) {
  5939. dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
  5940. pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
  5941. }
  5942. #ifdef I40E_FCOE
  5943. if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) {
  5944. dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n");
  5945. pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
  5946. }
  5947. #endif
  5948. return err;
  5949. }
  5950. /**
  5951. * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
  5952. * @vsi: the VSI being configured
  5953. * @v_idx: index of the vector in the vsi struct
  5954. *
  5955. * We allocate one q_vector. If allocation fails we return -ENOMEM.
  5956. **/
  5957. static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx)
  5958. {
  5959. struct i40e_q_vector *q_vector;
  5960. /* allocate q_vector */
  5961. q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
  5962. if (!q_vector)
  5963. return -ENOMEM;
  5964. q_vector->vsi = vsi;
  5965. q_vector->v_idx = v_idx;
  5966. cpumask_set_cpu(v_idx, &q_vector->affinity_mask);
  5967. if (vsi->netdev)
  5968. netif_napi_add(vsi->netdev, &q_vector->napi,
  5969. i40e_napi_poll, NAPI_POLL_WEIGHT);
  5970. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  5971. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  5972. /* tie q_vector and vsi together */
  5973. vsi->q_vectors[v_idx] = q_vector;
  5974. return 0;
  5975. }
  5976. /**
  5977. * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
  5978. * @vsi: the VSI being configured
  5979. *
  5980. * We allocate one q_vector per queue interrupt. If allocation fails we
  5981. * return -ENOMEM.
  5982. **/
  5983. static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
  5984. {
  5985. struct i40e_pf *pf = vsi->back;
  5986. int v_idx, num_q_vectors;
  5987. int err;
  5988. /* if not MSIX, give the one vector only to the LAN VSI */
  5989. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  5990. num_q_vectors = vsi->num_q_vectors;
  5991. else if (vsi == pf->vsi[pf->lan_vsi])
  5992. num_q_vectors = 1;
  5993. else
  5994. return -EINVAL;
  5995. for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
  5996. err = i40e_vsi_alloc_q_vector(vsi, v_idx);
  5997. if (err)
  5998. goto err_out;
  5999. }
  6000. return 0;
  6001. err_out:
  6002. while (v_idx--)
  6003. i40e_free_q_vector(vsi, v_idx);
  6004. return err;
  6005. }
  6006. /**
  6007. * i40e_init_interrupt_scheme - Determine proper interrupt scheme
  6008. * @pf: board private structure to initialize
  6009. **/
  6010. static void i40e_init_interrupt_scheme(struct i40e_pf *pf)
  6011. {
  6012. int err = 0;
  6013. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  6014. err = i40e_init_msix(pf);
  6015. if (err) {
  6016. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
  6017. #ifdef I40E_FCOE
  6018. I40E_FLAG_FCOE_ENABLED |
  6019. #endif
  6020. I40E_FLAG_RSS_ENABLED |
  6021. I40E_FLAG_DCB_CAPABLE |
  6022. I40E_FLAG_SRIOV_ENABLED |
  6023. I40E_FLAG_FD_SB_ENABLED |
  6024. I40E_FLAG_FD_ATR_ENABLED |
  6025. I40E_FLAG_VMDQ_ENABLED);
  6026. /* rework the queue expectations without MSIX */
  6027. i40e_determine_queue_usage(pf);
  6028. }
  6029. }
  6030. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  6031. (pf->flags & I40E_FLAG_MSI_ENABLED)) {
  6032. dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
  6033. err = pci_enable_msi(pf->pdev);
  6034. if (err) {
  6035. dev_info(&pf->pdev->dev, "MSI init failed - %d\n", err);
  6036. pf->flags &= ~I40E_FLAG_MSI_ENABLED;
  6037. }
  6038. }
  6039. if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
  6040. dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
  6041. /* track first vector for misc interrupts */
  6042. err = i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT-1);
  6043. }
  6044. /**
  6045. * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
  6046. * @pf: board private structure
  6047. *
  6048. * This sets up the handler for MSIX 0, which is used to manage the
  6049. * non-queue interrupts, e.g. AdminQ and errors. This is not used
  6050. * when in MSI or Legacy interrupt mode.
  6051. **/
  6052. static int i40e_setup_misc_vector(struct i40e_pf *pf)
  6053. {
  6054. struct i40e_hw *hw = &pf->hw;
  6055. int err = 0;
  6056. /* Only request the irq if this is the first time through, and
  6057. * not when we're rebuilding after a Reset
  6058. */
  6059. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
  6060. err = request_irq(pf->msix_entries[0].vector,
  6061. i40e_intr, 0, pf->misc_int_name, pf);
  6062. if (err) {
  6063. dev_info(&pf->pdev->dev,
  6064. "request_irq for %s failed: %d\n",
  6065. pf->misc_int_name, err);
  6066. return -EFAULT;
  6067. }
  6068. }
  6069. i40e_enable_misc_int_causes(hw);
  6070. /* associate no queues to the misc vector */
  6071. wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
  6072. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
  6073. i40e_flush(hw);
  6074. i40e_irq_dynamic_enable_icr0(pf);
  6075. return err;
  6076. }
  6077. /**
  6078. * i40e_config_rss - Prepare for RSS if used
  6079. * @pf: board private structure
  6080. **/
  6081. static int i40e_config_rss(struct i40e_pf *pf)
  6082. {
  6083. /* Set of random keys generated using kernel random number generator */
  6084. static const u32 seed[I40E_PFQF_HKEY_MAX_INDEX + 1] = {0x41b01687,
  6085. 0x183cfd8c, 0xce880440, 0x580cbc3c, 0x35897377,
  6086. 0x328b25e1, 0x4fa98922, 0xb7d90c14, 0xd5bad70d,
  6087. 0xcd15a2c1, 0xe8580225, 0x4a1e9d11, 0xfe5731be};
  6088. struct i40e_hw *hw = &pf->hw;
  6089. u32 lut = 0;
  6090. int i, j;
  6091. u64 hena;
  6092. u32 reg_val;
  6093. /* Fill out hash function seed */
  6094. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  6095. wr32(hw, I40E_PFQF_HKEY(i), seed[i]);
  6096. /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
  6097. hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
  6098. ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
  6099. hena |= I40E_DEFAULT_RSS_HENA;
  6100. wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
  6101. wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  6102. /* Check capability and Set table size and register per hw expectation*/
  6103. reg_val = rd32(hw, I40E_PFQF_CTL_0);
  6104. if (hw->func_caps.rss_table_size == 512) {
  6105. reg_val |= I40E_PFQF_CTL_0_HASHLUTSIZE_512;
  6106. pf->rss_table_size = 512;
  6107. } else {
  6108. pf->rss_table_size = 128;
  6109. reg_val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_512;
  6110. }
  6111. wr32(hw, I40E_PFQF_CTL_0, reg_val);
  6112. /* Populate the LUT with max no. of queues in round robin fashion */
  6113. for (i = 0, j = 0; i < pf->rss_table_size; i++, j++) {
  6114. /* The assumption is that lan qp count will be the highest
  6115. * qp count for any PF VSI that needs RSS.
  6116. * If multiple VSIs need RSS support, all the qp counts
  6117. * for those VSIs should be a power of 2 for RSS to work.
  6118. * If LAN VSI is the only consumer for RSS then this requirement
  6119. * is not necessary.
  6120. */
  6121. if (j == pf->rss_size)
  6122. j = 0;
  6123. /* lut = 4-byte sliding window of 4 lut entries */
  6124. lut = (lut << 8) | (j &
  6125. ((0x1 << pf->hw.func_caps.rss_table_entry_width) - 1));
  6126. /* On i = 3, we have 4 entries in lut; write to the register */
  6127. if ((i & 3) == 3)
  6128. wr32(hw, I40E_PFQF_HLUT(i >> 2), lut);
  6129. }
  6130. i40e_flush(hw);
  6131. return 0;
  6132. }
  6133. /**
  6134. * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
  6135. * @pf: board private structure
  6136. * @queue_count: the requested queue count for rss.
  6137. *
  6138. * returns 0 if rss is not enabled, if enabled returns the final rss queue
  6139. * count which may be different from the requested queue count.
  6140. **/
  6141. int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
  6142. {
  6143. if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
  6144. return 0;
  6145. queue_count = min_t(int, queue_count, pf->rss_size_max);
  6146. if (queue_count != pf->rss_size) {
  6147. i40e_prep_for_reset(pf);
  6148. pf->rss_size = queue_count;
  6149. i40e_reset_and_rebuild(pf, true);
  6150. i40e_config_rss(pf);
  6151. }
  6152. dev_info(&pf->pdev->dev, "RSS count: %d\n", pf->rss_size);
  6153. return pf->rss_size;
  6154. }
  6155. /**
  6156. * i40e_sw_init - Initialize general software structures (struct i40e_pf)
  6157. * @pf: board private structure to initialize
  6158. *
  6159. * i40e_sw_init initializes the Adapter private data structure.
  6160. * Fields are initialized based on PCI device information and
  6161. * OS network device settings (MTU size).
  6162. **/
  6163. static int i40e_sw_init(struct i40e_pf *pf)
  6164. {
  6165. int err = 0;
  6166. int size;
  6167. pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE,
  6168. (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK));
  6169. pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG;
  6170. if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) {
  6171. if (I40E_DEBUG_USER & debug)
  6172. pf->hw.debug_mask = debug;
  6173. pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER),
  6174. I40E_DEFAULT_MSG_ENABLE);
  6175. }
  6176. /* Set default capability flags */
  6177. pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
  6178. I40E_FLAG_MSI_ENABLED |
  6179. I40E_FLAG_MSIX_ENABLED |
  6180. I40E_FLAG_RX_1BUF_ENABLED;
  6181. /* Set default ITR */
  6182. pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
  6183. pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
  6184. /* Depending on PF configurations, it is possible that the RSS
  6185. * maximum might end up larger than the available queues
  6186. */
  6187. pf->rss_size_max = 0x1 << pf->hw.func_caps.rss_table_entry_width;
  6188. pf->rss_size = 1;
  6189. pf->rss_size_max = min_t(int, pf->rss_size_max,
  6190. pf->hw.func_caps.num_tx_qp);
  6191. if (pf->hw.func_caps.rss) {
  6192. pf->flags |= I40E_FLAG_RSS_ENABLED;
  6193. pf->rss_size = min_t(int, pf->rss_size_max, num_online_cpus());
  6194. }
  6195. /* MFP mode enabled */
  6196. if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.mfp_mode_1) {
  6197. pf->flags |= I40E_FLAG_MFP_ENABLED;
  6198. dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
  6199. }
  6200. /* FW/NVM is not yet fixed in this regard */
  6201. if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
  6202. (pf->hw.func_caps.fd_filters_best_effort > 0)) {
  6203. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  6204. pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
  6205. /* Setup a counter for fd_atr per pf */
  6206. pf->fd_atr_cnt_idx = I40E_FD_ATR_STAT_IDX(pf->hw.pf_id);
  6207. if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) {
  6208. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  6209. /* Setup a counter for fd_sb per pf */
  6210. pf->fd_sb_cnt_idx = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
  6211. } else {
  6212. dev_info(&pf->pdev->dev,
  6213. "Flow Director Sideband mode Disabled in MFP mode\n");
  6214. }
  6215. pf->fdir_pf_filter_count =
  6216. pf->hw.func_caps.fd_filters_guaranteed;
  6217. pf->hw.fdir_shared_filter_count =
  6218. pf->hw.func_caps.fd_filters_best_effort;
  6219. }
  6220. if (pf->hw.func_caps.vmdq) {
  6221. pf->flags |= I40E_FLAG_VMDQ_ENABLED;
  6222. pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
  6223. pf->num_vmdq_qps = I40E_DEFAULT_QUEUES_PER_VMDQ;
  6224. }
  6225. #ifdef I40E_FCOE
  6226. err = i40e_init_pf_fcoe(pf);
  6227. if (err)
  6228. dev_info(&pf->pdev->dev, "init_pf_fcoe failed: %d\n", err);
  6229. #endif /* I40E_FCOE */
  6230. #ifdef CONFIG_PCI_IOV
  6231. if (pf->hw.func_caps.num_vfs) {
  6232. pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
  6233. pf->flags |= I40E_FLAG_SRIOV_ENABLED;
  6234. pf->num_req_vfs = min_t(int,
  6235. pf->hw.func_caps.num_vfs,
  6236. I40E_MAX_VF_COUNT);
  6237. }
  6238. #endif /* CONFIG_PCI_IOV */
  6239. pf->eeprom_version = 0xDEAD;
  6240. pf->lan_veb = I40E_NO_VEB;
  6241. pf->lan_vsi = I40E_NO_VSI;
  6242. /* set up queue assignment tracking */
  6243. size = sizeof(struct i40e_lump_tracking)
  6244. + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
  6245. pf->qp_pile = kzalloc(size, GFP_KERNEL);
  6246. if (!pf->qp_pile) {
  6247. err = -ENOMEM;
  6248. goto sw_init_done;
  6249. }
  6250. pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
  6251. pf->qp_pile->search_hint = 0;
  6252. /* set up vector assignment tracking */
  6253. size = sizeof(struct i40e_lump_tracking)
  6254. + (sizeof(u16) * pf->hw.func_caps.num_msix_vectors);
  6255. pf->irq_pile = kzalloc(size, GFP_KERNEL);
  6256. if (!pf->irq_pile) {
  6257. kfree(pf->qp_pile);
  6258. err = -ENOMEM;
  6259. goto sw_init_done;
  6260. }
  6261. pf->irq_pile->num_entries = pf->hw.func_caps.num_msix_vectors;
  6262. pf->irq_pile->search_hint = 0;
  6263. pf->tx_timeout_recovery_level = 1;
  6264. mutex_init(&pf->switch_mutex);
  6265. sw_init_done:
  6266. return err;
  6267. }
  6268. /**
  6269. * i40e_set_ntuple - set the ntuple feature flag and take action
  6270. * @pf: board private structure to initialize
  6271. * @features: the feature set that the stack is suggesting
  6272. *
  6273. * returns a bool to indicate if reset needs to happen
  6274. **/
  6275. bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
  6276. {
  6277. bool need_reset = false;
  6278. /* Check if Flow Director n-tuple support was enabled or disabled. If
  6279. * the state changed, we need to reset.
  6280. */
  6281. if (features & NETIF_F_NTUPLE) {
  6282. /* Enable filters and mark for reset */
  6283. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  6284. need_reset = true;
  6285. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  6286. } else {
  6287. /* turn off filters, mark for reset and clear SW filter list */
  6288. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  6289. need_reset = true;
  6290. i40e_fdir_filter_exit(pf);
  6291. }
  6292. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  6293. pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
  6294. /* reset fd counters */
  6295. pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0;
  6296. pf->fdir_pf_active_filters = 0;
  6297. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  6298. dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
  6299. /* if ATR was auto disabled it can be re-enabled. */
  6300. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  6301. (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED))
  6302. pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  6303. }
  6304. return need_reset;
  6305. }
  6306. /**
  6307. * i40e_set_features - set the netdev feature flags
  6308. * @netdev: ptr to the netdev being adjusted
  6309. * @features: the feature set that the stack is suggesting
  6310. **/
  6311. static int i40e_set_features(struct net_device *netdev,
  6312. netdev_features_t features)
  6313. {
  6314. struct i40e_netdev_priv *np = netdev_priv(netdev);
  6315. struct i40e_vsi *vsi = np->vsi;
  6316. struct i40e_pf *pf = vsi->back;
  6317. bool need_reset;
  6318. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  6319. i40e_vlan_stripping_enable(vsi);
  6320. else
  6321. i40e_vlan_stripping_disable(vsi);
  6322. need_reset = i40e_set_ntuple(pf, features);
  6323. if (need_reset)
  6324. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  6325. return 0;
  6326. }
  6327. #ifdef CONFIG_I40E_VXLAN
  6328. /**
  6329. * i40e_get_vxlan_port_idx - Lookup a possibly offloaded for Rx UDP port
  6330. * @pf: board private structure
  6331. * @port: The UDP port to look up
  6332. *
  6333. * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
  6334. **/
  6335. static u8 i40e_get_vxlan_port_idx(struct i40e_pf *pf, __be16 port)
  6336. {
  6337. u8 i;
  6338. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  6339. if (pf->vxlan_ports[i] == port)
  6340. return i;
  6341. }
  6342. return i;
  6343. }
  6344. /**
  6345. * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
  6346. * @netdev: This physical port's netdev
  6347. * @sa_family: Socket Family that VXLAN is notifying us about
  6348. * @port: New UDP port number that VXLAN started listening to
  6349. **/
  6350. static void i40e_add_vxlan_port(struct net_device *netdev,
  6351. sa_family_t sa_family, __be16 port)
  6352. {
  6353. struct i40e_netdev_priv *np = netdev_priv(netdev);
  6354. struct i40e_vsi *vsi = np->vsi;
  6355. struct i40e_pf *pf = vsi->back;
  6356. u8 next_idx;
  6357. u8 idx;
  6358. if (sa_family == AF_INET6)
  6359. return;
  6360. idx = i40e_get_vxlan_port_idx(pf, port);
  6361. /* Check if port already exists */
  6362. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  6363. netdev_info(netdev, "Port %d already offloaded\n", ntohs(port));
  6364. return;
  6365. }
  6366. /* Now check if there is space to add the new port */
  6367. next_idx = i40e_get_vxlan_port_idx(pf, 0);
  6368. if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  6369. netdev_info(netdev, "Maximum number of UDP ports reached, not adding port %d\n",
  6370. ntohs(port));
  6371. return;
  6372. }
  6373. /* New port: add it and mark its index in the bitmap */
  6374. pf->vxlan_ports[next_idx] = port;
  6375. pf->pending_vxlan_bitmap |= (1 << next_idx);
  6376. pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC;
  6377. }
  6378. /**
  6379. * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
  6380. * @netdev: This physical port's netdev
  6381. * @sa_family: Socket Family that VXLAN is notifying us about
  6382. * @port: UDP port number that VXLAN stopped listening to
  6383. **/
  6384. static void i40e_del_vxlan_port(struct net_device *netdev,
  6385. sa_family_t sa_family, __be16 port)
  6386. {
  6387. struct i40e_netdev_priv *np = netdev_priv(netdev);
  6388. struct i40e_vsi *vsi = np->vsi;
  6389. struct i40e_pf *pf = vsi->back;
  6390. u8 idx;
  6391. if (sa_family == AF_INET6)
  6392. return;
  6393. idx = i40e_get_vxlan_port_idx(pf, port);
  6394. /* Check if port already exists */
  6395. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  6396. /* if port exists, set it to 0 (mark for deletion)
  6397. * and make it pending
  6398. */
  6399. pf->vxlan_ports[idx] = 0;
  6400. pf->pending_vxlan_bitmap |= (1 << idx);
  6401. pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC;
  6402. } else {
  6403. netdev_warn(netdev, "Port %d was not found, not deleting\n",
  6404. ntohs(port));
  6405. }
  6406. }
  6407. #endif
  6408. static int i40e_get_phys_port_id(struct net_device *netdev,
  6409. struct netdev_phys_port_id *ppid)
  6410. {
  6411. struct i40e_netdev_priv *np = netdev_priv(netdev);
  6412. struct i40e_pf *pf = np->vsi->back;
  6413. struct i40e_hw *hw = &pf->hw;
  6414. if (!(pf->flags & I40E_FLAG_PORT_ID_VALID))
  6415. return -EOPNOTSUPP;
  6416. ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
  6417. memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
  6418. return 0;
  6419. }
  6420. #ifdef HAVE_FDB_OPS
  6421. #ifdef USE_CONST_DEV_UC_CHAR
  6422. static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  6423. struct net_device *dev,
  6424. const unsigned char *addr,
  6425. u16 flags)
  6426. #else
  6427. static int i40e_ndo_fdb_add(struct ndmsg *ndm,
  6428. struct net_device *dev,
  6429. unsigned char *addr,
  6430. u16 flags)
  6431. #endif
  6432. {
  6433. struct i40e_netdev_priv *np = netdev_priv(dev);
  6434. struct i40e_pf *pf = np->vsi->back;
  6435. int err = 0;
  6436. if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
  6437. return -EOPNOTSUPP;
  6438. /* Hardware does not support aging addresses so if a
  6439. * ndm_state is given only allow permanent addresses
  6440. */
  6441. if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
  6442. netdev_info(dev, "FDB only supports static addresses\n");
  6443. return -EINVAL;
  6444. }
  6445. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
  6446. err = dev_uc_add_excl(dev, addr);
  6447. else if (is_multicast_ether_addr(addr))
  6448. err = dev_mc_add_excl(dev, addr);
  6449. else
  6450. err = -EINVAL;
  6451. /* Only return duplicate errors if NLM_F_EXCL is set */
  6452. if (err == -EEXIST && !(flags & NLM_F_EXCL))
  6453. err = 0;
  6454. return err;
  6455. }
  6456. #ifndef USE_DEFAULT_FDB_DEL_DUMP
  6457. #ifdef USE_CONST_DEV_UC_CHAR
  6458. static int i40e_ndo_fdb_del(struct ndmsg *ndm,
  6459. struct net_device *dev,
  6460. const unsigned char *addr)
  6461. #else
  6462. static int i40e_ndo_fdb_del(struct ndmsg *ndm,
  6463. struct net_device *dev,
  6464. unsigned char *addr)
  6465. #endif
  6466. {
  6467. struct i40e_netdev_priv *np = netdev_priv(dev);
  6468. struct i40e_pf *pf = np->vsi->back;
  6469. int err = -EOPNOTSUPP;
  6470. if (ndm->ndm_state & NUD_PERMANENT) {
  6471. netdev_info(dev, "FDB only supports static addresses\n");
  6472. return -EINVAL;
  6473. }
  6474. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  6475. if (is_unicast_ether_addr(addr))
  6476. err = dev_uc_del(dev, addr);
  6477. else if (is_multicast_ether_addr(addr))
  6478. err = dev_mc_del(dev, addr);
  6479. else
  6480. err = -EINVAL;
  6481. }
  6482. return err;
  6483. }
  6484. static int i40e_ndo_fdb_dump(struct sk_buff *skb,
  6485. struct netlink_callback *cb,
  6486. struct net_device *dev,
  6487. struct net_device *filter_dev,
  6488. int idx)
  6489. {
  6490. struct i40e_netdev_priv *np = netdev_priv(dev);
  6491. struct i40e_pf *pf = np->vsi->back;
  6492. if (pf->flags & I40E_FLAG_SRIOV_ENABLED)
  6493. idx = ndo_dflt_fdb_dump(skb, cb, dev, filter_dev, idx);
  6494. return idx;
  6495. }
  6496. #endif /* USE_DEFAULT_FDB_DEL_DUMP */
  6497. #endif /* HAVE_FDB_OPS */
  6498. static const struct net_device_ops i40e_netdev_ops = {
  6499. .ndo_open = i40e_open,
  6500. .ndo_stop = i40e_close,
  6501. .ndo_start_xmit = i40e_lan_xmit_frame,
  6502. .ndo_get_stats64 = i40e_get_netdev_stats_struct,
  6503. .ndo_set_rx_mode = i40e_set_rx_mode,
  6504. .ndo_validate_addr = eth_validate_addr,
  6505. .ndo_set_mac_address = i40e_set_mac,
  6506. .ndo_change_mtu = i40e_change_mtu,
  6507. .ndo_do_ioctl = i40e_ioctl,
  6508. .ndo_tx_timeout = i40e_tx_timeout,
  6509. .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
  6510. .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
  6511. #ifdef CONFIG_NET_POLL_CONTROLLER
  6512. .ndo_poll_controller = i40e_netpoll,
  6513. #endif
  6514. .ndo_setup_tc = i40e_setup_tc,
  6515. #ifdef I40E_FCOE
  6516. .ndo_fcoe_enable = i40e_fcoe_enable,
  6517. .ndo_fcoe_disable = i40e_fcoe_disable,
  6518. #endif
  6519. .ndo_set_features = i40e_set_features,
  6520. .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
  6521. .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
  6522. .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
  6523. .ndo_get_vf_config = i40e_ndo_get_vf_config,
  6524. .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
  6525. .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
  6526. #ifdef CONFIG_I40E_VXLAN
  6527. .ndo_add_vxlan_port = i40e_add_vxlan_port,
  6528. .ndo_del_vxlan_port = i40e_del_vxlan_port,
  6529. #endif
  6530. .ndo_get_phys_port_id = i40e_get_phys_port_id,
  6531. #ifdef HAVE_FDB_OPS
  6532. .ndo_fdb_add = i40e_ndo_fdb_add,
  6533. #ifndef USE_DEFAULT_FDB_DEL_DUMP
  6534. .ndo_fdb_del = i40e_ndo_fdb_del,
  6535. .ndo_fdb_dump = i40e_ndo_fdb_dump,
  6536. #endif
  6537. #endif
  6538. };
  6539. /**
  6540. * i40e_config_netdev - Setup the netdev flags
  6541. * @vsi: the VSI being configured
  6542. *
  6543. * Returns 0 on success, negative value on failure
  6544. **/
  6545. static int i40e_config_netdev(struct i40e_vsi *vsi)
  6546. {
  6547. u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  6548. struct i40e_pf *pf = vsi->back;
  6549. struct i40e_hw *hw = &pf->hw;
  6550. struct i40e_netdev_priv *np;
  6551. struct net_device *netdev;
  6552. u8 mac_addr[ETH_ALEN];
  6553. int etherdev_size;
  6554. etherdev_size = sizeof(struct i40e_netdev_priv);
  6555. netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
  6556. if (!netdev)
  6557. return -ENOMEM;
  6558. vsi->netdev = netdev;
  6559. np = netdev_priv(netdev);
  6560. np->vsi = vsi;
  6561. netdev->hw_enc_features |= NETIF_F_IP_CSUM |
  6562. NETIF_F_GSO_UDP_TUNNEL |
  6563. NETIF_F_TSO;
  6564. netdev->features = NETIF_F_SG |
  6565. NETIF_F_IP_CSUM |
  6566. NETIF_F_SCTP_CSUM |
  6567. NETIF_F_HIGHDMA |
  6568. NETIF_F_GSO_UDP_TUNNEL |
  6569. NETIF_F_HW_VLAN_CTAG_TX |
  6570. NETIF_F_HW_VLAN_CTAG_RX |
  6571. NETIF_F_HW_VLAN_CTAG_FILTER |
  6572. NETIF_F_IPV6_CSUM |
  6573. NETIF_F_TSO |
  6574. NETIF_F_TSO_ECN |
  6575. NETIF_F_TSO6 |
  6576. NETIF_F_RXCSUM |
  6577. NETIF_F_RXHASH |
  6578. 0;
  6579. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  6580. netdev->features |= NETIF_F_NTUPLE;
  6581. /* copy netdev features into list of user selectable features */
  6582. netdev->hw_features |= netdev->features;
  6583. if (vsi->type == I40E_VSI_MAIN) {
  6584. SET_NETDEV_DEV(netdev, &pf->pdev->dev);
  6585. ether_addr_copy(mac_addr, hw->mac.perm_addr);
  6586. /* The following steps are necessary to prevent reception
  6587. * of tagged packets - some older NVM configurations load a
  6588. * default a MAC-VLAN filter that accepts any tagged packet
  6589. * which must be replaced by a normal filter.
  6590. */
  6591. if (!i40e_rm_default_mac_filter(vsi, mac_addr))
  6592. i40e_add_filter(vsi, mac_addr,
  6593. I40E_VLAN_ANY, false, true);
  6594. } else {
  6595. /* relate the VSI_VMDQ name to the VSI_MAIN name */
  6596. snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
  6597. pf->vsi[pf->lan_vsi]->netdev->name);
  6598. random_ether_addr(mac_addr);
  6599. i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false);
  6600. }
  6601. i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false);
  6602. ether_addr_copy(netdev->dev_addr, mac_addr);
  6603. ether_addr_copy(netdev->perm_addr, mac_addr);
  6604. /* vlan gets same features (except vlan offload)
  6605. * after any tweaks for specific VSI types
  6606. */
  6607. netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX |
  6608. NETIF_F_HW_VLAN_CTAG_RX |
  6609. NETIF_F_HW_VLAN_CTAG_FILTER);
  6610. netdev->priv_flags |= IFF_UNICAST_FLT;
  6611. netdev->priv_flags |= IFF_SUPP_NOFCS;
  6612. /* Setup netdev TC information */
  6613. i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
  6614. netdev->netdev_ops = &i40e_netdev_ops;
  6615. netdev->watchdog_timeo = 5 * HZ;
  6616. i40e_set_ethtool_ops(netdev);
  6617. #ifdef I40E_FCOE
  6618. i40e_fcoe_config_netdev(netdev, vsi);
  6619. #endif
  6620. return 0;
  6621. }
  6622. /**
  6623. * i40e_vsi_delete - Delete a VSI from the switch
  6624. * @vsi: the VSI being removed
  6625. *
  6626. * Returns 0 on success, negative value on failure
  6627. **/
  6628. static void i40e_vsi_delete(struct i40e_vsi *vsi)
  6629. {
  6630. /* remove default VSI is not allowed */
  6631. if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
  6632. return;
  6633. i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
  6634. }
  6635. /**
  6636. * i40e_add_vsi - Add a VSI to the switch
  6637. * @vsi: the VSI being configured
  6638. *
  6639. * This initializes a VSI context depending on the VSI type to be added and
  6640. * passes it down to the add_vsi aq command.
  6641. **/
  6642. static int i40e_add_vsi(struct i40e_vsi *vsi)
  6643. {
  6644. int ret = -ENODEV;
  6645. struct i40e_mac_filter *f, *ftmp;
  6646. struct i40e_pf *pf = vsi->back;
  6647. struct i40e_hw *hw = &pf->hw;
  6648. struct i40e_vsi_context ctxt;
  6649. u8 enabled_tc = 0x1; /* TC0 enabled */
  6650. int f_count = 0;
  6651. memset(&ctxt, 0, sizeof(ctxt));
  6652. switch (vsi->type) {
  6653. case I40E_VSI_MAIN:
  6654. /* The PF's main VSI is already setup as part of the
  6655. * device initialization, so we'll not bother with
  6656. * the add_vsi call, but we will retrieve the current
  6657. * VSI context.
  6658. */
  6659. ctxt.seid = pf->main_vsi_seid;
  6660. ctxt.pf_num = pf->hw.pf_id;
  6661. ctxt.vf_num = 0;
  6662. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  6663. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  6664. if (ret) {
  6665. dev_info(&pf->pdev->dev,
  6666. "couldn't get pf vsi config, err %d, aq_err %d\n",
  6667. ret, pf->hw.aq.asq_last_status);
  6668. return -ENOENT;
  6669. }
  6670. memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
  6671. vsi->info.valid_sections = 0;
  6672. vsi->seid = ctxt.seid;
  6673. vsi->id = ctxt.vsi_number;
  6674. enabled_tc = i40e_pf_get_tc_map(pf);
  6675. /* MFP mode setup queue map and update VSI */
  6676. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  6677. memset(&ctxt, 0, sizeof(ctxt));
  6678. ctxt.seid = pf->main_vsi_seid;
  6679. ctxt.pf_num = pf->hw.pf_id;
  6680. ctxt.vf_num = 0;
  6681. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  6682. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  6683. if (ret) {
  6684. dev_info(&pf->pdev->dev,
  6685. "update vsi failed, aq_err=%d\n",
  6686. pf->hw.aq.asq_last_status);
  6687. ret = -ENOENT;
  6688. goto err;
  6689. }
  6690. /* update the local VSI info queue map */
  6691. i40e_vsi_update_queue_map(vsi, &ctxt);
  6692. vsi->info.valid_sections = 0;
  6693. } else {
  6694. /* Default/Main VSI is only enabled for TC0
  6695. * reconfigure it to enable all TCs that are
  6696. * available on the port in SFP mode.
  6697. */
  6698. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  6699. if (ret) {
  6700. dev_info(&pf->pdev->dev,
  6701. "failed to configure TCs for main VSI tc_map 0x%08x, err %d, aq_err %d\n",
  6702. enabled_tc, ret,
  6703. pf->hw.aq.asq_last_status);
  6704. ret = -ENOENT;
  6705. }
  6706. }
  6707. break;
  6708. case I40E_VSI_FDIR:
  6709. ctxt.pf_num = hw->pf_id;
  6710. ctxt.vf_num = 0;
  6711. ctxt.uplink_seid = vsi->uplink_seid;
  6712. ctxt.connection_type = 0x1; /* regular data port */
  6713. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  6714. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  6715. break;
  6716. case I40E_VSI_VMDQ2:
  6717. ctxt.pf_num = hw->pf_id;
  6718. ctxt.vf_num = 0;
  6719. ctxt.uplink_seid = vsi->uplink_seid;
  6720. ctxt.connection_type = 0x1; /* regular data port */
  6721. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  6722. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  6723. /* This VSI is connected to VEB so the switch_id
  6724. * should be set to zero by default.
  6725. */
  6726. ctxt.info.switch_id = 0;
  6727. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  6728. /* Setup the VSI tx/rx queue map for TC0 only for now */
  6729. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  6730. break;
  6731. case I40E_VSI_SRIOV:
  6732. ctxt.pf_num = hw->pf_id;
  6733. ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
  6734. ctxt.uplink_seid = vsi->uplink_seid;
  6735. ctxt.connection_type = 0x1; /* regular data port */
  6736. ctxt.flags = I40E_AQ_VSI_TYPE_VF;
  6737. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  6738. /* This VSI is connected to VEB so the switch_id
  6739. * should be set to zero by default.
  6740. */
  6741. ctxt.info.switch_id = cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  6742. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  6743. ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
  6744. if (pf->vf[vsi->vf_id].spoofchk) {
  6745. ctxt.info.valid_sections |=
  6746. cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
  6747. ctxt.info.sec_flags |=
  6748. (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
  6749. I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
  6750. }
  6751. /* Setup the VSI tx/rx queue map for TC0 only for now */
  6752. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  6753. break;
  6754. #ifdef I40E_FCOE
  6755. case I40E_VSI_FCOE:
  6756. ret = i40e_fcoe_vsi_init(vsi, &ctxt);
  6757. if (ret) {
  6758. dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n");
  6759. return ret;
  6760. }
  6761. break;
  6762. #endif /* I40E_FCOE */
  6763. default:
  6764. return -ENODEV;
  6765. }
  6766. if (vsi->type != I40E_VSI_MAIN) {
  6767. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  6768. if (ret) {
  6769. dev_info(&vsi->back->pdev->dev,
  6770. "add vsi failed, aq_err=%d\n",
  6771. vsi->back->hw.aq.asq_last_status);
  6772. ret = -ENOENT;
  6773. goto err;
  6774. }
  6775. memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
  6776. vsi->info.valid_sections = 0;
  6777. vsi->seid = ctxt.seid;
  6778. vsi->id = ctxt.vsi_number;
  6779. }
  6780. /* If macvlan filters already exist, force them to get loaded */
  6781. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  6782. f->changed = true;
  6783. f_count++;
  6784. if (f->is_laa && vsi->type == I40E_VSI_MAIN) {
  6785. struct i40e_aqc_remove_macvlan_element_data element;
  6786. memset(&element, 0, sizeof(element));
  6787. ether_addr_copy(element.mac_addr, f->macaddr);
  6788. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  6789. ret = i40e_aq_remove_macvlan(hw, vsi->seid,
  6790. &element, 1, NULL);
  6791. if (ret) {
  6792. /* some older FW has a different default */
  6793. element.flags |=
  6794. I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  6795. i40e_aq_remove_macvlan(hw, vsi->seid,
  6796. &element, 1, NULL);
  6797. }
  6798. i40e_aq_mac_address_write(hw,
  6799. I40E_AQC_WRITE_TYPE_LAA_WOL,
  6800. f->macaddr, NULL);
  6801. }
  6802. }
  6803. if (f_count) {
  6804. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  6805. pf->flags |= I40E_FLAG_FILTER_SYNC;
  6806. }
  6807. /* Update VSI BW information */
  6808. ret = i40e_vsi_get_bw_info(vsi);
  6809. if (ret) {
  6810. dev_info(&pf->pdev->dev,
  6811. "couldn't get vsi bw info, err %d, aq_err %d\n",
  6812. ret, pf->hw.aq.asq_last_status);
  6813. /* VSI is already added so not tearing that up */
  6814. ret = 0;
  6815. }
  6816. err:
  6817. return ret;
  6818. }
  6819. /**
  6820. * i40e_vsi_release - Delete a VSI and free its resources
  6821. * @vsi: the VSI being removed
  6822. *
  6823. * Returns 0 on success or < 0 on error
  6824. **/
  6825. int i40e_vsi_release(struct i40e_vsi *vsi)
  6826. {
  6827. struct i40e_mac_filter *f, *ftmp;
  6828. struct i40e_veb *veb = NULL;
  6829. struct i40e_pf *pf;
  6830. u16 uplink_seid;
  6831. int i, n;
  6832. pf = vsi->back;
  6833. /* release of a VEB-owner or last VSI is not allowed */
  6834. if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
  6835. dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
  6836. vsi->seid, vsi->uplink_seid);
  6837. return -ENODEV;
  6838. }
  6839. if (vsi == pf->vsi[pf->lan_vsi] &&
  6840. !test_bit(__I40E_DOWN, &pf->state)) {
  6841. dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
  6842. return -ENODEV;
  6843. }
  6844. uplink_seid = vsi->uplink_seid;
  6845. if (vsi->type != I40E_VSI_SRIOV) {
  6846. if (vsi->netdev_registered) {
  6847. vsi->netdev_registered = false;
  6848. if (vsi->netdev) {
  6849. /* results in a call to i40e_close() */
  6850. unregister_netdev(vsi->netdev);
  6851. }
  6852. } else {
  6853. i40e_vsi_close(vsi);
  6854. }
  6855. i40e_vsi_disable_irq(vsi);
  6856. }
  6857. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list)
  6858. i40e_del_filter(vsi, f->macaddr, f->vlan,
  6859. f->is_vf, f->is_netdev);
  6860. i40e_sync_vsi_filters(vsi);
  6861. i40e_vsi_delete(vsi);
  6862. i40e_vsi_free_q_vectors(vsi);
  6863. if (vsi->netdev) {
  6864. free_netdev(vsi->netdev);
  6865. vsi->netdev = NULL;
  6866. }
  6867. i40e_vsi_clear_rings(vsi);
  6868. i40e_vsi_clear(vsi);
  6869. /* If this was the last thing on the VEB, except for the
  6870. * controlling VSI, remove the VEB, which puts the controlling
  6871. * VSI onto the next level down in the switch.
  6872. *
  6873. * Well, okay, there's one more exception here: don't remove
  6874. * the orphan VEBs yet. We'll wait for an explicit remove request
  6875. * from up the network stack.
  6876. */
  6877. for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
  6878. if (pf->vsi[i] &&
  6879. pf->vsi[i]->uplink_seid == uplink_seid &&
  6880. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  6881. n++; /* count the VSIs */
  6882. }
  6883. }
  6884. for (i = 0; i < I40E_MAX_VEB; i++) {
  6885. if (!pf->veb[i])
  6886. continue;
  6887. if (pf->veb[i]->uplink_seid == uplink_seid)
  6888. n++; /* count the VEBs */
  6889. if (pf->veb[i]->seid == uplink_seid)
  6890. veb = pf->veb[i];
  6891. }
  6892. if (n == 0 && veb && veb->uplink_seid != 0)
  6893. i40e_veb_release(veb);
  6894. return 0;
  6895. }
  6896. /**
  6897. * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
  6898. * @vsi: ptr to the VSI
  6899. *
  6900. * This should only be called after i40e_vsi_mem_alloc() which allocates the
  6901. * corresponding SW VSI structure and initializes num_queue_pairs for the
  6902. * newly allocated VSI.
  6903. *
  6904. * Returns 0 on success or negative on failure
  6905. **/
  6906. static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
  6907. {
  6908. int ret = -ENOENT;
  6909. struct i40e_pf *pf = vsi->back;
  6910. if (vsi->q_vectors[0]) {
  6911. dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
  6912. vsi->seid);
  6913. return -EEXIST;
  6914. }
  6915. if (vsi->base_vector) {
  6916. dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
  6917. vsi->seid, vsi->base_vector);
  6918. return -EEXIST;
  6919. }
  6920. ret = i40e_vsi_alloc_q_vectors(vsi);
  6921. if (ret) {
  6922. dev_info(&pf->pdev->dev,
  6923. "failed to allocate %d q_vector for VSI %d, ret=%d\n",
  6924. vsi->num_q_vectors, vsi->seid, ret);
  6925. vsi->num_q_vectors = 0;
  6926. goto vector_setup_out;
  6927. }
  6928. if (vsi->num_q_vectors)
  6929. vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
  6930. vsi->num_q_vectors, vsi->idx);
  6931. if (vsi->base_vector < 0) {
  6932. dev_info(&pf->pdev->dev,
  6933. "failed to get queue tracking for VSI %d, err=%d\n",
  6934. vsi->seid, vsi->base_vector);
  6935. i40e_vsi_free_q_vectors(vsi);
  6936. ret = -ENOENT;
  6937. goto vector_setup_out;
  6938. }
  6939. vector_setup_out:
  6940. return ret;
  6941. }
  6942. /**
  6943. * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
  6944. * @vsi: pointer to the vsi.
  6945. *
  6946. * This re-allocates a vsi's queue resources.
  6947. *
  6948. * Returns pointer to the successfully allocated and configured VSI sw struct
  6949. * on success, otherwise returns NULL on failure.
  6950. **/
  6951. static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
  6952. {
  6953. struct i40e_pf *pf = vsi->back;
  6954. u8 enabled_tc;
  6955. int ret;
  6956. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  6957. i40e_vsi_clear_rings(vsi);
  6958. i40e_vsi_free_arrays(vsi, false);
  6959. i40e_set_num_rings_in_vsi(vsi);
  6960. ret = i40e_vsi_alloc_arrays(vsi, false);
  6961. if (ret)
  6962. goto err_vsi;
  6963. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
  6964. if (ret < 0) {
  6965. dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n",
  6966. vsi->seid, ret);
  6967. goto err_vsi;
  6968. }
  6969. vsi->base_queue = ret;
  6970. /* Update the FW view of the VSI. Force a reset of TC and queue
  6971. * layout configurations.
  6972. */
  6973. enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  6974. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  6975. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  6976. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  6977. /* assign it some queues */
  6978. ret = i40e_alloc_rings(vsi);
  6979. if (ret)
  6980. goto err_rings;
  6981. /* map all of the rings to the q_vectors */
  6982. i40e_vsi_map_rings_to_vectors(vsi);
  6983. return vsi;
  6984. err_rings:
  6985. i40e_vsi_free_q_vectors(vsi);
  6986. if (vsi->netdev_registered) {
  6987. vsi->netdev_registered = false;
  6988. unregister_netdev(vsi->netdev);
  6989. free_netdev(vsi->netdev);
  6990. vsi->netdev = NULL;
  6991. }
  6992. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  6993. err_vsi:
  6994. i40e_vsi_clear(vsi);
  6995. return NULL;
  6996. }
  6997. /**
  6998. * i40e_vsi_setup - Set up a VSI by a given type
  6999. * @pf: board private structure
  7000. * @type: VSI type
  7001. * @uplink_seid: the switch element to link to
  7002. * @param1: usage depends upon VSI type. For VF types, indicates VF id
  7003. *
  7004. * This allocates the sw VSI structure and its queue resources, then add a VSI
  7005. * to the identified VEB.
  7006. *
  7007. * Returns pointer to the successfully allocated and configure VSI sw struct on
  7008. * success, otherwise returns NULL on failure.
  7009. **/
  7010. struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
  7011. u16 uplink_seid, u32 param1)
  7012. {
  7013. struct i40e_vsi *vsi = NULL;
  7014. struct i40e_veb *veb = NULL;
  7015. int ret, i;
  7016. int v_idx;
  7017. /* The requested uplink_seid must be either
  7018. * - the PF's port seid
  7019. * no VEB is needed because this is the PF
  7020. * or this is a Flow Director special case VSI
  7021. * - seid of an existing VEB
  7022. * - seid of a VSI that owns an existing VEB
  7023. * - seid of a VSI that doesn't own a VEB
  7024. * a new VEB is created and the VSI becomes the owner
  7025. * - seid of the PF VSI, which is what creates the first VEB
  7026. * this is a special case of the previous
  7027. *
  7028. * Find which uplink_seid we were given and create a new VEB if needed
  7029. */
  7030. for (i = 0; i < I40E_MAX_VEB; i++) {
  7031. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
  7032. veb = pf->veb[i];
  7033. break;
  7034. }
  7035. }
  7036. if (!veb && uplink_seid != pf->mac_seid) {
  7037. for (i = 0; i < pf->num_alloc_vsi; i++) {
  7038. if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
  7039. vsi = pf->vsi[i];
  7040. break;
  7041. }
  7042. }
  7043. if (!vsi) {
  7044. dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
  7045. uplink_seid);
  7046. return NULL;
  7047. }
  7048. if (vsi->uplink_seid == pf->mac_seid)
  7049. veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
  7050. vsi->tc_config.enabled_tc);
  7051. else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
  7052. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  7053. vsi->tc_config.enabled_tc);
  7054. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  7055. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  7056. veb = pf->veb[i];
  7057. }
  7058. if (!veb) {
  7059. dev_info(&pf->pdev->dev, "couldn't add VEB\n");
  7060. return NULL;
  7061. }
  7062. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  7063. uplink_seid = veb->seid;
  7064. }
  7065. /* get vsi sw struct */
  7066. v_idx = i40e_vsi_mem_alloc(pf, type);
  7067. if (v_idx < 0)
  7068. goto err_alloc;
  7069. vsi = pf->vsi[v_idx];
  7070. if (!vsi)
  7071. goto err_alloc;
  7072. vsi->type = type;
  7073. vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
  7074. if (type == I40E_VSI_MAIN)
  7075. pf->lan_vsi = v_idx;
  7076. else if (type == I40E_VSI_SRIOV)
  7077. vsi->vf_id = param1;
  7078. /* assign it some queues */
  7079. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs,
  7080. vsi->idx);
  7081. if (ret < 0) {
  7082. dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n",
  7083. vsi->seid, ret);
  7084. goto err_vsi;
  7085. }
  7086. vsi->base_queue = ret;
  7087. /* get a VSI from the hardware */
  7088. vsi->uplink_seid = uplink_seid;
  7089. ret = i40e_add_vsi(vsi);
  7090. if (ret)
  7091. goto err_vsi;
  7092. switch (vsi->type) {
  7093. /* setup the netdev if needed */
  7094. case I40E_VSI_MAIN:
  7095. case I40E_VSI_VMDQ2:
  7096. case I40E_VSI_FCOE:
  7097. ret = i40e_config_netdev(vsi);
  7098. if (ret)
  7099. goto err_netdev;
  7100. ret = register_netdev(vsi->netdev);
  7101. if (ret)
  7102. goto err_netdev;
  7103. vsi->netdev_registered = true;
  7104. netif_carrier_off(vsi->netdev);
  7105. #ifdef CONFIG_I40E_DCB
  7106. /* Setup DCB netlink interface */
  7107. i40e_dcbnl_setup(vsi);
  7108. #endif /* CONFIG_I40E_DCB */
  7109. /* fall through */
  7110. case I40E_VSI_FDIR:
  7111. /* set up vectors and rings if needed */
  7112. ret = i40e_vsi_setup_vectors(vsi);
  7113. if (ret)
  7114. goto err_msix;
  7115. ret = i40e_alloc_rings(vsi);
  7116. if (ret)
  7117. goto err_rings;
  7118. /* map all of the rings to the q_vectors */
  7119. i40e_vsi_map_rings_to_vectors(vsi);
  7120. i40e_vsi_reset_stats(vsi);
  7121. break;
  7122. default:
  7123. /* no netdev or rings for the other VSI types */
  7124. break;
  7125. }
  7126. return vsi;
  7127. err_rings:
  7128. i40e_vsi_free_q_vectors(vsi);
  7129. err_msix:
  7130. if (vsi->netdev_registered) {
  7131. vsi->netdev_registered = false;
  7132. unregister_netdev(vsi->netdev);
  7133. free_netdev(vsi->netdev);
  7134. vsi->netdev = NULL;
  7135. }
  7136. err_netdev:
  7137. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  7138. err_vsi:
  7139. i40e_vsi_clear(vsi);
  7140. err_alloc:
  7141. return NULL;
  7142. }
  7143. /**
  7144. * i40e_veb_get_bw_info - Query VEB BW information
  7145. * @veb: the veb to query
  7146. *
  7147. * Query the Tx scheduler BW configuration data for given VEB
  7148. **/
  7149. static int i40e_veb_get_bw_info(struct i40e_veb *veb)
  7150. {
  7151. struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
  7152. struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
  7153. struct i40e_pf *pf = veb->pf;
  7154. struct i40e_hw *hw = &pf->hw;
  7155. u32 tc_bw_max;
  7156. int ret = 0;
  7157. int i;
  7158. ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
  7159. &bw_data, NULL);
  7160. if (ret) {
  7161. dev_info(&pf->pdev->dev,
  7162. "query veb bw config failed, aq_err=%d\n",
  7163. hw->aq.asq_last_status);
  7164. goto out;
  7165. }
  7166. ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
  7167. &ets_data, NULL);
  7168. if (ret) {
  7169. dev_info(&pf->pdev->dev,
  7170. "query veb bw ets config failed, aq_err=%d\n",
  7171. hw->aq.asq_last_status);
  7172. goto out;
  7173. }
  7174. veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
  7175. veb->bw_max_quanta = ets_data.tc_bw_max;
  7176. veb->is_abs_credits = bw_data.absolute_credits_enable;
  7177. tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
  7178. (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
  7179. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  7180. veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
  7181. veb->bw_tc_limit_credits[i] =
  7182. le16_to_cpu(bw_data.tc_bw_limits[i]);
  7183. veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
  7184. }
  7185. out:
  7186. return ret;
  7187. }
  7188. /**
  7189. * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
  7190. * @pf: board private structure
  7191. *
  7192. * On error: returns error code (negative)
  7193. * On success: returns vsi index in PF (positive)
  7194. **/
  7195. static int i40e_veb_mem_alloc(struct i40e_pf *pf)
  7196. {
  7197. int ret = -ENOENT;
  7198. struct i40e_veb *veb;
  7199. int i;
  7200. /* Need to protect the allocation of switch elements at the PF level */
  7201. mutex_lock(&pf->switch_mutex);
  7202. /* VEB list may be fragmented if VEB creation/destruction has
  7203. * been happening. We can afford to do a quick scan to look
  7204. * for any free slots in the list.
  7205. *
  7206. * find next empty veb slot, looping back around if necessary
  7207. */
  7208. i = 0;
  7209. while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
  7210. i++;
  7211. if (i >= I40E_MAX_VEB) {
  7212. ret = -ENOMEM;
  7213. goto err_alloc_veb; /* out of VEB slots! */
  7214. }
  7215. veb = kzalloc(sizeof(*veb), GFP_KERNEL);
  7216. if (!veb) {
  7217. ret = -ENOMEM;
  7218. goto err_alloc_veb;
  7219. }
  7220. veb->pf = pf;
  7221. veb->idx = i;
  7222. veb->enabled_tc = 1;
  7223. pf->veb[i] = veb;
  7224. ret = i;
  7225. err_alloc_veb:
  7226. mutex_unlock(&pf->switch_mutex);
  7227. return ret;
  7228. }
  7229. /**
  7230. * i40e_switch_branch_release - Delete a branch of the switch tree
  7231. * @branch: where to start deleting
  7232. *
  7233. * This uses recursion to find the tips of the branch to be
  7234. * removed, deleting until we get back to and can delete this VEB.
  7235. **/
  7236. static void i40e_switch_branch_release(struct i40e_veb *branch)
  7237. {
  7238. struct i40e_pf *pf = branch->pf;
  7239. u16 branch_seid = branch->seid;
  7240. u16 veb_idx = branch->idx;
  7241. int i;
  7242. /* release any VEBs on this VEB - RECURSION */
  7243. for (i = 0; i < I40E_MAX_VEB; i++) {
  7244. if (!pf->veb[i])
  7245. continue;
  7246. if (pf->veb[i]->uplink_seid == branch->seid)
  7247. i40e_switch_branch_release(pf->veb[i]);
  7248. }
  7249. /* Release the VSIs on this VEB, but not the owner VSI.
  7250. *
  7251. * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
  7252. * the VEB itself, so don't use (*branch) after this loop.
  7253. */
  7254. for (i = 0; i < pf->num_alloc_vsi; i++) {
  7255. if (!pf->vsi[i])
  7256. continue;
  7257. if (pf->vsi[i]->uplink_seid == branch_seid &&
  7258. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  7259. i40e_vsi_release(pf->vsi[i]);
  7260. }
  7261. }
  7262. /* There's one corner case where the VEB might not have been
  7263. * removed, so double check it here and remove it if needed.
  7264. * This case happens if the veb was created from the debugfs
  7265. * commands and no VSIs were added to it.
  7266. */
  7267. if (pf->veb[veb_idx])
  7268. i40e_veb_release(pf->veb[veb_idx]);
  7269. }
  7270. /**
  7271. * i40e_veb_clear - remove veb struct
  7272. * @veb: the veb to remove
  7273. **/
  7274. static void i40e_veb_clear(struct i40e_veb *veb)
  7275. {
  7276. if (!veb)
  7277. return;
  7278. if (veb->pf) {
  7279. struct i40e_pf *pf = veb->pf;
  7280. mutex_lock(&pf->switch_mutex);
  7281. if (pf->veb[veb->idx] == veb)
  7282. pf->veb[veb->idx] = NULL;
  7283. mutex_unlock(&pf->switch_mutex);
  7284. }
  7285. kfree(veb);
  7286. }
  7287. /**
  7288. * i40e_veb_release - Delete a VEB and free its resources
  7289. * @veb: the VEB being removed
  7290. **/
  7291. void i40e_veb_release(struct i40e_veb *veb)
  7292. {
  7293. struct i40e_vsi *vsi = NULL;
  7294. struct i40e_pf *pf;
  7295. int i, n = 0;
  7296. pf = veb->pf;
  7297. /* find the remaining VSI and check for extras */
  7298. for (i = 0; i < pf->num_alloc_vsi; i++) {
  7299. if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
  7300. n++;
  7301. vsi = pf->vsi[i];
  7302. }
  7303. }
  7304. if (n != 1) {
  7305. dev_info(&pf->pdev->dev,
  7306. "can't remove VEB %d with %d VSIs left\n",
  7307. veb->seid, n);
  7308. return;
  7309. }
  7310. /* move the remaining VSI to uplink veb */
  7311. vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
  7312. if (veb->uplink_seid) {
  7313. vsi->uplink_seid = veb->uplink_seid;
  7314. if (veb->uplink_seid == pf->mac_seid)
  7315. vsi->veb_idx = I40E_NO_VEB;
  7316. else
  7317. vsi->veb_idx = veb->veb_idx;
  7318. } else {
  7319. /* floating VEB */
  7320. vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  7321. vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
  7322. }
  7323. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  7324. i40e_veb_clear(veb);
  7325. }
  7326. /**
  7327. * i40e_add_veb - create the VEB in the switch
  7328. * @veb: the VEB to be instantiated
  7329. * @vsi: the controlling VSI
  7330. **/
  7331. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
  7332. {
  7333. bool is_default = false;
  7334. bool is_cloud = false;
  7335. int ret;
  7336. /* get a VEB from the hardware */
  7337. ret = i40e_aq_add_veb(&veb->pf->hw, veb->uplink_seid, vsi->seid,
  7338. veb->enabled_tc, is_default,
  7339. is_cloud, &veb->seid, NULL);
  7340. if (ret) {
  7341. dev_info(&veb->pf->pdev->dev,
  7342. "couldn't add VEB, err %d, aq_err %d\n",
  7343. ret, veb->pf->hw.aq.asq_last_status);
  7344. return -EPERM;
  7345. }
  7346. /* get statistics counter */
  7347. ret = i40e_aq_get_veb_parameters(&veb->pf->hw, veb->seid, NULL, NULL,
  7348. &veb->stats_idx, NULL, NULL, NULL);
  7349. if (ret) {
  7350. dev_info(&veb->pf->pdev->dev,
  7351. "couldn't get VEB statistics idx, err %d, aq_err %d\n",
  7352. ret, veb->pf->hw.aq.asq_last_status);
  7353. return -EPERM;
  7354. }
  7355. ret = i40e_veb_get_bw_info(veb);
  7356. if (ret) {
  7357. dev_info(&veb->pf->pdev->dev,
  7358. "couldn't get VEB bw info, err %d, aq_err %d\n",
  7359. ret, veb->pf->hw.aq.asq_last_status);
  7360. i40e_aq_delete_element(&veb->pf->hw, veb->seid, NULL);
  7361. return -ENOENT;
  7362. }
  7363. vsi->uplink_seid = veb->seid;
  7364. vsi->veb_idx = veb->idx;
  7365. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  7366. return 0;
  7367. }
  7368. /**
  7369. * i40e_veb_setup - Set up a VEB
  7370. * @pf: board private structure
  7371. * @flags: VEB setup flags
  7372. * @uplink_seid: the switch element to link to
  7373. * @vsi_seid: the initial VSI seid
  7374. * @enabled_tc: Enabled TC bit-map
  7375. *
  7376. * This allocates the sw VEB structure and links it into the switch
  7377. * It is possible and legal for this to be a duplicate of an already
  7378. * existing VEB. It is also possible for both uplink and vsi seids
  7379. * to be zero, in order to create a floating VEB.
  7380. *
  7381. * Returns pointer to the successfully allocated VEB sw struct on
  7382. * success, otherwise returns NULL on failure.
  7383. **/
  7384. struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
  7385. u16 uplink_seid, u16 vsi_seid,
  7386. u8 enabled_tc)
  7387. {
  7388. struct i40e_veb *veb, *uplink_veb = NULL;
  7389. int vsi_idx, veb_idx;
  7390. int ret;
  7391. /* if one seid is 0, the other must be 0 to create a floating relay */
  7392. if ((uplink_seid == 0 || vsi_seid == 0) &&
  7393. (uplink_seid + vsi_seid != 0)) {
  7394. dev_info(&pf->pdev->dev,
  7395. "one, not both seid's are 0: uplink=%d vsi=%d\n",
  7396. uplink_seid, vsi_seid);
  7397. return NULL;
  7398. }
  7399. /* make sure there is such a vsi and uplink */
  7400. for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
  7401. if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
  7402. break;
  7403. if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
  7404. dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
  7405. vsi_seid);
  7406. return NULL;
  7407. }
  7408. if (uplink_seid && uplink_seid != pf->mac_seid) {
  7409. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  7410. if (pf->veb[veb_idx] &&
  7411. pf->veb[veb_idx]->seid == uplink_seid) {
  7412. uplink_veb = pf->veb[veb_idx];
  7413. break;
  7414. }
  7415. }
  7416. if (!uplink_veb) {
  7417. dev_info(&pf->pdev->dev,
  7418. "uplink seid %d not found\n", uplink_seid);
  7419. return NULL;
  7420. }
  7421. }
  7422. /* get veb sw struct */
  7423. veb_idx = i40e_veb_mem_alloc(pf);
  7424. if (veb_idx < 0)
  7425. goto err_alloc;
  7426. veb = pf->veb[veb_idx];
  7427. veb->flags = flags;
  7428. veb->uplink_seid = uplink_seid;
  7429. veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
  7430. veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
  7431. /* create the VEB in the switch */
  7432. ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
  7433. if (ret)
  7434. goto err_veb;
  7435. if (vsi_idx == pf->lan_vsi)
  7436. pf->lan_veb = veb->idx;
  7437. return veb;
  7438. err_veb:
  7439. i40e_veb_clear(veb);
  7440. err_alloc:
  7441. return NULL;
  7442. }
  7443. /**
  7444. * i40e_setup_pf_switch_element - set pf vars based on switch type
  7445. * @pf: board private structure
  7446. * @ele: element we are building info from
  7447. * @num_reported: total number of elements
  7448. * @printconfig: should we print the contents
  7449. *
  7450. * helper function to assist in extracting a few useful SEID values.
  7451. **/
  7452. static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
  7453. struct i40e_aqc_switch_config_element_resp *ele,
  7454. u16 num_reported, bool printconfig)
  7455. {
  7456. u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
  7457. u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
  7458. u8 element_type = ele->element_type;
  7459. u16 seid = le16_to_cpu(ele->seid);
  7460. if (printconfig)
  7461. dev_info(&pf->pdev->dev,
  7462. "type=%d seid=%d uplink=%d downlink=%d\n",
  7463. element_type, seid, uplink_seid, downlink_seid);
  7464. switch (element_type) {
  7465. case I40E_SWITCH_ELEMENT_TYPE_MAC:
  7466. pf->mac_seid = seid;
  7467. break;
  7468. case I40E_SWITCH_ELEMENT_TYPE_VEB:
  7469. /* Main VEB? */
  7470. if (uplink_seid != pf->mac_seid)
  7471. break;
  7472. if (pf->lan_veb == I40E_NO_VEB) {
  7473. int v;
  7474. /* find existing or else empty VEB */
  7475. for (v = 0; v < I40E_MAX_VEB; v++) {
  7476. if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
  7477. pf->lan_veb = v;
  7478. break;
  7479. }
  7480. }
  7481. if (pf->lan_veb == I40E_NO_VEB) {
  7482. v = i40e_veb_mem_alloc(pf);
  7483. if (v < 0)
  7484. break;
  7485. pf->lan_veb = v;
  7486. }
  7487. }
  7488. pf->veb[pf->lan_veb]->seid = seid;
  7489. pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
  7490. pf->veb[pf->lan_veb]->pf = pf;
  7491. pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
  7492. break;
  7493. case I40E_SWITCH_ELEMENT_TYPE_VSI:
  7494. if (num_reported != 1)
  7495. break;
  7496. /* This is immediately after a reset so we can assume this is
  7497. * the PF's VSI
  7498. */
  7499. pf->mac_seid = uplink_seid;
  7500. pf->pf_seid = downlink_seid;
  7501. pf->main_vsi_seid = seid;
  7502. if (printconfig)
  7503. dev_info(&pf->pdev->dev,
  7504. "pf_seid=%d main_vsi_seid=%d\n",
  7505. pf->pf_seid, pf->main_vsi_seid);
  7506. break;
  7507. case I40E_SWITCH_ELEMENT_TYPE_PF:
  7508. case I40E_SWITCH_ELEMENT_TYPE_VF:
  7509. case I40E_SWITCH_ELEMENT_TYPE_EMP:
  7510. case I40E_SWITCH_ELEMENT_TYPE_BMC:
  7511. case I40E_SWITCH_ELEMENT_TYPE_PE:
  7512. case I40E_SWITCH_ELEMENT_TYPE_PA:
  7513. /* ignore these for now */
  7514. break;
  7515. default:
  7516. dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
  7517. element_type, seid);
  7518. break;
  7519. }
  7520. }
  7521. /**
  7522. * i40e_fetch_switch_configuration - Get switch config from firmware
  7523. * @pf: board private structure
  7524. * @printconfig: should we print the contents
  7525. *
  7526. * Get the current switch configuration from the device and
  7527. * extract a few useful SEID values.
  7528. **/
  7529. int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
  7530. {
  7531. struct i40e_aqc_get_switch_config_resp *sw_config;
  7532. u16 next_seid = 0;
  7533. int ret = 0;
  7534. u8 *aq_buf;
  7535. int i;
  7536. aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
  7537. if (!aq_buf)
  7538. return -ENOMEM;
  7539. sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
  7540. do {
  7541. u16 num_reported, num_total;
  7542. ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
  7543. I40E_AQ_LARGE_BUF,
  7544. &next_seid, NULL);
  7545. if (ret) {
  7546. dev_info(&pf->pdev->dev,
  7547. "get switch config failed %d aq_err=%x\n",
  7548. ret, pf->hw.aq.asq_last_status);
  7549. kfree(aq_buf);
  7550. return -ENOENT;
  7551. }
  7552. num_reported = le16_to_cpu(sw_config->header.num_reported);
  7553. num_total = le16_to_cpu(sw_config->header.num_total);
  7554. if (printconfig)
  7555. dev_info(&pf->pdev->dev,
  7556. "header: %d reported %d total\n",
  7557. num_reported, num_total);
  7558. for (i = 0; i < num_reported; i++) {
  7559. struct i40e_aqc_switch_config_element_resp *ele =
  7560. &sw_config->element[i];
  7561. i40e_setup_pf_switch_element(pf, ele, num_reported,
  7562. printconfig);
  7563. }
  7564. } while (next_seid != 0);
  7565. kfree(aq_buf);
  7566. return ret;
  7567. }
  7568. /**
  7569. * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
  7570. * @pf: board private structure
  7571. * @reinit: if the Main VSI needs to re-initialized.
  7572. *
  7573. * Returns 0 on success, negative value on failure
  7574. **/
  7575. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
  7576. {
  7577. int ret;
  7578. /* find out what's out there already */
  7579. ret = i40e_fetch_switch_configuration(pf, false);
  7580. if (ret) {
  7581. dev_info(&pf->pdev->dev,
  7582. "couldn't fetch switch config, err %d, aq_err %d\n",
  7583. ret, pf->hw.aq.asq_last_status);
  7584. return ret;
  7585. }
  7586. i40e_pf_reset_stats(pf);
  7587. /* first time setup */
  7588. if (pf->lan_vsi == I40E_NO_VSI || reinit) {
  7589. struct i40e_vsi *vsi = NULL;
  7590. u16 uplink_seid;
  7591. /* Set up the PF VSI associated with the PF's main VSI
  7592. * that is already in the HW switch
  7593. */
  7594. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  7595. uplink_seid = pf->veb[pf->lan_veb]->seid;
  7596. else
  7597. uplink_seid = pf->mac_seid;
  7598. if (pf->lan_vsi == I40E_NO_VSI)
  7599. vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
  7600. else if (reinit)
  7601. vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
  7602. if (!vsi) {
  7603. dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
  7604. i40e_fdir_teardown(pf);
  7605. return -EAGAIN;
  7606. }
  7607. } else {
  7608. /* force a reset of TC and queue layout configurations */
  7609. u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  7610. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  7611. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  7612. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  7613. }
  7614. i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
  7615. i40e_fdir_sb_setup(pf);
  7616. /* Setup static PF queue filter control settings */
  7617. ret = i40e_setup_pf_filter_control(pf);
  7618. if (ret) {
  7619. dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
  7620. ret);
  7621. /* Failure here should not stop continuing other steps */
  7622. }
  7623. /* enable RSS in the HW, even for only one queue, as the stack can use
  7624. * the hash
  7625. */
  7626. if ((pf->flags & I40E_FLAG_RSS_ENABLED))
  7627. i40e_config_rss(pf);
  7628. /* fill in link information and enable LSE reporting */
  7629. i40e_update_link_info(&pf->hw, true);
  7630. i40e_link_event(pf);
  7631. /* Initialize user-specific link properties */
  7632. pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
  7633. I40E_AQ_AN_COMPLETED) ? true : false);
  7634. i40e_ptp_init(pf);
  7635. return ret;
  7636. }
  7637. /**
  7638. * i40e_determine_queue_usage - Work out queue distribution
  7639. * @pf: board private structure
  7640. **/
  7641. static void i40e_determine_queue_usage(struct i40e_pf *pf)
  7642. {
  7643. int queues_left;
  7644. pf->num_lan_qps = 0;
  7645. #ifdef I40E_FCOE
  7646. pf->num_fcoe_qps = 0;
  7647. #endif
  7648. /* Find the max queues to be put into basic use. We'll always be
  7649. * using TC0, whether or not DCB is running, and TC0 will get the
  7650. * big RSS set.
  7651. */
  7652. queues_left = pf->hw.func_caps.num_tx_qp;
  7653. if ((queues_left == 1) ||
  7654. !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  7655. /* one qp for PF, no queues for anything else */
  7656. queues_left = 0;
  7657. pf->rss_size = pf->num_lan_qps = 1;
  7658. /* make sure all the fancies are disabled */
  7659. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  7660. #ifdef I40E_FCOE
  7661. I40E_FLAG_FCOE_ENABLED |
  7662. #endif
  7663. I40E_FLAG_FD_SB_ENABLED |
  7664. I40E_FLAG_FD_ATR_ENABLED |
  7665. I40E_FLAG_DCB_CAPABLE |
  7666. I40E_FLAG_SRIOV_ENABLED |
  7667. I40E_FLAG_VMDQ_ENABLED);
  7668. } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
  7669. I40E_FLAG_FD_SB_ENABLED |
  7670. I40E_FLAG_FD_ATR_ENABLED |
  7671. I40E_FLAG_DCB_CAPABLE))) {
  7672. /* one qp for PF */
  7673. pf->rss_size = pf->num_lan_qps = 1;
  7674. queues_left -= pf->num_lan_qps;
  7675. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  7676. #ifdef I40E_FCOE
  7677. I40E_FLAG_FCOE_ENABLED |
  7678. #endif
  7679. I40E_FLAG_FD_SB_ENABLED |
  7680. I40E_FLAG_FD_ATR_ENABLED |
  7681. I40E_FLAG_DCB_ENABLED |
  7682. I40E_FLAG_VMDQ_ENABLED);
  7683. } else {
  7684. /* Not enough queues for all TCs */
  7685. if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
  7686. (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
  7687. pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
  7688. dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
  7689. }
  7690. pf->num_lan_qps = pf->rss_size_max;
  7691. queues_left -= pf->num_lan_qps;
  7692. }
  7693. #ifdef I40E_FCOE
  7694. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  7695. if (I40E_DEFAULT_FCOE <= queues_left) {
  7696. pf->num_fcoe_qps = I40E_DEFAULT_FCOE;
  7697. } else if (I40E_MINIMUM_FCOE <= queues_left) {
  7698. pf->num_fcoe_qps = I40E_MINIMUM_FCOE;
  7699. } else {
  7700. pf->num_fcoe_qps = 0;
  7701. pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
  7702. dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n");
  7703. }
  7704. queues_left -= pf->num_fcoe_qps;
  7705. }
  7706. #endif
  7707. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  7708. if (queues_left > 1) {
  7709. queues_left -= 1; /* save 1 queue for FD */
  7710. } else {
  7711. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7712. dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
  7713. }
  7714. }
  7715. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  7716. pf->num_vf_qps && pf->num_req_vfs && queues_left) {
  7717. pf->num_req_vfs = min_t(int, pf->num_req_vfs,
  7718. (queues_left / pf->num_vf_qps));
  7719. queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
  7720. }
  7721. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  7722. pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
  7723. pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
  7724. (queues_left / pf->num_vmdq_qps));
  7725. queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
  7726. }
  7727. pf->queues_left = queues_left;
  7728. #ifdef I40E_FCOE
  7729. dev_info(&pf->pdev->dev, "fcoe queues = %d\n", pf->num_fcoe_qps);
  7730. #endif
  7731. }
  7732. /**
  7733. * i40e_setup_pf_filter_control - Setup PF static filter control
  7734. * @pf: PF to be setup
  7735. *
  7736. * i40e_setup_pf_filter_control sets up a pf's initial filter control
  7737. * settings. If PE/FCoE are enabled then it will also set the per PF
  7738. * based filter sizes required for them. It also enables Flow director,
  7739. * ethertype and macvlan type filter settings for the pf.
  7740. *
  7741. * Returns 0 on success, negative on failure
  7742. **/
  7743. static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
  7744. {
  7745. struct i40e_filter_control_settings *settings = &pf->filter_settings;
  7746. settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
  7747. /* Flow Director is enabled */
  7748. if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
  7749. settings->enable_fdir = true;
  7750. /* Ethtype and MACVLAN filters enabled for PF */
  7751. settings->enable_ethtype = true;
  7752. settings->enable_macvlan = true;
  7753. if (i40e_set_filter_control(&pf->hw, settings))
  7754. return -ENOENT;
  7755. return 0;
  7756. }
  7757. #define INFO_STRING_LEN 255
  7758. static void i40e_print_features(struct i40e_pf *pf)
  7759. {
  7760. struct i40e_hw *hw = &pf->hw;
  7761. char *buf, *string;
  7762. string = kzalloc(INFO_STRING_LEN, GFP_KERNEL);
  7763. if (!string) {
  7764. dev_err(&pf->pdev->dev, "Features string allocation failed\n");
  7765. return;
  7766. }
  7767. buf = string;
  7768. buf += sprintf(string, "Features: PF-id[%d] ", hw->pf_id);
  7769. #ifdef CONFIG_PCI_IOV
  7770. buf += sprintf(buf, "VFs: %d ", pf->num_req_vfs);
  7771. #endif
  7772. buf += sprintf(buf, "VSIs: %d QP: %d ", pf->hw.func_caps.num_vsis,
  7773. pf->vsi[pf->lan_vsi]->num_queue_pairs);
  7774. if (pf->flags & I40E_FLAG_RSS_ENABLED)
  7775. buf += sprintf(buf, "RSS ");
  7776. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
  7777. buf += sprintf(buf, "FD_ATR ");
  7778. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  7779. buf += sprintf(buf, "FD_SB ");
  7780. buf += sprintf(buf, "NTUPLE ");
  7781. }
  7782. if (pf->flags & I40E_FLAG_DCB_CAPABLE)
  7783. buf += sprintf(buf, "DCB ");
  7784. if (pf->flags & I40E_FLAG_PTP)
  7785. buf += sprintf(buf, "PTP ");
  7786. #ifdef I40E_FCOE
  7787. if (pf->flags & I40E_FLAG_FCOE_ENABLED)
  7788. buf += sprintf(buf, "FCOE ");
  7789. #endif
  7790. BUG_ON(buf > (string + INFO_STRING_LEN));
  7791. dev_info(&pf->pdev->dev, "%s\n", string);
  7792. kfree(string);
  7793. }
  7794. /**
  7795. * i40e_probe - Device initialization routine
  7796. * @pdev: PCI device information struct
  7797. * @ent: entry in i40e_pci_tbl
  7798. *
  7799. * i40e_probe initializes a pf identified by a pci_dev structure.
  7800. * The OS initialization, configuring of the pf private structure,
  7801. * and a hardware reset occur.
  7802. *
  7803. * Returns 0 on success, negative on failure
  7804. **/
  7805. static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  7806. {
  7807. struct i40e_pf *pf;
  7808. struct i40e_hw *hw;
  7809. static u16 pfs_found;
  7810. u16 link_status;
  7811. int err = 0;
  7812. u32 len;
  7813. u32 i;
  7814. err = pci_enable_device_mem(pdev);
  7815. if (err)
  7816. return err;
  7817. /* set up for high or low dma */
  7818. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  7819. if (err) {
  7820. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  7821. if (err) {
  7822. dev_err(&pdev->dev,
  7823. "DMA configuration failed: 0x%x\n", err);
  7824. goto err_dma;
  7825. }
  7826. }
  7827. /* set up pci connections */
  7828. err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
  7829. IORESOURCE_MEM), i40e_driver_name);
  7830. if (err) {
  7831. dev_info(&pdev->dev,
  7832. "pci_request_selected_regions failed %d\n", err);
  7833. goto err_pci_reg;
  7834. }
  7835. pci_enable_pcie_error_reporting(pdev);
  7836. pci_set_master(pdev);
  7837. /* Now that we have a PCI connection, we need to do the
  7838. * low level device setup. This is primarily setting up
  7839. * the Admin Queue structures and then querying for the
  7840. * device's current profile information.
  7841. */
  7842. pf = kzalloc(sizeof(*pf), GFP_KERNEL);
  7843. if (!pf) {
  7844. err = -ENOMEM;
  7845. goto err_pf_alloc;
  7846. }
  7847. pf->next_vsi = 0;
  7848. pf->pdev = pdev;
  7849. set_bit(__I40E_DOWN, &pf->state);
  7850. hw = &pf->hw;
  7851. hw->back = pf;
  7852. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  7853. pci_resource_len(pdev, 0));
  7854. if (!hw->hw_addr) {
  7855. err = -EIO;
  7856. dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
  7857. (unsigned int)pci_resource_start(pdev, 0),
  7858. (unsigned int)pci_resource_len(pdev, 0), err);
  7859. goto err_ioremap;
  7860. }
  7861. hw->vendor_id = pdev->vendor;
  7862. hw->device_id = pdev->device;
  7863. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  7864. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  7865. hw->subsystem_device_id = pdev->subsystem_device;
  7866. hw->bus.device = PCI_SLOT(pdev->devfn);
  7867. hw->bus.func = PCI_FUNC(pdev->devfn);
  7868. pf->instance = pfs_found;
  7869. /* do a special CORER for clearing PXE mode once at init */
  7870. if (hw->revision_id == 0 &&
  7871. (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
  7872. wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
  7873. i40e_flush(hw);
  7874. msleep(200);
  7875. pf->corer_count++;
  7876. i40e_clear_pxe_mode(hw);
  7877. }
  7878. /* Reset here to make sure all is clean and to define PF 'n' */
  7879. i40e_clear_hw(hw);
  7880. err = i40e_pf_reset(hw);
  7881. if (err) {
  7882. dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
  7883. goto err_pf_reset;
  7884. }
  7885. pf->pfr_count++;
  7886. hw->aq.num_arq_entries = I40E_AQ_LEN;
  7887. hw->aq.num_asq_entries = I40E_AQ_LEN;
  7888. hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  7889. hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  7890. pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
  7891. snprintf(pf->misc_int_name, sizeof(pf->misc_int_name) - 1,
  7892. "%s-pf%d:misc",
  7893. dev_driver_string(&pf->pdev->dev), pf->hw.pf_id);
  7894. err = i40e_init_shared_code(hw);
  7895. if (err) {
  7896. dev_info(&pdev->dev, "init_shared_code failed: %d\n", err);
  7897. goto err_pf_reset;
  7898. }
  7899. /* set up a default setting for link flow control */
  7900. pf->hw.fc.requested_mode = I40E_FC_NONE;
  7901. err = i40e_init_adminq(hw);
  7902. dev_info(&pdev->dev, "%s\n", i40e_fw_version_str(hw));
  7903. if (err) {
  7904. dev_info(&pdev->dev,
  7905. "The driver for the device stopped because the NVM image is newer than expected. You must install the most recent version of the network driver.\n");
  7906. goto err_pf_reset;
  7907. }
  7908. if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
  7909. hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
  7910. dev_info(&pdev->dev,
  7911. "The driver for the device detected a newer version of the NVM image than expected. Please install the most recent version of the network driver.\n");
  7912. else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
  7913. hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1))
  7914. dev_info(&pdev->dev,
  7915. "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
  7916. i40e_verify_eeprom(pf);
  7917. /* Rev 0 hardware was never productized */
  7918. if (hw->revision_id < 1)
  7919. dev_warn(&pdev->dev, "This device is a pre-production adapter/LOM. Please be aware there may be issues with your hardware. If you are experiencing problems please contact your Intel or hardware representative who provided you with this hardware.\n");
  7920. i40e_clear_pxe_mode(hw);
  7921. err = i40e_get_capabilities(pf);
  7922. if (err)
  7923. goto err_adminq_setup;
  7924. err = i40e_sw_init(pf);
  7925. if (err) {
  7926. dev_info(&pdev->dev, "sw_init failed: %d\n", err);
  7927. goto err_sw_init;
  7928. }
  7929. err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  7930. hw->func_caps.num_rx_qp,
  7931. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  7932. if (err) {
  7933. dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
  7934. goto err_init_lan_hmc;
  7935. }
  7936. err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  7937. if (err) {
  7938. dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
  7939. err = -ENOENT;
  7940. goto err_configure_lan_hmc;
  7941. }
  7942. i40e_get_mac_addr(hw, hw->mac.addr);
  7943. if (!is_valid_ether_addr(hw->mac.addr)) {
  7944. dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
  7945. err = -EIO;
  7946. goto err_mac_addr;
  7947. }
  7948. dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
  7949. ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
  7950. i40e_get_port_mac_addr(hw, hw->mac.port_addr);
  7951. if (is_valid_ether_addr(hw->mac.port_addr))
  7952. pf->flags |= I40E_FLAG_PORT_ID_VALID;
  7953. #ifdef I40E_FCOE
  7954. err = i40e_get_san_mac_addr(hw, hw->mac.san_addr);
  7955. if (err)
  7956. dev_info(&pdev->dev,
  7957. "(non-fatal) SAN MAC retrieval failed: %d\n", err);
  7958. if (!is_valid_ether_addr(hw->mac.san_addr)) {
  7959. dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
  7960. hw->mac.san_addr);
  7961. ether_addr_copy(hw->mac.san_addr, hw->mac.addr);
  7962. }
  7963. dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr);
  7964. #endif /* I40E_FCOE */
  7965. pci_set_drvdata(pdev, pf);
  7966. pci_save_state(pdev);
  7967. #ifdef CONFIG_I40E_DCB
  7968. err = i40e_init_pf_dcb(pf);
  7969. if (err) {
  7970. dev_info(&pdev->dev, "init_pf_dcb failed: %d\n", err);
  7971. pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
  7972. /* Continue without DCB enabled */
  7973. }
  7974. #endif /* CONFIG_I40E_DCB */
  7975. /* set up periodic task facility */
  7976. setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
  7977. pf->service_timer_period = HZ;
  7978. INIT_WORK(&pf->service_task, i40e_service_task);
  7979. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  7980. pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
  7981. pf->link_check_timeout = jiffies;
  7982. /* WoL defaults to disabled */
  7983. pf->wol_en = false;
  7984. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  7985. /* set up the main switch operations */
  7986. i40e_determine_queue_usage(pf);
  7987. i40e_init_interrupt_scheme(pf);
  7988. /* The number of VSIs reported by the FW is the minimum guaranteed
  7989. * to us; HW supports far more and we share the remaining pool with
  7990. * the other PFs. We allocate space for more than the guarantee with
  7991. * the understanding that we might not get them all later.
  7992. */
  7993. if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
  7994. pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
  7995. else
  7996. pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
  7997. /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
  7998. len = sizeof(struct i40e_vsi *) * pf->num_alloc_vsi;
  7999. pf->vsi = kzalloc(len, GFP_KERNEL);
  8000. if (!pf->vsi) {
  8001. err = -ENOMEM;
  8002. goto err_switch_setup;
  8003. }
  8004. err = i40e_setup_pf_switch(pf, false);
  8005. if (err) {
  8006. dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
  8007. goto err_vsis;
  8008. }
  8009. /* if FDIR VSI was set up, start it now */
  8010. for (i = 0; i < pf->num_alloc_vsi; i++) {
  8011. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  8012. i40e_vsi_open(pf->vsi[i]);
  8013. break;
  8014. }
  8015. }
  8016. /* The main driver is (mostly) up and happy. We need to set this state
  8017. * before setting up the misc vector or we get a race and the vector
  8018. * ends up disabled forever.
  8019. */
  8020. clear_bit(__I40E_DOWN, &pf->state);
  8021. /* In case of MSIX we are going to setup the misc vector right here
  8022. * to handle admin queue events etc. In case of legacy and MSI
  8023. * the misc functionality and queue processing is combined in
  8024. * the same vector and that gets setup at open.
  8025. */
  8026. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  8027. err = i40e_setup_misc_vector(pf);
  8028. if (err) {
  8029. dev_info(&pdev->dev,
  8030. "setup of misc vector failed: %d\n", err);
  8031. goto err_vsis;
  8032. }
  8033. }
  8034. #ifdef CONFIG_PCI_IOV
  8035. /* prep for VF support */
  8036. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  8037. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  8038. !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  8039. u32 val;
  8040. /* disable link interrupts for VFs */
  8041. val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
  8042. val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
  8043. wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
  8044. i40e_flush(hw);
  8045. if (pci_num_vf(pdev)) {
  8046. dev_info(&pdev->dev,
  8047. "Active VFs found, allocating resources.\n");
  8048. err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
  8049. if (err)
  8050. dev_info(&pdev->dev,
  8051. "Error %d allocating resources for existing VFs\n",
  8052. err);
  8053. }
  8054. }
  8055. #endif /* CONFIG_PCI_IOV */
  8056. pfs_found++;
  8057. i40e_dbg_pf_init(pf);
  8058. /* tell the firmware that we're starting */
  8059. i40e_send_version(pf);
  8060. /* since everything's happy, start the service_task timer */
  8061. mod_timer(&pf->service_timer,
  8062. round_jiffies(jiffies + pf->service_timer_period));
  8063. #ifdef I40E_FCOE
  8064. /* create FCoE interface */
  8065. i40e_fcoe_vsi_setup(pf);
  8066. #endif
  8067. /* Get the negotiated link width and speed from PCI config space */
  8068. pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, &link_status);
  8069. i40e_set_pci_config_data(hw, link_status);
  8070. dev_info(&pdev->dev, "PCI-Express: %s %s\n",
  8071. (hw->bus.speed == i40e_bus_speed_8000 ? "Speed 8.0GT/s" :
  8072. hw->bus.speed == i40e_bus_speed_5000 ? "Speed 5.0GT/s" :
  8073. hw->bus.speed == i40e_bus_speed_2500 ? "Speed 2.5GT/s" :
  8074. "Unknown"),
  8075. (hw->bus.width == i40e_bus_width_pcie_x8 ? "Width x8" :
  8076. hw->bus.width == i40e_bus_width_pcie_x4 ? "Width x4" :
  8077. hw->bus.width == i40e_bus_width_pcie_x2 ? "Width x2" :
  8078. hw->bus.width == i40e_bus_width_pcie_x1 ? "Width x1" :
  8079. "Unknown"));
  8080. if (hw->bus.width < i40e_bus_width_pcie_x8 ||
  8081. hw->bus.speed < i40e_bus_speed_8000) {
  8082. dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
  8083. dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
  8084. }
  8085. /* print a string summarizing features */
  8086. i40e_print_features(pf);
  8087. return 0;
  8088. /* Unwind what we've done if something failed in the setup */
  8089. err_vsis:
  8090. set_bit(__I40E_DOWN, &pf->state);
  8091. i40e_clear_interrupt_scheme(pf);
  8092. kfree(pf->vsi);
  8093. err_switch_setup:
  8094. i40e_reset_interrupt_capability(pf);
  8095. del_timer_sync(&pf->service_timer);
  8096. err_mac_addr:
  8097. err_configure_lan_hmc:
  8098. (void)i40e_shutdown_lan_hmc(hw);
  8099. err_init_lan_hmc:
  8100. kfree(pf->qp_pile);
  8101. kfree(pf->irq_pile);
  8102. err_sw_init:
  8103. err_adminq_setup:
  8104. (void)i40e_shutdown_adminq(hw);
  8105. err_pf_reset:
  8106. iounmap(hw->hw_addr);
  8107. err_ioremap:
  8108. kfree(pf);
  8109. err_pf_alloc:
  8110. pci_disable_pcie_error_reporting(pdev);
  8111. pci_release_selected_regions(pdev,
  8112. pci_select_bars(pdev, IORESOURCE_MEM));
  8113. err_pci_reg:
  8114. err_dma:
  8115. pci_disable_device(pdev);
  8116. return err;
  8117. }
  8118. /**
  8119. * i40e_remove - Device removal routine
  8120. * @pdev: PCI device information struct
  8121. *
  8122. * i40e_remove is called by the PCI subsystem to alert the driver
  8123. * that is should release a PCI device. This could be caused by a
  8124. * Hot-Plug event, or because the driver is going to be removed from
  8125. * memory.
  8126. **/
  8127. static void i40e_remove(struct pci_dev *pdev)
  8128. {
  8129. struct i40e_pf *pf = pci_get_drvdata(pdev);
  8130. i40e_status ret_code;
  8131. int i;
  8132. i40e_dbg_pf_exit(pf);
  8133. i40e_ptp_stop(pf);
  8134. /* no more scheduling of any task */
  8135. set_bit(__I40E_DOWN, &pf->state);
  8136. del_timer_sync(&pf->service_timer);
  8137. cancel_work_sync(&pf->service_task);
  8138. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  8139. i40e_free_vfs(pf);
  8140. pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
  8141. }
  8142. i40e_fdir_teardown(pf);
  8143. /* If there is a switch structure or any orphans, remove them.
  8144. * This will leave only the PF's VSI remaining.
  8145. */
  8146. for (i = 0; i < I40E_MAX_VEB; i++) {
  8147. if (!pf->veb[i])
  8148. continue;
  8149. if (pf->veb[i]->uplink_seid == pf->mac_seid ||
  8150. pf->veb[i]->uplink_seid == 0)
  8151. i40e_switch_branch_release(pf->veb[i]);
  8152. }
  8153. /* Now we can shutdown the PF's VSI, just before we kill
  8154. * adminq and hmc.
  8155. */
  8156. if (pf->vsi[pf->lan_vsi])
  8157. i40e_vsi_release(pf->vsi[pf->lan_vsi]);
  8158. i40e_stop_misc_vector(pf);
  8159. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  8160. synchronize_irq(pf->msix_entries[0].vector);
  8161. free_irq(pf->msix_entries[0].vector, pf);
  8162. }
  8163. /* shutdown and destroy the HMC */
  8164. if (pf->hw.hmc.hmc_obj) {
  8165. ret_code = i40e_shutdown_lan_hmc(&pf->hw);
  8166. if (ret_code)
  8167. dev_warn(&pdev->dev,
  8168. "Failed to destroy the HMC resources: %d\n",
  8169. ret_code);
  8170. }
  8171. /* shutdown the adminq */
  8172. ret_code = i40e_shutdown_adminq(&pf->hw);
  8173. if (ret_code)
  8174. dev_warn(&pdev->dev,
  8175. "Failed to destroy the Admin Queue resources: %d\n",
  8176. ret_code);
  8177. /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
  8178. i40e_clear_interrupt_scheme(pf);
  8179. for (i = 0; i < pf->num_alloc_vsi; i++) {
  8180. if (pf->vsi[i]) {
  8181. i40e_vsi_clear_rings(pf->vsi[i]);
  8182. i40e_vsi_clear(pf->vsi[i]);
  8183. pf->vsi[i] = NULL;
  8184. }
  8185. }
  8186. for (i = 0; i < I40E_MAX_VEB; i++) {
  8187. kfree(pf->veb[i]);
  8188. pf->veb[i] = NULL;
  8189. }
  8190. kfree(pf->qp_pile);
  8191. kfree(pf->irq_pile);
  8192. kfree(pf->vsi);
  8193. iounmap(pf->hw.hw_addr);
  8194. kfree(pf);
  8195. pci_release_selected_regions(pdev,
  8196. pci_select_bars(pdev, IORESOURCE_MEM));
  8197. pci_disable_pcie_error_reporting(pdev);
  8198. pci_disable_device(pdev);
  8199. }
  8200. /**
  8201. * i40e_pci_error_detected - warning that something funky happened in PCI land
  8202. * @pdev: PCI device information struct
  8203. *
  8204. * Called to warn that something happened and the error handling steps
  8205. * are in progress. Allows the driver to quiesce things, be ready for
  8206. * remediation.
  8207. **/
  8208. static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
  8209. enum pci_channel_state error)
  8210. {
  8211. struct i40e_pf *pf = pci_get_drvdata(pdev);
  8212. dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
  8213. /* shutdown all operations */
  8214. if (!test_bit(__I40E_SUSPENDED, &pf->state)) {
  8215. rtnl_lock();
  8216. i40e_prep_for_reset(pf);
  8217. rtnl_unlock();
  8218. }
  8219. /* Request a slot reset */
  8220. return PCI_ERS_RESULT_NEED_RESET;
  8221. }
  8222. /**
  8223. * i40e_pci_error_slot_reset - a PCI slot reset just happened
  8224. * @pdev: PCI device information struct
  8225. *
  8226. * Called to find if the driver can work with the device now that
  8227. * the pci slot has been reset. If a basic connection seems good
  8228. * (registers are readable and have sane content) then return a
  8229. * happy little PCI_ERS_RESULT_xxx.
  8230. **/
  8231. static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
  8232. {
  8233. struct i40e_pf *pf = pci_get_drvdata(pdev);
  8234. pci_ers_result_t result;
  8235. int err;
  8236. u32 reg;
  8237. dev_info(&pdev->dev, "%s\n", __func__);
  8238. if (pci_enable_device_mem(pdev)) {
  8239. dev_info(&pdev->dev,
  8240. "Cannot re-enable PCI device after reset.\n");
  8241. result = PCI_ERS_RESULT_DISCONNECT;
  8242. } else {
  8243. pci_set_master(pdev);
  8244. pci_restore_state(pdev);
  8245. pci_save_state(pdev);
  8246. pci_wake_from_d3(pdev, false);
  8247. reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  8248. if (reg == 0)
  8249. result = PCI_ERS_RESULT_RECOVERED;
  8250. else
  8251. result = PCI_ERS_RESULT_DISCONNECT;
  8252. }
  8253. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  8254. if (err) {
  8255. dev_info(&pdev->dev,
  8256. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
  8257. err);
  8258. /* non-fatal, continue */
  8259. }
  8260. return result;
  8261. }
  8262. /**
  8263. * i40e_pci_error_resume - restart operations after PCI error recovery
  8264. * @pdev: PCI device information struct
  8265. *
  8266. * Called to allow the driver to bring things back up after PCI error
  8267. * and/or reset recovery has finished.
  8268. **/
  8269. static void i40e_pci_error_resume(struct pci_dev *pdev)
  8270. {
  8271. struct i40e_pf *pf = pci_get_drvdata(pdev);
  8272. dev_info(&pdev->dev, "%s\n", __func__);
  8273. if (test_bit(__I40E_SUSPENDED, &pf->state))
  8274. return;
  8275. rtnl_lock();
  8276. i40e_handle_reset_warning(pf);
  8277. rtnl_lock();
  8278. }
  8279. /**
  8280. * i40e_shutdown - PCI callback for shutting down
  8281. * @pdev: PCI device information struct
  8282. **/
  8283. static void i40e_shutdown(struct pci_dev *pdev)
  8284. {
  8285. struct i40e_pf *pf = pci_get_drvdata(pdev);
  8286. struct i40e_hw *hw = &pf->hw;
  8287. set_bit(__I40E_SUSPENDED, &pf->state);
  8288. set_bit(__I40E_DOWN, &pf->state);
  8289. rtnl_lock();
  8290. i40e_prep_for_reset(pf);
  8291. rtnl_unlock();
  8292. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  8293. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  8294. if (system_state == SYSTEM_POWER_OFF) {
  8295. pci_wake_from_d3(pdev, pf->wol_en);
  8296. pci_set_power_state(pdev, PCI_D3hot);
  8297. }
  8298. }
  8299. #ifdef CONFIG_PM
  8300. /**
  8301. * i40e_suspend - PCI callback for moving to D3
  8302. * @pdev: PCI device information struct
  8303. **/
  8304. static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
  8305. {
  8306. struct i40e_pf *pf = pci_get_drvdata(pdev);
  8307. struct i40e_hw *hw = &pf->hw;
  8308. set_bit(__I40E_SUSPENDED, &pf->state);
  8309. set_bit(__I40E_DOWN, &pf->state);
  8310. rtnl_lock();
  8311. i40e_prep_for_reset(pf);
  8312. rtnl_unlock();
  8313. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  8314. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  8315. pci_wake_from_d3(pdev, pf->wol_en);
  8316. pci_set_power_state(pdev, PCI_D3hot);
  8317. return 0;
  8318. }
  8319. /**
  8320. * i40e_resume - PCI callback for waking up from D3
  8321. * @pdev: PCI device information struct
  8322. **/
  8323. static int i40e_resume(struct pci_dev *pdev)
  8324. {
  8325. struct i40e_pf *pf = pci_get_drvdata(pdev);
  8326. u32 err;
  8327. pci_set_power_state(pdev, PCI_D0);
  8328. pci_restore_state(pdev);
  8329. /* pci_restore_state() clears dev->state_saves, so
  8330. * call pci_save_state() again to restore it.
  8331. */
  8332. pci_save_state(pdev);
  8333. err = pci_enable_device_mem(pdev);
  8334. if (err) {
  8335. dev_err(&pdev->dev,
  8336. "%s: Cannot enable PCI device from suspend\n",
  8337. __func__);
  8338. return err;
  8339. }
  8340. pci_set_master(pdev);
  8341. /* no wakeup events while running */
  8342. pci_wake_from_d3(pdev, false);
  8343. /* handling the reset will rebuild the device state */
  8344. if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) {
  8345. clear_bit(__I40E_DOWN, &pf->state);
  8346. rtnl_lock();
  8347. i40e_reset_and_rebuild(pf, false);
  8348. rtnl_unlock();
  8349. }
  8350. return 0;
  8351. }
  8352. #endif
  8353. static const struct pci_error_handlers i40e_err_handler = {
  8354. .error_detected = i40e_pci_error_detected,
  8355. .slot_reset = i40e_pci_error_slot_reset,
  8356. .resume = i40e_pci_error_resume,
  8357. };
  8358. static struct pci_driver i40e_driver = {
  8359. .name = i40e_driver_name,
  8360. .id_table = i40e_pci_tbl,
  8361. .probe = i40e_probe,
  8362. .remove = i40e_remove,
  8363. #ifdef CONFIG_PM
  8364. .suspend = i40e_suspend,
  8365. .resume = i40e_resume,
  8366. #endif
  8367. .shutdown = i40e_shutdown,
  8368. .err_handler = &i40e_err_handler,
  8369. .sriov_configure = i40e_pci_sriov_configure,
  8370. };
  8371. /**
  8372. * i40e_init_module - Driver registration routine
  8373. *
  8374. * i40e_init_module is the first routine called when the driver is
  8375. * loaded. All it does is register with the PCI subsystem.
  8376. **/
  8377. static int __init i40e_init_module(void)
  8378. {
  8379. pr_info("%s: %s - version %s\n", i40e_driver_name,
  8380. i40e_driver_string, i40e_driver_version_str);
  8381. pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
  8382. i40e_dbg_init();
  8383. return pci_register_driver(&i40e_driver);
  8384. }
  8385. module_init(i40e_init_module);
  8386. /**
  8387. * i40e_exit_module - Driver exit cleanup routine
  8388. *
  8389. * i40e_exit_module is called just before the driver is removed
  8390. * from memory.
  8391. **/
  8392. static void __exit i40e_exit_module(void)
  8393. {
  8394. pci_unregister_driver(&i40e_driver);
  8395. i40e_dbg_exit();
  8396. }
  8397. module_exit(i40e_exit_module);