ixgbe_main.c 217 KB

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