i40e_main.c 318 KB

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