ixgbe_main.c 212 KB

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