ixgbe_main.c 217 KB

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