igb_main.c 197 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275
  1. /*******************************************************************************
  2. Intel(R) Gigabit Ethernet Linux driver
  3. Copyright(c) 2007-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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  21. #include <linux/module.h>
  22. #include <linux/types.h>
  23. #include <linux/init.h>
  24. #include <linux/bitops.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/pagemap.h>
  27. #include <linux/netdevice.h>
  28. #include <linux/ipv6.h>
  29. #include <linux/slab.h>
  30. #include <net/checksum.h>
  31. #include <net/ip6_checksum.h>
  32. #include <linux/net_tstamp.h>
  33. #include <linux/mii.h>
  34. #include <linux/ethtool.h>
  35. #include <linux/if.h>
  36. #include <linux/if_vlan.h>
  37. #include <linux/pci.h>
  38. #include <linux/pci-aspm.h>
  39. #include <linux/delay.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/ip.h>
  42. #include <linux/tcp.h>
  43. #include <linux/sctp.h>
  44. #include <linux/if_ether.h>
  45. #include <linux/aer.h>
  46. #include <linux/prefetch.h>
  47. #include <linux/pm_runtime.h>
  48. #ifdef CONFIG_IGB_DCA
  49. #include <linux/dca.h>
  50. #endif
  51. #include "igb.h"
  52. #define MAJ 3
  53. #define MIN 2
  54. #define BUILD 10
  55. #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
  56. __stringify(BUILD) "-k"
  57. char igb_driver_name[] = "igb";
  58. char igb_driver_version[] = DRV_VERSION;
  59. static const char igb_driver_string[] =
  60. "Intel(R) Gigabit Ethernet Network Driver";
  61. static const char igb_copyright[] = "Copyright (c) 2007-2012 Intel Corporation.";
  62. static const struct e1000_info *igb_info_tbl[] = {
  63. [board_82575] = &e1000_82575_info,
  64. };
  65. static DEFINE_PCI_DEVICE_TABLE(igb_pci_tbl) = {
  66. { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_COPPER), board_82575 },
  67. { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_FIBER), board_82575 },
  68. { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SERDES), board_82575 },
  69. { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SGMII), board_82575 },
  70. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER), board_82575 },
  71. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_FIBER), board_82575 },
  72. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_QUAD_FIBER), board_82575 },
  73. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SERDES), board_82575 },
  74. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SGMII), board_82575 },
  75. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER_DUAL), board_82575 },
  76. { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SGMII), board_82575 },
  77. { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SERDES), board_82575 },
  78. { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_BACKPLANE), board_82575 },
  79. { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SFP), board_82575 },
  80. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576), board_82575 },
  81. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS), board_82575 },
  82. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS_SERDES), board_82575 },
  83. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER), board_82575 },
  84. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES), board_82575 },
  85. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES_QUAD), board_82575 },
  86. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER_ET2), board_82575 },
  87. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER), board_82575 },
  88. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER), board_82575 },
  89. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES), board_82575 },
  90. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER), board_82575 },
  91. /* required last entry */
  92. {0, }
  93. };
  94. MODULE_DEVICE_TABLE(pci, igb_pci_tbl);
  95. void igb_reset(struct igb_adapter *);
  96. static int igb_setup_all_tx_resources(struct igb_adapter *);
  97. static int igb_setup_all_rx_resources(struct igb_adapter *);
  98. static void igb_free_all_tx_resources(struct igb_adapter *);
  99. static void igb_free_all_rx_resources(struct igb_adapter *);
  100. static void igb_setup_mrqc(struct igb_adapter *);
  101. static int igb_probe(struct pci_dev *, const struct pci_device_id *);
  102. static void __devexit igb_remove(struct pci_dev *pdev);
  103. static void igb_init_hw_timer(struct igb_adapter *adapter);
  104. static int igb_sw_init(struct igb_adapter *);
  105. static int igb_open(struct net_device *);
  106. static int igb_close(struct net_device *);
  107. static void igb_configure_tx(struct igb_adapter *);
  108. static void igb_configure_rx(struct igb_adapter *);
  109. static void igb_clean_all_tx_rings(struct igb_adapter *);
  110. static void igb_clean_all_rx_rings(struct igb_adapter *);
  111. static void igb_clean_tx_ring(struct igb_ring *);
  112. static void igb_clean_rx_ring(struct igb_ring *);
  113. static void igb_set_rx_mode(struct net_device *);
  114. static void igb_update_phy_info(unsigned long);
  115. static void igb_watchdog(unsigned long);
  116. static void igb_watchdog_task(struct work_struct *);
  117. static netdev_tx_t igb_xmit_frame(struct sk_buff *skb, struct net_device *);
  118. static struct rtnl_link_stats64 *igb_get_stats64(struct net_device *dev,
  119. struct rtnl_link_stats64 *stats);
  120. static int igb_change_mtu(struct net_device *, int);
  121. static int igb_set_mac(struct net_device *, void *);
  122. static void igb_set_uta(struct igb_adapter *adapter);
  123. static irqreturn_t igb_intr(int irq, void *);
  124. static irqreturn_t igb_intr_msi(int irq, void *);
  125. static irqreturn_t igb_msix_other(int irq, void *);
  126. static irqreturn_t igb_msix_ring(int irq, void *);
  127. #ifdef CONFIG_IGB_DCA
  128. static void igb_update_dca(struct igb_q_vector *);
  129. static void igb_setup_dca(struct igb_adapter *);
  130. #endif /* CONFIG_IGB_DCA */
  131. static int igb_poll(struct napi_struct *, int);
  132. static bool igb_clean_tx_irq(struct igb_q_vector *);
  133. static bool igb_clean_rx_irq(struct igb_q_vector *, int);
  134. static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
  135. static void igb_tx_timeout(struct net_device *);
  136. static void igb_reset_task(struct work_struct *);
  137. static void igb_vlan_mode(struct net_device *netdev, netdev_features_t features);
  138. static int igb_vlan_rx_add_vid(struct net_device *, u16);
  139. static int igb_vlan_rx_kill_vid(struct net_device *, u16);
  140. static void igb_restore_vlan(struct igb_adapter *);
  141. static void igb_rar_set_qsel(struct igb_adapter *, u8 *, u32 , u8);
  142. static void igb_ping_all_vfs(struct igb_adapter *);
  143. static void igb_msg_task(struct igb_adapter *);
  144. static void igb_vmm_control(struct igb_adapter *);
  145. static int igb_set_vf_mac(struct igb_adapter *, int, unsigned char *);
  146. static void igb_restore_vf_multicasts(struct igb_adapter *adapter);
  147. static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac);
  148. static int igb_ndo_set_vf_vlan(struct net_device *netdev,
  149. int vf, u16 vlan, u8 qos);
  150. static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate);
  151. static int igb_ndo_get_vf_config(struct net_device *netdev, int vf,
  152. struct ifla_vf_info *ivi);
  153. static void igb_check_vf_rate_limit(struct igb_adapter *);
  154. #ifdef CONFIG_PCI_IOV
  155. static int igb_vf_configure(struct igb_adapter *adapter, int vf);
  156. static int igb_find_enabled_vfs(struct igb_adapter *adapter);
  157. static int igb_check_vf_assignment(struct igb_adapter *adapter);
  158. #endif
  159. #ifdef CONFIG_PM
  160. #ifdef CONFIG_PM_SLEEP
  161. static int igb_suspend(struct device *);
  162. #endif
  163. static int igb_resume(struct device *);
  164. #ifdef CONFIG_PM_RUNTIME
  165. static int igb_runtime_suspend(struct device *dev);
  166. static int igb_runtime_resume(struct device *dev);
  167. static int igb_runtime_idle(struct device *dev);
  168. #endif
  169. static const struct dev_pm_ops igb_pm_ops = {
  170. SET_SYSTEM_SLEEP_PM_OPS(igb_suspend, igb_resume)
  171. SET_RUNTIME_PM_OPS(igb_runtime_suspend, igb_runtime_resume,
  172. igb_runtime_idle)
  173. };
  174. #endif
  175. static void igb_shutdown(struct pci_dev *);
  176. #ifdef CONFIG_IGB_DCA
  177. static int igb_notify_dca(struct notifier_block *, unsigned long, void *);
  178. static struct notifier_block dca_notifier = {
  179. .notifier_call = igb_notify_dca,
  180. .next = NULL,
  181. .priority = 0
  182. };
  183. #endif
  184. #ifdef CONFIG_NET_POLL_CONTROLLER
  185. /* for netdump / net console */
  186. static void igb_netpoll(struct net_device *);
  187. #endif
  188. #ifdef CONFIG_PCI_IOV
  189. static unsigned int max_vfs = 0;
  190. module_param(max_vfs, uint, 0);
  191. MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate "
  192. "per physical function");
  193. #endif /* CONFIG_PCI_IOV */
  194. static pci_ers_result_t igb_io_error_detected(struct pci_dev *,
  195. pci_channel_state_t);
  196. static pci_ers_result_t igb_io_slot_reset(struct pci_dev *);
  197. static void igb_io_resume(struct pci_dev *);
  198. static struct pci_error_handlers igb_err_handler = {
  199. .error_detected = igb_io_error_detected,
  200. .slot_reset = igb_io_slot_reset,
  201. .resume = igb_io_resume,
  202. };
  203. static void igb_init_dmac(struct igb_adapter *adapter, u32 pba);
  204. static struct pci_driver igb_driver = {
  205. .name = igb_driver_name,
  206. .id_table = igb_pci_tbl,
  207. .probe = igb_probe,
  208. .remove = __devexit_p(igb_remove),
  209. #ifdef CONFIG_PM
  210. .driver.pm = &igb_pm_ops,
  211. #endif
  212. .shutdown = igb_shutdown,
  213. .err_handler = &igb_err_handler
  214. };
  215. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  216. MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
  217. MODULE_LICENSE("GPL");
  218. MODULE_VERSION(DRV_VERSION);
  219. struct igb_reg_info {
  220. u32 ofs;
  221. char *name;
  222. };
  223. static const struct igb_reg_info igb_reg_info_tbl[] = {
  224. /* General Registers */
  225. {E1000_CTRL, "CTRL"},
  226. {E1000_STATUS, "STATUS"},
  227. {E1000_CTRL_EXT, "CTRL_EXT"},
  228. /* Interrupt Registers */
  229. {E1000_ICR, "ICR"},
  230. /* RX Registers */
  231. {E1000_RCTL, "RCTL"},
  232. {E1000_RDLEN(0), "RDLEN"},
  233. {E1000_RDH(0), "RDH"},
  234. {E1000_RDT(0), "RDT"},
  235. {E1000_RXDCTL(0), "RXDCTL"},
  236. {E1000_RDBAL(0), "RDBAL"},
  237. {E1000_RDBAH(0), "RDBAH"},
  238. /* TX Registers */
  239. {E1000_TCTL, "TCTL"},
  240. {E1000_TDBAL(0), "TDBAL"},
  241. {E1000_TDBAH(0), "TDBAH"},
  242. {E1000_TDLEN(0), "TDLEN"},
  243. {E1000_TDH(0), "TDH"},
  244. {E1000_TDT(0), "TDT"},
  245. {E1000_TXDCTL(0), "TXDCTL"},
  246. {E1000_TDFH, "TDFH"},
  247. {E1000_TDFT, "TDFT"},
  248. {E1000_TDFHS, "TDFHS"},
  249. {E1000_TDFPC, "TDFPC"},
  250. /* List Terminator */
  251. {}
  252. };
  253. /*
  254. * igb_regdump - register printout routine
  255. */
  256. static void igb_regdump(struct e1000_hw *hw, struct igb_reg_info *reginfo)
  257. {
  258. int n = 0;
  259. char rname[16];
  260. u32 regs[8];
  261. switch (reginfo->ofs) {
  262. case E1000_RDLEN(0):
  263. for (n = 0; n < 4; n++)
  264. regs[n] = rd32(E1000_RDLEN(n));
  265. break;
  266. case E1000_RDH(0):
  267. for (n = 0; n < 4; n++)
  268. regs[n] = rd32(E1000_RDH(n));
  269. break;
  270. case E1000_RDT(0):
  271. for (n = 0; n < 4; n++)
  272. regs[n] = rd32(E1000_RDT(n));
  273. break;
  274. case E1000_RXDCTL(0):
  275. for (n = 0; n < 4; n++)
  276. regs[n] = rd32(E1000_RXDCTL(n));
  277. break;
  278. case E1000_RDBAL(0):
  279. for (n = 0; n < 4; n++)
  280. regs[n] = rd32(E1000_RDBAL(n));
  281. break;
  282. case E1000_RDBAH(0):
  283. for (n = 0; n < 4; n++)
  284. regs[n] = rd32(E1000_RDBAH(n));
  285. break;
  286. case E1000_TDBAL(0):
  287. for (n = 0; n < 4; n++)
  288. regs[n] = rd32(E1000_RDBAL(n));
  289. break;
  290. case E1000_TDBAH(0):
  291. for (n = 0; n < 4; n++)
  292. regs[n] = rd32(E1000_TDBAH(n));
  293. break;
  294. case E1000_TDLEN(0):
  295. for (n = 0; n < 4; n++)
  296. regs[n] = rd32(E1000_TDLEN(n));
  297. break;
  298. case E1000_TDH(0):
  299. for (n = 0; n < 4; n++)
  300. regs[n] = rd32(E1000_TDH(n));
  301. break;
  302. case E1000_TDT(0):
  303. for (n = 0; n < 4; n++)
  304. regs[n] = rd32(E1000_TDT(n));
  305. break;
  306. case E1000_TXDCTL(0):
  307. for (n = 0; n < 4; n++)
  308. regs[n] = rd32(E1000_TXDCTL(n));
  309. break;
  310. default:
  311. pr_info("%-15s %08x\n", reginfo->name, rd32(reginfo->ofs));
  312. return;
  313. }
  314. snprintf(rname, 16, "%s%s", reginfo->name, "[0-3]");
  315. pr_info("%-15s %08x %08x %08x %08x\n", rname, regs[0], regs[1],
  316. regs[2], regs[3]);
  317. }
  318. /*
  319. * igb_dump - Print registers, tx-rings and rx-rings
  320. */
  321. static void igb_dump(struct igb_adapter *adapter)
  322. {
  323. struct net_device *netdev = adapter->netdev;
  324. struct e1000_hw *hw = &adapter->hw;
  325. struct igb_reg_info *reginfo;
  326. struct igb_ring *tx_ring;
  327. union e1000_adv_tx_desc *tx_desc;
  328. struct my_u0 { u64 a; u64 b; } *u0;
  329. struct igb_ring *rx_ring;
  330. union e1000_adv_rx_desc *rx_desc;
  331. u32 staterr;
  332. u16 i, n;
  333. if (!netif_msg_hw(adapter))
  334. return;
  335. /* Print netdevice Info */
  336. if (netdev) {
  337. dev_info(&adapter->pdev->dev, "Net device Info\n");
  338. pr_info("Device Name state trans_start "
  339. "last_rx\n");
  340. pr_info("%-15s %016lX %016lX %016lX\n", netdev->name,
  341. netdev->state, netdev->trans_start, netdev->last_rx);
  342. }
  343. /* Print Registers */
  344. dev_info(&adapter->pdev->dev, "Register Dump\n");
  345. pr_info(" Register Name Value\n");
  346. for (reginfo = (struct igb_reg_info *)igb_reg_info_tbl;
  347. reginfo->name; reginfo++) {
  348. igb_regdump(hw, reginfo);
  349. }
  350. /* Print TX Ring Summary */
  351. if (!netdev || !netif_running(netdev))
  352. goto exit;
  353. dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
  354. pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
  355. for (n = 0; n < adapter->num_tx_queues; n++) {
  356. struct igb_tx_buffer *buffer_info;
  357. tx_ring = adapter->tx_ring[n];
  358. buffer_info = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
  359. pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
  360. n, tx_ring->next_to_use, tx_ring->next_to_clean,
  361. (u64)buffer_info->dma,
  362. buffer_info->length,
  363. buffer_info->next_to_watch,
  364. (u64)buffer_info->time_stamp);
  365. }
  366. /* Print TX Rings */
  367. if (!netif_msg_tx_done(adapter))
  368. goto rx_ring_summary;
  369. dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
  370. /* Transmit Descriptor Formats
  371. *
  372. * Advanced Transmit Descriptor
  373. * +--------------------------------------------------------------+
  374. * 0 | Buffer Address [63:0] |
  375. * +--------------------------------------------------------------+
  376. * 8 | PAYLEN | PORTS |CC|IDX | STA | DCMD |DTYP|MAC|RSV| DTALEN |
  377. * +--------------------------------------------------------------+
  378. * 63 46 45 40 39 38 36 35 32 31 24 15 0
  379. */
  380. for (n = 0; n < adapter->num_tx_queues; n++) {
  381. tx_ring = adapter->tx_ring[n];
  382. pr_info("------------------------------------\n");
  383. pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
  384. pr_info("------------------------------------\n");
  385. pr_info("T [desc] [address 63:0 ] [PlPOCIStDDM Ln] "
  386. "[bi->dma ] leng ntw timestamp "
  387. "bi->skb\n");
  388. for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
  389. const char *next_desc;
  390. struct igb_tx_buffer *buffer_info;
  391. tx_desc = IGB_TX_DESC(tx_ring, i);
  392. buffer_info = &tx_ring->tx_buffer_info[i];
  393. u0 = (struct my_u0 *)tx_desc;
  394. if (i == tx_ring->next_to_use &&
  395. i == tx_ring->next_to_clean)
  396. next_desc = " NTC/U";
  397. else if (i == tx_ring->next_to_use)
  398. next_desc = " NTU";
  399. else if (i == tx_ring->next_to_clean)
  400. next_desc = " NTC";
  401. else
  402. next_desc = "";
  403. pr_info("T [0x%03X] %016llX %016llX %016llX"
  404. " %04X %p %016llX %p%s\n", i,
  405. le64_to_cpu(u0->a),
  406. le64_to_cpu(u0->b),
  407. (u64)buffer_info->dma,
  408. buffer_info->length,
  409. buffer_info->next_to_watch,
  410. (u64)buffer_info->time_stamp,
  411. buffer_info->skb, next_desc);
  412. if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
  413. print_hex_dump(KERN_INFO, "",
  414. DUMP_PREFIX_ADDRESS,
  415. 16, 1, phys_to_virt(buffer_info->dma),
  416. buffer_info->length, true);
  417. }
  418. }
  419. /* Print RX Rings Summary */
  420. rx_ring_summary:
  421. dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
  422. pr_info("Queue [NTU] [NTC]\n");
  423. for (n = 0; n < adapter->num_rx_queues; n++) {
  424. rx_ring = adapter->rx_ring[n];
  425. pr_info(" %5d %5X %5X\n",
  426. n, rx_ring->next_to_use, rx_ring->next_to_clean);
  427. }
  428. /* Print RX Rings */
  429. if (!netif_msg_rx_status(adapter))
  430. goto exit;
  431. dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
  432. /* Advanced Receive Descriptor (Read) Format
  433. * 63 1 0
  434. * +-----------------------------------------------------+
  435. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  436. * +----------------------------------------------+------+
  437. * 8 | Header Buffer Address [63:1] | DD |
  438. * +-----------------------------------------------------+
  439. *
  440. *
  441. * Advanced Receive Descriptor (Write-Back) Format
  442. *
  443. * 63 48 47 32 31 30 21 20 17 16 4 3 0
  444. * +------------------------------------------------------+
  445. * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
  446. * | Checksum Ident | | | | Type | Type |
  447. * +------------------------------------------------------+
  448. * 8 | VLAN Tag | Length | Extended Error | Extended Status |
  449. * +------------------------------------------------------+
  450. * 63 48 47 32 31 20 19 0
  451. */
  452. for (n = 0; n < adapter->num_rx_queues; n++) {
  453. rx_ring = adapter->rx_ring[n];
  454. pr_info("------------------------------------\n");
  455. pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
  456. pr_info("------------------------------------\n");
  457. pr_info("R [desc] [ PktBuf A0] [ HeadBuf DD] "
  458. "[bi->dma ] [bi->skb] <-- Adv Rx Read format\n");
  459. pr_info("RWB[desc] [PcsmIpSHl PtRs] [vl er S cks ln] -----"
  460. "----------- [bi->skb] <-- Adv Rx Write-Back format\n");
  461. for (i = 0; i < rx_ring->count; i++) {
  462. const char *next_desc;
  463. struct igb_rx_buffer *buffer_info;
  464. buffer_info = &rx_ring->rx_buffer_info[i];
  465. rx_desc = IGB_RX_DESC(rx_ring, i);
  466. u0 = (struct my_u0 *)rx_desc;
  467. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  468. if (i == rx_ring->next_to_use)
  469. next_desc = " NTU";
  470. else if (i == rx_ring->next_to_clean)
  471. next_desc = " NTC";
  472. else
  473. next_desc = "";
  474. if (staterr & E1000_RXD_STAT_DD) {
  475. /* Descriptor Done */
  476. pr_info("%s[0x%03X] %016llX %016llX -------"
  477. "--------- %p%s\n", "RWB", i,
  478. le64_to_cpu(u0->a),
  479. le64_to_cpu(u0->b),
  480. buffer_info->skb, next_desc);
  481. } else {
  482. pr_info("%s[0x%03X] %016llX %016llX %016llX"
  483. " %p%s\n", "R ", i,
  484. le64_to_cpu(u0->a),
  485. le64_to_cpu(u0->b),
  486. (u64)buffer_info->dma,
  487. buffer_info->skb, next_desc);
  488. if (netif_msg_pktdata(adapter)) {
  489. print_hex_dump(KERN_INFO, "",
  490. DUMP_PREFIX_ADDRESS,
  491. 16, 1,
  492. phys_to_virt(buffer_info->dma),
  493. IGB_RX_HDR_LEN, true);
  494. print_hex_dump(KERN_INFO, "",
  495. DUMP_PREFIX_ADDRESS,
  496. 16, 1,
  497. phys_to_virt(
  498. buffer_info->page_dma +
  499. buffer_info->page_offset),
  500. PAGE_SIZE/2, true);
  501. }
  502. }
  503. }
  504. }
  505. exit:
  506. return;
  507. }
  508. /**
  509. * igb_read_clock - read raw cycle counter (to be used by time counter)
  510. */
  511. static cycle_t igb_read_clock(const struct cyclecounter *tc)
  512. {
  513. struct igb_adapter *adapter =
  514. container_of(tc, struct igb_adapter, cycles);
  515. struct e1000_hw *hw = &adapter->hw;
  516. u64 stamp = 0;
  517. int shift = 0;
  518. /*
  519. * The timestamp latches on lowest register read. For the 82580
  520. * the lowest register is SYSTIMR instead of SYSTIML. However we never
  521. * adjusted TIMINCA so SYSTIMR will just read as all 0s so ignore it.
  522. */
  523. if (hw->mac.type >= e1000_82580) {
  524. stamp = rd32(E1000_SYSTIMR) >> 8;
  525. shift = IGB_82580_TSYNC_SHIFT;
  526. }
  527. stamp |= (u64)rd32(E1000_SYSTIML) << shift;
  528. stamp |= (u64)rd32(E1000_SYSTIMH) << (shift + 32);
  529. return stamp;
  530. }
  531. /**
  532. * igb_get_hw_dev - return device
  533. * used by hardware layer to print debugging information
  534. **/
  535. struct net_device *igb_get_hw_dev(struct e1000_hw *hw)
  536. {
  537. struct igb_adapter *adapter = hw->back;
  538. return adapter->netdev;
  539. }
  540. /**
  541. * igb_init_module - Driver Registration Routine
  542. *
  543. * igb_init_module is the first routine called when the driver is
  544. * loaded. All it does is register with the PCI subsystem.
  545. **/
  546. static int __init igb_init_module(void)
  547. {
  548. int ret;
  549. pr_info("%s - version %s\n",
  550. igb_driver_string, igb_driver_version);
  551. pr_info("%s\n", igb_copyright);
  552. #ifdef CONFIG_IGB_DCA
  553. dca_register_notify(&dca_notifier);
  554. #endif
  555. ret = pci_register_driver(&igb_driver);
  556. return ret;
  557. }
  558. module_init(igb_init_module);
  559. /**
  560. * igb_exit_module - Driver Exit Cleanup Routine
  561. *
  562. * igb_exit_module is called just before the driver is removed
  563. * from memory.
  564. **/
  565. static void __exit igb_exit_module(void)
  566. {
  567. #ifdef CONFIG_IGB_DCA
  568. dca_unregister_notify(&dca_notifier);
  569. #endif
  570. pci_unregister_driver(&igb_driver);
  571. }
  572. module_exit(igb_exit_module);
  573. #define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
  574. /**
  575. * igb_cache_ring_register - Descriptor ring to register mapping
  576. * @adapter: board private structure to initialize
  577. *
  578. * Once we know the feature-set enabled for the device, we'll cache
  579. * the register offset the descriptor ring is assigned to.
  580. **/
  581. static void igb_cache_ring_register(struct igb_adapter *adapter)
  582. {
  583. int i = 0, j = 0;
  584. u32 rbase_offset = adapter->vfs_allocated_count;
  585. switch (adapter->hw.mac.type) {
  586. case e1000_82576:
  587. /* The queues are allocated for virtualization such that VF 0
  588. * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
  589. * In order to avoid collision we start at the first free queue
  590. * and continue consuming queues in the same sequence
  591. */
  592. if (adapter->vfs_allocated_count) {
  593. for (; i < adapter->rss_queues; i++)
  594. adapter->rx_ring[i]->reg_idx = rbase_offset +
  595. Q_IDX_82576(i);
  596. }
  597. case e1000_82575:
  598. case e1000_82580:
  599. case e1000_i350:
  600. default:
  601. for (; i < adapter->num_rx_queues; i++)
  602. adapter->rx_ring[i]->reg_idx = rbase_offset + i;
  603. for (; j < adapter->num_tx_queues; j++)
  604. adapter->tx_ring[j]->reg_idx = rbase_offset + j;
  605. break;
  606. }
  607. }
  608. static void igb_free_queues(struct igb_adapter *adapter)
  609. {
  610. int i;
  611. for (i = 0; i < adapter->num_tx_queues; i++) {
  612. kfree(adapter->tx_ring[i]);
  613. adapter->tx_ring[i] = NULL;
  614. }
  615. for (i = 0; i < adapter->num_rx_queues; i++) {
  616. kfree(adapter->rx_ring[i]);
  617. adapter->rx_ring[i] = NULL;
  618. }
  619. adapter->num_rx_queues = 0;
  620. adapter->num_tx_queues = 0;
  621. }
  622. /**
  623. * igb_alloc_queues - Allocate memory for all rings
  624. * @adapter: board private structure to initialize
  625. *
  626. * We allocate one ring per queue at run-time since we don't know the
  627. * number of queues at compile-time.
  628. **/
  629. static int igb_alloc_queues(struct igb_adapter *adapter)
  630. {
  631. struct igb_ring *ring;
  632. int i;
  633. int orig_node = adapter->node;
  634. for (i = 0; i < adapter->num_tx_queues; i++) {
  635. if (orig_node == -1) {
  636. int cur_node = next_online_node(adapter->node);
  637. if (cur_node == MAX_NUMNODES)
  638. cur_node = first_online_node;
  639. adapter->node = cur_node;
  640. }
  641. ring = kzalloc_node(sizeof(struct igb_ring), GFP_KERNEL,
  642. adapter->node);
  643. if (!ring)
  644. ring = kzalloc(sizeof(struct igb_ring), GFP_KERNEL);
  645. if (!ring)
  646. goto err;
  647. ring->count = adapter->tx_ring_count;
  648. ring->queue_index = i;
  649. ring->dev = &adapter->pdev->dev;
  650. ring->netdev = adapter->netdev;
  651. ring->numa_node = adapter->node;
  652. /* For 82575, context index must be unique per ring. */
  653. if (adapter->hw.mac.type == e1000_82575)
  654. set_bit(IGB_RING_FLAG_TX_CTX_IDX, &ring->flags);
  655. adapter->tx_ring[i] = ring;
  656. }
  657. /* Restore the adapter's original node */
  658. adapter->node = orig_node;
  659. for (i = 0; i < adapter->num_rx_queues; i++) {
  660. if (orig_node == -1) {
  661. int cur_node = next_online_node(adapter->node);
  662. if (cur_node == MAX_NUMNODES)
  663. cur_node = first_online_node;
  664. adapter->node = cur_node;
  665. }
  666. ring = kzalloc_node(sizeof(struct igb_ring), GFP_KERNEL,
  667. adapter->node);
  668. if (!ring)
  669. ring = kzalloc(sizeof(struct igb_ring), GFP_KERNEL);
  670. if (!ring)
  671. goto err;
  672. ring->count = adapter->rx_ring_count;
  673. ring->queue_index = i;
  674. ring->dev = &adapter->pdev->dev;
  675. ring->netdev = adapter->netdev;
  676. ring->numa_node = adapter->node;
  677. /* set flag indicating ring supports SCTP checksum offload */
  678. if (adapter->hw.mac.type >= e1000_82576)
  679. set_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags);
  680. /* On i350, loopback VLAN packets have the tag byte-swapped. */
  681. if (adapter->hw.mac.type == e1000_i350)
  682. set_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &ring->flags);
  683. adapter->rx_ring[i] = ring;
  684. }
  685. /* Restore the adapter's original node */
  686. adapter->node = orig_node;
  687. igb_cache_ring_register(adapter);
  688. return 0;
  689. err:
  690. /* Restore the adapter's original node */
  691. adapter->node = orig_node;
  692. igb_free_queues(adapter);
  693. return -ENOMEM;
  694. }
  695. /**
  696. * igb_write_ivar - configure ivar for given MSI-X vector
  697. * @hw: pointer to the HW structure
  698. * @msix_vector: vector number we are allocating to a given ring
  699. * @index: row index of IVAR register to write within IVAR table
  700. * @offset: column offset of in IVAR, should be multiple of 8
  701. *
  702. * This function is intended to handle the writing of the IVAR register
  703. * for adapters 82576 and newer. The IVAR table consists of 2 columns,
  704. * each containing an cause allocation for an Rx and Tx ring, and a
  705. * variable number of rows depending on the number of queues supported.
  706. **/
  707. static void igb_write_ivar(struct e1000_hw *hw, int msix_vector,
  708. int index, int offset)
  709. {
  710. u32 ivar = array_rd32(E1000_IVAR0, index);
  711. /* clear any bits that are currently set */
  712. ivar &= ~((u32)0xFF << offset);
  713. /* write vector and valid bit */
  714. ivar |= (msix_vector | E1000_IVAR_VALID) << offset;
  715. array_wr32(E1000_IVAR0, index, ivar);
  716. }
  717. #define IGB_N0_QUEUE -1
  718. static void igb_assign_vector(struct igb_q_vector *q_vector, int msix_vector)
  719. {
  720. struct igb_adapter *adapter = q_vector->adapter;
  721. struct e1000_hw *hw = &adapter->hw;
  722. int rx_queue = IGB_N0_QUEUE;
  723. int tx_queue = IGB_N0_QUEUE;
  724. u32 msixbm = 0;
  725. if (q_vector->rx.ring)
  726. rx_queue = q_vector->rx.ring->reg_idx;
  727. if (q_vector->tx.ring)
  728. tx_queue = q_vector->tx.ring->reg_idx;
  729. switch (hw->mac.type) {
  730. case e1000_82575:
  731. /* The 82575 assigns vectors using a bitmask, which matches the
  732. bitmask for the EICR/EIMS/EIMC registers. To assign one
  733. or more queues to a vector, we write the appropriate bits
  734. into the MSIXBM register for that vector. */
  735. if (rx_queue > IGB_N0_QUEUE)
  736. msixbm = E1000_EICR_RX_QUEUE0 << rx_queue;
  737. if (tx_queue > IGB_N0_QUEUE)
  738. msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue;
  739. if (!adapter->msix_entries && msix_vector == 0)
  740. msixbm |= E1000_EIMS_OTHER;
  741. array_wr32(E1000_MSIXBM(0), msix_vector, msixbm);
  742. q_vector->eims_value = msixbm;
  743. break;
  744. case e1000_82576:
  745. /*
  746. * 82576 uses a table that essentially consists of 2 columns
  747. * with 8 rows. The ordering is column-major so we use the
  748. * lower 3 bits as the row index, and the 4th bit as the
  749. * column offset.
  750. */
  751. if (rx_queue > IGB_N0_QUEUE)
  752. igb_write_ivar(hw, msix_vector,
  753. rx_queue & 0x7,
  754. (rx_queue & 0x8) << 1);
  755. if (tx_queue > IGB_N0_QUEUE)
  756. igb_write_ivar(hw, msix_vector,
  757. tx_queue & 0x7,
  758. ((tx_queue & 0x8) << 1) + 8);
  759. q_vector->eims_value = 1 << msix_vector;
  760. break;
  761. case e1000_82580:
  762. case e1000_i350:
  763. /*
  764. * On 82580 and newer adapters the scheme is similar to 82576
  765. * however instead of ordering column-major we have things
  766. * ordered row-major. So we traverse the table by using
  767. * bit 0 as the column offset, and the remaining bits as the
  768. * row index.
  769. */
  770. if (rx_queue > IGB_N0_QUEUE)
  771. igb_write_ivar(hw, msix_vector,
  772. rx_queue >> 1,
  773. (rx_queue & 0x1) << 4);
  774. if (tx_queue > IGB_N0_QUEUE)
  775. igb_write_ivar(hw, msix_vector,
  776. tx_queue >> 1,
  777. ((tx_queue & 0x1) << 4) + 8);
  778. q_vector->eims_value = 1 << msix_vector;
  779. break;
  780. default:
  781. BUG();
  782. break;
  783. }
  784. /* add q_vector eims value to global eims_enable_mask */
  785. adapter->eims_enable_mask |= q_vector->eims_value;
  786. /* configure q_vector to set itr on first interrupt */
  787. q_vector->set_itr = 1;
  788. }
  789. /**
  790. * igb_configure_msix - Configure MSI-X hardware
  791. *
  792. * igb_configure_msix sets up the hardware to properly
  793. * generate MSI-X interrupts.
  794. **/
  795. static void igb_configure_msix(struct igb_adapter *adapter)
  796. {
  797. u32 tmp;
  798. int i, vector = 0;
  799. struct e1000_hw *hw = &adapter->hw;
  800. adapter->eims_enable_mask = 0;
  801. /* set vector for other causes, i.e. link changes */
  802. switch (hw->mac.type) {
  803. case e1000_82575:
  804. tmp = rd32(E1000_CTRL_EXT);
  805. /* enable MSI-X PBA support*/
  806. tmp |= E1000_CTRL_EXT_PBA_CLR;
  807. /* Auto-Mask interrupts upon ICR read. */
  808. tmp |= E1000_CTRL_EXT_EIAME;
  809. tmp |= E1000_CTRL_EXT_IRCA;
  810. wr32(E1000_CTRL_EXT, tmp);
  811. /* enable msix_other interrupt */
  812. array_wr32(E1000_MSIXBM(0), vector++,
  813. E1000_EIMS_OTHER);
  814. adapter->eims_other = E1000_EIMS_OTHER;
  815. break;
  816. case e1000_82576:
  817. case e1000_82580:
  818. case e1000_i350:
  819. /* Turn on MSI-X capability first, or our settings
  820. * won't stick. And it will take days to debug. */
  821. wr32(E1000_GPIE, E1000_GPIE_MSIX_MODE |
  822. E1000_GPIE_PBA | E1000_GPIE_EIAME |
  823. E1000_GPIE_NSICR);
  824. /* enable msix_other interrupt */
  825. adapter->eims_other = 1 << vector;
  826. tmp = (vector++ | E1000_IVAR_VALID) << 8;
  827. wr32(E1000_IVAR_MISC, tmp);
  828. break;
  829. default:
  830. /* do nothing, since nothing else supports MSI-X */
  831. break;
  832. } /* switch (hw->mac.type) */
  833. adapter->eims_enable_mask |= adapter->eims_other;
  834. for (i = 0; i < adapter->num_q_vectors; i++)
  835. igb_assign_vector(adapter->q_vector[i], vector++);
  836. wrfl();
  837. }
  838. /**
  839. * igb_request_msix - Initialize MSI-X interrupts
  840. *
  841. * igb_request_msix allocates MSI-X vectors and requests interrupts from the
  842. * kernel.
  843. **/
  844. static int igb_request_msix(struct igb_adapter *adapter)
  845. {
  846. struct net_device *netdev = adapter->netdev;
  847. struct e1000_hw *hw = &adapter->hw;
  848. int i, err = 0, vector = 0;
  849. err = request_irq(adapter->msix_entries[vector].vector,
  850. igb_msix_other, 0, netdev->name, adapter);
  851. if (err)
  852. goto out;
  853. vector++;
  854. for (i = 0; i < adapter->num_q_vectors; i++) {
  855. struct igb_q_vector *q_vector = adapter->q_vector[i];
  856. q_vector->itr_register = hw->hw_addr + E1000_EITR(vector);
  857. if (q_vector->rx.ring && q_vector->tx.ring)
  858. sprintf(q_vector->name, "%s-TxRx-%u", netdev->name,
  859. q_vector->rx.ring->queue_index);
  860. else if (q_vector->tx.ring)
  861. sprintf(q_vector->name, "%s-tx-%u", netdev->name,
  862. q_vector->tx.ring->queue_index);
  863. else if (q_vector->rx.ring)
  864. sprintf(q_vector->name, "%s-rx-%u", netdev->name,
  865. q_vector->rx.ring->queue_index);
  866. else
  867. sprintf(q_vector->name, "%s-unused", netdev->name);
  868. err = request_irq(adapter->msix_entries[vector].vector,
  869. igb_msix_ring, 0, q_vector->name,
  870. q_vector);
  871. if (err)
  872. goto out;
  873. vector++;
  874. }
  875. igb_configure_msix(adapter);
  876. return 0;
  877. out:
  878. return err;
  879. }
  880. static void igb_reset_interrupt_capability(struct igb_adapter *adapter)
  881. {
  882. if (adapter->msix_entries) {
  883. pci_disable_msix(adapter->pdev);
  884. kfree(adapter->msix_entries);
  885. adapter->msix_entries = NULL;
  886. } else if (adapter->flags & IGB_FLAG_HAS_MSI) {
  887. pci_disable_msi(adapter->pdev);
  888. }
  889. }
  890. /**
  891. * igb_free_q_vectors - Free memory allocated for interrupt vectors
  892. * @adapter: board private structure to initialize
  893. *
  894. * This function frees the memory allocated to the q_vectors. In addition if
  895. * NAPI is enabled it will delete any references to the NAPI struct prior
  896. * to freeing the q_vector.
  897. **/
  898. static void igb_free_q_vectors(struct igb_adapter *adapter)
  899. {
  900. int v_idx;
  901. for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
  902. struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
  903. adapter->q_vector[v_idx] = NULL;
  904. if (!q_vector)
  905. continue;
  906. netif_napi_del(&q_vector->napi);
  907. kfree(q_vector);
  908. }
  909. adapter->num_q_vectors = 0;
  910. }
  911. /**
  912. * igb_clear_interrupt_scheme - reset the device to a state of no interrupts
  913. *
  914. * This function resets the device so that it has 0 rx queues, tx queues, and
  915. * MSI-X interrupts allocated.
  916. */
  917. static void igb_clear_interrupt_scheme(struct igb_adapter *adapter)
  918. {
  919. igb_free_queues(adapter);
  920. igb_free_q_vectors(adapter);
  921. igb_reset_interrupt_capability(adapter);
  922. }
  923. /**
  924. * igb_set_interrupt_capability - set MSI or MSI-X if supported
  925. *
  926. * Attempt to configure interrupts using the best available
  927. * capabilities of the hardware and kernel.
  928. **/
  929. static int igb_set_interrupt_capability(struct igb_adapter *adapter)
  930. {
  931. int err;
  932. int numvecs, i;
  933. /* Number of supported queues. */
  934. adapter->num_rx_queues = adapter->rss_queues;
  935. if (adapter->vfs_allocated_count)
  936. adapter->num_tx_queues = 1;
  937. else
  938. adapter->num_tx_queues = adapter->rss_queues;
  939. /* start with one vector for every rx queue */
  940. numvecs = adapter->num_rx_queues;
  941. /* if tx handler is separate add 1 for every tx queue */
  942. if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS))
  943. numvecs += adapter->num_tx_queues;
  944. /* store the number of vectors reserved for queues */
  945. adapter->num_q_vectors = numvecs;
  946. /* add 1 vector for link status interrupts */
  947. numvecs++;
  948. adapter->msix_entries = kcalloc(numvecs, sizeof(struct msix_entry),
  949. GFP_KERNEL);
  950. if (!adapter->msix_entries)
  951. goto msi_only;
  952. for (i = 0; i < numvecs; i++)
  953. adapter->msix_entries[i].entry = i;
  954. err = pci_enable_msix(adapter->pdev,
  955. adapter->msix_entries,
  956. numvecs);
  957. if (err == 0)
  958. goto out;
  959. igb_reset_interrupt_capability(adapter);
  960. /* If we can't do MSI-X, try MSI */
  961. msi_only:
  962. #ifdef CONFIG_PCI_IOV
  963. /* disable SR-IOV for non MSI-X configurations */
  964. if (adapter->vf_data) {
  965. struct e1000_hw *hw = &adapter->hw;
  966. /* disable iov and allow time for transactions to clear */
  967. pci_disable_sriov(adapter->pdev);
  968. msleep(500);
  969. kfree(adapter->vf_data);
  970. adapter->vf_data = NULL;
  971. wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
  972. wrfl();
  973. msleep(100);
  974. dev_info(&adapter->pdev->dev, "IOV Disabled\n");
  975. }
  976. #endif
  977. adapter->vfs_allocated_count = 0;
  978. adapter->rss_queues = 1;
  979. adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
  980. adapter->num_rx_queues = 1;
  981. adapter->num_tx_queues = 1;
  982. adapter->num_q_vectors = 1;
  983. if (!pci_enable_msi(adapter->pdev))
  984. adapter->flags |= IGB_FLAG_HAS_MSI;
  985. out:
  986. /* Notify the stack of the (possibly) reduced queue counts. */
  987. netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
  988. return netif_set_real_num_rx_queues(adapter->netdev,
  989. adapter->num_rx_queues);
  990. }
  991. /**
  992. * igb_alloc_q_vectors - Allocate memory for interrupt vectors
  993. * @adapter: board private structure to initialize
  994. *
  995. * We allocate one q_vector per queue interrupt. If allocation fails we
  996. * return -ENOMEM.
  997. **/
  998. static int igb_alloc_q_vectors(struct igb_adapter *adapter)
  999. {
  1000. struct igb_q_vector *q_vector;
  1001. struct e1000_hw *hw = &adapter->hw;
  1002. int v_idx;
  1003. int orig_node = adapter->node;
  1004. for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
  1005. if ((adapter->num_q_vectors == (adapter->num_rx_queues +
  1006. adapter->num_tx_queues)) &&
  1007. (adapter->num_rx_queues == v_idx))
  1008. adapter->node = orig_node;
  1009. if (orig_node == -1) {
  1010. int cur_node = next_online_node(adapter->node);
  1011. if (cur_node == MAX_NUMNODES)
  1012. cur_node = first_online_node;
  1013. adapter->node = cur_node;
  1014. }
  1015. q_vector = kzalloc_node(sizeof(struct igb_q_vector), GFP_KERNEL,
  1016. adapter->node);
  1017. if (!q_vector)
  1018. q_vector = kzalloc(sizeof(struct igb_q_vector),
  1019. GFP_KERNEL);
  1020. if (!q_vector)
  1021. goto err_out;
  1022. q_vector->adapter = adapter;
  1023. q_vector->itr_register = hw->hw_addr + E1000_EITR(0);
  1024. q_vector->itr_val = IGB_START_ITR;
  1025. netif_napi_add(adapter->netdev, &q_vector->napi, igb_poll, 64);
  1026. adapter->q_vector[v_idx] = q_vector;
  1027. }
  1028. /* Restore the adapter's original node */
  1029. adapter->node = orig_node;
  1030. return 0;
  1031. err_out:
  1032. /* Restore the adapter's original node */
  1033. adapter->node = orig_node;
  1034. igb_free_q_vectors(adapter);
  1035. return -ENOMEM;
  1036. }
  1037. static void igb_map_rx_ring_to_vector(struct igb_adapter *adapter,
  1038. int ring_idx, int v_idx)
  1039. {
  1040. struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
  1041. q_vector->rx.ring = adapter->rx_ring[ring_idx];
  1042. q_vector->rx.ring->q_vector = q_vector;
  1043. q_vector->rx.count++;
  1044. q_vector->itr_val = adapter->rx_itr_setting;
  1045. if (q_vector->itr_val && q_vector->itr_val <= 3)
  1046. q_vector->itr_val = IGB_START_ITR;
  1047. }
  1048. static void igb_map_tx_ring_to_vector(struct igb_adapter *adapter,
  1049. int ring_idx, int v_idx)
  1050. {
  1051. struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
  1052. q_vector->tx.ring = adapter->tx_ring[ring_idx];
  1053. q_vector->tx.ring->q_vector = q_vector;
  1054. q_vector->tx.count++;
  1055. q_vector->itr_val = adapter->tx_itr_setting;
  1056. q_vector->tx.work_limit = adapter->tx_work_limit;
  1057. if (q_vector->itr_val && q_vector->itr_val <= 3)
  1058. q_vector->itr_val = IGB_START_ITR;
  1059. }
  1060. /**
  1061. * igb_map_ring_to_vector - maps allocated queues to vectors
  1062. *
  1063. * This function maps the recently allocated queues to vectors.
  1064. **/
  1065. static int igb_map_ring_to_vector(struct igb_adapter *adapter)
  1066. {
  1067. int i;
  1068. int v_idx = 0;
  1069. if ((adapter->num_q_vectors < adapter->num_rx_queues) ||
  1070. (adapter->num_q_vectors < adapter->num_tx_queues))
  1071. return -ENOMEM;
  1072. if (adapter->num_q_vectors >=
  1073. (adapter->num_rx_queues + adapter->num_tx_queues)) {
  1074. for (i = 0; i < adapter->num_rx_queues; i++)
  1075. igb_map_rx_ring_to_vector(adapter, i, v_idx++);
  1076. for (i = 0; i < adapter->num_tx_queues; i++)
  1077. igb_map_tx_ring_to_vector(adapter, i, v_idx++);
  1078. } else {
  1079. for (i = 0; i < adapter->num_rx_queues; i++) {
  1080. if (i < adapter->num_tx_queues)
  1081. igb_map_tx_ring_to_vector(adapter, i, v_idx);
  1082. igb_map_rx_ring_to_vector(adapter, i, v_idx++);
  1083. }
  1084. for (; i < adapter->num_tx_queues; i++)
  1085. igb_map_tx_ring_to_vector(adapter, i, v_idx++);
  1086. }
  1087. return 0;
  1088. }
  1089. /**
  1090. * igb_init_interrupt_scheme - initialize interrupts, allocate queues/vectors
  1091. *
  1092. * This function initializes the interrupts and allocates all of the queues.
  1093. **/
  1094. static int igb_init_interrupt_scheme(struct igb_adapter *adapter)
  1095. {
  1096. struct pci_dev *pdev = adapter->pdev;
  1097. int err;
  1098. err = igb_set_interrupt_capability(adapter);
  1099. if (err)
  1100. return err;
  1101. err = igb_alloc_q_vectors(adapter);
  1102. if (err) {
  1103. dev_err(&pdev->dev, "Unable to allocate memory for vectors\n");
  1104. goto err_alloc_q_vectors;
  1105. }
  1106. err = igb_alloc_queues(adapter);
  1107. if (err) {
  1108. dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
  1109. goto err_alloc_queues;
  1110. }
  1111. err = igb_map_ring_to_vector(adapter);
  1112. if (err) {
  1113. dev_err(&pdev->dev, "Invalid q_vector to ring mapping\n");
  1114. goto err_map_queues;
  1115. }
  1116. return 0;
  1117. err_map_queues:
  1118. igb_free_queues(adapter);
  1119. err_alloc_queues:
  1120. igb_free_q_vectors(adapter);
  1121. err_alloc_q_vectors:
  1122. igb_reset_interrupt_capability(adapter);
  1123. return err;
  1124. }
  1125. /**
  1126. * igb_request_irq - initialize interrupts
  1127. *
  1128. * Attempts to configure interrupts using the best available
  1129. * capabilities of the hardware and kernel.
  1130. **/
  1131. static int igb_request_irq(struct igb_adapter *adapter)
  1132. {
  1133. struct net_device *netdev = adapter->netdev;
  1134. struct pci_dev *pdev = adapter->pdev;
  1135. int err = 0;
  1136. if (adapter->msix_entries) {
  1137. err = igb_request_msix(adapter);
  1138. if (!err)
  1139. goto request_done;
  1140. /* fall back to MSI */
  1141. igb_clear_interrupt_scheme(adapter);
  1142. if (!pci_enable_msi(pdev))
  1143. adapter->flags |= IGB_FLAG_HAS_MSI;
  1144. igb_free_all_tx_resources(adapter);
  1145. igb_free_all_rx_resources(adapter);
  1146. adapter->num_tx_queues = 1;
  1147. adapter->num_rx_queues = 1;
  1148. adapter->num_q_vectors = 1;
  1149. err = igb_alloc_q_vectors(adapter);
  1150. if (err) {
  1151. dev_err(&pdev->dev,
  1152. "Unable to allocate memory for vectors\n");
  1153. goto request_done;
  1154. }
  1155. err = igb_alloc_queues(adapter);
  1156. if (err) {
  1157. dev_err(&pdev->dev,
  1158. "Unable to allocate memory for queues\n");
  1159. igb_free_q_vectors(adapter);
  1160. goto request_done;
  1161. }
  1162. igb_setup_all_tx_resources(adapter);
  1163. igb_setup_all_rx_resources(adapter);
  1164. }
  1165. igb_assign_vector(adapter->q_vector[0], 0);
  1166. if (adapter->flags & IGB_FLAG_HAS_MSI) {
  1167. err = request_irq(pdev->irq, igb_intr_msi, 0,
  1168. netdev->name, adapter);
  1169. if (!err)
  1170. goto request_done;
  1171. /* fall back to legacy interrupts */
  1172. igb_reset_interrupt_capability(adapter);
  1173. adapter->flags &= ~IGB_FLAG_HAS_MSI;
  1174. }
  1175. err = request_irq(pdev->irq, igb_intr, IRQF_SHARED,
  1176. netdev->name, adapter);
  1177. if (err)
  1178. dev_err(&pdev->dev, "Error %d getting interrupt\n",
  1179. err);
  1180. request_done:
  1181. return err;
  1182. }
  1183. static void igb_free_irq(struct igb_adapter *adapter)
  1184. {
  1185. if (adapter->msix_entries) {
  1186. int vector = 0, i;
  1187. free_irq(adapter->msix_entries[vector++].vector, adapter);
  1188. for (i = 0; i < adapter->num_q_vectors; i++)
  1189. free_irq(adapter->msix_entries[vector++].vector,
  1190. adapter->q_vector[i]);
  1191. } else {
  1192. free_irq(adapter->pdev->irq, adapter);
  1193. }
  1194. }
  1195. /**
  1196. * igb_irq_disable - Mask off interrupt generation on the NIC
  1197. * @adapter: board private structure
  1198. **/
  1199. static void igb_irq_disable(struct igb_adapter *adapter)
  1200. {
  1201. struct e1000_hw *hw = &adapter->hw;
  1202. /*
  1203. * we need to be careful when disabling interrupts. The VFs are also
  1204. * mapped into these registers and so clearing the bits can cause
  1205. * issues on the VF drivers so we only need to clear what we set
  1206. */
  1207. if (adapter->msix_entries) {
  1208. u32 regval = rd32(E1000_EIAM);
  1209. wr32(E1000_EIAM, regval & ~adapter->eims_enable_mask);
  1210. wr32(E1000_EIMC, adapter->eims_enable_mask);
  1211. regval = rd32(E1000_EIAC);
  1212. wr32(E1000_EIAC, regval & ~adapter->eims_enable_mask);
  1213. }
  1214. wr32(E1000_IAM, 0);
  1215. wr32(E1000_IMC, ~0);
  1216. wrfl();
  1217. if (adapter->msix_entries) {
  1218. int i;
  1219. for (i = 0; i < adapter->num_q_vectors; i++)
  1220. synchronize_irq(adapter->msix_entries[i].vector);
  1221. } else {
  1222. synchronize_irq(adapter->pdev->irq);
  1223. }
  1224. }
  1225. /**
  1226. * igb_irq_enable - Enable default interrupt generation settings
  1227. * @adapter: board private structure
  1228. **/
  1229. static void igb_irq_enable(struct igb_adapter *adapter)
  1230. {
  1231. struct e1000_hw *hw = &adapter->hw;
  1232. if (adapter->msix_entries) {
  1233. u32 ims = E1000_IMS_LSC | E1000_IMS_DOUTSYNC | E1000_IMS_DRSTA;
  1234. u32 regval = rd32(E1000_EIAC);
  1235. wr32(E1000_EIAC, regval | adapter->eims_enable_mask);
  1236. regval = rd32(E1000_EIAM);
  1237. wr32(E1000_EIAM, regval | adapter->eims_enable_mask);
  1238. wr32(E1000_EIMS, adapter->eims_enable_mask);
  1239. if (adapter->vfs_allocated_count) {
  1240. wr32(E1000_MBVFIMR, 0xFF);
  1241. ims |= E1000_IMS_VMMB;
  1242. }
  1243. wr32(E1000_IMS, ims);
  1244. } else {
  1245. wr32(E1000_IMS, IMS_ENABLE_MASK |
  1246. E1000_IMS_DRSTA);
  1247. wr32(E1000_IAM, IMS_ENABLE_MASK |
  1248. E1000_IMS_DRSTA);
  1249. }
  1250. }
  1251. static void igb_update_mng_vlan(struct igb_adapter *adapter)
  1252. {
  1253. struct e1000_hw *hw = &adapter->hw;
  1254. u16 vid = adapter->hw.mng_cookie.vlan_id;
  1255. u16 old_vid = adapter->mng_vlan_id;
  1256. if (hw->mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
  1257. /* add VID to filter table */
  1258. igb_vfta_set(hw, vid, true);
  1259. adapter->mng_vlan_id = vid;
  1260. } else {
  1261. adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
  1262. }
  1263. if ((old_vid != (u16)IGB_MNG_VLAN_NONE) &&
  1264. (vid != old_vid) &&
  1265. !test_bit(old_vid, adapter->active_vlans)) {
  1266. /* remove VID from filter table */
  1267. igb_vfta_set(hw, old_vid, false);
  1268. }
  1269. }
  1270. /**
  1271. * igb_release_hw_control - release control of the h/w to f/w
  1272. * @adapter: address of board private structure
  1273. *
  1274. * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
  1275. * For ASF and Pass Through versions of f/w this means that the
  1276. * driver is no longer loaded.
  1277. *
  1278. **/
  1279. static void igb_release_hw_control(struct igb_adapter *adapter)
  1280. {
  1281. struct e1000_hw *hw = &adapter->hw;
  1282. u32 ctrl_ext;
  1283. /* Let firmware take over control of h/w */
  1284. ctrl_ext = rd32(E1000_CTRL_EXT);
  1285. wr32(E1000_CTRL_EXT,
  1286. ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
  1287. }
  1288. /**
  1289. * igb_get_hw_control - get control of the h/w from f/w
  1290. * @adapter: address of board private structure
  1291. *
  1292. * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
  1293. * For ASF and Pass Through versions of f/w this means that
  1294. * the driver is loaded.
  1295. *
  1296. **/
  1297. static void igb_get_hw_control(struct igb_adapter *adapter)
  1298. {
  1299. struct e1000_hw *hw = &adapter->hw;
  1300. u32 ctrl_ext;
  1301. /* Let firmware know the driver has taken over */
  1302. ctrl_ext = rd32(E1000_CTRL_EXT);
  1303. wr32(E1000_CTRL_EXT,
  1304. ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
  1305. }
  1306. /**
  1307. * igb_configure - configure the hardware for RX and TX
  1308. * @adapter: private board structure
  1309. **/
  1310. static void igb_configure(struct igb_adapter *adapter)
  1311. {
  1312. struct net_device *netdev = adapter->netdev;
  1313. int i;
  1314. igb_get_hw_control(adapter);
  1315. igb_set_rx_mode(netdev);
  1316. igb_restore_vlan(adapter);
  1317. igb_setup_tctl(adapter);
  1318. igb_setup_mrqc(adapter);
  1319. igb_setup_rctl(adapter);
  1320. igb_configure_tx(adapter);
  1321. igb_configure_rx(adapter);
  1322. igb_rx_fifo_flush_82575(&adapter->hw);
  1323. /* call igb_desc_unused which always leaves
  1324. * at least 1 descriptor unused to make sure
  1325. * next_to_use != next_to_clean */
  1326. for (i = 0; i < adapter->num_rx_queues; i++) {
  1327. struct igb_ring *ring = adapter->rx_ring[i];
  1328. igb_alloc_rx_buffers(ring, igb_desc_unused(ring));
  1329. }
  1330. }
  1331. /**
  1332. * igb_power_up_link - Power up the phy/serdes link
  1333. * @adapter: address of board private structure
  1334. **/
  1335. void igb_power_up_link(struct igb_adapter *adapter)
  1336. {
  1337. if (adapter->hw.phy.media_type == e1000_media_type_copper)
  1338. igb_power_up_phy_copper(&adapter->hw);
  1339. else
  1340. igb_power_up_serdes_link_82575(&adapter->hw);
  1341. igb_reset_phy(&adapter->hw);
  1342. }
  1343. /**
  1344. * igb_power_down_link - Power down the phy/serdes link
  1345. * @adapter: address of board private structure
  1346. */
  1347. static void igb_power_down_link(struct igb_adapter *adapter)
  1348. {
  1349. if (adapter->hw.phy.media_type == e1000_media_type_copper)
  1350. igb_power_down_phy_copper_82575(&adapter->hw);
  1351. else
  1352. igb_shutdown_serdes_link_82575(&adapter->hw);
  1353. }
  1354. /**
  1355. * igb_up - Open the interface and prepare it to handle traffic
  1356. * @adapter: board private structure
  1357. **/
  1358. int igb_up(struct igb_adapter *adapter)
  1359. {
  1360. struct e1000_hw *hw = &adapter->hw;
  1361. int i;
  1362. /* hardware has been reset, we need to reload some things */
  1363. igb_configure(adapter);
  1364. clear_bit(__IGB_DOWN, &adapter->state);
  1365. for (i = 0; i < adapter->num_q_vectors; i++)
  1366. napi_enable(&(adapter->q_vector[i]->napi));
  1367. if (adapter->msix_entries)
  1368. igb_configure_msix(adapter);
  1369. else
  1370. igb_assign_vector(adapter->q_vector[0], 0);
  1371. /* Clear any pending interrupts. */
  1372. rd32(E1000_ICR);
  1373. igb_irq_enable(adapter);
  1374. /* notify VFs that reset has been completed */
  1375. if (adapter->vfs_allocated_count) {
  1376. u32 reg_data = rd32(E1000_CTRL_EXT);
  1377. reg_data |= E1000_CTRL_EXT_PFRSTD;
  1378. wr32(E1000_CTRL_EXT, reg_data);
  1379. }
  1380. netif_tx_start_all_queues(adapter->netdev);
  1381. /* start the watchdog. */
  1382. hw->mac.get_link_status = 1;
  1383. schedule_work(&adapter->watchdog_task);
  1384. return 0;
  1385. }
  1386. void igb_down(struct igb_adapter *adapter)
  1387. {
  1388. struct net_device *netdev = adapter->netdev;
  1389. struct e1000_hw *hw = &adapter->hw;
  1390. u32 tctl, rctl;
  1391. int i;
  1392. /* signal that we're down so the interrupt handler does not
  1393. * reschedule our watchdog timer */
  1394. set_bit(__IGB_DOWN, &adapter->state);
  1395. /* disable receives in the hardware */
  1396. rctl = rd32(E1000_RCTL);
  1397. wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
  1398. /* flush and sleep below */
  1399. netif_tx_stop_all_queues(netdev);
  1400. /* disable transmits in the hardware */
  1401. tctl = rd32(E1000_TCTL);
  1402. tctl &= ~E1000_TCTL_EN;
  1403. wr32(E1000_TCTL, tctl);
  1404. /* flush both disables and wait for them to finish */
  1405. wrfl();
  1406. msleep(10);
  1407. for (i = 0; i < adapter->num_q_vectors; i++)
  1408. napi_disable(&(adapter->q_vector[i]->napi));
  1409. igb_irq_disable(adapter);
  1410. del_timer_sync(&adapter->watchdog_timer);
  1411. del_timer_sync(&adapter->phy_info_timer);
  1412. netif_carrier_off(netdev);
  1413. /* record the stats before reset*/
  1414. spin_lock(&adapter->stats64_lock);
  1415. igb_update_stats(adapter, &adapter->stats64);
  1416. spin_unlock(&adapter->stats64_lock);
  1417. adapter->link_speed = 0;
  1418. adapter->link_duplex = 0;
  1419. if (!pci_channel_offline(adapter->pdev))
  1420. igb_reset(adapter);
  1421. igb_clean_all_tx_rings(adapter);
  1422. igb_clean_all_rx_rings(adapter);
  1423. #ifdef CONFIG_IGB_DCA
  1424. /* since we reset the hardware DCA settings were cleared */
  1425. igb_setup_dca(adapter);
  1426. #endif
  1427. }
  1428. void igb_reinit_locked(struct igb_adapter *adapter)
  1429. {
  1430. WARN_ON(in_interrupt());
  1431. while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
  1432. msleep(1);
  1433. igb_down(adapter);
  1434. igb_up(adapter);
  1435. clear_bit(__IGB_RESETTING, &adapter->state);
  1436. }
  1437. void igb_reset(struct igb_adapter *adapter)
  1438. {
  1439. struct pci_dev *pdev = adapter->pdev;
  1440. struct e1000_hw *hw = &adapter->hw;
  1441. struct e1000_mac_info *mac = &hw->mac;
  1442. struct e1000_fc_info *fc = &hw->fc;
  1443. u32 pba = 0, tx_space, min_tx_space, min_rx_space;
  1444. u16 hwm;
  1445. /* Repartition Pba for greater than 9k mtu
  1446. * To take effect CTRL.RST is required.
  1447. */
  1448. switch (mac->type) {
  1449. case e1000_i350:
  1450. case e1000_82580:
  1451. pba = rd32(E1000_RXPBS);
  1452. pba = igb_rxpbs_adjust_82580(pba);
  1453. break;
  1454. case e1000_82576:
  1455. pba = rd32(E1000_RXPBS);
  1456. pba &= E1000_RXPBS_SIZE_MASK_82576;
  1457. break;
  1458. case e1000_82575:
  1459. default:
  1460. pba = E1000_PBA_34K;
  1461. break;
  1462. }
  1463. if ((adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) &&
  1464. (mac->type < e1000_82576)) {
  1465. /* adjust PBA for jumbo frames */
  1466. wr32(E1000_PBA, pba);
  1467. /* To maintain wire speed transmits, the Tx FIFO should be
  1468. * large enough to accommodate two full transmit packets,
  1469. * rounded up to the next 1KB and expressed in KB. Likewise,
  1470. * the Rx FIFO should be large enough to accommodate at least
  1471. * one full receive packet and is similarly rounded up and
  1472. * expressed in KB. */
  1473. pba = rd32(E1000_PBA);
  1474. /* upper 16 bits has Tx packet buffer allocation size in KB */
  1475. tx_space = pba >> 16;
  1476. /* lower 16 bits has Rx packet buffer allocation size in KB */
  1477. pba &= 0xffff;
  1478. /* the tx fifo also stores 16 bytes of information about the tx
  1479. * but don't include ethernet FCS because hardware appends it */
  1480. min_tx_space = (adapter->max_frame_size +
  1481. sizeof(union e1000_adv_tx_desc) -
  1482. ETH_FCS_LEN) * 2;
  1483. min_tx_space = ALIGN(min_tx_space, 1024);
  1484. min_tx_space >>= 10;
  1485. /* software strips receive CRC, so leave room for it */
  1486. min_rx_space = adapter->max_frame_size;
  1487. min_rx_space = ALIGN(min_rx_space, 1024);
  1488. min_rx_space >>= 10;
  1489. /* If current Tx allocation is less than the min Tx FIFO size,
  1490. * and the min Tx FIFO size is less than the current Rx FIFO
  1491. * allocation, take space away from current Rx allocation */
  1492. if (tx_space < min_tx_space &&
  1493. ((min_tx_space - tx_space) < pba)) {
  1494. pba = pba - (min_tx_space - tx_space);
  1495. /* if short on rx space, rx wins and must trump tx
  1496. * adjustment */
  1497. if (pba < min_rx_space)
  1498. pba = min_rx_space;
  1499. }
  1500. wr32(E1000_PBA, pba);
  1501. }
  1502. /* flow control settings */
  1503. /* The high water mark must be low enough to fit one full frame
  1504. * (or the size used for early receive) above it in the Rx FIFO.
  1505. * Set it to the lower of:
  1506. * - 90% of the Rx FIFO size, or
  1507. * - the full Rx FIFO size minus one full frame */
  1508. hwm = min(((pba << 10) * 9 / 10),
  1509. ((pba << 10) - 2 * adapter->max_frame_size));
  1510. fc->high_water = hwm & 0xFFF0; /* 16-byte granularity */
  1511. fc->low_water = fc->high_water - 16;
  1512. fc->pause_time = 0xFFFF;
  1513. fc->send_xon = 1;
  1514. fc->current_mode = fc->requested_mode;
  1515. /* disable receive for all VFs and wait one second */
  1516. if (adapter->vfs_allocated_count) {
  1517. int i;
  1518. for (i = 0 ; i < adapter->vfs_allocated_count; i++)
  1519. adapter->vf_data[i].flags &= IGB_VF_FLAG_PF_SET_MAC;
  1520. /* ping all the active vfs to let them know we are going down */
  1521. igb_ping_all_vfs(adapter);
  1522. /* disable transmits and receives */
  1523. wr32(E1000_VFRE, 0);
  1524. wr32(E1000_VFTE, 0);
  1525. }
  1526. /* Allow time for pending master requests to run */
  1527. hw->mac.ops.reset_hw(hw);
  1528. wr32(E1000_WUC, 0);
  1529. if (hw->mac.ops.init_hw(hw))
  1530. dev_err(&pdev->dev, "Hardware Error\n");
  1531. igb_init_dmac(adapter, pba);
  1532. if (!netif_running(adapter->netdev))
  1533. igb_power_down_link(adapter);
  1534. igb_update_mng_vlan(adapter);
  1535. /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
  1536. wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
  1537. igb_get_phy_info(hw);
  1538. }
  1539. static netdev_features_t igb_fix_features(struct net_device *netdev,
  1540. netdev_features_t features)
  1541. {
  1542. /*
  1543. * Since there is no support for separate rx/tx vlan accel
  1544. * enable/disable make sure tx flag is always in same state as rx.
  1545. */
  1546. if (features & NETIF_F_HW_VLAN_RX)
  1547. features |= NETIF_F_HW_VLAN_TX;
  1548. else
  1549. features &= ~NETIF_F_HW_VLAN_TX;
  1550. return features;
  1551. }
  1552. static int igb_set_features(struct net_device *netdev,
  1553. netdev_features_t features)
  1554. {
  1555. netdev_features_t changed = netdev->features ^ features;
  1556. struct igb_adapter *adapter = netdev_priv(netdev);
  1557. if (changed & NETIF_F_HW_VLAN_RX)
  1558. igb_vlan_mode(netdev, features);
  1559. if (!(changed & NETIF_F_RXALL))
  1560. return 0;
  1561. netdev->features = features;
  1562. if (netif_running(netdev))
  1563. igb_reinit_locked(adapter);
  1564. else
  1565. igb_reset(adapter);
  1566. return 0;
  1567. }
  1568. static const struct net_device_ops igb_netdev_ops = {
  1569. .ndo_open = igb_open,
  1570. .ndo_stop = igb_close,
  1571. .ndo_start_xmit = igb_xmit_frame,
  1572. .ndo_get_stats64 = igb_get_stats64,
  1573. .ndo_set_rx_mode = igb_set_rx_mode,
  1574. .ndo_set_mac_address = igb_set_mac,
  1575. .ndo_change_mtu = igb_change_mtu,
  1576. .ndo_do_ioctl = igb_ioctl,
  1577. .ndo_tx_timeout = igb_tx_timeout,
  1578. .ndo_validate_addr = eth_validate_addr,
  1579. .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid,
  1580. .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid,
  1581. .ndo_set_vf_mac = igb_ndo_set_vf_mac,
  1582. .ndo_set_vf_vlan = igb_ndo_set_vf_vlan,
  1583. .ndo_set_vf_tx_rate = igb_ndo_set_vf_bw,
  1584. .ndo_get_vf_config = igb_ndo_get_vf_config,
  1585. #ifdef CONFIG_NET_POLL_CONTROLLER
  1586. .ndo_poll_controller = igb_netpoll,
  1587. #endif
  1588. .ndo_fix_features = igb_fix_features,
  1589. .ndo_set_features = igb_set_features,
  1590. };
  1591. /**
  1592. * igb_probe - Device Initialization Routine
  1593. * @pdev: PCI device information struct
  1594. * @ent: entry in igb_pci_tbl
  1595. *
  1596. * Returns 0 on success, negative on failure
  1597. *
  1598. * igb_probe initializes an adapter identified by a pci_dev structure.
  1599. * The OS initialization, configuring of the adapter private structure,
  1600. * and a hardware reset occur.
  1601. **/
  1602. static int __devinit igb_probe(struct pci_dev *pdev,
  1603. const struct pci_device_id *ent)
  1604. {
  1605. struct net_device *netdev;
  1606. struct igb_adapter *adapter;
  1607. struct e1000_hw *hw;
  1608. u16 eeprom_data = 0;
  1609. s32 ret_val;
  1610. static int global_quad_port_a; /* global quad port a indication */
  1611. const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
  1612. unsigned long mmio_start, mmio_len;
  1613. int err, pci_using_dac;
  1614. u16 eeprom_apme_mask = IGB_EEPROM_APME;
  1615. u8 part_str[E1000_PBANUM_LENGTH];
  1616. /* Catch broken hardware that put the wrong VF device ID in
  1617. * the PCIe SR-IOV capability.
  1618. */
  1619. if (pdev->is_virtfn) {
  1620. WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
  1621. pci_name(pdev), pdev->vendor, pdev->device);
  1622. return -EINVAL;
  1623. }
  1624. err = pci_enable_device_mem(pdev);
  1625. if (err)
  1626. return err;
  1627. pci_using_dac = 0;
  1628. err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
  1629. if (!err) {
  1630. err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
  1631. if (!err)
  1632. pci_using_dac = 1;
  1633. } else {
  1634. err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  1635. if (err) {
  1636. err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  1637. if (err) {
  1638. dev_err(&pdev->dev, "No usable DMA "
  1639. "configuration, aborting\n");
  1640. goto err_dma;
  1641. }
  1642. }
  1643. }
  1644. err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
  1645. IORESOURCE_MEM),
  1646. igb_driver_name);
  1647. if (err)
  1648. goto err_pci_reg;
  1649. pci_enable_pcie_error_reporting(pdev);
  1650. pci_set_master(pdev);
  1651. pci_save_state(pdev);
  1652. err = -ENOMEM;
  1653. netdev = alloc_etherdev_mq(sizeof(struct igb_adapter),
  1654. IGB_MAX_TX_QUEUES);
  1655. if (!netdev)
  1656. goto err_alloc_etherdev;
  1657. SET_NETDEV_DEV(netdev, &pdev->dev);
  1658. pci_set_drvdata(pdev, netdev);
  1659. adapter = netdev_priv(netdev);
  1660. adapter->netdev = netdev;
  1661. adapter->pdev = pdev;
  1662. hw = &adapter->hw;
  1663. hw->back = adapter;
  1664. adapter->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE;
  1665. mmio_start = pci_resource_start(pdev, 0);
  1666. mmio_len = pci_resource_len(pdev, 0);
  1667. err = -EIO;
  1668. hw->hw_addr = ioremap(mmio_start, mmio_len);
  1669. if (!hw->hw_addr)
  1670. goto err_ioremap;
  1671. netdev->netdev_ops = &igb_netdev_ops;
  1672. igb_set_ethtool_ops(netdev);
  1673. netdev->watchdog_timeo = 5 * HZ;
  1674. strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
  1675. netdev->mem_start = mmio_start;
  1676. netdev->mem_end = mmio_start + mmio_len;
  1677. /* PCI config space info */
  1678. hw->vendor_id = pdev->vendor;
  1679. hw->device_id = pdev->device;
  1680. hw->revision_id = pdev->revision;
  1681. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  1682. hw->subsystem_device_id = pdev->subsystem_device;
  1683. /* Copy the default MAC, PHY and NVM function pointers */
  1684. memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
  1685. memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
  1686. memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
  1687. /* Initialize skew-specific constants */
  1688. err = ei->get_invariants(hw);
  1689. if (err)
  1690. goto err_sw_init;
  1691. /* setup the private structure */
  1692. err = igb_sw_init(adapter);
  1693. if (err)
  1694. goto err_sw_init;
  1695. igb_get_bus_info_pcie(hw);
  1696. hw->phy.autoneg_wait_to_complete = false;
  1697. /* Copper options */
  1698. if (hw->phy.media_type == e1000_media_type_copper) {
  1699. hw->phy.mdix = AUTO_ALL_MODES;
  1700. hw->phy.disable_polarity_correction = false;
  1701. hw->phy.ms_type = e1000_ms_hw_default;
  1702. }
  1703. if (igb_check_reset_block(hw))
  1704. dev_info(&pdev->dev,
  1705. "PHY reset is blocked due to SOL/IDER session.\n");
  1706. /*
  1707. * features is initialized to 0 in allocation, it might have bits
  1708. * set by igb_sw_init so we should use an or instead of an
  1709. * assignment.
  1710. */
  1711. netdev->features |= NETIF_F_SG |
  1712. NETIF_F_IP_CSUM |
  1713. NETIF_F_IPV6_CSUM |
  1714. NETIF_F_TSO |
  1715. NETIF_F_TSO6 |
  1716. NETIF_F_RXHASH |
  1717. NETIF_F_RXCSUM |
  1718. NETIF_F_HW_VLAN_RX |
  1719. NETIF_F_HW_VLAN_TX;
  1720. /* copy netdev features into list of user selectable features */
  1721. netdev->hw_features |= netdev->features;
  1722. netdev->hw_features |= NETIF_F_RXALL;
  1723. /* set this bit last since it cannot be part of hw_features */
  1724. netdev->features |= NETIF_F_HW_VLAN_FILTER;
  1725. netdev->vlan_features |= NETIF_F_TSO |
  1726. NETIF_F_TSO6 |
  1727. NETIF_F_IP_CSUM |
  1728. NETIF_F_IPV6_CSUM |
  1729. NETIF_F_SG;
  1730. netdev->priv_flags |= IFF_SUPP_NOFCS;
  1731. if (pci_using_dac) {
  1732. netdev->features |= NETIF_F_HIGHDMA;
  1733. netdev->vlan_features |= NETIF_F_HIGHDMA;
  1734. }
  1735. if (hw->mac.type >= e1000_82576) {
  1736. netdev->hw_features |= NETIF_F_SCTP_CSUM;
  1737. netdev->features |= NETIF_F_SCTP_CSUM;
  1738. }
  1739. netdev->priv_flags |= IFF_UNICAST_FLT;
  1740. adapter->en_mng_pt = igb_enable_mng_pass_thru(hw);
  1741. /* before reading the NVM, reset the controller to put the device in a
  1742. * known good starting state */
  1743. hw->mac.ops.reset_hw(hw);
  1744. /* make sure the NVM is good */
  1745. if (hw->nvm.ops.validate(hw) < 0) {
  1746. dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
  1747. err = -EIO;
  1748. goto err_eeprom;
  1749. }
  1750. /* copy the MAC address out of the NVM */
  1751. if (hw->mac.ops.read_mac_addr(hw))
  1752. dev_err(&pdev->dev, "NVM Read Error\n");
  1753. memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
  1754. memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
  1755. if (!is_valid_ether_addr(netdev->perm_addr)) {
  1756. dev_err(&pdev->dev, "Invalid MAC Address\n");
  1757. err = -EIO;
  1758. goto err_eeprom;
  1759. }
  1760. setup_timer(&adapter->watchdog_timer, igb_watchdog,
  1761. (unsigned long) adapter);
  1762. setup_timer(&adapter->phy_info_timer, igb_update_phy_info,
  1763. (unsigned long) adapter);
  1764. INIT_WORK(&adapter->reset_task, igb_reset_task);
  1765. INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
  1766. /* Initialize link properties that are user-changeable */
  1767. adapter->fc_autoneg = true;
  1768. hw->mac.autoneg = true;
  1769. hw->phy.autoneg_advertised = 0x2f;
  1770. hw->fc.requested_mode = e1000_fc_default;
  1771. hw->fc.current_mode = e1000_fc_default;
  1772. igb_validate_mdi_setting(hw);
  1773. /* Initial Wake on LAN setting If APM wake is enabled in the EEPROM,
  1774. * enable the ACPI Magic Packet filter
  1775. */
  1776. if (hw->bus.func == 0)
  1777. hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
  1778. else if (hw->mac.type >= e1000_82580)
  1779. hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
  1780. NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
  1781. &eeprom_data);
  1782. else if (hw->bus.func == 1)
  1783. hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
  1784. if (eeprom_data & eeprom_apme_mask)
  1785. adapter->eeprom_wol |= E1000_WUFC_MAG;
  1786. /* now that we have the eeprom settings, apply the special cases where
  1787. * the eeprom may be wrong or the board simply won't support wake on
  1788. * lan on a particular port */
  1789. switch (pdev->device) {
  1790. case E1000_DEV_ID_82575GB_QUAD_COPPER:
  1791. adapter->eeprom_wol = 0;
  1792. break;
  1793. case E1000_DEV_ID_82575EB_FIBER_SERDES:
  1794. case E1000_DEV_ID_82576_FIBER:
  1795. case E1000_DEV_ID_82576_SERDES:
  1796. /* Wake events only supported on port A for dual fiber
  1797. * regardless of eeprom setting */
  1798. if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1)
  1799. adapter->eeprom_wol = 0;
  1800. break;
  1801. case E1000_DEV_ID_82576_QUAD_COPPER:
  1802. case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
  1803. /* if quad port adapter, disable WoL on all but port A */
  1804. if (global_quad_port_a != 0)
  1805. adapter->eeprom_wol = 0;
  1806. else
  1807. adapter->flags |= IGB_FLAG_QUAD_PORT_A;
  1808. /* Reset for multiple quad port adapters */
  1809. if (++global_quad_port_a == 4)
  1810. global_quad_port_a = 0;
  1811. break;
  1812. }
  1813. /* initialize the wol settings based on the eeprom settings */
  1814. adapter->wol = adapter->eeprom_wol;
  1815. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  1816. /* reset the hardware with the new settings */
  1817. igb_reset(adapter);
  1818. /* let the f/w know that the h/w is now under the control of the
  1819. * driver. */
  1820. igb_get_hw_control(adapter);
  1821. strcpy(netdev->name, "eth%d");
  1822. err = register_netdev(netdev);
  1823. if (err)
  1824. goto err_register;
  1825. /* carrier off reporting is important to ethtool even BEFORE open */
  1826. netif_carrier_off(netdev);
  1827. #ifdef CONFIG_IGB_DCA
  1828. if (dca_add_requester(&pdev->dev) == 0) {
  1829. adapter->flags |= IGB_FLAG_DCA_ENABLED;
  1830. dev_info(&pdev->dev, "DCA enabled\n");
  1831. igb_setup_dca(adapter);
  1832. }
  1833. #endif
  1834. /* do hw tstamp init after resetting */
  1835. igb_init_hw_timer(adapter);
  1836. dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n");
  1837. /* print bus type/speed/width info */
  1838. dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n",
  1839. netdev->name,
  1840. ((hw->bus.speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
  1841. (hw->bus.speed == e1000_bus_speed_5000) ? "5.0Gb/s" :
  1842. "unknown"),
  1843. ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
  1844. (hw->bus.width == e1000_bus_width_pcie_x2) ? "Width x2" :
  1845. (hw->bus.width == e1000_bus_width_pcie_x1) ? "Width x1" :
  1846. "unknown"),
  1847. netdev->dev_addr);
  1848. ret_val = igb_read_part_string(hw, part_str, E1000_PBANUM_LENGTH);
  1849. if (ret_val)
  1850. strcpy(part_str, "Unknown");
  1851. dev_info(&pdev->dev, "%s: PBA No: %s\n", netdev->name, part_str);
  1852. dev_info(&pdev->dev,
  1853. "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
  1854. adapter->msix_entries ? "MSI-X" :
  1855. (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
  1856. adapter->num_rx_queues, adapter->num_tx_queues);
  1857. switch (hw->mac.type) {
  1858. case e1000_i350:
  1859. igb_set_eee_i350(hw);
  1860. break;
  1861. default:
  1862. break;
  1863. }
  1864. pm_runtime_put_noidle(&pdev->dev);
  1865. return 0;
  1866. err_register:
  1867. igb_release_hw_control(adapter);
  1868. err_eeprom:
  1869. if (!igb_check_reset_block(hw))
  1870. igb_reset_phy(hw);
  1871. if (hw->flash_address)
  1872. iounmap(hw->flash_address);
  1873. err_sw_init:
  1874. igb_clear_interrupt_scheme(adapter);
  1875. iounmap(hw->hw_addr);
  1876. err_ioremap:
  1877. free_netdev(netdev);
  1878. err_alloc_etherdev:
  1879. pci_release_selected_regions(pdev,
  1880. pci_select_bars(pdev, IORESOURCE_MEM));
  1881. err_pci_reg:
  1882. err_dma:
  1883. pci_disable_device(pdev);
  1884. return err;
  1885. }
  1886. /**
  1887. * igb_remove - Device Removal Routine
  1888. * @pdev: PCI device information struct
  1889. *
  1890. * igb_remove is called by the PCI subsystem to alert the driver
  1891. * that it should release a PCI device. The could be caused by a
  1892. * Hot-Plug event, or because the driver is going to be removed from
  1893. * memory.
  1894. **/
  1895. static void __devexit igb_remove(struct pci_dev *pdev)
  1896. {
  1897. struct net_device *netdev = pci_get_drvdata(pdev);
  1898. struct igb_adapter *adapter = netdev_priv(netdev);
  1899. struct e1000_hw *hw = &adapter->hw;
  1900. pm_runtime_get_noresume(&pdev->dev);
  1901. /*
  1902. * The watchdog timer may be rescheduled, so explicitly
  1903. * disable watchdog from being rescheduled.
  1904. */
  1905. set_bit(__IGB_DOWN, &adapter->state);
  1906. del_timer_sync(&adapter->watchdog_timer);
  1907. del_timer_sync(&adapter->phy_info_timer);
  1908. cancel_work_sync(&adapter->reset_task);
  1909. cancel_work_sync(&adapter->watchdog_task);
  1910. #ifdef CONFIG_IGB_DCA
  1911. if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
  1912. dev_info(&pdev->dev, "DCA disabled\n");
  1913. dca_remove_requester(&pdev->dev);
  1914. adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
  1915. wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
  1916. }
  1917. #endif
  1918. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  1919. * would have already happened in close and is redundant. */
  1920. igb_release_hw_control(adapter);
  1921. unregister_netdev(netdev);
  1922. igb_clear_interrupt_scheme(adapter);
  1923. #ifdef CONFIG_PCI_IOV
  1924. /* reclaim resources allocated to VFs */
  1925. if (adapter->vf_data) {
  1926. /* disable iov and allow time for transactions to clear */
  1927. if (!igb_check_vf_assignment(adapter)) {
  1928. pci_disable_sriov(pdev);
  1929. msleep(500);
  1930. } else {
  1931. dev_info(&pdev->dev, "VF(s) assigned to guests!\n");
  1932. }
  1933. kfree(adapter->vf_data);
  1934. adapter->vf_data = NULL;
  1935. wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
  1936. wrfl();
  1937. msleep(100);
  1938. dev_info(&pdev->dev, "IOV Disabled\n");
  1939. }
  1940. #endif
  1941. iounmap(hw->hw_addr);
  1942. if (hw->flash_address)
  1943. iounmap(hw->flash_address);
  1944. pci_release_selected_regions(pdev,
  1945. pci_select_bars(pdev, IORESOURCE_MEM));
  1946. kfree(adapter->shadow_vfta);
  1947. free_netdev(netdev);
  1948. pci_disable_pcie_error_reporting(pdev);
  1949. pci_disable_device(pdev);
  1950. }
  1951. /**
  1952. * igb_probe_vfs - Initialize vf data storage and add VFs to pci config space
  1953. * @adapter: board private structure to initialize
  1954. *
  1955. * This function initializes the vf specific data storage and then attempts to
  1956. * allocate the VFs. The reason for ordering it this way is because it is much
  1957. * mor expensive time wise to disable SR-IOV than it is to allocate and free
  1958. * the memory for the VFs.
  1959. **/
  1960. static void __devinit igb_probe_vfs(struct igb_adapter * adapter)
  1961. {
  1962. #ifdef CONFIG_PCI_IOV
  1963. struct pci_dev *pdev = adapter->pdev;
  1964. int old_vfs = igb_find_enabled_vfs(adapter);
  1965. int i;
  1966. if (old_vfs) {
  1967. dev_info(&pdev->dev, "%d pre-allocated VFs found - override "
  1968. "max_vfs setting of %d\n", old_vfs, max_vfs);
  1969. adapter->vfs_allocated_count = old_vfs;
  1970. }
  1971. if (!adapter->vfs_allocated_count)
  1972. return;
  1973. adapter->vf_data = kcalloc(adapter->vfs_allocated_count,
  1974. sizeof(struct vf_data_storage), GFP_KERNEL);
  1975. /* if allocation failed then we do not support SR-IOV */
  1976. if (!adapter->vf_data) {
  1977. adapter->vfs_allocated_count = 0;
  1978. dev_err(&pdev->dev, "Unable to allocate memory for VF "
  1979. "Data Storage\n");
  1980. goto out;
  1981. }
  1982. if (!old_vfs) {
  1983. if (pci_enable_sriov(pdev, adapter->vfs_allocated_count))
  1984. goto err_out;
  1985. }
  1986. dev_info(&pdev->dev, "%d VFs allocated\n",
  1987. adapter->vfs_allocated_count);
  1988. for (i = 0; i < adapter->vfs_allocated_count; i++)
  1989. igb_vf_configure(adapter, i);
  1990. /* DMA Coalescing is not supported in IOV mode. */
  1991. adapter->flags &= ~IGB_FLAG_DMAC;
  1992. goto out;
  1993. err_out:
  1994. kfree(adapter->vf_data);
  1995. adapter->vf_data = NULL;
  1996. adapter->vfs_allocated_count = 0;
  1997. out:
  1998. return;
  1999. #endif /* CONFIG_PCI_IOV */
  2000. }
  2001. /**
  2002. * igb_init_hw_timer - Initialize hardware timer used with IEEE 1588 timestamp
  2003. * @adapter: board private structure to initialize
  2004. *
  2005. * igb_init_hw_timer initializes the function pointer and values for the hw
  2006. * timer found in hardware.
  2007. **/
  2008. static void igb_init_hw_timer(struct igb_adapter *adapter)
  2009. {
  2010. struct e1000_hw *hw = &adapter->hw;
  2011. switch (hw->mac.type) {
  2012. case e1000_i350:
  2013. case e1000_82580:
  2014. memset(&adapter->cycles, 0, sizeof(adapter->cycles));
  2015. adapter->cycles.read = igb_read_clock;
  2016. adapter->cycles.mask = CLOCKSOURCE_MASK(64);
  2017. adapter->cycles.mult = 1;
  2018. /*
  2019. * The 82580 timesync updates the system timer every 8ns by 8ns
  2020. * and the value cannot be shifted. Instead we need to shift
  2021. * the registers to generate a 64bit timer value. As a result
  2022. * SYSTIMR/L/H, TXSTMPL/H, RXSTMPL/H all have to be shifted by
  2023. * 24 in order to generate a larger value for synchronization.
  2024. */
  2025. adapter->cycles.shift = IGB_82580_TSYNC_SHIFT;
  2026. /* disable system timer temporarily by setting bit 31 */
  2027. wr32(E1000_TSAUXC, 0x80000000);
  2028. wrfl();
  2029. /* Set registers so that rollover occurs soon to test this. */
  2030. wr32(E1000_SYSTIMR, 0x00000000);
  2031. wr32(E1000_SYSTIML, 0x80000000);
  2032. wr32(E1000_SYSTIMH, 0x000000FF);
  2033. wrfl();
  2034. /* enable system timer by clearing bit 31 */
  2035. wr32(E1000_TSAUXC, 0x0);
  2036. wrfl();
  2037. timecounter_init(&adapter->clock,
  2038. &adapter->cycles,
  2039. ktime_to_ns(ktime_get_real()));
  2040. /*
  2041. * Synchronize our NIC clock against system wall clock. NIC
  2042. * time stamp reading requires ~3us per sample, each sample
  2043. * was pretty stable even under load => only require 10
  2044. * samples for each offset comparison.
  2045. */
  2046. memset(&adapter->compare, 0, sizeof(adapter->compare));
  2047. adapter->compare.source = &adapter->clock;
  2048. adapter->compare.target = ktime_get_real;
  2049. adapter->compare.num_samples = 10;
  2050. timecompare_update(&adapter->compare, 0);
  2051. break;
  2052. case e1000_82576:
  2053. /*
  2054. * Initialize hardware timer: we keep it running just in case
  2055. * that some program needs it later on.
  2056. */
  2057. memset(&adapter->cycles, 0, sizeof(adapter->cycles));
  2058. adapter->cycles.read = igb_read_clock;
  2059. adapter->cycles.mask = CLOCKSOURCE_MASK(64);
  2060. adapter->cycles.mult = 1;
  2061. /**
  2062. * Scale the NIC clock cycle by a large factor so that
  2063. * relatively small clock corrections can be added or
  2064. * subtracted at each clock tick. The drawbacks of a large
  2065. * factor are a) that the clock register overflows more quickly
  2066. * (not such a big deal) and b) that the increment per tick has
  2067. * to fit into 24 bits. As a result we need to use a shift of
  2068. * 19 so we can fit a value of 16 into the TIMINCA register.
  2069. */
  2070. adapter->cycles.shift = IGB_82576_TSYNC_SHIFT;
  2071. wr32(E1000_TIMINCA,
  2072. (1 << E1000_TIMINCA_16NS_SHIFT) |
  2073. (16 << IGB_82576_TSYNC_SHIFT));
  2074. /* Set registers so that rollover occurs soon to test this. */
  2075. wr32(E1000_SYSTIML, 0x00000000);
  2076. wr32(E1000_SYSTIMH, 0xFF800000);
  2077. wrfl();
  2078. timecounter_init(&adapter->clock,
  2079. &adapter->cycles,
  2080. ktime_to_ns(ktime_get_real()));
  2081. /*
  2082. * Synchronize our NIC clock against system wall clock. NIC
  2083. * time stamp reading requires ~3us per sample, each sample
  2084. * was pretty stable even under load => only require 10
  2085. * samples for each offset comparison.
  2086. */
  2087. memset(&adapter->compare, 0, sizeof(adapter->compare));
  2088. adapter->compare.source = &adapter->clock;
  2089. adapter->compare.target = ktime_get_real;
  2090. adapter->compare.num_samples = 10;
  2091. timecompare_update(&adapter->compare, 0);
  2092. break;
  2093. case e1000_82575:
  2094. /* 82575 does not support timesync */
  2095. default:
  2096. break;
  2097. }
  2098. }
  2099. /**
  2100. * igb_sw_init - Initialize general software structures (struct igb_adapter)
  2101. * @adapter: board private structure to initialize
  2102. *
  2103. * igb_sw_init initializes the Adapter private data structure.
  2104. * Fields are initialized based on PCI device information and
  2105. * OS network device settings (MTU size).
  2106. **/
  2107. static int __devinit igb_sw_init(struct igb_adapter *adapter)
  2108. {
  2109. struct e1000_hw *hw = &adapter->hw;
  2110. struct net_device *netdev = adapter->netdev;
  2111. struct pci_dev *pdev = adapter->pdev;
  2112. pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
  2113. /* set default ring sizes */
  2114. adapter->tx_ring_count = IGB_DEFAULT_TXD;
  2115. adapter->rx_ring_count = IGB_DEFAULT_RXD;
  2116. /* set default ITR values */
  2117. adapter->rx_itr_setting = IGB_DEFAULT_ITR;
  2118. adapter->tx_itr_setting = IGB_DEFAULT_ITR;
  2119. /* set default work limits */
  2120. adapter->tx_work_limit = IGB_DEFAULT_TX_WORK;
  2121. adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN +
  2122. VLAN_HLEN;
  2123. adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
  2124. adapter->node = -1;
  2125. spin_lock_init(&adapter->stats64_lock);
  2126. #ifdef CONFIG_PCI_IOV
  2127. switch (hw->mac.type) {
  2128. case e1000_82576:
  2129. case e1000_i350:
  2130. if (max_vfs > 7) {
  2131. dev_warn(&pdev->dev,
  2132. "Maximum of 7 VFs per PF, using max\n");
  2133. adapter->vfs_allocated_count = 7;
  2134. } else
  2135. adapter->vfs_allocated_count = max_vfs;
  2136. break;
  2137. default:
  2138. break;
  2139. }
  2140. #endif /* CONFIG_PCI_IOV */
  2141. adapter->rss_queues = min_t(u32, IGB_MAX_RX_QUEUES, num_online_cpus());
  2142. /* i350 cannot do RSS and SR-IOV at the same time */
  2143. if (hw->mac.type == e1000_i350 && adapter->vfs_allocated_count)
  2144. adapter->rss_queues = 1;
  2145. /*
  2146. * if rss_queues > 4 or vfs are going to be allocated with rss_queues
  2147. * then we should combine the queues into a queue pair in order to
  2148. * conserve interrupts due to limited supply
  2149. */
  2150. if ((adapter->rss_queues > 4) ||
  2151. ((adapter->rss_queues > 1) && (adapter->vfs_allocated_count > 6)))
  2152. adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
  2153. /* Setup and initialize a copy of the hw vlan table array */
  2154. adapter->shadow_vfta = kzalloc(sizeof(u32) *
  2155. E1000_VLAN_FILTER_TBL_SIZE,
  2156. GFP_ATOMIC);
  2157. /* This call may decrease the number of queues */
  2158. if (igb_init_interrupt_scheme(adapter)) {
  2159. dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
  2160. return -ENOMEM;
  2161. }
  2162. igb_probe_vfs(adapter);
  2163. /* Explicitly disable IRQ since the NIC can be in any state. */
  2164. igb_irq_disable(adapter);
  2165. if (hw->mac.type == e1000_i350)
  2166. adapter->flags &= ~IGB_FLAG_DMAC;
  2167. set_bit(__IGB_DOWN, &adapter->state);
  2168. return 0;
  2169. }
  2170. /**
  2171. * igb_open - Called when a network interface is made active
  2172. * @netdev: network interface device structure
  2173. *
  2174. * Returns 0 on success, negative value on failure
  2175. *
  2176. * The open entry point is called when a network interface is made
  2177. * active by the system (IFF_UP). At this point all resources needed
  2178. * for transmit and receive operations are allocated, the interrupt
  2179. * handler is registered with the OS, the watchdog timer is started,
  2180. * and the stack is notified that the interface is ready.
  2181. **/
  2182. static int __igb_open(struct net_device *netdev, bool resuming)
  2183. {
  2184. struct igb_adapter *adapter = netdev_priv(netdev);
  2185. struct e1000_hw *hw = &adapter->hw;
  2186. struct pci_dev *pdev = adapter->pdev;
  2187. int err;
  2188. int i;
  2189. /* disallow open during test */
  2190. if (test_bit(__IGB_TESTING, &adapter->state)) {
  2191. WARN_ON(resuming);
  2192. return -EBUSY;
  2193. }
  2194. if (!resuming)
  2195. pm_runtime_get_sync(&pdev->dev);
  2196. netif_carrier_off(netdev);
  2197. /* allocate transmit descriptors */
  2198. err = igb_setup_all_tx_resources(adapter);
  2199. if (err)
  2200. goto err_setup_tx;
  2201. /* allocate receive descriptors */
  2202. err = igb_setup_all_rx_resources(adapter);
  2203. if (err)
  2204. goto err_setup_rx;
  2205. igb_power_up_link(adapter);
  2206. /* before we allocate an interrupt, we must be ready to handle it.
  2207. * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
  2208. * as soon as we call pci_request_irq, so we have to setup our
  2209. * clean_rx handler before we do so. */
  2210. igb_configure(adapter);
  2211. err = igb_request_irq(adapter);
  2212. if (err)
  2213. goto err_req_irq;
  2214. /* From here on the code is the same as igb_up() */
  2215. clear_bit(__IGB_DOWN, &adapter->state);
  2216. for (i = 0; i < adapter->num_q_vectors; i++)
  2217. napi_enable(&(adapter->q_vector[i]->napi));
  2218. /* Clear any pending interrupts. */
  2219. rd32(E1000_ICR);
  2220. igb_irq_enable(adapter);
  2221. /* notify VFs that reset has been completed */
  2222. if (adapter->vfs_allocated_count) {
  2223. u32 reg_data = rd32(E1000_CTRL_EXT);
  2224. reg_data |= E1000_CTRL_EXT_PFRSTD;
  2225. wr32(E1000_CTRL_EXT, reg_data);
  2226. }
  2227. netif_tx_start_all_queues(netdev);
  2228. if (!resuming)
  2229. pm_runtime_put(&pdev->dev);
  2230. /* start the watchdog. */
  2231. hw->mac.get_link_status = 1;
  2232. schedule_work(&adapter->watchdog_task);
  2233. return 0;
  2234. err_req_irq:
  2235. igb_release_hw_control(adapter);
  2236. igb_power_down_link(adapter);
  2237. igb_free_all_rx_resources(adapter);
  2238. err_setup_rx:
  2239. igb_free_all_tx_resources(adapter);
  2240. err_setup_tx:
  2241. igb_reset(adapter);
  2242. if (!resuming)
  2243. pm_runtime_put(&pdev->dev);
  2244. return err;
  2245. }
  2246. static int igb_open(struct net_device *netdev)
  2247. {
  2248. return __igb_open(netdev, false);
  2249. }
  2250. /**
  2251. * igb_close - Disables a network interface
  2252. * @netdev: network interface device structure
  2253. *
  2254. * Returns 0, this is not allowed to fail
  2255. *
  2256. * The close entry point is called when an interface is de-activated
  2257. * by the OS. The hardware is still under the driver's control, but
  2258. * needs to be disabled. A global MAC reset is issued to stop the
  2259. * hardware, and all transmit and receive resources are freed.
  2260. **/
  2261. static int __igb_close(struct net_device *netdev, bool suspending)
  2262. {
  2263. struct igb_adapter *adapter = netdev_priv(netdev);
  2264. struct pci_dev *pdev = adapter->pdev;
  2265. WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
  2266. if (!suspending)
  2267. pm_runtime_get_sync(&pdev->dev);
  2268. igb_down(adapter);
  2269. igb_free_irq(adapter);
  2270. igb_free_all_tx_resources(adapter);
  2271. igb_free_all_rx_resources(adapter);
  2272. if (!suspending)
  2273. pm_runtime_put_sync(&pdev->dev);
  2274. return 0;
  2275. }
  2276. static int igb_close(struct net_device *netdev)
  2277. {
  2278. return __igb_close(netdev, false);
  2279. }
  2280. /**
  2281. * igb_setup_tx_resources - allocate Tx resources (Descriptors)
  2282. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  2283. *
  2284. * Return 0 on success, negative on failure
  2285. **/
  2286. int igb_setup_tx_resources(struct igb_ring *tx_ring)
  2287. {
  2288. struct device *dev = tx_ring->dev;
  2289. int orig_node = dev_to_node(dev);
  2290. int size;
  2291. size = sizeof(struct igb_tx_buffer) * tx_ring->count;
  2292. tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
  2293. if (!tx_ring->tx_buffer_info)
  2294. tx_ring->tx_buffer_info = vzalloc(size);
  2295. if (!tx_ring->tx_buffer_info)
  2296. goto err;
  2297. /* round up to nearest 4K */
  2298. tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);
  2299. tx_ring->size = ALIGN(tx_ring->size, 4096);
  2300. set_dev_node(dev, tx_ring->numa_node);
  2301. tx_ring->desc = dma_alloc_coherent(dev,
  2302. tx_ring->size,
  2303. &tx_ring->dma,
  2304. GFP_KERNEL);
  2305. set_dev_node(dev, orig_node);
  2306. if (!tx_ring->desc)
  2307. tx_ring->desc = dma_alloc_coherent(dev,
  2308. tx_ring->size,
  2309. &tx_ring->dma,
  2310. GFP_KERNEL);
  2311. if (!tx_ring->desc)
  2312. goto err;
  2313. tx_ring->next_to_use = 0;
  2314. tx_ring->next_to_clean = 0;
  2315. return 0;
  2316. err:
  2317. vfree(tx_ring->tx_buffer_info);
  2318. dev_err(dev,
  2319. "Unable to allocate memory for the transmit descriptor ring\n");
  2320. return -ENOMEM;
  2321. }
  2322. /**
  2323. * igb_setup_all_tx_resources - wrapper to allocate Tx resources
  2324. * (Descriptors) for all queues
  2325. * @adapter: board private structure
  2326. *
  2327. * Return 0 on success, negative on failure
  2328. **/
  2329. static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
  2330. {
  2331. struct pci_dev *pdev = adapter->pdev;
  2332. int i, err = 0;
  2333. for (i = 0; i < adapter->num_tx_queues; i++) {
  2334. err = igb_setup_tx_resources(adapter->tx_ring[i]);
  2335. if (err) {
  2336. dev_err(&pdev->dev,
  2337. "Allocation for Tx Queue %u failed\n", i);
  2338. for (i--; i >= 0; i--)
  2339. igb_free_tx_resources(adapter->tx_ring[i]);
  2340. break;
  2341. }
  2342. }
  2343. return err;
  2344. }
  2345. /**
  2346. * igb_setup_tctl - configure the transmit control registers
  2347. * @adapter: Board private structure
  2348. **/
  2349. void igb_setup_tctl(struct igb_adapter *adapter)
  2350. {
  2351. struct e1000_hw *hw = &adapter->hw;
  2352. u32 tctl;
  2353. /* disable queue 0 which is enabled by default on 82575 and 82576 */
  2354. wr32(E1000_TXDCTL(0), 0);
  2355. /* Program the Transmit Control Register */
  2356. tctl = rd32(E1000_TCTL);
  2357. tctl &= ~E1000_TCTL_CT;
  2358. tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
  2359. (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
  2360. igb_config_collision_dist(hw);
  2361. /* Enable transmits */
  2362. tctl |= E1000_TCTL_EN;
  2363. wr32(E1000_TCTL, tctl);
  2364. }
  2365. /**
  2366. * igb_configure_tx_ring - Configure transmit ring after Reset
  2367. * @adapter: board private structure
  2368. * @ring: tx ring to configure
  2369. *
  2370. * Configure a transmit ring after a reset.
  2371. **/
  2372. void igb_configure_tx_ring(struct igb_adapter *adapter,
  2373. struct igb_ring *ring)
  2374. {
  2375. struct e1000_hw *hw = &adapter->hw;
  2376. u32 txdctl = 0;
  2377. u64 tdba = ring->dma;
  2378. int reg_idx = ring->reg_idx;
  2379. /* disable the queue */
  2380. wr32(E1000_TXDCTL(reg_idx), 0);
  2381. wrfl();
  2382. mdelay(10);
  2383. wr32(E1000_TDLEN(reg_idx),
  2384. ring->count * sizeof(union e1000_adv_tx_desc));
  2385. wr32(E1000_TDBAL(reg_idx),
  2386. tdba & 0x00000000ffffffffULL);
  2387. wr32(E1000_TDBAH(reg_idx), tdba >> 32);
  2388. ring->tail = hw->hw_addr + E1000_TDT(reg_idx);
  2389. wr32(E1000_TDH(reg_idx), 0);
  2390. writel(0, ring->tail);
  2391. txdctl |= IGB_TX_PTHRESH;
  2392. txdctl |= IGB_TX_HTHRESH << 8;
  2393. txdctl |= IGB_TX_WTHRESH << 16;
  2394. txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
  2395. wr32(E1000_TXDCTL(reg_idx), txdctl);
  2396. netdev_tx_reset_queue(txring_txq(ring));
  2397. }
  2398. /**
  2399. * igb_configure_tx - Configure transmit Unit after Reset
  2400. * @adapter: board private structure
  2401. *
  2402. * Configure the Tx unit of the MAC after a reset.
  2403. **/
  2404. static void igb_configure_tx(struct igb_adapter *adapter)
  2405. {
  2406. int i;
  2407. for (i = 0; i < adapter->num_tx_queues; i++)
  2408. igb_configure_tx_ring(adapter, adapter->tx_ring[i]);
  2409. }
  2410. /**
  2411. * igb_setup_rx_resources - allocate Rx resources (Descriptors)
  2412. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  2413. *
  2414. * Returns 0 on success, negative on failure
  2415. **/
  2416. int igb_setup_rx_resources(struct igb_ring *rx_ring)
  2417. {
  2418. struct device *dev = rx_ring->dev;
  2419. int orig_node = dev_to_node(dev);
  2420. int size, desc_len;
  2421. size = sizeof(struct igb_rx_buffer) * rx_ring->count;
  2422. rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
  2423. if (!rx_ring->rx_buffer_info)
  2424. rx_ring->rx_buffer_info = vzalloc(size);
  2425. if (!rx_ring->rx_buffer_info)
  2426. goto err;
  2427. desc_len = sizeof(union e1000_adv_rx_desc);
  2428. /* Round up to nearest 4K */
  2429. rx_ring->size = rx_ring->count * desc_len;
  2430. rx_ring->size = ALIGN(rx_ring->size, 4096);
  2431. set_dev_node(dev, rx_ring->numa_node);
  2432. rx_ring->desc = dma_alloc_coherent(dev,
  2433. rx_ring->size,
  2434. &rx_ring->dma,
  2435. GFP_KERNEL);
  2436. set_dev_node(dev, orig_node);
  2437. if (!rx_ring->desc)
  2438. rx_ring->desc = dma_alloc_coherent(dev,
  2439. rx_ring->size,
  2440. &rx_ring->dma,
  2441. GFP_KERNEL);
  2442. if (!rx_ring->desc)
  2443. goto err;
  2444. rx_ring->next_to_clean = 0;
  2445. rx_ring->next_to_use = 0;
  2446. return 0;
  2447. err:
  2448. vfree(rx_ring->rx_buffer_info);
  2449. rx_ring->rx_buffer_info = NULL;
  2450. dev_err(dev, "Unable to allocate memory for the receive descriptor"
  2451. " ring\n");
  2452. return -ENOMEM;
  2453. }
  2454. /**
  2455. * igb_setup_all_rx_resources - wrapper to allocate Rx resources
  2456. * (Descriptors) for all queues
  2457. * @adapter: board private structure
  2458. *
  2459. * Return 0 on success, negative on failure
  2460. **/
  2461. static int igb_setup_all_rx_resources(struct igb_adapter *adapter)
  2462. {
  2463. struct pci_dev *pdev = adapter->pdev;
  2464. int i, err = 0;
  2465. for (i = 0; i < adapter->num_rx_queues; i++) {
  2466. err = igb_setup_rx_resources(adapter->rx_ring[i]);
  2467. if (err) {
  2468. dev_err(&pdev->dev,
  2469. "Allocation for Rx Queue %u failed\n", i);
  2470. for (i--; i >= 0; i--)
  2471. igb_free_rx_resources(adapter->rx_ring[i]);
  2472. break;
  2473. }
  2474. }
  2475. return err;
  2476. }
  2477. /**
  2478. * igb_setup_mrqc - configure the multiple receive queue control registers
  2479. * @adapter: Board private structure
  2480. **/
  2481. static void igb_setup_mrqc(struct igb_adapter *adapter)
  2482. {
  2483. struct e1000_hw *hw = &adapter->hw;
  2484. u32 mrqc, rxcsum;
  2485. u32 j, num_rx_queues, shift = 0, shift2 = 0;
  2486. union e1000_reta {
  2487. u32 dword;
  2488. u8 bytes[4];
  2489. } reta;
  2490. static const u8 rsshash[40] = {
  2491. 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, 0x41, 0x67,
  2492. 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, 0xd0, 0xca, 0x2b, 0xcb,
  2493. 0xae, 0x7b, 0x30, 0xb4, 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30,
  2494. 0xf2, 0x0c, 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa };
  2495. /* Fill out hash function seeds */
  2496. for (j = 0; j < 10; j++) {
  2497. u32 rsskey = rsshash[(j * 4)];
  2498. rsskey |= rsshash[(j * 4) + 1] << 8;
  2499. rsskey |= rsshash[(j * 4) + 2] << 16;
  2500. rsskey |= rsshash[(j * 4) + 3] << 24;
  2501. array_wr32(E1000_RSSRK(0), j, rsskey);
  2502. }
  2503. num_rx_queues = adapter->rss_queues;
  2504. if (adapter->vfs_allocated_count) {
  2505. /* 82575 and 82576 supports 2 RSS queues for VMDq */
  2506. switch (hw->mac.type) {
  2507. case e1000_i350:
  2508. case e1000_82580:
  2509. num_rx_queues = 1;
  2510. shift = 0;
  2511. break;
  2512. case e1000_82576:
  2513. shift = 3;
  2514. num_rx_queues = 2;
  2515. break;
  2516. case e1000_82575:
  2517. shift = 2;
  2518. shift2 = 6;
  2519. default:
  2520. break;
  2521. }
  2522. } else {
  2523. if (hw->mac.type == e1000_82575)
  2524. shift = 6;
  2525. }
  2526. for (j = 0; j < (32 * 4); j++) {
  2527. reta.bytes[j & 3] = (j % num_rx_queues) << shift;
  2528. if (shift2)
  2529. reta.bytes[j & 3] |= num_rx_queues << shift2;
  2530. if ((j & 3) == 3)
  2531. wr32(E1000_RETA(j >> 2), reta.dword);
  2532. }
  2533. /*
  2534. * Disable raw packet checksumming so that RSS hash is placed in
  2535. * descriptor on writeback. No need to enable TCP/UDP/IP checksum
  2536. * offloads as they are enabled by default
  2537. */
  2538. rxcsum = rd32(E1000_RXCSUM);
  2539. rxcsum |= E1000_RXCSUM_PCSD;
  2540. if (adapter->hw.mac.type >= e1000_82576)
  2541. /* Enable Receive Checksum Offload for SCTP */
  2542. rxcsum |= E1000_RXCSUM_CRCOFL;
  2543. /* Don't need to set TUOFL or IPOFL, they default to 1 */
  2544. wr32(E1000_RXCSUM, rxcsum);
  2545. /* If VMDq is enabled then we set the appropriate mode for that, else
  2546. * we default to RSS so that an RSS hash is calculated per packet even
  2547. * if we are only using one queue */
  2548. if (adapter->vfs_allocated_count) {
  2549. if (hw->mac.type > e1000_82575) {
  2550. /* Set the default pool for the PF's first queue */
  2551. u32 vtctl = rd32(E1000_VT_CTL);
  2552. vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK |
  2553. E1000_VT_CTL_DISABLE_DEF_POOL);
  2554. vtctl |= adapter->vfs_allocated_count <<
  2555. E1000_VT_CTL_DEFAULT_POOL_SHIFT;
  2556. wr32(E1000_VT_CTL, vtctl);
  2557. }
  2558. if (adapter->rss_queues > 1)
  2559. mrqc = E1000_MRQC_ENABLE_VMDQ_RSS_2Q;
  2560. else
  2561. mrqc = E1000_MRQC_ENABLE_VMDQ;
  2562. } else {
  2563. mrqc = E1000_MRQC_ENABLE_RSS_4Q;
  2564. }
  2565. igb_vmm_control(adapter);
  2566. /*
  2567. * Generate RSS hash based on TCP port numbers and/or
  2568. * IPv4/v6 src and dst addresses since UDP cannot be
  2569. * hashed reliably due to IP fragmentation
  2570. */
  2571. mrqc |= E1000_MRQC_RSS_FIELD_IPV4 |
  2572. E1000_MRQC_RSS_FIELD_IPV4_TCP |
  2573. E1000_MRQC_RSS_FIELD_IPV6 |
  2574. E1000_MRQC_RSS_FIELD_IPV6_TCP |
  2575. E1000_MRQC_RSS_FIELD_IPV6_TCP_EX;
  2576. wr32(E1000_MRQC, mrqc);
  2577. }
  2578. /**
  2579. * igb_setup_rctl - configure the receive control registers
  2580. * @adapter: Board private structure
  2581. **/
  2582. void igb_setup_rctl(struct igb_adapter *adapter)
  2583. {
  2584. struct e1000_hw *hw = &adapter->hw;
  2585. u32 rctl;
  2586. rctl = rd32(E1000_RCTL);
  2587. rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
  2588. rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
  2589. rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF |
  2590. (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
  2591. /*
  2592. * enable stripping of CRC. It's unlikely this will break BMC
  2593. * redirection as it did with e1000. Newer features require
  2594. * that the HW strips the CRC.
  2595. */
  2596. rctl |= E1000_RCTL_SECRC;
  2597. /* disable store bad packets and clear size bits. */
  2598. rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256);
  2599. /* enable LPE to prevent packets larger than max_frame_size */
  2600. rctl |= E1000_RCTL_LPE;
  2601. /* disable queue 0 to prevent tail write w/o re-config */
  2602. wr32(E1000_RXDCTL(0), 0);
  2603. /* Attention!!! For SR-IOV PF driver operations you must enable
  2604. * queue drop for all VF and PF queues to prevent head of line blocking
  2605. * if an un-trusted VF does not provide descriptors to hardware.
  2606. */
  2607. if (adapter->vfs_allocated_count) {
  2608. /* set all queue drop enable bits */
  2609. wr32(E1000_QDE, ALL_QUEUES);
  2610. }
  2611. /* This is useful for sniffing bad packets. */
  2612. if (adapter->netdev->features & NETIF_F_RXALL) {
  2613. /* UPE and MPE will be handled by normal PROMISC logic
  2614. * in e1000e_set_rx_mode */
  2615. rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
  2616. E1000_RCTL_BAM | /* RX All Bcast Pkts */
  2617. E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
  2618. rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
  2619. E1000_RCTL_DPF | /* Allow filtered pause */
  2620. E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
  2621. /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
  2622. * and that breaks VLANs.
  2623. */
  2624. }
  2625. wr32(E1000_RCTL, rctl);
  2626. }
  2627. static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size,
  2628. int vfn)
  2629. {
  2630. struct e1000_hw *hw = &adapter->hw;
  2631. u32 vmolr;
  2632. /* if it isn't the PF check to see if VFs are enabled and
  2633. * increase the size to support vlan tags */
  2634. if (vfn < adapter->vfs_allocated_count &&
  2635. adapter->vf_data[vfn].vlans_enabled)
  2636. size += VLAN_TAG_SIZE;
  2637. vmolr = rd32(E1000_VMOLR(vfn));
  2638. vmolr &= ~E1000_VMOLR_RLPML_MASK;
  2639. vmolr |= size | E1000_VMOLR_LPE;
  2640. wr32(E1000_VMOLR(vfn), vmolr);
  2641. return 0;
  2642. }
  2643. /**
  2644. * igb_rlpml_set - set maximum receive packet size
  2645. * @adapter: board private structure
  2646. *
  2647. * Configure maximum receivable packet size.
  2648. **/
  2649. static void igb_rlpml_set(struct igb_adapter *adapter)
  2650. {
  2651. u32 max_frame_size = adapter->max_frame_size;
  2652. struct e1000_hw *hw = &adapter->hw;
  2653. u16 pf_id = adapter->vfs_allocated_count;
  2654. if (pf_id) {
  2655. igb_set_vf_rlpml(adapter, max_frame_size, pf_id);
  2656. /*
  2657. * If we're in VMDQ or SR-IOV mode, then set global RLPML
  2658. * to our max jumbo frame size, in case we need to enable
  2659. * jumbo frames on one of the rings later.
  2660. * This will not pass over-length frames into the default
  2661. * queue because it's gated by the VMOLR.RLPML.
  2662. */
  2663. max_frame_size = MAX_JUMBO_FRAME_SIZE;
  2664. }
  2665. wr32(E1000_RLPML, max_frame_size);
  2666. }
  2667. static inline void igb_set_vmolr(struct igb_adapter *adapter,
  2668. int vfn, bool aupe)
  2669. {
  2670. struct e1000_hw *hw = &adapter->hw;
  2671. u32 vmolr;
  2672. /*
  2673. * This register exists only on 82576 and newer so if we are older then
  2674. * we should exit and do nothing
  2675. */
  2676. if (hw->mac.type < e1000_82576)
  2677. return;
  2678. vmolr = rd32(E1000_VMOLR(vfn));
  2679. vmolr |= E1000_VMOLR_STRVLAN; /* Strip vlan tags */
  2680. if (aupe)
  2681. vmolr |= E1000_VMOLR_AUPE; /* Accept untagged packets */
  2682. else
  2683. vmolr &= ~(E1000_VMOLR_AUPE); /* Tagged packets ONLY */
  2684. /* clear all bits that might not be set */
  2685. vmolr &= ~(E1000_VMOLR_BAM | E1000_VMOLR_RSSE);
  2686. if (adapter->rss_queues > 1 && vfn == adapter->vfs_allocated_count)
  2687. vmolr |= E1000_VMOLR_RSSE; /* enable RSS */
  2688. /*
  2689. * for VMDq only allow the VFs and pool 0 to accept broadcast and
  2690. * multicast packets
  2691. */
  2692. if (vfn <= adapter->vfs_allocated_count)
  2693. vmolr |= E1000_VMOLR_BAM; /* Accept broadcast */
  2694. wr32(E1000_VMOLR(vfn), vmolr);
  2695. }
  2696. /**
  2697. * igb_configure_rx_ring - Configure a receive ring after Reset
  2698. * @adapter: board private structure
  2699. * @ring: receive ring to be configured
  2700. *
  2701. * Configure the Rx unit of the MAC after a reset.
  2702. **/
  2703. void igb_configure_rx_ring(struct igb_adapter *adapter,
  2704. struct igb_ring *ring)
  2705. {
  2706. struct e1000_hw *hw = &adapter->hw;
  2707. u64 rdba = ring->dma;
  2708. int reg_idx = ring->reg_idx;
  2709. u32 srrctl = 0, rxdctl = 0;
  2710. /* disable the queue */
  2711. wr32(E1000_RXDCTL(reg_idx), 0);
  2712. /* Set DMA base address registers */
  2713. wr32(E1000_RDBAL(reg_idx),
  2714. rdba & 0x00000000ffffffffULL);
  2715. wr32(E1000_RDBAH(reg_idx), rdba >> 32);
  2716. wr32(E1000_RDLEN(reg_idx),
  2717. ring->count * sizeof(union e1000_adv_rx_desc));
  2718. /* initialize head and tail */
  2719. ring->tail = hw->hw_addr + E1000_RDT(reg_idx);
  2720. wr32(E1000_RDH(reg_idx), 0);
  2721. writel(0, ring->tail);
  2722. /* set descriptor configuration */
  2723. srrctl = IGB_RX_HDR_LEN << E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
  2724. #if (PAGE_SIZE / 2) > IGB_RXBUFFER_16384
  2725. srrctl |= IGB_RXBUFFER_16384 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
  2726. #else
  2727. srrctl |= (PAGE_SIZE / 2) >> E1000_SRRCTL_BSIZEPKT_SHIFT;
  2728. #endif
  2729. srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
  2730. if (hw->mac.type >= e1000_82580)
  2731. srrctl |= E1000_SRRCTL_TIMESTAMP;
  2732. /* Only set Drop Enable if we are supporting multiple queues */
  2733. if (adapter->vfs_allocated_count || adapter->num_rx_queues > 1)
  2734. srrctl |= E1000_SRRCTL_DROP_EN;
  2735. wr32(E1000_SRRCTL(reg_idx), srrctl);
  2736. /* set filtering for VMDQ pools */
  2737. igb_set_vmolr(adapter, reg_idx & 0x7, true);
  2738. rxdctl |= IGB_RX_PTHRESH;
  2739. rxdctl |= IGB_RX_HTHRESH << 8;
  2740. rxdctl |= IGB_RX_WTHRESH << 16;
  2741. /* enable receive descriptor fetching */
  2742. rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
  2743. wr32(E1000_RXDCTL(reg_idx), rxdctl);
  2744. }
  2745. /**
  2746. * igb_configure_rx - Configure receive Unit after Reset
  2747. * @adapter: board private structure
  2748. *
  2749. * Configure the Rx unit of the MAC after a reset.
  2750. **/
  2751. static void igb_configure_rx(struct igb_adapter *adapter)
  2752. {
  2753. int i;
  2754. /* set UTA to appropriate mode */
  2755. igb_set_uta(adapter);
  2756. /* set the correct pool for the PF default MAC address in entry 0 */
  2757. igb_rar_set_qsel(adapter, adapter->hw.mac.addr, 0,
  2758. adapter->vfs_allocated_count);
  2759. /* Setup the HW Rx Head and Tail Descriptor Pointers and
  2760. * the Base and Length of the Rx Descriptor Ring */
  2761. for (i = 0; i < adapter->num_rx_queues; i++)
  2762. igb_configure_rx_ring(adapter, adapter->rx_ring[i]);
  2763. }
  2764. /**
  2765. * igb_free_tx_resources - Free Tx Resources per Queue
  2766. * @tx_ring: Tx descriptor ring for a specific queue
  2767. *
  2768. * Free all transmit software resources
  2769. **/
  2770. void igb_free_tx_resources(struct igb_ring *tx_ring)
  2771. {
  2772. igb_clean_tx_ring(tx_ring);
  2773. vfree(tx_ring->tx_buffer_info);
  2774. tx_ring->tx_buffer_info = NULL;
  2775. /* if not set, then don't free */
  2776. if (!tx_ring->desc)
  2777. return;
  2778. dma_free_coherent(tx_ring->dev, tx_ring->size,
  2779. tx_ring->desc, tx_ring->dma);
  2780. tx_ring->desc = NULL;
  2781. }
  2782. /**
  2783. * igb_free_all_tx_resources - Free Tx Resources for All Queues
  2784. * @adapter: board private structure
  2785. *
  2786. * Free all transmit software resources
  2787. **/
  2788. static void igb_free_all_tx_resources(struct igb_adapter *adapter)
  2789. {
  2790. int i;
  2791. for (i = 0; i < adapter->num_tx_queues; i++)
  2792. igb_free_tx_resources(adapter->tx_ring[i]);
  2793. }
  2794. void igb_unmap_and_free_tx_resource(struct igb_ring *ring,
  2795. struct igb_tx_buffer *tx_buffer)
  2796. {
  2797. if (tx_buffer->skb) {
  2798. dev_kfree_skb_any(tx_buffer->skb);
  2799. if (tx_buffer->dma)
  2800. dma_unmap_single(ring->dev,
  2801. tx_buffer->dma,
  2802. tx_buffer->length,
  2803. DMA_TO_DEVICE);
  2804. } else if (tx_buffer->dma) {
  2805. dma_unmap_page(ring->dev,
  2806. tx_buffer->dma,
  2807. tx_buffer->length,
  2808. DMA_TO_DEVICE);
  2809. }
  2810. tx_buffer->next_to_watch = NULL;
  2811. tx_buffer->skb = NULL;
  2812. tx_buffer->dma = 0;
  2813. /* buffer_info must be completely set up in the transmit path */
  2814. }
  2815. /**
  2816. * igb_clean_tx_ring - Free Tx Buffers
  2817. * @tx_ring: ring to be cleaned
  2818. **/
  2819. static void igb_clean_tx_ring(struct igb_ring *tx_ring)
  2820. {
  2821. struct igb_tx_buffer *buffer_info;
  2822. unsigned long size;
  2823. u16 i;
  2824. if (!tx_ring->tx_buffer_info)
  2825. return;
  2826. /* Free all the Tx ring sk_buffs */
  2827. for (i = 0; i < tx_ring->count; i++) {
  2828. buffer_info = &tx_ring->tx_buffer_info[i];
  2829. igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
  2830. }
  2831. size = sizeof(struct igb_tx_buffer) * tx_ring->count;
  2832. memset(tx_ring->tx_buffer_info, 0, size);
  2833. /* Zero out the descriptor ring */
  2834. memset(tx_ring->desc, 0, tx_ring->size);
  2835. tx_ring->next_to_use = 0;
  2836. tx_ring->next_to_clean = 0;
  2837. }
  2838. /**
  2839. * igb_clean_all_tx_rings - Free Tx Buffers for all queues
  2840. * @adapter: board private structure
  2841. **/
  2842. static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
  2843. {
  2844. int i;
  2845. for (i = 0; i < adapter->num_tx_queues; i++)
  2846. igb_clean_tx_ring(adapter->tx_ring[i]);
  2847. }
  2848. /**
  2849. * igb_free_rx_resources - Free Rx Resources
  2850. * @rx_ring: ring to clean the resources from
  2851. *
  2852. * Free all receive software resources
  2853. **/
  2854. void igb_free_rx_resources(struct igb_ring *rx_ring)
  2855. {
  2856. igb_clean_rx_ring(rx_ring);
  2857. vfree(rx_ring->rx_buffer_info);
  2858. rx_ring->rx_buffer_info = NULL;
  2859. /* if not set, then don't free */
  2860. if (!rx_ring->desc)
  2861. return;
  2862. dma_free_coherent(rx_ring->dev, rx_ring->size,
  2863. rx_ring->desc, rx_ring->dma);
  2864. rx_ring->desc = NULL;
  2865. }
  2866. /**
  2867. * igb_free_all_rx_resources - Free Rx Resources for All Queues
  2868. * @adapter: board private structure
  2869. *
  2870. * Free all receive software resources
  2871. **/
  2872. static void igb_free_all_rx_resources(struct igb_adapter *adapter)
  2873. {
  2874. int i;
  2875. for (i = 0; i < adapter->num_rx_queues; i++)
  2876. igb_free_rx_resources(adapter->rx_ring[i]);
  2877. }
  2878. /**
  2879. * igb_clean_rx_ring - Free Rx Buffers per Queue
  2880. * @rx_ring: ring to free buffers from
  2881. **/
  2882. static void igb_clean_rx_ring(struct igb_ring *rx_ring)
  2883. {
  2884. unsigned long size;
  2885. u16 i;
  2886. if (!rx_ring->rx_buffer_info)
  2887. return;
  2888. /* Free all the Rx ring sk_buffs */
  2889. for (i = 0; i < rx_ring->count; i++) {
  2890. struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i];
  2891. if (buffer_info->dma) {
  2892. dma_unmap_single(rx_ring->dev,
  2893. buffer_info->dma,
  2894. IGB_RX_HDR_LEN,
  2895. DMA_FROM_DEVICE);
  2896. buffer_info->dma = 0;
  2897. }
  2898. if (buffer_info->skb) {
  2899. dev_kfree_skb(buffer_info->skb);
  2900. buffer_info->skb = NULL;
  2901. }
  2902. if (buffer_info->page_dma) {
  2903. dma_unmap_page(rx_ring->dev,
  2904. buffer_info->page_dma,
  2905. PAGE_SIZE / 2,
  2906. DMA_FROM_DEVICE);
  2907. buffer_info->page_dma = 0;
  2908. }
  2909. if (buffer_info->page) {
  2910. put_page(buffer_info->page);
  2911. buffer_info->page = NULL;
  2912. buffer_info->page_offset = 0;
  2913. }
  2914. }
  2915. size = sizeof(struct igb_rx_buffer) * rx_ring->count;
  2916. memset(rx_ring->rx_buffer_info, 0, size);
  2917. /* Zero out the descriptor ring */
  2918. memset(rx_ring->desc, 0, rx_ring->size);
  2919. rx_ring->next_to_clean = 0;
  2920. rx_ring->next_to_use = 0;
  2921. }
  2922. /**
  2923. * igb_clean_all_rx_rings - Free Rx Buffers for all queues
  2924. * @adapter: board private structure
  2925. **/
  2926. static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
  2927. {
  2928. int i;
  2929. for (i = 0; i < adapter->num_rx_queues; i++)
  2930. igb_clean_rx_ring(adapter->rx_ring[i]);
  2931. }
  2932. /**
  2933. * igb_set_mac - Change the Ethernet Address of the NIC
  2934. * @netdev: network interface device structure
  2935. * @p: pointer to an address structure
  2936. *
  2937. * Returns 0 on success, negative on failure
  2938. **/
  2939. static int igb_set_mac(struct net_device *netdev, void *p)
  2940. {
  2941. struct igb_adapter *adapter = netdev_priv(netdev);
  2942. struct e1000_hw *hw = &adapter->hw;
  2943. struct sockaddr *addr = p;
  2944. if (!is_valid_ether_addr(addr->sa_data))
  2945. return -EADDRNOTAVAIL;
  2946. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  2947. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  2948. /* set the correct pool for the new PF MAC address in entry 0 */
  2949. igb_rar_set_qsel(adapter, hw->mac.addr, 0,
  2950. adapter->vfs_allocated_count);
  2951. return 0;
  2952. }
  2953. /**
  2954. * igb_write_mc_addr_list - write multicast addresses to MTA
  2955. * @netdev: network interface device structure
  2956. *
  2957. * Writes multicast address list to the MTA hash table.
  2958. * Returns: -ENOMEM on failure
  2959. * 0 on no addresses written
  2960. * X on writing X addresses to MTA
  2961. **/
  2962. static int igb_write_mc_addr_list(struct net_device *netdev)
  2963. {
  2964. struct igb_adapter *adapter = netdev_priv(netdev);
  2965. struct e1000_hw *hw = &adapter->hw;
  2966. struct netdev_hw_addr *ha;
  2967. u8 *mta_list;
  2968. int i;
  2969. if (netdev_mc_empty(netdev)) {
  2970. /* nothing to program, so clear mc list */
  2971. igb_update_mc_addr_list(hw, NULL, 0);
  2972. igb_restore_vf_multicasts(adapter);
  2973. return 0;
  2974. }
  2975. mta_list = kzalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
  2976. if (!mta_list)
  2977. return -ENOMEM;
  2978. /* The shared function expects a packed array of only addresses. */
  2979. i = 0;
  2980. netdev_for_each_mc_addr(ha, netdev)
  2981. memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
  2982. igb_update_mc_addr_list(hw, mta_list, i);
  2983. kfree(mta_list);
  2984. return netdev_mc_count(netdev);
  2985. }
  2986. /**
  2987. * igb_write_uc_addr_list - write unicast addresses to RAR table
  2988. * @netdev: network interface device structure
  2989. *
  2990. * Writes unicast address list to the RAR table.
  2991. * Returns: -ENOMEM on failure/insufficient address space
  2992. * 0 on no addresses written
  2993. * X on writing X addresses to the RAR table
  2994. **/
  2995. static int igb_write_uc_addr_list(struct net_device *netdev)
  2996. {
  2997. struct igb_adapter *adapter = netdev_priv(netdev);
  2998. struct e1000_hw *hw = &adapter->hw;
  2999. unsigned int vfn = adapter->vfs_allocated_count;
  3000. unsigned int rar_entries = hw->mac.rar_entry_count - (vfn + 1);
  3001. int count = 0;
  3002. /* return ENOMEM indicating insufficient memory for addresses */
  3003. if (netdev_uc_count(netdev) > rar_entries)
  3004. return -ENOMEM;
  3005. if (!netdev_uc_empty(netdev) && rar_entries) {
  3006. struct netdev_hw_addr *ha;
  3007. netdev_for_each_uc_addr(ha, netdev) {
  3008. if (!rar_entries)
  3009. break;
  3010. igb_rar_set_qsel(adapter, ha->addr,
  3011. rar_entries--,
  3012. vfn);
  3013. count++;
  3014. }
  3015. }
  3016. /* write the addresses in reverse order to avoid write combining */
  3017. for (; rar_entries > 0 ; rar_entries--) {
  3018. wr32(E1000_RAH(rar_entries), 0);
  3019. wr32(E1000_RAL(rar_entries), 0);
  3020. }
  3021. wrfl();
  3022. return count;
  3023. }
  3024. /**
  3025. * igb_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
  3026. * @netdev: network interface device structure
  3027. *
  3028. * The set_rx_mode entry point is called whenever the unicast or multicast
  3029. * address lists or the network interface flags are updated. This routine is
  3030. * responsible for configuring the hardware for proper unicast, multicast,
  3031. * promiscuous mode, and all-multi behavior.
  3032. **/
  3033. static void igb_set_rx_mode(struct net_device *netdev)
  3034. {
  3035. struct igb_adapter *adapter = netdev_priv(netdev);
  3036. struct e1000_hw *hw = &adapter->hw;
  3037. unsigned int vfn = adapter->vfs_allocated_count;
  3038. u32 rctl, vmolr = 0;
  3039. int count;
  3040. /* Check for Promiscuous and All Multicast modes */
  3041. rctl = rd32(E1000_RCTL);
  3042. /* clear the effected bits */
  3043. rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_VFE);
  3044. if (netdev->flags & IFF_PROMISC) {
  3045. rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
  3046. vmolr |= (E1000_VMOLR_ROPE | E1000_VMOLR_MPME);
  3047. } else {
  3048. if (netdev->flags & IFF_ALLMULTI) {
  3049. rctl |= E1000_RCTL_MPE;
  3050. vmolr |= E1000_VMOLR_MPME;
  3051. } else {
  3052. /*
  3053. * Write addresses to the MTA, if the attempt fails
  3054. * then we should just turn on promiscuous mode so
  3055. * that we can at least receive multicast traffic
  3056. */
  3057. count = igb_write_mc_addr_list(netdev);
  3058. if (count < 0) {
  3059. rctl |= E1000_RCTL_MPE;
  3060. vmolr |= E1000_VMOLR_MPME;
  3061. } else if (count) {
  3062. vmolr |= E1000_VMOLR_ROMPE;
  3063. }
  3064. }
  3065. /*
  3066. * Write addresses to available RAR registers, if there is not
  3067. * sufficient space to store all the addresses then enable
  3068. * unicast promiscuous mode
  3069. */
  3070. count = igb_write_uc_addr_list(netdev);
  3071. if (count < 0) {
  3072. rctl |= E1000_RCTL_UPE;
  3073. vmolr |= E1000_VMOLR_ROPE;
  3074. }
  3075. rctl |= E1000_RCTL_VFE;
  3076. }
  3077. wr32(E1000_RCTL, rctl);
  3078. /*
  3079. * In order to support SR-IOV and eventually VMDq it is necessary to set
  3080. * the VMOLR to enable the appropriate modes. Without this workaround
  3081. * we will have issues with VLAN tag stripping not being done for frames
  3082. * that are only arriving because we are the default pool
  3083. */
  3084. if (hw->mac.type < e1000_82576)
  3085. return;
  3086. vmolr |= rd32(E1000_VMOLR(vfn)) &
  3087. ~(E1000_VMOLR_ROPE | E1000_VMOLR_MPME | E1000_VMOLR_ROMPE);
  3088. wr32(E1000_VMOLR(vfn), vmolr);
  3089. igb_restore_vf_multicasts(adapter);
  3090. }
  3091. static void igb_check_wvbr(struct igb_adapter *adapter)
  3092. {
  3093. struct e1000_hw *hw = &adapter->hw;
  3094. u32 wvbr = 0;
  3095. switch (hw->mac.type) {
  3096. case e1000_82576:
  3097. case e1000_i350:
  3098. if (!(wvbr = rd32(E1000_WVBR)))
  3099. return;
  3100. break;
  3101. default:
  3102. break;
  3103. }
  3104. adapter->wvbr |= wvbr;
  3105. }
  3106. #define IGB_STAGGERED_QUEUE_OFFSET 8
  3107. static void igb_spoof_check(struct igb_adapter *adapter)
  3108. {
  3109. int j;
  3110. if (!adapter->wvbr)
  3111. return;
  3112. for(j = 0; j < adapter->vfs_allocated_count; j++) {
  3113. if (adapter->wvbr & (1 << j) ||
  3114. adapter->wvbr & (1 << (j + IGB_STAGGERED_QUEUE_OFFSET))) {
  3115. dev_warn(&adapter->pdev->dev,
  3116. "Spoof event(s) detected on VF %d\n", j);
  3117. adapter->wvbr &=
  3118. ~((1 << j) |
  3119. (1 << (j + IGB_STAGGERED_QUEUE_OFFSET)));
  3120. }
  3121. }
  3122. }
  3123. /* Need to wait a few seconds after link up to get diagnostic information from
  3124. * the phy */
  3125. static void igb_update_phy_info(unsigned long data)
  3126. {
  3127. struct igb_adapter *adapter = (struct igb_adapter *) data;
  3128. igb_get_phy_info(&adapter->hw);
  3129. }
  3130. /**
  3131. * igb_has_link - check shared code for link and determine up/down
  3132. * @adapter: pointer to driver private info
  3133. **/
  3134. bool igb_has_link(struct igb_adapter *adapter)
  3135. {
  3136. struct e1000_hw *hw = &adapter->hw;
  3137. bool link_active = false;
  3138. s32 ret_val = 0;
  3139. /* get_link_status is set on LSC (link status) interrupt or
  3140. * rx sequence error interrupt. get_link_status will stay
  3141. * false until the e1000_check_for_link establishes link
  3142. * for copper adapters ONLY
  3143. */
  3144. switch (hw->phy.media_type) {
  3145. case e1000_media_type_copper:
  3146. if (hw->mac.get_link_status) {
  3147. ret_val = hw->mac.ops.check_for_link(hw);
  3148. link_active = !hw->mac.get_link_status;
  3149. } else {
  3150. link_active = true;
  3151. }
  3152. break;
  3153. case e1000_media_type_internal_serdes:
  3154. ret_val = hw->mac.ops.check_for_link(hw);
  3155. link_active = hw->mac.serdes_has_link;
  3156. break;
  3157. default:
  3158. case e1000_media_type_unknown:
  3159. break;
  3160. }
  3161. return link_active;
  3162. }
  3163. static bool igb_thermal_sensor_event(struct e1000_hw *hw, u32 event)
  3164. {
  3165. bool ret = false;
  3166. u32 ctrl_ext, thstat;
  3167. /* check for thermal sensor event on i350, copper only */
  3168. if (hw->mac.type == e1000_i350) {
  3169. thstat = rd32(E1000_THSTAT);
  3170. ctrl_ext = rd32(E1000_CTRL_EXT);
  3171. if ((hw->phy.media_type == e1000_media_type_copper) &&
  3172. !(ctrl_ext & E1000_CTRL_EXT_LINK_MODE_SGMII)) {
  3173. ret = !!(thstat & event);
  3174. }
  3175. }
  3176. return ret;
  3177. }
  3178. /**
  3179. * igb_watchdog - Timer Call-back
  3180. * @data: pointer to adapter cast into an unsigned long
  3181. **/
  3182. static void igb_watchdog(unsigned long data)
  3183. {
  3184. struct igb_adapter *adapter = (struct igb_adapter *)data;
  3185. /* Do the rest outside of interrupt context */
  3186. schedule_work(&adapter->watchdog_task);
  3187. }
  3188. static void igb_watchdog_task(struct work_struct *work)
  3189. {
  3190. struct igb_adapter *adapter = container_of(work,
  3191. struct igb_adapter,
  3192. watchdog_task);
  3193. struct e1000_hw *hw = &adapter->hw;
  3194. struct net_device *netdev = adapter->netdev;
  3195. u32 link;
  3196. int i;
  3197. link = igb_has_link(adapter);
  3198. if (link) {
  3199. /* Cancel scheduled suspend requests. */
  3200. pm_runtime_resume(netdev->dev.parent);
  3201. if (!netif_carrier_ok(netdev)) {
  3202. u32 ctrl;
  3203. hw->mac.ops.get_speed_and_duplex(hw,
  3204. &adapter->link_speed,
  3205. &adapter->link_duplex);
  3206. ctrl = rd32(E1000_CTRL);
  3207. /* Links status message must follow this format */
  3208. printk(KERN_INFO "igb: %s NIC Link is Up %d Mbps %s "
  3209. "Duplex, Flow Control: %s\n",
  3210. netdev->name,
  3211. adapter->link_speed,
  3212. adapter->link_duplex == FULL_DUPLEX ?
  3213. "Full" : "Half",
  3214. (ctrl & E1000_CTRL_TFCE) &&
  3215. (ctrl & E1000_CTRL_RFCE) ? "RX/TX" :
  3216. (ctrl & E1000_CTRL_RFCE) ? "RX" :
  3217. (ctrl & E1000_CTRL_TFCE) ? "TX" : "None");
  3218. /* check for thermal sensor event */
  3219. if (igb_thermal_sensor_event(hw,
  3220. E1000_THSTAT_LINK_THROTTLE)) {
  3221. netdev_info(netdev, "The network adapter link "
  3222. "speed was downshifted because it "
  3223. "overheated\n");
  3224. }
  3225. /* adjust timeout factor according to speed/duplex */
  3226. adapter->tx_timeout_factor = 1;
  3227. switch (adapter->link_speed) {
  3228. case SPEED_10:
  3229. adapter->tx_timeout_factor = 14;
  3230. break;
  3231. case SPEED_100:
  3232. /* maybe add some timeout factor ? */
  3233. break;
  3234. }
  3235. netif_carrier_on(netdev);
  3236. igb_ping_all_vfs(adapter);
  3237. igb_check_vf_rate_limit(adapter);
  3238. /* link state has changed, schedule phy info update */
  3239. if (!test_bit(__IGB_DOWN, &adapter->state))
  3240. mod_timer(&adapter->phy_info_timer,
  3241. round_jiffies(jiffies + 2 * HZ));
  3242. }
  3243. } else {
  3244. if (netif_carrier_ok(netdev)) {
  3245. adapter->link_speed = 0;
  3246. adapter->link_duplex = 0;
  3247. /* check for thermal sensor event */
  3248. if (igb_thermal_sensor_event(hw,
  3249. E1000_THSTAT_PWR_DOWN)) {
  3250. netdev_err(netdev, "The network adapter was "
  3251. "stopped because it overheated\n");
  3252. }
  3253. /* Links status message must follow this format */
  3254. printk(KERN_INFO "igb: %s NIC Link is Down\n",
  3255. netdev->name);
  3256. netif_carrier_off(netdev);
  3257. igb_ping_all_vfs(adapter);
  3258. /* link state has changed, schedule phy info update */
  3259. if (!test_bit(__IGB_DOWN, &adapter->state))
  3260. mod_timer(&adapter->phy_info_timer,
  3261. round_jiffies(jiffies + 2 * HZ));
  3262. pm_schedule_suspend(netdev->dev.parent,
  3263. MSEC_PER_SEC * 5);
  3264. }
  3265. }
  3266. spin_lock(&adapter->stats64_lock);
  3267. igb_update_stats(adapter, &adapter->stats64);
  3268. spin_unlock(&adapter->stats64_lock);
  3269. for (i = 0; i < adapter->num_tx_queues; i++) {
  3270. struct igb_ring *tx_ring = adapter->tx_ring[i];
  3271. if (!netif_carrier_ok(netdev)) {
  3272. /* We've lost link, so the controller stops DMA,
  3273. * but we've got queued Tx work that's never going
  3274. * to get done, so reset controller to flush Tx.
  3275. * (Do the reset outside of interrupt context). */
  3276. if (igb_desc_unused(tx_ring) + 1 < tx_ring->count) {
  3277. adapter->tx_timeout_count++;
  3278. schedule_work(&adapter->reset_task);
  3279. /* return immediately since reset is imminent */
  3280. return;
  3281. }
  3282. }
  3283. /* Force detection of hung controller every watchdog period */
  3284. set_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
  3285. }
  3286. /* Cause software interrupt to ensure rx ring is cleaned */
  3287. if (adapter->msix_entries) {
  3288. u32 eics = 0;
  3289. for (i = 0; i < adapter->num_q_vectors; i++)
  3290. eics |= adapter->q_vector[i]->eims_value;
  3291. wr32(E1000_EICS, eics);
  3292. } else {
  3293. wr32(E1000_ICS, E1000_ICS_RXDMT0);
  3294. }
  3295. igb_spoof_check(adapter);
  3296. /* Reset the timer */
  3297. if (!test_bit(__IGB_DOWN, &adapter->state))
  3298. mod_timer(&adapter->watchdog_timer,
  3299. round_jiffies(jiffies + 2 * HZ));
  3300. }
  3301. enum latency_range {
  3302. lowest_latency = 0,
  3303. low_latency = 1,
  3304. bulk_latency = 2,
  3305. latency_invalid = 255
  3306. };
  3307. /**
  3308. * igb_update_ring_itr - update the dynamic ITR value based on packet size
  3309. *
  3310. * Stores a new ITR value based on strictly on packet size. This
  3311. * algorithm is less sophisticated than that used in igb_update_itr,
  3312. * due to the difficulty of synchronizing statistics across multiple
  3313. * receive rings. The divisors and thresholds used by this function
  3314. * were determined based on theoretical maximum wire speed and testing
  3315. * data, in order to minimize response time while increasing bulk
  3316. * throughput.
  3317. * This functionality is controlled by the InterruptThrottleRate module
  3318. * parameter (see igb_param.c)
  3319. * NOTE: This function is called only when operating in a multiqueue
  3320. * receive environment.
  3321. * @q_vector: pointer to q_vector
  3322. **/
  3323. static void igb_update_ring_itr(struct igb_q_vector *q_vector)
  3324. {
  3325. int new_val = q_vector->itr_val;
  3326. int avg_wire_size = 0;
  3327. struct igb_adapter *adapter = q_vector->adapter;
  3328. unsigned int packets;
  3329. /* For non-gigabit speeds, just fix the interrupt rate at 4000
  3330. * ints/sec - ITR timer value of 120 ticks.
  3331. */
  3332. if (adapter->link_speed != SPEED_1000) {
  3333. new_val = IGB_4K_ITR;
  3334. goto set_itr_val;
  3335. }
  3336. packets = q_vector->rx.total_packets;
  3337. if (packets)
  3338. avg_wire_size = q_vector->rx.total_bytes / packets;
  3339. packets = q_vector->tx.total_packets;
  3340. if (packets)
  3341. avg_wire_size = max_t(u32, avg_wire_size,
  3342. q_vector->tx.total_bytes / packets);
  3343. /* if avg_wire_size isn't set no work was done */
  3344. if (!avg_wire_size)
  3345. goto clear_counts;
  3346. /* Add 24 bytes to size to account for CRC, preamble, and gap */
  3347. avg_wire_size += 24;
  3348. /* Don't starve jumbo frames */
  3349. avg_wire_size = min(avg_wire_size, 3000);
  3350. /* Give a little boost to mid-size frames */
  3351. if ((avg_wire_size > 300) && (avg_wire_size < 1200))
  3352. new_val = avg_wire_size / 3;
  3353. else
  3354. new_val = avg_wire_size / 2;
  3355. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  3356. if (new_val < IGB_20K_ITR &&
  3357. ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
  3358. (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
  3359. new_val = IGB_20K_ITR;
  3360. set_itr_val:
  3361. if (new_val != q_vector->itr_val) {
  3362. q_vector->itr_val = new_val;
  3363. q_vector->set_itr = 1;
  3364. }
  3365. clear_counts:
  3366. q_vector->rx.total_bytes = 0;
  3367. q_vector->rx.total_packets = 0;
  3368. q_vector->tx.total_bytes = 0;
  3369. q_vector->tx.total_packets = 0;
  3370. }
  3371. /**
  3372. * igb_update_itr - update the dynamic ITR value based on statistics
  3373. * Stores a new ITR value based on packets and byte
  3374. * counts during the last interrupt. The advantage of per interrupt
  3375. * computation is faster updates and more accurate ITR for the current
  3376. * traffic pattern. Constants in this function were computed
  3377. * based on theoretical maximum wire speed and thresholds were set based
  3378. * on testing data as well as attempting to minimize response time
  3379. * while increasing bulk throughput.
  3380. * this functionality is controlled by the InterruptThrottleRate module
  3381. * parameter (see igb_param.c)
  3382. * NOTE: These calculations are only valid when operating in a single-
  3383. * queue environment.
  3384. * @q_vector: pointer to q_vector
  3385. * @ring_container: ring info to update the itr for
  3386. **/
  3387. static void igb_update_itr(struct igb_q_vector *q_vector,
  3388. struct igb_ring_container *ring_container)
  3389. {
  3390. unsigned int packets = ring_container->total_packets;
  3391. unsigned int bytes = ring_container->total_bytes;
  3392. u8 itrval = ring_container->itr;
  3393. /* no packets, exit with status unchanged */
  3394. if (packets == 0)
  3395. return;
  3396. switch (itrval) {
  3397. case lowest_latency:
  3398. /* handle TSO and jumbo frames */
  3399. if (bytes/packets > 8000)
  3400. itrval = bulk_latency;
  3401. else if ((packets < 5) && (bytes > 512))
  3402. itrval = low_latency;
  3403. break;
  3404. case low_latency: /* 50 usec aka 20000 ints/s */
  3405. if (bytes > 10000) {
  3406. /* this if handles the TSO accounting */
  3407. if (bytes/packets > 8000) {
  3408. itrval = bulk_latency;
  3409. } else if ((packets < 10) || ((bytes/packets) > 1200)) {
  3410. itrval = bulk_latency;
  3411. } else if ((packets > 35)) {
  3412. itrval = lowest_latency;
  3413. }
  3414. } else if (bytes/packets > 2000) {
  3415. itrval = bulk_latency;
  3416. } else if (packets <= 2 && bytes < 512) {
  3417. itrval = lowest_latency;
  3418. }
  3419. break;
  3420. case bulk_latency: /* 250 usec aka 4000 ints/s */
  3421. if (bytes > 25000) {
  3422. if (packets > 35)
  3423. itrval = low_latency;
  3424. } else if (bytes < 1500) {
  3425. itrval = low_latency;
  3426. }
  3427. break;
  3428. }
  3429. /* clear work counters since we have the values we need */
  3430. ring_container->total_bytes = 0;
  3431. ring_container->total_packets = 0;
  3432. /* write updated itr to ring container */
  3433. ring_container->itr = itrval;
  3434. }
  3435. static void igb_set_itr(struct igb_q_vector *q_vector)
  3436. {
  3437. struct igb_adapter *adapter = q_vector->adapter;
  3438. u32 new_itr = q_vector->itr_val;
  3439. u8 current_itr = 0;
  3440. /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
  3441. if (adapter->link_speed != SPEED_1000) {
  3442. current_itr = 0;
  3443. new_itr = IGB_4K_ITR;
  3444. goto set_itr_now;
  3445. }
  3446. igb_update_itr(q_vector, &q_vector->tx);
  3447. igb_update_itr(q_vector, &q_vector->rx);
  3448. current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
  3449. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  3450. if (current_itr == lowest_latency &&
  3451. ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
  3452. (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
  3453. current_itr = low_latency;
  3454. switch (current_itr) {
  3455. /* counts and packets in update_itr are dependent on these numbers */
  3456. case lowest_latency:
  3457. new_itr = IGB_70K_ITR; /* 70,000 ints/sec */
  3458. break;
  3459. case low_latency:
  3460. new_itr = IGB_20K_ITR; /* 20,000 ints/sec */
  3461. break;
  3462. case bulk_latency:
  3463. new_itr = IGB_4K_ITR; /* 4,000 ints/sec */
  3464. break;
  3465. default:
  3466. break;
  3467. }
  3468. set_itr_now:
  3469. if (new_itr != q_vector->itr_val) {
  3470. /* this attempts to bias the interrupt rate towards Bulk
  3471. * by adding intermediate steps when interrupt rate is
  3472. * increasing */
  3473. new_itr = new_itr > q_vector->itr_val ?
  3474. max((new_itr * q_vector->itr_val) /
  3475. (new_itr + (q_vector->itr_val >> 2)),
  3476. new_itr) :
  3477. new_itr;
  3478. /* Don't write the value here; it resets the adapter's
  3479. * internal timer, and causes us to delay far longer than
  3480. * we should between interrupts. Instead, we write the ITR
  3481. * value at the beginning of the next interrupt so the timing
  3482. * ends up being correct.
  3483. */
  3484. q_vector->itr_val = new_itr;
  3485. q_vector->set_itr = 1;
  3486. }
  3487. }
  3488. static void igb_tx_ctxtdesc(struct igb_ring *tx_ring, u32 vlan_macip_lens,
  3489. u32 type_tucmd, u32 mss_l4len_idx)
  3490. {
  3491. struct e1000_adv_tx_context_desc *context_desc;
  3492. u16 i = tx_ring->next_to_use;
  3493. context_desc = IGB_TX_CTXTDESC(tx_ring, i);
  3494. i++;
  3495. tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
  3496. /* set bits to identify this as an advanced context descriptor */
  3497. type_tucmd |= E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT;
  3498. /* For 82575, context index must be unique per ring. */
  3499. if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
  3500. mss_l4len_idx |= tx_ring->reg_idx << 4;
  3501. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  3502. context_desc->seqnum_seed = 0;
  3503. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
  3504. context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
  3505. }
  3506. static int igb_tso(struct igb_ring *tx_ring,
  3507. struct igb_tx_buffer *first,
  3508. u8 *hdr_len)
  3509. {
  3510. struct sk_buff *skb = first->skb;
  3511. u32 vlan_macip_lens, type_tucmd;
  3512. u32 mss_l4len_idx, l4len;
  3513. if (!skb_is_gso(skb))
  3514. return 0;
  3515. if (skb_header_cloned(skb)) {
  3516. int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  3517. if (err)
  3518. return err;
  3519. }
  3520. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  3521. type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP;
  3522. if (first->protocol == __constant_htons(ETH_P_IP)) {
  3523. struct iphdr *iph = ip_hdr(skb);
  3524. iph->tot_len = 0;
  3525. iph->check = 0;
  3526. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  3527. iph->daddr, 0,
  3528. IPPROTO_TCP,
  3529. 0);
  3530. type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
  3531. first->tx_flags |= IGB_TX_FLAGS_TSO |
  3532. IGB_TX_FLAGS_CSUM |
  3533. IGB_TX_FLAGS_IPV4;
  3534. } else if (skb_is_gso_v6(skb)) {
  3535. ipv6_hdr(skb)->payload_len = 0;
  3536. tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  3537. &ipv6_hdr(skb)->daddr,
  3538. 0, IPPROTO_TCP, 0);
  3539. first->tx_flags |= IGB_TX_FLAGS_TSO |
  3540. IGB_TX_FLAGS_CSUM;
  3541. }
  3542. /* compute header lengths */
  3543. l4len = tcp_hdrlen(skb);
  3544. *hdr_len = skb_transport_offset(skb) + l4len;
  3545. /* update gso size and bytecount with header size */
  3546. first->gso_segs = skb_shinfo(skb)->gso_segs;
  3547. first->bytecount += (first->gso_segs - 1) * *hdr_len;
  3548. /* MSS L4LEN IDX */
  3549. mss_l4len_idx = l4len << E1000_ADVTXD_L4LEN_SHIFT;
  3550. mss_l4len_idx |= skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT;
  3551. /* VLAN MACLEN IPLEN */
  3552. vlan_macip_lens = skb_network_header_len(skb);
  3553. vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
  3554. vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
  3555. igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx);
  3556. return 1;
  3557. }
  3558. static void igb_tx_csum(struct igb_ring *tx_ring, struct igb_tx_buffer *first)
  3559. {
  3560. struct sk_buff *skb = first->skb;
  3561. u32 vlan_macip_lens = 0;
  3562. u32 mss_l4len_idx = 0;
  3563. u32 type_tucmd = 0;
  3564. if (skb->ip_summed != CHECKSUM_PARTIAL) {
  3565. if (!(first->tx_flags & IGB_TX_FLAGS_VLAN))
  3566. return;
  3567. } else {
  3568. u8 l4_hdr = 0;
  3569. switch (first->protocol) {
  3570. case __constant_htons(ETH_P_IP):
  3571. vlan_macip_lens |= skb_network_header_len(skb);
  3572. type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
  3573. l4_hdr = ip_hdr(skb)->protocol;
  3574. break;
  3575. case __constant_htons(ETH_P_IPV6):
  3576. vlan_macip_lens |= skb_network_header_len(skb);
  3577. l4_hdr = ipv6_hdr(skb)->nexthdr;
  3578. break;
  3579. default:
  3580. if (unlikely(net_ratelimit())) {
  3581. dev_warn(tx_ring->dev,
  3582. "partial checksum but proto=%x!\n",
  3583. first->protocol);
  3584. }
  3585. break;
  3586. }
  3587. switch (l4_hdr) {
  3588. case IPPROTO_TCP:
  3589. type_tucmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
  3590. mss_l4len_idx = tcp_hdrlen(skb) <<
  3591. E1000_ADVTXD_L4LEN_SHIFT;
  3592. break;
  3593. case IPPROTO_SCTP:
  3594. type_tucmd |= E1000_ADVTXD_TUCMD_L4T_SCTP;
  3595. mss_l4len_idx = sizeof(struct sctphdr) <<
  3596. E1000_ADVTXD_L4LEN_SHIFT;
  3597. break;
  3598. case IPPROTO_UDP:
  3599. mss_l4len_idx = sizeof(struct udphdr) <<
  3600. E1000_ADVTXD_L4LEN_SHIFT;
  3601. break;
  3602. default:
  3603. if (unlikely(net_ratelimit())) {
  3604. dev_warn(tx_ring->dev,
  3605. "partial checksum but l4 proto=%x!\n",
  3606. l4_hdr);
  3607. }
  3608. break;
  3609. }
  3610. /* update TX checksum flag */
  3611. first->tx_flags |= IGB_TX_FLAGS_CSUM;
  3612. }
  3613. vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
  3614. vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
  3615. igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx);
  3616. }
  3617. static __le32 igb_tx_cmd_type(u32 tx_flags)
  3618. {
  3619. /* set type for advanced descriptor with frame checksum insertion */
  3620. __le32 cmd_type = cpu_to_le32(E1000_ADVTXD_DTYP_DATA |
  3621. E1000_ADVTXD_DCMD_IFCS |
  3622. E1000_ADVTXD_DCMD_DEXT);
  3623. /* set HW vlan bit if vlan is present */
  3624. if (tx_flags & IGB_TX_FLAGS_VLAN)
  3625. cmd_type |= cpu_to_le32(E1000_ADVTXD_DCMD_VLE);
  3626. /* set timestamp bit if present */
  3627. if (tx_flags & IGB_TX_FLAGS_TSTAMP)
  3628. cmd_type |= cpu_to_le32(E1000_ADVTXD_MAC_TSTAMP);
  3629. /* set segmentation bits for TSO */
  3630. if (tx_flags & IGB_TX_FLAGS_TSO)
  3631. cmd_type |= cpu_to_le32(E1000_ADVTXD_DCMD_TSE);
  3632. return cmd_type;
  3633. }
  3634. static void igb_tx_olinfo_status(struct igb_ring *tx_ring,
  3635. union e1000_adv_tx_desc *tx_desc,
  3636. u32 tx_flags, unsigned int paylen)
  3637. {
  3638. u32 olinfo_status = paylen << E1000_ADVTXD_PAYLEN_SHIFT;
  3639. /* 82575 requires a unique index per ring if any offload is enabled */
  3640. if ((tx_flags & (IGB_TX_FLAGS_CSUM | IGB_TX_FLAGS_VLAN)) &&
  3641. test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
  3642. olinfo_status |= tx_ring->reg_idx << 4;
  3643. /* insert L4 checksum */
  3644. if (tx_flags & IGB_TX_FLAGS_CSUM) {
  3645. olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
  3646. /* insert IPv4 checksum */
  3647. if (tx_flags & IGB_TX_FLAGS_IPV4)
  3648. olinfo_status |= E1000_TXD_POPTS_IXSM << 8;
  3649. }
  3650. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  3651. }
  3652. /*
  3653. * The largest size we can write to the descriptor is 65535. In order to
  3654. * maintain a power of two alignment we have to limit ourselves to 32K.
  3655. */
  3656. #define IGB_MAX_TXD_PWR 15
  3657. #define IGB_MAX_DATA_PER_TXD (1<<IGB_MAX_TXD_PWR)
  3658. static void igb_tx_map(struct igb_ring *tx_ring,
  3659. struct igb_tx_buffer *first,
  3660. const u8 hdr_len)
  3661. {
  3662. struct sk_buff *skb = first->skb;
  3663. struct igb_tx_buffer *tx_buffer_info;
  3664. union e1000_adv_tx_desc *tx_desc;
  3665. dma_addr_t dma;
  3666. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
  3667. unsigned int data_len = skb->data_len;
  3668. unsigned int size = skb_headlen(skb);
  3669. unsigned int paylen = skb->len - hdr_len;
  3670. __le32 cmd_type;
  3671. u32 tx_flags = first->tx_flags;
  3672. u16 i = tx_ring->next_to_use;
  3673. tx_desc = IGB_TX_DESC(tx_ring, i);
  3674. igb_tx_olinfo_status(tx_ring, tx_desc, tx_flags, paylen);
  3675. cmd_type = igb_tx_cmd_type(tx_flags);
  3676. dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
  3677. if (dma_mapping_error(tx_ring->dev, dma))
  3678. goto dma_error;
  3679. /* record length, and DMA address */
  3680. first->length = size;
  3681. first->dma = dma;
  3682. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  3683. for (;;) {
  3684. while (unlikely(size > IGB_MAX_DATA_PER_TXD)) {
  3685. tx_desc->read.cmd_type_len =
  3686. cmd_type | cpu_to_le32(IGB_MAX_DATA_PER_TXD);
  3687. i++;
  3688. tx_desc++;
  3689. if (i == tx_ring->count) {
  3690. tx_desc = IGB_TX_DESC(tx_ring, 0);
  3691. i = 0;
  3692. }
  3693. dma += IGB_MAX_DATA_PER_TXD;
  3694. size -= IGB_MAX_DATA_PER_TXD;
  3695. tx_desc->read.olinfo_status = 0;
  3696. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  3697. }
  3698. if (likely(!data_len))
  3699. break;
  3700. tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
  3701. i++;
  3702. tx_desc++;
  3703. if (i == tx_ring->count) {
  3704. tx_desc = IGB_TX_DESC(tx_ring, 0);
  3705. i = 0;
  3706. }
  3707. size = skb_frag_size(frag);
  3708. data_len -= size;
  3709. dma = skb_frag_dma_map(tx_ring->dev, frag, 0,
  3710. size, DMA_TO_DEVICE);
  3711. if (dma_mapping_error(tx_ring->dev, dma))
  3712. goto dma_error;
  3713. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  3714. tx_buffer_info->length = size;
  3715. tx_buffer_info->dma = dma;
  3716. tx_desc->read.olinfo_status = 0;
  3717. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  3718. frag++;
  3719. }
  3720. netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
  3721. /* write last descriptor with RS and EOP bits */
  3722. cmd_type |= cpu_to_le32(size) | cpu_to_le32(IGB_TXD_DCMD);
  3723. if (unlikely(skb->no_fcs))
  3724. cmd_type &= ~(cpu_to_le32(E1000_ADVTXD_DCMD_IFCS));
  3725. tx_desc->read.cmd_type_len = cmd_type;
  3726. /* set the timestamp */
  3727. first->time_stamp = jiffies;
  3728. /*
  3729. * Force memory writes to complete before letting h/w know there
  3730. * are new descriptors to fetch. (Only applicable for weak-ordered
  3731. * memory model archs, such as IA-64).
  3732. *
  3733. * We also need this memory barrier to make certain all of the
  3734. * status bits have been updated before next_to_watch is written.
  3735. */
  3736. wmb();
  3737. /* set next_to_watch value indicating a packet is present */
  3738. first->next_to_watch = tx_desc;
  3739. i++;
  3740. if (i == tx_ring->count)
  3741. i = 0;
  3742. tx_ring->next_to_use = i;
  3743. writel(i, tx_ring->tail);
  3744. /* we need this if more than one processor can write to our tail
  3745. * at a time, it syncronizes IO on IA64/Altix systems */
  3746. mmiowb();
  3747. return;
  3748. dma_error:
  3749. dev_err(tx_ring->dev, "TX DMA map failed\n");
  3750. /* clear dma mappings for failed tx_buffer_info map */
  3751. for (;;) {
  3752. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  3753. igb_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
  3754. if (tx_buffer_info == first)
  3755. break;
  3756. if (i == 0)
  3757. i = tx_ring->count;
  3758. i--;
  3759. }
  3760. tx_ring->next_to_use = i;
  3761. }
  3762. static int __igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
  3763. {
  3764. struct net_device *netdev = tx_ring->netdev;
  3765. netif_stop_subqueue(netdev, tx_ring->queue_index);
  3766. /* Herbert's original patch had:
  3767. * smp_mb__after_netif_stop_queue();
  3768. * but since that doesn't exist yet, just open code it. */
  3769. smp_mb();
  3770. /* We need to check again in a case another CPU has just
  3771. * made room available. */
  3772. if (igb_desc_unused(tx_ring) < size)
  3773. return -EBUSY;
  3774. /* A reprieve! */
  3775. netif_wake_subqueue(netdev, tx_ring->queue_index);
  3776. u64_stats_update_begin(&tx_ring->tx_syncp2);
  3777. tx_ring->tx_stats.restart_queue2++;
  3778. u64_stats_update_end(&tx_ring->tx_syncp2);
  3779. return 0;
  3780. }
  3781. static inline int igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
  3782. {
  3783. if (igb_desc_unused(tx_ring) >= size)
  3784. return 0;
  3785. return __igb_maybe_stop_tx(tx_ring, size);
  3786. }
  3787. netdev_tx_t igb_xmit_frame_ring(struct sk_buff *skb,
  3788. struct igb_ring *tx_ring)
  3789. {
  3790. struct igb_tx_buffer *first;
  3791. int tso;
  3792. u32 tx_flags = 0;
  3793. __be16 protocol = vlan_get_protocol(skb);
  3794. u8 hdr_len = 0;
  3795. /* need: 1 descriptor per page,
  3796. * + 2 desc gap to keep tail from touching head,
  3797. * + 1 desc for skb->data,
  3798. * + 1 desc for context descriptor,
  3799. * otherwise try next time */
  3800. if (igb_maybe_stop_tx(tx_ring, skb_shinfo(skb)->nr_frags + 4)) {
  3801. /* this is a hard error */
  3802. return NETDEV_TX_BUSY;
  3803. }
  3804. /* record the location of the first descriptor for this packet */
  3805. first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
  3806. first->skb = skb;
  3807. first->bytecount = skb->len;
  3808. first->gso_segs = 1;
  3809. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
  3810. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  3811. tx_flags |= IGB_TX_FLAGS_TSTAMP;
  3812. }
  3813. if (vlan_tx_tag_present(skb)) {
  3814. tx_flags |= IGB_TX_FLAGS_VLAN;
  3815. tx_flags |= (vlan_tx_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT);
  3816. }
  3817. /* record initial flags and protocol */
  3818. first->tx_flags = tx_flags;
  3819. first->protocol = protocol;
  3820. tso = igb_tso(tx_ring, first, &hdr_len);
  3821. if (tso < 0)
  3822. goto out_drop;
  3823. else if (!tso)
  3824. igb_tx_csum(tx_ring, first);
  3825. igb_tx_map(tx_ring, first, hdr_len);
  3826. /* Make sure there is space in the ring for the next send. */
  3827. igb_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 4);
  3828. return NETDEV_TX_OK;
  3829. out_drop:
  3830. igb_unmap_and_free_tx_resource(tx_ring, first);
  3831. return NETDEV_TX_OK;
  3832. }
  3833. static inline struct igb_ring *igb_tx_queue_mapping(struct igb_adapter *adapter,
  3834. struct sk_buff *skb)
  3835. {
  3836. unsigned int r_idx = skb->queue_mapping;
  3837. if (r_idx >= adapter->num_tx_queues)
  3838. r_idx = r_idx % adapter->num_tx_queues;
  3839. return adapter->tx_ring[r_idx];
  3840. }
  3841. static netdev_tx_t igb_xmit_frame(struct sk_buff *skb,
  3842. struct net_device *netdev)
  3843. {
  3844. struct igb_adapter *adapter = netdev_priv(netdev);
  3845. if (test_bit(__IGB_DOWN, &adapter->state)) {
  3846. dev_kfree_skb_any(skb);
  3847. return NETDEV_TX_OK;
  3848. }
  3849. if (skb->len <= 0) {
  3850. dev_kfree_skb_any(skb);
  3851. return NETDEV_TX_OK;
  3852. }
  3853. /*
  3854. * The minimum packet size with TCTL.PSP set is 17 so pad the skb
  3855. * in order to meet this minimum size requirement.
  3856. */
  3857. if (skb->len < 17) {
  3858. if (skb_padto(skb, 17))
  3859. return NETDEV_TX_OK;
  3860. skb->len = 17;
  3861. }
  3862. return igb_xmit_frame_ring(skb, igb_tx_queue_mapping(adapter, skb));
  3863. }
  3864. /**
  3865. * igb_tx_timeout - Respond to a Tx Hang
  3866. * @netdev: network interface device structure
  3867. **/
  3868. static void igb_tx_timeout(struct net_device *netdev)
  3869. {
  3870. struct igb_adapter *adapter = netdev_priv(netdev);
  3871. struct e1000_hw *hw = &adapter->hw;
  3872. /* Do the reset outside of interrupt context */
  3873. adapter->tx_timeout_count++;
  3874. if (hw->mac.type >= e1000_82580)
  3875. hw->dev_spec._82575.global_device_reset = true;
  3876. schedule_work(&adapter->reset_task);
  3877. wr32(E1000_EICS,
  3878. (adapter->eims_enable_mask & ~adapter->eims_other));
  3879. }
  3880. static void igb_reset_task(struct work_struct *work)
  3881. {
  3882. struct igb_adapter *adapter;
  3883. adapter = container_of(work, struct igb_adapter, reset_task);
  3884. igb_dump(adapter);
  3885. netdev_err(adapter->netdev, "Reset adapter\n");
  3886. igb_reinit_locked(adapter);
  3887. }
  3888. /**
  3889. * igb_get_stats64 - Get System Network Statistics
  3890. * @netdev: network interface device structure
  3891. * @stats: rtnl_link_stats64 pointer
  3892. *
  3893. **/
  3894. static struct rtnl_link_stats64 *igb_get_stats64(struct net_device *netdev,
  3895. struct rtnl_link_stats64 *stats)
  3896. {
  3897. struct igb_adapter *adapter = netdev_priv(netdev);
  3898. spin_lock(&adapter->stats64_lock);
  3899. igb_update_stats(adapter, &adapter->stats64);
  3900. memcpy(stats, &adapter->stats64, sizeof(*stats));
  3901. spin_unlock(&adapter->stats64_lock);
  3902. return stats;
  3903. }
  3904. /**
  3905. * igb_change_mtu - Change the Maximum Transfer Unit
  3906. * @netdev: network interface device structure
  3907. * @new_mtu: new value for maximum frame size
  3908. *
  3909. * Returns 0 on success, negative on failure
  3910. **/
  3911. static int igb_change_mtu(struct net_device *netdev, int new_mtu)
  3912. {
  3913. struct igb_adapter *adapter = netdev_priv(netdev);
  3914. struct pci_dev *pdev = adapter->pdev;
  3915. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  3916. if ((new_mtu < 68) || (max_frame > MAX_JUMBO_FRAME_SIZE)) {
  3917. dev_err(&pdev->dev, "Invalid MTU setting\n");
  3918. return -EINVAL;
  3919. }
  3920. #define MAX_STD_JUMBO_FRAME_SIZE 9238
  3921. if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
  3922. dev_err(&pdev->dev, "MTU > 9216 not supported.\n");
  3923. return -EINVAL;
  3924. }
  3925. while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
  3926. msleep(1);
  3927. /* igb_down has a dependency on max_frame_size */
  3928. adapter->max_frame_size = max_frame;
  3929. if (netif_running(netdev))
  3930. igb_down(adapter);
  3931. dev_info(&pdev->dev, "changing MTU from %d to %d\n",
  3932. netdev->mtu, new_mtu);
  3933. netdev->mtu = new_mtu;
  3934. if (netif_running(netdev))
  3935. igb_up(adapter);
  3936. else
  3937. igb_reset(adapter);
  3938. clear_bit(__IGB_RESETTING, &adapter->state);
  3939. return 0;
  3940. }
  3941. /**
  3942. * igb_update_stats - Update the board statistics counters
  3943. * @adapter: board private structure
  3944. **/
  3945. void igb_update_stats(struct igb_adapter *adapter,
  3946. struct rtnl_link_stats64 *net_stats)
  3947. {
  3948. struct e1000_hw *hw = &adapter->hw;
  3949. struct pci_dev *pdev = adapter->pdev;
  3950. u32 reg, mpc;
  3951. u16 phy_tmp;
  3952. int i;
  3953. u64 bytes, packets;
  3954. unsigned int start;
  3955. u64 _bytes, _packets;
  3956. #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
  3957. /*
  3958. * Prevent stats update while adapter is being reset, or if the pci
  3959. * connection is down.
  3960. */
  3961. if (adapter->link_speed == 0)
  3962. return;
  3963. if (pci_channel_offline(pdev))
  3964. return;
  3965. bytes = 0;
  3966. packets = 0;
  3967. for (i = 0; i < adapter->num_rx_queues; i++) {
  3968. u32 rqdpc_tmp = rd32(E1000_RQDPC(i)) & 0x0FFF;
  3969. struct igb_ring *ring = adapter->rx_ring[i];
  3970. ring->rx_stats.drops += rqdpc_tmp;
  3971. net_stats->rx_fifo_errors += rqdpc_tmp;
  3972. do {
  3973. start = u64_stats_fetch_begin_bh(&ring->rx_syncp);
  3974. _bytes = ring->rx_stats.bytes;
  3975. _packets = ring->rx_stats.packets;
  3976. } while (u64_stats_fetch_retry_bh(&ring->rx_syncp, start));
  3977. bytes += _bytes;
  3978. packets += _packets;
  3979. }
  3980. net_stats->rx_bytes = bytes;
  3981. net_stats->rx_packets = packets;
  3982. bytes = 0;
  3983. packets = 0;
  3984. for (i = 0; i < adapter->num_tx_queues; i++) {
  3985. struct igb_ring *ring = adapter->tx_ring[i];
  3986. do {
  3987. start = u64_stats_fetch_begin_bh(&ring->tx_syncp);
  3988. _bytes = ring->tx_stats.bytes;
  3989. _packets = ring->tx_stats.packets;
  3990. } while (u64_stats_fetch_retry_bh(&ring->tx_syncp, start));
  3991. bytes += _bytes;
  3992. packets += _packets;
  3993. }
  3994. net_stats->tx_bytes = bytes;
  3995. net_stats->tx_packets = packets;
  3996. /* read stats registers */
  3997. adapter->stats.crcerrs += rd32(E1000_CRCERRS);
  3998. adapter->stats.gprc += rd32(E1000_GPRC);
  3999. adapter->stats.gorc += rd32(E1000_GORCL);
  4000. rd32(E1000_GORCH); /* clear GORCL */
  4001. adapter->stats.bprc += rd32(E1000_BPRC);
  4002. adapter->stats.mprc += rd32(E1000_MPRC);
  4003. adapter->stats.roc += rd32(E1000_ROC);
  4004. adapter->stats.prc64 += rd32(E1000_PRC64);
  4005. adapter->stats.prc127 += rd32(E1000_PRC127);
  4006. adapter->stats.prc255 += rd32(E1000_PRC255);
  4007. adapter->stats.prc511 += rd32(E1000_PRC511);
  4008. adapter->stats.prc1023 += rd32(E1000_PRC1023);
  4009. adapter->stats.prc1522 += rd32(E1000_PRC1522);
  4010. adapter->stats.symerrs += rd32(E1000_SYMERRS);
  4011. adapter->stats.sec += rd32(E1000_SEC);
  4012. mpc = rd32(E1000_MPC);
  4013. adapter->stats.mpc += mpc;
  4014. net_stats->rx_fifo_errors += mpc;
  4015. adapter->stats.scc += rd32(E1000_SCC);
  4016. adapter->stats.ecol += rd32(E1000_ECOL);
  4017. adapter->stats.mcc += rd32(E1000_MCC);
  4018. adapter->stats.latecol += rd32(E1000_LATECOL);
  4019. adapter->stats.dc += rd32(E1000_DC);
  4020. adapter->stats.rlec += rd32(E1000_RLEC);
  4021. adapter->stats.xonrxc += rd32(E1000_XONRXC);
  4022. adapter->stats.xontxc += rd32(E1000_XONTXC);
  4023. adapter->stats.xoffrxc += rd32(E1000_XOFFRXC);
  4024. adapter->stats.xofftxc += rd32(E1000_XOFFTXC);
  4025. adapter->stats.fcruc += rd32(E1000_FCRUC);
  4026. adapter->stats.gptc += rd32(E1000_GPTC);
  4027. adapter->stats.gotc += rd32(E1000_GOTCL);
  4028. rd32(E1000_GOTCH); /* clear GOTCL */
  4029. adapter->stats.rnbc += rd32(E1000_RNBC);
  4030. adapter->stats.ruc += rd32(E1000_RUC);
  4031. adapter->stats.rfc += rd32(E1000_RFC);
  4032. adapter->stats.rjc += rd32(E1000_RJC);
  4033. adapter->stats.tor += rd32(E1000_TORH);
  4034. adapter->stats.tot += rd32(E1000_TOTH);
  4035. adapter->stats.tpr += rd32(E1000_TPR);
  4036. adapter->stats.ptc64 += rd32(E1000_PTC64);
  4037. adapter->stats.ptc127 += rd32(E1000_PTC127);
  4038. adapter->stats.ptc255 += rd32(E1000_PTC255);
  4039. adapter->stats.ptc511 += rd32(E1000_PTC511);
  4040. adapter->stats.ptc1023 += rd32(E1000_PTC1023);
  4041. adapter->stats.ptc1522 += rd32(E1000_PTC1522);
  4042. adapter->stats.mptc += rd32(E1000_MPTC);
  4043. adapter->stats.bptc += rd32(E1000_BPTC);
  4044. adapter->stats.tpt += rd32(E1000_TPT);
  4045. adapter->stats.colc += rd32(E1000_COLC);
  4046. adapter->stats.algnerrc += rd32(E1000_ALGNERRC);
  4047. /* read internal phy specific stats */
  4048. reg = rd32(E1000_CTRL_EXT);
  4049. if (!(reg & E1000_CTRL_EXT_LINK_MODE_MASK)) {
  4050. adapter->stats.rxerrc += rd32(E1000_RXERRC);
  4051. adapter->stats.tncrs += rd32(E1000_TNCRS);
  4052. }
  4053. adapter->stats.tsctc += rd32(E1000_TSCTC);
  4054. adapter->stats.tsctfc += rd32(E1000_TSCTFC);
  4055. adapter->stats.iac += rd32(E1000_IAC);
  4056. adapter->stats.icrxoc += rd32(E1000_ICRXOC);
  4057. adapter->stats.icrxptc += rd32(E1000_ICRXPTC);
  4058. adapter->stats.icrxatc += rd32(E1000_ICRXATC);
  4059. adapter->stats.ictxptc += rd32(E1000_ICTXPTC);
  4060. adapter->stats.ictxatc += rd32(E1000_ICTXATC);
  4061. adapter->stats.ictxqec += rd32(E1000_ICTXQEC);
  4062. adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC);
  4063. adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC);
  4064. /* Fill out the OS statistics structure */
  4065. net_stats->multicast = adapter->stats.mprc;
  4066. net_stats->collisions = adapter->stats.colc;
  4067. /* Rx Errors */
  4068. /* RLEC on some newer hardware can be incorrect so build
  4069. * our own version based on RUC and ROC */
  4070. net_stats->rx_errors = adapter->stats.rxerrc +
  4071. adapter->stats.crcerrs + adapter->stats.algnerrc +
  4072. adapter->stats.ruc + adapter->stats.roc +
  4073. adapter->stats.cexterr;
  4074. net_stats->rx_length_errors = adapter->stats.ruc +
  4075. adapter->stats.roc;
  4076. net_stats->rx_crc_errors = adapter->stats.crcerrs;
  4077. net_stats->rx_frame_errors = adapter->stats.algnerrc;
  4078. net_stats->rx_missed_errors = adapter->stats.mpc;
  4079. /* Tx Errors */
  4080. net_stats->tx_errors = adapter->stats.ecol +
  4081. adapter->stats.latecol;
  4082. net_stats->tx_aborted_errors = adapter->stats.ecol;
  4083. net_stats->tx_window_errors = adapter->stats.latecol;
  4084. net_stats->tx_carrier_errors = adapter->stats.tncrs;
  4085. /* Tx Dropped needs to be maintained elsewhere */
  4086. /* Phy Stats */
  4087. if (hw->phy.media_type == e1000_media_type_copper) {
  4088. if ((adapter->link_speed == SPEED_1000) &&
  4089. (!igb_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
  4090. phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
  4091. adapter->phy_stats.idle_errors += phy_tmp;
  4092. }
  4093. }
  4094. /* Management Stats */
  4095. adapter->stats.mgptc += rd32(E1000_MGTPTC);
  4096. adapter->stats.mgprc += rd32(E1000_MGTPRC);
  4097. adapter->stats.mgpdc += rd32(E1000_MGTPDC);
  4098. /* OS2BMC Stats */
  4099. reg = rd32(E1000_MANC);
  4100. if (reg & E1000_MANC_EN_BMC2OS) {
  4101. adapter->stats.o2bgptc += rd32(E1000_O2BGPTC);
  4102. adapter->stats.o2bspc += rd32(E1000_O2BSPC);
  4103. adapter->stats.b2ospc += rd32(E1000_B2OSPC);
  4104. adapter->stats.b2ogprc += rd32(E1000_B2OGPRC);
  4105. }
  4106. }
  4107. static irqreturn_t igb_msix_other(int irq, void *data)
  4108. {
  4109. struct igb_adapter *adapter = data;
  4110. struct e1000_hw *hw = &adapter->hw;
  4111. u32 icr = rd32(E1000_ICR);
  4112. /* reading ICR causes bit 31 of EICR to be cleared */
  4113. if (icr & E1000_ICR_DRSTA)
  4114. schedule_work(&adapter->reset_task);
  4115. if (icr & E1000_ICR_DOUTSYNC) {
  4116. /* HW is reporting DMA is out of sync */
  4117. adapter->stats.doosync++;
  4118. /* The DMA Out of Sync is also indication of a spoof event
  4119. * in IOV mode. Check the Wrong VM Behavior register to
  4120. * see if it is really a spoof event. */
  4121. igb_check_wvbr(adapter);
  4122. }
  4123. /* Check for a mailbox event */
  4124. if (icr & E1000_ICR_VMMB)
  4125. igb_msg_task(adapter);
  4126. if (icr & E1000_ICR_LSC) {
  4127. hw->mac.get_link_status = 1;
  4128. /* guard against interrupt when we're going down */
  4129. if (!test_bit(__IGB_DOWN, &adapter->state))
  4130. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  4131. }
  4132. wr32(E1000_EIMS, adapter->eims_other);
  4133. return IRQ_HANDLED;
  4134. }
  4135. static void igb_write_itr(struct igb_q_vector *q_vector)
  4136. {
  4137. struct igb_adapter *adapter = q_vector->adapter;
  4138. u32 itr_val = q_vector->itr_val & 0x7FFC;
  4139. if (!q_vector->set_itr)
  4140. return;
  4141. if (!itr_val)
  4142. itr_val = 0x4;
  4143. if (adapter->hw.mac.type == e1000_82575)
  4144. itr_val |= itr_val << 16;
  4145. else
  4146. itr_val |= E1000_EITR_CNT_IGNR;
  4147. writel(itr_val, q_vector->itr_register);
  4148. q_vector->set_itr = 0;
  4149. }
  4150. static irqreturn_t igb_msix_ring(int irq, void *data)
  4151. {
  4152. struct igb_q_vector *q_vector = data;
  4153. /* Write the ITR value calculated from the previous interrupt. */
  4154. igb_write_itr(q_vector);
  4155. napi_schedule(&q_vector->napi);
  4156. return IRQ_HANDLED;
  4157. }
  4158. #ifdef CONFIG_IGB_DCA
  4159. static void igb_update_dca(struct igb_q_vector *q_vector)
  4160. {
  4161. struct igb_adapter *adapter = q_vector->adapter;
  4162. struct e1000_hw *hw = &adapter->hw;
  4163. int cpu = get_cpu();
  4164. if (q_vector->cpu == cpu)
  4165. goto out_no_update;
  4166. if (q_vector->tx.ring) {
  4167. int q = q_vector->tx.ring->reg_idx;
  4168. u32 dca_txctrl = rd32(E1000_DCA_TXCTRL(q));
  4169. if (hw->mac.type == e1000_82575) {
  4170. dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK;
  4171. dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
  4172. } else {
  4173. dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK_82576;
  4174. dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) <<
  4175. E1000_DCA_TXCTRL_CPUID_SHIFT;
  4176. }
  4177. dca_txctrl |= E1000_DCA_TXCTRL_DESC_DCA_EN;
  4178. wr32(E1000_DCA_TXCTRL(q), dca_txctrl);
  4179. }
  4180. if (q_vector->rx.ring) {
  4181. int q = q_vector->rx.ring->reg_idx;
  4182. u32 dca_rxctrl = rd32(E1000_DCA_RXCTRL(q));
  4183. if (hw->mac.type == e1000_82575) {
  4184. dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK;
  4185. dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
  4186. } else {
  4187. dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK_82576;
  4188. dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) <<
  4189. E1000_DCA_RXCTRL_CPUID_SHIFT;
  4190. }
  4191. dca_rxctrl |= E1000_DCA_RXCTRL_DESC_DCA_EN;
  4192. dca_rxctrl |= E1000_DCA_RXCTRL_HEAD_DCA_EN;
  4193. dca_rxctrl |= E1000_DCA_RXCTRL_DATA_DCA_EN;
  4194. wr32(E1000_DCA_RXCTRL(q), dca_rxctrl);
  4195. }
  4196. q_vector->cpu = cpu;
  4197. out_no_update:
  4198. put_cpu();
  4199. }
  4200. static void igb_setup_dca(struct igb_adapter *adapter)
  4201. {
  4202. struct e1000_hw *hw = &adapter->hw;
  4203. int i;
  4204. if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
  4205. return;
  4206. /* Always use CB2 mode, difference is masked in the CB driver. */
  4207. wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
  4208. for (i = 0; i < adapter->num_q_vectors; i++) {
  4209. adapter->q_vector[i]->cpu = -1;
  4210. igb_update_dca(adapter->q_vector[i]);
  4211. }
  4212. }
  4213. static int __igb_notify_dca(struct device *dev, void *data)
  4214. {
  4215. struct net_device *netdev = dev_get_drvdata(dev);
  4216. struct igb_adapter *adapter = netdev_priv(netdev);
  4217. struct pci_dev *pdev = adapter->pdev;
  4218. struct e1000_hw *hw = &adapter->hw;
  4219. unsigned long event = *(unsigned long *)data;
  4220. switch (event) {
  4221. case DCA_PROVIDER_ADD:
  4222. /* if already enabled, don't do it again */
  4223. if (adapter->flags & IGB_FLAG_DCA_ENABLED)
  4224. break;
  4225. if (dca_add_requester(dev) == 0) {
  4226. adapter->flags |= IGB_FLAG_DCA_ENABLED;
  4227. dev_info(&pdev->dev, "DCA enabled\n");
  4228. igb_setup_dca(adapter);
  4229. break;
  4230. }
  4231. /* Fall Through since DCA is disabled. */
  4232. case DCA_PROVIDER_REMOVE:
  4233. if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
  4234. /* without this a class_device is left
  4235. * hanging around in the sysfs model */
  4236. dca_remove_requester(dev);
  4237. dev_info(&pdev->dev, "DCA disabled\n");
  4238. adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
  4239. wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
  4240. }
  4241. break;
  4242. }
  4243. return 0;
  4244. }
  4245. static int igb_notify_dca(struct notifier_block *nb, unsigned long event,
  4246. void *p)
  4247. {
  4248. int ret_val;
  4249. ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event,
  4250. __igb_notify_dca);
  4251. return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
  4252. }
  4253. #endif /* CONFIG_IGB_DCA */
  4254. #ifdef CONFIG_PCI_IOV
  4255. static int igb_vf_configure(struct igb_adapter *adapter, int vf)
  4256. {
  4257. unsigned char mac_addr[ETH_ALEN];
  4258. struct pci_dev *pdev = adapter->pdev;
  4259. struct e1000_hw *hw = &adapter->hw;
  4260. struct pci_dev *pvfdev;
  4261. unsigned int device_id;
  4262. u16 thisvf_devfn;
  4263. random_ether_addr(mac_addr);
  4264. igb_set_vf_mac(adapter, vf, mac_addr);
  4265. switch (adapter->hw.mac.type) {
  4266. case e1000_82576:
  4267. device_id = IGB_82576_VF_DEV_ID;
  4268. /* VF Stride for 82576 is 2 */
  4269. thisvf_devfn = (pdev->devfn + 0x80 + (vf << 1)) |
  4270. (pdev->devfn & 1);
  4271. break;
  4272. case e1000_i350:
  4273. device_id = IGB_I350_VF_DEV_ID;
  4274. /* VF Stride for I350 is 4 */
  4275. thisvf_devfn = (pdev->devfn + 0x80 + (vf << 2)) |
  4276. (pdev->devfn & 3);
  4277. break;
  4278. default:
  4279. device_id = 0;
  4280. thisvf_devfn = 0;
  4281. break;
  4282. }
  4283. pvfdev = pci_get_device(hw->vendor_id, device_id, NULL);
  4284. while (pvfdev) {
  4285. if (pvfdev->devfn == thisvf_devfn)
  4286. break;
  4287. pvfdev = pci_get_device(hw->vendor_id,
  4288. device_id, pvfdev);
  4289. }
  4290. if (pvfdev)
  4291. adapter->vf_data[vf].vfdev = pvfdev;
  4292. else
  4293. dev_err(&pdev->dev,
  4294. "Couldn't find pci dev ptr for VF %4.4x\n",
  4295. thisvf_devfn);
  4296. return pvfdev != NULL;
  4297. }
  4298. static int igb_find_enabled_vfs(struct igb_adapter *adapter)
  4299. {
  4300. struct e1000_hw *hw = &adapter->hw;
  4301. struct pci_dev *pdev = adapter->pdev;
  4302. struct pci_dev *pvfdev;
  4303. u16 vf_devfn = 0;
  4304. u16 vf_stride;
  4305. unsigned int device_id;
  4306. int vfs_found = 0;
  4307. switch (adapter->hw.mac.type) {
  4308. case e1000_82576:
  4309. device_id = IGB_82576_VF_DEV_ID;
  4310. /* VF Stride for 82576 is 2 */
  4311. vf_stride = 2;
  4312. break;
  4313. case e1000_i350:
  4314. device_id = IGB_I350_VF_DEV_ID;
  4315. /* VF Stride for I350 is 4 */
  4316. vf_stride = 4;
  4317. break;
  4318. default:
  4319. device_id = 0;
  4320. vf_stride = 0;
  4321. break;
  4322. }
  4323. vf_devfn = pdev->devfn + 0x80;
  4324. pvfdev = pci_get_device(hw->vendor_id, device_id, NULL);
  4325. while (pvfdev) {
  4326. if (pvfdev->devfn == vf_devfn &&
  4327. (pvfdev->bus->number >= pdev->bus->number))
  4328. vfs_found++;
  4329. vf_devfn += vf_stride;
  4330. pvfdev = pci_get_device(hw->vendor_id,
  4331. device_id, pvfdev);
  4332. }
  4333. return vfs_found;
  4334. }
  4335. static int igb_check_vf_assignment(struct igb_adapter *adapter)
  4336. {
  4337. int i;
  4338. for (i = 0; i < adapter->vfs_allocated_count; i++) {
  4339. if (adapter->vf_data[i].vfdev) {
  4340. if (adapter->vf_data[i].vfdev->dev_flags &
  4341. PCI_DEV_FLAGS_ASSIGNED)
  4342. return true;
  4343. }
  4344. }
  4345. return false;
  4346. }
  4347. #endif
  4348. static void igb_ping_all_vfs(struct igb_adapter *adapter)
  4349. {
  4350. struct e1000_hw *hw = &adapter->hw;
  4351. u32 ping;
  4352. int i;
  4353. for (i = 0 ; i < adapter->vfs_allocated_count; i++) {
  4354. ping = E1000_PF_CONTROL_MSG;
  4355. if (adapter->vf_data[i].flags & IGB_VF_FLAG_CTS)
  4356. ping |= E1000_VT_MSGTYPE_CTS;
  4357. igb_write_mbx(hw, &ping, 1, i);
  4358. }
  4359. }
  4360. static int igb_set_vf_promisc(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
  4361. {
  4362. struct e1000_hw *hw = &adapter->hw;
  4363. u32 vmolr = rd32(E1000_VMOLR(vf));
  4364. struct vf_data_storage *vf_data = &adapter->vf_data[vf];
  4365. vf_data->flags &= ~(IGB_VF_FLAG_UNI_PROMISC |
  4366. IGB_VF_FLAG_MULTI_PROMISC);
  4367. vmolr &= ~(E1000_VMOLR_ROPE | E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
  4368. if (*msgbuf & E1000_VF_SET_PROMISC_MULTICAST) {
  4369. vmolr |= E1000_VMOLR_MPME;
  4370. vf_data->flags |= IGB_VF_FLAG_MULTI_PROMISC;
  4371. *msgbuf &= ~E1000_VF_SET_PROMISC_MULTICAST;
  4372. } else {
  4373. /*
  4374. * if we have hashes and we are clearing a multicast promisc
  4375. * flag we need to write the hashes to the MTA as this step
  4376. * was previously skipped
  4377. */
  4378. if (vf_data->num_vf_mc_hashes > 30) {
  4379. vmolr |= E1000_VMOLR_MPME;
  4380. } else if (vf_data->num_vf_mc_hashes) {
  4381. int j;
  4382. vmolr |= E1000_VMOLR_ROMPE;
  4383. for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
  4384. igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
  4385. }
  4386. }
  4387. wr32(E1000_VMOLR(vf), vmolr);
  4388. /* there are flags left unprocessed, likely not supported */
  4389. if (*msgbuf & E1000_VT_MSGINFO_MASK)
  4390. return -EINVAL;
  4391. return 0;
  4392. }
  4393. static int igb_set_vf_multicasts(struct igb_adapter *adapter,
  4394. u32 *msgbuf, u32 vf)
  4395. {
  4396. int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
  4397. u16 *hash_list = (u16 *)&msgbuf[1];
  4398. struct vf_data_storage *vf_data = &adapter->vf_data[vf];
  4399. int i;
  4400. /* salt away the number of multicast addresses assigned
  4401. * to this VF for later use to restore when the PF multi cast
  4402. * list changes
  4403. */
  4404. vf_data->num_vf_mc_hashes = n;
  4405. /* only up to 30 hash values supported */
  4406. if (n > 30)
  4407. n = 30;
  4408. /* store the hashes for later use */
  4409. for (i = 0; i < n; i++)
  4410. vf_data->vf_mc_hashes[i] = hash_list[i];
  4411. /* Flush and reset the mta with the new values */
  4412. igb_set_rx_mode(adapter->netdev);
  4413. return 0;
  4414. }
  4415. static void igb_restore_vf_multicasts(struct igb_adapter *adapter)
  4416. {
  4417. struct e1000_hw *hw = &adapter->hw;
  4418. struct vf_data_storage *vf_data;
  4419. int i, j;
  4420. for (i = 0; i < adapter->vfs_allocated_count; i++) {
  4421. u32 vmolr = rd32(E1000_VMOLR(i));
  4422. vmolr &= ~(E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
  4423. vf_data = &adapter->vf_data[i];
  4424. if ((vf_data->num_vf_mc_hashes > 30) ||
  4425. (vf_data->flags & IGB_VF_FLAG_MULTI_PROMISC)) {
  4426. vmolr |= E1000_VMOLR_MPME;
  4427. } else if (vf_data->num_vf_mc_hashes) {
  4428. vmolr |= E1000_VMOLR_ROMPE;
  4429. for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
  4430. igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
  4431. }
  4432. wr32(E1000_VMOLR(i), vmolr);
  4433. }
  4434. }
  4435. static void igb_clear_vf_vfta(struct igb_adapter *adapter, u32 vf)
  4436. {
  4437. struct e1000_hw *hw = &adapter->hw;
  4438. u32 pool_mask, reg, vid;
  4439. int i;
  4440. pool_mask = 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
  4441. /* Find the vlan filter for this id */
  4442. for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
  4443. reg = rd32(E1000_VLVF(i));
  4444. /* remove the vf from the pool */
  4445. reg &= ~pool_mask;
  4446. /* if pool is empty then remove entry from vfta */
  4447. if (!(reg & E1000_VLVF_POOLSEL_MASK) &&
  4448. (reg & E1000_VLVF_VLANID_ENABLE)) {
  4449. reg = 0;
  4450. vid = reg & E1000_VLVF_VLANID_MASK;
  4451. igb_vfta_set(hw, vid, false);
  4452. }
  4453. wr32(E1000_VLVF(i), reg);
  4454. }
  4455. adapter->vf_data[vf].vlans_enabled = 0;
  4456. }
  4457. static s32 igb_vlvf_set(struct igb_adapter *adapter, u32 vid, bool add, u32 vf)
  4458. {
  4459. struct e1000_hw *hw = &adapter->hw;
  4460. u32 reg, i;
  4461. /* The vlvf table only exists on 82576 hardware and newer */
  4462. if (hw->mac.type < e1000_82576)
  4463. return -1;
  4464. /* we only need to do this if VMDq is enabled */
  4465. if (!adapter->vfs_allocated_count)
  4466. return -1;
  4467. /* Find the vlan filter for this id */
  4468. for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
  4469. reg = rd32(E1000_VLVF(i));
  4470. if ((reg & E1000_VLVF_VLANID_ENABLE) &&
  4471. vid == (reg & E1000_VLVF_VLANID_MASK))
  4472. break;
  4473. }
  4474. if (add) {
  4475. if (i == E1000_VLVF_ARRAY_SIZE) {
  4476. /* Did not find a matching VLAN ID entry that was
  4477. * enabled. Search for a free filter entry, i.e.
  4478. * one without the enable bit set
  4479. */
  4480. for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
  4481. reg = rd32(E1000_VLVF(i));
  4482. if (!(reg & E1000_VLVF_VLANID_ENABLE))
  4483. break;
  4484. }
  4485. }
  4486. if (i < E1000_VLVF_ARRAY_SIZE) {
  4487. /* Found an enabled/available entry */
  4488. reg |= 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
  4489. /* if !enabled we need to set this up in vfta */
  4490. if (!(reg & E1000_VLVF_VLANID_ENABLE)) {
  4491. /* add VID to filter table */
  4492. igb_vfta_set(hw, vid, true);
  4493. reg |= E1000_VLVF_VLANID_ENABLE;
  4494. }
  4495. reg &= ~E1000_VLVF_VLANID_MASK;
  4496. reg |= vid;
  4497. wr32(E1000_VLVF(i), reg);
  4498. /* do not modify RLPML for PF devices */
  4499. if (vf >= adapter->vfs_allocated_count)
  4500. return 0;
  4501. if (!adapter->vf_data[vf].vlans_enabled) {
  4502. u32 size;
  4503. reg = rd32(E1000_VMOLR(vf));
  4504. size = reg & E1000_VMOLR_RLPML_MASK;
  4505. size += 4;
  4506. reg &= ~E1000_VMOLR_RLPML_MASK;
  4507. reg |= size;
  4508. wr32(E1000_VMOLR(vf), reg);
  4509. }
  4510. adapter->vf_data[vf].vlans_enabled++;
  4511. }
  4512. } else {
  4513. if (i < E1000_VLVF_ARRAY_SIZE) {
  4514. /* remove vf from the pool */
  4515. reg &= ~(1 << (E1000_VLVF_POOLSEL_SHIFT + vf));
  4516. /* if pool is empty then remove entry from vfta */
  4517. if (!(reg & E1000_VLVF_POOLSEL_MASK)) {
  4518. reg = 0;
  4519. igb_vfta_set(hw, vid, false);
  4520. }
  4521. wr32(E1000_VLVF(i), reg);
  4522. /* do not modify RLPML for PF devices */
  4523. if (vf >= adapter->vfs_allocated_count)
  4524. return 0;
  4525. adapter->vf_data[vf].vlans_enabled--;
  4526. if (!adapter->vf_data[vf].vlans_enabled) {
  4527. u32 size;
  4528. reg = rd32(E1000_VMOLR(vf));
  4529. size = reg & E1000_VMOLR_RLPML_MASK;
  4530. size -= 4;
  4531. reg &= ~E1000_VMOLR_RLPML_MASK;
  4532. reg |= size;
  4533. wr32(E1000_VMOLR(vf), reg);
  4534. }
  4535. }
  4536. }
  4537. return 0;
  4538. }
  4539. static void igb_set_vmvir(struct igb_adapter *adapter, u32 vid, u32 vf)
  4540. {
  4541. struct e1000_hw *hw = &adapter->hw;
  4542. if (vid)
  4543. wr32(E1000_VMVIR(vf), (vid | E1000_VMVIR_VLANA_DEFAULT));
  4544. else
  4545. wr32(E1000_VMVIR(vf), 0);
  4546. }
  4547. static int igb_ndo_set_vf_vlan(struct net_device *netdev,
  4548. int vf, u16 vlan, u8 qos)
  4549. {
  4550. int err = 0;
  4551. struct igb_adapter *adapter = netdev_priv(netdev);
  4552. if ((vf >= adapter->vfs_allocated_count) || (vlan > 4095) || (qos > 7))
  4553. return -EINVAL;
  4554. if (vlan || qos) {
  4555. err = igb_vlvf_set(adapter, vlan, !!vlan, vf);
  4556. if (err)
  4557. goto out;
  4558. igb_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf);
  4559. igb_set_vmolr(adapter, vf, !vlan);
  4560. adapter->vf_data[vf].pf_vlan = vlan;
  4561. adapter->vf_data[vf].pf_qos = qos;
  4562. dev_info(&adapter->pdev->dev,
  4563. "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf);
  4564. if (test_bit(__IGB_DOWN, &adapter->state)) {
  4565. dev_warn(&adapter->pdev->dev,
  4566. "The VF VLAN has been set,"
  4567. " but the PF device is not up.\n");
  4568. dev_warn(&adapter->pdev->dev,
  4569. "Bring the PF device up before"
  4570. " attempting to use the VF device.\n");
  4571. }
  4572. } else {
  4573. igb_vlvf_set(adapter, adapter->vf_data[vf].pf_vlan,
  4574. false, vf);
  4575. igb_set_vmvir(adapter, vlan, vf);
  4576. igb_set_vmolr(adapter, vf, true);
  4577. adapter->vf_data[vf].pf_vlan = 0;
  4578. adapter->vf_data[vf].pf_qos = 0;
  4579. }
  4580. out:
  4581. return err;
  4582. }
  4583. static int igb_set_vf_vlan(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
  4584. {
  4585. int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
  4586. int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK);
  4587. return igb_vlvf_set(adapter, vid, add, vf);
  4588. }
  4589. static inline void igb_vf_reset(struct igb_adapter *adapter, u32 vf)
  4590. {
  4591. /* clear flags - except flag that indicates PF has set the MAC */
  4592. adapter->vf_data[vf].flags &= IGB_VF_FLAG_PF_SET_MAC;
  4593. adapter->vf_data[vf].last_nack = jiffies;
  4594. /* reset offloads to defaults */
  4595. igb_set_vmolr(adapter, vf, true);
  4596. /* reset vlans for device */
  4597. igb_clear_vf_vfta(adapter, vf);
  4598. if (adapter->vf_data[vf].pf_vlan)
  4599. igb_ndo_set_vf_vlan(adapter->netdev, vf,
  4600. adapter->vf_data[vf].pf_vlan,
  4601. adapter->vf_data[vf].pf_qos);
  4602. else
  4603. igb_clear_vf_vfta(adapter, vf);
  4604. /* reset multicast table array for vf */
  4605. adapter->vf_data[vf].num_vf_mc_hashes = 0;
  4606. /* Flush and reset the mta with the new values */
  4607. igb_set_rx_mode(adapter->netdev);
  4608. }
  4609. static void igb_vf_reset_event(struct igb_adapter *adapter, u32 vf)
  4610. {
  4611. unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
  4612. /* generate a new mac address as we were hotplug removed/added */
  4613. if (!(adapter->vf_data[vf].flags & IGB_VF_FLAG_PF_SET_MAC))
  4614. random_ether_addr(vf_mac);
  4615. /* process remaining reset events */
  4616. igb_vf_reset(adapter, vf);
  4617. }
  4618. static void igb_vf_reset_msg(struct igb_adapter *adapter, u32 vf)
  4619. {
  4620. struct e1000_hw *hw = &adapter->hw;
  4621. unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
  4622. int rar_entry = hw->mac.rar_entry_count - (vf + 1);
  4623. u32 reg, msgbuf[3];
  4624. u8 *addr = (u8 *)(&msgbuf[1]);
  4625. /* process all the same items cleared in a function level reset */
  4626. igb_vf_reset(adapter, vf);
  4627. /* set vf mac address */
  4628. igb_rar_set_qsel(adapter, vf_mac, rar_entry, vf);
  4629. /* enable transmit and receive for vf */
  4630. reg = rd32(E1000_VFTE);
  4631. wr32(E1000_VFTE, reg | (1 << vf));
  4632. reg = rd32(E1000_VFRE);
  4633. wr32(E1000_VFRE, reg | (1 << vf));
  4634. adapter->vf_data[vf].flags |= IGB_VF_FLAG_CTS;
  4635. /* reply to reset with ack and vf mac address */
  4636. msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK;
  4637. memcpy(addr, vf_mac, 6);
  4638. igb_write_mbx(hw, msgbuf, 3, vf);
  4639. }
  4640. static int igb_set_vf_mac_addr(struct igb_adapter *adapter, u32 *msg, int vf)
  4641. {
  4642. /*
  4643. * The VF MAC Address is stored in a packed array of bytes
  4644. * starting at the second 32 bit word of the msg array
  4645. */
  4646. unsigned char *addr = (char *)&msg[1];
  4647. int err = -1;
  4648. if (is_valid_ether_addr(addr))
  4649. err = igb_set_vf_mac(adapter, vf, addr);
  4650. return err;
  4651. }
  4652. static void igb_rcv_ack_from_vf(struct igb_adapter *adapter, u32 vf)
  4653. {
  4654. struct e1000_hw *hw = &adapter->hw;
  4655. struct vf_data_storage *vf_data = &adapter->vf_data[vf];
  4656. u32 msg = E1000_VT_MSGTYPE_NACK;
  4657. /* if device isn't clear to send it shouldn't be reading either */
  4658. if (!(vf_data->flags & IGB_VF_FLAG_CTS) &&
  4659. time_after(jiffies, vf_data->last_nack + (2 * HZ))) {
  4660. igb_write_mbx(hw, &msg, 1, vf);
  4661. vf_data->last_nack = jiffies;
  4662. }
  4663. }
  4664. static void igb_rcv_msg_from_vf(struct igb_adapter *adapter, u32 vf)
  4665. {
  4666. struct pci_dev *pdev = adapter->pdev;
  4667. u32 msgbuf[E1000_VFMAILBOX_SIZE];
  4668. struct e1000_hw *hw = &adapter->hw;
  4669. struct vf_data_storage *vf_data = &adapter->vf_data[vf];
  4670. s32 retval;
  4671. retval = igb_read_mbx(hw, msgbuf, E1000_VFMAILBOX_SIZE, vf);
  4672. if (retval) {
  4673. /* if receive failed revoke VF CTS stats and restart init */
  4674. dev_err(&pdev->dev, "Error receiving message from VF\n");
  4675. vf_data->flags &= ~IGB_VF_FLAG_CTS;
  4676. if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
  4677. return;
  4678. goto out;
  4679. }
  4680. /* this is a message we already processed, do nothing */
  4681. if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK))
  4682. return;
  4683. /*
  4684. * until the vf completes a reset it should not be
  4685. * allowed to start any configuration.
  4686. */
  4687. if (msgbuf[0] == E1000_VF_RESET) {
  4688. igb_vf_reset_msg(adapter, vf);
  4689. return;
  4690. }
  4691. if (!(vf_data->flags & IGB_VF_FLAG_CTS)) {
  4692. if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
  4693. return;
  4694. retval = -1;
  4695. goto out;
  4696. }
  4697. switch ((msgbuf[0] & 0xFFFF)) {
  4698. case E1000_VF_SET_MAC_ADDR:
  4699. retval = -EINVAL;
  4700. if (!(vf_data->flags & IGB_VF_FLAG_PF_SET_MAC))
  4701. retval = igb_set_vf_mac_addr(adapter, msgbuf, vf);
  4702. else
  4703. dev_warn(&pdev->dev,
  4704. "VF %d attempted to override administratively "
  4705. "set MAC address\nReload the VF driver to "
  4706. "resume operations\n", vf);
  4707. break;
  4708. case E1000_VF_SET_PROMISC:
  4709. retval = igb_set_vf_promisc(adapter, msgbuf, vf);
  4710. break;
  4711. case E1000_VF_SET_MULTICAST:
  4712. retval = igb_set_vf_multicasts(adapter, msgbuf, vf);
  4713. break;
  4714. case E1000_VF_SET_LPE:
  4715. retval = igb_set_vf_rlpml(adapter, msgbuf[1], vf);
  4716. break;
  4717. case E1000_VF_SET_VLAN:
  4718. retval = -1;
  4719. if (vf_data->pf_vlan)
  4720. dev_warn(&pdev->dev,
  4721. "VF %d attempted to override administratively "
  4722. "set VLAN tag\nReload the VF driver to "
  4723. "resume operations\n", vf);
  4724. else
  4725. retval = igb_set_vf_vlan(adapter, msgbuf, vf);
  4726. break;
  4727. default:
  4728. dev_err(&pdev->dev, "Unhandled Msg %08x\n", msgbuf[0]);
  4729. retval = -1;
  4730. break;
  4731. }
  4732. msgbuf[0] |= E1000_VT_MSGTYPE_CTS;
  4733. out:
  4734. /* notify the VF of the results of what it sent us */
  4735. if (retval)
  4736. msgbuf[0] |= E1000_VT_MSGTYPE_NACK;
  4737. else
  4738. msgbuf[0] |= E1000_VT_MSGTYPE_ACK;
  4739. igb_write_mbx(hw, msgbuf, 1, vf);
  4740. }
  4741. static void igb_msg_task(struct igb_adapter *adapter)
  4742. {
  4743. struct e1000_hw *hw = &adapter->hw;
  4744. u32 vf;
  4745. for (vf = 0; vf < adapter->vfs_allocated_count; vf++) {
  4746. /* process any reset requests */
  4747. if (!igb_check_for_rst(hw, vf))
  4748. igb_vf_reset_event(adapter, vf);
  4749. /* process any messages pending */
  4750. if (!igb_check_for_msg(hw, vf))
  4751. igb_rcv_msg_from_vf(adapter, vf);
  4752. /* process any acks */
  4753. if (!igb_check_for_ack(hw, vf))
  4754. igb_rcv_ack_from_vf(adapter, vf);
  4755. }
  4756. }
  4757. /**
  4758. * igb_set_uta - Set unicast filter table address
  4759. * @adapter: board private structure
  4760. *
  4761. * The unicast table address is a register array of 32-bit registers.
  4762. * The table is meant to be used in a way similar to how the MTA is used
  4763. * however due to certain limitations in the hardware it is necessary to
  4764. * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
  4765. * enable bit to allow vlan tag stripping when promiscuous mode is enabled
  4766. **/
  4767. static void igb_set_uta(struct igb_adapter *adapter)
  4768. {
  4769. struct e1000_hw *hw = &adapter->hw;
  4770. int i;
  4771. /* The UTA table only exists on 82576 hardware and newer */
  4772. if (hw->mac.type < e1000_82576)
  4773. return;
  4774. /* we only need to do this if VMDq is enabled */
  4775. if (!adapter->vfs_allocated_count)
  4776. return;
  4777. for (i = 0; i < hw->mac.uta_reg_count; i++)
  4778. array_wr32(E1000_UTA, i, ~0);
  4779. }
  4780. /**
  4781. * igb_intr_msi - Interrupt Handler
  4782. * @irq: interrupt number
  4783. * @data: pointer to a network interface device structure
  4784. **/
  4785. static irqreturn_t igb_intr_msi(int irq, void *data)
  4786. {
  4787. struct igb_adapter *adapter = data;
  4788. struct igb_q_vector *q_vector = adapter->q_vector[0];
  4789. struct e1000_hw *hw = &adapter->hw;
  4790. /* read ICR disables interrupts using IAM */
  4791. u32 icr = rd32(E1000_ICR);
  4792. igb_write_itr(q_vector);
  4793. if (icr & E1000_ICR_DRSTA)
  4794. schedule_work(&adapter->reset_task);
  4795. if (icr & E1000_ICR_DOUTSYNC) {
  4796. /* HW is reporting DMA is out of sync */
  4797. adapter->stats.doosync++;
  4798. }
  4799. if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
  4800. hw->mac.get_link_status = 1;
  4801. if (!test_bit(__IGB_DOWN, &adapter->state))
  4802. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  4803. }
  4804. napi_schedule(&q_vector->napi);
  4805. return IRQ_HANDLED;
  4806. }
  4807. /**
  4808. * igb_intr - Legacy Interrupt Handler
  4809. * @irq: interrupt number
  4810. * @data: pointer to a network interface device structure
  4811. **/
  4812. static irqreturn_t igb_intr(int irq, void *data)
  4813. {
  4814. struct igb_adapter *adapter = data;
  4815. struct igb_q_vector *q_vector = adapter->q_vector[0];
  4816. struct e1000_hw *hw = &adapter->hw;
  4817. /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
  4818. * need for the IMC write */
  4819. u32 icr = rd32(E1000_ICR);
  4820. /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
  4821. * not set, then the adapter didn't send an interrupt */
  4822. if (!(icr & E1000_ICR_INT_ASSERTED))
  4823. return IRQ_NONE;
  4824. igb_write_itr(q_vector);
  4825. if (icr & E1000_ICR_DRSTA)
  4826. schedule_work(&adapter->reset_task);
  4827. if (icr & E1000_ICR_DOUTSYNC) {
  4828. /* HW is reporting DMA is out of sync */
  4829. adapter->stats.doosync++;
  4830. }
  4831. if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
  4832. hw->mac.get_link_status = 1;
  4833. /* guard against interrupt when we're going down */
  4834. if (!test_bit(__IGB_DOWN, &adapter->state))
  4835. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  4836. }
  4837. napi_schedule(&q_vector->napi);
  4838. return IRQ_HANDLED;
  4839. }
  4840. static void igb_ring_irq_enable(struct igb_q_vector *q_vector)
  4841. {
  4842. struct igb_adapter *adapter = q_vector->adapter;
  4843. struct e1000_hw *hw = &adapter->hw;
  4844. if ((q_vector->rx.ring && (adapter->rx_itr_setting & 3)) ||
  4845. (!q_vector->rx.ring && (adapter->tx_itr_setting & 3))) {
  4846. if ((adapter->num_q_vectors == 1) && !adapter->vf_data)
  4847. igb_set_itr(q_vector);
  4848. else
  4849. igb_update_ring_itr(q_vector);
  4850. }
  4851. if (!test_bit(__IGB_DOWN, &adapter->state)) {
  4852. if (adapter->msix_entries)
  4853. wr32(E1000_EIMS, q_vector->eims_value);
  4854. else
  4855. igb_irq_enable(adapter);
  4856. }
  4857. }
  4858. /**
  4859. * igb_poll - NAPI Rx polling callback
  4860. * @napi: napi polling structure
  4861. * @budget: count of how many packets we should handle
  4862. **/
  4863. static int igb_poll(struct napi_struct *napi, int budget)
  4864. {
  4865. struct igb_q_vector *q_vector = container_of(napi,
  4866. struct igb_q_vector,
  4867. napi);
  4868. bool clean_complete = true;
  4869. #ifdef CONFIG_IGB_DCA
  4870. if (q_vector->adapter->flags & IGB_FLAG_DCA_ENABLED)
  4871. igb_update_dca(q_vector);
  4872. #endif
  4873. if (q_vector->tx.ring)
  4874. clean_complete = igb_clean_tx_irq(q_vector);
  4875. if (q_vector->rx.ring)
  4876. clean_complete &= igb_clean_rx_irq(q_vector, budget);
  4877. /* If all work not completed, return budget and keep polling */
  4878. if (!clean_complete)
  4879. return budget;
  4880. /* If not enough Rx work done, exit the polling mode */
  4881. napi_complete(napi);
  4882. igb_ring_irq_enable(q_vector);
  4883. return 0;
  4884. }
  4885. /**
  4886. * igb_systim_to_hwtstamp - convert system time value to hw timestamp
  4887. * @adapter: board private structure
  4888. * @shhwtstamps: timestamp structure to update
  4889. * @regval: unsigned 64bit system time value.
  4890. *
  4891. * We need to convert the system time value stored in the RX/TXSTMP registers
  4892. * into a hwtstamp which can be used by the upper level timestamping functions
  4893. */
  4894. static void igb_systim_to_hwtstamp(struct igb_adapter *adapter,
  4895. struct skb_shared_hwtstamps *shhwtstamps,
  4896. u64 regval)
  4897. {
  4898. u64 ns;
  4899. /*
  4900. * The 82580 starts with 1ns at bit 0 in RX/TXSTMPL, shift this up to
  4901. * 24 to match clock shift we setup earlier.
  4902. */
  4903. if (adapter->hw.mac.type >= e1000_82580)
  4904. regval <<= IGB_82580_TSYNC_SHIFT;
  4905. ns = timecounter_cyc2time(&adapter->clock, regval);
  4906. timecompare_update(&adapter->compare, ns);
  4907. memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps));
  4908. shhwtstamps->hwtstamp = ns_to_ktime(ns);
  4909. shhwtstamps->syststamp = timecompare_transform(&adapter->compare, ns);
  4910. }
  4911. /**
  4912. * igb_tx_hwtstamp - utility function which checks for TX time stamp
  4913. * @q_vector: pointer to q_vector containing needed info
  4914. * @buffer: pointer to igb_tx_buffer structure
  4915. *
  4916. * If we were asked to do hardware stamping and such a time stamp is
  4917. * available, then it must have been for this skb here because we only
  4918. * allow only one such packet into the queue.
  4919. */
  4920. static void igb_tx_hwtstamp(struct igb_q_vector *q_vector,
  4921. struct igb_tx_buffer *buffer_info)
  4922. {
  4923. struct igb_adapter *adapter = q_vector->adapter;
  4924. struct e1000_hw *hw = &adapter->hw;
  4925. struct skb_shared_hwtstamps shhwtstamps;
  4926. u64 regval;
  4927. /* if skb does not support hw timestamp or TX stamp not valid exit */
  4928. if (likely(!(buffer_info->tx_flags & IGB_TX_FLAGS_TSTAMP)) ||
  4929. !(rd32(E1000_TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID))
  4930. return;
  4931. regval = rd32(E1000_TXSTMPL);
  4932. regval |= (u64)rd32(E1000_TXSTMPH) << 32;
  4933. igb_systim_to_hwtstamp(adapter, &shhwtstamps, regval);
  4934. skb_tstamp_tx(buffer_info->skb, &shhwtstamps);
  4935. }
  4936. /**
  4937. * igb_clean_tx_irq - Reclaim resources after transmit completes
  4938. * @q_vector: pointer to q_vector containing needed info
  4939. * returns true if ring is completely cleaned
  4940. **/
  4941. static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)
  4942. {
  4943. struct igb_adapter *adapter = q_vector->adapter;
  4944. struct igb_ring *tx_ring = q_vector->tx.ring;
  4945. struct igb_tx_buffer *tx_buffer;
  4946. union e1000_adv_tx_desc *tx_desc, *eop_desc;
  4947. unsigned int total_bytes = 0, total_packets = 0;
  4948. unsigned int budget = q_vector->tx.work_limit;
  4949. unsigned int i = tx_ring->next_to_clean;
  4950. if (test_bit(__IGB_DOWN, &adapter->state))
  4951. return true;
  4952. tx_buffer = &tx_ring->tx_buffer_info[i];
  4953. tx_desc = IGB_TX_DESC(tx_ring, i);
  4954. i -= tx_ring->count;
  4955. for (; budget; budget--) {
  4956. eop_desc = tx_buffer->next_to_watch;
  4957. /* prevent any other reads prior to eop_desc */
  4958. rmb();
  4959. /* if next_to_watch is not set then there is no work pending */
  4960. if (!eop_desc)
  4961. break;
  4962. /* if DD is not set pending work has not been completed */
  4963. if (!(eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)))
  4964. break;
  4965. /* clear next_to_watch to prevent false hangs */
  4966. tx_buffer->next_to_watch = NULL;
  4967. /* update the statistics for this packet */
  4968. total_bytes += tx_buffer->bytecount;
  4969. total_packets += tx_buffer->gso_segs;
  4970. /* retrieve hardware timestamp */
  4971. igb_tx_hwtstamp(q_vector, tx_buffer);
  4972. /* free the skb */
  4973. dev_kfree_skb_any(tx_buffer->skb);
  4974. tx_buffer->skb = NULL;
  4975. /* unmap skb header data */
  4976. dma_unmap_single(tx_ring->dev,
  4977. tx_buffer->dma,
  4978. tx_buffer->length,
  4979. DMA_TO_DEVICE);
  4980. /* clear last DMA location and unmap remaining buffers */
  4981. while (tx_desc != eop_desc) {
  4982. tx_buffer->dma = 0;
  4983. tx_buffer++;
  4984. tx_desc++;
  4985. i++;
  4986. if (unlikely(!i)) {
  4987. i -= tx_ring->count;
  4988. tx_buffer = tx_ring->tx_buffer_info;
  4989. tx_desc = IGB_TX_DESC(tx_ring, 0);
  4990. }
  4991. /* unmap any remaining paged data */
  4992. if (tx_buffer->dma) {
  4993. dma_unmap_page(tx_ring->dev,
  4994. tx_buffer->dma,
  4995. tx_buffer->length,
  4996. DMA_TO_DEVICE);
  4997. }
  4998. }
  4999. /* clear last DMA location */
  5000. tx_buffer->dma = 0;
  5001. /* move us one more past the eop_desc for start of next pkt */
  5002. tx_buffer++;
  5003. tx_desc++;
  5004. i++;
  5005. if (unlikely(!i)) {
  5006. i -= tx_ring->count;
  5007. tx_buffer = tx_ring->tx_buffer_info;
  5008. tx_desc = IGB_TX_DESC(tx_ring, 0);
  5009. }
  5010. }
  5011. netdev_tx_completed_queue(txring_txq(tx_ring),
  5012. total_packets, total_bytes);
  5013. i += tx_ring->count;
  5014. tx_ring->next_to_clean = i;
  5015. u64_stats_update_begin(&tx_ring->tx_syncp);
  5016. tx_ring->tx_stats.bytes += total_bytes;
  5017. tx_ring->tx_stats.packets += total_packets;
  5018. u64_stats_update_end(&tx_ring->tx_syncp);
  5019. q_vector->tx.total_bytes += total_bytes;
  5020. q_vector->tx.total_packets += total_packets;
  5021. if (test_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags)) {
  5022. struct e1000_hw *hw = &adapter->hw;
  5023. eop_desc = tx_buffer->next_to_watch;
  5024. /* Detect a transmit hang in hardware, this serializes the
  5025. * check with the clearing of time_stamp and movement of i */
  5026. clear_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
  5027. if (eop_desc &&
  5028. time_after(jiffies, tx_buffer->time_stamp +
  5029. (adapter->tx_timeout_factor * HZ)) &&
  5030. !(rd32(E1000_STATUS) & E1000_STATUS_TXOFF)) {
  5031. /* detected Tx unit hang */
  5032. dev_err(tx_ring->dev,
  5033. "Detected Tx Unit Hang\n"
  5034. " Tx Queue <%d>\n"
  5035. " TDH <%x>\n"
  5036. " TDT <%x>\n"
  5037. " next_to_use <%x>\n"
  5038. " next_to_clean <%x>\n"
  5039. "buffer_info[next_to_clean]\n"
  5040. " time_stamp <%lx>\n"
  5041. " next_to_watch <%p>\n"
  5042. " jiffies <%lx>\n"
  5043. " desc.status <%x>\n",
  5044. tx_ring->queue_index,
  5045. rd32(E1000_TDH(tx_ring->reg_idx)),
  5046. readl(tx_ring->tail),
  5047. tx_ring->next_to_use,
  5048. tx_ring->next_to_clean,
  5049. tx_buffer->time_stamp,
  5050. eop_desc,
  5051. jiffies,
  5052. eop_desc->wb.status);
  5053. netif_stop_subqueue(tx_ring->netdev,
  5054. tx_ring->queue_index);
  5055. /* we are about to reset, no point in enabling stuff */
  5056. return true;
  5057. }
  5058. }
  5059. if (unlikely(total_packets &&
  5060. netif_carrier_ok(tx_ring->netdev) &&
  5061. igb_desc_unused(tx_ring) >= IGB_TX_QUEUE_WAKE)) {
  5062. /* Make sure that anybody stopping the queue after this
  5063. * sees the new next_to_clean.
  5064. */
  5065. smp_mb();
  5066. if (__netif_subqueue_stopped(tx_ring->netdev,
  5067. tx_ring->queue_index) &&
  5068. !(test_bit(__IGB_DOWN, &adapter->state))) {
  5069. netif_wake_subqueue(tx_ring->netdev,
  5070. tx_ring->queue_index);
  5071. u64_stats_update_begin(&tx_ring->tx_syncp);
  5072. tx_ring->tx_stats.restart_queue++;
  5073. u64_stats_update_end(&tx_ring->tx_syncp);
  5074. }
  5075. }
  5076. return !!budget;
  5077. }
  5078. static inline void igb_rx_checksum(struct igb_ring *ring,
  5079. union e1000_adv_rx_desc *rx_desc,
  5080. struct sk_buff *skb)
  5081. {
  5082. skb_checksum_none_assert(skb);
  5083. /* Ignore Checksum bit is set */
  5084. if (igb_test_staterr(rx_desc, E1000_RXD_STAT_IXSM))
  5085. return;
  5086. /* Rx checksum disabled via ethtool */
  5087. if (!(ring->netdev->features & NETIF_F_RXCSUM))
  5088. return;
  5089. /* TCP/UDP checksum error bit is set */
  5090. if (igb_test_staterr(rx_desc,
  5091. E1000_RXDEXT_STATERR_TCPE |
  5092. E1000_RXDEXT_STATERR_IPE)) {
  5093. /*
  5094. * work around errata with sctp packets where the TCPE aka
  5095. * L4E bit is set incorrectly on 64 byte (60 byte w/o crc)
  5096. * packets, (aka let the stack check the crc32c)
  5097. */
  5098. if (!((skb->len == 60) &&
  5099. test_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags))) {
  5100. u64_stats_update_begin(&ring->rx_syncp);
  5101. ring->rx_stats.csum_err++;
  5102. u64_stats_update_end(&ring->rx_syncp);
  5103. }
  5104. /* let the stack verify checksum errors */
  5105. return;
  5106. }
  5107. /* It must be a TCP or UDP packet with a valid checksum */
  5108. if (igb_test_staterr(rx_desc, E1000_RXD_STAT_TCPCS |
  5109. E1000_RXD_STAT_UDPCS))
  5110. skb->ip_summed = CHECKSUM_UNNECESSARY;
  5111. dev_dbg(ring->dev, "cksum success: bits %08X\n",
  5112. le32_to_cpu(rx_desc->wb.upper.status_error));
  5113. }
  5114. static inline void igb_rx_hash(struct igb_ring *ring,
  5115. union e1000_adv_rx_desc *rx_desc,
  5116. struct sk_buff *skb)
  5117. {
  5118. if (ring->netdev->features & NETIF_F_RXHASH)
  5119. skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
  5120. }
  5121. static void igb_rx_hwtstamp(struct igb_q_vector *q_vector,
  5122. union e1000_adv_rx_desc *rx_desc,
  5123. struct sk_buff *skb)
  5124. {
  5125. struct igb_adapter *adapter = q_vector->adapter;
  5126. struct e1000_hw *hw = &adapter->hw;
  5127. u64 regval;
  5128. if (!igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP |
  5129. E1000_RXDADV_STAT_TS))
  5130. return;
  5131. /*
  5132. * If this bit is set, then the RX registers contain the time stamp. No
  5133. * other packet will be time stamped until we read these registers, so
  5134. * read the registers to make them available again. Because only one
  5135. * packet can be time stamped at a time, we know that the register
  5136. * values must belong to this one here and therefore we don't need to
  5137. * compare any of the additional attributes stored for it.
  5138. *
  5139. * If nothing went wrong, then it should have a shared tx_flags that we
  5140. * can turn into a skb_shared_hwtstamps.
  5141. */
  5142. if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
  5143. u32 *stamp = (u32 *)skb->data;
  5144. regval = le32_to_cpu(*(stamp + 2));
  5145. regval |= (u64)le32_to_cpu(*(stamp + 3)) << 32;
  5146. skb_pull(skb, IGB_TS_HDR_LEN);
  5147. } else {
  5148. if(!(rd32(E1000_TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
  5149. return;
  5150. regval = rd32(E1000_RXSTMPL);
  5151. regval |= (u64)rd32(E1000_RXSTMPH) << 32;
  5152. }
  5153. igb_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), regval);
  5154. }
  5155. static void igb_rx_vlan(struct igb_ring *ring,
  5156. union e1000_adv_rx_desc *rx_desc,
  5157. struct sk_buff *skb)
  5158. {
  5159. if (igb_test_staterr(rx_desc, E1000_RXD_STAT_VP)) {
  5160. u16 vid;
  5161. if (igb_test_staterr(rx_desc, E1000_RXDEXT_STATERR_LB) &&
  5162. test_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &ring->flags))
  5163. vid = be16_to_cpu(rx_desc->wb.upper.vlan);
  5164. else
  5165. vid = le16_to_cpu(rx_desc->wb.upper.vlan);
  5166. __vlan_hwaccel_put_tag(skb, vid);
  5167. }
  5168. }
  5169. static inline u16 igb_get_hlen(union e1000_adv_rx_desc *rx_desc)
  5170. {
  5171. /* HW will not DMA in data larger than the given buffer, even if it
  5172. * parses the (NFS, of course) header to be larger. In that case, it
  5173. * fills the header buffer and spills the rest into the page.
  5174. */
  5175. u16 hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hdr_info) &
  5176. E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT;
  5177. if (hlen > IGB_RX_HDR_LEN)
  5178. hlen = IGB_RX_HDR_LEN;
  5179. return hlen;
  5180. }
  5181. static bool igb_clean_rx_irq(struct igb_q_vector *q_vector, int budget)
  5182. {
  5183. struct igb_ring *rx_ring = q_vector->rx.ring;
  5184. union e1000_adv_rx_desc *rx_desc;
  5185. const int current_node = numa_node_id();
  5186. unsigned int total_bytes = 0, total_packets = 0;
  5187. u16 cleaned_count = igb_desc_unused(rx_ring);
  5188. u16 i = rx_ring->next_to_clean;
  5189. rx_desc = IGB_RX_DESC(rx_ring, i);
  5190. while (igb_test_staterr(rx_desc, E1000_RXD_STAT_DD)) {
  5191. struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i];
  5192. struct sk_buff *skb = buffer_info->skb;
  5193. union e1000_adv_rx_desc *next_rxd;
  5194. buffer_info->skb = NULL;
  5195. prefetch(skb->data);
  5196. i++;
  5197. if (i == rx_ring->count)
  5198. i = 0;
  5199. next_rxd = IGB_RX_DESC(rx_ring, i);
  5200. prefetch(next_rxd);
  5201. /*
  5202. * This memory barrier is needed to keep us from reading
  5203. * any other fields out of the rx_desc until we know the
  5204. * RXD_STAT_DD bit is set
  5205. */
  5206. rmb();
  5207. if (!skb_is_nonlinear(skb)) {
  5208. __skb_put(skb, igb_get_hlen(rx_desc));
  5209. dma_unmap_single(rx_ring->dev, buffer_info->dma,
  5210. IGB_RX_HDR_LEN,
  5211. DMA_FROM_DEVICE);
  5212. buffer_info->dma = 0;
  5213. }
  5214. if (rx_desc->wb.upper.length) {
  5215. u16 length = le16_to_cpu(rx_desc->wb.upper.length);
  5216. skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
  5217. buffer_info->page,
  5218. buffer_info->page_offset,
  5219. length);
  5220. skb->len += length;
  5221. skb->data_len += length;
  5222. skb->truesize += PAGE_SIZE / 2;
  5223. if ((page_count(buffer_info->page) != 1) ||
  5224. (page_to_nid(buffer_info->page) != current_node))
  5225. buffer_info->page = NULL;
  5226. else
  5227. get_page(buffer_info->page);
  5228. dma_unmap_page(rx_ring->dev, buffer_info->page_dma,
  5229. PAGE_SIZE / 2, DMA_FROM_DEVICE);
  5230. buffer_info->page_dma = 0;
  5231. }
  5232. if (!igb_test_staterr(rx_desc, E1000_RXD_STAT_EOP)) {
  5233. struct igb_rx_buffer *next_buffer;
  5234. next_buffer = &rx_ring->rx_buffer_info[i];
  5235. buffer_info->skb = next_buffer->skb;
  5236. buffer_info->dma = next_buffer->dma;
  5237. next_buffer->skb = skb;
  5238. next_buffer->dma = 0;
  5239. goto next_desc;
  5240. }
  5241. if (unlikely((igb_test_staterr(rx_desc,
  5242. E1000_RXDEXT_ERR_FRAME_ERR_MASK))
  5243. && !(rx_ring->netdev->features & NETIF_F_RXALL))) {
  5244. dev_kfree_skb_any(skb);
  5245. goto next_desc;
  5246. }
  5247. igb_rx_hwtstamp(q_vector, rx_desc, skb);
  5248. igb_rx_hash(rx_ring, rx_desc, skb);
  5249. igb_rx_checksum(rx_ring, rx_desc, skb);
  5250. igb_rx_vlan(rx_ring, rx_desc, skb);
  5251. total_bytes += skb->len;
  5252. total_packets++;
  5253. skb->protocol = eth_type_trans(skb, rx_ring->netdev);
  5254. napi_gro_receive(&q_vector->napi, skb);
  5255. budget--;
  5256. next_desc:
  5257. if (!budget)
  5258. break;
  5259. cleaned_count++;
  5260. /* return some buffers to hardware, one at a time is too slow */
  5261. if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
  5262. igb_alloc_rx_buffers(rx_ring, cleaned_count);
  5263. cleaned_count = 0;
  5264. }
  5265. /* use prefetched values */
  5266. rx_desc = next_rxd;
  5267. }
  5268. rx_ring->next_to_clean = i;
  5269. u64_stats_update_begin(&rx_ring->rx_syncp);
  5270. rx_ring->rx_stats.packets += total_packets;
  5271. rx_ring->rx_stats.bytes += total_bytes;
  5272. u64_stats_update_end(&rx_ring->rx_syncp);
  5273. q_vector->rx.total_packets += total_packets;
  5274. q_vector->rx.total_bytes += total_bytes;
  5275. if (cleaned_count)
  5276. igb_alloc_rx_buffers(rx_ring, cleaned_count);
  5277. return !!budget;
  5278. }
  5279. static bool igb_alloc_mapped_skb(struct igb_ring *rx_ring,
  5280. struct igb_rx_buffer *bi)
  5281. {
  5282. struct sk_buff *skb = bi->skb;
  5283. dma_addr_t dma = bi->dma;
  5284. if (dma)
  5285. return true;
  5286. if (likely(!skb)) {
  5287. skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
  5288. IGB_RX_HDR_LEN);
  5289. bi->skb = skb;
  5290. if (!skb) {
  5291. rx_ring->rx_stats.alloc_failed++;
  5292. return false;
  5293. }
  5294. /* initialize skb for ring */
  5295. skb_record_rx_queue(skb, rx_ring->queue_index);
  5296. }
  5297. dma = dma_map_single(rx_ring->dev, skb->data,
  5298. IGB_RX_HDR_LEN, DMA_FROM_DEVICE);
  5299. if (dma_mapping_error(rx_ring->dev, dma)) {
  5300. rx_ring->rx_stats.alloc_failed++;
  5301. return false;
  5302. }
  5303. bi->dma = dma;
  5304. return true;
  5305. }
  5306. static bool igb_alloc_mapped_page(struct igb_ring *rx_ring,
  5307. struct igb_rx_buffer *bi)
  5308. {
  5309. struct page *page = bi->page;
  5310. dma_addr_t page_dma = bi->page_dma;
  5311. unsigned int page_offset = bi->page_offset ^ (PAGE_SIZE / 2);
  5312. if (page_dma)
  5313. return true;
  5314. if (!page) {
  5315. page = alloc_page(GFP_ATOMIC | __GFP_COLD);
  5316. bi->page = page;
  5317. if (unlikely(!page)) {
  5318. rx_ring->rx_stats.alloc_failed++;
  5319. return false;
  5320. }
  5321. }
  5322. page_dma = dma_map_page(rx_ring->dev, page,
  5323. page_offset, PAGE_SIZE / 2,
  5324. DMA_FROM_DEVICE);
  5325. if (dma_mapping_error(rx_ring->dev, page_dma)) {
  5326. rx_ring->rx_stats.alloc_failed++;
  5327. return false;
  5328. }
  5329. bi->page_dma = page_dma;
  5330. bi->page_offset = page_offset;
  5331. return true;
  5332. }
  5333. /**
  5334. * igb_alloc_rx_buffers - Replace used receive buffers; packet split
  5335. * @adapter: address of board private structure
  5336. **/
  5337. void igb_alloc_rx_buffers(struct igb_ring *rx_ring, u16 cleaned_count)
  5338. {
  5339. union e1000_adv_rx_desc *rx_desc;
  5340. struct igb_rx_buffer *bi;
  5341. u16 i = rx_ring->next_to_use;
  5342. rx_desc = IGB_RX_DESC(rx_ring, i);
  5343. bi = &rx_ring->rx_buffer_info[i];
  5344. i -= rx_ring->count;
  5345. while (cleaned_count--) {
  5346. if (!igb_alloc_mapped_skb(rx_ring, bi))
  5347. break;
  5348. /* Refresh the desc even if buffer_addrs didn't change
  5349. * because each write-back erases this info. */
  5350. rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
  5351. if (!igb_alloc_mapped_page(rx_ring, bi))
  5352. break;
  5353. rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
  5354. rx_desc++;
  5355. bi++;
  5356. i++;
  5357. if (unlikely(!i)) {
  5358. rx_desc = IGB_RX_DESC(rx_ring, 0);
  5359. bi = rx_ring->rx_buffer_info;
  5360. i -= rx_ring->count;
  5361. }
  5362. /* clear the hdr_addr for the next_to_use descriptor */
  5363. rx_desc->read.hdr_addr = 0;
  5364. }
  5365. i += rx_ring->count;
  5366. if (rx_ring->next_to_use != i) {
  5367. rx_ring->next_to_use = i;
  5368. /* Force memory writes to complete before letting h/w
  5369. * know there are new descriptors to fetch. (Only
  5370. * applicable for weak-ordered memory model archs,
  5371. * such as IA-64). */
  5372. wmb();
  5373. writel(i, rx_ring->tail);
  5374. }
  5375. }
  5376. /**
  5377. * igb_mii_ioctl -
  5378. * @netdev:
  5379. * @ifreq:
  5380. * @cmd:
  5381. **/
  5382. static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  5383. {
  5384. struct igb_adapter *adapter = netdev_priv(netdev);
  5385. struct mii_ioctl_data *data = if_mii(ifr);
  5386. if (adapter->hw.phy.media_type != e1000_media_type_copper)
  5387. return -EOPNOTSUPP;
  5388. switch (cmd) {
  5389. case SIOCGMIIPHY:
  5390. data->phy_id = adapter->hw.phy.addr;
  5391. break;
  5392. case SIOCGMIIREG:
  5393. if (igb_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
  5394. &data->val_out))
  5395. return -EIO;
  5396. break;
  5397. case SIOCSMIIREG:
  5398. default:
  5399. return -EOPNOTSUPP;
  5400. }
  5401. return 0;
  5402. }
  5403. /**
  5404. * igb_hwtstamp_ioctl - control hardware time stamping
  5405. * @netdev:
  5406. * @ifreq:
  5407. * @cmd:
  5408. *
  5409. * Outgoing time stamping can be enabled and disabled. Play nice and
  5410. * disable it when requested, although it shouldn't case any overhead
  5411. * when no packet needs it. At most one packet in the queue may be
  5412. * marked for time stamping, otherwise it would be impossible to tell
  5413. * for sure to which packet the hardware time stamp belongs.
  5414. *
  5415. * Incoming time stamping has to be configured via the hardware
  5416. * filters. Not all combinations are supported, in particular event
  5417. * type has to be specified. Matching the kind of event packet is
  5418. * not supported, with the exception of "all V2 events regardless of
  5419. * level 2 or 4".
  5420. *
  5421. **/
  5422. static int igb_hwtstamp_ioctl(struct net_device *netdev,
  5423. struct ifreq *ifr, int cmd)
  5424. {
  5425. struct igb_adapter *adapter = netdev_priv(netdev);
  5426. struct e1000_hw *hw = &adapter->hw;
  5427. struct hwtstamp_config config;
  5428. u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
  5429. u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
  5430. u32 tsync_rx_cfg = 0;
  5431. bool is_l4 = false;
  5432. bool is_l2 = false;
  5433. u32 regval;
  5434. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  5435. return -EFAULT;
  5436. /* reserved for future extensions */
  5437. if (config.flags)
  5438. return -EINVAL;
  5439. switch (config.tx_type) {
  5440. case HWTSTAMP_TX_OFF:
  5441. tsync_tx_ctl = 0;
  5442. case HWTSTAMP_TX_ON:
  5443. break;
  5444. default:
  5445. return -ERANGE;
  5446. }
  5447. switch (config.rx_filter) {
  5448. case HWTSTAMP_FILTER_NONE:
  5449. tsync_rx_ctl = 0;
  5450. break;
  5451. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  5452. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  5453. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  5454. case HWTSTAMP_FILTER_ALL:
  5455. /*
  5456. * register TSYNCRXCFG must be set, therefore it is not
  5457. * possible to time stamp both Sync and Delay_Req messages
  5458. * => fall back to time stamping all packets
  5459. */
  5460. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
  5461. config.rx_filter = HWTSTAMP_FILTER_ALL;
  5462. break;
  5463. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  5464. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
  5465. tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE;
  5466. is_l4 = true;
  5467. break;
  5468. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  5469. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
  5470. tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE;
  5471. is_l4 = true;
  5472. break;
  5473. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  5474. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  5475. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
  5476. tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_SYNC_MESSAGE;
  5477. is_l2 = true;
  5478. is_l4 = true;
  5479. config.rx_filter = HWTSTAMP_FILTER_SOME;
  5480. break;
  5481. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  5482. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  5483. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
  5484. tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_DELAY_REQ_MESSAGE;
  5485. is_l2 = true;
  5486. is_l4 = true;
  5487. config.rx_filter = HWTSTAMP_FILTER_SOME;
  5488. break;
  5489. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  5490. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  5491. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  5492. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
  5493. config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  5494. is_l2 = true;
  5495. is_l4 = true;
  5496. break;
  5497. default:
  5498. return -ERANGE;
  5499. }
  5500. if (hw->mac.type == e1000_82575) {
  5501. if (tsync_rx_ctl | tsync_tx_ctl)
  5502. return -EINVAL;
  5503. return 0;
  5504. }
  5505. /*
  5506. * Per-packet timestamping only works if all packets are
  5507. * timestamped, so enable timestamping in all packets as
  5508. * long as one rx filter was configured.
  5509. */
  5510. if ((hw->mac.type >= e1000_82580) && tsync_rx_ctl) {
  5511. tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
  5512. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
  5513. }
  5514. /* enable/disable TX */
  5515. regval = rd32(E1000_TSYNCTXCTL);
  5516. regval &= ~E1000_TSYNCTXCTL_ENABLED;
  5517. regval |= tsync_tx_ctl;
  5518. wr32(E1000_TSYNCTXCTL, regval);
  5519. /* enable/disable RX */
  5520. regval = rd32(E1000_TSYNCRXCTL);
  5521. regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
  5522. regval |= tsync_rx_ctl;
  5523. wr32(E1000_TSYNCRXCTL, regval);
  5524. /* define which PTP packets are time stamped */
  5525. wr32(E1000_TSYNCRXCFG, tsync_rx_cfg);
  5526. /* define ethertype filter for timestamped packets */
  5527. if (is_l2)
  5528. wr32(E1000_ETQF(3),
  5529. (E1000_ETQF_FILTER_ENABLE | /* enable filter */
  5530. E1000_ETQF_1588 | /* enable timestamping */
  5531. ETH_P_1588)); /* 1588 eth protocol type */
  5532. else
  5533. wr32(E1000_ETQF(3), 0);
  5534. #define PTP_PORT 319
  5535. /* L4 Queue Filter[3]: filter by destination port and protocol */
  5536. if (is_l4) {
  5537. u32 ftqf = (IPPROTO_UDP /* UDP */
  5538. | E1000_FTQF_VF_BP /* VF not compared */
  5539. | E1000_FTQF_1588_TIME_STAMP /* Enable Timestamping */
  5540. | E1000_FTQF_MASK); /* mask all inputs */
  5541. ftqf &= ~E1000_FTQF_MASK_PROTO_BP; /* enable protocol check */
  5542. wr32(E1000_IMIR(3), htons(PTP_PORT));
  5543. wr32(E1000_IMIREXT(3),
  5544. (E1000_IMIREXT_SIZE_BP | E1000_IMIREXT_CTRL_BP));
  5545. if (hw->mac.type == e1000_82576) {
  5546. /* enable source port check */
  5547. wr32(E1000_SPQF(3), htons(PTP_PORT));
  5548. ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP;
  5549. }
  5550. wr32(E1000_FTQF(3), ftqf);
  5551. } else {
  5552. wr32(E1000_FTQF(3), E1000_FTQF_MASK);
  5553. }
  5554. wrfl();
  5555. adapter->hwtstamp_config = config;
  5556. /* clear TX/RX time stamp registers, just to be sure */
  5557. regval = rd32(E1000_TXSTMPH);
  5558. regval = rd32(E1000_RXSTMPH);
  5559. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  5560. -EFAULT : 0;
  5561. }
  5562. /**
  5563. * igb_ioctl -
  5564. * @netdev:
  5565. * @ifreq:
  5566. * @cmd:
  5567. **/
  5568. static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  5569. {
  5570. switch (cmd) {
  5571. case SIOCGMIIPHY:
  5572. case SIOCGMIIREG:
  5573. case SIOCSMIIREG:
  5574. return igb_mii_ioctl(netdev, ifr, cmd);
  5575. case SIOCSHWTSTAMP:
  5576. return igb_hwtstamp_ioctl(netdev, ifr, cmd);
  5577. default:
  5578. return -EOPNOTSUPP;
  5579. }
  5580. }
  5581. s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
  5582. {
  5583. struct igb_adapter *adapter = hw->back;
  5584. u16 cap_offset;
  5585. cap_offset = adapter->pdev->pcie_cap;
  5586. if (!cap_offset)
  5587. return -E1000_ERR_CONFIG;
  5588. pci_read_config_word(adapter->pdev, cap_offset + reg, value);
  5589. return 0;
  5590. }
  5591. s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
  5592. {
  5593. struct igb_adapter *adapter = hw->back;
  5594. u16 cap_offset;
  5595. cap_offset = adapter->pdev->pcie_cap;
  5596. if (!cap_offset)
  5597. return -E1000_ERR_CONFIG;
  5598. pci_write_config_word(adapter->pdev, cap_offset + reg, *value);
  5599. return 0;
  5600. }
  5601. static void igb_vlan_mode(struct net_device *netdev, netdev_features_t features)
  5602. {
  5603. struct igb_adapter *adapter = netdev_priv(netdev);
  5604. struct e1000_hw *hw = &adapter->hw;
  5605. u32 ctrl, rctl;
  5606. bool enable = !!(features & NETIF_F_HW_VLAN_RX);
  5607. if (enable) {
  5608. /* enable VLAN tag insert/strip */
  5609. ctrl = rd32(E1000_CTRL);
  5610. ctrl |= E1000_CTRL_VME;
  5611. wr32(E1000_CTRL, ctrl);
  5612. /* Disable CFI check */
  5613. rctl = rd32(E1000_RCTL);
  5614. rctl &= ~E1000_RCTL_CFIEN;
  5615. wr32(E1000_RCTL, rctl);
  5616. } else {
  5617. /* disable VLAN tag insert/strip */
  5618. ctrl = rd32(E1000_CTRL);
  5619. ctrl &= ~E1000_CTRL_VME;
  5620. wr32(E1000_CTRL, ctrl);
  5621. }
  5622. igb_rlpml_set(adapter);
  5623. }
  5624. static int igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  5625. {
  5626. struct igb_adapter *adapter = netdev_priv(netdev);
  5627. struct e1000_hw *hw = &adapter->hw;
  5628. int pf_id = adapter->vfs_allocated_count;
  5629. /* attempt to add filter to vlvf array */
  5630. igb_vlvf_set(adapter, vid, true, pf_id);
  5631. /* add the filter since PF can receive vlans w/o entry in vlvf */
  5632. igb_vfta_set(hw, vid, true);
  5633. set_bit(vid, adapter->active_vlans);
  5634. return 0;
  5635. }
  5636. static int igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  5637. {
  5638. struct igb_adapter *adapter = netdev_priv(netdev);
  5639. struct e1000_hw *hw = &adapter->hw;
  5640. int pf_id = adapter->vfs_allocated_count;
  5641. s32 err;
  5642. /* remove vlan from VLVF table array */
  5643. err = igb_vlvf_set(adapter, vid, false, pf_id);
  5644. /* if vid was not present in VLVF just remove it from table */
  5645. if (err)
  5646. igb_vfta_set(hw, vid, false);
  5647. clear_bit(vid, adapter->active_vlans);
  5648. return 0;
  5649. }
  5650. static void igb_restore_vlan(struct igb_adapter *adapter)
  5651. {
  5652. u16 vid;
  5653. igb_vlan_mode(adapter->netdev, adapter->netdev->features);
  5654. for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
  5655. igb_vlan_rx_add_vid(adapter->netdev, vid);
  5656. }
  5657. int igb_set_spd_dplx(struct igb_adapter *adapter, u32 spd, u8 dplx)
  5658. {
  5659. struct pci_dev *pdev = adapter->pdev;
  5660. struct e1000_mac_info *mac = &adapter->hw.mac;
  5661. mac->autoneg = 0;
  5662. /* Make sure dplx is at most 1 bit and lsb of speed is not set
  5663. * for the switch() below to work */
  5664. if ((spd & 1) || (dplx & ~1))
  5665. goto err_inval;
  5666. /* Fiber NIC's only allow 1000 Gbps Full duplex */
  5667. if ((adapter->hw.phy.media_type == e1000_media_type_internal_serdes) &&
  5668. spd != SPEED_1000 &&
  5669. dplx != DUPLEX_FULL)
  5670. goto err_inval;
  5671. switch (spd + dplx) {
  5672. case SPEED_10 + DUPLEX_HALF:
  5673. mac->forced_speed_duplex = ADVERTISE_10_HALF;
  5674. break;
  5675. case SPEED_10 + DUPLEX_FULL:
  5676. mac->forced_speed_duplex = ADVERTISE_10_FULL;
  5677. break;
  5678. case SPEED_100 + DUPLEX_HALF:
  5679. mac->forced_speed_duplex = ADVERTISE_100_HALF;
  5680. break;
  5681. case SPEED_100 + DUPLEX_FULL:
  5682. mac->forced_speed_duplex = ADVERTISE_100_FULL;
  5683. break;
  5684. case SPEED_1000 + DUPLEX_FULL:
  5685. mac->autoneg = 1;
  5686. adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
  5687. break;
  5688. case SPEED_1000 + DUPLEX_HALF: /* not supported */
  5689. default:
  5690. goto err_inval;
  5691. }
  5692. return 0;
  5693. err_inval:
  5694. dev_err(&pdev->dev, "Unsupported Speed/Duplex configuration\n");
  5695. return -EINVAL;
  5696. }
  5697. static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake,
  5698. bool runtime)
  5699. {
  5700. struct net_device *netdev = pci_get_drvdata(pdev);
  5701. struct igb_adapter *adapter = netdev_priv(netdev);
  5702. struct e1000_hw *hw = &adapter->hw;
  5703. u32 ctrl, rctl, status;
  5704. u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
  5705. #ifdef CONFIG_PM
  5706. int retval = 0;
  5707. #endif
  5708. netif_device_detach(netdev);
  5709. if (netif_running(netdev))
  5710. __igb_close(netdev, true);
  5711. igb_clear_interrupt_scheme(adapter);
  5712. #ifdef CONFIG_PM
  5713. retval = pci_save_state(pdev);
  5714. if (retval)
  5715. return retval;
  5716. #endif
  5717. status = rd32(E1000_STATUS);
  5718. if (status & E1000_STATUS_LU)
  5719. wufc &= ~E1000_WUFC_LNKC;
  5720. if (wufc) {
  5721. igb_setup_rctl(adapter);
  5722. igb_set_rx_mode(netdev);
  5723. /* turn on all-multi mode if wake on multicast is enabled */
  5724. if (wufc & E1000_WUFC_MC) {
  5725. rctl = rd32(E1000_RCTL);
  5726. rctl |= E1000_RCTL_MPE;
  5727. wr32(E1000_RCTL, rctl);
  5728. }
  5729. ctrl = rd32(E1000_CTRL);
  5730. /* advertise wake from D3Cold */
  5731. #define E1000_CTRL_ADVD3WUC 0x00100000
  5732. /* phy power management enable */
  5733. #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
  5734. ctrl |= E1000_CTRL_ADVD3WUC;
  5735. wr32(E1000_CTRL, ctrl);
  5736. /* Allow time for pending master requests to run */
  5737. igb_disable_pcie_master(hw);
  5738. wr32(E1000_WUC, E1000_WUC_PME_EN);
  5739. wr32(E1000_WUFC, wufc);
  5740. } else {
  5741. wr32(E1000_WUC, 0);
  5742. wr32(E1000_WUFC, 0);
  5743. }
  5744. *enable_wake = wufc || adapter->en_mng_pt;
  5745. if (!*enable_wake)
  5746. igb_power_down_link(adapter);
  5747. else
  5748. igb_power_up_link(adapter);
  5749. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  5750. * would have already happened in close and is redundant. */
  5751. igb_release_hw_control(adapter);
  5752. pci_disable_device(pdev);
  5753. return 0;
  5754. }
  5755. #ifdef CONFIG_PM
  5756. #ifdef CONFIG_PM_SLEEP
  5757. static int igb_suspend(struct device *dev)
  5758. {
  5759. int retval;
  5760. bool wake;
  5761. struct pci_dev *pdev = to_pci_dev(dev);
  5762. retval = __igb_shutdown(pdev, &wake, 0);
  5763. if (retval)
  5764. return retval;
  5765. if (wake) {
  5766. pci_prepare_to_sleep(pdev);
  5767. } else {
  5768. pci_wake_from_d3(pdev, false);
  5769. pci_set_power_state(pdev, PCI_D3hot);
  5770. }
  5771. return 0;
  5772. }
  5773. #endif /* CONFIG_PM_SLEEP */
  5774. static int igb_resume(struct device *dev)
  5775. {
  5776. struct pci_dev *pdev = to_pci_dev(dev);
  5777. struct net_device *netdev = pci_get_drvdata(pdev);
  5778. struct igb_adapter *adapter = netdev_priv(netdev);
  5779. struct e1000_hw *hw = &adapter->hw;
  5780. u32 err;
  5781. pci_set_power_state(pdev, PCI_D0);
  5782. pci_restore_state(pdev);
  5783. pci_save_state(pdev);
  5784. err = pci_enable_device_mem(pdev);
  5785. if (err) {
  5786. dev_err(&pdev->dev,
  5787. "igb: Cannot enable PCI device from suspend\n");
  5788. return err;
  5789. }
  5790. pci_set_master(pdev);
  5791. pci_enable_wake(pdev, PCI_D3hot, 0);
  5792. pci_enable_wake(pdev, PCI_D3cold, 0);
  5793. if (!rtnl_is_locked()) {
  5794. /*
  5795. * shut up ASSERT_RTNL() warning in
  5796. * netif_set_real_num_tx/rx_queues.
  5797. */
  5798. rtnl_lock();
  5799. err = igb_init_interrupt_scheme(adapter);
  5800. rtnl_unlock();
  5801. } else {
  5802. err = igb_init_interrupt_scheme(adapter);
  5803. }
  5804. if (err) {
  5805. dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
  5806. return -ENOMEM;
  5807. }
  5808. igb_reset(adapter);
  5809. /* let the f/w know that the h/w is now under the control of the
  5810. * driver. */
  5811. igb_get_hw_control(adapter);
  5812. wr32(E1000_WUS, ~0);
  5813. if (netdev->flags & IFF_UP) {
  5814. err = __igb_open(netdev, true);
  5815. if (err)
  5816. return err;
  5817. }
  5818. netif_device_attach(netdev);
  5819. return 0;
  5820. }
  5821. #ifdef CONFIG_PM_RUNTIME
  5822. static int igb_runtime_idle(struct device *dev)
  5823. {
  5824. struct pci_dev *pdev = to_pci_dev(dev);
  5825. struct net_device *netdev = pci_get_drvdata(pdev);
  5826. struct igb_adapter *adapter = netdev_priv(netdev);
  5827. if (!igb_has_link(adapter))
  5828. pm_schedule_suspend(dev, MSEC_PER_SEC * 5);
  5829. return -EBUSY;
  5830. }
  5831. static int igb_runtime_suspend(struct device *dev)
  5832. {
  5833. struct pci_dev *pdev = to_pci_dev(dev);
  5834. int retval;
  5835. bool wake;
  5836. retval = __igb_shutdown(pdev, &wake, 1);
  5837. if (retval)
  5838. return retval;
  5839. if (wake) {
  5840. pci_prepare_to_sleep(pdev);
  5841. } else {
  5842. pci_wake_from_d3(pdev, false);
  5843. pci_set_power_state(pdev, PCI_D3hot);
  5844. }
  5845. return 0;
  5846. }
  5847. static int igb_runtime_resume(struct device *dev)
  5848. {
  5849. return igb_resume(dev);
  5850. }
  5851. #endif /* CONFIG_PM_RUNTIME */
  5852. #endif
  5853. static void igb_shutdown(struct pci_dev *pdev)
  5854. {
  5855. bool wake;
  5856. __igb_shutdown(pdev, &wake, 0);
  5857. if (system_state == SYSTEM_POWER_OFF) {
  5858. pci_wake_from_d3(pdev, wake);
  5859. pci_set_power_state(pdev, PCI_D3hot);
  5860. }
  5861. }
  5862. #ifdef CONFIG_NET_POLL_CONTROLLER
  5863. /*
  5864. * Polling 'interrupt' - used by things like netconsole to send skbs
  5865. * without having to re-enable interrupts. It's not called while
  5866. * the interrupt routine is executing.
  5867. */
  5868. static void igb_netpoll(struct net_device *netdev)
  5869. {
  5870. struct igb_adapter *adapter = netdev_priv(netdev);
  5871. struct e1000_hw *hw = &adapter->hw;
  5872. struct igb_q_vector *q_vector;
  5873. int i;
  5874. for (i = 0; i < adapter->num_q_vectors; i++) {
  5875. q_vector = adapter->q_vector[i];
  5876. if (adapter->msix_entries)
  5877. wr32(E1000_EIMC, q_vector->eims_value);
  5878. else
  5879. igb_irq_disable(adapter);
  5880. napi_schedule(&q_vector->napi);
  5881. }
  5882. }
  5883. #endif /* CONFIG_NET_POLL_CONTROLLER */
  5884. /**
  5885. * igb_io_error_detected - called when PCI error is detected
  5886. * @pdev: Pointer to PCI device
  5887. * @state: The current pci connection state
  5888. *
  5889. * This function is called after a PCI bus error affecting
  5890. * this device has been detected.
  5891. */
  5892. static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,
  5893. pci_channel_state_t state)
  5894. {
  5895. struct net_device *netdev = pci_get_drvdata(pdev);
  5896. struct igb_adapter *adapter = netdev_priv(netdev);
  5897. netif_device_detach(netdev);
  5898. if (state == pci_channel_io_perm_failure)
  5899. return PCI_ERS_RESULT_DISCONNECT;
  5900. if (netif_running(netdev))
  5901. igb_down(adapter);
  5902. pci_disable_device(pdev);
  5903. /* Request a slot slot reset. */
  5904. return PCI_ERS_RESULT_NEED_RESET;
  5905. }
  5906. /**
  5907. * igb_io_slot_reset - called after the pci bus has been reset.
  5908. * @pdev: Pointer to PCI device
  5909. *
  5910. * Restart the card from scratch, as if from a cold-boot. Implementation
  5911. * resembles the first-half of the igb_resume routine.
  5912. */
  5913. static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
  5914. {
  5915. struct net_device *netdev = pci_get_drvdata(pdev);
  5916. struct igb_adapter *adapter = netdev_priv(netdev);
  5917. struct e1000_hw *hw = &adapter->hw;
  5918. pci_ers_result_t result;
  5919. int err;
  5920. if (pci_enable_device_mem(pdev)) {
  5921. dev_err(&pdev->dev,
  5922. "Cannot re-enable PCI device after reset.\n");
  5923. result = PCI_ERS_RESULT_DISCONNECT;
  5924. } else {
  5925. pci_set_master(pdev);
  5926. pci_restore_state(pdev);
  5927. pci_save_state(pdev);
  5928. pci_enable_wake(pdev, PCI_D3hot, 0);
  5929. pci_enable_wake(pdev, PCI_D3cold, 0);
  5930. igb_reset(adapter);
  5931. wr32(E1000_WUS, ~0);
  5932. result = PCI_ERS_RESULT_RECOVERED;
  5933. }
  5934. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  5935. if (err) {
  5936. dev_err(&pdev->dev, "pci_cleanup_aer_uncorrect_error_status "
  5937. "failed 0x%0x\n", err);
  5938. /* non-fatal, continue */
  5939. }
  5940. return result;
  5941. }
  5942. /**
  5943. * igb_io_resume - called when traffic can start flowing again.
  5944. * @pdev: Pointer to PCI device
  5945. *
  5946. * This callback is called when the error recovery driver tells us that
  5947. * its OK to resume normal operation. Implementation resembles the
  5948. * second-half of the igb_resume routine.
  5949. */
  5950. static void igb_io_resume(struct pci_dev *pdev)
  5951. {
  5952. struct net_device *netdev = pci_get_drvdata(pdev);
  5953. struct igb_adapter *adapter = netdev_priv(netdev);
  5954. if (netif_running(netdev)) {
  5955. if (igb_up(adapter)) {
  5956. dev_err(&pdev->dev, "igb_up failed after reset\n");
  5957. return;
  5958. }
  5959. }
  5960. netif_device_attach(netdev);
  5961. /* let the f/w know that the h/w is now under the control of the
  5962. * driver. */
  5963. igb_get_hw_control(adapter);
  5964. }
  5965. static void igb_rar_set_qsel(struct igb_adapter *adapter, u8 *addr, u32 index,
  5966. u8 qsel)
  5967. {
  5968. u32 rar_low, rar_high;
  5969. struct e1000_hw *hw = &adapter->hw;
  5970. /* HW expects these in little endian so we reverse the byte order
  5971. * from network order (big endian) to little endian
  5972. */
  5973. rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
  5974. ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
  5975. rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
  5976. /* Indicate to hardware the Address is Valid. */
  5977. rar_high |= E1000_RAH_AV;
  5978. if (hw->mac.type == e1000_82575)
  5979. rar_high |= E1000_RAH_POOL_1 * qsel;
  5980. else
  5981. rar_high |= E1000_RAH_POOL_1 << qsel;
  5982. wr32(E1000_RAL(index), rar_low);
  5983. wrfl();
  5984. wr32(E1000_RAH(index), rar_high);
  5985. wrfl();
  5986. }
  5987. static int igb_set_vf_mac(struct igb_adapter *adapter,
  5988. int vf, unsigned char *mac_addr)
  5989. {
  5990. struct e1000_hw *hw = &adapter->hw;
  5991. /* VF MAC addresses start at end of receive addresses and moves
  5992. * torwards the first, as a result a collision should not be possible */
  5993. int rar_entry = hw->mac.rar_entry_count - (vf + 1);
  5994. memcpy(adapter->vf_data[vf].vf_mac_addresses, mac_addr, ETH_ALEN);
  5995. igb_rar_set_qsel(adapter, mac_addr, rar_entry, vf);
  5996. return 0;
  5997. }
  5998. static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
  5999. {
  6000. struct igb_adapter *adapter = netdev_priv(netdev);
  6001. if (!is_valid_ether_addr(mac) || (vf >= adapter->vfs_allocated_count))
  6002. return -EINVAL;
  6003. adapter->vf_data[vf].flags |= IGB_VF_FLAG_PF_SET_MAC;
  6004. dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf);
  6005. dev_info(&adapter->pdev->dev, "Reload the VF driver to make this"
  6006. " change effective.");
  6007. if (test_bit(__IGB_DOWN, &adapter->state)) {
  6008. dev_warn(&adapter->pdev->dev, "The VF MAC address has been set,"
  6009. " but the PF device is not up.\n");
  6010. dev_warn(&adapter->pdev->dev, "Bring the PF device up before"
  6011. " attempting to use the VF device.\n");
  6012. }
  6013. return igb_set_vf_mac(adapter, vf, mac);
  6014. }
  6015. static int igb_link_mbps(int internal_link_speed)
  6016. {
  6017. switch (internal_link_speed) {
  6018. case SPEED_100:
  6019. return 100;
  6020. case SPEED_1000:
  6021. return 1000;
  6022. default:
  6023. return 0;
  6024. }
  6025. }
  6026. static void igb_set_vf_rate_limit(struct e1000_hw *hw, int vf, int tx_rate,
  6027. int link_speed)
  6028. {
  6029. int rf_dec, rf_int;
  6030. u32 bcnrc_val;
  6031. if (tx_rate != 0) {
  6032. /* Calculate the rate factor values to set */
  6033. rf_int = link_speed / tx_rate;
  6034. rf_dec = (link_speed - (rf_int * tx_rate));
  6035. rf_dec = (rf_dec * (1<<E1000_RTTBCNRC_RF_INT_SHIFT)) / tx_rate;
  6036. bcnrc_val = E1000_RTTBCNRC_RS_ENA;
  6037. bcnrc_val |= ((rf_int<<E1000_RTTBCNRC_RF_INT_SHIFT) &
  6038. E1000_RTTBCNRC_RF_INT_MASK);
  6039. bcnrc_val |= (rf_dec & E1000_RTTBCNRC_RF_DEC_MASK);
  6040. } else {
  6041. bcnrc_val = 0;
  6042. }
  6043. wr32(E1000_RTTDQSEL, vf); /* vf X uses queue X */
  6044. wr32(E1000_RTTBCNRC, bcnrc_val);
  6045. }
  6046. static void igb_check_vf_rate_limit(struct igb_adapter *adapter)
  6047. {
  6048. int actual_link_speed, i;
  6049. bool reset_rate = false;
  6050. /* VF TX rate limit was not set or not supported */
  6051. if ((adapter->vf_rate_link_speed == 0) ||
  6052. (adapter->hw.mac.type != e1000_82576))
  6053. return;
  6054. actual_link_speed = igb_link_mbps(adapter->link_speed);
  6055. if (actual_link_speed != adapter->vf_rate_link_speed) {
  6056. reset_rate = true;
  6057. adapter->vf_rate_link_speed = 0;
  6058. dev_info(&adapter->pdev->dev,
  6059. "Link speed has been changed. VF Transmit "
  6060. "rate is disabled\n");
  6061. }
  6062. for (i = 0; i < adapter->vfs_allocated_count; i++) {
  6063. if (reset_rate)
  6064. adapter->vf_data[i].tx_rate = 0;
  6065. igb_set_vf_rate_limit(&adapter->hw, i,
  6066. adapter->vf_data[i].tx_rate,
  6067. actual_link_speed);
  6068. }
  6069. }
  6070. static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate)
  6071. {
  6072. struct igb_adapter *adapter = netdev_priv(netdev);
  6073. struct e1000_hw *hw = &adapter->hw;
  6074. int actual_link_speed;
  6075. if (hw->mac.type != e1000_82576)
  6076. return -EOPNOTSUPP;
  6077. actual_link_speed = igb_link_mbps(adapter->link_speed);
  6078. if ((vf >= adapter->vfs_allocated_count) ||
  6079. (!(rd32(E1000_STATUS) & E1000_STATUS_LU)) ||
  6080. (tx_rate < 0) || (tx_rate > actual_link_speed))
  6081. return -EINVAL;
  6082. adapter->vf_rate_link_speed = actual_link_speed;
  6083. adapter->vf_data[vf].tx_rate = (u16)tx_rate;
  6084. igb_set_vf_rate_limit(hw, vf, tx_rate, actual_link_speed);
  6085. return 0;
  6086. }
  6087. static int igb_ndo_get_vf_config(struct net_device *netdev,
  6088. int vf, struct ifla_vf_info *ivi)
  6089. {
  6090. struct igb_adapter *adapter = netdev_priv(netdev);
  6091. if (vf >= adapter->vfs_allocated_count)
  6092. return -EINVAL;
  6093. ivi->vf = vf;
  6094. memcpy(&ivi->mac, adapter->vf_data[vf].vf_mac_addresses, ETH_ALEN);
  6095. ivi->tx_rate = adapter->vf_data[vf].tx_rate;
  6096. ivi->vlan = adapter->vf_data[vf].pf_vlan;
  6097. ivi->qos = adapter->vf_data[vf].pf_qos;
  6098. return 0;
  6099. }
  6100. static void igb_vmm_control(struct igb_adapter *adapter)
  6101. {
  6102. struct e1000_hw *hw = &adapter->hw;
  6103. u32 reg;
  6104. switch (hw->mac.type) {
  6105. case e1000_82575:
  6106. default:
  6107. /* replication is not supported for 82575 */
  6108. return;
  6109. case e1000_82576:
  6110. /* notify HW that the MAC is adding vlan tags */
  6111. reg = rd32(E1000_DTXCTL);
  6112. reg |= E1000_DTXCTL_VLAN_ADDED;
  6113. wr32(E1000_DTXCTL, reg);
  6114. case e1000_82580:
  6115. /* enable replication vlan tag stripping */
  6116. reg = rd32(E1000_RPLOLR);
  6117. reg |= E1000_RPLOLR_STRVLAN;
  6118. wr32(E1000_RPLOLR, reg);
  6119. case e1000_i350:
  6120. /* none of the above registers are supported by i350 */
  6121. break;
  6122. }
  6123. if (adapter->vfs_allocated_count) {
  6124. igb_vmdq_set_loopback_pf(hw, true);
  6125. igb_vmdq_set_replication_pf(hw, true);
  6126. igb_vmdq_set_anti_spoofing_pf(hw, true,
  6127. adapter->vfs_allocated_count);
  6128. } else {
  6129. igb_vmdq_set_loopback_pf(hw, false);
  6130. igb_vmdq_set_replication_pf(hw, false);
  6131. }
  6132. }
  6133. static void igb_init_dmac(struct igb_adapter *adapter, u32 pba)
  6134. {
  6135. struct e1000_hw *hw = &adapter->hw;
  6136. u32 dmac_thr;
  6137. u16 hwm;
  6138. if (hw->mac.type > e1000_82580) {
  6139. if (adapter->flags & IGB_FLAG_DMAC) {
  6140. u32 reg;
  6141. /* force threshold to 0. */
  6142. wr32(E1000_DMCTXTH, 0);
  6143. /*
  6144. * DMA Coalescing high water mark needs to be greater
  6145. * than the Rx threshold. Set hwm to PBA - max frame
  6146. * size in 16B units, capping it at PBA - 6KB.
  6147. */
  6148. hwm = 64 * pba - adapter->max_frame_size / 16;
  6149. if (hwm < 64 * (pba - 6))
  6150. hwm = 64 * (pba - 6);
  6151. reg = rd32(E1000_FCRTC);
  6152. reg &= ~E1000_FCRTC_RTH_COAL_MASK;
  6153. reg |= ((hwm << E1000_FCRTC_RTH_COAL_SHIFT)
  6154. & E1000_FCRTC_RTH_COAL_MASK);
  6155. wr32(E1000_FCRTC, reg);
  6156. /*
  6157. * Set the DMA Coalescing Rx threshold to PBA - 2 * max
  6158. * frame size, capping it at PBA - 10KB.
  6159. */
  6160. dmac_thr = pba - adapter->max_frame_size / 512;
  6161. if (dmac_thr < pba - 10)
  6162. dmac_thr = pba - 10;
  6163. reg = rd32(E1000_DMACR);
  6164. reg &= ~E1000_DMACR_DMACTHR_MASK;
  6165. reg |= ((dmac_thr << E1000_DMACR_DMACTHR_SHIFT)
  6166. & E1000_DMACR_DMACTHR_MASK);
  6167. /* transition to L0x or L1 if available..*/
  6168. reg |= (E1000_DMACR_DMAC_EN | E1000_DMACR_DMAC_LX_MASK);
  6169. /* watchdog timer= +-1000 usec in 32usec intervals */
  6170. reg |= (1000 >> 5);
  6171. wr32(E1000_DMACR, reg);
  6172. /*
  6173. * no lower threshold to disable
  6174. * coalescing(smart fifb)-UTRESH=0
  6175. */
  6176. wr32(E1000_DMCRTRH, 0);
  6177. reg = (IGB_DMCTLX_DCFLUSH_DIS | 0x4);
  6178. wr32(E1000_DMCTLX, reg);
  6179. /*
  6180. * free space in tx packet buffer to wake from
  6181. * DMA coal
  6182. */
  6183. wr32(E1000_DMCTXTH, (IGB_MIN_TXPBSIZE -
  6184. (IGB_TX_BUF_4096 + adapter->max_frame_size)) >> 6);
  6185. /*
  6186. * make low power state decision controlled
  6187. * by DMA coal
  6188. */
  6189. reg = rd32(E1000_PCIEMISC);
  6190. reg &= ~E1000_PCIEMISC_LX_DECISION;
  6191. wr32(E1000_PCIEMISC, reg);
  6192. } /* endif adapter->dmac is not disabled */
  6193. } else if (hw->mac.type == e1000_82580) {
  6194. u32 reg = rd32(E1000_PCIEMISC);
  6195. wr32(E1000_PCIEMISC, reg & ~E1000_PCIEMISC_LX_DECISION);
  6196. wr32(E1000_DMACR, 0);
  6197. }
  6198. }
  6199. /* igb_main.c */