ixgbe_main.c 307 KB

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