i40e_main.c 320 KB

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