i40e_main.c 202 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 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 with
  16. * this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * The full GNU General Public License is included in this distribution in
  20. * the file called "COPYING".
  21. *
  22. * Contact Information:
  23. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  24. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  25. *
  26. ******************************************************************************/
  27. /* Local includes */
  28. #include "i40e.h"
  29. const char i40e_driver_name[] = "i40e";
  30. static const char i40e_driver_string[] =
  31. "Intel(R) Ethernet Connection XL710 Network Driver";
  32. #define DRV_KERN "-k"
  33. #define DRV_VERSION_MAJOR 0
  34. #define DRV_VERSION_MINOR 3
  35. #define DRV_VERSION_BUILD 11
  36. #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
  37. __stringify(DRV_VERSION_MINOR) "." \
  38. __stringify(DRV_VERSION_BUILD) DRV_KERN
  39. const char i40e_driver_version_str[] = DRV_VERSION;
  40. static const char i40e_copyright[] = "Copyright (c) 2013 Intel Corporation.";
  41. /* a bit of forward declarations */
  42. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
  43. static void i40e_handle_reset_warning(struct i40e_pf *pf);
  44. static int i40e_add_vsi(struct i40e_vsi *vsi);
  45. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
  46. static int i40e_setup_pf_switch(struct i40e_pf *pf);
  47. static int i40e_setup_misc_vector(struct i40e_pf *pf);
  48. static void i40e_determine_queue_usage(struct i40e_pf *pf);
  49. static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
  50. /* i40e_pci_tbl - PCI Device ID Table
  51. *
  52. * Last entry must be all 0s
  53. *
  54. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  55. * Class, Class Mask, private data (not used) }
  56. */
  57. static DEFINE_PCI_DEVICE_TABLE(i40e_pci_tbl) = {
  58. {PCI_VDEVICE(INTEL, I40E_SFP_XL710_DEVICE_ID), 0},
  59. {PCI_VDEVICE(INTEL, I40E_SFP_X710_DEVICE_ID), 0},
  60. {PCI_VDEVICE(INTEL, I40E_QEMU_DEVICE_ID), 0},
  61. {PCI_VDEVICE(INTEL, I40E_KX_A_DEVICE_ID), 0},
  62. {PCI_VDEVICE(INTEL, I40E_KX_B_DEVICE_ID), 0},
  63. {PCI_VDEVICE(INTEL, I40E_KX_C_DEVICE_ID), 0},
  64. {PCI_VDEVICE(INTEL, I40E_KX_D_DEVICE_ID), 0},
  65. {PCI_VDEVICE(INTEL, I40E_QSFP_A_DEVICE_ID), 0},
  66. {PCI_VDEVICE(INTEL, I40E_QSFP_B_DEVICE_ID), 0},
  67. {PCI_VDEVICE(INTEL, I40E_QSFP_C_DEVICE_ID), 0},
  68. /* required last entry */
  69. {0, }
  70. };
  71. MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
  72. #define I40E_MAX_VF_COUNT 128
  73. static int debug = -1;
  74. module_param(debug, int, 0);
  75. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  76. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  77. MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
  78. MODULE_LICENSE("GPL");
  79. MODULE_VERSION(DRV_VERSION);
  80. /**
  81. * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
  82. * @hw: pointer to the HW structure
  83. * @mem: ptr to mem struct to fill out
  84. * @size: size of memory requested
  85. * @alignment: what to align the allocation to
  86. **/
  87. int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
  88. u64 size, u32 alignment)
  89. {
  90. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  91. mem->size = ALIGN(size, alignment);
  92. mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
  93. &mem->pa, GFP_KERNEL);
  94. if (!mem->va)
  95. return -ENOMEM;
  96. return 0;
  97. }
  98. /**
  99. * i40e_free_dma_mem_d - OS specific memory free for shared code
  100. * @hw: pointer to the HW structure
  101. * @mem: ptr to mem struct to free
  102. **/
  103. int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
  104. {
  105. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  106. dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
  107. mem->va = NULL;
  108. mem->pa = 0;
  109. mem->size = 0;
  110. return 0;
  111. }
  112. /**
  113. * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
  114. * @hw: pointer to the HW structure
  115. * @mem: ptr to mem struct to fill out
  116. * @size: size of memory requested
  117. **/
  118. int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
  119. u32 size)
  120. {
  121. mem->size = size;
  122. mem->va = kzalloc(size, GFP_KERNEL);
  123. if (!mem->va)
  124. return -ENOMEM;
  125. return 0;
  126. }
  127. /**
  128. * i40e_free_virt_mem_d - OS specific memory free for shared code
  129. * @hw: pointer to the HW structure
  130. * @mem: ptr to mem struct to free
  131. **/
  132. int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
  133. {
  134. /* it's ok to kfree a NULL pointer */
  135. kfree(mem->va);
  136. mem->va = NULL;
  137. mem->size = 0;
  138. return 0;
  139. }
  140. /**
  141. * i40e_get_lump - find a lump of free generic resource
  142. * @pf: board private structure
  143. * @pile: the pile of resource to search
  144. * @needed: the number of items needed
  145. * @id: an owner id to stick on the items assigned
  146. *
  147. * Returns the base item index of the lump, or negative for error
  148. *
  149. * The search_hint trick and lack of advanced fit-finding only work
  150. * because we're highly likely to have all the same size lump requests.
  151. * Linear search time and any fragmentation should be minimal.
  152. **/
  153. static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
  154. u16 needed, u16 id)
  155. {
  156. int ret = -ENOMEM;
  157. int i, j;
  158. if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
  159. dev_info(&pf->pdev->dev,
  160. "param err: pile=%p needed=%d id=0x%04x\n",
  161. pile, needed, id);
  162. return -EINVAL;
  163. }
  164. /* start the linear search with an imperfect hint */
  165. i = pile->search_hint;
  166. while (i < pile->num_entries) {
  167. /* skip already allocated entries */
  168. if (pile->list[i] & I40E_PILE_VALID_BIT) {
  169. i++;
  170. continue;
  171. }
  172. /* do we have enough in this lump? */
  173. for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
  174. if (pile->list[i+j] & I40E_PILE_VALID_BIT)
  175. break;
  176. }
  177. if (j == needed) {
  178. /* there was enough, so assign it to the requestor */
  179. for (j = 0; j < needed; j++)
  180. pile->list[i+j] = id | I40E_PILE_VALID_BIT;
  181. ret = i;
  182. pile->search_hint = i + j;
  183. break;
  184. } else {
  185. /* not enough, so skip over it and continue looking */
  186. i += j;
  187. }
  188. }
  189. return ret;
  190. }
  191. /**
  192. * i40e_put_lump - return a lump of generic resource
  193. * @pile: the pile of resource to search
  194. * @index: the base item index
  195. * @id: the owner id of the items assigned
  196. *
  197. * Returns the count of items in the lump
  198. **/
  199. static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
  200. {
  201. int valid_id = (id | I40E_PILE_VALID_BIT);
  202. int count = 0;
  203. int i;
  204. if (!pile || index >= pile->num_entries)
  205. return -EINVAL;
  206. for (i = index;
  207. i < pile->num_entries && pile->list[i] == valid_id;
  208. i++) {
  209. pile->list[i] = 0;
  210. count++;
  211. }
  212. if (count && index < pile->search_hint)
  213. pile->search_hint = index;
  214. return count;
  215. }
  216. /**
  217. * i40e_service_event_schedule - Schedule the service task to wake up
  218. * @pf: board private structure
  219. *
  220. * If not already scheduled, this puts the task into the work queue
  221. **/
  222. static void i40e_service_event_schedule(struct i40e_pf *pf)
  223. {
  224. if (!test_bit(__I40E_DOWN, &pf->state) &&
  225. !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) &&
  226. !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state))
  227. schedule_work(&pf->service_task);
  228. }
  229. /**
  230. * i40e_tx_timeout - Respond to a Tx Hang
  231. * @netdev: network interface device structure
  232. *
  233. * If any port has noticed a Tx timeout, it is likely that the whole
  234. * device is munged, not just the one netdev port, so go for the full
  235. * reset.
  236. **/
  237. static void i40e_tx_timeout(struct net_device *netdev)
  238. {
  239. struct i40e_netdev_priv *np = netdev_priv(netdev);
  240. struct i40e_vsi *vsi = np->vsi;
  241. struct i40e_pf *pf = vsi->back;
  242. pf->tx_timeout_count++;
  243. if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
  244. pf->tx_timeout_recovery_level = 0;
  245. pf->tx_timeout_last_recovery = jiffies;
  246. netdev_info(netdev, "tx_timeout recovery level %d\n",
  247. pf->tx_timeout_recovery_level);
  248. switch (pf->tx_timeout_recovery_level) {
  249. case 0:
  250. /* disable and re-enable queues for the VSI */
  251. if (in_interrupt()) {
  252. set_bit(__I40E_REINIT_REQUESTED, &pf->state);
  253. set_bit(__I40E_REINIT_REQUESTED, &vsi->state);
  254. } else {
  255. i40e_vsi_reinit_locked(vsi);
  256. }
  257. break;
  258. case 1:
  259. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  260. break;
  261. case 2:
  262. set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  263. break;
  264. case 3:
  265. set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  266. break;
  267. default:
  268. netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
  269. i40e_down(vsi);
  270. break;
  271. }
  272. i40e_service_event_schedule(pf);
  273. pf->tx_timeout_recovery_level++;
  274. }
  275. /**
  276. * i40e_release_rx_desc - Store the new tail and head values
  277. * @rx_ring: ring to bump
  278. * @val: new head index
  279. **/
  280. static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val)
  281. {
  282. rx_ring->next_to_use = val;
  283. /* Force memory writes to complete before letting h/w
  284. * know there are new descriptors to fetch. (Only
  285. * applicable for weak-ordered memory model archs,
  286. * such as IA-64).
  287. */
  288. wmb();
  289. writel(val, rx_ring->tail);
  290. }
  291. /**
  292. * i40e_get_vsi_stats_struct - Get System Network Statistics
  293. * @vsi: the VSI we care about
  294. *
  295. * Returns the address of the device statistics structure.
  296. * The statistics are actually updated from the service task.
  297. **/
  298. struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
  299. {
  300. return &vsi->net_stats;
  301. }
  302. /**
  303. * i40e_get_netdev_stats_struct - Get statistics for netdev interface
  304. * @netdev: network interface device structure
  305. *
  306. * Returns the address of the device statistics structure.
  307. * The statistics are actually updated from the service task.
  308. **/
  309. static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
  310. struct net_device *netdev,
  311. struct rtnl_link_stats64 *stats)
  312. {
  313. struct i40e_netdev_priv *np = netdev_priv(netdev);
  314. struct i40e_vsi *vsi = np->vsi;
  315. struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
  316. int i;
  317. rcu_read_lock();
  318. for (i = 0; i < vsi->num_queue_pairs; i++) {
  319. struct i40e_ring *tx_ring, *rx_ring;
  320. u64 bytes, packets;
  321. unsigned int start;
  322. tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
  323. if (!tx_ring)
  324. continue;
  325. do {
  326. start = u64_stats_fetch_begin_bh(&tx_ring->syncp);
  327. packets = tx_ring->stats.packets;
  328. bytes = tx_ring->stats.bytes;
  329. } while (u64_stats_fetch_retry_bh(&tx_ring->syncp, start));
  330. stats->tx_packets += packets;
  331. stats->tx_bytes += bytes;
  332. rx_ring = &tx_ring[1];
  333. do {
  334. start = u64_stats_fetch_begin_bh(&rx_ring->syncp);
  335. packets = rx_ring->stats.packets;
  336. bytes = rx_ring->stats.bytes;
  337. } while (u64_stats_fetch_retry_bh(&rx_ring->syncp, start));
  338. stats->rx_packets += packets;
  339. stats->rx_bytes += bytes;
  340. }
  341. rcu_read_unlock();
  342. /* following stats updated by ixgbe_watchdog_task() */
  343. stats->multicast = vsi_stats->multicast;
  344. stats->tx_errors = vsi_stats->tx_errors;
  345. stats->tx_dropped = vsi_stats->tx_dropped;
  346. stats->rx_errors = vsi_stats->rx_errors;
  347. stats->rx_crc_errors = vsi_stats->rx_crc_errors;
  348. stats->rx_length_errors = vsi_stats->rx_length_errors;
  349. return stats;
  350. }
  351. /**
  352. * i40e_vsi_reset_stats - Resets all stats of the given vsi
  353. * @vsi: the VSI to have its stats reset
  354. **/
  355. void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
  356. {
  357. struct rtnl_link_stats64 *ns;
  358. int i;
  359. if (!vsi)
  360. return;
  361. ns = i40e_get_vsi_stats_struct(vsi);
  362. memset(ns, 0, sizeof(*ns));
  363. memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
  364. memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
  365. memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
  366. if (vsi->rx_rings)
  367. for (i = 0; i < vsi->num_queue_pairs; i++) {
  368. memset(&vsi->rx_rings[i]->stats, 0 ,
  369. sizeof(vsi->rx_rings[i]->stats));
  370. memset(&vsi->rx_rings[i]->rx_stats, 0 ,
  371. sizeof(vsi->rx_rings[i]->rx_stats));
  372. memset(&vsi->tx_rings[i]->stats, 0 ,
  373. sizeof(vsi->tx_rings[i]->stats));
  374. memset(&vsi->tx_rings[i]->tx_stats, 0,
  375. sizeof(vsi->tx_rings[i]->tx_stats));
  376. }
  377. vsi->stat_offsets_loaded = false;
  378. }
  379. /**
  380. * i40e_pf_reset_stats - Reset all of the stats for the given pf
  381. * @pf: the PF to be reset
  382. **/
  383. void i40e_pf_reset_stats(struct i40e_pf *pf)
  384. {
  385. memset(&pf->stats, 0, sizeof(pf->stats));
  386. memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
  387. pf->stat_offsets_loaded = false;
  388. }
  389. /**
  390. * i40e_stat_update48 - read and update a 48 bit stat from the chip
  391. * @hw: ptr to the hardware info
  392. * @hireg: the high 32 bit reg to read
  393. * @loreg: the low 32 bit reg to read
  394. * @offset_loaded: has the initial offset been loaded yet
  395. * @offset: ptr to current offset value
  396. * @stat: ptr to the stat
  397. *
  398. * Since the device stats are not reset at PFReset, they likely will not
  399. * be zeroed when the driver starts. We'll save the first values read
  400. * and use them as offsets to be subtracted from the raw values in order
  401. * to report stats that count from zero. In the process, we also manage
  402. * the potential roll-over.
  403. **/
  404. static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
  405. bool offset_loaded, u64 *offset, u64 *stat)
  406. {
  407. u64 new_data;
  408. if (hw->device_id == I40E_QEMU_DEVICE_ID) {
  409. new_data = rd32(hw, loreg);
  410. new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
  411. } else {
  412. new_data = rd64(hw, loreg);
  413. }
  414. if (!offset_loaded)
  415. *offset = new_data;
  416. if (likely(new_data >= *offset))
  417. *stat = new_data - *offset;
  418. else
  419. *stat = (new_data + ((u64)1 << 48)) - *offset;
  420. *stat &= 0xFFFFFFFFFFFFULL;
  421. }
  422. /**
  423. * i40e_stat_update32 - read and update a 32 bit stat from the chip
  424. * @hw: ptr to the hardware info
  425. * @reg: the hw reg to read
  426. * @offset_loaded: has the initial offset been loaded yet
  427. * @offset: ptr to current offset value
  428. * @stat: ptr to the stat
  429. **/
  430. static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
  431. bool offset_loaded, u64 *offset, u64 *stat)
  432. {
  433. u32 new_data;
  434. new_data = rd32(hw, reg);
  435. if (!offset_loaded)
  436. *offset = new_data;
  437. if (likely(new_data >= *offset))
  438. *stat = (u32)(new_data - *offset);
  439. else
  440. *stat = (u32)((new_data + ((u64)1 << 32)) - *offset);
  441. }
  442. /**
  443. * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
  444. * @vsi: the VSI to be updated
  445. **/
  446. void i40e_update_eth_stats(struct i40e_vsi *vsi)
  447. {
  448. int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
  449. struct i40e_pf *pf = vsi->back;
  450. struct i40e_hw *hw = &pf->hw;
  451. struct i40e_eth_stats *oes;
  452. struct i40e_eth_stats *es; /* device's eth stats */
  453. es = &vsi->eth_stats;
  454. oes = &vsi->eth_stats_offsets;
  455. /* Gather up the stats that the hw collects */
  456. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  457. vsi->stat_offsets_loaded,
  458. &oes->tx_errors, &es->tx_errors);
  459. i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
  460. vsi->stat_offsets_loaded,
  461. &oes->rx_discards, &es->rx_discards);
  462. i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
  463. I40E_GLV_GORCL(stat_idx),
  464. vsi->stat_offsets_loaded,
  465. &oes->rx_bytes, &es->rx_bytes);
  466. i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
  467. I40E_GLV_UPRCL(stat_idx),
  468. vsi->stat_offsets_loaded,
  469. &oes->rx_unicast, &es->rx_unicast);
  470. i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
  471. I40E_GLV_MPRCL(stat_idx),
  472. vsi->stat_offsets_loaded,
  473. &oes->rx_multicast, &es->rx_multicast);
  474. i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
  475. I40E_GLV_BPRCL(stat_idx),
  476. vsi->stat_offsets_loaded,
  477. &oes->rx_broadcast, &es->rx_broadcast);
  478. i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
  479. I40E_GLV_GOTCL(stat_idx),
  480. vsi->stat_offsets_loaded,
  481. &oes->tx_bytes, &es->tx_bytes);
  482. i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
  483. I40E_GLV_UPTCL(stat_idx),
  484. vsi->stat_offsets_loaded,
  485. &oes->tx_unicast, &es->tx_unicast);
  486. i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
  487. I40E_GLV_MPTCL(stat_idx),
  488. vsi->stat_offsets_loaded,
  489. &oes->tx_multicast, &es->tx_multicast);
  490. i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
  491. I40E_GLV_BPTCL(stat_idx),
  492. vsi->stat_offsets_loaded,
  493. &oes->tx_broadcast, &es->tx_broadcast);
  494. vsi->stat_offsets_loaded = true;
  495. }
  496. /**
  497. * i40e_update_veb_stats - Update Switch component statistics
  498. * @veb: the VEB being updated
  499. **/
  500. static void i40e_update_veb_stats(struct i40e_veb *veb)
  501. {
  502. struct i40e_pf *pf = veb->pf;
  503. struct i40e_hw *hw = &pf->hw;
  504. struct i40e_eth_stats *oes;
  505. struct i40e_eth_stats *es; /* device's eth stats */
  506. int idx = 0;
  507. idx = veb->stats_idx;
  508. es = &veb->stats;
  509. oes = &veb->stats_offsets;
  510. /* Gather up the stats that the hw collects */
  511. i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
  512. veb->stat_offsets_loaded,
  513. &oes->tx_discards, &es->tx_discards);
  514. i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
  515. veb->stat_offsets_loaded,
  516. &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
  517. i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
  518. veb->stat_offsets_loaded,
  519. &oes->rx_bytes, &es->rx_bytes);
  520. i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
  521. veb->stat_offsets_loaded,
  522. &oes->rx_unicast, &es->rx_unicast);
  523. i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
  524. veb->stat_offsets_loaded,
  525. &oes->rx_multicast, &es->rx_multicast);
  526. i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
  527. veb->stat_offsets_loaded,
  528. &oes->rx_broadcast, &es->rx_broadcast);
  529. i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
  530. veb->stat_offsets_loaded,
  531. &oes->tx_bytes, &es->tx_bytes);
  532. i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
  533. veb->stat_offsets_loaded,
  534. &oes->tx_unicast, &es->tx_unicast);
  535. i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
  536. veb->stat_offsets_loaded,
  537. &oes->tx_multicast, &es->tx_multicast);
  538. i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
  539. veb->stat_offsets_loaded,
  540. &oes->tx_broadcast, &es->tx_broadcast);
  541. veb->stat_offsets_loaded = true;
  542. }
  543. /**
  544. * i40e_update_link_xoff_rx - Update XOFF received in link flow control mode
  545. * @pf: the corresponding PF
  546. *
  547. * Update the Rx XOFF counter (PAUSE frames) in link flow control mode
  548. **/
  549. static void i40e_update_link_xoff_rx(struct i40e_pf *pf)
  550. {
  551. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  552. struct i40e_hw_port_stats *nsd = &pf->stats;
  553. struct i40e_hw *hw = &pf->hw;
  554. u64 xoff = 0;
  555. u16 i, v;
  556. if ((hw->fc.current_mode != I40E_FC_FULL) &&
  557. (hw->fc.current_mode != I40E_FC_RX_PAUSE))
  558. return;
  559. xoff = nsd->link_xoff_rx;
  560. i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
  561. pf->stat_offsets_loaded,
  562. &osd->link_xoff_rx, &nsd->link_xoff_rx);
  563. /* No new LFC xoff rx */
  564. if (!(nsd->link_xoff_rx - xoff))
  565. return;
  566. /* Clear the __I40E_HANG_CHECK_ARMED bit for all Tx rings */
  567. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  568. struct i40e_vsi *vsi = pf->vsi[v];
  569. if (!vsi)
  570. continue;
  571. for (i = 0; i < vsi->num_queue_pairs; i++) {
  572. struct i40e_ring *ring = vsi->tx_rings[i];
  573. clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state);
  574. }
  575. }
  576. }
  577. /**
  578. * i40e_update_prio_xoff_rx - Update XOFF received in PFC mode
  579. * @pf: the corresponding PF
  580. *
  581. * Update the Rx XOFF counter (PAUSE frames) in PFC mode
  582. **/
  583. static void i40e_update_prio_xoff_rx(struct i40e_pf *pf)
  584. {
  585. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  586. struct i40e_hw_port_stats *nsd = &pf->stats;
  587. bool xoff[I40E_MAX_TRAFFIC_CLASS] = {false};
  588. struct i40e_dcbx_config *dcb_cfg;
  589. struct i40e_hw *hw = &pf->hw;
  590. u16 i, v;
  591. u8 tc;
  592. dcb_cfg = &hw->local_dcbx_config;
  593. /* See if DCB enabled with PFC TC */
  594. if (!(pf->flags & I40E_FLAG_DCB_ENABLED) ||
  595. !(dcb_cfg->pfc.pfcenable)) {
  596. i40e_update_link_xoff_rx(pf);
  597. return;
  598. }
  599. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  600. u64 prio_xoff = nsd->priority_xoff_rx[i];
  601. i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
  602. pf->stat_offsets_loaded,
  603. &osd->priority_xoff_rx[i],
  604. &nsd->priority_xoff_rx[i]);
  605. /* No new PFC xoff rx */
  606. if (!(nsd->priority_xoff_rx[i] - prio_xoff))
  607. continue;
  608. /* Get the TC for given priority */
  609. tc = dcb_cfg->etscfg.prioritytable[i];
  610. xoff[tc] = true;
  611. }
  612. /* Clear the __I40E_HANG_CHECK_ARMED bit for Tx rings */
  613. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  614. struct i40e_vsi *vsi = pf->vsi[v];
  615. if (!vsi)
  616. continue;
  617. for (i = 0; i < vsi->num_queue_pairs; i++) {
  618. struct i40e_ring *ring = vsi->tx_rings[i];
  619. tc = ring->dcb_tc;
  620. if (xoff[tc])
  621. clear_bit(__I40E_HANG_CHECK_ARMED,
  622. &ring->state);
  623. }
  624. }
  625. }
  626. /**
  627. * i40e_update_stats - Update the board statistics counters.
  628. * @vsi: the VSI to be updated
  629. *
  630. * There are a few instances where we store the same stat in a
  631. * couple of different structs. This is partly because we have
  632. * the netdev stats that need to be filled out, which is slightly
  633. * different from the "eth_stats" defined by the chip and used in
  634. * VF communications. We sort it all out here in a central place.
  635. **/
  636. void i40e_update_stats(struct i40e_vsi *vsi)
  637. {
  638. struct i40e_pf *pf = vsi->back;
  639. struct i40e_hw *hw = &pf->hw;
  640. struct rtnl_link_stats64 *ons;
  641. struct rtnl_link_stats64 *ns; /* netdev stats */
  642. struct i40e_eth_stats *oes;
  643. struct i40e_eth_stats *es; /* device's eth stats */
  644. u32 tx_restart, tx_busy;
  645. u32 rx_page, rx_buf;
  646. u64 rx_p, rx_b;
  647. u64 tx_p, tx_b;
  648. int i;
  649. u16 q;
  650. if (test_bit(__I40E_DOWN, &vsi->state) ||
  651. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  652. return;
  653. ns = i40e_get_vsi_stats_struct(vsi);
  654. ons = &vsi->net_stats_offsets;
  655. es = &vsi->eth_stats;
  656. oes = &vsi->eth_stats_offsets;
  657. /* Gather up the netdev and vsi stats that the driver collects
  658. * on the fly during packet processing
  659. */
  660. rx_b = rx_p = 0;
  661. tx_b = tx_p = 0;
  662. tx_restart = tx_busy = 0;
  663. rx_page = 0;
  664. rx_buf = 0;
  665. rcu_read_lock();
  666. for (q = 0; q < vsi->num_queue_pairs; q++) {
  667. struct i40e_ring *p;
  668. u64 bytes, packets;
  669. unsigned int start;
  670. /* locate Tx ring */
  671. p = ACCESS_ONCE(vsi->tx_rings[q]);
  672. do {
  673. start = u64_stats_fetch_begin_bh(&p->syncp);
  674. packets = p->stats.packets;
  675. bytes = p->stats.bytes;
  676. } while (u64_stats_fetch_retry_bh(&p->syncp, start));
  677. tx_b += bytes;
  678. tx_p += packets;
  679. tx_restart += p->tx_stats.restart_queue;
  680. tx_busy += p->tx_stats.tx_busy;
  681. /* Rx queue is part of the same block as Tx queue */
  682. p = &p[1];
  683. do {
  684. start = u64_stats_fetch_begin_bh(&p->syncp);
  685. packets = p->stats.packets;
  686. bytes = p->stats.bytes;
  687. } while (u64_stats_fetch_retry_bh(&p->syncp, start));
  688. rx_b += bytes;
  689. rx_p += packets;
  690. rx_buf += p->rx_stats.alloc_rx_buff_failed;
  691. rx_page += p->rx_stats.alloc_rx_page_failed;
  692. }
  693. rcu_read_unlock();
  694. vsi->tx_restart = tx_restart;
  695. vsi->tx_busy = tx_busy;
  696. vsi->rx_page_failed = rx_page;
  697. vsi->rx_buf_failed = rx_buf;
  698. ns->rx_packets = rx_p;
  699. ns->rx_bytes = rx_b;
  700. ns->tx_packets = tx_p;
  701. ns->tx_bytes = tx_b;
  702. i40e_update_eth_stats(vsi);
  703. /* update netdev stats from eth stats */
  704. ons->rx_errors = oes->rx_errors;
  705. ns->rx_errors = es->rx_errors;
  706. ons->tx_errors = oes->tx_errors;
  707. ns->tx_errors = es->tx_errors;
  708. ons->multicast = oes->rx_multicast;
  709. ns->multicast = es->rx_multicast;
  710. ons->tx_dropped = oes->tx_discards;
  711. ns->tx_dropped = es->tx_discards;
  712. /* Get the port data only if this is the main PF VSI */
  713. if (vsi == pf->vsi[pf->lan_vsi]) {
  714. struct i40e_hw_port_stats *nsd = &pf->stats;
  715. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  716. i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
  717. I40E_GLPRT_GORCL(hw->port),
  718. pf->stat_offsets_loaded,
  719. &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
  720. i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
  721. I40E_GLPRT_GOTCL(hw->port),
  722. pf->stat_offsets_loaded,
  723. &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
  724. i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
  725. pf->stat_offsets_loaded,
  726. &osd->eth.rx_discards,
  727. &nsd->eth.rx_discards);
  728. i40e_stat_update32(hw, I40E_GLPRT_TDPC(hw->port),
  729. pf->stat_offsets_loaded,
  730. &osd->eth.tx_discards,
  731. &nsd->eth.tx_discards);
  732. i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
  733. I40E_GLPRT_MPRCL(hw->port),
  734. pf->stat_offsets_loaded,
  735. &osd->eth.rx_multicast,
  736. &nsd->eth.rx_multicast);
  737. i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
  738. pf->stat_offsets_loaded,
  739. &osd->tx_dropped_link_down,
  740. &nsd->tx_dropped_link_down);
  741. i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
  742. pf->stat_offsets_loaded,
  743. &osd->crc_errors, &nsd->crc_errors);
  744. ns->rx_crc_errors = nsd->crc_errors;
  745. i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
  746. pf->stat_offsets_loaded,
  747. &osd->illegal_bytes, &nsd->illegal_bytes);
  748. ns->rx_errors = nsd->crc_errors
  749. + nsd->illegal_bytes;
  750. i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
  751. pf->stat_offsets_loaded,
  752. &osd->mac_local_faults,
  753. &nsd->mac_local_faults);
  754. i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
  755. pf->stat_offsets_loaded,
  756. &osd->mac_remote_faults,
  757. &nsd->mac_remote_faults);
  758. i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
  759. pf->stat_offsets_loaded,
  760. &osd->rx_length_errors,
  761. &nsd->rx_length_errors);
  762. ns->rx_length_errors = nsd->rx_length_errors;
  763. i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
  764. pf->stat_offsets_loaded,
  765. &osd->link_xon_rx, &nsd->link_xon_rx);
  766. i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
  767. pf->stat_offsets_loaded,
  768. &osd->link_xon_tx, &nsd->link_xon_tx);
  769. i40e_update_prio_xoff_rx(pf); /* handles I40E_GLPRT_LXOFFRXC */
  770. i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
  771. pf->stat_offsets_loaded,
  772. &osd->link_xoff_tx, &nsd->link_xoff_tx);
  773. for (i = 0; i < 8; i++) {
  774. i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
  775. pf->stat_offsets_loaded,
  776. &osd->priority_xon_rx[i],
  777. &nsd->priority_xon_rx[i]);
  778. i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
  779. pf->stat_offsets_loaded,
  780. &osd->priority_xon_tx[i],
  781. &nsd->priority_xon_tx[i]);
  782. i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
  783. pf->stat_offsets_loaded,
  784. &osd->priority_xoff_tx[i],
  785. &nsd->priority_xoff_tx[i]);
  786. i40e_stat_update32(hw,
  787. I40E_GLPRT_RXON2OFFCNT(hw->port, i),
  788. pf->stat_offsets_loaded,
  789. &osd->priority_xon_2_xoff[i],
  790. &nsd->priority_xon_2_xoff[i]);
  791. }
  792. i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
  793. I40E_GLPRT_PRC64L(hw->port),
  794. pf->stat_offsets_loaded,
  795. &osd->rx_size_64, &nsd->rx_size_64);
  796. i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
  797. I40E_GLPRT_PRC127L(hw->port),
  798. pf->stat_offsets_loaded,
  799. &osd->rx_size_127, &nsd->rx_size_127);
  800. i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
  801. I40E_GLPRT_PRC255L(hw->port),
  802. pf->stat_offsets_loaded,
  803. &osd->rx_size_255, &nsd->rx_size_255);
  804. i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
  805. I40E_GLPRT_PRC511L(hw->port),
  806. pf->stat_offsets_loaded,
  807. &osd->rx_size_511, &nsd->rx_size_511);
  808. i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
  809. I40E_GLPRT_PRC1023L(hw->port),
  810. pf->stat_offsets_loaded,
  811. &osd->rx_size_1023, &nsd->rx_size_1023);
  812. i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
  813. I40E_GLPRT_PRC1522L(hw->port),
  814. pf->stat_offsets_loaded,
  815. &osd->rx_size_1522, &nsd->rx_size_1522);
  816. i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
  817. I40E_GLPRT_PRC9522L(hw->port),
  818. pf->stat_offsets_loaded,
  819. &osd->rx_size_big, &nsd->rx_size_big);
  820. i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
  821. I40E_GLPRT_PTC64L(hw->port),
  822. pf->stat_offsets_loaded,
  823. &osd->tx_size_64, &nsd->tx_size_64);
  824. i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
  825. I40E_GLPRT_PTC127L(hw->port),
  826. pf->stat_offsets_loaded,
  827. &osd->tx_size_127, &nsd->tx_size_127);
  828. i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
  829. I40E_GLPRT_PTC255L(hw->port),
  830. pf->stat_offsets_loaded,
  831. &osd->tx_size_255, &nsd->tx_size_255);
  832. i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
  833. I40E_GLPRT_PTC511L(hw->port),
  834. pf->stat_offsets_loaded,
  835. &osd->tx_size_511, &nsd->tx_size_511);
  836. i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
  837. I40E_GLPRT_PTC1023L(hw->port),
  838. pf->stat_offsets_loaded,
  839. &osd->tx_size_1023, &nsd->tx_size_1023);
  840. i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
  841. I40E_GLPRT_PTC1522L(hw->port),
  842. pf->stat_offsets_loaded,
  843. &osd->tx_size_1522, &nsd->tx_size_1522);
  844. i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
  845. I40E_GLPRT_PTC9522L(hw->port),
  846. pf->stat_offsets_loaded,
  847. &osd->tx_size_big, &nsd->tx_size_big);
  848. i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
  849. pf->stat_offsets_loaded,
  850. &osd->rx_undersize, &nsd->rx_undersize);
  851. i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
  852. pf->stat_offsets_loaded,
  853. &osd->rx_fragments, &nsd->rx_fragments);
  854. i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
  855. pf->stat_offsets_loaded,
  856. &osd->rx_oversize, &nsd->rx_oversize);
  857. i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
  858. pf->stat_offsets_loaded,
  859. &osd->rx_jabber, &nsd->rx_jabber);
  860. }
  861. pf->stat_offsets_loaded = true;
  862. }
  863. /**
  864. * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
  865. * @vsi: the VSI to be searched
  866. * @macaddr: the MAC address
  867. * @vlan: the vlan
  868. * @is_vf: make sure its a vf filter, else doesn't matter
  869. * @is_netdev: make sure its a netdev filter, else doesn't matter
  870. *
  871. * Returns ptr to the filter object or NULL
  872. **/
  873. static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
  874. u8 *macaddr, s16 vlan,
  875. bool is_vf, bool is_netdev)
  876. {
  877. struct i40e_mac_filter *f;
  878. if (!vsi || !macaddr)
  879. return NULL;
  880. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  881. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  882. (vlan == f->vlan) &&
  883. (!is_vf || f->is_vf) &&
  884. (!is_netdev || f->is_netdev))
  885. return f;
  886. }
  887. return NULL;
  888. }
  889. /**
  890. * i40e_find_mac - Find a mac addr in the macvlan filters list
  891. * @vsi: the VSI to be searched
  892. * @macaddr: the MAC address we are searching for
  893. * @is_vf: make sure its a vf filter, else doesn't matter
  894. * @is_netdev: make sure its a netdev filter, else doesn't matter
  895. *
  896. * Returns the first filter with the provided MAC address or NULL if
  897. * MAC address was not found
  898. **/
  899. struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr,
  900. bool is_vf, bool is_netdev)
  901. {
  902. struct i40e_mac_filter *f;
  903. if (!vsi || !macaddr)
  904. return NULL;
  905. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  906. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  907. (!is_vf || f->is_vf) &&
  908. (!is_netdev || f->is_netdev))
  909. return f;
  910. }
  911. return NULL;
  912. }
  913. /**
  914. * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
  915. * @vsi: the VSI to be searched
  916. *
  917. * Returns true if VSI is in vlan mode or false otherwise
  918. **/
  919. bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
  920. {
  921. struct i40e_mac_filter *f;
  922. /* Only -1 for all the filters denotes not in vlan mode
  923. * so we have to go through all the list in order to make sure
  924. */
  925. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  926. if (f->vlan >= 0)
  927. return true;
  928. }
  929. return false;
  930. }
  931. /**
  932. * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
  933. * @vsi: the VSI to be searched
  934. * @macaddr: the mac address to be filtered
  935. * @is_vf: true if it is a vf
  936. * @is_netdev: true if it is a netdev
  937. *
  938. * Goes through all the macvlan filters and adds a
  939. * macvlan filter for each unique vlan that already exists
  940. *
  941. * Returns first filter found on success, else NULL
  942. **/
  943. struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr,
  944. bool is_vf, bool is_netdev)
  945. {
  946. struct i40e_mac_filter *f;
  947. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  948. if (!i40e_find_filter(vsi, macaddr, f->vlan,
  949. is_vf, is_netdev)) {
  950. if (!i40e_add_filter(vsi, macaddr, f->vlan,
  951. is_vf, is_netdev))
  952. return NULL;
  953. }
  954. }
  955. return list_first_entry_or_null(&vsi->mac_filter_list,
  956. struct i40e_mac_filter, list);
  957. }
  958. /**
  959. * i40e_add_filter - Add a mac/vlan filter to the VSI
  960. * @vsi: the VSI to be searched
  961. * @macaddr: the MAC address
  962. * @vlan: the vlan
  963. * @is_vf: make sure its a vf filter, else doesn't matter
  964. * @is_netdev: make sure its a netdev filter, else doesn't matter
  965. *
  966. * Returns ptr to the filter object or NULL when no memory available.
  967. **/
  968. struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
  969. u8 *macaddr, s16 vlan,
  970. bool is_vf, bool is_netdev)
  971. {
  972. struct i40e_mac_filter *f;
  973. if (!vsi || !macaddr)
  974. return NULL;
  975. f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
  976. if (!f) {
  977. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  978. if (!f)
  979. goto add_filter_out;
  980. memcpy(f->macaddr, macaddr, ETH_ALEN);
  981. f->vlan = vlan;
  982. f->changed = true;
  983. INIT_LIST_HEAD(&f->list);
  984. list_add(&f->list, &vsi->mac_filter_list);
  985. }
  986. /* increment counter and add a new flag if needed */
  987. if (is_vf) {
  988. if (!f->is_vf) {
  989. f->is_vf = true;
  990. f->counter++;
  991. }
  992. } else if (is_netdev) {
  993. if (!f->is_netdev) {
  994. f->is_netdev = true;
  995. f->counter++;
  996. }
  997. } else {
  998. f->counter++;
  999. }
  1000. /* changed tells sync_filters_subtask to
  1001. * push the filter down to the firmware
  1002. */
  1003. if (f->changed) {
  1004. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1005. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1006. }
  1007. add_filter_out:
  1008. return f;
  1009. }
  1010. /**
  1011. * i40e_del_filter - Remove a mac/vlan filter from the VSI
  1012. * @vsi: the VSI to be searched
  1013. * @macaddr: the MAC address
  1014. * @vlan: the vlan
  1015. * @is_vf: make sure it's a vf filter, else doesn't matter
  1016. * @is_netdev: make sure it's a netdev filter, else doesn't matter
  1017. **/
  1018. void i40e_del_filter(struct i40e_vsi *vsi,
  1019. u8 *macaddr, s16 vlan,
  1020. bool is_vf, bool is_netdev)
  1021. {
  1022. struct i40e_mac_filter *f;
  1023. if (!vsi || !macaddr)
  1024. return;
  1025. f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
  1026. if (!f || f->counter == 0)
  1027. return;
  1028. if (is_vf) {
  1029. if (f->is_vf) {
  1030. f->is_vf = false;
  1031. f->counter--;
  1032. }
  1033. } else if (is_netdev) {
  1034. if (f->is_netdev) {
  1035. f->is_netdev = false;
  1036. f->counter--;
  1037. }
  1038. } else {
  1039. /* make sure we don't remove a filter in use by vf or netdev */
  1040. int min_f = 0;
  1041. min_f += (f->is_vf ? 1 : 0);
  1042. min_f += (f->is_netdev ? 1 : 0);
  1043. if (f->counter > min_f)
  1044. f->counter--;
  1045. }
  1046. /* counter == 0 tells sync_filters_subtask to
  1047. * remove the filter from the firmware's list
  1048. */
  1049. if (f->counter == 0) {
  1050. f->changed = true;
  1051. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1052. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1053. }
  1054. }
  1055. /**
  1056. * i40e_set_mac - NDO callback to set mac address
  1057. * @netdev: network interface device structure
  1058. * @p: pointer to an address structure
  1059. *
  1060. * Returns 0 on success, negative on failure
  1061. **/
  1062. static int i40e_set_mac(struct net_device *netdev, void *p)
  1063. {
  1064. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1065. struct i40e_vsi *vsi = np->vsi;
  1066. struct sockaddr *addr = p;
  1067. struct i40e_mac_filter *f;
  1068. if (!is_valid_ether_addr(addr->sa_data))
  1069. return -EADDRNOTAVAIL;
  1070. netdev_info(netdev, "set mac address=%pM\n", addr->sa_data);
  1071. if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
  1072. return 0;
  1073. if (vsi->type == I40E_VSI_MAIN) {
  1074. i40e_status ret;
  1075. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  1076. I40E_AQC_WRITE_TYPE_LAA_ONLY,
  1077. addr->sa_data, NULL);
  1078. if (ret) {
  1079. netdev_info(netdev,
  1080. "Addr change for Main VSI failed: %d\n",
  1081. ret);
  1082. return -EADDRNOTAVAIL;
  1083. }
  1084. memcpy(vsi->back->hw.mac.addr, addr->sa_data, netdev->addr_len);
  1085. }
  1086. /* In order to be sure to not drop any packets, add the new address
  1087. * then delete the old one.
  1088. */
  1089. f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY, false, false);
  1090. if (!f)
  1091. return -ENOMEM;
  1092. i40e_sync_vsi_filters(vsi);
  1093. i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, false, false);
  1094. i40e_sync_vsi_filters(vsi);
  1095. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  1096. return 0;
  1097. }
  1098. /**
  1099. * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
  1100. * @vsi: the VSI being setup
  1101. * @ctxt: VSI context structure
  1102. * @enabled_tc: Enabled TCs bitmap
  1103. * @is_add: True if called before Add VSI
  1104. *
  1105. * Setup VSI queue mapping for enabled traffic classes.
  1106. **/
  1107. static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1108. struct i40e_vsi_context *ctxt,
  1109. u8 enabled_tc,
  1110. bool is_add)
  1111. {
  1112. struct i40e_pf *pf = vsi->back;
  1113. u16 sections = 0;
  1114. u8 netdev_tc = 0;
  1115. u16 numtc = 0;
  1116. u16 qcount;
  1117. u8 offset;
  1118. u16 qmap;
  1119. int i;
  1120. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1121. offset = 0;
  1122. if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  1123. /* Find numtc from enabled TC bitmap */
  1124. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1125. if (enabled_tc & (1 << i)) /* TC is enabled */
  1126. numtc++;
  1127. }
  1128. if (!numtc) {
  1129. dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
  1130. numtc = 1;
  1131. }
  1132. } else {
  1133. /* At least TC0 is enabled in case of non-DCB case */
  1134. numtc = 1;
  1135. }
  1136. vsi->tc_config.numtc = numtc;
  1137. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1138. /* Setup queue offset/count for all TCs for given VSI */
  1139. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1140. /* See if the given TC is enabled for the given VSI */
  1141. if (vsi->tc_config.enabled_tc & (1 << i)) { /* TC is enabled */
  1142. int pow, num_qps;
  1143. vsi->tc_config.tc_info[i].qoffset = offset;
  1144. switch (vsi->type) {
  1145. case I40E_VSI_MAIN:
  1146. if (i == 0)
  1147. qcount = pf->rss_size;
  1148. else
  1149. qcount = pf->num_tc_qps;
  1150. vsi->tc_config.tc_info[i].qcount = qcount;
  1151. break;
  1152. case I40E_VSI_FDIR:
  1153. case I40E_VSI_SRIOV:
  1154. case I40E_VSI_VMDQ2:
  1155. default:
  1156. qcount = vsi->alloc_queue_pairs;
  1157. vsi->tc_config.tc_info[i].qcount = qcount;
  1158. WARN_ON(i != 0);
  1159. break;
  1160. }
  1161. /* find the power-of-2 of the number of queue pairs */
  1162. num_qps = vsi->tc_config.tc_info[i].qcount;
  1163. pow = 0;
  1164. while (num_qps &&
  1165. ((1 << pow) < vsi->tc_config.tc_info[i].qcount)) {
  1166. pow++;
  1167. num_qps >>= 1;
  1168. }
  1169. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1170. qmap =
  1171. (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1172. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1173. offset += vsi->tc_config.tc_info[i].qcount;
  1174. } else {
  1175. /* TC is not enabled so set the offset to
  1176. * default queue and allocate one queue
  1177. * for the given TC.
  1178. */
  1179. vsi->tc_config.tc_info[i].qoffset = 0;
  1180. vsi->tc_config.tc_info[i].qcount = 1;
  1181. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1182. qmap = 0;
  1183. }
  1184. ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
  1185. }
  1186. /* Set actual Tx/Rx queue pairs */
  1187. vsi->num_queue_pairs = offset;
  1188. /* Scheduler section valid can only be set for ADD VSI */
  1189. if (is_add) {
  1190. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1191. ctxt->info.up_enable_bits = enabled_tc;
  1192. }
  1193. if (vsi->type == I40E_VSI_SRIOV) {
  1194. ctxt->info.mapping_flags |=
  1195. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
  1196. for (i = 0; i < vsi->num_queue_pairs; i++)
  1197. ctxt->info.queue_mapping[i] =
  1198. cpu_to_le16(vsi->base_queue + i);
  1199. } else {
  1200. ctxt->info.mapping_flags |=
  1201. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1202. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1203. }
  1204. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1205. }
  1206. /**
  1207. * i40e_set_rx_mode - NDO callback to set the netdev filters
  1208. * @netdev: network interface device structure
  1209. **/
  1210. static void i40e_set_rx_mode(struct net_device *netdev)
  1211. {
  1212. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1213. struct i40e_mac_filter *f, *ftmp;
  1214. struct i40e_vsi *vsi = np->vsi;
  1215. struct netdev_hw_addr *uca;
  1216. struct netdev_hw_addr *mca;
  1217. struct netdev_hw_addr *ha;
  1218. /* add addr if not already in the filter list */
  1219. netdev_for_each_uc_addr(uca, netdev) {
  1220. if (!i40e_find_mac(vsi, uca->addr, false, true)) {
  1221. if (i40e_is_vsi_in_vlan(vsi))
  1222. i40e_put_mac_in_vlan(vsi, uca->addr,
  1223. false, true);
  1224. else
  1225. i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY,
  1226. false, true);
  1227. }
  1228. }
  1229. netdev_for_each_mc_addr(mca, netdev) {
  1230. if (!i40e_find_mac(vsi, mca->addr, false, true)) {
  1231. if (i40e_is_vsi_in_vlan(vsi))
  1232. i40e_put_mac_in_vlan(vsi, mca->addr,
  1233. false, true);
  1234. else
  1235. i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY,
  1236. false, true);
  1237. }
  1238. }
  1239. /* remove filter if not in netdev list */
  1240. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1241. bool found = false;
  1242. if (!f->is_netdev)
  1243. continue;
  1244. if (is_multicast_ether_addr(f->macaddr)) {
  1245. netdev_for_each_mc_addr(mca, netdev) {
  1246. if (ether_addr_equal(mca->addr, f->macaddr)) {
  1247. found = true;
  1248. break;
  1249. }
  1250. }
  1251. } else {
  1252. netdev_for_each_uc_addr(uca, netdev) {
  1253. if (ether_addr_equal(uca->addr, f->macaddr)) {
  1254. found = true;
  1255. break;
  1256. }
  1257. }
  1258. for_each_dev_addr(netdev, ha) {
  1259. if (ether_addr_equal(ha->addr, f->macaddr)) {
  1260. found = true;
  1261. break;
  1262. }
  1263. }
  1264. }
  1265. if (!found)
  1266. i40e_del_filter(
  1267. vsi, f->macaddr, I40E_VLAN_ANY, false, true);
  1268. }
  1269. /* check for other flag changes */
  1270. if (vsi->current_netdev_flags != vsi->netdev->flags) {
  1271. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1272. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1273. }
  1274. }
  1275. /**
  1276. * i40e_sync_vsi_filters - Update the VSI filter list to the HW
  1277. * @vsi: ptr to the VSI
  1278. *
  1279. * Push any outstanding VSI filter changes through the AdminQ.
  1280. *
  1281. * Returns 0 or error value
  1282. **/
  1283. int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
  1284. {
  1285. struct i40e_mac_filter *f, *ftmp;
  1286. bool promisc_forced_on = false;
  1287. bool add_happened = false;
  1288. int filter_list_len = 0;
  1289. u32 changed_flags = 0;
  1290. i40e_status aq_ret = 0;
  1291. struct i40e_pf *pf;
  1292. int num_add = 0;
  1293. int num_del = 0;
  1294. u16 cmd_flags;
  1295. /* empty array typed pointers, kcalloc later */
  1296. struct i40e_aqc_add_macvlan_element_data *add_list;
  1297. struct i40e_aqc_remove_macvlan_element_data *del_list;
  1298. while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
  1299. usleep_range(1000, 2000);
  1300. pf = vsi->back;
  1301. if (vsi->netdev) {
  1302. changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
  1303. vsi->current_netdev_flags = vsi->netdev->flags;
  1304. }
  1305. if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
  1306. vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
  1307. filter_list_len = pf->hw.aq.asq_buf_size /
  1308. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  1309. del_list = kcalloc(filter_list_len,
  1310. sizeof(struct i40e_aqc_remove_macvlan_element_data),
  1311. GFP_KERNEL);
  1312. if (!del_list)
  1313. return -ENOMEM;
  1314. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1315. if (!f->changed)
  1316. continue;
  1317. if (f->counter != 0)
  1318. continue;
  1319. f->changed = false;
  1320. cmd_flags = 0;
  1321. /* add to delete list */
  1322. memcpy(del_list[num_del].mac_addr,
  1323. f->macaddr, ETH_ALEN);
  1324. del_list[num_del].vlan_tag =
  1325. cpu_to_le16((u16)(f->vlan ==
  1326. I40E_VLAN_ANY ? 0 : f->vlan));
  1327. /* vlan0 as wild card to allow packets from all vlans */
  1328. if (f->vlan == I40E_VLAN_ANY ||
  1329. (vsi->netdev && !(vsi->netdev->features &
  1330. NETIF_F_HW_VLAN_CTAG_FILTER)))
  1331. cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  1332. cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1333. del_list[num_del].flags = cmd_flags;
  1334. num_del++;
  1335. /* unlink from filter list */
  1336. list_del(&f->list);
  1337. kfree(f);
  1338. /* flush a full buffer */
  1339. if (num_del == filter_list_len) {
  1340. aq_ret = i40e_aq_remove_macvlan(&pf->hw,
  1341. vsi->seid, del_list, num_del,
  1342. NULL);
  1343. num_del = 0;
  1344. memset(del_list, 0, sizeof(*del_list));
  1345. if (aq_ret)
  1346. dev_info(&pf->pdev->dev,
  1347. "ignoring delete macvlan error, err %d, aq_err %d while flushing a full buffer\n",
  1348. aq_ret,
  1349. pf->hw.aq.asq_last_status);
  1350. }
  1351. }
  1352. if (num_del) {
  1353. aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid,
  1354. del_list, num_del, NULL);
  1355. num_del = 0;
  1356. if (aq_ret)
  1357. dev_info(&pf->pdev->dev,
  1358. "ignoring delete macvlan error, err %d, aq_err %d\n",
  1359. aq_ret, pf->hw.aq.asq_last_status);
  1360. }
  1361. kfree(del_list);
  1362. del_list = NULL;
  1363. /* do all the adds now */
  1364. filter_list_len = pf->hw.aq.asq_buf_size /
  1365. sizeof(struct i40e_aqc_add_macvlan_element_data),
  1366. add_list = kcalloc(filter_list_len,
  1367. sizeof(struct i40e_aqc_add_macvlan_element_data),
  1368. GFP_KERNEL);
  1369. if (!add_list)
  1370. return -ENOMEM;
  1371. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1372. if (!f->changed)
  1373. continue;
  1374. if (f->counter == 0)
  1375. continue;
  1376. f->changed = false;
  1377. add_happened = true;
  1378. cmd_flags = 0;
  1379. /* add to add array */
  1380. memcpy(add_list[num_add].mac_addr,
  1381. f->macaddr, ETH_ALEN);
  1382. add_list[num_add].vlan_tag =
  1383. cpu_to_le16(
  1384. (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan));
  1385. add_list[num_add].queue_number = 0;
  1386. cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
  1387. /* vlan0 as wild card to allow packets from all vlans */
  1388. if (f->vlan == I40E_VLAN_ANY || (vsi->netdev &&
  1389. !(vsi->netdev->features &
  1390. NETIF_F_HW_VLAN_CTAG_FILTER)))
  1391. cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
  1392. add_list[num_add].flags = cpu_to_le16(cmd_flags);
  1393. num_add++;
  1394. /* flush a full buffer */
  1395. if (num_add == filter_list_len) {
  1396. aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
  1397. add_list, num_add,
  1398. NULL);
  1399. num_add = 0;
  1400. if (aq_ret)
  1401. break;
  1402. memset(add_list, 0, sizeof(*add_list));
  1403. }
  1404. }
  1405. if (num_add) {
  1406. aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
  1407. add_list, num_add, NULL);
  1408. num_add = 0;
  1409. }
  1410. kfree(add_list);
  1411. add_list = NULL;
  1412. if (add_happened && (!aq_ret)) {
  1413. /* do nothing */;
  1414. } else if (add_happened && (aq_ret)) {
  1415. dev_info(&pf->pdev->dev,
  1416. "add filter failed, err %d, aq_err %d\n",
  1417. aq_ret, pf->hw.aq.asq_last_status);
  1418. if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) &&
  1419. !test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1420. &vsi->state)) {
  1421. promisc_forced_on = true;
  1422. set_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1423. &vsi->state);
  1424. dev_info(&pf->pdev->dev, "promiscuous mode forced on\n");
  1425. }
  1426. }
  1427. }
  1428. /* check for changes in promiscuous modes */
  1429. if (changed_flags & IFF_ALLMULTI) {
  1430. bool cur_multipromisc;
  1431. cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
  1432. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
  1433. vsi->seid,
  1434. cur_multipromisc,
  1435. NULL);
  1436. if (aq_ret)
  1437. dev_info(&pf->pdev->dev,
  1438. "set multi promisc failed, err %d, aq_err %d\n",
  1439. aq_ret, pf->hw.aq.asq_last_status);
  1440. }
  1441. if ((changed_flags & IFF_PROMISC) || promisc_forced_on) {
  1442. bool cur_promisc;
  1443. cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
  1444. test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1445. &vsi->state));
  1446. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(&vsi->back->hw,
  1447. vsi->seid,
  1448. cur_promisc, NULL);
  1449. if (aq_ret)
  1450. dev_info(&pf->pdev->dev,
  1451. "set uni promisc failed, err %d, aq_err %d\n",
  1452. aq_ret, pf->hw.aq.asq_last_status);
  1453. }
  1454. clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
  1455. return 0;
  1456. }
  1457. /**
  1458. * i40e_sync_filters_subtask - Sync the VSI filter list with HW
  1459. * @pf: board private structure
  1460. **/
  1461. static void i40e_sync_filters_subtask(struct i40e_pf *pf)
  1462. {
  1463. int v;
  1464. if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
  1465. return;
  1466. pf->flags &= ~I40E_FLAG_FILTER_SYNC;
  1467. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  1468. if (pf->vsi[v] &&
  1469. (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED))
  1470. i40e_sync_vsi_filters(pf->vsi[v]);
  1471. }
  1472. }
  1473. /**
  1474. * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  1475. * @netdev: network interface device structure
  1476. * @new_mtu: new value for maximum frame size
  1477. *
  1478. * Returns 0 on success, negative on failure
  1479. **/
  1480. static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
  1481. {
  1482. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1483. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
  1484. struct i40e_vsi *vsi = np->vsi;
  1485. /* MTU < 68 is an error and causes problems on some kernels */
  1486. if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
  1487. return -EINVAL;
  1488. netdev_info(netdev, "changing MTU from %d to %d\n",
  1489. netdev->mtu, new_mtu);
  1490. netdev->mtu = new_mtu;
  1491. if (netif_running(netdev))
  1492. i40e_vsi_reinit_locked(vsi);
  1493. return 0;
  1494. }
  1495. /**
  1496. * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
  1497. * @vsi: the vsi being adjusted
  1498. **/
  1499. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
  1500. {
  1501. struct i40e_vsi_context ctxt;
  1502. i40e_status ret;
  1503. if ((vsi->info.valid_sections &
  1504. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  1505. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
  1506. return; /* already enabled */
  1507. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  1508. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  1509. I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
  1510. ctxt.seid = vsi->seid;
  1511. memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
  1512. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  1513. if (ret) {
  1514. dev_info(&vsi->back->pdev->dev,
  1515. "%s: update vsi failed, aq_err=%d\n",
  1516. __func__, vsi->back->hw.aq.asq_last_status);
  1517. }
  1518. }
  1519. /**
  1520. * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
  1521. * @vsi: the vsi being adjusted
  1522. **/
  1523. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
  1524. {
  1525. struct i40e_vsi_context ctxt;
  1526. i40e_status ret;
  1527. if ((vsi->info.valid_sections &
  1528. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  1529. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
  1530. I40E_AQ_VSI_PVLAN_EMOD_MASK))
  1531. return; /* already disabled */
  1532. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  1533. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  1534. I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
  1535. ctxt.seid = vsi->seid;
  1536. memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
  1537. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  1538. if (ret) {
  1539. dev_info(&vsi->back->pdev->dev,
  1540. "%s: update vsi failed, aq_err=%d\n",
  1541. __func__, vsi->back->hw.aq.asq_last_status);
  1542. }
  1543. }
  1544. /**
  1545. * i40e_vlan_rx_register - Setup or shutdown vlan offload
  1546. * @netdev: network interface to be adjusted
  1547. * @features: netdev features to test if VLAN offload is enabled or not
  1548. **/
  1549. static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
  1550. {
  1551. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1552. struct i40e_vsi *vsi = np->vsi;
  1553. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  1554. i40e_vlan_stripping_enable(vsi);
  1555. else
  1556. i40e_vlan_stripping_disable(vsi);
  1557. }
  1558. /**
  1559. * i40e_vsi_add_vlan - Add vsi membership for given vlan
  1560. * @vsi: the vsi being configured
  1561. * @vid: vlan id to be added (0 = untagged only , -1 = any)
  1562. **/
  1563. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid)
  1564. {
  1565. struct i40e_mac_filter *f, *add_f;
  1566. bool is_netdev, is_vf;
  1567. int ret;
  1568. is_vf = (vsi->type == I40E_VSI_SRIOV);
  1569. is_netdev = !!(vsi->netdev);
  1570. if (is_netdev) {
  1571. add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid,
  1572. is_vf, is_netdev);
  1573. if (!add_f) {
  1574. dev_info(&vsi->back->pdev->dev,
  1575. "Could not add vlan filter %d for %pM\n",
  1576. vid, vsi->netdev->dev_addr);
  1577. return -ENOMEM;
  1578. }
  1579. }
  1580. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1581. add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
  1582. if (!add_f) {
  1583. dev_info(&vsi->back->pdev->dev,
  1584. "Could not add vlan filter %d for %pM\n",
  1585. vid, f->macaddr);
  1586. return -ENOMEM;
  1587. }
  1588. }
  1589. ret = i40e_sync_vsi_filters(vsi);
  1590. if (ret) {
  1591. dev_info(&vsi->back->pdev->dev,
  1592. "Could not sync filters for vid %d\n", vid);
  1593. return ret;
  1594. }
  1595. /* Now if we add a vlan tag, make sure to check if it is the first
  1596. * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
  1597. * with 0, so we now accept untagged and specified tagged traffic
  1598. * (and not any taged and untagged)
  1599. */
  1600. if (vid > 0) {
  1601. if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr,
  1602. I40E_VLAN_ANY,
  1603. is_vf, is_netdev)) {
  1604. i40e_del_filter(vsi, vsi->netdev->dev_addr,
  1605. I40E_VLAN_ANY, is_vf, is_netdev);
  1606. add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0,
  1607. is_vf, is_netdev);
  1608. if (!add_f) {
  1609. dev_info(&vsi->back->pdev->dev,
  1610. "Could not add filter 0 for %pM\n",
  1611. vsi->netdev->dev_addr);
  1612. return -ENOMEM;
  1613. }
  1614. }
  1615. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1616. if (i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  1617. is_vf, is_netdev)) {
  1618. i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  1619. is_vf, is_netdev);
  1620. add_f = i40e_add_filter(vsi, f->macaddr,
  1621. 0, is_vf, is_netdev);
  1622. if (!add_f) {
  1623. dev_info(&vsi->back->pdev->dev,
  1624. "Could not add filter 0 for %pM\n",
  1625. f->macaddr);
  1626. return -ENOMEM;
  1627. }
  1628. }
  1629. }
  1630. ret = i40e_sync_vsi_filters(vsi);
  1631. }
  1632. return ret;
  1633. }
  1634. /**
  1635. * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
  1636. * @vsi: the vsi being configured
  1637. * @vid: vlan id to be removed (0 = untagged only , -1 = any)
  1638. *
  1639. * Return: 0 on success or negative otherwise
  1640. **/
  1641. int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid)
  1642. {
  1643. struct net_device *netdev = vsi->netdev;
  1644. struct i40e_mac_filter *f, *add_f;
  1645. bool is_vf, is_netdev;
  1646. int filter_count = 0;
  1647. int ret;
  1648. is_vf = (vsi->type == I40E_VSI_SRIOV);
  1649. is_netdev = !!(netdev);
  1650. if (is_netdev)
  1651. i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev);
  1652. list_for_each_entry(f, &vsi->mac_filter_list, list)
  1653. i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
  1654. ret = i40e_sync_vsi_filters(vsi);
  1655. if (ret) {
  1656. dev_info(&vsi->back->pdev->dev, "Could not sync filters\n");
  1657. return ret;
  1658. }
  1659. /* go through all the filters for this VSI and if there is only
  1660. * vid == 0 it means there are no other filters, so vid 0 must
  1661. * be replaced with -1. This signifies that we should from now
  1662. * on accept any traffic (with any tag present, or untagged)
  1663. */
  1664. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1665. if (is_netdev) {
  1666. if (f->vlan &&
  1667. ether_addr_equal(netdev->dev_addr, f->macaddr))
  1668. filter_count++;
  1669. }
  1670. if (f->vlan)
  1671. filter_count++;
  1672. }
  1673. if (!filter_count && is_netdev) {
  1674. i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev);
  1675. f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
  1676. is_vf, is_netdev);
  1677. if (!f) {
  1678. dev_info(&vsi->back->pdev->dev,
  1679. "Could not add filter %d for %pM\n",
  1680. I40E_VLAN_ANY, netdev->dev_addr);
  1681. return -ENOMEM;
  1682. }
  1683. }
  1684. if (!filter_count) {
  1685. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1686. i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev);
  1687. add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  1688. is_vf, is_netdev);
  1689. if (!add_f) {
  1690. dev_info(&vsi->back->pdev->dev,
  1691. "Could not add filter %d for %pM\n",
  1692. I40E_VLAN_ANY, f->macaddr);
  1693. return -ENOMEM;
  1694. }
  1695. }
  1696. }
  1697. return i40e_sync_vsi_filters(vsi);
  1698. }
  1699. /**
  1700. * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
  1701. * @netdev: network interface to be adjusted
  1702. * @vid: vlan id to be added
  1703. *
  1704. * net_device_ops implementation for adding vlan ids
  1705. **/
  1706. static int i40e_vlan_rx_add_vid(struct net_device *netdev,
  1707. __always_unused __be16 proto, u16 vid)
  1708. {
  1709. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1710. struct i40e_vsi *vsi = np->vsi;
  1711. int ret = 0;
  1712. if (vid > 4095)
  1713. return -EINVAL;
  1714. netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid);
  1715. /* If the network stack called us with vid = 0, we should
  1716. * indicate to i40e_vsi_add_vlan() that we want to receive
  1717. * any traffic (i.e. with any vlan tag, or untagged)
  1718. */
  1719. ret = i40e_vsi_add_vlan(vsi, vid ? vid : I40E_VLAN_ANY);
  1720. if (!ret && (vid < VLAN_N_VID))
  1721. set_bit(vid, vsi->active_vlans);
  1722. return ret;
  1723. }
  1724. /**
  1725. * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
  1726. * @netdev: network interface to be adjusted
  1727. * @vid: vlan id to be removed
  1728. *
  1729. * net_device_ops implementation for adding vlan ids
  1730. **/
  1731. static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  1732. __always_unused __be16 proto, u16 vid)
  1733. {
  1734. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1735. struct i40e_vsi *vsi = np->vsi;
  1736. netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid);
  1737. /* return code is ignored as there is nothing a user
  1738. * can do about failure to remove and a log message was
  1739. * already printed from the other function
  1740. */
  1741. i40e_vsi_kill_vlan(vsi, vid);
  1742. clear_bit(vid, vsi->active_vlans);
  1743. return 0;
  1744. }
  1745. /**
  1746. * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
  1747. * @vsi: the vsi being brought back up
  1748. **/
  1749. static void i40e_restore_vlan(struct i40e_vsi *vsi)
  1750. {
  1751. u16 vid;
  1752. if (!vsi->netdev)
  1753. return;
  1754. i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
  1755. for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
  1756. i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
  1757. vid);
  1758. }
  1759. /**
  1760. * i40e_vsi_add_pvid - Add pvid for the VSI
  1761. * @vsi: the vsi being adjusted
  1762. * @vid: the vlan id to set as a PVID
  1763. **/
  1764. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
  1765. {
  1766. struct i40e_vsi_context ctxt;
  1767. i40e_status aq_ret;
  1768. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  1769. vsi->info.pvid = cpu_to_le16(vid);
  1770. vsi->info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID;
  1771. vsi->info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
  1772. ctxt.seid = vsi->seid;
  1773. memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
  1774. aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  1775. if (aq_ret) {
  1776. dev_info(&vsi->back->pdev->dev,
  1777. "%s: update vsi failed, aq_err=%d\n",
  1778. __func__, vsi->back->hw.aq.asq_last_status);
  1779. return -ENOENT;
  1780. }
  1781. return 0;
  1782. }
  1783. /**
  1784. * i40e_vsi_remove_pvid - Remove the pvid from the VSI
  1785. * @vsi: the vsi being adjusted
  1786. *
  1787. * Just use the vlan_rx_register() service to put it back to normal
  1788. **/
  1789. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
  1790. {
  1791. vsi->info.pvid = 0;
  1792. i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
  1793. }
  1794. /**
  1795. * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
  1796. * @vsi: ptr to the VSI
  1797. *
  1798. * If this function returns with an error, then it's possible one or
  1799. * more of the rings is populated (while the rest are not). It is the
  1800. * callers duty to clean those orphaned rings.
  1801. *
  1802. * Return 0 on success, negative on failure
  1803. **/
  1804. static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
  1805. {
  1806. int i, err = 0;
  1807. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  1808. err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
  1809. return err;
  1810. }
  1811. /**
  1812. * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
  1813. * @vsi: ptr to the VSI
  1814. *
  1815. * Free VSI's transmit software resources
  1816. **/
  1817. static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
  1818. {
  1819. int i;
  1820. for (i = 0; i < vsi->num_queue_pairs; i++)
  1821. if (vsi->tx_rings[i]->desc)
  1822. i40e_free_tx_resources(vsi->tx_rings[i]);
  1823. }
  1824. /**
  1825. * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
  1826. * @vsi: ptr to the VSI
  1827. *
  1828. * If this function returns with an error, then it's possible one or
  1829. * more of the rings is populated (while the rest are not). It is the
  1830. * callers duty to clean those orphaned rings.
  1831. *
  1832. * Return 0 on success, negative on failure
  1833. **/
  1834. static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
  1835. {
  1836. int i, err = 0;
  1837. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  1838. err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
  1839. return err;
  1840. }
  1841. /**
  1842. * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
  1843. * @vsi: ptr to the VSI
  1844. *
  1845. * Free all receive software resources
  1846. **/
  1847. static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
  1848. {
  1849. int i;
  1850. for (i = 0; i < vsi->num_queue_pairs; i++)
  1851. if (vsi->rx_rings[i]->desc)
  1852. i40e_free_rx_resources(vsi->rx_rings[i]);
  1853. }
  1854. /**
  1855. * i40e_configure_tx_ring - Configure a transmit ring context and rest
  1856. * @ring: The Tx ring to configure
  1857. *
  1858. * Configure the Tx descriptor ring in the HMC context.
  1859. **/
  1860. static int i40e_configure_tx_ring(struct i40e_ring *ring)
  1861. {
  1862. struct i40e_vsi *vsi = ring->vsi;
  1863. u16 pf_q = vsi->base_queue + ring->queue_index;
  1864. struct i40e_hw *hw = &vsi->back->hw;
  1865. struct i40e_hmc_obj_txq tx_ctx;
  1866. i40e_status err = 0;
  1867. u32 qtx_ctl = 0;
  1868. /* some ATR related tx ring init */
  1869. if (vsi->back->flags & I40E_FLAG_FDIR_ATR_ENABLED) {
  1870. ring->atr_sample_rate = vsi->back->atr_sample_rate;
  1871. ring->atr_count = 0;
  1872. } else {
  1873. ring->atr_sample_rate = 0;
  1874. }
  1875. /* initialize XPS */
  1876. if (ring->q_vector && ring->netdev &&
  1877. !test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
  1878. netif_set_xps_queue(ring->netdev,
  1879. &ring->q_vector->affinity_mask,
  1880. ring->queue_index);
  1881. /* clear the context structure first */
  1882. memset(&tx_ctx, 0, sizeof(tx_ctx));
  1883. tx_ctx.new_context = 1;
  1884. tx_ctx.base = (ring->dma / 128);
  1885. tx_ctx.qlen = ring->count;
  1886. tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FDIR_ENABLED |
  1887. I40E_FLAG_FDIR_ATR_ENABLED));
  1888. /* As part of VSI creation/update, FW allocates certain
  1889. * Tx arbitration queue sets for each TC enabled for
  1890. * the VSI. The FW returns the handles to these queue
  1891. * sets as part of the response buffer to Add VSI,
  1892. * Update VSI, etc. AQ commands. It is expected that
  1893. * these queue set handles be associated with the Tx
  1894. * queues by the driver as part of the TX queue context
  1895. * initialization. This has to be done regardless of
  1896. * DCB as by default everything is mapped to TC0.
  1897. */
  1898. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
  1899. tx_ctx.rdylist_act = 0;
  1900. /* clear the context in the HMC */
  1901. err = i40e_clear_lan_tx_queue_context(hw, pf_q);
  1902. if (err) {
  1903. dev_info(&vsi->back->pdev->dev,
  1904. "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
  1905. ring->queue_index, pf_q, err);
  1906. return -ENOMEM;
  1907. }
  1908. /* set the context in the HMC */
  1909. err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
  1910. if (err) {
  1911. dev_info(&vsi->back->pdev->dev,
  1912. "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
  1913. ring->queue_index, pf_q, err);
  1914. return -ENOMEM;
  1915. }
  1916. /* Now associate this queue with this PCI function */
  1917. qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
  1918. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
  1919. I40E_QTX_CTL_PF_INDX_MASK);
  1920. wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
  1921. i40e_flush(hw);
  1922. clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state);
  1923. /* cache tail off for easier writes later */
  1924. ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
  1925. return 0;
  1926. }
  1927. /**
  1928. * i40e_configure_rx_ring - Configure a receive ring context
  1929. * @ring: The Rx ring to configure
  1930. *
  1931. * Configure the Rx descriptor ring in the HMC context.
  1932. **/
  1933. static int i40e_configure_rx_ring(struct i40e_ring *ring)
  1934. {
  1935. struct i40e_vsi *vsi = ring->vsi;
  1936. u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
  1937. u16 pf_q = vsi->base_queue + ring->queue_index;
  1938. struct i40e_hw *hw = &vsi->back->hw;
  1939. struct i40e_hmc_obj_rxq rx_ctx;
  1940. i40e_status err = 0;
  1941. ring->state = 0;
  1942. /* clear the context structure first */
  1943. memset(&rx_ctx, 0, sizeof(rx_ctx));
  1944. ring->rx_buf_len = vsi->rx_buf_len;
  1945. ring->rx_hdr_len = vsi->rx_hdr_len;
  1946. rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
  1947. rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
  1948. rx_ctx.base = (ring->dma / 128);
  1949. rx_ctx.qlen = ring->count;
  1950. if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) {
  1951. set_ring_16byte_desc_enabled(ring);
  1952. rx_ctx.dsize = 0;
  1953. } else {
  1954. rx_ctx.dsize = 1;
  1955. }
  1956. rx_ctx.dtype = vsi->dtype;
  1957. if (vsi->dtype) {
  1958. set_ring_ps_enabled(ring);
  1959. rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
  1960. I40E_RX_SPLIT_IP |
  1961. I40E_RX_SPLIT_TCP_UDP |
  1962. I40E_RX_SPLIT_SCTP;
  1963. } else {
  1964. rx_ctx.hsplit_0 = 0;
  1965. }
  1966. rx_ctx.rxmax = min_t(u16, vsi->max_frame,
  1967. (chain_len * ring->rx_buf_len));
  1968. rx_ctx.tphrdesc_ena = 1;
  1969. rx_ctx.tphwdesc_ena = 1;
  1970. rx_ctx.tphdata_ena = 1;
  1971. rx_ctx.tphhead_ena = 1;
  1972. rx_ctx.lrxqthresh = 2;
  1973. rx_ctx.crcstrip = 1;
  1974. rx_ctx.l2tsel = 1;
  1975. rx_ctx.showiv = 1;
  1976. /* clear the context in the HMC */
  1977. err = i40e_clear_lan_rx_queue_context(hw, pf_q);
  1978. if (err) {
  1979. dev_info(&vsi->back->pdev->dev,
  1980. "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  1981. ring->queue_index, pf_q, err);
  1982. return -ENOMEM;
  1983. }
  1984. /* set the context in the HMC */
  1985. err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
  1986. if (err) {
  1987. dev_info(&vsi->back->pdev->dev,
  1988. "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  1989. ring->queue_index, pf_q, err);
  1990. return -ENOMEM;
  1991. }
  1992. /* cache tail for quicker writes, and clear the reg before use */
  1993. ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
  1994. writel(0, ring->tail);
  1995. i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
  1996. return 0;
  1997. }
  1998. /**
  1999. * i40e_vsi_configure_tx - Configure the VSI for Tx
  2000. * @vsi: VSI structure describing this set of rings and resources
  2001. *
  2002. * Configure the Tx VSI for operation.
  2003. **/
  2004. static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
  2005. {
  2006. int err = 0;
  2007. u16 i;
  2008. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2009. err = i40e_configure_tx_ring(vsi->tx_rings[i]);
  2010. return err;
  2011. }
  2012. /**
  2013. * i40e_vsi_configure_rx - Configure the VSI for Rx
  2014. * @vsi: the VSI being configured
  2015. *
  2016. * Configure the Rx VSI for operation.
  2017. **/
  2018. static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
  2019. {
  2020. int err = 0;
  2021. u16 i;
  2022. if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
  2023. vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
  2024. + ETH_FCS_LEN + VLAN_HLEN;
  2025. else
  2026. vsi->max_frame = I40E_RXBUFFER_2048;
  2027. /* figure out correct receive buffer length */
  2028. switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED |
  2029. I40E_FLAG_RX_PS_ENABLED)) {
  2030. case I40E_FLAG_RX_1BUF_ENABLED:
  2031. vsi->rx_hdr_len = 0;
  2032. vsi->rx_buf_len = vsi->max_frame;
  2033. vsi->dtype = I40E_RX_DTYPE_NO_SPLIT;
  2034. break;
  2035. case I40E_FLAG_RX_PS_ENABLED:
  2036. vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
  2037. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2038. vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT;
  2039. break;
  2040. default:
  2041. vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
  2042. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2043. vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS;
  2044. break;
  2045. }
  2046. /* round up for the chip's needs */
  2047. vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len,
  2048. (1 << I40E_RXQ_CTX_HBUFF_SHIFT));
  2049. vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
  2050. (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
  2051. /* set up individual rings */
  2052. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2053. err = i40e_configure_rx_ring(vsi->rx_rings[i]);
  2054. return err;
  2055. }
  2056. /**
  2057. * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
  2058. * @vsi: ptr to the VSI
  2059. **/
  2060. static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
  2061. {
  2062. u16 qoffset, qcount;
  2063. int i, n;
  2064. if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED))
  2065. return;
  2066. for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
  2067. if (!(vsi->tc_config.enabled_tc & (1 << n)))
  2068. continue;
  2069. qoffset = vsi->tc_config.tc_info[n].qoffset;
  2070. qcount = vsi->tc_config.tc_info[n].qcount;
  2071. for (i = qoffset; i < (qoffset + qcount); i++) {
  2072. struct i40e_ring *rx_ring = vsi->rx_rings[i];
  2073. struct i40e_ring *tx_ring = vsi->tx_rings[i];
  2074. rx_ring->dcb_tc = n;
  2075. tx_ring->dcb_tc = n;
  2076. }
  2077. }
  2078. }
  2079. /**
  2080. * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
  2081. * @vsi: ptr to the VSI
  2082. **/
  2083. static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
  2084. {
  2085. if (vsi->netdev)
  2086. i40e_set_rx_mode(vsi->netdev);
  2087. }
  2088. /**
  2089. * i40e_vsi_configure - Set up the VSI for action
  2090. * @vsi: the VSI being configured
  2091. **/
  2092. static int i40e_vsi_configure(struct i40e_vsi *vsi)
  2093. {
  2094. int err;
  2095. i40e_set_vsi_rx_mode(vsi);
  2096. i40e_restore_vlan(vsi);
  2097. i40e_vsi_config_dcb_rings(vsi);
  2098. err = i40e_vsi_configure_tx(vsi);
  2099. if (!err)
  2100. err = i40e_vsi_configure_rx(vsi);
  2101. return err;
  2102. }
  2103. /**
  2104. * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
  2105. * @vsi: the VSI being configured
  2106. **/
  2107. static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
  2108. {
  2109. struct i40e_pf *pf = vsi->back;
  2110. struct i40e_q_vector *q_vector;
  2111. struct i40e_hw *hw = &pf->hw;
  2112. u16 vector;
  2113. int i, q;
  2114. u32 val;
  2115. u32 qp;
  2116. /* The interrupt indexing is offset by 1 in the PFINT_ITRn
  2117. * and PFINT_LNKLSTn registers, e.g.:
  2118. * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
  2119. */
  2120. qp = vsi->base_queue;
  2121. vector = vsi->base_vector;
  2122. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  2123. q_vector = vsi->q_vectors[i];
  2124. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  2125. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2126. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
  2127. q_vector->rx.itr);
  2128. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  2129. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2130. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
  2131. q_vector->tx.itr);
  2132. /* Linked list for the queuepairs assigned to this vector */
  2133. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
  2134. for (q = 0; q < q_vector->num_ringpairs; q++) {
  2135. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2136. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2137. (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
  2138. (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
  2139. (I40E_QUEUE_TYPE_TX
  2140. << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
  2141. wr32(hw, I40E_QINT_RQCTL(qp), val);
  2142. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2143. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  2144. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  2145. ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
  2146. (I40E_QUEUE_TYPE_RX
  2147. << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2148. /* Terminate the linked list */
  2149. if (q == (q_vector->num_ringpairs - 1))
  2150. val |= (I40E_QUEUE_END_OF_LIST
  2151. << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  2152. wr32(hw, I40E_QINT_TQCTL(qp), val);
  2153. qp++;
  2154. }
  2155. }
  2156. i40e_flush(hw);
  2157. }
  2158. /**
  2159. * i40e_enable_misc_int_causes - enable the non-queue interrupts
  2160. * @hw: ptr to the hardware info
  2161. **/
  2162. static void i40e_enable_misc_int_causes(struct i40e_hw *hw)
  2163. {
  2164. u32 val;
  2165. /* clear things first */
  2166. wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
  2167. rd32(hw, I40E_PFINT_ICR0); /* read to clear */
  2168. val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
  2169. I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
  2170. I40E_PFINT_ICR0_ENA_GRST_MASK |
  2171. I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
  2172. I40E_PFINT_ICR0_ENA_GPIO_MASK |
  2173. I40E_PFINT_ICR0_ENA_STORM_DETECT_MASK |
  2174. I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
  2175. I40E_PFINT_ICR0_ENA_VFLR_MASK |
  2176. I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  2177. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  2178. /* SW_ITR_IDX = 0, but don't change INTENA */
  2179. wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTLN_SW_ITR_INDX_MASK |
  2180. I40E_PFINT_DYN_CTLN_INTENA_MSK_MASK);
  2181. /* OTHER_ITR_IDX = 0 */
  2182. wr32(hw, I40E_PFINT_STAT_CTL0, 0);
  2183. }
  2184. /**
  2185. * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
  2186. * @vsi: the VSI being configured
  2187. **/
  2188. static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
  2189. {
  2190. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  2191. struct i40e_pf *pf = vsi->back;
  2192. struct i40e_hw *hw = &pf->hw;
  2193. u32 val;
  2194. /* set the ITR configuration */
  2195. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  2196. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2197. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
  2198. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  2199. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2200. wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
  2201. i40e_enable_misc_int_causes(hw);
  2202. /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
  2203. wr32(hw, I40E_PFINT_LNKLST0, 0);
  2204. /* Associate the queue pair to the vector and enable the q int */
  2205. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2206. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2207. (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2208. wr32(hw, I40E_QINT_RQCTL(0), val);
  2209. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2210. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  2211. (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  2212. wr32(hw, I40E_QINT_TQCTL(0), val);
  2213. i40e_flush(hw);
  2214. }
  2215. /**
  2216. * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
  2217. * @pf: board private structure
  2218. **/
  2219. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
  2220. {
  2221. struct i40e_hw *hw = &pf->hw;
  2222. u32 val;
  2223. val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
  2224. I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
  2225. (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
  2226. wr32(hw, I40E_PFINT_DYN_CTL0, val);
  2227. i40e_flush(hw);
  2228. }
  2229. /**
  2230. * i40e_irq_dynamic_enable - Enable default interrupt generation settings
  2231. * @vsi: pointer to a vsi
  2232. * @vector: enable a particular Hw Interrupt vector
  2233. **/
  2234. void i40e_irq_dynamic_enable(struct i40e_vsi *vsi, int vector)
  2235. {
  2236. struct i40e_pf *pf = vsi->back;
  2237. struct i40e_hw *hw = &pf->hw;
  2238. u32 val;
  2239. val = I40E_PFINT_DYN_CTLN_INTENA_MASK |
  2240. I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
  2241. (I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  2242. wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val);
  2243. /* skip the flush */
  2244. }
  2245. /**
  2246. * i40e_msix_clean_rings - MSIX mode Interrupt Handler
  2247. * @irq: interrupt number
  2248. * @data: pointer to a q_vector
  2249. **/
  2250. static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
  2251. {
  2252. struct i40e_q_vector *q_vector = data;
  2253. if (!q_vector->tx.ring && !q_vector->rx.ring)
  2254. return IRQ_HANDLED;
  2255. napi_schedule(&q_vector->napi);
  2256. return IRQ_HANDLED;
  2257. }
  2258. /**
  2259. * i40e_fdir_clean_rings - Interrupt Handler for FDIR rings
  2260. * @irq: interrupt number
  2261. * @data: pointer to a q_vector
  2262. **/
  2263. static irqreturn_t i40e_fdir_clean_rings(int irq, void *data)
  2264. {
  2265. struct i40e_q_vector *q_vector = data;
  2266. if (!q_vector->tx.ring && !q_vector->rx.ring)
  2267. return IRQ_HANDLED;
  2268. pr_info("fdir ring cleaning needed\n");
  2269. return IRQ_HANDLED;
  2270. }
  2271. /**
  2272. * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
  2273. * @vsi: the VSI being configured
  2274. * @basename: name for the vector
  2275. *
  2276. * Allocates MSI-X vectors and requests interrupts from the kernel.
  2277. **/
  2278. static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
  2279. {
  2280. int q_vectors = vsi->num_q_vectors;
  2281. struct i40e_pf *pf = vsi->back;
  2282. int base = vsi->base_vector;
  2283. int rx_int_idx = 0;
  2284. int tx_int_idx = 0;
  2285. int vector, err;
  2286. for (vector = 0; vector < q_vectors; vector++) {
  2287. struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
  2288. if (q_vector->tx.ring && q_vector->rx.ring) {
  2289. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2290. "%s-%s-%d", basename, "TxRx", rx_int_idx++);
  2291. tx_int_idx++;
  2292. } else if (q_vector->rx.ring) {
  2293. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2294. "%s-%s-%d", basename, "rx", rx_int_idx++);
  2295. } else if (q_vector->tx.ring) {
  2296. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2297. "%s-%s-%d", basename, "tx", tx_int_idx++);
  2298. } else {
  2299. /* skip this unused q_vector */
  2300. continue;
  2301. }
  2302. err = request_irq(pf->msix_entries[base + vector].vector,
  2303. vsi->irq_handler,
  2304. 0,
  2305. q_vector->name,
  2306. q_vector);
  2307. if (err) {
  2308. dev_info(&pf->pdev->dev,
  2309. "%s: request_irq failed, error: %d\n",
  2310. __func__, err);
  2311. goto free_queue_irqs;
  2312. }
  2313. /* assign the mask for this irq */
  2314. irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
  2315. &q_vector->affinity_mask);
  2316. }
  2317. return 0;
  2318. free_queue_irqs:
  2319. while (vector) {
  2320. vector--;
  2321. irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
  2322. NULL);
  2323. free_irq(pf->msix_entries[base + vector].vector,
  2324. &(vsi->q_vectors[vector]));
  2325. }
  2326. return err;
  2327. }
  2328. /**
  2329. * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
  2330. * @vsi: the VSI being un-configured
  2331. **/
  2332. static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
  2333. {
  2334. struct i40e_pf *pf = vsi->back;
  2335. struct i40e_hw *hw = &pf->hw;
  2336. int base = vsi->base_vector;
  2337. int i;
  2338. for (i = 0; i < vsi->num_queue_pairs; i++) {
  2339. wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
  2340. wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
  2341. }
  2342. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2343. for (i = vsi->base_vector;
  2344. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  2345. wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
  2346. i40e_flush(hw);
  2347. for (i = 0; i < vsi->num_q_vectors; i++)
  2348. synchronize_irq(pf->msix_entries[i + base].vector);
  2349. } else {
  2350. /* Legacy and MSI mode - this stops all interrupt handling */
  2351. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  2352. wr32(hw, I40E_PFINT_DYN_CTL0, 0);
  2353. i40e_flush(hw);
  2354. synchronize_irq(pf->pdev->irq);
  2355. }
  2356. }
  2357. /**
  2358. * i40e_vsi_enable_irq - Enable IRQ for the given VSI
  2359. * @vsi: the VSI being configured
  2360. **/
  2361. static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
  2362. {
  2363. struct i40e_pf *pf = vsi->back;
  2364. int i;
  2365. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2366. for (i = vsi->base_vector;
  2367. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  2368. i40e_irq_dynamic_enable(vsi, i);
  2369. } else {
  2370. i40e_irq_dynamic_enable_icr0(pf);
  2371. }
  2372. i40e_flush(&pf->hw);
  2373. return 0;
  2374. }
  2375. /**
  2376. * i40e_stop_misc_vector - Stop the vector that handles non-queue events
  2377. * @pf: board private structure
  2378. **/
  2379. static void i40e_stop_misc_vector(struct i40e_pf *pf)
  2380. {
  2381. /* Disable ICR 0 */
  2382. wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
  2383. i40e_flush(&pf->hw);
  2384. }
  2385. /**
  2386. * i40e_intr - MSI/Legacy and non-queue interrupt handler
  2387. * @irq: interrupt number
  2388. * @data: pointer to a q_vector
  2389. *
  2390. * This is the handler used for all MSI/Legacy interrupts, and deals
  2391. * with both queue and non-queue interrupts. This is also used in
  2392. * MSIX mode to handle the non-queue interrupts.
  2393. **/
  2394. static irqreturn_t i40e_intr(int irq, void *data)
  2395. {
  2396. struct i40e_pf *pf = (struct i40e_pf *)data;
  2397. struct i40e_hw *hw = &pf->hw;
  2398. u32 icr0, icr0_remaining;
  2399. u32 val, ena_mask;
  2400. icr0 = rd32(hw, I40E_PFINT_ICR0);
  2401. val = rd32(hw, I40E_PFINT_DYN_CTL0);
  2402. val = val | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK;
  2403. wr32(hw, I40E_PFINT_DYN_CTL0, val);
  2404. /* if sharing a legacy IRQ, we might get called w/o an intr pending */
  2405. if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
  2406. return IRQ_NONE;
  2407. ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
  2408. /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
  2409. if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
  2410. /* temporarily disable queue cause for NAPI processing */
  2411. u32 qval = rd32(hw, I40E_QINT_RQCTL(0));
  2412. qval &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
  2413. wr32(hw, I40E_QINT_RQCTL(0), qval);
  2414. qval = rd32(hw, I40E_QINT_TQCTL(0));
  2415. qval &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
  2416. wr32(hw, I40E_QINT_TQCTL(0), qval);
  2417. if (!test_bit(__I40E_DOWN, &pf->state))
  2418. napi_schedule(&pf->vsi[pf->lan_vsi]->q_vectors[0]->napi);
  2419. }
  2420. if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
  2421. ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  2422. set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  2423. }
  2424. if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
  2425. ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  2426. set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  2427. }
  2428. if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
  2429. ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
  2430. set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
  2431. }
  2432. if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
  2433. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  2434. set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  2435. ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
  2436. val = rd32(hw, I40E_GLGEN_RSTAT);
  2437. val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
  2438. >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
  2439. if (val & I40E_RESET_CORER)
  2440. pf->corer_count++;
  2441. else if (val & I40E_RESET_GLOBR)
  2442. pf->globr_count++;
  2443. else if (val & I40E_RESET_EMPR)
  2444. pf->empr_count++;
  2445. }
  2446. /* If a critical error is pending we have no choice but to reset the
  2447. * device.
  2448. * Report and mask out any remaining unexpected interrupts.
  2449. */
  2450. icr0_remaining = icr0 & ena_mask;
  2451. if (icr0_remaining) {
  2452. dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
  2453. icr0_remaining);
  2454. if ((icr0_remaining & I40E_PFINT_ICR0_HMC_ERR_MASK) ||
  2455. (icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
  2456. (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
  2457. (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK) ||
  2458. (icr0_remaining & I40E_PFINT_ICR0_MAL_DETECT_MASK)) {
  2459. if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
  2460. dev_info(&pf->pdev->dev, "HMC error interrupt\n");
  2461. } else {
  2462. dev_info(&pf->pdev->dev, "device will be reset\n");
  2463. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  2464. i40e_service_event_schedule(pf);
  2465. }
  2466. }
  2467. ena_mask &= ~icr0_remaining;
  2468. }
  2469. /* re-enable interrupt causes */
  2470. wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
  2471. if (!test_bit(__I40E_DOWN, &pf->state)) {
  2472. i40e_service_event_schedule(pf);
  2473. i40e_irq_dynamic_enable_icr0(pf);
  2474. }
  2475. return IRQ_HANDLED;
  2476. }
  2477. /**
  2478. * i40e_map_vector_to_qp - Assigns the queue pair to the vector
  2479. * @vsi: the VSI being configured
  2480. * @v_idx: vector index
  2481. * @qp_idx: queue pair index
  2482. **/
  2483. static void map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
  2484. {
  2485. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  2486. struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
  2487. struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
  2488. tx_ring->q_vector = q_vector;
  2489. tx_ring->next = q_vector->tx.ring;
  2490. q_vector->tx.ring = tx_ring;
  2491. q_vector->tx.count++;
  2492. rx_ring->q_vector = q_vector;
  2493. rx_ring->next = q_vector->rx.ring;
  2494. q_vector->rx.ring = rx_ring;
  2495. q_vector->rx.count++;
  2496. }
  2497. /**
  2498. * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
  2499. * @vsi: the VSI being configured
  2500. *
  2501. * This function maps descriptor rings to the queue-specific vectors
  2502. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  2503. * one vector per queue pair, but on a constrained vector budget, we
  2504. * group the queue pairs as "efficiently" as possible.
  2505. **/
  2506. static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
  2507. {
  2508. int qp_remaining = vsi->num_queue_pairs;
  2509. int q_vectors = vsi->num_q_vectors;
  2510. int num_ringpairs;
  2511. int v_start = 0;
  2512. int qp_idx = 0;
  2513. /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
  2514. * group them so there are multiple queues per vector.
  2515. */
  2516. for (; v_start < q_vectors && qp_remaining; v_start++) {
  2517. struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
  2518. num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
  2519. q_vector->num_ringpairs = num_ringpairs;
  2520. q_vector->rx.count = 0;
  2521. q_vector->tx.count = 0;
  2522. q_vector->rx.ring = NULL;
  2523. q_vector->tx.ring = NULL;
  2524. while (num_ringpairs--) {
  2525. map_vector_to_qp(vsi, v_start, qp_idx);
  2526. qp_idx++;
  2527. qp_remaining--;
  2528. }
  2529. }
  2530. }
  2531. /**
  2532. * i40e_vsi_request_irq - Request IRQ from the OS
  2533. * @vsi: the VSI being configured
  2534. * @basename: name for the vector
  2535. **/
  2536. static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
  2537. {
  2538. struct i40e_pf *pf = vsi->back;
  2539. int err;
  2540. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  2541. err = i40e_vsi_request_irq_msix(vsi, basename);
  2542. else if (pf->flags & I40E_FLAG_MSI_ENABLED)
  2543. err = request_irq(pf->pdev->irq, i40e_intr, 0,
  2544. pf->misc_int_name, pf);
  2545. else
  2546. err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
  2547. pf->misc_int_name, pf);
  2548. if (err)
  2549. dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
  2550. return err;
  2551. }
  2552. #ifdef CONFIG_NET_POLL_CONTROLLER
  2553. /**
  2554. * i40e_netpoll - A Polling 'interrupt'handler
  2555. * @netdev: network interface device structure
  2556. *
  2557. * This is used by netconsole to send skbs without having to re-enable
  2558. * interrupts. It's not called while the normal interrupt routine is executing.
  2559. **/
  2560. static void i40e_netpoll(struct net_device *netdev)
  2561. {
  2562. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2563. struct i40e_vsi *vsi = np->vsi;
  2564. struct i40e_pf *pf = vsi->back;
  2565. int i;
  2566. /* if interface is down do nothing */
  2567. if (test_bit(__I40E_DOWN, &vsi->state))
  2568. return;
  2569. pf->flags |= I40E_FLAG_IN_NETPOLL;
  2570. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2571. for (i = 0; i < vsi->num_q_vectors; i++)
  2572. i40e_msix_clean_rings(0, vsi->q_vectors[i]);
  2573. } else {
  2574. i40e_intr(pf->pdev->irq, netdev);
  2575. }
  2576. pf->flags &= ~I40E_FLAG_IN_NETPOLL;
  2577. }
  2578. #endif
  2579. /**
  2580. * i40e_vsi_control_tx - Start or stop a VSI's rings
  2581. * @vsi: the VSI being configured
  2582. * @enable: start or stop the rings
  2583. **/
  2584. static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
  2585. {
  2586. struct i40e_pf *pf = vsi->back;
  2587. struct i40e_hw *hw = &pf->hw;
  2588. int i, j, pf_q;
  2589. u32 tx_reg;
  2590. pf_q = vsi->base_queue;
  2591. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  2592. j = 1000;
  2593. do {
  2594. usleep_range(1000, 2000);
  2595. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  2596. } while (j-- && ((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT)
  2597. ^ (tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)) & 1);
  2598. if (enable) {
  2599. /* is STAT set ? */
  2600. if ((tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) {
  2601. dev_info(&pf->pdev->dev,
  2602. "Tx %d already enabled\n", i);
  2603. continue;
  2604. }
  2605. } else {
  2606. /* is !STAT set ? */
  2607. if (!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) {
  2608. dev_info(&pf->pdev->dev,
  2609. "Tx %d already disabled\n", i);
  2610. continue;
  2611. }
  2612. }
  2613. /* turn on/off the queue */
  2614. if (enable)
  2615. tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK |
  2616. I40E_QTX_ENA_QENA_STAT_MASK;
  2617. else
  2618. tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
  2619. wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
  2620. /* wait for the change to finish */
  2621. for (j = 0; j < 10; j++) {
  2622. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  2623. if (enable) {
  2624. if ((tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  2625. break;
  2626. } else {
  2627. if (!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  2628. break;
  2629. }
  2630. udelay(10);
  2631. }
  2632. if (j >= 10) {
  2633. dev_info(&pf->pdev->dev, "Tx ring %d %sable timeout\n",
  2634. pf_q, (enable ? "en" : "dis"));
  2635. return -ETIMEDOUT;
  2636. }
  2637. }
  2638. return 0;
  2639. }
  2640. /**
  2641. * i40e_vsi_control_rx - Start or stop a VSI's rings
  2642. * @vsi: the VSI being configured
  2643. * @enable: start or stop the rings
  2644. **/
  2645. static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
  2646. {
  2647. struct i40e_pf *pf = vsi->back;
  2648. struct i40e_hw *hw = &pf->hw;
  2649. int i, j, pf_q;
  2650. u32 rx_reg;
  2651. pf_q = vsi->base_queue;
  2652. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  2653. j = 1000;
  2654. do {
  2655. usleep_range(1000, 2000);
  2656. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  2657. } while (j-- && ((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT)
  2658. ^ (rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT)) & 1);
  2659. if (enable) {
  2660. /* is STAT set ? */
  2661. if ((rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  2662. continue;
  2663. } else {
  2664. /* is !STAT set ? */
  2665. if (!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  2666. continue;
  2667. }
  2668. /* turn on/off the queue */
  2669. if (enable)
  2670. rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK |
  2671. I40E_QRX_ENA_QENA_STAT_MASK;
  2672. else
  2673. rx_reg &= ~(I40E_QRX_ENA_QENA_REQ_MASK |
  2674. I40E_QRX_ENA_QENA_STAT_MASK);
  2675. wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
  2676. /* wait for the change to finish */
  2677. for (j = 0; j < 10; j++) {
  2678. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  2679. if (enable) {
  2680. if ((rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  2681. break;
  2682. } else {
  2683. if (!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  2684. break;
  2685. }
  2686. udelay(10);
  2687. }
  2688. if (j >= 10) {
  2689. dev_info(&pf->pdev->dev, "Rx ring %d %sable timeout\n",
  2690. pf_q, (enable ? "en" : "dis"));
  2691. return -ETIMEDOUT;
  2692. }
  2693. }
  2694. return 0;
  2695. }
  2696. /**
  2697. * i40e_vsi_control_rings - Start or stop a VSI's rings
  2698. * @vsi: the VSI being configured
  2699. * @enable: start or stop the rings
  2700. **/
  2701. static int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request)
  2702. {
  2703. int ret;
  2704. /* do rx first for enable and last for disable */
  2705. if (request) {
  2706. ret = i40e_vsi_control_rx(vsi, request);
  2707. if (ret)
  2708. return ret;
  2709. ret = i40e_vsi_control_tx(vsi, request);
  2710. } else {
  2711. ret = i40e_vsi_control_tx(vsi, request);
  2712. if (ret)
  2713. return ret;
  2714. ret = i40e_vsi_control_rx(vsi, request);
  2715. }
  2716. return ret;
  2717. }
  2718. /**
  2719. * i40e_vsi_free_irq - Free the irq association with the OS
  2720. * @vsi: the VSI being configured
  2721. **/
  2722. static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
  2723. {
  2724. struct i40e_pf *pf = vsi->back;
  2725. struct i40e_hw *hw = &pf->hw;
  2726. int base = vsi->base_vector;
  2727. u32 val, qp;
  2728. int i;
  2729. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2730. if (!vsi->q_vectors)
  2731. return;
  2732. for (i = 0; i < vsi->num_q_vectors; i++) {
  2733. u16 vector = i + base;
  2734. /* free only the irqs that were actually requested */
  2735. if (vsi->q_vectors[i]->num_ringpairs == 0)
  2736. continue;
  2737. /* clear the affinity_mask in the IRQ descriptor */
  2738. irq_set_affinity_hint(pf->msix_entries[vector].vector,
  2739. NULL);
  2740. free_irq(pf->msix_entries[vector].vector,
  2741. vsi->q_vectors[i]);
  2742. /* Tear down the interrupt queue link list
  2743. *
  2744. * We know that they come in pairs and always
  2745. * the Rx first, then the Tx. To clear the
  2746. * link list, stick the EOL value into the
  2747. * next_q field of the registers.
  2748. */
  2749. val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
  2750. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  2751. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  2752. val |= I40E_QUEUE_END_OF_LIST
  2753. << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  2754. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
  2755. while (qp != I40E_QUEUE_END_OF_LIST) {
  2756. u32 next;
  2757. val = rd32(hw, I40E_QINT_RQCTL(qp));
  2758. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  2759. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  2760. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2761. I40E_QINT_RQCTL_INTEVENT_MASK);
  2762. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  2763. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  2764. wr32(hw, I40E_QINT_RQCTL(qp), val);
  2765. val = rd32(hw, I40E_QINT_TQCTL(qp));
  2766. next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
  2767. >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
  2768. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  2769. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  2770. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2771. I40E_QINT_TQCTL_INTEVENT_MASK);
  2772. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  2773. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  2774. wr32(hw, I40E_QINT_TQCTL(qp), val);
  2775. qp = next;
  2776. }
  2777. }
  2778. } else {
  2779. free_irq(pf->pdev->irq, pf);
  2780. val = rd32(hw, I40E_PFINT_LNKLST0);
  2781. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  2782. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  2783. val |= I40E_QUEUE_END_OF_LIST
  2784. << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  2785. wr32(hw, I40E_PFINT_LNKLST0, val);
  2786. val = rd32(hw, I40E_QINT_RQCTL(qp));
  2787. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  2788. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  2789. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2790. I40E_QINT_RQCTL_INTEVENT_MASK);
  2791. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  2792. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  2793. wr32(hw, I40E_QINT_RQCTL(qp), val);
  2794. val = rd32(hw, I40E_QINT_TQCTL(qp));
  2795. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  2796. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  2797. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2798. I40E_QINT_TQCTL_INTEVENT_MASK);
  2799. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  2800. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  2801. wr32(hw, I40E_QINT_TQCTL(qp), val);
  2802. }
  2803. }
  2804. /**
  2805. * i40e_free_q_vector - Free memory allocated for specific interrupt vector
  2806. * @vsi: the VSI being configured
  2807. * @v_idx: Index of vector to be freed
  2808. *
  2809. * This function frees the memory allocated to the q_vector. In addition if
  2810. * NAPI is enabled it will delete any references to the NAPI struct prior
  2811. * to freeing the q_vector.
  2812. **/
  2813. static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
  2814. {
  2815. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  2816. struct i40e_ring *ring;
  2817. if (!q_vector)
  2818. return;
  2819. /* disassociate q_vector from rings */
  2820. i40e_for_each_ring(ring, q_vector->tx)
  2821. ring->q_vector = NULL;
  2822. i40e_for_each_ring(ring, q_vector->rx)
  2823. ring->q_vector = NULL;
  2824. /* only VSI w/ an associated netdev is set up w/ NAPI */
  2825. if (vsi->netdev)
  2826. netif_napi_del(&q_vector->napi);
  2827. vsi->q_vectors[v_idx] = NULL;
  2828. kfree_rcu(q_vector, rcu);
  2829. }
  2830. /**
  2831. * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
  2832. * @vsi: the VSI being un-configured
  2833. *
  2834. * This frees the memory allocated to the q_vectors and
  2835. * deletes references to the NAPI struct.
  2836. **/
  2837. static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
  2838. {
  2839. int v_idx;
  2840. for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
  2841. i40e_free_q_vector(vsi, v_idx);
  2842. }
  2843. /**
  2844. * i40e_reset_interrupt_capability - Disable interrupt setup in OS
  2845. * @pf: board private structure
  2846. **/
  2847. static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
  2848. {
  2849. /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
  2850. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2851. pci_disable_msix(pf->pdev);
  2852. kfree(pf->msix_entries);
  2853. pf->msix_entries = NULL;
  2854. } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
  2855. pci_disable_msi(pf->pdev);
  2856. }
  2857. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  2858. }
  2859. /**
  2860. * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
  2861. * @pf: board private structure
  2862. *
  2863. * We go through and clear interrupt specific resources and reset the structure
  2864. * to pre-load conditions
  2865. **/
  2866. static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
  2867. {
  2868. int i;
  2869. i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
  2870. for (i = 0; i < pf->hw.func_caps.num_vsis; i++)
  2871. if (pf->vsi[i])
  2872. i40e_vsi_free_q_vectors(pf->vsi[i]);
  2873. i40e_reset_interrupt_capability(pf);
  2874. }
  2875. /**
  2876. * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
  2877. * @vsi: the VSI being configured
  2878. **/
  2879. static void i40e_napi_enable_all(struct i40e_vsi *vsi)
  2880. {
  2881. int q_idx;
  2882. if (!vsi->netdev)
  2883. return;
  2884. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
  2885. napi_enable(&vsi->q_vectors[q_idx]->napi);
  2886. }
  2887. /**
  2888. * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
  2889. * @vsi: the VSI being configured
  2890. **/
  2891. static void i40e_napi_disable_all(struct i40e_vsi *vsi)
  2892. {
  2893. int q_idx;
  2894. if (!vsi->netdev)
  2895. return;
  2896. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
  2897. napi_disable(&vsi->q_vectors[q_idx]->napi);
  2898. }
  2899. /**
  2900. * i40e_quiesce_vsi - Pause a given VSI
  2901. * @vsi: the VSI being paused
  2902. **/
  2903. static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
  2904. {
  2905. if (test_bit(__I40E_DOWN, &vsi->state))
  2906. return;
  2907. set_bit(__I40E_NEEDS_RESTART, &vsi->state);
  2908. if (vsi->netdev && netif_running(vsi->netdev)) {
  2909. vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
  2910. } else {
  2911. set_bit(__I40E_DOWN, &vsi->state);
  2912. i40e_down(vsi);
  2913. }
  2914. }
  2915. /**
  2916. * i40e_unquiesce_vsi - Resume a given VSI
  2917. * @vsi: the VSI being resumed
  2918. **/
  2919. static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
  2920. {
  2921. if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
  2922. return;
  2923. clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
  2924. if (vsi->netdev && netif_running(vsi->netdev))
  2925. vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
  2926. else
  2927. i40e_up(vsi); /* this clears the DOWN bit */
  2928. }
  2929. /**
  2930. * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
  2931. * @pf: the PF
  2932. **/
  2933. static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
  2934. {
  2935. int v;
  2936. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  2937. if (pf->vsi[v])
  2938. i40e_quiesce_vsi(pf->vsi[v]);
  2939. }
  2940. }
  2941. /**
  2942. * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
  2943. * @pf: the PF
  2944. **/
  2945. static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
  2946. {
  2947. int v;
  2948. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  2949. if (pf->vsi[v])
  2950. i40e_unquiesce_vsi(pf->vsi[v]);
  2951. }
  2952. }
  2953. /**
  2954. * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
  2955. * @dcbcfg: the corresponding DCBx configuration structure
  2956. *
  2957. * Return the number of TCs from given DCBx configuration
  2958. **/
  2959. static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
  2960. {
  2961. u8 num_tc = 0;
  2962. int i;
  2963. /* Scan the ETS Config Priority Table to find
  2964. * traffic class enabled for a given priority
  2965. * and use the traffic class index to get the
  2966. * number of traffic classes enabled
  2967. */
  2968. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  2969. if (dcbcfg->etscfg.prioritytable[i] > num_tc)
  2970. num_tc = dcbcfg->etscfg.prioritytable[i];
  2971. }
  2972. /* Traffic class index starts from zero so
  2973. * increment to return the actual count
  2974. */
  2975. return num_tc + 1;
  2976. }
  2977. /**
  2978. * i40e_dcb_get_enabled_tc - Get enabled traffic classes
  2979. * @dcbcfg: the corresponding DCBx configuration structure
  2980. *
  2981. * Query the current DCB configuration and return the number of
  2982. * traffic classes enabled from the given DCBX config
  2983. **/
  2984. static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
  2985. {
  2986. u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
  2987. u8 enabled_tc = 1;
  2988. u8 i;
  2989. for (i = 0; i < num_tc; i++)
  2990. enabled_tc |= 1 << i;
  2991. return enabled_tc;
  2992. }
  2993. /**
  2994. * i40e_pf_get_num_tc - Get enabled traffic classes for PF
  2995. * @pf: PF being queried
  2996. *
  2997. * Return number of traffic classes enabled for the given PF
  2998. **/
  2999. static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
  3000. {
  3001. struct i40e_hw *hw = &pf->hw;
  3002. u8 i, enabled_tc;
  3003. u8 num_tc = 0;
  3004. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  3005. /* If DCB is not enabled then always in single TC */
  3006. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  3007. return 1;
  3008. /* MFP mode return count of enabled TCs for this PF */
  3009. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  3010. enabled_tc = pf->hw.func_caps.enabled_tcmap;
  3011. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3012. if (enabled_tc & (1 << i))
  3013. num_tc++;
  3014. }
  3015. return num_tc;
  3016. }
  3017. /* SFP mode will be enabled for all TCs on port */
  3018. return i40e_dcb_get_num_tc(dcbcfg);
  3019. }
  3020. /**
  3021. * i40e_pf_get_default_tc - Get bitmap for first enabled TC
  3022. * @pf: PF being queried
  3023. *
  3024. * Return a bitmap for first enabled traffic class for this PF.
  3025. **/
  3026. static u8 i40e_pf_get_default_tc(struct i40e_pf *pf)
  3027. {
  3028. u8 enabled_tc = pf->hw.func_caps.enabled_tcmap;
  3029. u8 i = 0;
  3030. if (!enabled_tc)
  3031. return 0x1; /* TC0 */
  3032. /* Find the first enabled TC */
  3033. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3034. if (enabled_tc & (1 << i))
  3035. break;
  3036. }
  3037. return 1 << i;
  3038. }
  3039. /**
  3040. * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
  3041. * @pf: PF being queried
  3042. *
  3043. * Return a bitmap for enabled traffic classes for this PF.
  3044. **/
  3045. static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
  3046. {
  3047. /* If DCB is not enabled for this PF then just return default TC */
  3048. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  3049. return i40e_pf_get_default_tc(pf);
  3050. /* MFP mode will have enabled TCs set by FW */
  3051. if (pf->flags & I40E_FLAG_MFP_ENABLED)
  3052. return pf->hw.func_caps.enabled_tcmap;
  3053. /* SFP mode we want PF to be enabled for all TCs */
  3054. return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
  3055. }
  3056. /**
  3057. * i40e_vsi_get_bw_info - Query VSI BW Information
  3058. * @vsi: the VSI being queried
  3059. *
  3060. * Returns 0 on success, negative value on failure
  3061. **/
  3062. static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
  3063. {
  3064. struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
  3065. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  3066. struct i40e_pf *pf = vsi->back;
  3067. struct i40e_hw *hw = &pf->hw;
  3068. i40e_status aq_ret;
  3069. u32 tc_bw_max;
  3070. int i;
  3071. /* Get the VSI level BW configuration */
  3072. aq_ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
  3073. if (aq_ret) {
  3074. dev_info(&pf->pdev->dev,
  3075. "couldn't get pf vsi bw config, err %d, aq_err %d\n",
  3076. aq_ret, pf->hw.aq.asq_last_status);
  3077. return -EINVAL;
  3078. }
  3079. /* Get the VSI level BW configuration per TC */
  3080. aq_ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
  3081. NULL);
  3082. if (aq_ret) {
  3083. dev_info(&pf->pdev->dev,
  3084. "couldn't get pf vsi ets bw config, err %d, aq_err %d\n",
  3085. aq_ret, pf->hw.aq.asq_last_status);
  3086. return -EINVAL;
  3087. }
  3088. if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
  3089. dev_info(&pf->pdev->dev,
  3090. "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
  3091. bw_config.tc_valid_bits,
  3092. bw_ets_config.tc_valid_bits);
  3093. /* Still continuing */
  3094. }
  3095. vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
  3096. vsi->bw_max_quanta = bw_config.max_bw;
  3097. tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
  3098. (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
  3099. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3100. vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
  3101. vsi->bw_ets_limit_credits[i] =
  3102. le16_to_cpu(bw_ets_config.credits[i]);
  3103. /* 3 bits out of 4 for each TC */
  3104. vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
  3105. }
  3106. return 0;
  3107. }
  3108. /**
  3109. * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
  3110. * @vsi: the VSI being configured
  3111. * @enabled_tc: TC bitmap
  3112. * @bw_credits: BW shared credits per TC
  3113. *
  3114. * Returns 0 on success, negative value on failure
  3115. **/
  3116. static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
  3117. u8 *bw_share)
  3118. {
  3119. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  3120. i40e_status aq_ret;
  3121. int i;
  3122. bw_data.tc_valid_bits = enabled_tc;
  3123. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  3124. bw_data.tc_bw_credits[i] = bw_share[i];
  3125. aq_ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
  3126. NULL);
  3127. if (aq_ret) {
  3128. dev_info(&vsi->back->pdev->dev,
  3129. "%s: AQ command Config VSI BW allocation per TC failed = %d\n",
  3130. __func__, vsi->back->hw.aq.asq_last_status);
  3131. return -EINVAL;
  3132. }
  3133. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  3134. vsi->info.qs_handle[i] = bw_data.qs_handles[i];
  3135. return 0;
  3136. }
  3137. /**
  3138. * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
  3139. * @vsi: the VSI being configured
  3140. * @enabled_tc: TC map to be enabled
  3141. *
  3142. **/
  3143. static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  3144. {
  3145. struct net_device *netdev = vsi->netdev;
  3146. struct i40e_pf *pf = vsi->back;
  3147. struct i40e_hw *hw = &pf->hw;
  3148. u8 netdev_tc = 0;
  3149. int i;
  3150. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  3151. if (!netdev)
  3152. return;
  3153. if (!enabled_tc) {
  3154. netdev_reset_tc(netdev);
  3155. return;
  3156. }
  3157. /* Set up actual enabled TCs on the VSI */
  3158. if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
  3159. return;
  3160. /* set per TC queues for the VSI */
  3161. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3162. /* Only set TC queues for enabled tcs
  3163. *
  3164. * e.g. For a VSI that has TC0 and TC3 enabled the
  3165. * enabled_tc bitmap would be 0x00001001; the driver
  3166. * will set the numtc for netdev as 2 that will be
  3167. * referenced by the netdev layer as TC 0 and 1.
  3168. */
  3169. if (vsi->tc_config.enabled_tc & (1 << i))
  3170. netdev_set_tc_queue(netdev,
  3171. vsi->tc_config.tc_info[i].netdev_tc,
  3172. vsi->tc_config.tc_info[i].qcount,
  3173. vsi->tc_config.tc_info[i].qoffset);
  3174. }
  3175. /* Assign UP2TC map for the VSI */
  3176. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  3177. /* Get the actual TC# for the UP */
  3178. u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
  3179. /* Get the mapped netdev TC# for the UP */
  3180. netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
  3181. netdev_set_prio_tc_map(netdev, i, netdev_tc);
  3182. }
  3183. }
  3184. /**
  3185. * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
  3186. * @vsi: the VSI being configured
  3187. * @ctxt: the ctxt buffer returned from AQ VSI update param command
  3188. **/
  3189. static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
  3190. struct i40e_vsi_context *ctxt)
  3191. {
  3192. /* copy just the sections touched not the entire info
  3193. * since not all sections are valid as returned by
  3194. * update vsi params
  3195. */
  3196. vsi->info.mapping_flags = ctxt->info.mapping_flags;
  3197. memcpy(&vsi->info.queue_mapping,
  3198. &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
  3199. memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
  3200. sizeof(vsi->info.tc_mapping));
  3201. }
  3202. /**
  3203. * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
  3204. * @vsi: VSI to be configured
  3205. * @enabled_tc: TC bitmap
  3206. *
  3207. * This configures a particular VSI for TCs that are mapped to the
  3208. * given TC bitmap. It uses default bandwidth share for TCs across
  3209. * VSIs to configure TC for a particular VSI.
  3210. *
  3211. * NOTE:
  3212. * It is expected that the VSI queues have been quisced before calling
  3213. * this function.
  3214. **/
  3215. static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  3216. {
  3217. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  3218. struct i40e_vsi_context ctxt;
  3219. int ret = 0;
  3220. int i;
  3221. /* Check if enabled_tc is same as existing or new TCs */
  3222. if (vsi->tc_config.enabled_tc == enabled_tc)
  3223. return ret;
  3224. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  3225. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3226. if (enabled_tc & (1 << i))
  3227. bw_share[i] = 1;
  3228. }
  3229. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  3230. if (ret) {
  3231. dev_info(&vsi->back->pdev->dev,
  3232. "Failed configuring TC map %d for VSI %d\n",
  3233. enabled_tc, vsi->seid);
  3234. goto out;
  3235. }
  3236. /* Update Queue Pairs Mapping for currently enabled UPs */
  3237. ctxt.seid = vsi->seid;
  3238. ctxt.pf_num = vsi->back->hw.pf_id;
  3239. ctxt.vf_num = 0;
  3240. ctxt.uplink_seid = vsi->uplink_seid;
  3241. memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
  3242. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  3243. /* Update the VSI after updating the VSI queue-mapping information */
  3244. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  3245. if (ret) {
  3246. dev_info(&vsi->back->pdev->dev,
  3247. "update vsi failed, aq_err=%d\n",
  3248. vsi->back->hw.aq.asq_last_status);
  3249. goto out;
  3250. }
  3251. /* update the local VSI info with updated queue map */
  3252. i40e_vsi_update_queue_map(vsi, &ctxt);
  3253. vsi->info.valid_sections = 0;
  3254. /* Update current VSI BW information */
  3255. ret = i40e_vsi_get_bw_info(vsi);
  3256. if (ret) {
  3257. dev_info(&vsi->back->pdev->dev,
  3258. "Failed updating vsi bw info, aq_err=%d\n",
  3259. vsi->back->hw.aq.asq_last_status);
  3260. goto out;
  3261. }
  3262. /* Update the netdev TC setup */
  3263. i40e_vsi_config_netdev_tc(vsi, enabled_tc);
  3264. out:
  3265. return ret;
  3266. }
  3267. /**
  3268. * i40e_up_complete - Finish the last steps of bringing up a connection
  3269. * @vsi: the VSI being configured
  3270. **/
  3271. static int i40e_up_complete(struct i40e_vsi *vsi)
  3272. {
  3273. struct i40e_pf *pf = vsi->back;
  3274. int err;
  3275. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3276. i40e_vsi_configure_msix(vsi);
  3277. else
  3278. i40e_configure_msi_and_legacy(vsi);
  3279. /* start rings */
  3280. err = i40e_vsi_control_rings(vsi, true);
  3281. if (err)
  3282. return err;
  3283. clear_bit(__I40E_DOWN, &vsi->state);
  3284. i40e_napi_enable_all(vsi);
  3285. i40e_vsi_enable_irq(vsi);
  3286. if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
  3287. (vsi->netdev)) {
  3288. netdev_info(vsi->netdev, "NIC Link is Up\n");
  3289. netif_tx_start_all_queues(vsi->netdev);
  3290. netif_carrier_on(vsi->netdev);
  3291. } else if (vsi->netdev) {
  3292. netdev_info(vsi->netdev, "NIC Link is Down\n");
  3293. }
  3294. i40e_service_event_schedule(pf);
  3295. return 0;
  3296. }
  3297. /**
  3298. * i40e_vsi_reinit_locked - Reset the VSI
  3299. * @vsi: the VSI being configured
  3300. *
  3301. * Rebuild the ring structs after some configuration
  3302. * has changed, e.g. MTU size.
  3303. **/
  3304. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
  3305. {
  3306. struct i40e_pf *pf = vsi->back;
  3307. WARN_ON(in_interrupt());
  3308. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  3309. usleep_range(1000, 2000);
  3310. i40e_down(vsi);
  3311. /* Give a VF some time to respond to the reset. The
  3312. * two second wait is based upon the watchdog cycle in
  3313. * the VF driver.
  3314. */
  3315. if (vsi->type == I40E_VSI_SRIOV)
  3316. msleep(2000);
  3317. i40e_up(vsi);
  3318. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  3319. }
  3320. /**
  3321. * i40e_up - Bring the connection back up after being down
  3322. * @vsi: the VSI being configured
  3323. **/
  3324. int i40e_up(struct i40e_vsi *vsi)
  3325. {
  3326. int err;
  3327. err = i40e_vsi_configure(vsi);
  3328. if (!err)
  3329. err = i40e_up_complete(vsi);
  3330. return err;
  3331. }
  3332. /**
  3333. * i40e_down - Shutdown the connection processing
  3334. * @vsi: the VSI being stopped
  3335. **/
  3336. void i40e_down(struct i40e_vsi *vsi)
  3337. {
  3338. int i;
  3339. /* It is assumed that the caller of this function
  3340. * sets the vsi->state __I40E_DOWN bit.
  3341. */
  3342. if (vsi->netdev) {
  3343. netif_carrier_off(vsi->netdev);
  3344. netif_tx_disable(vsi->netdev);
  3345. }
  3346. i40e_vsi_disable_irq(vsi);
  3347. i40e_vsi_control_rings(vsi, false);
  3348. i40e_napi_disable_all(vsi);
  3349. for (i = 0; i < vsi->num_queue_pairs; i++) {
  3350. i40e_clean_tx_ring(vsi->tx_rings[i]);
  3351. i40e_clean_rx_ring(vsi->rx_rings[i]);
  3352. }
  3353. }
  3354. /**
  3355. * i40e_setup_tc - configure multiple traffic classes
  3356. * @netdev: net device to configure
  3357. * @tc: number of traffic classes to enable
  3358. **/
  3359. static int i40e_setup_tc(struct net_device *netdev, u8 tc)
  3360. {
  3361. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3362. struct i40e_vsi *vsi = np->vsi;
  3363. struct i40e_pf *pf = vsi->back;
  3364. u8 enabled_tc = 0;
  3365. int ret = -EINVAL;
  3366. int i;
  3367. /* Check if DCB enabled to continue */
  3368. if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  3369. netdev_info(netdev, "DCB is not enabled for adapter\n");
  3370. goto exit;
  3371. }
  3372. /* Check if MFP enabled */
  3373. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  3374. netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
  3375. goto exit;
  3376. }
  3377. /* Check whether tc count is within enabled limit */
  3378. if (tc > i40e_pf_get_num_tc(pf)) {
  3379. netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
  3380. goto exit;
  3381. }
  3382. /* Generate TC map for number of tc requested */
  3383. for (i = 0; i < tc; i++)
  3384. enabled_tc |= (1 << i);
  3385. /* Requesting same TC configuration as already enabled */
  3386. if (enabled_tc == vsi->tc_config.enabled_tc)
  3387. return 0;
  3388. /* Quiesce VSI queues */
  3389. i40e_quiesce_vsi(vsi);
  3390. /* Configure VSI for enabled TCs */
  3391. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  3392. if (ret) {
  3393. netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
  3394. vsi->seid);
  3395. goto exit;
  3396. }
  3397. /* Unquiesce VSI */
  3398. i40e_unquiesce_vsi(vsi);
  3399. exit:
  3400. return ret;
  3401. }
  3402. /**
  3403. * i40e_open - Called when a network interface is made active
  3404. * @netdev: network interface device structure
  3405. *
  3406. * The open entry point is called when a network interface is made
  3407. * active by the system (IFF_UP). At this point all resources needed
  3408. * for transmit and receive operations are allocated, the interrupt
  3409. * handler is registered with the OS, the netdev watchdog subtask is
  3410. * enabled, and the stack is notified that the interface is ready.
  3411. *
  3412. * Returns 0 on success, negative value on failure
  3413. **/
  3414. static int i40e_open(struct net_device *netdev)
  3415. {
  3416. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3417. struct i40e_vsi *vsi = np->vsi;
  3418. struct i40e_pf *pf = vsi->back;
  3419. char int_name[IFNAMSIZ];
  3420. int err;
  3421. /* disallow open during test */
  3422. if (test_bit(__I40E_TESTING, &pf->state))
  3423. return -EBUSY;
  3424. netif_carrier_off(netdev);
  3425. /* allocate descriptors */
  3426. err = i40e_vsi_setup_tx_resources(vsi);
  3427. if (err)
  3428. goto err_setup_tx;
  3429. err = i40e_vsi_setup_rx_resources(vsi);
  3430. if (err)
  3431. goto err_setup_rx;
  3432. err = i40e_vsi_configure(vsi);
  3433. if (err)
  3434. goto err_setup_rx;
  3435. snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
  3436. dev_driver_string(&pf->pdev->dev), netdev->name);
  3437. err = i40e_vsi_request_irq(vsi, int_name);
  3438. if (err)
  3439. goto err_setup_rx;
  3440. err = i40e_up_complete(vsi);
  3441. if (err)
  3442. goto err_up_complete;
  3443. if ((vsi->type == I40E_VSI_MAIN) || (vsi->type == I40E_VSI_VMDQ2)) {
  3444. err = i40e_aq_set_vsi_broadcast(&pf->hw, vsi->seid, true, NULL);
  3445. if (err)
  3446. netdev_info(netdev,
  3447. "couldn't set broadcast err %d aq_err %d\n",
  3448. err, pf->hw.aq.asq_last_status);
  3449. }
  3450. return 0;
  3451. err_up_complete:
  3452. i40e_down(vsi);
  3453. i40e_vsi_free_irq(vsi);
  3454. err_setup_rx:
  3455. i40e_vsi_free_rx_resources(vsi);
  3456. err_setup_tx:
  3457. i40e_vsi_free_tx_resources(vsi);
  3458. if (vsi == pf->vsi[pf->lan_vsi])
  3459. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  3460. return err;
  3461. }
  3462. /**
  3463. * i40e_close - Disables a network interface
  3464. * @netdev: network interface device structure
  3465. *
  3466. * The close entry point is called when an interface is de-activated
  3467. * by the OS. The hardware is still under the driver's control, but
  3468. * this netdev interface is disabled.
  3469. *
  3470. * Returns 0, this is not allowed to fail
  3471. **/
  3472. static int i40e_close(struct net_device *netdev)
  3473. {
  3474. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3475. struct i40e_vsi *vsi = np->vsi;
  3476. if (test_and_set_bit(__I40E_DOWN, &vsi->state))
  3477. return 0;
  3478. i40e_down(vsi);
  3479. i40e_vsi_free_irq(vsi);
  3480. i40e_vsi_free_tx_resources(vsi);
  3481. i40e_vsi_free_rx_resources(vsi);
  3482. return 0;
  3483. }
  3484. /**
  3485. * i40e_do_reset - Start a PF or Core Reset sequence
  3486. * @pf: board private structure
  3487. * @reset_flags: which reset is requested
  3488. *
  3489. * The essential difference in resets is that the PF Reset
  3490. * doesn't clear the packet buffers, doesn't reset the PE
  3491. * firmware, and doesn't bother the other PFs on the chip.
  3492. **/
  3493. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
  3494. {
  3495. u32 val;
  3496. WARN_ON(in_interrupt());
  3497. /* do the biggest reset indicated */
  3498. if (reset_flags & (1 << __I40E_GLOBAL_RESET_REQUESTED)) {
  3499. /* Request a Global Reset
  3500. *
  3501. * This will start the chip's countdown to the actual full
  3502. * chip reset event, and a warning interrupt to be sent
  3503. * to all PFs, including the requestor. Our handler
  3504. * for the warning interrupt will deal with the shutdown
  3505. * and recovery of the switch setup.
  3506. */
  3507. dev_info(&pf->pdev->dev, "GlobalR requested\n");
  3508. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  3509. val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
  3510. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  3511. } else if (reset_flags & (1 << __I40E_CORE_RESET_REQUESTED)) {
  3512. /* Request a Core Reset
  3513. *
  3514. * Same as Global Reset, except does *not* include the MAC/PHY
  3515. */
  3516. dev_info(&pf->pdev->dev, "CoreR requested\n");
  3517. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  3518. val |= I40E_GLGEN_RTRIG_CORER_MASK;
  3519. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  3520. i40e_flush(&pf->hw);
  3521. } else if (reset_flags & (1 << __I40E_PF_RESET_REQUESTED)) {
  3522. /* Request a PF Reset
  3523. *
  3524. * Resets only the PF-specific registers
  3525. *
  3526. * This goes directly to the tear-down and rebuild of
  3527. * the switch, since we need to do all the recovery as
  3528. * for the Core Reset.
  3529. */
  3530. dev_info(&pf->pdev->dev, "PFR requested\n");
  3531. i40e_handle_reset_warning(pf);
  3532. } else if (reset_flags & (1 << __I40E_REINIT_REQUESTED)) {
  3533. int v;
  3534. /* Find the VSI(s) that requested a re-init */
  3535. dev_info(&pf->pdev->dev,
  3536. "VSI reinit requested\n");
  3537. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  3538. struct i40e_vsi *vsi = pf->vsi[v];
  3539. if (vsi != NULL &&
  3540. test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
  3541. i40e_vsi_reinit_locked(pf->vsi[v]);
  3542. clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
  3543. }
  3544. }
  3545. /* no further action needed, so return now */
  3546. return;
  3547. } else {
  3548. dev_info(&pf->pdev->dev,
  3549. "bad reset request 0x%08x\n", reset_flags);
  3550. return;
  3551. }
  3552. }
  3553. /**
  3554. * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
  3555. * @pf: board private structure
  3556. * @e: event info posted on ARQ
  3557. *
  3558. * Handler for LAN Queue Overflow Event generated by the firmware for PF
  3559. * and VF queues
  3560. **/
  3561. static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
  3562. struct i40e_arq_event_info *e)
  3563. {
  3564. struct i40e_aqc_lan_overflow *data =
  3565. (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
  3566. u32 queue = le32_to_cpu(data->prtdcb_rupto);
  3567. u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
  3568. struct i40e_hw *hw = &pf->hw;
  3569. struct i40e_vf *vf;
  3570. u16 vf_id;
  3571. dev_info(&pf->pdev->dev, "%s: Rx Queue Number = %d QTX_CTL=0x%08x\n",
  3572. __func__, queue, qtx_ctl);
  3573. /* Queue belongs to VF, find the VF and issue VF reset */
  3574. if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
  3575. >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
  3576. vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
  3577. >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
  3578. vf_id -= hw->func_caps.vf_base_id;
  3579. vf = &pf->vf[vf_id];
  3580. i40e_vc_notify_vf_reset(vf);
  3581. /* Allow VF to process pending reset notification */
  3582. msleep(20);
  3583. i40e_reset_vf(vf, false);
  3584. }
  3585. }
  3586. /**
  3587. * i40e_service_event_complete - Finish up the service event
  3588. * @pf: board private structure
  3589. **/
  3590. static void i40e_service_event_complete(struct i40e_pf *pf)
  3591. {
  3592. BUG_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state));
  3593. /* flush memory to make sure state is correct before next watchog */
  3594. smp_mb__before_clear_bit();
  3595. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  3596. }
  3597. /**
  3598. * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
  3599. * @pf: board private structure
  3600. **/
  3601. static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
  3602. {
  3603. if (!(pf->flags & I40E_FLAG_FDIR_REQUIRES_REINIT))
  3604. return;
  3605. pf->flags &= ~I40E_FLAG_FDIR_REQUIRES_REINIT;
  3606. /* if interface is down do nothing */
  3607. if (test_bit(__I40E_DOWN, &pf->state))
  3608. return;
  3609. }
  3610. /**
  3611. * i40e_vsi_link_event - notify VSI of a link event
  3612. * @vsi: vsi to be notified
  3613. * @link_up: link up or down
  3614. **/
  3615. static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
  3616. {
  3617. if (!vsi)
  3618. return;
  3619. switch (vsi->type) {
  3620. case I40E_VSI_MAIN:
  3621. if (!vsi->netdev || !vsi->netdev_registered)
  3622. break;
  3623. if (link_up) {
  3624. netif_carrier_on(vsi->netdev);
  3625. netif_tx_wake_all_queues(vsi->netdev);
  3626. } else {
  3627. netif_carrier_off(vsi->netdev);
  3628. netif_tx_stop_all_queues(vsi->netdev);
  3629. }
  3630. break;
  3631. case I40E_VSI_SRIOV:
  3632. break;
  3633. case I40E_VSI_VMDQ2:
  3634. case I40E_VSI_CTRL:
  3635. case I40E_VSI_MIRROR:
  3636. default:
  3637. /* there is no notification for other VSIs */
  3638. break;
  3639. }
  3640. }
  3641. /**
  3642. * i40e_veb_link_event - notify elements on the veb of a link event
  3643. * @veb: veb to be notified
  3644. * @link_up: link up or down
  3645. **/
  3646. static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
  3647. {
  3648. struct i40e_pf *pf;
  3649. int i;
  3650. if (!veb || !veb->pf)
  3651. return;
  3652. pf = veb->pf;
  3653. /* depth first... */
  3654. for (i = 0; i < I40E_MAX_VEB; i++)
  3655. if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
  3656. i40e_veb_link_event(pf->veb[i], link_up);
  3657. /* ... now the local VSIs */
  3658. for (i = 0; i < pf->hw.func_caps.num_vsis; i++)
  3659. if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
  3660. i40e_vsi_link_event(pf->vsi[i], link_up);
  3661. }
  3662. /**
  3663. * i40e_link_event - Update netif_carrier status
  3664. * @pf: board private structure
  3665. **/
  3666. static void i40e_link_event(struct i40e_pf *pf)
  3667. {
  3668. bool new_link, old_link;
  3669. new_link = (pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP);
  3670. old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
  3671. if (new_link == old_link)
  3672. return;
  3673. if (!test_bit(__I40E_DOWN, &pf->vsi[pf->lan_vsi]->state))
  3674. netdev_info(pf->vsi[pf->lan_vsi]->netdev,
  3675. "NIC Link is %s\n", (new_link ? "Up" : "Down"));
  3676. /* Notify the base of the switch tree connected to
  3677. * the link. Floating VEBs are not notified.
  3678. */
  3679. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  3680. i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
  3681. else
  3682. i40e_vsi_link_event(pf->vsi[pf->lan_vsi], new_link);
  3683. if (pf->vf)
  3684. i40e_vc_notify_link_state(pf);
  3685. }
  3686. /**
  3687. * i40e_check_hang_subtask - Check for hung queues and dropped interrupts
  3688. * @pf: board private structure
  3689. *
  3690. * Set the per-queue flags to request a check for stuck queues in the irq
  3691. * clean functions, then force interrupts to be sure the irq clean is called.
  3692. **/
  3693. static void i40e_check_hang_subtask(struct i40e_pf *pf)
  3694. {
  3695. int i, v;
  3696. /* If we're down or resetting, just bail */
  3697. if (test_bit(__I40E_CONFIG_BUSY, &pf->state))
  3698. return;
  3699. /* for each VSI/netdev
  3700. * for each Tx queue
  3701. * set the check flag
  3702. * for each q_vector
  3703. * force an interrupt
  3704. */
  3705. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  3706. struct i40e_vsi *vsi = pf->vsi[v];
  3707. int armed = 0;
  3708. if (!pf->vsi[v] ||
  3709. test_bit(__I40E_DOWN, &vsi->state) ||
  3710. (vsi->netdev && !netif_carrier_ok(vsi->netdev)))
  3711. continue;
  3712. for (i = 0; i < vsi->num_queue_pairs; i++) {
  3713. set_check_for_tx_hang(vsi->tx_rings[i]);
  3714. if (test_bit(__I40E_HANG_CHECK_ARMED,
  3715. &vsi->tx_rings[i]->state))
  3716. armed++;
  3717. }
  3718. if (armed) {
  3719. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  3720. wr32(&vsi->back->hw, I40E_PFINT_DYN_CTL0,
  3721. (I40E_PFINT_DYN_CTL0_INTENA_MASK |
  3722. I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
  3723. } else {
  3724. u16 vec = vsi->base_vector - 1;
  3725. u32 val = (I40E_PFINT_DYN_CTLN_INTENA_MASK |
  3726. I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK);
  3727. for (i = 0; i < vsi->num_q_vectors; i++, vec++)
  3728. wr32(&vsi->back->hw,
  3729. I40E_PFINT_DYN_CTLN(vec), val);
  3730. }
  3731. i40e_flush(&vsi->back->hw);
  3732. }
  3733. }
  3734. }
  3735. /**
  3736. * i40e_watchdog_subtask - Check and bring link up
  3737. * @pf: board private structure
  3738. **/
  3739. static void i40e_watchdog_subtask(struct i40e_pf *pf)
  3740. {
  3741. int i;
  3742. /* if interface is down do nothing */
  3743. if (test_bit(__I40E_DOWN, &pf->state) ||
  3744. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  3745. return;
  3746. /* Update the stats for active netdevs so the network stack
  3747. * can look at updated numbers whenever it cares to
  3748. */
  3749. for (i = 0; i < pf->hw.func_caps.num_vsis; i++)
  3750. if (pf->vsi[i] && pf->vsi[i]->netdev)
  3751. i40e_update_stats(pf->vsi[i]);
  3752. /* Update the stats for the active switching components */
  3753. for (i = 0; i < I40E_MAX_VEB; i++)
  3754. if (pf->veb[i])
  3755. i40e_update_veb_stats(pf->veb[i]);
  3756. }
  3757. /**
  3758. * i40e_reset_subtask - Set up for resetting the device and driver
  3759. * @pf: board private structure
  3760. **/
  3761. static void i40e_reset_subtask(struct i40e_pf *pf)
  3762. {
  3763. u32 reset_flags = 0;
  3764. if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
  3765. reset_flags |= (1 << __I40E_REINIT_REQUESTED);
  3766. clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
  3767. }
  3768. if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
  3769. reset_flags |= (1 << __I40E_PF_RESET_REQUESTED);
  3770. clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  3771. }
  3772. if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
  3773. reset_flags |= (1 << __I40E_CORE_RESET_REQUESTED);
  3774. clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  3775. }
  3776. if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
  3777. reset_flags |= (1 << __I40E_GLOBAL_RESET_REQUESTED);
  3778. clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  3779. }
  3780. /* If there's a recovery already waiting, it takes
  3781. * precedence before starting a new reset sequence.
  3782. */
  3783. if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
  3784. i40e_handle_reset_warning(pf);
  3785. return;
  3786. }
  3787. /* If we're already down or resetting, just bail */
  3788. if (reset_flags &&
  3789. !test_bit(__I40E_DOWN, &pf->state) &&
  3790. !test_bit(__I40E_CONFIG_BUSY, &pf->state))
  3791. i40e_do_reset(pf, reset_flags);
  3792. }
  3793. /**
  3794. * i40e_handle_link_event - Handle link event
  3795. * @pf: board private structure
  3796. * @e: event info posted on ARQ
  3797. **/
  3798. static void i40e_handle_link_event(struct i40e_pf *pf,
  3799. struct i40e_arq_event_info *e)
  3800. {
  3801. struct i40e_hw *hw = &pf->hw;
  3802. struct i40e_aqc_get_link_status *status =
  3803. (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
  3804. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  3805. /* save off old link status information */
  3806. memcpy(&pf->hw.phy.link_info_old, hw_link_info,
  3807. sizeof(pf->hw.phy.link_info_old));
  3808. /* update link status */
  3809. hw_link_info->phy_type = (enum i40e_aq_phy_type)status->phy_type;
  3810. hw_link_info->link_speed = (enum i40e_aq_link_speed)status->link_speed;
  3811. hw_link_info->link_info = status->link_info;
  3812. hw_link_info->an_info = status->an_info;
  3813. hw_link_info->ext_info = status->ext_info;
  3814. hw_link_info->lse_enable =
  3815. le16_to_cpu(status->command_flags) &
  3816. I40E_AQ_LSE_ENABLE;
  3817. /* process the event */
  3818. i40e_link_event(pf);
  3819. /* Do a new status request to re-enable LSE reporting
  3820. * and load new status information into the hw struct,
  3821. * then see if the status changed while processing the
  3822. * initial event.
  3823. */
  3824. i40e_aq_get_link_info(&pf->hw, true, NULL, NULL);
  3825. i40e_link_event(pf);
  3826. }
  3827. /**
  3828. * i40e_clean_adminq_subtask - Clean the AdminQ rings
  3829. * @pf: board private structure
  3830. **/
  3831. static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
  3832. {
  3833. struct i40e_arq_event_info event;
  3834. struct i40e_hw *hw = &pf->hw;
  3835. u16 pending, i = 0;
  3836. i40e_status ret;
  3837. u16 opcode;
  3838. u32 val;
  3839. if (!test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state))
  3840. return;
  3841. event.msg_size = I40E_MAX_AQ_BUF_SIZE;
  3842. event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
  3843. if (!event.msg_buf)
  3844. return;
  3845. do {
  3846. ret = i40e_clean_arq_element(hw, &event, &pending);
  3847. if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
  3848. dev_info(&pf->pdev->dev, "No ARQ event found\n");
  3849. break;
  3850. } else if (ret) {
  3851. dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
  3852. break;
  3853. }
  3854. opcode = le16_to_cpu(event.desc.opcode);
  3855. switch (opcode) {
  3856. case i40e_aqc_opc_get_link_status:
  3857. i40e_handle_link_event(pf, &event);
  3858. break;
  3859. case i40e_aqc_opc_send_msg_to_pf:
  3860. ret = i40e_vc_process_vf_msg(pf,
  3861. le16_to_cpu(event.desc.retval),
  3862. le32_to_cpu(event.desc.cookie_high),
  3863. le32_to_cpu(event.desc.cookie_low),
  3864. event.msg_buf,
  3865. event.msg_size);
  3866. break;
  3867. case i40e_aqc_opc_lldp_update_mib:
  3868. dev_info(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
  3869. break;
  3870. case i40e_aqc_opc_event_lan_overflow:
  3871. dev_info(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
  3872. i40e_handle_lan_overflow_event(pf, &event);
  3873. break;
  3874. default:
  3875. dev_info(&pf->pdev->dev,
  3876. "ARQ Error: Unknown event %d received\n",
  3877. event.desc.opcode);
  3878. break;
  3879. }
  3880. } while (pending && (i++ < pf->adminq_work_limit));
  3881. clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  3882. /* re-enable Admin queue interrupt cause */
  3883. val = rd32(hw, I40E_PFINT_ICR0_ENA);
  3884. val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3885. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  3886. i40e_flush(hw);
  3887. kfree(event.msg_buf);
  3888. }
  3889. /**
  3890. * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
  3891. * @veb: pointer to the VEB instance
  3892. *
  3893. * This is a recursive function that first builds the attached VSIs then
  3894. * recurses in to build the next layer of VEB. We track the connections
  3895. * through our own index numbers because the seid's from the HW could
  3896. * change across the reset.
  3897. **/
  3898. static int i40e_reconstitute_veb(struct i40e_veb *veb)
  3899. {
  3900. struct i40e_vsi *ctl_vsi = NULL;
  3901. struct i40e_pf *pf = veb->pf;
  3902. int v, veb_idx;
  3903. int ret;
  3904. /* build VSI that owns this VEB, temporarily attached to base VEB */
  3905. for (v = 0; v < pf->hw.func_caps.num_vsis && !ctl_vsi; v++) {
  3906. if (pf->vsi[v] &&
  3907. pf->vsi[v]->veb_idx == veb->idx &&
  3908. pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
  3909. ctl_vsi = pf->vsi[v];
  3910. break;
  3911. }
  3912. }
  3913. if (!ctl_vsi) {
  3914. dev_info(&pf->pdev->dev,
  3915. "missing owner VSI for veb_idx %d\n", veb->idx);
  3916. ret = -ENOENT;
  3917. goto end_reconstitute;
  3918. }
  3919. if (ctl_vsi != pf->vsi[pf->lan_vsi])
  3920. ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  3921. ret = i40e_add_vsi(ctl_vsi);
  3922. if (ret) {
  3923. dev_info(&pf->pdev->dev,
  3924. "rebuild of owner VSI failed: %d\n", ret);
  3925. goto end_reconstitute;
  3926. }
  3927. i40e_vsi_reset_stats(ctl_vsi);
  3928. /* create the VEB in the switch and move the VSI onto the VEB */
  3929. ret = i40e_add_veb(veb, ctl_vsi);
  3930. if (ret)
  3931. goto end_reconstitute;
  3932. /* create the remaining VSIs attached to this VEB */
  3933. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  3934. if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
  3935. continue;
  3936. if (pf->vsi[v]->veb_idx == veb->idx) {
  3937. struct i40e_vsi *vsi = pf->vsi[v];
  3938. vsi->uplink_seid = veb->seid;
  3939. ret = i40e_add_vsi(vsi);
  3940. if (ret) {
  3941. dev_info(&pf->pdev->dev,
  3942. "rebuild of vsi_idx %d failed: %d\n",
  3943. v, ret);
  3944. goto end_reconstitute;
  3945. }
  3946. i40e_vsi_reset_stats(vsi);
  3947. }
  3948. }
  3949. /* create any VEBs attached to this VEB - RECURSION */
  3950. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  3951. if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
  3952. pf->veb[veb_idx]->uplink_seid = veb->seid;
  3953. ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
  3954. if (ret)
  3955. break;
  3956. }
  3957. }
  3958. end_reconstitute:
  3959. return ret;
  3960. }
  3961. /**
  3962. * i40e_get_capabilities - get info about the HW
  3963. * @pf: the PF struct
  3964. **/
  3965. static int i40e_get_capabilities(struct i40e_pf *pf)
  3966. {
  3967. struct i40e_aqc_list_capabilities_element_resp *cap_buf;
  3968. u16 data_size;
  3969. int buf_len;
  3970. int err;
  3971. buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
  3972. do {
  3973. cap_buf = kzalloc(buf_len, GFP_KERNEL);
  3974. if (!cap_buf)
  3975. return -ENOMEM;
  3976. /* this loads the data into the hw struct for us */
  3977. err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
  3978. &data_size,
  3979. i40e_aqc_opc_list_func_capabilities,
  3980. NULL);
  3981. /* data loaded, buffer no longer needed */
  3982. kfree(cap_buf);
  3983. if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
  3984. /* retry with a larger buffer */
  3985. buf_len = data_size;
  3986. } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
  3987. dev_info(&pf->pdev->dev,
  3988. "capability discovery failed: aq=%d\n",
  3989. pf->hw.aq.asq_last_status);
  3990. return -ENODEV;
  3991. }
  3992. } while (err);
  3993. if (pf->hw.debug_mask & I40E_DEBUG_USER)
  3994. dev_info(&pf->pdev->dev,
  3995. "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",
  3996. pf->hw.pf_id, pf->hw.func_caps.num_vfs,
  3997. pf->hw.func_caps.num_msix_vectors,
  3998. pf->hw.func_caps.num_msix_vectors_vf,
  3999. pf->hw.func_caps.fd_filters_guaranteed,
  4000. pf->hw.func_caps.fd_filters_best_effort,
  4001. pf->hw.func_caps.num_tx_qp,
  4002. pf->hw.func_caps.num_vsis);
  4003. return 0;
  4004. }
  4005. /**
  4006. * i40e_fdir_setup - initialize the Flow Director resources
  4007. * @pf: board private structure
  4008. **/
  4009. static void i40e_fdir_setup(struct i40e_pf *pf)
  4010. {
  4011. struct i40e_vsi *vsi;
  4012. bool new_vsi = false;
  4013. int err, i;
  4014. if (!(pf->flags & (I40E_FLAG_FDIR_ENABLED |
  4015. I40E_FLAG_FDIR_ATR_ENABLED)))
  4016. return;
  4017. pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
  4018. /* find existing or make new FDIR VSI */
  4019. vsi = NULL;
  4020. for (i = 0; i < pf->hw.func_caps.num_vsis; i++)
  4021. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR)
  4022. vsi = pf->vsi[i];
  4023. if (!vsi) {
  4024. vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, pf->mac_seid, 0);
  4025. if (!vsi) {
  4026. dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
  4027. pf->flags &= ~I40E_FLAG_FDIR_ENABLED;
  4028. return;
  4029. }
  4030. new_vsi = true;
  4031. }
  4032. WARN_ON(vsi->base_queue != I40E_FDIR_RING);
  4033. i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_rings);
  4034. err = i40e_vsi_setup_tx_resources(vsi);
  4035. if (!err)
  4036. err = i40e_vsi_setup_rx_resources(vsi);
  4037. if (!err)
  4038. err = i40e_vsi_configure(vsi);
  4039. if (!err && new_vsi) {
  4040. char int_name[IFNAMSIZ + 9];
  4041. snprintf(int_name, sizeof(int_name) - 1, "%s-fdir",
  4042. dev_driver_string(&pf->pdev->dev));
  4043. err = i40e_vsi_request_irq(vsi, int_name);
  4044. }
  4045. if (!err)
  4046. err = i40e_up_complete(vsi);
  4047. clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
  4048. }
  4049. /**
  4050. * i40e_fdir_teardown - release the Flow Director resources
  4051. * @pf: board private structure
  4052. **/
  4053. static void i40e_fdir_teardown(struct i40e_pf *pf)
  4054. {
  4055. int i;
  4056. for (i = 0; i < pf->hw.func_caps.num_vsis; i++) {
  4057. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  4058. i40e_vsi_release(pf->vsi[i]);
  4059. break;
  4060. }
  4061. }
  4062. }
  4063. /**
  4064. * i40e_handle_reset_warning - prep for the core to reset
  4065. * @pf: board private structure
  4066. *
  4067. * Close up the VFs and other things in prep for a Core Reset,
  4068. * then get ready to rebuild the world.
  4069. **/
  4070. static void i40e_handle_reset_warning(struct i40e_pf *pf)
  4071. {
  4072. struct i40e_driver_version dv;
  4073. struct i40e_hw *hw = &pf->hw;
  4074. i40e_status ret;
  4075. u32 v;
  4076. clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  4077. if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  4078. return;
  4079. dev_info(&pf->pdev->dev, "Tearing down internal switch for reset\n");
  4080. i40e_vc_notify_reset(pf);
  4081. /* quiesce the VSIs and their queues that are not already DOWN */
  4082. i40e_pf_quiesce_all_vsi(pf);
  4083. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  4084. if (pf->vsi[v])
  4085. pf->vsi[v]->seid = 0;
  4086. }
  4087. i40e_shutdown_adminq(&pf->hw);
  4088. /* Now we wait for GRST to settle out.
  4089. * We don't have to delete the VEBs or VSIs from the hw switch
  4090. * because the reset will make them disappear.
  4091. */
  4092. ret = i40e_pf_reset(hw);
  4093. if (ret)
  4094. dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
  4095. pf->pfr_count++;
  4096. if (test_bit(__I40E_DOWN, &pf->state))
  4097. goto end_core_reset;
  4098. dev_info(&pf->pdev->dev, "Rebuilding internal switch\n");
  4099. /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
  4100. ret = i40e_init_adminq(&pf->hw);
  4101. if (ret) {
  4102. dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, %d\n", ret);
  4103. goto end_core_reset;
  4104. }
  4105. ret = i40e_get_capabilities(pf);
  4106. if (ret) {
  4107. dev_info(&pf->pdev->dev, "i40e_get_capabilities failed, %d\n",
  4108. ret);
  4109. goto end_core_reset;
  4110. }
  4111. /* call shutdown HMC */
  4112. ret = i40e_shutdown_lan_hmc(hw);
  4113. if (ret) {
  4114. dev_info(&pf->pdev->dev, "shutdown_lan_hmc failed: %d\n", ret);
  4115. goto end_core_reset;
  4116. }
  4117. ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  4118. hw->func_caps.num_rx_qp,
  4119. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  4120. if (ret) {
  4121. dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
  4122. goto end_core_reset;
  4123. }
  4124. ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  4125. if (ret) {
  4126. dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
  4127. goto end_core_reset;
  4128. }
  4129. /* do basic switch setup */
  4130. ret = i40e_setup_pf_switch(pf);
  4131. if (ret)
  4132. goto end_core_reset;
  4133. /* Rebuild the VSIs and VEBs that existed before reset.
  4134. * They are still in our local switch element arrays, so only
  4135. * need to rebuild the switch model in the HW.
  4136. *
  4137. * If there were VEBs but the reconstitution failed, we'll try
  4138. * try to recover minimal use by getting the basic PF VSI working.
  4139. */
  4140. if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
  4141. dev_info(&pf->pdev->dev, "attempting to rebuild switch\n");
  4142. /* find the one VEB connected to the MAC, and find orphans */
  4143. for (v = 0; v < I40E_MAX_VEB; v++) {
  4144. if (!pf->veb[v])
  4145. continue;
  4146. if (pf->veb[v]->uplink_seid == pf->mac_seid ||
  4147. pf->veb[v]->uplink_seid == 0) {
  4148. ret = i40e_reconstitute_veb(pf->veb[v]);
  4149. if (!ret)
  4150. continue;
  4151. /* If Main VEB failed, we're in deep doodoo,
  4152. * so give up rebuilding the switch and set up
  4153. * for minimal rebuild of PF VSI.
  4154. * If orphan failed, we'll report the error
  4155. * but try to keep going.
  4156. */
  4157. if (pf->veb[v]->uplink_seid == pf->mac_seid) {
  4158. dev_info(&pf->pdev->dev,
  4159. "rebuild of switch failed: %d, will try to set up simple PF connection\n",
  4160. ret);
  4161. pf->vsi[pf->lan_vsi]->uplink_seid
  4162. = pf->mac_seid;
  4163. break;
  4164. } else if (pf->veb[v]->uplink_seid == 0) {
  4165. dev_info(&pf->pdev->dev,
  4166. "rebuild of orphan VEB failed: %d\n",
  4167. ret);
  4168. }
  4169. }
  4170. }
  4171. }
  4172. if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
  4173. dev_info(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
  4174. /* no VEB, so rebuild only the Main VSI */
  4175. ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
  4176. if (ret) {
  4177. dev_info(&pf->pdev->dev,
  4178. "rebuild of Main VSI failed: %d\n", ret);
  4179. goto end_core_reset;
  4180. }
  4181. }
  4182. /* reinit the misc interrupt */
  4183. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  4184. ret = i40e_setup_misc_vector(pf);
  4185. /* restart the VSIs that were rebuilt and running before the reset */
  4186. i40e_pf_unquiesce_all_vsi(pf);
  4187. /* tell the firmware that we're starting */
  4188. dv.major_version = DRV_VERSION_MAJOR;
  4189. dv.minor_version = DRV_VERSION_MINOR;
  4190. dv.build_version = DRV_VERSION_BUILD;
  4191. dv.subbuild_version = 0;
  4192. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  4193. dev_info(&pf->pdev->dev, "PF reset done\n");
  4194. end_core_reset:
  4195. clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
  4196. }
  4197. /**
  4198. * i40e_handle_mdd_event
  4199. * @pf: pointer to the pf structure
  4200. *
  4201. * Called from the MDD irq handler to identify possibly malicious vfs
  4202. **/
  4203. static void i40e_handle_mdd_event(struct i40e_pf *pf)
  4204. {
  4205. struct i40e_hw *hw = &pf->hw;
  4206. bool mdd_detected = false;
  4207. struct i40e_vf *vf;
  4208. u32 reg;
  4209. int i;
  4210. if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
  4211. return;
  4212. /* find what triggered the MDD event */
  4213. reg = rd32(hw, I40E_GL_MDET_TX);
  4214. if (reg & I40E_GL_MDET_TX_VALID_MASK) {
  4215. u8 func = (reg & I40E_GL_MDET_TX_FUNCTION_MASK)
  4216. >> I40E_GL_MDET_TX_FUNCTION_SHIFT;
  4217. u8 event = (reg & I40E_GL_MDET_TX_EVENT_SHIFT)
  4218. >> I40E_GL_MDET_TX_EVENT_SHIFT;
  4219. u8 queue = (reg & I40E_GL_MDET_TX_QUEUE_MASK)
  4220. >> I40E_GL_MDET_TX_QUEUE_SHIFT;
  4221. dev_info(&pf->pdev->dev,
  4222. "Malicious Driver Detection TX event 0x%02x on q %d of function 0x%02x\n",
  4223. event, queue, func);
  4224. wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
  4225. mdd_detected = true;
  4226. }
  4227. reg = rd32(hw, I40E_GL_MDET_RX);
  4228. if (reg & I40E_GL_MDET_RX_VALID_MASK) {
  4229. u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK)
  4230. >> I40E_GL_MDET_RX_FUNCTION_SHIFT;
  4231. u8 event = (reg & I40E_GL_MDET_RX_EVENT_SHIFT)
  4232. >> I40E_GL_MDET_RX_EVENT_SHIFT;
  4233. u8 queue = (reg & I40E_GL_MDET_RX_QUEUE_MASK)
  4234. >> I40E_GL_MDET_RX_QUEUE_SHIFT;
  4235. dev_info(&pf->pdev->dev,
  4236. "Malicious Driver Detection RX event 0x%02x on q %d of function 0x%02x\n",
  4237. event, queue, func);
  4238. wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
  4239. mdd_detected = true;
  4240. }
  4241. /* see if one of the VFs needs its hand slapped */
  4242. for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
  4243. vf = &(pf->vf[i]);
  4244. reg = rd32(hw, I40E_VP_MDET_TX(i));
  4245. if (reg & I40E_VP_MDET_TX_VALID_MASK) {
  4246. wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
  4247. vf->num_mdd_events++;
  4248. dev_info(&pf->pdev->dev, "MDD TX event on VF %d\n", i);
  4249. }
  4250. reg = rd32(hw, I40E_VP_MDET_RX(i));
  4251. if (reg & I40E_VP_MDET_RX_VALID_MASK) {
  4252. wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
  4253. vf->num_mdd_events++;
  4254. dev_info(&pf->pdev->dev, "MDD RX event on VF %d\n", i);
  4255. }
  4256. if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
  4257. dev_info(&pf->pdev->dev,
  4258. "Too many MDD events on VF %d, disabled\n", i);
  4259. dev_info(&pf->pdev->dev,
  4260. "Use PF Control I/F to re-enable the VF\n");
  4261. set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
  4262. }
  4263. }
  4264. /* re-enable mdd interrupt cause */
  4265. clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  4266. reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  4267. reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  4268. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  4269. i40e_flush(hw);
  4270. }
  4271. /**
  4272. * i40e_service_task - Run the driver's async subtasks
  4273. * @work: pointer to work_struct containing our data
  4274. **/
  4275. static void i40e_service_task(struct work_struct *work)
  4276. {
  4277. struct i40e_pf *pf = container_of(work,
  4278. struct i40e_pf,
  4279. service_task);
  4280. unsigned long start_time = jiffies;
  4281. i40e_reset_subtask(pf);
  4282. i40e_handle_mdd_event(pf);
  4283. i40e_vc_process_vflr_event(pf);
  4284. i40e_watchdog_subtask(pf);
  4285. i40e_fdir_reinit_subtask(pf);
  4286. i40e_check_hang_subtask(pf);
  4287. i40e_sync_filters_subtask(pf);
  4288. i40e_clean_adminq_subtask(pf);
  4289. i40e_service_event_complete(pf);
  4290. /* If the tasks have taken longer than one timer cycle or there
  4291. * is more work to be done, reschedule the service task now
  4292. * rather than wait for the timer to tick again.
  4293. */
  4294. if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
  4295. test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
  4296. test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
  4297. test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
  4298. i40e_service_event_schedule(pf);
  4299. }
  4300. /**
  4301. * i40e_service_timer - timer callback
  4302. * @data: pointer to PF struct
  4303. **/
  4304. static void i40e_service_timer(unsigned long data)
  4305. {
  4306. struct i40e_pf *pf = (struct i40e_pf *)data;
  4307. mod_timer(&pf->service_timer,
  4308. round_jiffies(jiffies + pf->service_timer_period));
  4309. i40e_service_event_schedule(pf);
  4310. }
  4311. /**
  4312. * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
  4313. * @vsi: the VSI being configured
  4314. **/
  4315. static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
  4316. {
  4317. struct i40e_pf *pf = vsi->back;
  4318. switch (vsi->type) {
  4319. case I40E_VSI_MAIN:
  4320. vsi->alloc_queue_pairs = pf->num_lan_qps;
  4321. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  4322. I40E_REQ_DESCRIPTOR_MULTIPLE);
  4323. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  4324. vsi->num_q_vectors = pf->num_lan_msix;
  4325. else
  4326. vsi->num_q_vectors = 1;
  4327. break;
  4328. case I40E_VSI_FDIR:
  4329. vsi->alloc_queue_pairs = 1;
  4330. vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
  4331. I40E_REQ_DESCRIPTOR_MULTIPLE);
  4332. vsi->num_q_vectors = 1;
  4333. break;
  4334. case I40E_VSI_VMDQ2:
  4335. vsi->alloc_queue_pairs = pf->num_vmdq_qps;
  4336. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  4337. I40E_REQ_DESCRIPTOR_MULTIPLE);
  4338. vsi->num_q_vectors = pf->num_vmdq_msix;
  4339. break;
  4340. case I40E_VSI_SRIOV:
  4341. vsi->alloc_queue_pairs = pf->num_vf_qps;
  4342. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  4343. I40E_REQ_DESCRIPTOR_MULTIPLE);
  4344. break;
  4345. default:
  4346. WARN_ON(1);
  4347. return -ENODATA;
  4348. }
  4349. return 0;
  4350. }
  4351. /**
  4352. * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
  4353. * @pf: board private structure
  4354. * @type: type of VSI
  4355. *
  4356. * On error: returns error code (negative)
  4357. * On success: returns vsi index in PF (positive)
  4358. **/
  4359. static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
  4360. {
  4361. int ret = -ENODEV;
  4362. struct i40e_vsi *vsi;
  4363. int sz_vectors;
  4364. int sz_rings;
  4365. int vsi_idx;
  4366. int i;
  4367. /* Need to protect the allocation of the VSIs at the PF level */
  4368. mutex_lock(&pf->switch_mutex);
  4369. /* VSI list may be fragmented if VSI creation/destruction has
  4370. * been happening. We can afford to do a quick scan to look
  4371. * for any free VSIs in the list.
  4372. *
  4373. * find next empty vsi slot, looping back around if necessary
  4374. */
  4375. i = pf->next_vsi;
  4376. while (i < pf->hw.func_caps.num_vsis && pf->vsi[i])
  4377. i++;
  4378. if (i >= pf->hw.func_caps.num_vsis) {
  4379. i = 0;
  4380. while (i < pf->next_vsi && pf->vsi[i])
  4381. i++;
  4382. }
  4383. if (i < pf->hw.func_caps.num_vsis && !pf->vsi[i]) {
  4384. vsi_idx = i; /* Found one! */
  4385. } else {
  4386. ret = -ENODEV;
  4387. goto unlock_pf; /* out of VSI slots! */
  4388. }
  4389. pf->next_vsi = ++i;
  4390. vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
  4391. if (!vsi) {
  4392. ret = -ENOMEM;
  4393. goto unlock_pf;
  4394. }
  4395. vsi->type = type;
  4396. vsi->back = pf;
  4397. set_bit(__I40E_DOWN, &vsi->state);
  4398. vsi->flags = 0;
  4399. vsi->idx = vsi_idx;
  4400. vsi->rx_itr_setting = pf->rx_itr_default;
  4401. vsi->tx_itr_setting = pf->tx_itr_default;
  4402. vsi->netdev_registered = false;
  4403. vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
  4404. INIT_LIST_HEAD(&vsi->mac_filter_list);
  4405. ret = i40e_set_num_rings_in_vsi(vsi);
  4406. if (ret)
  4407. goto err_rings;
  4408. /* allocate memory for ring pointers */
  4409. sz_rings = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
  4410. vsi->tx_rings = kzalloc(sz_rings, GFP_KERNEL);
  4411. if (!vsi->tx_rings) {
  4412. ret = -ENOMEM;
  4413. goto err_rings;
  4414. }
  4415. vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
  4416. /* allocate memory for q_vector pointers */
  4417. sz_vectors = sizeof(struct i40e_q_vectors *) * vsi->num_q_vectors;
  4418. vsi->q_vectors = kzalloc(sz_vectors, GFP_KERNEL);
  4419. if (!vsi->q_vectors) {
  4420. ret = -ENOMEM;
  4421. goto err_vectors;
  4422. }
  4423. /* Setup default MSIX irq handler for VSI */
  4424. i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
  4425. pf->vsi[vsi_idx] = vsi;
  4426. ret = vsi_idx;
  4427. goto unlock_pf;
  4428. err_vectors:
  4429. kfree(vsi->tx_rings);
  4430. err_rings:
  4431. pf->next_vsi = i - 1;
  4432. kfree(vsi);
  4433. unlock_pf:
  4434. mutex_unlock(&pf->switch_mutex);
  4435. return ret;
  4436. }
  4437. /**
  4438. * i40e_vsi_clear - Deallocate the VSI provided
  4439. * @vsi: the VSI being un-configured
  4440. **/
  4441. static int i40e_vsi_clear(struct i40e_vsi *vsi)
  4442. {
  4443. struct i40e_pf *pf;
  4444. if (!vsi)
  4445. return 0;
  4446. if (!vsi->back)
  4447. goto free_vsi;
  4448. pf = vsi->back;
  4449. mutex_lock(&pf->switch_mutex);
  4450. if (!pf->vsi[vsi->idx]) {
  4451. dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
  4452. vsi->idx, vsi->idx, vsi, vsi->type);
  4453. goto unlock_vsi;
  4454. }
  4455. if (pf->vsi[vsi->idx] != vsi) {
  4456. dev_err(&pf->pdev->dev,
  4457. "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
  4458. pf->vsi[vsi->idx]->idx,
  4459. pf->vsi[vsi->idx],
  4460. pf->vsi[vsi->idx]->type,
  4461. vsi->idx, vsi, vsi->type);
  4462. goto unlock_vsi;
  4463. }
  4464. /* updates the pf for this cleared vsi */
  4465. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  4466. i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
  4467. /* free the ring and vector containers */
  4468. kfree(vsi->q_vectors);
  4469. kfree(vsi->tx_rings);
  4470. pf->vsi[vsi->idx] = NULL;
  4471. if (vsi->idx < pf->next_vsi)
  4472. pf->next_vsi = vsi->idx;
  4473. unlock_vsi:
  4474. mutex_unlock(&pf->switch_mutex);
  4475. free_vsi:
  4476. kfree(vsi);
  4477. return 0;
  4478. }
  4479. /**
  4480. * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
  4481. * @vsi: the VSI being cleaned
  4482. **/
  4483. static s32 i40e_vsi_clear_rings(struct i40e_vsi *vsi)
  4484. {
  4485. int i;
  4486. if (vsi->tx_rings[0])
  4487. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  4488. kfree_rcu(vsi->tx_rings[i], rcu);
  4489. vsi->tx_rings[i] = NULL;
  4490. vsi->rx_rings[i] = NULL;
  4491. }
  4492. return 0;
  4493. }
  4494. /**
  4495. * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
  4496. * @vsi: the VSI being configured
  4497. **/
  4498. static int i40e_alloc_rings(struct i40e_vsi *vsi)
  4499. {
  4500. struct i40e_pf *pf = vsi->back;
  4501. int i;
  4502. /* Set basic values in the rings to be used later during open() */
  4503. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  4504. struct i40e_ring *tx_ring;
  4505. struct i40e_ring *rx_ring;
  4506. tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
  4507. if (!tx_ring)
  4508. goto err_out;
  4509. tx_ring->queue_index = i;
  4510. tx_ring->reg_idx = vsi->base_queue + i;
  4511. tx_ring->ring_active = false;
  4512. tx_ring->vsi = vsi;
  4513. tx_ring->netdev = vsi->netdev;
  4514. tx_ring->dev = &pf->pdev->dev;
  4515. tx_ring->count = vsi->num_desc;
  4516. tx_ring->size = 0;
  4517. tx_ring->dcb_tc = 0;
  4518. vsi->tx_rings[i] = tx_ring;
  4519. rx_ring = &tx_ring[1];
  4520. rx_ring->queue_index = i;
  4521. rx_ring->reg_idx = vsi->base_queue + i;
  4522. rx_ring->ring_active = false;
  4523. rx_ring->vsi = vsi;
  4524. rx_ring->netdev = vsi->netdev;
  4525. rx_ring->dev = &pf->pdev->dev;
  4526. rx_ring->count = vsi->num_desc;
  4527. rx_ring->size = 0;
  4528. rx_ring->dcb_tc = 0;
  4529. if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED)
  4530. set_ring_16byte_desc_enabled(rx_ring);
  4531. else
  4532. clear_ring_16byte_desc_enabled(rx_ring);
  4533. vsi->rx_rings[i] = rx_ring;
  4534. }
  4535. return 0;
  4536. err_out:
  4537. i40e_vsi_clear_rings(vsi);
  4538. return -ENOMEM;
  4539. }
  4540. /**
  4541. * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
  4542. * @pf: board private structure
  4543. * @vectors: the number of MSI-X vectors to request
  4544. *
  4545. * Returns the number of vectors reserved, or error
  4546. **/
  4547. static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
  4548. {
  4549. int err = 0;
  4550. pf->num_msix_entries = 0;
  4551. while (vectors >= I40E_MIN_MSIX) {
  4552. err = pci_enable_msix(pf->pdev, pf->msix_entries, vectors);
  4553. if (err == 0) {
  4554. /* good to go */
  4555. pf->num_msix_entries = vectors;
  4556. break;
  4557. } else if (err < 0) {
  4558. /* total failure */
  4559. dev_info(&pf->pdev->dev,
  4560. "MSI-X vector reservation failed: %d\n", err);
  4561. vectors = 0;
  4562. break;
  4563. } else {
  4564. /* err > 0 is the hint for retry */
  4565. dev_info(&pf->pdev->dev,
  4566. "MSI-X vectors wanted %d, retrying with %d\n",
  4567. vectors, err);
  4568. vectors = err;
  4569. }
  4570. }
  4571. if (vectors > 0 && vectors < I40E_MIN_MSIX) {
  4572. dev_info(&pf->pdev->dev,
  4573. "Couldn't get enough vectors, only %d available\n",
  4574. vectors);
  4575. vectors = 0;
  4576. }
  4577. return vectors;
  4578. }
  4579. /**
  4580. * i40e_init_msix - Setup the MSIX capability
  4581. * @pf: board private structure
  4582. *
  4583. * Work with the OS to set up the MSIX vectors needed.
  4584. *
  4585. * Returns 0 on success, negative on failure
  4586. **/
  4587. static int i40e_init_msix(struct i40e_pf *pf)
  4588. {
  4589. i40e_status err = 0;
  4590. struct i40e_hw *hw = &pf->hw;
  4591. int v_budget, i;
  4592. int vec;
  4593. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  4594. return -ENODEV;
  4595. /* The number of vectors we'll request will be comprised of:
  4596. * - Add 1 for "other" cause for Admin Queue events, etc.
  4597. * - The number of LAN queue pairs
  4598. * already adjusted for the NUMA node
  4599. * assumes symmetric Tx/Rx pairing
  4600. * - The number of VMDq pairs
  4601. * Once we count this up, try the request.
  4602. *
  4603. * If we can't get what we want, we'll simplify to nearly nothing
  4604. * and try again. If that still fails, we punt.
  4605. */
  4606. pf->num_lan_msix = pf->num_lan_qps;
  4607. pf->num_vmdq_msix = pf->num_vmdq_qps;
  4608. v_budget = 1 + pf->num_lan_msix;
  4609. v_budget += (pf->num_vmdq_vsis * pf->num_vmdq_msix);
  4610. if (pf->flags & I40E_FLAG_FDIR_ENABLED)
  4611. v_budget++;
  4612. /* Scale down if necessary, and the rings will share vectors */
  4613. v_budget = min_t(int, v_budget, hw->func_caps.num_msix_vectors);
  4614. pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
  4615. GFP_KERNEL);
  4616. if (!pf->msix_entries)
  4617. return -ENOMEM;
  4618. for (i = 0; i < v_budget; i++)
  4619. pf->msix_entries[i].entry = i;
  4620. vec = i40e_reserve_msix_vectors(pf, v_budget);
  4621. if (vec < I40E_MIN_MSIX) {
  4622. pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
  4623. kfree(pf->msix_entries);
  4624. pf->msix_entries = NULL;
  4625. return -ENODEV;
  4626. } else if (vec == I40E_MIN_MSIX) {
  4627. /* Adjust for minimal MSIX use */
  4628. dev_info(&pf->pdev->dev, "Features disabled, not enough MSIX vectors\n");
  4629. pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
  4630. pf->num_vmdq_vsis = 0;
  4631. pf->num_vmdq_qps = 0;
  4632. pf->num_vmdq_msix = 0;
  4633. pf->num_lan_qps = 1;
  4634. pf->num_lan_msix = 1;
  4635. } else if (vec != v_budget) {
  4636. /* Scale vector usage down */
  4637. pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
  4638. vec--; /* reserve the misc vector */
  4639. /* partition out the remaining vectors */
  4640. switch (vec) {
  4641. case 2:
  4642. pf->num_vmdq_vsis = 1;
  4643. pf->num_lan_msix = 1;
  4644. break;
  4645. case 3:
  4646. pf->num_vmdq_vsis = 1;
  4647. pf->num_lan_msix = 2;
  4648. break;
  4649. default:
  4650. pf->num_lan_msix = min_t(int, (vec / 2),
  4651. pf->num_lan_qps);
  4652. pf->num_vmdq_vsis = min_t(int, (vec - pf->num_lan_msix),
  4653. I40E_DEFAULT_NUM_VMDQ_VSI);
  4654. break;
  4655. }
  4656. }
  4657. return err;
  4658. }
  4659. /**
  4660. * i40e_alloc_q_vector - Allocate memory for a single interrupt vector
  4661. * @vsi: the VSI being configured
  4662. * @v_idx: index of the vector in the vsi struct
  4663. *
  4664. * We allocate one q_vector. If allocation fails we return -ENOMEM.
  4665. **/
  4666. static int i40e_alloc_q_vector(struct i40e_vsi *vsi, int v_idx)
  4667. {
  4668. struct i40e_q_vector *q_vector;
  4669. /* allocate q_vector */
  4670. q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
  4671. if (!q_vector)
  4672. return -ENOMEM;
  4673. q_vector->vsi = vsi;
  4674. q_vector->v_idx = v_idx;
  4675. cpumask_set_cpu(v_idx, &q_vector->affinity_mask);
  4676. if (vsi->netdev)
  4677. netif_napi_add(vsi->netdev, &q_vector->napi,
  4678. i40e_napi_poll, vsi->work_limit);
  4679. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  4680. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  4681. /* tie q_vector and vsi together */
  4682. vsi->q_vectors[v_idx] = q_vector;
  4683. return 0;
  4684. }
  4685. /**
  4686. * i40e_alloc_q_vectors - Allocate memory for interrupt vectors
  4687. * @vsi: the VSI being configured
  4688. *
  4689. * We allocate one q_vector per queue interrupt. If allocation fails we
  4690. * return -ENOMEM.
  4691. **/
  4692. static int i40e_alloc_q_vectors(struct i40e_vsi *vsi)
  4693. {
  4694. struct i40e_pf *pf = vsi->back;
  4695. int v_idx, num_q_vectors;
  4696. int err;
  4697. /* if not MSIX, give the one vector only to the LAN VSI */
  4698. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  4699. num_q_vectors = vsi->num_q_vectors;
  4700. else if (vsi == pf->vsi[pf->lan_vsi])
  4701. num_q_vectors = 1;
  4702. else
  4703. return -EINVAL;
  4704. for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
  4705. err = i40e_alloc_q_vector(vsi, v_idx);
  4706. if (err)
  4707. goto err_out;
  4708. }
  4709. return 0;
  4710. err_out:
  4711. while (v_idx--)
  4712. i40e_free_q_vector(vsi, v_idx);
  4713. return err;
  4714. }
  4715. /**
  4716. * i40e_init_interrupt_scheme - Determine proper interrupt scheme
  4717. * @pf: board private structure to initialize
  4718. **/
  4719. static void i40e_init_interrupt_scheme(struct i40e_pf *pf)
  4720. {
  4721. int err = 0;
  4722. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  4723. err = i40e_init_msix(pf);
  4724. if (err) {
  4725. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
  4726. I40E_FLAG_RSS_ENABLED |
  4727. I40E_FLAG_MQ_ENABLED |
  4728. I40E_FLAG_DCB_ENABLED |
  4729. I40E_FLAG_SRIOV_ENABLED |
  4730. I40E_FLAG_FDIR_ENABLED |
  4731. I40E_FLAG_FDIR_ATR_ENABLED |
  4732. I40E_FLAG_VMDQ_ENABLED);
  4733. /* rework the queue expectations without MSIX */
  4734. i40e_determine_queue_usage(pf);
  4735. }
  4736. }
  4737. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  4738. (pf->flags & I40E_FLAG_MSI_ENABLED)) {
  4739. dev_info(&pf->pdev->dev, "MSIX not available, trying MSI\n");
  4740. err = pci_enable_msi(pf->pdev);
  4741. if (err) {
  4742. dev_info(&pf->pdev->dev, "MSI init failed - %d\n", err);
  4743. pf->flags &= ~I40E_FLAG_MSI_ENABLED;
  4744. }
  4745. }
  4746. if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
  4747. dev_info(&pf->pdev->dev, "MSIX and MSI not available, falling back to Legacy IRQ\n");
  4748. /* track first vector for misc interrupts */
  4749. err = i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT-1);
  4750. }
  4751. /**
  4752. * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
  4753. * @pf: board private structure
  4754. *
  4755. * This sets up the handler for MSIX 0, which is used to manage the
  4756. * non-queue interrupts, e.g. AdminQ and errors. This is not used
  4757. * when in MSI or Legacy interrupt mode.
  4758. **/
  4759. static int i40e_setup_misc_vector(struct i40e_pf *pf)
  4760. {
  4761. struct i40e_hw *hw = &pf->hw;
  4762. int err = 0;
  4763. /* Only request the irq if this is the first time through, and
  4764. * not when we're rebuilding after a Reset
  4765. */
  4766. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
  4767. err = request_irq(pf->msix_entries[0].vector,
  4768. i40e_intr, 0, pf->misc_int_name, pf);
  4769. if (err) {
  4770. dev_info(&pf->pdev->dev,
  4771. "request_irq for msix_misc failed: %d\n", err);
  4772. return -EFAULT;
  4773. }
  4774. }
  4775. i40e_enable_misc_int_causes(hw);
  4776. /* associate no queues to the misc vector */
  4777. wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
  4778. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
  4779. i40e_flush(hw);
  4780. i40e_irq_dynamic_enable_icr0(pf);
  4781. return err;
  4782. }
  4783. /**
  4784. * i40e_config_rss - Prepare for RSS if used
  4785. * @pf: board private structure
  4786. **/
  4787. static int i40e_config_rss(struct i40e_pf *pf)
  4788. {
  4789. struct i40e_hw *hw = &pf->hw;
  4790. u32 lut = 0;
  4791. int i, j;
  4792. u64 hena;
  4793. /* Set of random keys generated using kernel random number generator */
  4794. static const u32 seed[I40E_PFQF_HKEY_MAX_INDEX + 1] = {0x41b01687,
  4795. 0x183cfd8c, 0xce880440, 0x580cbc3c, 0x35897377,
  4796. 0x328b25e1, 0x4fa98922, 0xb7d90c14, 0xd5bad70d,
  4797. 0xcd15a2c1, 0xe8580225, 0x4a1e9d11, 0xfe5731be};
  4798. /* Fill out hash function seed */
  4799. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  4800. wr32(hw, I40E_PFQF_HKEY(i), seed[i]);
  4801. /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
  4802. hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
  4803. ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
  4804. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  4805. ((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
  4806. ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
  4807. ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP) |
  4808. ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP) |
  4809. ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  4810. ((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
  4811. ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
  4812. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4)|
  4813. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
  4814. wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
  4815. wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  4816. /* Populate the LUT with max no. of queues in round robin fashion */
  4817. for (i = 0, j = 0; i < pf->hw.func_caps.rss_table_size; i++, j++) {
  4818. /* The assumption is that lan qp count will be the highest
  4819. * qp count for any PF VSI that needs RSS.
  4820. * If multiple VSIs need RSS support, all the qp counts
  4821. * for those VSIs should be a power of 2 for RSS to work.
  4822. * If LAN VSI is the only consumer for RSS then this requirement
  4823. * is not necessary.
  4824. */
  4825. if (j == pf->rss_size)
  4826. j = 0;
  4827. /* lut = 4-byte sliding window of 4 lut entries */
  4828. lut = (lut << 8) | (j &
  4829. ((0x1 << pf->hw.func_caps.rss_table_entry_width) - 1));
  4830. /* On i = 3, we have 4 entries in lut; write to the register */
  4831. if ((i & 3) == 3)
  4832. wr32(hw, I40E_PFQF_HLUT(i >> 2), lut);
  4833. }
  4834. i40e_flush(hw);
  4835. return 0;
  4836. }
  4837. /**
  4838. * i40e_sw_init - Initialize general software structures (struct i40e_pf)
  4839. * @pf: board private structure to initialize
  4840. *
  4841. * i40e_sw_init initializes the Adapter private data structure.
  4842. * Fields are initialized based on PCI device information and
  4843. * OS network device settings (MTU size).
  4844. **/
  4845. static int i40e_sw_init(struct i40e_pf *pf)
  4846. {
  4847. int err = 0;
  4848. int size;
  4849. pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE,
  4850. (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK));
  4851. if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) {
  4852. if (I40E_DEBUG_USER & debug)
  4853. pf->hw.debug_mask = debug;
  4854. pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER),
  4855. I40E_DEFAULT_MSG_ENABLE);
  4856. }
  4857. /* Set default capability flags */
  4858. pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
  4859. I40E_FLAG_MSI_ENABLED |
  4860. I40E_FLAG_MSIX_ENABLED |
  4861. I40E_FLAG_RX_PS_ENABLED |
  4862. I40E_FLAG_MQ_ENABLED |
  4863. I40E_FLAG_RX_1BUF_ENABLED;
  4864. pf->rss_size_max = 0x1 << pf->hw.func_caps.rss_table_entry_width;
  4865. if (pf->hw.func_caps.rss) {
  4866. pf->flags |= I40E_FLAG_RSS_ENABLED;
  4867. pf->rss_size = min_t(int, pf->rss_size_max,
  4868. nr_cpus_node(numa_node_id()));
  4869. } else {
  4870. pf->rss_size = 1;
  4871. }
  4872. if (pf->hw.func_caps.dcb)
  4873. pf->num_tc_qps = I40E_DEFAULT_QUEUES_PER_TC;
  4874. else
  4875. pf->num_tc_qps = 0;
  4876. if (pf->hw.func_caps.fd) {
  4877. /* FW/NVM is not yet fixed in this regard */
  4878. if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
  4879. (pf->hw.func_caps.fd_filters_best_effort > 0)) {
  4880. pf->flags |= I40E_FLAG_FDIR_ATR_ENABLED;
  4881. dev_info(&pf->pdev->dev,
  4882. "Flow Director ATR mode Enabled\n");
  4883. pf->flags |= I40E_FLAG_FDIR_ENABLED;
  4884. dev_info(&pf->pdev->dev,
  4885. "Flow Director Side Band mode Enabled\n");
  4886. pf->fdir_pf_filter_count =
  4887. pf->hw.func_caps.fd_filters_guaranteed;
  4888. }
  4889. } else {
  4890. pf->fdir_pf_filter_count = 0;
  4891. }
  4892. if (pf->hw.func_caps.vmdq) {
  4893. pf->flags |= I40E_FLAG_VMDQ_ENABLED;
  4894. pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
  4895. pf->num_vmdq_qps = I40E_DEFAULT_QUEUES_PER_VMDQ;
  4896. }
  4897. /* MFP mode enabled */
  4898. if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.mfp_mode_1) {
  4899. pf->flags |= I40E_FLAG_MFP_ENABLED;
  4900. dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
  4901. }
  4902. #ifdef CONFIG_PCI_IOV
  4903. if (pf->hw.func_caps.num_vfs) {
  4904. pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
  4905. pf->flags |= I40E_FLAG_SRIOV_ENABLED;
  4906. pf->num_req_vfs = min_t(int,
  4907. pf->hw.func_caps.num_vfs,
  4908. I40E_MAX_VF_COUNT);
  4909. }
  4910. #endif /* CONFIG_PCI_IOV */
  4911. pf->eeprom_version = 0xDEAD;
  4912. pf->lan_veb = I40E_NO_VEB;
  4913. pf->lan_vsi = I40E_NO_VSI;
  4914. /* set up queue assignment tracking */
  4915. size = sizeof(struct i40e_lump_tracking)
  4916. + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
  4917. pf->qp_pile = kzalloc(size, GFP_KERNEL);
  4918. if (!pf->qp_pile) {
  4919. err = -ENOMEM;
  4920. goto sw_init_done;
  4921. }
  4922. pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
  4923. pf->qp_pile->search_hint = 0;
  4924. /* set up vector assignment tracking */
  4925. size = sizeof(struct i40e_lump_tracking)
  4926. + (sizeof(u16) * pf->hw.func_caps.num_msix_vectors);
  4927. pf->irq_pile = kzalloc(size, GFP_KERNEL);
  4928. if (!pf->irq_pile) {
  4929. kfree(pf->qp_pile);
  4930. err = -ENOMEM;
  4931. goto sw_init_done;
  4932. }
  4933. pf->irq_pile->num_entries = pf->hw.func_caps.num_msix_vectors;
  4934. pf->irq_pile->search_hint = 0;
  4935. mutex_init(&pf->switch_mutex);
  4936. sw_init_done:
  4937. return err;
  4938. }
  4939. /**
  4940. * i40e_set_features - set the netdev feature flags
  4941. * @netdev: ptr to the netdev being adjusted
  4942. * @features: the feature set that the stack is suggesting
  4943. **/
  4944. static int i40e_set_features(struct net_device *netdev,
  4945. netdev_features_t features)
  4946. {
  4947. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4948. struct i40e_vsi *vsi = np->vsi;
  4949. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  4950. i40e_vlan_stripping_enable(vsi);
  4951. else
  4952. i40e_vlan_stripping_disable(vsi);
  4953. return 0;
  4954. }
  4955. static const struct net_device_ops i40e_netdev_ops = {
  4956. .ndo_open = i40e_open,
  4957. .ndo_stop = i40e_close,
  4958. .ndo_start_xmit = i40e_lan_xmit_frame,
  4959. .ndo_get_stats64 = i40e_get_netdev_stats_struct,
  4960. .ndo_set_rx_mode = i40e_set_rx_mode,
  4961. .ndo_validate_addr = eth_validate_addr,
  4962. .ndo_set_mac_address = i40e_set_mac,
  4963. .ndo_change_mtu = i40e_change_mtu,
  4964. .ndo_tx_timeout = i40e_tx_timeout,
  4965. .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
  4966. .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
  4967. #ifdef CONFIG_NET_POLL_CONTROLLER
  4968. .ndo_poll_controller = i40e_netpoll,
  4969. #endif
  4970. .ndo_setup_tc = i40e_setup_tc,
  4971. .ndo_set_features = i40e_set_features,
  4972. .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
  4973. .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
  4974. .ndo_set_vf_tx_rate = i40e_ndo_set_vf_bw,
  4975. .ndo_get_vf_config = i40e_ndo_get_vf_config,
  4976. };
  4977. /**
  4978. * i40e_config_netdev - Setup the netdev flags
  4979. * @vsi: the VSI being configured
  4980. *
  4981. * Returns 0 on success, negative value on failure
  4982. **/
  4983. static int i40e_config_netdev(struct i40e_vsi *vsi)
  4984. {
  4985. struct i40e_pf *pf = vsi->back;
  4986. struct i40e_hw *hw = &pf->hw;
  4987. struct i40e_netdev_priv *np;
  4988. struct net_device *netdev;
  4989. u8 mac_addr[ETH_ALEN];
  4990. int etherdev_size;
  4991. etherdev_size = sizeof(struct i40e_netdev_priv);
  4992. netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
  4993. if (!netdev)
  4994. return -ENOMEM;
  4995. vsi->netdev = netdev;
  4996. np = netdev_priv(netdev);
  4997. np->vsi = vsi;
  4998. netdev->hw_enc_features = NETIF_F_IP_CSUM |
  4999. NETIF_F_GSO_UDP_TUNNEL |
  5000. NETIF_F_TSO |
  5001. NETIF_F_SG;
  5002. netdev->features = NETIF_F_SG |
  5003. NETIF_F_IP_CSUM |
  5004. NETIF_F_SCTP_CSUM |
  5005. NETIF_F_HIGHDMA |
  5006. NETIF_F_GSO_UDP_TUNNEL |
  5007. NETIF_F_HW_VLAN_CTAG_TX |
  5008. NETIF_F_HW_VLAN_CTAG_RX |
  5009. NETIF_F_HW_VLAN_CTAG_FILTER |
  5010. NETIF_F_IPV6_CSUM |
  5011. NETIF_F_TSO |
  5012. NETIF_F_TSO6 |
  5013. NETIF_F_RXCSUM |
  5014. NETIF_F_RXHASH |
  5015. 0;
  5016. /* copy netdev features into list of user selectable features */
  5017. netdev->hw_features |= netdev->features;
  5018. if (vsi->type == I40E_VSI_MAIN) {
  5019. SET_NETDEV_DEV(netdev, &pf->pdev->dev);
  5020. memcpy(mac_addr, hw->mac.perm_addr, ETH_ALEN);
  5021. } else {
  5022. /* relate the VSI_VMDQ name to the VSI_MAIN name */
  5023. snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
  5024. pf->vsi[pf->lan_vsi]->netdev->name);
  5025. random_ether_addr(mac_addr);
  5026. i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false);
  5027. }
  5028. memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
  5029. memcpy(netdev->perm_addr, mac_addr, ETH_ALEN);
  5030. /* vlan gets same features (except vlan offload)
  5031. * after any tweaks for specific VSI types
  5032. */
  5033. netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX |
  5034. NETIF_F_HW_VLAN_CTAG_RX |
  5035. NETIF_F_HW_VLAN_CTAG_FILTER);
  5036. netdev->priv_flags |= IFF_UNICAST_FLT;
  5037. netdev->priv_flags |= IFF_SUPP_NOFCS;
  5038. /* Setup netdev TC information */
  5039. i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
  5040. netdev->netdev_ops = &i40e_netdev_ops;
  5041. netdev->watchdog_timeo = 5 * HZ;
  5042. i40e_set_ethtool_ops(netdev);
  5043. return 0;
  5044. }
  5045. /**
  5046. * i40e_vsi_delete - Delete a VSI from the switch
  5047. * @vsi: the VSI being removed
  5048. *
  5049. * Returns 0 on success, negative value on failure
  5050. **/
  5051. static void i40e_vsi_delete(struct i40e_vsi *vsi)
  5052. {
  5053. /* remove default VSI is not allowed */
  5054. if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
  5055. return;
  5056. /* there is no HW VSI for FDIR */
  5057. if (vsi->type == I40E_VSI_FDIR)
  5058. return;
  5059. i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
  5060. return;
  5061. }
  5062. /**
  5063. * i40e_add_vsi - Add a VSI to the switch
  5064. * @vsi: the VSI being configured
  5065. *
  5066. * This initializes a VSI context depending on the VSI type to be added and
  5067. * passes it down to the add_vsi aq command.
  5068. **/
  5069. static int i40e_add_vsi(struct i40e_vsi *vsi)
  5070. {
  5071. int ret = -ENODEV;
  5072. struct i40e_mac_filter *f, *ftmp;
  5073. struct i40e_pf *pf = vsi->back;
  5074. struct i40e_hw *hw = &pf->hw;
  5075. struct i40e_vsi_context ctxt;
  5076. u8 enabled_tc = 0x1; /* TC0 enabled */
  5077. int f_count = 0;
  5078. memset(&ctxt, 0, sizeof(ctxt));
  5079. switch (vsi->type) {
  5080. case I40E_VSI_MAIN:
  5081. /* The PF's main VSI is already setup as part of the
  5082. * device initialization, so we'll not bother with
  5083. * the add_vsi call, but we will retrieve the current
  5084. * VSI context.
  5085. */
  5086. ctxt.seid = pf->main_vsi_seid;
  5087. ctxt.pf_num = pf->hw.pf_id;
  5088. ctxt.vf_num = 0;
  5089. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  5090. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  5091. if (ret) {
  5092. dev_info(&pf->pdev->dev,
  5093. "couldn't get pf vsi config, err %d, aq_err %d\n",
  5094. ret, pf->hw.aq.asq_last_status);
  5095. return -ENOENT;
  5096. }
  5097. memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
  5098. vsi->info.valid_sections = 0;
  5099. vsi->seid = ctxt.seid;
  5100. vsi->id = ctxt.vsi_number;
  5101. enabled_tc = i40e_pf_get_tc_map(pf);
  5102. /* MFP mode setup queue map and update VSI */
  5103. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  5104. memset(&ctxt, 0, sizeof(ctxt));
  5105. ctxt.seid = pf->main_vsi_seid;
  5106. ctxt.pf_num = pf->hw.pf_id;
  5107. ctxt.vf_num = 0;
  5108. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  5109. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  5110. if (ret) {
  5111. dev_info(&pf->pdev->dev,
  5112. "update vsi failed, aq_err=%d\n",
  5113. pf->hw.aq.asq_last_status);
  5114. ret = -ENOENT;
  5115. goto err;
  5116. }
  5117. /* update the local VSI info queue map */
  5118. i40e_vsi_update_queue_map(vsi, &ctxt);
  5119. vsi->info.valid_sections = 0;
  5120. } else {
  5121. /* Default/Main VSI is only enabled for TC0
  5122. * reconfigure it to enable all TCs that are
  5123. * available on the port in SFP mode.
  5124. */
  5125. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  5126. if (ret) {
  5127. dev_info(&pf->pdev->dev,
  5128. "failed to configure TCs for main VSI tc_map 0x%08x, err %d, aq_err %d\n",
  5129. enabled_tc, ret,
  5130. pf->hw.aq.asq_last_status);
  5131. ret = -ENOENT;
  5132. }
  5133. }
  5134. break;
  5135. case I40E_VSI_FDIR:
  5136. /* no queue mapping or actual HW VSI needed */
  5137. vsi->info.valid_sections = 0;
  5138. vsi->seid = 0;
  5139. vsi->id = 0;
  5140. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  5141. return 0;
  5142. break;
  5143. case I40E_VSI_VMDQ2:
  5144. ctxt.pf_num = hw->pf_id;
  5145. ctxt.vf_num = 0;
  5146. ctxt.uplink_seid = vsi->uplink_seid;
  5147. ctxt.connection_type = 0x1; /* regular data port */
  5148. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  5149. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5150. /* This VSI is connected to VEB so the switch_id
  5151. * should be set to zero by default.
  5152. */
  5153. ctxt.info.switch_id = 0;
  5154. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
  5155. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5156. /* Setup the VSI tx/rx queue map for TC0 only for now */
  5157. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  5158. break;
  5159. case I40E_VSI_SRIOV:
  5160. ctxt.pf_num = hw->pf_id;
  5161. ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
  5162. ctxt.uplink_seid = vsi->uplink_seid;
  5163. ctxt.connection_type = 0x1; /* regular data port */
  5164. ctxt.flags = I40E_AQ_VSI_TYPE_VF;
  5165. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5166. /* This VSI is connected to VEB so the switch_id
  5167. * should be set to zero by default.
  5168. */
  5169. ctxt.info.switch_id = cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5170. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  5171. ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
  5172. /* Setup the VSI tx/rx queue map for TC0 only for now */
  5173. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  5174. break;
  5175. default:
  5176. return -ENODEV;
  5177. }
  5178. if (vsi->type != I40E_VSI_MAIN) {
  5179. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  5180. if (ret) {
  5181. dev_info(&vsi->back->pdev->dev,
  5182. "add vsi failed, aq_err=%d\n",
  5183. vsi->back->hw.aq.asq_last_status);
  5184. ret = -ENOENT;
  5185. goto err;
  5186. }
  5187. memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
  5188. vsi->info.valid_sections = 0;
  5189. vsi->seid = ctxt.seid;
  5190. vsi->id = ctxt.vsi_number;
  5191. }
  5192. /* If macvlan filters already exist, force them to get loaded */
  5193. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  5194. f->changed = true;
  5195. f_count++;
  5196. }
  5197. if (f_count) {
  5198. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  5199. pf->flags |= I40E_FLAG_FILTER_SYNC;
  5200. }
  5201. /* Update VSI BW information */
  5202. ret = i40e_vsi_get_bw_info(vsi);
  5203. if (ret) {
  5204. dev_info(&pf->pdev->dev,
  5205. "couldn't get vsi bw info, err %d, aq_err %d\n",
  5206. ret, pf->hw.aq.asq_last_status);
  5207. /* VSI is already added so not tearing that up */
  5208. ret = 0;
  5209. }
  5210. err:
  5211. return ret;
  5212. }
  5213. /**
  5214. * i40e_vsi_release - Delete a VSI and free its resources
  5215. * @vsi: the VSI being removed
  5216. *
  5217. * Returns 0 on success or < 0 on error
  5218. **/
  5219. int i40e_vsi_release(struct i40e_vsi *vsi)
  5220. {
  5221. struct i40e_mac_filter *f, *ftmp;
  5222. struct i40e_veb *veb = NULL;
  5223. struct i40e_pf *pf;
  5224. u16 uplink_seid;
  5225. int i, n;
  5226. pf = vsi->back;
  5227. /* release of a VEB-owner or last VSI is not allowed */
  5228. if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
  5229. dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
  5230. vsi->seid, vsi->uplink_seid);
  5231. return -ENODEV;
  5232. }
  5233. if (vsi == pf->vsi[pf->lan_vsi] &&
  5234. !test_bit(__I40E_DOWN, &pf->state)) {
  5235. dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
  5236. return -ENODEV;
  5237. }
  5238. uplink_seid = vsi->uplink_seid;
  5239. if (vsi->type != I40E_VSI_SRIOV) {
  5240. if (vsi->netdev_registered) {
  5241. vsi->netdev_registered = false;
  5242. if (vsi->netdev) {
  5243. /* results in a call to i40e_close() */
  5244. unregister_netdev(vsi->netdev);
  5245. free_netdev(vsi->netdev);
  5246. vsi->netdev = NULL;
  5247. }
  5248. } else {
  5249. if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
  5250. i40e_down(vsi);
  5251. i40e_vsi_free_irq(vsi);
  5252. i40e_vsi_free_tx_resources(vsi);
  5253. i40e_vsi_free_rx_resources(vsi);
  5254. }
  5255. i40e_vsi_disable_irq(vsi);
  5256. }
  5257. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list)
  5258. i40e_del_filter(vsi, f->macaddr, f->vlan,
  5259. f->is_vf, f->is_netdev);
  5260. i40e_sync_vsi_filters(vsi);
  5261. i40e_vsi_delete(vsi);
  5262. i40e_vsi_free_q_vectors(vsi);
  5263. i40e_vsi_clear_rings(vsi);
  5264. i40e_vsi_clear(vsi);
  5265. /* If this was the last thing on the VEB, except for the
  5266. * controlling VSI, remove the VEB, which puts the controlling
  5267. * VSI onto the next level down in the switch.
  5268. *
  5269. * Well, okay, there's one more exception here: don't remove
  5270. * the orphan VEBs yet. We'll wait for an explicit remove request
  5271. * from up the network stack.
  5272. */
  5273. for (n = 0, i = 0; i < pf->hw.func_caps.num_vsis; i++) {
  5274. if (pf->vsi[i] &&
  5275. pf->vsi[i]->uplink_seid == uplink_seid &&
  5276. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  5277. n++; /* count the VSIs */
  5278. }
  5279. }
  5280. for (i = 0; i < I40E_MAX_VEB; i++) {
  5281. if (!pf->veb[i])
  5282. continue;
  5283. if (pf->veb[i]->uplink_seid == uplink_seid)
  5284. n++; /* count the VEBs */
  5285. if (pf->veb[i]->seid == uplink_seid)
  5286. veb = pf->veb[i];
  5287. }
  5288. if (n == 0 && veb && veb->uplink_seid != 0)
  5289. i40e_veb_release(veb);
  5290. return 0;
  5291. }
  5292. /**
  5293. * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
  5294. * @vsi: ptr to the VSI
  5295. *
  5296. * This should only be called after i40e_vsi_mem_alloc() which allocates the
  5297. * corresponding SW VSI structure and initializes num_queue_pairs for the
  5298. * newly allocated VSI.
  5299. *
  5300. * Returns 0 on success or negative on failure
  5301. **/
  5302. static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
  5303. {
  5304. int ret = -ENOENT;
  5305. struct i40e_pf *pf = vsi->back;
  5306. if (vsi->q_vectors[0]) {
  5307. dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
  5308. vsi->seid);
  5309. return -EEXIST;
  5310. }
  5311. if (vsi->base_vector) {
  5312. dev_info(&pf->pdev->dev,
  5313. "VSI %d has non-zero base vector %d\n",
  5314. vsi->seid, vsi->base_vector);
  5315. return -EEXIST;
  5316. }
  5317. ret = i40e_alloc_q_vectors(vsi);
  5318. if (ret) {
  5319. dev_info(&pf->pdev->dev,
  5320. "failed to allocate %d q_vector for VSI %d, ret=%d\n",
  5321. vsi->num_q_vectors, vsi->seid, ret);
  5322. vsi->num_q_vectors = 0;
  5323. goto vector_setup_out;
  5324. }
  5325. if (vsi->num_q_vectors)
  5326. vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
  5327. vsi->num_q_vectors, vsi->idx);
  5328. if (vsi->base_vector < 0) {
  5329. dev_info(&pf->pdev->dev,
  5330. "failed to get q tracking for VSI %d, err=%d\n",
  5331. vsi->seid, vsi->base_vector);
  5332. i40e_vsi_free_q_vectors(vsi);
  5333. ret = -ENOENT;
  5334. goto vector_setup_out;
  5335. }
  5336. vector_setup_out:
  5337. return ret;
  5338. }
  5339. /**
  5340. * i40e_vsi_setup - Set up a VSI by a given type
  5341. * @pf: board private structure
  5342. * @type: VSI type
  5343. * @uplink_seid: the switch element to link to
  5344. * @param1: usage depends upon VSI type. For VF types, indicates VF id
  5345. *
  5346. * This allocates the sw VSI structure and its queue resources, then add a VSI
  5347. * to the identified VEB.
  5348. *
  5349. * Returns pointer to the successfully allocated and configure VSI sw struct on
  5350. * success, otherwise returns NULL on failure.
  5351. **/
  5352. struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
  5353. u16 uplink_seid, u32 param1)
  5354. {
  5355. struct i40e_vsi *vsi = NULL;
  5356. struct i40e_veb *veb = NULL;
  5357. int ret, i;
  5358. int v_idx;
  5359. /* The requested uplink_seid must be either
  5360. * - the PF's port seid
  5361. * no VEB is needed because this is the PF
  5362. * or this is a Flow Director special case VSI
  5363. * - seid of an existing VEB
  5364. * - seid of a VSI that owns an existing VEB
  5365. * - seid of a VSI that doesn't own a VEB
  5366. * a new VEB is created and the VSI becomes the owner
  5367. * - seid of the PF VSI, which is what creates the first VEB
  5368. * this is a special case of the previous
  5369. *
  5370. * Find which uplink_seid we were given and create a new VEB if needed
  5371. */
  5372. for (i = 0; i < I40E_MAX_VEB; i++) {
  5373. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
  5374. veb = pf->veb[i];
  5375. break;
  5376. }
  5377. }
  5378. if (!veb && uplink_seid != pf->mac_seid) {
  5379. for (i = 0; i < pf->hw.func_caps.num_vsis; i++) {
  5380. if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
  5381. vsi = pf->vsi[i];
  5382. break;
  5383. }
  5384. }
  5385. if (!vsi) {
  5386. dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
  5387. uplink_seid);
  5388. return NULL;
  5389. }
  5390. if (vsi->uplink_seid == pf->mac_seid)
  5391. veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
  5392. vsi->tc_config.enabled_tc);
  5393. else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
  5394. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  5395. vsi->tc_config.enabled_tc);
  5396. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  5397. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  5398. veb = pf->veb[i];
  5399. }
  5400. if (!veb) {
  5401. dev_info(&pf->pdev->dev, "couldn't add VEB\n");
  5402. return NULL;
  5403. }
  5404. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  5405. uplink_seid = veb->seid;
  5406. }
  5407. /* get vsi sw struct */
  5408. v_idx = i40e_vsi_mem_alloc(pf, type);
  5409. if (v_idx < 0)
  5410. goto err_alloc;
  5411. vsi = pf->vsi[v_idx];
  5412. vsi->type = type;
  5413. vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
  5414. if (type == I40E_VSI_MAIN)
  5415. pf->lan_vsi = v_idx;
  5416. else if (type == I40E_VSI_SRIOV)
  5417. vsi->vf_id = param1;
  5418. /* assign it some queues */
  5419. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
  5420. if (ret < 0) {
  5421. dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n",
  5422. vsi->seid, ret);
  5423. goto err_vsi;
  5424. }
  5425. vsi->base_queue = ret;
  5426. /* get a VSI from the hardware */
  5427. vsi->uplink_seid = uplink_seid;
  5428. ret = i40e_add_vsi(vsi);
  5429. if (ret)
  5430. goto err_vsi;
  5431. switch (vsi->type) {
  5432. /* setup the netdev if needed */
  5433. case I40E_VSI_MAIN:
  5434. case I40E_VSI_VMDQ2:
  5435. ret = i40e_config_netdev(vsi);
  5436. if (ret)
  5437. goto err_netdev;
  5438. ret = register_netdev(vsi->netdev);
  5439. if (ret)
  5440. goto err_netdev;
  5441. vsi->netdev_registered = true;
  5442. netif_carrier_off(vsi->netdev);
  5443. /* fall through */
  5444. case I40E_VSI_FDIR:
  5445. /* set up vectors and rings if needed */
  5446. ret = i40e_vsi_setup_vectors(vsi);
  5447. if (ret)
  5448. goto err_msix;
  5449. ret = i40e_alloc_rings(vsi);
  5450. if (ret)
  5451. goto err_rings;
  5452. /* map all of the rings to the q_vectors */
  5453. i40e_vsi_map_rings_to_vectors(vsi);
  5454. i40e_vsi_reset_stats(vsi);
  5455. break;
  5456. default:
  5457. /* no netdev or rings for the other VSI types */
  5458. break;
  5459. }
  5460. return vsi;
  5461. err_rings:
  5462. i40e_vsi_free_q_vectors(vsi);
  5463. err_msix:
  5464. if (vsi->netdev_registered) {
  5465. vsi->netdev_registered = false;
  5466. unregister_netdev(vsi->netdev);
  5467. free_netdev(vsi->netdev);
  5468. vsi->netdev = NULL;
  5469. }
  5470. err_netdev:
  5471. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  5472. err_vsi:
  5473. i40e_vsi_clear(vsi);
  5474. err_alloc:
  5475. return NULL;
  5476. }
  5477. /**
  5478. * i40e_veb_get_bw_info - Query VEB BW information
  5479. * @veb: the veb to query
  5480. *
  5481. * Query the Tx scheduler BW configuration data for given VEB
  5482. **/
  5483. static int i40e_veb_get_bw_info(struct i40e_veb *veb)
  5484. {
  5485. struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
  5486. struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
  5487. struct i40e_pf *pf = veb->pf;
  5488. struct i40e_hw *hw = &pf->hw;
  5489. u32 tc_bw_max;
  5490. int ret = 0;
  5491. int i;
  5492. ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
  5493. &bw_data, NULL);
  5494. if (ret) {
  5495. dev_info(&pf->pdev->dev,
  5496. "query veb bw config failed, aq_err=%d\n",
  5497. hw->aq.asq_last_status);
  5498. goto out;
  5499. }
  5500. ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
  5501. &ets_data, NULL);
  5502. if (ret) {
  5503. dev_info(&pf->pdev->dev,
  5504. "query veb bw ets config failed, aq_err=%d\n",
  5505. hw->aq.asq_last_status);
  5506. goto out;
  5507. }
  5508. veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
  5509. veb->bw_max_quanta = ets_data.tc_bw_max;
  5510. veb->is_abs_credits = bw_data.absolute_credits_enable;
  5511. tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
  5512. (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
  5513. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5514. veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
  5515. veb->bw_tc_limit_credits[i] =
  5516. le16_to_cpu(bw_data.tc_bw_limits[i]);
  5517. veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
  5518. }
  5519. out:
  5520. return ret;
  5521. }
  5522. /**
  5523. * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
  5524. * @pf: board private structure
  5525. *
  5526. * On error: returns error code (negative)
  5527. * On success: returns vsi index in PF (positive)
  5528. **/
  5529. static int i40e_veb_mem_alloc(struct i40e_pf *pf)
  5530. {
  5531. int ret = -ENOENT;
  5532. struct i40e_veb *veb;
  5533. int i;
  5534. /* Need to protect the allocation of switch elements at the PF level */
  5535. mutex_lock(&pf->switch_mutex);
  5536. /* VEB list may be fragmented if VEB creation/destruction has
  5537. * been happening. We can afford to do a quick scan to look
  5538. * for any free slots in the list.
  5539. *
  5540. * find next empty veb slot, looping back around if necessary
  5541. */
  5542. i = 0;
  5543. while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
  5544. i++;
  5545. if (i >= I40E_MAX_VEB) {
  5546. ret = -ENOMEM;
  5547. goto err_alloc_veb; /* out of VEB slots! */
  5548. }
  5549. veb = kzalloc(sizeof(*veb), GFP_KERNEL);
  5550. if (!veb) {
  5551. ret = -ENOMEM;
  5552. goto err_alloc_veb;
  5553. }
  5554. veb->pf = pf;
  5555. veb->idx = i;
  5556. veb->enabled_tc = 1;
  5557. pf->veb[i] = veb;
  5558. ret = i;
  5559. err_alloc_veb:
  5560. mutex_unlock(&pf->switch_mutex);
  5561. return ret;
  5562. }
  5563. /**
  5564. * i40e_switch_branch_release - Delete a branch of the switch tree
  5565. * @branch: where to start deleting
  5566. *
  5567. * This uses recursion to find the tips of the branch to be
  5568. * removed, deleting until we get back to and can delete this VEB.
  5569. **/
  5570. static void i40e_switch_branch_release(struct i40e_veb *branch)
  5571. {
  5572. struct i40e_pf *pf = branch->pf;
  5573. u16 branch_seid = branch->seid;
  5574. u16 veb_idx = branch->idx;
  5575. int i;
  5576. /* release any VEBs on this VEB - RECURSION */
  5577. for (i = 0; i < I40E_MAX_VEB; i++) {
  5578. if (!pf->veb[i])
  5579. continue;
  5580. if (pf->veb[i]->uplink_seid == branch->seid)
  5581. i40e_switch_branch_release(pf->veb[i]);
  5582. }
  5583. /* Release the VSIs on this VEB, but not the owner VSI.
  5584. *
  5585. * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
  5586. * the VEB itself, so don't use (*branch) after this loop.
  5587. */
  5588. for (i = 0; i < pf->hw.func_caps.num_vsis; i++) {
  5589. if (!pf->vsi[i])
  5590. continue;
  5591. if (pf->vsi[i]->uplink_seid == branch_seid &&
  5592. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  5593. i40e_vsi_release(pf->vsi[i]);
  5594. }
  5595. }
  5596. /* There's one corner case where the VEB might not have been
  5597. * removed, so double check it here and remove it if needed.
  5598. * This case happens if the veb was created from the debugfs
  5599. * commands and no VSIs were added to it.
  5600. */
  5601. if (pf->veb[veb_idx])
  5602. i40e_veb_release(pf->veb[veb_idx]);
  5603. }
  5604. /**
  5605. * i40e_veb_clear - remove veb struct
  5606. * @veb: the veb to remove
  5607. **/
  5608. static void i40e_veb_clear(struct i40e_veb *veb)
  5609. {
  5610. if (!veb)
  5611. return;
  5612. if (veb->pf) {
  5613. struct i40e_pf *pf = veb->pf;
  5614. mutex_lock(&pf->switch_mutex);
  5615. if (pf->veb[veb->idx] == veb)
  5616. pf->veb[veb->idx] = NULL;
  5617. mutex_unlock(&pf->switch_mutex);
  5618. }
  5619. kfree(veb);
  5620. }
  5621. /**
  5622. * i40e_veb_release - Delete a VEB and free its resources
  5623. * @veb: the VEB being removed
  5624. **/
  5625. void i40e_veb_release(struct i40e_veb *veb)
  5626. {
  5627. struct i40e_vsi *vsi = NULL;
  5628. struct i40e_pf *pf;
  5629. int i, n = 0;
  5630. pf = veb->pf;
  5631. /* find the remaining VSI and check for extras */
  5632. for (i = 0; i < pf->hw.func_caps.num_vsis; i++) {
  5633. if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
  5634. n++;
  5635. vsi = pf->vsi[i];
  5636. }
  5637. }
  5638. if (n != 1) {
  5639. dev_info(&pf->pdev->dev,
  5640. "can't remove VEB %d with %d VSIs left\n",
  5641. veb->seid, n);
  5642. return;
  5643. }
  5644. /* move the remaining VSI to uplink veb */
  5645. vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
  5646. if (veb->uplink_seid) {
  5647. vsi->uplink_seid = veb->uplink_seid;
  5648. if (veb->uplink_seid == pf->mac_seid)
  5649. vsi->veb_idx = I40E_NO_VEB;
  5650. else
  5651. vsi->veb_idx = veb->veb_idx;
  5652. } else {
  5653. /* floating VEB */
  5654. vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  5655. vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
  5656. }
  5657. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  5658. i40e_veb_clear(veb);
  5659. return;
  5660. }
  5661. /**
  5662. * i40e_add_veb - create the VEB in the switch
  5663. * @veb: the VEB to be instantiated
  5664. * @vsi: the controlling VSI
  5665. **/
  5666. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
  5667. {
  5668. bool is_default = (vsi->idx == vsi->back->lan_vsi);
  5669. int ret;
  5670. /* get a VEB from the hardware */
  5671. ret = i40e_aq_add_veb(&veb->pf->hw, veb->uplink_seid, vsi->seid,
  5672. veb->enabled_tc, is_default, &veb->seid, NULL);
  5673. if (ret) {
  5674. dev_info(&veb->pf->pdev->dev,
  5675. "couldn't add VEB, err %d, aq_err %d\n",
  5676. ret, veb->pf->hw.aq.asq_last_status);
  5677. return -EPERM;
  5678. }
  5679. /* get statistics counter */
  5680. ret = i40e_aq_get_veb_parameters(&veb->pf->hw, veb->seid, NULL, NULL,
  5681. &veb->stats_idx, NULL, NULL, NULL);
  5682. if (ret) {
  5683. dev_info(&veb->pf->pdev->dev,
  5684. "couldn't get VEB statistics idx, err %d, aq_err %d\n",
  5685. ret, veb->pf->hw.aq.asq_last_status);
  5686. return -EPERM;
  5687. }
  5688. ret = i40e_veb_get_bw_info(veb);
  5689. if (ret) {
  5690. dev_info(&veb->pf->pdev->dev,
  5691. "couldn't get VEB bw info, err %d, aq_err %d\n",
  5692. ret, veb->pf->hw.aq.asq_last_status);
  5693. i40e_aq_delete_element(&veb->pf->hw, veb->seid, NULL);
  5694. return -ENOENT;
  5695. }
  5696. vsi->uplink_seid = veb->seid;
  5697. vsi->veb_idx = veb->idx;
  5698. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  5699. return 0;
  5700. }
  5701. /**
  5702. * i40e_veb_setup - Set up a VEB
  5703. * @pf: board private structure
  5704. * @flags: VEB setup flags
  5705. * @uplink_seid: the switch element to link to
  5706. * @vsi_seid: the initial VSI seid
  5707. * @enabled_tc: Enabled TC bit-map
  5708. *
  5709. * This allocates the sw VEB structure and links it into the switch
  5710. * It is possible and legal for this to be a duplicate of an already
  5711. * existing VEB. It is also possible for both uplink and vsi seids
  5712. * to be zero, in order to create a floating VEB.
  5713. *
  5714. * Returns pointer to the successfully allocated VEB sw struct on
  5715. * success, otherwise returns NULL on failure.
  5716. **/
  5717. struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
  5718. u16 uplink_seid, u16 vsi_seid,
  5719. u8 enabled_tc)
  5720. {
  5721. struct i40e_veb *veb, *uplink_veb = NULL;
  5722. int vsi_idx, veb_idx;
  5723. int ret;
  5724. /* if one seid is 0, the other must be 0 to create a floating relay */
  5725. if ((uplink_seid == 0 || vsi_seid == 0) &&
  5726. (uplink_seid + vsi_seid != 0)) {
  5727. dev_info(&pf->pdev->dev,
  5728. "one, not both seid's are 0: uplink=%d vsi=%d\n",
  5729. uplink_seid, vsi_seid);
  5730. return NULL;
  5731. }
  5732. /* make sure there is such a vsi and uplink */
  5733. for (vsi_idx = 0; vsi_idx < pf->hw.func_caps.num_vsis; vsi_idx++)
  5734. if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
  5735. break;
  5736. if (vsi_idx >= pf->hw.func_caps.num_vsis && vsi_seid != 0) {
  5737. dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
  5738. vsi_seid);
  5739. return NULL;
  5740. }
  5741. if (uplink_seid && uplink_seid != pf->mac_seid) {
  5742. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  5743. if (pf->veb[veb_idx] &&
  5744. pf->veb[veb_idx]->seid == uplink_seid) {
  5745. uplink_veb = pf->veb[veb_idx];
  5746. break;
  5747. }
  5748. }
  5749. if (!uplink_veb) {
  5750. dev_info(&pf->pdev->dev,
  5751. "uplink seid %d not found\n", uplink_seid);
  5752. return NULL;
  5753. }
  5754. }
  5755. /* get veb sw struct */
  5756. veb_idx = i40e_veb_mem_alloc(pf);
  5757. if (veb_idx < 0)
  5758. goto err_alloc;
  5759. veb = pf->veb[veb_idx];
  5760. veb->flags = flags;
  5761. veb->uplink_seid = uplink_seid;
  5762. veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
  5763. veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
  5764. /* create the VEB in the switch */
  5765. ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
  5766. if (ret)
  5767. goto err_veb;
  5768. return veb;
  5769. err_veb:
  5770. i40e_veb_clear(veb);
  5771. err_alloc:
  5772. return NULL;
  5773. }
  5774. /**
  5775. * i40e_setup_pf_switch_element - set pf vars based on switch type
  5776. * @pf: board private structure
  5777. * @ele: element we are building info from
  5778. * @num_reported: total number of elements
  5779. * @printconfig: should we print the contents
  5780. *
  5781. * helper function to assist in extracting a few useful SEID values.
  5782. **/
  5783. static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
  5784. struct i40e_aqc_switch_config_element_resp *ele,
  5785. u16 num_reported, bool printconfig)
  5786. {
  5787. u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
  5788. u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
  5789. u8 element_type = ele->element_type;
  5790. u16 seid = le16_to_cpu(ele->seid);
  5791. if (printconfig)
  5792. dev_info(&pf->pdev->dev,
  5793. "type=%d seid=%d uplink=%d downlink=%d\n",
  5794. element_type, seid, uplink_seid, downlink_seid);
  5795. switch (element_type) {
  5796. case I40E_SWITCH_ELEMENT_TYPE_MAC:
  5797. pf->mac_seid = seid;
  5798. break;
  5799. case I40E_SWITCH_ELEMENT_TYPE_VEB:
  5800. /* Main VEB? */
  5801. if (uplink_seid != pf->mac_seid)
  5802. break;
  5803. if (pf->lan_veb == I40E_NO_VEB) {
  5804. int v;
  5805. /* find existing or else empty VEB */
  5806. for (v = 0; v < I40E_MAX_VEB; v++) {
  5807. if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
  5808. pf->lan_veb = v;
  5809. break;
  5810. }
  5811. }
  5812. if (pf->lan_veb == I40E_NO_VEB) {
  5813. v = i40e_veb_mem_alloc(pf);
  5814. if (v < 0)
  5815. break;
  5816. pf->lan_veb = v;
  5817. }
  5818. }
  5819. pf->veb[pf->lan_veb]->seid = seid;
  5820. pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
  5821. pf->veb[pf->lan_veb]->pf = pf;
  5822. pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
  5823. break;
  5824. case I40E_SWITCH_ELEMENT_TYPE_VSI:
  5825. if (num_reported != 1)
  5826. break;
  5827. /* This is immediately after a reset so we can assume this is
  5828. * the PF's VSI
  5829. */
  5830. pf->mac_seid = uplink_seid;
  5831. pf->pf_seid = downlink_seid;
  5832. pf->main_vsi_seid = seid;
  5833. if (printconfig)
  5834. dev_info(&pf->pdev->dev,
  5835. "pf_seid=%d main_vsi_seid=%d\n",
  5836. pf->pf_seid, pf->main_vsi_seid);
  5837. break;
  5838. case I40E_SWITCH_ELEMENT_TYPE_PF:
  5839. case I40E_SWITCH_ELEMENT_TYPE_VF:
  5840. case I40E_SWITCH_ELEMENT_TYPE_EMP:
  5841. case I40E_SWITCH_ELEMENT_TYPE_BMC:
  5842. case I40E_SWITCH_ELEMENT_TYPE_PE:
  5843. case I40E_SWITCH_ELEMENT_TYPE_PA:
  5844. /* ignore these for now */
  5845. break;
  5846. default:
  5847. dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
  5848. element_type, seid);
  5849. break;
  5850. }
  5851. }
  5852. /**
  5853. * i40e_fetch_switch_configuration - Get switch config from firmware
  5854. * @pf: board private structure
  5855. * @printconfig: should we print the contents
  5856. *
  5857. * Get the current switch configuration from the device and
  5858. * extract a few useful SEID values.
  5859. **/
  5860. int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
  5861. {
  5862. struct i40e_aqc_get_switch_config_resp *sw_config;
  5863. u16 next_seid = 0;
  5864. int ret = 0;
  5865. u8 *aq_buf;
  5866. int i;
  5867. aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
  5868. if (!aq_buf)
  5869. return -ENOMEM;
  5870. sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
  5871. do {
  5872. u16 num_reported, num_total;
  5873. ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
  5874. I40E_AQ_LARGE_BUF,
  5875. &next_seid, NULL);
  5876. if (ret) {
  5877. dev_info(&pf->pdev->dev,
  5878. "get switch config failed %d aq_err=%x\n",
  5879. ret, pf->hw.aq.asq_last_status);
  5880. kfree(aq_buf);
  5881. return -ENOENT;
  5882. }
  5883. num_reported = le16_to_cpu(sw_config->header.num_reported);
  5884. num_total = le16_to_cpu(sw_config->header.num_total);
  5885. if (printconfig)
  5886. dev_info(&pf->pdev->dev,
  5887. "header: %d reported %d total\n",
  5888. num_reported, num_total);
  5889. if (num_reported) {
  5890. int sz = sizeof(*sw_config) * num_reported;
  5891. kfree(pf->sw_config);
  5892. pf->sw_config = kzalloc(sz, GFP_KERNEL);
  5893. if (pf->sw_config)
  5894. memcpy(pf->sw_config, sw_config, sz);
  5895. }
  5896. for (i = 0; i < num_reported; i++) {
  5897. struct i40e_aqc_switch_config_element_resp *ele =
  5898. &sw_config->element[i];
  5899. i40e_setup_pf_switch_element(pf, ele, num_reported,
  5900. printconfig);
  5901. }
  5902. } while (next_seid != 0);
  5903. kfree(aq_buf);
  5904. return ret;
  5905. }
  5906. /**
  5907. * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
  5908. * @pf: board private structure
  5909. *
  5910. * Returns 0 on success, negative value on failure
  5911. **/
  5912. static int i40e_setup_pf_switch(struct i40e_pf *pf)
  5913. {
  5914. int ret;
  5915. /* find out what's out there already */
  5916. ret = i40e_fetch_switch_configuration(pf, false);
  5917. if (ret) {
  5918. dev_info(&pf->pdev->dev,
  5919. "couldn't fetch switch config, err %d, aq_err %d\n",
  5920. ret, pf->hw.aq.asq_last_status);
  5921. return ret;
  5922. }
  5923. i40e_pf_reset_stats(pf);
  5924. /* fdir VSI must happen first to be sure it gets queue 0, but only
  5925. * if there is enough room for the fdir VSI
  5926. */
  5927. if (pf->num_lan_qps > 1)
  5928. i40e_fdir_setup(pf);
  5929. /* first time setup */
  5930. if (pf->lan_vsi == I40E_NO_VSI) {
  5931. struct i40e_vsi *vsi = NULL;
  5932. u16 uplink_seid;
  5933. /* Set up the PF VSI associated with the PF's main VSI
  5934. * that is already in the HW switch
  5935. */
  5936. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  5937. uplink_seid = pf->veb[pf->lan_veb]->seid;
  5938. else
  5939. uplink_seid = pf->mac_seid;
  5940. vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
  5941. if (!vsi) {
  5942. dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
  5943. i40e_fdir_teardown(pf);
  5944. return -EAGAIN;
  5945. }
  5946. /* accommodate kcompat by copying the main VSI queue count
  5947. * into the pf, since this newer code pushes the pf queue
  5948. * info down a level into a VSI
  5949. */
  5950. pf->num_rx_queues = vsi->alloc_queue_pairs;
  5951. pf->num_tx_queues = vsi->alloc_queue_pairs;
  5952. } else {
  5953. /* force a reset of TC and queue layout configurations */
  5954. u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  5955. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  5956. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  5957. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  5958. }
  5959. i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
  5960. /* Setup static PF queue filter control settings */
  5961. ret = i40e_setup_pf_filter_control(pf);
  5962. if (ret) {
  5963. dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
  5964. ret);
  5965. /* Failure here should not stop continuing other steps */
  5966. }
  5967. /* enable RSS in the HW, even for only one queue, as the stack can use
  5968. * the hash
  5969. */
  5970. if ((pf->flags & I40E_FLAG_RSS_ENABLED))
  5971. i40e_config_rss(pf);
  5972. /* fill in link information and enable LSE reporting */
  5973. i40e_aq_get_link_info(&pf->hw, true, NULL, NULL);
  5974. i40e_link_event(pf);
  5975. /* Initialize user-specifics link properties */
  5976. pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
  5977. I40E_AQ_AN_COMPLETED) ? true : false);
  5978. pf->hw.fc.requested_mode = I40E_FC_DEFAULT;
  5979. if (pf->hw.phy.link_info.an_info &
  5980. (I40E_AQ_LINK_PAUSE_TX | I40E_AQ_LINK_PAUSE_RX))
  5981. pf->hw.fc.current_mode = I40E_FC_FULL;
  5982. else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX)
  5983. pf->hw.fc.current_mode = I40E_FC_TX_PAUSE;
  5984. else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX)
  5985. pf->hw.fc.current_mode = I40E_FC_RX_PAUSE;
  5986. else
  5987. pf->hw.fc.current_mode = I40E_FC_DEFAULT;
  5988. return ret;
  5989. }
  5990. /**
  5991. * i40e_set_rss_size - helper to set rss_size
  5992. * @pf: board private structure
  5993. * @queues_left: how many queues
  5994. */
  5995. static u16 i40e_set_rss_size(struct i40e_pf *pf, int queues_left)
  5996. {
  5997. int num_tc0;
  5998. num_tc0 = min_t(int, queues_left, pf->rss_size_max);
  5999. num_tc0 = min_t(int, num_tc0, nr_cpus_node(numa_node_id()));
  6000. num_tc0 = rounddown_pow_of_two(num_tc0);
  6001. return num_tc0;
  6002. }
  6003. /**
  6004. * i40e_determine_queue_usage - Work out queue distribution
  6005. * @pf: board private structure
  6006. **/
  6007. static void i40e_determine_queue_usage(struct i40e_pf *pf)
  6008. {
  6009. int accum_tc_size;
  6010. int queues_left;
  6011. pf->num_lan_qps = 0;
  6012. pf->num_tc_qps = rounddown_pow_of_two(pf->num_tc_qps);
  6013. accum_tc_size = (I40E_MAX_TRAFFIC_CLASS - 1) * pf->num_tc_qps;
  6014. /* Find the max queues to be put into basic use. We'll always be
  6015. * using TC0, whether or not DCB is running, and TC0 will get the
  6016. * big RSS set.
  6017. */
  6018. queues_left = pf->hw.func_caps.num_tx_qp;
  6019. if (!((pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  6020. (pf->flags & I40E_FLAG_MQ_ENABLED)) ||
  6021. !(pf->flags & (I40E_FLAG_RSS_ENABLED |
  6022. I40E_FLAG_FDIR_ENABLED | I40E_FLAG_DCB_ENABLED)) ||
  6023. (queues_left == 1)) {
  6024. /* one qp for PF, no queues for anything else */
  6025. queues_left = 0;
  6026. pf->rss_size = pf->num_lan_qps = 1;
  6027. /* make sure all the fancies are disabled */
  6028. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  6029. I40E_FLAG_MQ_ENABLED |
  6030. I40E_FLAG_FDIR_ENABLED |
  6031. I40E_FLAG_FDIR_ATR_ENABLED |
  6032. I40E_FLAG_DCB_ENABLED |
  6033. I40E_FLAG_SRIOV_ENABLED |
  6034. I40E_FLAG_VMDQ_ENABLED);
  6035. } else if (pf->flags & I40E_FLAG_RSS_ENABLED &&
  6036. !(pf->flags & I40E_FLAG_FDIR_ENABLED) &&
  6037. !(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  6038. pf->rss_size = i40e_set_rss_size(pf, queues_left);
  6039. queues_left -= pf->rss_size;
  6040. pf->num_lan_qps = pf->rss_size;
  6041. } else if (pf->flags & I40E_FLAG_RSS_ENABLED &&
  6042. !(pf->flags & I40E_FLAG_FDIR_ENABLED) &&
  6043. (pf->flags & I40E_FLAG_DCB_ENABLED)) {
  6044. /* save num_tc_qps queues for TCs 1 thru 7 and the rest
  6045. * are set up for RSS in TC0
  6046. */
  6047. queues_left -= accum_tc_size;
  6048. pf->rss_size = i40e_set_rss_size(pf, queues_left);
  6049. queues_left -= pf->rss_size;
  6050. if (queues_left < 0) {
  6051. dev_info(&pf->pdev->dev, "not enough queues for DCB\n");
  6052. return;
  6053. }
  6054. pf->num_lan_qps = pf->rss_size + accum_tc_size;
  6055. } else if (pf->flags & I40E_FLAG_RSS_ENABLED &&
  6056. (pf->flags & I40E_FLAG_FDIR_ENABLED) &&
  6057. !(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  6058. queues_left -= 1; /* save 1 queue for FD */
  6059. pf->rss_size = i40e_set_rss_size(pf, queues_left);
  6060. queues_left -= pf->rss_size;
  6061. if (queues_left < 0) {
  6062. dev_info(&pf->pdev->dev, "not enough queues for Flow Director\n");
  6063. return;
  6064. }
  6065. pf->num_lan_qps = pf->rss_size;
  6066. } else if (pf->flags & I40E_FLAG_RSS_ENABLED &&
  6067. (pf->flags & I40E_FLAG_FDIR_ENABLED) &&
  6068. (pf->flags & I40E_FLAG_DCB_ENABLED)) {
  6069. /* save 1 queue for TCs 1 thru 7,
  6070. * 1 queue for flow director,
  6071. * and the rest are set up for RSS in TC0
  6072. */
  6073. queues_left -= 1;
  6074. queues_left -= accum_tc_size;
  6075. pf->rss_size = i40e_set_rss_size(pf, queues_left);
  6076. queues_left -= pf->rss_size;
  6077. if (queues_left < 0) {
  6078. dev_info(&pf->pdev->dev, "not enough queues for DCB and Flow Director\n");
  6079. return;
  6080. }
  6081. pf->num_lan_qps = pf->rss_size + accum_tc_size;
  6082. } else {
  6083. dev_info(&pf->pdev->dev,
  6084. "Invalid configuration, flags=0x%08llx\n", pf->flags);
  6085. return;
  6086. }
  6087. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  6088. pf->num_vf_qps && pf->num_req_vfs && queues_left) {
  6089. pf->num_req_vfs = min_t(int, pf->num_req_vfs, (queues_left /
  6090. pf->num_vf_qps));
  6091. queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
  6092. }
  6093. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  6094. pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
  6095. pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
  6096. (queues_left / pf->num_vmdq_qps));
  6097. queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
  6098. }
  6099. return;
  6100. }
  6101. /**
  6102. * i40e_setup_pf_filter_control - Setup PF static filter control
  6103. * @pf: PF to be setup
  6104. *
  6105. * i40e_setup_pf_filter_control sets up a pf's initial filter control
  6106. * settings. If PE/FCoE are enabled then it will also set the per PF
  6107. * based filter sizes required for them. It also enables Flow director,
  6108. * ethertype and macvlan type filter settings for the pf.
  6109. *
  6110. * Returns 0 on success, negative on failure
  6111. **/
  6112. static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
  6113. {
  6114. struct i40e_filter_control_settings *settings = &pf->filter_settings;
  6115. settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
  6116. /* Flow Director is enabled */
  6117. if (pf->flags & (I40E_FLAG_FDIR_ENABLED | I40E_FLAG_FDIR_ATR_ENABLED))
  6118. settings->enable_fdir = true;
  6119. /* Ethtype and MACVLAN filters enabled for PF */
  6120. settings->enable_ethtype = true;
  6121. settings->enable_macvlan = true;
  6122. if (i40e_set_filter_control(&pf->hw, settings))
  6123. return -ENOENT;
  6124. return 0;
  6125. }
  6126. /**
  6127. * i40e_probe - Device initialization routine
  6128. * @pdev: PCI device information struct
  6129. * @ent: entry in i40e_pci_tbl
  6130. *
  6131. * i40e_probe initializes a pf identified by a pci_dev structure.
  6132. * The OS initialization, configuring of the pf private structure,
  6133. * and a hardware reset occur.
  6134. *
  6135. * Returns 0 on success, negative on failure
  6136. **/
  6137. static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  6138. {
  6139. struct i40e_driver_version dv;
  6140. struct i40e_pf *pf;
  6141. struct i40e_hw *hw;
  6142. int err = 0;
  6143. u32 len;
  6144. err = pci_enable_device_mem(pdev);
  6145. if (err)
  6146. return err;
  6147. /* set up for high or low dma */
  6148. if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) {
  6149. /* coherent mask for the same size will always succeed if
  6150. * dma_set_mask does
  6151. */
  6152. dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
  6153. } else if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
  6154. dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  6155. } else {
  6156. dev_err(&pdev->dev, "DMA configuration failed: %d\n", err);
  6157. err = -EIO;
  6158. goto err_dma;
  6159. }
  6160. /* set up pci connections */
  6161. err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
  6162. IORESOURCE_MEM), i40e_driver_name);
  6163. if (err) {
  6164. dev_info(&pdev->dev,
  6165. "pci_request_selected_regions failed %d\n", err);
  6166. goto err_pci_reg;
  6167. }
  6168. pci_enable_pcie_error_reporting(pdev);
  6169. pci_set_master(pdev);
  6170. /* Now that we have a PCI connection, we need to do the
  6171. * low level device setup. This is primarily setting up
  6172. * the Admin Queue structures and then querying for the
  6173. * device's current profile information.
  6174. */
  6175. pf = kzalloc(sizeof(*pf), GFP_KERNEL);
  6176. if (!pf) {
  6177. err = -ENOMEM;
  6178. goto err_pf_alloc;
  6179. }
  6180. pf->next_vsi = 0;
  6181. pf->pdev = pdev;
  6182. set_bit(__I40E_DOWN, &pf->state);
  6183. hw = &pf->hw;
  6184. hw->back = pf;
  6185. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  6186. pci_resource_len(pdev, 0));
  6187. if (!hw->hw_addr) {
  6188. err = -EIO;
  6189. dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
  6190. (unsigned int)pci_resource_start(pdev, 0),
  6191. (unsigned int)pci_resource_len(pdev, 0), err);
  6192. goto err_ioremap;
  6193. }
  6194. hw->vendor_id = pdev->vendor;
  6195. hw->device_id = pdev->device;
  6196. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  6197. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  6198. hw->subsystem_device_id = pdev->subsystem_device;
  6199. hw->bus.device = PCI_SLOT(pdev->devfn);
  6200. hw->bus.func = PCI_FUNC(pdev->devfn);
  6201. /* Reset here to make sure all is clean and to define PF 'n' */
  6202. err = i40e_pf_reset(hw);
  6203. if (err) {
  6204. dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
  6205. goto err_pf_reset;
  6206. }
  6207. pf->pfr_count++;
  6208. hw->aq.num_arq_entries = I40E_AQ_LEN;
  6209. hw->aq.num_asq_entries = I40E_AQ_LEN;
  6210. hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  6211. hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  6212. pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
  6213. snprintf(pf->misc_int_name, sizeof(pf->misc_int_name) - 1,
  6214. "%s-pf%d:misc",
  6215. dev_driver_string(&pf->pdev->dev), pf->hw.pf_id);
  6216. err = i40e_init_shared_code(hw);
  6217. if (err) {
  6218. dev_info(&pdev->dev, "init_shared_code failed: %d\n", err);
  6219. goto err_pf_reset;
  6220. }
  6221. err = i40e_init_adminq(hw);
  6222. dev_info(&pdev->dev, "%s\n", i40e_fw_version_str(hw));
  6223. if (err) {
  6224. dev_info(&pdev->dev,
  6225. "init_adminq failed: %d expecting API %02x.%02x\n",
  6226. err,
  6227. I40E_FW_API_VERSION_MAJOR, I40E_FW_API_VERSION_MINOR);
  6228. goto err_pf_reset;
  6229. }
  6230. err = i40e_get_capabilities(pf);
  6231. if (err)
  6232. goto err_adminq_setup;
  6233. err = i40e_sw_init(pf);
  6234. if (err) {
  6235. dev_info(&pdev->dev, "sw_init failed: %d\n", err);
  6236. goto err_sw_init;
  6237. }
  6238. err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  6239. hw->func_caps.num_rx_qp,
  6240. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  6241. if (err) {
  6242. dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
  6243. goto err_init_lan_hmc;
  6244. }
  6245. err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  6246. if (err) {
  6247. dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
  6248. err = -ENOENT;
  6249. goto err_configure_lan_hmc;
  6250. }
  6251. i40e_get_mac_addr(hw, hw->mac.addr);
  6252. if (i40e_validate_mac_addr(hw->mac.addr)) {
  6253. dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
  6254. err = -EIO;
  6255. goto err_mac_addr;
  6256. }
  6257. dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
  6258. memcpy(hw->mac.perm_addr, hw->mac.addr, ETH_ALEN);
  6259. pci_set_drvdata(pdev, pf);
  6260. pci_save_state(pdev);
  6261. /* set up periodic task facility */
  6262. setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
  6263. pf->service_timer_period = HZ;
  6264. INIT_WORK(&pf->service_task, i40e_service_task);
  6265. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  6266. pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
  6267. pf->link_check_timeout = jiffies;
  6268. /* set up the main switch operations */
  6269. i40e_determine_queue_usage(pf);
  6270. i40e_init_interrupt_scheme(pf);
  6271. /* Set up the *vsi struct based on the number of VSIs in the HW,
  6272. * and set up our local tracking of the MAIN PF vsi.
  6273. */
  6274. len = sizeof(struct i40e_vsi *) * pf->hw.func_caps.num_vsis;
  6275. pf->vsi = kzalloc(len, GFP_KERNEL);
  6276. if (!pf->vsi) {
  6277. err = -ENOMEM;
  6278. goto err_switch_setup;
  6279. }
  6280. err = i40e_setup_pf_switch(pf);
  6281. if (err) {
  6282. dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
  6283. goto err_vsis;
  6284. }
  6285. /* The main driver is (mostly) up and happy. We need to set this state
  6286. * before setting up the misc vector or we get a race and the vector
  6287. * ends up disabled forever.
  6288. */
  6289. clear_bit(__I40E_DOWN, &pf->state);
  6290. /* In case of MSIX we are going to setup the misc vector right here
  6291. * to handle admin queue events etc. In case of legacy and MSI
  6292. * the misc functionality and queue processing is combined in
  6293. * the same vector and that gets setup at open.
  6294. */
  6295. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  6296. err = i40e_setup_misc_vector(pf);
  6297. if (err) {
  6298. dev_info(&pdev->dev,
  6299. "setup of misc vector failed: %d\n", err);
  6300. goto err_vsis;
  6301. }
  6302. }
  6303. /* prep for VF support */
  6304. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  6305. (pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  6306. u32 val;
  6307. /* disable link interrupts for VFs */
  6308. val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
  6309. val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
  6310. wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
  6311. i40e_flush(hw);
  6312. }
  6313. i40e_dbg_pf_init(pf);
  6314. /* tell the firmware that we're starting */
  6315. dv.major_version = DRV_VERSION_MAJOR;
  6316. dv.minor_version = DRV_VERSION_MINOR;
  6317. dv.build_version = DRV_VERSION_BUILD;
  6318. dv.subbuild_version = 0;
  6319. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  6320. /* since everything's happy, start the service_task timer */
  6321. mod_timer(&pf->service_timer,
  6322. round_jiffies(jiffies + pf->service_timer_period));
  6323. return 0;
  6324. /* Unwind what we've done if something failed in the setup */
  6325. err_vsis:
  6326. set_bit(__I40E_DOWN, &pf->state);
  6327. err_switch_setup:
  6328. i40e_clear_interrupt_scheme(pf);
  6329. kfree(pf->vsi);
  6330. del_timer_sync(&pf->service_timer);
  6331. err_mac_addr:
  6332. err_configure_lan_hmc:
  6333. (void)i40e_shutdown_lan_hmc(hw);
  6334. err_init_lan_hmc:
  6335. kfree(pf->qp_pile);
  6336. kfree(pf->irq_pile);
  6337. err_sw_init:
  6338. err_adminq_setup:
  6339. (void)i40e_shutdown_adminq(hw);
  6340. err_pf_reset:
  6341. iounmap(hw->hw_addr);
  6342. err_ioremap:
  6343. kfree(pf);
  6344. err_pf_alloc:
  6345. pci_disable_pcie_error_reporting(pdev);
  6346. pci_release_selected_regions(pdev,
  6347. pci_select_bars(pdev, IORESOURCE_MEM));
  6348. err_pci_reg:
  6349. err_dma:
  6350. pci_disable_device(pdev);
  6351. return err;
  6352. }
  6353. /**
  6354. * i40e_remove - Device removal routine
  6355. * @pdev: PCI device information struct
  6356. *
  6357. * i40e_remove is called by the PCI subsystem to alert the driver
  6358. * that is should release a PCI device. This could be caused by a
  6359. * Hot-Plug event, or because the driver is going to be removed from
  6360. * memory.
  6361. **/
  6362. static void i40e_remove(struct pci_dev *pdev)
  6363. {
  6364. struct i40e_pf *pf = pci_get_drvdata(pdev);
  6365. i40e_status ret_code;
  6366. u32 reg;
  6367. int i;
  6368. i40e_dbg_pf_exit(pf);
  6369. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  6370. i40e_free_vfs(pf);
  6371. pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
  6372. }
  6373. /* no more scheduling of any task */
  6374. set_bit(__I40E_DOWN, &pf->state);
  6375. del_timer_sync(&pf->service_timer);
  6376. cancel_work_sync(&pf->service_task);
  6377. i40e_fdir_teardown(pf);
  6378. /* If there is a switch structure or any orphans, remove them.
  6379. * This will leave only the PF's VSI remaining.
  6380. */
  6381. for (i = 0; i < I40E_MAX_VEB; i++) {
  6382. if (!pf->veb[i])
  6383. continue;
  6384. if (pf->veb[i]->uplink_seid == pf->mac_seid ||
  6385. pf->veb[i]->uplink_seid == 0)
  6386. i40e_switch_branch_release(pf->veb[i]);
  6387. }
  6388. /* Now we can shutdown the PF's VSI, just before we kill
  6389. * adminq and hmc.
  6390. */
  6391. if (pf->vsi[pf->lan_vsi])
  6392. i40e_vsi_release(pf->vsi[pf->lan_vsi]);
  6393. i40e_stop_misc_vector(pf);
  6394. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  6395. synchronize_irq(pf->msix_entries[0].vector);
  6396. free_irq(pf->msix_entries[0].vector, pf);
  6397. }
  6398. /* shutdown and destroy the HMC */
  6399. ret_code = i40e_shutdown_lan_hmc(&pf->hw);
  6400. if (ret_code)
  6401. dev_warn(&pdev->dev,
  6402. "Failed to destroy the HMC resources: %d\n", ret_code);
  6403. /* shutdown the adminq */
  6404. i40e_aq_queue_shutdown(&pf->hw, true);
  6405. ret_code = i40e_shutdown_adminq(&pf->hw);
  6406. if (ret_code)
  6407. dev_warn(&pdev->dev,
  6408. "Failed to destroy the Admin Queue resources: %d\n",
  6409. ret_code);
  6410. /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
  6411. i40e_clear_interrupt_scheme(pf);
  6412. for (i = 0; i < pf->hw.func_caps.num_vsis; i++) {
  6413. if (pf->vsi[i]) {
  6414. i40e_vsi_clear_rings(pf->vsi[i]);
  6415. i40e_vsi_clear(pf->vsi[i]);
  6416. pf->vsi[i] = NULL;
  6417. }
  6418. }
  6419. for (i = 0; i < I40E_MAX_VEB; i++) {
  6420. kfree(pf->veb[i]);
  6421. pf->veb[i] = NULL;
  6422. }
  6423. kfree(pf->qp_pile);
  6424. kfree(pf->irq_pile);
  6425. kfree(pf->sw_config);
  6426. kfree(pf->vsi);
  6427. /* force a PF reset to clean anything leftover */
  6428. reg = rd32(&pf->hw, I40E_PFGEN_CTRL);
  6429. wr32(&pf->hw, I40E_PFGEN_CTRL, (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
  6430. i40e_flush(&pf->hw);
  6431. iounmap(pf->hw.hw_addr);
  6432. kfree(pf);
  6433. pci_release_selected_regions(pdev,
  6434. pci_select_bars(pdev, IORESOURCE_MEM));
  6435. pci_disable_pcie_error_reporting(pdev);
  6436. pci_disable_device(pdev);
  6437. }
  6438. /**
  6439. * i40e_pci_error_detected - warning that something funky happened in PCI land
  6440. * @pdev: PCI device information struct
  6441. *
  6442. * Called to warn that something happened and the error handling steps
  6443. * are in progress. Allows the driver to quiesce things, be ready for
  6444. * remediation.
  6445. **/
  6446. static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
  6447. enum pci_channel_state error)
  6448. {
  6449. struct i40e_pf *pf = pci_get_drvdata(pdev);
  6450. dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
  6451. /* shutdown all operations */
  6452. i40e_pf_quiesce_all_vsi(pf);
  6453. /* Request a slot reset */
  6454. return PCI_ERS_RESULT_NEED_RESET;
  6455. }
  6456. /**
  6457. * i40e_pci_error_slot_reset - a PCI slot reset just happened
  6458. * @pdev: PCI device information struct
  6459. *
  6460. * Called to find if the driver can work with the device now that
  6461. * the pci slot has been reset. If a basic connection seems good
  6462. * (registers are readable and have sane content) then return a
  6463. * happy little PCI_ERS_RESULT_xxx.
  6464. **/
  6465. static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
  6466. {
  6467. struct i40e_pf *pf = pci_get_drvdata(pdev);
  6468. pci_ers_result_t result;
  6469. int err;
  6470. u32 reg;
  6471. dev_info(&pdev->dev, "%s\n", __func__);
  6472. if (pci_enable_device_mem(pdev)) {
  6473. dev_info(&pdev->dev,
  6474. "Cannot re-enable PCI device after reset.\n");
  6475. result = PCI_ERS_RESULT_DISCONNECT;
  6476. } else {
  6477. pci_set_master(pdev);
  6478. pci_restore_state(pdev);
  6479. pci_save_state(pdev);
  6480. pci_wake_from_d3(pdev, false);
  6481. reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  6482. if (reg == 0)
  6483. result = PCI_ERS_RESULT_RECOVERED;
  6484. else
  6485. result = PCI_ERS_RESULT_DISCONNECT;
  6486. }
  6487. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  6488. if (err) {
  6489. dev_info(&pdev->dev,
  6490. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
  6491. err);
  6492. /* non-fatal, continue */
  6493. }
  6494. return result;
  6495. }
  6496. /**
  6497. * i40e_pci_error_resume - restart operations after PCI error recovery
  6498. * @pdev: PCI device information struct
  6499. *
  6500. * Called to allow the driver to bring things back up after PCI error
  6501. * and/or reset recovery has finished.
  6502. **/
  6503. static void i40e_pci_error_resume(struct pci_dev *pdev)
  6504. {
  6505. struct i40e_pf *pf = pci_get_drvdata(pdev);
  6506. dev_info(&pdev->dev, "%s\n", __func__);
  6507. i40e_handle_reset_warning(pf);
  6508. }
  6509. static const struct pci_error_handlers i40e_err_handler = {
  6510. .error_detected = i40e_pci_error_detected,
  6511. .slot_reset = i40e_pci_error_slot_reset,
  6512. .resume = i40e_pci_error_resume,
  6513. };
  6514. static struct pci_driver i40e_driver = {
  6515. .name = i40e_driver_name,
  6516. .id_table = i40e_pci_tbl,
  6517. .probe = i40e_probe,
  6518. .remove = i40e_remove,
  6519. .err_handler = &i40e_err_handler,
  6520. .sriov_configure = i40e_pci_sriov_configure,
  6521. };
  6522. /**
  6523. * i40e_init_module - Driver registration routine
  6524. *
  6525. * i40e_init_module is the first routine called when the driver is
  6526. * loaded. All it does is register with the PCI subsystem.
  6527. **/
  6528. static int __init i40e_init_module(void)
  6529. {
  6530. pr_info("%s: %s - version %s\n", i40e_driver_name,
  6531. i40e_driver_string, i40e_driver_version_str);
  6532. pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
  6533. i40e_dbg_init();
  6534. return pci_register_driver(&i40e_driver);
  6535. }
  6536. module_init(i40e_init_module);
  6537. /**
  6538. * i40e_exit_module - Driver exit cleanup routine
  6539. *
  6540. * i40e_exit_module is called just before the driver is removed
  6541. * from memory.
  6542. **/
  6543. static void __exit i40e_exit_module(void)
  6544. {
  6545. pci_unregister_driver(&i40e_driver);
  6546. i40e_dbg_exit();
  6547. }
  6548. module_exit(i40e_exit_module);