i40e_main.c 402 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 2013 - 2018 Intel Corporation. */
  3. #include <linux/etherdevice.h>
  4. #include <linux/of_net.h>
  5. #include <linux/pci.h>
  6. #include <linux/bpf.h>
  7. /* Local includes */
  8. #include "i40e.h"
  9. #include "i40e_diag.h"
  10. #include <net/udp_tunnel.h>
  11. /* All i40e tracepoints are defined by the include below, which
  12. * must be included exactly once across the whole kernel with
  13. * CREATE_TRACE_POINTS defined
  14. */
  15. #define CREATE_TRACE_POINTS
  16. #include "i40e_trace.h"
  17. const char i40e_driver_name[] = "i40e";
  18. static const char i40e_driver_string[] =
  19. "Intel(R) Ethernet Connection XL710 Network Driver";
  20. #define DRV_KERN "-k"
  21. #define DRV_VERSION_MAJOR 2
  22. #define DRV_VERSION_MINOR 3
  23. #define DRV_VERSION_BUILD 2
  24. #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
  25. __stringify(DRV_VERSION_MINOR) "." \
  26. __stringify(DRV_VERSION_BUILD) DRV_KERN
  27. const char i40e_driver_version_str[] = DRV_VERSION;
  28. static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
  29. /* a bit of forward declarations */
  30. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
  31. static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired);
  32. static int i40e_add_vsi(struct i40e_vsi *vsi);
  33. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
  34. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
  35. static int i40e_setup_misc_vector(struct i40e_pf *pf);
  36. static void i40e_determine_queue_usage(struct i40e_pf *pf);
  37. static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
  38. static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired);
  39. static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit,
  40. bool lock_acquired);
  41. static int i40e_reset(struct i40e_pf *pf);
  42. static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired);
  43. static void i40e_fdir_sb_setup(struct i40e_pf *pf);
  44. static int i40e_veb_get_bw_info(struct i40e_veb *veb);
  45. static int i40e_get_capabilities(struct i40e_pf *pf,
  46. enum i40e_admin_queue_opc list_type);
  47. /* i40e_pci_tbl - PCI Device ID Table
  48. *
  49. * Last entry must be all 0s
  50. *
  51. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  52. * Class, Class Mask, private data (not used) }
  53. */
  54. static const struct pci_device_id i40e_pci_tbl[] = {
  55. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
  56. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
  57. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
  58. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
  59. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
  60. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
  61. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
  62. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0},
  63. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0},
  64. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0},
  65. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0},
  66. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0},
  67. {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0},
  68. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0},
  69. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0},
  70. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
  71. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0},
  72. {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_B), 0},
  73. {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_SFP28), 0},
  74. /* required last entry */
  75. {0, }
  76. };
  77. MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
  78. #define I40E_MAX_VF_COUNT 128
  79. static int debug = -1;
  80. module_param(debug, uint, 0);
  81. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)");
  82. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  83. MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
  84. MODULE_LICENSE("GPL");
  85. MODULE_VERSION(DRV_VERSION);
  86. static struct workqueue_struct *i40e_wq;
  87. /**
  88. * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
  89. * @hw: pointer to the HW structure
  90. * @mem: ptr to mem struct to fill out
  91. * @size: size of memory requested
  92. * @alignment: what to align the allocation to
  93. **/
  94. int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
  95. u64 size, u32 alignment)
  96. {
  97. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  98. mem->size = ALIGN(size, alignment);
  99. mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
  100. &mem->pa, GFP_KERNEL);
  101. if (!mem->va)
  102. return -ENOMEM;
  103. return 0;
  104. }
  105. /**
  106. * i40e_free_dma_mem_d - OS specific memory free for shared code
  107. * @hw: pointer to the HW structure
  108. * @mem: ptr to mem struct to free
  109. **/
  110. int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
  111. {
  112. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  113. dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
  114. mem->va = NULL;
  115. mem->pa = 0;
  116. mem->size = 0;
  117. return 0;
  118. }
  119. /**
  120. * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
  121. * @hw: pointer to the HW structure
  122. * @mem: ptr to mem struct to fill out
  123. * @size: size of memory requested
  124. **/
  125. int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
  126. u32 size)
  127. {
  128. mem->size = size;
  129. mem->va = kzalloc(size, GFP_KERNEL);
  130. if (!mem->va)
  131. return -ENOMEM;
  132. return 0;
  133. }
  134. /**
  135. * i40e_free_virt_mem_d - OS specific memory free for shared code
  136. * @hw: pointer to the HW structure
  137. * @mem: ptr to mem struct to free
  138. **/
  139. int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
  140. {
  141. /* it's ok to kfree a NULL pointer */
  142. kfree(mem->va);
  143. mem->va = NULL;
  144. mem->size = 0;
  145. return 0;
  146. }
  147. /**
  148. * i40e_get_lump - find a lump of free generic resource
  149. * @pf: board private structure
  150. * @pile: the pile of resource to search
  151. * @needed: the number of items needed
  152. * @id: an owner id to stick on the items assigned
  153. *
  154. * Returns the base item index of the lump, or negative for error
  155. *
  156. * The search_hint trick and lack of advanced fit-finding only work
  157. * because we're highly likely to have all the same size lump requests.
  158. * Linear search time and any fragmentation should be minimal.
  159. **/
  160. static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
  161. u16 needed, u16 id)
  162. {
  163. int ret = -ENOMEM;
  164. int i, j;
  165. if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
  166. dev_info(&pf->pdev->dev,
  167. "param err: pile=%s needed=%d id=0x%04x\n",
  168. pile ? "<valid>" : "<null>", needed, id);
  169. return -EINVAL;
  170. }
  171. /* start the linear search with an imperfect hint */
  172. i = pile->search_hint;
  173. while (i < pile->num_entries) {
  174. /* skip already allocated entries */
  175. if (pile->list[i] & I40E_PILE_VALID_BIT) {
  176. i++;
  177. continue;
  178. }
  179. /* do we have enough in this lump? */
  180. for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
  181. if (pile->list[i+j] & I40E_PILE_VALID_BIT)
  182. break;
  183. }
  184. if (j == needed) {
  185. /* there was enough, so assign it to the requestor */
  186. for (j = 0; j < needed; j++)
  187. pile->list[i+j] = id | I40E_PILE_VALID_BIT;
  188. ret = i;
  189. pile->search_hint = i + j;
  190. break;
  191. }
  192. /* not enough, so skip over it and continue looking */
  193. i += j;
  194. }
  195. return ret;
  196. }
  197. /**
  198. * i40e_put_lump - return a lump of generic resource
  199. * @pile: the pile of resource to search
  200. * @index: the base item index
  201. * @id: the owner id of the items assigned
  202. *
  203. * Returns the count of items in the lump
  204. **/
  205. static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
  206. {
  207. int valid_id = (id | I40E_PILE_VALID_BIT);
  208. int count = 0;
  209. int i;
  210. if (!pile || index >= pile->num_entries)
  211. return -EINVAL;
  212. for (i = index;
  213. i < pile->num_entries && pile->list[i] == valid_id;
  214. i++) {
  215. pile->list[i] = 0;
  216. count++;
  217. }
  218. if (count && index < pile->search_hint)
  219. pile->search_hint = index;
  220. return count;
  221. }
  222. /**
  223. * i40e_find_vsi_from_id - searches for the vsi with the given id
  224. * @pf: the pf structure to search for the vsi
  225. * @id: id of the vsi it is searching for
  226. **/
  227. struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
  228. {
  229. int i;
  230. for (i = 0; i < pf->num_alloc_vsi; i++)
  231. if (pf->vsi[i] && (pf->vsi[i]->id == id))
  232. return pf->vsi[i];
  233. return NULL;
  234. }
  235. /**
  236. * i40e_service_event_schedule - Schedule the service task to wake up
  237. * @pf: board private structure
  238. *
  239. * If not already scheduled, this puts the task into the work queue
  240. **/
  241. void i40e_service_event_schedule(struct i40e_pf *pf)
  242. {
  243. if (!test_bit(__I40E_DOWN, pf->state) &&
  244. !test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  245. queue_work(i40e_wq, &pf->service_task);
  246. }
  247. /**
  248. * i40e_tx_timeout - Respond to a Tx Hang
  249. * @netdev: network interface device structure
  250. *
  251. * If any port has noticed a Tx timeout, it is likely that the whole
  252. * device is munged, not just the one netdev port, so go for the full
  253. * reset.
  254. **/
  255. static void i40e_tx_timeout(struct net_device *netdev)
  256. {
  257. struct i40e_netdev_priv *np = netdev_priv(netdev);
  258. struct i40e_vsi *vsi = np->vsi;
  259. struct i40e_pf *pf = vsi->back;
  260. struct i40e_ring *tx_ring = NULL;
  261. unsigned int i, hung_queue = 0;
  262. u32 head, val;
  263. pf->tx_timeout_count++;
  264. /* find the stopped queue the same way the stack does */
  265. for (i = 0; i < netdev->num_tx_queues; i++) {
  266. struct netdev_queue *q;
  267. unsigned long trans_start;
  268. q = netdev_get_tx_queue(netdev, i);
  269. trans_start = q->trans_start;
  270. if (netif_xmit_stopped(q) &&
  271. time_after(jiffies,
  272. (trans_start + netdev->watchdog_timeo))) {
  273. hung_queue = i;
  274. break;
  275. }
  276. }
  277. if (i == netdev->num_tx_queues) {
  278. netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
  279. } else {
  280. /* now that we have an index, find the tx_ring struct */
  281. for (i = 0; i < vsi->num_queue_pairs; i++) {
  282. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
  283. if (hung_queue ==
  284. vsi->tx_rings[i]->queue_index) {
  285. tx_ring = vsi->tx_rings[i];
  286. break;
  287. }
  288. }
  289. }
  290. }
  291. if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
  292. pf->tx_timeout_recovery_level = 1; /* reset after some time */
  293. else if (time_before(jiffies,
  294. (pf->tx_timeout_last_recovery + netdev->watchdog_timeo)))
  295. return; /* don't do any new action before the next timeout */
  296. /* don't kick off another recovery if one is already pending */
  297. if (test_and_set_bit(__I40E_TIMEOUT_RECOVERY_PENDING, pf->state))
  298. return;
  299. if (tx_ring) {
  300. head = i40e_get_head(tx_ring);
  301. /* Read interrupt register */
  302. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  303. val = rd32(&pf->hw,
  304. I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
  305. tx_ring->vsi->base_vector - 1));
  306. else
  307. val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
  308. 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",
  309. vsi->seid, hung_queue, tx_ring->next_to_clean,
  310. head, tx_ring->next_to_use,
  311. readl(tx_ring->tail), val);
  312. }
  313. pf->tx_timeout_last_recovery = jiffies;
  314. netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
  315. pf->tx_timeout_recovery_level, hung_queue);
  316. switch (pf->tx_timeout_recovery_level) {
  317. case 1:
  318. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  319. break;
  320. case 2:
  321. set_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
  322. break;
  323. case 3:
  324. set_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state);
  325. break;
  326. default:
  327. netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
  328. break;
  329. }
  330. i40e_service_event_schedule(pf);
  331. pf->tx_timeout_recovery_level++;
  332. }
  333. /**
  334. * i40e_get_vsi_stats_struct - Get System Network Statistics
  335. * @vsi: the VSI we care about
  336. *
  337. * Returns the address of the device statistics structure.
  338. * The statistics are actually updated from the service task.
  339. **/
  340. struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
  341. {
  342. return &vsi->net_stats;
  343. }
  344. /**
  345. * i40e_get_netdev_stats_struct_tx - populate stats from a Tx ring
  346. * @ring: Tx ring to get statistics from
  347. * @stats: statistics entry to be updated
  348. **/
  349. static void i40e_get_netdev_stats_struct_tx(struct i40e_ring *ring,
  350. struct rtnl_link_stats64 *stats)
  351. {
  352. u64 bytes, packets;
  353. unsigned int start;
  354. do {
  355. start = u64_stats_fetch_begin_irq(&ring->syncp);
  356. packets = ring->stats.packets;
  357. bytes = ring->stats.bytes;
  358. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  359. stats->tx_packets += packets;
  360. stats->tx_bytes += bytes;
  361. }
  362. /**
  363. * i40e_get_netdev_stats_struct - Get statistics for netdev interface
  364. * @netdev: network interface device structure
  365. * @stats: data structure to store statistics
  366. *
  367. * Returns the address of the device statistics structure.
  368. * The statistics are actually updated from the service task.
  369. **/
  370. static void i40e_get_netdev_stats_struct(struct net_device *netdev,
  371. struct rtnl_link_stats64 *stats)
  372. {
  373. struct i40e_netdev_priv *np = netdev_priv(netdev);
  374. struct i40e_vsi *vsi = np->vsi;
  375. struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
  376. struct i40e_ring *ring;
  377. int i;
  378. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  379. return;
  380. if (!vsi->tx_rings)
  381. return;
  382. rcu_read_lock();
  383. for (i = 0; i < vsi->num_queue_pairs; i++) {
  384. u64 bytes, packets;
  385. unsigned int start;
  386. ring = READ_ONCE(vsi->tx_rings[i]);
  387. if (!ring)
  388. continue;
  389. i40e_get_netdev_stats_struct_tx(ring, stats);
  390. if (i40e_enabled_xdp_vsi(vsi)) {
  391. ring = READ_ONCE(vsi->xdp_rings[i]);
  392. if (!ring)
  393. continue;
  394. i40e_get_netdev_stats_struct_tx(ring, stats);
  395. }
  396. ring = READ_ONCE(vsi->rx_rings[i]);
  397. if (!ring)
  398. continue;
  399. do {
  400. start = u64_stats_fetch_begin_irq(&ring->syncp);
  401. packets = ring->stats.packets;
  402. bytes = ring->stats.bytes;
  403. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  404. stats->rx_packets += packets;
  405. stats->rx_bytes += bytes;
  406. }
  407. rcu_read_unlock();
  408. /* following stats updated by i40e_watchdog_subtask() */
  409. stats->multicast = vsi_stats->multicast;
  410. stats->tx_errors = vsi_stats->tx_errors;
  411. stats->tx_dropped = vsi_stats->tx_dropped;
  412. stats->rx_errors = vsi_stats->rx_errors;
  413. stats->rx_dropped = vsi_stats->rx_dropped;
  414. stats->rx_crc_errors = vsi_stats->rx_crc_errors;
  415. stats->rx_length_errors = vsi_stats->rx_length_errors;
  416. }
  417. /**
  418. * i40e_vsi_reset_stats - Resets all stats of the given vsi
  419. * @vsi: the VSI to have its stats reset
  420. **/
  421. void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
  422. {
  423. struct rtnl_link_stats64 *ns;
  424. int i;
  425. if (!vsi)
  426. return;
  427. ns = i40e_get_vsi_stats_struct(vsi);
  428. memset(ns, 0, sizeof(*ns));
  429. memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
  430. memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
  431. memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
  432. if (vsi->rx_rings && vsi->rx_rings[0]) {
  433. for (i = 0; i < vsi->num_queue_pairs; i++) {
  434. memset(&vsi->rx_rings[i]->stats, 0,
  435. sizeof(vsi->rx_rings[i]->stats));
  436. memset(&vsi->rx_rings[i]->rx_stats, 0,
  437. sizeof(vsi->rx_rings[i]->rx_stats));
  438. memset(&vsi->tx_rings[i]->stats, 0,
  439. sizeof(vsi->tx_rings[i]->stats));
  440. memset(&vsi->tx_rings[i]->tx_stats, 0,
  441. sizeof(vsi->tx_rings[i]->tx_stats));
  442. }
  443. }
  444. vsi->stat_offsets_loaded = false;
  445. }
  446. /**
  447. * i40e_pf_reset_stats - Reset all of the stats for the given PF
  448. * @pf: the PF to be reset
  449. **/
  450. void i40e_pf_reset_stats(struct i40e_pf *pf)
  451. {
  452. int i;
  453. memset(&pf->stats, 0, sizeof(pf->stats));
  454. memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
  455. pf->stat_offsets_loaded = false;
  456. for (i = 0; i < I40E_MAX_VEB; i++) {
  457. if (pf->veb[i]) {
  458. memset(&pf->veb[i]->stats, 0,
  459. sizeof(pf->veb[i]->stats));
  460. memset(&pf->veb[i]->stats_offsets, 0,
  461. sizeof(pf->veb[i]->stats_offsets));
  462. pf->veb[i]->stat_offsets_loaded = false;
  463. }
  464. }
  465. pf->hw_csum_rx_error = 0;
  466. }
  467. /**
  468. * i40e_stat_update48 - read and update a 48 bit stat from the chip
  469. * @hw: ptr to the hardware info
  470. * @hireg: the high 32 bit reg to read
  471. * @loreg: the low 32 bit reg to read
  472. * @offset_loaded: has the initial offset been loaded yet
  473. * @offset: ptr to current offset value
  474. * @stat: ptr to the stat
  475. *
  476. * Since the device stats are not reset at PFReset, they likely will not
  477. * be zeroed when the driver starts. We'll save the first values read
  478. * and use them as offsets to be subtracted from the raw values in order
  479. * to report stats that count from zero. In the process, we also manage
  480. * the potential roll-over.
  481. **/
  482. static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
  483. bool offset_loaded, u64 *offset, u64 *stat)
  484. {
  485. u64 new_data;
  486. if (hw->device_id == I40E_DEV_ID_QEMU) {
  487. new_data = rd32(hw, loreg);
  488. new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
  489. } else {
  490. new_data = rd64(hw, loreg);
  491. }
  492. if (!offset_loaded)
  493. *offset = new_data;
  494. if (likely(new_data >= *offset))
  495. *stat = new_data - *offset;
  496. else
  497. *stat = (new_data + BIT_ULL(48)) - *offset;
  498. *stat &= 0xFFFFFFFFFFFFULL;
  499. }
  500. /**
  501. * i40e_stat_update32 - read and update a 32 bit stat from the chip
  502. * @hw: ptr to the hardware info
  503. * @reg: the hw reg to read
  504. * @offset_loaded: has the initial offset been loaded yet
  505. * @offset: ptr to current offset value
  506. * @stat: ptr to the stat
  507. **/
  508. static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
  509. bool offset_loaded, u64 *offset, u64 *stat)
  510. {
  511. u32 new_data;
  512. new_data = rd32(hw, reg);
  513. if (!offset_loaded)
  514. *offset = new_data;
  515. if (likely(new_data >= *offset))
  516. *stat = (u32)(new_data - *offset);
  517. else
  518. *stat = (u32)((new_data + BIT_ULL(32)) - *offset);
  519. }
  520. /**
  521. * i40e_stat_update_and_clear32 - read and clear hw reg, update a 32 bit stat
  522. * @hw: ptr to the hardware info
  523. * @reg: the hw reg to read and clear
  524. * @stat: ptr to the stat
  525. **/
  526. static void i40e_stat_update_and_clear32(struct i40e_hw *hw, u32 reg, u64 *stat)
  527. {
  528. u32 new_data = rd32(hw, reg);
  529. wr32(hw, reg, 1); /* must write a nonzero value to clear register */
  530. *stat += new_data;
  531. }
  532. /**
  533. * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
  534. * @vsi: the VSI to be updated
  535. **/
  536. void i40e_update_eth_stats(struct i40e_vsi *vsi)
  537. {
  538. int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
  539. struct i40e_pf *pf = vsi->back;
  540. struct i40e_hw *hw = &pf->hw;
  541. struct i40e_eth_stats *oes;
  542. struct i40e_eth_stats *es; /* device's eth stats */
  543. es = &vsi->eth_stats;
  544. oes = &vsi->eth_stats_offsets;
  545. /* Gather up the stats that the hw collects */
  546. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  547. vsi->stat_offsets_loaded,
  548. &oes->tx_errors, &es->tx_errors);
  549. i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
  550. vsi->stat_offsets_loaded,
  551. &oes->rx_discards, &es->rx_discards);
  552. i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
  553. vsi->stat_offsets_loaded,
  554. &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
  555. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  556. vsi->stat_offsets_loaded,
  557. &oes->tx_errors, &es->tx_errors);
  558. i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
  559. I40E_GLV_GORCL(stat_idx),
  560. vsi->stat_offsets_loaded,
  561. &oes->rx_bytes, &es->rx_bytes);
  562. i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
  563. I40E_GLV_UPRCL(stat_idx),
  564. vsi->stat_offsets_loaded,
  565. &oes->rx_unicast, &es->rx_unicast);
  566. i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
  567. I40E_GLV_MPRCL(stat_idx),
  568. vsi->stat_offsets_loaded,
  569. &oes->rx_multicast, &es->rx_multicast);
  570. i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
  571. I40E_GLV_BPRCL(stat_idx),
  572. vsi->stat_offsets_loaded,
  573. &oes->rx_broadcast, &es->rx_broadcast);
  574. i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
  575. I40E_GLV_GOTCL(stat_idx),
  576. vsi->stat_offsets_loaded,
  577. &oes->tx_bytes, &es->tx_bytes);
  578. i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
  579. I40E_GLV_UPTCL(stat_idx),
  580. vsi->stat_offsets_loaded,
  581. &oes->tx_unicast, &es->tx_unicast);
  582. i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
  583. I40E_GLV_MPTCL(stat_idx),
  584. vsi->stat_offsets_loaded,
  585. &oes->tx_multicast, &es->tx_multicast);
  586. i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
  587. I40E_GLV_BPTCL(stat_idx),
  588. vsi->stat_offsets_loaded,
  589. &oes->tx_broadcast, &es->tx_broadcast);
  590. vsi->stat_offsets_loaded = true;
  591. }
  592. /**
  593. * i40e_update_veb_stats - Update Switch component statistics
  594. * @veb: the VEB being updated
  595. **/
  596. static void i40e_update_veb_stats(struct i40e_veb *veb)
  597. {
  598. struct i40e_pf *pf = veb->pf;
  599. struct i40e_hw *hw = &pf->hw;
  600. struct i40e_eth_stats *oes;
  601. struct i40e_eth_stats *es; /* device's eth stats */
  602. struct i40e_veb_tc_stats *veb_oes;
  603. struct i40e_veb_tc_stats *veb_es;
  604. int i, idx = 0;
  605. idx = veb->stats_idx;
  606. es = &veb->stats;
  607. oes = &veb->stats_offsets;
  608. veb_es = &veb->tc_stats;
  609. veb_oes = &veb->tc_stats_offsets;
  610. /* Gather up the stats that the hw collects */
  611. i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
  612. veb->stat_offsets_loaded,
  613. &oes->tx_discards, &es->tx_discards);
  614. if (hw->revision_id > 0)
  615. i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
  616. veb->stat_offsets_loaded,
  617. &oes->rx_unknown_protocol,
  618. &es->rx_unknown_protocol);
  619. i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
  620. veb->stat_offsets_loaded,
  621. &oes->rx_bytes, &es->rx_bytes);
  622. i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
  623. veb->stat_offsets_loaded,
  624. &oes->rx_unicast, &es->rx_unicast);
  625. i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
  626. veb->stat_offsets_loaded,
  627. &oes->rx_multicast, &es->rx_multicast);
  628. i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
  629. veb->stat_offsets_loaded,
  630. &oes->rx_broadcast, &es->rx_broadcast);
  631. i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
  632. veb->stat_offsets_loaded,
  633. &oes->tx_bytes, &es->tx_bytes);
  634. i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
  635. veb->stat_offsets_loaded,
  636. &oes->tx_unicast, &es->tx_unicast);
  637. i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
  638. veb->stat_offsets_loaded,
  639. &oes->tx_multicast, &es->tx_multicast);
  640. i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
  641. veb->stat_offsets_loaded,
  642. &oes->tx_broadcast, &es->tx_broadcast);
  643. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  644. i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx),
  645. I40E_GLVEBTC_RPCL(i, idx),
  646. veb->stat_offsets_loaded,
  647. &veb_oes->tc_rx_packets[i],
  648. &veb_es->tc_rx_packets[i]);
  649. i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx),
  650. I40E_GLVEBTC_RBCL(i, idx),
  651. veb->stat_offsets_loaded,
  652. &veb_oes->tc_rx_bytes[i],
  653. &veb_es->tc_rx_bytes[i]);
  654. i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx),
  655. I40E_GLVEBTC_TPCL(i, idx),
  656. veb->stat_offsets_loaded,
  657. &veb_oes->tc_tx_packets[i],
  658. &veb_es->tc_tx_packets[i]);
  659. i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx),
  660. I40E_GLVEBTC_TBCL(i, idx),
  661. veb->stat_offsets_loaded,
  662. &veb_oes->tc_tx_bytes[i],
  663. &veb_es->tc_tx_bytes[i]);
  664. }
  665. veb->stat_offsets_loaded = true;
  666. }
  667. /**
  668. * i40e_update_vsi_stats - Update the vsi statistics counters.
  669. * @vsi: the VSI to be updated
  670. *
  671. * There are a few instances where we store the same stat in a
  672. * couple of different structs. This is partly because we have
  673. * the netdev stats that need to be filled out, which is slightly
  674. * different from the "eth_stats" defined by the chip and used in
  675. * VF communications. We sort it out here.
  676. **/
  677. static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
  678. {
  679. struct i40e_pf *pf = vsi->back;
  680. struct rtnl_link_stats64 *ons;
  681. struct rtnl_link_stats64 *ns; /* netdev stats */
  682. struct i40e_eth_stats *oes;
  683. struct i40e_eth_stats *es; /* device's eth stats */
  684. u32 tx_restart, tx_busy;
  685. struct i40e_ring *p;
  686. u32 rx_page, rx_buf;
  687. u64 bytes, packets;
  688. unsigned int start;
  689. u64 tx_linearize;
  690. u64 tx_force_wb;
  691. u64 rx_p, rx_b;
  692. u64 tx_p, tx_b;
  693. u16 q;
  694. if (test_bit(__I40E_VSI_DOWN, vsi->state) ||
  695. test_bit(__I40E_CONFIG_BUSY, pf->state))
  696. return;
  697. ns = i40e_get_vsi_stats_struct(vsi);
  698. ons = &vsi->net_stats_offsets;
  699. es = &vsi->eth_stats;
  700. oes = &vsi->eth_stats_offsets;
  701. /* Gather up the netdev and vsi stats that the driver collects
  702. * on the fly during packet processing
  703. */
  704. rx_b = rx_p = 0;
  705. tx_b = tx_p = 0;
  706. tx_restart = tx_busy = tx_linearize = tx_force_wb = 0;
  707. rx_page = 0;
  708. rx_buf = 0;
  709. rcu_read_lock();
  710. for (q = 0; q < vsi->num_queue_pairs; q++) {
  711. /* locate Tx ring */
  712. p = READ_ONCE(vsi->tx_rings[q]);
  713. if (!p)
  714. continue;
  715. do {
  716. start = u64_stats_fetch_begin_irq(&p->syncp);
  717. packets = p->stats.packets;
  718. bytes = p->stats.bytes;
  719. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  720. tx_b += bytes;
  721. tx_p += packets;
  722. tx_restart += p->tx_stats.restart_queue;
  723. tx_busy += p->tx_stats.tx_busy;
  724. tx_linearize += p->tx_stats.tx_linearize;
  725. tx_force_wb += p->tx_stats.tx_force_wb;
  726. /* locate Rx ring */
  727. p = READ_ONCE(vsi->rx_rings[q]);
  728. if (!p)
  729. continue;
  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. rx_b += bytes;
  736. rx_p += packets;
  737. rx_buf += p->rx_stats.alloc_buff_failed;
  738. rx_page += p->rx_stats.alloc_page_failed;
  739. }
  740. rcu_read_unlock();
  741. vsi->tx_restart = tx_restart;
  742. vsi->tx_busy = tx_busy;
  743. vsi->tx_linearize = tx_linearize;
  744. vsi->tx_force_wb = tx_force_wb;
  745. vsi->rx_page_failed = rx_page;
  746. vsi->rx_buf_failed = rx_buf;
  747. ns->rx_packets = rx_p;
  748. ns->rx_bytes = rx_b;
  749. ns->tx_packets = tx_p;
  750. ns->tx_bytes = tx_b;
  751. /* update netdev stats from eth stats */
  752. i40e_update_eth_stats(vsi);
  753. ons->tx_errors = oes->tx_errors;
  754. ns->tx_errors = es->tx_errors;
  755. ons->multicast = oes->rx_multicast;
  756. ns->multicast = es->rx_multicast;
  757. ons->rx_dropped = oes->rx_discards;
  758. ns->rx_dropped = es->rx_discards;
  759. ons->tx_dropped = oes->tx_discards;
  760. ns->tx_dropped = es->tx_discards;
  761. /* pull in a couple PF stats if this is the main vsi */
  762. if (vsi == pf->vsi[pf->lan_vsi]) {
  763. ns->rx_crc_errors = pf->stats.crc_errors;
  764. ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
  765. ns->rx_length_errors = pf->stats.rx_length_errors;
  766. }
  767. }
  768. /**
  769. * i40e_update_pf_stats - Update the PF statistics counters.
  770. * @pf: the PF to be updated
  771. **/
  772. static void i40e_update_pf_stats(struct i40e_pf *pf)
  773. {
  774. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  775. struct i40e_hw_port_stats *nsd = &pf->stats;
  776. struct i40e_hw *hw = &pf->hw;
  777. u32 val;
  778. int i;
  779. i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
  780. I40E_GLPRT_GORCL(hw->port),
  781. pf->stat_offsets_loaded,
  782. &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
  783. i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
  784. I40E_GLPRT_GOTCL(hw->port),
  785. pf->stat_offsets_loaded,
  786. &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
  787. i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
  788. pf->stat_offsets_loaded,
  789. &osd->eth.rx_discards,
  790. &nsd->eth.rx_discards);
  791. i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
  792. I40E_GLPRT_UPRCL(hw->port),
  793. pf->stat_offsets_loaded,
  794. &osd->eth.rx_unicast,
  795. &nsd->eth.rx_unicast);
  796. i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
  797. I40E_GLPRT_MPRCL(hw->port),
  798. pf->stat_offsets_loaded,
  799. &osd->eth.rx_multicast,
  800. &nsd->eth.rx_multicast);
  801. i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
  802. I40E_GLPRT_BPRCL(hw->port),
  803. pf->stat_offsets_loaded,
  804. &osd->eth.rx_broadcast,
  805. &nsd->eth.rx_broadcast);
  806. i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
  807. I40E_GLPRT_UPTCL(hw->port),
  808. pf->stat_offsets_loaded,
  809. &osd->eth.tx_unicast,
  810. &nsd->eth.tx_unicast);
  811. i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
  812. I40E_GLPRT_MPTCL(hw->port),
  813. pf->stat_offsets_loaded,
  814. &osd->eth.tx_multicast,
  815. &nsd->eth.tx_multicast);
  816. i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
  817. I40E_GLPRT_BPTCL(hw->port),
  818. pf->stat_offsets_loaded,
  819. &osd->eth.tx_broadcast,
  820. &nsd->eth.tx_broadcast);
  821. i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
  822. pf->stat_offsets_loaded,
  823. &osd->tx_dropped_link_down,
  824. &nsd->tx_dropped_link_down);
  825. i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
  826. pf->stat_offsets_loaded,
  827. &osd->crc_errors, &nsd->crc_errors);
  828. i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
  829. pf->stat_offsets_loaded,
  830. &osd->illegal_bytes, &nsd->illegal_bytes);
  831. i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
  832. pf->stat_offsets_loaded,
  833. &osd->mac_local_faults,
  834. &nsd->mac_local_faults);
  835. i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
  836. pf->stat_offsets_loaded,
  837. &osd->mac_remote_faults,
  838. &nsd->mac_remote_faults);
  839. i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
  840. pf->stat_offsets_loaded,
  841. &osd->rx_length_errors,
  842. &nsd->rx_length_errors);
  843. i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
  844. pf->stat_offsets_loaded,
  845. &osd->link_xon_rx, &nsd->link_xon_rx);
  846. i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
  847. pf->stat_offsets_loaded,
  848. &osd->link_xon_tx, &nsd->link_xon_tx);
  849. i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
  850. pf->stat_offsets_loaded,
  851. &osd->link_xoff_rx, &nsd->link_xoff_rx);
  852. i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
  853. pf->stat_offsets_loaded,
  854. &osd->link_xoff_tx, &nsd->link_xoff_tx);
  855. for (i = 0; i < 8; i++) {
  856. i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
  857. pf->stat_offsets_loaded,
  858. &osd->priority_xoff_rx[i],
  859. &nsd->priority_xoff_rx[i]);
  860. i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
  861. pf->stat_offsets_loaded,
  862. &osd->priority_xon_rx[i],
  863. &nsd->priority_xon_rx[i]);
  864. i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
  865. pf->stat_offsets_loaded,
  866. &osd->priority_xon_tx[i],
  867. &nsd->priority_xon_tx[i]);
  868. i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
  869. pf->stat_offsets_loaded,
  870. &osd->priority_xoff_tx[i],
  871. &nsd->priority_xoff_tx[i]);
  872. i40e_stat_update32(hw,
  873. I40E_GLPRT_RXON2OFFCNT(hw->port, i),
  874. pf->stat_offsets_loaded,
  875. &osd->priority_xon_2_xoff[i],
  876. &nsd->priority_xon_2_xoff[i]);
  877. }
  878. i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
  879. I40E_GLPRT_PRC64L(hw->port),
  880. pf->stat_offsets_loaded,
  881. &osd->rx_size_64, &nsd->rx_size_64);
  882. i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
  883. I40E_GLPRT_PRC127L(hw->port),
  884. pf->stat_offsets_loaded,
  885. &osd->rx_size_127, &nsd->rx_size_127);
  886. i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
  887. I40E_GLPRT_PRC255L(hw->port),
  888. pf->stat_offsets_loaded,
  889. &osd->rx_size_255, &nsd->rx_size_255);
  890. i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
  891. I40E_GLPRT_PRC511L(hw->port),
  892. pf->stat_offsets_loaded,
  893. &osd->rx_size_511, &nsd->rx_size_511);
  894. i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
  895. I40E_GLPRT_PRC1023L(hw->port),
  896. pf->stat_offsets_loaded,
  897. &osd->rx_size_1023, &nsd->rx_size_1023);
  898. i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
  899. I40E_GLPRT_PRC1522L(hw->port),
  900. pf->stat_offsets_loaded,
  901. &osd->rx_size_1522, &nsd->rx_size_1522);
  902. i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
  903. I40E_GLPRT_PRC9522L(hw->port),
  904. pf->stat_offsets_loaded,
  905. &osd->rx_size_big, &nsd->rx_size_big);
  906. i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
  907. I40E_GLPRT_PTC64L(hw->port),
  908. pf->stat_offsets_loaded,
  909. &osd->tx_size_64, &nsd->tx_size_64);
  910. i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
  911. I40E_GLPRT_PTC127L(hw->port),
  912. pf->stat_offsets_loaded,
  913. &osd->tx_size_127, &nsd->tx_size_127);
  914. i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
  915. I40E_GLPRT_PTC255L(hw->port),
  916. pf->stat_offsets_loaded,
  917. &osd->tx_size_255, &nsd->tx_size_255);
  918. i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
  919. I40E_GLPRT_PTC511L(hw->port),
  920. pf->stat_offsets_loaded,
  921. &osd->tx_size_511, &nsd->tx_size_511);
  922. i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
  923. I40E_GLPRT_PTC1023L(hw->port),
  924. pf->stat_offsets_loaded,
  925. &osd->tx_size_1023, &nsd->tx_size_1023);
  926. i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
  927. I40E_GLPRT_PTC1522L(hw->port),
  928. pf->stat_offsets_loaded,
  929. &osd->tx_size_1522, &nsd->tx_size_1522);
  930. i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
  931. I40E_GLPRT_PTC9522L(hw->port),
  932. pf->stat_offsets_loaded,
  933. &osd->tx_size_big, &nsd->tx_size_big);
  934. i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
  935. pf->stat_offsets_loaded,
  936. &osd->rx_undersize, &nsd->rx_undersize);
  937. i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
  938. pf->stat_offsets_loaded,
  939. &osd->rx_fragments, &nsd->rx_fragments);
  940. i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
  941. pf->stat_offsets_loaded,
  942. &osd->rx_oversize, &nsd->rx_oversize);
  943. i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
  944. pf->stat_offsets_loaded,
  945. &osd->rx_jabber, &nsd->rx_jabber);
  946. /* FDIR stats */
  947. i40e_stat_update_and_clear32(hw,
  948. I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(hw->pf_id)),
  949. &nsd->fd_atr_match);
  950. i40e_stat_update_and_clear32(hw,
  951. I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(hw->pf_id)),
  952. &nsd->fd_sb_match);
  953. i40e_stat_update_and_clear32(hw,
  954. I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(hw->pf_id)),
  955. &nsd->fd_atr_tunnel_match);
  956. val = rd32(hw, I40E_PRTPM_EEE_STAT);
  957. nsd->tx_lpi_status =
  958. (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
  959. I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
  960. nsd->rx_lpi_status =
  961. (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
  962. I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
  963. i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
  964. pf->stat_offsets_loaded,
  965. &osd->tx_lpi_count, &nsd->tx_lpi_count);
  966. i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
  967. pf->stat_offsets_loaded,
  968. &osd->rx_lpi_count, &nsd->rx_lpi_count);
  969. if (pf->flags & I40E_FLAG_FD_SB_ENABLED &&
  970. !test_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state))
  971. nsd->fd_sb_status = true;
  972. else
  973. nsd->fd_sb_status = false;
  974. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED &&
  975. !test_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state))
  976. nsd->fd_atr_status = true;
  977. else
  978. nsd->fd_atr_status = false;
  979. pf->stat_offsets_loaded = true;
  980. }
  981. /**
  982. * i40e_update_stats - Update the various statistics counters.
  983. * @vsi: the VSI to be updated
  984. *
  985. * Update the various stats for this VSI and its related entities.
  986. **/
  987. void i40e_update_stats(struct i40e_vsi *vsi)
  988. {
  989. struct i40e_pf *pf = vsi->back;
  990. if (vsi == pf->vsi[pf->lan_vsi])
  991. i40e_update_pf_stats(pf);
  992. i40e_update_vsi_stats(vsi);
  993. }
  994. /**
  995. * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
  996. * @vsi: the VSI to be searched
  997. * @macaddr: the MAC address
  998. * @vlan: the vlan
  999. *
  1000. * Returns ptr to the filter object or NULL
  1001. **/
  1002. static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
  1003. const u8 *macaddr, s16 vlan)
  1004. {
  1005. struct i40e_mac_filter *f;
  1006. u64 key;
  1007. if (!vsi || !macaddr)
  1008. return NULL;
  1009. key = i40e_addr_to_hkey(macaddr);
  1010. hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
  1011. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  1012. (vlan == f->vlan))
  1013. return f;
  1014. }
  1015. return NULL;
  1016. }
  1017. /**
  1018. * i40e_find_mac - Find a mac addr in the macvlan filters list
  1019. * @vsi: the VSI to be searched
  1020. * @macaddr: the MAC address we are searching for
  1021. *
  1022. * Returns the first filter with the provided MAC address or NULL if
  1023. * MAC address was not found
  1024. **/
  1025. struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr)
  1026. {
  1027. struct i40e_mac_filter *f;
  1028. u64 key;
  1029. if (!vsi || !macaddr)
  1030. return NULL;
  1031. key = i40e_addr_to_hkey(macaddr);
  1032. hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
  1033. if ((ether_addr_equal(macaddr, f->macaddr)))
  1034. return f;
  1035. }
  1036. return NULL;
  1037. }
  1038. /**
  1039. * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
  1040. * @vsi: the VSI to be searched
  1041. *
  1042. * Returns true if VSI is in vlan mode or false otherwise
  1043. **/
  1044. bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
  1045. {
  1046. /* If we have a PVID, always operate in VLAN mode */
  1047. if (vsi->info.pvid)
  1048. return true;
  1049. /* We need to operate in VLAN mode whenever we have any filters with
  1050. * a VLAN other than I40E_VLAN_ALL. We could check the table each
  1051. * time, incurring search cost repeatedly. However, we can notice two
  1052. * things:
  1053. *
  1054. * 1) the only place where we can gain a VLAN filter is in
  1055. * i40e_add_filter.
  1056. *
  1057. * 2) the only place where filters are actually removed is in
  1058. * i40e_sync_filters_subtask.
  1059. *
  1060. * Thus, we can simply use a boolean value, has_vlan_filters which we
  1061. * will set to true when we add a VLAN filter in i40e_add_filter. Then
  1062. * we have to perform the full search after deleting filters in
  1063. * i40e_sync_filters_subtask, but we already have to search
  1064. * filters here and can perform the check at the same time. This
  1065. * results in avoiding embedding a loop for VLAN mode inside another
  1066. * loop over all the filters, and should maintain correctness as noted
  1067. * above.
  1068. */
  1069. return vsi->has_vlan_filter;
  1070. }
  1071. /**
  1072. * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary
  1073. * @vsi: the VSI to configure
  1074. * @tmp_add_list: list of filters ready to be added
  1075. * @tmp_del_list: list of filters ready to be deleted
  1076. * @vlan_filters: the number of active VLAN filters
  1077. *
  1078. * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they
  1079. * behave as expected. If we have any active VLAN filters remaining or about
  1080. * to be added then we need to update non-VLAN filters to be marked as VLAN=0
  1081. * so that they only match against untagged traffic. If we no longer have any
  1082. * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1
  1083. * so that they match against both tagged and untagged traffic. In this way,
  1084. * we ensure that we correctly receive the desired traffic. This ensures that
  1085. * when we have an active VLAN we will receive only untagged traffic and
  1086. * traffic matching active VLANs. If we have no active VLANs then we will
  1087. * operate in non-VLAN mode and receive all traffic, tagged or untagged.
  1088. *
  1089. * Finally, in a similar fashion, this function also corrects filters when
  1090. * there is an active PVID assigned to this VSI.
  1091. *
  1092. * In case of memory allocation failure return -ENOMEM. Otherwise, return 0.
  1093. *
  1094. * This function is only expected to be called from within
  1095. * i40e_sync_vsi_filters.
  1096. *
  1097. * NOTE: This function expects to be called while under the
  1098. * mac_filter_hash_lock
  1099. */
  1100. static int i40e_correct_mac_vlan_filters(struct i40e_vsi *vsi,
  1101. struct hlist_head *tmp_add_list,
  1102. struct hlist_head *tmp_del_list,
  1103. int vlan_filters)
  1104. {
  1105. s16 pvid = le16_to_cpu(vsi->info.pvid);
  1106. struct i40e_mac_filter *f, *add_head;
  1107. struct i40e_new_mac_filter *new;
  1108. struct hlist_node *h;
  1109. int bkt, new_vlan;
  1110. /* To determine if a particular filter needs to be replaced we
  1111. * have the three following conditions:
  1112. *
  1113. * a) if we have a PVID assigned, then all filters which are
  1114. * not marked as VLAN=PVID must be replaced with filters that
  1115. * are.
  1116. * b) otherwise, if we have any active VLANS, all filters
  1117. * which are marked as VLAN=-1 must be replaced with
  1118. * filters marked as VLAN=0
  1119. * c) finally, if we do not have any active VLANS, all filters
  1120. * which are marked as VLAN=0 must be replaced with filters
  1121. * marked as VLAN=-1
  1122. */
  1123. /* Update the filters about to be added in place */
  1124. hlist_for_each_entry(new, tmp_add_list, hlist) {
  1125. if (pvid && new->f->vlan != pvid)
  1126. new->f->vlan = pvid;
  1127. else if (vlan_filters && new->f->vlan == I40E_VLAN_ANY)
  1128. new->f->vlan = 0;
  1129. else if (!vlan_filters && new->f->vlan == 0)
  1130. new->f->vlan = I40E_VLAN_ANY;
  1131. }
  1132. /* Update the remaining active filters */
  1133. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1134. /* Combine the checks for whether a filter needs to be changed
  1135. * and then determine the new VLAN inside the if block, in
  1136. * order to avoid duplicating code for adding the new filter
  1137. * then deleting the old filter.
  1138. */
  1139. if ((pvid && f->vlan != pvid) ||
  1140. (vlan_filters && f->vlan == I40E_VLAN_ANY) ||
  1141. (!vlan_filters && f->vlan == 0)) {
  1142. /* Determine the new vlan we will be adding */
  1143. if (pvid)
  1144. new_vlan = pvid;
  1145. else if (vlan_filters)
  1146. new_vlan = 0;
  1147. else
  1148. new_vlan = I40E_VLAN_ANY;
  1149. /* Create the new filter */
  1150. add_head = i40e_add_filter(vsi, f->macaddr, new_vlan);
  1151. if (!add_head)
  1152. return -ENOMEM;
  1153. /* Create a temporary i40e_new_mac_filter */
  1154. new = kzalloc(sizeof(*new), GFP_ATOMIC);
  1155. if (!new)
  1156. return -ENOMEM;
  1157. new->f = add_head;
  1158. new->state = add_head->state;
  1159. /* Add the new filter to the tmp list */
  1160. hlist_add_head(&new->hlist, tmp_add_list);
  1161. /* Put the original filter into the delete list */
  1162. f->state = I40E_FILTER_REMOVE;
  1163. hash_del(&f->hlist);
  1164. hlist_add_head(&f->hlist, tmp_del_list);
  1165. }
  1166. }
  1167. vsi->has_vlan_filter = !!vlan_filters;
  1168. return 0;
  1169. }
  1170. /**
  1171. * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
  1172. * @vsi: the PF Main VSI - inappropriate for any other VSI
  1173. * @macaddr: the MAC address
  1174. *
  1175. * Remove whatever filter the firmware set up so the driver can manage
  1176. * its own filtering intelligently.
  1177. **/
  1178. static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
  1179. {
  1180. struct i40e_aqc_remove_macvlan_element_data element;
  1181. struct i40e_pf *pf = vsi->back;
  1182. /* Only appropriate for the PF main VSI */
  1183. if (vsi->type != I40E_VSI_MAIN)
  1184. return;
  1185. memset(&element, 0, sizeof(element));
  1186. ether_addr_copy(element.mac_addr, macaddr);
  1187. element.vlan_tag = 0;
  1188. /* Ignore error returns, some firmware does it this way... */
  1189. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1190. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1191. memset(&element, 0, sizeof(element));
  1192. ether_addr_copy(element.mac_addr, macaddr);
  1193. element.vlan_tag = 0;
  1194. /* ...and some firmware does it this way. */
  1195. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
  1196. I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  1197. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1198. }
  1199. /**
  1200. * i40e_add_filter - Add a mac/vlan filter to the VSI
  1201. * @vsi: the VSI to be searched
  1202. * @macaddr: the MAC address
  1203. * @vlan: the vlan
  1204. *
  1205. * Returns ptr to the filter object or NULL when no memory available.
  1206. *
  1207. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1208. * being held.
  1209. **/
  1210. struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
  1211. const u8 *macaddr, s16 vlan)
  1212. {
  1213. struct i40e_mac_filter *f;
  1214. u64 key;
  1215. if (!vsi || !macaddr)
  1216. return NULL;
  1217. f = i40e_find_filter(vsi, macaddr, vlan);
  1218. if (!f) {
  1219. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  1220. if (!f)
  1221. return NULL;
  1222. /* Update the boolean indicating if we need to function in
  1223. * VLAN mode.
  1224. */
  1225. if (vlan >= 0)
  1226. vsi->has_vlan_filter = true;
  1227. ether_addr_copy(f->macaddr, macaddr);
  1228. f->vlan = vlan;
  1229. f->state = I40E_FILTER_NEW;
  1230. INIT_HLIST_NODE(&f->hlist);
  1231. key = i40e_addr_to_hkey(macaddr);
  1232. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1233. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1234. set_bit(__I40E_MACVLAN_SYNC_PENDING, vsi->back->state);
  1235. }
  1236. /* If we're asked to add a filter that has been marked for removal, it
  1237. * is safe to simply restore it to active state. __i40e_del_filter
  1238. * will have simply deleted any filters which were previously marked
  1239. * NEW or FAILED, so if it is currently marked REMOVE it must have
  1240. * previously been ACTIVE. Since we haven't yet run the sync filters
  1241. * task, just restore this filter to the ACTIVE state so that the
  1242. * sync task leaves it in place
  1243. */
  1244. if (f->state == I40E_FILTER_REMOVE)
  1245. f->state = I40E_FILTER_ACTIVE;
  1246. return f;
  1247. }
  1248. /**
  1249. * __i40e_del_filter - Remove a specific filter from the VSI
  1250. * @vsi: VSI to remove from
  1251. * @f: the filter to remove from the list
  1252. *
  1253. * This function should be called instead of i40e_del_filter only if you know
  1254. * the exact filter you will remove already, such as via i40e_find_filter or
  1255. * i40e_find_mac.
  1256. *
  1257. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1258. * being held.
  1259. * ANOTHER NOTE: This function MUST be called from within the context of
  1260. * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
  1261. * instead of list_for_each_entry().
  1262. **/
  1263. void __i40e_del_filter(struct i40e_vsi *vsi, struct i40e_mac_filter *f)
  1264. {
  1265. if (!f)
  1266. return;
  1267. /* If the filter was never added to firmware then we can just delete it
  1268. * directly and we don't want to set the status to remove or else an
  1269. * admin queue command will unnecessarily fire.
  1270. */
  1271. if ((f->state == I40E_FILTER_FAILED) ||
  1272. (f->state == I40E_FILTER_NEW)) {
  1273. hash_del(&f->hlist);
  1274. kfree(f);
  1275. } else {
  1276. f->state = I40E_FILTER_REMOVE;
  1277. }
  1278. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1279. set_bit(__I40E_MACVLAN_SYNC_PENDING, vsi->back->state);
  1280. }
  1281. /**
  1282. * i40e_del_filter - Remove a MAC/VLAN filter from the VSI
  1283. * @vsi: the VSI to be searched
  1284. * @macaddr: the MAC address
  1285. * @vlan: the VLAN
  1286. *
  1287. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1288. * being held.
  1289. * ANOTHER NOTE: This function MUST be called from within the context of
  1290. * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
  1291. * instead of list_for_each_entry().
  1292. **/
  1293. void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan)
  1294. {
  1295. struct i40e_mac_filter *f;
  1296. if (!vsi || !macaddr)
  1297. return;
  1298. f = i40e_find_filter(vsi, macaddr, vlan);
  1299. __i40e_del_filter(vsi, f);
  1300. }
  1301. /**
  1302. * i40e_add_mac_filter - Add a MAC filter for all active VLANs
  1303. * @vsi: the VSI to be searched
  1304. * @macaddr: the mac address to be filtered
  1305. *
  1306. * If we're not in VLAN mode, just add the filter to I40E_VLAN_ANY. Otherwise,
  1307. * go through all the macvlan filters and add a macvlan filter for each
  1308. * unique vlan that already exists. If a PVID has been assigned, instead only
  1309. * add the macaddr to that VLAN.
  1310. *
  1311. * Returns last filter added on success, else NULL
  1312. **/
  1313. struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi,
  1314. const u8 *macaddr)
  1315. {
  1316. struct i40e_mac_filter *f, *add = NULL;
  1317. struct hlist_node *h;
  1318. int bkt;
  1319. if (vsi->info.pvid)
  1320. return i40e_add_filter(vsi, macaddr,
  1321. le16_to_cpu(vsi->info.pvid));
  1322. if (!i40e_is_vsi_in_vlan(vsi))
  1323. return i40e_add_filter(vsi, macaddr, I40E_VLAN_ANY);
  1324. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1325. if (f->state == I40E_FILTER_REMOVE)
  1326. continue;
  1327. add = i40e_add_filter(vsi, macaddr, f->vlan);
  1328. if (!add)
  1329. return NULL;
  1330. }
  1331. return add;
  1332. }
  1333. /**
  1334. * i40e_del_mac_filter - Remove a MAC filter from all VLANs
  1335. * @vsi: the VSI to be searched
  1336. * @macaddr: the mac address to be removed
  1337. *
  1338. * Removes a given MAC address from a VSI regardless of what VLAN it has been
  1339. * associated with.
  1340. *
  1341. * Returns 0 for success, or error
  1342. **/
  1343. int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr)
  1344. {
  1345. struct i40e_mac_filter *f;
  1346. struct hlist_node *h;
  1347. bool found = false;
  1348. int bkt;
  1349. WARN(!spin_is_locked(&vsi->mac_filter_hash_lock),
  1350. "Missing mac_filter_hash_lock\n");
  1351. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1352. if (ether_addr_equal(macaddr, f->macaddr)) {
  1353. __i40e_del_filter(vsi, f);
  1354. found = true;
  1355. }
  1356. }
  1357. if (found)
  1358. return 0;
  1359. else
  1360. return -ENOENT;
  1361. }
  1362. /**
  1363. * i40e_set_mac - NDO callback to set mac address
  1364. * @netdev: network interface device structure
  1365. * @p: pointer to an address structure
  1366. *
  1367. * Returns 0 on success, negative on failure
  1368. **/
  1369. static int i40e_set_mac(struct net_device *netdev, void *p)
  1370. {
  1371. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1372. struct i40e_vsi *vsi = np->vsi;
  1373. struct i40e_pf *pf = vsi->back;
  1374. struct i40e_hw *hw = &pf->hw;
  1375. struct sockaddr *addr = p;
  1376. if (!is_valid_ether_addr(addr->sa_data))
  1377. return -EADDRNOTAVAIL;
  1378. if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
  1379. netdev_info(netdev, "already using mac address %pM\n",
  1380. addr->sa_data);
  1381. return 0;
  1382. }
  1383. if (test_bit(__I40E_VSI_DOWN, vsi->back->state) ||
  1384. test_bit(__I40E_RESET_RECOVERY_PENDING, vsi->back->state))
  1385. return -EADDRNOTAVAIL;
  1386. if (ether_addr_equal(hw->mac.addr, addr->sa_data))
  1387. netdev_info(netdev, "returning to hw mac address %pM\n",
  1388. hw->mac.addr);
  1389. else
  1390. netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
  1391. /* Copy the address first, so that we avoid a possible race with
  1392. * .set_rx_mode().
  1393. * - Remove old address from MAC filter
  1394. * - Copy new address
  1395. * - Add new address to MAC filter
  1396. */
  1397. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1398. i40e_del_mac_filter(vsi, netdev->dev_addr);
  1399. ether_addr_copy(netdev->dev_addr, addr->sa_data);
  1400. i40e_add_mac_filter(vsi, netdev->dev_addr);
  1401. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1402. if (vsi->type == I40E_VSI_MAIN) {
  1403. i40e_status ret;
  1404. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  1405. I40E_AQC_WRITE_TYPE_LAA_WOL,
  1406. addr->sa_data, NULL);
  1407. if (ret)
  1408. netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n",
  1409. i40e_stat_str(hw, ret),
  1410. i40e_aq_str(hw, hw->aq.asq_last_status));
  1411. }
  1412. /* schedule our worker thread which will take care of
  1413. * applying the new filter changes
  1414. */
  1415. i40e_service_event_schedule(vsi->back);
  1416. return 0;
  1417. }
  1418. /**
  1419. * i40e_config_rss_aq - Prepare for RSS using AQ commands
  1420. * @vsi: vsi structure
  1421. * @seed: RSS hash seed
  1422. **/
  1423. static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  1424. u8 *lut, u16 lut_size)
  1425. {
  1426. struct i40e_pf *pf = vsi->back;
  1427. struct i40e_hw *hw = &pf->hw;
  1428. int ret = 0;
  1429. if (seed) {
  1430. struct i40e_aqc_get_set_rss_key_data *seed_dw =
  1431. (struct i40e_aqc_get_set_rss_key_data *)seed;
  1432. ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw);
  1433. if (ret) {
  1434. dev_info(&pf->pdev->dev,
  1435. "Cannot set RSS key, err %s aq_err %s\n",
  1436. i40e_stat_str(hw, ret),
  1437. i40e_aq_str(hw, hw->aq.asq_last_status));
  1438. return ret;
  1439. }
  1440. }
  1441. if (lut) {
  1442. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  1443. ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  1444. if (ret) {
  1445. dev_info(&pf->pdev->dev,
  1446. "Cannot set RSS lut, err %s aq_err %s\n",
  1447. i40e_stat_str(hw, ret),
  1448. i40e_aq_str(hw, hw->aq.asq_last_status));
  1449. return ret;
  1450. }
  1451. }
  1452. return ret;
  1453. }
  1454. /**
  1455. * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
  1456. * @vsi: VSI structure
  1457. **/
  1458. static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
  1459. {
  1460. struct i40e_pf *pf = vsi->back;
  1461. u8 seed[I40E_HKEY_ARRAY_SIZE];
  1462. u8 *lut;
  1463. int ret;
  1464. if (!(pf->hw_features & I40E_HW_RSS_AQ_CAPABLE))
  1465. return 0;
  1466. if (!vsi->rss_size)
  1467. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  1468. vsi->num_queue_pairs);
  1469. if (!vsi->rss_size)
  1470. return -EINVAL;
  1471. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  1472. if (!lut)
  1473. return -ENOMEM;
  1474. /* Use the user configured hash keys and lookup table if there is one,
  1475. * otherwise use default
  1476. */
  1477. if (vsi->rss_lut_user)
  1478. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  1479. else
  1480. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  1481. if (vsi->rss_hkey_user)
  1482. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  1483. else
  1484. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  1485. ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
  1486. kfree(lut);
  1487. return ret;
  1488. }
  1489. /**
  1490. * i40e_vsi_setup_queue_map_mqprio - Prepares mqprio based tc_config
  1491. * @vsi: the VSI being configured,
  1492. * @ctxt: VSI context structure
  1493. * @enabled_tc: number of traffic classes to enable
  1494. *
  1495. * Prepares VSI tc_config to have queue configurations based on MQPRIO options.
  1496. **/
  1497. static int i40e_vsi_setup_queue_map_mqprio(struct i40e_vsi *vsi,
  1498. struct i40e_vsi_context *ctxt,
  1499. u8 enabled_tc)
  1500. {
  1501. u16 qcount = 0, max_qcount, qmap, sections = 0;
  1502. int i, override_q, pow, num_qps, ret;
  1503. u8 netdev_tc = 0, offset = 0;
  1504. if (vsi->type != I40E_VSI_MAIN)
  1505. return -EINVAL;
  1506. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1507. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1508. vsi->tc_config.numtc = vsi->mqprio_qopt.qopt.num_tc;
  1509. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1510. num_qps = vsi->mqprio_qopt.qopt.count[0];
  1511. /* find the next higher power-of-2 of num queue pairs */
  1512. pow = ilog2(num_qps);
  1513. if (!is_power_of_2(num_qps))
  1514. pow++;
  1515. qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1516. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1517. /* Setup queue offset/count for all TCs for given VSI */
  1518. max_qcount = vsi->mqprio_qopt.qopt.count[0];
  1519. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1520. /* See if the given TC is enabled for the given VSI */
  1521. if (vsi->tc_config.enabled_tc & BIT(i)) {
  1522. offset = vsi->mqprio_qopt.qopt.offset[i];
  1523. qcount = vsi->mqprio_qopt.qopt.count[i];
  1524. if (qcount > max_qcount)
  1525. max_qcount = qcount;
  1526. vsi->tc_config.tc_info[i].qoffset = offset;
  1527. vsi->tc_config.tc_info[i].qcount = qcount;
  1528. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1529. } else {
  1530. /* TC is not enabled so set the offset to
  1531. * default queue and allocate one queue
  1532. * for the given TC.
  1533. */
  1534. vsi->tc_config.tc_info[i].qoffset = 0;
  1535. vsi->tc_config.tc_info[i].qcount = 1;
  1536. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1537. }
  1538. }
  1539. /* Set actual Tx/Rx queue pairs */
  1540. vsi->num_queue_pairs = offset + qcount;
  1541. /* Setup queue TC[0].qmap for given VSI context */
  1542. ctxt->info.tc_mapping[0] = cpu_to_le16(qmap);
  1543. ctxt->info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1544. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1545. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1546. /* Reconfigure RSS for main VSI with max queue count */
  1547. vsi->rss_size = max_qcount;
  1548. ret = i40e_vsi_config_rss(vsi);
  1549. if (ret) {
  1550. dev_info(&vsi->back->pdev->dev,
  1551. "Failed to reconfig rss for num_queues (%u)\n",
  1552. max_qcount);
  1553. return ret;
  1554. }
  1555. vsi->reconfig_rss = true;
  1556. dev_dbg(&vsi->back->pdev->dev,
  1557. "Reconfigured rss with num_queues (%u)\n", max_qcount);
  1558. /* Find queue count available for channel VSIs and starting offset
  1559. * for channel VSIs
  1560. */
  1561. override_q = vsi->mqprio_qopt.qopt.count[0];
  1562. if (override_q && override_q < vsi->num_queue_pairs) {
  1563. vsi->cnt_q_avail = vsi->num_queue_pairs - override_q;
  1564. vsi->next_base_queue = override_q;
  1565. }
  1566. return 0;
  1567. }
  1568. /**
  1569. * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
  1570. * @vsi: the VSI being setup
  1571. * @ctxt: VSI context structure
  1572. * @enabled_tc: Enabled TCs bitmap
  1573. * @is_add: True if called before Add VSI
  1574. *
  1575. * Setup VSI queue mapping for enabled traffic classes.
  1576. **/
  1577. static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1578. struct i40e_vsi_context *ctxt,
  1579. u8 enabled_tc,
  1580. bool is_add)
  1581. {
  1582. struct i40e_pf *pf = vsi->back;
  1583. u16 sections = 0;
  1584. u8 netdev_tc = 0;
  1585. u16 numtc = 1;
  1586. u16 qcount;
  1587. u8 offset;
  1588. u16 qmap;
  1589. int i;
  1590. u16 num_tc_qps = 0;
  1591. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1592. offset = 0;
  1593. /* Number of queues per enabled TC */
  1594. num_tc_qps = vsi->alloc_queue_pairs;
  1595. if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  1596. /* Find numtc from enabled TC bitmap */
  1597. for (i = 0, numtc = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1598. if (enabled_tc & BIT(i)) /* TC is enabled */
  1599. numtc++;
  1600. }
  1601. if (!numtc) {
  1602. dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
  1603. numtc = 1;
  1604. }
  1605. num_tc_qps = num_tc_qps / numtc;
  1606. num_tc_qps = min_t(int, num_tc_qps,
  1607. i40e_pf_get_max_q_per_tc(pf));
  1608. }
  1609. vsi->tc_config.numtc = numtc;
  1610. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1611. /* Do not allow use more TC queue pairs than MSI-X vectors exist */
  1612. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  1613. num_tc_qps = min_t(int, num_tc_qps, pf->num_lan_msix);
  1614. /* Setup queue offset/count for all TCs for given VSI */
  1615. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1616. /* See if the given TC is enabled for the given VSI */
  1617. if (vsi->tc_config.enabled_tc & BIT(i)) {
  1618. /* TC is enabled */
  1619. int pow, num_qps;
  1620. switch (vsi->type) {
  1621. case I40E_VSI_MAIN:
  1622. if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED |
  1623. I40E_FLAG_FD_ATR_ENABLED)) ||
  1624. vsi->tc_config.enabled_tc != 1) {
  1625. qcount = min_t(int, pf->alloc_rss_size,
  1626. num_tc_qps);
  1627. break;
  1628. }
  1629. /* fall through */
  1630. case I40E_VSI_FDIR:
  1631. case I40E_VSI_SRIOV:
  1632. case I40E_VSI_VMDQ2:
  1633. default:
  1634. qcount = num_tc_qps;
  1635. WARN_ON(i != 0);
  1636. break;
  1637. }
  1638. vsi->tc_config.tc_info[i].qoffset = offset;
  1639. vsi->tc_config.tc_info[i].qcount = qcount;
  1640. /* find the next higher power-of-2 of num queue pairs */
  1641. num_qps = qcount;
  1642. pow = 0;
  1643. while (num_qps && (BIT_ULL(pow) < qcount)) {
  1644. pow++;
  1645. num_qps >>= 1;
  1646. }
  1647. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1648. qmap =
  1649. (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1650. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1651. offset += qcount;
  1652. } else {
  1653. /* TC is not enabled so set the offset to
  1654. * default queue and allocate one queue
  1655. * for the given TC.
  1656. */
  1657. vsi->tc_config.tc_info[i].qoffset = 0;
  1658. vsi->tc_config.tc_info[i].qcount = 1;
  1659. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1660. qmap = 0;
  1661. }
  1662. ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
  1663. }
  1664. /* Set actual Tx/Rx queue pairs */
  1665. vsi->num_queue_pairs = offset;
  1666. if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
  1667. if (vsi->req_queue_pairs > 0)
  1668. vsi->num_queue_pairs = vsi->req_queue_pairs;
  1669. else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  1670. vsi->num_queue_pairs = pf->num_lan_msix;
  1671. }
  1672. /* Scheduler section valid can only be set for ADD VSI */
  1673. if (is_add) {
  1674. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1675. ctxt->info.up_enable_bits = enabled_tc;
  1676. }
  1677. if (vsi->type == I40E_VSI_SRIOV) {
  1678. ctxt->info.mapping_flags |=
  1679. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
  1680. for (i = 0; i < vsi->num_queue_pairs; i++)
  1681. ctxt->info.queue_mapping[i] =
  1682. cpu_to_le16(vsi->base_queue + i);
  1683. } else {
  1684. ctxt->info.mapping_flags |=
  1685. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1686. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1687. }
  1688. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1689. }
  1690. /**
  1691. * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address
  1692. * @netdev: the netdevice
  1693. * @addr: address to add
  1694. *
  1695. * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
  1696. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  1697. */
  1698. static int i40e_addr_sync(struct net_device *netdev, const u8 *addr)
  1699. {
  1700. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1701. struct i40e_vsi *vsi = np->vsi;
  1702. if (i40e_add_mac_filter(vsi, addr))
  1703. return 0;
  1704. else
  1705. return -ENOMEM;
  1706. }
  1707. /**
  1708. * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
  1709. * @netdev: the netdevice
  1710. * @addr: address to add
  1711. *
  1712. * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
  1713. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  1714. */
  1715. static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr)
  1716. {
  1717. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1718. struct i40e_vsi *vsi = np->vsi;
  1719. /* Under some circumstances, we might receive a request to delete
  1720. * our own device address from our uc list. Because we store the
  1721. * device address in the VSI's MAC/VLAN filter list, we need to ignore
  1722. * such requests and not delete our device address from this list.
  1723. */
  1724. if (ether_addr_equal(addr, netdev->dev_addr))
  1725. return 0;
  1726. i40e_del_mac_filter(vsi, addr);
  1727. return 0;
  1728. }
  1729. /**
  1730. * i40e_set_rx_mode - NDO callback to set the netdev filters
  1731. * @netdev: network interface device structure
  1732. **/
  1733. static void i40e_set_rx_mode(struct net_device *netdev)
  1734. {
  1735. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1736. struct i40e_vsi *vsi = np->vsi;
  1737. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1738. __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
  1739. __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
  1740. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1741. /* check for other flag changes */
  1742. if (vsi->current_netdev_flags != vsi->netdev->flags) {
  1743. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1744. set_bit(__I40E_MACVLAN_SYNC_PENDING, vsi->back->state);
  1745. }
  1746. }
  1747. /**
  1748. * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
  1749. * @vsi: Pointer to VSI struct
  1750. * @from: Pointer to list which contains MAC filter entries - changes to
  1751. * those entries needs to be undone.
  1752. *
  1753. * MAC filter entries from this list were slated for deletion.
  1754. **/
  1755. static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi,
  1756. struct hlist_head *from)
  1757. {
  1758. struct i40e_mac_filter *f;
  1759. struct hlist_node *h;
  1760. hlist_for_each_entry_safe(f, h, from, hlist) {
  1761. u64 key = i40e_addr_to_hkey(f->macaddr);
  1762. /* Move the element back into MAC filter list*/
  1763. hlist_del(&f->hlist);
  1764. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1765. }
  1766. }
  1767. /**
  1768. * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
  1769. * @vsi: Pointer to vsi struct
  1770. * @from: Pointer to list which contains MAC filter entries - changes to
  1771. * those entries needs to be undone.
  1772. *
  1773. * MAC filter entries from this list were slated for addition.
  1774. **/
  1775. static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi,
  1776. struct hlist_head *from)
  1777. {
  1778. struct i40e_new_mac_filter *new;
  1779. struct hlist_node *h;
  1780. hlist_for_each_entry_safe(new, h, from, hlist) {
  1781. /* We can simply free the wrapper structure */
  1782. hlist_del(&new->hlist);
  1783. kfree(new);
  1784. }
  1785. }
  1786. /**
  1787. * i40e_next_entry - Get the next non-broadcast filter from a list
  1788. * @next: pointer to filter in list
  1789. *
  1790. * Returns the next non-broadcast filter in the list. Required so that we
  1791. * ignore broadcast filters within the list, since these are not handled via
  1792. * the normal firmware update path.
  1793. */
  1794. static
  1795. struct i40e_new_mac_filter *i40e_next_filter(struct i40e_new_mac_filter *next)
  1796. {
  1797. hlist_for_each_entry_continue(next, hlist) {
  1798. if (!is_broadcast_ether_addr(next->f->macaddr))
  1799. return next;
  1800. }
  1801. return NULL;
  1802. }
  1803. /**
  1804. * i40e_update_filter_state - Update filter state based on return data
  1805. * from firmware
  1806. * @count: Number of filters added
  1807. * @add_list: return data from fw
  1808. * @add_head: pointer to first filter in current batch
  1809. *
  1810. * MAC filter entries from list were slated to be added to device. Returns
  1811. * number of successful filters. Note that 0 does NOT mean success!
  1812. **/
  1813. static int
  1814. i40e_update_filter_state(int count,
  1815. struct i40e_aqc_add_macvlan_element_data *add_list,
  1816. struct i40e_new_mac_filter *add_head)
  1817. {
  1818. int retval = 0;
  1819. int i;
  1820. for (i = 0; i < count; i++) {
  1821. /* Always check status of each filter. We don't need to check
  1822. * the firmware return status because we pre-set the filter
  1823. * status to I40E_AQC_MM_ERR_NO_RES when sending the filter
  1824. * request to the adminq. Thus, if it no longer matches then
  1825. * we know the filter is active.
  1826. */
  1827. if (add_list[i].match_method == I40E_AQC_MM_ERR_NO_RES) {
  1828. add_head->state = I40E_FILTER_FAILED;
  1829. } else {
  1830. add_head->state = I40E_FILTER_ACTIVE;
  1831. retval++;
  1832. }
  1833. add_head = i40e_next_filter(add_head);
  1834. if (!add_head)
  1835. break;
  1836. }
  1837. return retval;
  1838. }
  1839. /**
  1840. * i40e_aqc_del_filters - Request firmware to delete a set of filters
  1841. * @vsi: ptr to the VSI
  1842. * @vsi_name: name to display in messages
  1843. * @list: the list of filters to send to firmware
  1844. * @num_del: the number of filters to delete
  1845. * @retval: Set to -EIO on failure to delete
  1846. *
  1847. * Send a request to firmware via AdminQ to delete a set of filters. Uses
  1848. * *retval instead of a return value so that success does not force ret_val to
  1849. * be set to 0. This ensures that a sequence of calls to this function
  1850. * preserve the previous value of *retval on successful delete.
  1851. */
  1852. static
  1853. void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name,
  1854. struct i40e_aqc_remove_macvlan_element_data *list,
  1855. int num_del, int *retval)
  1856. {
  1857. struct i40e_hw *hw = &vsi->back->hw;
  1858. i40e_status aq_ret;
  1859. int aq_err;
  1860. aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL);
  1861. aq_err = hw->aq.asq_last_status;
  1862. /* Explicitly ignore and do not report when firmware returns ENOENT */
  1863. if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) {
  1864. *retval = -EIO;
  1865. dev_info(&vsi->back->pdev->dev,
  1866. "ignoring delete macvlan error on %s, err %s, aq_err %s\n",
  1867. vsi_name, i40e_stat_str(hw, aq_ret),
  1868. i40e_aq_str(hw, aq_err));
  1869. }
  1870. }
  1871. /**
  1872. * i40e_aqc_add_filters - Request firmware to add a set of filters
  1873. * @vsi: ptr to the VSI
  1874. * @vsi_name: name to display in messages
  1875. * @list: the list of filters to send to firmware
  1876. * @add_head: Position in the add hlist
  1877. * @num_add: the number of filters to add
  1878. *
  1879. * Send a request to firmware via AdminQ to add a chunk of filters. Will set
  1880. * __I40E_VSI_OVERFLOW_PROMISC bit in vsi->state if the firmware has run out of
  1881. * space for more filters.
  1882. */
  1883. static
  1884. void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name,
  1885. struct i40e_aqc_add_macvlan_element_data *list,
  1886. struct i40e_new_mac_filter *add_head,
  1887. int num_add)
  1888. {
  1889. struct i40e_hw *hw = &vsi->back->hw;
  1890. int aq_err, fcnt;
  1891. i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL);
  1892. aq_err = hw->aq.asq_last_status;
  1893. fcnt = i40e_update_filter_state(num_add, list, add_head);
  1894. if (fcnt != num_add) {
  1895. set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  1896. dev_warn(&vsi->back->pdev->dev,
  1897. "Error %s adding RX filters on %s, promiscuous mode forced on\n",
  1898. i40e_aq_str(hw, aq_err),
  1899. vsi_name);
  1900. }
  1901. }
  1902. /**
  1903. * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags
  1904. * @vsi: pointer to the VSI
  1905. * @vsi_name: the VSI name
  1906. * @f: filter data
  1907. *
  1908. * This function sets or clears the promiscuous broadcast flags for VLAN
  1909. * filters in order to properly receive broadcast frames. Assumes that only
  1910. * broadcast filters are passed.
  1911. *
  1912. * Returns status indicating success or failure;
  1913. **/
  1914. static i40e_status
  1915. i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name,
  1916. struct i40e_mac_filter *f)
  1917. {
  1918. bool enable = f->state == I40E_FILTER_NEW;
  1919. struct i40e_hw *hw = &vsi->back->hw;
  1920. i40e_status aq_ret;
  1921. if (f->vlan == I40E_VLAN_ANY) {
  1922. aq_ret = i40e_aq_set_vsi_broadcast(hw,
  1923. vsi->seid,
  1924. enable,
  1925. NULL);
  1926. } else {
  1927. aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw,
  1928. vsi->seid,
  1929. enable,
  1930. f->vlan,
  1931. NULL);
  1932. }
  1933. if (aq_ret) {
  1934. set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  1935. dev_warn(&vsi->back->pdev->dev,
  1936. "Error %s, forcing overflow promiscuous on %s\n",
  1937. i40e_aq_str(hw, hw->aq.asq_last_status),
  1938. vsi_name);
  1939. }
  1940. return aq_ret;
  1941. }
  1942. /**
  1943. * i40e_set_promiscuous - set promiscuous mode
  1944. * @pf: board private structure
  1945. * @promisc: promisc on or off
  1946. *
  1947. * There are different ways of setting promiscuous mode on a PF depending on
  1948. * what state/environment we're in. This identifies and sets it appropriately.
  1949. * Returns 0 on success.
  1950. **/
  1951. static int i40e_set_promiscuous(struct i40e_pf *pf, bool promisc)
  1952. {
  1953. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  1954. struct i40e_hw *hw = &pf->hw;
  1955. i40e_status aq_ret;
  1956. if (vsi->type == I40E_VSI_MAIN &&
  1957. pf->lan_veb != I40E_NO_VEB &&
  1958. !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
  1959. /* set defport ON for Main VSI instead of true promisc
  1960. * this way we will get all unicast/multicast and VLAN
  1961. * promisc behavior but will not get VF or VMDq traffic
  1962. * replicated on the Main VSI.
  1963. */
  1964. if (promisc)
  1965. aq_ret = i40e_aq_set_default_vsi(hw,
  1966. vsi->seid,
  1967. NULL);
  1968. else
  1969. aq_ret = i40e_aq_clear_default_vsi(hw,
  1970. vsi->seid,
  1971. NULL);
  1972. if (aq_ret) {
  1973. dev_info(&pf->pdev->dev,
  1974. "Set default VSI failed, err %s, aq_err %s\n",
  1975. i40e_stat_str(hw, aq_ret),
  1976. i40e_aq_str(hw, hw->aq.asq_last_status));
  1977. }
  1978. } else {
  1979. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
  1980. hw,
  1981. vsi->seid,
  1982. promisc, NULL,
  1983. true);
  1984. if (aq_ret) {
  1985. dev_info(&pf->pdev->dev,
  1986. "set unicast promisc failed, err %s, aq_err %s\n",
  1987. i40e_stat_str(hw, aq_ret),
  1988. i40e_aq_str(hw, hw->aq.asq_last_status));
  1989. }
  1990. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
  1991. hw,
  1992. vsi->seid,
  1993. promisc, NULL);
  1994. if (aq_ret) {
  1995. dev_info(&pf->pdev->dev,
  1996. "set multicast promisc failed, err %s, aq_err %s\n",
  1997. i40e_stat_str(hw, aq_ret),
  1998. i40e_aq_str(hw, hw->aq.asq_last_status));
  1999. }
  2000. }
  2001. if (!aq_ret)
  2002. pf->cur_promisc = promisc;
  2003. return aq_ret;
  2004. }
  2005. /**
  2006. * i40e_sync_vsi_filters - Update the VSI filter list to the HW
  2007. * @vsi: ptr to the VSI
  2008. *
  2009. * Push any outstanding VSI filter changes through the AdminQ.
  2010. *
  2011. * Returns 0 or error value
  2012. **/
  2013. int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
  2014. {
  2015. struct hlist_head tmp_add_list, tmp_del_list;
  2016. struct i40e_mac_filter *f;
  2017. struct i40e_new_mac_filter *new, *add_head = NULL;
  2018. struct i40e_hw *hw = &vsi->back->hw;
  2019. bool old_overflow, new_overflow;
  2020. unsigned int failed_filters = 0;
  2021. unsigned int vlan_filters = 0;
  2022. char vsi_name[16] = "PF";
  2023. int filter_list_len = 0;
  2024. i40e_status aq_ret = 0;
  2025. u32 changed_flags = 0;
  2026. struct hlist_node *h;
  2027. struct i40e_pf *pf;
  2028. int num_add = 0;
  2029. int num_del = 0;
  2030. int retval = 0;
  2031. u16 cmd_flags;
  2032. int list_size;
  2033. int bkt;
  2034. /* empty array typed pointers, kcalloc later */
  2035. struct i40e_aqc_add_macvlan_element_data *add_list;
  2036. struct i40e_aqc_remove_macvlan_element_data *del_list;
  2037. while (test_and_set_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state))
  2038. usleep_range(1000, 2000);
  2039. pf = vsi->back;
  2040. old_overflow = test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  2041. if (vsi->netdev) {
  2042. changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
  2043. vsi->current_netdev_flags = vsi->netdev->flags;
  2044. }
  2045. INIT_HLIST_HEAD(&tmp_add_list);
  2046. INIT_HLIST_HEAD(&tmp_del_list);
  2047. if (vsi->type == I40E_VSI_SRIOV)
  2048. snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id);
  2049. else if (vsi->type != I40E_VSI_MAIN)
  2050. snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid);
  2051. if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
  2052. vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
  2053. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2054. /* Create a list of filters to delete. */
  2055. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2056. if (f->state == I40E_FILTER_REMOVE) {
  2057. /* Move the element into temporary del_list */
  2058. hash_del(&f->hlist);
  2059. hlist_add_head(&f->hlist, &tmp_del_list);
  2060. /* Avoid counting removed filters */
  2061. continue;
  2062. }
  2063. if (f->state == I40E_FILTER_NEW) {
  2064. /* Create a temporary i40e_new_mac_filter */
  2065. new = kzalloc(sizeof(*new), GFP_ATOMIC);
  2066. if (!new)
  2067. goto err_no_memory_locked;
  2068. /* Store pointer to the real filter */
  2069. new->f = f;
  2070. new->state = f->state;
  2071. /* Add it to the hash list */
  2072. hlist_add_head(&new->hlist, &tmp_add_list);
  2073. }
  2074. /* Count the number of active (current and new) VLAN
  2075. * filters we have now. Does not count filters which
  2076. * are marked for deletion.
  2077. */
  2078. if (f->vlan > 0)
  2079. vlan_filters++;
  2080. }
  2081. retval = i40e_correct_mac_vlan_filters(vsi,
  2082. &tmp_add_list,
  2083. &tmp_del_list,
  2084. vlan_filters);
  2085. if (retval)
  2086. goto err_no_memory_locked;
  2087. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2088. }
  2089. /* Now process 'del_list' outside the lock */
  2090. if (!hlist_empty(&tmp_del_list)) {
  2091. filter_list_len = hw->aq.asq_buf_size /
  2092. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  2093. list_size = filter_list_len *
  2094. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  2095. del_list = kzalloc(list_size, GFP_ATOMIC);
  2096. if (!del_list)
  2097. goto err_no_memory;
  2098. hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) {
  2099. cmd_flags = 0;
  2100. /* handle broadcast filters by updating the broadcast
  2101. * promiscuous flag and release filter list.
  2102. */
  2103. if (is_broadcast_ether_addr(f->macaddr)) {
  2104. i40e_aqc_broadcast_filter(vsi, vsi_name, f);
  2105. hlist_del(&f->hlist);
  2106. kfree(f);
  2107. continue;
  2108. }
  2109. /* add to delete list */
  2110. ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
  2111. if (f->vlan == I40E_VLAN_ANY) {
  2112. del_list[num_del].vlan_tag = 0;
  2113. cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  2114. } else {
  2115. del_list[num_del].vlan_tag =
  2116. cpu_to_le16((u16)(f->vlan));
  2117. }
  2118. cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  2119. del_list[num_del].flags = cmd_flags;
  2120. num_del++;
  2121. /* flush a full buffer */
  2122. if (num_del == filter_list_len) {
  2123. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  2124. num_del, &retval);
  2125. memset(del_list, 0, list_size);
  2126. num_del = 0;
  2127. }
  2128. /* Release memory for MAC filter entries which were
  2129. * synced up with HW.
  2130. */
  2131. hlist_del(&f->hlist);
  2132. kfree(f);
  2133. }
  2134. if (num_del) {
  2135. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  2136. num_del, &retval);
  2137. }
  2138. kfree(del_list);
  2139. del_list = NULL;
  2140. }
  2141. if (!hlist_empty(&tmp_add_list)) {
  2142. /* Do all the adds now. */
  2143. filter_list_len = hw->aq.asq_buf_size /
  2144. sizeof(struct i40e_aqc_add_macvlan_element_data);
  2145. list_size = filter_list_len *
  2146. sizeof(struct i40e_aqc_add_macvlan_element_data);
  2147. add_list = kzalloc(list_size, GFP_ATOMIC);
  2148. if (!add_list)
  2149. goto err_no_memory;
  2150. num_add = 0;
  2151. hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
  2152. /* handle broadcast filters by updating the broadcast
  2153. * promiscuous flag instead of adding a MAC filter.
  2154. */
  2155. if (is_broadcast_ether_addr(new->f->macaddr)) {
  2156. if (i40e_aqc_broadcast_filter(vsi, vsi_name,
  2157. new->f))
  2158. new->state = I40E_FILTER_FAILED;
  2159. else
  2160. new->state = I40E_FILTER_ACTIVE;
  2161. continue;
  2162. }
  2163. /* add to add array */
  2164. if (num_add == 0)
  2165. add_head = new;
  2166. cmd_flags = 0;
  2167. ether_addr_copy(add_list[num_add].mac_addr,
  2168. new->f->macaddr);
  2169. if (new->f->vlan == I40E_VLAN_ANY) {
  2170. add_list[num_add].vlan_tag = 0;
  2171. cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
  2172. } else {
  2173. add_list[num_add].vlan_tag =
  2174. cpu_to_le16((u16)(new->f->vlan));
  2175. }
  2176. add_list[num_add].queue_number = 0;
  2177. /* set invalid match method for later detection */
  2178. add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES;
  2179. cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
  2180. add_list[num_add].flags = cpu_to_le16(cmd_flags);
  2181. num_add++;
  2182. /* flush a full buffer */
  2183. if (num_add == filter_list_len) {
  2184. i40e_aqc_add_filters(vsi, vsi_name, add_list,
  2185. add_head, num_add);
  2186. memset(add_list, 0, list_size);
  2187. num_add = 0;
  2188. }
  2189. }
  2190. if (num_add) {
  2191. i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head,
  2192. num_add);
  2193. }
  2194. /* Now move all of the filters from the temp add list back to
  2195. * the VSI's list.
  2196. */
  2197. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2198. hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
  2199. /* Only update the state if we're still NEW */
  2200. if (new->f->state == I40E_FILTER_NEW)
  2201. new->f->state = new->state;
  2202. hlist_del(&new->hlist);
  2203. kfree(new);
  2204. }
  2205. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2206. kfree(add_list);
  2207. add_list = NULL;
  2208. }
  2209. /* Determine the number of active and failed filters. */
  2210. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2211. vsi->active_filters = 0;
  2212. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
  2213. if (f->state == I40E_FILTER_ACTIVE)
  2214. vsi->active_filters++;
  2215. else if (f->state == I40E_FILTER_FAILED)
  2216. failed_filters++;
  2217. }
  2218. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2219. /* Check if we are able to exit overflow promiscuous mode. We can
  2220. * safely exit if we didn't just enter, we no longer have any failed
  2221. * filters, and we have reduced filters below the threshold value.
  2222. */
  2223. if (old_overflow && !failed_filters &&
  2224. vsi->active_filters < vsi->promisc_threshold) {
  2225. dev_info(&pf->pdev->dev,
  2226. "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
  2227. vsi_name);
  2228. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  2229. vsi->promisc_threshold = 0;
  2230. }
  2231. /* if the VF is not trusted do not do promisc */
  2232. if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) {
  2233. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  2234. goto out;
  2235. }
  2236. new_overflow = test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  2237. /* If we are entering overflow promiscuous, we need to calculate a new
  2238. * threshold for when we are safe to exit
  2239. */
  2240. if (!old_overflow && new_overflow)
  2241. vsi->promisc_threshold = (vsi->active_filters * 3) / 4;
  2242. /* check for changes in promiscuous modes */
  2243. if (changed_flags & IFF_ALLMULTI) {
  2244. bool cur_multipromisc;
  2245. cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
  2246. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
  2247. vsi->seid,
  2248. cur_multipromisc,
  2249. NULL);
  2250. if (aq_ret) {
  2251. retval = i40e_aq_rc_to_posix(aq_ret,
  2252. hw->aq.asq_last_status);
  2253. dev_info(&pf->pdev->dev,
  2254. "set multi promisc failed on %s, err %s aq_err %s\n",
  2255. vsi_name,
  2256. i40e_stat_str(hw, aq_ret),
  2257. i40e_aq_str(hw, hw->aq.asq_last_status));
  2258. }
  2259. }
  2260. if ((changed_flags & IFF_PROMISC) || old_overflow != new_overflow) {
  2261. bool cur_promisc;
  2262. cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
  2263. new_overflow);
  2264. aq_ret = i40e_set_promiscuous(pf, cur_promisc);
  2265. if (aq_ret) {
  2266. retval = i40e_aq_rc_to_posix(aq_ret,
  2267. hw->aq.asq_last_status);
  2268. dev_info(&pf->pdev->dev,
  2269. "Setting promiscuous %s failed on %s, err %s aq_err %s\n",
  2270. cur_promisc ? "on" : "off",
  2271. vsi_name,
  2272. i40e_stat_str(hw, aq_ret),
  2273. i40e_aq_str(hw, hw->aq.asq_last_status));
  2274. }
  2275. }
  2276. out:
  2277. /* if something went wrong then set the changed flag so we try again */
  2278. if (retval)
  2279. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2280. clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
  2281. return retval;
  2282. err_no_memory:
  2283. /* Restore elements on the temporary add and delete lists */
  2284. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2285. err_no_memory_locked:
  2286. i40e_undo_del_filter_entries(vsi, &tmp_del_list);
  2287. i40e_undo_add_filter_entries(vsi, &tmp_add_list);
  2288. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2289. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2290. clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
  2291. return -ENOMEM;
  2292. }
  2293. /**
  2294. * i40e_sync_filters_subtask - Sync the VSI filter list with HW
  2295. * @pf: board private structure
  2296. **/
  2297. static void i40e_sync_filters_subtask(struct i40e_pf *pf)
  2298. {
  2299. int v;
  2300. if (!pf)
  2301. return;
  2302. if (!test_and_clear_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state))
  2303. return;
  2304. if (test_bit(__I40E_VF_DISABLE, pf->state)) {
  2305. set_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state);
  2306. return;
  2307. }
  2308. for (v = 0; v < pf->num_alloc_vsi; v++) {
  2309. if (pf->vsi[v] &&
  2310. (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
  2311. int ret = i40e_sync_vsi_filters(pf->vsi[v]);
  2312. if (ret) {
  2313. /* come back and try again later */
  2314. set_bit(__I40E_MACVLAN_SYNC_PENDING,
  2315. pf->state);
  2316. break;
  2317. }
  2318. }
  2319. }
  2320. }
  2321. /**
  2322. * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP
  2323. * @vsi: the vsi
  2324. **/
  2325. static int i40e_max_xdp_frame_size(struct i40e_vsi *vsi)
  2326. {
  2327. if (PAGE_SIZE >= 8192 || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
  2328. return I40E_RXBUFFER_2048;
  2329. else
  2330. return I40E_RXBUFFER_3072;
  2331. }
  2332. /**
  2333. * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  2334. * @netdev: network interface device structure
  2335. * @new_mtu: new value for maximum frame size
  2336. *
  2337. * Returns 0 on success, negative on failure
  2338. **/
  2339. static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
  2340. {
  2341. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2342. struct i40e_vsi *vsi = np->vsi;
  2343. struct i40e_pf *pf = vsi->back;
  2344. if (i40e_enabled_xdp_vsi(vsi)) {
  2345. int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  2346. if (frame_size > i40e_max_xdp_frame_size(vsi))
  2347. return -EINVAL;
  2348. }
  2349. netdev_info(netdev, "changing MTU from %d to %d\n",
  2350. netdev->mtu, new_mtu);
  2351. netdev->mtu = new_mtu;
  2352. if (netif_running(netdev))
  2353. i40e_vsi_reinit_locked(vsi);
  2354. set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
  2355. set_bit(__I40E_CLIENT_L2_CHANGE, pf->state);
  2356. return 0;
  2357. }
  2358. /**
  2359. * i40e_ioctl - Access the hwtstamp interface
  2360. * @netdev: network interface device structure
  2361. * @ifr: interface request data
  2362. * @cmd: ioctl command
  2363. **/
  2364. int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  2365. {
  2366. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2367. struct i40e_pf *pf = np->vsi->back;
  2368. switch (cmd) {
  2369. case SIOCGHWTSTAMP:
  2370. return i40e_ptp_get_ts_config(pf, ifr);
  2371. case SIOCSHWTSTAMP:
  2372. return i40e_ptp_set_ts_config(pf, ifr);
  2373. default:
  2374. return -EOPNOTSUPP;
  2375. }
  2376. }
  2377. /**
  2378. * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
  2379. * @vsi: the vsi being adjusted
  2380. **/
  2381. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
  2382. {
  2383. struct i40e_vsi_context ctxt;
  2384. i40e_status ret;
  2385. /* Don't modify stripping options if a port VLAN is active */
  2386. if (vsi->info.pvid)
  2387. return;
  2388. if ((vsi->info.valid_sections &
  2389. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2390. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
  2391. return; /* already enabled */
  2392. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2393. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2394. I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
  2395. ctxt.seid = vsi->seid;
  2396. ctxt.info = vsi->info;
  2397. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2398. if (ret) {
  2399. dev_info(&vsi->back->pdev->dev,
  2400. "update vlan stripping failed, err %s aq_err %s\n",
  2401. i40e_stat_str(&vsi->back->hw, ret),
  2402. i40e_aq_str(&vsi->back->hw,
  2403. vsi->back->hw.aq.asq_last_status));
  2404. }
  2405. }
  2406. /**
  2407. * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
  2408. * @vsi: the vsi being adjusted
  2409. **/
  2410. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
  2411. {
  2412. struct i40e_vsi_context ctxt;
  2413. i40e_status ret;
  2414. /* Don't modify stripping options if a port VLAN is active */
  2415. if (vsi->info.pvid)
  2416. return;
  2417. if ((vsi->info.valid_sections &
  2418. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2419. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
  2420. I40E_AQ_VSI_PVLAN_EMOD_MASK))
  2421. return; /* already disabled */
  2422. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2423. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2424. I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
  2425. ctxt.seid = vsi->seid;
  2426. ctxt.info = vsi->info;
  2427. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2428. if (ret) {
  2429. dev_info(&vsi->back->pdev->dev,
  2430. "update vlan stripping failed, err %s aq_err %s\n",
  2431. i40e_stat_str(&vsi->back->hw, ret),
  2432. i40e_aq_str(&vsi->back->hw,
  2433. vsi->back->hw.aq.asq_last_status));
  2434. }
  2435. }
  2436. /**
  2437. * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address
  2438. * @vsi: the vsi being configured
  2439. * @vid: vlan id to be added (0 = untagged only , -1 = any)
  2440. *
  2441. * This is a helper function for adding a new MAC/VLAN filter with the
  2442. * specified VLAN for each existing MAC address already in the hash table.
  2443. * This function does *not* perform any accounting to update filters based on
  2444. * VLAN mode.
  2445. *
  2446. * NOTE: this function expects to be called while under the
  2447. * mac_filter_hash_lock
  2448. **/
  2449. int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2450. {
  2451. struct i40e_mac_filter *f, *add_f;
  2452. struct hlist_node *h;
  2453. int bkt;
  2454. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2455. if (f->state == I40E_FILTER_REMOVE)
  2456. continue;
  2457. add_f = i40e_add_filter(vsi, f->macaddr, vid);
  2458. if (!add_f) {
  2459. dev_info(&vsi->back->pdev->dev,
  2460. "Could not add vlan filter %d for %pM\n",
  2461. vid, f->macaddr);
  2462. return -ENOMEM;
  2463. }
  2464. }
  2465. return 0;
  2466. }
  2467. /**
  2468. * i40e_vsi_add_vlan - Add VSI membership for given VLAN
  2469. * @vsi: the VSI being configured
  2470. * @vid: VLAN id to be added
  2471. **/
  2472. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid)
  2473. {
  2474. int err;
  2475. if (vsi->info.pvid)
  2476. return -EINVAL;
  2477. /* The network stack will attempt to add VID=0, with the intention to
  2478. * receive priority tagged packets with a VLAN of 0. Our HW receives
  2479. * these packets by default when configured to receive untagged
  2480. * packets, so we don't need to add a filter for this case.
  2481. * Additionally, HW interprets adding a VID=0 filter as meaning to
  2482. * receive *only* tagged traffic and stops receiving untagged traffic.
  2483. * Thus, we do not want to actually add a filter for VID=0
  2484. */
  2485. if (!vid)
  2486. return 0;
  2487. /* Locked once because all functions invoked below iterates list*/
  2488. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2489. err = i40e_add_vlan_all_mac(vsi, vid);
  2490. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2491. if (err)
  2492. return err;
  2493. /* schedule our worker thread which will take care of
  2494. * applying the new filter changes
  2495. */
  2496. i40e_service_event_schedule(vsi->back);
  2497. return 0;
  2498. }
  2499. /**
  2500. * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN
  2501. * @vsi: the vsi being configured
  2502. * @vid: vlan id to be removed (0 = untagged only , -1 = any)
  2503. *
  2504. * This function should be used to remove all VLAN filters which match the
  2505. * given VID. It does not schedule the service event and does not take the
  2506. * mac_filter_hash_lock so it may be combined with other operations under
  2507. * a single invocation of the mac_filter_hash_lock.
  2508. *
  2509. * NOTE: this function expects to be called while under the
  2510. * mac_filter_hash_lock
  2511. */
  2512. void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2513. {
  2514. struct i40e_mac_filter *f;
  2515. struct hlist_node *h;
  2516. int bkt;
  2517. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2518. if (f->vlan == vid)
  2519. __i40e_del_filter(vsi, f);
  2520. }
  2521. }
  2522. /**
  2523. * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN
  2524. * @vsi: the VSI being configured
  2525. * @vid: VLAN id to be removed
  2526. **/
  2527. void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid)
  2528. {
  2529. if (!vid || vsi->info.pvid)
  2530. return;
  2531. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2532. i40e_rm_vlan_all_mac(vsi, vid);
  2533. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2534. /* schedule our worker thread which will take care of
  2535. * applying the new filter changes
  2536. */
  2537. i40e_service_event_schedule(vsi->back);
  2538. }
  2539. /**
  2540. * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
  2541. * @netdev: network interface to be adjusted
  2542. * @proto: unused protocol value
  2543. * @vid: vlan id to be added
  2544. *
  2545. * net_device_ops implementation for adding vlan ids
  2546. **/
  2547. static int i40e_vlan_rx_add_vid(struct net_device *netdev,
  2548. __always_unused __be16 proto, u16 vid)
  2549. {
  2550. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2551. struct i40e_vsi *vsi = np->vsi;
  2552. int ret = 0;
  2553. if (vid >= VLAN_N_VID)
  2554. return -EINVAL;
  2555. ret = i40e_vsi_add_vlan(vsi, vid);
  2556. if (!ret)
  2557. set_bit(vid, vsi->active_vlans);
  2558. return ret;
  2559. }
  2560. /**
  2561. * i40e_vlan_rx_add_vid_up - Add a vlan id filter to HW offload in UP path
  2562. * @netdev: network interface to be adjusted
  2563. * @proto: unused protocol value
  2564. * @vid: vlan id to be added
  2565. **/
  2566. static void i40e_vlan_rx_add_vid_up(struct net_device *netdev,
  2567. __always_unused __be16 proto, u16 vid)
  2568. {
  2569. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2570. struct i40e_vsi *vsi = np->vsi;
  2571. if (vid >= VLAN_N_VID)
  2572. return;
  2573. set_bit(vid, vsi->active_vlans);
  2574. }
  2575. /**
  2576. * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
  2577. * @netdev: network interface to be adjusted
  2578. * @proto: unused protocol value
  2579. * @vid: vlan id to be removed
  2580. *
  2581. * net_device_ops implementation for removing vlan ids
  2582. **/
  2583. static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  2584. __always_unused __be16 proto, u16 vid)
  2585. {
  2586. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2587. struct i40e_vsi *vsi = np->vsi;
  2588. /* return code is ignored as there is nothing a user
  2589. * can do about failure to remove and a log message was
  2590. * already printed from the other function
  2591. */
  2592. i40e_vsi_kill_vlan(vsi, vid);
  2593. clear_bit(vid, vsi->active_vlans);
  2594. return 0;
  2595. }
  2596. /**
  2597. * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
  2598. * @vsi: the vsi being brought back up
  2599. **/
  2600. static void i40e_restore_vlan(struct i40e_vsi *vsi)
  2601. {
  2602. u16 vid;
  2603. if (!vsi->netdev)
  2604. return;
  2605. if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
  2606. i40e_vlan_stripping_enable(vsi);
  2607. else
  2608. i40e_vlan_stripping_disable(vsi);
  2609. for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
  2610. i40e_vlan_rx_add_vid_up(vsi->netdev, htons(ETH_P_8021Q),
  2611. vid);
  2612. }
  2613. /**
  2614. * i40e_vsi_add_pvid - Add pvid for the VSI
  2615. * @vsi: the vsi being adjusted
  2616. * @vid: the vlan id to set as a PVID
  2617. **/
  2618. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
  2619. {
  2620. struct i40e_vsi_context ctxt;
  2621. i40e_status ret;
  2622. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2623. vsi->info.pvid = cpu_to_le16(vid);
  2624. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
  2625. I40E_AQ_VSI_PVLAN_INSERT_PVID |
  2626. I40E_AQ_VSI_PVLAN_EMOD_STR;
  2627. ctxt.seid = vsi->seid;
  2628. ctxt.info = vsi->info;
  2629. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2630. if (ret) {
  2631. dev_info(&vsi->back->pdev->dev,
  2632. "add pvid failed, err %s aq_err %s\n",
  2633. i40e_stat_str(&vsi->back->hw, ret),
  2634. i40e_aq_str(&vsi->back->hw,
  2635. vsi->back->hw.aq.asq_last_status));
  2636. return -ENOENT;
  2637. }
  2638. return 0;
  2639. }
  2640. /**
  2641. * i40e_vsi_remove_pvid - Remove the pvid from the VSI
  2642. * @vsi: the vsi being adjusted
  2643. *
  2644. * Just use the vlan_rx_register() service to put it back to normal
  2645. **/
  2646. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
  2647. {
  2648. i40e_vlan_stripping_disable(vsi);
  2649. vsi->info.pvid = 0;
  2650. }
  2651. /**
  2652. * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
  2653. * @vsi: ptr to the VSI
  2654. *
  2655. * If this function returns with an error, then it's possible one or
  2656. * more of the rings is populated (while the rest are not). It is the
  2657. * callers duty to clean those orphaned rings.
  2658. *
  2659. * Return 0 on success, negative on failure
  2660. **/
  2661. static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
  2662. {
  2663. int i, err = 0;
  2664. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2665. err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
  2666. if (!i40e_enabled_xdp_vsi(vsi))
  2667. return err;
  2668. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2669. err = i40e_setup_tx_descriptors(vsi->xdp_rings[i]);
  2670. return err;
  2671. }
  2672. /**
  2673. * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
  2674. * @vsi: ptr to the VSI
  2675. *
  2676. * Free VSI's transmit software resources
  2677. **/
  2678. static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
  2679. {
  2680. int i;
  2681. if (vsi->tx_rings) {
  2682. for (i = 0; i < vsi->num_queue_pairs; i++)
  2683. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
  2684. i40e_free_tx_resources(vsi->tx_rings[i]);
  2685. }
  2686. if (vsi->xdp_rings) {
  2687. for (i = 0; i < vsi->num_queue_pairs; i++)
  2688. if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
  2689. i40e_free_tx_resources(vsi->xdp_rings[i]);
  2690. }
  2691. }
  2692. /**
  2693. * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
  2694. * @vsi: ptr to the VSI
  2695. *
  2696. * If this function returns with an error, then it's possible one or
  2697. * more of the rings is populated (while the rest are not). It is the
  2698. * callers duty to clean those orphaned rings.
  2699. *
  2700. * Return 0 on success, negative on failure
  2701. **/
  2702. static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
  2703. {
  2704. int i, err = 0;
  2705. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2706. err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
  2707. return err;
  2708. }
  2709. /**
  2710. * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
  2711. * @vsi: ptr to the VSI
  2712. *
  2713. * Free all receive software resources
  2714. **/
  2715. static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
  2716. {
  2717. int i;
  2718. if (!vsi->rx_rings)
  2719. return;
  2720. for (i = 0; i < vsi->num_queue_pairs; i++)
  2721. if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
  2722. i40e_free_rx_resources(vsi->rx_rings[i]);
  2723. }
  2724. /**
  2725. * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
  2726. * @ring: The Tx ring to configure
  2727. *
  2728. * This enables/disables XPS for a given Tx descriptor ring
  2729. * based on the TCs enabled for the VSI that ring belongs to.
  2730. **/
  2731. static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
  2732. {
  2733. int cpu;
  2734. if (!ring->q_vector || !ring->netdev || ring->ch)
  2735. return;
  2736. /* We only initialize XPS once, so as not to overwrite user settings */
  2737. if (test_and_set_bit(__I40E_TX_XPS_INIT_DONE, ring->state))
  2738. return;
  2739. cpu = cpumask_local_spread(ring->q_vector->v_idx, -1);
  2740. netif_set_xps_queue(ring->netdev, get_cpu_mask(cpu),
  2741. ring->queue_index);
  2742. }
  2743. /**
  2744. * i40e_configure_tx_ring - Configure a transmit ring context and rest
  2745. * @ring: The Tx ring to configure
  2746. *
  2747. * Configure the Tx descriptor ring in the HMC context.
  2748. **/
  2749. static int i40e_configure_tx_ring(struct i40e_ring *ring)
  2750. {
  2751. struct i40e_vsi *vsi = ring->vsi;
  2752. u16 pf_q = vsi->base_queue + ring->queue_index;
  2753. struct i40e_hw *hw = &vsi->back->hw;
  2754. struct i40e_hmc_obj_txq tx_ctx;
  2755. i40e_status err = 0;
  2756. u32 qtx_ctl = 0;
  2757. /* some ATR related tx ring init */
  2758. if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
  2759. ring->atr_sample_rate = vsi->back->atr_sample_rate;
  2760. ring->atr_count = 0;
  2761. } else {
  2762. ring->atr_sample_rate = 0;
  2763. }
  2764. /* configure XPS */
  2765. i40e_config_xps_tx_ring(ring);
  2766. /* clear the context structure first */
  2767. memset(&tx_ctx, 0, sizeof(tx_ctx));
  2768. tx_ctx.new_context = 1;
  2769. tx_ctx.base = (ring->dma / 128);
  2770. tx_ctx.qlen = ring->count;
  2771. tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
  2772. I40E_FLAG_FD_ATR_ENABLED));
  2773. tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
  2774. /* FDIR VSI tx ring can still use RS bit and writebacks */
  2775. if (vsi->type != I40E_VSI_FDIR)
  2776. tx_ctx.head_wb_ena = 1;
  2777. tx_ctx.head_wb_addr = ring->dma +
  2778. (ring->count * sizeof(struct i40e_tx_desc));
  2779. /* As part of VSI creation/update, FW allocates certain
  2780. * Tx arbitration queue sets for each TC enabled for
  2781. * the VSI. The FW returns the handles to these queue
  2782. * sets as part of the response buffer to Add VSI,
  2783. * Update VSI, etc. AQ commands. It is expected that
  2784. * these queue set handles be associated with the Tx
  2785. * queues by the driver as part of the TX queue context
  2786. * initialization. This has to be done regardless of
  2787. * DCB as by default everything is mapped to TC0.
  2788. */
  2789. if (ring->ch)
  2790. tx_ctx.rdylist =
  2791. le16_to_cpu(ring->ch->info.qs_handle[ring->dcb_tc]);
  2792. else
  2793. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
  2794. tx_ctx.rdylist_act = 0;
  2795. /* clear the context in the HMC */
  2796. err = i40e_clear_lan_tx_queue_context(hw, pf_q);
  2797. if (err) {
  2798. dev_info(&vsi->back->pdev->dev,
  2799. "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
  2800. ring->queue_index, pf_q, err);
  2801. return -ENOMEM;
  2802. }
  2803. /* set the context in the HMC */
  2804. err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
  2805. if (err) {
  2806. dev_info(&vsi->back->pdev->dev,
  2807. "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
  2808. ring->queue_index, pf_q, err);
  2809. return -ENOMEM;
  2810. }
  2811. /* Now associate this queue with this PCI function */
  2812. if (ring->ch) {
  2813. if (ring->ch->type == I40E_VSI_VMDQ2)
  2814. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2815. else
  2816. return -EINVAL;
  2817. qtx_ctl |= (ring->ch->vsi_number <<
  2818. I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2819. I40E_QTX_CTL_VFVM_INDX_MASK;
  2820. } else {
  2821. if (vsi->type == I40E_VSI_VMDQ2) {
  2822. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2823. qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2824. I40E_QTX_CTL_VFVM_INDX_MASK;
  2825. } else {
  2826. qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
  2827. }
  2828. }
  2829. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
  2830. I40E_QTX_CTL_PF_INDX_MASK);
  2831. wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
  2832. i40e_flush(hw);
  2833. /* cache tail off for easier writes later */
  2834. ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
  2835. return 0;
  2836. }
  2837. /**
  2838. * i40e_configure_rx_ring - Configure a receive ring context
  2839. * @ring: The Rx ring to configure
  2840. *
  2841. * Configure the Rx descriptor ring in the HMC context.
  2842. **/
  2843. static int i40e_configure_rx_ring(struct i40e_ring *ring)
  2844. {
  2845. struct i40e_vsi *vsi = ring->vsi;
  2846. u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
  2847. u16 pf_q = vsi->base_queue + ring->queue_index;
  2848. struct i40e_hw *hw = &vsi->back->hw;
  2849. struct i40e_hmc_obj_rxq rx_ctx;
  2850. i40e_status err = 0;
  2851. bitmap_zero(ring->state, __I40E_RING_STATE_NBITS);
  2852. /* clear the context structure first */
  2853. memset(&rx_ctx, 0, sizeof(rx_ctx));
  2854. ring->rx_buf_len = vsi->rx_buf_len;
  2855. rx_ctx.dbuff = DIV_ROUND_UP(ring->rx_buf_len,
  2856. BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
  2857. rx_ctx.base = (ring->dma / 128);
  2858. rx_ctx.qlen = ring->count;
  2859. /* use 32 byte descriptors */
  2860. rx_ctx.dsize = 1;
  2861. /* descriptor type is always zero
  2862. * rx_ctx.dtype = 0;
  2863. */
  2864. rx_ctx.hsplit_0 = 0;
  2865. rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
  2866. if (hw->revision_id == 0)
  2867. rx_ctx.lrxqthresh = 0;
  2868. else
  2869. rx_ctx.lrxqthresh = 1;
  2870. rx_ctx.crcstrip = 1;
  2871. rx_ctx.l2tsel = 1;
  2872. /* this controls whether VLAN is stripped from inner headers */
  2873. rx_ctx.showiv = 0;
  2874. /* set the prefena field to 1 because the manual says to */
  2875. rx_ctx.prefena = 1;
  2876. /* clear the context in the HMC */
  2877. err = i40e_clear_lan_rx_queue_context(hw, pf_q);
  2878. if (err) {
  2879. dev_info(&vsi->back->pdev->dev,
  2880. "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2881. ring->queue_index, pf_q, err);
  2882. return -ENOMEM;
  2883. }
  2884. /* set the context in the HMC */
  2885. err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
  2886. if (err) {
  2887. dev_info(&vsi->back->pdev->dev,
  2888. "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2889. ring->queue_index, pf_q, err);
  2890. return -ENOMEM;
  2891. }
  2892. /* configure Rx buffer alignment */
  2893. if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
  2894. clear_ring_build_skb_enabled(ring);
  2895. else
  2896. set_ring_build_skb_enabled(ring);
  2897. /* cache tail for quicker writes, and clear the reg before use */
  2898. ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
  2899. writel(0, ring->tail);
  2900. i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
  2901. return 0;
  2902. }
  2903. /**
  2904. * i40e_vsi_configure_tx - Configure the VSI for Tx
  2905. * @vsi: VSI structure describing this set of rings and resources
  2906. *
  2907. * Configure the Tx VSI for operation.
  2908. **/
  2909. static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
  2910. {
  2911. int err = 0;
  2912. u16 i;
  2913. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2914. err = i40e_configure_tx_ring(vsi->tx_rings[i]);
  2915. if (!i40e_enabled_xdp_vsi(vsi))
  2916. return err;
  2917. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2918. err = i40e_configure_tx_ring(vsi->xdp_rings[i]);
  2919. return err;
  2920. }
  2921. /**
  2922. * i40e_vsi_configure_rx - Configure the VSI for Rx
  2923. * @vsi: the VSI being configured
  2924. *
  2925. * Configure the Rx VSI for operation.
  2926. **/
  2927. static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
  2928. {
  2929. int err = 0;
  2930. u16 i;
  2931. if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) {
  2932. vsi->max_frame = I40E_MAX_RXBUFFER;
  2933. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2934. #if (PAGE_SIZE < 8192)
  2935. } else if (!I40E_2K_TOO_SMALL_WITH_PADDING &&
  2936. (vsi->netdev->mtu <= ETH_DATA_LEN)) {
  2937. vsi->max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
  2938. vsi->rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
  2939. #endif
  2940. } else {
  2941. vsi->max_frame = I40E_MAX_RXBUFFER;
  2942. vsi->rx_buf_len = (PAGE_SIZE < 8192) ? I40E_RXBUFFER_3072 :
  2943. I40E_RXBUFFER_2048;
  2944. }
  2945. /* set up individual rings */
  2946. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2947. err = i40e_configure_rx_ring(vsi->rx_rings[i]);
  2948. return err;
  2949. }
  2950. /**
  2951. * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
  2952. * @vsi: ptr to the VSI
  2953. **/
  2954. static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
  2955. {
  2956. struct i40e_ring *tx_ring, *rx_ring;
  2957. u16 qoffset, qcount;
  2958. int i, n;
  2959. if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  2960. /* Reset the TC information */
  2961. for (i = 0; i < vsi->num_queue_pairs; i++) {
  2962. rx_ring = vsi->rx_rings[i];
  2963. tx_ring = vsi->tx_rings[i];
  2964. rx_ring->dcb_tc = 0;
  2965. tx_ring->dcb_tc = 0;
  2966. }
  2967. return;
  2968. }
  2969. for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
  2970. if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
  2971. continue;
  2972. qoffset = vsi->tc_config.tc_info[n].qoffset;
  2973. qcount = vsi->tc_config.tc_info[n].qcount;
  2974. for (i = qoffset; i < (qoffset + qcount); i++) {
  2975. rx_ring = vsi->rx_rings[i];
  2976. tx_ring = vsi->tx_rings[i];
  2977. rx_ring->dcb_tc = n;
  2978. tx_ring->dcb_tc = n;
  2979. }
  2980. }
  2981. }
  2982. /**
  2983. * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
  2984. * @vsi: ptr to the VSI
  2985. **/
  2986. static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
  2987. {
  2988. if (vsi->netdev)
  2989. i40e_set_rx_mode(vsi->netdev);
  2990. }
  2991. /**
  2992. * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
  2993. * @vsi: Pointer to the targeted VSI
  2994. *
  2995. * This function replays the hlist on the hw where all the SB Flow Director
  2996. * filters were saved.
  2997. **/
  2998. static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
  2999. {
  3000. struct i40e_fdir_filter *filter;
  3001. struct i40e_pf *pf = vsi->back;
  3002. struct hlist_node *node;
  3003. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  3004. return;
  3005. /* Reset FDir counters as we're replaying all existing filters */
  3006. pf->fd_tcp4_filter_cnt = 0;
  3007. pf->fd_udp4_filter_cnt = 0;
  3008. pf->fd_sctp4_filter_cnt = 0;
  3009. pf->fd_ip4_filter_cnt = 0;
  3010. hlist_for_each_entry_safe(filter, node,
  3011. &pf->fdir_filter_list, fdir_node) {
  3012. i40e_add_del_fdir(vsi, filter, true);
  3013. }
  3014. }
  3015. /**
  3016. * i40e_vsi_configure - Set up the VSI for action
  3017. * @vsi: the VSI being configured
  3018. **/
  3019. static int i40e_vsi_configure(struct i40e_vsi *vsi)
  3020. {
  3021. int err;
  3022. i40e_set_vsi_rx_mode(vsi);
  3023. i40e_restore_vlan(vsi);
  3024. i40e_vsi_config_dcb_rings(vsi);
  3025. err = i40e_vsi_configure_tx(vsi);
  3026. if (!err)
  3027. err = i40e_vsi_configure_rx(vsi);
  3028. return err;
  3029. }
  3030. /**
  3031. * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
  3032. * @vsi: the VSI being configured
  3033. **/
  3034. static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
  3035. {
  3036. bool has_xdp = i40e_enabled_xdp_vsi(vsi);
  3037. struct i40e_pf *pf = vsi->back;
  3038. struct i40e_hw *hw = &pf->hw;
  3039. u16 vector;
  3040. int i, q;
  3041. u32 qp;
  3042. /* The interrupt indexing is offset by 1 in the PFINT_ITRn
  3043. * and PFINT_LNKLSTn registers, e.g.:
  3044. * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
  3045. */
  3046. qp = vsi->base_queue;
  3047. vector = vsi->base_vector;
  3048. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  3049. struct i40e_q_vector *q_vector = vsi->q_vectors[i];
  3050. q_vector->rx.next_update = jiffies + 1;
  3051. q_vector->rx.target_itr =
  3052. ITR_TO_REG(vsi->rx_rings[i]->itr_setting);
  3053. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
  3054. q_vector->rx.target_itr >> 1);
  3055. q_vector->rx.current_itr = q_vector->rx.target_itr;
  3056. q_vector->tx.next_update = jiffies + 1;
  3057. q_vector->tx.target_itr =
  3058. ITR_TO_REG(vsi->tx_rings[i]->itr_setting);
  3059. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
  3060. q_vector->tx.target_itr >> 1);
  3061. q_vector->tx.current_itr = q_vector->tx.target_itr;
  3062. wr32(hw, I40E_PFINT_RATEN(vector - 1),
  3063. i40e_intrl_usec_to_reg(vsi->int_rate_limit));
  3064. /* Linked list for the queuepairs assigned to this vector */
  3065. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
  3066. for (q = 0; q < q_vector->num_ringpairs; q++) {
  3067. u32 nextqp = has_xdp ? qp + vsi->alloc_queue_pairs : qp;
  3068. u32 val;
  3069. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3070. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  3071. (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
  3072. (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
  3073. (I40E_QUEUE_TYPE_TX <<
  3074. I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
  3075. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3076. if (has_xdp) {
  3077. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3078. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3079. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  3080. (qp << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
  3081. (I40E_QUEUE_TYPE_TX <<
  3082. I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3083. wr32(hw, I40E_QINT_TQCTL(nextqp), val);
  3084. }
  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 + 1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
  3089. (I40E_QUEUE_TYPE_RX <<
  3090. I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3091. /* Terminate the linked list */
  3092. if (q == (q_vector->num_ringpairs - 1))
  3093. val |= (I40E_QUEUE_END_OF_LIST <<
  3094. I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  3095. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3096. qp++;
  3097. }
  3098. }
  3099. i40e_flush(hw);
  3100. }
  3101. /**
  3102. * i40e_enable_misc_int_causes - enable the non-queue interrupts
  3103. * @pf: pointer to private device data structure
  3104. **/
  3105. static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
  3106. {
  3107. struct i40e_hw *hw = &pf->hw;
  3108. u32 val;
  3109. /* clear things first */
  3110. wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
  3111. rd32(hw, I40E_PFINT_ICR0); /* read to clear */
  3112. val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
  3113. I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
  3114. I40E_PFINT_ICR0_ENA_GRST_MASK |
  3115. I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
  3116. I40E_PFINT_ICR0_ENA_GPIO_MASK |
  3117. I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
  3118. I40E_PFINT_ICR0_ENA_VFLR_MASK |
  3119. I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3120. if (pf->flags & I40E_FLAG_IWARP_ENABLED)
  3121. val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3122. if (pf->flags & I40E_FLAG_PTP)
  3123. val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3124. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  3125. /* SW_ITR_IDX = 0, but don't change INTENA */
  3126. wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
  3127. I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
  3128. /* OTHER_ITR_IDX = 0 */
  3129. wr32(hw, I40E_PFINT_STAT_CTL0, 0);
  3130. }
  3131. /**
  3132. * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
  3133. * @vsi: the VSI being configured
  3134. **/
  3135. static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
  3136. {
  3137. u32 nextqp = i40e_enabled_xdp_vsi(vsi) ? vsi->alloc_queue_pairs : 0;
  3138. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3139. struct i40e_pf *pf = vsi->back;
  3140. struct i40e_hw *hw = &pf->hw;
  3141. u32 val;
  3142. /* set the ITR configuration */
  3143. q_vector->rx.next_update = jiffies + 1;
  3144. q_vector->rx.target_itr = ITR_TO_REG(vsi->rx_rings[0]->itr_setting);
  3145. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.target_itr >> 1);
  3146. q_vector->rx.current_itr = q_vector->rx.target_itr;
  3147. q_vector->tx.next_update = jiffies + 1;
  3148. q_vector->tx.target_itr = ITR_TO_REG(vsi->tx_rings[0]->itr_setting);
  3149. wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.target_itr >> 1);
  3150. q_vector->tx.current_itr = q_vector->tx.target_itr;
  3151. i40e_enable_misc_int_causes(pf);
  3152. /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
  3153. wr32(hw, I40E_PFINT_LNKLST0, 0);
  3154. /* Associate the queue pair to the vector and enable the queue int */
  3155. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3156. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  3157. (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
  3158. (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3159. wr32(hw, I40E_QINT_RQCTL(0), val);
  3160. if (i40e_enabled_xdp_vsi(vsi)) {
  3161. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3162. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT)|
  3163. (I40E_QUEUE_TYPE_TX
  3164. << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3165. wr32(hw, I40E_QINT_TQCTL(nextqp), val);
  3166. }
  3167. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3168. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3169. (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  3170. wr32(hw, I40E_QINT_TQCTL(0), val);
  3171. i40e_flush(hw);
  3172. }
  3173. /**
  3174. * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
  3175. * @pf: board private structure
  3176. **/
  3177. void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
  3178. {
  3179. struct i40e_hw *hw = &pf->hw;
  3180. wr32(hw, I40E_PFINT_DYN_CTL0,
  3181. I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  3182. i40e_flush(hw);
  3183. }
  3184. /**
  3185. * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
  3186. * @pf: board private structure
  3187. **/
  3188. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
  3189. {
  3190. struct i40e_hw *hw = &pf->hw;
  3191. u32 val;
  3192. val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
  3193. I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
  3194. (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
  3195. wr32(hw, I40E_PFINT_DYN_CTL0, val);
  3196. i40e_flush(hw);
  3197. }
  3198. /**
  3199. * i40e_msix_clean_rings - MSIX mode Interrupt Handler
  3200. * @irq: interrupt number
  3201. * @data: pointer to a q_vector
  3202. **/
  3203. static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
  3204. {
  3205. struct i40e_q_vector *q_vector = data;
  3206. if (!q_vector->tx.ring && !q_vector->rx.ring)
  3207. return IRQ_HANDLED;
  3208. napi_schedule_irqoff(&q_vector->napi);
  3209. return IRQ_HANDLED;
  3210. }
  3211. /**
  3212. * i40e_irq_affinity_notify - Callback for affinity changes
  3213. * @notify: context as to what irq was changed
  3214. * @mask: the new affinity mask
  3215. *
  3216. * This is a callback function used by the irq_set_affinity_notifier function
  3217. * so that we may register to receive changes to the irq affinity masks.
  3218. **/
  3219. static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify,
  3220. const cpumask_t *mask)
  3221. {
  3222. struct i40e_q_vector *q_vector =
  3223. container_of(notify, struct i40e_q_vector, affinity_notify);
  3224. cpumask_copy(&q_vector->affinity_mask, mask);
  3225. }
  3226. /**
  3227. * i40e_irq_affinity_release - Callback for affinity notifier release
  3228. * @ref: internal core kernel usage
  3229. *
  3230. * This is a callback function used by the irq_set_affinity_notifier function
  3231. * to inform the current notification subscriber that they will no longer
  3232. * receive notifications.
  3233. **/
  3234. static void i40e_irq_affinity_release(struct kref *ref) {}
  3235. /**
  3236. * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
  3237. * @vsi: the VSI being configured
  3238. * @basename: name for the vector
  3239. *
  3240. * Allocates MSI-X vectors and requests interrupts from the kernel.
  3241. **/
  3242. static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
  3243. {
  3244. int q_vectors = vsi->num_q_vectors;
  3245. struct i40e_pf *pf = vsi->back;
  3246. int base = vsi->base_vector;
  3247. int rx_int_idx = 0;
  3248. int tx_int_idx = 0;
  3249. int vector, err;
  3250. int irq_num;
  3251. int cpu;
  3252. for (vector = 0; vector < q_vectors; vector++) {
  3253. struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
  3254. irq_num = pf->msix_entries[base + vector].vector;
  3255. if (q_vector->tx.ring && q_vector->rx.ring) {
  3256. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3257. "%s-%s-%d", basename, "TxRx", rx_int_idx++);
  3258. tx_int_idx++;
  3259. } else if (q_vector->rx.ring) {
  3260. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3261. "%s-%s-%d", basename, "rx", rx_int_idx++);
  3262. } else if (q_vector->tx.ring) {
  3263. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3264. "%s-%s-%d", basename, "tx", tx_int_idx++);
  3265. } else {
  3266. /* skip this unused q_vector */
  3267. continue;
  3268. }
  3269. err = request_irq(irq_num,
  3270. vsi->irq_handler,
  3271. 0,
  3272. q_vector->name,
  3273. q_vector);
  3274. if (err) {
  3275. dev_info(&pf->pdev->dev,
  3276. "MSIX request_irq failed, error: %d\n", err);
  3277. goto free_queue_irqs;
  3278. }
  3279. /* register for affinity change notifications */
  3280. q_vector->affinity_notify.notify = i40e_irq_affinity_notify;
  3281. q_vector->affinity_notify.release = i40e_irq_affinity_release;
  3282. irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
  3283. /* Spread affinity hints out across online CPUs.
  3284. *
  3285. * get_cpu_mask returns a static constant mask with
  3286. * a permanent lifetime so it's ok to pass to
  3287. * irq_set_affinity_hint without making a copy.
  3288. */
  3289. cpu = cpumask_local_spread(q_vector->v_idx, -1);
  3290. irq_set_affinity_hint(irq_num, get_cpu_mask(cpu));
  3291. }
  3292. vsi->irqs_ready = true;
  3293. return 0;
  3294. free_queue_irqs:
  3295. while (vector) {
  3296. vector--;
  3297. irq_num = pf->msix_entries[base + vector].vector;
  3298. irq_set_affinity_notifier(irq_num, NULL);
  3299. irq_set_affinity_hint(irq_num, NULL);
  3300. free_irq(irq_num, &vsi->q_vectors[vector]);
  3301. }
  3302. return err;
  3303. }
  3304. /**
  3305. * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
  3306. * @vsi: the VSI being un-configured
  3307. **/
  3308. static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
  3309. {
  3310. struct i40e_pf *pf = vsi->back;
  3311. struct i40e_hw *hw = &pf->hw;
  3312. int base = vsi->base_vector;
  3313. int i;
  3314. /* disable interrupt causation from each queue */
  3315. for (i = 0; i < vsi->num_queue_pairs; i++) {
  3316. u32 val;
  3317. val = rd32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx));
  3318. val &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
  3319. wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), val);
  3320. val = rd32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx));
  3321. val &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
  3322. wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), val);
  3323. if (!i40e_enabled_xdp_vsi(vsi))
  3324. continue;
  3325. wr32(hw, I40E_QINT_TQCTL(vsi->xdp_rings[i]->reg_idx), 0);
  3326. }
  3327. /* disable each interrupt */
  3328. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3329. for (i = vsi->base_vector;
  3330. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  3331. wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
  3332. i40e_flush(hw);
  3333. for (i = 0; i < vsi->num_q_vectors; i++)
  3334. synchronize_irq(pf->msix_entries[i + base].vector);
  3335. } else {
  3336. /* Legacy and MSI mode - this stops all interrupt handling */
  3337. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  3338. wr32(hw, I40E_PFINT_DYN_CTL0, 0);
  3339. i40e_flush(hw);
  3340. synchronize_irq(pf->pdev->irq);
  3341. }
  3342. }
  3343. /**
  3344. * i40e_vsi_enable_irq - Enable IRQ for the given VSI
  3345. * @vsi: the VSI being configured
  3346. **/
  3347. static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
  3348. {
  3349. struct i40e_pf *pf = vsi->back;
  3350. int i;
  3351. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3352. for (i = 0; i < vsi->num_q_vectors; i++)
  3353. i40e_irq_dynamic_enable(vsi, i);
  3354. } else {
  3355. i40e_irq_dynamic_enable_icr0(pf);
  3356. }
  3357. i40e_flush(&pf->hw);
  3358. return 0;
  3359. }
  3360. /**
  3361. * i40e_free_misc_vector - Free the vector that handles non-queue events
  3362. * @pf: board private structure
  3363. **/
  3364. static void i40e_free_misc_vector(struct i40e_pf *pf)
  3365. {
  3366. /* Disable ICR 0 */
  3367. wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
  3368. i40e_flush(&pf->hw);
  3369. if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
  3370. synchronize_irq(pf->msix_entries[0].vector);
  3371. free_irq(pf->msix_entries[0].vector, pf);
  3372. clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state);
  3373. }
  3374. }
  3375. /**
  3376. * i40e_intr - MSI/Legacy and non-queue interrupt handler
  3377. * @irq: interrupt number
  3378. * @data: pointer to a q_vector
  3379. *
  3380. * This is the handler used for all MSI/Legacy interrupts, and deals
  3381. * with both queue and non-queue interrupts. This is also used in
  3382. * MSIX mode to handle the non-queue interrupts.
  3383. **/
  3384. static irqreturn_t i40e_intr(int irq, void *data)
  3385. {
  3386. struct i40e_pf *pf = (struct i40e_pf *)data;
  3387. struct i40e_hw *hw = &pf->hw;
  3388. irqreturn_t ret = IRQ_NONE;
  3389. u32 icr0, icr0_remaining;
  3390. u32 val, ena_mask;
  3391. icr0 = rd32(hw, I40E_PFINT_ICR0);
  3392. ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
  3393. /* if sharing a legacy IRQ, we might get called w/o an intr pending */
  3394. if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
  3395. goto enable_intr;
  3396. /* if interrupt but no bits showing, must be SWINT */
  3397. if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
  3398. (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
  3399. pf->sw_int_count++;
  3400. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  3401. (icr0 & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
  3402. ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3403. dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n");
  3404. set_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
  3405. }
  3406. /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
  3407. if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
  3408. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  3409. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3410. /* We do not have a way to disarm Queue causes while leaving
  3411. * interrupt enabled for all other causes, ideally
  3412. * interrupt should be disabled while we are in NAPI but
  3413. * this is not a performance path and napi_schedule()
  3414. * can deal with rescheduling.
  3415. */
  3416. if (!test_bit(__I40E_DOWN, pf->state))
  3417. napi_schedule_irqoff(&q_vector->napi);
  3418. }
  3419. if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
  3420. ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3421. set_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
  3422. i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
  3423. }
  3424. if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
  3425. ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  3426. set_bit(__I40E_MDD_EVENT_PENDING, pf->state);
  3427. }
  3428. if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
  3429. /* disable any further VFLR event notifications */
  3430. if (test_bit(__I40E_VF_RESETS_DISABLED, pf->state)) {
  3431. u32 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  3432. reg &= ~I40E_PFINT_ICR0_VFLR_MASK;
  3433. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  3434. } else {
  3435. ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
  3436. set_bit(__I40E_VFLR_EVENT_PENDING, pf->state);
  3437. }
  3438. }
  3439. if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
  3440. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  3441. set_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
  3442. ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
  3443. val = rd32(hw, I40E_GLGEN_RSTAT);
  3444. val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
  3445. >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
  3446. if (val == I40E_RESET_CORER) {
  3447. pf->corer_count++;
  3448. } else if (val == I40E_RESET_GLOBR) {
  3449. pf->globr_count++;
  3450. } else if (val == I40E_RESET_EMPR) {
  3451. pf->empr_count++;
  3452. set_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state);
  3453. }
  3454. }
  3455. if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
  3456. icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
  3457. dev_info(&pf->pdev->dev, "HMC error interrupt\n");
  3458. dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
  3459. rd32(hw, I40E_PFHMC_ERRORINFO),
  3460. rd32(hw, I40E_PFHMC_ERRORDATA));
  3461. }
  3462. if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
  3463. u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
  3464. if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
  3465. icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3466. i40e_ptp_tx_hwtstamp(pf);
  3467. }
  3468. }
  3469. /* If a critical error is pending we have no choice but to reset the
  3470. * device.
  3471. * Report and mask out any remaining unexpected interrupts.
  3472. */
  3473. icr0_remaining = icr0 & ena_mask;
  3474. if (icr0_remaining) {
  3475. dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
  3476. icr0_remaining);
  3477. if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
  3478. (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
  3479. (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
  3480. dev_info(&pf->pdev->dev, "device will be reset\n");
  3481. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  3482. i40e_service_event_schedule(pf);
  3483. }
  3484. ena_mask &= ~icr0_remaining;
  3485. }
  3486. ret = IRQ_HANDLED;
  3487. enable_intr:
  3488. /* re-enable interrupt causes */
  3489. wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
  3490. if (!test_bit(__I40E_DOWN, pf->state)) {
  3491. i40e_service_event_schedule(pf);
  3492. i40e_irq_dynamic_enable_icr0(pf);
  3493. }
  3494. return ret;
  3495. }
  3496. /**
  3497. * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
  3498. * @tx_ring: tx ring to clean
  3499. * @budget: how many cleans we're allowed
  3500. *
  3501. * Returns true if there's any budget left (e.g. the clean is finished)
  3502. **/
  3503. static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
  3504. {
  3505. struct i40e_vsi *vsi = tx_ring->vsi;
  3506. u16 i = tx_ring->next_to_clean;
  3507. struct i40e_tx_buffer *tx_buf;
  3508. struct i40e_tx_desc *tx_desc;
  3509. tx_buf = &tx_ring->tx_bi[i];
  3510. tx_desc = I40E_TX_DESC(tx_ring, i);
  3511. i -= tx_ring->count;
  3512. do {
  3513. struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
  3514. /* if next_to_watch is not set then there is no work pending */
  3515. if (!eop_desc)
  3516. break;
  3517. /* prevent any other reads prior to eop_desc */
  3518. smp_rmb();
  3519. /* if the descriptor isn't done, no work yet to do */
  3520. if (!(eop_desc->cmd_type_offset_bsz &
  3521. cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
  3522. break;
  3523. /* clear next_to_watch to prevent false hangs */
  3524. tx_buf->next_to_watch = NULL;
  3525. tx_desc->buffer_addr = 0;
  3526. tx_desc->cmd_type_offset_bsz = 0;
  3527. /* move past filter desc */
  3528. tx_buf++;
  3529. tx_desc++;
  3530. i++;
  3531. if (unlikely(!i)) {
  3532. i -= tx_ring->count;
  3533. tx_buf = tx_ring->tx_bi;
  3534. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3535. }
  3536. /* unmap skb header data */
  3537. dma_unmap_single(tx_ring->dev,
  3538. dma_unmap_addr(tx_buf, dma),
  3539. dma_unmap_len(tx_buf, len),
  3540. DMA_TO_DEVICE);
  3541. if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
  3542. kfree(tx_buf->raw_buf);
  3543. tx_buf->raw_buf = NULL;
  3544. tx_buf->tx_flags = 0;
  3545. tx_buf->next_to_watch = NULL;
  3546. dma_unmap_len_set(tx_buf, len, 0);
  3547. tx_desc->buffer_addr = 0;
  3548. tx_desc->cmd_type_offset_bsz = 0;
  3549. /* move us past the eop_desc for start of next FD desc */
  3550. tx_buf++;
  3551. tx_desc++;
  3552. i++;
  3553. if (unlikely(!i)) {
  3554. i -= tx_ring->count;
  3555. tx_buf = tx_ring->tx_bi;
  3556. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3557. }
  3558. /* update budget accounting */
  3559. budget--;
  3560. } while (likely(budget));
  3561. i += tx_ring->count;
  3562. tx_ring->next_to_clean = i;
  3563. if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
  3564. i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
  3565. return budget > 0;
  3566. }
  3567. /**
  3568. * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
  3569. * @irq: interrupt number
  3570. * @data: pointer to a q_vector
  3571. **/
  3572. static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
  3573. {
  3574. struct i40e_q_vector *q_vector = data;
  3575. struct i40e_vsi *vsi;
  3576. if (!q_vector->tx.ring)
  3577. return IRQ_HANDLED;
  3578. vsi = q_vector->tx.ring->vsi;
  3579. i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
  3580. return IRQ_HANDLED;
  3581. }
  3582. /**
  3583. * i40e_map_vector_to_qp - Assigns the queue pair to the vector
  3584. * @vsi: the VSI being configured
  3585. * @v_idx: vector index
  3586. * @qp_idx: queue pair index
  3587. **/
  3588. static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
  3589. {
  3590. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3591. struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
  3592. struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
  3593. tx_ring->q_vector = q_vector;
  3594. tx_ring->next = q_vector->tx.ring;
  3595. q_vector->tx.ring = tx_ring;
  3596. q_vector->tx.count++;
  3597. /* Place XDP Tx ring in the same q_vector ring list as regular Tx */
  3598. if (i40e_enabled_xdp_vsi(vsi)) {
  3599. struct i40e_ring *xdp_ring = vsi->xdp_rings[qp_idx];
  3600. xdp_ring->q_vector = q_vector;
  3601. xdp_ring->next = q_vector->tx.ring;
  3602. q_vector->tx.ring = xdp_ring;
  3603. q_vector->tx.count++;
  3604. }
  3605. rx_ring->q_vector = q_vector;
  3606. rx_ring->next = q_vector->rx.ring;
  3607. q_vector->rx.ring = rx_ring;
  3608. q_vector->rx.count++;
  3609. }
  3610. /**
  3611. * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
  3612. * @vsi: the VSI being configured
  3613. *
  3614. * This function maps descriptor rings to the queue-specific vectors
  3615. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  3616. * one vector per queue pair, but on a constrained vector budget, we
  3617. * group the queue pairs as "efficiently" as possible.
  3618. **/
  3619. static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
  3620. {
  3621. int qp_remaining = vsi->num_queue_pairs;
  3622. int q_vectors = vsi->num_q_vectors;
  3623. int num_ringpairs;
  3624. int v_start = 0;
  3625. int qp_idx = 0;
  3626. /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
  3627. * group them so there are multiple queues per vector.
  3628. * It is also important to go through all the vectors available to be
  3629. * sure that if we don't use all the vectors, that the remaining vectors
  3630. * are cleared. This is especially important when decreasing the
  3631. * number of queues in use.
  3632. */
  3633. for (; v_start < q_vectors; v_start++) {
  3634. struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
  3635. num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
  3636. q_vector->num_ringpairs = num_ringpairs;
  3637. q_vector->reg_idx = q_vector->v_idx + vsi->base_vector - 1;
  3638. q_vector->rx.count = 0;
  3639. q_vector->tx.count = 0;
  3640. q_vector->rx.ring = NULL;
  3641. q_vector->tx.ring = NULL;
  3642. while (num_ringpairs--) {
  3643. i40e_map_vector_to_qp(vsi, v_start, qp_idx);
  3644. qp_idx++;
  3645. qp_remaining--;
  3646. }
  3647. }
  3648. }
  3649. /**
  3650. * i40e_vsi_request_irq - Request IRQ from the OS
  3651. * @vsi: the VSI being configured
  3652. * @basename: name for the vector
  3653. **/
  3654. static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
  3655. {
  3656. struct i40e_pf *pf = vsi->back;
  3657. int err;
  3658. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3659. err = i40e_vsi_request_irq_msix(vsi, basename);
  3660. else if (pf->flags & I40E_FLAG_MSI_ENABLED)
  3661. err = request_irq(pf->pdev->irq, i40e_intr, 0,
  3662. pf->int_name, pf);
  3663. else
  3664. err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
  3665. pf->int_name, pf);
  3666. if (err)
  3667. dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
  3668. return err;
  3669. }
  3670. #ifdef CONFIG_NET_POLL_CONTROLLER
  3671. /**
  3672. * i40e_netpoll - A Polling 'interrupt' handler
  3673. * @netdev: network interface device structure
  3674. *
  3675. * This is used by netconsole to send skbs without having to re-enable
  3676. * interrupts. It's not called while the normal interrupt routine is executing.
  3677. **/
  3678. static void i40e_netpoll(struct net_device *netdev)
  3679. {
  3680. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3681. struct i40e_vsi *vsi = np->vsi;
  3682. struct i40e_pf *pf = vsi->back;
  3683. int i;
  3684. /* if interface is down do nothing */
  3685. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  3686. return;
  3687. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3688. for (i = 0; i < vsi->num_q_vectors; i++)
  3689. i40e_msix_clean_rings(0, vsi->q_vectors[i]);
  3690. } else {
  3691. i40e_intr(pf->pdev->irq, netdev);
  3692. }
  3693. }
  3694. #endif
  3695. #define I40E_QTX_ENA_WAIT_COUNT 50
  3696. /**
  3697. * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
  3698. * @pf: the PF being configured
  3699. * @pf_q: the PF queue
  3700. * @enable: enable or disable state of the queue
  3701. *
  3702. * This routine will wait for the given Tx queue of the PF to reach the
  3703. * enabled or disabled state.
  3704. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3705. * multiple retries; else will return 0 in case of success.
  3706. **/
  3707. static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3708. {
  3709. int i;
  3710. u32 tx_reg;
  3711. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3712. tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
  3713. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3714. break;
  3715. usleep_range(10, 20);
  3716. }
  3717. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3718. return -ETIMEDOUT;
  3719. return 0;
  3720. }
  3721. /**
  3722. * i40e_control_tx_q - Start or stop a particular Tx queue
  3723. * @pf: the PF structure
  3724. * @pf_q: the PF queue to configure
  3725. * @enable: start or stop the queue
  3726. *
  3727. * This function enables or disables a single queue. Note that any delay
  3728. * required after the operation is expected to be handled by the caller of
  3729. * this function.
  3730. **/
  3731. static void i40e_control_tx_q(struct i40e_pf *pf, int pf_q, bool enable)
  3732. {
  3733. struct i40e_hw *hw = &pf->hw;
  3734. u32 tx_reg;
  3735. int i;
  3736. /* warn the TX unit of coming changes */
  3737. i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
  3738. if (!enable)
  3739. usleep_range(10, 20);
  3740. for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
  3741. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  3742. if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
  3743. ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
  3744. break;
  3745. usleep_range(1000, 2000);
  3746. }
  3747. /* Skip if the queue is already in the requested state */
  3748. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3749. return;
  3750. /* turn on/off the queue */
  3751. if (enable) {
  3752. wr32(hw, I40E_QTX_HEAD(pf_q), 0);
  3753. tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
  3754. } else {
  3755. tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
  3756. }
  3757. wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
  3758. }
  3759. /**
  3760. * i40e_control_wait_tx_q - Start/stop Tx queue and wait for completion
  3761. * @seid: VSI SEID
  3762. * @pf: the PF structure
  3763. * @pf_q: the PF queue to configure
  3764. * @is_xdp: true if the queue is used for XDP
  3765. * @enable: start or stop the queue
  3766. **/
  3767. int i40e_control_wait_tx_q(int seid, struct i40e_pf *pf, int pf_q,
  3768. bool is_xdp, bool enable)
  3769. {
  3770. int ret;
  3771. i40e_control_tx_q(pf, pf_q, enable);
  3772. /* wait for the change to finish */
  3773. ret = i40e_pf_txq_wait(pf, pf_q, enable);
  3774. if (ret) {
  3775. dev_info(&pf->pdev->dev,
  3776. "VSI seid %d %sTx ring %d %sable timeout\n",
  3777. seid, (is_xdp ? "XDP " : ""), pf_q,
  3778. (enable ? "en" : "dis"));
  3779. }
  3780. return ret;
  3781. }
  3782. /**
  3783. * i40e_vsi_control_tx - Start or stop a VSI's rings
  3784. * @vsi: the VSI being configured
  3785. * @enable: start or stop the rings
  3786. **/
  3787. static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
  3788. {
  3789. struct i40e_pf *pf = vsi->back;
  3790. int i, pf_q, ret = 0;
  3791. pf_q = vsi->base_queue;
  3792. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3793. ret = i40e_control_wait_tx_q(vsi->seid, pf,
  3794. pf_q,
  3795. false /*is xdp*/, enable);
  3796. if (ret)
  3797. break;
  3798. if (!i40e_enabled_xdp_vsi(vsi))
  3799. continue;
  3800. ret = i40e_control_wait_tx_q(vsi->seid, pf,
  3801. pf_q + vsi->alloc_queue_pairs,
  3802. true /*is xdp*/, enable);
  3803. if (ret)
  3804. break;
  3805. }
  3806. return ret;
  3807. }
  3808. /**
  3809. * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
  3810. * @pf: the PF being configured
  3811. * @pf_q: the PF queue
  3812. * @enable: enable or disable state of the queue
  3813. *
  3814. * This routine will wait for the given Rx queue of the PF to reach the
  3815. * enabled or disabled state.
  3816. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3817. * multiple retries; else will return 0 in case of success.
  3818. **/
  3819. static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3820. {
  3821. int i;
  3822. u32 rx_reg;
  3823. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3824. rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
  3825. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3826. break;
  3827. usleep_range(10, 20);
  3828. }
  3829. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3830. return -ETIMEDOUT;
  3831. return 0;
  3832. }
  3833. /**
  3834. * i40e_control_rx_q - Start or stop a particular Rx queue
  3835. * @pf: the PF structure
  3836. * @pf_q: the PF queue to configure
  3837. * @enable: start or stop the queue
  3838. *
  3839. * This function enables or disables a single queue. Note that
  3840. * any delay required after the operation is expected to be
  3841. * handled by the caller of this function.
  3842. **/
  3843. static void i40e_control_rx_q(struct i40e_pf *pf, int pf_q, bool enable)
  3844. {
  3845. struct i40e_hw *hw = &pf->hw;
  3846. u32 rx_reg;
  3847. int i;
  3848. for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
  3849. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  3850. if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
  3851. ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
  3852. break;
  3853. usleep_range(1000, 2000);
  3854. }
  3855. /* Skip if the queue is already in the requested state */
  3856. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3857. return;
  3858. /* turn on/off the queue */
  3859. if (enable)
  3860. rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
  3861. else
  3862. rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
  3863. wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
  3864. }
  3865. /**
  3866. * i40e_control_wait_rx_q
  3867. * @pf: the PF structure
  3868. * @pf_q: queue being configured
  3869. * @enable: start or stop the rings
  3870. *
  3871. * This function enables or disables a single queue along with waiting
  3872. * for the change to finish. The caller of this function should handle
  3873. * the delays needed in the case of disabling queues.
  3874. **/
  3875. int i40e_control_wait_rx_q(struct i40e_pf *pf, int pf_q, bool enable)
  3876. {
  3877. int ret = 0;
  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. return ret;
  3883. return ret;
  3884. }
  3885. /**
  3886. * i40e_vsi_control_rx - Start or stop a VSI's rings
  3887. * @vsi: the VSI being configured
  3888. * @enable: start or stop the rings
  3889. **/
  3890. static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
  3891. {
  3892. struct i40e_pf *pf = vsi->back;
  3893. int i, pf_q, ret = 0;
  3894. pf_q = vsi->base_queue;
  3895. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3896. ret = i40e_control_wait_rx_q(pf, pf_q, enable);
  3897. if (ret) {
  3898. dev_info(&pf->pdev->dev,
  3899. "VSI seid %d Rx ring %d %sable timeout\n",
  3900. vsi->seid, pf_q, (enable ? "en" : "dis"));
  3901. break;
  3902. }
  3903. }
  3904. /* Due to HW errata, on Rx disable only, the register can indicate done
  3905. * before it really is. Needs 50ms to be sure
  3906. */
  3907. if (!enable)
  3908. mdelay(50);
  3909. return ret;
  3910. }
  3911. /**
  3912. * i40e_vsi_start_rings - Start a VSI's rings
  3913. * @vsi: the VSI being configured
  3914. **/
  3915. int i40e_vsi_start_rings(struct i40e_vsi *vsi)
  3916. {
  3917. int ret = 0;
  3918. /* do rx first for enable and last for disable */
  3919. ret = i40e_vsi_control_rx(vsi, true);
  3920. if (ret)
  3921. return ret;
  3922. ret = i40e_vsi_control_tx(vsi, true);
  3923. return ret;
  3924. }
  3925. /**
  3926. * i40e_vsi_stop_rings - Stop a VSI's rings
  3927. * @vsi: the VSI being configured
  3928. **/
  3929. void i40e_vsi_stop_rings(struct i40e_vsi *vsi)
  3930. {
  3931. /* When port TX is suspended, don't wait */
  3932. if (test_bit(__I40E_PORT_SUSPENDED, vsi->back->state))
  3933. return i40e_vsi_stop_rings_no_wait(vsi);
  3934. /* do rx first for enable and last for disable
  3935. * Ignore return value, we need to shutdown whatever we can
  3936. */
  3937. i40e_vsi_control_tx(vsi, false);
  3938. i40e_vsi_control_rx(vsi, false);
  3939. }
  3940. /**
  3941. * i40e_vsi_stop_rings_no_wait - Stop a VSI's rings and do not delay
  3942. * @vsi: the VSI being shutdown
  3943. *
  3944. * This function stops all the rings for a VSI but does not delay to verify
  3945. * that rings have been disabled. It is expected that the caller is shutting
  3946. * down multiple VSIs at once and will delay together for all the VSIs after
  3947. * initiating the shutdown. This is particularly useful for shutting down lots
  3948. * of VFs together. Otherwise, a large delay can be incurred while configuring
  3949. * each VSI in serial.
  3950. **/
  3951. void i40e_vsi_stop_rings_no_wait(struct i40e_vsi *vsi)
  3952. {
  3953. struct i40e_pf *pf = vsi->back;
  3954. int i, pf_q;
  3955. pf_q = vsi->base_queue;
  3956. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3957. i40e_control_tx_q(pf, pf_q, false);
  3958. i40e_control_rx_q(pf, pf_q, false);
  3959. }
  3960. }
  3961. /**
  3962. * i40e_vsi_free_irq - Free the irq association with the OS
  3963. * @vsi: the VSI being configured
  3964. **/
  3965. static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
  3966. {
  3967. struct i40e_pf *pf = vsi->back;
  3968. struct i40e_hw *hw = &pf->hw;
  3969. int base = vsi->base_vector;
  3970. u32 val, qp;
  3971. int i;
  3972. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3973. if (!vsi->q_vectors)
  3974. return;
  3975. if (!vsi->irqs_ready)
  3976. return;
  3977. vsi->irqs_ready = false;
  3978. for (i = 0; i < vsi->num_q_vectors; i++) {
  3979. int irq_num;
  3980. u16 vector;
  3981. vector = i + base;
  3982. irq_num = pf->msix_entries[vector].vector;
  3983. /* free only the irqs that were actually requested */
  3984. if (!vsi->q_vectors[i] ||
  3985. !vsi->q_vectors[i]->num_ringpairs)
  3986. continue;
  3987. /* clear the affinity notifier in the IRQ descriptor */
  3988. irq_set_affinity_notifier(irq_num, NULL);
  3989. /* remove our suggested affinity mask for this IRQ */
  3990. irq_set_affinity_hint(irq_num, NULL);
  3991. synchronize_irq(irq_num);
  3992. free_irq(irq_num, vsi->q_vectors[i]);
  3993. /* Tear down the interrupt queue link list
  3994. *
  3995. * We know that they come in pairs and always
  3996. * the Rx first, then the Tx. To clear the
  3997. * link list, stick the EOL value into the
  3998. * next_q field of the registers.
  3999. */
  4000. val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
  4001. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  4002. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  4003. val |= I40E_QUEUE_END_OF_LIST
  4004. << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  4005. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
  4006. while (qp != I40E_QUEUE_END_OF_LIST) {
  4007. u32 next;
  4008. val = rd32(hw, I40E_QINT_RQCTL(qp));
  4009. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  4010. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  4011. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  4012. I40E_QINT_RQCTL_INTEVENT_MASK);
  4013. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  4014. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  4015. wr32(hw, I40E_QINT_RQCTL(qp), val);
  4016. val = rd32(hw, I40E_QINT_TQCTL(qp));
  4017. next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
  4018. >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
  4019. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  4020. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  4021. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  4022. I40E_QINT_TQCTL_INTEVENT_MASK);
  4023. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  4024. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  4025. wr32(hw, I40E_QINT_TQCTL(qp), val);
  4026. qp = next;
  4027. }
  4028. }
  4029. } else {
  4030. free_irq(pf->pdev->irq, pf);
  4031. val = rd32(hw, I40E_PFINT_LNKLST0);
  4032. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  4033. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  4034. val |= I40E_QUEUE_END_OF_LIST
  4035. << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  4036. wr32(hw, I40E_PFINT_LNKLST0, val);
  4037. val = rd32(hw, I40E_QINT_RQCTL(qp));
  4038. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  4039. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  4040. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  4041. I40E_QINT_RQCTL_INTEVENT_MASK);
  4042. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  4043. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  4044. wr32(hw, I40E_QINT_RQCTL(qp), val);
  4045. val = rd32(hw, I40E_QINT_TQCTL(qp));
  4046. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  4047. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  4048. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  4049. I40E_QINT_TQCTL_INTEVENT_MASK);
  4050. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  4051. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  4052. wr32(hw, I40E_QINT_TQCTL(qp), val);
  4053. }
  4054. }
  4055. /**
  4056. * i40e_free_q_vector - Free memory allocated for specific interrupt vector
  4057. * @vsi: the VSI being configured
  4058. * @v_idx: Index of vector to be freed
  4059. *
  4060. * This function frees the memory allocated to the q_vector. In addition if
  4061. * NAPI is enabled it will delete any references to the NAPI struct prior
  4062. * to freeing the q_vector.
  4063. **/
  4064. static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
  4065. {
  4066. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  4067. struct i40e_ring *ring;
  4068. if (!q_vector)
  4069. return;
  4070. /* disassociate q_vector from rings */
  4071. i40e_for_each_ring(ring, q_vector->tx)
  4072. ring->q_vector = NULL;
  4073. i40e_for_each_ring(ring, q_vector->rx)
  4074. ring->q_vector = NULL;
  4075. /* only VSI w/ an associated netdev is set up w/ NAPI */
  4076. if (vsi->netdev)
  4077. netif_napi_del(&q_vector->napi);
  4078. vsi->q_vectors[v_idx] = NULL;
  4079. kfree_rcu(q_vector, rcu);
  4080. }
  4081. /**
  4082. * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
  4083. * @vsi: the VSI being un-configured
  4084. *
  4085. * This frees the memory allocated to the q_vectors and
  4086. * deletes references to the NAPI struct.
  4087. **/
  4088. static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
  4089. {
  4090. int v_idx;
  4091. for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
  4092. i40e_free_q_vector(vsi, v_idx);
  4093. }
  4094. /**
  4095. * i40e_reset_interrupt_capability - Disable interrupt setup in OS
  4096. * @pf: board private structure
  4097. **/
  4098. static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
  4099. {
  4100. /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
  4101. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  4102. pci_disable_msix(pf->pdev);
  4103. kfree(pf->msix_entries);
  4104. pf->msix_entries = NULL;
  4105. kfree(pf->irq_pile);
  4106. pf->irq_pile = NULL;
  4107. } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
  4108. pci_disable_msi(pf->pdev);
  4109. }
  4110. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  4111. }
  4112. /**
  4113. * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
  4114. * @pf: board private structure
  4115. *
  4116. * We go through and clear interrupt specific resources and reset the structure
  4117. * to pre-load conditions
  4118. **/
  4119. static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
  4120. {
  4121. int i;
  4122. i40e_free_misc_vector(pf);
  4123. i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
  4124. I40E_IWARP_IRQ_PILE_ID);
  4125. i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
  4126. for (i = 0; i < pf->num_alloc_vsi; i++)
  4127. if (pf->vsi[i])
  4128. i40e_vsi_free_q_vectors(pf->vsi[i]);
  4129. i40e_reset_interrupt_capability(pf);
  4130. }
  4131. /**
  4132. * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
  4133. * @vsi: the VSI being configured
  4134. **/
  4135. static void i40e_napi_enable_all(struct i40e_vsi *vsi)
  4136. {
  4137. int q_idx;
  4138. if (!vsi->netdev)
  4139. return;
  4140. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
  4141. struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
  4142. if (q_vector->rx.ring || q_vector->tx.ring)
  4143. napi_enable(&q_vector->napi);
  4144. }
  4145. }
  4146. /**
  4147. * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
  4148. * @vsi: the VSI being configured
  4149. **/
  4150. static void i40e_napi_disable_all(struct i40e_vsi *vsi)
  4151. {
  4152. int q_idx;
  4153. if (!vsi->netdev)
  4154. return;
  4155. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
  4156. struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
  4157. if (q_vector->rx.ring || q_vector->tx.ring)
  4158. napi_disable(&q_vector->napi);
  4159. }
  4160. }
  4161. /**
  4162. * i40e_vsi_close - Shut down a VSI
  4163. * @vsi: the vsi to be quelled
  4164. **/
  4165. static void i40e_vsi_close(struct i40e_vsi *vsi)
  4166. {
  4167. struct i40e_pf *pf = vsi->back;
  4168. if (!test_and_set_bit(__I40E_VSI_DOWN, vsi->state))
  4169. i40e_down(vsi);
  4170. i40e_vsi_free_irq(vsi);
  4171. i40e_vsi_free_tx_resources(vsi);
  4172. i40e_vsi_free_rx_resources(vsi);
  4173. vsi->current_netdev_flags = 0;
  4174. set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
  4175. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  4176. set_bit(__I40E_CLIENT_RESET, pf->state);
  4177. }
  4178. /**
  4179. * i40e_quiesce_vsi - Pause a given VSI
  4180. * @vsi: the VSI being paused
  4181. **/
  4182. static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
  4183. {
  4184. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  4185. return;
  4186. set_bit(__I40E_VSI_NEEDS_RESTART, vsi->state);
  4187. if (vsi->netdev && netif_running(vsi->netdev))
  4188. vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
  4189. else
  4190. i40e_vsi_close(vsi);
  4191. }
  4192. /**
  4193. * i40e_unquiesce_vsi - Resume a given VSI
  4194. * @vsi: the VSI being resumed
  4195. **/
  4196. static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
  4197. {
  4198. if (!test_and_clear_bit(__I40E_VSI_NEEDS_RESTART, vsi->state))
  4199. return;
  4200. if (vsi->netdev && netif_running(vsi->netdev))
  4201. vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
  4202. else
  4203. i40e_vsi_open(vsi); /* this clears the DOWN bit */
  4204. }
  4205. /**
  4206. * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
  4207. * @pf: the PF
  4208. **/
  4209. static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
  4210. {
  4211. int v;
  4212. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4213. if (pf->vsi[v])
  4214. i40e_quiesce_vsi(pf->vsi[v]);
  4215. }
  4216. }
  4217. /**
  4218. * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
  4219. * @pf: the PF
  4220. **/
  4221. static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
  4222. {
  4223. int v;
  4224. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4225. if (pf->vsi[v])
  4226. i40e_unquiesce_vsi(pf->vsi[v]);
  4227. }
  4228. }
  4229. /**
  4230. * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
  4231. * @vsi: the VSI being configured
  4232. *
  4233. * Wait until all queues on a given VSI have been disabled.
  4234. **/
  4235. int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
  4236. {
  4237. struct i40e_pf *pf = vsi->back;
  4238. int i, pf_q, ret;
  4239. pf_q = vsi->base_queue;
  4240. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  4241. /* Check and wait for the Tx queue */
  4242. ret = i40e_pf_txq_wait(pf, pf_q, false);
  4243. if (ret) {
  4244. dev_info(&pf->pdev->dev,
  4245. "VSI seid %d Tx ring %d disable timeout\n",
  4246. vsi->seid, pf_q);
  4247. return ret;
  4248. }
  4249. if (!i40e_enabled_xdp_vsi(vsi))
  4250. goto wait_rx;
  4251. /* Check and wait for the XDP Tx queue */
  4252. ret = i40e_pf_txq_wait(pf, pf_q + vsi->alloc_queue_pairs,
  4253. false);
  4254. if (ret) {
  4255. dev_info(&pf->pdev->dev,
  4256. "VSI seid %d XDP Tx ring %d disable timeout\n",
  4257. vsi->seid, pf_q);
  4258. return ret;
  4259. }
  4260. wait_rx:
  4261. /* Check and wait for the Rx queue */
  4262. ret = i40e_pf_rxq_wait(pf, pf_q, false);
  4263. if (ret) {
  4264. dev_info(&pf->pdev->dev,
  4265. "VSI seid %d Rx ring %d disable timeout\n",
  4266. vsi->seid, pf_q);
  4267. return ret;
  4268. }
  4269. }
  4270. return 0;
  4271. }
  4272. #ifdef CONFIG_I40E_DCB
  4273. /**
  4274. * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
  4275. * @pf: the PF
  4276. *
  4277. * This function waits for the queues to be in disabled state for all the
  4278. * VSIs that are managed by this PF.
  4279. **/
  4280. static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
  4281. {
  4282. int v, ret = 0;
  4283. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  4284. if (pf->vsi[v]) {
  4285. ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
  4286. if (ret)
  4287. break;
  4288. }
  4289. }
  4290. return ret;
  4291. }
  4292. #endif
  4293. /**
  4294. * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
  4295. * @pf: pointer to PF
  4296. *
  4297. * Get TC map for ISCSI PF type that will include iSCSI TC
  4298. * and LAN TC.
  4299. **/
  4300. static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
  4301. {
  4302. struct i40e_dcb_app_priority_table app;
  4303. struct i40e_hw *hw = &pf->hw;
  4304. u8 enabled_tc = 1; /* TC0 is always enabled */
  4305. u8 tc, i;
  4306. /* Get the iSCSI APP TLV */
  4307. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4308. for (i = 0; i < dcbcfg->numapps; i++) {
  4309. app = dcbcfg->app[i];
  4310. if (app.selector == I40E_APP_SEL_TCPIP &&
  4311. app.protocolid == I40E_APP_PROTOID_ISCSI) {
  4312. tc = dcbcfg->etscfg.prioritytable[app.priority];
  4313. enabled_tc |= BIT(tc);
  4314. break;
  4315. }
  4316. }
  4317. return enabled_tc;
  4318. }
  4319. /**
  4320. * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
  4321. * @dcbcfg: the corresponding DCBx configuration structure
  4322. *
  4323. * Return the number of TCs from given DCBx configuration
  4324. **/
  4325. static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
  4326. {
  4327. int i, tc_unused = 0;
  4328. u8 num_tc = 0;
  4329. u8 ret = 0;
  4330. /* Scan the ETS Config Priority Table to find
  4331. * traffic class enabled for a given priority
  4332. * and create a bitmask of enabled TCs
  4333. */
  4334. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
  4335. num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
  4336. /* Now scan the bitmask to check for
  4337. * contiguous TCs starting with TC0
  4338. */
  4339. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4340. if (num_tc & BIT(i)) {
  4341. if (!tc_unused) {
  4342. ret++;
  4343. } else {
  4344. pr_err("Non-contiguous TC - Disabling DCB\n");
  4345. return 1;
  4346. }
  4347. } else {
  4348. tc_unused = 1;
  4349. }
  4350. }
  4351. /* There is always at least TC0 */
  4352. if (!ret)
  4353. ret = 1;
  4354. return ret;
  4355. }
  4356. /**
  4357. * i40e_dcb_get_enabled_tc - Get enabled traffic classes
  4358. * @dcbcfg: the corresponding DCBx configuration structure
  4359. *
  4360. * Query the current DCB configuration and return the number of
  4361. * traffic classes enabled from the given DCBX config
  4362. **/
  4363. static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
  4364. {
  4365. u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
  4366. u8 enabled_tc = 1;
  4367. u8 i;
  4368. for (i = 0; i < num_tc; i++)
  4369. enabled_tc |= BIT(i);
  4370. return enabled_tc;
  4371. }
  4372. /**
  4373. * i40e_mqprio_get_enabled_tc - Get enabled traffic classes
  4374. * @pf: PF being queried
  4375. *
  4376. * Query the current MQPRIO configuration and return the number of
  4377. * traffic classes enabled.
  4378. **/
  4379. static u8 i40e_mqprio_get_enabled_tc(struct i40e_pf *pf)
  4380. {
  4381. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  4382. u8 num_tc = vsi->mqprio_qopt.qopt.num_tc;
  4383. u8 enabled_tc = 1, i;
  4384. for (i = 1; i < num_tc; i++)
  4385. enabled_tc |= BIT(i);
  4386. return enabled_tc;
  4387. }
  4388. /**
  4389. * i40e_pf_get_num_tc - Get enabled traffic classes for PF
  4390. * @pf: PF being queried
  4391. *
  4392. * Return number of traffic classes enabled for the given PF
  4393. **/
  4394. static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
  4395. {
  4396. struct i40e_hw *hw = &pf->hw;
  4397. u8 i, enabled_tc = 1;
  4398. u8 num_tc = 0;
  4399. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4400. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4401. return pf->vsi[pf->lan_vsi]->mqprio_qopt.qopt.num_tc;
  4402. /* If neither MQPRIO nor DCB is enabled, then always use single TC */
  4403. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4404. return 1;
  4405. /* SFP mode will be enabled for all TCs on port */
  4406. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4407. return i40e_dcb_get_num_tc(dcbcfg);
  4408. /* MFP mode return count of enabled TCs for this PF */
  4409. if (pf->hw.func_caps.iscsi)
  4410. enabled_tc = i40e_get_iscsi_tc_map(pf);
  4411. else
  4412. return 1; /* Only TC0 */
  4413. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4414. if (enabled_tc & BIT(i))
  4415. num_tc++;
  4416. }
  4417. return num_tc;
  4418. }
  4419. /**
  4420. * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
  4421. * @pf: PF being queried
  4422. *
  4423. * Return a bitmap for enabled traffic classes for this PF.
  4424. **/
  4425. static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
  4426. {
  4427. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4428. return i40e_mqprio_get_enabled_tc(pf);
  4429. /* If neither MQPRIO nor DCB is enabled for this PF then just return
  4430. * default TC
  4431. */
  4432. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4433. return I40E_DEFAULT_TRAFFIC_CLASS;
  4434. /* SFP mode we want PF to be enabled for all TCs */
  4435. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4436. return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
  4437. /* MFP enabled and iSCSI PF type */
  4438. if (pf->hw.func_caps.iscsi)
  4439. return i40e_get_iscsi_tc_map(pf);
  4440. else
  4441. return I40E_DEFAULT_TRAFFIC_CLASS;
  4442. }
  4443. /**
  4444. * i40e_vsi_get_bw_info - Query VSI BW Information
  4445. * @vsi: the VSI being queried
  4446. *
  4447. * Returns 0 on success, negative value on failure
  4448. **/
  4449. static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
  4450. {
  4451. struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
  4452. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  4453. struct i40e_pf *pf = vsi->back;
  4454. struct i40e_hw *hw = &pf->hw;
  4455. i40e_status ret;
  4456. u32 tc_bw_max;
  4457. int i;
  4458. /* Get the VSI level BW configuration */
  4459. ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
  4460. if (ret) {
  4461. dev_info(&pf->pdev->dev,
  4462. "couldn't get PF vsi bw config, err %s aq_err %s\n",
  4463. i40e_stat_str(&pf->hw, ret),
  4464. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4465. return -EINVAL;
  4466. }
  4467. /* Get the VSI level BW configuration per TC */
  4468. ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
  4469. NULL);
  4470. if (ret) {
  4471. dev_info(&pf->pdev->dev,
  4472. "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
  4473. i40e_stat_str(&pf->hw, ret),
  4474. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4475. return -EINVAL;
  4476. }
  4477. if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
  4478. dev_info(&pf->pdev->dev,
  4479. "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
  4480. bw_config.tc_valid_bits,
  4481. bw_ets_config.tc_valid_bits);
  4482. /* Still continuing */
  4483. }
  4484. vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
  4485. vsi->bw_max_quanta = bw_config.max_bw;
  4486. tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
  4487. (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
  4488. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4489. vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
  4490. vsi->bw_ets_limit_credits[i] =
  4491. le16_to_cpu(bw_ets_config.credits[i]);
  4492. /* 3 bits out of 4 for each TC */
  4493. vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
  4494. }
  4495. return 0;
  4496. }
  4497. /**
  4498. * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
  4499. * @vsi: the VSI being configured
  4500. * @enabled_tc: TC bitmap
  4501. * @bw_share: BW shared credits per TC
  4502. *
  4503. * Returns 0 on success, negative value on failure
  4504. **/
  4505. static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
  4506. u8 *bw_share)
  4507. {
  4508. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  4509. struct i40e_pf *pf = vsi->back;
  4510. i40e_status ret;
  4511. int i;
  4512. /* There is no need to reset BW when mqprio mode is on. */
  4513. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4514. return 0;
  4515. if (!vsi->mqprio_qopt.qopt.hw && !(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  4516. ret = i40e_set_bw_limit(vsi, vsi->seid, 0);
  4517. if (ret)
  4518. dev_info(&pf->pdev->dev,
  4519. "Failed to reset tx rate for vsi->seid %u\n",
  4520. vsi->seid);
  4521. return ret;
  4522. }
  4523. bw_data.tc_valid_bits = enabled_tc;
  4524. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4525. bw_data.tc_bw_credits[i] = bw_share[i];
  4526. ret = i40e_aq_config_vsi_tc_bw(&pf->hw, vsi->seid, &bw_data, NULL);
  4527. if (ret) {
  4528. dev_info(&pf->pdev->dev,
  4529. "AQ command Config VSI BW allocation per TC failed = %d\n",
  4530. pf->hw.aq.asq_last_status);
  4531. return -EINVAL;
  4532. }
  4533. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4534. vsi->info.qs_handle[i] = bw_data.qs_handles[i];
  4535. return 0;
  4536. }
  4537. /**
  4538. * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
  4539. * @vsi: the VSI being configured
  4540. * @enabled_tc: TC map to be enabled
  4541. *
  4542. **/
  4543. static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4544. {
  4545. struct net_device *netdev = vsi->netdev;
  4546. struct i40e_pf *pf = vsi->back;
  4547. struct i40e_hw *hw = &pf->hw;
  4548. u8 netdev_tc = 0;
  4549. int i;
  4550. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4551. if (!netdev)
  4552. return;
  4553. if (!enabled_tc) {
  4554. netdev_reset_tc(netdev);
  4555. return;
  4556. }
  4557. /* Set up actual enabled TCs on the VSI */
  4558. if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
  4559. return;
  4560. /* set per TC queues for the VSI */
  4561. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4562. /* Only set TC queues for enabled tcs
  4563. *
  4564. * e.g. For a VSI that has TC0 and TC3 enabled the
  4565. * enabled_tc bitmap would be 0x00001001; the driver
  4566. * will set the numtc for netdev as 2 that will be
  4567. * referenced by the netdev layer as TC 0 and 1.
  4568. */
  4569. if (vsi->tc_config.enabled_tc & BIT(i))
  4570. netdev_set_tc_queue(netdev,
  4571. vsi->tc_config.tc_info[i].netdev_tc,
  4572. vsi->tc_config.tc_info[i].qcount,
  4573. vsi->tc_config.tc_info[i].qoffset);
  4574. }
  4575. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4576. return;
  4577. /* Assign UP2TC map for the VSI */
  4578. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  4579. /* Get the actual TC# for the UP */
  4580. u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
  4581. /* Get the mapped netdev TC# for the UP */
  4582. netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
  4583. netdev_set_prio_tc_map(netdev, i, netdev_tc);
  4584. }
  4585. }
  4586. /**
  4587. * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
  4588. * @vsi: the VSI being configured
  4589. * @ctxt: the ctxt buffer returned from AQ VSI update param command
  4590. **/
  4591. static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
  4592. struct i40e_vsi_context *ctxt)
  4593. {
  4594. /* copy just the sections touched not the entire info
  4595. * since not all sections are valid as returned by
  4596. * update vsi params
  4597. */
  4598. vsi->info.mapping_flags = ctxt->info.mapping_flags;
  4599. memcpy(&vsi->info.queue_mapping,
  4600. &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
  4601. memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
  4602. sizeof(vsi->info.tc_mapping));
  4603. }
  4604. /**
  4605. * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
  4606. * @vsi: VSI to be configured
  4607. * @enabled_tc: TC bitmap
  4608. *
  4609. * This configures a particular VSI for TCs that are mapped to the
  4610. * given TC bitmap. It uses default bandwidth share for TCs across
  4611. * VSIs to configure TC for a particular VSI.
  4612. *
  4613. * NOTE:
  4614. * It is expected that the VSI queues have been quisced before calling
  4615. * this function.
  4616. **/
  4617. static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4618. {
  4619. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  4620. struct i40e_pf *pf = vsi->back;
  4621. struct i40e_hw *hw = &pf->hw;
  4622. struct i40e_vsi_context ctxt;
  4623. int ret = 0;
  4624. int i;
  4625. /* Check if enabled_tc is same as existing or new TCs */
  4626. if (vsi->tc_config.enabled_tc == enabled_tc &&
  4627. vsi->mqprio_qopt.mode != TC_MQPRIO_MODE_CHANNEL)
  4628. return ret;
  4629. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  4630. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4631. if (enabled_tc & BIT(i))
  4632. bw_share[i] = 1;
  4633. }
  4634. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  4635. if (ret) {
  4636. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  4637. dev_info(&pf->pdev->dev,
  4638. "Failed configuring TC map %d for VSI %d\n",
  4639. enabled_tc, vsi->seid);
  4640. ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid,
  4641. &bw_config, NULL);
  4642. if (ret) {
  4643. dev_info(&pf->pdev->dev,
  4644. "Failed querying vsi bw info, err %s aq_err %s\n",
  4645. i40e_stat_str(hw, ret),
  4646. i40e_aq_str(hw, hw->aq.asq_last_status));
  4647. goto out;
  4648. }
  4649. if ((bw_config.tc_valid_bits & enabled_tc) != enabled_tc) {
  4650. u8 valid_tc = bw_config.tc_valid_bits & enabled_tc;
  4651. if (!valid_tc)
  4652. valid_tc = bw_config.tc_valid_bits;
  4653. /* Always enable TC0, no matter what */
  4654. valid_tc |= 1;
  4655. dev_info(&pf->pdev->dev,
  4656. "Requested tc 0x%x, but FW reports 0x%x as valid. Attempting to use 0x%x.\n",
  4657. enabled_tc, bw_config.tc_valid_bits, valid_tc);
  4658. enabled_tc = valid_tc;
  4659. }
  4660. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  4661. if (ret) {
  4662. dev_err(&pf->pdev->dev,
  4663. "Unable to configure TC map %d for VSI %d\n",
  4664. enabled_tc, vsi->seid);
  4665. goto out;
  4666. }
  4667. }
  4668. /* Update Queue Pairs Mapping for currently enabled UPs */
  4669. ctxt.seid = vsi->seid;
  4670. ctxt.pf_num = vsi->back->hw.pf_id;
  4671. ctxt.vf_num = 0;
  4672. ctxt.uplink_seid = vsi->uplink_seid;
  4673. ctxt.info = vsi->info;
  4674. if (vsi->back->flags & I40E_FLAG_TC_MQPRIO) {
  4675. ret = i40e_vsi_setup_queue_map_mqprio(vsi, &ctxt, enabled_tc);
  4676. if (ret)
  4677. goto out;
  4678. } else {
  4679. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  4680. }
  4681. /* On destroying the qdisc, reset vsi->rss_size, as number of enabled
  4682. * queues changed.
  4683. */
  4684. if (!vsi->mqprio_qopt.qopt.hw && vsi->reconfig_rss) {
  4685. vsi->rss_size = min_t(int, vsi->back->alloc_rss_size,
  4686. vsi->num_queue_pairs);
  4687. ret = i40e_vsi_config_rss(vsi);
  4688. if (ret) {
  4689. dev_info(&vsi->back->pdev->dev,
  4690. "Failed to reconfig rss for num_queues\n");
  4691. return ret;
  4692. }
  4693. vsi->reconfig_rss = false;
  4694. }
  4695. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  4696. ctxt.info.valid_sections |=
  4697. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  4698. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  4699. }
  4700. /* Update the VSI after updating the VSI queue-mapping
  4701. * information
  4702. */
  4703. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  4704. if (ret) {
  4705. dev_info(&pf->pdev->dev,
  4706. "Update vsi tc config failed, err %s aq_err %s\n",
  4707. i40e_stat_str(hw, ret),
  4708. i40e_aq_str(hw, hw->aq.asq_last_status));
  4709. goto out;
  4710. }
  4711. /* update the local VSI info with updated queue map */
  4712. i40e_vsi_update_queue_map(vsi, &ctxt);
  4713. vsi->info.valid_sections = 0;
  4714. /* Update current VSI BW information */
  4715. ret = i40e_vsi_get_bw_info(vsi);
  4716. if (ret) {
  4717. dev_info(&pf->pdev->dev,
  4718. "Failed updating vsi bw info, err %s aq_err %s\n",
  4719. i40e_stat_str(hw, ret),
  4720. i40e_aq_str(hw, hw->aq.asq_last_status));
  4721. goto out;
  4722. }
  4723. /* Update the netdev TC setup */
  4724. i40e_vsi_config_netdev_tc(vsi, enabled_tc);
  4725. out:
  4726. return ret;
  4727. }
  4728. /**
  4729. * i40e_get_link_speed - Returns link speed for the interface
  4730. * @vsi: VSI to be configured
  4731. *
  4732. **/
  4733. static int i40e_get_link_speed(struct i40e_vsi *vsi)
  4734. {
  4735. struct i40e_pf *pf = vsi->back;
  4736. switch (pf->hw.phy.link_info.link_speed) {
  4737. case I40E_LINK_SPEED_40GB:
  4738. return 40000;
  4739. case I40E_LINK_SPEED_25GB:
  4740. return 25000;
  4741. case I40E_LINK_SPEED_20GB:
  4742. return 20000;
  4743. case I40E_LINK_SPEED_10GB:
  4744. return 10000;
  4745. case I40E_LINK_SPEED_1GB:
  4746. return 1000;
  4747. default:
  4748. return -EINVAL;
  4749. }
  4750. }
  4751. /**
  4752. * i40e_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
  4753. * @vsi: VSI to be configured
  4754. * @seid: seid of the channel/VSI
  4755. * @max_tx_rate: max TX rate to be configured as BW limit
  4756. *
  4757. * Helper function to set BW limit for a given VSI
  4758. **/
  4759. int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate)
  4760. {
  4761. struct i40e_pf *pf = vsi->back;
  4762. u64 credits = 0;
  4763. int speed = 0;
  4764. int ret = 0;
  4765. speed = i40e_get_link_speed(vsi);
  4766. if (max_tx_rate > speed) {
  4767. dev_err(&pf->pdev->dev,
  4768. "Invalid max tx rate %llu specified for VSI seid %d.",
  4769. max_tx_rate, seid);
  4770. return -EINVAL;
  4771. }
  4772. if (max_tx_rate && max_tx_rate < 50) {
  4773. dev_warn(&pf->pdev->dev,
  4774. "Setting max tx rate to minimum usable value of 50Mbps.\n");
  4775. max_tx_rate = 50;
  4776. }
  4777. /* Tx rate credits are in values of 50Mbps, 0 is disabled */
  4778. credits = max_tx_rate;
  4779. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  4780. ret = i40e_aq_config_vsi_bw_limit(&pf->hw, seid, credits,
  4781. I40E_MAX_BW_INACTIVE_ACCUM, NULL);
  4782. if (ret)
  4783. dev_err(&pf->pdev->dev,
  4784. "Failed set tx rate (%llu Mbps) for vsi->seid %u, err %s aq_err %s\n",
  4785. max_tx_rate, seid, i40e_stat_str(&pf->hw, ret),
  4786. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4787. return ret;
  4788. }
  4789. /**
  4790. * i40e_remove_queue_channels - Remove queue channels for the TCs
  4791. * @vsi: VSI to be configured
  4792. *
  4793. * Remove queue channels for the TCs
  4794. **/
  4795. static void i40e_remove_queue_channels(struct i40e_vsi *vsi)
  4796. {
  4797. enum i40e_admin_queue_err last_aq_status;
  4798. struct i40e_cloud_filter *cfilter;
  4799. struct i40e_channel *ch, *ch_tmp;
  4800. struct i40e_pf *pf = vsi->back;
  4801. struct hlist_node *node;
  4802. int ret, i;
  4803. /* Reset rss size that was stored when reconfiguring rss for
  4804. * channel VSIs with non-power-of-2 queue count.
  4805. */
  4806. vsi->current_rss_size = 0;
  4807. /* perform cleanup for channels if they exist */
  4808. if (list_empty(&vsi->ch_list))
  4809. return;
  4810. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4811. struct i40e_vsi *p_vsi;
  4812. list_del(&ch->list);
  4813. p_vsi = ch->parent_vsi;
  4814. if (!p_vsi || !ch->initialized) {
  4815. kfree(ch);
  4816. continue;
  4817. }
  4818. /* Reset queue contexts */
  4819. for (i = 0; i < ch->num_queue_pairs; i++) {
  4820. struct i40e_ring *tx_ring, *rx_ring;
  4821. u16 pf_q;
  4822. pf_q = ch->base_queue + i;
  4823. tx_ring = vsi->tx_rings[pf_q];
  4824. tx_ring->ch = NULL;
  4825. rx_ring = vsi->rx_rings[pf_q];
  4826. rx_ring->ch = NULL;
  4827. }
  4828. /* Reset BW configured for this VSI via mqprio */
  4829. ret = i40e_set_bw_limit(vsi, ch->seid, 0);
  4830. if (ret)
  4831. dev_info(&vsi->back->pdev->dev,
  4832. "Failed to reset tx rate for ch->seid %u\n",
  4833. ch->seid);
  4834. /* delete cloud filters associated with this channel */
  4835. hlist_for_each_entry_safe(cfilter, node,
  4836. &pf->cloud_filter_list, cloud_node) {
  4837. if (cfilter->seid != ch->seid)
  4838. continue;
  4839. hash_del(&cfilter->cloud_node);
  4840. if (cfilter->dst_port)
  4841. ret = i40e_add_del_cloud_filter_big_buf(vsi,
  4842. cfilter,
  4843. false);
  4844. else
  4845. ret = i40e_add_del_cloud_filter(vsi, cfilter,
  4846. false);
  4847. last_aq_status = pf->hw.aq.asq_last_status;
  4848. if (ret)
  4849. dev_info(&pf->pdev->dev,
  4850. "Failed to delete cloud filter, err %s aq_err %s\n",
  4851. i40e_stat_str(&pf->hw, ret),
  4852. i40e_aq_str(&pf->hw, last_aq_status));
  4853. kfree(cfilter);
  4854. }
  4855. /* delete VSI from FW */
  4856. ret = i40e_aq_delete_element(&vsi->back->hw, ch->seid,
  4857. NULL);
  4858. if (ret)
  4859. dev_err(&vsi->back->pdev->dev,
  4860. "unable to remove channel (%d) for parent VSI(%d)\n",
  4861. ch->seid, p_vsi->seid);
  4862. kfree(ch);
  4863. }
  4864. INIT_LIST_HEAD(&vsi->ch_list);
  4865. }
  4866. /**
  4867. * i40e_is_any_channel - channel exist or not
  4868. * @vsi: ptr to VSI to which channels are associated with
  4869. *
  4870. * Returns true or false if channel(s) exist for associated VSI or not
  4871. **/
  4872. static bool i40e_is_any_channel(struct i40e_vsi *vsi)
  4873. {
  4874. struct i40e_channel *ch, *ch_tmp;
  4875. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4876. if (ch->initialized)
  4877. return true;
  4878. }
  4879. return false;
  4880. }
  4881. /**
  4882. * i40e_get_max_queues_for_channel
  4883. * @vsi: ptr to VSI to which channels are associated with
  4884. *
  4885. * Helper function which returns max value among the queue counts set on the
  4886. * channels/TCs created.
  4887. **/
  4888. static int i40e_get_max_queues_for_channel(struct i40e_vsi *vsi)
  4889. {
  4890. struct i40e_channel *ch, *ch_tmp;
  4891. int max = 0;
  4892. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4893. if (!ch->initialized)
  4894. continue;
  4895. if (ch->num_queue_pairs > max)
  4896. max = ch->num_queue_pairs;
  4897. }
  4898. return max;
  4899. }
  4900. /**
  4901. * i40e_validate_num_queues - validate num_queues w.r.t channel
  4902. * @pf: ptr to PF device
  4903. * @num_queues: number of queues
  4904. * @vsi: the parent VSI
  4905. * @reconfig_rss: indicates should the RSS be reconfigured or not
  4906. *
  4907. * This function validates number of queues in the context of new channel
  4908. * which is being established and determines if RSS should be reconfigured
  4909. * or not for parent VSI.
  4910. **/
  4911. static int i40e_validate_num_queues(struct i40e_pf *pf, int num_queues,
  4912. struct i40e_vsi *vsi, bool *reconfig_rss)
  4913. {
  4914. int max_ch_queues;
  4915. if (!reconfig_rss)
  4916. return -EINVAL;
  4917. *reconfig_rss = false;
  4918. if (vsi->current_rss_size) {
  4919. if (num_queues > vsi->current_rss_size) {
  4920. dev_dbg(&pf->pdev->dev,
  4921. "Error: num_queues (%d) > vsi's current_size(%d)\n",
  4922. num_queues, vsi->current_rss_size);
  4923. return -EINVAL;
  4924. } else if ((num_queues < vsi->current_rss_size) &&
  4925. (!is_power_of_2(num_queues))) {
  4926. dev_dbg(&pf->pdev->dev,
  4927. "Error: num_queues (%d) < vsi's current_size(%d), but not power of 2\n",
  4928. num_queues, vsi->current_rss_size);
  4929. return -EINVAL;
  4930. }
  4931. }
  4932. if (!is_power_of_2(num_queues)) {
  4933. /* Find the max num_queues configured for channel if channel
  4934. * exist.
  4935. * if channel exist, then enforce 'num_queues' to be more than
  4936. * max ever queues configured for channel.
  4937. */
  4938. max_ch_queues = i40e_get_max_queues_for_channel(vsi);
  4939. if (num_queues < max_ch_queues) {
  4940. dev_dbg(&pf->pdev->dev,
  4941. "Error: num_queues (%d) < max queues configured for channel(%d)\n",
  4942. num_queues, max_ch_queues);
  4943. return -EINVAL;
  4944. }
  4945. *reconfig_rss = true;
  4946. }
  4947. return 0;
  4948. }
  4949. /**
  4950. * i40e_vsi_reconfig_rss - reconfig RSS based on specified rss_size
  4951. * @vsi: the VSI being setup
  4952. * @rss_size: size of RSS, accordingly LUT gets reprogrammed
  4953. *
  4954. * This function reconfigures RSS by reprogramming LUTs using 'rss_size'
  4955. **/
  4956. static int i40e_vsi_reconfig_rss(struct i40e_vsi *vsi, u16 rss_size)
  4957. {
  4958. struct i40e_pf *pf = vsi->back;
  4959. u8 seed[I40E_HKEY_ARRAY_SIZE];
  4960. struct i40e_hw *hw = &pf->hw;
  4961. int local_rss_size;
  4962. u8 *lut;
  4963. int ret;
  4964. if (!vsi->rss_size)
  4965. return -EINVAL;
  4966. if (rss_size > vsi->rss_size)
  4967. return -EINVAL;
  4968. local_rss_size = min_t(int, vsi->rss_size, rss_size);
  4969. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  4970. if (!lut)
  4971. return -ENOMEM;
  4972. /* Ignoring user configured lut if there is one */
  4973. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, local_rss_size);
  4974. /* Use user configured hash key if there is one, otherwise
  4975. * use default.
  4976. */
  4977. if (vsi->rss_hkey_user)
  4978. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  4979. else
  4980. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  4981. ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
  4982. if (ret) {
  4983. dev_info(&pf->pdev->dev,
  4984. "Cannot set RSS lut, err %s aq_err %s\n",
  4985. i40e_stat_str(hw, ret),
  4986. i40e_aq_str(hw, hw->aq.asq_last_status));
  4987. kfree(lut);
  4988. return ret;
  4989. }
  4990. kfree(lut);
  4991. /* Do the update w.r.t. storing rss_size */
  4992. if (!vsi->orig_rss_size)
  4993. vsi->orig_rss_size = vsi->rss_size;
  4994. vsi->current_rss_size = local_rss_size;
  4995. return ret;
  4996. }
  4997. /**
  4998. * i40e_channel_setup_queue_map - Setup a channel queue map
  4999. * @pf: ptr to PF device
  5000. * @vsi: the VSI being setup
  5001. * @ctxt: VSI context structure
  5002. * @ch: ptr to channel structure
  5003. *
  5004. * Setup queue map for a specific channel
  5005. **/
  5006. static void i40e_channel_setup_queue_map(struct i40e_pf *pf,
  5007. struct i40e_vsi_context *ctxt,
  5008. struct i40e_channel *ch)
  5009. {
  5010. u16 qcount, qmap, sections = 0;
  5011. u8 offset = 0;
  5012. int pow;
  5013. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  5014. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  5015. qcount = min_t(int, ch->num_queue_pairs, pf->num_lan_msix);
  5016. ch->num_queue_pairs = qcount;
  5017. /* find the next higher power-of-2 of num queue pairs */
  5018. pow = ilog2(qcount);
  5019. if (!is_power_of_2(qcount))
  5020. pow++;
  5021. qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  5022. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  5023. /* Setup queue TC[0].qmap for given VSI context */
  5024. ctxt->info.tc_mapping[0] = cpu_to_le16(qmap);
  5025. ctxt->info.up_enable_bits = 0x1; /* TC0 enabled */
  5026. ctxt->info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  5027. ctxt->info.queue_mapping[0] = cpu_to_le16(ch->base_queue);
  5028. ctxt->info.valid_sections |= cpu_to_le16(sections);
  5029. }
  5030. /**
  5031. * i40e_add_channel - add a channel by adding VSI
  5032. * @pf: ptr to PF device
  5033. * @uplink_seid: underlying HW switching element (VEB) ID
  5034. * @ch: ptr to channel structure
  5035. *
  5036. * Add a channel (VSI) using add_vsi and queue_map
  5037. **/
  5038. static int i40e_add_channel(struct i40e_pf *pf, u16 uplink_seid,
  5039. struct i40e_channel *ch)
  5040. {
  5041. struct i40e_hw *hw = &pf->hw;
  5042. struct i40e_vsi_context ctxt;
  5043. u8 enabled_tc = 0x1; /* TC0 enabled */
  5044. int ret;
  5045. if (ch->type != I40E_VSI_VMDQ2) {
  5046. dev_info(&pf->pdev->dev,
  5047. "add new vsi failed, ch->type %d\n", ch->type);
  5048. return -EINVAL;
  5049. }
  5050. memset(&ctxt, 0, sizeof(ctxt));
  5051. ctxt.pf_num = hw->pf_id;
  5052. ctxt.vf_num = 0;
  5053. ctxt.uplink_seid = uplink_seid;
  5054. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  5055. if (ch->type == I40E_VSI_VMDQ2)
  5056. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  5057. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) {
  5058. ctxt.info.valid_sections |=
  5059. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5060. ctxt.info.switch_id =
  5061. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5062. }
  5063. /* Set queue map for a given VSI context */
  5064. i40e_channel_setup_queue_map(pf, &ctxt, ch);
  5065. /* Now time to create VSI */
  5066. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  5067. if (ret) {
  5068. dev_info(&pf->pdev->dev,
  5069. "add new vsi failed, err %s aq_err %s\n",
  5070. i40e_stat_str(&pf->hw, ret),
  5071. i40e_aq_str(&pf->hw,
  5072. pf->hw.aq.asq_last_status));
  5073. return -ENOENT;
  5074. }
  5075. /* Success, update channel */
  5076. ch->enabled_tc = enabled_tc;
  5077. ch->seid = ctxt.seid;
  5078. ch->vsi_number = ctxt.vsi_number;
  5079. ch->stat_counter_idx = cpu_to_le16(ctxt.info.stat_counter_idx);
  5080. /* copy just the sections touched not the entire info
  5081. * since not all sections are valid as returned by
  5082. * update vsi params
  5083. */
  5084. ch->info.mapping_flags = ctxt.info.mapping_flags;
  5085. memcpy(&ch->info.queue_mapping,
  5086. &ctxt.info.queue_mapping, sizeof(ctxt.info.queue_mapping));
  5087. memcpy(&ch->info.tc_mapping, ctxt.info.tc_mapping,
  5088. sizeof(ctxt.info.tc_mapping));
  5089. return 0;
  5090. }
  5091. static int i40e_channel_config_bw(struct i40e_vsi *vsi, struct i40e_channel *ch,
  5092. u8 *bw_share)
  5093. {
  5094. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  5095. i40e_status ret;
  5096. int i;
  5097. bw_data.tc_valid_bits = ch->enabled_tc;
  5098. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  5099. bw_data.tc_bw_credits[i] = bw_share[i];
  5100. ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, ch->seid,
  5101. &bw_data, NULL);
  5102. if (ret) {
  5103. dev_info(&vsi->back->pdev->dev,
  5104. "Config VSI BW allocation per TC failed, aq_err: %d for new_vsi->seid %u\n",
  5105. vsi->back->hw.aq.asq_last_status, ch->seid);
  5106. return -EINVAL;
  5107. }
  5108. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  5109. ch->info.qs_handle[i] = bw_data.qs_handles[i];
  5110. return 0;
  5111. }
  5112. /**
  5113. * i40e_channel_config_tx_ring - config TX ring associated with new channel
  5114. * @pf: ptr to PF device
  5115. * @vsi: the VSI being setup
  5116. * @ch: ptr to channel structure
  5117. *
  5118. * Configure TX rings associated with channel (VSI) since queues are being
  5119. * from parent VSI.
  5120. **/
  5121. static int i40e_channel_config_tx_ring(struct i40e_pf *pf,
  5122. struct i40e_vsi *vsi,
  5123. struct i40e_channel *ch)
  5124. {
  5125. i40e_status ret;
  5126. int i;
  5127. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  5128. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  5129. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5130. if (ch->enabled_tc & BIT(i))
  5131. bw_share[i] = 1;
  5132. }
  5133. /* configure BW for new VSI */
  5134. ret = i40e_channel_config_bw(vsi, ch, bw_share);
  5135. if (ret) {
  5136. dev_info(&vsi->back->pdev->dev,
  5137. "Failed configuring TC map %d for channel (seid %u)\n",
  5138. ch->enabled_tc, ch->seid);
  5139. return ret;
  5140. }
  5141. for (i = 0; i < ch->num_queue_pairs; i++) {
  5142. struct i40e_ring *tx_ring, *rx_ring;
  5143. u16 pf_q;
  5144. pf_q = ch->base_queue + i;
  5145. /* Get to TX ring ptr of main VSI, for re-setup TX queue
  5146. * context
  5147. */
  5148. tx_ring = vsi->tx_rings[pf_q];
  5149. tx_ring->ch = ch;
  5150. /* Get the RX ring ptr */
  5151. rx_ring = vsi->rx_rings[pf_q];
  5152. rx_ring->ch = ch;
  5153. }
  5154. return 0;
  5155. }
  5156. /**
  5157. * i40e_setup_hw_channel - setup new channel
  5158. * @pf: ptr to PF device
  5159. * @vsi: the VSI being setup
  5160. * @ch: ptr to channel structure
  5161. * @uplink_seid: underlying HW switching element (VEB) ID
  5162. * @type: type of channel to be created (VMDq2/VF)
  5163. *
  5164. * Setup new channel (VSI) based on specified type (VMDq2/VF)
  5165. * and configures TX rings accordingly
  5166. **/
  5167. static inline int i40e_setup_hw_channel(struct i40e_pf *pf,
  5168. struct i40e_vsi *vsi,
  5169. struct i40e_channel *ch,
  5170. u16 uplink_seid, u8 type)
  5171. {
  5172. int ret;
  5173. ch->initialized = false;
  5174. ch->base_queue = vsi->next_base_queue;
  5175. ch->type = type;
  5176. /* Proceed with creation of channel (VMDq2) VSI */
  5177. ret = i40e_add_channel(pf, uplink_seid, ch);
  5178. if (ret) {
  5179. dev_info(&pf->pdev->dev,
  5180. "failed to add_channel using uplink_seid %u\n",
  5181. uplink_seid);
  5182. return ret;
  5183. }
  5184. /* Mark the successful creation of channel */
  5185. ch->initialized = true;
  5186. /* Reconfigure TX queues using QTX_CTL register */
  5187. ret = i40e_channel_config_tx_ring(pf, vsi, ch);
  5188. if (ret) {
  5189. dev_info(&pf->pdev->dev,
  5190. "failed to configure TX rings for channel %u\n",
  5191. ch->seid);
  5192. return ret;
  5193. }
  5194. /* update 'next_base_queue' */
  5195. vsi->next_base_queue = vsi->next_base_queue + ch->num_queue_pairs;
  5196. dev_dbg(&pf->pdev->dev,
  5197. "Added channel: vsi_seid %u, vsi_number %u, stat_counter_idx %u, num_queue_pairs %u, pf->next_base_queue %d\n",
  5198. ch->seid, ch->vsi_number, ch->stat_counter_idx,
  5199. ch->num_queue_pairs,
  5200. vsi->next_base_queue);
  5201. return ret;
  5202. }
  5203. /**
  5204. * i40e_setup_channel - setup new channel using uplink element
  5205. * @pf: ptr to PF device
  5206. * @type: type of channel to be created (VMDq2/VF)
  5207. * @uplink_seid: underlying HW switching element (VEB) ID
  5208. * @ch: ptr to channel structure
  5209. *
  5210. * Setup new channel (VSI) based on specified type (VMDq2/VF)
  5211. * and uplink switching element (uplink_seid)
  5212. **/
  5213. static bool i40e_setup_channel(struct i40e_pf *pf, struct i40e_vsi *vsi,
  5214. struct i40e_channel *ch)
  5215. {
  5216. u8 vsi_type;
  5217. u16 seid;
  5218. int ret;
  5219. if (vsi->type == I40E_VSI_MAIN) {
  5220. vsi_type = I40E_VSI_VMDQ2;
  5221. } else {
  5222. dev_err(&pf->pdev->dev, "unsupported parent vsi type(%d)\n",
  5223. vsi->type);
  5224. return false;
  5225. }
  5226. /* underlying switching element */
  5227. seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  5228. /* create channel (VSI), configure TX rings */
  5229. ret = i40e_setup_hw_channel(pf, vsi, ch, seid, vsi_type);
  5230. if (ret) {
  5231. dev_err(&pf->pdev->dev, "failed to setup hw_channel\n");
  5232. return false;
  5233. }
  5234. return ch->initialized ? true : false;
  5235. }
  5236. /**
  5237. * i40e_validate_and_set_switch_mode - sets up switch mode correctly
  5238. * @vsi: ptr to VSI which has PF backing
  5239. *
  5240. * Sets up switch mode correctly if it needs to be changed and perform
  5241. * what are allowed modes.
  5242. **/
  5243. static int i40e_validate_and_set_switch_mode(struct i40e_vsi *vsi)
  5244. {
  5245. u8 mode;
  5246. struct i40e_pf *pf = vsi->back;
  5247. struct i40e_hw *hw = &pf->hw;
  5248. int ret;
  5249. ret = i40e_get_capabilities(pf, i40e_aqc_opc_list_dev_capabilities);
  5250. if (ret)
  5251. return -EINVAL;
  5252. if (hw->dev_caps.switch_mode) {
  5253. /* if switch mode is set, support mode2 (non-tunneled for
  5254. * cloud filter) for now
  5255. */
  5256. u32 switch_mode = hw->dev_caps.switch_mode &
  5257. I40E_SWITCH_MODE_MASK;
  5258. if (switch_mode >= I40E_CLOUD_FILTER_MODE1) {
  5259. if (switch_mode == I40E_CLOUD_FILTER_MODE2)
  5260. return 0;
  5261. dev_err(&pf->pdev->dev,
  5262. "Invalid switch_mode (%d), only non-tunneled mode for cloud filter is supported\n",
  5263. hw->dev_caps.switch_mode);
  5264. return -EINVAL;
  5265. }
  5266. }
  5267. /* Set Bit 7 to be valid */
  5268. mode = I40E_AQ_SET_SWITCH_BIT7_VALID;
  5269. /* Set L4type for TCP support */
  5270. mode |= I40E_AQ_SET_SWITCH_L4_TYPE_TCP;
  5271. /* Set cloud filter mode */
  5272. mode |= I40E_AQ_SET_SWITCH_MODE_NON_TUNNEL;
  5273. /* Prep mode field for set_switch_config */
  5274. ret = i40e_aq_set_switch_config(hw, pf->last_sw_conf_flags,
  5275. pf->last_sw_conf_valid_flags,
  5276. mode, NULL);
  5277. if (ret && hw->aq.asq_last_status != I40E_AQ_RC_ESRCH)
  5278. dev_err(&pf->pdev->dev,
  5279. "couldn't set switch config bits, err %s aq_err %s\n",
  5280. i40e_stat_str(hw, ret),
  5281. i40e_aq_str(hw,
  5282. hw->aq.asq_last_status));
  5283. return ret;
  5284. }
  5285. /**
  5286. * i40e_create_queue_channel - function to create channel
  5287. * @vsi: VSI to be configured
  5288. * @ch: ptr to channel (it contains channel specific params)
  5289. *
  5290. * This function creates channel (VSI) using num_queues specified by user,
  5291. * reconfigs RSS if needed.
  5292. **/
  5293. int i40e_create_queue_channel(struct i40e_vsi *vsi,
  5294. struct i40e_channel *ch)
  5295. {
  5296. struct i40e_pf *pf = vsi->back;
  5297. bool reconfig_rss;
  5298. int err;
  5299. if (!ch)
  5300. return -EINVAL;
  5301. if (!ch->num_queue_pairs) {
  5302. dev_err(&pf->pdev->dev, "Invalid num_queues requested: %d\n",
  5303. ch->num_queue_pairs);
  5304. return -EINVAL;
  5305. }
  5306. /* validate user requested num_queues for channel */
  5307. err = i40e_validate_num_queues(pf, ch->num_queue_pairs, vsi,
  5308. &reconfig_rss);
  5309. if (err) {
  5310. dev_info(&pf->pdev->dev, "Failed to validate num_queues (%d)\n",
  5311. ch->num_queue_pairs);
  5312. return -EINVAL;
  5313. }
  5314. /* By default we are in VEPA mode, if this is the first VF/VMDq
  5315. * VSI to be added switch to VEB mode.
  5316. */
  5317. if ((!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) ||
  5318. (!i40e_is_any_channel(vsi))) {
  5319. if (!is_power_of_2(vsi->tc_config.tc_info[0].qcount)) {
  5320. dev_dbg(&pf->pdev->dev,
  5321. "Failed to create channel. Override queues (%u) not power of 2\n",
  5322. vsi->tc_config.tc_info[0].qcount);
  5323. return -EINVAL;
  5324. }
  5325. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  5326. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  5327. if (vsi->type == I40E_VSI_MAIN) {
  5328. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  5329. i40e_do_reset(pf, I40E_PF_RESET_FLAG,
  5330. true);
  5331. else
  5332. i40e_do_reset_safe(pf,
  5333. I40E_PF_RESET_FLAG);
  5334. }
  5335. }
  5336. /* now onwards for main VSI, number of queues will be value
  5337. * of TC0's queue count
  5338. */
  5339. }
  5340. /* By this time, vsi->cnt_q_avail shall be set to non-zero and
  5341. * it should be more than num_queues
  5342. */
  5343. if (!vsi->cnt_q_avail || vsi->cnt_q_avail < ch->num_queue_pairs) {
  5344. dev_dbg(&pf->pdev->dev,
  5345. "Error: cnt_q_avail (%u) less than num_queues %d\n",
  5346. vsi->cnt_q_avail, ch->num_queue_pairs);
  5347. return -EINVAL;
  5348. }
  5349. /* reconfig_rss only if vsi type is MAIN_VSI */
  5350. if (reconfig_rss && (vsi->type == I40E_VSI_MAIN)) {
  5351. err = i40e_vsi_reconfig_rss(vsi, ch->num_queue_pairs);
  5352. if (err) {
  5353. dev_info(&pf->pdev->dev,
  5354. "Error: unable to reconfig rss for num_queues (%u)\n",
  5355. ch->num_queue_pairs);
  5356. return -EINVAL;
  5357. }
  5358. }
  5359. if (!i40e_setup_channel(pf, vsi, ch)) {
  5360. dev_info(&pf->pdev->dev, "Failed to setup channel\n");
  5361. return -EINVAL;
  5362. }
  5363. dev_info(&pf->pdev->dev,
  5364. "Setup channel (id:%u) utilizing num_queues %d\n",
  5365. ch->seid, ch->num_queue_pairs);
  5366. /* configure VSI for BW limit */
  5367. if (ch->max_tx_rate) {
  5368. u64 credits = ch->max_tx_rate;
  5369. if (i40e_set_bw_limit(vsi, ch->seid, ch->max_tx_rate))
  5370. return -EINVAL;
  5371. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  5372. dev_dbg(&pf->pdev->dev,
  5373. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  5374. ch->max_tx_rate,
  5375. credits,
  5376. ch->seid);
  5377. }
  5378. /* in case of VF, this will be main SRIOV VSI */
  5379. ch->parent_vsi = vsi;
  5380. /* and update main_vsi's count for queue_available to use */
  5381. vsi->cnt_q_avail -= ch->num_queue_pairs;
  5382. return 0;
  5383. }
  5384. /**
  5385. * i40e_configure_queue_channels - Add queue channel for the given TCs
  5386. * @vsi: VSI to be configured
  5387. *
  5388. * Configures queue channel mapping to the given TCs
  5389. **/
  5390. static int i40e_configure_queue_channels(struct i40e_vsi *vsi)
  5391. {
  5392. struct i40e_channel *ch;
  5393. u64 max_rate = 0;
  5394. int ret = 0, i;
  5395. /* Create app vsi with the TCs. Main VSI with TC0 is already set up */
  5396. vsi->tc_seid_map[0] = vsi->seid;
  5397. for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5398. if (vsi->tc_config.enabled_tc & BIT(i)) {
  5399. ch = kzalloc(sizeof(*ch), GFP_KERNEL);
  5400. if (!ch) {
  5401. ret = -ENOMEM;
  5402. goto err_free;
  5403. }
  5404. INIT_LIST_HEAD(&ch->list);
  5405. ch->num_queue_pairs =
  5406. vsi->tc_config.tc_info[i].qcount;
  5407. ch->base_queue =
  5408. vsi->tc_config.tc_info[i].qoffset;
  5409. /* Bandwidth limit through tc interface is in bytes/s,
  5410. * change to Mbit/s
  5411. */
  5412. max_rate = vsi->mqprio_qopt.max_rate[i];
  5413. do_div(max_rate, I40E_BW_MBPS_DIVISOR);
  5414. ch->max_tx_rate = max_rate;
  5415. list_add_tail(&ch->list, &vsi->ch_list);
  5416. ret = i40e_create_queue_channel(vsi, ch);
  5417. if (ret) {
  5418. dev_err(&vsi->back->pdev->dev,
  5419. "Failed creating queue channel with TC%d: queues %d\n",
  5420. i, ch->num_queue_pairs);
  5421. goto err_free;
  5422. }
  5423. vsi->tc_seid_map[i] = ch->seid;
  5424. }
  5425. }
  5426. return ret;
  5427. err_free:
  5428. i40e_remove_queue_channels(vsi);
  5429. return ret;
  5430. }
  5431. /**
  5432. * i40e_veb_config_tc - Configure TCs for given VEB
  5433. * @veb: given VEB
  5434. * @enabled_tc: TC bitmap
  5435. *
  5436. * Configures given TC bitmap for VEB (switching) element
  5437. **/
  5438. int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
  5439. {
  5440. struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
  5441. struct i40e_pf *pf = veb->pf;
  5442. int ret = 0;
  5443. int i;
  5444. /* No TCs or already enabled TCs just return */
  5445. if (!enabled_tc || veb->enabled_tc == enabled_tc)
  5446. return ret;
  5447. bw_data.tc_valid_bits = enabled_tc;
  5448. /* bw_data.absolute_credits is not set (relative) */
  5449. /* Enable ETS TCs with equal BW Share for now */
  5450. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5451. if (enabled_tc & BIT(i))
  5452. bw_data.tc_bw_share_credits[i] = 1;
  5453. }
  5454. ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
  5455. &bw_data, NULL);
  5456. if (ret) {
  5457. dev_info(&pf->pdev->dev,
  5458. "VEB bw config failed, err %s aq_err %s\n",
  5459. i40e_stat_str(&pf->hw, ret),
  5460. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5461. goto out;
  5462. }
  5463. /* Update the BW information */
  5464. ret = i40e_veb_get_bw_info(veb);
  5465. if (ret) {
  5466. dev_info(&pf->pdev->dev,
  5467. "Failed getting veb bw config, err %s aq_err %s\n",
  5468. i40e_stat_str(&pf->hw, ret),
  5469. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5470. }
  5471. out:
  5472. return ret;
  5473. }
  5474. #ifdef CONFIG_I40E_DCB
  5475. /**
  5476. * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
  5477. * @pf: PF struct
  5478. *
  5479. * Reconfigure VEB/VSIs on a given PF; it is assumed that
  5480. * the caller would've quiesce all the VSIs before calling
  5481. * this function
  5482. **/
  5483. static void i40e_dcb_reconfigure(struct i40e_pf *pf)
  5484. {
  5485. u8 tc_map = 0;
  5486. int ret;
  5487. u8 v;
  5488. /* Enable the TCs available on PF to all VEBs */
  5489. tc_map = i40e_pf_get_tc_map(pf);
  5490. for (v = 0; v < I40E_MAX_VEB; v++) {
  5491. if (!pf->veb[v])
  5492. continue;
  5493. ret = i40e_veb_config_tc(pf->veb[v], tc_map);
  5494. if (ret) {
  5495. dev_info(&pf->pdev->dev,
  5496. "Failed configuring TC for VEB seid=%d\n",
  5497. pf->veb[v]->seid);
  5498. /* Will try to configure as many components */
  5499. }
  5500. }
  5501. /* Update each VSI */
  5502. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5503. if (!pf->vsi[v])
  5504. continue;
  5505. /* - Enable all TCs for the LAN VSI
  5506. * - For all others keep them at TC0 for now
  5507. */
  5508. if (v == pf->lan_vsi)
  5509. tc_map = i40e_pf_get_tc_map(pf);
  5510. else
  5511. tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
  5512. ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
  5513. if (ret) {
  5514. dev_info(&pf->pdev->dev,
  5515. "Failed configuring TC for VSI seid=%d\n",
  5516. pf->vsi[v]->seid);
  5517. /* Will try to configure as many components */
  5518. } else {
  5519. /* Re-configure VSI vectors based on updated TC map */
  5520. i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
  5521. if (pf->vsi[v]->netdev)
  5522. i40e_dcbnl_set_all(pf->vsi[v]);
  5523. }
  5524. }
  5525. }
  5526. /**
  5527. * i40e_resume_port_tx - Resume port Tx
  5528. * @pf: PF struct
  5529. *
  5530. * Resume a port's Tx and issue a PF reset in case of failure to
  5531. * resume.
  5532. **/
  5533. static int i40e_resume_port_tx(struct i40e_pf *pf)
  5534. {
  5535. struct i40e_hw *hw = &pf->hw;
  5536. int ret;
  5537. ret = i40e_aq_resume_port_tx(hw, NULL);
  5538. if (ret) {
  5539. dev_info(&pf->pdev->dev,
  5540. "Resume Port Tx failed, err %s aq_err %s\n",
  5541. i40e_stat_str(&pf->hw, ret),
  5542. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5543. /* Schedule PF reset to recover */
  5544. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  5545. i40e_service_event_schedule(pf);
  5546. }
  5547. return ret;
  5548. }
  5549. /**
  5550. * i40e_init_pf_dcb - Initialize DCB configuration
  5551. * @pf: PF being configured
  5552. *
  5553. * Query the current DCB configuration and cache it
  5554. * in the hardware structure
  5555. **/
  5556. static int i40e_init_pf_dcb(struct i40e_pf *pf)
  5557. {
  5558. struct i40e_hw *hw = &pf->hw;
  5559. int err = 0;
  5560. /* Do not enable DCB for SW1 and SW2 images even if the FW is capable
  5561. * Also do not enable DCBx if FW LLDP agent is disabled
  5562. */
  5563. if ((pf->hw_features & I40E_HW_NO_DCB_SUPPORT) ||
  5564. (pf->flags & I40E_FLAG_DISABLE_FW_LLDP))
  5565. goto out;
  5566. /* Get the initial DCB configuration */
  5567. err = i40e_init_dcb(hw);
  5568. if (!err) {
  5569. /* Device/Function is not DCBX capable */
  5570. if ((!hw->func_caps.dcb) ||
  5571. (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
  5572. dev_info(&pf->pdev->dev,
  5573. "DCBX offload is not supported or is disabled for this PF.\n");
  5574. } else {
  5575. /* When status is not DISABLED then DCBX in FW */
  5576. pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
  5577. DCB_CAP_DCBX_VER_IEEE;
  5578. pf->flags |= I40E_FLAG_DCB_CAPABLE;
  5579. /* Enable DCB tagging only when more than one TC
  5580. * or explicitly disable if only one TC
  5581. */
  5582. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  5583. pf->flags |= I40E_FLAG_DCB_ENABLED;
  5584. else
  5585. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  5586. dev_dbg(&pf->pdev->dev,
  5587. "DCBX offload is supported for this PF.\n");
  5588. }
  5589. } else if (pf->hw.aq.asq_last_status == I40E_AQ_RC_EPERM) {
  5590. dev_info(&pf->pdev->dev, "FW LLDP disabled for this PF.\n");
  5591. pf->flags |= I40E_FLAG_DISABLE_FW_LLDP;
  5592. } else {
  5593. dev_info(&pf->pdev->dev,
  5594. "Query for DCB configuration failed, err %s aq_err %s\n",
  5595. i40e_stat_str(&pf->hw, err),
  5596. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5597. }
  5598. out:
  5599. return err;
  5600. }
  5601. #endif /* CONFIG_I40E_DCB */
  5602. #define SPEED_SIZE 14
  5603. #define FC_SIZE 8
  5604. /**
  5605. * i40e_print_link_message - print link up or down
  5606. * @vsi: the VSI for which link needs a message
  5607. * @isup: true of link is up, false otherwise
  5608. */
  5609. void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
  5610. {
  5611. enum i40e_aq_link_speed new_speed;
  5612. struct i40e_pf *pf = vsi->back;
  5613. char *speed = "Unknown";
  5614. char *fc = "Unknown";
  5615. char *fec = "";
  5616. char *req_fec = "";
  5617. char *an = "";
  5618. new_speed = pf->hw.phy.link_info.link_speed;
  5619. if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed))
  5620. return;
  5621. vsi->current_isup = isup;
  5622. vsi->current_speed = new_speed;
  5623. if (!isup) {
  5624. netdev_info(vsi->netdev, "NIC Link is Down\n");
  5625. return;
  5626. }
  5627. /* Warn user if link speed on NPAR enabled partition is not at
  5628. * least 10GB
  5629. */
  5630. if (pf->hw.func_caps.npar_enable &&
  5631. (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
  5632. pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
  5633. netdev_warn(vsi->netdev,
  5634. "The partition detected link speed that is less than 10Gbps\n");
  5635. switch (pf->hw.phy.link_info.link_speed) {
  5636. case I40E_LINK_SPEED_40GB:
  5637. speed = "40 G";
  5638. break;
  5639. case I40E_LINK_SPEED_20GB:
  5640. speed = "20 G";
  5641. break;
  5642. case I40E_LINK_SPEED_25GB:
  5643. speed = "25 G";
  5644. break;
  5645. case I40E_LINK_SPEED_10GB:
  5646. speed = "10 G";
  5647. break;
  5648. case I40E_LINK_SPEED_1GB:
  5649. speed = "1000 M";
  5650. break;
  5651. case I40E_LINK_SPEED_100MB:
  5652. speed = "100 M";
  5653. break;
  5654. default:
  5655. break;
  5656. }
  5657. switch (pf->hw.fc.current_mode) {
  5658. case I40E_FC_FULL:
  5659. fc = "RX/TX";
  5660. break;
  5661. case I40E_FC_TX_PAUSE:
  5662. fc = "TX";
  5663. break;
  5664. case I40E_FC_RX_PAUSE:
  5665. fc = "RX";
  5666. break;
  5667. default:
  5668. fc = "None";
  5669. break;
  5670. }
  5671. if (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) {
  5672. req_fec = ", Requested FEC: None";
  5673. fec = ", FEC: None";
  5674. an = ", Autoneg: False";
  5675. if (pf->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED)
  5676. an = ", Autoneg: True";
  5677. if (pf->hw.phy.link_info.fec_info &
  5678. I40E_AQ_CONFIG_FEC_KR_ENA)
  5679. fec = ", FEC: CL74 FC-FEC/BASE-R";
  5680. else if (pf->hw.phy.link_info.fec_info &
  5681. I40E_AQ_CONFIG_FEC_RS_ENA)
  5682. fec = ", FEC: CL108 RS-FEC";
  5683. /* 'CL108 RS-FEC' should be displayed when RS is requested, or
  5684. * both RS and FC are requested
  5685. */
  5686. if (vsi->back->hw.phy.link_info.req_fec_info &
  5687. (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS)) {
  5688. if (vsi->back->hw.phy.link_info.req_fec_info &
  5689. I40E_AQ_REQUEST_FEC_RS)
  5690. req_fec = ", Requested FEC: CL108 RS-FEC";
  5691. else
  5692. req_fec = ", Requested FEC: CL74 FC-FEC/BASE-R";
  5693. }
  5694. }
  5695. netdev_info(vsi->netdev, "NIC Link is Up, %sbps Full Duplex%s%s%s, Flow Control: %s\n",
  5696. speed, req_fec, fec, an, fc);
  5697. }
  5698. /**
  5699. * i40e_up_complete - Finish the last steps of bringing up a connection
  5700. * @vsi: the VSI being configured
  5701. **/
  5702. static int i40e_up_complete(struct i40e_vsi *vsi)
  5703. {
  5704. struct i40e_pf *pf = vsi->back;
  5705. int err;
  5706. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  5707. i40e_vsi_configure_msix(vsi);
  5708. else
  5709. i40e_configure_msi_and_legacy(vsi);
  5710. /* start rings */
  5711. err = i40e_vsi_start_rings(vsi);
  5712. if (err)
  5713. return err;
  5714. clear_bit(__I40E_VSI_DOWN, vsi->state);
  5715. i40e_napi_enable_all(vsi);
  5716. i40e_vsi_enable_irq(vsi);
  5717. if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
  5718. (vsi->netdev)) {
  5719. i40e_print_link_message(vsi, true);
  5720. netif_tx_start_all_queues(vsi->netdev);
  5721. netif_carrier_on(vsi->netdev);
  5722. }
  5723. /* replay FDIR SB filters */
  5724. if (vsi->type == I40E_VSI_FDIR) {
  5725. /* reset fd counters */
  5726. pf->fd_add_err = 0;
  5727. pf->fd_atr_cnt = 0;
  5728. i40e_fdir_filter_restore(vsi);
  5729. }
  5730. /* On the next run of the service_task, notify any clients of the new
  5731. * opened netdev
  5732. */
  5733. set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
  5734. i40e_service_event_schedule(pf);
  5735. return 0;
  5736. }
  5737. /**
  5738. * i40e_vsi_reinit_locked - Reset the VSI
  5739. * @vsi: the VSI being configured
  5740. *
  5741. * Rebuild the ring structs after some configuration
  5742. * has changed, e.g. MTU size.
  5743. **/
  5744. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
  5745. {
  5746. struct i40e_pf *pf = vsi->back;
  5747. WARN_ON(in_interrupt());
  5748. while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state))
  5749. usleep_range(1000, 2000);
  5750. i40e_down(vsi);
  5751. i40e_up(vsi);
  5752. clear_bit(__I40E_CONFIG_BUSY, pf->state);
  5753. }
  5754. /**
  5755. * i40e_up - Bring the connection back up after being down
  5756. * @vsi: the VSI being configured
  5757. **/
  5758. int i40e_up(struct i40e_vsi *vsi)
  5759. {
  5760. int err;
  5761. err = i40e_vsi_configure(vsi);
  5762. if (!err)
  5763. err = i40e_up_complete(vsi);
  5764. return err;
  5765. }
  5766. /**
  5767. * i40e_force_link_state - Force the link status
  5768. * @pf: board private structure
  5769. * @is_up: whether the link state should be forced up or down
  5770. **/
  5771. static i40e_status i40e_force_link_state(struct i40e_pf *pf, bool is_up)
  5772. {
  5773. struct i40e_aq_get_phy_abilities_resp abilities;
  5774. struct i40e_aq_set_phy_config config = {0};
  5775. struct i40e_hw *hw = &pf->hw;
  5776. i40e_status err;
  5777. u64 mask;
  5778. u8 speed;
  5779. /* Card might've been put in an unstable state by other drivers
  5780. * and applications, which causes incorrect speed values being
  5781. * set on startup. In order to clear speed registers, we call
  5782. * get_phy_capabilities twice, once to get initial state of
  5783. * available speeds, and once to get current PHY config.
  5784. */
  5785. err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities,
  5786. NULL);
  5787. if (err) {
  5788. dev_err(&pf->pdev->dev,
  5789. "failed to get phy cap., ret = %s last_status = %s\n",
  5790. i40e_stat_str(hw, err),
  5791. i40e_aq_str(hw, hw->aq.asq_last_status));
  5792. return err;
  5793. }
  5794. speed = abilities.link_speed;
  5795. /* Get the current phy config */
  5796. err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
  5797. NULL);
  5798. if (err) {
  5799. dev_err(&pf->pdev->dev,
  5800. "failed to get phy cap., ret = %s last_status = %s\n",
  5801. i40e_stat_str(hw, err),
  5802. i40e_aq_str(hw, hw->aq.asq_last_status));
  5803. return err;
  5804. }
  5805. /* If link needs to go up, but was not forced to go down,
  5806. * and its speed values are OK, no need for a flap
  5807. */
  5808. if (is_up && abilities.phy_type != 0 && abilities.link_speed != 0)
  5809. return I40E_SUCCESS;
  5810. /* To force link we need to set bits for all supported PHY types,
  5811. * but there are now more than 32, so we need to split the bitmap
  5812. * across two fields.
  5813. */
  5814. mask = I40E_PHY_TYPES_BITMASK;
  5815. config.phy_type = is_up ? cpu_to_le32((u32)(mask & 0xffffffff)) : 0;
  5816. config.phy_type_ext = is_up ? (u8)((mask >> 32) & 0xff) : 0;
  5817. /* Copy the old settings, except of phy_type */
  5818. config.abilities = abilities.abilities;
  5819. if (abilities.link_speed != 0)
  5820. config.link_speed = abilities.link_speed;
  5821. else
  5822. config.link_speed = speed;
  5823. config.eee_capability = abilities.eee_capability;
  5824. config.eeer = abilities.eeer_val;
  5825. config.low_power_ctrl = abilities.d3_lpan;
  5826. config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
  5827. I40E_AQ_PHY_FEC_CONFIG_MASK;
  5828. err = i40e_aq_set_phy_config(hw, &config, NULL);
  5829. if (err) {
  5830. dev_err(&pf->pdev->dev,
  5831. "set phy config ret = %s last_status = %s\n",
  5832. i40e_stat_str(&pf->hw, err),
  5833. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5834. return err;
  5835. }
  5836. /* Update the link info */
  5837. err = i40e_update_link_info(hw);
  5838. if (err) {
  5839. /* Wait a little bit (on 40G cards it sometimes takes a really
  5840. * long time for link to come back from the atomic reset)
  5841. * and try once more
  5842. */
  5843. msleep(1000);
  5844. i40e_update_link_info(hw);
  5845. }
  5846. i40e_aq_set_link_restart_an(hw, true, NULL);
  5847. return I40E_SUCCESS;
  5848. }
  5849. /**
  5850. * i40e_down - Shutdown the connection processing
  5851. * @vsi: the VSI being stopped
  5852. **/
  5853. void i40e_down(struct i40e_vsi *vsi)
  5854. {
  5855. int i;
  5856. /* It is assumed that the caller of this function
  5857. * sets the vsi->state __I40E_VSI_DOWN bit.
  5858. */
  5859. if (vsi->netdev) {
  5860. netif_carrier_off(vsi->netdev);
  5861. netif_tx_disable(vsi->netdev);
  5862. }
  5863. i40e_vsi_disable_irq(vsi);
  5864. i40e_vsi_stop_rings(vsi);
  5865. if (vsi->type == I40E_VSI_MAIN &&
  5866. vsi->back->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED)
  5867. i40e_force_link_state(vsi->back, false);
  5868. i40e_napi_disable_all(vsi);
  5869. for (i = 0; i < vsi->num_queue_pairs; i++) {
  5870. i40e_clean_tx_ring(vsi->tx_rings[i]);
  5871. if (i40e_enabled_xdp_vsi(vsi))
  5872. i40e_clean_tx_ring(vsi->xdp_rings[i]);
  5873. i40e_clean_rx_ring(vsi->rx_rings[i]);
  5874. }
  5875. }
  5876. /**
  5877. * i40e_validate_mqprio_qopt- validate queue mapping info
  5878. * @vsi: the VSI being configured
  5879. * @mqprio_qopt: queue parametrs
  5880. **/
  5881. static int i40e_validate_mqprio_qopt(struct i40e_vsi *vsi,
  5882. struct tc_mqprio_qopt_offload *mqprio_qopt)
  5883. {
  5884. u64 sum_max_rate = 0;
  5885. u64 max_rate = 0;
  5886. int i;
  5887. if (mqprio_qopt->qopt.offset[0] != 0 ||
  5888. mqprio_qopt->qopt.num_tc < 1 ||
  5889. mqprio_qopt->qopt.num_tc > I40E_MAX_TRAFFIC_CLASS)
  5890. return -EINVAL;
  5891. for (i = 0; ; i++) {
  5892. if (!mqprio_qopt->qopt.count[i])
  5893. return -EINVAL;
  5894. if (mqprio_qopt->min_rate[i]) {
  5895. dev_err(&vsi->back->pdev->dev,
  5896. "Invalid min tx rate (greater than 0) specified\n");
  5897. return -EINVAL;
  5898. }
  5899. max_rate = mqprio_qopt->max_rate[i];
  5900. do_div(max_rate, I40E_BW_MBPS_DIVISOR);
  5901. sum_max_rate += max_rate;
  5902. if (i >= mqprio_qopt->qopt.num_tc - 1)
  5903. break;
  5904. if (mqprio_qopt->qopt.offset[i + 1] !=
  5905. (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i]))
  5906. return -EINVAL;
  5907. }
  5908. if (vsi->num_queue_pairs <
  5909. (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i])) {
  5910. return -EINVAL;
  5911. }
  5912. if (sum_max_rate > i40e_get_link_speed(vsi)) {
  5913. dev_err(&vsi->back->pdev->dev,
  5914. "Invalid max tx rate specified\n");
  5915. return -EINVAL;
  5916. }
  5917. return 0;
  5918. }
  5919. /**
  5920. * i40e_vsi_set_default_tc_config - set default values for tc configuration
  5921. * @vsi: the VSI being configured
  5922. **/
  5923. static void i40e_vsi_set_default_tc_config(struct i40e_vsi *vsi)
  5924. {
  5925. u16 qcount;
  5926. int i;
  5927. /* Only TC0 is enabled */
  5928. vsi->tc_config.numtc = 1;
  5929. vsi->tc_config.enabled_tc = 1;
  5930. qcount = min_t(int, vsi->alloc_queue_pairs,
  5931. i40e_pf_get_max_q_per_tc(vsi->back));
  5932. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5933. /* For the TC that is not enabled set the offset to to default
  5934. * queue and allocate one queue for the given TC.
  5935. */
  5936. vsi->tc_config.tc_info[i].qoffset = 0;
  5937. if (i == 0)
  5938. vsi->tc_config.tc_info[i].qcount = qcount;
  5939. else
  5940. vsi->tc_config.tc_info[i].qcount = 1;
  5941. vsi->tc_config.tc_info[i].netdev_tc = 0;
  5942. }
  5943. }
  5944. /**
  5945. * i40e_setup_tc - configure multiple traffic classes
  5946. * @netdev: net device to configure
  5947. * @type_data: tc offload data
  5948. **/
  5949. static int i40e_setup_tc(struct net_device *netdev, void *type_data)
  5950. {
  5951. struct tc_mqprio_qopt_offload *mqprio_qopt = type_data;
  5952. struct i40e_netdev_priv *np = netdev_priv(netdev);
  5953. struct i40e_vsi *vsi = np->vsi;
  5954. struct i40e_pf *pf = vsi->back;
  5955. u8 enabled_tc = 0, num_tc, hw;
  5956. bool need_reset = false;
  5957. int old_queue_pairs;
  5958. int ret = -EINVAL;
  5959. u16 mode;
  5960. int i;
  5961. old_queue_pairs = vsi->num_queue_pairs;
  5962. num_tc = mqprio_qopt->qopt.num_tc;
  5963. hw = mqprio_qopt->qopt.hw;
  5964. mode = mqprio_qopt->mode;
  5965. if (!hw) {
  5966. pf->flags &= ~I40E_FLAG_TC_MQPRIO;
  5967. memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt));
  5968. goto config_tc;
  5969. }
  5970. /* Check if MFP enabled */
  5971. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  5972. netdev_info(netdev,
  5973. "Configuring TC not supported in MFP mode\n");
  5974. return ret;
  5975. }
  5976. switch (mode) {
  5977. case TC_MQPRIO_MODE_DCB:
  5978. pf->flags &= ~I40E_FLAG_TC_MQPRIO;
  5979. /* Check if DCB enabled to continue */
  5980. if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  5981. netdev_info(netdev,
  5982. "DCB is not enabled for adapter\n");
  5983. return ret;
  5984. }
  5985. /* Check whether tc count is within enabled limit */
  5986. if (num_tc > i40e_pf_get_num_tc(pf)) {
  5987. netdev_info(netdev,
  5988. "TC count greater than enabled on link for adapter\n");
  5989. return ret;
  5990. }
  5991. break;
  5992. case TC_MQPRIO_MODE_CHANNEL:
  5993. if (pf->flags & I40E_FLAG_DCB_ENABLED) {
  5994. netdev_info(netdev,
  5995. "Full offload of TC Mqprio options is not supported when DCB is enabled\n");
  5996. return ret;
  5997. }
  5998. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  5999. return ret;
  6000. ret = i40e_validate_mqprio_qopt(vsi, mqprio_qopt);
  6001. if (ret)
  6002. return ret;
  6003. memcpy(&vsi->mqprio_qopt, mqprio_qopt,
  6004. sizeof(*mqprio_qopt));
  6005. pf->flags |= I40E_FLAG_TC_MQPRIO;
  6006. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  6007. break;
  6008. default:
  6009. return -EINVAL;
  6010. }
  6011. config_tc:
  6012. /* Generate TC map for number of tc requested */
  6013. for (i = 0; i < num_tc; i++)
  6014. enabled_tc |= BIT(i);
  6015. /* Requesting same TC configuration as already enabled */
  6016. if (enabled_tc == vsi->tc_config.enabled_tc &&
  6017. mode != TC_MQPRIO_MODE_CHANNEL)
  6018. return 0;
  6019. /* Quiesce VSI queues */
  6020. i40e_quiesce_vsi(vsi);
  6021. if (!hw && !(pf->flags & I40E_FLAG_TC_MQPRIO))
  6022. i40e_remove_queue_channels(vsi);
  6023. /* Configure VSI for enabled TCs */
  6024. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  6025. if (ret) {
  6026. netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
  6027. vsi->seid);
  6028. need_reset = true;
  6029. goto exit;
  6030. }
  6031. if (pf->flags & I40E_FLAG_TC_MQPRIO) {
  6032. if (vsi->mqprio_qopt.max_rate[0]) {
  6033. u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
  6034. do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
  6035. ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
  6036. if (!ret) {
  6037. u64 credits = max_tx_rate;
  6038. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  6039. dev_dbg(&vsi->back->pdev->dev,
  6040. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  6041. max_tx_rate,
  6042. credits,
  6043. vsi->seid);
  6044. } else {
  6045. need_reset = true;
  6046. goto exit;
  6047. }
  6048. }
  6049. ret = i40e_configure_queue_channels(vsi);
  6050. if (ret) {
  6051. vsi->num_queue_pairs = old_queue_pairs;
  6052. netdev_info(netdev,
  6053. "Failed configuring queue channels\n");
  6054. need_reset = true;
  6055. goto exit;
  6056. }
  6057. }
  6058. exit:
  6059. /* Reset the configuration data to defaults, only TC0 is enabled */
  6060. if (need_reset) {
  6061. i40e_vsi_set_default_tc_config(vsi);
  6062. need_reset = false;
  6063. }
  6064. /* Unquiesce VSI */
  6065. i40e_unquiesce_vsi(vsi);
  6066. return ret;
  6067. }
  6068. /**
  6069. * i40e_set_cld_element - sets cloud filter element data
  6070. * @filter: cloud filter rule
  6071. * @cld: ptr to cloud filter element data
  6072. *
  6073. * This is helper function to copy data into cloud filter element
  6074. **/
  6075. static inline void
  6076. i40e_set_cld_element(struct i40e_cloud_filter *filter,
  6077. struct i40e_aqc_cloud_filters_element_data *cld)
  6078. {
  6079. int i, j;
  6080. u32 ipa;
  6081. memset(cld, 0, sizeof(*cld));
  6082. ether_addr_copy(cld->outer_mac, filter->dst_mac);
  6083. ether_addr_copy(cld->inner_mac, filter->src_mac);
  6084. if (filter->n_proto != ETH_P_IP && filter->n_proto != ETH_P_IPV6)
  6085. return;
  6086. if (filter->n_proto == ETH_P_IPV6) {
  6087. #define IPV6_MAX_INDEX (ARRAY_SIZE(filter->dst_ipv6) - 1)
  6088. for (i = 0, j = 0; i < ARRAY_SIZE(filter->dst_ipv6);
  6089. i++, j += 2) {
  6090. ipa = be32_to_cpu(filter->dst_ipv6[IPV6_MAX_INDEX - i]);
  6091. ipa = cpu_to_le32(ipa);
  6092. memcpy(&cld->ipaddr.raw_v6.data[j], &ipa, sizeof(ipa));
  6093. }
  6094. } else {
  6095. ipa = be32_to_cpu(filter->dst_ipv4);
  6096. memcpy(&cld->ipaddr.v4.data, &ipa, sizeof(ipa));
  6097. }
  6098. cld->inner_vlan = cpu_to_le16(ntohs(filter->vlan_id));
  6099. /* tenant_id is not supported by FW now, once the support is enabled
  6100. * fill the cld->tenant_id with cpu_to_le32(filter->tenant_id)
  6101. */
  6102. if (filter->tenant_id)
  6103. return;
  6104. }
  6105. /**
  6106. * i40e_add_del_cloud_filter - Add/del cloud filter
  6107. * @vsi: pointer to VSI
  6108. * @filter: cloud filter rule
  6109. * @add: if true, add, if false, delete
  6110. *
  6111. * Add or delete a cloud filter for a specific flow spec.
  6112. * Returns 0 if the filter were successfully added.
  6113. **/
  6114. int i40e_add_del_cloud_filter(struct i40e_vsi *vsi,
  6115. struct i40e_cloud_filter *filter, bool add)
  6116. {
  6117. struct i40e_aqc_cloud_filters_element_data cld_filter;
  6118. struct i40e_pf *pf = vsi->back;
  6119. int ret;
  6120. static const u16 flag_table[128] = {
  6121. [I40E_CLOUD_FILTER_FLAGS_OMAC] =
  6122. I40E_AQC_ADD_CLOUD_FILTER_OMAC,
  6123. [I40E_CLOUD_FILTER_FLAGS_IMAC] =
  6124. I40E_AQC_ADD_CLOUD_FILTER_IMAC,
  6125. [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN] =
  6126. I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN,
  6127. [I40E_CLOUD_FILTER_FLAGS_IMAC_TEN_ID] =
  6128. I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID,
  6129. [I40E_CLOUD_FILTER_FLAGS_OMAC_TEN_ID_IMAC] =
  6130. I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC,
  6131. [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN_TEN_ID] =
  6132. I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID,
  6133. [I40E_CLOUD_FILTER_FLAGS_IIP] =
  6134. I40E_AQC_ADD_CLOUD_FILTER_IIP,
  6135. };
  6136. if (filter->flags >= ARRAY_SIZE(flag_table))
  6137. return I40E_ERR_CONFIG;
  6138. memset(&cld_filter, 0, sizeof(cld_filter));
  6139. /* copy element needed to add cloud filter from filter */
  6140. i40e_set_cld_element(filter, &cld_filter);
  6141. if (filter->tunnel_type != I40E_CLOUD_TNL_TYPE_NONE)
  6142. cld_filter.flags = cpu_to_le16(filter->tunnel_type <<
  6143. I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT);
  6144. if (filter->n_proto == ETH_P_IPV6)
  6145. cld_filter.flags |= cpu_to_le16(flag_table[filter->flags] |
  6146. I40E_AQC_ADD_CLOUD_FLAGS_IPV6);
  6147. else
  6148. cld_filter.flags |= cpu_to_le16(flag_table[filter->flags] |
  6149. I40E_AQC_ADD_CLOUD_FLAGS_IPV4);
  6150. if (add)
  6151. ret = i40e_aq_add_cloud_filters(&pf->hw, filter->seid,
  6152. &cld_filter, 1);
  6153. else
  6154. ret = i40e_aq_rem_cloud_filters(&pf->hw, filter->seid,
  6155. &cld_filter, 1);
  6156. if (ret)
  6157. dev_dbg(&pf->pdev->dev,
  6158. "Failed to %s cloud filter using l4 port %u, err %d aq_err %d\n",
  6159. add ? "add" : "delete", filter->dst_port, ret,
  6160. pf->hw.aq.asq_last_status);
  6161. else
  6162. dev_info(&pf->pdev->dev,
  6163. "%s cloud filter for VSI: %d\n",
  6164. add ? "Added" : "Deleted", filter->seid);
  6165. return ret;
  6166. }
  6167. /**
  6168. * i40e_add_del_cloud_filter_big_buf - Add/del cloud filter using big_buf
  6169. * @vsi: pointer to VSI
  6170. * @filter: cloud filter rule
  6171. * @add: if true, add, if false, delete
  6172. *
  6173. * Add or delete a cloud filter for a specific flow spec using big buffer.
  6174. * Returns 0 if the filter were successfully added.
  6175. **/
  6176. int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi *vsi,
  6177. struct i40e_cloud_filter *filter,
  6178. bool add)
  6179. {
  6180. struct i40e_aqc_cloud_filters_element_bb cld_filter;
  6181. struct i40e_pf *pf = vsi->back;
  6182. int ret;
  6183. /* Both (src/dst) valid mac_addr are not supported */
  6184. if ((is_valid_ether_addr(filter->dst_mac) &&
  6185. is_valid_ether_addr(filter->src_mac)) ||
  6186. (is_multicast_ether_addr(filter->dst_mac) &&
  6187. is_multicast_ether_addr(filter->src_mac)))
  6188. return -EOPNOTSUPP;
  6189. /* Big buffer cloud filter needs 'L4 port' to be non-zero. Also, UDP
  6190. * ports are not supported via big buffer now.
  6191. */
  6192. if (!filter->dst_port || filter->ip_proto == IPPROTO_UDP)
  6193. return -EOPNOTSUPP;
  6194. /* adding filter using src_port/src_ip is not supported at this stage */
  6195. if (filter->src_port ||
  6196. (filter->src_ipv4 && filter->n_proto != ETH_P_IPV6) ||
  6197. !ipv6_addr_any(&filter->ip.v6.src_ip6))
  6198. return -EOPNOTSUPP;
  6199. memset(&cld_filter, 0, sizeof(cld_filter));
  6200. /* copy element needed to add cloud filter from filter */
  6201. i40e_set_cld_element(filter, &cld_filter.element);
  6202. if (is_valid_ether_addr(filter->dst_mac) ||
  6203. is_valid_ether_addr(filter->src_mac) ||
  6204. is_multicast_ether_addr(filter->dst_mac) ||
  6205. is_multicast_ether_addr(filter->src_mac)) {
  6206. /* MAC + IP : unsupported mode */
  6207. if (filter->dst_ipv4)
  6208. return -EOPNOTSUPP;
  6209. /* since we validated that L4 port must be valid before
  6210. * we get here, start with respective "flags" value
  6211. * and update if vlan is present or not
  6212. */
  6213. cld_filter.element.flags =
  6214. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_PORT);
  6215. if (filter->vlan_id) {
  6216. cld_filter.element.flags =
  6217. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_VLAN_PORT);
  6218. }
  6219. } else if ((filter->dst_ipv4 && filter->n_proto != ETH_P_IPV6) ||
  6220. !ipv6_addr_any(&filter->ip.v6.dst_ip6)) {
  6221. cld_filter.element.flags =
  6222. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_IP_PORT);
  6223. if (filter->n_proto == ETH_P_IPV6)
  6224. cld_filter.element.flags |=
  6225. cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV6);
  6226. else
  6227. cld_filter.element.flags |=
  6228. cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV4);
  6229. } else {
  6230. dev_err(&pf->pdev->dev,
  6231. "either mac or ip has to be valid for cloud filter\n");
  6232. return -EINVAL;
  6233. }
  6234. /* Now copy L4 port in Byte 6..7 in general fields */
  6235. cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X16_WORD0] =
  6236. be16_to_cpu(filter->dst_port);
  6237. if (add) {
  6238. /* Validate current device switch mode, change if necessary */
  6239. ret = i40e_validate_and_set_switch_mode(vsi);
  6240. if (ret) {
  6241. dev_err(&pf->pdev->dev,
  6242. "failed to set switch mode, ret %d\n",
  6243. ret);
  6244. return ret;
  6245. }
  6246. ret = i40e_aq_add_cloud_filters_bb(&pf->hw, filter->seid,
  6247. &cld_filter, 1);
  6248. } else {
  6249. ret = i40e_aq_rem_cloud_filters_bb(&pf->hw, filter->seid,
  6250. &cld_filter, 1);
  6251. }
  6252. if (ret)
  6253. dev_dbg(&pf->pdev->dev,
  6254. "Failed to %s cloud filter(big buffer) err %d aq_err %d\n",
  6255. add ? "add" : "delete", ret, pf->hw.aq.asq_last_status);
  6256. else
  6257. dev_info(&pf->pdev->dev,
  6258. "%s cloud filter for VSI: %d, L4 port: %d\n",
  6259. add ? "add" : "delete", filter->seid,
  6260. ntohs(filter->dst_port));
  6261. return ret;
  6262. }
  6263. /**
  6264. * i40e_parse_cls_flower - Parse tc flower filters provided by kernel
  6265. * @vsi: Pointer to VSI
  6266. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6267. * @filter: Pointer to cloud filter structure
  6268. *
  6269. **/
  6270. static int i40e_parse_cls_flower(struct i40e_vsi *vsi,
  6271. struct tc_cls_flower_offload *f,
  6272. struct i40e_cloud_filter *filter)
  6273. {
  6274. u16 n_proto_mask = 0, n_proto_key = 0, addr_type = 0;
  6275. struct i40e_pf *pf = vsi->back;
  6276. u8 field_flags = 0;
  6277. if (f->dissector->used_keys &
  6278. ~(BIT(FLOW_DISSECTOR_KEY_CONTROL) |
  6279. BIT(FLOW_DISSECTOR_KEY_BASIC) |
  6280. BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) |
  6281. BIT(FLOW_DISSECTOR_KEY_VLAN) |
  6282. BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
  6283. BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
  6284. BIT(FLOW_DISSECTOR_KEY_PORTS) |
  6285. BIT(FLOW_DISSECTOR_KEY_ENC_KEYID))) {
  6286. dev_err(&pf->pdev->dev, "Unsupported key used: 0x%x\n",
  6287. f->dissector->used_keys);
  6288. return -EOPNOTSUPP;
  6289. }
  6290. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ENC_KEYID)) {
  6291. struct flow_dissector_key_keyid *key =
  6292. skb_flow_dissector_target(f->dissector,
  6293. FLOW_DISSECTOR_KEY_ENC_KEYID,
  6294. f->key);
  6295. struct flow_dissector_key_keyid *mask =
  6296. skb_flow_dissector_target(f->dissector,
  6297. FLOW_DISSECTOR_KEY_ENC_KEYID,
  6298. f->mask);
  6299. if (mask->keyid != 0)
  6300. field_flags |= I40E_CLOUD_FIELD_TEN_ID;
  6301. filter->tenant_id = be32_to_cpu(key->keyid);
  6302. }
  6303. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_BASIC)) {
  6304. struct flow_dissector_key_basic *key =
  6305. skb_flow_dissector_target(f->dissector,
  6306. FLOW_DISSECTOR_KEY_BASIC,
  6307. f->key);
  6308. struct flow_dissector_key_basic *mask =
  6309. skb_flow_dissector_target(f->dissector,
  6310. FLOW_DISSECTOR_KEY_BASIC,
  6311. f->mask);
  6312. n_proto_key = ntohs(key->n_proto);
  6313. n_proto_mask = ntohs(mask->n_proto);
  6314. if (n_proto_key == ETH_P_ALL) {
  6315. n_proto_key = 0;
  6316. n_proto_mask = 0;
  6317. }
  6318. filter->n_proto = n_proto_key & n_proto_mask;
  6319. filter->ip_proto = key->ip_proto;
  6320. }
  6321. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
  6322. struct flow_dissector_key_eth_addrs *key =
  6323. skb_flow_dissector_target(f->dissector,
  6324. FLOW_DISSECTOR_KEY_ETH_ADDRS,
  6325. f->key);
  6326. struct flow_dissector_key_eth_addrs *mask =
  6327. skb_flow_dissector_target(f->dissector,
  6328. FLOW_DISSECTOR_KEY_ETH_ADDRS,
  6329. f->mask);
  6330. /* use is_broadcast and is_zero to check for all 0xf or 0 */
  6331. if (!is_zero_ether_addr(mask->dst)) {
  6332. if (is_broadcast_ether_addr(mask->dst)) {
  6333. field_flags |= I40E_CLOUD_FIELD_OMAC;
  6334. } else {
  6335. dev_err(&pf->pdev->dev, "Bad ether dest mask %pM\n",
  6336. mask->dst);
  6337. return I40E_ERR_CONFIG;
  6338. }
  6339. }
  6340. if (!is_zero_ether_addr(mask->src)) {
  6341. if (is_broadcast_ether_addr(mask->src)) {
  6342. field_flags |= I40E_CLOUD_FIELD_IMAC;
  6343. } else {
  6344. dev_err(&pf->pdev->dev, "Bad ether src mask %pM\n",
  6345. mask->src);
  6346. return I40E_ERR_CONFIG;
  6347. }
  6348. }
  6349. ether_addr_copy(filter->dst_mac, key->dst);
  6350. ether_addr_copy(filter->src_mac, key->src);
  6351. }
  6352. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_VLAN)) {
  6353. struct flow_dissector_key_vlan *key =
  6354. skb_flow_dissector_target(f->dissector,
  6355. FLOW_DISSECTOR_KEY_VLAN,
  6356. f->key);
  6357. struct flow_dissector_key_vlan *mask =
  6358. skb_flow_dissector_target(f->dissector,
  6359. FLOW_DISSECTOR_KEY_VLAN,
  6360. f->mask);
  6361. if (mask->vlan_id) {
  6362. if (mask->vlan_id == VLAN_VID_MASK) {
  6363. field_flags |= I40E_CLOUD_FIELD_IVLAN;
  6364. } else {
  6365. dev_err(&pf->pdev->dev, "Bad vlan mask 0x%04x\n",
  6366. mask->vlan_id);
  6367. return I40E_ERR_CONFIG;
  6368. }
  6369. }
  6370. filter->vlan_id = cpu_to_be16(key->vlan_id);
  6371. }
  6372. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_CONTROL)) {
  6373. struct flow_dissector_key_control *key =
  6374. skb_flow_dissector_target(f->dissector,
  6375. FLOW_DISSECTOR_KEY_CONTROL,
  6376. f->key);
  6377. addr_type = key->addr_type;
  6378. }
  6379. if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
  6380. struct flow_dissector_key_ipv4_addrs *key =
  6381. skb_flow_dissector_target(f->dissector,
  6382. FLOW_DISSECTOR_KEY_IPV4_ADDRS,
  6383. f->key);
  6384. struct flow_dissector_key_ipv4_addrs *mask =
  6385. skb_flow_dissector_target(f->dissector,
  6386. FLOW_DISSECTOR_KEY_IPV4_ADDRS,
  6387. f->mask);
  6388. if (mask->dst) {
  6389. if (mask->dst == cpu_to_be32(0xffffffff)) {
  6390. field_flags |= I40E_CLOUD_FIELD_IIP;
  6391. } else {
  6392. dev_err(&pf->pdev->dev, "Bad ip dst mask %pI4b\n",
  6393. &mask->dst);
  6394. return I40E_ERR_CONFIG;
  6395. }
  6396. }
  6397. if (mask->src) {
  6398. if (mask->src == cpu_to_be32(0xffffffff)) {
  6399. field_flags |= I40E_CLOUD_FIELD_IIP;
  6400. } else {
  6401. dev_err(&pf->pdev->dev, "Bad ip src mask %pI4b\n",
  6402. &mask->src);
  6403. return I40E_ERR_CONFIG;
  6404. }
  6405. }
  6406. if (field_flags & I40E_CLOUD_FIELD_TEN_ID) {
  6407. dev_err(&pf->pdev->dev, "Tenant id not allowed for ip filter\n");
  6408. return I40E_ERR_CONFIG;
  6409. }
  6410. filter->dst_ipv4 = key->dst;
  6411. filter->src_ipv4 = key->src;
  6412. }
  6413. if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
  6414. struct flow_dissector_key_ipv6_addrs *key =
  6415. skb_flow_dissector_target(f->dissector,
  6416. FLOW_DISSECTOR_KEY_IPV6_ADDRS,
  6417. f->key);
  6418. struct flow_dissector_key_ipv6_addrs *mask =
  6419. skb_flow_dissector_target(f->dissector,
  6420. FLOW_DISSECTOR_KEY_IPV6_ADDRS,
  6421. f->mask);
  6422. /* src and dest IPV6 address should not be LOOPBACK
  6423. * (0:0:0:0:0:0:0:1), which can be represented as ::1
  6424. */
  6425. if (ipv6_addr_loopback(&key->dst) ||
  6426. ipv6_addr_loopback(&key->src)) {
  6427. dev_err(&pf->pdev->dev,
  6428. "Bad ipv6, addr is LOOPBACK\n");
  6429. return I40E_ERR_CONFIG;
  6430. }
  6431. if (!ipv6_addr_any(&mask->dst) || !ipv6_addr_any(&mask->src))
  6432. field_flags |= I40E_CLOUD_FIELD_IIP;
  6433. memcpy(&filter->src_ipv6, &key->src.s6_addr32,
  6434. sizeof(filter->src_ipv6));
  6435. memcpy(&filter->dst_ipv6, &key->dst.s6_addr32,
  6436. sizeof(filter->dst_ipv6));
  6437. }
  6438. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_PORTS)) {
  6439. struct flow_dissector_key_ports *key =
  6440. skb_flow_dissector_target(f->dissector,
  6441. FLOW_DISSECTOR_KEY_PORTS,
  6442. f->key);
  6443. struct flow_dissector_key_ports *mask =
  6444. skb_flow_dissector_target(f->dissector,
  6445. FLOW_DISSECTOR_KEY_PORTS,
  6446. f->mask);
  6447. if (mask->src) {
  6448. if (mask->src == cpu_to_be16(0xffff)) {
  6449. field_flags |= I40E_CLOUD_FIELD_IIP;
  6450. } else {
  6451. dev_err(&pf->pdev->dev, "Bad src port mask 0x%04x\n",
  6452. be16_to_cpu(mask->src));
  6453. return I40E_ERR_CONFIG;
  6454. }
  6455. }
  6456. if (mask->dst) {
  6457. if (mask->dst == cpu_to_be16(0xffff)) {
  6458. field_flags |= I40E_CLOUD_FIELD_IIP;
  6459. } else {
  6460. dev_err(&pf->pdev->dev, "Bad dst port mask 0x%04x\n",
  6461. be16_to_cpu(mask->dst));
  6462. return I40E_ERR_CONFIG;
  6463. }
  6464. }
  6465. filter->dst_port = key->dst;
  6466. filter->src_port = key->src;
  6467. switch (filter->ip_proto) {
  6468. case IPPROTO_TCP:
  6469. case IPPROTO_UDP:
  6470. break;
  6471. default:
  6472. dev_err(&pf->pdev->dev,
  6473. "Only UDP and TCP transport are supported\n");
  6474. return -EINVAL;
  6475. }
  6476. }
  6477. filter->flags = field_flags;
  6478. return 0;
  6479. }
  6480. /**
  6481. * i40e_handle_tclass: Forward to a traffic class on the device
  6482. * @vsi: Pointer to VSI
  6483. * @tc: traffic class index on the device
  6484. * @filter: Pointer to cloud filter structure
  6485. *
  6486. **/
  6487. static int i40e_handle_tclass(struct i40e_vsi *vsi, u32 tc,
  6488. struct i40e_cloud_filter *filter)
  6489. {
  6490. struct i40e_channel *ch, *ch_tmp;
  6491. /* direct to a traffic class on the same device */
  6492. if (tc == 0) {
  6493. filter->seid = vsi->seid;
  6494. return 0;
  6495. } else if (vsi->tc_config.enabled_tc & BIT(tc)) {
  6496. if (!filter->dst_port) {
  6497. dev_err(&vsi->back->pdev->dev,
  6498. "Specify destination port to direct to traffic class that is not default\n");
  6499. return -EINVAL;
  6500. }
  6501. if (list_empty(&vsi->ch_list))
  6502. return -EINVAL;
  6503. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list,
  6504. list) {
  6505. if (ch->seid == vsi->tc_seid_map[tc])
  6506. filter->seid = ch->seid;
  6507. }
  6508. return 0;
  6509. }
  6510. dev_err(&vsi->back->pdev->dev, "TC is not enabled\n");
  6511. return -EINVAL;
  6512. }
  6513. /**
  6514. * i40e_configure_clsflower - Configure tc flower filters
  6515. * @vsi: Pointer to VSI
  6516. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6517. *
  6518. **/
  6519. static int i40e_configure_clsflower(struct i40e_vsi *vsi,
  6520. struct tc_cls_flower_offload *cls_flower)
  6521. {
  6522. int tc = tc_classid_to_hwtc(vsi->netdev, cls_flower->classid);
  6523. struct i40e_cloud_filter *filter = NULL;
  6524. struct i40e_pf *pf = vsi->back;
  6525. int err = 0;
  6526. if (tc < 0) {
  6527. dev_err(&vsi->back->pdev->dev, "Invalid traffic class\n");
  6528. return -EOPNOTSUPP;
  6529. }
  6530. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
  6531. test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
  6532. return -EBUSY;
  6533. if (pf->fdir_pf_active_filters ||
  6534. (!hlist_empty(&pf->fdir_filter_list))) {
  6535. dev_err(&vsi->back->pdev->dev,
  6536. "Flow Director Sideband filters exists, turn ntuple off to configure cloud filters\n");
  6537. return -EINVAL;
  6538. }
  6539. if (vsi->back->flags & I40E_FLAG_FD_SB_ENABLED) {
  6540. dev_err(&vsi->back->pdev->dev,
  6541. "Disable Flow Director Sideband, configuring Cloud filters via tc-flower\n");
  6542. vsi->back->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  6543. vsi->back->flags |= I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6544. }
  6545. filter = kzalloc(sizeof(*filter), GFP_KERNEL);
  6546. if (!filter)
  6547. return -ENOMEM;
  6548. filter->cookie = cls_flower->cookie;
  6549. err = i40e_parse_cls_flower(vsi, cls_flower, filter);
  6550. if (err < 0)
  6551. goto err;
  6552. err = i40e_handle_tclass(vsi, tc, filter);
  6553. if (err < 0)
  6554. goto err;
  6555. /* Add cloud filter */
  6556. if (filter->dst_port)
  6557. err = i40e_add_del_cloud_filter_big_buf(vsi, filter, true);
  6558. else
  6559. err = i40e_add_del_cloud_filter(vsi, filter, true);
  6560. if (err) {
  6561. dev_err(&pf->pdev->dev,
  6562. "Failed to add cloud filter, err %s\n",
  6563. i40e_stat_str(&pf->hw, err));
  6564. goto err;
  6565. }
  6566. /* add filter to the ordered list */
  6567. INIT_HLIST_NODE(&filter->cloud_node);
  6568. hlist_add_head(&filter->cloud_node, &pf->cloud_filter_list);
  6569. pf->num_cloud_filters++;
  6570. return err;
  6571. err:
  6572. kfree(filter);
  6573. return err;
  6574. }
  6575. /**
  6576. * i40e_find_cloud_filter - Find the could filter in the list
  6577. * @vsi: Pointer to VSI
  6578. * @cookie: filter specific cookie
  6579. *
  6580. **/
  6581. static struct i40e_cloud_filter *i40e_find_cloud_filter(struct i40e_vsi *vsi,
  6582. unsigned long *cookie)
  6583. {
  6584. struct i40e_cloud_filter *filter = NULL;
  6585. struct hlist_node *node2;
  6586. hlist_for_each_entry_safe(filter, node2,
  6587. &vsi->back->cloud_filter_list, cloud_node)
  6588. if (!memcmp(cookie, &filter->cookie, sizeof(filter->cookie)))
  6589. return filter;
  6590. return NULL;
  6591. }
  6592. /**
  6593. * i40e_delete_clsflower - Remove tc flower filters
  6594. * @vsi: Pointer to VSI
  6595. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6596. *
  6597. **/
  6598. static int i40e_delete_clsflower(struct i40e_vsi *vsi,
  6599. struct tc_cls_flower_offload *cls_flower)
  6600. {
  6601. struct i40e_cloud_filter *filter = NULL;
  6602. struct i40e_pf *pf = vsi->back;
  6603. int err = 0;
  6604. filter = i40e_find_cloud_filter(vsi, &cls_flower->cookie);
  6605. if (!filter)
  6606. return -EINVAL;
  6607. hash_del(&filter->cloud_node);
  6608. if (filter->dst_port)
  6609. err = i40e_add_del_cloud_filter_big_buf(vsi, filter, false);
  6610. else
  6611. err = i40e_add_del_cloud_filter(vsi, filter, false);
  6612. kfree(filter);
  6613. if (err) {
  6614. dev_err(&pf->pdev->dev,
  6615. "Failed to delete cloud filter, err %s\n",
  6616. i40e_stat_str(&pf->hw, err));
  6617. return i40e_aq_rc_to_posix(err, pf->hw.aq.asq_last_status);
  6618. }
  6619. pf->num_cloud_filters--;
  6620. if (!pf->num_cloud_filters)
  6621. if ((pf->flags & I40E_FLAG_FD_SB_TO_CLOUD_FILTER) &&
  6622. !(pf->flags & I40E_FLAG_FD_SB_INACTIVE)) {
  6623. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  6624. pf->flags &= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6625. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  6626. }
  6627. return 0;
  6628. }
  6629. /**
  6630. * i40e_setup_tc_cls_flower - flower classifier offloads
  6631. * @netdev: net device to configure
  6632. * @type_data: offload data
  6633. **/
  6634. static int i40e_setup_tc_cls_flower(struct i40e_netdev_priv *np,
  6635. struct tc_cls_flower_offload *cls_flower)
  6636. {
  6637. struct i40e_vsi *vsi = np->vsi;
  6638. switch (cls_flower->command) {
  6639. case TC_CLSFLOWER_REPLACE:
  6640. return i40e_configure_clsflower(vsi, cls_flower);
  6641. case TC_CLSFLOWER_DESTROY:
  6642. return i40e_delete_clsflower(vsi, cls_flower);
  6643. case TC_CLSFLOWER_STATS:
  6644. return -EOPNOTSUPP;
  6645. default:
  6646. return -EOPNOTSUPP;
  6647. }
  6648. }
  6649. static int i40e_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
  6650. void *cb_priv)
  6651. {
  6652. struct i40e_netdev_priv *np = cb_priv;
  6653. if (!tc_cls_can_offload_and_chain0(np->vsi->netdev, type_data))
  6654. return -EOPNOTSUPP;
  6655. switch (type) {
  6656. case TC_SETUP_CLSFLOWER:
  6657. return i40e_setup_tc_cls_flower(np, type_data);
  6658. default:
  6659. return -EOPNOTSUPP;
  6660. }
  6661. }
  6662. static int i40e_setup_tc_block(struct net_device *dev,
  6663. struct tc_block_offload *f)
  6664. {
  6665. struct i40e_netdev_priv *np = netdev_priv(dev);
  6666. if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
  6667. return -EOPNOTSUPP;
  6668. switch (f->command) {
  6669. case TC_BLOCK_BIND:
  6670. return tcf_block_cb_register(f->block, i40e_setup_tc_block_cb,
  6671. np, np, f->extack);
  6672. case TC_BLOCK_UNBIND:
  6673. tcf_block_cb_unregister(f->block, i40e_setup_tc_block_cb, np);
  6674. return 0;
  6675. default:
  6676. return -EOPNOTSUPP;
  6677. }
  6678. }
  6679. static int __i40e_setup_tc(struct net_device *netdev, enum tc_setup_type type,
  6680. void *type_data)
  6681. {
  6682. switch (type) {
  6683. case TC_SETUP_QDISC_MQPRIO:
  6684. return i40e_setup_tc(netdev, type_data);
  6685. case TC_SETUP_BLOCK:
  6686. return i40e_setup_tc_block(netdev, type_data);
  6687. default:
  6688. return -EOPNOTSUPP;
  6689. }
  6690. }
  6691. /**
  6692. * i40e_open - Called when a network interface is made active
  6693. * @netdev: network interface device structure
  6694. *
  6695. * The open entry point is called when a network interface is made
  6696. * active by the system (IFF_UP). At this point all resources needed
  6697. * for transmit and receive operations are allocated, the interrupt
  6698. * handler is registered with the OS, the netdev watchdog subtask is
  6699. * enabled, and the stack is notified that the interface is ready.
  6700. *
  6701. * Returns 0 on success, negative value on failure
  6702. **/
  6703. int i40e_open(struct net_device *netdev)
  6704. {
  6705. struct i40e_netdev_priv *np = netdev_priv(netdev);
  6706. struct i40e_vsi *vsi = np->vsi;
  6707. struct i40e_pf *pf = vsi->back;
  6708. int err;
  6709. /* disallow open during test or if eeprom is broken */
  6710. if (test_bit(__I40E_TESTING, pf->state) ||
  6711. test_bit(__I40E_BAD_EEPROM, pf->state))
  6712. return -EBUSY;
  6713. netif_carrier_off(netdev);
  6714. if (i40e_force_link_state(pf, true))
  6715. return -EAGAIN;
  6716. err = i40e_vsi_open(vsi);
  6717. if (err)
  6718. return err;
  6719. /* configure global TSO hardware offload settings */
  6720. wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
  6721. TCP_FLAG_FIN) >> 16);
  6722. wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
  6723. TCP_FLAG_FIN |
  6724. TCP_FLAG_CWR) >> 16);
  6725. wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
  6726. udp_tunnel_get_rx_info(netdev);
  6727. return 0;
  6728. }
  6729. /**
  6730. * i40e_vsi_open -
  6731. * @vsi: the VSI to open
  6732. *
  6733. * Finish initialization of the VSI.
  6734. *
  6735. * Returns 0 on success, negative value on failure
  6736. *
  6737. * Note: expects to be called while under rtnl_lock()
  6738. **/
  6739. int i40e_vsi_open(struct i40e_vsi *vsi)
  6740. {
  6741. struct i40e_pf *pf = vsi->back;
  6742. char int_name[I40E_INT_NAME_STR_LEN];
  6743. int err;
  6744. /* allocate descriptors */
  6745. err = i40e_vsi_setup_tx_resources(vsi);
  6746. if (err)
  6747. goto err_setup_tx;
  6748. err = i40e_vsi_setup_rx_resources(vsi);
  6749. if (err)
  6750. goto err_setup_rx;
  6751. err = i40e_vsi_configure(vsi);
  6752. if (err)
  6753. goto err_setup_rx;
  6754. if (vsi->netdev) {
  6755. snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
  6756. dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
  6757. err = i40e_vsi_request_irq(vsi, int_name);
  6758. if (err)
  6759. goto err_setup_rx;
  6760. /* Notify the stack of the actual queue counts. */
  6761. err = netif_set_real_num_tx_queues(vsi->netdev,
  6762. vsi->num_queue_pairs);
  6763. if (err)
  6764. goto err_set_queues;
  6765. err = netif_set_real_num_rx_queues(vsi->netdev,
  6766. vsi->num_queue_pairs);
  6767. if (err)
  6768. goto err_set_queues;
  6769. } else if (vsi->type == I40E_VSI_FDIR) {
  6770. snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
  6771. dev_driver_string(&pf->pdev->dev),
  6772. dev_name(&pf->pdev->dev));
  6773. err = i40e_vsi_request_irq(vsi, int_name);
  6774. } else {
  6775. err = -EINVAL;
  6776. goto err_setup_rx;
  6777. }
  6778. err = i40e_up_complete(vsi);
  6779. if (err)
  6780. goto err_up_complete;
  6781. return 0;
  6782. err_up_complete:
  6783. i40e_down(vsi);
  6784. err_set_queues:
  6785. i40e_vsi_free_irq(vsi);
  6786. err_setup_rx:
  6787. i40e_vsi_free_rx_resources(vsi);
  6788. err_setup_tx:
  6789. i40e_vsi_free_tx_resources(vsi);
  6790. if (vsi == pf->vsi[pf->lan_vsi])
  6791. i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
  6792. return err;
  6793. }
  6794. /**
  6795. * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
  6796. * @pf: Pointer to PF
  6797. *
  6798. * This function destroys the hlist where all the Flow Director
  6799. * filters were saved.
  6800. **/
  6801. static void i40e_fdir_filter_exit(struct i40e_pf *pf)
  6802. {
  6803. struct i40e_fdir_filter *filter;
  6804. struct i40e_flex_pit *pit_entry, *tmp;
  6805. struct hlist_node *node2;
  6806. hlist_for_each_entry_safe(filter, node2,
  6807. &pf->fdir_filter_list, fdir_node) {
  6808. hlist_del(&filter->fdir_node);
  6809. kfree(filter);
  6810. }
  6811. list_for_each_entry_safe(pit_entry, tmp, &pf->l3_flex_pit_list, list) {
  6812. list_del(&pit_entry->list);
  6813. kfree(pit_entry);
  6814. }
  6815. INIT_LIST_HEAD(&pf->l3_flex_pit_list);
  6816. list_for_each_entry_safe(pit_entry, tmp, &pf->l4_flex_pit_list, list) {
  6817. list_del(&pit_entry->list);
  6818. kfree(pit_entry);
  6819. }
  6820. INIT_LIST_HEAD(&pf->l4_flex_pit_list);
  6821. pf->fdir_pf_active_filters = 0;
  6822. pf->fd_tcp4_filter_cnt = 0;
  6823. pf->fd_udp4_filter_cnt = 0;
  6824. pf->fd_sctp4_filter_cnt = 0;
  6825. pf->fd_ip4_filter_cnt = 0;
  6826. /* Reprogram the default input set for TCP/IPv4 */
  6827. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
  6828. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6829. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6830. /* Reprogram the default input set for UDP/IPv4 */
  6831. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_UDP,
  6832. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6833. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6834. /* Reprogram the default input set for SCTP/IPv4 */
  6835. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP,
  6836. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6837. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6838. /* Reprogram the default input set for Other/IPv4 */
  6839. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER,
  6840. I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
  6841. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV4,
  6842. I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
  6843. }
  6844. /**
  6845. * i40e_cloud_filter_exit - Cleans up the cloud filters
  6846. * @pf: Pointer to PF
  6847. *
  6848. * This function destroys the hlist where all the cloud filters
  6849. * were saved.
  6850. **/
  6851. static void i40e_cloud_filter_exit(struct i40e_pf *pf)
  6852. {
  6853. struct i40e_cloud_filter *cfilter;
  6854. struct hlist_node *node;
  6855. hlist_for_each_entry_safe(cfilter, node,
  6856. &pf->cloud_filter_list, cloud_node) {
  6857. hlist_del(&cfilter->cloud_node);
  6858. kfree(cfilter);
  6859. }
  6860. pf->num_cloud_filters = 0;
  6861. if ((pf->flags & I40E_FLAG_FD_SB_TO_CLOUD_FILTER) &&
  6862. !(pf->flags & I40E_FLAG_FD_SB_INACTIVE)) {
  6863. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  6864. pf->flags &= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6865. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  6866. }
  6867. }
  6868. /**
  6869. * i40e_close - Disables a network interface
  6870. * @netdev: network interface device structure
  6871. *
  6872. * The close entry point is called when an interface is de-activated
  6873. * by the OS. The hardware is still under the driver's control, but
  6874. * this netdev interface is disabled.
  6875. *
  6876. * Returns 0, this is not allowed to fail
  6877. **/
  6878. int i40e_close(struct net_device *netdev)
  6879. {
  6880. struct i40e_netdev_priv *np = netdev_priv(netdev);
  6881. struct i40e_vsi *vsi = np->vsi;
  6882. i40e_vsi_close(vsi);
  6883. return 0;
  6884. }
  6885. /**
  6886. * i40e_do_reset - Start a PF or Core Reset sequence
  6887. * @pf: board private structure
  6888. * @reset_flags: which reset is requested
  6889. * @lock_acquired: indicates whether or not the lock has been acquired
  6890. * before this function was called.
  6891. *
  6892. * The essential difference in resets is that the PF Reset
  6893. * doesn't clear the packet buffers, doesn't reset the PE
  6894. * firmware, and doesn't bother the other PFs on the chip.
  6895. **/
  6896. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags, bool lock_acquired)
  6897. {
  6898. u32 val;
  6899. WARN_ON(in_interrupt());
  6900. /* do the biggest reset indicated */
  6901. if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
  6902. /* Request a Global Reset
  6903. *
  6904. * This will start the chip's countdown to the actual full
  6905. * chip reset event, and a warning interrupt to be sent
  6906. * to all PFs, including the requestor. Our handler
  6907. * for the warning interrupt will deal with the shutdown
  6908. * and recovery of the switch setup.
  6909. */
  6910. dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
  6911. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  6912. val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
  6913. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  6914. } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
  6915. /* Request a Core Reset
  6916. *
  6917. * Same as Global Reset, except does *not* include the MAC/PHY
  6918. */
  6919. dev_dbg(&pf->pdev->dev, "CoreR requested\n");
  6920. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  6921. val |= I40E_GLGEN_RTRIG_CORER_MASK;
  6922. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  6923. i40e_flush(&pf->hw);
  6924. } else if (reset_flags & I40E_PF_RESET_FLAG) {
  6925. /* Request a PF Reset
  6926. *
  6927. * Resets only the PF-specific registers
  6928. *
  6929. * This goes directly to the tear-down and rebuild of
  6930. * the switch, since we need to do all the recovery as
  6931. * for the Core Reset.
  6932. */
  6933. dev_dbg(&pf->pdev->dev, "PFR requested\n");
  6934. i40e_handle_reset_warning(pf, lock_acquired);
  6935. } else if (reset_flags & I40E_PF_RESET_AND_REBUILD_FLAG) {
  6936. /* Request a PF Reset
  6937. *
  6938. * Resets PF and reinitializes PFs VSI.
  6939. */
  6940. i40e_prep_for_reset(pf, lock_acquired);
  6941. i40e_reset_and_rebuild(pf, true, lock_acquired);
  6942. } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
  6943. int v;
  6944. /* Find the VSI(s) that requested a re-init */
  6945. dev_info(&pf->pdev->dev,
  6946. "VSI reinit requested\n");
  6947. for (v = 0; v < pf->num_alloc_vsi; v++) {
  6948. struct i40e_vsi *vsi = pf->vsi[v];
  6949. if (vsi != NULL &&
  6950. test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED,
  6951. vsi->state))
  6952. i40e_vsi_reinit_locked(pf->vsi[v]);
  6953. }
  6954. } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
  6955. int v;
  6956. /* Find the VSI(s) that needs to be brought down */
  6957. dev_info(&pf->pdev->dev, "VSI down requested\n");
  6958. for (v = 0; v < pf->num_alloc_vsi; v++) {
  6959. struct i40e_vsi *vsi = pf->vsi[v];
  6960. if (vsi != NULL &&
  6961. test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED,
  6962. vsi->state)) {
  6963. set_bit(__I40E_VSI_DOWN, vsi->state);
  6964. i40e_down(vsi);
  6965. }
  6966. }
  6967. } else {
  6968. dev_info(&pf->pdev->dev,
  6969. "bad reset request 0x%08x\n", reset_flags);
  6970. }
  6971. }
  6972. #ifdef CONFIG_I40E_DCB
  6973. /**
  6974. * i40e_dcb_need_reconfig - Check if DCB needs reconfig
  6975. * @pf: board private structure
  6976. * @old_cfg: current DCB config
  6977. * @new_cfg: new DCB config
  6978. **/
  6979. bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
  6980. struct i40e_dcbx_config *old_cfg,
  6981. struct i40e_dcbx_config *new_cfg)
  6982. {
  6983. bool need_reconfig = false;
  6984. /* Check if ETS configuration has changed */
  6985. if (memcmp(&new_cfg->etscfg,
  6986. &old_cfg->etscfg,
  6987. sizeof(new_cfg->etscfg))) {
  6988. /* If Priority Table has changed reconfig is needed */
  6989. if (memcmp(&new_cfg->etscfg.prioritytable,
  6990. &old_cfg->etscfg.prioritytable,
  6991. sizeof(new_cfg->etscfg.prioritytable))) {
  6992. need_reconfig = true;
  6993. dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
  6994. }
  6995. if (memcmp(&new_cfg->etscfg.tcbwtable,
  6996. &old_cfg->etscfg.tcbwtable,
  6997. sizeof(new_cfg->etscfg.tcbwtable)))
  6998. dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
  6999. if (memcmp(&new_cfg->etscfg.tsatable,
  7000. &old_cfg->etscfg.tsatable,
  7001. sizeof(new_cfg->etscfg.tsatable)))
  7002. dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
  7003. }
  7004. /* Check if PFC configuration has changed */
  7005. if (memcmp(&new_cfg->pfc,
  7006. &old_cfg->pfc,
  7007. sizeof(new_cfg->pfc))) {
  7008. need_reconfig = true;
  7009. dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
  7010. }
  7011. /* Check if APP Table has changed */
  7012. if (memcmp(&new_cfg->app,
  7013. &old_cfg->app,
  7014. sizeof(new_cfg->app))) {
  7015. need_reconfig = true;
  7016. dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
  7017. }
  7018. dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
  7019. return need_reconfig;
  7020. }
  7021. /**
  7022. * i40e_handle_lldp_event - Handle LLDP Change MIB event
  7023. * @pf: board private structure
  7024. * @e: event info posted on ARQ
  7025. **/
  7026. static int i40e_handle_lldp_event(struct i40e_pf *pf,
  7027. struct i40e_arq_event_info *e)
  7028. {
  7029. struct i40e_aqc_lldp_get_mib *mib =
  7030. (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
  7031. struct i40e_hw *hw = &pf->hw;
  7032. struct i40e_dcbx_config tmp_dcbx_cfg;
  7033. bool need_reconfig = false;
  7034. int ret = 0;
  7035. u8 type;
  7036. /* Not DCB capable or capability disabled */
  7037. if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
  7038. return ret;
  7039. /* Ignore if event is not for Nearest Bridge */
  7040. type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
  7041. & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  7042. dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
  7043. if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
  7044. return ret;
  7045. /* Check MIB Type and return if event for Remote MIB update */
  7046. type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  7047. dev_dbg(&pf->pdev->dev,
  7048. "LLDP event mib type %s\n", type ? "remote" : "local");
  7049. if (type == I40E_AQ_LLDP_MIB_REMOTE) {
  7050. /* Update the remote cached instance and return */
  7051. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  7052. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  7053. &hw->remote_dcbx_config);
  7054. goto exit;
  7055. }
  7056. /* Store the old configuration */
  7057. tmp_dcbx_cfg = hw->local_dcbx_config;
  7058. /* Reset the old DCBx configuration data */
  7059. memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
  7060. /* Get updated DCBX data from firmware */
  7061. ret = i40e_get_dcb_config(&pf->hw);
  7062. if (ret) {
  7063. dev_info(&pf->pdev->dev,
  7064. "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
  7065. i40e_stat_str(&pf->hw, ret),
  7066. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7067. goto exit;
  7068. }
  7069. /* No change detected in DCBX configs */
  7070. if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
  7071. sizeof(tmp_dcbx_cfg))) {
  7072. dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
  7073. goto exit;
  7074. }
  7075. need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
  7076. &hw->local_dcbx_config);
  7077. i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
  7078. if (!need_reconfig)
  7079. goto exit;
  7080. /* Enable DCB tagging only when more than one TC */
  7081. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  7082. pf->flags |= I40E_FLAG_DCB_ENABLED;
  7083. else
  7084. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  7085. set_bit(__I40E_PORT_SUSPENDED, pf->state);
  7086. /* Reconfiguration needed quiesce all VSIs */
  7087. i40e_pf_quiesce_all_vsi(pf);
  7088. /* Changes in configuration update VEB/VSI */
  7089. i40e_dcb_reconfigure(pf);
  7090. ret = i40e_resume_port_tx(pf);
  7091. clear_bit(__I40E_PORT_SUSPENDED, pf->state);
  7092. /* In case of error no point in resuming VSIs */
  7093. if (ret)
  7094. goto exit;
  7095. /* Wait for the PF's queues to be disabled */
  7096. ret = i40e_pf_wait_queues_disabled(pf);
  7097. if (ret) {
  7098. /* Schedule PF reset to recover */
  7099. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  7100. i40e_service_event_schedule(pf);
  7101. } else {
  7102. i40e_pf_unquiesce_all_vsi(pf);
  7103. set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
  7104. set_bit(__I40E_CLIENT_L2_CHANGE, pf->state);
  7105. }
  7106. exit:
  7107. return ret;
  7108. }
  7109. #endif /* CONFIG_I40E_DCB */
  7110. /**
  7111. * i40e_do_reset_safe - Protected reset path for userland calls.
  7112. * @pf: board private structure
  7113. * @reset_flags: which reset is requested
  7114. *
  7115. **/
  7116. void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
  7117. {
  7118. rtnl_lock();
  7119. i40e_do_reset(pf, reset_flags, true);
  7120. rtnl_unlock();
  7121. }
  7122. /**
  7123. * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
  7124. * @pf: board private structure
  7125. * @e: event info posted on ARQ
  7126. *
  7127. * Handler for LAN Queue Overflow Event generated by the firmware for PF
  7128. * and VF queues
  7129. **/
  7130. static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
  7131. struct i40e_arq_event_info *e)
  7132. {
  7133. struct i40e_aqc_lan_overflow *data =
  7134. (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
  7135. u32 queue = le32_to_cpu(data->prtdcb_rupto);
  7136. u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
  7137. struct i40e_hw *hw = &pf->hw;
  7138. struct i40e_vf *vf;
  7139. u16 vf_id;
  7140. dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
  7141. queue, qtx_ctl);
  7142. /* Queue belongs to VF, find the VF and issue VF reset */
  7143. if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
  7144. >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
  7145. vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
  7146. >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
  7147. vf_id -= hw->func_caps.vf_base_id;
  7148. vf = &pf->vf[vf_id];
  7149. i40e_vc_notify_vf_reset(vf);
  7150. /* Allow VF to process pending reset notification */
  7151. msleep(20);
  7152. i40e_reset_vf(vf, false);
  7153. }
  7154. }
  7155. /**
  7156. * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
  7157. * @pf: board private structure
  7158. **/
  7159. u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
  7160. {
  7161. u32 val, fcnt_prog;
  7162. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  7163. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
  7164. return fcnt_prog;
  7165. }
  7166. /**
  7167. * i40e_get_current_fd_count - Get total FD filters programmed for this PF
  7168. * @pf: board private structure
  7169. **/
  7170. u32 i40e_get_current_fd_count(struct i40e_pf *pf)
  7171. {
  7172. u32 val, fcnt_prog;
  7173. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  7174. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
  7175. ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
  7176. I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
  7177. return fcnt_prog;
  7178. }
  7179. /**
  7180. * i40e_get_global_fd_count - Get total FD filters programmed on device
  7181. * @pf: board private structure
  7182. **/
  7183. u32 i40e_get_global_fd_count(struct i40e_pf *pf)
  7184. {
  7185. u32 val, fcnt_prog;
  7186. val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
  7187. fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
  7188. ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
  7189. I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
  7190. return fcnt_prog;
  7191. }
  7192. /**
  7193. * i40e_reenable_fdir_sb - Restore FDir SB capability
  7194. * @pf: board private structure
  7195. **/
  7196. static void i40e_reenable_fdir_sb(struct i40e_pf *pf)
  7197. {
  7198. if (test_and_clear_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state))
  7199. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  7200. (I40E_DEBUG_FD & pf->hw.debug_mask))
  7201. dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
  7202. }
  7203. /**
  7204. * i40e_reenable_fdir_atr - Restore FDir ATR capability
  7205. * @pf: board private structure
  7206. **/
  7207. static void i40e_reenable_fdir_atr(struct i40e_pf *pf)
  7208. {
  7209. if (test_and_clear_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state)) {
  7210. /* ATR uses the same filtering logic as SB rules. It only
  7211. * functions properly if the input set mask is at the default
  7212. * settings. It is safe to restore the default input set
  7213. * because there are no active TCPv4 filter rules.
  7214. */
  7215. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
  7216. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  7217. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  7218. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  7219. (I40E_DEBUG_FD & pf->hw.debug_mask))
  7220. dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
  7221. }
  7222. }
  7223. /**
  7224. * i40e_delete_invalid_filter - Delete an invalid FDIR filter
  7225. * @pf: board private structure
  7226. * @filter: FDir filter to remove
  7227. */
  7228. static void i40e_delete_invalid_filter(struct i40e_pf *pf,
  7229. struct i40e_fdir_filter *filter)
  7230. {
  7231. /* Update counters */
  7232. pf->fdir_pf_active_filters--;
  7233. pf->fd_inv = 0;
  7234. switch (filter->flow_type) {
  7235. case TCP_V4_FLOW:
  7236. pf->fd_tcp4_filter_cnt--;
  7237. break;
  7238. case UDP_V4_FLOW:
  7239. pf->fd_udp4_filter_cnt--;
  7240. break;
  7241. case SCTP_V4_FLOW:
  7242. pf->fd_sctp4_filter_cnt--;
  7243. break;
  7244. case IP_USER_FLOW:
  7245. switch (filter->ip4_proto) {
  7246. case IPPROTO_TCP:
  7247. pf->fd_tcp4_filter_cnt--;
  7248. break;
  7249. case IPPROTO_UDP:
  7250. pf->fd_udp4_filter_cnt--;
  7251. break;
  7252. case IPPROTO_SCTP:
  7253. pf->fd_sctp4_filter_cnt--;
  7254. break;
  7255. case IPPROTO_IP:
  7256. pf->fd_ip4_filter_cnt--;
  7257. break;
  7258. }
  7259. break;
  7260. }
  7261. /* Remove the filter from the list and free memory */
  7262. hlist_del(&filter->fdir_node);
  7263. kfree(filter);
  7264. }
  7265. /**
  7266. * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
  7267. * @pf: board private structure
  7268. **/
  7269. void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
  7270. {
  7271. struct i40e_fdir_filter *filter;
  7272. u32 fcnt_prog, fcnt_avail;
  7273. struct hlist_node *node;
  7274. if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
  7275. return;
  7276. /* Check if we have enough room to re-enable FDir SB capability. */
  7277. fcnt_prog = i40e_get_global_fd_count(pf);
  7278. fcnt_avail = pf->fdir_pf_filter_count;
  7279. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
  7280. (pf->fd_add_err == 0) ||
  7281. (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt))
  7282. i40e_reenable_fdir_sb(pf);
  7283. /* We should wait for even more space before re-enabling ATR.
  7284. * Additionally, we cannot enable ATR as long as we still have TCP SB
  7285. * rules active.
  7286. */
  7287. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) &&
  7288. (pf->fd_tcp4_filter_cnt == 0))
  7289. i40e_reenable_fdir_atr(pf);
  7290. /* if hw had a problem adding a filter, delete it */
  7291. if (pf->fd_inv > 0) {
  7292. hlist_for_each_entry_safe(filter, node,
  7293. &pf->fdir_filter_list, fdir_node)
  7294. if (filter->fd_id == pf->fd_inv)
  7295. i40e_delete_invalid_filter(pf, filter);
  7296. }
  7297. }
  7298. #define I40E_MIN_FD_FLUSH_INTERVAL 10
  7299. #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
  7300. /**
  7301. * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
  7302. * @pf: board private structure
  7303. **/
  7304. static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
  7305. {
  7306. unsigned long min_flush_time;
  7307. int flush_wait_retry = 50;
  7308. bool disable_atr = false;
  7309. int fd_room;
  7310. int reg;
  7311. if (!time_after(jiffies, pf->fd_flush_timestamp +
  7312. (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
  7313. return;
  7314. /* If the flush is happening too quick and we have mostly SB rules we
  7315. * should not re-enable ATR for some time.
  7316. */
  7317. min_flush_time = pf->fd_flush_timestamp +
  7318. (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
  7319. fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
  7320. if (!(time_after(jiffies, min_flush_time)) &&
  7321. (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
  7322. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7323. dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
  7324. disable_atr = true;
  7325. }
  7326. pf->fd_flush_timestamp = jiffies;
  7327. set_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
  7328. /* flush all filters */
  7329. wr32(&pf->hw, I40E_PFQF_CTL_1,
  7330. I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
  7331. i40e_flush(&pf->hw);
  7332. pf->fd_flush_cnt++;
  7333. pf->fd_add_err = 0;
  7334. do {
  7335. /* Check FD flush status every 5-6msec */
  7336. usleep_range(5000, 6000);
  7337. reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
  7338. if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
  7339. break;
  7340. } while (flush_wait_retry--);
  7341. if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
  7342. dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
  7343. } else {
  7344. /* replay sideband filters */
  7345. i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
  7346. if (!disable_atr && !pf->fd_tcp4_filter_cnt)
  7347. clear_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
  7348. clear_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
  7349. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7350. dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
  7351. }
  7352. }
  7353. /**
  7354. * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
  7355. * @pf: board private structure
  7356. **/
  7357. u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
  7358. {
  7359. return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
  7360. }
  7361. /* We can see up to 256 filter programming desc in transit if the filters are
  7362. * being applied really fast; before we see the first
  7363. * filter miss error on Rx queue 0. Accumulating enough error messages before
  7364. * reacting will make sure we don't cause flush too often.
  7365. */
  7366. #define I40E_MAX_FD_PROGRAM_ERROR 256
  7367. /**
  7368. * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
  7369. * @pf: board private structure
  7370. **/
  7371. static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
  7372. {
  7373. /* if interface is down do nothing */
  7374. if (test_bit(__I40E_DOWN, pf->state))
  7375. return;
  7376. if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
  7377. i40e_fdir_flush_and_replay(pf);
  7378. i40e_fdir_check_and_reenable(pf);
  7379. }
  7380. /**
  7381. * i40e_vsi_link_event - notify VSI of a link event
  7382. * @vsi: vsi to be notified
  7383. * @link_up: link up or down
  7384. **/
  7385. static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
  7386. {
  7387. if (!vsi || test_bit(__I40E_VSI_DOWN, vsi->state))
  7388. return;
  7389. switch (vsi->type) {
  7390. case I40E_VSI_MAIN:
  7391. if (!vsi->netdev || !vsi->netdev_registered)
  7392. break;
  7393. if (link_up) {
  7394. netif_carrier_on(vsi->netdev);
  7395. netif_tx_wake_all_queues(vsi->netdev);
  7396. } else {
  7397. netif_carrier_off(vsi->netdev);
  7398. netif_tx_stop_all_queues(vsi->netdev);
  7399. }
  7400. break;
  7401. case I40E_VSI_SRIOV:
  7402. case I40E_VSI_VMDQ2:
  7403. case I40E_VSI_CTRL:
  7404. case I40E_VSI_IWARP:
  7405. case I40E_VSI_MIRROR:
  7406. default:
  7407. /* there is no notification for other VSIs */
  7408. break;
  7409. }
  7410. }
  7411. /**
  7412. * i40e_veb_link_event - notify elements on the veb of a link event
  7413. * @veb: veb to be notified
  7414. * @link_up: link up or down
  7415. **/
  7416. static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
  7417. {
  7418. struct i40e_pf *pf;
  7419. int i;
  7420. if (!veb || !veb->pf)
  7421. return;
  7422. pf = veb->pf;
  7423. /* depth first... */
  7424. for (i = 0; i < I40E_MAX_VEB; i++)
  7425. if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
  7426. i40e_veb_link_event(pf->veb[i], link_up);
  7427. /* ... now the local VSIs */
  7428. for (i = 0; i < pf->num_alloc_vsi; i++)
  7429. if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
  7430. i40e_vsi_link_event(pf->vsi[i], link_up);
  7431. }
  7432. /**
  7433. * i40e_link_event - Update netif_carrier status
  7434. * @pf: board private structure
  7435. **/
  7436. static void i40e_link_event(struct i40e_pf *pf)
  7437. {
  7438. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7439. u8 new_link_speed, old_link_speed;
  7440. i40e_status status;
  7441. bool new_link, old_link;
  7442. /* save off old link status information */
  7443. pf->hw.phy.link_info_old = pf->hw.phy.link_info;
  7444. /* set this to force the get_link_status call to refresh state */
  7445. pf->hw.phy.get_link_info = true;
  7446. old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
  7447. status = i40e_get_link_status(&pf->hw, &new_link);
  7448. /* On success, disable temp link polling */
  7449. if (status == I40E_SUCCESS) {
  7450. clear_bit(__I40E_TEMP_LINK_POLLING, pf->state);
  7451. } else {
  7452. /* Enable link polling temporarily until i40e_get_link_status
  7453. * returns I40E_SUCCESS
  7454. */
  7455. set_bit(__I40E_TEMP_LINK_POLLING, pf->state);
  7456. dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
  7457. status);
  7458. return;
  7459. }
  7460. old_link_speed = pf->hw.phy.link_info_old.link_speed;
  7461. new_link_speed = pf->hw.phy.link_info.link_speed;
  7462. if (new_link == old_link &&
  7463. new_link_speed == old_link_speed &&
  7464. (test_bit(__I40E_VSI_DOWN, vsi->state) ||
  7465. new_link == netif_carrier_ok(vsi->netdev)))
  7466. return;
  7467. i40e_print_link_message(vsi, new_link);
  7468. /* Notify the base of the switch tree connected to
  7469. * the link. Floating VEBs are not notified.
  7470. */
  7471. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  7472. i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
  7473. else
  7474. i40e_vsi_link_event(vsi, new_link);
  7475. if (pf->vf)
  7476. i40e_vc_notify_link_state(pf);
  7477. if (pf->flags & I40E_FLAG_PTP)
  7478. i40e_ptp_set_increment(pf);
  7479. }
  7480. /**
  7481. * i40e_watchdog_subtask - periodic checks not using event driven response
  7482. * @pf: board private structure
  7483. **/
  7484. static void i40e_watchdog_subtask(struct i40e_pf *pf)
  7485. {
  7486. int i;
  7487. /* if interface is down do nothing */
  7488. if (test_bit(__I40E_DOWN, pf->state) ||
  7489. test_bit(__I40E_CONFIG_BUSY, pf->state))
  7490. return;
  7491. /* make sure we don't do these things too often */
  7492. if (time_before(jiffies, (pf->service_timer_previous +
  7493. pf->service_timer_period)))
  7494. return;
  7495. pf->service_timer_previous = jiffies;
  7496. if ((pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) ||
  7497. test_bit(__I40E_TEMP_LINK_POLLING, pf->state))
  7498. i40e_link_event(pf);
  7499. /* Update the stats for active netdevs so the network stack
  7500. * can look at updated numbers whenever it cares to
  7501. */
  7502. for (i = 0; i < pf->num_alloc_vsi; i++)
  7503. if (pf->vsi[i] && pf->vsi[i]->netdev)
  7504. i40e_update_stats(pf->vsi[i]);
  7505. if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
  7506. /* Update the stats for the active switching components */
  7507. for (i = 0; i < I40E_MAX_VEB; i++)
  7508. if (pf->veb[i])
  7509. i40e_update_veb_stats(pf->veb[i]);
  7510. }
  7511. i40e_ptp_rx_hang(pf);
  7512. i40e_ptp_tx_hang(pf);
  7513. }
  7514. /**
  7515. * i40e_reset_subtask - Set up for resetting the device and driver
  7516. * @pf: board private structure
  7517. **/
  7518. static void i40e_reset_subtask(struct i40e_pf *pf)
  7519. {
  7520. u32 reset_flags = 0;
  7521. if (test_bit(__I40E_REINIT_REQUESTED, pf->state)) {
  7522. reset_flags |= BIT(__I40E_REINIT_REQUESTED);
  7523. clear_bit(__I40E_REINIT_REQUESTED, pf->state);
  7524. }
  7525. if (test_bit(__I40E_PF_RESET_REQUESTED, pf->state)) {
  7526. reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
  7527. clear_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  7528. }
  7529. if (test_bit(__I40E_CORE_RESET_REQUESTED, pf->state)) {
  7530. reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
  7531. clear_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
  7532. }
  7533. if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state)) {
  7534. reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
  7535. clear_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state);
  7536. }
  7537. if (test_bit(__I40E_DOWN_REQUESTED, pf->state)) {
  7538. reset_flags |= BIT(__I40E_DOWN_REQUESTED);
  7539. clear_bit(__I40E_DOWN_REQUESTED, pf->state);
  7540. }
  7541. /* If there's a recovery already waiting, it takes
  7542. * precedence before starting a new reset sequence.
  7543. */
  7544. if (test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) {
  7545. i40e_prep_for_reset(pf, false);
  7546. i40e_reset(pf);
  7547. i40e_rebuild(pf, false, false);
  7548. }
  7549. /* If we're already down or resetting, just bail */
  7550. if (reset_flags &&
  7551. !test_bit(__I40E_DOWN, pf->state) &&
  7552. !test_bit(__I40E_CONFIG_BUSY, pf->state)) {
  7553. i40e_do_reset(pf, reset_flags, false);
  7554. }
  7555. }
  7556. /**
  7557. * i40e_handle_link_event - Handle link event
  7558. * @pf: board private structure
  7559. * @e: event info posted on ARQ
  7560. **/
  7561. static void i40e_handle_link_event(struct i40e_pf *pf,
  7562. struct i40e_arq_event_info *e)
  7563. {
  7564. struct i40e_aqc_get_link_status *status =
  7565. (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
  7566. /* Do a new status request to re-enable LSE reporting
  7567. * and load new status information into the hw struct
  7568. * This completely ignores any state information
  7569. * in the ARQ event info, instead choosing to always
  7570. * issue the AQ update link status command.
  7571. */
  7572. i40e_link_event(pf);
  7573. /* Check if module meets thermal requirements */
  7574. if (status->phy_type == I40E_PHY_TYPE_NOT_SUPPORTED_HIGH_TEMP) {
  7575. dev_err(&pf->pdev->dev,
  7576. "Rx/Tx is disabled on this device because the module does not meet thermal requirements.\n");
  7577. dev_err(&pf->pdev->dev,
  7578. "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
  7579. } else {
  7580. /* check for unqualified module, if link is down, suppress
  7581. * the message if link was forced to be down.
  7582. */
  7583. if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
  7584. (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
  7585. (!(status->link_info & I40E_AQ_LINK_UP)) &&
  7586. (!(pf->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED))) {
  7587. dev_err(&pf->pdev->dev,
  7588. "Rx/Tx is disabled on this device because an unsupported SFP module type was detected.\n");
  7589. dev_err(&pf->pdev->dev,
  7590. "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
  7591. }
  7592. }
  7593. }
  7594. /**
  7595. * i40e_clean_adminq_subtask - Clean the AdminQ rings
  7596. * @pf: board private structure
  7597. **/
  7598. static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
  7599. {
  7600. struct i40e_arq_event_info event;
  7601. struct i40e_hw *hw = &pf->hw;
  7602. u16 pending, i = 0;
  7603. i40e_status ret;
  7604. u16 opcode;
  7605. u32 oldval;
  7606. u32 val;
  7607. /* Do not run clean AQ when PF reset fails */
  7608. if (test_bit(__I40E_RESET_FAILED, pf->state))
  7609. return;
  7610. /* check for error indications */
  7611. val = rd32(&pf->hw, pf->hw.aq.arq.len);
  7612. oldval = val;
  7613. if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
  7614. if (hw->debug_mask & I40E_DEBUG_AQ)
  7615. dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
  7616. val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
  7617. }
  7618. if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
  7619. if (hw->debug_mask & I40E_DEBUG_AQ)
  7620. dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
  7621. val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
  7622. pf->arq_overflows++;
  7623. }
  7624. if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
  7625. if (hw->debug_mask & I40E_DEBUG_AQ)
  7626. dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
  7627. val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
  7628. }
  7629. if (oldval != val)
  7630. wr32(&pf->hw, pf->hw.aq.arq.len, val);
  7631. val = rd32(&pf->hw, pf->hw.aq.asq.len);
  7632. oldval = val;
  7633. if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
  7634. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7635. dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
  7636. val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
  7637. }
  7638. if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
  7639. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7640. dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
  7641. val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
  7642. }
  7643. if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
  7644. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7645. dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
  7646. val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
  7647. }
  7648. if (oldval != val)
  7649. wr32(&pf->hw, pf->hw.aq.asq.len, val);
  7650. event.buf_len = I40E_MAX_AQ_BUF_SIZE;
  7651. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  7652. if (!event.msg_buf)
  7653. return;
  7654. do {
  7655. ret = i40e_clean_arq_element(hw, &event, &pending);
  7656. if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
  7657. break;
  7658. else if (ret) {
  7659. dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
  7660. break;
  7661. }
  7662. opcode = le16_to_cpu(event.desc.opcode);
  7663. switch (opcode) {
  7664. case i40e_aqc_opc_get_link_status:
  7665. i40e_handle_link_event(pf, &event);
  7666. break;
  7667. case i40e_aqc_opc_send_msg_to_pf:
  7668. ret = i40e_vc_process_vf_msg(pf,
  7669. le16_to_cpu(event.desc.retval),
  7670. le32_to_cpu(event.desc.cookie_high),
  7671. le32_to_cpu(event.desc.cookie_low),
  7672. event.msg_buf,
  7673. event.msg_len);
  7674. break;
  7675. case i40e_aqc_opc_lldp_update_mib:
  7676. dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
  7677. #ifdef CONFIG_I40E_DCB
  7678. rtnl_lock();
  7679. ret = i40e_handle_lldp_event(pf, &event);
  7680. rtnl_unlock();
  7681. #endif /* CONFIG_I40E_DCB */
  7682. break;
  7683. case i40e_aqc_opc_event_lan_overflow:
  7684. dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
  7685. i40e_handle_lan_overflow_event(pf, &event);
  7686. break;
  7687. case i40e_aqc_opc_send_msg_to_peer:
  7688. dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
  7689. break;
  7690. case i40e_aqc_opc_nvm_erase:
  7691. case i40e_aqc_opc_nvm_update:
  7692. case i40e_aqc_opc_oem_post_update:
  7693. i40e_debug(&pf->hw, I40E_DEBUG_NVM,
  7694. "ARQ NVM operation 0x%04x completed\n",
  7695. opcode);
  7696. break;
  7697. default:
  7698. dev_info(&pf->pdev->dev,
  7699. "ARQ: Unknown event 0x%04x ignored\n",
  7700. opcode);
  7701. break;
  7702. }
  7703. } while (i++ < pf->adminq_work_limit);
  7704. if (i < pf->adminq_work_limit)
  7705. clear_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
  7706. /* re-enable Admin queue interrupt cause */
  7707. val = rd32(hw, I40E_PFINT_ICR0_ENA);
  7708. val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  7709. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  7710. i40e_flush(hw);
  7711. kfree(event.msg_buf);
  7712. }
  7713. /**
  7714. * i40e_verify_eeprom - make sure eeprom is good to use
  7715. * @pf: board private structure
  7716. **/
  7717. static void i40e_verify_eeprom(struct i40e_pf *pf)
  7718. {
  7719. int err;
  7720. err = i40e_diag_eeprom_test(&pf->hw);
  7721. if (err) {
  7722. /* retry in case of garbage read */
  7723. err = i40e_diag_eeprom_test(&pf->hw);
  7724. if (err) {
  7725. dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
  7726. err);
  7727. set_bit(__I40E_BAD_EEPROM, pf->state);
  7728. }
  7729. }
  7730. if (!err && test_bit(__I40E_BAD_EEPROM, pf->state)) {
  7731. dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
  7732. clear_bit(__I40E_BAD_EEPROM, pf->state);
  7733. }
  7734. }
  7735. /**
  7736. * i40e_enable_pf_switch_lb
  7737. * @pf: pointer to the PF structure
  7738. *
  7739. * enable switch loop back or die - no point in a return value
  7740. **/
  7741. static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
  7742. {
  7743. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7744. struct i40e_vsi_context ctxt;
  7745. int ret;
  7746. ctxt.seid = pf->main_vsi_seid;
  7747. ctxt.pf_num = pf->hw.pf_id;
  7748. ctxt.vf_num = 0;
  7749. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  7750. if (ret) {
  7751. dev_info(&pf->pdev->dev,
  7752. "couldn't get PF vsi config, err %s aq_err %s\n",
  7753. i40e_stat_str(&pf->hw, ret),
  7754. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7755. return;
  7756. }
  7757. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  7758. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  7759. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  7760. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  7761. if (ret) {
  7762. dev_info(&pf->pdev->dev,
  7763. "update vsi switch failed, err %s aq_err %s\n",
  7764. i40e_stat_str(&pf->hw, ret),
  7765. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7766. }
  7767. }
  7768. /**
  7769. * i40e_disable_pf_switch_lb
  7770. * @pf: pointer to the PF structure
  7771. *
  7772. * disable switch loop back or die - no point in a return value
  7773. **/
  7774. static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
  7775. {
  7776. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7777. struct i40e_vsi_context ctxt;
  7778. int ret;
  7779. ctxt.seid = pf->main_vsi_seid;
  7780. ctxt.pf_num = pf->hw.pf_id;
  7781. ctxt.vf_num = 0;
  7782. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  7783. if (ret) {
  7784. dev_info(&pf->pdev->dev,
  7785. "couldn't get PF vsi config, err %s aq_err %s\n",
  7786. i40e_stat_str(&pf->hw, ret),
  7787. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7788. return;
  7789. }
  7790. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  7791. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  7792. ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  7793. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  7794. if (ret) {
  7795. dev_info(&pf->pdev->dev,
  7796. "update vsi switch failed, err %s aq_err %s\n",
  7797. i40e_stat_str(&pf->hw, ret),
  7798. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7799. }
  7800. }
  7801. /**
  7802. * i40e_config_bridge_mode - Configure the HW bridge mode
  7803. * @veb: pointer to the bridge instance
  7804. *
  7805. * Configure the loop back mode for the LAN VSI that is downlink to the
  7806. * specified HW bridge instance. It is expected this function is called
  7807. * when a new HW bridge is instantiated.
  7808. **/
  7809. static void i40e_config_bridge_mode(struct i40e_veb *veb)
  7810. {
  7811. struct i40e_pf *pf = veb->pf;
  7812. if (pf->hw.debug_mask & I40E_DEBUG_LAN)
  7813. dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
  7814. veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  7815. if (veb->bridge_mode & BRIDGE_MODE_VEPA)
  7816. i40e_disable_pf_switch_lb(pf);
  7817. else
  7818. i40e_enable_pf_switch_lb(pf);
  7819. }
  7820. /**
  7821. * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
  7822. * @veb: pointer to the VEB instance
  7823. *
  7824. * This is a recursive function that first builds the attached VSIs then
  7825. * recurses in to build the next layer of VEB. We track the connections
  7826. * through our own index numbers because the seid's from the HW could
  7827. * change across the reset.
  7828. **/
  7829. static int i40e_reconstitute_veb(struct i40e_veb *veb)
  7830. {
  7831. struct i40e_vsi *ctl_vsi = NULL;
  7832. struct i40e_pf *pf = veb->pf;
  7833. int v, veb_idx;
  7834. int ret;
  7835. /* build VSI that owns this VEB, temporarily attached to base VEB */
  7836. for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
  7837. if (pf->vsi[v] &&
  7838. pf->vsi[v]->veb_idx == veb->idx &&
  7839. pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
  7840. ctl_vsi = pf->vsi[v];
  7841. break;
  7842. }
  7843. }
  7844. if (!ctl_vsi) {
  7845. dev_info(&pf->pdev->dev,
  7846. "missing owner VSI for veb_idx %d\n", veb->idx);
  7847. ret = -ENOENT;
  7848. goto end_reconstitute;
  7849. }
  7850. if (ctl_vsi != pf->vsi[pf->lan_vsi])
  7851. ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  7852. ret = i40e_add_vsi(ctl_vsi);
  7853. if (ret) {
  7854. dev_info(&pf->pdev->dev,
  7855. "rebuild of veb_idx %d owner VSI failed: %d\n",
  7856. veb->idx, ret);
  7857. goto end_reconstitute;
  7858. }
  7859. i40e_vsi_reset_stats(ctl_vsi);
  7860. /* create the VEB in the switch and move the VSI onto the VEB */
  7861. ret = i40e_add_veb(veb, ctl_vsi);
  7862. if (ret)
  7863. goto end_reconstitute;
  7864. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  7865. veb->bridge_mode = BRIDGE_MODE_VEB;
  7866. else
  7867. veb->bridge_mode = BRIDGE_MODE_VEPA;
  7868. i40e_config_bridge_mode(veb);
  7869. /* create the remaining VSIs attached to this VEB */
  7870. for (v = 0; v < pf->num_alloc_vsi; v++) {
  7871. if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
  7872. continue;
  7873. if (pf->vsi[v]->veb_idx == veb->idx) {
  7874. struct i40e_vsi *vsi = pf->vsi[v];
  7875. vsi->uplink_seid = veb->seid;
  7876. ret = i40e_add_vsi(vsi);
  7877. if (ret) {
  7878. dev_info(&pf->pdev->dev,
  7879. "rebuild of vsi_idx %d failed: %d\n",
  7880. v, ret);
  7881. goto end_reconstitute;
  7882. }
  7883. i40e_vsi_reset_stats(vsi);
  7884. }
  7885. }
  7886. /* create any VEBs attached to this VEB - RECURSION */
  7887. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  7888. if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
  7889. pf->veb[veb_idx]->uplink_seid = veb->seid;
  7890. ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
  7891. if (ret)
  7892. break;
  7893. }
  7894. }
  7895. end_reconstitute:
  7896. return ret;
  7897. }
  7898. /**
  7899. * i40e_get_capabilities - get info about the HW
  7900. * @pf: the PF struct
  7901. **/
  7902. static int i40e_get_capabilities(struct i40e_pf *pf,
  7903. enum i40e_admin_queue_opc list_type)
  7904. {
  7905. struct i40e_aqc_list_capabilities_element_resp *cap_buf;
  7906. u16 data_size;
  7907. int buf_len;
  7908. int err;
  7909. buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
  7910. do {
  7911. cap_buf = kzalloc(buf_len, GFP_KERNEL);
  7912. if (!cap_buf)
  7913. return -ENOMEM;
  7914. /* this loads the data into the hw struct for us */
  7915. err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
  7916. &data_size, list_type,
  7917. NULL);
  7918. /* data loaded, buffer no longer needed */
  7919. kfree(cap_buf);
  7920. if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
  7921. /* retry with a larger buffer */
  7922. buf_len = data_size;
  7923. } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
  7924. dev_info(&pf->pdev->dev,
  7925. "capability discovery failed, err %s aq_err %s\n",
  7926. i40e_stat_str(&pf->hw, err),
  7927. i40e_aq_str(&pf->hw,
  7928. pf->hw.aq.asq_last_status));
  7929. return -ENODEV;
  7930. }
  7931. } while (err);
  7932. if (pf->hw.debug_mask & I40E_DEBUG_USER) {
  7933. if (list_type == i40e_aqc_opc_list_func_capabilities) {
  7934. dev_info(&pf->pdev->dev,
  7935. "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",
  7936. pf->hw.pf_id, pf->hw.func_caps.num_vfs,
  7937. pf->hw.func_caps.num_msix_vectors,
  7938. pf->hw.func_caps.num_msix_vectors_vf,
  7939. pf->hw.func_caps.fd_filters_guaranteed,
  7940. pf->hw.func_caps.fd_filters_best_effort,
  7941. pf->hw.func_caps.num_tx_qp,
  7942. pf->hw.func_caps.num_vsis);
  7943. } else if (list_type == i40e_aqc_opc_list_dev_capabilities) {
  7944. dev_info(&pf->pdev->dev,
  7945. "switch_mode=0x%04x, function_valid=0x%08x\n",
  7946. pf->hw.dev_caps.switch_mode,
  7947. pf->hw.dev_caps.valid_functions);
  7948. dev_info(&pf->pdev->dev,
  7949. "SR-IOV=%d, num_vfs for all function=%u\n",
  7950. pf->hw.dev_caps.sr_iov_1_1,
  7951. pf->hw.dev_caps.num_vfs);
  7952. dev_info(&pf->pdev->dev,
  7953. "num_vsis=%u, num_rx:%u, num_tx=%u\n",
  7954. pf->hw.dev_caps.num_vsis,
  7955. pf->hw.dev_caps.num_rx_qp,
  7956. pf->hw.dev_caps.num_tx_qp);
  7957. }
  7958. }
  7959. if (list_type == i40e_aqc_opc_list_func_capabilities) {
  7960. #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
  7961. + pf->hw.func_caps.num_vfs)
  7962. if (pf->hw.revision_id == 0 &&
  7963. pf->hw.func_caps.num_vsis < DEF_NUM_VSI) {
  7964. dev_info(&pf->pdev->dev,
  7965. "got num_vsis %d, setting num_vsis to %d\n",
  7966. pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
  7967. pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
  7968. }
  7969. }
  7970. return 0;
  7971. }
  7972. static int i40e_vsi_clear(struct i40e_vsi *vsi);
  7973. /**
  7974. * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
  7975. * @pf: board private structure
  7976. **/
  7977. static void i40e_fdir_sb_setup(struct i40e_pf *pf)
  7978. {
  7979. struct i40e_vsi *vsi;
  7980. /* quick workaround for an NVM issue that leaves a critical register
  7981. * uninitialized
  7982. */
  7983. if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
  7984. static const u32 hkey[] = {
  7985. 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
  7986. 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
  7987. 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
  7988. 0x95b3a76d};
  7989. int i;
  7990. for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
  7991. wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
  7992. }
  7993. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  7994. return;
  7995. /* find existing VSI and see if it needs configuring */
  7996. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  7997. /* create a new VSI if none exists */
  7998. if (!vsi) {
  7999. vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
  8000. pf->vsi[pf->lan_vsi]->seid, 0);
  8001. if (!vsi) {
  8002. dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
  8003. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  8004. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  8005. return;
  8006. }
  8007. }
  8008. i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
  8009. }
  8010. /**
  8011. * i40e_fdir_teardown - release the Flow Director resources
  8012. * @pf: board private structure
  8013. **/
  8014. static void i40e_fdir_teardown(struct i40e_pf *pf)
  8015. {
  8016. struct i40e_vsi *vsi;
  8017. i40e_fdir_filter_exit(pf);
  8018. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  8019. if (vsi)
  8020. i40e_vsi_release(vsi);
  8021. }
  8022. /**
  8023. * i40e_rebuild_cloud_filters - Rebuilds cloud filters for VSIs
  8024. * @vsi: PF main vsi
  8025. * @seid: seid of main or channel VSIs
  8026. *
  8027. * Rebuilds cloud filters associated with main VSI and channel VSIs if they
  8028. * existed before reset
  8029. **/
  8030. static int i40e_rebuild_cloud_filters(struct i40e_vsi *vsi, u16 seid)
  8031. {
  8032. struct i40e_cloud_filter *cfilter;
  8033. struct i40e_pf *pf = vsi->back;
  8034. struct hlist_node *node;
  8035. i40e_status ret;
  8036. /* Add cloud filters back if they exist */
  8037. hlist_for_each_entry_safe(cfilter, node, &pf->cloud_filter_list,
  8038. cloud_node) {
  8039. if (cfilter->seid != seid)
  8040. continue;
  8041. if (cfilter->dst_port)
  8042. ret = i40e_add_del_cloud_filter_big_buf(vsi, cfilter,
  8043. true);
  8044. else
  8045. ret = i40e_add_del_cloud_filter(vsi, cfilter, true);
  8046. if (ret) {
  8047. dev_dbg(&pf->pdev->dev,
  8048. "Failed to rebuild cloud filter, err %s aq_err %s\n",
  8049. i40e_stat_str(&pf->hw, ret),
  8050. i40e_aq_str(&pf->hw,
  8051. pf->hw.aq.asq_last_status));
  8052. return ret;
  8053. }
  8054. }
  8055. return 0;
  8056. }
  8057. /**
  8058. * i40e_rebuild_channels - Rebuilds channel VSIs if they existed before reset
  8059. * @vsi: PF main vsi
  8060. *
  8061. * Rebuilds channel VSIs if they existed before reset
  8062. **/
  8063. static int i40e_rebuild_channels(struct i40e_vsi *vsi)
  8064. {
  8065. struct i40e_channel *ch, *ch_tmp;
  8066. i40e_status ret;
  8067. if (list_empty(&vsi->ch_list))
  8068. return 0;
  8069. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  8070. if (!ch->initialized)
  8071. break;
  8072. /* Proceed with creation of channel (VMDq2) VSI */
  8073. ret = i40e_add_channel(vsi->back, vsi->uplink_seid, ch);
  8074. if (ret) {
  8075. dev_info(&vsi->back->pdev->dev,
  8076. "failed to rebuild channels using uplink_seid %u\n",
  8077. vsi->uplink_seid);
  8078. return ret;
  8079. }
  8080. /* Reconfigure TX queues using QTX_CTL register */
  8081. ret = i40e_channel_config_tx_ring(vsi->back, vsi, ch);
  8082. if (ret) {
  8083. dev_info(&vsi->back->pdev->dev,
  8084. "failed to configure TX rings for channel %u\n",
  8085. ch->seid);
  8086. return ret;
  8087. }
  8088. /* update 'next_base_queue' */
  8089. vsi->next_base_queue = vsi->next_base_queue +
  8090. ch->num_queue_pairs;
  8091. if (ch->max_tx_rate) {
  8092. u64 credits = ch->max_tx_rate;
  8093. if (i40e_set_bw_limit(vsi, ch->seid,
  8094. ch->max_tx_rate))
  8095. return -EINVAL;
  8096. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  8097. dev_dbg(&vsi->back->pdev->dev,
  8098. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  8099. ch->max_tx_rate,
  8100. credits,
  8101. ch->seid);
  8102. }
  8103. ret = i40e_rebuild_cloud_filters(vsi, ch->seid);
  8104. if (ret) {
  8105. dev_dbg(&vsi->back->pdev->dev,
  8106. "Failed to rebuild cloud filters for channel VSI %u\n",
  8107. ch->seid);
  8108. return ret;
  8109. }
  8110. }
  8111. return 0;
  8112. }
  8113. /**
  8114. * i40e_prep_for_reset - prep for the core to reset
  8115. * @pf: board private structure
  8116. * @lock_acquired: indicates whether or not the lock has been acquired
  8117. * before this function was called.
  8118. *
  8119. * Close up the VFs and other things in prep for PF Reset.
  8120. **/
  8121. static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired)
  8122. {
  8123. struct i40e_hw *hw = &pf->hw;
  8124. i40e_status ret = 0;
  8125. u32 v;
  8126. clear_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
  8127. if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  8128. return;
  8129. if (i40e_check_asq_alive(&pf->hw))
  8130. i40e_vc_notify_reset(pf);
  8131. dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
  8132. /* quiesce the VSIs and their queues that are not already DOWN */
  8133. /* pf_quiesce_all_vsi modifies netdev structures -rtnl_lock needed */
  8134. if (!lock_acquired)
  8135. rtnl_lock();
  8136. i40e_pf_quiesce_all_vsi(pf);
  8137. if (!lock_acquired)
  8138. rtnl_unlock();
  8139. for (v = 0; v < pf->num_alloc_vsi; v++) {
  8140. if (pf->vsi[v])
  8141. pf->vsi[v]->seid = 0;
  8142. }
  8143. i40e_shutdown_adminq(&pf->hw);
  8144. /* call shutdown HMC */
  8145. if (hw->hmc.hmc_obj) {
  8146. ret = i40e_shutdown_lan_hmc(hw);
  8147. if (ret)
  8148. dev_warn(&pf->pdev->dev,
  8149. "shutdown_lan_hmc failed: %d\n", ret);
  8150. }
  8151. }
  8152. /**
  8153. * i40e_send_version - update firmware with driver version
  8154. * @pf: PF struct
  8155. */
  8156. static void i40e_send_version(struct i40e_pf *pf)
  8157. {
  8158. struct i40e_driver_version dv;
  8159. dv.major_version = DRV_VERSION_MAJOR;
  8160. dv.minor_version = DRV_VERSION_MINOR;
  8161. dv.build_version = DRV_VERSION_BUILD;
  8162. dv.subbuild_version = 0;
  8163. strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
  8164. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  8165. }
  8166. /**
  8167. * i40e_get_oem_version - get OEM specific version information
  8168. * @hw: pointer to the hardware structure
  8169. **/
  8170. static void i40e_get_oem_version(struct i40e_hw *hw)
  8171. {
  8172. u16 block_offset = 0xffff;
  8173. u16 block_length = 0;
  8174. u16 capabilities = 0;
  8175. u16 gen_snap = 0;
  8176. u16 release = 0;
  8177. #define I40E_SR_NVM_OEM_VERSION_PTR 0x1B
  8178. #define I40E_NVM_OEM_LENGTH_OFFSET 0x00
  8179. #define I40E_NVM_OEM_CAPABILITIES_OFFSET 0x01
  8180. #define I40E_NVM_OEM_GEN_OFFSET 0x02
  8181. #define I40E_NVM_OEM_RELEASE_OFFSET 0x03
  8182. #define I40E_NVM_OEM_CAPABILITIES_MASK 0x000F
  8183. #define I40E_NVM_OEM_LENGTH 3
  8184. /* Check if pointer to OEM version block is valid. */
  8185. i40e_read_nvm_word(hw, I40E_SR_NVM_OEM_VERSION_PTR, &block_offset);
  8186. if (block_offset == 0xffff)
  8187. return;
  8188. /* Check if OEM version block has correct length. */
  8189. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_LENGTH_OFFSET,
  8190. &block_length);
  8191. if (block_length < I40E_NVM_OEM_LENGTH)
  8192. return;
  8193. /* Check if OEM version format is as expected. */
  8194. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_CAPABILITIES_OFFSET,
  8195. &capabilities);
  8196. if ((capabilities & I40E_NVM_OEM_CAPABILITIES_MASK) != 0)
  8197. return;
  8198. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_GEN_OFFSET,
  8199. &gen_snap);
  8200. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_RELEASE_OFFSET,
  8201. &release);
  8202. hw->nvm.oem_ver = (gen_snap << I40E_OEM_SNAP_SHIFT) | release;
  8203. hw->nvm.eetrack = I40E_OEM_EETRACK_ID;
  8204. }
  8205. /**
  8206. * i40e_reset - wait for core reset to finish reset, reset pf if corer not seen
  8207. * @pf: board private structure
  8208. **/
  8209. static int i40e_reset(struct i40e_pf *pf)
  8210. {
  8211. struct i40e_hw *hw = &pf->hw;
  8212. i40e_status ret;
  8213. ret = i40e_pf_reset(hw);
  8214. if (ret) {
  8215. dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
  8216. set_bit(__I40E_RESET_FAILED, pf->state);
  8217. clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
  8218. } else {
  8219. pf->pfr_count++;
  8220. }
  8221. return ret;
  8222. }
  8223. /**
  8224. * i40e_rebuild - rebuild using a saved config
  8225. * @pf: board private structure
  8226. * @reinit: if the Main VSI needs to re-initialized.
  8227. * @lock_acquired: indicates whether or not the lock has been acquired
  8228. * before this function was called.
  8229. **/
  8230. static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired)
  8231. {
  8232. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  8233. struct i40e_hw *hw = &pf->hw;
  8234. i40e_status ret;
  8235. u32 val;
  8236. int v;
  8237. if (test_bit(__I40E_DOWN, pf->state))
  8238. goto clear_recovery;
  8239. dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
  8240. /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
  8241. ret = i40e_init_adminq(&pf->hw);
  8242. if (ret) {
  8243. dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
  8244. i40e_stat_str(&pf->hw, ret),
  8245. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8246. goto clear_recovery;
  8247. }
  8248. i40e_get_oem_version(&pf->hw);
  8249. if (test_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state) &&
  8250. ((hw->aq.fw_maj_ver == 4 && hw->aq.fw_min_ver <= 33) ||
  8251. hw->aq.fw_maj_ver < 4) && hw->mac.type == I40E_MAC_XL710) {
  8252. /* The following delay is necessary for 4.33 firmware and older
  8253. * to recover after EMP reset. 200 ms should suffice but we
  8254. * put here 300 ms to be sure that FW is ready to operate
  8255. * after reset.
  8256. */
  8257. mdelay(300);
  8258. }
  8259. /* re-verify the eeprom if we just had an EMP reset */
  8260. if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state))
  8261. i40e_verify_eeprom(pf);
  8262. i40e_clear_pxe_mode(hw);
  8263. ret = i40e_get_capabilities(pf, i40e_aqc_opc_list_func_capabilities);
  8264. if (ret)
  8265. goto end_core_reset;
  8266. ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  8267. hw->func_caps.num_rx_qp, 0, 0);
  8268. if (ret) {
  8269. dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
  8270. goto end_core_reset;
  8271. }
  8272. ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  8273. if (ret) {
  8274. dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
  8275. goto end_core_reset;
  8276. }
  8277. /* Enable FW to write a default DCB config on link-up */
  8278. i40e_aq_set_dcb_parameters(hw, true, NULL);
  8279. #ifdef CONFIG_I40E_DCB
  8280. ret = i40e_init_pf_dcb(pf);
  8281. if (ret) {
  8282. dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
  8283. pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
  8284. /* Continue without DCB enabled */
  8285. }
  8286. #endif /* CONFIG_I40E_DCB */
  8287. /* do basic switch setup */
  8288. if (!lock_acquired)
  8289. rtnl_lock();
  8290. ret = i40e_setup_pf_switch(pf, reinit);
  8291. if (ret)
  8292. goto end_unlock;
  8293. /* The driver only wants link up/down and module qualification
  8294. * reports from firmware. Note the negative logic.
  8295. */
  8296. ret = i40e_aq_set_phy_int_mask(&pf->hw,
  8297. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  8298. I40E_AQ_EVENT_MEDIA_NA |
  8299. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  8300. if (ret)
  8301. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  8302. i40e_stat_str(&pf->hw, ret),
  8303. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8304. /* Rebuild the VSIs and VEBs that existed before reset.
  8305. * They are still in our local switch element arrays, so only
  8306. * need to rebuild the switch model in the HW.
  8307. *
  8308. * If there were VEBs but the reconstitution failed, we'll try
  8309. * try to recover minimal use by getting the basic PF VSI working.
  8310. */
  8311. if (vsi->uplink_seid != pf->mac_seid) {
  8312. dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
  8313. /* find the one VEB connected to the MAC, and find orphans */
  8314. for (v = 0; v < I40E_MAX_VEB; v++) {
  8315. if (!pf->veb[v])
  8316. continue;
  8317. if (pf->veb[v]->uplink_seid == pf->mac_seid ||
  8318. pf->veb[v]->uplink_seid == 0) {
  8319. ret = i40e_reconstitute_veb(pf->veb[v]);
  8320. if (!ret)
  8321. continue;
  8322. /* If Main VEB failed, we're in deep doodoo,
  8323. * so give up rebuilding the switch and set up
  8324. * for minimal rebuild of PF VSI.
  8325. * If orphan failed, we'll report the error
  8326. * but try to keep going.
  8327. */
  8328. if (pf->veb[v]->uplink_seid == pf->mac_seid) {
  8329. dev_info(&pf->pdev->dev,
  8330. "rebuild of switch failed: %d, will try to set up simple PF connection\n",
  8331. ret);
  8332. vsi->uplink_seid = pf->mac_seid;
  8333. break;
  8334. } else if (pf->veb[v]->uplink_seid == 0) {
  8335. dev_info(&pf->pdev->dev,
  8336. "rebuild of orphan VEB failed: %d\n",
  8337. ret);
  8338. }
  8339. }
  8340. }
  8341. }
  8342. if (vsi->uplink_seid == pf->mac_seid) {
  8343. dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
  8344. /* no VEB, so rebuild only the Main VSI */
  8345. ret = i40e_add_vsi(vsi);
  8346. if (ret) {
  8347. dev_info(&pf->pdev->dev,
  8348. "rebuild of Main VSI failed: %d\n", ret);
  8349. goto end_unlock;
  8350. }
  8351. }
  8352. if (vsi->mqprio_qopt.max_rate[0]) {
  8353. u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
  8354. u64 credits = 0;
  8355. do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
  8356. ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
  8357. if (ret)
  8358. goto end_unlock;
  8359. credits = max_tx_rate;
  8360. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  8361. dev_dbg(&vsi->back->pdev->dev,
  8362. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  8363. max_tx_rate,
  8364. credits,
  8365. vsi->seid);
  8366. }
  8367. ret = i40e_rebuild_cloud_filters(vsi, vsi->seid);
  8368. if (ret)
  8369. goto end_unlock;
  8370. /* PF Main VSI is rebuild by now, go ahead and rebuild channel VSIs
  8371. * for this main VSI if they exist
  8372. */
  8373. ret = i40e_rebuild_channels(vsi);
  8374. if (ret)
  8375. goto end_unlock;
  8376. /* Reconfigure hardware for allowing smaller MSS in the case
  8377. * of TSO, so that we avoid the MDD being fired and causing
  8378. * a reset in the case of small MSS+TSO.
  8379. */
  8380. #define I40E_REG_MSS 0x000E64DC
  8381. #define I40E_REG_MSS_MIN_MASK 0x3FF0000
  8382. #define I40E_64BYTE_MSS 0x400000
  8383. val = rd32(hw, I40E_REG_MSS);
  8384. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  8385. val &= ~I40E_REG_MSS_MIN_MASK;
  8386. val |= I40E_64BYTE_MSS;
  8387. wr32(hw, I40E_REG_MSS, val);
  8388. }
  8389. if (pf->hw_features & I40E_HW_RESTART_AUTONEG) {
  8390. msleep(75);
  8391. ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  8392. if (ret)
  8393. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  8394. i40e_stat_str(&pf->hw, ret),
  8395. i40e_aq_str(&pf->hw,
  8396. pf->hw.aq.asq_last_status));
  8397. }
  8398. /* reinit the misc interrupt */
  8399. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  8400. ret = i40e_setup_misc_vector(pf);
  8401. /* Add a filter to drop all Flow control frames from any VSI from being
  8402. * transmitted. By doing so we stop a malicious VF from sending out
  8403. * PAUSE or PFC frames and potentially controlling traffic for other
  8404. * PF/VF VSIs.
  8405. * The FW can still send Flow control frames if enabled.
  8406. */
  8407. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  8408. pf->main_vsi_seid);
  8409. /* restart the VSIs that were rebuilt and running before the reset */
  8410. i40e_pf_unquiesce_all_vsi(pf);
  8411. /* Release the RTNL lock before we start resetting VFs */
  8412. if (!lock_acquired)
  8413. rtnl_unlock();
  8414. /* Restore promiscuous settings */
  8415. ret = i40e_set_promiscuous(pf, pf->cur_promisc);
  8416. if (ret)
  8417. dev_warn(&pf->pdev->dev,
  8418. "Failed to restore promiscuous setting: %s, err %s aq_err %s\n",
  8419. pf->cur_promisc ? "on" : "off",
  8420. i40e_stat_str(&pf->hw, ret),
  8421. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8422. i40e_reset_all_vfs(pf, true);
  8423. /* tell the firmware that we're starting */
  8424. i40e_send_version(pf);
  8425. /* We've already released the lock, so don't do it again */
  8426. goto end_core_reset;
  8427. end_unlock:
  8428. if (!lock_acquired)
  8429. rtnl_unlock();
  8430. end_core_reset:
  8431. clear_bit(__I40E_RESET_FAILED, pf->state);
  8432. clear_recovery:
  8433. clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
  8434. clear_bit(__I40E_TIMEOUT_RECOVERY_PENDING, pf->state);
  8435. }
  8436. /**
  8437. * i40e_reset_and_rebuild - reset and rebuild using a saved config
  8438. * @pf: board private structure
  8439. * @reinit: if the Main VSI needs to re-initialized.
  8440. * @lock_acquired: indicates whether or not the lock has been acquired
  8441. * before this function was called.
  8442. **/
  8443. static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit,
  8444. bool lock_acquired)
  8445. {
  8446. int ret;
  8447. /* Now we wait for GRST to settle out.
  8448. * We don't have to delete the VEBs or VSIs from the hw switch
  8449. * because the reset will make them disappear.
  8450. */
  8451. ret = i40e_reset(pf);
  8452. if (!ret)
  8453. i40e_rebuild(pf, reinit, lock_acquired);
  8454. }
  8455. /**
  8456. * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
  8457. * @pf: board private structure
  8458. *
  8459. * Close up the VFs and other things in prep for a Core Reset,
  8460. * then get ready to rebuild the world.
  8461. * @lock_acquired: indicates whether or not the lock has been acquired
  8462. * before this function was called.
  8463. **/
  8464. static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired)
  8465. {
  8466. i40e_prep_for_reset(pf, lock_acquired);
  8467. i40e_reset_and_rebuild(pf, false, lock_acquired);
  8468. }
  8469. /**
  8470. * i40e_handle_mdd_event
  8471. * @pf: pointer to the PF structure
  8472. *
  8473. * Called from the MDD irq handler to identify possibly malicious vfs
  8474. **/
  8475. static void i40e_handle_mdd_event(struct i40e_pf *pf)
  8476. {
  8477. struct i40e_hw *hw = &pf->hw;
  8478. bool mdd_detected = false;
  8479. bool pf_mdd_detected = false;
  8480. struct i40e_vf *vf;
  8481. u32 reg;
  8482. int i;
  8483. if (!test_bit(__I40E_MDD_EVENT_PENDING, pf->state))
  8484. return;
  8485. /* find what triggered the MDD event */
  8486. reg = rd32(hw, I40E_GL_MDET_TX);
  8487. if (reg & I40E_GL_MDET_TX_VALID_MASK) {
  8488. u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
  8489. I40E_GL_MDET_TX_PF_NUM_SHIFT;
  8490. u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
  8491. I40E_GL_MDET_TX_VF_NUM_SHIFT;
  8492. u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
  8493. I40E_GL_MDET_TX_EVENT_SHIFT;
  8494. u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
  8495. I40E_GL_MDET_TX_QUEUE_SHIFT) -
  8496. pf->hw.func_caps.base_queue;
  8497. if (netif_msg_tx_err(pf))
  8498. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
  8499. event, queue, pf_num, vf_num);
  8500. wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
  8501. mdd_detected = true;
  8502. }
  8503. reg = rd32(hw, I40E_GL_MDET_RX);
  8504. if (reg & I40E_GL_MDET_RX_VALID_MASK) {
  8505. u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
  8506. I40E_GL_MDET_RX_FUNCTION_SHIFT;
  8507. u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
  8508. I40E_GL_MDET_RX_EVENT_SHIFT;
  8509. u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
  8510. I40E_GL_MDET_RX_QUEUE_SHIFT) -
  8511. pf->hw.func_caps.base_queue;
  8512. if (netif_msg_rx_err(pf))
  8513. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
  8514. event, queue, func);
  8515. wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
  8516. mdd_detected = true;
  8517. }
  8518. if (mdd_detected) {
  8519. reg = rd32(hw, I40E_PF_MDET_TX);
  8520. if (reg & I40E_PF_MDET_TX_VALID_MASK) {
  8521. wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
  8522. dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
  8523. pf_mdd_detected = true;
  8524. }
  8525. reg = rd32(hw, I40E_PF_MDET_RX);
  8526. if (reg & I40E_PF_MDET_RX_VALID_MASK) {
  8527. wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
  8528. dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
  8529. pf_mdd_detected = true;
  8530. }
  8531. /* Queue belongs to the PF, initiate a reset */
  8532. if (pf_mdd_detected) {
  8533. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  8534. i40e_service_event_schedule(pf);
  8535. }
  8536. }
  8537. /* see if one of the VFs needs its hand slapped */
  8538. for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
  8539. vf = &(pf->vf[i]);
  8540. reg = rd32(hw, I40E_VP_MDET_TX(i));
  8541. if (reg & I40E_VP_MDET_TX_VALID_MASK) {
  8542. wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
  8543. vf->num_mdd_events++;
  8544. dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
  8545. i);
  8546. }
  8547. reg = rd32(hw, I40E_VP_MDET_RX(i));
  8548. if (reg & I40E_VP_MDET_RX_VALID_MASK) {
  8549. wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
  8550. vf->num_mdd_events++;
  8551. dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
  8552. i);
  8553. }
  8554. if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
  8555. dev_info(&pf->pdev->dev,
  8556. "Too many MDD events on VF %d, disabled\n", i);
  8557. dev_info(&pf->pdev->dev,
  8558. "Use PF Control I/F to re-enable the VF\n");
  8559. set_bit(I40E_VF_STATE_DISABLED, &vf->vf_states);
  8560. }
  8561. }
  8562. /* re-enable mdd interrupt cause */
  8563. clear_bit(__I40E_MDD_EVENT_PENDING, pf->state);
  8564. reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  8565. reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  8566. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  8567. i40e_flush(hw);
  8568. }
  8569. static const char *i40e_tunnel_name(u8 type)
  8570. {
  8571. switch (type) {
  8572. case UDP_TUNNEL_TYPE_VXLAN:
  8573. return "vxlan";
  8574. case UDP_TUNNEL_TYPE_GENEVE:
  8575. return "geneve";
  8576. default:
  8577. return "unknown";
  8578. }
  8579. }
  8580. /**
  8581. * i40e_sync_udp_filters - Trigger a sync event for existing UDP filters
  8582. * @pf: board private structure
  8583. **/
  8584. static void i40e_sync_udp_filters(struct i40e_pf *pf)
  8585. {
  8586. int i;
  8587. /* loop through and set pending bit for all active UDP filters */
  8588. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  8589. if (pf->udp_ports[i].port)
  8590. pf->pending_udp_bitmap |= BIT_ULL(i);
  8591. }
  8592. set_bit(__I40E_UDP_FILTER_SYNC_PENDING, pf->state);
  8593. }
  8594. /**
  8595. * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
  8596. * @pf: board private structure
  8597. **/
  8598. static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
  8599. {
  8600. struct i40e_hw *hw = &pf->hw;
  8601. u8 filter_index, type;
  8602. u16 port;
  8603. int i;
  8604. if (!test_and_clear_bit(__I40E_UDP_FILTER_SYNC_PENDING, pf->state))
  8605. return;
  8606. /* acquire RTNL to maintain state of flags and port requests */
  8607. rtnl_lock();
  8608. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  8609. if (pf->pending_udp_bitmap & BIT_ULL(i)) {
  8610. struct i40e_udp_port_config *udp_port;
  8611. i40e_status ret = 0;
  8612. udp_port = &pf->udp_ports[i];
  8613. pf->pending_udp_bitmap &= ~BIT_ULL(i);
  8614. port = READ_ONCE(udp_port->port);
  8615. type = READ_ONCE(udp_port->type);
  8616. filter_index = READ_ONCE(udp_port->filter_index);
  8617. /* release RTNL while we wait on AQ command */
  8618. rtnl_unlock();
  8619. if (port)
  8620. ret = i40e_aq_add_udp_tunnel(hw, port,
  8621. type,
  8622. &filter_index,
  8623. NULL);
  8624. else if (filter_index != I40E_UDP_PORT_INDEX_UNUSED)
  8625. ret = i40e_aq_del_udp_tunnel(hw, filter_index,
  8626. NULL);
  8627. /* reacquire RTNL so we can update filter_index */
  8628. rtnl_lock();
  8629. if (ret) {
  8630. dev_info(&pf->pdev->dev,
  8631. "%s %s port %d, index %d failed, err %s aq_err %s\n",
  8632. i40e_tunnel_name(type),
  8633. port ? "add" : "delete",
  8634. port,
  8635. filter_index,
  8636. i40e_stat_str(&pf->hw, ret),
  8637. i40e_aq_str(&pf->hw,
  8638. pf->hw.aq.asq_last_status));
  8639. if (port) {
  8640. /* failed to add, just reset port,
  8641. * drop pending bit for any deletion
  8642. */
  8643. udp_port->port = 0;
  8644. pf->pending_udp_bitmap &= ~BIT_ULL(i);
  8645. }
  8646. } else if (port) {
  8647. /* record filter index on success */
  8648. udp_port->filter_index = filter_index;
  8649. }
  8650. }
  8651. }
  8652. rtnl_unlock();
  8653. }
  8654. /**
  8655. * i40e_service_task - Run the driver's async subtasks
  8656. * @work: pointer to work_struct containing our data
  8657. **/
  8658. static void i40e_service_task(struct work_struct *work)
  8659. {
  8660. struct i40e_pf *pf = container_of(work,
  8661. struct i40e_pf,
  8662. service_task);
  8663. unsigned long start_time = jiffies;
  8664. /* don't bother with service tasks if a reset is in progress */
  8665. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  8666. return;
  8667. if (test_and_set_bit(__I40E_SERVICE_SCHED, pf->state))
  8668. return;
  8669. i40e_detect_recover_hung(pf->vsi[pf->lan_vsi]);
  8670. i40e_sync_filters_subtask(pf);
  8671. i40e_reset_subtask(pf);
  8672. i40e_handle_mdd_event(pf);
  8673. i40e_vc_process_vflr_event(pf);
  8674. i40e_watchdog_subtask(pf);
  8675. i40e_fdir_reinit_subtask(pf);
  8676. if (test_and_clear_bit(__I40E_CLIENT_RESET, pf->state)) {
  8677. /* Client subtask will reopen next time through. */
  8678. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], true);
  8679. } else {
  8680. i40e_client_subtask(pf);
  8681. if (test_and_clear_bit(__I40E_CLIENT_L2_CHANGE,
  8682. pf->state))
  8683. i40e_notify_client_of_l2_param_changes(
  8684. pf->vsi[pf->lan_vsi]);
  8685. }
  8686. i40e_sync_filters_subtask(pf);
  8687. i40e_sync_udp_filters_subtask(pf);
  8688. i40e_clean_adminq_subtask(pf);
  8689. /* flush memory to make sure state is correct before next watchdog */
  8690. smp_mb__before_atomic();
  8691. clear_bit(__I40E_SERVICE_SCHED, pf->state);
  8692. /* If the tasks have taken longer than one timer cycle or there
  8693. * is more work to be done, reschedule the service task now
  8694. * rather than wait for the timer to tick again.
  8695. */
  8696. if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
  8697. test_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state) ||
  8698. test_bit(__I40E_MDD_EVENT_PENDING, pf->state) ||
  8699. test_bit(__I40E_VFLR_EVENT_PENDING, pf->state))
  8700. i40e_service_event_schedule(pf);
  8701. }
  8702. /**
  8703. * i40e_service_timer - timer callback
  8704. * @data: pointer to PF struct
  8705. **/
  8706. static void i40e_service_timer(struct timer_list *t)
  8707. {
  8708. struct i40e_pf *pf = from_timer(pf, t, service_timer);
  8709. mod_timer(&pf->service_timer,
  8710. round_jiffies(jiffies + pf->service_timer_period));
  8711. i40e_service_event_schedule(pf);
  8712. }
  8713. /**
  8714. * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
  8715. * @vsi: the VSI being configured
  8716. **/
  8717. static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
  8718. {
  8719. struct i40e_pf *pf = vsi->back;
  8720. switch (vsi->type) {
  8721. case I40E_VSI_MAIN:
  8722. vsi->alloc_queue_pairs = pf->num_lan_qps;
  8723. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  8724. I40E_REQ_DESCRIPTOR_MULTIPLE);
  8725. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  8726. vsi->num_q_vectors = pf->num_lan_msix;
  8727. else
  8728. vsi->num_q_vectors = 1;
  8729. break;
  8730. case I40E_VSI_FDIR:
  8731. vsi->alloc_queue_pairs = 1;
  8732. vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
  8733. I40E_REQ_DESCRIPTOR_MULTIPLE);
  8734. vsi->num_q_vectors = pf->num_fdsb_msix;
  8735. break;
  8736. case I40E_VSI_VMDQ2:
  8737. vsi->alloc_queue_pairs = pf->num_vmdq_qps;
  8738. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  8739. I40E_REQ_DESCRIPTOR_MULTIPLE);
  8740. vsi->num_q_vectors = pf->num_vmdq_msix;
  8741. break;
  8742. case I40E_VSI_SRIOV:
  8743. vsi->alloc_queue_pairs = pf->num_vf_qps;
  8744. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  8745. I40E_REQ_DESCRIPTOR_MULTIPLE);
  8746. break;
  8747. default:
  8748. WARN_ON(1);
  8749. return -ENODATA;
  8750. }
  8751. return 0;
  8752. }
  8753. /**
  8754. * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
  8755. * @vsi: VSI pointer
  8756. * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
  8757. *
  8758. * On error: returns error code (negative)
  8759. * On success: returns 0
  8760. **/
  8761. static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
  8762. {
  8763. struct i40e_ring **next_rings;
  8764. int size;
  8765. int ret = 0;
  8766. /* allocate memory for both Tx, XDP Tx and Rx ring pointers */
  8767. size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs *
  8768. (i40e_enabled_xdp_vsi(vsi) ? 3 : 2);
  8769. vsi->tx_rings = kzalloc(size, GFP_KERNEL);
  8770. if (!vsi->tx_rings)
  8771. return -ENOMEM;
  8772. next_rings = vsi->tx_rings + vsi->alloc_queue_pairs;
  8773. if (i40e_enabled_xdp_vsi(vsi)) {
  8774. vsi->xdp_rings = next_rings;
  8775. next_rings += vsi->alloc_queue_pairs;
  8776. }
  8777. vsi->rx_rings = next_rings;
  8778. if (alloc_qvectors) {
  8779. /* allocate memory for q_vector pointers */
  8780. size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
  8781. vsi->q_vectors = kzalloc(size, GFP_KERNEL);
  8782. if (!vsi->q_vectors) {
  8783. ret = -ENOMEM;
  8784. goto err_vectors;
  8785. }
  8786. }
  8787. return ret;
  8788. err_vectors:
  8789. kfree(vsi->tx_rings);
  8790. return ret;
  8791. }
  8792. /**
  8793. * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
  8794. * @pf: board private structure
  8795. * @type: type of VSI
  8796. *
  8797. * On error: returns error code (negative)
  8798. * On success: returns vsi index in PF (positive)
  8799. **/
  8800. static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
  8801. {
  8802. int ret = -ENODEV;
  8803. struct i40e_vsi *vsi;
  8804. int vsi_idx;
  8805. int i;
  8806. /* Need to protect the allocation of the VSIs at the PF level */
  8807. mutex_lock(&pf->switch_mutex);
  8808. /* VSI list may be fragmented if VSI creation/destruction has
  8809. * been happening. We can afford to do a quick scan to look
  8810. * for any free VSIs in the list.
  8811. *
  8812. * find next empty vsi slot, looping back around if necessary
  8813. */
  8814. i = pf->next_vsi;
  8815. while (i < pf->num_alloc_vsi && pf->vsi[i])
  8816. i++;
  8817. if (i >= pf->num_alloc_vsi) {
  8818. i = 0;
  8819. while (i < pf->next_vsi && pf->vsi[i])
  8820. i++;
  8821. }
  8822. if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
  8823. vsi_idx = i; /* Found one! */
  8824. } else {
  8825. ret = -ENODEV;
  8826. goto unlock_pf; /* out of VSI slots! */
  8827. }
  8828. pf->next_vsi = ++i;
  8829. vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
  8830. if (!vsi) {
  8831. ret = -ENOMEM;
  8832. goto unlock_pf;
  8833. }
  8834. vsi->type = type;
  8835. vsi->back = pf;
  8836. set_bit(__I40E_VSI_DOWN, vsi->state);
  8837. vsi->flags = 0;
  8838. vsi->idx = vsi_idx;
  8839. vsi->int_rate_limit = 0;
  8840. vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
  8841. pf->rss_table_size : 64;
  8842. vsi->netdev_registered = false;
  8843. vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
  8844. hash_init(vsi->mac_filter_hash);
  8845. vsi->irqs_ready = false;
  8846. ret = i40e_set_num_rings_in_vsi(vsi);
  8847. if (ret)
  8848. goto err_rings;
  8849. ret = i40e_vsi_alloc_arrays(vsi, true);
  8850. if (ret)
  8851. goto err_rings;
  8852. /* Setup default MSIX irq handler for VSI */
  8853. i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
  8854. /* Initialize VSI lock */
  8855. spin_lock_init(&vsi->mac_filter_hash_lock);
  8856. pf->vsi[vsi_idx] = vsi;
  8857. ret = vsi_idx;
  8858. goto unlock_pf;
  8859. err_rings:
  8860. pf->next_vsi = i - 1;
  8861. kfree(vsi);
  8862. unlock_pf:
  8863. mutex_unlock(&pf->switch_mutex);
  8864. return ret;
  8865. }
  8866. /**
  8867. * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
  8868. * @vsi: VSI pointer
  8869. * @free_qvectors: a bool to specify if q_vectors need to be freed.
  8870. *
  8871. * On error: returns error code (negative)
  8872. * On success: returns 0
  8873. **/
  8874. static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
  8875. {
  8876. /* free the ring and vector containers */
  8877. if (free_qvectors) {
  8878. kfree(vsi->q_vectors);
  8879. vsi->q_vectors = NULL;
  8880. }
  8881. kfree(vsi->tx_rings);
  8882. vsi->tx_rings = NULL;
  8883. vsi->rx_rings = NULL;
  8884. vsi->xdp_rings = NULL;
  8885. }
  8886. /**
  8887. * i40e_clear_rss_config_user - clear the user configured RSS hash keys
  8888. * and lookup table
  8889. * @vsi: Pointer to VSI structure
  8890. */
  8891. static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
  8892. {
  8893. if (!vsi)
  8894. return;
  8895. kfree(vsi->rss_hkey_user);
  8896. vsi->rss_hkey_user = NULL;
  8897. kfree(vsi->rss_lut_user);
  8898. vsi->rss_lut_user = NULL;
  8899. }
  8900. /**
  8901. * i40e_vsi_clear - Deallocate the VSI provided
  8902. * @vsi: the VSI being un-configured
  8903. **/
  8904. static int i40e_vsi_clear(struct i40e_vsi *vsi)
  8905. {
  8906. struct i40e_pf *pf;
  8907. if (!vsi)
  8908. return 0;
  8909. if (!vsi->back)
  8910. goto free_vsi;
  8911. pf = vsi->back;
  8912. mutex_lock(&pf->switch_mutex);
  8913. if (!pf->vsi[vsi->idx]) {
  8914. dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](type %d)\n",
  8915. vsi->idx, vsi->idx, vsi->type);
  8916. goto unlock_vsi;
  8917. }
  8918. if (pf->vsi[vsi->idx] != vsi) {
  8919. dev_err(&pf->pdev->dev,
  8920. "pf->vsi[%d](type %d) != vsi[%d](type %d): no free!\n",
  8921. pf->vsi[vsi->idx]->idx,
  8922. pf->vsi[vsi->idx]->type,
  8923. vsi->idx, vsi->type);
  8924. goto unlock_vsi;
  8925. }
  8926. /* updates the PF for this cleared vsi */
  8927. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  8928. i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
  8929. i40e_vsi_free_arrays(vsi, true);
  8930. i40e_clear_rss_config_user(vsi);
  8931. pf->vsi[vsi->idx] = NULL;
  8932. if (vsi->idx < pf->next_vsi)
  8933. pf->next_vsi = vsi->idx;
  8934. unlock_vsi:
  8935. mutex_unlock(&pf->switch_mutex);
  8936. free_vsi:
  8937. kfree(vsi);
  8938. return 0;
  8939. }
  8940. /**
  8941. * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
  8942. * @vsi: the VSI being cleaned
  8943. **/
  8944. static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
  8945. {
  8946. int i;
  8947. if (vsi->tx_rings && vsi->tx_rings[0]) {
  8948. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  8949. kfree_rcu(vsi->tx_rings[i], rcu);
  8950. WRITE_ONCE(vsi->tx_rings[i], NULL);
  8951. WRITE_ONCE(vsi->rx_rings[i], NULL);
  8952. if (vsi->xdp_rings)
  8953. WRITE_ONCE(vsi->xdp_rings[i], NULL);
  8954. }
  8955. }
  8956. }
  8957. /**
  8958. * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
  8959. * @vsi: the VSI being configured
  8960. **/
  8961. static int i40e_alloc_rings(struct i40e_vsi *vsi)
  8962. {
  8963. int i, qpv = i40e_enabled_xdp_vsi(vsi) ? 3 : 2;
  8964. struct i40e_pf *pf = vsi->back;
  8965. struct i40e_ring *ring;
  8966. /* Set basic values in the rings to be used later during open() */
  8967. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  8968. /* allocate space for both Tx and Rx in one shot */
  8969. ring = kcalloc(qpv, sizeof(struct i40e_ring), GFP_KERNEL);
  8970. if (!ring)
  8971. goto err_out;
  8972. ring->queue_index = i;
  8973. ring->reg_idx = vsi->base_queue + i;
  8974. ring->ring_active = false;
  8975. ring->vsi = vsi;
  8976. ring->netdev = vsi->netdev;
  8977. ring->dev = &pf->pdev->dev;
  8978. ring->count = vsi->num_desc;
  8979. ring->size = 0;
  8980. ring->dcb_tc = 0;
  8981. if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE)
  8982. ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
  8983. ring->itr_setting = pf->tx_itr_default;
  8984. WRITE_ONCE(vsi->tx_rings[i], ring++);
  8985. if (!i40e_enabled_xdp_vsi(vsi))
  8986. goto setup_rx;
  8987. ring->queue_index = vsi->alloc_queue_pairs + i;
  8988. ring->reg_idx = vsi->base_queue + ring->queue_index;
  8989. ring->ring_active = false;
  8990. ring->vsi = vsi;
  8991. ring->netdev = NULL;
  8992. ring->dev = &pf->pdev->dev;
  8993. ring->count = vsi->num_desc;
  8994. ring->size = 0;
  8995. ring->dcb_tc = 0;
  8996. if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE)
  8997. ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
  8998. set_ring_xdp(ring);
  8999. ring->itr_setting = pf->tx_itr_default;
  9000. WRITE_ONCE(vsi->xdp_rings[i], ring++);
  9001. setup_rx:
  9002. ring->queue_index = i;
  9003. ring->reg_idx = vsi->base_queue + i;
  9004. ring->ring_active = false;
  9005. ring->vsi = vsi;
  9006. ring->netdev = vsi->netdev;
  9007. ring->dev = &pf->pdev->dev;
  9008. ring->count = vsi->num_desc;
  9009. ring->size = 0;
  9010. ring->dcb_tc = 0;
  9011. ring->itr_setting = pf->rx_itr_default;
  9012. WRITE_ONCE(vsi->rx_rings[i], ring);
  9013. }
  9014. return 0;
  9015. err_out:
  9016. i40e_vsi_clear_rings(vsi);
  9017. return -ENOMEM;
  9018. }
  9019. /**
  9020. * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
  9021. * @pf: board private structure
  9022. * @vectors: the number of MSI-X vectors to request
  9023. *
  9024. * Returns the number of vectors reserved, or error
  9025. **/
  9026. static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
  9027. {
  9028. vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
  9029. I40E_MIN_MSIX, vectors);
  9030. if (vectors < 0) {
  9031. dev_info(&pf->pdev->dev,
  9032. "MSI-X vector reservation failed: %d\n", vectors);
  9033. vectors = 0;
  9034. }
  9035. return vectors;
  9036. }
  9037. /**
  9038. * i40e_init_msix - Setup the MSIX capability
  9039. * @pf: board private structure
  9040. *
  9041. * Work with the OS to set up the MSIX vectors needed.
  9042. *
  9043. * Returns the number of vectors reserved or negative on failure
  9044. **/
  9045. static int i40e_init_msix(struct i40e_pf *pf)
  9046. {
  9047. struct i40e_hw *hw = &pf->hw;
  9048. int cpus, extra_vectors;
  9049. int vectors_left;
  9050. int v_budget, i;
  9051. int v_actual;
  9052. int iwarp_requested = 0;
  9053. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  9054. return -ENODEV;
  9055. /* The number of vectors we'll request will be comprised of:
  9056. * - Add 1 for "other" cause for Admin Queue events, etc.
  9057. * - The number of LAN queue pairs
  9058. * - Queues being used for RSS.
  9059. * We don't need as many as max_rss_size vectors.
  9060. * use rss_size instead in the calculation since that
  9061. * is governed by number of cpus in the system.
  9062. * - assumes symmetric Tx/Rx pairing
  9063. * - The number of VMDq pairs
  9064. * - The CPU count within the NUMA node if iWARP is enabled
  9065. * Once we count this up, try the request.
  9066. *
  9067. * If we can't get what we want, we'll simplify to nearly nothing
  9068. * and try again. If that still fails, we punt.
  9069. */
  9070. vectors_left = hw->func_caps.num_msix_vectors;
  9071. v_budget = 0;
  9072. /* reserve one vector for miscellaneous handler */
  9073. if (vectors_left) {
  9074. v_budget++;
  9075. vectors_left--;
  9076. }
  9077. /* reserve some vectors for the main PF traffic queues. Initially we
  9078. * only reserve at most 50% of the available vectors, in the case that
  9079. * the number of online CPUs is large. This ensures that we can enable
  9080. * extra features as well. Once we've enabled the other features, we
  9081. * will use any remaining vectors to reach as close as we can to the
  9082. * number of online CPUs.
  9083. */
  9084. cpus = num_online_cpus();
  9085. pf->num_lan_msix = min_t(int, cpus, vectors_left / 2);
  9086. vectors_left -= pf->num_lan_msix;
  9087. /* reserve one vector for sideband flow director */
  9088. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9089. if (vectors_left) {
  9090. pf->num_fdsb_msix = 1;
  9091. v_budget++;
  9092. vectors_left--;
  9093. } else {
  9094. pf->num_fdsb_msix = 0;
  9095. }
  9096. }
  9097. /* can we reserve enough for iWARP? */
  9098. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  9099. iwarp_requested = pf->num_iwarp_msix;
  9100. if (!vectors_left)
  9101. pf->num_iwarp_msix = 0;
  9102. else if (vectors_left < pf->num_iwarp_msix)
  9103. pf->num_iwarp_msix = 1;
  9104. v_budget += pf->num_iwarp_msix;
  9105. vectors_left -= pf->num_iwarp_msix;
  9106. }
  9107. /* any vectors left over go for VMDq support */
  9108. if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
  9109. if (!vectors_left) {
  9110. pf->num_vmdq_msix = 0;
  9111. pf->num_vmdq_qps = 0;
  9112. } else {
  9113. int vmdq_vecs_wanted =
  9114. pf->num_vmdq_vsis * pf->num_vmdq_qps;
  9115. int vmdq_vecs =
  9116. min_t(int, vectors_left, vmdq_vecs_wanted);
  9117. /* if we're short on vectors for what's desired, we limit
  9118. * the queues per vmdq. If this is still more than are
  9119. * available, the user will need to change the number of
  9120. * queues/vectors used by the PF later with the ethtool
  9121. * channels command
  9122. */
  9123. if (vectors_left < vmdq_vecs_wanted) {
  9124. pf->num_vmdq_qps = 1;
  9125. vmdq_vecs_wanted = pf->num_vmdq_vsis;
  9126. vmdq_vecs = min_t(int,
  9127. vectors_left,
  9128. vmdq_vecs_wanted);
  9129. }
  9130. pf->num_vmdq_msix = pf->num_vmdq_qps;
  9131. v_budget += vmdq_vecs;
  9132. vectors_left -= vmdq_vecs;
  9133. }
  9134. }
  9135. /* On systems with a large number of SMP cores, we previously limited
  9136. * the number of vectors for num_lan_msix to be at most 50% of the
  9137. * available vectors, to allow for other features. Now, we add back
  9138. * the remaining vectors. However, we ensure that the total
  9139. * num_lan_msix will not exceed num_online_cpus(). To do this, we
  9140. * calculate the number of vectors we can add without going over the
  9141. * cap of CPUs. For systems with a small number of CPUs this will be
  9142. * zero.
  9143. */
  9144. extra_vectors = min_t(int, cpus - pf->num_lan_msix, vectors_left);
  9145. pf->num_lan_msix += extra_vectors;
  9146. vectors_left -= extra_vectors;
  9147. WARN(vectors_left < 0,
  9148. "Calculation of remaining vectors underflowed. This is an accounting bug when determining total MSI-X vectors.\n");
  9149. v_budget += pf->num_lan_msix;
  9150. pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
  9151. GFP_KERNEL);
  9152. if (!pf->msix_entries)
  9153. return -ENOMEM;
  9154. for (i = 0; i < v_budget; i++)
  9155. pf->msix_entries[i].entry = i;
  9156. v_actual = i40e_reserve_msix_vectors(pf, v_budget);
  9157. if (v_actual < I40E_MIN_MSIX) {
  9158. pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
  9159. kfree(pf->msix_entries);
  9160. pf->msix_entries = NULL;
  9161. pci_disable_msix(pf->pdev);
  9162. return -ENODEV;
  9163. } else if (v_actual == I40E_MIN_MSIX) {
  9164. /* Adjust for minimal MSIX use */
  9165. pf->num_vmdq_vsis = 0;
  9166. pf->num_vmdq_qps = 0;
  9167. pf->num_lan_qps = 1;
  9168. pf->num_lan_msix = 1;
  9169. } else if (v_actual != v_budget) {
  9170. /* If we have limited resources, we will start with no vectors
  9171. * for the special features and then allocate vectors to some
  9172. * of these features based on the policy and at the end disable
  9173. * the features that did not get any vectors.
  9174. */
  9175. int vec;
  9176. dev_info(&pf->pdev->dev,
  9177. "MSI-X vector limit reached with %d, wanted %d, attempting to redistribute vectors\n",
  9178. v_actual, v_budget);
  9179. /* reserve the misc vector */
  9180. vec = v_actual - 1;
  9181. /* Scale vector usage down */
  9182. pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
  9183. pf->num_vmdq_vsis = 1;
  9184. pf->num_vmdq_qps = 1;
  9185. /* partition out the remaining vectors */
  9186. switch (vec) {
  9187. case 2:
  9188. pf->num_lan_msix = 1;
  9189. break;
  9190. case 3:
  9191. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  9192. pf->num_lan_msix = 1;
  9193. pf->num_iwarp_msix = 1;
  9194. } else {
  9195. pf->num_lan_msix = 2;
  9196. }
  9197. break;
  9198. default:
  9199. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  9200. pf->num_iwarp_msix = min_t(int, (vec / 3),
  9201. iwarp_requested);
  9202. pf->num_vmdq_vsis = min_t(int, (vec / 3),
  9203. I40E_DEFAULT_NUM_VMDQ_VSI);
  9204. } else {
  9205. pf->num_vmdq_vsis = min_t(int, (vec / 2),
  9206. I40E_DEFAULT_NUM_VMDQ_VSI);
  9207. }
  9208. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9209. pf->num_fdsb_msix = 1;
  9210. vec--;
  9211. }
  9212. pf->num_lan_msix = min_t(int,
  9213. (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
  9214. pf->num_lan_msix);
  9215. pf->num_lan_qps = pf->num_lan_msix;
  9216. break;
  9217. }
  9218. }
  9219. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  9220. (pf->num_fdsb_msix == 0)) {
  9221. dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
  9222. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  9223. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  9224. }
  9225. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  9226. (pf->num_vmdq_msix == 0)) {
  9227. dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
  9228. pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
  9229. }
  9230. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  9231. (pf->num_iwarp_msix == 0)) {
  9232. dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
  9233. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  9234. }
  9235. i40e_debug(&pf->hw, I40E_DEBUG_INIT,
  9236. "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
  9237. pf->num_lan_msix,
  9238. pf->num_vmdq_msix * pf->num_vmdq_vsis,
  9239. pf->num_fdsb_msix,
  9240. pf->num_iwarp_msix);
  9241. return v_actual;
  9242. }
  9243. /**
  9244. * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
  9245. * @vsi: the VSI being configured
  9246. * @v_idx: index of the vector in the vsi struct
  9247. * @cpu: cpu to be used on affinity_mask
  9248. *
  9249. * We allocate one q_vector. If allocation fails we return -ENOMEM.
  9250. **/
  9251. static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx, int cpu)
  9252. {
  9253. struct i40e_q_vector *q_vector;
  9254. /* allocate q_vector */
  9255. q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
  9256. if (!q_vector)
  9257. return -ENOMEM;
  9258. q_vector->vsi = vsi;
  9259. q_vector->v_idx = v_idx;
  9260. cpumask_copy(&q_vector->affinity_mask, cpu_possible_mask);
  9261. if (vsi->netdev)
  9262. netif_napi_add(vsi->netdev, &q_vector->napi,
  9263. i40e_napi_poll, NAPI_POLL_WEIGHT);
  9264. /* tie q_vector and vsi together */
  9265. vsi->q_vectors[v_idx] = q_vector;
  9266. return 0;
  9267. }
  9268. /**
  9269. * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
  9270. * @vsi: the VSI being configured
  9271. *
  9272. * We allocate one q_vector per queue interrupt. If allocation fails we
  9273. * return -ENOMEM.
  9274. **/
  9275. static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
  9276. {
  9277. struct i40e_pf *pf = vsi->back;
  9278. int err, v_idx, num_q_vectors, current_cpu;
  9279. /* if not MSIX, give the one vector only to the LAN VSI */
  9280. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  9281. num_q_vectors = vsi->num_q_vectors;
  9282. else if (vsi == pf->vsi[pf->lan_vsi])
  9283. num_q_vectors = 1;
  9284. else
  9285. return -EINVAL;
  9286. current_cpu = cpumask_first(cpu_online_mask);
  9287. for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
  9288. err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu);
  9289. if (err)
  9290. goto err_out;
  9291. current_cpu = cpumask_next(current_cpu, cpu_online_mask);
  9292. if (unlikely(current_cpu >= nr_cpu_ids))
  9293. current_cpu = cpumask_first(cpu_online_mask);
  9294. }
  9295. return 0;
  9296. err_out:
  9297. while (v_idx--)
  9298. i40e_free_q_vector(vsi, v_idx);
  9299. return err;
  9300. }
  9301. /**
  9302. * i40e_init_interrupt_scheme - Determine proper interrupt scheme
  9303. * @pf: board private structure to initialize
  9304. **/
  9305. static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
  9306. {
  9307. int vectors = 0;
  9308. ssize_t size;
  9309. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  9310. vectors = i40e_init_msix(pf);
  9311. if (vectors < 0) {
  9312. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
  9313. I40E_FLAG_IWARP_ENABLED |
  9314. I40E_FLAG_RSS_ENABLED |
  9315. I40E_FLAG_DCB_CAPABLE |
  9316. I40E_FLAG_DCB_ENABLED |
  9317. I40E_FLAG_SRIOV_ENABLED |
  9318. I40E_FLAG_FD_SB_ENABLED |
  9319. I40E_FLAG_FD_ATR_ENABLED |
  9320. I40E_FLAG_VMDQ_ENABLED);
  9321. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  9322. /* rework the queue expectations without MSIX */
  9323. i40e_determine_queue_usage(pf);
  9324. }
  9325. }
  9326. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  9327. (pf->flags & I40E_FLAG_MSI_ENABLED)) {
  9328. dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
  9329. vectors = pci_enable_msi(pf->pdev);
  9330. if (vectors < 0) {
  9331. dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
  9332. vectors);
  9333. pf->flags &= ~I40E_FLAG_MSI_ENABLED;
  9334. }
  9335. vectors = 1; /* one MSI or Legacy vector */
  9336. }
  9337. if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
  9338. dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
  9339. /* set up vector assignment tracking */
  9340. size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
  9341. pf->irq_pile = kzalloc(size, GFP_KERNEL);
  9342. if (!pf->irq_pile)
  9343. return -ENOMEM;
  9344. pf->irq_pile->num_entries = vectors;
  9345. pf->irq_pile->search_hint = 0;
  9346. /* track first vector for misc interrupts, ignore return */
  9347. (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
  9348. return 0;
  9349. }
  9350. /**
  9351. * i40e_restore_interrupt_scheme - Restore the interrupt scheme
  9352. * @pf: private board data structure
  9353. *
  9354. * Restore the interrupt scheme that was cleared when we suspended the
  9355. * device. This should be called during resume to re-allocate the q_vectors
  9356. * and reacquire IRQs.
  9357. */
  9358. static int i40e_restore_interrupt_scheme(struct i40e_pf *pf)
  9359. {
  9360. int err, i;
  9361. /* We cleared the MSI and MSI-X flags when disabling the old interrupt
  9362. * scheme. We need to re-enabled them here in order to attempt to
  9363. * re-acquire the MSI or MSI-X vectors
  9364. */
  9365. pf->flags |= (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  9366. err = i40e_init_interrupt_scheme(pf);
  9367. if (err)
  9368. return err;
  9369. /* Now that we've re-acquired IRQs, we need to remap the vectors and
  9370. * rings together again.
  9371. */
  9372. for (i = 0; i < pf->num_alloc_vsi; i++) {
  9373. if (pf->vsi[i]) {
  9374. err = i40e_vsi_alloc_q_vectors(pf->vsi[i]);
  9375. if (err)
  9376. goto err_unwind;
  9377. i40e_vsi_map_rings_to_vectors(pf->vsi[i]);
  9378. }
  9379. }
  9380. err = i40e_setup_misc_vector(pf);
  9381. if (err)
  9382. goto err_unwind;
  9383. if (pf->flags & I40E_FLAG_IWARP_ENABLED)
  9384. i40e_client_update_msix_info(pf);
  9385. return 0;
  9386. err_unwind:
  9387. while (i--) {
  9388. if (pf->vsi[i])
  9389. i40e_vsi_free_q_vectors(pf->vsi[i]);
  9390. }
  9391. return err;
  9392. }
  9393. /**
  9394. * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
  9395. * @pf: board private structure
  9396. *
  9397. * This sets up the handler for MSIX 0, which is used to manage the
  9398. * non-queue interrupts, e.g. AdminQ and errors. This is not used
  9399. * when in MSI or Legacy interrupt mode.
  9400. **/
  9401. static int i40e_setup_misc_vector(struct i40e_pf *pf)
  9402. {
  9403. struct i40e_hw *hw = &pf->hw;
  9404. int err = 0;
  9405. /* Only request the IRQ once, the first time through. */
  9406. if (!test_and_set_bit(__I40E_MISC_IRQ_REQUESTED, pf->state)) {
  9407. err = request_irq(pf->msix_entries[0].vector,
  9408. i40e_intr, 0, pf->int_name, pf);
  9409. if (err) {
  9410. clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state);
  9411. dev_info(&pf->pdev->dev,
  9412. "request_irq for %s failed: %d\n",
  9413. pf->int_name, err);
  9414. return -EFAULT;
  9415. }
  9416. }
  9417. i40e_enable_misc_int_causes(pf);
  9418. /* associate no queues to the misc vector */
  9419. wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
  9420. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K >> 1);
  9421. i40e_flush(hw);
  9422. i40e_irq_dynamic_enable_icr0(pf);
  9423. return err;
  9424. }
  9425. /**
  9426. * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
  9427. * @vsi: Pointer to vsi structure
  9428. * @seed: Buffter to store the hash keys
  9429. * @lut: Buffer to store the lookup table entries
  9430. * @lut_size: Size of buffer to store the lookup table entries
  9431. *
  9432. * Return 0 on success, negative on failure
  9433. */
  9434. static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  9435. u8 *lut, u16 lut_size)
  9436. {
  9437. struct i40e_pf *pf = vsi->back;
  9438. struct i40e_hw *hw = &pf->hw;
  9439. int ret = 0;
  9440. if (seed) {
  9441. ret = i40e_aq_get_rss_key(hw, vsi->id,
  9442. (struct i40e_aqc_get_set_rss_key_data *)seed);
  9443. if (ret) {
  9444. dev_info(&pf->pdev->dev,
  9445. "Cannot get RSS key, err %s aq_err %s\n",
  9446. i40e_stat_str(&pf->hw, ret),
  9447. i40e_aq_str(&pf->hw,
  9448. pf->hw.aq.asq_last_status));
  9449. return ret;
  9450. }
  9451. }
  9452. if (lut) {
  9453. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  9454. ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  9455. if (ret) {
  9456. dev_info(&pf->pdev->dev,
  9457. "Cannot get RSS lut, err %s aq_err %s\n",
  9458. i40e_stat_str(&pf->hw, ret),
  9459. i40e_aq_str(&pf->hw,
  9460. pf->hw.aq.asq_last_status));
  9461. return ret;
  9462. }
  9463. }
  9464. return ret;
  9465. }
  9466. /**
  9467. * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
  9468. * @vsi: Pointer to vsi structure
  9469. * @seed: RSS hash seed
  9470. * @lut: Lookup table
  9471. * @lut_size: Lookup table size
  9472. *
  9473. * Returns 0 on success, negative on failure
  9474. **/
  9475. static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
  9476. const u8 *lut, u16 lut_size)
  9477. {
  9478. struct i40e_pf *pf = vsi->back;
  9479. struct i40e_hw *hw = &pf->hw;
  9480. u16 vf_id = vsi->vf_id;
  9481. u8 i;
  9482. /* Fill out hash function seed */
  9483. if (seed) {
  9484. u32 *seed_dw = (u32 *)seed;
  9485. if (vsi->type == I40E_VSI_MAIN) {
  9486. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  9487. wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]);
  9488. } else if (vsi->type == I40E_VSI_SRIOV) {
  9489. for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++)
  9490. wr32(hw, I40E_VFQF_HKEY1(i, vf_id), seed_dw[i]);
  9491. } else {
  9492. dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n");
  9493. }
  9494. }
  9495. if (lut) {
  9496. u32 *lut_dw = (u32 *)lut;
  9497. if (vsi->type == I40E_VSI_MAIN) {
  9498. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  9499. return -EINVAL;
  9500. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  9501. wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
  9502. } else if (vsi->type == I40E_VSI_SRIOV) {
  9503. if (lut_size != I40E_VF_HLUT_ARRAY_SIZE)
  9504. return -EINVAL;
  9505. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  9506. wr32(hw, I40E_VFQF_HLUT1(i, vf_id), lut_dw[i]);
  9507. } else {
  9508. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  9509. }
  9510. }
  9511. i40e_flush(hw);
  9512. return 0;
  9513. }
  9514. /**
  9515. * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
  9516. * @vsi: Pointer to VSI structure
  9517. * @seed: Buffer to store the keys
  9518. * @lut: Buffer to store the lookup table entries
  9519. * @lut_size: Size of buffer to store the lookup table entries
  9520. *
  9521. * Returns 0 on success, negative on failure
  9522. */
  9523. static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
  9524. u8 *lut, u16 lut_size)
  9525. {
  9526. struct i40e_pf *pf = vsi->back;
  9527. struct i40e_hw *hw = &pf->hw;
  9528. u16 i;
  9529. if (seed) {
  9530. u32 *seed_dw = (u32 *)seed;
  9531. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  9532. seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
  9533. }
  9534. if (lut) {
  9535. u32 *lut_dw = (u32 *)lut;
  9536. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  9537. return -EINVAL;
  9538. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  9539. lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
  9540. }
  9541. return 0;
  9542. }
  9543. /**
  9544. * i40e_config_rss - Configure RSS keys and lut
  9545. * @vsi: Pointer to VSI structure
  9546. * @seed: RSS hash seed
  9547. * @lut: Lookup table
  9548. * @lut_size: Lookup table size
  9549. *
  9550. * Returns 0 on success, negative on failure
  9551. */
  9552. int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  9553. {
  9554. struct i40e_pf *pf = vsi->back;
  9555. if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)
  9556. return i40e_config_rss_aq(vsi, seed, lut, lut_size);
  9557. else
  9558. return i40e_config_rss_reg(vsi, seed, lut, lut_size);
  9559. }
  9560. /**
  9561. * i40e_get_rss - Get RSS keys and lut
  9562. * @vsi: Pointer to VSI structure
  9563. * @seed: Buffer to store the keys
  9564. * @lut: Buffer to store the lookup table entries
  9565. * @lut_size: Size of buffer to store the lookup table entries
  9566. *
  9567. * Returns 0 on success, negative on failure
  9568. */
  9569. int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  9570. {
  9571. struct i40e_pf *pf = vsi->back;
  9572. if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)
  9573. return i40e_get_rss_aq(vsi, seed, lut, lut_size);
  9574. else
  9575. return i40e_get_rss_reg(vsi, seed, lut, lut_size);
  9576. }
  9577. /**
  9578. * i40e_fill_rss_lut - Fill the RSS lookup table with default values
  9579. * @pf: Pointer to board private structure
  9580. * @lut: Lookup table
  9581. * @rss_table_size: Lookup table size
  9582. * @rss_size: Range of queue number for hashing
  9583. */
  9584. void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
  9585. u16 rss_table_size, u16 rss_size)
  9586. {
  9587. u16 i;
  9588. for (i = 0; i < rss_table_size; i++)
  9589. lut[i] = i % rss_size;
  9590. }
  9591. /**
  9592. * i40e_pf_config_rss - Prepare for RSS if used
  9593. * @pf: board private structure
  9594. **/
  9595. static int i40e_pf_config_rss(struct i40e_pf *pf)
  9596. {
  9597. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  9598. u8 seed[I40E_HKEY_ARRAY_SIZE];
  9599. u8 *lut;
  9600. struct i40e_hw *hw = &pf->hw;
  9601. u32 reg_val;
  9602. u64 hena;
  9603. int ret;
  9604. /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
  9605. hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  9606. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  9607. hena |= i40e_pf_get_default_rss_hena(pf);
  9608. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  9609. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  9610. /* Determine the RSS table size based on the hardware capabilities */
  9611. reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
  9612. reg_val = (pf->rss_table_size == 512) ?
  9613. (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
  9614. (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
  9615. i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
  9616. /* Determine the RSS size of the VSI */
  9617. if (!vsi->rss_size) {
  9618. u16 qcount;
  9619. /* If the firmware does something weird during VSI init, we
  9620. * could end up with zero TCs. Check for that to avoid
  9621. * divide-by-zero. It probably won't pass traffic, but it also
  9622. * won't panic.
  9623. */
  9624. qcount = vsi->num_queue_pairs /
  9625. (vsi->tc_config.numtc ? vsi->tc_config.numtc : 1);
  9626. vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
  9627. }
  9628. if (!vsi->rss_size)
  9629. return -EINVAL;
  9630. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  9631. if (!lut)
  9632. return -ENOMEM;
  9633. /* Use user configured lut if there is one, otherwise use default */
  9634. if (vsi->rss_lut_user)
  9635. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  9636. else
  9637. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  9638. /* Use user configured hash key if there is one, otherwise
  9639. * use default.
  9640. */
  9641. if (vsi->rss_hkey_user)
  9642. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  9643. else
  9644. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  9645. ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
  9646. kfree(lut);
  9647. return ret;
  9648. }
  9649. /**
  9650. * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
  9651. * @pf: board private structure
  9652. * @queue_count: the requested queue count for rss.
  9653. *
  9654. * returns 0 if rss is not enabled, if enabled returns the final rss queue
  9655. * count which may be different from the requested queue count.
  9656. * Note: expects to be called while under rtnl_lock()
  9657. **/
  9658. int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
  9659. {
  9660. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  9661. int new_rss_size;
  9662. if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
  9663. return 0;
  9664. new_rss_size = min_t(int, queue_count, pf->rss_size_max);
  9665. if (queue_count != vsi->num_queue_pairs) {
  9666. u16 qcount;
  9667. vsi->req_queue_pairs = queue_count;
  9668. i40e_prep_for_reset(pf, true);
  9669. pf->alloc_rss_size = new_rss_size;
  9670. i40e_reset_and_rebuild(pf, true, true);
  9671. /* Discard the user configured hash keys and lut, if less
  9672. * queues are enabled.
  9673. */
  9674. if (queue_count < vsi->rss_size) {
  9675. i40e_clear_rss_config_user(vsi);
  9676. dev_dbg(&pf->pdev->dev,
  9677. "discard user configured hash keys and lut\n");
  9678. }
  9679. /* Reset vsi->rss_size, as number of enabled queues changed */
  9680. qcount = vsi->num_queue_pairs / vsi->tc_config.numtc;
  9681. vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
  9682. i40e_pf_config_rss(pf);
  9683. }
  9684. dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n",
  9685. vsi->req_queue_pairs, pf->rss_size_max);
  9686. return pf->alloc_rss_size;
  9687. }
  9688. /**
  9689. * i40e_get_partition_bw_setting - Retrieve BW settings for this PF partition
  9690. * @pf: board private structure
  9691. **/
  9692. i40e_status i40e_get_partition_bw_setting(struct i40e_pf *pf)
  9693. {
  9694. i40e_status status;
  9695. bool min_valid, max_valid;
  9696. u32 max_bw, min_bw;
  9697. status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
  9698. &min_valid, &max_valid);
  9699. if (!status) {
  9700. if (min_valid)
  9701. pf->min_bw = min_bw;
  9702. if (max_valid)
  9703. pf->max_bw = max_bw;
  9704. }
  9705. return status;
  9706. }
  9707. /**
  9708. * i40e_set_partition_bw_setting - Set BW settings for this PF partition
  9709. * @pf: board private structure
  9710. **/
  9711. i40e_status i40e_set_partition_bw_setting(struct i40e_pf *pf)
  9712. {
  9713. struct i40e_aqc_configure_partition_bw_data bw_data;
  9714. i40e_status status;
  9715. memset(&bw_data, 0, sizeof(bw_data));
  9716. /* Set the valid bit for this PF */
  9717. bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
  9718. bw_data.max_bw[pf->hw.pf_id] = pf->max_bw & I40E_ALT_BW_VALUE_MASK;
  9719. bw_data.min_bw[pf->hw.pf_id] = pf->min_bw & I40E_ALT_BW_VALUE_MASK;
  9720. /* Set the new bandwidths */
  9721. status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
  9722. return status;
  9723. }
  9724. /**
  9725. * i40e_commit_partition_bw_setting - Commit BW settings for this PF partition
  9726. * @pf: board private structure
  9727. **/
  9728. i40e_status i40e_commit_partition_bw_setting(struct i40e_pf *pf)
  9729. {
  9730. /* Commit temporary BW setting to permanent NVM image */
  9731. enum i40e_admin_queue_err last_aq_status;
  9732. i40e_status ret;
  9733. u16 nvm_word;
  9734. if (pf->hw.partition_id != 1) {
  9735. dev_info(&pf->pdev->dev,
  9736. "Commit BW only works on partition 1! This is partition %d",
  9737. pf->hw.partition_id);
  9738. ret = I40E_NOT_SUPPORTED;
  9739. goto bw_commit_out;
  9740. }
  9741. /* Acquire NVM for read access */
  9742. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
  9743. last_aq_status = pf->hw.aq.asq_last_status;
  9744. if (ret) {
  9745. dev_info(&pf->pdev->dev,
  9746. "Cannot acquire NVM for read access, err %s aq_err %s\n",
  9747. i40e_stat_str(&pf->hw, ret),
  9748. i40e_aq_str(&pf->hw, last_aq_status));
  9749. goto bw_commit_out;
  9750. }
  9751. /* Read word 0x10 of NVM - SW compatibility word 1 */
  9752. ret = i40e_aq_read_nvm(&pf->hw,
  9753. I40E_SR_NVM_CONTROL_WORD,
  9754. 0x10, sizeof(nvm_word), &nvm_word,
  9755. false, NULL);
  9756. /* Save off last admin queue command status before releasing
  9757. * the NVM
  9758. */
  9759. last_aq_status = pf->hw.aq.asq_last_status;
  9760. i40e_release_nvm(&pf->hw);
  9761. if (ret) {
  9762. dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
  9763. i40e_stat_str(&pf->hw, ret),
  9764. i40e_aq_str(&pf->hw, last_aq_status));
  9765. goto bw_commit_out;
  9766. }
  9767. /* Wait a bit for NVM release to complete */
  9768. msleep(50);
  9769. /* Acquire NVM for write access */
  9770. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
  9771. last_aq_status = pf->hw.aq.asq_last_status;
  9772. if (ret) {
  9773. dev_info(&pf->pdev->dev,
  9774. "Cannot acquire NVM for write access, err %s aq_err %s\n",
  9775. i40e_stat_str(&pf->hw, ret),
  9776. i40e_aq_str(&pf->hw, last_aq_status));
  9777. goto bw_commit_out;
  9778. }
  9779. /* Write it back out unchanged to initiate update NVM,
  9780. * which will force a write of the shadow (alt) RAM to
  9781. * the NVM - thus storing the bandwidth values permanently.
  9782. */
  9783. ret = i40e_aq_update_nvm(&pf->hw,
  9784. I40E_SR_NVM_CONTROL_WORD,
  9785. 0x10, sizeof(nvm_word),
  9786. &nvm_word, true, 0, NULL);
  9787. /* Save off last admin queue command status before releasing
  9788. * the NVM
  9789. */
  9790. last_aq_status = pf->hw.aq.asq_last_status;
  9791. i40e_release_nvm(&pf->hw);
  9792. if (ret)
  9793. dev_info(&pf->pdev->dev,
  9794. "BW settings NOT SAVED, err %s aq_err %s\n",
  9795. i40e_stat_str(&pf->hw, ret),
  9796. i40e_aq_str(&pf->hw, last_aq_status));
  9797. bw_commit_out:
  9798. return ret;
  9799. }
  9800. /**
  9801. * i40e_sw_init - Initialize general software structures (struct i40e_pf)
  9802. * @pf: board private structure to initialize
  9803. *
  9804. * i40e_sw_init initializes the Adapter private data structure.
  9805. * Fields are initialized based on PCI device information and
  9806. * OS network device settings (MTU size).
  9807. **/
  9808. static int i40e_sw_init(struct i40e_pf *pf)
  9809. {
  9810. int err = 0;
  9811. int size;
  9812. u16 pow;
  9813. /* Set default capability flags */
  9814. pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
  9815. I40E_FLAG_MSI_ENABLED |
  9816. I40E_FLAG_MSIX_ENABLED;
  9817. /* Set default ITR */
  9818. pf->rx_itr_default = I40E_ITR_RX_DEF;
  9819. pf->tx_itr_default = I40E_ITR_TX_DEF;
  9820. /* Depending on PF configurations, it is possible that the RSS
  9821. * maximum might end up larger than the available queues
  9822. */
  9823. pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
  9824. pf->alloc_rss_size = 1;
  9825. pf->rss_table_size = pf->hw.func_caps.rss_table_size;
  9826. pf->rss_size_max = min_t(int, pf->rss_size_max,
  9827. pf->hw.func_caps.num_tx_qp);
  9828. /* find the next higher power-of-2 of num cpus */
  9829. pow = roundup_pow_of_two(num_online_cpus());
  9830. pf->rss_size_max = min_t(int, pf->rss_size_max, pow);
  9831. if (pf->hw.func_caps.rss) {
  9832. pf->flags |= I40E_FLAG_RSS_ENABLED;
  9833. pf->alloc_rss_size = min_t(int, pf->rss_size_max,
  9834. num_online_cpus());
  9835. }
  9836. /* MFP mode enabled */
  9837. if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
  9838. pf->flags |= I40E_FLAG_MFP_ENABLED;
  9839. dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
  9840. if (i40e_get_partition_bw_setting(pf)) {
  9841. dev_warn(&pf->pdev->dev,
  9842. "Could not get partition bw settings\n");
  9843. } else {
  9844. dev_info(&pf->pdev->dev,
  9845. "Partition BW Min = %8.8x, Max = %8.8x\n",
  9846. pf->min_bw, pf->max_bw);
  9847. /* nudge the Tx scheduler */
  9848. i40e_set_partition_bw_setting(pf);
  9849. }
  9850. }
  9851. if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
  9852. (pf->hw.func_caps.fd_filters_best_effort > 0)) {
  9853. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  9854. pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
  9855. if (pf->flags & I40E_FLAG_MFP_ENABLED &&
  9856. pf->hw.num_partitions > 1)
  9857. dev_info(&pf->pdev->dev,
  9858. "Flow Director Sideband mode Disabled in MFP mode\n");
  9859. else
  9860. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  9861. pf->fdir_pf_filter_count =
  9862. pf->hw.func_caps.fd_filters_guaranteed;
  9863. pf->hw.fdir_shared_filter_count =
  9864. pf->hw.func_caps.fd_filters_best_effort;
  9865. }
  9866. if (pf->hw.mac.type == I40E_MAC_X722) {
  9867. pf->hw_features |= (I40E_HW_RSS_AQ_CAPABLE |
  9868. I40E_HW_128_QP_RSS_CAPABLE |
  9869. I40E_HW_ATR_EVICT_CAPABLE |
  9870. I40E_HW_WB_ON_ITR_CAPABLE |
  9871. I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE |
  9872. I40E_HW_NO_PCI_LINK_CHECK |
  9873. I40E_HW_USE_SET_LLDP_MIB |
  9874. I40E_HW_GENEVE_OFFLOAD_CAPABLE |
  9875. I40E_HW_PTP_L4_CAPABLE |
  9876. I40E_HW_WOL_MC_MAGIC_PKT_WAKE |
  9877. I40E_HW_OUTER_UDP_CSUM_CAPABLE);
  9878. #define I40E_FDEVICT_PCTYPE_DEFAULT 0xc03
  9879. if (rd32(&pf->hw, I40E_GLQF_FDEVICTENA(1)) !=
  9880. I40E_FDEVICT_PCTYPE_DEFAULT) {
  9881. dev_warn(&pf->pdev->dev,
  9882. "FD EVICT PCTYPES are not right, disable FD HW EVICT\n");
  9883. pf->hw_features &= ~I40E_HW_ATR_EVICT_CAPABLE;
  9884. }
  9885. } else if ((pf->hw.aq.api_maj_ver > 1) ||
  9886. ((pf->hw.aq.api_maj_ver == 1) &&
  9887. (pf->hw.aq.api_min_ver > 4))) {
  9888. /* Supported in FW API version higher than 1.4 */
  9889. pf->hw_features |= I40E_HW_GENEVE_OFFLOAD_CAPABLE;
  9890. }
  9891. /* Enable HW ATR eviction if possible */
  9892. if (pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE)
  9893. pf->flags |= I40E_FLAG_HW_ATR_EVICT_ENABLED;
  9894. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  9895. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
  9896. (pf->hw.aq.fw_maj_ver < 4))) {
  9897. pf->hw_features |= I40E_HW_RESTART_AUTONEG;
  9898. /* No DCB support for FW < v4.33 */
  9899. pf->hw_features |= I40E_HW_NO_DCB_SUPPORT;
  9900. }
  9901. /* Disable FW LLDP if FW < v4.3 */
  9902. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  9903. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
  9904. (pf->hw.aq.fw_maj_ver < 4)))
  9905. pf->hw_features |= I40E_HW_STOP_FW_LLDP;
  9906. /* Use the FW Set LLDP MIB API if FW > v4.40 */
  9907. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  9908. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
  9909. (pf->hw.aq.fw_maj_ver >= 5)))
  9910. pf->hw_features |= I40E_HW_USE_SET_LLDP_MIB;
  9911. /* Enable PTP L4 if FW > v6.0 */
  9912. if (pf->hw.mac.type == I40E_MAC_XL710 &&
  9913. pf->hw.aq.fw_maj_ver >= 6)
  9914. pf->hw_features |= I40E_HW_PTP_L4_CAPABLE;
  9915. if (pf->hw.func_caps.vmdq && num_online_cpus() != 1) {
  9916. pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
  9917. pf->flags |= I40E_FLAG_VMDQ_ENABLED;
  9918. pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
  9919. }
  9920. if (pf->hw.func_caps.iwarp && num_online_cpus() != 1) {
  9921. pf->flags |= I40E_FLAG_IWARP_ENABLED;
  9922. /* IWARP needs one extra vector for CQP just like MISC.*/
  9923. pf->num_iwarp_msix = (int)num_online_cpus() + 1;
  9924. }
  9925. /* Stopping the FW LLDP engine is only supported on the
  9926. * XL710 with a FW ver >= 1.7. Also, stopping FW LLDP
  9927. * engine is not supported if NPAR is functioning on this
  9928. * part
  9929. */
  9930. if (pf->hw.mac.type == I40E_MAC_XL710 &&
  9931. !pf->hw.func_caps.npar_enable &&
  9932. (pf->hw.aq.api_maj_ver > 1 ||
  9933. (pf->hw.aq.api_maj_ver == 1 && pf->hw.aq.api_min_ver > 6)))
  9934. pf->hw_features |= I40E_HW_STOPPABLE_FW_LLDP;
  9935. #ifdef CONFIG_PCI_IOV
  9936. if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
  9937. pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
  9938. pf->flags |= I40E_FLAG_SRIOV_ENABLED;
  9939. pf->num_req_vfs = min_t(int,
  9940. pf->hw.func_caps.num_vfs,
  9941. I40E_MAX_VF_COUNT);
  9942. }
  9943. #endif /* CONFIG_PCI_IOV */
  9944. pf->eeprom_version = 0xDEAD;
  9945. pf->lan_veb = I40E_NO_VEB;
  9946. pf->lan_vsi = I40E_NO_VSI;
  9947. /* By default FW has this off for performance reasons */
  9948. pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
  9949. /* set up queue assignment tracking */
  9950. size = sizeof(struct i40e_lump_tracking)
  9951. + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
  9952. pf->qp_pile = kzalloc(size, GFP_KERNEL);
  9953. if (!pf->qp_pile) {
  9954. err = -ENOMEM;
  9955. goto sw_init_done;
  9956. }
  9957. pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
  9958. pf->qp_pile->search_hint = 0;
  9959. pf->tx_timeout_recovery_level = 1;
  9960. mutex_init(&pf->switch_mutex);
  9961. sw_init_done:
  9962. return err;
  9963. }
  9964. /**
  9965. * i40e_set_ntuple - set the ntuple feature flag and take action
  9966. * @pf: board private structure to initialize
  9967. * @features: the feature set that the stack is suggesting
  9968. *
  9969. * returns a bool to indicate if reset needs to happen
  9970. **/
  9971. bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
  9972. {
  9973. bool need_reset = false;
  9974. /* Check if Flow Director n-tuple support was enabled or disabled. If
  9975. * the state changed, we need to reset.
  9976. */
  9977. if (features & NETIF_F_NTUPLE) {
  9978. /* Enable filters and mark for reset */
  9979. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  9980. need_reset = true;
  9981. /* enable FD_SB only if there is MSI-X vector and no cloud
  9982. * filters exist
  9983. */
  9984. if (pf->num_fdsb_msix > 0 && !pf->num_cloud_filters) {
  9985. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  9986. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  9987. }
  9988. } else {
  9989. /* turn off filters, mark for reset and clear SW filter list */
  9990. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9991. need_reset = true;
  9992. i40e_fdir_filter_exit(pf);
  9993. }
  9994. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  9995. clear_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state);
  9996. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  9997. /* reset fd counters */
  9998. pf->fd_add_err = 0;
  9999. pf->fd_atr_cnt = 0;
  10000. /* if ATR was auto disabled it can be re-enabled. */
  10001. if (test_and_clear_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state))
  10002. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  10003. (I40E_DEBUG_FD & pf->hw.debug_mask))
  10004. dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
  10005. }
  10006. return need_reset;
  10007. }
  10008. /**
  10009. * i40e_clear_rss_lut - clear the rx hash lookup table
  10010. * @vsi: the VSI being configured
  10011. **/
  10012. static void i40e_clear_rss_lut(struct i40e_vsi *vsi)
  10013. {
  10014. struct i40e_pf *pf = vsi->back;
  10015. struct i40e_hw *hw = &pf->hw;
  10016. u16 vf_id = vsi->vf_id;
  10017. u8 i;
  10018. if (vsi->type == I40E_VSI_MAIN) {
  10019. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  10020. wr32(hw, I40E_PFQF_HLUT(i), 0);
  10021. } else if (vsi->type == I40E_VSI_SRIOV) {
  10022. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  10023. i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0);
  10024. } else {
  10025. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  10026. }
  10027. }
  10028. /**
  10029. * i40e_set_features - set the netdev feature flags
  10030. * @netdev: ptr to the netdev being adjusted
  10031. * @features: the feature set that the stack is suggesting
  10032. * Note: expects to be called while under rtnl_lock()
  10033. **/
  10034. static int i40e_set_features(struct net_device *netdev,
  10035. netdev_features_t features)
  10036. {
  10037. struct i40e_netdev_priv *np = netdev_priv(netdev);
  10038. struct i40e_vsi *vsi = np->vsi;
  10039. struct i40e_pf *pf = vsi->back;
  10040. bool need_reset;
  10041. if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
  10042. i40e_pf_config_rss(pf);
  10043. else if (!(features & NETIF_F_RXHASH) &&
  10044. netdev->features & NETIF_F_RXHASH)
  10045. i40e_clear_rss_lut(vsi);
  10046. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  10047. i40e_vlan_stripping_enable(vsi);
  10048. else
  10049. i40e_vlan_stripping_disable(vsi);
  10050. if (!(features & NETIF_F_HW_TC) && pf->num_cloud_filters) {
  10051. dev_err(&pf->pdev->dev,
  10052. "Offloaded tc filters active, can't turn hw_tc_offload off");
  10053. return -EINVAL;
  10054. }
  10055. need_reset = i40e_set_ntuple(pf, features);
  10056. if (need_reset)
  10057. i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
  10058. return 0;
  10059. }
  10060. /**
  10061. * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
  10062. * @pf: board private structure
  10063. * @port: The UDP port to look up
  10064. *
  10065. * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
  10066. **/
  10067. static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, u16 port)
  10068. {
  10069. u8 i;
  10070. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  10071. /* Do not report ports with pending deletions as
  10072. * being available.
  10073. */
  10074. if (!port && (pf->pending_udp_bitmap & BIT_ULL(i)))
  10075. continue;
  10076. if (pf->udp_ports[i].port == port)
  10077. return i;
  10078. }
  10079. return i;
  10080. }
  10081. /**
  10082. * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
  10083. * @netdev: This physical port's netdev
  10084. * @ti: Tunnel endpoint information
  10085. **/
  10086. static void i40e_udp_tunnel_add(struct net_device *netdev,
  10087. struct udp_tunnel_info *ti)
  10088. {
  10089. struct i40e_netdev_priv *np = netdev_priv(netdev);
  10090. struct i40e_vsi *vsi = np->vsi;
  10091. struct i40e_pf *pf = vsi->back;
  10092. u16 port = ntohs(ti->port);
  10093. u8 next_idx;
  10094. u8 idx;
  10095. idx = i40e_get_udp_port_idx(pf, port);
  10096. /* Check if port already exists */
  10097. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  10098. netdev_info(netdev, "port %d already offloaded\n", port);
  10099. return;
  10100. }
  10101. /* Now check if there is space to add the new port */
  10102. next_idx = i40e_get_udp_port_idx(pf, 0);
  10103. if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  10104. netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n",
  10105. port);
  10106. return;
  10107. }
  10108. switch (ti->type) {
  10109. case UDP_TUNNEL_TYPE_VXLAN:
  10110. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
  10111. break;
  10112. case UDP_TUNNEL_TYPE_GENEVE:
  10113. if (!(pf->hw_features & I40E_HW_GENEVE_OFFLOAD_CAPABLE))
  10114. return;
  10115. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
  10116. break;
  10117. default:
  10118. return;
  10119. }
  10120. /* New port: add it and mark its index in the bitmap */
  10121. pf->udp_ports[next_idx].port = port;
  10122. pf->udp_ports[next_idx].filter_index = I40E_UDP_PORT_INDEX_UNUSED;
  10123. pf->pending_udp_bitmap |= BIT_ULL(next_idx);
  10124. set_bit(__I40E_UDP_FILTER_SYNC_PENDING, pf->state);
  10125. }
  10126. /**
  10127. * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
  10128. * @netdev: This physical port's netdev
  10129. * @ti: Tunnel endpoint information
  10130. **/
  10131. static void i40e_udp_tunnel_del(struct net_device *netdev,
  10132. struct udp_tunnel_info *ti)
  10133. {
  10134. struct i40e_netdev_priv *np = netdev_priv(netdev);
  10135. struct i40e_vsi *vsi = np->vsi;
  10136. struct i40e_pf *pf = vsi->back;
  10137. u16 port = ntohs(ti->port);
  10138. u8 idx;
  10139. idx = i40e_get_udp_port_idx(pf, port);
  10140. /* Check if port already exists */
  10141. if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS)
  10142. goto not_found;
  10143. switch (ti->type) {
  10144. case UDP_TUNNEL_TYPE_VXLAN:
  10145. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN)
  10146. goto not_found;
  10147. break;
  10148. case UDP_TUNNEL_TYPE_GENEVE:
  10149. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE)
  10150. goto not_found;
  10151. break;
  10152. default:
  10153. goto not_found;
  10154. }
  10155. /* if port exists, set it to 0 (mark for deletion)
  10156. * and make it pending
  10157. */
  10158. pf->udp_ports[idx].port = 0;
  10159. /* Toggle pending bit instead of setting it. This way if we are
  10160. * deleting a port that has yet to be added we just clear the pending
  10161. * bit and don't have to worry about it.
  10162. */
  10163. pf->pending_udp_bitmap ^= BIT_ULL(idx);
  10164. set_bit(__I40E_UDP_FILTER_SYNC_PENDING, pf->state);
  10165. return;
  10166. not_found:
  10167. netdev_warn(netdev, "UDP port %d was not found, not deleting\n",
  10168. port);
  10169. }
  10170. static int i40e_get_phys_port_id(struct net_device *netdev,
  10171. struct netdev_phys_item_id *ppid)
  10172. {
  10173. struct i40e_netdev_priv *np = netdev_priv(netdev);
  10174. struct i40e_pf *pf = np->vsi->back;
  10175. struct i40e_hw *hw = &pf->hw;
  10176. if (!(pf->hw_features & I40E_HW_PORT_ID_VALID))
  10177. return -EOPNOTSUPP;
  10178. ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
  10179. memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
  10180. return 0;
  10181. }
  10182. /**
  10183. * i40e_ndo_fdb_add - add an entry to the hardware database
  10184. * @ndm: the input from the stack
  10185. * @tb: pointer to array of nladdr (unused)
  10186. * @dev: the net device pointer
  10187. * @addr: the MAC address entry being added
  10188. * @vid: VLAN ID
  10189. * @flags: instructions from stack about fdb operation
  10190. */
  10191. static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  10192. struct net_device *dev,
  10193. const unsigned char *addr, u16 vid,
  10194. u16 flags)
  10195. {
  10196. struct i40e_netdev_priv *np = netdev_priv(dev);
  10197. struct i40e_pf *pf = np->vsi->back;
  10198. int err = 0;
  10199. if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
  10200. return -EOPNOTSUPP;
  10201. if (vid) {
  10202. pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
  10203. return -EINVAL;
  10204. }
  10205. /* Hardware does not support aging addresses so if a
  10206. * ndm_state is given only allow permanent addresses
  10207. */
  10208. if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
  10209. netdev_info(dev, "FDB only supports static addresses\n");
  10210. return -EINVAL;
  10211. }
  10212. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
  10213. err = dev_uc_add_excl(dev, addr);
  10214. else if (is_multicast_ether_addr(addr))
  10215. err = dev_mc_add_excl(dev, addr);
  10216. else
  10217. err = -EINVAL;
  10218. /* Only return duplicate errors if NLM_F_EXCL is set */
  10219. if (err == -EEXIST && !(flags & NLM_F_EXCL))
  10220. err = 0;
  10221. return err;
  10222. }
  10223. /**
  10224. * i40e_ndo_bridge_setlink - Set the hardware bridge mode
  10225. * @dev: the netdev being configured
  10226. * @nlh: RTNL message
  10227. * @flags: bridge flags
  10228. *
  10229. * Inserts a new hardware bridge if not already created and
  10230. * enables the bridging mode requested (VEB or VEPA). If the
  10231. * hardware bridge has already been inserted and the request
  10232. * is to change the mode then that requires a PF reset to
  10233. * allow rebuild of the components with required hardware
  10234. * bridge mode enabled.
  10235. *
  10236. * Note: expects to be called while under rtnl_lock()
  10237. **/
  10238. static int i40e_ndo_bridge_setlink(struct net_device *dev,
  10239. struct nlmsghdr *nlh,
  10240. u16 flags)
  10241. {
  10242. struct i40e_netdev_priv *np = netdev_priv(dev);
  10243. struct i40e_vsi *vsi = np->vsi;
  10244. struct i40e_pf *pf = vsi->back;
  10245. struct i40e_veb *veb = NULL;
  10246. struct nlattr *attr, *br_spec;
  10247. int i, rem;
  10248. /* Only for PF VSI for now */
  10249. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  10250. return -EOPNOTSUPP;
  10251. /* Find the HW bridge for PF VSI */
  10252. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  10253. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  10254. veb = pf->veb[i];
  10255. }
  10256. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  10257. nla_for_each_nested(attr, br_spec, rem) {
  10258. __u16 mode;
  10259. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  10260. continue;
  10261. mode = nla_get_u16(attr);
  10262. if ((mode != BRIDGE_MODE_VEPA) &&
  10263. (mode != BRIDGE_MODE_VEB))
  10264. return -EINVAL;
  10265. /* Insert a new HW bridge */
  10266. if (!veb) {
  10267. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  10268. vsi->tc_config.enabled_tc);
  10269. if (veb) {
  10270. veb->bridge_mode = mode;
  10271. i40e_config_bridge_mode(veb);
  10272. } else {
  10273. /* No Bridge HW offload available */
  10274. return -ENOENT;
  10275. }
  10276. break;
  10277. } else if (mode != veb->bridge_mode) {
  10278. /* Existing HW bridge but different mode needs reset */
  10279. veb->bridge_mode = mode;
  10280. /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
  10281. if (mode == BRIDGE_MODE_VEB)
  10282. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  10283. else
  10284. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  10285. i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
  10286. break;
  10287. }
  10288. }
  10289. return 0;
  10290. }
  10291. /**
  10292. * i40e_ndo_bridge_getlink - Get the hardware bridge mode
  10293. * @skb: skb buff
  10294. * @pid: process id
  10295. * @seq: RTNL message seq #
  10296. * @dev: the netdev being configured
  10297. * @filter_mask: unused
  10298. * @nlflags: netlink flags passed in
  10299. *
  10300. * Return the mode in which the hardware bridge is operating in
  10301. * i.e VEB or VEPA.
  10302. **/
  10303. static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  10304. struct net_device *dev,
  10305. u32 __always_unused filter_mask,
  10306. int nlflags)
  10307. {
  10308. struct i40e_netdev_priv *np = netdev_priv(dev);
  10309. struct i40e_vsi *vsi = np->vsi;
  10310. struct i40e_pf *pf = vsi->back;
  10311. struct i40e_veb *veb = NULL;
  10312. int i;
  10313. /* Only for PF VSI for now */
  10314. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  10315. return -EOPNOTSUPP;
  10316. /* Find the HW bridge for the PF VSI */
  10317. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  10318. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  10319. veb = pf->veb[i];
  10320. }
  10321. if (!veb)
  10322. return 0;
  10323. return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
  10324. 0, 0, nlflags, filter_mask, NULL);
  10325. }
  10326. /**
  10327. * i40e_features_check - Validate encapsulated packet conforms to limits
  10328. * @skb: skb buff
  10329. * @dev: This physical port's netdev
  10330. * @features: Offload features that the stack believes apply
  10331. **/
  10332. static netdev_features_t i40e_features_check(struct sk_buff *skb,
  10333. struct net_device *dev,
  10334. netdev_features_t features)
  10335. {
  10336. size_t len;
  10337. /* No point in doing any of this if neither checksum nor GSO are
  10338. * being requested for this frame. We can rule out both by just
  10339. * checking for CHECKSUM_PARTIAL
  10340. */
  10341. if (skb->ip_summed != CHECKSUM_PARTIAL)
  10342. return features;
  10343. /* We cannot support GSO if the MSS is going to be less than
  10344. * 64 bytes. If it is then we need to drop support for GSO.
  10345. */
  10346. if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
  10347. features &= ~NETIF_F_GSO_MASK;
  10348. /* MACLEN can support at most 63 words */
  10349. len = skb_network_header(skb) - skb->data;
  10350. if (len & ~(63 * 2))
  10351. goto out_err;
  10352. /* IPLEN and EIPLEN can support at most 127 dwords */
  10353. len = skb_transport_header(skb) - skb_network_header(skb);
  10354. if (len & ~(127 * 4))
  10355. goto out_err;
  10356. if (skb->encapsulation) {
  10357. /* L4TUNLEN can support 127 words */
  10358. len = skb_inner_network_header(skb) - skb_transport_header(skb);
  10359. if (len & ~(127 * 2))
  10360. goto out_err;
  10361. /* IPLEN can support at most 127 dwords */
  10362. len = skb_inner_transport_header(skb) -
  10363. skb_inner_network_header(skb);
  10364. if (len & ~(127 * 4))
  10365. goto out_err;
  10366. }
  10367. /* No need to validate L4LEN as TCP is the only protocol with a
  10368. * a flexible value and we support all possible values supported
  10369. * by TCP, which is at most 15 dwords
  10370. */
  10371. return features;
  10372. out_err:
  10373. return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
  10374. }
  10375. /**
  10376. * i40e_xdp_setup - add/remove an XDP program
  10377. * @vsi: VSI to changed
  10378. * @prog: XDP program
  10379. **/
  10380. static int i40e_xdp_setup(struct i40e_vsi *vsi,
  10381. struct bpf_prog *prog)
  10382. {
  10383. int frame_size = vsi->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  10384. struct i40e_pf *pf = vsi->back;
  10385. struct bpf_prog *old_prog;
  10386. bool need_reset;
  10387. int i;
  10388. /* Don't allow frames that span over multiple buffers */
  10389. if (frame_size > vsi->rx_buf_len)
  10390. return -EINVAL;
  10391. if (!i40e_enabled_xdp_vsi(vsi) && !prog)
  10392. return 0;
  10393. /* When turning XDP on->off/off->on we reset and rebuild the rings. */
  10394. need_reset = (i40e_enabled_xdp_vsi(vsi) != !!prog);
  10395. if (need_reset)
  10396. i40e_prep_for_reset(pf, true);
  10397. old_prog = xchg(&vsi->xdp_prog, prog);
  10398. if (need_reset)
  10399. i40e_reset_and_rebuild(pf, true, true);
  10400. for (i = 0; i < vsi->num_queue_pairs; i++)
  10401. WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
  10402. if (old_prog)
  10403. bpf_prog_put(old_prog);
  10404. return 0;
  10405. }
  10406. /**
  10407. * i40e_xdp - implements ndo_bpf for i40e
  10408. * @dev: netdevice
  10409. * @xdp: XDP command
  10410. **/
  10411. static int i40e_xdp(struct net_device *dev,
  10412. struct netdev_bpf *xdp)
  10413. {
  10414. struct i40e_netdev_priv *np = netdev_priv(dev);
  10415. struct i40e_vsi *vsi = np->vsi;
  10416. if (vsi->type != I40E_VSI_MAIN)
  10417. return -EINVAL;
  10418. switch (xdp->command) {
  10419. case XDP_SETUP_PROG:
  10420. return i40e_xdp_setup(vsi, xdp->prog);
  10421. case XDP_QUERY_PROG:
  10422. xdp->prog_id = vsi->xdp_prog ? vsi->xdp_prog->aux->id : 0;
  10423. return 0;
  10424. default:
  10425. return -EINVAL;
  10426. }
  10427. }
  10428. static const struct net_device_ops i40e_netdev_ops = {
  10429. .ndo_open = i40e_open,
  10430. .ndo_stop = i40e_close,
  10431. .ndo_start_xmit = i40e_lan_xmit_frame,
  10432. .ndo_get_stats64 = i40e_get_netdev_stats_struct,
  10433. .ndo_set_rx_mode = i40e_set_rx_mode,
  10434. .ndo_validate_addr = eth_validate_addr,
  10435. .ndo_set_mac_address = i40e_set_mac,
  10436. .ndo_change_mtu = i40e_change_mtu,
  10437. .ndo_do_ioctl = i40e_ioctl,
  10438. .ndo_tx_timeout = i40e_tx_timeout,
  10439. .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
  10440. .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
  10441. #ifdef CONFIG_NET_POLL_CONTROLLER
  10442. .ndo_poll_controller = i40e_netpoll,
  10443. #endif
  10444. .ndo_setup_tc = __i40e_setup_tc,
  10445. .ndo_set_features = i40e_set_features,
  10446. .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
  10447. .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
  10448. .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
  10449. .ndo_get_vf_config = i40e_ndo_get_vf_config,
  10450. .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
  10451. .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
  10452. .ndo_set_vf_trust = i40e_ndo_set_vf_trust,
  10453. .ndo_udp_tunnel_add = i40e_udp_tunnel_add,
  10454. .ndo_udp_tunnel_del = i40e_udp_tunnel_del,
  10455. .ndo_get_phys_port_id = i40e_get_phys_port_id,
  10456. .ndo_fdb_add = i40e_ndo_fdb_add,
  10457. .ndo_features_check = i40e_features_check,
  10458. .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
  10459. .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
  10460. .ndo_bpf = i40e_xdp,
  10461. .ndo_xdp_xmit = i40e_xdp_xmit,
  10462. };
  10463. /**
  10464. * i40e_config_netdev - Setup the netdev flags
  10465. * @vsi: the VSI being configured
  10466. *
  10467. * Returns 0 on success, negative value on failure
  10468. **/
  10469. static int i40e_config_netdev(struct i40e_vsi *vsi)
  10470. {
  10471. struct i40e_pf *pf = vsi->back;
  10472. struct i40e_hw *hw = &pf->hw;
  10473. struct i40e_netdev_priv *np;
  10474. struct net_device *netdev;
  10475. u8 broadcast[ETH_ALEN];
  10476. u8 mac_addr[ETH_ALEN];
  10477. int etherdev_size;
  10478. netdev_features_t hw_enc_features;
  10479. netdev_features_t hw_features;
  10480. etherdev_size = sizeof(struct i40e_netdev_priv);
  10481. netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
  10482. if (!netdev)
  10483. return -ENOMEM;
  10484. vsi->netdev = netdev;
  10485. np = netdev_priv(netdev);
  10486. np->vsi = vsi;
  10487. hw_enc_features = NETIF_F_SG |
  10488. NETIF_F_IP_CSUM |
  10489. NETIF_F_IPV6_CSUM |
  10490. NETIF_F_HIGHDMA |
  10491. NETIF_F_SOFT_FEATURES |
  10492. NETIF_F_TSO |
  10493. NETIF_F_TSO_ECN |
  10494. NETIF_F_TSO6 |
  10495. NETIF_F_GSO_GRE |
  10496. NETIF_F_GSO_GRE_CSUM |
  10497. NETIF_F_GSO_PARTIAL |
  10498. NETIF_F_GSO_IPXIP4 |
  10499. NETIF_F_GSO_IPXIP6 |
  10500. NETIF_F_GSO_UDP_TUNNEL |
  10501. NETIF_F_GSO_UDP_TUNNEL_CSUM |
  10502. NETIF_F_SCTP_CRC |
  10503. NETIF_F_RXHASH |
  10504. NETIF_F_RXCSUM |
  10505. 0;
  10506. if (!(pf->hw_features & I40E_HW_OUTER_UDP_CSUM_CAPABLE))
  10507. netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
  10508. netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
  10509. netdev->hw_enc_features |= hw_enc_features;
  10510. /* record features VLANs can make use of */
  10511. netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID;
  10512. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  10513. netdev->hw_features |= NETIF_F_NTUPLE | NETIF_F_HW_TC;
  10514. hw_features = hw_enc_features |
  10515. NETIF_F_HW_VLAN_CTAG_TX |
  10516. NETIF_F_HW_VLAN_CTAG_RX;
  10517. netdev->hw_features |= hw_features;
  10518. netdev->features |= hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
  10519. netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
  10520. if (vsi->type == I40E_VSI_MAIN) {
  10521. SET_NETDEV_DEV(netdev, &pf->pdev->dev);
  10522. ether_addr_copy(mac_addr, hw->mac.perm_addr);
  10523. /* The following steps are necessary for two reasons. First,
  10524. * some older NVM configurations load a default MAC-VLAN
  10525. * filter that will accept any tagged packet, and we want to
  10526. * replace this with a normal filter. Additionally, it is
  10527. * possible our MAC address was provided by the platform using
  10528. * Open Firmware or similar.
  10529. *
  10530. * Thus, we need to remove the default filter and install one
  10531. * specific to the MAC address.
  10532. */
  10533. i40e_rm_default_mac_filter(vsi, mac_addr);
  10534. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10535. i40e_add_mac_filter(vsi, mac_addr);
  10536. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10537. } else {
  10538. /* Relate the VSI_VMDQ name to the VSI_MAIN name. Note that we
  10539. * are still limited by IFNAMSIZ, but we're adding 'v%d\0' to
  10540. * the end, which is 4 bytes long, so force truncation of the
  10541. * original name by IFNAMSIZ - 4
  10542. */
  10543. snprintf(netdev->name, IFNAMSIZ, "%.*sv%%d",
  10544. IFNAMSIZ - 4,
  10545. pf->vsi[pf->lan_vsi]->netdev->name);
  10546. eth_random_addr(mac_addr);
  10547. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10548. i40e_add_mac_filter(vsi, mac_addr);
  10549. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10550. }
  10551. /* Add the broadcast filter so that we initially will receive
  10552. * broadcast packets. Note that when a new VLAN is first added the
  10553. * driver will convert all filters marked I40E_VLAN_ANY into VLAN
  10554. * specific filters as part of transitioning into "vlan" operation.
  10555. * When more VLANs are added, the driver will copy each existing MAC
  10556. * filter and add it for the new VLAN.
  10557. *
  10558. * Broadcast filters are handled specially by
  10559. * i40e_sync_filters_subtask, as the driver must to set the broadcast
  10560. * promiscuous bit instead of adding this directly as a MAC/VLAN
  10561. * filter. The subtask will update the correct broadcast promiscuous
  10562. * bits as VLANs become active or inactive.
  10563. */
  10564. eth_broadcast_addr(broadcast);
  10565. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10566. i40e_add_mac_filter(vsi, broadcast);
  10567. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10568. ether_addr_copy(netdev->dev_addr, mac_addr);
  10569. ether_addr_copy(netdev->perm_addr, mac_addr);
  10570. /* i40iw_net_event() reads 16 bytes from neigh->primary_key */
  10571. netdev->neigh_priv_len = sizeof(u32) * 4;
  10572. netdev->priv_flags |= IFF_UNICAST_FLT;
  10573. netdev->priv_flags |= IFF_SUPP_NOFCS;
  10574. /* Setup netdev TC information */
  10575. i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
  10576. netdev->netdev_ops = &i40e_netdev_ops;
  10577. netdev->watchdog_timeo = 5 * HZ;
  10578. i40e_set_ethtool_ops(netdev);
  10579. /* MTU range: 68 - 9706 */
  10580. netdev->min_mtu = ETH_MIN_MTU;
  10581. netdev->max_mtu = I40E_MAX_RXBUFFER - I40E_PACKET_HDR_PAD;
  10582. return 0;
  10583. }
  10584. /**
  10585. * i40e_vsi_delete - Delete a VSI from the switch
  10586. * @vsi: the VSI being removed
  10587. *
  10588. * Returns 0 on success, negative value on failure
  10589. **/
  10590. static void i40e_vsi_delete(struct i40e_vsi *vsi)
  10591. {
  10592. /* remove default VSI is not allowed */
  10593. if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
  10594. return;
  10595. i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
  10596. }
  10597. /**
  10598. * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
  10599. * @vsi: the VSI being queried
  10600. *
  10601. * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
  10602. **/
  10603. int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
  10604. {
  10605. struct i40e_veb *veb;
  10606. struct i40e_pf *pf = vsi->back;
  10607. /* Uplink is not a bridge so default to VEB */
  10608. if (vsi->veb_idx == I40E_NO_VEB)
  10609. return 1;
  10610. veb = pf->veb[vsi->veb_idx];
  10611. if (!veb) {
  10612. dev_info(&pf->pdev->dev,
  10613. "There is no veb associated with the bridge\n");
  10614. return -ENOENT;
  10615. }
  10616. /* Uplink is a bridge in VEPA mode */
  10617. if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
  10618. return 0;
  10619. } else {
  10620. /* Uplink is a bridge in VEB mode */
  10621. return 1;
  10622. }
  10623. /* VEPA is now default bridge, so return 0 */
  10624. return 0;
  10625. }
  10626. /**
  10627. * i40e_add_vsi - Add a VSI to the switch
  10628. * @vsi: the VSI being configured
  10629. *
  10630. * This initializes a VSI context depending on the VSI type to be added and
  10631. * passes it down to the add_vsi aq command.
  10632. **/
  10633. static int i40e_add_vsi(struct i40e_vsi *vsi)
  10634. {
  10635. int ret = -ENODEV;
  10636. struct i40e_pf *pf = vsi->back;
  10637. struct i40e_hw *hw = &pf->hw;
  10638. struct i40e_vsi_context ctxt;
  10639. struct i40e_mac_filter *f;
  10640. struct hlist_node *h;
  10641. int bkt;
  10642. u8 enabled_tc = 0x1; /* TC0 enabled */
  10643. int f_count = 0;
  10644. memset(&ctxt, 0, sizeof(ctxt));
  10645. switch (vsi->type) {
  10646. case I40E_VSI_MAIN:
  10647. /* The PF's main VSI is already setup as part of the
  10648. * device initialization, so we'll not bother with
  10649. * the add_vsi call, but we will retrieve the current
  10650. * VSI context.
  10651. */
  10652. ctxt.seid = pf->main_vsi_seid;
  10653. ctxt.pf_num = pf->hw.pf_id;
  10654. ctxt.vf_num = 0;
  10655. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  10656. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  10657. if (ret) {
  10658. dev_info(&pf->pdev->dev,
  10659. "couldn't get PF vsi config, err %s aq_err %s\n",
  10660. i40e_stat_str(&pf->hw, ret),
  10661. i40e_aq_str(&pf->hw,
  10662. pf->hw.aq.asq_last_status));
  10663. return -ENOENT;
  10664. }
  10665. vsi->info = ctxt.info;
  10666. vsi->info.valid_sections = 0;
  10667. vsi->seid = ctxt.seid;
  10668. vsi->id = ctxt.vsi_number;
  10669. enabled_tc = i40e_pf_get_tc_map(pf);
  10670. /* Source pruning is enabled by default, so the flag is
  10671. * negative logic - if it's set, we need to fiddle with
  10672. * the VSI to disable source pruning.
  10673. */
  10674. if (pf->flags & I40E_FLAG_SOURCE_PRUNING_DISABLED) {
  10675. memset(&ctxt, 0, sizeof(ctxt));
  10676. ctxt.seid = pf->main_vsi_seid;
  10677. ctxt.pf_num = pf->hw.pf_id;
  10678. ctxt.vf_num = 0;
  10679. ctxt.info.valid_sections |=
  10680. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10681. ctxt.info.switch_id =
  10682. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
  10683. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  10684. if (ret) {
  10685. dev_info(&pf->pdev->dev,
  10686. "update vsi failed, err %s aq_err %s\n",
  10687. i40e_stat_str(&pf->hw, ret),
  10688. i40e_aq_str(&pf->hw,
  10689. pf->hw.aq.asq_last_status));
  10690. ret = -ENOENT;
  10691. goto err;
  10692. }
  10693. }
  10694. /* MFP mode setup queue map and update VSI */
  10695. if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
  10696. !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
  10697. memset(&ctxt, 0, sizeof(ctxt));
  10698. ctxt.seid = pf->main_vsi_seid;
  10699. ctxt.pf_num = pf->hw.pf_id;
  10700. ctxt.vf_num = 0;
  10701. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  10702. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  10703. if (ret) {
  10704. dev_info(&pf->pdev->dev,
  10705. "update vsi failed, err %s aq_err %s\n",
  10706. i40e_stat_str(&pf->hw, ret),
  10707. i40e_aq_str(&pf->hw,
  10708. pf->hw.aq.asq_last_status));
  10709. ret = -ENOENT;
  10710. goto err;
  10711. }
  10712. /* update the local VSI info queue map */
  10713. i40e_vsi_update_queue_map(vsi, &ctxt);
  10714. vsi->info.valid_sections = 0;
  10715. } else {
  10716. /* Default/Main VSI is only enabled for TC0
  10717. * reconfigure it to enable all TCs that are
  10718. * available on the port in SFP mode.
  10719. * For MFP case the iSCSI PF would use this
  10720. * flow to enable LAN+iSCSI TC.
  10721. */
  10722. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  10723. if (ret) {
  10724. /* Single TC condition is not fatal,
  10725. * message and continue
  10726. */
  10727. dev_info(&pf->pdev->dev,
  10728. "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
  10729. enabled_tc,
  10730. i40e_stat_str(&pf->hw, ret),
  10731. i40e_aq_str(&pf->hw,
  10732. pf->hw.aq.asq_last_status));
  10733. }
  10734. }
  10735. break;
  10736. case I40E_VSI_FDIR:
  10737. ctxt.pf_num = hw->pf_id;
  10738. ctxt.vf_num = 0;
  10739. ctxt.uplink_seid = vsi->uplink_seid;
  10740. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  10741. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  10742. if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
  10743. (i40e_is_vsi_uplink_mode_veb(vsi))) {
  10744. ctxt.info.valid_sections |=
  10745. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10746. ctxt.info.switch_id =
  10747. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  10748. }
  10749. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  10750. break;
  10751. case I40E_VSI_VMDQ2:
  10752. ctxt.pf_num = hw->pf_id;
  10753. ctxt.vf_num = 0;
  10754. ctxt.uplink_seid = vsi->uplink_seid;
  10755. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  10756. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  10757. /* This VSI is connected to VEB so the switch_id
  10758. * should be set to zero by default.
  10759. */
  10760. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  10761. ctxt.info.valid_sections |=
  10762. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10763. ctxt.info.switch_id =
  10764. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  10765. }
  10766. /* Setup the VSI tx/rx queue map for TC0 only for now */
  10767. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  10768. break;
  10769. case I40E_VSI_SRIOV:
  10770. ctxt.pf_num = hw->pf_id;
  10771. ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
  10772. ctxt.uplink_seid = vsi->uplink_seid;
  10773. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  10774. ctxt.flags = I40E_AQ_VSI_TYPE_VF;
  10775. /* This VSI is connected to VEB so the switch_id
  10776. * should be set to zero by default.
  10777. */
  10778. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  10779. ctxt.info.valid_sections |=
  10780. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10781. ctxt.info.switch_id =
  10782. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  10783. }
  10784. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  10785. ctxt.info.valid_sections |=
  10786. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  10787. ctxt.info.queueing_opt_flags |=
  10788. (I40E_AQ_VSI_QUE_OPT_TCP_ENA |
  10789. I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI);
  10790. }
  10791. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  10792. ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
  10793. if (pf->vf[vsi->vf_id].spoofchk) {
  10794. ctxt.info.valid_sections |=
  10795. cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
  10796. ctxt.info.sec_flags |=
  10797. (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
  10798. I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
  10799. }
  10800. /* Setup the VSI tx/rx queue map for TC0 only for now */
  10801. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  10802. break;
  10803. case I40E_VSI_IWARP:
  10804. /* send down message to iWARP */
  10805. break;
  10806. default:
  10807. return -ENODEV;
  10808. }
  10809. if (vsi->type != I40E_VSI_MAIN) {
  10810. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  10811. if (ret) {
  10812. dev_info(&vsi->back->pdev->dev,
  10813. "add vsi failed, err %s aq_err %s\n",
  10814. i40e_stat_str(&pf->hw, ret),
  10815. i40e_aq_str(&pf->hw,
  10816. pf->hw.aq.asq_last_status));
  10817. ret = -ENOENT;
  10818. goto err;
  10819. }
  10820. vsi->info = ctxt.info;
  10821. vsi->info.valid_sections = 0;
  10822. vsi->seid = ctxt.seid;
  10823. vsi->id = ctxt.vsi_number;
  10824. }
  10825. vsi->active_filters = 0;
  10826. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  10827. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10828. /* If macvlan filters already exist, force them to get loaded */
  10829. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  10830. f->state = I40E_FILTER_NEW;
  10831. f_count++;
  10832. }
  10833. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10834. if (f_count) {
  10835. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  10836. set_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state);
  10837. }
  10838. /* Update VSI BW information */
  10839. ret = i40e_vsi_get_bw_info(vsi);
  10840. if (ret) {
  10841. dev_info(&pf->pdev->dev,
  10842. "couldn't get vsi bw info, err %s aq_err %s\n",
  10843. i40e_stat_str(&pf->hw, ret),
  10844. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  10845. /* VSI is already added so not tearing that up */
  10846. ret = 0;
  10847. }
  10848. err:
  10849. return ret;
  10850. }
  10851. /**
  10852. * i40e_vsi_release - Delete a VSI and free its resources
  10853. * @vsi: the VSI being removed
  10854. *
  10855. * Returns 0 on success or < 0 on error
  10856. **/
  10857. int i40e_vsi_release(struct i40e_vsi *vsi)
  10858. {
  10859. struct i40e_mac_filter *f;
  10860. struct hlist_node *h;
  10861. struct i40e_veb *veb = NULL;
  10862. struct i40e_pf *pf;
  10863. u16 uplink_seid;
  10864. int i, n, bkt;
  10865. pf = vsi->back;
  10866. /* release of a VEB-owner or last VSI is not allowed */
  10867. if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
  10868. dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
  10869. vsi->seid, vsi->uplink_seid);
  10870. return -ENODEV;
  10871. }
  10872. if (vsi == pf->vsi[pf->lan_vsi] &&
  10873. !test_bit(__I40E_DOWN, pf->state)) {
  10874. dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
  10875. return -ENODEV;
  10876. }
  10877. uplink_seid = vsi->uplink_seid;
  10878. if (vsi->type != I40E_VSI_SRIOV) {
  10879. if (vsi->netdev_registered) {
  10880. vsi->netdev_registered = false;
  10881. if (vsi->netdev) {
  10882. /* results in a call to i40e_close() */
  10883. unregister_netdev(vsi->netdev);
  10884. }
  10885. } else {
  10886. i40e_vsi_close(vsi);
  10887. }
  10888. i40e_vsi_disable_irq(vsi);
  10889. }
  10890. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10891. /* clear the sync flag on all filters */
  10892. if (vsi->netdev) {
  10893. __dev_uc_unsync(vsi->netdev, NULL);
  10894. __dev_mc_unsync(vsi->netdev, NULL);
  10895. }
  10896. /* make sure any remaining filters are marked for deletion */
  10897. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
  10898. __i40e_del_filter(vsi, f);
  10899. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10900. i40e_sync_vsi_filters(vsi);
  10901. i40e_vsi_delete(vsi);
  10902. i40e_vsi_free_q_vectors(vsi);
  10903. if (vsi->netdev) {
  10904. free_netdev(vsi->netdev);
  10905. vsi->netdev = NULL;
  10906. }
  10907. i40e_vsi_clear_rings(vsi);
  10908. i40e_vsi_clear(vsi);
  10909. /* If this was the last thing on the VEB, except for the
  10910. * controlling VSI, remove the VEB, which puts the controlling
  10911. * VSI onto the next level down in the switch.
  10912. *
  10913. * Well, okay, there's one more exception here: don't remove
  10914. * the orphan VEBs yet. We'll wait for an explicit remove request
  10915. * from up the network stack.
  10916. */
  10917. for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
  10918. if (pf->vsi[i] &&
  10919. pf->vsi[i]->uplink_seid == uplink_seid &&
  10920. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  10921. n++; /* count the VSIs */
  10922. }
  10923. }
  10924. for (i = 0; i < I40E_MAX_VEB; i++) {
  10925. if (!pf->veb[i])
  10926. continue;
  10927. if (pf->veb[i]->uplink_seid == uplink_seid)
  10928. n++; /* count the VEBs */
  10929. if (pf->veb[i]->seid == uplink_seid)
  10930. veb = pf->veb[i];
  10931. }
  10932. if (n == 0 && veb && veb->uplink_seid != 0)
  10933. i40e_veb_release(veb);
  10934. return 0;
  10935. }
  10936. /**
  10937. * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
  10938. * @vsi: ptr to the VSI
  10939. *
  10940. * This should only be called after i40e_vsi_mem_alloc() which allocates the
  10941. * corresponding SW VSI structure and initializes num_queue_pairs for the
  10942. * newly allocated VSI.
  10943. *
  10944. * Returns 0 on success or negative on failure
  10945. **/
  10946. static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
  10947. {
  10948. int ret = -ENOENT;
  10949. struct i40e_pf *pf = vsi->back;
  10950. if (vsi->q_vectors[0]) {
  10951. dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
  10952. vsi->seid);
  10953. return -EEXIST;
  10954. }
  10955. if (vsi->base_vector) {
  10956. dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
  10957. vsi->seid, vsi->base_vector);
  10958. return -EEXIST;
  10959. }
  10960. ret = i40e_vsi_alloc_q_vectors(vsi);
  10961. if (ret) {
  10962. dev_info(&pf->pdev->dev,
  10963. "failed to allocate %d q_vector for VSI %d, ret=%d\n",
  10964. vsi->num_q_vectors, vsi->seid, ret);
  10965. vsi->num_q_vectors = 0;
  10966. goto vector_setup_out;
  10967. }
  10968. /* In Legacy mode, we do not have to get any other vector since we
  10969. * piggyback on the misc/ICR0 for queue interrupts.
  10970. */
  10971. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  10972. return ret;
  10973. if (vsi->num_q_vectors)
  10974. vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
  10975. vsi->num_q_vectors, vsi->idx);
  10976. if (vsi->base_vector < 0) {
  10977. dev_info(&pf->pdev->dev,
  10978. "failed to get tracking for %d vectors for VSI %d, err=%d\n",
  10979. vsi->num_q_vectors, vsi->seid, vsi->base_vector);
  10980. i40e_vsi_free_q_vectors(vsi);
  10981. ret = -ENOENT;
  10982. goto vector_setup_out;
  10983. }
  10984. vector_setup_out:
  10985. return ret;
  10986. }
  10987. /**
  10988. * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
  10989. * @vsi: pointer to the vsi.
  10990. *
  10991. * This re-allocates a vsi's queue resources.
  10992. *
  10993. * Returns pointer to the successfully allocated and configured VSI sw struct
  10994. * on success, otherwise returns NULL on failure.
  10995. **/
  10996. static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
  10997. {
  10998. u16 alloc_queue_pairs;
  10999. struct i40e_pf *pf;
  11000. u8 enabled_tc;
  11001. int ret;
  11002. if (!vsi)
  11003. return NULL;
  11004. pf = vsi->back;
  11005. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  11006. i40e_vsi_clear_rings(vsi);
  11007. i40e_vsi_free_arrays(vsi, false);
  11008. i40e_set_num_rings_in_vsi(vsi);
  11009. ret = i40e_vsi_alloc_arrays(vsi, false);
  11010. if (ret)
  11011. goto err_vsi;
  11012. alloc_queue_pairs = vsi->alloc_queue_pairs *
  11013. (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
  11014. ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
  11015. if (ret < 0) {
  11016. dev_info(&pf->pdev->dev,
  11017. "failed to get tracking for %d queues for VSI %d err %d\n",
  11018. alloc_queue_pairs, vsi->seid, ret);
  11019. goto err_vsi;
  11020. }
  11021. vsi->base_queue = ret;
  11022. /* Update the FW view of the VSI. Force a reset of TC and queue
  11023. * layout configurations.
  11024. */
  11025. enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  11026. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  11027. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  11028. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  11029. if (vsi->type == I40E_VSI_MAIN)
  11030. i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr);
  11031. /* assign it some queues */
  11032. ret = i40e_alloc_rings(vsi);
  11033. if (ret)
  11034. goto err_rings;
  11035. /* map all of the rings to the q_vectors */
  11036. i40e_vsi_map_rings_to_vectors(vsi);
  11037. return vsi;
  11038. err_rings:
  11039. i40e_vsi_free_q_vectors(vsi);
  11040. if (vsi->netdev_registered) {
  11041. vsi->netdev_registered = false;
  11042. unregister_netdev(vsi->netdev);
  11043. free_netdev(vsi->netdev);
  11044. vsi->netdev = NULL;
  11045. }
  11046. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  11047. err_vsi:
  11048. i40e_vsi_clear(vsi);
  11049. return NULL;
  11050. }
  11051. /**
  11052. * i40e_vsi_setup - Set up a VSI by a given type
  11053. * @pf: board private structure
  11054. * @type: VSI type
  11055. * @uplink_seid: the switch element to link to
  11056. * @param1: usage depends upon VSI type. For VF types, indicates VF id
  11057. *
  11058. * This allocates the sw VSI structure and its queue resources, then add a VSI
  11059. * to the identified VEB.
  11060. *
  11061. * Returns pointer to the successfully allocated and configure VSI sw struct on
  11062. * success, otherwise returns NULL on failure.
  11063. **/
  11064. struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
  11065. u16 uplink_seid, u32 param1)
  11066. {
  11067. struct i40e_vsi *vsi = NULL;
  11068. struct i40e_veb *veb = NULL;
  11069. u16 alloc_queue_pairs;
  11070. int ret, i;
  11071. int v_idx;
  11072. /* The requested uplink_seid must be either
  11073. * - the PF's port seid
  11074. * no VEB is needed because this is the PF
  11075. * or this is a Flow Director special case VSI
  11076. * - seid of an existing VEB
  11077. * - seid of a VSI that owns an existing VEB
  11078. * - seid of a VSI that doesn't own a VEB
  11079. * a new VEB is created and the VSI becomes the owner
  11080. * - seid of the PF VSI, which is what creates the first VEB
  11081. * this is a special case of the previous
  11082. *
  11083. * Find which uplink_seid we were given and create a new VEB if needed
  11084. */
  11085. for (i = 0; i < I40E_MAX_VEB; i++) {
  11086. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
  11087. veb = pf->veb[i];
  11088. break;
  11089. }
  11090. }
  11091. if (!veb && uplink_seid != pf->mac_seid) {
  11092. for (i = 0; i < pf->num_alloc_vsi; i++) {
  11093. if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
  11094. vsi = pf->vsi[i];
  11095. break;
  11096. }
  11097. }
  11098. if (!vsi) {
  11099. dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
  11100. uplink_seid);
  11101. return NULL;
  11102. }
  11103. if (vsi->uplink_seid == pf->mac_seid)
  11104. veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
  11105. vsi->tc_config.enabled_tc);
  11106. else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
  11107. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  11108. vsi->tc_config.enabled_tc);
  11109. if (veb) {
  11110. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
  11111. dev_info(&vsi->back->pdev->dev,
  11112. "New VSI creation error, uplink seid of LAN VSI expected.\n");
  11113. return NULL;
  11114. }
  11115. /* We come up by default in VEPA mode if SRIOV is not
  11116. * already enabled, in which case we can't force VEPA
  11117. * mode.
  11118. */
  11119. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  11120. veb->bridge_mode = BRIDGE_MODE_VEPA;
  11121. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  11122. }
  11123. i40e_config_bridge_mode(veb);
  11124. }
  11125. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  11126. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  11127. veb = pf->veb[i];
  11128. }
  11129. if (!veb) {
  11130. dev_info(&pf->pdev->dev, "couldn't add VEB\n");
  11131. return NULL;
  11132. }
  11133. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  11134. uplink_seid = veb->seid;
  11135. }
  11136. /* get vsi sw struct */
  11137. v_idx = i40e_vsi_mem_alloc(pf, type);
  11138. if (v_idx < 0)
  11139. goto err_alloc;
  11140. vsi = pf->vsi[v_idx];
  11141. if (!vsi)
  11142. goto err_alloc;
  11143. vsi->type = type;
  11144. vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
  11145. if (type == I40E_VSI_MAIN)
  11146. pf->lan_vsi = v_idx;
  11147. else if (type == I40E_VSI_SRIOV)
  11148. vsi->vf_id = param1;
  11149. /* assign it some queues */
  11150. alloc_queue_pairs = vsi->alloc_queue_pairs *
  11151. (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
  11152. ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
  11153. if (ret < 0) {
  11154. dev_info(&pf->pdev->dev,
  11155. "failed to get tracking for %d queues for VSI %d err=%d\n",
  11156. alloc_queue_pairs, vsi->seid, ret);
  11157. goto err_vsi;
  11158. }
  11159. vsi->base_queue = ret;
  11160. /* get a VSI from the hardware */
  11161. vsi->uplink_seid = uplink_seid;
  11162. ret = i40e_add_vsi(vsi);
  11163. if (ret)
  11164. goto err_vsi;
  11165. switch (vsi->type) {
  11166. /* setup the netdev if needed */
  11167. case I40E_VSI_MAIN:
  11168. case I40E_VSI_VMDQ2:
  11169. ret = i40e_config_netdev(vsi);
  11170. if (ret)
  11171. goto err_netdev;
  11172. ret = register_netdev(vsi->netdev);
  11173. if (ret)
  11174. goto err_netdev;
  11175. vsi->netdev_registered = true;
  11176. netif_carrier_off(vsi->netdev);
  11177. #ifdef CONFIG_I40E_DCB
  11178. /* Setup DCB netlink interface */
  11179. i40e_dcbnl_setup(vsi);
  11180. #endif /* CONFIG_I40E_DCB */
  11181. /* fall through */
  11182. case I40E_VSI_FDIR:
  11183. /* set up vectors and rings if needed */
  11184. ret = i40e_vsi_setup_vectors(vsi);
  11185. if (ret)
  11186. goto err_msix;
  11187. ret = i40e_alloc_rings(vsi);
  11188. if (ret)
  11189. goto err_rings;
  11190. /* map all of the rings to the q_vectors */
  11191. i40e_vsi_map_rings_to_vectors(vsi);
  11192. i40e_vsi_reset_stats(vsi);
  11193. break;
  11194. default:
  11195. /* no netdev or rings for the other VSI types */
  11196. break;
  11197. }
  11198. if ((pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) &&
  11199. (vsi->type == I40E_VSI_VMDQ2)) {
  11200. ret = i40e_vsi_config_rss(vsi);
  11201. }
  11202. return vsi;
  11203. err_rings:
  11204. i40e_vsi_free_q_vectors(vsi);
  11205. err_msix:
  11206. if (vsi->netdev_registered) {
  11207. vsi->netdev_registered = false;
  11208. unregister_netdev(vsi->netdev);
  11209. free_netdev(vsi->netdev);
  11210. vsi->netdev = NULL;
  11211. }
  11212. err_netdev:
  11213. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  11214. err_vsi:
  11215. i40e_vsi_clear(vsi);
  11216. err_alloc:
  11217. return NULL;
  11218. }
  11219. /**
  11220. * i40e_veb_get_bw_info - Query VEB BW information
  11221. * @veb: the veb to query
  11222. *
  11223. * Query the Tx scheduler BW configuration data for given VEB
  11224. **/
  11225. static int i40e_veb_get_bw_info(struct i40e_veb *veb)
  11226. {
  11227. struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
  11228. struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
  11229. struct i40e_pf *pf = veb->pf;
  11230. struct i40e_hw *hw = &pf->hw;
  11231. u32 tc_bw_max;
  11232. int ret = 0;
  11233. int i;
  11234. ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
  11235. &bw_data, NULL);
  11236. if (ret) {
  11237. dev_info(&pf->pdev->dev,
  11238. "query veb bw config failed, err %s aq_err %s\n",
  11239. i40e_stat_str(&pf->hw, ret),
  11240. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  11241. goto out;
  11242. }
  11243. ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
  11244. &ets_data, NULL);
  11245. if (ret) {
  11246. dev_info(&pf->pdev->dev,
  11247. "query veb bw ets config failed, err %s aq_err %s\n",
  11248. i40e_stat_str(&pf->hw, ret),
  11249. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  11250. goto out;
  11251. }
  11252. veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
  11253. veb->bw_max_quanta = ets_data.tc_bw_max;
  11254. veb->is_abs_credits = bw_data.absolute_credits_enable;
  11255. veb->enabled_tc = ets_data.tc_valid_bits;
  11256. tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
  11257. (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
  11258. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  11259. veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
  11260. veb->bw_tc_limit_credits[i] =
  11261. le16_to_cpu(bw_data.tc_bw_limits[i]);
  11262. veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
  11263. }
  11264. out:
  11265. return ret;
  11266. }
  11267. /**
  11268. * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
  11269. * @pf: board private structure
  11270. *
  11271. * On error: returns error code (negative)
  11272. * On success: returns vsi index in PF (positive)
  11273. **/
  11274. static int i40e_veb_mem_alloc(struct i40e_pf *pf)
  11275. {
  11276. int ret = -ENOENT;
  11277. struct i40e_veb *veb;
  11278. int i;
  11279. /* Need to protect the allocation of switch elements at the PF level */
  11280. mutex_lock(&pf->switch_mutex);
  11281. /* VEB list may be fragmented if VEB creation/destruction has
  11282. * been happening. We can afford to do a quick scan to look
  11283. * for any free slots in the list.
  11284. *
  11285. * find next empty veb slot, looping back around if necessary
  11286. */
  11287. i = 0;
  11288. while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
  11289. i++;
  11290. if (i >= I40E_MAX_VEB) {
  11291. ret = -ENOMEM;
  11292. goto err_alloc_veb; /* out of VEB slots! */
  11293. }
  11294. veb = kzalloc(sizeof(*veb), GFP_KERNEL);
  11295. if (!veb) {
  11296. ret = -ENOMEM;
  11297. goto err_alloc_veb;
  11298. }
  11299. veb->pf = pf;
  11300. veb->idx = i;
  11301. veb->enabled_tc = 1;
  11302. pf->veb[i] = veb;
  11303. ret = i;
  11304. err_alloc_veb:
  11305. mutex_unlock(&pf->switch_mutex);
  11306. return ret;
  11307. }
  11308. /**
  11309. * i40e_switch_branch_release - Delete a branch of the switch tree
  11310. * @branch: where to start deleting
  11311. *
  11312. * This uses recursion to find the tips of the branch to be
  11313. * removed, deleting until we get back to and can delete this VEB.
  11314. **/
  11315. static void i40e_switch_branch_release(struct i40e_veb *branch)
  11316. {
  11317. struct i40e_pf *pf = branch->pf;
  11318. u16 branch_seid = branch->seid;
  11319. u16 veb_idx = branch->idx;
  11320. int i;
  11321. /* release any VEBs on this VEB - RECURSION */
  11322. for (i = 0; i < I40E_MAX_VEB; i++) {
  11323. if (!pf->veb[i])
  11324. continue;
  11325. if (pf->veb[i]->uplink_seid == branch->seid)
  11326. i40e_switch_branch_release(pf->veb[i]);
  11327. }
  11328. /* Release the VSIs on this VEB, but not the owner VSI.
  11329. *
  11330. * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
  11331. * the VEB itself, so don't use (*branch) after this loop.
  11332. */
  11333. for (i = 0; i < pf->num_alloc_vsi; i++) {
  11334. if (!pf->vsi[i])
  11335. continue;
  11336. if (pf->vsi[i]->uplink_seid == branch_seid &&
  11337. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  11338. i40e_vsi_release(pf->vsi[i]);
  11339. }
  11340. }
  11341. /* There's one corner case where the VEB might not have been
  11342. * removed, so double check it here and remove it if needed.
  11343. * This case happens if the veb was created from the debugfs
  11344. * commands and no VSIs were added to it.
  11345. */
  11346. if (pf->veb[veb_idx])
  11347. i40e_veb_release(pf->veb[veb_idx]);
  11348. }
  11349. /**
  11350. * i40e_veb_clear - remove veb struct
  11351. * @veb: the veb to remove
  11352. **/
  11353. static void i40e_veb_clear(struct i40e_veb *veb)
  11354. {
  11355. if (!veb)
  11356. return;
  11357. if (veb->pf) {
  11358. struct i40e_pf *pf = veb->pf;
  11359. mutex_lock(&pf->switch_mutex);
  11360. if (pf->veb[veb->idx] == veb)
  11361. pf->veb[veb->idx] = NULL;
  11362. mutex_unlock(&pf->switch_mutex);
  11363. }
  11364. kfree(veb);
  11365. }
  11366. /**
  11367. * i40e_veb_release - Delete a VEB and free its resources
  11368. * @veb: the VEB being removed
  11369. **/
  11370. void i40e_veb_release(struct i40e_veb *veb)
  11371. {
  11372. struct i40e_vsi *vsi = NULL;
  11373. struct i40e_pf *pf;
  11374. int i, n = 0;
  11375. pf = veb->pf;
  11376. /* find the remaining VSI and check for extras */
  11377. for (i = 0; i < pf->num_alloc_vsi; i++) {
  11378. if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
  11379. n++;
  11380. vsi = pf->vsi[i];
  11381. }
  11382. }
  11383. if (n != 1) {
  11384. dev_info(&pf->pdev->dev,
  11385. "can't remove VEB %d with %d VSIs left\n",
  11386. veb->seid, n);
  11387. return;
  11388. }
  11389. /* move the remaining VSI to uplink veb */
  11390. vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
  11391. if (veb->uplink_seid) {
  11392. vsi->uplink_seid = veb->uplink_seid;
  11393. if (veb->uplink_seid == pf->mac_seid)
  11394. vsi->veb_idx = I40E_NO_VEB;
  11395. else
  11396. vsi->veb_idx = veb->veb_idx;
  11397. } else {
  11398. /* floating VEB */
  11399. vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  11400. vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
  11401. }
  11402. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  11403. i40e_veb_clear(veb);
  11404. }
  11405. /**
  11406. * i40e_add_veb - create the VEB in the switch
  11407. * @veb: the VEB to be instantiated
  11408. * @vsi: the controlling VSI
  11409. **/
  11410. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
  11411. {
  11412. struct i40e_pf *pf = veb->pf;
  11413. bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
  11414. int ret;
  11415. ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
  11416. veb->enabled_tc, false,
  11417. &veb->seid, enable_stats, NULL);
  11418. /* get a VEB from the hardware */
  11419. if (ret) {
  11420. dev_info(&pf->pdev->dev,
  11421. "couldn't add VEB, err %s aq_err %s\n",
  11422. i40e_stat_str(&pf->hw, ret),
  11423. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11424. return -EPERM;
  11425. }
  11426. /* get statistics counter */
  11427. ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
  11428. &veb->stats_idx, NULL, NULL, NULL);
  11429. if (ret) {
  11430. dev_info(&pf->pdev->dev,
  11431. "couldn't get VEB statistics idx, err %s aq_err %s\n",
  11432. i40e_stat_str(&pf->hw, ret),
  11433. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11434. return -EPERM;
  11435. }
  11436. ret = i40e_veb_get_bw_info(veb);
  11437. if (ret) {
  11438. dev_info(&pf->pdev->dev,
  11439. "couldn't get VEB bw info, err %s aq_err %s\n",
  11440. i40e_stat_str(&pf->hw, ret),
  11441. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11442. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  11443. return -ENOENT;
  11444. }
  11445. vsi->uplink_seid = veb->seid;
  11446. vsi->veb_idx = veb->idx;
  11447. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  11448. return 0;
  11449. }
  11450. /**
  11451. * i40e_veb_setup - Set up a VEB
  11452. * @pf: board private structure
  11453. * @flags: VEB setup flags
  11454. * @uplink_seid: the switch element to link to
  11455. * @vsi_seid: the initial VSI seid
  11456. * @enabled_tc: Enabled TC bit-map
  11457. *
  11458. * This allocates the sw VEB structure and links it into the switch
  11459. * It is possible and legal for this to be a duplicate of an already
  11460. * existing VEB. It is also possible for both uplink and vsi seids
  11461. * to be zero, in order to create a floating VEB.
  11462. *
  11463. * Returns pointer to the successfully allocated VEB sw struct on
  11464. * success, otherwise returns NULL on failure.
  11465. **/
  11466. struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
  11467. u16 uplink_seid, u16 vsi_seid,
  11468. u8 enabled_tc)
  11469. {
  11470. struct i40e_veb *veb, *uplink_veb = NULL;
  11471. int vsi_idx, veb_idx;
  11472. int ret;
  11473. /* if one seid is 0, the other must be 0 to create a floating relay */
  11474. if ((uplink_seid == 0 || vsi_seid == 0) &&
  11475. (uplink_seid + vsi_seid != 0)) {
  11476. dev_info(&pf->pdev->dev,
  11477. "one, not both seid's are 0: uplink=%d vsi=%d\n",
  11478. uplink_seid, vsi_seid);
  11479. return NULL;
  11480. }
  11481. /* make sure there is such a vsi and uplink */
  11482. for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
  11483. if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
  11484. break;
  11485. if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
  11486. dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
  11487. vsi_seid);
  11488. return NULL;
  11489. }
  11490. if (uplink_seid && uplink_seid != pf->mac_seid) {
  11491. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  11492. if (pf->veb[veb_idx] &&
  11493. pf->veb[veb_idx]->seid == uplink_seid) {
  11494. uplink_veb = pf->veb[veb_idx];
  11495. break;
  11496. }
  11497. }
  11498. if (!uplink_veb) {
  11499. dev_info(&pf->pdev->dev,
  11500. "uplink seid %d not found\n", uplink_seid);
  11501. return NULL;
  11502. }
  11503. }
  11504. /* get veb sw struct */
  11505. veb_idx = i40e_veb_mem_alloc(pf);
  11506. if (veb_idx < 0)
  11507. goto err_alloc;
  11508. veb = pf->veb[veb_idx];
  11509. veb->flags = flags;
  11510. veb->uplink_seid = uplink_seid;
  11511. veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
  11512. veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
  11513. /* create the VEB in the switch */
  11514. ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
  11515. if (ret)
  11516. goto err_veb;
  11517. if (vsi_idx == pf->lan_vsi)
  11518. pf->lan_veb = veb->idx;
  11519. return veb;
  11520. err_veb:
  11521. i40e_veb_clear(veb);
  11522. err_alloc:
  11523. return NULL;
  11524. }
  11525. /**
  11526. * i40e_setup_pf_switch_element - set PF vars based on switch type
  11527. * @pf: board private structure
  11528. * @ele: element we are building info from
  11529. * @num_reported: total number of elements
  11530. * @printconfig: should we print the contents
  11531. *
  11532. * helper function to assist in extracting a few useful SEID values.
  11533. **/
  11534. static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
  11535. struct i40e_aqc_switch_config_element_resp *ele,
  11536. u16 num_reported, bool printconfig)
  11537. {
  11538. u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
  11539. u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
  11540. u8 element_type = ele->element_type;
  11541. u16 seid = le16_to_cpu(ele->seid);
  11542. if (printconfig)
  11543. dev_info(&pf->pdev->dev,
  11544. "type=%d seid=%d uplink=%d downlink=%d\n",
  11545. element_type, seid, uplink_seid, downlink_seid);
  11546. switch (element_type) {
  11547. case I40E_SWITCH_ELEMENT_TYPE_MAC:
  11548. pf->mac_seid = seid;
  11549. break;
  11550. case I40E_SWITCH_ELEMENT_TYPE_VEB:
  11551. /* Main VEB? */
  11552. if (uplink_seid != pf->mac_seid)
  11553. break;
  11554. if (pf->lan_veb == I40E_NO_VEB) {
  11555. int v;
  11556. /* find existing or else empty VEB */
  11557. for (v = 0; v < I40E_MAX_VEB; v++) {
  11558. if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
  11559. pf->lan_veb = v;
  11560. break;
  11561. }
  11562. }
  11563. if (pf->lan_veb == I40E_NO_VEB) {
  11564. v = i40e_veb_mem_alloc(pf);
  11565. if (v < 0)
  11566. break;
  11567. pf->lan_veb = v;
  11568. }
  11569. }
  11570. pf->veb[pf->lan_veb]->seid = seid;
  11571. pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
  11572. pf->veb[pf->lan_veb]->pf = pf;
  11573. pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
  11574. break;
  11575. case I40E_SWITCH_ELEMENT_TYPE_VSI:
  11576. if (num_reported != 1)
  11577. break;
  11578. /* This is immediately after a reset so we can assume this is
  11579. * the PF's VSI
  11580. */
  11581. pf->mac_seid = uplink_seid;
  11582. pf->pf_seid = downlink_seid;
  11583. pf->main_vsi_seid = seid;
  11584. if (printconfig)
  11585. dev_info(&pf->pdev->dev,
  11586. "pf_seid=%d main_vsi_seid=%d\n",
  11587. pf->pf_seid, pf->main_vsi_seid);
  11588. break;
  11589. case I40E_SWITCH_ELEMENT_TYPE_PF:
  11590. case I40E_SWITCH_ELEMENT_TYPE_VF:
  11591. case I40E_SWITCH_ELEMENT_TYPE_EMP:
  11592. case I40E_SWITCH_ELEMENT_TYPE_BMC:
  11593. case I40E_SWITCH_ELEMENT_TYPE_PE:
  11594. case I40E_SWITCH_ELEMENT_TYPE_PA:
  11595. /* ignore these for now */
  11596. break;
  11597. default:
  11598. dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
  11599. element_type, seid);
  11600. break;
  11601. }
  11602. }
  11603. /**
  11604. * i40e_fetch_switch_configuration - Get switch config from firmware
  11605. * @pf: board private structure
  11606. * @printconfig: should we print the contents
  11607. *
  11608. * Get the current switch configuration from the device and
  11609. * extract a few useful SEID values.
  11610. **/
  11611. int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
  11612. {
  11613. struct i40e_aqc_get_switch_config_resp *sw_config;
  11614. u16 next_seid = 0;
  11615. int ret = 0;
  11616. u8 *aq_buf;
  11617. int i;
  11618. aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
  11619. if (!aq_buf)
  11620. return -ENOMEM;
  11621. sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
  11622. do {
  11623. u16 num_reported, num_total;
  11624. ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
  11625. I40E_AQ_LARGE_BUF,
  11626. &next_seid, NULL);
  11627. if (ret) {
  11628. dev_info(&pf->pdev->dev,
  11629. "get switch config failed err %s aq_err %s\n",
  11630. i40e_stat_str(&pf->hw, ret),
  11631. i40e_aq_str(&pf->hw,
  11632. pf->hw.aq.asq_last_status));
  11633. kfree(aq_buf);
  11634. return -ENOENT;
  11635. }
  11636. num_reported = le16_to_cpu(sw_config->header.num_reported);
  11637. num_total = le16_to_cpu(sw_config->header.num_total);
  11638. if (printconfig)
  11639. dev_info(&pf->pdev->dev,
  11640. "header: %d reported %d total\n",
  11641. num_reported, num_total);
  11642. for (i = 0; i < num_reported; i++) {
  11643. struct i40e_aqc_switch_config_element_resp *ele =
  11644. &sw_config->element[i];
  11645. i40e_setup_pf_switch_element(pf, ele, num_reported,
  11646. printconfig);
  11647. }
  11648. } while (next_seid != 0);
  11649. kfree(aq_buf);
  11650. return ret;
  11651. }
  11652. /**
  11653. * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
  11654. * @pf: board private structure
  11655. * @reinit: if the Main VSI needs to re-initialized.
  11656. *
  11657. * Returns 0 on success, negative value on failure
  11658. **/
  11659. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
  11660. {
  11661. u16 flags = 0;
  11662. int ret;
  11663. /* find out what's out there already */
  11664. ret = i40e_fetch_switch_configuration(pf, false);
  11665. if (ret) {
  11666. dev_info(&pf->pdev->dev,
  11667. "couldn't fetch switch config, err %s aq_err %s\n",
  11668. i40e_stat_str(&pf->hw, ret),
  11669. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11670. return ret;
  11671. }
  11672. i40e_pf_reset_stats(pf);
  11673. /* set the switch config bit for the whole device to
  11674. * support limited promisc or true promisc
  11675. * when user requests promisc. The default is limited
  11676. * promisc.
  11677. */
  11678. if ((pf->hw.pf_id == 0) &&
  11679. !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
  11680. flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  11681. pf->last_sw_conf_flags = flags;
  11682. }
  11683. if (pf->hw.pf_id == 0) {
  11684. u16 valid_flags;
  11685. valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  11686. ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, 0,
  11687. NULL);
  11688. if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
  11689. dev_info(&pf->pdev->dev,
  11690. "couldn't set switch config bits, err %s aq_err %s\n",
  11691. i40e_stat_str(&pf->hw, ret),
  11692. i40e_aq_str(&pf->hw,
  11693. pf->hw.aq.asq_last_status));
  11694. /* not a fatal problem, just keep going */
  11695. }
  11696. pf->last_sw_conf_valid_flags = valid_flags;
  11697. }
  11698. /* first time setup */
  11699. if (pf->lan_vsi == I40E_NO_VSI || reinit) {
  11700. struct i40e_vsi *vsi = NULL;
  11701. u16 uplink_seid;
  11702. /* Set up the PF VSI associated with the PF's main VSI
  11703. * that is already in the HW switch
  11704. */
  11705. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  11706. uplink_seid = pf->veb[pf->lan_veb]->seid;
  11707. else
  11708. uplink_seid = pf->mac_seid;
  11709. if (pf->lan_vsi == I40E_NO_VSI)
  11710. vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
  11711. else if (reinit)
  11712. vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
  11713. if (!vsi) {
  11714. dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
  11715. i40e_cloud_filter_exit(pf);
  11716. i40e_fdir_teardown(pf);
  11717. return -EAGAIN;
  11718. }
  11719. } else {
  11720. /* force a reset of TC and queue layout configurations */
  11721. u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  11722. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  11723. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  11724. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  11725. }
  11726. i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
  11727. i40e_fdir_sb_setup(pf);
  11728. /* Setup static PF queue filter control settings */
  11729. ret = i40e_setup_pf_filter_control(pf);
  11730. if (ret) {
  11731. dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
  11732. ret);
  11733. /* Failure here should not stop continuing other steps */
  11734. }
  11735. /* enable RSS in the HW, even for only one queue, as the stack can use
  11736. * the hash
  11737. */
  11738. if ((pf->flags & I40E_FLAG_RSS_ENABLED))
  11739. i40e_pf_config_rss(pf);
  11740. /* fill in link information and enable LSE reporting */
  11741. i40e_link_event(pf);
  11742. /* Initialize user-specific link properties */
  11743. pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
  11744. I40E_AQ_AN_COMPLETED) ? true : false);
  11745. i40e_ptp_init(pf);
  11746. /* repopulate tunnel port filters */
  11747. i40e_sync_udp_filters(pf);
  11748. return ret;
  11749. }
  11750. /**
  11751. * i40e_determine_queue_usage - Work out queue distribution
  11752. * @pf: board private structure
  11753. **/
  11754. static void i40e_determine_queue_usage(struct i40e_pf *pf)
  11755. {
  11756. int queues_left;
  11757. int q_max;
  11758. pf->num_lan_qps = 0;
  11759. /* Find the max queues to be put into basic use. We'll always be
  11760. * using TC0, whether or not DCB is running, and TC0 will get the
  11761. * big RSS set.
  11762. */
  11763. queues_left = pf->hw.func_caps.num_tx_qp;
  11764. if ((queues_left == 1) ||
  11765. !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  11766. /* one qp for PF, no queues for anything else */
  11767. queues_left = 0;
  11768. pf->alloc_rss_size = pf->num_lan_qps = 1;
  11769. /* make sure all the fancies are disabled */
  11770. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  11771. I40E_FLAG_IWARP_ENABLED |
  11772. I40E_FLAG_FD_SB_ENABLED |
  11773. I40E_FLAG_FD_ATR_ENABLED |
  11774. I40E_FLAG_DCB_CAPABLE |
  11775. I40E_FLAG_DCB_ENABLED |
  11776. I40E_FLAG_SRIOV_ENABLED |
  11777. I40E_FLAG_VMDQ_ENABLED);
  11778. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  11779. } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
  11780. I40E_FLAG_FD_SB_ENABLED |
  11781. I40E_FLAG_FD_ATR_ENABLED |
  11782. I40E_FLAG_DCB_CAPABLE))) {
  11783. /* one qp for PF */
  11784. pf->alloc_rss_size = pf->num_lan_qps = 1;
  11785. queues_left -= pf->num_lan_qps;
  11786. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  11787. I40E_FLAG_IWARP_ENABLED |
  11788. I40E_FLAG_FD_SB_ENABLED |
  11789. I40E_FLAG_FD_ATR_ENABLED |
  11790. I40E_FLAG_DCB_ENABLED |
  11791. I40E_FLAG_VMDQ_ENABLED);
  11792. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  11793. } else {
  11794. /* Not enough queues for all TCs */
  11795. if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
  11796. (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
  11797. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
  11798. I40E_FLAG_DCB_ENABLED);
  11799. dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
  11800. }
  11801. /* limit lan qps to the smaller of qps, cpus or msix */
  11802. q_max = max_t(int, pf->rss_size_max, num_online_cpus());
  11803. q_max = min_t(int, q_max, pf->hw.func_caps.num_tx_qp);
  11804. q_max = min_t(int, q_max, pf->hw.func_caps.num_msix_vectors);
  11805. pf->num_lan_qps = q_max;
  11806. queues_left -= pf->num_lan_qps;
  11807. }
  11808. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  11809. if (queues_left > 1) {
  11810. queues_left -= 1; /* save 1 queue for FD */
  11811. } else {
  11812. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  11813. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  11814. dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
  11815. }
  11816. }
  11817. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  11818. pf->num_vf_qps && pf->num_req_vfs && queues_left) {
  11819. pf->num_req_vfs = min_t(int, pf->num_req_vfs,
  11820. (queues_left / pf->num_vf_qps));
  11821. queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
  11822. }
  11823. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  11824. pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
  11825. pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
  11826. (queues_left / pf->num_vmdq_qps));
  11827. queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
  11828. }
  11829. pf->queues_left = queues_left;
  11830. dev_dbg(&pf->pdev->dev,
  11831. "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
  11832. pf->hw.func_caps.num_tx_qp,
  11833. !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
  11834. pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
  11835. pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
  11836. queues_left);
  11837. }
  11838. /**
  11839. * i40e_setup_pf_filter_control - Setup PF static filter control
  11840. * @pf: PF to be setup
  11841. *
  11842. * i40e_setup_pf_filter_control sets up a PF's initial filter control
  11843. * settings. If PE/FCoE are enabled then it will also set the per PF
  11844. * based filter sizes required for them. It also enables Flow director,
  11845. * ethertype and macvlan type filter settings for the pf.
  11846. *
  11847. * Returns 0 on success, negative on failure
  11848. **/
  11849. static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
  11850. {
  11851. struct i40e_filter_control_settings *settings = &pf->filter_settings;
  11852. settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
  11853. /* Flow Director is enabled */
  11854. if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
  11855. settings->enable_fdir = true;
  11856. /* Ethtype and MACVLAN filters enabled for PF */
  11857. settings->enable_ethtype = true;
  11858. settings->enable_macvlan = true;
  11859. if (i40e_set_filter_control(&pf->hw, settings))
  11860. return -ENOENT;
  11861. return 0;
  11862. }
  11863. #define INFO_STRING_LEN 255
  11864. #define REMAIN(__x) (INFO_STRING_LEN - (__x))
  11865. static void i40e_print_features(struct i40e_pf *pf)
  11866. {
  11867. struct i40e_hw *hw = &pf->hw;
  11868. char *buf;
  11869. int i;
  11870. buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
  11871. if (!buf)
  11872. return;
  11873. i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
  11874. #ifdef CONFIG_PCI_IOV
  11875. i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
  11876. #endif
  11877. i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d",
  11878. pf->hw.func_caps.num_vsis,
  11879. pf->vsi[pf->lan_vsi]->num_queue_pairs);
  11880. if (pf->flags & I40E_FLAG_RSS_ENABLED)
  11881. i += snprintf(&buf[i], REMAIN(i), " RSS");
  11882. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
  11883. i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
  11884. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  11885. i += snprintf(&buf[i], REMAIN(i), " FD_SB");
  11886. i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
  11887. }
  11888. if (pf->flags & I40E_FLAG_DCB_CAPABLE)
  11889. i += snprintf(&buf[i], REMAIN(i), " DCB");
  11890. i += snprintf(&buf[i], REMAIN(i), " VxLAN");
  11891. i += snprintf(&buf[i], REMAIN(i), " Geneve");
  11892. if (pf->flags & I40E_FLAG_PTP)
  11893. i += snprintf(&buf[i], REMAIN(i), " PTP");
  11894. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  11895. i += snprintf(&buf[i], REMAIN(i), " VEB");
  11896. else
  11897. i += snprintf(&buf[i], REMAIN(i), " VEPA");
  11898. dev_info(&pf->pdev->dev, "%s\n", buf);
  11899. kfree(buf);
  11900. WARN_ON(i > INFO_STRING_LEN);
  11901. }
  11902. /**
  11903. * i40e_get_platform_mac_addr - get platform-specific MAC address
  11904. * @pdev: PCI device information struct
  11905. * @pf: board private structure
  11906. *
  11907. * Look up the MAC address for the device. First we'll try
  11908. * eth_platform_get_mac_address, which will check Open Firmware, or arch
  11909. * specific fallback. Otherwise, we'll default to the stored value in
  11910. * firmware.
  11911. **/
  11912. static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
  11913. {
  11914. if (eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
  11915. i40e_get_mac_addr(&pf->hw, pf->hw.mac.addr);
  11916. }
  11917. /**
  11918. * i40e_probe - Device initialization routine
  11919. * @pdev: PCI device information struct
  11920. * @ent: entry in i40e_pci_tbl
  11921. *
  11922. * i40e_probe initializes a PF identified by a pci_dev structure.
  11923. * The OS initialization, configuring of the PF private structure,
  11924. * and a hardware reset occur.
  11925. *
  11926. * Returns 0 on success, negative on failure
  11927. **/
  11928. static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  11929. {
  11930. struct i40e_aq_get_phy_abilities_resp abilities;
  11931. struct i40e_pf *pf;
  11932. struct i40e_hw *hw;
  11933. static u16 pfs_found;
  11934. u16 wol_nvm_bits;
  11935. u16 link_status;
  11936. int err;
  11937. u32 val;
  11938. u32 i;
  11939. err = pci_enable_device_mem(pdev);
  11940. if (err)
  11941. return err;
  11942. /* set up for high or low dma */
  11943. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  11944. if (err) {
  11945. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  11946. if (err) {
  11947. dev_err(&pdev->dev,
  11948. "DMA configuration failed: 0x%x\n", err);
  11949. goto err_dma;
  11950. }
  11951. }
  11952. /* set up pci connections */
  11953. err = pci_request_mem_regions(pdev, i40e_driver_name);
  11954. if (err) {
  11955. dev_info(&pdev->dev,
  11956. "pci_request_selected_regions failed %d\n", err);
  11957. goto err_pci_reg;
  11958. }
  11959. pci_enable_pcie_error_reporting(pdev);
  11960. pci_set_master(pdev);
  11961. /* Now that we have a PCI connection, we need to do the
  11962. * low level device setup. This is primarily setting up
  11963. * the Admin Queue structures and then querying for the
  11964. * device's current profile information.
  11965. */
  11966. pf = kzalloc(sizeof(*pf), GFP_KERNEL);
  11967. if (!pf) {
  11968. err = -ENOMEM;
  11969. goto err_pf_alloc;
  11970. }
  11971. pf->next_vsi = 0;
  11972. pf->pdev = pdev;
  11973. set_bit(__I40E_DOWN, pf->state);
  11974. hw = &pf->hw;
  11975. hw->back = pf;
  11976. pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
  11977. I40E_MAX_CSR_SPACE);
  11978. hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
  11979. if (!hw->hw_addr) {
  11980. err = -EIO;
  11981. dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
  11982. (unsigned int)pci_resource_start(pdev, 0),
  11983. pf->ioremap_len, err);
  11984. goto err_ioremap;
  11985. }
  11986. hw->vendor_id = pdev->vendor;
  11987. hw->device_id = pdev->device;
  11988. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  11989. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  11990. hw->subsystem_device_id = pdev->subsystem_device;
  11991. hw->bus.device = PCI_SLOT(pdev->devfn);
  11992. hw->bus.func = PCI_FUNC(pdev->devfn);
  11993. hw->bus.bus_id = pdev->bus->number;
  11994. pf->instance = pfs_found;
  11995. /* Select something other than the 802.1ad ethertype for the
  11996. * switch to use internally and drop on ingress.
  11997. */
  11998. hw->switch_tag = 0xffff;
  11999. hw->first_tag = ETH_P_8021AD;
  12000. hw->second_tag = ETH_P_8021Q;
  12001. INIT_LIST_HEAD(&pf->l3_flex_pit_list);
  12002. INIT_LIST_HEAD(&pf->l4_flex_pit_list);
  12003. /* set up the locks for the AQ, do this only once in probe
  12004. * and destroy them only once in remove
  12005. */
  12006. mutex_init(&hw->aq.asq_mutex);
  12007. mutex_init(&hw->aq.arq_mutex);
  12008. pf->msg_enable = netif_msg_init(debug,
  12009. NETIF_MSG_DRV |
  12010. NETIF_MSG_PROBE |
  12011. NETIF_MSG_LINK);
  12012. if (debug < -1)
  12013. pf->hw.debug_mask = debug;
  12014. /* do a special CORER for clearing PXE mode once at init */
  12015. if (hw->revision_id == 0 &&
  12016. (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
  12017. wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
  12018. i40e_flush(hw);
  12019. msleep(200);
  12020. pf->corer_count++;
  12021. i40e_clear_pxe_mode(hw);
  12022. }
  12023. /* Reset here to make sure all is clean and to define PF 'n' */
  12024. i40e_clear_hw(hw);
  12025. err = i40e_pf_reset(hw);
  12026. if (err) {
  12027. dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
  12028. goto err_pf_reset;
  12029. }
  12030. pf->pfr_count++;
  12031. hw->aq.num_arq_entries = I40E_AQ_LEN;
  12032. hw->aq.num_asq_entries = I40E_AQ_LEN;
  12033. hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  12034. hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  12035. pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
  12036. snprintf(pf->int_name, sizeof(pf->int_name) - 1,
  12037. "%s-%s:misc",
  12038. dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
  12039. err = i40e_init_shared_code(hw);
  12040. if (err) {
  12041. dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
  12042. err);
  12043. goto err_pf_reset;
  12044. }
  12045. /* set up a default setting for link flow control */
  12046. pf->hw.fc.requested_mode = I40E_FC_NONE;
  12047. err = i40e_init_adminq(hw);
  12048. if (err) {
  12049. if (err == I40E_ERR_FIRMWARE_API_VERSION)
  12050. dev_info(&pdev->dev,
  12051. "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");
  12052. else
  12053. dev_info(&pdev->dev,
  12054. "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
  12055. goto err_pf_reset;
  12056. }
  12057. i40e_get_oem_version(hw);
  12058. /* provide nvm, fw, api versions */
  12059. dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
  12060. hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
  12061. hw->aq.api_maj_ver, hw->aq.api_min_ver,
  12062. i40e_nvm_version_str(hw));
  12063. if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
  12064. hw->aq.api_min_ver > I40E_FW_MINOR_VERSION(hw))
  12065. dev_info(&pdev->dev,
  12066. "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");
  12067. else if (hw->aq.api_maj_ver == 1 && hw->aq.api_min_ver < 4)
  12068. dev_info(&pdev->dev,
  12069. "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
  12070. i40e_verify_eeprom(pf);
  12071. /* Rev 0 hardware was never productized */
  12072. if (hw->revision_id < 1)
  12073. 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");
  12074. i40e_clear_pxe_mode(hw);
  12075. err = i40e_get_capabilities(pf, i40e_aqc_opc_list_func_capabilities);
  12076. if (err)
  12077. goto err_adminq_setup;
  12078. err = i40e_sw_init(pf);
  12079. if (err) {
  12080. dev_info(&pdev->dev, "sw_init failed: %d\n", err);
  12081. goto err_sw_init;
  12082. }
  12083. err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  12084. hw->func_caps.num_rx_qp, 0, 0);
  12085. if (err) {
  12086. dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
  12087. goto err_init_lan_hmc;
  12088. }
  12089. err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  12090. if (err) {
  12091. dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
  12092. err = -ENOENT;
  12093. goto err_configure_lan_hmc;
  12094. }
  12095. /* Disable LLDP for NICs that have firmware versions lower than v4.3.
  12096. * Ignore error return codes because if it was already disabled via
  12097. * hardware settings this will fail
  12098. */
  12099. if (pf->hw_features & I40E_HW_STOP_FW_LLDP) {
  12100. dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
  12101. i40e_aq_stop_lldp(hw, true, NULL);
  12102. }
  12103. /* allow a platform config to override the HW addr */
  12104. i40e_get_platform_mac_addr(pdev, pf);
  12105. if (!is_valid_ether_addr(hw->mac.addr)) {
  12106. dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
  12107. err = -EIO;
  12108. goto err_mac_addr;
  12109. }
  12110. dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
  12111. ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
  12112. i40e_get_port_mac_addr(hw, hw->mac.port_addr);
  12113. if (is_valid_ether_addr(hw->mac.port_addr))
  12114. pf->hw_features |= I40E_HW_PORT_ID_VALID;
  12115. pci_set_drvdata(pdev, pf);
  12116. pci_save_state(pdev);
  12117. /* Enable FW to write default DCB config on link-up */
  12118. i40e_aq_set_dcb_parameters(hw, true, NULL);
  12119. #ifdef CONFIG_I40E_DCB
  12120. err = i40e_init_pf_dcb(pf);
  12121. if (err) {
  12122. dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
  12123. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED);
  12124. /* Continue without DCB enabled */
  12125. }
  12126. #endif /* CONFIG_I40E_DCB */
  12127. /* set up periodic task facility */
  12128. timer_setup(&pf->service_timer, i40e_service_timer, 0);
  12129. pf->service_timer_period = HZ;
  12130. INIT_WORK(&pf->service_task, i40e_service_task);
  12131. clear_bit(__I40E_SERVICE_SCHED, pf->state);
  12132. /* NVM bit on means WoL disabled for the port */
  12133. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  12134. if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
  12135. pf->wol_en = false;
  12136. else
  12137. pf->wol_en = true;
  12138. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  12139. /* set up the main switch operations */
  12140. i40e_determine_queue_usage(pf);
  12141. err = i40e_init_interrupt_scheme(pf);
  12142. if (err)
  12143. goto err_switch_setup;
  12144. /* The number of VSIs reported by the FW is the minimum guaranteed
  12145. * to us; HW supports far more and we share the remaining pool with
  12146. * the other PFs. We allocate space for more than the guarantee with
  12147. * the understanding that we might not get them all later.
  12148. */
  12149. if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
  12150. pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
  12151. else
  12152. pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
  12153. /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
  12154. pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
  12155. GFP_KERNEL);
  12156. if (!pf->vsi) {
  12157. err = -ENOMEM;
  12158. goto err_switch_setup;
  12159. }
  12160. #ifdef CONFIG_PCI_IOV
  12161. /* prep for VF support */
  12162. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  12163. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  12164. !test_bit(__I40E_BAD_EEPROM, pf->state)) {
  12165. if (pci_num_vf(pdev))
  12166. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  12167. }
  12168. #endif
  12169. err = i40e_setup_pf_switch(pf, false);
  12170. if (err) {
  12171. dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
  12172. goto err_vsis;
  12173. }
  12174. INIT_LIST_HEAD(&pf->vsi[pf->lan_vsi]->ch_list);
  12175. /* if FDIR VSI was set up, start it now */
  12176. for (i = 0; i < pf->num_alloc_vsi; i++) {
  12177. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  12178. i40e_vsi_open(pf->vsi[i]);
  12179. break;
  12180. }
  12181. }
  12182. /* The driver only wants link up/down and module qualification
  12183. * reports from firmware. Note the negative logic.
  12184. */
  12185. err = i40e_aq_set_phy_int_mask(&pf->hw,
  12186. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  12187. I40E_AQ_EVENT_MEDIA_NA |
  12188. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  12189. if (err)
  12190. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  12191. i40e_stat_str(&pf->hw, err),
  12192. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  12193. /* Reconfigure hardware for allowing smaller MSS in the case
  12194. * of TSO, so that we avoid the MDD being fired and causing
  12195. * a reset in the case of small MSS+TSO.
  12196. */
  12197. val = rd32(hw, I40E_REG_MSS);
  12198. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  12199. val &= ~I40E_REG_MSS_MIN_MASK;
  12200. val |= I40E_64BYTE_MSS;
  12201. wr32(hw, I40E_REG_MSS, val);
  12202. }
  12203. if (pf->hw_features & I40E_HW_RESTART_AUTONEG) {
  12204. msleep(75);
  12205. err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  12206. if (err)
  12207. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  12208. i40e_stat_str(&pf->hw, err),
  12209. i40e_aq_str(&pf->hw,
  12210. pf->hw.aq.asq_last_status));
  12211. }
  12212. /* The main driver is (mostly) up and happy. We need to set this state
  12213. * before setting up the misc vector or we get a race and the vector
  12214. * ends up disabled forever.
  12215. */
  12216. clear_bit(__I40E_DOWN, pf->state);
  12217. /* In case of MSIX we are going to setup the misc vector right here
  12218. * to handle admin queue events etc. In case of legacy and MSI
  12219. * the misc functionality and queue processing is combined in
  12220. * the same vector and that gets setup at open.
  12221. */
  12222. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  12223. err = i40e_setup_misc_vector(pf);
  12224. if (err) {
  12225. dev_info(&pdev->dev,
  12226. "setup of misc vector failed: %d\n", err);
  12227. i40e_cloud_filter_exit(pf);
  12228. i40e_fdir_teardown(pf);
  12229. goto err_vsis;
  12230. }
  12231. }
  12232. #ifdef CONFIG_PCI_IOV
  12233. /* prep for VF support */
  12234. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  12235. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  12236. !test_bit(__I40E_BAD_EEPROM, pf->state)) {
  12237. /* disable link interrupts for VFs */
  12238. val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
  12239. val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
  12240. wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
  12241. i40e_flush(hw);
  12242. if (pci_num_vf(pdev)) {
  12243. dev_info(&pdev->dev,
  12244. "Active VFs found, allocating resources.\n");
  12245. err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
  12246. if (err)
  12247. dev_info(&pdev->dev,
  12248. "Error %d allocating resources for existing VFs\n",
  12249. err);
  12250. }
  12251. }
  12252. #endif /* CONFIG_PCI_IOV */
  12253. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  12254. pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
  12255. pf->num_iwarp_msix,
  12256. I40E_IWARP_IRQ_PILE_ID);
  12257. if (pf->iwarp_base_vector < 0) {
  12258. dev_info(&pdev->dev,
  12259. "failed to get tracking for %d vectors for IWARP err=%d\n",
  12260. pf->num_iwarp_msix, pf->iwarp_base_vector);
  12261. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  12262. }
  12263. }
  12264. i40e_dbg_pf_init(pf);
  12265. /* tell the firmware that we're starting */
  12266. i40e_send_version(pf);
  12267. /* since everything's happy, start the service_task timer */
  12268. mod_timer(&pf->service_timer,
  12269. round_jiffies(jiffies + pf->service_timer_period));
  12270. /* add this PF to client device list and launch a client service task */
  12271. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  12272. err = i40e_lan_add_device(pf);
  12273. if (err)
  12274. dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
  12275. err);
  12276. }
  12277. #define PCI_SPEED_SIZE 8
  12278. #define PCI_WIDTH_SIZE 8
  12279. /* Devices on the IOSF bus do not have this information
  12280. * and will report PCI Gen 1 x 1 by default so don't bother
  12281. * checking them.
  12282. */
  12283. if (!(pf->hw_features & I40E_HW_NO_PCI_LINK_CHECK)) {
  12284. char speed[PCI_SPEED_SIZE] = "Unknown";
  12285. char width[PCI_WIDTH_SIZE] = "Unknown";
  12286. /* Get the negotiated link width and speed from PCI config
  12287. * space
  12288. */
  12289. pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
  12290. &link_status);
  12291. i40e_set_pci_config_data(hw, link_status);
  12292. switch (hw->bus.speed) {
  12293. case i40e_bus_speed_8000:
  12294. strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
  12295. case i40e_bus_speed_5000:
  12296. strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
  12297. case i40e_bus_speed_2500:
  12298. strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
  12299. default:
  12300. break;
  12301. }
  12302. switch (hw->bus.width) {
  12303. case i40e_bus_width_pcie_x8:
  12304. strncpy(width, "8", PCI_WIDTH_SIZE); break;
  12305. case i40e_bus_width_pcie_x4:
  12306. strncpy(width, "4", PCI_WIDTH_SIZE); break;
  12307. case i40e_bus_width_pcie_x2:
  12308. strncpy(width, "2", PCI_WIDTH_SIZE); break;
  12309. case i40e_bus_width_pcie_x1:
  12310. strncpy(width, "1", PCI_WIDTH_SIZE); break;
  12311. default:
  12312. break;
  12313. }
  12314. dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
  12315. speed, width);
  12316. if (hw->bus.width < i40e_bus_width_pcie_x8 ||
  12317. hw->bus.speed < i40e_bus_speed_8000) {
  12318. dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
  12319. dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
  12320. }
  12321. }
  12322. /* get the requested speeds from the fw */
  12323. err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
  12324. if (err)
  12325. dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
  12326. i40e_stat_str(&pf->hw, err),
  12327. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  12328. pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
  12329. /* get the supported phy types from the fw */
  12330. err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
  12331. if (err)
  12332. dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
  12333. i40e_stat_str(&pf->hw, err),
  12334. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  12335. /* Add a filter to drop all Flow control frames from any VSI from being
  12336. * transmitted. By doing so we stop a malicious VF from sending out
  12337. * PAUSE or PFC frames and potentially controlling traffic for other
  12338. * PF/VF VSIs.
  12339. * The FW can still send Flow control frames if enabled.
  12340. */
  12341. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  12342. pf->main_vsi_seid);
  12343. if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
  12344. (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
  12345. pf->hw_features |= I40E_HW_PHY_CONTROLS_LEDS;
  12346. if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722)
  12347. pf->hw_features |= I40E_HW_HAVE_CRT_RETIMER;
  12348. /* print a string summarizing features */
  12349. i40e_print_features(pf);
  12350. return 0;
  12351. /* Unwind what we've done if something failed in the setup */
  12352. err_vsis:
  12353. set_bit(__I40E_DOWN, pf->state);
  12354. i40e_clear_interrupt_scheme(pf);
  12355. kfree(pf->vsi);
  12356. err_switch_setup:
  12357. i40e_reset_interrupt_capability(pf);
  12358. del_timer_sync(&pf->service_timer);
  12359. err_mac_addr:
  12360. err_configure_lan_hmc:
  12361. (void)i40e_shutdown_lan_hmc(hw);
  12362. err_init_lan_hmc:
  12363. kfree(pf->qp_pile);
  12364. err_sw_init:
  12365. err_adminq_setup:
  12366. err_pf_reset:
  12367. iounmap(hw->hw_addr);
  12368. err_ioremap:
  12369. kfree(pf);
  12370. err_pf_alloc:
  12371. pci_disable_pcie_error_reporting(pdev);
  12372. pci_release_mem_regions(pdev);
  12373. err_pci_reg:
  12374. err_dma:
  12375. pci_disable_device(pdev);
  12376. return err;
  12377. }
  12378. /**
  12379. * i40e_remove - Device removal routine
  12380. * @pdev: PCI device information struct
  12381. *
  12382. * i40e_remove is called by the PCI subsystem to alert the driver
  12383. * that is should release a PCI device. This could be caused by a
  12384. * Hot-Plug event, or because the driver is going to be removed from
  12385. * memory.
  12386. **/
  12387. static void i40e_remove(struct pci_dev *pdev)
  12388. {
  12389. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12390. struct i40e_hw *hw = &pf->hw;
  12391. i40e_status ret_code;
  12392. int i;
  12393. i40e_dbg_pf_exit(pf);
  12394. i40e_ptp_stop(pf);
  12395. /* Disable RSS in hw */
  12396. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
  12397. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
  12398. while (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  12399. usleep_range(1000, 2000);
  12400. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  12401. set_bit(__I40E_VF_RESETS_DISABLED, pf->state);
  12402. i40e_free_vfs(pf);
  12403. pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
  12404. }
  12405. /* no more scheduling of any task */
  12406. set_bit(__I40E_SUSPENDED, pf->state);
  12407. set_bit(__I40E_DOWN, pf->state);
  12408. if (pf->service_timer.function)
  12409. del_timer_sync(&pf->service_timer);
  12410. if (pf->service_task.func)
  12411. cancel_work_sync(&pf->service_task);
  12412. /* Client close must be called explicitly here because the timer
  12413. * has been stopped.
  12414. */
  12415. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
  12416. i40e_fdir_teardown(pf);
  12417. /* If there is a switch structure or any orphans, remove them.
  12418. * This will leave only the PF's VSI remaining.
  12419. */
  12420. for (i = 0; i < I40E_MAX_VEB; i++) {
  12421. if (!pf->veb[i])
  12422. continue;
  12423. if (pf->veb[i]->uplink_seid == pf->mac_seid ||
  12424. pf->veb[i]->uplink_seid == 0)
  12425. i40e_switch_branch_release(pf->veb[i]);
  12426. }
  12427. /* Now we can shutdown the PF's VSI, just before we kill
  12428. * adminq and hmc.
  12429. */
  12430. if (pf->vsi[pf->lan_vsi])
  12431. i40e_vsi_release(pf->vsi[pf->lan_vsi]);
  12432. i40e_cloud_filter_exit(pf);
  12433. /* remove attached clients */
  12434. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  12435. ret_code = i40e_lan_del_device(pf);
  12436. if (ret_code)
  12437. dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
  12438. ret_code);
  12439. }
  12440. /* shutdown and destroy the HMC */
  12441. if (hw->hmc.hmc_obj) {
  12442. ret_code = i40e_shutdown_lan_hmc(hw);
  12443. if (ret_code)
  12444. dev_warn(&pdev->dev,
  12445. "Failed to destroy the HMC resources: %d\n",
  12446. ret_code);
  12447. }
  12448. /* shutdown the adminq */
  12449. i40e_shutdown_adminq(hw);
  12450. /* destroy the locks only once, here */
  12451. mutex_destroy(&hw->aq.arq_mutex);
  12452. mutex_destroy(&hw->aq.asq_mutex);
  12453. /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
  12454. rtnl_lock();
  12455. i40e_clear_interrupt_scheme(pf);
  12456. for (i = 0; i < pf->num_alloc_vsi; i++) {
  12457. if (pf->vsi[i]) {
  12458. i40e_vsi_clear_rings(pf->vsi[i]);
  12459. i40e_vsi_clear(pf->vsi[i]);
  12460. pf->vsi[i] = NULL;
  12461. }
  12462. }
  12463. rtnl_unlock();
  12464. for (i = 0; i < I40E_MAX_VEB; i++) {
  12465. kfree(pf->veb[i]);
  12466. pf->veb[i] = NULL;
  12467. }
  12468. kfree(pf->qp_pile);
  12469. kfree(pf->vsi);
  12470. iounmap(hw->hw_addr);
  12471. kfree(pf);
  12472. pci_release_mem_regions(pdev);
  12473. pci_disable_pcie_error_reporting(pdev);
  12474. pci_disable_device(pdev);
  12475. }
  12476. /**
  12477. * i40e_pci_error_detected - warning that something funky happened in PCI land
  12478. * @pdev: PCI device information struct
  12479. * @error: the type of PCI error
  12480. *
  12481. * Called to warn that something happened and the error handling steps
  12482. * are in progress. Allows the driver to quiesce things, be ready for
  12483. * remediation.
  12484. **/
  12485. static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
  12486. enum pci_channel_state error)
  12487. {
  12488. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12489. dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
  12490. if (!pf) {
  12491. dev_info(&pdev->dev,
  12492. "Cannot recover - error happened during device probe\n");
  12493. return PCI_ERS_RESULT_DISCONNECT;
  12494. }
  12495. /* shutdown all operations */
  12496. if (!test_bit(__I40E_SUSPENDED, pf->state))
  12497. i40e_prep_for_reset(pf, false);
  12498. /* Request a slot reset */
  12499. return PCI_ERS_RESULT_NEED_RESET;
  12500. }
  12501. /**
  12502. * i40e_pci_error_slot_reset - a PCI slot reset just happened
  12503. * @pdev: PCI device information struct
  12504. *
  12505. * Called to find if the driver can work with the device now that
  12506. * the pci slot has been reset. If a basic connection seems good
  12507. * (registers are readable and have sane content) then return a
  12508. * happy little PCI_ERS_RESULT_xxx.
  12509. **/
  12510. static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
  12511. {
  12512. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12513. pci_ers_result_t result;
  12514. int err;
  12515. u32 reg;
  12516. dev_dbg(&pdev->dev, "%s\n", __func__);
  12517. if (pci_enable_device_mem(pdev)) {
  12518. dev_info(&pdev->dev,
  12519. "Cannot re-enable PCI device after reset.\n");
  12520. result = PCI_ERS_RESULT_DISCONNECT;
  12521. } else {
  12522. pci_set_master(pdev);
  12523. pci_restore_state(pdev);
  12524. pci_save_state(pdev);
  12525. pci_wake_from_d3(pdev, false);
  12526. reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  12527. if (reg == 0)
  12528. result = PCI_ERS_RESULT_RECOVERED;
  12529. else
  12530. result = PCI_ERS_RESULT_DISCONNECT;
  12531. }
  12532. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  12533. if (err) {
  12534. dev_info(&pdev->dev,
  12535. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
  12536. err);
  12537. /* non-fatal, continue */
  12538. }
  12539. return result;
  12540. }
  12541. /**
  12542. * i40e_pci_error_reset_prepare - prepare device driver for pci reset
  12543. * @pdev: PCI device information struct
  12544. */
  12545. static void i40e_pci_error_reset_prepare(struct pci_dev *pdev)
  12546. {
  12547. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12548. i40e_prep_for_reset(pf, false);
  12549. }
  12550. /**
  12551. * i40e_pci_error_reset_done - pci reset done, device driver reset can begin
  12552. * @pdev: PCI device information struct
  12553. */
  12554. static void i40e_pci_error_reset_done(struct pci_dev *pdev)
  12555. {
  12556. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12557. i40e_reset_and_rebuild(pf, false, false);
  12558. }
  12559. /**
  12560. * i40e_pci_error_resume - restart operations after PCI error recovery
  12561. * @pdev: PCI device information struct
  12562. *
  12563. * Called to allow the driver to bring things back up after PCI error
  12564. * and/or reset recovery has finished.
  12565. **/
  12566. static void i40e_pci_error_resume(struct pci_dev *pdev)
  12567. {
  12568. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12569. dev_dbg(&pdev->dev, "%s\n", __func__);
  12570. if (test_bit(__I40E_SUSPENDED, pf->state))
  12571. return;
  12572. i40e_handle_reset_warning(pf, false);
  12573. }
  12574. /**
  12575. * i40e_enable_mc_magic_wake - enable multicast magic packet wake up
  12576. * using the mac_address_write admin q function
  12577. * @pf: pointer to i40e_pf struct
  12578. **/
  12579. static void i40e_enable_mc_magic_wake(struct i40e_pf *pf)
  12580. {
  12581. struct i40e_hw *hw = &pf->hw;
  12582. i40e_status ret;
  12583. u8 mac_addr[6];
  12584. u16 flags = 0;
  12585. /* Get current MAC address in case it's an LAA */
  12586. if (pf->vsi[pf->lan_vsi] && pf->vsi[pf->lan_vsi]->netdev) {
  12587. ether_addr_copy(mac_addr,
  12588. pf->vsi[pf->lan_vsi]->netdev->dev_addr);
  12589. } else {
  12590. dev_err(&pf->pdev->dev,
  12591. "Failed to retrieve MAC address; using default\n");
  12592. ether_addr_copy(mac_addr, hw->mac.addr);
  12593. }
  12594. /* The FW expects the mac address write cmd to first be called with
  12595. * one of these flags before calling it again with the multicast
  12596. * enable flags.
  12597. */
  12598. flags = I40E_AQC_WRITE_TYPE_LAA_WOL;
  12599. if (hw->func_caps.flex10_enable && hw->partition_id != 1)
  12600. flags = I40E_AQC_WRITE_TYPE_LAA_ONLY;
  12601. ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
  12602. if (ret) {
  12603. dev_err(&pf->pdev->dev,
  12604. "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up");
  12605. return;
  12606. }
  12607. flags = I40E_AQC_MC_MAG_EN
  12608. | I40E_AQC_WOL_PRESERVE_ON_PFR
  12609. | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG;
  12610. ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
  12611. if (ret)
  12612. dev_err(&pf->pdev->dev,
  12613. "Failed to enable Multicast Magic Packet wake up\n");
  12614. }
  12615. /**
  12616. * i40e_shutdown - PCI callback for shutting down
  12617. * @pdev: PCI device information struct
  12618. **/
  12619. static void i40e_shutdown(struct pci_dev *pdev)
  12620. {
  12621. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12622. struct i40e_hw *hw = &pf->hw;
  12623. set_bit(__I40E_SUSPENDED, pf->state);
  12624. set_bit(__I40E_DOWN, pf->state);
  12625. del_timer_sync(&pf->service_timer);
  12626. cancel_work_sync(&pf->service_task);
  12627. i40e_cloud_filter_exit(pf);
  12628. i40e_fdir_teardown(pf);
  12629. /* Client close must be called explicitly here because the timer
  12630. * has been stopped.
  12631. */
  12632. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
  12633. if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE))
  12634. i40e_enable_mc_magic_wake(pf);
  12635. i40e_prep_for_reset(pf, false);
  12636. wr32(hw, I40E_PFPM_APM,
  12637. (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  12638. wr32(hw, I40E_PFPM_WUFC,
  12639. (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  12640. /* Since we're going to destroy queues during the
  12641. * i40e_clear_interrupt_scheme() we should hold the RTNL lock for this
  12642. * whole section
  12643. */
  12644. rtnl_lock();
  12645. i40e_clear_interrupt_scheme(pf);
  12646. rtnl_unlock();
  12647. if (system_state == SYSTEM_POWER_OFF) {
  12648. pci_wake_from_d3(pdev, pf->wol_en);
  12649. pci_set_power_state(pdev, PCI_D3hot);
  12650. }
  12651. }
  12652. /**
  12653. * i40e_suspend - PM callback for moving to D3
  12654. * @dev: generic device information structure
  12655. **/
  12656. static int __maybe_unused i40e_suspend(struct device *dev)
  12657. {
  12658. struct pci_dev *pdev = to_pci_dev(dev);
  12659. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12660. struct i40e_hw *hw = &pf->hw;
  12661. /* If we're already suspended, then there is nothing to do */
  12662. if (test_and_set_bit(__I40E_SUSPENDED, pf->state))
  12663. return 0;
  12664. set_bit(__I40E_DOWN, pf->state);
  12665. /* Ensure service task will not be running */
  12666. del_timer_sync(&pf->service_timer);
  12667. cancel_work_sync(&pf->service_task);
  12668. /* Client close must be called explicitly here because the timer
  12669. * has been stopped.
  12670. */
  12671. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
  12672. if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE))
  12673. i40e_enable_mc_magic_wake(pf);
  12674. /* Since we're going to destroy queues during the
  12675. * i40e_clear_interrupt_scheme() we should hold the RTNL lock for this
  12676. * whole section
  12677. */
  12678. rtnl_lock();
  12679. i40e_prep_for_reset(pf, true);
  12680. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  12681. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  12682. /* Clear the interrupt scheme and release our IRQs so that the system
  12683. * can safely hibernate even when there are a large number of CPUs.
  12684. * Otherwise hibernation might fail when mapping all the vectors back
  12685. * to CPU0.
  12686. */
  12687. i40e_clear_interrupt_scheme(pf);
  12688. rtnl_unlock();
  12689. return 0;
  12690. }
  12691. /**
  12692. * i40e_resume - PM callback for waking up from D3
  12693. * @dev: generic device information structure
  12694. **/
  12695. static int __maybe_unused i40e_resume(struct device *dev)
  12696. {
  12697. struct pci_dev *pdev = to_pci_dev(dev);
  12698. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12699. int err;
  12700. /* If we're not suspended, then there is nothing to do */
  12701. if (!test_bit(__I40E_SUSPENDED, pf->state))
  12702. return 0;
  12703. /* We need to hold the RTNL lock prior to restoring interrupt schemes,
  12704. * since we're going to be restoring queues
  12705. */
  12706. rtnl_lock();
  12707. /* We cleared the interrupt scheme when we suspended, so we need to
  12708. * restore it now to resume device functionality.
  12709. */
  12710. err = i40e_restore_interrupt_scheme(pf);
  12711. if (err) {
  12712. dev_err(&pdev->dev, "Cannot restore interrupt scheme: %d\n",
  12713. err);
  12714. }
  12715. clear_bit(__I40E_DOWN, pf->state);
  12716. i40e_reset_and_rebuild(pf, false, true);
  12717. rtnl_unlock();
  12718. /* Clear suspended state last after everything is recovered */
  12719. clear_bit(__I40E_SUSPENDED, pf->state);
  12720. /* Restart the service task */
  12721. mod_timer(&pf->service_timer,
  12722. round_jiffies(jiffies + pf->service_timer_period));
  12723. return 0;
  12724. }
  12725. static const struct pci_error_handlers i40e_err_handler = {
  12726. .error_detected = i40e_pci_error_detected,
  12727. .slot_reset = i40e_pci_error_slot_reset,
  12728. .reset_prepare = i40e_pci_error_reset_prepare,
  12729. .reset_done = i40e_pci_error_reset_done,
  12730. .resume = i40e_pci_error_resume,
  12731. };
  12732. static SIMPLE_DEV_PM_OPS(i40e_pm_ops, i40e_suspend, i40e_resume);
  12733. static struct pci_driver i40e_driver = {
  12734. .name = i40e_driver_name,
  12735. .id_table = i40e_pci_tbl,
  12736. .probe = i40e_probe,
  12737. .remove = i40e_remove,
  12738. .driver = {
  12739. .pm = &i40e_pm_ops,
  12740. },
  12741. .shutdown = i40e_shutdown,
  12742. .err_handler = &i40e_err_handler,
  12743. .sriov_configure = i40e_pci_sriov_configure,
  12744. };
  12745. /**
  12746. * i40e_init_module - Driver registration routine
  12747. *
  12748. * i40e_init_module is the first routine called when the driver is
  12749. * loaded. All it does is register with the PCI subsystem.
  12750. **/
  12751. static int __init i40e_init_module(void)
  12752. {
  12753. pr_info("%s: %s - version %s\n", i40e_driver_name,
  12754. i40e_driver_string, i40e_driver_version_str);
  12755. pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
  12756. /* There is no need to throttle the number of active tasks because
  12757. * each device limits its own task using a state bit for scheduling
  12758. * the service task, and the device tasks do not interfere with each
  12759. * other, so we don't set a max task limit. We must set WQ_MEM_RECLAIM
  12760. * since we need to be able to guarantee forward progress even under
  12761. * memory pressure.
  12762. */
  12763. i40e_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, i40e_driver_name);
  12764. if (!i40e_wq) {
  12765. pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
  12766. return -ENOMEM;
  12767. }
  12768. i40e_dbg_init();
  12769. return pci_register_driver(&i40e_driver);
  12770. }
  12771. module_init(i40e_init_module);
  12772. /**
  12773. * i40e_exit_module - Driver exit cleanup routine
  12774. *
  12775. * i40e_exit_module is called just before the driver is removed
  12776. * from memory.
  12777. **/
  12778. static void __exit i40e_exit_module(void)
  12779. {
  12780. pci_unregister_driver(&i40e_driver);
  12781. destroy_workqueue(i40e_wq);
  12782. i40e_dbg_exit();
  12783. }
  12784. module_exit(i40e_exit_module);