ixgbe_main.c 227 KB

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