i40e_main.c 395 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352
  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 = READ_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 = READ_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_set_promiscuous - set promiscuous mode
  1944. * @pf: board private structure
  1945. * @promisc: promisc on or off
  1946. *
  1947. * There are different ways of setting promiscuous mode on a PF depending on
  1948. * what state/environment we're in. This identifies and sets it appropriately.
  1949. * Returns 0 on success.
  1950. **/
  1951. static int i40e_set_promiscuous(struct i40e_pf *pf, bool promisc)
  1952. {
  1953. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  1954. struct i40e_hw *hw = &pf->hw;
  1955. i40e_status aq_ret;
  1956. if (vsi->type == I40E_VSI_MAIN &&
  1957. pf->lan_veb != I40E_NO_VEB &&
  1958. !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
  1959. /* set defport ON for Main VSI instead of true promisc
  1960. * this way we will get all unicast/multicast and VLAN
  1961. * promisc behavior but will not get VF or VMDq traffic
  1962. * replicated on the Main VSI.
  1963. */
  1964. if (promisc)
  1965. aq_ret = i40e_aq_set_default_vsi(hw,
  1966. vsi->seid,
  1967. NULL);
  1968. else
  1969. aq_ret = i40e_aq_clear_default_vsi(hw,
  1970. vsi->seid,
  1971. NULL);
  1972. if (aq_ret) {
  1973. dev_info(&pf->pdev->dev,
  1974. "Set default VSI failed, err %s, aq_err %s\n",
  1975. i40e_stat_str(hw, aq_ret),
  1976. i40e_aq_str(hw, hw->aq.asq_last_status));
  1977. }
  1978. } else {
  1979. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
  1980. hw,
  1981. vsi->seid,
  1982. promisc, NULL,
  1983. true);
  1984. if (aq_ret) {
  1985. dev_info(&pf->pdev->dev,
  1986. "set unicast promisc failed, err %s, aq_err %s\n",
  1987. i40e_stat_str(hw, aq_ret),
  1988. i40e_aq_str(hw, hw->aq.asq_last_status));
  1989. }
  1990. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
  1991. hw,
  1992. vsi->seid,
  1993. promisc, NULL);
  1994. if (aq_ret) {
  1995. dev_info(&pf->pdev->dev,
  1996. "set multicast promisc failed, err %s, aq_err %s\n",
  1997. i40e_stat_str(hw, aq_ret),
  1998. i40e_aq_str(hw, hw->aq.asq_last_status));
  1999. }
  2000. }
  2001. if (!aq_ret)
  2002. pf->cur_promisc = promisc;
  2003. return aq_ret;
  2004. }
  2005. /**
  2006. * i40e_sync_vsi_filters - Update the VSI filter list to the HW
  2007. * @vsi: ptr to the VSI
  2008. *
  2009. * Push any outstanding VSI filter changes through the AdminQ.
  2010. *
  2011. * Returns 0 or error value
  2012. **/
  2013. int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
  2014. {
  2015. struct hlist_head tmp_add_list, tmp_del_list;
  2016. struct i40e_mac_filter *f;
  2017. struct i40e_new_mac_filter *new, *add_head = NULL;
  2018. struct i40e_hw *hw = &vsi->back->hw;
  2019. unsigned int failed_filters = 0;
  2020. unsigned int vlan_filters = 0;
  2021. bool promisc_changed = false;
  2022. char vsi_name[16] = "PF";
  2023. int filter_list_len = 0;
  2024. i40e_status aq_ret = 0;
  2025. u32 changed_flags = 0;
  2026. struct hlist_node *h;
  2027. struct i40e_pf *pf;
  2028. int num_add = 0;
  2029. int num_del = 0;
  2030. int retval = 0;
  2031. u16 cmd_flags;
  2032. int list_size;
  2033. int bkt;
  2034. /* empty array typed pointers, kcalloc later */
  2035. struct i40e_aqc_add_macvlan_element_data *add_list;
  2036. struct i40e_aqc_remove_macvlan_element_data *del_list;
  2037. while (test_and_set_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state))
  2038. usleep_range(1000, 2000);
  2039. pf = vsi->back;
  2040. if (vsi->netdev) {
  2041. changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
  2042. vsi->current_netdev_flags = vsi->netdev->flags;
  2043. }
  2044. INIT_HLIST_HEAD(&tmp_add_list);
  2045. INIT_HLIST_HEAD(&tmp_del_list);
  2046. if (vsi->type == I40E_VSI_SRIOV)
  2047. snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id);
  2048. else if (vsi->type != I40E_VSI_MAIN)
  2049. snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid);
  2050. if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
  2051. vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
  2052. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2053. /* Create a list of filters to delete. */
  2054. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2055. if (f->state == I40E_FILTER_REMOVE) {
  2056. /* Move the element into temporary del_list */
  2057. hash_del(&f->hlist);
  2058. hlist_add_head(&f->hlist, &tmp_del_list);
  2059. /* Avoid counting removed filters */
  2060. continue;
  2061. }
  2062. if (f->state == I40E_FILTER_NEW) {
  2063. /* Create a temporary i40e_new_mac_filter */
  2064. new = kzalloc(sizeof(*new), GFP_ATOMIC);
  2065. if (!new)
  2066. goto err_no_memory_locked;
  2067. /* Store pointer to the real filter */
  2068. new->f = f;
  2069. new->state = f->state;
  2070. /* Add it to the hash list */
  2071. hlist_add_head(&new->hlist, &tmp_add_list);
  2072. }
  2073. /* Count the number of active (current and new) VLAN
  2074. * filters we have now. Does not count filters which
  2075. * are marked for deletion.
  2076. */
  2077. if (f->vlan > 0)
  2078. vlan_filters++;
  2079. }
  2080. retval = i40e_correct_mac_vlan_filters(vsi,
  2081. &tmp_add_list,
  2082. &tmp_del_list,
  2083. vlan_filters);
  2084. if (retval)
  2085. goto err_no_memory_locked;
  2086. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2087. }
  2088. /* Now process 'del_list' outside the lock */
  2089. if (!hlist_empty(&tmp_del_list)) {
  2090. filter_list_len = hw->aq.asq_buf_size /
  2091. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  2092. list_size = filter_list_len *
  2093. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  2094. del_list = kzalloc(list_size, GFP_ATOMIC);
  2095. if (!del_list)
  2096. goto err_no_memory;
  2097. hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) {
  2098. cmd_flags = 0;
  2099. /* handle broadcast filters by updating the broadcast
  2100. * promiscuous flag and release filter list.
  2101. */
  2102. if (is_broadcast_ether_addr(f->macaddr)) {
  2103. i40e_aqc_broadcast_filter(vsi, vsi_name, f);
  2104. hlist_del(&f->hlist);
  2105. kfree(f);
  2106. continue;
  2107. }
  2108. /* add to delete list */
  2109. ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
  2110. if (f->vlan == I40E_VLAN_ANY) {
  2111. del_list[num_del].vlan_tag = 0;
  2112. cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  2113. } else {
  2114. del_list[num_del].vlan_tag =
  2115. cpu_to_le16((u16)(f->vlan));
  2116. }
  2117. cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  2118. del_list[num_del].flags = cmd_flags;
  2119. num_del++;
  2120. /* flush a full buffer */
  2121. if (num_del == filter_list_len) {
  2122. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  2123. num_del, &retval);
  2124. memset(del_list, 0, list_size);
  2125. num_del = 0;
  2126. }
  2127. /* Release memory for MAC filter entries which were
  2128. * synced up with HW.
  2129. */
  2130. hlist_del(&f->hlist);
  2131. kfree(f);
  2132. }
  2133. if (num_del) {
  2134. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  2135. num_del, &retval);
  2136. }
  2137. kfree(del_list);
  2138. del_list = NULL;
  2139. }
  2140. if (!hlist_empty(&tmp_add_list)) {
  2141. /* Do all the adds now. */
  2142. filter_list_len = hw->aq.asq_buf_size /
  2143. sizeof(struct i40e_aqc_add_macvlan_element_data);
  2144. list_size = filter_list_len *
  2145. sizeof(struct i40e_aqc_add_macvlan_element_data);
  2146. add_list = kzalloc(list_size, GFP_ATOMIC);
  2147. if (!add_list)
  2148. goto err_no_memory;
  2149. num_add = 0;
  2150. hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
  2151. if (test_bit(__I40E_VSI_OVERFLOW_PROMISC,
  2152. vsi->state)) {
  2153. new->state = I40E_FILTER_FAILED;
  2154. continue;
  2155. }
  2156. /* handle broadcast filters by updating the broadcast
  2157. * promiscuous flag instead of adding a MAC filter.
  2158. */
  2159. if (is_broadcast_ether_addr(new->f->macaddr)) {
  2160. if (i40e_aqc_broadcast_filter(vsi, vsi_name,
  2161. new->f))
  2162. new->state = I40E_FILTER_FAILED;
  2163. else
  2164. new->state = I40E_FILTER_ACTIVE;
  2165. continue;
  2166. }
  2167. /* add to add array */
  2168. if (num_add == 0)
  2169. add_head = new;
  2170. cmd_flags = 0;
  2171. ether_addr_copy(add_list[num_add].mac_addr,
  2172. new->f->macaddr);
  2173. if (new->f->vlan == I40E_VLAN_ANY) {
  2174. add_list[num_add].vlan_tag = 0;
  2175. cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
  2176. } else {
  2177. add_list[num_add].vlan_tag =
  2178. cpu_to_le16((u16)(new->f->vlan));
  2179. }
  2180. add_list[num_add].queue_number = 0;
  2181. /* set invalid match method for later detection */
  2182. add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES;
  2183. cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
  2184. add_list[num_add].flags = cpu_to_le16(cmd_flags);
  2185. num_add++;
  2186. /* flush a full buffer */
  2187. if (num_add == filter_list_len) {
  2188. i40e_aqc_add_filters(vsi, vsi_name, add_list,
  2189. add_head, num_add,
  2190. &promisc_changed);
  2191. memset(add_list, 0, list_size);
  2192. num_add = 0;
  2193. }
  2194. }
  2195. if (num_add) {
  2196. i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head,
  2197. num_add, &promisc_changed);
  2198. }
  2199. /* Now move all of the filters from the temp add list back to
  2200. * the VSI's list.
  2201. */
  2202. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2203. hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
  2204. /* Only update the state if we're still NEW */
  2205. if (new->f->state == I40E_FILTER_NEW)
  2206. new->f->state = new->state;
  2207. hlist_del(&new->hlist);
  2208. kfree(new);
  2209. }
  2210. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2211. kfree(add_list);
  2212. add_list = NULL;
  2213. }
  2214. /* Determine the number of active and failed filters. */
  2215. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2216. vsi->active_filters = 0;
  2217. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
  2218. if (f->state == I40E_FILTER_ACTIVE)
  2219. vsi->active_filters++;
  2220. else if (f->state == I40E_FILTER_FAILED)
  2221. failed_filters++;
  2222. }
  2223. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2224. /* If promiscuous mode has changed, we need to calculate a new
  2225. * threshold for when we are safe to exit
  2226. */
  2227. if (promisc_changed)
  2228. vsi->promisc_threshold = (vsi->active_filters * 3) / 4;
  2229. /* Check if we are able to exit overflow promiscuous mode. We can
  2230. * safely exit if we didn't just enter, we no longer have any failed
  2231. * filters, and we have reduced filters below the threshold value.
  2232. */
  2233. if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state) &&
  2234. !promisc_changed && !failed_filters &&
  2235. (vsi->active_filters < vsi->promisc_threshold)) {
  2236. dev_info(&pf->pdev->dev,
  2237. "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
  2238. vsi_name);
  2239. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  2240. promisc_changed = true;
  2241. vsi->promisc_threshold = 0;
  2242. }
  2243. /* if the VF is not trusted do not do promisc */
  2244. if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) {
  2245. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  2246. goto out;
  2247. }
  2248. /* check for changes in promiscuous modes */
  2249. if (changed_flags & IFF_ALLMULTI) {
  2250. bool cur_multipromisc;
  2251. cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
  2252. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
  2253. vsi->seid,
  2254. cur_multipromisc,
  2255. NULL);
  2256. if (aq_ret) {
  2257. retval = i40e_aq_rc_to_posix(aq_ret,
  2258. hw->aq.asq_last_status);
  2259. dev_info(&pf->pdev->dev,
  2260. "set multi promisc failed on %s, err %s aq_err %s\n",
  2261. vsi_name,
  2262. i40e_stat_str(hw, aq_ret),
  2263. i40e_aq_str(hw, hw->aq.asq_last_status));
  2264. }
  2265. }
  2266. if ((changed_flags & IFF_PROMISC) || promisc_changed) {
  2267. bool cur_promisc;
  2268. cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
  2269. test_bit(__I40E_VSI_OVERFLOW_PROMISC,
  2270. vsi->state));
  2271. aq_ret = i40e_set_promiscuous(pf, cur_promisc);
  2272. if (aq_ret) {
  2273. retval = i40e_aq_rc_to_posix(aq_ret,
  2274. hw->aq.asq_last_status);
  2275. dev_info(&pf->pdev->dev,
  2276. "Setting promiscuous %s failed on %s, err %s aq_err %s\n",
  2277. cur_promisc ? "on" : "off",
  2278. vsi_name,
  2279. i40e_stat_str(hw, aq_ret),
  2280. i40e_aq_str(hw, hw->aq.asq_last_status));
  2281. }
  2282. }
  2283. out:
  2284. /* if something went wrong then set the changed flag so we try again */
  2285. if (retval)
  2286. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2287. clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
  2288. return retval;
  2289. err_no_memory:
  2290. /* Restore elements on the temporary add and delete lists */
  2291. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2292. err_no_memory_locked:
  2293. i40e_undo_del_filter_entries(vsi, &tmp_del_list);
  2294. i40e_undo_add_filter_entries(vsi, &tmp_add_list);
  2295. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2296. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2297. clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
  2298. return -ENOMEM;
  2299. }
  2300. /**
  2301. * i40e_sync_filters_subtask - Sync the VSI filter list with HW
  2302. * @pf: board private structure
  2303. **/
  2304. static void i40e_sync_filters_subtask(struct i40e_pf *pf)
  2305. {
  2306. int v;
  2307. if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
  2308. return;
  2309. pf->flags &= ~I40E_FLAG_FILTER_SYNC;
  2310. for (v = 0; v < pf->num_alloc_vsi; v++) {
  2311. if (pf->vsi[v] &&
  2312. (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
  2313. int ret = i40e_sync_vsi_filters(pf->vsi[v]);
  2314. if (ret) {
  2315. /* come back and try again later */
  2316. pf->flags |= I40E_FLAG_FILTER_SYNC;
  2317. break;
  2318. }
  2319. }
  2320. }
  2321. }
  2322. /**
  2323. * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP
  2324. * @vsi: the vsi
  2325. **/
  2326. static int i40e_max_xdp_frame_size(struct i40e_vsi *vsi)
  2327. {
  2328. if (PAGE_SIZE >= 8192 || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
  2329. return I40E_RXBUFFER_2048;
  2330. else
  2331. return I40E_RXBUFFER_3072;
  2332. }
  2333. /**
  2334. * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  2335. * @netdev: network interface device structure
  2336. * @new_mtu: new value for maximum frame size
  2337. *
  2338. * Returns 0 on success, negative on failure
  2339. **/
  2340. static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
  2341. {
  2342. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2343. struct i40e_vsi *vsi = np->vsi;
  2344. struct i40e_pf *pf = vsi->back;
  2345. if (i40e_enabled_xdp_vsi(vsi)) {
  2346. int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  2347. if (frame_size > i40e_max_xdp_frame_size(vsi))
  2348. return -EINVAL;
  2349. }
  2350. netdev_info(netdev, "changing MTU from %d to %d\n",
  2351. netdev->mtu, new_mtu);
  2352. netdev->mtu = new_mtu;
  2353. if (netif_running(netdev))
  2354. i40e_vsi_reinit_locked(vsi);
  2355. pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED |
  2356. I40E_FLAG_CLIENT_L2_CHANGE);
  2357. return 0;
  2358. }
  2359. /**
  2360. * i40e_ioctl - Access the hwtstamp interface
  2361. * @netdev: network interface device structure
  2362. * @ifr: interface request data
  2363. * @cmd: ioctl command
  2364. **/
  2365. int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  2366. {
  2367. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2368. struct i40e_pf *pf = np->vsi->back;
  2369. switch (cmd) {
  2370. case SIOCGHWTSTAMP:
  2371. return i40e_ptp_get_ts_config(pf, ifr);
  2372. case SIOCSHWTSTAMP:
  2373. return i40e_ptp_set_ts_config(pf, ifr);
  2374. default:
  2375. return -EOPNOTSUPP;
  2376. }
  2377. }
  2378. /**
  2379. * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
  2380. * @vsi: the vsi being adjusted
  2381. **/
  2382. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
  2383. {
  2384. struct i40e_vsi_context ctxt;
  2385. i40e_status ret;
  2386. if ((vsi->info.valid_sections &
  2387. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2388. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
  2389. return; /* already enabled */
  2390. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2391. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2392. I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
  2393. ctxt.seid = vsi->seid;
  2394. ctxt.info = vsi->info;
  2395. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2396. if (ret) {
  2397. dev_info(&vsi->back->pdev->dev,
  2398. "update vlan stripping failed, err %s aq_err %s\n",
  2399. i40e_stat_str(&vsi->back->hw, ret),
  2400. i40e_aq_str(&vsi->back->hw,
  2401. vsi->back->hw.aq.asq_last_status));
  2402. }
  2403. }
  2404. /**
  2405. * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
  2406. * @vsi: the vsi being adjusted
  2407. **/
  2408. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
  2409. {
  2410. struct i40e_vsi_context ctxt;
  2411. i40e_status ret;
  2412. if ((vsi->info.valid_sections &
  2413. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2414. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
  2415. I40E_AQ_VSI_PVLAN_EMOD_MASK))
  2416. return; /* already disabled */
  2417. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2418. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2419. I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
  2420. ctxt.seid = vsi->seid;
  2421. ctxt.info = vsi->info;
  2422. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2423. if (ret) {
  2424. dev_info(&vsi->back->pdev->dev,
  2425. "update vlan stripping failed, err %s aq_err %s\n",
  2426. i40e_stat_str(&vsi->back->hw, ret),
  2427. i40e_aq_str(&vsi->back->hw,
  2428. vsi->back->hw.aq.asq_last_status));
  2429. }
  2430. }
  2431. /**
  2432. * i40e_vlan_rx_register - Setup or shutdown vlan offload
  2433. * @netdev: network interface to be adjusted
  2434. * @features: netdev features to test if VLAN offload is enabled or not
  2435. **/
  2436. static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
  2437. {
  2438. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2439. struct i40e_vsi *vsi = np->vsi;
  2440. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  2441. i40e_vlan_stripping_enable(vsi);
  2442. else
  2443. i40e_vlan_stripping_disable(vsi);
  2444. }
  2445. /**
  2446. * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address
  2447. * @vsi: the vsi being configured
  2448. * @vid: vlan id to be added (0 = untagged only , -1 = any)
  2449. *
  2450. * This is a helper function for adding a new MAC/VLAN filter with the
  2451. * specified VLAN for each existing MAC address already in the hash table.
  2452. * This function does *not* perform any accounting to update filters based on
  2453. * VLAN mode.
  2454. *
  2455. * NOTE: this function expects to be called while under the
  2456. * mac_filter_hash_lock
  2457. **/
  2458. int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2459. {
  2460. struct i40e_mac_filter *f, *add_f;
  2461. struct hlist_node *h;
  2462. int bkt;
  2463. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2464. if (f->state == I40E_FILTER_REMOVE)
  2465. continue;
  2466. add_f = i40e_add_filter(vsi, f->macaddr, vid);
  2467. if (!add_f) {
  2468. dev_info(&vsi->back->pdev->dev,
  2469. "Could not add vlan filter %d for %pM\n",
  2470. vid, f->macaddr);
  2471. return -ENOMEM;
  2472. }
  2473. }
  2474. return 0;
  2475. }
  2476. /**
  2477. * i40e_vsi_add_vlan - Add VSI membership for given VLAN
  2478. * @vsi: the VSI being configured
  2479. * @vid: VLAN id to be added
  2480. **/
  2481. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid)
  2482. {
  2483. int err;
  2484. if (vsi->info.pvid)
  2485. return -EINVAL;
  2486. /* The network stack will attempt to add VID=0, with the intention to
  2487. * receive priority tagged packets with a VLAN of 0. Our HW receives
  2488. * these packets by default when configured to receive untagged
  2489. * packets, so we don't need to add a filter for this case.
  2490. * Additionally, HW interprets adding a VID=0 filter as meaning to
  2491. * receive *only* tagged traffic and stops receiving untagged traffic.
  2492. * Thus, we do not want to actually add a filter for VID=0
  2493. */
  2494. if (!vid)
  2495. return 0;
  2496. /* Locked once because all functions invoked below iterates list*/
  2497. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2498. err = i40e_add_vlan_all_mac(vsi, vid);
  2499. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2500. if (err)
  2501. return err;
  2502. /* schedule our worker thread which will take care of
  2503. * applying the new filter changes
  2504. */
  2505. i40e_service_event_schedule(vsi->back);
  2506. return 0;
  2507. }
  2508. /**
  2509. * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN
  2510. * @vsi: the vsi being configured
  2511. * @vid: vlan id to be removed (0 = untagged only , -1 = any)
  2512. *
  2513. * This function should be used to remove all VLAN filters which match the
  2514. * given VID. It does not schedule the service event and does not take the
  2515. * mac_filter_hash_lock so it may be combined with other operations under
  2516. * a single invocation of the mac_filter_hash_lock.
  2517. *
  2518. * NOTE: this function expects to be called while under the
  2519. * mac_filter_hash_lock
  2520. */
  2521. void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2522. {
  2523. struct i40e_mac_filter *f;
  2524. struct hlist_node *h;
  2525. int bkt;
  2526. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2527. if (f->vlan == vid)
  2528. __i40e_del_filter(vsi, f);
  2529. }
  2530. }
  2531. /**
  2532. * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN
  2533. * @vsi: the VSI being configured
  2534. * @vid: VLAN id to be removed
  2535. **/
  2536. void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid)
  2537. {
  2538. if (!vid || vsi->info.pvid)
  2539. return;
  2540. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2541. i40e_rm_vlan_all_mac(vsi, vid);
  2542. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2543. /* schedule our worker thread which will take care of
  2544. * applying the new filter changes
  2545. */
  2546. i40e_service_event_schedule(vsi->back);
  2547. }
  2548. /**
  2549. * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
  2550. * @netdev: network interface to be adjusted
  2551. * @vid: vlan id to be added
  2552. *
  2553. * net_device_ops implementation for adding vlan ids
  2554. **/
  2555. static int i40e_vlan_rx_add_vid(struct net_device *netdev,
  2556. __always_unused __be16 proto, u16 vid)
  2557. {
  2558. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2559. struct i40e_vsi *vsi = np->vsi;
  2560. int ret = 0;
  2561. if (vid >= VLAN_N_VID)
  2562. return -EINVAL;
  2563. ret = i40e_vsi_add_vlan(vsi, vid);
  2564. if (!ret)
  2565. set_bit(vid, vsi->active_vlans);
  2566. return ret;
  2567. }
  2568. /**
  2569. * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
  2570. * @netdev: network interface to be adjusted
  2571. * @vid: vlan id to be removed
  2572. *
  2573. * net_device_ops implementation for removing vlan ids
  2574. **/
  2575. static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  2576. __always_unused __be16 proto, u16 vid)
  2577. {
  2578. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2579. struct i40e_vsi *vsi = np->vsi;
  2580. /* return code is ignored as there is nothing a user
  2581. * can do about failure to remove and a log message was
  2582. * already printed from the other function
  2583. */
  2584. i40e_vsi_kill_vlan(vsi, vid);
  2585. clear_bit(vid, vsi->active_vlans);
  2586. return 0;
  2587. }
  2588. /**
  2589. * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
  2590. * @vsi: the vsi being brought back up
  2591. **/
  2592. static void i40e_restore_vlan(struct i40e_vsi *vsi)
  2593. {
  2594. u16 vid;
  2595. if (!vsi->netdev)
  2596. return;
  2597. i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
  2598. for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
  2599. i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
  2600. vid);
  2601. }
  2602. /**
  2603. * i40e_vsi_add_pvid - Add pvid for the VSI
  2604. * @vsi: the vsi being adjusted
  2605. * @vid: the vlan id to set as a PVID
  2606. **/
  2607. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
  2608. {
  2609. struct i40e_vsi_context ctxt;
  2610. i40e_status ret;
  2611. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2612. vsi->info.pvid = cpu_to_le16(vid);
  2613. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
  2614. I40E_AQ_VSI_PVLAN_INSERT_PVID |
  2615. I40E_AQ_VSI_PVLAN_EMOD_STR;
  2616. ctxt.seid = vsi->seid;
  2617. ctxt.info = vsi->info;
  2618. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2619. if (ret) {
  2620. dev_info(&vsi->back->pdev->dev,
  2621. "add pvid failed, err %s aq_err %s\n",
  2622. i40e_stat_str(&vsi->back->hw, ret),
  2623. i40e_aq_str(&vsi->back->hw,
  2624. vsi->back->hw.aq.asq_last_status));
  2625. return -ENOENT;
  2626. }
  2627. return 0;
  2628. }
  2629. /**
  2630. * i40e_vsi_remove_pvid - Remove the pvid from the VSI
  2631. * @vsi: the vsi being adjusted
  2632. *
  2633. * Just use the vlan_rx_register() service to put it back to normal
  2634. **/
  2635. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
  2636. {
  2637. i40e_vlan_stripping_disable(vsi);
  2638. vsi->info.pvid = 0;
  2639. }
  2640. /**
  2641. * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
  2642. * @vsi: ptr to the VSI
  2643. *
  2644. * If this function returns with an error, then it's possible one or
  2645. * more of the rings is populated (while the rest are not). It is the
  2646. * callers duty to clean those orphaned rings.
  2647. *
  2648. * Return 0 on success, negative on failure
  2649. **/
  2650. static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
  2651. {
  2652. int i, err = 0;
  2653. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2654. err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
  2655. if (!i40e_enabled_xdp_vsi(vsi))
  2656. return err;
  2657. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2658. err = i40e_setup_tx_descriptors(vsi->xdp_rings[i]);
  2659. return err;
  2660. }
  2661. /**
  2662. * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
  2663. * @vsi: ptr to the VSI
  2664. *
  2665. * Free VSI's transmit software resources
  2666. **/
  2667. static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
  2668. {
  2669. int i;
  2670. if (vsi->tx_rings) {
  2671. for (i = 0; i < vsi->num_queue_pairs; i++)
  2672. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
  2673. i40e_free_tx_resources(vsi->tx_rings[i]);
  2674. }
  2675. if (vsi->xdp_rings) {
  2676. for (i = 0; i < vsi->num_queue_pairs; i++)
  2677. if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
  2678. i40e_free_tx_resources(vsi->xdp_rings[i]);
  2679. }
  2680. }
  2681. /**
  2682. * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
  2683. * @vsi: ptr to the VSI
  2684. *
  2685. * If this function returns with an error, then it's possible one or
  2686. * more of the rings is populated (while the rest are not). It is the
  2687. * callers duty to clean those orphaned rings.
  2688. *
  2689. * Return 0 on success, negative on failure
  2690. **/
  2691. static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
  2692. {
  2693. int i, err = 0;
  2694. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2695. err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
  2696. return err;
  2697. }
  2698. /**
  2699. * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
  2700. * @vsi: ptr to the VSI
  2701. *
  2702. * Free all receive software resources
  2703. **/
  2704. static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
  2705. {
  2706. int i;
  2707. if (!vsi->rx_rings)
  2708. return;
  2709. for (i = 0; i < vsi->num_queue_pairs; i++)
  2710. if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
  2711. i40e_free_rx_resources(vsi->rx_rings[i]);
  2712. }
  2713. /**
  2714. * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
  2715. * @ring: The Tx ring to configure
  2716. *
  2717. * This enables/disables XPS for a given Tx descriptor ring
  2718. * based on the TCs enabled for the VSI that ring belongs to.
  2719. **/
  2720. static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
  2721. {
  2722. int cpu;
  2723. if (!ring->q_vector || !ring->netdev || ring->ch)
  2724. return;
  2725. /* We only initialize XPS once, so as not to overwrite user settings */
  2726. if (test_and_set_bit(__I40E_TX_XPS_INIT_DONE, ring->state))
  2727. return;
  2728. cpu = cpumask_local_spread(ring->q_vector->v_idx, -1);
  2729. netif_set_xps_queue(ring->netdev, get_cpu_mask(cpu),
  2730. ring->queue_index);
  2731. }
  2732. /**
  2733. * i40e_configure_tx_ring - Configure a transmit ring context and rest
  2734. * @ring: The Tx ring to configure
  2735. *
  2736. * Configure the Tx descriptor ring in the HMC context.
  2737. **/
  2738. static int i40e_configure_tx_ring(struct i40e_ring *ring)
  2739. {
  2740. struct i40e_vsi *vsi = ring->vsi;
  2741. u16 pf_q = vsi->base_queue + ring->queue_index;
  2742. struct i40e_hw *hw = &vsi->back->hw;
  2743. struct i40e_hmc_obj_txq tx_ctx;
  2744. i40e_status err = 0;
  2745. u32 qtx_ctl = 0;
  2746. /* some ATR related tx ring init */
  2747. if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
  2748. ring->atr_sample_rate = vsi->back->atr_sample_rate;
  2749. ring->atr_count = 0;
  2750. } else {
  2751. ring->atr_sample_rate = 0;
  2752. }
  2753. /* configure XPS */
  2754. i40e_config_xps_tx_ring(ring);
  2755. /* clear the context structure first */
  2756. memset(&tx_ctx, 0, sizeof(tx_ctx));
  2757. tx_ctx.new_context = 1;
  2758. tx_ctx.base = (ring->dma / 128);
  2759. tx_ctx.qlen = ring->count;
  2760. tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
  2761. I40E_FLAG_FD_ATR_ENABLED));
  2762. tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
  2763. /* FDIR VSI tx ring can still use RS bit and writebacks */
  2764. if (vsi->type != I40E_VSI_FDIR)
  2765. tx_ctx.head_wb_ena = 1;
  2766. tx_ctx.head_wb_addr = ring->dma +
  2767. (ring->count * sizeof(struct i40e_tx_desc));
  2768. /* As part of VSI creation/update, FW allocates certain
  2769. * Tx arbitration queue sets for each TC enabled for
  2770. * the VSI. The FW returns the handles to these queue
  2771. * sets as part of the response buffer to Add VSI,
  2772. * Update VSI, etc. AQ commands. It is expected that
  2773. * these queue set handles be associated with the Tx
  2774. * queues by the driver as part of the TX queue context
  2775. * initialization. This has to be done regardless of
  2776. * DCB as by default everything is mapped to TC0.
  2777. */
  2778. if (ring->ch)
  2779. tx_ctx.rdylist =
  2780. le16_to_cpu(ring->ch->info.qs_handle[ring->dcb_tc]);
  2781. else
  2782. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
  2783. tx_ctx.rdylist_act = 0;
  2784. /* clear the context in the HMC */
  2785. err = i40e_clear_lan_tx_queue_context(hw, pf_q);
  2786. if (err) {
  2787. dev_info(&vsi->back->pdev->dev,
  2788. "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
  2789. ring->queue_index, pf_q, err);
  2790. return -ENOMEM;
  2791. }
  2792. /* set the context in the HMC */
  2793. err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
  2794. if (err) {
  2795. dev_info(&vsi->back->pdev->dev,
  2796. "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
  2797. ring->queue_index, pf_q, err);
  2798. return -ENOMEM;
  2799. }
  2800. /* Now associate this queue with this PCI function */
  2801. if (ring->ch) {
  2802. if (ring->ch->type == I40E_VSI_VMDQ2)
  2803. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2804. else
  2805. return -EINVAL;
  2806. qtx_ctl |= (ring->ch->vsi_number <<
  2807. I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2808. I40E_QTX_CTL_VFVM_INDX_MASK;
  2809. } else {
  2810. if (vsi->type == I40E_VSI_VMDQ2) {
  2811. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2812. qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2813. I40E_QTX_CTL_VFVM_INDX_MASK;
  2814. } else {
  2815. qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
  2816. }
  2817. }
  2818. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
  2819. I40E_QTX_CTL_PF_INDX_MASK);
  2820. wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
  2821. i40e_flush(hw);
  2822. /* cache tail off for easier writes later */
  2823. ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
  2824. return 0;
  2825. }
  2826. /**
  2827. * i40e_configure_rx_ring - Configure a receive ring context
  2828. * @ring: The Rx ring to configure
  2829. *
  2830. * Configure the Rx descriptor ring in the HMC context.
  2831. **/
  2832. static int i40e_configure_rx_ring(struct i40e_ring *ring)
  2833. {
  2834. struct i40e_vsi *vsi = ring->vsi;
  2835. u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
  2836. u16 pf_q = vsi->base_queue + ring->queue_index;
  2837. struct i40e_hw *hw = &vsi->back->hw;
  2838. struct i40e_hmc_obj_rxq rx_ctx;
  2839. i40e_status err = 0;
  2840. bitmap_zero(ring->state, __I40E_RING_STATE_NBITS);
  2841. /* clear the context structure first */
  2842. memset(&rx_ctx, 0, sizeof(rx_ctx));
  2843. ring->rx_buf_len = vsi->rx_buf_len;
  2844. rx_ctx.dbuff = DIV_ROUND_UP(ring->rx_buf_len,
  2845. BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
  2846. rx_ctx.base = (ring->dma / 128);
  2847. rx_ctx.qlen = ring->count;
  2848. /* use 32 byte descriptors */
  2849. rx_ctx.dsize = 1;
  2850. /* descriptor type is always zero
  2851. * rx_ctx.dtype = 0;
  2852. */
  2853. rx_ctx.hsplit_0 = 0;
  2854. rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
  2855. if (hw->revision_id == 0)
  2856. rx_ctx.lrxqthresh = 0;
  2857. else
  2858. rx_ctx.lrxqthresh = 1;
  2859. rx_ctx.crcstrip = 1;
  2860. rx_ctx.l2tsel = 1;
  2861. /* this controls whether VLAN is stripped from inner headers */
  2862. rx_ctx.showiv = 0;
  2863. /* set the prefena field to 1 because the manual says to */
  2864. rx_ctx.prefena = 1;
  2865. /* clear the context in the HMC */
  2866. err = i40e_clear_lan_rx_queue_context(hw, pf_q);
  2867. if (err) {
  2868. dev_info(&vsi->back->pdev->dev,
  2869. "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2870. ring->queue_index, pf_q, err);
  2871. return -ENOMEM;
  2872. }
  2873. /* set the context in the HMC */
  2874. err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
  2875. if (err) {
  2876. dev_info(&vsi->back->pdev->dev,
  2877. "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2878. ring->queue_index, pf_q, err);
  2879. return -ENOMEM;
  2880. }
  2881. /* configure Rx buffer alignment */
  2882. if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
  2883. clear_ring_build_skb_enabled(ring);
  2884. else
  2885. set_ring_build_skb_enabled(ring);
  2886. /* cache tail for quicker writes, and clear the reg before use */
  2887. ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
  2888. writel(0, ring->tail);
  2889. i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
  2890. return 0;
  2891. }
  2892. /**
  2893. * i40e_vsi_configure_tx - Configure the VSI for Tx
  2894. * @vsi: VSI structure describing this set of rings and resources
  2895. *
  2896. * Configure the Tx VSI for operation.
  2897. **/
  2898. static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
  2899. {
  2900. int err = 0;
  2901. u16 i;
  2902. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2903. err = i40e_configure_tx_ring(vsi->tx_rings[i]);
  2904. if (!i40e_enabled_xdp_vsi(vsi))
  2905. return err;
  2906. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2907. err = i40e_configure_tx_ring(vsi->xdp_rings[i]);
  2908. return err;
  2909. }
  2910. /**
  2911. * i40e_vsi_configure_rx - Configure the VSI for Rx
  2912. * @vsi: the VSI being configured
  2913. *
  2914. * Configure the Rx VSI for operation.
  2915. **/
  2916. static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
  2917. {
  2918. int err = 0;
  2919. u16 i;
  2920. if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) {
  2921. vsi->max_frame = I40E_MAX_RXBUFFER;
  2922. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2923. #if (PAGE_SIZE < 8192)
  2924. } else if (!I40E_2K_TOO_SMALL_WITH_PADDING &&
  2925. (vsi->netdev->mtu <= ETH_DATA_LEN)) {
  2926. vsi->max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
  2927. vsi->rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
  2928. #endif
  2929. } else {
  2930. vsi->max_frame = I40E_MAX_RXBUFFER;
  2931. vsi->rx_buf_len = (PAGE_SIZE < 8192) ? I40E_RXBUFFER_3072 :
  2932. I40E_RXBUFFER_2048;
  2933. }
  2934. /* set up individual rings */
  2935. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2936. err = i40e_configure_rx_ring(vsi->rx_rings[i]);
  2937. return err;
  2938. }
  2939. /**
  2940. * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
  2941. * @vsi: ptr to the VSI
  2942. **/
  2943. static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
  2944. {
  2945. struct i40e_ring *tx_ring, *rx_ring;
  2946. u16 qoffset, qcount;
  2947. int i, n;
  2948. if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  2949. /* Reset the TC information */
  2950. for (i = 0; i < vsi->num_queue_pairs; i++) {
  2951. rx_ring = vsi->rx_rings[i];
  2952. tx_ring = vsi->tx_rings[i];
  2953. rx_ring->dcb_tc = 0;
  2954. tx_ring->dcb_tc = 0;
  2955. }
  2956. return;
  2957. }
  2958. for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
  2959. if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
  2960. continue;
  2961. qoffset = vsi->tc_config.tc_info[n].qoffset;
  2962. qcount = vsi->tc_config.tc_info[n].qcount;
  2963. for (i = qoffset; i < (qoffset + qcount); i++) {
  2964. rx_ring = vsi->rx_rings[i];
  2965. tx_ring = vsi->tx_rings[i];
  2966. rx_ring->dcb_tc = n;
  2967. tx_ring->dcb_tc = n;
  2968. }
  2969. }
  2970. }
  2971. /**
  2972. * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
  2973. * @vsi: ptr to the VSI
  2974. **/
  2975. static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
  2976. {
  2977. if (vsi->netdev)
  2978. i40e_set_rx_mode(vsi->netdev);
  2979. }
  2980. /**
  2981. * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
  2982. * @vsi: Pointer to the targeted VSI
  2983. *
  2984. * This function replays the hlist on the hw where all the SB Flow Director
  2985. * filters were saved.
  2986. **/
  2987. static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
  2988. {
  2989. struct i40e_fdir_filter *filter;
  2990. struct i40e_pf *pf = vsi->back;
  2991. struct hlist_node *node;
  2992. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  2993. return;
  2994. /* Reset FDir counters as we're replaying all existing filters */
  2995. pf->fd_tcp4_filter_cnt = 0;
  2996. pf->fd_udp4_filter_cnt = 0;
  2997. pf->fd_sctp4_filter_cnt = 0;
  2998. pf->fd_ip4_filter_cnt = 0;
  2999. hlist_for_each_entry_safe(filter, node,
  3000. &pf->fdir_filter_list, fdir_node) {
  3001. i40e_add_del_fdir(vsi, filter, true);
  3002. }
  3003. }
  3004. /**
  3005. * i40e_vsi_configure - Set up the VSI for action
  3006. * @vsi: the VSI being configured
  3007. **/
  3008. static int i40e_vsi_configure(struct i40e_vsi *vsi)
  3009. {
  3010. int err;
  3011. i40e_set_vsi_rx_mode(vsi);
  3012. i40e_restore_vlan(vsi);
  3013. i40e_vsi_config_dcb_rings(vsi);
  3014. err = i40e_vsi_configure_tx(vsi);
  3015. if (!err)
  3016. err = i40e_vsi_configure_rx(vsi);
  3017. return err;
  3018. }
  3019. /**
  3020. * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
  3021. * @vsi: the VSI being configured
  3022. **/
  3023. static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
  3024. {
  3025. bool has_xdp = i40e_enabled_xdp_vsi(vsi);
  3026. struct i40e_pf *pf = vsi->back;
  3027. struct i40e_hw *hw = &pf->hw;
  3028. u16 vector;
  3029. int i, q;
  3030. u32 qp;
  3031. /* The interrupt indexing is offset by 1 in the PFINT_ITRn
  3032. * and PFINT_LNKLSTn registers, e.g.:
  3033. * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
  3034. */
  3035. qp = vsi->base_queue;
  3036. vector = vsi->base_vector;
  3037. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  3038. struct i40e_q_vector *q_vector = vsi->q_vectors[i];
  3039. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  3040. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[i]->rx_itr_setting);
  3041. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  3042. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
  3043. q_vector->rx.itr);
  3044. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[i]->tx_itr_setting);
  3045. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  3046. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
  3047. q_vector->tx.itr);
  3048. wr32(hw, I40E_PFINT_RATEN(vector - 1),
  3049. i40e_intrl_usec_to_reg(vsi->int_rate_limit));
  3050. /* Linked list for the queuepairs assigned to this vector */
  3051. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
  3052. for (q = 0; q < q_vector->num_ringpairs; q++) {
  3053. u32 nextqp = has_xdp ? qp + vsi->alloc_queue_pairs : qp;
  3054. u32 val;
  3055. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3056. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  3057. (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
  3058. (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
  3059. (I40E_QUEUE_TYPE_TX <<
  3060. I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
  3061. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3062. if (has_xdp) {
  3063. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3064. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3065. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  3066. (qp << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
  3067. (I40E_QUEUE_TYPE_TX <<
  3068. I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3069. wr32(hw, I40E_QINT_TQCTL(nextqp), val);
  3070. }
  3071. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3072. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3073. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  3074. ((qp + 1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
  3075. (I40E_QUEUE_TYPE_RX <<
  3076. I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3077. /* Terminate the linked list */
  3078. if (q == (q_vector->num_ringpairs - 1))
  3079. val |= (I40E_QUEUE_END_OF_LIST <<
  3080. I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  3081. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3082. qp++;
  3083. }
  3084. }
  3085. i40e_flush(hw);
  3086. }
  3087. /**
  3088. * i40e_enable_misc_int_causes - enable the non-queue interrupts
  3089. * @hw: ptr to the hardware info
  3090. **/
  3091. static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
  3092. {
  3093. struct i40e_hw *hw = &pf->hw;
  3094. u32 val;
  3095. /* clear things first */
  3096. wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
  3097. rd32(hw, I40E_PFINT_ICR0); /* read to clear */
  3098. val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
  3099. I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
  3100. I40E_PFINT_ICR0_ENA_GRST_MASK |
  3101. I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
  3102. I40E_PFINT_ICR0_ENA_GPIO_MASK |
  3103. I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
  3104. I40E_PFINT_ICR0_ENA_VFLR_MASK |
  3105. I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3106. if (pf->flags & I40E_FLAG_IWARP_ENABLED)
  3107. val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3108. if (pf->flags & I40E_FLAG_PTP)
  3109. val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3110. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  3111. /* SW_ITR_IDX = 0, but don't change INTENA */
  3112. wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
  3113. I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
  3114. /* OTHER_ITR_IDX = 0 */
  3115. wr32(hw, I40E_PFINT_STAT_CTL0, 0);
  3116. }
  3117. /**
  3118. * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
  3119. * @vsi: the VSI being configured
  3120. **/
  3121. static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
  3122. {
  3123. u32 nextqp = i40e_enabled_xdp_vsi(vsi) ? vsi->alloc_queue_pairs : 0;
  3124. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3125. struct i40e_pf *pf = vsi->back;
  3126. struct i40e_hw *hw = &pf->hw;
  3127. u32 val;
  3128. /* set the ITR configuration */
  3129. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  3130. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting);
  3131. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  3132. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
  3133. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[0]->tx_itr_setting);
  3134. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  3135. wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
  3136. i40e_enable_misc_int_causes(pf);
  3137. /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
  3138. wr32(hw, I40E_PFINT_LNKLST0, 0);
  3139. /* Associate the queue pair to the vector and enable the queue int */
  3140. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3141. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  3142. (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
  3143. (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3144. wr32(hw, I40E_QINT_RQCTL(0), val);
  3145. if (i40e_enabled_xdp_vsi(vsi)) {
  3146. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3147. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT)|
  3148. (I40E_QUEUE_TYPE_TX
  3149. << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3150. wr32(hw, I40E_QINT_TQCTL(nextqp), val);
  3151. }
  3152. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3153. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3154. (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  3155. wr32(hw, I40E_QINT_TQCTL(0), val);
  3156. i40e_flush(hw);
  3157. }
  3158. /**
  3159. * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
  3160. * @pf: board private structure
  3161. **/
  3162. void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
  3163. {
  3164. struct i40e_hw *hw = &pf->hw;
  3165. wr32(hw, I40E_PFINT_DYN_CTL0,
  3166. I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  3167. i40e_flush(hw);
  3168. }
  3169. /**
  3170. * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
  3171. * @pf: board private structure
  3172. **/
  3173. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
  3174. {
  3175. struct i40e_hw *hw = &pf->hw;
  3176. u32 val;
  3177. val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
  3178. I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
  3179. (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
  3180. wr32(hw, I40E_PFINT_DYN_CTL0, val);
  3181. i40e_flush(hw);
  3182. }
  3183. /**
  3184. * i40e_msix_clean_rings - MSIX mode Interrupt Handler
  3185. * @irq: interrupt number
  3186. * @data: pointer to a q_vector
  3187. **/
  3188. static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
  3189. {
  3190. struct i40e_q_vector *q_vector = data;
  3191. if (!q_vector->tx.ring && !q_vector->rx.ring)
  3192. return IRQ_HANDLED;
  3193. napi_schedule_irqoff(&q_vector->napi);
  3194. return IRQ_HANDLED;
  3195. }
  3196. /**
  3197. * i40e_irq_affinity_notify - Callback for affinity changes
  3198. * @notify: context as to what irq was changed
  3199. * @mask: the new affinity mask
  3200. *
  3201. * This is a callback function used by the irq_set_affinity_notifier function
  3202. * so that we may register to receive changes to the irq affinity masks.
  3203. **/
  3204. static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify,
  3205. const cpumask_t *mask)
  3206. {
  3207. struct i40e_q_vector *q_vector =
  3208. container_of(notify, struct i40e_q_vector, affinity_notify);
  3209. cpumask_copy(&q_vector->affinity_mask, mask);
  3210. }
  3211. /**
  3212. * i40e_irq_affinity_release - Callback for affinity notifier release
  3213. * @ref: internal core kernel usage
  3214. *
  3215. * This is a callback function used by the irq_set_affinity_notifier function
  3216. * to inform the current notification subscriber that they will no longer
  3217. * receive notifications.
  3218. **/
  3219. static void i40e_irq_affinity_release(struct kref *ref) {}
  3220. /**
  3221. * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
  3222. * @vsi: the VSI being configured
  3223. * @basename: name for the vector
  3224. *
  3225. * Allocates MSI-X vectors and requests interrupts from the kernel.
  3226. **/
  3227. static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
  3228. {
  3229. int q_vectors = vsi->num_q_vectors;
  3230. struct i40e_pf *pf = vsi->back;
  3231. int base = vsi->base_vector;
  3232. int rx_int_idx = 0;
  3233. int tx_int_idx = 0;
  3234. int vector, err;
  3235. int irq_num;
  3236. int cpu;
  3237. for (vector = 0; vector < q_vectors; vector++) {
  3238. struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
  3239. irq_num = pf->msix_entries[base + vector].vector;
  3240. if (q_vector->tx.ring && q_vector->rx.ring) {
  3241. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3242. "%s-%s-%d", basename, "TxRx", rx_int_idx++);
  3243. tx_int_idx++;
  3244. } else if (q_vector->rx.ring) {
  3245. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3246. "%s-%s-%d", basename, "rx", rx_int_idx++);
  3247. } else if (q_vector->tx.ring) {
  3248. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3249. "%s-%s-%d", basename, "tx", tx_int_idx++);
  3250. } else {
  3251. /* skip this unused q_vector */
  3252. continue;
  3253. }
  3254. err = request_irq(irq_num,
  3255. vsi->irq_handler,
  3256. 0,
  3257. q_vector->name,
  3258. q_vector);
  3259. if (err) {
  3260. dev_info(&pf->pdev->dev,
  3261. "MSIX request_irq failed, error: %d\n", err);
  3262. goto free_queue_irqs;
  3263. }
  3264. /* register for affinity change notifications */
  3265. q_vector->affinity_notify.notify = i40e_irq_affinity_notify;
  3266. q_vector->affinity_notify.release = i40e_irq_affinity_release;
  3267. irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
  3268. /* Spread affinity hints out across online CPUs.
  3269. *
  3270. * get_cpu_mask returns a static constant mask with
  3271. * a permanent lifetime so it's ok to pass to
  3272. * irq_set_affinity_hint without making a copy.
  3273. */
  3274. cpu = cpumask_local_spread(q_vector->v_idx, -1);
  3275. irq_set_affinity_hint(irq_num, get_cpu_mask(cpu));
  3276. }
  3277. vsi->irqs_ready = true;
  3278. return 0;
  3279. free_queue_irqs:
  3280. while (vector) {
  3281. vector--;
  3282. irq_num = pf->msix_entries[base + vector].vector;
  3283. irq_set_affinity_notifier(irq_num, NULL);
  3284. irq_set_affinity_hint(irq_num, NULL);
  3285. free_irq(irq_num, &vsi->q_vectors[vector]);
  3286. }
  3287. return err;
  3288. }
  3289. /**
  3290. * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
  3291. * @vsi: the VSI being un-configured
  3292. **/
  3293. static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
  3294. {
  3295. struct i40e_pf *pf = vsi->back;
  3296. struct i40e_hw *hw = &pf->hw;
  3297. int base = vsi->base_vector;
  3298. int i;
  3299. /* disable interrupt causation from each queue */
  3300. for (i = 0; i < vsi->num_queue_pairs; i++) {
  3301. u32 val;
  3302. val = rd32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx));
  3303. val &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
  3304. wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), val);
  3305. val = rd32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx));
  3306. val &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
  3307. wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), val);
  3308. if (!i40e_enabled_xdp_vsi(vsi))
  3309. continue;
  3310. wr32(hw, I40E_QINT_TQCTL(vsi->xdp_rings[i]->reg_idx), 0);
  3311. }
  3312. /* disable each interrupt */
  3313. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3314. for (i = vsi->base_vector;
  3315. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  3316. wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
  3317. i40e_flush(hw);
  3318. for (i = 0; i < vsi->num_q_vectors; i++)
  3319. synchronize_irq(pf->msix_entries[i + base].vector);
  3320. } else {
  3321. /* Legacy and MSI mode - this stops all interrupt handling */
  3322. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  3323. wr32(hw, I40E_PFINT_DYN_CTL0, 0);
  3324. i40e_flush(hw);
  3325. synchronize_irq(pf->pdev->irq);
  3326. }
  3327. }
  3328. /**
  3329. * i40e_vsi_enable_irq - Enable IRQ for the given VSI
  3330. * @vsi: the VSI being configured
  3331. **/
  3332. static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
  3333. {
  3334. struct i40e_pf *pf = vsi->back;
  3335. int i;
  3336. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3337. for (i = 0; i < vsi->num_q_vectors; i++)
  3338. i40e_irq_dynamic_enable(vsi, i);
  3339. } else {
  3340. i40e_irq_dynamic_enable_icr0(pf);
  3341. }
  3342. i40e_flush(&pf->hw);
  3343. return 0;
  3344. }
  3345. /**
  3346. * i40e_free_misc_vector - Free the vector that handles non-queue events
  3347. * @pf: board private structure
  3348. **/
  3349. static void i40e_free_misc_vector(struct i40e_pf *pf)
  3350. {
  3351. /* Disable ICR 0 */
  3352. wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
  3353. i40e_flush(&pf->hw);
  3354. if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
  3355. synchronize_irq(pf->msix_entries[0].vector);
  3356. free_irq(pf->msix_entries[0].vector, pf);
  3357. clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state);
  3358. }
  3359. }
  3360. /**
  3361. * i40e_intr - MSI/Legacy and non-queue interrupt handler
  3362. * @irq: interrupt number
  3363. * @data: pointer to a q_vector
  3364. *
  3365. * This is the handler used for all MSI/Legacy interrupts, and deals
  3366. * with both queue and non-queue interrupts. This is also used in
  3367. * MSIX mode to handle the non-queue interrupts.
  3368. **/
  3369. static irqreturn_t i40e_intr(int irq, void *data)
  3370. {
  3371. struct i40e_pf *pf = (struct i40e_pf *)data;
  3372. struct i40e_hw *hw = &pf->hw;
  3373. irqreturn_t ret = IRQ_NONE;
  3374. u32 icr0, icr0_remaining;
  3375. u32 val, ena_mask;
  3376. icr0 = rd32(hw, I40E_PFINT_ICR0);
  3377. ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
  3378. /* if sharing a legacy IRQ, we might get called w/o an intr pending */
  3379. if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
  3380. goto enable_intr;
  3381. /* if interrupt but no bits showing, must be SWINT */
  3382. if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
  3383. (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
  3384. pf->sw_int_count++;
  3385. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  3386. (icr0 & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
  3387. ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3388. dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n");
  3389. set_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
  3390. }
  3391. /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
  3392. if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
  3393. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  3394. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3395. /* We do not have a way to disarm Queue causes while leaving
  3396. * interrupt enabled for all other causes, ideally
  3397. * interrupt should be disabled while we are in NAPI but
  3398. * this is not a performance path and napi_schedule()
  3399. * can deal with rescheduling.
  3400. */
  3401. if (!test_bit(__I40E_DOWN, pf->state))
  3402. napi_schedule_irqoff(&q_vector->napi);
  3403. }
  3404. if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
  3405. ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3406. set_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
  3407. i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
  3408. }
  3409. if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
  3410. ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  3411. set_bit(__I40E_MDD_EVENT_PENDING, pf->state);
  3412. }
  3413. if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
  3414. ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
  3415. set_bit(__I40E_VFLR_EVENT_PENDING, pf->state);
  3416. }
  3417. if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
  3418. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  3419. set_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
  3420. ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
  3421. val = rd32(hw, I40E_GLGEN_RSTAT);
  3422. val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
  3423. >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
  3424. if (val == I40E_RESET_CORER) {
  3425. pf->corer_count++;
  3426. } else if (val == I40E_RESET_GLOBR) {
  3427. pf->globr_count++;
  3428. } else if (val == I40E_RESET_EMPR) {
  3429. pf->empr_count++;
  3430. set_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state);
  3431. }
  3432. }
  3433. if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
  3434. icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
  3435. dev_info(&pf->pdev->dev, "HMC error interrupt\n");
  3436. dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
  3437. rd32(hw, I40E_PFHMC_ERRORINFO),
  3438. rd32(hw, I40E_PFHMC_ERRORDATA));
  3439. }
  3440. if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
  3441. u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
  3442. if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
  3443. icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3444. i40e_ptp_tx_hwtstamp(pf);
  3445. }
  3446. }
  3447. /* If a critical error is pending we have no choice but to reset the
  3448. * device.
  3449. * Report and mask out any remaining unexpected interrupts.
  3450. */
  3451. icr0_remaining = icr0 & ena_mask;
  3452. if (icr0_remaining) {
  3453. dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
  3454. icr0_remaining);
  3455. if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
  3456. (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
  3457. (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
  3458. dev_info(&pf->pdev->dev, "device will be reset\n");
  3459. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  3460. i40e_service_event_schedule(pf);
  3461. }
  3462. ena_mask &= ~icr0_remaining;
  3463. }
  3464. ret = IRQ_HANDLED;
  3465. enable_intr:
  3466. /* re-enable interrupt causes */
  3467. wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
  3468. if (!test_bit(__I40E_DOWN, pf->state)) {
  3469. i40e_service_event_schedule(pf);
  3470. i40e_irq_dynamic_enable_icr0(pf);
  3471. }
  3472. return ret;
  3473. }
  3474. /**
  3475. * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
  3476. * @tx_ring: tx ring to clean
  3477. * @budget: how many cleans we're allowed
  3478. *
  3479. * Returns true if there's any budget left (e.g. the clean is finished)
  3480. **/
  3481. static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
  3482. {
  3483. struct i40e_vsi *vsi = tx_ring->vsi;
  3484. u16 i = tx_ring->next_to_clean;
  3485. struct i40e_tx_buffer *tx_buf;
  3486. struct i40e_tx_desc *tx_desc;
  3487. tx_buf = &tx_ring->tx_bi[i];
  3488. tx_desc = I40E_TX_DESC(tx_ring, i);
  3489. i -= tx_ring->count;
  3490. do {
  3491. struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
  3492. /* if next_to_watch is not set then there is no work pending */
  3493. if (!eop_desc)
  3494. break;
  3495. /* prevent any other reads prior to eop_desc */
  3496. smp_rmb();
  3497. /* if the descriptor isn't done, no work yet to do */
  3498. if (!(eop_desc->cmd_type_offset_bsz &
  3499. cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
  3500. break;
  3501. /* clear next_to_watch to prevent false hangs */
  3502. tx_buf->next_to_watch = NULL;
  3503. tx_desc->buffer_addr = 0;
  3504. tx_desc->cmd_type_offset_bsz = 0;
  3505. /* move past filter desc */
  3506. tx_buf++;
  3507. tx_desc++;
  3508. i++;
  3509. if (unlikely(!i)) {
  3510. i -= tx_ring->count;
  3511. tx_buf = tx_ring->tx_bi;
  3512. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3513. }
  3514. /* unmap skb header data */
  3515. dma_unmap_single(tx_ring->dev,
  3516. dma_unmap_addr(tx_buf, dma),
  3517. dma_unmap_len(tx_buf, len),
  3518. DMA_TO_DEVICE);
  3519. if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
  3520. kfree(tx_buf->raw_buf);
  3521. tx_buf->raw_buf = NULL;
  3522. tx_buf->tx_flags = 0;
  3523. tx_buf->next_to_watch = NULL;
  3524. dma_unmap_len_set(tx_buf, len, 0);
  3525. tx_desc->buffer_addr = 0;
  3526. tx_desc->cmd_type_offset_bsz = 0;
  3527. /* move us past the eop_desc for start of next FD desc */
  3528. tx_buf++;
  3529. tx_desc++;
  3530. i++;
  3531. if (unlikely(!i)) {
  3532. i -= tx_ring->count;
  3533. tx_buf = tx_ring->tx_bi;
  3534. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3535. }
  3536. /* update budget accounting */
  3537. budget--;
  3538. } while (likely(budget));
  3539. i += tx_ring->count;
  3540. tx_ring->next_to_clean = i;
  3541. if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
  3542. i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
  3543. return budget > 0;
  3544. }
  3545. /**
  3546. * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
  3547. * @irq: interrupt number
  3548. * @data: pointer to a q_vector
  3549. **/
  3550. static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
  3551. {
  3552. struct i40e_q_vector *q_vector = data;
  3553. struct i40e_vsi *vsi;
  3554. if (!q_vector->tx.ring)
  3555. return IRQ_HANDLED;
  3556. vsi = q_vector->tx.ring->vsi;
  3557. i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
  3558. return IRQ_HANDLED;
  3559. }
  3560. /**
  3561. * i40e_map_vector_to_qp - Assigns the queue pair to the vector
  3562. * @vsi: the VSI being configured
  3563. * @v_idx: vector index
  3564. * @qp_idx: queue pair index
  3565. **/
  3566. static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
  3567. {
  3568. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3569. struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
  3570. struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
  3571. tx_ring->q_vector = q_vector;
  3572. tx_ring->next = q_vector->tx.ring;
  3573. q_vector->tx.ring = tx_ring;
  3574. q_vector->tx.count++;
  3575. /* Place XDP Tx ring in the same q_vector ring list as regular Tx */
  3576. if (i40e_enabled_xdp_vsi(vsi)) {
  3577. struct i40e_ring *xdp_ring = vsi->xdp_rings[qp_idx];
  3578. xdp_ring->q_vector = q_vector;
  3579. xdp_ring->next = q_vector->tx.ring;
  3580. q_vector->tx.ring = xdp_ring;
  3581. q_vector->tx.count++;
  3582. }
  3583. rx_ring->q_vector = q_vector;
  3584. rx_ring->next = q_vector->rx.ring;
  3585. q_vector->rx.ring = rx_ring;
  3586. q_vector->rx.count++;
  3587. }
  3588. /**
  3589. * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
  3590. * @vsi: the VSI being configured
  3591. *
  3592. * This function maps descriptor rings to the queue-specific vectors
  3593. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  3594. * one vector per queue pair, but on a constrained vector budget, we
  3595. * group the queue pairs as "efficiently" as possible.
  3596. **/
  3597. static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
  3598. {
  3599. int qp_remaining = vsi->num_queue_pairs;
  3600. int q_vectors = vsi->num_q_vectors;
  3601. int num_ringpairs;
  3602. int v_start = 0;
  3603. int qp_idx = 0;
  3604. /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
  3605. * group them so there are multiple queues per vector.
  3606. * It is also important to go through all the vectors available to be
  3607. * sure that if we don't use all the vectors, that the remaining vectors
  3608. * are cleared. This is especially important when decreasing the
  3609. * number of queues in use.
  3610. */
  3611. for (; v_start < q_vectors; v_start++) {
  3612. struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
  3613. num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
  3614. q_vector->num_ringpairs = num_ringpairs;
  3615. q_vector->rx.count = 0;
  3616. q_vector->tx.count = 0;
  3617. q_vector->rx.ring = NULL;
  3618. q_vector->tx.ring = NULL;
  3619. while (num_ringpairs--) {
  3620. i40e_map_vector_to_qp(vsi, v_start, qp_idx);
  3621. qp_idx++;
  3622. qp_remaining--;
  3623. }
  3624. }
  3625. }
  3626. /**
  3627. * i40e_vsi_request_irq - Request IRQ from the OS
  3628. * @vsi: the VSI being configured
  3629. * @basename: name for the vector
  3630. **/
  3631. static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
  3632. {
  3633. struct i40e_pf *pf = vsi->back;
  3634. int err;
  3635. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3636. err = i40e_vsi_request_irq_msix(vsi, basename);
  3637. else if (pf->flags & I40E_FLAG_MSI_ENABLED)
  3638. err = request_irq(pf->pdev->irq, i40e_intr, 0,
  3639. pf->int_name, pf);
  3640. else
  3641. err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
  3642. pf->int_name, pf);
  3643. if (err)
  3644. dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
  3645. return err;
  3646. }
  3647. #ifdef CONFIG_NET_POLL_CONTROLLER
  3648. /**
  3649. * i40e_netpoll - A Polling 'interrupt' handler
  3650. * @netdev: network interface device structure
  3651. *
  3652. * This is used by netconsole to send skbs without having to re-enable
  3653. * interrupts. It's not called while the normal interrupt routine is executing.
  3654. **/
  3655. static void i40e_netpoll(struct net_device *netdev)
  3656. {
  3657. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3658. struct i40e_vsi *vsi = np->vsi;
  3659. struct i40e_pf *pf = vsi->back;
  3660. int i;
  3661. /* if interface is down do nothing */
  3662. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  3663. return;
  3664. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3665. for (i = 0; i < vsi->num_q_vectors; i++)
  3666. i40e_msix_clean_rings(0, vsi->q_vectors[i]);
  3667. } else {
  3668. i40e_intr(pf->pdev->irq, netdev);
  3669. }
  3670. }
  3671. #endif
  3672. #define I40E_QTX_ENA_WAIT_COUNT 50
  3673. /**
  3674. * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
  3675. * @pf: the PF being configured
  3676. * @pf_q: the PF queue
  3677. * @enable: enable or disable state of the queue
  3678. *
  3679. * This routine will wait for the given Tx queue of the PF to reach the
  3680. * enabled or disabled state.
  3681. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3682. * multiple retries; else will return 0 in case of success.
  3683. **/
  3684. static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3685. {
  3686. int i;
  3687. u32 tx_reg;
  3688. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3689. tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
  3690. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3691. break;
  3692. usleep_range(10, 20);
  3693. }
  3694. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3695. return -ETIMEDOUT;
  3696. return 0;
  3697. }
  3698. /**
  3699. * i40e_control_tx_q - Start or stop a particular Tx queue
  3700. * @pf: the PF structure
  3701. * @pf_q: the PF queue to configure
  3702. * @enable: start or stop the queue
  3703. *
  3704. * This function enables or disables a single queue. Note that any delay
  3705. * required after the operation is expected to be handled by the caller of
  3706. * this function.
  3707. **/
  3708. static void i40e_control_tx_q(struct i40e_pf *pf, int pf_q, bool enable)
  3709. {
  3710. struct i40e_hw *hw = &pf->hw;
  3711. u32 tx_reg;
  3712. int i;
  3713. /* warn the TX unit of coming changes */
  3714. i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
  3715. if (!enable)
  3716. usleep_range(10, 20);
  3717. for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
  3718. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  3719. if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
  3720. ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
  3721. break;
  3722. usleep_range(1000, 2000);
  3723. }
  3724. /* Skip if the queue is already in the requested state */
  3725. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3726. return;
  3727. /* turn on/off the queue */
  3728. if (enable) {
  3729. wr32(hw, I40E_QTX_HEAD(pf_q), 0);
  3730. tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
  3731. } else {
  3732. tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
  3733. }
  3734. wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
  3735. }
  3736. /**
  3737. * i40e_control_wait_tx_q - Start/stop Tx queue and wait for completion
  3738. * @seid: VSI SEID
  3739. * @pf: the PF structure
  3740. * @pf_q: the PF queue to configure
  3741. * @is_xdp: true if the queue is used for XDP
  3742. * @enable: start or stop the queue
  3743. **/
  3744. static int i40e_control_wait_tx_q(int seid, struct i40e_pf *pf, int pf_q,
  3745. bool is_xdp, bool enable)
  3746. {
  3747. int ret;
  3748. i40e_control_tx_q(pf, pf_q, enable);
  3749. /* wait for the change to finish */
  3750. ret = i40e_pf_txq_wait(pf, pf_q, enable);
  3751. if (ret) {
  3752. dev_info(&pf->pdev->dev,
  3753. "VSI seid %d %sTx ring %d %sable timeout\n",
  3754. seid, (is_xdp ? "XDP " : ""), pf_q,
  3755. (enable ? "en" : "dis"));
  3756. }
  3757. return ret;
  3758. }
  3759. /**
  3760. * i40e_vsi_control_tx - Start or stop a VSI's rings
  3761. * @vsi: the VSI being configured
  3762. * @enable: start or stop the rings
  3763. **/
  3764. static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
  3765. {
  3766. struct i40e_pf *pf = vsi->back;
  3767. int i, pf_q, ret = 0;
  3768. pf_q = vsi->base_queue;
  3769. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3770. ret = i40e_control_wait_tx_q(vsi->seid, pf,
  3771. pf_q,
  3772. false /*is xdp*/, enable);
  3773. if (ret)
  3774. break;
  3775. if (!i40e_enabled_xdp_vsi(vsi))
  3776. continue;
  3777. ret = i40e_control_wait_tx_q(vsi->seid, pf,
  3778. pf_q + vsi->alloc_queue_pairs,
  3779. true /*is xdp*/, enable);
  3780. if (ret)
  3781. break;
  3782. }
  3783. return ret;
  3784. }
  3785. /**
  3786. * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
  3787. * @pf: the PF being configured
  3788. * @pf_q: the PF queue
  3789. * @enable: enable or disable state of the queue
  3790. *
  3791. * This routine will wait for the given Rx queue of the PF to reach the
  3792. * enabled or disabled state.
  3793. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3794. * multiple retries; else will return 0 in case of success.
  3795. **/
  3796. static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3797. {
  3798. int i;
  3799. u32 rx_reg;
  3800. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3801. rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
  3802. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3803. break;
  3804. usleep_range(10, 20);
  3805. }
  3806. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3807. return -ETIMEDOUT;
  3808. return 0;
  3809. }
  3810. /**
  3811. * i40e_control_rx_q - Start or stop a particular Rx queue
  3812. * @pf: the PF structure
  3813. * @pf_q: the PF queue to configure
  3814. * @enable: start or stop the queue
  3815. *
  3816. * This function enables or disables a single queue. Note that any delay
  3817. * required after the operation is expected to be handled by the caller of
  3818. * this function.
  3819. **/
  3820. static void i40e_control_rx_q(struct i40e_pf *pf, int pf_q, bool enable)
  3821. {
  3822. struct i40e_hw *hw = &pf->hw;
  3823. u32 rx_reg;
  3824. int i;
  3825. for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
  3826. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  3827. if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
  3828. ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
  3829. break;
  3830. usleep_range(1000, 2000);
  3831. }
  3832. /* Skip if the queue is already in the requested state */
  3833. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3834. return;
  3835. /* turn on/off the queue */
  3836. if (enable)
  3837. rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
  3838. else
  3839. rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
  3840. wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
  3841. }
  3842. /**
  3843. * i40e_vsi_control_rx - Start or stop a VSI's rings
  3844. * @vsi: the VSI being configured
  3845. * @enable: start or stop the rings
  3846. **/
  3847. static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
  3848. {
  3849. struct i40e_pf *pf = vsi->back;
  3850. int i, pf_q, ret = 0;
  3851. pf_q = vsi->base_queue;
  3852. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3853. i40e_control_rx_q(pf, pf_q, enable);
  3854. /* wait for the change to finish */
  3855. ret = i40e_pf_rxq_wait(pf, pf_q, enable);
  3856. if (ret) {
  3857. dev_info(&pf->pdev->dev,
  3858. "VSI seid %d Rx ring %d %sable timeout\n",
  3859. vsi->seid, pf_q, (enable ? "en" : "dis"));
  3860. break;
  3861. }
  3862. }
  3863. /* Due to HW errata, on Rx disable only, the register can indicate done
  3864. * before it really is. Needs 50ms to be sure
  3865. */
  3866. if (!enable)
  3867. mdelay(50);
  3868. return ret;
  3869. }
  3870. /**
  3871. * i40e_vsi_start_rings - Start a VSI's rings
  3872. * @vsi: the VSI being configured
  3873. **/
  3874. int i40e_vsi_start_rings(struct i40e_vsi *vsi)
  3875. {
  3876. int ret = 0;
  3877. /* do rx first for enable and last for disable */
  3878. ret = i40e_vsi_control_rx(vsi, true);
  3879. if (ret)
  3880. return ret;
  3881. ret = i40e_vsi_control_tx(vsi, true);
  3882. return ret;
  3883. }
  3884. /**
  3885. * i40e_vsi_stop_rings - Stop a VSI's rings
  3886. * @vsi: the VSI being configured
  3887. **/
  3888. void i40e_vsi_stop_rings(struct i40e_vsi *vsi)
  3889. {
  3890. /* When port TX is suspended, don't wait */
  3891. if (test_bit(__I40E_PORT_SUSPENDED, vsi->back->state))
  3892. return i40e_vsi_stop_rings_no_wait(vsi);
  3893. /* do rx first for enable and last for disable
  3894. * Ignore return value, we need to shutdown whatever we can
  3895. */
  3896. i40e_vsi_control_tx(vsi, false);
  3897. i40e_vsi_control_rx(vsi, false);
  3898. }
  3899. /**
  3900. * i40e_vsi_stop_rings_no_wait - Stop a VSI's rings and do not delay
  3901. * @vsi: the VSI being shutdown
  3902. *
  3903. * This function stops all the rings for a VSI but does not delay to verify
  3904. * that rings have been disabled. It is expected that the caller is shutting
  3905. * down multiple VSIs at once and will delay together for all the VSIs after
  3906. * initiating the shutdown. This is particularly useful for shutting down lots
  3907. * of VFs together. Otherwise, a large delay can be incurred while configuring
  3908. * each VSI in serial.
  3909. **/
  3910. void i40e_vsi_stop_rings_no_wait(struct i40e_vsi *vsi)
  3911. {
  3912. struct i40e_pf *pf = vsi->back;
  3913. int i, pf_q;
  3914. pf_q = vsi->base_queue;
  3915. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3916. i40e_control_tx_q(pf, pf_q, false);
  3917. i40e_control_rx_q(pf, pf_q, false);
  3918. }
  3919. }
  3920. /**
  3921. * i40e_vsi_free_irq - Free the irq association with the OS
  3922. * @vsi: the VSI being configured
  3923. **/
  3924. static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
  3925. {
  3926. struct i40e_pf *pf = vsi->back;
  3927. struct i40e_hw *hw = &pf->hw;
  3928. int base = vsi->base_vector;
  3929. u32 val, qp;
  3930. int i;
  3931. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3932. if (!vsi->q_vectors)
  3933. return;
  3934. if (!vsi->irqs_ready)
  3935. return;
  3936. vsi->irqs_ready = false;
  3937. for (i = 0; i < vsi->num_q_vectors; i++) {
  3938. int irq_num;
  3939. u16 vector;
  3940. vector = i + base;
  3941. irq_num = pf->msix_entries[vector].vector;
  3942. /* free only the irqs that were actually requested */
  3943. if (!vsi->q_vectors[i] ||
  3944. !vsi->q_vectors[i]->num_ringpairs)
  3945. continue;
  3946. /* clear the affinity notifier in the IRQ descriptor */
  3947. irq_set_affinity_notifier(irq_num, NULL);
  3948. /* remove our suggested affinity mask for this IRQ */
  3949. irq_set_affinity_hint(irq_num, NULL);
  3950. synchronize_irq(irq_num);
  3951. free_irq(irq_num, vsi->q_vectors[i]);
  3952. /* Tear down the interrupt queue link list
  3953. *
  3954. * We know that they come in pairs and always
  3955. * the Rx first, then the Tx. To clear the
  3956. * link list, stick the EOL value into the
  3957. * next_q field of the registers.
  3958. */
  3959. val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
  3960. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3961. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3962. val |= I40E_QUEUE_END_OF_LIST
  3963. << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3964. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
  3965. while (qp != I40E_QUEUE_END_OF_LIST) {
  3966. u32 next;
  3967. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3968. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3969. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3970. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3971. I40E_QINT_RQCTL_INTEVENT_MASK);
  3972. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3973. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3974. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3975. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3976. next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
  3977. >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
  3978. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3979. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3980. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3981. I40E_QINT_TQCTL_INTEVENT_MASK);
  3982. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3983. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3984. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3985. qp = next;
  3986. }
  3987. }
  3988. } else {
  3989. free_irq(pf->pdev->irq, pf);
  3990. val = rd32(hw, I40E_PFINT_LNKLST0);
  3991. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3992. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3993. val |= I40E_QUEUE_END_OF_LIST
  3994. << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  3995. wr32(hw, I40E_PFINT_LNKLST0, val);
  3996. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3997. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3998. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3999. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  4000. I40E_QINT_RQCTL_INTEVENT_MASK);
  4001. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  4002. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  4003. wr32(hw, I40E_QINT_RQCTL(qp), val);
  4004. val = rd32(hw, I40E_QINT_TQCTL(qp));
  4005. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  4006. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  4007. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  4008. I40E_QINT_TQCTL_INTEVENT_MASK);
  4009. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  4010. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  4011. wr32(hw, I40E_QINT_TQCTL(qp), val);
  4012. }
  4013. }
  4014. /**
  4015. * i40e_free_q_vector - Free memory allocated for specific interrupt vector
  4016. * @vsi: the VSI being configured
  4017. * @v_idx: Index of vector to be freed
  4018. *
  4019. * This function frees the memory allocated to the q_vector. In addition if
  4020. * NAPI is enabled it will delete any references to the NAPI struct prior
  4021. * to freeing the q_vector.
  4022. **/
  4023. static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
  4024. {
  4025. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  4026. struct i40e_ring *ring;
  4027. if (!q_vector)
  4028. return;
  4029. /* disassociate q_vector from rings */
  4030. i40e_for_each_ring(ring, q_vector->tx)
  4031. ring->q_vector = NULL;
  4032. i40e_for_each_ring(ring, q_vector->rx)
  4033. ring->q_vector = NULL;
  4034. /* only VSI w/ an associated netdev is set up w/ NAPI */
  4035. if (vsi->netdev)
  4036. netif_napi_del(&q_vector->napi);
  4037. vsi->q_vectors[v_idx] = NULL;
  4038. kfree_rcu(q_vector, rcu);
  4039. }
  4040. /**
  4041. * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
  4042. * @vsi: the VSI being un-configured
  4043. *
  4044. * This frees the memory allocated to the q_vectors and
  4045. * deletes references to the NAPI struct.
  4046. **/
  4047. static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
  4048. {
  4049. int v_idx;
  4050. for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
  4051. i40e_free_q_vector(vsi, v_idx);
  4052. }
  4053. /**
  4054. * i40e_reset_interrupt_capability - Disable interrupt setup in OS
  4055. * @pf: board private structure
  4056. **/
  4057. static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
  4058. {
  4059. /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
  4060. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  4061. pci_disable_msix(pf->pdev);
  4062. kfree(pf->msix_entries);
  4063. pf->msix_entries = NULL;
  4064. kfree(pf->irq_pile);
  4065. pf->irq_pile = NULL;
  4066. } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
  4067. pci_disable_msi(pf->pdev);
  4068. }
  4069. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  4070. }
  4071. /**
  4072. * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
  4073. * @pf: board private structure
  4074. *
  4075. * We go through and clear interrupt specific resources and reset the structure
  4076. * to pre-load conditions
  4077. **/
  4078. static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
  4079. {
  4080. int i;
  4081. i40e_free_misc_vector(pf);
  4082. i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
  4083. I40E_IWARP_IRQ_PILE_ID);
  4084. i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
  4085. for (i = 0; i < pf->num_alloc_vsi; i++)
  4086. if (pf->vsi[i])
  4087. i40e_vsi_free_q_vectors(pf->vsi[i]);
  4088. i40e_reset_interrupt_capability(pf);
  4089. }
  4090. /**
  4091. * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
  4092. * @vsi: the VSI being configured
  4093. **/
  4094. static void i40e_napi_enable_all(struct i40e_vsi *vsi)
  4095. {
  4096. int q_idx;
  4097. if (!vsi->netdev)
  4098. return;
  4099. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
  4100. struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
  4101. if (q_vector->rx.ring || q_vector->tx.ring)
  4102. napi_enable(&q_vector->napi);
  4103. }
  4104. }
  4105. /**
  4106. * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
  4107. * @vsi: the VSI being configured
  4108. **/
  4109. static void i40e_napi_disable_all(struct i40e_vsi *vsi)
  4110. {
  4111. int q_idx;
  4112. if (!vsi->netdev)
  4113. return;
  4114. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
  4115. struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
  4116. if (q_vector->rx.ring || q_vector->tx.ring)
  4117. napi_disable(&q_vector->napi);
  4118. }
  4119. }
  4120. /**
  4121. * i40e_vsi_close - Shut down a VSI
  4122. * @vsi: the vsi to be quelled
  4123. **/
  4124. static void i40e_vsi_close(struct i40e_vsi *vsi)
  4125. {
  4126. struct i40e_pf *pf = vsi->back;
  4127. if (!test_and_set_bit(__I40E_VSI_DOWN, vsi->state))
  4128. i40e_down(vsi);
  4129. i40e_vsi_free_irq(vsi);
  4130. i40e_vsi_free_tx_resources(vsi);
  4131. i40e_vsi_free_rx_resources(vsi);
  4132. vsi->current_netdev_flags = 0;
  4133. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  4134. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  4135. pf->flags |= I40E_FLAG_CLIENT_RESET;
  4136. }
  4137. /**
  4138. * i40e_quiesce_vsi - Pause a given VSI
  4139. * @vsi: the VSI being paused
  4140. **/
  4141. static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
  4142. {
  4143. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  4144. return;
  4145. set_bit(__I40E_VSI_NEEDS_RESTART, vsi->state);
  4146. if (vsi->netdev && netif_running(vsi->netdev))
  4147. vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
  4148. else
  4149. i40e_vsi_close(vsi);
  4150. }
  4151. /**
  4152. * i40e_unquiesce_vsi - Resume a given VSI
  4153. * @vsi: the VSI being resumed
  4154. **/
  4155. static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
  4156. {
  4157. if (!test_and_clear_bit(__I40E_VSI_NEEDS_RESTART, vsi->state))
  4158. return;
  4159. if (vsi->netdev && netif_running(vsi->netdev))
  4160. vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
  4161. else
  4162. i40e_vsi_open(vsi); /* this clears the DOWN bit */
  4163. }
  4164. /**
  4165. * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
  4166. * @pf: the PF
  4167. **/
  4168. static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
  4169. {
  4170. int v;
  4171. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4172. if (pf->vsi[v])
  4173. i40e_quiesce_vsi(pf->vsi[v]);
  4174. }
  4175. }
  4176. /**
  4177. * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
  4178. * @pf: the PF
  4179. **/
  4180. static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
  4181. {
  4182. int v;
  4183. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4184. if (pf->vsi[v])
  4185. i40e_unquiesce_vsi(pf->vsi[v]);
  4186. }
  4187. }
  4188. /**
  4189. * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
  4190. * @vsi: the VSI being configured
  4191. *
  4192. * Wait until all queues on a given VSI have been disabled.
  4193. **/
  4194. int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
  4195. {
  4196. struct i40e_pf *pf = vsi->back;
  4197. int i, pf_q, ret;
  4198. pf_q = vsi->base_queue;
  4199. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  4200. /* Check and wait for the Tx queue */
  4201. ret = i40e_pf_txq_wait(pf, pf_q, false);
  4202. if (ret) {
  4203. dev_info(&pf->pdev->dev,
  4204. "VSI seid %d Tx ring %d disable timeout\n",
  4205. vsi->seid, pf_q);
  4206. return ret;
  4207. }
  4208. if (!i40e_enabled_xdp_vsi(vsi))
  4209. goto wait_rx;
  4210. /* Check and wait for the XDP Tx queue */
  4211. ret = i40e_pf_txq_wait(pf, pf_q + vsi->alloc_queue_pairs,
  4212. false);
  4213. if (ret) {
  4214. dev_info(&pf->pdev->dev,
  4215. "VSI seid %d XDP Tx ring %d disable timeout\n",
  4216. vsi->seid, pf_q);
  4217. return ret;
  4218. }
  4219. wait_rx:
  4220. /* Check and wait for the Rx queue */
  4221. ret = i40e_pf_rxq_wait(pf, pf_q, false);
  4222. if (ret) {
  4223. dev_info(&pf->pdev->dev,
  4224. "VSI seid %d Rx ring %d disable timeout\n",
  4225. vsi->seid, pf_q);
  4226. return ret;
  4227. }
  4228. }
  4229. return 0;
  4230. }
  4231. #ifdef CONFIG_I40E_DCB
  4232. /**
  4233. * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
  4234. * @pf: the PF
  4235. *
  4236. * This function waits for the queues to be in disabled state for all the
  4237. * VSIs that are managed by this PF.
  4238. **/
  4239. static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
  4240. {
  4241. int v, ret = 0;
  4242. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  4243. if (pf->vsi[v]) {
  4244. ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
  4245. if (ret)
  4246. break;
  4247. }
  4248. }
  4249. return ret;
  4250. }
  4251. #endif
  4252. /**
  4253. * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
  4254. * @q_idx: TX queue number
  4255. * @vsi: Pointer to VSI struct
  4256. *
  4257. * This function checks specified queue for given VSI. Detects hung condition.
  4258. * We proactively detect hung TX queues by checking if interrupts are disabled
  4259. * but there are pending descriptors. If it appears hung, attempt to recover
  4260. * by triggering a SW interrupt.
  4261. **/
  4262. static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi)
  4263. {
  4264. struct i40e_ring *tx_ring = NULL;
  4265. struct i40e_pf *pf;
  4266. u32 val, tx_pending;
  4267. int i;
  4268. pf = vsi->back;
  4269. /* now that we have an index, find the tx_ring struct */
  4270. for (i = 0; i < vsi->num_queue_pairs; i++) {
  4271. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
  4272. if (q_idx == vsi->tx_rings[i]->queue_index) {
  4273. tx_ring = vsi->tx_rings[i];
  4274. break;
  4275. }
  4276. }
  4277. }
  4278. if (!tx_ring)
  4279. return;
  4280. /* Read interrupt register */
  4281. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  4282. val = rd32(&pf->hw,
  4283. I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
  4284. tx_ring->vsi->base_vector - 1));
  4285. else
  4286. val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
  4287. tx_pending = i40e_get_tx_pending(tx_ring);
  4288. /* Interrupts are disabled and TX pending is non-zero,
  4289. * trigger the SW interrupt (don't wait). Worst case
  4290. * there will be one extra interrupt which may result
  4291. * into not cleaning any queues because queues are cleaned.
  4292. */
  4293. if (tx_pending && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK)))
  4294. i40e_force_wb(vsi, tx_ring->q_vector);
  4295. }
  4296. /**
  4297. * i40e_detect_recover_hung - Function to detect and recover hung_queues
  4298. * @pf: pointer to PF struct
  4299. *
  4300. * LAN VSI has netdev and netdev has TX queues. This function is to check
  4301. * each of those TX queues if they are hung, trigger recovery by issuing
  4302. * SW interrupt.
  4303. **/
  4304. static void i40e_detect_recover_hung(struct i40e_pf *pf)
  4305. {
  4306. struct net_device *netdev;
  4307. struct i40e_vsi *vsi;
  4308. unsigned int i;
  4309. /* Only for LAN VSI */
  4310. vsi = pf->vsi[pf->lan_vsi];
  4311. if (!vsi)
  4312. return;
  4313. /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
  4314. if (test_bit(__I40E_VSI_DOWN, vsi->back->state) ||
  4315. test_bit(__I40E_RESET_RECOVERY_PENDING, vsi->back->state))
  4316. return;
  4317. /* Make sure type is MAIN VSI */
  4318. if (vsi->type != I40E_VSI_MAIN)
  4319. return;
  4320. netdev = vsi->netdev;
  4321. if (!netdev)
  4322. return;
  4323. /* Bail out if netif_carrier is not OK */
  4324. if (!netif_carrier_ok(netdev))
  4325. return;
  4326. /* Go thru' TX queues for netdev */
  4327. for (i = 0; i < netdev->num_tx_queues; i++) {
  4328. struct netdev_queue *q;
  4329. q = netdev_get_tx_queue(netdev, i);
  4330. if (q)
  4331. i40e_detect_recover_hung_queue(i, vsi);
  4332. }
  4333. }
  4334. /**
  4335. * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
  4336. * @pf: pointer to PF
  4337. *
  4338. * Get TC map for ISCSI PF type that will include iSCSI TC
  4339. * and LAN TC.
  4340. **/
  4341. static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
  4342. {
  4343. struct i40e_dcb_app_priority_table app;
  4344. struct i40e_hw *hw = &pf->hw;
  4345. u8 enabled_tc = 1; /* TC0 is always enabled */
  4346. u8 tc, i;
  4347. /* Get the iSCSI APP TLV */
  4348. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4349. for (i = 0; i < dcbcfg->numapps; i++) {
  4350. app = dcbcfg->app[i];
  4351. if (app.selector == I40E_APP_SEL_TCPIP &&
  4352. app.protocolid == I40E_APP_PROTOID_ISCSI) {
  4353. tc = dcbcfg->etscfg.prioritytable[app.priority];
  4354. enabled_tc |= BIT(tc);
  4355. break;
  4356. }
  4357. }
  4358. return enabled_tc;
  4359. }
  4360. /**
  4361. * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
  4362. * @dcbcfg: the corresponding DCBx configuration structure
  4363. *
  4364. * Return the number of TCs from given DCBx configuration
  4365. **/
  4366. static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
  4367. {
  4368. int i, tc_unused = 0;
  4369. u8 num_tc = 0;
  4370. u8 ret = 0;
  4371. /* Scan the ETS Config Priority Table to find
  4372. * traffic class enabled for a given priority
  4373. * and create a bitmask of enabled TCs
  4374. */
  4375. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
  4376. num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
  4377. /* Now scan the bitmask to check for
  4378. * contiguous TCs starting with TC0
  4379. */
  4380. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4381. if (num_tc & BIT(i)) {
  4382. if (!tc_unused) {
  4383. ret++;
  4384. } else {
  4385. pr_err("Non-contiguous TC - Disabling DCB\n");
  4386. return 1;
  4387. }
  4388. } else {
  4389. tc_unused = 1;
  4390. }
  4391. }
  4392. /* There is always at least TC0 */
  4393. if (!ret)
  4394. ret = 1;
  4395. return ret;
  4396. }
  4397. /**
  4398. * i40e_dcb_get_enabled_tc - Get enabled traffic classes
  4399. * @dcbcfg: the corresponding DCBx configuration structure
  4400. *
  4401. * Query the current DCB configuration and return the number of
  4402. * traffic classes enabled from the given DCBX config
  4403. **/
  4404. static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
  4405. {
  4406. u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
  4407. u8 enabled_tc = 1;
  4408. u8 i;
  4409. for (i = 0; i < num_tc; i++)
  4410. enabled_tc |= BIT(i);
  4411. return enabled_tc;
  4412. }
  4413. /**
  4414. * i40e_mqprio_get_enabled_tc - Get enabled traffic classes
  4415. * @pf: PF being queried
  4416. *
  4417. * Query the current MQPRIO configuration and return the number of
  4418. * traffic classes enabled.
  4419. **/
  4420. static u8 i40e_mqprio_get_enabled_tc(struct i40e_pf *pf)
  4421. {
  4422. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  4423. u8 num_tc = vsi->mqprio_qopt.qopt.num_tc;
  4424. u8 enabled_tc = 1, i;
  4425. for (i = 1; i < num_tc; i++)
  4426. enabled_tc |= BIT(i);
  4427. return enabled_tc;
  4428. }
  4429. /**
  4430. * i40e_pf_get_num_tc - Get enabled traffic classes for PF
  4431. * @pf: PF being queried
  4432. *
  4433. * Return number of traffic classes enabled for the given PF
  4434. **/
  4435. static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
  4436. {
  4437. struct i40e_hw *hw = &pf->hw;
  4438. u8 i, enabled_tc = 1;
  4439. u8 num_tc = 0;
  4440. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4441. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4442. return pf->vsi[pf->lan_vsi]->mqprio_qopt.qopt.num_tc;
  4443. /* If neither MQPRIO nor DCB is enabled, then always use single TC */
  4444. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4445. return 1;
  4446. /* SFP mode will be enabled for all TCs on port */
  4447. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4448. return i40e_dcb_get_num_tc(dcbcfg);
  4449. /* MFP mode return count of enabled TCs for this PF */
  4450. if (pf->hw.func_caps.iscsi)
  4451. enabled_tc = i40e_get_iscsi_tc_map(pf);
  4452. else
  4453. return 1; /* Only TC0 */
  4454. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4455. if (enabled_tc & BIT(i))
  4456. num_tc++;
  4457. }
  4458. return num_tc;
  4459. }
  4460. /**
  4461. * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
  4462. * @pf: PF being queried
  4463. *
  4464. * Return a bitmap for enabled traffic classes for this PF.
  4465. **/
  4466. static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
  4467. {
  4468. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4469. return i40e_mqprio_get_enabled_tc(pf);
  4470. /* If neither MQPRIO nor DCB is enabled for this PF then just return
  4471. * default TC
  4472. */
  4473. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4474. return I40E_DEFAULT_TRAFFIC_CLASS;
  4475. /* SFP mode we want PF to be enabled for all TCs */
  4476. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4477. return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
  4478. /* MFP enabled and iSCSI PF type */
  4479. if (pf->hw.func_caps.iscsi)
  4480. return i40e_get_iscsi_tc_map(pf);
  4481. else
  4482. return I40E_DEFAULT_TRAFFIC_CLASS;
  4483. }
  4484. /**
  4485. * i40e_vsi_get_bw_info - Query VSI BW Information
  4486. * @vsi: the VSI being queried
  4487. *
  4488. * Returns 0 on success, negative value on failure
  4489. **/
  4490. static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
  4491. {
  4492. struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
  4493. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  4494. struct i40e_pf *pf = vsi->back;
  4495. struct i40e_hw *hw = &pf->hw;
  4496. i40e_status ret;
  4497. u32 tc_bw_max;
  4498. int i;
  4499. /* Get the VSI level BW configuration */
  4500. ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
  4501. if (ret) {
  4502. dev_info(&pf->pdev->dev,
  4503. "couldn't get PF vsi bw config, err %s aq_err %s\n",
  4504. i40e_stat_str(&pf->hw, ret),
  4505. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4506. return -EINVAL;
  4507. }
  4508. /* Get the VSI level BW configuration per TC */
  4509. ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
  4510. NULL);
  4511. if (ret) {
  4512. dev_info(&pf->pdev->dev,
  4513. "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
  4514. i40e_stat_str(&pf->hw, ret),
  4515. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4516. return -EINVAL;
  4517. }
  4518. if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
  4519. dev_info(&pf->pdev->dev,
  4520. "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
  4521. bw_config.tc_valid_bits,
  4522. bw_ets_config.tc_valid_bits);
  4523. /* Still continuing */
  4524. }
  4525. vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
  4526. vsi->bw_max_quanta = bw_config.max_bw;
  4527. tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
  4528. (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
  4529. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4530. vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
  4531. vsi->bw_ets_limit_credits[i] =
  4532. le16_to_cpu(bw_ets_config.credits[i]);
  4533. /* 3 bits out of 4 for each TC */
  4534. vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
  4535. }
  4536. return 0;
  4537. }
  4538. /**
  4539. * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
  4540. * @vsi: the VSI being configured
  4541. * @enabled_tc: TC bitmap
  4542. * @bw_credits: BW shared credits per TC
  4543. *
  4544. * Returns 0 on success, negative value on failure
  4545. **/
  4546. static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
  4547. u8 *bw_share)
  4548. {
  4549. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  4550. i40e_status ret;
  4551. int i;
  4552. if (vsi->back->flags & I40E_FLAG_TC_MQPRIO)
  4553. return 0;
  4554. if (!vsi->mqprio_qopt.qopt.hw) {
  4555. ret = i40e_set_bw_limit(vsi, vsi->seid, 0);
  4556. if (ret)
  4557. dev_info(&vsi->back->pdev->dev,
  4558. "Failed to reset tx rate for vsi->seid %u\n",
  4559. vsi->seid);
  4560. return ret;
  4561. }
  4562. bw_data.tc_valid_bits = enabled_tc;
  4563. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4564. bw_data.tc_bw_credits[i] = bw_share[i];
  4565. ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
  4566. NULL);
  4567. if (ret) {
  4568. dev_info(&vsi->back->pdev->dev,
  4569. "AQ command Config VSI BW allocation per TC failed = %d\n",
  4570. vsi->back->hw.aq.asq_last_status);
  4571. return -EINVAL;
  4572. }
  4573. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4574. vsi->info.qs_handle[i] = bw_data.qs_handles[i];
  4575. return 0;
  4576. }
  4577. /**
  4578. * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
  4579. * @vsi: the VSI being configured
  4580. * @enabled_tc: TC map to be enabled
  4581. *
  4582. **/
  4583. static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4584. {
  4585. struct net_device *netdev = vsi->netdev;
  4586. struct i40e_pf *pf = vsi->back;
  4587. struct i40e_hw *hw = &pf->hw;
  4588. u8 netdev_tc = 0;
  4589. int i;
  4590. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4591. if (!netdev)
  4592. return;
  4593. if (!enabled_tc) {
  4594. netdev_reset_tc(netdev);
  4595. return;
  4596. }
  4597. /* Set up actual enabled TCs on the VSI */
  4598. if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
  4599. return;
  4600. /* set per TC queues for the VSI */
  4601. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4602. /* Only set TC queues for enabled tcs
  4603. *
  4604. * e.g. For a VSI that has TC0 and TC3 enabled the
  4605. * enabled_tc bitmap would be 0x00001001; the driver
  4606. * will set the numtc for netdev as 2 that will be
  4607. * referenced by the netdev layer as TC 0 and 1.
  4608. */
  4609. if (vsi->tc_config.enabled_tc & BIT(i))
  4610. netdev_set_tc_queue(netdev,
  4611. vsi->tc_config.tc_info[i].netdev_tc,
  4612. vsi->tc_config.tc_info[i].qcount,
  4613. vsi->tc_config.tc_info[i].qoffset);
  4614. }
  4615. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4616. return;
  4617. /* Assign UP2TC map for the VSI */
  4618. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  4619. /* Get the actual TC# for the UP */
  4620. u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
  4621. /* Get the mapped netdev TC# for the UP */
  4622. netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
  4623. netdev_set_prio_tc_map(netdev, i, netdev_tc);
  4624. }
  4625. }
  4626. /**
  4627. * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
  4628. * @vsi: the VSI being configured
  4629. * @ctxt: the ctxt buffer returned from AQ VSI update param command
  4630. **/
  4631. static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
  4632. struct i40e_vsi_context *ctxt)
  4633. {
  4634. /* copy just the sections touched not the entire info
  4635. * since not all sections are valid as returned by
  4636. * update vsi params
  4637. */
  4638. vsi->info.mapping_flags = ctxt->info.mapping_flags;
  4639. memcpy(&vsi->info.queue_mapping,
  4640. &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
  4641. memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
  4642. sizeof(vsi->info.tc_mapping));
  4643. }
  4644. /**
  4645. * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
  4646. * @vsi: VSI to be configured
  4647. * @enabled_tc: TC bitmap
  4648. *
  4649. * This configures a particular VSI for TCs that are mapped to the
  4650. * given TC bitmap. It uses default bandwidth share for TCs across
  4651. * VSIs to configure TC for a particular VSI.
  4652. *
  4653. * NOTE:
  4654. * It is expected that the VSI queues have been quisced before calling
  4655. * this function.
  4656. **/
  4657. static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4658. {
  4659. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  4660. struct i40e_vsi_context ctxt;
  4661. int ret = 0;
  4662. int i;
  4663. /* Check if enabled_tc is same as existing or new TCs */
  4664. if (vsi->tc_config.enabled_tc == enabled_tc &&
  4665. vsi->mqprio_qopt.mode != TC_MQPRIO_MODE_CHANNEL)
  4666. return ret;
  4667. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  4668. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4669. if (enabled_tc & BIT(i))
  4670. bw_share[i] = 1;
  4671. }
  4672. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  4673. if (ret) {
  4674. dev_info(&vsi->back->pdev->dev,
  4675. "Failed configuring TC map %d for VSI %d\n",
  4676. enabled_tc, vsi->seid);
  4677. goto out;
  4678. }
  4679. /* Update Queue Pairs Mapping for currently enabled UPs */
  4680. ctxt.seid = vsi->seid;
  4681. ctxt.pf_num = vsi->back->hw.pf_id;
  4682. ctxt.vf_num = 0;
  4683. ctxt.uplink_seid = vsi->uplink_seid;
  4684. ctxt.info = vsi->info;
  4685. if (vsi->back->flags & I40E_FLAG_TC_MQPRIO) {
  4686. ret = i40e_vsi_setup_queue_map_mqprio(vsi, &ctxt, enabled_tc);
  4687. if (ret)
  4688. goto out;
  4689. } else {
  4690. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  4691. }
  4692. /* On destroying the qdisc, reset vsi->rss_size, as number of enabled
  4693. * queues changed.
  4694. */
  4695. if (!vsi->mqprio_qopt.qopt.hw && vsi->reconfig_rss) {
  4696. vsi->rss_size = min_t(int, vsi->back->alloc_rss_size,
  4697. vsi->num_queue_pairs);
  4698. ret = i40e_vsi_config_rss(vsi);
  4699. if (ret) {
  4700. dev_info(&vsi->back->pdev->dev,
  4701. "Failed to reconfig rss for num_queues\n");
  4702. return ret;
  4703. }
  4704. vsi->reconfig_rss = false;
  4705. }
  4706. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  4707. ctxt.info.valid_sections |=
  4708. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  4709. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  4710. }
  4711. /* Update the VSI after updating the VSI queue-mapping
  4712. * information
  4713. */
  4714. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  4715. if (ret) {
  4716. dev_info(&vsi->back->pdev->dev,
  4717. "Update vsi tc config failed, err %s aq_err %s\n",
  4718. i40e_stat_str(&vsi->back->hw, ret),
  4719. i40e_aq_str(&vsi->back->hw,
  4720. vsi->back->hw.aq.asq_last_status));
  4721. goto out;
  4722. }
  4723. /* update the local VSI info with updated queue map */
  4724. i40e_vsi_update_queue_map(vsi, &ctxt);
  4725. vsi->info.valid_sections = 0;
  4726. /* Update current VSI BW information */
  4727. ret = i40e_vsi_get_bw_info(vsi);
  4728. if (ret) {
  4729. dev_info(&vsi->back->pdev->dev,
  4730. "Failed updating vsi bw info, err %s aq_err %s\n",
  4731. i40e_stat_str(&vsi->back->hw, ret),
  4732. i40e_aq_str(&vsi->back->hw,
  4733. vsi->back->hw.aq.asq_last_status));
  4734. goto out;
  4735. }
  4736. /* Update the netdev TC setup */
  4737. i40e_vsi_config_netdev_tc(vsi, enabled_tc);
  4738. out:
  4739. return ret;
  4740. }
  4741. /**
  4742. * i40e_get_link_speed - Returns link speed for the interface
  4743. * @vsi: VSI to be configured
  4744. *
  4745. **/
  4746. int i40e_get_link_speed(struct i40e_vsi *vsi)
  4747. {
  4748. struct i40e_pf *pf = vsi->back;
  4749. switch (pf->hw.phy.link_info.link_speed) {
  4750. case I40E_LINK_SPEED_40GB:
  4751. return 40000;
  4752. case I40E_LINK_SPEED_25GB:
  4753. return 25000;
  4754. case I40E_LINK_SPEED_20GB:
  4755. return 20000;
  4756. case I40E_LINK_SPEED_10GB:
  4757. return 10000;
  4758. case I40E_LINK_SPEED_1GB:
  4759. return 1000;
  4760. default:
  4761. return -EINVAL;
  4762. }
  4763. }
  4764. /**
  4765. * i40e_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
  4766. * @vsi: VSI to be configured
  4767. * @seid: seid of the channel/VSI
  4768. * @max_tx_rate: max TX rate to be configured as BW limit
  4769. *
  4770. * Helper function to set BW limit for a given VSI
  4771. **/
  4772. int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate)
  4773. {
  4774. struct i40e_pf *pf = vsi->back;
  4775. u64 credits = 0;
  4776. int speed = 0;
  4777. int ret = 0;
  4778. speed = i40e_get_link_speed(vsi);
  4779. if (max_tx_rate > speed) {
  4780. dev_err(&pf->pdev->dev,
  4781. "Invalid max tx rate %llu specified for VSI seid %d.",
  4782. max_tx_rate, seid);
  4783. return -EINVAL;
  4784. }
  4785. if (max_tx_rate && max_tx_rate < 50) {
  4786. dev_warn(&pf->pdev->dev,
  4787. "Setting max tx rate to minimum usable value of 50Mbps.\n");
  4788. max_tx_rate = 50;
  4789. }
  4790. /* Tx rate credits are in values of 50Mbps, 0 is disabled */
  4791. credits = max_tx_rate;
  4792. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  4793. ret = i40e_aq_config_vsi_bw_limit(&pf->hw, seid, credits,
  4794. I40E_MAX_BW_INACTIVE_ACCUM, NULL);
  4795. if (ret)
  4796. dev_err(&pf->pdev->dev,
  4797. "Failed set tx rate (%llu Mbps) for vsi->seid %u, err %s aq_err %s\n",
  4798. max_tx_rate, seid, i40e_stat_str(&pf->hw, ret),
  4799. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4800. return ret;
  4801. }
  4802. /**
  4803. * i40e_remove_queue_channels - Remove queue channels for the TCs
  4804. * @vsi: VSI to be configured
  4805. *
  4806. * Remove queue channels for the TCs
  4807. **/
  4808. static void i40e_remove_queue_channels(struct i40e_vsi *vsi)
  4809. {
  4810. enum i40e_admin_queue_err last_aq_status;
  4811. struct i40e_cloud_filter *cfilter;
  4812. struct i40e_channel *ch, *ch_tmp;
  4813. struct i40e_pf *pf = vsi->back;
  4814. struct hlist_node *node;
  4815. int ret, i;
  4816. /* Reset rss size that was stored when reconfiguring rss for
  4817. * channel VSIs with non-power-of-2 queue count.
  4818. */
  4819. vsi->current_rss_size = 0;
  4820. /* perform cleanup for channels if they exist */
  4821. if (list_empty(&vsi->ch_list))
  4822. return;
  4823. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4824. struct i40e_vsi *p_vsi;
  4825. list_del(&ch->list);
  4826. p_vsi = ch->parent_vsi;
  4827. if (!p_vsi || !ch->initialized) {
  4828. kfree(ch);
  4829. continue;
  4830. }
  4831. /* Reset queue contexts */
  4832. for (i = 0; i < ch->num_queue_pairs; i++) {
  4833. struct i40e_ring *tx_ring, *rx_ring;
  4834. u16 pf_q;
  4835. pf_q = ch->base_queue + i;
  4836. tx_ring = vsi->tx_rings[pf_q];
  4837. tx_ring->ch = NULL;
  4838. rx_ring = vsi->rx_rings[pf_q];
  4839. rx_ring->ch = NULL;
  4840. }
  4841. /* Reset BW configured for this VSI via mqprio */
  4842. ret = i40e_set_bw_limit(vsi, ch->seid, 0);
  4843. if (ret)
  4844. dev_info(&vsi->back->pdev->dev,
  4845. "Failed to reset tx rate for ch->seid %u\n",
  4846. ch->seid);
  4847. /* delete cloud filters associated with this channel */
  4848. hlist_for_each_entry_safe(cfilter, node,
  4849. &pf->cloud_filter_list, cloud_node) {
  4850. if (cfilter->seid != ch->seid)
  4851. continue;
  4852. hash_del(&cfilter->cloud_node);
  4853. if (cfilter->dst_port)
  4854. ret = i40e_add_del_cloud_filter_big_buf(vsi,
  4855. cfilter,
  4856. false);
  4857. else
  4858. ret = i40e_add_del_cloud_filter(vsi, cfilter,
  4859. false);
  4860. last_aq_status = pf->hw.aq.asq_last_status;
  4861. if (ret)
  4862. dev_info(&pf->pdev->dev,
  4863. "Failed to delete cloud filter, err %s aq_err %s\n",
  4864. i40e_stat_str(&pf->hw, ret),
  4865. i40e_aq_str(&pf->hw, last_aq_status));
  4866. kfree(cfilter);
  4867. }
  4868. /* delete VSI from FW */
  4869. ret = i40e_aq_delete_element(&vsi->back->hw, ch->seid,
  4870. NULL);
  4871. if (ret)
  4872. dev_err(&vsi->back->pdev->dev,
  4873. "unable to remove channel (%d) for parent VSI(%d)\n",
  4874. ch->seid, p_vsi->seid);
  4875. kfree(ch);
  4876. }
  4877. INIT_LIST_HEAD(&vsi->ch_list);
  4878. }
  4879. /**
  4880. * i40e_is_any_channel - channel exist or not
  4881. * @vsi: ptr to VSI to which channels are associated with
  4882. *
  4883. * Returns true or false if channel(s) exist for associated VSI or not
  4884. **/
  4885. static bool i40e_is_any_channel(struct i40e_vsi *vsi)
  4886. {
  4887. struct i40e_channel *ch, *ch_tmp;
  4888. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4889. if (ch->initialized)
  4890. return true;
  4891. }
  4892. return false;
  4893. }
  4894. /**
  4895. * i40e_get_max_queues_for_channel
  4896. * @vsi: ptr to VSI to which channels are associated with
  4897. *
  4898. * Helper function which returns max value among the queue counts set on the
  4899. * channels/TCs created.
  4900. **/
  4901. static int i40e_get_max_queues_for_channel(struct i40e_vsi *vsi)
  4902. {
  4903. struct i40e_channel *ch, *ch_tmp;
  4904. int max = 0;
  4905. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4906. if (!ch->initialized)
  4907. continue;
  4908. if (ch->num_queue_pairs > max)
  4909. max = ch->num_queue_pairs;
  4910. }
  4911. return max;
  4912. }
  4913. /**
  4914. * i40e_validate_num_queues - validate num_queues w.r.t channel
  4915. * @pf: ptr to PF device
  4916. * @num_queues: number of queues
  4917. * @vsi: the parent VSI
  4918. * @reconfig_rss: indicates should the RSS be reconfigured or not
  4919. *
  4920. * This function validates number of queues in the context of new channel
  4921. * which is being established and determines if RSS should be reconfigured
  4922. * or not for parent VSI.
  4923. **/
  4924. static int i40e_validate_num_queues(struct i40e_pf *pf, int num_queues,
  4925. struct i40e_vsi *vsi, bool *reconfig_rss)
  4926. {
  4927. int max_ch_queues;
  4928. if (!reconfig_rss)
  4929. return -EINVAL;
  4930. *reconfig_rss = false;
  4931. if (vsi->current_rss_size) {
  4932. if (num_queues > vsi->current_rss_size) {
  4933. dev_dbg(&pf->pdev->dev,
  4934. "Error: num_queues (%d) > vsi's current_size(%d)\n",
  4935. num_queues, vsi->current_rss_size);
  4936. return -EINVAL;
  4937. } else if ((num_queues < vsi->current_rss_size) &&
  4938. (!is_power_of_2(num_queues))) {
  4939. dev_dbg(&pf->pdev->dev,
  4940. "Error: num_queues (%d) < vsi's current_size(%d), but not power of 2\n",
  4941. num_queues, vsi->current_rss_size);
  4942. return -EINVAL;
  4943. }
  4944. }
  4945. if (!is_power_of_2(num_queues)) {
  4946. /* Find the max num_queues configured for channel if channel
  4947. * exist.
  4948. * if channel exist, then enforce 'num_queues' to be more than
  4949. * max ever queues configured for channel.
  4950. */
  4951. max_ch_queues = i40e_get_max_queues_for_channel(vsi);
  4952. if (num_queues < max_ch_queues) {
  4953. dev_dbg(&pf->pdev->dev,
  4954. "Error: num_queues (%d) < max queues configured for channel(%d)\n",
  4955. num_queues, max_ch_queues);
  4956. return -EINVAL;
  4957. }
  4958. *reconfig_rss = true;
  4959. }
  4960. return 0;
  4961. }
  4962. /**
  4963. * i40e_vsi_reconfig_rss - reconfig RSS based on specified rss_size
  4964. * @vsi: the VSI being setup
  4965. * @rss_size: size of RSS, accordingly LUT gets reprogrammed
  4966. *
  4967. * This function reconfigures RSS by reprogramming LUTs using 'rss_size'
  4968. **/
  4969. static int i40e_vsi_reconfig_rss(struct i40e_vsi *vsi, u16 rss_size)
  4970. {
  4971. struct i40e_pf *pf = vsi->back;
  4972. u8 seed[I40E_HKEY_ARRAY_SIZE];
  4973. struct i40e_hw *hw = &pf->hw;
  4974. int local_rss_size;
  4975. u8 *lut;
  4976. int ret;
  4977. if (!vsi->rss_size)
  4978. return -EINVAL;
  4979. if (rss_size > vsi->rss_size)
  4980. return -EINVAL;
  4981. local_rss_size = min_t(int, vsi->rss_size, rss_size);
  4982. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  4983. if (!lut)
  4984. return -ENOMEM;
  4985. /* Ignoring user configured lut if there is one */
  4986. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, local_rss_size);
  4987. /* Use user configured hash key if there is one, otherwise
  4988. * use default.
  4989. */
  4990. if (vsi->rss_hkey_user)
  4991. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  4992. else
  4993. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  4994. ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
  4995. if (ret) {
  4996. dev_info(&pf->pdev->dev,
  4997. "Cannot set RSS lut, err %s aq_err %s\n",
  4998. i40e_stat_str(hw, ret),
  4999. i40e_aq_str(hw, hw->aq.asq_last_status));
  5000. kfree(lut);
  5001. return ret;
  5002. }
  5003. kfree(lut);
  5004. /* Do the update w.r.t. storing rss_size */
  5005. if (!vsi->orig_rss_size)
  5006. vsi->orig_rss_size = vsi->rss_size;
  5007. vsi->current_rss_size = local_rss_size;
  5008. return ret;
  5009. }
  5010. /**
  5011. * i40e_channel_setup_queue_map - Setup a channel queue map
  5012. * @pf: ptr to PF device
  5013. * @vsi: the VSI being setup
  5014. * @ctxt: VSI context structure
  5015. * @ch: ptr to channel structure
  5016. *
  5017. * Setup queue map for a specific channel
  5018. **/
  5019. static void i40e_channel_setup_queue_map(struct i40e_pf *pf,
  5020. struct i40e_vsi_context *ctxt,
  5021. struct i40e_channel *ch)
  5022. {
  5023. u16 qcount, qmap, sections = 0;
  5024. u8 offset = 0;
  5025. int pow;
  5026. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  5027. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  5028. qcount = min_t(int, ch->num_queue_pairs, pf->num_lan_msix);
  5029. ch->num_queue_pairs = qcount;
  5030. /* find the next higher power-of-2 of num queue pairs */
  5031. pow = ilog2(qcount);
  5032. if (!is_power_of_2(qcount))
  5033. pow++;
  5034. qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  5035. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  5036. /* Setup queue TC[0].qmap for given VSI context */
  5037. ctxt->info.tc_mapping[0] = cpu_to_le16(qmap);
  5038. ctxt->info.up_enable_bits = 0x1; /* TC0 enabled */
  5039. ctxt->info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  5040. ctxt->info.queue_mapping[0] = cpu_to_le16(ch->base_queue);
  5041. ctxt->info.valid_sections |= cpu_to_le16(sections);
  5042. }
  5043. /**
  5044. * i40e_add_channel - add a channel by adding VSI
  5045. * @pf: ptr to PF device
  5046. * @uplink_seid: underlying HW switching element (VEB) ID
  5047. * @ch: ptr to channel structure
  5048. *
  5049. * Add a channel (VSI) using add_vsi and queue_map
  5050. **/
  5051. static int i40e_add_channel(struct i40e_pf *pf, u16 uplink_seid,
  5052. struct i40e_channel *ch)
  5053. {
  5054. struct i40e_hw *hw = &pf->hw;
  5055. struct i40e_vsi_context ctxt;
  5056. u8 enabled_tc = 0x1; /* TC0 enabled */
  5057. int ret;
  5058. if (ch->type != I40E_VSI_VMDQ2) {
  5059. dev_info(&pf->pdev->dev,
  5060. "add new vsi failed, ch->type %d\n", ch->type);
  5061. return -EINVAL;
  5062. }
  5063. memset(&ctxt, 0, sizeof(ctxt));
  5064. ctxt.pf_num = hw->pf_id;
  5065. ctxt.vf_num = 0;
  5066. ctxt.uplink_seid = uplink_seid;
  5067. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  5068. if (ch->type == I40E_VSI_VMDQ2)
  5069. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  5070. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) {
  5071. ctxt.info.valid_sections |=
  5072. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5073. ctxt.info.switch_id =
  5074. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5075. }
  5076. /* Set queue map for a given VSI context */
  5077. i40e_channel_setup_queue_map(pf, &ctxt, ch);
  5078. /* Now time to create VSI */
  5079. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  5080. if (ret) {
  5081. dev_info(&pf->pdev->dev,
  5082. "add new vsi failed, err %s aq_err %s\n",
  5083. i40e_stat_str(&pf->hw, ret),
  5084. i40e_aq_str(&pf->hw,
  5085. pf->hw.aq.asq_last_status));
  5086. return -ENOENT;
  5087. }
  5088. /* Success, update channel */
  5089. ch->enabled_tc = enabled_tc;
  5090. ch->seid = ctxt.seid;
  5091. ch->vsi_number = ctxt.vsi_number;
  5092. ch->stat_counter_idx = cpu_to_le16(ctxt.info.stat_counter_idx);
  5093. /* copy just the sections touched not the entire info
  5094. * since not all sections are valid as returned by
  5095. * update vsi params
  5096. */
  5097. ch->info.mapping_flags = ctxt.info.mapping_flags;
  5098. memcpy(&ch->info.queue_mapping,
  5099. &ctxt.info.queue_mapping, sizeof(ctxt.info.queue_mapping));
  5100. memcpy(&ch->info.tc_mapping, ctxt.info.tc_mapping,
  5101. sizeof(ctxt.info.tc_mapping));
  5102. return 0;
  5103. }
  5104. static int i40e_channel_config_bw(struct i40e_vsi *vsi, struct i40e_channel *ch,
  5105. u8 *bw_share)
  5106. {
  5107. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  5108. i40e_status ret;
  5109. int i;
  5110. bw_data.tc_valid_bits = ch->enabled_tc;
  5111. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  5112. bw_data.tc_bw_credits[i] = bw_share[i];
  5113. ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, ch->seid,
  5114. &bw_data, NULL);
  5115. if (ret) {
  5116. dev_info(&vsi->back->pdev->dev,
  5117. "Config VSI BW allocation per TC failed, aq_err: %d for new_vsi->seid %u\n",
  5118. vsi->back->hw.aq.asq_last_status, ch->seid);
  5119. return -EINVAL;
  5120. }
  5121. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  5122. ch->info.qs_handle[i] = bw_data.qs_handles[i];
  5123. return 0;
  5124. }
  5125. /**
  5126. * i40e_channel_config_tx_ring - config TX ring associated with new channel
  5127. * @pf: ptr to PF device
  5128. * @vsi: the VSI being setup
  5129. * @ch: ptr to channel structure
  5130. *
  5131. * Configure TX rings associated with channel (VSI) since queues are being
  5132. * from parent VSI.
  5133. **/
  5134. static int i40e_channel_config_tx_ring(struct i40e_pf *pf,
  5135. struct i40e_vsi *vsi,
  5136. struct i40e_channel *ch)
  5137. {
  5138. i40e_status ret;
  5139. int i;
  5140. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  5141. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  5142. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5143. if (ch->enabled_tc & BIT(i))
  5144. bw_share[i] = 1;
  5145. }
  5146. /* configure BW for new VSI */
  5147. ret = i40e_channel_config_bw(vsi, ch, bw_share);
  5148. if (ret) {
  5149. dev_info(&vsi->back->pdev->dev,
  5150. "Failed configuring TC map %d for channel (seid %u)\n",
  5151. ch->enabled_tc, ch->seid);
  5152. return ret;
  5153. }
  5154. for (i = 0; i < ch->num_queue_pairs; i++) {
  5155. struct i40e_ring *tx_ring, *rx_ring;
  5156. u16 pf_q;
  5157. pf_q = ch->base_queue + i;
  5158. /* Get to TX ring ptr of main VSI, for re-setup TX queue
  5159. * context
  5160. */
  5161. tx_ring = vsi->tx_rings[pf_q];
  5162. tx_ring->ch = ch;
  5163. /* Get the RX ring ptr */
  5164. rx_ring = vsi->rx_rings[pf_q];
  5165. rx_ring->ch = ch;
  5166. }
  5167. return 0;
  5168. }
  5169. /**
  5170. * i40e_setup_hw_channel - setup new channel
  5171. * @pf: ptr to PF device
  5172. * @vsi: the VSI being setup
  5173. * @ch: ptr to channel structure
  5174. * @uplink_seid: underlying HW switching element (VEB) ID
  5175. * @type: type of channel to be created (VMDq2/VF)
  5176. *
  5177. * Setup new channel (VSI) based on specified type (VMDq2/VF)
  5178. * and configures TX rings accordingly
  5179. **/
  5180. static inline int i40e_setup_hw_channel(struct i40e_pf *pf,
  5181. struct i40e_vsi *vsi,
  5182. struct i40e_channel *ch,
  5183. u16 uplink_seid, u8 type)
  5184. {
  5185. int ret;
  5186. ch->initialized = false;
  5187. ch->base_queue = vsi->next_base_queue;
  5188. ch->type = type;
  5189. /* Proceed with creation of channel (VMDq2) VSI */
  5190. ret = i40e_add_channel(pf, uplink_seid, ch);
  5191. if (ret) {
  5192. dev_info(&pf->pdev->dev,
  5193. "failed to add_channel using uplink_seid %u\n",
  5194. uplink_seid);
  5195. return ret;
  5196. }
  5197. /* Mark the successful creation of channel */
  5198. ch->initialized = true;
  5199. /* Reconfigure TX queues using QTX_CTL register */
  5200. ret = i40e_channel_config_tx_ring(pf, vsi, ch);
  5201. if (ret) {
  5202. dev_info(&pf->pdev->dev,
  5203. "failed to configure TX rings for channel %u\n",
  5204. ch->seid);
  5205. return ret;
  5206. }
  5207. /* update 'next_base_queue' */
  5208. vsi->next_base_queue = vsi->next_base_queue + ch->num_queue_pairs;
  5209. dev_dbg(&pf->pdev->dev,
  5210. "Added channel: vsi_seid %u, vsi_number %u, stat_counter_idx %u, num_queue_pairs %u, pf->next_base_queue %d\n",
  5211. ch->seid, ch->vsi_number, ch->stat_counter_idx,
  5212. ch->num_queue_pairs,
  5213. vsi->next_base_queue);
  5214. return ret;
  5215. }
  5216. /**
  5217. * i40e_setup_channel - setup new channel using uplink element
  5218. * @pf: ptr to PF device
  5219. * @type: type of channel to be created (VMDq2/VF)
  5220. * @uplink_seid: underlying HW switching element (VEB) ID
  5221. * @ch: ptr to channel structure
  5222. *
  5223. * Setup new channel (VSI) based on specified type (VMDq2/VF)
  5224. * and uplink switching element (uplink_seid)
  5225. **/
  5226. static bool i40e_setup_channel(struct i40e_pf *pf, struct i40e_vsi *vsi,
  5227. struct i40e_channel *ch)
  5228. {
  5229. u8 vsi_type;
  5230. u16 seid;
  5231. int ret;
  5232. if (vsi->type == I40E_VSI_MAIN) {
  5233. vsi_type = I40E_VSI_VMDQ2;
  5234. } else {
  5235. dev_err(&pf->pdev->dev, "unsupported parent vsi type(%d)\n",
  5236. vsi->type);
  5237. return false;
  5238. }
  5239. /* underlying switching element */
  5240. seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  5241. /* create channel (VSI), configure TX rings */
  5242. ret = i40e_setup_hw_channel(pf, vsi, ch, seid, vsi_type);
  5243. if (ret) {
  5244. dev_err(&pf->pdev->dev, "failed to setup hw_channel\n");
  5245. return false;
  5246. }
  5247. return ch->initialized ? true : false;
  5248. }
  5249. /**
  5250. * i40e_validate_and_set_switch_mode - sets up switch mode correctly
  5251. * @vsi: ptr to VSI which has PF backing
  5252. *
  5253. * Sets up switch mode correctly if it needs to be changed and perform
  5254. * what are allowed modes.
  5255. **/
  5256. static int i40e_validate_and_set_switch_mode(struct i40e_vsi *vsi)
  5257. {
  5258. u8 mode;
  5259. struct i40e_pf *pf = vsi->back;
  5260. struct i40e_hw *hw = &pf->hw;
  5261. int ret;
  5262. ret = i40e_get_capabilities(pf, i40e_aqc_opc_list_dev_capabilities);
  5263. if (ret)
  5264. return -EINVAL;
  5265. if (hw->dev_caps.switch_mode) {
  5266. /* if switch mode is set, support mode2 (non-tunneled for
  5267. * cloud filter) for now
  5268. */
  5269. u32 switch_mode = hw->dev_caps.switch_mode &
  5270. I40E_SWITCH_MODE_MASK;
  5271. if (switch_mode >= I40E_CLOUD_FILTER_MODE1) {
  5272. if (switch_mode == I40E_CLOUD_FILTER_MODE2)
  5273. return 0;
  5274. dev_err(&pf->pdev->dev,
  5275. "Invalid switch_mode (%d), only non-tunneled mode for cloud filter is supported\n",
  5276. hw->dev_caps.switch_mode);
  5277. return -EINVAL;
  5278. }
  5279. }
  5280. /* Set Bit 7 to be valid */
  5281. mode = I40E_AQ_SET_SWITCH_BIT7_VALID;
  5282. /* Set L4type to both TCP and UDP support */
  5283. mode |= I40E_AQ_SET_SWITCH_L4_TYPE_BOTH;
  5284. /* Set cloud filter mode */
  5285. mode |= I40E_AQ_SET_SWITCH_MODE_NON_TUNNEL;
  5286. /* Prep mode field for set_switch_config */
  5287. ret = i40e_aq_set_switch_config(hw, pf->last_sw_conf_flags,
  5288. pf->last_sw_conf_valid_flags,
  5289. mode, NULL);
  5290. if (ret && hw->aq.asq_last_status != I40E_AQ_RC_ESRCH)
  5291. dev_err(&pf->pdev->dev,
  5292. "couldn't set switch config bits, err %s aq_err %s\n",
  5293. i40e_stat_str(hw, ret),
  5294. i40e_aq_str(hw,
  5295. hw->aq.asq_last_status));
  5296. return ret;
  5297. }
  5298. /**
  5299. * i40e_create_queue_channel - function to create channel
  5300. * @vsi: VSI to be configured
  5301. * @ch: ptr to channel (it contains channel specific params)
  5302. *
  5303. * This function creates channel (VSI) using num_queues specified by user,
  5304. * reconfigs RSS if needed.
  5305. **/
  5306. int i40e_create_queue_channel(struct i40e_vsi *vsi,
  5307. struct i40e_channel *ch)
  5308. {
  5309. struct i40e_pf *pf = vsi->back;
  5310. bool reconfig_rss;
  5311. int err;
  5312. if (!ch)
  5313. return -EINVAL;
  5314. if (!ch->num_queue_pairs) {
  5315. dev_err(&pf->pdev->dev, "Invalid num_queues requested: %d\n",
  5316. ch->num_queue_pairs);
  5317. return -EINVAL;
  5318. }
  5319. /* validate user requested num_queues for channel */
  5320. err = i40e_validate_num_queues(pf, ch->num_queue_pairs, vsi,
  5321. &reconfig_rss);
  5322. if (err) {
  5323. dev_info(&pf->pdev->dev, "Failed to validate num_queues (%d)\n",
  5324. ch->num_queue_pairs);
  5325. return -EINVAL;
  5326. }
  5327. /* By default we are in VEPA mode, if this is the first VF/VMDq
  5328. * VSI to be added switch to VEB mode.
  5329. */
  5330. if ((!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) ||
  5331. (!i40e_is_any_channel(vsi))) {
  5332. if (!is_power_of_2(vsi->tc_config.tc_info[0].qcount)) {
  5333. dev_dbg(&pf->pdev->dev,
  5334. "Failed to create channel. Override queues (%u) not power of 2\n",
  5335. vsi->tc_config.tc_info[0].qcount);
  5336. return -EINVAL;
  5337. }
  5338. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  5339. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  5340. if (vsi->type == I40E_VSI_MAIN) {
  5341. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  5342. i40e_do_reset(pf, I40E_PF_RESET_FLAG,
  5343. true);
  5344. else
  5345. i40e_do_reset_safe(pf,
  5346. I40E_PF_RESET_FLAG);
  5347. }
  5348. }
  5349. /* now onwards for main VSI, number of queues will be value
  5350. * of TC0's queue count
  5351. */
  5352. }
  5353. /* By this time, vsi->cnt_q_avail shall be set to non-zero and
  5354. * it should be more than num_queues
  5355. */
  5356. if (!vsi->cnt_q_avail || vsi->cnt_q_avail < ch->num_queue_pairs) {
  5357. dev_dbg(&pf->pdev->dev,
  5358. "Error: cnt_q_avail (%u) less than num_queues %d\n",
  5359. vsi->cnt_q_avail, ch->num_queue_pairs);
  5360. return -EINVAL;
  5361. }
  5362. /* reconfig_rss only if vsi type is MAIN_VSI */
  5363. if (reconfig_rss && (vsi->type == I40E_VSI_MAIN)) {
  5364. err = i40e_vsi_reconfig_rss(vsi, ch->num_queue_pairs);
  5365. if (err) {
  5366. dev_info(&pf->pdev->dev,
  5367. "Error: unable to reconfig rss for num_queues (%u)\n",
  5368. ch->num_queue_pairs);
  5369. return -EINVAL;
  5370. }
  5371. }
  5372. if (!i40e_setup_channel(pf, vsi, ch)) {
  5373. dev_info(&pf->pdev->dev, "Failed to setup channel\n");
  5374. return -EINVAL;
  5375. }
  5376. dev_info(&pf->pdev->dev,
  5377. "Setup channel (id:%u) utilizing num_queues %d\n",
  5378. ch->seid, ch->num_queue_pairs);
  5379. /* configure VSI for BW limit */
  5380. if (ch->max_tx_rate) {
  5381. u64 credits = ch->max_tx_rate;
  5382. if (i40e_set_bw_limit(vsi, ch->seid, ch->max_tx_rate))
  5383. return -EINVAL;
  5384. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  5385. dev_dbg(&pf->pdev->dev,
  5386. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  5387. ch->max_tx_rate,
  5388. credits,
  5389. ch->seid);
  5390. }
  5391. /* in case of VF, this will be main SRIOV VSI */
  5392. ch->parent_vsi = vsi;
  5393. /* and update main_vsi's count for queue_available to use */
  5394. vsi->cnt_q_avail -= ch->num_queue_pairs;
  5395. return 0;
  5396. }
  5397. /**
  5398. * i40e_configure_queue_channels - Add queue channel for the given TCs
  5399. * @vsi: VSI to be configured
  5400. *
  5401. * Configures queue channel mapping to the given TCs
  5402. **/
  5403. static int i40e_configure_queue_channels(struct i40e_vsi *vsi)
  5404. {
  5405. struct i40e_channel *ch;
  5406. u64 max_rate = 0;
  5407. int ret = 0, i;
  5408. /* Create app vsi with the TCs. Main VSI with TC0 is already set up */
  5409. vsi->tc_seid_map[0] = vsi->seid;
  5410. for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5411. if (vsi->tc_config.enabled_tc & BIT(i)) {
  5412. ch = kzalloc(sizeof(*ch), GFP_KERNEL);
  5413. if (!ch) {
  5414. ret = -ENOMEM;
  5415. goto err_free;
  5416. }
  5417. INIT_LIST_HEAD(&ch->list);
  5418. ch->num_queue_pairs =
  5419. vsi->tc_config.tc_info[i].qcount;
  5420. ch->base_queue =
  5421. vsi->tc_config.tc_info[i].qoffset;
  5422. /* Bandwidth limit through tc interface is in bytes/s,
  5423. * change to Mbit/s
  5424. */
  5425. max_rate = vsi->mqprio_qopt.max_rate[i];
  5426. do_div(max_rate, I40E_BW_MBPS_DIVISOR);
  5427. ch->max_tx_rate = max_rate;
  5428. list_add_tail(&ch->list, &vsi->ch_list);
  5429. ret = i40e_create_queue_channel(vsi, ch);
  5430. if (ret) {
  5431. dev_err(&vsi->back->pdev->dev,
  5432. "Failed creating queue channel with TC%d: queues %d\n",
  5433. i, ch->num_queue_pairs);
  5434. goto err_free;
  5435. }
  5436. vsi->tc_seid_map[i] = ch->seid;
  5437. }
  5438. }
  5439. return ret;
  5440. err_free:
  5441. i40e_remove_queue_channels(vsi);
  5442. return ret;
  5443. }
  5444. /**
  5445. * i40e_veb_config_tc - Configure TCs for given VEB
  5446. * @veb: given VEB
  5447. * @enabled_tc: TC bitmap
  5448. *
  5449. * Configures given TC bitmap for VEB (switching) element
  5450. **/
  5451. int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
  5452. {
  5453. struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
  5454. struct i40e_pf *pf = veb->pf;
  5455. int ret = 0;
  5456. int i;
  5457. /* No TCs or already enabled TCs just return */
  5458. if (!enabled_tc || veb->enabled_tc == enabled_tc)
  5459. return ret;
  5460. bw_data.tc_valid_bits = enabled_tc;
  5461. /* bw_data.absolute_credits is not set (relative) */
  5462. /* Enable ETS TCs with equal BW Share for now */
  5463. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5464. if (enabled_tc & BIT(i))
  5465. bw_data.tc_bw_share_credits[i] = 1;
  5466. }
  5467. ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
  5468. &bw_data, NULL);
  5469. if (ret) {
  5470. dev_info(&pf->pdev->dev,
  5471. "VEB bw config failed, err %s aq_err %s\n",
  5472. i40e_stat_str(&pf->hw, ret),
  5473. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5474. goto out;
  5475. }
  5476. /* Update the BW information */
  5477. ret = i40e_veb_get_bw_info(veb);
  5478. if (ret) {
  5479. dev_info(&pf->pdev->dev,
  5480. "Failed getting veb bw config, err %s aq_err %s\n",
  5481. i40e_stat_str(&pf->hw, ret),
  5482. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5483. }
  5484. out:
  5485. return ret;
  5486. }
  5487. #ifdef CONFIG_I40E_DCB
  5488. /**
  5489. * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
  5490. * @pf: PF struct
  5491. *
  5492. * Reconfigure VEB/VSIs on a given PF; it is assumed that
  5493. * the caller would've quiesce all the VSIs before calling
  5494. * this function
  5495. **/
  5496. static void i40e_dcb_reconfigure(struct i40e_pf *pf)
  5497. {
  5498. u8 tc_map = 0;
  5499. int ret;
  5500. u8 v;
  5501. /* Enable the TCs available on PF to all VEBs */
  5502. tc_map = i40e_pf_get_tc_map(pf);
  5503. for (v = 0; v < I40E_MAX_VEB; v++) {
  5504. if (!pf->veb[v])
  5505. continue;
  5506. ret = i40e_veb_config_tc(pf->veb[v], tc_map);
  5507. if (ret) {
  5508. dev_info(&pf->pdev->dev,
  5509. "Failed configuring TC for VEB seid=%d\n",
  5510. pf->veb[v]->seid);
  5511. /* Will try to configure as many components */
  5512. }
  5513. }
  5514. /* Update each VSI */
  5515. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5516. if (!pf->vsi[v])
  5517. continue;
  5518. /* - Enable all TCs for the LAN VSI
  5519. * - For all others keep them at TC0 for now
  5520. */
  5521. if (v == pf->lan_vsi)
  5522. tc_map = i40e_pf_get_tc_map(pf);
  5523. else
  5524. tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
  5525. ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
  5526. if (ret) {
  5527. dev_info(&pf->pdev->dev,
  5528. "Failed configuring TC for VSI seid=%d\n",
  5529. pf->vsi[v]->seid);
  5530. /* Will try to configure as many components */
  5531. } else {
  5532. /* Re-configure VSI vectors based on updated TC map */
  5533. i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
  5534. if (pf->vsi[v]->netdev)
  5535. i40e_dcbnl_set_all(pf->vsi[v]);
  5536. }
  5537. }
  5538. }
  5539. /**
  5540. * i40e_resume_port_tx - Resume port Tx
  5541. * @pf: PF struct
  5542. *
  5543. * Resume a port's Tx and issue a PF reset in case of failure to
  5544. * resume.
  5545. **/
  5546. static int i40e_resume_port_tx(struct i40e_pf *pf)
  5547. {
  5548. struct i40e_hw *hw = &pf->hw;
  5549. int ret;
  5550. ret = i40e_aq_resume_port_tx(hw, NULL);
  5551. if (ret) {
  5552. dev_info(&pf->pdev->dev,
  5553. "Resume Port Tx failed, err %s aq_err %s\n",
  5554. i40e_stat_str(&pf->hw, ret),
  5555. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5556. /* Schedule PF reset to recover */
  5557. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  5558. i40e_service_event_schedule(pf);
  5559. }
  5560. return ret;
  5561. }
  5562. /**
  5563. * i40e_init_pf_dcb - Initialize DCB configuration
  5564. * @pf: PF being configured
  5565. *
  5566. * Query the current DCB configuration and cache it
  5567. * in the hardware structure
  5568. **/
  5569. static int i40e_init_pf_dcb(struct i40e_pf *pf)
  5570. {
  5571. struct i40e_hw *hw = &pf->hw;
  5572. int err = 0;
  5573. /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
  5574. if (pf->hw_features & I40E_HW_NO_DCB_SUPPORT)
  5575. goto out;
  5576. /* Get the initial DCB configuration */
  5577. err = i40e_init_dcb(hw);
  5578. if (!err) {
  5579. /* Device/Function is not DCBX capable */
  5580. if ((!hw->func_caps.dcb) ||
  5581. (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
  5582. dev_info(&pf->pdev->dev,
  5583. "DCBX offload is not supported or is disabled for this PF.\n");
  5584. } else {
  5585. /* When status is not DISABLED then DCBX in FW */
  5586. pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
  5587. DCB_CAP_DCBX_VER_IEEE;
  5588. pf->flags |= I40E_FLAG_DCB_CAPABLE;
  5589. /* Enable DCB tagging only when more than one TC
  5590. * or explicitly disable if only one TC
  5591. */
  5592. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  5593. pf->flags |= I40E_FLAG_DCB_ENABLED;
  5594. else
  5595. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  5596. dev_dbg(&pf->pdev->dev,
  5597. "DCBX offload is supported for this PF.\n");
  5598. }
  5599. } else {
  5600. dev_info(&pf->pdev->dev,
  5601. "Query for DCB configuration failed, err %s aq_err %s\n",
  5602. i40e_stat_str(&pf->hw, err),
  5603. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5604. }
  5605. out:
  5606. return err;
  5607. }
  5608. #endif /* CONFIG_I40E_DCB */
  5609. #define SPEED_SIZE 14
  5610. #define FC_SIZE 8
  5611. /**
  5612. * i40e_print_link_message - print link up or down
  5613. * @vsi: the VSI for which link needs a message
  5614. */
  5615. void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
  5616. {
  5617. enum i40e_aq_link_speed new_speed;
  5618. struct i40e_pf *pf = vsi->back;
  5619. char *speed = "Unknown";
  5620. char *fc = "Unknown";
  5621. char *fec = "";
  5622. char *req_fec = "";
  5623. char *an = "";
  5624. new_speed = pf->hw.phy.link_info.link_speed;
  5625. if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed))
  5626. return;
  5627. vsi->current_isup = isup;
  5628. vsi->current_speed = new_speed;
  5629. if (!isup) {
  5630. netdev_info(vsi->netdev, "NIC Link is Down\n");
  5631. return;
  5632. }
  5633. /* Warn user if link speed on NPAR enabled partition is not at
  5634. * least 10GB
  5635. */
  5636. if (pf->hw.func_caps.npar_enable &&
  5637. (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
  5638. pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
  5639. netdev_warn(vsi->netdev,
  5640. "The partition detected link speed that is less than 10Gbps\n");
  5641. switch (pf->hw.phy.link_info.link_speed) {
  5642. case I40E_LINK_SPEED_40GB:
  5643. speed = "40 G";
  5644. break;
  5645. case I40E_LINK_SPEED_20GB:
  5646. speed = "20 G";
  5647. break;
  5648. case I40E_LINK_SPEED_25GB:
  5649. speed = "25 G";
  5650. break;
  5651. case I40E_LINK_SPEED_10GB:
  5652. speed = "10 G";
  5653. break;
  5654. case I40E_LINK_SPEED_1GB:
  5655. speed = "1000 M";
  5656. break;
  5657. case I40E_LINK_SPEED_100MB:
  5658. speed = "100 M";
  5659. break;
  5660. default:
  5661. break;
  5662. }
  5663. switch (pf->hw.fc.current_mode) {
  5664. case I40E_FC_FULL:
  5665. fc = "RX/TX";
  5666. break;
  5667. case I40E_FC_TX_PAUSE:
  5668. fc = "TX";
  5669. break;
  5670. case I40E_FC_RX_PAUSE:
  5671. fc = "RX";
  5672. break;
  5673. default:
  5674. fc = "None";
  5675. break;
  5676. }
  5677. if (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) {
  5678. req_fec = ", Requested FEC: None";
  5679. fec = ", FEC: None";
  5680. an = ", Autoneg: False";
  5681. if (pf->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED)
  5682. an = ", Autoneg: True";
  5683. if (pf->hw.phy.link_info.fec_info &
  5684. I40E_AQ_CONFIG_FEC_KR_ENA)
  5685. fec = ", FEC: CL74 FC-FEC/BASE-R";
  5686. else if (pf->hw.phy.link_info.fec_info &
  5687. I40E_AQ_CONFIG_FEC_RS_ENA)
  5688. fec = ", FEC: CL108 RS-FEC";
  5689. /* 'CL108 RS-FEC' should be displayed when RS is requested, or
  5690. * both RS and FC are requested
  5691. */
  5692. if (vsi->back->hw.phy.link_info.req_fec_info &
  5693. (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS)) {
  5694. if (vsi->back->hw.phy.link_info.req_fec_info &
  5695. I40E_AQ_REQUEST_FEC_RS)
  5696. req_fec = ", Requested FEC: CL108 RS-FEC";
  5697. else
  5698. req_fec = ", Requested FEC: CL74 FC-FEC/BASE-R";
  5699. }
  5700. }
  5701. netdev_info(vsi->netdev, "NIC Link is Up, %sbps Full Duplex%s%s%s, Flow Control: %s\n",
  5702. speed, req_fec, fec, an, fc);
  5703. }
  5704. /**
  5705. * i40e_up_complete - Finish the last steps of bringing up a connection
  5706. * @vsi: the VSI being configured
  5707. **/
  5708. static int i40e_up_complete(struct i40e_vsi *vsi)
  5709. {
  5710. struct i40e_pf *pf = vsi->back;
  5711. int err;
  5712. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  5713. i40e_vsi_configure_msix(vsi);
  5714. else
  5715. i40e_configure_msi_and_legacy(vsi);
  5716. /* start rings */
  5717. err = i40e_vsi_start_rings(vsi);
  5718. if (err)
  5719. return err;
  5720. clear_bit(__I40E_VSI_DOWN, vsi->state);
  5721. i40e_napi_enable_all(vsi);
  5722. i40e_vsi_enable_irq(vsi);
  5723. if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
  5724. (vsi->netdev)) {
  5725. i40e_print_link_message(vsi, true);
  5726. netif_tx_start_all_queues(vsi->netdev);
  5727. netif_carrier_on(vsi->netdev);
  5728. }
  5729. /* replay FDIR SB filters */
  5730. if (vsi->type == I40E_VSI_FDIR) {
  5731. /* reset fd counters */
  5732. pf->fd_add_err = 0;
  5733. pf->fd_atr_cnt = 0;
  5734. i40e_fdir_filter_restore(vsi);
  5735. }
  5736. /* On the next run of the service_task, notify any clients of the new
  5737. * opened netdev
  5738. */
  5739. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  5740. i40e_service_event_schedule(pf);
  5741. return 0;
  5742. }
  5743. /**
  5744. * i40e_vsi_reinit_locked - Reset the VSI
  5745. * @vsi: the VSI being configured
  5746. *
  5747. * Rebuild the ring structs after some configuration
  5748. * has changed, e.g. MTU size.
  5749. **/
  5750. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
  5751. {
  5752. struct i40e_pf *pf = vsi->back;
  5753. WARN_ON(in_interrupt());
  5754. while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state))
  5755. usleep_range(1000, 2000);
  5756. i40e_down(vsi);
  5757. i40e_up(vsi);
  5758. clear_bit(__I40E_CONFIG_BUSY, pf->state);
  5759. }
  5760. /**
  5761. * i40e_up - Bring the connection back up after being down
  5762. * @vsi: the VSI being configured
  5763. **/
  5764. int i40e_up(struct i40e_vsi *vsi)
  5765. {
  5766. int err;
  5767. err = i40e_vsi_configure(vsi);
  5768. if (!err)
  5769. err = i40e_up_complete(vsi);
  5770. return err;
  5771. }
  5772. /**
  5773. * i40e_down - Shutdown the connection processing
  5774. * @vsi: the VSI being stopped
  5775. **/
  5776. void i40e_down(struct i40e_vsi *vsi)
  5777. {
  5778. int i;
  5779. /* It is assumed that the caller of this function
  5780. * sets the vsi->state __I40E_VSI_DOWN bit.
  5781. */
  5782. if (vsi->netdev) {
  5783. netif_carrier_off(vsi->netdev);
  5784. netif_tx_disable(vsi->netdev);
  5785. }
  5786. i40e_vsi_disable_irq(vsi);
  5787. i40e_vsi_stop_rings(vsi);
  5788. i40e_napi_disable_all(vsi);
  5789. for (i = 0; i < vsi->num_queue_pairs; i++) {
  5790. i40e_clean_tx_ring(vsi->tx_rings[i]);
  5791. if (i40e_enabled_xdp_vsi(vsi))
  5792. i40e_clean_tx_ring(vsi->xdp_rings[i]);
  5793. i40e_clean_rx_ring(vsi->rx_rings[i]);
  5794. }
  5795. }
  5796. /**
  5797. * i40e_validate_mqprio_qopt- validate queue mapping info
  5798. * @vsi: the VSI being configured
  5799. * @mqprio_qopt: queue parametrs
  5800. **/
  5801. static int i40e_validate_mqprio_qopt(struct i40e_vsi *vsi,
  5802. struct tc_mqprio_qopt_offload *mqprio_qopt)
  5803. {
  5804. u64 sum_max_rate = 0;
  5805. u64 max_rate = 0;
  5806. int i;
  5807. if (mqprio_qopt->qopt.offset[0] != 0 ||
  5808. mqprio_qopt->qopt.num_tc < 1 ||
  5809. mqprio_qopt->qopt.num_tc > I40E_MAX_TRAFFIC_CLASS)
  5810. return -EINVAL;
  5811. for (i = 0; ; i++) {
  5812. if (!mqprio_qopt->qopt.count[i])
  5813. return -EINVAL;
  5814. if (mqprio_qopt->min_rate[i]) {
  5815. dev_err(&vsi->back->pdev->dev,
  5816. "Invalid min tx rate (greater than 0) specified\n");
  5817. return -EINVAL;
  5818. }
  5819. max_rate = mqprio_qopt->max_rate[i];
  5820. do_div(max_rate, I40E_BW_MBPS_DIVISOR);
  5821. sum_max_rate += max_rate;
  5822. if (i >= mqprio_qopt->qopt.num_tc - 1)
  5823. break;
  5824. if (mqprio_qopt->qopt.offset[i + 1] !=
  5825. (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i]))
  5826. return -EINVAL;
  5827. }
  5828. if (vsi->num_queue_pairs <
  5829. (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i])) {
  5830. return -EINVAL;
  5831. }
  5832. if (sum_max_rate > i40e_get_link_speed(vsi)) {
  5833. dev_err(&vsi->back->pdev->dev,
  5834. "Invalid max tx rate specified\n");
  5835. return -EINVAL;
  5836. }
  5837. return 0;
  5838. }
  5839. /**
  5840. * i40e_vsi_set_default_tc_config - set default values for tc configuration
  5841. * @vsi: the VSI being configured
  5842. **/
  5843. static void i40e_vsi_set_default_tc_config(struct i40e_vsi *vsi)
  5844. {
  5845. u16 qcount;
  5846. int i;
  5847. /* Only TC0 is enabled */
  5848. vsi->tc_config.numtc = 1;
  5849. vsi->tc_config.enabled_tc = 1;
  5850. qcount = min_t(int, vsi->alloc_queue_pairs,
  5851. i40e_pf_get_max_q_per_tc(vsi->back));
  5852. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5853. /* For the TC that is not enabled set the offset to to default
  5854. * queue and allocate one queue for the given TC.
  5855. */
  5856. vsi->tc_config.tc_info[i].qoffset = 0;
  5857. if (i == 0)
  5858. vsi->tc_config.tc_info[i].qcount = qcount;
  5859. else
  5860. vsi->tc_config.tc_info[i].qcount = 1;
  5861. vsi->tc_config.tc_info[i].netdev_tc = 0;
  5862. }
  5863. }
  5864. /**
  5865. * i40e_setup_tc - configure multiple traffic classes
  5866. * @netdev: net device to configure
  5867. * @type_data: tc offload data
  5868. **/
  5869. static int i40e_setup_tc(struct net_device *netdev, void *type_data)
  5870. {
  5871. struct tc_mqprio_qopt_offload *mqprio_qopt = type_data;
  5872. struct i40e_netdev_priv *np = netdev_priv(netdev);
  5873. struct i40e_vsi *vsi = np->vsi;
  5874. struct i40e_pf *pf = vsi->back;
  5875. u8 enabled_tc = 0, num_tc, hw;
  5876. bool need_reset = false;
  5877. int ret = -EINVAL;
  5878. u16 mode;
  5879. int i;
  5880. num_tc = mqprio_qopt->qopt.num_tc;
  5881. hw = mqprio_qopt->qopt.hw;
  5882. mode = mqprio_qopt->mode;
  5883. if (!hw) {
  5884. pf->flags &= ~I40E_FLAG_TC_MQPRIO;
  5885. memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt));
  5886. goto config_tc;
  5887. }
  5888. /* Check if MFP enabled */
  5889. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  5890. netdev_info(netdev,
  5891. "Configuring TC not supported in MFP mode\n");
  5892. return ret;
  5893. }
  5894. switch (mode) {
  5895. case TC_MQPRIO_MODE_DCB:
  5896. pf->flags &= ~I40E_FLAG_TC_MQPRIO;
  5897. /* Check if DCB enabled to continue */
  5898. if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  5899. netdev_info(netdev,
  5900. "DCB is not enabled for adapter\n");
  5901. return ret;
  5902. }
  5903. /* Check whether tc count is within enabled limit */
  5904. if (num_tc > i40e_pf_get_num_tc(pf)) {
  5905. netdev_info(netdev,
  5906. "TC count greater than enabled on link for adapter\n");
  5907. return ret;
  5908. }
  5909. break;
  5910. case TC_MQPRIO_MODE_CHANNEL:
  5911. if (pf->flags & I40E_FLAG_DCB_ENABLED) {
  5912. netdev_info(netdev,
  5913. "Full offload of TC Mqprio options is not supported when DCB is enabled\n");
  5914. return ret;
  5915. }
  5916. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  5917. return ret;
  5918. ret = i40e_validate_mqprio_qopt(vsi, mqprio_qopt);
  5919. if (ret)
  5920. return ret;
  5921. memcpy(&vsi->mqprio_qopt, mqprio_qopt,
  5922. sizeof(*mqprio_qopt));
  5923. pf->flags |= I40E_FLAG_TC_MQPRIO;
  5924. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  5925. break;
  5926. default:
  5927. return -EINVAL;
  5928. }
  5929. config_tc:
  5930. /* Generate TC map for number of tc requested */
  5931. for (i = 0; i < num_tc; i++)
  5932. enabled_tc |= BIT(i);
  5933. /* Requesting same TC configuration as already enabled */
  5934. if (enabled_tc == vsi->tc_config.enabled_tc &&
  5935. mode != TC_MQPRIO_MODE_CHANNEL)
  5936. return 0;
  5937. /* Quiesce VSI queues */
  5938. i40e_quiesce_vsi(vsi);
  5939. if (!hw && !(pf->flags & I40E_FLAG_TC_MQPRIO))
  5940. i40e_remove_queue_channels(vsi);
  5941. /* Configure VSI for enabled TCs */
  5942. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  5943. if (ret) {
  5944. netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
  5945. vsi->seid);
  5946. need_reset = true;
  5947. goto exit;
  5948. }
  5949. if (pf->flags & I40E_FLAG_TC_MQPRIO) {
  5950. if (vsi->mqprio_qopt.max_rate[0]) {
  5951. u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
  5952. do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
  5953. ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
  5954. if (!ret) {
  5955. u64 credits = max_tx_rate;
  5956. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  5957. dev_dbg(&vsi->back->pdev->dev,
  5958. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  5959. max_tx_rate,
  5960. credits,
  5961. vsi->seid);
  5962. } else {
  5963. need_reset = true;
  5964. goto exit;
  5965. }
  5966. }
  5967. ret = i40e_configure_queue_channels(vsi);
  5968. if (ret) {
  5969. netdev_info(netdev,
  5970. "Failed configuring queue channels\n");
  5971. need_reset = true;
  5972. goto exit;
  5973. }
  5974. }
  5975. exit:
  5976. /* Reset the configuration data to defaults, only TC0 is enabled */
  5977. if (need_reset) {
  5978. i40e_vsi_set_default_tc_config(vsi);
  5979. need_reset = false;
  5980. }
  5981. /* Unquiesce VSI */
  5982. i40e_unquiesce_vsi(vsi);
  5983. return ret;
  5984. }
  5985. /**
  5986. * i40e_set_cld_element - sets cloud filter element data
  5987. * @filter: cloud filter rule
  5988. * @cld: ptr to cloud filter element data
  5989. *
  5990. * This is helper function to copy data into cloud filter element
  5991. **/
  5992. static inline void
  5993. i40e_set_cld_element(struct i40e_cloud_filter *filter,
  5994. struct i40e_aqc_cloud_filters_element_data *cld)
  5995. {
  5996. int i, j;
  5997. u32 ipa;
  5998. memset(cld, 0, sizeof(*cld));
  5999. ether_addr_copy(cld->outer_mac, filter->dst_mac);
  6000. ether_addr_copy(cld->inner_mac, filter->src_mac);
  6001. if (filter->n_proto != ETH_P_IP && filter->n_proto != ETH_P_IPV6)
  6002. return;
  6003. if (filter->n_proto == ETH_P_IPV6) {
  6004. #define IPV6_MAX_INDEX (ARRAY_SIZE(filter->dst_ipv6) - 1)
  6005. for (i = 0, j = 0; i < ARRAY_SIZE(filter->dst_ipv6);
  6006. i++, j += 2) {
  6007. ipa = be32_to_cpu(filter->dst_ipv6[IPV6_MAX_INDEX - i]);
  6008. ipa = cpu_to_le32(ipa);
  6009. memcpy(&cld->ipaddr.raw_v6.data[j], &ipa, sizeof(ipa));
  6010. }
  6011. } else {
  6012. ipa = be32_to_cpu(filter->dst_ipv4);
  6013. memcpy(&cld->ipaddr.v4.data, &ipa, sizeof(ipa));
  6014. }
  6015. cld->inner_vlan = cpu_to_le16(ntohs(filter->vlan_id));
  6016. /* tenant_id is not supported by FW now, once the support is enabled
  6017. * fill the cld->tenant_id with cpu_to_le32(filter->tenant_id)
  6018. */
  6019. if (filter->tenant_id)
  6020. return;
  6021. }
  6022. /**
  6023. * i40e_add_del_cloud_filter - Add/del cloud filter
  6024. * @vsi: pointer to VSI
  6025. * @filter: cloud filter rule
  6026. * @add: if true, add, if false, delete
  6027. *
  6028. * Add or delete a cloud filter for a specific flow spec.
  6029. * Returns 0 if the filter were successfully added.
  6030. **/
  6031. static int i40e_add_del_cloud_filter(struct i40e_vsi *vsi,
  6032. struct i40e_cloud_filter *filter, bool add)
  6033. {
  6034. struct i40e_aqc_cloud_filters_element_data cld_filter;
  6035. struct i40e_pf *pf = vsi->back;
  6036. int ret;
  6037. static const u16 flag_table[128] = {
  6038. [I40E_CLOUD_FILTER_FLAGS_OMAC] =
  6039. I40E_AQC_ADD_CLOUD_FILTER_OMAC,
  6040. [I40E_CLOUD_FILTER_FLAGS_IMAC] =
  6041. I40E_AQC_ADD_CLOUD_FILTER_IMAC,
  6042. [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN] =
  6043. I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN,
  6044. [I40E_CLOUD_FILTER_FLAGS_IMAC_TEN_ID] =
  6045. I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID,
  6046. [I40E_CLOUD_FILTER_FLAGS_OMAC_TEN_ID_IMAC] =
  6047. I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC,
  6048. [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN_TEN_ID] =
  6049. I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID,
  6050. [I40E_CLOUD_FILTER_FLAGS_IIP] =
  6051. I40E_AQC_ADD_CLOUD_FILTER_IIP,
  6052. };
  6053. if (filter->flags >= ARRAY_SIZE(flag_table))
  6054. return I40E_ERR_CONFIG;
  6055. /* copy element needed to add cloud filter from filter */
  6056. i40e_set_cld_element(filter, &cld_filter);
  6057. if (filter->tunnel_type != I40E_CLOUD_TNL_TYPE_NONE)
  6058. cld_filter.flags = cpu_to_le16(filter->tunnel_type <<
  6059. I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT);
  6060. if (filter->n_proto == ETH_P_IPV6)
  6061. cld_filter.flags |= cpu_to_le16(flag_table[filter->flags] |
  6062. I40E_AQC_ADD_CLOUD_FLAGS_IPV6);
  6063. else
  6064. cld_filter.flags |= cpu_to_le16(flag_table[filter->flags] |
  6065. I40E_AQC_ADD_CLOUD_FLAGS_IPV4);
  6066. if (add)
  6067. ret = i40e_aq_add_cloud_filters(&pf->hw, filter->seid,
  6068. &cld_filter, 1);
  6069. else
  6070. ret = i40e_aq_rem_cloud_filters(&pf->hw, filter->seid,
  6071. &cld_filter, 1);
  6072. if (ret)
  6073. dev_dbg(&pf->pdev->dev,
  6074. "Failed to %s cloud filter using l4 port %u, err %d aq_err %d\n",
  6075. add ? "add" : "delete", filter->dst_port, ret,
  6076. pf->hw.aq.asq_last_status);
  6077. else
  6078. dev_info(&pf->pdev->dev,
  6079. "%s cloud filter for VSI: %d\n",
  6080. add ? "Added" : "Deleted", filter->seid);
  6081. return ret;
  6082. }
  6083. /**
  6084. * i40e_add_del_cloud_filter_big_buf - Add/del cloud filter using big_buf
  6085. * @vsi: pointer to VSI
  6086. * @filter: cloud filter rule
  6087. * @add: if true, add, if false, delete
  6088. *
  6089. * Add or delete a cloud filter for a specific flow spec using big buffer.
  6090. * Returns 0 if the filter were successfully added.
  6091. **/
  6092. static int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi *vsi,
  6093. struct i40e_cloud_filter *filter,
  6094. bool add)
  6095. {
  6096. struct i40e_aqc_cloud_filters_element_bb cld_filter;
  6097. struct i40e_pf *pf = vsi->back;
  6098. int ret;
  6099. /* Both (src/dst) valid mac_addr are not supported */
  6100. if ((is_valid_ether_addr(filter->dst_mac) &&
  6101. is_valid_ether_addr(filter->src_mac)) ||
  6102. (is_multicast_ether_addr(filter->dst_mac) &&
  6103. is_multicast_ether_addr(filter->src_mac)))
  6104. return -EINVAL;
  6105. /* Make sure port is specified, otherwise bail out, for channel
  6106. * specific cloud filter needs 'L4 port' to be non-zero
  6107. */
  6108. if (!filter->dst_port)
  6109. return -EINVAL;
  6110. /* adding filter using src_port/src_ip is not supported at this stage */
  6111. if (filter->src_port || filter->src_ipv4 ||
  6112. !ipv6_addr_any(&filter->ip.v6.src_ip6))
  6113. return -EINVAL;
  6114. /* copy element needed to add cloud filter from filter */
  6115. i40e_set_cld_element(filter, &cld_filter.element);
  6116. if (is_valid_ether_addr(filter->dst_mac) ||
  6117. is_valid_ether_addr(filter->src_mac) ||
  6118. is_multicast_ether_addr(filter->dst_mac) ||
  6119. is_multicast_ether_addr(filter->src_mac)) {
  6120. /* MAC + IP : unsupported mode */
  6121. if (filter->dst_ipv4)
  6122. return -EINVAL;
  6123. /* since we validated that L4 port must be valid before
  6124. * we get here, start with respective "flags" value
  6125. * and update if vlan is present or not
  6126. */
  6127. cld_filter.element.flags =
  6128. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_PORT);
  6129. if (filter->vlan_id) {
  6130. cld_filter.element.flags =
  6131. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_VLAN_PORT);
  6132. }
  6133. } else if (filter->dst_ipv4 ||
  6134. !ipv6_addr_any(&filter->ip.v6.dst_ip6)) {
  6135. cld_filter.element.flags =
  6136. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_IP_PORT);
  6137. if (filter->n_proto == ETH_P_IPV6)
  6138. cld_filter.element.flags |=
  6139. cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV6);
  6140. else
  6141. cld_filter.element.flags |=
  6142. cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV4);
  6143. } else {
  6144. dev_err(&pf->pdev->dev,
  6145. "either mac or ip has to be valid for cloud filter\n");
  6146. return -EINVAL;
  6147. }
  6148. /* Now copy L4 port in Byte 6..7 in general fields */
  6149. cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X16_WORD0] =
  6150. be16_to_cpu(filter->dst_port);
  6151. if (add) {
  6152. /* Validate current device switch mode, change if necessary */
  6153. ret = i40e_validate_and_set_switch_mode(vsi);
  6154. if (ret) {
  6155. dev_err(&pf->pdev->dev,
  6156. "failed to set switch mode, ret %d\n",
  6157. ret);
  6158. return ret;
  6159. }
  6160. ret = i40e_aq_add_cloud_filters_bb(&pf->hw, filter->seid,
  6161. &cld_filter, 1);
  6162. } else {
  6163. ret = i40e_aq_rem_cloud_filters_bb(&pf->hw, filter->seid,
  6164. &cld_filter, 1);
  6165. }
  6166. if (ret)
  6167. dev_dbg(&pf->pdev->dev,
  6168. "Failed to %s cloud filter(big buffer) err %d aq_err %d\n",
  6169. add ? "add" : "delete", ret, pf->hw.aq.asq_last_status);
  6170. else
  6171. dev_info(&pf->pdev->dev,
  6172. "%s cloud filter for VSI: %d, L4 port: %d\n",
  6173. add ? "add" : "delete", filter->seid,
  6174. ntohs(filter->dst_port));
  6175. return ret;
  6176. }
  6177. /**
  6178. * i40e_parse_cls_flower - Parse tc flower filters provided by kernel
  6179. * @vsi: Pointer to VSI
  6180. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6181. * @filter: Pointer to cloud filter structure
  6182. *
  6183. **/
  6184. static int i40e_parse_cls_flower(struct i40e_vsi *vsi,
  6185. struct tc_cls_flower_offload *f,
  6186. struct i40e_cloud_filter *filter)
  6187. {
  6188. u16 n_proto_mask = 0, n_proto_key = 0, addr_type = 0;
  6189. struct i40e_pf *pf = vsi->back;
  6190. u8 field_flags = 0;
  6191. if (f->dissector->used_keys &
  6192. ~(BIT(FLOW_DISSECTOR_KEY_CONTROL) |
  6193. BIT(FLOW_DISSECTOR_KEY_BASIC) |
  6194. BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) |
  6195. BIT(FLOW_DISSECTOR_KEY_VLAN) |
  6196. BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
  6197. BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
  6198. BIT(FLOW_DISSECTOR_KEY_PORTS) |
  6199. BIT(FLOW_DISSECTOR_KEY_ENC_KEYID))) {
  6200. dev_err(&pf->pdev->dev, "Unsupported key used: 0x%x\n",
  6201. f->dissector->used_keys);
  6202. return -EOPNOTSUPP;
  6203. }
  6204. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ENC_KEYID)) {
  6205. struct flow_dissector_key_keyid *key =
  6206. skb_flow_dissector_target(f->dissector,
  6207. FLOW_DISSECTOR_KEY_ENC_KEYID,
  6208. f->key);
  6209. struct flow_dissector_key_keyid *mask =
  6210. skb_flow_dissector_target(f->dissector,
  6211. FLOW_DISSECTOR_KEY_ENC_KEYID,
  6212. f->mask);
  6213. if (mask->keyid != 0)
  6214. field_flags |= I40E_CLOUD_FIELD_TEN_ID;
  6215. filter->tenant_id = be32_to_cpu(key->keyid);
  6216. }
  6217. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_BASIC)) {
  6218. struct flow_dissector_key_basic *key =
  6219. skb_flow_dissector_target(f->dissector,
  6220. FLOW_DISSECTOR_KEY_BASIC,
  6221. f->key);
  6222. struct flow_dissector_key_basic *mask =
  6223. skb_flow_dissector_target(f->dissector,
  6224. FLOW_DISSECTOR_KEY_BASIC,
  6225. f->mask);
  6226. n_proto_key = ntohs(key->n_proto);
  6227. n_proto_mask = ntohs(mask->n_proto);
  6228. if (n_proto_key == ETH_P_ALL) {
  6229. n_proto_key = 0;
  6230. n_proto_mask = 0;
  6231. }
  6232. filter->n_proto = n_proto_key & n_proto_mask;
  6233. filter->ip_proto = key->ip_proto;
  6234. }
  6235. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
  6236. struct flow_dissector_key_eth_addrs *key =
  6237. skb_flow_dissector_target(f->dissector,
  6238. FLOW_DISSECTOR_KEY_ETH_ADDRS,
  6239. f->key);
  6240. struct flow_dissector_key_eth_addrs *mask =
  6241. skb_flow_dissector_target(f->dissector,
  6242. FLOW_DISSECTOR_KEY_ETH_ADDRS,
  6243. f->mask);
  6244. /* use is_broadcast and is_zero to check for all 0xf or 0 */
  6245. if (!is_zero_ether_addr(mask->dst)) {
  6246. if (is_broadcast_ether_addr(mask->dst)) {
  6247. field_flags |= I40E_CLOUD_FIELD_OMAC;
  6248. } else {
  6249. dev_err(&pf->pdev->dev, "Bad ether dest mask %pM\n",
  6250. mask->dst);
  6251. return I40E_ERR_CONFIG;
  6252. }
  6253. }
  6254. if (!is_zero_ether_addr(mask->src)) {
  6255. if (is_broadcast_ether_addr(mask->src)) {
  6256. field_flags |= I40E_CLOUD_FIELD_IMAC;
  6257. } else {
  6258. dev_err(&pf->pdev->dev, "Bad ether src mask %pM\n",
  6259. mask->src);
  6260. return I40E_ERR_CONFIG;
  6261. }
  6262. }
  6263. ether_addr_copy(filter->dst_mac, key->dst);
  6264. ether_addr_copy(filter->src_mac, key->src);
  6265. }
  6266. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_VLAN)) {
  6267. struct flow_dissector_key_vlan *key =
  6268. skb_flow_dissector_target(f->dissector,
  6269. FLOW_DISSECTOR_KEY_VLAN,
  6270. f->key);
  6271. struct flow_dissector_key_vlan *mask =
  6272. skb_flow_dissector_target(f->dissector,
  6273. FLOW_DISSECTOR_KEY_VLAN,
  6274. f->mask);
  6275. if (mask->vlan_id) {
  6276. if (mask->vlan_id == VLAN_VID_MASK) {
  6277. field_flags |= I40E_CLOUD_FIELD_IVLAN;
  6278. } else {
  6279. dev_err(&pf->pdev->dev, "Bad vlan mask 0x%04x\n",
  6280. mask->vlan_id);
  6281. return I40E_ERR_CONFIG;
  6282. }
  6283. }
  6284. filter->vlan_id = cpu_to_be16(key->vlan_id);
  6285. }
  6286. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_CONTROL)) {
  6287. struct flow_dissector_key_control *key =
  6288. skb_flow_dissector_target(f->dissector,
  6289. FLOW_DISSECTOR_KEY_CONTROL,
  6290. f->key);
  6291. addr_type = key->addr_type;
  6292. }
  6293. if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
  6294. struct flow_dissector_key_ipv4_addrs *key =
  6295. skb_flow_dissector_target(f->dissector,
  6296. FLOW_DISSECTOR_KEY_IPV4_ADDRS,
  6297. f->key);
  6298. struct flow_dissector_key_ipv4_addrs *mask =
  6299. skb_flow_dissector_target(f->dissector,
  6300. FLOW_DISSECTOR_KEY_IPV4_ADDRS,
  6301. f->mask);
  6302. if (mask->dst) {
  6303. if (mask->dst == cpu_to_be32(0xffffffff)) {
  6304. field_flags |= I40E_CLOUD_FIELD_IIP;
  6305. } else {
  6306. mask->dst = be32_to_cpu(mask->dst);
  6307. dev_err(&pf->pdev->dev, "Bad ip dst mask %pI4\n",
  6308. &mask->dst);
  6309. return I40E_ERR_CONFIG;
  6310. }
  6311. }
  6312. if (mask->src) {
  6313. if (mask->src == cpu_to_be32(0xffffffff)) {
  6314. field_flags |= I40E_CLOUD_FIELD_IIP;
  6315. } else {
  6316. mask->src = be32_to_cpu(mask->src);
  6317. dev_err(&pf->pdev->dev, "Bad ip src mask %pI4\n",
  6318. &mask->src);
  6319. return I40E_ERR_CONFIG;
  6320. }
  6321. }
  6322. if (field_flags & I40E_CLOUD_FIELD_TEN_ID) {
  6323. dev_err(&pf->pdev->dev, "Tenant id not allowed for ip filter\n");
  6324. return I40E_ERR_CONFIG;
  6325. }
  6326. filter->dst_ipv4 = key->dst;
  6327. filter->src_ipv4 = key->src;
  6328. }
  6329. if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
  6330. struct flow_dissector_key_ipv6_addrs *key =
  6331. skb_flow_dissector_target(f->dissector,
  6332. FLOW_DISSECTOR_KEY_IPV6_ADDRS,
  6333. f->key);
  6334. struct flow_dissector_key_ipv6_addrs *mask =
  6335. skb_flow_dissector_target(f->dissector,
  6336. FLOW_DISSECTOR_KEY_IPV6_ADDRS,
  6337. f->mask);
  6338. /* src and dest IPV6 address should not be LOOPBACK
  6339. * (0:0:0:0:0:0:0:1), which can be represented as ::1
  6340. */
  6341. if (ipv6_addr_loopback(&key->dst) ||
  6342. ipv6_addr_loopback(&key->src)) {
  6343. dev_err(&pf->pdev->dev,
  6344. "Bad ipv6, addr is LOOPBACK\n");
  6345. return I40E_ERR_CONFIG;
  6346. }
  6347. if (!ipv6_addr_any(&mask->dst) || !ipv6_addr_any(&mask->src))
  6348. field_flags |= I40E_CLOUD_FIELD_IIP;
  6349. memcpy(&filter->src_ipv6, &key->src.s6_addr32,
  6350. sizeof(filter->src_ipv6));
  6351. memcpy(&filter->dst_ipv6, &key->dst.s6_addr32,
  6352. sizeof(filter->dst_ipv6));
  6353. }
  6354. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_PORTS)) {
  6355. struct flow_dissector_key_ports *key =
  6356. skb_flow_dissector_target(f->dissector,
  6357. FLOW_DISSECTOR_KEY_PORTS,
  6358. f->key);
  6359. struct flow_dissector_key_ports *mask =
  6360. skb_flow_dissector_target(f->dissector,
  6361. FLOW_DISSECTOR_KEY_PORTS,
  6362. f->mask);
  6363. if (mask->src) {
  6364. if (mask->src == cpu_to_be16(0xffff)) {
  6365. field_flags |= I40E_CLOUD_FIELD_IIP;
  6366. } else {
  6367. dev_err(&pf->pdev->dev, "Bad src port mask 0x%04x\n",
  6368. be16_to_cpu(mask->src));
  6369. return I40E_ERR_CONFIG;
  6370. }
  6371. }
  6372. if (mask->dst) {
  6373. if (mask->dst == cpu_to_be16(0xffff)) {
  6374. field_flags |= I40E_CLOUD_FIELD_IIP;
  6375. } else {
  6376. dev_err(&pf->pdev->dev, "Bad dst port mask 0x%04x\n",
  6377. be16_to_cpu(mask->dst));
  6378. return I40E_ERR_CONFIG;
  6379. }
  6380. }
  6381. filter->dst_port = key->dst;
  6382. filter->src_port = key->src;
  6383. switch (filter->ip_proto) {
  6384. case IPPROTO_TCP:
  6385. case IPPROTO_UDP:
  6386. break;
  6387. default:
  6388. dev_err(&pf->pdev->dev,
  6389. "Only UDP and TCP transport are supported\n");
  6390. return -EINVAL;
  6391. }
  6392. }
  6393. filter->flags = field_flags;
  6394. return 0;
  6395. }
  6396. /**
  6397. * i40e_handle_tclass: Forward to a traffic class on the device
  6398. * @vsi: Pointer to VSI
  6399. * @tc: traffic class index on the device
  6400. * @filter: Pointer to cloud filter structure
  6401. *
  6402. **/
  6403. static int i40e_handle_tclass(struct i40e_vsi *vsi, u32 tc,
  6404. struct i40e_cloud_filter *filter)
  6405. {
  6406. struct i40e_channel *ch, *ch_tmp;
  6407. /* direct to a traffic class on the same device */
  6408. if (tc == 0) {
  6409. filter->seid = vsi->seid;
  6410. return 0;
  6411. } else if (vsi->tc_config.enabled_tc & BIT(tc)) {
  6412. if (!filter->dst_port) {
  6413. dev_err(&vsi->back->pdev->dev,
  6414. "Specify destination port to direct to traffic class that is not default\n");
  6415. return -EINVAL;
  6416. }
  6417. if (list_empty(&vsi->ch_list))
  6418. return -EINVAL;
  6419. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list,
  6420. list) {
  6421. if (ch->seid == vsi->tc_seid_map[tc])
  6422. filter->seid = ch->seid;
  6423. }
  6424. return 0;
  6425. }
  6426. dev_err(&vsi->back->pdev->dev, "TC is not enabled\n");
  6427. return -EINVAL;
  6428. }
  6429. /**
  6430. * i40e_configure_clsflower - Configure tc flower filters
  6431. * @vsi: Pointer to VSI
  6432. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6433. *
  6434. **/
  6435. static int i40e_configure_clsflower(struct i40e_vsi *vsi,
  6436. struct tc_cls_flower_offload *cls_flower)
  6437. {
  6438. int tc = tc_classid_to_hwtc(vsi->netdev, cls_flower->classid);
  6439. struct i40e_cloud_filter *filter = NULL;
  6440. struct i40e_pf *pf = vsi->back;
  6441. int err = 0;
  6442. if (tc < 0) {
  6443. dev_err(&vsi->back->pdev->dev, "Invalid traffic class\n");
  6444. return -EINVAL;
  6445. }
  6446. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
  6447. test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
  6448. return -EBUSY;
  6449. if (pf->fdir_pf_active_filters ||
  6450. (!hlist_empty(&pf->fdir_filter_list))) {
  6451. dev_err(&vsi->back->pdev->dev,
  6452. "Flow Director Sideband filters exists, turn ntuple off to configure cloud filters\n");
  6453. return -EINVAL;
  6454. }
  6455. if (vsi->back->flags & I40E_FLAG_FD_SB_ENABLED) {
  6456. dev_err(&vsi->back->pdev->dev,
  6457. "Disable Flow Director Sideband, configuring Cloud filters via tc-flower\n");
  6458. vsi->back->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  6459. vsi->back->flags |= I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6460. }
  6461. filter = kzalloc(sizeof(*filter), GFP_KERNEL);
  6462. if (!filter)
  6463. return -ENOMEM;
  6464. filter->cookie = cls_flower->cookie;
  6465. err = i40e_parse_cls_flower(vsi, cls_flower, filter);
  6466. if (err < 0)
  6467. goto err;
  6468. err = i40e_handle_tclass(vsi, tc, filter);
  6469. if (err < 0)
  6470. goto err;
  6471. /* Add cloud filter */
  6472. if (filter->dst_port)
  6473. err = i40e_add_del_cloud_filter_big_buf(vsi, filter, true);
  6474. else
  6475. err = i40e_add_del_cloud_filter(vsi, filter, true);
  6476. if (err) {
  6477. dev_err(&pf->pdev->dev,
  6478. "Failed to add cloud filter, err %s\n",
  6479. i40e_stat_str(&pf->hw, err));
  6480. err = i40e_aq_rc_to_posix(err, pf->hw.aq.asq_last_status);
  6481. goto err;
  6482. }
  6483. /* add filter to the ordered list */
  6484. INIT_HLIST_NODE(&filter->cloud_node);
  6485. hlist_add_head(&filter->cloud_node, &pf->cloud_filter_list);
  6486. pf->num_cloud_filters++;
  6487. return err;
  6488. err:
  6489. kfree(filter);
  6490. return err;
  6491. }
  6492. /**
  6493. * i40e_find_cloud_filter - Find the could filter in the list
  6494. * @vsi: Pointer to VSI
  6495. * @cookie: filter specific cookie
  6496. *
  6497. **/
  6498. static struct i40e_cloud_filter *i40e_find_cloud_filter(struct i40e_vsi *vsi,
  6499. unsigned long *cookie)
  6500. {
  6501. struct i40e_cloud_filter *filter = NULL;
  6502. struct hlist_node *node2;
  6503. hlist_for_each_entry_safe(filter, node2,
  6504. &vsi->back->cloud_filter_list, cloud_node)
  6505. if (!memcmp(cookie, &filter->cookie, sizeof(filter->cookie)))
  6506. return filter;
  6507. return NULL;
  6508. }
  6509. /**
  6510. * i40e_delete_clsflower - Remove tc flower filters
  6511. * @vsi: Pointer to VSI
  6512. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6513. *
  6514. **/
  6515. static int i40e_delete_clsflower(struct i40e_vsi *vsi,
  6516. struct tc_cls_flower_offload *cls_flower)
  6517. {
  6518. struct i40e_cloud_filter *filter = NULL;
  6519. struct i40e_pf *pf = vsi->back;
  6520. int err = 0;
  6521. filter = i40e_find_cloud_filter(vsi, &cls_flower->cookie);
  6522. if (!filter)
  6523. return -EINVAL;
  6524. hash_del(&filter->cloud_node);
  6525. if (filter->dst_port)
  6526. err = i40e_add_del_cloud_filter_big_buf(vsi, filter, false);
  6527. else
  6528. err = i40e_add_del_cloud_filter(vsi, filter, false);
  6529. kfree(filter);
  6530. if (err) {
  6531. dev_err(&pf->pdev->dev,
  6532. "Failed to delete cloud filter, err %s\n",
  6533. i40e_stat_str(&pf->hw, err));
  6534. return i40e_aq_rc_to_posix(err, pf->hw.aq.asq_last_status);
  6535. }
  6536. pf->num_cloud_filters--;
  6537. if (!pf->num_cloud_filters)
  6538. if ((pf->flags & I40E_FLAG_FD_SB_TO_CLOUD_FILTER) &&
  6539. !(pf->flags & I40E_FLAG_FD_SB_INACTIVE)) {
  6540. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  6541. pf->flags &= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6542. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  6543. }
  6544. return 0;
  6545. }
  6546. /**
  6547. * i40e_setup_tc_cls_flower - flower classifier offloads
  6548. * @netdev: net device to configure
  6549. * @type_data: offload data
  6550. **/
  6551. static int i40e_setup_tc_cls_flower(struct i40e_netdev_priv *np,
  6552. struct tc_cls_flower_offload *cls_flower)
  6553. {
  6554. struct i40e_vsi *vsi = np->vsi;
  6555. if (cls_flower->common.chain_index)
  6556. return -EOPNOTSUPP;
  6557. switch (cls_flower->command) {
  6558. case TC_CLSFLOWER_REPLACE:
  6559. return i40e_configure_clsflower(vsi, cls_flower);
  6560. case TC_CLSFLOWER_DESTROY:
  6561. return i40e_delete_clsflower(vsi, cls_flower);
  6562. case TC_CLSFLOWER_STATS:
  6563. return -EOPNOTSUPP;
  6564. default:
  6565. return -EINVAL;
  6566. }
  6567. }
  6568. static int i40e_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
  6569. void *cb_priv)
  6570. {
  6571. struct i40e_netdev_priv *np = cb_priv;
  6572. switch (type) {
  6573. case TC_SETUP_CLSFLOWER:
  6574. return i40e_setup_tc_cls_flower(np, type_data);
  6575. default:
  6576. return -EOPNOTSUPP;
  6577. }
  6578. }
  6579. static int i40e_setup_tc_block(struct net_device *dev,
  6580. struct tc_block_offload *f)
  6581. {
  6582. struct i40e_netdev_priv *np = netdev_priv(dev);
  6583. if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
  6584. return -EOPNOTSUPP;
  6585. switch (f->command) {
  6586. case TC_BLOCK_BIND:
  6587. return tcf_block_cb_register(f->block, i40e_setup_tc_block_cb,
  6588. np, np);
  6589. case TC_BLOCK_UNBIND:
  6590. tcf_block_cb_unregister(f->block, i40e_setup_tc_block_cb, np);
  6591. return 0;
  6592. default:
  6593. return -EOPNOTSUPP;
  6594. }
  6595. }
  6596. static int __i40e_setup_tc(struct net_device *netdev, enum tc_setup_type type,
  6597. void *type_data)
  6598. {
  6599. switch (type) {
  6600. case TC_SETUP_QDISC_MQPRIO:
  6601. return i40e_setup_tc(netdev, type_data);
  6602. case TC_SETUP_BLOCK:
  6603. return i40e_setup_tc_block(netdev, type_data);
  6604. default:
  6605. return -EOPNOTSUPP;
  6606. }
  6607. }
  6608. /**
  6609. * i40e_open - Called when a network interface is made active
  6610. * @netdev: network interface device structure
  6611. *
  6612. * The open entry point is called when a network interface is made
  6613. * active by the system (IFF_UP). At this point all resources needed
  6614. * for transmit and receive operations are allocated, the interrupt
  6615. * handler is registered with the OS, the netdev watchdog subtask is
  6616. * enabled, and the stack is notified that the interface is ready.
  6617. *
  6618. * Returns 0 on success, negative value on failure
  6619. **/
  6620. int i40e_open(struct net_device *netdev)
  6621. {
  6622. struct i40e_netdev_priv *np = netdev_priv(netdev);
  6623. struct i40e_vsi *vsi = np->vsi;
  6624. struct i40e_pf *pf = vsi->back;
  6625. int err;
  6626. /* disallow open during test or if eeprom is broken */
  6627. if (test_bit(__I40E_TESTING, pf->state) ||
  6628. test_bit(__I40E_BAD_EEPROM, pf->state))
  6629. return -EBUSY;
  6630. netif_carrier_off(netdev);
  6631. err = i40e_vsi_open(vsi);
  6632. if (err)
  6633. return err;
  6634. /* configure global TSO hardware offload settings */
  6635. wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
  6636. TCP_FLAG_FIN) >> 16);
  6637. wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
  6638. TCP_FLAG_FIN |
  6639. TCP_FLAG_CWR) >> 16);
  6640. wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
  6641. udp_tunnel_get_rx_info(netdev);
  6642. return 0;
  6643. }
  6644. /**
  6645. * i40e_vsi_open -
  6646. * @vsi: the VSI to open
  6647. *
  6648. * Finish initialization of the VSI.
  6649. *
  6650. * Returns 0 on success, negative value on failure
  6651. *
  6652. * Note: expects to be called while under rtnl_lock()
  6653. **/
  6654. int i40e_vsi_open(struct i40e_vsi *vsi)
  6655. {
  6656. struct i40e_pf *pf = vsi->back;
  6657. char int_name[I40E_INT_NAME_STR_LEN];
  6658. int err;
  6659. /* allocate descriptors */
  6660. err = i40e_vsi_setup_tx_resources(vsi);
  6661. if (err)
  6662. goto err_setup_tx;
  6663. err = i40e_vsi_setup_rx_resources(vsi);
  6664. if (err)
  6665. goto err_setup_rx;
  6666. err = i40e_vsi_configure(vsi);
  6667. if (err)
  6668. goto err_setup_rx;
  6669. if (vsi->netdev) {
  6670. snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
  6671. dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
  6672. err = i40e_vsi_request_irq(vsi, int_name);
  6673. if (err)
  6674. goto err_setup_rx;
  6675. /* Notify the stack of the actual queue counts. */
  6676. err = netif_set_real_num_tx_queues(vsi->netdev,
  6677. vsi->num_queue_pairs);
  6678. if (err)
  6679. goto err_set_queues;
  6680. err = netif_set_real_num_rx_queues(vsi->netdev,
  6681. vsi->num_queue_pairs);
  6682. if (err)
  6683. goto err_set_queues;
  6684. } else if (vsi->type == I40E_VSI_FDIR) {
  6685. snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
  6686. dev_driver_string(&pf->pdev->dev),
  6687. dev_name(&pf->pdev->dev));
  6688. err = i40e_vsi_request_irq(vsi, int_name);
  6689. } else {
  6690. err = -EINVAL;
  6691. goto err_setup_rx;
  6692. }
  6693. err = i40e_up_complete(vsi);
  6694. if (err)
  6695. goto err_up_complete;
  6696. return 0;
  6697. err_up_complete:
  6698. i40e_down(vsi);
  6699. err_set_queues:
  6700. i40e_vsi_free_irq(vsi);
  6701. err_setup_rx:
  6702. i40e_vsi_free_rx_resources(vsi);
  6703. err_setup_tx:
  6704. i40e_vsi_free_tx_resources(vsi);
  6705. if (vsi == pf->vsi[pf->lan_vsi])
  6706. i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
  6707. return err;
  6708. }
  6709. /**
  6710. * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
  6711. * @pf: Pointer to PF
  6712. *
  6713. * This function destroys the hlist where all the Flow Director
  6714. * filters were saved.
  6715. **/
  6716. static void i40e_fdir_filter_exit(struct i40e_pf *pf)
  6717. {
  6718. struct i40e_fdir_filter *filter;
  6719. struct i40e_flex_pit *pit_entry, *tmp;
  6720. struct hlist_node *node2;
  6721. hlist_for_each_entry_safe(filter, node2,
  6722. &pf->fdir_filter_list, fdir_node) {
  6723. hlist_del(&filter->fdir_node);
  6724. kfree(filter);
  6725. }
  6726. list_for_each_entry_safe(pit_entry, tmp, &pf->l3_flex_pit_list, list) {
  6727. list_del(&pit_entry->list);
  6728. kfree(pit_entry);
  6729. }
  6730. INIT_LIST_HEAD(&pf->l3_flex_pit_list);
  6731. list_for_each_entry_safe(pit_entry, tmp, &pf->l4_flex_pit_list, list) {
  6732. list_del(&pit_entry->list);
  6733. kfree(pit_entry);
  6734. }
  6735. INIT_LIST_HEAD(&pf->l4_flex_pit_list);
  6736. pf->fdir_pf_active_filters = 0;
  6737. pf->fd_tcp4_filter_cnt = 0;
  6738. pf->fd_udp4_filter_cnt = 0;
  6739. pf->fd_sctp4_filter_cnt = 0;
  6740. pf->fd_ip4_filter_cnt = 0;
  6741. /* Reprogram the default input set for TCP/IPv4 */
  6742. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
  6743. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6744. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6745. /* Reprogram the default input set for UDP/IPv4 */
  6746. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_UDP,
  6747. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6748. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6749. /* Reprogram the default input set for SCTP/IPv4 */
  6750. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP,
  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 Other/IPv4 */
  6754. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER,
  6755. I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
  6756. }
  6757. /**
  6758. * i40e_cloud_filter_exit - Cleans up the cloud filters
  6759. * @pf: Pointer to PF
  6760. *
  6761. * This function destroys the hlist where all the cloud filters
  6762. * were saved.
  6763. **/
  6764. static void i40e_cloud_filter_exit(struct i40e_pf *pf)
  6765. {
  6766. struct i40e_cloud_filter *cfilter;
  6767. struct hlist_node *node;
  6768. hlist_for_each_entry_safe(cfilter, node,
  6769. &pf->cloud_filter_list, cloud_node) {
  6770. hlist_del(&cfilter->cloud_node);
  6771. kfree(cfilter);
  6772. }
  6773. pf->num_cloud_filters = 0;
  6774. if ((pf->flags & I40E_FLAG_FD_SB_TO_CLOUD_FILTER) &&
  6775. !(pf->flags & I40E_FLAG_FD_SB_INACTIVE)) {
  6776. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  6777. pf->flags &= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6778. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  6779. }
  6780. }
  6781. /**
  6782. * i40e_close - Disables a network interface
  6783. * @netdev: network interface device structure
  6784. *
  6785. * The close entry point is called when an interface is de-activated
  6786. * by the OS. The hardware is still under the driver's control, but
  6787. * this netdev interface is disabled.
  6788. *
  6789. * Returns 0, this is not allowed to fail
  6790. **/
  6791. int i40e_close(struct net_device *netdev)
  6792. {
  6793. struct i40e_netdev_priv *np = netdev_priv(netdev);
  6794. struct i40e_vsi *vsi = np->vsi;
  6795. i40e_vsi_close(vsi);
  6796. return 0;
  6797. }
  6798. /**
  6799. * i40e_do_reset - Start a PF or Core Reset sequence
  6800. * @pf: board private structure
  6801. * @reset_flags: which reset is requested
  6802. * @lock_acquired: indicates whether or not the lock has been acquired
  6803. * before this function was called.
  6804. *
  6805. * The essential difference in resets is that the PF Reset
  6806. * doesn't clear the packet buffers, doesn't reset the PE
  6807. * firmware, and doesn't bother the other PFs on the chip.
  6808. **/
  6809. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags, bool lock_acquired)
  6810. {
  6811. u32 val;
  6812. WARN_ON(in_interrupt());
  6813. /* do the biggest reset indicated */
  6814. if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
  6815. /* Request a Global Reset
  6816. *
  6817. * This will start the chip's countdown to the actual full
  6818. * chip reset event, and a warning interrupt to be sent
  6819. * to all PFs, including the requestor. Our handler
  6820. * for the warning interrupt will deal with the shutdown
  6821. * and recovery of the switch setup.
  6822. */
  6823. dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
  6824. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  6825. val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
  6826. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  6827. } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
  6828. /* Request a Core Reset
  6829. *
  6830. * Same as Global Reset, except does *not* include the MAC/PHY
  6831. */
  6832. dev_dbg(&pf->pdev->dev, "CoreR requested\n");
  6833. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  6834. val |= I40E_GLGEN_RTRIG_CORER_MASK;
  6835. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  6836. i40e_flush(&pf->hw);
  6837. } else if (reset_flags & I40E_PF_RESET_FLAG) {
  6838. /* Request a PF Reset
  6839. *
  6840. * Resets only the PF-specific registers
  6841. *
  6842. * This goes directly to the tear-down and rebuild of
  6843. * the switch, since we need to do all the recovery as
  6844. * for the Core Reset.
  6845. */
  6846. dev_dbg(&pf->pdev->dev, "PFR requested\n");
  6847. i40e_handle_reset_warning(pf, lock_acquired);
  6848. } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
  6849. int v;
  6850. /* Find the VSI(s) that requested a re-init */
  6851. dev_info(&pf->pdev->dev,
  6852. "VSI reinit requested\n");
  6853. for (v = 0; v < pf->num_alloc_vsi; v++) {
  6854. struct i40e_vsi *vsi = pf->vsi[v];
  6855. if (vsi != NULL &&
  6856. test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED,
  6857. vsi->state))
  6858. i40e_vsi_reinit_locked(pf->vsi[v]);
  6859. }
  6860. } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
  6861. int v;
  6862. /* Find the VSI(s) that needs to be brought down */
  6863. dev_info(&pf->pdev->dev, "VSI down requested\n");
  6864. for (v = 0; v < pf->num_alloc_vsi; v++) {
  6865. struct i40e_vsi *vsi = pf->vsi[v];
  6866. if (vsi != NULL &&
  6867. test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED,
  6868. vsi->state)) {
  6869. set_bit(__I40E_VSI_DOWN, vsi->state);
  6870. i40e_down(vsi);
  6871. }
  6872. }
  6873. } else {
  6874. dev_info(&pf->pdev->dev,
  6875. "bad reset request 0x%08x\n", reset_flags);
  6876. }
  6877. }
  6878. #ifdef CONFIG_I40E_DCB
  6879. /**
  6880. * i40e_dcb_need_reconfig - Check if DCB needs reconfig
  6881. * @pf: board private structure
  6882. * @old_cfg: current DCB config
  6883. * @new_cfg: new DCB config
  6884. **/
  6885. bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
  6886. struct i40e_dcbx_config *old_cfg,
  6887. struct i40e_dcbx_config *new_cfg)
  6888. {
  6889. bool need_reconfig = false;
  6890. /* Check if ETS configuration has changed */
  6891. if (memcmp(&new_cfg->etscfg,
  6892. &old_cfg->etscfg,
  6893. sizeof(new_cfg->etscfg))) {
  6894. /* If Priority Table has changed reconfig is needed */
  6895. if (memcmp(&new_cfg->etscfg.prioritytable,
  6896. &old_cfg->etscfg.prioritytable,
  6897. sizeof(new_cfg->etscfg.prioritytable))) {
  6898. need_reconfig = true;
  6899. dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
  6900. }
  6901. if (memcmp(&new_cfg->etscfg.tcbwtable,
  6902. &old_cfg->etscfg.tcbwtable,
  6903. sizeof(new_cfg->etscfg.tcbwtable)))
  6904. dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
  6905. if (memcmp(&new_cfg->etscfg.tsatable,
  6906. &old_cfg->etscfg.tsatable,
  6907. sizeof(new_cfg->etscfg.tsatable)))
  6908. dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
  6909. }
  6910. /* Check if PFC configuration has changed */
  6911. if (memcmp(&new_cfg->pfc,
  6912. &old_cfg->pfc,
  6913. sizeof(new_cfg->pfc))) {
  6914. need_reconfig = true;
  6915. dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
  6916. }
  6917. /* Check if APP Table has changed */
  6918. if (memcmp(&new_cfg->app,
  6919. &old_cfg->app,
  6920. sizeof(new_cfg->app))) {
  6921. need_reconfig = true;
  6922. dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
  6923. }
  6924. dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
  6925. return need_reconfig;
  6926. }
  6927. /**
  6928. * i40e_handle_lldp_event - Handle LLDP Change MIB event
  6929. * @pf: board private structure
  6930. * @e: event info posted on ARQ
  6931. **/
  6932. static int i40e_handle_lldp_event(struct i40e_pf *pf,
  6933. struct i40e_arq_event_info *e)
  6934. {
  6935. struct i40e_aqc_lldp_get_mib *mib =
  6936. (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
  6937. struct i40e_hw *hw = &pf->hw;
  6938. struct i40e_dcbx_config tmp_dcbx_cfg;
  6939. bool need_reconfig = false;
  6940. int ret = 0;
  6941. u8 type;
  6942. /* Not DCB capable or capability disabled */
  6943. if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
  6944. return ret;
  6945. /* Ignore if event is not for Nearest Bridge */
  6946. type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
  6947. & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  6948. dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
  6949. if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
  6950. return ret;
  6951. /* Check MIB Type and return if event for Remote MIB update */
  6952. type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  6953. dev_dbg(&pf->pdev->dev,
  6954. "LLDP event mib type %s\n", type ? "remote" : "local");
  6955. if (type == I40E_AQ_LLDP_MIB_REMOTE) {
  6956. /* Update the remote cached instance and return */
  6957. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  6958. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  6959. &hw->remote_dcbx_config);
  6960. goto exit;
  6961. }
  6962. /* Store the old configuration */
  6963. tmp_dcbx_cfg = hw->local_dcbx_config;
  6964. /* Reset the old DCBx configuration data */
  6965. memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
  6966. /* Get updated DCBX data from firmware */
  6967. ret = i40e_get_dcb_config(&pf->hw);
  6968. if (ret) {
  6969. dev_info(&pf->pdev->dev,
  6970. "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
  6971. i40e_stat_str(&pf->hw, ret),
  6972. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6973. goto exit;
  6974. }
  6975. /* No change detected in DCBX configs */
  6976. if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
  6977. sizeof(tmp_dcbx_cfg))) {
  6978. dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
  6979. goto exit;
  6980. }
  6981. need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
  6982. &hw->local_dcbx_config);
  6983. i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
  6984. if (!need_reconfig)
  6985. goto exit;
  6986. /* Enable DCB tagging only when more than one TC */
  6987. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  6988. pf->flags |= I40E_FLAG_DCB_ENABLED;
  6989. else
  6990. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  6991. set_bit(__I40E_PORT_SUSPENDED, pf->state);
  6992. /* Reconfiguration needed quiesce all VSIs */
  6993. i40e_pf_quiesce_all_vsi(pf);
  6994. /* Changes in configuration update VEB/VSI */
  6995. i40e_dcb_reconfigure(pf);
  6996. ret = i40e_resume_port_tx(pf);
  6997. clear_bit(__I40E_PORT_SUSPENDED, pf->state);
  6998. /* In case of error no point in resuming VSIs */
  6999. if (ret)
  7000. goto exit;
  7001. /* Wait for the PF's queues to be disabled */
  7002. ret = i40e_pf_wait_queues_disabled(pf);
  7003. if (ret) {
  7004. /* Schedule PF reset to recover */
  7005. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  7006. i40e_service_event_schedule(pf);
  7007. } else {
  7008. i40e_pf_unquiesce_all_vsi(pf);
  7009. pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED |
  7010. I40E_FLAG_CLIENT_L2_CHANGE);
  7011. }
  7012. exit:
  7013. return ret;
  7014. }
  7015. #endif /* CONFIG_I40E_DCB */
  7016. /**
  7017. * i40e_do_reset_safe - Protected reset path for userland calls.
  7018. * @pf: board private structure
  7019. * @reset_flags: which reset is requested
  7020. *
  7021. **/
  7022. void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
  7023. {
  7024. rtnl_lock();
  7025. i40e_do_reset(pf, reset_flags, true);
  7026. rtnl_unlock();
  7027. }
  7028. /**
  7029. * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
  7030. * @pf: board private structure
  7031. * @e: event info posted on ARQ
  7032. *
  7033. * Handler for LAN Queue Overflow Event generated by the firmware for PF
  7034. * and VF queues
  7035. **/
  7036. static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
  7037. struct i40e_arq_event_info *e)
  7038. {
  7039. struct i40e_aqc_lan_overflow *data =
  7040. (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
  7041. u32 queue = le32_to_cpu(data->prtdcb_rupto);
  7042. u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
  7043. struct i40e_hw *hw = &pf->hw;
  7044. struct i40e_vf *vf;
  7045. u16 vf_id;
  7046. dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
  7047. queue, qtx_ctl);
  7048. /* Queue belongs to VF, find the VF and issue VF reset */
  7049. if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
  7050. >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
  7051. vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
  7052. >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
  7053. vf_id -= hw->func_caps.vf_base_id;
  7054. vf = &pf->vf[vf_id];
  7055. i40e_vc_notify_vf_reset(vf);
  7056. /* Allow VF to process pending reset notification */
  7057. msleep(20);
  7058. i40e_reset_vf(vf, false);
  7059. }
  7060. }
  7061. /**
  7062. * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
  7063. * @pf: board private structure
  7064. **/
  7065. u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
  7066. {
  7067. u32 val, fcnt_prog;
  7068. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  7069. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
  7070. return fcnt_prog;
  7071. }
  7072. /**
  7073. * i40e_get_current_fd_count - Get total FD filters programmed for this PF
  7074. * @pf: board private structure
  7075. **/
  7076. u32 i40e_get_current_fd_count(struct i40e_pf *pf)
  7077. {
  7078. u32 val, fcnt_prog;
  7079. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  7080. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
  7081. ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
  7082. I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
  7083. return fcnt_prog;
  7084. }
  7085. /**
  7086. * i40e_get_global_fd_count - Get total FD filters programmed on device
  7087. * @pf: board private structure
  7088. **/
  7089. u32 i40e_get_global_fd_count(struct i40e_pf *pf)
  7090. {
  7091. u32 val, fcnt_prog;
  7092. val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
  7093. fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
  7094. ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
  7095. I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
  7096. return fcnt_prog;
  7097. }
  7098. /**
  7099. * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
  7100. * @pf: board private structure
  7101. **/
  7102. void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
  7103. {
  7104. struct i40e_fdir_filter *filter;
  7105. u32 fcnt_prog, fcnt_avail;
  7106. struct hlist_node *node;
  7107. if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
  7108. return;
  7109. /* Check if we have enough room to re-enable FDir SB capability. */
  7110. fcnt_prog = i40e_get_global_fd_count(pf);
  7111. fcnt_avail = pf->fdir_pf_filter_count;
  7112. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
  7113. (pf->fd_add_err == 0) ||
  7114. (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
  7115. if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED) {
  7116. pf->flags &= ~I40E_FLAG_FD_SB_AUTO_DISABLED;
  7117. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  7118. (I40E_DEBUG_FD & pf->hw.debug_mask))
  7119. dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
  7120. }
  7121. }
  7122. /* We should wait for even more space before re-enabling ATR.
  7123. * Additionally, we cannot enable ATR as long as we still have TCP SB
  7124. * rules active.
  7125. */
  7126. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) &&
  7127. (pf->fd_tcp4_filter_cnt == 0)) {
  7128. if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) {
  7129. pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
  7130. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  7131. (I40E_DEBUG_FD & pf->hw.debug_mask))
  7132. dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
  7133. }
  7134. }
  7135. /* if hw had a problem adding a filter, delete it */
  7136. if (pf->fd_inv > 0) {
  7137. hlist_for_each_entry_safe(filter, node,
  7138. &pf->fdir_filter_list, fdir_node) {
  7139. if (filter->fd_id == pf->fd_inv) {
  7140. hlist_del(&filter->fdir_node);
  7141. kfree(filter);
  7142. pf->fdir_pf_active_filters--;
  7143. pf->fd_inv = 0;
  7144. }
  7145. }
  7146. }
  7147. }
  7148. #define I40E_MIN_FD_FLUSH_INTERVAL 10
  7149. #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
  7150. /**
  7151. * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
  7152. * @pf: board private structure
  7153. **/
  7154. static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
  7155. {
  7156. unsigned long min_flush_time;
  7157. int flush_wait_retry = 50;
  7158. bool disable_atr = false;
  7159. int fd_room;
  7160. int reg;
  7161. if (!time_after(jiffies, pf->fd_flush_timestamp +
  7162. (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
  7163. return;
  7164. /* If the flush is happening too quick and we have mostly SB rules we
  7165. * should not re-enable ATR for some time.
  7166. */
  7167. min_flush_time = pf->fd_flush_timestamp +
  7168. (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
  7169. fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
  7170. if (!(time_after(jiffies, min_flush_time)) &&
  7171. (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
  7172. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7173. dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
  7174. disable_atr = true;
  7175. }
  7176. pf->fd_flush_timestamp = jiffies;
  7177. pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED;
  7178. /* flush all filters */
  7179. wr32(&pf->hw, I40E_PFQF_CTL_1,
  7180. I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
  7181. i40e_flush(&pf->hw);
  7182. pf->fd_flush_cnt++;
  7183. pf->fd_add_err = 0;
  7184. do {
  7185. /* Check FD flush status every 5-6msec */
  7186. usleep_range(5000, 6000);
  7187. reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
  7188. if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
  7189. break;
  7190. } while (flush_wait_retry--);
  7191. if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
  7192. dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
  7193. } else {
  7194. /* replay sideband filters */
  7195. i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
  7196. if (!disable_atr && !pf->fd_tcp4_filter_cnt)
  7197. pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
  7198. clear_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
  7199. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7200. dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
  7201. }
  7202. }
  7203. /**
  7204. * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
  7205. * @pf: board private structure
  7206. **/
  7207. u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
  7208. {
  7209. return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
  7210. }
  7211. /* We can see up to 256 filter programming desc in transit if the filters are
  7212. * being applied really fast; before we see the first
  7213. * filter miss error on Rx queue 0. Accumulating enough error messages before
  7214. * reacting will make sure we don't cause flush too often.
  7215. */
  7216. #define I40E_MAX_FD_PROGRAM_ERROR 256
  7217. /**
  7218. * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
  7219. * @pf: board private structure
  7220. **/
  7221. static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
  7222. {
  7223. /* if interface is down do nothing */
  7224. if (test_bit(__I40E_DOWN, pf->state))
  7225. return;
  7226. if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
  7227. i40e_fdir_flush_and_replay(pf);
  7228. i40e_fdir_check_and_reenable(pf);
  7229. }
  7230. /**
  7231. * i40e_vsi_link_event - notify VSI of a link event
  7232. * @vsi: vsi to be notified
  7233. * @link_up: link up or down
  7234. **/
  7235. static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
  7236. {
  7237. if (!vsi || test_bit(__I40E_VSI_DOWN, vsi->state))
  7238. return;
  7239. switch (vsi->type) {
  7240. case I40E_VSI_MAIN:
  7241. if (!vsi->netdev || !vsi->netdev_registered)
  7242. break;
  7243. if (link_up) {
  7244. netif_carrier_on(vsi->netdev);
  7245. netif_tx_wake_all_queues(vsi->netdev);
  7246. } else {
  7247. netif_carrier_off(vsi->netdev);
  7248. netif_tx_stop_all_queues(vsi->netdev);
  7249. }
  7250. break;
  7251. case I40E_VSI_SRIOV:
  7252. case I40E_VSI_VMDQ2:
  7253. case I40E_VSI_CTRL:
  7254. case I40E_VSI_IWARP:
  7255. case I40E_VSI_MIRROR:
  7256. default:
  7257. /* there is no notification for other VSIs */
  7258. break;
  7259. }
  7260. }
  7261. /**
  7262. * i40e_veb_link_event - notify elements on the veb of a link event
  7263. * @veb: veb to be notified
  7264. * @link_up: link up or down
  7265. **/
  7266. static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
  7267. {
  7268. struct i40e_pf *pf;
  7269. int i;
  7270. if (!veb || !veb->pf)
  7271. return;
  7272. pf = veb->pf;
  7273. /* depth first... */
  7274. for (i = 0; i < I40E_MAX_VEB; i++)
  7275. if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
  7276. i40e_veb_link_event(pf->veb[i], link_up);
  7277. /* ... now the local VSIs */
  7278. for (i = 0; i < pf->num_alloc_vsi; i++)
  7279. if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
  7280. i40e_vsi_link_event(pf->vsi[i], link_up);
  7281. }
  7282. /**
  7283. * i40e_link_event - Update netif_carrier status
  7284. * @pf: board private structure
  7285. **/
  7286. static void i40e_link_event(struct i40e_pf *pf)
  7287. {
  7288. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7289. u8 new_link_speed, old_link_speed;
  7290. i40e_status status;
  7291. bool new_link, old_link;
  7292. /* save off old link status information */
  7293. pf->hw.phy.link_info_old = pf->hw.phy.link_info;
  7294. /* set this to force the get_link_status call to refresh state */
  7295. pf->hw.phy.get_link_info = true;
  7296. old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
  7297. status = i40e_get_link_status(&pf->hw, &new_link);
  7298. /* On success, disable temp link polling */
  7299. if (status == I40E_SUCCESS) {
  7300. if (pf->flags & I40E_FLAG_TEMP_LINK_POLLING)
  7301. pf->flags &= ~I40E_FLAG_TEMP_LINK_POLLING;
  7302. } else {
  7303. /* Enable link polling temporarily until i40e_get_link_status
  7304. * returns I40E_SUCCESS
  7305. */
  7306. pf->flags |= I40E_FLAG_TEMP_LINK_POLLING;
  7307. dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
  7308. status);
  7309. return;
  7310. }
  7311. old_link_speed = pf->hw.phy.link_info_old.link_speed;
  7312. new_link_speed = pf->hw.phy.link_info.link_speed;
  7313. if (new_link == old_link &&
  7314. new_link_speed == old_link_speed &&
  7315. (test_bit(__I40E_VSI_DOWN, vsi->state) ||
  7316. new_link == netif_carrier_ok(vsi->netdev)))
  7317. return;
  7318. i40e_print_link_message(vsi, new_link);
  7319. /* Notify the base of the switch tree connected to
  7320. * the link. Floating VEBs are not notified.
  7321. */
  7322. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  7323. i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
  7324. else
  7325. i40e_vsi_link_event(vsi, new_link);
  7326. if (pf->vf)
  7327. i40e_vc_notify_link_state(pf);
  7328. if (pf->flags & I40E_FLAG_PTP)
  7329. i40e_ptp_set_increment(pf);
  7330. }
  7331. /**
  7332. * i40e_watchdog_subtask - periodic checks not using event driven response
  7333. * @pf: board private structure
  7334. **/
  7335. static void i40e_watchdog_subtask(struct i40e_pf *pf)
  7336. {
  7337. int i;
  7338. /* if interface is down do nothing */
  7339. if (test_bit(__I40E_DOWN, pf->state) ||
  7340. test_bit(__I40E_CONFIG_BUSY, pf->state))
  7341. return;
  7342. /* make sure we don't do these things too often */
  7343. if (time_before(jiffies, (pf->service_timer_previous +
  7344. pf->service_timer_period)))
  7345. return;
  7346. pf->service_timer_previous = jiffies;
  7347. if ((pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) ||
  7348. (pf->flags & I40E_FLAG_TEMP_LINK_POLLING))
  7349. i40e_link_event(pf);
  7350. /* Update the stats for active netdevs so the network stack
  7351. * can look at updated numbers whenever it cares to
  7352. */
  7353. for (i = 0; i < pf->num_alloc_vsi; i++)
  7354. if (pf->vsi[i] && pf->vsi[i]->netdev)
  7355. i40e_update_stats(pf->vsi[i]);
  7356. if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
  7357. /* Update the stats for the active switching components */
  7358. for (i = 0; i < I40E_MAX_VEB; i++)
  7359. if (pf->veb[i])
  7360. i40e_update_veb_stats(pf->veb[i]);
  7361. }
  7362. i40e_ptp_rx_hang(pf);
  7363. i40e_ptp_tx_hang(pf);
  7364. }
  7365. /**
  7366. * i40e_reset_subtask - Set up for resetting the device and driver
  7367. * @pf: board private structure
  7368. **/
  7369. static void i40e_reset_subtask(struct i40e_pf *pf)
  7370. {
  7371. u32 reset_flags = 0;
  7372. if (test_bit(__I40E_REINIT_REQUESTED, pf->state)) {
  7373. reset_flags |= BIT(__I40E_REINIT_REQUESTED);
  7374. clear_bit(__I40E_REINIT_REQUESTED, pf->state);
  7375. }
  7376. if (test_bit(__I40E_PF_RESET_REQUESTED, pf->state)) {
  7377. reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
  7378. clear_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  7379. }
  7380. if (test_bit(__I40E_CORE_RESET_REQUESTED, pf->state)) {
  7381. reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
  7382. clear_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
  7383. }
  7384. if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state)) {
  7385. reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
  7386. clear_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state);
  7387. }
  7388. if (test_bit(__I40E_DOWN_REQUESTED, pf->state)) {
  7389. reset_flags |= BIT(__I40E_DOWN_REQUESTED);
  7390. clear_bit(__I40E_DOWN_REQUESTED, pf->state);
  7391. }
  7392. /* If there's a recovery already waiting, it takes
  7393. * precedence before starting a new reset sequence.
  7394. */
  7395. if (test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) {
  7396. i40e_prep_for_reset(pf, false);
  7397. i40e_reset(pf);
  7398. i40e_rebuild(pf, false, false);
  7399. }
  7400. /* If we're already down or resetting, just bail */
  7401. if (reset_flags &&
  7402. !test_bit(__I40E_DOWN, pf->state) &&
  7403. !test_bit(__I40E_CONFIG_BUSY, pf->state)) {
  7404. i40e_do_reset(pf, reset_flags, false);
  7405. }
  7406. }
  7407. /**
  7408. * i40e_handle_link_event - Handle link event
  7409. * @pf: board private structure
  7410. * @e: event info posted on ARQ
  7411. **/
  7412. static void i40e_handle_link_event(struct i40e_pf *pf,
  7413. struct i40e_arq_event_info *e)
  7414. {
  7415. struct i40e_aqc_get_link_status *status =
  7416. (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
  7417. /* Do a new status request to re-enable LSE reporting
  7418. * and load new status information into the hw struct
  7419. * This completely ignores any state information
  7420. * in the ARQ event info, instead choosing to always
  7421. * issue the AQ update link status command.
  7422. */
  7423. i40e_link_event(pf);
  7424. /* Check if module meets thermal requirements */
  7425. if (status->phy_type == I40E_PHY_TYPE_NOT_SUPPORTED_HIGH_TEMP) {
  7426. dev_err(&pf->pdev->dev,
  7427. "Rx/Tx is disabled on this device because the module does not meet thermal requirements.\n");
  7428. dev_err(&pf->pdev->dev,
  7429. "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
  7430. } else {
  7431. /* check for unqualified module, if link is down, suppress
  7432. * the message if link was forced to be down.
  7433. */
  7434. if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
  7435. (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
  7436. (!(status->link_info & I40E_AQ_LINK_UP)) &&
  7437. (!(pf->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED))) {
  7438. dev_err(&pf->pdev->dev,
  7439. "Rx/Tx is disabled on this device because an unsupported SFP module type was detected.\n");
  7440. dev_err(&pf->pdev->dev,
  7441. "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
  7442. }
  7443. }
  7444. }
  7445. /**
  7446. * i40e_clean_adminq_subtask - Clean the AdminQ rings
  7447. * @pf: board private structure
  7448. **/
  7449. static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
  7450. {
  7451. struct i40e_arq_event_info event;
  7452. struct i40e_hw *hw = &pf->hw;
  7453. u16 pending, i = 0;
  7454. i40e_status ret;
  7455. u16 opcode;
  7456. u32 oldval;
  7457. u32 val;
  7458. /* Do not run clean AQ when PF reset fails */
  7459. if (test_bit(__I40E_RESET_FAILED, pf->state))
  7460. return;
  7461. /* check for error indications */
  7462. val = rd32(&pf->hw, pf->hw.aq.arq.len);
  7463. oldval = val;
  7464. if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
  7465. if (hw->debug_mask & I40E_DEBUG_AQ)
  7466. dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
  7467. val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
  7468. }
  7469. if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
  7470. if (hw->debug_mask & I40E_DEBUG_AQ)
  7471. dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
  7472. val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
  7473. pf->arq_overflows++;
  7474. }
  7475. if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
  7476. if (hw->debug_mask & I40E_DEBUG_AQ)
  7477. dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
  7478. val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
  7479. }
  7480. if (oldval != val)
  7481. wr32(&pf->hw, pf->hw.aq.arq.len, val);
  7482. val = rd32(&pf->hw, pf->hw.aq.asq.len);
  7483. oldval = val;
  7484. if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
  7485. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7486. dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
  7487. val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
  7488. }
  7489. if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
  7490. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7491. dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
  7492. val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
  7493. }
  7494. if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
  7495. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7496. dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
  7497. val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
  7498. }
  7499. if (oldval != val)
  7500. wr32(&pf->hw, pf->hw.aq.asq.len, val);
  7501. event.buf_len = I40E_MAX_AQ_BUF_SIZE;
  7502. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  7503. if (!event.msg_buf)
  7504. return;
  7505. do {
  7506. ret = i40e_clean_arq_element(hw, &event, &pending);
  7507. if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
  7508. break;
  7509. else if (ret) {
  7510. dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
  7511. break;
  7512. }
  7513. opcode = le16_to_cpu(event.desc.opcode);
  7514. switch (opcode) {
  7515. case i40e_aqc_opc_get_link_status:
  7516. i40e_handle_link_event(pf, &event);
  7517. break;
  7518. case i40e_aqc_opc_send_msg_to_pf:
  7519. ret = i40e_vc_process_vf_msg(pf,
  7520. le16_to_cpu(event.desc.retval),
  7521. le32_to_cpu(event.desc.cookie_high),
  7522. le32_to_cpu(event.desc.cookie_low),
  7523. event.msg_buf,
  7524. event.msg_len);
  7525. break;
  7526. case i40e_aqc_opc_lldp_update_mib:
  7527. dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
  7528. #ifdef CONFIG_I40E_DCB
  7529. rtnl_lock();
  7530. ret = i40e_handle_lldp_event(pf, &event);
  7531. rtnl_unlock();
  7532. #endif /* CONFIG_I40E_DCB */
  7533. break;
  7534. case i40e_aqc_opc_event_lan_overflow:
  7535. dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
  7536. i40e_handle_lan_overflow_event(pf, &event);
  7537. break;
  7538. case i40e_aqc_opc_send_msg_to_peer:
  7539. dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
  7540. break;
  7541. case i40e_aqc_opc_nvm_erase:
  7542. case i40e_aqc_opc_nvm_update:
  7543. case i40e_aqc_opc_oem_post_update:
  7544. i40e_debug(&pf->hw, I40E_DEBUG_NVM,
  7545. "ARQ NVM operation 0x%04x completed\n",
  7546. opcode);
  7547. break;
  7548. default:
  7549. dev_info(&pf->pdev->dev,
  7550. "ARQ: Unknown event 0x%04x ignored\n",
  7551. opcode);
  7552. break;
  7553. }
  7554. } while (i++ < pf->adminq_work_limit);
  7555. if (i < pf->adminq_work_limit)
  7556. clear_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
  7557. /* re-enable Admin queue interrupt cause */
  7558. val = rd32(hw, I40E_PFINT_ICR0_ENA);
  7559. val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  7560. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  7561. i40e_flush(hw);
  7562. kfree(event.msg_buf);
  7563. }
  7564. /**
  7565. * i40e_verify_eeprom - make sure eeprom is good to use
  7566. * @pf: board private structure
  7567. **/
  7568. static void i40e_verify_eeprom(struct i40e_pf *pf)
  7569. {
  7570. int err;
  7571. err = i40e_diag_eeprom_test(&pf->hw);
  7572. if (err) {
  7573. /* retry in case of garbage read */
  7574. err = i40e_diag_eeprom_test(&pf->hw);
  7575. if (err) {
  7576. dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
  7577. err);
  7578. set_bit(__I40E_BAD_EEPROM, pf->state);
  7579. }
  7580. }
  7581. if (!err && test_bit(__I40E_BAD_EEPROM, pf->state)) {
  7582. dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
  7583. clear_bit(__I40E_BAD_EEPROM, pf->state);
  7584. }
  7585. }
  7586. /**
  7587. * i40e_enable_pf_switch_lb
  7588. * @pf: pointer to the PF structure
  7589. *
  7590. * enable switch loop back or die - no point in a return value
  7591. **/
  7592. static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
  7593. {
  7594. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7595. struct i40e_vsi_context ctxt;
  7596. int ret;
  7597. ctxt.seid = pf->main_vsi_seid;
  7598. ctxt.pf_num = pf->hw.pf_id;
  7599. ctxt.vf_num = 0;
  7600. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  7601. if (ret) {
  7602. dev_info(&pf->pdev->dev,
  7603. "couldn't get PF vsi config, err %s aq_err %s\n",
  7604. i40e_stat_str(&pf->hw, ret),
  7605. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7606. return;
  7607. }
  7608. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  7609. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  7610. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  7611. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  7612. if (ret) {
  7613. dev_info(&pf->pdev->dev,
  7614. "update vsi switch failed, err %s aq_err %s\n",
  7615. i40e_stat_str(&pf->hw, ret),
  7616. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7617. }
  7618. }
  7619. /**
  7620. * i40e_disable_pf_switch_lb
  7621. * @pf: pointer to the PF structure
  7622. *
  7623. * disable switch loop back or die - no point in a return value
  7624. **/
  7625. static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
  7626. {
  7627. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7628. struct i40e_vsi_context ctxt;
  7629. int ret;
  7630. ctxt.seid = pf->main_vsi_seid;
  7631. ctxt.pf_num = pf->hw.pf_id;
  7632. ctxt.vf_num = 0;
  7633. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  7634. if (ret) {
  7635. dev_info(&pf->pdev->dev,
  7636. "couldn't get PF vsi config, err %s aq_err %s\n",
  7637. i40e_stat_str(&pf->hw, ret),
  7638. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7639. return;
  7640. }
  7641. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  7642. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  7643. ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  7644. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  7645. if (ret) {
  7646. dev_info(&pf->pdev->dev,
  7647. "update vsi switch failed, err %s aq_err %s\n",
  7648. i40e_stat_str(&pf->hw, ret),
  7649. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7650. }
  7651. }
  7652. /**
  7653. * i40e_config_bridge_mode - Configure the HW bridge mode
  7654. * @veb: pointer to the bridge instance
  7655. *
  7656. * Configure the loop back mode for the LAN VSI that is downlink to the
  7657. * specified HW bridge instance. It is expected this function is called
  7658. * when a new HW bridge is instantiated.
  7659. **/
  7660. static void i40e_config_bridge_mode(struct i40e_veb *veb)
  7661. {
  7662. struct i40e_pf *pf = veb->pf;
  7663. if (pf->hw.debug_mask & I40E_DEBUG_LAN)
  7664. dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
  7665. veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  7666. if (veb->bridge_mode & BRIDGE_MODE_VEPA)
  7667. i40e_disable_pf_switch_lb(pf);
  7668. else
  7669. i40e_enable_pf_switch_lb(pf);
  7670. }
  7671. /**
  7672. * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
  7673. * @veb: pointer to the VEB instance
  7674. *
  7675. * This is a recursive function that first builds the attached VSIs then
  7676. * recurses in to build the next layer of VEB. We track the connections
  7677. * through our own index numbers because the seid's from the HW could
  7678. * change across the reset.
  7679. **/
  7680. static int i40e_reconstitute_veb(struct i40e_veb *veb)
  7681. {
  7682. struct i40e_vsi *ctl_vsi = NULL;
  7683. struct i40e_pf *pf = veb->pf;
  7684. int v, veb_idx;
  7685. int ret;
  7686. /* build VSI that owns this VEB, temporarily attached to base VEB */
  7687. for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
  7688. if (pf->vsi[v] &&
  7689. pf->vsi[v]->veb_idx == veb->idx &&
  7690. pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
  7691. ctl_vsi = pf->vsi[v];
  7692. break;
  7693. }
  7694. }
  7695. if (!ctl_vsi) {
  7696. dev_info(&pf->pdev->dev,
  7697. "missing owner VSI for veb_idx %d\n", veb->idx);
  7698. ret = -ENOENT;
  7699. goto end_reconstitute;
  7700. }
  7701. if (ctl_vsi != pf->vsi[pf->lan_vsi])
  7702. ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  7703. ret = i40e_add_vsi(ctl_vsi);
  7704. if (ret) {
  7705. dev_info(&pf->pdev->dev,
  7706. "rebuild of veb_idx %d owner VSI failed: %d\n",
  7707. veb->idx, ret);
  7708. goto end_reconstitute;
  7709. }
  7710. i40e_vsi_reset_stats(ctl_vsi);
  7711. /* create the VEB in the switch and move the VSI onto the VEB */
  7712. ret = i40e_add_veb(veb, ctl_vsi);
  7713. if (ret)
  7714. goto end_reconstitute;
  7715. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  7716. veb->bridge_mode = BRIDGE_MODE_VEB;
  7717. else
  7718. veb->bridge_mode = BRIDGE_MODE_VEPA;
  7719. i40e_config_bridge_mode(veb);
  7720. /* create the remaining VSIs attached to this VEB */
  7721. for (v = 0; v < pf->num_alloc_vsi; v++) {
  7722. if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
  7723. continue;
  7724. if (pf->vsi[v]->veb_idx == veb->idx) {
  7725. struct i40e_vsi *vsi = pf->vsi[v];
  7726. vsi->uplink_seid = veb->seid;
  7727. ret = i40e_add_vsi(vsi);
  7728. if (ret) {
  7729. dev_info(&pf->pdev->dev,
  7730. "rebuild of vsi_idx %d failed: %d\n",
  7731. v, ret);
  7732. goto end_reconstitute;
  7733. }
  7734. i40e_vsi_reset_stats(vsi);
  7735. }
  7736. }
  7737. /* create any VEBs attached to this VEB - RECURSION */
  7738. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  7739. if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
  7740. pf->veb[veb_idx]->uplink_seid = veb->seid;
  7741. ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
  7742. if (ret)
  7743. break;
  7744. }
  7745. }
  7746. end_reconstitute:
  7747. return ret;
  7748. }
  7749. /**
  7750. * i40e_get_capabilities - get info about the HW
  7751. * @pf: the PF struct
  7752. **/
  7753. static int i40e_get_capabilities(struct i40e_pf *pf,
  7754. enum i40e_admin_queue_opc list_type)
  7755. {
  7756. struct i40e_aqc_list_capabilities_element_resp *cap_buf;
  7757. u16 data_size;
  7758. int buf_len;
  7759. int err;
  7760. buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
  7761. do {
  7762. cap_buf = kzalloc(buf_len, GFP_KERNEL);
  7763. if (!cap_buf)
  7764. return -ENOMEM;
  7765. /* this loads the data into the hw struct for us */
  7766. err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
  7767. &data_size, list_type,
  7768. NULL);
  7769. /* data loaded, buffer no longer needed */
  7770. kfree(cap_buf);
  7771. if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
  7772. /* retry with a larger buffer */
  7773. buf_len = data_size;
  7774. } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
  7775. dev_info(&pf->pdev->dev,
  7776. "capability discovery failed, err %s aq_err %s\n",
  7777. i40e_stat_str(&pf->hw, err),
  7778. i40e_aq_str(&pf->hw,
  7779. pf->hw.aq.asq_last_status));
  7780. return -ENODEV;
  7781. }
  7782. } while (err);
  7783. if (pf->hw.debug_mask & I40E_DEBUG_USER) {
  7784. if (list_type == i40e_aqc_opc_list_func_capabilities) {
  7785. dev_info(&pf->pdev->dev,
  7786. "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",
  7787. pf->hw.pf_id, pf->hw.func_caps.num_vfs,
  7788. pf->hw.func_caps.num_msix_vectors,
  7789. pf->hw.func_caps.num_msix_vectors_vf,
  7790. pf->hw.func_caps.fd_filters_guaranteed,
  7791. pf->hw.func_caps.fd_filters_best_effort,
  7792. pf->hw.func_caps.num_tx_qp,
  7793. pf->hw.func_caps.num_vsis);
  7794. } else if (list_type == i40e_aqc_opc_list_dev_capabilities) {
  7795. dev_info(&pf->pdev->dev,
  7796. "switch_mode=0x%04x, function_valid=0x%08x\n",
  7797. pf->hw.dev_caps.switch_mode,
  7798. pf->hw.dev_caps.valid_functions);
  7799. dev_info(&pf->pdev->dev,
  7800. "SR-IOV=%d, num_vfs for all function=%u\n",
  7801. pf->hw.dev_caps.sr_iov_1_1,
  7802. pf->hw.dev_caps.num_vfs);
  7803. dev_info(&pf->pdev->dev,
  7804. "num_vsis=%u, num_rx:%u, num_tx=%u\n",
  7805. pf->hw.dev_caps.num_vsis,
  7806. pf->hw.dev_caps.num_rx_qp,
  7807. pf->hw.dev_caps.num_tx_qp);
  7808. }
  7809. }
  7810. if (list_type == i40e_aqc_opc_list_func_capabilities) {
  7811. #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
  7812. + pf->hw.func_caps.num_vfs)
  7813. if (pf->hw.revision_id == 0 &&
  7814. pf->hw.func_caps.num_vsis < DEF_NUM_VSI) {
  7815. dev_info(&pf->pdev->dev,
  7816. "got num_vsis %d, setting num_vsis to %d\n",
  7817. pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
  7818. pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
  7819. }
  7820. }
  7821. return 0;
  7822. }
  7823. static int i40e_vsi_clear(struct i40e_vsi *vsi);
  7824. /**
  7825. * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
  7826. * @pf: board private structure
  7827. **/
  7828. static void i40e_fdir_sb_setup(struct i40e_pf *pf)
  7829. {
  7830. struct i40e_vsi *vsi;
  7831. /* quick workaround for an NVM issue that leaves a critical register
  7832. * uninitialized
  7833. */
  7834. if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
  7835. static const u32 hkey[] = {
  7836. 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
  7837. 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
  7838. 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
  7839. 0x95b3a76d};
  7840. int i;
  7841. for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
  7842. wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
  7843. }
  7844. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  7845. return;
  7846. /* find existing VSI and see if it needs configuring */
  7847. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  7848. /* create a new VSI if none exists */
  7849. if (!vsi) {
  7850. vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
  7851. pf->vsi[pf->lan_vsi]->seid, 0);
  7852. if (!vsi) {
  7853. dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
  7854. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7855. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  7856. return;
  7857. }
  7858. }
  7859. i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
  7860. }
  7861. /**
  7862. * i40e_fdir_teardown - release the Flow Director resources
  7863. * @pf: board private structure
  7864. **/
  7865. static void i40e_fdir_teardown(struct i40e_pf *pf)
  7866. {
  7867. struct i40e_vsi *vsi;
  7868. i40e_fdir_filter_exit(pf);
  7869. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  7870. if (vsi)
  7871. i40e_vsi_release(vsi);
  7872. }
  7873. /**
  7874. * i40e_rebuild_cloud_filters - Rebuilds cloud filters for VSIs
  7875. * @vsi: PF main vsi
  7876. * @seid: seid of main or channel VSIs
  7877. *
  7878. * Rebuilds cloud filters associated with main VSI and channel VSIs if they
  7879. * existed before reset
  7880. **/
  7881. static int i40e_rebuild_cloud_filters(struct i40e_vsi *vsi, u16 seid)
  7882. {
  7883. struct i40e_cloud_filter *cfilter;
  7884. struct i40e_pf *pf = vsi->back;
  7885. struct hlist_node *node;
  7886. i40e_status ret;
  7887. /* Add cloud filters back if they exist */
  7888. hlist_for_each_entry_safe(cfilter, node, &pf->cloud_filter_list,
  7889. cloud_node) {
  7890. if (cfilter->seid != seid)
  7891. continue;
  7892. if (cfilter->dst_port)
  7893. ret = i40e_add_del_cloud_filter_big_buf(vsi, cfilter,
  7894. true);
  7895. else
  7896. ret = i40e_add_del_cloud_filter(vsi, cfilter, true);
  7897. if (ret) {
  7898. dev_dbg(&pf->pdev->dev,
  7899. "Failed to rebuild cloud filter, err %s aq_err %s\n",
  7900. i40e_stat_str(&pf->hw, ret),
  7901. i40e_aq_str(&pf->hw,
  7902. pf->hw.aq.asq_last_status));
  7903. return ret;
  7904. }
  7905. }
  7906. return 0;
  7907. }
  7908. /**
  7909. * i40e_rebuild_channels - Rebuilds channel VSIs if they existed before reset
  7910. * @vsi: PF main vsi
  7911. *
  7912. * Rebuilds channel VSIs if they existed before reset
  7913. **/
  7914. static int i40e_rebuild_channels(struct i40e_vsi *vsi)
  7915. {
  7916. struct i40e_channel *ch, *ch_tmp;
  7917. i40e_status ret;
  7918. if (list_empty(&vsi->ch_list))
  7919. return 0;
  7920. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  7921. if (!ch->initialized)
  7922. break;
  7923. /* Proceed with creation of channel (VMDq2) VSI */
  7924. ret = i40e_add_channel(vsi->back, vsi->uplink_seid, ch);
  7925. if (ret) {
  7926. dev_info(&vsi->back->pdev->dev,
  7927. "failed to rebuild channels using uplink_seid %u\n",
  7928. vsi->uplink_seid);
  7929. return ret;
  7930. }
  7931. if (ch->max_tx_rate) {
  7932. u64 credits = ch->max_tx_rate;
  7933. if (i40e_set_bw_limit(vsi, ch->seid,
  7934. ch->max_tx_rate))
  7935. return -EINVAL;
  7936. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  7937. dev_dbg(&vsi->back->pdev->dev,
  7938. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  7939. ch->max_tx_rate,
  7940. credits,
  7941. ch->seid);
  7942. }
  7943. ret = i40e_rebuild_cloud_filters(vsi, ch->seid);
  7944. if (ret) {
  7945. dev_dbg(&vsi->back->pdev->dev,
  7946. "Failed to rebuild cloud filters for channel VSI %u\n",
  7947. ch->seid);
  7948. return ret;
  7949. }
  7950. }
  7951. return 0;
  7952. }
  7953. /**
  7954. * i40e_prep_for_reset - prep for the core to reset
  7955. * @pf: board private structure
  7956. * @lock_acquired: indicates whether or not the lock has been acquired
  7957. * before this function was called.
  7958. *
  7959. * Close up the VFs and other things in prep for PF Reset.
  7960. **/
  7961. static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired)
  7962. {
  7963. struct i40e_hw *hw = &pf->hw;
  7964. i40e_status ret = 0;
  7965. u32 v;
  7966. clear_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
  7967. if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  7968. return;
  7969. if (i40e_check_asq_alive(&pf->hw))
  7970. i40e_vc_notify_reset(pf);
  7971. dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
  7972. /* quiesce the VSIs and their queues that are not already DOWN */
  7973. /* pf_quiesce_all_vsi modifies netdev structures -rtnl_lock needed */
  7974. if (!lock_acquired)
  7975. rtnl_lock();
  7976. i40e_pf_quiesce_all_vsi(pf);
  7977. if (!lock_acquired)
  7978. rtnl_unlock();
  7979. for (v = 0; v < pf->num_alloc_vsi; v++) {
  7980. if (pf->vsi[v])
  7981. pf->vsi[v]->seid = 0;
  7982. }
  7983. i40e_shutdown_adminq(&pf->hw);
  7984. /* call shutdown HMC */
  7985. if (hw->hmc.hmc_obj) {
  7986. ret = i40e_shutdown_lan_hmc(hw);
  7987. if (ret)
  7988. dev_warn(&pf->pdev->dev,
  7989. "shutdown_lan_hmc failed: %d\n", ret);
  7990. }
  7991. }
  7992. /**
  7993. * i40e_send_version - update firmware with driver version
  7994. * @pf: PF struct
  7995. */
  7996. static void i40e_send_version(struct i40e_pf *pf)
  7997. {
  7998. struct i40e_driver_version dv;
  7999. dv.major_version = DRV_VERSION_MAJOR;
  8000. dv.minor_version = DRV_VERSION_MINOR;
  8001. dv.build_version = DRV_VERSION_BUILD;
  8002. dv.subbuild_version = 0;
  8003. strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
  8004. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  8005. }
  8006. /**
  8007. * i40e_get_oem_version - get OEM specific version information
  8008. * @hw: pointer to the hardware structure
  8009. **/
  8010. static void i40e_get_oem_version(struct i40e_hw *hw)
  8011. {
  8012. u16 block_offset = 0xffff;
  8013. u16 block_length = 0;
  8014. u16 capabilities = 0;
  8015. u16 gen_snap = 0;
  8016. u16 release = 0;
  8017. #define I40E_SR_NVM_OEM_VERSION_PTR 0x1B
  8018. #define I40E_NVM_OEM_LENGTH_OFFSET 0x00
  8019. #define I40E_NVM_OEM_CAPABILITIES_OFFSET 0x01
  8020. #define I40E_NVM_OEM_GEN_OFFSET 0x02
  8021. #define I40E_NVM_OEM_RELEASE_OFFSET 0x03
  8022. #define I40E_NVM_OEM_CAPABILITIES_MASK 0x000F
  8023. #define I40E_NVM_OEM_LENGTH 3
  8024. /* Check if pointer to OEM version block is valid. */
  8025. i40e_read_nvm_word(hw, I40E_SR_NVM_OEM_VERSION_PTR, &block_offset);
  8026. if (block_offset == 0xffff)
  8027. return;
  8028. /* Check if OEM version block has correct length. */
  8029. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_LENGTH_OFFSET,
  8030. &block_length);
  8031. if (block_length < I40E_NVM_OEM_LENGTH)
  8032. return;
  8033. /* Check if OEM version format is as expected. */
  8034. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_CAPABILITIES_OFFSET,
  8035. &capabilities);
  8036. if ((capabilities & I40E_NVM_OEM_CAPABILITIES_MASK) != 0)
  8037. return;
  8038. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_GEN_OFFSET,
  8039. &gen_snap);
  8040. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_RELEASE_OFFSET,
  8041. &release);
  8042. hw->nvm.oem_ver = (gen_snap << I40E_OEM_SNAP_SHIFT) | release;
  8043. hw->nvm.eetrack = I40E_OEM_EETRACK_ID;
  8044. }
  8045. /**
  8046. * i40e_reset - wait for core reset to finish reset, reset pf if corer not seen
  8047. * @pf: board private structure
  8048. **/
  8049. static int i40e_reset(struct i40e_pf *pf)
  8050. {
  8051. struct i40e_hw *hw = &pf->hw;
  8052. i40e_status ret;
  8053. ret = i40e_pf_reset(hw);
  8054. if (ret) {
  8055. dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
  8056. set_bit(__I40E_RESET_FAILED, pf->state);
  8057. clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
  8058. } else {
  8059. pf->pfr_count++;
  8060. }
  8061. return ret;
  8062. }
  8063. /**
  8064. * i40e_rebuild - rebuild using a saved config
  8065. * @pf: board private structure
  8066. * @reinit: if the Main VSI needs to re-initialized.
  8067. * @lock_acquired: indicates whether or not the lock has been acquired
  8068. * before this function was called.
  8069. **/
  8070. static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired)
  8071. {
  8072. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  8073. struct i40e_hw *hw = &pf->hw;
  8074. u8 set_fc_aq_fail = 0;
  8075. i40e_status ret;
  8076. u32 val;
  8077. int v;
  8078. if (test_bit(__I40E_DOWN, pf->state))
  8079. goto clear_recovery;
  8080. dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
  8081. /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
  8082. ret = i40e_init_adminq(&pf->hw);
  8083. if (ret) {
  8084. dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
  8085. i40e_stat_str(&pf->hw, ret),
  8086. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8087. goto clear_recovery;
  8088. }
  8089. i40e_get_oem_version(&pf->hw);
  8090. /* re-verify the eeprom if we just had an EMP reset */
  8091. if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state))
  8092. i40e_verify_eeprom(pf);
  8093. i40e_clear_pxe_mode(hw);
  8094. ret = i40e_get_capabilities(pf, i40e_aqc_opc_list_func_capabilities);
  8095. if (ret)
  8096. goto end_core_reset;
  8097. ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  8098. hw->func_caps.num_rx_qp, 0, 0);
  8099. if (ret) {
  8100. dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
  8101. goto end_core_reset;
  8102. }
  8103. ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  8104. if (ret) {
  8105. dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
  8106. goto end_core_reset;
  8107. }
  8108. #ifdef CONFIG_I40E_DCB
  8109. ret = i40e_init_pf_dcb(pf);
  8110. if (ret) {
  8111. dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
  8112. pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
  8113. /* Continue without DCB enabled */
  8114. }
  8115. #endif /* CONFIG_I40E_DCB */
  8116. /* do basic switch setup */
  8117. if (!lock_acquired)
  8118. rtnl_lock();
  8119. ret = i40e_setup_pf_switch(pf, reinit);
  8120. if (ret)
  8121. goto end_unlock;
  8122. /* The driver only wants link up/down and module qualification
  8123. * reports from firmware. Note the negative logic.
  8124. */
  8125. ret = i40e_aq_set_phy_int_mask(&pf->hw,
  8126. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  8127. I40E_AQ_EVENT_MEDIA_NA |
  8128. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  8129. if (ret)
  8130. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  8131. i40e_stat_str(&pf->hw, ret),
  8132. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8133. /* make sure our flow control settings are restored */
  8134. ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
  8135. if (ret)
  8136. dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
  8137. i40e_stat_str(&pf->hw, ret),
  8138. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8139. /* Rebuild the VSIs and VEBs that existed before reset.
  8140. * They are still in our local switch element arrays, so only
  8141. * need to rebuild the switch model in the HW.
  8142. *
  8143. * If there were VEBs but the reconstitution failed, we'll try
  8144. * try to recover minimal use by getting the basic PF VSI working.
  8145. */
  8146. if (vsi->uplink_seid != pf->mac_seid) {
  8147. dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
  8148. /* find the one VEB connected to the MAC, and find orphans */
  8149. for (v = 0; v < I40E_MAX_VEB; v++) {
  8150. if (!pf->veb[v])
  8151. continue;
  8152. if (pf->veb[v]->uplink_seid == pf->mac_seid ||
  8153. pf->veb[v]->uplink_seid == 0) {
  8154. ret = i40e_reconstitute_veb(pf->veb[v]);
  8155. if (!ret)
  8156. continue;
  8157. /* If Main VEB failed, we're in deep doodoo,
  8158. * so give up rebuilding the switch and set up
  8159. * for minimal rebuild of PF VSI.
  8160. * If orphan failed, we'll report the error
  8161. * but try to keep going.
  8162. */
  8163. if (pf->veb[v]->uplink_seid == pf->mac_seid) {
  8164. dev_info(&pf->pdev->dev,
  8165. "rebuild of switch failed: %d, will try to set up simple PF connection\n",
  8166. ret);
  8167. vsi->uplink_seid = pf->mac_seid;
  8168. break;
  8169. } else if (pf->veb[v]->uplink_seid == 0) {
  8170. dev_info(&pf->pdev->dev,
  8171. "rebuild of orphan VEB failed: %d\n",
  8172. ret);
  8173. }
  8174. }
  8175. }
  8176. }
  8177. if (vsi->uplink_seid == pf->mac_seid) {
  8178. dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
  8179. /* no VEB, so rebuild only the Main VSI */
  8180. ret = i40e_add_vsi(vsi);
  8181. if (ret) {
  8182. dev_info(&pf->pdev->dev,
  8183. "rebuild of Main VSI failed: %d\n", ret);
  8184. goto end_unlock;
  8185. }
  8186. }
  8187. if (vsi->mqprio_qopt.max_rate[0]) {
  8188. u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
  8189. u64 credits = 0;
  8190. do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
  8191. ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
  8192. if (ret)
  8193. goto end_unlock;
  8194. credits = max_tx_rate;
  8195. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  8196. dev_dbg(&vsi->back->pdev->dev,
  8197. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  8198. max_tx_rate,
  8199. credits,
  8200. vsi->seid);
  8201. }
  8202. ret = i40e_rebuild_cloud_filters(vsi, vsi->seid);
  8203. if (ret)
  8204. goto end_unlock;
  8205. /* PF Main VSI is rebuild by now, go ahead and rebuild channel VSIs
  8206. * for this main VSI if they exist
  8207. */
  8208. ret = i40e_rebuild_channels(vsi);
  8209. if (ret)
  8210. goto end_unlock;
  8211. /* Reconfigure hardware for allowing smaller MSS in the case
  8212. * of TSO, so that we avoid the MDD being fired and causing
  8213. * a reset in the case of small MSS+TSO.
  8214. */
  8215. #define I40E_REG_MSS 0x000E64DC
  8216. #define I40E_REG_MSS_MIN_MASK 0x3FF0000
  8217. #define I40E_64BYTE_MSS 0x400000
  8218. val = rd32(hw, I40E_REG_MSS);
  8219. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  8220. val &= ~I40E_REG_MSS_MIN_MASK;
  8221. val |= I40E_64BYTE_MSS;
  8222. wr32(hw, I40E_REG_MSS, val);
  8223. }
  8224. if (pf->hw_features & I40E_HW_RESTART_AUTONEG) {
  8225. msleep(75);
  8226. ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  8227. if (ret)
  8228. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  8229. i40e_stat_str(&pf->hw, ret),
  8230. i40e_aq_str(&pf->hw,
  8231. pf->hw.aq.asq_last_status));
  8232. }
  8233. /* reinit the misc interrupt */
  8234. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  8235. ret = i40e_setup_misc_vector(pf);
  8236. /* Add a filter to drop all Flow control frames from any VSI from being
  8237. * transmitted. By doing so we stop a malicious VF from sending out
  8238. * PAUSE or PFC frames and potentially controlling traffic for other
  8239. * PF/VF VSIs.
  8240. * The FW can still send Flow control frames if enabled.
  8241. */
  8242. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  8243. pf->main_vsi_seid);
  8244. /* restart the VSIs that were rebuilt and running before the reset */
  8245. i40e_pf_unquiesce_all_vsi(pf);
  8246. /* Release the RTNL lock before we start resetting VFs */
  8247. if (!lock_acquired)
  8248. rtnl_unlock();
  8249. /* Restore promiscuous settings */
  8250. ret = i40e_set_promiscuous(pf, pf->cur_promisc);
  8251. if (ret)
  8252. dev_warn(&pf->pdev->dev,
  8253. "Failed to restore promiscuous setting: %s, err %s aq_err %s\n",
  8254. pf->cur_promisc ? "on" : "off",
  8255. i40e_stat_str(&pf->hw, ret),
  8256. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  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);