i40e_main.c 396 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 3
  46. #define DRV_VERSION_BUILD 2
  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. /* Copy the address first, so that we avoid a possible race with
  1412. * .set_rx_mode(). If we copy after changing the address in the filter
  1413. * list, we might open ourselves to a narrow race window where
  1414. * .set_rx_mode could delete our dev_addr filter and prevent traffic
  1415. * from passing.
  1416. */
  1417. ether_addr_copy(netdev->dev_addr, addr->sa_data);
  1418. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1419. i40e_del_mac_filter(vsi, netdev->dev_addr);
  1420. i40e_add_mac_filter(vsi, addr->sa_data);
  1421. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1422. if (vsi->type == I40E_VSI_MAIN) {
  1423. i40e_status ret;
  1424. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  1425. I40E_AQC_WRITE_TYPE_LAA_WOL,
  1426. addr->sa_data, NULL);
  1427. if (ret)
  1428. netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n",
  1429. i40e_stat_str(hw, ret),
  1430. i40e_aq_str(hw, hw->aq.asq_last_status));
  1431. }
  1432. /* schedule our worker thread which will take care of
  1433. * applying the new filter changes
  1434. */
  1435. i40e_service_event_schedule(vsi->back);
  1436. return 0;
  1437. }
  1438. /**
  1439. * i40e_config_rss_aq - Prepare for RSS using AQ commands
  1440. * @vsi: vsi structure
  1441. * @seed: RSS hash seed
  1442. **/
  1443. static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  1444. u8 *lut, u16 lut_size)
  1445. {
  1446. struct i40e_pf *pf = vsi->back;
  1447. struct i40e_hw *hw = &pf->hw;
  1448. int ret = 0;
  1449. if (seed) {
  1450. struct i40e_aqc_get_set_rss_key_data *seed_dw =
  1451. (struct i40e_aqc_get_set_rss_key_data *)seed;
  1452. ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw);
  1453. if (ret) {
  1454. dev_info(&pf->pdev->dev,
  1455. "Cannot set RSS key, err %s aq_err %s\n",
  1456. i40e_stat_str(hw, ret),
  1457. i40e_aq_str(hw, hw->aq.asq_last_status));
  1458. return ret;
  1459. }
  1460. }
  1461. if (lut) {
  1462. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  1463. ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  1464. if (ret) {
  1465. dev_info(&pf->pdev->dev,
  1466. "Cannot set RSS lut, err %s aq_err %s\n",
  1467. i40e_stat_str(hw, ret),
  1468. i40e_aq_str(hw, hw->aq.asq_last_status));
  1469. return ret;
  1470. }
  1471. }
  1472. return ret;
  1473. }
  1474. /**
  1475. * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
  1476. * @vsi: VSI structure
  1477. **/
  1478. static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
  1479. {
  1480. struct i40e_pf *pf = vsi->back;
  1481. u8 seed[I40E_HKEY_ARRAY_SIZE];
  1482. u8 *lut;
  1483. int ret;
  1484. if (!(pf->hw_features & I40E_HW_RSS_AQ_CAPABLE))
  1485. return 0;
  1486. if (!vsi->rss_size)
  1487. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  1488. vsi->num_queue_pairs);
  1489. if (!vsi->rss_size)
  1490. return -EINVAL;
  1491. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  1492. if (!lut)
  1493. return -ENOMEM;
  1494. /* Use the user configured hash keys and lookup table if there is one,
  1495. * otherwise use default
  1496. */
  1497. if (vsi->rss_lut_user)
  1498. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  1499. else
  1500. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  1501. if (vsi->rss_hkey_user)
  1502. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  1503. else
  1504. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  1505. ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
  1506. kfree(lut);
  1507. return ret;
  1508. }
  1509. /**
  1510. * i40e_vsi_setup_queue_map_mqprio - Prepares mqprio based tc_config
  1511. * @vsi: the VSI being configured,
  1512. * @ctxt: VSI context structure
  1513. * @enabled_tc: number of traffic classes to enable
  1514. *
  1515. * Prepares VSI tc_config to have queue configurations based on MQPRIO options.
  1516. **/
  1517. static int i40e_vsi_setup_queue_map_mqprio(struct i40e_vsi *vsi,
  1518. struct i40e_vsi_context *ctxt,
  1519. u8 enabled_tc)
  1520. {
  1521. u16 qcount = 0, max_qcount, qmap, sections = 0;
  1522. int i, override_q, pow, num_qps, ret;
  1523. u8 netdev_tc = 0, offset = 0;
  1524. if (vsi->type != I40E_VSI_MAIN)
  1525. return -EINVAL;
  1526. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1527. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1528. vsi->tc_config.numtc = vsi->mqprio_qopt.qopt.num_tc;
  1529. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1530. num_qps = vsi->mqprio_qopt.qopt.count[0];
  1531. /* find the next higher power-of-2 of num queue pairs */
  1532. pow = ilog2(num_qps);
  1533. if (!is_power_of_2(num_qps))
  1534. pow++;
  1535. qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1536. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1537. /* Setup queue offset/count for all TCs for given VSI */
  1538. max_qcount = vsi->mqprio_qopt.qopt.count[0];
  1539. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1540. /* See if the given TC is enabled for the given VSI */
  1541. if (vsi->tc_config.enabled_tc & BIT(i)) {
  1542. offset = vsi->mqprio_qopt.qopt.offset[i];
  1543. qcount = vsi->mqprio_qopt.qopt.count[i];
  1544. if (qcount > max_qcount)
  1545. max_qcount = qcount;
  1546. vsi->tc_config.tc_info[i].qoffset = offset;
  1547. vsi->tc_config.tc_info[i].qcount = qcount;
  1548. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1549. } else {
  1550. /* TC is not enabled so set the offset to
  1551. * default queue and allocate one queue
  1552. * for the given TC.
  1553. */
  1554. vsi->tc_config.tc_info[i].qoffset = 0;
  1555. vsi->tc_config.tc_info[i].qcount = 1;
  1556. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1557. }
  1558. }
  1559. /* Set actual Tx/Rx queue pairs */
  1560. vsi->num_queue_pairs = offset + qcount;
  1561. /* Setup queue TC[0].qmap for given VSI context */
  1562. ctxt->info.tc_mapping[0] = cpu_to_le16(qmap);
  1563. ctxt->info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1564. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1565. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1566. /* Reconfigure RSS for main VSI with max queue count */
  1567. vsi->rss_size = max_qcount;
  1568. ret = i40e_vsi_config_rss(vsi);
  1569. if (ret) {
  1570. dev_info(&vsi->back->pdev->dev,
  1571. "Failed to reconfig rss for num_queues (%u)\n",
  1572. max_qcount);
  1573. return ret;
  1574. }
  1575. vsi->reconfig_rss = true;
  1576. dev_dbg(&vsi->back->pdev->dev,
  1577. "Reconfigured rss with num_queues (%u)\n", max_qcount);
  1578. /* Find queue count available for channel VSIs and starting offset
  1579. * for channel VSIs
  1580. */
  1581. override_q = vsi->mqprio_qopt.qopt.count[0];
  1582. if (override_q && override_q < vsi->num_queue_pairs) {
  1583. vsi->cnt_q_avail = vsi->num_queue_pairs - override_q;
  1584. vsi->next_base_queue = override_q;
  1585. }
  1586. return 0;
  1587. }
  1588. /**
  1589. * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
  1590. * @vsi: the VSI being setup
  1591. * @ctxt: VSI context structure
  1592. * @enabled_tc: Enabled TCs bitmap
  1593. * @is_add: True if called before Add VSI
  1594. *
  1595. * Setup VSI queue mapping for enabled traffic classes.
  1596. **/
  1597. static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1598. struct i40e_vsi_context *ctxt,
  1599. u8 enabled_tc,
  1600. bool is_add)
  1601. {
  1602. struct i40e_pf *pf = vsi->back;
  1603. u16 sections = 0;
  1604. u8 netdev_tc = 0;
  1605. u16 numtc = 1;
  1606. u16 qcount;
  1607. u8 offset;
  1608. u16 qmap;
  1609. int i;
  1610. u16 num_tc_qps = 0;
  1611. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1612. offset = 0;
  1613. /* Number of queues per enabled TC */
  1614. num_tc_qps = vsi->alloc_queue_pairs;
  1615. if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  1616. /* Find numtc from enabled TC bitmap */
  1617. for (i = 0, numtc = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1618. if (enabled_tc & BIT(i)) /* TC is enabled */
  1619. numtc++;
  1620. }
  1621. if (!numtc) {
  1622. dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
  1623. numtc = 1;
  1624. }
  1625. num_tc_qps = num_tc_qps / numtc;
  1626. num_tc_qps = min_t(int, num_tc_qps,
  1627. i40e_pf_get_max_q_per_tc(pf));
  1628. }
  1629. vsi->tc_config.numtc = numtc;
  1630. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1631. /* Do not allow use more TC queue pairs than MSI-X vectors exist */
  1632. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  1633. num_tc_qps = min_t(int, num_tc_qps, pf->num_lan_msix);
  1634. /* Setup queue offset/count for all TCs for given VSI */
  1635. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1636. /* See if the given TC is enabled for the given VSI */
  1637. if (vsi->tc_config.enabled_tc & BIT(i)) {
  1638. /* TC is enabled */
  1639. int pow, num_qps;
  1640. switch (vsi->type) {
  1641. case I40E_VSI_MAIN:
  1642. if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED |
  1643. I40E_FLAG_FD_ATR_ENABLED)) ||
  1644. vsi->tc_config.enabled_tc != 1) {
  1645. qcount = min_t(int, pf->alloc_rss_size,
  1646. num_tc_qps);
  1647. break;
  1648. }
  1649. case I40E_VSI_FDIR:
  1650. case I40E_VSI_SRIOV:
  1651. case I40E_VSI_VMDQ2:
  1652. default:
  1653. qcount = num_tc_qps;
  1654. WARN_ON(i != 0);
  1655. break;
  1656. }
  1657. vsi->tc_config.tc_info[i].qoffset = offset;
  1658. vsi->tc_config.tc_info[i].qcount = qcount;
  1659. /* find the next higher power-of-2 of num queue pairs */
  1660. num_qps = qcount;
  1661. pow = 0;
  1662. while (num_qps && (BIT_ULL(pow) < qcount)) {
  1663. pow++;
  1664. num_qps >>= 1;
  1665. }
  1666. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1667. qmap =
  1668. (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1669. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1670. offset += qcount;
  1671. } else {
  1672. /* TC is not enabled so set the offset to
  1673. * default queue and allocate one queue
  1674. * for the given TC.
  1675. */
  1676. vsi->tc_config.tc_info[i].qoffset = 0;
  1677. vsi->tc_config.tc_info[i].qcount = 1;
  1678. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1679. qmap = 0;
  1680. }
  1681. ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
  1682. }
  1683. /* Set actual Tx/Rx queue pairs */
  1684. vsi->num_queue_pairs = offset;
  1685. if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
  1686. if (vsi->req_queue_pairs > 0)
  1687. vsi->num_queue_pairs = vsi->req_queue_pairs;
  1688. else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  1689. vsi->num_queue_pairs = pf->num_lan_msix;
  1690. }
  1691. /* Scheduler section valid can only be set for ADD VSI */
  1692. if (is_add) {
  1693. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1694. ctxt->info.up_enable_bits = enabled_tc;
  1695. }
  1696. if (vsi->type == I40E_VSI_SRIOV) {
  1697. ctxt->info.mapping_flags |=
  1698. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
  1699. for (i = 0; i < vsi->num_queue_pairs; i++)
  1700. ctxt->info.queue_mapping[i] =
  1701. cpu_to_le16(vsi->base_queue + i);
  1702. } else {
  1703. ctxt->info.mapping_flags |=
  1704. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1705. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1706. }
  1707. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1708. }
  1709. /**
  1710. * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address
  1711. * @netdev: the netdevice
  1712. * @addr: address to add
  1713. *
  1714. * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
  1715. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  1716. */
  1717. static int i40e_addr_sync(struct net_device *netdev, const u8 *addr)
  1718. {
  1719. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1720. struct i40e_vsi *vsi = np->vsi;
  1721. if (i40e_add_mac_filter(vsi, addr))
  1722. return 0;
  1723. else
  1724. return -ENOMEM;
  1725. }
  1726. /**
  1727. * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
  1728. * @netdev: the netdevice
  1729. * @addr: address to add
  1730. *
  1731. * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
  1732. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  1733. */
  1734. static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr)
  1735. {
  1736. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1737. struct i40e_vsi *vsi = np->vsi;
  1738. /* Under some circumstances, we might receive a request to delete
  1739. * our own device address from our uc list. Because we store the
  1740. * device address in the VSI's MAC/VLAN filter list, we need to ignore
  1741. * such requests and not delete our device address from this list.
  1742. */
  1743. if (ether_addr_equal(addr, netdev->dev_addr))
  1744. return 0;
  1745. i40e_del_mac_filter(vsi, addr);
  1746. return 0;
  1747. }
  1748. /**
  1749. * i40e_set_rx_mode - NDO callback to set the netdev filters
  1750. * @netdev: network interface device structure
  1751. **/
  1752. static void i40e_set_rx_mode(struct net_device *netdev)
  1753. {
  1754. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1755. struct i40e_vsi *vsi = np->vsi;
  1756. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1757. __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
  1758. __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
  1759. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1760. /* check for other flag changes */
  1761. if (vsi->current_netdev_flags != vsi->netdev->flags) {
  1762. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1763. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1764. }
  1765. }
  1766. /**
  1767. * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
  1768. * @vsi: Pointer to VSI struct
  1769. * @from: Pointer to list which contains MAC filter entries - changes to
  1770. * those entries needs to be undone.
  1771. *
  1772. * MAC filter entries from this list were slated for deletion.
  1773. **/
  1774. static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi,
  1775. struct hlist_head *from)
  1776. {
  1777. struct i40e_mac_filter *f;
  1778. struct hlist_node *h;
  1779. hlist_for_each_entry_safe(f, h, from, hlist) {
  1780. u64 key = i40e_addr_to_hkey(f->macaddr);
  1781. /* Move the element back into MAC filter list*/
  1782. hlist_del(&f->hlist);
  1783. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1784. }
  1785. }
  1786. /**
  1787. * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
  1788. * @vsi: Pointer to vsi struct
  1789. * @from: Pointer to list which contains MAC filter entries - changes to
  1790. * those entries needs to be undone.
  1791. *
  1792. * MAC filter entries from this list were slated for addition.
  1793. **/
  1794. static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi,
  1795. struct hlist_head *from)
  1796. {
  1797. struct i40e_new_mac_filter *new;
  1798. struct hlist_node *h;
  1799. hlist_for_each_entry_safe(new, h, from, hlist) {
  1800. /* We can simply free the wrapper structure */
  1801. hlist_del(&new->hlist);
  1802. kfree(new);
  1803. }
  1804. }
  1805. /**
  1806. * i40e_next_entry - Get the next non-broadcast filter from a list
  1807. * @next: pointer to filter in list
  1808. *
  1809. * Returns the next non-broadcast filter in the list. Required so that we
  1810. * ignore broadcast filters within the list, since these are not handled via
  1811. * the normal firmware update path.
  1812. */
  1813. static
  1814. struct i40e_new_mac_filter *i40e_next_filter(struct i40e_new_mac_filter *next)
  1815. {
  1816. hlist_for_each_entry_continue(next, hlist) {
  1817. if (!is_broadcast_ether_addr(next->f->macaddr))
  1818. return next;
  1819. }
  1820. return NULL;
  1821. }
  1822. /**
  1823. * i40e_update_filter_state - Update filter state based on return data
  1824. * from firmware
  1825. * @count: Number of filters added
  1826. * @add_list: return data from fw
  1827. * @head: pointer to first filter in current batch
  1828. *
  1829. * MAC filter entries from list were slated to be added to device. Returns
  1830. * number of successful filters. Note that 0 does NOT mean success!
  1831. **/
  1832. static int
  1833. i40e_update_filter_state(int count,
  1834. struct i40e_aqc_add_macvlan_element_data *add_list,
  1835. struct i40e_new_mac_filter *add_head)
  1836. {
  1837. int retval = 0;
  1838. int i;
  1839. for (i = 0; i < count; i++) {
  1840. /* Always check status of each filter. We don't need to check
  1841. * the firmware return status because we pre-set the filter
  1842. * status to I40E_AQC_MM_ERR_NO_RES when sending the filter
  1843. * request to the adminq. Thus, if it no longer matches then
  1844. * we know the filter is active.
  1845. */
  1846. if (add_list[i].match_method == I40E_AQC_MM_ERR_NO_RES) {
  1847. add_head->state = I40E_FILTER_FAILED;
  1848. } else {
  1849. add_head->state = I40E_FILTER_ACTIVE;
  1850. retval++;
  1851. }
  1852. add_head = i40e_next_filter(add_head);
  1853. if (!add_head)
  1854. break;
  1855. }
  1856. return retval;
  1857. }
  1858. /**
  1859. * i40e_aqc_del_filters - Request firmware to delete a set of filters
  1860. * @vsi: ptr to the VSI
  1861. * @vsi_name: name to display in messages
  1862. * @list: the list of filters to send to firmware
  1863. * @num_del: the number of filters to delete
  1864. * @retval: Set to -EIO on failure to delete
  1865. *
  1866. * Send a request to firmware via AdminQ to delete a set of filters. Uses
  1867. * *retval instead of a return value so that success does not force ret_val to
  1868. * be set to 0. This ensures that a sequence of calls to this function
  1869. * preserve the previous value of *retval on successful delete.
  1870. */
  1871. static
  1872. void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name,
  1873. struct i40e_aqc_remove_macvlan_element_data *list,
  1874. int num_del, int *retval)
  1875. {
  1876. struct i40e_hw *hw = &vsi->back->hw;
  1877. i40e_status aq_ret;
  1878. int aq_err;
  1879. aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL);
  1880. aq_err = hw->aq.asq_last_status;
  1881. /* Explicitly ignore and do not report when firmware returns ENOENT */
  1882. if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) {
  1883. *retval = -EIO;
  1884. dev_info(&vsi->back->pdev->dev,
  1885. "ignoring delete macvlan error on %s, err %s, aq_err %s\n",
  1886. vsi_name, i40e_stat_str(hw, aq_ret),
  1887. i40e_aq_str(hw, aq_err));
  1888. }
  1889. }
  1890. /**
  1891. * i40e_aqc_add_filters - Request firmware to add a set of filters
  1892. * @vsi: ptr to the VSI
  1893. * @vsi_name: name to display in messages
  1894. * @list: the list of filters to send to firmware
  1895. * @add_head: Position in the add hlist
  1896. * @num_add: the number of filters to add
  1897. * @promisc_change: set to true on exit if promiscuous mode was forced on
  1898. *
  1899. * Send a request to firmware via AdminQ to add a chunk of filters. Will set
  1900. * promisc_changed to true if the firmware has run out of space for more
  1901. * filters.
  1902. */
  1903. static
  1904. void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name,
  1905. struct i40e_aqc_add_macvlan_element_data *list,
  1906. struct i40e_new_mac_filter *add_head,
  1907. int num_add, bool *promisc_changed)
  1908. {
  1909. struct i40e_hw *hw = &vsi->back->hw;
  1910. int aq_err, fcnt;
  1911. i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL);
  1912. aq_err = hw->aq.asq_last_status;
  1913. fcnt = i40e_update_filter_state(num_add, list, add_head);
  1914. if (fcnt != num_add) {
  1915. *promisc_changed = true;
  1916. set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  1917. dev_warn(&vsi->back->pdev->dev,
  1918. "Error %s adding RX filters on %s, promiscuous mode forced on\n",
  1919. i40e_aq_str(hw, aq_err),
  1920. vsi_name);
  1921. }
  1922. }
  1923. /**
  1924. * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags
  1925. * @vsi: pointer to the VSI
  1926. * @f: filter data
  1927. *
  1928. * This function sets or clears the promiscuous broadcast flags for VLAN
  1929. * filters in order to properly receive broadcast frames. Assumes that only
  1930. * broadcast filters are passed.
  1931. *
  1932. * Returns status indicating success or failure;
  1933. **/
  1934. static i40e_status
  1935. i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name,
  1936. struct i40e_mac_filter *f)
  1937. {
  1938. bool enable = f->state == I40E_FILTER_NEW;
  1939. struct i40e_hw *hw = &vsi->back->hw;
  1940. i40e_status aq_ret;
  1941. if (f->vlan == I40E_VLAN_ANY) {
  1942. aq_ret = i40e_aq_set_vsi_broadcast(hw,
  1943. vsi->seid,
  1944. enable,
  1945. NULL);
  1946. } else {
  1947. aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw,
  1948. vsi->seid,
  1949. enable,
  1950. f->vlan,
  1951. NULL);
  1952. }
  1953. if (aq_ret)
  1954. dev_warn(&vsi->back->pdev->dev,
  1955. "Error %s setting broadcast promiscuous mode on %s\n",
  1956. i40e_aq_str(hw, hw->aq.asq_last_status),
  1957. vsi_name);
  1958. return aq_ret;
  1959. }
  1960. /**
  1961. * i40e_set_promiscuous - set promiscuous mode
  1962. * @pf: board private structure
  1963. * @promisc: promisc on or off
  1964. *
  1965. * There are different ways of setting promiscuous mode on a PF depending on
  1966. * what state/environment we're in. This identifies and sets it appropriately.
  1967. * Returns 0 on success.
  1968. **/
  1969. static int i40e_set_promiscuous(struct i40e_pf *pf, bool promisc)
  1970. {
  1971. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  1972. struct i40e_hw *hw = &pf->hw;
  1973. i40e_status aq_ret;
  1974. if (vsi->type == I40E_VSI_MAIN &&
  1975. pf->lan_veb != I40E_NO_VEB &&
  1976. !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
  1977. /* set defport ON for Main VSI instead of true promisc
  1978. * this way we will get all unicast/multicast and VLAN
  1979. * promisc behavior but will not get VF or VMDq traffic
  1980. * replicated on the Main VSI.
  1981. */
  1982. if (promisc)
  1983. aq_ret = i40e_aq_set_default_vsi(hw,
  1984. vsi->seid,
  1985. NULL);
  1986. else
  1987. aq_ret = i40e_aq_clear_default_vsi(hw,
  1988. vsi->seid,
  1989. NULL);
  1990. if (aq_ret) {
  1991. dev_info(&pf->pdev->dev,
  1992. "Set default VSI failed, err %s, aq_err %s\n",
  1993. i40e_stat_str(hw, aq_ret),
  1994. i40e_aq_str(hw, hw->aq.asq_last_status));
  1995. }
  1996. } else {
  1997. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
  1998. hw,
  1999. vsi->seid,
  2000. promisc, NULL,
  2001. true);
  2002. if (aq_ret) {
  2003. dev_info(&pf->pdev->dev,
  2004. "set unicast promisc failed, err %s, aq_err %s\n",
  2005. i40e_stat_str(hw, aq_ret),
  2006. i40e_aq_str(hw, hw->aq.asq_last_status));
  2007. }
  2008. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
  2009. hw,
  2010. vsi->seid,
  2011. promisc, NULL);
  2012. if (aq_ret) {
  2013. dev_info(&pf->pdev->dev,
  2014. "set multicast promisc failed, err %s, aq_err %s\n",
  2015. i40e_stat_str(hw, aq_ret),
  2016. i40e_aq_str(hw, hw->aq.asq_last_status));
  2017. }
  2018. }
  2019. if (!aq_ret)
  2020. pf->cur_promisc = promisc;
  2021. return aq_ret;
  2022. }
  2023. /**
  2024. * i40e_sync_vsi_filters - Update the VSI filter list to the HW
  2025. * @vsi: ptr to the VSI
  2026. *
  2027. * Push any outstanding VSI filter changes through the AdminQ.
  2028. *
  2029. * Returns 0 or error value
  2030. **/
  2031. int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
  2032. {
  2033. struct hlist_head tmp_add_list, tmp_del_list;
  2034. struct i40e_mac_filter *f;
  2035. struct i40e_new_mac_filter *new, *add_head = NULL;
  2036. struct i40e_hw *hw = &vsi->back->hw;
  2037. unsigned int failed_filters = 0;
  2038. unsigned int vlan_filters = 0;
  2039. bool promisc_changed = false;
  2040. char vsi_name[16] = "PF";
  2041. int filter_list_len = 0;
  2042. i40e_status aq_ret = 0;
  2043. u32 changed_flags = 0;
  2044. struct hlist_node *h;
  2045. struct i40e_pf *pf;
  2046. int num_add = 0;
  2047. int num_del = 0;
  2048. int retval = 0;
  2049. u16 cmd_flags;
  2050. int list_size;
  2051. int bkt;
  2052. /* empty array typed pointers, kcalloc later */
  2053. struct i40e_aqc_add_macvlan_element_data *add_list;
  2054. struct i40e_aqc_remove_macvlan_element_data *del_list;
  2055. while (test_and_set_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state))
  2056. usleep_range(1000, 2000);
  2057. pf = vsi->back;
  2058. if (vsi->netdev) {
  2059. changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
  2060. vsi->current_netdev_flags = vsi->netdev->flags;
  2061. }
  2062. INIT_HLIST_HEAD(&tmp_add_list);
  2063. INIT_HLIST_HEAD(&tmp_del_list);
  2064. if (vsi->type == I40E_VSI_SRIOV)
  2065. snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id);
  2066. else if (vsi->type != I40E_VSI_MAIN)
  2067. snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid);
  2068. if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
  2069. vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
  2070. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2071. /* Create a list of filters to delete. */
  2072. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2073. if (f->state == I40E_FILTER_REMOVE) {
  2074. /* Move the element into temporary del_list */
  2075. hash_del(&f->hlist);
  2076. hlist_add_head(&f->hlist, &tmp_del_list);
  2077. /* Avoid counting removed filters */
  2078. continue;
  2079. }
  2080. if (f->state == I40E_FILTER_NEW) {
  2081. /* Create a temporary i40e_new_mac_filter */
  2082. new = kzalloc(sizeof(*new), GFP_ATOMIC);
  2083. if (!new)
  2084. goto err_no_memory_locked;
  2085. /* Store pointer to the real filter */
  2086. new->f = f;
  2087. new->state = f->state;
  2088. /* Add it to the hash list */
  2089. hlist_add_head(&new->hlist, &tmp_add_list);
  2090. }
  2091. /* Count the number of active (current and new) VLAN
  2092. * filters we have now. Does not count filters which
  2093. * are marked for deletion.
  2094. */
  2095. if (f->vlan > 0)
  2096. vlan_filters++;
  2097. }
  2098. retval = i40e_correct_mac_vlan_filters(vsi,
  2099. &tmp_add_list,
  2100. &tmp_del_list,
  2101. vlan_filters);
  2102. if (retval)
  2103. goto err_no_memory_locked;
  2104. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2105. }
  2106. /* Now process 'del_list' outside the lock */
  2107. if (!hlist_empty(&tmp_del_list)) {
  2108. filter_list_len = hw->aq.asq_buf_size /
  2109. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  2110. list_size = filter_list_len *
  2111. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  2112. del_list = kzalloc(list_size, GFP_ATOMIC);
  2113. if (!del_list)
  2114. goto err_no_memory;
  2115. hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) {
  2116. cmd_flags = 0;
  2117. /* handle broadcast filters by updating the broadcast
  2118. * promiscuous flag and release filter list.
  2119. */
  2120. if (is_broadcast_ether_addr(f->macaddr)) {
  2121. i40e_aqc_broadcast_filter(vsi, vsi_name, f);
  2122. hlist_del(&f->hlist);
  2123. kfree(f);
  2124. continue;
  2125. }
  2126. /* add to delete list */
  2127. ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
  2128. if (f->vlan == I40E_VLAN_ANY) {
  2129. del_list[num_del].vlan_tag = 0;
  2130. cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  2131. } else {
  2132. del_list[num_del].vlan_tag =
  2133. cpu_to_le16((u16)(f->vlan));
  2134. }
  2135. cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  2136. del_list[num_del].flags = cmd_flags;
  2137. num_del++;
  2138. /* flush a full buffer */
  2139. if (num_del == filter_list_len) {
  2140. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  2141. num_del, &retval);
  2142. memset(del_list, 0, list_size);
  2143. num_del = 0;
  2144. }
  2145. /* Release memory for MAC filter entries which were
  2146. * synced up with HW.
  2147. */
  2148. hlist_del(&f->hlist);
  2149. kfree(f);
  2150. }
  2151. if (num_del) {
  2152. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  2153. num_del, &retval);
  2154. }
  2155. kfree(del_list);
  2156. del_list = NULL;
  2157. }
  2158. if (!hlist_empty(&tmp_add_list)) {
  2159. /* Do all the adds now. */
  2160. filter_list_len = hw->aq.asq_buf_size /
  2161. sizeof(struct i40e_aqc_add_macvlan_element_data);
  2162. list_size = filter_list_len *
  2163. sizeof(struct i40e_aqc_add_macvlan_element_data);
  2164. add_list = kzalloc(list_size, GFP_ATOMIC);
  2165. if (!add_list)
  2166. goto err_no_memory;
  2167. num_add = 0;
  2168. hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
  2169. if (test_bit(__I40E_VSI_OVERFLOW_PROMISC,
  2170. vsi->state)) {
  2171. new->state = I40E_FILTER_FAILED;
  2172. continue;
  2173. }
  2174. /* handle broadcast filters by updating the broadcast
  2175. * promiscuous flag instead of adding a MAC filter.
  2176. */
  2177. if (is_broadcast_ether_addr(new->f->macaddr)) {
  2178. if (i40e_aqc_broadcast_filter(vsi, vsi_name,
  2179. new->f))
  2180. new->state = I40E_FILTER_FAILED;
  2181. else
  2182. new->state = I40E_FILTER_ACTIVE;
  2183. continue;
  2184. }
  2185. /* add to add array */
  2186. if (num_add == 0)
  2187. add_head = new;
  2188. cmd_flags = 0;
  2189. ether_addr_copy(add_list[num_add].mac_addr,
  2190. new->f->macaddr);
  2191. if (new->f->vlan == I40E_VLAN_ANY) {
  2192. add_list[num_add].vlan_tag = 0;
  2193. cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
  2194. } else {
  2195. add_list[num_add].vlan_tag =
  2196. cpu_to_le16((u16)(new->f->vlan));
  2197. }
  2198. add_list[num_add].queue_number = 0;
  2199. /* set invalid match method for later detection */
  2200. add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES;
  2201. cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
  2202. add_list[num_add].flags = cpu_to_le16(cmd_flags);
  2203. num_add++;
  2204. /* flush a full buffer */
  2205. if (num_add == filter_list_len) {
  2206. i40e_aqc_add_filters(vsi, vsi_name, add_list,
  2207. add_head, num_add,
  2208. &promisc_changed);
  2209. memset(add_list, 0, list_size);
  2210. num_add = 0;
  2211. }
  2212. }
  2213. if (num_add) {
  2214. i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head,
  2215. num_add, &promisc_changed);
  2216. }
  2217. /* Now move all of the filters from the temp add list back to
  2218. * the VSI's list.
  2219. */
  2220. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2221. hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
  2222. /* Only update the state if we're still NEW */
  2223. if (new->f->state == I40E_FILTER_NEW)
  2224. new->f->state = new->state;
  2225. hlist_del(&new->hlist);
  2226. kfree(new);
  2227. }
  2228. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2229. kfree(add_list);
  2230. add_list = NULL;
  2231. }
  2232. /* Determine the number of active and failed filters. */
  2233. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2234. vsi->active_filters = 0;
  2235. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
  2236. if (f->state == I40E_FILTER_ACTIVE)
  2237. vsi->active_filters++;
  2238. else if (f->state == I40E_FILTER_FAILED)
  2239. failed_filters++;
  2240. }
  2241. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2242. /* If promiscuous mode has changed, we need to calculate a new
  2243. * threshold for when we are safe to exit
  2244. */
  2245. if (promisc_changed)
  2246. vsi->promisc_threshold = (vsi->active_filters * 3) / 4;
  2247. /* Check if we are able to exit overflow promiscuous mode. We can
  2248. * safely exit if we didn't just enter, we no longer have any failed
  2249. * filters, and we have reduced filters below the threshold value.
  2250. */
  2251. if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state) &&
  2252. !promisc_changed && !failed_filters &&
  2253. (vsi->active_filters < vsi->promisc_threshold)) {
  2254. dev_info(&pf->pdev->dev,
  2255. "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
  2256. vsi_name);
  2257. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  2258. promisc_changed = true;
  2259. vsi->promisc_threshold = 0;
  2260. }
  2261. /* if the VF is not trusted do not do promisc */
  2262. if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) {
  2263. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  2264. goto out;
  2265. }
  2266. /* check for changes in promiscuous modes */
  2267. if (changed_flags & IFF_ALLMULTI) {
  2268. bool cur_multipromisc;
  2269. cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
  2270. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
  2271. vsi->seid,
  2272. cur_multipromisc,
  2273. NULL);
  2274. if (aq_ret) {
  2275. retval = i40e_aq_rc_to_posix(aq_ret,
  2276. hw->aq.asq_last_status);
  2277. dev_info(&pf->pdev->dev,
  2278. "set multi promisc failed on %s, err %s aq_err %s\n",
  2279. vsi_name,
  2280. i40e_stat_str(hw, aq_ret),
  2281. i40e_aq_str(hw, hw->aq.asq_last_status));
  2282. }
  2283. }
  2284. if ((changed_flags & IFF_PROMISC) || promisc_changed) {
  2285. bool cur_promisc;
  2286. cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
  2287. test_bit(__I40E_VSI_OVERFLOW_PROMISC,
  2288. vsi->state));
  2289. aq_ret = i40e_set_promiscuous(pf, cur_promisc);
  2290. if (aq_ret) {
  2291. retval = i40e_aq_rc_to_posix(aq_ret,
  2292. hw->aq.asq_last_status);
  2293. dev_info(&pf->pdev->dev,
  2294. "Setting promiscuous %s failed on %s, err %s aq_err %s\n",
  2295. cur_promisc ? "on" : "off",
  2296. vsi_name,
  2297. i40e_stat_str(hw, aq_ret),
  2298. i40e_aq_str(hw, hw->aq.asq_last_status));
  2299. }
  2300. }
  2301. out:
  2302. /* if something went wrong then set the changed flag so we try again */
  2303. if (retval)
  2304. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2305. clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
  2306. return retval;
  2307. err_no_memory:
  2308. /* Restore elements on the temporary add and delete lists */
  2309. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2310. err_no_memory_locked:
  2311. i40e_undo_del_filter_entries(vsi, &tmp_del_list);
  2312. i40e_undo_add_filter_entries(vsi, &tmp_add_list);
  2313. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2314. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2315. clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
  2316. return -ENOMEM;
  2317. }
  2318. /**
  2319. * i40e_sync_filters_subtask - Sync the VSI filter list with HW
  2320. * @pf: board private structure
  2321. **/
  2322. static void i40e_sync_filters_subtask(struct i40e_pf *pf)
  2323. {
  2324. int v;
  2325. if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
  2326. return;
  2327. pf->flags &= ~I40E_FLAG_FILTER_SYNC;
  2328. for (v = 0; v < pf->num_alloc_vsi; v++) {
  2329. if (pf->vsi[v] &&
  2330. (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
  2331. int ret = i40e_sync_vsi_filters(pf->vsi[v]);
  2332. if (ret) {
  2333. /* come back and try again later */
  2334. pf->flags |= I40E_FLAG_FILTER_SYNC;
  2335. break;
  2336. }
  2337. }
  2338. }
  2339. }
  2340. /**
  2341. * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP
  2342. * @vsi: the vsi
  2343. **/
  2344. static int i40e_max_xdp_frame_size(struct i40e_vsi *vsi)
  2345. {
  2346. if (PAGE_SIZE >= 8192 || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
  2347. return I40E_RXBUFFER_2048;
  2348. else
  2349. return I40E_RXBUFFER_3072;
  2350. }
  2351. /**
  2352. * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  2353. * @netdev: network interface device structure
  2354. * @new_mtu: new value for maximum frame size
  2355. *
  2356. * Returns 0 on success, negative on failure
  2357. **/
  2358. static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
  2359. {
  2360. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2361. struct i40e_vsi *vsi = np->vsi;
  2362. struct i40e_pf *pf = vsi->back;
  2363. if (i40e_enabled_xdp_vsi(vsi)) {
  2364. int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  2365. if (frame_size > i40e_max_xdp_frame_size(vsi))
  2366. return -EINVAL;
  2367. }
  2368. netdev_info(netdev, "changing MTU from %d to %d\n",
  2369. netdev->mtu, new_mtu);
  2370. netdev->mtu = new_mtu;
  2371. if (netif_running(netdev))
  2372. i40e_vsi_reinit_locked(vsi);
  2373. pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED |
  2374. I40E_FLAG_CLIENT_L2_CHANGE);
  2375. return 0;
  2376. }
  2377. /**
  2378. * i40e_ioctl - Access the hwtstamp interface
  2379. * @netdev: network interface device structure
  2380. * @ifr: interface request data
  2381. * @cmd: ioctl command
  2382. **/
  2383. int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  2384. {
  2385. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2386. struct i40e_pf *pf = np->vsi->back;
  2387. switch (cmd) {
  2388. case SIOCGHWTSTAMP:
  2389. return i40e_ptp_get_ts_config(pf, ifr);
  2390. case SIOCSHWTSTAMP:
  2391. return i40e_ptp_set_ts_config(pf, ifr);
  2392. default:
  2393. return -EOPNOTSUPP;
  2394. }
  2395. }
  2396. /**
  2397. * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
  2398. * @vsi: the vsi being adjusted
  2399. **/
  2400. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
  2401. {
  2402. struct i40e_vsi_context ctxt;
  2403. i40e_status ret;
  2404. if ((vsi->info.valid_sections &
  2405. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2406. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
  2407. return; /* already enabled */
  2408. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2409. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2410. I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
  2411. ctxt.seid = vsi->seid;
  2412. ctxt.info = vsi->info;
  2413. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2414. if (ret) {
  2415. dev_info(&vsi->back->pdev->dev,
  2416. "update vlan stripping failed, err %s aq_err %s\n",
  2417. i40e_stat_str(&vsi->back->hw, ret),
  2418. i40e_aq_str(&vsi->back->hw,
  2419. vsi->back->hw.aq.asq_last_status));
  2420. }
  2421. }
  2422. /**
  2423. * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
  2424. * @vsi: the vsi being adjusted
  2425. **/
  2426. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
  2427. {
  2428. struct i40e_vsi_context ctxt;
  2429. i40e_status ret;
  2430. if ((vsi->info.valid_sections &
  2431. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2432. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
  2433. I40E_AQ_VSI_PVLAN_EMOD_MASK))
  2434. return; /* already disabled */
  2435. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2436. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2437. I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
  2438. ctxt.seid = vsi->seid;
  2439. ctxt.info = vsi->info;
  2440. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2441. if (ret) {
  2442. dev_info(&vsi->back->pdev->dev,
  2443. "update vlan stripping failed, err %s aq_err %s\n",
  2444. i40e_stat_str(&vsi->back->hw, ret),
  2445. i40e_aq_str(&vsi->back->hw,
  2446. vsi->back->hw.aq.asq_last_status));
  2447. }
  2448. }
  2449. /**
  2450. * i40e_vlan_rx_register - Setup or shutdown vlan offload
  2451. * @netdev: network interface to be adjusted
  2452. * @features: netdev features to test if VLAN offload is enabled or not
  2453. **/
  2454. static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
  2455. {
  2456. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2457. struct i40e_vsi *vsi = np->vsi;
  2458. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  2459. i40e_vlan_stripping_enable(vsi);
  2460. else
  2461. i40e_vlan_stripping_disable(vsi);
  2462. }
  2463. /**
  2464. * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address
  2465. * @vsi: the vsi being configured
  2466. * @vid: vlan id to be added (0 = untagged only , -1 = any)
  2467. *
  2468. * This is a helper function for adding a new MAC/VLAN filter with the
  2469. * specified VLAN for each existing MAC address already in the hash table.
  2470. * This function does *not* perform any accounting to update filters based on
  2471. * VLAN mode.
  2472. *
  2473. * NOTE: this function expects to be called while under the
  2474. * mac_filter_hash_lock
  2475. **/
  2476. int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2477. {
  2478. struct i40e_mac_filter *f, *add_f;
  2479. struct hlist_node *h;
  2480. int bkt;
  2481. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2482. if (f->state == I40E_FILTER_REMOVE)
  2483. continue;
  2484. add_f = i40e_add_filter(vsi, f->macaddr, vid);
  2485. if (!add_f) {
  2486. dev_info(&vsi->back->pdev->dev,
  2487. "Could not add vlan filter %d for %pM\n",
  2488. vid, f->macaddr);
  2489. return -ENOMEM;
  2490. }
  2491. }
  2492. return 0;
  2493. }
  2494. /**
  2495. * i40e_vsi_add_vlan - Add VSI membership for given VLAN
  2496. * @vsi: the VSI being configured
  2497. * @vid: VLAN id to be added
  2498. **/
  2499. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid)
  2500. {
  2501. int err;
  2502. if (vsi->info.pvid)
  2503. return -EINVAL;
  2504. /* The network stack will attempt to add VID=0, with the intention to
  2505. * receive priority tagged packets with a VLAN of 0. Our HW receives
  2506. * these packets by default when configured to receive untagged
  2507. * packets, so we don't need to add a filter for this case.
  2508. * Additionally, HW interprets adding a VID=0 filter as meaning to
  2509. * receive *only* tagged traffic and stops receiving untagged traffic.
  2510. * Thus, we do not want to actually add a filter for VID=0
  2511. */
  2512. if (!vid)
  2513. return 0;
  2514. /* Locked once because all functions invoked below iterates list*/
  2515. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2516. err = i40e_add_vlan_all_mac(vsi, vid);
  2517. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2518. if (err)
  2519. return err;
  2520. /* schedule our worker thread which will take care of
  2521. * applying the new filter changes
  2522. */
  2523. i40e_service_event_schedule(vsi->back);
  2524. return 0;
  2525. }
  2526. /**
  2527. * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN
  2528. * @vsi: the vsi being configured
  2529. * @vid: vlan id to be removed (0 = untagged only , -1 = any)
  2530. *
  2531. * This function should be used to remove all VLAN filters which match the
  2532. * given VID. It does not schedule the service event and does not take the
  2533. * mac_filter_hash_lock so it may be combined with other operations under
  2534. * a single invocation of the mac_filter_hash_lock.
  2535. *
  2536. * NOTE: this function expects to be called while under the
  2537. * mac_filter_hash_lock
  2538. */
  2539. void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2540. {
  2541. struct i40e_mac_filter *f;
  2542. struct hlist_node *h;
  2543. int bkt;
  2544. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2545. if (f->vlan == vid)
  2546. __i40e_del_filter(vsi, f);
  2547. }
  2548. }
  2549. /**
  2550. * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN
  2551. * @vsi: the VSI being configured
  2552. * @vid: VLAN id to be removed
  2553. **/
  2554. void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid)
  2555. {
  2556. if (!vid || vsi->info.pvid)
  2557. return;
  2558. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2559. i40e_rm_vlan_all_mac(vsi, vid);
  2560. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2561. /* schedule our worker thread which will take care of
  2562. * applying the new filter changes
  2563. */
  2564. i40e_service_event_schedule(vsi->back);
  2565. }
  2566. /**
  2567. * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
  2568. * @netdev: network interface to be adjusted
  2569. * @vid: vlan id to be added
  2570. *
  2571. * net_device_ops implementation for adding vlan ids
  2572. **/
  2573. static int i40e_vlan_rx_add_vid(struct net_device *netdev,
  2574. __always_unused __be16 proto, u16 vid)
  2575. {
  2576. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2577. struct i40e_vsi *vsi = np->vsi;
  2578. int ret = 0;
  2579. if (vid >= VLAN_N_VID)
  2580. return -EINVAL;
  2581. ret = i40e_vsi_add_vlan(vsi, vid);
  2582. if (!ret)
  2583. set_bit(vid, vsi->active_vlans);
  2584. return ret;
  2585. }
  2586. /**
  2587. * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
  2588. * @netdev: network interface to be adjusted
  2589. * @vid: vlan id to be removed
  2590. *
  2591. * net_device_ops implementation for removing vlan ids
  2592. **/
  2593. static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  2594. __always_unused __be16 proto, u16 vid)
  2595. {
  2596. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2597. struct i40e_vsi *vsi = np->vsi;
  2598. /* return code is ignored as there is nothing a user
  2599. * can do about failure to remove and a log message was
  2600. * already printed from the other function
  2601. */
  2602. i40e_vsi_kill_vlan(vsi, vid);
  2603. clear_bit(vid, vsi->active_vlans);
  2604. return 0;
  2605. }
  2606. /**
  2607. * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
  2608. * @vsi: the vsi being brought back up
  2609. **/
  2610. static void i40e_restore_vlan(struct i40e_vsi *vsi)
  2611. {
  2612. u16 vid;
  2613. if (!vsi->netdev)
  2614. return;
  2615. i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
  2616. for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
  2617. i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
  2618. vid);
  2619. }
  2620. /**
  2621. * i40e_vsi_add_pvid - Add pvid for the VSI
  2622. * @vsi: the vsi being adjusted
  2623. * @vid: the vlan id to set as a PVID
  2624. **/
  2625. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
  2626. {
  2627. struct i40e_vsi_context ctxt;
  2628. i40e_status ret;
  2629. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2630. vsi->info.pvid = cpu_to_le16(vid);
  2631. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
  2632. I40E_AQ_VSI_PVLAN_INSERT_PVID |
  2633. I40E_AQ_VSI_PVLAN_EMOD_STR;
  2634. ctxt.seid = vsi->seid;
  2635. ctxt.info = vsi->info;
  2636. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2637. if (ret) {
  2638. dev_info(&vsi->back->pdev->dev,
  2639. "add pvid failed, err %s aq_err %s\n",
  2640. i40e_stat_str(&vsi->back->hw, ret),
  2641. i40e_aq_str(&vsi->back->hw,
  2642. vsi->back->hw.aq.asq_last_status));
  2643. return -ENOENT;
  2644. }
  2645. return 0;
  2646. }
  2647. /**
  2648. * i40e_vsi_remove_pvid - Remove the pvid from the VSI
  2649. * @vsi: the vsi being adjusted
  2650. *
  2651. * Just use the vlan_rx_register() service to put it back to normal
  2652. **/
  2653. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
  2654. {
  2655. i40e_vlan_stripping_disable(vsi);
  2656. vsi->info.pvid = 0;
  2657. }
  2658. /**
  2659. * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
  2660. * @vsi: ptr to the VSI
  2661. *
  2662. * If this function returns with an error, then it's possible one or
  2663. * more of the rings is populated (while the rest are not). It is the
  2664. * callers duty to clean those orphaned rings.
  2665. *
  2666. * Return 0 on success, negative on failure
  2667. **/
  2668. static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
  2669. {
  2670. int i, err = 0;
  2671. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2672. err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
  2673. if (!i40e_enabled_xdp_vsi(vsi))
  2674. return err;
  2675. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2676. err = i40e_setup_tx_descriptors(vsi->xdp_rings[i]);
  2677. return err;
  2678. }
  2679. /**
  2680. * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
  2681. * @vsi: ptr to the VSI
  2682. *
  2683. * Free VSI's transmit software resources
  2684. **/
  2685. static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
  2686. {
  2687. int i;
  2688. if (vsi->tx_rings) {
  2689. for (i = 0; i < vsi->num_queue_pairs; i++)
  2690. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
  2691. i40e_free_tx_resources(vsi->tx_rings[i]);
  2692. }
  2693. if (vsi->xdp_rings) {
  2694. for (i = 0; i < vsi->num_queue_pairs; i++)
  2695. if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
  2696. i40e_free_tx_resources(vsi->xdp_rings[i]);
  2697. }
  2698. }
  2699. /**
  2700. * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
  2701. * @vsi: ptr to the VSI
  2702. *
  2703. * If this function returns with an error, then it's possible one or
  2704. * more of the rings is populated (while the rest are not). It is the
  2705. * callers duty to clean those orphaned rings.
  2706. *
  2707. * Return 0 on success, negative on failure
  2708. **/
  2709. static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
  2710. {
  2711. int i, err = 0;
  2712. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2713. err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
  2714. return err;
  2715. }
  2716. /**
  2717. * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
  2718. * @vsi: ptr to the VSI
  2719. *
  2720. * Free all receive software resources
  2721. **/
  2722. static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
  2723. {
  2724. int i;
  2725. if (!vsi->rx_rings)
  2726. return;
  2727. for (i = 0; i < vsi->num_queue_pairs; i++)
  2728. if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
  2729. i40e_free_rx_resources(vsi->rx_rings[i]);
  2730. }
  2731. /**
  2732. * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
  2733. * @ring: The Tx ring to configure
  2734. *
  2735. * This enables/disables XPS for a given Tx descriptor ring
  2736. * based on the TCs enabled for the VSI that ring belongs to.
  2737. **/
  2738. static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
  2739. {
  2740. int cpu;
  2741. if (!ring->q_vector || !ring->netdev || ring->ch)
  2742. return;
  2743. /* We only initialize XPS once, so as not to overwrite user settings */
  2744. if (test_and_set_bit(__I40E_TX_XPS_INIT_DONE, ring->state))
  2745. return;
  2746. cpu = cpumask_local_spread(ring->q_vector->v_idx, -1);
  2747. netif_set_xps_queue(ring->netdev, get_cpu_mask(cpu),
  2748. ring->queue_index);
  2749. }
  2750. /**
  2751. * i40e_configure_tx_ring - Configure a transmit ring context and rest
  2752. * @ring: The Tx ring to configure
  2753. *
  2754. * Configure the Tx descriptor ring in the HMC context.
  2755. **/
  2756. static int i40e_configure_tx_ring(struct i40e_ring *ring)
  2757. {
  2758. struct i40e_vsi *vsi = ring->vsi;
  2759. u16 pf_q = vsi->base_queue + ring->queue_index;
  2760. struct i40e_hw *hw = &vsi->back->hw;
  2761. struct i40e_hmc_obj_txq tx_ctx;
  2762. i40e_status err = 0;
  2763. u32 qtx_ctl = 0;
  2764. /* some ATR related tx ring init */
  2765. if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
  2766. ring->atr_sample_rate = vsi->back->atr_sample_rate;
  2767. ring->atr_count = 0;
  2768. } else {
  2769. ring->atr_sample_rate = 0;
  2770. }
  2771. /* configure XPS */
  2772. i40e_config_xps_tx_ring(ring);
  2773. /* clear the context structure first */
  2774. memset(&tx_ctx, 0, sizeof(tx_ctx));
  2775. tx_ctx.new_context = 1;
  2776. tx_ctx.base = (ring->dma / 128);
  2777. tx_ctx.qlen = ring->count;
  2778. tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
  2779. I40E_FLAG_FD_ATR_ENABLED));
  2780. tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
  2781. /* FDIR VSI tx ring can still use RS bit and writebacks */
  2782. if (vsi->type != I40E_VSI_FDIR)
  2783. tx_ctx.head_wb_ena = 1;
  2784. tx_ctx.head_wb_addr = ring->dma +
  2785. (ring->count * sizeof(struct i40e_tx_desc));
  2786. /* As part of VSI creation/update, FW allocates certain
  2787. * Tx arbitration queue sets for each TC enabled for
  2788. * the VSI. The FW returns the handles to these queue
  2789. * sets as part of the response buffer to Add VSI,
  2790. * Update VSI, etc. AQ commands. It is expected that
  2791. * these queue set handles be associated with the Tx
  2792. * queues by the driver as part of the TX queue context
  2793. * initialization. This has to be done regardless of
  2794. * DCB as by default everything is mapped to TC0.
  2795. */
  2796. if (ring->ch)
  2797. tx_ctx.rdylist =
  2798. le16_to_cpu(ring->ch->info.qs_handle[ring->dcb_tc]);
  2799. else
  2800. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
  2801. tx_ctx.rdylist_act = 0;
  2802. /* clear the context in the HMC */
  2803. err = i40e_clear_lan_tx_queue_context(hw, pf_q);
  2804. if (err) {
  2805. dev_info(&vsi->back->pdev->dev,
  2806. "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
  2807. ring->queue_index, pf_q, err);
  2808. return -ENOMEM;
  2809. }
  2810. /* set the context in the HMC */
  2811. err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
  2812. if (err) {
  2813. dev_info(&vsi->back->pdev->dev,
  2814. "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
  2815. ring->queue_index, pf_q, err);
  2816. return -ENOMEM;
  2817. }
  2818. /* Now associate this queue with this PCI function */
  2819. if (ring->ch) {
  2820. if (ring->ch->type == I40E_VSI_VMDQ2)
  2821. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2822. else
  2823. return -EINVAL;
  2824. qtx_ctl |= (ring->ch->vsi_number <<
  2825. I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2826. I40E_QTX_CTL_VFVM_INDX_MASK;
  2827. } else {
  2828. if (vsi->type == I40E_VSI_VMDQ2) {
  2829. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2830. qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2831. I40E_QTX_CTL_VFVM_INDX_MASK;
  2832. } else {
  2833. qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
  2834. }
  2835. }
  2836. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
  2837. I40E_QTX_CTL_PF_INDX_MASK);
  2838. wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
  2839. i40e_flush(hw);
  2840. /* cache tail off for easier writes later */
  2841. ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
  2842. return 0;
  2843. }
  2844. /**
  2845. * i40e_configure_rx_ring - Configure a receive ring context
  2846. * @ring: The Rx ring to configure
  2847. *
  2848. * Configure the Rx descriptor ring in the HMC context.
  2849. **/
  2850. static int i40e_configure_rx_ring(struct i40e_ring *ring)
  2851. {
  2852. struct i40e_vsi *vsi = ring->vsi;
  2853. u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
  2854. u16 pf_q = vsi->base_queue + ring->queue_index;
  2855. struct i40e_hw *hw = &vsi->back->hw;
  2856. struct i40e_hmc_obj_rxq rx_ctx;
  2857. i40e_status err = 0;
  2858. bitmap_zero(ring->state, __I40E_RING_STATE_NBITS);
  2859. /* clear the context structure first */
  2860. memset(&rx_ctx, 0, sizeof(rx_ctx));
  2861. ring->rx_buf_len = vsi->rx_buf_len;
  2862. rx_ctx.dbuff = DIV_ROUND_UP(ring->rx_buf_len,
  2863. BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
  2864. rx_ctx.base = (ring->dma / 128);
  2865. rx_ctx.qlen = ring->count;
  2866. /* use 32 byte descriptors */
  2867. rx_ctx.dsize = 1;
  2868. /* descriptor type is always zero
  2869. * rx_ctx.dtype = 0;
  2870. */
  2871. rx_ctx.hsplit_0 = 0;
  2872. rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
  2873. if (hw->revision_id == 0)
  2874. rx_ctx.lrxqthresh = 0;
  2875. else
  2876. rx_ctx.lrxqthresh = 1;
  2877. rx_ctx.crcstrip = 1;
  2878. rx_ctx.l2tsel = 1;
  2879. /* this controls whether VLAN is stripped from inner headers */
  2880. rx_ctx.showiv = 0;
  2881. /* set the prefena field to 1 because the manual says to */
  2882. rx_ctx.prefena = 1;
  2883. /* clear the context in the HMC */
  2884. err = i40e_clear_lan_rx_queue_context(hw, pf_q);
  2885. if (err) {
  2886. dev_info(&vsi->back->pdev->dev,
  2887. "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2888. ring->queue_index, pf_q, err);
  2889. return -ENOMEM;
  2890. }
  2891. /* set the context in the HMC */
  2892. err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
  2893. if (err) {
  2894. dev_info(&vsi->back->pdev->dev,
  2895. "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2896. ring->queue_index, pf_q, err);
  2897. return -ENOMEM;
  2898. }
  2899. /* configure Rx buffer alignment */
  2900. if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
  2901. clear_ring_build_skb_enabled(ring);
  2902. else
  2903. set_ring_build_skb_enabled(ring);
  2904. /* cache tail for quicker writes, and clear the reg before use */
  2905. ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
  2906. writel(0, ring->tail);
  2907. i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
  2908. return 0;
  2909. }
  2910. /**
  2911. * i40e_vsi_configure_tx - Configure the VSI for Tx
  2912. * @vsi: VSI structure describing this set of rings and resources
  2913. *
  2914. * Configure the Tx VSI for operation.
  2915. **/
  2916. static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
  2917. {
  2918. int err = 0;
  2919. u16 i;
  2920. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2921. err = i40e_configure_tx_ring(vsi->tx_rings[i]);
  2922. if (!i40e_enabled_xdp_vsi(vsi))
  2923. return err;
  2924. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2925. err = i40e_configure_tx_ring(vsi->xdp_rings[i]);
  2926. return err;
  2927. }
  2928. /**
  2929. * i40e_vsi_configure_rx - Configure the VSI for Rx
  2930. * @vsi: the VSI being configured
  2931. *
  2932. * Configure the Rx VSI for operation.
  2933. **/
  2934. static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
  2935. {
  2936. int err = 0;
  2937. u16 i;
  2938. if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) {
  2939. vsi->max_frame = I40E_MAX_RXBUFFER;
  2940. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2941. #if (PAGE_SIZE < 8192)
  2942. } else if (!I40E_2K_TOO_SMALL_WITH_PADDING &&
  2943. (vsi->netdev->mtu <= ETH_DATA_LEN)) {
  2944. vsi->max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
  2945. vsi->rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
  2946. #endif
  2947. } else {
  2948. vsi->max_frame = I40E_MAX_RXBUFFER;
  2949. vsi->rx_buf_len = (PAGE_SIZE < 8192) ? I40E_RXBUFFER_3072 :
  2950. I40E_RXBUFFER_2048;
  2951. }
  2952. /* set up individual rings */
  2953. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2954. err = i40e_configure_rx_ring(vsi->rx_rings[i]);
  2955. return err;
  2956. }
  2957. /**
  2958. * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
  2959. * @vsi: ptr to the VSI
  2960. **/
  2961. static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
  2962. {
  2963. struct i40e_ring *tx_ring, *rx_ring;
  2964. u16 qoffset, qcount;
  2965. int i, n;
  2966. if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  2967. /* Reset the TC information */
  2968. for (i = 0; i < vsi->num_queue_pairs; i++) {
  2969. rx_ring = vsi->rx_rings[i];
  2970. tx_ring = vsi->tx_rings[i];
  2971. rx_ring->dcb_tc = 0;
  2972. tx_ring->dcb_tc = 0;
  2973. }
  2974. return;
  2975. }
  2976. for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
  2977. if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
  2978. continue;
  2979. qoffset = vsi->tc_config.tc_info[n].qoffset;
  2980. qcount = vsi->tc_config.tc_info[n].qcount;
  2981. for (i = qoffset; i < (qoffset + qcount); i++) {
  2982. rx_ring = vsi->rx_rings[i];
  2983. tx_ring = vsi->tx_rings[i];
  2984. rx_ring->dcb_tc = n;
  2985. tx_ring->dcb_tc = n;
  2986. }
  2987. }
  2988. }
  2989. /**
  2990. * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
  2991. * @vsi: ptr to the VSI
  2992. **/
  2993. static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
  2994. {
  2995. if (vsi->netdev)
  2996. i40e_set_rx_mode(vsi->netdev);
  2997. }
  2998. /**
  2999. * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
  3000. * @vsi: Pointer to the targeted VSI
  3001. *
  3002. * This function replays the hlist on the hw where all the SB Flow Director
  3003. * filters were saved.
  3004. **/
  3005. static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
  3006. {
  3007. struct i40e_fdir_filter *filter;
  3008. struct i40e_pf *pf = vsi->back;
  3009. struct hlist_node *node;
  3010. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  3011. return;
  3012. /* Reset FDir counters as we're replaying all existing filters */
  3013. pf->fd_tcp4_filter_cnt = 0;
  3014. pf->fd_udp4_filter_cnt = 0;
  3015. pf->fd_sctp4_filter_cnt = 0;
  3016. pf->fd_ip4_filter_cnt = 0;
  3017. hlist_for_each_entry_safe(filter, node,
  3018. &pf->fdir_filter_list, fdir_node) {
  3019. i40e_add_del_fdir(vsi, filter, true);
  3020. }
  3021. }
  3022. /**
  3023. * i40e_vsi_configure - Set up the VSI for action
  3024. * @vsi: the VSI being configured
  3025. **/
  3026. static int i40e_vsi_configure(struct i40e_vsi *vsi)
  3027. {
  3028. int err;
  3029. i40e_set_vsi_rx_mode(vsi);
  3030. i40e_restore_vlan(vsi);
  3031. i40e_vsi_config_dcb_rings(vsi);
  3032. err = i40e_vsi_configure_tx(vsi);
  3033. if (!err)
  3034. err = i40e_vsi_configure_rx(vsi);
  3035. return err;
  3036. }
  3037. /**
  3038. * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
  3039. * @vsi: the VSI being configured
  3040. **/
  3041. static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
  3042. {
  3043. bool has_xdp = i40e_enabled_xdp_vsi(vsi);
  3044. struct i40e_pf *pf = vsi->back;
  3045. struct i40e_hw *hw = &pf->hw;
  3046. u16 vector;
  3047. int i, q;
  3048. u32 qp;
  3049. /* The interrupt indexing is offset by 1 in the PFINT_ITRn
  3050. * and PFINT_LNKLSTn registers, e.g.:
  3051. * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
  3052. */
  3053. qp = vsi->base_queue;
  3054. vector = vsi->base_vector;
  3055. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  3056. struct i40e_q_vector *q_vector = vsi->q_vectors[i];
  3057. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  3058. q_vector->rx.target_itr =
  3059. ITR_TO_REG(vsi->rx_rings[i]->itr_setting);
  3060. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  3061. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
  3062. q_vector->rx.target_itr);
  3063. q_vector->rx.current_itr = q_vector->rx.target_itr;
  3064. q_vector->tx.target_itr =
  3065. ITR_TO_REG(vsi->tx_rings[i]->itr_setting);
  3066. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  3067. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
  3068. q_vector->tx.target_itr);
  3069. q_vector->tx.current_itr = q_vector->tx.target_itr;
  3070. wr32(hw, I40E_PFINT_RATEN(vector - 1),
  3071. i40e_intrl_usec_to_reg(vsi->int_rate_limit));
  3072. /* Linked list for the queuepairs assigned to this vector */
  3073. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
  3074. for (q = 0; q < q_vector->num_ringpairs; q++) {
  3075. u32 nextqp = has_xdp ? qp + vsi->alloc_queue_pairs : qp;
  3076. u32 val;
  3077. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3078. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  3079. (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
  3080. (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
  3081. (I40E_QUEUE_TYPE_TX <<
  3082. I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
  3083. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3084. if (has_xdp) {
  3085. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3086. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3087. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  3088. (qp << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
  3089. (I40E_QUEUE_TYPE_TX <<
  3090. I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3091. wr32(hw, I40E_QINT_TQCTL(nextqp), val);
  3092. }
  3093. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3094. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3095. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  3096. ((qp + 1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
  3097. (I40E_QUEUE_TYPE_RX <<
  3098. I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3099. /* Terminate the linked list */
  3100. if (q == (q_vector->num_ringpairs - 1))
  3101. val |= (I40E_QUEUE_END_OF_LIST <<
  3102. I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  3103. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3104. qp++;
  3105. }
  3106. }
  3107. i40e_flush(hw);
  3108. }
  3109. /**
  3110. * i40e_enable_misc_int_causes - enable the non-queue interrupts
  3111. * @hw: ptr to the hardware info
  3112. **/
  3113. static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
  3114. {
  3115. struct i40e_hw *hw = &pf->hw;
  3116. u32 val;
  3117. /* clear things first */
  3118. wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
  3119. rd32(hw, I40E_PFINT_ICR0); /* read to clear */
  3120. val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
  3121. I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
  3122. I40E_PFINT_ICR0_ENA_GRST_MASK |
  3123. I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
  3124. I40E_PFINT_ICR0_ENA_GPIO_MASK |
  3125. I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
  3126. I40E_PFINT_ICR0_ENA_VFLR_MASK |
  3127. I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3128. if (pf->flags & I40E_FLAG_IWARP_ENABLED)
  3129. val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3130. if (pf->flags & I40E_FLAG_PTP)
  3131. val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3132. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  3133. /* SW_ITR_IDX = 0, but don't change INTENA */
  3134. wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
  3135. I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
  3136. /* OTHER_ITR_IDX = 0 */
  3137. wr32(hw, I40E_PFINT_STAT_CTL0, 0);
  3138. }
  3139. /**
  3140. * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
  3141. * @vsi: the VSI being configured
  3142. **/
  3143. static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
  3144. {
  3145. u32 nextqp = i40e_enabled_xdp_vsi(vsi) ? vsi->alloc_queue_pairs : 0;
  3146. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3147. struct i40e_pf *pf = vsi->back;
  3148. struct i40e_hw *hw = &pf->hw;
  3149. u32 val;
  3150. /* set the ITR configuration */
  3151. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  3152. q_vector->rx.target_itr = ITR_TO_REG(vsi->rx_rings[0]->itr_setting);
  3153. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  3154. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.target_itr);
  3155. q_vector->rx.current_itr = q_vector->rx.target_itr;
  3156. q_vector->tx.target_itr = ITR_TO_REG(vsi->tx_rings[0]->itr_setting);
  3157. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  3158. wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.target_itr);
  3159. q_vector->tx.current_itr = q_vector->tx.target_itr;
  3160. i40e_enable_misc_int_causes(pf);
  3161. /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
  3162. wr32(hw, I40E_PFINT_LNKLST0, 0);
  3163. /* Associate the queue pair to the vector and enable the queue int */
  3164. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3165. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  3166. (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
  3167. (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3168. wr32(hw, I40E_QINT_RQCTL(0), val);
  3169. if (i40e_enabled_xdp_vsi(vsi)) {
  3170. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3171. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT)|
  3172. (I40E_QUEUE_TYPE_TX
  3173. << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3174. wr32(hw, I40E_QINT_TQCTL(nextqp), val);
  3175. }
  3176. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3177. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3178. (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  3179. wr32(hw, I40E_QINT_TQCTL(0), val);
  3180. i40e_flush(hw);
  3181. }
  3182. /**
  3183. * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
  3184. * @pf: board private structure
  3185. **/
  3186. void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
  3187. {
  3188. struct i40e_hw *hw = &pf->hw;
  3189. wr32(hw, I40E_PFINT_DYN_CTL0,
  3190. I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  3191. i40e_flush(hw);
  3192. }
  3193. /**
  3194. * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
  3195. * @pf: board private structure
  3196. **/
  3197. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
  3198. {
  3199. struct i40e_hw *hw = &pf->hw;
  3200. u32 val;
  3201. val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
  3202. I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
  3203. (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
  3204. wr32(hw, I40E_PFINT_DYN_CTL0, val);
  3205. i40e_flush(hw);
  3206. }
  3207. /**
  3208. * i40e_msix_clean_rings - MSIX mode Interrupt Handler
  3209. * @irq: interrupt number
  3210. * @data: pointer to a q_vector
  3211. **/
  3212. static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
  3213. {
  3214. struct i40e_q_vector *q_vector = data;
  3215. if (!q_vector->tx.ring && !q_vector->rx.ring)
  3216. return IRQ_HANDLED;
  3217. napi_schedule_irqoff(&q_vector->napi);
  3218. return IRQ_HANDLED;
  3219. }
  3220. /**
  3221. * i40e_irq_affinity_notify - Callback for affinity changes
  3222. * @notify: context as to what irq was changed
  3223. * @mask: the new affinity mask
  3224. *
  3225. * This is a callback function used by the irq_set_affinity_notifier function
  3226. * so that we may register to receive changes to the irq affinity masks.
  3227. **/
  3228. static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify,
  3229. const cpumask_t *mask)
  3230. {
  3231. struct i40e_q_vector *q_vector =
  3232. container_of(notify, struct i40e_q_vector, affinity_notify);
  3233. cpumask_copy(&q_vector->affinity_mask, mask);
  3234. }
  3235. /**
  3236. * i40e_irq_affinity_release - Callback for affinity notifier release
  3237. * @ref: internal core kernel usage
  3238. *
  3239. * This is a callback function used by the irq_set_affinity_notifier function
  3240. * to inform the current notification subscriber that they will no longer
  3241. * receive notifications.
  3242. **/
  3243. static void i40e_irq_affinity_release(struct kref *ref) {}
  3244. /**
  3245. * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
  3246. * @vsi: the VSI being configured
  3247. * @basename: name for the vector
  3248. *
  3249. * Allocates MSI-X vectors and requests interrupts from the kernel.
  3250. **/
  3251. static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
  3252. {
  3253. int q_vectors = vsi->num_q_vectors;
  3254. struct i40e_pf *pf = vsi->back;
  3255. int base = vsi->base_vector;
  3256. int rx_int_idx = 0;
  3257. int tx_int_idx = 0;
  3258. int vector, err;
  3259. int irq_num;
  3260. int cpu;
  3261. for (vector = 0; vector < q_vectors; vector++) {
  3262. struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
  3263. irq_num = pf->msix_entries[base + vector].vector;
  3264. if (q_vector->tx.ring && q_vector->rx.ring) {
  3265. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3266. "%s-%s-%d", basename, "TxRx", rx_int_idx++);
  3267. tx_int_idx++;
  3268. } else if (q_vector->rx.ring) {
  3269. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3270. "%s-%s-%d", basename, "rx", rx_int_idx++);
  3271. } else if (q_vector->tx.ring) {
  3272. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3273. "%s-%s-%d", basename, "tx", tx_int_idx++);
  3274. } else {
  3275. /* skip this unused q_vector */
  3276. continue;
  3277. }
  3278. err = request_irq(irq_num,
  3279. vsi->irq_handler,
  3280. 0,
  3281. q_vector->name,
  3282. q_vector);
  3283. if (err) {
  3284. dev_info(&pf->pdev->dev,
  3285. "MSIX request_irq failed, error: %d\n", err);
  3286. goto free_queue_irqs;
  3287. }
  3288. /* register for affinity change notifications */
  3289. q_vector->affinity_notify.notify = i40e_irq_affinity_notify;
  3290. q_vector->affinity_notify.release = i40e_irq_affinity_release;
  3291. irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
  3292. /* Spread affinity hints out across online CPUs.
  3293. *
  3294. * get_cpu_mask returns a static constant mask with
  3295. * a permanent lifetime so it's ok to pass to
  3296. * irq_set_affinity_hint without making a copy.
  3297. */
  3298. cpu = cpumask_local_spread(q_vector->v_idx, -1);
  3299. irq_set_affinity_hint(irq_num, get_cpu_mask(cpu));
  3300. }
  3301. vsi->irqs_ready = true;
  3302. return 0;
  3303. free_queue_irqs:
  3304. while (vector) {
  3305. vector--;
  3306. irq_num = pf->msix_entries[base + vector].vector;
  3307. irq_set_affinity_notifier(irq_num, NULL);
  3308. irq_set_affinity_hint(irq_num, NULL);
  3309. free_irq(irq_num, &vsi->q_vectors[vector]);
  3310. }
  3311. return err;
  3312. }
  3313. /**
  3314. * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
  3315. * @vsi: the VSI being un-configured
  3316. **/
  3317. static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
  3318. {
  3319. struct i40e_pf *pf = vsi->back;
  3320. struct i40e_hw *hw = &pf->hw;
  3321. int base = vsi->base_vector;
  3322. int i;
  3323. /* disable interrupt causation from each queue */
  3324. for (i = 0; i < vsi->num_queue_pairs; i++) {
  3325. u32 val;
  3326. val = rd32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx));
  3327. val &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
  3328. wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), val);
  3329. val = rd32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx));
  3330. val &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
  3331. wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), val);
  3332. if (!i40e_enabled_xdp_vsi(vsi))
  3333. continue;
  3334. wr32(hw, I40E_QINT_TQCTL(vsi->xdp_rings[i]->reg_idx), 0);
  3335. }
  3336. /* disable each interrupt */
  3337. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3338. for (i = vsi->base_vector;
  3339. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  3340. wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
  3341. i40e_flush(hw);
  3342. for (i = 0; i < vsi->num_q_vectors; i++)
  3343. synchronize_irq(pf->msix_entries[i + base].vector);
  3344. } else {
  3345. /* Legacy and MSI mode - this stops all interrupt handling */
  3346. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  3347. wr32(hw, I40E_PFINT_DYN_CTL0, 0);
  3348. i40e_flush(hw);
  3349. synchronize_irq(pf->pdev->irq);
  3350. }
  3351. }
  3352. /**
  3353. * i40e_vsi_enable_irq - Enable IRQ for the given VSI
  3354. * @vsi: the VSI being configured
  3355. **/
  3356. static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
  3357. {
  3358. struct i40e_pf *pf = vsi->back;
  3359. int i;
  3360. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3361. for (i = 0; i < vsi->num_q_vectors; i++)
  3362. i40e_irq_dynamic_enable(vsi, i);
  3363. } else {
  3364. i40e_irq_dynamic_enable_icr0(pf);
  3365. }
  3366. i40e_flush(&pf->hw);
  3367. return 0;
  3368. }
  3369. /**
  3370. * i40e_free_misc_vector - Free the vector that handles non-queue events
  3371. * @pf: board private structure
  3372. **/
  3373. static void i40e_free_misc_vector(struct i40e_pf *pf)
  3374. {
  3375. /* Disable ICR 0 */
  3376. wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
  3377. i40e_flush(&pf->hw);
  3378. if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
  3379. synchronize_irq(pf->msix_entries[0].vector);
  3380. free_irq(pf->msix_entries[0].vector, pf);
  3381. clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state);
  3382. }
  3383. }
  3384. /**
  3385. * i40e_intr - MSI/Legacy and non-queue interrupt handler
  3386. * @irq: interrupt number
  3387. * @data: pointer to a q_vector
  3388. *
  3389. * This is the handler used for all MSI/Legacy interrupts, and deals
  3390. * with both queue and non-queue interrupts. This is also used in
  3391. * MSIX mode to handle the non-queue interrupts.
  3392. **/
  3393. static irqreturn_t i40e_intr(int irq, void *data)
  3394. {
  3395. struct i40e_pf *pf = (struct i40e_pf *)data;
  3396. struct i40e_hw *hw = &pf->hw;
  3397. irqreturn_t ret = IRQ_NONE;
  3398. u32 icr0, icr0_remaining;
  3399. u32 val, ena_mask;
  3400. icr0 = rd32(hw, I40E_PFINT_ICR0);
  3401. ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
  3402. /* if sharing a legacy IRQ, we might get called w/o an intr pending */
  3403. if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
  3404. goto enable_intr;
  3405. /* if interrupt but no bits showing, must be SWINT */
  3406. if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
  3407. (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
  3408. pf->sw_int_count++;
  3409. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  3410. (icr0 & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
  3411. ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3412. dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n");
  3413. set_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
  3414. }
  3415. /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
  3416. if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
  3417. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  3418. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3419. /* We do not have a way to disarm Queue causes while leaving
  3420. * interrupt enabled for all other causes, ideally
  3421. * interrupt should be disabled while we are in NAPI but
  3422. * this is not a performance path and napi_schedule()
  3423. * can deal with rescheduling.
  3424. */
  3425. if (!test_bit(__I40E_DOWN, pf->state))
  3426. napi_schedule_irqoff(&q_vector->napi);
  3427. }
  3428. if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
  3429. ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3430. set_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
  3431. i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
  3432. }
  3433. if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
  3434. ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  3435. set_bit(__I40E_MDD_EVENT_PENDING, pf->state);
  3436. }
  3437. if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
  3438. ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
  3439. set_bit(__I40E_VFLR_EVENT_PENDING, pf->state);
  3440. }
  3441. if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
  3442. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  3443. set_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
  3444. ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
  3445. val = rd32(hw, I40E_GLGEN_RSTAT);
  3446. val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
  3447. >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
  3448. if (val == I40E_RESET_CORER) {
  3449. pf->corer_count++;
  3450. } else if (val == I40E_RESET_GLOBR) {
  3451. pf->globr_count++;
  3452. } else if (val == I40E_RESET_EMPR) {
  3453. pf->empr_count++;
  3454. set_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state);
  3455. }
  3456. }
  3457. if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
  3458. icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
  3459. dev_info(&pf->pdev->dev, "HMC error interrupt\n");
  3460. dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
  3461. rd32(hw, I40E_PFHMC_ERRORINFO),
  3462. rd32(hw, I40E_PFHMC_ERRORDATA));
  3463. }
  3464. if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
  3465. u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
  3466. if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
  3467. icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3468. i40e_ptp_tx_hwtstamp(pf);
  3469. }
  3470. }
  3471. /* If a critical error is pending we have no choice but to reset the
  3472. * device.
  3473. * Report and mask out any remaining unexpected interrupts.
  3474. */
  3475. icr0_remaining = icr0 & ena_mask;
  3476. if (icr0_remaining) {
  3477. dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
  3478. icr0_remaining);
  3479. if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
  3480. (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
  3481. (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
  3482. dev_info(&pf->pdev->dev, "device will be reset\n");
  3483. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  3484. i40e_service_event_schedule(pf);
  3485. }
  3486. ena_mask &= ~icr0_remaining;
  3487. }
  3488. ret = IRQ_HANDLED;
  3489. enable_intr:
  3490. /* re-enable interrupt causes */
  3491. wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
  3492. if (!test_bit(__I40E_DOWN, pf->state)) {
  3493. i40e_service_event_schedule(pf);
  3494. i40e_irq_dynamic_enable_icr0(pf);
  3495. }
  3496. return ret;
  3497. }
  3498. /**
  3499. * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
  3500. * @tx_ring: tx ring to clean
  3501. * @budget: how many cleans we're allowed
  3502. *
  3503. * Returns true if there's any budget left (e.g. the clean is finished)
  3504. **/
  3505. static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
  3506. {
  3507. struct i40e_vsi *vsi = tx_ring->vsi;
  3508. u16 i = tx_ring->next_to_clean;
  3509. struct i40e_tx_buffer *tx_buf;
  3510. struct i40e_tx_desc *tx_desc;
  3511. tx_buf = &tx_ring->tx_bi[i];
  3512. tx_desc = I40E_TX_DESC(tx_ring, i);
  3513. i -= tx_ring->count;
  3514. do {
  3515. struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
  3516. /* if next_to_watch is not set then there is no work pending */
  3517. if (!eop_desc)
  3518. break;
  3519. /* prevent any other reads prior to eop_desc */
  3520. smp_rmb();
  3521. /* if the descriptor isn't done, no work yet to do */
  3522. if (!(eop_desc->cmd_type_offset_bsz &
  3523. cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
  3524. break;
  3525. /* clear next_to_watch to prevent false hangs */
  3526. tx_buf->next_to_watch = NULL;
  3527. tx_desc->buffer_addr = 0;
  3528. tx_desc->cmd_type_offset_bsz = 0;
  3529. /* move past filter desc */
  3530. tx_buf++;
  3531. tx_desc++;
  3532. i++;
  3533. if (unlikely(!i)) {
  3534. i -= tx_ring->count;
  3535. tx_buf = tx_ring->tx_bi;
  3536. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3537. }
  3538. /* unmap skb header data */
  3539. dma_unmap_single(tx_ring->dev,
  3540. dma_unmap_addr(tx_buf, dma),
  3541. dma_unmap_len(tx_buf, len),
  3542. DMA_TO_DEVICE);
  3543. if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
  3544. kfree(tx_buf->raw_buf);
  3545. tx_buf->raw_buf = NULL;
  3546. tx_buf->tx_flags = 0;
  3547. tx_buf->next_to_watch = NULL;
  3548. dma_unmap_len_set(tx_buf, len, 0);
  3549. tx_desc->buffer_addr = 0;
  3550. tx_desc->cmd_type_offset_bsz = 0;
  3551. /* move us past the eop_desc for start of next FD desc */
  3552. tx_buf++;
  3553. tx_desc++;
  3554. i++;
  3555. if (unlikely(!i)) {
  3556. i -= tx_ring->count;
  3557. tx_buf = tx_ring->tx_bi;
  3558. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3559. }
  3560. /* update budget accounting */
  3561. budget--;
  3562. } while (likely(budget));
  3563. i += tx_ring->count;
  3564. tx_ring->next_to_clean = i;
  3565. if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
  3566. i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
  3567. return budget > 0;
  3568. }
  3569. /**
  3570. * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
  3571. * @irq: interrupt number
  3572. * @data: pointer to a q_vector
  3573. **/
  3574. static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
  3575. {
  3576. struct i40e_q_vector *q_vector = data;
  3577. struct i40e_vsi *vsi;
  3578. if (!q_vector->tx.ring)
  3579. return IRQ_HANDLED;
  3580. vsi = q_vector->tx.ring->vsi;
  3581. i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
  3582. return IRQ_HANDLED;
  3583. }
  3584. /**
  3585. * i40e_map_vector_to_qp - Assigns the queue pair to the vector
  3586. * @vsi: the VSI being configured
  3587. * @v_idx: vector index
  3588. * @qp_idx: queue pair index
  3589. **/
  3590. static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
  3591. {
  3592. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3593. struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
  3594. struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
  3595. tx_ring->q_vector = q_vector;
  3596. tx_ring->next = q_vector->tx.ring;
  3597. q_vector->tx.ring = tx_ring;
  3598. q_vector->tx.count++;
  3599. /* Place XDP Tx ring in the same q_vector ring list as regular Tx */
  3600. if (i40e_enabled_xdp_vsi(vsi)) {
  3601. struct i40e_ring *xdp_ring = vsi->xdp_rings[qp_idx];
  3602. xdp_ring->q_vector = q_vector;
  3603. xdp_ring->next = q_vector->tx.ring;
  3604. q_vector->tx.ring = xdp_ring;
  3605. q_vector->tx.count++;
  3606. }
  3607. rx_ring->q_vector = q_vector;
  3608. rx_ring->next = q_vector->rx.ring;
  3609. q_vector->rx.ring = rx_ring;
  3610. q_vector->rx.count++;
  3611. }
  3612. /**
  3613. * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
  3614. * @vsi: the VSI being configured
  3615. *
  3616. * This function maps descriptor rings to the queue-specific vectors
  3617. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  3618. * one vector per queue pair, but on a constrained vector budget, we
  3619. * group the queue pairs as "efficiently" as possible.
  3620. **/
  3621. static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
  3622. {
  3623. int qp_remaining = vsi->num_queue_pairs;
  3624. int q_vectors = vsi->num_q_vectors;
  3625. int num_ringpairs;
  3626. int v_start = 0;
  3627. int qp_idx = 0;
  3628. /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
  3629. * group them so there are multiple queues per vector.
  3630. * It is also important to go through all the vectors available to be
  3631. * sure that if we don't use all the vectors, that the remaining vectors
  3632. * are cleared. This is especially important when decreasing the
  3633. * number of queues in use.
  3634. */
  3635. for (; v_start < q_vectors; v_start++) {
  3636. struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
  3637. num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
  3638. q_vector->num_ringpairs = num_ringpairs;
  3639. q_vector->reg_idx = q_vector->v_idx + vsi->base_vector - 1;
  3640. q_vector->rx.count = 0;
  3641. q_vector->tx.count = 0;
  3642. q_vector->rx.ring = NULL;
  3643. q_vector->tx.ring = NULL;
  3644. while (num_ringpairs--) {
  3645. i40e_map_vector_to_qp(vsi, v_start, qp_idx);
  3646. qp_idx++;
  3647. qp_remaining--;
  3648. }
  3649. }
  3650. }
  3651. /**
  3652. * i40e_vsi_request_irq - Request IRQ from the OS
  3653. * @vsi: the VSI being configured
  3654. * @basename: name for the vector
  3655. **/
  3656. static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
  3657. {
  3658. struct i40e_pf *pf = vsi->back;
  3659. int err;
  3660. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3661. err = i40e_vsi_request_irq_msix(vsi, basename);
  3662. else if (pf->flags & I40E_FLAG_MSI_ENABLED)
  3663. err = request_irq(pf->pdev->irq, i40e_intr, 0,
  3664. pf->int_name, pf);
  3665. else
  3666. err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
  3667. pf->int_name, pf);
  3668. if (err)
  3669. dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
  3670. return err;
  3671. }
  3672. #ifdef CONFIG_NET_POLL_CONTROLLER
  3673. /**
  3674. * i40e_netpoll - A Polling 'interrupt' handler
  3675. * @netdev: network interface device structure
  3676. *
  3677. * This is used by netconsole to send skbs without having to re-enable
  3678. * interrupts. It's not called while the normal interrupt routine is executing.
  3679. **/
  3680. static void i40e_netpoll(struct net_device *netdev)
  3681. {
  3682. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3683. struct i40e_vsi *vsi = np->vsi;
  3684. struct i40e_pf *pf = vsi->back;
  3685. int i;
  3686. /* if interface is down do nothing */
  3687. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  3688. return;
  3689. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3690. for (i = 0; i < vsi->num_q_vectors; i++)
  3691. i40e_msix_clean_rings(0, vsi->q_vectors[i]);
  3692. } else {
  3693. i40e_intr(pf->pdev->irq, netdev);
  3694. }
  3695. }
  3696. #endif
  3697. #define I40E_QTX_ENA_WAIT_COUNT 50
  3698. /**
  3699. * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
  3700. * @pf: the PF being configured
  3701. * @pf_q: the PF queue
  3702. * @enable: enable or disable state of the queue
  3703. *
  3704. * This routine will wait for the given Tx queue of the PF to reach the
  3705. * enabled or disabled state.
  3706. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3707. * multiple retries; else will return 0 in case of success.
  3708. **/
  3709. static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3710. {
  3711. int i;
  3712. u32 tx_reg;
  3713. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3714. tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
  3715. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3716. break;
  3717. usleep_range(10, 20);
  3718. }
  3719. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3720. return -ETIMEDOUT;
  3721. return 0;
  3722. }
  3723. /**
  3724. * i40e_control_tx_q - Start or stop a particular Tx queue
  3725. * @pf: the PF structure
  3726. * @pf_q: the PF queue to configure
  3727. * @enable: start or stop the queue
  3728. *
  3729. * This function enables or disables a single queue. Note that any delay
  3730. * required after the operation is expected to be handled by the caller of
  3731. * this function.
  3732. **/
  3733. static void i40e_control_tx_q(struct i40e_pf *pf, int pf_q, bool enable)
  3734. {
  3735. struct i40e_hw *hw = &pf->hw;
  3736. u32 tx_reg;
  3737. int i;
  3738. /* warn the TX unit of coming changes */
  3739. i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
  3740. if (!enable)
  3741. usleep_range(10, 20);
  3742. for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
  3743. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  3744. if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
  3745. ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
  3746. break;
  3747. usleep_range(1000, 2000);
  3748. }
  3749. /* Skip if the queue is already in the requested state */
  3750. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3751. return;
  3752. /* turn on/off the queue */
  3753. if (enable) {
  3754. wr32(hw, I40E_QTX_HEAD(pf_q), 0);
  3755. tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
  3756. } else {
  3757. tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
  3758. }
  3759. wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
  3760. }
  3761. /**
  3762. * i40e_control_wait_tx_q - Start/stop Tx queue and wait for completion
  3763. * @seid: VSI SEID
  3764. * @pf: the PF structure
  3765. * @pf_q: the PF queue to configure
  3766. * @is_xdp: true if the queue is used for XDP
  3767. * @enable: start or stop the queue
  3768. **/
  3769. static int i40e_control_wait_tx_q(int seid, struct i40e_pf *pf, int pf_q,
  3770. bool is_xdp, bool enable)
  3771. {
  3772. int ret;
  3773. i40e_control_tx_q(pf, pf_q, enable);
  3774. /* wait for the change to finish */
  3775. ret = i40e_pf_txq_wait(pf, pf_q, enable);
  3776. if (ret) {
  3777. dev_info(&pf->pdev->dev,
  3778. "VSI seid %d %sTx ring %d %sable timeout\n",
  3779. seid, (is_xdp ? "XDP " : ""), pf_q,
  3780. (enable ? "en" : "dis"));
  3781. }
  3782. return ret;
  3783. }
  3784. /**
  3785. * i40e_vsi_control_tx - Start or stop a VSI's rings
  3786. * @vsi: the VSI being configured
  3787. * @enable: start or stop the rings
  3788. **/
  3789. static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
  3790. {
  3791. struct i40e_pf *pf = vsi->back;
  3792. int i, pf_q, ret = 0;
  3793. pf_q = vsi->base_queue;
  3794. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3795. ret = i40e_control_wait_tx_q(vsi->seid, pf,
  3796. pf_q,
  3797. false /*is xdp*/, enable);
  3798. if (ret)
  3799. break;
  3800. if (!i40e_enabled_xdp_vsi(vsi))
  3801. continue;
  3802. ret = i40e_control_wait_tx_q(vsi->seid, pf,
  3803. pf_q + vsi->alloc_queue_pairs,
  3804. true /*is xdp*/, enable);
  3805. if (ret)
  3806. break;
  3807. }
  3808. return ret;
  3809. }
  3810. /**
  3811. * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
  3812. * @pf: the PF being configured
  3813. * @pf_q: the PF queue
  3814. * @enable: enable or disable state of the queue
  3815. *
  3816. * This routine will wait for the given Rx queue of the PF to reach the
  3817. * enabled or disabled state.
  3818. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3819. * multiple retries; else will return 0 in case of success.
  3820. **/
  3821. static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3822. {
  3823. int i;
  3824. u32 rx_reg;
  3825. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3826. rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
  3827. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3828. break;
  3829. usleep_range(10, 20);
  3830. }
  3831. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3832. return -ETIMEDOUT;
  3833. return 0;
  3834. }
  3835. /**
  3836. * i40e_control_rx_q - Start or stop a particular Rx queue
  3837. * @pf: the PF structure
  3838. * @pf_q: the PF queue to configure
  3839. * @enable: start or stop the queue
  3840. *
  3841. * This function enables or disables a single queue. Note that any delay
  3842. * required after the operation is expected to be handled by the caller of
  3843. * this function.
  3844. **/
  3845. static void i40e_control_rx_q(struct i40e_pf *pf, int pf_q, bool enable)
  3846. {
  3847. struct i40e_hw *hw = &pf->hw;
  3848. u32 rx_reg;
  3849. int i;
  3850. for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
  3851. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  3852. if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
  3853. ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
  3854. break;
  3855. usleep_range(1000, 2000);
  3856. }
  3857. /* Skip if the queue is already in the requested state */
  3858. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3859. return;
  3860. /* turn on/off the queue */
  3861. if (enable)
  3862. rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
  3863. else
  3864. rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
  3865. wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
  3866. }
  3867. /**
  3868. * i40e_vsi_control_rx - Start or stop a VSI's rings
  3869. * @vsi: the VSI being configured
  3870. * @enable: start or stop the rings
  3871. **/
  3872. static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
  3873. {
  3874. struct i40e_pf *pf = vsi->back;
  3875. int i, pf_q, ret = 0;
  3876. pf_q = vsi->base_queue;
  3877. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3878. i40e_control_rx_q(pf, pf_q, enable);
  3879. /* wait for the change to finish */
  3880. ret = i40e_pf_rxq_wait(pf, pf_q, enable);
  3881. if (ret) {
  3882. dev_info(&pf->pdev->dev,
  3883. "VSI seid %d Rx ring %d %sable timeout\n",
  3884. vsi->seid, pf_q, (enable ? "en" : "dis"));
  3885. break;
  3886. }
  3887. }
  3888. /* Due to HW errata, on Rx disable only, the register can indicate done
  3889. * before it really is. Needs 50ms to be sure
  3890. */
  3891. if (!enable)
  3892. mdelay(50);
  3893. return ret;
  3894. }
  3895. /**
  3896. * i40e_vsi_start_rings - Start a VSI's rings
  3897. * @vsi: the VSI being configured
  3898. **/
  3899. int i40e_vsi_start_rings(struct i40e_vsi *vsi)
  3900. {
  3901. int ret = 0;
  3902. /* do rx first for enable and last for disable */
  3903. ret = i40e_vsi_control_rx(vsi, true);
  3904. if (ret)
  3905. return ret;
  3906. ret = i40e_vsi_control_tx(vsi, true);
  3907. return ret;
  3908. }
  3909. /**
  3910. * i40e_vsi_stop_rings - Stop a VSI's rings
  3911. * @vsi: the VSI being configured
  3912. **/
  3913. void i40e_vsi_stop_rings(struct i40e_vsi *vsi)
  3914. {
  3915. /* When port TX is suspended, don't wait */
  3916. if (test_bit(__I40E_PORT_SUSPENDED, vsi->back->state))
  3917. return i40e_vsi_stop_rings_no_wait(vsi);
  3918. /* do rx first for enable and last for disable
  3919. * Ignore return value, we need to shutdown whatever we can
  3920. */
  3921. i40e_vsi_control_tx(vsi, false);
  3922. i40e_vsi_control_rx(vsi, false);
  3923. }
  3924. /**
  3925. * i40e_vsi_stop_rings_no_wait - Stop a VSI's rings and do not delay
  3926. * @vsi: the VSI being shutdown
  3927. *
  3928. * This function stops all the rings for a VSI but does not delay to verify
  3929. * that rings have been disabled. It is expected that the caller is shutting
  3930. * down multiple VSIs at once and will delay together for all the VSIs after
  3931. * initiating the shutdown. This is particularly useful for shutting down lots
  3932. * of VFs together. Otherwise, a large delay can be incurred while configuring
  3933. * each VSI in serial.
  3934. **/
  3935. void i40e_vsi_stop_rings_no_wait(struct i40e_vsi *vsi)
  3936. {
  3937. struct i40e_pf *pf = vsi->back;
  3938. int i, pf_q;
  3939. pf_q = vsi->base_queue;
  3940. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3941. i40e_control_tx_q(pf, pf_q, false);
  3942. i40e_control_rx_q(pf, pf_q, false);
  3943. }
  3944. }
  3945. /**
  3946. * i40e_vsi_free_irq - Free the irq association with the OS
  3947. * @vsi: the VSI being configured
  3948. **/
  3949. static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
  3950. {
  3951. struct i40e_pf *pf = vsi->back;
  3952. struct i40e_hw *hw = &pf->hw;
  3953. int base = vsi->base_vector;
  3954. u32 val, qp;
  3955. int i;
  3956. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3957. if (!vsi->q_vectors)
  3958. return;
  3959. if (!vsi->irqs_ready)
  3960. return;
  3961. vsi->irqs_ready = false;
  3962. for (i = 0; i < vsi->num_q_vectors; i++) {
  3963. int irq_num;
  3964. u16 vector;
  3965. vector = i + base;
  3966. irq_num = pf->msix_entries[vector].vector;
  3967. /* free only the irqs that were actually requested */
  3968. if (!vsi->q_vectors[i] ||
  3969. !vsi->q_vectors[i]->num_ringpairs)
  3970. continue;
  3971. /* clear the affinity notifier in the IRQ descriptor */
  3972. irq_set_affinity_notifier(irq_num, NULL);
  3973. /* remove our suggested affinity mask for this IRQ */
  3974. irq_set_affinity_hint(irq_num, NULL);
  3975. synchronize_irq(irq_num);
  3976. free_irq(irq_num, vsi->q_vectors[i]);
  3977. /* Tear down the interrupt queue link list
  3978. *
  3979. * We know that they come in pairs and always
  3980. * the Rx first, then the Tx. To clear the
  3981. * link list, stick the EOL value into the
  3982. * next_q field of the registers.
  3983. */
  3984. val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
  3985. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3986. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3987. val |= I40E_QUEUE_END_OF_LIST
  3988. << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3989. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
  3990. while (qp != I40E_QUEUE_END_OF_LIST) {
  3991. u32 next;
  3992. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3993. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3994. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3995. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3996. I40E_QINT_RQCTL_INTEVENT_MASK);
  3997. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3998. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3999. wr32(hw, I40E_QINT_RQCTL(qp), val);
  4000. val = rd32(hw, I40E_QINT_TQCTL(qp));
  4001. next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
  4002. >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
  4003. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  4004. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  4005. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  4006. I40E_QINT_TQCTL_INTEVENT_MASK);
  4007. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  4008. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  4009. wr32(hw, I40E_QINT_TQCTL(qp), val);
  4010. qp = next;
  4011. }
  4012. }
  4013. } else {
  4014. free_irq(pf->pdev->irq, pf);
  4015. val = rd32(hw, I40E_PFINT_LNKLST0);
  4016. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  4017. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  4018. val |= I40E_QUEUE_END_OF_LIST
  4019. << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  4020. wr32(hw, I40E_PFINT_LNKLST0, val);
  4021. val = rd32(hw, I40E_QINT_RQCTL(qp));
  4022. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  4023. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  4024. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  4025. I40E_QINT_RQCTL_INTEVENT_MASK);
  4026. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  4027. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  4028. wr32(hw, I40E_QINT_RQCTL(qp), val);
  4029. val = rd32(hw, I40E_QINT_TQCTL(qp));
  4030. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  4031. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  4032. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  4033. I40E_QINT_TQCTL_INTEVENT_MASK);
  4034. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  4035. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  4036. wr32(hw, I40E_QINT_TQCTL(qp), val);
  4037. }
  4038. }
  4039. /**
  4040. * i40e_free_q_vector - Free memory allocated for specific interrupt vector
  4041. * @vsi: the VSI being configured
  4042. * @v_idx: Index of vector to be freed
  4043. *
  4044. * This function frees the memory allocated to the q_vector. In addition if
  4045. * NAPI is enabled it will delete any references to the NAPI struct prior
  4046. * to freeing the q_vector.
  4047. **/
  4048. static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
  4049. {
  4050. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  4051. struct i40e_ring *ring;
  4052. if (!q_vector)
  4053. return;
  4054. /* disassociate q_vector from rings */
  4055. i40e_for_each_ring(ring, q_vector->tx)
  4056. ring->q_vector = NULL;
  4057. i40e_for_each_ring(ring, q_vector->rx)
  4058. ring->q_vector = NULL;
  4059. /* only VSI w/ an associated netdev is set up w/ NAPI */
  4060. if (vsi->netdev)
  4061. netif_napi_del(&q_vector->napi);
  4062. vsi->q_vectors[v_idx] = NULL;
  4063. kfree_rcu(q_vector, rcu);
  4064. }
  4065. /**
  4066. * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
  4067. * @vsi: the VSI being un-configured
  4068. *
  4069. * This frees the memory allocated to the q_vectors and
  4070. * deletes references to the NAPI struct.
  4071. **/
  4072. static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
  4073. {
  4074. int v_idx;
  4075. for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
  4076. i40e_free_q_vector(vsi, v_idx);
  4077. }
  4078. /**
  4079. * i40e_reset_interrupt_capability - Disable interrupt setup in OS
  4080. * @pf: board private structure
  4081. **/
  4082. static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
  4083. {
  4084. /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
  4085. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  4086. pci_disable_msix(pf->pdev);
  4087. kfree(pf->msix_entries);
  4088. pf->msix_entries = NULL;
  4089. kfree(pf->irq_pile);
  4090. pf->irq_pile = NULL;
  4091. } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
  4092. pci_disable_msi(pf->pdev);
  4093. }
  4094. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  4095. }
  4096. /**
  4097. * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
  4098. * @pf: board private structure
  4099. *
  4100. * We go through and clear interrupt specific resources and reset the structure
  4101. * to pre-load conditions
  4102. **/
  4103. static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
  4104. {
  4105. int i;
  4106. i40e_free_misc_vector(pf);
  4107. i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
  4108. I40E_IWARP_IRQ_PILE_ID);
  4109. i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
  4110. for (i = 0; i < pf->num_alloc_vsi; i++)
  4111. if (pf->vsi[i])
  4112. i40e_vsi_free_q_vectors(pf->vsi[i]);
  4113. i40e_reset_interrupt_capability(pf);
  4114. }
  4115. /**
  4116. * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
  4117. * @vsi: the VSI being configured
  4118. **/
  4119. static void i40e_napi_enable_all(struct i40e_vsi *vsi)
  4120. {
  4121. int q_idx;
  4122. if (!vsi->netdev)
  4123. return;
  4124. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
  4125. struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
  4126. if (q_vector->rx.ring || q_vector->tx.ring)
  4127. napi_enable(&q_vector->napi);
  4128. }
  4129. }
  4130. /**
  4131. * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
  4132. * @vsi: the VSI being configured
  4133. **/
  4134. static void i40e_napi_disable_all(struct i40e_vsi *vsi)
  4135. {
  4136. int q_idx;
  4137. if (!vsi->netdev)
  4138. return;
  4139. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
  4140. struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
  4141. if (q_vector->rx.ring || q_vector->tx.ring)
  4142. napi_disable(&q_vector->napi);
  4143. }
  4144. }
  4145. /**
  4146. * i40e_vsi_close - Shut down a VSI
  4147. * @vsi: the vsi to be quelled
  4148. **/
  4149. static void i40e_vsi_close(struct i40e_vsi *vsi)
  4150. {
  4151. struct i40e_pf *pf = vsi->back;
  4152. if (!test_and_set_bit(__I40E_VSI_DOWN, vsi->state))
  4153. i40e_down(vsi);
  4154. i40e_vsi_free_irq(vsi);
  4155. i40e_vsi_free_tx_resources(vsi);
  4156. i40e_vsi_free_rx_resources(vsi);
  4157. vsi->current_netdev_flags = 0;
  4158. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  4159. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  4160. pf->flags |= I40E_FLAG_CLIENT_RESET;
  4161. }
  4162. /**
  4163. * i40e_quiesce_vsi - Pause a given VSI
  4164. * @vsi: the VSI being paused
  4165. **/
  4166. static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
  4167. {
  4168. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  4169. return;
  4170. set_bit(__I40E_VSI_NEEDS_RESTART, vsi->state);
  4171. if (vsi->netdev && netif_running(vsi->netdev))
  4172. vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
  4173. else
  4174. i40e_vsi_close(vsi);
  4175. }
  4176. /**
  4177. * i40e_unquiesce_vsi - Resume a given VSI
  4178. * @vsi: the VSI being resumed
  4179. **/
  4180. static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
  4181. {
  4182. if (!test_and_clear_bit(__I40E_VSI_NEEDS_RESTART, vsi->state))
  4183. return;
  4184. if (vsi->netdev && netif_running(vsi->netdev))
  4185. vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
  4186. else
  4187. i40e_vsi_open(vsi); /* this clears the DOWN bit */
  4188. }
  4189. /**
  4190. * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
  4191. * @pf: the PF
  4192. **/
  4193. static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
  4194. {
  4195. int v;
  4196. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4197. if (pf->vsi[v])
  4198. i40e_quiesce_vsi(pf->vsi[v]);
  4199. }
  4200. }
  4201. /**
  4202. * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
  4203. * @pf: the PF
  4204. **/
  4205. static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
  4206. {
  4207. int v;
  4208. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4209. if (pf->vsi[v])
  4210. i40e_unquiesce_vsi(pf->vsi[v]);
  4211. }
  4212. }
  4213. /**
  4214. * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
  4215. * @vsi: the VSI being configured
  4216. *
  4217. * Wait until all queues on a given VSI have been disabled.
  4218. **/
  4219. int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
  4220. {
  4221. struct i40e_pf *pf = vsi->back;
  4222. int i, pf_q, ret;
  4223. pf_q = vsi->base_queue;
  4224. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  4225. /* Check and wait for the Tx queue */
  4226. ret = i40e_pf_txq_wait(pf, pf_q, false);
  4227. if (ret) {
  4228. dev_info(&pf->pdev->dev,
  4229. "VSI seid %d Tx ring %d disable timeout\n",
  4230. vsi->seid, pf_q);
  4231. return ret;
  4232. }
  4233. if (!i40e_enabled_xdp_vsi(vsi))
  4234. goto wait_rx;
  4235. /* Check and wait for the XDP Tx queue */
  4236. ret = i40e_pf_txq_wait(pf, pf_q + vsi->alloc_queue_pairs,
  4237. false);
  4238. if (ret) {
  4239. dev_info(&pf->pdev->dev,
  4240. "VSI seid %d XDP Tx ring %d disable timeout\n",
  4241. vsi->seid, pf_q);
  4242. return ret;
  4243. }
  4244. wait_rx:
  4245. /* Check and wait for the Rx queue */
  4246. ret = i40e_pf_rxq_wait(pf, pf_q, false);
  4247. if (ret) {
  4248. dev_info(&pf->pdev->dev,
  4249. "VSI seid %d Rx ring %d disable timeout\n",
  4250. vsi->seid, pf_q);
  4251. return ret;
  4252. }
  4253. }
  4254. return 0;
  4255. }
  4256. #ifdef CONFIG_I40E_DCB
  4257. /**
  4258. * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
  4259. * @pf: the PF
  4260. *
  4261. * This function waits for the queues to be in disabled state for all the
  4262. * VSIs that are managed by this PF.
  4263. **/
  4264. static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
  4265. {
  4266. int v, ret = 0;
  4267. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  4268. if (pf->vsi[v]) {
  4269. ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
  4270. if (ret)
  4271. break;
  4272. }
  4273. }
  4274. return ret;
  4275. }
  4276. #endif
  4277. /**
  4278. * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
  4279. * @pf: pointer to PF
  4280. *
  4281. * Get TC map for ISCSI PF type that will include iSCSI TC
  4282. * and LAN TC.
  4283. **/
  4284. static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
  4285. {
  4286. struct i40e_dcb_app_priority_table app;
  4287. struct i40e_hw *hw = &pf->hw;
  4288. u8 enabled_tc = 1; /* TC0 is always enabled */
  4289. u8 tc, i;
  4290. /* Get the iSCSI APP TLV */
  4291. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4292. for (i = 0; i < dcbcfg->numapps; i++) {
  4293. app = dcbcfg->app[i];
  4294. if (app.selector == I40E_APP_SEL_TCPIP &&
  4295. app.protocolid == I40E_APP_PROTOID_ISCSI) {
  4296. tc = dcbcfg->etscfg.prioritytable[app.priority];
  4297. enabled_tc |= BIT(tc);
  4298. break;
  4299. }
  4300. }
  4301. return enabled_tc;
  4302. }
  4303. /**
  4304. * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
  4305. * @dcbcfg: the corresponding DCBx configuration structure
  4306. *
  4307. * Return the number of TCs from given DCBx configuration
  4308. **/
  4309. static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
  4310. {
  4311. int i, tc_unused = 0;
  4312. u8 num_tc = 0;
  4313. u8 ret = 0;
  4314. /* Scan the ETS Config Priority Table to find
  4315. * traffic class enabled for a given priority
  4316. * and create a bitmask of enabled TCs
  4317. */
  4318. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
  4319. num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
  4320. /* Now scan the bitmask to check for
  4321. * contiguous TCs starting with TC0
  4322. */
  4323. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4324. if (num_tc & BIT(i)) {
  4325. if (!tc_unused) {
  4326. ret++;
  4327. } else {
  4328. pr_err("Non-contiguous TC - Disabling DCB\n");
  4329. return 1;
  4330. }
  4331. } else {
  4332. tc_unused = 1;
  4333. }
  4334. }
  4335. /* There is always at least TC0 */
  4336. if (!ret)
  4337. ret = 1;
  4338. return ret;
  4339. }
  4340. /**
  4341. * i40e_dcb_get_enabled_tc - Get enabled traffic classes
  4342. * @dcbcfg: the corresponding DCBx configuration structure
  4343. *
  4344. * Query the current DCB configuration and return the number of
  4345. * traffic classes enabled from the given DCBX config
  4346. **/
  4347. static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
  4348. {
  4349. u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
  4350. u8 enabled_tc = 1;
  4351. u8 i;
  4352. for (i = 0; i < num_tc; i++)
  4353. enabled_tc |= BIT(i);
  4354. return enabled_tc;
  4355. }
  4356. /**
  4357. * i40e_mqprio_get_enabled_tc - Get enabled traffic classes
  4358. * @pf: PF being queried
  4359. *
  4360. * Query the current MQPRIO configuration and return the number of
  4361. * traffic classes enabled.
  4362. **/
  4363. static u8 i40e_mqprio_get_enabled_tc(struct i40e_pf *pf)
  4364. {
  4365. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  4366. u8 num_tc = vsi->mqprio_qopt.qopt.num_tc;
  4367. u8 enabled_tc = 1, i;
  4368. for (i = 1; i < num_tc; i++)
  4369. enabled_tc |= BIT(i);
  4370. return enabled_tc;
  4371. }
  4372. /**
  4373. * i40e_pf_get_num_tc - Get enabled traffic classes for PF
  4374. * @pf: PF being queried
  4375. *
  4376. * Return number of traffic classes enabled for the given PF
  4377. **/
  4378. static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
  4379. {
  4380. struct i40e_hw *hw = &pf->hw;
  4381. u8 i, enabled_tc = 1;
  4382. u8 num_tc = 0;
  4383. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4384. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4385. return pf->vsi[pf->lan_vsi]->mqprio_qopt.qopt.num_tc;
  4386. /* If neither MQPRIO nor DCB is enabled, then always use single TC */
  4387. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4388. return 1;
  4389. /* SFP mode will be enabled for all TCs on port */
  4390. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4391. return i40e_dcb_get_num_tc(dcbcfg);
  4392. /* MFP mode return count of enabled TCs for this PF */
  4393. if (pf->hw.func_caps.iscsi)
  4394. enabled_tc = i40e_get_iscsi_tc_map(pf);
  4395. else
  4396. return 1; /* Only TC0 */
  4397. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4398. if (enabled_tc & BIT(i))
  4399. num_tc++;
  4400. }
  4401. return num_tc;
  4402. }
  4403. /**
  4404. * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
  4405. * @pf: PF being queried
  4406. *
  4407. * Return a bitmap for enabled traffic classes for this PF.
  4408. **/
  4409. static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
  4410. {
  4411. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4412. return i40e_mqprio_get_enabled_tc(pf);
  4413. /* If neither MQPRIO nor DCB is enabled for this PF then just return
  4414. * default TC
  4415. */
  4416. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4417. return I40E_DEFAULT_TRAFFIC_CLASS;
  4418. /* SFP mode we want PF to be enabled for all TCs */
  4419. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4420. return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
  4421. /* MFP enabled and iSCSI PF type */
  4422. if (pf->hw.func_caps.iscsi)
  4423. return i40e_get_iscsi_tc_map(pf);
  4424. else
  4425. return I40E_DEFAULT_TRAFFIC_CLASS;
  4426. }
  4427. /**
  4428. * i40e_vsi_get_bw_info - Query VSI BW Information
  4429. * @vsi: the VSI being queried
  4430. *
  4431. * Returns 0 on success, negative value on failure
  4432. **/
  4433. static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
  4434. {
  4435. struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
  4436. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  4437. struct i40e_pf *pf = vsi->back;
  4438. struct i40e_hw *hw = &pf->hw;
  4439. i40e_status ret;
  4440. u32 tc_bw_max;
  4441. int i;
  4442. /* Get the VSI level BW configuration */
  4443. ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
  4444. if (ret) {
  4445. dev_info(&pf->pdev->dev,
  4446. "couldn't get PF vsi bw config, err %s aq_err %s\n",
  4447. i40e_stat_str(&pf->hw, ret),
  4448. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4449. return -EINVAL;
  4450. }
  4451. /* Get the VSI level BW configuration per TC */
  4452. ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
  4453. NULL);
  4454. if (ret) {
  4455. dev_info(&pf->pdev->dev,
  4456. "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
  4457. i40e_stat_str(&pf->hw, ret),
  4458. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4459. return -EINVAL;
  4460. }
  4461. if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
  4462. dev_info(&pf->pdev->dev,
  4463. "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
  4464. bw_config.tc_valid_bits,
  4465. bw_ets_config.tc_valid_bits);
  4466. /* Still continuing */
  4467. }
  4468. vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
  4469. vsi->bw_max_quanta = bw_config.max_bw;
  4470. tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
  4471. (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
  4472. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4473. vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
  4474. vsi->bw_ets_limit_credits[i] =
  4475. le16_to_cpu(bw_ets_config.credits[i]);
  4476. /* 3 bits out of 4 for each TC */
  4477. vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
  4478. }
  4479. return 0;
  4480. }
  4481. /**
  4482. * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
  4483. * @vsi: the VSI being configured
  4484. * @enabled_tc: TC bitmap
  4485. * @bw_credits: BW shared credits per TC
  4486. *
  4487. * Returns 0 on success, negative value on failure
  4488. **/
  4489. static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
  4490. u8 *bw_share)
  4491. {
  4492. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  4493. i40e_status ret;
  4494. int i;
  4495. if (vsi->back->flags & I40E_FLAG_TC_MQPRIO)
  4496. return 0;
  4497. if (!vsi->mqprio_qopt.qopt.hw) {
  4498. ret = i40e_set_bw_limit(vsi, vsi->seid, 0);
  4499. if (ret)
  4500. dev_info(&vsi->back->pdev->dev,
  4501. "Failed to reset tx rate for vsi->seid %u\n",
  4502. vsi->seid);
  4503. return ret;
  4504. }
  4505. bw_data.tc_valid_bits = enabled_tc;
  4506. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4507. bw_data.tc_bw_credits[i] = bw_share[i];
  4508. ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
  4509. NULL);
  4510. if (ret) {
  4511. dev_info(&vsi->back->pdev->dev,
  4512. "AQ command Config VSI BW allocation per TC failed = %d\n",
  4513. vsi->back->hw.aq.asq_last_status);
  4514. return -EINVAL;
  4515. }
  4516. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4517. vsi->info.qs_handle[i] = bw_data.qs_handles[i];
  4518. return 0;
  4519. }
  4520. /**
  4521. * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
  4522. * @vsi: the VSI being configured
  4523. * @enabled_tc: TC map to be enabled
  4524. *
  4525. **/
  4526. static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4527. {
  4528. struct net_device *netdev = vsi->netdev;
  4529. struct i40e_pf *pf = vsi->back;
  4530. struct i40e_hw *hw = &pf->hw;
  4531. u8 netdev_tc = 0;
  4532. int i;
  4533. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4534. if (!netdev)
  4535. return;
  4536. if (!enabled_tc) {
  4537. netdev_reset_tc(netdev);
  4538. return;
  4539. }
  4540. /* Set up actual enabled TCs on the VSI */
  4541. if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
  4542. return;
  4543. /* set per TC queues for the VSI */
  4544. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4545. /* Only set TC queues for enabled tcs
  4546. *
  4547. * e.g. For a VSI that has TC0 and TC3 enabled the
  4548. * enabled_tc bitmap would be 0x00001001; the driver
  4549. * will set the numtc for netdev as 2 that will be
  4550. * referenced by the netdev layer as TC 0 and 1.
  4551. */
  4552. if (vsi->tc_config.enabled_tc & BIT(i))
  4553. netdev_set_tc_queue(netdev,
  4554. vsi->tc_config.tc_info[i].netdev_tc,
  4555. vsi->tc_config.tc_info[i].qcount,
  4556. vsi->tc_config.tc_info[i].qoffset);
  4557. }
  4558. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4559. return;
  4560. /* Assign UP2TC map for the VSI */
  4561. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  4562. /* Get the actual TC# for the UP */
  4563. u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
  4564. /* Get the mapped netdev TC# for the UP */
  4565. netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
  4566. netdev_set_prio_tc_map(netdev, i, netdev_tc);
  4567. }
  4568. }
  4569. /**
  4570. * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
  4571. * @vsi: the VSI being configured
  4572. * @ctxt: the ctxt buffer returned from AQ VSI update param command
  4573. **/
  4574. static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
  4575. struct i40e_vsi_context *ctxt)
  4576. {
  4577. /* copy just the sections touched not the entire info
  4578. * since not all sections are valid as returned by
  4579. * update vsi params
  4580. */
  4581. vsi->info.mapping_flags = ctxt->info.mapping_flags;
  4582. memcpy(&vsi->info.queue_mapping,
  4583. &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
  4584. memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
  4585. sizeof(vsi->info.tc_mapping));
  4586. }
  4587. /**
  4588. * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
  4589. * @vsi: VSI to be configured
  4590. * @enabled_tc: TC bitmap
  4591. *
  4592. * This configures a particular VSI for TCs that are mapped to the
  4593. * given TC bitmap. It uses default bandwidth share for TCs across
  4594. * VSIs to configure TC for a particular VSI.
  4595. *
  4596. * NOTE:
  4597. * It is expected that the VSI queues have been quisced before calling
  4598. * this function.
  4599. **/
  4600. static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4601. {
  4602. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  4603. struct i40e_pf *pf = vsi->back;
  4604. struct i40e_hw *hw = &pf->hw;
  4605. struct i40e_vsi_context ctxt;
  4606. int ret = 0;
  4607. int i;
  4608. /* Check if enabled_tc is same as existing or new TCs */
  4609. if (vsi->tc_config.enabled_tc == enabled_tc &&
  4610. vsi->mqprio_qopt.mode != TC_MQPRIO_MODE_CHANNEL)
  4611. return ret;
  4612. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  4613. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4614. if (enabled_tc & BIT(i))
  4615. bw_share[i] = 1;
  4616. }
  4617. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  4618. if (ret) {
  4619. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  4620. dev_info(&pf->pdev->dev,
  4621. "Failed configuring TC map %d for VSI %d\n",
  4622. enabled_tc, vsi->seid);
  4623. ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid,
  4624. &bw_config, NULL);
  4625. if (ret) {
  4626. dev_info(&pf->pdev->dev,
  4627. "Failed querying vsi bw info, err %s aq_err %s\n",
  4628. i40e_stat_str(hw, ret),
  4629. i40e_aq_str(hw, hw->aq.asq_last_status));
  4630. goto out;
  4631. }
  4632. if ((bw_config.tc_valid_bits & enabled_tc) != enabled_tc) {
  4633. u8 valid_tc = bw_config.tc_valid_bits & enabled_tc;
  4634. if (!valid_tc)
  4635. valid_tc = bw_config.tc_valid_bits;
  4636. /* Always enable TC0, no matter what */
  4637. valid_tc |= 1;
  4638. dev_info(&pf->pdev->dev,
  4639. "Requested tc 0x%x, but FW reports 0x%x as valid. Attempting to use 0x%x.\n",
  4640. enabled_tc, bw_config.tc_valid_bits, valid_tc);
  4641. enabled_tc = valid_tc;
  4642. }
  4643. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  4644. if (ret) {
  4645. dev_err(&pf->pdev->dev,
  4646. "Unable to configure TC map %d for VSI %d\n",
  4647. enabled_tc, vsi->seid);
  4648. goto out;
  4649. }
  4650. }
  4651. /* Update Queue Pairs Mapping for currently enabled UPs */
  4652. ctxt.seid = vsi->seid;
  4653. ctxt.pf_num = vsi->back->hw.pf_id;
  4654. ctxt.vf_num = 0;
  4655. ctxt.uplink_seid = vsi->uplink_seid;
  4656. ctxt.info = vsi->info;
  4657. if (vsi->back->flags & I40E_FLAG_TC_MQPRIO) {
  4658. ret = i40e_vsi_setup_queue_map_mqprio(vsi, &ctxt, enabled_tc);
  4659. if (ret)
  4660. goto out;
  4661. } else {
  4662. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  4663. }
  4664. /* On destroying the qdisc, reset vsi->rss_size, as number of enabled
  4665. * queues changed.
  4666. */
  4667. if (!vsi->mqprio_qopt.qopt.hw && vsi->reconfig_rss) {
  4668. vsi->rss_size = min_t(int, vsi->back->alloc_rss_size,
  4669. vsi->num_queue_pairs);
  4670. ret = i40e_vsi_config_rss(vsi);
  4671. if (ret) {
  4672. dev_info(&vsi->back->pdev->dev,
  4673. "Failed to reconfig rss for num_queues\n");
  4674. return ret;
  4675. }
  4676. vsi->reconfig_rss = false;
  4677. }
  4678. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  4679. ctxt.info.valid_sections |=
  4680. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  4681. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  4682. }
  4683. /* Update the VSI after updating the VSI queue-mapping
  4684. * information
  4685. */
  4686. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  4687. if (ret) {
  4688. dev_info(&pf->pdev->dev,
  4689. "Update vsi tc config failed, err %s aq_err %s\n",
  4690. i40e_stat_str(hw, ret),
  4691. i40e_aq_str(hw, hw->aq.asq_last_status));
  4692. goto out;
  4693. }
  4694. /* update the local VSI info with updated queue map */
  4695. i40e_vsi_update_queue_map(vsi, &ctxt);
  4696. vsi->info.valid_sections = 0;
  4697. /* Update current VSI BW information */
  4698. ret = i40e_vsi_get_bw_info(vsi);
  4699. if (ret) {
  4700. dev_info(&pf->pdev->dev,
  4701. "Failed updating vsi bw info, err %s aq_err %s\n",
  4702. i40e_stat_str(hw, ret),
  4703. i40e_aq_str(hw, hw->aq.asq_last_status));
  4704. goto out;
  4705. }
  4706. /* Update the netdev TC setup */
  4707. i40e_vsi_config_netdev_tc(vsi, enabled_tc);
  4708. out:
  4709. return ret;
  4710. }
  4711. /**
  4712. * i40e_get_link_speed - Returns link speed for the interface
  4713. * @vsi: VSI to be configured
  4714. *
  4715. **/
  4716. int i40e_get_link_speed(struct i40e_vsi *vsi)
  4717. {
  4718. struct i40e_pf *pf = vsi->back;
  4719. switch (pf->hw.phy.link_info.link_speed) {
  4720. case I40E_LINK_SPEED_40GB:
  4721. return 40000;
  4722. case I40E_LINK_SPEED_25GB:
  4723. return 25000;
  4724. case I40E_LINK_SPEED_20GB:
  4725. return 20000;
  4726. case I40E_LINK_SPEED_10GB:
  4727. return 10000;
  4728. case I40E_LINK_SPEED_1GB:
  4729. return 1000;
  4730. default:
  4731. return -EINVAL;
  4732. }
  4733. }
  4734. /**
  4735. * i40e_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
  4736. * @vsi: VSI to be configured
  4737. * @seid: seid of the channel/VSI
  4738. * @max_tx_rate: max TX rate to be configured as BW limit
  4739. *
  4740. * Helper function to set BW limit for a given VSI
  4741. **/
  4742. int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate)
  4743. {
  4744. struct i40e_pf *pf = vsi->back;
  4745. u64 credits = 0;
  4746. int speed = 0;
  4747. int ret = 0;
  4748. speed = i40e_get_link_speed(vsi);
  4749. if (max_tx_rate > speed) {
  4750. dev_err(&pf->pdev->dev,
  4751. "Invalid max tx rate %llu specified for VSI seid %d.",
  4752. max_tx_rate, seid);
  4753. return -EINVAL;
  4754. }
  4755. if (max_tx_rate && max_tx_rate < 50) {
  4756. dev_warn(&pf->pdev->dev,
  4757. "Setting max tx rate to minimum usable value of 50Mbps.\n");
  4758. max_tx_rate = 50;
  4759. }
  4760. /* Tx rate credits are in values of 50Mbps, 0 is disabled */
  4761. credits = max_tx_rate;
  4762. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  4763. ret = i40e_aq_config_vsi_bw_limit(&pf->hw, seid, credits,
  4764. I40E_MAX_BW_INACTIVE_ACCUM, NULL);
  4765. if (ret)
  4766. dev_err(&pf->pdev->dev,
  4767. "Failed set tx rate (%llu Mbps) for vsi->seid %u, err %s aq_err %s\n",
  4768. max_tx_rate, seid, i40e_stat_str(&pf->hw, ret),
  4769. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4770. return ret;
  4771. }
  4772. /**
  4773. * i40e_remove_queue_channels - Remove queue channels for the TCs
  4774. * @vsi: VSI to be configured
  4775. *
  4776. * Remove queue channels for the TCs
  4777. **/
  4778. static void i40e_remove_queue_channels(struct i40e_vsi *vsi)
  4779. {
  4780. enum i40e_admin_queue_err last_aq_status;
  4781. struct i40e_cloud_filter *cfilter;
  4782. struct i40e_channel *ch, *ch_tmp;
  4783. struct i40e_pf *pf = vsi->back;
  4784. struct hlist_node *node;
  4785. int ret, i;
  4786. /* Reset rss size that was stored when reconfiguring rss for
  4787. * channel VSIs with non-power-of-2 queue count.
  4788. */
  4789. vsi->current_rss_size = 0;
  4790. /* perform cleanup for channels if they exist */
  4791. if (list_empty(&vsi->ch_list))
  4792. return;
  4793. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4794. struct i40e_vsi *p_vsi;
  4795. list_del(&ch->list);
  4796. p_vsi = ch->parent_vsi;
  4797. if (!p_vsi || !ch->initialized) {
  4798. kfree(ch);
  4799. continue;
  4800. }
  4801. /* Reset queue contexts */
  4802. for (i = 0; i < ch->num_queue_pairs; i++) {
  4803. struct i40e_ring *tx_ring, *rx_ring;
  4804. u16 pf_q;
  4805. pf_q = ch->base_queue + i;
  4806. tx_ring = vsi->tx_rings[pf_q];
  4807. tx_ring->ch = NULL;
  4808. rx_ring = vsi->rx_rings[pf_q];
  4809. rx_ring->ch = NULL;
  4810. }
  4811. /* Reset BW configured for this VSI via mqprio */
  4812. ret = i40e_set_bw_limit(vsi, ch->seid, 0);
  4813. if (ret)
  4814. dev_info(&vsi->back->pdev->dev,
  4815. "Failed to reset tx rate for ch->seid %u\n",
  4816. ch->seid);
  4817. /* delete cloud filters associated with this channel */
  4818. hlist_for_each_entry_safe(cfilter, node,
  4819. &pf->cloud_filter_list, cloud_node) {
  4820. if (cfilter->seid != ch->seid)
  4821. continue;
  4822. hash_del(&cfilter->cloud_node);
  4823. if (cfilter->dst_port)
  4824. ret = i40e_add_del_cloud_filter_big_buf(vsi,
  4825. cfilter,
  4826. false);
  4827. else
  4828. ret = i40e_add_del_cloud_filter(vsi, cfilter,
  4829. false);
  4830. last_aq_status = pf->hw.aq.asq_last_status;
  4831. if (ret)
  4832. dev_info(&pf->pdev->dev,
  4833. "Failed to delete cloud filter, err %s aq_err %s\n",
  4834. i40e_stat_str(&pf->hw, ret),
  4835. i40e_aq_str(&pf->hw, last_aq_status));
  4836. kfree(cfilter);
  4837. }
  4838. /* delete VSI from FW */
  4839. ret = i40e_aq_delete_element(&vsi->back->hw, ch->seid,
  4840. NULL);
  4841. if (ret)
  4842. dev_err(&vsi->back->pdev->dev,
  4843. "unable to remove channel (%d) for parent VSI(%d)\n",
  4844. ch->seid, p_vsi->seid);
  4845. kfree(ch);
  4846. }
  4847. INIT_LIST_HEAD(&vsi->ch_list);
  4848. }
  4849. /**
  4850. * i40e_is_any_channel - channel exist or not
  4851. * @vsi: ptr to VSI to which channels are associated with
  4852. *
  4853. * Returns true or false if channel(s) exist for associated VSI or not
  4854. **/
  4855. static bool i40e_is_any_channel(struct i40e_vsi *vsi)
  4856. {
  4857. struct i40e_channel *ch, *ch_tmp;
  4858. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4859. if (ch->initialized)
  4860. return true;
  4861. }
  4862. return false;
  4863. }
  4864. /**
  4865. * i40e_get_max_queues_for_channel
  4866. * @vsi: ptr to VSI to which channels are associated with
  4867. *
  4868. * Helper function which returns max value among the queue counts set on the
  4869. * channels/TCs created.
  4870. **/
  4871. static int i40e_get_max_queues_for_channel(struct i40e_vsi *vsi)
  4872. {
  4873. struct i40e_channel *ch, *ch_tmp;
  4874. int max = 0;
  4875. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4876. if (!ch->initialized)
  4877. continue;
  4878. if (ch->num_queue_pairs > max)
  4879. max = ch->num_queue_pairs;
  4880. }
  4881. return max;
  4882. }
  4883. /**
  4884. * i40e_validate_num_queues - validate num_queues w.r.t channel
  4885. * @pf: ptr to PF device
  4886. * @num_queues: number of queues
  4887. * @vsi: the parent VSI
  4888. * @reconfig_rss: indicates should the RSS be reconfigured or not
  4889. *
  4890. * This function validates number of queues in the context of new channel
  4891. * which is being established and determines if RSS should be reconfigured
  4892. * or not for parent VSI.
  4893. **/
  4894. static int i40e_validate_num_queues(struct i40e_pf *pf, int num_queues,
  4895. struct i40e_vsi *vsi, bool *reconfig_rss)
  4896. {
  4897. int max_ch_queues;
  4898. if (!reconfig_rss)
  4899. return -EINVAL;
  4900. *reconfig_rss = false;
  4901. if (vsi->current_rss_size) {
  4902. if (num_queues > vsi->current_rss_size) {
  4903. dev_dbg(&pf->pdev->dev,
  4904. "Error: num_queues (%d) > vsi's current_size(%d)\n",
  4905. num_queues, vsi->current_rss_size);
  4906. return -EINVAL;
  4907. } else if ((num_queues < vsi->current_rss_size) &&
  4908. (!is_power_of_2(num_queues))) {
  4909. dev_dbg(&pf->pdev->dev,
  4910. "Error: num_queues (%d) < vsi's current_size(%d), but not power of 2\n",
  4911. num_queues, vsi->current_rss_size);
  4912. return -EINVAL;
  4913. }
  4914. }
  4915. if (!is_power_of_2(num_queues)) {
  4916. /* Find the max num_queues configured for channel if channel
  4917. * exist.
  4918. * if channel exist, then enforce 'num_queues' to be more than
  4919. * max ever queues configured for channel.
  4920. */
  4921. max_ch_queues = i40e_get_max_queues_for_channel(vsi);
  4922. if (num_queues < max_ch_queues) {
  4923. dev_dbg(&pf->pdev->dev,
  4924. "Error: num_queues (%d) < max queues configured for channel(%d)\n",
  4925. num_queues, max_ch_queues);
  4926. return -EINVAL;
  4927. }
  4928. *reconfig_rss = true;
  4929. }
  4930. return 0;
  4931. }
  4932. /**
  4933. * i40e_vsi_reconfig_rss - reconfig RSS based on specified rss_size
  4934. * @vsi: the VSI being setup
  4935. * @rss_size: size of RSS, accordingly LUT gets reprogrammed
  4936. *
  4937. * This function reconfigures RSS by reprogramming LUTs using 'rss_size'
  4938. **/
  4939. static int i40e_vsi_reconfig_rss(struct i40e_vsi *vsi, u16 rss_size)
  4940. {
  4941. struct i40e_pf *pf = vsi->back;
  4942. u8 seed[I40E_HKEY_ARRAY_SIZE];
  4943. struct i40e_hw *hw = &pf->hw;
  4944. int local_rss_size;
  4945. u8 *lut;
  4946. int ret;
  4947. if (!vsi->rss_size)
  4948. return -EINVAL;
  4949. if (rss_size > vsi->rss_size)
  4950. return -EINVAL;
  4951. local_rss_size = min_t(int, vsi->rss_size, rss_size);
  4952. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  4953. if (!lut)
  4954. return -ENOMEM;
  4955. /* Ignoring user configured lut if there is one */
  4956. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, local_rss_size);
  4957. /* Use user configured hash key if there is one, otherwise
  4958. * use default.
  4959. */
  4960. if (vsi->rss_hkey_user)
  4961. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  4962. else
  4963. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  4964. ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
  4965. if (ret) {
  4966. dev_info(&pf->pdev->dev,
  4967. "Cannot set RSS lut, err %s aq_err %s\n",
  4968. i40e_stat_str(hw, ret),
  4969. i40e_aq_str(hw, hw->aq.asq_last_status));
  4970. kfree(lut);
  4971. return ret;
  4972. }
  4973. kfree(lut);
  4974. /* Do the update w.r.t. storing rss_size */
  4975. if (!vsi->orig_rss_size)
  4976. vsi->orig_rss_size = vsi->rss_size;
  4977. vsi->current_rss_size = local_rss_size;
  4978. return ret;
  4979. }
  4980. /**
  4981. * i40e_channel_setup_queue_map - Setup a channel queue map
  4982. * @pf: ptr to PF device
  4983. * @vsi: the VSI being setup
  4984. * @ctxt: VSI context structure
  4985. * @ch: ptr to channel structure
  4986. *
  4987. * Setup queue map for a specific channel
  4988. **/
  4989. static void i40e_channel_setup_queue_map(struct i40e_pf *pf,
  4990. struct i40e_vsi_context *ctxt,
  4991. struct i40e_channel *ch)
  4992. {
  4993. u16 qcount, qmap, sections = 0;
  4994. u8 offset = 0;
  4995. int pow;
  4996. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  4997. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  4998. qcount = min_t(int, ch->num_queue_pairs, pf->num_lan_msix);
  4999. ch->num_queue_pairs = qcount;
  5000. /* find the next higher power-of-2 of num queue pairs */
  5001. pow = ilog2(qcount);
  5002. if (!is_power_of_2(qcount))
  5003. pow++;
  5004. qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  5005. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  5006. /* Setup queue TC[0].qmap for given VSI context */
  5007. ctxt->info.tc_mapping[0] = cpu_to_le16(qmap);
  5008. ctxt->info.up_enable_bits = 0x1; /* TC0 enabled */
  5009. ctxt->info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  5010. ctxt->info.queue_mapping[0] = cpu_to_le16(ch->base_queue);
  5011. ctxt->info.valid_sections |= cpu_to_le16(sections);
  5012. }
  5013. /**
  5014. * i40e_add_channel - add a channel by adding VSI
  5015. * @pf: ptr to PF device
  5016. * @uplink_seid: underlying HW switching element (VEB) ID
  5017. * @ch: ptr to channel structure
  5018. *
  5019. * Add a channel (VSI) using add_vsi and queue_map
  5020. **/
  5021. static int i40e_add_channel(struct i40e_pf *pf, u16 uplink_seid,
  5022. struct i40e_channel *ch)
  5023. {
  5024. struct i40e_hw *hw = &pf->hw;
  5025. struct i40e_vsi_context ctxt;
  5026. u8 enabled_tc = 0x1; /* TC0 enabled */
  5027. int ret;
  5028. if (ch->type != I40E_VSI_VMDQ2) {
  5029. dev_info(&pf->pdev->dev,
  5030. "add new vsi failed, ch->type %d\n", ch->type);
  5031. return -EINVAL;
  5032. }
  5033. memset(&ctxt, 0, sizeof(ctxt));
  5034. ctxt.pf_num = hw->pf_id;
  5035. ctxt.vf_num = 0;
  5036. ctxt.uplink_seid = uplink_seid;
  5037. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  5038. if (ch->type == I40E_VSI_VMDQ2)
  5039. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  5040. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) {
  5041. ctxt.info.valid_sections |=
  5042. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5043. ctxt.info.switch_id =
  5044. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5045. }
  5046. /* Set queue map for a given VSI context */
  5047. i40e_channel_setup_queue_map(pf, &ctxt, ch);
  5048. /* Now time to create VSI */
  5049. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  5050. if (ret) {
  5051. dev_info(&pf->pdev->dev,
  5052. "add new vsi failed, err %s aq_err %s\n",
  5053. i40e_stat_str(&pf->hw, ret),
  5054. i40e_aq_str(&pf->hw,
  5055. pf->hw.aq.asq_last_status));
  5056. return -ENOENT;
  5057. }
  5058. /* Success, update channel */
  5059. ch->enabled_tc = enabled_tc;
  5060. ch->seid = ctxt.seid;
  5061. ch->vsi_number = ctxt.vsi_number;
  5062. ch->stat_counter_idx = cpu_to_le16(ctxt.info.stat_counter_idx);
  5063. /* copy just the sections touched not the entire info
  5064. * since not all sections are valid as returned by
  5065. * update vsi params
  5066. */
  5067. ch->info.mapping_flags = ctxt.info.mapping_flags;
  5068. memcpy(&ch->info.queue_mapping,
  5069. &ctxt.info.queue_mapping, sizeof(ctxt.info.queue_mapping));
  5070. memcpy(&ch->info.tc_mapping, ctxt.info.tc_mapping,
  5071. sizeof(ctxt.info.tc_mapping));
  5072. return 0;
  5073. }
  5074. static int i40e_channel_config_bw(struct i40e_vsi *vsi, struct i40e_channel *ch,
  5075. u8 *bw_share)
  5076. {
  5077. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  5078. i40e_status ret;
  5079. int i;
  5080. bw_data.tc_valid_bits = ch->enabled_tc;
  5081. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  5082. bw_data.tc_bw_credits[i] = bw_share[i];
  5083. ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, ch->seid,
  5084. &bw_data, NULL);
  5085. if (ret) {
  5086. dev_info(&vsi->back->pdev->dev,
  5087. "Config VSI BW allocation per TC failed, aq_err: %d for new_vsi->seid %u\n",
  5088. vsi->back->hw.aq.asq_last_status, ch->seid);
  5089. return -EINVAL;
  5090. }
  5091. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  5092. ch->info.qs_handle[i] = bw_data.qs_handles[i];
  5093. return 0;
  5094. }
  5095. /**
  5096. * i40e_channel_config_tx_ring - config TX ring associated with new channel
  5097. * @pf: ptr to PF device
  5098. * @vsi: the VSI being setup
  5099. * @ch: ptr to channel structure
  5100. *
  5101. * Configure TX rings associated with channel (VSI) since queues are being
  5102. * from parent VSI.
  5103. **/
  5104. static int i40e_channel_config_tx_ring(struct i40e_pf *pf,
  5105. struct i40e_vsi *vsi,
  5106. struct i40e_channel *ch)
  5107. {
  5108. i40e_status ret;
  5109. int i;
  5110. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  5111. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  5112. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5113. if (ch->enabled_tc & BIT(i))
  5114. bw_share[i] = 1;
  5115. }
  5116. /* configure BW for new VSI */
  5117. ret = i40e_channel_config_bw(vsi, ch, bw_share);
  5118. if (ret) {
  5119. dev_info(&vsi->back->pdev->dev,
  5120. "Failed configuring TC map %d for channel (seid %u)\n",
  5121. ch->enabled_tc, ch->seid);
  5122. return ret;
  5123. }
  5124. for (i = 0; i < ch->num_queue_pairs; i++) {
  5125. struct i40e_ring *tx_ring, *rx_ring;
  5126. u16 pf_q;
  5127. pf_q = ch->base_queue + i;
  5128. /* Get to TX ring ptr of main VSI, for re-setup TX queue
  5129. * context
  5130. */
  5131. tx_ring = vsi->tx_rings[pf_q];
  5132. tx_ring->ch = ch;
  5133. /* Get the RX ring ptr */
  5134. rx_ring = vsi->rx_rings[pf_q];
  5135. rx_ring->ch = ch;
  5136. }
  5137. return 0;
  5138. }
  5139. /**
  5140. * i40e_setup_hw_channel - setup new channel
  5141. * @pf: ptr to PF device
  5142. * @vsi: the VSI being setup
  5143. * @ch: ptr to channel structure
  5144. * @uplink_seid: underlying HW switching element (VEB) ID
  5145. * @type: type of channel to be created (VMDq2/VF)
  5146. *
  5147. * Setup new channel (VSI) based on specified type (VMDq2/VF)
  5148. * and configures TX rings accordingly
  5149. **/
  5150. static inline int i40e_setup_hw_channel(struct i40e_pf *pf,
  5151. struct i40e_vsi *vsi,
  5152. struct i40e_channel *ch,
  5153. u16 uplink_seid, u8 type)
  5154. {
  5155. int ret;
  5156. ch->initialized = false;
  5157. ch->base_queue = vsi->next_base_queue;
  5158. ch->type = type;
  5159. /* Proceed with creation of channel (VMDq2) VSI */
  5160. ret = i40e_add_channel(pf, uplink_seid, ch);
  5161. if (ret) {
  5162. dev_info(&pf->pdev->dev,
  5163. "failed to add_channel using uplink_seid %u\n",
  5164. uplink_seid);
  5165. return ret;
  5166. }
  5167. /* Mark the successful creation of channel */
  5168. ch->initialized = true;
  5169. /* Reconfigure TX queues using QTX_CTL register */
  5170. ret = i40e_channel_config_tx_ring(pf, vsi, ch);
  5171. if (ret) {
  5172. dev_info(&pf->pdev->dev,
  5173. "failed to configure TX rings for channel %u\n",
  5174. ch->seid);
  5175. return ret;
  5176. }
  5177. /* update 'next_base_queue' */
  5178. vsi->next_base_queue = vsi->next_base_queue + ch->num_queue_pairs;
  5179. dev_dbg(&pf->pdev->dev,
  5180. "Added channel: vsi_seid %u, vsi_number %u, stat_counter_idx %u, num_queue_pairs %u, pf->next_base_queue %d\n",
  5181. ch->seid, ch->vsi_number, ch->stat_counter_idx,
  5182. ch->num_queue_pairs,
  5183. vsi->next_base_queue);
  5184. return ret;
  5185. }
  5186. /**
  5187. * i40e_setup_channel - setup new channel using uplink element
  5188. * @pf: ptr to PF device
  5189. * @type: type of channel to be created (VMDq2/VF)
  5190. * @uplink_seid: underlying HW switching element (VEB) ID
  5191. * @ch: ptr to channel structure
  5192. *
  5193. * Setup new channel (VSI) based on specified type (VMDq2/VF)
  5194. * and uplink switching element (uplink_seid)
  5195. **/
  5196. static bool i40e_setup_channel(struct i40e_pf *pf, struct i40e_vsi *vsi,
  5197. struct i40e_channel *ch)
  5198. {
  5199. u8 vsi_type;
  5200. u16 seid;
  5201. int ret;
  5202. if (vsi->type == I40E_VSI_MAIN) {
  5203. vsi_type = I40E_VSI_VMDQ2;
  5204. } else {
  5205. dev_err(&pf->pdev->dev, "unsupported parent vsi type(%d)\n",
  5206. vsi->type);
  5207. return false;
  5208. }
  5209. /* underlying switching element */
  5210. seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  5211. /* create channel (VSI), configure TX rings */
  5212. ret = i40e_setup_hw_channel(pf, vsi, ch, seid, vsi_type);
  5213. if (ret) {
  5214. dev_err(&pf->pdev->dev, "failed to setup hw_channel\n");
  5215. return false;
  5216. }
  5217. return ch->initialized ? true : false;
  5218. }
  5219. /**
  5220. * i40e_validate_and_set_switch_mode - sets up switch mode correctly
  5221. * @vsi: ptr to VSI which has PF backing
  5222. *
  5223. * Sets up switch mode correctly if it needs to be changed and perform
  5224. * what are allowed modes.
  5225. **/
  5226. static int i40e_validate_and_set_switch_mode(struct i40e_vsi *vsi)
  5227. {
  5228. u8 mode;
  5229. struct i40e_pf *pf = vsi->back;
  5230. struct i40e_hw *hw = &pf->hw;
  5231. int ret;
  5232. ret = i40e_get_capabilities(pf, i40e_aqc_opc_list_dev_capabilities);
  5233. if (ret)
  5234. return -EINVAL;
  5235. if (hw->dev_caps.switch_mode) {
  5236. /* if switch mode is set, support mode2 (non-tunneled for
  5237. * cloud filter) for now
  5238. */
  5239. u32 switch_mode = hw->dev_caps.switch_mode &
  5240. I40E_SWITCH_MODE_MASK;
  5241. if (switch_mode >= I40E_CLOUD_FILTER_MODE1) {
  5242. if (switch_mode == I40E_CLOUD_FILTER_MODE2)
  5243. return 0;
  5244. dev_err(&pf->pdev->dev,
  5245. "Invalid switch_mode (%d), only non-tunneled mode for cloud filter is supported\n",
  5246. hw->dev_caps.switch_mode);
  5247. return -EINVAL;
  5248. }
  5249. }
  5250. /* Set Bit 7 to be valid */
  5251. mode = I40E_AQ_SET_SWITCH_BIT7_VALID;
  5252. /* Set L4type for TCP support */
  5253. mode |= I40E_AQ_SET_SWITCH_L4_TYPE_TCP;
  5254. /* Set cloud filter mode */
  5255. mode |= I40E_AQ_SET_SWITCH_MODE_NON_TUNNEL;
  5256. /* Prep mode field for set_switch_config */
  5257. ret = i40e_aq_set_switch_config(hw, pf->last_sw_conf_flags,
  5258. pf->last_sw_conf_valid_flags,
  5259. mode, NULL);
  5260. if (ret && hw->aq.asq_last_status != I40E_AQ_RC_ESRCH)
  5261. dev_err(&pf->pdev->dev,
  5262. "couldn't set switch config bits, err %s aq_err %s\n",
  5263. i40e_stat_str(hw, ret),
  5264. i40e_aq_str(hw,
  5265. hw->aq.asq_last_status));
  5266. return ret;
  5267. }
  5268. /**
  5269. * i40e_create_queue_channel - function to create channel
  5270. * @vsi: VSI to be configured
  5271. * @ch: ptr to channel (it contains channel specific params)
  5272. *
  5273. * This function creates channel (VSI) using num_queues specified by user,
  5274. * reconfigs RSS if needed.
  5275. **/
  5276. int i40e_create_queue_channel(struct i40e_vsi *vsi,
  5277. struct i40e_channel *ch)
  5278. {
  5279. struct i40e_pf *pf = vsi->back;
  5280. bool reconfig_rss;
  5281. int err;
  5282. if (!ch)
  5283. return -EINVAL;
  5284. if (!ch->num_queue_pairs) {
  5285. dev_err(&pf->pdev->dev, "Invalid num_queues requested: %d\n",
  5286. ch->num_queue_pairs);
  5287. return -EINVAL;
  5288. }
  5289. /* validate user requested num_queues for channel */
  5290. err = i40e_validate_num_queues(pf, ch->num_queue_pairs, vsi,
  5291. &reconfig_rss);
  5292. if (err) {
  5293. dev_info(&pf->pdev->dev, "Failed to validate num_queues (%d)\n",
  5294. ch->num_queue_pairs);
  5295. return -EINVAL;
  5296. }
  5297. /* By default we are in VEPA mode, if this is the first VF/VMDq
  5298. * VSI to be added switch to VEB mode.
  5299. */
  5300. if ((!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) ||
  5301. (!i40e_is_any_channel(vsi))) {
  5302. if (!is_power_of_2(vsi->tc_config.tc_info[0].qcount)) {
  5303. dev_dbg(&pf->pdev->dev,
  5304. "Failed to create channel. Override queues (%u) not power of 2\n",
  5305. vsi->tc_config.tc_info[0].qcount);
  5306. return -EINVAL;
  5307. }
  5308. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  5309. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  5310. if (vsi->type == I40E_VSI_MAIN) {
  5311. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  5312. i40e_do_reset(pf, I40E_PF_RESET_FLAG,
  5313. true);
  5314. else
  5315. i40e_do_reset_safe(pf,
  5316. I40E_PF_RESET_FLAG);
  5317. }
  5318. }
  5319. /* now onwards for main VSI, number of queues will be value
  5320. * of TC0's queue count
  5321. */
  5322. }
  5323. /* By this time, vsi->cnt_q_avail shall be set to non-zero and
  5324. * it should be more than num_queues
  5325. */
  5326. if (!vsi->cnt_q_avail || vsi->cnt_q_avail < ch->num_queue_pairs) {
  5327. dev_dbg(&pf->pdev->dev,
  5328. "Error: cnt_q_avail (%u) less than num_queues %d\n",
  5329. vsi->cnt_q_avail, ch->num_queue_pairs);
  5330. return -EINVAL;
  5331. }
  5332. /* reconfig_rss only if vsi type is MAIN_VSI */
  5333. if (reconfig_rss && (vsi->type == I40E_VSI_MAIN)) {
  5334. err = i40e_vsi_reconfig_rss(vsi, ch->num_queue_pairs);
  5335. if (err) {
  5336. dev_info(&pf->pdev->dev,
  5337. "Error: unable to reconfig rss for num_queues (%u)\n",
  5338. ch->num_queue_pairs);
  5339. return -EINVAL;
  5340. }
  5341. }
  5342. if (!i40e_setup_channel(pf, vsi, ch)) {
  5343. dev_info(&pf->pdev->dev, "Failed to setup channel\n");
  5344. return -EINVAL;
  5345. }
  5346. dev_info(&pf->pdev->dev,
  5347. "Setup channel (id:%u) utilizing num_queues %d\n",
  5348. ch->seid, ch->num_queue_pairs);
  5349. /* configure VSI for BW limit */
  5350. if (ch->max_tx_rate) {
  5351. u64 credits = ch->max_tx_rate;
  5352. if (i40e_set_bw_limit(vsi, ch->seid, ch->max_tx_rate))
  5353. return -EINVAL;
  5354. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  5355. dev_dbg(&pf->pdev->dev,
  5356. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  5357. ch->max_tx_rate,
  5358. credits,
  5359. ch->seid);
  5360. }
  5361. /* in case of VF, this will be main SRIOV VSI */
  5362. ch->parent_vsi = vsi;
  5363. /* and update main_vsi's count for queue_available to use */
  5364. vsi->cnt_q_avail -= ch->num_queue_pairs;
  5365. return 0;
  5366. }
  5367. /**
  5368. * i40e_configure_queue_channels - Add queue channel for the given TCs
  5369. * @vsi: VSI to be configured
  5370. *
  5371. * Configures queue channel mapping to the given TCs
  5372. **/
  5373. static int i40e_configure_queue_channels(struct i40e_vsi *vsi)
  5374. {
  5375. struct i40e_channel *ch;
  5376. u64 max_rate = 0;
  5377. int ret = 0, i;
  5378. /* Create app vsi with the TCs. Main VSI with TC0 is already set up */
  5379. vsi->tc_seid_map[0] = vsi->seid;
  5380. for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5381. if (vsi->tc_config.enabled_tc & BIT(i)) {
  5382. ch = kzalloc(sizeof(*ch), GFP_KERNEL);
  5383. if (!ch) {
  5384. ret = -ENOMEM;
  5385. goto err_free;
  5386. }
  5387. INIT_LIST_HEAD(&ch->list);
  5388. ch->num_queue_pairs =
  5389. vsi->tc_config.tc_info[i].qcount;
  5390. ch->base_queue =
  5391. vsi->tc_config.tc_info[i].qoffset;
  5392. /* Bandwidth limit through tc interface is in bytes/s,
  5393. * change to Mbit/s
  5394. */
  5395. max_rate = vsi->mqprio_qopt.max_rate[i];
  5396. do_div(max_rate, I40E_BW_MBPS_DIVISOR);
  5397. ch->max_tx_rate = max_rate;
  5398. list_add_tail(&ch->list, &vsi->ch_list);
  5399. ret = i40e_create_queue_channel(vsi, ch);
  5400. if (ret) {
  5401. dev_err(&vsi->back->pdev->dev,
  5402. "Failed creating queue channel with TC%d: queues %d\n",
  5403. i, ch->num_queue_pairs);
  5404. goto err_free;
  5405. }
  5406. vsi->tc_seid_map[i] = ch->seid;
  5407. }
  5408. }
  5409. return ret;
  5410. err_free:
  5411. i40e_remove_queue_channels(vsi);
  5412. return ret;
  5413. }
  5414. /**
  5415. * i40e_veb_config_tc - Configure TCs for given VEB
  5416. * @veb: given VEB
  5417. * @enabled_tc: TC bitmap
  5418. *
  5419. * Configures given TC bitmap for VEB (switching) element
  5420. **/
  5421. int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
  5422. {
  5423. struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
  5424. struct i40e_pf *pf = veb->pf;
  5425. int ret = 0;
  5426. int i;
  5427. /* No TCs or already enabled TCs just return */
  5428. if (!enabled_tc || veb->enabled_tc == enabled_tc)
  5429. return ret;
  5430. bw_data.tc_valid_bits = enabled_tc;
  5431. /* bw_data.absolute_credits is not set (relative) */
  5432. /* Enable ETS TCs with equal BW Share for now */
  5433. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5434. if (enabled_tc & BIT(i))
  5435. bw_data.tc_bw_share_credits[i] = 1;
  5436. }
  5437. ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
  5438. &bw_data, NULL);
  5439. if (ret) {
  5440. dev_info(&pf->pdev->dev,
  5441. "VEB bw config failed, err %s aq_err %s\n",
  5442. i40e_stat_str(&pf->hw, ret),
  5443. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5444. goto out;
  5445. }
  5446. /* Update the BW information */
  5447. ret = i40e_veb_get_bw_info(veb);
  5448. if (ret) {
  5449. dev_info(&pf->pdev->dev,
  5450. "Failed getting veb bw config, err %s aq_err %s\n",
  5451. i40e_stat_str(&pf->hw, ret),
  5452. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5453. }
  5454. out:
  5455. return ret;
  5456. }
  5457. #ifdef CONFIG_I40E_DCB
  5458. /**
  5459. * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
  5460. * @pf: PF struct
  5461. *
  5462. * Reconfigure VEB/VSIs on a given PF; it is assumed that
  5463. * the caller would've quiesce all the VSIs before calling
  5464. * this function
  5465. **/
  5466. static void i40e_dcb_reconfigure(struct i40e_pf *pf)
  5467. {
  5468. u8 tc_map = 0;
  5469. int ret;
  5470. u8 v;
  5471. /* Enable the TCs available on PF to all VEBs */
  5472. tc_map = i40e_pf_get_tc_map(pf);
  5473. for (v = 0; v < I40E_MAX_VEB; v++) {
  5474. if (!pf->veb[v])
  5475. continue;
  5476. ret = i40e_veb_config_tc(pf->veb[v], tc_map);
  5477. if (ret) {
  5478. dev_info(&pf->pdev->dev,
  5479. "Failed configuring TC for VEB seid=%d\n",
  5480. pf->veb[v]->seid);
  5481. /* Will try to configure as many components */
  5482. }
  5483. }
  5484. /* Update each VSI */
  5485. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5486. if (!pf->vsi[v])
  5487. continue;
  5488. /* - Enable all TCs for the LAN VSI
  5489. * - For all others keep them at TC0 for now
  5490. */
  5491. if (v == pf->lan_vsi)
  5492. tc_map = i40e_pf_get_tc_map(pf);
  5493. else
  5494. tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
  5495. ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
  5496. if (ret) {
  5497. dev_info(&pf->pdev->dev,
  5498. "Failed configuring TC for VSI seid=%d\n",
  5499. pf->vsi[v]->seid);
  5500. /* Will try to configure as many components */
  5501. } else {
  5502. /* Re-configure VSI vectors based on updated TC map */
  5503. i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
  5504. if (pf->vsi[v]->netdev)
  5505. i40e_dcbnl_set_all(pf->vsi[v]);
  5506. }
  5507. }
  5508. }
  5509. /**
  5510. * i40e_resume_port_tx - Resume port Tx
  5511. * @pf: PF struct
  5512. *
  5513. * Resume a port's Tx and issue a PF reset in case of failure to
  5514. * resume.
  5515. **/
  5516. static int i40e_resume_port_tx(struct i40e_pf *pf)
  5517. {
  5518. struct i40e_hw *hw = &pf->hw;
  5519. int ret;
  5520. ret = i40e_aq_resume_port_tx(hw, NULL);
  5521. if (ret) {
  5522. dev_info(&pf->pdev->dev,
  5523. "Resume Port Tx failed, err %s aq_err %s\n",
  5524. i40e_stat_str(&pf->hw, ret),
  5525. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5526. /* Schedule PF reset to recover */
  5527. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  5528. i40e_service_event_schedule(pf);
  5529. }
  5530. return ret;
  5531. }
  5532. /**
  5533. * i40e_init_pf_dcb - Initialize DCB configuration
  5534. * @pf: PF being configured
  5535. *
  5536. * Query the current DCB configuration and cache it
  5537. * in the hardware structure
  5538. **/
  5539. static int i40e_init_pf_dcb(struct i40e_pf *pf)
  5540. {
  5541. struct i40e_hw *hw = &pf->hw;
  5542. int err = 0;
  5543. /* Do not enable DCB for SW1 and SW2 images even if the FW is capable
  5544. * Also do not enable DCBx if FW LLDP agent is disabled
  5545. */
  5546. if ((pf->hw_features & I40E_HW_NO_DCB_SUPPORT) ||
  5547. (pf->flags & I40E_FLAG_DISABLE_FW_LLDP))
  5548. goto out;
  5549. /* Get the initial DCB configuration */
  5550. err = i40e_init_dcb(hw);
  5551. if (!err) {
  5552. /* Device/Function is not DCBX capable */
  5553. if ((!hw->func_caps.dcb) ||
  5554. (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
  5555. dev_info(&pf->pdev->dev,
  5556. "DCBX offload is not supported or is disabled for this PF.\n");
  5557. } else {
  5558. /* When status is not DISABLED then DCBX in FW */
  5559. pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
  5560. DCB_CAP_DCBX_VER_IEEE;
  5561. pf->flags |= I40E_FLAG_DCB_CAPABLE;
  5562. /* Enable DCB tagging only when more than one TC
  5563. * or explicitly disable if only one TC
  5564. */
  5565. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  5566. pf->flags |= I40E_FLAG_DCB_ENABLED;
  5567. else
  5568. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  5569. dev_dbg(&pf->pdev->dev,
  5570. "DCBX offload is supported for this PF.\n");
  5571. }
  5572. } else if (pf->hw.aq.asq_last_status == I40E_AQ_RC_EPERM) {
  5573. dev_info(&pf->pdev->dev, "FW LLDP disabled for this PF.\n");
  5574. pf->flags |= I40E_FLAG_DISABLE_FW_LLDP;
  5575. } else {
  5576. dev_info(&pf->pdev->dev,
  5577. "Query for DCB configuration failed, err %s aq_err %s\n",
  5578. i40e_stat_str(&pf->hw, err),
  5579. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5580. }
  5581. out:
  5582. return err;
  5583. }
  5584. #endif /* CONFIG_I40E_DCB */
  5585. #define SPEED_SIZE 14
  5586. #define FC_SIZE 8
  5587. /**
  5588. * i40e_print_link_message - print link up or down
  5589. * @vsi: the VSI for which link needs a message
  5590. */
  5591. void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
  5592. {
  5593. enum i40e_aq_link_speed new_speed;
  5594. struct i40e_pf *pf = vsi->back;
  5595. char *speed = "Unknown";
  5596. char *fc = "Unknown";
  5597. char *fec = "";
  5598. char *req_fec = "";
  5599. char *an = "";
  5600. new_speed = pf->hw.phy.link_info.link_speed;
  5601. if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed))
  5602. return;
  5603. vsi->current_isup = isup;
  5604. vsi->current_speed = new_speed;
  5605. if (!isup) {
  5606. netdev_info(vsi->netdev, "NIC Link is Down\n");
  5607. return;
  5608. }
  5609. /* Warn user if link speed on NPAR enabled partition is not at
  5610. * least 10GB
  5611. */
  5612. if (pf->hw.func_caps.npar_enable &&
  5613. (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
  5614. pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
  5615. netdev_warn(vsi->netdev,
  5616. "The partition detected link speed that is less than 10Gbps\n");
  5617. switch (pf->hw.phy.link_info.link_speed) {
  5618. case I40E_LINK_SPEED_40GB:
  5619. speed = "40 G";
  5620. break;
  5621. case I40E_LINK_SPEED_20GB:
  5622. speed = "20 G";
  5623. break;
  5624. case I40E_LINK_SPEED_25GB:
  5625. speed = "25 G";
  5626. break;
  5627. case I40E_LINK_SPEED_10GB:
  5628. speed = "10 G";
  5629. break;
  5630. case I40E_LINK_SPEED_1GB:
  5631. speed = "1000 M";
  5632. break;
  5633. case I40E_LINK_SPEED_100MB:
  5634. speed = "100 M";
  5635. break;
  5636. default:
  5637. break;
  5638. }
  5639. switch (pf->hw.fc.current_mode) {
  5640. case I40E_FC_FULL:
  5641. fc = "RX/TX";
  5642. break;
  5643. case I40E_FC_TX_PAUSE:
  5644. fc = "TX";
  5645. break;
  5646. case I40E_FC_RX_PAUSE:
  5647. fc = "RX";
  5648. break;
  5649. default:
  5650. fc = "None";
  5651. break;
  5652. }
  5653. if (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) {
  5654. req_fec = ", Requested FEC: None";
  5655. fec = ", FEC: None";
  5656. an = ", Autoneg: False";
  5657. if (pf->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED)
  5658. an = ", Autoneg: True";
  5659. if (pf->hw.phy.link_info.fec_info &
  5660. I40E_AQ_CONFIG_FEC_KR_ENA)
  5661. fec = ", FEC: CL74 FC-FEC/BASE-R";
  5662. else if (pf->hw.phy.link_info.fec_info &
  5663. I40E_AQ_CONFIG_FEC_RS_ENA)
  5664. fec = ", FEC: CL108 RS-FEC";
  5665. /* 'CL108 RS-FEC' should be displayed when RS is requested, or
  5666. * both RS and FC are requested
  5667. */
  5668. if (vsi->back->hw.phy.link_info.req_fec_info &
  5669. (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS)) {
  5670. if (vsi->back->hw.phy.link_info.req_fec_info &
  5671. I40E_AQ_REQUEST_FEC_RS)
  5672. req_fec = ", Requested FEC: CL108 RS-FEC";
  5673. else
  5674. req_fec = ", Requested FEC: CL74 FC-FEC/BASE-R";
  5675. }
  5676. }
  5677. netdev_info(vsi->netdev, "NIC Link is Up, %sbps Full Duplex%s%s%s, Flow Control: %s\n",
  5678. speed, req_fec, fec, an, fc);
  5679. }
  5680. /**
  5681. * i40e_up_complete - Finish the last steps of bringing up a connection
  5682. * @vsi: the VSI being configured
  5683. **/
  5684. static int i40e_up_complete(struct i40e_vsi *vsi)
  5685. {
  5686. struct i40e_pf *pf = vsi->back;
  5687. int err;
  5688. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  5689. i40e_vsi_configure_msix(vsi);
  5690. else
  5691. i40e_configure_msi_and_legacy(vsi);
  5692. /* start rings */
  5693. err = i40e_vsi_start_rings(vsi);
  5694. if (err)
  5695. return err;
  5696. clear_bit(__I40E_VSI_DOWN, vsi->state);
  5697. i40e_napi_enable_all(vsi);
  5698. i40e_vsi_enable_irq(vsi);
  5699. if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
  5700. (vsi->netdev)) {
  5701. i40e_print_link_message(vsi, true);
  5702. netif_tx_start_all_queues(vsi->netdev);
  5703. netif_carrier_on(vsi->netdev);
  5704. }
  5705. /* replay FDIR SB filters */
  5706. if (vsi->type == I40E_VSI_FDIR) {
  5707. /* reset fd counters */
  5708. pf->fd_add_err = 0;
  5709. pf->fd_atr_cnt = 0;
  5710. i40e_fdir_filter_restore(vsi);
  5711. }
  5712. /* On the next run of the service_task, notify any clients of the new
  5713. * opened netdev
  5714. */
  5715. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  5716. i40e_service_event_schedule(pf);
  5717. return 0;
  5718. }
  5719. /**
  5720. * i40e_vsi_reinit_locked - Reset the VSI
  5721. * @vsi: the VSI being configured
  5722. *
  5723. * Rebuild the ring structs after some configuration
  5724. * has changed, e.g. MTU size.
  5725. **/
  5726. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
  5727. {
  5728. struct i40e_pf *pf = vsi->back;
  5729. WARN_ON(in_interrupt());
  5730. while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state))
  5731. usleep_range(1000, 2000);
  5732. i40e_down(vsi);
  5733. i40e_up(vsi);
  5734. clear_bit(__I40E_CONFIG_BUSY, pf->state);
  5735. }
  5736. /**
  5737. * i40e_up - Bring the connection back up after being down
  5738. * @vsi: the VSI being configured
  5739. **/
  5740. int i40e_up(struct i40e_vsi *vsi)
  5741. {
  5742. int err;
  5743. err = i40e_vsi_configure(vsi);
  5744. if (!err)
  5745. err = i40e_up_complete(vsi);
  5746. return err;
  5747. }
  5748. /**
  5749. * i40e_down - Shutdown the connection processing
  5750. * @vsi: the VSI being stopped
  5751. **/
  5752. void i40e_down(struct i40e_vsi *vsi)
  5753. {
  5754. int i;
  5755. /* It is assumed that the caller of this function
  5756. * sets the vsi->state __I40E_VSI_DOWN bit.
  5757. */
  5758. if (vsi->netdev) {
  5759. netif_carrier_off(vsi->netdev);
  5760. netif_tx_disable(vsi->netdev);
  5761. }
  5762. i40e_vsi_disable_irq(vsi);
  5763. i40e_vsi_stop_rings(vsi);
  5764. i40e_napi_disable_all(vsi);
  5765. for (i = 0; i < vsi->num_queue_pairs; i++) {
  5766. i40e_clean_tx_ring(vsi->tx_rings[i]);
  5767. if (i40e_enabled_xdp_vsi(vsi))
  5768. i40e_clean_tx_ring(vsi->xdp_rings[i]);
  5769. i40e_clean_rx_ring(vsi->rx_rings[i]);
  5770. }
  5771. }
  5772. /**
  5773. * i40e_validate_mqprio_qopt- validate queue mapping info
  5774. * @vsi: the VSI being configured
  5775. * @mqprio_qopt: queue parametrs
  5776. **/
  5777. static int i40e_validate_mqprio_qopt(struct i40e_vsi *vsi,
  5778. struct tc_mqprio_qopt_offload *mqprio_qopt)
  5779. {
  5780. u64 sum_max_rate = 0;
  5781. u64 max_rate = 0;
  5782. int i;
  5783. if (mqprio_qopt->qopt.offset[0] != 0 ||
  5784. mqprio_qopt->qopt.num_tc < 1 ||
  5785. mqprio_qopt->qopt.num_tc > I40E_MAX_TRAFFIC_CLASS)
  5786. return -EINVAL;
  5787. for (i = 0; ; i++) {
  5788. if (!mqprio_qopt->qopt.count[i])
  5789. return -EINVAL;
  5790. if (mqprio_qopt->min_rate[i]) {
  5791. dev_err(&vsi->back->pdev->dev,
  5792. "Invalid min tx rate (greater than 0) specified\n");
  5793. return -EINVAL;
  5794. }
  5795. max_rate = mqprio_qopt->max_rate[i];
  5796. do_div(max_rate, I40E_BW_MBPS_DIVISOR);
  5797. sum_max_rate += max_rate;
  5798. if (i >= mqprio_qopt->qopt.num_tc - 1)
  5799. break;
  5800. if (mqprio_qopt->qopt.offset[i + 1] !=
  5801. (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i]))
  5802. return -EINVAL;
  5803. }
  5804. if (vsi->num_queue_pairs <
  5805. (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i])) {
  5806. return -EINVAL;
  5807. }
  5808. if (sum_max_rate > i40e_get_link_speed(vsi)) {
  5809. dev_err(&vsi->back->pdev->dev,
  5810. "Invalid max tx rate specified\n");
  5811. return -EINVAL;
  5812. }
  5813. return 0;
  5814. }
  5815. /**
  5816. * i40e_vsi_set_default_tc_config - set default values for tc configuration
  5817. * @vsi: the VSI being configured
  5818. **/
  5819. static void i40e_vsi_set_default_tc_config(struct i40e_vsi *vsi)
  5820. {
  5821. u16 qcount;
  5822. int i;
  5823. /* Only TC0 is enabled */
  5824. vsi->tc_config.numtc = 1;
  5825. vsi->tc_config.enabled_tc = 1;
  5826. qcount = min_t(int, vsi->alloc_queue_pairs,
  5827. i40e_pf_get_max_q_per_tc(vsi->back));
  5828. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5829. /* For the TC that is not enabled set the offset to to default
  5830. * queue and allocate one queue for the given TC.
  5831. */
  5832. vsi->tc_config.tc_info[i].qoffset = 0;
  5833. if (i == 0)
  5834. vsi->tc_config.tc_info[i].qcount = qcount;
  5835. else
  5836. vsi->tc_config.tc_info[i].qcount = 1;
  5837. vsi->tc_config.tc_info[i].netdev_tc = 0;
  5838. }
  5839. }
  5840. /**
  5841. * i40e_setup_tc - configure multiple traffic classes
  5842. * @netdev: net device to configure
  5843. * @type_data: tc offload data
  5844. **/
  5845. static int i40e_setup_tc(struct net_device *netdev, void *type_data)
  5846. {
  5847. struct tc_mqprio_qopt_offload *mqprio_qopt = type_data;
  5848. struct i40e_netdev_priv *np = netdev_priv(netdev);
  5849. struct i40e_vsi *vsi = np->vsi;
  5850. struct i40e_pf *pf = vsi->back;
  5851. u8 enabled_tc = 0, num_tc, hw;
  5852. bool need_reset = false;
  5853. int ret = -EINVAL;
  5854. u16 mode;
  5855. int i;
  5856. num_tc = mqprio_qopt->qopt.num_tc;
  5857. hw = mqprio_qopt->qopt.hw;
  5858. mode = mqprio_qopt->mode;
  5859. if (!hw) {
  5860. pf->flags &= ~I40E_FLAG_TC_MQPRIO;
  5861. memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt));
  5862. goto config_tc;
  5863. }
  5864. /* Check if MFP enabled */
  5865. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  5866. netdev_info(netdev,
  5867. "Configuring TC not supported in MFP mode\n");
  5868. return ret;
  5869. }
  5870. switch (mode) {
  5871. case TC_MQPRIO_MODE_DCB:
  5872. pf->flags &= ~I40E_FLAG_TC_MQPRIO;
  5873. /* Check if DCB enabled to continue */
  5874. if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  5875. netdev_info(netdev,
  5876. "DCB is not enabled for adapter\n");
  5877. return ret;
  5878. }
  5879. /* Check whether tc count is within enabled limit */
  5880. if (num_tc > i40e_pf_get_num_tc(pf)) {
  5881. netdev_info(netdev,
  5882. "TC count greater than enabled on link for adapter\n");
  5883. return ret;
  5884. }
  5885. break;
  5886. case TC_MQPRIO_MODE_CHANNEL:
  5887. if (pf->flags & I40E_FLAG_DCB_ENABLED) {
  5888. netdev_info(netdev,
  5889. "Full offload of TC Mqprio options is not supported when DCB is enabled\n");
  5890. return ret;
  5891. }
  5892. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  5893. return ret;
  5894. ret = i40e_validate_mqprio_qopt(vsi, mqprio_qopt);
  5895. if (ret)
  5896. return ret;
  5897. memcpy(&vsi->mqprio_qopt, mqprio_qopt,
  5898. sizeof(*mqprio_qopt));
  5899. pf->flags |= I40E_FLAG_TC_MQPRIO;
  5900. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  5901. break;
  5902. default:
  5903. return -EINVAL;
  5904. }
  5905. config_tc:
  5906. /* Generate TC map for number of tc requested */
  5907. for (i = 0; i < num_tc; i++)
  5908. enabled_tc |= BIT(i);
  5909. /* Requesting same TC configuration as already enabled */
  5910. if (enabled_tc == vsi->tc_config.enabled_tc &&
  5911. mode != TC_MQPRIO_MODE_CHANNEL)
  5912. return 0;
  5913. /* Quiesce VSI queues */
  5914. i40e_quiesce_vsi(vsi);
  5915. if (!hw && !(pf->flags & I40E_FLAG_TC_MQPRIO))
  5916. i40e_remove_queue_channels(vsi);
  5917. /* Configure VSI for enabled TCs */
  5918. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  5919. if (ret) {
  5920. netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
  5921. vsi->seid);
  5922. need_reset = true;
  5923. goto exit;
  5924. }
  5925. if (pf->flags & I40E_FLAG_TC_MQPRIO) {
  5926. if (vsi->mqprio_qopt.max_rate[0]) {
  5927. u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
  5928. do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
  5929. ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
  5930. if (!ret) {
  5931. u64 credits = max_tx_rate;
  5932. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  5933. dev_dbg(&vsi->back->pdev->dev,
  5934. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  5935. max_tx_rate,
  5936. credits,
  5937. vsi->seid);
  5938. } else {
  5939. need_reset = true;
  5940. goto exit;
  5941. }
  5942. }
  5943. ret = i40e_configure_queue_channels(vsi);
  5944. if (ret) {
  5945. netdev_info(netdev,
  5946. "Failed configuring queue channels\n");
  5947. need_reset = true;
  5948. goto exit;
  5949. }
  5950. }
  5951. exit:
  5952. /* Reset the configuration data to defaults, only TC0 is enabled */
  5953. if (need_reset) {
  5954. i40e_vsi_set_default_tc_config(vsi);
  5955. need_reset = false;
  5956. }
  5957. /* Unquiesce VSI */
  5958. i40e_unquiesce_vsi(vsi);
  5959. return ret;
  5960. }
  5961. /**
  5962. * i40e_set_cld_element - sets cloud filter element data
  5963. * @filter: cloud filter rule
  5964. * @cld: ptr to cloud filter element data
  5965. *
  5966. * This is helper function to copy data into cloud filter element
  5967. **/
  5968. static inline void
  5969. i40e_set_cld_element(struct i40e_cloud_filter *filter,
  5970. struct i40e_aqc_cloud_filters_element_data *cld)
  5971. {
  5972. int i, j;
  5973. u32 ipa;
  5974. memset(cld, 0, sizeof(*cld));
  5975. ether_addr_copy(cld->outer_mac, filter->dst_mac);
  5976. ether_addr_copy(cld->inner_mac, filter->src_mac);
  5977. if (filter->n_proto != ETH_P_IP && filter->n_proto != ETH_P_IPV6)
  5978. return;
  5979. if (filter->n_proto == ETH_P_IPV6) {
  5980. #define IPV6_MAX_INDEX (ARRAY_SIZE(filter->dst_ipv6) - 1)
  5981. for (i = 0, j = 0; i < ARRAY_SIZE(filter->dst_ipv6);
  5982. i++, j += 2) {
  5983. ipa = be32_to_cpu(filter->dst_ipv6[IPV6_MAX_INDEX - i]);
  5984. ipa = cpu_to_le32(ipa);
  5985. memcpy(&cld->ipaddr.raw_v6.data[j], &ipa, sizeof(ipa));
  5986. }
  5987. } else {
  5988. ipa = be32_to_cpu(filter->dst_ipv4);
  5989. memcpy(&cld->ipaddr.v4.data, &ipa, sizeof(ipa));
  5990. }
  5991. cld->inner_vlan = cpu_to_le16(ntohs(filter->vlan_id));
  5992. /* tenant_id is not supported by FW now, once the support is enabled
  5993. * fill the cld->tenant_id with cpu_to_le32(filter->tenant_id)
  5994. */
  5995. if (filter->tenant_id)
  5996. return;
  5997. }
  5998. /**
  5999. * i40e_add_del_cloud_filter - Add/del cloud filter
  6000. * @vsi: pointer to VSI
  6001. * @filter: cloud filter rule
  6002. * @add: if true, add, if false, delete
  6003. *
  6004. * Add or delete a cloud filter for a specific flow spec.
  6005. * Returns 0 if the filter were successfully added.
  6006. **/
  6007. static int i40e_add_del_cloud_filter(struct i40e_vsi *vsi,
  6008. struct i40e_cloud_filter *filter, bool add)
  6009. {
  6010. struct i40e_aqc_cloud_filters_element_data cld_filter;
  6011. struct i40e_pf *pf = vsi->back;
  6012. int ret;
  6013. static const u16 flag_table[128] = {
  6014. [I40E_CLOUD_FILTER_FLAGS_OMAC] =
  6015. I40E_AQC_ADD_CLOUD_FILTER_OMAC,
  6016. [I40E_CLOUD_FILTER_FLAGS_IMAC] =
  6017. I40E_AQC_ADD_CLOUD_FILTER_IMAC,
  6018. [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN] =
  6019. I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN,
  6020. [I40E_CLOUD_FILTER_FLAGS_IMAC_TEN_ID] =
  6021. I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID,
  6022. [I40E_CLOUD_FILTER_FLAGS_OMAC_TEN_ID_IMAC] =
  6023. I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC,
  6024. [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN_TEN_ID] =
  6025. I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID,
  6026. [I40E_CLOUD_FILTER_FLAGS_IIP] =
  6027. I40E_AQC_ADD_CLOUD_FILTER_IIP,
  6028. };
  6029. if (filter->flags >= ARRAY_SIZE(flag_table))
  6030. return I40E_ERR_CONFIG;
  6031. /* copy element needed to add cloud filter from filter */
  6032. i40e_set_cld_element(filter, &cld_filter);
  6033. if (filter->tunnel_type != I40E_CLOUD_TNL_TYPE_NONE)
  6034. cld_filter.flags = cpu_to_le16(filter->tunnel_type <<
  6035. I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT);
  6036. if (filter->n_proto == ETH_P_IPV6)
  6037. cld_filter.flags |= cpu_to_le16(flag_table[filter->flags] |
  6038. I40E_AQC_ADD_CLOUD_FLAGS_IPV6);
  6039. else
  6040. cld_filter.flags |= cpu_to_le16(flag_table[filter->flags] |
  6041. I40E_AQC_ADD_CLOUD_FLAGS_IPV4);
  6042. if (add)
  6043. ret = i40e_aq_add_cloud_filters(&pf->hw, filter->seid,
  6044. &cld_filter, 1);
  6045. else
  6046. ret = i40e_aq_rem_cloud_filters(&pf->hw, filter->seid,
  6047. &cld_filter, 1);
  6048. if (ret)
  6049. dev_dbg(&pf->pdev->dev,
  6050. "Failed to %s cloud filter using l4 port %u, err %d aq_err %d\n",
  6051. add ? "add" : "delete", filter->dst_port, ret,
  6052. pf->hw.aq.asq_last_status);
  6053. else
  6054. dev_info(&pf->pdev->dev,
  6055. "%s cloud filter for VSI: %d\n",
  6056. add ? "Added" : "Deleted", filter->seid);
  6057. return ret;
  6058. }
  6059. /**
  6060. * i40e_add_del_cloud_filter_big_buf - Add/del cloud filter using big_buf
  6061. * @vsi: pointer to VSI
  6062. * @filter: cloud filter rule
  6063. * @add: if true, add, if false, delete
  6064. *
  6065. * Add or delete a cloud filter for a specific flow spec using big buffer.
  6066. * Returns 0 if the filter were successfully added.
  6067. **/
  6068. static int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi *vsi,
  6069. struct i40e_cloud_filter *filter,
  6070. bool add)
  6071. {
  6072. struct i40e_aqc_cloud_filters_element_bb cld_filter;
  6073. struct i40e_pf *pf = vsi->back;
  6074. int ret;
  6075. /* Both (src/dst) valid mac_addr are not supported */
  6076. if ((is_valid_ether_addr(filter->dst_mac) &&
  6077. is_valid_ether_addr(filter->src_mac)) ||
  6078. (is_multicast_ether_addr(filter->dst_mac) &&
  6079. is_multicast_ether_addr(filter->src_mac)))
  6080. return -EOPNOTSUPP;
  6081. /* Big buffer cloud filter needs 'L4 port' to be non-zero. Also, UDP
  6082. * ports are not supported via big buffer now.
  6083. */
  6084. if (!filter->dst_port || filter->ip_proto == IPPROTO_UDP)
  6085. return -EOPNOTSUPP;
  6086. /* adding filter using src_port/src_ip is not supported at this stage */
  6087. if (filter->src_port || filter->src_ipv4 ||
  6088. !ipv6_addr_any(&filter->ip.v6.src_ip6))
  6089. return -EOPNOTSUPP;
  6090. /* copy element needed to add cloud filter from filter */
  6091. i40e_set_cld_element(filter, &cld_filter.element);
  6092. if (is_valid_ether_addr(filter->dst_mac) ||
  6093. is_valid_ether_addr(filter->src_mac) ||
  6094. is_multicast_ether_addr(filter->dst_mac) ||
  6095. is_multicast_ether_addr(filter->src_mac)) {
  6096. /* MAC + IP : unsupported mode */
  6097. if (filter->dst_ipv4)
  6098. return -EOPNOTSUPP;
  6099. /* since we validated that L4 port must be valid before
  6100. * we get here, start with respective "flags" value
  6101. * and update if vlan is present or not
  6102. */
  6103. cld_filter.element.flags =
  6104. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_PORT);
  6105. if (filter->vlan_id) {
  6106. cld_filter.element.flags =
  6107. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_VLAN_PORT);
  6108. }
  6109. } else if (filter->dst_ipv4 ||
  6110. !ipv6_addr_any(&filter->ip.v6.dst_ip6)) {
  6111. cld_filter.element.flags =
  6112. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_IP_PORT);
  6113. if (filter->n_proto == ETH_P_IPV6)
  6114. cld_filter.element.flags |=
  6115. cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV6);
  6116. else
  6117. cld_filter.element.flags |=
  6118. cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV4);
  6119. } else {
  6120. dev_err(&pf->pdev->dev,
  6121. "either mac or ip has to be valid for cloud filter\n");
  6122. return -EINVAL;
  6123. }
  6124. /* Now copy L4 port in Byte 6..7 in general fields */
  6125. cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X16_WORD0] =
  6126. be16_to_cpu(filter->dst_port);
  6127. if (add) {
  6128. /* Validate current device switch mode, change if necessary */
  6129. ret = i40e_validate_and_set_switch_mode(vsi);
  6130. if (ret) {
  6131. dev_err(&pf->pdev->dev,
  6132. "failed to set switch mode, ret %d\n",
  6133. ret);
  6134. return ret;
  6135. }
  6136. ret = i40e_aq_add_cloud_filters_bb(&pf->hw, filter->seid,
  6137. &cld_filter, 1);
  6138. } else {
  6139. ret = i40e_aq_rem_cloud_filters_bb(&pf->hw, filter->seid,
  6140. &cld_filter, 1);
  6141. }
  6142. if (ret)
  6143. dev_dbg(&pf->pdev->dev,
  6144. "Failed to %s cloud filter(big buffer) err %d aq_err %d\n",
  6145. add ? "add" : "delete", ret, pf->hw.aq.asq_last_status);
  6146. else
  6147. dev_info(&pf->pdev->dev,
  6148. "%s cloud filter for VSI: %d, L4 port: %d\n",
  6149. add ? "add" : "delete", filter->seid,
  6150. ntohs(filter->dst_port));
  6151. return ret;
  6152. }
  6153. /**
  6154. * i40e_parse_cls_flower - Parse tc flower filters provided by kernel
  6155. * @vsi: Pointer to VSI
  6156. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6157. * @filter: Pointer to cloud filter structure
  6158. *
  6159. **/
  6160. static int i40e_parse_cls_flower(struct i40e_vsi *vsi,
  6161. struct tc_cls_flower_offload *f,
  6162. struct i40e_cloud_filter *filter)
  6163. {
  6164. u16 n_proto_mask = 0, n_proto_key = 0, addr_type = 0;
  6165. struct i40e_pf *pf = vsi->back;
  6166. u8 field_flags = 0;
  6167. if (f->dissector->used_keys &
  6168. ~(BIT(FLOW_DISSECTOR_KEY_CONTROL) |
  6169. BIT(FLOW_DISSECTOR_KEY_BASIC) |
  6170. BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) |
  6171. BIT(FLOW_DISSECTOR_KEY_VLAN) |
  6172. BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
  6173. BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
  6174. BIT(FLOW_DISSECTOR_KEY_PORTS) |
  6175. BIT(FLOW_DISSECTOR_KEY_ENC_KEYID))) {
  6176. dev_err(&pf->pdev->dev, "Unsupported key used: 0x%x\n",
  6177. f->dissector->used_keys);
  6178. return -EOPNOTSUPP;
  6179. }
  6180. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ENC_KEYID)) {
  6181. struct flow_dissector_key_keyid *key =
  6182. skb_flow_dissector_target(f->dissector,
  6183. FLOW_DISSECTOR_KEY_ENC_KEYID,
  6184. f->key);
  6185. struct flow_dissector_key_keyid *mask =
  6186. skb_flow_dissector_target(f->dissector,
  6187. FLOW_DISSECTOR_KEY_ENC_KEYID,
  6188. f->mask);
  6189. if (mask->keyid != 0)
  6190. field_flags |= I40E_CLOUD_FIELD_TEN_ID;
  6191. filter->tenant_id = be32_to_cpu(key->keyid);
  6192. }
  6193. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_BASIC)) {
  6194. struct flow_dissector_key_basic *key =
  6195. skb_flow_dissector_target(f->dissector,
  6196. FLOW_DISSECTOR_KEY_BASIC,
  6197. f->key);
  6198. struct flow_dissector_key_basic *mask =
  6199. skb_flow_dissector_target(f->dissector,
  6200. FLOW_DISSECTOR_KEY_BASIC,
  6201. f->mask);
  6202. n_proto_key = ntohs(key->n_proto);
  6203. n_proto_mask = ntohs(mask->n_proto);
  6204. if (n_proto_key == ETH_P_ALL) {
  6205. n_proto_key = 0;
  6206. n_proto_mask = 0;
  6207. }
  6208. filter->n_proto = n_proto_key & n_proto_mask;
  6209. filter->ip_proto = key->ip_proto;
  6210. }
  6211. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
  6212. struct flow_dissector_key_eth_addrs *key =
  6213. skb_flow_dissector_target(f->dissector,
  6214. FLOW_DISSECTOR_KEY_ETH_ADDRS,
  6215. f->key);
  6216. struct flow_dissector_key_eth_addrs *mask =
  6217. skb_flow_dissector_target(f->dissector,
  6218. FLOW_DISSECTOR_KEY_ETH_ADDRS,
  6219. f->mask);
  6220. /* use is_broadcast and is_zero to check for all 0xf or 0 */
  6221. if (!is_zero_ether_addr(mask->dst)) {
  6222. if (is_broadcast_ether_addr(mask->dst)) {
  6223. field_flags |= I40E_CLOUD_FIELD_OMAC;
  6224. } else {
  6225. dev_err(&pf->pdev->dev, "Bad ether dest mask %pM\n",
  6226. mask->dst);
  6227. return I40E_ERR_CONFIG;
  6228. }
  6229. }
  6230. if (!is_zero_ether_addr(mask->src)) {
  6231. if (is_broadcast_ether_addr(mask->src)) {
  6232. field_flags |= I40E_CLOUD_FIELD_IMAC;
  6233. } else {
  6234. dev_err(&pf->pdev->dev, "Bad ether src mask %pM\n",
  6235. mask->src);
  6236. return I40E_ERR_CONFIG;
  6237. }
  6238. }
  6239. ether_addr_copy(filter->dst_mac, key->dst);
  6240. ether_addr_copy(filter->src_mac, key->src);
  6241. }
  6242. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_VLAN)) {
  6243. struct flow_dissector_key_vlan *key =
  6244. skb_flow_dissector_target(f->dissector,
  6245. FLOW_DISSECTOR_KEY_VLAN,
  6246. f->key);
  6247. struct flow_dissector_key_vlan *mask =
  6248. skb_flow_dissector_target(f->dissector,
  6249. FLOW_DISSECTOR_KEY_VLAN,
  6250. f->mask);
  6251. if (mask->vlan_id) {
  6252. if (mask->vlan_id == VLAN_VID_MASK) {
  6253. field_flags |= I40E_CLOUD_FIELD_IVLAN;
  6254. } else {
  6255. dev_err(&pf->pdev->dev, "Bad vlan mask 0x%04x\n",
  6256. mask->vlan_id);
  6257. return I40E_ERR_CONFIG;
  6258. }
  6259. }
  6260. filter->vlan_id = cpu_to_be16(key->vlan_id);
  6261. }
  6262. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_CONTROL)) {
  6263. struct flow_dissector_key_control *key =
  6264. skb_flow_dissector_target(f->dissector,
  6265. FLOW_DISSECTOR_KEY_CONTROL,
  6266. f->key);
  6267. addr_type = key->addr_type;
  6268. }
  6269. if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
  6270. struct flow_dissector_key_ipv4_addrs *key =
  6271. skb_flow_dissector_target(f->dissector,
  6272. FLOW_DISSECTOR_KEY_IPV4_ADDRS,
  6273. f->key);
  6274. struct flow_dissector_key_ipv4_addrs *mask =
  6275. skb_flow_dissector_target(f->dissector,
  6276. FLOW_DISSECTOR_KEY_IPV4_ADDRS,
  6277. f->mask);
  6278. if (mask->dst) {
  6279. if (mask->dst == cpu_to_be32(0xffffffff)) {
  6280. field_flags |= I40E_CLOUD_FIELD_IIP;
  6281. } else {
  6282. mask->dst = be32_to_cpu(mask->dst);
  6283. dev_err(&pf->pdev->dev, "Bad ip dst mask %pI4\n",
  6284. &mask->dst);
  6285. return I40E_ERR_CONFIG;
  6286. }
  6287. }
  6288. if (mask->src) {
  6289. if (mask->src == cpu_to_be32(0xffffffff)) {
  6290. field_flags |= I40E_CLOUD_FIELD_IIP;
  6291. } else {
  6292. mask->src = be32_to_cpu(mask->src);
  6293. dev_err(&pf->pdev->dev, "Bad ip src mask %pI4\n",
  6294. &mask->src);
  6295. return I40E_ERR_CONFIG;
  6296. }
  6297. }
  6298. if (field_flags & I40E_CLOUD_FIELD_TEN_ID) {
  6299. dev_err(&pf->pdev->dev, "Tenant id not allowed for ip filter\n");
  6300. return I40E_ERR_CONFIG;
  6301. }
  6302. filter->dst_ipv4 = key->dst;
  6303. filter->src_ipv4 = key->src;
  6304. }
  6305. if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
  6306. struct flow_dissector_key_ipv6_addrs *key =
  6307. skb_flow_dissector_target(f->dissector,
  6308. FLOW_DISSECTOR_KEY_IPV6_ADDRS,
  6309. f->key);
  6310. struct flow_dissector_key_ipv6_addrs *mask =
  6311. skb_flow_dissector_target(f->dissector,
  6312. FLOW_DISSECTOR_KEY_IPV6_ADDRS,
  6313. f->mask);
  6314. /* src and dest IPV6 address should not be LOOPBACK
  6315. * (0:0:0:0:0:0:0:1), which can be represented as ::1
  6316. */
  6317. if (ipv6_addr_loopback(&key->dst) ||
  6318. ipv6_addr_loopback(&key->src)) {
  6319. dev_err(&pf->pdev->dev,
  6320. "Bad ipv6, addr is LOOPBACK\n");
  6321. return I40E_ERR_CONFIG;
  6322. }
  6323. if (!ipv6_addr_any(&mask->dst) || !ipv6_addr_any(&mask->src))
  6324. field_flags |= I40E_CLOUD_FIELD_IIP;
  6325. memcpy(&filter->src_ipv6, &key->src.s6_addr32,
  6326. sizeof(filter->src_ipv6));
  6327. memcpy(&filter->dst_ipv6, &key->dst.s6_addr32,
  6328. sizeof(filter->dst_ipv6));
  6329. }
  6330. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_PORTS)) {
  6331. struct flow_dissector_key_ports *key =
  6332. skb_flow_dissector_target(f->dissector,
  6333. FLOW_DISSECTOR_KEY_PORTS,
  6334. f->key);
  6335. struct flow_dissector_key_ports *mask =
  6336. skb_flow_dissector_target(f->dissector,
  6337. FLOW_DISSECTOR_KEY_PORTS,
  6338. f->mask);
  6339. if (mask->src) {
  6340. if (mask->src == cpu_to_be16(0xffff)) {
  6341. field_flags |= I40E_CLOUD_FIELD_IIP;
  6342. } else {
  6343. dev_err(&pf->pdev->dev, "Bad src port mask 0x%04x\n",
  6344. be16_to_cpu(mask->src));
  6345. return I40E_ERR_CONFIG;
  6346. }
  6347. }
  6348. if (mask->dst) {
  6349. if (mask->dst == cpu_to_be16(0xffff)) {
  6350. field_flags |= I40E_CLOUD_FIELD_IIP;
  6351. } else {
  6352. dev_err(&pf->pdev->dev, "Bad dst port mask 0x%04x\n",
  6353. be16_to_cpu(mask->dst));
  6354. return I40E_ERR_CONFIG;
  6355. }
  6356. }
  6357. filter->dst_port = key->dst;
  6358. filter->src_port = key->src;
  6359. switch (filter->ip_proto) {
  6360. case IPPROTO_TCP:
  6361. case IPPROTO_UDP:
  6362. break;
  6363. default:
  6364. dev_err(&pf->pdev->dev,
  6365. "Only UDP and TCP transport are supported\n");
  6366. return -EINVAL;
  6367. }
  6368. }
  6369. filter->flags = field_flags;
  6370. return 0;
  6371. }
  6372. /**
  6373. * i40e_handle_tclass: Forward to a traffic class on the device
  6374. * @vsi: Pointer to VSI
  6375. * @tc: traffic class index on the device
  6376. * @filter: Pointer to cloud filter structure
  6377. *
  6378. **/
  6379. static int i40e_handle_tclass(struct i40e_vsi *vsi, u32 tc,
  6380. struct i40e_cloud_filter *filter)
  6381. {
  6382. struct i40e_channel *ch, *ch_tmp;
  6383. /* direct to a traffic class on the same device */
  6384. if (tc == 0) {
  6385. filter->seid = vsi->seid;
  6386. return 0;
  6387. } else if (vsi->tc_config.enabled_tc & BIT(tc)) {
  6388. if (!filter->dst_port) {
  6389. dev_err(&vsi->back->pdev->dev,
  6390. "Specify destination port to direct to traffic class that is not default\n");
  6391. return -EINVAL;
  6392. }
  6393. if (list_empty(&vsi->ch_list))
  6394. return -EINVAL;
  6395. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list,
  6396. list) {
  6397. if (ch->seid == vsi->tc_seid_map[tc])
  6398. filter->seid = ch->seid;
  6399. }
  6400. return 0;
  6401. }
  6402. dev_err(&vsi->back->pdev->dev, "TC is not enabled\n");
  6403. return -EINVAL;
  6404. }
  6405. /**
  6406. * i40e_configure_clsflower - Configure tc flower filters
  6407. * @vsi: Pointer to VSI
  6408. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6409. *
  6410. **/
  6411. static int i40e_configure_clsflower(struct i40e_vsi *vsi,
  6412. struct tc_cls_flower_offload *cls_flower)
  6413. {
  6414. int tc = tc_classid_to_hwtc(vsi->netdev, cls_flower->classid);
  6415. struct i40e_cloud_filter *filter = NULL;
  6416. struct i40e_pf *pf = vsi->back;
  6417. int err = 0;
  6418. if (tc < 0) {
  6419. dev_err(&vsi->back->pdev->dev, "Invalid traffic class\n");
  6420. return -EOPNOTSUPP;
  6421. }
  6422. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
  6423. test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
  6424. return -EBUSY;
  6425. if (pf->fdir_pf_active_filters ||
  6426. (!hlist_empty(&pf->fdir_filter_list))) {
  6427. dev_err(&vsi->back->pdev->dev,
  6428. "Flow Director Sideband filters exists, turn ntuple off to configure cloud filters\n");
  6429. return -EINVAL;
  6430. }
  6431. if (vsi->back->flags & I40E_FLAG_FD_SB_ENABLED) {
  6432. dev_err(&vsi->back->pdev->dev,
  6433. "Disable Flow Director Sideband, configuring Cloud filters via tc-flower\n");
  6434. vsi->back->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  6435. vsi->back->flags |= I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6436. }
  6437. filter = kzalloc(sizeof(*filter), GFP_KERNEL);
  6438. if (!filter)
  6439. return -ENOMEM;
  6440. filter->cookie = cls_flower->cookie;
  6441. err = i40e_parse_cls_flower(vsi, cls_flower, filter);
  6442. if (err < 0)
  6443. goto err;
  6444. err = i40e_handle_tclass(vsi, tc, filter);
  6445. if (err < 0)
  6446. goto err;
  6447. /* Add cloud filter */
  6448. if (filter->dst_port)
  6449. err = i40e_add_del_cloud_filter_big_buf(vsi, filter, true);
  6450. else
  6451. err = i40e_add_del_cloud_filter(vsi, filter, true);
  6452. if (err) {
  6453. dev_err(&pf->pdev->dev,
  6454. "Failed to add cloud filter, err %s\n",
  6455. i40e_stat_str(&pf->hw, err));
  6456. goto err;
  6457. }
  6458. /* add filter to the ordered list */
  6459. INIT_HLIST_NODE(&filter->cloud_node);
  6460. hlist_add_head(&filter->cloud_node, &pf->cloud_filter_list);
  6461. pf->num_cloud_filters++;
  6462. return err;
  6463. err:
  6464. kfree(filter);
  6465. return err;
  6466. }
  6467. /**
  6468. * i40e_find_cloud_filter - Find the could filter in the list
  6469. * @vsi: Pointer to VSI
  6470. * @cookie: filter specific cookie
  6471. *
  6472. **/
  6473. static struct i40e_cloud_filter *i40e_find_cloud_filter(struct i40e_vsi *vsi,
  6474. unsigned long *cookie)
  6475. {
  6476. struct i40e_cloud_filter *filter = NULL;
  6477. struct hlist_node *node2;
  6478. hlist_for_each_entry_safe(filter, node2,
  6479. &vsi->back->cloud_filter_list, cloud_node)
  6480. if (!memcmp(cookie, &filter->cookie, sizeof(filter->cookie)))
  6481. return filter;
  6482. return NULL;
  6483. }
  6484. /**
  6485. * i40e_delete_clsflower - Remove tc flower filters
  6486. * @vsi: Pointer to VSI
  6487. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6488. *
  6489. **/
  6490. static int i40e_delete_clsflower(struct i40e_vsi *vsi,
  6491. struct tc_cls_flower_offload *cls_flower)
  6492. {
  6493. struct i40e_cloud_filter *filter = NULL;
  6494. struct i40e_pf *pf = vsi->back;
  6495. int err = 0;
  6496. filter = i40e_find_cloud_filter(vsi, &cls_flower->cookie);
  6497. if (!filter)
  6498. return -EINVAL;
  6499. hash_del(&filter->cloud_node);
  6500. if (filter->dst_port)
  6501. err = i40e_add_del_cloud_filter_big_buf(vsi, filter, false);
  6502. else
  6503. err = i40e_add_del_cloud_filter(vsi, filter, false);
  6504. kfree(filter);
  6505. if (err) {
  6506. dev_err(&pf->pdev->dev,
  6507. "Failed to delete cloud filter, err %s\n",
  6508. i40e_stat_str(&pf->hw, err));
  6509. return i40e_aq_rc_to_posix(err, pf->hw.aq.asq_last_status);
  6510. }
  6511. pf->num_cloud_filters--;
  6512. if (!pf->num_cloud_filters)
  6513. if ((pf->flags & I40E_FLAG_FD_SB_TO_CLOUD_FILTER) &&
  6514. !(pf->flags & I40E_FLAG_FD_SB_INACTIVE)) {
  6515. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  6516. pf->flags &= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6517. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  6518. }
  6519. return 0;
  6520. }
  6521. /**
  6522. * i40e_setup_tc_cls_flower - flower classifier offloads
  6523. * @netdev: net device to configure
  6524. * @type_data: offload data
  6525. **/
  6526. static int i40e_setup_tc_cls_flower(struct i40e_netdev_priv *np,
  6527. struct tc_cls_flower_offload *cls_flower)
  6528. {
  6529. struct i40e_vsi *vsi = np->vsi;
  6530. switch (cls_flower->command) {
  6531. case TC_CLSFLOWER_REPLACE:
  6532. return i40e_configure_clsflower(vsi, cls_flower);
  6533. case TC_CLSFLOWER_DESTROY:
  6534. return i40e_delete_clsflower(vsi, cls_flower);
  6535. case TC_CLSFLOWER_STATS:
  6536. return -EOPNOTSUPP;
  6537. default:
  6538. return -EINVAL;
  6539. }
  6540. }
  6541. static int i40e_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
  6542. void *cb_priv)
  6543. {
  6544. struct i40e_netdev_priv *np = cb_priv;
  6545. if (!tc_cls_can_offload_and_chain0(np->vsi->netdev, type_data))
  6546. return -EOPNOTSUPP;
  6547. switch (type) {
  6548. case TC_SETUP_CLSFLOWER:
  6549. return i40e_setup_tc_cls_flower(np, type_data);
  6550. default:
  6551. return -EOPNOTSUPP;
  6552. }
  6553. }
  6554. static int i40e_setup_tc_block(struct net_device *dev,
  6555. struct tc_block_offload *f)
  6556. {
  6557. struct i40e_netdev_priv *np = netdev_priv(dev);
  6558. if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
  6559. return -EOPNOTSUPP;
  6560. switch (f->command) {
  6561. case TC_BLOCK_BIND:
  6562. return tcf_block_cb_register(f->block, i40e_setup_tc_block_cb,
  6563. np, np);
  6564. case TC_BLOCK_UNBIND:
  6565. tcf_block_cb_unregister(f->block, i40e_setup_tc_block_cb, np);
  6566. return 0;
  6567. default:
  6568. return -EOPNOTSUPP;
  6569. }
  6570. }
  6571. static int __i40e_setup_tc(struct net_device *netdev, enum tc_setup_type type,
  6572. void *type_data)
  6573. {
  6574. switch (type) {
  6575. case TC_SETUP_QDISC_MQPRIO:
  6576. return i40e_setup_tc(netdev, type_data);
  6577. case TC_SETUP_BLOCK:
  6578. return i40e_setup_tc_block(netdev, type_data);
  6579. default:
  6580. return -EOPNOTSUPP;
  6581. }
  6582. }
  6583. /**
  6584. * i40e_open - Called when a network interface is made active
  6585. * @netdev: network interface device structure
  6586. *
  6587. * The open entry point is called when a network interface is made
  6588. * active by the system (IFF_UP). At this point all resources needed
  6589. * for transmit and receive operations are allocated, the interrupt
  6590. * handler is registered with the OS, the netdev watchdog subtask is
  6591. * enabled, and the stack is notified that the interface is ready.
  6592. *
  6593. * Returns 0 on success, negative value on failure
  6594. **/
  6595. int i40e_open(struct net_device *netdev)
  6596. {
  6597. struct i40e_netdev_priv *np = netdev_priv(netdev);
  6598. struct i40e_vsi *vsi = np->vsi;
  6599. struct i40e_pf *pf = vsi->back;
  6600. int err;
  6601. /* disallow open during test or if eeprom is broken */
  6602. if (test_bit(__I40E_TESTING, pf->state) ||
  6603. test_bit(__I40E_BAD_EEPROM, pf->state))
  6604. return -EBUSY;
  6605. netif_carrier_off(netdev);
  6606. err = i40e_vsi_open(vsi);
  6607. if (err)
  6608. return err;
  6609. /* configure global TSO hardware offload settings */
  6610. wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
  6611. TCP_FLAG_FIN) >> 16);
  6612. wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
  6613. TCP_FLAG_FIN |
  6614. TCP_FLAG_CWR) >> 16);
  6615. wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
  6616. udp_tunnel_get_rx_info(netdev);
  6617. return 0;
  6618. }
  6619. /**
  6620. * i40e_vsi_open -
  6621. * @vsi: the VSI to open
  6622. *
  6623. * Finish initialization of the VSI.
  6624. *
  6625. * Returns 0 on success, negative value on failure
  6626. *
  6627. * Note: expects to be called while under rtnl_lock()
  6628. **/
  6629. int i40e_vsi_open(struct i40e_vsi *vsi)
  6630. {
  6631. struct i40e_pf *pf = vsi->back;
  6632. char int_name[I40E_INT_NAME_STR_LEN];
  6633. int err;
  6634. /* allocate descriptors */
  6635. err = i40e_vsi_setup_tx_resources(vsi);
  6636. if (err)
  6637. goto err_setup_tx;
  6638. err = i40e_vsi_setup_rx_resources(vsi);
  6639. if (err)
  6640. goto err_setup_rx;
  6641. err = i40e_vsi_configure(vsi);
  6642. if (err)
  6643. goto err_setup_rx;
  6644. if (vsi->netdev) {
  6645. snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
  6646. dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
  6647. err = i40e_vsi_request_irq(vsi, int_name);
  6648. if (err)
  6649. goto err_setup_rx;
  6650. /* Notify the stack of the actual queue counts. */
  6651. err = netif_set_real_num_tx_queues(vsi->netdev,
  6652. vsi->num_queue_pairs);
  6653. if (err)
  6654. goto err_set_queues;
  6655. err = netif_set_real_num_rx_queues(vsi->netdev,
  6656. vsi->num_queue_pairs);
  6657. if (err)
  6658. goto err_set_queues;
  6659. } else if (vsi->type == I40E_VSI_FDIR) {
  6660. snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
  6661. dev_driver_string(&pf->pdev->dev),
  6662. dev_name(&pf->pdev->dev));
  6663. err = i40e_vsi_request_irq(vsi, int_name);
  6664. } else {
  6665. err = -EINVAL;
  6666. goto err_setup_rx;
  6667. }
  6668. err = i40e_up_complete(vsi);
  6669. if (err)
  6670. goto err_up_complete;
  6671. return 0;
  6672. err_up_complete:
  6673. i40e_down(vsi);
  6674. err_set_queues:
  6675. i40e_vsi_free_irq(vsi);
  6676. err_setup_rx:
  6677. i40e_vsi_free_rx_resources(vsi);
  6678. err_setup_tx:
  6679. i40e_vsi_free_tx_resources(vsi);
  6680. if (vsi == pf->vsi[pf->lan_vsi])
  6681. i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
  6682. return err;
  6683. }
  6684. /**
  6685. * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
  6686. * @pf: Pointer to PF
  6687. *
  6688. * This function destroys the hlist where all the Flow Director
  6689. * filters were saved.
  6690. **/
  6691. static void i40e_fdir_filter_exit(struct i40e_pf *pf)
  6692. {
  6693. struct i40e_fdir_filter *filter;
  6694. struct i40e_flex_pit *pit_entry, *tmp;
  6695. struct hlist_node *node2;
  6696. hlist_for_each_entry_safe(filter, node2,
  6697. &pf->fdir_filter_list, fdir_node) {
  6698. hlist_del(&filter->fdir_node);
  6699. kfree(filter);
  6700. }
  6701. list_for_each_entry_safe(pit_entry, tmp, &pf->l3_flex_pit_list, list) {
  6702. list_del(&pit_entry->list);
  6703. kfree(pit_entry);
  6704. }
  6705. INIT_LIST_HEAD(&pf->l3_flex_pit_list);
  6706. list_for_each_entry_safe(pit_entry, tmp, &pf->l4_flex_pit_list, list) {
  6707. list_del(&pit_entry->list);
  6708. kfree(pit_entry);
  6709. }
  6710. INIT_LIST_HEAD(&pf->l4_flex_pit_list);
  6711. pf->fdir_pf_active_filters = 0;
  6712. pf->fd_tcp4_filter_cnt = 0;
  6713. pf->fd_udp4_filter_cnt = 0;
  6714. pf->fd_sctp4_filter_cnt = 0;
  6715. pf->fd_ip4_filter_cnt = 0;
  6716. /* Reprogram the default input set for TCP/IPv4 */
  6717. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
  6718. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6719. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6720. /* Reprogram the default input set for UDP/IPv4 */
  6721. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_UDP,
  6722. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6723. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6724. /* Reprogram the default input set for SCTP/IPv4 */
  6725. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP,
  6726. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6727. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6728. /* Reprogram the default input set for Other/IPv4 */
  6729. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER,
  6730. I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
  6731. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV4,
  6732. I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
  6733. }
  6734. /**
  6735. * i40e_cloud_filter_exit - Cleans up the cloud filters
  6736. * @pf: Pointer to PF
  6737. *
  6738. * This function destroys the hlist where all the cloud filters
  6739. * were saved.
  6740. **/
  6741. static void i40e_cloud_filter_exit(struct i40e_pf *pf)
  6742. {
  6743. struct i40e_cloud_filter *cfilter;
  6744. struct hlist_node *node;
  6745. hlist_for_each_entry_safe(cfilter, node,
  6746. &pf->cloud_filter_list, cloud_node) {
  6747. hlist_del(&cfilter->cloud_node);
  6748. kfree(cfilter);
  6749. }
  6750. pf->num_cloud_filters = 0;
  6751. if ((pf->flags & I40E_FLAG_FD_SB_TO_CLOUD_FILTER) &&
  6752. !(pf->flags & I40E_FLAG_FD_SB_INACTIVE)) {
  6753. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  6754. pf->flags &= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6755. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  6756. }
  6757. }
  6758. /**
  6759. * i40e_close - Disables a network interface
  6760. * @netdev: network interface device structure
  6761. *
  6762. * The close entry point is called when an interface is de-activated
  6763. * by the OS. The hardware is still under the driver's control, but
  6764. * this netdev interface is disabled.
  6765. *
  6766. * Returns 0, this is not allowed to fail
  6767. **/
  6768. int i40e_close(struct net_device *netdev)
  6769. {
  6770. struct i40e_netdev_priv *np = netdev_priv(netdev);
  6771. struct i40e_vsi *vsi = np->vsi;
  6772. i40e_vsi_close(vsi);
  6773. return 0;
  6774. }
  6775. /**
  6776. * i40e_do_reset - Start a PF or Core Reset sequence
  6777. * @pf: board private structure
  6778. * @reset_flags: which reset is requested
  6779. * @lock_acquired: indicates whether or not the lock has been acquired
  6780. * before this function was called.
  6781. *
  6782. * The essential difference in resets is that the PF Reset
  6783. * doesn't clear the packet buffers, doesn't reset the PE
  6784. * firmware, and doesn't bother the other PFs on the chip.
  6785. **/
  6786. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags, bool lock_acquired)
  6787. {
  6788. u32 val;
  6789. WARN_ON(in_interrupt());
  6790. /* do the biggest reset indicated */
  6791. if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
  6792. /* Request a Global Reset
  6793. *
  6794. * This will start the chip's countdown to the actual full
  6795. * chip reset event, and a warning interrupt to be sent
  6796. * to all PFs, including the requestor. Our handler
  6797. * for the warning interrupt will deal with the shutdown
  6798. * and recovery of the switch setup.
  6799. */
  6800. dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
  6801. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  6802. val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
  6803. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  6804. } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
  6805. /* Request a Core Reset
  6806. *
  6807. * Same as Global Reset, except does *not* include the MAC/PHY
  6808. */
  6809. dev_dbg(&pf->pdev->dev, "CoreR requested\n");
  6810. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  6811. val |= I40E_GLGEN_RTRIG_CORER_MASK;
  6812. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  6813. i40e_flush(&pf->hw);
  6814. } else if (reset_flags & I40E_PF_RESET_FLAG) {
  6815. /* Request a PF Reset
  6816. *
  6817. * Resets only the PF-specific registers
  6818. *
  6819. * This goes directly to the tear-down and rebuild of
  6820. * the switch, since we need to do all the recovery as
  6821. * for the Core Reset.
  6822. */
  6823. dev_dbg(&pf->pdev->dev, "PFR requested\n");
  6824. i40e_handle_reset_warning(pf, lock_acquired);
  6825. } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
  6826. int v;
  6827. /* Find the VSI(s) that requested a re-init */
  6828. dev_info(&pf->pdev->dev,
  6829. "VSI reinit requested\n");
  6830. for (v = 0; v < pf->num_alloc_vsi; v++) {
  6831. struct i40e_vsi *vsi = pf->vsi[v];
  6832. if (vsi != NULL &&
  6833. test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED,
  6834. vsi->state))
  6835. i40e_vsi_reinit_locked(pf->vsi[v]);
  6836. }
  6837. } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
  6838. int v;
  6839. /* Find the VSI(s) that needs to be brought down */
  6840. dev_info(&pf->pdev->dev, "VSI down requested\n");
  6841. for (v = 0; v < pf->num_alloc_vsi; v++) {
  6842. struct i40e_vsi *vsi = pf->vsi[v];
  6843. if (vsi != NULL &&
  6844. test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED,
  6845. vsi->state)) {
  6846. set_bit(__I40E_VSI_DOWN, vsi->state);
  6847. i40e_down(vsi);
  6848. }
  6849. }
  6850. } else {
  6851. dev_info(&pf->pdev->dev,
  6852. "bad reset request 0x%08x\n", reset_flags);
  6853. }
  6854. }
  6855. #ifdef CONFIG_I40E_DCB
  6856. /**
  6857. * i40e_dcb_need_reconfig - Check if DCB needs reconfig
  6858. * @pf: board private structure
  6859. * @old_cfg: current DCB config
  6860. * @new_cfg: new DCB config
  6861. **/
  6862. bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
  6863. struct i40e_dcbx_config *old_cfg,
  6864. struct i40e_dcbx_config *new_cfg)
  6865. {
  6866. bool need_reconfig = false;
  6867. /* Check if ETS configuration has changed */
  6868. if (memcmp(&new_cfg->etscfg,
  6869. &old_cfg->etscfg,
  6870. sizeof(new_cfg->etscfg))) {
  6871. /* If Priority Table has changed reconfig is needed */
  6872. if (memcmp(&new_cfg->etscfg.prioritytable,
  6873. &old_cfg->etscfg.prioritytable,
  6874. sizeof(new_cfg->etscfg.prioritytable))) {
  6875. need_reconfig = true;
  6876. dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
  6877. }
  6878. if (memcmp(&new_cfg->etscfg.tcbwtable,
  6879. &old_cfg->etscfg.tcbwtable,
  6880. sizeof(new_cfg->etscfg.tcbwtable)))
  6881. dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
  6882. if (memcmp(&new_cfg->etscfg.tsatable,
  6883. &old_cfg->etscfg.tsatable,
  6884. sizeof(new_cfg->etscfg.tsatable)))
  6885. dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
  6886. }
  6887. /* Check if PFC configuration has changed */
  6888. if (memcmp(&new_cfg->pfc,
  6889. &old_cfg->pfc,
  6890. sizeof(new_cfg->pfc))) {
  6891. need_reconfig = true;
  6892. dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
  6893. }
  6894. /* Check if APP Table has changed */
  6895. if (memcmp(&new_cfg->app,
  6896. &old_cfg->app,
  6897. sizeof(new_cfg->app))) {
  6898. need_reconfig = true;
  6899. dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
  6900. }
  6901. dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
  6902. return need_reconfig;
  6903. }
  6904. /**
  6905. * i40e_handle_lldp_event - Handle LLDP Change MIB event
  6906. * @pf: board private structure
  6907. * @e: event info posted on ARQ
  6908. **/
  6909. static int i40e_handle_lldp_event(struct i40e_pf *pf,
  6910. struct i40e_arq_event_info *e)
  6911. {
  6912. struct i40e_aqc_lldp_get_mib *mib =
  6913. (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
  6914. struct i40e_hw *hw = &pf->hw;
  6915. struct i40e_dcbx_config tmp_dcbx_cfg;
  6916. bool need_reconfig = false;
  6917. int ret = 0;
  6918. u8 type;
  6919. /* Not DCB capable or capability disabled */
  6920. if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
  6921. return ret;
  6922. /* Ignore if event is not for Nearest Bridge */
  6923. type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
  6924. & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  6925. dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
  6926. if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
  6927. return ret;
  6928. /* Check MIB Type and return if event for Remote MIB update */
  6929. type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  6930. dev_dbg(&pf->pdev->dev,
  6931. "LLDP event mib type %s\n", type ? "remote" : "local");
  6932. if (type == I40E_AQ_LLDP_MIB_REMOTE) {
  6933. /* Update the remote cached instance and return */
  6934. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  6935. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  6936. &hw->remote_dcbx_config);
  6937. goto exit;
  6938. }
  6939. /* Store the old configuration */
  6940. tmp_dcbx_cfg = hw->local_dcbx_config;
  6941. /* Reset the old DCBx configuration data */
  6942. memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
  6943. /* Get updated DCBX data from firmware */
  6944. ret = i40e_get_dcb_config(&pf->hw);
  6945. if (ret) {
  6946. dev_info(&pf->pdev->dev,
  6947. "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
  6948. i40e_stat_str(&pf->hw, ret),
  6949. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6950. goto exit;
  6951. }
  6952. /* No change detected in DCBX configs */
  6953. if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
  6954. sizeof(tmp_dcbx_cfg))) {
  6955. dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
  6956. goto exit;
  6957. }
  6958. need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
  6959. &hw->local_dcbx_config);
  6960. i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
  6961. if (!need_reconfig)
  6962. goto exit;
  6963. /* Enable DCB tagging only when more than one TC */
  6964. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  6965. pf->flags |= I40E_FLAG_DCB_ENABLED;
  6966. else
  6967. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  6968. set_bit(__I40E_PORT_SUSPENDED, pf->state);
  6969. /* Reconfiguration needed quiesce all VSIs */
  6970. i40e_pf_quiesce_all_vsi(pf);
  6971. /* Changes in configuration update VEB/VSI */
  6972. i40e_dcb_reconfigure(pf);
  6973. ret = i40e_resume_port_tx(pf);
  6974. clear_bit(__I40E_PORT_SUSPENDED, pf->state);
  6975. /* In case of error no point in resuming VSIs */
  6976. if (ret)
  6977. goto exit;
  6978. /* Wait for the PF's queues to be disabled */
  6979. ret = i40e_pf_wait_queues_disabled(pf);
  6980. if (ret) {
  6981. /* Schedule PF reset to recover */
  6982. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  6983. i40e_service_event_schedule(pf);
  6984. } else {
  6985. i40e_pf_unquiesce_all_vsi(pf);
  6986. pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED |
  6987. I40E_FLAG_CLIENT_L2_CHANGE);
  6988. }
  6989. exit:
  6990. return ret;
  6991. }
  6992. #endif /* CONFIG_I40E_DCB */
  6993. /**
  6994. * i40e_do_reset_safe - Protected reset path for userland calls.
  6995. * @pf: board private structure
  6996. * @reset_flags: which reset is requested
  6997. *
  6998. **/
  6999. void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
  7000. {
  7001. rtnl_lock();
  7002. i40e_do_reset(pf, reset_flags, true);
  7003. rtnl_unlock();
  7004. }
  7005. /**
  7006. * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
  7007. * @pf: board private structure
  7008. * @e: event info posted on ARQ
  7009. *
  7010. * Handler for LAN Queue Overflow Event generated by the firmware for PF
  7011. * and VF queues
  7012. **/
  7013. static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
  7014. struct i40e_arq_event_info *e)
  7015. {
  7016. struct i40e_aqc_lan_overflow *data =
  7017. (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
  7018. u32 queue = le32_to_cpu(data->prtdcb_rupto);
  7019. u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
  7020. struct i40e_hw *hw = &pf->hw;
  7021. struct i40e_vf *vf;
  7022. u16 vf_id;
  7023. dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
  7024. queue, qtx_ctl);
  7025. /* Queue belongs to VF, find the VF and issue VF reset */
  7026. if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
  7027. >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
  7028. vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
  7029. >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
  7030. vf_id -= hw->func_caps.vf_base_id;
  7031. vf = &pf->vf[vf_id];
  7032. i40e_vc_notify_vf_reset(vf);
  7033. /* Allow VF to process pending reset notification */
  7034. msleep(20);
  7035. i40e_reset_vf(vf, false);
  7036. }
  7037. }
  7038. /**
  7039. * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
  7040. * @pf: board private structure
  7041. **/
  7042. u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
  7043. {
  7044. u32 val, fcnt_prog;
  7045. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  7046. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
  7047. return fcnt_prog;
  7048. }
  7049. /**
  7050. * i40e_get_current_fd_count - Get total FD filters programmed for this PF
  7051. * @pf: board private structure
  7052. **/
  7053. u32 i40e_get_current_fd_count(struct i40e_pf *pf)
  7054. {
  7055. u32 val, fcnt_prog;
  7056. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  7057. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
  7058. ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
  7059. I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
  7060. return fcnt_prog;
  7061. }
  7062. /**
  7063. * i40e_get_global_fd_count - Get total FD filters programmed on device
  7064. * @pf: board private structure
  7065. **/
  7066. u32 i40e_get_global_fd_count(struct i40e_pf *pf)
  7067. {
  7068. u32 val, fcnt_prog;
  7069. val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
  7070. fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
  7071. ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
  7072. I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
  7073. return fcnt_prog;
  7074. }
  7075. /**
  7076. * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
  7077. * @pf: board private structure
  7078. **/
  7079. void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
  7080. {
  7081. struct i40e_fdir_filter *filter;
  7082. u32 fcnt_prog, fcnt_avail;
  7083. struct hlist_node *node;
  7084. if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
  7085. return;
  7086. /* Check if we have enough room to re-enable FDir SB capability. */
  7087. fcnt_prog = i40e_get_global_fd_count(pf);
  7088. fcnt_avail = pf->fdir_pf_filter_count;
  7089. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
  7090. (pf->fd_add_err == 0) ||
  7091. (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
  7092. if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED) {
  7093. pf->flags &= ~I40E_FLAG_FD_SB_AUTO_DISABLED;
  7094. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  7095. (I40E_DEBUG_FD & pf->hw.debug_mask))
  7096. dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
  7097. }
  7098. }
  7099. /* We should wait for even more space before re-enabling ATR.
  7100. * Additionally, we cannot enable ATR as long as we still have TCP SB
  7101. * rules active.
  7102. */
  7103. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) &&
  7104. (pf->fd_tcp4_filter_cnt == 0)) {
  7105. if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) {
  7106. pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
  7107. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  7108. (I40E_DEBUG_FD & pf->hw.debug_mask))
  7109. dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
  7110. }
  7111. }
  7112. /* if hw had a problem adding a filter, delete it */
  7113. if (pf->fd_inv > 0) {
  7114. hlist_for_each_entry_safe(filter, node,
  7115. &pf->fdir_filter_list, fdir_node) {
  7116. if (filter->fd_id == pf->fd_inv) {
  7117. hlist_del(&filter->fdir_node);
  7118. kfree(filter);
  7119. pf->fdir_pf_active_filters--;
  7120. pf->fd_inv = 0;
  7121. }
  7122. }
  7123. }
  7124. }
  7125. #define I40E_MIN_FD_FLUSH_INTERVAL 10
  7126. #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
  7127. /**
  7128. * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
  7129. * @pf: board private structure
  7130. **/
  7131. static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
  7132. {
  7133. unsigned long min_flush_time;
  7134. int flush_wait_retry = 50;
  7135. bool disable_atr = false;
  7136. int fd_room;
  7137. int reg;
  7138. if (!time_after(jiffies, pf->fd_flush_timestamp +
  7139. (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
  7140. return;
  7141. /* If the flush is happening too quick and we have mostly SB rules we
  7142. * should not re-enable ATR for some time.
  7143. */
  7144. min_flush_time = pf->fd_flush_timestamp +
  7145. (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
  7146. fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
  7147. if (!(time_after(jiffies, min_flush_time)) &&
  7148. (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
  7149. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7150. dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
  7151. disable_atr = true;
  7152. }
  7153. pf->fd_flush_timestamp = jiffies;
  7154. pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED;
  7155. /* flush all filters */
  7156. wr32(&pf->hw, I40E_PFQF_CTL_1,
  7157. I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
  7158. i40e_flush(&pf->hw);
  7159. pf->fd_flush_cnt++;
  7160. pf->fd_add_err = 0;
  7161. do {
  7162. /* Check FD flush status every 5-6msec */
  7163. usleep_range(5000, 6000);
  7164. reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
  7165. if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
  7166. break;
  7167. } while (flush_wait_retry--);
  7168. if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
  7169. dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
  7170. } else {
  7171. /* replay sideband filters */
  7172. i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
  7173. if (!disable_atr && !pf->fd_tcp4_filter_cnt)
  7174. pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
  7175. clear_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
  7176. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7177. dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
  7178. }
  7179. }
  7180. /**
  7181. * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
  7182. * @pf: board private structure
  7183. **/
  7184. u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
  7185. {
  7186. return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
  7187. }
  7188. /* We can see up to 256 filter programming desc in transit if the filters are
  7189. * being applied really fast; before we see the first
  7190. * filter miss error on Rx queue 0. Accumulating enough error messages before
  7191. * reacting will make sure we don't cause flush too often.
  7192. */
  7193. #define I40E_MAX_FD_PROGRAM_ERROR 256
  7194. /**
  7195. * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
  7196. * @pf: board private structure
  7197. **/
  7198. static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
  7199. {
  7200. /* if interface is down do nothing */
  7201. if (test_bit(__I40E_DOWN, pf->state))
  7202. return;
  7203. if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
  7204. i40e_fdir_flush_and_replay(pf);
  7205. i40e_fdir_check_and_reenable(pf);
  7206. }
  7207. /**
  7208. * i40e_vsi_link_event - notify VSI of a link event
  7209. * @vsi: vsi to be notified
  7210. * @link_up: link up or down
  7211. **/
  7212. static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
  7213. {
  7214. if (!vsi || test_bit(__I40E_VSI_DOWN, vsi->state))
  7215. return;
  7216. switch (vsi->type) {
  7217. case I40E_VSI_MAIN:
  7218. if (!vsi->netdev || !vsi->netdev_registered)
  7219. break;
  7220. if (link_up) {
  7221. netif_carrier_on(vsi->netdev);
  7222. netif_tx_wake_all_queues(vsi->netdev);
  7223. } else {
  7224. netif_carrier_off(vsi->netdev);
  7225. netif_tx_stop_all_queues(vsi->netdev);
  7226. }
  7227. break;
  7228. case I40E_VSI_SRIOV:
  7229. case I40E_VSI_VMDQ2:
  7230. case I40E_VSI_CTRL:
  7231. case I40E_VSI_IWARP:
  7232. case I40E_VSI_MIRROR:
  7233. default:
  7234. /* there is no notification for other VSIs */
  7235. break;
  7236. }
  7237. }
  7238. /**
  7239. * i40e_veb_link_event - notify elements on the veb of a link event
  7240. * @veb: veb to be notified
  7241. * @link_up: link up or down
  7242. **/
  7243. static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
  7244. {
  7245. struct i40e_pf *pf;
  7246. int i;
  7247. if (!veb || !veb->pf)
  7248. return;
  7249. pf = veb->pf;
  7250. /* depth first... */
  7251. for (i = 0; i < I40E_MAX_VEB; i++)
  7252. if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
  7253. i40e_veb_link_event(pf->veb[i], link_up);
  7254. /* ... now the local VSIs */
  7255. for (i = 0; i < pf->num_alloc_vsi; i++)
  7256. if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
  7257. i40e_vsi_link_event(pf->vsi[i], link_up);
  7258. }
  7259. /**
  7260. * i40e_link_event - Update netif_carrier status
  7261. * @pf: board private structure
  7262. **/
  7263. static void i40e_link_event(struct i40e_pf *pf)
  7264. {
  7265. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7266. u8 new_link_speed, old_link_speed;
  7267. i40e_status status;
  7268. bool new_link, old_link;
  7269. /* save off old link status information */
  7270. pf->hw.phy.link_info_old = pf->hw.phy.link_info;
  7271. /* set this to force the get_link_status call to refresh state */
  7272. pf->hw.phy.get_link_info = true;
  7273. old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
  7274. status = i40e_get_link_status(&pf->hw, &new_link);
  7275. /* On success, disable temp link polling */
  7276. if (status == I40E_SUCCESS) {
  7277. if (pf->flags & I40E_FLAG_TEMP_LINK_POLLING)
  7278. pf->flags &= ~I40E_FLAG_TEMP_LINK_POLLING;
  7279. } else {
  7280. /* Enable link polling temporarily until i40e_get_link_status
  7281. * returns I40E_SUCCESS
  7282. */
  7283. pf->flags |= I40E_FLAG_TEMP_LINK_POLLING;
  7284. dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
  7285. status);
  7286. return;
  7287. }
  7288. old_link_speed = pf->hw.phy.link_info_old.link_speed;
  7289. new_link_speed = pf->hw.phy.link_info.link_speed;
  7290. if (new_link == old_link &&
  7291. new_link_speed == old_link_speed &&
  7292. (test_bit(__I40E_VSI_DOWN, vsi->state) ||
  7293. new_link == netif_carrier_ok(vsi->netdev)))
  7294. return;
  7295. i40e_print_link_message(vsi, new_link);
  7296. /* Notify the base of the switch tree connected to
  7297. * the link. Floating VEBs are not notified.
  7298. */
  7299. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  7300. i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
  7301. else
  7302. i40e_vsi_link_event(vsi, new_link);
  7303. if (pf->vf)
  7304. i40e_vc_notify_link_state(pf);
  7305. if (pf->flags & I40E_FLAG_PTP)
  7306. i40e_ptp_set_increment(pf);
  7307. }
  7308. /**
  7309. * i40e_watchdog_subtask - periodic checks not using event driven response
  7310. * @pf: board private structure
  7311. **/
  7312. static void i40e_watchdog_subtask(struct i40e_pf *pf)
  7313. {
  7314. int i;
  7315. /* if interface is down do nothing */
  7316. if (test_bit(__I40E_DOWN, pf->state) ||
  7317. test_bit(__I40E_CONFIG_BUSY, pf->state))
  7318. return;
  7319. /* make sure we don't do these things too often */
  7320. if (time_before(jiffies, (pf->service_timer_previous +
  7321. pf->service_timer_period)))
  7322. return;
  7323. pf->service_timer_previous = jiffies;
  7324. if ((pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) ||
  7325. (pf->flags & I40E_FLAG_TEMP_LINK_POLLING))
  7326. i40e_link_event(pf);
  7327. /* Update the stats for active netdevs so the network stack
  7328. * can look at updated numbers whenever it cares to
  7329. */
  7330. for (i = 0; i < pf->num_alloc_vsi; i++)
  7331. if (pf->vsi[i] && pf->vsi[i]->netdev)
  7332. i40e_update_stats(pf->vsi[i]);
  7333. if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
  7334. /* Update the stats for the active switching components */
  7335. for (i = 0; i < I40E_MAX_VEB; i++)
  7336. if (pf->veb[i])
  7337. i40e_update_veb_stats(pf->veb[i]);
  7338. }
  7339. i40e_ptp_rx_hang(pf);
  7340. i40e_ptp_tx_hang(pf);
  7341. }
  7342. /**
  7343. * i40e_reset_subtask - Set up for resetting the device and driver
  7344. * @pf: board private structure
  7345. **/
  7346. static void i40e_reset_subtask(struct i40e_pf *pf)
  7347. {
  7348. u32 reset_flags = 0;
  7349. if (test_bit(__I40E_REINIT_REQUESTED, pf->state)) {
  7350. reset_flags |= BIT(__I40E_REINIT_REQUESTED);
  7351. clear_bit(__I40E_REINIT_REQUESTED, pf->state);
  7352. }
  7353. if (test_bit(__I40E_PF_RESET_REQUESTED, pf->state)) {
  7354. reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
  7355. clear_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  7356. }
  7357. if (test_bit(__I40E_CORE_RESET_REQUESTED, pf->state)) {
  7358. reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
  7359. clear_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
  7360. }
  7361. if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state)) {
  7362. reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
  7363. clear_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state);
  7364. }
  7365. if (test_bit(__I40E_DOWN_REQUESTED, pf->state)) {
  7366. reset_flags |= BIT(__I40E_DOWN_REQUESTED);
  7367. clear_bit(__I40E_DOWN_REQUESTED, pf->state);
  7368. }
  7369. /* If there's a recovery already waiting, it takes
  7370. * precedence before starting a new reset sequence.
  7371. */
  7372. if (test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) {
  7373. i40e_prep_for_reset(pf, false);
  7374. i40e_reset(pf);
  7375. i40e_rebuild(pf, false, false);
  7376. }
  7377. /* If we're already down or resetting, just bail */
  7378. if (reset_flags &&
  7379. !test_bit(__I40E_DOWN, pf->state) &&
  7380. !test_bit(__I40E_CONFIG_BUSY, pf->state)) {
  7381. i40e_do_reset(pf, reset_flags, false);
  7382. }
  7383. }
  7384. /**
  7385. * i40e_handle_link_event - Handle link event
  7386. * @pf: board private structure
  7387. * @e: event info posted on ARQ
  7388. **/
  7389. static void i40e_handle_link_event(struct i40e_pf *pf,
  7390. struct i40e_arq_event_info *e)
  7391. {
  7392. struct i40e_aqc_get_link_status *status =
  7393. (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
  7394. /* Do a new status request to re-enable LSE reporting
  7395. * and load new status information into the hw struct
  7396. * This completely ignores any state information
  7397. * in the ARQ event info, instead choosing to always
  7398. * issue the AQ update link status command.
  7399. */
  7400. i40e_link_event(pf);
  7401. /* Check if module meets thermal requirements */
  7402. if (status->phy_type == I40E_PHY_TYPE_NOT_SUPPORTED_HIGH_TEMP) {
  7403. dev_err(&pf->pdev->dev,
  7404. "Rx/Tx is disabled on this device because the module does not meet thermal requirements.\n");
  7405. dev_err(&pf->pdev->dev,
  7406. "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
  7407. } else {
  7408. /* check for unqualified module, if link is down, suppress
  7409. * the message if link was forced to be down.
  7410. */
  7411. if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
  7412. (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
  7413. (!(status->link_info & I40E_AQ_LINK_UP)) &&
  7414. (!(pf->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED))) {
  7415. dev_err(&pf->pdev->dev,
  7416. "Rx/Tx is disabled on this device because an unsupported SFP module type was detected.\n");
  7417. dev_err(&pf->pdev->dev,
  7418. "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
  7419. }
  7420. }
  7421. }
  7422. /**
  7423. * i40e_clean_adminq_subtask - Clean the AdminQ rings
  7424. * @pf: board private structure
  7425. **/
  7426. static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
  7427. {
  7428. struct i40e_arq_event_info event;
  7429. struct i40e_hw *hw = &pf->hw;
  7430. u16 pending, i = 0;
  7431. i40e_status ret;
  7432. u16 opcode;
  7433. u32 oldval;
  7434. u32 val;
  7435. /* Do not run clean AQ when PF reset fails */
  7436. if (test_bit(__I40E_RESET_FAILED, pf->state))
  7437. return;
  7438. /* check for error indications */
  7439. val = rd32(&pf->hw, pf->hw.aq.arq.len);
  7440. oldval = val;
  7441. if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
  7442. if (hw->debug_mask & I40E_DEBUG_AQ)
  7443. dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
  7444. val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
  7445. }
  7446. if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
  7447. if (hw->debug_mask & I40E_DEBUG_AQ)
  7448. dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
  7449. val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
  7450. pf->arq_overflows++;
  7451. }
  7452. if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
  7453. if (hw->debug_mask & I40E_DEBUG_AQ)
  7454. dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
  7455. val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
  7456. }
  7457. if (oldval != val)
  7458. wr32(&pf->hw, pf->hw.aq.arq.len, val);
  7459. val = rd32(&pf->hw, pf->hw.aq.asq.len);
  7460. oldval = val;
  7461. if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
  7462. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7463. dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
  7464. val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
  7465. }
  7466. if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
  7467. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7468. dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
  7469. val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
  7470. }
  7471. if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
  7472. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7473. dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
  7474. val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
  7475. }
  7476. if (oldval != val)
  7477. wr32(&pf->hw, pf->hw.aq.asq.len, val);
  7478. event.buf_len = I40E_MAX_AQ_BUF_SIZE;
  7479. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  7480. if (!event.msg_buf)
  7481. return;
  7482. do {
  7483. ret = i40e_clean_arq_element(hw, &event, &pending);
  7484. if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
  7485. break;
  7486. else if (ret) {
  7487. dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
  7488. break;
  7489. }
  7490. opcode = le16_to_cpu(event.desc.opcode);
  7491. switch (opcode) {
  7492. case i40e_aqc_opc_get_link_status:
  7493. i40e_handle_link_event(pf, &event);
  7494. break;
  7495. case i40e_aqc_opc_send_msg_to_pf:
  7496. ret = i40e_vc_process_vf_msg(pf,
  7497. le16_to_cpu(event.desc.retval),
  7498. le32_to_cpu(event.desc.cookie_high),
  7499. le32_to_cpu(event.desc.cookie_low),
  7500. event.msg_buf,
  7501. event.msg_len);
  7502. break;
  7503. case i40e_aqc_opc_lldp_update_mib:
  7504. dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
  7505. #ifdef CONFIG_I40E_DCB
  7506. rtnl_lock();
  7507. ret = i40e_handle_lldp_event(pf, &event);
  7508. rtnl_unlock();
  7509. #endif /* CONFIG_I40E_DCB */
  7510. break;
  7511. case i40e_aqc_opc_event_lan_overflow:
  7512. dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
  7513. i40e_handle_lan_overflow_event(pf, &event);
  7514. break;
  7515. case i40e_aqc_opc_send_msg_to_peer:
  7516. dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
  7517. break;
  7518. case i40e_aqc_opc_nvm_erase:
  7519. case i40e_aqc_opc_nvm_update:
  7520. case i40e_aqc_opc_oem_post_update:
  7521. i40e_debug(&pf->hw, I40E_DEBUG_NVM,
  7522. "ARQ NVM operation 0x%04x completed\n",
  7523. opcode);
  7524. break;
  7525. default:
  7526. dev_info(&pf->pdev->dev,
  7527. "ARQ: Unknown event 0x%04x ignored\n",
  7528. opcode);
  7529. break;
  7530. }
  7531. } while (i++ < pf->adminq_work_limit);
  7532. if (i < pf->adminq_work_limit)
  7533. clear_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
  7534. /* re-enable Admin queue interrupt cause */
  7535. val = rd32(hw, I40E_PFINT_ICR0_ENA);
  7536. val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  7537. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  7538. i40e_flush(hw);
  7539. kfree(event.msg_buf);
  7540. }
  7541. /**
  7542. * i40e_verify_eeprom - make sure eeprom is good to use
  7543. * @pf: board private structure
  7544. **/
  7545. static void i40e_verify_eeprom(struct i40e_pf *pf)
  7546. {
  7547. int err;
  7548. err = i40e_diag_eeprom_test(&pf->hw);
  7549. if (err) {
  7550. /* retry in case of garbage read */
  7551. err = i40e_diag_eeprom_test(&pf->hw);
  7552. if (err) {
  7553. dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
  7554. err);
  7555. set_bit(__I40E_BAD_EEPROM, pf->state);
  7556. }
  7557. }
  7558. if (!err && test_bit(__I40E_BAD_EEPROM, pf->state)) {
  7559. dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
  7560. clear_bit(__I40E_BAD_EEPROM, pf->state);
  7561. }
  7562. }
  7563. /**
  7564. * i40e_enable_pf_switch_lb
  7565. * @pf: pointer to the PF structure
  7566. *
  7567. * enable switch loop back or die - no point in a return value
  7568. **/
  7569. static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
  7570. {
  7571. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7572. struct i40e_vsi_context ctxt;
  7573. int ret;
  7574. ctxt.seid = pf->main_vsi_seid;
  7575. ctxt.pf_num = pf->hw.pf_id;
  7576. ctxt.vf_num = 0;
  7577. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  7578. if (ret) {
  7579. dev_info(&pf->pdev->dev,
  7580. "couldn't get PF vsi config, err %s aq_err %s\n",
  7581. i40e_stat_str(&pf->hw, ret),
  7582. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7583. return;
  7584. }
  7585. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  7586. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  7587. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  7588. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  7589. if (ret) {
  7590. dev_info(&pf->pdev->dev,
  7591. "update vsi switch failed, err %s aq_err %s\n",
  7592. i40e_stat_str(&pf->hw, ret),
  7593. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7594. }
  7595. }
  7596. /**
  7597. * i40e_disable_pf_switch_lb
  7598. * @pf: pointer to the PF structure
  7599. *
  7600. * disable switch loop back or die - no point in a return value
  7601. **/
  7602. static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
  7603. {
  7604. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7605. struct i40e_vsi_context ctxt;
  7606. int ret;
  7607. ctxt.seid = pf->main_vsi_seid;
  7608. ctxt.pf_num = pf->hw.pf_id;
  7609. ctxt.vf_num = 0;
  7610. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  7611. if (ret) {
  7612. dev_info(&pf->pdev->dev,
  7613. "couldn't get PF vsi config, err %s aq_err %s\n",
  7614. i40e_stat_str(&pf->hw, ret),
  7615. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7616. return;
  7617. }
  7618. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  7619. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  7620. ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  7621. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  7622. if (ret) {
  7623. dev_info(&pf->pdev->dev,
  7624. "update vsi switch failed, err %s aq_err %s\n",
  7625. i40e_stat_str(&pf->hw, ret),
  7626. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7627. }
  7628. }
  7629. /**
  7630. * i40e_config_bridge_mode - Configure the HW bridge mode
  7631. * @veb: pointer to the bridge instance
  7632. *
  7633. * Configure the loop back mode for the LAN VSI that is downlink to the
  7634. * specified HW bridge instance. It is expected this function is called
  7635. * when a new HW bridge is instantiated.
  7636. **/
  7637. static void i40e_config_bridge_mode(struct i40e_veb *veb)
  7638. {
  7639. struct i40e_pf *pf = veb->pf;
  7640. if (pf->hw.debug_mask & I40E_DEBUG_LAN)
  7641. dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
  7642. veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  7643. if (veb->bridge_mode & BRIDGE_MODE_VEPA)
  7644. i40e_disable_pf_switch_lb(pf);
  7645. else
  7646. i40e_enable_pf_switch_lb(pf);
  7647. }
  7648. /**
  7649. * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
  7650. * @veb: pointer to the VEB instance
  7651. *
  7652. * This is a recursive function that first builds the attached VSIs then
  7653. * recurses in to build the next layer of VEB. We track the connections
  7654. * through our own index numbers because the seid's from the HW could
  7655. * change across the reset.
  7656. **/
  7657. static int i40e_reconstitute_veb(struct i40e_veb *veb)
  7658. {
  7659. struct i40e_vsi *ctl_vsi = NULL;
  7660. struct i40e_pf *pf = veb->pf;
  7661. int v, veb_idx;
  7662. int ret;
  7663. /* build VSI that owns this VEB, temporarily attached to base VEB */
  7664. for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
  7665. if (pf->vsi[v] &&
  7666. pf->vsi[v]->veb_idx == veb->idx &&
  7667. pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
  7668. ctl_vsi = pf->vsi[v];
  7669. break;
  7670. }
  7671. }
  7672. if (!ctl_vsi) {
  7673. dev_info(&pf->pdev->dev,
  7674. "missing owner VSI for veb_idx %d\n", veb->idx);
  7675. ret = -ENOENT;
  7676. goto end_reconstitute;
  7677. }
  7678. if (ctl_vsi != pf->vsi[pf->lan_vsi])
  7679. ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  7680. ret = i40e_add_vsi(ctl_vsi);
  7681. if (ret) {
  7682. dev_info(&pf->pdev->dev,
  7683. "rebuild of veb_idx %d owner VSI failed: %d\n",
  7684. veb->idx, ret);
  7685. goto end_reconstitute;
  7686. }
  7687. i40e_vsi_reset_stats(ctl_vsi);
  7688. /* create the VEB in the switch and move the VSI onto the VEB */
  7689. ret = i40e_add_veb(veb, ctl_vsi);
  7690. if (ret)
  7691. goto end_reconstitute;
  7692. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  7693. veb->bridge_mode = BRIDGE_MODE_VEB;
  7694. else
  7695. veb->bridge_mode = BRIDGE_MODE_VEPA;
  7696. i40e_config_bridge_mode(veb);
  7697. /* create the remaining VSIs attached to this VEB */
  7698. for (v = 0; v < pf->num_alloc_vsi; v++) {
  7699. if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
  7700. continue;
  7701. if (pf->vsi[v]->veb_idx == veb->idx) {
  7702. struct i40e_vsi *vsi = pf->vsi[v];
  7703. vsi->uplink_seid = veb->seid;
  7704. ret = i40e_add_vsi(vsi);
  7705. if (ret) {
  7706. dev_info(&pf->pdev->dev,
  7707. "rebuild of vsi_idx %d failed: %d\n",
  7708. v, ret);
  7709. goto end_reconstitute;
  7710. }
  7711. i40e_vsi_reset_stats(vsi);
  7712. }
  7713. }
  7714. /* create any VEBs attached to this VEB - RECURSION */
  7715. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  7716. if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
  7717. pf->veb[veb_idx]->uplink_seid = veb->seid;
  7718. ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
  7719. if (ret)
  7720. break;
  7721. }
  7722. }
  7723. end_reconstitute:
  7724. return ret;
  7725. }
  7726. /**
  7727. * i40e_get_capabilities - get info about the HW
  7728. * @pf: the PF struct
  7729. **/
  7730. static int i40e_get_capabilities(struct i40e_pf *pf,
  7731. enum i40e_admin_queue_opc list_type)
  7732. {
  7733. struct i40e_aqc_list_capabilities_element_resp *cap_buf;
  7734. u16 data_size;
  7735. int buf_len;
  7736. int err;
  7737. buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
  7738. do {
  7739. cap_buf = kzalloc(buf_len, GFP_KERNEL);
  7740. if (!cap_buf)
  7741. return -ENOMEM;
  7742. /* this loads the data into the hw struct for us */
  7743. err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
  7744. &data_size, list_type,
  7745. NULL);
  7746. /* data loaded, buffer no longer needed */
  7747. kfree(cap_buf);
  7748. if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
  7749. /* retry with a larger buffer */
  7750. buf_len = data_size;
  7751. } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
  7752. dev_info(&pf->pdev->dev,
  7753. "capability discovery failed, err %s aq_err %s\n",
  7754. i40e_stat_str(&pf->hw, err),
  7755. i40e_aq_str(&pf->hw,
  7756. pf->hw.aq.asq_last_status));
  7757. return -ENODEV;
  7758. }
  7759. } while (err);
  7760. if (pf->hw.debug_mask & I40E_DEBUG_USER) {
  7761. if (list_type == i40e_aqc_opc_list_func_capabilities) {
  7762. dev_info(&pf->pdev->dev,
  7763. "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",
  7764. pf->hw.pf_id, pf->hw.func_caps.num_vfs,
  7765. pf->hw.func_caps.num_msix_vectors,
  7766. pf->hw.func_caps.num_msix_vectors_vf,
  7767. pf->hw.func_caps.fd_filters_guaranteed,
  7768. pf->hw.func_caps.fd_filters_best_effort,
  7769. pf->hw.func_caps.num_tx_qp,
  7770. pf->hw.func_caps.num_vsis);
  7771. } else if (list_type == i40e_aqc_opc_list_dev_capabilities) {
  7772. dev_info(&pf->pdev->dev,
  7773. "switch_mode=0x%04x, function_valid=0x%08x\n",
  7774. pf->hw.dev_caps.switch_mode,
  7775. pf->hw.dev_caps.valid_functions);
  7776. dev_info(&pf->pdev->dev,
  7777. "SR-IOV=%d, num_vfs for all function=%u\n",
  7778. pf->hw.dev_caps.sr_iov_1_1,
  7779. pf->hw.dev_caps.num_vfs);
  7780. dev_info(&pf->pdev->dev,
  7781. "num_vsis=%u, num_rx:%u, num_tx=%u\n",
  7782. pf->hw.dev_caps.num_vsis,
  7783. pf->hw.dev_caps.num_rx_qp,
  7784. pf->hw.dev_caps.num_tx_qp);
  7785. }
  7786. }
  7787. if (list_type == i40e_aqc_opc_list_func_capabilities) {
  7788. #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
  7789. + pf->hw.func_caps.num_vfs)
  7790. if (pf->hw.revision_id == 0 &&
  7791. pf->hw.func_caps.num_vsis < DEF_NUM_VSI) {
  7792. dev_info(&pf->pdev->dev,
  7793. "got num_vsis %d, setting num_vsis to %d\n",
  7794. pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
  7795. pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
  7796. }
  7797. }
  7798. return 0;
  7799. }
  7800. static int i40e_vsi_clear(struct i40e_vsi *vsi);
  7801. /**
  7802. * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
  7803. * @pf: board private structure
  7804. **/
  7805. static void i40e_fdir_sb_setup(struct i40e_pf *pf)
  7806. {
  7807. struct i40e_vsi *vsi;
  7808. /* quick workaround for an NVM issue that leaves a critical register
  7809. * uninitialized
  7810. */
  7811. if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
  7812. static const u32 hkey[] = {
  7813. 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
  7814. 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
  7815. 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
  7816. 0x95b3a76d};
  7817. int i;
  7818. for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
  7819. wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
  7820. }
  7821. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  7822. return;
  7823. /* find existing VSI and see if it needs configuring */
  7824. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  7825. /* create a new VSI if none exists */
  7826. if (!vsi) {
  7827. vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
  7828. pf->vsi[pf->lan_vsi]->seid, 0);
  7829. if (!vsi) {
  7830. dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
  7831. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7832. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  7833. return;
  7834. }
  7835. }
  7836. i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
  7837. }
  7838. /**
  7839. * i40e_fdir_teardown - release the Flow Director resources
  7840. * @pf: board private structure
  7841. **/
  7842. static void i40e_fdir_teardown(struct i40e_pf *pf)
  7843. {
  7844. struct i40e_vsi *vsi;
  7845. i40e_fdir_filter_exit(pf);
  7846. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  7847. if (vsi)
  7848. i40e_vsi_release(vsi);
  7849. }
  7850. /**
  7851. * i40e_rebuild_cloud_filters - Rebuilds cloud filters for VSIs
  7852. * @vsi: PF main vsi
  7853. * @seid: seid of main or channel VSIs
  7854. *
  7855. * Rebuilds cloud filters associated with main VSI and channel VSIs if they
  7856. * existed before reset
  7857. **/
  7858. static int i40e_rebuild_cloud_filters(struct i40e_vsi *vsi, u16 seid)
  7859. {
  7860. struct i40e_cloud_filter *cfilter;
  7861. struct i40e_pf *pf = vsi->back;
  7862. struct hlist_node *node;
  7863. i40e_status ret;
  7864. /* Add cloud filters back if they exist */
  7865. hlist_for_each_entry_safe(cfilter, node, &pf->cloud_filter_list,
  7866. cloud_node) {
  7867. if (cfilter->seid != seid)
  7868. continue;
  7869. if (cfilter->dst_port)
  7870. ret = i40e_add_del_cloud_filter_big_buf(vsi, cfilter,
  7871. true);
  7872. else
  7873. ret = i40e_add_del_cloud_filter(vsi, cfilter, true);
  7874. if (ret) {
  7875. dev_dbg(&pf->pdev->dev,
  7876. "Failed to rebuild cloud filter, err %s aq_err %s\n",
  7877. i40e_stat_str(&pf->hw, ret),
  7878. i40e_aq_str(&pf->hw,
  7879. pf->hw.aq.asq_last_status));
  7880. return ret;
  7881. }
  7882. }
  7883. return 0;
  7884. }
  7885. /**
  7886. * i40e_rebuild_channels - Rebuilds channel VSIs if they existed before reset
  7887. * @vsi: PF main vsi
  7888. *
  7889. * Rebuilds channel VSIs if they existed before reset
  7890. **/
  7891. static int i40e_rebuild_channels(struct i40e_vsi *vsi)
  7892. {
  7893. struct i40e_channel *ch, *ch_tmp;
  7894. i40e_status ret;
  7895. if (list_empty(&vsi->ch_list))
  7896. return 0;
  7897. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  7898. if (!ch->initialized)
  7899. break;
  7900. /* Proceed with creation of channel (VMDq2) VSI */
  7901. ret = i40e_add_channel(vsi->back, vsi->uplink_seid, ch);
  7902. if (ret) {
  7903. dev_info(&vsi->back->pdev->dev,
  7904. "failed to rebuild channels using uplink_seid %u\n",
  7905. vsi->uplink_seid);
  7906. return ret;
  7907. }
  7908. /* Reconfigure TX queues using QTX_CTL register */
  7909. ret = i40e_channel_config_tx_ring(vsi->back, vsi, ch);
  7910. if (ret) {
  7911. dev_info(&vsi->back->pdev->dev,
  7912. "failed to configure TX rings for channel %u\n",
  7913. ch->seid);
  7914. return ret;
  7915. }
  7916. /* update 'next_base_queue' */
  7917. vsi->next_base_queue = vsi->next_base_queue +
  7918. ch->num_queue_pairs;
  7919. if (ch->max_tx_rate) {
  7920. u64 credits = ch->max_tx_rate;
  7921. if (i40e_set_bw_limit(vsi, ch->seid,
  7922. ch->max_tx_rate))
  7923. return -EINVAL;
  7924. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  7925. dev_dbg(&vsi->back->pdev->dev,
  7926. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  7927. ch->max_tx_rate,
  7928. credits,
  7929. ch->seid);
  7930. }
  7931. ret = i40e_rebuild_cloud_filters(vsi, ch->seid);
  7932. if (ret) {
  7933. dev_dbg(&vsi->back->pdev->dev,
  7934. "Failed to rebuild cloud filters for channel VSI %u\n",
  7935. ch->seid);
  7936. return ret;
  7937. }
  7938. }
  7939. return 0;
  7940. }
  7941. /**
  7942. * i40e_prep_for_reset - prep for the core to reset
  7943. * @pf: board private structure
  7944. * @lock_acquired: indicates whether or not the lock has been acquired
  7945. * before this function was called.
  7946. *
  7947. * Close up the VFs and other things in prep for PF Reset.
  7948. **/
  7949. static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired)
  7950. {
  7951. struct i40e_hw *hw = &pf->hw;
  7952. i40e_status ret = 0;
  7953. u32 v;
  7954. clear_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
  7955. if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  7956. return;
  7957. if (i40e_check_asq_alive(&pf->hw))
  7958. i40e_vc_notify_reset(pf);
  7959. dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
  7960. /* quiesce the VSIs and their queues that are not already DOWN */
  7961. /* pf_quiesce_all_vsi modifies netdev structures -rtnl_lock needed */
  7962. if (!lock_acquired)
  7963. rtnl_lock();
  7964. i40e_pf_quiesce_all_vsi(pf);
  7965. if (!lock_acquired)
  7966. rtnl_unlock();
  7967. for (v = 0; v < pf->num_alloc_vsi; v++) {
  7968. if (pf->vsi[v])
  7969. pf->vsi[v]->seid = 0;
  7970. }
  7971. i40e_shutdown_adminq(&pf->hw);
  7972. /* call shutdown HMC */
  7973. if (hw->hmc.hmc_obj) {
  7974. ret = i40e_shutdown_lan_hmc(hw);
  7975. if (ret)
  7976. dev_warn(&pf->pdev->dev,
  7977. "shutdown_lan_hmc failed: %d\n", ret);
  7978. }
  7979. }
  7980. /**
  7981. * i40e_send_version - update firmware with driver version
  7982. * @pf: PF struct
  7983. */
  7984. static void i40e_send_version(struct i40e_pf *pf)
  7985. {
  7986. struct i40e_driver_version dv;
  7987. dv.major_version = DRV_VERSION_MAJOR;
  7988. dv.minor_version = DRV_VERSION_MINOR;
  7989. dv.build_version = DRV_VERSION_BUILD;
  7990. dv.subbuild_version = 0;
  7991. strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
  7992. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  7993. }
  7994. /**
  7995. * i40e_get_oem_version - get OEM specific version information
  7996. * @hw: pointer to the hardware structure
  7997. **/
  7998. static void i40e_get_oem_version(struct i40e_hw *hw)
  7999. {
  8000. u16 block_offset = 0xffff;
  8001. u16 block_length = 0;
  8002. u16 capabilities = 0;
  8003. u16 gen_snap = 0;
  8004. u16 release = 0;
  8005. #define I40E_SR_NVM_OEM_VERSION_PTR 0x1B
  8006. #define I40E_NVM_OEM_LENGTH_OFFSET 0x00
  8007. #define I40E_NVM_OEM_CAPABILITIES_OFFSET 0x01
  8008. #define I40E_NVM_OEM_GEN_OFFSET 0x02
  8009. #define I40E_NVM_OEM_RELEASE_OFFSET 0x03
  8010. #define I40E_NVM_OEM_CAPABILITIES_MASK 0x000F
  8011. #define I40E_NVM_OEM_LENGTH 3
  8012. /* Check if pointer to OEM version block is valid. */
  8013. i40e_read_nvm_word(hw, I40E_SR_NVM_OEM_VERSION_PTR, &block_offset);
  8014. if (block_offset == 0xffff)
  8015. return;
  8016. /* Check if OEM version block has correct length. */
  8017. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_LENGTH_OFFSET,
  8018. &block_length);
  8019. if (block_length < I40E_NVM_OEM_LENGTH)
  8020. return;
  8021. /* Check if OEM version format is as expected. */
  8022. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_CAPABILITIES_OFFSET,
  8023. &capabilities);
  8024. if ((capabilities & I40E_NVM_OEM_CAPABILITIES_MASK) != 0)
  8025. return;
  8026. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_GEN_OFFSET,
  8027. &gen_snap);
  8028. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_RELEASE_OFFSET,
  8029. &release);
  8030. hw->nvm.oem_ver = (gen_snap << I40E_OEM_SNAP_SHIFT) | release;
  8031. hw->nvm.eetrack = I40E_OEM_EETRACK_ID;
  8032. }
  8033. /**
  8034. * i40e_reset - wait for core reset to finish reset, reset pf if corer not seen
  8035. * @pf: board private structure
  8036. **/
  8037. static int i40e_reset(struct i40e_pf *pf)
  8038. {
  8039. struct i40e_hw *hw = &pf->hw;
  8040. i40e_status ret;
  8041. ret = i40e_pf_reset(hw);
  8042. if (ret) {
  8043. dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
  8044. set_bit(__I40E_RESET_FAILED, pf->state);
  8045. clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
  8046. } else {
  8047. pf->pfr_count++;
  8048. }
  8049. return ret;
  8050. }
  8051. /**
  8052. * i40e_rebuild - rebuild using a saved config
  8053. * @pf: board private structure
  8054. * @reinit: if the Main VSI needs to re-initialized.
  8055. * @lock_acquired: indicates whether or not the lock has been acquired
  8056. * before this function was called.
  8057. **/
  8058. static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired)
  8059. {
  8060. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  8061. struct i40e_hw *hw = &pf->hw;
  8062. u8 set_fc_aq_fail = 0;
  8063. i40e_status ret;
  8064. u32 val;
  8065. int v;
  8066. if (test_bit(__I40E_DOWN, pf->state))
  8067. goto clear_recovery;
  8068. dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
  8069. /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
  8070. ret = i40e_init_adminq(&pf->hw);
  8071. if (ret) {
  8072. dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
  8073. i40e_stat_str(&pf->hw, ret),
  8074. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8075. goto clear_recovery;
  8076. }
  8077. i40e_get_oem_version(&pf->hw);
  8078. if (test_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state) &&
  8079. ((hw->aq.fw_maj_ver == 4 && hw->aq.fw_min_ver <= 33) ||
  8080. hw->aq.fw_maj_ver < 4) && hw->mac.type == I40E_MAC_XL710) {
  8081. /* The following delay is necessary for 4.33 firmware and older
  8082. * to recover after EMP reset. 200 ms should suffice but we
  8083. * put here 300 ms to be sure that FW is ready to operate
  8084. * after reset.
  8085. */
  8086. mdelay(300);
  8087. }
  8088. /* re-verify the eeprom if we just had an EMP reset */
  8089. if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state))
  8090. i40e_verify_eeprom(pf);
  8091. i40e_clear_pxe_mode(hw);
  8092. ret = i40e_get_capabilities(pf, i40e_aqc_opc_list_func_capabilities);
  8093. if (ret)
  8094. goto end_core_reset;
  8095. ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  8096. hw->func_caps.num_rx_qp, 0, 0);
  8097. if (ret) {
  8098. dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
  8099. goto end_core_reset;
  8100. }
  8101. ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  8102. if (ret) {
  8103. dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
  8104. goto end_core_reset;
  8105. }
  8106. /* Enable FW to write a default DCB config on link-up */
  8107. i40e_aq_set_dcb_parameters(hw, true, NULL);
  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->vsi[pf->lan_vsi]);
  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->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->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->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. return -ENOMEM;
  9153. pf->irq_pile->num_entries = vectors;
  9154. pf->irq_pile->search_hint = 0;
  9155. /* track first vector for misc interrupts, ignore return */
  9156. (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
  9157. return 0;
  9158. }
  9159. /**
  9160. * i40e_restore_interrupt_scheme - Restore the interrupt scheme
  9161. * @pf: private board data structure
  9162. *
  9163. * Restore the interrupt scheme that was cleared when we suspended the
  9164. * device. This should be called during resume to re-allocate the q_vectors
  9165. * and reacquire IRQs.
  9166. */
  9167. static int i40e_restore_interrupt_scheme(struct i40e_pf *pf)
  9168. {
  9169. int err, i;
  9170. /* We cleared the MSI and MSI-X flags when disabling the old interrupt
  9171. * scheme. We need to re-enabled them here in order to attempt to
  9172. * re-acquire the MSI or MSI-X vectors
  9173. */
  9174. pf->flags |= (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  9175. err = i40e_init_interrupt_scheme(pf);
  9176. if (err)
  9177. return err;
  9178. /* Now that we've re-acquired IRQs, we need to remap the vectors and
  9179. * rings together again.
  9180. */
  9181. for (i = 0; i < pf->num_alloc_vsi; i++) {
  9182. if (pf->vsi[i]) {
  9183. err = i40e_vsi_alloc_q_vectors(pf->vsi[i]);
  9184. if (err)
  9185. goto err_unwind;
  9186. i40e_vsi_map_rings_to_vectors(pf->vsi[i]);
  9187. }
  9188. }
  9189. err = i40e_setup_misc_vector(pf);
  9190. if (err)
  9191. goto err_unwind;
  9192. return 0;
  9193. err_unwind:
  9194. while (i--) {
  9195. if (pf->vsi[i])
  9196. i40e_vsi_free_q_vectors(pf->vsi[i]);
  9197. }
  9198. return err;
  9199. }
  9200. /**
  9201. * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
  9202. * @pf: board private structure
  9203. *
  9204. * This sets up the handler for MSIX 0, which is used to manage the
  9205. * non-queue interrupts, e.g. AdminQ and errors. This is not used
  9206. * when in MSI or Legacy interrupt mode.
  9207. **/
  9208. static int i40e_setup_misc_vector(struct i40e_pf *pf)
  9209. {
  9210. struct i40e_hw *hw = &pf->hw;
  9211. int err = 0;
  9212. /* Only request the IRQ once, the first time through. */
  9213. if (!test_and_set_bit(__I40E_MISC_IRQ_REQUESTED, pf->state)) {
  9214. err = request_irq(pf->msix_entries[0].vector,
  9215. i40e_intr, 0, pf->int_name, pf);
  9216. if (err) {
  9217. clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state);
  9218. dev_info(&pf->pdev->dev,
  9219. "request_irq for %s failed: %d\n",
  9220. pf->int_name, err);
  9221. return -EFAULT;
  9222. }
  9223. }
  9224. i40e_enable_misc_int_causes(pf);
  9225. /* associate no queues to the misc vector */
  9226. wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
  9227. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
  9228. i40e_flush(hw);
  9229. i40e_irq_dynamic_enable_icr0(pf);
  9230. return err;
  9231. }
  9232. /**
  9233. * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
  9234. * @vsi: Pointer to vsi structure
  9235. * @seed: Buffter to store the hash keys
  9236. * @lut: Buffer to store the lookup table entries
  9237. * @lut_size: Size of buffer to store the lookup table entries
  9238. *
  9239. * Return 0 on success, negative on failure
  9240. */
  9241. static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  9242. u8 *lut, u16 lut_size)
  9243. {
  9244. struct i40e_pf *pf = vsi->back;
  9245. struct i40e_hw *hw = &pf->hw;
  9246. int ret = 0;
  9247. if (seed) {
  9248. ret = i40e_aq_get_rss_key(hw, vsi->id,
  9249. (struct i40e_aqc_get_set_rss_key_data *)seed);
  9250. if (ret) {
  9251. dev_info(&pf->pdev->dev,
  9252. "Cannot get RSS key, err %s aq_err %s\n",
  9253. i40e_stat_str(&pf->hw, ret),
  9254. i40e_aq_str(&pf->hw,
  9255. pf->hw.aq.asq_last_status));
  9256. return ret;
  9257. }
  9258. }
  9259. if (lut) {
  9260. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  9261. ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  9262. if (ret) {
  9263. dev_info(&pf->pdev->dev,
  9264. "Cannot get RSS lut, err %s aq_err %s\n",
  9265. i40e_stat_str(&pf->hw, ret),
  9266. i40e_aq_str(&pf->hw,
  9267. pf->hw.aq.asq_last_status));
  9268. return ret;
  9269. }
  9270. }
  9271. return ret;
  9272. }
  9273. /**
  9274. * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
  9275. * @vsi: Pointer to vsi structure
  9276. * @seed: RSS hash seed
  9277. * @lut: Lookup table
  9278. * @lut_size: Lookup table size
  9279. *
  9280. * Returns 0 on success, negative on failure
  9281. **/
  9282. static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
  9283. const u8 *lut, u16 lut_size)
  9284. {
  9285. struct i40e_pf *pf = vsi->back;
  9286. struct i40e_hw *hw = &pf->hw;
  9287. u16 vf_id = vsi->vf_id;
  9288. u8 i;
  9289. /* Fill out hash function seed */
  9290. if (seed) {
  9291. u32 *seed_dw = (u32 *)seed;
  9292. if (vsi->type == I40E_VSI_MAIN) {
  9293. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  9294. wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]);
  9295. } else if (vsi->type == I40E_VSI_SRIOV) {
  9296. for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++)
  9297. wr32(hw, I40E_VFQF_HKEY1(i, vf_id), seed_dw[i]);
  9298. } else {
  9299. dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n");
  9300. }
  9301. }
  9302. if (lut) {
  9303. u32 *lut_dw = (u32 *)lut;
  9304. if (vsi->type == I40E_VSI_MAIN) {
  9305. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  9306. return -EINVAL;
  9307. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  9308. wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
  9309. } else if (vsi->type == I40E_VSI_SRIOV) {
  9310. if (lut_size != I40E_VF_HLUT_ARRAY_SIZE)
  9311. return -EINVAL;
  9312. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  9313. wr32(hw, I40E_VFQF_HLUT1(i, vf_id), lut_dw[i]);
  9314. } else {
  9315. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  9316. }
  9317. }
  9318. i40e_flush(hw);
  9319. return 0;
  9320. }
  9321. /**
  9322. * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
  9323. * @vsi: Pointer to VSI structure
  9324. * @seed: Buffer to store the keys
  9325. * @lut: Buffer to store the lookup table entries
  9326. * @lut_size: Size of buffer to store the lookup table entries
  9327. *
  9328. * Returns 0 on success, negative on failure
  9329. */
  9330. static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
  9331. u8 *lut, u16 lut_size)
  9332. {
  9333. struct i40e_pf *pf = vsi->back;
  9334. struct i40e_hw *hw = &pf->hw;
  9335. u16 i;
  9336. if (seed) {
  9337. u32 *seed_dw = (u32 *)seed;
  9338. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  9339. seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
  9340. }
  9341. if (lut) {
  9342. u32 *lut_dw = (u32 *)lut;
  9343. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  9344. return -EINVAL;
  9345. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  9346. lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
  9347. }
  9348. return 0;
  9349. }
  9350. /**
  9351. * i40e_config_rss - Configure RSS keys and lut
  9352. * @vsi: Pointer to VSI structure
  9353. * @seed: RSS hash seed
  9354. * @lut: Lookup table
  9355. * @lut_size: Lookup table size
  9356. *
  9357. * Returns 0 on success, negative on failure
  9358. */
  9359. int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  9360. {
  9361. struct i40e_pf *pf = vsi->back;
  9362. if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)
  9363. return i40e_config_rss_aq(vsi, seed, lut, lut_size);
  9364. else
  9365. return i40e_config_rss_reg(vsi, seed, lut, lut_size);
  9366. }
  9367. /**
  9368. * i40e_get_rss - Get RSS keys and lut
  9369. * @vsi: Pointer to VSI structure
  9370. * @seed: Buffer to store the keys
  9371. * @lut: Buffer to store the lookup table entries
  9372. * lut_size: Size of buffer to store the lookup table entries
  9373. *
  9374. * Returns 0 on success, negative on failure
  9375. */
  9376. int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  9377. {
  9378. struct i40e_pf *pf = vsi->back;
  9379. if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)
  9380. return i40e_get_rss_aq(vsi, seed, lut, lut_size);
  9381. else
  9382. return i40e_get_rss_reg(vsi, seed, lut, lut_size);
  9383. }
  9384. /**
  9385. * i40e_fill_rss_lut - Fill the RSS lookup table with default values
  9386. * @pf: Pointer to board private structure
  9387. * @lut: Lookup table
  9388. * @rss_table_size: Lookup table size
  9389. * @rss_size: Range of queue number for hashing
  9390. */
  9391. void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
  9392. u16 rss_table_size, u16 rss_size)
  9393. {
  9394. u16 i;
  9395. for (i = 0; i < rss_table_size; i++)
  9396. lut[i] = i % rss_size;
  9397. }
  9398. /**
  9399. * i40e_pf_config_rss - Prepare for RSS if used
  9400. * @pf: board private structure
  9401. **/
  9402. static int i40e_pf_config_rss(struct i40e_pf *pf)
  9403. {
  9404. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  9405. u8 seed[I40E_HKEY_ARRAY_SIZE];
  9406. u8 *lut;
  9407. struct i40e_hw *hw = &pf->hw;
  9408. u32 reg_val;
  9409. u64 hena;
  9410. int ret;
  9411. /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
  9412. hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  9413. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  9414. hena |= i40e_pf_get_default_rss_hena(pf);
  9415. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  9416. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  9417. /* Determine the RSS table size based on the hardware capabilities */
  9418. reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
  9419. reg_val = (pf->rss_table_size == 512) ?
  9420. (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
  9421. (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
  9422. i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
  9423. /* Determine the RSS size of the VSI */
  9424. if (!vsi->rss_size) {
  9425. u16 qcount;
  9426. /* If the firmware does something weird during VSI init, we
  9427. * could end up with zero TCs. Check for that to avoid
  9428. * divide-by-zero. It probably won't pass traffic, but it also
  9429. * won't panic.
  9430. */
  9431. qcount = vsi->num_queue_pairs /
  9432. (vsi->tc_config.numtc ? vsi->tc_config.numtc : 1);
  9433. vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
  9434. }
  9435. if (!vsi->rss_size)
  9436. return -EINVAL;
  9437. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  9438. if (!lut)
  9439. return -ENOMEM;
  9440. /* Use user configured lut if there is one, otherwise use default */
  9441. if (vsi->rss_lut_user)
  9442. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  9443. else
  9444. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  9445. /* Use user configured hash key if there is one, otherwise
  9446. * use default.
  9447. */
  9448. if (vsi->rss_hkey_user)
  9449. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  9450. else
  9451. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  9452. ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
  9453. kfree(lut);
  9454. return ret;
  9455. }
  9456. /**
  9457. * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
  9458. * @pf: board private structure
  9459. * @queue_count: the requested queue count for rss.
  9460. *
  9461. * returns 0 if rss is not enabled, if enabled returns the final rss queue
  9462. * count which may be different from the requested queue count.
  9463. * Note: expects to be called while under rtnl_lock()
  9464. **/
  9465. int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
  9466. {
  9467. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  9468. int new_rss_size;
  9469. if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
  9470. return 0;
  9471. new_rss_size = min_t(int, queue_count, pf->rss_size_max);
  9472. if (queue_count != vsi->num_queue_pairs) {
  9473. u16 qcount;
  9474. vsi->req_queue_pairs = queue_count;
  9475. i40e_prep_for_reset(pf, true);
  9476. pf->alloc_rss_size = new_rss_size;
  9477. i40e_reset_and_rebuild(pf, true, true);
  9478. /* Discard the user configured hash keys and lut, if less
  9479. * queues are enabled.
  9480. */
  9481. if (queue_count < vsi->rss_size) {
  9482. i40e_clear_rss_config_user(vsi);
  9483. dev_dbg(&pf->pdev->dev,
  9484. "discard user configured hash keys and lut\n");
  9485. }
  9486. /* Reset vsi->rss_size, as number of enabled queues changed */
  9487. qcount = vsi->num_queue_pairs / vsi->tc_config.numtc;
  9488. vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
  9489. i40e_pf_config_rss(pf);
  9490. }
  9491. dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n",
  9492. vsi->req_queue_pairs, pf->rss_size_max);
  9493. return pf->alloc_rss_size;
  9494. }
  9495. /**
  9496. * i40e_get_partition_bw_setting - Retrieve BW settings for this PF partition
  9497. * @pf: board private structure
  9498. **/
  9499. i40e_status i40e_get_partition_bw_setting(struct i40e_pf *pf)
  9500. {
  9501. i40e_status status;
  9502. bool min_valid, max_valid;
  9503. u32 max_bw, min_bw;
  9504. status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
  9505. &min_valid, &max_valid);
  9506. if (!status) {
  9507. if (min_valid)
  9508. pf->min_bw = min_bw;
  9509. if (max_valid)
  9510. pf->max_bw = max_bw;
  9511. }
  9512. return status;
  9513. }
  9514. /**
  9515. * i40e_set_partition_bw_setting - Set BW settings for this PF partition
  9516. * @pf: board private structure
  9517. **/
  9518. i40e_status i40e_set_partition_bw_setting(struct i40e_pf *pf)
  9519. {
  9520. struct i40e_aqc_configure_partition_bw_data bw_data;
  9521. i40e_status status;
  9522. /* Set the valid bit for this PF */
  9523. bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
  9524. bw_data.max_bw[pf->hw.pf_id] = pf->max_bw & I40E_ALT_BW_VALUE_MASK;
  9525. bw_data.min_bw[pf->hw.pf_id] = pf->min_bw & I40E_ALT_BW_VALUE_MASK;
  9526. /* Set the new bandwidths */
  9527. status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
  9528. return status;
  9529. }
  9530. /**
  9531. * i40e_commit_partition_bw_setting - Commit BW settings for this PF partition
  9532. * @pf: board private structure
  9533. **/
  9534. i40e_status i40e_commit_partition_bw_setting(struct i40e_pf *pf)
  9535. {
  9536. /* Commit temporary BW setting to permanent NVM image */
  9537. enum i40e_admin_queue_err last_aq_status;
  9538. i40e_status ret;
  9539. u16 nvm_word;
  9540. if (pf->hw.partition_id != 1) {
  9541. dev_info(&pf->pdev->dev,
  9542. "Commit BW only works on partition 1! This is partition %d",
  9543. pf->hw.partition_id);
  9544. ret = I40E_NOT_SUPPORTED;
  9545. goto bw_commit_out;
  9546. }
  9547. /* Acquire NVM for read access */
  9548. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
  9549. last_aq_status = pf->hw.aq.asq_last_status;
  9550. if (ret) {
  9551. dev_info(&pf->pdev->dev,
  9552. "Cannot acquire NVM for read access, err %s aq_err %s\n",
  9553. i40e_stat_str(&pf->hw, ret),
  9554. i40e_aq_str(&pf->hw, last_aq_status));
  9555. goto bw_commit_out;
  9556. }
  9557. /* Read word 0x10 of NVM - SW compatibility word 1 */
  9558. ret = i40e_aq_read_nvm(&pf->hw,
  9559. I40E_SR_NVM_CONTROL_WORD,
  9560. 0x10, sizeof(nvm_word), &nvm_word,
  9561. false, NULL);
  9562. /* Save off last admin queue command status before releasing
  9563. * the NVM
  9564. */
  9565. last_aq_status = pf->hw.aq.asq_last_status;
  9566. i40e_release_nvm(&pf->hw);
  9567. if (ret) {
  9568. dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
  9569. i40e_stat_str(&pf->hw, ret),
  9570. i40e_aq_str(&pf->hw, last_aq_status));
  9571. goto bw_commit_out;
  9572. }
  9573. /* Wait a bit for NVM release to complete */
  9574. msleep(50);
  9575. /* Acquire NVM for write access */
  9576. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
  9577. last_aq_status = pf->hw.aq.asq_last_status;
  9578. if (ret) {
  9579. dev_info(&pf->pdev->dev,
  9580. "Cannot acquire NVM for write access, err %s aq_err %s\n",
  9581. i40e_stat_str(&pf->hw, ret),
  9582. i40e_aq_str(&pf->hw, last_aq_status));
  9583. goto bw_commit_out;
  9584. }
  9585. /* Write it back out unchanged to initiate update NVM,
  9586. * which will force a write of the shadow (alt) RAM to
  9587. * the NVM - thus storing the bandwidth values permanently.
  9588. */
  9589. ret = i40e_aq_update_nvm(&pf->hw,
  9590. I40E_SR_NVM_CONTROL_WORD,
  9591. 0x10, sizeof(nvm_word),
  9592. &nvm_word, true, 0, NULL);
  9593. /* Save off last admin queue command status before releasing
  9594. * the NVM
  9595. */
  9596. last_aq_status = pf->hw.aq.asq_last_status;
  9597. i40e_release_nvm(&pf->hw);
  9598. if (ret)
  9599. dev_info(&pf->pdev->dev,
  9600. "BW settings NOT SAVED, err %s aq_err %s\n",
  9601. i40e_stat_str(&pf->hw, ret),
  9602. i40e_aq_str(&pf->hw, last_aq_status));
  9603. bw_commit_out:
  9604. return ret;
  9605. }
  9606. /**
  9607. * i40e_sw_init - Initialize general software structures (struct i40e_pf)
  9608. * @pf: board private structure to initialize
  9609. *
  9610. * i40e_sw_init initializes the Adapter private data structure.
  9611. * Fields are initialized based on PCI device information and
  9612. * OS network device settings (MTU size).
  9613. **/
  9614. static int i40e_sw_init(struct i40e_pf *pf)
  9615. {
  9616. int err = 0;
  9617. int size;
  9618. /* Set default capability flags */
  9619. pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
  9620. I40E_FLAG_MSI_ENABLED |
  9621. I40E_FLAG_MSIX_ENABLED;
  9622. /* Set default ITR */
  9623. pf->rx_itr_default = I40E_ITR_RX_DEF;
  9624. pf->tx_itr_default = I40E_ITR_TX_DEF;
  9625. /* Depending on PF configurations, it is possible that the RSS
  9626. * maximum might end up larger than the available queues
  9627. */
  9628. pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
  9629. pf->alloc_rss_size = 1;
  9630. pf->rss_table_size = pf->hw.func_caps.rss_table_size;
  9631. pf->rss_size_max = min_t(int, pf->rss_size_max,
  9632. pf->hw.func_caps.num_tx_qp);
  9633. if (pf->hw.func_caps.rss) {
  9634. pf->flags |= I40E_FLAG_RSS_ENABLED;
  9635. pf->alloc_rss_size = min_t(int, pf->rss_size_max,
  9636. num_online_cpus());
  9637. }
  9638. /* MFP mode enabled */
  9639. if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
  9640. pf->flags |= I40E_FLAG_MFP_ENABLED;
  9641. dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
  9642. if (i40e_get_partition_bw_setting(pf)) {
  9643. dev_warn(&pf->pdev->dev,
  9644. "Could not get partition bw settings\n");
  9645. } else {
  9646. dev_info(&pf->pdev->dev,
  9647. "Partition BW Min = %8.8x, Max = %8.8x\n",
  9648. pf->min_bw, pf->max_bw);
  9649. /* nudge the Tx scheduler */
  9650. i40e_set_partition_bw_setting(pf);
  9651. }
  9652. }
  9653. if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
  9654. (pf->hw.func_caps.fd_filters_best_effort > 0)) {
  9655. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  9656. pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
  9657. if (pf->flags & I40E_FLAG_MFP_ENABLED &&
  9658. pf->hw.num_partitions > 1)
  9659. dev_info(&pf->pdev->dev,
  9660. "Flow Director Sideband mode Disabled in MFP mode\n");
  9661. else
  9662. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  9663. pf->fdir_pf_filter_count =
  9664. pf->hw.func_caps.fd_filters_guaranteed;
  9665. pf->hw.fdir_shared_filter_count =
  9666. pf->hw.func_caps.fd_filters_best_effort;
  9667. }
  9668. if (pf->hw.mac.type == I40E_MAC_X722) {
  9669. pf->hw_features |= (I40E_HW_RSS_AQ_CAPABLE |
  9670. I40E_HW_128_QP_RSS_CAPABLE |
  9671. I40E_HW_ATR_EVICT_CAPABLE |
  9672. I40E_HW_WB_ON_ITR_CAPABLE |
  9673. I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE |
  9674. I40E_HW_NO_PCI_LINK_CHECK |
  9675. I40E_HW_USE_SET_LLDP_MIB |
  9676. I40E_HW_GENEVE_OFFLOAD_CAPABLE |
  9677. I40E_HW_PTP_L4_CAPABLE |
  9678. I40E_HW_WOL_MC_MAGIC_PKT_WAKE |
  9679. I40E_HW_OUTER_UDP_CSUM_CAPABLE);
  9680. #define I40E_FDEVICT_PCTYPE_DEFAULT 0xc03
  9681. if (rd32(&pf->hw, I40E_GLQF_FDEVICTENA(1)) !=
  9682. I40E_FDEVICT_PCTYPE_DEFAULT) {
  9683. dev_warn(&pf->pdev->dev,
  9684. "FD EVICT PCTYPES are not right, disable FD HW EVICT\n");
  9685. pf->hw_features &= ~I40E_HW_ATR_EVICT_CAPABLE;
  9686. }
  9687. } else if ((pf->hw.aq.api_maj_ver > 1) ||
  9688. ((pf->hw.aq.api_maj_ver == 1) &&
  9689. (pf->hw.aq.api_min_ver > 4))) {
  9690. /* Supported in FW API version higher than 1.4 */
  9691. pf->hw_features |= I40E_HW_GENEVE_OFFLOAD_CAPABLE;
  9692. }
  9693. /* Enable HW ATR eviction if possible */
  9694. if (pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE)
  9695. pf->flags |= I40E_FLAG_HW_ATR_EVICT_ENABLED;
  9696. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  9697. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
  9698. (pf->hw.aq.fw_maj_ver < 4))) {
  9699. pf->hw_features |= I40E_HW_RESTART_AUTONEG;
  9700. /* No DCB support for FW < v4.33 */
  9701. pf->hw_features |= I40E_HW_NO_DCB_SUPPORT;
  9702. }
  9703. /* Disable FW LLDP if FW < v4.3 */
  9704. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  9705. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
  9706. (pf->hw.aq.fw_maj_ver < 4)))
  9707. pf->hw_features |= I40E_HW_STOP_FW_LLDP;
  9708. /* Use the FW Set LLDP MIB API if FW > v4.40 */
  9709. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  9710. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
  9711. (pf->hw.aq.fw_maj_ver >= 5)))
  9712. pf->hw_features |= I40E_HW_USE_SET_LLDP_MIB;
  9713. /* Enable PTP L4 if FW > v6.0 */
  9714. if (pf->hw.mac.type == I40E_MAC_XL710 &&
  9715. pf->hw.aq.fw_maj_ver >= 6)
  9716. pf->hw_features |= I40E_HW_PTP_L4_CAPABLE;
  9717. if (pf->hw.func_caps.vmdq && num_online_cpus() != 1) {
  9718. pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
  9719. pf->flags |= I40E_FLAG_VMDQ_ENABLED;
  9720. pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
  9721. }
  9722. if (pf->hw.func_caps.iwarp && num_online_cpus() != 1) {
  9723. pf->flags |= I40E_FLAG_IWARP_ENABLED;
  9724. /* IWARP needs one extra vector for CQP just like MISC.*/
  9725. pf->num_iwarp_msix = (int)num_online_cpus() + 1;
  9726. }
  9727. #ifdef CONFIG_PCI_IOV
  9728. if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
  9729. pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
  9730. pf->flags |= I40E_FLAG_SRIOV_ENABLED;
  9731. pf->num_req_vfs = min_t(int,
  9732. pf->hw.func_caps.num_vfs,
  9733. I40E_MAX_VF_COUNT);
  9734. }
  9735. #endif /* CONFIG_PCI_IOV */
  9736. pf->eeprom_version = 0xDEAD;
  9737. pf->lan_veb = I40E_NO_VEB;
  9738. pf->lan_vsi = I40E_NO_VSI;
  9739. /* By default FW has this off for performance reasons */
  9740. pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
  9741. /* set up queue assignment tracking */
  9742. size = sizeof(struct i40e_lump_tracking)
  9743. + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
  9744. pf->qp_pile = kzalloc(size, GFP_KERNEL);
  9745. if (!pf->qp_pile) {
  9746. err = -ENOMEM;
  9747. goto sw_init_done;
  9748. }
  9749. pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
  9750. pf->qp_pile->search_hint = 0;
  9751. pf->tx_timeout_recovery_level = 1;
  9752. mutex_init(&pf->switch_mutex);
  9753. sw_init_done:
  9754. return err;
  9755. }
  9756. /**
  9757. * i40e_set_ntuple - set the ntuple feature flag and take action
  9758. * @pf: board private structure to initialize
  9759. * @features: the feature set that the stack is suggesting
  9760. *
  9761. * returns a bool to indicate if reset needs to happen
  9762. **/
  9763. bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
  9764. {
  9765. bool need_reset = false;
  9766. /* Check if Flow Director n-tuple support was enabled or disabled. If
  9767. * the state changed, we need to reset.
  9768. */
  9769. if (features & NETIF_F_NTUPLE) {
  9770. /* Enable filters and mark for reset */
  9771. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  9772. need_reset = true;
  9773. /* enable FD_SB only if there is MSI-X vector and no cloud
  9774. * filters exist
  9775. */
  9776. if (pf->num_fdsb_msix > 0 && !pf->num_cloud_filters) {
  9777. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  9778. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  9779. }
  9780. } else {
  9781. /* turn off filters, mark for reset and clear SW filter list */
  9782. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9783. need_reset = true;
  9784. i40e_fdir_filter_exit(pf);
  9785. }
  9786. pf->flags &= ~(I40E_FLAG_FD_SB_ENABLED |
  9787. I40E_FLAG_FD_SB_AUTO_DISABLED);
  9788. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  9789. /* reset fd counters */
  9790. pf->fd_add_err = 0;
  9791. pf->fd_atr_cnt = 0;
  9792. /* if ATR was auto disabled it can be re-enabled. */
  9793. if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) {
  9794. pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
  9795. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  9796. (I40E_DEBUG_FD & pf->hw.debug_mask))
  9797. dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
  9798. }
  9799. }
  9800. return need_reset;
  9801. }
  9802. /**
  9803. * i40e_clear_rss_lut - clear the rx hash lookup table
  9804. * @vsi: the VSI being configured
  9805. **/
  9806. static void i40e_clear_rss_lut(struct i40e_vsi *vsi)
  9807. {
  9808. struct i40e_pf *pf = vsi->back;
  9809. struct i40e_hw *hw = &pf->hw;
  9810. u16 vf_id = vsi->vf_id;
  9811. u8 i;
  9812. if (vsi->type == I40E_VSI_MAIN) {
  9813. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  9814. wr32(hw, I40E_PFQF_HLUT(i), 0);
  9815. } else if (vsi->type == I40E_VSI_SRIOV) {
  9816. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  9817. i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0);
  9818. } else {
  9819. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  9820. }
  9821. }
  9822. /**
  9823. * i40e_set_features - set the netdev feature flags
  9824. * @netdev: ptr to the netdev being adjusted
  9825. * @features: the feature set that the stack is suggesting
  9826. * Note: expects to be called while under rtnl_lock()
  9827. **/
  9828. static int i40e_set_features(struct net_device *netdev,
  9829. netdev_features_t features)
  9830. {
  9831. struct i40e_netdev_priv *np = netdev_priv(netdev);
  9832. struct i40e_vsi *vsi = np->vsi;
  9833. struct i40e_pf *pf = vsi->back;
  9834. bool need_reset;
  9835. if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
  9836. i40e_pf_config_rss(pf);
  9837. else if (!(features & NETIF_F_RXHASH) &&
  9838. netdev->features & NETIF_F_RXHASH)
  9839. i40e_clear_rss_lut(vsi);
  9840. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  9841. i40e_vlan_stripping_enable(vsi);
  9842. else
  9843. i40e_vlan_stripping_disable(vsi);
  9844. if (!(features & NETIF_F_HW_TC) && pf->num_cloud_filters) {
  9845. dev_err(&pf->pdev->dev,
  9846. "Offloaded tc filters active, can't turn hw_tc_offload off");
  9847. return -EINVAL;
  9848. }
  9849. need_reset = i40e_set_ntuple(pf, features);
  9850. if (need_reset)
  9851. i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
  9852. return 0;
  9853. }
  9854. /**
  9855. * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
  9856. * @pf: board private structure
  9857. * @port: The UDP port to look up
  9858. *
  9859. * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
  9860. **/
  9861. static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, u16 port)
  9862. {
  9863. u8 i;
  9864. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  9865. if (pf->udp_ports[i].port == port)
  9866. return i;
  9867. }
  9868. return i;
  9869. }
  9870. /**
  9871. * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
  9872. * @netdev: This physical port's netdev
  9873. * @ti: Tunnel endpoint information
  9874. **/
  9875. static void i40e_udp_tunnel_add(struct net_device *netdev,
  9876. struct udp_tunnel_info *ti)
  9877. {
  9878. struct i40e_netdev_priv *np = netdev_priv(netdev);
  9879. struct i40e_vsi *vsi = np->vsi;
  9880. struct i40e_pf *pf = vsi->back;
  9881. u16 port = ntohs(ti->port);
  9882. u8 next_idx;
  9883. u8 idx;
  9884. idx = i40e_get_udp_port_idx(pf, port);
  9885. /* Check if port already exists */
  9886. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  9887. netdev_info(netdev, "port %d already offloaded\n", port);
  9888. return;
  9889. }
  9890. /* Now check if there is space to add the new port */
  9891. next_idx = i40e_get_udp_port_idx(pf, 0);
  9892. if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  9893. netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n",
  9894. port);
  9895. return;
  9896. }
  9897. switch (ti->type) {
  9898. case UDP_TUNNEL_TYPE_VXLAN:
  9899. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
  9900. break;
  9901. case UDP_TUNNEL_TYPE_GENEVE:
  9902. if (!(pf->hw_features & I40E_HW_GENEVE_OFFLOAD_CAPABLE))
  9903. return;
  9904. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
  9905. break;
  9906. default:
  9907. return;
  9908. }
  9909. /* New port: add it and mark its index in the bitmap */
  9910. pf->udp_ports[next_idx].port = port;
  9911. pf->pending_udp_bitmap |= BIT_ULL(next_idx);
  9912. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  9913. }
  9914. /**
  9915. * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
  9916. * @netdev: This physical port's netdev
  9917. * @ti: Tunnel endpoint information
  9918. **/
  9919. static void i40e_udp_tunnel_del(struct net_device *netdev,
  9920. struct udp_tunnel_info *ti)
  9921. {
  9922. struct i40e_netdev_priv *np = netdev_priv(netdev);
  9923. struct i40e_vsi *vsi = np->vsi;
  9924. struct i40e_pf *pf = vsi->back;
  9925. u16 port = ntohs(ti->port);
  9926. u8 idx;
  9927. idx = i40e_get_udp_port_idx(pf, port);
  9928. /* Check if port already exists */
  9929. if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS)
  9930. goto not_found;
  9931. switch (ti->type) {
  9932. case UDP_TUNNEL_TYPE_VXLAN:
  9933. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN)
  9934. goto not_found;
  9935. break;
  9936. case UDP_TUNNEL_TYPE_GENEVE:
  9937. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE)
  9938. goto not_found;
  9939. break;
  9940. default:
  9941. goto not_found;
  9942. }
  9943. /* if port exists, set it to 0 (mark for deletion)
  9944. * and make it pending
  9945. */
  9946. pf->udp_ports[idx].port = 0;
  9947. pf->pending_udp_bitmap |= BIT_ULL(idx);
  9948. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  9949. return;
  9950. not_found:
  9951. netdev_warn(netdev, "UDP port %d was not found, not deleting\n",
  9952. port);
  9953. }
  9954. static int i40e_get_phys_port_id(struct net_device *netdev,
  9955. struct netdev_phys_item_id *ppid)
  9956. {
  9957. struct i40e_netdev_priv *np = netdev_priv(netdev);
  9958. struct i40e_pf *pf = np->vsi->back;
  9959. struct i40e_hw *hw = &pf->hw;
  9960. if (!(pf->hw_features & I40E_HW_PORT_ID_VALID))
  9961. return -EOPNOTSUPP;
  9962. ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
  9963. memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
  9964. return 0;
  9965. }
  9966. /**
  9967. * i40e_ndo_fdb_add - add an entry to the hardware database
  9968. * @ndm: the input from the stack
  9969. * @tb: pointer to array of nladdr (unused)
  9970. * @dev: the net device pointer
  9971. * @addr: the MAC address entry being added
  9972. * @flags: instructions from stack about fdb operation
  9973. */
  9974. static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  9975. struct net_device *dev,
  9976. const unsigned char *addr, u16 vid,
  9977. u16 flags)
  9978. {
  9979. struct i40e_netdev_priv *np = netdev_priv(dev);
  9980. struct i40e_pf *pf = np->vsi->back;
  9981. int err = 0;
  9982. if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
  9983. return -EOPNOTSUPP;
  9984. if (vid) {
  9985. pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
  9986. return -EINVAL;
  9987. }
  9988. /* Hardware does not support aging addresses so if a
  9989. * ndm_state is given only allow permanent addresses
  9990. */
  9991. if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
  9992. netdev_info(dev, "FDB only supports static addresses\n");
  9993. return -EINVAL;
  9994. }
  9995. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
  9996. err = dev_uc_add_excl(dev, addr);
  9997. else if (is_multicast_ether_addr(addr))
  9998. err = dev_mc_add_excl(dev, addr);
  9999. else
  10000. err = -EINVAL;
  10001. /* Only return duplicate errors if NLM_F_EXCL is set */
  10002. if (err == -EEXIST && !(flags & NLM_F_EXCL))
  10003. err = 0;
  10004. return err;
  10005. }
  10006. /**
  10007. * i40e_ndo_bridge_setlink - Set the hardware bridge mode
  10008. * @dev: the netdev being configured
  10009. * @nlh: RTNL message
  10010. *
  10011. * Inserts a new hardware bridge if not already created and
  10012. * enables the bridging mode requested (VEB or VEPA). If the
  10013. * hardware bridge has already been inserted and the request
  10014. * is to change the mode then that requires a PF reset to
  10015. * allow rebuild of the components with required hardware
  10016. * bridge mode enabled.
  10017. *
  10018. * Note: expects to be called while under rtnl_lock()
  10019. **/
  10020. static int i40e_ndo_bridge_setlink(struct net_device *dev,
  10021. struct nlmsghdr *nlh,
  10022. u16 flags)
  10023. {
  10024. struct i40e_netdev_priv *np = netdev_priv(dev);
  10025. struct i40e_vsi *vsi = np->vsi;
  10026. struct i40e_pf *pf = vsi->back;
  10027. struct i40e_veb *veb = NULL;
  10028. struct nlattr *attr, *br_spec;
  10029. int i, rem;
  10030. /* Only for PF VSI for now */
  10031. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  10032. return -EOPNOTSUPP;
  10033. /* Find the HW bridge for PF VSI */
  10034. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  10035. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  10036. veb = pf->veb[i];
  10037. }
  10038. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  10039. nla_for_each_nested(attr, br_spec, rem) {
  10040. __u16 mode;
  10041. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  10042. continue;
  10043. mode = nla_get_u16(attr);
  10044. if ((mode != BRIDGE_MODE_VEPA) &&
  10045. (mode != BRIDGE_MODE_VEB))
  10046. return -EINVAL;
  10047. /* Insert a new HW bridge */
  10048. if (!veb) {
  10049. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  10050. vsi->tc_config.enabled_tc);
  10051. if (veb) {
  10052. veb->bridge_mode = mode;
  10053. i40e_config_bridge_mode(veb);
  10054. } else {
  10055. /* No Bridge HW offload available */
  10056. return -ENOENT;
  10057. }
  10058. break;
  10059. } else if (mode != veb->bridge_mode) {
  10060. /* Existing HW bridge but different mode needs reset */
  10061. veb->bridge_mode = mode;
  10062. /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
  10063. if (mode == BRIDGE_MODE_VEB)
  10064. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  10065. else
  10066. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  10067. i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
  10068. break;
  10069. }
  10070. }
  10071. return 0;
  10072. }
  10073. /**
  10074. * i40e_ndo_bridge_getlink - Get the hardware bridge mode
  10075. * @skb: skb buff
  10076. * @pid: process id
  10077. * @seq: RTNL message seq #
  10078. * @dev: the netdev being configured
  10079. * @filter_mask: unused
  10080. * @nlflags: netlink flags passed in
  10081. *
  10082. * Return the mode in which the hardware bridge is operating in
  10083. * i.e VEB or VEPA.
  10084. **/
  10085. static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  10086. struct net_device *dev,
  10087. u32 __always_unused filter_mask,
  10088. int nlflags)
  10089. {
  10090. struct i40e_netdev_priv *np = netdev_priv(dev);
  10091. struct i40e_vsi *vsi = np->vsi;
  10092. struct i40e_pf *pf = vsi->back;
  10093. struct i40e_veb *veb = NULL;
  10094. int i;
  10095. /* Only for PF VSI for now */
  10096. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  10097. return -EOPNOTSUPP;
  10098. /* Find the HW bridge for the PF VSI */
  10099. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  10100. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  10101. veb = pf->veb[i];
  10102. }
  10103. if (!veb)
  10104. return 0;
  10105. return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
  10106. 0, 0, nlflags, filter_mask, NULL);
  10107. }
  10108. /**
  10109. * i40e_features_check - Validate encapsulated packet conforms to limits
  10110. * @skb: skb buff
  10111. * @dev: This physical port's netdev
  10112. * @features: Offload features that the stack believes apply
  10113. **/
  10114. static netdev_features_t i40e_features_check(struct sk_buff *skb,
  10115. struct net_device *dev,
  10116. netdev_features_t features)
  10117. {
  10118. size_t len;
  10119. /* No point in doing any of this if neither checksum nor GSO are
  10120. * being requested for this frame. We can rule out both by just
  10121. * checking for CHECKSUM_PARTIAL
  10122. */
  10123. if (skb->ip_summed != CHECKSUM_PARTIAL)
  10124. return features;
  10125. /* We cannot support GSO if the MSS is going to be less than
  10126. * 64 bytes. If it is then we need to drop support for GSO.
  10127. */
  10128. if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
  10129. features &= ~NETIF_F_GSO_MASK;
  10130. /* MACLEN can support at most 63 words */
  10131. len = skb_network_header(skb) - skb->data;
  10132. if (len & ~(63 * 2))
  10133. goto out_err;
  10134. /* IPLEN and EIPLEN can support at most 127 dwords */
  10135. len = skb_transport_header(skb) - skb_network_header(skb);
  10136. if (len & ~(127 * 4))
  10137. goto out_err;
  10138. if (skb->encapsulation) {
  10139. /* L4TUNLEN can support 127 words */
  10140. len = skb_inner_network_header(skb) - skb_transport_header(skb);
  10141. if (len & ~(127 * 2))
  10142. goto out_err;
  10143. /* IPLEN can support at most 127 dwords */
  10144. len = skb_inner_transport_header(skb) -
  10145. skb_inner_network_header(skb);
  10146. if (len & ~(127 * 4))
  10147. goto out_err;
  10148. }
  10149. /* No need to validate L4LEN as TCP is the only protocol with a
  10150. * a flexible value and we support all possible values supported
  10151. * by TCP, which is at most 15 dwords
  10152. */
  10153. return features;
  10154. out_err:
  10155. return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
  10156. }
  10157. /**
  10158. * i40e_xdp_setup - add/remove an XDP program
  10159. * @vsi: VSI to changed
  10160. * @prog: XDP program
  10161. **/
  10162. static int i40e_xdp_setup(struct i40e_vsi *vsi,
  10163. struct bpf_prog *prog)
  10164. {
  10165. int frame_size = vsi->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  10166. struct i40e_pf *pf = vsi->back;
  10167. struct bpf_prog *old_prog;
  10168. bool need_reset;
  10169. int i;
  10170. /* Don't allow frames that span over multiple buffers */
  10171. if (frame_size > vsi->rx_buf_len)
  10172. return -EINVAL;
  10173. if (!i40e_enabled_xdp_vsi(vsi) && !prog)
  10174. return 0;
  10175. /* When turning XDP on->off/off->on we reset and rebuild the rings. */
  10176. need_reset = (i40e_enabled_xdp_vsi(vsi) != !!prog);
  10177. if (need_reset)
  10178. i40e_prep_for_reset(pf, true);
  10179. old_prog = xchg(&vsi->xdp_prog, prog);
  10180. if (need_reset)
  10181. i40e_reset_and_rebuild(pf, true, true);
  10182. for (i = 0; i < vsi->num_queue_pairs; i++)
  10183. WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
  10184. if (old_prog)
  10185. bpf_prog_put(old_prog);
  10186. return 0;
  10187. }
  10188. /**
  10189. * i40e_xdp - implements ndo_bpf for i40e
  10190. * @dev: netdevice
  10191. * @xdp: XDP command
  10192. **/
  10193. static int i40e_xdp(struct net_device *dev,
  10194. struct netdev_bpf *xdp)
  10195. {
  10196. struct i40e_netdev_priv *np = netdev_priv(dev);
  10197. struct i40e_vsi *vsi = np->vsi;
  10198. if (vsi->type != I40E_VSI_MAIN)
  10199. return -EINVAL;
  10200. switch (xdp->command) {
  10201. case XDP_SETUP_PROG:
  10202. return i40e_xdp_setup(vsi, xdp->prog);
  10203. case XDP_QUERY_PROG:
  10204. xdp->prog_attached = i40e_enabled_xdp_vsi(vsi);
  10205. xdp->prog_id = vsi->xdp_prog ? vsi->xdp_prog->aux->id : 0;
  10206. return 0;
  10207. default:
  10208. return -EINVAL;
  10209. }
  10210. }
  10211. static const struct net_device_ops i40e_netdev_ops = {
  10212. .ndo_open = i40e_open,
  10213. .ndo_stop = i40e_close,
  10214. .ndo_start_xmit = i40e_lan_xmit_frame,
  10215. .ndo_get_stats64 = i40e_get_netdev_stats_struct,
  10216. .ndo_set_rx_mode = i40e_set_rx_mode,
  10217. .ndo_validate_addr = eth_validate_addr,
  10218. .ndo_set_mac_address = i40e_set_mac,
  10219. .ndo_change_mtu = i40e_change_mtu,
  10220. .ndo_do_ioctl = i40e_ioctl,
  10221. .ndo_tx_timeout = i40e_tx_timeout,
  10222. .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
  10223. .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
  10224. #ifdef CONFIG_NET_POLL_CONTROLLER
  10225. .ndo_poll_controller = i40e_netpoll,
  10226. #endif
  10227. .ndo_setup_tc = __i40e_setup_tc,
  10228. .ndo_set_features = i40e_set_features,
  10229. .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
  10230. .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
  10231. .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
  10232. .ndo_get_vf_config = i40e_ndo_get_vf_config,
  10233. .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
  10234. .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
  10235. .ndo_set_vf_trust = i40e_ndo_set_vf_trust,
  10236. .ndo_udp_tunnel_add = i40e_udp_tunnel_add,
  10237. .ndo_udp_tunnel_del = i40e_udp_tunnel_del,
  10238. .ndo_get_phys_port_id = i40e_get_phys_port_id,
  10239. .ndo_fdb_add = i40e_ndo_fdb_add,
  10240. .ndo_features_check = i40e_features_check,
  10241. .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
  10242. .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
  10243. .ndo_bpf = i40e_xdp,
  10244. };
  10245. /**
  10246. * i40e_config_netdev - Setup the netdev flags
  10247. * @vsi: the VSI being configured
  10248. *
  10249. * Returns 0 on success, negative value on failure
  10250. **/
  10251. static int i40e_config_netdev(struct i40e_vsi *vsi)
  10252. {
  10253. struct i40e_pf *pf = vsi->back;
  10254. struct i40e_hw *hw = &pf->hw;
  10255. struct i40e_netdev_priv *np;
  10256. struct net_device *netdev;
  10257. u8 broadcast[ETH_ALEN];
  10258. u8 mac_addr[ETH_ALEN];
  10259. int etherdev_size;
  10260. netdev_features_t hw_enc_features;
  10261. netdev_features_t hw_features;
  10262. etherdev_size = sizeof(struct i40e_netdev_priv);
  10263. netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
  10264. if (!netdev)
  10265. return -ENOMEM;
  10266. vsi->netdev = netdev;
  10267. np = netdev_priv(netdev);
  10268. np->vsi = vsi;
  10269. hw_enc_features = NETIF_F_SG |
  10270. NETIF_F_IP_CSUM |
  10271. NETIF_F_IPV6_CSUM |
  10272. NETIF_F_HIGHDMA |
  10273. NETIF_F_SOFT_FEATURES |
  10274. NETIF_F_TSO |
  10275. NETIF_F_TSO_ECN |
  10276. NETIF_F_TSO6 |
  10277. NETIF_F_GSO_GRE |
  10278. NETIF_F_GSO_GRE_CSUM |
  10279. NETIF_F_GSO_PARTIAL |
  10280. NETIF_F_GSO_UDP_TUNNEL |
  10281. NETIF_F_GSO_UDP_TUNNEL_CSUM |
  10282. NETIF_F_SCTP_CRC |
  10283. NETIF_F_RXHASH |
  10284. NETIF_F_RXCSUM |
  10285. 0;
  10286. if (!(pf->hw_features & I40E_HW_OUTER_UDP_CSUM_CAPABLE))
  10287. netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
  10288. netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
  10289. netdev->hw_enc_features |= hw_enc_features;
  10290. /* record features VLANs can make use of */
  10291. netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID;
  10292. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  10293. netdev->hw_features |= NETIF_F_NTUPLE | NETIF_F_HW_TC;
  10294. hw_features = hw_enc_features |
  10295. NETIF_F_HW_VLAN_CTAG_TX |
  10296. NETIF_F_HW_VLAN_CTAG_RX;
  10297. netdev->hw_features |= hw_features;
  10298. netdev->features |= hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
  10299. netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
  10300. if (vsi->type == I40E_VSI_MAIN) {
  10301. SET_NETDEV_DEV(netdev, &pf->pdev->dev);
  10302. ether_addr_copy(mac_addr, hw->mac.perm_addr);
  10303. /* The following steps are necessary for two reasons. First,
  10304. * some older NVM configurations load a default MAC-VLAN
  10305. * filter that will accept any tagged packet, and we want to
  10306. * replace this with a normal filter. Additionally, it is
  10307. * possible our MAC address was provided by the platform using
  10308. * Open Firmware or similar.
  10309. *
  10310. * Thus, we need to remove the default filter and install one
  10311. * specific to the MAC address.
  10312. */
  10313. i40e_rm_default_mac_filter(vsi, mac_addr);
  10314. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10315. i40e_add_mac_filter(vsi, mac_addr);
  10316. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10317. } else {
  10318. /* Relate the VSI_VMDQ name to the VSI_MAIN name. Note that we
  10319. * are still limited by IFNAMSIZ, but we're adding 'v%d\0' to
  10320. * the end, which is 4 bytes long, so force truncation of the
  10321. * original name by IFNAMSIZ - 4
  10322. */
  10323. snprintf(netdev->name, IFNAMSIZ, "%.*sv%%d",
  10324. IFNAMSIZ - 4,
  10325. pf->vsi[pf->lan_vsi]->netdev->name);
  10326. random_ether_addr(mac_addr);
  10327. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10328. i40e_add_mac_filter(vsi, mac_addr);
  10329. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10330. }
  10331. /* Add the broadcast filter so that we initially will receive
  10332. * broadcast packets. Note that when a new VLAN is first added the
  10333. * driver will convert all filters marked I40E_VLAN_ANY into VLAN
  10334. * specific filters as part of transitioning into "vlan" operation.
  10335. * When more VLANs are added, the driver will copy each existing MAC
  10336. * filter and add it for the new VLAN.
  10337. *
  10338. * Broadcast filters are handled specially by
  10339. * i40e_sync_filters_subtask, as the driver must to set the broadcast
  10340. * promiscuous bit instead of adding this directly as a MAC/VLAN
  10341. * filter. The subtask will update the correct broadcast promiscuous
  10342. * bits as VLANs become active or inactive.
  10343. */
  10344. eth_broadcast_addr(broadcast);
  10345. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10346. i40e_add_mac_filter(vsi, broadcast);
  10347. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10348. ether_addr_copy(netdev->dev_addr, mac_addr);
  10349. ether_addr_copy(netdev->perm_addr, mac_addr);
  10350. netdev->priv_flags |= IFF_UNICAST_FLT;
  10351. netdev->priv_flags |= IFF_SUPP_NOFCS;
  10352. /* Setup netdev TC information */
  10353. i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
  10354. netdev->netdev_ops = &i40e_netdev_ops;
  10355. netdev->watchdog_timeo = 5 * HZ;
  10356. i40e_set_ethtool_ops(netdev);
  10357. /* MTU range: 68 - 9706 */
  10358. netdev->min_mtu = ETH_MIN_MTU;
  10359. netdev->max_mtu = I40E_MAX_RXBUFFER - I40E_PACKET_HDR_PAD;
  10360. return 0;
  10361. }
  10362. /**
  10363. * i40e_vsi_delete - Delete a VSI from the switch
  10364. * @vsi: the VSI being removed
  10365. *
  10366. * Returns 0 on success, negative value on failure
  10367. **/
  10368. static void i40e_vsi_delete(struct i40e_vsi *vsi)
  10369. {
  10370. /* remove default VSI is not allowed */
  10371. if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
  10372. return;
  10373. i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
  10374. }
  10375. /**
  10376. * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
  10377. * @vsi: the VSI being queried
  10378. *
  10379. * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
  10380. **/
  10381. int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
  10382. {
  10383. struct i40e_veb *veb;
  10384. struct i40e_pf *pf = vsi->back;
  10385. /* Uplink is not a bridge so default to VEB */
  10386. if (vsi->veb_idx == I40E_NO_VEB)
  10387. return 1;
  10388. veb = pf->veb[vsi->veb_idx];
  10389. if (!veb) {
  10390. dev_info(&pf->pdev->dev,
  10391. "There is no veb associated with the bridge\n");
  10392. return -ENOENT;
  10393. }
  10394. /* Uplink is a bridge in VEPA mode */
  10395. if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
  10396. return 0;
  10397. } else {
  10398. /* Uplink is a bridge in VEB mode */
  10399. return 1;
  10400. }
  10401. /* VEPA is now default bridge, so return 0 */
  10402. return 0;
  10403. }
  10404. /**
  10405. * i40e_add_vsi - Add a VSI to the switch
  10406. * @vsi: the VSI being configured
  10407. *
  10408. * This initializes a VSI context depending on the VSI type to be added and
  10409. * passes it down to the add_vsi aq command.
  10410. **/
  10411. static int i40e_add_vsi(struct i40e_vsi *vsi)
  10412. {
  10413. int ret = -ENODEV;
  10414. struct i40e_pf *pf = vsi->back;
  10415. struct i40e_hw *hw = &pf->hw;
  10416. struct i40e_vsi_context ctxt;
  10417. struct i40e_mac_filter *f;
  10418. struct hlist_node *h;
  10419. int bkt;
  10420. u8 enabled_tc = 0x1; /* TC0 enabled */
  10421. int f_count = 0;
  10422. memset(&ctxt, 0, sizeof(ctxt));
  10423. switch (vsi->type) {
  10424. case I40E_VSI_MAIN:
  10425. /* The PF's main VSI is already setup as part of the
  10426. * device initialization, so we'll not bother with
  10427. * the add_vsi call, but we will retrieve the current
  10428. * VSI context.
  10429. */
  10430. ctxt.seid = pf->main_vsi_seid;
  10431. ctxt.pf_num = pf->hw.pf_id;
  10432. ctxt.vf_num = 0;
  10433. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  10434. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  10435. if (ret) {
  10436. dev_info(&pf->pdev->dev,
  10437. "couldn't get PF vsi config, err %s aq_err %s\n",
  10438. i40e_stat_str(&pf->hw, ret),
  10439. i40e_aq_str(&pf->hw,
  10440. pf->hw.aq.asq_last_status));
  10441. return -ENOENT;
  10442. }
  10443. vsi->info = ctxt.info;
  10444. vsi->info.valid_sections = 0;
  10445. vsi->seid = ctxt.seid;
  10446. vsi->id = ctxt.vsi_number;
  10447. enabled_tc = i40e_pf_get_tc_map(pf);
  10448. /* Source pruning is enabled by default, so the flag is
  10449. * negative logic - if it's set, we need to fiddle with
  10450. * the VSI to disable source pruning.
  10451. */
  10452. if (pf->flags & I40E_FLAG_SOURCE_PRUNING_DISABLED) {
  10453. memset(&ctxt, 0, sizeof(ctxt));
  10454. ctxt.seid = pf->main_vsi_seid;
  10455. ctxt.pf_num = pf->hw.pf_id;
  10456. ctxt.vf_num = 0;
  10457. ctxt.info.valid_sections |=
  10458. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10459. ctxt.info.switch_id =
  10460. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
  10461. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  10462. if (ret) {
  10463. dev_info(&pf->pdev->dev,
  10464. "update vsi failed, err %s aq_err %s\n",
  10465. i40e_stat_str(&pf->hw, ret),
  10466. i40e_aq_str(&pf->hw,
  10467. pf->hw.aq.asq_last_status));
  10468. ret = -ENOENT;
  10469. goto err;
  10470. }
  10471. }
  10472. /* MFP mode setup queue map and update VSI */
  10473. if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
  10474. !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
  10475. memset(&ctxt, 0, sizeof(ctxt));
  10476. ctxt.seid = pf->main_vsi_seid;
  10477. ctxt.pf_num = pf->hw.pf_id;
  10478. ctxt.vf_num = 0;
  10479. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  10480. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  10481. if (ret) {
  10482. dev_info(&pf->pdev->dev,
  10483. "update vsi failed, err %s aq_err %s\n",
  10484. i40e_stat_str(&pf->hw, ret),
  10485. i40e_aq_str(&pf->hw,
  10486. pf->hw.aq.asq_last_status));
  10487. ret = -ENOENT;
  10488. goto err;
  10489. }
  10490. /* update the local VSI info queue map */
  10491. i40e_vsi_update_queue_map(vsi, &ctxt);
  10492. vsi->info.valid_sections = 0;
  10493. } else {
  10494. /* Default/Main VSI is only enabled for TC0
  10495. * reconfigure it to enable all TCs that are
  10496. * available on the port in SFP mode.
  10497. * For MFP case the iSCSI PF would use this
  10498. * flow to enable LAN+iSCSI TC.
  10499. */
  10500. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  10501. if (ret) {
  10502. /* Single TC condition is not fatal,
  10503. * message and continue
  10504. */
  10505. dev_info(&pf->pdev->dev,
  10506. "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
  10507. enabled_tc,
  10508. i40e_stat_str(&pf->hw, ret),
  10509. i40e_aq_str(&pf->hw,
  10510. pf->hw.aq.asq_last_status));
  10511. }
  10512. }
  10513. break;
  10514. case I40E_VSI_FDIR:
  10515. ctxt.pf_num = hw->pf_id;
  10516. ctxt.vf_num = 0;
  10517. ctxt.uplink_seid = vsi->uplink_seid;
  10518. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  10519. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  10520. if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
  10521. (i40e_is_vsi_uplink_mode_veb(vsi))) {
  10522. ctxt.info.valid_sections |=
  10523. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10524. ctxt.info.switch_id =
  10525. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  10526. }
  10527. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  10528. break;
  10529. case I40E_VSI_VMDQ2:
  10530. ctxt.pf_num = hw->pf_id;
  10531. ctxt.vf_num = 0;
  10532. ctxt.uplink_seid = vsi->uplink_seid;
  10533. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  10534. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  10535. /* This VSI is connected to VEB so the switch_id
  10536. * should be set to zero by default.
  10537. */
  10538. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  10539. ctxt.info.valid_sections |=
  10540. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10541. ctxt.info.switch_id =
  10542. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  10543. }
  10544. /* Setup the VSI tx/rx queue map for TC0 only for now */
  10545. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  10546. break;
  10547. case I40E_VSI_SRIOV:
  10548. ctxt.pf_num = hw->pf_id;
  10549. ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
  10550. ctxt.uplink_seid = vsi->uplink_seid;
  10551. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  10552. ctxt.flags = I40E_AQ_VSI_TYPE_VF;
  10553. /* This VSI is connected to VEB so the switch_id
  10554. * should be set to zero by default.
  10555. */
  10556. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  10557. ctxt.info.valid_sections |=
  10558. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10559. ctxt.info.switch_id =
  10560. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  10561. }
  10562. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  10563. ctxt.info.valid_sections |=
  10564. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  10565. ctxt.info.queueing_opt_flags |=
  10566. (I40E_AQ_VSI_QUE_OPT_TCP_ENA |
  10567. I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI);
  10568. }
  10569. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  10570. ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
  10571. if (pf->vf[vsi->vf_id].spoofchk) {
  10572. ctxt.info.valid_sections |=
  10573. cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
  10574. ctxt.info.sec_flags |=
  10575. (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
  10576. I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
  10577. }
  10578. /* Setup the VSI tx/rx queue map for TC0 only for now */
  10579. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  10580. break;
  10581. case I40E_VSI_IWARP:
  10582. /* send down message to iWARP */
  10583. break;
  10584. default:
  10585. return -ENODEV;
  10586. }
  10587. if (vsi->type != I40E_VSI_MAIN) {
  10588. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  10589. if (ret) {
  10590. dev_info(&vsi->back->pdev->dev,
  10591. "add vsi failed, err %s aq_err %s\n",
  10592. i40e_stat_str(&pf->hw, ret),
  10593. i40e_aq_str(&pf->hw,
  10594. pf->hw.aq.asq_last_status));
  10595. ret = -ENOENT;
  10596. goto err;
  10597. }
  10598. vsi->info = ctxt.info;
  10599. vsi->info.valid_sections = 0;
  10600. vsi->seid = ctxt.seid;
  10601. vsi->id = ctxt.vsi_number;
  10602. }
  10603. vsi->active_filters = 0;
  10604. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  10605. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10606. /* If macvlan filters already exist, force them to get loaded */
  10607. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  10608. f->state = I40E_FILTER_NEW;
  10609. f_count++;
  10610. }
  10611. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10612. if (f_count) {
  10613. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  10614. pf->flags |= I40E_FLAG_FILTER_SYNC;
  10615. }
  10616. /* Update VSI BW information */
  10617. ret = i40e_vsi_get_bw_info(vsi);
  10618. if (ret) {
  10619. dev_info(&pf->pdev->dev,
  10620. "couldn't get vsi bw info, err %s aq_err %s\n",
  10621. i40e_stat_str(&pf->hw, ret),
  10622. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  10623. /* VSI is already added so not tearing that up */
  10624. ret = 0;
  10625. }
  10626. err:
  10627. return ret;
  10628. }
  10629. /**
  10630. * i40e_vsi_release - Delete a VSI and free its resources
  10631. * @vsi: the VSI being removed
  10632. *
  10633. * Returns 0 on success or < 0 on error
  10634. **/
  10635. int i40e_vsi_release(struct i40e_vsi *vsi)
  10636. {
  10637. struct i40e_mac_filter *f;
  10638. struct hlist_node *h;
  10639. struct i40e_veb *veb = NULL;
  10640. struct i40e_pf *pf;
  10641. u16 uplink_seid;
  10642. int i, n, bkt;
  10643. pf = vsi->back;
  10644. /* release of a VEB-owner or last VSI is not allowed */
  10645. if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
  10646. dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
  10647. vsi->seid, vsi->uplink_seid);
  10648. return -ENODEV;
  10649. }
  10650. if (vsi == pf->vsi[pf->lan_vsi] &&
  10651. !test_bit(__I40E_DOWN, pf->state)) {
  10652. dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
  10653. return -ENODEV;
  10654. }
  10655. uplink_seid = vsi->uplink_seid;
  10656. if (vsi->type != I40E_VSI_SRIOV) {
  10657. if (vsi->netdev_registered) {
  10658. vsi->netdev_registered = false;
  10659. if (vsi->netdev) {
  10660. /* results in a call to i40e_close() */
  10661. unregister_netdev(vsi->netdev);
  10662. }
  10663. } else {
  10664. i40e_vsi_close(vsi);
  10665. }
  10666. i40e_vsi_disable_irq(vsi);
  10667. }
  10668. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10669. /* clear the sync flag on all filters */
  10670. if (vsi->netdev) {
  10671. __dev_uc_unsync(vsi->netdev, NULL);
  10672. __dev_mc_unsync(vsi->netdev, NULL);
  10673. }
  10674. /* make sure any remaining filters are marked for deletion */
  10675. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
  10676. __i40e_del_filter(vsi, f);
  10677. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10678. i40e_sync_vsi_filters(vsi);
  10679. i40e_vsi_delete(vsi);
  10680. i40e_vsi_free_q_vectors(vsi);
  10681. if (vsi->netdev) {
  10682. free_netdev(vsi->netdev);
  10683. vsi->netdev = NULL;
  10684. }
  10685. i40e_vsi_clear_rings(vsi);
  10686. i40e_vsi_clear(vsi);
  10687. /* If this was the last thing on the VEB, except for the
  10688. * controlling VSI, remove the VEB, which puts the controlling
  10689. * VSI onto the next level down in the switch.
  10690. *
  10691. * Well, okay, there's one more exception here: don't remove
  10692. * the orphan VEBs yet. We'll wait for an explicit remove request
  10693. * from up the network stack.
  10694. */
  10695. for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
  10696. if (pf->vsi[i] &&
  10697. pf->vsi[i]->uplink_seid == uplink_seid &&
  10698. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  10699. n++; /* count the VSIs */
  10700. }
  10701. }
  10702. for (i = 0; i < I40E_MAX_VEB; i++) {
  10703. if (!pf->veb[i])
  10704. continue;
  10705. if (pf->veb[i]->uplink_seid == uplink_seid)
  10706. n++; /* count the VEBs */
  10707. if (pf->veb[i]->seid == uplink_seid)
  10708. veb = pf->veb[i];
  10709. }
  10710. if (n == 0 && veb && veb->uplink_seid != 0)
  10711. i40e_veb_release(veb);
  10712. return 0;
  10713. }
  10714. /**
  10715. * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
  10716. * @vsi: ptr to the VSI
  10717. *
  10718. * This should only be called after i40e_vsi_mem_alloc() which allocates the
  10719. * corresponding SW VSI structure and initializes num_queue_pairs for the
  10720. * newly allocated VSI.
  10721. *
  10722. * Returns 0 on success or negative on failure
  10723. **/
  10724. static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
  10725. {
  10726. int ret = -ENOENT;
  10727. struct i40e_pf *pf = vsi->back;
  10728. if (vsi->q_vectors[0]) {
  10729. dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
  10730. vsi->seid);
  10731. return -EEXIST;
  10732. }
  10733. if (vsi->base_vector) {
  10734. dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
  10735. vsi->seid, vsi->base_vector);
  10736. return -EEXIST;
  10737. }
  10738. ret = i40e_vsi_alloc_q_vectors(vsi);
  10739. if (ret) {
  10740. dev_info(&pf->pdev->dev,
  10741. "failed to allocate %d q_vector for VSI %d, ret=%d\n",
  10742. vsi->num_q_vectors, vsi->seid, ret);
  10743. vsi->num_q_vectors = 0;
  10744. goto vector_setup_out;
  10745. }
  10746. /* In Legacy mode, we do not have to get any other vector since we
  10747. * piggyback on the misc/ICR0 for queue interrupts.
  10748. */
  10749. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  10750. return ret;
  10751. if (vsi->num_q_vectors)
  10752. vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
  10753. vsi->num_q_vectors, vsi->idx);
  10754. if (vsi->base_vector < 0) {
  10755. dev_info(&pf->pdev->dev,
  10756. "failed to get tracking for %d vectors for VSI %d, err=%d\n",
  10757. vsi->num_q_vectors, vsi->seid, vsi->base_vector);
  10758. i40e_vsi_free_q_vectors(vsi);
  10759. ret = -ENOENT;
  10760. goto vector_setup_out;
  10761. }
  10762. vector_setup_out:
  10763. return ret;
  10764. }
  10765. /**
  10766. * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
  10767. * @vsi: pointer to the vsi.
  10768. *
  10769. * This re-allocates a vsi's queue resources.
  10770. *
  10771. * Returns pointer to the successfully allocated and configured VSI sw struct
  10772. * on success, otherwise returns NULL on failure.
  10773. **/
  10774. static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
  10775. {
  10776. u16 alloc_queue_pairs;
  10777. struct i40e_pf *pf;
  10778. u8 enabled_tc;
  10779. int ret;
  10780. if (!vsi)
  10781. return NULL;
  10782. pf = vsi->back;
  10783. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  10784. i40e_vsi_clear_rings(vsi);
  10785. i40e_vsi_free_arrays(vsi, false);
  10786. i40e_set_num_rings_in_vsi(vsi);
  10787. ret = i40e_vsi_alloc_arrays(vsi, false);
  10788. if (ret)
  10789. goto err_vsi;
  10790. alloc_queue_pairs = vsi->alloc_queue_pairs *
  10791. (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
  10792. ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
  10793. if (ret < 0) {
  10794. dev_info(&pf->pdev->dev,
  10795. "failed to get tracking for %d queues for VSI %d err %d\n",
  10796. alloc_queue_pairs, vsi->seid, ret);
  10797. goto err_vsi;
  10798. }
  10799. vsi->base_queue = ret;
  10800. /* Update the FW view of the VSI. Force a reset of TC and queue
  10801. * layout configurations.
  10802. */
  10803. enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  10804. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  10805. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  10806. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  10807. if (vsi->type == I40E_VSI_MAIN)
  10808. i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr);
  10809. /* assign it some queues */
  10810. ret = i40e_alloc_rings(vsi);
  10811. if (ret)
  10812. goto err_rings;
  10813. /* map all of the rings to the q_vectors */
  10814. i40e_vsi_map_rings_to_vectors(vsi);
  10815. return vsi;
  10816. err_rings:
  10817. i40e_vsi_free_q_vectors(vsi);
  10818. if (vsi->netdev_registered) {
  10819. vsi->netdev_registered = false;
  10820. unregister_netdev(vsi->netdev);
  10821. free_netdev(vsi->netdev);
  10822. vsi->netdev = NULL;
  10823. }
  10824. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  10825. err_vsi:
  10826. i40e_vsi_clear(vsi);
  10827. return NULL;
  10828. }
  10829. /**
  10830. * i40e_vsi_setup - Set up a VSI by a given type
  10831. * @pf: board private structure
  10832. * @type: VSI type
  10833. * @uplink_seid: the switch element to link to
  10834. * @param1: usage depends upon VSI type. For VF types, indicates VF id
  10835. *
  10836. * This allocates the sw VSI structure and its queue resources, then add a VSI
  10837. * to the identified VEB.
  10838. *
  10839. * Returns pointer to the successfully allocated and configure VSI sw struct on
  10840. * success, otherwise returns NULL on failure.
  10841. **/
  10842. struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
  10843. u16 uplink_seid, u32 param1)
  10844. {
  10845. struct i40e_vsi *vsi = NULL;
  10846. struct i40e_veb *veb = NULL;
  10847. u16 alloc_queue_pairs;
  10848. int ret, i;
  10849. int v_idx;
  10850. /* The requested uplink_seid must be either
  10851. * - the PF's port seid
  10852. * no VEB is needed because this is the PF
  10853. * or this is a Flow Director special case VSI
  10854. * - seid of an existing VEB
  10855. * - seid of a VSI that owns an existing VEB
  10856. * - seid of a VSI that doesn't own a VEB
  10857. * a new VEB is created and the VSI becomes the owner
  10858. * - seid of the PF VSI, which is what creates the first VEB
  10859. * this is a special case of the previous
  10860. *
  10861. * Find which uplink_seid we were given and create a new VEB if needed
  10862. */
  10863. for (i = 0; i < I40E_MAX_VEB; i++) {
  10864. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
  10865. veb = pf->veb[i];
  10866. break;
  10867. }
  10868. }
  10869. if (!veb && uplink_seid != pf->mac_seid) {
  10870. for (i = 0; i < pf->num_alloc_vsi; i++) {
  10871. if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
  10872. vsi = pf->vsi[i];
  10873. break;
  10874. }
  10875. }
  10876. if (!vsi) {
  10877. dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
  10878. uplink_seid);
  10879. return NULL;
  10880. }
  10881. if (vsi->uplink_seid == pf->mac_seid)
  10882. veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
  10883. vsi->tc_config.enabled_tc);
  10884. else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
  10885. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  10886. vsi->tc_config.enabled_tc);
  10887. if (veb) {
  10888. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
  10889. dev_info(&vsi->back->pdev->dev,
  10890. "New VSI creation error, uplink seid of LAN VSI expected.\n");
  10891. return NULL;
  10892. }
  10893. /* We come up by default in VEPA mode if SRIOV is not
  10894. * already enabled, in which case we can't force VEPA
  10895. * mode.
  10896. */
  10897. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  10898. veb->bridge_mode = BRIDGE_MODE_VEPA;
  10899. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  10900. }
  10901. i40e_config_bridge_mode(veb);
  10902. }
  10903. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  10904. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  10905. veb = pf->veb[i];
  10906. }
  10907. if (!veb) {
  10908. dev_info(&pf->pdev->dev, "couldn't add VEB\n");
  10909. return NULL;
  10910. }
  10911. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  10912. uplink_seid = veb->seid;
  10913. }
  10914. /* get vsi sw struct */
  10915. v_idx = i40e_vsi_mem_alloc(pf, type);
  10916. if (v_idx < 0)
  10917. goto err_alloc;
  10918. vsi = pf->vsi[v_idx];
  10919. if (!vsi)
  10920. goto err_alloc;
  10921. vsi->type = type;
  10922. vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
  10923. if (type == I40E_VSI_MAIN)
  10924. pf->lan_vsi = v_idx;
  10925. else if (type == I40E_VSI_SRIOV)
  10926. vsi->vf_id = param1;
  10927. /* assign it some queues */
  10928. alloc_queue_pairs = vsi->alloc_queue_pairs *
  10929. (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
  10930. ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
  10931. if (ret < 0) {
  10932. dev_info(&pf->pdev->dev,
  10933. "failed to get tracking for %d queues for VSI %d err=%d\n",
  10934. alloc_queue_pairs, vsi->seid, ret);
  10935. goto err_vsi;
  10936. }
  10937. vsi->base_queue = ret;
  10938. /* get a VSI from the hardware */
  10939. vsi->uplink_seid = uplink_seid;
  10940. ret = i40e_add_vsi(vsi);
  10941. if (ret)
  10942. goto err_vsi;
  10943. switch (vsi->type) {
  10944. /* setup the netdev if needed */
  10945. case I40E_VSI_MAIN:
  10946. case I40E_VSI_VMDQ2:
  10947. ret = i40e_config_netdev(vsi);
  10948. if (ret)
  10949. goto err_netdev;
  10950. ret = register_netdev(vsi->netdev);
  10951. if (ret)
  10952. goto err_netdev;
  10953. vsi->netdev_registered = true;
  10954. netif_carrier_off(vsi->netdev);
  10955. #ifdef CONFIG_I40E_DCB
  10956. /* Setup DCB netlink interface */
  10957. i40e_dcbnl_setup(vsi);
  10958. #endif /* CONFIG_I40E_DCB */
  10959. /* fall through */
  10960. case I40E_VSI_FDIR:
  10961. /* set up vectors and rings if needed */
  10962. ret = i40e_vsi_setup_vectors(vsi);
  10963. if (ret)
  10964. goto err_msix;
  10965. ret = i40e_alloc_rings(vsi);
  10966. if (ret)
  10967. goto err_rings;
  10968. /* map all of the rings to the q_vectors */
  10969. i40e_vsi_map_rings_to_vectors(vsi);
  10970. i40e_vsi_reset_stats(vsi);
  10971. break;
  10972. default:
  10973. /* no netdev or rings for the other VSI types */
  10974. break;
  10975. }
  10976. if ((pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) &&
  10977. (vsi->type == I40E_VSI_VMDQ2)) {
  10978. ret = i40e_vsi_config_rss(vsi);
  10979. }
  10980. return vsi;
  10981. err_rings:
  10982. i40e_vsi_free_q_vectors(vsi);
  10983. err_msix:
  10984. if (vsi->netdev_registered) {
  10985. vsi->netdev_registered = false;
  10986. unregister_netdev(vsi->netdev);
  10987. free_netdev(vsi->netdev);
  10988. vsi->netdev = NULL;
  10989. }
  10990. err_netdev:
  10991. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  10992. err_vsi:
  10993. i40e_vsi_clear(vsi);
  10994. err_alloc:
  10995. return NULL;
  10996. }
  10997. /**
  10998. * i40e_veb_get_bw_info - Query VEB BW information
  10999. * @veb: the veb to query
  11000. *
  11001. * Query the Tx scheduler BW configuration data for given VEB
  11002. **/
  11003. static int i40e_veb_get_bw_info(struct i40e_veb *veb)
  11004. {
  11005. struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
  11006. struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
  11007. struct i40e_pf *pf = veb->pf;
  11008. struct i40e_hw *hw = &pf->hw;
  11009. u32 tc_bw_max;
  11010. int ret = 0;
  11011. int i;
  11012. ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
  11013. &bw_data, NULL);
  11014. if (ret) {
  11015. dev_info(&pf->pdev->dev,
  11016. "query veb bw config failed, err %s aq_err %s\n",
  11017. i40e_stat_str(&pf->hw, ret),
  11018. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  11019. goto out;
  11020. }
  11021. ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
  11022. &ets_data, NULL);
  11023. if (ret) {
  11024. dev_info(&pf->pdev->dev,
  11025. "query veb bw ets config failed, err %s aq_err %s\n",
  11026. i40e_stat_str(&pf->hw, ret),
  11027. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  11028. goto out;
  11029. }
  11030. veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
  11031. veb->bw_max_quanta = ets_data.tc_bw_max;
  11032. veb->is_abs_credits = bw_data.absolute_credits_enable;
  11033. veb->enabled_tc = ets_data.tc_valid_bits;
  11034. tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
  11035. (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
  11036. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  11037. veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
  11038. veb->bw_tc_limit_credits[i] =
  11039. le16_to_cpu(bw_data.tc_bw_limits[i]);
  11040. veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
  11041. }
  11042. out:
  11043. return ret;
  11044. }
  11045. /**
  11046. * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
  11047. * @pf: board private structure
  11048. *
  11049. * On error: returns error code (negative)
  11050. * On success: returns vsi index in PF (positive)
  11051. **/
  11052. static int i40e_veb_mem_alloc(struct i40e_pf *pf)
  11053. {
  11054. int ret = -ENOENT;
  11055. struct i40e_veb *veb;
  11056. int i;
  11057. /* Need to protect the allocation of switch elements at the PF level */
  11058. mutex_lock(&pf->switch_mutex);
  11059. /* VEB list may be fragmented if VEB creation/destruction has
  11060. * been happening. We can afford to do a quick scan to look
  11061. * for any free slots in the list.
  11062. *
  11063. * find next empty veb slot, looping back around if necessary
  11064. */
  11065. i = 0;
  11066. while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
  11067. i++;
  11068. if (i >= I40E_MAX_VEB) {
  11069. ret = -ENOMEM;
  11070. goto err_alloc_veb; /* out of VEB slots! */
  11071. }
  11072. veb = kzalloc(sizeof(*veb), GFP_KERNEL);
  11073. if (!veb) {
  11074. ret = -ENOMEM;
  11075. goto err_alloc_veb;
  11076. }
  11077. veb->pf = pf;
  11078. veb->idx = i;
  11079. veb->enabled_tc = 1;
  11080. pf->veb[i] = veb;
  11081. ret = i;
  11082. err_alloc_veb:
  11083. mutex_unlock(&pf->switch_mutex);
  11084. return ret;
  11085. }
  11086. /**
  11087. * i40e_switch_branch_release - Delete a branch of the switch tree
  11088. * @branch: where to start deleting
  11089. *
  11090. * This uses recursion to find the tips of the branch to be
  11091. * removed, deleting until we get back to and can delete this VEB.
  11092. **/
  11093. static void i40e_switch_branch_release(struct i40e_veb *branch)
  11094. {
  11095. struct i40e_pf *pf = branch->pf;
  11096. u16 branch_seid = branch->seid;
  11097. u16 veb_idx = branch->idx;
  11098. int i;
  11099. /* release any VEBs on this VEB - RECURSION */
  11100. for (i = 0; i < I40E_MAX_VEB; i++) {
  11101. if (!pf->veb[i])
  11102. continue;
  11103. if (pf->veb[i]->uplink_seid == branch->seid)
  11104. i40e_switch_branch_release(pf->veb[i]);
  11105. }
  11106. /* Release the VSIs on this VEB, but not the owner VSI.
  11107. *
  11108. * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
  11109. * the VEB itself, so don't use (*branch) after this loop.
  11110. */
  11111. for (i = 0; i < pf->num_alloc_vsi; i++) {
  11112. if (!pf->vsi[i])
  11113. continue;
  11114. if (pf->vsi[i]->uplink_seid == branch_seid &&
  11115. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  11116. i40e_vsi_release(pf->vsi[i]);
  11117. }
  11118. }
  11119. /* There's one corner case where the VEB might not have been
  11120. * removed, so double check it here and remove it if needed.
  11121. * This case happens if the veb was created from the debugfs
  11122. * commands and no VSIs were added to it.
  11123. */
  11124. if (pf->veb[veb_idx])
  11125. i40e_veb_release(pf->veb[veb_idx]);
  11126. }
  11127. /**
  11128. * i40e_veb_clear - remove veb struct
  11129. * @veb: the veb to remove
  11130. **/
  11131. static void i40e_veb_clear(struct i40e_veb *veb)
  11132. {
  11133. if (!veb)
  11134. return;
  11135. if (veb->pf) {
  11136. struct i40e_pf *pf = veb->pf;
  11137. mutex_lock(&pf->switch_mutex);
  11138. if (pf->veb[veb->idx] == veb)
  11139. pf->veb[veb->idx] = NULL;
  11140. mutex_unlock(&pf->switch_mutex);
  11141. }
  11142. kfree(veb);
  11143. }
  11144. /**
  11145. * i40e_veb_release - Delete a VEB and free its resources
  11146. * @veb: the VEB being removed
  11147. **/
  11148. void i40e_veb_release(struct i40e_veb *veb)
  11149. {
  11150. struct i40e_vsi *vsi = NULL;
  11151. struct i40e_pf *pf;
  11152. int i, n = 0;
  11153. pf = veb->pf;
  11154. /* find the remaining VSI and check for extras */
  11155. for (i = 0; i < pf->num_alloc_vsi; i++) {
  11156. if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
  11157. n++;
  11158. vsi = pf->vsi[i];
  11159. }
  11160. }
  11161. if (n != 1) {
  11162. dev_info(&pf->pdev->dev,
  11163. "can't remove VEB %d with %d VSIs left\n",
  11164. veb->seid, n);
  11165. return;
  11166. }
  11167. /* move the remaining VSI to uplink veb */
  11168. vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
  11169. if (veb->uplink_seid) {
  11170. vsi->uplink_seid = veb->uplink_seid;
  11171. if (veb->uplink_seid == pf->mac_seid)
  11172. vsi->veb_idx = I40E_NO_VEB;
  11173. else
  11174. vsi->veb_idx = veb->veb_idx;
  11175. } else {
  11176. /* floating VEB */
  11177. vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  11178. vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
  11179. }
  11180. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  11181. i40e_veb_clear(veb);
  11182. }
  11183. /**
  11184. * i40e_add_veb - create the VEB in the switch
  11185. * @veb: the VEB to be instantiated
  11186. * @vsi: the controlling VSI
  11187. **/
  11188. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
  11189. {
  11190. struct i40e_pf *pf = veb->pf;
  11191. bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
  11192. int ret;
  11193. ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
  11194. veb->enabled_tc, false,
  11195. &veb->seid, enable_stats, NULL);
  11196. /* get a VEB from the hardware */
  11197. if (ret) {
  11198. dev_info(&pf->pdev->dev,
  11199. "couldn't add VEB, err %s aq_err %s\n",
  11200. i40e_stat_str(&pf->hw, ret),
  11201. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11202. return -EPERM;
  11203. }
  11204. /* get statistics counter */
  11205. ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
  11206. &veb->stats_idx, NULL, NULL, NULL);
  11207. if (ret) {
  11208. dev_info(&pf->pdev->dev,
  11209. "couldn't get VEB statistics idx, err %s aq_err %s\n",
  11210. i40e_stat_str(&pf->hw, ret),
  11211. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11212. return -EPERM;
  11213. }
  11214. ret = i40e_veb_get_bw_info(veb);
  11215. if (ret) {
  11216. dev_info(&pf->pdev->dev,
  11217. "couldn't get VEB bw info, err %s aq_err %s\n",
  11218. i40e_stat_str(&pf->hw, ret),
  11219. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11220. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  11221. return -ENOENT;
  11222. }
  11223. vsi->uplink_seid = veb->seid;
  11224. vsi->veb_idx = veb->idx;
  11225. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  11226. return 0;
  11227. }
  11228. /**
  11229. * i40e_veb_setup - Set up a VEB
  11230. * @pf: board private structure
  11231. * @flags: VEB setup flags
  11232. * @uplink_seid: the switch element to link to
  11233. * @vsi_seid: the initial VSI seid
  11234. * @enabled_tc: Enabled TC bit-map
  11235. *
  11236. * This allocates the sw VEB structure and links it into the switch
  11237. * It is possible and legal for this to be a duplicate of an already
  11238. * existing VEB. It is also possible for both uplink and vsi seids
  11239. * to be zero, in order to create a floating VEB.
  11240. *
  11241. * Returns pointer to the successfully allocated VEB sw struct on
  11242. * success, otherwise returns NULL on failure.
  11243. **/
  11244. struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
  11245. u16 uplink_seid, u16 vsi_seid,
  11246. u8 enabled_tc)
  11247. {
  11248. struct i40e_veb *veb, *uplink_veb = NULL;
  11249. int vsi_idx, veb_idx;
  11250. int ret;
  11251. /* if one seid is 0, the other must be 0 to create a floating relay */
  11252. if ((uplink_seid == 0 || vsi_seid == 0) &&
  11253. (uplink_seid + vsi_seid != 0)) {
  11254. dev_info(&pf->pdev->dev,
  11255. "one, not both seid's are 0: uplink=%d vsi=%d\n",
  11256. uplink_seid, vsi_seid);
  11257. return NULL;
  11258. }
  11259. /* make sure there is such a vsi and uplink */
  11260. for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
  11261. if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
  11262. break;
  11263. if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
  11264. dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
  11265. vsi_seid);
  11266. return NULL;
  11267. }
  11268. if (uplink_seid && uplink_seid != pf->mac_seid) {
  11269. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  11270. if (pf->veb[veb_idx] &&
  11271. pf->veb[veb_idx]->seid == uplink_seid) {
  11272. uplink_veb = pf->veb[veb_idx];
  11273. break;
  11274. }
  11275. }
  11276. if (!uplink_veb) {
  11277. dev_info(&pf->pdev->dev,
  11278. "uplink seid %d not found\n", uplink_seid);
  11279. return NULL;
  11280. }
  11281. }
  11282. /* get veb sw struct */
  11283. veb_idx = i40e_veb_mem_alloc(pf);
  11284. if (veb_idx < 0)
  11285. goto err_alloc;
  11286. veb = pf->veb[veb_idx];
  11287. veb->flags = flags;
  11288. veb->uplink_seid = uplink_seid;
  11289. veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
  11290. veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
  11291. /* create the VEB in the switch */
  11292. ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
  11293. if (ret)
  11294. goto err_veb;
  11295. if (vsi_idx == pf->lan_vsi)
  11296. pf->lan_veb = veb->idx;
  11297. return veb;
  11298. err_veb:
  11299. i40e_veb_clear(veb);
  11300. err_alloc:
  11301. return NULL;
  11302. }
  11303. /**
  11304. * i40e_setup_pf_switch_element - set PF vars based on switch type
  11305. * @pf: board private structure
  11306. * @ele: element we are building info from
  11307. * @num_reported: total number of elements
  11308. * @printconfig: should we print the contents
  11309. *
  11310. * helper function to assist in extracting a few useful SEID values.
  11311. **/
  11312. static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
  11313. struct i40e_aqc_switch_config_element_resp *ele,
  11314. u16 num_reported, bool printconfig)
  11315. {
  11316. u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
  11317. u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
  11318. u8 element_type = ele->element_type;
  11319. u16 seid = le16_to_cpu(ele->seid);
  11320. if (printconfig)
  11321. dev_info(&pf->pdev->dev,
  11322. "type=%d seid=%d uplink=%d downlink=%d\n",
  11323. element_type, seid, uplink_seid, downlink_seid);
  11324. switch (element_type) {
  11325. case I40E_SWITCH_ELEMENT_TYPE_MAC:
  11326. pf->mac_seid = seid;
  11327. break;
  11328. case I40E_SWITCH_ELEMENT_TYPE_VEB:
  11329. /* Main VEB? */
  11330. if (uplink_seid != pf->mac_seid)
  11331. break;
  11332. if (pf->lan_veb == I40E_NO_VEB) {
  11333. int v;
  11334. /* find existing or else empty VEB */
  11335. for (v = 0; v < I40E_MAX_VEB; v++) {
  11336. if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
  11337. pf->lan_veb = v;
  11338. break;
  11339. }
  11340. }
  11341. if (pf->lan_veb == I40E_NO_VEB) {
  11342. v = i40e_veb_mem_alloc(pf);
  11343. if (v < 0)
  11344. break;
  11345. pf->lan_veb = v;
  11346. }
  11347. }
  11348. pf->veb[pf->lan_veb]->seid = seid;
  11349. pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
  11350. pf->veb[pf->lan_veb]->pf = pf;
  11351. pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
  11352. break;
  11353. case I40E_SWITCH_ELEMENT_TYPE_VSI:
  11354. if (num_reported != 1)
  11355. break;
  11356. /* This is immediately after a reset so we can assume this is
  11357. * the PF's VSI
  11358. */
  11359. pf->mac_seid = uplink_seid;
  11360. pf->pf_seid = downlink_seid;
  11361. pf->main_vsi_seid = seid;
  11362. if (printconfig)
  11363. dev_info(&pf->pdev->dev,
  11364. "pf_seid=%d main_vsi_seid=%d\n",
  11365. pf->pf_seid, pf->main_vsi_seid);
  11366. break;
  11367. case I40E_SWITCH_ELEMENT_TYPE_PF:
  11368. case I40E_SWITCH_ELEMENT_TYPE_VF:
  11369. case I40E_SWITCH_ELEMENT_TYPE_EMP:
  11370. case I40E_SWITCH_ELEMENT_TYPE_BMC:
  11371. case I40E_SWITCH_ELEMENT_TYPE_PE:
  11372. case I40E_SWITCH_ELEMENT_TYPE_PA:
  11373. /* ignore these for now */
  11374. break;
  11375. default:
  11376. dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
  11377. element_type, seid);
  11378. break;
  11379. }
  11380. }
  11381. /**
  11382. * i40e_fetch_switch_configuration - Get switch config from firmware
  11383. * @pf: board private structure
  11384. * @printconfig: should we print the contents
  11385. *
  11386. * Get the current switch configuration from the device and
  11387. * extract a few useful SEID values.
  11388. **/
  11389. int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
  11390. {
  11391. struct i40e_aqc_get_switch_config_resp *sw_config;
  11392. u16 next_seid = 0;
  11393. int ret = 0;
  11394. u8 *aq_buf;
  11395. int i;
  11396. aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
  11397. if (!aq_buf)
  11398. return -ENOMEM;
  11399. sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
  11400. do {
  11401. u16 num_reported, num_total;
  11402. ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
  11403. I40E_AQ_LARGE_BUF,
  11404. &next_seid, NULL);
  11405. if (ret) {
  11406. dev_info(&pf->pdev->dev,
  11407. "get switch config failed err %s aq_err %s\n",
  11408. i40e_stat_str(&pf->hw, ret),
  11409. i40e_aq_str(&pf->hw,
  11410. pf->hw.aq.asq_last_status));
  11411. kfree(aq_buf);
  11412. return -ENOENT;
  11413. }
  11414. num_reported = le16_to_cpu(sw_config->header.num_reported);
  11415. num_total = le16_to_cpu(sw_config->header.num_total);
  11416. if (printconfig)
  11417. dev_info(&pf->pdev->dev,
  11418. "header: %d reported %d total\n",
  11419. num_reported, num_total);
  11420. for (i = 0; i < num_reported; i++) {
  11421. struct i40e_aqc_switch_config_element_resp *ele =
  11422. &sw_config->element[i];
  11423. i40e_setup_pf_switch_element(pf, ele, num_reported,
  11424. printconfig);
  11425. }
  11426. } while (next_seid != 0);
  11427. kfree(aq_buf);
  11428. return ret;
  11429. }
  11430. /**
  11431. * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
  11432. * @pf: board private structure
  11433. * @reinit: if the Main VSI needs to re-initialized.
  11434. *
  11435. * Returns 0 on success, negative value on failure
  11436. **/
  11437. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
  11438. {
  11439. u16 flags = 0;
  11440. int ret;
  11441. /* find out what's out there already */
  11442. ret = i40e_fetch_switch_configuration(pf, false);
  11443. if (ret) {
  11444. dev_info(&pf->pdev->dev,
  11445. "couldn't fetch switch config, err %s aq_err %s\n",
  11446. i40e_stat_str(&pf->hw, ret),
  11447. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11448. return ret;
  11449. }
  11450. i40e_pf_reset_stats(pf);
  11451. /* set the switch config bit for the whole device to
  11452. * support limited promisc or true promisc
  11453. * when user requests promisc. The default is limited
  11454. * promisc.
  11455. */
  11456. if ((pf->hw.pf_id == 0) &&
  11457. !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
  11458. flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  11459. pf->last_sw_conf_flags = flags;
  11460. }
  11461. if (pf->hw.pf_id == 0) {
  11462. u16 valid_flags;
  11463. valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  11464. ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, 0,
  11465. NULL);
  11466. if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
  11467. dev_info(&pf->pdev->dev,
  11468. "couldn't set switch config bits, err %s aq_err %s\n",
  11469. i40e_stat_str(&pf->hw, ret),
  11470. i40e_aq_str(&pf->hw,
  11471. pf->hw.aq.asq_last_status));
  11472. /* not a fatal problem, just keep going */
  11473. }
  11474. pf->last_sw_conf_valid_flags = valid_flags;
  11475. }
  11476. /* first time setup */
  11477. if (pf->lan_vsi == I40E_NO_VSI || reinit) {
  11478. struct i40e_vsi *vsi = NULL;
  11479. u16 uplink_seid;
  11480. /* Set up the PF VSI associated with the PF's main VSI
  11481. * that is already in the HW switch
  11482. */
  11483. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  11484. uplink_seid = pf->veb[pf->lan_veb]->seid;
  11485. else
  11486. uplink_seid = pf->mac_seid;
  11487. if (pf->lan_vsi == I40E_NO_VSI)
  11488. vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
  11489. else if (reinit)
  11490. vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
  11491. if (!vsi) {
  11492. dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
  11493. i40e_cloud_filter_exit(pf);
  11494. i40e_fdir_teardown(pf);
  11495. return -EAGAIN;
  11496. }
  11497. } else {
  11498. /* force a reset of TC and queue layout configurations */
  11499. u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  11500. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  11501. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  11502. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  11503. }
  11504. i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
  11505. i40e_fdir_sb_setup(pf);
  11506. /* Setup static PF queue filter control settings */
  11507. ret = i40e_setup_pf_filter_control(pf);
  11508. if (ret) {
  11509. dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
  11510. ret);
  11511. /* Failure here should not stop continuing other steps */
  11512. }
  11513. /* enable RSS in the HW, even for only one queue, as the stack can use
  11514. * the hash
  11515. */
  11516. if ((pf->flags & I40E_FLAG_RSS_ENABLED))
  11517. i40e_pf_config_rss(pf);
  11518. /* fill in link information and enable LSE reporting */
  11519. i40e_link_event(pf);
  11520. /* Initialize user-specific link properties */
  11521. pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
  11522. I40E_AQ_AN_COMPLETED) ? true : false);
  11523. i40e_ptp_init(pf);
  11524. /* repopulate tunnel port filters */
  11525. i40e_sync_udp_filters(pf);
  11526. return ret;
  11527. }
  11528. /**
  11529. * i40e_determine_queue_usage - Work out queue distribution
  11530. * @pf: board private structure
  11531. **/
  11532. static void i40e_determine_queue_usage(struct i40e_pf *pf)
  11533. {
  11534. int queues_left;
  11535. int q_max;
  11536. pf->num_lan_qps = 0;
  11537. /* Find the max queues to be put into basic use. We'll always be
  11538. * using TC0, whether or not DCB is running, and TC0 will get the
  11539. * big RSS set.
  11540. */
  11541. queues_left = pf->hw.func_caps.num_tx_qp;
  11542. if ((queues_left == 1) ||
  11543. !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  11544. /* one qp for PF, no queues for anything else */
  11545. queues_left = 0;
  11546. pf->alloc_rss_size = pf->num_lan_qps = 1;
  11547. /* make sure all the fancies are disabled */
  11548. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  11549. I40E_FLAG_IWARP_ENABLED |
  11550. I40E_FLAG_FD_SB_ENABLED |
  11551. I40E_FLAG_FD_ATR_ENABLED |
  11552. I40E_FLAG_DCB_CAPABLE |
  11553. I40E_FLAG_DCB_ENABLED |
  11554. I40E_FLAG_SRIOV_ENABLED |
  11555. I40E_FLAG_VMDQ_ENABLED);
  11556. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  11557. } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
  11558. I40E_FLAG_FD_SB_ENABLED |
  11559. I40E_FLAG_FD_ATR_ENABLED |
  11560. I40E_FLAG_DCB_CAPABLE))) {
  11561. /* one qp for PF */
  11562. pf->alloc_rss_size = pf->num_lan_qps = 1;
  11563. queues_left -= pf->num_lan_qps;
  11564. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  11565. I40E_FLAG_IWARP_ENABLED |
  11566. I40E_FLAG_FD_SB_ENABLED |
  11567. I40E_FLAG_FD_ATR_ENABLED |
  11568. I40E_FLAG_DCB_ENABLED |
  11569. I40E_FLAG_VMDQ_ENABLED);
  11570. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  11571. } else {
  11572. /* Not enough queues for all TCs */
  11573. if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
  11574. (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
  11575. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
  11576. I40E_FLAG_DCB_ENABLED);
  11577. dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
  11578. }
  11579. /* limit lan qps to the smaller of qps, cpus or msix */
  11580. q_max = max_t(int, pf->rss_size_max, num_online_cpus());
  11581. q_max = min_t(int, q_max, pf->hw.func_caps.num_tx_qp);
  11582. q_max = min_t(int, q_max, pf->hw.func_caps.num_msix_vectors);
  11583. pf->num_lan_qps = q_max;
  11584. queues_left -= pf->num_lan_qps;
  11585. }
  11586. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  11587. if (queues_left > 1) {
  11588. queues_left -= 1; /* save 1 queue for FD */
  11589. } else {
  11590. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  11591. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  11592. dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
  11593. }
  11594. }
  11595. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  11596. pf->num_vf_qps && pf->num_req_vfs && queues_left) {
  11597. pf->num_req_vfs = min_t(int, pf->num_req_vfs,
  11598. (queues_left / pf->num_vf_qps));
  11599. queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
  11600. }
  11601. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  11602. pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
  11603. pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
  11604. (queues_left / pf->num_vmdq_qps));
  11605. queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
  11606. }
  11607. pf->queues_left = queues_left;
  11608. dev_dbg(&pf->pdev->dev,
  11609. "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
  11610. pf->hw.func_caps.num_tx_qp,
  11611. !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
  11612. pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
  11613. pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
  11614. queues_left);
  11615. }
  11616. /**
  11617. * i40e_setup_pf_filter_control - Setup PF static filter control
  11618. * @pf: PF to be setup
  11619. *
  11620. * i40e_setup_pf_filter_control sets up a PF's initial filter control
  11621. * settings. If PE/FCoE are enabled then it will also set the per PF
  11622. * based filter sizes required for them. It also enables Flow director,
  11623. * ethertype and macvlan type filter settings for the pf.
  11624. *
  11625. * Returns 0 on success, negative on failure
  11626. **/
  11627. static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
  11628. {
  11629. struct i40e_filter_control_settings *settings = &pf->filter_settings;
  11630. settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
  11631. /* Flow Director is enabled */
  11632. if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
  11633. settings->enable_fdir = true;
  11634. /* Ethtype and MACVLAN filters enabled for PF */
  11635. settings->enable_ethtype = true;
  11636. settings->enable_macvlan = true;
  11637. if (i40e_set_filter_control(&pf->hw, settings))
  11638. return -ENOENT;
  11639. return 0;
  11640. }
  11641. #define INFO_STRING_LEN 255
  11642. #define REMAIN(__x) (INFO_STRING_LEN - (__x))
  11643. static void i40e_print_features(struct i40e_pf *pf)
  11644. {
  11645. struct i40e_hw *hw = &pf->hw;
  11646. char *buf;
  11647. int i;
  11648. buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
  11649. if (!buf)
  11650. return;
  11651. i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
  11652. #ifdef CONFIG_PCI_IOV
  11653. i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
  11654. #endif
  11655. i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d",
  11656. pf->hw.func_caps.num_vsis,
  11657. pf->vsi[pf->lan_vsi]->num_queue_pairs);
  11658. if (pf->flags & I40E_FLAG_RSS_ENABLED)
  11659. i += snprintf(&buf[i], REMAIN(i), " RSS");
  11660. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
  11661. i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
  11662. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  11663. i += snprintf(&buf[i], REMAIN(i), " FD_SB");
  11664. i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
  11665. }
  11666. if (pf->flags & I40E_FLAG_DCB_CAPABLE)
  11667. i += snprintf(&buf[i], REMAIN(i), " DCB");
  11668. i += snprintf(&buf[i], REMAIN(i), " VxLAN");
  11669. i += snprintf(&buf[i], REMAIN(i), " Geneve");
  11670. if (pf->flags & I40E_FLAG_PTP)
  11671. i += snprintf(&buf[i], REMAIN(i), " PTP");
  11672. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  11673. i += snprintf(&buf[i], REMAIN(i), " VEB");
  11674. else
  11675. i += snprintf(&buf[i], REMAIN(i), " VEPA");
  11676. dev_info(&pf->pdev->dev, "%s\n", buf);
  11677. kfree(buf);
  11678. WARN_ON(i > INFO_STRING_LEN);
  11679. }
  11680. /**
  11681. * i40e_get_platform_mac_addr - get platform-specific MAC address
  11682. * @pdev: PCI device information struct
  11683. * @pf: board private structure
  11684. *
  11685. * Look up the MAC address for the device. First we'll try
  11686. * eth_platform_get_mac_address, which will check Open Firmware, or arch
  11687. * specific fallback. Otherwise, we'll default to the stored value in
  11688. * firmware.
  11689. **/
  11690. static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
  11691. {
  11692. if (eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
  11693. i40e_get_mac_addr(&pf->hw, pf->hw.mac.addr);
  11694. }
  11695. /**
  11696. * i40e_probe - Device initialization routine
  11697. * @pdev: PCI device information struct
  11698. * @ent: entry in i40e_pci_tbl
  11699. *
  11700. * i40e_probe initializes a PF identified by a pci_dev structure.
  11701. * The OS initialization, configuring of the PF private structure,
  11702. * and a hardware reset occur.
  11703. *
  11704. * Returns 0 on success, negative on failure
  11705. **/
  11706. static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  11707. {
  11708. struct i40e_aq_get_phy_abilities_resp abilities;
  11709. struct i40e_pf *pf;
  11710. struct i40e_hw *hw;
  11711. static u16 pfs_found;
  11712. u16 wol_nvm_bits;
  11713. u16 link_status;
  11714. int err;
  11715. u32 val;
  11716. u32 i;
  11717. u8 set_fc_aq_fail;
  11718. err = pci_enable_device_mem(pdev);
  11719. if (err)
  11720. return err;
  11721. /* set up for high or low dma */
  11722. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  11723. if (err) {
  11724. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  11725. if (err) {
  11726. dev_err(&pdev->dev,
  11727. "DMA configuration failed: 0x%x\n", err);
  11728. goto err_dma;
  11729. }
  11730. }
  11731. /* set up pci connections */
  11732. err = pci_request_mem_regions(pdev, i40e_driver_name);
  11733. if (err) {
  11734. dev_info(&pdev->dev,
  11735. "pci_request_selected_regions failed %d\n", err);
  11736. goto err_pci_reg;
  11737. }
  11738. pci_enable_pcie_error_reporting(pdev);
  11739. pci_set_master(pdev);
  11740. /* Now that we have a PCI connection, we need to do the
  11741. * low level device setup. This is primarily setting up
  11742. * the Admin Queue structures and then querying for the
  11743. * device's current profile information.
  11744. */
  11745. pf = kzalloc(sizeof(*pf), GFP_KERNEL);
  11746. if (!pf) {
  11747. err = -ENOMEM;
  11748. goto err_pf_alloc;
  11749. }
  11750. pf->next_vsi = 0;
  11751. pf->pdev = pdev;
  11752. set_bit(__I40E_DOWN, pf->state);
  11753. hw = &pf->hw;
  11754. hw->back = pf;
  11755. pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
  11756. I40E_MAX_CSR_SPACE);
  11757. hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
  11758. if (!hw->hw_addr) {
  11759. err = -EIO;
  11760. dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
  11761. (unsigned int)pci_resource_start(pdev, 0),
  11762. pf->ioremap_len, err);
  11763. goto err_ioremap;
  11764. }
  11765. hw->vendor_id = pdev->vendor;
  11766. hw->device_id = pdev->device;
  11767. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  11768. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  11769. hw->subsystem_device_id = pdev->subsystem_device;
  11770. hw->bus.device = PCI_SLOT(pdev->devfn);
  11771. hw->bus.func = PCI_FUNC(pdev->devfn);
  11772. hw->bus.bus_id = pdev->bus->number;
  11773. pf->instance = pfs_found;
  11774. /* Select something other than the 802.1ad ethertype for the
  11775. * switch to use internally and drop on ingress.
  11776. */
  11777. hw->switch_tag = 0xffff;
  11778. hw->first_tag = ETH_P_8021AD;
  11779. hw->second_tag = ETH_P_8021Q;
  11780. INIT_LIST_HEAD(&pf->l3_flex_pit_list);
  11781. INIT_LIST_HEAD(&pf->l4_flex_pit_list);
  11782. /* set up the locks for the AQ, do this only once in probe
  11783. * and destroy them only once in remove
  11784. */
  11785. mutex_init(&hw->aq.asq_mutex);
  11786. mutex_init(&hw->aq.arq_mutex);
  11787. pf->msg_enable = netif_msg_init(debug,
  11788. NETIF_MSG_DRV |
  11789. NETIF_MSG_PROBE |
  11790. NETIF_MSG_LINK);
  11791. if (debug < -1)
  11792. pf->hw.debug_mask = debug;
  11793. /* do a special CORER for clearing PXE mode once at init */
  11794. if (hw->revision_id == 0 &&
  11795. (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
  11796. wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
  11797. i40e_flush(hw);
  11798. msleep(200);
  11799. pf->corer_count++;
  11800. i40e_clear_pxe_mode(hw);
  11801. }
  11802. /* Reset here to make sure all is clean and to define PF 'n' */
  11803. i40e_clear_hw(hw);
  11804. err = i40e_pf_reset(hw);
  11805. if (err) {
  11806. dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
  11807. goto err_pf_reset;
  11808. }
  11809. pf->pfr_count++;
  11810. hw->aq.num_arq_entries = I40E_AQ_LEN;
  11811. hw->aq.num_asq_entries = I40E_AQ_LEN;
  11812. hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  11813. hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  11814. pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
  11815. snprintf(pf->int_name, sizeof(pf->int_name) - 1,
  11816. "%s-%s:misc",
  11817. dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
  11818. err = i40e_init_shared_code(hw);
  11819. if (err) {
  11820. dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
  11821. err);
  11822. goto err_pf_reset;
  11823. }
  11824. /* set up a default setting for link flow control */
  11825. pf->hw.fc.requested_mode = I40E_FC_NONE;
  11826. err = i40e_init_adminq(hw);
  11827. if (err) {
  11828. if (err == I40E_ERR_FIRMWARE_API_VERSION)
  11829. dev_info(&pdev->dev,
  11830. "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");
  11831. else
  11832. dev_info(&pdev->dev,
  11833. "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
  11834. goto err_pf_reset;
  11835. }
  11836. i40e_get_oem_version(hw);
  11837. /* provide nvm, fw, api versions */
  11838. dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
  11839. hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
  11840. hw->aq.api_maj_ver, hw->aq.api_min_ver,
  11841. i40e_nvm_version_str(hw));
  11842. if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
  11843. hw->aq.api_min_ver > I40E_FW_MINOR_VERSION(hw))
  11844. dev_info(&pdev->dev,
  11845. "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");
  11846. else if (hw->aq.api_maj_ver == 1 && hw->aq.api_min_ver < 4)
  11847. dev_info(&pdev->dev,
  11848. "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
  11849. i40e_verify_eeprom(pf);
  11850. /* Rev 0 hardware was never productized */
  11851. if (hw->revision_id < 1)
  11852. 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");
  11853. i40e_clear_pxe_mode(hw);
  11854. err = i40e_get_capabilities(pf, i40e_aqc_opc_list_func_capabilities);
  11855. if (err)
  11856. goto err_adminq_setup;
  11857. err = i40e_sw_init(pf);
  11858. if (err) {
  11859. dev_info(&pdev->dev, "sw_init failed: %d\n", err);
  11860. goto err_sw_init;
  11861. }
  11862. err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  11863. hw->func_caps.num_rx_qp, 0, 0);
  11864. if (err) {
  11865. dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
  11866. goto err_init_lan_hmc;
  11867. }
  11868. err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  11869. if (err) {
  11870. dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
  11871. err = -ENOENT;
  11872. goto err_configure_lan_hmc;
  11873. }
  11874. /* Disable LLDP for NICs that have firmware versions lower than v4.3.
  11875. * Ignore error return codes because if it was already disabled via
  11876. * hardware settings this will fail
  11877. */
  11878. if (pf->hw_features & I40E_HW_STOP_FW_LLDP) {
  11879. dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
  11880. i40e_aq_stop_lldp(hw, true, NULL);
  11881. }
  11882. /* allow a platform config to override the HW addr */
  11883. i40e_get_platform_mac_addr(pdev, pf);
  11884. if (!is_valid_ether_addr(hw->mac.addr)) {
  11885. dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
  11886. err = -EIO;
  11887. goto err_mac_addr;
  11888. }
  11889. dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
  11890. ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
  11891. i40e_get_port_mac_addr(hw, hw->mac.port_addr);
  11892. if (is_valid_ether_addr(hw->mac.port_addr))
  11893. pf->hw_features |= I40E_HW_PORT_ID_VALID;
  11894. pci_set_drvdata(pdev, pf);
  11895. pci_save_state(pdev);
  11896. /* Enable FW to write default DCB config on link-up */
  11897. i40e_aq_set_dcb_parameters(hw, true, NULL);
  11898. #ifdef CONFIG_I40E_DCB
  11899. err = i40e_init_pf_dcb(pf);
  11900. if (err) {
  11901. dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
  11902. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED);
  11903. /* Continue without DCB enabled */
  11904. }
  11905. #endif /* CONFIG_I40E_DCB */
  11906. /* set up periodic task facility */
  11907. timer_setup(&pf->service_timer, i40e_service_timer, 0);
  11908. pf->service_timer_period = HZ;
  11909. INIT_WORK(&pf->service_task, i40e_service_task);
  11910. clear_bit(__I40E_SERVICE_SCHED, pf->state);
  11911. /* NVM bit on means WoL disabled for the port */
  11912. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  11913. if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
  11914. pf->wol_en = false;
  11915. else
  11916. pf->wol_en = true;
  11917. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  11918. /* set up the main switch operations */
  11919. i40e_determine_queue_usage(pf);
  11920. err = i40e_init_interrupt_scheme(pf);
  11921. if (err)
  11922. goto err_switch_setup;
  11923. /* The number of VSIs reported by the FW is the minimum guaranteed
  11924. * to us; HW supports far more and we share the remaining pool with
  11925. * the other PFs. We allocate space for more than the guarantee with
  11926. * the understanding that we might not get them all later.
  11927. */
  11928. if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
  11929. pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
  11930. else
  11931. pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
  11932. /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
  11933. pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
  11934. GFP_KERNEL);
  11935. if (!pf->vsi) {
  11936. err = -ENOMEM;
  11937. goto err_switch_setup;
  11938. }
  11939. #ifdef CONFIG_PCI_IOV
  11940. /* prep for VF support */
  11941. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  11942. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  11943. !test_bit(__I40E_BAD_EEPROM, pf->state)) {
  11944. if (pci_num_vf(pdev))
  11945. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  11946. }
  11947. #endif
  11948. err = i40e_setup_pf_switch(pf, false);
  11949. if (err) {
  11950. dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
  11951. goto err_vsis;
  11952. }
  11953. INIT_LIST_HEAD(&pf->vsi[pf->lan_vsi]->ch_list);
  11954. /* Make sure flow control is set according to current settings */
  11955. err = i40e_set_fc(hw, &set_fc_aq_fail, true);
  11956. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
  11957. dev_dbg(&pf->pdev->dev,
  11958. "Set fc with err %s aq_err %s on get_phy_cap\n",
  11959. i40e_stat_str(hw, err),
  11960. i40e_aq_str(hw, hw->aq.asq_last_status));
  11961. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
  11962. dev_dbg(&pf->pdev->dev,
  11963. "Set fc with err %s aq_err %s on set_phy_config\n",
  11964. i40e_stat_str(hw, err),
  11965. i40e_aq_str(hw, hw->aq.asq_last_status));
  11966. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
  11967. dev_dbg(&pf->pdev->dev,
  11968. "Set fc with err %s aq_err %s on get_link_info\n",
  11969. i40e_stat_str(hw, err),
  11970. i40e_aq_str(hw, hw->aq.asq_last_status));
  11971. /* if FDIR VSI was set up, start it now */
  11972. for (i = 0; i < pf->num_alloc_vsi; i++) {
  11973. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  11974. i40e_vsi_open(pf->vsi[i]);
  11975. break;
  11976. }
  11977. }
  11978. /* The driver only wants link up/down and module qualification
  11979. * reports from firmware. Note the negative logic.
  11980. */
  11981. err = i40e_aq_set_phy_int_mask(&pf->hw,
  11982. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  11983. I40E_AQ_EVENT_MEDIA_NA |
  11984. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  11985. if (err)
  11986. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  11987. i40e_stat_str(&pf->hw, err),
  11988. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11989. /* Reconfigure hardware for allowing smaller MSS in the case
  11990. * of TSO, so that we avoid the MDD being fired and causing
  11991. * a reset in the case of small MSS+TSO.
  11992. */
  11993. val = rd32(hw, I40E_REG_MSS);
  11994. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  11995. val &= ~I40E_REG_MSS_MIN_MASK;
  11996. val |= I40E_64BYTE_MSS;
  11997. wr32(hw, I40E_REG_MSS, val);
  11998. }
  11999. if (pf->hw_features & I40E_HW_RESTART_AUTONEG) {
  12000. msleep(75);
  12001. err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  12002. if (err)
  12003. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  12004. i40e_stat_str(&pf->hw, err),
  12005. i40e_aq_str(&pf->hw,
  12006. pf->hw.aq.asq_last_status));
  12007. }
  12008. /* The main driver is (mostly) up and happy. We need to set this state
  12009. * before setting up the misc vector or we get a race and the vector
  12010. * ends up disabled forever.
  12011. */
  12012. clear_bit(__I40E_DOWN, pf->state);
  12013. /* In case of MSIX we are going to setup the misc vector right here
  12014. * to handle admin queue events etc. In case of legacy and MSI
  12015. * the misc functionality and queue processing is combined in
  12016. * the same vector and that gets setup at open.
  12017. */
  12018. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  12019. err = i40e_setup_misc_vector(pf);
  12020. if (err) {
  12021. dev_info(&pdev->dev,
  12022. "setup of misc vector failed: %d\n", err);
  12023. goto err_vsis;
  12024. }
  12025. }
  12026. #ifdef CONFIG_PCI_IOV
  12027. /* prep for VF support */
  12028. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  12029. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  12030. !test_bit(__I40E_BAD_EEPROM, pf->state)) {
  12031. /* disable link interrupts for VFs */
  12032. val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
  12033. val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
  12034. wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
  12035. i40e_flush(hw);
  12036. if (pci_num_vf(pdev)) {
  12037. dev_info(&pdev->dev,
  12038. "Active VFs found, allocating resources.\n");
  12039. err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
  12040. if (err)
  12041. dev_info(&pdev->dev,
  12042. "Error %d allocating resources for existing VFs\n",
  12043. err);
  12044. }
  12045. }
  12046. #endif /* CONFIG_PCI_IOV */
  12047. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  12048. pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
  12049. pf->num_iwarp_msix,
  12050. I40E_IWARP_IRQ_PILE_ID);
  12051. if (pf->iwarp_base_vector < 0) {
  12052. dev_info(&pdev->dev,
  12053. "failed to get tracking for %d vectors for IWARP err=%d\n",
  12054. pf->num_iwarp_msix, pf->iwarp_base_vector);
  12055. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  12056. }
  12057. }
  12058. i40e_dbg_pf_init(pf);
  12059. /* tell the firmware that we're starting */
  12060. i40e_send_version(pf);
  12061. /* since everything's happy, start the service_task timer */
  12062. mod_timer(&pf->service_timer,
  12063. round_jiffies(jiffies + pf->service_timer_period));
  12064. /* add this PF to client device list and launch a client service task */
  12065. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  12066. err = i40e_lan_add_device(pf);
  12067. if (err)
  12068. dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
  12069. err);
  12070. }
  12071. #define PCI_SPEED_SIZE 8
  12072. #define PCI_WIDTH_SIZE 8
  12073. /* Devices on the IOSF bus do not have this information
  12074. * and will report PCI Gen 1 x 1 by default so don't bother
  12075. * checking them.
  12076. */
  12077. if (!(pf->hw_features & I40E_HW_NO_PCI_LINK_CHECK)) {
  12078. char speed[PCI_SPEED_SIZE] = "Unknown";
  12079. char width[PCI_WIDTH_SIZE] = "Unknown";
  12080. /* Get the negotiated link width and speed from PCI config
  12081. * space
  12082. */
  12083. pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
  12084. &link_status);
  12085. i40e_set_pci_config_data(hw, link_status);
  12086. switch (hw->bus.speed) {
  12087. case i40e_bus_speed_8000:
  12088. strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
  12089. case i40e_bus_speed_5000:
  12090. strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
  12091. case i40e_bus_speed_2500:
  12092. strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
  12093. default:
  12094. break;
  12095. }
  12096. switch (hw->bus.width) {
  12097. case i40e_bus_width_pcie_x8:
  12098. strncpy(width, "8", PCI_WIDTH_SIZE); break;
  12099. case i40e_bus_width_pcie_x4:
  12100. strncpy(width, "4", PCI_WIDTH_SIZE); break;
  12101. case i40e_bus_width_pcie_x2:
  12102. strncpy(width, "2", PCI_WIDTH_SIZE); break;
  12103. case i40e_bus_width_pcie_x1:
  12104. strncpy(width, "1", PCI_WIDTH_SIZE); break;
  12105. default:
  12106. break;
  12107. }
  12108. dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
  12109. speed, width);
  12110. if (hw->bus.width < i40e_bus_width_pcie_x8 ||
  12111. hw->bus.speed < i40e_bus_speed_8000) {
  12112. dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
  12113. dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
  12114. }
  12115. }
  12116. /* get the requested speeds from the fw */
  12117. err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
  12118. if (err)
  12119. dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
  12120. i40e_stat_str(&pf->hw, err),
  12121. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  12122. pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
  12123. /* get the supported phy types from the fw */
  12124. err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
  12125. if (err)
  12126. dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
  12127. i40e_stat_str(&pf->hw, err),
  12128. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  12129. /* Add a filter to drop all Flow control frames from any VSI from being
  12130. * transmitted. By doing so we stop a malicious VF from sending out
  12131. * PAUSE or PFC frames and potentially controlling traffic for other
  12132. * PF/VF VSIs.
  12133. * The FW can still send Flow control frames if enabled.
  12134. */
  12135. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  12136. pf->main_vsi_seid);
  12137. if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
  12138. (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
  12139. pf->hw_features |= I40E_HW_PHY_CONTROLS_LEDS;
  12140. if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722)
  12141. pf->hw_features |= I40E_HW_HAVE_CRT_RETIMER;
  12142. /* print a string summarizing features */
  12143. i40e_print_features(pf);
  12144. return 0;
  12145. /* Unwind what we've done if something failed in the setup */
  12146. err_vsis:
  12147. set_bit(__I40E_DOWN, pf->state);
  12148. i40e_clear_interrupt_scheme(pf);
  12149. kfree(pf->vsi);
  12150. err_switch_setup:
  12151. i40e_reset_interrupt_capability(pf);
  12152. del_timer_sync(&pf->service_timer);
  12153. err_mac_addr:
  12154. err_configure_lan_hmc:
  12155. (void)i40e_shutdown_lan_hmc(hw);
  12156. err_init_lan_hmc:
  12157. kfree(pf->qp_pile);
  12158. err_sw_init:
  12159. err_adminq_setup:
  12160. err_pf_reset:
  12161. iounmap(hw->hw_addr);
  12162. err_ioremap:
  12163. kfree(pf);
  12164. err_pf_alloc:
  12165. pci_disable_pcie_error_reporting(pdev);
  12166. pci_release_mem_regions(pdev);
  12167. err_pci_reg:
  12168. err_dma:
  12169. pci_disable_device(pdev);
  12170. return err;
  12171. }
  12172. /**
  12173. * i40e_remove - Device removal routine
  12174. * @pdev: PCI device information struct
  12175. *
  12176. * i40e_remove is called by the PCI subsystem to alert the driver
  12177. * that is should release a PCI device. This could be caused by a
  12178. * Hot-Plug event, or because the driver is going to be removed from
  12179. * memory.
  12180. **/
  12181. static void i40e_remove(struct pci_dev *pdev)
  12182. {
  12183. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12184. struct i40e_hw *hw = &pf->hw;
  12185. i40e_status ret_code;
  12186. int i;
  12187. i40e_dbg_pf_exit(pf);
  12188. i40e_ptp_stop(pf);
  12189. /* Disable RSS in hw */
  12190. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
  12191. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
  12192. /* no more scheduling of any task */
  12193. set_bit(__I40E_SUSPENDED, pf->state);
  12194. set_bit(__I40E_DOWN, pf->state);
  12195. if (pf->service_timer.function)
  12196. del_timer_sync(&pf->service_timer);
  12197. if (pf->service_task.func)
  12198. cancel_work_sync(&pf->service_task);
  12199. /* Client close must be called explicitly here because the timer
  12200. * has been stopped.
  12201. */
  12202. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
  12203. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  12204. i40e_free_vfs(pf);
  12205. pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
  12206. }
  12207. i40e_fdir_teardown(pf);
  12208. /* If there is a switch structure or any orphans, remove them.
  12209. * This will leave only the PF's VSI remaining.
  12210. */
  12211. for (i = 0; i < I40E_MAX_VEB; i++) {
  12212. if (!pf->veb[i])
  12213. continue;
  12214. if (pf->veb[i]->uplink_seid == pf->mac_seid ||
  12215. pf->veb[i]->uplink_seid == 0)
  12216. i40e_switch_branch_release(pf->veb[i]);
  12217. }
  12218. /* Now we can shutdown the PF's VSI, just before we kill
  12219. * adminq and hmc.
  12220. */
  12221. if (pf->vsi[pf->lan_vsi])
  12222. i40e_vsi_release(pf->vsi[pf->lan_vsi]);
  12223. i40e_cloud_filter_exit(pf);
  12224. /* remove attached clients */
  12225. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  12226. ret_code = i40e_lan_del_device(pf);
  12227. if (ret_code)
  12228. dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
  12229. ret_code);
  12230. }
  12231. /* shutdown and destroy the HMC */
  12232. if (hw->hmc.hmc_obj) {
  12233. ret_code = i40e_shutdown_lan_hmc(hw);
  12234. if (ret_code)
  12235. dev_warn(&pdev->dev,
  12236. "Failed to destroy the HMC resources: %d\n",
  12237. ret_code);
  12238. }
  12239. /* shutdown the adminq */
  12240. i40e_shutdown_adminq(hw);
  12241. /* destroy the locks only once, here */
  12242. mutex_destroy(&hw->aq.arq_mutex);
  12243. mutex_destroy(&hw->aq.asq_mutex);
  12244. /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
  12245. i40e_clear_interrupt_scheme(pf);
  12246. for (i = 0; i < pf->num_alloc_vsi; i++) {
  12247. if (pf->vsi[i]) {
  12248. i40e_vsi_clear_rings(pf->vsi[i]);
  12249. i40e_vsi_clear(pf->vsi[i]);
  12250. pf->vsi[i] = NULL;
  12251. }
  12252. }
  12253. for (i = 0; i < I40E_MAX_VEB; i++) {
  12254. kfree(pf->veb[i]);
  12255. pf->veb[i] = NULL;
  12256. }
  12257. kfree(pf->qp_pile);
  12258. kfree(pf->vsi);
  12259. iounmap(hw->hw_addr);
  12260. kfree(pf);
  12261. pci_release_mem_regions(pdev);
  12262. pci_disable_pcie_error_reporting(pdev);
  12263. pci_disable_device(pdev);
  12264. }
  12265. /**
  12266. * i40e_pci_error_detected - warning that something funky happened in PCI land
  12267. * @pdev: PCI device information struct
  12268. *
  12269. * Called to warn that something happened and the error handling steps
  12270. * are in progress. Allows the driver to quiesce things, be ready for
  12271. * remediation.
  12272. **/
  12273. static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
  12274. enum pci_channel_state error)
  12275. {
  12276. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12277. dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
  12278. if (!pf) {
  12279. dev_info(&pdev->dev,
  12280. "Cannot recover - error happened during device probe\n");
  12281. return PCI_ERS_RESULT_DISCONNECT;
  12282. }
  12283. /* shutdown all operations */
  12284. if (!test_bit(__I40E_SUSPENDED, pf->state))
  12285. i40e_prep_for_reset(pf, false);
  12286. /* Request a slot reset */
  12287. return PCI_ERS_RESULT_NEED_RESET;
  12288. }
  12289. /**
  12290. * i40e_pci_error_slot_reset - a PCI slot reset just happened
  12291. * @pdev: PCI device information struct
  12292. *
  12293. * Called to find if the driver can work with the device now that
  12294. * the pci slot has been reset. If a basic connection seems good
  12295. * (registers are readable and have sane content) then return a
  12296. * happy little PCI_ERS_RESULT_xxx.
  12297. **/
  12298. static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
  12299. {
  12300. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12301. pci_ers_result_t result;
  12302. int err;
  12303. u32 reg;
  12304. dev_dbg(&pdev->dev, "%s\n", __func__);
  12305. if (pci_enable_device_mem(pdev)) {
  12306. dev_info(&pdev->dev,
  12307. "Cannot re-enable PCI device after reset.\n");
  12308. result = PCI_ERS_RESULT_DISCONNECT;
  12309. } else {
  12310. pci_set_master(pdev);
  12311. pci_restore_state(pdev);
  12312. pci_save_state(pdev);
  12313. pci_wake_from_d3(pdev, false);
  12314. reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  12315. if (reg == 0)
  12316. result = PCI_ERS_RESULT_RECOVERED;
  12317. else
  12318. result = PCI_ERS_RESULT_DISCONNECT;
  12319. }
  12320. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  12321. if (err) {
  12322. dev_info(&pdev->dev,
  12323. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
  12324. err);
  12325. /* non-fatal, continue */
  12326. }
  12327. return result;
  12328. }
  12329. /**
  12330. * i40e_pci_error_reset_prepare - prepare device driver for pci reset
  12331. * @pdev: PCI device information struct
  12332. */
  12333. static void i40e_pci_error_reset_prepare(struct pci_dev *pdev)
  12334. {
  12335. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12336. i40e_prep_for_reset(pf, false);
  12337. }
  12338. /**
  12339. * i40e_pci_error_reset_done - pci reset done, device driver reset can begin
  12340. * @pdev: PCI device information struct
  12341. */
  12342. static void i40e_pci_error_reset_done(struct pci_dev *pdev)
  12343. {
  12344. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12345. i40e_reset_and_rebuild(pf, false, false);
  12346. }
  12347. /**
  12348. * i40e_pci_error_resume - restart operations after PCI error recovery
  12349. * @pdev: PCI device information struct
  12350. *
  12351. * Called to allow the driver to bring things back up after PCI error
  12352. * and/or reset recovery has finished.
  12353. **/
  12354. static void i40e_pci_error_resume(struct pci_dev *pdev)
  12355. {
  12356. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12357. dev_dbg(&pdev->dev, "%s\n", __func__);
  12358. if (test_bit(__I40E_SUSPENDED, pf->state))
  12359. return;
  12360. i40e_handle_reset_warning(pf, false);
  12361. }
  12362. /**
  12363. * i40e_enable_mc_magic_wake - enable multicast magic packet wake up
  12364. * using the mac_address_write admin q function
  12365. * @pf: pointer to i40e_pf struct
  12366. **/
  12367. static void i40e_enable_mc_magic_wake(struct i40e_pf *pf)
  12368. {
  12369. struct i40e_hw *hw = &pf->hw;
  12370. i40e_status ret;
  12371. u8 mac_addr[6];
  12372. u16 flags = 0;
  12373. /* Get current MAC address in case it's an LAA */
  12374. if (pf->vsi[pf->lan_vsi] && pf->vsi[pf->lan_vsi]->netdev) {
  12375. ether_addr_copy(mac_addr,
  12376. pf->vsi[pf->lan_vsi]->netdev->dev_addr);
  12377. } else {
  12378. dev_err(&pf->pdev->dev,
  12379. "Failed to retrieve MAC address; using default\n");
  12380. ether_addr_copy(mac_addr, hw->mac.addr);
  12381. }
  12382. /* The FW expects the mac address write cmd to first be called with
  12383. * one of these flags before calling it again with the multicast
  12384. * enable flags.
  12385. */
  12386. flags = I40E_AQC_WRITE_TYPE_LAA_WOL;
  12387. if (hw->func_caps.flex10_enable && hw->partition_id != 1)
  12388. flags = I40E_AQC_WRITE_TYPE_LAA_ONLY;
  12389. ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
  12390. if (ret) {
  12391. dev_err(&pf->pdev->dev,
  12392. "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up");
  12393. return;
  12394. }
  12395. flags = I40E_AQC_MC_MAG_EN
  12396. | I40E_AQC_WOL_PRESERVE_ON_PFR
  12397. | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG;
  12398. ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
  12399. if (ret)
  12400. dev_err(&pf->pdev->dev,
  12401. "Failed to enable Multicast Magic Packet wake up\n");
  12402. }
  12403. /**
  12404. * i40e_shutdown - PCI callback for shutting down
  12405. * @pdev: PCI device information struct
  12406. **/
  12407. static void i40e_shutdown(struct pci_dev *pdev)
  12408. {
  12409. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12410. struct i40e_hw *hw = &pf->hw;
  12411. set_bit(__I40E_SUSPENDED, pf->state);
  12412. set_bit(__I40E_DOWN, pf->state);
  12413. rtnl_lock();
  12414. i40e_prep_for_reset(pf, true);
  12415. rtnl_unlock();
  12416. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  12417. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  12418. del_timer_sync(&pf->service_timer);
  12419. cancel_work_sync(&pf->service_task);
  12420. i40e_cloud_filter_exit(pf);
  12421. i40e_fdir_teardown(pf);
  12422. /* Client close must be called explicitly here because the timer
  12423. * has been stopped.
  12424. */
  12425. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
  12426. if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE))
  12427. i40e_enable_mc_magic_wake(pf);
  12428. i40e_prep_for_reset(pf, false);
  12429. wr32(hw, I40E_PFPM_APM,
  12430. (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  12431. wr32(hw, I40E_PFPM_WUFC,
  12432. (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  12433. i40e_clear_interrupt_scheme(pf);
  12434. if (system_state == SYSTEM_POWER_OFF) {
  12435. pci_wake_from_d3(pdev, pf->wol_en);
  12436. pci_set_power_state(pdev, PCI_D3hot);
  12437. }
  12438. }
  12439. /**
  12440. * i40e_suspend - PM callback for moving to D3
  12441. * @dev: generic device information structure
  12442. **/
  12443. static int __maybe_unused i40e_suspend(struct device *dev)
  12444. {
  12445. struct pci_dev *pdev = to_pci_dev(dev);
  12446. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12447. struct i40e_hw *hw = &pf->hw;
  12448. /* If we're already suspended, then there is nothing to do */
  12449. if (test_and_set_bit(__I40E_SUSPENDED, pf->state))
  12450. return 0;
  12451. set_bit(__I40E_DOWN, pf->state);
  12452. /* Ensure service task will not be running */
  12453. del_timer_sync(&pf->service_timer);
  12454. cancel_work_sync(&pf->service_task);
  12455. if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE))
  12456. i40e_enable_mc_magic_wake(pf);
  12457. i40e_prep_for_reset(pf, false);
  12458. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  12459. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  12460. /* Clear the interrupt scheme and release our IRQs so that the system
  12461. * can safely hibernate even when there are a large number of CPUs.
  12462. * Otherwise hibernation might fail when mapping all the vectors back
  12463. * to CPU0.
  12464. */
  12465. i40e_clear_interrupt_scheme(pf);
  12466. return 0;
  12467. }
  12468. /**
  12469. * i40e_resume - PM callback for waking up from D3
  12470. * @dev: generic device information structure
  12471. **/
  12472. static int __maybe_unused i40e_resume(struct device *dev)
  12473. {
  12474. struct pci_dev *pdev = to_pci_dev(dev);
  12475. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12476. int err;
  12477. /* If we're not suspended, then there is nothing to do */
  12478. if (!test_bit(__I40E_SUSPENDED, pf->state))
  12479. return 0;
  12480. /* We cleared the interrupt scheme when we suspended, so we need to
  12481. * restore it now to resume device functionality.
  12482. */
  12483. err = i40e_restore_interrupt_scheme(pf);
  12484. if (err) {
  12485. dev_err(&pdev->dev, "Cannot restore interrupt scheme: %d\n",
  12486. err);
  12487. }
  12488. clear_bit(__I40E_DOWN, pf->state);
  12489. i40e_reset_and_rebuild(pf, false, false);
  12490. /* Clear suspended state last after everything is recovered */
  12491. clear_bit(__I40E_SUSPENDED, pf->state);
  12492. /* Restart the service task */
  12493. mod_timer(&pf->service_timer,
  12494. round_jiffies(jiffies + pf->service_timer_period));
  12495. return 0;
  12496. }
  12497. static const struct pci_error_handlers i40e_err_handler = {
  12498. .error_detected = i40e_pci_error_detected,
  12499. .slot_reset = i40e_pci_error_slot_reset,
  12500. .reset_prepare = i40e_pci_error_reset_prepare,
  12501. .reset_done = i40e_pci_error_reset_done,
  12502. .resume = i40e_pci_error_resume,
  12503. };
  12504. static SIMPLE_DEV_PM_OPS(i40e_pm_ops, i40e_suspend, i40e_resume);
  12505. static struct pci_driver i40e_driver = {
  12506. .name = i40e_driver_name,
  12507. .id_table = i40e_pci_tbl,
  12508. .probe = i40e_probe,
  12509. .remove = i40e_remove,
  12510. .driver = {
  12511. .pm = &i40e_pm_ops,
  12512. },
  12513. .shutdown = i40e_shutdown,
  12514. .err_handler = &i40e_err_handler,
  12515. .sriov_configure = i40e_pci_sriov_configure,
  12516. };
  12517. /**
  12518. * i40e_init_module - Driver registration routine
  12519. *
  12520. * i40e_init_module is the first routine called when the driver is
  12521. * loaded. All it does is register with the PCI subsystem.
  12522. **/
  12523. static int __init i40e_init_module(void)
  12524. {
  12525. pr_info("%s: %s - version %s\n", i40e_driver_name,
  12526. i40e_driver_string, i40e_driver_version_str);
  12527. pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
  12528. /* There is no need to throttle the number of active tasks because
  12529. * each device limits its own task using a state bit for scheduling
  12530. * the service task, and the device tasks do not interfere with each
  12531. * other, so we don't set a max task limit. We must set WQ_MEM_RECLAIM
  12532. * since we need to be able to guarantee forward progress even under
  12533. * memory pressure.
  12534. */
  12535. i40e_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, i40e_driver_name);
  12536. if (!i40e_wq) {
  12537. pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
  12538. return -ENOMEM;
  12539. }
  12540. i40e_dbg_init();
  12541. return pci_register_driver(&i40e_driver);
  12542. }
  12543. module_init(i40e_init_module);
  12544. /**
  12545. * i40e_exit_module - Driver exit cleanup routine
  12546. *
  12547. * i40e_exit_module is called just before the driver is removed
  12548. * from memory.
  12549. **/
  12550. static void __exit i40e_exit_module(void)
  12551. {
  12552. pci_unregister_driver(&i40e_driver);
  12553. destroy_workqueue(i40e_wq);
  12554. i40e_dbg_exit();
  12555. }
  12556. module_exit(i40e_exit_module);