ixgbe_main.c 301 KB

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