ixgbe_main.c 301 KB

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