i40e_main.c 317 KB

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