ixgbe_main.c 255 KB

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