i40e_main.c 279 KB

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