ixgbe_main.c 284 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2016 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. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include <linux/types.h>
  22. #include <linux/module.h>
  23. #include <linux/pci.h>
  24. #include <linux/netdevice.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/string.h>
  27. #include <linux/in.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/ip.h>
  30. #include <linux/tcp.h>
  31. #include <linux/sctp.h>
  32. #include <linux/pkt_sched.h>
  33. #include <linux/ipv6.h>
  34. #include <linux/slab.h>
  35. #include <net/checksum.h>
  36. #include <net/ip6_checksum.h>
  37. #include <linux/etherdevice.h>
  38. #include <linux/ethtool.h>
  39. #include <linux/if.h>
  40. #include <linux/if_vlan.h>
  41. #include <linux/if_macvlan.h>
  42. #include <linux/if_bridge.h>
  43. #include <linux/prefetch.h>
  44. #include <scsi/fc/fc_fcoe.h>
  45. #include <net/udp_tunnel.h>
  46. #include <net/pkt_cls.h>
  47. #include <net/tc_act/tc_gact.h>
  48. #include <net/tc_act/tc_mirred.h>
  49. #include <net/vxlan.h>
  50. #include "ixgbe.h"
  51. #include "ixgbe_common.h"
  52. #include "ixgbe_dcb_82599.h"
  53. #include "ixgbe_sriov.h"
  54. #include "ixgbe_model.h"
  55. char ixgbe_driver_name[] = "ixgbe";
  56. static const char ixgbe_driver_string[] =
  57. "Intel(R) 10 Gigabit PCI Express Network Driver";
  58. #ifdef IXGBE_FCOE
  59. char ixgbe_default_device_descr[] =
  60. "Intel(R) 10 Gigabit Network Connection";
  61. #else
  62. static char ixgbe_default_device_descr[] =
  63. "Intel(R) 10 Gigabit Network Connection";
  64. #endif
  65. #define DRV_VERSION "5.0.0-k"
  66. const char ixgbe_driver_version[] = DRV_VERSION;
  67. static const char ixgbe_copyright[] =
  68. "Copyright (c) 1999-2016 Intel Corporation.";
  69. static const char ixgbe_overheat_msg[] = "Network adapter has been stopped because it has over heated. Restart the computer. If the problem persists, power off the system and replace the adapter";
  70. static const struct ixgbe_info *ixgbe_info_tbl[] = {
  71. [board_82598] = &ixgbe_82598_info,
  72. [board_82599] = &ixgbe_82599_info,
  73. [board_X540] = &ixgbe_X540_info,
  74. [board_X550] = &ixgbe_X550_info,
  75. [board_X550EM_x] = &ixgbe_X550EM_x_info,
  76. [board_x550em_a] = &ixgbe_x550em_a_info,
  77. [board_x550em_a_fw] = &ixgbe_x550em_a_fw_info,
  78. };
  79. /* ixgbe_pci_tbl - PCI Device ID Table
  80. *
  81. * Wildcard entries (PCI_ANY_ID) should come last
  82. * Last entry must be all 0s
  83. *
  84. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  85. * Class, Class Mask, private data (not used) }
  86. */
  87. static const struct pci_device_id ixgbe_pci_tbl[] = {
  88. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
  89. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
  90. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
  91. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
  92. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
  93. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
  94. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
  95. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
  96. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
  97. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
  98. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
  99. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
  100. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
  101. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
  102. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
  103. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
  104. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
  105. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
  106. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
  107. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
  108. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
  109. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
  110. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
  111. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
  112. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
  113. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
  114. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 },
  115. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
  116. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
  117. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
  118. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550},
  119. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550},
  120. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x},
  121. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_XFI), board_X550EM_x},
  122. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x},
  123. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x},
  124. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x},
  125. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a },
  126. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR_L), board_x550em_a },
  127. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP_N), board_x550em_a },
  128. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a },
  129. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII_L), board_x550em_a },
  130. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_10G_T), board_x550em_a},
  131. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a },
  132. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T), board_x550em_a_fw },
  133. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T_L), board_x550em_a_fw },
  134. /* required last entry */
  135. {0, }
  136. };
  137. MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
  138. #ifdef CONFIG_IXGBE_DCA
  139. static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
  140. void *p);
  141. static struct notifier_block dca_notifier = {
  142. .notifier_call = ixgbe_notify_dca,
  143. .next = NULL,
  144. .priority = 0
  145. };
  146. #endif
  147. #ifdef CONFIG_PCI_IOV
  148. static unsigned int max_vfs;
  149. module_param(max_vfs, uint, 0);
  150. MODULE_PARM_DESC(max_vfs,
  151. "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63. (Deprecated)");
  152. #endif /* CONFIG_PCI_IOV */
  153. static unsigned int allow_unsupported_sfp;
  154. module_param(allow_unsupported_sfp, uint, 0);
  155. MODULE_PARM_DESC(allow_unsupported_sfp,
  156. "Allow unsupported and untested SFP+ modules on 82599-based adapters");
  157. #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
  158. static int debug = -1;
  159. module_param(debug, int, 0);
  160. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  161. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  162. MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
  163. MODULE_LICENSE("GPL");
  164. MODULE_VERSION(DRV_VERSION);
  165. static struct workqueue_struct *ixgbe_wq;
  166. static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
  167. static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *);
  168. static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
  169. u32 reg, u16 *value)
  170. {
  171. struct pci_dev *parent_dev;
  172. struct pci_bus *parent_bus;
  173. parent_bus = adapter->pdev->bus->parent;
  174. if (!parent_bus)
  175. return -1;
  176. parent_dev = parent_bus->self;
  177. if (!parent_dev)
  178. return -1;
  179. if (!pci_is_pcie(parent_dev))
  180. return -1;
  181. pcie_capability_read_word(parent_dev, reg, value);
  182. if (*value == IXGBE_FAILED_READ_CFG_WORD &&
  183. ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
  184. return -1;
  185. return 0;
  186. }
  187. static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
  188. {
  189. struct ixgbe_hw *hw = &adapter->hw;
  190. u16 link_status = 0;
  191. int err;
  192. hw->bus.type = ixgbe_bus_type_pci_express;
  193. /* Get the negotiated link width and speed from PCI config space of the
  194. * parent, as this device is behind a switch
  195. */
  196. err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
  197. /* assume caller will handle error case */
  198. if (err)
  199. return err;
  200. hw->bus.width = ixgbe_convert_bus_width(link_status);
  201. hw->bus.speed = ixgbe_convert_bus_speed(link_status);
  202. return 0;
  203. }
  204. /**
  205. * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
  206. * @hw: hw specific details
  207. *
  208. * This function is used by probe to determine whether a device's PCI-Express
  209. * bandwidth details should be gathered from the parent bus instead of from the
  210. * device. Used to ensure that various locations all have the correct device ID
  211. * checks.
  212. */
  213. static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
  214. {
  215. switch (hw->device_id) {
  216. case IXGBE_DEV_ID_82599_SFP_SF_QP:
  217. case IXGBE_DEV_ID_82599_QSFP_SF_QP:
  218. return true;
  219. default:
  220. return false;
  221. }
  222. }
  223. static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
  224. int expected_gts)
  225. {
  226. struct ixgbe_hw *hw = &adapter->hw;
  227. int max_gts = 0;
  228. enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
  229. enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
  230. struct pci_dev *pdev;
  231. /* Some devices are not connected over PCIe and thus do not negotiate
  232. * speed. These devices do not have valid bus info, and thus any report
  233. * we generate may not be correct.
  234. */
  235. if (hw->bus.type == ixgbe_bus_type_internal)
  236. return;
  237. /* determine whether to use the parent device */
  238. if (ixgbe_pcie_from_parent(&adapter->hw))
  239. pdev = adapter->pdev->bus->parent->self;
  240. else
  241. pdev = adapter->pdev;
  242. if (pcie_get_minimum_link(pdev, &speed, &width) ||
  243. speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
  244. e_dev_warn("Unable to determine PCI Express bandwidth.\n");
  245. return;
  246. }
  247. switch (speed) {
  248. case PCIE_SPEED_2_5GT:
  249. /* 8b/10b encoding reduces max throughput by 20% */
  250. max_gts = 2 * width;
  251. break;
  252. case PCIE_SPEED_5_0GT:
  253. /* 8b/10b encoding reduces max throughput by 20% */
  254. max_gts = 4 * width;
  255. break;
  256. case PCIE_SPEED_8_0GT:
  257. /* 128b/130b encoding reduces throughput by less than 2% */
  258. max_gts = 8 * width;
  259. break;
  260. default:
  261. e_dev_warn("Unable to determine PCI Express bandwidth.\n");
  262. return;
  263. }
  264. e_dev_info("PCI Express bandwidth of %dGT/s available\n",
  265. max_gts);
  266. e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n",
  267. (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
  268. speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
  269. speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
  270. "Unknown"),
  271. width,
  272. (speed == PCIE_SPEED_2_5GT ? "20%" :
  273. speed == PCIE_SPEED_5_0GT ? "20%" :
  274. speed == PCIE_SPEED_8_0GT ? "<2%" :
  275. "Unknown"));
  276. if (max_gts < expected_gts) {
  277. e_dev_warn("This is not sufficient for optimal performance of this card.\n");
  278. e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n",
  279. expected_gts);
  280. e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n");
  281. }
  282. }
  283. static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
  284. {
  285. if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
  286. !test_bit(__IXGBE_REMOVING, &adapter->state) &&
  287. !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
  288. queue_work(ixgbe_wq, &adapter->service_task);
  289. }
  290. static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
  291. {
  292. struct ixgbe_adapter *adapter = hw->back;
  293. if (!hw->hw_addr)
  294. return;
  295. hw->hw_addr = NULL;
  296. e_dev_err("Adapter removed\n");
  297. if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
  298. ixgbe_service_event_schedule(adapter);
  299. }
  300. static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
  301. {
  302. u32 value;
  303. /* The following check not only optimizes a bit by not
  304. * performing a read on the status register when the
  305. * register just read was a status register read that
  306. * returned IXGBE_FAILED_READ_REG. It also blocks any
  307. * potential recursion.
  308. */
  309. if (reg == IXGBE_STATUS) {
  310. ixgbe_remove_adapter(hw);
  311. return;
  312. }
  313. value = ixgbe_read_reg(hw, IXGBE_STATUS);
  314. if (value == IXGBE_FAILED_READ_REG)
  315. ixgbe_remove_adapter(hw);
  316. }
  317. /**
  318. * ixgbe_read_reg - Read from device register
  319. * @hw: hw specific details
  320. * @reg: offset of register to read
  321. *
  322. * Returns : value read or IXGBE_FAILED_READ_REG if removed
  323. *
  324. * This function is used to read device registers. It checks for device
  325. * removal by confirming any read that returns all ones by checking the
  326. * status register value for all ones. This function avoids reading from
  327. * the hardware if a removal was previously detected in which case it
  328. * returns IXGBE_FAILED_READ_REG (all ones).
  329. */
  330. u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
  331. {
  332. u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
  333. u32 value;
  334. if (ixgbe_removed(reg_addr))
  335. return IXGBE_FAILED_READ_REG;
  336. if (unlikely(hw->phy.nw_mng_if_sel &
  337. IXGBE_NW_MNG_IF_SEL_ENABLE_10_100M)) {
  338. struct ixgbe_adapter *adapter;
  339. int i;
  340. for (i = 0; i < 200; ++i) {
  341. value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY);
  342. if (likely(!value))
  343. goto writes_completed;
  344. if (value == IXGBE_FAILED_READ_REG) {
  345. ixgbe_remove_adapter(hw);
  346. return IXGBE_FAILED_READ_REG;
  347. }
  348. udelay(5);
  349. }
  350. adapter = hw->back;
  351. e_warn(hw, "register writes incomplete %08x\n", value);
  352. }
  353. writes_completed:
  354. value = readl(reg_addr + reg);
  355. if (unlikely(value == IXGBE_FAILED_READ_REG))
  356. ixgbe_check_remove(hw, reg);
  357. return value;
  358. }
  359. static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
  360. {
  361. u16 value;
  362. pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
  363. if (value == IXGBE_FAILED_READ_CFG_WORD) {
  364. ixgbe_remove_adapter(hw);
  365. return true;
  366. }
  367. return false;
  368. }
  369. u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
  370. {
  371. struct ixgbe_adapter *adapter = hw->back;
  372. u16 value;
  373. if (ixgbe_removed(hw->hw_addr))
  374. return IXGBE_FAILED_READ_CFG_WORD;
  375. pci_read_config_word(adapter->pdev, reg, &value);
  376. if (value == IXGBE_FAILED_READ_CFG_WORD &&
  377. ixgbe_check_cfg_remove(hw, adapter->pdev))
  378. return IXGBE_FAILED_READ_CFG_WORD;
  379. return value;
  380. }
  381. #ifdef CONFIG_PCI_IOV
  382. static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
  383. {
  384. struct ixgbe_adapter *adapter = hw->back;
  385. u32 value;
  386. if (ixgbe_removed(hw->hw_addr))
  387. return IXGBE_FAILED_READ_CFG_DWORD;
  388. pci_read_config_dword(adapter->pdev, reg, &value);
  389. if (value == IXGBE_FAILED_READ_CFG_DWORD &&
  390. ixgbe_check_cfg_remove(hw, adapter->pdev))
  391. return IXGBE_FAILED_READ_CFG_DWORD;
  392. return value;
  393. }
  394. #endif /* CONFIG_PCI_IOV */
  395. void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
  396. {
  397. struct ixgbe_adapter *adapter = hw->back;
  398. if (ixgbe_removed(hw->hw_addr))
  399. return;
  400. pci_write_config_word(adapter->pdev, reg, value);
  401. }
  402. static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
  403. {
  404. BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
  405. /* flush memory to make sure state is correct before next watchdog */
  406. smp_mb__before_atomic();
  407. clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
  408. }
  409. struct ixgbe_reg_info {
  410. u32 ofs;
  411. char *name;
  412. };
  413. static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
  414. /* General Registers */
  415. {IXGBE_CTRL, "CTRL"},
  416. {IXGBE_STATUS, "STATUS"},
  417. {IXGBE_CTRL_EXT, "CTRL_EXT"},
  418. /* Interrupt Registers */
  419. {IXGBE_EICR, "EICR"},
  420. /* RX Registers */
  421. {IXGBE_SRRCTL(0), "SRRCTL"},
  422. {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
  423. {IXGBE_RDLEN(0), "RDLEN"},
  424. {IXGBE_RDH(0), "RDH"},
  425. {IXGBE_RDT(0), "RDT"},
  426. {IXGBE_RXDCTL(0), "RXDCTL"},
  427. {IXGBE_RDBAL(0), "RDBAL"},
  428. {IXGBE_RDBAH(0), "RDBAH"},
  429. /* TX Registers */
  430. {IXGBE_TDBAL(0), "TDBAL"},
  431. {IXGBE_TDBAH(0), "TDBAH"},
  432. {IXGBE_TDLEN(0), "TDLEN"},
  433. {IXGBE_TDH(0), "TDH"},
  434. {IXGBE_TDT(0), "TDT"},
  435. {IXGBE_TXDCTL(0), "TXDCTL"},
  436. /* List Terminator */
  437. { .name = NULL }
  438. };
  439. /*
  440. * ixgbe_regdump - register printout routine
  441. */
  442. static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
  443. {
  444. int i;
  445. char rname[16];
  446. u32 regs[64];
  447. switch (reginfo->ofs) {
  448. case IXGBE_SRRCTL(0):
  449. for (i = 0; i < 64; i++)
  450. regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
  451. break;
  452. case IXGBE_DCA_RXCTRL(0):
  453. for (i = 0; i < 64; i++)
  454. regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
  455. break;
  456. case IXGBE_RDLEN(0):
  457. for (i = 0; i < 64; i++)
  458. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
  459. break;
  460. case IXGBE_RDH(0):
  461. for (i = 0; i < 64; i++)
  462. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
  463. break;
  464. case IXGBE_RDT(0):
  465. for (i = 0; i < 64; i++)
  466. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
  467. break;
  468. case IXGBE_RXDCTL(0):
  469. for (i = 0; i < 64; i++)
  470. regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
  471. break;
  472. case IXGBE_RDBAL(0):
  473. for (i = 0; i < 64; i++)
  474. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
  475. break;
  476. case IXGBE_RDBAH(0):
  477. for (i = 0; i < 64; i++)
  478. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
  479. break;
  480. case IXGBE_TDBAL(0):
  481. for (i = 0; i < 64; i++)
  482. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
  483. break;
  484. case IXGBE_TDBAH(0):
  485. for (i = 0; i < 64; i++)
  486. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
  487. break;
  488. case IXGBE_TDLEN(0):
  489. for (i = 0; i < 64; i++)
  490. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
  491. break;
  492. case IXGBE_TDH(0):
  493. for (i = 0; i < 64; i++)
  494. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
  495. break;
  496. case IXGBE_TDT(0):
  497. for (i = 0; i < 64; i++)
  498. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
  499. break;
  500. case IXGBE_TXDCTL(0):
  501. for (i = 0; i < 64; i++)
  502. regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
  503. break;
  504. default:
  505. pr_info("%-15s %08x\n",
  506. reginfo->name, IXGBE_READ_REG(hw, reginfo->ofs));
  507. return;
  508. }
  509. i = 0;
  510. while (i < 64) {
  511. int j;
  512. char buf[9 * 8 + 1];
  513. char *p = buf;
  514. snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i, i + 7);
  515. for (j = 0; j < 8; j++)
  516. p += sprintf(p, " %08x", regs[i++]);
  517. pr_err("%-15s%s\n", rname, buf);
  518. }
  519. }
  520. /*
  521. * ixgbe_dump - Print registers, tx-rings and rx-rings
  522. */
  523. static void ixgbe_dump(struct ixgbe_adapter *adapter)
  524. {
  525. struct net_device *netdev = adapter->netdev;
  526. struct ixgbe_hw *hw = &adapter->hw;
  527. struct ixgbe_reg_info *reginfo;
  528. int n = 0;
  529. struct ixgbe_ring *tx_ring;
  530. struct ixgbe_tx_buffer *tx_buffer;
  531. union ixgbe_adv_tx_desc *tx_desc;
  532. struct my_u0 { u64 a; u64 b; } *u0;
  533. struct ixgbe_ring *rx_ring;
  534. union ixgbe_adv_rx_desc *rx_desc;
  535. struct ixgbe_rx_buffer *rx_buffer_info;
  536. int i = 0;
  537. if (!netif_msg_hw(adapter))
  538. return;
  539. /* Print netdevice Info */
  540. if (netdev) {
  541. dev_info(&adapter->pdev->dev, "Net device Info\n");
  542. pr_info("Device Name state "
  543. "trans_start\n");
  544. pr_info("%-15s %016lX %016lX\n",
  545. netdev->name,
  546. netdev->state,
  547. dev_trans_start(netdev));
  548. }
  549. /* Print Registers */
  550. dev_info(&adapter->pdev->dev, "Register Dump\n");
  551. pr_info(" Register Name Value\n");
  552. for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
  553. reginfo->name; reginfo++) {
  554. ixgbe_regdump(hw, reginfo);
  555. }
  556. /* Print TX Ring Summary */
  557. if (!netdev || !netif_running(netdev))
  558. return;
  559. dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
  560. pr_info(" %s %s %s %s\n",
  561. "Queue [NTU] [NTC] [bi(ntc)->dma ]",
  562. "leng", "ntw", "timestamp");
  563. for (n = 0; n < adapter->num_tx_queues; n++) {
  564. tx_ring = adapter->tx_ring[n];
  565. tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
  566. pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
  567. n, tx_ring->next_to_use, tx_ring->next_to_clean,
  568. (u64)dma_unmap_addr(tx_buffer, dma),
  569. dma_unmap_len(tx_buffer, len),
  570. tx_buffer->next_to_watch,
  571. (u64)tx_buffer->time_stamp);
  572. }
  573. /* Print TX Rings */
  574. if (!netif_msg_tx_done(adapter))
  575. goto rx_ring_summary;
  576. dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
  577. /* Transmit Descriptor Formats
  578. *
  579. * 82598 Advanced Transmit Descriptor
  580. * +--------------------------------------------------------------+
  581. * 0 | Buffer Address [63:0] |
  582. * +--------------------------------------------------------------+
  583. * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
  584. * +--------------------------------------------------------------+
  585. * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
  586. *
  587. * 82598 Advanced Transmit Descriptor (Write-Back Format)
  588. * +--------------------------------------------------------------+
  589. * 0 | RSV [63:0] |
  590. * +--------------------------------------------------------------+
  591. * 8 | RSV | STA | NXTSEQ |
  592. * +--------------------------------------------------------------+
  593. * 63 36 35 32 31 0
  594. *
  595. * 82599+ Advanced Transmit Descriptor
  596. * +--------------------------------------------------------------+
  597. * 0 | Buffer Address [63:0] |
  598. * +--------------------------------------------------------------+
  599. * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
  600. * +--------------------------------------------------------------+
  601. * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
  602. *
  603. * 82599+ Advanced Transmit Descriptor (Write-Back Format)
  604. * +--------------------------------------------------------------+
  605. * 0 | RSV [63:0] |
  606. * +--------------------------------------------------------------+
  607. * 8 | RSV | STA | RSV |
  608. * +--------------------------------------------------------------+
  609. * 63 36 35 32 31 0
  610. */
  611. for (n = 0; n < adapter->num_tx_queues; n++) {
  612. tx_ring = adapter->tx_ring[n];
  613. pr_info("------------------------------------\n");
  614. pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
  615. pr_info("------------------------------------\n");
  616. pr_info("%s%s %s %s %s %s\n",
  617. "T [desc] [address 63:0 ] ",
  618. "[PlPOIdStDDt Ln] [bi->dma ] ",
  619. "leng", "ntw", "timestamp", "bi->skb");
  620. for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
  621. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  622. tx_buffer = &tx_ring->tx_buffer_info[i];
  623. u0 = (struct my_u0 *)tx_desc;
  624. if (dma_unmap_len(tx_buffer, len) > 0) {
  625. const char *ring_desc;
  626. if (i == tx_ring->next_to_use &&
  627. i == tx_ring->next_to_clean)
  628. ring_desc = " NTC/U";
  629. else if (i == tx_ring->next_to_use)
  630. ring_desc = " NTU";
  631. else if (i == tx_ring->next_to_clean)
  632. ring_desc = " NTC";
  633. else
  634. ring_desc = "";
  635. pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p%s",
  636. i,
  637. le64_to_cpu(u0->a),
  638. le64_to_cpu(u0->b),
  639. (u64)dma_unmap_addr(tx_buffer, dma),
  640. dma_unmap_len(tx_buffer, len),
  641. tx_buffer->next_to_watch,
  642. (u64)tx_buffer->time_stamp,
  643. tx_buffer->skb,
  644. ring_desc);
  645. if (netif_msg_pktdata(adapter) &&
  646. tx_buffer->skb)
  647. print_hex_dump(KERN_INFO, "",
  648. DUMP_PREFIX_ADDRESS, 16, 1,
  649. tx_buffer->skb->data,
  650. dma_unmap_len(tx_buffer, len),
  651. true);
  652. }
  653. }
  654. }
  655. /* Print RX Rings Summary */
  656. rx_ring_summary:
  657. dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
  658. pr_info("Queue [NTU] [NTC]\n");
  659. for (n = 0; n < adapter->num_rx_queues; n++) {
  660. rx_ring = adapter->rx_ring[n];
  661. pr_info("%5d %5X %5X\n",
  662. n, rx_ring->next_to_use, rx_ring->next_to_clean);
  663. }
  664. /* Print RX Rings */
  665. if (!netif_msg_rx_status(adapter))
  666. return;
  667. dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
  668. /* Receive Descriptor Formats
  669. *
  670. * 82598 Advanced Receive Descriptor (Read) Format
  671. * 63 1 0
  672. * +-----------------------------------------------------+
  673. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  674. * +----------------------------------------------+------+
  675. * 8 | Header Buffer Address [63:1] | DD |
  676. * +-----------------------------------------------------+
  677. *
  678. *
  679. * 82598 Advanced Receive Descriptor (Write-Back) Format
  680. *
  681. * 63 48 47 32 31 30 21 20 16 15 4 3 0
  682. * +------------------------------------------------------+
  683. * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
  684. * | Packet | IP | | | | Type | Type |
  685. * | Checksum | Ident | | | | | |
  686. * +------------------------------------------------------+
  687. * 8 | VLAN Tag | Length | Extended Error | Extended Status |
  688. * +------------------------------------------------------+
  689. * 63 48 47 32 31 20 19 0
  690. *
  691. * 82599+ Advanced Receive Descriptor (Read) Format
  692. * 63 1 0
  693. * +-----------------------------------------------------+
  694. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  695. * +----------------------------------------------+------+
  696. * 8 | Header Buffer Address [63:1] | DD |
  697. * +-----------------------------------------------------+
  698. *
  699. *
  700. * 82599+ Advanced Receive Descriptor (Write-Back) Format
  701. *
  702. * 63 48 47 32 31 30 21 20 17 16 4 3 0
  703. * +------------------------------------------------------+
  704. * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
  705. * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
  706. * |/ Flow Dir Flt ID | | | | | |
  707. * +------------------------------------------------------+
  708. * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
  709. * +------------------------------------------------------+
  710. * 63 48 47 32 31 20 19 0
  711. */
  712. for (n = 0; n < adapter->num_rx_queues; n++) {
  713. rx_ring = adapter->rx_ring[n];
  714. pr_info("------------------------------------\n");
  715. pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
  716. pr_info("------------------------------------\n");
  717. pr_info("%s%s%s\n",
  718. "R [desc] [ PktBuf A0] ",
  719. "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
  720. "<-- Adv Rx Read format");
  721. pr_info("%s%s%s\n",
  722. "RWB[desc] [PcsmIpSHl PtRs] ",
  723. "[vl er S cks ln] ---------------- [bi->skb ] ",
  724. "<-- Adv Rx Write-Back format");
  725. for (i = 0; i < rx_ring->count; i++) {
  726. const char *ring_desc;
  727. if (i == rx_ring->next_to_use)
  728. ring_desc = " NTU";
  729. else if (i == rx_ring->next_to_clean)
  730. ring_desc = " NTC";
  731. else
  732. ring_desc = "";
  733. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  734. rx_desc = IXGBE_RX_DESC(rx_ring, i);
  735. u0 = (struct my_u0 *)rx_desc;
  736. if (rx_desc->wb.upper.length) {
  737. /* Descriptor Done */
  738. pr_info("RWB[0x%03X] %016llX %016llX ---------------- %p%s\n",
  739. i,
  740. le64_to_cpu(u0->a),
  741. le64_to_cpu(u0->b),
  742. rx_buffer_info->skb,
  743. ring_desc);
  744. } else {
  745. pr_info("R [0x%03X] %016llX %016llX %016llX %p%s\n",
  746. i,
  747. le64_to_cpu(u0->a),
  748. le64_to_cpu(u0->b),
  749. (u64)rx_buffer_info->dma,
  750. rx_buffer_info->skb,
  751. ring_desc);
  752. if (netif_msg_pktdata(adapter) &&
  753. rx_buffer_info->dma) {
  754. print_hex_dump(KERN_INFO, "",
  755. DUMP_PREFIX_ADDRESS, 16, 1,
  756. page_address(rx_buffer_info->page) +
  757. rx_buffer_info->page_offset,
  758. ixgbe_rx_bufsz(rx_ring), true);
  759. }
  760. }
  761. }
  762. }
  763. }
  764. static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
  765. {
  766. u32 ctrl_ext;
  767. /* Let firmware take over control of h/w */
  768. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  769. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  770. ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
  771. }
  772. static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
  773. {
  774. u32 ctrl_ext;
  775. /* Let firmware know the driver has taken over */
  776. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  777. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  778. ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
  779. }
  780. /**
  781. * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
  782. * @adapter: pointer to adapter struct
  783. * @direction: 0 for Rx, 1 for Tx, -1 for other causes
  784. * @queue: queue to map the corresponding interrupt to
  785. * @msix_vector: the vector to map to the corresponding queue
  786. *
  787. */
  788. static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
  789. u8 queue, u8 msix_vector)
  790. {
  791. u32 ivar, index;
  792. struct ixgbe_hw *hw = &adapter->hw;
  793. switch (hw->mac.type) {
  794. case ixgbe_mac_82598EB:
  795. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  796. if (direction == -1)
  797. direction = 0;
  798. index = (((direction * 64) + queue) >> 2) & 0x1F;
  799. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
  800. ivar &= ~(0xFF << (8 * (queue & 0x3)));
  801. ivar |= (msix_vector << (8 * (queue & 0x3)));
  802. IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
  803. break;
  804. case ixgbe_mac_82599EB:
  805. case ixgbe_mac_X540:
  806. case ixgbe_mac_X550:
  807. case ixgbe_mac_X550EM_x:
  808. case ixgbe_mac_x550em_a:
  809. if (direction == -1) {
  810. /* other causes */
  811. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  812. index = ((queue & 1) * 8);
  813. ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
  814. ivar &= ~(0xFF << index);
  815. ivar |= (msix_vector << index);
  816. IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
  817. break;
  818. } else {
  819. /* tx or rx causes */
  820. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  821. index = ((16 * (queue & 1)) + (8 * direction));
  822. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
  823. ivar &= ~(0xFF << index);
  824. ivar |= (msix_vector << index);
  825. IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
  826. break;
  827. }
  828. default:
  829. break;
  830. }
  831. }
  832. static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
  833. u64 qmask)
  834. {
  835. u32 mask;
  836. switch (adapter->hw.mac.type) {
  837. case ixgbe_mac_82598EB:
  838. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  839. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
  840. break;
  841. case ixgbe_mac_82599EB:
  842. case ixgbe_mac_X540:
  843. case ixgbe_mac_X550:
  844. case ixgbe_mac_X550EM_x:
  845. case ixgbe_mac_x550em_a:
  846. mask = (qmask & 0xFFFFFFFF);
  847. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
  848. mask = (qmask >> 32);
  849. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
  850. break;
  851. default:
  852. break;
  853. }
  854. }
  855. static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
  856. {
  857. struct ixgbe_hw *hw = &adapter->hw;
  858. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  859. int i;
  860. u32 data;
  861. if ((hw->fc.current_mode != ixgbe_fc_full) &&
  862. (hw->fc.current_mode != ixgbe_fc_rx_pause))
  863. return;
  864. switch (hw->mac.type) {
  865. case ixgbe_mac_82598EB:
  866. data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  867. break;
  868. default:
  869. data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
  870. }
  871. hwstats->lxoffrxc += data;
  872. /* refill credits (no tx hang) if we received xoff */
  873. if (!data)
  874. return;
  875. for (i = 0; i < adapter->num_tx_queues; i++)
  876. clear_bit(__IXGBE_HANG_CHECK_ARMED,
  877. &adapter->tx_ring[i]->state);
  878. }
  879. static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
  880. {
  881. struct ixgbe_hw *hw = &adapter->hw;
  882. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  883. u32 xoff[8] = {0};
  884. u8 tc;
  885. int i;
  886. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  887. if (adapter->ixgbe_ieee_pfc)
  888. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  889. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
  890. ixgbe_update_xoff_rx_lfc(adapter);
  891. return;
  892. }
  893. /* update stats for each tc, only valid with PFC enabled */
  894. for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
  895. u32 pxoffrxc;
  896. switch (hw->mac.type) {
  897. case ixgbe_mac_82598EB:
  898. pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
  899. break;
  900. default:
  901. pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
  902. }
  903. hwstats->pxoffrxc[i] += pxoffrxc;
  904. /* Get the TC for given UP */
  905. tc = netdev_get_prio_tc_map(adapter->netdev, i);
  906. xoff[tc] += pxoffrxc;
  907. }
  908. /* disarm tx queues that have received xoff frames */
  909. for (i = 0; i < adapter->num_tx_queues; i++) {
  910. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  911. tc = tx_ring->dcb_tc;
  912. if (xoff[tc])
  913. clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
  914. }
  915. }
  916. static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
  917. {
  918. return ring->stats.packets;
  919. }
  920. static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
  921. {
  922. struct ixgbe_adapter *adapter;
  923. struct ixgbe_hw *hw;
  924. u32 head, tail;
  925. if (ring->l2_accel_priv)
  926. adapter = ring->l2_accel_priv->real_adapter;
  927. else
  928. adapter = netdev_priv(ring->netdev);
  929. hw = &adapter->hw;
  930. head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
  931. tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
  932. if (head != tail)
  933. return (head < tail) ?
  934. tail - head : (tail + ring->count - head);
  935. return 0;
  936. }
  937. static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
  938. {
  939. u32 tx_done = ixgbe_get_tx_completed(tx_ring);
  940. u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
  941. u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
  942. clear_check_for_tx_hang(tx_ring);
  943. /*
  944. * Check for a hung queue, but be thorough. This verifies
  945. * that a transmit has been completed since the previous
  946. * check AND there is at least one packet pending. The
  947. * ARMED bit is set to indicate a potential hang. The
  948. * bit is cleared if a pause frame is received to remove
  949. * false hang detection due to PFC or 802.3x frames. By
  950. * requiring this to fail twice we avoid races with
  951. * pfc clearing the ARMED bit and conditions where we
  952. * run the check_tx_hang logic with a transmit completion
  953. * pending but without time to complete it yet.
  954. */
  955. if (tx_done_old == tx_done && tx_pending)
  956. /* make sure it is true for two checks in a row */
  957. return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
  958. &tx_ring->state);
  959. /* update completed stats and continue */
  960. tx_ring->tx_stats.tx_done_old = tx_done;
  961. /* reset the countdown */
  962. clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
  963. return false;
  964. }
  965. /**
  966. * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
  967. * @adapter: driver private struct
  968. **/
  969. static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
  970. {
  971. /* Do the reset outside of interrupt context */
  972. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  973. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  974. e_warn(drv, "initiating reset due to tx timeout\n");
  975. ixgbe_service_event_schedule(adapter);
  976. }
  977. }
  978. /**
  979. * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
  980. **/
  981. static int ixgbe_tx_maxrate(struct net_device *netdev,
  982. int queue_index, u32 maxrate)
  983. {
  984. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  985. struct ixgbe_hw *hw = &adapter->hw;
  986. u32 bcnrc_val = ixgbe_link_mbps(adapter);
  987. if (!maxrate)
  988. return 0;
  989. /* Calculate the rate factor values to set */
  990. bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
  991. bcnrc_val /= maxrate;
  992. /* clear everything but the rate factor */
  993. bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
  994. IXGBE_RTTBCNRC_RF_DEC_MASK;
  995. /* enable the rate scheduler */
  996. bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
  997. IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index);
  998. IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
  999. return 0;
  1000. }
  1001. /**
  1002. * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
  1003. * @q_vector: structure containing interrupt and ring information
  1004. * @tx_ring: tx ring to clean
  1005. * @napi_budget: Used to determine if we are in netpoll
  1006. **/
  1007. static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
  1008. struct ixgbe_ring *tx_ring, int napi_budget)
  1009. {
  1010. struct ixgbe_adapter *adapter = q_vector->adapter;
  1011. struct ixgbe_tx_buffer *tx_buffer;
  1012. union ixgbe_adv_tx_desc *tx_desc;
  1013. unsigned int total_bytes = 0, total_packets = 0;
  1014. unsigned int budget = q_vector->tx.work_limit;
  1015. unsigned int i = tx_ring->next_to_clean;
  1016. if (test_bit(__IXGBE_DOWN, &adapter->state))
  1017. return true;
  1018. tx_buffer = &tx_ring->tx_buffer_info[i];
  1019. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  1020. i -= tx_ring->count;
  1021. do {
  1022. union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
  1023. /* if next_to_watch is not set then there is no work pending */
  1024. if (!eop_desc)
  1025. break;
  1026. /* prevent any other reads prior to eop_desc */
  1027. read_barrier_depends();
  1028. /* if DD is not set pending work has not been completed */
  1029. if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
  1030. break;
  1031. /* clear next_to_watch to prevent false hangs */
  1032. tx_buffer->next_to_watch = NULL;
  1033. /* update the statistics for this packet */
  1034. total_bytes += tx_buffer->bytecount;
  1035. total_packets += tx_buffer->gso_segs;
  1036. /* free the skb */
  1037. napi_consume_skb(tx_buffer->skb, napi_budget);
  1038. /* unmap skb header data */
  1039. dma_unmap_single(tx_ring->dev,
  1040. dma_unmap_addr(tx_buffer, dma),
  1041. dma_unmap_len(tx_buffer, len),
  1042. DMA_TO_DEVICE);
  1043. /* clear tx_buffer data */
  1044. dma_unmap_len_set(tx_buffer, len, 0);
  1045. /* unmap remaining buffers */
  1046. while (tx_desc != eop_desc) {
  1047. tx_buffer++;
  1048. tx_desc++;
  1049. i++;
  1050. if (unlikely(!i)) {
  1051. i -= tx_ring->count;
  1052. tx_buffer = tx_ring->tx_buffer_info;
  1053. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  1054. }
  1055. /* unmap any remaining paged data */
  1056. if (dma_unmap_len(tx_buffer, len)) {
  1057. dma_unmap_page(tx_ring->dev,
  1058. dma_unmap_addr(tx_buffer, dma),
  1059. dma_unmap_len(tx_buffer, len),
  1060. DMA_TO_DEVICE);
  1061. dma_unmap_len_set(tx_buffer, len, 0);
  1062. }
  1063. }
  1064. /* move us one more past the eop_desc for start of next pkt */
  1065. tx_buffer++;
  1066. tx_desc++;
  1067. i++;
  1068. if (unlikely(!i)) {
  1069. i -= tx_ring->count;
  1070. tx_buffer = tx_ring->tx_buffer_info;
  1071. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  1072. }
  1073. /* issue prefetch for next Tx descriptor */
  1074. prefetch(tx_desc);
  1075. /* update budget accounting */
  1076. budget--;
  1077. } while (likely(budget));
  1078. i += tx_ring->count;
  1079. tx_ring->next_to_clean = i;
  1080. u64_stats_update_begin(&tx_ring->syncp);
  1081. tx_ring->stats.bytes += total_bytes;
  1082. tx_ring->stats.packets += total_packets;
  1083. u64_stats_update_end(&tx_ring->syncp);
  1084. q_vector->tx.total_bytes += total_bytes;
  1085. q_vector->tx.total_packets += total_packets;
  1086. if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
  1087. /* schedule immediate reset if we believe we hung */
  1088. struct ixgbe_hw *hw = &adapter->hw;
  1089. e_err(drv, "Detected Tx Unit Hang\n"
  1090. " Tx Queue <%d>\n"
  1091. " TDH, TDT <%x>, <%x>\n"
  1092. " next_to_use <%x>\n"
  1093. " next_to_clean <%x>\n"
  1094. "tx_buffer_info[next_to_clean]\n"
  1095. " time_stamp <%lx>\n"
  1096. " jiffies <%lx>\n",
  1097. tx_ring->queue_index,
  1098. IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
  1099. IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
  1100. tx_ring->next_to_use, i,
  1101. tx_ring->tx_buffer_info[i].time_stamp, jiffies);
  1102. netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
  1103. e_info(probe,
  1104. "tx hang %d detected on queue %d, resetting adapter\n",
  1105. adapter->tx_timeout_count + 1, tx_ring->queue_index);
  1106. /* schedule immediate reset if we believe we hung */
  1107. ixgbe_tx_timeout_reset(adapter);
  1108. /* the adapter is about to reset, no point in enabling stuff */
  1109. return true;
  1110. }
  1111. netdev_tx_completed_queue(txring_txq(tx_ring),
  1112. total_packets, total_bytes);
  1113. #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
  1114. if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
  1115. (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
  1116. /* Make sure that anybody stopping the queue after this
  1117. * sees the new next_to_clean.
  1118. */
  1119. smp_mb();
  1120. if (__netif_subqueue_stopped(tx_ring->netdev,
  1121. tx_ring->queue_index)
  1122. && !test_bit(__IXGBE_DOWN, &adapter->state)) {
  1123. netif_wake_subqueue(tx_ring->netdev,
  1124. tx_ring->queue_index);
  1125. ++tx_ring->tx_stats.restart_queue;
  1126. }
  1127. }
  1128. return !!budget;
  1129. }
  1130. #ifdef CONFIG_IXGBE_DCA
  1131. static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
  1132. struct ixgbe_ring *tx_ring,
  1133. int cpu)
  1134. {
  1135. struct ixgbe_hw *hw = &adapter->hw;
  1136. u32 txctrl = 0;
  1137. u16 reg_offset;
  1138. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1139. txctrl = dca3_get_tag(tx_ring->dev, cpu);
  1140. switch (hw->mac.type) {
  1141. case ixgbe_mac_82598EB:
  1142. reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
  1143. break;
  1144. case ixgbe_mac_82599EB:
  1145. case ixgbe_mac_X540:
  1146. reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
  1147. txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
  1148. break;
  1149. default:
  1150. /* for unknown hardware do not write register */
  1151. return;
  1152. }
  1153. /*
  1154. * We can enable relaxed ordering for reads, but not writes when
  1155. * DCA is enabled. This is due to a known issue in some chipsets
  1156. * which will cause the DCA tag to be cleared.
  1157. */
  1158. txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
  1159. IXGBE_DCA_TXCTRL_DATA_RRO_EN |
  1160. IXGBE_DCA_TXCTRL_DESC_DCA_EN;
  1161. IXGBE_WRITE_REG(hw, reg_offset, txctrl);
  1162. }
  1163. static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
  1164. struct ixgbe_ring *rx_ring,
  1165. int cpu)
  1166. {
  1167. struct ixgbe_hw *hw = &adapter->hw;
  1168. u32 rxctrl = 0;
  1169. u8 reg_idx = rx_ring->reg_idx;
  1170. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1171. rxctrl = dca3_get_tag(rx_ring->dev, cpu);
  1172. switch (hw->mac.type) {
  1173. case ixgbe_mac_82599EB:
  1174. case ixgbe_mac_X540:
  1175. rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
  1176. break;
  1177. default:
  1178. break;
  1179. }
  1180. /*
  1181. * We can enable relaxed ordering for reads, but not writes when
  1182. * DCA is enabled. This is due to a known issue in some chipsets
  1183. * which will cause the DCA tag to be cleared.
  1184. */
  1185. rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
  1186. IXGBE_DCA_RXCTRL_DATA_DCA_EN |
  1187. IXGBE_DCA_RXCTRL_DESC_DCA_EN;
  1188. IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
  1189. }
  1190. static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
  1191. {
  1192. struct ixgbe_adapter *adapter = q_vector->adapter;
  1193. struct ixgbe_ring *ring;
  1194. int cpu = get_cpu();
  1195. if (q_vector->cpu == cpu)
  1196. goto out_no_update;
  1197. ixgbe_for_each_ring(ring, q_vector->tx)
  1198. ixgbe_update_tx_dca(adapter, ring, cpu);
  1199. ixgbe_for_each_ring(ring, q_vector->rx)
  1200. ixgbe_update_rx_dca(adapter, ring, cpu);
  1201. q_vector->cpu = cpu;
  1202. out_no_update:
  1203. put_cpu();
  1204. }
  1205. static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
  1206. {
  1207. int i;
  1208. /* always use CB2 mode, difference is masked in the CB driver */
  1209. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1210. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1211. IXGBE_DCA_CTRL_DCA_MODE_CB2);
  1212. else
  1213. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1214. IXGBE_DCA_CTRL_DCA_DISABLE);
  1215. for (i = 0; i < adapter->num_q_vectors; i++) {
  1216. adapter->q_vector[i]->cpu = -1;
  1217. ixgbe_update_dca(adapter->q_vector[i]);
  1218. }
  1219. }
  1220. static int __ixgbe_notify_dca(struct device *dev, void *data)
  1221. {
  1222. struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
  1223. unsigned long event = *(unsigned long *)data;
  1224. if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
  1225. return 0;
  1226. switch (event) {
  1227. case DCA_PROVIDER_ADD:
  1228. /* if we're already enabled, don't do it again */
  1229. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1230. break;
  1231. if (dca_add_requester(dev) == 0) {
  1232. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  1233. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1234. IXGBE_DCA_CTRL_DCA_MODE_CB2);
  1235. break;
  1236. }
  1237. /* Fall Through since DCA is disabled. */
  1238. case DCA_PROVIDER_REMOVE:
  1239. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  1240. dca_remove_requester(dev);
  1241. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  1242. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1243. IXGBE_DCA_CTRL_DCA_DISABLE);
  1244. }
  1245. break;
  1246. }
  1247. return 0;
  1248. }
  1249. #endif /* CONFIG_IXGBE_DCA */
  1250. #define IXGBE_RSS_L4_TYPES_MASK \
  1251. ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
  1252. (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
  1253. (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
  1254. (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
  1255. static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
  1256. union ixgbe_adv_rx_desc *rx_desc,
  1257. struct sk_buff *skb)
  1258. {
  1259. u16 rss_type;
  1260. if (!(ring->netdev->features & NETIF_F_RXHASH))
  1261. return;
  1262. rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
  1263. IXGBE_RXDADV_RSSTYPE_MASK;
  1264. if (!rss_type)
  1265. return;
  1266. skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
  1267. (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
  1268. PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
  1269. }
  1270. #ifdef IXGBE_FCOE
  1271. /**
  1272. * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
  1273. * @ring: structure containing ring specific data
  1274. * @rx_desc: advanced rx descriptor
  1275. *
  1276. * Returns : true if it is FCoE pkt
  1277. */
  1278. static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
  1279. union ixgbe_adv_rx_desc *rx_desc)
  1280. {
  1281. __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  1282. return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
  1283. ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
  1284. (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
  1285. IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
  1286. }
  1287. #endif /* IXGBE_FCOE */
  1288. /**
  1289. * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
  1290. * @ring: structure containing ring specific data
  1291. * @rx_desc: current Rx descriptor being processed
  1292. * @skb: skb currently being received and modified
  1293. **/
  1294. static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
  1295. union ixgbe_adv_rx_desc *rx_desc,
  1296. struct sk_buff *skb)
  1297. {
  1298. __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  1299. bool encap_pkt = false;
  1300. skb_checksum_none_assert(skb);
  1301. /* Rx csum disabled */
  1302. if (!(ring->netdev->features & NETIF_F_RXCSUM))
  1303. return;
  1304. /* check for VXLAN and Geneve packets */
  1305. if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) {
  1306. encap_pkt = true;
  1307. skb->encapsulation = 1;
  1308. }
  1309. /* if IP and error */
  1310. if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
  1311. ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
  1312. ring->rx_stats.csum_err++;
  1313. return;
  1314. }
  1315. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
  1316. return;
  1317. if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
  1318. /*
  1319. * 82599 errata, UDP frames with a 0 checksum can be marked as
  1320. * checksum errors.
  1321. */
  1322. if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
  1323. test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
  1324. return;
  1325. ring->rx_stats.csum_err++;
  1326. return;
  1327. }
  1328. /* It must be a TCP or UDP packet with a valid checksum */
  1329. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1330. if (encap_pkt) {
  1331. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
  1332. return;
  1333. if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
  1334. skb->ip_summed = CHECKSUM_NONE;
  1335. return;
  1336. }
  1337. /* If we checked the outer header let the stack know */
  1338. skb->csum_level = 1;
  1339. }
  1340. }
  1341. static inline unsigned int ixgbe_rx_offset(struct ixgbe_ring *rx_ring)
  1342. {
  1343. return ring_uses_build_skb(rx_ring) ? IXGBE_SKB_PAD : 0;
  1344. }
  1345. static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
  1346. struct ixgbe_rx_buffer *bi)
  1347. {
  1348. struct page *page = bi->page;
  1349. dma_addr_t dma;
  1350. /* since we are recycling buffers we should seldom need to alloc */
  1351. if (likely(page))
  1352. return true;
  1353. /* alloc new page for storage */
  1354. page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
  1355. if (unlikely(!page)) {
  1356. rx_ring->rx_stats.alloc_rx_page_failed++;
  1357. return false;
  1358. }
  1359. /* map page for use */
  1360. dma = dma_map_page_attrs(rx_ring->dev, page, 0,
  1361. ixgbe_rx_pg_size(rx_ring),
  1362. DMA_FROM_DEVICE,
  1363. IXGBE_RX_DMA_ATTR);
  1364. /*
  1365. * if mapping failed free memory back to system since
  1366. * there isn't much point in holding memory we can't use
  1367. */
  1368. if (dma_mapping_error(rx_ring->dev, dma)) {
  1369. __free_pages(page, ixgbe_rx_pg_order(rx_ring));
  1370. rx_ring->rx_stats.alloc_rx_page_failed++;
  1371. return false;
  1372. }
  1373. bi->dma = dma;
  1374. bi->page = page;
  1375. bi->page_offset = ixgbe_rx_offset(rx_ring);
  1376. bi->pagecnt_bias = 1;
  1377. return true;
  1378. }
  1379. /**
  1380. * ixgbe_alloc_rx_buffers - Replace used receive buffers
  1381. * @rx_ring: ring to place buffers on
  1382. * @cleaned_count: number of buffers to replace
  1383. **/
  1384. void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
  1385. {
  1386. union ixgbe_adv_rx_desc *rx_desc;
  1387. struct ixgbe_rx_buffer *bi;
  1388. u16 i = rx_ring->next_to_use;
  1389. u16 bufsz;
  1390. /* nothing to do */
  1391. if (!cleaned_count)
  1392. return;
  1393. rx_desc = IXGBE_RX_DESC(rx_ring, i);
  1394. bi = &rx_ring->rx_buffer_info[i];
  1395. i -= rx_ring->count;
  1396. bufsz = ixgbe_rx_bufsz(rx_ring);
  1397. do {
  1398. if (!ixgbe_alloc_mapped_page(rx_ring, bi))
  1399. break;
  1400. /* sync the buffer for use by the device */
  1401. dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
  1402. bi->page_offset, bufsz,
  1403. DMA_FROM_DEVICE);
  1404. /*
  1405. * Refresh the desc even if buffer_addrs didn't change
  1406. * because each write-back erases this info.
  1407. */
  1408. rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
  1409. rx_desc++;
  1410. bi++;
  1411. i++;
  1412. if (unlikely(!i)) {
  1413. rx_desc = IXGBE_RX_DESC(rx_ring, 0);
  1414. bi = rx_ring->rx_buffer_info;
  1415. i -= rx_ring->count;
  1416. }
  1417. /* clear the length for the next_to_use descriptor */
  1418. rx_desc->wb.upper.length = 0;
  1419. cleaned_count--;
  1420. } while (cleaned_count);
  1421. i += rx_ring->count;
  1422. if (rx_ring->next_to_use != i) {
  1423. rx_ring->next_to_use = i;
  1424. /* update next to alloc since we have filled the ring */
  1425. rx_ring->next_to_alloc = i;
  1426. /* Force memory writes to complete before letting h/w
  1427. * know there are new descriptors to fetch. (Only
  1428. * applicable for weak-ordered memory model archs,
  1429. * such as IA-64).
  1430. */
  1431. wmb();
  1432. writel(i, rx_ring->tail);
  1433. }
  1434. }
  1435. static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
  1436. struct sk_buff *skb)
  1437. {
  1438. u16 hdr_len = skb_headlen(skb);
  1439. /* set gso_size to avoid messing up TCP MSS */
  1440. skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
  1441. IXGBE_CB(skb)->append_cnt);
  1442. skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
  1443. }
  1444. static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
  1445. struct sk_buff *skb)
  1446. {
  1447. /* if append_cnt is 0 then frame is not RSC */
  1448. if (!IXGBE_CB(skb)->append_cnt)
  1449. return;
  1450. rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
  1451. rx_ring->rx_stats.rsc_flush++;
  1452. ixgbe_set_rsc_gso_size(rx_ring, skb);
  1453. /* gso_size is computed using append_cnt so always clear it last */
  1454. IXGBE_CB(skb)->append_cnt = 0;
  1455. }
  1456. /**
  1457. * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
  1458. * @rx_ring: rx descriptor ring packet is being transacted on
  1459. * @rx_desc: pointer to the EOP Rx descriptor
  1460. * @skb: pointer to current skb being populated
  1461. *
  1462. * This function checks the ring, descriptor, and packet information in
  1463. * order to populate the hash, checksum, VLAN, timestamp, protocol, and
  1464. * other fields within the skb.
  1465. **/
  1466. static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
  1467. union ixgbe_adv_rx_desc *rx_desc,
  1468. struct sk_buff *skb)
  1469. {
  1470. struct net_device *dev = rx_ring->netdev;
  1471. u32 flags = rx_ring->q_vector->adapter->flags;
  1472. ixgbe_update_rsc_stats(rx_ring, skb);
  1473. ixgbe_rx_hash(rx_ring, rx_desc, skb);
  1474. ixgbe_rx_checksum(rx_ring, rx_desc, skb);
  1475. if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED))
  1476. ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
  1477. if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
  1478. ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
  1479. u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
  1480. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
  1481. }
  1482. skb_record_rx_queue(skb, rx_ring->queue_index);
  1483. skb->protocol = eth_type_trans(skb, dev);
  1484. }
  1485. static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
  1486. struct sk_buff *skb)
  1487. {
  1488. napi_gro_receive(&q_vector->napi, skb);
  1489. }
  1490. /**
  1491. * ixgbe_is_non_eop - process handling of non-EOP buffers
  1492. * @rx_ring: Rx ring being processed
  1493. * @rx_desc: Rx descriptor for current buffer
  1494. * @skb: Current socket buffer containing buffer in progress
  1495. *
  1496. * This function updates next to clean. If the buffer is an EOP buffer
  1497. * this function exits returning false, otherwise it will place the
  1498. * sk_buff in the next buffer to be chained and return true indicating
  1499. * that this is in fact a non-EOP buffer.
  1500. **/
  1501. static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
  1502. union ixgbe_adv_rx_desc *rx_desc,
  1503. struct sk_buff *skb)
  1504. {
  1505. u32 ntc = rx_ring->next_to_clean + 1;
  1506. /* fetch, update, and store next to clean */
  1507. ntc = (ntc < rx_ring->count) ? ntc : 0;
  1508. rx_ring->next_to_clean = ntc;
  1509. prefetch(IXGBE_RX_DESC(rx_ring, ntc));
  1510. /* update RSC append count if present */
  1511. if (ring_is_rsc_enabled(rx_ring)) {
  1512. __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
  1513. cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
  1514. if (unlikely(rsc_enabled)) {
  1515. u32 rsc_cnt = le32_to_cpu(rsc_enabled);
  1516. rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
  1517. IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
  1518. /* update ntc based on RSC value */
  1519. ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
  1520. ntc &= IXGBE_RXDADV_NEXTP_MASK;
  1521. ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
  1522. }
  1523. }
  1524. /* if we are the last buffer then there is nothing else to do */
  1525. if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
  1526. return false;
  1527. /* place skb in next buffer to be received */
  1528. rx_ring->rx_buffer_info[ntc].skb = skb;
  1529. rx_ring->rx_stats.non_eop_descs++;
  1530. return true;
  1531. }
  1532. /**
  1533. * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
  1534. * @rx_ring: rx descriptor ring packet is being transacted on
  1535. * @skb: pointer to current skb being adjusted
  1536. *
  1537. * This function is an ixgbe specific version of __pskb_pull_tail. The
  1538. * main difference between this version and the original function is that
  1539. * this function can make several assumptions about the state of things
  1540. * that allow for significant optimizations versus the standard function.
  1541. * As a result we can do things like drop a frag and maintain an accurate
  1542. * truesize for the skb.
  1543. */
  1544. static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
  1545. struct sk_buff *skb)
  1546. {
  1547. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
  1548. unsigned char *va;
  1549. unsigned int pull_len;
  1550. /*
  1551. * it is valid to use page_address instead of kmap since we are
  1552. * working with pages allocated out of the lomem pool per
  1553. * alloc_page(GFP_ATOMIC)
  1554. */
  1555. va = skb_frag_address(frag);
  1556. /*
  1557. * we need the header to contain the greater of either ETH_HLEN or
  1558. * 60 bytes if the skb->len is less than 60 for skb_pad.
  1559. */
  1560. pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
  1561. /* align pull length to size of long to optimize memcpy performance */
  1562. skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
  1563. /* update all of the pointers */
  1564. skb_frag_size_sub(frag, pull_len);
  1565. frag->page_offset += pull_len;
  1566. skb->data_len -= pull_len;
  1567. skb->tail += pull_len;
  1568. }
  1569. /**
  1570. * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
  1571. * @rx_ring: rx descriptor ring packet is being transacted on
  1572. * @skb: pointer to current skb being updated
  1573. *
  1574. * This function provides a basic DMA sync up for the first fragment of an
  1575. * skb. The reason for doing this is that the first fragment cannot be
  1576. * unmapped until we have reached the end of packet descriptor for a buffer
  1577. * chain.
  1578. */
  1579. static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
  1580. struct sk_buff *skb)
  1581. {
  1582. /* if the page was released unmap it, else just sync our portion */
  1583. if (unlikely(IXGBE_CB(skb)->page_released)) {
  1584. dma_unmap_page_attrs(rx_ring->dev, IXGBE_CB(skb)->dma,
  1585. ixgbe_rx_pg_size(rx_ring),
  1586. DMA_FROM_DEVICE,
  1587. IXGBE_RX_DMA_ATTR);
  1588. } else {
  1589. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
  1590. dma_sync_single_range_for_cpu(rx_ring->dev,
  1591. IXGBE_CB(skb)->dma,
  1592. frag->page_offset,
  1593. skb_frag_size(frag),
  1594. DMA_FROM_DEVICE);
  1595. }
  1596. }
  1597. /**
  1598. * ixgbe_cleanup_headers - Correct corrupted or empty headers
  1599. * @rx_ring: rx descriptor ring packet is being transacted on
  1600. * @rx_desc: pointer to the EOP Rx descriptor
  1601. * @skb: pointer to current skb being fixed
  1602. *
  1603. * Check for corrupted packet headers caused by senders on the local L2
  1604. * embedded NIC switch not setting up their Tx Descriptors right. These
  1605. * should be very rare.
  1606. *
  1607. * Also address the case where we are pulling data in on pages only
  1608. * and as such no data is present in the skb header.
  1609. *
  1610. * In addition if skb is not at least 60 bytes we need to pad it so that
  1611. * it is large enough to qualify as a valid Ethernet frame.
  1612. *
  1613. * Returns true if an error was encountered and skb was freed.
  1614. **/
  1615. static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
  1616. union ixgbe_adv_rx_desc *rx_desc,
  1617. struct sk_buff *skb)
  1618. {
  1619. struct net_device *netdev = rx_ring->netdev;
  1620. /* verify that the packet does not have any known errors */
  1621. if (unlikely(ixgbe_test_staterr(rx_desc,
  1622. IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
  1623. !(netdev->features & NETIF_F_RXALL))) {
  1624. dev_kfree_skb_any(skb);
  1625. return true;
  1626. }
  1627. /* place header in linear portion of buffer */
  1628. if (!skb_headlen(skb))
  1629. ixgbe_pull_tail(rx_ring, skb);
  1630. #ifdef IXGBE_FCOE
  1631. /* do not attempt to pad FCoE Frames as this will disrupt DDP */
  1632. if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
  1633. return false;
  1634. #endif
  1635. /* if eth_skb_pad returns an error the skb was freed */
  1636. if (eth_skb_pad(skb))
  1637. return true;
  1638. return false;
  1639. }
  1640. /**
  1641. * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
  1642. * @rx_ring: rx descriptor ring to store buffers on
  1643. * @old_buff: donor buffer to have page reused
  1644. *
  1645. * Synchronizes page for reuse by the adapter
  1646. **/
  1647. static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
  1648. struct ixgbe_rx_buffer *old_buff)
  1649. {
  1650. struct ixgbe_rx_buffer *new_buff;
  1651. u16 nta = rx_ring->next_to_alloc;
  1652. new_buff = &rx_ring->rx_buffer_info[nta];
  1653. /* update, and store next to alloc */
  1654. nta++;
  1655. rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
  1656. /* Transfer page from old buffer to new buffer.
  1657. * Move each member individually to avoid possible store
  1658. * forwarding stalls and unnecessary copy of skb.
  1659. */
  1660. new_buff->dma = old_buff->dma;
  1661. new_buff->page = old_buff->page;
  1662. new_buff->page_offset = old_buff->page_offset;
  1663. new_buff->pagecnt_bias = old_buff->pagecnt_bias;
  1664. }
  1665. static inline bool ixgbe_page_is_reserved(struct page *page)
  1666. {
  1667. return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
  1668. }
  1669. static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer *rx_buffer)
  1670. {
  1671. unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
  1672. struct page *page = rx_buffer->page;
  1673. /* avoid re-using remote pages */
  1674. if (unlikely(ixgbe_page_is_reserved(page)))
  1675. return false;
  1676. #if (PAGE_SIZE < 8192)
  1677. /* if we are only owner of page we can reuse it */
  1678. if (unlikely((page_ref_count(page) - pagecnt_bias) > 1))
  1679. return false;
  1680. #else
  1681. /* The last offset is a bit aggressive in that we assume the
  1682. * worst case of FCoE being enabled and using a 3K buffer.
  1683. * However this should have minimal impact as the 1K extra is
  1684. * still less than one buffer in size.
  1685. */
  1686. #define IXGBE_LAST_OFFSET \
  1687. (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K)
  1688. if (rx_buffer->page_offset > IXGBE_LAST_OFFSET)
  1689. return false;
  1690. #endif
  1691. /* If we have drained the page fragment pool we need to update
  1692. * the pagecnt_bias and page count so that we fully restock the
  1693. * number of references the driver holds.
  1694. */
  1695. if (unlikely(!pagecnt_bias)) {
  1696. page_ref_add(page, USHRT_MAX);
  1697. rx_buffer->pagecnt_bias = USHRT_MAX;
  1698. }
  1699. return true;
  1700. }
  1701. /**
  1702. * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
  1703. * @rx_ring: rx descriptor ring to transact packets on
  1704. * @rx_buffer: buffer containing page to add
  1705. * @rx_desc: descriptor containing length of buffer written by hardware
  1706. * @skb: sk_buff to place the data into
  1707. *
  1708. * This function will add the data contained in rx_buffer->page to the skb.
  1709. * This is done either through a direct copy if the data in the buffer is
  1710. * less than the skb header size, otherwise it will just attach the page as
  1711. * a frag to the skb.
  1712. *
  1713. * The function will then update the page offset if necessary and return
  1714. * true if the buffer can be reused by the adapter.
  1715. **/
  1716. static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
  1717. struct ixgbe_rx_buffer *rx_buffer,
  1718. struct sk_buff *skb,
  1719. unsigned int size)
  1720. {
  1721. #if (PAGE_SIZE < 8192)
  1722. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1723. #else
  1724. unsigned int truesize = ring_uses_build_skb(rx_ring) ?
  1725. SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
  1726. SKB_DATA_ALIGN(size);
  1727. #endif
  1728. skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
  1729. rx_buffer->page_offset, size, truesize);
  1730. #if (PAGE_SIZE < 8192)
  1731. rx_buffer->page_offset ^= truesize;
  1732. #else
  1733. rx_buffer->page_offset += truesize;
  1734. #endif
  1735. }
  1736. static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring,
  1737. union ixgbe_adv_rx_desc *rx_desc,
  1738. struct sk_buff **skb,
  1739. const unsigned int size)
  1740. {
  1741. struct ixgbe_rx_buffer *rx_buffer;
  1742. rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
  1743. prefetchw(rx_buffer->page);
  1744. *skb = rx_buffer->skb;
  1745. /* Delay unmapping of the first packet. It carries the header
  1746. * information, HW may still access the header after the writeback.
  1747. * Only unmap it when EOP is reached
  1748. */
  1749. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) {
  1750. if (!*skb)
  1751. goto skip_sync;
  1752. } else {
  1753. if (*skb)
  1754. ixgbe_dma_sync_frag(rx_ring, *skb);
  1755. }
  1756. /* we are reusing so sync this buffer for CPU use */
  1757. dma_sync_single_range_for_cpu(rx_ring->dev,
  1758. rx_buffer->dma,
  1759. rx_buffer->page_offset,
  1760. size,
  1761. DMA_FROM_DEVICE);
  1762. skip_sync:
  1763. rx_buffer->pagecnt_bias--;
  1764. return rx_buffer;
  1765. }
  1766. static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring,
  1767. struct ixgbe_rx_buffer *rx_buffer,
  1768. struct sk_buff *skb)
  1769. {
  1770. if (ixgbe_can_reuse_rx_page(rx_buffer)) {
  1771. /* hand second half of page back to the ring */
  1772. ixgbe_reuse_rx_page(rx_ring, rx_buffer);
  1773. } else {
  1774. if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
  1775. /* the page has been released from the ring */
  1776. IXGBE_CB(skb)->page_released = true;
  1777. } else {
  1778. /* we are not reusing the buffer so unmap it */
  1779. dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
  1780. ixgbe_rx_pg_size(rx_ring),
  1781. DMA_FROM_DEVICE,
  1782. IXGBE_RX_DMA_ATTR);
  1783. }
  1784. __page_frag_cache_drain(rx_buffer->page,
  1785. rx_buffer->pagecnt_bias);
  1786. }
  1787. /* clear contents of rx_buffer */
  1788. rx_buffer->page = NULL;
  1789. rx_buffer->skb = NULL;
  1790. }
  1791. static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring,
  1792. struct ixgbe_rx_buffer *rx_buffer,
  1793. union ixgbe_adv_rx_desc *rx_desc,
  1794. unsigned int size)
  1795. {
  1796. void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
  1797. #if (PAGE_SIZE < 8192)
  1798. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1799. #else
  1800. unsigned int truesize = SKB_DATA_ALIGN(size);
  1801. #endif
  1802. struct sk_buff *skb;
  1803. /* prefetch first cache line of first page */
  1804. prefetch(va);
  1805. #if L1_CACHE_BYTES < 128
  1806. prefetch(va + L1_CACHE_BYTES);
  1807. #endif
  1808. /* allocate a skb to store the frags */
  1809. skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE);
  1810. if (unlikely(!skb))
  1811. return NULL;
  1812. if (size > IXGBE_RX_HDR_SIZE) {
  1813. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
  1814. IXGBE_CB(skb)->dma = rx_buffer->dma;
  1815. skb_add_rx_frag(skb, 0, rx_buffer->page,
  1816. rx_buffer->page_offset,
  1817. size, truesize);
  1818. #if (PAGE_SIZE < 8192)
  1819. rx_buffer->page_offset ^= truesize;
  1820. #else
  1821. rx_buffer->page_offset += truesize;
  1822. #endif
  1823. } else {
  1824. memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
  1825. rx_buffer->pagecnt_bias++;
  1826. }
  1827. return skb;
  1828. }
  1829. static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,
  1830. struct ixgbe_rx_buffer *rx_buffer,
  1831. union ixgbe_adv_rx_desc *rx_desc,
  1832. unsigned int size)
  1833. {
  1834. void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
  1835. #if (PAGE_SIZE < 8192)
  1836. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1837. #else
  1838. unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
  1839. SKB_DATA_ALIGN(IXGBE_SKB_PAD + size);
  1840. #endif
  1841. struct sk_buff *skb;
  1842. /* prefetch first cache line of first page */
  1843. prefetch(va);
  1844. #if L1_CACHE_BYTES < 128
  1845. prefetch(va + L1_CACHE_BYTES);
  1846. #endif
  1847. /* build an skb around the page buffer */
  1848. skb = build_skb(va - IXGBE_SKB_PAD, truesize);
  1849. if (unlikely(!skb))
  1850. return NULL;
  1851. /* update pointers within the skb to store the data */
  1852. skb_reserve(skb, IXGBE_SKB_PAD);
  1853. __skb_put(skb, size);
  1854. /* record DMA address if this is the start of a chain of buffers */
  1855. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
  1856. IXGBE_CB(skb)->dma = rx_buffer->dma;
  1857. /* update buffer offset */
  1858. #if (PAGE_SIZE < 8192)
  1859. rx_buffer->page_offset ^= truesize;
  1860. #else
  1861. rx_buffer->page_offset += truesize;
  1862. #endif
  1863. return skb;
  1864. }
  1865. /**
  1866. * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
  1867. * @q_vector: structure containing interrupt and ring information
  1868. * @rx_ring: rx descriptor ring to transact packets on
  1869. * @budget: Total limit on number of packets to process
  1870. *
  1871. * This function provides a "bounce buffer" approach to Rx interrupt
  1872. * processing. The advantage to this is that on systems that have
  1873. * expensive overhead for IOMMU access this provides a means of avoiding
  1874. * it by maintaining the mapping of the page to the syste.
  1875. *
  1876. * Returns amount of work completed
  1877. **/
  1878. static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
  1879. struct ixgbe_ring *rx_ring,
  1880. const int budget)
  1881. {
  1882. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  1883. #ifdef IXGBE_FCOE
  1884. struct ixgbe_adapter *adapter = q_vector->adapter;
  1885. int ddp_bytes;
  1886. unsigned int mss = 0;
  1887. #endif /* IXGBE_FCOE */
  1888. u16 cleaned_count = ixgbe_desc_unused(rx_ring);
  1889. while (likely(total_rx_packets < budget)) {
  1890. union ixgbe_adv_rx_desc *rx_desc;
  1891. struct ixgbe_rx_buffer *rx_buffer;
  1892. struct sk_buff *skb;
  1893. unsigned int size;
  1894. /* return some buffers to hardware, one at a time is too slow */
  1895. if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
  1896. ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
  1897. cleaned_count = 0;
  1898. }
  1899. rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
  1900. size = le16_to_cpu(rx_desc->wb.upper.length);
  1901. if (!size)
  1902. break;
  1903. /* This memory barrier is needed to keep us from reading
  1904. * any other fields out of the rx_desc until we know the
  1905. * descriptor has been written back
  1906. */
  1907. dma_rmb();
  1908. rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size);
  1909. /* retrieve a buffer from the ring */
  1910. if (skb)
  1911. ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size);
  1912. else if (ring_uses_build_skb(rx_ring))
  1913. skb = ixgbe_build_skb(rx_ring, rx_buffer,
  1914. rx_desc, size);
  1915. else
  1916. skb = ixgbe_construct_skb(rx_ring, rx_buffer,
  1917. rx_desc, size);
  1918. /* exit if we failed to retrieve a buffer */
  1919. if (!skb) {
  1920. rx_ring->rx_stats.alloc_rx_buff_failed++;
  1921. rx_buffer->pagecnt_bias++;
  1922. break;
  1923. }
  1924. ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb);
  1925. cleaned_count++;
  1926. /* place incomplete frames back on ring for completion */
  1927. if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
  1928. continue;
  1929. /* verify the packet layout is correct */
  1930. if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
  1931. continue;
  1932. /* probably a little skewed due to removing CRC */
  1933. total_rx_bytes += skb->len;
  1934. /* populate checksum, timestamp, VLAN, and protocol */
  1935. ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
  1936. #ifdef IXGBE_FCOE
  1937. /* if ddp, not passing to ULD unless for FCP_RSP or error */
  1938. if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
  1939. ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
  1940. /* include DDPed FCoE data */
  1941. if (ddp_bytes > 0) {
  1942. if (!mss) {
  1943. mss = rx_ring->netdev->mtu -
  1944. sizeof(struct fcoe_hdr) -
  1945. sizeof(struct fc_frame_header) -
  1946. sizeof(struct fcoe_crc_eof);
  1947. if (mss > 512)
  1948. mss &= ~511;
  1949. }
  1950. total_rx_bytes += ddp_bytes;
  1951. total_rx_packets += DIV_ROUND_UP(ddp_bytes,
  1952. mss);
  1953. }
  1954. if (!ddp_bytes) {
  1955. dev_kfree_skb_any(skb);
  1956. continue;
  1957. }
  1958. }
  1959. #endif /* IXGBE_FCOE */
  1960. ixgbe_rx_skb(q_vector, skb);
  1961. /* update budget accounting */
  1962. total_rx_packets++;
  1963. }
  1964. u64_stats_update_begin(&rx_ring->syncp);
  1965. rx_ring->stats.packets += total_rx_packets;
  1966. rx_ring->stats.bytes += total_rx_bytes;
  1967. u64_stats_update_end(&rx_ring->syncp);
  1968. q_vector->rx.total_packets += total_rx_packets;
  1969. q_vector->rx.total_bytes += total_rx_bytes;
  1970. return total_rx_packets;
  1971. }
  1972. /**
  1973. * ixgbe_configure_msix - Configure MSI-X hardware
  1974. * @adapter: board private structure
  1975. *
  1976. * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
  1977. * interrupts.
  1978. **/
  1979. static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
  1980. {
  1981. struct ixgbe_q_vector *q_vector;
  1982. int v_idx;
  1983. u32 mask;
  1984. /* Populate MSIX to EITR Select */
  1985. if (adapter->num_vfs > 32) {
  1986. u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
  1987. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
  1988. }
  1989. /*
  1990. * Populate the IVAR table and set the ITR values to the
  1991. * corresponding register.
  1992. */
  1993. for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
  1994. struct ixgbe_ring *ring;
  1995. q_vector = adapter->q_vector[v_idx];
  1996. ixgbe_for_each_ring(ring, q_vector->rx)
  1997. ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
  1998. ixgbe_for_each_ring(ring, q_vector->tx)
  1999. ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
  2000. ixgbe_write_eitr(q_vector);
  2001. }
  2002. switch (adapter->hw.mac.type) {
  2003. case ixgbe_mac_82598EB:
  2004. ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
  2005. v_idx);
  2006. break;
  2007. case ixgbe_mac_82599EB:
  2008. case ixgbe_mac_X540:
  2009. case ixgbe_mac_X550:
  2010. case ixgbe_mac_X550EM_x:
  2011. case ixgbe_mac_x550em_a:
  2012. ixgbe_set_ivar(adapter, -1, 1, v_idx);
  2013. break;
  2014. default:
  2015. break;
  2016. }
  2017. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
  2018. /* set up to autoclear timer, and the vectors */
  2019. mask = IXGBE_EIMS_ENABLE_MASK;
  2020. mask &= ~(IXGBE_EIMS_OTHER |
  2021. IXGBE_EIMS_MAILBOX |
  2022. IXGBE_EIMS_LSC);
  2023. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
  2024. }
  2025. enum latency_range {
  2026. lowest_latency = 0,
  2027. low_latency = 1,
  2028. bulk_latency = 2,
  2029. latency_invalid = 255
  2030. };
  2031. /**
  2032. * ixgbe_update_itr - update the dynamic ITR value based on statistics
  2033. * @q_vector: structure containing interrupt and ring information
  2034. * @ring_container: structure containing ring performance data
  2035. *
  2036. * Stores a new ITR value based on packets and byte
  2037. * counts during the last interrupt. The advantage of per interrupt
  2038. * computation is faster updates and more accurate ITR for the current
  2039. * traffic pattern. Constants in this function were computed
  2040. * based on theoretical maximum wire speed and thresholds were set based
  2041. * on testing data as well as attempting to minimize response time
  2042. * while increasing bulk throughput.
  2043. * this functionality is controlled by the InterruptThrottleRate module
  2044. * parameter (see ixgbe_param.c)
  2045. **/
  2046. static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
  2047. struct ixgbe_ring_container *ring_container)
  2048. {
  2049. int bytes = ring_container->total_bytes;
  2050. int packets = ring_container->total_packets;
  2051. u32 timepassed_us;
  2052. u64 bytes_perint;
  2053. u8 itr_setting = ring_container->itr;
  2054. if (packets == 0)
  2055. return;
  2056. /* simple throttlerate management
  2057. * 0-10MB/s lowest (100000 ints/s)
  2058. * 10-20MB/s low (20000 ints/s)
  2059. * 20-1249MB/s bulk (12000 ints/s)
  2060. */
  2061. /* what was last interrupt timeslice? */
  2062. timepassed_us = q_vector->itr >> 2;
  2063. if (timepassed_us == 0)
  2064. return;
  2065. bytes_perint = bytes / timepassed_us; /* bytes/usec */
  2066. switch (itr_setting) {
  2067. case lowest_latency:
  2068. if (bytes_perint > 10)
  2069. itr_setting = low_latency;
  2070. break;
  2071. case low_latency:
  2072. if (bytes_perint > 20)
  2073. itr_setting = bulk_latency;
  2074. else if (bytes_perint <= 10)
  2075. itr_setting = lowest_latency;
  2076. break;
  2077. case bulk_latency:
  2078. if (bytes_perint <= 20)
  2079. itr_setting = low_latency;
  2080. break;
  2081. }
  2082. /* clear work counters since we have the values we need */
  2083. ring_container->total_bytes = 0;
  2084. ring_container->total_packets = 0;
  2085. /* write updated itr to ring container */
  2086. ring_container->itr = itr_setting;
  2087. }
  2088. /**
  2089. * ixgbe_write_eitr - write EITR register in hardware specific way
  2090. * @q_vector: structure containing interrupt and ring information
  2091. *
  2092. * This function is made to be called by ethtool and by the driver
  2093. * when it needs to update EITR registers at runtime. Hardware
  2094. * specific quirks/differences are taken care of here.
  2095. */
  2096. void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
  2097. {
  2098. struct ixgbe_adapter *adapter = q_vector->adapter;
  2099. struct ixgbe_hw *hw = &adapter->hw;
  2100. int v_idx = q_vector->v_idx;
  2101. u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
  2102. switch (adapter->hw.mac.type) {
  2103. case ixgbe_mac_82598EB:
  2104. /* must write high and low 16 bits to reset counter */
  2105. itr_reg |= (itr_reg << 16);
  2106. break;
  2107. case ixgbe_mac_82599EB:
  2108. case ixgbe_mac_X540:
  2109. case ixgbe_mac_X550:
  2110. case ixgbe_mac_X550EM_x:
  2111. case ixgbe_mac_x550em_a:
  2112. /*
  2113. * set the WDIS bit to not clear the timer bits and cause an
  2114. * immediate assertion of the interrupt
  2115. */
  2116. itr_reg |= IXGBE_EITR_CNT_WDIS;
  2117. break;
  2118. default:
  2119. break;
  2120. }
  2121. IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
  2122. }
  2123. static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
  2124. {
  2125. u32 new_itr = q_vector->itr;
  2126. u8 current_itr;
  2127. ixgbe_update_itr(q_vector, &q_vector->tx);
  2128. ixgbe_update_itr(q_vector, &q_vector->rx);
  2129. current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
  2130. switch (current_itr) {
  2131. /* counts and packets in update_itr are dependent on these numbers */
  2132. case lowest_latency:
  2133. new_itr = IXGBE_100K_ITR;
  2134. break;
  2135. case low_latency:
  2136. new_itr = IXGBE_20K_ITR;
  2137. break;
  2138. case bulk_latency:
  2139. new_itr = IXGBE_12K_ITR;
  2140. break;
  2141. default:
  2142. break;
  2143. }
  2144. if (new_itr != q_vector->itr) {
  2145. /* do an exponential smoothing */
  2146. new_itr = (10 * new_itr * q_vector->itr) /
  2147. ((9 * new_itr) + q_vector->itr);
  2148. /* save the algorithm value here */
  2149. q_vector->itr = new_itr;
  2150. ixgbe_write_eitr(q_vector);
  2151. }
  2152. }
  2153. /**
  2154. * ixgbe_check_overtemp_subtask - check for over temperature
  2155. * @adapter: pointer to adapter
  2156. **/
  2157. static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
  2158. {
  2159. struct ixgbe_hw *hw = &adapter->hw;
  2160. u32 eicr = adapter->interrupt_event;
  2161. s32 rc;
  2162. if (test_bit(__IXGBE_DOWN, &adapter->state))
  2163. return;
  2164. if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
  2165. !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
  2166. return;
  2167. adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2168. switch (hw->device_id) {
  2169. case IXGBE_DEV_ID_82599_T3_LOM:
  2170. /*
  2171. * Since the warning interrupt is for both ports
  2172. * we don't have to check if:
  2173. * - This interrupt wasn't for our port.
  2174. * - We may have missed the interrupt so always have to
  2175. * check if we got a LSC
  2176. */
  2177. if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
  2178. !(eicr & IXGBE_EICR_LSC))
  2179. return;
  2180. if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
  2181. u32 speed;
  2182. bool link_up = false;
  2183. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  2184. if (link_up)
  2185. return;
  2186. }
  2187. /* Check if this is not due to overtemp */
  2188. if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
  2189. return;
  2190. break;
  2191. case IXGBE_DEV_ID_X550EM_A_1G_T:
  2192. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  2193. rc = hw->phy.ops.check_overtemp(hw);
  2194. if (rc != IXGBE_ERR_OVERTEMP)
  2195. return;
  2196. break;
  2197. default:
  2198. if (adapter->hw.mac.type >= ixgbe_mac_X540)
  2199. return;
  2200. if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
  2201. return;
  2202. break;
  2203. }
  2204. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  2205. adapter->interrupt_event = 0;
  2206. }
  2207. static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
  2208. {
  2209. struct ixgbe_hw *hw = &adapter->hw;
  2210. if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
  2211. (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
  2212. e_crit(probe, "Fan has stopped, replace the adapter\n");
  2213. /* write to clear the interrupt */
  2214. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
  2215. }
  2216. }
  2217. static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
  2218. {
  2219. struct ixgbe_hw *hw = &adapter->hw;
  2220. if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
  2221. return;
  2222. switch (adapter->hw.mac.type) {
  2223. case ixgbe_mac_82599EB:
  2224. /*
  2225. * Need to check link state so complete overtemp check
  2226. * on service task
  2227. */
  2228. if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
  2229. (eicr & IXGBE_EICR_LSC)) &&
  2230. (!test_bit(__IXGBE_DOWN, &adapter->state))) {
  2231. adapter->interrupt_event = eicr;
  2232. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2233. ixgbe_service_event_schedule(adapter);
  2234. return;
  2235. }
  2236. return;
  2237. case ixgbe_mac_x550em_a:
  2238. if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) {
  2239. adapter->interrupt_event = eicr;
  2240. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2241. ixgbe_service_event_schedule(adapter);
  2242. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
  2243. IXGBE_EICR_GPI_SDP0_X550EM_a);
  2244. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR,
  2245. IXGBE_EICR_GPI_SDP0_X550EM_a);
  2246. }
  2247. return;
  2248. case ixgbe_mac_X550:
  2249. case ixgbe_mac_X540:
  2250. if (!(eicr & IXGBE_EICR_TS))
  2251. return;
  2252. break;
  2253. default:
  2254. return;
  2255. }
  2256. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  2257. }
  2258. static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
  2259. {
  2260. switch (hw->mac.type) {
  2261. case ixgbe_mac_82598EB:
  2262. if (hw->phy.type == ixgbe_phy_nl)
  2263. return true;
  2264. return false;
  2265. case ixgbe_mac_82599EB:
  2266. case ixgbe_mac_X550EM_x:
  2267. case ixgbe_mac_x550em_a:
  2268. switch (hw->mac.ops.get_media_type(hw)) {
  2269. case ixgbe_media_type_fiber:
  2270. case ixgbe_media_type_fiber_qsfp:
  2271. return true;
  2272. default:
  2273. return false;
  2274. }
  2275. default:
  2276. return false;
  2277. }
  2278. }
  2279. static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
  2280. {
  2281. struct ixgbe_hw *hw = &adapter->hw;
  2282. u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
  2283. if (!ixgbe_is_sfp(hw))
  2284. return;
  2285. /* Later MAC's use different SDP */
  2286. if (hw->mac.type >= ixgbe_mac_X540)
  2287. eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
  2288. if (eicr & eicr_mask) {
  2289. /* Clear the interrupt */
  2290. IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
  2291. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2292. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  2293. adapter->sfp_poll_time = 0;
  2294. ixgbe_service_event_schedule(adapter);
  2295. }
  2296. }
  2297. if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
  2298. (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
  2299. /* Clear the interrupt */
  2300. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
  2301. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2302. adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
  2303. ixgbe_service_event_schedule(adapter);
  2304. }
  2305. }
  2306. }
  2307. static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
  2308. {
  2309. struct ixgbe_hw *hw = &adapter->hw;
  2310. adapter->lsc_int++;
  2311. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  2312. adapter->link_check_timeout = jiffies;
  2313. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2314. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
  2315. IXGBE_WRITE_FLUSH(hw);
  2316. ixgbe_service_event_schedule(adapter);
  2317. }
  2318. }
  2319. static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
  2320. u64 qmask)
  2321. {
  2322. u32 mask;
  2323. struct ixgbe_hw *hw = &adapter->hw;
  2324. switch (hw->mac.type) {
  2325. case ixgbe_mac_82598EB:
  2326. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  2327. IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
  2328. break;
  2329. case ixgbe_mac_82599EB:
  2330. case ixgbe_mac_X540:
  2331. case ixgbe_mac_X550:
  2332. case ixgbe_mac_X550EM_x:
  2333. case ixgbe_mac_x550em_a:
  2334. mask = (qmask & 0xFFFFFFFF);
  2335. if (mask)
  2336. IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
  2337. mask = (qmask >> 32);
  2338. if (mask)
  2339. IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
  2340. break;
  2341. default:
  2342. break;
  2343. }
  2344. /* skip the flush */
  2345. }
  2346. static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
  2347. u64 qmask)
  2348. {
  2349. u32 mask;
  2350. struct ixgbe_hw *hw = &adapter->hw;
  2351. switch (hw->mac.type) {
  2352. case ixgbe_mac_82598EB:
  2353. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  2354. IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
  2355. break;
  2356. case ixgbe_mac_82599EB:
  2357. case ixgbe_mac_X540:
  2358. case ixgbe_mac_X550:
  2359. case ixgbe_mac_X550EM_x:
  2360. case ixgbe_mac_x550em_a:
  2361. mask = (qmask & 0xFFFFFFFF);
  2362. if (mask)
  2363. IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
  2364. mask = (qmask >> 32);
  2365. if (mask)
  2366. IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
  2367. break;
  2368. default:
  2369. break;
  2370. }
  2371. /* skip the flush */
  2372. }
  2373. /**
  2374. * ixgbe_irq_enable - Enable default interrupt generation settings
  2375. * @adapter: board private structure
  2376. **/
  2377. static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
  2378. bool flush)
  2379. {
  2380. struct ixgbe_hw *hw = &adapter->hw;
  2381. u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
  2382. /* don't reenable LSC while waiting for link */
  2383. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
  2384. mask &= ~IXGBE_EIMS_LSC;
  2385. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
  2386. switch (adapter->hw.mac.type) {
  2387. case ixgbe_mac_82599EB:
  2388. mask |= IXGBE_EIMS_GPI_SDP0(hw);
  2389. break;
  2390. case ixgbe_mac_X540:
  2391. case ixgbe_mac_X550:
  2392. case ixgbe_mac_X550EM_x:
  2393. case ixgbe_mac_x550em_a:
  2394. mask |= IXGBE_EIMS_TS;
  2395. break;
  2396. default:
  2397. break;
  2398. }
  2399. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  2400. mask |= IXGBE_EIMS_GPI_SDP1(hw);
  2401. switch (adapter->hw.mac.type) {
  2402. case ixgbe_mac_82599EB:
  2403. mask |= IXGBE_EIMS_GPI_SDP1(hw);
  2404. mask |= IXGBE_EIMS_GPI_SDP2(hw);
  2405. /* fall through */
  2406. case ixgbe_mac_X540:
  2407. case ixgbe_mac_X550:
  2408. case ixgbe_mac_X550EM_x:
  2409. case ixgbe_mac_x550em_a:
  2410. if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
  2411. adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
  2412. adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
  2413. mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
  2414. if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
  2415. mask |= IXGBE_EICR_GPI_SDP0_X540;
  2416. mask |= IXGBE_EIMS_ECC;
  2417. mask |= IXGBE_EIMS_MAILBOX;
  2418. break;
  2419. default:
  2420. break;
  2421. }
  2422. if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
  2423. !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
  2424. mask |= IXGBE_EIMS_FLOW_DIR;
  2425. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
  2426. if (queues)
  2427. ixgbe_irq_enable_queues(adapter, ~0);
  2428. if (flush)
  2429. IXGBE_WRITE_FLUSH(&adapter->hw);
  2430. }
  2431. static irqreturn_t ixgbe_msix_other(int irq, void *data)
  2432. {
  2433. struct ixgbe_adapter *adapter = data;
  2434. struct ixgbe_hw *hw = &adapter->hw;
  2435. u32 eicr;
  2436. /*
  2437. * Workaround for Silicon errata. Use clear-by-write instead
  2438. * of clear-by-read. Reading with EICS will return the
  2439. * interrupt causes without clearing, which later be done
  2440. * with the write to EICR.
  2441. */
  2442. eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
  2443. /* The lower 16bits of the EICR register are for the queue interrupts
  2444. * which should be masked here in order to not accidentally clear them if
  2445. * the bits are high when ixgbe_msix_other is called. There is a race
  2446. * condition otherwise which results in possible performance loss
  2447. * especially if the ixgbe_msix_other interrupt is triggering
  2448. * consistently (as it would when PPS is turned on for the X540 device)
  2449. */
  2450. eicr &= 0xFFFF0000;
  2451. IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
  2452. if (eicr & IXGBE_EICR_LSC)
  2453. ixgbe_check_lsc(adapter);
  2454. if (eicr & IXGBE_EICR_MAILBOX)
  2455. ixgbe_msg_task(adapter);
  2456. switch (hw->mac.type) {
  2457. case ixgbe_mac_82599EB:
  2458. case ixgbe_mac_X540:
  2459. case ixgbe_mac_X550:
  2460. case ixgbe_mac_X550EM_x:
  2461. case ixgbe_mac_x550em_a:
  2462. if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
  2463. (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
  2464. adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
  2465. ixgbe_service_event_schedule(adapter);
  2466. IXGBE_WRITE_REG(hw, IXGBE_EICR,
  2467. IXGBE_EICR_GPI_SDP0_X540);
  2468. }
  2469. if (eicr & IXGBE_EICR_ECC) {
  2470. e_info(link, "Received ECC Err, initiating reset\n");
  2471. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  2472. ixgbe_service_event_schedule(adapter);
  2473. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
  2474. }
  2475. /* Handle Flow Director Full threshold interrupt */
  2476. if (eicr & IXGBE_EICR_FLOW_DIR) {
  2477. int reinit_count = 0;
  2478. int i;
  2479. for (i = 0; i < adapter->num_tx_queues; i++) {
  2480. struct ixgbe_ring *ring = adapter->tx_ring[i];
  2481. if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
  2482. &ring->state))
  2483. reinit_count++;
  2484. }
  2485. if (reinit_count) {
  2486. /* no more flow director interrupts until after init */
  2487. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
  2488. adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  2489. ixgbe_service_event_schedule(adapter);
  2490. }
  2491. }
  2492. ixgbe_check_sfp_event(adapter, eicr);
  2493. ixgbe_check_overtemp_event(adapter, eicr);
  2494. break;
  2495. default:
  2496. break;
  2497. }
  2498. ixgbe_check_fan_failure(adapter, eicr);
  2499. if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
  2500. ixgbe_ptp_check_pps_event(adapter);
  2501. /* re-enable the original interrupt state, no lsc, no queues */
  2502. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2503. ixgbe_irq_enable(adapter, false, false);
  2504. return IRQ_HANDLED;
  2505. }
  2506. static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
  2507. {
  2508. struct ixgbe_q_vector *q_vector = data;
  2509. /* EIAM disabled interrupts (on this vector) for us */
  2510. if (q_vector->rx.ring || q_vector->tx.ring)
  2511. napi_schedule_irqoff(&q_vector->napi);
  2512. return IRQ_HANDLED;
  2513. }
  2514. /**
  2515. * ixgbe_poll - NAPI Rx polling callback
  2516. * @napi: structure for representing this polling device
  2517. * @budget: how many packets driver is allowed to clean
  2518. *
  2519. * This function is used for legacy and MSI, NAPI mode
  2520. **/
  2521. int ixgbe_poll(struct napi_struct *napi, int budget)
  2522. {
  2523. struct ixgbe_q_vector *q_vector =
  2524. container_of(napi, struct ixgbe_q_vector, napi);
  2525. struct ixgbe_adapter *adapter = q_vector->adapter;
  2526. struct ixgbe_ring *ring;
  2527. int per_ring_budget, work_done = 0;
  2528. bool clean_complete = true;
  2529. #ifdef CONFIG_IXGBE_DCA
  2530. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  2531. ixgbe_update_dca(q_vector);
  2532. #endif
  2533. ixgbe_for_each_ring(ring, q_vector->tx) {
  2534. if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
  2535. clean_complete = false;
  2536. }
  2537. /* Exit if we are called by netpoll */
  2538. if (budget <= 0)
  2539. return budget;
  2540. /* attempt to distribute budget to each queue fairly, but don't allow
  2541. * the budget to go below 1 because we'll exit polling */
  2542. if (q_vector->rx.count > 1)
  2543. per_ring_budget = max(budget/q_vector->rx.count, 1);
  2544. else
  2545. per_ring_budget = budget;
  2546. ixgbe_for_each_ring(ring, q_vector->rx) {
  2547. int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
  2548. per_ring_budget);
  2549. work_done += cleaned;
  2550. if (cleaned >= per_ring_budget)
  2551. clean_complete = false;
  2552. }
  2553. /* If all work not completed, return budget and keep polling */
  2554. if (!clean_complete)
  2555. return budget;
  2556. /* all work done, exit the polling mode */
  2557. napi_complete_done(napi, work_done);
  2558. if (adapter->rx_itr_setting & 1)
  2559. ixgbe_set_itr(q_vector);
  2560. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2561. ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx));
  2562. return min(work_done, budget - 1);
  2563. }
  2564. /**
  2565. * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
  2566. * @adapter: board private structure
  2567. *
  2568. * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
  2569. * interrupts from the kernel.
  2570. **/
  2571. static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
  2572. {
  2573. struct net_device *netdev = adapter->netdev;
  2574. int vector, err;
  2575. int ri = 0, ti = 0;
  2576. for (vector = 0; vector < adapter->num_q_vectors; vector++) {
  2577. struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
  2578. struct msix_entry *entry = &adapter->msix_entries[vector];
  2579. if (q_vector->tx.ring && q_vector->rx.ring) {
  2580. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2581. "%s-%s-%d", netdev->name, "TxRx", ri++);
  2582. ti++;
  2583. } else if (q_vector->rx.ring) {
  2584. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2585. "%s-%s-%d", netdev->name, "rx", ri++);
  2586. } else if (q_vector->tx.ring) {
  2587. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2588. "%s-%s-%d", netdev->name, "tx", ti++);
  2589. } else {
  2590. /* skip this unused q_vector */
  2591. continue;
  2592. }
  2593. err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
  2594. q_vector->name, q_vector);
  2595. if (err) {
  2596. e_err(probe, "request_irq failed for MSIX interrupt "
  2597. "Error: %d\n", err);
  2598. goto free_queue_irqs;
  2599. }
  2600. /* If Flow Director is enabled, set interrupt affinity */
  2601. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  2602. /* assign the mask for this irq */
  2603. irq_set_affinity_hint(entry->vector,
  2604. &q_vector->affinity_mask);
  2605. }
  2606. }
  2607. err = request_irq(adapter->msix_entries[vector].vector,
  2608. ixgbe_msix_other, 0, netdev->name, adapter);
  2609. if (err) {
  2610. e_err(probe, "request_irq for msix_other failed: %d\n", err);
  2611. goto free_queue_irqs;
  2612. }
  2613. return 0;
  2614. free_queue_irqs:
  2615. while (vector) {
  2616. vector--;
  2617. irq_set_affinity_hint(adapter->msix_entries[vector].vector,
  2618. NULL);
  2619. free_irq(adapter->msix_entries[vector].vector,
  2620. adapter->q_vector[vector]);
  2621. }
  2622. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  2623. pci_disable_msix(adapter->pdev);
  2624. kfree(adapter->msix_entries);
  2625. adapter->msix_entries = NULL;
  2626. return err;
  2627. }
  2628. /**
  2629. * ixgbe_intr - legacy mode Interrupt Handler
  2630. * @irq: interrupt number
  2631. * @data: pointer to a network interface device structure
  2632. **/
  2633. static irqreturn_t ixgbe_intr(int irq, void *data)
  2634. {
  2635. struct ixgbe_adapter *adapter = data;
  2636. struct ixgbe_hw *hw = &adapter->hw;
  2637. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  2638. u32 eicr;
  2639. /*
  2640. * Workaround for silicon errata #26 on 82598. Mask the interrupt
  2641. * before the read of EICR.
  2642. */
  2643. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  2644. /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
  2645. * therefore no explicit interrupt disable is necessary */
  2646. eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
  2647. if (!eicr) {
  2648. /*
  2649. * shared interrupt alert!
  2650. * make sure interrupts are enabled because the read will
  2651. * have disabled interrupts due to EIAM
  2652. * finish the workaround of silicon errata on 82598. Unmask
  2653. * the interrupt that we masked before the EICR read.
  2654. */
  2655. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2656. ixgbe_irq_enable(adapter, true, true);
  2657. return IRQ_NONE; /* Not our interrupt */
  2658. }
  2659. if (eicr & IXGBE_EICR_LSC)
  2660. ixgbe_check_lsc(adapter);
  2661. switch (hw->mac.type) {
  2662. case ixgbe_mac_82599EB:
  2663. ixgbe_check_sfp_event(adapter, eicr);
  2664. /* Fall through */
  2665. case ixgbe_mac_X540:
  2666. case ixgbe_mac_X550:
  2667. case ixgbe_mac_X550EM_x:
  2668. case ixgbe_mac_x550em_a:
  2669. if (eicr & IXGBE_EICR_ECC) {
  2670. e_info(link, "Received ECC Err, initiating reset\n");
  2671. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  2672. ixgbe_service_event_schedule(adapter);
  2673. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
  2674. }
  2675. ixgbe_check_overtemp_event(adapter, eicr);
  2676. break;
  2677. default:
  2678. break;
  2679. }
  2680. ixgbe_check_fan_failure(adapter, eicr);
  2681. if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
  2682. ixgbe_ptp_check_pps_event(adapter);
  2683. /* would disable interrupts here but EIAM disabled it */
  2684. napi_schedule_irqoff(&q_vector->napi);
  2685. /*
  2686. * re-enable link(maybe) and non-queue interrupts, no flush.
  2687. * ixgbe_poll will re-enable the queue interrupts
  2688. */
  2689. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2690. ixgbe_irq_enable(adapter, false, false);
  2691. return IRQ_HANDLED;
  2692. }
  2693. /**
  2694. * ixgbe_request_irq - initialize interrupts
  2695. * @adapter: board private structure
  2696. *
  2697. * Attempts to configure interrupts using the best available
  2698. * capabilities of the hardware and kernel.
  2699. **/
  2700. static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
  2701. {
  2702. struct net_device *netdev = adapter->netdev;
  2703. int err;
  2704. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  2705. err = ixgbe_request_msix_irqs(adapter);
  2706. else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
  2707. err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
  2708. netdev->name, adapter);
  2709. else
  2710. err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
  2711. netdev->name, adapter);
  2712. if (err)
  2713. e_err(probe, "request_irq failed, Error %d\n", err);
  2714. return err;
  2715. }
  2716. static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
  2717. {
  2718. int vector;
  2719. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  2720. free_irq(adapter->pdev->irq, adapter);
  2721. return;
  2722. }
  2723. if (!adapter->msix_entries)
  2724. return;
  2725. for (vector = 0; vector < adapter->num_q_vectors; vector++) {
  2726. struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
  2727. struct msix_entry *entry = &adapter->msix_entries[vector];
  2728. /* free only the irqs that were actually requested */
  2729. if (!q_vector->rx.ring && !q_vector->tx.ring)
  2730. continue;
  2731. /* clear the affinity_mask in the IRQ descriptor */
  2732. irq_set_affinity_hint(entry->vector, NULL);
  2733. free_irq(entry->vector, q_vector);
  2734. }
  2735. free_irq(adapter->msix_entries[vector].vector, adapter);
  2736. }
  2737. /**
  2738. * ixgbe_irq_disable - Mask off interrupt generation on the NIC
  2739. * @adapter: board private structure
  2740. **/
  2741. static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
  2742. {
  2743. switch (adapter->hw.mac.type) {
  2744. case ixgbe_mac_82598EB:
  2745. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
  2746. break;
  2747. case ixgbe_mac_82599EB:
  2748. case ixgbe_mac_X540:
  2749. case ixgbe_mac_X550:
  2750. case ixgbe_mac_X550EM_x:
  2751. case ixgbe_mac_x550em_a:
  2752. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
  2753. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
  2754. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
  2755. break;
  2756. default:
  2757. break;
  2758. }
  2759. IXGBE_WRITE_FLUSH(&adapter->hw);
  2760. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2761. int vector;
  2762. for (vector = 0; vector < adapter->num_q_vectors; vector++)
  2763. synchronize_irq(adapter->msix_entries[vector].vector);
  2764. synchronize_irq(adapter->msix_entries[vector++].vector);
  2765. } else {
  2766. synchronize_irq(adapter->pdev->irq);
  2767. }
  2768. }
  2769. /**
  2770. * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
  2771. *
  2772. **/
  2773. static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
  2774. {
  2775. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  2776. ixgbe_write_eitr(q_vector);
  2777. ixgbe_set_ivar(adapter, 0, 0, 0);
  2778. ixgbe_set_ivar(adapter, 1, 0, 0);
  2779. e_info(hw, "Legacy interrupt IVAR setup done\n");
  2780. }
  2781. /**
  2782. * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
  2783. * @adapter: board private structure
  2784. * @ring: structure containing ring specific data
  2785. *
  2786. * Configure the Tx descriptor ring after a reset.
  2787. **/
  2788. void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
  2789. struct ixgbe_ring *ring)
  2790. {
  2791. struct ixgbe_hw *hw = &adapter->hw;
  2792. u64 tdba = ring->dma;
  2793. int wait_loop = 10;
  2794. u32 txdctl = IXGBE_TXDCTL_ENABLE;
  2795. u8 reg_idx = ring->reg_idx;
  2796. /* disable queue to avoid issues while updating state */
  2797. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
  2798. IXGBE_WRITE_FLUSH(hw);
  2799. IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
  2800. (tdba & DMA_BIT_MASK(32)));
  2801. IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
  2802. IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
  2803. ring->count * sizeof(union ixgbe_adv_tx_desc));
  2804. IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
  2805. IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
  2806. ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
  2807. /*
  2808. * set WTHRESH to encourage burst writeback, it should not be set
  2809. * higher than 1 when:
  2810. * - ITR is 0 as it could cause false TX hangs
  2811. * - ITR is set to > 100k int/sec and BQL is enabled
  2812. *
  2813. * In order to avoid issues WTHRESH + PTHRESH should always be equal
  2814. * to or less than the number of on chip descriptors, which is
  2815. * currently 40.
  2816. */
  2817. if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
  2818. txdctl |= 1u << 16; /* WTHRESH = 1 */
  2819. else
  2820. txdctl |= 8u << 16; /* WTHRESH = 8 */
  2821. /*
  2822. * Setting PTHRESH to 32 both improves performance
  2823. * and avoids a TX hang with DFP enabled
  2824. */
  2825. txdctl |= (1u << 8) | /* HTHRESH = 1 */
  2826. 32; /* PTHRESH = 32 */
  2827. /* reinitialize flowdirector state */
  2828. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  2829. ring->atr_sample_rate = adapter->atr_sample_rate;
  2830. ring->atr_count = 0;
  2831. set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
  2832. } else {
  2833. ring->atr_sample_rate = 0;
  2834. }
  2835. /* initialize XPS */
  2836. if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
  2837. struct ixgbe_q_vector *q_vector = ring->q_vector;
  2838. if (q_vector)
  2839. netif_set_xps_queue(ring->netdev,
  2840. &q_vector->affinity_mask,
  2841. ring->queue_index);
  2842. }
  2843. clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
  2844. /* reinitialize tx_buffer_info */
  2845. memset(ring->tx_buffer_info, 0,
  2846. sizeof(struct ixgbe_tx_buffer) * ring->count);
  2847. /* enable queue */
  2848. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
  2849. /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
  2850. if (hw->mac.type == ixgbe_mac_82598EB &&
  2851. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  2852. return;
  2853. /* poll to verify queue is enabled */
  2854. do {
  2855. usleep_range(1000, 2000);
  2856. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
  2857. } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
  2858. if (!wait_loop)
  2859. hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx);
  2860. }
  2861. static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
  2862. {
  2863. struct ixgbe_hw *hw = &adapter->hw;
  2864. u32 rttdcs, mtqc;
  2865. u8 tcs = netdev_get_num_tc(adapter->netdev);
  2866. if (hw->mac.type == ixgbe_mac_82598EB)
  2867. return;
  2868. /* disable the arbiter while setting MTQC */
  2869. rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
  2870. rttdcs |= IXGBE_RTTDCS_ARBDIS;
  2871. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  2872. /* set transmit pool layout */
  2873. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  2874. mtqc = IXGBE_MTQC_VT_ENA;
  2875. if (tcs > 4)
  2876. mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
  2877. else if (tcs > 1)
  2878. mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
  2879. else if (adapter->ring_feature[RING_F_VMDQ].mask ==
  2880. IXGBE_82599_VMDQ_4Q_MASK)
  2881. mtqc |= IXGBE_MTQC_32VF;
  2882. else
  2883. mtqc |= IXGBE_MTQC_64VF;
  2884. } else {
  2885. if (tcs > 4)
  2886. mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
  2887. else if (tcs > 1)
  2888. mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
  2889. else
  2890. mtqc = IXGBE_MTQC_64Q_1PB;
  2891. }
  2892. IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
  2893. /* Enable Security TX Buffer IFG for multiple pb */
  2894. if (tcs) {
  2895. u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
  2896. sectx |= IXGBE_SECTX_DCB;
  2897. IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
  2898. }
  2899. /* re-enable the arbiter */
  2900. rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
  2901. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  2902. }
  2903. /**
  2904. * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
  2905. * @adapter: board private structure
  2906. *
  2907. * Configure the Tx unit of the MAC after a reset.
  2908. **/
  2909. static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
  2910. {
  2911. struct ixgbe_hw *hw = &adapter->hw;
  2912. u32 dmatxctl;
  2913. u32 i;
  2914. ixgbe_setup_mtqc(adapter);
  2915. if (hw->mac.type != ixgbe_mac_82598EB) {
  2916. /* DMATXCTL.EN must be before Tx queues are enabled */
  2917. dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
  2918. dmatxctl |= IXGBE_DMATXCTL_TE;
  2919. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
  2920. }
  2921. /* Setup the HW Tx Head and Tail descriptor pointers */
  2922. for (i = 0; i < adapter->num_tx_queues; i++)
  2923. ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
  2924. }
  2925. static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
  2926. struct ixgbe_ring *ring)
  2927. {
  2928. struct ixgbe_hw *hw = &adapter->hw;
  2929. u8 reg_idx = ring->reg_idx;
  2930. u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
  2931. srrctl |= IXGBE_SRRCTL_DROP_EN;
  2932. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  2933. }
  2934. static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
  2935. struct ixgbe_ring *ring)
  2936. {
  2937. struct ixgbe_hw *hw = &adapter->hw;
  2938. u8 reg_idx = ring->reg_idx;
  2939. u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
  2940. srrctl &= ~IXGBE_SRRCTL_DROP_EN;
  2941. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  2942. }
  2943. #ifdef CONFIG_IXGBE_DCB
  2944. void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
  2945. #else
  2946. static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
  2947. #endif
  2948. {
  2949. int i;
  2950. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  2951. if (adapter->ixgbe_ieee_pfc)
  2952. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  2953. /*
  2954. * We should set the drop enable bit if:
  2955. * SR-IOV is enabled
  2956. * or
  2957. * Number of Rx queues > 1 and flow control is disabled
  2958. *
  2959. * This allows us to avoid head of line blocking for security
  2960. * and performance reasons.
  2961. */
  2962. if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
  2963. !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
  2964. for (i = 0; i < adapter->num_rx_queues; i++)
  2965. ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
  2966. } else {
  2967. for (i = 0; i < adapter->num_rx_queues; i++)
  2968. ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
  2969. }
  2970. }
  2971. #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
  2972. static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
  2973. struct ixgbe_ring *rx_ring)
  2974. {
  2975. struct ixgbe_hw *hw = &adapter->hw;
  2976. u32 srrctl;
  2977. u8 reg_idx = rx_ring->reg_idx;
  2978. if (hw->mac.type == ixgbe_mac_82598EB) {
  2979. u16 mask = adapter->ring_feature[RING_F_RSS].mask;
  2980. /*
  2981. * if VMDq is not active we must program one srrctl register
  2982. * per RSS queue since we have enabled RDRXCTL.MVMEN
  2983. */
  2984. reg_idx &= mask;
  2985. }
  2986. /* configure header buffer length, needed for RSC */
  2987. srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
  2988. /* configure the packet buffer length */
  2989. if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state))
  2990. srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  2991. else
  2992. srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  2993. /* configure descriptor type */
  2994. srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
  2995. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  2996. }
  2997. /**
  2998. * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
  2999. * @adapter: device handle
  3000. *
  3001. * - 82598/82599/X540: 128
  3002. * - X550(non-SRIOV mode): 512
  3003. * - X550(SRIOV mode): 64
  3004. */
  3005. u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
  3006. {
  3007. if (adapter->hw.mac.type < ixgbe_mac_X550)
  3008. return 128;
  3009. else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  3010. return 64;
  3011. else
  3012. return 512;
  3013. }
  3014. /**
  3015. * ixgbe_store_key - Write the RSS key to HW
  3016. * @adapter: device handle
  3017. *
  3018. * Write the RSS key stored in adapter.rss_key to HW.
  3019. */
  3020. void ixgbe_store_key(struct ixgbe_adapter *adapter)
  3021. {
  3022. struct ixgbe_hw *hw = &adapter->hw;
  3023. int i;
  3024. for (i = 0; i < 10; i++)
  3025. IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
  3026. }
  3027. /**
  3028. * ixgbe_store_reta - Write the RETA table to HW
  3029. * @adapter: device handle
  3030. *
  3031. * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
  3032. */
  3033. void ixgbe_store_reta(struct ixgbe_adapter *adapter)
  3034. {
  3035. u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  3036. struct ixgbe_hw *hw = &adapter->hw;
  3037. u32 reta = 0;
  3038. u32 indices_multi;
  3039. u8 *indir_tbl = adapter->rss_indir_tbl;
  3040. /* Fill out the redirection table as follows:
  3041. * - 82598: 8 bit wide entries containing pair of 4 bit RSS
  3042. * indices.
  3043. * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
  3044. * - X550: 8 bit wide entries containing 6 bit RSS index
  3045. */
  3046. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  3047. indices_multi = 0x11;
  3048. else
  3049. indices_multi = 0x1;
  3050. /* Write redirection table to HW */
  3051. for (i = 0; i < reta_entries; i++) {
  3052. reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
  3053. if ((i & 3) == 3) {
  3054. if (i < 128)
  3055. IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
  3056. else
  3057. IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
  3058. reta);
  3059. reta = 0;
  3060. }
  3061. }
  3062. }
  3063. /**
  3064. * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
  3065. * @adapter: device handle
  3066. *
  3067. * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
  3068. */
  3069. static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
  3070. {
  3071. u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  3072. struct ixgbe_hw *hw = &adapter->hw;
  3073. u32 vfreta = 0;
  3074. unsigned int pf_pool = adapter->num_vfs;
  3075. /* Write redirection table to HW */
  3076. for (i = 0; i < reta_entries; i++) {
  3077. vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
  3078. if ((i & 3) == 3) {
  3079. IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool),
  3080. vfreta);
  3081. vfreta = 0;
  3082. }
  3083. }
  3084. }
  3085. static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
  3086. {
  3087. u32 i, j;
  3088. u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  3089. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  3090. /* Program table for at least 4 queues w/ SR-IOV so that VFs can
  3091. * make full use of any rings they may have. We will use the
  3092. * PSRTYPE register to control how many rings we use within the PF.
  3093. */
  3094. if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4))
  3095. rss_i = 4;
  3096. /* Fill out hash function seeds */
  3097. ixgbe_store_key(adapter);
  3098. /* Fill out redirection table */
  3099. memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
  3100. for (i = 0, j = 0; i < reta_entries; i++, j++) {
  3101. if (j == rss_i)
  3102. j = 0;
  3103. adapter->rss_indir_tbl[i] = j;
  3104. }
  3105. ixgbe_store_reta(adapter);
  3106. }
  3107. static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
  3108. {
  3109. struct ixgbe_hw *hw = &adapter->hw;
  3110. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  3111. unsigned int pf_pool = adapter->num_vfs;
  3112. int i, j;
  3113. /* Fill out hash function seeds */
  3114. for (i = 0; i < 10; i++)
  3115. IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool),
  3116. adapter->rss_key[i]);
  3117. /* Fill out the redirection table */
  3118. for (i = 0, j = 0; i < 64; i++, j++) {
  3119. if (j == rss_i)
  3120. j = 0;
  3121. adapter->rss_indir_tbl[i] = j;
  3122. }
  3123. ixgbe_store_vfreta(adapter);
  3124. }
  3125. static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
  3126. {
  3127. struct ixgbe_hw *hw = &adapter->hw;
  3128. u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
  3129. u32 rxcsum;
  3130. /* Disable indicating checksum in descriptor, enables RSS hash */
  3131. rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
  3132. rxcsum |= IXGBE_RXCSUM_PCSD;
  3133. IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
  3134. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  3135. if (adapter->ring_feature[RING_F_RSS].mask)
  3136. mrqc = IXGBE_MRQC_RSSEN;
  3137. } else {
  3138. u8 tcs = netdev_get_num_tc(adapter->netdev);
  3139. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  3140. if (tcs > 4)
  3141. mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
  3142. else if (tcs > 1)
  3143. mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
  3144. else if (adapter->ring_feature[RING_F_VMDQ].mask ==
  3145. IXGBE_82599_VMDQ_4Q_MASK)
  3146. mrqc = IXGBE_MRQC_VMDQRSS32EN;
  3147. else
  3148. mrqc = IXGBE_MRQC_VMDQRSS64EN;
  3149. } else {
  3150. if (tcs > 4)
  3151. mrqc = IXGBE_MRQC_RTRSS8TCEN;
  3152. else if (tcs > 1)
  3153. mrqc = IXGBE_MRQC_RTRSS4TCEN;
  3154. else
  3155. mrqc = IXGBE_MRQC_RSSEN;
  3156. }
  3157. }
  3158. /* Perform hash on these packet types */
  3159. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
  3160. IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
  3161. IXGBE_MRQC_RSS_FIELD_IPV6 |
  3162. IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
  3163. if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
  3164. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
  3165. if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
  3166. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
  3167. netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key));
  3168. if ((hw->mac.type >= ixgbe_mac_X550) &&
  3169. (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
  3170. unsigned int pf_pool = adapter->num_vfs;
  3171. /* Enable VF RSS mode */
  3172. mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
  3173. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  3174. /* Setup RSS through the VF registers */
  3175. ixgbe_setup_vfreta(adapter);
  3176. vfmrqc = IXGBE_MRQC_RSSEN;
  3177. vfmrqc |= rss_field;
  3178. IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc);
  3179. } else {
  3180. ixgbe_setup_reta(adapter);
  3181. mrqc |= rss_field;
  3182. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  3183. }
  3184. }
  3185. /**
  3186. * ixgbe_configure_rscctl - enable RSC for the indicated ring
  3187. * @adapter: address of board private structure
  3188. * @index: index of ring to set
  3189. **/
  3190. static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
  3191. struct ixgbe_ring *ring)
  3192. {
  3193. struct ixgbe_hw *hw = &adapter->hw;
  3194. u32 rscctrl;
  3195. u8 reg_idx = ring->reg_idx;
  3196. if (!ring_is_rsc_enabled(ring))
  3197. return;
  3198. rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
  3199. rscctrl |= IXGBE_RSCCTL_RSCEN;
  3200. /*
  3201. * we must limit the number of descriptors so that the
  3202. * total size of max desc * buf_len is not greater
  3203. * than 65536
  3204. */
  3205. rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
  3206. IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
  3207. }
  3208. #define IXGBE_MAX_RX_DESC_POLL 10
  3209. static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
  3210. struct ixgbe_ring *ring)
  3211. {
  3212. struct ixgbe_hw *hw = &adapter->hw;
  3213. int wait_loop = IXGBE_MAX_RX_DESC_POLL;
  3214. u32 rxdctl;
  3215. u8 reg_idx = ring->reg_idx;
  3216. if (ixgbe_removed(hw->hw_addr))
  3217. return;
  3218. /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
  3219. if (hw->mac.type == ixgbe_mac_82598EB &&
  3220. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  3221. return;
  3222. do {
  3223. usleep_range(1000, 2000);
  3224. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3225. } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
  3226. if (!wait_loop) {
  3227. e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
  3228. "the polling period\n", reg_idx);
  3229. }
  3230. }
  3231. void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
  3232. struct ixgbe_ring *ring)
  3233. {
  3234. struct ixgbe_hw *hw = &adapter->hw;
  3235. int wait_loop = IXGBE_MAX_RX_DESC_POLL;
  3236. u32 rxdctl;
  3237. u8 reg_idx = ring->reg_idx;
  3238. if (ixgbe_removed(hw->hw_addr))
  3239. return;
  3240. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3241. rxdctl &= ~IXGBE_RXDCTL_ENABLE;
  3242. /* write value back with RXDCTL.ENABLE bit cleared */
  3243. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  3244. if (hw->mac.type == ixgbe_mac_82598EB &&
  3245. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  3246. return;
  3247. /* the hardware may take up to 100us to really disable the rx queue */
  3248. do {
  3249. udelay(10);
  3250. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3251. } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
  3252. if (!wait_loop) {
  3253. e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
  3254. "the polling period\n", reg_idx);
  3255. }
  3256. }
  3257. void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
  3258. struct ixgbe_ring *ring)
  3259. {
  3260. struct ixgbe_hw *hw = &adapter->hw;
  3261. union ixgbe_adv_rx_desc *rx_desc;
  3262. u64 rdba = ring->dma;
  3263. u32 rxdctl;
  3264. u8 reg_idx = ring->reg_idx;
  3265. /* disable queue to avoid issues while updating state */
  3266. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3267. ixgbe_disable_rx_queue(adapter, ring);
  3268. IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
  3269. IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
  3270. IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
  3271. ring->count * sizeof(union ixgbe_adv_rx_desc));
  3272. /* Force flushing of IXGBE_RDLEN to prevent MDD */
  3273. IXGBE_WRITE_FLUSH(hw);
  3274. IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
  3275. IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
  3276. ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
  3277. ixgbe_configure_srrctl(adapter, ring);
  3278. ixgbe_configure_rscctl(adapter, ring);
  3279. if (hw->mac.type == ixgbe_mac_82598EB) {
  3280. /*
  3281. * enable cache line friendly hardware writes:
  3282. * PTHRESH=32 descriptors (half the internal cache),
  3283. * this also removes ugly rx_no_buffer_count increment
  3284. * HTHRESH=4 descriptors (to minimize latency on fetch)
  3285. * WTHRESH=8 burst writeback up to two cache lines
  3286. */
  3287. rxdctl &= ~0x3FFFFF;
  3288. rxdctl |= 0x080420;
  3289. #if (PAGE_SIZE < 8192)
  3290. } else {
  3291. rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK |
  3292. IXGBE_RXDCTL_RLPML_EN);
  3293. /* Limit the maximum frame size so we don't overrun the skb */
  3294. if (ring_uses_build_skb(ring) &&
  3295. !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state))
  3296. rxdctl |= IXGBE_MAX_2K_FRAME_BUILD_SKB |
  3297. IXGBE_RXDCTL_RLPML_EN;
  3298. #endif
  3299. }
  3300. /* initialize rx_buffer_info */
  3301. memset(ring->rx_buffer_info, 0,
  3302. sizeof(struct ixgbe_rx_buffer) * ring->count);
  3303. /* initialize Rx descriptor 0 */
  3304. rx_desc = IXGBE_RX_DESC(ring, 0);
  3305. rx_desc->wb.upper.length = 0;
  3306. /* enable receive descriptor ring */
  3307. rxdctl |= IXGBE_RXDCTL_ENABLE;
  3308. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  3309. ixgbe_rx_desc_queue_enable(adapter, ring);
  3310. ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
  3311. }
  3312. static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
  3313. {
  3314. struct ixgbe_hw *hw = &adapter->hw;
  3315. int rss_i = adapter->ring_feature[RING_F_RSS].indices;
  3316. u16 pool;
  3317. /* PSRTYPE must be initialized in non 82598 adapters */
  3318. u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
  3319. IXGBE_PSRTYPE_UDPHDR |
  3320. IXGBE_PSRTYPE_IPV4HDR |
  3321. IXGBE_PSRTYPE_L2HDR |
  3322. IXGBE_PSRTYPE_IPV6HDR;
  3323. if (hw->mac.type == ixgbe_mac_82598EB)
  3324. return;
  3325. if (rss_i > 3)
  3326. psrtype |= 2u << 29;
  3327. else if (rss_i > 1)
  3328. psrtype |= 1u << 29;
  3329. for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
  3330. IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
  3331. }
  3332. static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
  3333. {
  3334. struct ixgbe_hw *hw = &adapter->hw;
  3335. u32 reg_offset, vf_shift;
  3336. u32 gcr_ext, vmdctl;
  3337. int i;
  3338. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  3339. return;
  3340. vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  3341. vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
  3342. vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
  3343. vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
  3344. vmdctl |= IXGBE_VT_CTL_REPLEN;
  3345. IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
  3346. vf_shift = VMDQ_P(0) % 32;
  3347. reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
  3348. /* Enable only the PF's pool for Tx/Rx */
  3349. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift));
  3350. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
  3351. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift));
  3352. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
  3353. if (adapter->bridge_mode == BRIDGE_MODE_VEB)
  3354. IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
  3355. /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
  3356. hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
  3357. /* clear VLAN promisc flag so VFTA will be updated if necessary */
  3358. adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
  3359. /*
  3360. * Set up VF register offsets for selected VT Mode,
  3361. * i.e. 32 or 64 VFs for SR-IOV
  3362. */
  3363. switch (adapter->ring_feature[RING_F_VMDQ].mask) {
  3364. case IXGBE_82599_VMDQ_8Q_MASK:
  3365. gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
  3366. break;
  3367. case IXGBE_82599_VMDQ_4Q_MASK:
  3368. gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
  3369. break;
  3370. default:
  3371. gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
  3372. break;
  3373. }
  3374. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
  3375. for (i = 0; i < adapter->num_vfs; i++) {
  3376. /* configure spoof checking */
  3377. ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i,
  3378. adapter->vfinfo[i].spoofchk_enabled);
  3379. /* Enable/Disable RSS query feature */
  3380. ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
  3381. adapter->vfinfo[i].rss_query_enabled);
  3382. }
  3383. }
  3384. static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
  3385. {
  3386. struct ixgbe_hw *hw = &adapter->hw;
  3387. struct net_device *netdev = adapter->netdev;
  3388. int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  3389. struct ixgbe_ring *rx_ring;
  3390. int i;
  3391. u32 mhadd, hlreg0;
  3392. #ifdef IXGBE_FCOE
  3393. /* adjust max frame to be able to do baby jumbo for FCoE */
  3394. if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
  3395. (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
  3396. max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  3397. #endif /* IXGBE_FCOE */
  3398. /* adjust max frame to be at least the size of a standard frame */
  3399. if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
  3400. max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
  3401. mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
  3402. if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
  3403. mhadd &= ~IXGBE_MHADD_MFS_MASK;
  3404. mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
  3405. IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
  3406. }
  3407. hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
  3408. /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
  3409. hlreg0 |= IXGBE_HLREG0_JUMBOEN;
  3410. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
  3411. /*
  3412. * Setup the HW Rx Head and Tail Descriptor Pointers and
  3413. * the Base and Length of the Rx Descriptor Ring
  3414. */
  3415. for (i = 0; i < adapter->num_rx_queues; i++) {
  3416. rx_ring = adapter->rx_ring[i];
  3417. clear_ring_rsc_enabled(rx_ring);
  3418. clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3419. clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
  3420. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  3421. set_ring_rsc_enabled(rx_ring);
  3422. if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state))
  3423. set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3424. clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
  3425. if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY)
  3426. continue;
  3427. set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
  3428. #if (PAGE_SIZE < 8192)
  3429. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  3430. set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3431. if (IXGBE_2K_TOO_SMALL_WITH_PADDING ||
  3432. (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
  3433. set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3434. #endif
  3435. }
  3436. }
  3437. static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
  3438. {
  3439. struct ixgbe_hw *hw = &adapter->hw;
  3440. u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  3441. switch (hw->mac.type) {
  3442. case ixgbe_mac_82598EB:
  3443. /*
  3444. * For VMDq support of different descriptor types or
  3445. * buffer sizes through the use of multiple SRRCTL
  3446. * registers, RDRXCTL.MVMEN must be set to 1
  3447. *
  3448. * also, the manual doesn't mention it clearly but DCA hints
  3449. * will only use queue 0's tags unless this bit is set. Side
  3450. * effects of setting this bit are only that SRRCTL must be
  3451. * fully programmed [0..15]
  3452. */
  3453. rdrxctl |= IXGBE_RDRXCTL_MVMEN;
  3454. break;
  3455. case ixgbe_mac_X550:
  3456. case ixgbe_mac_X550EM_x:
  3457. case ixgbe_mac_x550em_a:
  3458. if (adapter->num_vfs)
  3459. rdrxctl |= IXGBE_RDRXCTL_PSP;
  3460. /* fall through for older HW */
  3461. case ixgbe_mac_82599EB:
  3462. case ixgbe_mac_X540:
  3463. /* Disable RSC for ACK packets */
  3464. IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
  3465. (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
  3466. rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
  3467. /* hardware requires some bits to be set by default */
  3468. rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
  3469. rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
  3470. break;
  3471. default:
  3472. /* We should do nothing since we don't know this hardware */
  3473. return;
  3474. }
  3475. IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
  3476. }
  3477. /**
  3478. * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
  3479. * @adapter: board private structure
  3480. *
  3481. * Configure the Rx unit of the MAC after a reset.
  3482. **/
  3483. static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
  3484. {
  3485. struct ixgbe_hw *hw = &adapter->hw;
  3486. int i;
  3487. u32 rxctrl, rfctl;
  3488. /* disable receives while setting up the descriptors */
  3489. hw->mac.ops.disable_rx(hw);
  3490. ixgbe_setup_psrtype(adapter);
  3491. ixgbe_setup_rdrxctl(adapter);
  3492. /* RSC Setup */
  3493. rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
  3494. rfctl &= ~IXGBE_RFCTL_RSC_DIS;
  3495. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
  3496. rfctl |= IXGBE_RFCTL_RSC_DIS;
  3497. /* disable NFS filtering */
  3498. rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS);
  3499. IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
  3500. /* Program registers for the distribution of queues */
  3501. ixgbe_setup_mrqc(adapter);
  3502. /* set_rx_buffer_len must be called before ring initialization */
  3503. ixgbe_set_rx_buffer_len(adapter);
  3504. /*
  3505. * Setup the HW Rx Head and Tail Descriptor Pointers and
  3506. * the Base and Length of the Rx Descriptor Ring
  3507. */
  3508. for (i = 0; i < adapter->num_rx_queues; i++)
  3509. ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
  3510. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  3511. /* disable drop enable for 82598 parts */
  3512. if (hw->mac.type == ixgbe_mac_82598EB)
  3513. rxctrl |= IXGBE_RXCTRL_DMBYPS;
  3514. /* enable all receives */
  3515. rxctrl |= IXGBE_RXCTRL_RXEN;
  3516. hw->mac.ops.enable_rx_dma(hw, rxctrl);
  3517. }
  3518. static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
  3519. __be16 proto, u16 vid)
  3520. {
  3521. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3522. struct ixgbe_hw *hw = &adapter->hw;
  3523. /* add VID to filter table */
  3524. if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3525. hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
  3526. set_bit(vid, adapter->active_vlans);
  3527. return 0;
  3528. }
  3529. static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
  3530. {
  3531. u32 vlvf;
  3532. int idx;
  3533. /* short cut the special case */
  3534. if (vlan == 0)
  3535. return 0;
  3536. /* Search for the vlan id in the VLVF entries */
  3537. for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
  3538. vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
  3539. if ((vlvf & VLAN_VID_MASK) == vlan)
  3540. break;
  3541. }
  3542. return idx;
  3543. }
  3544. void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
  3545. {
  3546. struct ixgbe_hw *hw = &adapter->hw;
  3547. u32 bits, word;
  3548. int idx;
  3549. idx = ixgbe_find_vlvf_entry(hw, vid);
  3550. if (!idx)
  3551. return;
  3552. /* See if any other pools are set for this VLAN filter
  3553. * entry other than the PF.
  3554. */
  3555. word = idx * 2 + (VMDQ_P(0) / 32);
  3556. bits = ~BIT(VMDQ_P(0) % 32);
  3557. bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
  3558. /* Disable the filter so this falls into the default pool. */
  3559. if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
  3560. if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3561. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
  3562. IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
  3563. }
  3564. }
  3565. static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
  3566. __be16 proto, u16 vid)
  3567. {
  3568. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3569. struct ixgbe_hw *hw = &adapter->hw;
  3570. /* remove VID from filter table */
  3571. if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3572. hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
  3573. clear_bit(vid, adapter->active_vlans);
  3574. return 0;
  3575. }
  3576. /**
  3577. * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
  3578. * @adapter: driver data
  3579. */
  3580. static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
  3581. {
  3582. struct ixgbe_hw *hw = &adapter->hw;
  3583. u32 vlnctrl;
  3584. int i, j;
  3585. switch (hw->mac.type) {
  3586. case ixgbe_mac_82598EB:
  3587. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3588. vlnctrl &= ~IXGBE_VLNCTRL_VME;
  3589. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3590. break;
  3591. case ixgbe_mac_82599EB:
  3592. case ixgbe_mac_X540:
  3593. case ixgbe_mac_X550:
  3594. case ixgbe_mac_X550EM_x:
  3595. case ixgbe_mac_x550em_a:
  3596. for (i = 0; i < adapter->num_rx_queues; i++) {
  3597. struct ixgbe_ring *ring = adapter->rx_ring[i];
  3598. if (ring->l2_accel_priv)
  3599. continue;
  3600. j = ring->reg_idx;
  3601. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  3602. vlnctrl &= ~IXGBE_RXDCTL_VME;
  3603. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  3604. }
  3605. break;
  3606. default:
  3607. break;
  3608. }
  3609. }
  3610. /**
  3611. * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
  3612. * @adapter: driver data
  3613. */
  3614. static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
  3615. {
  3616. struct ixgbe_hw *hw = &adapter->hw;
  3617. u32 vlnctrl;
  3618. int i, j;
  3619. switch (hw->mac.type) {
  3620. case ixgbe_mac_82598EB:
  3621. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3622. vlnctrl |= IXGBE_VLNCTRL_VME;
  3623. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3624. break;
  3625. case ixgbe_mac_82599EB:
  3626. case ixgbe_mac_X540:
  3627. case ixgbe_mac_X550:
  3628. case ixgbe_mac_X550EM_x:
  3629. case ixgbe_mac_x550em_a:
  3630. for (i = 0; i < adapter->num_rx_queues; i++) {
  3631. struct ixgbe_ring *ring = adapter->rx_ring[i];
  3632. if (ring->l2_accel_priv)
  3633. continue;
  3634. j = ring->reg_idx;
  3635. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  3636. vlnctrl |= IXGBE_RXDCTL_VME;
  3637. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  3638. }
  3639. break;
  3640. default:
  3641. break;
  3642. }
  3643. }
  3644. static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
  3645. {
  3646. struct ixgbe_hw *hw = &adapter->hw;
  3647. u32 vlnctrl, i;
  3648. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3649. if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
  3650. /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
  3651. vlnctrl |= IXGBE_VLNCTRL_VFE;
  3652. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3653. } else {
  3654. vlnctrl &= ~IXGBE_VLNCTRL_VFE;
  3655. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3656. return;
  3657. }
  3658. /* Nothing to do for 82598 */
  3659. if (hw->mac.type == ixgbe_mac_82598EB)
  3660. return;
  3661. /* We are already in VLAN promisc, nothing to do */
  3662. if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
  3663. return;
  3664. /* Set flag so we don't redo unnecessary work */
  3665. adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
  3666. /* Add PF to all active pools */
  3667. for (i = IXGBE_VLVF_ENTRIES; --i;) {
  3668. u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
  3669. u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
  3670. vlvfb |= BIT(VMDQ_P(0) % 32);
  3671. IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
  3672. }
  3673. /* Set all bits in the VLAN filter table array */
  3674. for (i = hw->mac.vft_size; i--;)
  3675. IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
  3676. }
  3677. #define VFTA_BLOCK_SIZE 8
  3678. static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
  3679. {
  3680. struct ixgbe_hw *hw = &adapter->hw;
  3681. u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
  3682. u32 vid_start = vfta_offset * 32;
  3683. u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
  3684. u32 i, vid, word, bits;
  3685. for (i = IXGBE_VLVF_ENTRIES; --i;) {
  3686. u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
  3687. /* pull VLAN ID from VLVF */
  3688. vid = vlvf & VLAN_VID_MASK;
  3689. /* only concern outselves with a certain range */
  3690. if (vid < vid_start || vid >= vid_end)
  3691. continue;
  3692. if (vlvf) {
  3693. /* record VLAN ID in VFTA */
  3694. vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
  3695. /* if PF is part of this then continue */
  3696. if (test_bit(vid, adapter->active_vlans))
  3697. continue;
  3698. }
  3699. /* remove PF from the pool */
  3700. word = i * 2 + VMDQ_P(0) / 32;
  3701. bits = ~BIT(VMDQ_P(0) % 32);
  3702. bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
  3703. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
  3704. }
  3705. /* extract values from active_vlans and write back to VFTA */
  3706. for (i = VFTA_BLOCK_SIZE; i--;) {
  3707. vid = (vfta_offset + i) * 32;
  3708. word = vid / BITS_PER_LONG;
  3709. bits = vid % BITS_PER_LONG;
  3710. vfta[i] |= adapter->active_vlans[word] >> bits;
  3711. IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
  3712. }
  3713. }
  3714. static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
  3715. {
  3716. struct ixgbe_hw *hw = &adapter->hw;
  3717. u32 vlnctrl, i;
  3718. /* Set VLAN filtering to enabled */
  3719. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3720. vlnctrl |= IXGBE_VLNCTRL_VFE;
  3721. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3722. if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) ||
  3723. hw->mac.type == ixgbe_mac_82598EB)
  3724. return;
  3725. /* We are not in VLAN promisc, nothing to do */
  3726. if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3727. return;
  3728. /* Set flag so we don't redo unnecessary work */
  3729. adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
  3730. for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
  3731. ixgbe_scrub_vfta(adapter, i);
  3732. }
  3733. static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
  3734. {
  3735. u16 vid = 1;
  3736. ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
  3737. for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
  3738. ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
  3739. }
  3740. /**
  3741. * ixgbe_write_mc_addr_list - write multicast addresses to MTA
  3742. * @netdev: network interface device structure
  3743. *
  3744. * Writes multicast address list to the MTA hash table.
  3745. * Returns: -ENOMEM on failure
  3746. * 0 on no addresses written
  3747. * X on writing X addresses to MTA
  3748. **/
  3749. static int ixgbe_write_mc_addr_list(struct net_device *netdev)
  3750. {
  3751. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3752. struct ixgbe_hw *hw = &adapter->hw;
  3753. if (!netif_running(netdev))
  3754. return 0;
  3755. if (hw->mac.ops.update_mc_addr_list)
  3756. hw->mac.ops.update_mc_addr_list(hw, netdev);
  3757. else
  3758. return -ENOMEM;
  3759. #ifdef CONFIG_PCI_IOV
  3760. ixgbe_restore_vf_multicasts(adapter);
  3761. #endif
  3762. return netdev_mc_count(netdev);
  3763. }
  3764. #ifdef CONFIG_PCI_IOV
  3765. void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
  3766. {
  3767. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  3768. struct ixgbe_hw *hw = &adapter->hw;
  3769. int i;
  3770. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  3771. mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
  3772. if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
  3773. hw->mac.ops.set_rar(hw, i,
  3774. mac_table->addr,
  3775. mac_table->pool,
  3776. IXGBE_RAH_AV);
  3777. else
  3778. hw->mac.ops.clear_rar(hw, i);
  3779. }
  3780. }
  3781. #endif
  3782. static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
  3783. {
  3784. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  3785. struct ixgbe_hw *hw = &adapter->hw;
  3786. int i;
  3787. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  3788. if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
  3789. continue;
  3790. mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
  3791. if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
  3792. hw->mac.ops.set_rar(hw, i,
  3793. mac_table->addr,
  3794. mac_table->pool,
  3795. IXGBE_RAH_AV);
  3796. else
  3797. hw->mac.ops.clear_rar(hw, i);
  3798. }
  3799. }
  3800. static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
  3801. {
  3802. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  3803. struct ixgbe_hw *hw = &adapter->hw;
  3804. int i;
  3805. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  3806. mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
  3807. mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
  3808. }
  3809. ixgbe_sync_mac_table(adapter);
  3810. }
  3811. static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
  3812. {
  3813. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  3814. struct ixgbe_hw *hw = &adapter->hw;
  3815. int i, count = 0;
  3816. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  3817. /* do not count default RAR as available */
  3818. if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
  3819. continue;
  3820. /* only count unused and addresses that belong to us */
  3821. if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
  3822. if (mac_table->pool != pool)
  3823. continue;
  3824. }
  3825. count++;
  3826. }
  3827. return count;
  3828. }
  3829. /* this function destroys the first RAR entry */
  3830. static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
  3831. {
  3832. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  3833. struct ixgbe_hw *hw = &adapter->hw;
  3834. memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
  3835. mac_table->pool = VMDQ_P(0);
  3836. mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
  3837. hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
  3838. IXGBE_RAH_AV);
  3839. }
  3840. int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
  3841. const u8 *addr, u16 pool)
  3842. {
  3843. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  3844. struct ixgbe_hw *hw = &adapter->hw;
  3845. int i;
  3846. if (is_zero_ether_addr(addr))
  3847. return -EINVAL;
  3848. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  3849. if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
  3850. continue;
  3851. ether_addr_copy(mac_table->addr, addr);
  3852. mac_table->pool = pool;
  3853. mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
  3854. IXGBE_MAC_STATE_IN_USE;
  3855. ixgbe_sync_mac_table(adapter);
  3856. return i;
  3857. }
  3858. return -ENOMEM;
  3859. }
  3860. int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
  3861. const u8 *addr, u16 pool)
  3862. {
  3863. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  3864. struct ixgbe_hw *hw = &adapter->hw;
  3865. int i;
  3866. if (is_zero_ether_addr(addr))
  3867. return -EINVAL;
  3868. /* search table for addr, if found clear IN_USE flag and sync */
  3869. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  3870. /* we can only delete an entry if it is in use */
  3871. if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
  3872. continue;
  3873. /* we only care about entries that belong to the given pool */
  3874. if (mac_table->pool != pool)
  3875. continue;
  3876. /* we only care about a specific MAC address */
  3877. if (!ether_addr_equal(addr, mac_table->addr))
  3878. continue;
  3879. mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
  3880. mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
  3881. ixgbe_sync_mac_table(adapter);
  3882. return 0;
  3883. }
  3884. return -ENOMEM;
  3885. }
  3886. /**
  3887. * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
  3888. * @netdev: network interface device structure
  3889. *
  3890. * Writes unicast address list to the RAR table.
  3891. * Returns: -ENOMEM on failure/insufficient address space
  3892. * 0 on no addresses written
  3893. * X on writing X addresses to the RAR table
  3894. **/
  3895. static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
  3896. {
  3897. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3898. int count = 0;
  3899. /* return ENOMEM indicating insufficient memory for addresses */
  3900. if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn))
  3901. return -ENOMEM;
  3902. if (!netdev_uc_empty(netdev)) {
  3903. struct netdev_hw_addr *ha;
  3904. netdev_for_each_uc_addr(ha, netdev) {
  3905. ixgbe_del_mac_filter(adapter, ha->addr, vfn);
  3906. ixgbe_add_mac_filter(adapter, ha->addr, vfn);
  3907. count++;
  3908. }
  3909. }
  3910. return count;
  3911. }
  3912. static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
  3913. {
  3914. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3915. int ret;
  3916. ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
  3917. return min_t(int, ret, 0);
  3918. }
  3919. static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
  3920. {
  3921. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3922. ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
  3923. return 0;
  3924. }
  3925. /**
  3926. * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
  3927. * @netdev: network interface device structure
  3928. *
  3929. * The set_rx_method entry point is called whenever the unicast/multicast
  3930. * address list or the network interface flags are updated. This routine is
  3931. * responsible for configuring the hardware for proper unicast, multicast and
  3932. * promiscuous mode.
  3933. **/
  3934. void ixgbe_set_rx_mode(struct net_device *netdev)
  3935. {
  3936. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3937. struct ixgbe_hw *hw = &adapter->hw;
  3938. u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
  3939. netdev_features_t features = netdev->features;
  3940. int count;
  3941. /* Check for Promiscuous and All Multicast modes */
  3942. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  3943. /* set all bits that we expect to always be set */
  3944. fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
  3945. fctrl |= IXGBE_FCTRL_BAM;
  3946. fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
  3947. fctrl |= IXGBE_FCTRL_PMCF;
  3948. /* clear the bits we are changing the status of */
  3949. fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  3950. if (netdev->flags & IFF_PROMISC) {
  3951. hw->addr_ctrl.user_set_promisc = true;
  3952. fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  3953. vmolr |= IXGBE_VMOLR_MPE;
  3954. features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
  3955. } else {
  3956. if (netdev->flags & IFF_ALLMULTI) {
  3957. fctrl |= IXGBE_FCTRL_MPE;
  3958. vmolr |= IXGBE_VMOLR_MPE;
  3959. }
  3960. hw->addr_ctrl.user_set_promisc = false;
  3961. }
  3962. /*
  3963. * Write addresses to available RAR registers, if there is not
  3964. * sufficient space to store all the addresses then enable
  3965. * unicast promiscuous mode
  3966. */
  3967. if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
  3968. fctrl |= IXGBE_FCTRL_UPE;
  3969. vmolr |= IXGBE_VMOLR_ROPE;
  3970. }
  3971. /* Write addresses to the MTA, if the attempt fails
  3972. * then we should just turn on promiscuous mode so
  3973. * that we can at least receive multicast traffic
  3974. */
  3975. count = ixgbe_write_mc_addr_list(netdev);
  3976. if (count < 0) {
  3977. fctrl |= IXGBE_FCTRL_MPE;
  3978. vmolr |= IXGBE_VMOLR_MPE;
  3979. } else if (count) {
  3980. vmolr |= IXGBE_VMOLR_ROMPE;
  3981. }
  3982. if (hw->mac.type != ixgbe_mac_82598EB) {
  3983. vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
  3984. ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
  3985. IXGBE_VMOLR_ROPE);
  3986. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
  3987. }
  3988. /* This is useful for sniffing bad packets. */
  3989. if (features & NETIF_F_RXALL) {
  3990. /* UPE and MPE will be handled by normal PROMISC logic
  3991. * in e1000e_set_rx_mode */
  3992. fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
  3993. IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
  3994. IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
  3995. fctrl &= ~(IXGBE_FCTRL_DPF);
  3996. /* NOTE: VLAN filtering is disabled by setting PROMISC */
  3997. }
  3998. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  3999. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  4000. ixgbe_vlan_strip_enable(adapter);
  4001. else
  4002. ixgbe_vlan_strip_disable(adapter);
  4003. if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
  4004. ixgbe_vlan_promisc_disable(adapter);
  4005. else
  4006. ixgbe_vlan_promisc_enable(adapter);
  4007. }
  4008. static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
  4009. {
  4010. int q_idx;
  4011. for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
  4012. napi_enable(&adapter->q_vector[q_idx]->napi);
  4013. }
  4014. static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
  4015. {
  4016. int q_idx;
  4017. for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
  4018. napi_disable(&adapter->q_vector[q_idx]->napi);
  4019. }
  4020. static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask)
  4021. {
  4022. struct ixgbe_hw *hw = &adapter->hw;
  4023. u32 vxlanctrl;
  4024. if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE |
  4025. IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)))
  4026. return;
  4027. vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) && ~mask;
  4028. IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl);
  4029. if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK)
  4030. adapter->vxlan_port = 0;
  4031. if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK)
  4032. adapter->geneve_port = 0;
  4033. }
  4034. #ifdef CONFIG_IXGBE_DCB
  4035. /**
  4036. * ixgbe_configure_dcb - Configure DCB hardware
  4037. * @adapter: ixgbe adapter struct
  4038. *
  4039. * This is called by the driver on open to configure the DCB hardware.
  4040. * This is also called by the gennetlink interface when reconfiguring
  4041. * the DCB state.
  4042. */
  4043. static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
  4044. {
  4045. struct ixgbe_hw *hw = &adapter->hw;
  4046. int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  4047. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
  4048. if (hw->mac.type == ixgbe_mac_82598EB)
  4049. netif_set_gso_max_size(adapter->netdev, 65536);
  4050. return;
  4051. }
  4052. if (hw->mac.type == ixgbe_mac_82598EB)
  4053. netif_set_gso_max_size(adapter->netdev, 32768);
  4054. #ifdef IXGBE_FCOE
  4055. if (adapter->netdev->features & NETIF_F_FCOE_MTU)
  4056. max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
  4057. #endif
  4058. /* reconfigure the hardware */
  4059. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
  4060. ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
  4061. DCB_TX_CONFIG);
  4062. ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
  4063. DCB_RX_CONFIG);
  4064. ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
  4065. } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
  4066. ixgbe_dcb_hw_ets(&adapter->hw,
  4067. adapter->ixgbe_ieee_ets,
  4068. max_frame);
  4069. ixgbe_dcb_hw_pfc_config(&adapter->hw,
  4070. adapter->ixgbe_ieee_pfc->pfc_en,
  4071. adapter->ixgbe_ieee_ets->prio_tc);
  4072. }
  4073. /* Enable RSS Hash per TC */
  4074. if (hw->mac.type != ixgbe_mac_82598EB) {
  4075. u32 msb = 0;
  4076. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
  4077. while (rss_i) {
  4078. msb++;
  4079. rss_i >>= 1;
  4080. }
  4081. /* write msb to all 8 TCs in one write */
  4082. IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
  4083. }
  4084. }
  4085. #endif
  4086. /* Additional bittime to account for IXGBE framing */
  4087. #define IXGBE_ETH_FRAMING 20
  4088. /**
  4089. * ixgbe_hpbthresh - calculate high water mark for flow control
  4090. *
  4091. * @adapter: board private structure to calculate for
  4092. * @pb: packet buffer to calculate
  4093. */
  4094. static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
  4095. {
  4096. struct ixgbe_hw *hw = &adapter->hw;
  4097. struct net_device *dev = adapter->netdev;
  4098. int link, tc, kb, marker;
  4099. u32 dv_id, rx_pba;
  4100. /* Calculate max LAN frame size */
  4101. tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
  4102. #ifdef IXGBE_FCOE
  4103. /* FCoE traffic class uses FCOE jumbo frames */
  4104. if ((dev->features & NETIF_F_FCOE_MTU) &&
  4105. (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
  4106. (pb == ixgbe_fcoe_get_tc(adapter)))
  4107. tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  4108. #endif
  4109. /* Calculate delay value for device */
  4110. switch (hw->mac.type) {
  4111. case ixgbe_mac_X540:
  4112. case ixgbe_mac_X550:
  4113. case ixgbe_mac_X550EM_x:
  4114. case ixgbe_mac_x550em_a:
  4115. dv_id = IXGBE_DV_X540(link, tc);
  4116. break;
  4117. default:
  4118. dv_id = IXGBE_DV(link, tc);
  4119. break;
  4120. }
  4121. /* Loopback switch introduces additional latency */
  4122. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  4123. dv_id += IXGBE_B2BT(tc);
  4124. /* Delay value is calculated in bit times convert to KB */
  4125. kb = IXGBE_BT2KB(dv_id);
  4126. rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
  4127. marker = rx_pba - kb;
  4128. /* It is possible that the packet buffer is not large enough
  4129. * to provide required headroom. In this case throw an error
  4130. * to user and a do the best we can.
  4131. */
  4132. if (marker < 0) {
  4133. e_warn(drv, "Packet Buffer(%i) can not provide enough"
  4134. "headroom to support flow control."
  4135. "Decrease MTU or number of traffic classes\n", pb);
  4136. marker = tc + 1;
  4137. }
  4138. return marker;
  4139. }
  4140. /**
  4141. * ixgbe_lpbthresh - calculate low water mark for for flow control
  4142. *
  4143. * @adapter: board private structure to calculate for
  4144. * @pb: packet buffer to calculate
  4145. */
  4146. static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
  4147. {
  4148. struct ixgbe_hw *hw = &adapter->hw;
  4149. struct net_device *dev = adapter->netdev;
  4150. int tc;
  4151. u32 dv_id;
  4152. /* Calculate max LAN frame size */
  4153. tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
  4154. #ifdef IXGBE_FCOE
  4155. /* FCoE traffic class uses FCOE jumbo frames */
  4156. if ((dev->features & NETIF_F_FCOE_MTU) &&
  4157. (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
  4158. (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
  4159. tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  4160. #endif
  4161. /* Calculate delay value for device */
  4162. switch (hw->mac.type) {
  4163. case ixgbe_mac_X540:
  4164. case ixgbe_mac_X550:
  4165. case ixgbe_mac_X550EM_x:
  4166. case ixgbe_mac_x550em_a:
  4167. dv_id = IXGBE_LOW_DV_X540(tc);
  4168. break;
  4169. default:
  4170. dv_id = IXGBE_LOW_DV(tc);
  4171. break;
  4172. }
  4173. /* Delay value is calculated in bit times convert to KB */
  4174. return IXGBE_BT2KB(dv_id);
  4175. }
  4176. /*
  4177. * ixgbe_pbthresh_setup - calculate and setup high low water marks
  4178. */
  4179. static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
  4180. {
  4181. struct ixgbe_hw *hw = &adapter->hw;
  4182. int num_tc = netdev_get_num_tc(adapter->netdev);
  4183. int i;
  4184. if (!num_tc)
  4185. num_tc = 1;
  4186. for (i = 0; i < num_tc; i++) {
  4187. hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
  4188. hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
  4189. /* Low water marks must not be larger than high water marks */
  4190. if (hw->fc.low_water[i] > hw->fc.high_water[i])
  4191. hw->fc.low_water[i] = 0;
  4192. }
  4193. for (; i < MAX_TRAFFIC_CLASS; i++)
  4194. hw->fc.high_water[i] = 0;
  4195. }
  4196. static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
  4197. {
  4198. struct ixgbe_hw *hw = &adapter->hw;
  4199. int hdrm;
  4200. u8 tc = netdev_get_num_tc(adapter->netdev);
  4201. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  4202. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  4203. hdrm = 32 << adapter->fdir_pballoc;
  4204. else
  4205. hdrm = 0;
  4206. hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
  4207. ixgbe_pbthresh_setup(adapter);
  4208. }
  4209. static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
  4210. {
  4211. struct ixgbe_hw *hw = &adapter->hw;
  4212. struct hlist_node *node2;
  4213. struct ixgbe_fdir_filter *filter;
  4214. spin_lock(&adapter->fdir_perfect_lock);
  4215. if (!hlist_empty(&adapter->fdir_filter_list))
  4216. ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
  4217. hlist_for_each_entry_safe(filter, node2,
  4218. &adapter->fdir_filter_list, fdir_node) {
  4219. ixgbe_fdir_write_perfect_filter_82599(hw,
  4220. &filter->filter,
  4221. filter->sw_idx,
  4222. (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
  4223. IXGBE_FDIR_DROP_QUEUE :
  4224. adapter->rx_ring[filter->action]->reg_idx);
  4225. }
  4226. spin_unlock(&adapter->fdir_perfect_lock);
  4227. }
  4228. static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
  4229. struct ixgbe_adapter *adapter)
  4230. {
  4231. struct ixgbe_hw *hw = &adapter->hw;
  4232. u32 vmolr;
  4233. /* No unicast promiscuous support for VMDQ devices. */
  4234. vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
  4235. vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
  4236. /* clear the affected bit */
  4237. vmolr &= ~IXGBE_VMOLR_MPE;
  4238. if (dev->flags & IFF_ALLMULTI) {
  4239. vmolr |= IXGBE_VMOLR_MPE;
  4240. } else {
  4241. vmolr |= IXGBE_VMOLR_ROMPE;
  4242. hw->mac.ops.update_mc_addr_list(hw, dev);
  4243. }
  4244. ixgbe_write_uc_addr_list(adapter->netdev, pool);
  4245. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
  4246. }
  4247. static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
  4248. {
  4249. struct ixgbe_adapter *adapter = vadapter->real_adapter;
  4250. int rss_i = adapter->num_rx_queues_per_pool;
  4251. struct ixgbe_hw *hw = &adapter->hw;
  4252. u16 pool = vadapter->pool;
  4253. u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
  4254. IXGBE_PSRTYPE_UDPHDR |
  4255. IXGBE_PSRTYPE_IPV4HDR |
  4256. IXGBE_PSRTYPE_L2HDR |
  4257. IXGBE_PSRTYPE_IPV6HDR;
  4258. if (hw->mac.type == ixgbe_mac_82598EB)
  4259. return;
  4260. if (rss_i > 3)
  4261. psrtype |= 2u << 29;
  4262. else if (rss_i > 1)
  4263. psrtype |= 1u << 29;
  4264. IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
  4265. }
  4266. /**
  4267. * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
  4268. * @rx_ring: ring to free buffers from
  4269. **/
  4270. static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
  4271. {
  4272. u16 i = rx_ring->next_to_clean;
  4273. struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
  4274. /* Free all the Rx ring sk_buffs */
  4275. while (i != rx_ring->next_to_alloc) {
  4276. if (rx_buffer->skb) {
  4277. struct sk_buff *skb = rx_buffer->skb;
  4278. if (IXGBE_CB(skb)->page_released)
  4279. dma_unmap_page_attrs(rx_ring->dev,
  4280. IXGBE_CB(skb)->dma,
  4281. ixgbe_rx_pg_size(rx_ring),
  4282. DMA_FROM_DEVICE,
  4283. IXGBE_RX_DMA_ATTR);
  4284. dev_kfree_skb(skb);
  4285. }
  4286. /* Invalidate cache lines that may have been written to by
  4287. * device so that we avoid corrupting memory.
  4288. */
  4289. dma_sync_single_range_for_cpu(rx_ring->dev,
  4290. rx_buffer->dma,
  4291. rx_buffer->page_offset,
  4292. ixgbe_rx_bufsz(rx_ring),
  4293. DMA_FROM_DEVICE);
  4294. /* free resources associated with mapping */
  4295. dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
  4296. ixgbe_rx_pg_size(rx_ring),
  4297. DMA_FROM_DEVICE,
  4298. IXGBE_RX_DMA_ATTR);
  4299. __page_frag_cache_drain(rx_buffer->page,
  4300. rx_buffer->pagecnt_bias);
  4301. i++;
  4302. rx_buffer++;
  4303. if (i == rx_ring->count) {
  4304. i = 0;
  4305. rx_buffer = rx_ring->rx_buffer_info;
  4306. }
  4307. }
  4308. rx_ring->next_to_alloc = 0;
  4309. rx_ring->next_to_clean = 0;
  4310. rx_ring->next_to_use = 0;
  4311. }
  4312. static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
  4313. struct ixgbe_ring *rx_ring)
  4314. {
  4315. struct ixgbe_adapter *adapter = vadapter->real_adapter;
  4316. int index = rx_ring->queue_index + vadapter->rx_base_queue;
  4317. /* shutdown specific queue receive and wait for dma to settle */
  4318. ixgbe_disable_rx_queue(adapter, rx_ring);
  4319. usleep_range(10000, 20000);
  4320. ixgbe_irq_disable_queues(adapter, BIT_ULL(index));
  4321. ixgbe_clean_rx_ring(rx_ring);
  4322. rx_ring->l2_accel_priv = NULL;
  4323. }
  4324. static int ixgbe_fwd_ring_down(struct net_device *vdev,
  4325. struct ixgbe_fwd_adapter *accel)
  4326. {
  4327. struct ixgbe_adapter *adapter = accel->real_adapter;
  4328. unsigned int rxbase = accel->rx_base_queue;
  4329. unsigned int txbase = accel->tx_base_queue;
  4330. int i;
  4331. netif_tx_stop_all_queues(vdev);
  4332. for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
  4333. ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
  4334. adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
  4335. }
  4336. for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
  4337. adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
  4338. adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
  4339. }
  4340. return 0;
  4341. }
  4342. static int ixgbe_fwd_ring_up(struct net_device *vdev,
  4343. struct ixgbe_fwd_adapter *accel)
  4344. {
  4345. struct ixgbe_adapter *adapter = accel->real_adapter;
  4346. unsigned int rxbase, txbase, queues;
  4347. int i, baseq, err = 0;
  4348. if (!test_bit(accel->pool, &adapter->fwd_bitmask))
  4349. return 0;
  4350. baseq = accel->pool * adapter->num_rx_queues_per_pool;
  4351. netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
  4352. accel->pool, adapter->num_rx_pools,
  4353. baseq, baseq + adapter->num_rx_queues_per_pool,
  4354. adapter->fwd_bitmask);
  4355. accel->netdev = vdev;
  4356. accel->rx_base_queue = rxbase = baseq;
  4357. accel->tx_base_queue = txbase = baseq;
  4358. for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
  4359. ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
  4360. for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
  4361. adapter->rx_ring[rxbase + i]->netdev = vdev;
  4362. adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
  4363. ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
  4364. }
  4365. for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
  4366. adapter->tx_ring[txbase + i]->netdev = vdev;
  4367. adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
  4368. }
  4369. queues = min_t(unsigned int,
  4370. adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
  4371. err = netif_set_real_num_tx_queues(vdev, queues);
  4372. if (err)
  4373. goto fwd_queue_err;
  4374. err = netif_set_real_num_rx_queues(vdev, queues);
  4375. if (err)
  4376. goto fwd_queue_err;
  4377. if (is_valid_ether_addr(vdev->dev_addr))
  4378. ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool);
  4379. ixgbe_fwd_psrtype(accel);
  4380. ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter);
  4381. return err;
  4382. fwd_queue_err:
  4383. ixgbe_fwd_ring_down(vdev, accel);
  4384. return err;
  4385. }
  4386. static int ixgbe_upper_dev_walk(struct net_device *upper, void *data)
  4387. {
  4388. if (netif_is_macvlan(upper)) {
  4389. struct macvlan_dev *dfwd = netdev_priv(upper);
  4390. struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
  4391. if (dfwd->fwd_priv)
  4392. ixgbe_fwd_ring_up(upper, vadapter);
  4393. }
  4394. return 0;
  4395. }
  4396. static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
  4397. {
  4398. netdev_walk_all_upper_dev_rcu(adapter->netdev,
  4399. ixgbe_upper_dev_walk, NULL);
  4400. }
  4401. static void ixgbe_configure(struct ixgbe_adapter *adapter)
  4402. {
  4403. struct ixgbe_hw *hw = &adapter->hw;
  4404. ixgbe_configure_pb(adapter);
  4405. #ifdef CONFIG_IXGBE_DCB
  4406. ixgbe_configure_dcb(adapter);
  4407. #endif
  4408. /*
  4409. * We must restore virtualization before VLANs or else
  4410. * the VLVF registers will not be populated
  4411. */
  4412. ixgbe_configure_virtualization(adapter);
  4413. ixgbe_set_rx_mode(adapter->netdev);
  4414. ixgbe_restore_vlan(adapter);
  4415. switch (hw->mac.type) {
  4416. case ixgbe_mac_82599EB:
  4417. case ixgbe_mac_X540:
  4418. hw->mac.ops.disable_rx_buff(hw);
  4419. break;
  4420. default:
  4421. break;
  4422. }
  4423. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  4424. ixgbe_init_fdir_signature_82599(&adapter->hw,
  4425. adapter->fdir_pballoc);
  4426. } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
  4427. ixgbe_init_fdir_perfect_82599(&adapter->hw,
  4428. adapter->fdir_pballoc);
  4429. ixgbe_fdir_filter_restore(adapter);
  4430. }
  4431. switch (hw->mac.type) {
  4432. case ixgbe_mac_82599EB:
  4433. case ixgbe_mac_X540:
  4434. hw->mac.ops.enable_rx_buff(hw);
  4435. break;
  4436. default:
  4437. break;
  4438. }
  4439. #ifdef CONFIG_IXGBE_DCA
  4440. /* configure DCA */
  4441. if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
  4442. ixgbe_setup_dca(adapter);
  4443. #endif /* CONFIG_IXGBE_DCA */
  4444. #ifdef IXGBE_FCOE
  4445. /* configure FCoE L2 filters, redirection table, and Rx control */
  4446. ixgbe_configure_fcoe(adapter);
  4447. #endif /* IXGBE_FCOE */
  4448. ixgbe_configure_tx(adapter);
  4449. ixgbe_configure_rx(adapter);
  4450. ixgbe_configure_dfwd(adapter);
  4451. }
  4452. /**
  4453. * ixgbe_sfp_link_config - set up SFP+ link
  4454. * @adapter: pointer to private adapter struct
  4455. **/
  4456. static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
  4457. {
  4458. /*
  4459. * We are assuming the worst case scenario here, and that
  4460. * is that an SFP was inserted/removed after the reset
  4461. * but before SFP detection was enabled. As such the best
  4462. * solution is to just start searching as soon as we start
  4463. */
  4464. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  4465. adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
  4466. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  4467. adapter->sfp_poll_time = 0;
  4468. }
  4469. /**
  4470. * ixgbe_non_sfp_link_config - set up non-SFP+ link
  4471. * @hw: pointer to private hardware struct
  4472. *
  4473. * Returns 0 on success, negative on failure
  4474. **/
  4475. static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
  4476. {
  4477. u32 speed;
  4478. bool autoneg, link_up = false;
  4479. int ret = IXGBE_ERR_LINK_SETUP;
  4480. if (hw->mac.ops.check_link)
  4481. ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
  4482. if (ret)
  4483. return ret;
  4484. speed = hw->phy.autoneg_advertised;
  4485. if ((!speed) && (hw->mac.ops.get_link_capabilities))
  4486. ret = hw->mac.ops.get_link_capabilities(hw, &speed,
  4487. &autoneg);
  4488. if (ret)
  4489. return ret;
  4490. if (hw->mac.ops.setup_link)
  4491. ret = hw->mac.ops.setup_link(hw, speed, link_up);
  4492. return ret;
  4493. }
  4494. static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
  4495. {
  4496. struct ixgbe_hw *hw = &adapter->hw;
  4497. u32 gpie = 0;
  4498. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  4499. gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
  4500. IXGBE_GPIE_OCD;
  4501. gpie |= IXGBE_GPIE_EIAME;
  4502. /*
  4503. * use EIAM to auto-mask when MSI-X interrupt is asserted
  4504. * this saves a register write for every interrupt
  4505. */
  4506. switch (hw->mac.type) {
  4507. case ixgbe_mac_82598EB:
  4508. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  4509. break;
  4510. case ixgbe_mac_82599EB:
  4511. case ixgbe_mac_X540:
  4512. case ixgbe_mac_X550:
  4513. case ixgbe_mac_X550EM_x:
  4514. case ixgbe_mac_x550em_a:
  4515. default:
  4516. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
  4517. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
  4518. break;
  4519. }
  4520. } else {
  4521. /* legacy interrupts, use EIAM to auto-mask when reading EICR,
  4522. * specifically only auto mask tx and rx interrupts */
  4523. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  4524. }
  4525. /* XXX: to interrupt immediately for EICS writes, enable this */
  4526. /* gpie |= IXGBE_GPIE_EIMEN; */
  4527. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  4528. gpie &= ~IXGBE_GPIE_VTMODE_MASK;
  4529. switch (adapter->ring_feature[RING_F_VMDQ].mask) {
  4530. case IXGBE_82599_VMDQ_8Q_MASK:
  4531. gpie |= IXGBE_GPIE_VTMODE_16;
  4532. break;
  4533. case IXGBE_82599_VMDQ_4Q_MASK:
  4534. gpie |= IXGBE_GPIE_VTMODE_32;
  4535. break;
  4536. default:
  4537. gpie |= IXGBE_GPIE_VTMODE_64;
  4538. break;
  4539. }
  4540. }
  4541. /* Enable Thermal over heat sensor interrupt */
  4542. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
  4543. switch (adapter->hw.mac.type) {
  4544. case ixgbe_mac_82599EB:
  4545. gpie |= IXGBE_SDP0_GPIEN_8259X;
  4546. break;
  4547. default:
  4548. break;
  4549. }
  4550. }
  4551. /* Enable fan failure interrupt */
  4552. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  4553. gpie |= IXGBE_SDP1_GPIEN(hw);
  4554. switch (hw->mac.type) {
  4555. case ixgbe_mac_82599EB:
  4556. gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
  4557. break;
  4558. case ixgbe_mac_X550EM_x:
  4559. case ixgbe_mac_x550em_a:
  4560. gpie |= IXGBE_SDP0_GPIEN_X540;
  4561. break;
  4562. default:
  4563. break;
  4564. }
  4565. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  4566. }
  4567. static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
  4568. {
  4569. struct ixgbe_hw *hw = &adapter->hw;
  4570. int err;
  4571. u32 ctrl_ext;
  4572. ixgbe_get_hw_control(adapter);
  4573. ixgbe_setup_gpie(adapter);
  4574. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  4575. ixgbe_configure_msix(adapter);
  4576. else
  4577. ixgbe_configure_msi_and_legacy(adapter);
  4578. /* enable the optics for 82599 SFP+ fiber */
  4579. if (hw->mac.ops.enable_tx_laser)
  4580. hw->mac.ops.enable_tx_laser(hw);
  4581. if (hw->phy.ops.set_phy_power)
  4582. hw->phy.ops.set_phy_power(hw, true);
  4583. smp_mb__before_atomic();
  4584. clear_bit(__IXGBE_DOWN, &adapter->state);
  4585. ixgbe_napi_enable_all(adapter);
  4586. if (ixgbe_is_sfp(hw)) {
  4587. ixgbe_sfp_link_config(adapter);
  4588. } else {
  4589. err = ixgbe_non_sfp_link_config(hw);
  4590. if (err)
  4591. e_err(probe, "link_config FAILED %d\n", err);
  4592. }
  4593. /* clear any pending interrupts, may auto mask */
  4594. IXGBE_READ_REG(hw, IXGBE_EICR);
  4595. ixgbe_irq_enable(adapter, true, true);
  4596. /*
  4597. * If this adapter has a fan, check to see if we had a failure
  4598. * before we enabled the interrupt.
  4599. */
  4600. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  4601. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  4602. if (esdp & IXGBE_ESDP_SDP1)
  4603. e_crit(drv, "Fan has stopped, replace the adapter\n");
  4604. }
  4605. /* bring the link up in the watchdog, this could race with our first
  4606. * link up interrupt but shouldn't be a problem */
  4607. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  4608. adapter->link_check_timeout = jiffies;
  4609. mod_timer(&adapter->service_timer, jiffies);
  4610. /* Set PF Reset Done bit so PF/VF Mail Ops can work */
  4611. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  4612. ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
  4613. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  4614. }
  4615. void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
  4616. {
  4617. WARN_ON(in_interrupt());
  4618. /* put off any impending NetWatchDogTimeout */
  4619. netif_trans_update(adapter->netdev);
  4620. while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
  4621. usleep_range(1000, 2000);
  4622. if (adapter->hw.phy.type == ixgbe_phy_fw)
  4623. ixgbe_watchdog_link_is_down(adapter);
  4624. ixgbe_down(adapter);
  4625. /*
  4626. * If SR-IOV enabled then wait a bit before bringing the adapter
  4627. * back up to give the VFs time to respond to the reset. The
  4628. * two second wait is based upon the watchdog timer cycle in
  4629. * the VF driver.
  4630. */
  4631. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  4632. msleep(2000);
  4633. ixgbe_up(adapter);
  4634. clear_bit(__IXGBE_RESETTING, &adapter->state);
  4635. }
  4636. void ixgbe_up(struct ixgbe_adapter *adapter)
  4637. {
  4638. /* hardware has been reset, we need to reload some things */
  4639. ixgbe_configure(adapter);
  4640. ixgbe_up_complete(adapter);
  4641. }
  4642. void ixgbe_reset(struct ixgbe_adapter *adapter)
  4643. {
  4644. struct ixgbe_hw *hw = &adapter->hw;
  4645. struct net_device *netdev = adapter->netdev;
  4646. int err;
  4647. if (ixgbe_removed(hw->hw_addr))
  4648. return;
  4649. /* lock SFP init bit to prevent race conditions with the watchdog */
  4650. while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  4651. usleep_range(1000, 2000);
  4652. /* clear all SFP and link config related flags while holding SFP_INIT */
  4653. adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
  4654. IXGBE_FLAG2_SFP_NEEDS_RESET);
  4655. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
  4656. err = hw->mac.ops.init_hw(hw);
  4657. switch (err) {
  4658. case 0:
  4659. case IXGBE_ERR_SFP_NOT_PRESENT:
  4660. case IXGBE_ERR_SFP_NOT_SUPPORTED:
  4661. break;
  4662. case IXGBE_ERR_MASTER_REQUESTS_PENDING:
  4663. e_dev_err("master disable timed out\n");
  4664. break;
  4665. case IXGBE_ERR_EEPROM_VERSION:
  4666. /* We are running on a pre-production device, log a warning */
  4667. e_dev_warn("This device is a pre-production adapter/LOM. "
  4668. "Please be aware there may be issues associated with "
  4669. "your hardware. If you are experiencing problems "
  4670. "please contact your Intel or hardware "
  4671. "representative who provided you with this "
  4672. "hardware.\n");
  4673. break;
  4674. default:
  4675. e_dev_err("Hardware Error: %d\n", err);
  4676. }
  4677. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  4678. /* flush entries out of MAC table */
  4679. ixgbe_flush_sw_mac_table(adapter);
  4680. __dev_uc_unsync(netdev, NULL);
  4681. /* do not flush user set addresses */
  4682. ixgbe_mac_set_default_filter(adapter);
  4683. /* update SAN MAC vmdq pool selection */
  4684. if (hw->mac.san_mac_rar_index)
  4685. hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
  4686. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  4687. ixgbe_ptp_reset(adapter);
  4688. if (hw->phy.ops.set_phy_power) {
  4689. if (!netif_running(adapter->netdev) && !adapter->wol)
  4690. hw->phy.ops.set_phy_power(hw, false);
  4691. else
  4692. hw->phy.ops.set_phy_power(hw, true);
  4693. }
  4694. }
  4695. /**
  4696. * ixgbe_clean_tx_ring - Free Tx Buffers
  4697. * @tx_ring: ring to be cleaned
  4698. **/
  4699. static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
  4700. {
  4701. u16 i = tx_ring->next_to_clean;
  4702. struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
  4703. while (i != tx_ring->next_to_use) {
  4704. union ixgbe_adv_tx_desc *eop_desc, *tx_desc;
  4705. /* Free all the Tx ring sk_buffs */
  4706. dev_kfree_skb_any(tx_buffer->skb);
  4707. /* unmap skb header data */
  4708. dma_unmap_single(tx_ring->dev,
  4709. dma_unmap_addr(tx_buffer, dma),
  4710. dma_unmap_len(tx_buffer, len),
  4711. DMA_TO_DEVICE);
  4712. /* check for eop_desc to determine the end of the packet */
  4713. eop_desc = tx_buffer->next_to_watch;
  4714. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  4715. /* unmap remaining buffers */
  4716. while (tx_desc != eop_desc) {
  4717. tx_buffer++;
  4718. tx_desc++;
  4719. i++;
  4720. if (unlikely(i == tx_ring->count)) {
  4721. i = 0;
  4722. tx_buffer = tx_ring->tx_buffer_info;
  4723. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  4724. }
  4725. /* unmap any remaining paged data */
  4726. if (dma_unmap_len(tx_buffer, len))
  4727. dma_unmap_page(tx_ring->dev,
  4728. dma_unmap_addr(tx_buffer, dma),
  4729. dma_unmap_len(tx_buffer, len),
  4730. DMA_TO_DEVICE);
  4731. }
  4732. /* move us one more past the eop_desc for start of next pkt */
  4733. tx_buffer++;
  4734. i++;
  4735. if (unlikely(i == tx_ring->count)) {
  4736. i = 0;
  4737. tx_buffer = tx_ring->tx_buffer_info;
  4738. }
  4739. }
  4740. /* reset BQL for queue */
  4741. netdev_tx_reset_queue(txring_txq(tx_ring));
  4742. /* reset next_to_use and next_to_clean */
  4743. tx_ring->next_to_use = 0;
  4744. tx_ring->next_to_clean = 0;
  4745. }
  4746. /**
  4747. * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
  4748. * @adapter: board private structure
  4749. **/
  4750. static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
  4751. {
  4752. int i;
  4753. for (i = 0; i < adapter->num_rx_queues; i++)
  4754. ixgbe_clean_rx_ring(adapter->rx_ring[i]);
  4755. }
  4756. /**
  4757. * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
  4758. * @adapter: board private structure
  4759. **/
  4760. static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
  4761. {
  4762. int i;
  4763. for (i = 0; i < adapter->num_tx_queues; i++)
  4764. ixgbe_clean_tx_ring(adapter->tx_ring[i]);
  4765. }
  4766. static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
  4767. {
  4768. struct hlist_node *node2;
  4769. struct ixgbe_fdir_filter *filter;
  4770. spin_lock(&adapter->fdir_perfect_lock);
  4771. hlist_for_each_entry_safe(filter, node2,
  4772. &adapter->fdir_filter_list, fdir_node) {
  4773. hlist_del(&filter->fdir_node);
  4774. kfree(filter);
  4775. }
  4776. adapter->fdir_filter_count = 0;
  4777. spin_unlock(&adapter->fdir_perfect_lock);
  4778. }
  4779. static int ixgbe_disable_macvlan(struct net_device *upper, void *data)
  4780. {
  4781. if (netif_is_macvlan(upper)) {
  4782. struct macvlan_dev *vlan = netdev_priv(upper);
  4783. if (vlan->fwd_priv) {
  4784. netif_tx_stop_all_queues(upper);
  4785. netif_carrier_off(upper);
  4786. netif_tx_disable(upper);
  4787. }
  4788. }
  4789. return 0;
  4790. }
  4791. void ixgbe_down(struct ixgbe_adapter *adapter)
  4792. {
  4793. struct net_device *netdev = adapter->netdev;
  4794. struct ixgbe_hw *hw = &adapter->hw;
  4795. int i;
  4796. /* signal that we are down to the interrupt handler */
  4797. if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
  4798. return; /* do nothing if already down */
  4799. /* disable receives */
  4800. hw->mac.ops.disable_rx(hw);
  4801. /* disable all enabled rx queues */
  4802. for (i = 0; i < adapter->num_rx_queues; i++)
  4803. /* this call also flushes the previous write */
  4804. ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
  4805. usleep_range(10000, 20000);
  4806. netif_tx_stop_all_queues(netdev);
  4807. /* call carrier off first to avoid false dev_watchdog timeouts */
  4808. netif_carrier_off(netdev);
  4809. netif_tx_disable(netdev);
  4810. /* disable any upper devices */
  4811. netdev_walk_all_upper_dev_rcu(adapter->netdev,
  4812. ixgbe_disable_macvlan, NULL);
  4813. ixgbe_irq_disable(adapter);
  4814. ixgbe_napi_disable_all(adapter);
  4815. clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  4816. adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  4817. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  4818. del_timer_sync(&adapter->service_timer);
  4819. if (adapter->num_vfs) {
  4820. /* Clear EITR Select mapping */
  4821. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
  4822. /* Mark all the VFs as inactive */
  4823. for (i = 0 ; i < adapter->num_vfs; i++)
  4824. adapter->vfinfo[i].clear_to_send = false;
  4825. /* ping all the active vfs to let them know we are going down */
  4826. ixgbe_ping_all_vfs(adapter);
  4827. /* Disable all VFTE/VFRE TX/RX */
  4828. ixgbe_disable_tx_rx(adapter);
  4829. }
  4830. /* disable transmits in the hardware now that interrupts are off */
  4831. for (i = 0; i < adapter->num_tx_queues; i++) {
  4832. u8 reg_idx = adapter->tx_ring[i]->reg_idx;
  4833. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
  4834. }
  4835. /* Disable the Tx DMA engine on 82599 and later MAC */
  4836. switch (hw->mac.type) {
  4837. case ixgbe_mac_82599EB:
  4838. case ixgbe_mac_X540:
  4839. case ixgbe_mac_X550:
  4840. case ixgbe_mac_X550EM_x:
  4841. case ixgbe_mac_x550em_a:
  4842. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
  4843. (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
  4844. ~IXGBE_DMATXCTL_TE));
  4845. break;
  4846. default:
  4847. break;
  4848. }
  4849. if (!pci_channel_offline(adapter->pdev))
  4850. ixgbe_reset(adapter);
  4851. /* power down the optics for 82599 SFP+ fiber */
  4852. if (hw->mac.ops.disable_tx_laser)
  4853. hw->mac.ops.disable_tx_laser(hw);
  4854. ixgbe_clean_all_tx_rings(adapter);
  4855. ixgbe_clean_all_rx_rings(adapter);
  4856. }
  4857. /**
  4858. * ixgbe_eee_capable - helper function to determine EEE support on X550
  4859. * @adapter: board private structure
  4860. */
  4861. static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter)
  4862. {
  4863. struct ixgbe_hw *hw = &adapter->hw;
  4864. switch (hw->device_id) {
  4865. case IXGBE_DEV_ID_X550EM_A_1G_T:
  4866. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  4867. if (!hw->phy.eee_speeds_supported)
  4868. break;
  4869. adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE;
  4870. if (!hw->phy.eee_speeds_advertised)
  4871. break;
  4872. adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
  4873. break;
  4874. default:
  4875. adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE;
  4876. adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
  4877. break;
  4878. }
  4879. }
  4880. /**
  4881. * ixgbe_tx_timeout - Respond to a Tx Hang
  4882. * @netdev: network interface device structure
  4883. **/
  4884. static void ixgbe_tx_timeout(struct net_device *netdev)
  4885. {
  4886. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4887. /* Do the reset outside of interrupt context */
  4888. ixgbe_tx_timeout_reset(adapter);
  4889. }
  4890. #ifdef CONFIG_IXGBE_DCB
  4891. static void ixgbe_init_dcb(struct ixgbe_adapter *adapter)
  4892. {
  4893. struct ixgbe_hw *hw = &adapter->hw;
  4894. struct tc_configuration *tc;
  4895. int j;
  4896. switch (hw->mac.type) {
  4897. case ixgbe_mac_82598EB:
  4898. case ixgbe_mac_82599EB:
  4899. adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
  4900. adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
  4901. break;
  4902. case ixgbe_mac_X540:
  4903. case ixgbe_mac_X550:
  4904. adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
  4905. adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
  4906. break;
  4907. case ixgbe_mac_X550EM_x:
  4908. case ixgbe_mac_x550em_a:
  4909. default:
  4910. adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS;
  4911. adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS;
  4912. break;
  4913. }
  4914. /* Configure DCB traffic classes */
  4915. for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
  4916. tc = &adapter->dcb_cfg.tc_config[j];
  4917. tc->path[DCB_TX_CONFIG].bwg_id = 0;
  4918. tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
  4919. tc->path[DCB_RX_CONFIG].bwg_id = 0;
  4920. tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
  4921. tc->dcb_pfc = pfc_disabled;
  4922. }
  4923. /* Initialize default user to priority mapping, UPx->TC0 */
  4924. tc = &adapter->dcb_cfg.tc_config[0];
  4925. tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
  4926. tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
  4927. adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
  4928. adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
  4929. adapter->dcb_cfg.pfc_mode_enable = false;
  4930. adapter->dcb_set_bitmap = 0x00;
  4931. if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
  4932. adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
  4933. memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
  4934. sizeof(adapter->temp_dcb_cfg));
  4935. }
  4936. #endif
  4937. /**
  4938. * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
  4939. * @adapter: board private structure to initialize
  4940. *
  4941. * ixgbe_sw_init initializes the Adapter private data structure.
  4942. * Fields are initialized based on PCI device information and
  4943. * OS network device settings (MTU size).
  4944. **/
  4945. static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
  4946. const struct ixgbe_info *ii)
  4947. {
  4948. struct ixgbe_hw *hw = &adapter->hw;
  4949. struct pci_dev *pdev = adapter->pdev;
  4950. unsigned int rss, fdir;
  4951. u32 fwsm;
  4952. int i;
  4953. /* PCI config space info */
  4954. hw->vendor_id = pdev->vendor;
  4955. hw->device_id = pdev->device;
  4956. hw->revision_id = pdev->revision;
  4957. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  4958. hw->subsystem_device_id = pdev->subsystem_device;
  4959. /* get_invariants needs the device IDs */
  4960. ii->get_invariants(hw);
  4961. /* Set common capability flags and settings */
  4962. rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
  4963. adapter->ring_feature[RING_F_RSS].limit = rss;
  4964. adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
  4965. adapter->max_q_vectors = MAX_Q_VECTORS_82599;
  4966. adapter->atr_sample_rate = 20;
  4967. fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
  4968. adapter->ring_feature[RING_F_FDIR].limit = fdir;
  4969. adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
  4970. #ifdef CONFIG_IXGBE_DCA
  4971. adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
  4972. #endif
  4973. #ifdef CONFIG_IXGBE_DCB
  4974. adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
  4975. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  4976. #endif
  4977. #ifdef IXGBE_FCOE
  4978. adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
  4979. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  4980. #ifdef CONFIG_IXGBE_DCB
  4981. /* Default traffic class to use for FCoE */
  4982. adapter->fcoe.up = IXGBE_FCOE_DEFTC;
  4983. #endif /* CONFIG_IXGBE_DCB */
  4984. #endif /* IXGBE_FCOE */
  4985. /* initialize static ixgbe jump table entries */
  4986. adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]),
  4987. GFP_KERNEL);
  4988. if (!adapter->jump_tables[0])
  4989. return -ENOMEM;
  4990. adapter->jump_tables[0]->mat = ixgbe_ipv4_fields;
  4991. for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++)
  4992. adapter->jump_tables[i] = NULL;
  4993. adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
  4994. hw->mac.num_rar_entries,
  4995. GFP_ATOMIC);
  4996. if (!adapter->mac_table)
  4997. return -ENOMEM;
  4998. /* Set MAC specific capability flags and exceptions */
  4999. switch (hw->mac.type) {
  5000. case ixgbe_mac_82598EB:
  5001. adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
  5002. if (hw->device_id == IXGBE_DEV_ID_82598AT)
  5003. adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
  5004. adapter->max_q_vectors = MAX_Q_VECTORS_82598;
  5005. adapter->ring_feature[RING_F_FDIR].limit = 0;
  5006. adapter->atr_sample_rate = 0;
  5007. adapter->fdir_pballoc = 0;
  5008. #ifdef IXGBE_FCOE
  5009. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  5010. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  5011. #ifdef CONFIG_IXGBE_DCB
  5012. adapter->fcoe.up = 0;
  5013. #endif /* IXGBE_DCB */
  5014. #endif /* IXGBE_FCOE */
  5015. break;
  5016. case ixgbe_mac_82599EB:
  5017. if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
  5018. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5019. break;
  5020. case ixgbe_mac_X540:
  5021. fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
  5022. if (fwsm & IXGBE_FWSM_TS_ENABLED)
  5023. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5024. break;
  5025. case ixgbe_mac_x550em_a:
  5026. adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE;
  5027. switch (hw->device_id) {
  5028. case IXGBE_DEV_ID_X550EM_A_1G_T:
  5029. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  5030. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5031. break;
  5032. default:
  5033. break;
  5034. }
  5035. /* fall through */
  5036. case ixgbe_mac_X550EM_x:
  5037. #ifdef CONFIG_IXGBE_DCB
  5038. adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE;
  5039. #endif
  5040. #ifdef IXGBE_FCOE
  5041. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  5042. #ifdef CONFIG_IXGBE_DCB
  5043. adapter->fcoe.up = 0;
  5044. #endif /* IXGBE_DCB */
  5045. #endif /* IXGBE_FCOE */
  5046. /* Fall Through */
  5047. case ixgbe_mac_X550:
  5048. if (hw->mac.type == ixgbe_mac_X550)
  5049. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5050. #ifdef CONFIG_IXGBE_DCA
  5051. adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
  5052. #endif
  5053. adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
  5054. break;
  5055. default:
  5056. break;
  5057. }
  5058. #ifdef IXGBE_FCOE
  5059. /* FCoE support exists, always init the FCoE lock */
  5060. spin_lock_init(&adapter->fcoe.lock);
  5061. #endif
  5062. /* n-tuple support exists, always init our spinlock */
  5063. spin_lock_init(&adapter->fdir_perfect_lock);
  5064. #ifdef CONFIG_IXGBE_DCB
  5065. ixgbe_init_dcb(adapter);
  5066. #endif
  5067. /* default flow control settings */
  5068. hw->fc.requested_mode = ixgbe_fc_full;
  5069. hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
  5070. ixgbe_pbthresh_setup(adapter);
  5071. hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
  5072. hw->fc.send_xon = true;
  5073. hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
  5074. #ifdef CONFIG_PCI_IOV
  5075. if (max_vfs > 0)
  5076. e_dev_warn("Enabling SR-IOV VFs using the max_vfs module parameter is deprecated - please use the pci sysfs interface instead.\n");
  5077. /* assign number of SR-IOV VFs */
  5078. if (hw->mac.type != ixgbe_mac_82598EB) {
  5079. if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
  5080. max_vfs = 0;
  5081. e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
  5082. }
  5083. }
  5084. #endif /* CONFIG_PCI_IOV */
  5085. /* enable itr by default in dynamic mode */
  5086. adapter->rx_itr_setting = 1;
  5087. adapter->tx_itr_setting = 1;
  5088. /* set default ring sizes */
  5089. adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
  5090. adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
  5091. /* set default work limits */
  5092. adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
  5093. /* initialize eeprom parameters */
  5094. if (ixgbe_init_eeprom_params_generic(hw)) {
  5095. e_dev_err("EEPROM initialization failed\n");
  5096. return -EIO;
  5097. }
  5098. /* PF holds first pool slot */
  5099. set_bit(0, &adapter->fwd_bitmask);
  5100. set_bit(__IXGBE_DOWN, &adapter->state);
  5101. return 0;
  5102. }
  5103. /**
  5104. * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
  5105. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  5106. *
  5107. * Return 0 on success, negative on failure
  5108. **/
  5109. int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
  5110. {
  5111. struct device *dev = tx_ring->dev;
  5112. int orig_node = dev_to_node(dev);
  5113. int ring_node = -1;
  5114. int size;
  5115. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  5116. if (tx_ring->q_vector)
  5117. ring_node = tx_ring->q_vector->numa_node;
  5118. tx_ring->tx_buffer_info = vmalloc_node(size, ring_node);
  5119. if (!tx_ring->tx_buffer_info)
  5120. tx_ring->tx_buffer_info = vmalloc(size);
  5121. if (!tx_ring->tx_buffer_info)
  5122. goto err;
  5123. u64_stats_init(&tx_ring->syncp);
  5124. /* round up to nearest 4K */
  5125. tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
  5126. tx_ring->size = ALIGN(tx_ring->size, 4096);
  5127. set_dev_node(dev, ring_node);
  5128. tx_ring->desc = dma_alloc_coherent(dev,
  5129. tx_ring->size,
  5130. &tx_ring->dma,
  5131. GFP_KERNEL);
  5132. set_dev_node(dev, orig_node);
  5133. if (!tx_ring->desc)
  5134. tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
  5135. &tx_ring->dma, GFP_KERNEL);
  5136. if (!tx_ring->desc)
  5137. goto err;
  5138. tx_ring->next_to_use = 0;
  5139. tx_ring->next_to_clean = 0;
  5140. return 0;
  5141. err:
  5142. vfree(tx_ring->tx_buffer_info);
  5143. tx_ring->tx_buffer_info = NULL;
  5144. dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
  5145. return -ENOMEM;
  5146. }
  5147. /**
  5148. * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
  5149. * @adapter: board private structure
  5150. *
  5151. * If this function returns with an error, then it's possible one or
  5152. * more of the rings is populated (while the rest are not). It is the
  5153. * callers duty to clean those orphaned rings.
  5154. *
  5155. * Return 0 on success, negative on failure
  5156. **/
  5157. static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
  5158. {
  5159. int i, err = 0;
  5160. for (i = 0; i < adapter->num_tx_queues; i++) {
  5161. err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
  5162. if (!err)
  5163. continue;
  5164. e_err(probe, "Allocation for Tx Queue %u failed\n", i);
  5165. goto err_setup_tx;
  5166. }
  5167. return 0;
  5168. err_setup_tx:
  5169. /* rewind the index freeing the rings as we go */
  5170. while (i--)
  5171. ixgbe_free_tx_resources(adapter->tx_ring[i]);
  5172. return err;
  5173. }
  5174. /**
  5175. * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
  5176. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  5177. *
  5178. * Returns 0 on success, negative on failure
  5179. **/
  5180. int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
  5181. {
  5182. struct device *dev = rx_ring->dev;
  5183. int orig_node = dev_to_node(dev);
  5184. int ring_node = -1;
  5185. int size;
  5186. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  5187. if (rx_ring->q_vector)
  5188. ring_node = rx_ring->q_vector->numa_node;
  5189. rx_ring->rx_buffer_info = vmalloc_node(size, ring_node);
  5190. if (!rx_ring->rx_buffer_info)
  5191. rx_ring->rx_buffer_info = vmalloc(size);
  5192. if (!rx_ring->rx_buffer_info)
  5193. goto err;
  5194. u64_stats_init(&rx_ring->syncp);
  5195. /* Round up to nearest 4K */
  5196. rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
  5197. rx_ring->size = ALIGN(rx_ring->size, 4096);
  5198. set_dev_node(dev, ring_node);
  5199. rx_ring->desc = dma_alloc_coherent(dev,
  5200. rx_ring->size,
  5201. &rx_ring->dma,
  5202. GFP_KERNEL);
  5203. set_dev_node(dev, orig_node);
  5204. if (!rx_ring->desc)
  5205. rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
  5206. &rx_ring->dma, GFP_KERNEL);
  5207. if (!rx_ring->desc)
  5208. goto err;
  5209. rx_ring->next_to_clean = 0;
  5210. rx_ring->next_to_use = 0;
  5211. return 0;
  5212. err:
  5213. vfree(rx_ring->rx_buffer_info);
  5214. rx_ring->rx_buffer_info = NULL;
  5215. dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
  5216. return -ENOMEM;
  5217. }
  5218. /**
  5219. * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
  5220. * @adapter: board private structure
  5221. *
  5222. * If this function returns with an error, then it's possible one or
  5223. * more of the rings is populated (while the rest are not). It is the
  5224. * callers duty to clean those orphaned rings.
  5225. *
  5226. * Return 0 on success, negative on failure
  5227. **/
  5228. static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
  5229. {
  5230. int i, err = 0;
  5231. for (i = 0; i < adapter->num_rx_queues; i++) {
  5232. err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
  5233. if (!err)
  5234. continue;
  5235. e_err(probe, "Allocation for Rx Queue %u failed\n", i);
  5236. goto err_setup_rx;
  5237. }
  5238. #ifdef IXGBE_FCOE
  5239. err = ixgbe_setup_fcoe_ddp_resources(adapter);
  5240. if (!err)
  5241. #endif
  5242. return 0;
  5243. err_setup_rx:
  5244. /* rewind the index freeing the rings as we go */
  5245. while (i--)
  5246. ixgbe_free_rx_resources(adapter->rx_ring[i]);
  5247. return err;
  5248. }
  5249. /**
  5250. * ixgbe_free_tx_resources - Free Tx Resources per Queue
  5251. * @tx_ring: Tx descriptor ring for a specific queue
  5252. *
  5253. * Free all transmit software resources
  5254. **/
  5255. void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
  5256. {
  5257. ixgbe_clean_tx_ring(tx_ring);
  5258. vfree(tx_ring->tx_buffer_info);
  5259. tx_ring->tx_buffer_info = NULL;
  5260. /* if not set, then don't free */
  5261. if (!tx_ring->desc)
  5262. return;
  5263. dma_free_coherent(tx_ring->dev, tx_ring->size,
  5264. tx_ring->desc, tx_ring->dma);
  5265. tx_ring->desc = NULL;
  5266. }
  5267. /**
  5268. * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
  5269. * @adapter: board private structure
  5270. *
  5271. * Free all transmit software resources
  5272. **/
  5273. static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
  5274. {
  5275. int i;
  5276. for (i = 0; i < adapter->num_tx_queues; i++)
  5277. if (adapter->tx_ring[i]->desc)
  5278. ixgbe_free_tx_resources(adapter->tx_ring[i]);
  5279. }
  5280. /**
  5281. * ixgbe_free_rx_resources - Free Rx Resources
  5282. * @rx_ring: ring to clean the resources from
  5283. *
  5284. * Free all receive software resources
  5285. **/
  5286. void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
  5287. {
  5288. ixgbe_clean_rx_ring(rx_ring);
  5289. vfree(rx_ring->rx_buffer_info);
  5290. rx_ring->rx_buffer_info = NULL;
  5291. /* if not set, then don't free */
  5292. if (!rx_ring->desc)
  5293. return;
  5294. dma_free_coherent(rx_ring->dev, rx_ring->size,
  5295. rx_ring->desc, rx_ring->dma);
  5296. rx_ring->desc = NULL;
  5297. }
  5298. /**
  5299. * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
  5300. * @adapter: board private structure
  5301. *
  5302. * Free all receive software resources
  5303. **/
  5304. static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
  5305. {
  5306. int i;
  5307. #ifdef IXGBE_FCOE
  5308. ixgbe_free_fcoe_ddp_resources(adapter);
  5309. #endif
  5310. for (i = 0; i < adapter->num_rx_queues; i++)
  5311. if (adapter->rx_ring[i]->desc)
  5312. ixgbe_free_rx_resources(adapter->rx_ring[i]);
  5313. }
  5314. /**
  5315. * ixgbe_change_mtu - Change the Maximum Transfer Unit
  5316. * @netdev: network interface device structure
  5317. * @new_mtu: new value for maximum frame size
  5318. *
  5319. * Returns 0 on success, negative on failure
  5320. **/
  5321. static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
  5322. {
  5323. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5324. /*
  5325. * For 82599EB we cannot allow legacy VFs to enable their receive
  5326. * paths when MTU greater than 1500 is configured. So display a
  5327. * warning that legacy VFs will be disabled.
  5328. */
  5329. if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
  5330. (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
  5331. (new_mtu > ETH_DATA_LEN))
  5332. e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
  5333. e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
  5334. /* must set new MTU before calling down or up */
  5335. netdev->mtu = new_mtu;
  5336. if (netif_running(netdev))
  5337. ixgbe_reinit_locked(adapter);
  5338. return 0;
  5339. }
  5340. /**
  5341. * ixgbe_open - Called when a network interface is made active
  5342. * @netdev: network interface device structure
  5343. *
  5344. * Returns 0 on success, negative value on failure
  5345. *
  5346. * The open entry point is called when a network interface is made
  5347. * active by the system (IFF_UP). At this point all resources needed
  5348. * for transmit and receive operations are allocated, the interrupt
  5349. * handler is registered with the OS, the watchdog timer is started,
  5350. * and the stack is notified that the interface is ready.
  5351. **/
  5352. int ixgbe_open(struct net_device *netdev)
  5353. {
  5354. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5355. struct ixgbe_hw *hw = &adapter->hw;
  5356. int err, queues;
  5357. /* disallow open during test */
  5358. if (test_bit(__IXGBE_TESTING, &adapter->state))
  5359. return -EBUSY;
  5360. netif_carrier_off(netdev);
  5361. /* allocate transmit descriptors */
  5362. err = ixgbe_setup_all_tx_resources(adapter);
  5363. if (err)
  5364. goto err_setup_tx;
  5365. /* allocate receive descriptors */
  5366. err = ixgbe_setup_all_rx_resources(adapter);
  5367. if (err)
  5368. goto err_setup_rx;
  5369. ixgbe_configure(adapter);
  5370. err = ixgbe_request_irq(adapter);
  5371. if (err)
  5372. goto err_req_irq;
  5373. /* Notify the stack of the actual queue counts. */
  5374. if (adapter->num_rx_pools > 1)
  5375. queues = adapter->num_rx_queues_per_pool;
  5376. else
  5377. queues = adapter->num_tx_queues;
  5378. err = netif_set_real_num_tx_queues(netdev, queues);
  5379. if (err)
  5380. goto err_set_queues;
  5381. if (adapter->num_rx_pools > 1 &&
  5382. adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
  5383. queues = IXGBE_MAX_L2A_QUEUES;
  5384. else
  5385. queues = adapter->num_rx_queues;
  5386. err = netif_set_real_num_rx_queues(netdev, queues);
  5387. if (err)
  5388. goto err_set_queues;
  5389. ixgbe_ptp_init(adapter);
  5390. ixgbe_up_complete(adapter);
  5391. ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK);
  5392. udp_tunnel_get_rx_info(netdev);
  5393. return 0;
  5394. err_set_queues:
  5395. ixgbe_free_irq(adapter);
  5396. err_req_irq:
  5397. ixgbe_free_all_rx_resources(adapter);
  5398. if (hw->phy.ops.set_phy_power && !adapter->wol)
  5399. hw->phy.ops.set_phy_power(&adapter->hw, false);
  5400. err_setup_rx:
  5401. ixgbe_free_all_tx_resources(adapter);
  5402. err_setup_tx:
  5403. ixgbe_reset(adapter);
  5404. return err;
  5405. }
  5406. static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
  5407. {
  5408. ixgbe_ptp_suspend(adapter);
  5409. if (adapter->hw.phy.ops.enter_lplu) {
  5410. adapter->hw.phy.reset_disable = true;
  5411. ixgbe_down(adapter);
  5412. adapter->hw.phy.ops.enter_lplu(&adapter->hw);
  5413. adapter->hw.phy.reset_disable = false;
  5414. } else {
  5415. ixgbe_down(adapter);
  5416. }
  5417. ixgbe_free_irq(adapter);
  5418. ixgbe_free_all_tx_resources(adapter);
  5419. ixgbe_free_all_rx_resources(adapter);
  5420. }
  5421. /**
  5422. * ixgbe_close - Disables a network interface
  5423. * @netdev: network interface device structure
  5424. *
  5425. * Returns 0, this is not allowed to fail
  5426. *
  5427. * The close entry point is called when an interface is de-activated
  5428. * by the OS. The hardware is still under the drivers control, but
  5429. * needs to be disabled. A global MAC reset is issued to stop the
  5430. * hardware, and all transmit and receive resources are freed.
  5431. **/
  5432. int ixgbe_close(struct net_device *netdev)
  5433. {
  5434. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5435. ixgbe_ptp_stop(adapter);
  5436. if (netif_device_present(netdev))
  5437. ixgbe_close_suspend(adapter);
  5438. ixgbe_fdir_filter_exit(adapter);
  5439. ixgbe_release_hw_control(adapter);
  5440. return 0;
  5441. }
  5442. #ifdef CONFIG_PM
  5443. static int ixgbe_resume(struct pci_dev *pdev)
  5444. {
  5445. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  5446. struct net_device *netdev = adapter->netdev;
  5447. u32 err;
  5448. adapter->hw.hw_addr = adapter->io_addr;
  5449. pci_set_power_state(pdev, PCI_D0);
  5450. pci_restore_state(pdev);
  5451. /*
  5452. * pci_restore_state clears dev->state_saved so call
  5453. * pci_save_state to restore it.
  5454. */
  5455. pci_save_state(pdev);
  5456. err = pci_enable_device_mem(pdev);
  5457. if (err) {
  5458. e_dev_err("Cannot enable PCI device from suspend\n");
  5459. return err;
  5460. }
  5461. smp_mb__before_atomic();
  5462. clear_bit(__IXGBE_DISABLED, &adapter->state);
  5463. pci_set_master(pdev);
  5464. pci_wake_from_d3(pdev, false);
  5465. ixgbe_reset(adapter);
  5466. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  5467. rtnl_lock();
  5468. err = ixgbe_init_interrupt_scheme(adapter);
  5469. if (!err && netif_running(netdev))
  5470. err = ixgbe_open(netdev);
  5471. if (!err)
  5472. netif_device_attach(netdev);
  5473. rtnl_unlock();
  5474. return err;
  5475. }
  5476. #endif /* CONFIG_PM */
  5477. static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
  5478. {
  5479. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  5480. struct net_device *netdev = adapter->netdev;
  5481. struct ixgbe_hw *hw = &adapter->hw;
  5482. u32 ctrl, fctrl;
  5483. u32 wufc = adapter->wol;
  5484. #ifdef CONFIG_PM
  5485. int retval = 0;
  5486. #endif
  5487. rtnl_lock();
  5488. netif_device_detach(netdev);
  5489. if (netif_running(netdev))
  5490. ixgbe_close_suspend(adapter);
  5491. ixgbe_clear_interrupt_scheme(adapter);
  5492. rtnl_unlock();
  5493. #ifdef CONFIG_PM
  5494. retval = pci_save_state(pdev);
  5495. if (retval)
  5496. return retval;
  5497. #endif
  5498. if (hw->mac.ops.stop_link_on_d3)
  5499. hw->mac.ops.stop_link_on_d3(hw);
  5500. if (wufc) {
  5501. ixgbe_set_rx_mode(netdev);
  5502. /* enable the optics for 82599 SFP+ fiber as we can WoL */
  5503. if (hw->mac.ops.enable_tx_laser)
  5504. hw->mac.ops.enable_tx_laser(hw);
  5505. /* turn on all-multi mode if wake on multicast is enabled */
  5506. if (wufc & IXGBE_WUFC_MC) {
  5507. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  5508. fctrl |= IXGBE_FCTRL_MPE;
  5509. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  5510. }
  5511. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  5512. ctrl |= IXGBE_CTRL_GIO_DIS;
  5513. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  5514. IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
  5515. } else {
  5516. IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
  5517. IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
  5518. }
  5519. switch (hw->mac.type) {
  5520. case ixgbe_mac_82598EB:
  5521. pci_wake_from_d3(pdev, false);
  5522. break;
  5523. case ixgbe_mac_82599EB:
  5524. case ixgbe_mac_X540:
  5525. case ixgbe_mac_X550:
  5526. case ixgbe_mac_X550EM_x:
  5527. case ixgbe_mac_x550em_a:
  5528. pci_wake_from_d3(pdev, !!wufc);
  5529. break;
  5530. default:
  5531. break;
  5532. }
  5533. *enable_wake = !!wufc;
  5534. if (hw->phy.ops.set_phy_power && !*enable_wake)
  5535. hw->phy.ops.set_phy_power(hw, false);
  5536. ixgbe_release_hw_control(adapter);
  5537. if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
  5538. pci_disable_device(pdev);
  5539. return 0;
  5540. }
  5541. #ifdef CONFIG_PM
  5542. static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
  5543. {
  5544. int retval;
  5545. bool wake;
  5546. retval = __ixgbe_shutdown(pdev, &wake);
  5547. if (retval)
  5548. return retval;
  5549. if (wake) {
  5550. pci_prepare_to_sleep(pdev);
  5551. } else {
  5552. pci_wake_from_d3(pdev, false);
  5553. pci_set_power_state(pdev, PCI_D3hot);
  5554. }
  5555. return 0;
  5556. }
  5557. #endif /* CONFIG_PM */
  5558. static void ixgbe_shutdown(struct pci_dev *pdev)
  5559. {
  5560. bool wake;
  5561. __ixgbe_shutdown(pdev, &wake);
  5562. if (system_state == SYSTEM_POWER_OFF) {
  5563. pci_wake_from_d3(pdev, wake);
  5564. pci_set_power_state(pdev, PCI_D3hot);
  5565. }
  5566. }
  5567. /**
  5568. * ixgbe_update_stats - Update the board statistics counters.
  5569. * @adapter: board private structure
  5570. **/
  5571. void ixgbe_update_stats(struct ixgbe_adapter *adapter)
  5572. {
  5573. struct net_device *netdev = adapter->netdev;
  5574. struct ixgbe_hw *hw = &adapter->hw;
  5575. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  5576. u64 total_mpc = 0;
  5577. u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
  5578. u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
  5579. u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
  5580. u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
  5581. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  5582. test_bit(__IXGBE_RESETTING, &adapter->state))
  5583. return;
  5584. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  5585. u64 rsc_count = 0;
  5586. u64 rsc_flush = 0;
  5587. for (i = 0; i < adapter->num_rx_queues; i++) {
  5588. rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
  5589. rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
  5590. }
  5591. adapter->rsc_total_count = rsc_count;
  5592. adapter->rsc_total_flush = rsc_flush;
  5593. }
  5594. for (i = 0; i < adapter->num_rx_queues; i++) {
  5595. struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
  5596. non_eop_descs += rx_ring->rx_stats.non_eop_descs;
  5597. alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
  5598. alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
  5599. hw_csum_rx_error += rx_ring->rx_stats.csum_err;
  5600. bytes += rx_ring->stats.bytes;
  5601. packets += rx_ring->stats.packets;
  5602. }
  5603. adapter->non_eop_descs = non_eop_descs;
  5604. adapter->alloc_rx_page_failed = alloc_rx_page_failed;
  5605. adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
  5606. adapter->hw_csum_rx_error = hw_csum_rx_error;
  5607. netdev->stats.rx_bytes = bytes;
  5608. netdev->stats.rx_packets = packets;
  5609. bytes = 0;
  5610. packets = 0;
  5611. /* gather some stats to the adapter struct that are per queue */
  5612. for (i = 0; i < adapter->num_tx_queues; i++) {
  5613. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  5614. restart_queue += tx_ring->tx_stats.restart_queue;
  5615. tx_busy += tx_ring->tx_stats.tx_busy;
  5616. bytes += tx_ring->stats.bytes;
  5617. packets += tx_ring->stats.packets;
  5618. }
  5619. adapter->restart_queue = restart_queue;
  5620. adapter->tx_busy = tx_busy;
  5621. netdev->stats.tx_bytes = bytes;
  5622. netdev->stats.tx_packets = packets;
  5623. hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  5624. /* 8 register reads */
  5625. for (i = 0; i < 8; i++) {
  5626. /* for packet buffers not used, the register should read 0 */
  5627. mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
  5628. missed_rx += mpc;
  5629. hwstats->mpc[i] += mpc;
  5630. total_mpc += hwstats->mpc[i];
  5631. hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
  5632. hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
  5633. switch (hw->mac.type) {
  5634. case ixgbe_mac_82598EB:
  5635. hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  5636. hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  5637. hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  5638. hwstats->pxonrxc[i] +=
  5639. IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
  5640. break;
  5641. case ixgbe_mac_82599EB:
  5642. case ixgbe_mac_X540:
  5643. case ixgbe_mac_X550:
  5644. case ixgbe_mac_X550EM_x:
  5645. case ixgbe_mac_x550em_a:
  5646. hwstats->pxonrxc[i] +=
  5647. IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
  5648. break;
  5649. default:
  5650. break;
  5651. }
  5652. }
  5653. /*16 register reads */
  5654. for (i = 0; i < 16; i++) {
  5655. hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  5656. hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  5657. if ((hw->mac.type == ixgbe_mac_82599EB) ||
  5658. (hw->mac.type == ixgbe_mac_X540) ||
  5659. (hw->mac.type == ixgbe_mac_X550) ||
  5660. (hw->mac.type == ixgbe_mac_X550EM_x) ||
  5661. (hw->mac.type == ixgbe_mac_x550em_a)) {
  5662. hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
  5663. IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
  5664. hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
  5665. IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
  5666. }
  5667. }
  5668. hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
  5669. /* work around hardware counting issue */
  5670. hwstats->gprc -= missed_rx;
  5671. ixgbe_update_xoff_received(adapter);
  5672. /* 82598 hardware only has a 32 bit counter in the high register */
  5673. switch (hw->mac.type) {
  5674. case ixgbe_mac_82598EB:
  5675. hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  5676. hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
  5677. hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
  5678. hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
  5679. break;
  5680. case ixgbe_mac_X540:
  5681. case ixgbe_mac_X550:
  5682. case ixgbe_mac_X550EM_x:
  5683. case ixgbe_mac_x550em_a:
  5684. /* OS2BMC stats are X540 and later */
  5685. hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
  5686. hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
  5687. hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
  5688. hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
  5689. case ixgbe_mac_82599EB:
  5690. for (i = 0; i < 16; i++)
  5691. adapter->hw_rx_no_dma_resources +=
  5692. IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  5693. hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
  5694. IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
  5695. hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
  5696. IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
  5697. hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
  5698. IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
  5699. hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
  5700. hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
  5701. hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
  5702. #ifdef IXGBE_FCOE
  5703. hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
  5704. hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
  5705. hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
  5706. hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
  5707. hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
  5708. hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
  5709. /* Add up per cpu counters for total ddp aloc fail */
  5710. if (adapter->fcoe.ddp_pool) {
  5711. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  5712. struct ixgbe_fcoe_ddp_pool *ddp_pool;
  5713. unsigned int cpu;
  5714. u64 noddp = 0, noddp_ext_buff = 0;
  5715. for_each_possible_cpu(cpu) {
  5716. ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
  5717. noddp += ddp_pool->noddp;
  5718. noddp_ext_buff += ddp_pool->noddp_ext_buff;
  5719. }
  5720. hwstats->fcoe_noddp = noddp;
  5721. hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
  5722. }
  5723. #endif /* IXGBE_FCOE */
  5724. break;
  5725. default:
  5726. break;
  5727. }
  5728. bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
  5729. hwstats->bprc += bprc;
  5730. hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
  5731. if (hw->mac.type == ixgbe_mac_82598EB)
  5732. hwstats->mprc -= bprc;
  5733. hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
  5734. hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
  5735. hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
  5736. hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
  5737. hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
  5738. hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
  5739. hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
  5740. hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
  5741. lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  5742. hwstats->lxontxc += lxon;
  5743. lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  5744. hwstats->lxofftxc += lxoff;
  5745. hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
  5746. hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
  5747. /*
  5748. * 82598 errata - tx of flow control packets is included in tx counters
  5749. */
  5750. xon_off_tot = lxon + lxoff;
  5751. hwstats->gptc -= xon_off_tot;
  5752. hwstats->mptc -= xon_off_tot;
  5753. hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
  5754. hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
  5755. hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
  5756. hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
  5757. hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
  5758. hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
  5759. hwstats->ptc64 -= xon_off_tot;
  5760. hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
  5761. hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
  5762. hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
  5763. hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
  5764. hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
  5765. hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
  5766. /* Fill out the OS statistics structure */
  5767. netdev->stats.multicast = hwstats->mprc;
  5768. /* Rx Errors */
  5769. netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
  5770. netdev->stats.rx_dropped = 0;
  5771. netdev->stats.rx_length_errors = hwstats->rlec;
  5772. netdev->stats.rx_crc_errors = hwstats->crcerrs;
  5773. netdev->stats.rx_missed_errors = total_mpc;
  5774. }
  5775. /**
  5776. * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
  5777. * @adapter: pointer to the device adapter structure
  5778. **/
  5779. static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
  5780. {
  5781. struct ixgbe_hw *hw = &adapter->hw;
  5782. int i;
  5783. if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
  5784. return;
  5785. adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  5786. /* if interface is down do nothing */
  5787. if (test_bit(__IXGBE_DOWN, &adapter->state))
  5788. return;
  5789. /* do nothing if we are not using signature filters */
  5790. if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
  5791. return;
  5792. adapter->fdir_overflow++;
  5793. if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
  5794. for (i = 0; i < adapter->num_tx_queues; i++)
  5795. set_bit(__IXGBE_TX_FDIR_INIT_DONE,
  5796. &(adapter->tx_ring[i]->state));
  5797. /* re-enable flow director interrupts */
  5798. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
  5799. } else {
  5800. e_err(probe, "failed to finish FDIR re-initialization, "
  5801. "ignored adding FDIR ATR filters\n");
  5802. }
  5803. }
  5804. /**
  5805. * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
  5806. * @adapter: pointer to the device adapter structure
  5807. *
  5808. * This function serves two purposes. First it strobes the interrupt lines
  5809. * in order to make certain interrupts are occurring. Secondly it sets the
  5810. * bits needed to check for TX hangs. As a result we should immediately
  5811. * determine if a hang has occurred.
  5812. */
  5813. static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
  5814. {
  5815. struct ixgbe_hw *hw = &adapter->hw;
  5816. u64 eics = 0;
  5817. int i;
  5818. /* If we're down, removing or resetting, just bail */
  5819. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  5820. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  5821. test_bit(__IXGBE_RESETTING, &adapter->state))
  5822. return;
  5823. /* Force detection of hung controller */
  5824. if (netif_carrier_ok(adapter->netdev)) {
  5825. for (i = 0; i < adapter->num_tx_queues; i++)
  5826. set_check_for_tx_hang(adapter->tx_ring[i]);
  5827. }
  5828. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  5829. /*
  5830. * for legacy and MSI interrupts don't set any bits
  5831. * that are enabled for EIAM, because this operation
  5832. * would set *both* EIMS and EICS for any bit in EIAM
  5833. */
  5834. IXGBE_WRITE_REG(hw, IXGBE_EICS,
  5835. (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
  5836. } else {
  5837. /* get one bit for every active tx/rx interrupt vector */
  5838. for (i = 0; i < adapter->num_q_vectors; i++) {
  5839. struct ixgbe_q_vector *qv = adapter->q_vector[i];
  5840. if (qv->rx.ring || qv->tx.ring)
  5841. eics |= BIT_ULL(i);
  5842. }
  5843. }
  5844. /* Cause software interrupt to ensure rings are cleaned */
  5845. ixgbe_irq_rearm_queues(adapter, eics);
  5846. }
  5847. /**
  5848. * ixgbe_watchdog_update_link - update the link status
  5849. * @adapter: pointer to the device adapter structure
  5850. * @link_speed: pointer to a u32 to store the link_speed
  5851. **/
  5852. static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
  5853. {
  5854. struct ixgbe_hw *hw = &adapter->hw;
  5855. u32 link_speed = adapter->link_speed;
  5856. bool link_up = adapter->link_up;
  5857. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  5858. if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
  5859. return;
  5860. if (hw->mac.ops.check_link) {
  5861. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  5862. } else {
  5863. /* always assume link is up, if no check link function */
  5864. link_speed = IXGBE_LINK_SPEED_10GB_FULL;
  5865. link_up = true;
  5866. }
  5867. if (adapter->ixgbe_ieee_pfc)
  5868. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  5869. if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
  5870. hw->mac.ops.fc_enable(hw);
  5871. ixgbe_set_rx_drop_en(adapter);
  5872. }
  5873. if (link_up ||
  5874. time_after(jiffies, (adapter->link_check_timeout +
  5875. IXGBE_TRY_LINK_TIMEOUT))) {
  5876. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  5877. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
  5878. IXGBE_WRITE_FLUSH(hw);
  5879. }
  5880. adapter->link_up = link_up;
  5881. adapter->link_speed = link_speed;
  5882. }
  5883. static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
  5884. {
  5885. #ifdef CONFIG_IXGBE_DCB
  5886. struct net_device *netdev = adapter->netdev;
  5887. struct dcb_app app = {
  5888. .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
  5889. .protocol = 0,
  5890. };
  5891. u8 up = 0;
  5892. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
  5893. up = dcb_ieee_getapp_mask(netdev, &app);
  5894. adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
  5895. #endif
  5896. }
  5897. static int ixgbe_enable_macvlan(struct net_device *upper, void *data)
  5898. {
  5899. if (netif_is_macvlan(upper)) {
  5900. struct macvlan_dev *vlan = netdev_priv(upper);
  5901. if (vlan->fwd_priv)
  5902. netif_tx_wake_all_queues(upper);
  5903. }
  5904. return 0;
  5905. }
  5906. /**
  5907. * ixgbe_watchdog_link_is_up - update netif_carrier status and
  5908. * print link up message
  5909. * @adapter: pointer to the device adapter structure
  5910. **/
  5911. static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
  5912. {
  5913. struct net_device *netdev = adapter->netdev;
  5914. struct ixgbe_hw *hw = &adapter->hw;
  5915. u32 link_speed = adapter->link_speed;
  5916. const char *speed_str;
  5917. bool flow_rx, flow_tx;
  5918. /* only continue if link was previously down */
  5919. if (netif_carrier_ok(netdev))
  5920. return;
  5921. adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
  5922. switch (hw->mac.type) {
  5923. case ixgbe_mac_82598EB: {
  5924. u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  5925. u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
  5926. flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
  5927. flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
  5928. }
  5929. break;
  5930. case ixgbe_mac_X540:
  5931. case ixgbe_mac_X550:
  5932. case ixgbe_mac_X550EM_x:
  5933. case ixgbe_mac_x550em_a:
  5934. case ixgbe_mac_82599EB: {
  5935. u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  5936. u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
  5937. flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
  5938. flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
  5939. }
  5940. break;
  5941. default:
  5942. flow_tx = false;
  5943. flow_rx = false;
  5944. break;
  5945. }
  5946. adapter->last_rx_ptp_check = jiffies;
  5947. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  5948. ixgbe_ptp_start_cyclecounter(adapter);
  5949. switch (link_speed) {
  5950. case IXGBE_LINK_SPEED_10GB_FULL:
  5951. speed_str = "10 Gbps";
  5952. break;
  5953. case IXGBE_LINK_SPEED_2_5GB_FULL:
  5954. speed_str = "2.5 Gbps";
  5955. break;
  5956. case IXGBE_LINK_SPEED_1GB_FULL:
  5957. speed_str = "1 Gbps";
  5958. break;
  5959. case IXGBE_LINK_SPEED_100_FULL:
  5960. speed_str = "100 Mbps";
  5961. break;
  5962. case IXGBE_LINK_SPEED_10_FULL:
  5963. speed_str = "10 Mbps";
  5964. break;
  5965. default:
  5966. speed_str = "unknown speed";
  5967. break;
  5968. }
  5969. e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
  5970. ((flow_rx && flow_tx) ? "RX/TX" :
  5971. (flow_rx ? "RX" :
  5972. (flow_tx ? "TX" : "None"))));
  5973. netif_carrier_on(netdev);
  5974. ixgbe_check_vf_rate_limit(adapter);
  5975. /* enable transmits */
  5976. netif_tx_wake_all_queues(adapter->netdev);
  5977. /* enable any upper devices */
  5978. rtnl_lock();
  5979. netdev_walk_all_upper_dev_rcu(adapter->netdev,
  5980. ixgbe_enable_macvlan, NULL);
  5981. rtnl_unlock();
  5982. /* update the default user priority for VFs */
  5983. ixgbe_update_default_up(adapter);
  5984. /* ping all the active vfs to let them know link has changed */
  5985. ixgbe_ping_all_vfs(adapter);
  5986. }
  5987. /**
  5988. * ixgbe_watchdog_link_is_down - update netif_carrier status and
  5989. * print link down message
  5990. * @adapter: pointer to the adapter structure
  5991. **/
  5992. static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
  5993. {
  5994. struct net_device *netdev = adapter->netdev;
  5995. struct ixgbe_hw *hw = &adapter->hw;
  5996. adapter->link_up = false;
  5997. adapter->link_speed = 0;
  5998. /* only continue if link was up previously */
  5999. if (!netif_carrier_ok(netdev))
  6000. return;
  6001. /* poll for SFP+ cable when link is down */
  6002. if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
  6003. adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
  6004. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  6005. ixgbe_ptp_start_cyclecounter(adapter);
  6006. e_info(drv, "NIC Link is Down\n");
  6007. netif_carrier_off(netdev);
  6008. /* ping all the active vfs to let them know link has changed */
  6009. ixgbe_ping_all_vfs(adapter);
  6010. }
  6011. static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
  6012. {
  6013. int i;
  6014. for (i = 0; i < adapter->num_tx_queues; i++) {
  6015. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  6016. if (tx_ring->next_to_use != tx_ring->next_to_clean)
  6017. return true;
  6018. }
  6019. return false;
  6020. }
  6021. static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
  6022. {
  6023. struct ixgbe_hw *hw = &adapter->hw;
  6024. struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
  6025. u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
  6026. int i, j;
  6027. if (!adapter->num_vfs)
  6028. return false;
  6029. /* resetting the PF is only needed for MAC before X550 */
  6030. if (hw->mac.type >= ixgbe_mac_X550)
  6031. return false;
  6032. for (i = 0; i < adapter->num_vfs; i++) {
  6033. for (j = 0; j < q_per_pool; j++) {
  6034. u32 h, t;
  6035. h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
  6036. t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
  6037. if (h != t)
  6038. return true;
  6039. }
  6040. }
  6041. return false;
  6042. }
  6043. /**
  6044. * ixgbe_watchdog_flush_tx - flush queues on link down
  6045. * @adapter: pointer to the device adapter structure
  6046. **/
  6047. static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
  6048. {
  6049. if (!netif_carrier_ok(adapter->netdev)) {
  6050. if (ixgbe_ring_tx_pending(adapter) ||
  6051. ixgbe_vf_tx_pending(adapter)) {
  6052. /* We've lost link, so the controller stops DMA,
  6053. * but we've got queued Tx work that's never going
  6054. * to get done, so reset controller to flush Tx.
  6055. * (Do the reset outside of interrupt context).
  6056. */
  6057. e_warn(drv, "initiating reset to clear Tx work after link loss\n");
  6058. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  6059. }
  6060. }
  6061. }
  6062. #ifdef CONFIG_PCI_IOV
  6063. static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter,
  6064. struct pci_dev *vfdev)
  6065. {
  6066. if (!pci_wait_for_pending_transaction(vfdev))
  6067. e_dev_warn("Issuing VFLR with pending transactions\n");
  6068. e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev));
  6069. pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
  6070. msleep(100);
  6071. }
  6072. static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
  6073. {
  6074. struct ixgbe_hw *hw = &adapter->hw;
  6075. struct pci_dev *pdev = adapter->pdev;
  6076. unsigned int vf;
  6077. u32 gpc;
  6078. if (!(netif_carrier_ok(adapter->netdev)))
  6079. return;
  6080. gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
  6081. if (gpc) /* If incrementing then no need for the check below */
  6082. return;
  6083. /* Check to see if a bad DMA write target from an errant or
  6084. * malicious VF has caused a PCIe error. If so then we can
  6085. * issue a VFLR to the offending VF(s) and then resume without
  6086. * requesting a full slot reset.
  6087. */
  6088. if (!pdev)
  6089. return;
  6090. /* check status reg for all VFs owned by this PF */
  6091. for (vf = 0; vf < adapter->num_vfs; ++vf) {
  6092. struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
  6093. u16 status_reg;
  6094. if (!vfdev)
  6095. continue;
  6096. pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
  6097. if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
  6098. status_reg & PCI_STATUS_REC_MASTER_ABORT)
  6099. ixgbe_issue_vf_flr(adapter, vfdev);
  6100. }
  6101. }
  6102. static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
  6103. {
  6104. u32 ssvpc;
  6105. /* Do not perform spoof check for 82598 or if not in IOV mode */
  6106. if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
  6107. adapter->num_vfs == 0)
  6108. return;
  6109. ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
  6110. /*
  6111. * ssvpc register is cleared on read, if zero then no
  6112. * spoofed packets in the last interval.
  6113. */
  6114. if (!ssvpc)
  6115. return;
  6116. e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
  6117. }
  6118. #else
  6119. static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
  6120. {
  6121. }
  6122. static void
  6123. ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
  6124. {
  6125. }
  6126. #endif /* CONFIG_PCI_IOV */
  6127. /**
  6128. * ixgbe_watchdog_subtask - check and bring link up
  6129. * @adapter: pointer to the device adapter structure
  6130. **/
  6131. static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
  6132. {
  6133. /* if interface is down, removing or resetting, do nothing */
  6134. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  6135. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  6136. test_bit(__IXGBE_RESETTING, &adapter->state))
  6137. return;
  6138. ixgbe_watchdog_update_link(adapter);
  6139. if (adapter->link_up)
  6140. ixgbe_watchdog_link_is_up(adapter);
  6141. else
  6142. ixgbe_watchdog_link_is_down(adapter);
  6143. ixgbe_check_for_bad_vf(adapter);
  6144. ixgbe_spoof_check(adapter);
  6145. ixgbe_update_stats(adapter);
  6146. ixgbe_watchdog_flush_tx(adapter);
  6147. }
  6148. /**
  6149. * ixgbe_sfp_detection_subtask - poll for SFP+ cable
  6150. * @adapter: the ixgbe adapter structure
  6151. **/
  6152. static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
  6153. {
  6154. struct ixgbe_hw *hw = &adapter->hw;
  6155. s32 err;
  6156. /* not searching for SFP so there is nothing to do here */
  6157. if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
  6158. !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
  6159. return;
  6160. if (adapter->sfp_poll_time &&
  6161. time_after(adapter->sfp_poll_time, jiffies))
  6162. return; /* If not yet time to poll for SFP */
  6163. /* someone else is in init, wait until next service event */
  6164. if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  6165. return;
  6166. adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
  6167. err = hw->phy.ops.identify_sfp(hw);
  6168. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
  6169. goto sfp_out;
  6170. if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
  6171. /* If no cable is present, then we need to reset
  6172. * the next time we find a good cable. */
  6173. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  6174. }
  6175. /* exit on error */
  6176. if (err)
  6177. goto sfp_out;
  6178. /* exit if reset not needed */
  6179. if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
  6180. goto sfp_out;
  6181. adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
  6182. /*
  6183. * A module may be identified correctly, but the EEPROM may not have
  6184. * support for that module. setup_sfp() will fail in that case, so
  6185. * we should not allow that module to load.
  6186. */
  6187. if (hw->mac.type == ixgbe_mac_82598EB)
  6188. err = hw->phy.ops.reset(hw);
  6189. else
  6190. err = hw->mac.ops.setup_sfp(hw);
  6191. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
  6192. goto sfp_out;
  6193. adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
  6194. e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
  6195. sfp_out:
  6196. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  6197. if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
  6198. (adapter->netdev->reg_state == NETREG_REGISTERED)) {
  6199. e_dev_err("failed to initialize because an unsupported "
  6200. "SFP+ module type was detected.\n");
  6201. e_dev_err("Reload the driver after installing a "
  6202. "supported module.\n");
  6203. unregister_netdev(adapter->netdev);
  6204. }
  6205. }
  6206. /**
  6207. * ixgbe_sfp_link_config_subtask - set up link SFP after module install
  6208. * @adapter: the ixgbe adapter structure
  6209. **/
  6210. static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
  6211. {
  6212. struct ixgbe_hw *hw = &adapter->hw;
  6213. u32 speed;
  6214. bool autoneg = false;
  6215. if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
  6216. return;
  6217. /* someone else is in init, wait until next service event */
  6218. if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  6219. return;
  6220. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
  6221. speed = hw->phy.autoneg_advertised;
  6222. if ((!speed) && (hw->mac.ops.get_link_capabilities)) {
  6223. hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
  6224. /* setup the highest link when no autoneg */
  6225. if (!autoneg) {
  6226. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  6227. speed = IXGBE_LINK_SPEED_10GB_FULL;
  6228. }
  6229. }
  6230. if (hw->mac.ops.setup_link)
  6231. hw->mac.ops.setup_link(hw, speed, true);
  6232. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  6233. adapter->link_check_timeout = jiffies;
  6234. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  6235. }
  6236. /**
  6237. * ixgbe_service_timer - Timer Call-back
  6238. * @data: pointer to adapter cast into an unsigned long
  6239. **/
  6240. static void ixgbe_service_timer(unsigned long data)
  6241. {
  6242. struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
  6243. unsigned long next_event_offset;
  6244. /* poll faster when waiting for link */
  6245. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
  6246. next_event_offset = HZ / 10;
  6247. else
  6248. next_event_offset = HZ * 2;
  6249. /* Reset the timer */
  6250. mod_timer(&adapter->service_timer, next_event_offset + jiffies);
  6251. ixgbe_service_event_schedule(adapter);
  6252. }
  6253. static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
  6254. {
  6255. struct ixgbe_hw *hw = &adapter->hw;
  6256. u32 status;
  6257. if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
  6258. return;
  6259. adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
  6260. if (!hw->phy.ops.handle_lasi)
  6261. return;
  6262. status = hw->phy.ops.handle_lasi(&adapter->hw);
  6263. if (status != IXGBE_ERR_OVERTEMP)
  6264. return;
  6265. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  6266. }
  6267. static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
  6268. {
  6269. if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state))
  6270. return;
  6271. /* If we're already down, removing or resetting, just bail */
  6272. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  6273. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  6274. test_bit(__IXGBE_RESETTING, &adapter->state))
  6275. return;
  6276. ixgbe_dump(adapter);
  6277. netdev_err(adapter->netdev, "Reset adapter\n");
  6278. adapter->tx_timeout_count++;
  6279. rtnl_lock();
  6280. ixgbe_reinit_locked(adapter);
  6281. rtnl_unlock();
  6282. }
  6283. /**
  6284. * ixgbe_service_task - manages and runs subtasks
  6285. * @work: pointer to work_struct containing our data
  6286. **/
  6287. static void ixgbe_service_task(struct work_struct *work)
  6288. {
  6289. struct ixgbe_adapter *adapter = container_of(work,
  6290. struct ixgbe_adapter,
  6291. service_task);
  6292. if (ixgbe_removed(adapter->hw.hw_addr)) {
  6293. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  6294. rtnl_lock();
  6295. ixgbe_down(adapter);
  6296. rtnl_unlock();
  6297. }
  6298. ixgbe_service_event_complete(adapter);
  6299. return;
  6300. }
  6301. if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) {
  6302. rtnl_lock();
  6303. adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
  6304. udp_tunnel_get_rx_info(adapter->netdev);
  6305. rtnl_unlock();
  6306. }
  6307. ixgbe_reset_subtask(adapter);
  6308. ixgbe_phy_interrupt_subtask(adapter);
  6309. ixgbe_sfp_detection_subtask(adapter);
  6310. ixgbe_sfp_link_config_subtask(adapter);
  6311. ixgbe_check_overtemp_subtask(adapter);
  6312. ixgbe_watchdog_subtask(adapter);
  6313. ixgbe_fdir_reinit_subtask(adapter);
  6314. ixgbe_check_hang_subtask(adapter);
  6315. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
  6316. ixgbe_ptp_overflow_check(adapter);
  6317. ixgbe_ptp_rx_hang(adapter);
  6318. }
  6319. ixgbe_service_event_complete(adapter);
  6320. }
  6321. static int ixgbe_tso(struct ixgbe_ring *tx_ring,
  6322. struct ixgbe_tx_buffer *first,
  6323. u8 *hdr_len)
  6324. {
  6325. u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
  6326. struct sk_buff *skb = first->skb;
  6327. union {
  6328. struct iphdr *v4;
  6329. struct ipv6hdr *v6;
  6330. unsigned char *hdr;
  6331. } ip;
  6332. union {
  6333. struct tcphdr *tcp;
  6334. unsigned char *hdr;
  6335. } l4;
  6336. u32 paylen, l4_offset;
  6337. int err;
  6338. if (skb->ip_summed != CHECKSUM_PARTIAL)
  6339. return 0;
  6340. if (!skb_is_gso(skb))
  6341. return 0;
  6342. err = skb_cow_head(skb, 0);
  6343. if (err < 0)
  6344. return err;
  6345. ip.hdr = skb_network_header(skb);
  6346. l4.hdr = skb_checksum_start(skb);
  6347. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  6348. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
  6349. /* initialize outer IP header fields */
  6350. if (ip.v4->version == 4) {
  6351. unsigned char *csum_start = skb_checksum_start(skb);
  6352. unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
  6353. /* IP header will have to cancel out any data that
  6354. * is not a part of the outer IP header
  6355. */
  6356. ip.v4->check = csum_fold(csum_partial(trans_start,
  6357. csum_start - trans_start,
  6358. 0));
  6359. type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
  6360. ip.v4->tot_len = 0;
  6361. first->tx_flags |= IXGBE_TX_FLAGS_TSO |
  6362. IXGBE_TX_FLAGS_CSUM |
  6363. IXGBE_TX_FLAGS_IPV4;
  6364. } else {
  6365. ip.v6->payload_len = 0;
  6366. first->tx_flags |= IXGBE_TX_FLAGS_TSO |
  6367. IXGBE_TX_FLAGS_CSUM;
  6368. }
  6369. /* determine offset of inner transport header */
  6370. l4_offset = l4.hdr - skb->data;
  6371. /* compute length of segmentation header */
  6372. *hdr_len = (l4.tcp->doff * 4) + l4_offset;
  6373. /* remove payload length from inner checksum */
  6374. paylen = skb->len - l4_offset;
  6375. csum_replace_by_diff(&l4.tcp->check, htonl(paylen));
  6376. /* update gso size and bytecount with header size */
  6377. first->gso_segs = skb_shinfo(skb)->gso_segs;
  6378. first->bytecount += (first->gso_segs - 1) * *hdr_len;
  6379. /* mss_l4len_id: use 0 as index for TSO */
  6380. mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT;
  6381. mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
  6382. /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
  6383. vlan_macip_lens = l4.hdr - ip.hdr;
  6384. vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
  6385. vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  6386. ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
  6387. mss_l4len_idx);
  6388. return 1;
  6389. }
  6390. static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
  6391. {
  6392. unsigned int offset = 0;
  6393. ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
  6394. return offset == skb_checksum_start_offset(skb);
  6395. }
  6396. static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
  6397. struct ixgbe_tx_buffer *first)
  6398. {
  6399. struct sk_buff *skb = first->skb;
  6400. u32 vlan_macip_lens = 0;
  6401. u32 type_tucmd = 0;
  6402. if (skb->ip_summed != CHECKSUM_PARTIAL) {
  6403. csum_failed:
  6404. if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
  6405. IXGBE_TX_FLAGS_CC)))
  6406. return;
  6407. goto no_csum;
  6408. }
  6409. switch (skb->csum_offset) {
  6410. case offsetof(struct tcphdr, check):
  6411. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
  6412. /* fall through */
  6413. case offsetof(struct udphdr, check):
  6414. break;
  6415. case offsetof(struct sctphdr, checksum):
  6416. /* validate that this is actually an SCTP request */
  6417. if (((first->protocol == htons(ETH_P_IP)) &&
  6418. (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
  6419. ((first->protocol == htons(ETH_P_IPV6)) &&
  6420. ixgbe_ipv6_csum_is_sctp(skb))) {
  6421. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  6422. break;
  6423. }
  6424. /* fall through */
  6425. default:
  6426. skb_checksum_help(skb);
  6427. goto csum_failed;
  6428. }
  6429. /* update TX checksum flag */
  6430. first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
  6431. vlan_macip_lens = skb_checksum_start_offset(skb) -
  6432. skb_network_offset(skb);
  6433. no_csum:
  6434. /* vlan_macip_lens: MACLEN, VLAN tag */
  6435. vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
  6436. vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  6437. ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0);
  6438. }
  6439. #define IXGBE_SET_FLAG(_input, _flag, _result) \
  6440. ((_flag <= _result) ? \
  6441. ((u32)(_input & _flag) * (_result / _flag)) : \
  6442. ((u32)(_input & _flag) / (_flag / _result)))
  6443. static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
  6444. {
  6445. /* set type for advanced descriptor with frame checksum insertion */
  6446. u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
  6447. IXGBE_ADVTXD_DCMD_DEXT |
  6448. IXGBE_ADVTXD_DCMD_IFCS;
  6449. /* set HW vlan bit if vlan is present */
  6450. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
  6451. IXGBE_ADVTXD_DCMD_VLE);
  6452. /* set segmentation enable bits for TSO/FSO */
  6453. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
  6454. IXGBE_ADVTXD_DCMD_TSE);
  6455. /* set timestamp bit if present */
  6456. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
  6457. IXGBE_ADVTXD_MAC_TSTAMP);
  6458. /* insert frame checksum */
  6459. cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
  6460. return cmd_type;
  6461. }
  6462. static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
  6463. u32 tx_flags, unsigned int paylen)
  6464. {
  6465. u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
  6466. /* enable L4 checksum for TSO and TX checksum offload */
  6467. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6468. IXGBE_TX_FLAGS_CSUM,
  6469. IXGBE_ADVTXD_POPTS_TXSM);
  6470. /* enble IPv4 checksum for TSO */
  6471. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6472. IXGBE_TX_FLAGS_IPV4,
  6473. IXGBE_ADVTXD_POPTS_IXSM);
  6474. /*
  6475. * Check Context must be set if Tx switch is enabled, which it
  6476. * always is for case where virtual functions are running
  6477. */
  6478. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6479. IXGBE_TX_FLAGS_CC,
  6480. IXGBE_ADVTXD_CC);
  6481. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  6482. }
  6483. static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
  6484. {
  6485. netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
  6486. /* Herbert's original patch had:
  6487. * smp_mb__after_netif_stop_queue();
  6488. * but since that doesn't exist yet, just open code it.
  6489. */
  6490. smp_mb();
  6491. /* We need to check again in a case another CPU has just
  6492. * made room available.
  6493. */
  6494. if (likely(ixgbe_desc_unused(tx_ring) < size))
  6495. return -EBUSY;
  6496. /* A reprieve! - use start_queue because it doesn't call schedule */
  6497. netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
  6498. ++tx_ring->tx_stats.restart_queue;
  6499. return 0;
  6500. }
  6501. static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
  6502. {
  6503. if (likely(ixgbe_desc_unused(tx_ring) >= size))
  6504. return 0;
  6505. return __ixgbe_maybe_stop_tx(tx_ring, size);
  6506. }
  6507. #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
  6508. IXGBE_TXD_CMD_RS)
  6509. static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
  6510. struct ixgbe_tx_buffer *first,
  6511. const u8 hdr_len)
  6512. {
  6513. struct sk_buff *skb = first->skb;
  6514. struct ixgbe_tx_buffer *tx_buffer;
  6515. union ixgbe_adv_tx_desc *tx_desc;
  6516. struct skb_frag_struct *frag;
  6517. dma_addr_t dma;
  6518. unsigned int data_len, size;
  6519. u32 tx_flags = first->tx_flags;
  6520. u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
  6521. u16 i = tx_ring->next_to_use;
  6522. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  6523. ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
  6524. size = skb_headlen(skb);
  6525. data_len = skb->data_len;
  6526. #ifdef IXGBE_FCOE
  6527. if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
  6528. if (data_len < sizeof(struct fcoe_crc_eof)) {
  6529. size -= sizeof(struct fcoe_crc_eof) - data_len;
  6530. data_len = 0;
  6531. } else {
  6532. data_len -= sizeof(struct fcoe_crc_eof);
  6533. }
  6534. }
  6535. #endif
  6536. dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
  6537. tx_buffer = first;
  6538. for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
  6539. if (dma_mapping_error(tx_ring->dev, dma))
  6540. goto dma_error;
  6541. /* record length, and DMA address */
  6542. dma_unmap_len_set(tx_buffer, len, size);
  6543. dma_unmap_addr_set(tx_buffer, dma, dma);
  6544. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  6545. while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
  6546. tx_desc->read.cmd_type_len =
  6547. cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
  6548. i++;
  6549. tx_desc++;
  6550. if (i == tx_ring->count) {
  6551. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  6552. i = 0;
  6553. }
  6554. tx_desc->read.olinfo_status = 0;
  6555. dma += IXGBE_MAX_DATA_PER_TXD;
  6556. size -= IXGBE_MAX_DATA_PER_TXD;
  6557. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  6558. }
  6559. if (likely(!data_len))
  6560. break;
  6561. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
  6562. i++;
  6563. tx_desc++;
  6564. if (i == tx_ring->count) {
  6565. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  6566. i = 0;
  6567. }
  6568. tx_desc->read.olinfo_status = 0;
  6569. #ifdef IXGBE_FCOE
  6570. size = min_t(unsigned int, data_len, skb_frag_size(frag));
  6571. #else
  6572. size = skb_frag_size(frag);
  6573. #endif
  6574. data_len -= size;
  6575. dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
  6576. DMA_TO_DEVICE);
  6577. tx_buffer = &tx_ring->tx_buffer_info[i];
  6578. }
  6579. /* write last descriptor with RS and EOP bits */
  6580. cmd_type |= size | IXGBE_TXD_CMD;
  6581. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
  6582. netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
  6583. /* set the timestamp */
  6584. first->time_stamp = jiffies;
  6585. /*
  6586. * Force memory writes to complete before letting h/w know there
  6587. * are new descriptors to fetch. (Only applicable for weak-ordered
  6588. * memory model archs, such as IA-64).
  6589. *
  6590. * We also need this memory barrier to make certain all of the
  6591. * status bits have been updated before next_to_watch is written.
  6592. */
  6593. wmb();
  6594. /* set next_to_watch value indicating a packet is present */
  6595. first->next_to_watch = tx_desc;
  6596. i++;
  6597. if (i == tx_ring->count)
  6598. i = 0;
  6599. tx_ring->next_to_use = i;
  6600. ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
  6601. if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
  6602. writel(i, tx_ring->tail);
  6603. /* we need this if more than one processor can write to our tail
  6604. * at a time, it synchronizes IO on IA64/Altix systems
  6605. */
  6606. mmiowb();
  6607. }
  6608. return;
  6609. dma_error:
  6610. dev_err(tx_ring->dev, "TX DMA map failed\n");
  6611. tx_buffer = &tx_ring->tx_buffer_info[i];
  6612. /* clear dma mappings for failed tx_buffer_info map */
  6613. while (tx_buffer != first) {
  6614. if (dma_unmap_len(tx_buffer, len))
  6615. dma_unmap_page(tx_ring->dev,
  6616. dma_unmap_addr(tx_buffer, dma),
  6617. dma_unmap_len(tx_buffer, len),
  6618. DMA_TO_DEVICE);
  6619. dma_unmap_len_set(tx_buffer, len, 0);
  6620. if (i--)
  6621. i += tx_ring->count;
  6622. tx_buffer = &tx_ring->tx_buffer_info[i];
  6623. }
  6624. if (dma_unmap_len(tx_buffer, len))
  6625. dma_unmap_single(tx_ring->dev,
  6626. dma_unmap_addr(tx_buffer, dma),
  6627. dma_unmap_len(tx_buffer, len),
  6628. DMA_TO_DEVICE);
  6629. dma_unmap_len_set(tx_buffer, len, 0);
  6630. dev_kfree_skb_any(first->skb);
  6631. first->skb = NULL;
  6632. tx_ring->next_to_use = i;
  6633. }
  6634. static void ixgbe_atr(struct ixgbe_ring *ring,
  6635. struct ixgbe_tx_buffer *first)
  6636. {
  6637. struct ixgbe_q_vector *q_vector = ring->q_vector;
  6638. union ixgbe_atr_hash_dword input = { .dword = 0 };
  6639. union ixgbe_atr_hash_dword common = { .dword = 0 };
  6640. union {
  6641. unsigned char *network;
  6642. struct iphdr *ipv4;
  6643. struct ipv6hdr *ipv6;
  6644. } hdr;
  6645. struct tcphdr *th;
  6646. unsigned int hlen;
  6647. struct sk_buff *skb;
  6648. __be16 vlan_id;
  6649. int l4_proto;
  6650. /* if ring doesn't have a interrupt vector, cannot perform ATR */
  6651. if (!q_vector)
  6652. return;
  6653. /* do nothing if sampling is disabled */
  6654. if (!ring->atr_sample_rate)
  6655. return;
  6656. ring->atr_count++;
  6657. /* currently only IPv4/IPv6 with TCP is supported */
  6658. if ((first->protocol != htons(ETH_P_IP)) &&
  6659. (first->protocol != htons(ETH_P_IPV6)))
  6660. return;
  6661. /* snag network header to get L4 type and address */
  6662. skb = first->skb;
  6663. hdr.network = skb_network_header(skb);
  6664. if (unlikely(hdr.network <= skb->data))
  6665. return;
  6666. if (skb->encapsulation &&
  6667. first->protocol == htons(ETH_P_IP) &&
  6668. hdr.ipv4->protocol == IPPROTO_UDP) {
  6669. struct ixgbe_adapter *adapter = q_vector->adapter;
  6670. if (unlikely(skb_tail_pointer(skb) < hdr.network +
  6671. VXLAN_HEADROOM))
  6672. return;
  6673. /* verify the port is recognized as VXLAN */
  6674. if (adapter->vxlan_port &&
  6675. udp_hdr(skb)->dest == adapter->vxlan_port)
  6676. hdr.network = skb_inner_network_header(skb);
  6677. if (adapter->geneve_port &&
  6678. udp_hdr(skb)->dest == adapter->geneve_port)
  6679. hdr.network = skb_inner_network_header(skb);
  6680. }
  6681. /* Make sure we have at least [minimum IPv4 header + TCP]
  6682. * or [IPv6 header] bytes
  6683. */
  6684. if (unlikely(skb_tail_pointer(skb) < hdr.network + 40))
  6685. return;
  6686. /* Currently only IPv4/IPv6 with TCP is supported */
  6687. switch (hdr.ipv4->version) {
  6688. case IPVERSION:
  6689. /* access ihl as u8 to avoid unaligned access on ia64 */
  6690. hlen = (hdr.network[0] & 0x0F) << 2;
  6691. l4_proto = hdr.ipv4->protocol;
  6692. break;
  6693. case 6:
  6694. hlen = hdr.network - skb->data;
  6695. l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
  6696. hlen -= hdr.network - skb->data;
  6697. break;
  6698. default:
  6699. return;
  6700. }
  6701. if (l4_proto != IPPROTO_TCP)
  6702. return;
  6703. if (unlikely(skb_tail_pointer(skb) < hdr.network +
  6704. hlen + sizeof(struct tcphdr)))
  6705. return;
  6706. th = (struct tcphdr *)(hdr.network + hlen);
  6707. /* skip this packet since the socket is closing */
  6708. if (th->fin)
  6709. return;
  6710. /* sample on all syn packets or once every atr sample count */
  6711. if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
  6712. return;
  6713. /* reset sample count */
  6714. ring->atr_count = 0;
  6715. vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
  6716. /*
  6717. * src and dst are inverted, think how the receiver sees them
  6718. *
  6719. * The input is broken into two sections, a non-compressed section
  6720. * containing vm_pool, vlan_id, and flow_type. The rest of the data
  6721. * is XORed together and stored in the compressed dword.
  6722. */
  6723. input.formatted.vlan_id = vlan_id;
  6724. /*
  6725. * since src port and flex bytes occupy the same word XOR them together
  6726. * and write the value to source port portion of compressed dword
  6727. */
  6728. if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
  6729. common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
  6730. else
  6731. common.port.src ^= th->dest ^ first->protocol;
  6732. common.port.dst ^= th->source;
  6733. switch (hdr.ipv4->version) {
  6734. case IPVERSION:
  6735. input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
  6736. common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
  6737. break;
  6738. case 6:
  6739. input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
  6740. common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
  6741. hdr.ipv6->saddr.s6_addr32[1] ^
  6742. hdr.ipv6->saddr.s6_addr32[2] ^
  6743. hdr.ipv6->saddr.s6_addr32[3] ^
  6744. hdr.ipv6->daddr.s6_addr32[0] ^
  6745. hdr.ipv6->daddr.s6_addr32[1] ^
  6746. hdr.ipv6->daddr.s6_addr32[2] ^
  6747. hdr.ipv6->daddr.s6_addr32[3];
  6748. break;
  6749. default:
  6750. break;
  6751. }
  6752. if (hdr.network != skb_network_header(skb))
  6753. input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
  6754. /* This assumes the Rx queue and Tx queue are bound to the same CPU */
  6755. ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
  6756. input, common, ring->queue_index);
  6757. }
  6758. static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
  6759. void *accel_priv, select_queue_fallback_t fallback)
  6760. {
  6761. struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
  6762. #ifdef IXGBE_FCOE
  6763. struct ixgbe_adapter *adapter;
  6764. struct ixgbe_ring_feature *f;
  6765. int txq;
  6766. #endif
  6767. if (fwd_adapter)
  6768. return skb->queue_mapping + fwd_adapter->tx_base_queue;
  6769. #ifdef IXGBE_FCOE
  6770. /*
  6771. * only execute the code below if protocol is FCoE
  6772. * or FIP and we have FCoE enabled on the adapter
  6773. */
  6774. switch (vlan_get_protocol(skb)) {
  6775. case htons(ETH_P_FCOE):
  6776. case htons(ETH_P_FIP):
  6777. adapter = netdev_priv(dev);
  6778. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  6779. break;
  6780. default:
  6781. return fallback(dev, skb);
  6782. }
  6783. f = &adapter->ring_feature[RING_F_FCOE];
  6784. txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
  6785. smp_processor_id();
  6786. while (txq >= f->indices)
  6787. txq -= f->indices;
  6788. return txq + f->offset;
  6789. #else
  6790. return fallback(dev, skb);
  6791. #endif
  6792. }
  6793. netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
  6794. struct ixgbe_adapter *adapter,
  6795. struct ixgbe_ring *tx_ring)
  6796. {
  6797. struct ixgbe_tx_buffer *first;
  6798. int tso;
  6799. u32 tx_flags = 0;
  6800. unsigned short f;
  6801. u16 count = TXD_USE_COUNT(skb_headlen(skb));
  6802. __be16 protocol = skb->protocol;
  6803. u8 hdr_len = 0;
  6804. /*
  6805. * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
  6806. * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
  6807. * + 2 desc gap to keep tail from touching head,
  6808. * + 1 desc for context descriptor,
  6809. * otherwise try next time
  6810. */
  6811. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
  6812. count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
  6813. if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
  6814. tx_ring->tx_stats.tx_busy++;
  6815. return NETDEV_TX_BUSY;
  6816. }
  6817. /* record the location of the first descriptor for this packet */
  6818. first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
  6819. first->skb = skb;
  6820. first->bytecount = skb->len;
  6821. first->gso_segs = 1;
  6822. /* if we have a HW VLAN tag being added default to the HW one */
  6823. if (skb_vlan_tag_present(skb)) {
  6824. tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
  6825. tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
  6826. /* else if it is a SW VLAN check the next protocol and store the tag */
  6827. } else if (protocol == htons(ETH_P_8021Q)) {
  6828. struct vlan_hdr *vhdr, _vhdr;
  6829. vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
  6830. if (!vhdr)
  6831. goto out_drop;
  6832. tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
  6833. IXGBE_TX_FLAGS_VLAN_SHIFT;
  6834. tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
  6835. }
  6836. protocol = vlan_get_protocol(skb);
  6837. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
  6838. adapter->ptp_clock &&
  6839. !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
  6840. &adapter->state)) {
  6841. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  6842. tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
  6843. /* schedule check for Tx timestamp */
  6844. adapter->ptp_tx_skb = skb_get(skb);
  6845. adapter->ptp_tx_start = jiffies;
  6846. schedule_work(&adapter->ptp_tx_work);
  6847. }
  6848. skb_tx_timestamp(skb);
  6849. #ifdef CONFIG_PCI_IOV
  6850. /*
  6851. * Use the l2switch_enable flag - would be false if the DMA
  6852. * Tx switch had been disabled.
  6853. */
  6854. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  6855. tx_flags |= IXGBE_TX_FLAGS_CC;
  6856. #endif
  6857. /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
  6858. if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
  6859. ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
  6860. (skb->priority != TC_PRIO_CONTROL))) {
  6861. tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
  6862. tx_flags |= (skb->priority & 0x7) <<
  6863. IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
  6864. if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
  6865. struct vlan_ethhdr *vhdr;
  6866. if (skb_cow_head(skb, 0))
  6867. goto out_drop;
  6868. vhdr = (struct vlan_ethhdr *)skb->data;
  6869. vhdr->h_vlan_TCI = htons(tx_flags >>
  6870. IXGBE_TX_FLAGS_VLAN_SHIFT);
  6871. } else {
  6872. tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
  6873. }
  6874. }
  6875. /* record initial flags and protocol */
  6876. first->tx_flags = tx_flags;
  6877. first->protocol = protocol;
  6878. #ifdef IXGBE_FCOE
  6879. /* setup tx offload for FCoE */
  6880. if ((protocol == htons(ETH_P_FCOE)) &&
  6881. (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
  6882. tso = ixgbe_fso(tx_ring, first, &hdr_len);
  6883. if (tso < 0)
  6884. goto out_drop;
  6885. goto xmit_fcoe;
  6886. }
  6887. #endif /* IXGBE_FCOE */
  6888. tso = ixgbe_tso(tx_ring, first, &hdr_len);
  6889. if (tso < 0)
  6890. goto out_drop;
  6891. else if (!tso)
  6892. ixgbe_tx_csum(tx_ring, first);
  6893. /* add the ATR filter if ATR is on */
  6894. if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
  6895. ixgbe_atr(tx_ring, first);
  6896. #ifdef IXGBE_FCOE
  6897. xmit_fcoe:
  6898. #endif /* IXGBE_FCOE */
  6899. ixgbe_tx_map(tx_ring, first, hdr_len);
  6900. return NETDEV_TX_OK;
  6901. out_drop:
  6902. dev_kfree_skb_any(first->skb);
  6903. first->skb = NULL;
  6904. return NETDEV_TX_OK;
  6905. }
  6906. static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
  6907. struct net_device *netdev,
  6908. struct ixgbe_ring *ring)
  6909. {
  6910. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6911. struct ixgbe_ring *tx_ring;
  6912. /*
  6913. * The minimum packet size for olinfo paylen is 17 so pad the skb
  6914. * in order to meet this minimum size requirement.
  6915. */
  6916. if (skb_put_padto(skb, 17))
  6917. return NETDEV_TX_OK;
  6918. tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
  6919. return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
  6920. }
  6921. static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
  6922. struct net_device *netdev)
  6923. {
  6924. return __ixgbe_xmit_frame(skb, netdev, NULL);
  6925. }
  6926. /**
  6927. * ixgbe_set_mac - Change the Ethernet Address of the NIC
  6928. * @netdev: network interface device structure
  6929. * @p: pointer to an address structure
  6930. *
  6931. * Returns 0 on success, negative on failure
  6932. **/
  6933. static int ixgbe_set_mac(struct net_device *netdev, void *p)
  6934. {
  6935. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6936. struct ixgbe_hw *hw = &adapter->hw;
  6937. struct sockaddr *addr = p;
  6938. if (!is_valid_ether_addr(addr->sa_data))
  6939. return -EADDRNOTAVAIL;
  6940. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  6941. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  6942. ixgbe_mac_set_default_filter(adapter);
  6943. return 0;
  6944. }
  6945. static int
  6946. ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
  6947. {
  6948. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6949. struct ixgbe_hw *hw = &adapter->hw;
  6950. u16 value;
  6951. int rc;
  6952. if (prtad != hw->phy.mdio.prtad)
  6953. return -EINVAL;
  6954. rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
  6955. if (!rc)
  6956. rc = value;
  6957. return rc;
  6958. }
  6959. static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
  6960. u16 addr, u16 value)
  6961. {
  6962. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6963. struct ixgbe_hw *hw = &adapter->hw;
  6964. if (prtad != hw->phy.mdio.prtad)
  6965. return -EINVAL;
  6966. return hw->phy.ops.write_reg(hw, addr, devad, value);
  6967. }
  6968. static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
  6969. {
  6970. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6971. switch (cmd) {
  6972. case SIOCSHWTSTAMP:
  6973. return ixgbe_ptp_set_ts_config(adapter, req);
  6974. case SIOCGHWTSTAMP:
  6975. return ixgbe_ptp_get_ts_config(adapter, req);
  6976. default:
  6977. return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
  6978. }
  6979. }
  6980. /**
  6981. * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
  6982. * netdev->dev_addrs
  6983. * @netdev: network interface device structure
  6984. *
  6985. * Returns non-zero on failure
  6986. **/
  6987. static int ixgbe_add_sanmac_netdev(struct net_device *dev)
  6988. {
  6989. int err = 0;
  6990. struct ixgbe_adapter *adapter = netdev_priv(dev);
  6991. struct ixgbe_hw *hw = &adapter->hw;
  6992. if (is_valid_ether_addr(hw->mac.san_addr)) {
  6993. rtnl_lock();
  6994. err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
  6995. rtnl_unlock();
  6996. /* update SAN MAC vmdq pool selection */
  6997. hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
  6998. }
  6999. return err;
  7000. }
  7001. /**
  7002. * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
  7003. * netdev->dev_addrs
  7004. * @netdev: network interface device structure
  7005. *
  7006. * Returns non-zero on failure
  7007. **/
  7008. static int ixgbe_del_sanmac_netdev(struct net_device *dev)
  7009. {
  7010. int err = 0;
  7011. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7012. struct ixgbe_mac_info *mac = &adapter->hw.mac;
  7013. if (is_valid_ether_addr(mac->san_addr)) {
  7014. rtnl_lock();
  7015. err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
  7016. rtnl_unlock();
  7017. }
  7018. return err;
  7019. }
  7020. #ifdef CONFIG_NET_POLL_CONTROLLER
  7021. /*
  7022. * Polling 'interrupt' - used by things like netconsole to send skbs
  7023. * without having to re-enable interrupts. It's not called while
  7024. * the interrupt routine is executing.
  7025. */
  7026. static void ixgbe_netpoll(struct net_device *netdev)
  7027. {
  7028. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7029. int i;
  7030. /* if interface is down do nothing */
  7031. if (test_bit(__IXGBE_DOWN, &adapter->state))
  7032. return;
  7033. /* loop through and schedule all active queues */
  7034. for (i = 0; i < adapter->num_q_vectors; i++)
  7035. ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
  7036. }
  7037. #endif
  7038. static void ixgbe_get_stats64(struct net_device *netdev,
  7039. struct rtnl_link_stats64 *stats)
  7040. {
  7041. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7042. int i;
  7043. rcu_read_lock();
  7044. for (i = 0; i < adapter->num_rx_queues; i++) {
  7045. struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
  7046. u64 bytes, packets;
  7047. unsigned int start;
  7048. if (ring) {
  7049. do {
  7050. start = u64_stats_fetch_begin_irq(&ring->syncp);
  7051. packets = ring->stats.packets;
  7052. bytes = ring->stats.bytes;
  7053. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  7054. stats->rx_packets += packets;
  7055. stats->rx_bytes += bytes;
  7056. }
  7057. }
  7058. for (i = 0; i < adapter->num_tx_queues; i++) {
  7059. struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
  7060. u64 bytes, packets;
  7061. unsigned int start;
  7062. if (ring) {
  7063. do {
  7064. start = u64_stats_fetch_begin_irq(&ring->syncp);
  7065. packets = ring->stats.packets;
  7066. bytes = ring->stats.bytes;
  7067. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  7068. stats->tx_packets += packets;
  7069. stats->tx_bytes += bytes;
  7070. }
  7071. }
  7072. rcu_read_unlock();
  7073. /* following stats updated by ixgbe_watchdog_task() */
  7074. stats->multicast = netdev->stats.multicast;
  7075. stats->rx_errors = netdev->stats.rx_errors;
  7076. stats->rx_length_errors = netdev->stats.rx_length_errors;
  7077. stats->rx_crc_errors = netdev->stats.rx_crc_errors;
  7078. stats->rx_missed_errors = netdev->stats.rx_missed_errors;
  7079. }
  7080. #ifdef CONFIG_IXGBE_DCB
  7081. /**
  7082. * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
  7083. * @adapter: pointer to ixgbe_adapter
  7084. * @tc: number of traffic classes currently enabled
  7085. *
  7086. * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
  7087. * 802.1Q priority maps to a packet buffer that exists.
  7088. */
  7089. static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
  7090. {
  7091. struct ixgbe_hw *hw = &adapter->hw;
  7092. u32 reg, rsave;
  7093. int i;
  7094. /* 82598 have a static priority to TC mapping that can not
  7095. * be changed so no validation is needed.
  7096. */
  7097. if (hw->mac.type == ixgbe_mac_82598EB)
  7098. return;
  7099. reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
  7100. rsave = reg;
  7101. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  7102. u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
  7103. /* If up2tc is out of bounds default to zero */
  7104. if (up2tc > tc)
  7105. reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
  7106. }
  7107. if (reg != rsave)
  7108. IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
  7109. return;
  7110. }
  7111. /**
  7112. * ixgbe_set_prio_tc_map - Configure netdev prio tc map
  7113. * @adapter: Pointer to adapter struct
  7114. *
  7115. * Populate the netdev user priority to tc map
  7116. */
  7117. static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
  7118. {
  7119. struct net_device *dev = adapter->netdev;
  7120. struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
  7121. struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
  7122. u8 prio;
  7123. for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
  7124. u8 tc = 0;
  7125. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
  7126. tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
  7127. else if (ets)
  7128. tc = ets->prio_tc[prio];
  7129. netdev_set_prio_tc_map(dev, prio, tc);
  7130. }
  7131. }
  7132. #endif /* CONFIG_IXGBE_DCB */
  7133. /**
  7134. * ixgbe_setup_tc - configure net_device for multiple traffic classes
  7135. *
  7136. * @netdev: net device to configure
  7137. * @tc: number of traffic classes to enable
  7138. */
  7139. int ixgbe_setup_tc(struct net_device *dev, u8 tc)
  7140. {
  7141. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7142. struct ixgbe_hw *hw = &adapter->hw;
  7143. bool pools;
  7144. /* Hardware supports up to 8 traffic classes */
  7145. if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
  7146. return -EINVAL;
  7147. if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
  7148. return -EINVAL;
  7149. pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
  7150. if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
  7151. return -EBUSY;
  7152. /* Hardware has to reinitialize queues and interrupts to
  7153. * match packet buffer alignment. Unfortunately, the
  7154. * hardware is not flexible enough to do this dynamically.
  7155. */
  7156. if (netif_running(dev))
  7157. ixgbe_close(dev);
  7158. else
  7159. ixgbe_reset(adapter);
  7160. ixgbe_clear_interrupt_scheme(adapter);
  7161. #ifdef CONFIG_IXGBE_DCB
  7162. if (tc) {
  7163. netdev_set_num_tc(dev, tc);
  7164. ixgbe_set_prio_tc_map(adapter);
  7165. adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
  7166. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  7167. adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
  7168. adapter->hw.fc.requested_mode = ixgbe_fc_none;
  7169. }
  7170. } else {
  7171. netdev_reset_tc(dev);
  7172. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  7173. adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
  7174. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  7175. adapter->temp_dcb_cfg.pfc_mode_enable = false;
  7176. adapter->dcb_cfg.pfc_mode_enable = false;
  7177. }
  7178. ixgbe_validate_rtr(adapter, tc);
  7179. #endif /* CONFIG_IXGBE_DCB */
  7180. ixgbe_init_interrupt_scheme(adapter);
  7181. if (netif_running(dev))
  7182. return ixgbe_open(dev);
  7183. return 0;
  7184. }
  7185. static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
  7186. struct tc_cls_u32_offload *cls)
  7187. {
  7188. u32 hdl = cls->knode.handle;
  7189. u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
  7190. u32 loc = cls->knode.handle & 0xfffff;
  7191. int err = 0, i, j;
  7192. struct ixgbe_jump_table *jump = NULL;
  7193. if (loc > IXGBE_MAX_HW_ENTRIES)
  7194. return -EINVAL;
  7195. if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
  7196. return -EINVAL;
  7197. /* Clear this filter in the link data it is associated with */
  7198. if (uhtid != 0x800) {
  7199. jump = adapter->jump_tables[uhtid];
  7200. if (!jump)
  7201. return -EINVAL;
  7202. if (!test_bit(loc - 1, jump->child_loc_map))
  7203. return -EINVAL;
  7204. clear_bit(loc - 1, jump->child_loc_map);
  7205. }
  7206. /* Check if the filter being deleted is a link */
  7207. for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
  7208. jump = adapter->jump_tables[i];
  7209. if (jump && jump->link_hdl == hdl) {
  7210. /* Delete filters in the hardware in the child hash
  7211. * table associated with this link
  7212. */
  7213. for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) {
  7214. if (!test_bit(j, jump->child_loc_map))
  7215. continue;
  7216. spin_lock(&adapter->fdir_perfect_lock);
  7217. err = ixgbe_update_ethtool_fdir_entry(adapter,
  7218. NULL,
  7219. j + 1);
  7220. spin_unlock(&adapter->fdir_perfect_lock);
  7221. clear_bit(j, jump->child_loc_map);
  7222. }
  7223. /* Remove resources for this link */
  7224. kfree(jump->input);
  7225. kfree(jump->mask);
  7226. kfree(jump);
  7227. adapter->jump_tables[i] = NULL;
  7228. return err;
  7229. }
  7230. }
  7231. spin_lock(&adapter->fdir_perfect_lock);
  7232. err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
  7233. spin_unlock(&adapter->fdir_perfect_lock);
  7234. return err;
  7235. }
  7236. static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
  7237. __be16 protocol,
  7238. struct tc_cls_u32_offload *cls)
  7239. {
  7240. u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
  7241. if (uhtid >= IXGBE_MAX_LINK_HANDLE)
  7242. return -EINVAL;
  7243. /* This ixgbe devices do not support hash tables at the moment
  7244. * so abort when given hash tables.
  7245. */
  7246. if (cls->hnode.divisor > 0)
  7247. return -EINVAL;
  7248. set_bit(uhtid - 1, &adapter->tables);
  7249. return 0;
  7250. }
  7251. static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
  7252. struct tc_cls_u32_offload *cls)
  7253. {
  7254. u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
  7255. if (uhtid >= IXGBE_MAX_LINK_HANDLE)
  7256. return -EINVAL;
  7257. clear_bit(uhtid - 1, &adapter->tables);
  7258. return 0;
  7259. }
  7260. #ifdef CONFIG_NET_CLS_ACT
  7261. struct upper_walk_data {
  7262. struct ixgbe_adapter *adapter;
  7263. u64 action;
  7264. int ifindex;
  7265. u8 queue;
  7266. };
  7267. static int get_macvlan_queue(struct net_device *upper, void *_data)
  7268. {
  7269. if (netif_is_macvlan(upper)) {
  7270. struct macvlan_dev *dfwd = netdev_priv(upper);
  7271. struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
  7272. struct upper_walk_data *data = _data;
  7273. struct ixgbe_adapter *adapter = data->adapter;
  7274. int ifindex = data->ifindex;
  7275. if (vadapter && vadapter->netdev->ifindex == ifindex) {
  7276. data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
  7277. data->action = data->queue;
  7278. return 1;
  7279. }
  7280. }
  7281. return 0;
  7282. }
  7283. static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
  7284. u8 *queue, u64 *action)
  7285. {
  7286. unsigned int num_vfs = adapter->num_vfs, vf;
  7287. struct upper_walk_data data;
  7288. struct net_device *upper;
  7289. /* redirect to a SRIOV VF */
  7290. for (vf = 0; vf < num_vfs; ++vf) {
  7291. upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
  7292. if (upper->ifindex == ifindex) {
  7293. if (adapter->num_rx_pools > 1)
  7294. *queue = vf * 2;
  7295. else
  7296. *queue = vf * adapter->num_rx_queues_per_pool;
  7297. *action = vf + 1;
  7298. *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
  7299. return 0;
  7300. }
  7301. }
  7302. /* redirect to a offloaded macvlan netdev */
  7303. data.adapter = adapter;
  7304. data.ifindex = ifindex;
  7305. data.action = 0;
  7306. data.queue = 0;
  7307. if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
  7308. get_macvlan_queue, &data)) {
  7309. *action = data.action;
  7310. *queue = data.queue;
  7311. return 0;
  7312. }
  7313. return -EINVAL;
  7314. }
  7315. static int parse_tc_actions(struct ixgbe_adapter *adapter,
  7316. struct tcf_exts *exts, u64 *action, u8 *queue)
  7317. {
  7318. const struct tc_action *a;
  7319. LIST_HEAD(actions);
  7320. int err;
  7321. if (tc_no_actions(exts))
  7322. return -EINVAL;
  7323. tcf_exts_to_list(exts, &actions);
  7324. list_for_each_entry(a, &actions, list) {
  7325. /* Drop action */
  7326. if (is_tcf_gact_shot(a)) {
  7327. *action = IXGBE_FDIR_DROP_QUEUE;
  7328. *queue = IXGBE_FDIR_DROP_QUEUE;
  7329. return 0;
  7330. }
  7331. /* Redirect to a VF or a offloaded macvlan */
  7332. if (is_tcf_mirred_egress_redirect(a)) {
  7333. int ifindex = tcf_mirred_ifindex(a);
  7334. err = handle_redirect_action(adapter, ifindex, queue,
  7335. action);
  7336. if (err == 0)
  7337. return err;
  7338. }
  7339. }
  7340. return -EINVAL;
  7341. }
  7342. #else
  7343. static int parse_tc_actions(struct ixgbe_adapter *adapter,
  7344. struct tcf_exts *exts, u64 *action, u8 *queue)
  7345. {
  7346. return -EINVAL;
  7347. }
  7348. #endif /* CONFIG_NET_CLS_ACT */
  7349. static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input,
  7350. union ixgbe_atr_input *mask,
  7351. struct tc_cls_u32_offload *cls,
  7352. struct ixgbe_mat_field *field_ptr,
  7353. struct ixgbe_nexthdr *nexthdr)
  7354. {
  7355. int i, j, off;
  7356. __be32 val, m;
  7357. bool found_entry = false, found_jump_field = false;
  7358. for (i = 0; i < cls->knode.sel->nkeys; i++) {
  7359. off = cls->knode.sel->keys[i].off;
  7360. val = cls->knode.sel->keys[i].val;
  7361. m = cls->knode.sel->keys[i].mask;
  7362. for (j = 0; field_ptr[j].val; j++) {
  7363. if (field_ptr[j].off == off) {
  7364. field_ptr[j].val(input, mask, val, m);
  7365. input->filter.formatted.flow_type |=
  7366. field_ptr[j].type;
  7367. found_entry = true;
  7368. break;
  7369. }
  7370. }
  7371. if (nexthdr) {
  7372. if (nexthdr->off == cls->knode.sel->keys[i].off &&
  7373. nexthdr->val == cls->knode.sel->keys[i].val &&
  7374. nexthdr->mask == cls->knode.sel->keys[i].mask)
  7375. found_jump_field = true;
  7376. else
  7377. continue;
  7378. }
  7379. }
  7380. if (nexthdr && !found_jump_field)
  7381. return -EINVAL;
  7382. if (!found_entry)
  7383. return 0;
  7384. mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
  7385. IXGBE_ATR_L4TYPE_MASK;
  7386. if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
  7387. mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
  7388. return 0;
  7389. }
  7390. static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
  7391. __be16 protocol,
  7392. struct tc_cls_u32_offload *cls)
  7393. {
  7394. u32 loc = cls->knode.handle & 0xfffff;
  7395. struct ixgbe_hw *hw = &adapter->hw;
  7396. struct ixgbe_mat_field *field_ptr;
  7397. struct ixgbe_fdir_filter *input = NULL;
  7398. union ixgbe_atr_input *mask = NULL;
  7399. struct ixgbe_jump_table *jump = NULL;
  7400. int i, err = -EINVAL;
  7401. u8 queue;
  7402. u32 uhtid, link_uhtid;
  7403. uhtid = TC_U32_USERHTID(cls->knode.handle);
  7404. link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
  7405. /* At the moment cls_u32 jumps to network layer and skips past
  7406. * L2 headers. The canonical method to match L2 frames is to use
  7407. * negative values. However this is error prone at best but really
  7408. * just broken because there is no way to "know" what sort of hdr
  7409. * is in front of the network layer. Fix cls_u32 to support L2
  7410. * headers when needed.
  7411. */
  7412. if (protocol != htons(ETH_P_IP))
  7413. return err;
  7414. if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
  7415. e_err(drv, "Location out of range\n");
  7416. return err;
  7417. }
  7418. /* cls u32 is a graph starting at root node 0x800. The driver tracks
  7419. * links and also the fields used to advance the parser across each
  7420. * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
  7421. * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
  7422. * To add support for new nodes update ixgbe_model.h parse structures
  7423. * this function _should_ be generic try not to hardcode values here.
  7424. */
  7425. if (uhtid == 0x800) {
  7426. field_ptr = (adapter->jump_tables[0])->mat;
  7427. } else {
  7428. if (uhtid >= IXGBE_MAX_LINK_HANDLE)
  7429. return err;
  7430. if (!adapter->jump_tables[uhtid])
  7431. return err;
  7432. field_ptr = (adapter->jump_tables[uhtid])->mat;
  7433. }
  7434. if (!field_ptr)
  7435. return err;
  7436. /* At this point we know the field_ptr is valid and need to either
  7437. * build cls_u32 link or attach filter. Because adding a link to
  7438. * a handle that does not exist is invalid and the same for adding
  7439. * rules to handles that don't exist.
  7440. */
  7441. if (link_uhtid) {
  7442. struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
  7443. if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
  7444. return err;
  7445. if (!test_bit(link_uhtid - 1, &adapter->tables))
  7446. return err;
  7447. /* Multiple filters as links to the same hash table are not
  7448. * supported. To add a new filter with the same next header
  7449. * but different match/jump conditions, create a new hash table
  7450. * and link to it.
  7451. */
  7452. if (adapter->jump_tables[link_uhtid] &&
  7453. (adapter->jump_tables[link_uhtid])->link_hdl) {
  7454. e_err(drv, "Link filter exists for link: %x\n",
  7455. link_uhtid);
  7456. return err;
  7457. }
  7458. for (i = 0; nexthdr[i].jump; i++) {
  7459. if (nexthdr[i].o != cls->knode.sel->offoff ||
  7460. nexthdr[i].s != cls->knode.sel->offshift ||
  7461. nexthdr[i].m != cls->knode.sel->offmask)
  7462. return err;
  7463. jump = kzalloc(sizeof(*jump), GFP_KERNEL);
  7464. if (!jump)
  7465. return -ENOMEM;
  7466. input = kzalloc(sizeof(*input), GFP_KERNEL);
  7467. if (!input) {
  7468. err = -ENOMEM;
  7469. goto free_jump;
  7470. }
  7471. mask = kzalloc(sizeof(*mask), GFP_KERNEL);
  7472. if (!mask) {
  7473. err = -ENOMEM;
  7474. goto free_input;
  7475. }
  7476. jump->input = input;
  7477. jump->mask = mask;
  7478. jump->link_hdl = cls->knode.handle;
  7479. err = ixgbe_clsu32_build_input(input, mask, cls,
  7480. field_ptr, &nexthdr[i]);
  7481. if (!err) {
  7482. jump->mat = nexthdr[i].jump;
  7483. adapter->jump_tables[link_uhtid] = jump;
  7484. break;
  7485. }
  7486. }
  7487. return 0;
  7488. }
  7489. input = kzalloc(sizeof(*input), GFP_KERNEL);
  7490. if (!input)
  7491. return -ENOMEM;
  7492. mask = kzalloc(sizeof(*mask), GFP_KERNEL);
  7493. if (!mask) {
  7494. err = -ENOMEM;
  7495. goto free_input;
  7496. }
  7497. if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) {
  7498. if ((adapter->jump_tables[uhtid])->input)
  7499. memcpy(input, (adapter->jump_tables[uhtid])->input,
  7500. sizeof(*input));
  7501. if ((adapter->jump_tables[uhtid])->mask)
  7502. memcpy(mask, (adapter->jump_tables[uhtid])->mask,
  7503. sizeof(*mask));
  7504. /* Lookup in all child hash tables if this location is already
  7505. * filled with a filter
  7506. */
  7507. for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
  7508. struct ixgbe_jump_table *link = adapter->jump_tables[i];
  7509. if (link && (test_bit(loc - 1, link->child_loc_map))) {
  7510. e_err(drv, "Filter exists in location: %x\n",
  7511. loc);
  7512. err = -EINVAL;
  7513. goto err_out;
  7514. }
  7515. }
  7516. }
  7517. err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL);
  7518. if (err)
  7519. goto err_out;
  7520. err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
  7521. &queue);
  7522. if (err < 0)
  7523. goto err_out;
  7524. input->sw_idx = loc;
  7525. spin_lock(&adapter->fdir_perfect_lock);
  7526. if (hlist_empty(&adapter->fdir_filter_list)) {
  7527. memcpy(&adapter->fdir_mask, mask, sizeof(*mask));
  7528. err = ixgbe_fdir_set_input_mask_82599(hw, mask);
  7529. if (err)
  7530. goto err_out_w_lock;
  7531. } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) {
  7532. err = -EINVAL;
  7533. goto err_out_w_lock;
  7534. }
  7535. ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask);
  7536. err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
  7537. input->sw_idx, queue);
  7538. if (!err)
  7539. ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
  7540. spin_unlock(&adapter->fdir_perfect_lock);
  7541. if ((uhtid != 0x800) && (adapter->jump_tables[uhtid]))
  7542. set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map);
  7543. kfree(mask);
  7544. return err;
  7545. err_out_w_lock:
  7546. spin_unlock(&adapter->fdir_perfect_lock);
  7547. err_out:
  7548. kfree(mask);
  7549. free_input:
  7550. kfree(input);
  7551. free_jump:
  7552. kfree(jump);
  7553. return err;
  7554. }
  7555. static int __ixgbe_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
  7556. struct tc_to_netdev *tc)
  7557. {
  7558. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7559. if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) &&
  7560. tc->type == TC_SETUP_CLSU32) {
  7561. switch (tc->cls_u32->command) {
  7562. case TC_CLSU32_NEW_KNODE:
  7563. case TC_CLSU32_REPLACE_KNODE:
  7564. return ixgbe_configure_clsu32(adapter,
  7565. proto, tc->cls_u32);
  7566. case TC_CLSU32_DELETE_KNODE:
  7567. return ixgbe_delete_clsu32(adapter, tc->cls_u32);
  7568. case TC_CLSU32_NEW_HNODE:
  7569. case TC_CLSU32_REPLACE_HNODE:
  7570. return ixgbe_configure_clsu32_add_hnode(adapter, proto,
  7571. tc->cls_u32);
  7572. case TC_CLSU32_DELETE_HNODE:
  7573. return ixgbe_configure_clsu32_del_hnode(adapter,
  7574. tc->cls_u32);
  7575. default:
  7576. return -EINVAL;
  7577. }
  7578. }
  7579. if (tc->type != TC_SETUP_MQPRIO)
  7580. return -EINVAL;
  7581. tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
  7582. return ixgbe_setup_tc(dev, tc->mqprio->num_tc);
  7583. }
  7584. #ifdef CONFIG_PCI_IOV
  7585. void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
  7586. {
  7587. struct net_device *netdev = adapter->netdev;
  7588. rtnl_lock();
  7589. ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
  7590. rtnl_unlock();
  7591. }
  7592. #endif
  7593. void ixgbe_do_reset(struct net_device *netdev)
  7594. {
  7595. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7596. if (netif_running(netdev))
  7597. ixgbe_reinit_locked(adapter);
  7598. else
  7599. ixgbe_reset(adapter);
  7600. }
  7601. static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
  7602. netdev_features_t features)
  7603. {
  7604. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7605. /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
  7606. if (!(features & NETIF_F_RXCSUM))
  7607. features &= ~NETIF_F_LRO;
  7608. /* Turn off LRO if not RSC capable */
  7609. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
  7610. features &= ~NETIF_F_LRO;
  7611. return features;
  7612. }
  7613. static int ixgbe_set_features(struct net_device *netdev,
  7614. netdev_features_t features)
  7615. {
  7616. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7617. netdev_features_t changed = netdev->features ^ features;
  7618. bool need_reset = false;
  7619. /* Make sure RSC matches LRO, reset if change */
  7620. if (!(features & NETIF_F_LRO)) {
  7621. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  7622. need_reset = true;
  7623. adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
  7624. } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
  7625. !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
  7626. if (adapter->rx_itr_setting == 1 ||
  7627. adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
  7628. adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
  7629. need_reset = true;
  7630. } else if ((changed ^ features) & NETIF_F_LRO) {
  7631. e_info(probe, "rx-usecs set too low, "
  7632. "disabling RSC\n");
  7633. }
  7634. }
  7635. /*
  7636. * Check if Flow Director n-tuple support or hw_tc support was
  7637. * enabled or disabled. If the state changed, we need to reset.
  7638. */
  7639. if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
  7640. /* turn off ATR, enable perfect filters and reset */
  7641. if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
  7642. need_reset = true;
  7643. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  7644. adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  7645. } else {
  7646. /* turn off perfect filters, enable ATR and reset */
  7647. if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  7648. need_reset = true;
  7649. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  7650. /* We cannot enable ATR if SR-IOV is enabled */
  7651. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
  7652. /* We cannot enable ATR if we have 2 or more tcs */
  7653. (netdev_get_num_tc(netdev) > 1) ||
  7654. /* We cannot enable ATR if RSS is disabled */
  7655. (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
  7656. /* A sample rate of 0 indicates ATR disabled */
  7657. (!adapter->atr_sample_rate))
  7658. ; /* do nothing not supported */
  7659. else /* otherwise supported and set the flag */
  7660. adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
  7661. }
  7662. if (changed & NETIF_F_RXALL)
  7663. need_reset = true;
  7664. netdev->features = features;
  7665. if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
  7666. if (features & NETIF_F_RXCSUM) {
  7667. adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
  7668. } else {
  7669. u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
  7670. ixgbe_clear_udp_tunnel_port(adapter, port_mask);
  7671. }
  7672. }
  7673. if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) {
  7674. if (features & NETIF_F_RXCSUM) {
  7675. adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
  7676. } else {
  7677. u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
  7678. ixgbe_clear_udp_tunnel_port(adapter, port_mask);
  7679. }
  7680. }
  7681. if (need_reset)
  7682. ixgbe_do_reset(netdev);
  7683. else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
  7684. NETIF_F_HW_VLAN_CTAG_FILTER))
  7685. ixgbe_set_rx_mode(netdev);
  7686. return 0;
  7687. }
  7688. /**
  7689. * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports
  7690. * @dev: The port's netdev
  7691. * @ti: Tunnel endpoint information
  7692. **/
  7693. static void ixgbe_add_udp_tunnel_port(struct net_device *dev,
  7694. struct udp_tunnel_info *ti)
  7695. {
  7696. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7697. struct ixgbe_hw *hw = &adapter->hw;
  7698. __be16 port = ti->port;
  7699. u32 port_shift = 0;
  7700. u32 reg;
  7701. if (ti->sa_family != AF_INET)
  7702. return;
  7703. switch (ti->type) {
  7704. case UDP_TUNNEL_TYPE_VXLAN:
  7705. if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
  7706. return;
  7707. if (adapter->vxlan_port == port)
  7708. return;
  7709. if (adapter->vxlan_port) {
  7710. netdev_info(dev,
  7711. "VXLAN port %d set, not adding port %d\n",
  7712. ntohs(adapter->vxlan_port),
  7713. ntohs(port));
  7714. return;
  7715. }
  7716. adapter->vxlan_port = port;
  7717. break;
  7718. case UDP_TUNNEL_TYPE_GENEVE:
  7719. if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
  7720. return;
  7721. if (adapter->geneve_port == port)
  7722. return;
  7723. if (adapter->geneve_port) {
  7724. netdev_info(dev,
  7725. "GENEVE port %d set, not adding port %d\n",
  7726. ntohs(adapter->geneve_port),
  7727. ntohs(port));
  7728. return;
  7729. }
  7730. port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT;
  7731. adapter->geneve_port = port;
  7732. break;
  7733. default:
  7734. return;
  7735. }
  7736. reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift;
  7737. IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg);
  7738. }
  7739. /**
  7740. * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports
  7741. * @dev: The port's netdev
  7742. * @ti: Tunnel endpoint information
  7743. **/
  7744. static void ixgbe_del_udp_tunnel_port(struct net_device *dev,
  7745. struct udp_tunnel_info *ti)
  7746. {
  7747. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7748. u32 port_mask;
  7749. if (ti->type != UDP_TUNNEL_TYPE_VXLAN &&
  7750. ti->type != UDP_TUNNEL_TYPE_GENEVE)
  7751. return;
  7752. if (ti->sa_family != AF_INET)
  7753. return;
  7754. switch (ti->type) {
  7755. case UDP_TUNNEL_TYPE_VXLAN:
  7756. if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
  7757. return;
  7758. if (adapter->vxlan_port != ti->port) {
  7759. netdev_info(dev, "VXLAN port %d not found\n",
  7760. ntohs(ti->port));
  7761. return;
  7762. }
  7763. port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
  7764. break;
  7765. case UDP_TUNNEL_TYPE_GENEVE:
  7766. if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
  7767. return;
  7768. if (adapter->geneve_port != ti->port) {
  7769. netdev_info(dev, "GENEVE port %d not found\n",
  7770. ntohs(ti->port));
  7771. return;
  7772. }
  7773. port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
  7774. break;
  7775. default:
  7776. return;
  7777. }
  7778. ixgbe_clear_udp_tunnel_port(adapter, port_mask);
  7779. adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
  7780. }
  7781. static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  7782. struct net_device *dev,
  7783. const unsigned char *addr, u16 vid,
  7784. u16 flags)
  7785. {
  7786. /* guarantee we can provide a unique filter for the unicast address */
  7787. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
  7788. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7789. u16 pool = VMDQ_P(0);
  7790. if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
  7791. return -ENOMEM;
  7792. }
  7793. return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
  7794. }
  7795. /**
  7796. * ixgbe_configure_bridge_mode - set various bridge modes
  7797. * @adapter - the private structure
  7798. * @mode - requested bridge mode
  7799. *
  7800. * Configure some settings require for various bridge modes.
  7801. **/
  7802. static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
  7803. __u16 mode)
  7804. {
  7805. struct ixgbe_hw *hw = &adapter->hw;
  7806. unsigned int p, num_pools;
  7807. u32 vmdctl;
  7808. switch (mode) {
  7809. case BRIDGE_MODE_VEPA:
  7810. /* disable Tx loopback, rely on switch hairpin mode */
  7811. IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
  7812. /* must enable Rx switching replication to allow multicast
  7813. * packet reception on all VFs, and to enable source address
  7814. * pruning.
  7815. */
  7816. vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
  7817. vmdctl |= IXGBE_VT_CTL_REPLEN;
  7818. IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
  7819. /* enable Rx source address pruning. Note, this requires
  7820. * replication to be enabled or else it does nothing.
  7821. */
  7822. num_pools = adapter->num_vfs + adapter->num_rx_pools;
  7823. for (p = 0; p < num_pools; p++) {
  7824. if (hw->mac.ops.set_source_address_pruning)
  7825. hw->mac.ops.set_source_address_pruning(hw,
  7826. true,
  7827. p);
  7828. }
  7829. break;
  7830. case BRIDGE_MODE_VEB:
  7831. /* enable Tx loopback for internal VF/PF communication */
  7832. IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
  7833. IXGBE_PFDTXGSWC_VT_LBEN);
  7834. /* disable Rx switching replication unless we have SR-IOV
  7835. * virtual functions
  7836. */
  7837. vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
  7838. if (!adapter->num_vfs)
  7839. vmdctl &= ~IXGBE_VT_CTL_REPLEN;
  7840. IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
  7841. /* disable Rx source address pruning, since we don't expect to
  7842. * be receiving external loopback of our transmitted frames.
  7843. */
  7844. num_pools = adapter->num_vfs + adapter->num_rx_pools;
  7845. for (p = 0; p < num_pools; p++) {
  7846. if (hw->mac.ops.set_source_address_pruning)
  7847. hw->mac.ops.set_source_address_pruning(hw,
  7848. false,
  7849. p);
  7850. }
  7851. break;
  7852. default:
  7853. return -EINVAL;
  7854. }
  7855. adapter->bridge_mode = mode;
  7856. e_info(drv, "enabling bridge mode: %s\n",
  7857. mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  7858. return 0;
  7859. }
  7860. static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
  7861. struct nlmsghdr *nlh, u16 flags)
  7862. {
  7863. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7864. struct nlattr *attr, *br_spec;
  7865. int rem;
  7866. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  7867. return -EOPNOTSUPP;
  7868. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  7869. if (!br_spec)
  7870. return -EINVAL;
  7871. nla_for_each_nested(attr, br_spec, rem) {
  7872. int status;
  7873. __u16 mode;
  7874. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  7875. continue;
  7876. if (nla_len(attr) < sizeof(mode))
  7877. return -EINVAL;
  7878. mode = nla_get_u16(attr);
  7879. status = ixgbe_configure_bridge_mode(adapter, mode);
  7880. if (status)
  7881. return status;
  7882. break;
  7883. }
  7884. return 0;
  7885. }
  7886. static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  7887. struct net_device *dev,
  7888. u32 filter_mask, int nlflags)
  7889. {
  7890. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7891. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  7892. return 0;
  7893. return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
  7894. adapter->bridge_mode, 0, 0, nlflags,
  7895. filter_mask, NULL);
  7896. }
  7897. static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
  7898. {
  7899. struct ixgbe_fwd_adapter *fwd_adapter = NULL;
  7900. struct ixgbe_adapter *adapter = netdev_priv(pdev);
  7901. int used_pools = adapter->num_vfs + adapter->num_rx_pools;
  7902. unsigned int limit;
  7903. int pool, err;
  7904. /* Hardware has a limited number of available pools. Each VF, and the
  7905. * PF require a pool. Check to ensure we don't attempt to use more
  7906. * then the available number of pools.
  7907. */
  7908. if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
  7909. return ERR_PTR(-EINVAL);
  7910. #ifdef CONFIG_RPS
  7911. if (vdev->num_rx_queues != vdev->num_tx_queues) {
  7912. netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
  7913. vdev->name);
  7914. return ERR_PTR(-EINVAL);
  7915. }
  7916. #endif
  7917. /* Check for hardware restriction on number of rx/tx queues */
  7918. if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
  7919. vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
  7920. netdev_info(pdev,
  7921. "%s: Supports RX/TX Queue counts 1,2, and 4\n",
  7922. pdev->name);
  7923. return ERR_PTR(-EINVAL);
  7924. }
  7925. if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
  7926. adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
  7927. (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
  7928. return ERR_PTR(-EBUSY);
  7929. fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL);
  7930. if (!fwd_adapter)
  7931. return ERR_PTR(-ENOMEM);
  7932. pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
  7933. adapter->num_rx_pools++;
  7934. set_bit(pool, &adapter->fwd_bitmask);
  7935. limit = find_last_bit(&adapter->fwd_bitmask, 32);
  7936. /* Enable VMDq flag so device will be set in VM mode */
  7937. adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
  7938. adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
  7939. adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
  7940. /* Force reinit of ring allocation with VMDQ enabled */
  7941. err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
  7942. if (err)
  7943. goto fwd_add_err;
  7944. fwd_adapter->pool = pool;
  7945. fwd_adapter->real_adapter = adapter;
  7946. if (netif_running(pdev)) {
  7947. err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
  7948. if (err)
  7949. goto fwd_add_err;
  7950. netif_tx_start_all_queues(vdev);
  7951. }
  7952. return fwd_adapter;
  7953. fwd_add_err:
  7954. /* unwind counter and free adapter struct */
  7955. netdev_info(pdev,
  7956. "%s: dfwd hardware acceleration failed\n", vdev->name);
  7957. clear_bit(pool, &adapter->fwd_bitmask);
  7958. adapter->num_rx_pools--;
  7959. kfree(fwd_adapter);
  7960. return ERR_PTR(err);
  7961. }
  7962. static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
  7963. {
  7964. struct ixgbe_fwd_adapter *fwd_adapter = priv;
  7965. struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
  7966. unsigned int limit;
  7967. clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
  7968. adapter->num_rx_pools--;
  7969. limit = find_last_bit(&adapter->fwd_bitmask, 32);
  7970. adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
  7971. ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
  7972. ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
  7973. netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
  7974. fwd_adapter->pool, adapter->num_rx_pools,
  7975. fwd_adapter->rx_base_queue,
  7976. fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
  7977. adapter->fwd_bitmask);
  7978. kfree(fwd_adapter);
  7979. }
  7980. #define IXGBE_MAX_MAC_HDR_LEN 127
  7981. #define IXGBE_MAX_NETWORK_HDR_LEN 511
  7982. static netdev_features_t
  7983. ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
  7984. netdev_features_t features)
  7985. {
  7986. unsigned int network_hdr_len, mac_hdr_len;
  7987. /* Make certain the headers can be described by a context descriptor */
  7988. mac_hdr_len = skb_network_header(skb) - skb->data;
  7989. if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN))
  7990. return features & ~(NETIF_F_HW_CSUM |
  7991. NETIF_F_SCTP_CRC |
  7992. NETIF_F_HW_VLAN_CTAG_TX |
  7993. NETIF_F_TSO |
  7994. NETIF_F_TSO6);
  7995. network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
  7996. if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN))
  7997. return features & ~(NETIF_F_HW_CSUM |
  7998. NETIF_F_SCTP_CRC |
  7999. NETIF_F_TSO |
  8000. NETIF_F_TSO6);
  8001. /* We can only support IPV4 TSO in tunnels if we can mangle the
  8002. * inner IP ID field, so strip TSO if MANGLEID is not supported.
  8003. */
  8004. if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID))
  8005. features &= ~NETIF_F_TSO;
  8006. return features;
  8007. }
  8008. static const struct net_device_ops ixgbe_netdev_ops = {
  8009. .ndo_open = ixgbe_open,
  8010. .ndo_stop = ixgbe_close,
  8011. .ndo_start_xmit = ixgbe_xmit_frame,
  8012. .ndo_select_queue = ixgbe_select_queue,
  8013. .ndo_set_rx_mode = ixgbe_set_rx_mode,
  8014. .ndo_validate_addr = eth_validate_addr,
  8015. .ndo_set_mac_address = ixgbe_set_mac,
  8016. .ndo_change_mtu = ixgbe_change_mtu,
  8017. .ndo_tx_timeout = ixgbe_tx_timeout,
  8018. .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
  8019. .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
  8020. .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
  8021. .ndo_do_ioctl = ixgbe_ioctl,
  8022. .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
  8023. .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
  8024. .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
  8025. .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
  8026. .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
  8027. .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
  8028. .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
  8029. .ndo_get_stats64 = ixgbe_get_stats64,
  8030. .ndo_setup_tc = __ixgbe_setup_tc,
  8031. #ifdef CONFIG_NET_POLL_CONTROLLER
  8032. .ndo_poll_controller = ixgbe_netpoll,
  8033. #endif
  8034. #ifdef IXGBE_FCOE
  8035. .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
  8036. .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
  8037. .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
  8038. .ndo_fcoe_enable = ixgbe_fcoe_enable,
  8039. .ndo_fcoe_disable = ixgbe_fcoe_disable,
  8040. .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
  8041. .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
  8042. #endif /* IXGBE_FCOE */
  8043. .ndo_set_features = ixgbe_set_features,
  8044. .ndo_fix_features = ixgbe_fix_features,
  8045. .ndo_fdb_add = ixgbe_ndo_fdb_add,
  8046. .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
  8047. .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
  8048. .ndo_dfwd_add_station = ixgbe_fwd_add,
  8049. .ndo_dfwd_del_station = ixgbe_fwd_del,
  8050. .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port,
  8051. .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port,
  8052. .ndo_features_check = ixgbe_features_check,
  8053. };
  8054. /**
  8055. * ixgbe_enumerate_functions - Get the number of ports this device has
  8056. * @adapter: adapter structure
  8057. *
  8058. * This function enumerates the phsyical functions co-located on a single slot,
  8059. * in order to determine how many ports a device has. This is most useful in
  8060. * determining the required GT/s of PCIe bandwidth necessary for optimal
  8061. * performance.
  8062. **/
  8063. static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
  8064. {
  8065. struct pci_dev *entry, *pdev = adapter->pdev;
  8066. int physfns = 0;
  8067. /* Some cards can not use the generic count PCIe functions method,
  8068. * because they are behind a parent switch, so we hardcode these with
  8069. * the correct number of functions.
  8070. */
  8071. if (ixgbe_pcie_from_parent(&adapter->hw))
  8072. physfns = 4;
  8073. list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
  8074. /* don't count virtual functions */
  8075. if (entry->is_virtfn)
  8076. continue;
  8077. /* When the devices on the bus don't all match our device ID,
  8078. * we can't reliably determine the correct number of
  8079. * functions. This can occur if a function has been direct
  8080. * attached to a virtual machine using VT-d, for example. In
  8081. * this case, simply return -1 to indicate this.
  8082. */
  8083. if ((entry->vendor != pdev->vendor) ||
  8084. (entry->device != pdev->device))
  8085. return -1;
  8086. physfns++;
  8087. }
  8088. return physfns;
  8089. }
  8090. /**
  8091. * ixgbe_wol_supported - Check whether device supports WoL
  8092. * @adapter: the adapter private structure
  8093. * @device_id: the device ID
  8094. * @subdev_id: the subsystem device ID
  8095. *
  8096. * This function is used by probe and ethtool to determine
  8097. * which devices have WoL support
  8098. *
  8099. **/
  8100. bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
  8101. u16 subdevice_id)
  8102. {
  8103. struct ixgbe_hw *hw = &adapter->hw;
  8104. u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
  8105. /* WOL not supported on 82598 */
  8106. if (hw->mac.type == ixgbe_mac_82598EB)
  8107. return false;
  8108. /* check eeprom to see if WOL is enabled for X540 and newer */
  8109. if (hw->mac.type >= ixgbe_mac_X540) {
  8110. if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
  8111. ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
  8112. (hw->bus.func == 0)))
  8113. return true;
  8114. }
  8115. /* WOL is determined based on device IDs for 82599 MACs */
  8116. switch (device_id) {
  8117. case IXGBE_DEV_ID_82599_SFP:
  8118. /* Only these subdevices could supports WOL */
  8119. switch (subdevice_id) {
  8120. case IXGBE_SUBDEV_ID_82599_560FLR:
  8121. case IXGBE_SUBDEV_ID_82599_LOM_SNAP6:
  8122. case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
  8123. case IXGBE_SUBDEV_ID_82599_SFP_2OCP:
  8124. /* only support first port */
  8125. if (hw->bus.func != 0)
  8126. break;
  8127. case IXGBE_SUBDEV_ID_82599_SP_560FLR:
  8128. case IXGBE_SUBDEV_ID_82599_SFP:
  8129. case IXGBE_SUBDEV_ID_82599_RNDC:
  8130. case IXGBE_SUBDEV_ID_82599_ECNA_DP:
  8131. case IXGBE_SUBDEV_ID_82599_SFP_1OCP:
  8132. case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1:
  8133. case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2:
  8134. return true;
  8135. }
  8136. break;
  8137. case IXGBE_DEV_ID_82599EN_SFP:
  8138. /* Only these subdevices support WOL */
  8139. switch (subdevice_id) {
  8140. case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
  8141. return true;
  8142. }
  8143. break;
  8144. case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
  8145. /* All except this subdevice support WOL */
  8146. if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
  8147. return true;
  8148. break;
  8149. case IXGBE_DEV_ID_82599_KX4:
  8150. return true;
  8151. default:
  8152. break;
  8153. }
  8154. return false;
  8155. }
  8156. /**
  8157. * ixgbe_probe - Device Initialization Routine
  8158. * @pdev: PCI device information struct
  8159. * @ent: entry in ixgbe_pci_tbl
  8160. *
  8161. * Returns 0 on success, negative on failure
  8162. *
  8163. * ixgbe_probe initializes an adapter identified by a pci_dev structure.
  8164. * The OS initialization, configuring of the adapter private structure,
  8165. * and a hardware reset occur.
  8166. **/
  8167. static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  8168. {
  8169. struct net_device *netdev;
  8170. struct ixgbe_adapter *adapter = NULL;
  8171. struct ixgbe_hw *hw;
  8172. const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
  8173. int i, err, pci_using_dac, expected_gts;
  8174. unsigned int indices = MAX_TX_QUEUES;
  8175. u8 part_str[IXGBE_PBANUM_LENGTH];
  8176. bool disable_dev = false;
  8177. #ifdef IXGBE_FCOE
  8178. u16 device_caps;
  8179. #endif
  8180. u32 eec;
  8181. /* Catch broken hardware that put the wrong VF device ID in
  8182. * the PCIe SR-IOV capability.
  8183. */
  8184. if (pdev->is_virtfn) {
  8185. WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
  8186. pci_name(pdev), pdev->vendor, pdev->device);
  8187. return -EINVAL;
  8188. }
  8189. err = pci_enable_device_mem(pdev);
  8190. if (err)
  8191. return err;
  8192. if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
  8193. pci_using_dac = 1;
  8194. } else {
  8195. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  8196. if (err) {
  8197. dev_err(&pdev->dev,
  8198. "No usable DMA configuration, aborting\n");
  8199. goto err_dma;
  8200. }
  8201. pci_using_dac = 0;
  8202. }
  8203. err = pci_request_mem_regions(pdev, ixgbe_driver_name);
  8204. if (err) {
  8205. dev_err(&pdev->dev,
  8206. "pci_request_selected_regions failed 0x%x\n", err);
  8207. goto err_pci_reg;
  8208. }
  8209. pci_enable_pcie_error_reporting(pdev);
  8210. pci_set_master(pdev);
  8211. pci_save_state(pdev);
  8212. if (ii->mac == ixgbe_mac_82598EB) {
  8213. #ifdef CONFIG_IXGBE_DCB
  8214. /* 8 TC w/ 4 queues per TC */
  8215. indices = 4 * MAX_TRAFFIC_CLASS;
  8216. #else
  8217. indices = IXGBE_MAX_RSS_INDICES;
  8218. #endif
  8219. }
  8220. netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
  8221. if (!netdev) {
  8222. err = -ENOMEM;
  8223. goto err_alloc_etherdev;
  8224. }
  8225. SET_NETDEV_DEV(netdev, &pdev->dev);
  8226. adapter = netdev_priv(netdev);
  8227. adapter->netdev = netdev;
  8228. adapter->pdev = pdev;
  8229. hw = &adapter->hw;
  8230. hw->back = adapter;
  8231. adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
  8232. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  8233. pci_resource_len(pdev, 0));
  8234. adapter->io_addr = hw->hw_addr;
  8235. if (!hw->hw_addr) {
  8236. err = -EIO;
  8237. goto err_ioremap;
  8238. }
  8239. netdev->netdev_ops = &ixgbe_netdev_ops;
  8240. ixgbe_set_ethtool_ops(netdev);
  8241. netdev->watchdog_timeo = 5 * HZ;
  8242. strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
  8243. /* Setup hw api */
  8244. hw->mac.ops = *ii->mac_ops;
  8245. hw->mac.type = ii->mac;
  8246. hw->mvals = ii->mvals;
  8247. if (ii->link_ops)
  8248. hw->link.ops = *ii->link_ops;
  8249. /* EEPROM */
  8250. hw->eeprom.ops = *ii->eeprom_ops;
  8251. eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
  8252. if (ixgbe_removed(hw->hw_addr)) {
  8253. err = -EIO;
  8254. goto err_ioremap;
  8255. }
  8256. /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
  8257. if (!(eec & BIT(8)))
  8258. hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
  8259. /* PHY */
  8260. hw->phy.ops = *ii->phy_ops;
  8261. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  8262. /* ixgbe_identify_phy_generic will set prtad and mmds properly */
  8263. hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
  8264. hw->phy.mdio.mmds = 0;
  8265. hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  8266. hw->phy.mdio.dev = netdev;
  8267. hw->phy.mdio.mdio_read = ixgbe_mdio_read;
  8268. hw->phy.mdio.mdio_write = ixgbe_mdio_write;
  8269. /* setup the private structure */
  8270. err = ixgbe_sw_init(adapter, ii);
  8271. if (err)
  8272. goto err_sw_init;
  8273. /* Make sure the SWFW semaphore is in a valid state */
  8274. if (hw->mac.ops.init_swfw_sync)
  8275. hw->mac.ops.init_swfw_sync(hw);
  8276. /* Make it possible the adapter to be woken up via WOL */
  8277. switch (adapter->hw.mac.type) {
  8278. case ixgbe_mac_82599EB:
  8279. case ixgbe_mac_X540:
  8280. case ixgbe_mac_X550:
  8281. case ixgbe_mac_X550EM_x:
  8282. case ixgbe_mac_x550em_a:
  8283. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  8284. break;
  8285. default:
  8286. break;
  8287. }
  8288. /*
  8289. * If there is a fan on this device and it has failed log the
  8290. * failure.
  8291. */
  8292. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  8293. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  8294. if (esdp & IXGBE_ESDP_SDP1)
  8295. e_crit(probe, "Fan has stopped, replace the adapter\n");
  8296. }
  8297. if (allow_unsupported_sfp)
  8298. hw->allow_unsupported_sfp = allow_unsupported_sfp;
  8299. /* reset_hw fills in the perm_addr as well */
  8300. hw->phy.reset_if_overtemp = true;
  8301. err = hw->mac.ops.reset_hw(hw);
  8302. hw->phy.reset_if_overtemp = false;
  8303. ixgbe_set_eee_capable(adapter);
  8304. if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
  8305. err = 0;
  8306. } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  8307. e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
  8308. e_dev_err("Reload the driver after installing a supported module.\n");
  8309. goto err_sw_init;
  8310. } else if (err) {
  8311. e_dev_err("HW Init failed: %d\n", err);
  8312. goto err_sw_init;
  8313. }
  8314. #ifdef CONFIG_PCI_IOV
  8315. /* SR-IOV not supported on the 82598 */
  8316. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  8317. goto skip_sriov;
  8318. /* Mailbox */
  8319. ixgbe_init_mbx_params_pf(hw);
  8320. hw->mbx.ops = ii->mbx_ops;
  8321. pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
  8322. ixgbe_enable_sriov(adapter, max_vfs);
  8323. skip_sriov:
  8324. #endif
  8325. netdev->features = NETIF_F_SG |
  8326. NETIF_F_TSO |
  8327. NETIF_F_TSO6 |
  8328. NETIF_F_RXHASH |
  8329. NETIF_F_RXCSUM |
  8330. NETIF_F_HW_CSUM;
  8331. #define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
  8332. NETIF_F_GSO_GRE_CSUM | \
  8333. NETIF_F_GSO_IPXIP4 | \
  8334. NETIF_F_GSO_IPXIP6 | \
  8335. NETIF_F_GSO_UDP_TUNNEL | \
  8336. NETIF_F_GSO_UDP_TUNNEL_CSUM)
  8337. netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES;
  8338. netdev->features |= NETIF_F_GSO_PARTIAL |
  8339. IXGBE_GSO_PARTIAL_FEATURES;
  8340. if (hw->mac.type >= ixgbe_mac_82599EB)
  8341. netdev->features |= NETIF_F_SCTP_CRC;
  8342. /* copy netdev features into list of user selectable features */
  8343. netdev->hw_features |= netdev->features |
  8344. NETIF_F_HW_VLAN_CTAG_FILTER |
  8345. NETIF_F_HW_VLAN_CTAG_RX |
  8346. NETIF_F_HW_VLAN_CTAG_TX |
  8347. NETIF_F_RXALL |
  8348. NETIF_F_HW_L2FW_DOFFLOAD;
  8349. if (hw->mac.type >= ixgbe_mac_82599EB)
  8350. netdev->hw_features |= NETIF_F_NTUPLE |
  8351. NETIF_F_HW_TC;
  8352. if (pci_using_dac)
  8353. netdev->features |= NETIF_F_HIGHDMA;
  8354. netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
  8355. netdev->hw_enc_features |= netdev->vlan_features;
  8356. netdev->mpls_features |= NETIF_F_HW_CSUM;
  8357. /* set this bit last since it cannot be part of vlan_features */
  8358. netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
  8359. NETIF_F_HW_VLAN_CTAG_RX |
  8360. NETIF_F_HW_VLAN_CTAG_TX;
  8361. netdev->priv_flags |= IFF_UNICAST_FLT;
  8362. netdev->priv_flags |= IFF_SUPP_NOFCS;
  8363. /* MTU range: 68 - 9710 */
  8364. netdev->min_mtu = ETH_MIN_MTU;
  8365. netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
  8366. #ifdef CONFIG_IXGBE_DCB
  8367. if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
  8368. netdev->dcbnl_ops = &ixgbe_dcbnl_ops;
  8369. #endif
  8370. #ifdef IXGBE_FCOE
  8371. if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
  8372. unsigned int fcoe_l;
  8373. if (hw->mac.ops.get_device_caps) {
  8374. hw->mac.ops.get_device_caps(hw, &device_caps);
  8375. if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
  8376. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  8377. }
  8378. fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
  8379. adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
  8380. netdev->features |= NETIF_F_FSO |
  8381. NETIF_F_FCOE_CRC;
  8382. netdev->vlan_features |= NETIF_F_FSO |
  8383. NETIF_F_FCOE_CRC |
  8384. NETIF_F_FCOE_MTU;
  8385. }
  8386. #endif /* IXGBE_FCOE */
  8387. if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
  8388. netdev->hw_features |= NETIF_F_LRO;
  8389. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  8390. netdev->features |= NETIF_F_LRO;
  8391. /* make sure the EEPROM is good */
  8392. if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
  8393. e_dev_err("The EEPROM Checksum Is Not Valid\n");
  8394. err = -EIO;
  8395. goto err_sw_init;
  8396. }
  8397. eth_platform_get_mac_address(&adapter->pdev->dev,
  8398. adapter->hw.mac.perm_addr);
  8399. memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
  8400. if (!is_valid_ether_addr(netdev->dev_addr)) {
  8401. e_dev_err("invalid MAC address\n");
  8402. err = -EIO;
  8403. goto err_sw_init;
  8404. }
  8405. /* Set hw->mac.addr to permanent MAC address */
  8406. ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
  8407. ixgbe_mac_set_default_filter(adapter);
  8408. setup_timer(&adapter->service_timer, &ixgbe_service_timer,
  8409. (unsigned long) adapter);
  8410. if (ixgbe_removed(hw->hw_addr)) {
  8411. err = -EIO;
  8412. goto err_sw_init;
  8413. }
  8414. INIT_WORK(&adapter->service_task, ixgbe_service_task);
  8415. set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
  8416. clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
  8417. err = ixgbe_init_interrupt_scheme(adapter);
  8418. if (err)
  8419. goto err_sw_init;
  8420. /* WOL not supported for all devices */
  8421. adapter->wol = 0;
  8422. hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
  8423. hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
  8424. pdev->subsystem_device);
  8425. if (hw->wol_enabled)
  8426. adapter->wol = IXGBE_WUFC_MAG;
  8427. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  8428. /* save off EEPROM version number */
  8429. hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
  8430. hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
  8431. /* pick up the PCI bus settings for reporting later */
  8432. if (ixgbe_pcie_from_parent(hw))
  8433. ixgbe_get_parent_bus_info(adapter);
  8434. else
  8435. hw->mac.ops.get_bus_info(hw);
  8436. /* calculate the expected PCIe bandwidth required for optimal
  8437. * performance. Note that some older parts will never have enough
  8438. * bandwidth due to being older generation PCIe parts. We clamp these
  8439. * parts to ensure no warning is displayed if it can't be fixed.
  8440. */
  8441. switch (hw->mac.type) {
  8442. case ixgbe_mac_82598EB:
  8443. expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
  8444. break;
  8445. default:
  8446. expected_gts = ixgbe_enumerate_functions(adapter) * 10;
  8447. break;
  8448. }
  8449. /* don't check link if we failed to enumerate functions */
  8450. if (expected_gts > 0)
  8451. ixgbe_check_minimum_link(adapter, expected_gts);
  8452. err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
  8453. if (err)
  8454. strlcpy(part_str, "Unknown", sizeof(part_str));
  8455. if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
  8456. e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
  8457. hw->mac.type, hw->phy.type, hw->phy.sfp_type,
  8458. part_str);
  8459. else
  8460. e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
  8461. hw->mac.type, hw->phy.type, part_str);
  8462. e_dev_info("%pM\n", netdev->dev_addr);
  8463. /* reset the hardware with the new settings */
  8464. err = hw->mac.ops.start_hw(hw);
  8465. if (err == IXGBE_ERR_EEPROM_VERSION) {
  8466. /* We are running on a pre-production device, log a warning */
  8467. e_dev_warn("This device is a pre-production adapter/LOM. "
  8468. "Please be aware there may be issues associated "
  8469. "with your hardware. If you are experiencing "
  8470. "problems please contact your Intel or hardware "
  8471. "representative who provided you with this "
  8472. "hardware.\n");
  8473. }
  8474. strcpy(netdev->name, "eth%d");
  8475. err = register_netdev(netdev);
  8476. if (err)
  8477. goto err_register;
  8478. pci_set_drvdata(pdev, adapter);
  8479. /* power down the optics for 82599 SFP+ fiber */
  8480. if (hw->mac.ops.disable_tx_laser)
  8481. hw->mac.ops.disable_tx_laser(hw);
  8482. /* carrier off reporting is important to ethtool even BEFORE open */
  8483. netif_carrier_off(netdev);
  8484. #ifdef CONFIG_IXGBE_DCA
  8485. if (dca_add_requester(&pdev->dev) == 0) {
  8486. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  8487. ixgbe_setup_dca(adapter);
  8488. }
  8489. #endif
  8490. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  8491. e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
  8492. for (i = 0; i < adapter->num_vfs; i++)
  8493. ixgbe_vf_configuration(pdev, (i | 0x10000000));
  8494. }
  8495. /* firmware requires driver version to be 0xFFFFFFFF
  8496. * since os does not support feature
  8497. */
  8498. if (hw->mac.ops.set_fw_drv_ver)
  8499. hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF,
  8500. sizeof(ixgbe_driver_version) - 1,
  8501. ixgbe_driver_version);
  8502. /* add san mac addr to netdev */
  8503. ixgbe_add_sanmac_netdev(netdev);
  8504. e_dev_info("%s\n", ixgbe_default_device_descr);
  8505. #ifdef CONFIG_IXGBE_HWMON
  8506. if (ixgbe_sysfs_init(adapter))
  8507. e_err(probe, "failed to allocate sysfs resources\n");
  8508. #endif /* CONFIG_IXGBE_HWMON */
  8509. ixgbe_dbg_adapter_init(adapter);
  8510. /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
  8511. if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
  8512. hw->mac.ops.setup_link(hw,
  8513. IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
  8514. true);
  8515. return 0;
  8516. err_register:
  8517. ixgbe_release_hw_control(adapter);
  8518. ixgbe_clear_interrupt_scheme(adapter);
  8519. err_sw_init:
  8520. ixgbe_disable_sriov(adapter);
  8521. adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
  8522. iounmap(adapter->io_addr);
  8523. kfree(adapter->jump_tables[0]);
  8524. kfree(adapter->mac_table);
  8525. err_ioremap:
  8526. disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
  8527. free_netdev(netdev);
  8528. err_alloc_etherdev:
  8529. pci_release_mem_regions(pdev);
  8530. err_pci_reg:
  8531. err_dma:
  8532. if (!adapter || disable_dev)
  8533. pci_disable_device(pdev);
  8534. return err;
  8535. }
  8536. /**
  8537. * ixgbe_remove - Device Removal Routine
  8538. * @pdev: PCI device information struct
  8539. *
  8540. * ixgbe_remove is called by the PCI subsystem to alert the driver
  8541. * that it should release a PCI device. The could be caused by a
  8542. * Hot-Plug event, or because the driver is going to be removed from
  8543. * memory.
  8544. **/
  8545. static void ixgbe_remove(struct pci_dev *pdev)
  8546. {
  8547. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  8548. struct net_device *netdev;
  8549. bool disable_dev;
  8550. int i;
  8551. /* if !adapter then we already cleaned up in probe */
  8552. if (!adapter)
  8553. return;
  8554. netdev = adapter->netdev;
  8555. ixgbe_dbg_adapter_exit(adapter);
  8556. set_bit(__IXGBE_REMOVING, &adapter->state);
  8557. cancel_work_sync(&adapter->service_task);
  8558. #ifdef CONFIG_IXGBE_DCA
  8559. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  8560. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  8561. dca_remove_requester(&pdev->dev);
  8562. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  8563. IXGBE_DCA_CTRL_DCA_DISABLE);
  8564. }
  8565. #endif
  8566. #ifdef CONFIG_IXGBE_HWMON
  8567. ixgbe_sysfs_exit(adapter);
  8568. #endif /* CONFIG_IXGBE_HWMON */
  8569. /* remove the added san mac */
  8570. ixgbe_del_sanmac_netdev(netdev);
  8571. #ifdef CONFIG_PCI_IOV
  8572. ixgbe_disable_sriov(adapter);
  8573. #endif
  8574. if (netdev->reg_state == NETREG_REGISTERED)
  8575. unregister_netdev(netdev);
  8576. ixgbe_clear_interrupt_scheme(adapter);
  8577. ixgbe_release_hw_control(adapter);
  8578. #ifdef CONFIG_DCB
  8579. kfree(adapter->ixgbe_ieee_pfc);
  8580. kfree(adapter->ixgbe_ieee_ets);
  8581. #endif
  8582. iounmap(adapter->io_addr);
  8583. pci_release_mem_regions(pdev);
  8584. e_dev_info("complete\n");
  8585. for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) {
  8586. if (adapter->jump_tables[i]) {
  8587. kfree(adapter->jump_tables[i]->input);
  8588. kfree(adapter->jump_tables[i]->mask);
  8589. }
  8590. kfree(adapter->jump_tables[i]);
  8591. }
  8592. kfree(adapter->mac_table);
  8593. disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
  8594. free_netdev(netdev);
  8595. pci_disable_pcie_error_reporting(pdev);
  8596. if (disable_dev)
  8597. pci_disable_device(pdev);
  8598. }
  8599. /**
  8600. * ixgbe_io_error_detected - called when PCI error is detected
  8601. * @pdev: Pointer to PCI device
  8602. * @state: The current pci connection state
  8603. *
  8604. * This function is called after a PCI bus error affecting
  8605. * this device has been detected.
  8606. */
  8607. static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
  8608. pci_channel_state_t state)
  8609. {
  8610. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  8611. struct net_device *netdev = adapter->netdev;
  8612. #ifdef CONFIG_PCI_IOV
  8613. struct ixgbe_hw *hw = &adapter->hw;
  8614. struct pci_dev *bdev, *vfdev;
  8615. u32 dw0, dw1, dw2, dw3;
  8616. int vf, pos;
  8617. u16 req_id, pf_func;
  8618. if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
  8619. adapter->num_vfs == 0)
  8620. goto skip_bad_vf_detection;
  8621. bdev = pdev->bus->self;
  8622. while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
  8623. bdev = bdev->bus->self;
  8624. if (!bdev)
  8625. goto skip_bad_vf_detection;
  8626. pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
  8627. if (!pos)
  8628. goto skip_bad_vf_detection;
  8629. dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
  8630. dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
  8631. dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
  8632. dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
  8633. if (ixgbe_removed(hw->hw_addr))
  8634. goto skip_bad_vf_detection;
  8635. req_id = dw1 >> 16;
  8636. /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
  8637. if (!(req_id & 0x0080))
  8638. goto skip_bad_vf_detection;
  8639. pf_func = req_id & 0x01;
  8640. if ((pf_func & 1) == (pdev->devfn & 1)) {
  8641. unsigned int device_id;
  8642. vf = (req_id & 0x7F) >> 1;
  8643. e_dev_err("VF %d has caused a PCIe error\n", vf);
  8644. e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
  8645. "%8.8x\tdw3: %8.8x\n",
  8646. dw0, dw1, dw2, dw3);
  8647. switch (adapter->hw.mac.type) {
  8648. case ixgbe_mac_82599EB:
  8649. device_id = IXGBE_82599_VF_DEVICE_ID;
  8650. break;
  8651. case ixgbe_mac_X540:
  8652. device_id = IXGBE_X540_VF_DEVICE_ID;
  8653. break;
  8654. case ixgbe_mac_X550:
  8655. device_id = IXGBE_DEV_ID_X550_VF;
  8656. break;
  8657. case ixgbe_mac_X550EM_x:
  8658. device_id = IXGBE_DEV_ID_X550EM_X_VF;
  8659. break;
  8660. case ixgbe_mac_x550em_a:
  8661. device_id = IXGBE_DEV_ID_X550EM_A_VF;
  8662. break;
  8663. default:
  8664. device_id = 0;
  8665. break;
  8666. }
  8667. /* Find the pci device of the offending VF */
  8668. vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
  8669. while (vfdev) {
  8670. if (vfdev->devfn == (req_id & 0xFF))
  8671. break;
  8672. vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  8673. device_id, vfdev);
  8674. }
  8675. /*
  8676. * There's a slim chance the VF could have been hot plugged,
  8677. * so if it is no longer present we don't need to issue the
  8678. * VFLR. Just clean up the AER in that case.
  8679. */
  8680. if (vfdev) {
  8681. ixgbe_issue_vf_flr(adapter, vfdev);
  8682. /* Free device reference count */
  8683. pci_dev_put(vfdev);
  8684. }
  8685. pci_cleanup_aer_uncorrect_error_status(pdev);
  8686. }
  8687. /*
  8688. * Even though the error may have occurred on the other port
  8689. * we still need to increment the vf error reference count for
  8690. * both ports because the I/O resume function will be called
  8691. * for both of them.
  8692. */
  8693. adapter->vferr_refcount++;
  8694. return PCI_ERS_RESULT_RECOVERED;
  8695. skip_bad_vf_detection:
  8696. #endif /* CONFIG_PCI_IOV */
  8697. if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
  8698. return PCI_ERS_RESULT_DISCONNECT;
  8699. rtnl_lock();
  8700. netif_device_detach(netdev);
  8701. if (state == pci_channel_io_perm_failure) {
  8702. rtnl_unlock();
  8703. return PCI_ERS_RESULT_DISCONNECT;
  8704. }
  8705. if (netif_running(netdev))
  8706. ixgbe_close_suspend(adapter);
  8707. if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
  8708. pci_disable_device(pdev);
  8709. rtnl_unlock();
  8710. /* Request a slot reset. */
  8711. return PCI_ERS_RESULT_NEED_RESET;
  8712. }
  8713. /**
  8714. * ixgbe_io_slot_reset - called after the pci bus has been reset.
  8715. * @pdev: Pointer to PCI device
  8716. *
  8717. * Restart the card from scratch, as if from a cold-boot.
  8718. */
  8719. static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
  8720. {
  8721. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  8722. pci_ers_result_t result;
  8723. int err;
  8724. if (pci_enable_device_mem(pdev)) {
  8725. e_err(probe, "Cannot re-enable PCI device after reset.\n");
  8726. result = PCI_ERS_RESULT_DISCONNECT;
  8727. } else {
  8728. smp_mb__before_atomic();
  8729. clear_bit(__IXGBE_DISABLED, &adapter->state);
  8730. adapter->hw.hw_addr = adapter->io_addr;
  8731. pci_set_master(pdev);
  8732. pci_restore_state(pdev);
  8733. pci_save_state(pdev);
  8734. pci_wake_from_d3(pdev, false);
  8735. ixgbe_reset(adapter);
  8736. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  8737. result = PCI_ERS_RESULT_RECOVERED;
  8738. }
  8739. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  8740. if (err) {
  8741. e_dev_err("pci_cleanup_aer_uncorrect_error_status "
  8742. "failed 0x%0x\n", err);
  8743. /* non-fatal, continue */
  8744. }
  8745. return result;
  8746. }
  8747. /**
  8748. * ixgbe_io_resume - called when traffic can start flowing again.
  8749. * @pdev: Pointer to PCI device
  8750. *
  8751. * This callback is called when the error recovery driver tells us that
  8752. * its OK to resume normal operation.
  8753. */
  8754. static void ixgbe_io_resume(struct pci_dev *pdev)
  8755. {
  8756. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  8757. struct net_device *netdev = adapter->netdev;
  8758. #ifdef CONFIG_PCI_IOV
  8759. if (adapter->vferr_refcount) {
  8760. e_info(drv, "Resuming after VF err\n");
  8761. adapter->vferr_refcount--;
  8762. return;
  8763. }
  8764. #endif
  8765. rtnl_lock();
  8766. if (netif_running(netdev))
  8767. ixgbe_open(netdev);
  8768. netif_device_attach(netdev);
  8769. rtnl_unlock();
  8770. }
  8771. static const struct pci_error_handlers ixgbe_err_handler = {
  8772. .error_detected = ixgbe_io_error_detected,
  8773. .slot_reset = ixgbe_io_slot_reset,
  8774. .resume = ixgbe_io_resume,
  8775. };
  8776. static struct pci_driver ixgbe_driver = {
  8777. .name = ixgbe_driver_name,
  8778. .id_table = ixgbe_pci_tbl,
  8779. .probe = ixgbe_probe,
  8780. .remove = ixgbe_remove,
  8781. #ifdef CONFIG_PM
  8782. .suspend = ixgbe_suspend,
  8783. .resume = ixgbe_resume,
  8784. #endif
  8785. .shutdown = ixgbe_shutdown,
  8786. .sriov_configure = ixgbe_pci_sriov_configure,
  8787. .err_handler = &ixgbe_err_handler
  8788. };
  8789. /**
  8790. * ixgbe_init_module - Driver Registration Routine
  8791. *
  8792. * ixgbe_init_module is the first routine called when the driver is
  8793. * loaded. All it does is register with the PCI subsystem.
  8794. **/
  8795. static int __init ixgbe_init_module(void)
  8796. {
  8797. int ret;
  8798. pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
  8799. pr_info("%s\n", ixgbe_copyright);
  8800. ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
  8801. if (!ixgbe_wq) {
  8802. pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
  8803. return -ENOMEM;
  8804. }
  8805. ixgbe_dbg_init();
  8806. ret = pci_register_driver(&ixgbe_driver);
  8807. if (ret) {
  8808. destroy_workqueue(ixgbe_wq);
  8809. ixgbe_dbg_exit();
  8810. return ret;
  8811. }
  8812. #ifdef CONFIG_IXGBE_DCA
  8813. dca_register_notify(&dca_notifier);
  8814. #endif
  8815. return 0;
  8816. }
  8817. module_init(ixgbe_init_module);
  8818. /**
  8819. * ixgbe_exit_module - Driver Exit Cleanup Routine
  8820. *
  8821. * ixgbe_exit_module is called just before the driver is removed
  8822. * from memory.
  8823. **/
  8824. static void __exit ixgbe_exit_module(void)
  8825. {
  8826. #ifdef CONFIG_IXGBE_DCA
  8827. dca_unregister_notify(&dca_notifier);
  8828. #endif
  8829. pci_unregister_driver(&ixgbe_driver);
  8830. ixgbe_dbg_exit();
  8831. if (ixgbe_wq) {
  8832. destroy_workqueue(ixgbe_wq);
  8833. ixgbe_wq = NULL;
  8834. }
  8835. }
  8836. #ifdef CONFIG_IXGBE_DCA
  8837. static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
  8838. void *p)
  8839. {
  8840. int ret_val;
  8841. ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
  8842. __ixgbe_notify_dca);
  8843. return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
  8844. }
  8845. #endif /* CONFIG_IXGBE_DCA */
  8846. module_exit(ixgbe_exit_module);
  8847. /* ixgbe_main.c */