i40e_main.c 394 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2017 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. #include <linux/etherdevice.h>
  27. #include <linux/of_net.h>
  28. #include <linux/pci.h>
  29. #include <linux/bpf.h>
  30. /* Local includes */
  31. #include "i40e.h"
  32. #include "i40e_diag.h"
  33. #include <net/udp_tunnel.h>
  34. /* All i40e tracepoints are defined by the include below, which
  35. * must be included exactly once across the whole kernel with
  36. * CREATE_TRACE_POINTS defined
  37. */
  38. #define CREATE_TRACE_POINTS
  39. #include "i40e_trace.h"
  40. const char i40e_driver_name[] = "i40e";
  41. static const char i40e_driver_string[] =
  42. "Intel(R) Ethernet Connection XL710 Network Driver";
  43. #define DRV_KERN "-k"
  44. #define DRV_VERSION_MAJOR 2
  45. #define DRV_VERSION_MINOR 1
  46. #define DRV_VERSION_BUILD 14
  47. #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
  48. __stringify(DRV_VERSION_MINOR) "." \
  49. __stringify(DRV_VERSION_BUILD) DRV_KERN
  50. const char i40e_driver_version_str[] = DRV_VERSION;
  51. static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
  52. /* a bit of forward declarations */
  53. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
  54. static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired);
  55. static int i40e_add_vsi(struct i40e_vsi *vsi);
  56. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
  57. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
  58. static int i40e_setup_misc_vector(struct i40e_pf *pf);
  59. static void i40e_determine_queue_usage(struct i40e_pf *pf);
  60. static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
  61. static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired);
  62. static int i40e_reset(struct i40e_pf *pf);
  63. static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired);
  64. static void i40e_fdir_sb_setup(struct i40e_pf *pf);
  65. static int i40e_veb_get_bw_info(struct i40e_veb *veb);
  66. static int i40e_add_del_cloud_filter(struct i40e_vsi *vsi,
  67. struct i40e_cloud_filter *filter,
  68. bool add);
  69. static int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi *vsi,
  70. struct i40e_cloud_filter *filter,
  71. bool add);
  72. static int i40e_get_capabilities(struct i40e_pf *pf,
  73. enum i40e_admin_queue_opc list_type);
  74. /* i40e_pci_tbl - PCI Device ID Table
  75. *
  76. * Last entry must be all 0s
  77. *
  78. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  79. * Class, Class Mask, private data (not used) }
  80. */
  81. static const struct pci_device_id i40e_pci_tbl[] = {
  82. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
  83. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
  84. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
  85. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
  86. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
  87. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
  88. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
  89. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0},
  90. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0},
  91. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0},
  92. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0},
  93. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0},
  94. {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0},
  95. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0},
  96. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0},
  97. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
  98. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0},
  99. {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_B), 0},
  100. {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_SFP28), 0},
  101. /* required last entry */
  102. {0, }
  103. };
  104. MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
  105. #define I40E_MAX_VF_COUNT 128
  106. static int debug = -1;
  107. module_param(debug, uint, 0);
  108. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)");
  109. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  110. MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
  111. MODULE_LICENSE("GPL");
  112. MODULE_VERSION(DRV_VERSION);
  113. static struct workqueue_struct *i40e_wq;
  114. /**
  115. * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
  116. * @hw: pointer to the HW structure
  117. * @mem: ptr to mem struct to fill out
  118. * @size: size of memory requested
  119. * @alignment: what to align the allocation to
  120. **/
  121. int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
  122. u64 size, u32 alignment)
  123. {
  124. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  125. mem->size = ALIGN(size, alignment);
  126. mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
  127. &mem->pa, GFP_KERNEL);
  128. if (!mem->va)
  129. return -ENOMEM;
  130. return 0;
  131. }
  132. /**
  133. * i40e_free_dma_mem_d - OS specific memory free for shared code
  134. * @hw: pointer to the HW structure
  135. * @mem: ptr to mem struct to free
  136. **/
  137. int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
  138. {
  139. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  140. dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
  141. mem->va = NULL;
  142. mem->pa = 0;
  143. mem->size = 0;
  144. return 0;
  145. }
  146. /**
  147. * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
  148. * @hw: pointer to the HW structure
  149. * @mem: ptr to mem struct to fill out
  150. * @size: size of memory requested
  151. **/
  152. int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
  153. u32 size)
  154. {
  155. mem->size = size;
  156. mem->va = kzalloc(size, GFP_KERNEL);
  157. if (!mem->va)
  158. return -ENOMEM;
  159. return 0;
  160. }
  161. /**
  162. * i40e_free_virt_mem_d - OS specific memory free for shared code
  163. * @hw: pointer to the HW structure
  164. * @mem: ptr to mem struct to free
  165. **/
  166. int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
  167. {
  168. /* it's ok to kfree a NULL pointer */
  169. kfree(mem->va);
  170. mem->va = NULL;
  171. mem->size = 0;
  172. return 0;
  173. }
  174. /**
  175. * i40e_get_lump - find a lump of free generic resource
  176. * @pf: board private structure
  177. * @pile: the pile of resource to search
  178. * @needed: the number of items needed
  179. * @id: an owner id to stick on the items assigned
  180. *
  181. * Returns the base item index of the lump, or negative for error
  182. *
  183. * The search_hint trick and lack of advanced fit-finding only work
  184. * because we're highly likely to have all the same size lump requests.
  185. * Linear search time and any fragmentation should be minimal.
  186. **/
  187. static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
  188. u16 needed, u16 id)
  189. {
  190. int ret = -ENOMEM;
  191. int i, j;
  192. if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
  193. dev_info(&pf->pdev->dev,
  194. "param err: pile=%p needed=%d id=0x%04x\n",
  195. pile, needed, id);
  196. return -EINVAL;
  197. }
  198. /* start the linear search with an imperfect hint */
  199. i = pile->search_hint;
  200. while (i < pile->num_entries) {
  201. /* skip already allocated entries */
  202. if (pile->list[i] & I40E_PILE_VALID_BIT) {
  203. i++;
  204. continue;
  205. }
  206. /* do we have enough in this lump? */
  207. for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
  208. if (pile->list[i+j] & I40E_PILE_VALID_BIT)
  209. break;
  210. }
  211. if (j == needed) {
  212. /* there was enough, so assign it to the requestor */
  213. for (j = 0; j < needed; j++)
  214. pile->list[i+j] = id | I40E_PILE_VALID_BIT;
  215. ret = i;
  216. pile->search_hint = i + j;
  217. break;
  218. }
  219. /* not enough, so skip over it and continue looking */
  220. i += j;
  221. }
  222. return ret;
  223. }
  224. /**
  225. * i40e_put_lump - return a lump of generic resource
  226. * @pile: the pile of resource to search
  227. * @index: the base item index
  228. * @id: the owner id of the items assigned
  229. *
  230. * Returns the count of items in the lump
  231. **/
  232. static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
  233. {
  234. int valid_id = (id | I40E_PILE_VALID_BIT);
  235. int count = 0;
  236. int i;
  237. if (!pile || index >= pile->num_entries)
  238. return -EINVAL;
  239. for (i = index;
  240. i < pile->num_entries && pile->list[i] == valid_id;
  241. i++) {
  242. pile->list[i] = 0;
  243. count++;
  244. }
  245. if (count && index < pile->search_hint)
  246. pile->search_hint = index;
  247. return count;
  248. }
  249. /**
  250. * i40e_find_vsi_from_id - searches for the vsi with the given id
  251. * @pf - the pf structure to search for the vsi
  252. * @id - id of the vsi it is searching for
  253. **/
  254. struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
  255. {
  256. int i;
  257. for (i = 0; i < pf->num_alloc_vsi; i++)
  258. if (pf->vsi[i] && (pf->vsi[i]->id == id))
  259. return pf->vsi[i];
  260. return NULL;
  261. }
  262. /**
  263. * i40e_service_event_schedule - Schedule the service task to wake up
  264. * @pf: board private structure
  265. *
  266. * If not already scheduled, this puts the task into the work queue
  267. **/
  268. void i40e_service_event_schedule(struct i40e_pf *pf)
  269. {
  270. if (!test_bit(__I40E_DOWN, pf->state) &&
  271. !test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  272. queue_work(i40e_wq, &pf->service_task);
  273. }
  274. /**
  275. * i40e_tx_timeout - Respond to a Tx Hang
  276. * @netdev: network interface device structure
  277. *
  278. * If any port has noticed a Tx timeout, it is likely that the whole
  279. * device is munged, not just the one netdev port, so go for the full
  280. * reset.
  281. **/
  282. static void i40e_tx_timeout(struct net_device *netdev)
  283. {
  284. struct i40e_netdev_priv *np = netdev_priv(netdev);
  285. struct i40e_vsi *vsi = np->vsi;
  286. struct i40e_pf *pf = vsi->back;
  287. struct i40e_ring *tx_ring = NULL;
  288. unsigned int i, hung_queue = 0;
  289. u32 head, val;
  290. pf->tx_timeout_count++;
  291. /* find the stopped queue the same way the stack does */
  292. for (i = 0; i < netdev->num_tx_queues; i++) {
  293. struct netdev_queue *q;
  294. unsigned long trans_start;
  295. q = netdev_get_tx_queue(netdev, i);
  296. trans_start = q->trans_start;
  297. if (netif_xmit_stopped(q) &&
  298. time_after(jiffies,
  299. (trans_start + netdev->watchdog_timeo))) {
  300. hung_queue = i;
  301. break;
  302. }
  303. }
  304. if (i == netdev->num_tx_queues) {
  305. netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
  306. } else {
  307. /* now that we have an index, find the tx_ring struct */
  308. for (i = 0; i < vsi->num_queue_pairs; i++) {
  309. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
  310. if (hung_queue ==
  311. vsi->tx_rings[i]->queue_index) {
  312. tx_ring = vsi->tx_rings[i];
  313. break;
  314. }
  315. }
  316. }
  317. }
  318. if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
  319. pf->tx_timeout_recovery_level = 1; /* reset after some time */
  320. else if (time_before(jiffies,
  321. (pf->tx_timeout_last_recovery + netdev->watchdog_timeo)))
  322. return; /* don't do any new action before the next timeout */
  323. if (tx_ring) {
  324. head = i40e_get_head(tx_ring);
  325. /* Read interrupt register */
  326. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  327. val = rd32(&pf->hw,
  328. I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
  329. tx_ring->vsi->base_vector - 1));
  330. else
  331. val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
  332. netdev_info(netdev, "tx_timeout: VSI_seid: %d, Q %d, NTC: 0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x, INT: 0x%x\n",
  333. vsi->seid, hung_queue, tx_ring->next_to_clean,
  334. head, tx_ring->next_to_use,
  335. readl(tx_ring->tail), val);
  336. }
  337. pf->tx_timeout_last_recovery = jiffies;
  338. netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
  339. pf->tx_timeout_recovery_level, hung_queue);
  340. switch (pf->tx_timeout_recovery_level) {
  341. case 1:
  342. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  343. break;
  344. case 2:
  345. set_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
  346. break;
  347. case 3:
  348. set_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state);
  349. break;
  350. default:
  351. netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
  352. break;
  353. }
  354. i40e_service_event_schedule(pf);
  355. pf->tx_timeout_recovery_level++;
  356. }
  357. /**
  358. * i40e_get_vsi_stats_struct - Get System Network Statistics
  359. * @vsi: the VSI we care about
  360. *
  361. * Returns the address of the device statistics structure.
  362. * The statistics are actually updated from the service task.
  363. **/
  364. struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
  365. {
  366. return &vsi->net_stats;
  367. }
  368. /**
  369. * i40e_get_netdev_stats_struct_tx - populate stats from a Tx ring
  370. * @ring: Tx ring to get statistics from
  371. * @stats: statistics entry to be updated
  372. **/
  373. static void i40e_get_netdev_stats_struct_tx(struct i40e_ring *ring,
  374. struct rtnl_link_stats64 *stats)
  375. {
  376. u64 bytes, packets;
  377. unsigned int start;
  378. do {
  379. start = u64_stats_fetch_begin_irq(&ring->syncp);
  380. packets = ring->stats.packets;
  381. bytes = ring->stats.bytes;
  382. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  383. stats->tx_packets += packets;
  384. stats->tx_bytes += bytes;
  385. }
  386. /**
  387. * i40e_get_netdev_stats_struct - Get statistics for netdev interface
  388. * @netdev: network interface device structure
  389. *
  390. * Returns the address of the device statistics structure.
  391. * The statistics are actually updated from the service task.
  392. **/
  393. static void i40e_get_netdev_stats_struct(struct net_device *netdev,
  394. struct rtnl_link_stats64 *stats)
  395. {
  396. struct i40e_netdev_priv *np = netdev_priv(netdev);
  397. struct i40e_ring *tx_ring, *rx_ring;
  398. struct i40e_vsi *vsi = np->vsi;
  399. struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
  400. int i;
  401. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  402. return;
  403. if (!vsi->tx_rings)
  404. return;
  405. rcu_read_lock();
  406. for (i = 0; i < vsi->num_queue_pairs; i++) {
  407. u64 bytes, packets;
  408. unsigned int start;
  409. tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
  410. if (!tx_ring)
  411. continue;
  412. i40e_get_netdev_stats_struct_tx(tx_ring, stats);
  413. rx_ring = &tx_ring[1];
  414. do {
  415. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  416. packets = rx_ring->stats.packets;
  417. bytes = rx_ring->stats.bytes;
  418. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  419. stats->rx_packets += packets;
  420. stats->rx_bytes += bytes;
  421. if (i40e_enabled_xdp_vsi(vsi))
  422. i40e_get_netdev_stats_struct_tx(&rx_ring[1], stats);
  423. }
  424. rcu_read_unlock();
  425. /* following stats updated by i40e_watchdog_subtask() */
  426. stats->multicast = vsi_stats->multicast;
  427. stats->tx_errors = vsi_stats->tx_errors;
  428. stats->tx_dropped = vsi_stats->tx_dropped;
  429. stats->rx_errors = vsi_stats->rx_errors;
  430. stats->rx_dropped = vsi_stats->rx_dropped;
  431. stats->rx_crc_errors = vsi_stats->rx_crc_errors;
  432. stats->rx_length_errors = vsi_stats->rx_length_errors;
  433. }
  434. /**
  435. * i40e_vsi_reset_stats - Resets all stats of the given vsi
  436. * @vsi: the VSI to have its stats reset
  437. **/
  438. void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
  439. {
  440. struct rtnl_link_stats64 *ns;
  441. int i;
  442. if (!vsi)
  443. return;
  444. ns = i40e_get_vsi_stats_struct(vsi);
  445. memset(ns, 0, sizeof(*ns));
  446. memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
  447. memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
  448. memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
  449. if (vsi->rx_rings && vsi->rx_rings[0]) {
  450. for (i = 0; i < vsi->num_queue_pairs; i++) {
  451. memset(&vsi->rx_rings[i]->stats, 0,
  452. sizeof(vsi->rx_rings[i]->stats));
  453. memset(&vsi->rx_rings[i]->rx_stats, 0,
  454. sizeof(vsi->rx_rings[i]->rx_stats));
  455. memset(&vsi->tx_rings[i]->stats, 0,
  456. sizeof(vsi->tx_rings[i]->stats));
  457. memset(&vsi->tx_rings[i]->tx_stats, 0,
  458. sizeof(vsi->tx_rings[i]->tx_stats));
  459. }
  460. }
  461. vsi->stat_offsets_loaded = false;
  462. }
  463. /**
  464. * i40e_pf_reset_stats - Reset all of the stats for the given PF
  465. * @pf: the PF to be reset
  466. **/
  467. void i40e_pf_reset_stats(struct i40e_pf *pf)
  468. {
  469. int i;
  470. memset(&pf->stats, 0, sizeof(pf->stats));
  471. memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
  472. pf->stat_offsets_loaded = false;
  473. for (i = 0; i < I40E_MAX_VEB; i++) {
  474. if (pf->veb[i]) {
  475. memset(&pf->veb[i]->stats, 0,
  476. sizeof(pf->veb[i]->stats));
  477. memset(&pf->veb[i]->stats_offsets, 0,
  478. sizeof(pf->veb[i]->stats_offsets));
  479. pf->veb[i]->stat_offsets_loaded = false;
  480. }
  481. }
  482. pf->hw_csum_rx_error = 0;
  483. }
  484. /**
  485. * i40e_stat_update48 - read and update a 48 bit stat from the chip
  486. * @hw: ptr to the hardware info
  487. * @hireg: the high 32 bit reg to read
  488. * @loreg: the low 32 bit reg to read
  489. * @offset_loaded: has the initial offset been loaded yet
  490. * @offset: ptr to current offset value
  491. * @stat: ptr to the stat
  492. *
  493. * Since the device stats are not reset at PFReset, they likely will not
  494. * be zeroed when the driver starts. We'll save the first values read
  495. * and use them as offsets to be subtracted from the raw values in order
  496. * to report stats that count from zero. In the process, we also manage
  497. * the potential roll-over.
  498. **/
  499. static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
  500. bool offset_loaded, u64 *offset, u64 *stat)
  501. {
  502. u64 new_data;
  503. if (hw->device_id == I40E_DEV_ID_QEMU) {
  504. new_data = rd32(hw, loreg);
  505. new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
  506. } else {
  507. new_data = rd64(hw, loreg);
  508. }
  509. if (!offset_loaded)
  510. *offset = new_data;
  511. if (likely(new_data >= *offset))
  512. *stat = new_data - *offset;
  513. else
  514. *stat = (new_data + BIT_ULL(48)) - *offset;
  515. *stat &= 0xFFFFFFFFFFFFULL;
  516. }
  517. /**
  518. * i40e_stat_update32 - read and update a 32 bit stat from the chip
  519. * @hw: ptr to the hardware info
  520. * @reg: the hw reg to read
  521. * @offset_loaded: has the initial offset been loaded yet
  522. * @offset: ptr to current offset value
  523. * @stat: ptr to the stat
  524. **/
  525. static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
  526. bool offset_loaded, u64 *offset, u64 *stat)
  527. {
  528. u32 new_data;
  529. new_data = rd32(hw, reg);
  530. if (!offset_loaded)
  531. *offset = new_data;
  532. if (likely(new_data >= *offset))
  533. *stat = (u32)(new_data - *offset);
  534. else
  535. *stat = (u32)((new_data + BIT_ULL(32)) - *offset);
  536. }
  537. /**
  538. * i40e_stat_update_and_clear32 - read and clear hw reg, update a 32 bit stat
  539. * @hw: ptr to the hardware info
  540. * @reg: the hw reg to read and clear
  541. * @stat: ptr to the stat
  542. **/
  543. static void i40e_stat_update_and_clear32(struct i40e_hw *hw, u32 reg, u64 *stat)
  544. {
  545. u32 new_data = rd32(hw, reg);
  546. wr32(hw, reg, 1); /* must write a nonzero value to clear register */
  547. *stat += new_data;
  548. }
  549. /**
  550. * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
  551. * @vsi: the VSI to be updated
  552. **/
  553. void i40e_update_eth_stats(struct i40e_vsi *vsi)
  554. {
  555. int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
  556. struct i40e_pf *pf = vsi->back;
  557. struct i40e_hw *hw = &pf->hw;
  558. struct i40e_eth_stats *oes;
  559. struct i40e_eth_stats *es; /* device's eth stats */
  560. es = &vsi->eth_stats;
  561. oes = &vsi->eth_stats_offsets;
  562. /* Gather up the stats that the hw collects */
  563. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  564. vsi->stat_offsets_loaded,
  565. &oes->tx_errors, &es->tx_errors);
  566. i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
  567. vsi->stat_offsets_loaded,
  568. &oes->rx_discards, &es->rx_discards);
  569. i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
  570. vsi->stat_offsets_loaded,
  571. &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
  572. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  573. vsi->stat_offsets_loaded,
  574. &oes->tx_errors, &es->tx_errors);
  575. i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
  576. I40E_GLV_GORCL(stat_idx),
  577. vsi->stat_offsets_loaded,
  578. &oes->rx_bytes, &es->rx_bytes);
  579. i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
  580. I40E_GLV_UPRCL(stat_idx),
  581. vsi->stat_offsets_loaded,
  582. &oes->rx_unicast, &es->rx_unicast);
  583. i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
  584. I40E_GLV_MPRCL(stat_idx),
  585. vsi->stat_offsets_loaded,
  586. &oes->rx_multicast, &es->rx_multicast);
  587. i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
  588. I40E_GLV_BPRCL(stat_idx),
  589. vsi->stat_offsets_loaded,
  590. &oes->rx_broadcast, &es->rx_broadcast);
  591. i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
  592. I40E_GLV_GOTCL(stat_idx),
  593. vsi->stat_offsets_loaded,
  594. &oes->tx_bytes, &es->tx_bytes);
  595. i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
  596. I40E_GLV_UPTCL(stat_idx),
  597. vsi->stat_offsets_loaded,
  598. &oes->tx_unicast, &es->tx_unicast);
  599. i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
  600. I40E_GLV_MPTCL(stat_idx),
  601. vsi->stat_offsets_loaded,
  602. &oes->tx_multicast, &es->tx_multicast);
  603. i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
  604. I40E_GLV_BPTCL(stat_idx),
  605. vsi->stat_offsets_loaded,
  606. &oes->tx_broadcast, &es->tx_broadcast);
  607. vsi->stat_offsets_loaded = true;
  608. }
  609. /**
  610. * i40e_update_veb_stats - Update Switch component statistics
  611. * @veb: the VEB being updated
  612. **/
  613. static void i40e_update_veb_stats(struct i40e_veb *veb)
  614. {
  615. struct i40e_pf *pf = veb->pf;
  616. struct i40e_hw *hw = &pf->hw;
  617. struct i40e_eth_stats *oes;
  618. struct i40e_eth_stats *es; /* device's eth stats */
  619. struct i40e_veb_tc_stats *veb_oes;
  620. struct i40e_veb_tc_stats *veb_es;
  621. int i, idx = 0;
  622. idx = veb->stats_idx;
  623. es = &veb->stats;
  624. oes = &veb->stats_offsets;
  625. veb_es = &veb->tc_stats;
  626. veb_oes = &veb->tc_stats_offsets;
  627. /* Gather up the stats that the hw collects */
  628. i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
  629. veb->stat_offsets_loaded,
  630. &oes->tx_discards, &es->tx_discards);
  631. if (hw->revision_id > 0)
  632. i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
  633. veb->stat_offsets_loaded,
  634. &oes->rx_unknown_protocol,
  635. &es->rx_unknown_protocol);
  636. i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
  637. veb->stat_offsets_loaded,
  638. &oes->rx_bytes, &es->rx_bytes);
  639. i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
  640. veb->stat_offsets_loaded,
  641. &oes->rx_unicast, &es->rx_unicast);
  642. i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
  643. veb->stat_offsets_loaded,
  644. &oes->rx_multicast, &es->rx_multicast);
  645. i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
  646. veb->stat_offsets_loaded,
  647. &oes->rx_broadcast, &es->rx_broadcast);
  648. i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
  649. veb->stat_offsets_loaded,
  650. &oes->tx_bytes, &es->tx_bytes);
  651. i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
  652. veb->stat_offsets_loaded,
  653. &oes->tx_unicast, &es->tx_unicast);
  654. i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
  655. veb->stat_offsets_loaded,
  656. &oes->tx_multicast, &es->tx_multicast);
  657. i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
  658. veb->stat_offsets_loaded,
  659. &oes->tx_broadcast, &es->tx_broadcast);
  660. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  661. i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx),
  662. I40E_GLVEBTC_RPCL(i, idx),
  663. veb->stat_offsets_loaded,
  664. &veb_oes->tc_rx_packets[i],
  665. &veb_es->tc_rx_packets[i]);
  666. i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx),
  667. I40E_GLVEBTC_RBCL(i, idx),
  668. veb->stat_offsets_loaded,
  669. &veb_oes->tc_rx_bytes[i],
  670. &veb_es->tc_rx_bytes[i]);
  671. i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx),
  672. I40E_GLVEBTC_TPCL(i, idx),
  673. veb->stat_offsets_loaded,
  674. &veb_oes->tc_tx_packets[i],
  675. &veb_es->tc_tx_packets[i]);
  676. i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx),
  677. I40E_GLVEBTC_TBCL(i, idx),
  678. veb->stat_offsets_loaded,
  679. &veb_oes->tc_tx_bytes[i],
  680. &veb_es->tc_tx_bytes[i]);
  681. }
  682. veb->stat_offsets_loaded = true;
  683. }
  684. /**
  685. * i40e_update_vsi_stats - Update the vsi statistics counters.
  686. * @vsi: the VSI to be updated
  687. *
  688. * There are a few instances where we store the same stat in a
  689. * couple of different structs. This is partly because we have
  690. * the netdev stats that need to be filled out, which is slightly
  691. * different from the "eth_stats" defined by the chip and used in
  692. * VF communications. We sort it out here.
  693. **/
  694. static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
  695. {
  696. struct i40e_pf *pf = vsi->back;
  697. struct rtnl_link_stats64 *ons;
  698. struct rtnl_link_stats64 *ns; /* netdev stats */
  699. struct i40e_eth_stats *oes;
  700. struct i40e_eth_stats *es; /* device's eth stats */
  701. u32 tx_restart, tx_busy;
  702. struct i40e_ring *p;
  703. u32 rx_page, rx_buf;
  704. u64 bytes, packets;
  705. unsigned int start;
  706. u64 tx_linearize;
  707. u64 tx_force_wb;
  708. u64 rx_p, rx_b;
  709. u64 tx_p, tx_b;
  710. u16 q;
  711. if (test_bit(__I40E_VSI_DOWN, vsi->state) ||
  712. test_bit(__I40E_CONFIG_BUSY, pf->state))
  713. return;
  714. ns = i40e_get_vsi_stats_struct(vsi);
  715. ons = &vsi->net_stats_offsets;
  716. es = &vsi->eth_stats;
  717. oes = &vsi->eth_stats_offsets;
  718. /* Gather up the netdev and vsi stats that the driver collects
  719. * on the fly during packet processing
  720. */
  721. rx_b = rx_p = 0;
  722. tx_b = tx_p = 0;
  723. tx_restart = tx_busy = tx_linearize = tx_force_wb = 0;
  724. rx_page = 0;
  725. rx_buf = 0;
  726. rcu_read_lock();
  727. for (q = 0; q < vsi->num_queue_pairs; q++) {
  728. /* locate Tx ring */
  729. p = ACCESS_ONCE(vsi->tx_rings[q]);
  730. do {
  731. start = u64_stats_fetch_begin_irq(&p->syncp);
  732. packets = p->stats.packets;
  733. bytes = p->stats.bytes;
  734. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  735. tx_b += bytes;
  736. tx_p += packets;
  737. tx_restart += p->tx_stats.restart_queue;
  738. tx_busy += p->tx_stats.tx_busy;
  739. tx_linearize += p->tx_stats.tx_linearize;
  740. tx_force_wb += p->tx_stats.tx_force_wb;
  741. /* Rx queue is part of the same block as Tx queue */
  742. p = &p[1];
  743. do {
  744. start = u64_stats_fetch_begin_irq(&p->syncp);
  745. packets = p->stats.packets;
  746. bytes = p->stats.bytes;
  747. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  748. rx_b += bytes;
  749. rx_p += packets;
  750. rx_buf += p->rx_stats.alloc_buff_failed;
  751. rx_page += p->rx_stats.alloc_page_failed;
  752. }
  753. rcu_read_unlock();
  754. vsi->tx_restart = tx_restart;
  755. vsi->tx_busy = tx_busy;
  756. vsi->tx_linearize = tx_linearize;
  757. vsi->tx_force_wb = tx_force_wb;
  758. vsi->rx_page_failed = rx_page;
  759. vsi->rx_buf_failed = rx_buf;
  760. ns->rx_packets = rx_p;
  761. ns->rx_bytes = rx_b;
  762. ns->tx_packets = tx_p;
  763. ns->tx_bytes = tx_b;
  764. /* update netdev stats from eth stats */
  765. i40e_update_eth_stats(vsi);
  766. ons->tx_errors = oes->tx_errors;
  767. ns->tx_errors = es->tx_errors;
  768. ons->multicast = oes->rx_multicast;
  769. ns->multicast = es->rx_multicast;
  770. ons->rx_dropped = oes->rx_discards;
  771. ns->rx_dropped = es->rx_discards;
  772. ons->tx_dropped = oes->tx_discards;
  773. ns->tx_dropped = es->tx_discards;
  774. /* pull in a couple PF stats if this is the main vsi */
  775. if (vsi == pf->vsi[pf->lan_vsi]) {
  776. ns->rx_crc_errors = pf->stats.crc_errors;
  777. ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
  778. ns->rx_length_errors = pf->stats.rx_length_errors;
  779. }
  780. }
  781. /**
  782. * i40e_update_pf_stats - Update the PF statistics counters.
  783. * @pf: the PF to be updated
  784. **/
  785. static void i40e_update_pf_stats(struct i40e_pf *pf)
  786. {
  787. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  788. struct i40e_hw_port_stats *nsd = &pf->stats;
  789. struct i40e_hw *hw = &pf->hw;
  790. u32 val;
  791. int i;
  792. i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
  793. I40E_GLPRT_GORCL(hw->port),
  794. pf->stat_offsets_loaded,
  795. &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
  796. i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
  797. I40E_GLPRT_GOTCL(hw->port),
  798. pf->stat_offsets_loaded,
  799. &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
  800. i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
  801. pf->stat_offsets_loaded,
  802. &osd->eth.rx_discards,
  803. &nsd->eth.rx_discards);
  804. i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
  805. I40E_GLPRT_UPRCL(hw->port),
  806. pf->stat_offsets_loaded,
  807. &osd->eth.rx_unicast,
  808. &nsd->eth.rx_unicast);
  809. i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
  810. I40E_GLPRT_MPRCL(hw->port),
  811. pf->stat_offsets_loaded,
  812. &osd->eth.rx_multicast,
  813. &nsd->eth.rx_multicast);
  814. i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
  815. I40E_GLPRT_BPRCL(hw->port),
  816. pf->stat_offsets_loaded,
  817. &osd->eth.rx_broadcast,
  818. &nsd->eth.rx_broadcast);
  819. i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
  820. I40E_GLPRT_UPTCL(hw->port),
  821. pf->stat_offsets_loaded,
  822. &osd->eth.tx_unicast,
  823. &nsd->eth.tx_unicast);
  824. i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
  825. I40E_GLPRT_MPTCL(hw->port),
  826. pf->stat_offsets_loaded,
  827. &osd->eth.tx_multicast,
  828. &nsd->eth.tx_multicast);
  829. i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
  830. I40E_GLPRT_BPTCL(hw->port),
  831. pf->stat_offsets_loaded,
  832. &osd->eth.tx_broadcast,
  833. &nsd->eth.tx_broadcast);
  834. i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
  835. pf->stat_offsets_loaded,
  836. &osd->tx_dropped_link_down,
  837. &nsd->tx_dropped_link_down);
  838. i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
  839. pf->stat_offsets_loaded,
  840. &osd->crc_errors, &nsd->crc_errors);
  841. i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
  842. pf->stat_offsets_loaded,
  843. &osd->illegal_bytes, &nsd->illegal_bytes);
  844. i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
  845. pf->stat_offsets_loaded,
  846. &osd->mac_local_faults,
  847. &nsd->mac_local_faults);
  848. i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
  849. pf->stat_offsets_loaded,
  850. &osd->mac_remote_faults,
  851. &nsd->mac_remote_faults);
  852. i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
  853. pf->stat_offsets_loaded,
  854. &osd->rx_length_errors,
  855. &nsd->rx_length_errors);
  856. i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
  857. pf->stat_offsets_loaded,
  858. &osd->link_xon_rx, &nsd->link_xon_rx);
  859. i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
  860. pf->stat_offsets_loaded,
  861. &osd->link_xon_tx, &nsd->link_xon_tx);
  862. i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
  863. pf->stat_offsets_loaded,
  864. &osd->link_xoff_rx, &nsd->link_xoff_rx);
  865. i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
  866. pf->stat_offsets_loaded,
  867. &osd->link_xoff_tx, &nsd->link_xoff_tx);
  868. for (i = 0; i < 8; i++) {
  869. i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
  870. pf->stat_offsets_loaded,
  871. &osd->priority_xoff_rx[i],
  872. &nsd->priority_xoff_rx[i]);
  873. i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
  874. pf->stat_offsets_loaded,
  875. &osd->priority_xon_rx[i],
  876. &nsd->priority_xon_rx[i]);
  877. i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
  878. pf->stat_offsets_loaded,
  879. &osd->priority_xon_tx[i],
  880. &nsd->priority_xon_tx[i]);
  881. i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
  882. pf->stat_offsets_loaded,
  883. &osd->priority_xoff_tx[i],
  884. &nsd->priority_xoff_tx[i]);
  885. i40e_stat_update32(hw,
  886. I40E_GLPRT_RXON2OFFCNT(hw->port, i),
  887. pf->stat_offsets_loaded,
  888. &osd->priority_xon_2_xoff[i],
  889. &nsd->priority_xon_2_xoff[i]);
  890. }
  891. i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
  892. I40E_GLPRT_PRC64L(hw->port),
  893. pf->stat_offsets_loaded,
  894. &osd->rx_size_64, &nsd->rx_size_64);
  895. i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
  896. I40E_GLPRT_PRC127L(hw->port),
  897. pf->stat_offsets_loaded,
  898. &osd->rx_size_127, &nsd->rx_size_127);
  899. i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
  900. I40E_GLPRT_PRC255L(hw->port),
  901. pf->stat_offsets_loaded,
  902. &osd->rx_size_255, &nsd->rx_size_255);
  903. i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
  904. I40E_GLPRT_PRC511L(hw->port),
  905. pf->stat_offsets_loaded,
  906. &osd->rx_size_511, &nsd->rx_size_511);
  907. i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
  908. I40E_GLPRT_PRC1023L(hw->port),
  909. pf->stat_offsets_loaded,
  910. &osd->rx_size_1023, &nsd->rx_size_1023);
  911. i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
  912. I40E_GLPRT_PRC1522L(hw->port),
  913. pf->stat_offsets_loaded,
  914. &osd->rx_size_1522, &nsd->rx_size_1522);
  915. i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
  916. I40E_GLPRT_PRC9522L(hw->port),
  917. pf->stat_offsets_loaded,
  918. &osd->rx_size_big, &nsd->rx_size_big);
  919. i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
  920. I40E_GLPRT_PTC64L(hw->port),
  921. pf->stat_offsets_loaded,
  922. &osd->tx_size_64, &nsd->tx_size_64);
  923. i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
  924. I40E_GLPRT_PTC127L(hw->port),
  925. pf->stat_offsets_loaded,
  926. &osd->tx_size_127, &nsd->tx_size_127);
  927. i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
  928. I40E_GLPRT_PTC255L(hw->port),
  929. pf->stat_offsets_loaded,
  930. &osd->tx_size_255, &nsd->tx_size_255);
  931. i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
  932. I40E_GLPRT_PTC511L(hw->port),
  933. pf->stat_offsets_loaded,
  934. &osd->tx_size_511, &nsd->tx_size_511);
  935. i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
  936. I40E_GLPRT_PTC1023L(hw->port),
  937. pf->stat_offsets_loaded,
  938. &osd->tx_size_1023, &nsd->tx_size_1023);
  939. i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
  940. I40E_GLPRT_PTC1522L(hw->port),
  941. pf->stat_offsets_loaded,
  942. &osd->tx_size_1522, &nsd->tx_size_1522);
  943. i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
  944. I40E_GLPRT_PTC9522L(hw->port),
  945. pf->stat_offsets_loaded,
  946. &osd->tx_size_big, &nsd->tx_size_big);
  947. i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
  948. pf->stat_offsets_loaded,
  949. &osd->rx_undersize, &nsd->rx_undersize);
  950. i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
  951. pf->stat_offsets_loaded,
  952. &osd->rx_fragments, &nsd->rx_fragments);
  953. i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
  954. pf->stat_offsets_loaded,
  955. &osd->rx_oversize, &nsd->rx_oversize);
  956. i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
  957. pf->stat_offsets_loaded,
  958. &osd->rx_jabber, &nsd->rx_jabber);
  959. /* FDIR stats */
  960. i40e_stat_update_and_clear32(hw,
  961. I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(hw->pf_id)),
  962. &nsd->fd_atr_match);
  963. i40e_stat_update_and_clear32(hw,
  964. I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(hw->pf_id)),
  965. &nsd->fd_sb_match);
  966. i40e_stat_update_and_clear32(hw,
  967. I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(hw->pf_id)),
  968. &nsd->fd_atr_tunnel_match);
  969. val = rd32(hw, I40E_PRTPM_EEE_STAT);
  970. nsd->tx_lpi_status =
  971. (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
  972. I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
  973. nsd->rx_lpi_status =
  974. (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
  975. I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
  976. i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
  977. pf->stat_offsets_loaded,
  978. &osd->tx_lpi_count, &nsd->tx_lpi_count);
  979. i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
  980. pf->stat_offsets_loaded,
  981. &osd->rx_lpi_count, &nsd->rx_lpi_count);
  982. if (pf->flags & I40E_FLAG_FD_SB_ENABLED &&
  983. !(pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED))
  984. nsd->fd_sb_status = true;
  985. else
  986. nsd->fd_sb_status = false;
  987. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED &&
  988. !(pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED))
  989. nsd->fd_atr_status = true;
  990. else
  991. nsd->fd_atr_status = false;
  992. pf->stat_offsets_loaded = true;
  993. }
  994. /**
  995. * i40e_update_stats - Update the various statistics counters.
  996. * @vsi: the VSI to be updated
  997. *
  998. * Update the various stats for this VSI and its related entities.
  999. **/
  1000. void i40e_update_stats(struct i40e_vsi *vsi)
  1001. {
  1002. struct i40e_pf *pf = vsi->back;
  1003. if (vsi == pf->vsi[pf->lan_vsi])
  1004. i40e_update_pf_stats(pf);
  1005. i40e_update_vsi_stats(vsi);
  1006. }
  1007. /**
  1008. * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
  1009. * @vsi: the VSI to be searched
  1010. * @macaddr: the MAC address
  1011. * @vlan: the vlan
  1012. *
  1013. * Returns ptr to the filter object or NULL
  1014. **/
  1015. static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
  1016. const u8 *macaddr, s16 vlan)
  1017. {
  1018. struct i40e_mac_filter *f;
  1019. u64 key;
  1020. if (!vsi || !macaddr)
  1021. return NULL;
  1022. key = i40e_addr_to_hkey(macaddr);
  1023. hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
  1024. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  1025. (vlan == f->vlan))
  1026. return f;
  1027. }
  1028. return NULL;
  1029. }
  1030. /**
  1031. * i40e_find_mac - Find a mac addr in the macvlan filters list
  1032. * @vsi: the VSI to be searched
  1033. * @macaddr: the MAC address we are searching for
  1034. *
  1035. * Returns the first filter with the provided MAC address or NULL if
  1036. * MAC address was not found
  1037. **/
  1038. struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr)
  1039. {
  1040. struct i40e_mac_filter *f;
  1041. u64 key;
  1042. if (!vsi || !macaddr)
  1043. return NULL;
  1044. key = i40e_addr_to_hkey(macaddr);
  1045. hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
  1046. if ((ether_addr_equal(macaddr, f->macaddr)))
  1047. return f;
  1048. }
  1049. return NULL;
  1050. }
  1051. /**
  1052. * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
  1053. * @vsi: the VSI to be searched
  1054. *
  1055. * Returns true if VSI is in vlan mode or false otherwise
  1056. **/
  1057. bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
  1058. {
  1059. /* If we have a PVID, always operate in VLAN mode */
  1060. if (vsi->info.pvid)
  1061. return true;
  1062. /* We need to operate in VLAN mode whenever we have any filters with
  1063. * a VLAN other than I40E_VLAN_ALL. We could check the table each
  1064. * time, incurring search cost repeatedly. However, we can notice two
  1065. * things:
  1066. *
  1067. * 1) the only place where we can gain a VLAN filter is in
  1068. * i40e_add_filter.
  1069. *
  1070. * 2) the only place where filters are actually removed is in
  1071. * i40e_sync_filters_subtask.
  1072. *
  1073. * Thus, we can simply use a boolean value, has_vlan_filters which we
  1074. * will set to true when we add a VLAN filter in i40e_add_filter. Then
  1075. * we have to perform the full search after deleting filters in
  1076. * i40e_sync_filters_subtask, but we already have to search
  1077. * filters here and can perform the check at the same time. This
  1078. * results in avoiding embedding a loop for VLAN mode inside another
  1079. * loop over all the filters, and should maintain correctness as noted
  1080. * above.
  1081. */
  1082. return vsi->has_vlan_filter;
  1083. }
  1084. /**
  1085. * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary
  1086. * @vsi: the VSI to configure
  1087. * @tmp_add_list: list of filters ready to be added
  1088. * @tmp_del_list: list of filters ready to be deleted
  1089. * @vlan_filters: the number of active VLAN filters
  1090. *
  1091. * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they
  1092. * behave as expected. If we have any active VLAN filters remaining or about
  1093. * to be added then we need to update non-VLAN filters to be marked as VLAN=0
  1094. * so that they only match against untagged traffic. If we no longer have any
  1095. * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1
  1096. * so that they match against both tagged and untagged traffic. In this way,
  1097. * we ensure that we correctly receive the desired traffic. This ensures that
  1098. * when we have an active VLAN we will receive only untagged traffic and
  1099. * traffic matching active VLANs. If we have no active VLANs then we will
  1100. * operate in non-VLAN mode and receive all traffic, tagged or untagged.
  1101. *
  1102. * Finally, in a similar fashion, this function also corrects filters when
  1103. * there is an active PVID assigned to this VSI.
  1104. *
  1105. * In case of memory allocation failure return -ENOMEM. Otherwise, return 0.
  1106. *
  1107. * This function is only expected to be called from within
  1108. * i40e_sync_vsi_filters.
  1109. *
  1110. * NOTE: This function expects to be called while under the
  1111. * mac_filter_hash_lock
  1112. */
  1113. static int i40e_correct_mac_vlan_filters(struct i40e_vsi *vsi,
  1114. struct hlist_head *tmp_add_list,
  1115. struct hlist_head *tmp_del_list,
  1116. int vlan_filters)
  1117. {
  1118. s16 pvid = le16_to_cpu(vsi->info.pvid);
  1119. struct i40e_mac_filter *f, *add_head;
  1120. struct i40e_new_mac_filter *new;
  1121. struct hlist_node *h;
  1122. int bkt, new_vlan;
  1123. /* To determine if a particular filter needs to be replaced we
  1124. * have the three following conditions:
  1125. *
  1126. * a) if we have a PVID assigned, then all filters which are
  1127. * not marked as VLAN=PVID must be replaced with filters that
  1128. * are.
  1129. * b) otherwise, if we have any active VLANS, all filters
  1130. * which are marked as VLAN=-1 must be replaced with
  1131. * filters marked as VLAN=0
  1132. * c) finally, if we do not have any active VLANS, all filters
  1133. * which are marked as VLAN=0 must be replaced with filters
  1134. * marked as VLAN=-1
  1135. */
  1136. /* Update the filters about to be added in place */
  1137. hlist_for_each_entry(new, tmp_add_list, hlist) {
  1138. if (pvid && new->f->vlan != pvid)
  1139. new->f->vlan = pvid;
  1140. else if (vlan_filters && new->f->vlan == I40E_VLAN_ANY)
  1141. new->f->vlan = 0;
  1142. else if (!vlan_filters && new->f->vlan == 0)
  1143. new->f->vlan = I40E_VLAN_ANY;
  1144. }
  1145. /* Update the remaining active filters */
  1146. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1147. /* Combine the checks for whether a filter needs to be changed
  1148. * and then determine the new VLAN inside the if block, in
  1149. * order to avoid duplicating code for adding the new filter
  1150. * then deleting the old filter.
  1151. */
  1152. if ((pvid && f->vlan != pvid) ||
  1153. (vlan_filters && f->vlan == I40E_VLAN_ANY) ||
  1154. (!vlan_filters && f->vlan == 0)) {
  1155. /* Determine the new vlan we will be adding */
  1156. if (pvid)
  1157. new_vlan = pvid;
  1158. else if (vlan_filters)
  1159. new_vlan = 0;
  1160. else
  1161. new_vlan = I40E_VLAN_ANY;
  1162. /* Create the new filter */
  1163. add_head = i40e_add_filter(vsi, f->macaddr, new_vlan);
  1164. if (!add_head)
  1165. return -ENOMEM;
  1166. /* Create a temporary i40e_new_mac_filter */
  1167. new = kzalloc(sizeof(*new), GFP_ATOMIC);
  1168. if (!new)
  1169. return -ENOMEM;
  1170. new->f = add_head;
  1171. new->state = add_head->state;
  1172. /* Add the new filter to the tmp list */
  1173. hlist_add_head(&new->hlist, tmp_add_list);
  1174. /* Put the original filter into the delete list */
  1175. f->state = I40E_FILTER_REMOVE;
  1176. hash_del(&f->hlist);
  1177. hlist_add_head(&f->hlist, tmp_del_list);
  1178. }
  1179. }
  1180. vsi->has_vlan_filter = !!vlan_filters;
  1181. return 0;
  1182. }
  1183. /**
  1184. * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
  1185. * @vsi: the PF Main VSI - inappropriate for any other VSI
  1186. * @macaddr: the MAC address
  1187. *
  1188. * Remove whatever filter the firmware set up so the driver can manage
  1189. * its own filtering intelligently.
  1190. **/
  1191. static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
  1192. {
  1193. struct i40e_aqc_remove_macvlan_element_data element;
  1194. struct i40e_pf *pf = vsi->back;
  1195. /* Only appropriate for the PF main VSI */
  1196. if (vsi->type != I40E_VSI_MAIN)
  1197. return;
  1198. memset(&element, 0, sizeof(element));
  1199. ether_addr_copy(element.mac_addr, macaddr);
  1200. element.vlan_tag = 0;
  1201. /* Ignore error returns, some firmware does it this way... */
  1202. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1203. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1204. memset(&element, 0, sizeof(element));
  1205. ether_addr_copy(element.mac_addr, macaddr);
  1206. element.vlan_tag = 0;
  1207. /* ...and some firmware does it this way. */
  1208. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
  1209. I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  1210. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1211. }
  1212. /**
  1213. * i40e_add_filter - Add a mac/vlan filter to the VSI
  1214. * @vsi: the VSI to be searched
  1215. * @macaddr: the MAC address
  1216. * @vlan: the vlan
  1217. *
  1218. * Returns ptr to the filter object or NULL when no memory available.
  1219. *
  1220. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1221. * being held.
  1222. **/
  1223. struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
  1224. const u8 *macaddr, s16 vlan)
  1225. {
  1226. struct i40e_mac_filter *f;
  1227. u64 key;
  1228. if (!vsi || !macaddr)
  1229. return NULL;
  1230. f = i40e_find_filter(vsi, macaddr, vlan);
  1231. if (!f) {
  1232. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  1233. if (!f)
  1234. return NULL;
  1235. /* Update the boolean indicating if we need to function in
  1236. * VLAN mode.
  1237. */
  1238. if (vlan >= 0)
  1239. vsi->has_vlan_filter = true;
  1240. ether_addr_copy(f->macaddr, macaddr);
  1241. f->vlan = vlan;
  1242. /* If we're in overflow promisc mode, set the state directly
  1243. * to failed, so we don't bother to try sending the filter
  1244. * to the hardware.
  1245. */
  1246. if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state))
  1247. f->state = I40E_FILTER_FAILED;
  1248. else
  1249. f->state = I40E_FILTER_NEW;
  1250. INIT_HLIST_NODE(&f->hlist);
  1251. key = i40e_addr_to_hkey(macaddr);
  1252. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1253. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1254. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1255. }
  1256. /* If we're asked to add a filter that has been marked for removal, it
  1257. * is safe to simply restore it to active state. __i40e_del_filter
  1258. * will have simply deleted any filters which were previously marked
  1259. * NEW or FAILED, so if it is currently marked REMOVE it must have
  1260. * previously been ACTIVE. Since we haven't yet run the sync filters
  1261. * task, just restore this filter to the ACTIVE state so that the
  1262. * sync task leaves it in place
  1263. */
  1264. if (f->state == I40E_FILTER_REMOVE)
  1265. f->state = I40E_FILTER_ACTIVE;
  1266. return f;
  1267. }
  1268. /**
  1269. * __i40e_del_filter - Remove a specific filter from the VSI
  1270. * @vsi: VSI to remove from
  1271. * @f: the filter to remove from the list
  1272. *
  1273. * This function should be called instead of i40e_del_filter only if you know
  1274. * the exact filter you will remove already, such as via i40e_find_filter or
  1275. * i40e_find_mac.
  1276. *
  1277. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1278. * being held.
  1279. * ANOTHER NOTE: This function MUST be called from within the context of
  1280. * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
  1281. * instead of list_for_each_entry().
  1282. **/
  1283. void __i40e_del_filter(struct i40e_vsi *vsi, struct i40e_mac_filter *f)
  1284. {
  1285. if (!f)
  1286. return;
  1287. /* If the filter was never added to firmware then we can just delete it
  1288. * directly and we don't want to set the status to remove or else an
  1289. * admin queue command will unnecessarily fire.
  1290. */
  1291. if ((f->state == I40E_FILTER_FAILED) ||
  1292. (f->state == I40E_FILTER_NEW)) {
  1293. hash_del(&f->hlist);
  1294. kfree(f);
  1295. } else {
  1296. f->state = I40E_FILTER_REMOVE;
  1297. }
  1298. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1299. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1300. }
  1301. /**
  1302. * i40e_del_filter - Remove a MAC/VLAN filter from the VSI
  1303. * @vsi: the VSI to be searched
  1304. * @macaddr: the MAC address
  1305. * @vlan: the VLAN
  1306. *
  1307. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1308. * being held.
  1309. * ANOTHER NOTE: This function MUST be called from within the context of
  1310. * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
  1311. * instead of list_for_each_entry().
  1312. **/
  1313. void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan)
  1314. {
  1315. struct i40e_mac_filter *f;
  1316. if (!vsi || !macaddr)
  1317. return;
  1318. f = i40e_find_filter(vsi, macaddr, vlan);
  1319. __i40e_del_filter(vsi, f);
  1320. }
  1321. /**
  1322. * i40e_add_mac_filter - Add a MAC filter for all active VLANs
  1323. * @vsi: the VSI to be searched
  1324. * @macaddr: the mac address to be filtered
  1325. *
  1326. * If we're not in VLAN mode, just add the filter to I40E_VLAN_ANY. Otherwise,
  1327. * go through all the macvlan filters and add a macvlan filter for each
  1328. * unique vlan that already exists. If a PVID has been assigned, instead only
  1329. * add the macaddr to that VLAN.
  1330. *
  1331. * Returns last filter added on success, else NULL
  1332. **/
  1333. struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi,
  1334. const u8 *macaddr)
  1335. {
  1336. struct i40e_mac_filter *f, *add = NULL;
  1337. struct hlist_node *h;
  1338. int bkt;
  1339. if (vsi->info.pvid)
  1340. return i40e_add_filter(vsi, macaddr,
  1341. le16_to_cpu(vsi->info.pvid));
  1342. if (!i40e_is_vsi_in_vlan(vsi))
  1343. return i40e_add_filter(vsi, macaddr, I40E_VLAN_ANY);
  1344. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1345. if (f->state == I40E_FILTER_REMOVE)
  1346. continue;
  1347. add = i40e_add_filter(vsi, macaddr, f->vlan);
  1348. if (!add)
  1349. return NULL;
  1350. }
  1351. return add;
  1352. }
  1353. /**
  1354. * i40e_del_mac_filter - Remove a MAC filter from all VLANs
  1355. * @vsi: the VSI to be searched
  1356. * @macaddr: the mac address to be removed
  1357. *
  1358. * Removes a given MAC address from a VSI regardless of what VLAN it has been
  1359. * associated with.
  1360. *
  1361. * Returns 0 for success, or error
  1362. **/
  1363. int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr)
  1364. {
  1365. struct i40e_mac_filter *f;
  1366. struct hlist_node *h;
  1367. bool found = false;
  1368. int bkt;
  1369. WARN(!spin_is_locked(&vsi->mac_filter_hash_lock),
  1370. "Missing mac_filter_hash_lock\n");
  1371. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1372. if (ether_addr_equal(macaddr, f->macaddr)) {
  1373. __i40e_del_filter(vsi, f);
  1374. found = true;
  1375. }
  1376. }
  1377. if (found)
  1378. return 0;
  1379. else
  1380. return -ENOENT;
  1381. }
  1382. /**
  1383. * i40e_set_mac - NDO callback to set mac address
  1384. * @netdev: network interface device structure
  1385. * @p: pointer to an address structure
  1386. *
  1387. * Returns 0 on success, negative on failure
  1388. **/
  1389. static int i40e_set_mac(struct net_device *netdev, void *p)
  1390. {
  1391. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1392. struct i40e_vsi *vsi = np->vsi;
  1393. struct i40e_pf *pf = vsi->back;
  1394. struct i40e_hw *hw = &pf->hw;
  1395. struct sockaddr *addr = p;
  1396. if (!is_valid_ether_addr(addr->sa_data))
  1397. return -EADDRNOTAVAIL;
  1398. if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
  1399. netdev_info(netdev, "already using mac address %pM\n",
  1400. addr->sa_data);
  1401. return 0;
  1402. }
  1403. if (test_bit(__I40E_VSI_DOWN, vsi->back->state) ||
  1404. test_bit(__I40E_RESET_RECOVERY_PENDING, vsi->back->state))
  1405. return -EADDRNOTAVAIL;
  1406. if (ether_addr_equal(hw->mac.addr, addr->sa_data))
  1407. netdev_info(netdev, "returning to hw mac address %pM\n",
  1408. hw->mac.addr);
  1409. else
  1410. netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
  1411. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1412. i40e_del_mac_filter(vsi, netdev->dev_addr);
  1413. i40e_add_mac_filter(vsi, addr->sa_data);
  1414. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1415. ether_addr_copy(netdev->dev_addr, addr->sa_data);
  1416. if (vsi->type == I40E_VSI_MAIN) {
  1417. i40e_status ret;
  1418. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  1419. I40E_AQC_WRITE_TYPE_LAA_WOL,
  1420. addr->sa_data, NULL);
  1421. if (ret)
  1422. netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n",
  1423. i40e_stat_str(hw, ret),
  1424. i40e_aq_str(hw, hw->aq.asq_last_status));
  1425. }
  1426. /* schedule our worker thread which will take care of
  1427. * applying the new filter changes
  1428. */
  1429. i40e_service_event_schedule(vsi->back);
  1430. return 0;
  1431. }
  1432. /**
  1433. * i40e_config_rss_aq - Prepare for RSS using AQ commands
  1434. * @vsi: vsi structure
  1435. * @seed: RSS hash seed
  1436. **/
  1437. static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  1438. u8 *lut, u16 lut_size)
  1439. {
  1440. struct i40e_pf *pf = vsi->back;
  1441. struct i40e_hw *hw = &pf->hw;
  1442. int ret = 0;
  1443. if (seed) {
  1444. struct i40e_aqc_get_set_rss_key_data *seed_dw =
  1445. (struct i40e_aqc_get_set_rss_key_data *)seed;
  1446. ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw);
  1447. if (ret) {
  1448. dev_info(&pf->pdev->dev,
  1449. "Cannot set RSS key, err %s aq_err %s\n",
  1450. i40e_stat_str(hw, ret),
  1451. i40e_aq_str(hw, hw->aq.asq_last_status));
  1452. return ret;
  1453. }
  1454. }
  1455. if (lut) {
  1456. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  1457. ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  1458. if (ret) {
  1459. dev_info(&pf->pdev->dev,
  1460. "Cannot set RSS lut, err %s aq_err %s\n",
  1461. i40e_stat_str(hw, ret),
  1462. i40e_aq_str(hw, hw->aq.asq_last_status));
  1463. return ret;
  1464. }
  1465. }
  1466. return ret;
  1467. }
  1468. /**
  1469. * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
  1470. * @vsi: VSI structure
  1471. **/
  1472. static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
  1473. {
  1474. struct i40e_pf *pf = vsi->back;
  1475. u8 seed[I40E_HKEY_ARRAY_SIZE];
  1476. u8 *lut;
  1477. int ret;
  1478. if (!(pf->hw_features & I40E_HW_RSS_AQ_CAPABLE))
  1479. return 0;
  1480. if (!vsi->rss_size)
  1481. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  1482. vsi->num_queue_pairs);
  1483. if (!vsi->rss_size)
  1484. return -EINVAL;
  1485. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  1486. if (!lut)
  1487. return -ENOMEM;
  1488. /* Use the user configured hash keys and lookup table if there is one,
  1489. * otherwise use default
  1490. */
  1491. if (vsi->rss_lut_user)
  1492. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  1493. else
  1494. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  1495. if (vsi->rss_hkey_user)
  1496. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  1497. else
  1498. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  1499. ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
  1500. kfree(lut);
  1501. return ret;
  1502. }
  1503. /**
  1504. * i40e_vsi_setup_queue_map_mqprio - Prepares mqprio based tc_config
  1505. * @vsi: the VSI being configured,
  1506. * @ctxt: VSI context structure
  1507. * @enabled_tc: number of traffic classes to enable
  1508. *
  1509. * Prepares VSI tc_config to have queue configurations based on MQPRIO options.
  1510. **/
  1511. static int i40e_vsi_setup_queue_map_mqprio(struct i40e_vsi *vsi,
  1512. struct i40e_vsi_context *ctxt,
  1513. u8 enabled_tc)
  1514. {
  1515. u16 qcount = 0, max_qcount, qmap, sections = 0;
  1516. int i, override_q, pow, num_qps, ret;
  1517. u8 netdev_tc = 0, offset = 0;
  1518. if (vsi->type != I40E_VSI_MAIN)
  1519. return -EINVAL;
  1520. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1521. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1522. vsi->tc_config.numtc = vsi->mqprio_qopt.qopt.num_tc;
  1523. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1524. num_qps = vsi->mqprio_qopt.qopt.count[0];
  1525. /* find the next higher power-of-2 of num queue pairs */
  1526. pow = ilog2(num_qps);
  1527. if (!is_power_of_2(num_qps))
  1528. pow++;
  1529. qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1530. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1531. /* Setup queue offset/count for all TCs for given VSI */
  1532. max_qcount = vsi->mqprio_qopt.qopt.count[0];
  1533. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1534. /* See if the given TC is enabled for the given VSI */
  1535. if (vsi->tc_config.enabled_tc & BIT(i)) {
  1536. offset = vsi->mqprio_qopt.qopt.offset[i];
  1537. qcount = vsi->mqprio_qopt.qopt.count[i];
  1538. if (qcount > max_qcount)
  1539. max_qcount = qcount;
  1540. vsi->tc_config.tc_info[i].qoffset = offset;
  1541. vsi->tc_config.tc_info[i].qcount = qcount;
  1542. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1543. } else {
  1544. /* TC is not enabled so set the offset to
  1545. * default queue and allocate one queue
  1546. * for the given TC.
  1547. */
  1548. vsi->tc_config.tc_info[i].qoffset = 0;
  1549. vsi->tc_config.tc_info[i].qcount = 1;
  1550. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1551. }
  1552. }
  1553. /* Set actual Tx/Rx queue pairs */
  1554. vsi->num_queue_pairs = offset + qcount;
  1555. /* Setup queue TC[0].qmap for given VSI context */
  1556. ctxt->info.tc_mapping[0] = cpu_to_le16(qmap);
  1557. ctxt->info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1558. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1559. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1560. /* Reconfigure RSS for main VSI with max queue count */
  1561. vsi->rss_size = max_qcount;
  1562. ret = i40e_vsi_config_rss(vsi);
  1563. if (ret) {
  1564. dev_info(&vsi->back->pdev->dev,
  1565. "Failed to reconfig rss for num_queues (%u)\n",
  1566. max_qcount);
  1567. return ret;
  1568. }
  1569. vsi->reconfig_rss = true;
  1570. dev_dbg(&vsi->back->pdev->dev,
  1571. "Reconfigured rss with num_queues (%u)\n", max_qcount);
  1572. /* Find queue count available for channel VSIs and starting offset
  1573. * for channel VSIs
  1574. */
  1575. override_q = vsi->mqprio_qopt.qopt.count[0];
  1576. if (override_q && override_q < vsi->num_queue_pairs) {
  1577. vsi->cnt_q_avail = vsi->num_queue_pairs - override_q;
  1578. vsi->next_base_queue = override_q;
  1579. }
  1580. return 0;
  1581. }
  1582. /**
  1583. * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
  1584. * @vsi: the VSI being setup
  1585. * @ctxt: VSI context structure
  1586. * @enabled_tc: Enabled TCs bitmap
  1587. * @is_add: True if called before Add VSI
  1588. *
  1589. * Setup VSI queue mapping for enabled traffic classes.
  1590. **/
  1591. static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1592. struct i40e_vsi_context *ctxt,
  1593. u8 enabled_tc,
  1594. bool is_add)
  1595. {
  1596. struct i40e_pf *pf = vsi->back;
  1597. u16 sections = 0;
  1598. u8 netdev_tc = 0;
  1599. u16 numtc = 0;
  1600. u16 qcount;
  1601. u8 offset;
  1602. u16 qmap;
  1603. int i;
  1604. u16 num_tc_qps = 0;
  1605. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1606. offset = 0;
  1607. if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  1608. /* Find numtc from enabled TC bitmap */
  1609. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1610. if (enabled_tc & BIT(i)) /* TC is enabled */
  1611. numtc++;
  1612. }
  1613. if (!numtc) {
  1614. dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
  1615. numtc = 1;
  1616. }
  1617. } else {
  1618. /* At least TC0 is enabled in non-DCB, non-MQPRIO case */
  1619. numtc = 1;
  1620. }
  1621. vsi->tc_config.numtc = numtc;
  1622. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1623. /* Number of queues per enabled TC */
  1624. qcount = vsi->alloc_queue_pairs;
  1625. num_tc_qps = qcount / numtc;
  1626. num_tc_qps = min_t(int, num_tc_qps, i40e_pf_get_max_q_per_tc(pf));
  1627. /* Setup queue offset/count for all TCs for given VSI */
  1628. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1629. /* See if the given TC is enabled for the given VSI */
  1630. if (vsi->tc_config.enabled_tc & BIT(i)) {
  1631. /* TC is enabled */
  1632. int pow, num_qps;
  1633. switch (vsi->type) {
  1634. case I40E_VSI_MAIN:
  1635. qcount = min_t(int, pf->alloc_rss_size,
  1636. num_tc_qps);
  1637. break;
  1638. case I40E_VSI_FDIR:
  1639. case I40E_VSI_SRIOV:
  1640. case I40E_VSI_VMDQ2:
  1641. default:
  1642. qcount = num_tc_qps;
  1643. WARN_ON(i != 0);
  1644. break;
  1645. }
  1646. vsi->tc_config.tc_info[i].qoffset = offset;
  1647. vsi->tc_config.tc_info[i].qcount = qcount;
  1648. /* find the next higher power-of-2 of num queue pairs */
  1649. num_qps = qcount;
  1650. pow = 0;
  1651. while (num_qps && (BIT_ULL(pow) < qcount)) {
  1652. pow++;
  1653. num_qps >>= 1;
  1654. }
  1655. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1656. qmap =
  1657. (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1658. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1659. offset += qcount;
  1660. } else {
  1661. /* TC is not enabled so set the offset to
  1662. * default queue and allocate one queue
  1663. * for the given TC.
  1664. */
  1665. vsi->tc_config.tc_info[i].qoffset = 0;
  1666. vsi->tc_config.tc_info[i].qcount = 1;
  1667. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1668. qmap = 0;
  1669. }
  1670. ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
  1671. }
  1672. /* Set actual Tx/Rx queue pairs */
  1673. vsi->num_queue_pairs = offset;
  1674. if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
  1675. if (vsi->req_queue_pairs > 0)
  1676. vsi->num_queue_pairs = vsi->req_queue_pairs;
  1677. else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  1678. vsi->num_queue_pairs = pf->num_lan_msix;
  1679. }
  1680. /* Scheduler section valid can only be set for ADD VSI */
  1681. if (is_add) {
  1682. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1683. ctxt->info.up_enable_bits = enabled_tc;
  1684. }
  1685. if (vsi->type == I40E_VSI_SRIOV) {
  1686. ctxt->info.mapping_flags |=
  1687. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
  1688. for (i = 0; i < vsi->num_queue_pairs; i++)
  1689. ctxt->info.queue_mapping[i] =
  1690. cpu_to_le16(vsi->base_queue + i);
  1691. } else {
  1692. ctxt->info.mapping_flags |=
  1693. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1694. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1695. }
  1696. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1697. }
  1698. /**
  1699. * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address
  1700. * @netdev: the netdevice
  1701. * @addr: address to add
  1702. *
  1703. * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
  1704. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  1705. */
  1706. static int i40e_addr_sync(struct net_device *netdev, const u8 *addr)
  1707. {
  1708. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1709. struct i40e_vsi *vsi = np->vsi;
  1710. if (i40e_add_mac_filter(vsi, addr))
  1711. return 0;
  1712. else
  1713. return -ENOMEM;
  1714. }
  1715. /**
  1716. * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
  1717. * @netdev: the netdevice
  1718. * @addr: address to add
  1719. *
  1720. * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
  1721. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  1722. */
  1723. static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr)
  1724. {
  1725. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1726. struct i40e_vsi *vsi = np->vsi;
  1727. i40e_del_mac_filter(vsi, addr);
  1728. return 0;
  1729. }
  1730. /**
  1731. * i40e_set_rx_mode - NDO callback to set the netdev filters
  1732. * @netdev: network interface device structure
  1733. **/
  1734. static void i40e_set_rx_mode(struct net_device *netdev)
  1735. {
  1736. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1737. struct i40e_vsi *vsi = np->vsi;
  1738. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1739. __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
  1740. __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
  1741. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1742. /* check for other flag changes */
  1743. if (vsi->current_netdev_flags != vsi->netdev->flags) {
  1744. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1745. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1746. }
  1747. }
  1748. /**
  1749. * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
  1750. * @vsi: Pointer to VSI struct
  1751. * @from: Pointer to list which contains MAC filter entries - changes to
  1752. * those entries needs to be undone.
  1753. *
  1754. * MAC filter entries from this list were slated for deletion.
  1755. **/
  1756. static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi,
  1757. struct hlist_head *from)
  1758. {
  1759. struct i40e_mac_filter *f;
  1760. struct hlist_node *h;
  1761. hlist_for_each_entry_safe(f, h, from, hlist) {
  1762. u64 key = i40e_addr_to_hkey(f->macaddr);
  1763. /* Move the element back into MAC filter list*/
  1764. hlist_del(&f->hlist);
  1765. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1766. }
  1767. }
  1768. /**
  1769. * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
  1770. * @vsi: Pointer to vsi struct
  1771. * @from: Pointer to list which contains MAC filter entries - changes to
  1772. * those entries needs to be undone.
  1773. *
  1774. * MAC filter entries from this list were slated for addition.
  1775. **/
  1776. static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi,
  1777. struct hlist_head *from)
  1778. {
  1779. struct i40e_new_mac_filter *new;
  1780. struct hlist_node *h;
  1781. hlist_for_each_entry_safe(new, h, from, hlist) {
  1782. /* We can simply free the wrapper structure */
  1783. hlist_del(&new->hlist);
  1784. kfree(new);
  1785. }
  1786. }
  1787. /**
  1788. * i40e_next_entry - Get the next non-broadcast filter from a list
  1789. * @next: pointer to filter in list
  1790. *
  1791. * Returns the next non-broadcast filter in the list. Required so that we
  1792. * ignore broadcast filters within the list, since these are not handled via
  1793. * the normal firmware update path.
  1794. */
  1795. static
  1796. struct i40e_new_mac_filter *i40e_next_filter(struct i40e_new_mac_filter *next)
  1797. {
  1798. hlist_for_each_entry_continue(next, hlist) {
  1799. if (!is_broadcast_ether_addr(next->f->macaddr))
  1800. return next;
  1801. }
  1802. return NULL;
  1803. }
  1804. /**
  1805. * i40e_update_filter_state - Update filter state based on return data
  1806. * from firmware
  1807. * @count: Number of filters added
  1808. * @add_list: return data from fw
  1809. * @head: pointer to first filter in current batch
  1810. *
  1811. * MAC filter entries from list were slated to be added to device. Returns
  1812. * number of successful filters. Note that 0 does NOT mean success!
  1813. **/
  1814. static int
  1815. i40e_update_filter_state(int count,
  1816. struct i40e_aqc_add_macvlan_element_data *add_list,
  1817. struct i40e_new_mac_filter *add_head)
  1818. {
  1819. int retval = 0;
  1820. int i;
  1821. for (i = 0; i < count; i++) {
  1822. /* Always check status of each filter. We don't need to check
  1823. * the firmware return status because we pre-set the filter
  1824. * status to I40E_AQC_MM_ERR_NO_RES when sending the filter
  1825. * request to the adminq. Thus, if it no longer matches then
  1826. * we know the filter is active.
  1827. */
  1828. if (add_list[i].match_method == I40E_AQC_MM_ERR_NO_RES) {
  1829. add_head->state = I40E_FILTER_FAILED;
  1830. } else {
  1831. add_head->state = I40E_FILTER_ACTIVE;
  1832. retval++;
  1833. }
  1834. add_head = i40e_next_filter(add_head);
  1835. if (!add_head)
  1836. break;
  1837. }
  1838. return retval;
  1839. }
  1840. /**
  1841. * i40e_aqc_del_filters - Request firmware to delete a set of filters
  1842. * @vsi: ptr to the VSI
  1843. * @vsi_name: name to display in messages
  1844. * @list: the list of filters to send to firmware
  1845. * @num_del: the number of filters to delete
  1846. * @retval: Set to -EIO on failure to delete
  1847. *
  1848. * Send a request to firmware via AdminQ to delete a set of filters. Uses
  1849. * *retval instead of a return value so that success does not force ret_val to
  1850. * be set to 0. This ensures that a sequence of calls to this function
  1851. * preserve the previous value of *retval on successful delete.
  1852. */
  1853. static
  1854. void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name,
  1855. struct i40e_aqc_remove_macvlan_element_data *list,
  1856. int num_del, int *retval)
  1857. {
  1858. struct i40e_hw *hw = &vsi->back->hw;
  1859. i40e_status aq_ret;
  1860. int aq_err;
  1861. aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL);
  1862. aq_err = hw->aq.asq_last_status;
  1863. /* Explicitly ignore and do not report when firmware returns ENOENT */
  1864. if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) {
  1865. *retval = -EIO;
  1866. dev_info(&vsi->back->pdev->dev,
  1867. "ignoring delete macvlan error on %s, err %s, aq_err %s\n",
  1868. vsi_name, i40e_stat_str(hw, aq_ret),
  1869. i40e_aq_str(hw, aq_err));
  1870. }
  1871. }
  1872. /**
  1873. * i40e_aqc_add_filters - Request firmware to add a set of filters
  1874. * @vsi: ptr to the VSI
  1875. * @vsi_name: name to display in messages
  1876. * @list: the list of filters to send to firmware
  1877. * @add_head: Position in the add hlist
  1878. * @num_add: the number of filters to add
  1879. * @promisc_change: set to true on exit if promiscuous mode was forced on
  1880. *
  1881. * Send a request to firmware via AdminQ to add a chunk of filters. Will set
  1882. * promisc_changed to true if the firmware has run out of space for more
  1883. * filters.
  1884. */
  1885. static
  1886. void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name,
  1887. struct i40e_aqc_add_macvlan_element_data *list,
  1888. struct i40e_new_mac_filter *add_head,
  1889. int num_add, bool *promisc_changed)
  1890. {
  1891. struct i40e_hw *hw = &vsi->back->hw;
  1892. int aq_err, fcnt;
  1893. i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL);
  1894. aq_err = hw->aq.asq_last_status;
  1895. fcnt = i40e_update_filter_state(num_add, list, add_head);
  1896. if (fcnt != num_add) {
  1897. *promisc_changed = true;
  1898. set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  1899. dev_warn(&vsi->back->pdev->dev,
  1900. "Error %s adding RX filters on %s, promiscuous mode forced on\n",
  1901. i40e_aq_str(hw, aq_err),
  1902. vsi_name);
  1903. }
  1904. }
  1905. /**
  1906. * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags
  1907. * @vsi: pointer to the VSI
  1908. * @f: filter data
  1909. *
  1910. * This function sets or clears the promiscuous broadcast flags for VLAN
  1911. * filters in order to properly receive broadcast frames. Assumes that only
  1912. * broadcast filters are passed.
  1913. *
  1914. * Returns status indicating success or failure;
  1915. **/
  1916. static i40e_status
  1917. i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name,
  1918. struct i40e_mac_filter *f)
  1919. {
  1920. bool enable = f->state == I40E_FILTER_NEW;
  1921. struct i40e_hw *hw = &vsi->back->hw;
  1922. i40e_status aq_ret;
  1923. if (f->vlan == I40E_VLAN_ANY) {
  1924. aq_ret = i40e_aq_set_vsi_broadcast(hw,
  1925. vsi->seid,
  1926. enable,
  1927. NULL);
  1928. } else {
  1929. aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw,
  1930. vsi->seid,
  1931. enable,
  1932. f->vlan,
  1933. NULL);
  1934. }
  1935. if (aq_ret)
  1936. dev_warn(&vsi->back->pdev->dev,
  1937. "Error %s setting broadcast promiscuous mode on %s\n",
  1938. i40e_aq_str(hw, hw->aq.asq_last_status),
  1939. vsi_name);
  1940. return aq_ret;
  1941. }
  1942. /**
  1943. * i40e_sync_vsi_filters - Update the VSI filter list to the HW
  1944. * @vsi: ptr to the VSI
  1945. *
  1946. * Push any outstanding VSI filter changes through the AdminQ.
  1947. *
  1948. * Returns 0 or error value
  1949. **/
  1950. int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
  1951. {
  1952. struct hlist_head tmp_add_list, tmp_del_list;
  1953. struct i40e_mac_filter *f;
  1954. struct i40e_new_mac_filter *new, *add_head = NULL;
  1955. struct i40e_hw *hw = &vsi->back->hw;
  1956. unsigned int failed_filters = 0;
  1957. unsigned int vlan_filters = 0;
  1958. bool promisc_changed = false;
  1959. char vsi_name[16] = "PF";
  1960. int filter_list_len = 0;
  1961. i40e_status aq_ret = 0;
  1962. u32 changed_flags = 0;
  1963. struct hlist_node *h;
  1964. struct i40e_pf *pf;
  1965. int num_add = 0;
  1966. int num_del = 0;
  1967. int retval = 0;
  1968. u16 cmd_flags;
  1969. int list_size;
  1970. int bkt;
  1971. /* empty array typed pointers, kcalloc later */
  1972. struct i40e_aqc_add_macvlan_element_data *add_list;
  1973. struct i40e_aqc_remove_macvlan_element_data *del_list;
  1974. while (test_and_set_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state))
  1975. usleep_range(1000, 2000);
  1976. pf = vsi->back;
  1977. if (vsi->netdev) {
  1978. changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
  1979. vsi->current_netdev_flags = vsi->netdev->flags;
  1980. }
  1981. INIT_HLIST_HEAD(&tmp_add_list);
  1982. INIT_HLIST_HEAD(&tmp_del_list);
  1983. if (vsi->type == I40E_VSI_SRIOV)
  1984. snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id);
  1985. else if (vsi->type != I40E_VSI_MAIN)
  1986. snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid);
  1987. if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
  1988. vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
  1989. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1990. /* Create a list of filters to delete. */
  1991. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1992. if (f->state == I40E_FILTER_REMOVE) {
  1993. /* Move the element into temporary del_list */
  1994. hash_del(&f->hlist);
  1995. hlist_add_head(&f->hlist, &tmp_del_list);
  1996. /* Avoid counting removed filters */
  1997. continue;
  1998. }
  1999. if (f->state == I40E_FILTER_NEW) {
  2000. /* Create a temporary i40e_new_mac_filter */
  2001. new = kzalloc(sizeof(*new), GFP_ATOMIC);
  2002. if (!new)
  2003. goto err_no_memory_locked;
  2004. /* Store pointer to the real filter */
  2005. new->f = f;
  2006. new->state = f->state;
  2007. /* Add it to the hash list */
  2008. hlist_add_head(&new->hlist, &tmp_add_list);
  2009. }
  2010. /* Count the number of active (current and new) VLAN
  2011. * filters we have now. Does not count filters which
  2012. * are marked for deletion.
  2013. */
  2014. if (f->vlan > 0)
  2015. vlan_filters++;
  2016. }
  2017. retval = i40e_correct_mac_vlan_filters(vsi,
  2018. &tmp_add_list,
  2019. &tmp_del_list,
  2020. vlan_filters);
  2021. if (retval)
  2022. goto err_no_memory_locked;
  2023. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2024. }
  2025. /* Now process 'del_list' outside the lock */
  2026. if (!hlist_empty(&tmp_del_list)) {
  2027. filter_list_len = hw->aq.asq_buf_size /
  2028. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  2029. list_size = filter_list_len *
  2030. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  2031. del_list = kzalloc(list_size, GFP_ATOMIC);
  2032. if (!del_list)
  2033. goto err_no_memory;
  2034. hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) {
  2035. cmd_flags = 0;
  2036. /* handle broadcast filters by updating the broadcast
  2037. * promiscuous flag and release filter list.
  2038. */
  2039. if (is_broadcast_ether_addr(f->macaddr)) {
  2040. i40e_aqc_broadcast_filter(vsi, vsi_name, f);
  2041. hlist_del(&f->hlist);
  2042. kfree(f);
  2043. continue;
  2044. }
  2045. /* add to delete list */
  2046. ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
  2047. if (f->vlan == I40E_VLAN_ANY) {
  2048. del_list[num_del].vlan_tag = 0;
  2049. cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  2050. } else {
  2051. del_list[num_del].vlan_tag =
  2052. cpu_to_le16((u16)(f->vlan));
  2053. }
  2054. cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  2055. del_list[num_del].flags = cmd_flags;
  2056. num_del++;
  2057. /* flush a full buffer */
  2058. if (num_del == filter_list_len) {
  2059. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  2060. num_del, &retval);
  2061. memset(del_list, 0, list_size);
  2062. num_del = 0;
  2063. }
  2064. /* Release memory for MAC filter entries which were
  2065. * synced up with HW.
  2066. */
  2067. hlist_del(&f->hlist);
  2068. kfree(f);
  2069. }
  2070. if (num_del) {
  2071. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  2072. num_del, &retval);
  2073. }
  2074. kfree(del_list);
  2075. del_list = NULL;
  2076. }
  2077. if (!hlist_empty(&tmp_add_list)) {
  2078. /* Do all the adds now. */
  2079. filter_list_len = hw->aq.asq_buf_size /
  2080. sizeof(struct i40e_aqc_add_macvlan_element_data);
  2081. list_size = filter_list_len *
  2082. sizeof(struct i40e_aqc_add_macvlan_element_data);
  2083. add_list = kzalloc(list_size, GFP_ATOMIC);
  2084. if (!add_list)
  2085. goto err_no_memory;
  2086. num_add = 0;
  2087. hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
  2088. if (test_bit(__I40E_VSI_OVERFLOW_PROMISC,
  2089. vsi->state)) {
  2090. new->state = I40E_FILTER_FAILED;
  2091. continue;
  2092. }
  2093. /* handle broadcast filters by updating the broadcast
  2094. * promiscuous flag instead of adding a MAC filter.
  2095. */
  2096. if (is_broadcast_ether_addr(new->f->macaddr)) {
  2097. if (i40e_aqc_broadcast_filter(vsi, vsi_name,
  2098. new->f))
  2099. new->state = I40E_FILTER_FAILED;
  2100. else
  2101. new->state = I40E_FILTER_ACTIVE;
  2102. continue;
  2103. }
  2104. /* add to add array */
  2105. if (num_add == 0)
  2106. add_head = new;
  2107. cmd_flags = 0;
  2108. ether_addr_copy(add_list[num_add].mac_addr,
  2109. new->f->macaddr);
  2110. if (new->f->vlan == I40E_VLAN_ANY) {
  2111. add_list[num_add].vlan_tag = 0;
  2112. cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
  2113. } else {
  2114. add_list[num_add].vlan_tag =
  2115. cpu_to_le16((u16)(new->f->vlan));
  2116. }
  2117. add_list[num_add].queue_number = 0;
  2118. /* set invalid match method for later detection */
  2119. add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES;
  2120. cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
  2121. add_list[num_add].flags = cpu_to_le16(cmd_flags);
  2122. num_add++;
  2123. /* flush a full buffer */
  2124. if (num_add == filter_list_len) {
  2125. i40e_aqc_add_filters(vsi, vsi_name, add_list,
  2126. add_head, num_add,
  2127. &promisc_changed);
  2128. memset(add_list, 0, list_size);
  2129. num_add = 0;
  2130. }
  2131. }
  2132. if (num_add) {
  2133. i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head,
  2134. num_add, &promisc_changed);
  2135. }
  2136. /* Now move all of the filters from the temp add list back to
  2137. * the VSI's list.
  2138. */
  2139. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2140. hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
  2141. /* Only update the state if we're still NEW */
  2142. if (new->f->state == I40E_FILTER_NEW)
  2143. new->f->state = new->state;
  2144. hlist_del(&new->hlist);
  2145. kfree(new);
  2146. }
  2147. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2148. kfree(add_list);
  2149. add_list = NULL;
  2150. }
  2151. /* Determine the number of active and failed filters. */
  2152. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2153. vsi->active_filters = 0;
  2154. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
  2155. if (f->state == I40E_FILTER_ACTIVE)
  2156. vsi->active_filters++;
  2157. else if (f->state == I40E_FILTER_FAILED)
  2158. failed_filters++;
  2159. }
  2160. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2161. /* If promiscuous mode has changed, we need to calculate a new
  2162. * threshold for when we are safe to exit
  2163. */
  2164. if (promisc_changed)
  2165. vsi->promisc_threshold = (vsi->active_filters * 3) / 4;
  2166. /* Check if we are able to exit overflow promiscuous mode. We can
  2167. * safely exit if we didn't just enter, we no longer have any failed
  2168. * filters, and we have reduced filters below the threshold value.
  2169. */
  2170. if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state) &&
  2171. !promisc_changed && !failed_filters &&
  2172. (vsi->active_filters < vsi->promisc_threshold)) {
  2173. dev_info(&pf->pdev->dev,
  2174. "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
  2175. vsi_name);
  2176. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  2177. promisc_changed = true;
  2178. vsi->promisc_threshold = 0;
  2179. }
  2180. /* if the VF is not trusted do not do promisc */
  2181. if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) {
  2182. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  2183. goto out;
  2184. }
  2185. /* check for changes in promiscuous modes */
  2186. if (changed_flags & IFF_ALLMULTI) {
  2187. bool cur_multipromisc;
  2188. cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
  2189. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
  2190. vsi->seid,
  2191. cur_multipromisc,
  2192. NULL);
  2193. if (aq_ret) {
  2194. retval = i40e_aq_rc_to_posix(aq_ret,
  2195. hw->aq.asq_last_status);
  2196. dev_info(&pf->pdev->dev,
  2197. "set multi promisc failed on %s, err %s aq_err %s\n",
  2198. vsi_name,
  2199. i40e_stat_str(hw, aq_ret),
  2200. i40e_aq_str(hw, hw->aq.asq_last_status));
  2201. }
  2202. }
  2203. if ((changed_flags & IFF_PROMISC) || promisc_changed) {
  2204. bool cur_promisc;
  2205. cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
  2206. test_bit(__I40E_VSI_OVERFLOW_PROMISC,
  2207. vsi->state));
  2208. if ((vsi->type == I40E_VSI_MAIN) &&
  2209. (pf->lan_veb != I40E_NO_VEB) &&
  2210. !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
  2211. /* set defport ON for Main VSI instead of true promisc
  2212. * this way we will get all unicast/multicast and VLAN
  2213. * promisc behavior but will not get VF or VMDq traffic
  2214. * replicated on the Main VSI.
  2215. */
  2216. if (pf->cur_promisc != cur_promisc) {
  2217. pf->cur_promisc = cur_promisc;
  2218. if (cur_promisc)
  2219. aq_ret =
  2220. i40e_aq_set_default_vsi(hw,
  2221. vsi->seid,
  2222. NULL);
  2223. else
  2224. aq_ret =
  2225. i40e_aq_clear_default_vsi(hw,
  2226. vsi->seid,
  2227. NULL);
  2228. if (aq_ret) {
  2229. retval = i40e_aq_rc_to_posix(aq_ret,
  2230. hw->aq.asq_last_status);
  2231. dev_info(&pf->pdev->dev,
  2232. "Set default VSI failed on %s, err %s, aq_err %s\n",
  2233. vsi_name,
  2234. i40e_stat_str(hw, aq_ret),
  2235. i40e_aq_str(hw,
  2236. hw->aq.asq_last_status));
  2237. }
  2238. }
  2239. } else {
  2240. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
  2241. hw,
  2242. vsi->seid,
  2243. cur_promisc, NULL,
  2244. true);
  2245. if (aq_ret) {
  2246. retval =
  2247. i40e_aq_rc_to_posix(aq_ret,
  2248. hw->aq.asq_last_status);
  2249. dev_info(&pf->pdev->dev,
  2250. "set unicast promisc failed on %s, err %s, aq_err %s\n",
  2251. vsi_name,
  2252. i40e_stat_str(hw, aq_ret),
  2253. i40e_aq_str(hw,
  2254. hw->aq.asq_last_status));
  2255. }
  2256. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
  2257. hw,
  2258. vsi->seid,
  2259. cur_promisc, NULL);
  2260. if (aq_ret) {
  2261. retval =
  2262. i40e_aq_rc_to_posix(aq_ret,
  2263. hw->aq.asq_last_status);
  2264. dev_info(&pf->pdev->dev,
  2265. "set multicast promisc failed on %s, err %s, aq_err %s\n",
  2266. vsi_name,
  2267. i40e_stat_str(hw, aq_ret),
  2268. i40e_aq_str(hw,
  2269. hw->aq.asq_last_status));
  2270. }
  2271. }
  2272. aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
  2273. vsi->seid,
  2274. cur_promisc, NULL);
  2275. if (aq_ret) {
  2276. retval = i40e_aq_rc_to_posix(aq_ret,
  2277. pf->hw.aq.asq_last_status);
  2278. dev_info(&pf->pdev->dev,
  2279. "set brdcast promisc failed, err %s, aq_err %s\n",
  2280. i40e_stat_str(hw, aq_ret),
  2281. i40e_aq_str(hw,
  2282. hw->aq.asq_last_status));
  2283. }
  2284. }
  2285. out:
  2286. /* if something went wrong then set the changed flag so we try again */
  2287. if (retval)
  2288. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2289. clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
  2290. return retval;
  2291. err_no_memory:
  2292. /* Restore elements on the temporary add and delete lists */
  2293. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2294. err_no_memory_locked:
  2295. i40e_undo_del_filter_entries(vsi, &tmp_del_list);
  2296. i40e_undo_add_filter_entries(vsi, &tmp_add_list);
  2297. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2298. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2299. clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
  2300. return -ENOMEM;
  2301. }
  2302. /**
  2303. * i40e_sync_filters_subtask - Sync the VSI filter list with HW
  2304. * @pf: board private structure
  2305. **/
  2306. static void i40e_sync_filters_subtask(struct i40e_pf *pf)
  2307. {
  2308. int v;
  2309. if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
  2310. return;
  2311. pf->flags &= ~I40E_FLAG_FILTER_SYNC;
  2312. for (v = 0; v < pf->num_alloc_vsi; v++) {
  2313. if (pf->vsi[v] &&
  2314. (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
  2315. int ret = i40e_sync_vsi_filters(pf->vsi[v]);
  2316. if (ret) {
  2317. /* come back and try again later */
  2318. pf->flags |= I40E_FLAG_FILTER_SYNC;
  2319. break;
  2320. }
  2321. }
  2322. }
  2323. }
  2324. /**
  2325. * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP
  2326. * @vsi: the vsi
  2327. **/
  2328. static int i40e_max_xdp_frame_size(struct i40e_vsi *vsi)
  2329. {
  2330. if (PAGE_SIZE >= 8192 || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
  2331. return I40E_RXBUFFER_2048;
  2332. else
  2333. return I40E_RXBUFFER_3072;
  2334. }
  2335. /**
  2336. * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  2337. * @netdev: network interface device structure
  2338. * @new_mtu: new value for maximum frame size
  2339. *
  2340. * Returns 0 on success, negative on failure
  2341. **/
  2342. static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
  2343. {
  2344. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2345. struct i40e_vsi *vsi = np->vsi;
  2346. struct i40e_pf *pf = vsi->back;
  2347. if (i40e_enabled_xdp_vsi(vsi)) {
  2348. int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  2349. if (frame_size > i40e_max_xdp_frame_size(vsi))
  2350. return -EINVAL;
  2351. }
  2352. netdev_info(netdev, "changing MTU from %d to %d\n",
  2353. netdev->mtu, new_mtu);
  2354. netdev->mtu = new_mtu;
  2355. if (netif_running(netdev))
  2356. i40e_vsi_reinit_locked(vsi);
  2357. pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED |
  2358. I40E_FLAG_CLIENT_L2_CHANGE);
  2359. return 0;
  2360. }
  2361. /**
  2362. * i40e_ioctl - Access the hwtstamp interface
  2363. * @netdev: network interface device structure
  2364. * @ifr: interface request data
  2365. * @cmd: ioctl command
  2366. **/
  2367. int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  2368. {
  2369. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2370. struct i40e_pf *pf = np->vsi->back;
  2371. switch (cmd) {
  2372. case SIOCGHWTSTAMP:
  2373. return i40e_ptp_get_ts_config(pf, ifr);
  2374. case SIOCSHWTSTAMP:
  2375. return i40e_ptp_set_ts_config(pf, ifr);
  2376. default:
  2377. return -EOPNOTSUPP;
  2378. }
  2379. }
  2380. /**
  2381. * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
  2382. * @vsi: the vsi being adjusted
  2383. **/
  2384. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
  2385. {
  2386. struct i40e_vsi_context ctxt;
  2387. i40e_status ret;
  2388. if ((vsi->info.valid_sections &
  2389. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2390. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
  2391. return; /* already enabled */
  2392. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2393. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2394. I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
  2395. ctxt.seid = vsi->seid;
  2396. ctxt.info = vsi->info;
  2397. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2398. if (ret) {
  2399. dev_info(&vsi->back->pdev->dev,
  2400. "update vlan stripping failed, err %s aq_err %s\n",
  2401. i40e_stat_str(&vsi->back->hw, ret),
  2402. i40e_aq_str(&vsi->back->hw,
  2403. vsi->back->hw.aq.asq_last_status));
  2404. }
  2405. }
  2406. /**
  2407. * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
  2408. * @vsi: the vsi being adjusted
  2409. **/
  2410. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
  2411. {
  2412. struct i40e_vsi_context ctxt;
  2413. i40e_status ret;
  2414. if ((vsi->info.valid_sections &
  2415. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2416. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
  2417. I40E_AQ_VSI_PVLAN_EMOD_MASK))
  2418. return; /* already disabled */
  2419. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2420. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2421. I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
  2422. ctxt.seid = vsi->seid;
  2423. ctxt.info = vsi->info;
  2424. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2425. if (ret) {
  2426. dev_info(&vsi->back->pdev->dev,
  2427. "update vlan stripping failed, err %s aq_err %s\n",
  2428. i40e_stat_str(&vsi->back->hw, ret),
  2429. i40e_aq_str(&vsi->back->hw,
  2430. vsi->back->hw.aq.asq_last_status));
  2431. }
  2432. }
  2433. /**
  2434. * i40e_vlan_rx_register - Setup or shutdown vlan offload
  2435. * @netdev: network interface to be adjusted
  2436. * @features: netdev features to test if VLAN offload is enabled or not
  2437. **/
  2438. static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
  2439. {
  2440. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2441. struct i40e_vsi *vsi = np->vsi;
  2442. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  2443. i40e_vlan_stripping_enable(vsi);
  2444. else
  2445. i40e_vlan_stripping_disable(vsi);
  2446. }
  2447. /**
  2448. * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address
  2449. * @vsi: the vsi being configured
  2450. * @vid: vlan id to be added (0 = untagged only , -1 = any)
  2451. *
  2452. * This is a helper function for adding a new MAC/VLAN filter with the
  2453. * specified VLAN for each existing MAC address already in the hash table.
  2454. * This function does *not* perform any accounting to update filters based on
  2455. * VLAN mode.
  2456. *
  2457. * NOTE: this function expects to be called while under the
  2458. * mac_filter_hash_lock
  2459. **/
  2460. int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2461. {
  2462. struct i40e_mac_filter *f, *add_f;
  2463. struct hlist_node *h;
  2464. int bkt;
  2465. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2466. if (f->state == I40E_FILTER_REMOVE)
  2467. continue;
  2468. add_f = i40e_add_filter(vsi, f->macaddr, vid);
  2469. if (!add_f) {
  2470. dev_info(&vsi->back->pdev->dev,
  2471. "Could not add vlan filter %d for %pM\n",
  2472. vid, f->macaddr);
  2473. return -ENOMEM;
  2474. }
  2475. }
  2476. return 0;
  2477. }
  2478. /**
  2479. * i40e_vsi_add_vlan - Add VSI membership for given VLAN
  2480. * @vsi: the VSI being configured
  2481. * @vid: VLAN id to be added
  2482. **/
  2483. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid)
  2484. {
  2485. int err;
  2486. if (vsi->info.pvid)
  2487. return -EINVAL;
  2488. /* The network stack will attempt to add VID=0, with the intention to
  2489. * receive priority tagged packets with a VLAN of 0. Our HW receives
  2490. * these packets by default when configured to receive untagged
  2491. * packets, so we don't need to add a filter for this case.
  2492. * Additionally, HW interprets adding a VID=0 filter as meaning to
  2493. * receive *only* tagged traffic and stops receiving untagged traffic.
  2494. * Thus, we do not want to actually add a filter for VID=0
  2495. */
  2496. if (!vid)
  2497. return 0;
  2498. /* Locked once because all functions invoked below iterates list*/
  2499. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2500. err = i40e_add_vlan_all_mac(vsi, vid);
  2501. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2502. if (err)
  2503. return err;
  2504. /* schedule our worker thread which will take care of
  2505. * applying the new filter changes
  2506. */
  2507. i40e_service_event_schedule(vsi->back);
  2508. return 0;
  2509. }
  2510. /**
  2511. * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN
  2512. * @vsi: the vsi being configured
  2513. * @vid: vlan id to be removed (0 = untagged only , -1 = any)
  2514. *
  2515. * This function should be used to remove all VLAN filters which match the
  2516. * given VID. It does not schedule the service event and does not take the
  2517. * mac_filter_hash_lock so it may be combined with other operations under
  2518. * a single invocation of the mac_filter_hash_lock.
  2519. *
  2520. * NOTE: this function expects to be called while under the
  2521. * mac_filter_hash_lock
  2522. */
  2523. void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2524. {
  2525. struct i40e_mac_filter *f;
  2526. struct hlist_node *h;
  2527. int bkt;
  2528. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2529. if (f->vlan == vid)
  2530. __i40e_del_filter(vsi, f);
  2531. }
  2532. }
  2533. /**
  2534. * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN
  2535. * @vsi: the VSI being configured
  2536. * @vid: VLAN id to be removed
  2537. **/
  2538. void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid)
  2539. {
  2540. if (!vid || vsi->info.pvid)
  2541. return;
  2542. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2543. i40e_rm_vlan_all_mac(vsi, vid);
  2544. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2545. /* schedule our worker thread which will take care of
  2546. * applying the new filter changes
  2547. */
  2548. i40e_service_event_schedule(vsi->back);
  2549. }
  2550. /**
  2551. * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
  2552. * @netdev: network interface to be adjusted
  2553. * @vid: vlan id to be added
  2554. *
  2555. * net_device_ops implementation for adding vlan ids
  2556. **/
  2557. static int i40e_vlan_rx_add_vid(struct net_device *netdev,
  2558. __always_unused __be16 proto, u16 vid)
  2559. {
  2560. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2561. struct i40e_vsi *vsi = np->vsi;
  2562. int ret = 0;
  2563. if (vid >= VLAN_N_VID)
  2564. return -EINVAL;
  2565. ret = i40e_vsi_add_vlan(vsi, vid);
  2566. if (!ret)
  2567. set_bit(vid, vsi->active_vlans);
  2568. return ret;
  2569. }
  2570. /**
  2571. * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
  2572. * @netdev: network interface to be adjusted
  2573. * @vid: vlan id to be removed
  2574. *
  2575. * net_device_ops implementation for removing vlan ids
  2576. **/
  2577. static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  2578. __always_unused __be16 proto, u16 vid)
  2579. {
  2580. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2581. struct i40e_vsi *vsi = np->vsi;
  2582. /* return code is ignored as there is nothing a user
  2583. * can do about failure to remove and a log message was
  2584. * already printed from the other function
  2585. */
  2586. i40e_vsi_kill_vlan(vsi, vid);
  2587. clear_bit(vid, vsi->active_vlans);
  2588. return 0;
  2589. }
  2590. /**
  2591. * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
  2592. * @vsi: the vsi being brought back up
  2593. **/
  2594. static void i40e_restore_vlan(struct i40e_vsi *vsi)
  2595. {
  2596. u16 vid;
  2597. if (!vsi->netdev)
  2598. return;
  2599. i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
  2600. for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
  2601. i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
  2602. vid);
  2603. }
  2604. /**
  2605. * i40e_vsi_add_pvid - Add pvid for the VSI
  2606. * @vsi: the vsi being adjusted
  2607. * @vid: the vlan id to set as a PVID
  2608. **/
  2609. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
  2610. {
  2611. struct i40e_vsi_context ctxt;
  2612. i40e_status ret;
  2613. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2614. vsi->info.pvid = cpu_to_le16(vid);
  2615. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
  2616. I40E_AQ_VSI_PVLAN_INSERT_PVID |
  2617. I40E_AQ_VSI_PVLAN_EMOD_STR;
  2618. ctxt.seid = vsi->seid;
  2619. ctxt.info = vsi->info;
  2620. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2621. if (ret) {
  2622. dev_info(&vsi->back->pdev->dev,
  2623. "add pvid failed, err %s aq_err %s\n",
  2624. i40e_stat_str(&vsi->back->hw, ret),
  2625. i40e_aq_str(&vsi->back->hw,
  2626. vsi->back->hw.aq.asq_last_status));
  2627. return -ENOENT;
  2628. }
  2629. return 0;
  2630. }
  2631. /**
  2632. * i40e_vsi_remove_pvid - Remove the pvid from the VSI
  2633. * @vsi: the vsi being adjusted
  2634. *
  2635. * Just use the vlan_rx_register() service to put it back to normal
  2636. **/
  2637. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
  2638. {
  2639. i40e_vlan_stripping_disable(vsi);
  2640. vsi->info.pvid = 0;
  2641. }
  2642. /**
  2643. * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
  2644. * @vsi: ptr to the VSI
  2645. *
  2646. * If this function returns with an error, then it's possible one or
  2647. * more of the rings is populated (while the rest are not). It is the
  2648. * callers duty to clean those orphaned rings.
  2649. *
  2650. * Return 0 on success, negative on failure
  2651. **/
  2652. static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
  2653. {
  2654. int i, err = 0;
  2655. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2656. err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
  2657. if (!i40e_enabled_xdp_vsi(vsi))
  2658. return err;
  2659. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2660. err = i40e_setup_tx_descriptors(vsi->xdp_rings[i]);
  2661. return err;
  2662. }
  2663. /**
  2664. * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
  2665. * @vsi: ptr to the VSI
  2666. *
  2667. * Free VSI's transmit software resources
  2668. **/
  2669. static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
  2670. {
  2671. int i;
  2672. if (vsi->tx_rings) {
  2673. for (i = 0; i < vsi->num_queue_pairs; i++)
  2674. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
  2675. i40e_free_tx_resources(vsi->tx_rings[i]);
  2676. }
  2677. if (vsi->xdp_rings) {
  2678. for (i = 0; i < vsi->num_queue_pairs; i++)
  2679. if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
  2680. i40e_free_tx_resources(vsi->xdp_rings[i]);
  2681. }
  2682. }
  2683. /**
  2684. * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
  2685. * @vsi: ptr to the VSI
  2686. *
  2687. * If this function returns with an error, then it's possible one or
  2688. * more of the rings is populated (while the rest are not). It is the
  2689. * callers duty to clean those orphaned rings.
  2690. *
  2691. * Return 0 on success, negative on failure
  2692. **/
  2693. static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
  2694. {
  2695. int i, err = 0;
  2696. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2697. err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
  2698. return err;
  2699. }
  2700. /**
  2701. * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
  2702. * @vsi: ptr to the VSI
  2703. *
  2704. * Free all receive software resources
  2705. **/
  2706. static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
  2707. {
  2708. int i;
  2709. if (!vsi->rx_rings)
  2710. return;
  2711. for (i = 0; i < vsi->num_queue_pairs; i++)
  2712. if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
  2713. i40e_free_rx_resources(vsi->rx_rings[i]);
  2714. }
  2715. /**
  2716. * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
  2717. * @ring: The Tx ring to configure
  2718. *
  2719. * This enables/disables XPS for a given Tx descriptor ring
  2720. * based on the TCs enabled for the VSI that ring belongs to.
  2721. **/
  2722. static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
  2723. {
  2724. int cpu;
  2725. if (!ring->q_vector || !ring->netdev || ring->ch)
  2726. return;
  2727. /* We only initialize XPS once, so as not to overwrite user settings */
  2728. if (test_and_set_bit(__I40E_TX_XPS_INIT_DONE, ring->state))
  2729. return;
  2730. cpu = cpumask_local_spread(ring->q_vector->v_idx, -1);
  2731. netif_set_xps_queue(ring->netdev, get_cpu_mask(cpu),
  2732. ring->queue_index);
  2733. }
  2734. /**
  2735. * i40e_configure_tx_ring - Configure a transmit ring context and rest
  2736. * @ring: The Tx ring to configure
  2737. *
  2738. * Configure the Tx descriptor ring in the HMC context.
  2739. **/
  2740. static int i40e_configure_tx_ring(struct i40e_ring *ring)
  2741. {
  2742. struct i40e_vsi *vsi = ring->vsi;
  2743. u16 pf_q = vsi->base_queue + ring->queue_index;
  2744. struct i40e_hw *hw = &vsi->back->hw;
  2745. struct i40e_hmc_obj_txq tx_ctx;
  2746. i40e_status err = 0;
  2747. u32 qtx_ctl = 0;
  2748. /* some ATR related tx ring init */
  2749. if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
  2750. ring->atr_sample_rate = vsi->back->atr_sample_rate;
  2751. ring->atr_count = 0;
  2752. } else {
  2753. ring->atr_sample_rate = 0;
  2754. }
  2755. /* configure XPS */
  2756. i40e_config_xps_tx_ring(ring);
  2757. /* clear the context structure first */
  2758. memset(&tx_ctx, 0, sizeof(tx_ctx));
  2759. tx_ctx.new_context = 1;
  2760. tx_ctx.base = (ring->dma / 128);
  2761. tx_ctx.qlen = ring->count;
  2762. tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
  2763. I40E_FLAG_FD_ATR_ENABLED));
  2764. tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
  2765. /* FDIR VSI tx ring can still use RS bit and writebacks */
  2766. if (vsi->type != I40E_VSI_FDIR)
  2767. tx_ctx.head_wb_ena = 1;
  2768. tx_ctx.head_wb_addr = ring->dma +
  2769. (ring->count * sizeof(struct i40e_tx_desc));
  2770. /* As part of VSI creation/update, FW allocates certain
  2771. * Tx arbitration queue sets for each TC enabled for
  2772. * the VSI. The FW returns the handles to these queue
  2773. * sets as part of the response buffer to Add VSI,
  2774. * Update VSI, etc. AQ commands. It is expected that
  2775. * these queue set handles be associated with the Tx
  2776. * queues by the driver as part of the TX queue context
  2777. * initialization. This has to be done regardless of
  2778. * DCB as by default everything is mapped to TC0.
  2779. */
  2780. if (ring->ch)
  2781. tx_ctx.rdylist =
  2782. le16_to_cpu(ring->ch->info.qs_handle[ring->dcb_tc]);
  2783. else
  2784. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
  2785. tx_ctx.rdylist_act = 0;
  2786. /* clear the context in the HMC */
  2787. err = i40e_clear_lan_tx_queue_context(hw, pf_q);
  2788. if (err) {
  2789. dev_info(&vsi->back->pdev->dev,
  2790. "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
  2791. ring->queue_index, pf_q, err);
  2792. return -ENOMEM;
  2793. }
  2794. /* set the context in the HMC */
  2795. err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
  2796. if (err) {
  2797. dev_info(&vsi->back->pdev->dev,
  2798. "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
  2799. ring->queue_index, pf_q, err);
  2800. return -ENOMEM;
  2801. }
  2802. /* Now associate this queue with this PCI function */
  2803. if (ring->ch) {
  2804. if (ring->ch->type == I40E_VSI_VMDQ2)
  2805. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2806. else
  2807. return -EINVAL;
  2808. qtx_ctl |= (ring->ch->vsi_number <<
  2809. I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2810. I40E_QTX_CTL_VFVM_INDX_MASK;
  2811. } else {
  2812. if (vsi->type == I40E_VSI_VMDQ2) {
  2813. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2814. qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2815. I40E_QTX_CTL_VFVM_INDX_MASK;
  2816. } else {
  2817. qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
  2818. }
  2819. }
  2820. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
  2821. I40E_QTX_CTL_PF_INDX_MASK);
  2822. wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
  2823. i40e_flush(hw);
  2824. /* cache tail off for easier writes later */
  2825. ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
  2826. return 0;
  2827. }
  2828. /**
  2829. * i40e_configure_rx_ring - Configure a receive ring context
  2830. * @ring: The Rx ring to configure
  2831. *
  2832. * Configure the Rx descriptor ring in the HMC context.
  2833. **/
  2834. static int i40e_configure_rx_ring(struct i40e_ring *ring)
  2835. {
  2836. struct i40e_vsi *vsi = ring->vsi;
  2837. u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
  2838. u16 pf_q = vsi->base_queue + ring->queue_index;
  2839. struct i40e_hw *hw = &vsi->back->hw;
  2840. struct i40e_hmc_obj_rxq rx_ctx;
  2841. i40e_status err = 0;
  2842. bitmap_zero(ring->state, __I40E_RING_STATE_NBITS);
  2843. /* clear the context structure first */
  2844. memset(&rx_ctx, 0, sizeof(rx_ctx));
  2845. ring->rx_buf_len = vsi->rx_buf_len;
  2846. rx_ctx.dbuff = DIV_ROUND_UP(ring->rx_buf_len,
  2847. BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
  2848. rx_ctx.base = (ring->dma / 128);
  2849. rx_ctx.qlen = ring->count;
  2850. /* use 32 byte descriptors */
  2851. rx_ctx.dsize = 1;
  2852. /* descriptor type is always zero
  2853. * rx_ctx.dtype = 0;
  2854. */
  2855. rx_ctx.hsplit_0 = 0;
  2856. rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
  2857. if (hw->revision_id == 0)
  2858. rx_ctx.lrxqthresh = 0;
  2859. else
  2860. rx_ctx.lrxqthresh = 1;
  2861. rx_ctx.crcstrip = 1;
  2862. rx_ctx.l2tsel = 1;
  2863. /* this controls whether VLAN is stripped from inner headers */
  2864. rx_ctx.showiv = 0;
  2865. /* set the prefena field to 1 because the manual says to */
  2866. rx_ctx.prefena = 1;
  2867. /* clear the context in the HMC */
  2868. err = i40e_clear_lan_rx_queue_context(hw, pf_q);
  2869. if (err) {
  2870. dev_info(&vsi->back->pdev->dev,
  2871. "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2872. ring->queue_index, pf_q, err);
  2873. return -ENOMEM;
  2874. }
  2875. /* set the context in the HMC */
  2876. err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
  2877. if (err) {
  2878. dev_info(&vsi->back->pdev->dev,
  2879. "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2880. ring->queue_index, pf_q, err);
  2881. return -ENOMEM;
  2882. }
  2883. /* configure Rx buffer alignment */
  2884. if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
  2885. clear_ring_build_skb_enabled(ring);
  2886. else
  2887. set_ring_build_skb_enabled(ring);
  2888. /* cache tail for quicker writes, and clear the reg before use */
  2889. ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
  2890. writel(0, ring->tail);
  2891. i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
  2892. return 0;
  2893. }
  2894. /**
  2895. * i40e_vsi_configure_tx - Configure the VSI for Tx
  2896. * @vsi: VSI structure describing this set of rings and resources
  2897. *
  2898. * Configure the Tx VSI for operation.
  2899. **/
  2900. static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
  2901. {
  2902. int err = 0;
  2903. u16 i;
  2904. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2905. err = i40e_configure_tx_ring(vsi->tx_rings[i]);
  2906. if (!i40e_enabled_xdp_vsi(vsi))
  2907. return err;
  2908. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2909. err = i40e_configure_tx_ring(vsi->xdp_rings[i]);
  2910. return err;
  2911. }
  2912. /**
  2913. * i40e_vsi_configure_rx - Configure the VSI for Rx
  2914. * @vsi: the VSI being configured
  2915. *
  2916. * Configure the Rx VSI for operation.
  2917. **/
  2918. static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
  2919. {
  2920. int err = 0;
  2921. u16 i;
  2922. if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) {
  2923. vsi->max_frame = I40E_MAX_RXBUFFER;
  2924. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2925. #if (PAGE_SIZE < 8192)
  2926. } else if (!I40E_2K_TOO_SMALL_WITH_PADDING &&
  2927. (vsi->netdev->mtu <= ETH_DATA_LEN)) {
  2928. vsi->max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
  2929. vsi->rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
  2930. #endif
  2931. } else {
  2932. vsi->max_frame = I40E_MAX_RXBUFFER;
  2933. vsi->rx_buf_len = (PAGE_SIZE < 8192) ? I40E_RXBUFFER_3072 :
  2934. I40E_RXBUFFER_2048;
  2935. }
  2936. /* set up individual rings */
  2937. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2938. err = i40e_configure_rx_ring(vsi->rx_rings[i]);
  2939. return err;
  2940. }
  2941. /**
  2942. * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
  2943. * @vsi: ptr to the VSI
  2944. **/
  2945. static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
  2946. {
  2947. struct i40e_ring *tx_ring, *rx_ring;
  2948. u16 qoffset, qcount;
  2949. int i, n;
  2950. if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  2951. /* Reset the TC information */
  2952. for (i = 0; i < vsi->num_queue_pairs; i++) {
  2953. rx_ring = vsi->rx_rings[i];
  2954. tx_ring = vsi->tx_rings[i];
  2955. rx_ring->dcb_tc = 0;
  2956. tx_ring->dcb_tc = 0;
  2957. }
  2958. return;
  2959. }
  2960. for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
  2961. if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
  2962. continue;
  2963. qoffset = vsi->tc_config.tc_info[n].qoffset;
  2964. qcount = vsi->tc_config.tc_info[n].qcount;
  2965. for (i = qoffset; i < (qoffset + qcount); i++) {
  2966. rx_ring = vsi->rx_rings[i];
  2967. tx_ring = vsi->tx_rings[i];
  2968. rx_ring->dcb_tc = n;
  2969. tx_ring->dcb_tc = n;
  2970. }
  2971. }
  2972. }
  2973. /**
  2974. * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
  2975. * @vsi: ptr to the VSI
  2976. **/
  2977. static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
  2978. {
  2979. if (vsi->netdev)
  2980. i40e_set_rx_mode(vsi->netdev);
  2981. }
  2982. /**
  2983. * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
  2984. * @vsi: Pointer to the targeted VSI
  2985. *
  2986. * This function replays the hlist on the hw where all the SB Flow Director
  2987. * filters were saved.
  2988. **/
  2989. static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
  2990. {
  2991. struct i40e_fdir_filter *filter;
  2992. struct i40e_pf *pf = vsi->back;
  2993. struct hlist_node *node;
  2994. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  2995. return;
  2996. /* Reset FDir counters as we're replaying all existing filters */
  2997. pf->fd_tcp4_filter_cnt = 0;
  2998. pf->fd_udp4_filter_cnt = 0;
  2999. pf->fd_sctp4_filter_cnt = 0;
  3000. pf->fd_ip4_filter_cnt = 0;
  3001. hlist_for_each_entry_safe(filter, node,
  3002. &pf->fdir_filter_list, fdir_node) {
  3003. i40e_add_del_fdir(vsi, filter, true);
  3004. }
  3005. }
  3006. /**
  3007. * i40e_vsi_configure - Set up the VSI for action
  3008. * @vsi: the VSI being configured
  3009. **/
  3010. static int i40e_vsi_configure(struct i40e_vsi *vsi)
  3011. {
  3012. int err;
  3013. i40e_set_vsi_rx_mode(vsi);
  3014. i40e_restore_vlan(vsi);
  3015. i40e_vsi_config_dcb_rings(vsi);
  3016. err = i40e_vsi_configure_tx(vsi);
  3017. if (!err)
  3018. err = i40e_vsi_configure_rx(vsi);
  3019. return err;
  3020. }
  3021. /**
  3022. * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
  3023. * @vsi: the VSI being configured
  3024. **/
  3025. static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
  3026. {
  3027. bool has_xdp = i40e_enabled_xdp_vsi(vsi);
  3028. struct i40e_pf *pf = vsi->back;
  3029. struct i40e_hw *hw = &pf->hw;
  3030. u16 vector;
  3031. int i, q;
  3032. u32 qp;
  3033. /* The interrupt indexing is offset by 1 in the PFINT_ITRn
  3034. * and PFINT_LNKLSTn registers, e.g.:
  3035. * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
  3036. */
  3037. qp = vsi->base_queue;
  3038. vector = vsi->base_vector;
  3039. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  3040. struct i40e_q_vector *q_vector = vsi->q_vectors[i];
  3041. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  3042. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[i]->rx_itr_setting);
  3043. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  3044. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
  3045. q_vector->rx.itr);
  3046. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[i]->tx_itr_setting);
  3047. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  3048. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
  3049. q_vector->tx.itr);
  3050. wr32(hw, I40E_PFINT_RATEN(vector - 1),
  3051. i40e_intrl_usec_to_reg(vsi->int_rate_limit));
  3052. /* Linked list for the queuepairs assigned to this vector */
  3053. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
  3054. for (q = 0; q < q_vector->num_ringpairs; q++) {
  3055. u32 nextqp = has_xdp ? qp + vsi->alloc_queue_pairs : qp;
  3056. u32 val;
  3057. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3058. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  3059. (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
  3060. (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
  3061. (I40E_QUEUE_TYPE_TX <<
  3062. I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
  3063. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3064. if (has_xdp) {
  3065. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3066. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3067. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  3068. (qp << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
  3069. (I40E_QUEUE_TYPE_TX <<
  3070. I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3071. wr32(hw, I40E_QINT_TQCTL(nextqp), val);
  3072. }
  3073. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3074. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3075. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  3076. ((qp + 1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
  3077. (I40E_QUEUE_TYPE_RX <<
  3078. I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3079. /* Terminate the linked list */
  3080. if (q == (q_vector->num_ringpairs - 1))
  3081. val |= (I40E_QUEUE_END_OF_LIST <<
  3082. I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  3083. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3084. qp++;
  3085. }
  3086. }
  3087. i40e_flush(hw);
  3088. }
  3089. /**
  3090. * i40e_enable_misc_int_causes - enable the non-queue interrupts
  3091. * @hw: ptr to the hardware info
  3092. **/
  3093. static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
  3094. {
  3095. struct i40e_hw *hw = &pf->hw;
  3096. u32 val;
  3097. /* clear things first */
  3098. wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
  3099. rd32(hw, I40E_PFINT_ICR0); /* read to clear */
  3100. val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
  3101. I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
  3102. I40E_PFINT_ICR0_ENA_GRST_MASK |
  3103. I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
  3104. I40E_PFINT_ICR0_ENA_GPIO_MASK |
  3105. I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
  3106. I40E_PFINT_ICR0_ENA_VFLR_MASK |
  3107. I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3108. if (pf->flags & I40E_FLAG_IWARP_ENABLED)
  3109. val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3110. if (pf->flags & I40E_FLAG_PTP)
  3111. val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3112. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  3113. /* SW_ITR_IDX = 0, but don't change INTENA */
  3114. wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
  3115. I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
  3116. /* OTHER_ITR_IDX = 0 */
  3117. wr32(hw, I40E_PFINT_STAT_CTL0, 0);
  3118. }
  3119. /**
  3120. * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
  3121. * @vsi: the VSI being configured
  3122. **/
  3123. static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
  3124. {
  3125. u32 nextqp = i40e_enabled_xdp_vsi(vsi) ? vsi->alloc_queue_pairs : 0;
  3126. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3127. struct i40e_pf *pf = vsi->back;
  3128. struct i40e_hw *hw = &pf->hw;
  3129. u32 val;
  3130. /* set the ITR configuration */
  3131. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  3132. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting);
  3133. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  3134. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
  3135. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[0]->tx_itr_setting);
  3136. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  3137. wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
  3138. i40e_enable_misc_int_causes(pf);
  3139. /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
  3140. wr32(hw, I40E_PFINT_LNKLST0, 0);
  3141. /* Associate the queue pair to the vector and enable the queue int */
  3142. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3143. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  3144. (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
  3145. (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3146. wr32(hw, I40E_QINT_RQCTL(0), val);
  3147. if (i40e_enabled_xdp_vsi(vsi)) {
  3148. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3149. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT)|
  3150. (I40E_QUEUE_TYPE_TX
  3151. << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3152. wr32(hw, I40E_QINT_TQCTL(nextqp), val);
  3153. }
  3154. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3155. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3156. (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  3157. wr32(hw, I40E_QINT_TQCTL(0), val);
  3158. i40e_flush(hw);
  3159. }
  3160. /**
  3161. * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
  3162. * @pf: board private structure
  3163. **/
  3164. void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
  3165. {
  3166. struct i40e_hw *hw = &pf->hw;
  3167. wr32(hw, I40E_PFINT_DYN_CTL0,
  3168. I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  3169. i40e_flush(hw);
  3170. }
  3171. /**
  3172. * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
  3173. * @pf: board private structure
  3174. **/
  3175. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
  3176. {
  3177. struct i40e_hw *hw = &pf->hw;
  3178. u32 val;
  3179. val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
  3180. I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
  3181. (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
  3182. wr32(hw, I40E_PFINT_DYN_CTL0, val);
  3183. i40e_flush(hw);
  3184. }
  3185. /**
  3186. * i40e_msix_clean_rings - MSIX mode Interrupt Handler
  3187. * @irq: interrupt number
  3188. * @data: pointer to a q_vector
  3189. **/
  3190. static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
  3191. {
  3192. struct i40e_q_vector *q_vector = data;
  3193. if (!q_vector->tx.ring && !q_vector->rx.ring)
  3194. return IRQ_HANDLED;
  3195. napi_schedule_irqoff(&q_vector->napi);
  3196. return IRQ_HANDLED;
  3197. }
  3198. /**
  3199. * i40e_irq_affinity_notify - Callback for affinity changes
  3200. * @notify: context as to what irq was changed
  3201. * @mask: the new affinity mask
  3202. *
  3203. * This is a callback function used by the irq_set_affinity_notifier function
  3204. * so that we may register to receive changes to the irq affinity masks.
  3205. **/
  3206. static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify,
  3207. const cpumask_t *mask)
  3208. {
  3209. struct i40e_q_vector *q_vector =
  3210. container_of(notify, struct i40e_q_vector, affinity_notify);
  3211. cpumask_copy(&q_vector->affinity_mask, mask);
  3212. }
  3213. /**
  3214. * i40e_irq_affinity_release - Callback for affinity notifier release
  3215. * @ref: internal core kernel usage
  3216. *
  3217. * This is a callback function used by the irq_set_affinity_notifier function
  3218. * to inform the current notification subscriber that they will no longer
  3219. * receive notifications.
  3220. **/
  3221. static void i40e_irq_affinity_release(struct kref *ref) {}
  3222. /**
  3223. * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
  3224. * @vsi: the VSI being configured
  3225. * @basename: name for the vector
  3226. *
  3227. * Allocates MSI-X vectors and requests interrupts from the kernel.
  3228. **/
  3229. static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
  3230. {
  3231. int q_vectors = vsi->num_q_vectors;
  3232. struct i40e_pf *pf = vsi->back;
  3233. int base = vsi->base_vector;
  3234. int rx_int_idx = 0;
  3235. int tx_int_idx = 0;
  3236. int vector, err;
  3237. int irq_num;
  3238. int cpu;
  3239. for (vector = 0; vector < q_vectors; vector++) {
  3240. struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
  3241. irq_num = pf->msix_entries[base + vector].vector;
  3242. if (q_vector->tx.ring && q_vector->rx.ring) {
  3243. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3244. "%s-%s-%d", basename, "TxRx", rx_int_idx++);
  3245. tx_int_idx++;
  3246. } else if (q_vector->rx.ring) {
  3247. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3248. "%s-%s-%d", basename, "rx", rx_int_idx++);
  3249. } else if (q_vector->tx.ring) {
  3250. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3251. "%s-%s-%d", basename, "tx", tx_int_idx++);
  3252. } else {
  3253. /* skip this unused q_vector */
  3254. continue;
  3255. }
  3256. err = request_irq(irq_num,
  3257. vsi->irq_handler,
  3258. 0,
  3259. q_vector->name,
  3260. q_vector);
  3261. if (err) {
  3262. dev_info(&pf->pdev->dev,
  3263. "MSIX request_irq failed, error: %d\n", err);
  3264. goto free_queue_irqs;
  3265. }
  3266. /* register for affinity change notifications */
  3267. q_vector->affinity_notify.notify = i40e_irq_affinity_notify;
  3268. q_vector->affinity_notify.release = i40e_irq_affinity_release;
  3269. irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
  3270. /* Spread affinity hints out across online CPUs.
  3271. *
  3272. * get_cpu_mask returns a static constant mask with
  3273. * a permanent lifetime so it's ok to pass to
  3274. * irq_set_affinity_hint without making a copy.
  3275. */
  3276. cpu = cpumask_local_spread(q_vector->v_idx, -1);
  3277. irq_set_affinity_hint(irq_num, get_cpu_mask(cpu));
  3278. }
  3279. vsi->irqs_ready = true;
  3280. return 0;
  3281. free_queue_irqs:
  3282. while (vector) {
  3283. vector--;
  3284. irq_num = pf->msix_entries[base + vector].vector;
  3285. irq_set_affinity_notifier(irq_num, NULL);
  3286. irq_set_affinity_hint(irq_num, NULL);
  3287. free_irq(irq_num, &vsi->q_vectors[vector]);
  3288. }
  3289. return err;
  3290. }
  3291. /**
  3292. * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
  3293. * @vsi: the VSI being un-configured
  3294. **/
  3295. static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
  3296. {
  3297. struct i40e_pf *pf = vsi->back;
  3298. struct i40e_hw *hw = &pf->hw;
  3299. int base = vsi->base_vector;
  3300. int i;
  3301. /* disable interrupt causation from each queue */
  3302. for (i = 0; i < vsi->num_queue_pairs; i++) {
  3303. u32 val;
  3304. val = rd32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx));
  3305. val &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
  3306. wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), val);
  3307. val = rd32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx));
  3308. val &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
  3309. wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), val);
  3310. if (!i40e_enabled_xdp_vsi(vsi))
  3311. continue;
  3312. wr32(hw, I40E_QINT_TQCTL(vsi->xdp_rings[i]->reg_idx), 0);
  3313. }
  3314. /* disable each interrupt */
  3315. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3316. for (i = vsi->base_vector;
  3317. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  3318. wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
  3319. i40e_flush(hw);
  3320. for (i = 0; i < vsi->num_q_vectors; i++)
  3321. synchronize_irq(pf->msix_entries[i + base].vector);
  3322. } else {
  3323. /* Legacy and MSI mode - this stops all interrupt handling */
  3324. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  3325. wr32(hw, I40E_PFINT_DYN_CTL0, 0);
  3326. i40e_flush(hw);
  3327. synchronize_irq(pf->pdev->irq);
  3328. }
  3329. }
  3330. /**
  3331. * i40e_vsi_enable_irq - Enable IRQ for the given VSI
  3332. * @vsi: the VSI being configured
  3333. **/
  3334. static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
  3335. {
  3336. struct i40e_pf *pf = vsi->back;
  3337. int i;
  3338. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3339. for (i = 0; i < vsi->num_q_vectors; i++)
  3340. i40e_irq_dynamic_enable(vsi, i);
  3341. } else {
  3342. i40e_irq_dynamic_enable_icr0(pf);
  3343. }
  3344. i40e_flush(&pf->hw);
  3345. return 0;
  3346. }
  3347. /**
  3348. * i40e_free_misc_vector - Free the vector that handles non-queue events
  3349. * @pf: board private structure
  3350. **/
  3351. static void i40e_free_misc_vector(struct i40e_pf *pf)
  3352. {
  3353. /* Disable ICR 0 */
  3354. wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
  3355. i40e_flush(&pf->hw);
  3356. if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
  3357. synchronize_irq(pf->msix_entries[0].vector);
  3358. free_irq(pf->msix_entries[0].vector, pf);
  3359. clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state);
  3360. }
  3361. }
  3362. /**
  3363. * i40e_intr - MSI/Legacy and non-queue interrupt handler
  3364. * @irq: interrupt number
  3365. * @data: pointer to a q_vector
  3366. *
  3367. * This is the handler used for all MSI/Legacy interrupts, and deals
  3368. * with both queue and non-queue interrupts. This is also used in
  3369. * MSIX mode to handle the non-queue interrupts.
  3370. **/
  3371. static irqreturn_t i40e_intr(int irq, void *data)
  3372. {
  3373. struct i40e_pf *pf = (struct i40e_pf *)data;
  3374. struct i40e_hw *hw = &pf->hw;
  3375. irqreturn_t ret = IRQ_NONE;
  3376. u32 icr0, icr0_remaining;
  3377. u32 val, ena_mask;
  3378. icr0 = rd32(hw, I40E_PFINT_ICR0);
  3379. ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
  3380. /* if sharing a legacy IRQ, we might get called w/o an intr pending */
  3381. if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
  3382. goto enable_intr;
  3383. /* if interrupt but no bits showing, must be SWINT */
  3384. if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
  3385. (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
  3386. pf->sw_int_count++;
  3387. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  3388. (icr0 & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
  3389. ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3390. dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n");
  3391. set_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
  3392. }
  3393. /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
  3394. if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
  3395. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  3396. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3397. /* We do not have a way to disarm Queue causes while leaving
  3398. * interrupt enabled for all other causes, ideally
  3399. * interrupt should be disabled while we are in NAPI but
  3400. * this is not a performance path and napi_schedule()
  3401. * can deal with rescheduling.
  3402. */
  3403. if (!test_bit(__I40E_DOWN, pf->state))
  3404. napi_schedule_irqoff(&q_vector->napi);
  3405. }
  3406. if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
  3407. ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3408. set_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
  3409. i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
  3410. }
  3411. if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
  3412. ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  3413. set_bit(__I40E_MDD_EVENT_PENDING, pf->state);
  3414. }
  3415. if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
  3416. ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
  3417. set_bit(__I40E_VFLR_EVENT_PENDING, pf->state);
  3418. }
  3419. if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
  3420. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  3421. set_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
  3422. ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
  3423. val = rd32(hw, I40E_GLGEN_RSTAT);
  3424. val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
  3425. >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
  3426. if (val == I40E_RESET_CORER) {
  3427. pf->corer_count++;
  3428. } else if (val == I40E_RESET_GLOBR) {
  3429. pf->globr_count++;
  3430. } else if (val == I40E_RESET_EMPR) {
  3431. pf->empr_count++;
  3432. set_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state);
  3433. }
  3434. }
  3435. if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
  3436. icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
  3437. dev_info(&pf->pdev->dev, "HMC error interrupt\n");
  3438. dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
  3439. rd32(hw, I40E_PFHMC_ERRORINFO),
  3440. rd32(hw, I40E_PFHMC_ERRORDATA));
  3441. }
  3442. if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
  3443. u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
  3444. if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
  3445. icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3446. i40e_ptp_tx_hwtstamp(pf);
  3447. }
  3448. }
  3449. /* If a critical error is pending we have no choice but to reset the
  3450. * device.
  3451. * Report and mask out any remaining unexpected interrupts.
  3452. */
  3453. icr0_remaining = icr0 & ena_mask;
  3454. if (icr0_remaining) {
  3455. dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
  3456. icr0_remaining);
  3457. if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
  3458. (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
  3459. (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
  3460. dev_info(&pf->pdev->dev, "device will be reset\n");
  3461. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  3462. i40e_service_event_schedule(pf);
  3463. }
  3464. ena_mask &= ~icr0_remaining;
  3465. }
  3466. ret = IRQ_HANDLED;
  3467. enable_intr:
  3468. /* re-enable interrupt causes */
  3469. wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
  3470. if (!test_bit(__I40E_DOWN, pf->state)) {
  3471. i40e_service_event_schedule(pf);
  3472. i40e_irq_dynamic_enable_icr0(pf);
  3473. }
  3474. return ret;
  3475. }
  3476. /**
  3477. * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
  3478. * @tx_ring: tx ring to clean
  3479. * @budget: how many cleans we're allowed
  3480. *
  3481. * Returns true if there's any budget left (e.g. the clean is finished)
  3482. **/
  3483. static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
  3484. {
  3485. struct i40e_vsi *vsi = tx_ring->vsi;
  3486. u16 i = tx_ring->next_to_clean;
  3487. struct i40e_tx_buffer *tx_buf;
  3488. struct i40e_tx_desc *tx_desc;
  3489. tx_buf = &tx_ring->tx_bi[i];
  3490. tx_desc = I40E_TX_DESC(tx_ring, i);
  3491. i -= tx_ring->count;
  3492. do {
  3493. struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
  3494. /* if next_to_watch is not set then there is no work pending */
  3495. if (!eop_desc)
  3496. break;
  3497. /* prevent any other reads prior to eop_desc */
  3498. read_barrier_depends();
  3499. /* if the descriptor isn't done, no work yet to do */
  3500. if (!(eop_desc->cmd_type_offset_bsz &
  3501. cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
  3502. break;
  3503. /* clear next_to_watch to prevent false hangs */
  3504. tx_buf->next_to_watch = NULL;
  3505. tx_desc->buffer_addr = 0;
  3506. tx_desc->cmd_type_offset_bsz = 0;
  3507. /* move past filter desc */
  3508. tx_buf++;
  3509. tx_desc++;
  3510. i++;
  3511. if (unlikely(!i)) {
  3512. i -= tx_ring->count;
  3513. tx_buf = tx_ring->tx_bi;
  3514. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3515. }
  3516. /* unmap skb header data */
  3517. dma_unmap_single(tx_ring->dev,
  3518. dma_unmap_addr(tx_buf, dma),
  3519. dma_unmap_len(tx_buf, len),
  3520. DMA_TO_DEVICE);
  3521. if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
  3522. kfree(tx_buf->raw_buf);
  3523. tx_buf->raw_buf = NULL;
  3524. tx_buf->tx_flags = 0;
  3525. tx_buf->next_to_watch = NULL;
  3526. dma_unmap_len_set(tx_buf, len, 0);
  3527. tx_desc->buffer_addr = 0;
  3528. tx_desc->cmd_type_offset_bsz = 0;
  3529. /* move us past the eop_desc for start of next FD desc */
  3530. tx_buf++;
  3531. tx_desc++;
  3532. i++;
  3533. if (unlikely(!i)) {
  3534. i -= tx_ring->count;
  3535. tx_buf = tx_ring->tx_bi;
  3536. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3537. }
  3538. /* update budget accounting */
  3539. budget--;
  3540. } while (likely(budget));
  3541. i += tx_ring->count;
  3542. tx_ring->next_to_clean = i;
  3543. if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
  3544. i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
  3545. return budget > 0;
  3546. }
  3547. /**
  3548. * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
  3549. * @irq: interrupt number
  3550. * @data: pointer to a q_vector
  3551. **/
  3552. static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
  3553. {
  3554. struct i40e_q_vector *q_vector = data;
  3555. struct i40e_vsi *vsi;
  3556. if (!q_vector->tx.ring)
  3557. return IRQ_HANDLED;
  3558. vsi = q_vector->tx.ring->vsi;
  3559. i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
  3560. return IRQ_HANDLED;
  3561. }
  3562. /**
  3563. * i40e_map_vector_to_qp - Assigns the queue pair to the vector
  3564. * @vsi: the VSI being configured
  3565. * @v_idx: vector index
  3566. * @qp_idx: queue pair index
  3567. **/
  3568. static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
  3569. {
  3570. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3571. struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
  3572. struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
  3573. tx_ring->q_vector = q_vector;
  3574. tx_ring->next = q_vector->tx.ring;
  3575. q_vector->tx.ring = tx_ring;
  3576. q_vector->tx.count++;
  3577. /* Place XDP Tx ring in the same q_vector ring list as regular Tx */
  3578. if (i40e_enabled_xdp_vsi(vsi)) {
  3579. struct i40e_ring *xdp_ring = vsi->xdp_rings[qp_idx];
  3580. xdp_ring->q_vector = q_vector;
  3581. xdp_ring->next = q_vector->tx.ring;
  3582. q_vector->tx.ring = xdp_ring;
  3583. q_vector->tx.count++;
  3584. }
  3585. rx_ring->q_vector = q_vector;
  3586. rx_ring->next = q_vector->rx.ring;
  3587. q_vector->rx.ring = rx_ring;
  3588. q_vector->rx.count++;
  3589. }
  3590. /**
  3591. * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
  3592. * @vsi: the VSI being configured
  3593. *
  3594. * This function maps descriptor rings to the queue-specific vectors
  3595. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  3596. * one vector per queue pair, but on a constrained vector budget, we
  3597. * group the queue pairs as "efficiently" as possible.
  3598. **/
  3599. static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
  3600. {
  3601. int qp_remaining = vsi->num_queue_pairs;
  3602. int q_vectors = vsi->num_q_vectors;
  3603. int num_ringpairs;
  3604. int v_start = 0;
  3605. int qp_idx = 0;
  3606. /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
  3607. * group them so there are multiple queues per vector.
  3608. * It is also important to go through all the vectors available to be
  3609. * sure that if we don't use all the vectors, that the remaining vectors
  3610. * are cleared. This is especially important when decreasing the
  3611. * number of queues in use.
  3612. */
  3613. for (; v_start < q_vectors; v_start++) {
  3614. struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
  3615. num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
  3616. q_vector->num_ringpairs = num_ringpairs;
  3617. q_vector->rx.count = 0;
  3618. q_vector->tx.count = 0;
  3619. q_vector->rx.ring = NULL;
  3620. q_vector->tx.ring = NULL;
  3621. while (num_ringpairs--) {
  3622. i40e_map_vector_to_qp(vsi, v_start, qp_idx);
  3623. qp_idx++;
  3624. qp_remaining--;
  3625. }
  3626. }
  3627. }
  3628. /**
  3629. * i40e_vsi_request_irq - Request IRQ from the OS
  3630. * @vsi: the VSI being configured
  3631. * @basename: name for the vector
  3632. **/
  3633. static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
  3634. {
  3635. struct i40e_pf *pf = vsi->back;
  3636. int err;
  3637. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3638. err = i40e_vsi_request_irq_msix(vsi, basename);
  3639. else if (pf->flags & I40E_FLAG_MSI_ENABLED)
  3640. err = request_irq(pf->pdev->irq, i40e_intr, 0,
  3641. pf->int_name, pf);
  3642. else
  3643. err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
  3644. pf->int_name, pf);
  3645. if (err)
  3646. dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
  3647. return err;
  3648. }
  3649. #ifdef CONFIG_NET_POLL_CONTROLLER
  3650. /**
  3651. * i40e_netpoll - A Polling 'interrupt' handler
  3652. * @netdev: network interface device structure
  3653. *
  3654. * This is used by netconsole to send skbs without having to re-enable
  3655. * interrupts. It's not called while the normal interrupt routine is executing.
  3656. **/
  3657. static void i40e_netpoll(struct net_device *netdev)
  3658. {
  3659. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3660. struct i40e_vsi *vsi = np->vsi;
  3661. struct i40e_pf *pf = vsi->back;
  3662. int i;
  3663. /* if interface is down do nothing */
  3664. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  3665. return;
  3666. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3667. for (i = 0; i < vsi->num_q_vectors; i++)
  3668. i40e_msix_clean_rings(0, vsi->q_vectors[i]);
  3669. } else {
  3670. i40e_intr(pf->pdev->irq, netdev);
  3671. }
  3672. }
  3673. #endif
  3674. #define I40E_QTX_ENA_WAIT_COUNT 50
  3675. /**
  3676. * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
  3677. * @pf: the PF being configured
  3678. * @pf_q: the PF queue
  3679. * @enable: enable or disable state of the queue
  3680. *
  3681. * This routine will wait for the given Tx queue of the PF to reach the
  3682. * enabled or disabled state.
  3683. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3684. * multiple retries; else will return 0 in case of success.
  3685. **/
  3686. static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3687. {
  3688. int i;
  3689. u32 tx_reg;
  3690. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3691. tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
  3692. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3693. break;
  3694. usleep_range(10, 20);
  3695. }
  3696. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3697. return -ETIMEDOUT;
  3698. return 0;
  3699. }
  3700. /**
  3701. * i40e_control_tx_q - Start or stop a particular Tx queue
  3702. * @pf: the PF structure
  3703. * @pf_q: the PF queue to configure
  3704. * @enable: start or stop the queue
  3705. *
  3706. * This function enables or disables a single queue. Note that any delay
  3707. * required after the operation is expected to be handled by the caller of
  3708. * this function.
  3709. **/
  3710. static void i40e_control_tx_q(struct i40e_pf *pf, int pf_q, bool enable)
  3711. {
  3712. struct i40e_hw *hw = &pf->hw;
  3713. u32 tx_reg;
  3714. int i;
  3715. /* warn the TX unit of coming changes */
  3716. i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
  3717. if (!enable)
  3718. usleep_range(10, 20);
  3719. for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
  3720. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  3721. if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
  3722. ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
  3723. break;
  3724. usleep_range(1000, 2000);
  3725. }
  3726. /* Skip if the queue is already in the requested state */
  3727. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3728. return;
  3729. /* turn on/off the queue */
  3730. if (enable) {
  3731. wr32(hw, I40E_QTX_HEAD(pf_q), 0);
  3732. tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
  3733. } else {
  3734. tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
  3735. }
  3736. wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
  3737. }
  3738. /**
  3739. * i40e_control_wait_tx_q - Start/stop Tx queue and wait for completion
  3740. * @seid: VSI SEID
  3741. * @pf: the PF structure
  3742. * @pf_q: the PF queue to configure
  3743. * @is_xdp: true if the queue is used for XDP
  3744. * @enable: start or stop the queue
  3745. **/
  3746. static int i40e_control_wait_tx_q(int seid, struct i40e_pf *pf, int pf_q,
  3747. bool is_xdp, bool enable)
  3748. {
  3749. int ret;
  3750. i40e_control_tx_q(pf, pf_q, enable);
  3751. /* wait for the change to finish */
  3752. ret = i40e_pf_txq_wait(pf, pf_q, enable);
  3753. if (ret) {
  3754. dev_info(&pf->pdev->dev,
  3755. "VSI seid %d %sTx ring %d %sable timeout\n",
  3756. seid, (is_xdp ? "XDP " : ""), pf_q,
  3757. (enable ? "en" : "dis"));
  3758. }
  3759. return ret;
  3760. }
  3761. /**
  3762. * i40e_vsi_control_tx - Start or stop a VSI's rings
  3763. * @vsi: the VSI being configured
  3764. * @enable: start or stop the rings
  3765. **/
  3766. static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
  3767. {
  3768. struct i40e_pf *pf = vsi->back;
  3769. int i, pf_q, ret = 0;
  3770. pf_q = vsi->base_queue;
  3771. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3772. ret = i40e_control_wait_tx_q(vsi->seid, pf,
  3773. pf_q,
  3774. false /*is xdp*/, enable);
  3775. if (ret)
  3776. break;
  3777. if (!i40e_enabled_xdp_vsi(vsi))
  3778. continue;
  3779. ret = i40e_control_wait_tx_q(vsi->seid, pf,
  3780. pf_q + vsi->alloc_queue_pairs,
  3781. true /*is xdp*/, enable);
  3782. if (ret)
  3783. break;
  3784. }
  3785. return ret;
  3786. }
  3787. /**
  3788. * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
  3789. * @pf: the PF being configured
  3790. * @pf_q: the PF queue
  3791. * @enable: enable or disable state of the queue
  3792. *
  3793. * This routine will wait for the given Rx queue of the PF to reach the
  3794. * enabled or disabled state.
  3795. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3796. * multiple retries; else will return 0 in case of success.
  3797. **/
  3798. static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3799. {
  3800. int i;
  3801. u32 rx_reg;
  3802. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3803. rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
  3804. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3805. break;
  3806. usleep_range(10, 20);
  3807. }
  3808. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3809. return -ETIMEDOUT;
  3810. return 0;
  3811. }
  3812. /**
  3813. * i40e_control_rx_q - Start or stop a particular Rx queue
  3814. * @pf: the PF structure
  3815. * @pf_q: the PF queue to configure
  3816. * @enable: start or stop the queue
  3817. *
  3818. * This function enables or disables a single queue. Note that any delay
  3819. * required after the operation is expected to be handled by the caller of
  3820. * this function.
  3821. **/
  3822. static void i40e_control_rx_q(struct i40e_pf *pf, int pf_q, bool enable)
  3823. {
  3824. struct i40e_hw *hw = &pf->hw;
  3825. u32 rx_reg;
  3826. int i;
  3827. for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
  3828. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  3829. if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
  3830. ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
  3831. break;
  3832. usleep_range(1000, 2000);
  3833. }
  3834. /* Skip if the queue is already in the requested state */
  3835. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3836. return;
  3837. /* turn on/off the queue */
  3838. if (enable)
  3839. rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
  3840. else
  3841. rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
  3842. wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
  3843. }
  3844. /**
  3845. * i40e_vsi_control_rx - Start or stop a VSI's rings
  3846. * @vsi: the VSI being configured
  3847. * @enable: start or stop the rings
  3848. **/
  3849. static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
  3850. {
  3851. struct i40e_pf *pf = vsi->back;
  3852. int i, pf_q, ret = 0;
  3853. pf_q = vsi->base_queue;
  3854. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3855. i40e_control_rx_q(pf, pf_q, enable);
  3856. /* wait for the change to finish */
  3857. ret = i40e_pf_rxq_wait(pf, pf_q, enable);
  3858. if (ret) {
  3859. dev_info(&pf->pdev->dev,
  3860. "VSI seid %d Rx ring %d %sable timeout\n",
  3861. vsi->seid, pf_q, (enable ? "en" : "dis"));
  3862. break;
  3863. }
  3864. }
  3865. /* Due to HW errata, on Rx disable only, the register can indicate done
  3866. * before it really is. Needs 50ms to be sure
  3867. */
  3868. if (!enable)
  3869. mdelay(50);
  3870. return ret;
  3871. }
  3872. /**
  3873. * i40e_vsi_start_rings - Start a VSI's rings
  3874. * @vsi: the VSI being configured
  3875. **/
  3876. int i40e_vsi_start_rings(struct i40e_vsi *vsi)
  3877. {
  3878. int ret = 0;
  3879. /* do rx first for enable and last for disable */
  3880. ret = i40e_vsi_control_rx(vsi, true);
  3881. if (ret)
  3882. return ret;
  3883. ret = i40e_vsi_control_tx(vsi, true);
  3884. return ret;
  3885. }
  3886. /**
  3887. * i40e_vsi_stop_rings - Stop a VSI's rings
  3888. * @vsi: the VSI being configured
  3889. **/
  3890. void i40e_vsi_stop_rings(struct i40e_vsi *vsi)
  3891. {
  3892. /* When port TX is suspended, don't wait */
  3893. if (test_bit(__I40E_PORT_SUSPENDED, vsi->back->state))
  3894. return i40e_vsi_stop_rings_no_wait(vsi);
  3895. /* do rx first for enable and last for disable
  3896. * Ignore return value, we need to shutdown whatever we can
  3897. */
  3898. i40e_vsi_control_tx(vsi, false);
  3899. i40e_vsi_control_rx(vsi, false);
  3900. }
  3901. /**
  3902. * i40e_vsi_stop_rings_no_wait - Stop a VSI's rings and do not delay
  3903. * @vsi: the VSI being shutdown
  3904. *
  3905. * This function stops all the rings for a VSI but does not delay to verify
  3906. * that rings have been disabled. It is expected that the caller is shutting
  3907. * down multiple VSIs at once and will delay together for all the VSIs after
  3908. * initiating the shutdown. This is particularly useful for shutting down lots
  3909. * of VFs together. Otherwise, a large delay can be incurred while configuring
  3910. * each VSI in serial.
  3911. **/
  3912. void i40e_vsi_stop_rings_no_wait(struct i40e_vsi *vsi)
  3913. {
  3914. struct i40e_pf *pf = vsi->back;
  3915. int i, pf_q;
  3916. pf_q = vsi->base_queue;
  3917. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3918. i40e_control_tx_q(pf, pf_q, false);
  3919. i40e_control_rx_q(pf, pf_q, false);
  3920. }
  3921. }
  3922. /**
  3923. * i40e_vsi_free_irq - Free the irq association with the OS
  3924. * @vsi: the VSI being configured
  3925. **/
  3926. static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
  3927. {
  3928. struct i40e_pf *pf = vsi->back;
  3929. struct i40e_hw *hw = &pf->hw;
  3930. int base = vsi->base_vector;
  3931. u32 val, qp;
  3932. int i;
  3933. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3934. if (!vsi->q_vectors)
  3935. return;
  3936. if (!vsi->irqs_ready)
  3937. return;
  3938. vsi->irqs_ready = false;
  3939. for (i = 0; i < vsi->num_q_vectors; i++) {
  3940. int irq_num;
  3941. u16 vector;
  3942. vector = i + base;
  3943. irq_num = pf->msix_entries[vector].vector;
  3944. /* free only the irqs that were actually requested */
  3945. if (!vsi->q_vectors[i] ||
  3946. !vsi->q_vectors[i]->num_ringpairs)
  3947. continue;
  3948. /* clear the affinity notifier in the IRQ descriptor */
  3949. irq_set_affinity_notifier(irq_num, NULL);
  3950. /* remove our suggested affinity mask for this IRQ */
  3951. irq_set_affinity_hint(irq_num, NULL);
  3952. synchronize_irq(irq_num);
  3953. free_irq(irq_num, vsi->q_vectors[i]);
  3954. /* Tear down the interrupt queue link list
  3955. *
  3956. * We know that they come in pairs and always
  3957. * the Rx first, then the Tx. To clear the
  3958. * link list, stick the EOL value into the
  3959. * next_q field of the registers.
  3960. */
  3961. val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
  3962. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3963. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3964. val |= I40E_QUEUE_END_OF_LIST
  3965. << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3966. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
  3967. while (qp != I40E_QUEUE_END_OF_LIST) {
  3968. u32 next;
  3969. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3970. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3971. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3972. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3973. I40E_QINT_RQCTL_INTEVENT_MASK);
  3974. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3975. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3976. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3977. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3978. next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
  3979. >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
  3980. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3981. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3982. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3983. I40E_QINT_TQCTL_INTEVENT_MASK);
  3984. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3985. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3986. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3987. qp = next;
  3988. }
  3989. }
  3990. } else {
  3991. free_irq(pf->pdev->irq, pf);
  3992. val = rd32(hw, I40E_PFINT_LNKLST0);
  3993. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3994. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3995. val |= I40E_QUEUE_END_OF_LIST
  3996. << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  3997. wr32(hw, I40E_PFINT_LNKLST0, val);
  3998. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3999. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  4000. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  4001. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  4002. I40E_QINT_RQCTL_INTEVENT_MASK);
  4003. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  4004. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  4005. wr32(hw, I40E_QINT_RQCTL(qp), val);
  4006. val = rd32(hw, I40E_QINT_TQCTL(qp));
  4007. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  4008. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  4009. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  4010. I40E_QINT_TQCTL_INTEVENT_MASK);
  4011. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  4012. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  4013. wr32(hw, I40E_QINT_TQCTL(qp), val);
  4014. }
  4015. }
  4016. /**
  4017. * i40e_free_q_vector - Free memory allocated for specific interrupt vector
  4018. * @vsi: the VSI being configured
  4019. * @v_idx: Index of vector to be freed
  4020. *
  4021. * This function frees the memory allocated to the q_vector. In addition if
  4022. * NAPI is enabled it will delete any references to the NAPI struct prior
  4023. * to freeing the q_vector.
  4024. **/
  4025. static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
  4026. {
  4027. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  4028. struct i40e_ring *ring;
  4029. if (!q_vector)
  4030. return;
  4031. /* disassociate q_vector from rings */
  4032. i40e_for_each_ring(ring, q_vector->tx)
  4033. ring->q_vector = NULL;
  4034. i40e_for_each_ring(ring, q_vector->rx)
  4035. ring->q_vector = NULL;
  4036. /* only VSI w/ an associated netdev is set up w/ NAPI */
  4037. if (vsi->netdev)
  4038. netif_napi_del(&q_vector->napi);
  4039. vsi->q_vectors[v_idx] = NULL;
  4040. kfree_rcu(q_vector, rcu);
  4041. }
  4042. /**
  4043. * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
  4044. * @vsi: the VSI being un-configured
  4045. *
  4046. * This frees the memory allocated to the q_vectors and
  4047. * deletes references to the NAPI struct.
  4048. **/
  4049. static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
  4050. {
  4051. int v_idx;
  4052. for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
  4053. i40e_free_q_vector(vsi, v_idx);
  4054. }
  4055. /**
  4056. * i40e_reset_interrupt_capability - Disable interrupt setup in OS
  4057. * @pf: board private structure
  4058. **/
  4059. static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
  4060. {
  4061. /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
  4062. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  4063. pci_disable_msix(pf->pdev);
  4064. kfree(pf->msix_entries);
  4065. pf->msix_entries = NULL;
  4066. kfree(pf->irq_pile);
  4067. pf->irq_pile = NULL;
  4068. } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
  4069. pci_disable_msi(pf->pdev);
  4070. }
  4071. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  4072. }
  4073. /**
  4074. * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
  4075. * @pf: board private structure
  4076. *
  4077. * We go through and clear interrupt specific resources and reset the structure
  4078. * to pre-load conditions
  4079. **/
  4080. static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
  4081. {
  4082. int i;
  4083. i40e_free_misc_vector(pf);
  4084. i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
  4085. I40E_IWARP_IRQ_PILE_ID);
  4086. i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
  4087. for (i = 0; i < pf->num_alloc_vsi; i++)
  4088. if (pf->vsi[i])
  4089. i40e_vsi_free_q_vectors(pf->vsi[i]);
  4090. i40e_reset_interrupt_capability(pf);
  4091. }
  4092. /**
  4093. * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
  4094. * @vsi: the VSI being configured
  4095. **/
  4096. static void i40e_napi_enable_all(struct i40e_vsi *vsi)
  4097. {
  4098. int q_idx;
  4099. if (!vsi->netdev)
  4100. return;
  4101. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
  4102. struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
  4103. if (q_vector->rx.ring || q_vector->tx.ring)
  4104. napi_enable(&q_vector->napi);
  4105. }
  4106. }
  4107. /**
  4108. * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
  4109. * @vsi: the VSI being configured
  4110. **/
  4111. static void i40e_napi_disable_all(struct i40e_vsi *vsi)
  4112. {
  4113. int q_idx;
  4114. if (!vsi->netdev)
  4115. return;
  4116. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
  4117. struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
  4118. if (q_vector->rx.ring || q_vector->tx.ring)
  4119. napi_disable(&q_vector->napi);
  4120. }
  4121. }
  4122. /**
  4123. * i40e_vsi_close - Shut down a VSI
  4124. * @vsi: the vsi to be quelled
  4125. **/
  4126. static void i40e_vsi_close(struct i40e_vsi *vsi)
  4127. {
  4128. struct i40e_pf *pf = vsi->back;
  4129. if (!test_and_set_bit(__I40E_VSI_DOWN, vsi->state))
  4130. i40e_down(vsi);
  4131. i40e_vsi_free_irq(vsi);
  4132. i40e_vsi_free_tx_resources(vsi);
  4133. i40e_vsi_free_rx_resources(vsi);
  4134. vsi->current_netdev_flags = 0;
  4135. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  4136. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  4137. pf->flags |= I40E_FLAG_CLIENT_RESET;
  4138. }
  4139. /**
  4140. * i40e_quiesce_vsi - Pause a given VSI
  4141. * @vsi: the VSI being paused
  4142. **/
  4143. static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
  4144. {
  4145. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  4146. return;
  4147. set_bit(__I40E_VSI_NEEDS_RESTART, vsi->state);
  4148. if (vsi->netdev && netif_running(vsi->netdev))
  4149. vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
  4150. else
  4151. i40e_vsi_close(vsi);
  4152. }
  4153. /**
  4154. * i40e_unquiesce_vsi - Resume a given VSI
  4155. * @vsi: the VSI being resumed
  4156. **/
  4157. static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
  4158. {
  4159. if (!test_and_clear_bit(__I40E_VSI_NEEDS_RESTART, vsi->state))
  4160. return;
  4161. if (vsi->netdev && netif_running(vsi->netdev))
  4162. vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
  4163. else
  4164. i40e_vsi_open(vsi); /* this clears the DOWN bit */
  4165. }
  4166. /**
  4167. * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
  4168. * @pf: the PF
  4169. **/
  4170. static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
  4171. {
  4172. int v;
  4173. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4174. if (pf->vsi[v])
  4175. i40e_quiesce_vsi(pf->vsi[v]);
  4176. }
  4177. }
  4178. /**
  4179. * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
  4180. * @pf: the PF
  4181. **/
  4182. static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
  4183. {
  4184. int v;
  4185. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4186. if (pf->vsi[v])
  4187. i40e_unquiesce_vsi(pf->vsi[v]);
  4188. }
  4189. }
  4190. /**
  4191. * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
  4192. * @vsi: the VSI being configured
  4193. *
  4194. * Wait until all queues on a given VSI have been disabled.
  4195. **/
  4196. int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
  4197. {
  4198. struct i40e_pf *pf = vsi->back;
  4199. int i, pf_q, ret;
  4200. pf_q = vsi->base_queue;
  4201. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  4202. /* Check and wait for the Tx queue */
  4203. ret = i40e_pf_txq_wait(pf, pf_q, false);
  4204. if (ret) {
  4205. dev_info(&pf->pdev->dev,
  4206. "VSI seid %d Tx ring %d disable timeout\n",
  4207. vsi->seid, pf_q);
  4208. return ret;
  4209. }
  4210. if (!i40e_enabled_xdp_vsi(vsi))
  4211. goto wait_rx;
  4212. /* Check and wait for the XDP Tx queue */
  4213. ret = i40e_pf_txq_wait(pf, pf_q + vsi->alloc_queue_pairs,
  4214. false);
  4215. if (ret) {
  4216. dev_info(&pf->pdev->dev,
  4217. "VSI seid %d XDP Tx ring %d disable timeout\n",
  4218. vsi->seid, pf_q);
  4219. return ret;
  4220. }
  4221. wait_rx:
  4222. /* Check and wait for the Rx queue */
  4223. ret = i40e_pf_rxq_wait(pf, pf_q, false);
  4224. if (ret) {
  4225. dev_info(&pf->pdev->dev,
  4226. "VSI seid %d Rx ring %d disable timeout\n",
  4227. vsi->seid, pf_q);
  4228. return ret;
  4229. }
  4230. }
  4231. return 0;
  4232. }
  4233. #ifdef CONFIG_I40E_DCB
  4234. /**
  4235. * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
  4236. * @pf: the PF
  4237. *
  4238. * This function waits for the queues to be in disabled state for all the
  4239. * VSIs that are managed by this PF.
  4240. **/
  4241. static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
  4242. {
  4243. int v, ret = 0;
  4244. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  4245. if (pf->vsi[v]) {
  4246. ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
  4247. if (ret)
  4248. break;
  4249. }
  4250. }
  4251. return ret;
  4252. }
  4253. #endif
  4254. /**
  4255. * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
  4256. * @q_idx: TX queue number
  4257. * @vsi: Pointer to VSI struct
  4258. *
  4259. * This function checks specified queue for given VSI. Detects hung condition.
  4260. * We proactively detect hung TX queues by checking if interrupts are disabled
  4261. * but there are pending descriptors. If it appears hung, attempt to recover
  4262. * by triggering a SW interrupt.
  4263. **/
  4264. static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi)
  4265. {
  4266. struct i40e_ring *tx_ring = NULL;
  4267. struct i40e_pf *pf;
  4268. u32 val, tx_pending;
  4269. int i;
  4270. pf = vsi->back;
  4271. /* now that we have an index, find the tx_ring struct */
  4272. for (i = 0; i < vsi->num_queue_pairs; i++) {
  4273. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
  4274. if (q_idx == vsi->tx_rings[i]->queue_index) {
  4275. tx_ring = vsi->tx_rings[i];
  4276. break;
  4277. }
  4278. }
  4279. }
  4280. if (!tx_ring)
  4281. return;
  4282. /* Read interrupt register */
  4283. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  4284. val = rd32(&pf->hw,
  4285. I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
  4286. tx_ring->vsi->base_vector - 1));
  4287. else
  4288. val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
  4289. tx_pending = i40e_get_tx_pending(tx_ring);
  4290. /* Interrupts are disabled and TX pending is non-zero,
  4291. * trigger the SW interrupt (don't wait). Worst case
  4292. * there will be one extra interrupt which may result
  4293. * into not cleaning any queues because queues are cleaned.
  4294. */
  4295. if (tx_pending && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK)))
  4296. i40e_force_wb(vsi, tx_ring->q_vector);
  4297. }
  4298. /**
  4299. * i40e_detect_recover_hung - Function to detect and recover hung_queues
  4300. * @pf: pointer to PF struct
  4301. *
  4302. * LAN VSI has netdev and netdev has TX queues. This function is to check
  4303. * each of those TX queues if they are hung, trigger recovery by issuing
  4304. * SW interrupt.
  4305. **/
  4306. static void i40e_detect_recover_hung(struct i40e_pf *pf)
  4307. {
  4308. struct net_device *netdev;
  4309. struct i40e_vsi *vsi;
  4310. unsigned int i;
  4311. /* Only for LAN VSI */
  4312. vsi = pf->vsi[pf->lan_vsi];
  4313. if (!vsi)
  4314. return;
  4315. /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
  4316. if (test_bit(__I40E_VSI_DOWN, vsi->back->state) ||
  4317. test_bit(__I40E_RESET_RECOVERY_PENDING, vsi->back->state))
  4318. return;
  4319. /* Make sure type is MAIN VSI */
  4320. if (vsi->type != I40E_VSI_MAIN)
  4321. return;
  4322. netdev = vsi->netdev;
  4323. if (!netdev)
  4324. return;
  4325. /* Bail out if netif_carrier is not OK */
  4326. if (!netif_carrier_ok(netdev))
  4327. return;
  4328. /* Go thru' TX queues for netdev */
  4329. for (i = 0; i < netdev->num_tx_queues; i++) {
  4330. struct netdev_queue *q;
  4331. q = netdev_get_tx_queue(netdev, i);
  4332. if (q)
  4333. i40e_detect_recover_hung_queue(i, vsi);
  4334. }
  4335. }
  4336. /**
  4337. * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
  4338. * @pf: pointer to PF
  4339. *
  4340. * Get TC map for ISCSI PF type that will include iSCSI TC
  4341. * and LAN TC.
  4342. **/
  4343. static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
  4344. {
  4345. struct i40e_dcb_app_priority_table app;
  4346. struct i40e_hw *hw = &pf->hw;
  4347. u8 enabled_tc = 1; /* TC0 is always enabled */
  4348. u8 tc, i;
  4349. /* Get the iSCSI APP TLV */
  4350. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4351. for (i = 0; i < dcbcfg->numapps; i++) {
  4352. app = dcbcfg->app[i];
  4353. if (app.selector == I40E_APP_SEL_TCPIP &&
  4354. app.protocolid == I40E_APP_PROTOID_ISCSI) {
  4355. tc = dcbcfg->etscfg.prioritytable[app.priority];
  4356. enabled_tc |= BIT(tc);
  4357. break;
  4358. }
  4359. }
  4360. return enabled_tc;
  4361. }
  4362. /**
  4363. * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
  4364. * @dcbcfg: the corresponding DCBx configuration structure
  4365. *
  4366. * Return the number of TCs from given DCBx configuration
  4367. **/
  4368. static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
  4369. {
  4370. int i, tc_unused = 0;
  4371. u8 num_tc = 0;
  4372. u8 ret = 0;
  4373. /* Scan the ETS Config Priority Table to find
  4374. * traffic class enabled for a given priority
  4375. * and create a bitmask of enabled TCs
  4376. */
  4377. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
  4378. num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
  4379. /* Now scan the bitmask to check for
  4380. * contiguous TCs starting with TC0
  4381. */
  4382. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4383. if (num_tc & BIT(i)) {
  4384. if (!tc_unused) {
  4385. ret++;
  4386. } else {
  4387. pr_err("Non-contiguous TC - Disabling DCB\n");
  4388. return 1;
  4389. }
  4390. } else {
  4391. tc_unused = 1;
  4392. }
  4393. }
  4394. /* There is always at least TC0 */
  4395. if (!ret)
  4396. ret = 1;
  4397. return ret;
  4398. }
  4399. /**
  4400. * i40e_dcb_get_enabled_tc - Get enabled traffic classes
  4401. * @dcbcfg: the corresponding DCBx configuration structure
  4402. *
  4403. * Query the current DCB configuration and return the number of
  4404. * traffic classes enabled from the given DCBX config
  4405. **/
  4406. static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
  4407. {
  4408. u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
  4409. u8 enabled_tc = 1;
  4410. u8 i;
  4411. for (i = 0; i < num_tc; i++)
  4412. enabled_tc |= BIT(i);
  4413. return enabled_tc;
  4414. }
  4415. /**
  4416. * i40e_mqprio_get_enabled_tc - Get enabled traffic classes
  4417. * @pf: PF being queried
  4418. *
  4419. * Query the current MQPRIO configuration and return the number of
  4420. * traffic classes enabled.
  4421. **/
  4422. static u8 i40e_mqprio_get_enabled_tc(struct i40e_pf *pf)
  4423. {
  4424. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  4425. u8 num_tc = vsi->mqprio_qopt.qopt.num_tc;
  4426. u8 enabled_tc = 1, i;
  4427. for (i = 1; i < num_tc; i++)
  4428. enabled_tc |= BIT(i);
  4429. return enabled_tc;
  4430. }
  4431. /**
  4432. * i40e_pf_get_num_tc - Get enabled traffic classes for PF
  4433. * @pf: PF being queried
  4434. *
  4435. * Return number of traffic classes enabled for the given PF
  4436. **/
  4437. static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
  4438. {
  4439. struct i40e_hw *hw = &pf->hw;
  4440. u8 i, enabled_tc = 1;
  4441. u8 num_tc = 0;
  4442. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4443. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4444. return pf->vsi[pf->lan_vsi]->mqprio_qopt.qopt.num_tc;
  4445. /* If neither MQPRIO nor DCB is enabled, then always use single TC */
  4446. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4447. return 1;
  4448. /* SFP mode will be enabled for all TCs on port */
  4449. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4450. return i40e_dcb_get_num_tc(dcbcfg);
  4451. /* MFP mode return count of enabled TCs for this PF */
  4452. if (pf->hw.func_caps.iscsi)
  4453. enabled_tc = i40e_get_iscsi_tc_map(pf);
  4454. else
  4455. return 1; /* Only TC0 */
  4456. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4457. if (enabled_tc & BIT(i))
  4458. num_tc++;
  4459. }
  4460. return num_tc;
  4461. }
  4462. /**
  4463. * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
  4464. * @pf: PF being queried
  4465. *
  4466. * Return a bitmap for enabled traffic classes for this PF.
  4467. **/
  4468. static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
  4469. {
  4470. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4471. return i40e_mqprio_get_enabled_tc(pf);
  4472. /* If neither MQPRIO nor DCB is enabled for this PF then just return
  4473. * default TC
  4474. */
  4475. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4476. return I40E_DEFAULT_TRAFFIC_CLASS;
  4477. /* SFP mode we want PF to be enabled for all TCs */
  4478. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4479. return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
  4480. /* MFP enabled and iSCSI PF type */
  4481. if (pf->hw.func_caps.iscsi)
  4482. return i40e_get_iscsi_tc_map(pf);
  4483. else
  4484. return I40E_DEFAULT_TRAFFIC_CLASS;
  4485. }
  4486. /**
  4487. * i40e_vsi_get_bw_info - Query VSI BW Information
  4488. * @vsi: the VSI being queried
  4489. *
  4490. * Returns 0 on success, negative value on failure
  4491. **/
  4492. static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
  4493. {
  4494. struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
  4495. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  4496. struct i40e_pf *pf = vsi->back;
  4497. struct i40e_hw *hw = &pf->hw;
  4498. i40e_status ret;
  4499. u32 tc_bw_max;
  4500. int i;
  4501. /* Get the VSI level BW configuration */
  4502. ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
  4503. if (ret) {
  4504. dev_info(&pf->pdev->dev,
  4505. "couldn't get PF vsi bw config, err %s aq_err %s\n",
  4506. i40e_stat_str(&pf->hw, ret),
  4507. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4508. return -EINVAL;
  4509. }
  4510. /* Get the VSI level BW configuration per TC */
  4511. ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
  4512. NULL);
  4513. if (ret) {
  4514. dev_info(&pf->pdev->dev,
  4515. "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
  4516. i40e_stat_str(&pf->hw, ret),
  4517. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4518. return -EINVAL;
  4519. }
  4520. if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
  4521. dev_info(&pf->pdev->dev,
  4522. "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
  4523. bw_config.tc_valid_bits,
  4524. bw_ets_config.tc_valid_bits);
  4525. /* Still continuing */
  4526. }
  4527. vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
  4528. vsi->bw_max_quanta = bw_config.max_bw;
  4529. tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
  4530. (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
  4531. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4532. vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
  4533. vsi->bw_ets_limit_credits[i] =
  4534. le16_to_cpu(bw_ets_config.credits[i]);
  4535. /* 3 bits out of 4 for each TC */
  4536. vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
  4537. }
  4538. return 0;
  4539. }
  4540. /**
  4541. * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
  4542. * @vsi: the VSI being configured
  4543. * @enabled_tc: TC bitmap
  4544. * @bw_credits: BW shared credits per TC
  4545. *
  4546. * Returns 0 on success, negative value on failure
  4547. **/
  4548. static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
  4549. u8 *bw_share)
  4550. {
  4551. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  4552. i40e_status ret;
  4553. int i;
  4554. if (vsi->back->flags & I40E_FLAG_TC_MQPRIO)
  4555. return 0;
  4556. if (!vsi->mqprio_qopt.qopt.hw) {
  4557. ret = i40e_set_bw_limit(vsi, vsi->seid, 0);
  4558. if (ret)
  4559. dev_info(&vsi->back->pdev->dev,
  4560. "Failed to reset tx rate for vsi->seid %u\n",
  4561. vsi->seid);
  4562. return ret;
  4563. }
  4564. bw_data.tc_valid_bits = enabled_tc;
  4565. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4566. bw_data.tc_bw_credits[i] = bw_share[i];
  4567. ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
  4568. NULL);
  4569. if (ret) {
  4570. dev_info(&vsi->back->pdev->dev,
  4571. "AQ command Config VSI BW allocation per TC failed = %d\n",
  4572. vsi->back->hw.aq.asq_last_status);
  4573. return -EINVAL;
  4574. }
  4575. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4576. vsi->info.qs_handle[i] = bw_data.qs_handles[i];
  4577. return 0;
  4578. }
  4579. /**
  4580. * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
  4581. * @vsi: the VSI being configured
  4582. * @enabled_tc: TC map to be enabled
  4583. *
  4584. **/
  4585. static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4586. {
  4587. struct net_device *netdev = vsi->netdev;
  4588. struct i40e_pf *pf = vsi->back;
  4589. struct i40e_hw *hw = &pf->hw;
  4590. u8 netdev_tc = 0;
  4591. int i;
  4592. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4593. if (!netdev)
  4594. return;
  4595. if (!enabled_tc) {
  4596. netdev_reset_tc(netdev);
  4597. return;
  4598. }
  4599. /* Set up actual enabled TCs on the VSI */
  4600. if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
  4601. return;
  4602. /* set per TC queues for the VSI */
  4603. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4604. /* Only set TC queues for enabled tcs
  4605. *
  4606. * e.g. For a VSI that has TC0 and TC3 enabled the
  4607. * enabled_tc bitmap would be 0x00001001; the driver
  4608. * will set the numtc for netdev as 2 that will be
  4609. * referenced by the netdev layer as TC 0 and 1.
  4610. */
  4611. if (vsi->tc_config.enabled_tc & BIT(i))
  4612. netdev_set_tc_queue(netdev,
  4613. vsi->tc_config.tc_info[i].netdev_tc,
  4614. vsi->tc_config.tc_info[i].qcount,
  4615. vsi->tc_config.tc_info[i].qoffset);
  4616. }
  4617. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4618. return;
  4619. /* Assign UP2TC map for the VSI */
  4620. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  4621. /* Get the actual TC# for the UP */
  4622. u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
  4623. /* Get the mapped netdev TC# for the UP */
  4624. netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
  4625. netdev_set_prio_tc_map(netdev, i, netdev_tc);
  4626. }
  4627. }
  4628. /**
  4629. * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
  4630. * @vsi: the VSI being configured
  4631. * @ctxt: the ctxt buffer returned from AQ VSI update param command
  4632. **/
  4633. static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
  4634. struct i40e_vsi_context *ctxt)
  4635. {
  4636. /* copy just the sections touched not the entire info
  4637. * since not all sections are valid as returned by
  4638. * update vsi params
  4639. */
  4640. vsi->info.mapping_flags = ctxt->info.mapping_flags;
  4641. memcpy(&vsi->info.queue_mapping,
  4642. &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
  4643. memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
  4644. sizeof(vsi->info.tc_mapping));
  4645. }
  4646. /**
  4647. * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
  4648. * @vsi: VSI to be configured
  4649. * @enabled_tc: TC bitmap
  4650. *
  4651. * This configures a particular VSI for TCs that are mapped to the
  4652. * given TC bitmap. It uses default bandwidth share for TCs across
  4653. * VSIs to configure TC for a particular VSI.
  4654. *
  4655. * NOTE:
  4656. * It is expected that the VSI queues have been quisced before calling
  4657. * this function.
  4658. **/
  4659. static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4660. {
  4661. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  4662. struct i40e_vsi_context ctxt;
  4663. int ret = 0;
  4664. int i;
  4665. /* Check if enabled_tc is same as existing or new TCs */
  4666. if (vsi->tc_config.enabled_tc == enabled_tc &&
  4667. vsi->mqprio_qopt.mode != TC_MQPRIO_MODE_CHANNEL)
  4668. return ret;
  4669. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  4670. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4671. if (enabled_tc & BIT(i))
  4672. bw_share[i] = 1;
  4673. }
  4674. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  4675. if (ret) {
  4676. dev_info(&vsi->back->pdev->dev,
  4677. "Failed configuring TC map %d for VSI %d\n",
  4678. enabled_tc, vsi->seid);
  4679. goto out;
  4680. }
  4681. /* Update Queue Pairs Mapping for currently enabled UPs */
  4682. ctxt.seid = vsi->seid;
  4683. ctxt.pf_num = vsi->back->hw.pf_id;
  4684. ctxt.vf_num = 0;
  4685. ctxt.uplink_seid = vsi->uplink_seid;
  4686. ctxt.info = vsi->info;
  4687. if (vsi->back->flags & I40E_FLAG_TC_MQPRIO) {
  4688. ret = i40e_vsi_setup_queue_map_mqprio(vsi, &ctxt, enabled_tc);
  4689. if (ret)
  4690. goto out;
  4691. } else {
  4692. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  4693. }
  4694. /* On destroying the qdisc, reset vsi->rss_size, as number of enabled
  4695. * queues changed.
  4696. */
  4697. if (!vsi->mqprio_qopt.qopt.hw && vsi->reconfig_rss) {
  4698. vsi->rss_size = min_t(int, vsi->back->alloc_rss_size,
  4699. vsi->num_queue_pairs);
  4700. ret = i40e_vsi_config_rss(vsi);
  4701. if (ret) {
  4702. dev_info(&vsi->back->pdev->dev,
  4703. "Failed to reconfig rss for num_queues\n");
  4704. return ret;
  4705. }
  4706. vsi->reconfig_rss = false;
  4707. }
  4708. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  4709. ctxt.info.valid_sections |=
  4710. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  4711. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  4712. }
  4713. /* Update the VSI after updating the VSI queue-mapping
  4714. * information
  4715. */
  4716. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  4717. if (ret) {
  4718. dev_info(&vsi->back->pdev->dev,
  4719. "Update vsi tc config failed, err %s aq_err %s\n",
  4720. i40e_stat_str(&vsi->back->hw, ret),
  4721. i40e_aq_str(&vsi->back->hw,
  4722. vsi->back->hw.aq.asq_last_status));
  4723. goto out;
  4724. }
  4725. /* update the local VSI info with updated queue map */
  4726. i40e_vsi_update_queue_map(vsi, &ctxt);
  4727. vsi->info.valid_sections = 0;
  4728. /* Update current VSI BW information */
  4729. ret = i40e_vsi_get_bw_info(vsi);
  4730. if (ret) {
  4731. dev_info(&vsi->back->pdev->dev,
  4732. "Failed updating vsi bw info, err %s aq_err %s\n",
  4733. i40e_stat_str(&vsi->back->hw, ret),
  4734. i40e_aq_str(&vsi->back->hw,
  4735. vsi->back->hw.aq.asq_last_status));
  4736. goto out;
  4737. }
  4738. /* Update the netdev TC setup */
  4739. i40e_vsi_config_netdev_tc(vsi, enabled_tc);
  4740. out:
  4741. return ret;
  4742. }
  4743. /**
  4744. * i40e_get_link_speed - Returns link speed for the interface
  4745. * @vsi: VSI to be configured
  4746. *
  4747. **/
  4748. int i40e_get_link_speed(struct i40e_vsi *vsi)
  4749. {
  4750. struct i40e_pf *pf = vsi->back;
  4751. switch (pf->hw.phy.link_info.link_speed) {
  4752. case I40E_LINK_SPEED_40GB:
  4753. return 40000;
  4754. case I40E_LINK_SPEED_25GB:
  4755. return 25000;
  4756. case I40E_LINK_SPEED_20GB:
  4757. return 20000;
  4758. case I40E_LINK_SPEED_10GB:
  4759. return 10000;
  4760. case I40E_LINK_SPEED_1GB:
  4761. return 1000;
  4762. default:
  4763. return -EINVAL;
  4764. }
  4765. }
  4766. /**
  4767. * i40e_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
  4768. * @vsi: VSI to be configured
  4769. * @seid: seid of the channel/VSI
  4770. * @max_tx_rate: max TX rate to be configured as BW limit
  4771. *
  4772. * Helper function to set BW limit for a given VSI
  4773. **/
  4774. int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate)
  4775. {
  4776. struct i40e_pf *pf = vsi->back;
  4777. u64 credits = 0;
  4778. int speed = 0;
  4779. int ret = 0;
  4780. speed = i40e_get_link_speed(vsi);
  4781. if (max_tx_rate > speed) {
  4782. dev_err(&pf->pdev->dev,
  4783. "Invalid max tx rate %llu specified for VSI seid %d.",
  4784. max_tx_rate, seid);
  4785. return -EINVAL;
  4786. }
  4787. if (max_tx_rate && max_tx_rate < 50) {
  4788. dev_warn(&pf->pdev->dev,
  4789. "Setting max tx rate to minimum usable value of 50Mbps.\n");
  4790. max_tx_rate = 50;
  4791. }
  4792. /* Tx rate credits are in values of 50Mbps, 0 is disabled */
  4793. credits = max_tx_rate;
  4794. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  4795. ret = i40e_aq_config_vsi_bw_limit(&pf->hw, seid, credits,
  4796. I40E_MAX_BW_INACTIVE_ACCUM, NULL);
  4797. if (ret)
  4798. dev_err(&pf->pdev->dev,
  4799. "Failed set tx rate (%llu Mbps) for vsi->seid %u, err %s aq_err %s\n",
  4800. max_tx_rate, seid, i40e_stat_str(&pf->hw, ret),
  4801. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4802. return ret;
  4803. }
  4804. /**
  4805. * i40e_remove_queue_channels - Remove queue channels for the TCs
  4806. * @vsi: VSI to be configured
  4807. *
  4808. * Remove queue channels for the TCs
  4809. **/
  4810. static void i40e_remove_queue_channels(struct i40e_vsi *vsi)
  4811. {
  4812. enum i40e_admin_queue_err last_aq_status;
  4813. struct i40e_cloud_filter *cfilter;
  4814. struct i40e_channel *ch, *ch_tmp;
  4815. struct i40e_pf *pf = vsi->back;
  4816. struct hlist_node *node;
  4817. int ret, i;
  4818. /* Reset rss size that was stored when reconfiguring rss for
  4819. * channel VSIs with non-power-of-2 queue count.
  4820. */
  4821. vsi->current_rss_size = 0;
  4822. /* perform cleanup for channels if they exist */
  4823. if (list_empty(&vsi->ch_list))
  4824. return;
  4825. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4826. struct i40e_vsi *p_vsi;
  4827. list_del(&ch->list);
  4828. p_vsi = ch->parent_vsi;
  4829. if (!p_vsi || !ch->initialized) {
  4830. kfree(ch);
  4831. continue;
  4832. }
  4833. /* Reset queue contexts */
  4834. for (i = 0; i < ch->num_queue_pairs; i++) {
  4835. struct i40e_ring *tx_ring, *rx_ring;
  4836. u16 pf_q;
  4837. pf_q = ch->base_queue + i;
  4838. tx_ring = vsi->tx_rings[pf_q];
  4839. tx_ring->ch = NULL;
  4840. rx_ring = vsi->rx_rings[pf_q];
  4841. rx_ring->ch = NULL;
  4842. }
  4843. /* Reset BW configured for this VSI via mqprio */
  4844. ret = i40e_set_bw_limit(vsi, ch->seid, 0);
  4845. if (ret)
  4846. dev_info(&vsi->back->pdev->dev,
  4847. "Failed to reset tx rate for ch->seid %u\n",
  4848. ch->seid);
  4849. /* delete cloud filters associated with this channel */
  4850. hlist_for_each_entry_safe(cfilter, node,
  4851. &pf->cloud_filter_list, cloud_node) {
  4852. if (cfilter->seid != ch->seid)
  4853. continue;
  4854. hash_del(&cfilter->cloud_node);
  4855. if (cfilter->dst_port)
  4856. ret = i40e_add_del_cloud_filter_big_buf(vsi,
  4857. cfilter,
  4858. false);
  4859. else
  4860. ret = i40e_add_del_cloud_filter(vsi, cfilter,
  4861. false);
  4862. last_aq_status = pf->hw.aq.asq_last_status;
  4863. if (ret)
  4864. dev_info(&pf->pdev->dev,
  4865. "Failed to delete cloud filter, err %s aq_err %s\n",
  4866. i40e_stat_str(&pf->hw, ret),
  4867. i40e_aq_str(&pf->hw, last_aq_status));
  4868. kfree(cfilter);
  4869. }
  4870. /* delete VSI from FW */
  4871. ret = i40e_aq_delete_element(&vsi->back->hw, ch->seid,
  4872. NULL);
  4873. if (ret)
  4874. dev_err(&vsi->back->pdev->dev,
  4875. "unable to remove channel (%d) for parent VSI(%d)\n",
  4876. ch->seid, p_vsi->seid);
  4877. kfree(ch);
  4878. }
  4879. INIT_LIST_HEAD(&vsi->ch_list);
  4880. }
  4881. /**
  4882. * i40e_is_any_channel - channel exist or not
  4883. * @vsi: ptr to VSI to which channels are associated with
  4884. *
  4885. * Returns true or false if channel(s) exist for associated VSI or not
  4886. **/
  4887. static bool i40e_is_any_channel(struct i40e_vsi *vsi)
  4888. {
  4889. struct i40e_channel *ch, *ch_tmp;
  4890. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4891. if (ch->initialized)
  4892. return true;
  4893. }
  4894. return false;
  4895. }
  4896. /**
  4897. * i40e_get_max_queues_for_channel
  4898. * @vsi: ptr to VSI to which channels are associated with
  4899. *
  4900. * Helper function which returns max value among the queue counts set on the
  4901. * channels/TCs created.
  4902. **/
  4903. static int i40e_get_max_queues_for_channel(struct i40e_vsi *vsi)
  4904. {
  4905. struct i40e_channel *ch, *ch_tmp;
  4906. int max = 0;
  4907. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4908. if (!ch->initialized)
  4909. continue;
  4910. if (ch->num_queue_pairs > max)
  4911. max = ch->num_queue_pairs;
  4912. }
  4913. return max;
  4914. }
  4915. /**
  4916. * i40e_validate_num_queues - validate num_queues w.r.t channel
  4917. * @pf: ptr to PF device
  4918. * @num_queues: number of queues
  4919. * @vsi: the parent VSI
  4920. * @reconfig_rss: indicates should the RSS be reconfigured or not
  4921. *
  4922. * This function validates number of queues in the context of new channel
  4923. * which is being established and determines if RSS should be reconfigured
  4924. * or not for parent VSI.
  4925. **/
  4926. static int i40e_validate_num_queues(struct i40e_pf *pf, int num_queues,
  4927. struct i40e_vsi *vsi, bool *reconfig_rss)
  4928. {
  4929. int max_ch_queues;
  4930. if (!reconfig_rss)
  4931. return -EINVAL;
  4932. *reconfig_rss = false;
  4933. if (num_queues > I40E_MAX_QUEUES_PER_CH) {
  4934. dev_err(&pf->pdev->dev,
  4935. "Failed to create VMDq VSI. User requested num_queues (%d) > I40E_MAX_QUEUES_PER_VSI (%u)\n",
  4936. num_queues, I40E_MAX_QUEUES_PER_CH);
  4937. return -EINVAL;
  4938. }
  4939. if (vsi->current_rss_size) {
  4940. if (num_queues > vsi->current_rss_size) {
  4941. dev_dbg(&pf->pdev->dev,
  4942. "Error: num_queues (%d) > vsi's current_size(%d)\n",
  4943. num_queues, vsi->current_rss_size);
  4944. return -EINVAL;
  4945. } else if ((num_queues < vsi->current_rss_size) &&
  4946. (!is_power_of_2(num_queues))) {
  4947. dev_dbg(&pf->pdev->dev,
  4948. "Error: num_queues (%d) < vsi's current_size(%d), but not power of 2\n",
  4949. num_queues, vsi->current_rss_size);
  4950. return -EINVAL;
  4951. }
  4952. }
  4953. if (!is_power_of_2(num_queues)) {
  4954. /* Find the max num_queues configured for channel if channel
  4955. * exist.
  4956. * if channel exist, then enforce 'num_queues' to be more than
  4957. * max ever queues configured for channel.
  4958. */
  4959. max_ch_queues = i40e_get_max_queues_for_channel(vsi);
  4960. if (num_queues < max_ch_queues) {
  4961. dev_dbg(&pf->pdev->dev,
  4962. "Error: num_queues (%d) < max queues configured for channel(%d)\n",
  4963. num_queues, max_ch_queues);
  4964. return -EINVAL;
  4965. }
  4966. *reconfig_rss = true;
  4967. }
  4968. return 0;
  4969. }
  4970. /**
  4971. * i40e_vsi_reconfig_rss - reconfig RSS based on specified rss_size
  4972. * @vsi: the VSI being setup
  4973. * @rss_size: size of RSS, accordingly LUT gets reprogrammed
  4974. *
  4975. * This function reconfigures RSS by reprogramming LUTs using 'rss_size'
  4976. **/
  4977. static int i40e_vsi_reconfig_rss(struct i40e_vsi *vsi, u16 rss_size)
  4978. {
  4979. struct i40e_pf *pf = vsi->back;
  4980. u8 seed[I40E_HKEY_ARRAY_SIZE];
  4981. struct i40e_hw *hw = &pf->hw;
  4982. int local_rss_size;
  4983. u8 *lut;
  4984. int ret;
  4985. if (!vsi->rss_size)
  4986. return -EINVAL;
  4987. if (rss_size > vsi->rss_size)
  4988. return -EINVAL;
  4989. local_rss_size = min_t(int, vsi->rss_size, rss_size);
  4990. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  4991. if (!lut)
  4992. return -ENOMEM;
  4993. /* Ignoring user configured lut if there is one */
  4994. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, local_rss_size);
  4995. /* Use user configured hash key if there is one, otherwise
  4996. * use default.
  4997. */
  4998. if (vsi->rss_hkey_user)
  4999. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  5000. else
  5001. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  5002. ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
  5003. if (ret) {
  5004. dev_info(&pf->pdev->dev,
  5005. "Cannot set RSS lut, err %s aq_err %s\n",
  5006. i40e_stat_str(hw, ret),
  5007. i40e_aq_str(hw, hw->aq.asq_last_status));
  5008. kfree(lut);
  5009. return ret;
  5010. }
  5011. kfree(lut);
  5012. /* Do the update w.r.t. storing rss_size */
  5013. if (!vsi->orig_rss_size)
  5014. vsi->orig_rss_size = vsi->rss_size;
  5015. vsi->current_rss_size = local_rss_size;
  5016. return ret;
  5017. }
  5018. /**
  5019. * i40e_channel_setup_queue_map - Setup a channel queue map
  5020. * @pf: ptr to PF device
  5021. * @vsi: the VSI being setup
  5022. * @ctxt: VSI context structure
  5023. * @ch: ptr to channel structure
  5024. *
  5025. * Setup queue map for a specific channel
  5026. **/
  5027. static void i40e_channel_setup_queue_map(struct i40e_pf *pf,
  5028. struct i40e_vsi_context *ctxt,
  5029. struct i40e_channel *ch)
  5030. {
  5031. u16 qcount, qmap, sections = 0;
  5032. u8 offset = 0;
  5033. int pow;
  5034. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  5035. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  5036. qcount = min_t(int, ch->num_queue_pairs, pf->num_lan_msix);
  5037. ch->num_queue_pairs = qcount;
  5038. /* find the next higher power-of-2 of num queue pairs */
  5039. pow = ilog2(qcount);
  5040. if (!is_power_of_2(qcount))
  5041. pow++;
  5042. qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  5043. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  5044. /* Setup queue TC[0].qmap for given VSI context */
  5045. ctxt->info.tc_mapping[0] = cpu_to_le16(qmap);
  5046. ctxt->info.up_enable_bits = 0x1; /* TC0 enabled */
  5047. ctxt->info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  5048. ctxt->info.queue_mapping[0] = cpu_to_le16(ch->base_queue);
  5049. ctxt->info.valid_sections |= cpu_to_le16(sections);
  5050. }
  5051. /**
  5052. * i40e_add_channel - add a channel by adding VSI
  5053. * @pf: ptr to PF device
  5054. * @uplink_seid: underlying HW switching element (VEB) ID
  5055. * @ch: ptr to channel structure
  5056. *
  5057. * Add a channel (VSI) using add_vsi and queue_map
  5058. **/
  5059. static int i40e_add_channel(struct i40e_pf *pf, u16 uplink_seid,
  5060. struct i40e_channel *ch)
  5061. {
  5062. struct i40e_hw *hw = &pf->hw;
  5063. struct i40e_vsi_context ctxt;
  5064. u8 enabled_tc = 0x1; /* TC0 enabled */
  5065. int ret;
  5066. if (ch->type != I40E_VSI_VMDQ2) {
  5067. dev_info(&pf->pdev->dev,
  5068. "add new vsi failed, ch->type %d\n", ch->type);
  5069. return -EINVAL;
  5070. }
  5071. memset(&ctxt, 0, sizeof(ctxt));
  5072. ctxt.pf_num = hw->pf_id;
  5073. ctxt.vf_num = 0;
  5074. ctxt.uplink_seid = uplink_seid;
  5075. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  5076. if (ch->type == I40E_VSI_VMDQ2)
  5077. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  5078. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) {
  5079. ctxt.info.valid_sections |=
  5080. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5081. ctxt.info.switch_id =
  5082. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5083. }
  5084. /* Set queue map for a given VSI context */
  5085. i40e_channel_setup_queue_map(pf, &ctxt, ch);
  5086. /* Now time to create VSI */
  5087. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  5088. if (ret) {
  5089. dev_info(&pf->pdev->dev,
  5090. "add new vsi failed, err %s aq_err %s\n",
  5091. i40e_stat_str(&pf->hw, ret),
  5092. i40e_aq_str(&pf->hw,
  5093. pf->hw.aq.asq_last_status));
  5094. return -ENOENT;
  5095. }
  5096. /* Success, update channel */
  5097. ch->enabled_tc = enabled_tc;
  5098. ch->seid = ctxt.seid;
  5099. ch->vsi_number = ctxt.vsi_number;
  5100. ch->stat_counter_idx = cpu_to_le16(ctxt.info.stat_counter_idx);
  5101. /* copy just the sections touched not the entire info
  5102. * since not all sections are valid as returned by
  5103. * update vsi params
  5104. */
  5105. ch->info.mapping_flags = ctxt.info.mapping_flags;
  5106. memcpy(&ch->info.queue_mapping,
  5107. &ctxt.info.queue_mapping, sizeof(ctxt.info.queue_mapping));
  5108. memcpy(&ch->info.tc_mapping, ctxt.info.tc_mapping,
  5109. sizeof(ctxt.info.tc_mapping));
  5110. return 0;
  5111. }
  5112. static int i40e_channel_config_bw(struct i40e_vsi *vsi, struct i40e_channel *ch,
  5113. u8 *bw_share)
  5114. {
  5115. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  5116. i40e_status ret;
  5117. int i;
  5118. bw_data.tc_valid_bits = ch->enabled_tc;
  5119. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  5120. bw_data.tc_bw_credits[i] = bw_share[i];
  5121. ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, ch->seid,
  5122. &bw_data, NULL);
  5123. if (ret) {
  5124. dev_info(&vsi->back->pdev->dev,
  5125. "Config VSI BW allocation per TC failed, aq_err: %d for new_vsi->seid %u\n",
  5126. vsi->back->hw.aq.asq_last_status, ch->seid);
  5127. return -EINVAL;
  5128. }
  5129. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  5130. ch->info.qs_handle[i] = bw_data.qs_handles[i];
  5131. return 0;
  5132. }
  5133. /**
  5134. * i40e_channel_config_tx_ring - config TX ring associated with new channel
  5135. * @pf: ptr to PF device
  5136. * @vsi: the VSI being setup
  5137. * @ch: ptr to channel structure
  5138. *
  5139. * Configure TX rings associated with channel (VSI) since queues are being
  5140. * from parent VSI.
  5141. **/
  5142. static int i40e_channel_config_tx_ring(struct i40e_pf *pf,
  5143. struct i40e_vsi *vsi,
  5144. struct i40e_channel *ch)
  5145. {
  5146. i40e_status ret;
  5147. int i;
  5148. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  5149. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  5150. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5151. if (ch->enabled_tc & BIT(i))
  5152. bw_share[i] = 1;
  5153. }
  5154. /* configure BW for new VSI */
  5155. ret = i40e_channel_config_bw(vsi, ch, bw_share);
  5156. if (ret) {
  5157. dev_info(&vsi->back->pdev->dev,
  5158. "Failed configuring TC map %d for channel (seid %u)\n",
  5159. ch->enabled_tc, ch->seid);
  5160. return ret;
  5161. }
  5162. for (i = 0; i < ch->num_queue_pairs; i++) {
  5163. struct i40e_ring *tx_ring, *rx_ring;
  5164. u16 pf_q;
  5165. pf_q = ch->base_queue + i;
  5166. /* Get to TX ring ptr of main VSI, for re-setup TX queue
  5167. * context
  5168. */
  5169. tx_ring = vsi->tx_rings[pf_q];
  5170. tx_ring->ch = ch;
  5171. /* Get the RX ring ptr */
  5172. rx_ring = vsi->rx_rings[pf_q];
  5173. rx_ring->ch = ch;
  5174. }
  5175. return 0;
  5176. }
  5177. /**
  5178. * i40e_setup_hw_channel - setup new channel
  5179. * @pf: ptr to PF device
  5180. * @vsi: the VSI being setup
  5181. * @ch: ptr to channel structure
  5182. * @uplink_seid: underlying HW switching element (VEB) ID
  5183. * @type: type of channel to be created (VMDq2/VF)
  5184. *
  5185. * Setup new channel (VSI) based on specified type (VMDq2/VF)
  5186. * and configures TX rings accordingly
  5187. **/
  5188. static inline int i40e_setup_hw_channel(struct i40e_pf *pf,
  5189. struct i40e_vsi *vsi,
  5190. struct i40e_channel *ch,
  5191. u16 uplink_seid, u8 type)
  5192. {
  5193. int ret;
  5194. ch->initialized = false;
  5195. ch->base_queue = vsi->next_base_queue;
  5196. ch->type = type;
  5197. /* Proceed with creation of channel (VMDq2) VSI */
  5198. ret = i40e_add_channel(pf, uplink_seid, ch);
  5199. if (ret) {
  5200. dev_info(&pf->pdev->dev,
  5201. "failed to add_channel using uplink_seid %u\n",
  5202. uplink_seid);
  5203. return ret;
  5204. }
  5205. /* Mark the successful creation of channel */
  5206. ch->initialized = true;
  5207. /* Reconfigure TX queues using QTX_CTL register */
  5208. ret = i40e_channel_config_tx_ring(pf, vsi, ch);
  5209. if (ret) {
  5210. dev_info(&pf->pdev->dev,
  5211. "failed to configure TX rings for channel %u\n",
  5212. ch->seid);
  5213. return ret;
  5214. }
  5215. /* update 'next_base_queue' */
  5216. vsi->next_base_queue = vsi->next_base_queue + ch->num_queue_pairs;
  5217. dev_dbg(&pf->pdev->dev,
  5218. "Added channel: vsi_seid %u, vsi_number %u, stat_counter_idx %u, num_queue_pairs %u, pf->next_base_queue %d\n",
  5219. ch->seid, ch->vsi_number, ch->stat_counter_idx,
  5220. ch->num_queue_pairs,
  5221. vsi->next_base_queue);
  5222. return ret;
  5223. }
  5224. /**
  5225. * i40e_setup_channel - setup new channel using uplink element
  5226. * @pf: ptr to PF device
  5227. * @type: type of channel to be created (VMDq2/VF)
  5228. * @uplink_seid: underlying HW switching element (VEB) ID
  5229. * @ch: ptr to channel structure
  5230. *
  5231. * Setup new channel (VSI) based on specified type (VMDq2/VF)
  5232. * and uplink switching element (uplink_seid)
  5233. **/
  5234. static bool i40e_setup_channel(struct i40e_pf *pf, struct i40e_vsi *vsi,
  5235. struct i40e_channel *ch)
  5236. {
  5237. u8 vsi_type;
  5238. u16 seid;
  5239. int ret;
  5240. if (vsi->type == I40E_VSI_MAIN) {
  5241. vsi_type = I40E_VSI_VMDQ2;
  5242. } else {
  5243. dev_err(&pf->pdev->dev, "unsupported parent vsi type(%d)\n",
  5244. vsi->type);
  5245. return false;
  5246. }
  5247. /* underlying switching element */
  5248. seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  5249. /* create channel (VSI), configure TX rings */
  5250. ret = i40e_setup_hw_channel(pf, vsi, ch, seid, vsi_type);
  5251. if (ret) {
  5252. dev_err(&pf->pdev->dev, "failed to setup hw_channel\n");
  5253. return false;
  5254. }
  5255. return ch->initialized ? true : false;
  5256. }
  5257. /**
  5258. * i40e_validate_and_set_switch_mode - sets up switch mode correctly
  5259. * @vsi: ptr to VSI which has PF backing
  5260. *
  5261. * Sets up switch mode correctly if it needs to be changed and perform
  5262. * what are allowed modes.
  5263. **/
  5264. static int i40e_validate_and_set_switch_mode(struct i40e_vsi *vsi)
  5265. {
  5266. u8 mode;
  5267. struct i40e_pf *pf = vsi->back;
  5268. struct i40e_hw *hw = &pf->hw;
  5269. int ret;
  5270. ret = i40e_get_capabilities(pf, i40e_aqc_opc_list_dev_capabilities);
  5271. if (ret)
  5272. return -EINVAL;
  5273. if (hw->dev_caps.switch_mode) {
  5274. /* if switch mode is set, support mode2 (non-tunneled for
  5275. * cloud filter) for now
  5276. */
  5277. u32 switch_mode = hw->dev_caps.switch_mode &
  5278. I40E_SWITCH_MODE_MASK;
  5279. if (switch_mode >= I40E_CLOUD_FILTER_MODE1) {
  5280. if (switch_mode == I40E_CLOUD_FILTER_MODE2)
  5281. return 0;
  5282. dev_err(&pf->pdev->dev,
  5283. "Invalid switch_mode (%d), only non-tunneled mode for cloud filter is supported\n",
  5284. hw->dev_caps.switch_mode);
  5285. return -EINVAL;
  5286. }
  5287. }
  5288. /* Set Bit 7 to be valid */
  5289. mode = I40E_AQ_SET_SWITCH_BIT7_VALID;
  5290. /* Set L4type to both TCP and UDP support */
  5291. mode |= I40E_AQ_SET_SWITCH_L4_TYPE_BOTH;
  5292. /* Set cloud filter mode */
  5293. mode |= I40E_AQ_SET_SWITCH_MODE_NON_TUNNEL;
  5294. /* Prep mode field for set_switch_config */
  5295. ret = i40e_aq_set_switch_config(hw, pf->last_sw_conf_flags,
  5296. pf->last_sw_conf_valid_flags,
  5297. mode, NULL);
  5298. if (ret && hw->aq.asq_last_status != I40E_AQ_RC_ESRCH)
  5299. dev_err(&pf->pdev->dev,
  5300. "couldn't set switch config bits, err %s aq_err %s\n",
  5301. i40e_stat_str(hw, ret),
  5302. i40e_aq_str(hw,
  5303. hw->aq.asq_last_status));
  5304. return ret;
  5305. }
  5306. /**
  5307. * i40e_create_queue_channel - function to create channel
  5308. * @vsi: VSI to be configured
  5309. * @ch: ptr to channel (it contains channel specific params)
  5310. *
  5311. * This function creates channel (VSI) using num_queues specified by user,
  5312. * reconfigs RSS if needed.
  5313. **/
  5314. int i40e_create_queue_channel(struct i40e_vsi *vsi,
  5315. struct i40e_channel *ch)
  5316. {
  5317. struct i40e_pf *pf = vsi->back;
  5318. bool reconfig_rss;
  5319. int err;
  5320. if (!ch)
  5321. return -EINVAL;
  5322. if (!ch->num_queue_pairs) {
  5323. dev_err(&pf->pdev->dev, "Invalid num_queues requested: %d\n",
  5324. ch->num_queue_pairs);
  5325. return -EINVAL;
  5326. }
  5327. /* validate user requested num_queues for channel */
  5328. err = i40e_validate_num_queues(pf, ch->num_queue_pairs, vsi,
  5329. &reconfig_rss);
  5330. if (err) {
  5331. dev_info(&pf->pdev->dev, "Failed to validate num_queues (%d)\n",
  5332. ch->num_queue_pairs);
  5333. return -EINVAL;
  5334. }
  5335. /* By default we are in VEPA mode, if this is the first VF/VMDq
  5336. * VSI to be added switch to VEB mode.
  5337. */
  5338. if ((!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) ||
  5339. (!i40e_is_any_channel(vsi))) {
  5340. if (!is_power_of_2(vsi->tc_config.tc_info[0].qcount)) {
  5341. dev_dbg(&pf->pdev->dev,
  5342. "Failed to create channel. Override queues (%u) not power of 2\n",
  5343. vsi->tc_config.tc_info[0].qcount);
  5344. return -EINVAL;
  5345. }
  5346. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  5347. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  5348. if (vsi->type == I40E_VSI_MAIN) {
  5349. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  5350. i40e_do_reset(pf, I40E_PF_RESET_FLAG,
  5351. true);
  5352. else
  5353. i40e_do_reset_safe(pf,
  5354. I40E_PF_RESET_FLAG);
  5355. }
  5356. }
  5357. /* now onwards for main VSI, number of queues will be value
  5358. * of TC0's queue count
  5359. */
  5360. }
  5361. /* By this time, vsi->cnt_q_avail shall be set to non-zero and
  5362. * it should be more than num_queues
  5363. */
  5364. if (!vsi->cnt_q_avail || vsi->cnt_q_avail < ch->num_queue_pairs) {
  5365. dev_dbg(&pf->pdev->dev,
  5366. "Error: cnt_q_avail (%u) less than num_queues %d\n",
  5367. vsi->cnt_q_avail, ch->num_queue_pairs);
  5368. return -EINVAL;
  5369. }
  5370. /* reconfig_rss only if vsi type is MAIN_VSI */
  5371. if (reconfig_rss && (vsi->type == I40E_VSI_MAIN)) {
  5372. err = i40e_vsi_reconfig_rss(vsi, ch->num_queue_pairs);
  5373. if (err) {
  5374. dev_info(&pf->pdev->dev,
  5375. "Error: unable to reconfig rss for num_queues (%u)\n",
  5376. ch->num_queue_pairs);
  5377. return -EINVAL;
  5378. }
  5379. }
  5380. if (!i40e_setup_channel(pf, vsi, ch)) {
  5381. dev_info(&pf->pdev->dev, "Failed to setup channel\n");
  5382. return -EINVAL;
  5383. }
  5384. dev_info(&pf->pdev->dev,
  5385. "Setup channel (id:%u) utilizing num_queues %d\n",
  5386. ch->seid, ch->num_queue_pairs);
  5387. /* configure VSI for BW limit */
  5388. if (ch->max_tx_rate) {
  5389. u64 credits = ch->max_tx_rate;
  5390. if (i40e_set_bw_limit(vsi, ch->seid, ch->max_tx_rate))
  5391. return -EINVAL;
  5392. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  5393. dev_dbg(&pf->pdev->dev,
  5394. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  5395. ch->max_tx_rate,
  5396. credits,
  5397. ch->seid);
  5398. }
  5399. /* in case of VF, this will be main SRIOV VSI */
  5400. ch->parent_vsi = vsi;
  5401. /* and update main_vsi's count for queue_available to use */
  5402. vsi->cnt_q_avail -= ch->num_queue_pairs;
  5403. return 0;
  5404. }
  5405. /**
  5406. * i40e_configure_queue_channels - Add queue channel for the given TCs
  5407. * @vsi: VSI to be configured
  5408. *
  5409. * Configures queue channel mapping to the given TCs
  5410. **/
  5411. static int i40e_configure_queue_channels(struct i40e_vsi *vsi)
  5412. {
  5413. struct i40e_channel *ch;
  5414. u64 max_rate = 0;
  5415. int ret = 0, i;
  5416. /* Create app vsi with the TCs. Main VSI with TC0 is already set up */
  5417. vsi->tc_seid_map[0] = vsi->seid;
  5418. for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5419. if (vsi->tc_config.enabled_tc & BIT(i)) {
  5420. ch = kzalloc(sizeof(*ch), GFP_KERNEL);
  5421. if (!ch) {
  5422. ret = -ENOMEM;
  5423. goto err_free;
  5424. }
  5425. INIT_LIST_HEAD(&ch->list);
  5426. ch->num_queue_pairs =
  5427. vsi->tc_config.tc_info[i].qcount;
  5428. ch->base_queue =
  5429. vsi->tc_config.tc_info[i].qoffset;
  5430. /* Bandwidth limit through tc interface is in bytes/s,
  5431. * change to Mbit/s
  5432. */
  5433. max_rate = vsi->mqprio_qopt.max_rate[i];
  5434. do_div(max_rate, I40E_BW_MBPS_DIVISOR);
  5435. ch->max_tx_rate = max_rate;
  5436. list_add_tail(&ch->list, &vsi->ch_list);
  5437. ret = i40e_create_queue_channel(vsi, ch);
  5438. if (ret) {
  5439. dev_err(&vsi->back->pdev->dev,
  5440. "Failed creating queue channel with TC%d: queues %d\n",
  5441. i, ch->num_queue_pairs);
  5442. goto err_free;
  5443. }
  5444. vsi->tc_seid_map[i] = ch->seid;
  5445. }
  5446. }
  5447. return ret;
  5448. err_free:
  5449. i40e_remove_queue_channels(vsi);
  5450. return ret;
  5451. }
  5452. /**
  5453. * i40e_veb_config_tc - Configure TCs for given VEB
  5454. * @veb: given VEB
  5455. * @enabled_tc: TC bitmap
  5456. *
  5457. * Configures given TC bitmap for VEB (switching) element
  5458. **/
  5459. int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
  5460. {
  5461. struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
  5462. struct i40e_pf *pf = veb->pf;
  5463. int ret = 0;
  5464. int i;
  5465. /* No TCs or already enabled TCs just return */
  5466. if (!enabled_tc || veb->enabled_tc == enabled_tc)
  5467. return ret;
  5468. bw_data.tc_valid_bits = enabled_tc;
  5469. /* bw_data.absolute_credits is not set (relative) */
  5470. /* Enable ETS TCs with equal BW Share for now */
  5471. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5472. if (enabled_tc & BIT(i))
  5473. bw_data.tc_bw_share_credits[i] = 1;
  5474. }
  5475. ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
  5476. &bw_data, NULL);
  5477. if (ret) {
  5478. dev_info(&pf->pdev->dev,
  5479. "VEB bw config failed, err %s aq_err %s\n",
  5480. i40e_stat_str(&pf->hw, ret),
  5481. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5482. goto out;
  5483. }
  5484. /* Update the BW information */
  5485. ret = i40e_veb_get_bw_info(veb);
  5486. if (ret) {
  5487. dev_info(&pf->pdev->dev,
  5488. "Failed getting veb bw config, err %s aq_err %s\n",
  5489. i40e_stat_str(&pf->hw, ret),
  5490. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5491. }
  5492. out:
  5493. return ret;
  5494. }
  5495. #ifdef CONFIG_I40E_DCB
  5496. /**
  5497. * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
  5498. * @pf: PF struct
  5499. *
  5500. * Reconfigure VEB/VSIs on a given PF; it is assumed that
  5501. * the caller would've quiesce all the VSIs before calling
  5502. * this function
  5503. **/
  5504. static void i40e_dcb_reconfigure(struct i40e_pf *pf)
  5505. {
  5506. u8 tc_map = 0;
  5507. int ret;
  5508. u8 v;
  5509. /* Enable the TCs available on PF to all VEBs */
  5510. tc_map = i40e_pf_get_tc_map(pf);
  5511. for (v = 0; v < I40E_MAX_VEB; v++) {
  5512. if (!pf->veb[v])
  5513. continue;
  5514. ret = i40e_veb_config_tc(pf->veb[v], tc_map);
  5515. if (ret) {
  5516. dev_info(&pf->pdev->dev,
  5517. "Failed configuring TC for VEB seid=%d\n",
  5518. pf->veb[v]->seid);
  5519. /* Will try to configure as many components */
  5520. }
  5521. }
  5522. /* Update each VSI */
  5523. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5524. if (!pf->vsi[v])
  5525. continue;
  5526. /* - Enable all TCs for the LAN VSI
  5527. * - For all others keep them at TC0 for now
  5528. */
  5529. if (v == pf->lan_vsi)
  5530. tc_map = i40e_pf_get_tc_map(pf);
  5531. else
  5532. tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
  5533. ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
  5534. if (ret) {
  5535. dev_info(&pf->pdev->dev,
  5536. "Failed configuring TC for VSI seid=%d\n",
  5537. pf->vsi[v]->seid);
  5538. /* Will try to configure as many components */
  5539. } else {
  5540. /* Re-configure VSI vectors based on updated TC map */
  5541. i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
  5542. if (pf->vsi[v]->netdev)
  5543. i40e_dcbnl_set_all(pf->vsi[v]);
  5544. }
  5545. }
  5546. }
  5547. /**
  5548. * i40e_resume_port_tx - Resume port Tx
  5549. * @pf: PF struct
  5550. *
  5551. * Resume a port's Tx and issue a PF reset in case of failure to
  5552. * resume.
  5553. **/
  5554. static int i40e_resume_port_tx(struct i40e_pf *pf)
  5555. {
  5556. struct i40e_hw *hw = &pf->hw;
  5557. int ret;
  5558. ret = i40e_aq_resume_port_tx(hw, NULL);
  5559. if (ret) {
  5560. dev_info(&pf->pdev->dev,
  5561. "Resume Port Tx failed, err %s aq_err %s\n",
  5562. i40e_stat_str(&pf->hw, ret),
  5563. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5564. /* Schedule PF reset to recover */
  5565. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  5566. i40e_service_event_schedule(pf);
  5567. }
  5568. return ret;
  5569. }
  5570. /**
  5571. * i40e_init_pf_dcb - Initialize DCB configuration
  5572. * @pf: PF being configured
  5573. *
  5574. * Query the current DCB configuration and cache it
  5575. * in the hardware structure
  5576. **/
  5577. static int i40e_init_pf_dcb(struct i40e_pf *pf)
  5578. {
  5579. struct i40e_hw *hw = &pf->hw;
  5580. int err = 0;
  5581. /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
  5582. if (pf->hw_features & I40E_HW_NO_DCB_SUPPORT)
  5583. goto out;
  5584. /* Get the initial DCB configuration */
  5585. err = i40e_init_dcb(hw);
  5586. if (!err) {
  5587. /* Device/Function is not DCBX capable */
  5588. if ((!hw->func_caps.dcb) ||
  5589. (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
  5590. dev_info(&pf->pdev->dev,
  5591. "DCBX offload is not supported or is disabled for this PF.\n");
  5592. } else {
  5593. /* When status is not DISABLED then DCBX in FW */
  5594. pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
  5595. DCB_CAP_DCBX_VER_IEEE;
  5596. pf->flags |= I40E_FLAG_DCB_CAPABLE;
  5597. /* Enable DCB tagging only when more than one TC
  5598. * or explicitly disable if only one TC
  5599. */
  5600. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  5601. pf->flags |= I40E_FLAG_DCB_ENABLED;
  5602. else
  5603. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  5604. dev_dbg(&pf->pdev->dev,
  5605. "DCBX offload is supported for this PF.\n");
  5606. }
  5607. } else {
  5608. dev_info(&pf->pdev->dev,
  5609. "Query for DCB configuration failed, err %s aq_err %s\n",
  5610. i40e_stat_str(&pf->hw, err),
  5611. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5612. }
  5613. out:
  5614. return err;
  5615. }
  5616. #endif /* CONFIG_I40E_DCB */
  5617. #define SPEED_SIZE 14
  5618. #define FC_SIZE 8
  5619. /**
  5620. * i40e_print_link_message - print link up or down
  5621. * @vsi: the VSI for which link needs a message
  5622. */
  5623. void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
  5624. {
  5625. enum i40e_aq_link_speed new_speed;
  5626. struct i40e_pf *pf = vsi->back;
  5627. char *speed = "Unknown";
  5628. char *fc = "Unknown";
  5629. char *fec = "";
  5630. char *req_fec = "";
  5631. char *an = "";
  5632. new_speed = pf->hw.phy.link_info.link_speed;
  5633. if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed))
  5634. return;
  5635. vsi->current_isup = isup;
  5636. vsi->current_speed = new_speed;
  5637. if (!isup) {
  5638. netdev_info(vsi->netdev, "NIC Link is Down\n");
  5639. return;
  5640. }
  5641. /* Warn user if link speed on NPAR enabled partition is not at
  5642. * least 10GB
  5643. */
  5644. if (pf->hw.func_caps.npar_enable &&
  5645. (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
  5646. pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
  5647. netdev_warn(vsi->netdev,
  5648. "The partition detected link speed that is less than 10Gbps\n");
  5649. switch (pf->hw.phy.link_info.link_speed) {
  5650. case I40E_LINK_SPEED_40GB:
  5651. speed = "40 G";
  5652. break;
  5653. case I40E_LINK_SPEED_20GB:
  5654. speed = "20 G";
  5655. break;
  5656. case I40E_LINK_SPEED_25GB:
  5657. speed = "25 G";
  5658. break;
  5659. case I40E_LINK_SPEED_10GB:
  5660. speed = "10 G";
  5661. break;
  5662. case I40E_LINK_SPEED_1GB:
  5663. speed = "1000 M";
  5664. break;
  5665. case I40E_LINK_SPEED_100MB:
  5666. speed = "100 M";
  5667. break;
  5668. default:
  5669. break;
  5670. }
  5671. switch (pf->hw.fc.current_mode) {
  5672. case I40E_FC_FULL:
  5673. fc = "RX/TX";
  5674. break;
  5675. case I40E_FC_TX_PAUSE:
  5676. fc = "TX";
  5677. break;
  5678. case I40E_FC_RX_PAUSE:
  5679. fc = "RX";
  5680. break;
  5681. default:
  5682. fc = "None";
  5683. break;
  5684. }
  5685. if (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) {
  5686. req_fec = ", Requested FEC: None";
  5687. fec = ", FEC: None";
  5688. an = ", Autoneg: False";
  5689. if (pf->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED)
  5690. an = ", Autoneg: True";
  5691. if (pf->hw.phy.link_info.fec_info &
  5692. I40E_AQ_CONFIG_FEC_KR_ENA)
  5693. fec = ", FEC: CL74 FC-FEC/BASE-R";
  5694. else if (pf->hw.phy.link_info.fec_info &
  5695. I40E_AQ_CONFIG_FEC_RS_ENA)
  5696. fec = ", FEC: CL108 RS-FEC";
  5697. /* 'CL108 RS-FEC' should be displayed when RS is requested, or
  5698. * both RS and FC are requested
  5699. */
  5700. if (vsi->back->hw.phy.link_info.req_fec_info &
  5701. (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS)) {
  5702. if (vsi->back->hw.phy.link_info.req_fec_info &
  5703. I40E_AQ_REQUEST_FEC_RS)
  5704. req_fec = ", Requested FEC: CL108 RS-FEC";
  5705. else
  5706. req_fec = ", Requested FEC: CL74 FC-FEC/BASE-R";
  5707. }
  5708. }
  5709. netdev_info(vsi->netdev, "NIC Link is Up, %sbps Full Duplex%s%s%s, Flow Control: %s\n",
  5710. speed, req_fec, fec, an, fc);
  5711. }
  5712. /**
  5713. * i40e_up_complete - Finish the last steps of bringing up a connection
  5714. * @vsi: the VSI being configured
  5715. **/
  5716. static int i40e_up_complete(struct i40e_vsi *vsi)
  5717. {
  5718. struct i40e_pf *pf = vsi->back;
  5719. int err;
  5720. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  5721. i40e_vsi_configure_msix(vsi);
  5722. else
  5723. i40e_configure_msi_and_legacy(vsi);
  5724. /* start rings */
  5725. err = i40e_vsi_start_rings(vsi);
  5726. if (err)
  5727. return err;
  5728. clear_bit(__I40E_VSI_DOWN, vsi->state);
  5729. i40e_napi_enable_all(vsi);
  5730. i40e_vsi_enable_irq(vsi);
  5731. if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
  5732. (vsi->netdev)) {
  5733. i40e_print_link_message(vsi, true);
  5734. netif_tx_start_all_queues(vsi->netdev);
  5735. netif_carrier_on(vsi->netdev);
  5736. }
  5737. /* replay FDIR SB filters */
  5738. if (vsi->type == I40E_VSI_FDIR) {
  5739. /* reset fd counters */
  5740. pf->fd_add_err = 0;
  5741. pf->fd_atr_cnt = 0;
  5742. i40e_fdir_filter_restore(vsi);
  5743. }
  5744. /* On the next run of the service_task, notify any clients of the new
  5745. * opened netdev
  5746. */
  5747. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  5748. i40e_service_event_schedule(pf);
  5749. return 0;
  5750. }
  5751. /**
  5752. * i40e_vsi_reinit_locked - Reset the VSI
  5753. * @vsi: the VSI being configured
  5754. *
  5755. * Rebuild the ring structs after some configuration
  5756. * has changed, e.g. MTU size.
  5757. **/
  5758. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
  5759. {
  5760. struct i40e_pf *pf = vsi->back;
  5761. WARN_ON(in_interrupt());
  5762. while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state))
  5763. usleep_range(1000, 2000);
  5764. i40e_down(vsi);
  5765. i40e_up(vsi);
  5766. clear_bit(__I40E_CONFIG_BUSY, pf->state);
  5767. }
  5768. /**
  5769. * i40e_up - Bring the connection back up after being down
  5770. * @vsi: the VSI being configured
  5771. **/
  5772. int i40e_up(struct i40e_vsi *vsi)
  5773. {
  5774. int err;
  5775. err = i40e_vsi_configure(vsi);
  5776. if (!err)
  5777. err = i40e_up_complete(vsi);
  5778. return err;
  5779. }
  5780. /**
  5781. * i40e_down - Shutdown the connection processing
  5782. * @vsi: the VSI being stopped
  5783. **/
  5784. void i40e_down(struct i40e_vsi *vsi)
  5785. {
  5786. int i;
  5787. /* It is assumed that the caller of this function
  5788. * sets the vsi->state __I40E_VSI_DOWN bit.
  5789. */
  5790. if (vsi->netdev) {
  5791. netif_carrier_off(vsi->netdev);
  5792. netif_tx_disable(vsi->netdev);
  5793. }
  5794. i40e_vsi_disable_irq(vsi);
  5795. i40e_vsi_stop_rings(vsi);
  5796. i40e_napi_disable_all(vsi);
  5797. for (i = 0; i < vsi->num_queue_pairs; i++) {
  5798. i40e_clean_tx_ring(vsi->tx_rings[i]);
  5799. if (i40e_enabled_xdp_vsi(vsi))
  5800. i40e_clean_tx_ring(vsi->xdp_rings[i]);
  5801. i40e_clean_rx_ring(vsi->rx_rings[i]);
  5802. }
  5803. }
  5804. /**
  5805. * i40e_validate_mqprio_qopt- validate queue mapping info
  5806. * @vsi: the VSI being configured
  5807. * @mqprio_qopt: queue parametrs
  5808. **/
  5809. static int i40e_validate_mqprio_qopt(struct i40e_vsi *vsi,
  5810. struct tc_mqprio_qopt_offload *mqprio_qopt)
  5811. {
  5812. u64 sum_max_rate = 0;
  5813. u64 max_rate = 0;
  5814. int i;
  5815. if (mqprio_qopt->qopt.offset[0] != 0 ||
  5816. mqprio_qopt->qopt.num_tc < 1 ||
  5817. mqprio_qopt->qopt.num_tc > I40E_MAX_TRAFFIC_CLASS)
  5818. return -EINVAL;
  5819. for (i = 0; ; i++) {
  5820. if (!mqprio_qopt->qopt.count[i])
  5821. return -EINVAL;
  5822. if (mqprio_qopt->min_rate[i]) {
  5823. dev_err(&vsi->back->pdev->dev,
  5824. "Invalid min tx rate (greater than 0) specified\n");
  5825. return -EINVAL;
  5826. }
  5827. max_rate = mqprio_qopt->max_rate[i];
  5828. do_div(max_rate, I40E_BW_MBPS_DIVISOR);
  5829. sum_max_rate += max_rate;
  5830. if (i >= mqprio_qopt->qopt.num_tc - 1)
  5831. break;
  5832. if (mqprio_qopt->qopt.offset[i + 1] !=
  5833. (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i]))
  5834. return -EINVAL;
  5835. }
  5836. if (vsi->num_queue_pairs <
  5837. (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i])) {
  5838. return -EINVAL;
  5839. }
  5840. if (sum_max_rate > i40e_get_link_speed(vsi)) {
  5841. dev_err(&vsi->back->pdev->dev,
  5842. "Invalid max tx rate specified\n");
  5843. return -EINVAL;
  5844. }
  5845. return 0;
  5846. }
  5847. /**
  5848. * i40e_vsi_set_default_tc_config - set default values for tc configuration
  5849. * @vsi: the VSI being configured
  5850. **/
  5851. static void i40e_vsi_set_default_tc_config(struct i40e_vsi *vsi)
  5852. {
  5853. u16 qcount;
  5854. int i;
  5855. /* Only TC0 is enabled */
  5856. vsi->tc_config.numtc = 1;
  5857. vsi->tc_config.enabled_tc = 1;
  5858. qcount = min_t(int, vsi->alloc_queue_pairs,
  5859. i40e_pf_get_max_q_per_tc(vsi->back));
  5860. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5861. /* For the TC that is not enabled set the offset to to default
  5862. * queue and allocate one queue for the given TC.
  5863. */
  5864. vsi->tc_config.tc_info[i].qoffset = 0;
  5865. if (i == 0)
  5866. vsi->tc_config.tc_info[i].qcount = qcount;
  5867. else
  5868. vsi->tc_config.tc_info[i].qcount = 1;
  5869. vsi->tc_config.tc_info[i].netdev_tc = 0;
  5870. }
  5871. }
  5872. /**
  5873. * i40e_setup_tc - configure multiple traffic classes
  5874. * @netdev: net device to configure
  5875. * @type_data: tc offload data
  5876. **/
  5877. static int i40e_setup_tc(struct net_device *netdev, void *type_data)
  5878. {
  5879. struct tc_mqprio_qopt_offload *mqprio_qopt = type_data;
  5880. struct i40e_netdev_priv *np = netdev_priv(netdev);
  5881. struct i40e_vsi *vsi = np->vsi;
  5882. struct i40e_pf *pf = vsi->back;
  5883. u8 enabled_tc = 0, num_tc, hw;
  5884. bool need_reset = false;
  5885. int ret = -EINVAL;
  5886. u16 mode;
  5887. int i;
  5888. num_tc = mqprio_qopt->qopt.num_tc;
  5889. hw = mqprio_qopt->qopt.hw;
  5890. mode = mqprio_qopt->mode;
  5891. if (!hw) {
  5892. pf->flags &= ~I40E_FLAG_TC_MQPRIO;
  5893. memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt));
  5894. goto config_tc;
  5895. }
  5896. /* Check if MFP enabled */
  5897. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  5898. netdev_info(netdev,
  5899. "Configuring TC not supported in MFP mode\n");
  5900. return ret;
  5901. }
  5902. switch (mode) {
  5903. case TC_MQPRIO_MODE_DCB:
  5904. pf->flags &= ~I40E_FLAG_TC_MQPRIO;
  5905. /* Check if DCB enabled to continue */
  5906. if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  5907. netdev_info(netdev,
  5908. "DCB is not enabled for adapter\n");
  5909. return ret;
  5910. }
  5911. /* Check whether tc count is within enabled limit */
  5912. if (num_tc > i40e_pf_get_num_tc(pf)) {
  5913. netdev_info(netdev,
  5914. "TC count greater than enabled on link for adapter\n");
  5915. return ret;
  5916. }
  5917. break;
  5918. case TC_MQPRIO_MODE_CHANNEL:
  5919. if (pf->flags & I40E_FLAG_DCB_ENABLED) {
  5920. netdev_info(netdev,
  5921. "Full offload of TC Mqprio options is not supported when DCB is enabled\n");
  5922. return ret;
  5923. }
  5924. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  5925. return ret;
  5926. ret = i40e_validate_mqprio_qopt(vsi, mqprio_qopt);
  5927. if (ret)
  5928. return ret;
  5929. memcpy(&vsi->mqprio_qopt, mqprio_qopt,
  5930. sizeof(*mqprio_qopt));
  5931. pf->flags |= I40E_FLAG_TC_MQPRIO;
  5932. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  5933. break;
  5934. default:
  5935. return -EINVAL;
  5936. }
  5937. config_tc:
  5938. /* Generate TC map for number of tc requested */
  5939. for (i = 0; i < num_tc; i++)
  5940. enabled_tc |= BIT(i);
  5941. /* Requesting same TC configuration as already enabled */
  5942. if (enabled_tc == vsi->tc_config.enabled_tc &&
  5943. mode != TC_MQPRIO_MODE_CHANNEL)
  5944. return 0;
  5945. /* Quiesce VSI queues */
  5946. i40e_quiesce_vsi(vsi);
  5947. if (!hw && !(pf->flags & I40E_FLAG_TC_MQPRIO))
  5948. i40e_remove_queue_channels(vsi);
  5949. /* Configure VSI for enabled TCs */
  5950. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  5951. if (ret) {
  5952. netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
  5953. vsi->seid);
  5954. need_reset = true;
  5955. goto exit;
  5956. }
  5957. if (pf->flags & I40E_FLAG_TC_MQPRIO) {
  5958. if (vsi->mqprio_qopt.max_rate[0]) {
  5959. u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
  5960. do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
  5961. ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
  5962. if (!ret) {
  5963. u64 credits = max_tx_rate;
  5964. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  5965. dev_dbg(&vsi->back->pdev->dev,
  5966. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  5967. max_tx_rate,
  5968. credits,
  5969. vsi->seid);
  5970. } else {
  5971. need_reset = true;
  5972. goto exit;
  5973. }
  5974. }
  5975. ret = i40e_configure_queue_channels(vsi);
  5976. if (ret) {
  5977. netdev_info(netdev,
  5978. "Failed configuring queue channels\n");
  5979. need_reset = true;
  5980. goto exit;
  5981. }
  5982. }
  5983. exit:
  5984. /* Reset the configuration data to defaults, only TC0 is enabled */
  5985. if (need_reset) {
  5986. i40e_vsi_set_default_tc_config(vsi);
  5987. need_reset = false;
  5988. }
  5989. /* Unquiesce VSI */
  5990. i40e_unquiesce_vsi(vsi);
  5991. return ret;
  5992. }
  5993. /**
  5994. * i40e_set_cld_element - sets cloud filter element data
  5995. * @filter: cloud filter rule
  5996. * @cld: ptr to cloud filter element data
  5997. *
  5998. * This is helper function to copy data into cloud filter element
  5999. **/
  6000. static inline void
  6001. i40e_set_cld_element(struct i40e_cloud_filter *filter,
  6002. struct i40e_aqc_cloud_filters_element_data *cld)
  6003. {
  6004. int i, j;
  6005. u32 ipa;
  6006. memset(cld, 0, sizeof(*cld));
  6007. ether_addr_copy(cld->outer_mac, filter->dst_mac);
  6008. ether_addr_copy(cld->inner_mac, filter->src_mac);
  6009. if (filter->n_proto != ETH_P_IP && filter->n_proto != ETH_P_IPV6)
  6010. return;
  6011. if (filter->n_proto == ETH_P_IPV6) {
  6012. #define IPV6_MAX_INDEX (ARRAY_SIZE(filter->dst_ipv6) - 1)
  6013. for (i = 0, j = 0; i < ARRAY_SIZE(filter->dst_ipv6);
  6014. i++, j += 2) {
  6015. ipa = be32_to_cpu(filter->dst_ipv6[IPV6_MAX_INDEX - i]);
  6016. ipa = cpu_to_le32(ipa);
  6017. memcpy(&cld->ipaddr.raw_v6.data[j], &ipa, sizeof(ipa));
  6018. }
  6019. } else {
  6020. ipa = be32_to_cpu(filter->dst_ipv4);
  6021. memcpy(&cld->ipaddr.v4.data, &ipa, sizeof(ipa));
  6022. }
  6023. cld->inner_vlan = cpu_to_le16(ntohs(filter->vlan_id));
  6024. /* tenant_id is not supported by FW now, once the support is enabled
  6025. * fill the cld->tenant_id with cpu_to_le32(filter->tenant_id)
  6026. */
  6027. if (filter->tenant_id)
  6028. return;
  6029. }
  6030. /**
  6031. * i40e_add_del_cloud_filter - Add/del cloud filter
  6032. * @vsi: pointer to VSI
  6033. * @filter: cloud filter rule
  6034. * @add: if true, add, if false, delete
  6035. *
  6036. * Add or delete a cloud filter for a specific flow spec.
  6037. * Returns 0 if the filter were successfully added.
  6038. **/
  6039. static int i40e_add_del_cloud_filter(struct i40e_vsi *vsi,
  6040. struct i40e_cloud_filter *filter, bool add)
  6041. {
  6042. struct i40e_aqc_cloud_filters_element_data cld_filter;
  6043. struct i40e_pf *pf = vsi->back;
  6044. int ret;
  6045. static const u16 flag_table[128] = {
  6046. [I40E_CLOUD_FILTER_FLAGS_OMAC] =
  6047. I40E_AQC_ADD_CLOUD_FILTER_OMAC,
  6048. [I40E_CLOUD_FILTER_FLAGS_IMAC] =
  6049. I40E_AQC_ADD_CLOUD_FILTER_IMAC,
  6050. [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN] =
  6051. I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN,
  6052. [I40E_CLOUD_FILTER_FLAGS_IMAC_TEN_ID] =
  6053. I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID,
  6054. [I40E_CLOUD_FILTER_FLAGS_OMAC_TEN_ID_IMAC] =
  6055. I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC,
  6056. [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN_TEN_ID] =
  6057. I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID,
  6058. [I40E_CLOUD_FILTER_FLAGS_IIP] =
  6059. I40E_AQC_ADD_CLOUD_FILTER_IIP,
  6060. };
  6061. if (filter->flags >= ARRAY_SIZE(flag_table))
  6062. return I40E_ERR_CONFIG;
  6063. /* copy element needed to add cloud filter from filter */
  6064. i40e_set_cld_element(filter, &cld_filter);
  6065. if (filter->tunnel_type != I40E_CLOUD_TNL_TYPE_NONE)
  6066. cld_filter.flags = cpu_to_le16(filter->tunnel_type <<
  6067. I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT);
  6068. if (filter->n_proto == ETH_P_IPV6)
  6069. cld_filter.flags |= cpu_to_le16(flag_table[filter->flags] |
  6070. I40E_AQC_ADD_CLOUD_FLAGS_IPV6);
  6071. else
  6072. cld_filter.flags |= cpu_to_le16(flag_table[filter->flags] |
  6073. I40E_AQC_ADD_CLOUD_FLAGS_IPV4);
  6074. if (add)
  6075. ret = i40e_aq_add_cloud_filters(&pf->hw, filter->seid,
  6076. &cld_filter, 1);
  6077. else
  6078. ret = i40e_aq_rem_cloud_filters(&pf->hw, filter->seid,
  6079. &cld_filter, 1);
  6080. if (ret)
  6081. dev_dbg(&pf->pdev->dev,
  6082. "Failed to %s cloud filter using l4 port %u, err %d aq_err %d\n",
  6083. add ? "add" : "delete", filter->dst_port, ret,
  6084. pf->hw.aq.asq_last_status);
  6085. else
  6086. dev_info(&pf->pdev->dev,
  6087. "%s cloud filter for VSI: %d\n",
  6088. add ? "Added" : "Deleted", filter->seid);
  6089. return ret;
  6090. }
  6091. /**
  6092. * i40e_add_del_cloud_filter_big_buf - Add/del cloud filter using big_buf
  6093. * @vsi: pointer to VSI
  6094. * @filter: cloud filter rule
  6095. * @add: if true, add, if false, delete
  6096. *
  6097. * Add or delete a cloud filter for a specific flow spec using big buffer.
  6098. * Returns 0 if the filter were successfully added.
  6099. **/
  6100. static int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi *vsi,
  6101. struct i40e_cloud_filter *filter,
  6102. bool add)
  6103. {
  6104. struct i40e_aqc_cloud_filters_element_bb cld_filter;
  6105. struct i40e_pf *pf = vsi->back;
  6106. int ret;
  6107. /* Both (src/dst) valid mac_addr are not supported */
  6108. if ((is_valid_ether_addr(filter->dst_mac) &&
  6109. is_valid_ether_addr(filter->src_mac)) ||
  6110. (is_multicast_ether_addr(filter->dst_mac) &&
  6111. is_multicast_ether_addr(filter->src_mac)))
  6112. return -EINVAL;
  6113. /* Make sure port is specified, otherwise bail out, for channel
  6114. * specific cloud filter needs 'L4 port' to be non-zero
  6115. */
  6116. if (!filter->dst_port)
  6117. return -EINVAL;
  6118. /* adding filter using src_port/src_ip is not supported at this stage */
  6119. if (filter->src_port || filter->src_ipv4 ||
  6120. !ipv6_addr_any(&filter->ip.v6.src_ip6))
  6121. return -EINVAL;
  6122. /* copy element needed to add cloud filter from filter */
  6123. i40e_set_cld_element(filter, &cld_filter.element);
  6124. if (is_valid_ether_addr(filter->dst_mac) ||
  6125. is_valid_ether_addr(filter->src_mac) ||
  6126. is_multicast_ether_addr(filter->dst_mac) ||
  6127. is_multicast_ether_addr(filter->src_mac)) {
  6128. /* MAC + IP : unsupported mode */
  6129. if (filter->dst_ipv4)
  6130. return -EINVAL;
  6131. /* since we validated that L4 port must be valid before
  6132. * we get here, start with respective "flags" value
  6133. * and update if vlan is present or not
  6134. */
  6135. cld_filter.element.flags =
  6136. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_PORT);
  6137. if (filter->vlan_id) {
  6138. cld_filter.element.flags =
  6139. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_VLAN_PORT);
  6140. }
  6141. } else if (filter->dst_ipv4 ||
  6142. !ipv6_addr_any(&filter->ip.v6.dst_ip6)) {
  6143. cld_filter.element.flags =
  6144. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_IP_PORT);
  6145. if (filter->n_proto == ETH_P_IPV6)
  6146. cld_filter.element.flags |=
  6147. cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV6);
  6148. else
  6149. cld_filter.element.flags |=
  6150. cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV4);
  6151. } else {
  6152. dev_err(&pf->pdev->dev,
  6153. "either mac or ip has to be valid for cloud filter\n");
  6154. return -EINVAL;
  6155. }
  6156. /* Now copy L4 port in Byte 6..7 in general fields */
  6157. cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X16_WORD0] =
  6158. be16_to_cpu(filter->dst_port);
  6159. if (add) {
  6160. /* Validate current device switch mode, change if necessary */
  6161. ret = i40e_validate_and_set_switch_mode(vsi);
  6162. if (ret) {
  6163. dev_err(&pf->pdev->dev,
  6164. "failed to set switch mode, ret %d\n",
  6165. ret);
  6166. return ret;
  6167. }
  6168. ret = i40e_aq_add_cloud_filters_bb(&pf->hw, filter->seid,
  6169. &cld_filter, 1);
  6170. } else {
  6171. ret = i40e_aq_rem_cloud_filters_bb(&pf->hw, filter->seid,
  6172. &cld_filter, 1);
  6173. }
  6174. if (ret)
  6175. dev_dbg(&pf->pdev->dev,
  6176. "Failed to %s cloud filter(big buffer) err %d aq_err %d\n",
  6177. add ? "add" : "delete", ret, pf->hw.aq.asq_last_status);
  6178. else
  6179. dev_info(&pf->pdev->dev,
  6180. "%s cloud filter for VSI: %d, L4 port: %d\n",
  6181. add ? "add" : "delete", filter->seid,
  6182. ntohs(filter->dst_port));
  6183. return ret;
  6184. }
  6185. /**
  6186. * i40e_parse_cls_flower - Parse tc flower filters provided by kernel
  6187. * @vsi: Pointer to VSI
  6188. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6189. * @filter: Pointer to cloud filter structure
  6190. *
  6191. **/
  6192. static int i40e_parse_cls_flower(struct i40e_vsi *vsi,
  6193. struct tc_cls_flower_offload *f,
  6194. struct i40e_cloud_filter *filter)
  6195. {
  6196. u16 n_proto_mask = 0, n_proto_key = 0, addr_type = 0;
  6197. struct i40e_pf *pf = vsi->back;
  6198. u8 field_flags = 0;
  6199. if (f->dissector->used_keys &
  6200. ~(BIT(FLOW_DISSECTOR_KEY_CONTROL) |
  6201. BIT(FLOW_DISSECTOR_KEY_BASIC) |
  6202. BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) |
  6203. BIT(FLOW_DISSECTOR_KEY_VLAN) |
  6204. BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
  6205. BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
  6206. BIT(FLOW_DISSECTOR_KEY_PORTS) |
  6207. BIT(FLOW_DISSECTOR_KEY_ENC_KEYID))) {
  6208. dev_err(&pf->pdev->dev, "Unsupported key used: 0x%x\n",
  6209. f->dissector->used_keys);
  6210. return -EOPNOTSUPP;
  6211. }
  6212. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ENC_KEYID)) {
  6213. struct flow_dissector_key_keyid *key =
  6214. skb_flow_dissector_target(f->dissector,
  6215. FLOW_DISSECTOR_KEY_ENC_KEYID,
  6216. f->key);
  6217. struct flow_dissector_key_keyid *mask =
  6218. skb_flow_dissector_target(f->dissector,
  6219. FLOW_DISSECTOR_KEY_ENC_KEYID,
  6220. f->mask);
  6221. if (mask->keyid != 0)
  6222. field_flags |= I40E_CLOUD_FIELD_TEN_ID;
  6223. filter->tenant_id = be32_to_cpu(key->keyid);
  6224. }
  6225. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_BASIC)) {
  6226. struct flow_dissector_key_basic *key =
  6227. skb_flow_dissector_target(f->dissector,
  6228. FLOW_DISSECTOR_KEY_BASIC,
  6229. f->key);
  6230. struct flow_dissector_key_basic *mask =
  6231. skb_flow_dissector_target(f->dissector,
  6232. FLOW_DISSECTOR_KEY_BASIC,
  6233. f->mask);
  6234. n_proto_key = ntohs(key->n_proto);
  6235. n_proto_mask = ntohs(mask->n_proto);
  6236. if (n_proto_key == ETH_P_ALL) {
  6237. n_proto_key = 0;
  6238. n_proto_mask = 0;
  6239. }
  6240. filter->n_proto = n_proto_key & n_proto_mask;
  6241. filter->ip_proto = key->ip_proto;
  6242. }
  6243. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
  6244. struct flow_dissector_key_eth_addrs *key =
  6245. skb_flow_dissector_target(f->dissector,
  6246. FLOW_DISSECTOR_KEY_ETH_ADDRS,
  6247. f->key);
  6248. struct flow_dissector_key_eth_addrs *mask =
  6249. skb_flow_dissector_target(f->dissector,
  6250. FLOW_DISSECTOR_KEY_ETH_ADDRS,
  6251. f->mask);
  6252. /* use is_broadcast and is_zero to check for all 0xf or 0 */
  6253. if (!is_zero_ether_addr(mask->dst)) {
  6254. if (is_broadcast_ether_addr(mask->dst)) {
  6255. field_flags |= I40E_CLOUD_FIELD_OMAC;
  6256. } else {
  6257. dev_err(&pf->pdev->dev, "Bad ether dest mask %pM\n",
  6258. mask->dst);
  6259. return I40E_ERR_CONFIG;
  6260. }
  6261. }
  6262. if (!is_zero_ether_addr(mask->src)) {
  6263. if (is_broadcast_ether_addr(mask->src)) {
  6264. field_flags |= I40E_CLOUD_FIELD_IMAC;
  6265. } else {
  6266. dev_err(&pf->pdev->dev, "Bad ether src mask %pM\n",
  6267. mask->src);
  6268. return I40E_ERR_CONFIG;
  6269. }
  6270. }
  6271. ether_addr_copy(filter->dst_mac, key->dst);
  6272. ether_addr_copy(filter->src_mac, key->src);
  6273. }
  6274. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_VLAN)) {
  6275. struct flow_dissector_key_vlan *key =
  6276. skb_flow_dissector_target(f->dissector,
  6277. FLOW_DISSECTOR_KEY_VLAN,
  6278. f->key);
  6279. struct flow_dissector_key_vlan *mask =
  6280. skb_flow_dissector_target(f->dissector,
  6281. FLOW_DISSECTOR_KEY_VLAN,
  6282. f->mask);
  6283. if (mask->vlan_id) {
  6284. if (mask->vlan_id == VLAN_VID_MASK) {
  6285. field_flags |= I40E_CLOUD_FIELD_IVLAN;
  6286. } else {
  6287. dev_err(&pf->pdev->dev, "Bad vlan mask 0x%04x\n",
  6288. mask->vlan_id);
  6289. return I40E_ERR_CONFIG;
  6290. }
  6291. }
  6292. filter->vlan_id = cpu_to_be16(key->vlan_id);
  6293. }
  6294. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_CONTROL)) {
  6295. struct flow_dissector_key_control *key =
  6296. skb_flow_dissector_target(f->dissector,
  6297. FLOW_DISSECTOR_KEY_CONTROL,
  6298. f->key);
  6299. addr_type = key->addr_type;
  6300. }
  6301. if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
  6302. struct flow_dissector_key_ipv4_addrs *key =
  6303. skb_flow_dissector_target(f->dissector,
  6304. FLOW_DISSECTOR_KEY_IPV4_ADDRS,
  6305. f->key);
  6306. struct flow_dissector_key_ipv4_addrs *mask =
  6307. skb_flow_dissector_target(f->dissector,
  6308. FLOW_DISSECTOR_KEY_IPV4_ADDRS,
  6309. f->mask);
  6310. if (mask->dst) {
  6311. if (mask->dst == cpu_to_be32(0xffffffff)) {
  6312. field_flags |= I40E_CLOUD_FIELD_IIP;
  6313. } else {
  6314. mask->dst = be32_to_cpu(mask->dst);
  6315. dev_err(&pf->pdev->dev, "Bad ip dst mask %pI4\n",
  6316. &mask->dst);
  6317. return I40E_ERR_CONFIG;
  6318. }
  6319. }
  6320. if (mask->src) {
  6321. if (mask->src == cpu_to_be32(0xffffffff)) {
  6322. field_flags |= I40E_CLOUD_FIELD_IIP;
  6323. } else {
  6324. mask->src = be32_to_cpu(mask->src);
  6325. dev_err(&pf->pdev->dev, "Bad ip src mask %pI4\n",
  6326. &mask->src);
  6327. return I40E_ERR_CONFIG;
  6328. }
  6329. }
  6330. if (field_flags & I40E_CLOUD_FIELD_TEN_ID) {
  6331. dev_err(&pf->pdev->dev, "Tenant id not allowed for ip filter\n");
  6332. return I40E_ERR_CONFIG;
  6333. }
  6334. filter->dst_ipv4 = key->dst;
  6335. filter->src_ipv4 = key->src;
  6336. }
  6337. if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
  6338. struct flow_dissector_key_ipv6_addrs *key =
  6339. skb_flow_dissector_target(f->dissector,
  6340. FLOW_DISSECTOR_KEY_IPV6_ADDRS,
  6341. f->key);
  6342. struct flow_dissector_key_ipv6_addrs *mask =
  6343. skb_flow_dissector_target(f->dissector,
  6344. FLOW_DISSECTOR_KEY_IPV6_ADDRS,
  6345. f->mask);
  6346. /* src and dest IPV6 address should not be LOOPBACK
  6347. * (0:0:0:0:0:0:0:1), which can be represented as ::1
  6348. */
  6349. if (ipv6_addr_loopback(&key->dst) ||
  6350. ipv6_addr_loopback(&key->src)) {
  6351. dev_err(&pf->pdev->dev,
  6352. "Bad ipv6, addr is LOOPBACK\n");
  6353. return I40E_ERR_CONFIG;
  6354. }
  6355. if (!ipv6_addr_any(&mask->dst) || !ipv6_addr_any(&mask->src))
  6356. field_flags |= I40E_CLOUD_FIELD_IIP;
  6357. memcpy(&filter->src_ipv6, &key->src.s6_addr32,
  6358. sizeof(filter->src_ipv6));
  6359. memcpy(&filter->dst_ipv6, &key->dst.s6_addr32,
  6360. sizeof(filter->dst_ipv6));
  6361. }
  6362. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_PORTS)) {
  6363. struct flow_dissector_key_ports *key =
  6364. skb_flow_dissector_target(f->dissector,
  6365. FLOW_DISSECTOR_KEY_PORTS,
  6366. f->key);
  6367. struct flow_dissector_key_ports *mask =
  6368. skb_flow_dissector_target(f->dissector,
  6369. FLOW_DISSECTOR_KEY_PORTS,
  6370. f->mask);
  6371. if (mask->src) {
  6372. if (mask->src == cpu_to_be16(0xffff)) {
  6373. field_flags |= I40E_CLOUD_FIELD_IIP;
  6374. } else {
  6375. dev_err(&pf->pdev->dev, "Bad src port mask 0x%04x\n",
  6376. be16_to_cpu(mask->src));
  6377. return I40E_ERR_CONFIG;
  6378. }
  6379. }
  6380. if (mask->dst) {
  6381. if (mask->dst == cpu_to_be16(0xffff)) {
  6382. field_flags |= I40E_CLOUD_FIELD_IIP;
  6383. } else {
  6384. dev_err(&pf->pdev->dev, "Bad dst port mask 0x%04x\n",
  6385. be16_to_cpu(mask->dst));
  6386. return I40E_ERR_CONFIG;
  6387. }
  6388. }
  6389. filter->dst_port = key->dst;
  6390. filter->src_port = key->src;
  6391. switch (filter->ip_proto) {
  6392. case IPPROTO_TCP:
  6393. case IPPROTO_UDP:
  6394. break;
  6395. default:
  6396. dev_err(&pf->pdev->dev,
  6397. "Only UDP and TCP transport are supported\n");
  6398. return -EINVAL;
  6399. }
  6400. }
  6401. filter->flags = field_flags;
  6402. return 0;
  6403. }
  6404. /**
  6405. * i40e_handle_tclass: Forward to a traffic class on the device
  6406. * @vsi: Pointer to VSI
  6407. * @tc: traffic class index on the device
  6408. * @filter: Pointer to cloud filter structure
  6409. *
  6410. **/
  6411. static int i40e_handle_tclass(struct i40e_vsi *vsi, u32 tc,
  6412. struct i40e_cloud_filter *filter)
  6413. {
  6414. struct i40e_channel *ch, *ch_tmp;
  6415. /* direct to a traffic class on the same device */
  6416. if (tc == 0) {
  6417. filter->seid = vsi->seid;
  6418. return 0;
  6419. } else if (vsi->tc_config.enabled_tc & BIT(tc)) {
  6420. if (!filter->dst_port) {
  6421. dev_err(&vsi->back->pdev->dev,
  6422. "Specify destination port to direct to traffic class that is not default\n");
  6423. return -EINVAL;
  6424. }
  6425. if (list_empty(&vsi->ch_list))
  6426. return -EINVAL;
  6427. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list,
  6428. list) {
  6429. if (ch->seid == vsi->tc_seid_map[tc])
  6430. filter->seid = ch->seid;
  6431. }
  6432. return 0;
  6433. }
  6434. dev_err(&vsi->back->pdev->dev, "TC is not enabled\n");
  6435. return -EINVAL;
  6436. }
  6437. /**
  6438. * i40e_configure_clsflower - Configure tc flower filters
  6439. * @vsi: Pointer to VSI
  6440. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6441. *
  6442. **/
  6443. static int i40e_configure_clsflower(struct i40e_vsi *vsi,
  6444. struct tc_cls_flower_offload *cls_flower)
  6445. {
  6446. int tc = tc_classid_to_hwtc(vsi->netdev, cls_flower->classid);
  6447. struct i40e_cloud_filter *filter = NULL;
  6448. struct i40e_pf *pf = vsi->back;
  6449. int err = 0;
  6450. if (tc < 0) {
  6451. dev_err(&vsi->back->pdev->dev, "Invalid traffic class\n");
  6452. return -EINVAL;
  6453. }
  6454. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
  6455. test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
  6456. return -EBUSY;
  6457. if (pf->fdir_pf_active_filters ||
  6458. (!hlist_empty(&pf->fdir_filter_list))) {
  6459. dev_err(&vsi->back->pdev->dev,
  6460. "Flow Director Sideband filters exists, turn ntuple off to configure cloud filters\n");
  6461. return -EINVAL;
  6462. }
  6463. if (vsi->back->flags & I40E_FLAG_FD_SB_ENABLED) {
  6464. dev_err(&vsi->back->pdev->dev,
  6465. "Disable Flow Director Sideband, configuring Cloud filters via tc-flower\n");
  6466. vsi->back->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  6467. vsi->back->flags |= I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6468. }
  6469. filter = kzalloc(sizeof(*filter), GFP_KERNEL);
  6470. if (!filter)
  6471. return -ENOMEM;
  6472. filter->cookie = cls_flower->cookie;
  6473. err = i40e_parse_cls_flower(vsi, cls_flower, filter);
  6474. if (err < 0)
  6475. goto err;
  6476. err = i40e_handle_tclass(vsi, tc, filter);
  6477. if (err < 0)
  6478. goto err;
  6479. /* Add cloud filter */
  6480. if (filter->dst_port)
  6481. err = i40e_add_del_cloud_filter_big_buf(vsi, filter, true);
  6482. else
  6483. err = i40e_add_del_cloud_filter(vsi, filter, true);
  6484. if (err) {
  6485. dev_err(&pf->pdev->dev,
  6486. "Failed to add cloud filter, err %s\n",
  6487. i40e_stat_str(&pf->hw, err));
  6488. err = i40e_aq_rc_to_posix(err, pf->hw.aq.asq_last_status);
  6489. goto err;
  6490. }
  6491. /* add filter to the ordered list */
  6492. INIT_HLIST_NODE(&filter->cloud_node);
  6493. hlist_add_head(&filter->cloud_node, &pf->cloud_filter_list);
  6494. pf->num_cloud_filters++;
  6495. return err;
  6496. err:
  6497. kfree(filter);
  6498. return err;
  6499. }
  6500. /**
  6501. * i40e_find_cloud_filter - Find the could filter in the list
  6502. * @vsi: Pointer to VSI
  6503. * @cookie: filter specific cookie
  6504. *
  6505. **/
  6506. static struct i40e_cloud_filter *i40e_find_cloud_filter(struct i40e_vsi *vsi,
  6507. unsigned long *cookie)
  6508. {
  6509. struct i40e_cloud_filter *filter = NULL;
  6510. struct hlist_node *node2;
  6511. hlist_for_each_entry_safe(filter, node2,
  6512. &vsi->back->cloud_filter_list, cloud_node)
  6513. if (!memcmp(cookie, &filter->cookie, sizeof(filter->cookie)))
  6514. return filter;
  6515. return NULL;
  6516. }
  6517. /**
  6518. * i40e_delete_clsflower - Remove tc flower filters
  6519. * @vsi: Pointer to VSI
  6520. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6521. *
  6522. **/
  6523. static int i40e_delete_clsflower(struct i40e_vsi *vsi,
  6524. struct tc_cls_flower_offload *cls_flower)
  6525. {
  6526. struct i40e_cloud_filter *filter = NULL;
  6527. struct i40e_pf *pf = vsi->back;
  6528. int err = 0;
  6529. filter = i40e_find_cloud_filter(vsi, &cls_flower->cookie);
  6530. if (!filter)
  6531. return -EINVAL;
  6532. hash_del(&filter->cloud_node);
  6533. if (filter->dst_port)
  6534. err = i40e_add_del_cloud_filter_big_buf(vsi, filter, false);
  6535. else
  6536. err = i40e_add_del_cloud_filter(vsi, filter, false);
  6537. kfree(filter);
  6538. if (err) {
  6539. dev_err(&pf->pdev->dev,
  6540. "Failed to delete cloud filter, err %s\n",
  6541. i40e_stat_str(&pf->hw, err));
  6542. return i40e_aq_rc_to_posix(err, pf->hw.aq.asq_last_status);
  6543. }
  6544. pf->num_cloud_filters--;
  6545. if (!pf->num_cloud_filters)
  6546. if ((pf->flags & I40E_FLAG_FD_SB_TO_CLOUD_FILTER) &&
  6547. !(pf->flags & I40E_FLAG_FD_SB_INACTIVE)) {
  6548. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  6549. pf->flags &= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6550. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  6551. }
  6552. return 0;
  6553. }
  6554. /**
  6555. * i40e_setup_tc_cls_flower - flower classifier offloads
  6556. * @netdev: net device to configure
  6557. * @type_data: offload data
  6558. **/
  6559. static int i40e_setup_tc_cls_flower(struct i40e_netdev_priv *np,
  6560. struct tc_cls_flower_offload *cls_flower)
  6561. {
  6562. struct i40e_vsi *vsi = np->vsi;
  6563. if (cls_flower->common.chain_index)
  6564. return -EOPNOTSUPP;
  6565. switch (cls_flower->command) {
  6566. case TC_CLSFLOWER_REPLACE:
  6567. return i40e_configure_clsflower(vsi, cls_flower);
  6568. case TC_CLSFLOWER_DESTROY:
  6569. return i40e_delete_clsflower(vsi, cls_flower);
  6570. case TC_CLSFLOWER_STATS:
  6571. return -EOPNOTSUPP;
  6572. default:
  6573. return -EINVAL;
  6574. }
  6575. }
  6576. static int i40e_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
  6577. void *cb_priv)
  6578. {
  6579. struct i40e_netdev_priv *np = cb_priv;
  6580. switch (type) {
  6581. case TC_SETUP_CLSFLOWER:
  6582. return i40e_setup_tc_cls_flower(np, type_data);
  6583. default:
  6584. return -EOPNOTSUPP;
  6585. }
  6586. }
  6587. static int i40e_setup_tc_block(struct net_device *dev,
  6588. struct tc_block_offload *f)
  6589. {
  6590. struct i40e_netdev_priv *np = netdev_priv(dev);
  6591. if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
  6592. return -EOPNOTSUPP;
  6593. switch (f->command) {
  6594. case TC_BLOCK_BIND:
  6595. return tcf_block_cb_register(f->block, i40e_setup_tc_block_cb,
  6596. np, np);
  6597. case TC_BLOCK_UNBIND:
  6598. tcf_block_cb_unregister(f->block, i40e_setup_tc_block_cb, np);
  6599. return 0;
  6600. default:
  6601. return -EOPNOTSUPP;
  6602. }
  6603. }
  6604. static int __i40e_setup_tc(struct net_device *netdev, enum tc_setup_type type,
  6605. void *type_data)
  6606. {
  6607. switch (type) {
  6608. case TC_SETUP_MQPRIO:
  6609. return i40e_setup_tc(netdev, type_data);
  6610. case TC_SETUP_BLOCK:
  6611. return i40e_setup_tc_block(netdev, type_data);
  6612. default:
  6613. return -EOPNOTSUPP;
  6614. }
  6615. }
  6616. /**
  6617. * i40e_open - Called when a network interface is made active
  6618. * @netdev: network interface device structure
  6619. *
  6620. * The open entry point is called when a network interface is made
  6621. * active by the system (IFF_UP). At this point all resources needed
  6622. * for transmit and receive operations are allocated, the interrupt
  6623. * handler is registered with the OS, the netdev watchdog subtask is
  6624. * enabled, and the stack is notified that the interface is ready.
  6625. *
  6626. * Returns 0 on success, negative value on failure
  6627. **/
  6628. int i40e_open(struct net_device *netdev)
  6629. {
  6630. struct i40e_netdev_priv *np = netdev_priv(netdev);
  6631. struct i40e_vsi *vsi = np->vsi;
  6632. struct i40e_pf *pf = vsi->back;
  6633. int err;
  6634. /* disallow open during test or if eeprom is broken */
  6635. if (test_bit(__I40E_TESTING, pf->state) ||
  6636. test_bit(__I40E_BAD_EEPROM, pf->state))
  6637. return -EBUSY;
  6638. netif_carrier_off(netdev);
  6639. err = i40e_vsi_open(vsi);
  6640. if (err)
  6641. return err;
  6642. /* configure global TSO hardware offload settings */
  6643. wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
  6644. TCP_FLAG_FIN) >> 16);
  6645. wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
  6646. TCP_FLAG_FIN |
  6647. TCP_FLAG_CWR) >> 16);
  6648. wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
  6649. udp_tunnel_get_rx_info(netdev);
  6650. return 0;
  6651. }
  6652. /**
  6653. * i40e_vsi_open -
  6654. * @vsi: the VSI to open
  6655. *
  6656. * Finish initialization of the VSI.
  6657. *
  6658. * Returns 0 on success, negative value on failure
  6659. *
  6660. * Note: expects to be called while under rtnl_lock()
  6661. **/
  6662. int i40e_vsi_open(struct i40e_vsi *vsi)
  6663. {
  6664. struct i40e_pf *pf = vsi->back;
  6665. char int_name[I40E_INT_NAME_STR_LEN];
  6666. int err;
  6667. /* allocate descriptors */
  6668. err = i40e_vsi_setup_tx_resources(vsi);
  6669. if (err)
  6670. goto err_setup_tx;
  6671. err = i40e_vsi_setup_rx_resources(vsi);
  6672. if (err)
  6673. goto err_setup_rx;
  6674. err = i40e_vsi_configure(vsi);
  6675. if (err)
  6676. goto err_setup_rx;
  6677. if (vsi->netdev) {
  6678. snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
  6679. dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
  6680. err = i40e_vsi_request_irq(vsi, int_name);
  6681. if (err)
  6682. goto err_setup_rx;
  6683. /* Notify the stack of the actual queue counts. */
  6684. err = netif_set_real_num_tx_queues(vsi->netdev,
  6685. vsi->num_queue_pairs);
  6686. if (err)
  6687. goto err_set_queues;
  6688. err = netif_set_real_num_rx_queues(vsi->netdev,
  6689. vsi->num_queue_pairs);
  6690. if (err)
  6691. goto err_set_queues;
  6692. } else if (vsi->type == I40E_VSI_FDIR) {
  6693. snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
  6694. dev_driver_string(&pf->pdev->dev),
  6695. dev_name(&pf->pdev->dev));
  6696. err = i40e_vsi_request_irq(vsi, int_name);
  6697. } else {
  6698. err = -EINVAL;
  6699. goto err_setup_rx;
  6700. }
  6701. err = i40e_up_complete(vsi);
  6702. if (err)
  6703. goto err_up_complete;
  6704. return 0;
  6705. err_up_complete:
  6706. i40e_down(vsi);
  6707. err_set_queues:
  6708. i40e_vsi_free_irq(vsi);
  6709. err_setup_rx:
  6710. i40e_vsi_free_rx_resources(vsi);
  6711. err_setup_tx:
  6712. i40e_vsi_free_tx_resources(vsi);
  6713. if (vsi == pf->vsi[pf->lan_vsi])
  6714. i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
  6715. return err;
  6716. }
  6717. /**
  6718. * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
  6719. * @pf: Pointer to PF
  6720. *
  6721. * This function destroys the hlist where all the Flow Director
  6722. * filters were saved.
  6723. **/
  6724. static void i40e_fdir_filter_exit(struct i40e_pf *pf)
  6725. {
  6726. struct i40e_fdir_filter *filter;
  6727. struct i40e_flex_pit *pit_entry, *tmp;
  6728. struct hlist_node *node2;
  6729. hlist_for_each_entry_safe(filter, node2,
  6730. &pf->fdir_filter_list, fdir_node) {
  6731. hlist_del(&filter->fdir_node);
  6732. kfree(filter);
  6733. }
  6734. list_for_each_entry_safe(pit_entry, tmp, &pf->l3_flex_pit_list, list) {
  6735. list_del(&pit_entry->list);
  6736. kfree(pit_entry);
  6737. }
  6738. INIT_LIST_HEAD(&pf->l3_flex_pit_list);
  6739. list_for_each_entry_safe(pit_entry, tmp, &pf->l4_flex_pit_list, list) {
  6740. list_del(&pit_entry->list);
  6741. kfree(pit_entry);
  6742. }
  6743. INIT_LIST_HEAD(&pf->l4_flex_pit_list);
  6744. pf->fdir_pf_active_filters = 0;
  6745. pf->fd_tcp4_filter_cnt = 0;
  6746. pf->fd_udp4_filter_cnt = 0;
  6747. pf->fd_sctp4_filter_cnt = 0;
  6748. pf->fd_ip4_filter_cnt = 0;
  6749. /* Reprogram the default input set for TCP/IPv4 */
  6750. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
  6751. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6752. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6753. /* Reprogram the default input set for UDP/IPv4 */
  6754. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_UDP,
  6755. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6756. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6757. /* Reprogram the default input set for SCTP/IPv4 */
  6758. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP,
  6759. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6760. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6761. /* Reprogram the default input set for Other/IPv4 */
  6762. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER,
  6763. I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
  6764. }
  6765. /**
  6766. * i40e_cloud_filter_exit - Cleans up the cloud filters
  6767. * @pf: Pointer to PF
  6768. *
  6769. * This function destroys the hlist where all the cloud filters
  6770. * were saved.
  6771. **/
  6772. static void i40e_cloud_filter_exit(struct i40e_pf *pf)
  6773. {
  6774. struct i40e_cloud_filter *cfilter;
  6775. struct hlist_node *node;
  6776. hlist_for_each_entry_safe(cfilter, node,
  6777. &pf->cloud_filter_list, cloud_node) {
  6778. hlist_del(&cfilter->cloud_node);
  6779. kfree(cfilter);
  6780. }
  6781. pf->num_cloud_filters = 0;
  6782. if ((pf->flags & I40E_FLAG_FD_SB_TO_CLOUD_FILTER) &&
  6783. !(pf->flags & I40E_FLAG_FD_SB_INACTIVE)) {
  6784. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  6785. pf->flags &= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6786. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  6787. }
  6788. }
  6789. /**
  6790. * i40e_close - Disables a network interface
  6791. * @netdev: network interface device structure
  6792. *
  6793. * The close entry point is called when an interface is de-activated
  6794. * by the OS. The hardware is still under the driver's control, but
  6795. * this netdev interface is disabled.
  6796. *
  6797. * Returns 0, this is not allowed to fail
  6798. **/
  6799. int i40e_close(struct net_device *netdev)
  6800. {
  6801. struct i40e_netdev_priv *np = netdev_priv(netdev);
  6802. struct i40e_vsi *vsi = np->vsi;
  6803. i40e_vsi_close(vsi);
  6804. return 0;
  6805. }
  6806. /**
  6807. * i40e_do_reset - Start a PF or Core Reset sequence
  6808. * @pf: board private structure
  6809. * @reset_flags: which reset is requested
  6810. * @lock_acquired: indicates whether or not the lock has been acquired
  6811. * before this function was called.
  6812. *
  6813. * The essential difference in resets is that the PF Reset
  6814. * doesn't clear the packet buffers, doesn't reset the PE
  6815. * firmware, and doesn't bother the other PFs on the chip.
  6816. **/
  6817. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags, bool lock_acquired)
  6818. {
  6819. u32 val;
  6820. WARN_ON(in_interrupt());
  6821. /* do the biggest reset indicated */
  6822. if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
  6823. /* Request a Global Reset
  6824. *
  6825. * This will start the chip's countdown to the actual full
  6826. * chip reset event, and a warning interrupt to be sent
  6827. * to all PFs, including the requestor. Our handler
  6828. * for the warning interrupt will deal with the shutdown
  6829. * and recovery of the switch setup.
  6830. */
  6831. dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
  6832. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  6833. val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
  6834. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  6835. } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
  6836. /* Request a Core Reset
  6837. *
  6838. * Same as Global Reset, except does *not* include the MAC/PHY
  6839. */
  6840. dev_dbg(&pf->pdev->dev, "CoreR requested\n");
  6841. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  6842. val |= I40E_GLGEN_RTRIG_CORER_MASK;
  6843. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  6844. i40e_flush(&pf->hw);
  6845. } else if (reset_flags & I40E_PF_RESET_FLAG) {
  6846. /* Request a PF Reset
  6847. *
  6848. * Resets only the PF-specific registers
  6849. *
  6850. * This goes directly to the tear-down and rebuild of
  6851. * the switch, since we need to do all the recovery as
  6852. * for the Core Reset.
  6853. */
  6854. dev_dbg(&pf->pdev->dev, "PFR requested\n");
  6855. i40e_handle_reset_warning(pf, lock_acquired);
  6856. } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
  6857. int v;
  6858. /* Find the VSI(s) that requested a re-init */
  6859. dev_info(&pf->pdev->dev,
  6860. "VSI reinit requested\n");
  6861. for (v = 0; v < pf->num_alloc_vsi; v++) {
  6862. struct i40e_vsi *vsi = pf->vsi[v];
  6863. if (vsi != NULL &&
  6864. test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED,
  6865. vsi->state))
  6866. i40e_vsi_reinit_locked(pf->vsi[v]);
  6867. }
  6868. } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
  6869. int v;
  6870. /* Find the VSI(s) that needs to be brought down */
  6871. dev_info(&pf->pdev->dev, "VSI down requested\n");
  6872. for (v = 0; v < pf->num_alloc_vsi; v++) {
  6873. struct i40e_vsi *vsi = pf->vsi[v];
  6874. if (vsi != NULL &&
  6875. test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED,
  6876. vsi->state)) {
  6877. set_bit(__I40E_VSI_DOWN, vsi->state);
  6878. i40e_down(vsi);
  6879. }
  6880. }
  6881. } else {
  6882. dev_info(&pf->pdev->dev,
  6883. "bad reset request 0x%08x\n", reset_flags);
  6884. }
  6885. }
  6886. #ifdef CONFIG_I40E_DCB
  6887. /**
  6888. * i40e_dcb_need_reconfig - Check if DCB needs reconfig
  6889. * @pf: board private structure
  6890. * @old_cfg: current DCB config
  6891. * @new_cfg: new DCB config
  6892. **/
  6893. bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
  6894. struct i40e_dcbx_config *old_cfg,
  6895. struct i40e_dcbx_config *new_cfg)
  6896. {
  6897. bool need_reconfig = false;
  6898. /* Check if ETS configuration has changed */
  6899. if (memcmp(&new_cfg->etscfg,
  6900. &old_cfg->etscfg,
  6901. sizeof(new_cfg->etscfg))) {
  6902. /* If Priority Table has changed reconfig is needed */
  6903. if (memcmp(&new_cfg->etscfg.prioritytable,
  6904. &old_cfg->etscfg.prioritytable,
  6905. sizeof(new_cfg->etscfg.prioritytable))) {
  6906. need_reconfig = true;
  6907. dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
  6908. }
  6909. if (memcmp(&new_cfg->etscfg.tcbwtable,
  6910. &old_cfg->etscfg.tcbwtable,
  6911. sizeof(new_cfg->etscfg.tcbwtable)))
  6912. dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
  6913. if (memcmp(&new_cfg->etscfg.tsatable,
  6914. &old_cfg->etscfg.tsatable,
  6915. sizeof(new_cfg->etscfg.tsatable)))
  6916. dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
  6917. }
  6918. /* Check if PFC configuration has changed */
  6919. if (memcmp(&new_cfg->pfc,
  6920. &old_cfg->pfc,
  6921. sizeof(new_cfg->pfc))) {
  6922. need_reconfig = true;
  6923. dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
  6924. }
  6925. /* Check if APP Table has changed */
  6926. if (memcmp(&new_cfg->app,
  6927. &old_cfg->app,
  6928. sizeof(new_cfg->app))) {
  6929. need_reconfig = true;
  6930. dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
  6931. }
  6932. dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
  6933. return need_reconfig;
  6934. }
  6935. /**
  6936. * i40e_handle_lldp_event - Handle LLDP Change MIB event
  6937. * @pf: board private structure
  6938. * @e: event info posted on ARQ
  6939. **/
  6940. static int i40e_handle_lldp_event(struct i40e_pf *pf,
  6941. struct i40e_arq_event_info *e)
  6942. {
  6943. struct i40e_aqc_lldp_get_mib *mib =
  6944. (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
  6945. struct i40e_hw *hw = &pf->hw;
  6946. struct i40e_dcbx_config tmp_dcbx_cfg;
  6947. bool need_reconfig = false;
  6948. int ret = 0;
  6949. u8 type;
  6950. /* Not DCB capable or capability disabled */
  6951. if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
  6952. return ret;
  6953. /* Ignore if event is not for Nearest Bridge */
  6954. type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
  6955. & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  6956. dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
  6957. if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
  6958. return ret;
  6959. /* Check MIB Type and return if event for Remote MIB update */
  6960. type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  6961. dev_dbg(&pf->pdev->dev,
  6962. "LLDP event mib type %s\n", type ? "remote" : "local");
  6963. if (type == I40E_AQ_LLDP_MIB_REMOTE) {
  6964. /* Update the remote cached instance and return */
  6965. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  6966. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  6967. &hw->remote_dcbx_config);
  6968. goto exit;
  6969. }
  6970. /* Store the old configuration */
  6971. tmp_dcbx_cfg = hw->local_dcbx_config;
  6972. /* Reset the old DCBx configuration data */
  6973. memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
  6974. /* Get updated DCBX data from firmware */
  6975. ret = i40e_get_dcb_config(&pf->hw);
  6976. if (ret) {
  6977. dev_info(&pf->pdev->dev,
  6978. "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
  6979. i40e_stat_str(&pf->hw, ret),
  6980. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6981. goto exit;
  6982. }
  6983. /* No change detected in DCBX configs */
  6984. if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
  6985. sizeof(tmp_dcbx_cfg))) {
  6986. dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
  6987. goto exit;
  6988. }
  6989. need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
  6990. &hw->local_dcbx_config);
  6991. i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
  6992. if (!need_reconfig)
  6993. goto exit;
  6994. /* Enable DCB tagging only when more than one TC */
  6995. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  6996. pf->flags |= I40E_FLAG_DCB_ENABLED;
  6997. else
  6998. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  6999. set_bit(__I40E_PORT_SUSPENDED, pf->state);
  7000. /* Reconfiguration needed quiesce all VSIs */
  7001. i40e_pf_quiesce_all_vsi(pf);
  7002. /* Changes in configuration update VEB/VSI */
  7003. i40e_dcb_reconfigure(pf);
  7004. ret = i40e_resume_port_tx(pf);
  7005. clear_bit(__I40E_PORT_SUSPENDED, pf->state);
  7006. /* In case of error no point in resuming VSIs */
  7007. if (ret)
  7008. goto exit;
  7009. /* Wait for the PF's queues to be disabled */
  7010. ret = i40e_pf_wait_queues_disabled(pf);
  7011. if (ret) {
  7012. /* Schedule PF reset to recover */
  7013. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  7014. i40e_service_event_schedule(pf);
  7015. } else {
  7016. i40e_pf_unquiesce_all_vsi(pf);
  7017. pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED |
  7018. I40E_FLAG_CLIENT_L2_CHANGE);
  7019. }
  7020. exit:
  7021. return ret;
  7022. }
  7023. #endif /* CONFIG_I40E_DCB */
  7024. /**
  7025. * i40e_do_reset_safe - Protected reset path for userland calls.
  7026. * @pf: board private structure
  7027. * @reset_flags: which reset is requested
  7028. *
  7029. **/
  7030. void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
  7031. {
  7032. rtnl_lock();
  7033. i40e_do_reset(pf, reset_flags, true);
  7034. rtnl_unlock();
  7035. }
  7036. /**
  7037. * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
  7038. * @pf: board private structure
  7039. * @e: event info posted on ARQ
  7040. *
  7041. * Handler for LAN Queue Overflow Event generated by the firmware for PF
  7042. * and VF queues
  7043. **/
  7044. static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
  7045. struct i40e_arq_event_info *e)
  7046. {
  7047. struct i40e_aqc_lan_overflow *data =
  7048. (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
  7049. u32 queue = le32_to_cpu(data->prtdcb_rupto);
  7050. u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
  7051. struct i40e_hw *hw = &pf->hw;
  7052. struct i40e_vf *vf;
  7053. u16 vf_id;
  7054. dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
  7055. queue, qtx_ctl);
  7056. /* Queue belongs to VF, find the VF and issue VF reset */
  7057. if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
  7058. >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
  7059. vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
  7060. >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
  7061. vf_id -= hw->func_caps.vf_base_id;
  7062. vf = &pf->vf[vf_id];
  7063. i40e_vc_notify_vf_reset(vf);
  7064. /* Allow VF to process pending reset notification */
  7065. msleep(20);
  7066. i40e_reset_vf(vf, false);
  7067. }
  7068. }
  7069. /**
  7070. * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
  7071. * @pf: board private structure
  7072. **/
  7073. u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
  7074. {
  7075. u32 val, fcnt_prog;
  7076. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  7077. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
  7078. return fcnt_prog;
  7079. }
  7080. /**
  7081. * i40e_get_current_fd_count - Get total FD filters programmed for this PF
  7082. * @pf: board private structure
  7083. **/
  7084. u32 i40e_get_current_fd_count(struct i40e_pf *pf)
  7085. {
  7086. u32 val, fcnt_prog;
  7087. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  7088. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
  7089. ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
  7090. I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
  7091. return fcnt_prog;
  7092. }
  7093. /**
  7094. * i40e_get_global_fd_count - Get total FD filters programmed on device
  7095. * @pf: board private structure
  7096. **/
  7097. u32 i40e_get_global_fd_count(struct i40e_pf *pf)
  7098. {
  7099. u32 val, fcnt_prog;
  7100. val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
  7101. fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
  7102. ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
  7103. I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
  7104. return fcnt_prog;
  7105. }
  7106. /**
  7107. * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
  7108. * @pf: board private structure
  7109. **/
  7110. void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
  7111. {
  7112. struct i40e_fdir_filter *filter;
  7113. u32 fcnt_prog, fcnt_avail;
  7114. struct hlist_node *node;
  7115. if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
  7116. return;
  7117. /* Check if we have enough room to re-enable FDir SB capability. */
  7118. fcnt_prog = i40e_get_global_fd_count(pf);
  7119. fcnt_avail = pf->fdir_pf_filter_count;
  7120. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
  7121. (pf->fd_add_err == 0) ||
  7122. (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
  7123. if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED) {
  7124. pf->flags &= ~I40E_FLAG_FD_SB_AUTO_DISABLED;
  7125. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  7126. (I40E_DEBUG_FD & pf->hw.debug_mask))
  7127. dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
  7128. }
  7129. }
  7130. /* We should wait for even more space before re-enabling ATR.
  7131. * Additionally, we cannot enable ATR as long as we still have TCP SB
  7132. * rules active.
  7133. */
  7134. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) &&
  7135. (pf->fd_tcp4_filter_cnt == 0)) {
  7136. if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) {
  7137. pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
  7138. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  7139. (I40E_DEBUG_FD & pf->hw.debug_mask))
  7140. dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
  7141. }
  7142. }
  7143. /* if hw had a problem adding a filter, delete it */
  7144. if (pf->fd_inv > 0) {
  7145. hlist_for_each_entry_safe(filter, node,
  7146. &pf->fdir_filter_list, fdir_node) {
  7147. if (filter->fd_id == pf->fd_inv) {
  7148. hlist_del(&filter->fdir_node);
  7149. kfree(filter);
  7150. pf->fdir_pf_active_filters--;
  7151. pf->fd_inv = 0;
  7152. }
  7153. }
  7154. }
  7155. }
  7156. #define I40E_MIN_FD_FLUSH_INTERVAL 10
  7157. #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
  7158. /**
  7159. * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
  7160. * @pf: board private structure
  7161. **/
  7162. static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
  7163. {
  7164. unsigned long min_flush_time;
  7165. int flush_wait_retry = 50;
  7166. bool disable_atr = false;
  7167. int fd_room;
  7168. int reg;
  7169. if (!time_after(jiffies, pf->fd_flush_timestamp +
  7170. (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
  7171. return;
  7172. /* If the flush is happening too quick and we have mostly SB rules we
  7173. * should not re-enable ATR for some time.
  7174. */
  7175. min_flush_time = pf->fd_flush_timestamp +
  7176. (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
  7177. fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
  7178. if (!(time_after(jiffies, min_flush_time)) &&
  7179. (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
  7180. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7181. dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
  7182. disable_atr = true;
  7183. }
  7184. pf->fd_flush_timestamp = jiffies;
  7185. pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED;
  7186. /* flush all filters */
  7187. wr32(&pf->hw, I40E_PFQF_CTL_1,
  7188. I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
  7189. i40e_flush(&pf->hw);
  7190. pf->fd_flush_cnt++;
  7191. pf->fd_add_err = 0;
  7192. do {
  7193. /* Check FD flush status every 5-6msec */
  7194. usleep_range(5000, 6000);
  7195. reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
  7196. if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
  7197. break;
  7198. } while (flush_wait_retry--);
  7199. if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
  7200. dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
  7201. } else {
  7202. /* replay sideband filters */
  7203. i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
  7204. if (!disable_atr && !pf->fd_tcp4_filter_cnt)
  7205. pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
  7206. clear_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
  7207. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7208. dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
  7209. }
  7210. }
  7211. /**
  7212. * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
  7213. * @pf: board private structure
  7214. **/
  7215. u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
  7216. {
  7217. return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
  7218. }
  7219. /* We can see up to 256 filter programming desc in transit if the filters are
  7220. * being applied really fast; before we see the first
  7221. * filter miss error on Rx queue 0. Accumulating enough error messages before
  7222. * reacting will make sure we don't cause flush too often.
  7223. */
  7224. #define I40E_MAX_FD_PROGRAM_ERROR 256
  7225. /**
  7226. * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
  7227. * @pf: board private structure
  7228. **/
  7229. static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
  7230. {
  7231. /* if interface is down do nothing */
  7232. if (test_bit(__I40E_DOWN, pf->state))
  7233. return;
  7234. if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
  7235. i40e_fdir_flush_and_replay(pf);
  7236. i40e_fdir_check_and_reenable(pf);
  7237. }
  7238. /**
  7239. * i40e_vsi_link_event - notify VSI of a link event
  7240. * @vsi: vsi to be notified
  7241. * @link_up: link up or down
  7242. **/
  7243. static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
  7244. {
  7245. if (!vsi || test_bit(__I40E_VSI_DOWN, vsi->state))
  7246. return;
  7247. switch (vsi->type) {
  7248. case I40E_VSI_MAIN:
  7249. if (!vsi->netdev || !vsi->netdev_registered)
  7250. break;
  7251. if (link_up) {
  7252. netif_carrier_on(vsi->netdev);
  7253. netif_tx_wake_all_queues(vsi->netdev);
  7254. } else {
  7255. netif_carrier_off(vsi->netdev);
  7256. netif_tx_stop_all_queues(vsi->netdev);
  7257. }
  7258. break;
  7259. case I40E_VSI_SRIOV:
  7260. case I40E_VSI_VMDQ2:
  7261. case I40E_VSI_CTRL:
  7262. case I40E_VSI_IWARP:
  7263. case I40E_VSI_MIRROR:
  7264. default:
  7265. /* there is no notification for other VSIs */
  7266. break;
  7267. }
  7268. }
  7269. /**
  7270. * i40e_veb_link_event - notify elements on the veb of a link event
  7271. * @veb: veb to be notified
  7272. * @link_up: link up or down
  7273. **/
  7274. static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
  7275. {
  7276. struct i40e_pf *pf;
  7277. int i;
  7278. if (!veb || !veb->pf)
  7279. return;
  7280. pf = veb->pf;
  7281. /* depth first... */
  7282. for (i = 0; i < I40E_MAX_VEB; i++)
  7283. if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
  7284. i40e_veb_link_event(pf->veb[i], link_up);
  7285. /* ... now the local VSIs */
  7286. for (i = 0; i < pf->num_alloc_vsi; i++)
  7287. if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
  7288. i40e_vsi_link_event(pf->vsi[i], link_up);
  7289. }
  7290. /**
  7291. * i40e_link_event - Update netif_carrier status
  7292. * @pf: board private structure
  7293. **/
  7294. static void i40e_link_event(struct i40e_pf *pf)
  7295. {
  7296. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7297. u8 new_link_speed, old_link_speed;
  7298. i40e_status status;
  7299. bool new_link, old_link;
  7300. /* save off old link status information */
  7301. pf->hw.phy.link_info_old = pf->hw.phy.link_info;
  7302. /* set this to force the get_link_status call to refresh state */
  7303. pf->hw.phy.get_link_info = true;
  7304. old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
  7305. status = i40e_get_link_status(&pf->hw, &new_link);
  7306. /* On success, disable temp link polling */
  7307. if (status == I40E_SUCCESS) {
  7308. if (pf->flags & I40E_FLAG_TEMP_LINK_POLLING)
  7309. pf->flags &= ~I40E_FLAG_TEMP_LINK_POLLING;
  7310. } else {
  7311. /* Enable link polling temporarily until i40e_get_link_status
  7312. * returns I40E_SUCCESS
  7313. */
  7314. pf->flags |= I40E_FLAG_TEMP_LINK_POLLING;
  7315. dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
  7316. status);
  7317. return;
  7318. }
  7319. old_link_speed = pf->hw.phy.link_info_old.link_speed;
  7320. new_link_speed = pf->hw.phy.link_info.link_speed;
  7321. if (new_link == old_link &&
  7322. new_link_speed == old_link_speed &&
  7323. (test_bit(__I40E_VSI_DOWN, vsi->state) ||
  7324. new_link == netif_carrier_ok(vsi->netdev)))
  7325. return;
  7326. i40e_print_link_message(vsi, new_link);
  7327. /* Notify the base of the switch tree connected to
  7328. * the link. Floating VEBs are not notified.
  7329. */
  7330. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  7331. i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
  7332. else
  7333. i40e_vsi_link_event(vsi, new_link);
  7334. if (pf->vf)
  7335. i40e_vc_notify_link_state(pf);
  7336. if (pf->flags & I40E_FLAG_PTP)
  7337. i40e_ptp_set_increment(pf);
  7338. }
  7339. /**
  7340. * i40e_watchdog_subtask - periodic checks not using event driven response
  7341. * @pf: board private structure
  7342. **/
  7343. static void i40e_watchdog_subtask(struct i40e_pf *pf)
  7344. {
  7345. int i;
  7346. /* if interface is down do nothing */
  7347. if (test_bit(__I40E_DOWN, pf->state) ||
  7348. test_bit(__I40E_CONFIG_BUSY, pf->state))
  7349. return;
  7350. /* make sure we don't do these things too often */
  7351. if (time_before(jiffies, (pf->service_timer_previous +
  7352. pf->service_timer_period)))
  7353. return;
  7354. pf->service_timer_previous = jiffies;
  7355. if ((pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) ||
  7356. (pf->flags & I40E_FLAG_TEMP_LINK_POLLING))
  7357. i40e_link_event(pf);
  7358. /* Update the stats for active netdevs so the network stack
  7359. * can look at updated numbers whenever it cares to
  7360. */
  7361. for (i = 0; i < pf->num_alloc_vsi; i++)
  7362. if (pf->vsi[i] && pf->vsi[i]->netdev)
  7363. i40e_update_stats(pf->vsi[i]);
  7364. if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
  7365. /* Update the stats for the active switching components */
  7366. for (i = 0; i < I40E_MAX_VEB; i++)
  7367. if (pf->veb[i])
  7368. i40e_update_veb_stats(pf->veb[i]);
  7369. }
  7370. i40e_ptp_rx_hang(pf);
  7371. i40e_ptp_tx_hang(pf);
  7372. }
  7373. /**
  7374. * i40e_reset_subtask - Set up for resetting the device and driver
  7375. * @pf: board private structure
  7376. **/
  7377. static void i40e_reset_subtask(struct i40e_pf *pf)
  7378. {
  7379. u32 reset_flags = 0;
  7380. if (test_bit(__I40E_REINIT_REQUESTED, pf->state)) {
  7381. reset_flags |= BIT(__I40E_REINIT_REQUESTED);
  7382. clear_bit(__I40E_REINIT_REQUESTED, pf->state);
  7383. }
  7384. if (test_bit(__I40E_PF_RESET_REQUESTED, pf->state)) {
  7385. reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
  7386. clear_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  7387. }
  7388. if (test_bit(__I40E_CORE_RESET_REQUESTED, pf->state)) {
  7389. reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
  7390. clear_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
  7391. }
  7392. if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state)) {
  7393. reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
  7394. clear_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state);
  7395. }
  7396. if (test_bit(__I40E_DOWN_REQUESTED, pf->state)) {
  7397. reset_flags |= BIT(__I40E_DOWN_REQUESTED);
  7398. clear_bit(__I40E_DOWN_REQUESTED, pf->state);
  7399. }
  7400. /* If there's a recovery already waiting, it takes
  7401. * precedence before starting a new reset sequence.
  7402. */
  7403. if (test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) {
  7404. i40e_prep_for_reset(pf, false);
  7405. i40e_reset(pf);
  7406. i40e_rebuild(pf, false, false);
  7407. }
  7408. /* If we're already down or resetting, just bail */
  7409. if (reset_flags &&
  7410. !test_bit(__I40E_DOWN, pf->state) &&
  7411. !test_bit(__I40E_CONFIG_BUSY, pf->state)) {
  7412. i40e_do_reset(pf, reset_flags, false);
  7413. }
  7414. }
  7415. /**
  7416. * i40e_handle_link_event - Handle link event
  7417. * @pf: board private structure
  7418. * @e: event info posted on ARQ
  7419. **/
  7420. static void i40e_handle_link_event(struct i40e_pf *pf,
  7421. struct i40e_arq_event_info *e)
  7422. {
  7423. struct i40e_aqc_get_link_status *status =
  7424. (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
  7425. /* Do a new status request to re-enable LSE reporting
  7426. * and load new status information into the hw struct
  7427. * This completely ignores any state information
  7428. * in the ARQ event info, instead choosing to always
  7429. * issue the AQ update link status command.
  7430. */
  7431. i40e_link_event(pf);
  7432. /* Check if module meets thermal requirements */
  7433. if (status->phy_type == I40E_PHY_TYPE_NOT_SUPPORTED_HIGH_TEMP) {
  7434. dev_err(&pf->pdev->dev,
  7435. "Rx/Tx is disabled on this device because the module does not meet thermal requirements.\n");
  7436. dev_err(&pf->pdev->dev,
  7437. "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
  7438. } else {
  7439. /* check for unqualified module, if link is down, suppress
  7440. * the message if link was forced to be down.
  7441. */
  7442. if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
  7443. (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
  7444. (!(status->link_info & I40E_AQ_LINK_UP)) &&
  7445. (!(pf->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED))) {
  7446. dev_err(&pf->pdev->dev,
  7447. "Rx/Tx is disabled on this device because an unsupported SFP module type was detected.\n");
  7448. dev_err(&pf->pdev->dev,
  7449. "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
  7450. }
  7451. }
  7452. }
  7453. /**
  7454. * i40e_clean_adminq_subtask - Clean the AdminQ rings
  7455. * @pf: board private structure
  7456. **/
  7457. static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
  7458. {
  7459. struct i40e_arq_event_info event;
  7460. struct i40e_hw *hw = &pf->hw;
  7461. u16 pending, i = 0;
  7462. i40e_status ret;
  7463. u16 opcode;
  7464. u32 oldval;
  7465. u32 val;
  7466. /* Do not run clean AQ when PF reset fails */
  7467. if (test_bit(__I40E_RESET_FAILED, pf->state))
  7468. return;
  7469. /* check for error indications */
  7470. val = rd32(&pf->hw, pf->hw.aq.arq.len);
  7471. oldval = val;
  7472. if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
  7473. if (hw->debug_mask & I40E_DEBUG_AQ)
  7474. dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
  7475. val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
  7476. }
  7477. if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
  7478. if (hw->debug_mask & I40E_DEBUG_AQ)
  7479. dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
  7480. val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
  7481. pf->arq_overflows++;
  7482. }
  7483. if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
  7484. if (hw->debug_mask & I40E_DEBUG_AQ)
  7485. dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
  7486. val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
  7487. }
  7488. if (oldval != val)
  7489. wr32(&pf->hw, pf->hw.aq.arq.len, val);
  7490. val = rd32(&pf->hw, pf->hw.aq.asq.len);
  7491. oldval = val;
  7492. if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
  7493. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7494. dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
  7495. val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
  7496. }
  7497. if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
  7498. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7499. dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
  7500. val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
  7501. }
  7502. if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
  7503. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7504. dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
  7505. val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
  7506. }
  7507. if (oldval != val)
  7508. wr32(&pf->hw, pf->hw.aq.asq.len, val);
  7509. event.buf_len = I40E_MAX_AQ_BUF_SIZE;
  7510. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  7511. if (!event.msg_buf)
  7512. return;
  7513. do {
  7514. ret = i40e_clean_arq_element(hw, &event, &pending);
  7515. if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
  7516. break;
  7517. else if (ret) {
  7518. dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
  7519. break;
  7520. }
  7521. opcode = le16_to_cpu(event.desc.opcode);
  7522. switch (opcode) {
  7523. case i40e_aqc_opc_get_link_status:
  7524. i40e_handle_link_event(pf, &event);
  7525. break;
  7526. case i40e_aqc_opc_send_msg_to_pf:
  7527. ret = i40e_vc_process_vf_msg(pf,
  7528. le16_to_cpu(event.desc.retval),
  7529. le32_to_cpu(event.desc.cookie_high),
  7530. le32_to_cpu(event.desc.cookie_low),
  7531. event.msg_buf,
  7532. event.msg_len);
  7533. break;
  7534. case i40e_aqc_opc_lldp_update_mib:
  7535. dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
  7536. #ifdef CONFIG_I40E_DCB
  7537. rtnl_lock();
  7538. ret = i40e_handle_lldp_event(pf, &event);
  7539. rtnl_unlock();
  7540. #endif /* CONFIG_I40E_DCB */
  7541. break;
  7542. case i40e_aqc_opc_event_lan_overflow:
  7543. dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
  7544. i40e_handle_lan_overflow_event(pf, &event);
  7545. break;
  7546. case i40e_aqc_opc_send_msg_to_peer:
  7547. dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
  7548. break;
  7549. case i40e_aqc_opc_nvm_erase:
  7550. case i40e_aqc_opc_nvm_update:
  7551. case i40e_aqc_opc_oem_post_update:
  7552. i40e_debug(&pf->hw, I40E_DEBUG_NVM,
  7553. "ARQ NVM operation 0x%04x completed\n",
  7554. opcode);
  7555. break;
  7556. default:
  7557. dev_info(&pf->pdev->dev,
  7558. "ARQ: Unknown event 0x%04x ignored\n",
  7559. opcode);
  7560. break;
  7561. }
  7562. } while (i++ < pf->adminq_work_limit);
  7563. if (i < pf->adminq_work_limit)
  7564. clear_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
  7565. /* re-enable Admin queue interrupt cause */
  7566. val = rd32(hw, I40E_PFINT_ICR0_ENA);
  7567. val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  7568. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  7569. i40e_flush(hw);
  7570. kfree(event.msg_buf);
  7571. }
  7572. /**
  7573. * i40e_verify_eeprom - make sure eeprom is good to use
  7574. * @pf: board private structure
  7575. **/
  7576. static void i40e_verify_eeprom(struct i40e_pf *pf)
  7577. {
  7578. int err;
  7579. err = i40e_diag_eeprom_test(&pf->hw);
  7580. if (err) {
  7581. /* retry in case of garbage read */
  7582. err = i40e_diag_eeprom_test(&pf->hw);
  7583. if (err) {
  7584. dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
  7585. err);
  7586. set_bit(__I40E_BAD_EEPROM, pf->state);
  7587. }
  7588. }
  7589. if (!err && test_bit(__I40E_BAD_EEPROM, pf->state)) {
  7590. dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
  7591. clear_bit(__I40E_BAD_EEPROM, pf->state);
  7592. }
  7593. }
  7594. /**
  7595. * i40e_enable_pf_switch_lb
  7596. * @pf: pointer to the PF structure
  7597. *
  7598. * enable switch loop back or die - no point in a return value
  7599. **/
  7600. static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
  7601. {
  7602. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7603. struct i40e_vsi_context ctxt;
  7604. int ret;
  7605. ctxt.seid = pf->main_vsi_seid;
  7606. ctxt.pf_num = pf->hw.pf_id;
  7607. ctxt.vf_num = 0;
  7608. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  7609. if (ret) {
  7610. dev_info(&pf->pdev->dev,
  7611. "couldn't get PF vsi config, err %s aq_err %s\n",
  7612. i40e_stat_str(&pf->hw, ret),
  7613. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7614. return;
  7615. }
  7616. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  7617. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  7618. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  7619. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  7620. if (ret) {
  7621. dev_info(&pf->pdev->dev,
  7622. "update vsi switch failed, err %s aq_err %s\n",
  7623. i40e_stat_str(&pf->hw, ret),
  7624. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7625. }
  7626. }
  7627. /**
  7628. * i40e_disable_pf_switch_lb
  7629. * @pf: pointer to the PF structure
  7630. *
  7631. * disable switch loop back or die - no point in a return value
  7632. **/
  7633. static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
  7634. {
  7635. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7636. struct i40e_vsi_context ctxt;
  7637. int ret;
  7638. ctxt.seid = pf->main_vsi_seid;
  7639. ctxt.pf_num = pf->hw.pf_id;
  7640. ctxt.vf_num = 0;
  7641. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  7642. if (ret) {
  7643. dev_info(&pf->pdev->dev,
  7644. "couldn't get PF vsi config, err %s aq_err %s\n",
  7645. i40e_stat_str(&pf->hw, ret),
  7646. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7647. return;
  7648. }
  7649. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  7650. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  7651. ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  7652. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  7653. if (ret) {
  7654. dev_info(&pf->pdev->dev,
  7655. "update vsi switch failed, err %s aq_err %s\n",
  7656. i40e_stat_str(&pf->hw, ret),
  7657. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7658. }
  7659. }
  7660. /**
  7661. * i40e_config_bridge_mode - Configure the HW bridge mode
  7662. * @veb: pointer to the bridge instance
  7663. *
  7664. * Configure the loop back mode for the LAN VSI that is downlink to the
  7665. * specified HW bridge instance. It is expected this function is called
  7666. * when a new HW bridge is instantiated.
  7667. **/
  7668. static void i40e_config_bridge_mode(struct i40e_veb *veb)
  7669. {
  7670. struct i40e_pf *pf = veb->pf;
  7671. if (pf->hw.debug_mask & I40E_DEBUG_LAN)
  7672. dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
  7673. veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  7674. if (veb->bridge_mode & BRIDGE_MODE_VEPA)
  7675. i40e_disable_pf_switch_lb(pf);
  7676. else
  7677. i40e_enable_pf_switch_lb(pf);
  7678. }
  7679. /**
  7680. * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
  7681. * @veb: pointer to the VEB instance
  7682. *
  7683. * This is a recursive function that first builds the attached VSIs then
  7684. * recurses in to build the next layer of VEB. We track the connections
  7685. * through our own index numbers because the seid's from the HW could
  7686. * change across the reset.
  7687. **/
  7688. static int i40e_reconstitute_veb(struct i40e_veb *veb)
  7689. {
  7690. struct i40e_vsi *ctl_vsi = NULL;
  7691. struct i40e_pf *pf = veb->pf;
  7692. int v, veb_idx;
  7693. int ret;
  7694. /* build VSI that owns this VEB, temporarily attached to base VEB */
  7695. for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
  7696. if (pf->vsi[v] &&
  7697. pf->vsi[v]->veb_idx == veb->idx &&
  7698. pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
  7699. ctl_vsi = pf->vsi[v];
  7700. break;
  7701. }
  7702. }
  7703. if (!ctl_vsi) {
  7704. dev_info(&pf->pdev->dev,
  7705. "missing owner VSI for veb_idx %d\n", veb->idx);
  7706. ret = -ENOENT;
  7707. goto end_reconstitute;
  7708. }
  7709. if (ctl_vsi != pf->vsi[pf->lan_vsi])
  7710. ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  7711. ret = i40e_add_vsi(ctl_vsi);
  7712. if (ret) {
  7713. dev_info(&pf->pdev->dev,
  7714. "rebuild of veb_idx %d owner VSI failed: %d\n",
  7715. veb->idx, ret);
  7716. goto end_reconstitute;
  7717. }
  7718. i40e_vsi_reset_stats(ctl_vsi);
  7719. /* create the VEB in the switch and move the VSI onto the VEB */
  7720. ret = i40e_add_veb(veb, ctl_vsi);
  7721. if (ret)
  7722. goto end_reconstitute;
  7723. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  7724. veb->bridge_mode = BRIDGE_MODE_VEB;
  7725. else
  7726. veb->bridge_mode = BRIDGE_MODE_VEPA;
  7727. i40e_config_bridge_mode(veb);
  7728. /* create the remaining VSIs attached to this VEB */
  7729. for (v = 0; v < pf->num_alloc_vsi; v++) {
  7730. if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
  7731. continue;
  7732. if (pf->vsi[v]->veb_idx == veb->idx) {
  7733. struct i40e_vsi *vsi = pf->vsi[v];
  7734. vsi->uplink_seid = veb->seid;
  7735. ret = i40e_add_vsi(vsi);
  7736. if (ret) {
  7737. dev_info(&pf->pdev->dev,
  7738. "rebuild of vsi_idx %d failed: %d\n",
  7739. v, ret);
  7740. goto end_reconstitute;
  7741. }
  7742. i40e_vsi_reset_stats(vsi);
  7743. }
  7744. }
  7745. /* create any VEBs attached to this VEB - RECURSION */
  7746. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  7747. if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
  7748. pf->veb[veb_idx]->uplink_seid = veb->seid;
  7749. ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
  7750. if (ret)
  7751. break;
  7752. }
  7753. }
  7754. end_reconstitute:
  7755. return ret;
  7756. }
  7757. /**
  7758. * i40e_get_capabilities - get info about the HW
  7759. * @pf: the PF struct
  7760. **/
  7761. static int i40e_get_capabilities(struct i40e_pf *pf,
  7762. enum i40e_admin_queue_opc list_type)
  7763. {
  7764. struct i40e_aqc_list_capabilities_element_resp *cap_buf;
  7765. u16 data_size;
  7766. int buf_len;
  7767. int err;
  7768. buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
  7769. do {
  7770. cap_buf = kzalloc(buf_len, GFP_KERNEL);
  7771. if (!cap_buf)
  7772. return -ENOMEM;
  7773. /* this loads the data into the hw struct for us */
  7774. err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
  7775. &data_size, list_type,
  7776. NULL);
  7777. /* data loaded, buffer no longer needed */
  7778. kfree(cap_buf);
  7779. if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
  7780. /* retry with a larger buffer */
  7781. buf_len = data_size;
  7782. } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
  7783. dev_info(&pf->pdev->dev,
  7784. "capability discovery failed, err %s aq_err %s\n",
  7785. i40e_stat_str(&pf->hw, err),
  7786. i40e_aq_str(&pf->hw,
  7787. pf->hw.aq.asq_last_status));
  7788. return -ENODEV;
  7789. }
  7790. } while (err);
  7791. if (pf->hw.debug_mask & I40E_DEBUG_USER) {
  7792. if (list_type == i40e_aqc_opc_list_func_capabilities) {
  7793. dev_info(&pf->pdev->dev,
  7794. "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",
  7795. pf->hw.pf_id, pf->hw.func_caps.num_vfs,
  7796. pf->hw.func_caps.num_msix_vectors,
  7797. pf->hw.func_caps.num_msix_vectors_vf,
  7798. pf->hw.func_caps.fd_filters_guaranteed,
  7799. pf->hw.func_caps.fd_filters_best_effort,
  7800. pf->hw.func_caps.num_tx_qp,
  7801. pf->hw.func_caps.num_vsis);
  7802. } else if (list_type == i40e_aqc_opc_list_dev_capabilities) {
  7803. dev_info(&pf->pdev->dev,
  7804. "switch_mode=0x%04x, function_valid=0x%08x\n",
  7805. pf->hw.dev_caps.switch_mode,
  7806. pf->hw.dev_caps.valid_functions);
  7807. dev_info(&pf->pdev->dev,
  7808. "SR-IOV=%d, num_vfs for all function=%u\n",
  7809. pf->hw.dev_caps.sr_iov_1_1,
  7810. pf->hw.dev_caps.num_vfs);
  7811. dev_info(&pf->pdev->dev,
  7812. "num_vsis=%u, num_rx:%u, num_tx=%u\n",
  7813. pf->hw.dev_caps.num_vsis,
  7814. pf->hw.dev_caps.num_rx_qp,
  7815. pf->hw.dev_caps.num_tx_qp);
  7816. }
  7817. }
  7818. if (list_type == i40e_aqc_opc_list_func_capabilities) {
  7819. #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
  7820. + pf->hw.func_caps.num_vfs)
  7821. if (pf->hw.revision_id == 0 &&
  7822. pf->hw.func_caps.num_vsis < DEF_NUM_VSI) {
  7823. dev_info(&pf->pdev->dev,
  7824. "got num_vsis %d, setting num_vsis to %d\n",
  7825. pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
  7826. pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
  7827. }
  7828. }
  7829. return 0;
  7830. }
  7831. static int i40e_vsi_clear(struct i40e_vsi *vsi);
  7832. /**
  7833. * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
  7834. * @pf: board private structure
  7835. **/
  7836. static void i40e_fdir_sb_setup(struct i40e_pf *pf)
  7837. {
  7838. struct i40e_vsi *vsi;
  7839. /* quick workaround for an NVM issue that leaves a critical register
  7840. * uninitialized
  7841. */
  7842. if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
  7843. static const u32 hkey[] = {
  7844. 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
  7845. 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
  7846. 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
  7847. 0x95b3a76d};
  7848. int i;
  7849. for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
  7850. wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
  7851. }
  7852. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  7853. return;
  7854. /* find existing VSI and see if it needs configuring */
  7855. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  7856. /* create a new VSI if none exists */
  7857. if (!vsi) {
  7858. vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
  7859. pf->vsi[pf->lan_vsi]->seid, 0);
  7860. if (!vsi) {
  7861. dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
  7862. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7863. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  7864. return;
  7865. }
  7866. }
  7867. i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
  7868. }
  7869. /**
  7870. * i40e_fdir_teardown - release the Flow Director resources
  7871. * @pf: board private structure
  7872. **/
  7873. static void i40e_fdir_teardown(struct i40e_pf *pf)
  7874. {
  7875. struct i40e_vsi *vsi;
  7876. i40e_fdir_filter_exit(pf);
  7877. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  7878. if (vsi)
  7879. i40e_vsi_release(vsi);
  7880. }
  7881. /**
  7882. * i40e_rebuild_cloud_filters - Rebuilds cloud filters for VSIs
  7883. * @vsi: PF main vsi
  7884. * @seid: seid of main or channel VSIs
  7885. *
  7886. * Rebuilds cloud filters associated with main VSI and channel VSIs if they
  7887. * existed before reset
  7888. **/
  7889. static int i40e_rebuild_cloud_filters(struct i40e_vsi *vsi, u16 seid)
  7890. {
  7891. struct i40e_cloud_filter *cfilter;
  7892. struct i40e_pf *pf = vsi->back;
  7893. struct hlist_node *node;
  7894. i40e_status ret;
  7895. /* Add cloud filters back if they exist */
  7896. hlist_for_each_entry_safe(cfilter, node, &pf->cloud_filter_list,
  7897. cloud_node) {
  7898. if (cfilter->seid != seid)
  7899. continue;
  7900. if (cfilter->dst_port)
  7901. ret = i40e_add_del_cloud_filter_big_buf(vsi, cfilter,
  7902. true);
  7903. else
  7904. ret = i40e_add_del_cloud_filter(vsi, cfilter, true);
  7905. if (ret) {
  7906. dev_dbg(&pf->pdev->dev,
  7907. "Failed to rebuild cloud filter, err %s aq_err %s\n",
  7908. i40e_stat_str(&pf->hw, ret),
  7909. i40e_aq_str(&pf->hw,
  7910. pf->hw.aq.asq_last_status));
  7911. return ret;
  7912. }
  7913. }
  7914. return 0;
  7915. }
  7916. /**
  7917. * i40e_rebuild_channels - Rebuilds channel VSIs if they existed before reset
  7918. * @vsi: PF main vsi
  7919. *
  7920. * Rebuilds channel VSIs if they existed before reset
  7921. **/
  7922. static int i40e_rebuild_channels(struct i40e_vsi *vsi)
  7923. {
  7924. struct i40e_channel *ch, *ch_tmp;
  7925. i40e_status ret;
  7926. if (list_empty(&vsi->ch_list))
  7927. return 0;
  7928. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  7929. if (!ch->initialized)
  7930. break;
  7931. /* Proceed with creation of channel (VMDq2) VSI */
  7932. ret = i40e_add_channel(vsi->back, vsi->uplink_seid, ch);
  7933. if (ret) {
  7934. dev_info(&vsi->back->pdev->dev,
  7935. "failed to rebuild channels using uplink_seid %u\n",
  7936. vsi->uplink_seid);
  7937. return ret;
  7938. }
  7939. if (ch->max_tx_rate) {
  7940. u64 credits = ch->max_tx_rate;
  7941. if (i40e_set_bw_limit(vsi, ch->seid,
  7942. ch->max_tx_rate))
  7943. return -EINVAL;
  7944. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  7945. dev_dbg(&vsi->back->pdev->dev,
  7946. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  7947. ch->max_tx_rate,
  7948. credits,
  7949. ch->seid);
  7950. }
  7951. ret = i40e_rebuild_cloud_filters(vsi, ch->seid);
  7952. if (ret) {
  7953. dev_dbg(&vsi->back->pdev->dev,
  7954. "Failed to rebuild cloud filters for channel VSI %u\n",
  7955. ch->seid);
  7956. return ret;
  7957. }
  7958. }
  7959. return 0;
  7960. }
  7961. /**
  7962. * i40e_prep_for_reset - prep for the core to reset
  7963. * @pf: board private structure
  7964. * @lock_acquired: indicates whether or not the lock has been acquired
  7965. * before this function was called.
  7966. *
  7967. * Close up the VFs and other things in prep for PF Reset.
  7968. **/
  7969. static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired)
  7970. {
  7971. struct i40e_hw *hw = &pf->hw;
  7972. i40e_status ret = 0;
  7973. u32 v;
  7974. clear_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
  7975. if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  7976. return;
  7977. if (i40e_check_asq_alive(&pf->hw))
  7978. i40e_vc_notify_reset(pf);
  7979. dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
  7980. /* quiesce the VSIs and their queues that are not already DOWN */
  7981. /* pf_quiesce_all_vsi modifies netdev structures -rtnl_lock needed */
  7982. if (!lock_acquired)
  7983. rtnl_lock();
  7984. i40e_pf_quiesce_all_vsi(pf);
  7985. if (!lock_acquired)
  7986. rtnl_unlock();
  7987. for (v = 0; v < pf->num_alloc_vsi; v++) {
  7988. if (pf->vsi[v])
  7989. pf->vsi[v]->seid = 0;
  7990. }
  7991. i40e_shutdown_adminq(&pf->hw);
  7992. /* call shutdown HMC */
  7993. if (hw->hmc.hmc_obj) {
  7994. ret = i40e_shutdown_lan_hmc(hw);
  7995. if (ret)
  7996. dev_warn(&pf->pdev->dev,
  7997. "shutdown_lan_hmc failed: %d\n", ret);
  7998. }
  7999. }
  8000. /**
  8001. * i40e_send_version - update firmware with driver version
  8002. * @pf: PF struct
  8003. */
  8004. static void i40e_send_version(struct i40e_pf *pf)
  8005. {
  8006. struct i40e_driver_version dv;
  8007. dv.major_version = DRV_VERSION_MAJOR;
  8008. dv.minor_version = DRV_VERSION_MINOR;
  8009. dv.build_version = DRV_VERSION_BUILD;
  8010. dv.subbuild_version = 0;
  8011. strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
  8012. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  8013. }
  8014. /**
  8015. * i40e_get_oem_version - get OEM specific version information
  8016. * @hw: pointer to the hardware structure
  8017. **/
  8018. static void i40e_get_oem_version(struct i40e_hw *hw)
  8019. {
  8020. u16 block_offset = 0xffff;
  8021. u16 block_length = 0;
  8022. u16 capabilities = 0;
  8023. u16 gen_snap = 0;
  8024. u16 release = 0;
  8025. #define I40E_SR_NVM_OEM_VERSION_PTR 0x1B
  8026. #define I40E_NVM_OEM_LENGTH_OFFSET 0x00
  8027. #define I40E_NVM_OEM_CAPABILITIES_OFFSET 0x01
  8028. #define I40E_NVM_OEM_GEN_OFFSET 0x02
  8029. #define I40E_NVM_OEM_RELEASE_OFFSET 0x03
  8030. #define I40E_NVM_OEM_CAPABILITIES_MASK 0x000F
  8031. #define I40E_NVM_OEM_LENGTH 3
  8032. /* Check if pointer to OEM version block is valid. */
  8033. i40e_read_nvm_word(hw, I40E_SR_NVM_OEM_VERSION_PTR, &block_offset);
  8034. if (block_offset == 0xffff)
  8035. return;
  8036. /* Check if OEM version block has correct length. */
  8037. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_LENGTH_OFFSET,
  8038. &block_length);
  8039. if (block_length < I40E_NVM_OEM_LENGTH)
  8040. return;
  8041. /* Check if OEM version format is as expected. */
  8042. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_CAPABILITIES_OFFSET,
  8043. &capabilities);
  8044. if ((capabilities & I40E_NVM_OEM_CAPABILITIES_MASK) != 0)
  8045. return;
  8046. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_GEN_OFFSET,
  8047. &gen_snap);
  8048. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_RELEASE_OFFSET,
  8049. &release);
  8050. hw->nvm.oem_ver = (gen_snap << I40E_OEM_SNAP_SHIFT) | release;
  8051. hw->nvm.eetrack = I40E_OEM_EETRACK_ID;
  8052. }
  8053. /**
  8054. * i40e_reset - wait for core reset to finish reset, reset pf if corer not seen
  8055. * @pf: board private structure
  8056. **/
  8057. static int i40e_reset(struct i40e_pf *pf)
  8058. {
  8059. struct i40e_hw *hw = &pf->hw;
  8060. i40e_status ret;
  8061. ret = i40e_pf_reset(hw);
  8062. if (ret) {
  8063. dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
  8064. set_bit(__I40E_RESET_FAILED, pf->state);
  8065. clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
  8066. } else {
  8067. pf->pfr_count++;
  8068. }
  8069. return ret;
  8070. }
  8071. /**
  8072. * i40e_rebuild - rebuild using a saved config
  8073. * @pf: board private structure
  8074. * @reinit: if the Main VSI needs to re-initialized.
  8075. * @lock_acquired: indicates whether or not the lock has been acquired
  8076. * before this function was called.
  8077. **/
  8078. static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired)
  8079. {
  8080. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  8081. struct i40e_hw *hw = &pf->hw;
  8082. u8 set_fc_aq_fail = 0;
  8083. i40e_status ret;
  8084. u32 val;
  8085. int v;
  8086. if (test_bit(__I40E_DOWN, pf->state))
  8087. goto clear_recovery;
  8088. dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
  8089. /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
  8090. ret = i40e_init_adminq(&pf->hw);
  8091. if (ret) {
  8092. dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
  8093. i40e_stat_str(&pf->hw, ret),
  8094. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8095. goto clear_recovery;
  8096. }
  8097. i40e_get_oem_version(&pf->hw);
  8098. /* re-verify the eeprom if we just had an EMP reset */
  8099. if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state))
  8100. i40e_verify_eeprom(pf);
  8101. i40e_clear_pxe_mode(hw);
  8102. ret = i40e_get_capabilities(pf, i40e_aqc_opc_list_func_capabilities);
  8103. if (ret)
  8104. goto end_core_reset;
  8105. ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  8106. hw->func_caps.num_rx_qp, 0, 0);
  8107. if (ret) {
  8108. dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
  8109. goto end_core_reset;
  8110. }
  8111. ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  8112. if (ret) {
  8113. dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
  8114. goto end_core_reset;
  8115. }
  8116. #ifdef CONFIG_I40E_DCB
  8117. ret = i40e_init_pf_dcb(pf);
  8118. if (ret) {
  8119. dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
  8120. pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
  8121. /* Continue without DCB enabled */
  8122. }
  8123. #endif /* CONFIG_I40E_DCB */
  8124. /* do basic switch setup */
  8125. if (!lock_acquired)
  8126. rtnl_lock();
  8127. ret = i40e_setup_pf_switch(pf, reinit);
  8128. if (ret)
  8129. goto end_unlock;
  8130. /* The driver only wants link up/down and module qualification
  8131. * reports from firmware. Note the negative logic.
  8132. */
  8133. ret = i40e_aq_set_phy_int_mask(&pf->hw,
  8134. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  8135. I40E_AQ_EVENT_MEDIA_NA |
  8136. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  8137. if (ret)
  8138. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  8139. i40e_stat_str(&pf->hw, ret),
  8140. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8141. /* make sure our flow control settings are restored */
  8142. ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
  8143. if (ret)
  8144. dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
  8145. i40e_stat_str(&pf->hw, ret),
  8146. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8147. /* Rebuild the VSIs and VEBs that existed before reset.
  8148. * They are still in our local switch element arrays, so only
  8149. * need to rebuild the switch model in the HW.
  8150. *
  8151. * If there were VEBs but the reconstitution failed, we'll try
  8152. * try to recover minimal use by getting the basic PF VSI working.
  8153. */
  8154. if (vsi->uplink_seid != pf->mac_seid) {
  8155. dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
  8156. /* find the one VEB connected to the MAC, and find orphans */
  8157. for (v = 0; v < I40E_MAX_VEB; v++) {
  8158. if (!pf->veb[v])
  8159. continue;
  8160. if (pf->veb[v]->uplink_seid == pf->mac_seid ||
  8161. pf->veb[v]->uplink_seid == 0) {
  8162. ret = i40e_reconstitute_veb(pf->veb[v]);
  8163. if (!ret)
  8164. continue;
  8165. /* If Main VEB failed, we're in deep doodoo,
  8166. * so give up rebuilding the switch and set up
  8167. * for minimal rebuild of PF VSI.
  8168. * If orphan failed, we'll report the error
  8169. * but try to keep going.
  8170. */
  8171. if (pf->veb[v]->uplink_seid == pf->mac_seid) {
  8172. dev_info(&pf->pdev->dev,
  8173. "rebuild of switch failed: %d, will try to set up simple PF connection\n",
  8174. ret);
  8175. vsi->uplink_seid = pf->mac_seid;
  8176. break;
  8177. } else if (pf->veb[v]->uplink_seid == 0) {
  8178. dev_info(&pf->pdev->dev,
  8179. "rebuild of orphan VEB failed: %d\n",
  8180. ret);
  8181. }
  8182. }
  8183. }
  8184. }
  8185. if (vsi->uplink_seid == pf->mac_seid) {
  8186. dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
  8187. /* no VEB, so rebuild only the Main VSI */
  8188. ret = i40e_add_vsi(vsi);
  8189. if (ret) {
  8190. dev_info(&pf->pdev->dev,
  8191. "rebuild of Main VSI failed: %d\n", ret);
  8192. goto end_unlock;
  8193. }
  8194. }
  8195. if (vsi->mqprio_qopt.max_rate[0]) {
  8196. u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
  8197. u64 credits = 0;
  8198. do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
  8199. ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
  8200. if (ret)
  8201. goto end_unlock;
  8202. credits = max_tx_rate;
  8203. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  8204. dev_dbg(&vsi->back->pdev->dev,
  8205. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  8206. max_tx_rate,
  8207. credits,
  8208. vsi->seid);
  8209. }
  8210. ret = i40e_rebuild_cloud_filters(vsi, vsi->seid);
  8211. if (ret)
  8212. goto end_unlock;
  8213. /* PF Main VSI is rebuild by now, go ahead and rebuild channel VSIs
  8214. * for this main VSI if they exist
  8215. */
  8216. ret = i40e_rebuild_channels(vsi);
  8217. if (ret)
  8218. goto end_unlock;
  8219. /* Reconfigure hardware for allowing smaller MSS in the case
  8220. * of TSO, so that we avoid the MDD being fired and causing
  8221. * a reset in the case of small MSS+TSO.
  8222. */
  8223. #define I40E_REG_MSS 0x000E64DC
  8224. #define I40E_REG_MSS_MIN_MASK 0x3FF0000
  8225. #define I40E_64BYTE_MSS 0x400000
  8226. val = rd32(hw, I40E_REG_MSS);
  8227. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  8228. val &= ~I40E_REG_MSS_MIN_MASK;
  8229. val |= I40E_64BYTE_MSS;
  8230. wr32(hw, I40E_REG_MSS, val);
  8231. }
  8232. if (pf->hw_features & I40E_HW_RESTART_AUTONEG) {
  8233. msleep(75);
  8234. ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  8235. if (ret)
  8236. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  8237. i40e_stat_str(&pf->hw, ret),
  8238. i40e_aq_str(&pf->hw,
  8239. pf->hw.aq.asq_last_status));
  8240. }
  8241. /* reinit the misc interrupt */
  8242. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  8243. ret = i40e_setup_misc_vector(pf);
  8244. /* Add a filter to drop all Flow control frames from any VSI from being
  8245. * transmitted. By doing so we stop a malicious VF from sending out
  8246. * PAUSE or PFC frames and potentially controlling traffic for other
  8247. * PF/VF VSIs.
  8248. * The FW can still send Flow control frames if enabled.
  8249. */
  8250. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  8251. pf->main_vsi_seid);
  8252. /* restart the VSIs that were rebuilt and running before the reset */
  8253. i40e_pf_unquiesce_all_vsi(pf);
  8254. /* Release the RTNL lock before we start resetting VFs */
  8255. if (!lock_acquired)
  8256. rtnl_unlock();
  8257. i40e_reset_all_vfs(pf, true);
  8258. /* tell the firmware that we're starting */
  8259. i40e_send_version(pf);
  8260. /* We've already released the lock, so don't do it again */
  8261. goto end_core_reset;
  8262. end_unlock:
  8263. if (!lock_acquired)
  8264. rtnl_unlock();
  8265. end_core_reset:
  8266. clear_bit(__I40E_RESET_FAILED, pf->state);
  8267. clear_recovery:
  8268. clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
  8269. }
  8270. /**
  8271. * i40e_reset_and_rebuild - reset and rebuild using a saved config
  8272. * @pf: board private structure
  8273. * @reinit: if the Main VSI needs to re-initialized.
  8274. * @lock_acquired: indicates whether or not the lock has been acquired
  8275. * before this function was called.
  8276. **/
  8277. static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit,
  8278. bool lock_acquired)
  8279. {
  8280. int ret;
  8281. /* Now we wait for GRST to settle out.
  8282. * We don't have to delete the VEBs or VSIs from the hw switch
  8283. * because the reset will make them disappear.
  8284. */
  8285. ret = i40e_reset(pf);
  8286. if (!ret)
  8287. i40e_rebuild(pf, reinit, lock_acquired);
  8288. }
  8289. /**
  8290. * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
  8291. * @pf: board private structure
  8292. *
  8293. * Close up the VFs and other things in prep for a Core Reset,
  8294. * then get ready to rebuild the world.
  8295. * @lock_acquired: indicates whether or not the lock has been acquired
  8296. * before this function was called.
  8297. **/
  8298. static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired)
  8299. {
  8300. i40e_prep_for_reset(pf, lock_acquired);
  8301. i40e_reset_and_rebuild(pf, false, lock_acquired);
  8302. }
  8303. /**
  8304. * i40e_handle_mdd_event
  8305. * @pf: pointer to the PF structure
  8306. *
  8307. * Called from the MDD irq handler to identify possibly malicious vfs
  8308. **/
  8309. static void i40e_handle_mdd_event(struct i40e_pf *pf)
  8310. {
  8311. struct i40e_hw *hw = &pf->hw;
  8312. bool mdd_detected = false;
  8313. bool pf_mdd_detected = false;
  8314. struct i40e_vf *vf;
  8315. u32 reg;
  8316. int i;
  8317. if (!test_bit(__I40E_MDD_EVENT_PENDING, pf->state))
  8318. return;
  8319. /* find what triggered the MDD event */
  8320. reg = rd32(hw, I40E_GL_MDET_TX);
  8321. if (reg & I40E_GL_MDET_TX_VALID_MASK) {
  8322. u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
  8323. I40E_GL_MDET_TX_PF_NUM_SHIFT;
  8324. u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
  8325. I40E_GL_MDET_TX_VF_NUM_SHIFT;
  8326. u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
  8327. I40E_GL_MDET_TX_EVENT_SHIFT;
  8328. u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
  8329. I40E_GL_MDET_TX_QUEUE_SHIFT) -
  8330. pf->hw.func_caps.base_queue;
  8331. if (netif_msg_tx_err(pf))
  8332. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
  8333. event, queue, pf_num, vf_num);
  8334. wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
  8335. mdd_detected = true;
  8336. }
  8337. reg = rd32(hw, I40E_GL_MDET_RX);
  8338. if (reg & I40E_GL_MDET_RX_VALID_MASK) {
  8339. u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
  8340. I40E_GL_MDET_RX_FUNCTION_SHIFT;
  8341. u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
  8342. I40E_GL_MDET_RX_EVENT_SHIFT;
  8343. u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
  8344. I40E_GL_MDET_RX_QUEUE_SHIFT) -
  8345. pf->hw.func_caps.base_queue;
  8346. if (netif_msg_rx_err(pf))
  8347. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
  8348. event, queue, func);
  8349. wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
  8350. mdd_detected = true;
  8351. }
  8352. if (mdd_detected) {
  8353. reg = rd32(hw, I40E_PF_MDET_TX);
  8354. if (reg & I40E_PF_MDET_TX_VALID_MASK) {
  8355. wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
  8356. dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
  8357. pf_mdd_detected = true;
  8358. }
  8359. reg = rd32(hw, I40E_PF_MDET_RX);
  8360. if (reg & I40E_PF_MDET_RX_VALID_MASK) {
  8361. wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
  8362. dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
  8363. pf_mdd_detected = true;
  8364. }
  8365. /* Queue belongs to the PF, initiate a reset */
  8366. if (pf_mdd_detected) {
  8367. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  8368. i40e_service_event_schedule(pf);
  8369. }
  8370. }
  8371. /* see if one of the VFs needs its hand slapped */
  8372. for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
  8373. vf = &(pf->vf[i]);
  8374. reg = rd32(hw, I40E_VP_MDET_TX(i));
  8375. if (reg & I40E_VP_MDET_TX_VALID_MASK) {
  8376. wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
  8377. vf->num_mdd_events++;
  8378. dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
  8379. i);
  8380. }
  8381. reg = rd32(hw, I40E_VP_MDET_RX(i));
  8382. if (reg & I40E_VP_MDET_RX_VALID_MASK) {
  8383. wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
  8384. vf->num_mdd_events++;
  8385. dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
  8386. i);
  8387. }
  8388. if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
  8389. dev_info(&pf->pdev->dev,
  8390. "Too many MDD events on VF %d, disabled\n", i);
  8391. dev_info(&pf->pdev->dev,
  8392. "Use PF Control I/F to re-enable the VF\n");
  8393. set_bit(I40E_VF_STATE_DISABLED, &vf->vf_states);
  8394. }
  8395. }
  8396. /* re-enable mdd interrupt cause */
  8397. clear_bit(__I40E_MDD_EVENT_PENDING, pf->state);
  8398. reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  8399. reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  8400. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  8401. i40e_flush(hw);
  8402. }
  8403. static const char *i40e_tunnel_name(struct i40e_udp_port_config *port)
  8404. {
  8405. switch (port->type) {
  8406. case UDP_TUNNEL_TYPE_VXLAN:
  8407. return "vxlan";
  8408. case UDP_TUNNEL_TYPE_GENEVE:
  8409. return "geneve";
  8410. default:
  8411. return "unknown";
  8412. }
  8413. }
  8414. /**
  8415. * i40e_sync_udp_filters - Trigger a sync event for existing UDP filters
  8416. * @pf: board private structure
  8417. **/
  8418. static void i40e_sync_udp_filters(struct i40e_pf *pf)
  8419. {
  8420. int i;
  8421. /* loop through and set pending bit for all active UDP filters */
  8422. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  8423. if (pf->udp_ports[i].port)
  8424. pf->pending_udp_bitmap |= BIT_ULL(i);
  8425. }
  8426. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  8427. }
  8428. /**
  8429. * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
  8430. * @pf: board private structure
  8431. **/
  8432. static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
  8433. {
  8434. struct i40e_hw *hw = &pf->hw;
  8435. i40e_status ret;
  8436. u16 port;
  8437. int i;
  8438. if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC))
  8439. return;
  8440. pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC;
  8441. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  8442. if (pf->pending_udp_bitmap & BIT_ULL(i)) {
  8443. pf->pending_udp_bitmap &= ~BIT_ULL(i);
  8444. port = pf->udp_ports[i].port;
  8445. if (port)
  8446. ret = i40e_aq_add_udp_tunnel(hw, port,
  8447. pf->udp_ports[i].type,
  8448. NULL, NULL);
  8449. else
  8450. ret = i40e_aq_del_udp_tunnel(hw, i, NULL);
  8451. if (ret) {
  8452. dev_info(&pf->pdev->dev,
  8453. "%s %s port %d, index %d failed, err %s aq_err %s\n",
  8454. i40e_tunnel_name(&pf->udp_ports[i]),
  8455. port ? "add" : "delete",
  8456. port, i,
  8457. i40e_stat_str(&pf->hw, ret),
  8458. i40e_aq_str(&pf->hw,
  8459. pf->hw.aq.asq_last_status));
  8460. pf->udp_ports[i].port = 0;
  8461. }
  8462. }
  8463. }
  8464. }
  8465. /**
  8466. * i40e_service_task - Run the driver's async subtasks
  8467. * @work: pointer to work_struct containing our data
  8468. **/
  8469. static void i40e_service_task(struct work_struct *work)
  8470. {
  8471. struct i40e_pf *pf = container_of(work,
  8472. struct i40e_pf,
  8473. service_task);
  8474. unsigned long start_time = jiffies;
  8475. /* don't bother with service tasks if a reset is in progress */
  8476. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  8477. return;
  8478. if (test_and_set_bit(__I40E_SERVICE_SCHED, pf->state))
  8479. return;
  8480. i40e_detect_recover_hung(pf);
  8481. i40e_sync_filters_subtask(pf);
  8482. i40e_reset_subtask(pf);
  8483. i40e_handle_mdd_event(pf);
  8484. i40e_vc_process_vflr_event(pf);
  8485. i40e_watchdog_subtask(pf);
  8486. i40e_fdir_reinit_subtask(pf);
  8487. if (pf->flags & I40E_FLAG_CLIENT_RESET) {
  8488. /* Client subtask will reopen next time through. */
  8489. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], true);
  8490. pf->flags &= ~I40E_FLAG_CLIENT_RESET;
  8491. } else {
  8492. i40e_client_subtask(pf);
  8493. if (pf->flags & I40E_FLAG_CLIENT_L2_CHANGE) {
  8494. i40e_notify_client_of_l2_param_changes(
  8495. pf->vsi[pf->lan_vsi]);
  8496. pf->flags &= ~I40E_FLAG_CLIENT_L2_CHANGE;
  8497. }
  8498. }
  8499. i40e_sync_filters_subtask(pf);
  8500. i40e_sync_udp_filters_subtask(pf);
  8501. i40e_clean_adminq_subtask(pf);
  8502. /* flush memory to make sure state is correct before next watchdog */
  8503. smp_mb__before_atomic();
  8504. clear_bit(__I40E_SERVICE_SCHED, pf->state);
  8505. /* If the tasks have taken longer than one timer cycle or there
  8506. * is more work to be done, reschedule the service task now
  8507. * rather than wait for the timer to tick again.
  8508. */
  8509. if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
  8510. test_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state) ||
  8511. test_bit(__I40E_MDD_EVENT_PENDING, pf->state) ||
  8512. test_bit(__I40E_VFLR_EVENT_PENDING, pf->state))
  8513. i40e_service_event_schedule(pf);
  8514. }
  8515. /**
  8516. * i40e_service_timer - timer callback
  8517. * @data: pointer to PF struct
  8518. **/
  8519. static void i40e_service_timer(struct timer_list *t)
  8520. {
  8521. struct i40e_pf *pf = from_timer(pf, t, service_timer);
  8522. mod_timer(&pf->service_timer,
  8523. round_jiffies(jiffies + pf->service_timer_period));
  8524. i40e_service_event_schedule(pf);
  8525. }
  8526. /**
  8527. * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
  8528. * @vsi: the VSI being configured
  8529. **/
  8530. static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
  8531. {
  8532. struct i40e_pf *pf = vsi->back;
  8533. switch (vsi->type) {
  8534. case I40E_VSI_MAIN:
  8535. vsi->alloc_queue_pairs = pf->num_lan_qps;
  8536. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  8537. I40E_REQ_DESCRIPTOR_MULTIPLE);
  8538. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  8539. vsi->num_q_vectors = pf->num_lan_msix;
  8540. else
  8541. vsi->num_q_vectors = 1;
  8542. break;
  8543. case I40E_VSI_FDIR:
  8544. vsi->alloc_queue_pairs = 1;
  8545. vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
  8546. I40E_REQ_DESCRIPTOR_MULTIPLE);
  8547. vsi->num_q_vectors = pf->num_fdsb_msix;
  8548. break;
  8549. case I40E_VSI_VMDQ2:
  8550. vsi->alloc_queue_pairs = pf->num_vmdq_qps;
  8551. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  8552. I40E_REQ_DESCRIPTOR_MULTIPLE);
  8553. vsi->num_q_vectors = pf->num_vmdq_msix;
  8554. break;
  8555. case I40E_VSI_SRIOV:
  8556. vsi->alloc_queue_pairs = pf->num_vf_qps;
  8557. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  8558. I40E_REQ_DESCRIPTOR_MULTIPLE);
  8559. break;
  8560. default:
  8561. WARN_ON(1);
  8562. return -ENODATA;
  8563. }
  8564. return 0;
  8565. }
  8566. /**
  8567. * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
  8568. * @vsi: VSI pointer
  8569. * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
  8570. *
  8571. * On error: returns error code (negative)
  8572. * On success: returns 0
  8573. **/
  8574. static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
  8575. {
  8576. struct i40e_ring **next_rings;
  8577. int size;
  8578. int ret = 0;
  8579. /* allocate memory for both Tx, XDP Tx and Rx ring pointers */
  8580. size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs *
  8581. (i40e_enabled_xdp_vsi(vsi) ? 3 : 2);
  8582. vsi->tx_rings = kzalloc(size, GFP_KERNEL);
  8583. if (!vsi->tx_rings)
  8584. return -ENOMEM;
  8585. next_rings = vsi->tx_rings + vsi->alloc_queue_pairs;
  8586. if (i40e_enabled_xdp_vsi(vsi)) {
  8587. vsi->xdp_rings = next_rings;
  8588. next_rings += vsi->alloc_queue_pairs;
  8589. }
  8590. vsi->rx_rings = next_rings;
  8591. if (alloc_qvectors) {
  8592. /* allocate memory for q_vector pointers */
  8593. size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
  8594. vsi->q_vectors = kzalloc(size, GFP_KERNEL);
  8595. if (!vsi->q_vectors) {
  8596. ret = -ENOMEM;
  8597. goto err_vectors;
  8598. }
  8599. }
  8600. return ret;
  8601. err_vectors:
  8602. kfree(vsi->tx_rings);
  8603. return ret;
  8604. }
  8605. /**
  8606. * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
  8607. * @pf: board private structure
  8608. * @type: type of VSI
  8609. *
  8610. * On error: returns error code (negative)
  8611. * On success: returns vsi index in PF (positive)
  8612. **/
  8613. static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
  8614. {
  8615. int ret = -ENODEV;
  8616. struct i40e_vsi *vsi;
  8617. int vsi_idx;
  8618. int i;
  8619. /* Need to protect the allocation of the VSIs at the PF level */
  8620. mutex_lock(&pf->switch_mutex);
  8621. /* VSI list may be fragmented if VSI creation/destruction has
  8622. * been happening. We can afford to do a quick scan to look
  8623. * for any free VSIs in the list.
  8624. *
  8625. * find next empty vsi slot, looping back around if necessary
  8626. */
  8627. i = pf->next_vsi;
  8628. while (i < pf->num_alloc_vsi && pf->vsi[i])
  8629. i++;
  8630. if (i >= pf->num_alloc_vsi) {
  8631. i = 0;
  8632. while (i < pf->next_vsi && pf->vsi[i])
  8633. i++;
  8634. }
  8635. if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
  8636. vsi_idx = i; /* Found one! */
  8637. } else {
  8638. ret = -ENODEV;
  8639. goto unlock_pf; /* out of VSI slots! */
  8640. }
  8641. pf->next_vsi = ++i;
  8642. vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
  8643. if (!vsi) {
  8644. ret = -ENOMEM;
  8645. goto unlock_pf;
  8646. }
  8647. vsi->type = type;
  8648. vsi->back = pf;
  8649. set_bit(__I40E_VSI_DOWN, vsi->state);
  8650. vsi->flags = 0;
  8651. vsi->idx = vsi_idx;
  8652. vsi->int_rate_limit = 0;
  8653. vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
  8654. pf->rss_table_size : 64;
  8655. vsi->netdev_registered = false;
  8656. vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
  8657. hash_init(vsi->mac_filter_hash);
  8658. vsi->irqs_ready = false;
  8659. ret = i40e_set_num_rings_in_vsi(vsi);
  8660. if (ret)
  8661. goto err_rings;
  8662. ret = i40e_vsi_alloc_arrays(vsi, true);
  8663. if (ret)
  8664. goto err_rings;
  8665. /* Setup default MSIX irq handler for VSI */
  8666. i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
  8667. /* Initialize VSI lock */
  8668. spin_lock_init(&vsi->mac_filter_hash_lock);
  8669. pf->vsi[vsi_idx] = vsi;
  8670. ret = vsi_idx;
  8671. goto unlock_pf;
  8672. err_rings:
  8673. pf->next_vsi = i - 1;
  8674. kfree(vsi);
  8675. unlock_pf:
  8676. mutex_unlock(&pf->switch_mutex);
  8677. return ret;
  8678. }
  8679. /**
  8680. * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
  8681. * @type: VSI pointer
  8682. * @free_qvectors: a bool to specify if q_vectors need to be freed.
  8683. *
  8684. * On error: returns error code (negative)
  8685. * On success: returns 0
  8686. **/
  8687. static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
  8688. {
  8689. /* free the ring and vector containers */
  8690. if (free_qvectors) {
  8691. kfree(vsi->q_vectors);
  8692. vsi->q_vectors = NULL;
  8693. }
  8694. kfree(vsi->tx_rings);
  8695. vsi->tx_rings = NULL;
  8696. vsi->rx_rings = NULL;
  8697. vsi->xdp_rings = NULL;
  8698. }
  8699. /**
  8700. * i40e_clear_rss_config_user - clear the user configured RSS hash keys
  8701. * and lookup table
  8702. * @vsi: Pointer to VSI structure
  8703. */
  8704. static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
  8705. {
  8706. if (!vsi)
  8707. return;
  8708. kfree(vsi->rss_hkey_user);
  8709. vsi->rss_hkey_user = NULL;
  8710. kfree(vsi->rss_lut_user);
  8711. vsi->rss_lut_user = NULL;
  8712. }
  8713. /**
  8714. * i40e_vsi_clear - Deallocate the VSI provided
  8715. * @vsi: the VSI being un-configured
  8716. **/
  8717. static int i40e_vsi_clear(struct i40e_vsi *vsi)
  8718. {
  8719. struct i40e_pf *pf;
  8720. if (!vsi)
  8721. return 0;
  8722. if (!vsi->back)
  8723. goto free_vsi;
  8724. pf = vsi->back;
  8725. mutex_lock(&pf->switch_mutex);
  8726. if (!pf->vsi[vsi->idx]) {
  8727. dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
  8728. vsi->idx, vsi->idx, vsi, vsi->type);
  8729. goto unlock_vsi;
  8730. }
  8731. if (pf->vsi[vsi->idx] != vsi) {
  8732. dev_err(&pf->pdev->dev,
  8733. "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
  8734. pf->vsi[vsi->idx]->idx,
  8735. pf->vsi[vsi->idx],
  8736. pf->vsi[vsi->idx]->type,
  8737. vsi->idx, vsi, vsi->type);
  8738. goto unlock_vsi;
  8739. }
  8740. /* updates the PF for this cleared vsi */
  8741. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  8742. i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
  8743. i40e_vsi_free_arrays(vsi, true);
  8744. i40e_clear_rss_config_user(vsi);
  8745. pf->vsi[vsi->idx] = NULL;
  8746. if (vsi->idx < pf->next_vsi)
  8747. pf->next_vsi = vsi->idx;
  8748. unlock_vsi:
  8749. mutex_unlock(&pf->switch_mutex);
  8750. free_vsi:
  8751. kfree(vsi);
  8752. return 0;
  8753. }
  8754. /**
  8755. * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
  8756. * @vsi: the VSI being cleaned
  8757. **/
  8758. static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
  8759. {
  8760. int i;
  8761. if (vsi->tx_rings && vsi->tx_rings[0]) {
  8762. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  8763. kfree_rcu(vsi->tx_rings[i], rcu);
  8764. vsi->tx_rings[i] = NULL;
  8765. vsi->rx_rings[i] = NULL;
  8766. if (vsi->xdp_rings)
  8767. vsi->xdp_rings[i] = NULL;
  8768. }
  8769. }
  8770. }
  8771. /**
  8772. * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
  8773. * @vsi: the VSI being configured
  8774. **/
  8775. static int i40e_alloc_rings(struct i40e_vsi *vsi)
  8776. {
  8777. int i, qpv = i40e_enabled_xdp_vsi(vsi) ? 3 : 2;
  8778. struct i40e_pf *pf = vsi->back;
  8779. struct i40e_ring *ring;
  8780. /* Set basic values in the rings to be used later during open() */
  8781. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  8782. /* allocate space for both Tx and Rx in one shot */
  8783. ring = kcalloc(qpv, sizeof(struct i40e_ring), GFP_KERNEL);
  8784. if (!ring)
  8785. goto err_out;
  8786. ring->queue_index = i;
  8787. ring->reg_idx = vsi->base_queue + i;
  8788. ring->ring_active = false;
  8789. ring->vsi = vsi;
  8790. ring->netdev = vsi->netdev;
  8791. ring->dev = &pf->pdev->dev;
  8792. ring->count = vsi->num_desc;
  8793. ring->size = 0;
  8794. ring->dcb_tc = 0;
  8795. if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE)
  8796. ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
  8797. ring->tx_itr_setting = pf->tx_itr_default;
  8798. vsi->tx_rings[i] = ring++;
  8799. if (!i40e_enabled_xdp_vsi(vsi))
  8800. goto setup_rx;
  8801. ring->queue_index = vsi->alloc_queue_pairs + i;
  8802. ring->reg_idx = vsi->base_queue + ring->queue_index;
  8803. ring->ring_active = false;
  8804. ring->vsi = vsi;
  8805. ring->netdev = NULL;
  8806. ring->dev = &pf->pdev->dev;
  8807. ring->count = vsi->num_desc;
  8808. ring->size = 0;
  8809. ring->dcb_tc = 0;
  8810. if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE)
  8811. ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
  8812. set_ring_xdp(ring);
  8813. ring->tx_itr_setting = pf->tx_itr_default;
  8814. vsi->xdp_rings[i] = ring++;
  8815. setup_rx:
  8816. ring->queue_index = i;
  8817. ring->reg_idx = vsi->base_queue + i;
  8818. ring->ring_active = false;
  8819. ring->vsi = vsi;
  8820. ring->netdev = vsi->netdev;
  8821. ring->dev = &pf->pdev->dev;
  8822. ring->count = vsi->num_desc;
  8823. ring->size = 0;
  8824. ring->dcb_tc = 0;
  8825. ring->rx_itr_setting = pf->rx_itr_default;
  8826. vsi->rx_rings[i] = ring;
  8827. }
  8828. return 0;
  8829. err_out:
  8830. i40e_vsi_clear_rings(vsi);
  8831. return -ENOMEM;
  8832. }
  8833. /**
  8834. * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
  8835. * @pf: board private structure
  8836. * @vectors: the number of MSI-X vectors to request
  8837. *
  8838. * Returns the number of vectors reserved, or error
  8839. **/
  8840. static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
  8841. {
  8842. vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
  8843. I40E_MIN_MSIX, vectors);
  8844. if (vectors < 0) {
  8845. dev_info(&pf->pdev->dev,
  8846. "MSI-X vector reservation failed: %d\n", vectors);
  8847. vectors = 0;
  8848. }
  8849. return vectors;
  8850. }
  8851. /**
  8852. * i40e_init_msix - Setup the MSIX capability
  8853. * @pf: board private structure
  8854. *
  8855. * Work with the OS to set up the MSIX vectors needed.
  8856. *
  8857. * Returns the number of vectors reserved or negative on failure
  8858. **/
  8859. static int i40e_init_msix(struct i40e_pf *pf)
  8860. {
  8861. struct i40e_hw *hw = &pf->hw;
  8862. int cpus, extra_vectors;
  8863. int vectors_left;
  8864. int v_budget, i;
  8865. int v_actual;
  8866. int iwarp_requested = 0;
  8867. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  8868. return -ENODEV;
  8869. /* The number of vectors we'll request will be comprised of:
  8870. * - Add 1 for "other" cause for Admin Queue events, etc.
  8871. * - The number of LAN queue pairs
  8872. * - Queues being used for RSS.
  8873. * We don't need as many as max_rss_size vectors.
  8874. * use rss_size instead in the calculation since that
  8875. * is governed by number of cpus in the system.
  8876. * - assumes symmetric Tx/Rx pairing
  8877. * - The number of VMDq pairs
  8878. * - The CPU count within the NUMA node if iWARP is enabled
  8879. * Once we count this up, try the request.
  8880. *
  8881. * If we can't get what we want, we'll simplify to nearly nothing
  8882. * and try again. If that still fails, we punt.
  8883. */
  8884. vectors_left = hw->func_caps.num_msix_vectors;
  8885. v_budget = 0;
  8886. /* reserve one vector for miscellaneous handler */
  8887. if (vectors_left) {
  8888. v_budget++;
  8889. vectors_left--;
  8890. }
  8891. /* reserve some vectors for the main PF traffic queues. Initially we
  8892. * only reserve at most 50% of the available vectors, in the case that
  8893. * the number of online CPUs is large. This ensures that we can enable
  8894. * extra features as well. Once we've enabled the other features, we
  8895. * will use any remaining vectors to reach as close as we can to the
  8896. * number of online CPUs.
  8897. */
  8898. cpus = num_online_cpus();
  8899. pf->num_lan_msix = min_t(int, cpus, vectors_left / 2);
  8900. vectors_left -= pf->num_lan_msix;
  8901. /* reserve one vector for sideband flow director */
  8902. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  8903. if (vectors_left) {
  8904. pf->num_fdsb_msix = 1;
  8905. v_budget++;
  8906. vectors_left--;
  8907. } else {
  8908. pf->num_fdsb_msix = 0;
  8909. }
  8910. }
  8911. /* can we reserve enough for iWARP? */
  8912. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  8913. iwarp_requested = pf->num_iwarp_msix;
  8914. if (!vectors_left)
  8915. pf->num_iwarp_msix = 0;
  8916. else if (vectors_left < pf->num_iwarp_msix)
  8917. pf->num_iwarp_msix = 1;
  8918. v_budget += pf->num_iwarp_msix;
  8919. vectors_left -= pf->num_iwarp_msix;
  8920. }
  8921. /* any vectors left over go for VMDq support */
  8922. if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
  8923. int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
  8924. int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted);
  8925. if (!vectors_left) {
  8926. pf->num_vmdq_msix = 0;
  8927. pf->num_vmdq_qps = 0;
  8928. } else {
  8929. /* if we're short on vectors for what's desired, we limit
  8930. * the queues per vmdq. If this is still more than are
  8931. * available, the user will need to change the number of
  8932. * queues/vectors used by the PF later with the ethtool
  8933. * channels command
  8934. */
  8935. if (vmdq_vecs < vmdq_vecs_wanted)
  8936. pf->num_vmdq_qps = 1;
  8937. pf->num_vmdq_msix = pf->num_vmdq_qps;
  8938. v_budget += vmdq_vecs;
  8939. vectors_left -= vmdq_vecs;
  8940. }
  8941. }
  8942. /* On systems with a large number of SMP cores, we previously limited
  8943. * the number of vectors for num_lan_msix to be at most 50% of the
  8944. * available vectors, to allow for other features. Now, we add back
  8945. * the remaining vectors. However, we ensure that the total
  8946. * num_lan_msix will not exceed num_online_cpus(). To do this, we
  8947. * calculate the number of vectors we can add without going over the
  8948. * cap of CPUs. For systems with a small number of CPUs this will be
  8949. * zero.
  8950. */
  8951. extra_vectors = min_t(int, cpus - pf->num_lan_msix, vectors_left);
  8952. pf->num_lan_msix += extra_vectors;
  8953. vectors_left -= extra_vectors;
  8954. WARN(vectors_left < 0,
  8955. "Calculation of remaining vectors underflowed. This is an accounting bug when determining total MSI-X vectors.\n");
  8956. v_budget += pf->num_lan_msix;
  8957. pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
  8958. GFP_KERNEL);
  8959. if (!pf->msix_entries)
  8960. return -ENOMEM;
  8961. for (i = 0; i < v_budget; i++)
  8962. pf->msix_entries[i].entry = i;
  8963. v_actual = i40e_reserve_msix_vectors(pf, v_budget);
  8964. if (v_actual < I40E_MIN_MSIX) {
  8965. pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
  8966. kfree(pf->msix_entries);
  8967. pf->msix_entries = NULL;
  8968. pci_disable_msix(pf->pdev);
  8969. return -ENODEV;
  8970. } else if (v_actual == I40E_MIN_MSIX) {
  8971. /* Adjust for minimal MSIX use */
  8972. pf->num_vmdq_vsis = 0;
  8973. pf->num_vmdq_qps = 0;
  8974. pf->num_lan_qps = 1;
  8975. pf->num_lan_msix = 1;
  8976. } else if (v_actual != v_budget) {
  8977. /* If we have limited resources, we will start with no vectors
  8978. * for the special features and then allocate vectors to some
  8979. * of these features based on the policy and at the end disable
  8980. * the features that did not get any vectors.
  8981. */
  8982. int vec;
  8983. dev_info(&pf->pdev->dev,
  8984. "MSI-X vector limit reached with %d, wanted %d, attempting to redistribute vectors\n",
  8985. v_actual, v_budget);
  8986. /* reserve the misc vector */
  8987. vec = v_actual - 1;
  8988. /* Scale vector usage down */
  8989. pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
  8990. pf->num_vmdq_vsis = 1;
  8991. pf->num_vmdq_qps = 1;
  8992. /* partition out the remaining vectors */
  8993. switch (vec) {
  8994. case 2:
  8995. pf->num_lan_msix = 1;
  8996. break;
  8997. case 3:
  8998. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  8999. pf->num_lan_msix = 1;
  9000. pf->num_iwarp_msix = 1;
  9001. } else {
  9002. pf->num_lan_msix = 2;
  9003. }
  9004. break;
  9005. default:
  9006. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  9007. pf->num_iwarp_msix = min_t(int, (vec / 3),
  9008. iwarp_requested);
  9009. pf->num_vmdq_vsis = min_t(int, (vec / 3),
  9010. I40E_DEFAULT_NUM_VMDQ_VSI);
  9011. } else {
  9012. pf->num_vmdq_vsis = min_t(int, (vec / 2),
  9013. I40E_DEFAULT_NUM_VMDQ_VSI);
  9014. }
  9015. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9016. pf->num_fdsb_msix = 1;
  9017. vec--;
  9018. }
  9019. pf->num_lan_msix = min_t(int,
  9020. (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
  9021. pf->num_lan_msix);
  9022. pf->num_lan_qps = pf->num_lan_msix;
  9023. break;
  9024. }
  9025. }
  9026. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  9027. (pf->num_fdsb_msix == 0)) {
  9028. dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
  9029. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  9030. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  9031. }
  9032. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  9033. (pf->num_vmdq_msix == 0)) {
  9034. dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
  9035. pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
  9036. }
  9037. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  9038. (pf->num_iwarp_msix == 0)) {
  9039. dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
  9040. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  9041. }
  9042. i40e_debug(&pf->hw, I40E_DEBUG_INIT,
  9043. "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
  9044. pf->num_lan_msix,
  9045. pf->num_vmdq_msix * pf->num_vmdq_vsis,
  9046. pf->num_fdsb_msix,
  9047. pf->num_iwarp_msix);
  9048. return v_actual;
  9049. }
  9050. /**
  9051. * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
  9052. * @vsi: the VSI being configured
  9053. * @v_idx: index of the vector in the vsi struct
  9054. * @cpu: cpu to be used on affinity_mask
  9055. *
  9056. * We allocate one q_vector. If allocation fails we return -ENOMEM.
  9057. **/
  9058. static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx, int cpu)
  9059. {
  9060. struct i40e_q_vector *q_vector;
  9061. /* allocate q_vector */
  9062. q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
  9063. if (!q_vector)
  9064. return -ENOMEM;
  9065. q_vector->vsi = vsi;
  9066. q_vector->v_idx = v_idx;
  9067. cpumask_copy(&q_vector->affinity_mask, cpu_possible_mask);
  9068. if (vsi->netdev)
  9069. netif_napi_add(vsi->netdev, &q_vector->napi,
  9070. i40e_napi_poll, NAPI_POLL_WEIGHT);
  9071. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  9072. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  9073. /* tie q_vector and vsi together */
  9074. vsi->q_vectors[v_idx] = q_vector;
  9075. return 0;
  9076. }
  9077. /**
  9078. * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
  9079. * @vsi: the VSI being configured
  9080. *
  9081. * We allocate one q_vector per queue interrupt. If allocation fails we
  9082. * return -ENOMEM.
  9083. **/
  9084. static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
  9085. {
  9086. struct i40e_pf *pf = vsi->back;
  9087. int err, v_idx, num_q_vectors, current_cpu;
  9088. /* if not MSIX, give the one vector only to the LAN VSI */
  9089. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  9090. num_q_vectors = vsi->num_q_vectors;
  9091. else if (vsi == pf->vsi[pf->lan_vsi])
  9092. num_q_vectors = 1;
  9093. else
  9094. return -EINVAL;
  9095. current_cpu = cpumask_first(cpu_online_mask);
  9096. for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
  9097. err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu);
  9098. if (err)
  9099. goto err_out;
  9100. current_cpu = cpumask_next(current_cpu, cpu_online_mask);
  9101. if (unlikely(current_cpu >= nr_cpu_ids))
  9102. current_cpu = cpumask_first(cpu_online_mask);
  9103. }
  9104. return 0;
  9105. err_out:
  9106. while (v_idx--)
  9107. i40e_free_q_vector(vsi, v_idx);
  9108. return err;
  9109. }
  9110. /**
  9111. * i40e_init_interrupt_scheme - Determine proper interrupt scheme
  9112. * @pf: board private structure to initialize
  9113. **/
  9114. static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
  9115. {
  9116. int vectors = 0;
  9117. ssize_t size;
  9118. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  9119. vectors = i40e_init_msix(pf);
  9120. if (vectors < 0) {
  9121. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
  9122. I40E_FLAG_IWARP_ENABLED |
  9123. I40E_FLAG_RSS_ENABLED |
  9124. I40E_FLAG_DCB_CAPABLE |
  9125. I40E_FLAG_DCB_ENABLED |
  9126. I40E_FLAG_SRIOV_ENABLED |
  9127. I40E_FLAG_FD_SB_ENABLED |
  9128. I40E_FLAG_FD_ATR_ENABLED |
  9129. I40E_FLAG_VMDQ_ENABLED);
  9130. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  9131. /* rework the queue expectations without MSIX */
  9132. i40e_determine_queue_usage(pf);
  9133. }
  9134. }
  9135. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  9136. (pf->flags & I40E_FLAG_MSI_ENABLED)) {
  9137. dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
  9138. vectors = pci_enable_msi(pf->pdev);
  9139. if (vectors < 0) {
  9140. dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
  9141. vectors);
  9142. pf->flags &= ~I40E_FLAG_MSI_ENABLED;
  9143. }
  9144. vectors = 1; /* one MSI or Legacy vector */
  9145. }
  9146. if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
  9147. dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
  9148. /* set up vector assignment tracking */
  9149. size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
  9150. pf->irq_pile = kzalloc(size, GFP_KERNEL);
  9151. if (!pf->irq_pile) {
  9152. dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n");
  9153. return -ENOMEM;
  9154. }
  9155. pf->irq_pile->num_entries = vectors;
  9156. pf->irq_pile->search_hint = 0;
  9157. /* track first vector for misc interrupts, ignore return */
  9158. (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
  9159. return 0;
  9160. }
  9161. /**
  9162. * i40e_restore_interrupt_scheme - Restore the interrupt scheme
  9163. * @pf: private board data structure
  9164. *
  9165. * Restore the interrupt scheme that was cleared when we suspended the
  9166. * device. This should be called during resume to re-allocate the q_vectors
  9167. * and reacquire IRQs.
  9168. */
  9169. static int i40e_restore_interrupt_scheme(struct i40e_pf *pf)
  9170. {
  9171. int err, i;
  9172. /* We cleared the MSI and MSI-X flags when disabling the old interrupt
  9173. * scheme. We need to re-enabled them here in order to attempt to
  9174. * re-acquire the MSI or MSI-X vectors
  9175. */
  9176. pf->flags |= (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  9177. err = i40e_init_interrupt_scheme(pf);
  9178. if (err)
  9179. return err;
  9180. /* Now that we've re-acquired IRQs, we need to remap the vectors and
  9181. * rings together again.
  9182. */
  9183. for (i = 0; i < pf->num_alloc_vsi; i++) {
  9184. if (pf->vsi[i]) {
  9185. err = i40e_vsi_alloc_q_vectors(pf->vsi[i]);
  9186. if (err)
  9187. goto err_unwind;
  9188. i40e_vsi_map_rings_to_vectors(pf->vsi[i]);
  9189. }
  9190. }
  9191. err = i40e_setup_misc_vector(pf);
  9192. if (err)
  9193. goto err_unwind;
  9194. return 0;
  9195. err_unwind:
  9196. while (i--) {
  9197. if (pf->vsi[i])
  9198. i40e_vsi_free_q_vectors(pf->vsi[i]);
  9199. }
  9200. return err;
  9201. }
  9202. /**
  9203. * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
  9204. * @pf: board private structure
  9205. *
  9206. * This sets up the handler for MSIX 0, which is used to manage the
  9207. * non-queue interrupts, e.g. AdminQ and errors. This is not used
  9208. * when in MSI or Legacy interrupt mode.
  9209. **/
  9210. static int i40e_setup_misc_vector(struct i40e_pf *pf)
  9211. {
  9212. struct i40e_hw *hw = &pf->hw;
  9213. int err = 0;
  9214. /* Only request the IRQ once, the first time through. */
  9215. if (!test_and_set_bit(__I40E_MISC_IRQ_REQUESTED, pf->state)) {
  9216. err = request_irq(pf->msix_entries[0].vector,
  9217. i40e_intr, 0, pf->int_name, pf);
  9218. if (err) {
  9219. clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state);
  9220. dev_info(&pf->pdev->dev,
  9221. "request_irq for %s failed: %d\n",
  9222. pf->int_name, err);
  9223. return -EFAULT;
  9224. }
  9225. }
  9226. i40e_enable_misc_int_causes(pf);
  9227. /* associate no queues to the misc vector */
  9228. wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
  9229. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
  9230. i40e_flush(hw);
  9231. i40e_irq_dynamic_enable_icr0(pf);
  9232. return err;
  9233. }
  9234. /**
  9235. * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
  9236. * @vsi: Pointer to vsi structure
  9237. * @seed: Buffter to store the hash keys
  9238. * @lut: Buffer to store the lookup table entries
  9239. * @lut_size: Size of buffer to store the lookup table entries
  9240. *
  9241. * Return 0 on success, negative on failure
  9242. */
  9243. static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  9244. u8 *lut, u16 lut_size)
  9245. {
  9246. struct i40e_pf *pf = vsi->back;
  9247. struct i40e_hw *hw = &pf->hw;
  9248. int ret = 0;
  9249. if (seed) {
  9250. ret = i40e_aq_get_rss_key(hw, vsi->id,
  9251. (struct i40e_aqc_get_set_rss_key_data *)seed);
  9252. if (ret) {
  9253. dev_info(&pf->pdev->dev,
  9254. "Cannot get RSS key, err %s aq_err %s\n",
  9255. i40e_stat_str(&pf->hw, ret),
  9256. i40e_aq_str(&pf->hw,
  9257. pf->hw.aq.asq_last_status));
  9258. return ret;
  9259. }
  9260. }
  9261. if (lut) {
  9262. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  9263. ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  9264. if (ret) {
  9265. dev_info(&pf->pdev->dev,
  9266. "Cannot get RSS lut, err %s aq_err %s\n",
  9267. i40e_stat_str(&pf->hw, ret),
  9268. i40e_aq_str(&pf->hw,
  9269. pf->hw.aq.asq_last_status));
  9270. return ret;
  9271. }
  9272. }
  9273. return ret;
  9274. }
  9275. /**
  9276. * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
  9277. * @vsi: Pointer to vsi structure
  9278. * @seed: RSS hash seed
  9279. * @lut: Lookup table
  9280. * @lut_size: Lookup table size
  9281. *
  9282. * Returns 0 on success, negative on failure
  9283. **/
  9284. static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
  9285. const u8 *lut, u16 lut_size)
  9286. {
  9287. struct i40e_pf *pf = vsi->back;
  9288. struct i40e_hw *hw = &pf->hw;
  9289. u16 vf_id = vsi->vf_id;
  9290. u8 i;
  9291. /* Fill out hash function seed */
  9292. if (seed) {
  9293. u32 *seed_dw = (u32 *)seed;
  9294. if (vsi->type == I40E_VSI_MAIN) {
  9295. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  9296. wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]);
  9297. } else if (vsi->type == I40E_VSI_SRIOV) {
  9298. for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++)
  9299. wr32(hw, I40E_VFQF_HKEY1(i, vf_id), seed_dw[i]);
  9300. } else {
  9301. dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n");
  9302. }
  9303. }
  9304. if (lut) {
  9305. u32 *lut_dw = (u32 *)lut;
  9306. if (vsi->type == I40E_VSI_MAIN) {
  9307. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  9308. return -EINVAL;
  9309. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  9310. wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
  9311. } else if (vsi->type == I40E_VSI_SRIOV) {
  9312. if (lut_size != I40E_VF_HLUT_ARRAY_SIZE)
  9313. return -EINVAL;
  9314. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  9315. wr32(hw, I40E_VFQF_HLUT1(i, vf_id), lut_dw[i]);
  9316. } else {
  9317. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  9318. }
  9319. }
  9320. i40e_flush(hw);
  9321. return 0;
  9322. }
  9323. /**
  9324. * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
  9325. * @vsi: Pointer to VSI structure
  9326. * @seed: Buffer to store the keys
  9327. * @lut: Buffer to store the lookup table entries
  9328. * @lut_size: Size of buffer to store the lookup table entries
  9329. *
  9330. * Returns 0 on success, negative on failure
  9331. */
  9332. static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
  9333. u8 *lut, u16 lut_size)
  9334. {
  9335. struct i40e_pf *pf = vsi->back;
  9336. struct i40e_hw *hw = &pf->hw;
  9337. u16 i;
  9338. if (seed) {
  9339. u32 *seed_dw = (u32 *)seed;
  9340. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  9341. seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
  9342. }
  9343. if (lut) {
  9344. u32 *lut_dw = (u32 *)lut;
  9345. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  9346. return -EINVAL;
  9347. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  9348. lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
  9349. }
  9350. return 0;
  9351. }
  9352. /**
  9353. * i40e_config_rss - Configure RSS keys and lut
  9354. * @vsi: Pointer to VSI structure
  9355. * @seed: RSS hash seed
  9356. * @lut: Lookup table
  9357. * @lut_size: Lookup table size
  9358. *
  9359. * Returns 0 on success, negative on failure
  9360. */
  9361. int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  9362. {
  9363. struct i40e_pf *pf = vsi->back;
  9364. if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)
  9365. return i40e_config_rss_aq(vsi, seed, lut, lut_size);
  9366. else
  9367. return i40e_config_rss_reg(vsi, seed, lut, lut_size);
  9368. }
  9369. /**
  9370. * i40e_get_rss - Get RSS keys and lut
  9371. * @vsi: Pointer to VSI structure
  9372. * @seed: Buffer to store the keys
  9373. * @lut: Buffer to store the lookup table entries
  9374. * lut_size: Size of buffer to store the lookup table entries
  9375. *
  9376. * Returns 0 on success, negative on failure
  9377. */
  9378. int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  9379. {
  9380. struct i40e_pf *pf = vsi->back;
  9381. if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)
  9382. return i40e_get_rss_aq(vsi, seed, lut, lut_size);
  9383. else
  9384. return i40e_get_rss_reg(vsi, seed, lut, lut_size);
  9385. }
  9386. /**
  9387. * i40e_fill_rss_lut - Fill the RSS lookup table with default values
  9388. * @pf: Pointer to board private structure
  9389. * @lut: Lookup table
  9390. * @rss_table_size: Lookup table size
  9391. * @rss_size: Range of queue number for hashing
  9392. */
  9393. void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
  9394. u16 rss_table_size, u16 rss_size)
  9395. {
  9396. u16 i;
  9397. for (i = 0; i < rss_table_size; i++)
  9398. lut[i] = i % rss_size;
  9399. }
  9400. /**
  9401. * i40e_pf_config_rss - Prepare for RSS if used
  9402. * @pf: board private structure
  9403. **/
  9404. static int i40e_pf_config_rss(struct i40e_pf *pf)
  9405. {
  9406. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  9407. u8 seed[I40E_HKEY_ARRAY_SIZE];
  9408. u8 *lut;
  9409. struct i40e_hw *hw = &pf->hw;
  9410. u32 reg_val;
  9411. u64 hena;
  9412. int ret;
  9413. /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
  9414. hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  9415. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  9416. hena |= i40e_pf_get_default_rss_hena(pf);
  9417. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  9418. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  9419. /* Determine the RSS table size based on the hardware capabilities */
  9420. reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
  9421. reg_val = (pf->rss_table_size == 512) ?
  9422. (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
  9423. (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
  9424. i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
  9425. /* Determine the RSS size of the VSI */
  9426. if (!vsi->rss_size) {
  9427. u16 qcount;
  9428. qcount = vsi->num_queue_pairs / vsi->tc_config.numtc;
  9429. vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
  9430. }
  9431. if (!vsi->rss_size)
  9432. return -EINVAL;
  9433. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  9434. if (!lut)
  9435. return -ENOMEM;
  9436. /* Use user configured lut if there is one, otherwise use default */
  9437. if (vsi->rss_lut_user)
  9438. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  9439. else
  9440. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  9441. /* Use user configured hash key if there is one, otherwise
  9442. * use default.
  9443. */
  9444. if (vsi->rss_hkey_user)
  9445. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  9446. else
  9447. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  9448. ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
  9449. kfree(lut);
  9450. return ret;
  9451. }
  9452. /**
  9453. * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
  9454. * @pf: board private structure
  9455. * @queue_count: the requested queue count for rss.
  9456. *
  9457. * returns 0 if rss is not enabled, if enabled returns the final rss queue
  9458. * count which may be different from the requested queue count.
  9459. * Note: expects to be called while under rtnl_lock()
  9460. **/
  9461. int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
  9462. {
  9463. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  9464. int new_rss_size;
  9465. if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
  9466. return 0;
  9467. new_rss_size = min_t(int, queue_count, pf->rss_size_max);
  9468. if (queue_count != vsi->num_queue_pairs) {
  9469. u16 qcount;
  9470. vsi->req_queue_pairs = queue_count;
  9471. i40e_prep_for_reset(pf, true);
  9472. pf->alloc_rss_size = new_rss_size;
  9473. i40e_reset_and_rebuild(pf, true, true);
  9474. /* Discard the user configured hash keys and lut, if less
  9475. * queues are enabled.
  9476. */
  9477. if (queue_count < vsi->rss_size) {
  9478. i40e_clear_rss_config_user(vsi);
  9479. dev_dbg(&pf->pdev->dev,
  9480. "discard user configured hash keys and lut\n");
  9481. }
  9482. /* Reset vsi->rss_size, as number of enabled queues changed */
  9483. qcount = vsi->num_queue_pairs / vsi->tc_config.numtc;
  9484. vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
  9485. i40e_pf_config_rss(pf);
  9486. }
  9487. dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n",
  9488. vsi->req_queue_pairs, pf->rss_size_max);
  9489. return pf->alloc_rss_size;
  9490. }
  9491. /**
  9492. * i40e_get_partition_bw_setting - Retrieve BW settings for this PF partition
  9493. * @pf: board private structure
  9494. **/
  9495. i40e_status i40e_get_partition_bw_setting(struct i40e_pf *pf)
  9496. {
  9497. i40e_status status;
  9498. bool min_valid, max_valid;
  9499. u32 max_bw, min_bw;
  9500. status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
  9501. &min_valid, &max_valid);
  9502. if (!status) {
  9503. if (min_valid)
  9504. pf->min_bw = min_bw;
  9505. if (max_valid)
  9506. pf->max_bw = max_bw;
  9507. }
  9508. return status;
  9509. }
  9510. /**
  9511. * i40e_set_partition_bw_setting - Set BW settings for this PF partition
  9512. * @pf: board private structure
  9513. **/
  9514. i40e_status i40e_set_partition_bw_setting(struct i40e_pf *pf)
  9515. {
  9516. struct i40e_aqc_configure_partition_bw_data bw_data;
  9517. i40e_status status;
  9518. /* Set the valid bit for this PF */
  9519. bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
  9520. bw_data.max_bw[pf->hw.pf_id] = pf->max_bw & I40E_ALT_BW_VALUE_MASK;
  9521. bw_data.min_bw[pf->hw.pf_id] = pf->min_bw & I40E_ALT_BW_VALUE_MASK;
  9522. /* Set the new bandwidths */
  9523. status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
  9524. return status;
  9525. }
  9526. /**
  9527. * i40e_commit_partition_bw_setting - Commit BW settings for this PF partition
  9528. * @pf: board private structure
  9529. **/
  9530. i40e_status i40e_commit_partition_bw_setting(struct i40e_pf *pf)
  9531. {
  9532. /* Commit temporary BW setting to permanent NVM image */
  9533. enum i40e_admin_queue_err last_aq_status;
  9534. i40e_status ret;
  9535. u16 nvm_word;
  9536. if (pf->hw.partition_id != 1) {
  9537. dev_info(&pf->pdev->dev,
  9538. "Commit BW only works on partition 1! This is partition %d",
  9539. pf->hw.partition_id);
  9540. ret = I40E_NOT_SUPPORTED;
  9541. goto bw_commit_out;
  9542. }
  9543. /* Acquire NVM for read access */
  9544. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
  9545. last_aq_status = pf->hw.aq.asq_last_status;
  9546. if (ret) {
  9547. dev_info(&pf->pdev->dev,
  9548. "Cannot acquire NVM for read access, err %s aq_err %s\n",
  9549. i40e_stat_str(&pf->hw, ret),
  9550. i40e_aq_str(&pf->hw, last_aq_status));
  9551. goto bw_commit_out;
  9552. }
  9553. /* Read word 0x10 of NVM - SW compatibility word 1 */
  9554. ret = i40e_aq_read_nvm(&pf->hw,
  9555. I40E_SR_NVM_CONTROL_WORD,
  9556. 0x10, sizeof(nvm_word), &nvm_word,
  9557. false, NULL);
  9558. /* Save off last admin queue command status before releasing
  9559. * the NVM
  9560. */
  9561. last_aq_status = pf->hw.aq.asq_last_status;
  9562. i40e_release_nvm(&pf->hw);
  9563. if (ret) {
  9564. dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
  9565. i40e_stat_str(&pf->hw, ret),
  9566. i40e_aq_str(&pf->hw, last_aq_status));
  9567. goto bw_commit_out;
  9568. }
  9569. /* Wait a bit for NVM release to complete */
  9570. msleep(50);
  9571. /* Acquire NVM for write access */
  9572. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
  9573. last_aq_status = pf->hw.aq.asq_last_status;
  9574. if (ret) {
  9575. dev_info(&pf->pdev->dev,
  9576. "Cannot acquire NVM for write access, err %s aq_err %s\n",
  9577. i40e_stat_str(&pf->hw, ret),
  9578. i40e_aq_str(&pf->hw, last_aq_status));
  9579. goto bw_commit_out;
  9580. }
  9581. /* Write it back out unchanged to initiate update NVM,
  9582. * which will force a write of the shadow (alt) RAM to
  9583. * the NVM - thus storing the bandwidth values permanently.
  9584. */
  9585. ret = i40e_aq_update_nvm(&pf->hw,
  9586. I40E_SR_NVM_CONTROL_WORD,
  9587. 0x10, sizeof(nvm_word),
  9588. &nvm_word, true, NULL);
  9589. /* Save off last admin queue command status before releasing
  9590. * the NVM
  9591. */
  9592. last_aq_status = pf->hw.aq.asq_last_status;
  9593. i40e_release_nvm(&pf->hw);
  9594. if (ret)
  9595. dev_info(&pf->pdev->dev,
  9596. "BW settings NOT SAVED, err %s aq_err %s\n",
  9597. i40e_stat_str(&pf->hw, ret),
  9598. i40e_aq_str(&pf->hw, last_aq_status));
  9599. bw_commit_out:
  9600. return ret;
  9601. }
  9602. /**
  9603. * i40e_sw_init - Initialize general software structures (struct i40e_pf)
  9604. * @pf: board private structure to initialize
  9605. *
  9606. * i40e_sw_init initializes the Adapter private data structure.
  9607. * Fields are initialized based on PCI device information and
  9608. * OS network device settings (MTU size).
  9609. **/
  9610. static int i40e_sw_init(struct i40e_pf *pf)
  9611. {
  9612. int err = 0;
  9613. int size;
  9614. /* Set default capability flags */
  9615. pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
  9616. I40E_FLAG_MSI_ENABLED |
  9617. I40E_FLAG_MSIX_ENABLED;
  9618. /* Set default ITR */
  9619. pf->rx_itr_default = I40E_ITR_RX_DEF;
  9620. pf->tx_itr_default = I40E_ITR_TX_DEF;
  9621. /* Depending on PF configurations, it is possible that the RSS
  9622. * maximum might end up larger than the available queues
  9623. */
  9624. pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
  9625. pf->alloc_rss_size = 1;
  9626. pf->rss_table_size = pf->hw.func_caps.rss_table_size;
  9627. pf->rss_size_max = min_t(int, pf->rss_size_max,
  9628. pf->hw.func_caps.num_tx_qp);
  9629. if (pf->hw.func_caps.rss) {
  9630. pf->flags |= I40E_FLAG_RSS_ENABLED;
  9631. pf->alloc_rss_size = min_t(int, pf->rss_size_max,
  9632. num_online_cpus());
  9633. }
  9634. /* MFP mode enabled */
  9635. if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
  9636. pf->flags |= I40E_FLAG_MFP_ENABLED;
  9637. dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
  9638. if (i40e_get_partition_bw_setting(pf)) {
  9639. dev_warn(&pf->pdev->dev,
  9640. "Could not get partition bw settings\n");
  9641. } else {
  9642. dev_info(&pf->pdev->dev,
  9643. "Partition BW Min = %8.8x, Max = %8.8x\n",
  9644. pf->min_bw, pf->max_bw);
  9645. /* nudge the Tx scheduler */
  9646. i40e_set_partition_bw_setting(pf);
  9647. }
  9648. }
  9649. if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
  9650. (pf->hw.func_caps.fd_filters_best_effort > 0)) {
  9651. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  9652. pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
  9653. if (pf->flags & I40E_FLAG_MFP_ENABLED &&
  9654. pf->hw.num_partitions > 1)
  9655. dev_info(&pf->pdev->dev,
  9656. "Flow Director Sideband mode Disabled in MFP mode\n");
  9657. else
  9658. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  9659. pf->fdir_pf_filter_count =
  9660. pf->hw.func_caps.fd_filters_guaranteed;
  9661. pf->hw.fdir_shared_filter_count =
  9662. pf->hw.func_caps.fd_filters_best_effort;
  9663. }
  9664. if (pf->hw.mac.type == I40E_MAC_X722) {
  9665. pf->hw_features |= (I40E_HW_RSS_AQ_CAPABLE |
  9666. I40E_HW_128_QP_RSS_CAPABLE |
  9667. I40E_HW_ATR_EVICT_CAPABLE |
  9668. I40E_HW_WB_ON_ITR_CAPABLE |
  9669. I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE |
  9670. I40E_HW_NO_PCI_LINK_CHECK |
  9671. I40E_HW_USE_SET_LLDP_MIB |
  9672. I40E_HW_GENEVE_OFFLOAD_CAPABLE |
  9673. I40E_HW_PTP_L4_CAPABLE |
  9674. I40E_HW_WOL_MC_MAGIC_PKT_WAKE |
  9675. I40E_HW_OUTER_UDP_CSUM_CAPABLE);
  9676. #define I40E_FDEVICT_PCTYPE_DEFAULT 0xc03
  9677. if (rd32(&pf->hw, I40E_GLQF_FDEVICTENA(1)) !=
  9678. I40E_FDEVICT_PCTYPE_DEFAULT) {
  9679. dev_warn(&pf->pdev->dev,
  9680. "FD EVICT PCTYPES are not right, disable FD HW EVICT\n");
  9681. pf->hw_features &= ~I40E_HW_ATR_EVICT_CAPABLE;
  9682. }
  9683. } else if ((pf->hw.aq.api_maj_ver > 1) ||
  9684. ((pf->hw.aq.api_maj_ver == 1) &&
  9685. (pf->hw.aq.api_min_ver > 4))) {
  9686. /* Supported in FW API version higher than 1.4 */
  9687. pf->hw_features |= I40E_HW_GENEVE_OFFLOAD_CAPABLE;
  9688. }
  9689. /* Enable HW ATR eviction if possible */
  9690. if (pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE)
  9691. pf->flags |= I40E_FLAG_HW_ATR_EVICT_ENABLED;
  9692. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  9693. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
  9694. (pf->hw.aq.fw_maj_ver < 4))) {
  9695. pf->hw_features |= I40E_HW_RESTART_AUTONEG;
  9696. /* No DCB support for FW < v4.33 */
  9697. pf->hw_features |= I40E_HW_NO_DCB_SUPPORT;
  9698. }
  9699. /* Disable FW LLDP if FW < v4.3 */
  9700. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  9701. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
  9702. (pf->hw.aq.fw_maj_ver < 4)))
  9703. pf->hw_features |= I40E_HW_STOP_FW_LLDP;
  9704. /* Use the FW Set LLDP MIB API if FW > v4.40 */
  9705. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  9706. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
  9707. (pf->hw.aq.fw_maj_ver >= 5)))
  9708. pf->hw_features |= I40E_HW_USE_SET_LLDP_MIB;
  9709. /* Enable PTP L4 if FW > v6.0 */
  9710. if (pf->hw.mac.type == I40E_MAC_XL710 &&
  9711. pf->hw.aq.fw_maj_ver >= 6)
  9712. pf->hw_features |= I40E_HW_PTP_L4_CAPABLE;
  9713. if (pf->hw.func_caps.vmdq) {
  9714. pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
  9715. pf->flags |= I40E_FLAG_VMDQ_ENABLED;
  9716. pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
  9717. }
  9718. if (pf->hw.func_caps.iwarp) {
  9719. pf->flags |= I40E_FLAG_IWARP_ENABLED;
  9720. /* IWARP needs one extra vector for CQP just like MISC.*/
  9721. pf->num_iwarp_msix = (int)num_online_cpus() + 1;
  9722. }
  9723. #ifdef CONFIG_PCI_IOV
  9724. if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
  9725. pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
  9726. pf->flags |= I40E_FLAG_SRIOV_ENABLED;
  9727. pf->num_req_vfs = min_t(int,
  9728. pf->hw.func_caps.num_vfs,
  9729. I40E_MAX_VF_COUNT);
  9730. }
  9731. #endif /* CONFIG_PCI_IOV */
  9732. pf->eeprom_version = 0xDEAD;
  9733. pf->lan_veb = I40E_NO_VEB;
  9734. pf->lan_vsi = I40E_NO_VSI;
  9735. /* By default FW has this off for performance reasons */
  9736. pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
  9737. /* set up queue assignment tracking */
  9738. size = sizeof(struct i40e_lump_tracking)
  9739. + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
  9740. pf->qp_pile = kzalloc(size, GFP_KERNEL);
  9741. if (!pf->qp_pile) {
  9742. err = -ENOMEM;
  9743. goto sw_init_done;
  9744. }
  9745. pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
  9746. pf->qp_pile->search_hint = 0;
  9747. pf->tx_timeout_recovery_level = 1;
  9748. mutex_init(&pf->switch_mutex);
  9749. sw_init_done:
  9750. return err;
  9751. }
  9752. /**
  9753. * i40e_set_ntuple - set the ntuple feature flag and take action
  9754. * @pf: board private structure to initialize
  9755. * @features: the feature set that the stack is suggesting
  9756. *
  9757. * returns a bool to indicate if reset needs to happen
  9758. **/
  9759. bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
  9760. {
  9761. bool need_reset = false;
  9762. /* Check if Flow Director n-tuple support was enabled or disabled. If
  9763. * the state changed, we need to reset.
  9764. */
  9765. if (features & NETIF_F_NTUPLE) {
  9766. /* Enable filters and mark for reset */
  9767. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  9768. need_reset = true;
  9769. /* enable FD_SB only if there is MSI-X vector and no cloud
  9770. * filters exist
  9771. */
  9772. if (pf->num_fdsb_msix > 0 && !pf->num_cloud_filters) {
  9773. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  9774. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  9775. }
  9776. } else {
  9777. /* turn off filters, mark for reset and clear SW filter list */
  9778. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9779. need_reset = true;
  9780. i40e_fdir_filter_exit(pf);
  9781. }
  9782. pf->flags &= ~(I40E_FLAG_FD_SB_ENABLED |
  9783. I40E_FLAG_FD_SB_AUTO_DISABLED);
  9784. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  9785. /* reset fd counters */
  9786. pf->fd_add_err = 0;
  9787. pf->fd_atr_cnt = 0;
  9788. /* if ATR was auto disabled it can be re-enabled. */
  9789. if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) {
  9790. pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
  9791. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  9792. (I40E_DEBUG_FD & pf->hw.debug_mask))
  9793. dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
  9794. }
  9795. }
  9796. return need_reset;
  9797. }
  9798. /**
  9799. * i40e_clear_rss_lut - clear the rx hash lookup table
  9800. * @vsi: the VSI being configured
  9801. **/
  9802. static void i40e_clear_rss_lut(struct i40e_vsi *vsi)
  9803. {
  9804. struct i40e_pf *pf = vsi->back;
  9805. struct i40e_hw *hw = &pf->hw;
  9806. u16 vf_id = vsi->vf_id;
  9807. u8 i;
  9808. if (vsi->type == I40E_VSI_MAIN) {
  9809. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  9810. wr32(hw, I40E_PFQF_HLUT(i), 0);
  9811. } else if (vsi->type == I40E_VSI_SRIOV) {
  9812. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  9813. i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0);
  9814. } else {
  9815. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  9816. }
  9817. }
  9818. /**
  9819. * i40e_set_features - set the netdev feature flags
  9820. * @netdev: ptr to the netdev being adjusted
  9821. * @features: the feature set that the stack is suggesting
  9822. * Note: expects to be called while under rtnl_lock()
  9823. **/
  9824. static int i40e_set_features(struct net_device *netdev,
  9825. netdev_features_t features)
  9826. {
  9827. struct i40e_netdev_priv *np = netdev_priv(netdev);
  9828. struct i40e_vsi *vsi = np->vsi;
  9829. struct i40e_pf *pf = vsi->back;
  9830. bool need_reset;
  9831. if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
  9832. i40e_pf_config_rss(pf);
  9833. else if (!(features & NETIF_F_RXHASH) &&
  9834. netdev->features & NETIF_F_RXHASH)
  9835. i40e_clear_rss_lut(vsi);
  9836. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  9837. i40e_vlan_stripping_enable(vsi);
  9838. else
  9839. i40e_vlan_stripping_disable(vsi);
  9840. if (!(features & NETIF_F_HW_TC) && pf->num_cloud_filters) {
  9841. dev_err(&pf->pdev->dev,
  9842. "Offloaded tc filters active, can't turn hw_tc_offload off");
  9843. return -EINVAL;
  9844. }
  9845. need_reset = i40e_set_ntuple(pf, features);
  9846. if (need_reset)
  9847. i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
  9848. return 0;
  9849. }
  9850. /**
  9851. * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
  9852. * @pf: board private structure
  9853. * @port: The UDP port to look up
  9854. *
  9855. * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
  9856. **/
  9857. static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, u16 port)
  9858. {
  9859. u8 i;
  9860. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  9861. if (pf->udp_ports[i].port == port)
  9862. return i;
  9863. }
  9864. return i;
  9865. }
  9866. /**
  9867. * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
  9868. * @netdev: This physical port's netdev
  9869. * @ti: Tunnel endpoint information
  9870. **/
  9871. static void i40e_udp_tunnel_add(struct net_device *netdev,
  9872. struct udp_tunnel_info *ti)
  9873. {
  9874. struct i40e_netdev_priv *np = netdev_priv(netdev);
  9875. struct i40e_vsi *vsi = np->vsi;
  9876. struct i40e_pf *pf = vsi->back;
  9877. u16 port = ntohs(ti->port);
  9878. u8 next_idx;
  9879. u8 idx;
  9880. idx = i40e_get_udp_port_idx(pf, port);
  9881. /* Check if port already exists */
  9882. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  9883. netdev_info(netdev, "port %d already offloaded\n", port);
  9884. return;
  9885. }
  9886. /* Now check if there is space to add the new port */
  9887. next_idx = i40e_get_udp_port_idx(pf, 0);
  9888. if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  9889. netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n",
  9890. port);
  9891. return;
  9892. }
  9893. switch (ti->type) {
  9894. case UDP_TUNNEL_TYPE_VXLAN:
  9895. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
  9896. break;
  9897. case UDP_TUNNEL_TYPE_GENEVE:
  9898. if (!(pf->hw_features & I40E_HW_GENEVE_OFFLOAD_CAPABLE))
  9899. return;
  9900. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
  9901. break;
  9902. default:
  9903. return;
  9904. }
  9905. /* New port: add it and mark its index in the bitmap */
  9906. pf->udp_ports[next_idx].port = port;
  9907. pf->pending_udp_bitmap |= BIT_ULL(next_idx);
  9908. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  9909. }
  9910. /**
  9911. * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
  9912. * @netdev: This physical port's netdev
  9913. * @ti: Tunnel endpoint information
  9914. **/
  9915. static void i40e_udp_tunnel_del(struct net_device *netdev,
  9916. struct udp_tunnel_info *ti)
  9917. {
  9918. struct i40e_netdev_priv *np = netdev_priv(netdev);
  9919. struct i40e_vsi *vsi = np->vsi;
  9920. struct i40e_pf *pf = vsi->back;
  9921. u16 port = ntohs(ti->port);
  9922. u8 idx;
  9923. idx = i40e_get_udp_port_idx(pf, port);
  9924. /* Check if port already exists */
  9925. if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS)
  9926. goto not_found;
  9927. switch (ti->type) {
  9928. case UDP_TUNNEL_TYPE_VXLAN:
  9929. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN)
  9930. goto not_found;
  9931. break;
  9932. case UDP_TUNNEL_TYPE_GENEVE:
  9933. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE)
  9934. goto not_found;
  9935. break;
  9936. default:
  9937. goto not_found;
  9938. }
  9939. /* if port exists, set it to 0 (mark for deletion)
  9940. * and make it pending
  9941. */
  9942. pf->udp_ports[idx].port = 0;
  9943. pf->pending_udp_bitmap |= BIT_ULL(idx);
  9944. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  9945. return;
  9946. not_found:
  9947. netdev_warn(netdev, "UDP port %d was not found, not deleting\n",
  9948. port);
  9949. }
  9950. static int i40e_get_phys_port_id(struct net_device *netdev,
  9951. struct netdev_phys_item_id *ppid)
  9952. {
  9953. struct i40e_netdev_priv *np = netdev_priv(netdev);
  9954. struct i40e_pf *pf = np->vsi->back;
  9955. struct i40e_hw *hw = &pf->hw;
  9956. if (!(pf->hw_features & I40E_HW_PORT_ID_VALID))
  9957. return -EOPNOTSUPP;
  9958. ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
  9959. memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
  9960. return 0;
  9961. }
  9962. /**
  9963. * i40e_ndo_fdb_add - add an entry to the hardware database
  9964. * @ndm: the input from the stack
  9965. * @tb: pointer to array of nladdr (unused)
  9966. * @dev: the net device pointer
  9967. * @addr: the MAC address entry being added
  9968. * @flags: instructions from stack about fdb operation
  9969. */
  9970. static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  9971. struct net_device *dev,
  9972. const unsigned char *addr, u16 vid,
  9973. u16 flags)
  9974. {
  9975. struct i40e_netdev_priv *np = netdev_priv(dev);
  9976. struct i40e_pf *pf = np->vsi->back;
  9977. int err = 0;
  9978. if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
  9979. return -EOPNOTSUPP;
  9980. if (vid) {
  9981. pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
  9982. return -EINVAL;
  9983. }
  9984. /* Hardware does not support aging addresses so if a
  9985. * ndm_state is given only allow permanent addresses
  9986. */
  9987. if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
  9988. netdev_info(dev, "FDB only supports static addresses\n");
  9989. return -EINVAL;
  9990. }
  9991. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
  9992. err = dev_uc_add_excl(dev, addr);
  9993. else if (is_multicast_ether_addr(addr))
  9994. err = dev_mc_add_excl(dev, addr);
  9995. else
  9996. err = -EINVAL;
  9997. /* Only return duplicate errors if NLM_F_EXCL is set */
  9998. if (err == -EEXIST && !(flags & NLM_F_EXCL))
  9999. err = 0;
  10000. return err;
  10001. }
  10002. /**
  10003. * i40e_ndo_bridge_setlink - Set the hardware bridge mode
  10004. * @dev: the netdev being configured
  10005. * @nlh: RTNL message
  10006. *
  10007. * Inserts a new hardware bridge if not already created and
  10008. * enables the bridging mode requested (VEB or VEPA). If the
  10009. * hardware bridge has already been inserted and the request
  10010. * is to change the mode then that requires a PF reset to
  10011. * allow rebuild of the components with required hardware
  10012. * bridge mode enabled.
  10013. *
  10014. * Note: expects to be called while under rtnl_lock()
  10015. **/
  10016. static int i40e_ndo_bridge_setlink(struct net_device *dev,
  10017. struct nlmsghdr *nlh,
  10018. u16 flags)
  10019. {
  10020. struct i40e_netdev_priv *np = netdev_priv(dev);
  10021. struct i40e_vsi *vsi = np->vsi;
  10022. struct i40e_pf *pf = vsi->back;
  10023. struct i40e_veb *veb = NULL;
  10024. struct nlattr *attr, *br_spec;
  10025. int i, rem;
  10026. /* Only for PF VSI for now */
  10027. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  10028. return -EOPNOTSUPP;
  10029. /* Find the HW bridge for PF VSI */
  10030. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  10031. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  10032. veb = pf->veb[i];
  10033. }
  10034. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  10035. nla_for_each_nested(attr, br_spec, rem) {
  10036. __u16 mode;
  10037. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  10038. continue;
  10039. mode = nla_get_u16(attr);
  10040. if ((mode != BRIDGE_MODE_VEPA) &&
  10041. (mode != BRIDGE_MODE_VEB))
  10042. return -EINVAL;
  10043. /* Insert a new HW bridge */
  10044. if (!veb) {
  10045. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  10046. vsi->tc_config.enabled_tc);
  10047. if (veb) {
  10048. veb->bridge_mode = mode;
  10049. i40e_config_bridge_mode(veb);
  10050. } else {
  10051. /* No Bridge HW offload available */
  10052. return -ENOENT;
  10053. }
  10054. break;
  10055. } else if (mode != veb->bridge_mode) {
  10056. /* Existing HW bridge but different mode needs reset */
  10057. veb->bridge_mode = mode;
  10058. /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
  10059. if (mode == BRIDGE_MODE_VEB)
  10060. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  10061. else
  10062. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  10063. i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
  10064. break;
  10065. }
  10066. }
  10067. return 0;
  10068. }
  10069. /**
  10070. * i40e_ndo_bridge_getlink - Get the hardware bridge mode
  10071. * @skb: skb buff
  10072. * @pid: process id
  10073. * @seq: RTNL message seq #
  10074. * @dev: the netdev being configured
  10075. * @filter_mask: unused
  10076. * @nlflags: netlink flags passed in
  10077. *
  10078. * Return the mode in which the hardware bridge is operating in
  10079. * i.e VEB or VEPA.
  10080. **/
  10081. static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  10082. struct net_device *dev,
  10083. u32 __always_unused filter_mask,
  10084. int nlflags)
  10085. {
  10086. struct i40e_netdev_priv *np = netdev_priv(dev);
  10087. struct i40e_vsi *vsi = np->vsi;
  10088. struct i40e_pf *pf = vsi->back;
  10089. struct i40e_veb *veb = NULL;
  10090. int i;
  10091. /* Only for PF VSI for now */
  10092. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  10093. return -EOPNOTSUPP;
  10094. /* Find the HW bridge for the PF VSI */
  10095. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  10096. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  10097. veb = pf->veb[i];
  10098. }
  10099. if (!veb)
  10100. return 0;
  10101. return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
  10102. 0, 0, nlflags, filter_mask, NULL);
  10103. }
  10104. /**
  10105. * i40e_features_check - Validate encapsulated packet conforms to limits
  10106. * @skb: skb buff
  10107. * @dev: This physical port's netdev
  10108. * @features: Offload features that the stack believes apply
  10109. **/
  10110. static netdev_features_t i40e_features_check(struct sk_buff *skb,
  10111. struct net_device *dev,
  10112. netdev_features_t features)
  10113. {
  10114. size_t len;
  10115. /* No point in doing any of this if neither checksum nor GSO are
  10116. * being requested for this frame. We can rule out both by just
  10117. * checking for CHECKSUM_PARTIAL
  10118. */
  10119. if (skb->ip_summed != CHECKSUM_PARTIAL)
  10120. return features;
  10121. /* We cannot support GSO if the MSS is going to be less than
  10122. * 64 bytes. If it is then we need to drop support for GSO.
  10123. */
  10124. if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
  10125. features &= ~NETIF_F_GSO_MASK;
  10126. /* MACLEN can support at most 63 words */
  10127. len = skb_network_header(skb) - skb->data;
  10128. if (len & ~(63 * 2))
  10129. goto out_err;
  10130. /* IPLEN and EIPLEN can support at most 127 dwords */
  10131. len = skb_transport_header(skb) - skb_network_header(skb);
  10132. if (len & ~(127 * 4))
  10133. goto out_err;
  10134. if (skb->encapsulation) {
  10135. /* L4TUNLEN can support 127 words */
  10136. len = skb_inner_network_header(skb) - skb_transport_header(skb);
  10137. if (len & ~(127 * 2))
  10138. goto out_err;
  10139. /* IPLEN can support at most 127 dwords */
  10140. len = skb_inner_transport_header(skb) -
  10141. skb_inner_network_header(skb);
  10142. if (len & ~(127 * 4))
  10143. goto out_err;
  10144. }
  10145. /* No need to validate L4LEN as TCP is the only protocol with a
  10146. * a flexible value and we support all possible values supported
  10147. * by TCP, which is at most 15 dwords
  10148. */
  10149. return features;
  10150. out_err:
  10151. return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
  10152. }
  10153. /**
  10154. * i40e_xdp_setup - add/remove an XDP program
  10155. * @vsi: VSI to changed
  10156. * @prog: XDP program
  10157. **/
  10158. static int i40e_xdp_setup(struct i40e_vsi *vsi,
  10159. struct bpf_prog *prog)
  10160. {
  10161. int frame_size = vsi->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  10162. struct i40e_pf *pf = vsi->back;
  10163. struct bpf_prog *old_prog;
  10164. bool need_reset;
  10165. int i;
  10166. /* Don't allow frames that span over multiple buffers */
  10167. if (frame_size > vsi->rx_buf_len)
  10168. return -EINVAL;
  10169. if (!i40e_enabled_xdp_vsi(vsi) && !prog)
  10170. return 0;
  10171. /* When turning XDP on->off/off->on we reset and rebuild the rings. */
  10172. need_reset = (i40e_enabled_xdp_vsi(vsi) != !!prog);
  10173. if (need_reset)
  10174. i40e_prep_for_reset(pf, true);
  10175. old_prog = xchg(&vsi->xdp_prog, prog);
  10176. if (need_reset)
  10177. i40e_reset_and_rebuild(pf, true, true);
  10178. for (i = 0; i < vsi->num_queue_pairs; i++)
  10179. WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
  10180. if (old_prog)
  10181. bpf_prog_put(old_prog);
  10182. return 0;
  10183. }
  10184. /**
  10185. * i40e_xdp - implements ndo_bpf for i40e
  10186. * @dev: netdevice
  10187. * @xdp: XDP command
  10188. **/
  10189. static int i40e_xdp(struct net_device *dev,
  10190. struct netdev_bpf *xdp)
  10191. {
  10192. struct i40e_netdev_priv *np = netdev_priv(dev);
  10193. struct i40e_vsi *vsi = np->vsi;
  10194. if (vsi->type != I40E_VSI_MAIN)
  10195. return -EINVAL;
  10196. switch (xdp->command) {
  10197. case XDP_SETUP_PROG:
  10198. return i40e_xdp_setup(vsi, xdp->prog);
  10199. case XDP_QUERY_PROG:
  10200. xdp->prog_attached = i40e_enabled_xdp_vsi(vsi);
  10201. xdp->prog_id = vsi->xdp_prog ? vsi->xdp_prog->aux->id : 0;
  10202. return 0;
  10203. default:
  10204. return -EINVAL;
  10205. }
  10206. }
  10207. static const struct net_device_ops i40e_netdev_ops = {
  10208. .ndo_open = i40e_open,
  10209. .ndo_stop = i40e_close,
  10210. .ndo_start_xmit = i40e_lan_xmit_frame,
  10211. .ndo_get_stats64 = i40e_get_netdev_stats_struct,
  10212. .ndo_set_rx_mode = i40e_set_rx_mode,
  10213. .ndo_validate_addr = eth_validate_addr,
  10214. .ndo_set_mac_address = i40e_set_mac,
  10215. .ndo_change_mtu = i40e_change_mtu,
  10216. .ndo_do_ioctl = i40e_ioctl,
  10217. .ndo_tx_timeout = i40e_tx_timeout,
  10218. .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
  10219. .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
  10220. #ifdef CONFIG_NET_POLL_CONTROLLER
  10221. .ndo_poll_controller = i40e_netpoll,
  10222. #endif
  10223. .ndo_setup_tc = __i40e_setup_tc,
  10224. .ndo_set_features = i40e_set_features,
  10225. .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
  10226. .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
  10227. .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
  10228. .ndo_get_vf_config = i40e_ndo_get_vf_config,
  10229. .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
  10230. .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
  10231. .ndo_set_vf_trust = i40e_ndo_set_vf_trust,
  10232. .ndo_udp_tunnel_add = i40e_udp_tunnel_add,
  10233. .ndo_udp_tunnel_del = i40e_udp_tunnel_del,
  10234. .ndo_get_phys_port_id = i40e_get_phys_port_id,
  10235. .ndo_fdb_add = i40e_ndo_fdb_add,
  10236. .ndo_features_check = i40e_features_check,
  10237. .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
  10238. .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
  10239. .ndo_bpf = i40e_xdp,
  10240. };
  10241. /**
  10242. * i40e_config_netdev - Setup the netdev flags
  10243. * @vsi: the VSI being configured
  10244. *
  10245. * Returns 0 on success, negative value on failure
  10246. **/
  10247. static int i40e_config_netdev(struct i40e_vsi *vsi)
  10248. {
  10249. struct i40e_pf *pf = vsi->back;
  10250. struct i40e_hw *hw = &pf->hw;
  10251. struct i40e_netdev_priv *np;
  10252. struct net_device *netdev;
  10253. u8 broadcast[ETH_ALEN];
  10254. u8 mac_addr[ETH_ALEN];
  10255. int etherdev_size;
  10256. netdev_features_t hw_enc_features;
  10257. netdev_features_t hw_features;
  10258. etherdev_size = sizeof(struct i40e_netdev_priv);
  10259. netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
  10260. if (!netdev)
  10261. return -ENOMEM;
  10262. vsi->netdev = netdev;
  10263. np = netdev_priv(netdev);
  10264. np->vsi = vsi;
  10265. hw_enc_features = NETIF_F_SG |
  10266. NETIF_F_IP_CSUM |
  10267. NETIF_F_IPV6_CSUM |
  10268. NETIF_F_HIGHDMA |
  10269. NETIF_F_SOFT_FEATURES |
  10270. NETIF_F_TSO |
  10271. NETIF_F_TSO_ECN |
  10272. NETIF_F_TSO6 |
  10273. NETIF_F_GSO_GRE |
  10274. NETIF_F_GSO_GRE_CSUM |
  10275. NETIF_F_GSO_PARTIAL |
  10276. NETIF_F_GSO_UDP_TUNNEL |
  10277. NETIF_F_GSO_UDP_TUNNEL_CSUM |
  10278. NETIF_F_SCTP_CRC |
  10279. NETIF_F_RXHASH |
  10280. NETIF_F_RXCSUM |
  10281. 0;
  10282. if (!(pf->hw_features & I40E_HW_OUTER_UDP_CSUM_CAPABLE))
  10283. netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
  10284. netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
  10285. netdev->hw_enc_features |= hw_enc_features;
  10286. /* record features VLANs can make use of */
  10287. netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID;
  10288. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  10289. netdev->hw_features |= NETIF_F_NTUPLE | NETIF_F_HW_TC;
  10290. hw_features = hw_enc_features |
  10291. NETIF_F_HW_VLAN_CTAG_TX |
  10292. NETIF_F_HW_VLAN_CTAG_RX;
  10293. netdev->hw_features |= hw_features;
  10294. netdev->features |= hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
  10295. netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
  10296. if (vsi->type == I40E_VSI_MAIN) {
  10297. SET_NETDEV_DEV(netdev, &pf->pdev->dev);
  10298. ether_addr_copy(mac_addr, hw->mac.perm_addr);
  10299. /* The following steps are necessary for two reasons. First,
  10300. * some older NVM configurations load a default MAC-VLAN
  10301. * filter that will accept any tagged packet, and we want to
  10302. * replace this with a normal filter. Additionally, it is
  10303. * possible our MAC address was provided by the platform using
  10304. * Open Firmware or similar.
  10305. *
  10306. * Thus, we need to remove the default filter and install one
  10307. * specific to the MAC address.
  10308. */
  10309. i40e_rm_default_mac_filter(vsi, mac_addr);
  10310. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10311. i40e_add_mac_filter(vsi, mac_addr);
  10312. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10313. } else {
  10314. /* Relate the VSI_VMDQ name to the VSI_MAIN name. Note that we
  10315. * are still limited by IFNAMSIZ, but we're adding 'v%d\0' to
  10316. * the end, which is 4 bytes long, so force truncation of the
  10317. * original name by IFNAMSIZ - 4
  10318. */
  10319. snprintf(netdev->name, IFNAMSIZ, "%.*sv%%d",
  10320. IFNAMSIZ - 4,
  10321. pf->vsi[pf->lan_vsi]->netdev->name);
  10322. random_ether_addr(mac_addr);
  10323. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10324. i40e_add_mac_filter(vsi, mac_addr);
  10325. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10326. }
  10327. /* Add the broadcast filter so that we initially will receive
  10328. * broadcast packets. Note that when a new VLAN is first added the
  10329. * driver will convert all filters marked I40E_VLAN_ANY into VLAN
  10330. * specific filters as part of transitioning into "vlan" operation.
  10331. * When more VLANs are added, the driver will copy each existing MAC
  10332. * filter and add it for the new VLAN.
  10333. *
  10334. * Broadcast filters are handled specially by
  10335. * i40e_sync_filters_subtask, as the driver must to set the broadcast
  10336. * promiscuous bit instead of adding this directly as a MAC/VLAN
  10337. * filter. The subtask will update the correct broadcast promiscuous
  10338. * bits as VLANs become active or inactive.
  10339. */
  10340. eth_broadcast_addr(broadcast);
  10341. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10342. i40e_add_mac_filter(vsi, broadcast);
  10343. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10344. ether_addr_copy(netdev->dev_addr, mac_addr);
  10345. ether_addr_copy(netdev->perm_addr, mac_addr);
  10346. netdev->priv_flags |= IFF_UNICAST_FLT;
  10347. netdev->priv_flags |= IFF_SUPP_NOFCS;
  10348. /* Setup netdev TC information */
  10349. i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
  10350. netdev->netdev_ops = &i40e_netdev_ops;
  10351. netdev->watchdog_timeo = 5 * HZ;
  10352. i40e_set_ethtool_ops(netdev);
  10353. /* MTU range: 68 - 9706 */
  10354. netdev->min_mtu = ETH_MIN_MTU;
  10355. netdev->max_mtu = I40E_MAX_RXBUFFER - I40E_PACKET_HDR_PAD;
  10356. return 0;
  10357. }
  10358. /**
  10359. * i40e_vsi_delete - Delete a VSI from the switch
  10360. * @vsi: the VSI being removed
  10361. *
  10362. * Returns 0 on success, negative value on failure
  10363. **/
  10364. static void i40e_vsi_delete(struct i40e_vsi *vsi)
  10365. {
  10366. /* remove default VSI is not allowed */
  10367. if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
  10368. return;
  10369. i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
  10370. }
  10371. /**
  10372. * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
  10373. * @vsi: the VSI being queried
  10374. *
  10375. * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
  10376. **/
  10377. int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
  10378. {
  10379. struct i40e_veb *veb;
  10380. struct i40e_pf *pf = vsi->back;
  10381. /* Uplink is not a bridge so default to VEB */
  10382. if (vsi->veb_idx == I40E_NO_VEB)
  10383. return 1;
  10384. veb = pf->veb[vsi->veb_idx];
  10385. if (!veb) {
  10386. dev_info(&pf->pdev->dev,
  10387. "There is no veb associated with the bridge\n");
  10388. return -ENOENT;
  10389. }
  10390. /* Uplink is a bridge in VEPA mode */
  10391. if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
  10392. return 0;
  10393. } else {
  10394. /* Uplink is a bridge in VEB mode */
  10395. return 1;
  10396. }
  10397. /* VEPA is now default bridge, so return 0 */
  10398. return 0;
  10399. }
  10400. /**
  10401. * i40e_add_vsi - Add a VSI to the switch
  10402. * @vsi: the VSI being configured
  10403. *
  10404. * This initializes a VSI context depending on the VSI type to be added and
  10405. * passes it down to the add_vsi aq command.
  10406. **/
  10407. static int i40e_add_vsi(struct i40e_vsi *vsi)
  10408. {
  10409. int ret = -ENODEV;
  10410. struct i40e_pf *pf = vsi->back;
  10411. struct i40e_hw *hw = &pf->hw;
  10412. struct i40e_vsi_context ctxt;
  10413. struct i40e_mac_filter *f;
  10414. struct hlist_node *h;
  10415. int bkt;
  10416. u8 enabled_tc = 0x1; /* TC0 enabled */
  10417. int f_count = 0;
  10418. memset(&ctxt, 0, sizeof(ctxt));
  10419. switch (vsi->type) {
  10420. case I40E_VSI_MAIN:
  10421. /* The PF's main VSI is already setup as part of the
  10422. * device initialization, so we'll not bother with
  10423. * the add_vsi call, but we will retrieve the current
  10424. * VSI context.
  10425. */
  10426. ctxt.seid = pf->main_vsi_seid;
  10427. ctxt.pf_num = pf->hw.pf_id;
  10428. ctxt.vf_num = 0;
  10429. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  10430. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  10431. if (ret) {
  10432. dev_info(&pf->pdev->dev,
  10433. "couldn't get PF vsi config, err %s aq_err %s\n",
  10434. i40e_stat_str(&pf->hw, ret),
  10435. i40e_aq_str(&pf->hw,
  10436. pf->hw.aq.asq_last_status));
  10437. return -ENOENT;
  10438. }
  10439. vsi->info = ctxt.info;
  10440. vsi->info.valid_sections = 0;
  10441. vsi->seid = ctxt.seid;
  10442. vsi->id = ctxt.vsi_number;
  10443. enabled_tc = i40e_pf_get_tc_map(pf);
  10444. /* Source pruning is enabled by default, so the flag is
  10445. * negative logic - if it's set, we need to fiddle with
  10446. * the VSI to disable source pruning.
  10447. */
  10448. if (pf->flags & I40E_FLAG_SOURCE_PRUNING_DISABLED) {
  10449. memset(&ctxt, 0, sizeof(ctxt));
  10450. ctxt.seid = pf->main_vsi_seid;
  10451. ctxt.pf_num = pf->hw.pf_id;
  10452. ctxt.vf_num = 0;
  10453. ctxt.info.valid_sections |=
  10454. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10455. ctxt.info.switch_id =
  10456. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
  10457. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  10458. if (ret) {
  10459. dev_info(&pf->pdev->dev,
  10460. "update vsi failed, err %s aq_err %s\n",
  10461. i40e_stat_str(&pf->hw, ret),
  10462. i40e_aq_str(&pf->hw,
  10463. pf->hw.aq.asq_last_status));
  10464. ret = -ENOENT;
  10465. goto err;
  10466. }
  10467. }
  10468. /* MFP mode setup queue map and update VSI */
  10469. if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
  10470. !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
  10471. memset(&ctxt, 0, sizeof(ctxt));
  10472. ctxt.seid = pf->main_vsi_seid;
  10473. ctxt.pf_num = pf->hw.pf_id;
  10474. ctxt.vf_num = 0;
  10475. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  10476. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  10477. if (ret) {
  10478. dev_info(&pf->pdev->dev,
  10479. "update vsi failed, err %s aq_err %s\n",
  10480. i40e_stat_str(&pf->hw, ret),
  10481. i40e_aq_str(&pf->hw,
  10482. pf->hw.aq.asq_last_status));
  10483. ret = -ENOENT;
  10484. goto err;
  10485. }
  10486. /* update the local VSI info queue map */
  10487. i40e_vsi_update_queue_map(vsi, &ctxt);
  10488. vsi->info.valid_sections = 0;
  10489. } else {
  10490. /* Default/Main VSI is only enabled for TC0
  10491. * reconfigure it to enable all TCs that are
  10492. * available on the port in SFP mode.
  10493. * For MFP case the iSCSI PF would use this
  10494. * flow to enable LAN+iSCSI TC.
  10495. */
  10496. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  10497. if (ret) {
  10498. /* Single TC condition is not fatal,
  10499. * message and continue
  10500. */
  10501. dev_info(&pf->pdev->dev,
  10502. "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
  10503. enabled_tc,
  10504. i40e_stat_str(&pf->hw, ret),
  10505. i40e_aq_str(&pf->hw,
  10506. pf->hw.aq.asq_last_status));
  10507. }
  10508. }
  10509. break;
  10510. case I40E_VSI_FDIR:
  10511. ctxt.pf_num = hw->pf_id;
  10512. ctxt.vf_num = 0;
  10513. ctxt.uplink_seid = vsi->uplink_seid;
  10514. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  10515. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  10516. if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
  10517. (i40e_is_vsi_uplink_mode_veb(vsi))) {
  10518. ctxt.info.valid_sections |=
  10519. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10520. ctxt.info.switch_id =
  10521. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  10522. }
  10523. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  10524. break;
  10525. case I40E_VSI_VMDQ2:
  10526. ctxt.pf_num = hw->pf_id;
  10527. ctxt.vf_num = 0;
  10528. ctxt.uplink_seid = vsi->uplink_seid;
  10529. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  10530. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  10531. /* This VSI is connected to VEB so the switch_id
  10532. * should be set to zero by default.
  10533. */
  10534. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  10535. ctxt.info.valid_sections |=
  10536. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10537. ctxt.info.switch_id =
  10538. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  10539. }
  10540. /* Setup the VSI tx/rx queue map for TC0 only for now */
  10541. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  10542. break;
  10543. case I40E_VSI_SRIOV:
  10544. ctxt.pf_num = hw->pf_id;
  10545. ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
  10546. ctxt.uplink_seid = vsi->uplink_seid;
  10547. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  10548. ctxt.flags = I40E_AQ_VSI_TYPE_VF;
  10549. /* This VSI is connected to VEB so the switch_id
  10550. * should be set to zero by default.
  10551. */
  10552. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  10553. ctxt.info.valid_sections |=
  10554. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10555. ctxt.info.switch_id =
  10556. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  10557. }
  10558. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  10559. ctxt.info.valid_sections |=
  10560. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  10561. ctxt.info.queueing_opt_flags |=
  10562. (I40E_AQ_VSI_QUE_OPT_TCP_ENA |
  10563. I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI);
  10564. }
  10565. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  10566. ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
  10567. if (pf->vf[vsi->vf_id].spoofchk) {
  10568. ctxt.info.valid_sections |=
  10569. cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
  10570. ctxt.info.sec_flags |=
  10571. (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
  10572. I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
  10573. }
  10574. /* Setup the VSI tx/rx queue map for TC0 only for now */
  10575. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  10576. break;
  10577. case I40E_VSI_IWARP:
  10578. /* send down message to iWARP */
  10579. break;
  10580. default:
  10581. return -ENODEV;
  10582. }
  10583. if (vsi->type != I40E_VSI_MAIN) {
  10584. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  10585. if (ret) {
  10586. dev_info(&vsi->back->pdev->dev,
  10587. "add vsi failed, err %s aq_err %s\n",
  10588. i40e_stat_str(&pf->hw, ret),
  10589. i40e_aq_str(&pf->hw,
  10590. pf->hw.aq.asq_last_status));
  10591. ret = -ENOENT;
  10592. goto err;
  10593. }
  10594. vsi->info = ctxt.info;
  10595. vsi->info.valid_sections = 0;
  10596. vsi->seid = ctxt.seid;
  10597. vsi->id = ctxt.vsi_number;
  10598. }
  10599. vsi->active_filters = 0;
  10600. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  10601. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10602. /* If macvlan filters already exist, force them to get loaded */
  10603. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  10604. f->state = I40E_FILTER_NEW;
  10605. f_count++;
  10606. }
  10607. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10608. if (f_count) {
  10609. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  10610. pf->flags |= I40E_FLAG_FILTER_SYNC;
  10611. }
  10612. /* Update VSI BW information */
  10613. ret = i40e_vsi_get_bw_info(vsi);
  10614. if (ret) {
  10615. dev_info(&pf->pdev->dev,
  10616. "couldn't get vsi bw info, err %s aq_err %s\n",
  10617. i40e_stat_str(&pf->hw, ret),
  10618. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  10619. /* VSI is already added so not tearing that up */
  10620. ret = 0;
  10621. }
  10622. err:
  10623. return ret;
  10624. }
  10625. /**
  10626. * i40e_vsi_release - Delete a VSI and free its resources
  10627. * @vsi: the VSI being removed
  10628. *
  10629. * Returns 0 on success or < 0 on error
  10630. **/
  10631. int i40e_vsi_release(struct i40e_vsi *vsi)
  10632. {
  10633. struct i40e_mac_filter *f;
  10634. struct hlist_node *h;
  10635. struct i40e_veb *veb = NULL;
  10636. struct i40e_pf *pf;
  10637. u16 uplink_seid;
  10638. int i, n, bkt;
  10639. pf = vsi->back;
  10640. /* release of a VEB-owner or last VSI is not allowed */
  10641. if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
  10642. dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
  10643. vsi->seid, vsi->uplink_seid);
  10644. return -ENODEV;
  10645. }
  10646. if (vsi == pf->vsi[pf->lan_vsi] &&
  10647. !test_bit(__I40E_DOWN, pf->state)) {
  10648. dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
  10649. return -ENODEV;
  10650. }
  10651. uplink_seid = vsi->uplink_seid;
  10652. if (vsi->type != I40E_VSI_SRIOV) {
  10653. if (vsi->netdev_registered) {
  10654. vsi->netdev_registered = false;
  10655. if (vsi->netdev) {
  10656. /* results in a call to i40e_close() */
  10657. unregister_netdev(vsi->netdev);
  10658. }
  10659. } else {
  10660. i40e_vsi_close(vsi);
  10661. }
  10662. i40e_vsi_disable_irq(vsi);
  10663. }
  10664. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10665. /* clear the sync flag on all filters */
  10666. if (vsi->netdev) {
  10667. __dev_uc_unsync(vsi->netdev, NULL);
  10668. __dev_mc_unsync(vsi->netdev, NULL);
  10669. }
  10670. /* make sure any remaining filters are marked for deletion */
  10671. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
  10672. __i40e_del_filter(vsi, f);
  10673. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10674. i40e_sync_vsi_filters(vsi);
  10675. i40e_vsi_delete(vsi);
  10676. i40e_vsi_free_q_vectors(vsi);
  10677. if (vsi->netdev) {
  10678. free_netdev(vsi->netdev);
  10679. vsi->netdev = NULL;
  10680. }
  10681. i40e_vsi_clear_rings(vsi);
  10682. i40e_vsi_clear(vsi);
  10683. /* If this was the last thing on the VEB, except for the
  10684. * controlling VSI, remove the VEB, which puts the controlling
  10685. * VSI onto the next level down in the switch.
  10686. *
  10687. * Well, okay, there's one more exception here: don't remove
  10688. * the orphan VEBs yet. We'll wait for an explicit remove request
  10689. * from up the network stack.
  10690. */
  10691. for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
  10692. if (pf->vsi[i] &&
  10693. pf->vsi[i]->uplink_seid == uplink_seid &&
  10694. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  10695. n++; /* count the VSIs */
  10696. }
  10697. }
  10698. for (i = 0; i < I40E_MAX_VEB; i++) {
  10699. if (!pf->veb[i])
  10700. continue;
  10701. if (pf->veb[i]->uplink_seid == uplink_seid)
  10702. n++; /* count the VEBs */
  10703. if (pf->veb[i]->seid == uplink_seid)
  10704. veb = pf->veb[i];
  10705. }
  10706. if (n == 0 && veb && veb->uplink_seid != 0)
  10707. i40e_veb_release(veb);
  10708. return 0;
  10709. }
  10710. /**
  10711. * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
  10712. * @vsi: ptr to the VSI
  10713. *
  10714. * This should only be called after i40e_vsi_mem_alloc() which allocates the
  10715. * corresponding SW VSI structure and initializes num_queue_pairs for the
  10716. * newly allocated VSI.
  10717. *
  10718. * Returns 0 on success or negative on failure
  10719. **/
  10720. static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
  10721. {
  10722. int ret = -ENOENT;
  10723. struct i40e_pf *pf = vsi->back;
  10724. if (vsi->q_vectors[0]) {
  10725. dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
  10726. vsi->seid);
  10727. return -EEXIST;
  10728. }
  10729. if (vsi->base_vector) {
  10730. dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
  10731. vsi->seid, vsi->base_vector);
  10732. return -EEXIST;
  10733. }
  10734. ret = i40e_vsi_alloc_q_vectors(vsi);
  10735. if (ret) {
  10736. dev_info(&pf->pdev->dev,
  10737. "failed to allocate %d q_vector for VSI %d, ret=%d\n",
  10738. vsi->num_q_vectors, vsi->seid, ret);
  10739. vsi->num_q_vectors = 0;
  10740. goto vector_setup_out;
  10741. }
  10742. /* In Legacy mode, we do not have to get any other vector since we
  10743. * piggyback on the misc/ICR0 for queue interrupts.
  10744. */
  10745. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  10746. return ret;
  10747. if (vsi->num_q_vectors)
  10748. vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
  10749. vsi->num_q_vectors, vsi->idx);
  10750. if (vsi->base_vector < 0) {
  10751. dev_info(&pf->pdev->dev,
  10752. "failed to get tracking for %d vectors for VSI %d, err=%d\n",
  10753. vsi->num_q_vectors, vsi->seid, vsi->base_vector);
  10754. i40e_vsi_free_q_vectors(vsi);
  10755. ret = -ENOENT;
  10756. goto vector_setup_out;
  10757. }
  10758. vector_setup_out:
  10759. return ret;
  10760. }
  10761. /**
  10762. * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
  10763. * @vsi: pointer to the vsi.
  10764. *
  10765. * This re-allocates a vsi's queue resources.
  10766. *
  10767. * Returns pointer to the successfully allocated and configured VSI sw struct
  10768. * on success, otherwise returns NULL on failure.
  10769. **/
  10770. static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
  10771. {
  10772. u16 alloc_queue_pairs;
  10773. struct i40e_pf *pf;
  10774. u8 enabled_tc;
  10775. int ret;
  10776. if (!vsi)
  10777. return NULL;
  10778. pf = vsi->back;
  10779. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  10780. i40e_vsi_clear_rings(vsi);
  10781. i40e_vsi_free_arrays(vsi, false);
  10782. i40e_set_num_rings_in_vsi(vsi);
  10783. ret = i40e_vsi_alloc_arrays(vsi, false);
  10784. if (ret)
  10785. goto err_vsi;
  10786. alloc_queue_pairs = vsi->alloc_queue_pairs *
  10787. (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
  10788. ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
  10789. if (ret < 0) {
  10790. dev_info(&pf->pdev->dev,
  10791. "failed to get tracking for %d queues for VSI %d err %d\n",
  10792. alloc_queue_pairs, vsi->seid, ret);
  10793. goto err_vsi;
  10794. }
  10795. vsi->base_queue = ret;
  10796. /* Update the FW view of the VSI. Force a reset of TC and queue
  10797. * layout configurations.
  10798. */
  10799. enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  10800. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  10801. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  10802. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  10803. if (vsi->type == I40E_VSI_MAIN)
  10804. i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr);
  10805. /* assign it some queues */
  10806. ret = i40e_alloc_rings(vsi);
  10807. if (ret)
  10808. goto err_rings;
  10809. /* map all of the rings to the q_vectors */
  10810. i40e_vsi_map_rings_to_vectors(vsi);
  10811. return vsi;
  10812. err_rings:
  10813. i40e_vsi_free_q_vectors(vsi);
  10814. if (vsi->netdev_registered) {
  10815. vsi->netdev_registered = false;
  10816. unregister_netdev(vsi->netdev);
  10817. free_netdev(vsi->netdev);
  10818. vsi->netdev = NULL;
  10819. }
  10820. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  10821. err_vsi:
  10822. i40e_vsi_clear(vsi);
  10823. return NULL;
  10824. }
  10825. /**
  10826. * i40e_vsi_setup - Set up a VSI by a given type
  10827. * @pf: board private structure
  10828. * @type: VSI type
  10829. * @uplink_seid: the switch element to link to
  10830. * @param1: usage depends upon VSI type. For VF types, indicates VF id
  10831. *
  10832. * This allocates the sw VSI structure and its queue resources, then add a VSI
  10833. * to the identified VEB.
  10834. *
  10835. * Returns pointer to the successfully allocated and configure VSI sw struct on
  10836. * success, otherwise returns NULL on failure.
  10837. **/
  10838. struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
  10839. u16 uplink_seid, u32 param1)
  10840. {
  10841. struct i40e_vsi *vsi = NULL;
  10842. struct i40e_veb *veb = NULL;
  10843. u16 alloc_queue_pairs;
  10844. int ret, i;
  10845. int v_idx;
  10846. /* The requested uplink_seid must be either
  10847. * - the PF's port seid
  10848. * no VEB is needed because this is the PF
  10849. * or this is a Flow Director special case VSI
  10850. * - seid of an existing VEB
  10851. * - seid of a VSI that owns an existing VEB
  10852. * - seid of a VSI that doesn't own a VEB
  10853. * a new VEB is created and the VSI becomes the owner
  10854. * - seid of the PF VSI, which is what creates the first VEB
  10855. * this is a special case of the previous
  10856. *
  10857. * Find which uplink_seid we were given and create a new VEB if needed
  10858. */
  10859. for (i = 0; i < I40E_MAX_VEB; i++) {
  10860. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
  10861. veb = pf->veb[i];
  10862. break;
  10863. }
  10864. }
  10865. if (!veb && uplink_seid != pf->mac_seid) {
  10866. for (i = 0; i < pf->num_alloc_vsi; i++) {
  10867. if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
  10868. vsi = pf->vsi[i];
  10869. break;
  10870. }
  10871. }
  10872. if (!vsi) {
  10873. dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
  10874. uplink_seid);
  10875. return NULL;
  10876. }
  10877. if (vsi->uplink_seid == pf->mac_seid)
  10878. veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
  10879. vsi->tc_config.enabled_tc);
  10880. else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
  10881. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  10882. vsi->tc_config.enabled_tc);
  10883. if (veb) {
  10884. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
  10885. dev_info(&vsi->back->pdev->dev,
  10886. "New VSI creation error, uplink seid of LAN VSI expected.\n");
  10887. return NULL;
  10888. }
  10889. /* We come up by default in VEPA mode if SRIOV is not
  10890. * already enabled, in which case we can't force VEPA
  10891. * mode.
  10892. */
  10893. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  10894. veb->bridge_mode = BRIDGE_MODE_VEPA;
  10895. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  10896. }
  10897. i40e_config_bridge_mode(veb);
  10898. }
  10899. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  10900. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  10901. veb = pf->veb[i];
  10902. }
  10903. if (!veb) {
  10904. dev_info(&pf->pdev->dev, "couldn't add VEB\n");
  10905. return NULL;
  10906. }
  10907. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  10908. uplink_seid = veb->seid;
  10909. }
  10910. /* get vsi sw struct */
  10911. v_idx = i40e_vsi_mem_alloc(pf, type);
  10912. if (v_idx < 0)
  10913. goto err_alloc;
  10914. vsi = pf->vsi[v_idx];
  10915. if (!vsi)
  10916. goto err_alloc;
  10917. vsi->type = type;
  10918. vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
  10919. if (type == I40E_VSI_MAIN)
  10920. pf->lan_vsi = v_idx;
  10921. else if (type == I40E_VSI_SRIOV)
  10922. vsi->vf_id = param1;
  10923. /* assign it some queues */
  10924. alloc_queue_pairs = vsi->alloc_queue_pairs *
  10925. (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
  10926. ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
  10927. if (ret < 0) {
  10928. dev_info(&pf->pdev->dev,
  10929. "failed to get tracking for %d queues for VSI %d err=%d\n",
  10930. alloc_queue_pairs, vsi->seid, ret);
  10931. goto err_vsi;
  10932. }
  10933. vsi->base_queue = ret;
  10934. /* get a VSI from the hardware */
  10935. vsi->uplink_seid = uplink_seid;
  10936. ret = i40e_add_vsi(vsi);
  10937. if (ret)
  10938. goto err_vsi;
  10939. switch (vsi->type) {
  10940. /* setup the netdev if needed */
  10941. case I40E_VSI_MAIN:
  10942. case I40E_VSI_VMDQ2:
  10943. ret = i40e_config_netdev(vsi);
  10944. if (ret)
  10945. goto err_netdev;
  10946. ret = register_netdev(vsi->netdev);
  10947. if (ret)
  10948. goto err_netdev;
  10949. vsi->netdev_registered = true;
  10950. netif_carrier_off(vsi->netdev);
  10951. #ifdef CONFIG_I40E_DCB
  10952. /* Setup DCB netlink interface */
  10953. i40e_dcbnl_setup(vsi);
  10954. #endif /* CONFIG_I40E_DCB */
  10955. /* fall through */
  10956. case I40E_VSI_FDIR:
  10957. /* set up vectors and rings if needed */
  10958. ret = i40e_vsi_setup_vectors(vsi);
  10959. if (ret)
  10960. goto err_msix;
  10961. ret = i40e_alloc_rings(vsi);
  10962. if (ret)
  10963. goto err_rings;
  10964. /* map all of the rings to the q_vectors */
  10965. i40e_vsi_map_rings_to_vectors(vsi);
  10966. i40e_vsi_reset_stats(vsi);
  10967. break;
  10968. default:
  10969. /* no netdev or rings for the other VSI types */
  10970. break;
  10971. }
  10972. if ((pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) &&
  10973. (vsi->type == I40E_VSI_VMDQ2)) {
  10974. ret = i40e_vsi_config_rss(vsi);
  10975. }
  10976. return vsi;
  10977. err_rings:
  10978. i40e_vsi_free_q_vectors(vsi);
  10979. err_msix:
  10980. if (vsi->netdev_registered) {
  10981. vsi->netdev_registered = false;
  10982. unregister_netdev(vsi->netdev);
  10983. free_netdev(vsi->netdev);
  10984. vsi->netdev = NULL;
  10985. }
  10986. err_netdev:
  10987. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  10988. err_vsi:
  10989. i40e_vsi_clear(vsi);
  10990. err_alloc:
  10991. return NULL;
  10992. }
  10993. /**
  10994. * i40e_veb_get_bw_info - Query VEB BW information
  10995. * @veb: the veb to query
  10996. *
  10997. * Query the Tx scheduler BW configuration data for given VEB
  10998. **/
  10999. static int i40e_veb_get_bw_info(struct i40e_veb *veb)
  11000. {
  11001. struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
  11002. struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
  11003. struct i40e_pf *pf = veb->pf;
  11004. struct i40e_hw *hw = &pf->hw;
  11005. u32 tc_bw_max;
  11006. int ret = 0;
  11007. int i;
  11008. ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
  11009. &bw_data, NULL);
  11010. if (ret) {
  11011. dev_info(&pf->pdev->dev,
  11012. "query veb bw config failed, err %s aq_err %s\n",
  11013. i40e_stat_str(&pf->hw, ret),
  11014. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  11015. goto out;
  11016. }
  11017. ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
  11018. &ets_data, NULL);
  11019. if (ret) {
  11020. dev_info(&pf->pdev->dev,
  11021. "query veb bw ets config failed, err %s aq_err %s\n",
  11022. i40e_stat_str(&pf->hw, ret),
  11023. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  11024. goto out;
  11025. }
  11026. veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
  11027. veb->bw_max_quanta = ets_data.tc_bw_max;
  11028. veb->is_abs_credits = bw_data.absolute_credits_enable;
  11029. veb->enabled_tc = ets_data.tc_valid_bits;
  11030. tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
  11031. (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
  11032. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  11033. veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
  11034. veb->bw_tc_limit_credits[i] =
  11035. le16_to_cpu(bw_data.tc_bw_limits[i]);
  11036. veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
  11037. }
  11038. out:
  11039. return ret;
  11040. }
  11041. /**
  11042. * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
  11043. * @pf: board private structure
  11044. *
  11045. * On error: returns error code (negative)
  11046. * On success: returns vsi index in PF (positive)
  11047. **/
  11048. static int i40e_veb_mem_alloc(struct i40e_pf *pf)
  11049. {
  11050. int ret = -ENOENT;
  11051. struct i40e_veb *veb;
  11052. int i;
  11053. /* Need to protect the allocation of switch elements at the PF level */
  11054. mutex_lock(&pf->switch_mutex);
  11055. /* VEB list may be fragmented if VEB creation/destruction has
  11056. * been happening. We can afford to do a quick scan to look
  11057. * for any free slots in the list.
  11058. *
  11059. * find next empty veb slot, looping back around if necessary
  11060. */
  11061. i = 0;
  11062. while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
  11063. i++;
  11064. if (i >= I40E_MAX_VEB) {
  11065. ret = -ENOMEM;
  11066. goto err_alloc_veb; /* out of VEB slots! */
  11067. }
  11068. veb = kzalloc(sizeof(*veb), GFP_KERNEL);
  11069. if (!veb) {
  11070. ret = -ENOMEM;
  11071. goto err_alloc_veb;
  11072. }
  11073. veb->pf = pf;
  11074. veb->idx = i;
  11075. veb->enabled_tc = 1;
  11076. pf->veb[i] = veb;
  11077. ret = i;
  11078. err_alloc_veb:
  11079. mutex_unlock(&pf->switch_mutex);
  11080. return ret;
  11081. }
  11082. /**
  11083. * i40e_switch_branch_release - Delete a branch of the switch tree
  11084. * @branch: where to start deleting
  11085. *
  11086. * This uses recursion to find the tips of the branch to be
  11087. * removed, deleting until we get back to and can delete this VEB.
  11088. **/
  11089. static void i40e_switch_branch_release(struct i40e_veb *branch)
  11090. {
  11091. struct i40e_pf *pf = branch->pf;
  11092. u16 branch_seid = branch->seid;
  11093. u16 veb_idx = branch->idx;
  11094. int i;
  11095. /* release any VEBs on this VEB - RECURSION */
  11096. for (i = 0; i < I40E_MAX_VEB; i++) {
  11097. if (!pf->veb[i])
  11098. continue;
  11099. if (pf->veb[i]->uplink_seid == branch->seid)
  11100. i40e_switch_branch_release(pf->veb[i]);
  11101. }
  11102. /* Release the VSIs on this VEB, but not the owner VSI.
  11103. *
  11104. * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
  11105. * the VEB itself, so don't use (*branch) after this loop.
  11106. */
  11107. for (i = 0; i < pf->num_alloc_vsi; i++) {
  11108. if (!pf->vsi[i])
  11109. continue;
  11110. if (pf->vsi[i]->uplink_seid == branch_seid &&
  11111. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  11112. i40e_vsi_release(pf->vsi[i]);
  11113. }
  11114. }
  11115. /* There's one corner case where the VEB might not have been
  11116. * removed, so double check it here and remove it if needed.
  11117. * This case happens if the veb was created from the debugfs
  11118. * commands and no VSIs were added to it.
  11119. */
  11120. if (pf->veb[veb_idx])
  11121. i40e_veb_release(pf->veb[veb_idx]);
  11122. }
  11123. /**
  11124. * i40e_veb_clear - remove veb struct
  11125. * @veb: the veb to remove
  11126. **/
  11127. static void i40e_veb_clear(struct i40e_veb *veb)
  11128. {
  11129. if (!veb)
  11130. return;
  11131. if (veb->pf) {
  11132. struct i40e_pf *pf = veb->pf;
  11133. mutex_lock(&pf->switch_mutex);
  11134. if (pf->veb[veb->idx] == veb)
  11135. pf->veb[veb->idx] = NULL;
  11136. mutex_unlock(&pf->switch_mutex);
  11137. }
  11138. kfree(veb);
  11139. }
  11140. /**
  11141. * i40e_veb_release - Delete a VEB and free its resources
  11142. * @veb: the VEB being removed
  11143. **/
  11144. void i40e_veb_release(struct i40e_veb *veb)
  11145. {
  11146. struct i40e_vsi *vsi = NULL;
  11147. struct i40e_pf *pf;
  11148. int i, n = 0;
  11149. pf = veb->pf;
  11150. /* find the remaining VSI and check for extras */
  11151. for (i = 0; i < pf->num_alloc_vsi; i++) {
  11152. if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
  11153. n++;
  11154. vsi = pf->vsi[i];
  11155. }
  11156. }
  11157. if (n != 1) {
  11158. dev_info(&pf->pdev->dev,
  11159. "can't remove VEB %d with %d VSIs left\n",
  11160. veb->seid, n);
  11161. return;
  11162. }
  11163. /* move the remaining VSI to uplink veb */
  11164. vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
  11165. if (veb->uplink_seid) {
  11166. vsi->uplink_seid = veb->uplink_seid;
  11167. if (veb->uplink_seid == pf->mac_seid)
  11168. vsi->veb_idx = I40E_NO_VEB;
  11169. else
  11170. vsi->veb_idx = veb->veb_idx;
  11171. } else {
  11172. /* floating VEB */
  11173. vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  11174. vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
  11175. }
  11176. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  11177. i40e_veb_clear(veb);
  11178. }
  11179. /**
  11180. * i40e_add_veb - create the VEB in the switch
  11181. * @veb: the VEB to be instantiated
  11182. * @vsi: the controlling VSI
  11183. **/
  11184. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
  11185. {
  11186. struct i40e_pf *pf = veb->pf;
  11187. bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
  11188. int ret;
  11189. ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
  11190. veb->enabled_tc, false,
  11191. &veb->seid, enable_stats, NULL);
  11192. /* get a VEB from the hardware */
  11193. if (ret) {
  11194. dev_info(&pf->pdev->dev,
  11195. "couldn't add VEB, err %s aq_err %s\n",
  11196. i40e_stat_str(&pf->hw, ret),
  11197. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11198. return -EPERM;
  11199. }
  11200. /* get statistics counter */
  11201. ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
  11202. &veb->stats_idx, NULL, NULL, NULL);
  11203. if (ret) {
  11204. dev_info(&pf->pdev->dev,
  11205. "couldn't get VEB statistics idx, err %s aq_err %s\n",
  11206. i40e_stat_str(&pf->hw, ret),
  11207. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11208. return -EPERM;
  11209. }
  11210. ret = i40e_veb_get_bw_info(veb);
  11211. if (ret) {
  11212. dev_info(&pf->pdev->dev,
  11213. "couldn't get VEB bw info, err %s aq_err %s\n",
  11214. i40e_stat_str(&pf->hw, ret),
  11215. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11216. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  11217. return -ENOENT;
  11218. }
  11219. vsi->uplink_seid = veb->seid;
  11220. vsi->veb_idx = veb->idx;
  11221. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  11222. return 0;
  11223. }
  11224. /**
  11225. * i40e_veb_setup - Set up a VEB
  11226. * @pf: board private structure
  11227. * @flags: VEB setup flags
  11228. * @uplink_seid: the switch element to link to
  11229. * @vsi_seid: the initial VSI seid
  11230. * @enabled_tc: Enabled TC bit-map
  11231. *
  11232. * This allocates the sw VEB structure and links it into the switch
  11233. * It is possible and legal for this to be a duplicate of an already
  11234. * existing VEB. It is also possible for both uplink and vsi seids
  11235. * to be zero, in order to create a floating VEB.
  11236. *
  11237. * Returns pointer to the successfully allocated VEB sw struct on
  11238. * success, otherwise returns NULL on failure.
  11239. **/
  11240. struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
  11241. u16 uplink_seid, u16 vsi_seid,
  11242. u8 enabled_tc)
  11243. {
  11244. struct i40e_veb *veb, *uplink_veb = NULL;
  11245. int vsi_idx, veb_idx;
  11246. int ret;
  11247. /* if one seid is 0, the other must be 0 to create a floating relay */
  11248. if ((uplink_seid == 0 || vsi_seid == 0) &&
  11249. (uplink_seid + vsi_seid != 0)) {
  11250. dev_info(&pf->pdev->dev,
  11251. "one, not both seid's are 0: uplink=%d vsi=%d\n",
  11252. uplink_seid, vsi_seid);
  11253. return NULL;
  11254. }
  11255. /* make sure there is such a vsi and uplink */
  11256. for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
  11257. if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
  11258. break;
  11259. if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
  11260. dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
  11261. vsi_seid);
  11262. return NULL;
  11263. }
  11264. if (uplink_seid && uplink_seid != pf->mac_seid) {
  11265. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  11266. if (pf->veb[veb_idx] &&
  11267. pf->veb[veb_idx]->seid == uplink_seid) {
  11268. uplink_veb = pf->veb[veb_idx];
  11269. break;
  11270. }
  11271. }
  11272. if (!uplink_veb) {
  11273. dev_info(&pf->pdev->dev,
  11274. "uplink seid %d not found\n", uplink_seid);
  11275. return NULL;
  11276. }
  11277. }
  11278. /* get veb sw struct */
  11279. veb_idx = i40e_veb_mem_alloc(pf);
  11280. if (veb_idx < 0)
  11281. goto err_alloc;
  11282. veb = pf->veb[veb_idx];
  11283. veb->flags = flags;
  11284. veb->uplink_seid = uplink_seid;
  11285. veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
  11286. veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
  11287. /* create the VEB in the switch */
  11288. ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
  11289. if (ret)
  11290. goto err_veb;
  11291. if (vsi_idx == pf->lan_vsi)
  11292. pf->lan_veb = veb->idx;
  11293. return veb;
  11294. err_veb:
  11295. i40e_veb_clear(veb);
  11296. err_alloc:
  11297. return NULL;
  11298. }
  11299. /**
  11300. * i40e_setup_pf_switch_element - set PF vars based on switch type
  11301. * @pf: board private structure
  11302. * @ele: element we are building info from
  11303. * @num_reported: total number of elements
  11304. * @printconfig: should we print the contents
  11305. *
  11306. * helper function to assist in extracting a few useful SEID values.
  11307. **/
  11308. static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
  11309. struct i40e_aqc_switch_config_element_resp *ele,
  11310. u16 num_reported, bool printconfig)
  11311. {
  11312. u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
  11313. u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
  11314. u8 element_type = ele->element_type;
  11315. u16 seid = le16_to_cpu(ele->seid);
  11316. if (printconfig)
  11317. dev_info(&pf->pdev->dev,
  11318. "type=%d seid=%d uplink=%d downlink=%d\n",
  11319. element_type, seid, uplink_seid, downlink_seid);
  11320. switch (element_type) {
  11321. case I40E_SWITCH_ELEMENT_TYPE_MAC:
  11322. pf->mac_seid = seid;
  11323. break;
  11324. case I40E_SWITCH_ELEMENT_TYPE_VEB:
  11325. /* Main VEB? */
  11326. if (uplink_seid != pf->mac_seid)
  11327. break;
  11328. if (pf->lan_veb == I40E_NO_VEB) {
  11329. int v;
  11330. /* find existing or else empty VEB */
  11331. for (v = 0; v < I40E_MAX_VEB; v++) {
  11332. if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
  11333. pf->lan_veb = v;
  11334. break;
  11335. }
  11336. }
  11337. if (pf->lan_veb == I40E_NO_VEB) {
  11338. v = i40e_veb_mem_alloc(pf);
  11339. if (v < 0)
  11340. break;
  11341. pf->lan_veb = v;
  11342. }
  11343. }
  11344. pf->veb[pf->lan_veb]->seid = seid;
  11345. pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
  11346. pf->veb[pf->lan_veb]->pf = pf;
  11347. pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
  11348. break;
  11349. case I40E_SWITCH_ELEMENT_TYPE_VSI:
  11350. if (num_reported != 1)
  11351. break;
  11352. /* This is immediately after a reset so we can assume this is
  11353. * the PF's VSI
  11354. */
  11355. pf->mac_seid = uplink_seid;
  11356. pf->pf_seid = downlink_seid;
  11357. pf->main_vsi_seid = seid;
  11358. if (printconfig)
  11359. dev_info(&pf->pdev->dev,
  11360. "pf_seid=%d main_vsi_seid=%d\n",
  11361. pf->pf_seid, pf->main_vsi_seid);
  11362. break;
  11363. case I40E_SWITCH_ELEMENT_TYPE_PF:
  11364. case I40E_SWITCH_ELEMENT_TYPE_VF:
  11365. case I40E_SWITCH_ELEMENT_TYPE_EMP:
  11366. case I40E_SWITCH_ELEMENT_TYPE_BMC:
  11367. case I40E_SWITCH_ELEMENT_TYPE_PE:
  11368. case I40E_SWITCH_ELEMENT_TYPE_PA:
  11369. /* ignore these for now */
  11370. break;
  11371. default:
  11372. dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
  11373. element_type, seid);
  11374. break;
  11375. }
  11376. }
  11377. /**
  11378. * i40e_fetch_switch_configuration - Get switch config from firmware
  11379. * @pf: board private structure
  11380. * @printconfig: should we print the contents
  11381. *
  11382. * Get the current switch configuration from the device and
  11383. * extract a few useful SEID values.
  11384. **/
  11385. int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
  11386. {
  11387. struct i40e_aqc_get_switch_config_resp *sw_config;
  11388. u16 next_seid = 0;
  11389. int ret = 0;
  11390. u8 *aq_buf;
  11391. int i;
  11392. aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
  11393. if (!aq_buf)
  11394. return -ENOMEM;
  11395. sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
  11396. do {
  11397. u16 num_reported, num_total;
  11398. ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
  11399. I40E_AQ_LARGE_BUF,
  11400. &next_seid, NULL);
  11401. if (ret) {
  11402. dev_info(&pf->pdev->dev,
  11403. "get switch config failed err %s aq_err %s\n",
  11404. i40e_stat_str(&pf->hw, ret),
  11405. i40e_aq_str(&pf->hw,
  11406. pf->hw.aq.asq_last_status));
  11407. kfree(aq_buf);
  11408. return -ENOENT;
  11409. }
  11410. num_reported = le16_to_cpu(sw_config->header.num_reported);
  11411. num_total = le16_to_cpu(sw_config->header.num_total);
  11412. if (printconfig)
  11413. dev_info(&pf->pdev->dev,
  11414. "header: %d reported %d total\n",
  11415. num_reported, num_total);
  11416. for (i = 0; i < num_reported; i++) {
  11417. struct i40e_aqc_switch_config_element_resp *ele =
  11418. &sw_config->element[i];
  11419. i40e_setup_pf_switch_element(pf, ele, num_reported,
  11420. printconfig);
  11421. }
  11422. } while (next_seid != 0);
  11423. kfree(aq_buf);
  11424. return ret;
  11425. }
  11426. /**
  11427. * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
  11428. * @pf: board private structure
  11429. * @reinit: if the Main VSI needs to re-initialized.
  11430. *
  11431. * Returns 0 on success, negative value on failure
  11432. **/
  11433. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
  11434. {
  11435. u16 flags = 0;
  11436. int ret;
  11437. /* find out what's out there already */
  11438. ret = i40e_fetch_switch_configuration(pf, false);
  11439. if (ret) {
  11440. dev_info(&pf->pdev->dev,
  11441. "couldn't fetch switch config, err %s aq_err %s\n",
  11442. i40e_stat_str(&pf->hw, ret),
  11443. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11444. return ret;
  11445. }
  11446. i40e_pf_reset_stats(pf);
  11447. /* set the switch config bit for the whole device to
  11448. * support limited promisc or true promisc
  11449. * when user requests promisc. The default is limited
  11450. * promisc.
  11451. */
  11452. if ((pf->hw.pf_id == 0) &&
  11453. !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
  11454. flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  11455. pf->last_sw_conf_flags = flags;
  11456. }
  11457. if (pf->hw.pf_id == 0) {
  11458. u16 valid_flags;
  11459. valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  11460. ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, 0,
  11461. NULL);
  11462. if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
  11463. dev_info(&pf->pdev->dev,
  11464. "couldn't set switch config bits, err %s aq_err %s\n",
  11465. i40e_stat_str(&pf->hw, ret),
  11466. i40e_aq_str(&pf->hw,
  11467. pf->hw.aq.asq_last_status));
  11468. /* not a fatal problem, just keep going */
  11469. }
  11470. pf->last_sw_conf_valid_flags = valid_flags;
  11471. }
  11472. /* first time setup */
  11473. if (pf->lan_vsi == I40E_NO_VSI || reinit) {
  11474. struct i40e_vsi *vsi = NULL;
  11475. u16 uplink_seid;
  11476. /* Set up the PF VSI associated with the PF's main VSI
  11477. * that is already in the HW switch
  11478. */
  11479. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  11480. uplink_seid = pf->veb[pf->lan_veb]->seid;
  11481. else
  11482. uplink_seid = pf->mac_seid;
  11483. if (pf->lan_vsi == I40E_NO_VSI)
  11484. vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
  11485. else if (reinit)
  11486. vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
  11487. if (!vsi) {
  11488. dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
  11489. i40e_cloud_filter_exit(pf);
  11490. i40e_fdir_teardown(pf);
  11491. return -EAGAIN;
  11492. }
  11493. } else {
  11494. /* force a reset of TC and queue layout configurations */
  11495. u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  11496. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  11497. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  11498. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  11499. }
  11500. i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
  11501. i40e_fdir_sb_setup(pf);
  11502. /* Setup static PF queue filter control settings */
  11503. ret = i40e_setup_pf_filter_control(pf);
  11504. if (ret) {
  11505. dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
  11506. ret);
  11507. /* Failure here should not stop continuing other steps */
  11508. }
  11509. /* enable RSS in the HW, even for only one queue, as the stack can use
  11510. * the hash
  11511. */
  11512. if ((pf->flags & I40E_FLAG_RSS_ENABLED))
  11513. i40e_pf_config_rss(pf);
  11514. /* fill in link information and enable LSE reporting */
  11515. i40e_link_event(pf);
  11516. /* Initialize user-specific link properties */
  11517. pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
  11518. I40E_AQ_AN_COMPLETED) ? true : false);
  11519. i40e_ptp_init(pf);
  11520. /* repopulate tunnel port filters */
  11521. i40e_sync_udp_filters(pf);
  11522. return ret;
  11523. }
  11524. /**
  11525. * i40e_determine_queue_usage - Work out queue distribution
  11526. * @pf: board private structure
  11527. **/
  11528. static void i40e_determine_queue_usage(struct i40e_pf *pf)
  11529. {
  11530. int queues_left;
  11531. int q_max;
  11532. pf->num_lan_qps = 0;
  11533. /* Find the max queues to be put into basic use. We'll always be
  11534. * using TC0, whether or not DCB is running, and TC0 will get the
  11535. * big RSS set.
  11536. */
  11537. queues_left = pf->hw.func_caps.num_tx_qp;
  11538. if ((queues_left == 1) ||
  11539. !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  11540. /* one qp for PF, no queues for anything else */
  11541. queues_left = 0;
  11542. pf->alloc_rss_size = pf->num_lan_qps = 1;
  11543. /* make sure all the fancies are disabled */
  11544. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  11545. I40E_FLAG_IWARP_ENABLED |
  11546. I40E_FLAG_FD_SB_ENABLED |
  11547. I40E_FLAG_FD_ATR_ENABLED |
  11548. I40E_FLAG_DCB_CAPABLE |
  11549. I40E_FLAG_DCB_ENABLED |
  11550. I40E_FLAG_SRIOV_ENABLED |
  11551. I40E_FLAG_VMDQ_ENABLED);
  11552. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  11553. } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
  11554. I40E_FLAG_FD_SB_ENABLED |
  11555. I40E_FLAG_FD_ATR_ENABLED |
  11556. I40E_FLAG_DCB_CAPABLE))) {
  11557. /* one qp for PF */
  11558. pf->alloc_rss_size = pf->num_lan_qps = 1;
  11559. queues_left -= pf->num_lan_qps;
  11560. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  11561. I40E_FLAG_IWARP_ENABLED |
  11562. I40E_FLAG_FD_SB_ENABLED |
  11563. I40E_FLAG_FD_ATR_ENABLED |
  11564. I40E_FLAG_DCB_ENABLED |
  11565. I40E_FLAG_VMDQ_ENABLED);
  11566. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  11567. } else {
  11568. /* Not enough queues for all TCs */
  11569. if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
  11570. (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
  11571. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
  11572. I40E_FLAG_DCB_ENABLED);
  11573. dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
  11574. }
  11575. /* limit lan qps to the smaller of qps, cpus or msix */
  11576. q_max = max_t(int, pf->rss_size_max, num_online_cpus());
  11577. q_max = min_t(int, q_max, pf->hw.func_caps.num_tx_qp);
  11578. q_max = min_t(int, q_max, pf->hw.func_caps.num_msix_vectors);
  11579. pf->num_lan_qps = q_max;
  11580. queues_left -= pf->num_lan_qps;
  11581. }
  11582. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  11583. if (queues_left > 1) {
  11584. queues_left -= 1; /* save 1 queue for FD */
  11585. } else {
  11586. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  11587. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  11588. dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
  11589. }
  11590. }
  11591. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  11592. pf->num_vf_qps && pf->num_req_vfs && queues_left) {
  11593. pf->num_req_vfs = min_t(int, pf->num_req_vfs,
  11594. (queues_left / pf->num_vf_qps));
  11595. queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
  11596. }
  11597. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  11598. pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
  11599. pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
  11600. (queues_left / pf->num_vmdq_qps));
  11601. queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
  11602. }
  11603. pf->queues_left = queues_left;
  11604. dev_dbg(&pf->pdev->dev,
  11605. "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
  11606. pf->hw.func_caps.num_tx_qp,
  11607. !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
  11608. pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
  11609. pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
  11610. queues_left);
  11611. }
  11612. /**
  11613. * i40e_setup_pf_filter_control - Setup PF static filter control
  11614. * @pf: PF to be setup
  11615. *
  11616. * i40e_setup_pf_filter_control sets up a PF's initial filter control
  11617. * settings. If PE/FCoE are enabled then it will also set the per PF
  11618. * based filter sizes required for them. It also enables Flow director,
  11619. * ethertype and macvlan type filter settings for the pf.
  11620. *
  11621. * Returns 0 on success, negative on failure
  11622. **/
  11623. static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
  11624. {
  11625. struct i40e_filter_control_settings *settings = &pf->filter_settings;
  11626. settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
  11627. /* Flow Director is enabled */
  11628. if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
  11629. settings->enable_fdir = true;
  11630. /* Ethtype and MACVLAN filters enabled for PF */
  11631. settings->enable_ethtype = true;
  11632. settings->enable_macvlan = true;
  11633. if (i40e_set_filter_control(&pf->hw, settings))
  11634. return -ENOENT;
  11635. return 0;
  11636. }
  11637. #define INFO_STRING_LEN 255
  11638. #define REMAIN(__x) (INFO_STRING_LEN - (__x))
  11639. static void i40e_print_features(struct i40e_pf *pf)
  11640. {
  11641. struct i40e_hw *hw = &pf->hw;
  11642. char *buf;
  11643. int i;
  11644. buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
  11645. if (!buf)
  11646. return;
  11647. i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
  11648. #ifdef CONFIG_PCI_IOV
  11649. i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
  11650. #endif
  11651. i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d",
  11652. pf->hw.func_caps.num_vsis,
  11653. pf->vsi[pf->lan_vsi]->num_queue_pairs);
  11654. if (pf->flags & I40E_FLAG_RSS_ENABLED)
  11655. i += snprintf(&buf[i], REMAIN(i), " RSS");
  11656. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
  11657. i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
  11658. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  11659. i += snprintf(&buf[i], REMAIN(i), " FD_SB");
  11660. i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
  11661. }
  11662. if (pf->flags & I40E_FLAG_DCB_CAPABLE)
  11663. i += snprintf(&buf[i], REMAIN(i), " DCB");
  11664. i += snprintf(&buf[i], REMAIN(i), " VxLAN");
  11665. i += snprintf(&buf[i], REMAIN(i), " Geneve");
  11666. if (pf->flags & I40E_FLAG_PTP)
  11667. i += snprintf(&buf[i], REMAIN(i), " PTP");
  11668. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  11669. i += snprintf(&buf[i], REMAIN(i), " VEB");
  11670. else
  11671. i += snprintf(&buf[i], REMAIN(i), " VEPA");
  11672. dev_info(&pf->pdev->dev, "%s\n", buf);
  11673. kfree(buf);
  11674. WARN_ON(i > INFO_STRING_LEN);
  11675. }
  11676. /**
  11677. * i40e_get_platform_mac_addr - get platform-specific MAC address
  11678. * @pdev: PCI device information struct
  11679. * @pf: board private structure
  11680. *
  11681. * Look up the MAC address for the device. First we'll try
  11682. * eth_platform_get_mac_address, which will check Open Firmware, or arch
  11683. * specific fallback. Otherwise, we'll default to the stored value in
  11684. * firmware.
  11685. **/
  11686. static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
  11687. {
  11688. if (eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
  11689. i40e_get_mac_addr(&pf->hw, pf->hw.mac.addr);
  11690. }
  11691. /**
  11692. * i40e_probe - Device initialization routine
  11693. * @pdev: PCI device information struct
  11694. * @ent: entry in i40e_pci_tbl
  11695. *
  11696. * i40e_probe initializes a PF identified by a pci_dev structure.
  11697. * The OS initialization, configuring of the PF private structure,
  11698. * and a hardware reset occur.
  11699. *
  11700. * Returns 0 on success, negative on failure
  11701. **/
  11702. static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  11703. {
  11704. struct i40e_aq_get_phy_abilities_resp abilities;
  11705. struct i40e_pf *pf;
  11706. struct i40e_hw *hw;
  11707. static u16 pfs_found;
  11708. u16 wol_nvm_bits;
  11709. u16 link_status;
  11710. int err;
  11711. u32 val;
  11712. u32 i;
  11713. u8 set_fc_aq_fail;
  11714. err = pci_enable_device_mem(pdev);
  11715. if (err)
  11716. return err;
  11717. /* set up for high or low dma */
  11718. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  11719. if (err) {
  11720. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  11721. if (err) {
  11722. dev_err(&pdev->dev,
  11723. "DMA configuration failed: 0x%x\n", err);
  11724. goto err_dma;
  11725. }
  11726. }
  11727. /* set up pci connections */
  11728. err = pci_request_mem_regions(pdev, i40e_driver_name);
  11729. if (err) {
  11730. dev_info(&pdev->dev,
  11731. "pci_request_selected_regions failed %d\n", err);
  11732. goto err_pci_reg;
  11733. }
  11734. pci_enable_pcie_error_reporting(pdev);
  11735. pci_set_master(pdev);
  11736. /* Now that we have a PCI connection, we need to do the
  11737. * low level device setup. This is primarily setting up
  11738. * the Admin Queue structures and then querying for the
  11739. * device's current profile information.
  11740. */
  11741. pf = kzalloc(sizeof(*pf), GFP_KERNEL);
  11742. if (!pf) {
  11743. err = -ENOMEM;
  11744. goto err_pf_alloc;
  11745. }
  11746. pf->next_vsi = 0;
  11747. pf->pdev = pdev;
  11748. set_bit(__I40E_DOWN, pf->state);
  11749. hw = &pf->hw;
  11750. hw->back = pf;
  11751. pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
  11752. I40E_MAX_CSR_SPACE);
  11753. hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
  11754. if (!hw->hw_addr) {
  11755. err = -EIO;
  11756. dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
  11757. (unsigned int)pci_resource_start(pdev, 0),
  11758. pf->ioremap_len, err);
  11759. goto err_ioremap;
  11760. }
  11761. hw->vendor_id = pdev->vendor;
  11762. hw->device_id = pdev->device;
  11763. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  11764. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  11765. hw->subsystem_device_id = pdev->subsystem_device;
  11766. hw->bus.device = PCI_SLOT(pdev->devfn);
  11767. hw->bus.func = PCI_FUNC(pdev->devfn);
  11768. hw->bus.bus_id = pdev->bus->number;
  11769. pf->instance = pfs_found;
  11770. /* Select something other than the 802.1ad ethertype for the
  11771. * switch to use internally and drop on ingress.
  11772. */
  11773. hw->switch_tag = 0xffff;
  11774. hw->first_tag = ETH_P_8021AD;
  11775. hw->second_tag = ETH_P_8021Q;
  11776. INIT_LIST_HEAD(&pf->l3_flex_pit_list);
  11777. INIT_LIST_HEAD(&pf->l4_flex_pit_list);
  11778. /* set up the locks for the AQ, do this only once in probe
  11779. * and destroy them only once in remove
  11780. */
  11781. mutex_init(&hw->aq.asq_mutex);
  11782. mutex_init(&hw->aq.arq_mutex);
  11783. pf->msg_enable = netif_msg_init(debug,
  11784. NETIF_MSG_DRV |
  11785. NETIF_MSG_PROBE |
  11786. NETIF_MSG_LINK);
  11787. if (debug < -1)
  11788. pf->hw.debug_mask = debug;
  11789. /* do a special CORER for clearing PXE mode once at init */
  11790. if (hw->revision_id == 0 &&
  11791. (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
  11792. wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
  11793. i40e_flush(hw);
  11794. msleep(200);
  11795. pf->corer_count++;
  11796. i40e_clear_pxe_mode(hw);
  11797. }
  11798. /* Reset here to make sure all is clean and to define PF 'n' */
  11799. i40e_clear_hw(hw);
  11800. err = i40e_pf_reset(hw);
  11801. if (err) {
  11802. dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
  11803. goto err_pf_reset;
  11804. }
  11805. pf->pfr_count++;
  11806. hw->aq.num_arq_entries = I40E_AQ_LEN;
  11807. hw->aq.num_asq_entries = I40E_AQ_LEN;
  11808. hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  11809. hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  11810. pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
  11811. snprintf(pf->int_name, sizeof(pf->int_name) - 1,
  11812. "%s-%s:misc",
  11813. dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
  11814. err = i40e_init_shared_code(hw);
  11815. if (err) {
  11816. dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
  11817. err);
  11818. goto err_pf_reset;
  11819. }
  11820. /* set up a default setting for link flow control */
  11821. pf->hw.fc.requested_mode = I40E_FC_NONE;
  11822. err = i40e_init_adminq(hw);
  11823. if (err) {
  11824. if (err == I40E_ERR_FIRMWARE_API_VERSION)
  11825. dev_info(&pdev->dev,
  11826. "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");
  11827. else
  11828. dev_info(&pdev->dev,
  11829. "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
  11830. goto err_pf_reset;
  11831. }
  11832. i40e_get_oem_version(hw);
  11833. /* provide nvm, fw, api versions */
  11834. dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
  11835. hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
  11836. hw->aq.api_maj_ver, hw->aq.api_min_ver,
  11837. i40e_nvm_version_str(hw));
  11838. if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
  11839. hw->aq.api_min_ver > I40E_FW_MINOR_VERSION(hw))
  11840. dev_info(&pdev->dev,
  11841. "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");
  11842. else if (hw->aq.api_maj_ver == 1 && hw->aq.api_min_ver < 4)
  11843. dev_info(&pdev->dev,
  11844. "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
  11845. i40e_verify_eeprom(pf);
  11846. /* Rev 0 hardware was never productized */
  11847. if (hw->revision_id < 1)
  11848. 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");
  11849. i40e_clear_pxe_mode(hw);
  11850. err = i40e_get_capabilities(pf, i40e_aqc_opc_list_func_capabilities);
  11851. if (err)
  11852. goto err_adminq_setup;
  11853. err = i40e_sw_init(pf);
  11854. if (err) {
  11855. dev_info(&pdev->dev, "sw_init failed: %d\n", err);
  11856. goto err_sw_init;
  11857. }
  11858. err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  11859. hw->func_caps.num_rx_qp, 0, 0);
  11860. if (err) {
  11861. dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
  11862. goto err_init_lan_hmc;
  11863. }
  11864. err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  11865. if (err) {
  11866. dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
  11867. err = -ENOENT;
  11868. goto err_configure_lan_hmc;
  11869. }
  11870. /* Disable LLDP for NICs that have firmware versions lower than v4.3.
  11871. * Ignore error return codes because if it was already disabled via
  11872. * hardware settings this will fail
  11873. */
  11874. if (pf->hw_features & I40E_HW_STOP_FW_LLDP) {
  11875. dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
  11876. i40e_aq_stop_lldp(hw, true, NULL);
  11877. }
  11878. /* allow a platform config to override the HW addr */
  11879. i40e_get_platform_mac_addr(pdev, pf);
  11880. if (!is_valid_ether_addr(hw->mac.addr)) {
  11881. dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
  11882. err = -EIO;
  11883. goto err_mac_addr;
  11884. }
  11885. dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
  11886. ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
  11887. i40e_get_port_mac_addr(hw, hw->mac.port_addr);
  11888. if (is_valid_ether_addr(hw->mac.port_addr))
  11889. pf->hw_features |= I40E_HW_PORT_ID_VALID;
  11890. pci_set_drvdata(pdev, pf);
  11891. pci_save_state(pdev);
  11892. #ifdef CONFIG_I40E_DCB
  11893. err = i40e_init_pf_dcb(pf);
  11894. if (err) {
  11895. dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
  11896. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED);
  11897. /* Continue without DCB enabled */
  11898. }
  11899. #endif /* CONFIG_I40E_DCB */
  11900. /* set up periodic task facility */
  11901. timer_setup(&pf->service_timer, i40e_service_timer, 0);
  11902. pf->service_timer_period = HZ;
  11903. INIT_WORK(&pf->service_task, i40e_service_task);
  11904. clear_bit(__I40E_SERVICE_SCHED, pf->state);
  11905. /* NVM bit on means WoL disabled for the port */
  11906. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  11907. if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
  11908. pf->wol_en = false;
  11909. else
  11910. pf->wol_en = true;
  11911. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  11912. /* set up the main switch operations */
  11913. i40e_determine_queue_usage(pf);
  11914. err = i40e_init_interrupt_scheme(pf);
  11915. if (err)
  11916. goto err_switch_setup;
  11917. /* The number of VSIs reported by the FW is the minimum guaranteed
  11918. * to us; HW supports far more and we share the remaining pool with
  11919. * the other PFs. We allocate space for more than the guarantee with
  11920. * the understanding that we might not get them all later.
  11921. */
  11922. if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
  11923. pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
  11924. else
  11925. pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
  11926. /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
  11927. pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
  11928. GFP_KERNEL);
  11929. if (!pf->vsi) {
  11930. err = -ENOMEM;
  11931. goto err_switch_setup;
  11932. }
  11933. #ifdef CONFIG_PCI_IOV
  11934. /* prep for VF support */
  11935. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  11936. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  11937. !test_bit(__I40E_BAD_EEPROM, pf->state)) {
  11938. if (pci_num_vf(pdev))
  11939. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  11940. }
  11941. #endif
  11942. err = i40e_setup_pf_switch(pf, false);
  11943. if (err) {
  11944. dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
  11945. goto err_vsis;
  11946. }
  11947. INIT_LIST_HEAD(&pf->vsi[pf->lan_vsi]->ch_list);
  11948. /* Make sure flow control is set according to current settings */
  11949. err = i40e_set_fc(hw, &set_fc_aq_fail, true);
  11950. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
  11951. dev_dbg(&pf->pdev->dev,
  11952. "Set fc with err %s aq_err %s on get_phy_cap\n",
  11953. i40e_stat_str(hw, err),
  11954. i40e_aq_str(hw, hw->aq.asq_last_status));
  11955. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
  11956. dev_dbg(&pf->pdev->dev,
  11957. "Set fc with err %s aq_err %s on set_phy_config\n",
  11958. i40e_stat_str(hw, err),
  11959. i40e_aq_str(hw, hw->aq.asq_last_status));
  11960. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
  11961. dev_dbg(&pf->pdev->dev,
  11962. "Set fc with err %s aq_err %s on get_link_info\n",
  11963. i40e_stat_str(hw, err),
  11964. i40e_aq_str(hw, hw->aq.asq_last_status));
  11965. /* if FDIR VSI was set up, start it now */
  11966. for (i = 0; i < pf->num_alloc_vsi; i++) {
  11967. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  11968. i40e_vsi_open(pf->vsi[i]);
  11969. break;
  11970. }
  11971. }
  11972. /* The driver only wants link up/down and module qualification
  11973. * reports from firmware. Note the negative logic.
  11974. */
  11975. err = i40e_aq_set_phy_int_mask(&pf->hw,
  11976. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  11977. I40E_AQ_EVENT_MEDIA_NA |
  11978. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  11979. if (err)
  11980. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  11981. i40e_stat_str(&pf->hw, err),
  11982. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11983. /* Reconfigure hardware for allowing smaller MSS in the case
  11984. * of TSO, so that we avoid the MDD being fired and causing
  11985. * a reset in the case of small MSS+TSO.
  11986. */
  11987. val = rd32(hw, I40E_REG_MSS);
  11988. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  11989. val &= ~I40E_REG_MSS_MIN_MASK;
  11990. val |= I40E_64BYTE_MSS;
  11991. wr32(hw, I40E_REG_MSS, val);
  11992. }
  11993. if (pf->hw_features & I40E_HW_RESTART_AUTONEG) {
  11994. msleep(75);
  11995. err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  11996. if (err)
  11997. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  11998. i40e_stat_str(&pf->hw, err),
  11999. i40e_aq_str(&pf->hw,
  12000. pf->hw.aq.asq_last_status));
  12001. }
  12002. /* The main driver is (mostly) up and happy. We need to set this state
  12003. * before setting up the misc vector or we get a race and the vector
  12004. * ends up disabled forever.
  12005. */
  12006. clear_bit(__I40E_DOWN, pf->state);
  12007. /* In case of MSIX we are going to setup the misc vector right here
  12008. * to handle admin queue events etc. In case of legacy and MSI
  12009. * the misc functionality and queue processing is combined in
  12010. * the same vector and that gets setup at open.
  12011. */
  12012. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  12013. err = i40e_setup_misc_vector(pf);
  12014. if (err) {
  12015. dev_info(&pdev->dev,
  12016. "setup of misc vector failed: %d\n", err);
  12017. goto err_vsis;
  12018. }
  12019. }
  12020. #ifdef CONFIG_PCI_IOV
  12021. /* prep for VF support */
  12022. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  12023. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  12024. !test_bit(__I40E_BAD_EEPROM, pf->state)) {
  12025. /* disable link interrupts for VFs */
  12026. val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
  12027. val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
  12028. wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
  12029. i40e_flush(hw);
  12030. if (pci_num_vf(pdev)) {
  12031. dev_info(&pdev->dev,
  12032. "Active VFs found, allocating resources.\n");
  12033. err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
  12034. if (err)
  12035. dev_info(&pdev->dev,
  12036. "Error %d allocating resources for existing VFs\n",
  12037. err);
  12038. }
  12039. }
  12040. #endif /* CONFIG_PCI_IOV */
  12041. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  12042. pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
  12043. pf->num_iwarp_msix,
  12044. I40E_IWARP_IRQ_PILE_ID);
  12045. if (pf->iwarp_base_vector < 0) {
  12046. dev_info(&pdev->dev,
  12047. "failed to get tracking for %d vectors for IWARP err=%d\n",
  12048. pf->num_iwarp_msix, pf->iwarp_base_vector);
  12049. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  12050. }
  12051. }
  12052. i40e_dbg_pf_init(pf);
  12053. /* tell the firmware that we're starting */
  12054. i40e_send_version(pf);
  12055. /* since everything's happy, start the service_task timer */
  12056. mod_timer(&pf->service_timer,
  12057. round_jiffies(jiffies + pf->service_timer_period));
  12058. /* add this PF to client device list and launch a client service task */
  12059. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  12060. err = i40e_lan_add_device(pf);
  12061. if (err)
  12062. dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
  12063. err);
  12064. }
  12065. #define PCI_SPEED_SIZE 8
  12066. #define PCI_WIDTH_SIZE 8
  12067. /* Devices on the IOSF bus do not have this information
  12068. * and will report PCI Gen 1 x 1 by default so don't bother
  12069. * checking them.
  12070. */
  12071. if (!(pf->hw_features & I40E_HW_NO_PCI_LINK_CHECK)) {
  12072. char speed[PCI_SPEED_SIZE] = "Unknown";
  12073. char width[PCI_WIDTH_SIZE] = "Unknown";
  12074. /* Get the negotiated link width and speed from PCI config
  12075. * space
  12076. */
  12077. pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
  12078. &link_status);
  12079. i40e_set_pci_config_data(hw, link_status);
  12080. switch (hw->bus.speed) {
  12081. case i40e_bus_speed_8000:
  12082. strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
  12083. case i40e_bus_speed_5000:
  12084. strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
  12085. case i40e_bus_speed_2500:
  12086. strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
  12087. default:
  12088. break;
  12089. }
  12090. switch (hw->bus.width) {
  12091. case i40e_bus_width_pcie_x8:
  12092. strncpy(width, "8", PCI_WIDTH_SIZE); break;
  12093. case i40e_bus_width_pcie_x4:
  12094. strncpy(width, "4", PCI_WIDTH_SIZE); break;
  12095. case i40e_bus_width_pcie_x2:
  12096. strncpy(width, "2", PCI_WIDTH_SIZE); break;
  12097. case i40e_bus_width_pcie_x1:
  12098. strncpy(width, "1", PCI_WIDTH_SIZE); break;
  12099. default:
  12100. break;
  12101. }
  12102. dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
  12103. speed, width);
  12104. if (hw->bus.width < i40e_bus_width_pcie_x8 ||
  12105. hw->bus.speed < i40e_bus_speed_8000) {
  12106. dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
  12107. dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
  12108. }
  12109. }
  12110. /* get the requested speeds from the fw */
  12111. err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
  12112. if (err)
  12113. dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
  12114. i40e_stat_str(&pf->hw, err),
  12115. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  12116. pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
  12117. /* get the supported phy types from the fw */
  12118. err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
  12119. if (err)
  12120. dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
  12121. i40e_stat_str(&pf->hw, err),
  12122. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  12123. /* Add a filter to drop all Flow control frames from any VSI from being
  12124. * transmitted. By doing so we stop a malicious VF from sending out
  12125. * PAUSE or PFC frames and potentially controlling traffic for other
  12126. * PF/VF VSIs.
  12127. * The FW can still send Flow control frames if enabled.
  12128. */
  12129. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  12130. pf->main_vsi_seid);
  12131. if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
  12132. (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
  12133. pf->hw_features |= I40E_HW_PHY_CONTROLS_LEDS;
  12134. if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722)
  12135. pf->hw_features |= I40E_HW_HAVE_CRT_RETIMER;
  12136. /* print a string summarizing features */
  12137. i40e_print_features(pf);
  12138. return 0;
  12139. /* Unwind what we've done if something failed in the setup */
  12140. err_vsis:
  12141. set_bit(__I40E_DOWN, pf->state);
  12142. i40e_clear_interrupt_scheme(pf);
  12143. kfree(pf->vsi);
  12144. err_switch_setup:
  12145. i40e_reset_interrupt_capability(pf);
  12146. del_timer_sync(&pf->service_timer);
  12147. err_mac_addr:
  12148. err_configure_lan_hmc:
  12149. (void)i40e_shutdown_lan_hmc(hw);
  12150. err_init_lan_hmc:
  12151. kfree(pf->qp_pile);
  12152. err_sw_init:
  12153. err_adminq_setup:
  12154. err_pf_reset:
  12155. iounmap(hw->hw_addr);
  12156. err_ioremap:
  12157. kfree(pf);
  12158. err_pf_alloc:
  12159. pci_disable_pcie_error_reporting(pdev);
  12160. pci_release_mem_regions(pdev);
  12161. err_pci_reg:
  12162. err_dma:
  12163. pci_disable_device(pdev);
  12164. return err;
  12165. }
  12166. /**
  12167. * i40e_remove - Device removal routine
  12168. * @pdev: PCI device information struct
  12169. *
  12170. * i40e_remove is called by the PCI subsystem to alert the driver
  12171. * that is should release a PCI device. This could be caused by a
  12172. * Hot-Plug event, or because the driver is going to be removed from
  12173. * memory.
  12174. **/
  12175. static void i40e_remove(struct pci_dev *pdev)
  12176. {
  12177. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12178. struct i40e_hw *hw = &pf->hw;
  12179. i40e_status ret_code;
  12180. int i;
  12181. i40e_dbg_pf_exit(pf);
  12182. i40e_ptp_stop(pf);
  12183. /* Disable RSS in hw */
  12184. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
  12185. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
  12186. /* no more scheduling of any task */
  12187. set_bit(__I40E_SUSPENDED, pf->state);
  12188. set_bit(__I40E_DOWN, pf->state);
  12189. if (pf->service_timer.function)
  12190. del_timer_sync(&pf->service_timer);
  12191. if (pf->service_task.func)
  12192. cancel_work_sync(&pf->service_task);
  12193. /* Client close must be called explicitly here because the timer
  12194. * has been stopped.
  12195. */
  12196. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
  12197. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  12198. i40e_free_vfs(pf);
  12199. pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
  12200. }
  12201. i40e_fdir_teardown(pf);
  12202. /* If there is a switch structure or any orphans, remove them.
  12203. * This will leave only the PF's VSI remaining.
  12204. */
  12205. for (i = 0; i < I40E_MAX_VEB; i++) {
  12206. if (!pf->veb[i])
  12207. continue;
  12208. if (pf->veb[i]->uplink_seid == pf->mac_seid ||
  12209. pf->veb[i]->uplink_seid == 0)
  12210. i40e_switch_branch_release(pf->veb[i]);
  12211. }
  12212. /* Now we can shutdown the PF's VSI, just before we kill
  12213. * adminq and hmc.
  12214. */
  12215. if (pf->vsi[pf->lan_vsi])
  12216. i40e_vsi_release(pf->vsi[pf->lan_vsi]);
  12217. i40e_cloud_filter_exit(pf);
  12218. /* remove attached clients */
  12219. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  12220. ret_code = i40e_lan_del_device(pf);
  12221. if (ret_code)
  12222. dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
  12223. ret_code);
  12224. }
  12225. /* shutdown and destroy the HMC */
  12226. if (hw->hmc.hmc_obj) {
  12227. ret_code = i40e_shutdown_lan_hmc(hw);
  12228. if (ret_code)
  12229. dev_warn(&pdev->dev,
  12230. "Failed to destroy the HMC resources: %d\n",
  12231. ret_code);
  12232. }
  12233. /* shutdown the adminq */
  12234. i40e_shutdown_adminq(hw);
  12235. /* destroy the locks only once, here */
  12236. mutex_destroy(&hw->aq.arq_mutex);
  12237. mutex_destroy(&hw->aq.asq_mutex);
  12238. /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
  12239. i40e_clear_interrupt_scheme(pf);
  12240. for (i = 0; i < pf->num_alloc_vsi; i++) {
  12241. if (pf->vsi[i]) {
  12242. i40e_vsi_clear_rings(pf->vsi[i]);
  12243. i40e_vsi_clear(pf->vsi[i]);
  12244. pf->vsi[i] = NULL;
  12245. }
  12246. }
  12247. for (i = 0; i < I40E_MAX_VEB; i++) {
  12248. kfree(pf->veb[i]);
  12249. pf->veb[i] = NULL;
  12250. }
  12251. kfree(pf->qp_pile);
  12252. kfree(pf->vsi);
  12253. iounmap(hw->hw_addr);
  12254. kfree(pf);
  12255. pci_release_mem_regions(pdev);
  12256. pci_disable_pcie_error_reporting(pdev);
  12257. pci_disable_device(pdev);
  12258. }
  12259. /**
  12260. * i40e_pci_error_detected - warning that something funky happened in PCI land
  12261. * @pdev: PCI device information struct
  12262. *
  12263. * Called to warn that something happened and the error handling steps
  12264. * are in progress. Allows the driver to quiesce things, be ready for
  12265. * remediation.
  12266. **/
  12267. static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
  12268. enum pci_channel_state error)
  12269. {
  12270. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12271. dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
  12272. if (!pf) {
  12273. dev_info(&pdev->dev,
  12274. "Cannot recover - error happened during device probe\n");
  12275. return PCI_ERS_RESULT_DISCONNECT;
  12276. }
  12277. /* shutdown all operations */
  12278. if (!test_bit(__I40E_SUSPENDED, pf->state))
  12279. i40e_prep_for_reset(pf, false);
  12280. /* Request a slot reset */
  12281. return PCI_ERS_RESULT_NEED_RESET;
  12282. }
  12283. /**
  12284. * i40e_pci_error_slot_reset - a PCI slot reset just happened
  12285. * @pdev: PCI device information struct
  12286. *
  12287. * Called to find if the driver can work with the device now that
  12288. * the pci slot has been reset. If a basic connection seems good
  12289. * (registers are readable and have sane content) then return a
  12290. * happy little PCI_ERS_RESULT_xxx.
  12291. **/
  12292. static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
  12293. {
  12294. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12295. pci_ers_result_t result;
  12296. int err;
  12297. u32 reg;
  12298. dev_dbg(&pdev->dev, "%s\n", __func__);
  12299. if (pci_enable_device_mem(pdev)) {
  12300. dev_info(&pdev->dev,
  12301. "Cannot re-enable PCI device after reset.\n");
  12302. result = PCI_ERS_RESULT_DISCONNECT;
  12303. } else {
  12304. pci_set_master(pdev);
  12305. pci_restore_state(pdev);
  12306. pci_save_state(pdev);
  12307. pci_wake_from_d3(pdev, false);
  12308. reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  12309. if (reg == 0)
  12310. result = PCI_ERS_RESULT_RECOVERED;
  12311. else
  12312. result = PCI_ERS_RESULT_DISCONNECT;
  12313. }
  12314. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  12315. if (err) {
  12316. dev_info(&pdev->dev,
  12317. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
  12318. err);
  12319. /* non-fatal, continue */
  12320. }
  12321. return result;
  12322. }
  12323. /**
  12324. * i40e_pci_error_reset_prepare - prepare device driver for pci reset
  12325. * @pdev: PCI device information struct
  12326. */
  12327. static void i40e_pci_error_reset_prepare(struct pci_dev *pdev)
  12328. {
  12329. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12330. i40e_prep_for_reset(pf, false);
  12331. }
  12332. /**
  12333. * i40e_pci_error_reset_done - pci reset done, device driver reset can begin
  12334. * @pdev: PCI device information struct
  12335. */
  12336. static void i40e_pci_error_reset_done(struct pci_dev *pdev)
  12337. {
  12338. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12339. i40e_reset_and_rebuild(pf, false, false);
  12340. }
  12341. /**
  12342. * i40e_pci_error_resume - restart operations after PCI error recovery
  12343. * @pdev: PCI device information struct
  12344. *
  12345. * Called to allow the driver to bring things back up after PCI error
  12346. * and/or reset recovery has finished.
  12347. **/
  12348. static void i40e_pci_error_resume(struct pci_dev *pdev)
  12349. {
  12350. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12351. dev_dbg(&pdev->dev, "%s\n", __func__);
  12352. if (test_bit(__I40E_SUSPENDED, pf->state))
  12353. return;
  12354. i40e_handle_reset_warning(pf, false);
  12355. }
  12356. /**
  12357. * i40e_enable_mc_magic_wake - enable multicast magic packet wake up
  12358. * using the mac_address_write admin q function
  12359. * @pf: pointer to i40e_pf struct
  12360. **/
  12361. static void i40e_enable_mc_magic_wake(struct i40e_pf *pf)
  12362. {
  12363. struct i40e_hw *hw = &pf->hw;
  12364. i40e_status ret;
  12365. u8 mac_addr[6];
  12366. u16 flags = 0;
  12367. /* Get current MAC address in case it's an LAA */
  12368. if (pf->vsi[pf->lan_vsi] && pf->vsi[pf->lan_vsi]->netdev) {
  12369. ether_addr_copy(mac_addr,
  12370. pf->vsi[pf->lan_vsi]->netdev->dev_addr);
  12371. } else {
  12372. dev_err(&pf->pdev->dev,
  12373. "Failed to retrieve MAC address; using default\n");
  12374. ether_addr_copy(mac_addr, hw->mac.addr);
  12375. }
  12376. /* The FW expects the mac address write cmd to first be called with
  12377. * one of these flags before calling it again with the multicast
  12378. * enable flags.
  12379. */
  12380. flags = I40E_AQC_WRITE_TYPE_LAA_WOL;
  12381. if (hw->func_caps.flex10_enable && hw->partition_id != 1)
  12382. flags = I40E_AQC_WRITE_TYPE_LAA_ONLY;
  12383. ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
  12384. if (ret) {
  12385. dev_err(&pf->pdev->dev,
  12386. "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up");
  12387. return;
  12388. }
  12389. flags = I40E_AQC_MC_MAG_EN
  12390. | I40E_AQC_WOL_PRESERVE_ON_PFR
  12391. | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG;
  12392. ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
  12393. if (ret)
  12394. dev_err(&pf->pdev->dev,
  12395. "Failed to enable Multicast Magic Packet wake up\n");
  12396. }
  12397. /**
  12398. * i40e_shutdown - PCI callback for shutting down
  12399. * @pdev: PCI device information struct
  12400. **/
  12401. static void i40e_shutdown(struct pci_dev *pdev)
  12402. {
  12403. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12404. struct i40e_hw *hw = &pf->hw;
  12405. set_bit(__I40E_SUSPENDED, pf->state);
  12406. set_bit(__I40E_DOWN, pf->state);
  12407. rtnl_lock();
  12408. i40e_prep_for_reset(pf, true);
  12409. rtnl_unlock();
  12410. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  12411. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  12412. del_timer_sync(&pf->service_timer);
  12413. cancel_work_sync(&pf->service_task);
  12414. i40e_cloud_filter_exit(pf);
  12415. i40e_fdir_teardown(pf);
  12416. /* Client close must be called explicitly here because the timer
  12417. * has been stopped.
  12418. */
  12419. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
  12420. if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE))
  12421. i40e_enable_mc_magic_wake(pf);
  12422. i40e_prep_for_reset(pf, false);
  12423. wr32(hw, I40E_PFPM_APM,
  12424. (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  12425. wr32(hw, I40E_PFPM_WUFC,
  12426. (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  12427. i40e_clear_interrupt_scheme(pf);
  12428. if (system_state == SYSTEM_POWER_OFF) {
  12429. pci_wake_from_d3(pdev, pf->wol_en);
  12430. pci_set_power_state(pdev, PCI_D3hot);
  12431. }
  12432. }
  12433. /**
  12434. * i40e_suspend - PM callback for moving to D3
  12435. * @dev: generic device information structure
  12436. **/
  12437. static int __maybe_unused i40e_suspend(struct device *dev)
  12438. {
  12439. struct pci_dev *pdev = to_pci_dev(dev);
  12440. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12441. struct i40e_hw *hw = &pf->hw;
  12442. /* If we're already suspended, then there is nothing to do */
  12443. if (test_and_set_bit(__I40E_SUSPENDED, pf->state))
  12444. return 0;
  12445. set_bit(__I40E_DOWN, pf->state);
  12446. /* Ensure service task will not be running */
  12447. del_timer_sync(&pf->service_timer);
  12448. cancel_work_sync(&pf->service_task);
  12449. if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE))
  12450. i40e_enable_mc_magic_wake(pf);
  12451. i40e_prep_for_reset(pf, false);
  12452. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  12453. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  12454. /* Clear the interrupt scheme and release our IRQs so that the system
  12455. * can safely hibernate even when there are a large number of CPUs.
  12456. * Otherwise hibernation might fail when mapping all the vectors back
  12457. * to CPU0.
  12458. */
  12459. i40e_clear_interrupt_scheme(pf);
  12460. return 0;
  12461. }
  12462. /**
  12463. * i40e_resume - PM callback for waking up from D3
  12464. * @dev: generic device information structure
  12465. **/
  12466. static int __maybe_unused i40e_resume(struct device *dev)
  12467. {
  12468. struct pci_dev *pdev = to_pci_dev(dev);
  12469. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12470. int err;
  12471. /* If we're not suspended, then there is nothing to do */
  12472. if (!test_bit(__I40E_SUSPENDED, pf->state))
  12473. return 0;
  12474. /* We cleared the interrupt scheme when we suspended, so we need to
  12475. * restore it now to resume device functionality.
  12476. */
  12477. err = i40e_restore_interrupt_scheme(pf);
  12478. if (err) {
  12479. dev_err(&pdev->dev, "Cannot restore interrupt scheme: %d\n",
  12480. err);
  12481. }
  12482. clear_bit(__I40E_DOWN, pf->state);
  12483. i40e_reset_and_rebuild(pf, false, false);
  12484. /* Clear suspended state last after everything is recovered */
  12485. clear_bit(__I40E_SUSPENDED, pf->state);
  12486. /* Restart the service task */
  12487. mod_timer(&pf->service_timer,
  12488. round_jiffies(jiffies + pf->service_timer_period));
  12489. return 0;
  12490. }
  12491. static const struct pci_error_handlers i40e_err_handler = {
  12492. .error_detected = i40e_pci_error_detected,
  12493. .slot_reset = i40e_pci_error_slot_reset,
  12494. .reset_prepare = i40e_pci_error_reset_prepare,
  12495. .reset_done = i40e_pci_error_reset_done,
  12496. .resume = i40e_pci_error_resume,
  12497. };
  12498. static SIMPLE_DEV_PM_OPS(i40e_pm_ops, i40e_suspend, i40e_resume);
  12499. static struct pci_driver i40e_driver = {
  12500. .name = i40e_driver_name,
  12501. .id_table = i40e_pci_tbl,
  12502. .probe = i40e_probe,
  12503. .remove = i40e_remove,
  12504. .driver = {
  12505. .pm = &i40e_pm_ops,
  12506. },
  12507. .shutdown = i40e_shutdown,
  12508. .err_handler = &i40e_err_handler,
  12509. .sriov_configure = i40e_pci_sriov_configure,
  12510. };
  12511. /**
  12512. * i40e_init_module - Driver registration routine
  12513. *
  12514. * i40e_init_module is the first routine called when the driver is
  12515. * loaded. All it does is register with the PCI subsystem.
  12516. **/
  12517. static int __init i40e_init_module(void)
  12518. {
  12519. pr_info("%s: %s - version %s\n", i40e_driver_name,
  12520. i40e_driver_string, i40e_driver_version_str);
  12521. pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
  12522. /* There is no need to throttle the number of active tasks because
  12523. * each device limits its own task using a state bit for scheduling
  12524. * the service task, and the device tasks do not interfere with each
  12525. * other, so we don't set a max task limit. We must set WQ_MEM_RECLAIM
  12526. * since we need to be able to guarantee forward progress even under
  12527. * memory pressure.
  12528. */
  12529. i40e_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, i40e_driver_name);
  12530. if (!i40e_wq) {
  12531. pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
  12532. return -ENOMEM;
  12533. }
  12534. i40e_dbg_init();
  12535. return pci_register_driver(&i40e_driver);
  12536. }
  12537. module_init(i40e_init_module);
  12538. /**
  12539. * i40e_exit_module - Driver exit cleanup routine
  12540. *
  12541. * i40e_exit_module is called just before the driver is removed
  12542. * from memory.
  12543. **/
  12544. static void __exit i40e_exit_module(void)
  12545. {
  12546. pci_unregister_driver(&i40e_driver);
  12547. destroy_workqueue(i40e_wq);
  12548. i40e_dbg_exit();
  12549. }
  12550. module_exit(i40e_exit_module);