ixgbe_main.c 301 KB

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