i40e_main.c 317 KB

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