ixgbe_main.c 211 KB

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