ixgbe_main.c 318 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 1999 - 2018 Intel Corporation. */
  3. #include <linux/types.h>
  4. #include <linux/module.h>
  5. #include <linux/pci.h>
  6. #include <linux/netdevice.h>
  7. #include <linux/vmalloc.h>
  8. #include <linux/string.h>
  9. #include <linux/in.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/ip.h>
  12. #include <linux/tcp.h>
  13. #include <linux/sctp.h>
  14. #include <linux/pkt_sched.h>
  15. #include <linux/ipv6.h>
  16. #include <linux/slab.h>
  17. #include <net/checksum.h>
  18. #include <net/ip6_checksum.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/ethtool.h>
  21. #include <linux/if.h>
  22. #include <linux/if_vlan.h>
  23. #include <linux/if_macvlan.h>
  24. #include <linux/if_bridge.h>
  25. #include <linux/prefetch.h>
  26. #include <linux/bpf.h>
  27. #include <linux/bpf_trace.h>
  28. #include <linux/atomic.h>
  29. #include <linux/numa.h>
  30. #include <generated/utsrelease.h>
  31. #include <scsi/fc/fc_fcoe.h>
  32. #include <net/udp_tunnel.h>
  33. #include <net/pkt_cls.h>
  34. #include <net/tc_act/tc_gact.h>
  35. #include <net/tc_act/tc_mirred.h>
  36. #include <net/vxlan.h>
  37. #include <net/mpls.h>
  38. #include <net/netdev_queues.h>
  39. #include <net/xdp_sock_drv.h>
  40. #include <net/xfrm.h>
  41. #include "ixgbe.h"
  42. #include "ixgbe_common.h"
  43. #include "ixgbe_dcb_82599.h"
  44. #include "ixgbe_phy.h"
  45. #include "ixgbe_sriov.h"
  46. #include "ixgbe_model.h"
  47. #include "ixgbe_txrx_common.h"
  48. char ixgbe_driver_name[] = "ixgbe";
  49. static const char ixgbe_driver_string[] =
  50. "Intel(R) 10 Gigabit PCI Express Network Driver";
  51. #ifdef IXGBE_FCOE
  52. char ixgbe_default_device_descr[] =
  53. "Intel(R) 10 Gigabit Network Connection";
  54. #else
  55. static char ixgbe_default_device_descr[] =
  56. "Intel(R) 10 Gigabit Network Connection";
  57. #endif
  58. static const char ixgbe_copyright[] =
  59. "Copyright (c) 1999-2016 Intel Corporation.";
  60. static const char ixgbe_overheat_msg[] = "Network adapter has been stopped because it has over heated. Restart the computer. If the problem persists, power off the system and replace the adapter";
  61. static const struct ixgbe_info *ixgbe_info_tbl[] = {
  62. [board_82598] = &ixgbe_82598_info,
  63. [board_82599] = &ixgbe_82599_info,
  64. [board_X540] = &ixgbe_X540_info,
  65. [board_X550] = &ixgbe_X550_info,
  66. [board_X550EM_x] = &ixgbe_X550EM_x_info,
  67. [board_x550em_x_fw] = &ixgbe_x550em_x_fw_info,
  68. [board_x550em_a] = &ixgbe_x550em_a_info,
  69. [board_x550em_a_fw] = &ixgbe_x550em_a_fw_info,
  70. };
  71. /* ixgbe_pci_tbl - PCI Device ID Table
  72. *
  73. * Wildcard entries (PCI_ANY_ID) should come last
  74. * Last entry must be all 0s
  75. *
  76. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  77. * Class, Class Mask, private data (not used) }
  78. */
  79. static const struct pci_device_id ixgbe_pci_tbl[] = {
  80. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
  81. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
  82. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
  83. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
  84. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
  85. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
  86. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
  87. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
  88. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
  89. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
  90. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
  91. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
  92. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
  93. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
  94. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
  95. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
  96. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
  97. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
  98. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
  99. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
  100. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
  101. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
  102. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
  103. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
  104. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
  105. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
  106. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 },
  107. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
  108. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
  109. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
  110. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550},
  111. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550},
  112. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x},
  113. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_XFI), board_X550EM_x},
  114. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x},
  115. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x},
  116. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x},
  117. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_1G_T), board_x550em_x_fw},
  118. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a },
  119. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR_L), board_x550em_a },
  120. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP_N), board_x550em_a },
  121. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a },
  122. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII_L), board_x550em_a },
  123. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_10G_T), board_x550em_a},
  124. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a },
  125. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T), board_x550em_a_fw },
  126. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T_L), board_x550em_a_fw },
  127. /* required last entry */
  128. {0, }
  129. };
  130. MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
  131. #ifdef CONFIG_IXGBE_DCA
  132. static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
  133. void *p);
  134. static struct notifier_block dca_notifier = {
  135. .notifier_call = ixgbe_notify_dca,
  136. .next = NULL,
  137. .priority = 0
  138. };
  139. #endif
  140. #ifdef CONFIG_PCI_IOV
  141. static unsigned int max_vfs;
  142. module_param(max_vfs, uint, 0);
  143. MODULE_PARM_DESC(max_vfs,
  144. "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63. (Deprecated)");
  145. #endif /* CONFIG_PCI_IOV */
  146. static bool allow_unsupported_sfp;
  147. module_param(allow_unsupported_sfp, bool, 0444);
  148. MODULE_PARM_DESC(allow_unsupported_sfp,
  149. "Allow unsupported and untested SFP+ modules on 82599-based adapters");
  150. #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
  151. static int debug = -1;
  152. module_param(debug, int, 0);
  153. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  154. MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
  155. MODULE_LICENSE("GPL v2");
  156. DEFINE_STATIC_KEY_FALSE(ixgbe_xdp_locking_key);
  157. EXPORT_SYMBOL(ixgbe_xdp_locking_key);
  158. static struct workqueue_struct *ixgbe_wq;
  159. static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
  160. static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *);
  161. static const struct net_device_ops ixgbe_netdev_ops;
  162. static bool netif_is_ixgbe(struct net_device *dev)
  163. {
  164. return dev && (dev->netdev_ops == &ixgbe_netdev_ops);
  165. }
  166. static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
  167. u32 reg, u16 *value)
  168. {
  169. struct pci_dev *parent_dev;
  170. struct pci_bus *parent_bus;
  171. parent_bus = adapter->pdev->bus->parent;
  172. if (!parent_bus)
  173. return -1;
  174. parent_dev = parent_bus->self;
  175. if (!parent_dev)
  176. return -1;
  177. if (!pci_is_pcie(parent_dev))
  178. return -1;
  179. pcie_capability_read_word(parent_dev, reg, value);
  180. if (*value == IXGBE_FAILED_READ_CFG_WORD &&
  181. ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
  182. return -1;
  183. return 0;
  184. }
  185. static int ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
  186. {
  187. struct ixgbe_hw *hw = &adapter->hw;
  188. u16 link_status = 0;
  189. int err;
  190. hw->bus.type = ixgbe_bus_type_pci_express;
  191. /* Get the negotiated link width and speed from PCI config space of the
  192. * parent, as this device is behind a switch
  193. */
  194. err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
  195. /* assume caller will handle error case */
  196. if (err)
  197. return err;
  198. hw->bus.width = ixgbe_convert_bus_width(link_status);
  199. hw->bus.speed = ixgbe_convert_bus_speed(link_status);
  200. return 0;
  201. }
  202. /**
  203. * ixgbe_pcie_from_parent - Determine whether PCIe info should come from parent
  204. * @hw: hw specific details
  205. *
  206. * This function is used by probe to determine whether a device's PCI-Express
  207. * bandwidth details should be gathered from the parent bus instead of from the
  208. * device. Used to ensure that various locations all have the correct device ID
  209. * checks.
  210. */
  211. static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
  212. {
  213. switch (hw->device_id) {
  214. case IXGBE_DEV_ID_82599_SFP_SF_QP:
  215. case IXGBE_DEV_ID_82599_QSFP_SF_QP:
  216. return true;
  217. default:
  218. return false;
  219. }
  220. }
  221. static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
  222. int expected_gts)
  223. {
  224. struct ixgbe_hw *hw = &adapter->hw;
  225. struct pci_dev *pdev;
  226. /* Some devices are not connected over PCIe and thus do not negotiate
  227. * speed. These devices do not have valid bus info, and thus any report
  228. * we generate may not be correct.
  229. */
  230. if (hw->bus.type == ixgbe_bus_type_internal)
  231. return;
  232. /* determine whether to use the parent device */
  233. if (ixgbe_pcie_from_parent(&adapter->hw))
  234. pdev = adapter->pdev->bus->parent->self;
  235. else
  236. pdev = adapter->pdev;
  237. pcie_print_link_status(pdev);
  238. }
  239. static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
  240. {
  241. if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
  242. !test_bit(__IXGBE_REMOVING, &adapter->state) &&
  243. !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
  244. queue_work(ixgbe_wq, &adapter->service_task);
  245. }
  246. static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
  247. {
  248. struct ixgbe_adapter *adapter = hw->back;
  249. if (!hw->hw_addr)
  250. return;
  251. hw->hw_addr = NULL;
  252. e_dev_err("Adapter removed\n");
  253. if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
  254. ixgbe_service_event_schedule(adapter);
  255. }
  256. static u32 ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
  257. {
  258. u8 __iomem *reg_addr;
  259. u32 value;
  260. int i;
  261. reg_addr = READ_ONCE(hw->hw_addr);
  262. if (ixgbe_removed(reg_addr))
  263. return IXGBE_FAILED_READ_REG;
  264. /* Register read of 0xFFFFFFF can indicate the adapter has been removed,
  265. * so perform several status register reads to determine if the adapter
  266. * has been removed.
  267. */
  268. for (i = 0; i < IXGBE_FAILED_READ_RETRIES; i++) {
  269. value = readl(reg_addr + IXGBE_STATUS);
  270. if (value != IXGBE_FAILED_READ_REG)
  271. break;
  272. mdelay(3);
  273. }
  274. if (value == IXGBE_FAILED_READ_REG)
  275. ixgbe_remove_adapter(hw);
  276. else
  277. value = readl(reg_addr + reg);
  278. return value;
  279. }
  280. /**
  281. * ixgbe_read_reg - Read from device register
  282. * @hw: hw specific details
  283. * @reg: offset of register to read
  284. *
  285. * Returns : value read or IXGBE_FAILED_READ_REG if removed
  286. *
  287. * This function is used to read device registers. It checks for device
  288. * removal by confirming any read that returns all ones by checking the
  289. * status register value for all ones. This function avoids reading from
  290. * the hardware if a removal was previously detected in which case it
  291. * returns IXGBE_FAILED_READ_REG (all ones).
  292. */
  293. u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
  294. {
  295. u8 __iomem *reg_addr = READ_ONCE(hw->hw_addr);
  296. u32 value;
  297. if (ixgbe_removed(reg_addr))
  298. return IXGBE_FAILED_READ_REG;
  299. if (unlikely(hw->phy.nw_mng_if_sel &
  300. IXGBE_NW_MNG_IF_SEL_SGMII_ENABLE)) {
  301. struct ixgbe_adapter *adapter;
  302. int i;
  303. for (i = 0; i < 200; ++i) {
  304. value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY);
  305. if (likely(!value))
  306. goto writes_completed;
  307. if (value == IXGBE_FAILED_READ_REG) {
  308. ixgbe_remove_adapter(hw);
  309. return IXGBE_FAILED_READ_REG;
  310. }
  311. udelay(5);
  312. }
  313. adapter = hw->back;
  314. e_warn(hw, "register writes incomplete %08x\n", value);
  315. }
  316. writes_completed:
  317. value = readl(reg_addr + reg);
  318. if (unlikely(value == IXGBE_FAILED_READ_REG))
  319. value = ixgbe_check_remove(hw, reg);
  320. return value;
  321. }
  322. static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
  323. {
  324. u16 value;
  325. pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
  326. if (value == IXGBE_FAILED_READ_CFG_WORD) {
  327. ixgbe_remove_adapter(hw);
  328. return true;
  329. }
  330. return false;
  331. }
  332. u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
  333. {
  334. struct ixgbe_adapter *adapter = hw->back;
  335. u16 value;
  336. if (ixgbe_removed(hw->hw_addr))
  337. return IXGBE_FAILED_READ_CFG_WORD;
  338. pci_read_config_word(adapter->pdev, reg, &value);
  339. if (value == IXGBE_FAILED_READ_CFG_WORD &&
  340. ixgbe_check_cfg_remove(hw, adapter->pdev))
  341. return IXGBE_FAILED_READ_CFG_WORD;
  342. return value;
  343. }
  344. #ifdef CONFIG_PCI_IOV
  345. static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
  346. {
  347. struct ixgbe_adapter *adapter = hw->back;
  348. u32 value;
  349. if (ixgbe_removed(hw->hw_addr))
  350. return IXGBE_FAILED_READ_CFG_DWORD;
  351. pci_read_config_dword(adapter->pdev, reg, &value);
  352. if (value == IXGBE_FAILED_READ_CFG_DWORD &&
  353. ixgbe_check_cfg_remove(hw, adapter->pdev))
  354. return IXGBE_FAILED_READ_CFG_DWORD;
  355. return value;
  356. }
  357. #endif /* CONFIG_PCI_IOV */
  358. void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
  359. {
  360. struct ixgbe_adapter *adapter = hw->back;
  361. if (ixgbe_removed(hw->hw_addr))
  362. return;
  363. pci_write_config_word(adapter->pdev, reg, value);
  364. }
  365. static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
  366. {
  367. BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
  368. /* flush memory to make sure state is correct before next watchdog */
  369. smp_mb__before_atomic();
  370. clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
  371. }
  372. struct ixgbe_reg_info {
  373. u32 ofs;
  374. char *name;
  375. };
  376. static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
  377. /* General Registers */
  378. {IXGBE_CTRL, "CTRL"},
  379. {IXGBE_STATUS, "STATUS"},
  380. {IXGBE_CTRL_EXT, "CTRL_EXT"},
  381. /* Interrupt Registers */
  382. {IXGBE_EICR, "EICR"},
  383. /* RX Registers */
  384. {IXGBE_SRRCTL(0), "SRRCTL"},
  385. {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
  386. {IXGBE_RDLEN(0), "RDLEN"},
  387. {IXGBE_RDH(0), "RDH"},
  388. {IXGBE_RDT(0), "RDT"},
  389. {IXGBE_RXDCTL(0), "RXDCTL"},
  390. {IXGBE_RDBAL(0), "RDBAL"},
  391. {IXGBE_RDBAH(0), "RDBAH"},
  392. /* TX Registers */
  393. {IXGBE_TDBAL(0), "TDBAL"},
  394. {IXGBE_TDBAH(0), "TDBAH"},
  395. {IXGBE_TDLEN(0), "TDLEN"},
  396. {IXGBE_TDH(0), "TDH"},
  397. {IXGBE_TDT(0), "TDT"},
  398. {IXGBE_TXDCTL(0), "TXDCTL"},
  399. /* List Terminator */
  400. { .name = NULL }
  401. };
  402. /*
  403. * ixgbe_regdump - register printout routine
  404. */
  405. static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
  406. {
  407. int i;
  408. char rname[16];
  409. u32 regs[64];
  410. switch (reginfo->ofs) {
  411. case IXGBE_SRRCTL(0):
  412. for (i = 0; i < 64; i++)
  413. regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
  414. break;
  415. case IXGBE_DCA_RXCTRL(0):
  416. for (i = 0; i < 64; i++)
  417. regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
  418. break;
  419. case IXGBE_RDLEN(0):
  420. for (i = 0; i < 64; i++)
  421. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
  422. break;
  423. case IXGBE_RDH(0):
  424. for (i = 0; i < 64; i++)
  425. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
  426. break;
  427. case IXGBE_RDT(0):
  428. for (i = 0; i < 64; i++)
  429. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
  430. break;
  431. case IXGBE_RXDCTL(0):
  432. for (i = 0; i < 64; i++)
  433. regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
  434. break;
  435. case IXGBE_RDBAL(0):
  436. for (i = 0; i < 64; i++)
  437. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
  438. break;
  439. case IXGBE_RDBAH(0):
  440. for (i = 0; i < 64; i++)
  441. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
  442. break;
  443. case IXGBE_TDBAL(0):
  444. for (i = 0; i < 64; i++)
  445. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
  446. break;
  447. case IXGBE_TDBAH(0):
  448. for (i = 0; i < 64; i++)
  449. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
  450. break;
  451. case IXGBE_TDLEN(0):
  452. for (i = 0; i < 64; i++)
  453. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
  454. break;
  455. case IXGBE_TDH(0):
  456. for (i = 0; i < 64; i++)
  457. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
  458. break;
  459. case IXGBE_TDT(0):
  460. for (i = 0; i < 64; i++)
  461. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
  462. break;
  463. case IXGBE_TXDCTL(0):
  464. for (i = 0; i < 64; i++)
  465. regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
  466. break;
  467. default:
  468. pr_info("%-15s %08x\n",
  469. reginfo->name, IXGBE_READ_REG(hw, reginfo->ofs));
  470. return;
  471. }
  472. i = 0;
  473. while (i < 64) {
  474. int j;
  475. char buf[9 * 8 + 1];
  476. char *p = buf;
  477. snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i, i + 7);
  478. for (j = 0; j < 8; j++)
  479. p += sprintf(p, " %08x", regs[i++]);
  480. pr_err("%-15s%s\n", rname, buf);
  481. }
  482. }
  483. static void ixgbe_print_buffer(struct ixgbe_ring *ring, int n)
  484. {
  485. struct ixgbe_tx_buffer *tx_buffer;
  486. tx_buffer = &ring->tx_buffer_info[ring->next_to_clean];
  487. pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
  488. n, ring->next_to_use, ring->next_to_clean,
  489. (u64)dma_unmap_addr(tx_buffer, dma),
  490. dma_unmap_len(tx_buffer, len),
  491. tx_buffer->next_to_watch,
  492. (u64)tx_buffer->time_stamp);
  493. }
  494. /*
  495. * ixgbe_dump - Print registers, tx-rings and rx-rings
  496. */
  497. static void ixgbe_dump(struct ixgbe_adapter *adapter)
  498. {
  499. struct net_device *netdev = adapter->netdev;
  500. struct ixgbe_hw *hw = &adapter->hw;
  501. struct ixgbe_reg_info *reginfo;
  502. int n = 0;
  503. struct ixgbe_ring *ring;
  504. struct ixgbe_tx_buffer *tx_buffer;
  505. union ixgbe_adv_tx_desc *tx_desc;
  506. struct my_u0 { u64 a; u64 b; } *u0;
  507. struct ixgbe_ring *rx_ring;
  508. union ixgbe_adv_rx_desc *rx_desc;
  509. struct ixgbe_rx_buffer *rx_buffer_info;
  510. int i = 0;
  511. if (!netif_msg_hw(adapter))
  512. return;
  513. /* Print netdevice Info */
  514. if (netdev) {
  515. dev_info(&adapter->pdev->dev, "Net device Info\n");
  516. pr_info("Device Name state "
  517. "trans_start\n");
  518. pr_info("%-15s %016lX %016lX\n",
  519. netdev->name,
  520. netdev->state,
  521. dev_trans_start(netdev));
  522. }
  523. /* Print Registers */
  524. dev_info(&adapter->pdev->dev, "Register Dump\n");
  525. pr_info(" Register Name Value\n");
  526. for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
  527. reginfo->name; reginfo++) {
  528. ixgbe_regdump(hw, reginfo);
  529. }
  530. /* Print TX Ring Summary */
  531. if (!netdev || !netif_running(netdev))
  532. return;
  533. dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
  534. pr_info(" %s %s %s %s\n",
  535. "Queue [NTU] [NTC] [bi(ntc)->dma ]",
  536. "leng", "ntw", "timestamp");
  537. for (n = 0; n < adapter->num_tx_queues; n++) {
  538. ring = adapter->tx_ring[n];
  539. ixgbe_print_buffer(ring, n);
  540. }
  541. for (n = 0; n < adapter->num_xdp_queues; n++) {
  542. ring = adapter->xdp_ring[n];
  543. ixgbe_print_buffer(ring, n);
  544. }
  545. /* Print TX Rings */
  546. if (!netif_msg_tx_done(adapter))
  547. goto rx_ring_summary;
  548. dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
  549. /* Transmit Descriptor Formats
  550. *
  551. * 82598 Advanced Transmit Descriptor
  552. * +--------------------------------------------------------------+
  553. * 0 | Buffer Address [63:0] |
  554. * +--------------------------------------------------------------+
  555. * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
  556. * +--------------------------------------------------------------+
  557. * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
  558. *
  559. * 82598 Advanced Transmit Descriptor (Write-Back Format)
  560. * +--------------------------------------------------------------+
  561. * 0 | RSV [63:0] |
  562. * +--------------------------------------------------------------+
  563. * 8 | RSV | STA | NXTSEQ |
  564. * +--------------------------------------------------------------+
  565. * 63 36 35 32 31 0
  566. *
  567. * 82599+ Advanced Transmit Descriptor
  568. * +--------------------------------------------------------------+
  569. * 0 | Buffer Address [63:0] |
  570. * +--------------------------------------------------------------+
  571. * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
  572. * +--------------------------------------------------------------+
  573. * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
  574. *
  575. * 82599+ Advanced Transmit Descriptor (Write-Back Format)
  576. * +--------------------------------------------------------------+
  577. * 0 | RSV [63:0] |
  578. * +--------------------------------------------------------------+
  579. * 8 | RSV | STA | RSV |
  580. * +--------------------------------------------------------------+
  581. * 63 36 35 32 31 0
  582. */
  583. for (n = 0; n < adapter->num_tx_queues; n++) {
  584. ring = adapter->tx_ring[n];
  585. pr_info("------------------------------------\n");
  586. pr_info("TX QUEUE INDEX = %d\n", ring->queue_index);
  587. pr_info("------------------------------------\n");
  588. pr_info("%s%s %s %s %s %s\n",
  589. "T [desc] [address 63:0 ] ",
  590. "[PlPOIdStDDt Ln] [bi->dma ] ",
  591. "leng", "ntw", "timestamp", "bi->skb");
  592. for (i = 0; ring->desc && (i < ring->count); i++) {
  593. tx_desc = IXGBE_TX_DESC(ring, i);
  594. tx_buffer = &ring->tx_buffer_info[i];
  595. u0 = (struct my_u0 *)tx_desc;
  596. if (dma_unmap_len(tx_buffer, len) > 0) {
  597. const char *ring_desc;
  598. if (i == ring->next_to_use &&
  599. i == ring->next_to_clean)
  600. ring_desc = " NTC/U";
  601. else if (i == ring->next_to_use)
  602. ring_desc = " NTU";
  603. else if (i == ring->next_to_clean)
  604. ring_desc = " NTC";
  605. else
  606. ring_desc = "";
  607. pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p%s",
  608. i,
  609. le64_to_cpu((__force __le64)u0->a),
  610. le64_to_cpu((__force __le64)u0->b),
  611. (u64)dma_unmap_addr(tx_buffer, dma),
  612. dma_unmap_len(tx_buffer, len),
  613. tx_buffer->next_to_watch,
  614. (u64)tx_buffer->time_stamp,
  615. tx_buffer->skb,
  616. ring_desc);
  617. if (netif_msg_pktdata(adapter) &&
  618. tx_buffer->skb)
  619. print_hex_dump(KERN_INFO, "",
  620. DUMP_PREFIX_ADDRESS, 16, 1,
  621. tx_buffer->skb->data,
  622. dma_unmap_len(tx_buffer, len),
  623. true);
  624. }
  625. }
  626. }
  627. /* Print RX Rings Summary */
  628. rx_ring_summary:
  629. dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
  630. pr_info("Queue [NTU] [NTC]\n");
  631. for (n = 0; n < adapter->num_rx_queues; n++) {
  632. rx_ring = adapter->rx_ring[n];
  633. pr_info("%5d %5X %5X\n",
  634. n, rx_ring->next_to_use, rx_ring->next_to_clean);
  635. }
  636. /* Print RX Rings */
  637. if (!netif_msg_rx_status(adapter))
  638. return;
  639. dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
  640. /* Receive Descriptor Formats
  641. *
  642. * 82598 Advanced Receive Descriptor (Read) Format
  643. * 63 1 0
  644. * +-----------------------------------------------------+
  645. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  646. * +----------------------------------------------+------+
  647. * 8 | Header Buffer Address [63:1] | DD |
  648. * +-----------------------------------------------------+
  649. *
  650. *
  651. * 82598 Advanced Receive Descriptor (Write-Back) Format
  652. *
  653. * 63 48 47 32 31 30 21 20 16 15 4 3 0
  654. * +------------------------------------------------------+
  655. * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
  656. * | Packet | IP | | | | Type | Type |
  657. * | Checksum | Ident | | | | | |
  658. * +------------------------------------------------------+
  659. * 8 | VLAN Tag | Length | Extended Error | Extended Status |
  660. * +------------------------------------------------------+
  661. * 63 48 47 32 31 20 19 0
  662. *
  663. * 82599+ Advanced Receive Descriptor (Read) Format
  664. * 63 1 0
  665. * +-----------------------------------------------------+
  666. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  667. * +----------------------------------------------+------+
  668. * 8 | Header Buffer Address [63:1] | DD |
  669. * +-----------------------------------------------------+
  670. *
  671. *
  672. * 82599+ Advanced Receive Descriptor (Write-Back) Format
  673. *
  674. * 63 48 47 32 31 30 21 20 17 16 4 3 0
  675. * +------------------------------------------------------+
  676. * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
  677. * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
  678. * |/ Flow Dir Flt ID | | | | | |
  679. * +------------------------------------------------------+
  680. * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
  681. * +------------------------------------------------------+
  682. * 63 48 47 32 31 20 19 0
  683. */
  684. for (n = 0; n < adapter->num_rx_queues; n++) {
  685. rx_ring = adapter->rx_ring[n];
  686. pr_info("------------------------------------\n");
  687. pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
  688. pr_info("------------------------------------\n");
  689. pr_info("%s%s%s\n",
  690. "R [desc] [ PktBuf A0] ",
  691. "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
  692. "<-- Adv Rx Read format");
  693. pr_info("%s%s%s\n",
  694. "RWB[desc] [PcsmIpSHl PtRs] ",
  695. "[vl er S cks ln] ---------------- [bi->skb ] ",
  696. "<-- Adv Rx Write-Back format");
  697. for (i = 0; i < rx_ring->count; i++) {
  698. const char *ring_desc;
  699. if (i == rx_ring->next_to_use)
  700. ring_desc = " NTU";
  701. else if (i == rx_ring->next_to_clean)
  702. ring_desc = " NTC";
  703. else
  704. ring_desc = "";
  705. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  706. rx_desc = IXGBE_RX_DESC(rx_ring, i);
  707. u0 = (struct my_u0 *)rx_desc;
  708. if (rx_desc->wb.upper.length) {
  709. /* Descriptor Done */
  710. pr_info("RWB[0x%03X] %016llX %016llX ---------------- %p%s\n",
  711. i,
  712. le64_to_cpu((__force __le64)u0->a),
  713. le64_to_cpu((__force __le64)u0->b),
  714. rx_buffer_info->skb,
  715. ring_desc);
  716. } else {
  717. pr_info("R [0x%03X] %016llX %016llX %016llX %p%s\n",
  718. i,
  719. le64_to_cpu((__force __le64)u0->a),
  720. le64_to_cpu((__force __le64)u0->b),
  721. (u64)rx_buffer_info->dma,
  722. rx_buffer_info->skb,
  723. ring_desc);
  724. if (netif_msg_pktdata(adapter) &&
  725. rx_buffer_info->dma) {
  726. print_hex_dump(KERN_INFO, "",
  727. DUMP_PREFIX_ADDRESS, 16, 1,
  728. page_address(rx_buffer_info->page) +
  729. rx_buffer_info->page_offset,
  730. ixgbe_rx_bufsz(rx_ring), true);
  731. }
  732. }
  733. }
  734. }
  735. }
  736. static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
  737. {
  738. u32 ctrl_ext;
  739. /* Let firmware take over control of h/w */
  740. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  741. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  742. ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
  743. }
  744. static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
  745. {
  746. u32 ctrl_ext;
  747. /* Let firmware know the driver has taken over */
  748. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  749. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  750. ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
  751. }
  752. /**
  753. * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
  754. * @adapter: pointer to adapter struct
  755. * @direction: 0 for Rx, 1 for Tx, -1 for other causes
  756. * @queue: queue to map the corresponding interrupt to
  757. * @msix_vector: the vector to map to the corresponding queue
  758. *
  759. */
  760. static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
  761. u8 queue, u8 msix_vector)
  762. {
  763. u32 ivar, index;
  764. struct ixgbe_hw *hw = &adapter->hw;
  765. switch (hw->mac.type) {
  766. case ixgbe_mac_82598EB:
  767. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  768. if (direction == -1)
  769. direction = 0;
  770. index = (((direction * 64) + queue) >> 2) & 0x1F;
  771. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
  772. ivar &= ~(0xFF << (8 * (queue & 0x3)));
  773. ivar |= (msix_vector << (8 * (queue & 0x3)));
  774. IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
  775. break;
  776. case ixgbe_mac_82599EB:
  777. case ixgbe_mac_X540:
  778. case ixgbe_mac_X550:
  779. case ixgbe_mac_X550EM_x:
  780. case ixgbe_mac_x550em_a:
  781. if (direction == -1) {
  782. /* other causes */
  783. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  784. index = ((queue & 1) * 8);
  785. ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
  786. ivar &= ~(0xFF << index);
  787. ivar |= (msix_vector << index);
  788. IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
  789. break;
  790. } else {
  791. /* tx or rx causes */
  792. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  793. index = ((16 * (queue & 1)) + (8 * direction));
  794. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
  795. ivar &= ~(0xFF << index);
  796. ivar |= (msix_vector << index);
  797. IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
  798. break;
  799. }
  800. default:
  801. break;
  802. }
  803. }
  804. void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
  805. u64 qmask)
  806. {
  807. u32 mask;
  808. switch (adapter->hw.mac.type) {
  809. case ixgbe_mac_82598EB:
  810. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  811. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
  812. break;
  813. case ixgbe_mac_82599EB:
  814. case ixgbe_mac_X540:
  815. case ixgbe_mac_X550:
  816. case ixgbe_mac_X550EM_x:
  817. case ixgbe_mac_x550em_a:
  818. mask = (qmask & 0xFFFFFFFF);
  819. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
  820. mask = (qmask >> 32);
  821. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
  822. break;
  823. default:
  824. break;
  825. }
  826. }
  827. static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
  828. {
  829. struct ixgbe_hw *hw = &adapter->hw;
  830. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  831. int i;
  832. u32 data;
  833. if ((hw->fc.current_mode != ixgbe_fc_full) &&
  834. (hw->fc.current_mode != ixgbe_fc_rx_pause))
  835. return;
  836. switch (hw->mac.type) {
  837. case ixgbe_mac_82598EB:
  838. data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  839. break;
  840. default:
  841. data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
  842. }
  843. hwstats->lxoffrxc += data;
  844. /* refill credits (no tx hang) if we received xoff */
  845. if (!data)
  846. return;
  847. for (i = 0; i < adapter->num_tx_queues; i++)
  848. clear_bit(__IXGBE_HANG_CHECK_ARMED,
  849. &adapter->tx_ring[i]->state);
  850. for (i = 0; i < adapter->num_xdp_queues; i++)
  851. clear_bit(__IXGBE_HANG_CHECK_ARMED,
  852. &adapter->xdp_ring[i]->state);
  853. }
  854. static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
  855. {
  856. struct ixgbe_hw *hw = &adapter->hw;
  857. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  858. u32 xoff[8] = {0};
  859. u8 tc;
  860. int i;
  861. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  862. if (adapter->ixgbe_ieee_pfc)
  863. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  864. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
  865. ixgbe_update_xoff_rx_lfc(adapter);
  866. return;
  867. }
  868. /* update stats for each tc, only valid with PFC enabled */
  869. for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
  870. u32 pxoffrxc;
  871. switch (hw->mac.type) {
  872. case ixgbe_mac_82598EB:
  873. pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
  874. break;
  875. default:
  876. pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
  877. }
  878. hwstats->pxoffrxc[i] += pxoffrxc;
  879. /* Get the TC for given UP */
  880. tc = netdev_get_prio_tc_map(adapter->netdev, i);
  881. xoff[tc] += pxoffrxc;
  882. }
  883. /* disarm tx queues that have received xoff frames */
  884. for (i = 0; i < adapter->num_tx_queues; i++) {
  885. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  886. tc = tx_ring->dcb_tc;
  887. if (xoff[tc])
  888. clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
  889. }
  890. for (i = 0; i < adapter->num_xdp_queues; i++) {
  891. struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i];
  892. tc = xdp_ring->dcb_tc;
  893. if (xoff[tc])
  894. clear_bit(__IXGBE_HANG_CHECK_ARMED, &xdp_ring->state);
  895. }
  896. }
  897. static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
  898. {
  899. return ring->stats.packets;
  900. }
  901. static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
  902. {
  903. unsigned int head, tail;
  904. head = ring->next_to_clean;
  905. tail = ring->next_to_use;
  906. return ((head <= tail) ? tail : tail + ring->count) - head;
  907. }
  908. static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
  909. {
  910. u32 tx_done = ixgbe_get_tx_completed(tx_ring);
  911. u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
  912. u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
  913. clear_check_for_tx_hang(tx_ring);
  914. /*
  915. * Check for a hung queue, but be thorough. This verifies
  916. * that a transmit has been completed since the previous
  917. * check AND there is at least one packet pending. The
  918. * ARMED bit is set to indicate a potential hang. The
  919. * bit is cleared if a pause frame is received to remove
  920. * false hang detection due to PFC or 802.3x frames. By
  921. * requiring this to fail twice we avoid races with
  922. * pfc clearing the ARMED bit and conditions where we
  923. * run the check_tx_hang logic with a transmit completion
  924. * pending but without time to complete it yet.
  925. */
  926. if (tx_done_old == tx_done && tx_pending)
  927. /* make sure it is true for two checks in a row */
  928. return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
  929. &tx_ring->state);
  930. /* update completed stats and continue */
  931. tx_ring->tx_stats.tx_done_old = tx_done;
  932. /* reset the countdown */
  933. clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
  934. return false;
  935. }
  936. /**
  937. * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
  938. * @adapter: driver private struct
  939. **/
  940. static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
  941. {
  942. /* Do the reset outside of interrupt context */
  943. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  944. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  945. e_warn(drv, "initiating reset due to tx timeout\n");
  946. ixgbe_service_event_schedule(adapter);
  947. }
  948. }
  949. /**
  950. * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
  951. * @netdev: network interface device structure
  952. * @queue_index: Tx queue to set
  953. * @maxrate: desired maximum transmit bitrate
  954. **/
  955. static int ixgbe_tx_maxrate(struct net_device *netdev,
  956. int queue_index, u32 maxrate)
  957. {
  958. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  959. struct ixgbe_hw *hw = &adapter->hw;
  960. u32 bcnrc_val = ixgbe_link_mbps(adapter);
  961. if (!maxrate)
  962. return 0;
  963. /* Calculate the rate factor values to set */
  964. bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
  965. bcnrc_val /= maxrate;
  966. /* clear everything but the rate factor */
  967. bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
  968. IXGBE_RTTBCNRC_RF_DEC_MASK;
  969. /* enable the rate scheduler */
  970. bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
  971. IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index);
  972. IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
  973. return 0;
  974. }
  975. /**
  976. * ixgbe_update_tx_ring_stats - Update Tx ring specific counters
  977. * @tx_ring: ring to update
  978. * @q_vector: queue vector ring belongs to
  979. * @pkts: number of processed packets
  980. * @bytes: number of processed bytes
  981. */
  982. void ixgbe_update_tx_ring_stats(struct ixgbe_ring *tx_ring,
  983. struct ixgbe_q_vector *q_vector, u64 pkts,
  984. u64 bytes)
  985. {
  986. u64_stats_update_begin(&tx_ring->syncp);
  987. tx_ring->stats.bytes += bytes;
  988. tx_ring->stats.packets += pkts;
  989. u64_stats_update_end(&tx_ring->syncp);
  990. q_vector->tx.total_bytes += bytes;
  991. q_vector->tx.total_packets += pkts;
  992. }
  993. /**
  994. * ixgbe_update_rx_ring_stats - Update Rx ring specific counters
  995. * @rx_ring: ring to update
  996. * @q_vector: queue vector ring belongs to
  997. * @pkts: number of processed packets
  998. * @bytes: number of processed bytes
  999. */
  1000. void ixgbe_update_rx_ring_stats(struct ixgbe_ring *rx_ring,
  1001. struct ixgbe_q_vector *q_vector, u64 pkts,
  1002. u64 bytes)
  1003. {
  1004. u64_stats_update_begin(&rx_ring->syncp);
  1005. rx_ring->stats.bytes += bytes;
  1006. rx_ring->stats.packets += pkts;
  1007. u64_stats_update_end(&rx_ring->syncp);
  1008. q_vector->rx.total_bytes += bytes;
  1009. q_vector->rx.total_packets += pkts;
  1010. }
  1011. /**
  1012. * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
  1013. * @q_vector: structure containing interrupt and ring information
  1014. * @tx_ring: tx ring to clean
  1015. * @napi_budget: Used to determine if we are in netpoll
  1016. **/
  1017. static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
  1018. struct ixgbe_ring *tx_ring, int napi_budget)
  1019. {
  1020. struct ixgbe_adapter *adapter = q_vector->adapter;
  1021. struct ixgbe_tx_buffer *tx_buffer;
  1022. union ixgbe_adv_tx_desc *tx_desc;
  1023. unsigned int total_bytes = 0, total_packets = 0, total_ipsec = 0;
  1024. unsigned int budget = q_vector->tx.work_limit;
  1025. unsigned int i = tx_ring->next_to_clean;
  1026. struct netdev_queue *txq;
  1027. if (test_bit(__IXGBE_DOWN, &adapter->state))
  1028. return true;
  1029. tx_buffer = &tx_ring->tx_buffer_info[i];
  1030. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  1031. i -= tx_ring->count;
  1032. do {
  1033. union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
  1034. /* if next_to_watch is not set then there is no work pending */
  1035. if (!eop_desc)
  1036. break;
  1037. /* prevent any other reads prior to eop_desc */
  1038. smp_rmb();
  1039. /* if DD is not set pending work has not been completed */
  1040. if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
  1041. break;
  1042. /* clear next_to_watch to prevent false hangs */
  1043. tx_buffer->next_to_watch = NULL;
  1044. /* update the statistics for this packet */
  1045. total_bytes += tx_buffer->bytecount;
  1046. total_packets += tx_buffer->gso_segs;
  1047. if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_IPSEC)
  1048. total_ipsec++;
  1049. /* free the skb */
  1050. if (ring_is_xdp(tx_ring))
  1051. xdp_return_frame(tx_buffer->xdpf);
  1052. else
  1053. napi_consume_skb(tx_buffer->skb, napi_budget);
  1054. /* unmap skb header data */
  1055. dma_unmap_single(tx_ring->dev,
  1056. dma_unmap_addr(tx_buffer, dma),
  1057. dma_unmap_len(tx_buffer, len),
  1058. DMA_TO_DEVICE);
  1059. /* clear tx_buffer data */
  1060. dma_unmap_len_set(tx_buffer, len, 0);
  1061. /* unmap remaining buffers */
  1062. while (tx_desc != eop_desc) {
  1063. tx_buffer++;
  1064. tx_desc++;
  1065. i++;
  1066. if (unlikely(!i)) {
  1067. i -= tx_ring->count;
  1068. tx_buffer = tx_ring->tx_buffer_info;
  1069. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  1070. }
  1071. /* unmap any remaining paged data */
  1072. if (dma_unmap_len(tx_buffer, len)) {
  1073. dma_unmap_page(tx_ring->dev,
  1074. dma_unmap_addr(tx_buffer, dma),
  1075. dma_unmap_len(tx_buffer, len),
  1076. DMA_TO_DEVICE);
  1077. dma_unmap_len_set(tx_buffer, len, 0);
  1078. }
  1079. }
  1080. /* move us one more past the eop_desc for start of next pkt */
  1081. tx_buffer++;
  1082. tx_desc++;
  1083. i++;
  1084. if (unlikely(!i)) {
  1085. i -= tx_ring->count;
  1086. tx_buffer = tx_ring->tx_buffer_info;
  1087. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  1088. }
  1089. /* issue prefetch for next Tx descriptor */
  1090. prefetch(tx_desc);
  1091. /* update budget accounting */
  1092. budget--;
  1093. } while (likely(budget));
  1094. i += tx_ring->count;
  1095. tx_ring->next_to_clean = i;
  1096. ixgbe_update_tx_ring_stats(tx_ring, q_vector, total_packets,
  1097. total_bytes);
  1098. adapter->tx_ipsec += total_ipsec;
  1099. if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
  1100. /* schedule immediate reset if we believe we hung */
  1101. struct ixgbe_hw *hw = &adapter->hw;
  1102. e_err(drv, "Detected Tx Unit Hang %s\n"
  1103. " Tx Queue <%d>\n"
  1104. " TDH, TDT <%x>, <%x>\n"
  1105. " next_to_use <%x>\n"
  1106. " next_to_clean <%x>\n"
  1107. "tx_buffer_info[next_to_clean]\n"
  1108. " time_stamp <%lx>\n"
  1109. " jiffies <%lx>\n",
  1110. ring_is_xdp(tx_ring) ? "(XDP)" : "",
  1111. tx_ring->queue_index,
  1112. IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
  1113. IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
  1114. tx_ring->next_to_use, i,
  1115. tx_ring->tx_buffer_info[i].time_stamp, jiffies);
  1116. if (!ring_is_xdp(tx_ring))
  1117. netif_stop_subqueue(tx_ring->netdev,
  1118. tx_ring->queue_index);
  1119. e_info(probe,
  1120. "tx hang %d detected on queue %d, resetting adapter\n",
  1121. adapter->tx_timeout_count + 1, tx_ring->queue_index);
  1122. /* schedule immediate reset if we believe we hung */
  1123. ixgbe_tx_timeout_reset(adapter);
  1124. /* the adapter is about to reset, no point in enabling stuff */
  1125. return true;
  1126. }
  1127. if (ring_is_xdp(tx_ring))
  1128. return !!budget;
  1129. #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
  1130. txq = netdev_get_tx_queue(tx_ring->netdev, tx_ring->queue_index);
  1131. if (!__netif_txq_completed_wake(txq, total_packets, total_bytes,
  1132. ixgbe_desc_unused(tx_ring),
  1133. TX_WAKE_THRESHOLD,
  1134. !netif_carrier_ok(tx_ring->netdev) ||
  1135. test_bit(__IXGBE_DOWN, &adapter->state)))
  1136. ++tx_ring->tx_stats.restart_queue;
  1137. return !!budget;
  1138. }
  1139. #ifdef CONFIG_IXGBE_DCA
  1140. static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
  1141. struct ixgbe_ring *tx_ring,
  1142. int cpu)
  1143. {
  1144. struct ixgbe_hw *hw = &adapter->hw;
  1145. u32 txctrl = 0;
  1146. u16 reg_offset;
  1147. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1148. txctrl = dca3_get_tag(tx_ring->dev, cpu);
  1149. switch (hw->mac.type) {
  1150. case ixgbe_mac_82598EB:
  1151. reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
  1152. break;
  1153. case ixgbe_mac_82599EB:
  1154. case ixgbe_mac_X540:
  1155. reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
  1156. txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
  1157. break;
  1158. default:
  1159. /* for unknown hardware do not write register */
  1160. return;
  1161. }
  1162. /*
  1163. * We can enable relaxed ordering for reads, but not writes when
  1164. * DCA is enabled. This is due to a known issue in some chipsets
  1165. * which will cause the DCA tag to be cleared.
  1166. */
  1167. txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
  1168. IXGBE_DCA_TXCTRL_DATA_RRO_EN |
  1169. IXGBE_DCA_TXCTRL_DESC_DCA_EN;
  1170. IXGBE_WRITE_REG(hw, reg_offset, txctrl);
  1171. }
  1172. static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
  1173. struct ixgbe_ring *rx_ring,
  1174. int cpu)
  1175. {
  1176. struct ixgbe_hw *hw = &adapter->hw;
  1177. u32 rxctrl = 0;
  1178. u8 reg_idx = rx_ring->reg_idx;
  1179. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1180. rxctrl = dca3_get_tag(rx_ring->dev, cpu);
  1181. switch (hw->mac.type) {
  1182. case ixgbe_mac_82599EB:
  1183. case ixgbe_mac_X540:
  1184. rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
  1185. break;
  1186. default:
  1187. break;
  1188. }
  1189. /*
  1190. * We can enable relaxed ordering for reads, but not writes when
  1191. * DCA is enabled. This is due to a known issue in some chipsets
  1192. * which will cause the DCA tag to be cleared.
  1193. */
  1194. rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
  1195. IXGBE_DCA_RXCTRL_DATA_DCA_EN |
  1196. IXGBE_DCA_RXCTRL_DESC_DCA_EN;
  1197. IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
  1198. }
  1199. static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
  1200. {
  1201. struct ixgbe_adapter *adapter = q_vector->adapter;
  1202. struct ixgbe_ring *ring;
  1203. int cpu = get_cpu();
  1204. if (q_vector->cpu == cpu)
  1205. goto out_no_update;
  1206. ixgbe_for_each_ring(ring, q_vector->tx)
  1207. ixgbe_update_tx_dca(adapter, ring, cpu);
  1208. ixgbe_for_each_ring(ring, q_vector->rx)
  1209. ixgbe_update_rx_dca(adapter, ring, cpu);
  1210. q_vector->cpu = cpu;
  1211. out_no_update:
  1212. put_cpu();
  1213. }
  1214. static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
  1215. {
  1216. int i;
  1217. /* always use CB2 mode, difference is masked in the CB driver */
  1218. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1219. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1220. IXGBE_DCA_CTRL_DCA_MODE_CB2);
  1221. else
  1222. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1223. IXGBE_DCA_CTRL_DCA_DISABLE);
  1224. for (i = 0; i < adapter->num_q_vectors; i++) {
  1225. adapter->q_vector[i]->cpu = -1;
  1226. ixgbe_update_dca(adapter->q_vector[i]);
  1227. }
  1228. }
  1229. static int __ixgbe_notify_dca(struct device *dev, void *data)
  1230. {
  1231. struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
  1232. unsigned long event = *(unsigned long *)data;
  1233. if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
  1234. return 0;
  1235. switch (event) {
  1236. case DCA_PROVIDER_ADD:
  1237. /* if we're already enabled, don't do it again */
  1238. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1239. break;
  1240. if (dca_add_requester(dev) == 0) {
  1241. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  1242. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1243. IXGBE_DCA_CTRL_DCA_MODE_CB2);
  1244. break;
  1245. }
  1246. fallthrough; /* DCA is disabled. */
  1247. case DCA_PROVIDER_REMOVE:
  1248. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  1249. dca_remove_requester(dev);
  1250. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  1251. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1252. IXGBE_DCA_CTRL_DCA_DISABLE);
  1253. }
  1254. break;
  1255. }
  1256. return 0;
  1257. }
  1258. #endif /* CONFIG_IXGBE_DCA */
  1259. #define IXGBE_RSS_L4_TYPES_MASK \
  1260. ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
  1261. (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
  1262. (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
  1263. (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
  1264. static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
  1265. union ixgbe_adv_rx_desc *rx_desc,
  1266. struct sk_buff *skb)
  1267. {
  1268. u16 rss_type;
  1269. if (!(ring->netdev->features & NETIF_F_RXHASH))
  1270. return;
  1271. rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
  1272. IXGBE_RXDADV_RSSTYPE_MASK;
  1273. if (!rss_type)
  1274. return;
  1275. skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
  1276. (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
  1277. PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
  1278. }
  1279. #ifdef IXGBE_FCOE
  1280. /**
  1281. * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
  1282. * @ring: structure containing ring specific data
  1283. * @rx_desc: advanced rx descriptor
  1284. *
  1285. * Returns : true if it is FCoE pkt
  1286. */
  1287. static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
  1288. union ixgbe_adv_rx_desc *rx_desc)
  1289. {
  1290. __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  1291. return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
  1292. ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
  1293. (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
  1294. IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
  1295. }
  1296. #endif /* IXGBE_FCOE */
  1297. /**
  1298. * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
  1299. * @ring: structure containing ring specific data
  1300. * @rx_desc: current Rx descriptor being processed
  1301. * @skb: skb currently being received and modified
  1302. **/
  1303. static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
  1304. union ixgbe_adv_rx_desc *rx_desc,
  1305. struct sk_buff *skb)
  1306. {
  1307. __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  1308. bool encap_pkt = false;
  1309. skb_checksum_none_assert(skb);
  1310. /* Rx csum disabled */
  1311. if (!(ring->netdev->features & NETIF_F_RXCSUM))
  1312. return;
  1313. /* check for VXLAN and Geneve packets */
  1314. if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) {
  1315. encap_pkt = true;
  1316. skb->encapsulation = 1;
  1317. }
  1318. /* if IP and error */
  1319. if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
  1320. ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
  1321. ring->rx_stats.csum_err++;
  1322. return;
  1323. }
  1324. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
  1325. return;
  1326. if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
  1327. /*
  1328. * 82599 errata, UDP frames with a 0 checksum can be marked as
  1329. * checksum errors.
  1330. */
  1331. if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
  1332. test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
  1333. return;
  1334. ring->rx_stats.csum_err++;
  1335. return;
  1336. }
  1337. /* It must be a TCP or UDP packet with a valid checksum */
  1338. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1339. if (encap_pkt) {
  1340. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
  1341. return;
  1342. if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
  1343. skb->ip_summed = CHECKSUM_NONE;
  1344. return;
  1345. }
  1346. /* If we checked the outer header let the stack know */
  1347. skb->csum_level = 1;
  1348. }
  1349. }
  1350. static unsigned int ixgbe_rx_offset(struct ixgbe_ring *rx_ring)
  1351. {
  1352. return ring_uses_build_skb(rx_ring) ? IXGBE_SKB_PAD : 0;
  1353. }
  1354. static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
  1355. struct ixgbe_rx_buffer *bi)
  1356. {
  1357. struct page *page = bi->page;
  1358. dma_addr_t dma;
  1359. /* since we are recycling buffers we should seldom need to alloc */
  1360. if (likely(page))
  1361. return true;
  1362. /* alloc new page for storage */
  1363. page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
  1364. if (unlikely(!page)) {
  1365. rx_ring->rx_stats.alloc_rx_page_failed++;
  1366. return false;
  1367. }
  1368. /* map page for use */
  1369. dma = dma_map_page_attrs(rx_ring->dev, page, 0,
  1370. ixgbe_rx_pg_size(rx_ring),
  1371. DMA_FROM_DEVICE,
  1372. IXGBE_RX_DMA_ATTR);
  1373. /*
  1374. * if mapping failed free memory back to system since
  1375. * there isn't much point in holding memory we can't use
  1376. */
  1377. if (dma_mapping_error(rx_ring->dev, dma)) {
  1378. __free_pages(page, ixgbe_rx_pg_order(rx_ring));
  1379. rx_ring->rx_stats.alloc_rx_page_failed++;
  1380. return false;
  1381. }
  1382. bi->dma = dma;
  1383. bi->page = page;
  1384. bi->page_offset = rx_ring->rx_offset;
  1385. page_ref_add(page, USHRT_MAX - 1);
  1386. bi->pagecnt_bias = USHRT_MAX;
  1387. rx_ring->rx_stats.alloc_rx_page++;
  1388. return true;
  1389. }
  1390. /**
  1391. * ixgbe_alloc_rx_buffers - Replace used receive buffers
  1392. * @rx_ring: ring to place buffers on
  1393. * @cleaned_count: number of buffers to replace
  1394. **/
  1395. void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
  1396. {
  1397. union ixgbe_adv_rx_desc *rx_desc;
  1398. struct ixgbe_rx_buffer *bi;
  1399. u16 i = rx_ring->next_to_use;
  1400. u16 bufsz;
  1401. /* nothing to do */
  1402. if (!cleaned_count)
  1403. return;
  1404. rx_desc = IXGBE_RX_DESC(rx_ring, i);
  1405. bi = &rx_ring->rx_buffer_info[i];
  1406. i -= rx_ring->count;
  1407. bufsz = ixgbe_rx_bufsz(rx_ring);
  1408. do {
  1409. if (!ixgbe_alloc_mapped_page(rx_ring, bi))
  1410. break;
  1411. /* sync the buffer for use by the device */
  1412. dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
  1413. bi->page_offset, bufsz,
  1414. DMA_FROM_DEVICE);
  1415. /*
  1416. * Refresh the desc even if buffer_addrs didn't change
  1417. * because each write-back erases this info.
  1418. */
  1419. rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
  1420. rx_desc++;
  1421. bi++;
  1422. i++;
  1423. if (unlikely(!i)) {
  1424. rx_desc = IXGBE_RX_DESC(rx_ring, 0);
  1425. bi = rx_ring->rx_buffer_info;
  1426. i -= rx_ring->count;
  1427. }
  1428. /* clear the length for the next_to_use descriptor */
  1429. rx_desc->wb.upper.length = 0;
  1430. cleaned_count--;
  1431. } while (cleaned_count);
  1432. i += rx_ring->count;
  1433. if (rx_ring->next_to_use != i) {
  1434. rx_ring->next_to_use = i;
  1435. /* update next to alloc since we have filled the ring */
  1436. rx_ring->next_to_alloc = i;
  1437. /* Force memory writes to complete before letting h/w
  1438. * know there are new descriptors to fetch. (Only
  1439. * applicable for weak-ordered memory model archs,
  1440. * such as IA-64).
  1441. */
  1442. wmb();
  1443. writel(i, rx_ring->tail);
  1444. }
  1445. }
  1446. static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
  1447. struct sk_buff *skb)
  1448. {
  1449. u16 hdr_len = skb_headlen(skb);
  1450. /* set gso_size to avoid messing up TCP MSS */
  1451. skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
  1452. IXGBE_CB(skb)->append_cnt);
  1453. skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
  1454. }
  1455. static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
  1456. struct sk_buff *skb)
  1457. {
  1458. /* if append_cnt is 0 then frame is not RSC */
  1459. if (!IXGBE_CB(skb)->append_cnt)
  1460. return;
  1461. rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
  1462. rx_ring->rx_stats.rsc_flush++;
  1463. ixgbe_set_rsc_gso_size(rx_ring, skb);
  1464. /* gso_size is computed using append_cnt so always clear it last */
  1465. IXGBE_CB(skb)->append_cnt = 0;
  1466. }
  1467. /**
  1468. * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
  1469. * @rx_ring: rx descriptor ring packet is being transacted on
  1470. * @rx_desc: pointer to the EOP Rx descriptor
  1471. * @skb: pointer to current skb being populated
  1472. *
  1473. * This function checks the ring, descriptor, and packet information in
  1474. * order to populate the hash, checksum, VLAN, timestamp, protocol, and
  1475. * other fields within the skb.
  1476. **/
  1477. void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
  1478. union ixgbe_adv_rx_desc *rx_desc,
  1479. struct sk_buff *skb)
  1480. {
  1481. struct net_device *dev = rx_ring->netdev;
  1482. u32 flags = rx_ring->q_vector->adapter->flags;
  1483. ixgbe_update_rsc_stats(rx_ring, skb);
  1484. ixgbe_rx_hash(rx_ring, rx_desc, skb);
  1485. ixgbe_rx_checksum(rx_ring, rx_desc, skb);
  1486. if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED))
  1487. ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
  1488. if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
  1489. ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
  1490. u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
  1491. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
  1492. }
  1493. if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_STAT_SECP))
  1494. ixgbe_ipsec_rx(rx_ring, rx_desc, skb);
  1495. /* record Rx queue, or update MACVLAN statistics */
  1496. if (netif_is_ixgbe(dev))
  1497. skb_record_rx_queue(skb, rx_ring->queue_index);
  1498. else
  1499. macvlan_count_rx(netdev_priv(dev), skb->len + ETH_HLEN, true,
  1500. false);
  1501. skb->protocol = eth_type_trans(skb, dev);
  1502. }
  1503. void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
  1504. struct sk_buff *skb)
  1505. {
  1506. napi_gro_receive(&q_vector->napi, skb);
  1507. }
  1508. /**
  1509. * ixgbe_is_non_eop - process handling of non-EOP buffers
  1510. * @rx_ring: Rx ring being processed
  1511. * @rx_desc: Rx descriptor for current buffer
  1512. * @skb: Current socket buffer containing buffer in progress
  1513. *
  1514. * This function updates next to clean. If the buffer is an EOP buffer
  1515. * this function exits returning false, otherwise it will place the
  1516. * sk_buff in the next buffer to be chained and return true indicating
  1517. * that this is in fact a non-EOP buffer.
  1518. **/
  1519. static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
  1520. union ixgbe_adv_rx_desc *rx_desc,
  1521. struct sk_buff *skb)
  1522. {
  1523. u32 ntc = rx_ring->next_to_clean + 1;
  1524. /* fetch, update, and store next to clean */
  1525. ntc = (ntc < rx_ring->count) ? ntc : 0;
  1526. rx_ring->next_to_clean = ntc;
  1527. prefetch(IXGBE_RX_DESC(rx_ring, ntc));
  1528. /* update RSC append count if present */
  1529. if (ring_is_rsc_enabled(rx_ring)) {
  1530. __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
  1531. cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
  1532. if (unlikely(rsc_enabled)) {
  1533. u32 rsc_cnt = le32_to_cpu(rsc_enabled);
  1534. rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
  1535. IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
  1536. /* update ntc based on RSC value */
  1537. ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
  1538. ntc &= IXGBE_RXDADV_NEXTP_MASK;
  1539. ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
  1540. }
  1541. }
  1542. /* if we are the last buffer then there is nothing else to do */
  1543. if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
  1544. return false;
  1545. /* place skb in next buffer to be received */
  1546. rx_ring->rx_buffer_info[ntc].skb = skb;
  1547. rx_ring->rx_stats.non_eop_descs++;
  1548. return true;
  1549. }
  1550. /**
  1551. * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
  1552. * @rx_ring: rx descriptor ring packet is being transacted on
  1553. * @skb: pointer to current skb being adjusted
  1554. *
  1555. * This function is an ixgbe specific version of __pskb_pull_tail. The
  1556. * main difference between this version and the original function is that
  1557. * this function can make several assumptions about the state of things
  1558. * that allow for significant optimizations versus the standard function.
  1559. * As a result we can do things like drop a frag and maintain an accurate
  1560. * truesize for the skb.
  1561. */
  1562. static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
  1563. struct sk_buff *skb)
  1564. {
  1565. skb_frag_t *frag = &skb_shinfo(skb)->frags[0];
  1566. unsigned char *va;
  1567. unsigned int pull_len;
  1568. /*
  1569. * it is valid to use page_address instead of kmap since we are
  1570. * working with pages allocated out of the lomem pool per
  1571. * alloc_page(GFP_ATOMIC)
  1572. */
  1573. va = skb_frag_address(frag);
  1574. /*
  1575. * we need the header to contain the greater of either ETH_HLEN or
  1576. * 60 bytes if the skb->len is less than 60 for skb_pad.
  1577. */
  1578. pull_len = eth_get_headlen(skb->dev, va, IXGBE_RX_HDR_SIZE);
  1579. /* align pull length to size of long to optimize memcpy performance */
  1580. skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
  1581. /* update all of the pointers */
  1582. skb_frag_size_sub(frag, pull_len);
  1583. skb_frag_off_add(frag, pull_len);
  1584. skb->data_len -= pull_len;
  1585. skb->tail += pull_len;
  1586. }
  1587. /**
  1588. * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
  1589. * @rx_ring: rx descriptor ring packet is being transacted on
  1590. * @skb: pointer to current skb being updated
  1591. *
  1592. * This function provides a basic DMA sync up for the first fragment of an
  1593. * skb. The reason for doing this is that the first fragment cannot be
  1594. * unmapped until we have reached the end of packet descriptor for a buffer
  1595. * chain.
  1596. */
  1597. static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
  1598. struct sk_buff *skb)
  1599. {
  1600. if (ring_uses_build_skb(rx_ring)) {
  1601. unsigned long mask = (unsigned long)ixgbe_rx_pg_size(rx_ring) - 1;
  1602. unsigned long offset = (unsigned long)(skb->data) & mask;
  1603. dma_sync_single_range_for_cpu(rx_ring->dev,
  1604. IXGBE_CB(skb)->dma,
  1605. offset,
  1606. skb_headlen(skb),
  1607. DMA_FROM_DEVICE);
  1608. } else {
  1609. skb_frag_t *frag = &skb_shinfo(skb)->frags[0];
  1610. dma_sync_single_range_for_cpu(rx_ring->dev,
  1611. IXGBE_CB(skb)->dma,
  1612. skb_frag_off(frag),
  1613. skb_frag_size(frag),
  1614. DMA_FROM_DEVICE);
  1615. }
  1616. /* If the page was released, just unmap it. */
  1617. if (unlikely(IXGBE_CB(skb)->page_released)) {
  1618. dma_unmap_page_attrs(rx_ring->dev, IXGBE_CB(skb)->dma,
  1619. ixgbe_rx_pg_size(rx_ring),
  1620. DMA_FROM_DEVICE,
  1621. IXGBE_RX_DMA_ATTR);
  1622. }
  1623. }
  1624. /**
  1625. * ixgbe_cleanup_headers - Correct corrupted or empty headers
  1626. * @rx_ring: rx descriptor ring packet is being transacted on
  1627. * @rx_desc: pointer to the EOP Rx descriptor
  1628. * @skb: pointer to current skb being fixed
  1629. *
  1630. * Check if the skb is valid in the XDP case it will be an error pointer.
  1631. * Return true in this case to abort processing and advance to next
  1632. * descriptor.
  1633. *
  1634. * Check for corrupted packet headers caused by senders on the local L2
  1635. * embedded NIC switch not setting up their Tx Descriptors right. These
  1636. * should be very rare.
  1637. *
  1638. * Also address the case where we are pulling data in on pages only
  1639. * and as such no data is present in the skb header.
  1640. *
  1641. * In addition if skb is not at least 60 bytes we need to pad it so that
  1642. * it is large enough to qualify as a valid Ethernet frame.
  1643. *
  1644. * Returns true if an error was encountered and skb was freed.
  1645. **/
  1646. bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
  1647. union ixgbe_adv_rx_desc *rx_desc,
  1648. struct sk_buff *skb)
  1649. {
  1650. struct net_device *netdev = rx_ring->netdev;
  1651. /* XDP packets use error pointer so abort at this point */
  1652. if (IS_ERR(skb))
  1653. return true;
  1654. /* Verify netdev is present, and that packet does not have any
  1655. * errors that would be unacceptable to the netdev.
  1656. */
  1657. if (!netdev ||
  1658. (unlikely(ixgbe_test_staterr(rx_desc,
  1659. IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
  1660. !(netdev->features & NETIF_F_RXALL)))) {
  1661. dev_kfree_skb_any(skb);
  1662. return true;
  1663. }
  1664. /* place header in linear portion of buffer */
  1665. if (!skb_headlen(skb))
  1666. ixgbe_pull_tail(rx_ring, skb);
  1667. #ifdef IXGBE_FCOE
  1668. /* do not attempt to pad FCoE Frames as this will disrupt DDP */
  1669. if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
  1670. return false;
  1671. #endif
  1672. /* if eth_skb_pad returns an error the skb was freed */
  1673. if (eth_skb_pad(skb))
  1674. return true;
  1675. return false;
  1676. }
  1677. /**
  1678. * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
  1679. * @rx_ring: rx descriptor ring to store buffers on
  1680. * @old_buff: donor buffer to have page reused
  1681. *
  1682. * Synchronizes page for reuse by the adapter
  1683. **/
  1684. static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
  1685. struct ixgbe_rx_buffer *old_buff)
  1686. {
  1687. struct ixgbe_rx_buffer *new_buff;
  1688. u16 nta = rx_ring->next_to_alloc;
  1689. new_buff = &rx_ring->rx_buffer_info[nta];
  1690. /* update, and store next to alloc */
  1691. nta++;
  1692. rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
  1693. /* Transfer page from old buffer to new buffer.
  1694. * Move each member individually to avoid possible store
  1695. * forwarding stalls and unnecessary copy of skb.
  1696. */
  1697. new_buff->dma = old_buff->dma;
  1698. new_buff->page = old_buff->page;
  1699. new_buff->page_offset = old_buff->page_offset;
  1700. new_buff->pagecnt_bias = old_buff->pagecnt_bias;
  1701. }
  1702. static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer *rx_buffer,
  1703. int rx_buffer_pgcnt)
  1704. {
  1705. unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
  1706. struct page *page = rx_buffer->page;
  1707. /* avoid re-using remote and pfmemalloc pages */
  1708. if (!dev_page_is_reusable(page))
  1709. return false;
  1710. #if (PAGE_SIZE < 8192)
  1711. /* if we are only owner of page we can reuse it */
  1712. if (unlikely((rx_buffer_pgcnt - pagecnt_bias) > 1))
  1713. return false;
  1714. #else
  1715. /* The last offset is a bit aggressive in that we assume the
  1716. * worst case of FCoE being enabled and using a 3K buffer.
  1717. * However this should have minimal impact as the 1K extra is
  1718. * still less than one buffer in size.
  1719. */
  1720. #define IXGBE_LAST_OFFSET \
  1721. (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K)
  1722. if (rx_buffer->page_offset > IXGBE_LAST_OFFSET)
  1723. return false;
  1724. #endif
  1725. /* If we have drained the page fragment pool we need to update
  1726. * the pagecnt_bias and page count so that we fully restock the
  1727. * number of references the driver holds.
  1728. */
  1729. if (unlikely(pagecnt_bias == 1)) {
  1730. page_ref_add(page, USHRT_MAX - 1);
  1731. rx_buffer->pagecnt_bias = USHRT_MAX;
  1732. }
  1733. return true;
  1734. }
  1735. /**
  1736. * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
  1737. * @rx_ring: rx descriptor ring to transact packets on
  1738. * @rx_buffer: buffer containing page to add
  1739. * @skb: sk_buff to place the data into
  1740. * @size: size of data in rx_buffer
  1741. *
  1742. * This function will add the data contained in rx_buffer->page to the skb.
  1743. * This is done either through a direct copy if the data in the buffer is
  1744. * less than the skb header size, otherwise it will just attach the page as
  1745. * a frag to the skb.
  1746. *
  1747. * The function will then update the page offset if necessary and return
  1748. * true if the buffer can be reused by the adapter.
  1749. **/
  1750. static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
  1751. struct ixgbe_rx_buffer *rx_buffer,
  1752. struct sk_buff *skb,
  1753. unsigned int size)
  1754. {
  1755. #if (PAGE_SIZE < 8192)
  1756. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1757. #else
  1758. unsigned int truesize = rx_ring->rx_offset ?
  1759. SKB_DATA_ALIGN(rx_ring->rx_offset + size) :
  1760. SKB_DATA_ALIGN(size);
  1761. #endif
  1762. skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
  1763. rx_buffer->page_offset, size, truesize);
  1764. #if (PAGE_SIZE < 8192)
  1765. rx_buffer->page_offset ^= truesize;
  1766. #else
  1767. rx_buffer->page_offset += truesize;
  1768. #endif
  1769. }
  1770. static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring,
  1771. union ixgbe_adv_rx_desc *rx_desc,
  1772. struct sk_buff **skb,
  1773. const unsigned int size,
  1774. int *rx_buffer_pgcnt)
  1775. {
  1776. struct ixgbe_rx_buffer *rx_buffer;
  1777. rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
  1778. *rx_buffer_pgcnt =
  1779. #if (PAGE_SIZE < 8192)
  1780. page_count(rx_buffer->page);
  1781. #else
  1782. 0;
  1783. #endif
  1784. prefetchw(rx_buffer->page);
  1785. *skb = rx_buffer->skb;
  1786. /* Delay unmapping of the first packet. It carries the header
  1787. * information, HW may still access the header after the writeback.
  1788. * Only unmap it when EOP is reached
  1789. */
  1790. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) {
  1791. if (!*skb)
  1792. goto skip_sync;
  1793. } else {
  1794. if (*skb)
  1795. ixgbe_dma_sync_frag(rx_ring, *skb);
  1796. }
  1797. /* we are reusing so sync this buffer for CPU use */
  1798. dma_sync_single_range_for_cpu(rx_ring->dev,
  1799. rx_buffer->dma,
  1800. rx_buffer->page_offset,
  1801. size,
  1802. DMA_FROM_DEVICE);
  1803. skip_sync:
  1804. rx_buffer->pagecnt_bias--;
  1805. return rx_buffer;
  1806. }
  1807. static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring,
  1808. struct ixgbe_rx_buffer *rx_buffer,
  1809. struct sk_buff *skb,
  1810. int rx_buffer_pgcnt)
  1811. {
  1812. if (ixgbe_can_reuse_rx_page(rx_buffer, rx_buffer_pgcnt)) {
  1813. /* hand second half of page back to the ring */
  1814. ixgbe_reuse_rx_page(rx_ring, rx_buffer);
  1815. } else {
  1816. if (!IS_ERR(skb) && IXGBE_CB(skb)->dma == rx_buffer->dma) {
  1817. /* the page has been released from the ring */
  1818. IXGBE_CB(skb)->page_released = true;
  1819. } else {
  1820. /* we are not reusing the buffer so unmap it */
  1821. dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
  1822. ixgbe_rx_pg_size(rx_ring),
  1823. DMA_FROM_DEVICE,
  1824. IXGBE_RX_DMA_ATTR);
  1825. }
  1826. __page_frag_cache_drain(rx_buffer->page,
  1827. rx_buffer->pagecnt_bias);
  1828. }
  1829. /* clear contents of rx_buffer */
  1830. rx_buffer->page = NULL;
  1831. rx_buffer->skb = NULL;
  1832. }
  1833. static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring,
  1834. struct ixgbe_rx_buffer *rx_buffer,
  1835. struct xdp_buff *xdp,
  1836. union ixgbe_adv_rx_desc *rx_desc)
  1837. {
  1838. unsigned int size = xdp->data_end - xdp->data;
  1839. #if (PAGE_SIZE < 8192)
  1840. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1841. #else
  1842. unsigned int truesize = SKB_DATA_ALIGN(xdp->data_end -
  1843. xdp->data_hard_start);
  1844. #endif
  1845. struct sk_buff *skb;
  1846. /* prefetch first cache line of first page */
  1847. net_prefetch(xdp->data);
  1848. /* Note, we get here by enabling legacy-rx via:
  1849. *
  1850. * ethtool --set-priv-flags <dev> legacy-rx on
  1851. *
  1852. * In this mode, we currently get 0 extra XDP headroom as
  1853. * opposed to having legacy-rx off, where we process XDP
  1854. * packets going to stack via ixgbe_build_skb(). The latter
  1855. * provides us currently with 192 bytes of headroom.
  1856. *
  1857. * For ixgbe_construct_skb() mode it means that the
  1858. * xdp->data_meta will always point to xdp->data, since
  1859. * the helper cannot expand the head. Should this ever
  1860. * change in future for legacy-rx mode on, then lets also
  1861. * add xdp->data_meta handling here.
  1862. */
  1863. /* allocate a skb to store the frags */
  1864. skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE);
  1865. if (unlikely(!skb))
  1866. return NULL;
  1867. if (size > IXGBE_RX_HDR_SIZE) {
  1868. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
  1869. IXGBE_CB(skb)->dma = rx_buffer->dma;
  1870. skb_add_rx_frag(skb, 0, rx_buffer->page,
  1871. xdp->data - page_address(rx_buffer->page),
  1872. size, truesize);
  1873. #if (PAGE_SIZE < 8192)
  1874. rx_buffer->page_offset ^= truesize;
  1875. #else
  1876. rx_buffer->page_offset += truesize;
  1877. #endif
  1878. } else {
  1879. memcpy(__skb_put(skb, size),
  1880. xdp->data, ALIGN(size, sizeof(long)));
  1881. rx_buffer->pagecnt_bias++;
  1882. }
  1883. return skb;
  1884. }
  1885. static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,
  1886. struct ixgbe_rx_buffer *rx_buffer,
  1887. struct xdp_buff *xdp,
  1888. union ixgbe_adv_rx_desc *rx_desc)
  1889. {
  1890. unsigned int metasize = xdp->data - xdp->data_meta;
  1891. #if (PAGE_SIZE < 8192)
  1892. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1893. #else
  1894. unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
  1895. SKB_DATA_ALIGN(xdp->data_end -
  1896. xdp->data_hard_start);
  1897. #endif
  1898. struct sk_buff *skb;
  1899. /* Prefetch first cache line of first page. If xdp->data_meta
  1900. * is unused, this points extactly as xdp->data, otherwise we
  1901. * likely have a consumer accessing first few bytes of meta
  1902. * data, and then actual data.
  1903. */
  1904. net_prefetch(xdp->data_meta);
  1905. /* build an skb to around the page buffer */
  1906. skb = napi_build_skb(xdp->data_hard_start, truesize);
  1907. if (unlikely(!skb))
  1908. return NULL;
  1909. /* update pointers within the skb to store the data */
  1910. skb_reserve(skb, xdp->data - xdp->data_hard_start);
  1911. __skb_put(skb, xdp->data_end - xdp->data);
  1912. if (metasize)
  1913. skb_metadata_set(skb, metasize);
  1914. /* record DMA address if this is the start of a chain of buffers */
  1915. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
  1916. IXGBE_CB(skb)->dma = rx_buffer->dma;
  1917. /* update buffer offset */
  1918. #if (PAGE_SIZE < 8192)
  1919. rx_buffer->page_offset ^= truesize;
  1920. #else
  1921. rx_buffer->page_offset += truesize;
  1922. #endif
  1923. return skb;
  1924. }
  1925. static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter,
  1926. struct ixgbe_ring *rx_ring,
  1927. struct xdp_buff *xdp)
  1928. {
  1929. int err, result = IXGBE_XDP_PASS;
  1930. struct bpf_prog *xdp_prog;
  1931. struct ixgbe_ring *ring;
  1932. struct xdp_frame *xdpf;
  1933. u32 act;
  1934. xdp_prog = READ_ONCE(rx_ring->xdp_prog);
  1935. if (!xdp_prog)
  1936. goto xdp_out;
  1937. prefetchw(xdp->data_hard_start); /* xdp_frame write */
  1938. act = bpf_prog_run_xdp(xdp_prog, xdp);
  1939. switch (act) {
  1940. case XDP_PASS:
  1941. break;
  1942. case XDP_TX:
  1943. xdpf = xdp_convert_buff_to_frame(xdp);
  1944. if (unlikely(!xdpf))
  1945. goto out_failure;
  1946. ring = ixgbe_determine_xdp_ring(adapter);
  1947. if (static_branch_unlikely(&ixgbe_xdp_locking_key))
  1948. spin_lock(&ring->tx_lock);
  1949. result = ixgbe_xmit_xdp_ring(ring, xdpf);
  1950. if (static_branch_unlikely(&ixgbe_xdp_locking_key))
  1951. spin_unlock(&ring->tx_lock);
  1952. if (result == IXGBE_XDP_CONSUMED)
  1953. goto out_failure;
  1954. break;
  1955. case XDP_REDIRECT:
  1956. err = xdp_do_redirect(adapter->netdev, xdp, xdp_prog);
  1957. if (err)
  1958. goto out_failure;
  1959. result = IXGBE_XDP_REDIR;
  1960. break;
  1961. default:
  1962. bpf_warn_invalid_xdp_action(rx_ring->netdev, xdp_prog, act);
  1963. fallthrough;
  1964. case XDP_ABORTED:
  1965. out_failure:
  1966. trace_xdp_exception(rx_ring->netdev, xdp_prog, act);
  1967. fallthrough; /* handle aborts by dropping packet */
  1968. case XDP_DROP:
  1969. result = IXGBE_XDP_CONSUMED;
  1970. break;
  1971. }
  1972. xdp_out:
  1973. return ERR_PTR(-result);
  1974. }
  1975. static unsigned int ixgbe_rx_frame_truesize(struct ixgbe_ring *rx_ring,
  1976. unsigned int size)
  1977. {
  1978. unsigned int truesize;
  1979. #if (PAGE_SIZE < 8192)
  1980. truesize = ixgbe_rx_pg_size(rx_ring) / 2; /* Must be power-of-2 */
  1981. #else
  1982. truesize = rx_ring->rx_offset ?
  1983. SKB_DATA_ALIGN(rx_ring->rx_offset + size) +
  1984. SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) :
  1985. SKB_DATA_ALIGN(size);
  1986. #endif
  1987. return truesize;
  1988. }
  1989. static void ixgbe_rx_buffer_flip(struct ixgbe_ring *rx_ring,
  1990. struct ixgbe_rx_buffer *rx_buffer,
  1991. unsigned int size)
  1992. {
  1993. unsigned int truesize = ixgbe_rx_frame_truesize(rx_ring, size);
  1994. #if (PAGE_SIZE < 8192)
  1995. rx_buffer->page_offset ^= truesize;
  1996. #else
  1997. rx_buffer->page_offset += truesize;
  1998. #endif
  1999. }
  2000. /**
  2001. * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
  2002. * @q_vector: structure containing interrupt and ring information
  2003. * @rx_ring: rx descriptor ring to transact packets on
  2004. * @budget: Total limit on number of packets to process
  2005. *
  2006. * This function provides a "bounce buffer" approach to Rx interrupt
  2007. * processing. The advantage to this is that on systems that have
  2008. * expensive overhead for IOMMU access this provides a means of avoiding
  2009. * it by maintaining the mapping of the page to the syste.
  2010. *
  2011. * Returns amount of work completed
  2012. **/
  2013. static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
  2014. struct ixgbe_ring *rx_ring,
  2015. const int budget)
  2016. {
  2017. unsigned int total_rx_bytes = 0, total_rx_packets = 0, frame_sz = 0;
  2018. struct ixgbe_adapter *adapter = q_vector->adapter;
  2019. #ifdef IXGBE_FCOE
  2020. int ddp_bytes;
  2021. unsigned int mss = 0;
  2022. #endif /* IXGBE_FCOE */
  2023. u16 cleaned_count = ixgbe_desc_unused(rx_ring);
  2024. unsigned int offset = rx_ring->rx_offset;
  2025. unsigned int xdp_xmit = 0;
  2026. struct xdp_buff xdp;
  2027. /* Frame size depend on rx_ring setup when PAGE_SIZE=4K */
  2028. #if (PAGE_SIZE < 8192)
  2029. frame_sz = ixgbe_rx_frame_truesize(rx_ring, 0);
  2030. #endif
  2031. xdp_init_buff(&xdp, frame_sz, &rx_ring->xdp_rxq);
  2032. while (likely(total_rx_packets < budget)) {
  2033. union ixgbe_adv_rx_desc *rx_desc;
  2034. struct ixgbe_rx_buffer *rx_buffer;
  2035. struct sk_buff *skb;
  2036. int rx_buffer_pgcnt;
  2037. unsigned int size;
  2038. /* return some buffers to hardware, one at a time is too slow */
  2039. if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
  2040. ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
  2041. cleaned_count = 0;
  2042. }
  2043. rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
  2044. size = le16_to_cpu(rx_desc->wb.upper.length);
  2045. if (!size)
  2046. break;
  2047. /* This memory barrier is needed to keep us from reading
  2048. * any other fields out of the rx_desc until we know the
  2049. * descriptor has been written back
  2050. */
  2051. dma_rmb();
  2052. rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size, &rx_buffer_pgcnt);
  2053. /* retrieve a buffer from the ring */
  2054. if (!skb) {
  2055. unsigned char *hard_start;
  2056. hard_start = page_address(rx_buffer->page) +
  2057. rx_buffer->page_offset - offset;
  2058. xdp_prepare_buff(&xdp, hard_start, offset, size, true);
  2059. xdp_buff_clear_frags_flag(&xdp);
  2060. #if (PAGE_SIZE > 4096)
  2061. /* At larger PAGE_SIZE, frame_sz depend on len size */
  2062. xdp.frame_sz = ixgbe_rx_frame_truesize(rx_ring, size);
  2063. #endif
  2064. skb = ixgbe_run_xdp(adapter, rx_ring, &xdp);
  2065. }
  2066. if (IS_ERR(skb)) {
  2067. unsigned int xdp_res = -PTR_ERR(skb);
  2068. if (xdp_res & (IXGBE_XDP_TX | IXGBE_XDP_REDIR)) {
  2069. xdp_xmit |= xdp_res;
  2070. ixgbe_rx_buffer_flip(rx_ring, rx_buffer, size);
  2071. } else {
  2072. rx_buffer->pagecnt_bias++;
  2073. }
  2074. total_rx_packets++;
  2075. total_rx_bytes += size;
  2076. } else if (skb) {
  2077. ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size);
  2078. } else if (ring_uses_build_skb(rx_ring)) {
  2079. skb = ixgbe_build_skb(rx_ring, rx_buffer,
  2080. &xdp, rx_desc);
  2081. } else {
  2082. skb = ixgbe_construct_skb(rx_ring, rx_buffer,
  2083. &xdp, rx_desc);
  2084. }
  2085. /* exit if we failed to retrieve a buffer */
  2086. if (!skb) {
  2087. rx_ring->rx_stats.alloc_rx_buff_failed++;
  2088. rx_buffer->pagecnt_bias++;
  2089. break;
  2090. }
  2091. ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb, rx_buffer_pgcnt);
  2092. cleaned_count++;
  2093. /* place incomplete frames back on ring for completion */
  2094. if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
  2095. continue;
  2096. /* verify the packet layout is correct */
  2097. if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
  2098. continue;
  2099. /* probably a little skewed due to removing CRC */
  2100. total_rx_bytes += skb->len;
  2101. /* populate checksum, timestamp, VLAN, and protocol */
  2102. ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
  2103. #ifdef IXGBE_FCOE
  2104. /* if ddp, not passing to ULD unless for FCP_RSP or error */
  2105. if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
  2106. ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
  2107. /* include DDPed FCoE data */
  2108. if (ddp_bytes > 0) {
  2109. if (!mss) {
  2110. mss = rx_ring->netdev->mtu -
  2111. sizeof(struct fcoe_hdr) -
  2112. sizeof(struct fc_frame_header) -
  2113. sizeof(struct fcoe_crc_eof);
  2114. if (mss > 512)
  2115. mss &= ~511;
  2116. }
  2117. total_rx_bytes += ddp_bytes;
  2118. total_rx_packets += DIV_ROUND_UP(ddp_bytes,
  2119. mss);
  2120. }
  2121. if (!ddp_bytes) {
  2122. dev_kfree_skb_any(skb);
  2123. continue;
  2124. }
  2125. }
  2126. #endif /* IXGBE_FCOE */
  2127. ixgbe_rx_skb(q_vector, skb);
  2128. /* update budget accounting */
  2129. total_rx_packets++;
  2130. }
  2131. if (xdp_xmit & IXGBE_XDP_REDIR)
  2132. xdp_do_flush();
  2133. if (xdp_xmit & IXGBE_XDP_TX) {
  2134. struct ixgbe_ring *ring = ixgbe_determine_xdp_ring(adapter);
  2135. ixgbe_xdp_ring_update_tail_locked(ring);
  2136. }
  2137. ixgbe_update_rx_ring_stats(rx_ring, q_vector, total_rx_packets,
  2138. total_rx_bytes);
  2139. return total_rx_packets;
  2140. }
  2141. /**
  2142. * ixgbe_configure_msix - Configure MSI-X hardware
  2143. * @adapter: board private structure
  2144. *
  2145. * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
  2146. * interrupts.
  2147. **/
  2148. static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
  2149. {
  2150. struct ixgbe_q_vector *q_vector;
  2151. int v_idx;
  2152. u32 mask;
  2153. /* Populate MSIX to EITR Select */
  2154. if (adapter->num_vfs > 32) {
  2155. u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
  2156. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
  2157. }
  2158. /*
  2159. * Populate the IVAR table and set the ITR values to the
  2160. * corresponding register.
  2161. */
  2162. for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
  2163. struct ixgbe_ring *ring;
  2164. q_vector = adapter->q_vector[v_idx];
  2165. ixgbe_for_each_ring(ring, q_vector->rx)
  2166. ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
  2167. ixgbe_for_each_ring(ring, q_vector->tx)
  2168. ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
  2169. ixgbe_write_eitr(q_vector);
  2170. }
  2171. switch (adapter->hw.mac.type) {
  2172. case ixgbe_mac_82598EB:
  2173. ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
  2174. v_idx);
  2175. break;
  2176. case ixgbe_mac_82599EB:
  2177. case ixgbe_mac_X540:
  2178. case ixgbe_mac_X550:
  2179. case ixgbe_mac_X550EM_x:
  2180. case ixgbe_mac_x550em_a:
  2181. ixgbe_set_ivar(adapter, -1, 1, v_idx);
  2182. break;
  2183. default:
  2184. break;
  2185. }
  2186. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
  2187. /* set up to autoclear timer, and the vectors */
  2188. mask = IXGBE_EIMS_ENABLE_MASK;
  2189. mask &= ~(IXGBE_EIMS_OTHER |
  2190. IXGBE_EIMS_MAILBOX |
  2191. IXGBE_EIMS_LSC);
  2192. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
  2193. }
  2194. /**
  2195. * ixgbe_update_itr - update the dynamic ITR value based on statistics
  2196. * @q_vector: structure containing interrupt and ring information
  2197. * @ring_container: structure containing ring performance data
  2198. *
  2199. * Stores a new ITR value based on packets and byte
  2200. * counts during the last interrupt. The advantage of per interrupt
  2201. * computation is faster updates and more accurate ITR for the current
  2202. * traffic pattern. Constants in this function were computed
  2203. * based on theoretical maximum wire speed and thresholds were set based
  2204. * on testing data as well as attempting to minimize response time
  2205. * while increasing bulk throughput.
  2206. **/
  2207. static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
  2208. struct ixgbe_ring_container *ring_container)
  2209. {
  2210. unsigned int itr = IXGBE_ITR_ADAPTIVE_MIN_USECS |
  2211. IXGBE_ITR_ADAPTIVE_LATENCY;
  2212. unsigned int avg_wire_size, packets, bytes;
  2213. unsigned long next_update = jiffies;
  2214. /* If we don't have any rings just leave ourselves set for maximum
  2215. * possible latency so we take ourselves out of the equation.
  2216. */
  2217. if (!ring_container->ring)
  2218. return;
  2219. /* If we didn't update within up to 1 - 2 jiffies we can assume
  2220. * that either packets are coming in so slow there hasn't been
  2221. * any work, or that there is so much work that NAPI is dealing
  2222. * with interrupt moderation and we don't need to do anything.
  2223. */
  2224. if (time_after(next_update, ring_container->next_update))
  2225. goto clear_counts;
  2226. packets = ring_container->total_packets;
  2227. /* We have no packets to actually measure against. This means
  2228. * either one of the other queues on this vector is active or
  2229. * we are a Tx queue doing TSO with too high of an interrupt rate.
  2230. *
  2231. * When this occurs just tick up our delay by the minimum value
  2232. * and hope that this extra delay will prevent us from being called
  2233. * without any work on our queue.
  2234. */
  2235. if (!packets) {
  2236. itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
  2237. if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
  2238. itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
  2239. itr += ring_container->itr & IXGBE_ITR_ADAPTIVE_LATENCY;
  2240. goto clear_counts;
  2241. }
  2242. bytes = ring_container->total_bytes;
  2243. /* If packets are less than 4 or bytes are less than 9000 assume
  2244. * insufficient data to use bulk rate limiting approach. We are
  2245. * likely latency driven.
  2246. */
  2247. if (packets < 4 && bytes < 9000) {
  2248. itr = IXGBE_ITR_ADAPTIVE_LATENCY;
  2249. goto adjust_by_size;
  2250. }
  2251. /* Between 4 and 48 we can assume that our current interrupt delay
  2252. * is only slightly too low. As such we should increase it by a small
  2253. * fixed amount.
  2254. */
  2255. if (packets < 48) {
  2256. itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
  2257. if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
  2258. itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
  2259. goto clear_counts;
  2260. }
  2261. /* Between 48 and 96 is our "goldilocks" zone where we are working
  2262. * out "just right". Just report that our current ITR is good for us.
  2263. */
  2264. if (packets < 96) {
  2265. itr = q_vector->itr >> 2;
  2266. goto clear_counts;
  2267. }
  2268. /* If packet count is 96 or greater we are likely looking at a slight
  2269. * overrun of the delay we want. Try halving our delay to see if that
  2270. * will cut the number of packets in half per interrupt.
  2271. */
  2272. if (packets < 256) {
  2273. itr = q_vector->itr >> 3;
  2274. if (itr < IXGBE_ITR_ADAPTIVE_MIN_USECS)
  2275. itr = IXGBE_ITR_ADAPTIVE_MIN_USECS;
  2276. goto clear_counts;
  2277. }
  2278. /* The paths below assume we are dealing with a bulk ITR since number
  2279. * of packets is 256 or greater. We are just going to have to compute
  2280. * a value and try to bring the count under control, though for smaller
  2281. * packet sizes there isn't much we can do as NAPI polling will likely
  2282. * be kicking in sooner rather than later.
  2283. */
  2284. itr = IXGBE_ITR_ADAPTIVE_BULK;
  2285. adjust_by_size:
  2286. /* If packet counts are 256 or greater we can assume we have a gross
  2287. * overestimation of what the rate should be. Instead of trying to fine
  2288. * tune it just use the formula below to try and dial in an exact value
  2289. * give the current packet size of the frame.
  2290. */
  2291. avg_wire_size = bytes / packets;
  2292. /* The following is a crude approximation of:
  2293. * wmem_default / (size + overhead) = desired_pkts_per_int
  2294. * rate / bits_per_byte / (size + ethernet overhead) = pkt_rate
  2295. * (desired_pkt_rate / pkt_rate) * usecs_per_sec = ITR value
  2296. *
  2297. * Assuming wmem_default is 212992 and overhead is 640 bytes per
  2298. * packet, (256 skb, 64 headroom, 320 shared info), we can reduce the
  2299. * formula down to
  2300. *
  2301. * (170 * (size + 24)) / (size + 640) = ITR
  2302. *
  2303. * We first do some math on the packet size and then finally bitshift
  2304. * by 8 after rounding up. We also have to account for PCIe link speed
  2305. * difference as ITR scales based on this.
  2306. */
  2307. if (avg_wire_size <= 60) {
  2308. /* Start at 50k ints/sec */
  2309. avg_wire_size = 5120;
  2310. } else if (avg_wire_size <= 316) {
  2311. /* 50K ints/sec to 16K ints/sec */
  2312. avg_wire_size *= 40;
  2313. avg_wire_size += 2720;
  2314. } else if (avg_wire_size <= 1084) {
  2315. /* 16K ints/sec to 9.2K ints/sec */
  2316. avg_wire_size *= 15;
  2317. avg_wire_size += 11452;
  2318. } else if (avg_wire_size < 1968) {
  2319. /* 9.2K ints/sec to 8K ints/sec */
  2320. avg_wire_size *= 5;
  2321. avg_wire_size += 22420;
  2322. } else {
  2323. /* plateau at a limit of 8K ints/sec */
  2324. avg_wire_size = 32256;
  2325. }
  2326. /* If we are in low latency mode half our delay which doubles the rate
  2327. * to somewhere between 100K to 16K ints/sec
  2328. */
  2329. if (itr & IXGBE_ITR_ADAPTIVE_LATENCY)
  2330. avg_wire_size >>= 1;
  2331. /* Resultant value is 256 times larger than it needs to be. This
  2332. * gives us room to adjust the value as needed to either increase
  2333. * or decrease the value based on link speeds of 10G, 2.5G, 1G, etc.
  2334. *
  2335. * Use addition as we have already recorded the new latency flag
  2336. * for the ITR value.
  2337. */
  2338. switch (q_vector->adapter->link_speed) {
  2339. case IXGBE_LINK_SPEED_10GB_FULL:
  2340. case IXGBE_LINK_SPEED_100_FULL:
  2341. default:
  2342. itr += DIV_ROUND_UP(avg_wire_size,
  2343. IXGBE_ITR_ADAPTIVE_MIN_INC * 256) *
  2344. IXGBE_ITR_ADAPTIVE_MIN_INC;
  2345. break;
  2346. case IXGBE_LINK_SPEED_2_5GB_FULL:
  2347. case IXGBE_LINK_SPEED_1GB_FULL:
  2348. case IXGBE_LINK_SPEED_10_FULL:
  2349. if (avg_wire_size > 8064)
  2350. avg_wire_size = 8064;
  2351. itr += DIV_ROUND_UP(avg_wire_size,
  2352. IXGBE_ITR_ADAPTIVE_MIN_INC * 64) *
  2353. IXGBE_ITR_ADAPTIVE_MIN_INC;
  2354. break;
  2355. }
  2356. clear_counts:
  2357. /* write back value */
  2358. ring_container->itr = itr;
  2359. /* next update should occur within next jiffy */
  2360. ring_container->next_update = next_update + 1;
  2361. ring_container->total_bytes = 0;
  2362. ring_container->total_packets = 0;
  2363. }
  2364. /**
  2365. * ixgbe_write_eitr - write EITR register in hardware specific way
  2366. * @q_vector: structure containing interrupt and ring information
  2367. *
  2368. * This function is made to be called by ethtool and by the driver
  2369. * when it needs to update EITR registers at runtime. Hardware
  2370. * specific quirks/differences are taken care of here.
  2371. */
  2372. void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
  2373. {
  2374. struct ixgbe_adapter *adapter = q_vector->adapter;
  2375. struct ixgbe_hw *hw = &adapter->hw;
  2376. int v_idx = q_vector->v_idx;
  2377. u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
  2378. switch (adapter->hw.mac.type) {
  2379. case ixgbe_mac_82598EB:
  2380. /* must write high and low 16 bits to reset counter */
  2381. itr_reg |= (itr_reg << 16);
  2382. break;
  2383. case ixgbe_mac_82599EB:
  2384. case ixgbe_mac_X540:
  2385. case ixgbe_mac_X550:
  2386. case ixgbe_mac_X550EM_x:
  2387. case ixgbe_mac_x550em_a:
  2388. /*
  2389. * set the WDIS bit to not clear the timer bits and cause an
  2390. * immediate assertion of the interrupt
  2391. */
  2392. itr_reg |= IXGBE_EITR_CNT_WDIS;
  2393. break;
  2394. default:
  2395. break;
  2396. }
  2397. IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
  2398. }
  2399. static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
  2400. {
  2401. u32 new_itr;
  2402. ixgbe_update_itr(q_vector, &q_vector->tx);
  2403. ixgbe_update_itr(q_vector, &q_vector->rx);
  2404. /* use the smallest value of new ITR delay calculations */
  2405. new_itr = min(q_vector->rx.itr, q_vector->tx.itr);
  2406. /* Clear latency flag if set, shift into correct position */
  2407. new_itr &= ~IXGBE_ITR_ADAPTIVE_LATENCY;
  2408. new_itr <<= 2;
  2409. if (new_itr != q_vector->itr) {
  2410. /* save the algorithm value here */
  2411. q_vector->itr = new_itr;
  2412. ixgbe_write_eitr(q_vector);
  2413. }
  2414. }
  2415. /**
  2416. * ixgbe_check_overtemp_subtask - check for over temperature
  2417. * @adapter: pointer to adapter
  2418. **/
  2419. static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
  2420. {
  2421. struct ixgbe_hw *hw = &adapter->hw;
  2422. u32 eicr = adapter->interrupt_event;
  2423. if (test_bit(__IXGBE_DOWN, &adapter->state))
  2424. return;
  2425. if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
  2426. return;
  2427. adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2428. switch (hw->device_id) {
  2429. case IXGBE_DEV_ID_82599_T3_LOM:
  2430. /*
  2431. * Since the warning interrupt is for both ports
  2432. * we don't have to check if:
  2433. * - This interrupt wasn't for our port.
  2434. * - We may have missed the interrupt so always have to
  2435. * check if we got a LSC
  2436. */
  2437. if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
  2438. !(eicr & IXGBE_EICR_LSC))
  2439. return;
  2440. if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
  2441. u32 speed;
  2442. bool link_up = false;
  2443. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  2444. if (link_up)
  2445. return;
  2446. }
  2447. /* Check if this is not due to overtemp */
  2448. if (!hw->phy.ops.check_overtemp(hw))
  2449. return;
  2450. break;
  2451. case IXGBE_DEV_ID_X550EM_A_1G_T:
  2452. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  2453. if (!hw->phy.ops.check_overtemp(hw))
  2454. return;
  2455. break;
  2456. default:
  2457. if (adapter->hw.mac.type >= ixgbe_mac_X540)
  2458. return;
  2459. if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
  2460. return;
  2461. break;
  2462. }
  2463. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  2464. adapter->interrupt_event = 0;
  2465. }
  2466. static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
  2467. {
  2468. struct ixgbe_hw *hw = &adapter->hw;
  2469. if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
  2470. (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
  2471. e_crit(probe, "Fan has stopped, replace the adapter\n");
  2472. /* write to clear the interrupt */
  2473. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
  2474. }
  2475. }
  2476. static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
  2477. {
  2478. struct ixgbe_hw *hw = &adapter->hw;
  2479. if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
  2480. return;
  2481. switch (adapter->hw.mac.type) {
  2482. case ixgbe_mac_82599EB:
  2483. /*
  2484. * Need to check link state so complete overtemp check
  2485. * on service task
  2486. */
  2487. if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
  2488. (eicr & IXGBE_EICR_LSC)) &&
  2489. (!test_bit(__IXGBE_DOWN, &adapter->state))) {
  2490. adapter->interrupt_event = eicr;
  2491. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2492. ixgbe_service_event_schedule(adapter);
  2493. return;
  2494. }
  2495. return;
  2496. case ixgbe_mac_x550em_a:
  2497. if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) {
  2498. adapter->interrupt_event = eicr;
  2499. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2500. ixgbe_service_event_schedule(adapter);
  2501. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
  2502. IXGBE_EICR_GPI_SDP0_X550EM_a);
  2503. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR,
  2504. IXGBE_EICR_GPI_SDP0_X550EM_a);
  2505. }
  2506. return;
  2507. case ixgbe_mac_X550:
  2508. case ixgbe_mac_X540:
  2509. if (!(eicr & IXGBE_EICR_TS))
  2510. return;
  2511. break;
  2512. default:
  2513. return;
  2514. }
  2515. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  2516. }
  2517. static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
  2518. {
  2519. switch (hw->mac.type) {
  2520. case ixgbe_mac_82598EB:
  2521. if (hw->phy.type == ixgbe_phy_nl)
  2522. return true;
  2523. return false;
  2524. case ixgbe_mac_82599EB:
  2525. case ixgbe_mac_X550EM_x:
  2526. case ixgbe_mac_x550em_a:
  2527. switch (hw->mac.ops.get_media_type(hw)) {
  2528. case ixgbe_media_type_fiber:
  2529. case ixgbe_media_type_fiber_qsfp:
  2530. return true;
  2531. default:
  2532. return false;
  2533. }
  2534. default:
  2535. return false;
  2536. }
  2537. }
  2538. static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
  2539. {
  2540. struct ixgbe_hw *hw = &adapter->hw;
  2541. u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
  2542. if (!ixgbe_is_sfp(hw))
  2543. return;
  2544. /* Later MAC's use different SDP */
  2545. if (hw->mac.type >= ixgbe_mac_X540)
  2546. eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
  2547. if (eicr & eicr_mask) {
  2548. /* Clear the interrupt */
  2549. IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
  2550. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2551. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  2552. adapter->sfp_poll_time = 0;
  2553. ixgbe_service_event_schedule(adapter);
  2554. }
  2555. }
  2556. if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
  2557. (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
  2558. /* Clear the interrupt */
  2559. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
  2560. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2561. adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
  2562. ixgbe_service_event_schedule(adapter);
  2563. }
  2564. }
  2565. }
  2566. static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
  2567. {
  2568. struct ixgbe_hw *hw = &adapter->hw;
  2569. adapter->lsc_int++;
  2570. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  2571. adapter->link_check_timeout = jiffies;
  2572. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2573. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
  2574. IXGBE_WRITE_FLUSH(hw);
  2575. ixgbe_service_event_schedule(adapter);
  2576. }
  2577. }
  2578. static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
  2579. u64 qmask)
  2580. {
  2581. struct ixgbe_hw *hw = &adapter->hw;
  2582. u32 mask;
  2583. switch (hw->mac.type) {
  2584. case ixgbe_mac_82598EB:
  2585. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  2586. IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
  2587. break;
  2588. case ixgbe_mac_82599EB:
  2589. case ixgbe_mac_X540:
  2590. case ixgbe_mac_X550:
  2591. case ixgbe_mac_X550EM_x:
  2592. case ixgbe_mac_x550em_a:
  2593. mask = (qmask & 0xFFFFFFFF);
  2594. if (mask)
  2595. IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
  2596. mask = (qmask >> 32);
  2597. if (mask)
  2598. IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
  2599. break;
  2600. default:
  2601. break;
  2602. }
  2603. /* skip the flush */
  2604. }
  2605. /**
  2606. * ixgbe_irq_enable - Enable default interrupt generation settings
  2607. * @adapter: board private structure
  2608. * @queues: enable irqs for queues
  2609. * @flush: flush register write
  2610. **/
  2611. static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
  2612. bool flush)
  2613. {
  2614. struct ixgbe_hw *hw = &adapter->hw;
  2615. u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
  2616. /* don't reenable LSC while waiting for link */
  2617. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
  2618. mask &= ~IXGBE_EIMS_LSC;
  2619. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
  2620. switch (adapter->hw.mac.type) {
  2621. case ixgbe_mac_82599EB:
  2622. mask |= IXGBE_EIMS_GPI_SDP0(hw);
  2623. break;
  2624. case ixgbe_mac_X540:
  2625. case ixgbe_mac_X550:
  2626. case ixgbe_mac_X550EM_x:
  2627. case ixgbe_mac_x550em_a:
  2628. mask |= IXGBE_EIMS_TS;
  2629. break;
  2630. default:
  2631. break;
  2632. }
  2633. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  2634. mask |= IXGBE_EIMS_GPI_SDP1(hw);
  2635. switch (adapter->hw.mac.type) {
  2636. case ixgbe_mac_82599EB:
  2637. mask |= IXGBE_EIMS_GPI_SDP1(hw);
  2638. mask |= IXGBE_EIMS_GPI_SDP2(hw);
  2639. fallthrough;
  2640. case ixgbe_mac_X540:
  2641. case ixgbe_mac_X550:
  2642. case ixgbe_mac_X550EM_x:
  2643. case ixgbe_mac_x550em_a:
  2644. if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
  2645. adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
  2646. adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
  2647. mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
  2648. if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
  2649. mask |= IXGBE_EICR_GPI_SDP0_X540;
  2650. mask |= IXGBE_EIMS_ECC;
  2651. mask |= IXGBE_EIMS_MAILBOX;
  2652. break;
  2653. default:
  2654. break;
  2655. }
  2656. if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
  2657. !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
  2658. mask |= IXGBE_EIMS_FLOW_DIR;
  2659. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
  2660. if (queues)
  2661. ixgbe_irq_enable_queues(adapter, ~0);
  2662. if (flush)
  2663. IXGBE_WRITE_FLUSH(&adapter->hw);
  2664. }
  2665. static irqreturn_t ixgbe_msix_other(int irq, void *data)
  2666. {
  2667. struct ixgbe_adapter *adapter = data;
  2668. struct ixgbe_hw *hw = &adapter->hw;
  2669. u32 eicr;
  2670. /*
  2671. * Workaround for Silicon errata. Use clear-by-write instead
  2672. * of clear-by-read. Reading with EICS will return the
  2673. * interrupt causes without clearing, which later be done
  2674. * with the write to EICR.
  2675. */
  2676. eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
  2677. /* The lower 16bits of the EICR register are for the queue interrupts
  2678. * which should be masked here in order to not accidentally clear them if
  2679. * the bits are high when ixgbe_msix_other is called. There is a race
  2680. * condition otherwise which results in possible performance loss
  2681. * especially if the ixgbe_msix_other interrupt is triggering
  2682. * consistently (as it would when PPS is turned on for the X540 device)
  2683. */
  2684. eicr &= 0xFFFF0000;
  2685. IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
  2686. if (eicr & IXGBE_EICR_LSC)
  2687. ixgbe_check_lsc(adapter);
  2688. if (eicr & IXGBE_EICR_MAILBOX)
  2689. ixgbe_msg_task(adapter);
  2690. switch (hw->mac.type) {
  2691. case ixgbe_mac_82599EB:
  2692. case ixgbe_mac_X540:
  2693. case ixgbe_mac_X550:
  2694. case ixgbe_mac_X550EM_x:
  2695. case ixgbe_mac_x550em_a:
  2696. if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
  2697. (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
  2698. adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
  2699. ixgbe_service_event_schedule(adapter);
  2700. IXGBE_WRITE_REG(hw, IXGBE_EICR,
  2701. IXGBE_EICR_GPI_SDP0_X540);
  2702. }
  2703. if (eicr & IXGBE_EICR_ECC) {
  2704. e_info(link, "Received ECC Err, initiating reset\n");
  2705. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  2706. ixgbe_service_event_schedule(adapter);
  2707. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
  2708. }
  2709. /* Handle Flow Director Full threshold interrupt */
  2710. if (eicr & IXGBE_EICR_FLOW_DIR) {
  2711. int reinit_count = 0;
  2712. int i;
  2713. for (i = 0; i < adapter->num_tx_queues; i++) {
  2714. struct ixgbe_ring *ring = adapter->tx_ring[i];
  2715. if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
  2716. &ring->state))
  2717. reinit_count++;
  2718. }
  2719. if (reinit_count) {
  2720. /* no more flow director interrupts until after init */
  2721. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
  2722. adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  2723. ixgbe_service_event_schedule(adapter);
  2724. }
  2725. }
  2726. ixgbe_check_sfp_event(adapter, eicr);
  2727. ixgbe_check_overtemp_event(adapter, eicr);
  2728. break;
  2729. default:
  2730. break;
  2731. }
  2732. ixgbe_check_fan_failure(adapter, eicr);
  2733. if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
  2734. ixgbe_ptp_check_pps_event(adapter);
  2735. /* re-enable the original interrupt state, no lsc, no queues */
  2736. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2737. ixgbe_irq_enable(adapter, false, false);
  2738. return IRQ_HANDLED;
  2739. }
  2740. static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
  2741. {
  2742. struct ixgbe_q_vector *q_vector = data;
  2743. /* EIAM disabled interrupts (on this vector) for us */
  2744. if (q_vector->rx.ring || q_vector->tx.ring)
  2745. napi_schedule_irqoff(&q_vector->napi);
  2746. return IRQ_HANDLED;
  2747. }
  2748. /**
  2749. * ixgbe_poll - NAPI Rx polling callback
  2750. * @napi: structure for representing this polling device
  2751. * @budget: how many packets driver is allowed to clean
  2752. *
  2753. * This function is used for legacy and MSI, NAPI mode
  2754. **/
  2755. int ixgbe_poll(struct napi_struct *napi, int budget)
  2756. {
  2757. struct ixgbe_q_vector *q_vector =
  2758. container_of(napi, struct ixgbe_q_vector, napi);
  2759. struct ixgbe_adapter *adapter = q_vector->adapter;
  2760. struct ixgbe_ring *ring;
  2761. int per_ring_budget, work_done = 0;
  2762. bool clean_complete = true;
  2763. #ifdef CONFIG_IXGBE_DCA
  2764. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  2765. ixgbe_update_dca(q_vector);
  2766. #endif
  2767. ixgbe_for_each_ring(ring, q_vector->tx) {
  2768. bool wd = ring->xsk_pool ?
  2769. ixgbe_clean_xdp_tx_irq(q_vector, ring, budget) :
  2770. ixgbe_clean_tx_irq(q_vector, ring, budget);
  2771. if (!wd)
  2772. clean_complete = false;
  2773. }
  2774. /* Exit if we are called by netpoll */
  2775. if (budget <= 0)
  2776. return budget;
  2777. /* attempt to distribute budget to each queue fairly, but don't allow
  2778. * the budget to go below 1 because we'll exit polling */
  2779. if (q_vector->rx.count > 1)
  2780. per_ring_budget = max(budget/q_vector->rx.count, 1);
  2781. else
  2782. per_ring_budget = budget;
  2783. ixgbe_for_each_ring(ring, q_vector->rx) {
  2784. int cleaned = ring->xsk_pool ?
  2785. ixgbe_clean_rx_irq_zc(q_vector, ring,
  2786. per_ring_budget) :
  2787. ixgbe_clean_rx_irq(q_vector, ring,
  2788. per_ring_budget);
  2789. work_done += cleaned;
  2790. if (cleaned >= per_ring_budget)
  2791. clean_complete = false;
  2792. }
  2793. /* If all work not completed, return budget and keep polling */
  2794. if (!clean_complete)
  2795. return budget;
  2796. /* all work done, exit the polling mode */
  2797. if (likely(napi_complete_done(napi, work_done))) {
  2798. if (adapter->rx_itr_setting & 1)
  2799. ixgbe_set_itr(q_vector);
  2800. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2801. ixgbe_irq_enable_queues(adapter,
  2802. BIT_ULL(q_vector->v_idx));
  2803. }
  2804. return min(work_done, budget - 1);
  2805. }
  2806. /**
  2807. * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
  2808. * @adapter: board private structure
  2809. *
  2810. * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
  2811. * interrupts from the kernel.
  2812. **/
  2813. static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
  2814. {
  2815. struct net_device *netdev = adapter->netdev;
  2816. unsigned int ri = 0, ti = 0;
  2817. int vector, err;
  2818. for (vector = 0; vector < adapter->num_q_vectors; vector++) {
  2819. struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
  2820. struct msix_entry *entry = &adapter->msix_entries[vector];
  2821. if (q_vector->tx.ring && q_vector->rx.ring) {
  2822. snprintf(q_vector->name, sizeof(q_vector->name),
  2823. "%s-TxRx-%u", netdev->name, ri++);
  2824. ti++;
  2825. } else if (q_vector->rx.ring) {
  2826. snprintf(q_vector->name, sizeof(q_vector->name),
  2827. "%s-rx-%u", netdev->name, ri++);
  2828. } else if (q_vector->tx.ring) {
  2829. snprintf(q_vector->name, sizeof(q_vector->name),
  2830. "%s-tx-%u", netdev->name, ti++);
  2831. } else {
  2832. /* skip this unused q_vector */
  2833. continue;
  2834. }
  2835. err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
  2836. q_vector->name, q_vector);
  2837. if (err) {
  2838. e_err(probe, "request_irq failed for MSIX interrupt "
  2839. "Error: %d\n", err);
  2840. goto free_queue_irqs;
  2841. }
  2842. /* If Flow Director is enabled, set interrupt affinity */
  2843. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  2844. /* assign the mask for this irq */
  2845. irq_update_affinity_hint(entry->vector,
  2846. &q_vector->affinity_mask);
  2847. }
  2848. }
  2849. err = request_irq(adapter->msix_entries[vector].vector,
  2850. ixgbe_msix_other, 0, netdev->name, adapter);
  2851. if (err) {
  2852. e_err(probe, "request_irq for msix_other failed: %d\n", err);
  2853. goto free_queue_irqs;
  2854. }
  2855. return 0;
  2856. free_queue_irqs:
  2857. while (vector) {
  2858. vector--;
  2859. irq_update_affinity_hint(adapter->msix_entries[vector].vector,
  2860. NULL);
  2861. free_irq(adapter->msix_entries[vector].vector,
  2862. adapter->q_vector[vector]);
  2863. }
  2864. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  2865. pci_disable_msix(adapter->pdev);
  2866. kfree(adapter->msix_entries);
  2867. adapter->msix_entries = NULL;
  2868. return err;
  2869. }
  2870. /**
  2871. * ixgbe_intr - legacy mode Interrupt Handler
  2872. * @irq: interrupt number
  2873. * @data: pointer to a network interface device structure
  2874. **/
  2875. static irqreturn_t ixgbe_intr(int irq, void *data)
  2876. {
  2877. struct ixgbe_adapter *adapter = data;
  2878. struct ixgbe_hw *hw = &adapter->hw;
  2879. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  2880. u32 eicr;
  2881. /*
  2882. * Workaround for silicon errata #26 on 82598. Mask the interrupt
  2883. * before the read of EICR.
  2884. */
  2885. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  2886. /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
  2887. * therefore no explicit interrupt disable is necessary */
  2888. eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
  2889. if (!eicr) {
  2890. /*
  2891. * shared interrupt alert!
  2892. * make sure interrupts are enabled because the read will
  2893. * have disabled interrupts due to EIAM
  2894. * finish the workaround of silicon errata on 82598. Unmask
  2895. * the interrupt that we masked before the EICR read.
  2896. */
  2897. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2898. ixgbe_irq_enable(adapter, true, true);
  2899. return IRQ_NONE; /* Not our interrupt */
  2900. }
  2901. if (eicr & IXGBE_EICR_LSC)
  2902. ixgbe_check_lsc(adapter);
  2903. switch (hw->mac.type) {
  2904. case ixgbe_mac_82599EB:
  2905. ixgbe_check_sfp_event(adapter, eicr);
  2906. fallthrough;
  2907. case ixgbe_mac_X540:
  2908. case ixgbe_mac_X550:
  2909. case ixgbe_mac_X550EM_x:
  2910. case ixgbe_mac_x550em_a:
  2911. if (eicr & IXGBE_EICR_ECC) {
  2912. e_info(link, "Received ECC Err, initiating reset\n");
  2913. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  2914. ixgbe_service_event_schedule(adapter);
  2915. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
  2916. }
  2917. ixgbe_check_overtemp_event(adapter, eicr);
  2918. break;
  2919. default:
  2920. break;
  2921. }
  2922. ixgbe_check_fan_failure(adapter, eicr);
  2923. if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
  2924. ixgbe_ptp_check_pps_event(adapter);
  2925. /* would disable interrupts here but EIAM disabled it */
  2926. napi_schedule_irqoff(&q_vector->napi);
  2927. /*
  2928. * re-enable link(maybe) and non-queue interrupts, no flush.
  2929. * ixgbe_poll will re-enable the queue interrupts
  2930. */
  2931. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2932. ixgbe_irq_enable(adapter, false, false);
  2933. return IRQ_HANDLED;
  2934. }
  2935. /**
  2936. * ixgbe_request_irq - initialize interrupts
  2937. * @adapter: board private structure
  2938. *
  2939. * Attempts to configure interrupts using the best available
  2940. * capabilities of the hardware and kernel.
  2941. **/
  2942. static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
  2943. {
  2944. struct net_device *netdev = adapter->netdev;
  2945. int err;
  2946. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  2947. err = ixgbe_request_msix_irqs(adapter);
  2948. else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
  2949. err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
  2950. netdev->name, adapter);
  2951. else
  2952. err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
  2953. netdev->name, adapter);
  2954. if (err)
  2955. e_err(probe, "request_irq failed, Error %d\n", err);
  2956. return err;
  2957. }
  2958. static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
  2959. {
  2960. int vector;
  2961. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  2962. free_irq(adapter->pdev->irq, adapter);
  2963. return;
  2964. }
  2965. if (!adapter->msix_entries)
  2966. return;
  2967. for (vector = 0; vector < adapter->num_q_vectors; vector++) {
  2968. struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
  2969. struct msix_entry *entry = &adapter->msix_entries[vector];
  2970. /* free only the irqs that were actually requested */
  2971. if (!q_vector->rx.ring && !q_vector->tx.ring)
  2972. continue;
  2973. /* clear the affinity_mask in the IRQ descriptor */
  2974. irq_update_affinity_hint(entry->vector, NULL);
  2975. free_irq(entry->vector, q_vector);
  2976. }
  2977. free_irq(adapter->msix_entries[vector].vector, adapter);
  2978. }
  2979. /**
  2980. * ixgbe_irq_disable - Mask off interrupt generation on the NIC
  2981. * @adapter: board private structure
  2982. **/
  2983. static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
  2984. {
  2985. switch (adapter->hw.mac.type) {
  2986. case ixgbe_mac_82598EB:
  2987. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
  2988. break;
  2989. case ixgbe_mac_82599EB:
  2990. case ixgbe_mac_X540:
  2991. case ixgbe_mac_X550:
  2992. case ixgbe_mac_X550EM_x:
  2993. case ixgbe_mac_x550em_a:
  2994. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
  2995. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
  2996. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
  2997. break;
  2998. default:
  2999. break;
  3000. }
  3001. IXGBE_WRITE_FLUSH(&adapter->hw);
  3002. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  3003. int vector;
  3004. for (vector = 0; vector < adapter->num_q_vectors; vector++)
  3005. synchronize_irq(adapter->msix_entries[vector].vector);
  3006. synchronize_irq(adapter->msix_entries[vector++].vector);
  3007. } else {
  3008. synchronize_irq(adapter->pdev->irq);
  3009. }
  3010. }
  3011. /**
  3012. * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
  3013. * @adapter: board private structure
  3014. *
  3015. **/
  3016. static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
  3017. {
  3018. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  3019. ixgbe_write_eitr(q_vector);
  3020. ixgbe_set_ivar(adapter, 0, 0, 0);
  3021. ixgbe_set_ivar(adapter, 1, 0, 0);
  3022. e_info(hw, "Legacy interrupt IVAR setup done\n");
  3023. }
  3024. /**
  3025. * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
  3026. * @adapter: board private structure
  3027. * @ring: structure containing ring specific data
  3028. *
  3029. * Configure the Tx descriptor ring after a reset.
  3030. **/
  3031. void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
  3032. struct ixgbe_ring *ring)
  3033. {
  3034. struct ixgbe_hw *hw = &adapter->hw;
  3035. u64 tdba = ring->dma;
  3036. int wait_loop = 10;
  3037. u32 txdctl = IXGBE_TXDCTL_ENABLE;
  3038. u8 reg_idx = ring->reg_idx;
  3039. ring->xsk_pool = NULL;
  3040. if (ring_is_xdp(ring))
  3041. ring->xsk_pool = ixgbe_xsk_pool(adapter, ring);
  3042. /* disable queue to avoid issues while updating state */
  3043. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
  3044. IXGBE_WRITE_FLUSH(hw);
  3045. IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
  3046. (tdba & DMA_BIT_MASK(32)));
  3047. IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
  3048. IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
  3049. ring->count * sizeof(union ixgbe_adv_tx_desc));
  3050. IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
  3051. IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
  3052. ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
  3053. /*
  3054. * set WTHRESH to encourage burst writeback, it should not be set
  3055. * higher than 1 when:
  3056. * - ITR is 0 as it could cause false TX hangs
  3057. * - ITR is set to > 100k int/sec and BQL is enabled
  3058. *
  3059. * In order to avoid issues WTHRESH + PTHRESH should always be equal
  3060. * to or less than the number of on chip descriptors, which is
  3061. * currently 40.
  3062. */
  3063. if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
  3064. txdctl |= 1u << 16; /* WTHRESH = 1 */
  3065. else
  3066. txdctl |= 8u << 16; /* WTHRESH = 8 */
  3067. /*
  3068. * Setting PTHRESH to 32 both improves performance
  3069. * and avoids a TX hang with DFP enabled
  3070. */
  3071. txdctl |= (1u << 8) | /* HTHRESH = 1 */
  3072. 32; /* PTHRESH = 32 */
  3073. /* reinitialize flowdirector state */
  3074. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  3075. ring->atr_sample_rate = adapter->atr_sample_rate;
  3076. ring->atr_count = 0;
  3077. set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
  3078. } else {
  3079. ring->atr_sample_rate = 0;
  3080. }
  3081. /* initialize XPS */
  3082. if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
  3083. struct ixgbe_q_vector *q_vector = ring->q_vector;
  3084. if (q_vector)
  3085. netif_set_xps_queue(ring->netdev,
  3086. &q_vector->affinity_mask,
  3087. ring->queue_index);
  3088. }
  3089. clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
  3090. /* reinitialize tx_buffer_info */
  3091. memset(ring->tx_buffer_info, 0,
  3092. sizeof(struct ixgbe_tx_buffer) * ring->count);
  3093. /* enable queue */
  3094. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
  3095. /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
  3096. if (hw->mac.type == ixgbe_mac_82598EB &&
  3097. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  3098. return;
  3099. /* poll to verify queue is enabled */
  3100. do {
  3101. usleep_range(1000, 2000);
  3102. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
  3103. } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
  3104. if (!wait_loop)
  3105. hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx);
  3106. }
  3107. static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
  3108. {
  3109. struct ixgbe_hw *hw = &adapter->hw;
  3110. u32 rttdcs, mtqc;
  3111. u8 tcs = adapter->hw_tcs;
  3112. if (hw->mac.type == ixgbe_mac_82598EB)
  3113. return;
  3114. /* disable the arbiter while setting MTQC */
  3115. rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
  3116. rttdcs |= IXGBE_RTTDCS_ARBDIS;
  3117. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  3118. /* set transmit pool layout */
  3119. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  3120. mtqc = IXGBE_MTQC_VT_ENA;
  3121. if (tcs > 4)
  3122. mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
  3123. else if (tcs > 1)
  3124. mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
  3125. else if (adapter->ring_feature[RING_F_VMDQ].mask ==
  3126. IXGBE_82599_VMDQ_4Q_MASK)
  3127. mtqc |= IXGBE_MTQC_32VF;
  3128. else
  3129. mtqc |= IXGBE_MTQC_64VF;
  3130. } else {
  3131. if (tcs > 4) {
  3132. mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
  3133. } else if (tcs > 1) {
  3134. mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
  3135. } else {
  3136. u8 max_txq = adapter->num_tx_queues +
  3137. adapter->num_xdp_queues;
  3138. if (max_txq > 63)
  3139. mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
  3140. else
  3141. mtqc = IXGBE_MTQC_64Q_1PB;
  3142. }
  3143. }
  3144. IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
  3145. /* Enable Security TX Buffer IFG for multiple pb */
  3146. if (tcs) {
  3147. u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
  3148. sectx |= IXGBE_SECTX_DCB;
  3149. IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
  3150. }
  3151. /* re-enable the arbiter */
  3152. rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
  3153. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  3154. }
  3155. /**
  3156. * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
  3157. * @adapter: board private structure
  3158. *
  3159. * Configure the Tx unit of the MAC after a reset.
  3160. **/
  3161. static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
  3162. {
  3163. struct ixgbe_hw *hw = &adapter->hw;
  3164. u32 dmatxctl;
  3165. u32 i;
  3166. ixgbe_setup_mtqc(adapter);
  3167. if (hw->mac.type != ixgbe_mac_82598EB) {
  3168. /* DMATXCTL.EN must be before Tx queues are enabled */
  3169. dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
  3170. dmatxctl |= IXGBE_DMATXCTL_TE;
  3171. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
  3172. }
  3173. /* Setup the HW Tx Head and Tail descriptor pointers */
  3174. for (i = 0; i < adapter->num_tx_queues; i++)
  3175. ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
  3176. for (i = 0; i < adapter->num_xdp_queues; i++)
  3177. ixgbe_configure_tx_ring(adapter, adapter->xdp_ring[i]);
  3178. }
  3179. static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
  3180. struct ixgbe_ring *ring)
  3181. {
  3182. struct ixgbe_hw *hw = &adapter->hw;
  3183. u8 reg_idx = ring->reg_idx;
  3184. u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
  3185. srrctl |= IXGBE_SRRCTL_DROP_EN;
  3186. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  3187. }
  3188. static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
  3189. struct ixgbe_ring *ring)
  3190. {
  3191. struct ixgbe_hw *hw = &adapter->hw;
  3192. u8 reg_idx = ring->reg_idx;
  3193. u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
  3194. srrctl &= ~IXGBE_SRRCTL_DROP_EN;
  3195. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  3196. }
  3197. #ifdef CONFIG_IXGBE_DCB
  3198. void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
  3199. #else
  3200. static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
  3201. #endif
  3202. {
  3203. int i;
  3204. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  3205. if (adapter->ixgbe_ieee_pfc)
  3206. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  3207. /*
  3208. * We should set the drop enable bit if:
  3209. * SR-IOV is enabled
  3210. * or
  3211. * Number of Rx queues > 1 and flow control is disabled
  3212. *
  3213. * This allows us to avoid head of line blocking for security
  3214. * and performance reasons.
  3215. */
  3216. if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
  3217. !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
  3218. for (i = 0; i < adapter->num_rx_queues; i++)
  3219. ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
  3220. } else {
  3221. for (i = 0; i < adapter->num_rx_queues; i++)
  3222. ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
  3223. }
  3224. }
  3225. #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
  3226. static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
  3227. struct ixgbe_ring *rx_ring)
  3228. {
  3229. struct ixgbe_hw *hw = &adapter->hw;
  3230. u32 srrctl;
  3231. u8 reg_idx = rx_ring->reg_idx;
  3232. if (hw->mac.type == ixgbe_mac_82598EB) {
  3233. u16 mask = adapter->ring_feature[RING_F_RSS].mask;
  3234. /*
  3235. * if VMDq is not active we must program one srrctl register
  3236. * per RSS queue since we have enabled RDRXCTL.MVMEN
  3237. */
  3238. reg_idx &= mask;
  3239. }
  3240. /* configure header buffer length, needed for RSC */
  3241. srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
  3242. /* configure the packet buffer length */
  3243. if (rx_ring->xsk_pool) {
  3244. u32 xsk_buf_len = xsk_pool_get_rx_frame_size(rx_ring->xsk_pool);
  3245. /* If the MAC support setting RXDCTL.RLPML, the
  3246. * SRRCTL[n].BSIZEPKT is set to PAGE_SIZE and
  3247. * RXDCTL.RLPML is set to the actual UMEM buffer
  3248. * size. If not, then we are stuck with a 1k buffer
  3249. * size resolution. In this case frames larger than
  3250. * the UMEM buffer size viewed in a 1k resolution will
  3251. * be dropped.
  3252. */
  3253. if (hw->mac.type != ixgbe_mac_82599EB)
  3254. srrctl |= PAGE_SIZE >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  3255. else
  3256. srrctl |= xsk_buf_len >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  3257. } else if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state)) {
  3258. srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  3259. } else {
  3260. srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  3261. }
  3262. /* configure descriptor type */
  3263. srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
  3264. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  3265. }
  3266. /**
  3267. * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
  3268. * @adapter: device handle
  3269. *
  3270. * - 82598/82599/X540: 128
  3271. * - X550(non-SRIOV mode): 512
  3272. * - X550(SRIOV mode): 64
  3273. */
  3274. u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
  3275. {
  3276. if (adapter->hw.mac.type < ixgbe_mac_X550)
  3277. return 128;
  3278. else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  3279. return 64;
  3280. else
  3281. return 512;
  3282. }
  3283. /**
  3284. * ixgbe_store_key - Write the RSS key to HW
  3285. * @adapter: device handle
  3286. *
  3287. * Write the RSS key stored in adapter.rss_key to HW.
  3288. */
  3289. void ixgbe_store_key(struct ixgbe_adapter *adapter)
  3290. {
  3291. struct ixgbe_hw *hw = &adapter->hw;
  3292. int i;
  3293. for (i = 0; i < 10; i++)
  3294. IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
  3295. }
  3296. /**
  3297. * ixgbe_init_rss_key - Initialize adapter RSS key
  3298. * @adapter: device handle
  3299. *
  3300. * Allocates and initializes the RSS key if it is not allocated.
  3301. **/
  3302. static inline int ixgbe_init_rss_key(struct ixgbe_adapter *adapter)
  3303. {
  3304. u32 *rss_key;
  3305. if (!adapter->rss_key) {
  3306. rss_key = kzalloc(IXGBE_RSS_KEY_SIZE, GFP_KERNEL);
  3307. if (unlikely(!rss_key))
  3308. return -ENOMEM;
  3309. netdev_rss_key_fill(rss_key, IXGBE_RSS_KEY_SIZE);
  3310. adapter->rss_key = rss_key;
  3311. }
  3312. return 0;
  3313. }
  3314. /**
  3315. * ixgbe_store_reta - Write the RETA table to HW
  3316. * @adapter: device handle
  3317. *
  3318. * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
  3319. */
  3320. void ixgbe_store_reta(struct ixgbe_adapter *adapter)
  3321. {
  3322. u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  3323. struct ixgbe_hw *hw = &adapter->hw;
  3324. u32 reta = 0;
  3325. u32 indices_multi;
  3326. u8 *indir_tbl = adapter->rss_indir_tbl;
  3327. /* Fill out the redirection table as follows:
  3328. * - 82598: 8 bit wide entries containing pair of 4 bit RSS
  3329. * indices.
  3330. * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
  3331. * - X550: 8 bit wide entries containing 6 bit RSS index
  3332. */
  3333. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  3334. indices_multi = 0x11;
  3335. else
  3336. indices_multi = 0x1;
  3337. /* Write redirection table to HW */
  3338. for (i = 0; i < reta_entries; i++) {
  3339. reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
  3340. if ((i & 3) == 3) {
  3341. if (i < 128)
  3342. IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
  3343. else
  3344. IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
  3345. reta);
  3346. reta = 0;
  3347. }
  3348. }
  3349. }
  3350. /**
  3351. * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
  3352. * @adapter: device handle
  3353. *
  3354. * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
  3355. */
  3356. static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
  3357. {
  3358. u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  3359. struct ixgbe_hw *hw = &adapter->hw;
  3360. u32 vfreta = 0;
  3361. /* Write redirection table to HW */
  3362. for (i = 0; i < reta_entries; i++) {
  3363. u16 pool = adapter->num_rx_pools;
  3364. vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
  3365. if ((i & 3) != 3)
  3366. continue;
  3367. while (pool--)
  3368. IXGBE_WRITE_REG(hw,
  3369. IXGBE_PFVFRETA(i >> 2, VMDQ_P(pool)),
  3370. vfreta);
  3371. vfreta = 0;
  3372. }
  3373. }
  3374. static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
  3375. {
  3376. u32 i, j;
  3377. u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  3378. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  3379. /* Program table for at least 4 queues w/ SR-IOV so that VFs can
  3380. * make full use of any rings they may have. We will use the
  3381. * PSRTYPE register to control how many rings we use within the PF.
  3382. */
  3383. if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4))
  3384. rss_i = 4;
  3385. /* Fill out hash function seeds */
  3386. ixgbe_store_key(adapter);
  3387. /* Fill out redirection table */
  3388. memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
  3389. for (i = 0, j = 0; i < reta_entries; i++, j++) {
  3390. if (j == rss_i)
  3391. j = 0;
  3392. adapter->rss_indir_tbl[i] = j;
  3393. }
  3394. ixgbe_store_reta(adapter);
  3395. }
  3396. static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
  3397. {
  3398. struct ixgbe_hw *hw = &adapter->hw;
  3399. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  3400. int i, j;
  3401. /* Fill out hash function seeds */
  3402. for (i = 0; i < 10; i++) {
  3403. u16 pool = adapter->num_rx_pools;
  3404. while (pool--)
  3405. IXGBE_WRITE_REG(hw,
  3406. IXGBE_PFVFRSSRK(i, VMDQ_P(pool)),
  3407. *(adapter->rss_key + i));
  3408. }
  3409. /* Fill out the redirection table */
  3410. for (i = 0, j = 0; i < 64; i++, j++) {
  3411. if (j == rss_i)
  3412. j = 0;
  3413. adapter->rss_indir_tbl[i] = j;
  3414. }
  3415. ixgbe_store_vfreta(adapter);
  3416. }
  3417. static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
  3418. {
  3419. struct ixgbe_hw *hw = &adapter->hw;
  3420. u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
  3421. u32 rxcsum;
  3422. /* Disable indicating checksum in descriptor, enables RSS hash */
  3423. rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
  3424. rxcsum |= IXGBE_RXCSUM_PCSD;
  3425. IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
  3426. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  3427. if (adapter->ring_feature[RING_F_RSS].mask)
  3428. mrqc = IXGBE_MRQC_RSSEN;
  3429. } else {
  3430. u8 tcs = adapter->hw_tcs;
  3431. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  3432. if (tcs > 4)
  3433. mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
  3434. else if (tcs > 1)
  3435. mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
  3436. else if (adapter->ring_feature[RING_F_VMDQ].mask ==
  3437. IXGBE_82599_VMDQ_4Q_MASK)
  3438. mrqc = IXGBE_MRQC_VMDQRSS32EN;
  3439. else
  3440. mrqc = IXGBE_MRQC_VMDQRSS64EN;
  3441. /* Enable L3/L4 for Tx Switched packets only for X550,
  3442. * older devices do not support this feature
  3443. */
  3444. if (hw->mac.type >= ixgbe_mac_X550)
  3445. mrqc |= IXGBE_MRQC_L3L4TXSWEN;
  3446. } else {
  3447. if (tcs > 4)
  3448. mrqc = IXGBE_MRQC_RTRSS8TCEN;
  3449. else if (tcs > 1)
  3450. mrqc = IXGBE_MRQC_RTRSS4TCEN;
  3451. else
  3452. mrqc = IXGBE_MRQC_RSSEN;
  3453. }
  3454. }
  3455. /* Perform hash on these packet types */
  3456. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
  3457. IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
  3458. IXGBE_MRQC_RSS_FIELD_IPV6 |
  3459. IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
  3460. if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
  3461. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
  3462. if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
  3463. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
  3464. if ((hw->mac.type >= ixgbe_mac_X550) &&
  3465. (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
  3466. u16 pool = adapter->num_rx_pools;
  3467. /* Enable VF RSS mode */
  3468. mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
  3469. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  3470. /* Setup RSS through the VF registers */
  3471. ixgbe_setup_vfreta(adapter);
  3472. vfmrqc = IXGBE_MRQC_RSSEN;
  3473. vfmrqc |= rss_field;
  3474. while (pool--)
  3475. IXGBE_WRITE_REG(hw,
  3476. IXGBE_PFVFMRQC(VMDQ_P(pool)),
  3477. vfmrqc);
  3478. } else {
  3479. ixgbe_setup_reta(adapter);
  3480. mrqc |= rss_field;
  3481. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  3482. }
  3483. }
  3484. /**
  3485. * ixgbe_configure_rscctl - enable RSC for the indicated ring
  3486. * @adapter: address of board private structure
  3487. * @ring: structure containing ring specific data
  3488. **/
  3489. static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
  3490. struct ixgbe_ring *ring)
  3491. {
  3492. struct ixgbe_hw *hw = &adapter->hw;
  3493. u32 rscctrl;
  3494. u8 reg_idx = ring->reg_idx;
  3495. if (!ring_is_rsc_enabled(ring))
  3496. return;
  3497. rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
  3498. rscctrl |= IXGBE_RSCCTL_RSCEN;
  3499. /*
  3500. * we must limit the number of descriptors so that the
  3501. * total size of max desc * buf_len is not greater
  3502. * than 65536
  3503. */
  3504. rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
  3505. IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
  3506. }
  3507. #define IXGBE_MAX_RX_DESC_POLL 10
  3508. static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
  3509. struct ixgbe_ring *ring)
  3510. {
  3511. struct ixgbe_hw *hw = &adapter->hw;
  3512. int wait_loop = IXGBE_MAX_RX_DESC_POLL;
  3513. u32 rxdctl;
  3514. u8 reg_idx = ring->reg_idx;
  3515. if (ixgbe_removed(hw->hw_addr))
  3516. return;
  3517. /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
  3518. if (hw->mac.type == ixgbe_mac_82598EB &&
  3519. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  3520. return;
  3521. do {
  3522. usleep_range(1000, 2000);
  3523. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3524. } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
  3525. if (!wait_loop) {
  3526. e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
  3527. "the polling period\n", reg_idx);
  3528. }
  3529. }
  3530. void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
  3531. struct ixgbe_ring *ring)
  3532. {
  3533. struct ixgbe_hw *hw = &adapter->hw;
  3534. union ixgbe_adv_rx_desc *rx_desc;
  3535. u64 rdba = ring->dma;
  3536. u32 rxdctl;
  3537. u8 reg_idx = ring->reg_idx;
  3538. xdp_rxq_info_unreg_mem_model(&ring->xdp_rxq);
  3539. ring->xsk_pool = ixgbe_xsk_pool(adapter, ring);
  3540. if (ring->xsk_pool) {
  3541. WARN_ON(xdp_rxq_info_reg_mem_model(&ring->xdp_rxq,
  3542. MEM_TYPE_XSK_BUFF_POOL,
  3543. NULL));
  3544. xsk_pool_set_rxq_info(ring->xsk_pool, &ring->xdp_rxq);
  3545. } else {
  3546. WARN_ON(xdp_rxq_info_reg_mem_model(&ring->xdp_rxq,
  3547. MEM_TYPE_PAGE_SHARED, NULL));
  3548. }
  3549. /* disable queue to avoid use of these values while updating state */
  3550. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3551. rxdctl &= ~IXGBE_RXDCTL_ENABLE;
  3552. /* write value back with RXDCTL.ENABLE bit cleared */
  3553. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  3554. IXGBE_WRITE_FLUSH(hw);
  3555. IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
  3556. IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
  3557. IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
  3558. ring->count * sizeof(union ixgbe_adv_rx_desc));
  3559. /* Force flushing of IXGBE_RDLEN to prevent MDD */
  3560. IXGBE_WRITE_FLUSH(hw);
  3561. IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
  3562. IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
  3563. ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
  3564. ixgbe_configure_srrctl(adapter, ring);
  3565. ixgbe_configure_rscctl(adapter, ring);
  3566. if (hw->mac.type == ixgbe_mac_82598EB) {
  3567. /*
  3568. * enable cache line friendly hardware writes:
  3569. * PTHRESH=32 descriptors (half the internal cache),
  3570. * this also removes ugly rx_no_buffer_count increment
  3571. * HTHRESH=4 descriptors (to minimize latency on fetch)
  3572. * WTHRESH=8 burst writeback up to two cache lines
  3573. */
  3574. rxdctl &= ~0x3FFFFF;
  3575. rxdctl |= 0x080420;
  3576. #if (PAGE_SIZE < 8192)
  3577. /* RXDCTL.RLPML does not work on 82599 */
  3578. } else if (hw->mac.type != ixgbe_mac_82599EB) {
  3579. rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK |
  3580. IXGBE_RXDCTL_RLPML_EN);
  3581. /* Limit the maximum frame size so we don't overrun the skb.
  3582. * This can happen in SRIOV mode when the MTU of the VF is
  3583. * higher than the MTU of the PF.
  3584. */
  3585. if (ring_uses_build_skb(ring) &&
  3586. !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state))
  3587. rxdctl |= IXGBE_MAX_2K_FRAME_BUILD_SKB |
  3588. IXGBE_RXDCTL_RLPML_EN;
  3589. #endif
  3590. }
  3591. ring->rx_offset = ixgbe_rx_offset(ring);
  3592. if (ring->xsk_pool && hw->mac.type != ixgbe_mac_82599EB) {
  3593. u32 xsk_buf_len = xsk_pool_get_rx_frame_size(ring->xsk_pool);
  3594. rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK |
  3595. IXGBE_RXDCTL_RLPML_EN);
  3596. rxdctl |= xsk_buf_len | IXGBE_RXDCTL_RLPML_EN;
  3597. ring->rx_buf_len = xsk_buf_len;
  3598. }
  3599. /* initialize rx_buffer_info */
  3600. memset(ring->rx_buffer_info, 0,
  3601. sizeof(struct ixgbe_rx_buffer) * ring->count);
  3602. /* initialize Rx descriptor 0 */
  3603. rx_desc = IXGBE_RX_DESC(ring, 0);
  3604. rx_desc->wb.upper.length = 0;
  3605. /* enable receive descriptor ring */
  3606. rxdctl |= IXGBE_RXDCTL_ENABLE;
  3607. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  3608. ixgbe_rx_desc_queue_enable(adapter, ring);
  3609. if (ring->xsk_pool)
  3610. ixgbe_alloc_rx_buffers_zc(ring, ixgbe_desc_unused(ring));
  3611. else
  3612. ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
  3613. }
  3614. static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
  3615. {
  3616. struct ixgbe_hw *hw = &adapter->hw;
  3617. int rss_i = adapter->ring_feature[RING_F_RSS].indices;
  3618. u16 pool = adapter->num_rx_pools;
  3619. /* PSRTYPE must be initialized in non 82598 adapters */
  3620. u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
  3621. IXGBE_PSRTYPE_UDPHDR |
  3622. IXGBE_PSRTYPE_IPV4HDR |
  3623. IXGBE_PSRTYPE_L2HDR |
  3624. IXGBE_PSRTYPE_IPV6HDR;
  3625. if (hw->mac.type == ixgbe_mac_82598EB)
  3626. return;
  3627. if (rss_i > 3)
  3628. psrtype |= 2u << 29;
  3629. else if (rss_i > 1)
  3630. psrtype |= 1u << 29;
  3631. while (pool--)
  3632. IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
  3633. }
  3634. static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
  3635. {
  3636. struct ixgbe_hw *hw = &adapter->hw;
  3637. u16 pool = adapter->num_rx_pools;
  3638. u32 reg_offset, vf_shift, vmolr;
  3639. u32 gcr_ext, vmdctl;
  3640. int i;
  3641. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  3642. return;
  3643. vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  3644. vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
  3645. vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
  3646. vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
  3647. vmdctl |= IXGBE_VT_CTL_REPLEN;
  3648. IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
  3649. /* accept untagged packets until a vlan tag is
  3650. * specifically set for the VMDQ queue/pool
  3651. */
  3652. vmolr = IXGBE_VMOLR_AUPE;
  3653. while (pool--)
  3654. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(pool)), vmolr);
  3655. vf_shift = VMDQ_P(0) % 32;
  3656. reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
  3657. /* Enable only the PF's pool for Tx/Rx */
  3658. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift));
  3659. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
  3660. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift));
  3661. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
  3662. if (adapter->bridge_mode == BRIDGE_MODE_VEB)
  3663. IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
  3664. /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
  3665. hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
  3666. /* clear VLAN promisc flag so VFTA will be updated if necessary */
  3667. adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
  3668. /*
  3669. * Set up VF register offsets for selected VT Mode,
  3670. * i.e. 32 or 64 VFs for SR-IOV
  3671. */
  3672. switch (adapter->ring_feature[RING_F_VMDQ].mask) {
  3673. case IXGBE_82599_VMDQ_8Q_MASK:
  3674. gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
  3675. break;
  3676. case IXGBE_82599_VMDQ_4Q_MASK:
  3677. gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
  3678. break;
  3679. default:
  3680. gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
  3681. break;
  3682. }
  3683. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
  3684. for (i = 0; i < adapter->num_vfs; i++) {
  3685. /* configure spoof checking */
  3686. ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i,
  3687. adapter->vfinfo[i].spoofchk_enabled);
  3688. /* Enable/Disable RSS query feature */
  3689. ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
  3690. adapter->vfinfo[i].rss_query_enabled);
  3691. }
  3692. }
  3693. static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
  3694. {
  3695. struct ixgbe_hw *hw = &adapter->hw;
  3696. struct net_device *netdev = adapter->netdev;
  3697. int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  3698. struct ixgbe_ring *rx_ring;
  3699. int i;
  3700. u32 mhadd, hlreg0;
  3701. #ifdef IXGBE_FCOE
  3702. /* adjust max frame to be able to do baby jumbo for FCoE */
  3703. if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
  3704. (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
  3705. max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  3706. #endif /* IXGBE_FCOE */
  3707. /* adjust max frame to be at least the size of a standard frame */
  3708. if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
  3709. max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
  3710. mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
  3711. if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
  3712. mhadd &= ~IXGBE_MHADD_MFS_MASK;
  3713. mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
  3714. IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
  3715. }
  3716. hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
  3717. /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
  3718. hlreg0 |= IXGBE_HLREG0_JUMBOEN;
  3719. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
  3720. /*
  3721. * Setup the HW Rx Head and Tail Descriptor Pointers and
  3722. * the Base and Length of the Rx Descriptor Ring
  3723. */
  3724. for (i = 0; i < adapter->num_rx_queues; i++) {
  3725. rx_ring = adapter->rx_ring[i];
  3726. clear_ring_rsc_enabled(rx_ring);
  3727. clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3728. clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
  3729. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  3730. set_ring_rsc_enabled(rx_ring);
  3731. if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state))
  3732. set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3733. if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY)
  3734. continue;
  3735. set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
  3736. #if (PAGE_SIZE < 8192)
  3737. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  3738. set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3739. if (IXGBE_2K_TOO_SMALL_WITH_PADDING ||
  3740. (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
  3741. set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3742. #endif
  3743. }
  3744. }
  3745. static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
  3746. {
  3747. struct ixgbe_hw *hw = &adapter->hw;
  3748. u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  3749. switch (hw->mac.type) {
  3750. case ixgbe_mac_82598EB:
  3751. /*
  3752. * For VMDq support of different descriptor types or
  3753. * buffer sizes through the use of multiple SRRCTL
  3754. * registers, RDRXCTL.MVMEN must be set to 1
  3755. *
  3756. * also, the manual doesn't mention it clearly but DCA hints
  3757. * will only use queue 0's tags unless this bit is set. Side
  3758. * effects of setting this bit are only that SRRCTL must be
  3759. * fully programmed [0..15]
  3760. */
  3761. rdrxctl |= IXGBE_RDRXCTL_MVMEN;
  3762. break;
  3763. case ixgbe_mac_X550:
  3764. case ixgbe_mac_X550EM_x:
  3765. case ixgbe_mac_x550em_a:
  3766. if (adapter->num_vfs)
  3767. rdrxctl |= IXGBE_RDRXCTL_PSP;
  3768. fallthrough;
  3769. case ixgbe_mac_82599EB:
  3770. case ixgbe_mac_X540:
  3771. /* Disable RSC for ACK packets */
  3772. IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
  3773. (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
  3774. rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
  3775. /* hardware requires some bits to be set by default */
  3776. rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
  3777. rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
  3778. break;
  3779. default:
  3780. /* We should do nothing since we don't know this hardware */
  3781. return;
  3782. }
  3783. IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
  3784. }
  3785. /**
  3786. * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
  3787. * @adapter: board private structure
  3788. *
  3789. * Configure the Rx unit of the MAC after a reset.
  3790. **/
  3791. static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
  3792. {
  3793. struct ixgbe_hw *hw = &adapter->hw;
  3794. int i;
  3795. u32 rxctrl, rfctl;
  3796. /* disable receives while setting up the descriptors */
  3797. hw->mac.ops.disable_rx(hw);
  3798. ixgbe_setup_psrtype(adapter);
  3799. ixgbe_setup_rdrxctl(adapter);
  3800. /* RSC Setup */
  3801. rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
  3802. rfctl &= ~IXGBE_RFCTL_RSC_DIS;
  3803. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
  3804. rfctl |= IXGBE_RFCTL_RSC_DIS;
  3805. /* disable NFS filtering */
  3806. rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS);
  3807. IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
  3808. /* Program registers for the distribution of queues */
  3809. ixgbe_setup_mrqc(adapter);
  3810. /* set_rx_buffer_len must be called before ring initialization */
  3811. ixgbe_set_rx_buffer_len(adapter);
  3812. /*
  3813. * Setup the HW Rx Head and Tail Descriptor Pointers and
  3814. * the Base and Length of the Rx Descriptor Ring
  3815. */
  3816. for (i = 0; i < adapter->num_rx_queues; i++)
  3817. ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
  3818. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  3819. /* disable drop enable for 82598 parts */
  3820. if (hw->mac.type == ixgbe_mac_82598EB)
  3821. rxctrl |= IXGBE_RXCTRL_DMBYPS;
  3822. /* enable all receives */
  3823. rxctrl |= IXGBE_RXCTRL_RXEN;
  3824. hw->mac.ops.enable_rx_dma(hw, rxctrl);
  3825. }
  3826. static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
  3827. __be16 proto, u16 vid)
  3828. {
  3829. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3830. struct ixgbe_hw *hw = &adapter->hw;
  3831. /* add VID to filter table */
  3832. if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3833. hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
  3834. set_bit(vid, adapter->active_vlans);
  3835. return 0;
  3836. }
  3837. static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
  3838. {
  3839. u32 vlvf;
  3840. int idx;
  3841. /* short cut the special case */
  3842. if (vlan == 0)
  3843. return 0;
  3844. /* Search for the vlan id in the VLVF entries */
  3845. for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
  3846. vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
  3847. if ((vlvf & VLAN_VID_MASK) == vlan)
  3848. break;
  3849. }
  3850. return idx;
  3851. }
  3852. void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
  3853. {
  3854. struct ixgbe_hw *hw = &adapter->hw;
  3855. u32 bits, word;
  3856. int idx;
  3857. idx = ixgbe_find_vlvf_entry(hw, vid);
  3858. if (!idx)
  3859. return;
  3860. /* See if any other pools are set for this VLAN filter
  3861. * entry other than the PF.
  3862. */
  3863. word = idx * 2 + (VMDQ_P(0) / 32);
  3864. bits = ~BIT(VMDQ_P(0) % 32);
  3865. bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
  3866. /* Disable the filter so this falls into the default pool. */
  3867. if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
  3868. if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3869. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
  3870. IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
  3871. }
  3872. }
  3873. static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
  3874. __be16 proto, u16 vid)
  3875. {
  3876. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3877. struct ixgbe_hw *hw = &adapter->hw;
  3878. /* remove VID from filter table */
  3879. if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3880. hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
  3881. clear_bit(vid, adapter->active_vlans);
  3882. return 0;
  3883. }
  3884. /**
  3885. * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
  3886. * @adapter: driver data
  3887. */
  3888. static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
  3889. {
  3890. struct ixgbe_hw *hw = &adapter->hw;
  3891. u32 vlnctrl;
  3892. int i, j;
  3893. switch (hw->mac.type) {
  3894. case ixgbe_mac_82598EB:
  3895. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3896. vlnctrl &= ~IXGBE_VLNCTRL_VME;
  3897. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3898. break;
  3899. case ixgbe_mac_82599EB:
  3900. case ixgbe_mac_X540:
  3901. case ixgbe_mac_X550:
  3902. case ixgbe_mac_X550EM_x:
  3903. case ixgbe_mac_x550em_a:
  3904. for (i = 0; i < adapter->num_rx_queues; i++) {
  3905. struct ixgbe_ring *ring = adapter->rx_ring[i];
  3906. if (!netif_is_ixgbe(ring->netdev))
  3907. continue;
  3908. j = ring->reg_idx;
  3909. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  3910. vlnctrl &= ~IXGBE_RXDCTL_VME;
  3911. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  3912. }
  3913. break;
  3914. default:
  3915. break;
  3916. }
  3917. }
  3918. /**
  3919. * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
  3920. * @adapter: driver data
  3921. */
  3922. static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
  3923. {
  3924. struct ixgbe_hw *hw = &adapter->hw;
  3925. u32 vlnctrl;
  3926. int i, j;
  3927. switch (hw->mac.type) {
  3928. case ixgbe_mac_82598EB:
  3929. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3930. vlnctrl |= IXGBE_VLNCTRL_VME;
  3931. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3932. break;
  3933. case ixgbe_mac_82599EB:
  3934. case ixgbe_mac_X540:
  3935. case ixgbe_mac_X550:
  3936. case ixgbe_mac_X550EM_x:
  3937. case ixgbe_mac_x550em_a:
  3938. for (i = 0; i < adapter->num_rx_queues; i++) {
  3939. struct ixgbe_ring *ring = adapter->rx_ring[i];
  3940. if (!netif_is_ixgbe(ring->netdev))
  3941. continue;
  3942. j = ring->reg_idx;
  3943. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  3944. vlnctrl |= IXGBE_RXDCTL_VME;
  3945. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  3946. }
  3947. break;
  3948. default:
  3949. break;
  3950. }
  3951. }
  3952. static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
  3953. {
  3954. struct ixgbe_hw *hw = &adapter->hw;
  3955. u32 vlnctrl, i;
  3956. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3957. if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
  3958. /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
  3959. vlnctrl |= IXGBE_VLNCTRL_VFE;
  3960. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3961. } else {
  3962. vlnctrl &= ~IXGBE_VLNCTRL_VFE;
  3963. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3964. return;
  3965. }
  3966. /* Nothing to do for 82598 */
  3967. if (hw->mac.type == ixgbe_mac_82598EB)
  3968. return;
  3969. /* We are already in VLAN promisc, nothing to do */
  3970. if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
  3971. return;
  3972. /* Set flag so we don't redo unnecessary work */
  3973. adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
  3974. /* Add PF to all active pools */
  3975. for (i = IXGBE_VLVF_ENTRIES; --i;) {
  3976. u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
  3977. u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
  3978. vlvfb |= BIT(VMDQ_P(0) % 32);
  3979. IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
  3980. }
  3981. /* Set all bits in the VLAN filter table array */
  3982. for (i = hw->mac.vft_size; i--;)
  3983. IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
  3984. }
  3985. #define VFTA_BLOCK_SIZE 8
  3986. static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
  3987. {
  3988. struct ixgbe_hw *hw = &adapter->hw;
  3989. u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
  3990. u32 vid_start = vfta_offset * 32;
  3991. u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
  3992. u32 i, vid, word, bits;
  3993. for (i = IXGBE_VLVF_ENTRIES; --i;) {
  3994. u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
  3995. /* pull VLAN ID from VLVF */
  3996. vid = vlvf & VLAN_VID_MASK;
  3997. /* only concern outselves with a certain range */
  3998. if (vid < vid_start || vid >= vid_end)
  3999. continue;
  4000. if (vlvf) {
  4001. /* record VLAN ID in VFTA */
  4002. vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
  4003. /* if PF is part of this then continue */
  4004. if (test_bit(vid, adapter->active_vlans))
  4005. continue;
  4006. }
  4007. /* remove PF from the pool */
  4008. word = i * 2 + VMDQ_P(0) / 32;
  4009. bits = ~BIT(VMDQ_P(0) % 32);
  4010. bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
  4011. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
  4012. }
  4013. /* extract values from active_vlans and write back to VFTA */
  4014. for (i = VFTA_BLOCK_SIZE; i--;) {
  4015. vid = (vfta_offset + i) * 32;
  4016. word = vid / BITS_PER_LONG;
  4017. bits = vid % BITS_PER_LONG;
  4018. vfta[i] |= adapter->active_vlans[word] >> bits;
  4019. IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
  4020. }
  4021. }
  4022. static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
  4023. {
  4024. struct ixgbe_hw *hw = &adapter->hw;
  4025. u32 vlnctrl, i;
  4026. /* Set VLAN filtering to enabled */
  4027. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  4028. vlnctrl |= IXGBE_VLNCTRL_VFE;
  4029. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  4030. if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) ||
  4031. hw->mac.type == ixgbe_mac_82598EB)
  4032. return;
  4033. /* We are not in VLAN promisc, nothing to do */
  4034. if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  4035. return;
  4036. /* Set flag so we don't redo unnecessary work */
  4037. adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
  4038. for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
  4039. ixgbe_scrub_vfta(adapter, i);
  4040. }
  4041. static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
  4042. {
  4043. u16 vid = 1;
  4044. ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
  4045. for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
  4046. ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
  4047. }
  4048. /**
  4049. * ixgbe_write_mc_addr_list - write multicast addresses to MTA
  4050. * @netdev: network interface device structure
  4051. *
  4052. * Writes multicast address list to the MTA hash table.
  4053. * Returns: -ENOMEM on failure
  4054. * 0 on no addresses written
  4055. * X on writing X addresses to MTA
  4056. **/
  4057. static int ixgbe_write_mc_addr_list(struct net_device *netdev)
  4058. {
  4059. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4060. struct ixgbe_hw *hw = &adapter->hw;
  4061. if (!netif_running(netdev))
  4062. return 0;
  4063. if (hw->mac.ops.update_mc_addr_list)
  4064. hw->mac.ops.update_mc_addr_list(hw, netdev);
  4065. else
  4066. return -ENOMEM;
  4067. #ifdef CONFIG_PCI_IOV
  4068. ixgbe_restore_vf_multicasts(adapter);
  4069. #endif
  4070. return netdev_mc_count(netdev);
  4071. }
  4072. #ifdef CONFIG_PCI_IOV
  4073. void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
  4074. {
  4075. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4076. struct ixgbe_hw *hw = &adapter->hw;
  4077. int i;
  4078. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4079. mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
  4080. if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
  4081. hw->mac.ops.set_rar(hw, i,
  4082. mac_table->addr,
  4083. mac_table->pool,
  4084. IXGBE_RAH_AV);
  4085. else
  4086. hw->mac.ops.clear_rar(hw, i);
  4087. }
  4088. }
  4089. #endif
  4090. static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
  4091. {
  4092. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4093. struct ixgbe_hw *hw = &adapter->hw;
  4094. int i;
  4095. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4096. if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
  4097. continue;
  4098. mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
  4099. if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
  4100. hw->mac.ops.set_rar(hw, i,
  4101. mac_table->addr,
  4102. mac_table->pool,
  4103. IXGBE_RAH_AV);
  4104. else
  4105. hw->mac.ops.clear_rar(hw, i);
  4106. }
  4107. }
  4108. static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
  4109. {
  4110. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4111. struct ixgbe_hw *hw = &adapter->hw;
  4112. int i;
  4113. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4114. mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
  4115. mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
  4116. }
  4117. ixgbe_sync_mac_table(adapter);
  4118. }
  4119. static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
  4120. {
  4121. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4122. struct ixgbe_hw *hw = &adapter->hw;
  4123. int i, count = 0;
  4124. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4125. /* do not count default RAR as available */
  4126. if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
  4127. continue;
  4128. /* only count unused and addresses that belong to us */
  4129. if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
  4130. if (mac_table->pool != pool)
  4131. continue;
  4132. }
  4133. count++;
  4134. }
  4135. return count;
  4136. }
  4137. /* this function destroys the first RAR entry */
  4138. static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
  4139. {
  4140. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4141. struct ixgbe_hw *hw = &adapter->hw;
  4142. memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
  4143. mac_table->pool = VMDQ_P(0);
  4144. mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
  4145. hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
  4146. IXGBE_RAH_AV);
  4147. }
  4148. int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
  4149. const u8 *addr, u16 pool)
  4150. {
  4151. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4152. struct ixgbe_hw *hw = &adapter->hw;
  4153. int i;
  4154. if (is_zero_ether_addr(addr))
  4155. return -EINVAL;
  4156. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4157. if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
  4158. continue;
  4159. ether_addr_copy(mac_table->addr, addr);
  4160. mac_table->pool = pool;
  4161. mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
  4162. IXGBE_MAC_STATE_IN_USE;
  4163. ixgbe_sync_mac_table(adapter);
  4164. return i;
  4165. }
  4166. return -ENOMEM;
  4167. }
  4168. int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
  4169. const u8 *addr, u16 pool)
  4170. {
  4171. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4172. struct ixgbe_hw *hw = &adapter->hw;
  4173. int i;
  4174. if (is_zero_ether_addr(addr))
  4175. return -EINVAL;
  4176. /* search table for addr, if found clear IN_USE flag and sync */
  4177. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4178. /* we can only delete an entry if it is in use */
  4179. if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
  4180. continue;
  4181. /* we only care about entries that belong to the given pool */
  4182. if (mac_table->pool != pool)
  4183. continue;
  4184. /* we only care about a specific MAC address */
  4185. if (!ether_addr_equal(addr, mac_table->addr))
  4186. continue;
  4187. mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
  4188. mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
  4189. ixgbe_sync_mac_table(adapter);
  4190. return 0;
  4191. }
  4192. return -ENOMEM;
  4193. }
  4194. static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
  4195. {
  4196. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4197. int ret;
  4198. ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
  4199. return min_t(int, ret, 0);
  4200. }
  4201. static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
  4202. {
  4203. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4204. ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
  4205. return 0;
  4206. }
  4207. /**
  4208. * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
  4209. * @netdev: network interface device structure
  4210. *
  4211. * The set_rx_method entry point is called whenever the unicast/multicast
  4212. * address list or the network interface flags are updated. This routine is
  4213. * responsible for configuring the hardware for proper unicast, multicast and
  4214. * promiscuous mode.
  4215. **/
  4216. void ixgbe_set_rx_mode(struct net_device *netdev)
  4217. {
  4218. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4219. struct ixgbe_hw *hw = &adapter->hw;
  4220. u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
  4221. netdev_features_t features = netdev->features;
  4222. int count;
  4223. /* Check for Promiscuous and All Multicast modes */
  4224. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  4225. /* set all bits that we expect to always be set */
  4226. fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
  4227. fctrl |= IXGBE_FCTRL_BAM;
  4228. fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
  4229. fctrl |= IXGBE_FCTRL_PMCF;
  4230. /* clear the bits we are changing the status of */
  4231. fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  4232. if (netdev->flags & IFF_PROMISC) {
  4233. hw->addr_ctrl.user_set_promisc = true;
  4234. fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  4235. vmolr |= IXGBE_VMOLR_MPE;
  4236. features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
  4237. } else {
  4238. if (netdev->flags & IFF_ALLMULTI) {
  4239. fctrl |= IXGBE_FCTRL_MPE;
  4240. vmolr |= IXGBE_VMOLR_MPE;
  4241. }
  4242. hw->addr_ctrl.user_set_promisc = false;
  4243. }
  4244. /*
  4245. * Write addresses to available RAR registers, if there is not
  4246. * sufficient space to store all the addresses then enable
  4247. * unicast promiscuous mode
  4248. */
  4249. if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
  4250. fctrl |= IXGBE_FCTRL_UPE;
  4251. vmolr |= IXGBE_VMOLR_ROPE;
  4252. }
  4253. /* Write addresses to the MTA, if the attempt fails
  4254. * then we should just turn on promiscuous mode so
  4255. * that we can at least receive multicast traffic
  4256. */
  4257. count = ixgbe_write_mc_addr_list(netdev);
  4258. if (count < 0) {
  4259. fctrl |= IXGBE_FCTRL_MPE;
  4260. vmolr |= IXGBE_VMOLR_MPE;
  4261. } else if (count) {
  4262. vmolr |= IXGBE_VMOLR_ROMPE;
  4263. }
  4264. if (hw->mac.type != ixgbe_mac_82598EB) {
  4265. vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
  4266. ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
  4267. IXGBE_VMOLR_ROPE);
  4268. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
  4269. }
  4270. /* This is useful for sniffing bad packets. */
  4271. if (features & NETIF_F_RXALL) {
  4272. /* UPE and MPE will be handled by normal PROMISC logic
  4273. * in e1000e_set_rx_mode */
  4274. fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
  4275. IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
  4276. IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
  4277. fctrl &= ~(IXGBE_FCTRL_DPF);
  4278. /* NOTE: VLAN filtering is disabled by setting PROMISC */
  4279. }
  4280. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  4281. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  4282. ixgbe_vlan_strip_enable(adapter);
  4283. else
  4284. ixgbe_vlan_strip_disable(adapter);
  4285. if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
  4286. ixgbe_vlan_promisc_disable(adapter);
  4287. else
  4288. ixgbe_vlan_promisc_enable(adapter);
  4289. }
  4290. static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
  4291. {
  4292. int q_idx;
  4293. for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
  4294. napi_enable(&adapter->q_vector[q_idx]->napi);
  4295. }
  4296. static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
  4297. {
  4298. int q_idx;
  4299. for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
  4300. napi_disable(&adapter->q_vector[q_idx]->napi);
  4301. }
  4302. static int ixgbe_udp_tunnel_sync(struct net_device *dev, unsigned int table)
  4303. {
  4304. struct ixgbe_adapter *adapter = netdev_priv(dev);
  4305. struct ixgbe_hw *hw = &adapter->hw;
  4306. struct udp_tunnel_info ti;
  4307. udp_tunnel_nic_get_port(dev, table, 0, &ti);
  4308. if (ti.type == UDP_TUNNEL_TYPE_VXLAN)
  4309. adapter->vxlan_port = ti.port;
  4310. else
  4311. adapter->geneve_port = ti.port;
  4312. IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL,
  4313. ntohs(adapter->vxlan_port) |
  4314. ntohs(adapter->geneve_port) <<
  4315. IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT);
  4316. return 0;
  4317. }
  4318. static const struct udp_tunnel_nic_info ixgbe_udp_tunnels_x550 = {
  4319. .sync_table = ixgbe_udp_tunnel_sync,
  4320. .flags = UDP_TUNNEL_NIC_INFO_IPV4_ONLY,
  4321. .tables = {
  4322. { .n_entries = 1, .tunnel_types = UDP_TUNNEL_TYPE_VXLAN, },
  4323. },
  4324. };
  4325. static const struct udp_tunnel_nic_info ixgbe_udp_tunnels_x550em_a = {
  4326. .sync_table = ixgbe_udp_tunnel_sync,
  4327. .flags = UDP_TUNNEL_NIC_INFO_IPV4_ONLY,
  4328. .tables = {
  4329. { .n_entries = 1, .tunnel_types = UDP_TUNNEL_TYPE_VXLAN, },
  4330. { .n_entries = 1, .tunnel_types = UDP_TUNNEL_TYPE_GENEVE, },
  4331. },
  4332. };
  4333. #ifdef CONFIG_IXGBE_DCB
  4334. /**
  4335. * ixgbe_configure_dcb - Configure DCB hardware
  4336. * @adapter: ixgbe adapter struct
  4337. *
  4338. * This is called by the driver on open to configure the DCB hardware.
  4339. * This is also called by the gennetlink interface when reconfiguring
  4340. * the DCB state.
  4341. */
  4342. static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
  4343. {
  4344. struct ixgbe_hw *hw = &adapter->hw;
  4345. int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  4346. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
  4347. if (hw->mac.type == ixgbe_mac_82598EB)
  4348. netif_set_tso_max_size(adapter->netdev, 65536);
  4349. return;
  4350. }
  4351. if (hw->mac.type == ixgbe_mac_82598EB)
  4352. netif_set_tso_max_size(adapter->netdev, 32768);
  4353. #ifdef IXGBE_FCOE
  4354. if (adapter->netdev->fcoe_mtu)
  4355. max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
  4356. #endif
  4357. /* reconfigure the hardware */
  4358. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
  4359. ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
  4360. DCB_TX_CONFIG);
  4361. ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
  4362. DCB_RX_CONFIG);
  4363. ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
  4364. } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
  4365. ixgbe_dcb_hw_ets(&adapter->hw,
  4366. adapter->ixgbe_ieee_ets,
  4367. max_frame);
  4368. ixgbe_dcb_hw_pfc_config(&adapter->hw,
  4369. adapter->ixgbe_ieee_pfc->pfc_en,
  4370. adapter->ixgbe_ieee_ets->prio_tc);
  4371. }
  4372. /* Enable RSS Hash per TC */
  4373. if (hw->mac.type != ixgbe_mac_82598EB) {
  4374. u32 msb = 0;
  4375. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
  4376. while (rss_i) {
  4377. msb++;
  4378. rss_i >>= 1;
  4379. }
  4380. /* write msb to all 8 TCs in one write */
  4381. IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
  4382. }
  4383. }
  4384. #endif
  4385. /* Additional bittime to account for IXGBE framing */
  4386. #define IXGBE_ETH_FRAMING 20
  4387. /**
  4388. * ixgbe_hpbthresh - calculate high water mark for flow control
  4389. *
  4390. * @adapter: board private structure to calculate for
  4391. * @pb: packet buffer to calculate
  4392. */
  4393. static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
  4394. {
  4395. struct ixgbe_hw *hw = &adapter->hw;
  4396. struct net_device *dev = adapter->netdev;
  4397. int link, tc, kb, marker;
  4398. u32 dv_id, rx_pba;
  4399. /* Calculate max LAN frame size */
  4400. tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
  4401. #ifdef IXGBE_FCOE
  4402. /* FCoE traffic class uses FCOE jumbo frames */
  4403. if (dev->fcoe_mtu && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE &&
  4404. (pb == ixgbe_fcoe_get_tc(adapter)))
  4405. tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  4406. #endif
  4407. /* Calculate delay value for device */
  4408. switch (hw->mac.type) {
  4409. case ixgbe_mac_X540:
  4410. case ixgbe_mac_X550:
  4411. case ixgbe_mac_X550EM_x:
  4412. case ixgbe_mac_x550em_a:
  4413. dv_id = IXGBE_DV_X540(link, tc);
  4414. break;
  4415. default:
  4416. dv_id = IXGBE_DV(link, tc);
  4417. break;
  4418. }
  4419. /* Loopback switch introduces additional latency */
  4420. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  4421. dv_id += IXGBE_B2BT(tc);
  4422. /* Delay value is calculated in bit times convert to KB */
  4423. kb = IXGBE_BT2KB(dv_id);
  4424. rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
  4425. marker = rx_pba - kb;
  4426. /* It is possible that the packet buffer is not large enough
  4427. * to provide required headroom. In this case throw an error
  4428. * to user and a do the best we can.
  4429. */
  4430. if (marker < 0) {
  4431. e_warn(drv, "Packet Buffer(%i) can not provide enough"
  4432. "headroom to support flow control."
  4433. "Decrease MTU or number of traffic classes\n", pb);
  4434. marker = tc + 1;
  4435. }
  4436. return marker;
  4437. }
  4438. /**
  4439. * ixgbe_lpbthresh - calculate low water mark for flow control
  4440. *
  4441. * @adapter: board private structure to calculate for
  4442. * @pb: packet buffer to calculate
  4443. */
  4444. static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
  4445. {
  4446. struct ixgbe_hw *hw = &adapter->hw;
  4447. struct net_device *dev = adapter->netdev;
  4448. int tc;
  4449. u32 dv_id;
  4450. /* Calculate max LAN frame size */
  4451. tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
  4452. #ifdef IXGBE_FCOE
  4453. /* FCoE traffic class uses FCOE jumbo frames */
  4454. if (dev->fcoe_mtu && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE &&
  4455. (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
  4456. tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  4457. #endif
  4458. /* Calculate delay value for device */
  4459. switch (hw->mac.type) {
  4460. case ixgbe_mac_X540:
  4461. case ixgbe_mac_X550:
  4462. case ixgbe_mac_X550EM_x:
  4463. case ixgbe_mac_x550em_a:
  4464. dv_id = IXGBE_LOW_DV_X540(tc);
  4465. break;
  4466. default:
  4467. dv_id = IXGBE_LOW_DV(tc);
  4468. break;
  4469. }
  4470. /* Delay value is calculated in bit times convert to KB */
  4471. return IXGBE_BT2KB(dv_id);
  4472. }
  4473. /*
  4474. * ixgbe_pbthresh_setup - calculate and setup high low water marks
  4475. */
  4476. static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
  4477. {
  4478. struct ixgbe_hw *hw = &adapter->hw;
  4479. int num_tc = adapter->hw_tcs;
  4480. int i;
  4481. if (!num_tc)
  4482. num_tc = 1;
  4483. for (i = 0; i < num_tc; i++) {
  4484. hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
  4485. hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
  4486. /* Low water marks must not be larger than high water marks */
  4487. if (hw->fc.low_water[i] > hw->fc.high_water[i])
  4488. hw->fc.low_water[i] = 0;
  4489. }
  4490. for (; i < MAX_TRAFFIC_CLASS; i++)
  4491. hw->fc.high_water[i] = 0;
  4492. }
  4493. static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
  4494. {
  4495. struct ixgbe_hw *hw = &adapter->hw;
  4496. int hdrm;
  4497. u8 tc = adapter->hw_tcs;
  4498. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  4499. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  4500. hdrm = 32 << adapter->fdir_pballoc;
  4501. else
  4502. hdrm = 0;
  4503. hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
  4504. ixgbe_pbthresh_setup(adapter);
  4505. }
  4506. static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
  4507. {
  4508. struct ixgbe_hw *hw = &adapter->hw;
  4509. struct hlist_node *node2;
  4510. struct ixgbe_fdir_filter *filter;
  4511. u8 queue;
  4512. spin_lock(&adapter->fdir_perfect_lock);
  4513. if (!hlist_empty(&adapter->fdir_filter_list))
  4514. ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
  4515. hlist_for_each_entry_safe(filter, node2,
  4516. &adapter->fdir_filter_list, fdir_node) {
  4517. if (filter->action == IXGBE_FDIR_DROP_QUEUE) {
  4518. queue = IXGBE_FDIR_DROP_QUEUE;
  4519. } else {
  4520. u32 ring = ethtool_get_flow_spec_ring(filter->action);
  4521. u8 vf = ethtool_get_flow_spec_ring_vf(filter->action);
  4522. if (!vf && (ring >= adapter->num_rx_queues)) {
  4523. e_err(drv, "FDIR restore failed without VF, ring: %u\n",
  4524. ring);
  4525. continue;
  4526. } else if (vf &&
  4527. ((vf > adapter->num_vfs) ||
  4528. ring >= adapter->num_rx_queues_per_pool)) {
  4529. e_err(drv, "FDIR restore failed with VF, vf: %hhu, ring: %u\n",
  4530. vf, ring);
  4531. continue;
  4532. }
  4533. /* Map the ring onto the absolute queue index */
  4534. if (!vf)
  4535. queue = adapter->rx_ring[ring]->reg_idx;
  4536. else
  4537. queue = ((vf - 1) *
  4538. adapter->num_rx_queues_per_pool) + ring;
  4539. }
  4540. ixgbe_fdir_write_perfect_filter_82599(hw,
  4541. &filter->filter, filter->sw_idx, queue);
  4542. }
  4543. spin_unlock(&adapter->fdir_perfect_lock);
  4544. }
  4545. /**
  4546. * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
  4547. * @rx_ring: ring to free buffers from
  4548. **/
  4549. static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
  4550. {
  4551. u16 i = rx_ring->next_to_clean;
  4552. struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
  4553. if (rx_ring->xsk_pool) {
  4554. ixgbe_xsk_clean_rx_ring(rx_ring);
  4555. goto skip_free;
  4556. }
  4557. /* Free all the Rx ring sk_buffs */
  4558. while (i != rx_ring->next_to_alloc) {
  4559. if (rx_buffer->skb) {
  4560. struct sk_buff *skb = rx_buffer->skb;
  4561. if (IXGBE_CB(skb)->page_released)
  4562. dma_unmap_page_attrs(rx_ring->dev,
  4563. IXGBE_CB(skb)->dma,
  4564. ixgbe_rx_pg_size(rx_ring),
  4565. DMA_FROM_DEVICE,
  4566. IXGBE_RX_DMA_ATTR);
  4567. dev_kfree_skb(skb);
  4568. }
  4569. /* Invalidate cache lines that may have been written to by
  4570. * device so that we avoid corrupting memory.
  4571. */
  4572. dma_sync_single_range_for_cpu(rx_ring->dev,
  4573. rx_buffer->dma,
  4574. rx_buffer->page_offset,
  4575. ixgbe_rx_bufsz(rx_ring),
  4576. DMA_FROM_DEVICE);
  4577. /* free resources associated with mapping */
  4578. dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
  4579. ixgbe_rx_pg_size(rx_ring),
  4580. DMA_FROM_DEVICE,
  4581. IXGBE_RX_DMA_ATTR);
  4582. __page_frag_cache_drain(rx_buffer->page,
  4583. rx_buffer->pagecnt_bias);
  4584. i++;
  4585. rx_buffer++;
  4586. if (i == rx_ring->count) {
  4587. i = 0;
  4588. rx_buffer = rx_ring->rx_buffer_info;
  4589. }
  4590. }
  4591. skip_free:
  4592. rx_ring->next_to_alloc = 0;
  4593. rx_ring->next_to_clean = 0;
  4594. rx_ring->next_to_use = 0;
  4595. }
  4596. static int ixgbe_fwd_ring_up(struct ixgbe_adapter *adapter,
  4597. struct ixgbe_fwd_adapter *accel)
  4598. {
  4599. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  4600. int num_tc = netdev_get_num_tc(adapter->netdev);
  4601. struct net_device *vdev = accel->netdev;
  4602. int i, baseq, err;
  4603. baseq = accel->pool * adapter->num_rx_queues_per_pool;
  4604. netdev_dbg(vdev, "pool %i:%i queues %i:%i\n",
  4605. accel->pool, adapter->num_rx_pools,
  4606. baseq, baseq + adapter->num_rx_queues_per_pool);
  4607. accel->rx_base_queue = baseq;
  4608. accel->tx_base_queue = baseq;
  4609. /* record configuration for macvlan interface in vdev */
  4610. for (i = 0; i < num_tc; i++)
  4611. netdev_bind_sb_channel_queue(adapter->netdev, vdev,
  4612. i, rss_i, baseq + (rss_i * i));
  4613. for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
  4614. adapter->rx_ring[baseq + i]->netdev = vdev;
  4615. /* Guarantee all rings are updated before we update the
  4616. * MAC address filter.
  4617. */
  4618. wmb();
  4619. /* ixgbe_add_mac_filter will return an index if it succeeds, so we
  4620. * need to only treat it as an error value if it is negative.
  4621. */
  4622. err = ixgbe_add_mac_filter(adapter, vdev->dev_addr,
  4623. VMDQ_P(accel->pool));
  4624. if (err >= 0)
  4625. return 0;
  4626. /* if we cannot add the MAC rule then disable the offload */
  4627. macvlan_release_l2fw_offload(vdev);
  4628. for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
  4629. adapter->rx_ring[baseq + i]->netdev = NULL;
  4630. netdev_err(vdev, "L2FW offload disabled due to L2 filter error\n");
  4631. /* unbind the queues and drop the subordinate channel config */
  4632. netdev_unbind_sb_channel(adapter->netdev, vdev);
  4633. netdev_set_sb_channel(vdev, 0);
  4634. clear_bit(accel->pool, adapter->fwd_bitmask);
  4635. kfree(accel);
  4636. return err;
  4637. }
  4638. static int ixgbe_macvlan_up(struct net_device *vdev,
  4639. struct netdev_nested_priv *priv)
  4640. {
  4641. struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)priv->data;
  4642. struct ixgbe_fwd_adapter *accel;
  4643. if (!netif_is_macvlan(vdev))
  4644. return 0;
  4645. accel = macvlan_accel_priv(vdev);
  4646. if (!accel)
  4647. return 0;
  4648. ixgbe_fwd_ring_up(adapter, accel);
  4649. return 0;
  4650. }
  4651. static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
  4652. {
  4653. struct netdev_nested_priv priv = {
  4654. .data = (void *)adapter,
  4655. };
  4656. netdev_walk_all_upper_dev_rcu(adapter->netdev,
  4657. ixgbe_macvlan_up, &priv);
  4658. }
  4659. static void ixgbe_configure(struct ixgbe_adapter *adapter)
  4660. {
  4661. struct ixgbe_hw *hw = &adapter->hw;
  4662. ixgbe_configure_pb(adapter);
  4663. #ifdef CONFIG_IXGBE_DCB
  4664. ixgbe_configure_dcb(adapter);
  4665. #endif
  4666. /*
  4667. * We must restore virtualization before VLANs or else
  4668. * the VLVF registers will not be populated
  4669. */
  4670. ixgbe_configure_virtualization(adapter);
  4671. ixgbe_set_rx_mode(adapter->netdev);
  4672. ixgbe_restore_vlan(adapter);
  4673. ixgbe_ipsec_restore(adapter);
  4674. switch (hw->mac.type) {
  4675. case ixgbe_mac_82599EB:
  4676. case ixgbe_mac_X540:
  4677. hw->mac.ops.disable_rx_buff(hw);
  4678. break;
  4679. default:
  4680. break;
  4681. }
  4682. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  4683. ixgbe_init_fdir_signature_82599(&adapter->hw,
  4684. adapter->fdir_pballoc);
  4685. } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
  4686. ixgbe_init_fdir_perfect_82599(&adapter->hw,
  4687. adapter->fdir_pballoc);
  4688. ixgbe_fdir_filter_restore(adapter);
  4689. }
  4690. switch (hw->mac.type) {
  4691. case ixgbe_mac_82599EB:
  4692. case ixgbe_mac_X540:
  4693. hw->mac.ops.enable_rx_buff(hw);
  4694. break;
  4695. default:
  4696. break;
  4697. }
  4698. #ifdef CONFIG_IXGBE_DCA
  4699. /* configure DCA */
  4700. if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
  4701. ixgbe_setup_dca(adapter);
  4702. #endif /* CONFIG_IXGBE_DCA */
  4703. #ifdef IXGBE_FCOE
  4704. /* configure FCoE L2 filters, redirection table, and Rx control */
  4705. ixgbe_configure_fcoe(adapter);
  4706. #endif /* IXGBE_FCOE */
  4707. ixgbe_configure_tx(adapter);
  4708. ixgbe_configure_rx(adapter);
  4709. ixgbe_configure_dfwd(adapter);
  4710. }
  4711. /**
  4712. * ixgbe_sfp_link_config - set up SFP+ link
  4713. * @adapter: pointer to private adapter struct
  4714. **/
  4715. static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
  4716. {
  4717. /*
  4718. * We are assuming the worst case scenario here, and that
  4719. * is that an SFP was inserted/removed after the reset
  4720. * but before SFP detection was enabled. As such the best
  4721. * solution is to just start searching as soon as we start
  4722. */
  4723. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  4724. adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
  4725. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  4726. adapter->sfp_poll_time = 0;
  4727. }
  4728. /**
  4729. * ixgbe_non_sfp_link_config - set up non-SFP+ link
  4730. * @hw: pointer to private hardware struct
  4731. *
  4732. * Returns 0 on success, negative on failure
  4733. **/
  4734. static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
  4735. {
  4736. u32 speed;
  4737. bool autoneg, link_up = false;
  4738. int ret = -EIO;
  4739. if (hw->mac.ops.check_link)
  4740. ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
  4741. if (ret)
  4742. return ret;
  4743. speed = hw->phy.autoneg_advertised;
  4744. if (!speed && hw->mac.ops.get_link_capabilities) {
  4745. ret = hw->mac.ops.get_link_capabilities(hw, &speed,
  4746. &autoneg);
  4747. /* remove NBASE-T speeds from default autonegotiation
  4748. * to accommodate broken network switches in the field
  4749. * which cannot cope with advertised NBASE-T speeds
  4750. */
  4751. speed &= ~(IXGBE_LINK_SPEED_5GB_FULL |
  4752. IXGBE_LINK_SPEED_2_5GB_FULL);
  4753. }
  4754. if (ret)
  4755. return ret;
  4756. if (hw->mac.ops.setup_link)
  4757. ret = hw->mac.ops.setup_link(hw, speed, link_up);
  4758. return ret;
  4759. }
  4760. /**
  4761. * ixgbe_clear_vf_stats_counters - Clear out VF stats after reset
  4762. * @adapter: board private structure
  4763. *
  4764. * On a reset we need to clear out the VF stats or accounting gets
  4765. * messed up because they're not clear on read.
  4766. **/
  4767. static void ixgbe_clear_vf_stats_counters(struct ixgbe_adapter *adapter)
  4768. {
  4769. struct ixgbe_hw *hw = &adapter->hw;
  4770. int i;
  4771. for (i = 0; i < adapter->num_vfs; i++) {
  4772. adapter->vfinfo[i].last_vfstats.gprc =
  4773. IXGBE_READ_REG(hw, IXGBE_PVFGPRC(i));
  4774. adapter->vfinfo[i].saved_rst_vfstats.gprc +=
  4775. adapter->vfinfo[i].vfstats.gprc;
  4776. adapter->vfinfo[i].vfstats.gprc = 0;
  4777. adapter->vfinfo[i].last_vfstats.gptc =
  4778. IXGBE_READ_REG(hw, IXGBE_PVFGPTC(i));
  4779. adapter->vfinfo[i].saved_rst_vfstats.gptc +=
  4780. adapter->vfinfo[i].vfstats.gptc;
  4781. adapter->vfinfo[i].vfstats.gptc = 0;
  4782. adapter->vfinfo[i].last_vfstats.gorc =
  4783. IXGBE_READ_REG(hw, IXGBE_PVFGORC_LSB(i));
  4784. adapter->vfinfo[i].saved_rst_vfstats.gorc +=
  4785. adapter->vfinfo[i].vfstats.gorc;
  4786. adapter->vfinfo[i].vfstats.gorc = 0;
  4787. adapter->vfinfo[i].last_vfstats.gotc =
  4788. IXGBE_READ_REG(hw, IXGBE_PVFGOTC_LSB(i));
  4789. adapter->vfinfo[i].saved_rst_vfstats.gotc +=
  4790. adapter->vfinfo[i].vfstats.gotc;
  4791. adapter->vfinfo[i].vfstats.gotc = 0;
  4792. adapter->vfinfo[i].last_vfstats.mprc =
  4793. IXGBE_READ_REG(hw, IXGBE_PVFMPRC(i));
  4794. adapter->vfinfo[i].saved_rst_vfstats.mprc +=
  4795. adapter->vfinfo[i].vfstats.mprc;
  4796. adapter->vfinfo[i].vfstats.mprc = 0;
  4797. }
  4798. }
  4799. static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
  4800. {
  4801. struct ixgbe_hw *hw = &adapter->hw;
  4802. u32 gpie = 0;
  4803. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  4804. gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
  4805. IXGBE_GPIE_OCD;
  4806. gpie |= IXGBE_GPIE_EIAME;
  4807. /*
  4808. * use EIAM to auto-mask when MSI-X interrupt is asserted
  4809. * this saves a register write for every interrupt
  4810. */
  4811. switch (hw->mac.type) {
  4812. case ixgbe_mac_82598EB:
  4813. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  4814. break;
  4815. case ixgbe_mac_82599EB:
  4816. case ixgbe_mac_X540:
  4817. case ixgbe_mac_X550:
  4818. case ixgbe_mac_X550EM_x:
  4819. case ixgbe_mac_x550em_a:
  4820. default:
  4821. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
  4822. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
  4823. break;
  4824. }
  4825. } else {
  4826. /* legacy interrupts, use EIAM to auto-mask when reading EICR,
  4827. * specifically only auto mask tx and rx interrupts */
  4828. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  4829. }
  4830. /* XXX: to interrupt immediately for EICS writes, enable this */
  4831. /* gpie |= IXGBE_GPIE_EIMEN; */
  4832. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  4833. gpie &= ~IXGBE_GPIE_VTMODE_MASK;
  4834. switch (adapter->ring_feature[RING_F_VMDQ].mask) {
  4835. case IXGBE_82599_VMDQ_8Q_MASK:
  4836. gpie |= IXGBE_GPIE_VTMODE_16;
  4837. break;
  4838. case IXGBE_82599_VMDQ_4Q_MASK:
  4839. gpie |= IXGBE_GPIE_VTMODE_32;
  4840. break;
  4841. default:
  4842. gpie |= IXGBE_GPIE_VTMODE_64;
  4843. break;
  4844. }
  4845. }
  4846. /* Enable Thermal over heat sensor interrupt */
  4847. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
  4848. switch (adapter->hw.mac.type) {
  4849. case ixgbe_mac_82599EB:
  4850. gpie |= IXGBE_SDP0_GPIEN_8259X;
  4851. break;
  4852. default:
  4853. break;
  4854. }
  4855. }
  4856. /* Enable fan failure interrupt */
  4857. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  4858. gpie |= IXGBE_SDP1_GPIEN(hw);
  4859. switch (hw->mac.type) {
  4860. case ixgbe_mac_82599EB:
  4861. gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
  4862. break;
  4863. case ixgbe_mac_X550EM_x:
  4864. case ixgbe_mac_x550em_a:
  4865. gpie |= IXGBE_SDP0_GPIEN_X540;
  4866. break;
  4867. default:
  4868. break;
  4869. }
  4870. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  4871. }
  4872. static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
  4873. {
  4874. struct ixgbe_hw *hw = &adapter->hw;
  4875. int err;
  4876. u32 ctrl_ext;
  4877. ixgbe_get_hw_control(adapter);
  4878. ixgbe_setup_gpie(adapter);
  4879. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  4880. ixgbe_configure_msix(adapter);
  4881. else
  4882. ixgbe_configure_msi_and_legacy(adapter);
  4883. /* enable the optics for 82599 SFP+ fiber */
  4884. if (hw->mac.ops.enable_tx_laser)
  4885. hw->mac.ops.enable_tx_laser(hw);
  4886. if (hw->phy.ops.set_phy_power)
  4887. hw->phy.ops.set_phy_power(hw, true);
  4888. smp_mb__before_atomic();
  4889. clear_bit(__IXGBE_DOWN, &adapter->state);
  4890. ixgbe_napi_enable_all(adapter);
  4891. if (ixgbe_is_sfp(hw)) {
  4892. ixgbe_sfp_link_config(adapter);
  4893. } else {
  4894. err = ixgbe_non_sfp_link_config(hw);
  4895. if (err)
  4896. e_err(probe, "link_config FAILED %d\n", err);
  4897. }
  4898. /* clear any pending interrupts, may auto mask */
  4899. IXGBE_READ_REG(hw, IXGBE_EICR);
  4900. ixgbe_irq_enable(adapter, true, true);
  4901. /*
  4902. * If this adapter has a fan, check to see if we had a failure
  4903. * before we enabled the interrupt.
  4904. */
  4905. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  4906. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  4907. if (esdp & IXGBE_ESDP_SDP1)
  4908. e_crit(drv, "Fan has stopped, replace the adapter\n");
  4909. }
  4910. /* bring the link up in the watchdog, this could race with our first
  4911. * link up interrupt but shouldn't be a problem */
  4912. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  4913. adapter->link_check_timeout = jiffies;
  4914. mod_timer(&adapter->service_timer, jiffies);
  4915. ixgbe_clear_vf_stats_counters(adapter);
  4916. /* Set PF Reset Done bit so PF/VF Mail Ops can work */
  4917. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  4918. ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
  4919. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  4920. /* update setting rx tx for all active vfs */
  4921. ixgbe_set_all_vfs(adapter);
  4922. }
  4923. void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
  4924. {
  4925. /* put off any impending NetWatchDogTimeout */
  4926. netif_trans_update(adapter->netdev);
  4927. while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
  4928. usleep_range(1000, 2000);
  4929. if (adapter->hw.phy.type == ixgbe_phy_fw)
  4930. ixgbe_watchdog_link_is_down(adapter);
  4931. ixgbe_down(adapter);
  4932. /*
  4933. * If SR-IOV enabled then wait a bit before bringing the adapter
  4934. * back up to give the VFs time to respond to the reset. The
  4935. * two second wait is based upon the watchdog timer cycle in
  4936. * the VF driver.
  4937. */
  4938. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  4939. msleep(2000);
  4940. ixgbe_up(adapter);
  4941. clear_bit(__IXGBE_RESETTING, &adapter->state);
  4942. }
  4943. void ixgbe_up(struct ixgbe_adapter *adapter)
  4944. {
  4945. /* hardware has been reset, we need to reload some things */
  4946. ixgbe_configure(adapter);
  4947. ixgbe_up_complete(adapter);
  4948. }
  4949. static unsigned long ixgbe_get_completion_timeout(struct ixgbe_adapter *adapter)
  4950. {
  4951. u16 devctl2;
  4952. pcie_capability_read_word(adapter->pdev, PCI_EXP_DEVCTL2, &devctl2);
  4953. switch (devctl2 & IXGBE_PCIDEVCTRL2_TIMEO_MASK) {
  4954. case IXGBE_PCIDEVCTRL2_17_34s:
  4955. case IXGBE_PCIDEVCTRL2_4_8s:
  4956. /* For now we cap the upper limit on delay to 2 seconds
  4957. * as we end up going up to 34 seconds of delay in worst
  4958. * case timeout value.
  4959. */
  4960. case IXGBE_PCIDEVCTRL2_1_2s:
  4961. return 2000000ul; /* 2.0 s */
  4962. case IXGBE_PCIDEVCTRL2_260_520ms:
  4963. return 520000ul; /* 520 ms */
  4964. case IXGBE_PCIDEVCTRL2_65_130ms:
  4965. return 130000ul; /* 130 ms */
  4966. case IXGBE_PCIDEVCTRL2_16_32ms:
  4967. return 32000ul; /* 32 ms */
  4968. case IXGBE_PCIDEVCTRL2_1_2ms:
  4969. return 2000ul; /* 2 ms */
  4970. case IXGBE_PCIDEVCTRL2_50_100us:
  4971. return 100ul; /* 100 us */
  4972. case IXGBE_PCIDEVCTRL2_16_32ms_def:
  4973. return 32000ul; /* 32 ms */
  4974. default:
  4975. break;
  4976. }
  4977. /* We shouldn't need to hit this path, but just in case default as
  4978. * though completion timeout is not supported and support 32ms.
  4979. */
  4980. return 32000ul;
  4981. }
  4982. void ixgbe_disable_rx(struct ixgbe_adapter *adapter)
  4983. {
  4984. unsigned long wait_delay, delay_interval;
  4985. struct ixgbe_hw *hw = &adapter->hw;
  4986. int i, wait_loop;
  4987. u32 rxdctl;
  4988. /* disable receives */
  4989. hw->mac.ops.disable_rx(hw);
  4990. if (ixgbe_removed(hw->hw_addr))
  4991. return;
  4992. /* disable all enabled Rx queues */
  4993. for (i = 0; i < adapter->num_rx_queues; i++) {
  4994. struct ixgbe_ring *ring = adapter->rx_ring[i];
  4995. u8 reg_idx = ring->reg_idx;
  4996. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  4997. rxdctl &= ~IXGBE_RXDCTL_ENABLE;
  4998. rxdctl |= IXGBE_RXDCTL_SWFLSH;
  4999. /* write value back with RXDCTL.ENABLE bit cleared */
  5000. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  5001. }
  5002. /* RXDCTL.EN may not change on 82598 if link is down, so skip it */
  5003. if (hw->mac.type == ixgbe_mac_82598EB &&
  5004. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  5005. return;
  5006. /* Determine our minimum delay interval. We will increase this value
  5007. * with each subsequent test. This way if the device returns quickly
  5008. * we should spend as little time as possible waiting, however as
  5009. * the time increases we will wait for larger periods of time.
  5010. *
  5011. * The trick here is that we increase the interval using the
  5012. * following pattern: 1x 3x 5x 7x 9x 11x 13x 15x 17x 19x. The result
  5013. * of that wait is that it totals up to 100x whatever interval we
  5014. * choose. Since our minimum wait is 100us we can just divide the
  5015. * total timeout by 100 to get our minimum delay interval.
  5016. */
  5017. delay_interval = ixgbe_get_completion_timeout(adapter) / 100;
  5018. wait_loop = IXGBE_MAX_RX_DESC_POLL;
  5019. wait_delay = delay_interval;
  5020. while (wait_loop--) {
  5021. usleep_range(wait_delay, wait_delay + 10);
  5022. wait_delay += delay_interval * 2;
  5023. rxdctl = 0;
  5024. /* OR together the reading of all the active RXDCTL registers,
  5025. * and then test the result. We need the disable to complete
  5026. * before we start freeing the memory and invalidating the
  5027. * DMA mappings.
  5028. */
  5029. for (i = 0; i < adapter->num_rx_queues; i++) {
  5030. struct ixgbe_ring *ring = adapter->rx_ring[i];
  5031. u8 reg_idx = ring->reg_idx;
  5032. rxdctl |= IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  5033. }
  5034. if (!(rxdctl & IXGBE_RXDCTL_ENABLE))
  5035. return;
  5036. }
  5037. e_err(drv,
  5038. "RXDCTL.ENABLE for one or more queues not cleared within the polling period\n");
  5039. }
  5040. void ixgbe_disable_tx(struct ixgbe_adapter *adapter)
  5041. {
  5042. unsigned long wait_delay, delay_interval;
  5043. struct ixgbe_hw *hw = &adapter->hw;
  5044. int i, wait_loop;
  5045. u32 txdctl;
  5046. if (ixgbe_removed(hw->hw_addr))
  5047. return;
  5048. /* disable all enabled Tx queues */
  5049. for (i = 0; i < adapter->num_tx_queues; i++) {
  5050. struct ixgbe_ring *ring = adapter->tx_ring[i];
  5051. u8 reg_idx = ring->reg_idx;
  5052. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
  5053. }
  5054. /* disable all enabled XDP Tx queues */
  5055. for (i = 0; i < adapter->num_xdp_queues; i++) {
  5056. struct ixgbe_ring *ring = adapter->xdp_ring[i];
  5057. u8 reg_idx = ring->reg_idx;
  5058. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
  5059. }
  5060. /* If the link is not up there shouldn't be much in the way of
  5061. * pending transactions. Those that are left will be flushed out
  5062. * when the reset logic goes through the flush sequence to clean out
  5063. * the pending Tx transactions.
  5064. */
  5065. if (!(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  5066. goto dma_engine_disable;
  5067. /* Determine our minimum delay interval. We will increase this value
  5068. * with each subsequent test. This way if the device returns quickly
  5069. * we should spend as little time as possible waiting, however as
  5070. * the time increases we will wait for larger periods of time.
  5071. *
  5072. * The trick here is that we increase the interval using the
  5073. * following pattern: 1x 3x 5x 7x 9x 11x 13x 15x 17x 19x. The result
  5074. * of that wait is that it totals up to 100x whatever interval we
  5075. * choose. Since our minimum wait is 100us we can just divide the
  5076. * total timeout by 100 to get our minimum delay interval.
  5077. */
  5078. delay_interval = ixgbe_get_completion_timeout(adapter) / 100;
  5079. wait_loop = IXGBE_MAX_RX_DESC_POLL;
  5080. wait_delay = delay_interval;
  5081. while (wait_loop--) {
  5082. usleep_range(wait_delay, wait_delay + 10);
  5083. wait_delay += delay_interval * 2;
  5084. txdctl = 0;
  5085. /* OR together the reading of all the active TXDCTL registers,
  5086. * and then test the result. We need the disable to complete
  5087. * before we start freeing the memory and invalidating the
  5088. * DMA mappings.
  5089. */
  5090. for (i = 0; i < adapter->num_tx_queues; i++) {
  5091. struct ixgbe_ring *ring = adapter->tx_ring[i];
  5092. u8 reg_idx = ring->reg_idx;
  5093. txdctl |= IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
  5094. }
  5095. for (i = 0; i < adapter->num_xdp_queues; i++) {
  5096. struct ixgbe_ring *ring = adapter->xdp_ring[i];
  5097. u8 reg_idx = ring->reg_idx;
  5098. txdctl |= IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
  5099. }
  5100. if (!(txdctl & IXGBE_TXDCTL_ENABLE))
  5101. goto dma_engine_disable;
  5102. }
  5103. e_err(drv,
  5104. "TXDCTL.ENABLE for one or more queues not cleared within the polling period\n");
  5105. dma_engine_disable:
  5106. /* Disable the Tx DMA engine on 82599 and later MAC */
  5107. switch (hw->mac.type) {
  5108. case ixgbe_mac_82599EB:
  5109. case ixgbe_mac_X540:
  5110. case ixgbe_mac_X550:
  5111. case ixgbe_mac_X550EM_x:
  5112. case ixgbe_mac_x550em_a:
  5113. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
  5114. (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
  5115. ~IXGBE_DMATXCTL_TE));
  5116. fallthrough;
  5117. default:
  5118. break;
  5119. }
  5120. }
  5121. void ixgbe_reset(struct ixgbe_adapter *adapter)
  5122. {
  5123. struct ixgbe_hw *hw = &adapter->hw;
  5124. struct net_device *netdev = adapter->netdev;
  5125. int err;
  5126. if (ixgbe_removed(hw->hw_addr))
  5127. return;
  5128. /* lock SFP init bit to prevent race conditions with the watchdog */
  5129. while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  5130. usleep_range(1000, 2000);
  5131. /* clear all SFP and link config related flags while holding SFP_INIT */
  5132. adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
  5133. IXGBE_FLAG2_SFP_NEEDS_RESET);
  5134. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
  5135. err = hw->mac.ops.init_hw(hw);
  5136. switch (err) {
  5137. case 0:
  5138. case -ENOENT:
  5139. case -EOPNOTSUPP:
  5140. break;
  5141. case -EALREADY:
  5142. e_dev_err("primary disable timed out\n");
  5143. break;
  5144. case -EACCES:
  5145. /* We are running on a pre-production device, log a warning */
  5146. e_dev_warn("This device is a pre-production adapter/LOM. "
  5147. "Please be aware there may be issues associated with "
  5148. "your hardware. If you are experiencing problems "
  5149. "please contact your Intel or hardware "
  5150. "representative who provided you with this "
  5151. "hardware.\n");
  5152. break;
  5153. default:
  5154. e_dev_err("Hardware Error: %d\n", err);
  5155. }
  5156. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  5157. /* flush entries out of MAC table */
  5158. ixgbe_flush_sw_mac_table(adapter);
  5159. __dev_uc_unsync(netdev, NULL);
  5160. /* do not flush user set addresses */
  5161. ixgbe_mac_set_default_filter(adapter);
  5162. /* update SAN MAC vmdq pool selection */
  5163. if (hw->mac.san_mac_rar_index)
  5164. hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
  5165. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  5166. ixgbe_ptp_reset(adapter);
  5167. if (hw->phy.ops.set_phy_power) {
  5168. if (!netif_running(adapter->netdev) && !adapter->wol)
  5169. hw->phy.ops.set_phy_power(hw, false);
  5170. else
  5171. hw->phy.ops.set_phy_power(hw, true);
  5172. }
  5173. }
  5174. /**
  5175. * ixgbe_clean_tx_ring - Free Tx Buffers
  5176. * @tx_ring: ring to be cleaned
  5177. **/
  5178. static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
  5179. {
  5180. u16 i = tx_ring->next_to_clean;
  5181. struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
  5182. if (tx_ring->xsk_pool) {
  5183. ixgbe_xsk_clean_tx_ring(tx_ring);
  5184. goto out;
  5185. }
  5186. while (i != tx_ring->next_to_use) {
  5187. union ixgbe_adv_tx_desc *eop_desc, *tx_desc;
  5188. /* Free all the Tx ring sk_buffs */
  5189. if (ring_is_xdp(tx_ring))
  5190. xdp_return_frame(tx_buffer->xdpf);
  5191. else
  5192. dev_kfree_skb_any(tx_buffer->skb);
  5193. /* unmap skb header data */
  5194. dma_unmap_single(tx_ring->dev,
  5195. dma_unmap_addr(tx_buffer, dma),
  5196. dma_unmap_len(tx_buffer, len),
  5197. DMA_TO_DEVICE);
  5198. /* check for eop_desc to determine the end of the packet */
  5199. eop_desc = tx_buffer->next_to_watch;
  5200. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  5201. /* unmap remaining buffers */
  5202. while (tx_desc != eop_desc) {
  5203. tx_buffer++;
  5204. tx_desc++;
  5205. i++;
  5206. if (unlikely(i == tx_ring->count)) {
  5207. i = 0;
  5208. tx_buffer = tx_ring->tx_buffer_info;
  5209. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  5210. }
  5211. /* unmap any remaining paged data */
  5212. if (dma_unmap_len(tx_buffer, len))
  5213. dma_unmap_page(tx_ring->dev,
  5214. dma_unmap_addr(tx_buffer, dma),
  5215. dma_unmap_len(tx_buffer, len),
  5216. DMA_TO_DEVICE);
  5217. }
  5218. /* move us one more past the eop_desc for start of next pkt */
  5219. tx_buffer++;
  5220. i++;
  5221. if (unlikely(i == tx_ring->count)) {
  5222. i = 0;
  5223. tx_buffer = tx_ring->tx_buffer_info;
  5224. }
  5225. }
  5226. /* reset BQL for queue */
  5227. if (!ring_is_xdp(tx_ring))
  5228. netdev_tx_reset_queue(txring_txq(tx_ring));
  5229. out:
  5230. /* reset next_to_use and next_to_clean */
  5231. tx_ring->next_to_use = 0;
  5232. tx_ring->next_to_clean = 0;
  5233. }
  5234. /**
  5235. * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
  5236. * @adapter: board private structure
  5237. **/
  5238. static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
  5239. {
  5240. int i;
  5241. for (i = 0; i < adapter->num_rx_queues; i++)
  5242. ixgbe_clean_rx_ring(adapter->rx_ring[i]);
  5243. }
  5244. /**
  5245. * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
  5246. * @adapter: board private structure
  5247. **/
  5248. static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
  5249. {
  5250. int i;
  5251. for (i = 0; i < adapter->num_tx_queues; i++)
  5252. ixgbe_clean_tx_ring(adapter->tx_ring[i]);
  5253. for (i = 0; i < adapter->num_xdp_queues; i++)
  5254. ixgbe_clean_tx_ring(adapter->xdp_ring[i]);
  5255. }
  5256. static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
  5257. {
  5258. struct hlist_node *node2;
  5259. struct ixgbe_fdir_filter *filter;
  5260. spin_lock(&adapter->fdir_perfect_lock);
  5261. hlist_for_each_entry_safe(filter, node2,
  5262. &adapter->fdir_filter_list, fdir_node) {
  5263. hlist_del(&filter->fdir_node);
  5264. kfree(filter);
  5265. }
  5266. adapter->fdir_filter_count = 0;
  5267. spin_unlock(&adapter->fdir_perfect_lock);
  5268. }
  5269. void ixgbe_down(struct ixgbe_adapter *adapter)
  5270. {
  5271. struct net_device *netdev = adapter->netdev;
  5272. struct ixgbe_hw *hw = &adapter->hw;
  5273. int i;
  5274. /* signal that we are down to the interrupt handler */
  5275. if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
  5276. return; /* do nothing if already down */
  5277. /* Shut off incoming Tx traffic */
  5278. netif_tx_stop_all_queues(netdev);
  5279. /* call carrier off first to avoid false dev_watchdog timeouts */
  5280. netif_carrier_off(netdev);
  5281. netif_tx_disable(netdev);
  5282. /* Disable Rx */
  5283. ixgbe_disable_rx(adapter);
  5284. /* synchronize_rcu() needed for pending XDP buffers to drain */
  5285. if (adapter->xdp_ring[0])
  5286. synchronize_rcu();
  5287. ixgbe_irq_disable(adapter);
  5288. ixgbe_napi_disable_all(adapter);
  5289. clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  5290. adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  5291. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  5292. del_timer_sync(&adapter->service_timer);
  5293. if (adapter->num_vfs) {
  5294. /* Clear EITR Select mapping */
  5295. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
  5296. /* Mark all the VFs as inactive */
  5297. for (i = 0 ; i < adapter->num_vfs; i++)
  5298. adapter->vfinfo[i].clear_to_send = false;
  5299. /* update setting rx tx for all active vfs */
  5300. ixgbe_set_all_vfs(adapter);
  5301. }
  5302. /* disable transmits in the hardware now that interrupts are off */
  5303. ixgbe_disable_tx(adapter);
  5304. if (!pci_channel_offline(adapter->pdev))
  5305. ixgbe_reset(adapter);
  5306. /* power down the optics for 82599 SFP+ fiber */
  5307. if (hw->mac.ops.disable_tx_laser)
  5308. hw->mac.ops.disable_tx_laser(hw);
  5309. ixgbe_clean_all_tx_rings(adapter);
  5310. ixgbe_clean_all_rx_rings(adapter);
  5311. }
  5312. /**
  5313. * ixgbe_set_eee_capable - helper function to determine EEE support on X550
  5314. * @adapter: board private structure
  5315. */
  5316. static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter)
  5317. {
  5318. struct ixgbe_hw *hw = &adapter->hw;
  5319. switch (hw->device_id) {
  5320. case IXGBE_DEV_ID_X550EM_A_1G_T:
  5321. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  5322. if (!hw->phy.eee_speeds_supported)
  5323. break;
  5324. adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE;
  5325. if (!hw->phy.eee_speeds_advertised)
  5326. break;
  5327. adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
  5328. break;
  5329. default:
  5330. adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE;
  5331. adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
  5332. break;
  5333. }
  5334. }
  5335. /**
  5336. * ixgbe_tx_timeout - Respond to a Tx Hang
  5337. * @netdev: network interface device structure
  5338. * @txqueue: queue number that timed out
  5339. **/
  5340. static void ixgbe_tx_timeout(struct net_device *netdev, unsigned int __always_unused txqueue)
  5341. {
  5342. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5343. /* Do the reset outside of interrupt context */
  5344. ixgbe_tx_timeout_reset(adapter);
  5345. }
  5346. #ifdef CONFIG_IXGBE_DCB
  5347. static void ixgbe_init_dcb(struct ixgbe_adapter *adapter)
  5348. {
  5349. struct ixgbe_hw *hw = &adapter->hw;
  5350. struct tc_configuration *tc;
  5351. int j;
  5352. switch (hw->mac.type) {
  5353. case ixgbe_mac_82598EB:
  5354. case ixgbe_mac_82599EB:
  5355. adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
  5356. adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
  5357. break;
  5358. case ixgbe_mac_X540:
  5359. case ixgbe_mac_X550:
  5360. adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
  5361. adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
  5362. break;
  5363. case ixgbe_mac_X550EM_x:
  5364. case ixgbe_mac_x550em_a:
  5365. default:
  5366. adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS;
  5367. adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS;
  5368. break;
  5369. }
  5370. /* Configure DCB traffic classes */
  5371. for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
  5372. tc = &adapter->dcb_cfg.tc_config[j];
  5373. tc->path[DCB_TX_CONFIG].bwg_id = 0;
  5374. tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
  5375. tc->path[DCB_RX_CONFIG].bwg_id = 0;
  5376. tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
  5377. tc->dcb_pfc = pfc_disabled;
  5378. }
  5379. /* Initialize default user to priority mapping, UPx->TC0 */
  5380. tc = &adapter->dcb_cfg.tc_config[0];
  5381. tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
  5382. tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
  5383. adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
  5384. adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
  5385. adapter->dcb_cfg.pfc_mode_enable = false;
  5386. adapter->dcb_set_bitmap = 0x00;
  5387. if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
  5388. adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
  5389. memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
  5390. sizeof(adapter->temp_dcb_cfg));
  5391. }
  5392. #endif
  5393. /**
  5394. * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
  5395. * @adapter: board private structure to initialize
  5396. * @ii: pointer to ixgbe_info for device
  5397. *
  5398. * ixgbe_sw_init initializes the Adapter private data structure.
  5399. * Fields are initialized based on PCI device information and
  5400. * OS network device settings (MTU size).
  5401. **/
  5402. static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
  5403. const struct ixgbe_info *ii)
  5404. {
  5405. struct ixgbe_hw *hw = &adapter->hw;
  5406. struct pci_dev *pdev = adapter->pdev;
  5407. unsigned int rss, fdir;
  5408. u32 fwsm;
  5409. int i;
  5410. /* PCI config space info */
  5411. hw->vendor_id = pdev->vendor;
  5412. hw->device_id = pdev->device;
  5413. hw->revision_id = pdev->revision;
  5414. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  5415. hw->subsystem_device_id = pdev->subsystem_device;
  5416. /* get_invariants needs the device IDs */
  5417. ii->get_invariants(hw);
  5418. /* Set common capability flags and settings */
  5419. rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
  5420. adapter->ring_feature[RING_F_RSS].limit = rss;
  5421. adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
  5422. adapter->max_q_vectors = MAX_Q_VECTORS_82599;
  5423. adapter->atr_sample_rate = 20;
  5424. fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
  5425. adapter->ring_feature[RING_F_FDIR].limit = fdir;
  5426. adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
  5427. adapter->ring_feature[RING_F_VMDQ].limit = 1;
  5428. #ifdef CONFIG_IXGBE_DCA
  5429. adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
  5430. #endif
  5431. #ifdef CONFIG_IXGBE_DCB
  5432. adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
  5433. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  5434. #endif
  5435. #ifdef IXGBE_FCOE
  5436. adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
  5437. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  5438. #ifdef CONFIG_IXGBE_DCB
  5439. /* Default traffic class to use for FCoE */
  5440. adapter->fcoe.up = IXGBE_FCOE_DEFTC;
  5441. #endif /* CONFIG_IXGBE_DCB */
  5442. #endif /* IXGBE_FCOE */
  5443. /* initialize static ixgbe jump table entries */
  5444. adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]),
  5445. GFP_KERNEL);
  5446. if (!adapter->jump_tables[0])
  5447. return -ENOMEM;
  5448. adapter->jump_tables[0]->mat = ixgbe_ipv4_fields;
  5449. for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++)
  5450. adapter->jump_tables[i] = NULL;
  5451. adapter->mac_table = kcalloc(hw->mac.num_rar_entries,
  5452. sizeof(struct ixgbe_mac_addr),
  5453. GFP_KERNEL);
  5454. if (!adapter->mac_table)
  5455. return -ENOMEM;
  5456. if (ixgbe_init_rss_key(adapter))
  5457. return -ENOMEM;
  5458. adapter->af_xdp_zc_qps = bitmap_zalloc(IXGBE_MAX_XDP_QS, GFP_KERNEL);
  5459. if (!adapter->af_xdp_zc_qps)
  5460. return -ENOMEM;
  5461. /* Set MAC specific capability flags and exceptions */
  5462. switch (hw->mac.type) {
  5463. case ixgbe_mac_82598EB:
  5464. adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
  5465. if (hw->device_id == IXGBE_DEV_ID_82598AT)
  5466. adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
  5467. adapter->max_q_vectors = MAX_Q_VECTORS_82598;
  5468. adapter->ring_feature[RING_F_FDIR].limit = 0;
  5469. adapter->atr_sample_rate = 0;
  5470. adapter->fdir_pballoc = 0;
  5471. #ifdef IXGBE_FCOE
  5472. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  5473. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  5474. #ifdef CONFIG_IXGBE_DCB
  5475. adapter->fcoe.up = 0;
  5476. #endif /* IXGBE_DCB */
  5477. #endif /* IXGBE_FCOE */
  5478. break;
  5479. case ixgbe_mac_82599EB:
  5480. if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
  5481. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5482. break;
  5483. case ixgbe_mac_X540:
  5484. fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
  5485. if (fwsm & IXGBE_FWSM_TS_ENABLED)
  5486. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5487. break;
  5488. case ixgbe_mac_x550em_a:
  5489. switch (hw->device_id) {
  5490. case IXGBE_DEV_ID_X550EM_A_1G_T:
  5491. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  5492. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5493. break;
  5494. default:
  5495. break;
  5496. }
  5497. fallthrough;
  5498. case ixgbe_mac_X550EM_x:
  5499. #ifdef CONFIG_IXGBE_DCB
  5500. adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE;
  5501. #endif
  5502. #ifdef IXGBE_FCOE
  5503. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  5504. #ifdef CONFIG_IXGBE_DCB
  5505. adapter->fcoe.up = 0;
  5506. #endif /* IXGBE_DCB */
  5507. #endif /* IXGBE_FCOE */
  5508. fallthrough;
  5509. case ixgbe_mac_X550:
  5510. if (hw->mac.type == ixgbe_mac_X550)
  5511. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5512. #ifdef CONFIG_IXGBE_DCA
  5513. adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
  5514. #endif
  5515. break;
  5516. default:
  5517. break;
  5518. }
  5519. #ifdef IXGBE_FCOE
  5520. /* FCoE support exists, always init the FCoE lock */
  5521. spin_lock_init(&adapter->fcoe.lock);
  5522. #endif
  5523. /* n-tuple support exists, always init our spinlock */
  5524. spin_lock_init(&adapter->fdir_perfect_lock);
  5525. /* init spinlock to avoid concurrency of VF resources */
  5526. spin_lock_init(&adapter->vfs_lock);
  5527. #ifdef CONFIG_IXGBE_DCB
  5528. ixgbe_init_dcb(adapter);
  5529. #endif
  5530. ixgbe_init_ipsec_offload(adapter);
  5531. /* default flow control settings */
  5532. hw->fc.requested_mode = ixgbe_fc_full;
  5533. hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
  5534. ixgbe_pbthresh_setup(adapter);
  5535. hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
  5536. hw->fc.send_xon = true;
  5537. hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
  5538. #ifdef CONFIG_PCI_IOV
  5539. if (max_vfs > 0)
  5540. e_dev_warn("Enabling SR-IOV VFs using the max_vfs module parameter is deprecated - please use the pci sysfs interface instead.\n");
  5541. /* assign number of SR-IOV VFs */
  5542. if (hw->mac.type != ixgbe_mac_82598EB) {
  5543. if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
  5544. max_vfs = 0;
  5545. e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
  5546. }
  5547. }
  5548. #endif /* CONFIG_PCI_IOV */
  5549. /* enable itr by default in dynamic mode */
  5550. adapter->rx_itr_setting = 1;
  5551. adapter->tx_itr_setting = 1;
  5552. /* set default ring sizes */
  5553. adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
  5554. adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
  5555. /* set default work limits */
  5556. adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
  5557. /* initialize eeprom parameters */
  5558. if (ixgbe_init_eeprom_params_generic(hw)) {
  5559. e_dev_err("EEPROM initialization failed\n");
  5560. return -EIO;
  5561. }
  5562. /* PF holds first pool slot */
  5563. set_bit(0, adapter->fwd_bitmask);
  5564. set_bit(__IXGBE_DOWN, &adapter->state);
  5565. /* enable locking for XDP_TX if we have more CPUs than queues */
  5566. if (nr_cpu_ids > IXGBE_MAX_XDP_QS)
  5567. static_branch_enable(&ixgbe_xdp_locking_key);
  5568. return 0;
  5569. }
  5570. /**
  5571. * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
  5572. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  5573. *
  5574. * Return 0 on success, negative on failure
  5575. **/
  5576. int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
  5577. {
  5578. struct device *dev = tx_ring->dev;
  5579. int orig_node = dev_to_node(dev);
  5580. int ring_node = NUMA_NO_NODE;
  5581. int size;
  5582. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  5583. if (tx_ring->q_vector)
  5584. ring_node = tx_ring->q_vector->numa_node;
  5585. tx_ring->tx_buffer_info = vmalloc_node(size, ring_node);
  5586. if (!tx_ring->tx_buffer_info)
  5587. tx_ring->tx_buffer_info = vmalloc(size);
  5588. if (!tx_ring->tx_buffer_info)
  5589. goto err;
  5590. /* round up to nearest 4K */
  5591. tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
  5592. tx_ring->size = ALIGN(tx_ring->size, 4096);
  5593. set_dev_node(dev, ring_node);
  5594. tx_ring->desc = dma_alloc_coherent(dev,
  5595. tx_ring->size,
  5596. &tx_ring->dma,
  5597. GFP_KERNEL);
  5598. set_dev_node(dev, orig_node);
  5599. if (!tx_ring->desc)
  5600. tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
  5601. &tx_ring->dma, GFP_KERNEL);
  5602. if (!tx_ring->desc)
  5603. goto err;
  5604. tx_ring->next_to_use = 0;
  5605. tx_ring->next_to_clean = 0;
  5606. return 0;
  5607. err:
  5608. vfree(tx_ring->tx_buffer_info);
  5609. tx_ring->tx_buffer_info = NULL;
  5610. dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
  5611. return -ENOMEM;
  5612. }
  5613. /**
  5614. * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
  5615. * @adapter: board private structure
  5616. *
  5617. * If this function returns with an error, then it's possible one or
  5618. * more of the rings is populated (while the rest are not). It is the
  5619. * callers duty to clean those orphaned rings.
  5620. *
  5621. * Return 0 on success, negative on failure
  5622. **/
  5623. static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
  5624. {
  5625. int i, j = 0, err = 0;
  5626. for (i = 0; i < adapter->num_tx_queues; i++) {
  5627. err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
  5628. if (!err)
  5629. continue;
  5630. e_err(probe, "Allocation for Tx Queue %u failed\n", i);
  5631. goto err_setup_tx;
  5632. }
  5633. for (j = 0; j < adapter->num_xdp_queues; j++) {
  5634. err = ixgbe_setup_tx_resources(adapter->xdp_ring[j]);
  5635. if (!err)
  5636. continue;
  5637. e_err(probe, "Allocation for Tx Queue %u failed\n", j);
  5638. goto err_setup_tx;
  5639. }
  5640. return 0;
  5641. err_setup_tx:
  5642. /* rewind the index freeing the rings as we go */
  5643. while (j--)
  5644. ixgbe_free_tx_resources(adapter->xdp_ring[j]);
  5645. while (i--)
  5646. ixgbe_free_tx_resources(adapter->tx_ring[i]);
  5647. return err;
  5648. }
  5649. static int ixgbe_rx_napi_id(struct ixgbe_ring *rx_ring)
  5650. {
  5651. struct ixgbe_q_vector *q_vector = rx_ring->q_vector;
  5652. return q_vector ? q_vector->napi.napi_id : 0;
  5653. }
  5654. /**
  5655. * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
  5656. * @adapter: pointer to ixgbe_adapter
  5657. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  5658. *
  5659. * Returns 0 on success, negative on failure
  5660. **/
  5661. int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
  5662. struct ixgbe_ring *rx_ring)
  5663. {
  5664. struct device *dev = rx_ring->dev;
  5665. int orig_node = dev_to_node(dev);
  5666. int ring_node = NUMA_NO_NODE;
  5667. int size;
  5668. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  5669. if (rx_ring->q_vector)
  5670. ring_node = rx_ring->q_vector->numa_node;
  5671. rx_ring->rx_buffer_info = vmalloc_node(size, ring_node);
  5672. if (!rx_ring->rx_buffer_info)
  5673. rx_ring->rx_buffer_info = vmalloc(size);
  5674. if (!rx_ring->rx_buffer_info)
  5675. goto err;
  5676. /* Round up to nearest 4K */
  5677. rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
  5678. rx_ring->size = ALIGN(rx_ring->size, 4096);
  5679. set_dev_node(dev, ring_node);
  5680. rx_ring->desc = dma_alloc_coherent(dev,
  5681. rx_ring->size,
  5682. &rx_ring->dma,
  5683. GFP_KERNEL);
  5684. set_dev_node(dev, orig_node);
  5685. if (!rx_ring->desc)
  5686. rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
  5687. &rx_ring->dma, GFP_KERNEL);
  5688. if (!rx_ring->desc)
  5689. goto err;
  5690. rx_ring->next_to_clean = 0;
  5691. rx_ring->next_to_use = 0;
  5692. /* XDP RX-queue info */
  5693. if (xdp_rxq_info_reg(&rx_ring->xdp_rxq, adapter->netdev,
  5694. rx_ring->queue_index, ixgbe_rx_napi_id(rx_ring)) < 0)
  5695. goto err;
  5696. WRITE_ONCE(rx_ring->xdp_prog, adapter->xdp_prog);
  5697. return 0;
  5698. err:
  5699. vfree(rx_ring->rx_buffer_info);
  5700. rx_ring->rx_buffer_info = NULL;
  5701. dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
  5702. return -ENOMEM;
  5703. }
  5704. /**
  5705. * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
  5706. * @adapter: board private structure
  5707. *
  5708. * If this function returns with an error, then it's possible one or
  5709. * more of the rings is populated (while the rest are not). It is the
  5710. * callers duty to clean those orphaned rings.
  5711. *
  5712. * Return 0 on success, negative on failure
  5713. **/
  5714. static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
  5715. {
  5716. int i, err = 0;
  5717. for (i = 0; i < adapter->num_rx_queues; i++) {
  5718. err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]);
  5719. if (!err)
  5720. continue;
  5721. e_err(probe, "Allocation for Rx Queue %u failed\n", i);
  5722. goto err_setup_rx;
  5723. }
  5724. #ifdef IXGBE_FCOE
  5725. err = ixgbe_setup_fcoe_ddp_resources(adapter);
  5726. if (!err)
  5727. #endif
  5728. return 0;
  5729. err_setup_rx:
  5730. /* rewind the index freeing the rings as we go */
  5731. while (i--)
  5732. ixgbe_free_rx_resources(adapter->rx_ring[i]);
  5733. return err;
  5734. }
  5735. /**
  5736. * ixgbe_free_tx_resources - Free Tx Resources per Queue
  5737. * @tx_ring: Tx descriptor ring for a specific queue
  5738. *
  5739. * Free all transmit software resources
  5740. **/
  5741. void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
  5742. {
  5743. ixgbe_clean_tx_ring(tx_ring);
  5744. vfree(tx_ring->tx_buffer_info);
  5745. tx_ring->tx_buffer_info = NULL;
  5746. /* if not set, then don't free */
  5747. if (!tx_ring->desc)
  5748. return;
  5749. dma_free_coherent(tx_ring->dev, tx_ring->size,
  5750. tx_ring->desc, tx_ring->dma);
  5751. tx_ring->desc = NULL;
  5752. }
  5753. /**
  5754. * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
  5755. * @adapter: board private structure
  5756. *
  5757. * Free all transmit software resources
  5758. **/
  5759. static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
  5760. {
  5761. int i;
  5762. for (i = 0; i < adapter->num_tx_queues; i++)
  5763. if (adapter->tx_ring[i]->desc)
  5764. ixgbe_free_tx_resources(adapter->tx_ring[i]);
  5765. for (i = 0; i < adapter->num_xdp_queues; i++)
  5766. if (adapter->xdp_ring[i]->desc)
  5767. ixgbe_free_tx_resources(adapter->xdp_ring[i]);
  5768. }
  5769. /**
  5770. * ixgbe_free_rx_resources - Free Rx Resources
  5771. * @rx_ring: ring to clean the resources from
  5772. *
  5773. * Free all receive software resources
  5774. **/
  5775. void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
  5776. {
  5777. ixgbe_clean_rx_ring(rx_ring);
  5778. rx_ring->xdp_prog = NULL;
  5779. xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
  5780. vfree(rx_ring->rx_buffer_info);
  5781. rx_ring->rx_buffer_info = NULL;
  5782. /* if not set, then don't free */
  5783. if (!rx_ring->desc)
  5784. return;
  5785. dma_free_coherent(rx_ring->dev, rx_ring->size,
  5786. rx_ring->desc, rx_ring->dma);
  5787. rx_ring->desc = NULL;
  5788. }
  5789. /**
  5790. * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
  5791. * @adapter: board private structure
  5792. *
  5793. * Free all receive software resources
  5794. **/
  5795. static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
  5796. {
  5797. int i;
  5798. #ifdef IXGBE_FCOE
  5799. ixgbe_free_fcoe_ddp_resources(adapter);
  5800. #endif
  5801. for (i = 0; i < adapter->num_rx_queues; i++)
  5802. if (adapter->rx_ring[i]->desc)
  5803. ixgbe_free_rx_resources(adapter->rx_ring[i]);
  5804. }
  5805. /**
  5806. * ixgbe_max_xdp_frame_size - returns the maximum allowed frame size for XDP
  5807. * @adapter: device handle, pointer to adapter
  5808. */
  5809. static int ixgbe_max_xdp_frame_size(struct ixgbe_adapter *adapter)
  5810. {
  5811. if (PAGE_SIZE >= 8192 || adapter->flags2 & IXGBE_FLAG2_RX_LEGACY)
  5812. return IXGBE_RXBUFFER_2K;
  5813. else
  5814. return IXGBE_RXBUFFER_3K;
  5815. }
  5816. /**
  5817. * ixgbe_change_mtu - Change the Maximum Transfer Unit
  5818. * @netdev: network interface device structure
  5819. * @new_mtu: new value for maximum frame size
  5820. *
  5821. * Returns 0 on success, negative on failure
  5822. **/
  5823. static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
  5824. {
  5825. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5826. if (ixgbe_enabled_xdp_adapter(adapter)) {
  5827. int new_frame_size = new_mtu + IXGBE_PKT_HDR_PAD;
  5828. if (new_frame_size > ixgbe_max_xdp_frame_size(adapter)) {
  5829. e_warn(probe, "Requested MTU size is not supported with XDP\n");
  5830. return -EINVAL;
  5831. }
  5832. }
  5833. /*
  5834. * For 82599EB we cannot allow legacy VFs to enable their receive
  5835. * paths when MTU greater than 1500 is configured. So display a
  5836. * warning that legacy VFs will be disabled.
  5837. */
  5838. if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
  5839. (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
  5840. (new_mtu > ETH_DATA_LEN))
  5841. e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
  5842. netdev_dbg(netdev, "changing MTU from %d to %d\n",
  5843. netdev->mtu, new_mtu);
  5844. /* must set new MTU before calling down or up */
  5845. WRITE_ONCE(netdev->mtu, new_mtu);
  5846. if (netif_running(netdev))
  5847. ixgbe_reinit_locked(adapter);
  5848. return 0;
  5849. }
  5850. /**
  5851. * ixgbe_open - Called when a network interface is made active
  5852. * @netdev: network interface device structure
  5853. *
  5854. * Returns 0 on success, negative value on failure
  5855. *
  5856. * The open entry point is called when a network interface is made
  5857. * active by the system (IFF_UP). At this point all resources needed
  5858. * for transmit and receive operations are allocated, the interrupt
  5859. * handler is registered with the OS, the watchdog timer is started,
  5860. * and the stack is notified that the interface is ready.
  5861. **/
  5862. int ixgbe_open(struct net_device *netdev)
  5863. {
  5864. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5865. struct ixgbe_hw *hw = &adapter->hw;
  5866. int err, queues;
  5867. /* disallow open during test */
  5868. if (test_bit(__IXGBE_TESTING, &adapter->state))
  5869. return -EBUSY;
  5870. netif_carrier_off(netdev);
  5871. /* allocate transmit descriptors */
  5872. err = ixgbe_setup_all_tx_resources(adapter);
  5873. if (err)
  5874. goto err_setup_tx;
  5875. /* allocate receive descriptors */
  5876. err = ixgbe_setup_all_rx_resources(adapter);
  5877. if (err)
  5878. goto err_setup_rx;
  5879. ixgbe_configure(adapter);
  5880. err = ixgbe_request_irq(adapter);
  5881. if (err)
  5882. goto err_req_irq;
  5883. /* Notify the stack of the actual queue counts. */
  5884. queues = adapter->num_tx_queues;
  5885. err = netif_set_real_num_tx_queues(netdev, queues);
  5886. if (err)
  5887. goto err_set_queues;
  5888. queues = adapter->num_rx_queues;
  5889. err = netif_set_real_num_rx_queues(netdev, queues);
  5890. if (err)
  5891. goto err_set_queues;
  5892. ixgbe_ptp_init(adapter);
  5893. ixgbe_up_complete(adapter);
  5894. udp_tunnel_nic_reset_ntf(netdev);
  5895. return 0;
  5896. err_set_queues:
  5897. ixgbe_free_irq(adapter);
  5898. err_req_irq:
  5899. ixgbe_free_all_rx_resources(adapter);
  5900. if (hw->phy.ops.set_phy_power && !adapter->wol)
  5901. hw->phy.ops.set_phy_power(&adapter->hw, false);
  5902. err_setup_rx:
  5903. ixgbe_free_all_tx_resources(adapter);
  5904. err_setup_tx:
  5905. ixgbe_reset(adapter);
  5906. return err;
  5907. }
  5908. static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
  5909. {
  5910. ixgbe_ptp_suspend(adapter);
  5911. if (adapter->hw.phy.ops.enter_lplu) {
  5912. adapter->hw.phy.reset_disable = true;
  5913. ixgbe_down(adapter);
  5914. adapter->hw.phy.ops.enter_lplu(&adapter->hw);
  5915. adapter->hw.phy.reset_disable = false;
  5916. } else {
  5917. ixgbe_down(adapter);
  5918. }
  5919. ixgbe_free_irq(adapter);
  5920. ixgbe_free_all_tx_resources(adapter);
  5921. ixgbe_free_all_rx_resources(adapter);
  5922. }
  5923. /**
  5924. * ixgbe_close - Disables a network interface
  5925. * @netdev: network interface device structure
  5926. *
  5927. * Returns 0, this is not allowed to fail
  5928. *
  5929. * The close entry point is called when an interface is de-activated
  5930. * by the OS. The hardware is still under the drivers control, but
  5931. * needs to be disabled. A global MAC reset is issued to stop the
  5932. * hardware, and all transmit and receive resources are freed.
  5933. **/
  5934. int ixgbe_close(struct net_device *netdev)
  5935. {
  5936. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5937. ixgbe_ptp_stop(adapter);
  5938. if (netif_device_present(netdev))
  5939. ixgbe_close_suspend(adapter);
  5940. ixgbe_fdir_filter_exit(adapter);
  5941. ixgbe_release_hw_control(adapter);
  5942. return 0;
  5943. }
  5944. static int ixgbe_resume(struct device *dev_d)
  5945. {
  5946. struct pci_dev *pdev = to_pci_dev(dev_d);
  5947. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  5948. struct net_device *netdev = adapter->netdev;
  5949. u32 err;
  5950. adapter->hw.hw_addr = adapter->io_addr;
  5951. err = pci_enable_device_mem(pdev);
  5952. if (err) {
  5953. e_dev_err("Cannot enable PCI device from suspend\n");
  5954. return err;
  5955. }
  5956. smp_mb__before_atomic();
  5957. clear_bit(__IXGBE_DISABLED, &adapter->state);
  5958. pci_set_master(pdev);
  5959. device_wakeup_disable(dev_d);
  5960. ixgbe_reset(adapter);
  5961. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  5962. rtnl_lock();
  5963. err = ixgbe_init_interrupt_scheme(adapter);
  5964. if (!err && netif_running(netdev))
  5965. err = ixgbe_open(netdev);
  5966. if (!err)
  5967. netif_device_attach(netdev);
  5968. rtnl_unlock();
  5969. return err;
  5970. }
  5971. static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
  5972. {
  5973. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  5974. struct net_device *netdev = adapter->netdev;
  5975. struct ixgbe_hw *hw = &adapter->hw;
  5976. u32 ctrl;
  5977. u32 wufc = adapter->wol;
  5978. rtnl_lock();
  5979. netif_device_detach(netdev);
  5980. if (netif_running(netdev))
  5981. ixgbe_close_suspend(adapter);
  5982. ixgbe_clear_interrupt_scheme(adapter);
  5983. rtnl_unlock();
  5984. if (hw->mac.ops.stop_link_on_d3)
  5985. hw->mac.ops.stop_link_on_d3(hw);
  5986. if (wufc) {
  5987. u32 fctrl;
  5988. ixgbe_set_rx_mode(netdev);
  5989. /* enable the optics for 82599 SFP+ fiber as we can WoL */
  5990. if (hw->mac.ops.enable_tx_laser)
  5991. hw->mac.ops.enable_tx_laser(hw);
  5992. /* enable the reception of multicast packets */
  5993. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  5994. fctrl |= IXGBE_FCTRL_MPE;
  5995. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  5996. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  5997. ctrl |= IXGBE_CTRL_GIO_DIS;
  5998. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  5999. IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
  6000. } else {
  6001. IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
  6002. IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
  6003. }
  6004. switch (hw->mac.type) {
  6005. case ixgbe_mac_82598EB:
  6006. pci_wake_from_d3(pdev, false);
  6007. break;
  6008. case ixgbe_mac_82599EB:
  6009. case ixgbe_mac_X540:
  6010. case ixgbe_mac_X550:
  6011. case ixgbe_mac_X550EM_x:
  6012. case ixgbe_mac_x550em_a:
  6013. pci_wake_from_d3(pdev, !!wufc);
  6014. break;
  6015. default:
  6016. break;
  6017. }
  6018. *enable_wake = !!wufc;
  6019. if (hw->phy.ops.set_phy_power && !*enable_wake)
  6020. hw->phy.ops.set_phy_power(hw, false);
  6021. ixgbe_release_hw_control(adapter);
  6022. if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
  6023. pci_disable_device(pdev);
  6024. return 0;
  6025. }
  6026. static int ixgbe_suspend(struct device *dev_d)
  6027. {
  6028. struct pci_dev *pdev = to_pci_dev(dev_d);
  6029. int retval;
  6030. bool wake;
  6031. retval = __ixgbe_shutdown(pdev, &wake);
  6032. device_set_wakeup_enable(dev_d, wake);
  6033. return retval;
  6034. }
  6035. static void ixgbe_shutdown(struct pci_dev *pdev)
  6036. {
  6037. bool wake;
  6038. __ixgbe_shutdown(pdev, &wake);
  6039. if (system_state == SYSTEM_POWER_OFF) {
  6040. pci_wake_from_d3(pdev, wake);
  6041. pci_set_power_state(pdev, PCI_D3hot);
  6042. }
  6043. }
  6044. /**
  6045. * ixgbe_update_stats - Update the board statistics counters.
  6046. * @adapter: board private structure
  6047. **/
  6048. void ixgbe_update_stats(struct ixgbe_adapter *adapter)
  6049. {
  6050. struct net_device *netdev = adapter->netdev;
  6051. struct ixgbe_hw *hw = &adapter->hw;
  6052. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  6053. u64 total_mpc = 0;
  6054. u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
  6055. u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
  6056. u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
  6057. u64 alloc_rx_page = 0;
  6058. u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
  6059. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  6060. test_bit(__IXGBE_RESETTING, &adapter->state))
  6061. return;
  6062. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  6063. u64 rsc_count = 0;
  6064. u64 rsc_flush = 0;
  6065. for (i = 0; i < adapter->num_rx_queues; i++) {
  6066. rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
  6067. rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
  6068. }
  6069. adapter->rsc_total_count = rsc_count;
  6070. adapter->rsc_total_flush = rsc_flush;
  6071. }
  6072. for (i = 0; i < adapter->num_rx_queues; i++) {
  6073. struct ixgbe_ring *rx_ring = READ_ONCE(adapter->rx_ring[i]);
  6074. if (!rx_ring)
  6075. continue;
  6076. non_eop_descs += rx_ring->rx_stats.non_eop_descs;
  6077. alloc_rx_page += rx_ring->rx_stats.alloc_rx_page;
  6078. alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
  6079. alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
  6080. hw_csum_rx_error += rx_ring->rx_stats.csum_err;
  6081. bytes += rx_ring->stats.bytes;
  6082. packets += rx_ring->stats.packets;
  6083. }
  6084. adapter->non_eop_descs = non_eop_descs;
  6085. adapter->alloc_rx_page = alloc_rx_page;
  6086. adapter->alloc_rx_page_failed = alloc_rx_page_failed;
  6087. adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
  6088. adapter->hw_csum_rx_error = hw_csum_rx_error;
  6089. netdev->stats.rx_bytes = bytes;
  6090. netdev->stats.rx_packets = packets;
  6091. bytes = 0;
  6092. packets = 0;
  6093. /* gather some stats to the adapter struct that are per queue */
  6094. for (i = 0; i < adapter->num_tx_queues; i++) {
  6095. struct ixgbe_ring *tx_ring = READ_ONCE(adapter->tx_ring[i]);
  6096. if (!tx_ring)
  6097. continue;
  6098. restart_queue += tx_ring->tx_stats.restart_queue;
  6099. tx_busy += tx_ring->tx_stats.tx_busy;
  6100. bytes += tx_ring->stats.bytes;
  6101. packets += tx_ring->stats.packets;
  6102. }
  6103. for (i = 0; i < adapter->num_xdp_queues; i++) {
  6104. struct ixgbe_ring *xdp_ring = READ_ONCE(adapter->xdp_ring[i]);
  6105. if (!xdp_ring)
  6106. continue;
  6107. restart_queue += xdp_ring->tx_stats.restart_queue;
  6108. tx_busy += xdp_ring->tx_stats.tx_busy;
  6109. bytes += xdp_ring->stats.bytes;
  6110. packets += xdp_ring->stats.packets;
  6111. }
  6112. adapter->restart_queue = restart_queue;
  6113. adapter->tx_busy = tx_busy;
  6114. netdev->stats.tx_bytes = bytes;
  6115. netdev->stats.tx_packets = packets;
  6116. hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  6117. /* 8 register reads */
  6118. for (i = 0; i < 8; i++) {
  6119. /* for packet buffers not used, the register should read 0 */
  6120. mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
  6121. missed_rx += mpc;
  6122. hwstats->mpc[i] += mpc;
  6123. total_mpc += hwstats->mpc[i];
  6124. hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
  6125. hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
  6126. switch (hw->mac.type) {
  6127. case ixgbe_mac_82598EB:
  6128. hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  6129. hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  6130. hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  6131. hwstats->pxonrxc[i] +=
  6132. IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
  6133. break;
  6134. case ixgbe_mac_82599EB:
  6135. case ixgbe_mac_X540:
  6136. case ixgbe_mac_X550:
  6137. case ixgbe_mac_X550EM_x:
  6138. case ixgbe_mac_x550em_a:
  6139. hwstats->pxonrxc[i] +=
  6140. IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
  6141. break;
  6142. default:
  6143. break;
  6144. }
  6145. }
  6146. /*16 register reads */
  6147. for (i = 0; i < 16; i++) {
  6148. hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  6149. hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  6150. if ((hw->mac.type == ixgbe_mac_82599EB) ||
  6151. (hw->mac.type == ixgbe_mac_X540) ||
  6152. (hw->mac.type == ixgbe_mac_X550) ||
  6153. (hw->mac.type == ixgbe_mac_X550EM_x) ||
  6154. (hw->mac.type == ixgbe_mac_x550em_a)) {
  6155. hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
  6156. IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
  6157. hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
  6158. IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
  6159. }
  6160. }
  6161. hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
  6162. /* work around hardware counting issue */
  6163. hwstats->gprc -= missed_rx;
  6164. ixgbe_update_xoff_received(adapter);
  6165. /* 82598 hardware only has a 32 bit counter in the high register */
  6166. switch (hw->mac.type) {
  6167. case ixgbe_mac_82598EB:
  6168. hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  6169. hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
  6170. hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
  6171. hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
  6172. break;
  6173. case ixgbe_mac_X540:
  6174. case ixgbe_mac_X550:
  6175. case ixgbe_mac_X550EM_x:
  6176. case ixgbe_mac_x550em_a:
  6177. /* OS2BMC stats are X540 and later */
  6178. hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
  6179. hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
  6180. hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
  6181. hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
  6182. fallthrough;
  6183. case ixgbe_mac_82599EB:
  6184. for (i = 0; i < 16; i++)
  6185. adapter->hw_rx_no_dma_resources +=
  6186. IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  6187. hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
  6188. IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
  6189. hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
  6190. IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
  6191. hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
  6192. IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
  6193. hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
  6194. hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
  6195. hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
  6196. #ifdef IXGBE_FCOE
  6197. hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
  6198. hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
  6199. hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
  6200. hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
  6201. hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
  6202. hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
  6203. /* Add up per cpu counters for total ddp aloc fail */
  6204. if (adapter->fcoe.ddp_pool) {
  6205. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  6206. struct ixgbe_fcoe_ddp_pool *ddp_pool;
  6207. unsigned int cpu;
  6208. u64 noddp = 0, noddp_ext_buff = 0;
  6209. for_each_possible_cpu(cpu) {
  6210. ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
  6211. noddp += ddp_pool->noddp;
  6212. noddp_ext_buff += ddp_pool->noddp_ext_buff;
  6213. }
  6214. hwstats->fcoe_noddp = noddp;
  6215. hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
  6216. }
  6217. #endif /* IXGBE_FCOE */
  6218. break;
  6219. default:
  6220. break;
  6221. }
  6222. bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
  6223. hwstats->bprc += bprc;
  6224. hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
  6225. if (hw->mac.type == ixgbe_mac_82598EB)
  6226. hwstats->mprc -= bprc;
  6227. hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
  6228. hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
  6229. hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
  6230. hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
  6231. hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
  6232. hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
  6233. hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
  6234. hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
  6235. lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  6236. hwstats->lxontxc += lxon;
  6237. lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  6238. hwstats->lxofftxc += lxoff;
  6239. hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
  6240. hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
  6241. /*
  6242. * 82598 errata - tx of flow control packets is included in tx counters
  6243. */
  6244. xon_off_tot = lxon + lxoff;
  6245. hwstats->gptc -= xon_off_tot;
  6246. hwstats->mptc -= xon_off_tot;
  6247. hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
  6248. hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
  6249. hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
  6250. hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
  6251. hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
  6252. hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
  6253. hwstats->ptc64 -= xon_off_tot;
  6254. hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
  6255. hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
  6256. hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
  6257. hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
  6258. hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
  6259. hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
  6260. /* Fill out the OS statistics structure */
  6261. netdev->stats.multicast = hwstats->mprc;
  6262. /* Rx Errors */
  6263. netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
  6264. netdev->stats.rx_dropped = 0;
  6265. netdev->stats.rx_length_errors = hwstats->rlec;
  6266. netdev->stats.rx_crc_errors = hwstats->crcerrs;
  6267. netdev->stats.rx_missed_errors = total_mpc;
  6268. /* VF Stats Collection - skip while resetting because these
  6269. * are not clear on read and otherwise you'll sometimes get
  6270. * crazy values.
  6271. */
  6272. if (!test_bit(__IXGBE_RESETTING, &adapter->state)) {
  6273. for (i = 0; i < adapter->num_vfs; i++) {
  6274. UPDATE_VF_COUNTER_32bit(IXGBE_PVFGPRC(i),
  6275. adapter->vfinfo[i].last_vfstats.gprc,
  6276. adapter->vfinfo[i].vfstats.gprc);
  6277. UPDATE_VF_COUNTER_32bit(IXGBE_PVFGPTC(i),
  6278. adapter->vfinfo[i].last_vfstats.gptc,
  6279. adapter->vfinfo[i].vfstats.gptc);
  6280. UPDATE_VF_COUNTER_36bit(IXGBE_PVFGORC_LSB(i),
  6281. IXGBE_PVFGORC_MSB(i),
  6282. adapter->vfinfo[i].last_vfstats.gorc,
  6283. adapter->vfinfo[i].vfstats.gorc);
  6284. UPDATE_VF_COUNTER_36bit(IXGBE_PVFGOTC_LSB(i),
  6285. IXGBE_PVFGOTC_MSB(i),
  6286. adapter->vfinfo[i].last_vfstats.gotc,
  6287. adapter->vfinfo[i].vfstats.gotc);
  6288. UPDATE_VF_COUNTER_32bit(IXGBE_PVFMPRC(i),
  6289. adapter->vfinfo[i].last_vfstats.mprc,
  6290. adapter->vfinfo[i].vfstats.mprc);
  6291. }
  6292. }
  6293. }
  6294. /**
  6295. * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
  6296. * @adapter: pointer to the device adapter structure
  6297. **/
  6298. static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
  6299. {
  6300. struct ixgbe_hw *hw = &adapter->hw;
  6301. int i;
  6302. if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
  6303. return;
  6304. adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  6305. /* if interface is down do nothing */
  6306. if (test_bit(__IXGBE_DOWN, &adapter->state))
  6307. return;
  6308. /* do nothing if we are not using signature filters */
  6309. if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
  6310. return;
  6311. adapter->fdir_overflow++;
  6312. if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
  6313. for (i = 0; i < adapter->num_tx_queues; i++)
  6314. set_bit(__IXGBE_TX_FDIR_INIT_DONE,
  6315. &(adapter->tx_ring[i]->state));
  6316. for (i = 0; i < adapter->num_xdp_queues; i++)
  6317. set_bit(__IXGBE_TX_FDIR_INIT_DONE,
  6318. &adapter->xdp_ring[i]->state);
  6319. /* re-enable flow director interrupts */
  6320. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
  6321. } else {
  6322. e_err(probe, "failed to finish FDIR re-initialization, "
  6323. "ignored adding FDIR ATR filters\n");
  6324. }
  6325. }
  6326. /**
  6327. * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
  6328. * @adapter: pointer to the device adapter structure
  6329. *
  6330. * This function serves two purposes. First it strobes the interrupt lines
  6331. * in order to make certain interrupts are occurring. Secondly it sets the
  6332. * bits needed to check for TX hangs. As a result we should immediately
  6333. * determine if a hang has occurred.
  6334. */
  6335. static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
  6336. {
  6337. struct ixgbe_hw *hw = &adapter->hw;
  6338. u64 eics = 0;
  6339. int i;
  6340. /* If we're down, removing or resetting, just bail */
  6341. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  6342. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  6343. test_bit(__IXGBE_RESETTING, &adapter->state))
  6344. return;
  6345. /* Force detection of hung controller */
  6346. if (netif_carrier_ok(adapter->netdev)) {
  6347. for (i = 0; i < adapter->num_tx_queues; i++)
  6348. set_check_for_tx_hang(adapter->tx_ring[i]);
  6349. for (i = 0; i < adapter->num_xdp_queues; i++)
  6350. set_check_for_tx_hang(adapter->xdp_ring[i]);
  6351. }
  6352. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  6353. /*
  6354. * for legacy and MSI interrupts don't set any bits
  6355. * that are enabled for EIAM, because this operation
  6356. * would set *both* EIMS and EICS for any bit in EIAM
  6357. */
  6358. IXGBE_WRITE_REG(hw, IXGBE_EICS,
  6359. (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
  6360. } else {
  6361. /* get one bit for every active tx/rx interrupt vector */
  6362. for (i = 0; i < adapter->num_q_vectors; i++) {
  6363. struct ixgbe_q_vector *qv = adapter->q_vector[i];
  6364. if (qv->rx.ring || qv->tx.ring)
  6365. eics |= BIT_ULL(i);
  6366. }
  6367. }
  6368. /* Cause software interrupt to ensure rings are cleaned */
  6369. ixgbe_irq_rearm_queues(adapter, eics);
  6370. }
  6371. /**
  6372. * ixgbe_watchdog_update_link - update the link status
  6373. * @adapter: pointer to the device adapter structure
  6374. **/
  6375. static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
  6376. {
  6377. struct ixgbe_hw *hw = &adapter->hw;
  6378. u32 link_speed = adapter->link_speed;
  6379. bool link_up = adapter->link_up;
  6380. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  6381. if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
  6382. return;
  6383. if (hw->mac.ops.check_link) {
  6384. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  6385. } else {
  6386. /* always assume link is up, if no check link function */
  6387. link_speed = IXGBE_LINK_SPEED_10GB_FULL;
  6388. link_up = true;
  6389. }
  6390. if (adapter->ixgbe_ieee_pfc)
  6391. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  6392. if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
  6393. hw->mac.ops.fc_enable(hw);
  6394. ixgbe_set_rx_drop_en(adapter);
  6395. }
  6396. if (link_up ||
  6397. time_after(jiffies, (adapter->link_check_timeout +
  6398. IXGBE_TRY_LINK_TIMEOUT))) {
  6399. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  6400. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
  6401. IXGBE_WRITE_FLUSH(hw);
  6402. }
  6403. adapter->link_up = link_up;
  6404. adapter->link_speed = link_speed;
  6405. }
  6406. static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
  6407. {
  6408. #ifdef CONFIG_IXGBE_DCB
  6409. struct net_device *netdev = adapter->netdev;
  6410. struct dcb_app app = {
  6411. .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
  6412. .protocol = 0,
  6413. };
  6414. u8 up = 0;
  6415. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
  6416. up = dcb_ieee_getapp_mask(netdev, &app);
  6417. adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
  6418. #endif
  6419. }
  6420. /**
  6421. * ixgbe_watchdog_link_is_up - update netif_carrier status and
  6422. * print link up message
  6423. * @adapter: pointer to the device adapter structure
  6424. **/
  6425. static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
  6426. {
  6427. struct net_device *netdev = adapter->netdev;
  6428. struct ixgbe_hw *hw = &adapter->hw;
  6429. u32 link_speed = adapter->link_speed;
  6430. const char *speed_str;
  6431. bool flow_rx, flow_tx;
  6432. /* only continue if link was previously down */
  6433. if (netif_carrier_ok(netdev))
  6434. return;
  6435. adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
  6436. switch (hw->mac.type) {
  6437. case ixgbe_mac_82598EB: {
  6438. u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  6439. u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
  6440. flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
  6441. flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
  6442. }
  6443. break;
  6444. case ixgbe_mac_X540:
  6445. case ixgbe_mac_X550:
  6446. case ixgbe_mac_X550EM_x:
  6447. case ixgbe_mac_x550em_a:
  6448. case ixgbe_mac_82599EB: {
  6449. u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  6450. u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
  6451. flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
  6452. flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
  6453. }
  6454. break;
  6455. default:
  6456. flow_tx = false;
  6457. flow_rx = false;
  6458. break;
  6459. }
  6460. adapter->last_rx_ptp_check = jiffies;
  6461. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  6462. ixgbe_ptp_start_cyclecounter(adapter);
  6463. switch (link_speed) {
  6464. case IXGBE_LINK_SPEED_10GB_FULL:
  6465. speed_str = "10 Gbps";
  6466. break;
  6467. case IXGBE_LINK_SPEED_5GB_FULL:
  6468. speed_str = "5 Gbps";
  6469. break;
  6470. case IXGBE_LINK_SPEED_2_5GB_FULL:
  6471. speed_str = "2.5 Gbps";
  6472. break;
  6473. case IXGBE_LINK_SPEED_1GB_FULL:
  6474. speed_str = "1 Gbps";
  6475. break;
  6476. case IXGBE_LINK_SPEED_100_FULL:
  6477. speed_str = "100 Mbps";
  6478. break;
  6479. case IXGBE_LINK_SPEED_10_FULL:
  6480. speed_str = "10 Mbps";
  6481. break;
  6482. default:
  6483. speed_str = "unknown speed";
  6484. break;
  6485. }
  6486. e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
  6487. ((flow_rx && flow_tx) ? "RX/TX" :
  6488. (flow_rx ? "RX" :
  6489. (flow_tx ? "TX" : "None"))));
  6490. netif_carrier_on(netdev);
  6491. ixgbe_check_vf_rate_limit(adapter);
  6492. /* enable transmits */
  6493. netif_tx_wake_all_queues(adapter->netdev);
  6494. /* update the default user priority for VFs */
  6495. ixgbe_update_default_up(adapter);
  6496. /* ping all the active vfs to let them know link has changed */
  6497. ixgbe_ping_all_vfs(adapter);
  6498. }
  6499. /**
  6500. * ixgbe_watchdog_link_is_down - update netif_carrier status and
  6501. * print link down message
  6502. * @adapter: pointer to the adapter structure
  6503. **/
  6504. static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
  6505. {
  6506. struct net_device *netdev = adapter->netdev;
  6507. struct ixgbe_hw *hw = &adapter->hw;
  6508. adapter->link_up = false;
  6509. adapter->link_speed = 0;
  6510. /* only continue if link was up previously */
  6511. if (!netif_carrier_ok(netdev))
  6512. return;
  6513. /* poll for SFP+ cable when link is down */
  6514. if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
  6515. adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
  6516. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  6517. ixgbe_ptp_start_cyclecounter(adapter);
  6518. e_info(drv, "NIC Link is Down\n");
  6519. netif_carrier_off(netdev);
  6520. /* ping all the active vfs to let them know link has changed */
  6521. ixgbe_ping_all_vfs(adapter);
  6522. }
  6523. static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
  6524. {
  6525. int i;
  6526. for (i = 0; i < adapter->num_tx_queues; i++) {
  6527. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  6528. if (tx_ring->next_to_use != tx_ring->next_to_clean)
  6529. return true;
  6530. }
  6531. for (i = 0; i < adapter->num_xdp_queues; i++) {
  6532. struct ixgbe_ring *ring = adapter->xdp_ring[i];
  6533. if (ring->next_to_use != ring->next_to_clean)
  6534. return true;
  6535. }
  6536. return false;
  6537. }
  6538. static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
  6539. {
  6540. struct ixgbe_hw *hw = &adapter->hw;
  6541. struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
  6542. u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
  6543. int i, j;
  6544. if (!adapter->num_vfs)
  6545. return false;
  6546. /* resetting the PF is only needed for MAC before X550 */
  6547. if (hw->mac.type >= ixgbe_mac_X550)
  6548. return false;
  6549. for (i = 0; i < adapter->num_vfs; i++) {
  6550. for (j = 0; j < q_per_pool; j++) {
  6551. u32 h, t;
  6552. h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
  6553. t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
  6554. if (h != t)
  6555. return true;
  6556. }
  6557. }
  6558. return false;
  6559. }
  6560. /**
  6561. * ixgbe_watchdog_flush_tx - flush queues on link down
  6562. * @adapter: pointer to the device adapter structure
  6563. **/
  6564. static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
  6565. {
  6566. if (!netif_carrier_ok(adapter->netdev)) {
  6567. if (ixgbe_ring_tx_pending(adapter) ||
  6568. ixgbe_vf_tx_pending(adapter)) {
  6569. /* We've lost link, so the controller stops DMA,
  6570. * but we've got queued Tx work that's never going
  6571. * to get done, so reset controller to flush Tx.
  6572. * (Do the reset outside of interrupt context).
  6573. */
  6574. e_warn(drv, "initiating reset to clear Tx work after link loss\n");
  6575. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  6576. }
  6577. }
  6578. }
  6579. #ifdef CONFIG_PCI_IOV
  6580. static void ixgbe_bad_vf_abort(struct ixgbe_adapter *adapter, u32 vf)
  6581. {
  6582. struct ixgbe_hw *hw = &adapter->hw;
  6583. if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
  6584. adapter->flags2 & IXGBE_FLAG2_AUTO_DISABLE_VF) {
  6585. adapter->vfinfo[vf].primary_abort_count++;
  6586. if (adapter->vfinfo[vf].primary_abort_count ==
  6587. IXGBE_PRIMARY_ABORT_LIMIT) {
  6588. ixgbe_set_vf_link_state(adapter, vf,
  6589. IFLA_VF_LINK_STATE_DISABLE);
  6590. adapter->vfinfo[vf].primary_abort_count = 0;
  6591. e_info(drv,
  6592. "Malicious Driver Detection event detected on PF %d VF %d MAC: %pM mdd-disable-vf=on",
  6593. hw->bus.func, vf,
  6594. adapter->vfinfo[vf].vf_mac_addresses);
  6595. }
  6596. }
  6597. }
  6598. static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
  6599. {
  6600. struct ixgbe_hw *hw = &adapter->hw;
  6601. struct pci_dev *pdev = adapter->pdev;
  6602. unsigned int vf;
  6603. u32 gpc;
  6604. if (!(netif_carrier_ok(adapter->netdev)))
  6605. return;
  6606. gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
  6607. if (gpc) /* If incrementing then no need for the check below */
  6608. return;
  6609. /* Check to see if a bad DMA write target from an errant or
  6610. * malicious VF has caused a PCIe error. If so then we can
  6611. * issue a VFLR to the offending VF(s) and then resume without
  6612. * requesting a full slot reset.
  6613. */
  6614. if (!pdev)
  6615. return;
  6616. /* check status reg for all VFs owned by this PF */
  6617. for (vf = 0; vf < adapter->num_vfs; ++vf) {
  6618. struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
  6619. u16 status_reg;
  6620. if (!vfdev)
  6621. continue;
  6622. pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
  6623. if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
  6624. status_reg & PCI_STATUS_REC_MASTER_ABORT) {
  6625. ixgbe_bad_vf_abort(adapter, vf);
  6626. pcie_flr(vfdev);
  6627. }
  6628. }
  6629. }
  6630. static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
  6631. {
  6632. u32 ssvpc;
  6633. /* Do not perform spoof check for 82598 or if not in IOV mode */
  6634. if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
  6635. adapter->num_vfs == 0)
  6636. return;
  6637. ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
  6638. /*
  6639. * ssvpc register is cleared on read, if zero then no
  6640. * spoofed packets in the last interval.
  6641. */
  6642. if (!ssvpc)
  6643. return;
  6644. e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
  6645. }
  6646. #else
  6647. static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
  6648. {
  6649. }
  6650. static void
  6651. ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
  6652. {
  6653. }
  6654. #endif /* CONFIG_PCI_IOV */
  6655. /**
  6656. * ixgbe_watchdog_subtask - check and bring link up
  6657. * @adapter: pointer to the device adapter structure
  6658. **/
  6659. static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
  6660. {
  6661. /* if interface is down, removing or resetting, do nothing */
  6662. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  6663. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  6664. test_bit(__IXGBE_RESETTING, &adapter->state))
  6665. return;
  6666. ixgbe_watchdog_update_link(adapter);
  6667. if (adapter->link_up)
  6668. ixgbe_watchdog_link_is_up(adapter);
  6669. else
  6670. ixgbe_watchdog_link_is_down(adapter);
  6671. ixgbe_check_for_bad_vf(adapter);
  6672. ixgbe_spoof_check(adapter);
  6673. ixgbe_update_stats(adapter);
  6674. ixgbe_watchdog_flush_tx(adapter);
  6675. }
  6676. /**
  6677. * ixgbe_sfp_detection_subtask - poll for SFP+ cable
  6678. * @adapter: the ixgbe adapter structure
  6679. **/
  6680. static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
  6681. {
  6682. struct ixgbe_hw *hw = &adapter->hw;
  6683. int err;
  6684. /* not searching for SFP so there is nothing to do here */
  6685. if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
  6686. !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
  6687. return;
  6688. if (adapter->sfp_poll_time &&
  6689. time_after(adapter->sfp_poll_time, jiffies))
  6690. return; /* If not yet time to poll for SFP */
  6691. /* someone else is in init, wait until next service event */
  6692. if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  6693. return;
  6694. adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
  6695. err = hw->phy.ops.identify_sfp(hw);
  6696. if (err == -EOPNOTSUPP)
  6697. goto sfp_out;
  6698. if (err == -ENOENT) {
  6699. /* If no cable is present, then we need to reset
  6700. * the next time we find a good cable. */
  6701. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  6702. }
  6703. /* exit on error */
  6704. if (err)
  6705. goto sfp_out;
  6706. /* exit if reset not needed */
  6707. if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
  6708. goto sfp_out;
  6709. adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
  6710. /*
  6711. * A module may be identified correctly, but the EEPROM may not have
  6712. * support for that module. setup_sfp() will fail in that case, so
  6713. * we should not allow that module to load.
  6714. */
  6715. if (hw->mac.type == ixgbe_mac_82598EB)
  6716. err = hw->phy.ops.reset(hw);
  6717. else
  6718. err = hw->mac.ops.setup_sfp(hw);
  6719. if (err == -EOPNOTSUPP)
  6720. goto sfp_out;
  6721. adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
  6722. e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
  6723. sfp_out:
  6724. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  6725. if (err == -EOPNOTSUPP &&
  6726. adapter->netdev->reg_state == NETREG_REGISTERED) {
  6727. e_dev_err("failed to initialize because an unsupported "
  6728. "SFP+ module type was detected.\n");
  6729. e_dev_err("Reload the driver after installing a "
  6730. "supported module.\n");
  6731. unregister_netdev(adapter->netdev);
  6732. }
  6733. }
  6734. /**
  6735. * ixgbe_sfp_link_config_subtask - set up link SFP after module install
  6736. * @adapter: the ixgbe adapter structure
  6737. **/
  6738. static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
  6739. {
  6740. struct ixgbe_hw *hw = &adapter->hw;
  6741. u32 cap_speed;
  6742. u32 speed;
  6743. bool autoneg = false;
  6744. if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
  6745. return;
  6746. /* someone else is in init, wait until next service event */
  6747. if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  6748. return;
  6749. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
  6750. hw->mac.ops.get_link_capabilities(hw, &cap_speed, &autoneg);
  6751. /* advertise highest capable link speed */
  6752. if (!autoneg && (cap_speed & IXGBE_LINK_SPEED_10GB_FULL))
  6753. speed = IXGBE_LINK_SPEED_10GB_FULL;
  6754. else
  6755. speed = cap_speed & (IXGBE_LINK_SPEED_10GB_FULL |
  6756. IXGBE_LINK_SPEED_1GB_FULL);
  6757. if (hw->mac.ops.setup_link)
  6758. hw->mac.ops.setup_link(hw, speed, true);
  6759. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  6760. adapter->link_check_timeout = jiffies;
  6761. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  6762. }
  6763. /**
  6764. * ixgbe_service_timer - Timer Call-back
  6765. * @t: pointer to timer_list structure
  6766. **/
  6767. static void ixgbe_service_timer(struct timer_list *t)
  6768. {
  6769. struct ixgbe_adapter *adapter = from_timer(adapter, t, service_timer);
  6770. unsigned long next_event_offset;
  6771. /* poll faster when waiting for link */
  6772. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
  6773. next_event_offset = HZ / 10;
  6774. else
  6775. next_event_offset = HZ * 2;
  6776. /* Reset the timer */
  6777. mod_timer(&adapter->service_timer, next_event_offset + jiffies);
  6778. ixgbe_service_event_schedule(adapter);
  6779. }
  6780. static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
  6781. {
  6782. struct ixgbe_hw *hw = &adapter->hw;
  6783. bool overtemp;
  6784. if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
  6785. return;
  6786. adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
  6787. if (!hw->phy.ops.handle_lasi)
  6788. return;
  6789. hw->phy.ops.handle_lasi(&adapter->hw, &overtemp);
  6790. if (overtemp)
  6791. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  6792. }
  6793. static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
  6794. {
  6795. if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state))
  6796. return;
  6797. rtnl_lock();
  6798. /* If we're already down, removing or resetting, just bail */
  6799. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  6800. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  6801. test_bit(__IXGBE_RESETTING, &adapter->state)) {
  6802. rtnl_unlock();
  6803. return;
  6804. }
  6805. ixgbe_dump(adapter);
  6806. netdev_err(adapter->netdev, "Reset adapter\n");
  6807. adapter->tx_timeout_count++;
  6808. ixgbe_reinit_locked(adapter);
  6809. rtnl_unlock();
  6810. }
  6811. /**
  6812. * ixgbe_check_fw_error - Check firmware for errors
  6813. * @adapter: the adapter private structure
  6814. *
  6815. * Check firmware errors in register FWSM
  6816. */
  6817. static bool ixgbe_check_fw_error(struct ixgbe_adapter *adapter)
  6818. {
  6819. struct ixgbe_hw *hw = &adapter->hw;
  6820. u32 fwsm;
  6821. /* read fwsm.ext_err_ind register and log errors */
  6822. fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
  6823. if (fwsm & IXGBE_FWSM_EXT_ERR_IND_MASK ||
  6824. !(fwsm & IXGBE_FWSM_FW_VAL_BIT))
  6825. e_dev_warn("Warning firmware error detected FWSM: 0x%08X\n",
  6826. fwsm);
  6827. if (hw->mac.ops.fw_recovery_mode && hw->mac.ops.fw_recovery_mode(hw)) {
  6828. e_dev_err("Firmware recovery mode detected. Limiting functionality. Refer to the Intel(R) Ethernet Adapters and Devices User Guide for details on firmware recovery mode.\n");
  6829. return true;
  6830. }
  6831. return false;
  6832. }
  6833. /**
  6834. * ixgbe_service_task - manages and runs subtasks
  6835. * @work: pointer to work_struct containing our data
  6836. **/
  6837. static void ixgbe_service_task(struct work_struct *work)
  6838. {
  6839. struct ixgbe_adapter *adapter = container_of(work,
  6840. struct ixgbe_adapter,
  6841. service_task);
  6842. if (ixgbe_removed(adapter->hw.hw_addr)) {
  6843. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  6844. rtnl_lock();
  6845. ixgbe_down(adapter);
  6846. rtnl_unlock();
  6847. }
  6848. ixgbe_service_event_complete(adapter);
  6849. return;
  6850. }
  6851. if (ixgbe_check_fw_error(adapter)) {
  6852. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  6853. unregister_netdev(adapter->netdev);
  6854. ixgbe_service_event_complete(adapter);
  6855. return;
  6856. }
  6857. ixgbe_reset_subtask(adapter);
  6858. ixgbe_phy_interrupt_subtask(adapter);
  6859. ixgbe_sfp_detection_subtask(adapter);
  6860. ixgbe_sfp_link_config_subtask(adapter);
  6861. ixgbe_check_overtemp_subtask(adapter);
  6862. ixgbe_watchdog_subtask(adapter);
  6863. ixgbe_fdir_reinit_subtask(adapter);
  6864. ixgbe_check_hang_subtask(adapter);
  6865. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
  6866. ixgbe_ptp_overflow_check(adapter);
  6867. if (adapter->flags & IXGBE_FLAG_RX_HWTSTAMP_IN_REGISTER)
  6868. ixgbe_ptp_rx_hang(adapter);
  6869. ixgbe_ptp_tx_hang(adapter);
  6870. }
  6871. ixgbe_service_event_complete(adapter);
  6872. }
  6873. static int ixgbe_tso(struct ixgbe_ring *tx_ring,
  6874. struct ixgbe_tx_buffer *first,
  6875. u8 *hdr_len,
  6876. struct ixgbe_ipsec_tx_data *itd)
  6877. {
  6878. u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
  6879. struct sk_buff *skb = first->skb;
  6880. union {
  6881. struct iphdr *v4;
  6882. struct ipv6hdr *v6;
  6883. unsigned char *hdr;
  6884. } ip;
  6885. union {
  6886. struct tcphdr *tcp;
  6887. struct udphdr *udp;
  6888. unsigned char *hdr;
  6889. } l4;
  6890. u32 paylen, l4_offset;
  6891. u32 fceof_saidx = 0;
  6892. int err;
  6893. if (skb->ip_summed != CHECKSUM_PARTIAL)
  6894. return 0;
  6895. if (!skb_is_gso(skb))
  6896. return 0;
  6897. err = skb_cow_head(skb, 0);
  6898. if (err < 0)
  6899. return err;
  6900. if (eth_p_mpls(first->protocol))
  6901. ip.hdr = skb_inner_network_header(skb);
  6902. else
  6903. ip.hdr = skb_network_header(skb);
  6904. l4.hdr = skb_checksum_start(skb);
  6905. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  6906. type_tucmd = (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) ?
  6907. IXGBE_ADVTXD_TUCMD_L4T_UDP : IXGBE_ADVTXD_TUCMD_L4T_TCP;
  6908. /* initialize outer IP header fields */
  6909. if (ip.v4->version == 4) {
  6910. unsigned char *csum_start = skb_checksum_start(skb);
  6911. unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
  6912. int len = csum_start - trans_start;
  6913. /* IP header will have to cancel out any data that
  6914. * is not a part of the outer IP header, so set to
  6915. * a reverse csum if needed, else init check to 0.
  6916. */
  6917. ip.v4->check = (skb_shinfo(skb)->gso_type & SKB_GSO_PARTIAL) ?
  6918. csum_fold(csum_partial(trans_start,
  6919. len, 0)) : 0;
  6920. type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
  6921. ip.v4->tot_len = 0;
  6922. first->tx_flags |= IXGBE_TX_FLAGS_TSO |
  6923. IXGBE_TX_FLAGS_CSUM |
  6924. IXGBE_TX_FLAGS_IPV4;
  6925. } else {
  6926. ip.v6->payload_len = 0;
  6927. first->tx_flags |= IXGBE_TX_FLAGS_TSO |
  6928. IXGBE_TX_FLAGS_CSUM;
  6929. }
  6930. /* determine offset of inner transport header */
  6931. l4_offset = l4.hdr - skb->data;
  6932. /* remove payload length from inner checksum */
  6933. paylen = skb->len - l4_offset;
  6934. if (type_tucmd & IXGBE_ADVTXD_TUCMD_L4T_TCP) {
  6935. /* compute length of segmentation header */
  6936. *hdr_len = (l4.tcp->doff * 4) + l4_offset;
  6937. csum_replace_by_diff(&l4.tcp->check,
  6938. (__force __wsum)htonl(paylen));
  6939. } else {
  6940. /* compute length of segmentation header */
  6941. *hdr_len = sizeof(*l4.udp) + l4_offset;
  6942. csum_replace_by_diff(&l4.udp->check,
  6943. (__force __wsum)htonl(paylen));
  6944. }
  6945. /* update gso size and bytecount with header size */
  6946. first->gso_segs = skb_shinfo(skb)->gso_segs;
  6947. first->bytecount += (first->gso_segs - 1) * *hdr_len;
  6948. /* mss_l4len_id: use 0 as index for TSO */
  6949. mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT;
  6950. mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
  6951. fceof_saidx |= itd->sa_idx;
  6952. type_tucmd |= itd->flags | itd->trailer_len;
  6953. /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
  6954. vlan_macip_lens = l4.hdr - ip.hdr;
  6955. vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
  6956. vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  6957. ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd,
  6958. mss_l4len_idx);
  6959. return 1;
  6960. }
  6961. static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
  6962. struct ixgbe_tx_buffer *first,
  6963. struct ixgbe_ipsec_tx_data *itd)
  6964. {
  6965. struct sk_buff *skb = first->skb;
  6966. u32 vlan_macip_lens = 0;
  6967. u32 fceof_saidx = 0;
  6968. u32 type_tucmd = 0;
  6969. if (skb->ip_summed != CHECKSUM_PARTIAL) {
  6970. csum_failed:
  6971. if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
  6972. IXGBE_TX_FLAGS_CC)))
  6973. return;
  6974. goto no_csum;
  6975. }
  6976. switch (skb->csum_offset) {
  6977. case offsetof(struct tcphdr, check):
  6978. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
  6979. fallthrough;
  6980. case offsetof(struct udphdr, check):
  6981. break;
  6982. case offsetof(struct sctphdr, checksum):
  6983. /* validate that this is actually an SCTP request */
  6984. if (skb_csum_is_sctp(skb)) {
  6985. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  6986. break;
  6987. }
  6988. fallthrough;
  6989. default:
  6990. skb_checksum_help(skb);
  6991. goto csum_failed;
  6992. }
  6993. /* update TX checksum flag */
  6994. first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
  6995. vlan_macip_lens = skb_checksum_start_offset(skb) -
  6996. skb_network_offset(skb);
  6997. no_csum:
  6998. /* vlan_macip_lens: MACLEN, VLAN tag */
  6999. vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
  7000. vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  7001. fceof_saidx |= itd->sa_idx;
  7002. type_tucmd |= itd->flags | itd->trailer_len;
  7003. ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd, 0);
  7004. }
  7005. #define IXGBE_SET_FLAG(_input, _flag, _result) \
  7006. ((_flag <= _result) ? \
  7007. ((u32)(_input & _flag) * (_result / _flag)) : \
  7008. ((u32)(_input & _flag) / (_flag / _result)))
  7009. static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
  7010. {
  7011. /* set type for advanced descriptor with frame checksum insertion */
  7012. u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
  7013. IXGBE_ADVTXD_DCMD_DEXT |
  7014. IXGBE_ADVTXD_DCMD_IFCS;
  7015. /* set HW vlan bit if vlan is present */
  7016. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
  7017. IXGBE_ADVTXD_DCMD_VLE);
  7018. /* set segmentation enable bits for TSO/FSO */
  7019. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
  7020. IXGBE_ADVTXD_DCMD_TSE);
  7021. /* set timestamp bit if present */
  7022. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
  7023. IXGBE_ADVTXD_MAC_TSTAMP);
  7024. /* insert frame checksum */
  7025. cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
  7026. return cmd_type;
  7027. }
  7028. static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
  7029. u32 tx_flags, unsigned int paylen)
  7030. {
  7031. u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
  7032. /* enable L4 checksum for TSO and TX checksum offload */
  7033. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  7034. IXGBE_TX_FLAGS_CSUM,
  7035. IXGBE_ADVTXD_POPTS_TXSM);
  7036. /* enable IPv4 checksum for TSO */
  7037. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  7038. IXGBE_TX_FLAGS_IPV4,
  7039. IXGBE_ADVTXD_POPTS_IXSM);
  7040. /* enable IPsec */
  7041. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  7042. IXGBE_TX_FLAGS_IPSEC,
  7043. IXGBE_ADVTXD_POPTS_IPSEC);
  7044. /*
  7045. * Check Context must be set if Tx switch is enabled, which it
  7046. * always is for case where virtual functions are running
  7047. */
  7048. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  7049. IXGBE_TX_FLAGS_CC,
  7050. IXGBE_ADVTXD_CC);
  7051. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  7052. }
  7053. static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
  7054. {
  7055. if (!netif_subqueue_try_stop(tx_ring->netdev, tx_ring->queue_index,
  7056. ixgbe_desc_unused(tx_ring), size))
  7057. return -EBUSY;
  7058. ++tx_ring->tx_stats.restart_queue;
  7059. return 0;
  7060. }
  7061. static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
  7062. {
  7063. if (likely(ixgbe_desc_unused(tx_ring) >= size))
  7064. return 0;
  7065. return __ixgbe_maybe_stop_tx(tx_ring, size);
  7066. }
  7067. static int ixgbe_tx_map(struct ixgbe_ring *tx_ring,
  7068. struct ixgbe_tx_buffer *first,
  7069. const u8 hdr_len)
  7070. {
  7071. struct sk_buff *skb = first->skb;
  7072. struct ixgbe_tx_buffer *tx_buffer;
  7073. union ixgbe_adv_tx_desc *tx_desc;
  7074. skb_frag_t *frag;
  7075. dma_addr_t dma;
  7076. unsigned int data_len, size;
  7077. u32 tx_flags = first->tx_flags;
  7078. u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
  7079. u16 i = tx_ring->next_to_use;
  7080. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  7081. ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
  7082. size = skb_headlen(skb);
  7083. data_len = skb->data_len;
  7084. #ifdef IXGBE_FCOE
  7085. if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
  7086. if (data_len < sizeof(struct fcoe_crc_eof)) {
  7087. size -= sizeof(struct fcoe_crc_eof) - data_len;
  7088. data_len = 0;
  7089. } else {
  7090. data_len -= sizeof(struct fcoe_crc_eof);
  7091. }
  7092. }
  7093. #endif
  7094. dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
  7095. tx_buffer = first;
  7096. for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
  7097. if (dma_mapping_error(tx_ring->dev, dma))
  7098. goto dma_error;
  7099. /* record length, and DMA address */
  7100. dma_unmap_len_set(tx_buffer, len, size);
  7101. dma_unmap_addr_set(tx_buffer, dma, dma);
  7102. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  7103. while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
  7104. tx_desc->read.cmd_type_len =
  7105. cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
  7106. i++;
  7107. tx_desc++;
  7108. if (i == tx_ring->count) {
  7109. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  7110. i = 0;
  7111. }
  7112. tx_desc->read.olinfo_status = 0;
  7113. dma += IXGBE_MAX_DATA_PER_TXD;
  7114. size -= IXGBE_MAX_DATA_PER_TXD;
  7115. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  7116. }
  7117. if (likely(!data_len))
  7118. break;
  7119. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
  7120. i++;
  7121. tx_desc++;
  7122. if (i == tx_ring->count) {
  7123. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  7124. i = 0;
  7125. }
  7126. tx_desc->read.olinfo_status = 0;
  7127. #ifdef IXGBE_FCOE
  7128. size = min_t(unsigned int, data_len, skb_frag_size(frag));
  7129. #else
  7130. size = skb_frag_size(frag);
  7131. #endif
  7132. data_len -= size;
  7133. dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
  7134. DMA_TO_DEVICE);
  7135. tx_buffer = &tx_ring->tx_buffer_info[i];
  7136. }
  7137. /* write last descriptor with RS and EOP bits */
  7138. cmd_type |= size | IXGBE_TXD_CMD;
  7139. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
  7140. netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
  7141. /* set the timestamp */
  7142. first->time_stamp = jiffies;
  7143. skb_tx_timestamp(skb);
  7144. /*
  7145. * Force memory writes to complete before letting h/w know there
  7146. * are new descriptors to fetch. (Only applicable for weak-ordered
  7147. * memory model archs, such as IA-64).
  7148. *
  7149. * We also need this memory barrier to make certain all of the
  7150. * status bits have been updated before next_to_watch is written.
  7151. */
  7152. wmb();
  7153. /* set next_to_watch value indicating a packet is present */
  7154. first->next_to_watch = tx_desc;
  7155. i++;
  7156. if (i == tx_ring->count)
  7157. i = 0;
  7158. tx_ring->next_to_use = i;
  7159. ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
  7160. if (netif_xmit_stopped(txring_txq(tx_ring)) || !netdev_xmit_more()) {
  7161. writel(i, tx_ring->tail);
  7162. }
  7163. return 0;
  7164. dma_error:
  7165. dev_err(tx_ring->dev, "TX DMA map failed\n");
  7166. /* clear dma mappings for failed tx_buffer_info map */
  7167. for (;;) {
  7168. tx_buffer = &tx_ring->tx_buffer_info[i];
  7169. if (dma_unmap_len(tx_buffer, len))
  7170. dma_unmap_page(tx_ring->dev,
  7171. dma_unmap_addr(tx_buffer, dma),
  7172. dma_unmap_len(tx_buffer, len),
  7173. DMA_TO_DEVICE);
  7174. dma_unmap_len_set(tx_buffer, len, 0);
  7175. if (tx_buffer == first)
  7176. break;
  7177. if (i == 0)
  7178. i += tx_ring->count;
  7179. i--;
  7180. }
  7181. dev_kfree_skb_any(first->skb);
  7182. first->skb = NULL;
  7183. tx_ring->next_to_use = i;
  7184. return -1;
  7185. }
  7186. static void ixgbe_atr(struct ixgbe_ring *ring,
  7187. struct ixgbe_tx_buffer *first)
  7188. {
  7189. struct ixgbe_q_vector *q_vector = ring->q_vector;
  7190. union ixgbe_atr_hash_dword input = { .dword = 0 };
  7191. union ixgbe_atr_hash_dword common = { .dword = 0 };
  7192. union {
  7193. unsigned char *network;
  7194. struct iphdr *ipv4;
  7195. struct ipv6hdr *ipv6;
  7196. } hdr;
  7197. struct tcphdr *th;
  7198. unsigned int hlen;
  7199. struct sk_buff *skb;
  7200. __be16 vlan_id;
  7201. int l4_proto;
  7202. /* if ring doesn't have a interrupt vector, cannot perform ATR */
  7203. if (!q_vector)
  7204. return;
  7205. /* do nothing if sampling is disabled */
  7206. if (!ring->atr_sample_rate)
  7207. return;
  7208. ring->atr_count++;
  7209. /* currently only IPv4/IPv6 with TCP is supported */
  7210. if ((first->protocol != htons(ETH_P_IP)) &&
  7211. (first->protocol != htons(ETH_P_IPV6)))
  7212. return;
  7213. /* snag network header to get L4 type and address */
  7214. skb = first->skb;
  7215. hdr.network = skb_network_header(skb);
  7216. if (unlikely(hdr.network <= skb->data))
  7217. return;
  7218. if (skb->encapsulation &&
  7219. first->protocol == htons(ETH_P_IP) &&
  7220. hdr.ipv4->protocol == IPPROTO_UDP) {
  7221. struct ixgbe_adapter *adapter = q_vector->adapter;
  7222. if (unlikely(skb_tail_pointer(skb) < hdr.network +
  7223. vxlan_headroom(0)))
  7224. return;
  7225. /* verify the port is recognized as VXLAN */
  7226. if (adapter->vxlan_port &&
  7227. udp_hdr(skb)->dest == adapter->vxlan_port)
  7228. hdr.network = skb_inner_network_header(skb);
  7229. if (adapter->geneve_port &&
  7230. udp_hdr(skb)->dest == adapter->geneve_port)
  7231. hdr.network = skb_inner_network_header(skb);
  7232. }
  7233. /* Make sure we have at least [minimum IPv4 header + TCP]
  7234. * or [IPv6 header] bytes
  7235. */
  7236. if (unlikely(skb_tail_pointer(skb) < hdr.network + 40))
  7237. return;
  7238. /* Currently only IPv4/IPv6 with TCP is supported */
  7239. switch (hdr.ipv4->version) {
  7240. case IPVERSION:
  7241. /* access ihl as u8 to avoid unaligned access on ia64 */
  7242. hlen = (hdr.network[0] & 0x0F) << 2;
  7243. l4_proto = hdr.ipv4->protocol;
  7244. break;
  7245. case 6:
  7246. hlen = hdr.network - skb->data;
  7247. l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
  7248. hlen -= hdr.network - skb->data;
  7249. break;
  7250. default:
  7251. return;
  7252. }
  7253. if (l4_proto != IPPROTO_TCP)
  7254. return;
  7255. if (unlikely(skb_tail_pointer(skb) < hdr.network +
  7256. hlen + sizeof(struct tcphdr)))
  7257. return;
  7258. th = (struct tcphdr *)(hdr.network + hlen);
  7259. /* skip this packet since the socket is closing */
  7260. if (th->fin)
  7261. return;
  7262. /* sample on all syn packets or once every atr sample count */
  7263. if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
  7264. return;
  7265. /* reset sample count */
  7266. ring->atr_count = 0;
  7267. vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
  7268. /*
  7269. * src and dst are inverted, think how the receiver sees them
  7270. *
  7271. * The input is broken into two sections, a non-compressed section
  7272. * containing vm_pool, vlan_id, and flow_type. The rest of the data
  7273. * is XORed together and stored in the compressed dword.
  7274. */
  7275. input.formatted.vlan_id = vlan_id;
  7276. /*
  7277. * since src port and flex bytes occupy the same word XOR them together
  7278. * and write the value to source port portion of compressed dword
  7279. */
  7280. if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
  7281. common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
  7282. else
  7283. common.port.src ^= th->dest ^ first->protocol;
  7284. common.port.dst ^= th->source;
  7285. switch (hdr.ipv4->version) {
  7286. case IPVERSION:
  7287. input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
  7288. common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
  7289. break;
  7290. case 6:
  7291. input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
  7292. common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
  7293. hdr.ipv6->saddr.s6_addr32[1] ^
  7294. hdr.ipv6->saddr.s6_addr32[2] ^
  7295. hdr.ipv6->saddr.s6_addr32[3] ^
  7296. hdr.ipv6->daddr.s6_addr32[0] ^
  7297. hdr.ipv6->daddr.s6_addr32[1] ^
  7298. hdr.ipv6->daddr.s6_addr32[2] ^
  7299. hdr.ipv6->daddr.s6_addr32[3];
  7300. break;
  7301. default:
  7302. break;
  7303. }
  7304. if (hdr.network != skb_network_header(skb))
  7305. input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
  7306. /* This assumes the Rx queue and Tx queue are bound to the same CPU */
  7307. ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
  7308. input, common, ring->queue_index);
  7309. }
  7310. #ifdef IXGBE_FCOE
  7311. static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
  7312. struct net_device *sb_dev)
  7313. {
  7314. struct ixgbe_adapter *adapter;
  7315. struct ixgbe_ring_feature *f;
  7316. int txq;
  7317. if (sb_dev) {
  7318. u8 tc = netdev_get_prio_tc_map(dev, skb->priority);
  7319. struct net_device *vdev = sb_dev;
  7320. txq = vdev->tc_to_txq[tc].offset;
  7321. txq += reciprocal_scale(skb_get_hash(skb),
  7322. vdev->tc_to_txq[tc].count);
  7323. return txq;
  7324. }
  7325. /*
  7326. * only execute the code below if protocol is FCoE
  7327. * or FIP and we have FCoE enabled on the adapter
  7328. */
  7329. switch (vlan_get_protocol(skb)) {
  7330. case htons(ETH_P_FCOE):
  7331. case htons(ETH_P_FIP):
  7332. adapter = netdev_priv(dev);
  7333. if (!sb_dev && (adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
  7334. break;
  7335. fallthrough;
  7336. default:
  7337. return netdev_pick_tx(dev, skb, sb_dev);
  7338. }
  7339. f = &adapter->ring_feature[RING_F_FCOE];
  7340. txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
  7341. smp_processor_id();
  7342. while (txq >= f->indices)
  7343. txq -= f->indices;
  7344. return txq + f->offset;
  7345. }
  7346. #endif
  7347. int ixgbe_xmit_xdp_ring(struct ixgbe_ring *ring,
  7348. struct xdp_frame *xdpf)
  7349. {
  7350. struct skb_shared_info *sinfo = xdp_get_shared_info_from_frame(xdpf);
  7351. u8 nr_frags = unlikely(xdp_frame_has_frags(xdpf)) ? sinfo->nr_frags : 0;
  7352. u16 i = 0, index = ring->next_to_use;
  7353. struct ixgbe_tx_buffer *tx_head = &ring->tx_buffer_info[index];
  7354. struct ixgbe_tx_buffer *tx_buff = tx_head;
  7355. union ixgbe_adv_tx_desc *tx_desc = IXGBE_TX_DESC(ring, index);
  7356. u32 cmd_type, len = xdpf->len;
  7357. void *data = xdpf->data;
  7358. if (unlikely(ixgbe_desc_unused(ring) < 1 + nr_frags))
  7359. return IXGBE_XDP_CONSUMED;
  7360. tx_head->bytecount = xdp_get_frame_len(xdpf);
  7361. tx_head->gso_segs = 1;
  7362. tx_head->xdpf = xdpf;
  7363. tx_desc->read.olinfo_status =
  7364. cpu_to_le32(tx_head->bytecount << IXGBE_ADVTXD_PAYLEN_SHIFT);
  7365. for (;;) {
  7366. dma_addr_t dma;
  7367. dma = dma_map_single(ring->dev, data, len, DMA_TO_DEVICE);
  7368. if (dma_mapping_error(ring->dev, dma))
  7369. goto unmap;
  7370. dma_unmap_len_set(tx_buff, len, len);
  7371. dma_unmap_addr_set(tx_buff, dma, dma);
  7372. cmd_type = IXGBE_ADVTXD_DTYP_DATA | IXGBE_ADVTXD_DCMD_DEXT |
  7373. IXGBE_ADVTXD_DCMD_IFCS | len;
  7374. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
  7375. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  7376. tx_buff->protocol = 0;
  7377. if (++index == ring->count)
  7378. index = 0;
  7379. if (i == nr_frags)
  7380. break;
  7381. tx_buff = &ring->tx_buffer_info[index];
  7382. tx_desc = IXGBE_TX_DESC(ring, index);
  7383. tx_desc->read.olinfo_status = 0;
  7384. data = skb_frag_address(&sinfo->frags[i]);
  7385. len = skb_frag_size(&sinfo->frags[i]);
  7386. i++;
  7387. }
  7388. /* put descriptor type bits */
  7389. tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD);
  7390. /* Avoid any potential race with xdp_xmit and cleanup */
  7391. smp_wmb();
  7392. tx_head->next_to_watch = tx_desc;
  7393. ring->next_to_use = index;
  7394. return IXGBE_XDP_TX;
  7395. unmap:
  7396. for (;;) {
  7397. tx_buff = &ring->tx_buffer_info[index];
  7398. if (dma_unmap_len(tx_buff, len))
  7399. dma_unmap_page(ring->dev, dma_unmap_addr(tx_buff, dma),
  7400. dma_unmap_len(tx_buff, len),
  7401. DMA_TO_DEVICE);
  7402. dma_unmap_len_set(tx_buff, len, 0);
  7403. if (tx_buff == tx_head)
  7404. break;
  7405. if (!index)
  7406. index += ring->count;
  7407. index--;
  7408. }
  7409. return IXGBE_XDP_CONSUMED;
  7410. }
  7411. netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
  7412. struct ixgbe_adapter *adapter,
  7413. struct ixgbe_ring *tx_ring)
  7414. {
  7415. struct ixgbe_tx_buffer *first;
  7416. int tso;
  7417. u32 tx_flags = 0;
  7418. unsigned short f;
  7419. u16 count = TXD_USE_COUNT(skb_headlen(skb));
  7420. struct ixgbe_ipsec_tx_data ipsec_tx = { 0 };
  7421. __be16 protocol = skb->protocol;
  7422. u8 hdr_len = 0;
  7423. /*
  7424. * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
  7425. * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
  7426. * + 2 desc gap to keep tail from touching head,
  7427. * + 1 desc for context descriptor,
  7428. * otherwise try next time
  7429. */
  7430. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
  7431. count += TXD_USE_COUNT(skb_frag_size(
  7432. &skb_shinfo(skb)->frags[f]));
  7433. if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
  7434. tx_ring->tx_stats.tx_busy++;
  7435. return NETDEV_TX_BUSY;
  7436. }
  7437. /* record the location of the first descriptor for this packet */
  7438. first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
  7439. first->skb = skb;
  7440. first->bytecount = skb->len;
  7441. first->gso_segs = 1;
  7442. /* if we have a HW VLAN tag being added default to the HW one */
  7443. if (skb_vlan_tag_present(skb)) {
  7444. tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
  7445. tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
  7446. /* else if it is a SW VLAN check the next protocol and store the tag */
  7447. } else if (protocol == htons(ETH_P_8021Q)) {
  7448. struct vlan_hdr *vhdr, _vhdr;
  7449. vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
  7450. if (!vhdr)
  7451. goto out_drop;
  7452. tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
  7453. IXGBE_TX_FLAGS_VLAN_SHIFT;
  7454. tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
  7455. }
  7456. protocol = vlan_get_protocol(skb);
  7457. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
  7458. adapter->ptp_clock) {
  7459. if (adapter->tstamp_config.tx_type == HWTSTAMP_TX_ON &&
  7460. !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
  7461. &adapter->state)) {
  7462. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  7463. tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
  7464. /* schedule check for Tx timestamp */
  7465. adapter->ptp_tx_skb = skb_get(skb);
  7466. adapter->ptp_tx_start = jiffies;
  7467. schedule_work(&adapter->ptp_tx_work);
  7468. } else {
  7469. adapter->tx_hwtstamp_skipped++;
  7470. }
  7471. }
  7472. #ifdef CONFIG_PCI_IOV
  7473. /*
  7474. * Use the l2switch_enable flag - would be false if the DMA
  7475. * Tx switch had been disabled.
  7476. */
  7477. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  7478. tx_flags |= IXGBE_TX_FLAGS_CC;
  7479. #endif
  7480. /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
  7481. if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
  7482. ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
  7483. (skb->priority != TC_PRIO_CONTROL))) {
  7484. tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
  7485. tx_flags |= (skb->priority & 0x7) <<
  7486. IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
  7487. if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
  7488. struct vlan_ethhdr *vhdr;
  7489. if (skb_cow_head(skb, 0))
  7490. goto out_drop;
  7491. vhdr = skb_vlan_eth_hdr(skb);
  7492. vhdr->h_vlan_TCI = htons(tx_flags >>
  7493. IXGBE_TX_FLAGS_VLAN_SHIFT);
  7494. } else {
  7495. tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
  7496. }
  7497. }
  7498. /* record initial flags and protocol */
  7499. first->tx_flags = tx_flags;
  7500. first->protocol = protocol;
  7501. #ifdef IXGBE_FCOE
  7502. /* setup tx offload for FCoE */
  7503. if ((protocol == htons(ETH_P_FCOE)) &&
  7504. (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
  7505. tso = ixgbe_fso(tx_ring, first, &hdr_len);
  7506. if (tso < 0)
  7507. goto out_drop;
  7508. goto xmit_fcoe;
  7509. }
  7510. #endif /* IXGBE_FCOE */
  7511. #ifdef CONFIG_IXGBE_IPSEC
  7512. if (xfrm_offload(skb) &&
  7513. !ixgbe_ipsec_tx(tx_ring, first, &ipsec_tx))
  7514. goto out_drop;
  7515. #endif
  7516. tso = ixgbe_tso(tx_ring, first, &hdr_len, &ipsec_tx);
  7517. if (tso < 0)
  7518. goto out_drop;
  7519. else if (!tso)
  7520. ixgbe_tx_csum(tx_ring, first, &ipsec_tx);
  7521. /* add the ATR filter if ATR is on */
  7522. if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
  7523. ixgbe_atr(tx_ring, first);
  7524. #ifdef IXGBE_FCOE
  7525. xmit_fcoe:
  7526. #endif /* IXGBE_FCOE */
  7527. if (ixgbe_tx_map(tx_ring, first, hdr_len))
  7528. goto cleanup_tx_timestamp;
  7529. return NETDEV_TX_OK;
  7530. out_drop:
  7531. dev_kfree_skb_any(first->skb);
  7532. first->skb = NULL;
  7533. cleanup_tx_timestamp:
  7534. if (unlikely(tx_flags & IXGBE_TX_FLAGS_TSTAMP)) {
  7535. dev_kfree_skb_any(adapter->ptp_tx_skb);
  7536. adapter->ptp_tx_skb = NULL;
  7537. cancel_work_sync(&adapter->ptp_tx_work);
  7538. clear_bit_unlock(__IXGBE_PTP_TX_IN_PROGRESS, &adapter->state);
  7539. }
  7540. return NETDEV_TX_OK;
  7541. }
  7542. static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
  7543. struct net_device *netdev,
  7544. struct ixgbe_ring *ring)
  7545. {
  7546. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7547. struct ixgbe_ring *tx_ring;
  7548. /*
  7549. * The minimum packet size for olinfo paylen is 17 so pad the skb
  7550. * in order to meet this minimum size requirement.
  7551. */
  7552. if (skb_put_padto(skb, 17))
  7553. return NETDEV_TX_OK;
  7554. tx_ring = ring ? ring : adapter->tx_ring[skb_get_queue_mapping(skb)];
  7555. if (unlikely(test_bit(__IXGBE_TX_DISABLED, &tx_ring->state)))
  7556. return NETDEV_TX_BUSY;
  7557. return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
  7558. }
  7559. static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
  7560. struct net_device *netdev)
  7561. {
  7562. return __ixgbe_xmit_frame(skb, netdev, NULL);
  7563. }
  7564. /**
  7565. * ixgbe_set_mac - Change the Ethernet Address of the NIC
  7566. * @netdev: network interface device structure
  7567. * @p: pointer to an address structure
  7568. *
  7569. * Returns 0 on success, negative on failure
  7570. **/
  7571. static int ixgbe_set_mac(struct net_device *netdev, void *p)
  7572. {
  7573. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7574. struct ixgbe_hw *hw = &adapter->hw;
  7575. struct sockaddr *addr = p;
  7576. if (!is_valid_ether_addr(addr->sa_data))
  7577. return -EADDRNOTAVAIL;
  7578. eth_hw_addr_set(netdev, addr->sa_data);
  7579. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  7580. ixgbe_mac_set_default_filter(adapter);
  7581. return 0;
  7582. }
  7583. static int
  7584. ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
  7585. {
  7586. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7587. struct ixgbe_hw *hw = &adapter->hw;
  7588. u16 value;
  7589. int rc;
  7590. if (adapter->mii_bus) {
  7591. int regnum = addr;
  7592. if (devad != MDIO_DEVAD_NONE)
  7593. return mdiobus_c45_read(adapter->mii_bus, prtad,
  7594. devad, regnum);
  7595. return mdiobus_read(adapter->mii_bus, prtad, regnum);
  7596. }
  7597. if (prtad != hw->phy.mdio.prtad)
  7598. return -EINVAL;
  7599. rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
  7600. if (!rc)
  7601. rc = value;
  7602. return rc;
  7603. }
  7604. static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
  7605. u16 addr, u16 value)
  7606. {
  7607. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7608. struct ixgbe_hw *hw = &adapter->hw;
  7609. if (adapter->mii_bus) {
  7610. int regnum = addr;
  7611. if (devad != MDIO_DEVAD_NONE)
  7612. return mdiobus_c45_write(adapter->mii_bus, prtad, devad,
  7613. regnum, value);
  7614. return mdiobus_write(adapter->mii_bus, prtad, regnum, value);
  7615. }
  7616. if (prtad != hw->phy.mdio.prtad)
  7617. return -EINVAL;
  7618. return hw->phy.ops.write_reg(hw, addr, devad, value);
  7619. }
  7620. static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
  7621. {
  7622. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7623. switch (cmd) {
  7624. case SIOCSHWTSTAMP:
  7625. return ixgbe_ptp_set_ts_config(adapter, req);
  7626. case SIOCGHWTSTAMP:
  7627. return ixgbe_ptp_get_ts_config(adapter, req);
  7628. case SIOCGMIIPHY:
  7629. if (!adapter->hw.phy.ops.read_reg)
  7630. return -EOPNOTSUPP;
  7631. fallthrough;
  7632. default:
  7633. return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
  7634. }
  7635. }
  7636. /**
  7637. * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
  7638. * netdev->dev_addrs
  7639. * @dev: network interface device structure
  7640. *
  7641. * Returns non-zero on failure
  7642. **/
  7643. static int ixgbe_add_sanmac_netdev(struct net_device *dev)
  7644. {
  7645. int err = 0;
  7646. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7647. struct ixgbe_hw *hw = &adapter->hw;
  7648. if (is_valid_ether_addr(hw->mac.san_addr)) {
  7649. rtnl_lock();
  7650. err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
  7651. rtnl_unlock();
  7652. /* update SAN MAC vmdq pool selection */
  7653. hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
  7654. }
  7655. return err;
  7656. }
  7657. /**
  7658. * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
  7659. * netdev->dev_addrs
  7660. * @dev: network interface device structure
  7661. *
  7662. * Returns non-zero on failure
  7663. **/
  7664. static int ixgbe_del_sanmac_netdev(struct net_device *dev)
  7665. {
  7666. int err = 0;
  7667. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7668. struct ixgbe_mac_info *mac = &adapter->hw.mac;
  7669. if (is_valid_ether_addr(mac->san_addr)) {
  7670. rtnl_lock();
  7671. err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
  7672. rtnl_unlock();
  7673. }
  7674. return err;
  7675. }
  7676. static void ixgbe_get_ring_stats64(struct rtnl_link_stats64 *stats,
  7677. struct ixgbe_ring *ring)
  7678. {
  7679. u64 bytes, packets;
  7680. unsigned int start;
  7681. if (ring) {
  7682. do {
  7683. start = u64_stats_fetch_begin(&ring->syncp);
  7684. packets = ring->stats.packets;
  7685. bytes = ring->stats.bytes;
  7686. } while (u64_stats_fetch_retry(&ring->syncp, start));
  7687. stats->tx_packets += packets;
  7688. stats->tx_bytes += bytes;
  7689. }
  7690. }
  7691. static void ixgbe_get_stats64(struct net_device *netdev,
  7692. struct rtnl_link_stats64 *stats)
  7693. {
  7694. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7695. int i;
  7696. rcu_read_lock();
  7697. for (i = 0; i < adapter->num_rx_queues; i++) {
  7698. struct ixgbe_ring *ring = READ_ONCE(adapter->rx_ring[i]);
  7699. u64 bytes, packets;
  7700. unsigned int start;
  7701. if (ring) {
  7702. do {
  7703. start = u64_stats_fetch_begin(&ring->syncp);
  7704. packets = ring->stats.packets;
  7705. bytes = ring->stats.bytes;
  7706. } while (u64_stats_fetch_retry(&ring->syncp, start));
  7707. stats->rx_packets += packets;
  7708. stats->rx_bytes += bytes;
  7709. }
  7710. }
  7711. for (i = 0; i < adapter->num_tx_queues; i++) {
  7712. struct ixgbe_ring *ring = READ_ONCE(adapter->tx_ring[i]);
  7713. ixgbe_get_ring_stats64(stats, ring);
  7714. }
  7715. for (i = 0; i < adapter->num_xdp_queues; i++) {
  7716. struct ixgbe_ring *ring = READ_ONCE(adapter->xdp_ring[i]);
  7717. ixgbe_get_ring_stats64(stats, ring);
  7718. }
  7719. rcu_read_unlock();
  7720. /* following stats updated by ixgbe_watchdog_task() */
  7721. stats->multicast = netdev->stats.multicast;
  7722. stats->rx_errors = netdev->stats.rx_errors;
  7723. stats->rx_length_errors = netdev->stats.rx_length_errors;
  7724. stats->rx_crc_errors = netdev->stats.rx_crc_errors;
  7725. stats->rx_missed_errors = netdev->stats.rx_missed_errors;
  7726. }
  7727. static int ixgbe_ndo_get_vf_stats(struct net_device *netdev, int vf,
  7728. struct ifla_vf_stats *vf_stats)
  7729. {
  7730. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7731. if (vf < 0 || vf >= adapter->num_vfs)
  7732. return -EINVAL;
  7733. vf_stats->rx_packets = adapter->vfinfo[vf].vfstats.gprc;
  7734. vf_stats->rx_bytes = adapter->vfinfo[vf].vfstats.gorc;
  7735. vf_stats->tx_packets = adapter->vfinfo[vf].vfstats.gptc;
  7736. vf_stats->tx_bytes = adapter->vfinfo[vf].vfstats.gotc;
  7737. vf_stats->multicast = adapter->vfinfo[vf].vfstats.mprc;
  7738. return 0;
  7739. }
  7740. #ifdef CONFIG_IXGBE_DCB
  7741. /**
  7742. * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
  7743. * @adapter: pointer to ixgbe_adapter
  7744. * @tc: number of traffic classes currently enabled
  7745. *
  7746. * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
  7747. * 802.1Q priority maps to a packet buffer that exists.
  7748. */
  7749. static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
  7750. {
  7751. struct ixgbe_hw *hw = &adapter->hw;
  7752. u32 reg, rsave;
  7753. int i;
  7754. /* 82598 have a static priority to TC mapping that can not
  7755. * be changed so no validation is needed.
  7756. */
  7757. if (hw->mac.type == ixgbe_mac_82598EB)
  7758. return;
  7759. reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
  7760. rsave = reg;
  7761. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  7762. u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
  7763. /* If up2tc is out of bounds default to zero */
  7764. if (up2tc > tc)
  7765. reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
  7766. }
  7767. if (reg != rsave)
  7768. IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
  7769. return;
  7770. }
  7771. /**
  7772. * ixgbe_set_prio_tc_map - Configure netdev prio tc map
  7773. * @adapter: Pointer to adapter struct
  7774. *
  7775. * Populate the netdev user priority to tc map
  7776. */
  7777. static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
  7778. {
  7779. struct net_device *dev = adapter->netdev;
  7780. struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
  7781. struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
  7782. u8 prio;
  7783. for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
  7784. u8 tc = 0;
  7785. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
  7786. tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
  7787. else if (ets)
  7788. tc = ets->prio_tc[prio];
  7789. netdev_set_prio_tc_map(dev, prio, tc);
  7790. }
  7791. }
  7792. #endif /* CONFIG_IXGBE_DCB */
  7793. static int ixgbe_reassign_macvlan_pool(struct net_device *vdev,
  7794. struct netdev_nested_priv *priv)
  7795. {
  7796. struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)priv->data;
  7797. struct ixgbe_fwd_adapter *accel;
  7798. int pool;
  7799. /* we only care about macvlans... */
  7800. if (!netif_is_macvlan(vdev))
  7801. return 0;
  7802. /* that have hardware offload enabled... */
  7803. accel = macvlan_accel_priv(vdev);
  7804. if (!accel)
  7805. return 0;
  7806. /* If we can relocate to a different bit do so */
  7807. pool = find_first_zero_bit(adapter->fwd_bitmask, adapter->num_rx_pools);
  7808. if (pool < adapter->num_rx_pools) {
  7809. set_bit(pool, adapter->fwd_bitmask);
  7810. accel->pool = pool;
  7811. return 0;
  7812. }
  7813. /* if we cannot find a free pool then disable the offload */
  7814. netdev_err(vdev, "L2FW offload disabled due to lack of queue resources\n");
  7815. macvlan_release_l2fw_offload(vdev);
  7816. /* unbind the queues and drop the subordinate channel config */
  7817. netdev_unbind_sb_channel(adapter->netdev, vdev);
  7818. netdev_set_sb_channel(vdev, 0);
  7819. kfree(accel);
  7820. return 0;
  7821. }
  7822. static void ixgbe_defrag_macvlan_pools(struct net_device *dev)
  7823. {
  7824. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7825. struct netdev_nested_priv priv = {
  7826. .data = (void *)adapter,
  7827. };
  7828. /* flush any stale bits out of the fwd bitmask */
  7829. bitmap_clear(adapter->fwd_bitmask, 1, 63);
  7830. /* walk through upper devices reassigning pools */
  7831. netdev_walk_all_upper_dev_rcu(dev, ixgbe_reassign_macvlan_pool,
  7832. &priv);
  7833. }
  7834. /**
  7835. * ixgbe_setup_tc - configure net_device for multiple traffic classes
  7836. *
  7837. * @dev: net device to configure
  7838. * @tc: number of traffic classes to enable
  7839. */
  7840. int ixgbe_setup_tc(struct net_device *dev, u8 tc)
  7841. {
  7842. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7843. struct ixgbe_hw *hw = &adapter->hw;
  7844. /* Hardware supports up to 8 traffic classes */
  7845. if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
  7846. return -EINVAL;
  7847. if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
  7848. return -EINVAL;
  7849. /* Hardware has to reinitialize queues and interrupts to
  7850. * match packet buffer alignment. Unfortunately, the
  7851. * hardware is not flexible enough to do this dynamically.
  7852. */
  7853. if (netif_running(dev))
  7854. ixgbe_close(dev);
  7855. else
  7856. ixgbe_reset(adapter);
  7857. ixgbe_clear_interrupt_scheme(adapter);
  7858. #ifdef CONFIG_IXGBE_DCB
  7859. if (tc) {
  7860. if (adapter->xdp_prog) {
  7861. e_warn(probe, "DCB is not supported with XDP\n");
  7862. ixgbe_init_interrupt_scheme(adapter);
  7863. if (netif_running(dev))
  7864. ixgbe_open(dev);
  7865. return -EINVAL;
  7866. }
  7867. netdev_set_num_tc(dev, tc);
  7868. ixgbe_set_prio_tc_map(adapter);
  7869. adapter->hw_tcs = tc;
  7870. adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
  7871. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  7872. adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
  7873. adapter->hw.fc.requested_mode = ixgbe_fc_none;
  7874. }
  7875. } else {
  7876. netdev_reset_tc(dev);
  7877. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  7878. adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
  7879. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  7880. adapter->hw_tcs = tc;
  7881. adapter->temp_dcb_cfg.pfc_mode_enable = false;
  7882. adapter->dcb_cfg.pfc_mode_enable = false;
  7883. }
  7884. ixgbe_validate_rtr(adapter, tc);
  7885. #endif /* CONFIG_IXGBE_DCB */
  7886. ixgbe_init_interrupt_scheme(adapter);
  7887. ixgbe_defrag_macvlan_pools(dev);
  7888. if (netif_running(dev))
  7889. return ixgbe_open(dev);
  7890. return 0;
  7891. }
  7892. static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
  7893. struct tc_cls_u32_offload *cls)
  7894. {
  7895. u32 hdl = cls->knode.handle;
  7896. u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
  7897. u32 loc = cls->knode.handle & 0xfffff;
  7898. int err = 0, i, j;
  7899. struct ixgbe_jump_table *jump = NULL;
  7900. if (loc > IXGBE_MAX_HW_ENTRIES)
  7901. return -EINVAL;
  7902. if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
  7903. return -EINVAL;
  7904. /* Clear this filter in the link data it is associated with */
  7905. if (uhtid != 0x800) {
  7906. jump = adapter->jump_tables[uhtid];
  7907. if (!jump)
  7908. return -EINVAL;
  7909. if (!test_bit(loc - 1, jump->child_loc_map))
  7910. return -EINVAL;
  7911. clear_bit(loc - 1, jump->child_loc_map);
  7912. }
  7913. /* Check if the filter being deleted is a link */
  7914. for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
  7915. jump = adapter->jump_tables[i];
  7916. if (jump && jump->link_hdl == hdl) {
  7917. /* Delete filters in the hardware in the child hash
  7918. * table associated with this link
  7919. */
  7920. for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) {
  7921. if (!test_bit(j, jump->child_loc_map))
  7922. continue;
  7923. spin_lock(&adapter->fdir_perfect_lock);
  7924. err = ixgbe_update_ethtool_fdir_entry(adapter,
  7925. NULL,
  7926. j + 1);
  7927. spin_unlock(&adapter->fdir_perfect_lock);
  7928. clear_bit(j, jump->child_loc_map);
  7929. }
  7930. /* Remove resources for this link */
  7931. kfree(jump->input);
  7932. kfree(jump->mask);
  7933. kfree(jump);
  7934. adapter->jump_tables[i] = NULL;
  7935. return err;
  7936. }
  7937. }
  7938. spin_lock(&adapter->fdir_perfect_lock);
  7939. err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
  7940. spin_unlock(&adapter->fdir_perfect_lock);
  7941. return err;
  7942. }
  7943. static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
  7944. struct tc_cls_u32_offload *cls)
  7945. {
  7946. u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
  7947. if (uhtid >= IXGBE_MAX_LINK_HANDLE)
  7948. return -EINVAL;
  7949. /* This ixgbe devices do not support hash tables at the moment
  7950. * so abort when given hash tables.
  7951. */
  7952. if (cls->hnode.divisor > 0)
  7953. return -EINVAL;
  7954. set_bit(uhtid - 1, &adapter->tables);
  7955. return 0;
  7956. }
  7957. static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
  7958. struct tc_cls_u32_offload *cls)
  7959. {
  7960. u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
  7961. if (uhtid >= IXGBE_MAX_LINK_HANDLE)
  7962. return -EINVAL;
  7963. clear_bit(uhtid - 1, &adapter->tables);
  7964. return 0;
  7965. }
  7966. #ifdef CONFIG_NET_CLS_ACT
  7967. struct upper_walk_data {
  7968. struct ixgbe_adapter *adapter;
  7969. u64 action;
  7970. int ifindex;
  7971. u8 queue;
  7972. };
  7973. static int get_macvlan_queue(struct net_device *upper,
  7974. struct netdev_nested_priv *priv)
  7975. {
  7976. if (netif_is_macvlan(upper)) {
  7977. struct ixgbe_fwd_adapter *vadapter = macvlan_accel_priv(upper);
  7978. struct ixgbe_adapter *adapter;
  7979. struct upper_walk_data *data;
  7980. int ifindex;
  7981. data = (struct upper_walk_data *)priv->data;
  7982. ifindex = data->ifindex;
  7983. adapter = data->adapter;
  7984. if (vadapter && upper->ifindex == ifindex) {
  7985. data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
  7986. data->action = data->queue;
  7987. return 1;
  7988. }
  7989. }
  7990. return 0;
  7991. }
  7992. static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
  7993. u8 *queue, u64 *action)
  7994. {
  7995. struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
  7996. unsigned int num_vfs = adapter->num_vfs, vf;
  7997. struct netdev_nested_priv priv;
  7998. struct upper_walk_data data;
  7999. struct net_device *upper;
  8000. /* redirect to a SRIOV VF */
  8001. for (vf = 0; vf < num_vfs; ++vf) {
  8002. upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
  8003. if (upper->ifindex == ifindex) {
  8004. *queue = vf * __ALIGN_MASK(1, ~vmdq->mask);
  8005. *action = vf + 1;
  8006. *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
  8007. return 0;
  8008. }
  8009. }
  8010. /* redirect to a offloaded macvlan netdev */
  8011. data.adapter = adapter;
  8012. data.ifindex = ifindex;
  8013. data.action = 0;
  8014. data.queue = 0;
  8015. priv.data = (void *)&data;
  8016. if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
  8017. get_macvlan_queue, &priv)) {
  8018. *action = data.action;
  8019. *queue = data.queue;
  8020. return 0;
  8021. }
  8022. return -EINVAL;
  8023. }
  8024. static int parse_tc_actions(struct ixgbe_adapter *adapter,
  8025. struct tcf_exts *exts, u64 *action, u8 *queue)
  8026. {
  8027. const struct tc_action *a;
  8028. int i;
  8029. if (!tcf_exts_has_actions(exts))
  8030. return -EINVAL;
  8031. tcf_exts_for_each_action(i, a, exts) {
  8032. /* Drop action */
  8033. if (is_tcf_gact_shot(a)) {
  8034. *action = IXGBE_FDIR_DROP_QUEUE;
  8035. *queue = IXGBE_FDIR_DROP_QUEUE;
  8036. return 0;
  8037. }
  8038. /* Redirect to a VF or a offloaded macvlan */
  8039. if (is_tcf_mirred_egress_redirect(a)) {
  8040. struct net_device *dev = tcf_mirred_dev(a);
  8041. if (!dev)
  8042. return -EINVAL;
  8043. return handle_redirect_action(adapter, dev->ifindex,
  8044. queue, action);
  8045. }
  8046. return -EINVAL;
  8047. }
  8048. return -EINVAL;
  8049. }
  8050. #else
  8051. static int parse_tc_actions(struct ixgbe_adapter *adapter,
  8052. struct tcf_exts *exts, u64 *action, u8 *queue)
  8053. {
  8054. return -EINVAL;
  8055. }
  8056. #endif /* CONFIG_NET_CLS_ACT */
  8057. static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input,
  8058. union ixgbe_atr_input *mask,
  8059. struct tc_cls_u32_offload *cls,
  8060. struct ixgbe_mat_field *field_ptr,
  8061. struct ixgbe_nexthdr *nexthdr)
  8062. {
  8063. int i, j, off;
  8064. __be32 val, m;
  8065. bool found_entry = false, found_jump_field = false;
  8066. for (i = 0; i < cls->knode.sel->nkeys; i++) {
  8067. off = cls->knode.sel->keys[i].off;
  8068. val = cls->knode.sel->keys[i].val;
  8069. m = cls->knode.sel->keys[i].mask;
  8070. for (j = 0; field_ptr[j].val; j++) {
  8071. if (field_ptr[j].off == off) {
  8072. field_ptr[j].val(input, mask, (__force u32)val,
  8073. (__force u32)m);
  8074. input->filter.formatted.flow_type |=
  8075. field_ptr[j].type;
  8076. found_entry = true;
  8077. break;
  8078. }
  8079. }
  8080. if (nexthdr) {
  8081. if (nexthdr->off == cls->knode.sel->keys[i].off &&
  8082. nexthdr->val ==
  8083. (__force u32)cls->knode.sel->keys[i].val &&
  8084. nexthdr->mask ==
  8085. (__force u32)cls->knode.sel->keys[i].mask)
  8086. found_jump_field = true;
  8087. else
  8088. continue;
  8089. }
  8090. }
  8091. if (nexthdr && !found_jump_field)
  8092. return -EINVAL;
  8093. if (!found_entry)
  8094. return 0;
  8095. mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
  8096. IXGBE_ATR_L4TYPE_MASK;
  8097. if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
  8098. mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
  8099. return 0;
  8100. }
  8101. static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
  8102. struct tc_cls_u32_offload *cls)
  8103. {
  8104. __be16 protocol = cls->common.protocol;
  8105. u32 loc = cls->knode.handle & 0xfffff;
  8106. struct ixgbe_hw *hw = &adapter->hw;
  8107. struct ixgbe_mat_field *field_ptr;
  8108. struct ixgbe_fdir_filter *input = NULL;
  8109. union ixgbe_atr_input *mask = NULL;
  8110. struct ixgbe_jump_table *jump = NULL;
  8111. int i, err = -EINVAL;
  8112. u8 queue;
  8113. u32 uhtid, link_uhtid;
  8114. uhtid = TC_U32_USERHTID(cls->knode.handle);
  8115. link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
  8116. /* At the moment cls_u32 jumps to network layer and skips past
  8117. * L2 headers. The canonical method to match L2 frames is to use
  8118. * negative values. However this is error prone at best but really
  8119. * just broken because there is no way to "know" what sort of hdr
  8120. * is in front of the network layer. Fix cls_u32 to support L2
  8121. * headers when needed.
  8122. */
  8123. if (protocol != htons(ETH_P_IP))
  8124. return err;
  8125. if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
  8126. e_err(drv, "Location out of range\n");
  8127. return err;
  8128. }
  8129. /* cls u32 is a graph starting at root node 0x800. The driver tracks
  8130. * links and also the fields used to advance the parser across each
  8131. * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
  8132. * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
  8133. * To add support for new nodes update ixgbe_model.h parse structures
  8134. * this function _should_ be generic try not to hardcode values here.
  8135. */
  8136. if (uhtid == 0x800) {
  8137. field_ptr = (adapter->jump_tables[0])->mat;
  8138. } else {
  8139. if (uhtid >= IXGBE_MAX_LINK_HANDLE)
  8140. return err;
  8141. if (!adapter->jump_tables[uhtid])
  8142. return err;
  8143. field_ptr = (adapter->jump_tables[uhtid])->mat;
  8144. }
  8145. if (!field_ptr)
  8146. return err;
  8147. /* At this point we know the field_ptr is valid and need to either
  8148. * build cls_u32 link or attach filter. Because adding a link to
  8149. * a handle that does not exist is invalid and the same for adding
  8150. * rules to handles that don't exist.
  8151. */
  8152. if (link_uhtid) {
  8153. struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
  8154. if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
  8155. return err;
  8156. if (!test_bit(link_uhtid - 1, &adapter->tables))
  8157. return err;
  8158. /* Multiple filters as links to the same hash table are not
  8159. * supported. To add a new filter with the same next header
  8160. * but different match/jump conditions, create a new hash table
  8161. * and link to it.
  8162. */
  8163. if (adapter->jump_tables[link_uhtid] &&
  8164. (adapter->jump_tables[link_uhtid])->link_hdl) {
  8165. e_err(drv, "Link filter exists for link: %x\n",
  8166. link_uhtid);
  8167. return err;
  8168. }
  8169. for (i = 0; nexthdr[i].jump; i++) {
  8170. if (nexthdr[i].o != cls->knode.sel->offoff ||
  8171. nexthdr[i].s != cls->knode.sel->offshift ||
  8172. nexthdr[i].m !=
  8173. (__force u32)cls->knode.sel->offmask)
  8174. return err;
  8175. jump = kzalloc(sizeof(*jump), GFP_KERNEL);
  8176. if (!jump)
  8177. return -ENOMEM;
  8178. input = kzalloc(sizeof(*input), GFP_KERNEL);
  8179. if (!input) {
  8180. err = -ENOMEM;
  8181. goto free_jump;
  8182. }
  8183. mask = kzalloc(sizeof(*mask), GFP_KERNEL);
  8184. if (!mask) {
  8185. err = -ENOMEM;
  8186. goto free_input;
  8187. }
  8188. jump->input = input;
  8189. jump->mask = mask;
  8190. jump->link_hdl = cls->knode.handle;
  8191. err = ixgbe_clsu32_build_input(input, mask, cls,
  8192. field_ptr, &nexthdr[i]);
  8193. if (!err) {
  8194. jump->mat = nexthdr[i].jump;
  8195. adapter->jump_tables[link_uhtid] = jump;
  8196. break;
  8197. } else {
  8198. kfree(mask);
  8199. kfree(input);
  8200. kfree(jump);
  8201. }
  8202. }
  8203. return 0;
  8204. }
  8205. input = kzalloc(sizeof(*input), GFP_KERNEL);
  8206. if (!input)
  8207. return -ENOMEM;
  8208. mask = kzalloc(sizeof(*mask), GFP_KERNEL);
  8209. if (!mask) {
  8210. err = -ENOMEM;
  8211. goto free_input;
  8212. }
  8213. if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) {
  8214. if ((adapter->jump_tables[uhtid])->input)
  8215. memcpy(input, (adapter->jump_tables[uhtid])->input,
  8216. sizeof(*input));
  8217. if ((adapter->jump_tables[uhtid])->mask)
  8218. memcpy(mask, (adapter->jump_tables[uhtid])->mask,
  8219. sizeof(*mask));
  8220. /* Lookup in all child hash tables if this location is already
  8221. * filled with a filter
  8222. */
  8223. for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
  8224. struct ixgbe_jump_table *link = adapter->jump_tables[i];
  8225. if (link && (test_bit(loc - 1, link->child_loc_map))) {
  8226. e_err(drv, "Filter exists in location: %x\n",
  8227. loc);
  8228. err = -EINVAL;
  8229. goto err_out;
  8230. }
  8231. }
  8232. }
  8233. err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL);
  8234. if (err)
  8235. goto err_out;
  8236. err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
  8237. &queue);
  8238. if (err < 0)
  8239. goto err_out;
  8240. input->sw_idx = loc;
  8241. spin_lock(&adapter->fdir_perfect_lock);
  8242. if (hlist_empty(&adapter->fdir_filter_list)) {
  8243. memcpy(&adapter->fdir_mask, mask, sizeof(*mask));
  8244. err = ixgbe_fdir_set_input_mask_82599(hw, mask);
  8245. if (err)
  8246. goto err_out_w_lock;
  8247. } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) {
  8248. err = -EINVAL;
  8249. goto err_out_w_lock;
  8250. }
  8251. ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask);
  8252. err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
  8253. input->sw_idx, queue);
  8254. if (err)
  8255. goto err_out_w_lock;
  8256. ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
  8257. spin_unlock(&adapter->fdir_perfect_lock);
  8258. if ((uhtid != 0x800) && (adapter->jump_tables[uhtid]))
  8259. set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map);
  8260. kfree(mask);
  8261. return err;
  8262. err_out_w_lock:
  8263. spin_unlock(&adapter->fdir_perfect_lock);
  8264. err_out:
  8265. kfree(mask);
  8266. free_input:
  8267. kfree(input);
  8268. free_jump:
  8269. kfree(jump);
  8270. return err;
  8271. }
  8272. static int ixgbe_setup_tc_cls_u32(struct ixgbe_adapter *adapter,
  8273. struct tc_cls_u32_offload *cls_u32)
  8274. {
  8275. switch (cls_u32->command) {
  8276. case TC_CLSU32_NEW_KNODE:
  8277. case TC_CLSU32_REPLACE_KNODE:
  8278. return ixgbe_configure_clsu32(adapter, cls_u32);
  8279. case TC_CLSU32_DELETE_KNODE:
  8280. return ixgbe_delete_clsu32(adapter, cls_u32);
  8281. case TC_CLSU32_NEW_HNODE:
  8282. case TC_CLSU32_REPLACE_HNODE:
  8283. return ixgbe_configure_clsu32_add_hnode(adapter, cls_u32);
  8284. case TC_CLSU32_DELETE_HNODE:
  8285. return ixgbe_configure_clsu32_del_hnode(adapter, cls_u32);
  8286. default:
  8287. return -EOPNOTSUPP;
  8288. }
  8289. }
  8290. static int ixgbe_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
  8291. void *cb_priv)
  8292. {
  8293. struct ixgbe_adapter *adapter = cb_priv;
  8294. if (!tc_cls_can_offload_and_chain0(adapter->netdev, type_data))
  8295. return -EOPNOTSUPP;
  8296. switch (type) {
  8297. case TC_SETUP_CLSU32:
  8298. return ixgbe_setup_tc_cls_u32(adapter, type_data);
  8299. default:
  8300. return -EOPNOTSUPP;
  8301. }
  8302. }
  8303. static int ixgbe_setup_tc_mqprio(struct net_device *dev,
  8304. struct tc_mqprio_qopt *mqprio)
  8305. {
  8306. mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
  8307. return ixgbe_setup_tc(dev, mqprio->num_tc);
  8308. }
  8309. static LIST_HEAD(ixgbe_block_cb_list);
  8310. static int __ixgbe_setup_tc(struct net_device *dev, enum tc_setup_type type,
  8311. void *type_data)
  8312. {
  8313. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8314. switch (type) {
  8315. case TC_SETUP_BLOCK:
  8316. return flow_block_cb_setup_simple(type_data,
  8317. &ixgbe_block_cb_list,
  8318. ixgbe_setup_tc_block_cb,
  8319. adapter, adapter, true);
  8320. case TC_SETUP_QDISC_MQPRIO:
  8321. return ixgbe_setup_tc_mqprio(dev, type_data);
  8322. default:
  8323. return -EOPNOTSUPP;
  8324. }
  8325. }
  8326. #ifdef CONFIG_PCI_IOV
  8327. void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
  8328. {
  8329. struct net_device *netdev = adapter->netdev;
  8330. rtnl_lock();
  8331. ixgbe_setup_tc(netdev, adapter->hw_tcs);
  8332. rtnl_unlock();
  8333. }
  8334. #endif
  8335. void ixgbe_do_reset(struct net_device *netdev)
  8336. {
  8337. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  8338. if (netif_running(netdev))
  8339. ixgbe_reinit_locked(adapter);
  8340. else
  8341. ixgbe_reset(adapter);
  8342. }
  8343. static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
  8344. netdev_features_t features)
  8345. {
  8346. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  8347. /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
  8348. if (!(features & NETIF_F_RXCSUM))
  8349. features &= ~NETIF_F_LRO;
  8350. /* Turn off LRO if not RSC capable */
  8351. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
  8352. features &= ~NETIF_F_LRO;
  8353. if (adapter->xdp_prog && (features & NETIF_F_LRO)) {
  8354. e_dev_err("LRO is not supported with XDP\n");
  8355. features &= ~NETIF_F_LRO;
  8356. }
  8357. return features;
  8358. }
  8359. static void ixgbe_reset_l2fw_offload(struct ixgbe_adapter *adapter)
  8360. {
  8361. int rss = min_t(int, ixgbe_max_rss_indices(adapter),
  8362. num_online_cpus());
  8363. /* go back to full RSS if we're not running SR-IOV */
  8364. if (!adapter->ring_feature[RING_F_VMDQ].offset)
  8365. adapter->flags &= ~(IXGBE_FLAG_VMDQ_ENABLED |
  8366. IXGBE_FLAG_SRIOV_ENABLED);
  8367. adapter->ring_feature[RING_F_RSS].limit = rss;
  8368. adapter->ring_feature[RING_F_VMDQ].limit = 1;
  8369. ixgbe_setup_tc(adapter->netdev, adapter->hw_tcs);
  8370. }
  8371. static int ixgbe_set_features(struct net_device *netdev,
  8372. netdev_features_t features)
  8373. {
  8374. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  8375. netdev_features_t changed = netdev->features ^ features;
  8376. bool need_reset = false;
  8377. /* Make sure RSC matches LRO, reset if change */
  8378. if (!(features & NETIF_F_LRO)) {
  8379. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  8380. need_reset = true;
  8381. adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
  8382. } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
  8383. !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
  8384. if (adapter->rx_itr_setting == 1 ||
  8385. adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
  8386. adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
  8387. need_reset = true;
  8388. } else if ((changed ^ features) & NETIF_F_LRO) {
  8389. e_info(probe, "rx-usecs set too low, "
  8390. "disabling RSC\n");
  8391. }
  8392. }
  8393. /*
  8394. * Check if Flow Director n-tuple support or hw_tc support was
  8395. * enabled or disabled. If the state changed, we need to reset.
  8396. */
  8397. if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
  8398. /* turn off ATR, enable perfect filters and reset */
  8399. if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
  8400. need_reset = true;
  8401. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  8402. adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  8403. } else {
  8404. /* turn off perfect filters, enable ATR and reset */
  8405. if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  8406. need_reset = true;
  8407. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  8408. /* We cannot enable ATR if SR-IOV is enabled */
  8409. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
  8410. /* We cannot enable ATR if we have 2 or more tcs */
  8411. (adapter->hw_tcs > 1) ||
  8412. /* We cannot enable ATR if RSS is disabled */
  8413. (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
  8414. /* A sample rate of 0 indicates ATR disabled */
  8415. (!adapter->atr_sample_rate))
  8416. ; /* do nothing not supported */
  8417. else /* otherwise supported and set the flag */
  8418. adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
  8419. }
  8420. if (changed & NETIF_F_RXALL)
  8421. need_reset = true;
  8422. netdev->features = features;
  8423. if ((changed & NETIF_F_HW_L2FW_DOFFLOAD) && adapter->num_rx_pools > 1)
  8424. ixgbe_reset_l2fw_offload(adapter);
  8425. else if (need_reset)
  8426. ixgbe_do_reset(netdev);
  8427. else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
  8428. NETIF_F_HW_VLAN_CTAG_FILTER))
  8429. ixgbe_set_rx_mode(netdev);
  8430. return 1;
  8431. }
  8432. static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  8433. struct net_device *dev,
  8434. const unsigned char *addr, u16 vid,
  8435. u16 flags,
  8436. struct netlink_ext_ack *extack)
  8437. {
  8438. /* guarantee we can provide a unique filter for the unicast address */
  8439. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
  8440. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8441. u16 pool = VMDQ_P(0);
  8442. if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
  8443. return -ENOMEM;
  8444. }
  8445. return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
  8446. }
  8447. /**
  8448. * ixgbe_configure_bridge_mode - set various bridge modes
  8449. * @adapter: the private structure
  8450. * @mode: requested bridge mode
  8451. *
  8452. * Configure some settings require for various bridge modes.
  8453. **/
  8454. static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
  8455. __u16 mode)
  8456. {
  8457. struct ixgbe_hw *hw = &adapter->hw;
  8458. unsigned int p, num_pools;
  8459. u32 vmdctl;
  8460. switch (mode) {
  8461. case BRIDGE_MODE_VEPA:
  8462. /* disable Tx loopback, rely on switch hairpin mode */
  8463. IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
  8464. /* must enable Rx switching replication to allow multicast
  8465. * packet reception on all VFs, and to enable source address
  8466. * pruning.
  8467. */
  8468. vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
  8469. vmdctl |= IXGBE_VT_CTL_REPLEN;
  8470. IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
  8471. /* enable Rx source address pruning. Note, this requires
  8472. * replication to be enabled or else it does nothing.
  8473. */
  8474. num_pools = adapter->num_vfs + adapter->num_rx_pools;
  8475. for (p = 0; p < num_pools; p++) {
  8476. if (hw->mac.ops.set_source_address_pruning)
  8477. hw->mac.ops.set_source_address_pruning(hw,
  8478. true,
  8479. p);
  8480. }
  8481. break;
  8482. case BRIDGE_MODE_VEB:
  8483. /* enable Tx loopback for internal VF/PF communication */
  8484. IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
  8485. IXGBE_PFDTXGSWC_VT_LBEN);
  8486. /* disable Rx switching replication unless we have SR-IOV
  8487. * virtual functions
  8488. */
  8489. vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
  8490. if (!adapter->num_vfs)
  8491. vmdctl &= ~IXGBE_VT_CTL_REPLEN;
  8492. IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
  8493. /* disable Rx source address pruning, since we don't expect to
  8494. * be receiving external loopback of our transmitted frames.
  8495. */
  8496. num_pools = adapter->num_vfs + adapter->num_rx_pools;
  8497. for (p = 0; p < num_pools; p++) {
  8498. if (hw->mac.ops.set_source_address_pruning)
  8499. hw->mac.ops.set_source_address_pruning(hw,
  8500. false,
  8501. p);
  8502. }
  8503. break;
  8504. default:
  8505. return -EINVAL;
  8506. }
  8507. adapter->bridge_mode = mode;
  8508. e_info(drv, "enabling bridge mode: %s\n",
  8509. mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  8510. return 0;
  8511. }
  8512. static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
  8513. struct nlmsghdr *nlh, u16 flags,
  8514. struct netlink_ext_ack *extack)
  8515. {
  8516. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8517. struct nlattr *attr, *br_spec;
  8518. int rem;
  8519. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  8520. return -EOPNOTSUPP;
  8521. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  8522. if (!br_spec)
  8523. return -EINVAL;
  8524. nla_for_each_nested_type(attr, IFLA_BRIDGE_MODE, br_spec, rem) {
  8525. __u16 mode = nla_get_u16(attr);
  8526. int status = ixgbe_configure_bridge_mode(adapter, mode);
  8527. if (status)
  8528. return status;
  8529. break;
  8530. }
  8531. return 0;
  8532. }
  8533. static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  8534. struct net_device *dev,
  8535. u32 filter_mask, int nlflags)
  8536. {
  8537. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8538. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  8539. return 0;
  8540. return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
  8541. adapter->bridge_mode, 0, 0, nlflags,
  8542. filter_mask, NULL);
  8543. }
  8544. static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
  8545. {
  8546. struct ixgbe_adapter *adapter = netdev_priv(pdev);
  8547. struct ixgbe_fwd_adapter *accel;
  8548. int tcs = adapter->hw_tcs ? : 1;
  8549. int pool, err;
  8550. if (adapter->xdp_prog) {
  8551. e_warn(probe, "L2FW offload is not supported with XDP\n");
  8552. return ERR_PTR(-EINVAL);
  8553. }
  8554. /* The hardware supported by ixgbe only filters on the destination MAC
  8555. * address. In order to avoid issues we only support offloading modes
  8556. * where the hardware can actually provide the functionality.
  8557. */
  8558. if (!macvlan_supports_dest_filter(vdev))
  8559. return ERR_PTR(-EMEDIUMTYPE);
  8560. /* We need to lock down the macvlan to be a single queue device so that
  8561. * we can reuse the tc_to_txq field in the macvlan netdev to represent
  8562. * the queue mapping to our netdev.
  8563. */
  8564. if (netif_is_multiqueue(vdev))
  8565. return ERR_PTR(-ERANGE);
  8566. pool = find_first_zero_bit(adapter->fwd_bitmask, adapter->num_rx_pools);
  8567. if (pool == adapter->num_rx_pools) {
  8568. u16 used_pools = adapter->num_vfs + adapter->num_rx_pools;
  8569. u16 reserved_pools;
  8570. if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
  8571. adapter->num_rx_pools >= (MAX_TX_QUEUES / tcs)) ||
  8572. adapter->num_rx_pools > IXGBE_MAX_MACVLANS)
  8573. return ERR_PTR(-EBUSY);
  8574. /* Hardware has a limited number of available pools. Each VF,
  8575. * and the PF require a pool. Check to ensure we don't
  8576. * attempt to use more then the available number of pools.
  8577. */
  8578. if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
  8579. return ERR_PTR(-EBUSY);
  8580. /* Enable VMDq flag so device will be set in VM mode */
  8581. adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED |
  8582. IXGBE_FLAG_SRIOV_ENABLED;
  8583. /* Try to reserve as many queues per pool as possible,
  8584. * we start with the configurations that support 4 queues
  8585. * per pools, followed by 2, and then by just 1 per pool.
  8586. */
  8587. if (used_pools < 32 && adapter->num_rx_pools < 16)
  8588. reserved_pools = min_t(u16,
  8589. 32 - used_pools,
  8590. 16 - adapter->num_rx_pools);
  8591. else if (adapter->num_rx_pools < 32)
  8592. reserved_pools = min_t(u16,
  8593. 64 - used_pools,
  8594. 32 - adapter->num_rx_pools);
  8595. else
  8596. reserved_pools = 64 - used_pools;
  8597. if (!reserved_pools)
  8598. return ERR_PTR(-EBUSY);
  8599. adapter->ring_feature[RING_F_VMDQ].limit += reserved_pools;
  8600. /* Force reinit of ring allocation with VMDQ enabled */
  8601. err = ixgbe_setup_tc(pdev, adapter->hw_tcs);
  8602. if (err)
  8603. return ERR_PTR(err);
  8604. if (pool >= adapter->num_rx_pools)
  8605. return ERR_PTR(-ENOMEM);
  8606. }
  8607. accel = kzalloc(sizeof(*accel), GFP_KERNEL);
  8608. if (!accel)
  8609. return ERR_PTR(-ENOMEM);
  8610. set_bit(pool, adapter->fwd_bitmask);
  8611. netdev_set_sb_channel(vdev, pool);
  8612. accel->pool = pool;
  8613. accel->netdev = vdev;
  8614. if (!netif_running(pdev))
  8615. return accel;
  8616. err = ixgbe_fwd_ring_up(adapter, accel);
  8617. if (err)
  8618. return ERR_PTR(err);
  8619. return accel;
  8620. }
  8621. static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
  8622. {
  8623. struct ixgbe_fwd_adapter *accel = priv;
  8624. struct ixgbe_adapter *adapter = netdev_priv(pdev);
  8625. unsigned int rxbase = accel->rx_base_queue;
  8626. unsigned int i;
  8627. /* delete unicast filter associated with offloaded interface */
  8628. ixgbe_del_mac_filter(adapter, accel->netdev->dev_addr,
  8629. VMDQ_P(accel->pool));
  8630. /* Allow remaining Rx packets to get flushed out of the
  8631. * Rx FIFO before we drop the netdev for the ring.
  8632. */
  8633. usleep_range(10000, 20000);
  8634. for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
  8635. struct ixgbe_ring *ring = adapter->rx_ring[rxbase + i];
  8636. struct ixgbe_q_vector *qv = ring->q_vector;
  8637. /* Make sure we aren't processing any packets and clear
  8638. * netdev to shut down the ring.
  8639. */
  8640. if (netif_running(adapter->netdev))
  8641. napi_synchronize(&qv->napi);
  8642. ring->netdev = NULL;
  8643. }
  8644. /* unbind the queues and drop the subordinate channel config */
  8645. netdev_unbind_sb_channel(pdev, accel->netdev);
  8646. netdev_set_sb_channel(accel->netdev, 0);
  8647. clear_bit(accel->pool, adapter->fwd_bitmask);
  8648. kfree(accel);
  8649. }
  8650. #define IXGBE_MAX_MAC_HDR_LEN 127
  8651. #define IXGBE_MAX_NETWORK_HDR_LEN 511
  8652. static netdev_features_t
  8653. ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
  8654. netdev_features_t features)
  8655. {
  8656. unsigned int network_hdr_len, mac_hdr_len;
  8657. /* Make certain the headers can be described by a context descriptor */
  8658. mac_hdr_len = skb_network_offset(skb);
  8659. if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN))
  8660. return features & ~(NETIF_F_HW_CSUM |
  8661. NETIF_F_SCTP_CRC |
  8662. NETIF_F_GSO_UDP_L4 |
  8663. NETIF_F_HW_VLAN_CTAG_TX |
  8664. NETIF_F_TSO |
  8665. NETIF_F_TSO6);
  8666. network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
  8667. if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN))
  8668. return features & ~(NETIF_F_HW_CSUM |
  8669. NETIF_F_SCTP_CRC |
  8670. NETIF_F_GSO_UDP_L4 |
  8671. NETIF_F_TSO |
  8672. NETIF_F_TSO6);
  8673. /* We can only support IPV4 TSO in tunnels if we can mangle the
  8674. * inner IP ID field, so strip TSO if MANGLEID is not supported.
  8675. * IPsec offoad sets skb->encapsulation but still can handle
  8676. * the TSO, so it's the exception.
  8677. */
  8678. if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID)) {
  8679. #ifdef CONFIG_IXGBE_IPSEC
  8680. if (!secpath_exists(skb))
  8681. #endif
  8682. features &= ~NETIF_F_TSO;
  8683. }
  8684. return features;
  8685. }
  8686. static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)
  8687. {
  8688. int i, frame_size = dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  8689. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8690. struct bpf_prog *old_prog;
  8691. bool need_reset;
  8692. int num_queues;
  8693. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  8694. return -EINVAL;
  8695. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
  8696. return -EINVAL;
  8697. /* verify ixgbe ring attributes are sufficient for XDP */
  8698. for (i = 0; i < adapter->num_rx_queues; i++) {
  8699. struct ixgbe_ring *ring = adapter->rx_ring[i];
  8700. if (ring_is_rsc_enabled(ring))
  8701. return -EINVAL;
  8702. if (frame_size > ixgbe_rx_bufsz(ring))
  8703. return -EINVAL;
  8704. }
  8705. /* if the number of cpus is much larger than the maximum of queues,
  8706. * we should stop it and then return with ENOMEM like before.
  8707. */
  8708. if (nr_cpu_ids > IXGBE_MAX_XDP_QS * 2)
  8709. return -ENOMEM;
  8710. old_prog = xchg(&adapter->xdp_prog, prog);
  8711. need_reset = (!!prog != !!old_prog);
  8712. /* If transitioning XDP modes reconfigure rings */
  8713. if (need_reset) {
  8714. int err;
  8715. if (!prog)
  8716. /* Wait until ndo_xsk_wakeup completes. */
  8717. synchronize_rcu();
  8718. err = ixgbe_setup_tc(dev, adapter->hw_tcs);
  8719. if (err)
  8720. return -EINVAL;
  8721. if (!prog)
  8722. xdp_features_clear_redirect_target(dev);
  8723. } else {
  8724. for (i = 0; i < adapter->num_rx_queues; i++) {
  8725. WRITE_ONCE(adapter->rx_ring[i]->xdp_prog,
  8726. adapter->xdp_prog);
  8727. }
  8728. }
  8729. if (old_prog)
  8730. bpf_prog_put(old_prog);
  8731. /* Kick start the NAPI context if there is an AF_XDP socket open
  8732. * on that queue id. This so that receiving will start.
  8733. */
  8734. if (need_reset && prog) {
  8735. num_queues = min_t(int, adapter->num_rx_queues,
  8736. adapter->num_xdp_queues);
  8737. for (i = 0; i < num_queues; i++)
  8738. if (adapter->xdp_ring[i]->xsk_pool)
  8739. (void)ixgbe_xsk_wakeup(adapter->netdev, i,
  8740. XDP_WAKEUP_RX);
  8741. xdp_features_set_redirect_target(dev, true);
  8742. }
  8743. return 0;
  8744. }
  8745. static int ixgbe_xdp(struct net_device *dev, struct netdev_bpf *xdp)
  8746. {
  8747. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8748. switch (xdp->command) {
  8749. case XDP_SETUP_PROG:
  8750. return ixgbe_xdp_setup(dev, xdp->prog);
  8751. case XDP_SETUP_XSK_POOL:
  8752. return ixgbe_xsk_pool_setup(adapter, xdp->xsk.pool,
  8753. xdp->xsk.queue_id);
  8754. default:
  8755. return -EINVAL;
  8756. }
  8757. }
  8758. void ixgbe_xdp_ring_update_tail(struct ixgbe_ring *ring)
  8759. {
  8760. /* Force memory writes to complete before letting h/w know there
  8761. * are new descriptors to fetch.
  8762. */
  8763. wmb();
  8764. writel(ring->next_to_use, ring->tail);
  8765. }
  8766. void ixgbe_xdp_ring_update_tail_locked(struct ixgbe_ring *ring)
  8767. {
  8768. if (static_branch_unlikely(&ixgbe_xdp_locking_key))
  8769. spin_lock(&ring->tx_lock);
  8770. ixgbe_xdp_ring_update_tail(ring);
  8771. if (static_branch_unlikely(&ixgbe_xdp_locking_key))
  8772. spin_unlock(&ring->tx_lock);
  8773. }
  8774. static int ixgbe_xdp_xmit(struct net_device *dev, int n,
  8775. struct xdp_frame **frames, u32 flags)
  8776. {
  8777. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8778. struct ixgbe_ring *ring;
  8779. int nxmit = 0;
  8780. int i;
  8781. if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state)))
  8782. return -ENETDOWN;
  8783. if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
  8784. return -EINVAL;
  8785. /* During program transitions its possible adapter->xdp_prog is assigned
  8786. * but ring has not been configured yet. In this case simply abort xmit.
  8787. */
  8788. ring = adapter->xdp_prog ? ixgbe_determine_xdp_ring(adapter) : NULL;
  8789. if (unlikely(!ring))
  8790. return -ENXIO;
  8791. if (unlikely(test_bit(__IXGBE_TX_DISABLED, &ring->state)))
  8792. return -ENXIO;
  8793. if (static_branch_unlikely(&ixgbe_xdp_locking_key))
  8794. spin_lock(&ring->tx_lock);
  8795. for (i = 0; i < n; i++) {
  8796. struct xdp_frame *xdpf = frames[i];
  8797. int err;
  8798. err = ixgbe_xmit_xdp_ring(ring, xdpf);
  8799. if (err != IXGBE_XDP_TX)
  8800. break;
  8801. nxmit++;
  8802. }
  8803. if (unlikely(flags & XDP_XMIT_FLUSH))
  8804. ixgbe_xdp_ring_update_tail(ring);
  8805. if (static_branch_unlikely(&ixgbe_xdp_locking_key))
  8806. spin_unlock(&ring->tx_lock);
  8807. return nxmit;
  8808. }
  8809. static const struct net_device_ops ixgbe_netdev_ops = {
  8810. .ndo_open = ixgbe_open,
  8811. .ndo_stop = ixgbe_close,
  8812. .ndo_start_xmit = ixgbe_xmit_frame,
  8813. .ndo_set_rx_mode = ixgbe_set_rx_mode,
  8814. .ndo_validate_addr = eth_validate_addr,
  8815. .ndo_set_mac_address = ixgbe_set_mac,
  8816. .ndo_change_mtu = ixgbe_change_mtu,
  8817. .ndo_tx_timeout = ixgbe_tx_timeout,
  8818. .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
  8819. .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
  8820. .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
  8821. .ndo_eth_ioctl = ixgbe_ioctl,
  8822. .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
  8823. .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
  8824. .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
  8825. .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
  8826. .ndo_set_vf_link_state = ixgbe_ndo_set_vf_link_state,
  8827. .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
  8828. .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
  8829. .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
  8830. .ndo_get_vf_stats = ixgbe_ndo_get_vf_stats,
  8831. .ndo_get_stats64 = ixgbe_get_stats64,
  8832. .ndo_setup_tc = __ixgbe_setup_tc,
  8833. #ifdef IXGBE_FCOE
  8834. .ndo_select_queue = ixgbe_select_queue,
  8835. .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
  8836. .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
  8837. .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
  8838. .ndo_fcoe_enable = ixgbe_fcoe_enable,
  8839. .ndo_fcoe_disable = ixgbe_fcoe_disable,
  8840. .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
  8841. .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
  8842. #endif /* IXGBE_FCOE */
  8843. .ndo_set_features = ixgbe_set_features,
  8844. .ndo_fix_features = ixgbe_fix_features,
  8845. .ndo_fdb_add = ixgbe_ndo_fdb_add,
  8846. .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
  8847. .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
  8848. .ndo_dfwd_add_station = ixgbe_fwd_add,
  8849. .ndo_dfwd_del_station = ixgbe_fwd_del,
  8850. .ndo_features_check = ixgbe_features_check,
  8851. .ndo_bpf = ixgbe_xdp,
  8852. .ndo_xdp_xmit = ixgbe_xdp_xmit,
  8853. .ndo_xsk_wakeup = ixgbe_xsk_wakeup,
  8854. };
  8855. static void ixgbe_disable_txr_hw(struct ixgbe_adapter *adapter,
  8856. struct ixgbe_ring *tx_ring)
  8857. {
  8858. unsigned long wait_delay, delay_interval;
  8859. struct ixgbe_hw *hw = &adapter->hw;
  8860. u8 reg_idx = tx_ring->reg_idx;
  8861. int wait_loop;
  8862. u32 txdctl;
  8863. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
  8864. /* delay mechanism from ixgbe_disable_tx */
  8865. delay_interval = ixgbe_get_completion_timeout(adapter) / 100;
  8866. wait_loop = IXGBE_MAX_RX_DESC_POLL;
  8867. wait_delay = delay_interval;
  8868. while (wait_loop--) {
  8869. usleep_range(wait_delay, wait_delay + 10);
  8870. wait_delay += delay_interval * 2;
  8871. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
  8872. if (!(txdctl & IXGBE_TXDCTL_ENABLE))
  8873. return;
  8874. }
  8875. e_err(drv, "TXDCTL.ENABLE not cleared within the polling period\n");
  8876. }
  8877. static void ixgbe_disable_txr(struct ixgbe_adapter *adapter,
  8878. struct ixgbe_ring *tx_ring)
  8879. {
  8880. set_bit(__IXGBE_TX_DISABLED, &tx_ring->state);
  8881. ixgbe_disable_txr_hw(adapter, tx_ring);
  8882. }
  8883. static void ixgbe_disable_rxr_hw(struct ixgbe_adapter *adapter,
  8884. struct ixgbe_ring *rx_ring)
  8885. {
  8886. unsigned long wait_delay, delay_interval;
  8887. struct ixgbe_hw *hw = &adapter->hw;
  8888. u8 reg_idx = rx_ring->reg_idx;
  8889. int wait_loop;
  8890. u32 rxdctl;
  8891. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  8892. rxdctl &= ~IXGBE_RXDCTL_ENABLE;
  8893. rxdctl |= IXGBE_RXDCTL_SWFLSH;
  8894. /* write value back with RXDCTL.ENABLE bit cleared */
  8895. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  8896. /* RXDCTL.EN may not change on 82598 if link is down, so skip it */
  8897. if (hw->mac.type == ixgbe_mac_82598EB &&
  8898. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  8899. return;
  8900. /* delay mechanism from ixgbe_disable_rx */
  8901. delay_interval = ixgbe_get_completion_timeout(adapter) / 100;
  8902. wait_loop = IXGBE_MAX_RX_DESC_POLL;
  8903. wait_delay = delay_interval;
  8904. while (wait_loop--) {
  8905. usleep_range(wait_delay, wait_delay + 10);
  8906. wait_delay += delay_interval * 2;
  8907. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  8908. if (!(rxdctl & IXGBE_RXDCTL_ENABLE))
  8909. return;
  8910. }
  8911. e_err(drv, "RXDCTL.ENABLE not cleared within the polling period\n");
  8912. }
  8913. static void ixgbe_reset_txr_stats(struct ixgbe_ring *tx_ring)
  8914. {
  8915. memset(&tx_ring->stats, 0, sizeof(tx_ring->stats));
  8916. memset(&tx_ring->tx_stats, 0, sizeof(tx_ring->tx_stats));
  8917. }
  8918. static void ixgbe_reset_rxr_stats(struct ixgbe_ring *rx_ring)
  8919. {
  8920. memset(&rx_ring->stats, 0, sizeof(rx_ring->stats));
  8921. memset(&rx_ring->rx_stats, 0, sizeof(rx_ring->rx_stats));
  8922. }
  8923. /**
  8924. * ixgbe_irq_disable_single - Disable single IRQ vector
  8925. * @adapter: adapter structure
  8926. * @ring: ring index
  8927. **/
  8928. static void ixgbe_irq_disable_single(struct ixgbe_adapter *adapter, u32 ring)
  8929. {
  8930. struct ixgbe_hw *hw = &adapter->hw;
  8931. u64 qmask = BIT_ULL(ring);
  8932. u32 mask;
  8933. switch (adapter->hw.mac.type) {
  8934. case ixgbe_mac_82598EB:
  8935. mask = qmask & IXGBE_EIMC_RTX_QUEUE;
  8936. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask);
  8937. break;
  8938. case ixgbe_mac_82599EB:
  8939. case ixgbe_mac_X540:
  8940. case ixgbe_mac_X550:
  8941. case ixgbe_mac_X550EM_x:
  8942. case ixgbe_mac_x550em_a:
  8943. mask = (qmask & 0xFFFFFFFF);
  8944. if (mask)
  8945. IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
  8946. mask = (qmask >> 32);
  8947. if (mask)
  8948. IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
  8949. break;
  8950. default:
  8951. break;
  8952. }
  8953. IXGBE_WRITE_FLUSH(&adapter->hw);
  8954. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  8955. synchronize_irq(adapter->msix_entries[ring].vector);
  8956. else
  8957. synchronize_irq(adapter->pdev->irq);
  8958. }
  8959. /**
  8960. * ixgbe_txrx_ring_disable - Disable Rx/Tx/XDP Tx rings
  8961. * @adapter: adapter structure
  8962. * @ring: ring index
  8963. *
  8964. * This function disables a certain Rx/Tx/XDP Tx ring. The function
  8965. * assumes that the netdev is running.
  8966. **/
  8967. void ixgbe_txrx_ring_disable(struct ixgbe_adapter *adapter, int ring)
  8968. {
  8969. struct ixgbe_ring *rx_ring, *tx_ring, *xdp_ring;
  8970. rx_ring = adapter->rx_ring[ring];
  8971. tx_ring = adapter->tx_ring[ring];
  8972. xdp_ring = adapter->xdp_ring[ring];
  8973. ixgbe_irq_disable_single(adapter, ring);
  8974. /* Rx/Tx/XDP Tx share the same napi context. */
  8975. napi_disable(&rx_ring->q_vector->napi);
  8976. ixgbe_disable_txr(adapter, tx_ring);
  8977. if (xdp_ring)
  8978. ixgbe_disable_txr(adapter, xdp_ring);
  8979. ixgbe_disable_rxr_hw(adapter, rx_ring);
  8980. if (xdp_ring)
  8981. synchronize_rcu();
  8982. ixgbe_clean_tx_ring(tx_ring);
  8983. if (xdp_ring)
  8984. ixgbe_clean_tx_ring(xdp_ring);
  8985. ixgbe_clean_rx_ring(rx_ring);
  8986. ixgbe_reset_txr_stats(tx_ring);
  8987. if (xdp_ring)
  8988. ixgbe_reset_txr_stats(xdp_ring);
  8989. ixgbe_reset_rxr_stats(rx_ring);
  8990. }
  8991. /**
  8992. * ixgbe_txrx_ring_enable - Enable Rx/Tx/XDP Tx rings
  8993. * @adapter: adapter structure
  8994. * @ring: ring index
  8995. *
  8996. * This function enables a certain Rx/Tx/XDP Tx ring. The function
  8997. * assumes that the netdev is running.
  8998. **/
  8999. void ixgbe_txrx_ring_enable(struct ixgbe_adapter *adapter, int ring)
  9000. {
  9001. struct ixgbe_ring *rx_ring, *tx_ring, *xdp_ring;
  9002. rx_ring = adapter->rx_ring[ring];
  9003. tx_ring = adapter->tx_ring[ring];
  9004. xdp_ring = adapter->xdp_ring[ring];
  9005. ixgbe_configure_tx_ring(adapter, tx_ring);
  9006. if (xdp_ring)
  9007. ixgbe_configure_tx_ring(adapter, xdp_ring);
  9008. ixgbe_configure_rx_ring(adapter, rx_ring);
  9009. clear_bit(__IXGBE_TX_DISABLED, &tx_ring->state);
  9010. if (xdp_ring)
  9011. clear_bit(__IXGBE_TX_DISABLED, &xdp_ring->state);
  9012. /* Rx/Tx/XDP Tx share the same napi context. */
  9013. napi_enable(&rx_ring->q_vector->napi);
  9014. ixgbe_irq_enable_queues(adapter, BIT_ULL(ring));
  9015. IXGBE_WRITE_FLUSH(&adapter->hw);
  9016. }
  9017. /**
  9018. * ixgbe_enumerate_functions - Get the number of ports this device has
  9019. * @adapter: adapter structure
  9020. *
  9021. * This function enumerates the phsyical functions co-located on a single slot,
  9022. * in order to determine how many ports a device has. This is most useful in
  9023. * determining the required GT/s of PCIe bandwidth necessary for optimal
  9024. * performance.
  9025. **/
  9026. static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
  9027. {
  9028. struct pci_dev *entry, *pdev = adapter->pdev;
  9029. int physfns = 0;
  9030. /* Some cards can not use the generic count PCIe functions method,
  9031. * because they are behind a parent switch, so we hardcode these with
  9032. * the correct number of functions.
  9033. */
  9034. if (ixgbe_pcie_from_parent(&adapter->hw))
  9035. physfns = 4;
  9036. list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
  9037. /* don't count virtual functions */
  9038. if (entry->is_virtfn)
  9039. continue;
  9040. /* When the devices on the bus don't all match our device ID,
  9041. * we can't reliably determine the correct number of
  9042. * functions. This can occur if a function has been direct
  9043. * attached to a virtual machine using VT-d, for example. In
  9044. * this case, simply return -1 to indicate this.
  9045. */
  9046. if ((entry->vendor != pdev->vendor) ||
  9047. (entry->device != pdev->device))
  9048. return -1;
  9049. physfns++;
  9050. }
  9051. return physfns;
  9052. }
  9053. /**
  9054. * ixgbe_wol_supported - Check whether device supports WoL
  9055. * @adapter: the adapter private structure
  9056. * @device_id: the device ID
  9057. * @subdevice_id: the subsystem device ID
  9058. *
  9059. * This function is used by probe and ethtool to determine
  9060. * which devices have WoL support
  9061. *
  9062. **/
  9063. bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
  9064. u16 subdevice_id)
  9065. {
  9066. struct ixgbe_hw *hw = &adapter->hw;
  9067. u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
  9068. /* WOL not supported on 82598 */
  9069. if (hw->mac.type == ixgbe_mac_82598EB)
  9070. return false;
  9071. /* check eeprom to see if WOL is enabled for X540 and newer */
  9072. if (hw->mac.type >= ixgbe_mac_X540) {
  9073. if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
  9074. ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
  9075. (hw->bus.func == 0)))
  9076. return true;
  9077. }
  9078. /* WOL is determined based on device IDs for 82599 MACs */
  9079. switch (device_id) {
  9080. case IXGBE_DEV_ID_82599_SFP:
  9081. /* Only these subdevices could supports WOL */
  9082. switch (subdevice_id) {
  9083. case IXGBE_SUBDEV_ID_82599_560FLR:
  9084. case IXGBE_SUBDEV_ID_82599_LOM_SNAP6:
  9085. case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
  9086. case IXGBE_SUBDEV_ID_82599_SFP_2OCP:
  9087. /* only support first port */
  9088. if (hw->bus.func != 0)
  9089. break;
  9090. fallthrough;
  9091. case IXGBE_SUBDEV_ID_82599_SP_560FLR:
  9092. case IXGBE_SUBDEV_ID_82599_SFP:
  9093. case IXGBE_SUBDEV_ID_82599_RNDC:
  9094. case IXGBE_SUBDEV_ID_82599_ECNA_DP:
  9095. case IXGBE_SUBDEV_ID_82599_SFP_1OCP:
  9096. case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1:
  9097. case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2:
  9098. return true;
  9099. }
  9100. break;
  9101. case IXGBE_DEV_ID_82599EN_SFP:
  9102. /* Only these subdevices support WOL */
  9103. switch (subdevice_id) {
  9104. case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
  9105. return true;
  9106. }
  9107. break;
  9108. case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
  9109. /* All except this subdevice support WOL */
  9110. if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
  9111. return true;
  9112. break;
  9113. case IXGBE_DEV_ID_82599_KX4:
  9114. return true;
  9115. default:
  9116. break;
  9117. }
  9118. return false;
  9119. }
  9120. /**
  9121. * ixgbe_set_fw_version - Set FW version
  9122. * @adapter: the adapter private structure
  9123. *
  9124. * This function is used by probe and ethtool to determine the FW version to
  9125. * format to display. The FW version is taken from the EEPROM/NVM.
  9126. */
  9127. static void ixgbe_set_fw_version(struct ixgbe_adapter *adapter)
  9128. {
  9129. struct ixgbe_hw *hw = &adapter->hw;
  9130. struct ixgbe_nvm_version nvm_ver;
  9131. ixgbe_get_oem_prod_version(hw, &nvm_ver);
  9132. if (nvm_ver.oem_valid) {
  9133. snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
  9134. "%x.%x.%x", nvm_ver.oem_major, nvm_ver.oem_minor,
  9135. nvm_ver.oem_release);
  9136. return;
  9137. }
  9138. ixgbe_get_etk_id(hw, &nvm_ver);
  9139. ixgbe_get_orom_version(hw, &nvm_ver);
  9140. if (nvm_ver.or_valid) {
  9141. snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
  9142. "0x%08x, %d.%d.%d", nvm_ver.etk_id, nvm_ver.or_major,
  9143. nvm_ver.or_build, nvm_ver.or_patch);
  9144. return;
  9145. }
  9146. /* Set ETrack ID format */
  9147. snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
  9148. "0x%08x", nvm_ver.etk_id);
  9149. }
  9150. /**
  9151. * ixgbe_probe - Device Initialization Routine
  9152. * @pdev: PCI device information struct
  9153. * @ent: entry in ixgbe_pci_tbl
  9154. *
  9155. * Returns 0 on success, negative on failure
  9156. *
  9157. * ixgbe_probe initializes an adapter identified by a pci_dev structure.
  9158. * The OS initialization, configuring of the adapter private structure,
  9159. * and a hardware reset occur.
  9160. **/
  9161. static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  9162. {
  9163. struct net_device *netdev;
  9164. struct ixgbe_adapter *adapter = NULL;
  9165. struct ixgbe_hw *hw;
  9166. const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
  9167. unsigned int indices = MAX_TX_QUEUES;
  9168. u8 part_str[IXGBE_PBANUM_LENGTH];
  9169. int i, err, expected_gts;
  9170. bool disable_dev = false;
  9171. #ifdef IXGBE_FCOE
  9172. u16 device_caps;
  9173. #endif
  9174. u32 eec;
  9175. /* Catch broken hardware that put the wrong VF device ID in
  9176. * the PCIe SR-IOV capability.
  9177. */
  9178. if (pdev->is_virtfn) {
  9179. WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
  9180. pci_name(pdev), pdev->vendor, pdev->device);
  9181. return -EINVAL;
  9182. }
  9183. err = pci_enable_device_mem(pdev);
  9184. if (err)
  9185. return err;
  9186. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  9187. if (err) {
  9188. dev_err(&pdev->dev,
  9189. "No usable DMA configuration, aborting\n");
  9190. goto err_dma;
  9191. }
  9192. err = pci_request_mem_regions(pdev, ixgbe_driver_name);
  9193. if (err) {
  9194. dev_err(&pdev->dev,
  9195. "pci_request_selected_regions failed 0x%x\n", err);
  9196. goto err_pci_reg;
  9197. }
  9198. pci_set_master(pdev);
  9199. pci_save_state(pdev);
  9200. if (ii->mac == ixgbe_mac_82598EB) {
  9201. #ifdef CONFIG_IXGBE_DCB
  9202. /* 8 TC w/ 4 queues per TC */
  9203. indices = 4 * MAX_TRAFFIC_CLASS;
  9204. #else
  9205. indices = IXGBE_MAX_RSS_INDICES;
  9206. #endif
  9207. }
  9208. netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
  9209. if (!netdev) {
  9210. err = -ENOMEM;
  9211. goto err_alloc_etherdev;
  9212. }
  9213. SET_NETDEV_DEV(netdev, &pdev->dev);
  9214. adapter = netdev_priv(netdev);
  9215. adapter->netdev = netdev;
  9216. adapter->pdev = pdev;
  9217. hw = &adapter->hw;
  9218. hw->back = adapter;
  9219. adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
  9220. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  9221. pci_resource_len(pdev, 0));
  9222. adapter->io_addr = hw->hw_addr;
  9223. if (!hw->hw_addr) {
  9224. err = -EIO;
  9225. goto err_ioremap;
  9226. }
  9227. netdev->netdev_ops = &ixgbe_netdev_ops;
  9228. ixgbe_set_ethtool_ops(netdev);
  9229. netdev->watchdog_timeo = 5 * HZ;
  9230. strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
  9231. /* Setup hw api */
  9232. hw->mac.ops = *ii->mac_ops;
  9233. hw->mac.type = ii->mac;
  9234. hw->mvals = ii->mvals;
  9235. if (ii->link_ops)
  9236. hw->link.ops = *ii->link_ops;
  9237. /* EEPROM */
  9238. hw->eeprom.ops = *ii->eeprom_ops;
  9239. eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
  9240. if (ixgbe_removed(hw->hw_addr)) {
  9241. err = -EIO;
  9242. goto err_ioremap;
  9243. }
  9244. /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
  9245. if (!(eec & BIT(8)))
  9246. hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
  9247. /* PHY */
  9248. hw->phy.ops = *ii->phy_ops;
  9249. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  9250. /* ixgbe_identify_phy_generic will set prtad and mmds properly */
  9251. hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
  9252. hw->phy.mdio.mmds = 0;
  9253. hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  9254. hw->phy.mdio.dev = netdev;
  9255. hw->phy.mdio.mdio_read = ixgbe_mdio_read;
  9256. hw->phy.mdio.mdio_write = ixgbe_mdio_write;
  9257. /* setup the private structure */
  9258. err = ixgbe_sw_init(adapter, ii);
  9259. if (err)
  9260. goto err_sw_init;
  9261. if (adapter->hw.mac.type == ixgbe_mac_82599EB)
  9262. adapter->flags2 |= IXGBE_FLAG2_AUTO_DISABLE_VF;
  9263. switch (adapter->hw.mac.type) {
  9264. case ixgbe_mac_X550:
  9265. case ixgbe_mac_X550EM_x:
  9266. netdev->udp_tunnel_nic_info = &ixgbe_udp_tunnels_x550;
  9267. break;
  9268. case ixgbe_mac_x550em_a:
  9269. netdev->udp_tunnel_nic_info = &ixgbe_udp_tunnels_x550em_a;
  9270. break;
  9271. default:
  9272. break;
  9273. }
  9274. /* Make sure the SWFW semaphore is in a valid state */
  9275. if (hw->mac.ops.init_swfw_sync)
  9276. hw->mac.ops.init_swfw_sync(hw);
  9277. /* Make it possible the adapter to be woken up via WOL */
  9278. switch (adapter->hw.mac.type) {
  9279. case ixgbe_mac_82599EB:
  9280. case ixgbe_mac_X540:
  9281. case ixgbe_mac_X550:
  9282. case ixgbe_mac_X550EM_x:
  9283. case ixgbe_mac_x550em_a:
  9284. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  9285. break;
  9286. default:
  9287. break;
  9288. }
  9289. /*
  9290. * If there is a fan on this device and it has failed log the
  9291. * failure.
  9292. */
  9293. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  9294. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  9295. if (esdp & IXGBE_ESDP_SDP1)
  9296. e_crit(probe, "Fan has stopped, replace the adapter\n");
  9297. }
  9298. if (allow_unsupported_sfp)
  9299. hw->allow_unsupported_sfp = allow_unsupported_sfp;
  9300. /* reset_hw fills in the perm_addr as well */
  9301. hw->phy.reset_if_overtemp = true;
  9302. err = hw->mac.ops.reset_hw(hw);
  9303. hw->phy.reset_if_overtemp = false;
  9304. ixgbe_set_eee_capable(adapter);
  9305. if (err == -ENOENT) {
  9306. err = 0;
  9307. } else if (err == -EOPNOTSUPP) {
  9308. e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
  9309. e_dev_err("Reload the driver after installing a supported module.\n");
  9310. goto err_sw_init;
  9311. } else if (err) {
  9312. e_dev_err("HW Init failed: %d\n", err);
  9313. goto err_sw_init;
  9314. }
  9315. #ifdef CONFIG_PCI_IOV
  9316. /* SR-IOV not supported on the 82598 */
  9317. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  9318. goto skip_sriov;
  9319. /* Mailbox */
  9320. ixgbe_init_mbx_params_pf(hw);
  9321. hw->mbx.ops = ii->mbx_ops;
  9322. pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
  9323. ixgbe_enable_sriov(adapter, max_vfs);
  9324. skip_sriov:
  9325. #endif
  9326. netdev->features = NETIF_F_SG |
  9327. NETIF_F_TSO |
  9328. NETIF_F_TSO6 |
  9329. NETIF_F_RXHASH |
  9330. NETIF_F_RXCSUM |
  9331. NETIF_F_HW_CSUM;
  9332. #define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
  9333. NETIF_F_GSO_GRE_CSUM | \
  9334. NETIF_F_GSO_IPXIP4 | \
  9335. NETIF_F_GSO_IPXIP6 | \
  9336. NETIF_F_GSO_UDP_TUNNEL | \
  9337. NETIF_F_GSO_UDP_TUNNEL_CSUM)
  9338. netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES;
  9339. netdev->features |= NETIF_F_GSO_PARTIAL |
  9340. IXGBE_GSO_PARTIAL_FEATURES;
  9341. if (hw->mac.type >= ixgbe_mac_82599EB)
  9342. netdev->features |= NETIF_F_SCTP_CRC | NETIF_F_GSO_UDP_L4;
  9343. #ifdef CONFIG_IXGBE_IPSEC
  9344. #define IXGBE_ESP_FEATURES (NETIF_F_HW_ESP | \
  9345. NETIF_F_HW_ESP_TX_CSUM | \
  9346. NETIF_F_GSO_ESP)
  9347. if (adapter->ipsec)
  9348. netdev->features |= IXGBE_ESP_FEATURES;
  9349. #endif
  9350. /* copy netdev features into list of user selectable features */
  9351. netdev->hw_features |= netdev->features |
  9352. NETIF_F_HW_VLAN_CTAG_FILTER |
  9353. NETIF_F_HW_VLAN_CTAG_RX |
  9354. NETIF_F_HW_VLAN_CTAG_TX |
  9355. NETIF_F_RXALL |
  9356. NETIF_F_HW_L2FW_DOFFLOAD;
  9357. if (hw->mac.type >= ixgbe_mac_82599EB)
  9358. netdev->hw_features |= NETIF_F_NTUPLE |
  9359. NETIF_F_HW_TC;
  9360. netdev->features |= NETIF_F_HIGHDMA;
  9361. netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
  9362. netdev->hw_enc_features |= netdev->vlan_features;
  9363. netdev->mpls_features |= NETIF_F_SG |
  9364. NETIF_F_TSO |
  9365. NETIF_F_TSO6 |
  9366. NETIF_F_HW_CSUM;
  9367. netdev->mpls_features |= IXGBE_GSO_PARTIAL_FEATURES;
  9368. /* set this bit last since it cannot be part of vlan_features */
  9369. netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
  9370. NETIF_F_HW_VLAN_CTAG_RX |
  9371. NETIF_F_HW_VLAN_CTAG_TX;
  9372. netdev->priv_flags |= IFF_UNICAST_FLT;
  9373. netdev->priv_flags |= IFF_SUPP_NOFCS;
  9374. netdev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT |
  9375. NETDEV_XDP_ACT_XSK_ZEROCOPY;
  9376. /* MTU range: 68 - 9710 */
  9377. netdev->min_mtu = ETH_MIN_MTU;
  9378. netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
  9379. #ifdef CONFIG_IXGBE_DCB
  9380. if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
  9381. netdev->dcbnl_ops = &ixgbe_dcbnl_ops;
  9382. #endif
  9383. #ifdef IXGBE_FCOE
  9384. if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
  9385. unsigned int fcoe_l;
  9386. if (hw->mac.ops.get_device_caps) {
  9387. hw->mac.ops.get_device_caps(hw, &device_caps);
  9388. if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
  9389. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  9390. }
  9391. fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
  9392. adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
  9393. netdev->features |= NETIF_F_FSO |
  9394. NETIF_F_FCOE_CRC;
  9395. netdev->vlan_features |= NETIF_F_FSO |
  9396. NETIF_F_FCOE_CRC;
  9397. }
  9398. #endif /* IXGBE_FCOE */
  9399. if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
  9400. netdev->hw_features |= NETIF_F_LRO;
  9401. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  9402. netdev->features |= NETIF_F_LRO;
  9403. if (ixgbe_check_fw_error(adapter)) {
  9404. err = -EIO;
  9405. goto err_sw_init;
  9406. }
  9407. /* make sure the EEPROM is good */
  9408. if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
  9409. e_dev_err("The EEPROM Checksum Is Not Valid\n");
  9410. err = -EIO;
  9411. goto err_sw_init;
  9412. }
  9413. eth_platform_get_mac_address(&adapter->pdev->dev,
  9414. adapter->hw.mac.perm_addr);
  9415. eth_hw_addr_set(netdev, hw->mac.perm_addr);
  9416. if (!is_valid_ether_addr(netdev->dev_addr)) {
  9417. e_dev_err("invalid MAC address\n");
  9418. err = -EIO;
  9419. goto err_sw_init;
  9420. }
  9421. /* Set hw->mac.addr to permanent MAC address */
  9422. ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
  9423. ixgbe_mac_set_default_filter(adapter);
  9424. timer_setup(&adapter->service_timer, ixgbe_service_timer, 0);
  9425. if (ixgbe_removed(hw->hw_addr)) {
  9426. err = -EIO;
  9427. goto err_sw_init;
  9428. }
  9429. INIT_WORK(&adapter->service_task, ixgbe_service_task);
  9430. set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
  9431. clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
  9432. err = ixgbe_init_interrupt_scheme(adapter);
  9433. if (err)
  9434. goto err_sw_init;
  9435. for (i = 0; i < adapter->num_rx_queues; i++)
  9436. u64_stats_init(&adapter->rx_ring[i]->syncp);
  9437. for (i = 0; i < adapter->num_tx_queues; i++)
  9438. u64_stats_init(&adapter->tx_ring[i]->syncp);
  9439. for (i = 0; i < adapter->num_xdp_queues; i++)
  9440. u64_stats_init(&adapter->xdp_ring[i]->syncp);
  9441. /* WOL not supported for all devices */
  9442. adapter->wol = 0;
  9443. hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
  9444. hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
  9445. pdev->subsystem_device);
  9446. if (hw->wol_enabled)
  9447. adapter->wol = IXGBE_WUFC_MAG;
  9448. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  9449. /* save off EEPROM version number */
  9450. ixgbe_set_fw_version(adapter);
  9451. /* pick up the PCI bus settings for reporting later */
  9452. if (ixgbe_pcie_from_parent(hw))
  9453. ixgbe_get_parent_bus_info(adapter);
  9454. else
  9455. hw->mac.ops.get_bus_info(hw);
  9456. /* calculate the expected PCIe bandwidth required for optimal
  9457. * performance. Note that some older parts will never have enough
  9458. * bandwidth due to being older generation PCIe parts. We clamp these
  9459. * parts to ensure no warning is displayed if it can't be fixed.
  9460. */
  9461. switch (hw->mac.type) {
  9462. case ixgbe_mac_82598EB:
  9463. expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
  9464. break;
  9465. default:
  9466. expected_gts = ixgbe_enumerate_functions(adapter) * 10;
  9467. break;
  9468. }
  9469. /* don't check link if we failed to enumerate functions */
  9470. if (expected_gts > 0)
  9471. ixgbe_check_minimum_link(adapter, expected_gts);
  9472. err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
  9473. if (err)
  9474. strscpy(part_str, "Unknown", sizeof(part_str));
  9475. if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
  9476. e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
  9477. hw->mac.type, hw->phy.type, hw->phy.sfp_type,
  9478. part_str);
  9479. else
  9480. e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
  9481. hw->mac.type, hw->phy.type, part_str);
  9482. e_dev_info("%pM\n", netdev->dev_addr);
  9483. /* reset the hardware with the new settings */
  9484. err = hw->mac.ops.start_hw(hw);
  9485. if (err == -EACCES) {
  9486. /* We are running on a pre-production device, log a warning */
  9487. e_dev_warn("This device is a pre-production adapter/LOM. "
  9488. "Please be aware there may be issues associated "
  9489. "with your hardware. If you are experiencing "
  9490. "problems please contact your Intel or hardware "
  9491. "representative who provided you with this "
  9492. "hardware.\n");
  9493. }
  9494. strcpy(netdev->name, "eth%d");
  9495. pci_set_drvdata(pdev, adapter);
  9496. err = register_netdev(netdev);
  9497. if (err)
  9498. goto err_register;
  9499. /* power down the optics for 82599 SFP+ fiber */
  9500. if (hw->mac.ops.disable_tx_laser)
  9501. hw->mac.ops.disable_tx_laser(hw);
  9502. /* carrier off reporting is important to ethtool even BEFORE open */
  9503. netif_carrier_off(netdev);
  9504. #ifdef CONFIG_IXGBE_DCA
  9505. if (dca_add_requester(&pdev->dev) == 0) {
  9506. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  9507. ixgbe_setup_dca(adapter);
  9508. }
  9509. #endif
  9510. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  9511. e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
  9512. for (i = 0; i < adapter->num_vfs; i++)
  9513. ixgbe_vf_configuration(pdev, (i | 0x10000000));
  9514. }
  9515. /* firmware requires driver version to be 0xFFFFFFFF
  9516. * since os does not support feature
  9517. */
  9518. if (hw->mac.ops.set_fw_drv_ver)
  9519. hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF,
  9520. sizeof(UTS_RELEASE) - 1,
  9521. UTS_RELEASE);
  9522. /* add san mac addr to netdev */
  9523. ixgbe_add_sanmac_netdev(netdev);
  9524. e_dev_info("%s\n", ixgbe_default_device_descr);
  9525. #ifdef CONFIG_IXGBE_HWMON
  9526. if (ixgbe_sysfs_init(adapter))
  9527. e_err(probe, "failed to allocate sysfs resources\n");
  9528. #endif /* CONFIG_IXGBE_HWMON */
  9529. ixgbe_dbg_adapter_init(adapter);
  9530. /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
  9531. if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
  9532. hw->mac.ops.setup_link(hw,
  9533. IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
  9534. true);
  9535. err = ixgbe_mii_bus_init(hw);
  9536. if (err)
  9537. goto err_netdev;
  9538. return 0;
  9539. err_netdev:
  9540. unregister_netdev(netdev);
  9541. err_register:
  9542. ixgbe_release_hw_control(adapter);
  9543. ixgbe_clear_interrupt_scheme(adapter);
  9544. err_sw_init:
  9545. ixgbe_disable_sriov(adapter);
  9546. adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
  9547. iounmap(adapter->io_addr);
  9548. kfree(adapter->jump_tables[0]);
  9549. kfree(adapter->mac_table);
  9550. kfree(adapter->rss_key);
  9551. bitmap_free(adapter->af_xdp_zc_qps);
  9552. err_ioremap:
  9553. disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
  9554. free_netdev(netdev);
  9555. err_alloc_etherdev:
  9556. pci_release_mem_regions(pdev);
  9557. err_pci_reg:
  9558. err_dma:
  9559. if (!adapter || disable_dev)
  9560. pci_disable_device(pdev);
  9561. return err;
  9562. }
  9563. /**
  9564. * ixgbe_remove - Device Removal Routine
  9565. * @pdev: PCI device information struct
  9566. *
  9567. * ixgbe_remove is called by the PCI subsystem to alert the driver
  9568. * that it should release a PCI device. The could be caused by a
  9569. * Hot-Plug event, or because the driver is going to be removed from
  9570. * memory.
  9571. **/
  9572. static void ixgbe_remove(struct pci_dev *pdev)
  9573. {
  9574. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  9575. struct net_device *netdev;
  9576. bool disable_dev;
  9577. int i;
  9578. /* if !adapter then we already cleaned up in probe */
  9579. if (!adapter)
  9580. return;
  9581. netdev = adapter->netdev;
  9582. ixgbe_dbg_adapter_exit(adapter);
  9583. set_bit(__IXGBE_REMOVING, &adapter->state);
  9584. cancel_work_sync(&adapter->service_task);
  9585. if (adapter->mii_bus)
  9586. mdiobus_unregister(adapter->mii_bus);
  9587. #ifdef CONFIG_IXGBE_DCA
  9588. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  9589. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  9590. dca_remove_requester(&pdev->dev);
  9591. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  9592. IXGBE_DCA_CTRL_DCA_DISABLE);
  9593. }
  9594. #endif
  9595. #ifdef CONFIG_IXGBE_HWMON
  9596. ixgbe_sysfs_exit(adapter);
  9597. #endif /* CONFIG_IXGBE_HWMON */
  9598. /* remove the added san mac */
  9599. ixgbe_del_sanmac_netdev(netdev);
  9600. #ifdef CONFIG_PCI_IOV
  9601. ixgbe_disable_sriov(adapter);
  9602. #endif
  9603. if (netdev->reg_state == NETREG_REGISTERED)
  9604. unregister_netdev(netdev);
  9605. ixgbe_stop_ipsec_offload(adapter);
  9606. ixgbe_clear_interrupt_scheme(adapter);
  9607. ixgbe_release_hw_control(adapter);
  9608. #ifdef CONFIG_DCB
  9609. kfree(adapter->ixgbe_ieee_pfc);
  9610. kfree(adapter->ixgbe_ieee_ets);
  9611. #endif
  9612. iounmap(adapter->io_addr);
  9613. pci_release_mem_regions(pdev);
  9614. e_dev_info("complete\n");
  9615. for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) {
  9616. if (adapter->jump_tables[i]) {
  9617. kfree(adapter->jump_tables[i]->input);
  9618. kfree(adapter->jump_tables[i]->mask);
  9619. }
  9620. kfree(adapter->jump_tables[i]);
  9621. }
  9622. kfree(adapter->mac_table);
  9623. kfree(adapter->rss_key);
  9624. bitmap_free(adapter->af_xdp_zc_qps);
  9625. disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
  9626. free_netdev(netdev);
  9627. if (disable_dev)
  9628. pci_disable_device(pdev);
  9629. }
  9630. /**
  9631. * ixgbe_io_error_detected - called when PCI error is detected
  9632. * @pdev: Pointer to PCI device
  9633. * @state: The current pci connection state
  9634. *
  9635. * This function is called after a PCI bus error affecting
  9636. * this device has been detected.
  9637. */
  9638. static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
  9639. pci_channel_state_t state)
  9640. {
  9641. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  9642. struct net_device *netdev = adapter->netdev;
  9643. #ifdef CONFIG_PCI_IOV
  9644. struct ixgbe_hw *hw = &adapter->hw;
  9645. struct pci_dev *bdev, *vfdev;
  9646. u32 dw0, dw1, dw2, dw3;
  9647. int vf, pos;
  9648. u16 req_id, pf_func;
  9649. if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
  9650. adapter->num_vfs == 0)
  9651. goto skip_bad_vf_detection;
  9652. bdev = pdev->bus->self;
  9653. while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
  9654. bdev = bdev->bus->self;
  9655. if (!bdev)
  9656. goto skip_bad_vf_detection;
  9657. pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
  9658. if (!pos)
  9659. goto skip_bad_vf_detection;
  9660. dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
  9661. dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
  9662. dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
  9663. dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
  9664. if (ixgbe_removed(hw->hw_addr))
  9665. goto skip_bad_vf_detection;
  9666. req_id = dw1 >> 16;
  9667. /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
  9668. if (!(req_id & 0x0080))
  9669. goto skip_bad_vf_detection;
  9670. pf_func = req_id & 0x01;
  9671. if ((pf_func & 1) == (pdev->devfn & 1)) {
  9672. unsigned int device_id;
  9673. vf = FIELD_GET(0x7F, req_id);
  9674. e_dev_err("VF %d has caused a PCIe error\n", vf);
  9675. e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
  9676. "%8.8x\tdw3: %8.8x\n",
  9677. dw0, dw1, dw2, dw3);
  9678. switch (adapter->hw.mac.type) {
  9679. case ixgbe_mac_82599EB:
  9680. device_id = IXGBE_82599_VF_DEVICE_ID;
  9681. break;
  9682. case ixgbe_mac_X540:
  9683. device_id = IXGBE_X540_VF_DEVICE_ID;
  9684. break;
  9685. case ixgbe_mac_X550:
  9686. device_id = IXGBE_DEV_ID_X550_VF;
  9687. break;
  9688. case ixgbe_mac_X550EM_x:
  9689. device_id = IXGBE_DEV_ID_X550EM_X_VF;
  9690. break;
  9691. case ixgbe_mac_x550em_a:
  9692. device_id = IXGBE_DEV_ID_X550EM_A_VF;
  9693. break;
  9694. default:
  9695. device_id = 0;
  9696. break;
  9697. }
  9698. /* Find the pci device of the offending VF */
  9699. vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
  9700. while (vfdev) {
  9701. if (vfdev->devfn == (req_id & 0xFF))
  9702. break;
  9703. vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  9704. device_id, vfdev);
  9705. }
  9706. /*
  9707. * There's a slim chance the VF could have been hot plugged,
  9708. * so if it is no longer present we don't need to issue the
  9709. * VFLR. Just clean up the AER in that case.
  9710. */
  9711. if (vfdev) {
  9712. pcie_flr(vfdev);
  9713. /* Free device reference count */
  9714. pci_dev_put(vfdev);
  9715. }
  9716. }
  9717. /*
  9718. * Even though the error may have occurred on the other port
  9719. * we still need to increment the vf error reference count for
  9720. * both ports because the I/O resume function will be called
  9721. * for both of them.
  9722. */
  9723. adapter->vferr_refcount++;
  9724. return PCI_ERS_RESULT_RECOVERED;
  9725. skip_bad_vf_detection:
  9726. #endif /* CONFIG_PCI_IOV */
  9727. if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
  9728. return PCI_ERS_RESULT_DISCONNECT;
  9729. if (!netif_device_present(netdev))
  9730. return PCI_ERS_RESULT_DISCONNECT;
  9731. rtnl_lock();
  9732. netif_device_detach(netdev);
  9733. if (netif_running(netdev))
  9734. ixgbe_close_suspend(adapter);
  9735. if (state == pci_channel_io_perm_failure) {
  9736. rtnl_unlock();
  9737. return PCI_ERS_RESULT_DISCONNECT;
  9738. }
  9739. if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
  9740. pci_disable_device(pdev);
  9741. rtnl_unlock();
  9742. /* Request a slot reset. */
  9743. return PCI_ERS_RESULT_NEED_RESET;
  9744. }
  9745. /**
  9746. * ixgbe_io_slot_reset - called after the pci bus has been reset.
  9747. * @pdev: Pointer to PCI device
  9748. *
  9749. * Restart the card from scratch, as if from a cold-boot.
  9750. */
  9751. static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
  9752. {
  9753. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  9754. pci_ers_result_t result;
  9755. if (pci_enable_device_mem(pdev)) {
  9756. e_err(probe, "Cannot re-enable PCI device after reset.\n");
  9757. result = PCI_ERS_RESULT_DISCONNECT;
  9758. } else {
  9759. smp_mb__before_atomic();
  9760. clear_bit(__IXGBE_DISABLED, &adapter->state);
  9761. adapter->hw.hw_addr = adapter->io_addr;
  9762. pci_set_master(pdev);
  9763. pci_restore_state(pdev);
  9764. pci_save_state(pdev);
  9765. pci_wake_from_d3(pdev, false);
  9766. ixgbe_reset(adapter);
  9767. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  9768. result = PCI_ERS_RESULT_RECOVERED;
  9769. }
  9770. return result;
  9771. }
  9772. /**
  9773. * ixgbe_io_resume - called when traffic can start flowing again.
  9774. * @pdev: Pointer to PCI device
  9775. *
  9776. * This callback is called when the error recovery driver tells us that
  9777. * its OK to resume normal operation.
  9778. */
  9779. static void ixgbe_io_resume(struct pci_dev *pdev)
  9780. {
  9781. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  9782. struct net_device *netdev = adapter->netdev;
  9783. #ifdef CONFIG_PCI_IOV
  9784. if (adapter->vferr_refcount) {
  9785. e_info(drv, "Resuming after VF err\n");
  9786. adapter->vferr_refcount--;
  9787. return;
  9788. }
  9789. #endif
  9790. rtnl_lock();
  9791. if (netif_running(netdev))
  9792. ixgbe_open(netdev);
  9793. netif_device_attach(netdev);
  9794. rtnl_unlock();
  9795. }
  9796. static const struct pci_error_handlers ixgbe_err_handler = {
  9797. .error_detected = ixgbe_io_error_detected,
  9798. .slot_reset = ixgbe_io_slot_reset,
  9799. .resume = ixgbe_io_resume,
  9800. };
  9801. static DEFINE_SIMPLE_DEV_PM_OPS(ixgbe_pm_ops, ixgbe_suspend, ixgbe_resume);
  9802. static struct pci_driver ixgbe_driver = {
  9803. .name = ixgbe_driver_name,
  9804. .id_table = ixgbe_pci_tbl,
  9805. .probe = ixgbe_probe,
  9806. .remove = ixgbe_remove,
  9807. .driver.pm = pm_sleep_ptr(&ixgbe_pm_ops),
  9808. .shutdown = ixgbe_shutdown,
  9809. .sriov_configure = ixgbe_pci_sriov_configure,
  9810. .err_handler = &ixgbe_err_handler
  9811. };
  9812. /**
  9813. * ixgbe_init_module - Driver Registration Routine
  9814. *
  9815. * ixgbe_init_module is the first routine called when the driver is
  9816. * loaded. All it does is register with the PCI subsystem.
  9817. **/
  9818. static int __init ixgbe_init_module(void)
  9819. {
  9820. int ret;
  9821. pr_info("%s\n", ixgbe_driver_string);
  9822. pr_info("%s\n", ixgbe_copyright);
  9823. ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
  9824. if (!ixgbe_wq) {
  9825. pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
  9826. return -ENOMEM;
  9827. }
  9828. ixgbe_dbg_init();
  9829. ret = pci_register_driver(&ixgbe_driver);
  9830. if (ret) {
  9831. destroy_workqueue(ixgbe_wq);
  9832. ixgbe_dbg_exit();
  9833. return ret;
  9834. }
  9835. #ifdef CONFIG_IXGBE_DCA
  9836. dca_register_notify(&dca_notifier);
  9837. #endif
  9838. return 0;
  9839. }
  9840. module_init(ixgbe_init_module);
  9841. /**
  9842. * ixgbe_exit_module - Driver Exit Cleanup Routine
  9843. *
  9844. * ixgbe_exit_module is called just before the driver is removed
  9845. * from memory.
  9846. **/
  9847. static void __exit ixgbe_exit_module(void)
  9848. {
  9849. #ifdef CONFIG_IXGBE_DCA
  9850. dca_unregister_notify(&dca_notifier);
  9851. #endif
  9852. pci_unregister_driver(&ixgbe_driver);
  9853. ixgbe_dbg_exit();
  9854. if (ixgbe_wq) {
  9855. destroy_workqueue(ixgbe_wq);
  9856. ixgbe_wq = NULL;
  9857. }
  9858. }
  9859. #ifdef CONFIG_IXGBE_DCA
  9860. static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
  9861. void *p)
  9862. {
  9863. int ret_val;
  9864. ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
  9865. __ixgbe_notify_dca);
  9866. return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
  9867. }
  9868. #endif /* CONFIG_IXGBE_DCA */
  9869. module_exit(ixgbe_exit_module);
  9870. /* ixgbe_main.c */