i40e_main.c 275 KB

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