i40e_main.c 318 KB

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