ixgbe_main.c 214 KB

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