netdev.c 213 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 1999 - 2018 Intel Corporation. */
  3. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  4. #include <linux/module.h>
  5. #include <linux/types.h>
  6. #include <linux/init.h>
  7. #include <linux/pci.h>
  8. #include <linux/vmalloc.h>
  9. #include <linux/pagemap.h>
  10. #include <linux/delay.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/tcp.h>
  14. #include <linux/ipv6.h>
  15. #include <linux/slab.h>
  16. #include <net/checksum.h>
  17. #include <net/ip6_checksum.h>
  18. #include <linux/ethtool.h>
  19. #include <linux/if_vlan.h>
  20. #include <linux/cpu.h>
  21. #include <linux/smp.h>
  22. #include <linux/pm_qos.h>
  23. #include <linux/pm_runtime.h>
  24. #include <linux/aer.h>
  25. #include <linux/prefetch.h>
  26. #include "e1000.h"
  27. #define DRV_EXTRAVERSION "-k"
  28. #define DRV_VERSION "3.2.6" DRV_EXTRAVERSION
  29. char e1000e_driver_name[] = "e1000e";
  30. const char e1000e_driver_version[] = DRV_VERSION;
  31. #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
  32. static int debug = -1;
  33. module_param(debug, int, 0);
  34. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  35. static const struct e1000_info *e1000_info_tbl[] = {
  36. [board_82571] = &e1000_82571_info,
  37. [board_82572] = &e1000_82572_info,
  38. [board_82573] = &e1000_82573_info,
  39. [board_82574] = &e1000_82574_info,
  40. [board_82583] = &e1000_82583_info,
  41. [board_80003es2lan] = &e1000_es2_info,
  42. [board_ich8lan] = &e1000_ich8_info,
  43. [board_ich9lan] = &e1000_ich9_info,
  44. [board_ich10lan] = &e1000_ich10_info,
  45. [board_pchlan] = &e1000_pch_info,
  46. [board_pch2lan] = &e1000_pch2_info,
  47. [board_pch_lpt] = &e1000_pch_lpt_info,
  48. [board_pch_spt] = &e1000_pch_spt_info,
  49. [board_pch_cnp] = &e1000_pch_cnp_info,
  50. };
  51. struct e1000_reg_info {
  52. u32 ofs;
  53. char *name;
  54. };
  55. static const struct e1000_reg_info e1000_reg_info_tbl[] = {
  56. /* General Registers */
  57. {E1000_CTRL, "CTRL"},
  58. {E1000_STATUS, "STATUS"},
  59. {E1000_CTRL_EXT, "CTRL_EXT"},
  60. /* Interrupt Registers */
  61. {E1000_ICR, "ICR"},
  62. /* Rx Registers */
  63. {E1000_RCTL, "RCTL"},
  64. {E1000_RDLEN(0), "RDLEN"},
  65. {E1000_RDH(0), "RDH"},
  66. {E1000_RDT(0), "RDT"},
  67. {E1000_RDTR, "RDTR"},
  68. {E1000_RXDCTL(0), "RXDCTL"},
  69. {E1000_ERT, "ERT"},
  70. {E1000_RDBAL(0), "RDBAL"},
  71. {E1000_RDBAH(0), "RDBAH"},
  72. {E1000_RDFH, "RDFH"},
  73. {E1000_RDFT, "RDFT"},
  74. {E1000_RDFHS, "RDFHS"},
  75. {E1000_RDFTS, "RDFTS"},
  76. {E1000_RDFPC, "RDFPC"},
  77. /* Tx Registers */
  78. {E1000_TCTL, "TCTL"},
  79. {E1000_TDBAL(0), "TDBAL"},
  80. {E1000_TDBAH(0), "TDBAH"},
  81. {E1000_TDLEN(0), "TDLEN"},
  82. {E1000_TDH(0), "TDH"},
  83. {E1000_TDT(0), "TDT"},
  84. {E1000_TIDV, "TIDV"},
  85. {E1000_TXDCTL(0), "TXDCTL"},
  86. {E1000_TADV, "TADV"},
  87. {E1000_TARC(0), "TARC"},
  88. {E1000_TDFH, "TDFH"},
  89. {E1000_TDFT, "TDFT"},
  90. {E1000_TDFHS, "TDFHS"},
  91. {E1000_TDFTS, "TDFTS"},
  92. {E1000_TDFPC, "TDFPC"},
  93. /* List Terminator */
  94. {0, NULL}
  95. };
  96. /**
  97. * __ew32_prepare - prepare to write to MAC CSR register on certain parts
  98. * @hw: pointer to the HW structure
  99. *
  100. * When updating the MAC CSR registers, the Manageability Engine (ME) could
  101. * be accessing the registers at the same time. Normally, this is handled in
  102. * h/w by an arbiter but on some parts there is a bug that acknowledges Host
  103. * accesses later than it should which could result in the register to have
  104. * an incorrect value. Workaround this by checking the FWSM register which
  105. * has bit 24 set while ME is accessing MAC CSR registers, wait if it is set
  106. * and try again a number of times.
  107. **/
  108. static void __ew32_prepare(struct e1000_hw *hw)
  109. {
  110. s32 i = E1000_ICH_FWSM_PCIM2PCI_COUNT;
  111. while ((er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI) && --i)
  112. udelay(50);
  113. }
  114. void __ew32(struct e1000_hw *hw, unsigned long reg, u32 val)
  115. {
  116. if (hw->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
  117. __ew32_prepare(hw);
  118. writel(val, hw->hw_addr + reg);
  119. }
  120. /**
  121. * e1000_regdump - register printout routine
  122. * @hw: pointer to the HW structure
  123. * @reginfo: pointer to the register info table
  124. **/
  125. static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
  126. {
  127. int n = 0;
  128. char rname[16];
  129. u32 regs[8];
  130. switch (reginfo->ofs) {
  131. case E1000_RXDCTL(0):
  132. for (n = 0; n < 2; n++)
  133. regs[n] = __er32(hw, E1000_RXDCTL(n));
  134. break;
  135. case E1000_TXDCTL(0):
  136. for (n = 0; n < 2; n++)
  137. regs[n] = __er32(hw, E1000_TXDCTL(n));
  138. break;
  139. case E1000_TARC(0):
  140. for (n = 0; n < 2; n++)
  141. regs[n] = __er32(hw, E1000_TARC(n));
  142. break;
  143. default:
  144. pr_info("%-15s %08x\n",
  145. reginfo->name, __er32(hw, reginfo->ofs));
  146. return;
  147. }
  148. snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
  149. pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
  150. }
  151. static void e1000e_dump_ps_pages(struct e1000_adapter *adapter,
  152. struct e1000_buffer *bi)
  153. {
  154. int i;
  155. struct e1000_ps_page *ps_page;
  156. for (i = 0; i < adapter->rx_ps_pages; i++) {
  157. ps_page = &bi->ps_pages[i];
  158. if (ps_page->page) {
  159. pr_info("packet dump for ps_page %d:\n", i);
  160. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
  161. 16, 1, page_address(ps_page->page),
  162. PAGE_SIZE, true);
  163. }
  164. }
  165. }
  166. /**
  167. * e1000e_dump - Print registers, Tx-ring and Rx-ring
  168. * @adapter: board private structure
  169. **/
  170. static void e1000e_dump(struct e1000_adapter *adapter)
  171. {
  172. struct net_device *netdev = adapter->netdev;
  173. struct e1000_hw *hw = &adapter->hw;
  174. struct e1000_reg_info *reginfo;
  175. struct e1000_ring *tx_ring = adapter->tx_ring;
  176. struct e1000_tx_desc *tx_desc;
  177. struct my_u0 {
  178. __le64 a;
  179. __le64 b;
  180. } *u0;
  181. struct e1000_buffer *buffer_info;
  182. struct e1000_ring *rx_ring = adapter->rx_ring;
  183. union e1000_rx_desc_packet_split *rx_desc_ps;
  184. union e1000_rx_desc_extended *rx_desc;
  185. struct my_u1 {
  186. __le64 a;
  187. __le64 b;
  188. __le64 c;
  189. __le64 d;
  190. } *u1;
  191. u32 staterr;
  192. int i = 0;
  193. if (!netif_msg_hw(adapter))
  194. return;
  195. /* Print netdevice Info */
  196. if (netdev) {
  197. dev_info(&adapter->pdev->dev, "Net device Info\n");
  198. pr_info("Device Name state trans_start\n");
  199. pr_info("%-15s %016lX %016lX\n", netdev->name,
  200. netdev->state, dev_trans_start(netdev));
  201. }
  202. /* Print Registers */
  203. dev_info(&adapter->pdev->dev, "Register Dump\n");
  204. pr_info(" Register Name Value\n");
  205. for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
  206. reginfo->name; reginfo++) {
  207. e1000_regdump(hw, reginfo);
  208. }
  209. /* Print Tx Ring Summary */
  210. if (!netdev || !netif_running(netdev))
  211. return;
  212. dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
  213. pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
  214. buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
  215. pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
  216. 0, tx_ring->next_to_use, tx_ring->next_to_clean,
  217. (unsigned long long)buffer_info->dma,
  218. buffer_info->length,
  219. buffer_info->next_to_watch,
  220. (unsigned long long)buffer_info->time_stamp);
  221. /* Print Tx Ring */
  222. if (!netif_msg_tx_done(adapter))
  223. goto rx_ring_summary;
  224. dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
  225. /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
  226. *
  227. * Legacy Transmit Descriptor
  228. * +--------------------------------------------------------------+
  229. * 0 | Buffer Address [63:0] (Reserved on Write Back) |
  230. * +--------------------------------------------------------------+
  231. * 8 | Special | CSS | Status | CMD | CSO | Length |
  232. * +--------------------------------------------------------------+
  233. * 63 48 47 36 35 32 31 24 23 16 15 0
  234. *
  235. * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
  236. * 63 48 47 40 39 32 31 16 15 8 7 0
  237. * +----------------------------------------------------------------+
  238. * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
  239. * +----------------------------------------------------------------+
  240. * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
  241. * +----------------------------------------------------------------+
  242. * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
  243. *
  244. * Extended Data Descriptor (DTYP=0x1)
  245. * +----------------------------------------------------------------+
  246. * 0 | Buffer Address [63:0] |
  247. * +----------------------------------------------------------------+
  248. * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
  249. * +----------------------------------------------------------------+
  250. * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
  251. */
  252. pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
  253. pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
  254. pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Data format\n");
  255. for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
  256. const char *next_desc;
  257. tx_desc = E1000_TX_DESC(*tx_ring, i);
  258. buffer_info = &tx_ring->buffer_info[i];
  259. u0 = (struct my_u0 *)tx_desc;
  260. if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
  261. next_desc = " NTC/U";
  262. else if (i == tx_ring->next_to_use)
  263. next_desc = " NTU";
  264. else if (i == tx_ring->next_to_clean)
  265. next_desc = " NTC";
  266. else
  267. next_desc = "";
  268. pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
  269. (!(le64_to_cpu(u0->b) & BIT(29)) ? 'l' :
  270. ((le64_to_cpu(u0->b) & BIT(20)) ? 'd' : 'c')),
  271. i,
  272. (unsigned long long)le64_to_cpu(u0->a),
  273. (unsigned long long)le64_to_cpu(u0->b),
  274. (unsigned long long)buffer_info->dma,
  275. buffer_info->length, buffer_info->next_to_watch,
  276. (unsigned long long)buffer_info->time_stamp,
  277. buffer_info->skb, next_desc);
  278. if (netif_msg_pktdata(adapter) && buffer_info->skb)
  279. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
  280. 16, 1, buffer_info->skb->data,
  281. buffer_info->skb->len, true);
  282. }
  283. /* Print Rx Ring Summary */
  284. rx_ring_summary:
  285. dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
  286. pr_info("Queue [NTU] [NTC]\n");
  287. pr_info(" %5d %5X %5X\n",
  288. 0, rx_ring->next_to_use, rx_ring->next_to_clean);
  289. /* Print Rx Ring */
  290. if (!netif_msg_rx_status(adapter))
  291. return;
  292. dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
  293. switch (adapter->rx_ps_pages) {
  294. case 1:
  295. case 2:
  296. case 3:
  297. /* [Extended] Packet Split Receive Descriptor Format
  298. *
  299. * +-----------------------------------------------------+
  300. * 0 | Buffer Address 0 [63:0] |
  301. * +-----------------------------------------------------+
  302. * 8 | Buffer Address 1 [63:0] |
  303. * +-----------------------------------------------------+
  304. * 16 | Buffer Address 2 [63:0] |
  305. * +-----------------------------------------------------+
  306. * 24 | Buffer Address 3 [63:0] |
  307. * +-----------------------------------------------------+
  308. */
  309. pr_info("R [desc] [buffer 0 63:0 ] [buffer 1 63:0 ] [buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] [bi->skb] <-- Ext Pkt Split format\n");
  310. /* [Extended] Receive Descriptor (Write-Back) Format
  311. *
  312. * 63 48 47 32 31 13 12 8 7 4 3 0
  313. * +------------------------------------------------------+
  314. * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
  315. * | Checksum | Ident | | Queue | | Type |
  316. * +------------------------------------------------------+
  317. * 8 | VLAN Tag | Length | Extended Error | Extended Status |
  318. * +------------------------------------------------------+
  319. * 63 48 47 32 31 20 19 0
  320. */
  321. pr_info("RWB[desc] [ck ipid mrqhsh] [vl l0 ee es] [ l3 l2 l1 hs] [reserved ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n");
  322. for (i = 0; i < rx_ring->count; i++) {
  323. const char *next_desc;
  324. buffer_info = &rx_ring->buffer_info[i];
  325. rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
  326. u1 = (struct my_u1 *)rx_desc_ps;
  327. staterr =
  328. le32_to_cpu(rx_desc_ps->wb.middle.status_error);
  329. if (i == rx_ring->next_to_use)
  330. next_desc = " NTU";
  331. else if (i == rx_ring->next_to_clean)
  332. next_desc = " NTC";
  333. else
  334. next_desc = "";
  335. if (staterr & E1000_RXD_STAT_DD) {
  336. /* Descriptor Done */
  337. pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
  338. "RWB", i,
  339. (unsigned long long)le64_to_cpu(u1->a),
  340. (unsigned long long)le64_to_cpu(u1->b),
  341. (unsigned long long)le64_to_cpu(u1->c),
  342. (unsigned long long)le64_to_cpu(u1->d),
  343. buffer_info->skb, next_desc);
  344. } else {
  345. pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
  346. "R ", i,
  347. (unsigned long long)le64_to_cpu(u1->a),
  348. (unsigned long long)le64_to_cpu(u1->b),
  349. (unsigned long long)le64_to_cpu(u1->c),
  350. (unsigned long long)le64_to_cpu(u1->d),
  351. (unsigned long long)buffer_info->dma,
  352. buffer_info->skb, next_desc);
  353. if (netif_msg_pktdata(adapter))
  354. e1000e_dump_ps_pages(adapter,
  355. buffer_info);
  356. }
  357. }
  358. break;
  359. default:
  360. case 0:
  361. /* Extended Receive Descriptor (Read) Format
  362. *
  363. * +-----------------------------------------------------+
  364. * 0 | Buffer Address [63:0] |
  365. * +-----------------------------------------------------+
  366. * 8 | Reserved |
  367. * +-----------------------------------------------------+
  368. */
  369. pr_info("R [desc] [buf addr 63:0 ] [reserved 63:0 ] [bi->dma ] [bi->skb] <-- Ext (Read) format\n");
  370. /* Extended Receive Descriptor (Write-Back) Format
  371. *
  372. * 63 48 47 32 31 24 23 4 3 0
  373. * +------------------------------------------------------+
  374. * | RSS Hash | | | |
  375. * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
  376. * | Packet | IP | | | Type |
  377. * | Checksum | Ident | | | |
  378. * +------------------------------------------------------+
  379. * 8 | VLAN Tag | Length | Extended Error | Extended Status |
  380. * +------------------------------------------------------+
  381. * 63 48 47 32 31 20 19 0
  382. */
  383. pr_info("RWB[desc] [cs ipid mrq] [vt ln xe xs] [bi->skb] <-- Ext (Write-Back) format\n");
  384. for (i = 0; i < rx_ring->count; i++) {
  385. const char *next_desc;
  386. buffer_info = &rx_ring->buffer_info[i];
  387. rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
  388. u1 = (struct my_u1 *)rx_desc;
  389. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  390. if (i == rx_ring->next_to_use)
  391. next_desc = " NTU";
  392. else if (i == rx_ring->next_to_clean)
  393. next_desc = " NTC";
  394. else
  395. next_desc = "";
  396. if (staterr & E1000_RXD_STAT_DD) {
  397. /* Descriptor Done */
  398. pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
  399. "RWB", i,
  400. (unsigned long long)le64_to_cpu(u1->a),
  401. (unsigned long long)le64_to_cpu(u1->b),
  402. buffer_info->skb, next_desc);
  403. } else {
  404. pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
  405. "R ", i,
  406. (unsigned long long)le64_to_cpu(u1->a),
  407. (unsigned long long)le64_to_cpu(u1->b),
  408. (unsigned long long)buffer_info->dma,
  409. buffer_info->skb, next_desc);
  410. if (netif_msg_pktdata(adapter) &&
  411. buffer_info->skb)
  412. print_hex_dump(KERN_INFO, "",
  413. DUMP_PREFIX_ADDRESS, 16,
  414. 1,
  415. buffer_info->skb->data,
  416. adapter->rx_buffer_len,
  417. true);
  418. }
  419. }
  420. }
  421. }
  422. /**
  423. * e1000_desc_unused - calculate if we have unused descriptors
  424. **/
  425. static int e1000_desc_unused(struct e1000_ring *ring)
  426. {
  427. if (ring->next_to_clean > ring->next_to_use)
  428. return ring->next_to_clean - ring->next_to_use - 1;
  429. return ring->count + ring->next_to_clean - ring->next_to_use - 1;
  430. }
  431. /**
  432. * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp
  433. * @adapter: board private structure
  434. * @hwtstamps: time stamp structure to update
  435. * @systim: unsigned 64bit system time value.
  436. *
  437. * Convert the system time value stored in the RX/TXSTMP registers into a
  438. * hwtstamp which can be used by the upper level time stamping functions.
  439. *
  440. * The 'systim_lock' spinlock is used to protect the consistency of the
  441. * system time value. This is needed because reading the 64 bit time
  442. * value involves reading two 32 bit registers. The first read latches the
  443. * value.
  444. **/
  445. static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter,
  446. struct skb_shared_hwtstamps *hwtstamps,
  447. u64 systim)
  448. {
  449. u64 ns;
  450. unsigned long flags;
  451. spin_lock_irqsave(&adapter->systim_lock, flags);
  452. ns = timecounter_cyc2time(&adapter->tc, systim);
  453. spin_unlock_irqrestore(&adapter->systim_lock, flags);
  454. memset(hwtstamps, 0, sizeof(*hwtstamps));
  455. hwtstamps->hwtstamp = ns_to_ktime(ns);
  456. }
  457. /**
  458. * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp
  459. * @adapter: board private structure
  460. * @status: descriptor extended error and status field
  461. * @skb: particular skb to include time stamp
  462. *
  463. * If the time stamp is valid, convert it into the timecounter ns value
  464. * and store that result into the shhwtstamps structure which is passed
  465. * up the network stack.
  466. **/
  467. static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status,
  468. struct sk_buff *skb)
  469. {
  470. struct e1000_hw *hw = &adapter->hw;
  471. u64 rxstmp;
  472. if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) ||
  473. !(status & E1000_RXDEXT_STATERR_TST) ||
  474. !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
  475. return;
  476. /* The Rx time stamp registers contain the time stamp. No other
  477. * received packet will be time stamped until the Rx time stamp
  478. * registers are read. Because only one packet can be time stamped
  479. * at a time, the register values must belong to this packet and
  480. * therefore none of the other additional attributes need to be
  481. * compared.
  482. */
  483. rxstmp = (u64)er32(RXSTMPL);
  484. rxstmp |= (u64)er32(RXSTMPH) << 32;
  485. e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp);
  486. adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP;
  487. }
  488. /**
  489. * e1000_receive_skb - helper function to handle Rx indications
  490. * @adapter: board private structure
  491. * @staterr: descriptor extended error and status field as written by hardware
  492. * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
  493. * @skb: pointer to sk_buff to be indicated to stack
  494. **/
  495. static void e1000_receive_skb(struct e1000_adapter *adapter,
  496. struct net_device *netdev, struct sk_buff *skb,
  497. u32 staterr, __le16 vlan)
  498. {
  499. u16 tag = le16_to_cpu(vlan);
  500. e1000e_rx_hwtstamp(adapter, staterr, skb);
  501. skb->protocol = eth_type_trans(skb, netdev);
  502. if (staterr & E1000_RXD_STAT_VP)
  503. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
  504. napi_gro_receive(&adapter->napi, skb);
  505. }
  506. /**
  507. * e1000_rx_checksum - Receive Checksum Offload
  508. * @adapter: board private structure
  509. * @status_err: receive descriptor status and error fields
  510. * @csum: receive descriptor csum field
  511. * @sk_buff: socket buffer with received data
  512. **/
  513. static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
  514. struct sk_buff *skb)
  515. {
  516. u16 status = (u16)status_err;
  517. u8 errors = (u8)(status_err >> 24);
  518. skb_checksum_none_assert(skb);
  519. /* Rx checksum disabled */
  520. if (!(adapter->netdev->features & NETIF_F_RXCSUM))
  521. return;
  522. /* Ignore Checksum bit is set */
  523. if (status & E1000_RXD_STAT_IXSM)
  524. return;
  525. /* TCP/UDP checksum error bit or IP checksum error bit is set */
  526. if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) {
  527. /* let the stack verify checksum errors */
  528. adapter->hw_csum_err++;
  529. return;
  530. }
  531. /* TCP/UDP Checksum has not been calculated */
  532. if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
  533. return;
  534. /* It must be a TCP or UDP packet with a valid checksum */
  535. skb->ip_summed = CHECKSUM_UNNECESSARY;
  536. adapter->hw_csum_good++;
  537. }
  538. static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
  539. {
  540. struct e1000_adapter *adapter = rx_ring->adapter;
  541. struct e1000_hw *hw = &adapter->hw;
  542. __ew32_prepare(hw);
  543. writel(i, rx_ring->tail);
  544. if (unlikely(i != readl(rx_ring->tail))) {
  545. u32 rctl = er32(RCTL);
  546. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  547. e_err("ME firmware caused invalid RDT - resetting\n");
  548. schedule_work(&adapter->reset_task);
  549. }
  550. }
  551. static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
  552. {
  553. struct e1000_adapter *adapter = tx_ring->adapter;
  554. struct e1000_hw *hw = &adapter->hw;
  555. __ew32_prepare(hw);
  556. writel(i, tx_ring->tail);
  557. if (unlikely(i != readl(tx_ring->tail))) {
  558. u32 tctl = er32(TCTL);
  559. ew32(TCTL, tctl & ~E1000_TCTL_EN);
  560. e_err("ME firmware caused invalid TDT - resetting\n");
  561. schedule_work(&adapter->reset_task);
  562. }
  563. }
  564. /**
  565. * e1000_alloc_rx_buffers - Replace used receive buffers
  566. * @rx_ring: Rx descriptor ring
  567. **/
  568. static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
  569. int cleaned_count, gfp_t gfp)
  570. {
  571. struct e1000_adapter *adapter = rx_ring->adapter;
  572. struct net_device *netdev = adapter->netdev;
  573. struct pci_dev *pdev = adapter->pdev;
  574. union e1000_rx_desc_extended *rx_desc;
  575. struct e1000_buffer *buffer_info;
  576. struct sk_buff *skb;
  577. unsigned int i;
  578. unsigned int bufsz = adapter->rx_buffer_len;
  579. i = rx_ring->next_to_use;
  580. buffer_info = &rx_ring->buffer_info[i];
  581. while (cleaned_count--) {
  582. skb = buffer_info->skb;
  583. if (skb) {
  584. skb_trim(skb, 0);
  585. goto map_skb;
  586. }
  587. skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
  588. if (!skb) {
  589. /* Better luck next round */
  590. adapter->alloc_rx_buff_failed++;
  591. break;
  592. }
  593. buffer_info->skb = skb;
  594. map_skb:
  595. buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
  596. adapter->rx_buffer_len,
  597. DMA_FROM_DEVICE);
  598. if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
  599. dev_err(&pdev->dev, "Rx DMA map failed\n");
  600. adapter->rx_dma_failed++;
  601. break;
  602. }
  603. rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
  604. rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
  605. if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
  606. /* Force memory writes to complete before letting h/w
  607. * know there are new descriptors to fetch. (Only
  608. * applicable for weak-ordered memory model archs,
  609. * such as IA-64).
  610. */
  611. wmb();
  612. if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
  613. e1000e_update_rdt_wa(rx_ring, i);
  614. else
  615. writel(i, rx_ring->tail);
  616. }
  617. i++;
  618. if (i == rx_ring->count)
  619. i = 0;
  620. buffer_info = &rx_ring->buffer_info[i];
  621. }
  622. rx_ring->next_to_use = i;
  623. }
  624. /**
  625. * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
  626. * @rx_ring: Rx descriptor ring
  627. **/
  628. static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
  629. int cleaned_count, gfp_t gfp)
  630. {
  631. struct e1000_adapter *adapter = rx_ring->adapter;
  632. struct net_device *netdev = adapter->netdev;
  633. struct pci_dev *pdev = adapter->pdev;
  634. union e1000_rx_desc_packet_split *rx_desc;
  635. struct e1000_buffer *buffer_info;
  636. struct e1000_ps_page *ps_page;
  637. struct sk_buff *skb;
  638. unsigned int i, j;
  639. i = rx_ring->next_to_use;
  640. buffer_info = &rx_ring->buffer_info[i];
  641. while (cleaned_count--) {
  642. rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
  643. for (j = 0; j < PS_PAGE_BUFFERS; j++) {
  644. ps_page = &buffer_info->ps_pages[j];
  645. if (j >= adapter->rx_ps_pages) {
  646. /* all unused desc entries get hw null ptr */
  647. rx_desc->read.buffer_addr[j + 1] =
  648. ~cpu_to_le64(0);
  649. continue;
  650. }
  651. if (!ps_page->page) {
  652. ps_page->page = alloc_page(gfp);
  653. if (!ps_page->page) {
  654. adapter->alloc_rx_buff_failed++;
  655. goto no_buffers;
  656. }
  657. ps_page->dma = dma_map_page(&pdev->dev,
  658. ps_page->page,
  659. 0, PAGE_SIZE,
  660. DMA_FROM_DEVICE);
  661. if (dma_mapping_error(&pdev->dev,
  662. ps_page->dma)) {
  663. dev_err(&adapter->pdev->dev,
  664. "Rx DMA page map failed\n");
  665. adapter->rx_dma_failed++;
  666. goto no_buffers;
  667. }
  668. }
  669. /* Refresh the desc even if buffer_addrs
  670. * didn't change because each write-back
  671. * erases this info.
  672. */
  673. rx_desc->read.buffer_addr[j + 1] =
  674. cpu_to_le64(ps_page->dma);
  675. }
  676. skb = __netdev_alloc_skb_ip_align(netdev, adapter->rx_ps_bsize0,
  677. gfp);
  678. if (!skb) {
  679. adapter->alloc_rx_buff_failed++;
  680. break;
  681. }
  682. buffer_info->skb = skb;
  683. buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
  684. adapter->rx_ps_bsize0,
  685. DMA_FROM_DEVICE);
  686. if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
  687. dev_err(&pdev->dev, "Rx DMA map failed\n");
  688. adapter->rx_dma_failed++;
  689. /* cleanup skb */
  690. dev_kfree_skb_any(skb);
  691. buffer_info->skb = NULL;
  692. break;
  693. }
  694. rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
  695. if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
  696. /* Force memory writes to complete before letting h/w
  697. * know there are new descriptors to fetch. (Only
  698. * applicable for weak-ordered memory model archs,
  699. * such as IA-64).
  700. */
  701. wmb();
  702. if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
  703. e1000e_update_rdt_wa(rx_ring, i << 1);
  704. else
  705. writel(i << 1, rx_ring->tail);
  706. }
  707. i++;
  708. if (i == rx_ring->count)
  709. i = 0;
  710. buffer_info = &rx_ring->buffer_info[i];
  711. }
  712. no_buffers:
  713. rx_ring->next_to_use = i;
  714. }
  715. /**
  716. * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
  717. * @rx_ring: Rx descriptor ring
  718. * @cleaned_count: number of buffers to allocate this pass
  719. **/
  720. static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
  721. int cleaned_count, gfp_t gfp)
  722. {
  723. struct e1000_adapter *adapter = rx_ring->adapter;
  724. struct net_device *netdev = adapter->netdev;
  725. struct pci_dev *pdev = adapter->pdev;
  726. union e1000_rx_desc_extended *rx_desc;
  727. struct e1000_buffer *buffer_info;
  728. struct sk_buff *skb;
  729. unsigned int i;
  730. unsigned int bufsz = 256 - 16; /* for skb_reserve */
  731. i = rx_ring->next_to_use;
  732. buffer_info = &rx_ring->buffer_info[i];
  733. while (cleaned_count--) {
  734. skb = buffer_info->skb;
  735. if (skb) {
  736. skb_trim(skb, 0);
  737. goto check_page;
  738. }
  739. skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
  740. if (unlikely(!skb)) {
  741. /* Better luck next round */
  742. adapter->alloc_rx_buff_failed++;
  743. break;
  744. }
  745. buffer_info->skb = skb;
  746. check_page:
  747. /* allocate a new page if necessary */
  748. if (!buffer_info->page) {
  749. buffer_info->page = alloc_page(gfp);
  750. if (unlikely(!buffer_info->page)) {
  751. adapter->alloc_rx_buff_failed++;
  752. break;
  753. }
  754. }
  755. if (!buffer_info->dma) {
  756. buffer_info->dma = dma_map_page(&pdev->dev,
  757. buffer_info->page, 0,
  758. PAGE_SIZE,
  759. DMA_FROM_DEVICE);
  760. if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
  761. adapter->alloc_rx_buff_failed++;
  762. break;
  763. }
  764. }
  765. rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
  766. rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
  767. if (unlikely(++i == rx_ring->count))
  768. i = 0;
  769. buffer_info = &rx_ring->buffer_info[i];
  770. }
  771. if (likely(rx_ring->next_to_use != i)) {
  772. rx_ring->next_to_use = i;
  773. if (unlikely(i-- == 0))
  774. i = (rx_ring->count - 1);
  775. /* Force memory writes to complete before letting h/w
  776. * know there are new descriptors to fetch. (Only
  777. * applicable for weak-ordered memory model archs,
  778. * such as IA-64).
  779. */
  780. wmb();
  781. if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
  782. e1000e_update_rdt_wa(rx_ring, i);
  783. else
  784. writel(i, rx_ring->tail);
  785. }
  786. }
  787. static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
  788. struct sk_buff *skb)
  789. {
  790. if (netdev->features & NETIF_F_RXHASH)
  791. skb_set_hash(skb, le32_to_cpu(rss), PKT_HASH_TYPE_L3);
  792. }
  793. /**
  794. * e1000_clean_rx_irq - Send received data up the network stack
  795. * @rx_ring: Rx descriptor ring
  796. *
  797. * the return value indicates whether actual cleaning was done, there
  798. * is no guarantee that everything was cleaned
  799. **/
  800. static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
  801. int work_to_do)
  802. {
  803. struct e1000_adapter *adapter = rx_ring->adapter;
  804. struct net_device *netdev = adapter->netdev;
  805. struct pci_dev *pdev = adapter->pdev;
  806. struct e1000_hw *hw = &adapter->hw;
  807. union e1000_rx_desc_extended *rx_desc, *next_rxd;
  808. struct e1000_buffer *buffer_info, *next_buffer;
  809. u32 length, staterr;
  810. unsigned int i;
  811. int cleaned_count = 0;
  812. bool cleaned = false;
  813. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  814. i = rx_ring->next_to_clean;
  815. rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
  816. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  817. buffer_info = &rx_ring->buffer_info[i];
  818. while (staterr & E1000_RXD_STAT_DD) {
  819. struct sk_buff *skb;
  820. if (*work_done >= work_to_do)
  821. break;
  822. (*work_done)++;
  823. dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
  824. skb = buffer_info->skb;
  825. buffer_info->skb = NULL;
  826. prefetch(skb->data - NET_IP_ALIGN);
  827. i++;
  828. if (i == rx_ring->count)
  829. i = 0;
  830. next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
  831. prefetch(next_rxd);
  832. next_buffer = &rx_ring->buffer_info[i];
  833. cleaned = true;
  834. cleaned_count++;
  835. dma_unmap_single(&pdev->dev, buffer_info->dma,
  836. adapter->rx_buffer_len, DMA_FROM_DEVICE);
  837. buffer_info->dma = 0;
  838. length = le16_to_cpu(rx_desc->wb.upper.length);
  839. /* !EOP means multiple descriptors were used to store a single
  840. * packet, if that's the case we need to toss it. In fact, we
  841. * need to toss every packet with the EOP bit clear and the
  842. * next frame that _does_ have the EOP bit set, as it is by
  843. * definition only a frame fragment
  844. */
  845. if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
  846. adapter->flags2 |= FLAG2_IS_DISCARDING;
  847. if (adapter->flags2 & FLAG2_IS_DISCARDING) {
  848. /* All receives must fit into a single buffer */
  849. e_dbg("Receive packet consumed multiple buffers\n");
  850. /* recycle */
  851. buffer_info->skb = skb;
  852. if (staterr & E1000_RXD_STAT_EOP)
  853. adapter->flags2 &= ~FLAG2_IS_DISCARDING;
  854. goto next_desc;
  855. }
  856. if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
  857. !(netdev->features & NETIF_F_RXALL))) {
  858. /* recycle */
  859. buffer_info->skb = skb;
  860. goto next_desc;
  861. }
  862. /* adjust length to remove Ethernet CRC */
  863. if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
  864. /* If configured to store CRC, don't subtract FCS,
  865. * but keep the FCS bytes out of the total_rx_bytes
  866. * counter
  867. */
  868. if (netdev->features & NETIF_F_RXFCS)
  869. total_rx_bytes -= 4;
  870. else
  871. length -= 4;
  872. }
  873. total_rx_bytes += length;
  874. total_rx_packets++;
  875. /* code added for copybreak, this should improve
  876. * performance for small packets with large amounts
  877. * of reassembly being done in the stack
  878. */
  879. if (length < copybreak) {
  880. struct sk_buff *new_skb =
  881. napi_alloc_skb(&adapter->napi, length);
  882. if (new_skb) {
  883. skb_copy_to_linear_data_offset(new_skb,
  884. -NET_IP_ALIGN,
  885. (skb->data -
  886. NET_IP_ALIGN),
  887. (length +
  888. NET_IP_ALIGN));
  889. /* save the skb in buffer_info as good */
  890. buffer_info->skb = skb;
  891. skb = new_skb;
  892. }
  893. /* else just continue with the old one */
  894. }
  895. /* end copybreak code */
  896. skb_put(skb, length);
  897. /* Receive Checksum Offload */
  898. e1000_rx_checksum(adapter, staterr, skb);
  899. e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
  900. e1000_receive_skb(adapter, netdev, skb, staterr,
  901. rx_desc->wb.upper.vlan);
  902. next_desc:
  903. rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
  904. /* return some buffers to hardware, one at a time is too slow */
  905. if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
  906. adapter->alloc_rx_buf(rx_ring, cleaned_count,
  907. GFP_ATOMIC);
  908. cleaned_count = 0;
  909. }
  910. /* use prefetched values */
  911. rx_desc = next_rxd;
  912. buffer_info = next_buffer;
  913. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  914. }
  915. rx_ring->next_to_clean = i;
  916. cleaned_count = e1000_desc_unused(rx_ring);
  917. if (cleaned_count)
  918. adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
  919. adapter->total_rx_bytes += total_rx_bytes;
  920. adapter->total_rx_packets += total_rx_packets;
  921. return cleaned;
  922. }
  923. static void e1000_put_txbuf(struct e1000_ring *tx_ring,
  924. struct e1000_buffer *buffer_info,
  925. bool drop)
  926. {
  927. struct e1000_adapter *adapter = tx_ring->adapter;
  928. if (buffer_info->dma) {
  929. if (buffer_info->mapped_as_page)
  930. dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
  931. buffer_info->length, DMA_TO_DEVICE);
  932. else
  933. dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
  934. buffer_info->length, DMA_TO_DEVICE);
  935. buffer_info->dma = 0;
  936. }
  937. if (buffer_info->skb) {
  938. if (drop)
  939. dev_kfree_skb_any(buffer_info->skb);
  940. else
  941. dev_consume_skb_any(buffer_info->skb);
  942. buffer_info->skb = NULL;
  943. }
  944. buffer_info->time_stamp = 0;
  945. }
  946. static void e1000_print_hw_hang(struct work_struct *work)
  947. {
  948. struct e1000_adapter *adapter = container_of(work,
  949. struct e1000_adapter,
  950. print_hang_task);
  951. struct net_device *netdev = adapter->netdev;
  952. struct e1000_ring *tx_ring = adapter->tx_ring;
  953. unsigned int i = tx_ring->next_to_clean;
  954. unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
  955. struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
  956. struct e1000_hw *hw = &adapter->hw;
  957. u16 phy_status, phy_1000t_status, phy_ext_status;
  958. u16 pci_status;
  959. if (test_bit(__E1000_DOWN, &adapter->state))
  960. return;
  961. if (!adapter->tx_hang_recheck && (adapter->flags2 & FLAG2_DMA_BURST)) {
  962. /* May be block on write-back, flush and detect again
  963. * flush pending descriptor writebacks to memory
  964. */
  965. ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
  966. /* execute the writes immediately */
  967. e1e_flush();
  968. /* Due to rare timing issues, write to TIDV again to ensure
  969. * the write is successful
  970. */
  971. ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
  972. /* execute the writes immediately */
  973. e1e_flush();
  974. adapter->tx_hang_recheck = true;
  975. return;
  976. }
  977. adapter->tx_hang_recheck = false;
  978. if (er32(TDH(0)) == er32(TDT(0))) {
  979. e_dbg("false hang detected, ignoring\n");
  980. return;
  981. }
  982. /* Real hang detected */
  983. netif_stop_queue(netdev);
  984. e1e_rphy(hw, MII_BMSR, &phy_status);
  985. e1e_rphy(hw, MII_STAT1000, &phy_1000t_status);
  986. e1e_rphy(hw, MII_ESTATUS, &phy_ext_status);
  987. pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
  988. /* detected Hardware unit hang */
  989. e_err("Detected Hardware Unit Hang:\n"
  990. " TDH <%x>\n"
  991. " TDT <%x>\n"
  992. " next_to_use <%x>\n"
  993. " next_to_clean <%x>\n"
  994. "buffer_info[next_to_clean]:\n"
  995. " time_stamp <%lx>\n"
  996. " next_to_watch <%x>\n"
  997. " jiffies <%lx>\n"
  998. " next_to_watch.status <%x>\n"
  999. "MAC Status <%x>\n"
  1000. "PHY Status <%x>\n"
  1001. "PHY 1000BASE-T Status <%x>\n"
  1002. "PHY Extended Status <%x>\n"
  1003. "PCI Status <%x>\n",
  1004. readl(tx_ring->head), readl(tx_ring->tail), tx_ring->next_to_use,
  1005. tx_ring->next_to_clean, tx_ring->buffer_info[eop].time_stamp,
  1006. eop, jiffies, eop_desc->upper.fields.status, er32(STATUS),
  1007. phy_status, phy_1000t_status, phy_ext_status, pci_status);
  1008. e1000e_dump(adapter);
  1009. /* Suggest workaround for known h/w issue */
  1010. if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE))
  1011. e_err("Try turning off Tx pause (flow control) via ethtool\n");
  1012. }
  1013. /**
  1014. * e1000e_tx_hwtstamp_work - check for Tx time stamp
  1015. * @work: pointer to work struct
  1016. *
  1017. * This work function polls the TSYNCTXCTL valid bit to determine when a
  1018. * timestamp has been taken for the current stored skb. The timestamp must
  1019. * be for this skb because only one such packet is allowed in the queue.
  1020. */
  1021. static void e1000e_tx_hwtstamp_work(struct work_struct *work)
  1022. {
  1023. struct e1000_adapter *adapter = container_of(work, struct e1000_adapter,
  1024. tx_hwtstamp_work);
  1025. struct e1000_hw *hw = &adapter->hw;
  1026. if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) {
  1027. struct sk_buff *skb = adapter->tx_hwtstamp_skb;
  1028. struct skb_shared_hwtstamps shhwtstamps;
  1029. u64 txstmp;
  1030. txstmp = er32(TXSTMPL);
  1031. txstmp |= (u64)er32(TXSTMPH) << 32;
  1032. e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp);
  1033. /* Clear the global tx_hwtstamp_skb pointer and force writes
  1034. * prior to notifying the stack of a Tx timestamp.
  1035. */
  1036. adapter->tx_hwtstamp_skb = NULL;
  1037. wmb(); /* force write prior to skb_tstamp_tx */
  1038. skb_tstamp_tx(skb, &shhwtstamps);
  1039. dev_consume_skb_any(skb);
  1040. } else if (time_after(jiffies, adapter->tx_hwtstamp_start
  1041. + adapter->tx_timeout_factor * HZ)) {
  1042. dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
  1043. adapter->tx_hwtstamp_skb = NULL;
  1044. adapter->tx_hwtstamp_timeouts++;
  1045. e_warn("clearing Tx timestamp hang\n");
  1046. } else {
  1047. /* reschedule to check later */
  1048. schedule_work(&adapter->tx_hwtstamp_work);
  1049. }
  1050. }
  1051. /**
  1052. * e1000_clean_tx_irq - Reclaim resources after transmit completes
  1053. * @tx_ring: Tx descriptor ring
  1054. *
  1055. * the return value indicates whether actual cleaning was done, there
  1056. * is no guarantee that everything was cleaned
  1057. **/
  1058. static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
  1059. {
  1060. struct e1000_adapter *adapter = tx_ring->adapter;
  1061. struct net_device *netdev = adapter->netdev;
  1062. struct e1000_hw *hw = &adapter->hw;
  1063. struct e1000_tx_desc *tx_desc, *eop_desc;
  1064. struct e1000_buffer *buffer_info;
  1065. unsigned int i, eop;
  1066. unsigned int count = 0;
  1067. unsigned int total_tx_bytes = 0, total_tx_packets = 0;
  1068. unsigned int bytes_compl = 0, pkts_compl = 0;
  1069. i = tx_ring->next_to_clean;
  1070. eop = tx_ring->buffer_info[i].next_to_watch;
  1071. eop_desc = E1000_TX_DESC(*tx_ring, eop);
  1072. while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
  1073. (count < tx_ring->count)) {
  1074. bool cleaned = false;
  1075. dma_rmb(); /* read buffer_info after eop_desc */
  1076. for (; !cleaned; count++) {
  1077. tx_desc = E1000_TX_DESC(*tx_ring, i);
  1078. buffer_info = &tx_ring->buffer_info[i];
  1079. cleaned = (i == eop);
  1080. if (cleaned) {
  1081. total_tx_packets += buffer_info->segs;
  1082. total_tx_bytes += buffer_info->bytecount;
  1083. if (buffer_info->skb) {
  1084. bytes_compl += buffer_info->skb->len;
  1085. pkts_compl++;
  1086. }
  1087. }
  1088. e1000_put_txbuf(tx_ring, buffer_info, false);
  1089. tx_desc->upper.data = 0;
  1090. i++;
  1091. if (i == tx_ring->count)
  1092. i = 0;
  1093. }
  1094. if (i == tx_ring->next_to_use)
  1095. break;
  1096. eop = tx_ring->buffer_info[i].next_to_watch;
  1097. eop_desc = E1000_TX_DESC(*tx_ring, eop);
  1098. }
  1099. tx_ring->next_to_clean = i;
  1100. netdev_completed_queue(netdev, pkts_compl, bytes_compl);
  1101. #define TX_WAKE_THRESHOLD 32
  1102. if (count && netif_carrier_ok(netdev) &&
  1103. e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
  1104. /* Make sure that anybody stopping the queue after this
  1105. * sees the new next_to_clean.
  1106. */
  1107. smp_mb();
  1108. if (netif_queue_stopped(netdev) &&
  1109. !(test_bit(__E1000_DOWN, &adapter->state))) {
  1110. netif_wake_queue(netdev);
  1111. ++adapter->restart_queue;
  1112. }
  1113. }
  1114. if (adapter->detect_tx_hung) {
  1115. /* Detect a transmit hang in hardware, this serializes the
  1116. * check with the clearing of time_stamp and movement of i
  1117. */
  1118. adapter->detect_tx_hung = false;
  1119. if (tx_ring->buffer_info[i].time_stamp &&
  1120. time_after(jiffies, tx_ring->buffer_info[i].time_stamp
  1121. + (adapter->tx_timeout_factor * HZ)) &&
  1122. !(er32(STATUS) & E1000_STATUS_TXOFF))
  1123. schedule_work(&adapter->print_hang_task);
  1124. else
  1125. adapter->tx_hang_recheck = false;
  1126. }
  1127. adapter->total_tx_bytes += total_tx_bytes;
  1128. adapter->total_tx_packets += total_tx_packets;
  1129. return count < tx_ring->count;
  1130. }
  1131. /**
  1132. * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
  1133. * @rx_ring: Rx descriptor ring
  1134. *
  1135. * the return value indicates whether actual cleaning was done, there
  1136. * is no guarantee that everything was cleaned
  1137. **/
  1138. static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
  1139. int work_to_do)
  1140. {
  1141. struct e1000_adapter *adapter = rx_ring->adapter;
  1142. struct e1000_hw *hw = &adapter->hw;
  1143. union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
  1144. struct net_device *netdev = adapter->netdev;
  1145. struct pci_dev *pdev = adapter->pdev;
  1146. struct e1000_buffer *buffer_info, *next_buffer;
  1147. struct e1000_ps_page *ps_page;
  1148. struct sk_buff *skb;
  1149. unsigned int i, j;
  1150. u32 length, staterr;
  1151. int cleaned_count = 0;
  1152. bool cleaned = false;
  1153. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  1154. i = rx_ring->next_to_clean;
  1155. rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
  1156. staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
  1157. buffer_info = &rx_ring->buffer_info[i];
  1158. while (staterr & E1000_RXD_STAT_DD) {
  1159. if (*work_done >= work_to_do)
  1160. break;
  1161. (*work_done)++;
  1162. skb = buffer_info->skb;
  1163. dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
  1164. /* in the packet split case this is header only */
  1165. prefetch(skb->data - NET_IP_ALIGN);
  1166. i++;
  1167. if (i == rx_ring->count)
  1168. i = 0;
  1169. next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
  1170. prefetch(next_rxd);
  1171. next_buffer = &rx_ring->buffer_info[i];
  1172. cleaned = true;
  1173. cleaned_count++;
  1174. dma_unmap_single(&pdev->dev, buffer_info->dma,
  1175. adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
  1176. buffer_info->dma = 0;
  1177. /* see !EOP comment in other Rx routine */
  1178. if (!(staterr & E1000_RXD_STAT_EOP))
  1179. adapter->flags2 |= FLAG2_IS_DISCARDING;
  1180. if (adapter->flags2 & FLAG2_IS_DISCARDING) {
  1181. e_dbg("Packet Split buffers didn't pick up the full packet\n");
  1182. dev_kfree_skb_irq(skb);
  1183. if (staterr & E1000_RXD_STAT_EOP)
  1184. adapter->flags2 &= ~FLAG2_IS_DISCARDING;
  1185. goto next_desc;
  1186. }
  1187. if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
  1188. !(netdev->features & NETIF_F_RXALL))) {
  1189. dev_kfree_skb_irq(skb);
  1190. goto next_desc;
  1191. }
  1192. length = le16_to_cpu(rx_desc->wb.middle.length0);
  1193. if (!length) {
  1194. e_dbg("Last part of the packet spanning multiple descriptors\n");
  1195. dev_kfree_skb_irq(skb);
  1196. goto next_desc;
  1197. }
  1198. /* Good Receive */
  1199. skb_put(skb, length);
  1200. {
  1201. /* this looks ugly, but it seems compiler issues make
  1202. * it more efficient than reusing j
  1203. */
  1204. int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
  1205. /* page alloc/put takes too long and effects small
  1206. * packet throughput, so unsplit small packets and
  1207. * save the alloc/put only valid in softirq (napi)
  1208. * context to call kmap_*
  1209. */
  1210. if (l1 && (l1 <= copybreak) &&
  1211. ((length + l1) <= adapter->rx_ps_bsize0)) {
  1212. u8 *vaddr;
  1213. ps_page = &buffer_info->ps_pages[0];
  1214. /* there is no documentation about how to call
  1215. * kmap_atomic, so we can't hold the mapping
  1216. * very long
  1217. */
  1218. dma_sync_single_for_cpu(&pdev->dev,
  1219. ps_page->dma,
  1220. PAGE_SIZE,
  1221. DMA_FROM_DEVICE);
  1222. vaddr = kmap_atomic(ps_page->page);
  1223. memcpy(skb_tail_pointer(skb), vaddr, l1);
  1224. kunmap_atomic(vaddr);
  1225. dma_sync_single_for_device(&pdev->dev,
  1226. ps_page->dma,
  1227. PAGE_SIZE,
  1228. DMA_FROM_DEVICE);
  1229. /* remove the CRC */
  1230. if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
  1231. if (!(netdev->features & NETIF_F_RXFCS))
  1232. l1 -= 4;
  1233. }
  1234. skb_put(skb, l1);
  1235. goto copydone;
  1236. } /* if */
  1237. }
  1238. for (j = 0; j < PS_PAGE_BUFFERS; j++) {
  1239. length = le16_to_cpu(rx_desc->wb.upper.length[j]);
  1240. if (!length)
  1241. break;
  1242. ps_page = &buffer_info->ps_pages[j];
  1243. dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
  1244. DMA_FROM_DEVICE);
  1245. ps_page->dma = 0;
  1246. skb_fill_page_desc(skb, j, ps_page->page, 0, length);
  1247. ps_page->page = NULL;
  1248. skb->len += length;
  1249. skb->data_len += length;
  1250. skb->truesize += PAGE_SIZE;
  1251. }
  1252. /* strip the ethernet crc, problem is we're using pages now so
  1253. * this whole operation can get a little cpu intensive
  1254. */
  1255. if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
  1256. if (!(netdev->features & NETIF_F_RXFCS))
  1257. pskb_trim(skb, skb->len - 4);
  1258. }
  1259. copydone:
  1260. total_rx_bytes += skb->len;
  1261. total_rx_packets++;
  1262. e1000_rx_checksum(adapter, staterr, skb);
  1263. e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
  1264. if (rx_desc->wb.upper.header_status &
  1265. cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
  1266. adapter->rx_hdr_split++;
  1267. e1000_receive_skb(adapter, netdev, skb, staterr,
  1268. rx_desc->wb.middle.vlan);
  1269. next_desc:
  1270. rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
  1271. buffer_info->skb = NULL;
  1272. /* return some buffers to hardware, one at a time is too slow */
  1273. if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
  1274. adapter->alloc_rx_buf(rx_ring, cleaned_count,
  1275. GFP_ATOMIC);
  1276. cleaned_count = 0;
  1277. }
  1278. /* use prefetched values */
  1279. rx_desc = next_rxd;
  1280. buffer_info = next_buffer;
  1281. staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
  1282. }
  1283. rx_ring->next_to_clean = i;
  1284. cleaned_count = e1000_desc_unused(rx_ring);
  1285. if (cleaned_count)
  1286. adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
  1287. adapter->total_rx_bytes += total_rx_bytes;
  1288. adapter->total_rx_packets += total_rx_packets;
  1289. return cleaned;
  1290. }
  1291. /**
  1292. * e1000_consume_page - helper function
  1293. **/
  1294. static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
  1295. u16 length)
  1296. {
  1297. bi->page = NULL;
  1298. skb->len += length;
  1299. skb->data_len += length;
  1300. skb->truesize += PAGE_SIZE;
  1301. }
  1302. /**
  1303. * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
  1304. * @adapter: board private structure
  1305. *
  1306. * the return value indicates whether actual cleaning was done, there
  1307. * is no guarantee that everything was cleaned
  1308. **/
  1309. static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
  1310. int work_to_do)
  1311. {
  1312. struct e1000_adapter *adapter = rx_ring->adapter;
  1313. struct net_device *netdev = adapter->netdev;
  1314. struct pci_dev *pdev = adapter->pdev;
  1315. union e1000_rx_desc_extended *rx_desc, *next_rxd;
  1316. struct e1000_buffer *buffer_info, *next_buffer;
  1317. u32 length, staterr;
  1318. unsigned int i;
  1319. int cleaned_count = 0;
  1320. bool cleaned = false;
  1321. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  1322. struct skb_shared_info *shinfo;
  1323. i = rx_ring->next_to_clean;
  1324. rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
  1325. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  1326. buffer_info = &rx_ring->buffer_info[i];
  1327. while (staterr & E1000_RXD_STAT_DD) {
  1328. struct sk_buff *skb;
  1329. if (*work_done >= work_to_do)
  1330. break;
  1331. (*work_done)++;
  1332. dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
  1333. skb = buffer_info->skb;
  1334. buffer_info->skb = NULL;
  1335. ++i;
  1336. if (i == rx_ring->count)
  1337. i = 0;
  1338. next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
  1339. prefetch(next_rxd);
  1340. next_buffer = &rx_ring->buffer_info[i];
  1341. cleaned = true;
  1342. cleaned_count++;
  1343. dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
  1344. DMA_FROM_DEVICE);
  1345. buffer_info->dma = 0;
  1346. length = le16_to_cpu(rx_desc->wb.upper.length);
  1347. /* errors is only valid for DD + EOP descriptors */
  1348. if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
  1349. ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
  1350. !(netdev->features & NETIF_F_RXALL)))) {
  1351. /* recycle both page and skb */
  1352. buffer_info->skb = skb;
  1353. /* an error means any chain goes out the window too */
  1354. if (rx_ring->rx_skb_top)
  1355. dev_kfree_skb_irq(rx_ring->rx_skb_top);
  1356. rx_ring->rx_skb_top = NULL;
  1357. goto next_desc;
  1358. }
  1359. #define rxtop (rx_ring->rx_skb_top)
  1360. if (!(staterr & E1000_RXD_STAT_EOP)) {
  1361. /* this descriptor is only the beginning (or middle) */
  1362. if (!rxtop) {
  1363. /* this is the beginning of a chain */
  1364. rxtop = skb;
  1365. skb_fill_page_desc(rxtop, 0, buffer_info->page,
  1366. 0, length);
  1367. } else {
  1368. /* this is the middle of a chain */
  1369. shinfo = skb_shinfo(rxtop);
  1370. skb_fill_page_desc(rxtop, shinfo->nr_frags,
  1371. buffer_info->page, 0,
  1372. length);
  1373. /* re-use the skb, only consumed the page */
  1374. buffer_info->skb = skb;
  1375. }
  1376. e1000_consume_page(buffer_info, rxtop, length);
  1377. goto next_desc;
  1378. } else {
  1379. if (rxtop) {
  1380. /* end of the chain */
  1381. shinfo = skb_shinfo(rxtop);
  1382. skb_fill_page_desc(rxtop, shinfo->nr_frags,
  1383. buffer_info->page, 0,
  1384. length);
  1385. /* re-use the current skb, we only consumed the
  1386. * page
  1387. */
  1388. buffer_info->skb = skb;
  1389. skb = rxtop;
  1390. rxtop = NULL;
  1391. e1000_consume_page(buffer_info, skb, length);
  1392. } else {
  1393. /* no chain, got EOP, this buf is the packet
  1394. * copybreak to save the put_page/alloc_page
  1395. */
  1396. if (length <= copybreak &&
  1397. skb_tailroom(skb) >= length) {
  1398. u8 *vaddr;
  1399. vaddr = kmap_atomic(buffer_info->page);
  1400. memcpy(skb_tail_pointer(skb), vaddr,
  1401. length);
  1402. kunmap_atomic(vaddr);
  1403. /* re-use the page, so don't erase
  1404. * buffer_info->page
  1405. */
  1406. skb_put(skb, length);
  1407. } else {
  1408. skb_fill_page_desc(skb, 0,
  1409. buffer_info->page, 0,
  1410. length);
  1411. e1000_consume_page(buffer_info, skb,
  1412. length);
  1413. }
  1414. }
  1415. }
  1416. /* Receive Checksum Offload */
  1417. e1000_rx_checksum(adapter, staterr, skb);
  1418. e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
  1419. /* probably a little skewed due to removing CRC */
  1420. total_rx_bytes += skb->len;
  1421. total_rx_packets++;
  1422. /* eth type trans needs skb->data to point to something */
  1423. if (!pskb_may_pull(skb, ETH_HLEN)) {
  1424. e_err("pskb_may_pull failed.\n");
  1425. dev_kfree_skb_irq(skb);
  1426. goto next_desc;
  1427. }
  1428. e1000_receive_skb(adapter, netdev, skb, staterr,
  1429. rx_desc->wb.upper.vlan);
  1430. next_desc:
  1431. rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
  1432. /* return some buffers to hardware, one at a time is too slow */
  1433. if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
  1434. adapter->alloc_rx_buf(rx_ring, cleaned_count,
  1435. GFP_ATOMIC);
  1436. cleaned_count = 0;
  1437. }
  1438. /* use prefetched values */
  1439. rx_desc = next_rxd;
  1440. buffer_info = next_buffer;
  1441. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  1442. }
  1443. rx_ring->next_to_clean = i;
  1444. cleaned_count = e1000_desc_unused(rx_ring);
  1445. if (cleaned_count)
  1446. adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
  1447. adapter->total_rx_bytes += total_rx_bytes;
  1448. adapter->total_rx_packets += total_rx_packets;
  1449. return cleaned;
  1450. }
  1451. /**
  1452. * e1000_clean_rx_ring - Free Rx Buffers per Queue
  1453. * @rx_ring: Rx descriptor ring
  1454. **/
  1455. static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
  1456. {
  1457. struct e1000_adapter *adapter = rx_ring->adapter;
  1458. struct e1000_buffer *buffer_info;
  1459. struct e1000_ps_page *ps_page;
  1460. struct pci_dev *pdev = adapter->pdev;
  1461. unsigned int i, j;
  1462. /* Free all the Rx ring sk_buffs */
  1463. for (i = 0; i < rx_ring->count; i++) {
  1464. buffer_info = &rx_ring->buffer_info[i];
  1465. if (buffer_info->dma) {
  1466. if (adapter->clean_rx == e1000_clean_rx_irq)
  1467. dma_unmap_single(&pdev->dev, buffer_info->dma,
  1468. adapter->rx_buffer_len,
  1469. DMA_FROM_DEVICE);
  1470. else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
  1471. dma_unmap_page(&pdev->dev, buffer_info->dma,
  1472. PAGE_SIZE, DMA_FROM_DEVICE);
  1473. else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
  1474. dma_unmap_single(&pdev->dev, buffer_info->dma,
  1475. adapter->rx_ps_bsize0,
  1476. DMA_FROM_DEVICE);
  1477. buffer_info->dma = 0;
  1478. }
  1479. if (buffer_info->page) {
  1480. put_page(buffer_info->page);
  1481. buffer_info->page = NULL;
  1482. }
  1483. if (buffer_info->skb) {
  1484. dev_kfree_skb(buffer_info->skb);
  1485. buffer_info->skb = NULL;
  1486. }
  1487. for (j = 0; j < PS_PAGE_BUFFERS; j++) {
  1488. ps_page = &buffer_info->ps_pages[j];
  1489. if (!ps_page->page)
  1490. break;
  1491. dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
  1492. DMA_FROM_DEVICE);
  1493. ps_page->dma = 0;
  1494. put_page(ps_page->page);
  1495. ps_page->page = NULL;
  1496. }
  1497. }
  1498. /* there also may be some cached data from a chained receive */
  1499. if (rx_ring->rx_skb_top) {
  1500. dev_kfree_skb(rx_ring->rx_skb_top);
  1501. rx_ring->rx_skb_top = NULL;
  1502. }
  1503. /* Zero out the descriptor ring */
  1504. memset(rx_ring->desc, 0, rx_ring->size);
  1505. rx_ring->next_to_clean = 0;
  1506. rx_ring->next_to_use = 0;
  1507. adapter->flags2 &= ~FLAG2_IS_DISCARDING;
  1508. }
  1509. static void e1000e_downshift_workaround(struct work_struct *work)
  1510. {
  1511. struct e1000_adapter *adapter = container_of(work,
  1512. struct e1000_adapter,
  1513. downshift_task);
  1514. if (test_bit(__E1000_DOWN, &adapter->state))
  1515. return;
  1516. e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
  1517. }
  1518. /**
  1519. * e1000_intr_msi - Interrupt Handler
  1520. * @irq: interrupt number
  1521. * @data: pointer to a network interface device structure
  1522. **/
  1523. static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
  1524. {
  1525. struct net_device *netdev = data;
  1526. struct e1000_adapter *adapter = netdev_priv(netdev);
  1527. struct e1000_hw *hw = &adapter->hw;
  1528. u32 icr = er32(ICR);
  1529. /* read ICR disables interrupts using IAM */
  1530. if (icr & E1000_ICR_LSC) {
  1531. hw->mac.get_link_status = true;
  1532. /* ICH8 workaround-- Call gig speed drop workaround on cable
  1533. * disconnect (LSC) before accessing any PHY registers
  1534. */
  1535. if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
  1536. (!(er32(STATUS) & E1000_STATUS_LU)))
  1537. schedule_work(&adapter->downshift_task);
  1538. /* 80003ES2LAN workaround-- For packet buffer work-around on
  1539. * link down event; disable receives here in the ISR and reset
  1540. * adapter in watchdog
  1541. */
  1542. if (netif_carrier_ok(netdev) &&
  1543. adapter->flags & FLAG_RX_NEEDS_RESTART) {
  1544. /* disable receives */
  1545. u32 rctl = er32(RCTL);
  1546. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  1547. adapter->flags |= FLAG_RESTART_NOW;
  1548. }
  1549. /* guard against interrupt when we're going down */
  1550. if (!test_bit(__E1000_DOWN, &adapter->state))
  1551. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  1552. }
  1553. /* Reset on uncorrectable ECC error */
  1554. if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) {
  1555. u32 pbeccsts = er32(PBECCSTS);
  1556. adapter->corr_errors +=
  1557. pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
  1558. adapter->uncorr_errors +=
  1559. (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
  1560. E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
  1561. /* Do the reset outside of interrupt context */
  1562. schedule_work(&adapter->reset_task);
  1563. /* return immediately since reset is imminent */
  1564. return IRQ_HANDLED;
  1565. }
  1566. if (napi_schedule_prep(&adapter->napi)) {
  1567. adapter->total_tx_bytes = 0;
  1568. adapter->total_tx_packets = 0;
  1569. adapter->total_rx_bytes = 0;
  1570. adapter->total_rx_packets = 0;
  1571. __napi_schedule(&adapter->napi);
  1572. }
  1573. return IRQ_HANDLED;
  1574. }
  1575. /**
  1576. * e1000_intr - Interrupt Handler
  1577. * @irq: interrupt number
  1578. * @data: pointer to a network interface device structure
  1579. **/
  1580. static irqreturn_t e1000_intr(int __always_unused irq, void *data)
  1581. {
  1582. struct net_device *netdev = data;
  1583. struct e1000_adapter *adapter = netdev_priv(netdev);
  1584. struct e1000_hw *hw = &adapter->hw;
  1585. u32 rctl, icr = er32(ICR);
  1586. if (!icr || test_bit(__E1000_DOWN, &adapter->state))
  1587. return IRQ_NONE; /* Not our interrupt */
  1588. /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
  1589. * not set, then the adapter didn't send an interrupt
  1590. */
  1591. if (!(icr & E1000_ICR_INT_ASSERTED))
  1592. return IRQ_NONE;
  1593. /* Interrupt Auto-Mask...upon reading ICR,
  1594. * interrupts are masked. No need for the
  1595. * IMC write
  1596. */
  1597. if (icr & E1000_ICR_LSC) {
  1598. hw->mac.get_link_status = true;
  1599. /* ICH8 workaround-- Call gig speed drop workaround on cable
  1600. * disconnect (LSC) before accessing any PHY registers
  1601. */
  1602. if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
  1603. (!(er32(STATUS) & E1000_STATUS_LU)))
  1604. schedule_work(&adapter->downshift_task);
  1605. /* 80003ES2LAN workaround--
  1606. * For packet buffer work-around on link down event;
  1607. * disable receives here in the ISR and
  1608. * reset adapter in watchdog
  1609. */
  1610. if (netif_carrier_ok(netdev) &&
  1611. (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
  1612. /* disable receives */
  1613. rctl = er32(RCTL);
  1614. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  1615. adapter->flags |= FLAG_RESTART_NOW;
  1616. }
  1617. /* guard against interrupt when we're going down */
  1618. if (!test_bit(__E1000_DOWN, &adapter->state))
  1619. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  1620. }
  1621. /* Reset on uncorrectable ECC error */
  1622. if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) {
  1623. u32 pbeccsts = er32(PBECCSTS);
  1624. adapter->corr_errors +=
  1625. pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
  1626. adapter->uncorr_errors +=
  1627. (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
  1628. E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
  1629. /* Do the reset outside of interrupt context */
  1630. schedule_work(&adapter->reset_task);
  1631. /* return immediately since reset is imminent */
  1632. return IRQ_HANDLED;
  1633. }
  1634. if (napi_schedule_prep(&adapter->napi)) {
  1635. adapter->total_tx_bytes = 0;
  1636. adapter->total_tx_packets = 0;
  1637. adapter->total_rx_bytes = 0;
  1638. adapter->total_rx_packets = 0;
  1639. __napi_schedule(&adapter->napi);
  1640. }
  1641. return IRQ_HANDLED;
  1642. }
  1643. static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
  1644. {
  1645. struct net_device *netdev = data;
  1646. struct e1000_adapter *adapter = netdev_priv(netdev);
  1647. struct e1000_hw *hw = &adapter->hw;
  1648. u32 icr = er32(ICR);
  1649. if (icr & adapter->eiac_mask)
  1650. ew32(ICS, (icr & adapter->eiac_mask));
  1651. if (icr & E1000_ICR_LSC) {
  1652. hw->mac.get_link_status = true;
  1653. /* guard against interrupt when we're going down */
  1654. if (!test_bit(__E1000_DOWN, &adapter->state))
  1655. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  1656. }
  1657. if (!test_bit(__E1000_DOWN, &adapter->state))
  1658. ew32(IMS, E1000_IMS_OTHER | IMS_OTHER_MASK);
  1659. return IRQ_HANDLED;
  1660. }
  1661. static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
  1662. {
  1663. struct net_device *netdev = data;
  1664. struct e1000_adapter *adapter = netdev_priv(netdev);
  1665. struct e1000_hw *hw = &adapter->hw;
  1666. struct e1000_ring *tx_ring = adapter->tx_ring;
  1667. adapter->total_tx_bytes = 0;
  1668. adapter->total_tx_packets = 0;
  1669. if (!e1000_clean_tx_irq(tx_ring))
  1670. /* Ring was not completely cleaned, so fire another interrupt */
  1671. ew32(ICS, tx_ring->ims_val);
  1672. if (!test_bit(__E1000_DOWN, &adapter->state))
  1673. ew32(IMS, adapter->tx_ring->ims_val);
  1674. return IRQ_HANDLED;
  1675. }
  1676. static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
  1677. {
  1678. struct net_device *netdev = data;
  1679. struct e1000_adapter *adapter = netdev_priv(netdev);
  1680. struct e1000_ring *rx_ring = adapter->rx_ring;
  1681. /* Write the ITR value calculated at the end of the
  1682. * previous interrupt.
  1683. */
  1684. if (rx_ring->set_itr) {
  1685. u32 itr = rx_ring->itr_val ?
  1686. 1000000000 / (rx_ring->itr_val * 256) : 0;
  1687. writel(itr, rx_ring->itr_register);
  1688. rx_ring->set_itr = 0;
  1689. }
  1690. if (napi_schedule_prep(&adapter->napi)) {
  1691. adapter->total_rx_bytes = 0;
  1692. adapter->total_rx_packets = 0;
  1693. __napi_schedule(&adapter->napi);
  1694. }
  1695. return IRQ_HANDLED;
  1696. }
  1697. /**
  1698. * e1000_configure_msix - Configure MSI-X hardware
  1699. *
  1700. * e1000_configure_msix sets up the hardware to properly
  1701. * generate MSI-X interrupts.
  1702. **/
  1703. static void e1000_configure_msix(struct e1000_adapter *adapter)
  1704. {
  1705. struct e1000_hw *hw = &adapter->hw;
  1706. struct e1000_ring *rx_ring = adapter->rx_ring;
  1707. struct e1000_ring *tx_ring = adapter->tx_ring;
  1708. int vector = 0;
  1709. u32 ctrl_ext, ivar = 0;
  1710. adapter->eiac_mask = 0;
  1711. /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
  1712. if (hw->mac.type == e1000_82574) {
  1713. u32 rfctl = er32(RFCTL);
  1714. rfctl |= E1000_RFCTL_ACK_DIS;
  1715. ew32(RFCTL, rfctl);
  1716. }
  1717. /* Configure Rx vector */
  1718. rx_ring->ims_val = E1000_IMS_RXQ0;
  1719. adapter->eiac_mask |= rx_ring->ims_val;
  1720. if (rx_ring->itr_val)
  1721. writel(1000000000 / (rx_ring->itr_val * 256),
  1722. rx_ring->itr_register);
  1723. else
  1724. writel(1, rx_ring->itr_register);
  1725. ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
  1726. /* Configure Tx vector */
  1727. tx_ring->ims_val = E1000_IMS_TXQ0;
  1728. vector++;
  1729. if (tx_ring->itr_val)
  1730. writel(1000000000 / (tx_ring->itr_val * 256),
  1731. tx_ring->itr_register);
  1732. else
  1733. writel(1, tx_ring->itr_register);
  1734. adapter->eiac_mask |= tx_ring->ims_val;
  1735. ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
  1736. /* set vector for Other Causes, e.g. link changes */
  1737. vector++;
  1738. ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
  1739. if (rx_ring->itr_val)
  1740. writel(1000000000 / (rx_ring->itr_val * 256),
  1741. hw->hw_addr + E1000_EITR_82574(vector));
  1742. else
  1743. writel(1, hw->hw_addr + E1000_EITR_82574(vector));
  1744. /* Cause Tx interrupts on every write back */
  1745. ivar |= BIT(31);
  1746. ew32(IVAR, ivar);
  1747. /* enable MSI-X PBA support */
  1748. ctrl_ext = er32(CTRL_EXT) & ~E1000_CTRL_EXT_IAME;
  1749. ctrl_ext |= E1000_CTRL_EXT_PBA_CLR | E1000_CTRL_EXT_EIAME;
  1750. ew32(CTRL_EXT, ctrl_ext);
  1751. e1e_flush();
  1752. }
  1753. void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
  1754. {
  1755. if (adapter->msix_entries) {
  1756. pci_disable_msix(adapter->pdev);
  1757. kfree(adapter->msix_entries);
  1758. adapter->msix_entries = NULL;
  1759. } else if (adapter->flags & FLAG_MSI_ENABLED) {
  1760. pci_disable_msi(adapter->pdev);
  1761. adapter->flags &= ~FLAG_MSI_ENABLED;
  1762. }
  1763. }
  1764. /**
  1765. * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
  1766. *
  1767. * Attempt to configure interrupts using the best available
  1768. * capabilities of the hardware and kernel.
  1769. **/
  1770. void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
  1771. {
  1772. int err;
  1773. int i;
  1774. switch (adapter->int_mode) {
  1775. case E1000E_INT_MODE_MSIX:
  1776. if (adapter->flags & FLAG_HAS_MSIX) {
  1777. adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
  1778. adapter->msix_entries = kcalloc(adapter->num_vectors,
  1779. sizeof(struct
  1780. msix_entry),
  1781. GFP_KERNEL);
  1782. if (adapter->msix_entries) {
  1783. struct e1000_adapter *a = adapter;
  1784. for (i = 0; i < adapter->num_vectors; i++)
  1785. adapter->msix_entries[i].entry = i;
  1786. err = pci_enable_msix_range(a->pdev,
  1787. a->msix_entries,
  1788. a->num_vectors,
  1789. a->num_vectors);
  1790. if (err > 0)
  1791. return;
  1792. }
  1793. /* MSI-X failed, so fall through and try MSI */
  1794. e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
  1795. e1000e_reset_interrupt_capability(adapter);
  1796. }
  1797. adapter->int_mode = E1000E_INT_MODE_MSI;
  1798. /* Fall through */
  1799. case E1000E_INT_MODE_MSI:
  1800. if (!pci_enable_msi(adapter->pdev)) {
  1801. adapter->flags |= FLAG_MSI_ENABLED;
  1802. } else {
  1803. adapter->int_mode = E1000E_INT_MODE_LEGACY;
  1804. e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
  1805. }
  1806. /* Fall through */
  1807. case E1000E_INT_MODE_LEGACY:
  1808. /* Don't do anything; this is the system default */
  1809. break;
  1810. }
  1811. /* store the number of vectors being used */
  1812. adapter->num_vectors = 1;
  1813. }
  1814. /**
  1815. * e1000_request_msix - Initialize MSI-X interrupts
  1816. *
  1817. * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
  1818. * kernel.
  1819. **/
  1820. static int e1000_request_msix(struct e1000_adapter *adapter)
  1821. {
  1822. struct net_device *netdev = adapter->netdev;
  1823. int err = 0, vector = 0;
  1824. if (strlen(netdev->name) < (IFNAMSIZ - 5))
  1825. snprintf(adapter->rx_ring->name,
  1826. sizeof(adapter->rx_ring->name) - 1,
  1827. "%.14s-rx-0", netdev->name);
  1828. else
  1829. memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
  1830. err = request_irq(adapter->msix_entries[vector].vector,
  1831. e1000_intr_msix_rx, 0, adapter->rx_ring->name,
  1832. netdev);
  1833. if (err)
  1834. return err;
  1835. adapter->rx_ring->itr_register = adapter->hw.hw_addr +
  1836. E1000_EITR_82574(vector);
  1837. adapter->rx_ring->itr_val = adapter->itr;
  1838. vector++;
  1839. if (strlen(netdev->name) < (IFNAMSIZ - 5))
  1840. snprintf(adapter->tx_ring->name,
  1841. sizeof(adapter->tx_ring->name) - 1,
  1842. "%.14s-tx-0", netdev->name);
  1843. else
  1844. memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
  1845. err = request_irq(adapter->msix_entries[vector].vector,
  1846. e1000_intr_msix_tx, 0, adapter->tx_ring->name,
  1847. netdev);
  1848. if (err)
  1849. return err;
  1850. adapter->tx_ring->itr_register = adapter->hw.hw_addr +
  1851. E1000_EITR_82574(vector);
  1852. adapter->tx_ring->itr_val = adapter->itr;
  1853. vector++;
  1854. err = request_irq(adapter->msix_entries[vector].vector,
  1855. e1000_msix_other, 0, netdev->name, netdev);
  1856. if (err)
  1857. return err;
  1858. e1000_configure_msix(adapter);
  1859. return 0;
  1860. }
  1861. /**
  1862. * e1000_request_irq - initialize interrupts
  1863. *
  1864. * Attempts to configure interrupts using the best available
  1865. * capabilities of the hardware and kernel.
  1866. **/
  1867. static int e1000_request_irq(struct e1000_adapter *adapter)
  1868. {
  1869. struct net_device *netdev = adapter->netdev;
  1870. int err;
  1871. if (adapter->msix_entries) {
  1872. err = e1000_request_msix(adapter);
  1873. if (!err)
  1874. return err;
  1875. /* fall back to MSI */
  1876. e1000e_reset_interrupt_capability(adapter);
  1877. adapter->int_mode = E1000E_INT_MODE_MSI;
  1878. e1000e_set_interrupt_capability(adapter);
  1879. }
  1880. if (adapter->flags & FLAG_MSI_ENABLED) {
  1881. err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
  1882. netdev->name, netdev);
  1883. if (!err)
  1884. return err;
  1885. /* fall back to legacy interrupt */
  1886. e1000e_reset_interrupt_capability(adapter);
  1887. adapter->int_mode = E1000E_INT_MODE_LEGACY;
  1888. }
  1889. err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
  1890. netdev->name, netdev);
  1891. if (err)
  1892. e_err("Unable to allocate interrupt, Error: %d\n", err);
  1893. return err;
  1894. }
  1895. static void e1000_free_irq(struct e1000_adapter *adapter)
  1896. {
  1897. struct net_device *netdev = adapter->netdev;
  1898. if (adapter->msix_entries) {
  1899. int vector = 0;
  1900. free_irq(adapter->msix_entries[vector].vector, netdev);
  1901. vector++;
  1902. free_irq(adapter->msix_entries[vector].vector, netdev);
  1903. vector++;
  1904. /* Other Causes interrupt vector */
  1905. free_irq(adapter->msix_entries[vector].vector, netdev);
  1906. return;
  1907. }
  1908. free_irq(adapter->pdev->irq, netdev);
  1909. }
  1910. /**
  1911. * e1000_irq_disable - Mask off interrupt generation on the NIC
  1912. **/
  1913. static void e1000_irq_disable(struct e1000_adapter *adapter)
  1914. {
  1915. struct e1000_hw *hw = &adapter->hw;
  1916. ew32(IMC, ~0);
  1917. if (adapter->msix_entries)
  1918. ew32(EIAC_82574, 0);
  1919. e1e_flush();
  1920. if (adapter->msix_entries) {
  1921. int i;
  1922. for (i = 0; i < adapter->num_vectors; i++)
  1923. synchronize_irq(adapter->msix_entries[i].vector);
  1924. } else {
  1925. synchronize_irq(adapter->pdev->irq);
  1926. }
  1927. }
  1928. /**
  1929. * e1000_irq_enable - Enable default interrupt generation settings
  1930. **/
  1931. static void e1000_irq_enable(struct e1000_adapter *adapter)
  1932. {
  1933. struct e1000_hw *hw = &adapter->hw;
  1934. if (adapter->msix_entries) {
  1935. ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
  1936. ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER |
  1937. IMS_OTHER_MASK);
  1938. } else if (hw->mac.type >= e1000_pch_lpt) {
  1939. ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
  1940. } else {
  1941. ew32(IMS, IMS_ENABLE_MASK);
  1942. }
  1943. e1e_flush();
  1944. }
  1945. /**
  1946. * e1000e_get_hw_control - get control of the h/w from f/w
  1947. * @adapter: address of board private structure
  1948. *
  1949. * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
  1950. * For ASF and Pass Through versions of f/w this means that
  1951. * the driver is loaded. For AMT version (only with 82573)
  1952. * of the f/w this means that the network i/f is open.
  1953. **/
  1954. void e1000e_get_hw_control(struct e1000_adapter *adapter)
  1955. {
  1956. struct e1000_hw *hw = &adapter->hw;
  1957. u32 ctrl_ext;
  1958. u32 swsm;
  1959. /* Let firmware know the driver has taken over */
  1960. if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
  1961. swsm = er32(SWSM);
  1962. ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
  1963. } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
  1964. ctrl_ext = er32(CTRL_EXT);
  1965. ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
  1966. }
  1967. }
  1968. /**
  1969. * e1000e_release_hw_control - release control of the h/w to f/w
  1970. * @adapter: address of board private structure
  1971. *
  1972. * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
  1973. * For ASF and Pass Through versions of f/w this means that the
  1974. * driver is no longer loaded. For AMT version (only with 82573) i
  1975. * of the f/w this means that the network i/f is closed.
  1976. *
  1977. **/
  1978. void e1000e_release_hw_control(struct e1000_adapter *adapter)
  1979. {
  1980. struct e1000_hw *hw = &adapter->hw;
  1981. u32 ctrl_ext;
  1982. u32 swsm;
  1983. /* Let firmware taken over control of h/w */
  1984. if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
  1985. swsm = er32(SWSM);
  1986. ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
  1987. } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
  1988. ctrl_ext = er32(CTRL_EXT);
  1989. ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
  1990. }
  1991. }
  1992. /**
  1993. * e1000_alloc_ring_dma - allocate memory for a ring structure
  1994. **/
  1995. static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
  1996. struct e1000_ring *ring)
  1997. {
  1998. struct pci_dev *pdev = adapter->pdev;
  1999. ring->desc = dma_zalloc_coherent(&pdev->dev, ring->size, &ring->dma,
  2000. GFP_KERNEL);
  2001. if (!ring->desc)
  2002. return -ENOMEM;
  2003. return 0;
  2004. }
  2005. /**
  2006. * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
  2007. * @tx_ring: Tx descriptor ring
  2008. *
  2009. * Return 0 on success, negative on failure
  2010. **/
  2011. int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
  2012. {
  2013. struct e1000_adapter *adapter = tx_ring->adapter;
  2014. int err = -ENOMEM, size;
  2015. size = sizeof(struct e1000_buffer) * tx_ring->count;
  2016. tx_ring->buffer_info = vzalloc(size);
  2017. if (!tx_ring->buffer_info)
  2018. goto err;
  2019. /* round up to nearest 4K */
  2020. tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
  2021. tx_ring->size = ALIGN(tx_ring->size, 4096);
  2022. err = e1000_alloc_ring_dma(adapter, tx_ring);
  2023. if (err)
  2024. goto err;
  2025. tx_ring->next_to_use = 0;
  2026. tx_ring->next_to_clean = 0;
  2027. return 0;
  2028. err:
  2029. vfree(tx_ring->buffer_info);
  2030. e_err("Unable to allocate memory for the transmit descriptor ring\n");
  2031. return err;
  2032. }
  2033. /**
  2034. * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
  2035. * @rx_ring: Rx descriptor ring
  2036. *
  2037. * Returns 0 on success, negative on failure
  2038. **/
  2039. int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
  2040. {
  2041. struct e1000_adapter *adapter = rx_ring->adapter;
  2042. struct e1000_buffer *buffer_info;
  2043. int i, size, desc_len, err = -ENOMEM;
  2044. size = sizeof(struct e1000_buffer) * rx_ring->count;
  2045. rx_ring->buffer_info = vzalloc(size);
  2046. if (!rx_ring->buffer_info)
  2047. goto err;
  2048. for (i = 0; i < rx_ring->count; i++) {
  2049. buffer_info = &rx_ring->buffer_info[i];
  2050. buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
  2051. sizeof(struct e1000_ps_page),
  2052. GFP_KERNEL);
  2053. if (!buffer_info->ps_pages)
  2054. goto err_pages;
  2055. }
  2056. desc_len = sizeof(union e1000_rx_desc_packet_split);
  2057. /* Round up to nearest 4K */
  2058. rx_ring->size = rx_ring->count * desc_len;
  2059. rx_ring->size = ALIGN(rx_ring->size, 4096);
  2060. err = e1000_alloc_ring_dma(adapter, rx_ring);
  2061. if (err)
  2062. goto err_pages;
  2063. rx_ring->next_to_clean = 0;
  2064. rx_ring->next_to_use = 0;
  2065. rx_ring->rx_skb_top = NULL;
  2066. return 0;
  2067. err_pages:
  2068. for (i = 0; i < rx_ring->count; i++) {
  2069. buffer_info = &rx_ring->buffer_info[i];
  2070. kfree(buffer_info->ps_pages);
  2071. }
  2072. err:
  2073. vfree(rx_ring->buffer_info);
  2074. e_err("Unable to allocate memory for the receive descriptor ring\n");
  2075. return err;
  2076. }
  2077. /**
  2078. * e1000_clean_tx_ring - Free Tx Buffers
  2079. * @tx_ring: Tx descriptor ring
  2080. **/
  2081. static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
  2082. {
  2083. struct e1000_adapter *adapter = tx_ring->adapter;
  2084. struct e1000_buffer *buffer_info;
  2085. unsigned long size;
  2086. unsigned int i;
  2087. for (i = 0; i < tx_ring->count; i++) {
  2088. buffer_info = &tx_ring->buffer_info[i];
  2089. e1000_put_txbuf(tx_ring, buffer_info, false);
  2090. }
  2091. netdev_reset_queue(adapter->netdev);
  2092. size = sizeof(struct e1000_buffer) * tx_ring->count;
  2093. memset(tx_ring->buffer_info, 0, size);
  2094. memset(tx_ring->desc, 0, tx_ring->size);
  2095. tx_ring->next_to_use = 0;
  2096. tx_ring->next_to_clean = 0;
  2097. }
  2098. /**
  2099. * e1000e_free_tx_resources - Free Tx Resources per Queue
  2100. * @tx_ring: Tx descriptor ring
  2101. *
  2102. * Free all transmit software resources
  2103. **/
  2104. void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
  2105. {
  2106. struct e1000_adapter *adapter = tx_ring->adapter;
  2107. struct pci_dev *pdev = adapter->pdev;
  2108. e1000_clean_tx_ring(tx_ring);
  2109. vfree(tx_ring->buffer_info);
  2110. tx_ring->buffer_info = NULL;
  2111. dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
  2112. tx_ring->dma);
  2113. tx_ring->desc = NULL;
  2114. }
  2115. /**
  2116. * e1000e_free_rx_resources - Free Rx Resources
  2117. * @rx_ring: Rx descriptor ring
  2118. *
  2119. * Free all receive software resources
  2120. **/
  2121. void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
  2122. {
  2123. struct e1000_adapter *adapter = rx_ring->adapter;
  2124. struct pci_dev *pdev = adapter->pdev;
  2125. int i;
  2126. e1000_clean_rx_ring(rx_ring);
  2127. for (i = 0; i < rx_ring->count; i++)
  2128. kfree(rx_ring->buffer_info[i].ps_pages);
  2129. vfree(rx_ring->buffer_info);
  2130. rx_ring->buffer_info = NULL;
  2131. dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
  2132. rx_ring->dma);
  2133. rx_ring->desc = NULL;
  2134. }
  2135. /**
  2136. * e1000_update_itr - update the dynamic ITR value based on statistics
  2137. * @adapter: pointer to adapter
  2138. * @itr_setting: current adapter->itr
  2139. * @packets: the number of packets during this measurement interval
  2140. * @bytes: the number of bytes during this measurement interval
  2141. *
  2142. * Stores a new ITR value based on packets and byte
  2143. * counts during the last interrupt. The advantage of per interrupt
  2144. * computation is faster updates and more accurate ITR for the current
  2145. * traffic pattern. Constants in this function were computed
  2146. * based on theoretical maximum wire speed and thresholds were set based
  2147. * on testing data as well as attempting to minimize response time
  2148. * while increasing bulk throughput. This functionality is controlled
  2149. * by the InterruptThrottleRate module parameter.
  2150. **/
  2151. static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
  2152. {
  2153. unsigned int retval = itr_setting;
  2154. if (packets == 0)
  2155. return itr_setting;
  2156. switch (itr_setting) {
  2157. case lowest_latency:
  2158. /* handle TSO and jumbo frames */
  2159. if (bytes / packets > 8000)
  2160. retval = bulk_latency;
  2161. else if ((packets < 5) && (bytes > 512))
  2162. retval = low_latency;
  2163. break;
  2164. case low_latency: /* 50 usec aka 20000 ints/s */
  2165. if (bytes > 10000) {
  2166. /* this if handles the TSO accounting */
  2167. if (bytes / packets > 8000)
  2168. retval = bulk_latency;
  2169. else if ((packets < 10) || ((bytes / packets) > 1200))
  2170. retval = bulk_latency;
  2171. else if ((packets > 35))
  2172. retval = lowest_latency;
  2173. } else if (bytes / packets > 2000) {
  2174. retval = bulk_latency;
  2175. } else if (packets <= 2 && bytes < 512) {
  2176. retval = lowest_latency;
  2177. }
  2178. break;
  2179. case bulk_latency: /* 250 usec aka 4000 ints/s */
  2180. if (bytes > 25000) {
  2181. if (packets > 35)
  2182. retval = low_latency;
  2183. } else if (bytes < 6000) {
  2184. retval = low_latency;
  2185. }
  2186. break;
  2187. }
  2188. return retval;
  2189. }
  2190. static void e1000_set_itr(struct e1000_adapter *adapter)
  2191. {
  2192. u16 current_itr;
  2193. u32 new_itr = adapter->itr;
  2194. /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
  2195. if (adapter->link_speed != SPEED_1000) {
  2196. current_itr = 0;
  2197. new_itr = 4000;
  2198. goto set_itr_now;
  2199. }
  2200. if (adapter->flags2 & FLAG2_DISABLE_AIM) {
  2201. new_itr = 0;
  2202. goto set_itr_now;
  2203. }
  2204. adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
  2205. adapter->total_tx_packets,
  2206. adapter->total_tx_bytes);
  2207. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  2208. if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
  2209. adapter->tx_itr = low_latency;
  2210. adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
  2211. adapter->total_rx_packets,
  2212. adapter->total_rx_bytes);
  2213. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  2214. if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
  2215. adapter->rx_itr = low_latency;
  2216. current_itr = max(adapter->rx_itr, adapter->tx_itr);
  2217. /* counts and packets in update_itr are dependent on these numbers */
  2218. switch (current_itr) {
  2219. case lowest_latency:
  2220. new_itr = 70000;
  2221. break;
  2222. case low_latency:
  2223. new_itr = 20000; /* aka hwitr = ~200 */
  2224. break;
  2225. case bulk_latency:
  2226. new_itr = 4000;
  2227. break;
  2228. default:
  2229. break;
  2230. }
  2231. set_itr_now:
  2232. if (new_itr != adapter->itr) {
  2233. /* this attempts to bias the interrupt rate towards Bulk
  2234. * by adding intermediate steps when interrupt rate is
  2235. * increasing
  2236. */
  2237. new_itr = new_itr > adapter->itr ?
  2238. min(adapter->itr + (new_itr >> 2), new_itr) : new_itr;
  2239. adapter->itr = new_itr;
  2240. adapter->rx_ring->itr_val = new_itr;
  2241. if (adapter->msix_entries)
  2242. adapter->rx_ring->set_itr = 1;
  2243. else
  2244. e1000e_write_itr(adapter, new_itr);
  2245. }
  2246. }
  2247. /**
  2248. * e1000e_write_itr - write the ITR value to the appropriate registers
  2249. * @adapter: address of board private structure
  2250. * @itr: new ITR value to program
  2251. *
  2252. * e1000e_write_itr determines if the adapter is in MSI-X mode
  2253. * and, if so, writes the EITR registers with the ITR value.
  2254. * Otherwise, it writes the ITR value into the ITR register.
  2255. **/
  2256. void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
  2257. {
  2258. struct e1000_hw *hw = &adapter->hw;
  2259. u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
  2260. if (adapter->msix_entries) {
  2261. int vector;
  2262. for (vector = 0; vector < adapter->num_vectors; vector++)
  2263. writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
  2264. } else {
  2265. ew32(ITR, new_itr);
  2266. }
  2267. }
  2268. /**
  2269. * e1000_alloc_queues - Allocate memory for all rings
  2270. * @adapter: board private structure to initialize
  2271. **/
  2272. static int e1000_alloc_queues(struct e1000_adapter *adapter)
  2273. {
  2274. int size = sizeof(struct e1000_ring);
  2275. adapter->tx_ring = kzalloc(size, GFP_KERNEL);
  2276. if (!adapter->tx_ring)
  2277. goto err;
  2278. adapter->tx_ring->count = adapter->tx_ring_count;
  2279. adapter->tx_ring->adapter = adapter;
  2280. adapter->rx_ring = kzalloc(size, GFP_KERNEL);
  2281. if (!adapter->rx_ring)
  2282. goto err;
  2283. adapter->rx_ring->count = adapter->rx_ring_count;
  2284. adapter->rx_ring->adapter = adapter;
  2285. return 0;
  2286. err:
  2287. e_err("Unable to allocate memory for queues\n");
  2288. kfree(adapter->rx_ring);
  2289. kfree(adapter->tx_ring);
  2290. return -ENOMEM;
  2291. }
  2292. /**
  2293. * e1000e_poll - NAPI Rx polling callback
  2294. * @napi: struct associated with this polling callback
  2295. * @weight: number of packets driver is allowed to process this poll
  2296. **/
  2297. static int e1000e_poll(struct napi_struct *napi, int weight)
  2298. {
  2299. struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
  2300. napi);
  2301. struct e1000_hw *hw = &adapter->hw;
  2302. struct net_device *poll_dev = adapter->netdev;
  2303. int tx_cleaned = 1, work_done = 0;
  2304. adapter = netdev_priv(poll_dev);
  2305. if (!adapter->msix_entries ||
  2306. (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
  2307. tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
  2308. adapter->clean_rx(adapter->rx_ring, &work_done, weight);
  2309. if (!tx_cleaned)
  2310. work_done = weight;
  2311. /* If weight not fully consumed, exit the polling mode */
  2312. if (work_done < weight) {
  2313. if (adapter->itr_setting & 3)
  2314. e1000_set_itr(adapter);
  2315. napi_complete_done(napi, work_done);
  2316. if (!test_bit(__E1000_DOWN, &adapter->state)) {
  2317. if (adapter->msix_entries)
  2318. ew32(IMS, adapter->rx_ring->ims_val);
  2319. else
  2320. e1000_irq_enable(adapter);
  2321. }
  2322. }
  2323. return work_done;
  2324. }
  2325. static int e1000_vlan_rx_add_vid(struct net_device *netdev,
  2326. __always_unused __be16 proto, u16 vid)
  2327. {
  2328. struct e1000_adapter *adapter = netdev_priv(netdev);
  2329. struct e1000_hw *hw = &adapter->hw;
  2330. u32 vfta, index;
  2331. /* don't update vlan cookie if already programmed */
  2332. if ((adapter->hw.mng_cookie.status &
  2333. E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
  2334. (vid == adapter->mng_vlan_id))
  2335. return 0;
  2336. /* add VID to filter table */
  2337. if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
  2338. index = (vid >> 5) & 0x7F;
  2339. vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
  2340. vfta |= BIT((vid & 0x1F));
  2341. hw->mac.ops.write_vfta(hw, index, vfta);
  2342. }
  2343. set_bit(vid, adapter->active_vlans);
  2344. return 0;
  2345. }
  2346. static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
  2347. __always_unused __be16 proto, u16 vid)
  2348. {
  2349. struct e1000_adapter *adapter = netdev_priv(netdev);
  2350. struct e1000_hw *hw = &adapter->hw;
  2351. u32 vfta, index;
  2352. if ((adapter->hw.mng_cookie.status &
  2353. E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
  2354. (vid == adapter->mng_vlan_id)) {
  2355. /* release control to f/w */
  2356. e1000e_release_hw_control(adapter);
  2357. return 0;
  2358. }
  2359. /* remove VID from filter table */
  2360. if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
  2361. index = (vid >> 5) & 0x7F;
  2362. vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
  2363. vfta &= ~BIT((vid & 0x1F));
  2364. hw->mac.ops.write_vfta(hw, index, vfta);
  2365. }
  2366. clear_bit(vid, adapter->active_vlans);
  2367. return 0;
  2368. }
  2369. /**
  2370. * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
  2371. * @adapter: board private structure to initialize
  2372. **/
  2373. static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
  2374. {
  2375. struct net_device *netdev = adapter->netdev;
  2376. struct e1000_hw *hw = &adapter->hw;
  2377. u32 rctl;
  2378. if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
  2379. /* disable VLAN receive filtering */
  2380. rctl = er32(RCTL);
  2381. rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
  2382. ew32(RCTL, rctl);
  2383. if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
  2384. e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
  2385. adapter->mng_vlan_id);
  2386. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  2387. }
  2388. }
  2389. }
  2390. /**
  2391. * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
  2392. * @adapter: board private structure to initialize
  2393. **/
  2394. static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
  2395. {
  2396. struct e1000_hw *hw = &adapter->hw;
  2397. u32 rctl;
  2398. if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
  2399. /* enable VLAN receive filtering */
  2400. rctl = er32(RCTL);
  2401. rctl |= E1000_RCTL_VFE;
  2402. rctl &= ~E1000_RCTL_CFIEN;
  2403. ew32(RCTL, rctl);
  2404. }
  2405. }
  2406. /**
  2407. * e1000e_vlan_strip_disable - helper to disable HW VLAN stripping
  2408. * @adapter: board private structure to initialize
  2409. **/
  2410. static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
  2411. {
  2412. struct e1000_hw *hw = &adapter->hw;
  2413. u32 ctrl;
  2414. /* disable VLAN tag insert/strip */
  2415. ctrl = er32(CTRL);
  2416. ctrl &= ~E1000_CTRL_VME;
  2417. ew32(CTRL, ctrl);
  2418. }
  2419. /**
  2420. * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
  2421. * @adapter: board private structure to initialize
  2422. **/
  2423. static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
  2424. {
  2425. struct e1000_hw *hw = &adapter->hw;
  2426. u32 ctrl;
  2427. /* enable VLAN tag insert/strip */
  2428. ctrl = er32(CTRL);
  2429. ctrl |= E1000_CTRL_VME;
  2430. ew32(CTRL, ctrl);
  2431. }
  2432. static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
  2433. {
  2434. struct net_device *netdev = adapter->netdev;
  2435. u16 vid = adapter->hw.mng_cookie.vlan_id;
  2436. u16 old_vid = adapter->mng_vlan_id;
  2437. if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
  2438. e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
  2439. adapter->mng_vlan_id = vid;
  2440. }
  2441. if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
  2442. e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), old_vid);
  2443. }
  2444. static void e1000_restore_vlan(struct e1000_adapter *adapter)
  2445. {
  2446. u16 vid;
  2447. e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
  2448. for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
  2449. e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
  2450. }
  2451. static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
  2452. {
  2453. struct e1000_hw *hw = &adapter->hw;
  2454. u32 manc, manc2h, mdef, i, j;
  2455. if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
  2456. return;
  2457. manc = er32(MANC);
  2458. /* enable receiving management packets to the host. this will probably
  2459. * generate destination unreachable messages from the host OS, but
  2460. * the packets will be handled on SMBUS
  2461. */
  2462. manc |= E1000_MANC_EN_MNG2HOST;
  2463. manc2h = er32(MANC2H);
  2464. switch (hw->mac.type) {
  2465. default:
  2466. manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
  2467. break;
  2468. case e1000_82574:
  2469. case e1000_82583:
  2470. /* Check if IPMI pass-through decision filter already exists;
  2471. * if so, enable it.
  2472. */
  2473. for (i = 0, j = 0; i < 8; i++) {
  2474. mdef = er32(MDEF(i));
  2475. /* Ignore filters with anything other than IPMI ports */
  2476. if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
  2477. continue;
  2478. /* Enable this decision filter in MANC2H */
  2479. if (mdef)
  2480. manc2h |= BIT(i);
  2481. j |= mdef;
  2482. }
  2483. if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
  2484. break;
  2485. /* Create new decision filter in an empty filter */
  2486. for (i = 0, j = 0; i < 8; i++)
  2487. if (er32(MDEF(i)) == 0) {
  2488. ew32(MDEF(i), (E1000_MDEF_PORT_623 |
  2489. E1000_MDEF_PORT_664));
  2490. manc2h |= BIT(1);
  2491. j++;
  2492. break;
  2493. }
  2494. if (!j)
  2495. e_warn("Unable to create IPMI pass-through filter\n");
  2496. break;
  2497. }
  2498. ew32(MANC2H, manc2h);
  2499. ew32(MANC, manc);
  2500. }
  2501. /**
  2502. * e1000_configure_tx - Configure Transmit Unit after Reset
  2503. * @adapter: board private structure
  2504. *
  2505. * Configure the Tx unit of the MAC after a reset.
  2506. **/
  2507. static void e1000_configure_tx(struct e1000_adapter *adapter)
  2508. {
  2509. struct e1000_hw *hw = &adapter->hw;
  2510. struct e1000_ring *tx_ring = adapter->tx_ring;
  2511. u64 tdba;
  2512. u32 tdlen, tctl, tarc;
  2513. /* Setup the HW Tx Head and Tail descriptor pointers */
  2514. tdba = tx_ring->dma;
  2515. tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
  2516. ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
  2517. ew32(TDBAH(0), (tdba >> 32));
  2518. ew32(TDLEN(0), tdlen);
  2519. ew32(TDH(0), 0);
  2520. ew32(TDT(0), 0);
  2521. tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
  2522. tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
  2523. writel(0, tx_ring->head);
  2524. if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
  2525. e1000e_update_tdt_wa(tx_ring, 0);
  2526. else
  2527. writel(0, tx_ring->tail);
  2528. /* Set the Tx Interrupt Delay register */
  2529. ew32(TIDV, adapter->tx_int_delay);
  2530. /* Tx irq moderation */
  2531. ew32(TADV, adapter->tx_abs_int_delay);
  2532. if (adapter->flags2 & FLAG2_DMA_BURST) {
  2533. u32 txdctl = er32(TXDCTL(0));
  2534. txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
  2535. E1000_TXDCTL_WTHRESH);
  2536. /* set up some performance related parameters to encourage the
  2537. * hardware to use the bus more efficiently in bursts, depends
  2538. * on the tx_int_delay to be enabled,
  2539. * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
  2540. * hthresh = 1 ==> prefetch when one or more available
  2541. * pthresh = 0x1f ==> prefetch if internal cache 31 or less
  2542. * BEWARE: this seems to work but should be considered first if
  2543. * there are Tx hangs or other Tx related bugs
  2544. */
  2545. txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
  2546. ew32(TXDCTL(0), txdctl);
  2547. }
  2548. /* erratum work around: set txdctl the same for both queues */
  2549. ew32(TXDCTL(1), er32(TXDCTL(0)));
  2550. /* Program the Transmit Control Register */
  2551. tctl = er32(TCTL);
  2552. tctl &= ~E1000_TCTL_CT;
  2553. tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
  2554. (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
  2555. if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
  2556. tarc = er32(TARC(0));
  2557. /* set the speed mode bit, we'll clear it if we're not at
  2558. * gigabit link later
  2559. */
  2560. #define SPEED_MODE_BIT BIT(21)
  2561. tarc |= SPEED_MODE_BIT;
  2562. ew32(TARC(0), tarc);
  2563. }
  2564. /* errata: program both queues to unweighted RR */
  2565. if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
  2566. tarc = er32(TARC(0));
  2567. tarc |= 1;
  2568. ew32(TARC(0), tarc);
  2569. tarc = er32(TARC(1));
  2570. tarc |= 1;
  2571. ew32(TARC(1), tarc);
  2572. }
  2573. /* Setup Transmit Descriptor Settings for eop descriptor */
  2574. adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
  2575. /* only set IDE if we are delaying interrupts using the timers */
  2576. if (adapter->tx_int_delay)
  2577. adapter->txd_cmd |= E1000_TXD_CMD_IDE;
  2578. /* enable Report Status bit */
  2579. adapter->txd_cmd |= E1000_TXD_CMD_RS;
  2580. ew32(TCTL, tctl);
  2581. hw->mac.ops.config_collision_dist(hw);
  2582. /* SPT and KBL Si errata workaround to avoid data corruption */
  2583. if (hw->mac.type == e1000_pch_spt) {
  2584. u32 reg_val;
  2585. reg_val = er32(IOSFPC);
  2586. reg_val |= E1000_RCTL_RDMTS_HEX;
  2587. ew32(IOSFPC, reg_val);
  2588. reg_val = er32(TARC(0));
  2589. /* SPT and KBL Si errata workaround to avoid Tx hang.
  2590. * Dropping the number of outstanding requests from
  2591. * 3 to 2 in order to avoid a buffer overrun.
  2592. */
  2593. reg_val &= ~E1000_TARC0_CB_MULTIQ_3_REQ;
  2594. reg_val |= E1000_TARC0_CB_MULTIQ_2_REQ;
  2595. ew32(TARC(0), reg_val);
  2596. }
  2597. }
  2598. /**
  2599. * e1000_setup_rctl - configure the receive control registers
  2600. * @adapter: Board private structure
  2601. **/
  2602. #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
  2603. (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
  2604. static void e1000_setup_rctl(struct e1000_adapter *adapter)
  2605. {
  2606. struct e1000_hw *hw = &adapter->hw;
  2607. u32 rctl, rfctl;
  2608. u32 pages = 0;
  2609. /* Workaround Si errata on PCHx - configure jumbo frame flow.
  2610. * If jumbo frames not set, program related MAC/PHY registers
  2611. * to h/w defaults
  2612. */
  2613. if (hw->mac.type >= e1000_pch2lan) {
  2614. s32 ret_val;
  2615. if (adapter->netdev->mtu > ETH_DATA_LEN)
  2616. ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
  2617. else
  2618. ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
  2619. if (ret_val)
  2620. e_dbg("failed to enable|disable jumbo frame workaround mode\n");
  2621. }
  2622. /* Program MC offset vector base */
  2623. rctl = er32(RCTL);
  2624. rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
  2625. rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
  2626. E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
  2627. (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
  2628. /* Do not Store bad packets */
  2629. rctl &= ~E1000_RCTL_SBP;
  2630. /* Enable Long Packet receive */
  2631. if (adapter->netdev->mtu <= ETH_DATA_LEN)
  2632. rctl &= ~E1000_RCTL_LPE;
  2633. else
  2634. rctl |= E1000_RCTL_LPE;
  2635. /* Some systems expect that the CRC is included in SMBUS traffic. The
  2636. * hardware strips the CRC before sending to both SMBUS (BMC) and to
  2637. * host memory when this is enabled
  2638. */
  2639. if (adapter->flags2 & FLAG2_CRC_STRIPPING)
  2640. rctl |= E1000_RCTL_SECRC;
  2641. /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
  2642. if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
  2643. u16 phy_data;
  2644. e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
  2645. phy_data &= 0xfff8;
  2646. phy_data |= BIT(2);
  2647. e1e_wphy(hw, PHY_REG(770, 26), phy_data);
  2648. e1e_rphy(hw, 22, &phy_data);
  2649. phy_data &= 0x0fff;
  2650. phy_data |= BIT(14);
  2651. e1e_wphy(hw, 0x10, 0x2823);
  2652. e1e_wphy(hw, 0x11, 0x0003);
  2653. e1e_wphy(hw, 22, phy_data);
  2654. }
  2655. /* Setup buffer sizes */
  2656. rctl &= ~E1000_RCTL_SZ_4096;
  2657. rctl |= E1000_RCTL_BSEX;
  2658. switch (adapter->rx_buffer_len) {
  2659. case 2048:
  2660. default:
  2661. rctl |= E1000_RCTL_SZ_2048;
  2662. rctl &= ~E1000_RCTL_BSEX;
  2663. break;
  2664. case 4096:
  2665. rctl |= E1000_RCTL_SZ_4096;
  2666. break;
  2667. case 8192:
  2668. rctl |= E1000_RCTL_SZ_8192;
  2669. break;
  2670. case 16384:
  2671. rctl |= E1000_RCTL_SZ_16384;
  2672. break;
  2673. }
  2674. /* Enable Extended Status in all Receive Descriptors */
  2675. rfctl = er32(RFCTL);
  2676. rfctl |= E1000_RFCTL_EXTEN;
  2677. ew32(RFCTL, rfctl);
  2678. /* 82571 and greater support packet-split where the protocol
  2679. * header is placed in skb->data and the packet data is
  2680. * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
  2681. * In the case of a non-split, skb->data is linearly filled,
  2682. * followed by the page buffers. Therefore, skb->data is
  2683. * sized to hold the largest protocol header.
  2684. *
  2685. * allocations using alloc_page take too long for regular MTU
  2686. * so only enable packet split for jumbo frames
  2687. *
  2688. * Using pages when the page size is greater than 16k wastes
  2689. * a lot of memory, since we allocate 3 pages at all times
  2690. * per packet.
  2691. */
  2692. pages = PAGE_USE_COUNT(adapter->netdev->mtu);
  2693. if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
  2694. adapter->rx_ps_pages = pages;
  2695. else
  2696. adapter->rx_ps_pages = 0;
  2697. if (adapter->rx_ps_pages) {
  2698. u32 psrctl = 0;
  2699. /* Enable Packet split descriptors */
  2700. rctl |= E1000_RCTL_DTYP_PS;
  2701. psrctl |= adapter->rx_ps_bsize0 >> E1000_PSRCTL_BSIZE0_SHIFT;
  2702. switch (adapter->rx_ps_pages) {
  2703. case 3:
  2704. psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE3_SHIFT;
  2705. /* fall-through */
  2706. case 2:
  2707. psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE2_SHIFT;
  2708. /* fall-through */
  2709. case 1:
  2710. psrctl |= PAGE_SIZE >> E1000_PSRCTL_BSIZE1_SHIFT;
  2711. break;
  2712. }
  2713. ew32(PSRCTL, psrctl);
  2714. }
  2715. /* This is useful for sniffing bad packets. */
  2716. if (adapter->netdev->features & NETIF_F_RXALL) {
  2717. /* UPE and MPE will be handled by normal PROMISC logic
  2718. * in e1000e_set_rx_mode
  2719. */
  2720. rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
  2721. E1000_RCTL_BAM | /* RX All Bcast Pkts */
  2722. E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
  2723. rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
  2724. E1000_RCTL_DPF | /* Allow filtered pause */
  2725. E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
  2726. /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
  2727. * and that breaks VLANs.
  2728. */
  2729. }
  2730. ew32(RCTL, rctl);
  2731. /* just started the receive unit, no need to restart */
  2732. adapter->flags &= ~FLAG_RESTART_NOW;
  2733. }
  2734. /**
  2735. * e1000_configure_rx - Configure Receive Unit after Reset
  2736. * @adapter: board private structure
  2737. *
  2738. * Configure the Rx unit of the MAC after a reset.
  2739. **/
  2740. static void e1000_configure_rx(struct e1000_adapter *adapter)
  2741. {
  2742. struct e1000_hw *hw = &adapter->hw;
  2743. struct e1000_ring *rx_ring = adapter->rx_ring;
  2744. u64 rdba;
  2745. u32 rdlen, rctl, rxcsum, ctrl_ext;
  2746. if (adapter->rx_ps_pages) {
  2747. /* this is a 32 byte descriptor */
  2748. rdlen = rx_ring->count *
  2749. sizeof(union e1000_rx_desc_packet_split);
  2750. adapter->clean_rx = e1000_clean_rx_irq_ps;
  2751. adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
  2752. } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
  2753. rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
  2754. adapter->clean_rx = e1000_clean_jumbo_rx_irq;
  2755. adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
  2756. } else {
  2757. rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
  2758. adapter->clean_rx = e1000_clean_rx_irq;
  2759. adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
  2760. }
  2761. /* disable receives while setting up the descriptors */
  2762. rctl = er32(RCTL);
  2763. if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
  2764. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  2765. e1e_flush();
  2766. usleep_range(10000, 20000);
  2767. if (adapter->flags2 & FLAG2_DMA_BURST) {
  2768. /* set the writeback threshold (only takes effect if the RDTR
  2769. * is set). set GRAN=1 and write back up to 0x4 worth, and
  2770. * enable prefetching of 0x20 Rx descriptors
  2771. * granularity = 01
  2772. * wthresh = 04,
  2773. * hthresh = 04,
  2774. * pthresh = 0x20
  2775. */
  2776. ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
  2777. ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
  2778. }
  2779. /* set the Receive Delay Timer Register */
  2780. ew32(RDTR, adapter->rx_int_delay);
  2781. /* irq moderation */
  2782. ew32(RADV, adapter->rx_abs_int_delay);
  2783. if ((adapter->itr_setting != 0) && (adapter->itr != 0))
  2784. e1000e_write_itr(adapter, adapter->itr);
  2785. ctrl_ext = er32(CTRL_EXT);
  2786. /* Auto-Mask interrupts upon ICR access */
  2787. ctrl_ext |= E1000_CTRL_EXT_IAME;
  2788. ew32(IAM, 0xffffffff);
  2789. ew32(CTRL_EXT, ctrl_ext);
  2790. e1e_flush();
  2791. /* Setup the HW Rx Head and Tail Descriptor Pointers and
  2792. * the Base and Length of the Rx Descriptor Ring
  2793. */
  2794. rdba = rx_ring->dma;
  2795. ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
  2796. ew32(RDBAH(0), (rdba >> 32));
  2797. ew32(RDLEN(0), rdlen);
  2798. ew32(RDH(0), 0);
  2799. ew32(RDT(0), 0);
  2800. rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
  2801. rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
  2802. writel(0, rx_ring->head);
  2803. if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
  2804. e1000e_update_rdt_wa(rx_ring, 0);
  2805. else
  2806. writel(0, rx_ring->tail);
  2807. /* Enable Receive Checksum Offload for TCP and UDP */
  2808. rxcsum = er32(RXCSUM);
  2809. if (adapter->netdev->features & NETIF_F_RXCSUM)
  2810. rxcsum |= E1000_RXCSUM_TUOFL;
  2811. else
  2812. rxcsum &= ~E1000_RXCSUM_TUOFL;
  2813. ew32(RXCSUM, rxcsum);
  2814. /* With jumbo frames, excessive C-state transition latencies result
  2815. * in dropped transactions.
  2816. */
  2817. if (adapter->netdev->mtu > ETH_DATA_LEN) {
  2818. u32 lat =
  2819. ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
  2820. adapter->max_frame_size) * 8 / 1000;
  2821. if (adapter->flags & FLAG_IS_ICH) {
  2822. u32 rxdctl = er32(RXDCTL(0));
  2823. ew32(RXDCTL(0), rxdctl | 0x3 | BIT(8));
  2824. }
  2825. dev_info(&adapter->pdev->dev,
  2826. "Some CPU C-states have been disabled in order to enable jumbo frames\n");
  2827. pm_qos_update_request(&adapter->pm_qos_req, lat);
  2828. } else {
  2829. pm_qos_update_request(&adapter->pm_qos_req,
  2830. PM_QOS_DEFAULT_VALUE);
  2831. }
  2832. /* Enable Receives */
  2833. ew32(RCTL, rctl);
  2834. }
  2835. /**
  2836. * e1000e_write_mc_addr_list - write multicast addresses to MTA
  2837. * @netdev: network interface device structure
  2838. *
  2839. * Writes multicast address list to the MTA hash table.
  2840. * Returns: -ENOMEM on failure
  2841. * 0 on no addresses written
  2842. * X on writing X addresses to MTA
  2843. */
  2844. static int e1000e_write_mc_addr_list(struct net_device *netdev)
  2845. {
  2846. struct e1000_adapter *adapter = netdev_priv(netdev);
  2847. struct e1000_hw *hw = &adapter->hw;
  2848. struct netdev_hw_addr *ha;
  2849. u8 *mta_list;
  2850. int i;
  2851. if (netdev_mc_empty(netdev)) {
  2852. /* nothing to program, so clear mc list */
  2853. hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
  2854. return 0;
  2855. }
  2856. mta_list = kcalloc(netdev_mc_count(netdev), ETH_ALEN, GFP_ATOMIC);
  2857. if (!mta_list)
  2858. return -ENOMEM;
  2859. /* update_mc_addr_list expects a packed array of only addresses. */
  2860. i = 0;
  2861. netdev_for_each_mc_addr(ha, netdev)
  2862. memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
  2863. hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
  2864. kfree(mta_list);
  2865. return netdev_mc_count(netdev);
  2866. }
  2867. /**
  2868. * e1000e_write_uc_addr_list - write unicast addresses to RAR table
  2869. * @netdev: network interface device structure
  2870. *
  2871. * Writes unicast address list to the RAR table.
  2872. * Returns: -ENOMEM on failure/insufficient address space
  2873. * 0 on no addresses written
  2874. * X on writing X addresses to the RAR table
  2875. **/
  2876. static int e1000e_write_uc_addr_list(struct net_device *netdev)
  2877. {
  2878. struct e1000_adapter *adapter = netdev_priv(netdev);
  2879. struct e1000_hw *hw = &adapter->hw;
  2880. unsigned int rar_entries;
  2881. int count = 0;
  2882. rar_entries = hw->mac.ops.rar_get_count(hw);
  2883. /* save a rar entry for our hardware address */
  2884. rar_entries--;
  2885. /* save a rar entry for the LAA workaround */
  2886. if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
  2887. rar_entries--;
  2888. /* return ENOMEM indicating insufficient memory for addresses */
  2889. if (netdev_uc_count(netdev) > rar_entries)
  2890. return -ENOMEM;
  2891. if (!netdev_uc_empty(netdev) && rar_entries) {
  2892. struct netdev_hw_addr *ha;
  2893. /* write the addresses in reverse order to avoid write
  2894. * combining
  2895. */
  2896. netdev_for_each_uc_addr(ha, netdev) {
  2897. int ret_val;
  2898. if (!rar_entries)
  2899. break;
  2900. ret_val = hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
  2901. if (ret_val < 0)
  2902. return -ENOMEM;
  2903. count++;
  2904. }
  2905. }
  2906. /* zero out the remaining RAR entries not used above */
  2907. for (; rar_entries > 0; rar_entries--) {
  2908. ew32(RAH(rar_entries), 0);
  2909. ew32(RAL(rar_entries), 0);
  2910. }
  2911. e1e_flush();
  2912. return count;
  2913. }
  2914. /**
  2915. * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
  2916. * @netdev: network interface device structure
  2917. *
  2918. * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
  2919. * address list or the network interface flags are updated. This routine is
  2920. * responsible for configuring the hardware for proper unicast, multicast,
  2921. * promiscuous mode, and all-multi behavior.
  2922. **/
  2923. static void e1000e_set_rx_mode(struct net_device *netdev)
  2924. {
  2925. struct e1000_adapter *adapter = netdev_priv(netdev);
  2926. struct e1000_hw *hw = &adapter->hw;
  2927. u32 rctl;
  2928. if (pm_runtime_suspended(netdev->dev.parent))
  2929. return;
  2930. /* Check for Promiscuous and All Multicast modes */
  2931. rctl = er32(RCTL);
  2932. /* clear the affected bits */
  2933. rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
  2934. if (netdev->flags & IFF_PROMISC) {
  2935. rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
  2936. /* Do not hardware filter VLANs in promisc mode */
  2937. e1000e_vlan_filter_disable(adapter);
  2938. } else {
  2939. int count;
  2940. if (netdev->flags & IFF_ALLMULTI) {
  2941. rctl |= E1000_RCTL_MPE;
  2942. } else {
  2943. /* Write addresses to the MTA, if the attempt fails
  2944. * then we should just turn on promiscuous mode so
  2945. * that we can at least receive multicast traffic
  2946. */
  2947. count = e1000e_write_mc_addr_list(netdev);
  2948. if (count < 0)
  2949. rctl |= E1000_RCTL_MPE;
  2950. }
  2951. e1000e_vlan_filter_enable(adapter);
  2952. /* Write addresses to available RAR registers, if there is not
  2953. * sufficient space to store all the addresses then enable
  2954. * unicast promiscuous mode
  2955. */
  2956. count = e1000e_write_uc_addr_list(netdev);
  2957. if (count < 0)
  2958. rctl |= E1000_RCTL_UPE;
  2959. }
  2960. ew32(RCTL, rctl);
  2961. if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
  2962. e1000e_vlan_strip_enable(adapter);
  2963. else
  2964. e1000e_vlan_strip_disable(adapter);
  2965. }
  2966. static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
  2967. {
  2968. struct e1000_hw *hw = &adapter->hw;
  2969. u32 mrqc, rxcsum;
  2970. u32 rss_key[10];
  2971. int i;
  2972. netdev_rss_key_fill(rss_key, sizeof(rss_key));
  2973. for (i = 0; i < 10; i++)
  2974. ew32(RSSRK(i), rss_key[i]);
  2975. /* Direct all traffic to queue 0 */
  2976. for (i = 0; i < 32; i++)
  2977. ew32(RETA(i), 0);
  2978. /* Disable raw packet checksumming so that RSS hash is placed in
  2979. * descriptor on writeback.
  2980. */
  2981. rxcsum = er32(RXCSUM);
  2982. rxcsum |= E1000_RXCSUM_PCSD;
  2983. ew32(RXCSUM, rxcsum);
  2984. mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
  2985. E1000_MRQC_RSS_FIELD_IPV4_TCP |
  2986. E1000_MRQC_RSS_FIELD_IPV6 |
  2987. E1000_MRQC_RSS_FIELD_IPV6_TCP |
  2988. E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
  2989. ew32(MRQC, mrqc);
  2990. }
  2991. /**
  2992. * e1000e_get_base_timinca - get default SYSTIM time increment attributes
  2993. * @adapter: board private structure
  2994. * @timinca: pointer to returned time increment attributes
  2995. *
  2996. * Get attributes for incrementing the System Time Register SYSTIML/H at
  2997. * the default base frequency, and set the cyclecounter shift value.
  2998. **/
  2999. s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
  3000. {
  3001. struct e1000_hw *hw = &adapter->hw;
  3002. u32 incvalue, incperiod, shift;
  3003. /* Make sure clock is enabled on I217/I218/I219 before checking
  3004. * the frequency
  3005. */
  3006. if ((hw->mac.type >= e1000_pch_lpt) &&
  3007. !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
  3008. !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
  3009. u32 fextnvm7 = er32(FEXTNVM7);
  3010. if (!(fextnvm7 & BIT(0))) {
  3011. ew32(FEXTNVM7, fextnvm7 | BIT(0));
  3012. e1e_flush();
  3013. }
  3014. }
  3015. switch (hw->mac.type) {
  3016. case e1000_pch2lan:
  3017. /* Stable 96MHz frequency */
  3018. incperiod = INCPERIOD_96MHZ;
  3019. incvalue = INCVALUE_96MHZ;
  3020. shift = INCVALUE_SHIFT_96MHZ;
  3021. adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
  3022. break;
  3023. case e1000_pch_lpt:
  3024. if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) {
  3025. /* Stable 96MHz frequency */
  3026. incperiod = INCPERIOD_96MHZ;
  3027. incvalue = INCVALUE_96MHZ;
  3028. shift = INCVALUE_SHIFT_96MHZ;
  3029. adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
  3030. } else {
  3031. /* Stable 25MHz frequency */
  3032. incperiod = INCPERIOD_25MHZ;
  3033. incvalue = INCVALUE_25MHZ;
  3034. shift = INCVALUE_SHIFT_25MHZ;
  3035. adapter->cc.shift = shift;
  3036. }
  3037. break;
  3038. case e1000_pch_spt:
  3039. /* Stable 24MHz frequency */
  3040. incperiod = INCPERIOD_24MHZ;
  3041. incvalue = INCVALUE_24MHZ;
  3042. shift = INCVALUE_SHIFT_24MHZ;
  3043. adapter->cc.shift = shift;
  3044. break;
  3045. case e1000_pch_cnp:
  3046. if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) {
  3047. /* Stable 24MHz frequency */
  3048. incperiod = INCPERIOD_24MHZ;
  3049. incvalue = INCVALUE_24MHZ;
  3050. shift = INCVALUE_SHIFT_24MHZ;
  3051. adapter->cc.shift = shift;
  3052. } else {
  3053. /* Stable 38400KHz frequency */
  3054. incperiod = INCPERIOD_38400KHZ;
  3055. incvalue = INCVALUE_38400KHZ;
  3056. shift = INCVALUE_SHIFT_38400KHZ;
  3057. adapter->cc.shift = shift;
  3058. }
  3059. break;
  3060. case e1000_82574:
  3061. case e1000_82583:
  3062. /* Stable 25MHz frequency */
  3063. incperiod = INCPERIOD_25MHZ;
  3064. incvalue = INCVALUE_25MHZ;
  3065. shift = INCVALUE_SHIFT_25MHZ;
  3066. adapter->cc.shift = shift;
  3067. break;
  3068. default:
  3069. return -EINVAL;
  3070. }
  3071. *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
  3072. ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
  3073. return 0;
  3074. }
  3075. /**
  3076. * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
  3077. * @adapter: board private structure
  3078. *
  3079. * Outgoing time stamping can be enabled and disabled. Play nice and
  3080. * disable it when requested, although it shouldn't cause any overhead
  3081. * when no packet needs it. At most one packet in the queue may be
  3082. * marked for time stamping, otherwise it would be impossible to tell
  3083. * for sure to which packet the hardware time stamp belongs.
  3084. *
  3085. * Incoming time stamping has to be configured via the hardware filters.
  3086. * Not all combinations are supported, in particular event type has to be
  3087. * specified. Matching the kind of event packet is not supported, with the
  3088. * exception of "all V2 events regardless of level 2 or 4".
  3089. **/
  3090. static int e1000e_config_hwtstamp(struct e1000_adapter *adapter,
  3091. struct hwtstamp_config *config)
  3092. {
  3093. struct e1000_hw *hw = &adapter->hw;
  3094. u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
  3095. u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
  3096. u32 rxmtrl = 0;
  3097. u16 rxudp = 0;
  3098. bool is_l4 = false;
  3099. bool is_l2 = false;
  3100. u32 regval;
  3101. if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
  3102. return -EINVAL;
  3103. /* flags reserved for future extensions - must be zero */
  3104. if (config->flags)
  3105. return -EINVAL;
  3106. switch (config->tx_type) {
  3107. case HWTSTAMP_TX_OFF:
  3108. tsync_tx_ctl = 0;
  3109. break;
  3110. case HWTSTAMP_TX_ON:
  3111. break;
  3112. default:
  3113. return -ERANGE;
  3114. }
  3115. switch (config->rx_filter) {
  3116. case HWTSTAMP_FILTER_NONE:
  3117. tsync_rx_ctl = 0;
  3118. break;
  3119. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  3120. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
  3121. rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
  3122. is_l4 = true;
  3123. break;
  3124. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  3125. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
  3126. rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
  3127. is_l4 = true;
  3128. break;
  3129. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  3130. /* Also time stamps V2 L2 Path Delay Request/Response */
  3131. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
  3132. rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
  3133. is_l2 = true;
  3134. break;
  3135. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  3136. /* Also time stamps V2 L2 Path Delay Request/Response. */
  3137. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
  3138. rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
  3139. is_l2 = true;
  3140. break;
  3141. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  3142. /* Hardware cannot filter just V2 L4 Sync messages;
  3143. * fall-through to V2 (both L2 and L4) Sync.
  3144. */
  3145. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  3146. /* Also time stamps V2 Path Delay Request/Response. */
  3147. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
  3148. rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
  3149. is_l2 = true;
  3150. is_l4 = true;
  3151. break;
  3152. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  3153. /* Hardware cannot filter just V2 L4 Delay Request messages;
  3154. * fall-through to V2 (both L2 and L4) Delay Request.
  3155. */
  3156. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  3157. /* Also time stamps V2 Path Delay Request/Response. */
  3158. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
  3159. rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
  3160. is_l2 = true;
  3161. is_l4 = true;
  3162. break;
  3163. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  3164. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  3165. /* Hardware cannot filter just V2 L4 or L2 Event messages;
  3166. * fall-through to all V2 (both L2 and L4) Events.
  3167. */
  3168. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  3169. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
  3170. config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  3171. is_l2 = true;
  3172. is_l4 = true;
  3173. break;
  3174. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  3175. /* For V1, the hardware can only filter Sync messages or
  3176. * Delay Request messages but not both so fall-through to
  3177. * time stamp all packets.
  3178. */
  3179. case HWTSTAMP_FILTER_NTP_ALL:
  3180. case HWTSTAMP_FILTER_ALL:
  3181. is_l2 = true;
  3182. is_l4 = true;
  3183. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
  3184. config->rx_filter = HWTSTAMP_FILTER_ALL;
  3185. break;
  3186. default:
  3187. return -ERANGE;
  3188. }
  3189. adapter->hwtstamp_config = *config;
  3190. /* enable/disable Tx h/w time stamping */
  3191. regval = er32(TSYNCTXCTL);
  3192. regval &= ~E1000_TSYNCTXCTL_ENABLED;
  3193. regval |= tsync_tx_ctl;
  3194. ew32(TSYNCTXCTL, regval);
  3195. if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
  3196. (regval & E1000_TSYNCTXCTL_ENABLED)) {
  3197. e_err("Timesync Tx Control register not set as expected\n");
  3198. return -EAGAIN;
  3199. }
  3200. /* enable/disable Rx h/w time stamping */
  3201. regval = er32(TSYNCRXCTL);
  3202. regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
  3203. regval |= tsync_rx_ctl;
  3204. ew32(TSYNCRXCTL, regval);
  3205. if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
  3206. E1000_TSYNCRXCTL_TYPE_MASK)) !=
  3207. (regval & (E1000_TSYNCRXCTL_ENABLED |
  3208. E1000_TSYNCRXCTL_TYPE_MASK))) {
  3209. e_err("Timesync Rx Control register not set as expected\n");
  3210. return -EAGAIN;
  3211. }
  3212. /* L2: define ethertype filter for time stamped packets */
  3213. if (is_l2)
  3214. rxmtrl |= ETH_P_1588;
  3215. /* define which PTP packets get time stamped */
  3216. ew32(RXMTRL, rxmtrl);
  3217. /* Filter by destination port */
  3218. if (is_l4) {
  3219. rxudp = PTP_EV_PORT;
  3220. cpu_to_be16s(&rxudp);
  3221. }
  3222. ew32(RXUDP, rxudp);
  3223. e1e_flush();
  3224. /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
  3225. er32(RXSTMPH);
  3226. er32(TXSTMPH);
  3227. return 0;
  3228. }
  3229. /**
  3230. * e1000_configure - configure the hardware for Rx and Tx
  3231. * @adapter: private board structure
  3232. **/
  3233. static void e1000_configure(struct e1000_adapter *adapter)
  3234. {
  3235. struct e1000_ring *rx_ring = adapter->rx_ring;
  3236. e1000e_set_rx_mode(adapter->netdev);
  3237. e1000_restore_vlan(adapter);
  3238. e1000_init_manageability_pt(adapter);
  3239. e1000_configure_tx(adapter);
  3240. if (adapter->netdev->features & NETIF_F_RXHASH)
  3241. e1000e_setup_rss_hash(adapter);
  3242. e1000_setup_rctl(adapter);
  3243. e1000_configure_rx(adapter);
  3244. adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
  3245. }
  3246. /**
  3247. * e1000e_power_up_phy - restore link in case the phy was powered down
  3248. * @adapter: address of board private structure
  3249. *
  3250. * The phy may be powered down to save power and turn off link when the
  3251. * driver is unloaded and wake on lan is not enabled (among others)
  3252. * *** this routine MUST be followed by a call to e1000e_reset ***
  3253. **/
  3254. void e1000e_power_up_phy(struct e1000_adapter *adapter)
  3255. {
  3256. if (adapter->hw.phy.ops.power_up)
  3257. adapter->hw.phy.ops.power_up(&adapter->hw);
  3258. adapter->hw.mac.ops.setup_link(&adapter->hw);
  3259. }
  3260. /**
  3261. * e1000_power_down_phy - Power down the PHY
  3262. *
  3263. * Power down the PHY so no link is implied when interface is down.
  3264. * The PHY cannot be powered down if management or WoL is active.
  3265. */
  3266. static void e1000_power_down_phy(struct e1000_adapter *adapter)
  3267. {
  3268. if (adapter->hw.phy.ops.power_down)
  3269. adapter->hw.phy.ops.power_down(&adapter->hw);
  3270. }
  3271. /**
  3272. * e1000_flush_tx_ring - remove all descriptors from the tx_ring
  3273. *
  3274. * We want to clear all pending descriptors from the TX ring.
  3275. * zeroing happens when the HW reads the regs. We assign the ring itself as
  3276. * the data of the next descriptor. We don't care about the data we are about
  3277. * to reset the HW.
  3278. */
  3279. static void e1000_flush_tx_ring(struct e1000_adapter *adapter)
  3280. {
  3281. struct e1000_hw *hw = &adapter->hw;
  3282. struct e1000_ring *tx_ring = adapter->tx_ring;
  3283. struct e1000_tx_desc *tx_desc = NULL;
  3284. u32 tdt, tctl, txd_lower = E1000_TXD_CMD_IFCS;
  3285. u16 size = 512;
  3286. tctl = er32(TCTL);
  3287. ew32(TCTL, tctl | E1000_TCTL_EN);
  3288. tdt = er32(TDT(0));
  3289. BUG_ON(tdt != tx_ring->next_to_use);
  3290. tx_desc = E1000_TX_DESC(*tx_ring, tx_ring->next_to_use);
  3291. tx_desc->buffer_addr = tx_ring->dma;
  3292. tx_desc->lower.data = cpu_to_le32(txd_lower | size);
  3293. tx_desc->upper.data = 0;
  3294. /* flush descriptors to memory before notifying the HW */
  3295. wmb();
  3296. tx_ring->next_to_use++;
  3297. if (tx_ring->next_to_use == tx_ring->count)
  3298. tx_ring->next_to_use = 0;
  3299. ew32(TDT(0), tx_ring->next_to_use);
  3300. mmiowb();
  3301. usleep_range(200, 250);
  3302. }
  3303. /**
  3304. * e1000_flush_rx_ring - remove all descriptors from the rx_ring
  3305. *
  3306. * Mark all descriptors in the RX ring as consumed and disable the rx ring
  3307. */
  3308. static void e1000_flush_rx_ring(struct e1000_adapter *adapter)
  3309. {
  3310. u32 rctl, rxdctl;
  3311. struct e1000_hw *hw = &adapter->hw;
  3312. rctl = er32(RCTL);
  3313. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  3314. e1e_flush();
  3315. usleep_range(100, 150);
  3316. rxdctl = er32(RXDCTL(0));
  3317. /* zero the lower 14 bits (prefetch and host thresholds) */
  3318. rxdctl &= 0xffffc000;
  3319. /* update thresholds: prefetch threshold to 31, host threshold to 1
  3320. * and make sure the granularity is "descriptors" and not "cache lines"
  3321. */
  3322. rxdctl |= (0x1F | BIT(8) | E1000_RXDCTL_THRESH_UNIT_DESC);
  3323. ew32(RXDCTL(0), rxdctl);
  3324. /* momentarily enable the RX ring for the changes to take effect */
  3325. ew32(RCTL, rctl | E1000_RCTL_EN);
  3326. e1e_flush();
  3327. usleep_range(100, 150);
  3328. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  3329. }
  3330. /**
  3331. * e1000_flush_desc_rings - remove all descriptors from the descriptor rings
  3332. *
  3333. * In i219, the descriptor rings must be emptied before resetting the HW
  3334. * or before changing the device state to D3 during runtime (runtime PM).
  3335. *
  3336. * Failure to do this will cause the HW to enter a unit hang state which can
  3337. * only be released by PCI reset on the device
  3338. *
  3339. */
  3340. static void e1000_flush_desc_rings(struct e1000_adapter *adapter)
  3341. {
  3342. u16 hang_state;
  3343. u32 fext_nvm11, tdlen;
  3344. struct e1000_hw *hw = &adapter->hw;
  3345. /* First, disable MULR fix in FEXTNVM11 */
  3346. fext_nvm11 = er32(FEXTNVM11);
  3347. fext_nvm11 |= E1000_FEXTNVM11_DISABLE_MULR_FIX;
  3348. ew32(FEXTNVM11, fext_nvm11);
  3349. /* do nothing if we're not in faulty state, or if the queue is empty */
  3350. tdlen = er32(TDLEN(0));
  3351. pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS,
  3352. &hang_state);
  3353. if (!(hang_state & FLUSH_DESC_REQUIRED) || !tdlen)
  3354. return;
  3355. e1000_flush_tx_ring(adapter);
  3356. /* recheck, maybe the fault is caused by the rx ring */
  3357. pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS,
  3358. &hang_state);
  3359. if (hang_state & FLUSH_DESC_REQUIRED)
  3360. e1000_flush_rx_ring(adapter);
  3361. }
  3362. /**
  3363. * e1000e_systim_reset - reset the timesync registers after a hardware reset
  3364. * @adapter: board private structure
  3365. *
  3366. * When the MAC is reset, all hardware bits for timesync will be reset to the
  3367. * default values. This function will restore the settings last in place.
  3368. * Since the clock SYSTIME registers are reset, we will simply restore the
  3369. * cyclecounter to the kernel real clock time.
  3370. **/
  3371. static void e1000e_systim_reset(struct e1000_adapter *adapter)
  3372. {
  3373. struct ptp_clock_info *info = &adapter->ptp_clock_info;
  3374. struct e1000_hw *hw = &adapter->hw;
  3375. unsigned long flags;
  3376. u32 timinca;
  3377. s32 ret_val;
  3378. if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
  3379. return;
  3380. if (info->adjfreq) {
  3381. /* restore the previous ptp frequency delta */
  3382. ret_val = info->adjfreq(info, adapter->ptp_delta);
  3383. } else {
  3384. /* set the default base frequency if no adjustment possible */
  3385. ret_val = e1000e_get_base_timinca(adapter, &timinca);
  3386. if (!ret_val)
  3387. ew32(TIMINCA, timinca);
  3388. }
  3389. if (ret_val) {
  3390. dev_warn(&adapter->pdev->dev,
  3391. "Failed to restore TIMINCA clock rate delta: %d\n",
  3392. ret_val);
  3393. return;
  3394. }
  3395. /* reset the systim ns time counter */
  3396. spin_lock_irqsave(&adapter->systim_lock, flags);
  3397. timecounter_init(&adapter->tc, &adapter->cc,
  3398. ktime_to_ns(ktime_get_real()));
  3399. spin_unlock_irqrestore(&adapter->systim_lock, flags);
  3400. /* restore the previous hwtstamp configuration settings */
  3401. e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config);
  3402. }
  3403. /**
  3404. * e1000e_reset - bring the hardware into a known good state
  3405. *
  3406. * This function boots the hardware and enables some settings that
  3407. * require a configuration cycle of the hardware - those cannot be
  3408. * set/changed during runtime. After reset the device needs to be
  3409. * properly configured for Rx, Tx etc.
  3410. */
  3411. void e1000e_reset(struct e1000_adapter *adapter)
  3412. {
  3413. struct e1000_mac_info *mac = &adapter->hw.mac;
  3414. struct e1000_fc_info *fc = &adapter->hw.fc;
  3415. struct e1000_hw *hw = &adapter->hw;
  3416. u32 tx_space, min_tx_space, min_rx_space;
  3417. u32 pba = adapter->pba;
  3418. u16 hwm;
  3419. /* reset Packet Buffer Allocation to default */
  3420. ew32(PBA, pba);
  3421. if (adapter->max_frame_size > (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)) {
  3422. /* To maintain wire speed transmits, the Tx FIFO should be
  3423. * large enough to accommodate two full transmit packets,
  3424. * rounded up to the next 1KB and expressed in KB. Likewise,
  3425. * the Rx FIFO should be large enough to accommodate at least
  3426. * one full receive packet and is similarly rounded up and
  3427. * expressed in KB.
  3428. */
  3429. pba = er32(PBA);
  3430. /* upper 16 bits has Tx packet buffer allocation size in KB */
  3431. tx_space = pba >> 16;
  3432. /* lower 16 bits has Rx packet buffer allocation size in KB */
  3433. pba &= 0xffff;
  3434. /* the Tx fifo also stores 16 bytes of information about the Tx
  3435. * but don't include ethernet FCS because hardware appends it
  3436. */
  3437. min_tx_space = (adapter->max_frame_size +
  3438. sizeof(struct e1000_tx_desc) - ETH_FCS_LEN) * 2;
  3439. min_tx_space = ALIGN(min_tx_space, 1024);
  3440. min_tx_space >>= 10;
  3441. /* software strips receive CRC, so leave room for it */
  3442. min_rx_space = adapter->max_frame_size;
  3443. min_rx_space = ALIGN(min_rx_space, 1024);
  3444. min_rx_space >>= 10;
  3445. /* If current Tx allocation is less than the min Tx FIFO size,
  3446. * and the min Tx FIFO size is less than the current Rx FIFO
  3447. * allocation, take space away from current Rx allocation
  3448. */
  3449. if ((tx_space < min_tx_space) &&
  3450. ((min_tx_space - tx_space) < pba)) {
  3451. pba -= min_tx_space - tx_space;
  3452. /* if short on Rx space, Rx wins and must trump Tx
  3453. * adjustment
  3454. */
  3455. if (pba < min_rx_space)
  3456. pba = min_rx_space;
  3457. }
  3458. ew32(PBA, pba);
  3459. }
  3460. /* flow control settings
  3461. *
  3462. * The high water mark must be low enough to fit one full frame
  3463. * (or the size used for early receive) above it in the Rx FIFO.
  3464. * Set it to the lower of:
  3465. * - 90% of the Rx FIFO size, and
  3466. * - the full Rx FIFO size minus one full frame
  3467. */
  3468. if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
  3469. fc->pause_time = 0xFFFF;
  3470. else
  3471. fc->pause_time = E1000_FC_PAUSE_TIME;
  3472. fc->send_xon = true;
  3473. fc->current_mode = fc->requested_mode;
  3474. switch (hw->mac.type) {
  3475. case e1000_ich9lan:
  3476. case e1000_ich10lan:
  3477. if (adapter->netdev->mtu > ETH_DATA_LEN) {
  3478. pba = 14;
  3479. ew32(PBA, pba);
  3480. fc->high_water = 0x2800;
  3481. fc->low_water = fc->high_water - 8;
  3482. break;
  3483. }
  3484. /* fall-through */
  3485. default:
  3486. hwm = min(((pba << 10) * 9 / 10),
  3487. ((pba << 10) - adapter->max_frame_size));
  3488. fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
  3489. fc->low_water = fc->high_water - 8;
  3490. break;
  3491. case e1000_pchlan:
  3492. /* Workaround PCH LOM adapter hangs with certain network
  3493. * loads. If hangs persist, try disabling Tx flow control.
  3494. */
  3495. if (adapter->netdev->mtu > ETH_DATA_LEN) {
  3496. fc->high_water = 0x3500;
  3497. fc->low_water = 0x1500;
  3498. } else {
  3499. fc->high_water = 0x5000;
  3500. fc->low_water = 0x3000;
  3501. }
  3502. fc->refresh_time = 0x1000;
  3503. break;
  3504. case e1000_pch2lan:
  3505. case e1000_pch_lpt:
  3506. case e1000_pch_spt:
  3507. case e1000_pch_cnp:
  3508. fc->refresh_time = 0x0400;
  3509. if (adapter->netdev->mtu <= ETH_DATA_LEN) {
  3510. fc->high_water = 0x05C20;
  3511. fc->low_water = 0x05048;
  3512. fc->pause_time = 0x0650;
  3513. break;
  3514. }
  3515. pba = 14;
  3516. ew32(PBA, pba);
  3517. fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
  3518. fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
  3519. break;
  3520. }
  3521. /* Alignment of Tx data is on an arbitrary byte boundary with the
  3522. * maximum size per Tx descriptor limited only to the transmit
  3523. * allocation of the packet buffer minus 96 bytes with an upper
  3524. * limit of 24KB due to receive synchronization limitations.
  3525. */
  3526. adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
  3527. 24 << 10);
  3528. /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
  3529. * fit in receive buffer.
  3530. */
  3531. if (adapter->itr_setting & 0x3) {
  3532. if ((adapter->max_frame_size * 2) > (pba << 10)) {
  3533. if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
  3534. dev_info(&adapter->pdev->dev,
  3535. "Interrupt Throttle Rate off\n");
  3536. adapter->flags2 |= FLAG2_DISABLE_AIM;
  3537. e1000e_write_itr(adapter, 0);
  3538. }
  3539. } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
  3540. dev_info(&adapter->pdev->dev,
  3541. "Interrupt Throttle Rate on\n");
  3542. adapter->flags2 &= ~FLAG2_DISABLE_AIM;
  3543. adapter->itr = 20000;
  3544. e1000e_write_itr(adapter, adapter->itr);
  3545. }
  3546. }
  3547. if (hw->mac.type >= e1000_pch_spt)
  3548. e1000_flush_desc_rings(adapter);
  3549. /* Allow time for pending master requests to run */
  3550. mac->ops.reset_hw(hw);
  3551. /* For parts with AMT enabled, let the firmware know
  3552. * that the network interface is in control
  3553. */
  3554. if (adapter->flags & FLAG_HAS_AMT)
  3555. e1000e_get_hw_control(adapter);
  3556. ew32(WUC, 0);
  3557. if (mac->ops.init_hw(hw))
  3558. e_err("Hardware Error\n");
  3559. e1000_update_mng_vlan(adapter);
  3560. /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
  3561. ew32(VET, ETH_P_8021Q);
  3562. e1000e_reset_adaptive(hw);
  3563. /* restore systim and hwtstamp settings */
  3564. e1000e_systim_reset(adapter);
  3565. /* Set EEE advertisement as appropriate */
  3566. if (adapter->flags2 & FLAG2_HAS_EEE) {
  3567. s32 ret_val;
  3568. u16 adv_addr;
  3569. switch (hw->phy.type) {
  3570. case e1000_phy_82579:
  3571. adv_addr = I82579_EEE_ADVERTISEMENT;
  3572. break;
  3573. case e1000_phy_i217:
  3574. adv_addr = I217_EEE_ADVERTISEMENT;
  3575. break;
  3576. default:
  3577. dev_err(&adapter->pdev->dev,
  3578. "Invalid PHY type setting EEE advertisement\n");
  3579. return;
  3580. }
  3581. ret_val = hw->phy.ops.acquire(hw);
  3582. if (ret_val) {
  3583. dev_err(&adapter->pdev->dev,
  3584. "EEE advertisement - unable to acquire PHY\n");
  3585. return;
  3586. }
  3587. e1000_write_emi_reg_locked(hw, adv_addr,
  3588. hw->dev_spec.ich8lan.eee_disable ?
  3589. 0 : adapter->eee_advert);
  3590. hw->phy.ops.release(hw);
  3591. }
  3592. if (!netif_running(adapter->netdev) &&
  3593. !test_bit(__E1000_TESTING, &adapter->state))
  3594. e1000_power_down_phy(adapter);
  3595. e1000_get_phy_info(hw);
  3596. if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
  3597. !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
  3598. u16 phy_data = 0;
  3599. /* speed up time to link by disabling smart power down, ignore
  3600. * the return value of this function because there is nothing
  3601. * different we would do if it failed
  3602. */
  3603. e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
  3604. phy_data &= ~IGP02E1000_PM_SPD;
  3605. e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
  3606. }
  3607. if (hw->mac.type >= e1000_pch_spt && adapter->int_mode == 0) {
  3608. u32 reg;
  3609. /* Fextnvm7 @ 0xe4[2] = 1 */
  3610. reg = er32(FEXTNVM7);
  3611. reg |= E1000_FEXTNVM7_SIDE_CLK_UNGATE;
  3612. ew32(FEXTNVM7, reg);
  3613. /* Fextnvm9 @ 0x5bb4[13:12] = 11 */
  3614. reg = er32(FEXTNVM9);
  3615. reg |= E1000_FEXTNVM9_IOSFSB_CLKGATE_DIS |
  3616. E1000_FEXTNVM9_IOSFSB_CLKREQ_DIS;
  3617. ew32(FEXTNVM9, reg);
  3618. }
  3619. }
  3620. /**
  3621. * e1000e_trigger_lsc - trigger an LSC interrupt
  3622. * @adapter:
  3623. *
  3624. * Fire a link status change interrupt to start the watchdog.
  3625. **/
  3626. static void e1000e_trigger_lsc(struct e1000_adapter *adapter)
  3627. {
  3628. struct e1000_hw *hw = &adapter->hw;
  3629. if (adapter->msix_entries)
  3630. ew32(ICS, E1000_ICS_LSC | E1000_ICS_OTHER);
  3631. else
  3632. ew32(ICS, E1000_ICS_LSC);
  3633. }
  3634. void e1000e_up(struct e1000_adapter *adapter)
  3635. {
  3636. /* hardware has been reset, we need to reload some things */
  3637. e1000_configure(adapter);
  3638. clear_bit(__E1000_DOWN, &adapter->state);
  3639. if (adapter->msix_entries)
  3640. e1000_configure_msix(adapter);
  3641. e1000_irq_enable(adapter);
  3642. /* Tx queue started by watchdog timer when link is up */
  3643. e1000e_trigger_lsc(adapter);
  3644. }
  3645. static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
  3646. {
  3647. struct e1000_hw *hw = &adapter->hw;
  3648. if (!(adapter->flags2 & FLAG2_DMA_BURST))
  3649. return;
  3650. /* flush pending descriptor writebacks to memory */
  3651. ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
  3652. ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
  3653. /* execute the writes immediately */
  3654. e1e_flush();
  3655. /* due to rare timing issues, write to TIDV/RDTR again to ensure the
  3656. * write is successful
  3657. */
  3658. ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
  3659. ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
  3660. /* execute the writes immediately */
  3661. e1e_flush();
  3662. }
  3663. static void e1000e_update_stats(struct e1000_adapter *adapter);
  3664. /**
  3665. * e1000e_down - quiesce the device and optionally reset the hardware
  3666. * @adapter: board private structure
  3667. * @reset: boolean flag to reset the hardware or not
  3668. */
  3669. void e1000e_down(struct e1000_adapter *adapter, bool reset)
  3670. {
  3671. struct net_device *netdev = adapter->netdev;
  3672. struct e1000_hw *hw = &adapter->hw;
  3673. u32 tctl, rctl;
  3674. /* signal that we're down so the interrupt handler does not
  3675. * reschedule our watchdog timer
  3676. */
  3677. set_bit(__E1000_DOWN, &adapter->state);
  3678. netif_carrier_off(netdev);
  3679. /* disable receives in the hardware */
  3680. rctl = er32(RCTL);
  3681. if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
  3682. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  3683. /* flush and sleep below */
  3684. netif_stop_queue(netdev);
  3685. /* disable transmits in the hardware */
  3686. tctl = er32(TCTL);
  3687. tctl &= ~E1000_TCTL_EN;
  3688. ew32(TCTL, tctl);
  3689. /* flush both disables and wait for them to finish */
  3690. e1e_flush();
  3691. usleep_range(10000, 20000);
  3692. e1000_irq_disable(adapter);
  3693. napi_synchronize(&adapter->napi);
  3694. del_timer_sync(&adapter->watchdog_timer);
  3695. del_timer_sync(&adapter->phy_info_timer);
  3696. spin_lock(&adapter->stats64_lock);
  3697. e1000e_update_stats(adapter);
  3698. spin_unlock(&adapter->stats64_lock);
  3699. e1000e_flush_descriptors(adapter);
  3700. adapter->link_speed = 0;
  3701. adapter->link_duplex = 0;
  3702. /* Disable Si errata workaround on PCHx for jumbo frame flow */
  3703. if ((hw->mac.type >= e1000_pch2lan) &&
  3704. (adapter->netdev->mtu > ETH_DATA_LEN) &&
  3705. e1000_lv_jumbo_workaround_ich8lan(hw, false))
  3706. e_dbg("failed to disable jumbo frame workaround mode\n");
  3707. if (!pci_channel_offline(adapter->pdev)) {
  3708. if (reset)
  3709. e1000e_reset(adapter);
  3710. else if (hw->mac.type >= e1000_pch_spt)
  3711. e1000_flush_desc_rings(adapter);
  3712. }
  3713. e1000_clean_tx_ring(adapter->tx_ring);
  3714. e1000_clean_rx_ring(adapter->rx_ring);
  3715. }
  3716. void e1000e_reinit_locked(struct e1000_adapter *adapter)
  3717. {
  3718. might_sleep();
  3719. while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
  3720. usleep_range(1000, 2000);
  3721. e1000e_down(adapter, true);
  3722. e1000e_up(adapter);
  3723. clear_bit(__E1000_RESETTING, &adapter->state);
  3724. }
  3725. /**
  3726. * e1000e_sanitize_systim - sanitize raw cycle counter reads
  3727. * @hw: pointer to the HW structure
  3728. * @systim: time value read, sanitized and returned
  3729. *
  3730. * Errata for 82574/82583 possible bad bits read from SYSTIMH/L:
  3731. * check to see that the time is incrementing at a reasonable
  3732. * rate and is a multiple of incvalue.
  3733. **/
  3734. static u64 e1000e_sanitize_systim(struct e1000_hw *hw, u64 systim)
  3735. {
  3736. u64 time_delta, rem, temp;
  3737. u64 systim_next;
  3738. u32 incvalue;
  3739. int i;
  3740. incvalue = er32(TIMINCA) & E1000_TIMINCA_INCVALUE_MASK;
  3741. for (i = 0; i < E1000_MAX_82574_SYSTIM_REREADS; i++) {
  3742. /* latch SYSTIMH on read of SYSTIML */
  3743. systim_next = (u64)er32(SYSTIML);
  3744. systim_next |= (u64)er32(SYSTIMH) << 32;
  3745. time_delta = systim_next - systim;
  3746. temp = time_delta;
  3747. /* VMWare users have seen incvalue of zero, don't div / 0 */
  3748. rem = incvalue ? do_div(temp, incvalue) : (time_delta != 0);
  3749. systim = systim_next;
  3750. if ((time_delta < E1000_82574_SYSTIM_EPSILON) && (rem == 0))
  3751. break;
  3752. }
  3753. return systim;
  3754. }
  3755. /**
  3756. * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
  3757. * @cc: cyclecounter structure
  3758. **/
  3759. static u64 e1000e_cyclecounter_read(const struct cyclecounter *cc)
  3760. {
  3761. struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
  3762. cc);
  3763. struct e1000_hw *hw = &adapter->hw;
  3764. u32 systimel, systimeh;
  3765. u64 systim;
  3766. /* SYSTIMH latching upon SYSTIML read does not work well.
  3767. * This means that if SYSTIML overflows after we read it but before
  3768. * we read SYSTIMH, the value of SYSTIMH has been incremented and we
  3769. * will experience a huge non linear increment in the systime value
  3770. * to fix that we test for overflow and if true, we re-read systime.
  3771. */
  3772. systimel = er32(SYSTIML);
  3773. systimeh = er32(SYSTIMH);
  3774. /* Is systimel is so large that overflow is possible? */
  3775. if (systimel >= (u32)0xffffffff - E1000_TIMINCA_INCVALUE_MASK) {
  3776. u32 systimel_2 = er32(SYSTIML);
  3777. if (systimel > systimel_2) {
  3778. /* There was an overflow, read again SYSTIMH, and use
  3779. * systimel_2
  3780. */
  3781. systimeh = er32(SYSTIMH);
  3782. systimel = systimel_2;
  3783. }
  3784. }
  3785. systim = (u64)systimel;
  3786. systim |= (u64)systimeh << 32;
  3787. if (adapter->flags2 & FLAG2_CHECK_SYSTIM_OVERFLOW)
  3788. systim = e1000e_sanitize_systim(hw, systim);
  3789. return systim;
  3790. }
  3791. /**
  3792. * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
  3793. * @adapter: board private structure to initialize
  3794. *
  3795. * e1000_sw_init initializes the Adapter private data structure.
  3796. * Fields are initialized based on PCI device information and
  3797. * OS network device settings (MTU size).
  3798. **/
  3799. static int e1000_sw_init(struct e1000_adapter *adapter)
  3800. {
  3801. struct net_device *netdev = adapter->netdev;
  3802. adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN;
  3803. adapter->rx_ps_bsize0 = 128;
  3804. adapter->max_frame_size = netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
  3805. adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
  3806. adapter->tx_ring_count = E1000_DEFAULT_TXD;
  3807. adapter->rx_ring_count = E1000_DEFAULT_RXD;
  3808. spin_lock_init(&adapter->stats64_lock);
  3809. e1000e_set_interrupt_capability(adapter);
  3810. if (e1000_alloc_queues(adapter))
  3811. return -ENOMEM;
  3812. /* Setup hardware time stamping cyclecounter */
  3813. if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
  3814. adapter->cc.read = e1000e_cyclecounter_read;
  3815. adapter->cc.mask = CYCLECOUNTER_MASK(64);
  3816. adapter->cc.mult = 1;
  3817. /* cc.shift set in e1000e_get_base_tininca() */
  3818. spin_lock_init(&adapter->systim_lock);
  3819. INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
  3820. }
  3821. /* Explicitly disable IRQ since the NIC can be in any state. */
  3822. e1000_irq_disable(adapter);
  3823. set_bit(__E1000_DOWN, &adapter->state);
  3824. return 0;
  3825. }
  3826. /**
  3827. * e1000_intr_msi_test - Interrupt Handler
  3828. * @irq: interrupt number
  3829. * @data: pointer to a network interface device structure
  3830. **/
  3831. static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
  3832. {
  3833. struct net_device *netdev = data;
  3834. struct e1000_adapter *adapter = netdev_priv(netdev);
  3835. struct e1000_hw *hw = &adapter->hw;
  3836. u32 icr = er32(ICR);
  3837. e_dbg("icr is %08X\n", icr);
  3838. if (icr & E1000_ICR_RXSEQ) {
  3839. adapter->flags &= ~FLAG_MSI_TEST_FAILED;
  3840. /* Force memory writes to complete before acknowledging the
  3841. * interrupt is handled.
  3842. */
  3843. wmb();
  3844. }
  3845. return IRQ_HANDLED;
  3846. }
  3847. /**
  3848. * e1000_test_msi_interrupt - Returns 0 for successful test
  3849. * @adapter: board private struct
  3850. *
  3851. * code flow taken from tg3.c
  3852. **/
  3853. static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
  3854. {
  3855. struct net_device *netdev = adapter->netdev;
  3856. struct e1000_hw *hw = &adapter->hw;
  3857. int err;
  3858. /* poll_enable hasn't been called yet, so don't need disable */
  3859. /* clear any pending events */
  3860. er32(ICR);
  3861. /* free the real vector and request a test handler */
  3862. e1000_free_irq(adapter);
  3863. e1000e_reset_interrupt_capability(adapter);
  3864. /* Assume that the test fails, if it succeeds then the test
  3865. * MSI irq handler will unset this flag
  3866. */
  3867. adapter->flags |= FLAG_MSI_TEST_FAILED;
  3868. err = pci_enable_msi(adapter->pdev);
  3869. if (err)
  3870. goto msi_test_failed;
  3871. err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
  3872. netdev->name, netdev);
  3873. if (err) {
  3874. pci_disable_msi(adapter->pdev);
  3875. goto msi_test_failed;
  3876. }
  3877. /* Force memory writes to complete before enabling and firing an
  3878. * interrupt.
  3879. */
  3880. wmb();
  3881. e1000_irq_enable(adapter);
  3882. /* fire an unusual interrupt on the test handler */
  3883. ew32(ICS, E1000_ICS_RXSEQ);
  3884. e1e_flush();
  3885. msleep(100);
  3886. e1000_irq_disable(adapter);
  3887. rmb(); /* read flags after interrupt has been fired */
  3888. if (adapter->flags & FLAG_MSI_TEST_FAILED) {
  3889. adapter->int_mode = E1000E_INT_MODE_LEGACY;
  3890. e_info("MSI interrupt test failed, using legacy interrupt.\n");
  3891. } else {
  3892. e_dbg("MSI interrupt test succeeded!\n");
  3893. }
  3894. free_irq(adapter->pdev->irq, netdev);
  3895. pci_disable_msi(adapter->pdev);
  3896. msi_test_failed:
  3897. e1000e_set_interrupt_capability(adapter);
  3898. return e1000_request_irq(adapter);
  3899. }
  3900. /**
  3901. * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
  3902. * @adapter: board private struct
  3903. *
  3904. * code flow taken from tg3.c, called with e1000 interrupts disabled.
  3905. **/
  3906. static int e1000_test_msi(struct e1000_adapter *adapter)
  3907. {
  3908. int err;
  3909. u16 pci_cmd;
  3910. if (!(adapter->flags & FLAG_MSI_ENABLED))
  3911. return 0;
  3912. /* disable SERR in case the MSI write causes a master abort */
  3913. pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
  3914. if (pci_cmd & PCI_COMMAND_SERR)
  3915. pci_write_config_word(adapter->pdev, PCI_COMMAND,
  3916. pci_cmd & ~PCI_COMMAND_SERR);
  3917. err = e1000_test_msi_interrupt(adapter);
  3918. /* re-enable SERR */
  3919. if (pci_cmd & PCI_COMMAND_SERR) {
  3920. pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
  3921. pci_cmd |= PCI_COMMAND_SERR;
  3922. pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
  3923. }
  3924. return err;
  3925. }
  3926. /**
  3927. * e1000e_open - Called when a network interface is made active
  3928. * @netdev: network interface device structure
  3929. *
  3930. * Returns 0 on success, negative value on failure
  3931. *
  3932. * The open entry point is called when a network interface is made
  3933. * active by the system (IFF_UP). At this point all resources needed
  3934. * for transmit and receive operations are allocated, the interrupt
  3935. * handler is registered with the OS, the watchdog timer is started,
  3936. * and the stack is notified that the interface is ready.
  3937. **/
  3938. int e1000e_open(struct net_device *netdev)
  3939. {
  3940. struct e1000_adapter *adapter = netdev_priv(netdev);
  3941. struct e1000_hw *hw = &adapter->hw;
  3942. struct pci_dev *pdev = adapter->pdev;
  3943. int err;
  3944. /* disallow open during test */
  3945. if (test_bit(__E1000_TESTING, &adapter->state))
  3946. return -EBUSY;
  3947. pm_runtime_get_sync(&pdev->dev);
  3948. netif_carrier_off(netdev);
  3949. netif_stop_queue(netdev);
  3950. /* allocate transmit descriptors */
  3951. err = e1000e_setup_tx_resources(adapter->tx_ring);
  3952. if (err)
  3953. goto err_setup_tx;
  3954. /* allocate receive descriptors */
  3955. err = e1000e_setup_rx_resources(adapter->rx_ring);
  3956. if (err)
  3957. goto err_setup_rx;
  3958. /* If AMT is enabled, let the firmware know that the network
  3959. * interface is now open and reset the part to a known state.
  3960. */
  3961. if (adapter->flags & FLAG_HAS_AMT) {
  3962. e1000e_get_hw_control(adapter);
  3963. e1000e_reset(adapter);
  3964. }
  3965. e1000e_power_up_phy(adapter);
  3966. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  3967. if ((adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
  3968. e1000_update_mng_vlan(adapter);
  3969. /* DMA latency requirement to workaround jumbo issue */
  3970. pm_qos_add_request(&adapter->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
  3971. PM_QOS_DEFAULT_VALUE);
  3972. /* before we allocate an interrupt, we must be ready to handle it.
  3973. * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
  3974. * as soon as we call pci_request_irq, so we have to setup our
  3975. * clean_rx handler before we do so.
  3976. */
  3977. e1000_configure(adapter);
  3978. err = e1000_request_irq(adapter);
  3979. if (err)
  3980. goto err_req_irq;
  3981. /* Work around PCIe errata with MSI interrupts causing some chipsets to
  3982. * ignore e1000e MSI messages, which means we need to test our MSI
  3983. * interrupt now
  3984. */
  3985. if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
  3986. err = e1000_test_msi(adapter);
  3987. if (err) {
  3988. e_err("Interrupt allocation failed\n");
  3989. goto err_req_irq;
  3990. }
  3991. }
  3992. /* From here on the code is the same as e1000e_up() */
  3993. clear_bit(__E1000_DOWN, &adapter->state);
  3994. napi_enable(&adapter->napi);
  3995. e1000_irq_enable(adapter);
  3996. adapter->tx_hang_recheck = false;
  3997. hw->mac.get_link_status = true;
  3998. pm_runtime_put(&pdev->dev);
  3999. e1000e_trigger_lsc(adapter);
  4000. return 0;
  4001. err_req_irq:
  4002. pm_qos_remove_request(&adapter->pm_qos_req);
  4003. e1000e_release_hw_control(adapter);
  4004. e1000_power_down_phy(adapter);
  4005. e1000e_free_rx_resources(adapter->rx_ring);
  4006. err_setup_rx:
  4007. e1000e_free_tx_resources(adapter->tx_ring);
  4008. err_setup_tx:
  4009. e1000e_reset(adapter);
  4010. pm_runtime_put_sync(&pdev->dev);
  4011. return err;
  4012. }
  4013. /**
  4014. * e1000e_close - Disables a network interface
  4015. * @netdev: network interface device structure
  4016. *
  4017. * Returns 0, this is not allowed to fail
  4018. *
  4019. * The close entry point is called when an interface is de-activated
  4020. * by the OS. The hardware is still under the drivers control, but
  4021. * needs to be disabled. A global MAC reset is issued to stop the
  4022. * hardware, and all transmit and receive resources are freed.
  4023. **/
  4024. int e1000e_close(struct net_device *netdev)
  4025. {
  4026. struct e1000_adapter *adapter = netdev_priv(netdev);
  4027. struct pci_dev *pdev = adapter->pdev;
  4028. int count = E1000_CHECK_RESET_COUNT;
  4029. while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
  4030. usleep_range(10000, 20000);
  4031. WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
  4032. pm_runtime_get_sync(&pdev->dev);
  4033. if (!test_bit(__E1000_DOWN, &adapter->state)) {
  4034. e1000e_down(adapter, true);
  4035. e1000_free_irq(adapter);
  4036. /* Link status message must follow this format */
  4037. pr_info("%s NIC Link is Down\n", adapter->netdev->name);
  4038. }
  4039. napi_disable(&adapter->napi);
  4040. e1000e_free_tx_resources(adapter->tx_ring);
  4041. e1000e_free_rx_resources(adapter->rx_ring);
  4042. /* kill manageability vlan ID if supported, but not if a vlan with
  4043. * the same ID is registered on the host OS (let 8021q kill it)
  4044. */
  4045. if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
  4046. e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
  4047. adapter->mng_vlan_id);
  4048. /* If AMT is enabled, let the firmware know that the network
  4049. * interface is now closed
  4050. */
  4051. if ((adapter->flags & FLAG_HAS_AMT) &&
  4052. !test_bit(__E1000_TESTING, &adapter->state))
  4053. e1000e_release_hw_control(adapter);
  4054. pm_qos_remove_request(&adapter->pm_qos_req);
  4055. pm_runtime_put_sync(&pdev->dev);
  4056. return 0;
  4057. }
  4058. /**
  4059. * e1000_set_mac - Change the Ethernet Address of the NIC
  4060. * @netdev: network interface device structure
  4061. * @p: pointer to an address structure
  4062. *
  4063. * Returns 0 on success, negative on failure
  4064. **/
  4065. static int e1000_set_mac(struct net_device *netdev, void *p)
  4066. {
  4067. struct e1000_adapter *adapter = netdev_priv(netdev);
  4068. struct e1000_hw *hw = &adapter->hw;
  4069. struct sockaddr *addr = p;
  4070. if (!is_valid_ether_addr(addr->sa_data))
  4071. return -EADDRNOTAVAIL;
  4072. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  4073. memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
  4074. hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
  4075. if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
  4076. /* activate the work around */
  4077. e1000e_set_laa_state_82571(&adapter->hw, 1);
  4078. /* Hold a copy of the LAA in RAR[14] This is done so that
  4079. * between the time RAR[0] gets clobbered and the time it
  4080. * gets fixed (in e1000_watchdog), the actual LAA is in one
  4081. * of the RARs and no incoming packets directed to this port
  4082. * are dropped. Eventually the LAA will be in RAR[0] and
  4083. * RAR[14]
  4084. */
  4085. hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
  4086. adapter->hw.mac.rar_entry_count - 1);
  4087. }
  4088. return 0;
  4089. }
  4090. /**
  4091. * e1000e_update_phy_task - work thread to update phy
  4092. * @work: pointer to our work struct
  4093. *
  4094. * this worker thread exists because we must acquire a
  4095. * semaphore to read the phy, which we could msleep while
  4096. * waiting for it, and we can't msleep in a timer.
  4097. **/
  4098. static void e1000e_update_phy_task(struct work_struct *work)
  4099. {
  4100. struct e1000_adapter *adapter = container_of(work,
  4101. struct e1000_adapter,
  4102. update_phy_task);
  4103. struct e1000_hw *hw = &adapter->hw;
  4104. if (test_bit(__E1000_DOWN, &adapter->state))
  4105. return;
  4106. e1000_get_phy_info(hw);
  4107. /* Enable EEE on 82579 after link up */
  4108. if (hw->phy.type >= e1000_phy_82579)
  4109. e1000_set_eee_pchlan(hw);
  4110. }
  4111. /**
  4112. * e1000_update_phy_info - timre call-back to update PHY info
  4113. * @data: pointer to adapter cast into an unsigned long
  4114. *
  4115. * Need to wait a few seconds after link up to get diagnostic information from
  4116. * the phy
  4117. **/
  4118. static void e1000_update_phy_info(struct timer_list *t)
  4119. {
  4120. struct e1000_adapter *adapter = from_timer(adapter, t, phy_info_timer);
  4121. if (test_bit(__E1000_DOWN, &adapter->state))
  4122. return;
  4123. schedule_work(&adapter->update_phy_task);
  4124. }
  4125. /**
  4126. * e1000e_update_phy_stats - Update the PHY statistics counters
  4127. * @adapter: board private structure
  4128. *
  4129. * Read/clear the upper 16-bit PHY registers and read/accumulate lower
  4130. **/
  4131. static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
  4132. {
  4133. struct e1000_hw *hw = &adapter->hw;
  4134. s32 ret_val;
  4135. u16 phy_data;
  4136. ret_val = hw->phy.ops.acquire(hw);
  4137. if (ret_val)
  4138. return;
  4139. /* A page set is expensive so check if already on desired page.
  4140. * If not, set to the page with the PHY status registers.
  4141. */
  4142. hw->phy.addr = 1;
  4143. ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
  4144. &phy_data);
  4145. if (ret_val)
  4146. goto release;
  4147. if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
  4148. ret_val = hw->phy.ops.set_page(hw,
  4149. HV_STATS_PAGE << IGP_PAGE_SHIFT);
  4150. if (ret_val)
  4151. goto release;
  4152. }
  4153. /* Single Collision Count */
  4154. hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
  4155. ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
  4156. if (!ret_val)
  4157. adapter->stats.scc += phy_data;
  4158. /* Excessive Collision Count */
  4159. hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
  4160. ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
  4161. if (!ret_val)
  4162. adapter->stats.ecol += phy_data;
  4163. /* Multiple Collision Count */
  4164. hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
  4165. ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
  4166. if (!ret_val)
  4167. adapter->stats.mcc += phy_data;
  4168. /* Late Collision Count */
  4169. hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
  4170. ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
  4171. if (!ret_val)
  4172. adapter->stats.latecol += phy_data;
  4173. /* Collision Count - also used for adaptive IFS */
  4174. hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
  4175. ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
  4176. if (!ret_val)
  4177. hw->mac.collision_delta = phy_data;
  4178. /* Defer Count */
  4179. hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
  4180. ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
  4181. if (!ret_val)
  4182. adapter->stats.dc += phy_data;
  4183. /* Transmit with no CRS */
  4184. hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
  4185. ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
  4186. if (!ret_val)
  4187. adapter->stats.tncrs += phy_data;
  4188. release:
  4189. hw->phy.ops.release(hw);
  4190. }
  4191. /**
  4192. * e1000e_update_stats - Update the board statistics counters
  4193. * @adapter: board private structure
  4194. **/
  4195. static void e1000e_update_stats(struct e1000_adapter *adapter)
  4196. {
  4197. struct net_device *netdev = adapter->netdev;
  4198. struct e1000_hw *hw = &adapter->hw;
  4199. struct pci_dev *pdev = adapter->pdev;
  4200. /* Prevent stats update while adapter is being reset, or if the pci
  4201. * connection is down.
  4202. */
  4203. if (adapter->link_speed == 0)
  4204. return;
  4205. if (pci_channel_offline(pdev))
  4206. return;
  4207. adapter->stats.crcerrs += er32(CRCERRS);
  4208. adapter->stats.gprc += er32(GPRC);
  4209. adapter->stats.gorc += er32(GORCL);
  4210. er32(GORCH); /* Clear gorc */
  4211. adapter->stats.bprc += er32(BPRC);
  4212. adapter->stats.mprc += er32(MPRC);
  4213. adapter->stats.roc += er32(ROC);
  4214. adapter->stats.mpc += er32(MPC);
  4215. /* Half-duplex statistics */
  4216. if (adapter->link_duplex == HALF_DUPLEX) {
  4217. if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
  4218. e1000e_update_phy_stats(adapter);
  4219. } else {
  4220. adapter->stats.scc += er32(SCC);
  4221. adapter->stats.ecol += er32(ECOL);
  4222. adapter->stats.mcc += er32(MCC);
  4223. adapter->stats.latecol += er32(LATECOL);
  4224. adapter->stats.dc += er32(DC);
  4225. hw->mac.collision_delta = er32(COLC);
  4226. if ((hw->mac.type != e1000_82574) &&
  4227. (hw->mac.type != e1000_82583))
  4228. adapter->stats.tncrs += er32(TNCRS);
  4229. }
  4230. adapter->stats.colc += hw->mac.collision_delta;
  4231. }
  4232. adapter->stats.xonrxc += er32(XONRXC);
  4233. adapter->stats.xontxc += er32(XONTXC);
  4234. adapter->stats.xoffrxc += er32(XOFFRXC);
  4235. adapter->stats.xofftxc += er32(XOFFTXC);
  4236. adapter->stats.gptc += er32(GPTC);
  4237. adapter->stats.gotc += er32(GOTCL);
  4238. er32(GOTCH); /* Clear gotc */
  4239. adapter->stats.rnbc += er32(RNBC);
  4240. adapter->stats.ruc += er32(RUC);
  4241. adapter->stats.mptc += er32(MPTC);
  4242. adapter->stats.bptc += er32(BPTC);
  4243. /* used for adaptive IFS */
  4244. hw->mac.tx_packet_delta = er32(TPT);
  4245. adapter->stats.tpt += hw->mac.tx_packet_delta;
  4246. adapter->stats.algnerrc += er32(ALGNERRC);
  4247. adapter->stats.rxerrc += er32(RXERRC);
  4248. adapter->stats.cexterr += er32(CEXTERR);
  4249. adapter->stats.tsctc += er32(TSCTC);
  4250. adapter->stats.tsctfc += er32(TSCTFC);
  4251. /* Fill out the OS statistics structure */
  4252. netdev->stats.multicast = adapter->stats.mprc;
  4253. netdev->stats.collisions = adapter->stats.colc;
  4254. /* Rx Errors */
  4255. /* RLEC on some newer hardware can be incorrect so build
  4256. * our own version based on RUC and ROC
  4257. */
  4258. netdev->stats.rx_errors = adapter->stats.rxerrc +
  4259. adapter->stats.crcerrs + adapter->stats.algnerrc +
  4260. adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
  4261. netdev->stats.rx_length_errors = adapter->stats.ruc +
  4262. adapter->stats.roc;
  4263. netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
  4264. netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
  4265. netdev->stats.rx_missed_errors = adapter->stats.mpc;
  4266. /* Tx Errors */
  4267. netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol;
  4268. netdev->stats.tx_aborted_errors = adapter->stats.ecol;
  4269. netdev->stats.tx_window_errors = adapter->stats.latecol;
  4270. netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
  4271. /* Tx Dropped needs to be maintained elsewhere */
  4272. /* Management Stats */
  4273. adapter->stats.mgptc += er32(MGTPTC);
  4274. adapter->stats.mgprc += er32(MGTPRC);
  4275. adapter->stats.mgpdc += er32(MGTPDC);
  4276. /* Correctable ECC Errors */
  4277. if (hw->mac.type >= e1000_pch_lpt) {
  4278. u32 pbeccsts = er32(PBECCSTS);
  4279. adapter->corr_errors +=
  4280. pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
  4281. adapter->uncorr_errors +=
  4282. (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
  4283. E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
  4284. }
  4285. }
  4286. /**
  4287. * e1000_phy_read_status - Update the PHY register status snapshot
  4288. * @adapter: board private structure
  4289. **/
  4290. static void e1000_phy_read_status(struct e1000_adapter *adapter)
  4291. {
  4292. struct e1000_hw *hw = &adapter->hw;
  4293. struct e1000_phy_regs *phy = &adapter->phy_regs;
  4294. if (!pm_runtime_suspended((&adapter->pdev->dev)->parent) &&
  4295. (er32(STATUS) & E1000_STATUS_LU) &&
  4296. (adapter->hw.phy.media_type == e1000_media_type_copper)) {
  4297. int ret_val;
  4298. ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
  4299. ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
  4300. ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
  4301. ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
  4302. ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
  4303. ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
  4304. ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
  4305. ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
  4306. if (ret_val)
  4307. e_warn("Error reading PHY register\n");
  4308. } else {
  4309. /* Do not read PHY registers if link is not up
  4310. * Set values to typical power-on defaults
  4311. */
  4312. phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
  4313. phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
  4314. BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
  4315. BMSR_ERCAP);
  4316. phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
  4317. ADVERTISE_ALL | ADVERTISE_CSMA);
  4318. phy->lpa = 0;
  4319. phy->expansion = EXPANSION_ENABLENPAGE;
  4320. phy->ctrl1000 = ADVERTISE_1000FULL;
  4321. phy->stat1000 = 0;
  4322. phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
  4323. }
  4324. }
  4325. static void e1000_print_link_info(struct e1000_adapter *adapter)
  4326. {
  4327. struct e1000_hw *hw = &adapter->hw;
  4328. u32 ctrl = er32(CTRL);
  4329. /* Link status message must follow this format for user tools */
  4330. pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
  4331. adapter->netdev->name, adapter->link_speed,
  4332. adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
  4333. (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
  4334. (ctrl & E1000_CTRL_RFCE) ? "Rx" :
  4335. (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
  4336. }
  4337. static bool e1000e_has_link(struct e1000_adapter *adapter)
  4338. {
  4339. struct e1000_hw *hw = &adapter->hw;
  4340. bool link_active = false;
  4341. s32 ret_val = 0;
  4342. /* get_link_status is set on LSC (link status) interrupt or
  4343. * Rx sequence error interrupt. get_link_status will stay
  4344. * true until the check_for_link establishes link
  4345. * for copper adapters ONLY
  4346. */
  4347. switch (hw->phy.media_type) {
  4348. case e1000_media_type_copper:
  4349. if (hw->mac.get_link_status) {
  4350. ret_val = hw->mac.ops.check_for_link(hw);
  4351. link_active = !hw->mac.get_link_status;
  4352. } else {
  4353. link_active = true;
  4354. }
  4355. break;
  4356. case e1000_media_type_fiber:
  4357. ret_val = hw->mac.ops.check_for_link(hw);
  4358. link_active = !!(er32(STATUS) & E1000_STATUS_LU);
  4359. break;
  4360. case e1000_media_type_internal_serdes:
  4361. ret_val = hw->mac.ops.check_for_link(hw);
  4362. link_active = hw->mac.serdes_has_link;
  4363. break;
  4364. default:
  4365. case e1000_media_type_unknown:
  4366. break;
  4367. }
  4368. if ((ret_val == -E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
  4369. (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
  4370. /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
  4371. e_info("Gigabit has been disabled, downgrading speed\n");
  4372. }
  4373. return link_active;
  4374. }
  4375. static void e1000e_enable_receives(struct e1000_adapter *adapter)
  4376. {
  4377. /* make sure the receive unit is started */
  4378. if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
  4379. (adapter->flags & FLAG_RESTART_NOW)) {
  4380. struct e1000_hw *hw = &adapter->hw;
  4381. u32 rctl = er32(RCTL);
  4382. ew32(RCTL, rctl | E1000_RCTL_EN);
  4383. adapter->flags &= ~FLAG_RESTART_NOW;
  4384. }
  4385. }
  4386. static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
  4387. {
  4388. struct e1000_hw *hw = &adapter->hw;
  4389. /* With 82574 controllers, PHY needs to be checked periodically
  4390. * for hung state and reset, if two calls return true
  4391. */
  4392. if (e1000_check_phy_82574(hw))
  4393. adapter->phy_hang_count++;
  4394. else
  4395. adapter->phy_hang_count = 0;
  4396. if (adapter->phy_hang_count > 1) {
  4397. adapter->phy_hang_count = 0;
  4398. e_dbg("PHY appears hung - resetting\n");
  4399. schedule_work(&adapter->reset_task);
  4400. }
  4401. }
  4402. /**
  4403. * e1000_watchdog - Timer Call-back
  4404. * @data: pointer to adapter cast into an unsigned long
  4405. **/
  4406. static void e1000_watchdog(struct timer_list *t)
  4407. {
  4408. struct e1000_adapter *adapter = from_timer(adapter, t, watchdog_timer);
  4409. /* Do the rest outside of interrupt context */
  4410. schedule_work(&adapter->watchdog_task);
  4411. /* TODO: make this use queue_delayed_work() */
  4412. }
  4413. static void e1000_watchdog_task(struct work_struct *work)
  4414. {
  4415. struct e1000_adapter *adapter = container_of(work,
  4416. struct e1000_adapter,
  4417. watchdog_task);
  4418. struct net_device *netdev = adapter->netdev;
  4419. struct e1000_mac_info *mac = &adapter->hw.mac;
  4420. struct e1000_phy_info *phy = &adapter->hw.phy;
  4421. struct e1000_ring *tx_ring = adapter->tx_ring;
  4422. struct e1000_hw *hw = &adapter->hw;
  4423. u32 link, tctl;
  4424. if (test_bit(__E1000_DOWN, &adapter->state))
  4425. return;
  4426. link = e1000e_has_link(adapter);
  4427. if ((netif_carrier_ok(netdev)) && link) {
  4428. /* Cancel scheduled suspend requests. */
  4429. pm_runtime_resume(netdev->dev.parent);
  4430. e1000e_enable_receives(adapter);
  4431. goto link_up;
  4432. }
  4433. if ((e1000e_enable_tx_pkt_filtering(hw)) &&
  4434. (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
  4435. e1000_update_mng_vlan(adapter);
  4436. if (link) {
  4437. if (!netif_carrier_ok(netdev)) {
  4438. bool txb2b = true;
  4439. /* Cancel scheduled suspend requests. */
  4440. pm_runtime_resume(netdev->dev.parent);
  4441. /* update snapshot of PHY registers on LSC */
  4442. e1000_phy_read_status(adapter);
  4443. mac->ops.get_link_up_info(&adapter->hw,
  4444. &adapter->link_speed,
  4445. &adapter->link_duplex);
  4446. e1000_print_link_info(adapter);
  4447. /* check if SmartSpeed worked */
  4448. e1000e_check_downshift(hw);
  4449. if (phy->speed_downgraded)
  4450. netdev_warn(netdev,
  4451. "Link Speed was downgraded by SmartSpeed\n");
  4452. /* On supported PHYs, check for duplex mismatch only
  4453. * if link has autonegotiated at 10/100 half
  4454. */
  4455. if ((hw->phy.type == e1000_phy_igp_3 ||
  4456. hw->phy.type == e1000_phy_bm) &&
  4457. hw->mac.autoneg &&
  4458. (adapter->link_speed == SPEED_10 ||
  4459. adapter->link_speed == SPEED_100) &&
  4460. (adapter->link_duplex == HALF_DUPLEX)) {
  4461. u16 autoneg_exp;
  4462. e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
  4463. if (!(autoneg_exp & EXPANSION_NWAY))
  4464. e_info("Autonegotiated half duplex but link partner cannot autoneg. Try forcing full duplex if link gets many collisions.\n");
  4465. }
  4466. /* adjust timeout factor according to speed/duplex */
  4467. adapter->tx_timeout_factor = 1;
  4468. switch (adapter->link_speed) {
  4469. case SPEED_10:
  4470. txb2b = false;
  4471. adapter->tx_timeout_factor = 16;
  4472. break;
  4473. case SPEED_100:
  4474. txb2b = false;
  4475. adapter->tx_timeout_factor = 10;
  4476. break;
  4477. }
  4478. /* workaround: re-program speed mode bit after
  4479. * link-up event
  4480. */
  4481. if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
  4482. !txb2b) {
  4483. u32 tarc0;
  4484. tarc0 = er32(TARC(0));
  4485. tarc0 &= ~SPEED_MODE_BIT;
  4486. ew32(TARC(0), tarc0);
  4487. }
  4488. /* disable TSO for pcie and 10/100 speeds, to avoid
  4489. * some hardware issues
  4490. */
  4491. if (!(adapter->flags & FLAG_TSO_FORCE)) {
  4492. switch (adapter->link_speed) {
  4493. case SPEED_10:
  4494. case SPEED_100:
  4495. e_info("10/100 speed: disabling TSO\n");
  4496. netdev->features &= ~NETIF_F_TSO;
  4497. netdev->features &= ~NETIF_F_TSO6;
  4498. break;
  4499. case SPEED_1000:
  4500. netdev->features |= NETIF_F_TSO;
  4501. netdev->features |= NETIF_F_TSO6;
  4502. break;
  4503. default:
  4504. /* oops */
  4505. break;
  4506. }
  4507. if (hw->mac.type == e1000_pch_spt) {
  4508. netdev->features &= ~NETIF_F_TSO;
  4509. netdev->features &= ~NETIF_F_TSO6;
  4510. }
  4511. }
  4512. /* enable transmits in the hardware, need to do this
  4513. * after setting TARC(0)
  4514. */
  4515. tctl = er32(TCTL);
  4516. tctl |= E1000_TCTL_EN;
  4517. ew32(TCTL, tctl);
  4518. /* Perform any post-link-up configuration before
  4519. * reporting link up.
  4520. */
  4521. if (phy->ops.cfg_on_link_up)
  4522. phy->ops.cfg_on_link_up(hw);
  4523. netif_wake_queue(netdev);
  4524. netif_carrier_on(netdev);
  4525. if (!test_bit(__E1000_DOWN, &adapter->state))
  4526. mod_timer(&adapter->phy_info_timer,
  4527. round_jiffies(jiffies + 2 * HZ));
  4528. }
  4529. } else {
  4530. if (netif_carrier_ok(netdev)) {
  4531. adapter->link_speed = 0;
  4532. adapter->link_duplex = 0;
  4533. /* Link status message must follow this format */
  4534. pr_info("%s NIC Link is Down\n", adapter->netdev->name);
  4535. netif_carrier_off(netdev);
  4536. netif_stop_queue(netdev);
  4537. if (!test_bit(__E1000_DOWN, &adapter->state))
  4538. mod_timer(&adapter->phy_info_timer,
  4539. round_jiffies(jiffies + 2 * HZ));
  4540. /* 8000ES2LAN requires a Rx packet buffer work-around
  4541. * on link down event; reset the controller to flush
  4542. * the Rx packet buffer.
  4543. */
  4544. if (adapter->flags & FLAG_RX_NEEDS_RESTART)
  4545. adapter->flags |= FLAG_RESTART_NOW;
  4546. else
  4547. pm_schedule_suspend(netdev->dev.parent,
  4548. LINK_TIMEOUT);
  4549. }
  4550. }
  4551. link_up:
  4552. spin_lock(&adapter->stats64_lock);
  4553. e1000e_update_stats(adapter);
  4554. mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
  4555. adapter->tpt_old = adapter->stats.tpt;
  4556. mac->collision_delta = adapter->stats.colc - adapter->colc_old;
  4557. adapter->colc_old = adapter->stats.colc;
  4558. adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
  4559. adapter->gorc_old = adapter->stats.gorc;
  4560. adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
  4561. adapter->gotc_old = adapter->stats.gotc;
  4562. spin_unlock(&adapter->stats64_lock);
  4563. /* If the link is lost the controller stops DMA, but
  4564. * if there is queued Tx work it cannot be done. So
  4565. * reset the controller to flush the Tx packet buffers.
  4566. */
  4567. if (!netif_carrier_ok(netdev) &&
  4568. (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
  4569. adapter->flags |= FLAG_RESTART_NOW;
  4570. /* If reset is necessary, do it outside of interrupt context. */
  4571. if (adapter->flags & FLAG_RESTART_NOW) {
  4572. schedule_work(&adapter->reset_task);
  4573. /* return immediately since reset is imminent */
  4574. return;
  4575. }
  4576. e1000e_update_adaptive(&adapter->hw);
  4577. /* Simple mode for Interrupt Throttle Rate (ITR) */
  4578. if (adapter->itr_setting == 4) {
  4579. /* Symmetric Tx/Rx gets a reduced ITR=2000;
  4580. * Total asymmetrical Tx or Rx gets ITR=8000;
  4581. * everyone else is between 2000-8000.
  4582. */
  4583. u32 goc = (adapter->gotc + adapter->gorc) / 10000;
  4584. u32 dif = (adapter->gotc > adapter->gorc ?
  4585. adapter->gotc - adapter->gorc :
  4586. adapter->gorc - adapter->gotc) / 10000;
  4587. u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
  4588. e1000e_write_itr(adapter, itr);
  4589. }
  4590. /* Cause software interrupt to ensure Rx ring is cleaned */
  4591. if (adapter->msix_entries)
  4592. ew32(ICS, adapter->rx_ring->ims_val);
  4593. else
  4594. ew32(ICS, E1000_ICS_RXDMT0);
  4595. /* flush pending descriptors to memory before detecting Tx hang */
  4596. e1000e_flush_descriptors(adapter);
  4597. /* Force detection of hung controller every watchdog period */
  4598. adapter->detect_tx_hung = true;
  4599. /* With 82571 controllers, LAA may be overwritten due to controller
  4600. * reset from the other port. Set the appropriate LAA in RAR[0]
  4601. */
  4602. if (e1000e_get_laa_state_82571(hw))
  4603. hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
  4604. if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
  4605. e1000e_check_82574_phy_workaround(adapter);
  4606. /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
  4607. if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
  4608. if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
  4609. (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
  4610. er32(RXSTMPH);
  4611. adapter->rx_hwtstamp_cleared++;
  4612. } else {
  4613. adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
  4614. }
  4615. }
  4616. /* Reset the timer */
  4617. if (!test_bit(__E1000_DOWN, &adapter->state))
  4618. mod_timer(&adapter->watchdog_timer,
  4619. round_jiffies(jiffies + 2 * HZ));
  4620. }
  4621. #define E1000_TX_FLAGS_CSUM 0x00000001
  4622. #define E1000_TX_FLAGS_VLAN 0x00000002
  4623. #define E1000_TX_FLAGS_TSO 0x00000004
  4624. #define E1000_TX_FLAGS_IPV4 0x00000008
  4625. #define E1000_TX_FLAGS_NO_FCS 0x00000010
  4626. #define E1000_TX_FLAGS_HWTSTAMP 0x00000020
  4627. #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
  4628. #define E1000_TX_FLAGS_VLAN_SHIFT 16
  4629. static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb,
  4630. __be16 protocol)
  4631. {
  4632. struct e1000_context_desc *context_desc;
  4633. struct e1000_buffer *buffer_info;
  4634. unsigned int i;
  4635. u32 cmd_length = 0;
  4636. u16 ipcse = 0, mss;
  4637. u8 ipcss, ipcso, tucss, tucso, hdr_len;
  4638. int err;
  4639. if (!skb_is_gso(skb))
  4640. return 0;
  4641. err = skb_cow_head(skb, 0);
  4642. if (err < 0)
  4643. return err;
  4644. hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  4645. mss = skb_shinfo(skb)->gso_size;
  4646. if (protocol == htons(ETH_P_IP)) {
  4647. struct iphdr *iph = ip_hdr(skb);
  4648. iph->tot_len = 0;
  4649. iph->check = 0;
  4650. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
  4651. 0, IPPROTO_TCP, 0);
  4652. cmd_length = E1000_TXD_CMD_IP;
  4653. ipcse = skb_transport_offset(skb) - 1;
  4654. } else if (skb_is_gso_v6(skb)) {
  4655. ipv6_hdr(skb)->payload_len = 0;
  4656. tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  4657. &ipv6_hdr(skb)->daddr,
  4658. 0, IPPROTO_TCP, 0);
  4659. ipcse = 0;
  4660. }
  4661. ipcss = skb_network_offset(skb);
  4662. ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
  4663. tucss = skb_transport_offset(skb);
  4664. tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
  4665. cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
  4666. E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
  4667. i = tx_ring->next_to_use;
  4668. context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
  4669. buffer_info = &tx_ring->buffer_info[i];
  4670. context_desc->lower_setup.ip_fields.ipcss = ipcss;
  4671. context_desc->lower_setup.ip_fields.ipcso = ipcso;
  4672. context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
  4673. context_desc->upper_setup.tcp_fields.tucss = tucss;
  4674. context_desc->upper_setup.tcp_fields.tucso = tucso;
  4675. context_desc->upper_setup.tcp_fields.tucse = 0;
  4676. context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
  4677. context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
  4678. context_desc->cmd_and_length = cpu_to_le32(cmd_length);
  4679. buffer_info->time_stamp = jiffies;
  4680. buffer_info->next_to_watch = i;
  4681. i++;
  4682. if (i == tx_ring->count)
  4683. i = 0;
  4684. tx_ring->next_to_use = i;
  4685. return 1;
  4686. }
  4687. static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb,
  4688. __be16 protocol)
  4689. {
  4690. struct e1000_adapter *adapter = tx_ring->adapter;
  4691. struct e1000_context_desc *context_desc;
  4692. struct e1000_buffer *buffer_info;
  4693. unsigned int i;
  4694. u8 css;
  4695. u32 cmd_len = E1000_TXD_CMD_DEXT;
  4696. if (skb->ip_summed != CHECKSUM_PARTIAL)
  4697. return false;
  4698. switch (protocol) {
  4699. case cpu_to_be16(ETH_P_IP):
  4700. if (ip_hdr(skb)->protocol == IPPROTO_TCP)
  4701. cmd_len |= E1000_TXD_CMD_TCP;
  4702. break;
  4703. case cpu_to_be16(ETH_P_IPV6):
  4704. /* XXX not handling all IPV6 headers */
  4705. if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
  4706. cmd_len |= E1000_TXD_CMD_TCP;
  4707. break;
  4708. default:
  4709. if (unlikely(net_ratelimit()))
  4710. e_warn("checksum_partial proto=%x!\n",
  4711. be16_to_cpu(protocol));
  4712. break;
  4713. }
  4714. css = skb_checksum_start_offset(skb);
  4715. i = tx_ring->next_to_use;
  4716. buffer_info = &tx_ring->buffer_info[i];
  4717. context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
  4718. context_desc->lower_setup.ip_config = 0;
  4719. context_desc->upper_setup.tcp_fields.tucss = css;
  4720. context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
  4721. context_desc->upper_setup.tcp_fields.tucse = 0;
  4722. context_desc->tcp_seg_setup.data = 0;
  4723. context_desc->cmd_and_length = cpu_to_le32(cmd_len);
  4724. buffer_info->time_stamp = jiffies;
  4725. buffer_info->next_to_watch = i;
  4726. i++;
  4727. if (i == tx_ring->count)
  4728. i = 0;
  4729. tx_ring->next_to_use = i;
  4730. return true;
  4731. }
  4732. static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
  4733. unsigned int first, unsigned int max_per_txd,
  4734. unsigned int nr_frags)
  4735. {
  4736. struct e1000_adapter *adapter = tx_ring->adapter;
  4737. struct pci_dev *pdev = adapter->pdev;
  4738. struct e1000_buffer *buffer_info;
  4739. unsigned int len = skb_headlen(skb);
  4740. unsigned int offset = 0, size, count = 0, i;
  4741. unsigned int f, bytecount, segs;
  4742. i = tx_ring->next_to_use;
  4743. while (len) {
  4744. buffer_info = &tx_ring->buffer_info[i];
  4745. size = min(len, max_per_txd);
  4746. buffer_info->length = size;
  4747. buffer_info->time_stamp = jiffies;
  4748. buffer_info->next_to_watch = i;
  4749. buffer_info->dma = dma_map_single(&pdev->dev,
  4750. skb->data + offset,
  4751. size, DMA_TO_DEVICE);
  4752. buffer_info->mapped_as_page = false;
  4753. if (dma_mapping_error(&pdev->dev, buffer_info->dma))
  4754. goto dma_error;
  4755. len -= size;
  4756. offset += size;
  4757. count++;
  4758. if (len) {
  4759. i++;
  4760. if (i == tx_ring->count)
  4761. i = 0;
  4762. }
  4763. }
  4764. for (f = 0; f < nr_frags; f++) {
  4765. const struct skb_frag_struct *frag;
  4766. frag = &skb_shinfo(skb)->frags[f];
  4767. len = skb_frag_size(frag);
  4768. offset = 0;
  4769. while (len) {
  4770. i++;
  4771. if (i == tx_ring->count)
  4772. i = 0;
  4773. buffer_info = &tx_ring->buffer_info[i];
  4774. size = min(len, max_per_txd);
  4775. buffer_info->length = size;
  4776. buffer_info->time_stamp = jiffies;
  4777. buffer_info->next_to_watch = i;
  4778. buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
  4779. offset, size,
  4780. DMA_TO_DEVICE);
  4781. buffer_info->mapped_as_page = true;
  4782. if (dma_mapping_error(&pdev->dev, buffer_info->dma))
  4783. goto dma_error;
  4784. len -= size;
  4785. offset += size;
  4786. count++;
  4787. }
  4788. }
  4789. segs = skb_shinfo(skb)->gso_segs ? : 1;
  4790. /* multiply data chunks by size of headers */
  4791. bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
  4792. tx_ring->buffer_info[i].skb = skb;
  4793. tx_ring->buffer_info[i].segs = segs;
  4794. tx_ring->buffer_info[i].bytecount = bytecount;
  4795. tx_ring->buffer_info[first].next_to_watch = i;
  4796. return count;
  4797. dma_error:
  4798. dev_err(&pdev->dev, "Tx DMA map failed\n");
  4799. buffer_info->dma = 0;
  4800. if (count)
  4801. count--;
  4802. while (count--) {
  4803. if (i == 0)
  4804. i += tx_ring->count;
  4805. i--;
  4806. buffer_info = &tx_ring->buffer_info[i];
  4807. e1000_put_txbuf(tx_ring, buffer_info, true);
  4808. }
  4809. return 0;
  4810. }
  4811. static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
  4812. {
  4813. struct e1000_adapter *adapter = tx_ring->adapter;
  4814. struct e1000_tx_desc *tx_desc = NULL;
  4815. struct e1000_buffer *buffer_info;
  4816. u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
  4817. unsigned int i;
  4818. if (tx_flags & E1000_TX_FLAGS_TSO) {
  4819. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
  4820. E1000_TXD_CMD_TSE;
  4821. txd_upper |= E1000_TXD_POPTS_TXSM << 8;
  4822. if (tx_flags & E1000_TX_FLAGS_IPV4)
  4823. txd_upper |= E1000_TXD_POPTS_IXSM << 8;
  4824. }
  4825. if (tx_flags & E1000_TX_FLAGS_CSUM) {
  4826. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
  4827. txd_upper |= E1000_TXD_POPTS_TXSM << 8;
  4828. }
  4829. if (tx_flags & E1000_TX_FLAGS_VLAN) {
  4830. txd_lower |= E1000_TXD_CMD_VLE;
  4831. txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
  4832. }
  4833. if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
  4834. txd_lower &= ~(E1000_TXD_CMD_IFCS);
  4835. if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
  4836. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
  4837. txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
  4838. }
  4839. i = tx_ring->next_to_use;
  4840. do {
  4841. buffer_info = &tx_ring->buffer_info[i];
  4842. tx_desc = E1000_TX_DESC(*tx_ring, i);
  4843. tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
  4844. tx_desc->lower.data = cpu_to_le32(txd_lower |
  4845. buffer_info->length);
  4846. tx_desc->upper.data = cpu_to_le32(txd_upper);
  4847. i++;
  4848. if (i == tx_ring->count)
  4849. i = 0;
  4850. } while (--count > 0);
  4851. tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
  4852. /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
  4853. if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
  4854. tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
  4855. /* Force memory writes to complete before letting h/w
  4856. * know there are new descriptors to fetch. (Only
  4857. * applicable for weak-ordered memory model archs,
  4858. * such as IA-64).
  4859. */
  4860. wmb();
  4861. tx_ring->next_to_use = i;
  4862. }
  4863. #define MINIMUM_DHCP_PACKET_SIZE 282
  4864. static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
  4865. struct sk_buff *skb)
  4866. {
  4867. struct e1000_hw *hw = &adapter->hw;
  4868. u16 length, offset;
  4869. if (skb_vlan_tag_present(skb) &&
  4870. !((skb_vlan_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
  4871. (adapter->hw.mng_cookie.status &
  4872. E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
  4873. return 0;
  4874. if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
  4875. return 0;
  4876. if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP))
  4877. return 0;
  4878. {
  4879. const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14);
  4880. struct udphdr *udp;
  4881. if (ip->protocol != IPPROTO_UDP)
  4882. return 0;
  4883. udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
  4884. if (ntohs(udp->dest) != 67)
  4885. return 0;
  4886. offset = (u8 *)udp + 8 - skb->data;
  4887. length = skb->len - offset;
  4888. return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
  4889. }
  4890. return 0;
  4891. }
  4892. static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
  4893. {
  4894. struct e1000_adapter *adapter = tx_ring->adapter;
  4895. netif_stop_queue(adapter->netdev);
  4896. /* Herbert's original patch had:
  4897. * smp_mb__after_netif_stop_queue();
  4898. * but since that doesn't exist yet, just open code it.
  4899. */
  4900. smp_mb();
  4901. /* We need to check again in a case another CPU has just
  4902. * made room available.
  4903. */
  4904. if (e1000_desc_unused(tx_ring) < size)
  4905. return -EBUSY;
  4906. /* A reprieve! */
  4907. netif_start_queue(adapter->netdev);
  4908. ++adapter->restart_queue;
  4909. return 0;
  4910. }
  4911. static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
  4912. {
  4913. BUG_ON(size > tx_ring->count);
  4914. if (e1000_desc_unused(tx_ring) >= size)
  4915. return 0;
  4916. return __e1000_maybe_stop_tx(tx_ring, size);
  4917. }
  4918. static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
  4919. struct net_device *netdev)
  4920. {
  4921. struct e1000_adapter *adapter = netdev_priv(netdev);
  4922. struct e1000_ring *tx_ring = adapter->tx_ring;
  4923. unsigned int first;
  4924. unsigned int tx_flags = 0;
  4925. unsigned int len = skb_headlen(skb);
  4926. unsigned int nr_frags;
  4927. unsigned int mss;
  4928. int count = 0;
  4929. int tso;
  4930. unsigned int f;
  4931. __be16 protocol = vlan_get_protocol(skb);
  4932. if (test_bit(__E1000_DOWN, &adapter->state)) {
  4933. dev_kfree_skb_any(skb);
  4934. return NETDEV_TX_OK;
  4935. }
  4936. if (skb->len <= 0) {
  4937. dev_kfree_skb_any(skb);
  4938. return NETDEV_TX_OK;
  4939. }
  4940. /* The minimum packet size with TCTL.PSP set is 17 bytes so
  4941. * pad skb in order to meet this minimum size requirement
  4942. */
  4943. if (skb_put_padto(skb, 17))
  4944. return NETDEV_TX_OK;
  4945. mss = skb_shinfo(skb)->gso_size;
  4946. if (mss) {
  4947. u8 hdr_len;
  4948. /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
  4949. * points to just header, pull a few bytes of payload from
  4950. * frags into skb->data
  4951. */
  4952. hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  4953. /* we do this workaround for ES2LAN, but it is un-necessary,
  4954. * avoiding it could save a lot of cycles
  4955. */
  4956. if (skb->data_len && (hdr_len == len)) {
  4957. unsigned int pull_size;
  4958. pull_size = min_t(unsigned int, 4, skb->data_len);
  4959. if (!__pskb_pull_tail(skb, pull_size)) {
  4960. e_err("__pskb_pull_tail failed.\n");
  4961. dev_kfree_skb_any(skb);
  4962. return NETDEV_TX_OK;
  4963. }
  4964. len = skb_headlen(skb);
  4965. }
  4966. }
  4967. /* reserve a descriptor for the offload context */
  4968. if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
  4969. count++;
  4970. count++;
  4971. count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
  4972. nr_frags = skb_shinfo(skb)->nr_frags;
  4973. for (f = 0; f < nr_frags; f++)
  4974. count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
  4975. adapter->tx_fifo_limit);
  4976. if (adapter->hw.mac.tx_pkt_filtering)
  4977. e1000_transfer_dhcp_info(adapter, skb);
  4978. /* need: count + 2 desc gap to keep tail from touching
  4979. * head, otherwise try next time
  4980. */
  4981. if (e1000_maybe_stop_tx(tx_ring, count + 2))
  4982. return NETDEV_TX_BUSY;
  4983. if (skb_vlan_tag_present(skb)) {
  4984. tx_flags |= E1000_TX_FLAGS_VLAN;
  4985. tx_flags |= (skb_vlan_tag_get(skb) <<
  4986. E1000_TX_FLAGS_VLAN_SHIFT);
  4987. }
  4988. first = tx_ring->next_to_use;
  4989. tso = e1000_tso(tx_ring, skb, protocol);
  4990. if (tso < 0) {
  4991. dev_kfree_skb_any(skb);
  4992. return NETDEV_TX_OK;
  4993. }
  4994. if (tso)
  4995. tx_flags |= E1000_TX_FLAGS_TSO;
  4996. else if (e1000_tx_csum(tx_ring, skb, protocol))
  4997. tx_flags |= E1000_TX_FLAGS_CSUM;
  4998. /* Old method was to assume IPv4 packet by default if TSO was enabled.
  4999. * 82571 hardware supports TSO capabilities for IPv6 as well...
  5000. * no longer assume, we must.
  5001. */
  5002. if (protocol == htons(ETH_P_IP))
  5003. tx_flags |= E1000_TX_FLAGS_IPV4;
  5004. if (unlikely(skb->no_fcs))
  5005. tx_flags |= E1000_TX_FLAGS_NO_FCS;
  5006. /* if count is 0 then mapping error has occurred */
  5007. count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
  5008. nr_frags);
  5009. if (count) {
  5010. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
  5011. (adapter->flags & FLAG_HAS_HW_TIMESTAMP)) {
  5012. if (!adapter->tx_hwtstamp_skb) {
  5013. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  5014. tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
  5015. adapter->tx_hwtstamp_skb = skb_get(skb);
  5016. adapter->tx_hwtstamp_start = jiffies;
  5017. schedule_work(&adapter->tx_hwtstamp_work);
  5018. } else {
  5019. adapter->tx_hwtstamp_skipped++;
  5020. }
  5021. }
  5022. skb_tx_timestamp(skb);
  5023. netdev_sent_queue(netdev, skb->len);
  5024. e1000_tx_queue(tx_ring, tx_flags, count);
  5025. /* Make sure there is space in the ring for the next send. */
  5026. e1000_maybe_stop_tx(tx_ring,
  5027. (MAX_SKB_FRAGS *
  5028. DIV_ROUND_UP(PAGE_SIZE,
  5029. adapter->tx_fifo_limit) + 2));
  5030. if (!skb->xmit_more ||
  5031. netif_xmit_stopped(netdev_get_tx_queue(netdev, 0))) {
  5032. if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
  5033. e1000e_update_tdt_wa(tx_ring,
  5034. tx_ring->next_to_use);
  5035. else
  5036. writel(tx_ring->next_to_use, tx_ring->tail);
  5037. /* we need this if more than one processor can write
  5038. * to our tail at a time, it synchronizes IO on
  5039. *IA64/Altix systems
  5040. */
  5041. mmiowb();
  5042. }
  5043. } else {
  5044. dev_kfree_skb_any(skb);
  5045. tx_ring->buffer_info[first].time_stamp = 0;
  5046. tx_ring->next_to_use = first;
  5047. }
  5048. return NETDEV_TX_OK;
  5049. }
  5050. /**
  5051. * e1000_tx_timeout - Respond to a Tx Hang
  5052. * @netdev: network interface device structure
  5053. **/
  5054. static void e1000_tx_timeout(struct net_device *netdev)
  5055. {
  5056. struct e1000_adapter *adapter = netdev_priv(netdev);
  5057. /* Do the reset outside of interrupt context */
  5058. adapter->tx_timeout_count++;
  5059. schedule_work(&adapter->reset_task);
  5060. }
  5061. static void e1000_reset_task(struct work_struct *work)
  5062. {
  5063. struct e1000_adapter *adapter;
  5064. adapter = container_of(work, struct e1000_adapter, reset_task);
  5065. rtnl_lock();
  5066. /* don't run the task if already down */
  5067. if (test_bit(__E1000_DOWN, &adapter->state)) {
  5068. rtnl_unlock();
  5069. return;
  5070. }
  5071. if (!(adapter->flags & FLAG_RESTART_NOW)) {
  5072. e1000e_dump(adapter);
  5073. e_err("Reset adapter unexpectedly\n");
  5074. }
  5075. e1000e_reinit_locked(adapter);
  5076. rtnl_unlock();
  5077. }
  5078. /**
  5079. * e1000_get_stats64 - Get System Network Statistics
  5080. * @netdev: network interface device structure
  5081. * @stats: rtnl_link_stats64 pointer
  5082. *
  5083. * Returns the address of the device statistics structure.
  5084. **/
  5085. void e1000e_get_stats64(struct net_device *netdev,
  5086. struct rtnl_link_stats64 *stats)
  5087. {
  5088. struct e1000_adapter *adapter = netdev_priv(netdev);
  5089. spin_lock(&adapter->stats64_lock);
  5090. e1000e_update_stats(adapter);
  5091. /* Fill out the OS statistics structure */
  5092. stats->rx_bytes = adapter->stats.gorc;
  5093. stats->rx_packets = adapter->stats.gprc;
  5094. stats->tx_bytes = adapter->stats.gotc;
  5095. stats->tx_packets = adapter->stats.gptc;
  5096. stats->multicast = adapter->stats.mprc;
  5097. stats->collisions = adapter->stats.colc;
  5098. /* Rx Errors */
  5099. /* RLEC on some newer hardware can be incorrect so build
  5100. * our own version based on RUC and ROC
  5101. */
  5102. stats->rx_errors = adapter->stats.rxerrc +
  5103. adapter->stats.crcerrs + adapter->stats.algnerrc +
  5104. adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
  5105. stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc;
  5106. stats->rx_crc_errors = adapter->stats.crcerrs;
  5107. stats->rx_frame_errors = adapter->stats.algnerrc;
  5108. stats->rx_missed_errors = adapter->stats.mpc;
  5109. /* Tx Errors */
  5110. stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol;
  5111. stats->tx_aborted_errors = adapter->stats.ecol;
  5112. stats->tx_window_errors = adapter->stats.latecol;
  5113. stats->tx_carrier_errors = adapter->stats.tncrs;
  5114. /* Tx Dropped needs to be maintained elsewhere */
  5115. spin_unlock(&adapter->stats64_lock);
  5116. }
  5117. /**
  5118. * e1000_change_mtu - Change the Maximum Transfer Unit
  5119. * @netdev: network interface device structure
  5120. * @new_mtu: new value for maximum frame size
  5121. *
  5122. * Returns 0 on success, negative on failure
  5123. **/
  5124. static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
  5125. {
  5126. struct e1000_adapter *adapter = netdev_priv(netdev);
  5127. int max_frame = new_mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
  5128. /* Jumbo frame support */
  5129. if ((new_mtu > ETH_DATA_LEN) &&
  5130. !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
  5131. e_err("Jumbo Frames not supported.\n");
  5132. return -EINVAL;
  5133. }
  5134. /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
  5135. if ((adapter->hw.mac.type >= e1000_pch2lan) &&
  5136. !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
  5137. (new_mtu > ETH_DATA_LEN)) {
  5138. e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
  5139. return -EINVAL;
  5140. }
  5141. while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
  5142. usleep_range(1000, 2000);
  5143. /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
  5144. adapter->max_frame_size = max_frame;
  5145. e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
  5146. netdev->mtu = new_mtu;
  5147. pm_runtime_get_sync(netdev->dev.parent);
  5148. if (netif_running(netdev))
  5149. e1000e_down(adapter, true);
  5150. /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
  5151. * means we reserve 2 more, this pushes us to allocate from the next
  5152. * larger slab size.
  5153. * i.e. RXBUFFER_2048 --> size-4096 slab
  5154. * However with the new *_jumbo_rx* routines, jumbo receives will use
  5155. * fragmented skbs
  5156. */
  5157. if (max_frame <= 2048)
  5158. adapter->rx_buffer_len = 2048;
  5159. else
  5160. adapter->rx_buffer_len = 4096;
  5161. /* adjust allocation if LPE protects us, and we aren't using SBP */
  5162. if (max_frame <= (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN))
  5163. adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN;
  5164. if (netif_running(netdev))
  5165. e1000e_up(adapter);
  5166. else
  5167. e1000e_reset(adapter);
  5168. pm_runtime_put_sync(netdev->dev.parent);
  5169. clear_bit(__E1000_RESETTING, &adapter->state);
  5170. return 0;
  5171. }
  5172. static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
  5173. int cmd)
  5174. {
  5175. struct e1000_adapter *adapter = netdev_priv(netdev);
  5176. struct mii_ioctl_data *data = if_mii(ifr);
  5177. if (adapter->hw.phy.media_type != e1000_media_type_copper)
  5178. return -EOPNOTSUPP;
  5179. switch (cmd) {
  5180. case SIOCGMIIPHY:
  5181. data->phy_id = adapter->hw.phy.addr;
  5182. break;
  5183. case SIOCGMIIREG:
  5184. e1000_phy_read_status(adapter);
  5185. switch (data->reg_num & 0x1F) {
  5186. case MII_BMCR:
  5187. data->val_out = adapter->phy_regs.bmcr;
  5188. break;
  5189. case MII_BMSR:
  5190. data->val_out = adapter->phy_regs.bmsr;
  5191. break;
  5192. case MII_PHYSID1:
  5193. data->val_out = (adapter->hw.phy.id >> 16);
  5194. break;
  5195. case MII_PHYSID2:
  5196. data->val_out = (adapter->hw.phy.id & 0xFFFF);
  5197. break;
  5198. case MII_ADVERTISE:
  5199. data->val_out = adapter->phy_regs.advertise;
  5200. break;
  5201. case MII_LPA:
  5202. data->val_out = adapter->phy_regs.lpa;
  5203. break;
  5204. case MII_EXPANSION:
  5205. data->val_out = adapter->phy_regs.expansion;
  5206. break;
  5207. case MII_CTRL1000:
  5208. data->val_out = adapter->phy_regs.ctrl1000;
  5209. break;
  5210. case MII_STAT1000:
  5211. data->val_out = adapter->phy_regs.stat1000;
  5212. break;
  5213. case MII_ESTATUS:
  5214. data->val_out = adapter->phy_regs.estatus;
  5215. break;
  5216. default:
  5217. return -EIO;
  5218. }
  5219. break;
  5220. case SIOCSMIIREG:
  5221. default:
  5222. return -EOPNOTSUPP;
  5223. }
  5224. return 0;
  5225. }
  5226. /**
  5227. * e1000e_hwtstamp_ioctl - control hardware time stamping
  5228. * @netdev: network interface device structure
  5229. * @ifreq: interface request
  5230. *
  5231. * Outgoing time stamping can be enabled and disabled. Play nice and
  5232. * disable it when requested, although it shouldn't cause any overhead
  5233. * when no packet needs it. At most one packet in the queue may be
  5234. * marked for time stamping, otherwise it would be impossible to tell
  5235. * for sure to which packet the hardware time stamp belongs.
  5236. *
  5237. * Incoming time stamping has to be configured via the hardware filters.
  5238. * Not all combinations are supported, in particular event type has to be
  5239. * specified. Matching the kind of event packet is not supported, with the
  5240. * exception of "all V2 events regardless of level 2 or 4".
  5241. **/
  5242. static int e1000e_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
  5243. {
  5244. struct e1000_adapter *adapter = netdev_priv(netdev);
  5245. struct hwtstamp_config config;
  5246. int ret_val;
  5247. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  5248. return -EFAULT;
  5249. ret_val = e1000e_config_hwtstamp(adapter, &config);
  5250. if (ret_val)
  5251. return ret_val;
  5252. switch (config.rx_filter) {
  5253. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  5254. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  5255. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  5256. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  5257. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  5258. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  5259. /* With V2 type filters which specify a Sync or Delay Request,
  5260. * Path Delay Request/Response messages are also time stamped
  5261. * by hardware so notify the caller the requested packets plus
  5262. * some others are time stamped.
  5263. */
  5264. config.rx_filter = HWTSTAMP_FILTER_SOME;
  5265. break;
  5266. default:
  5267. break;
  5268. }
  5269. return copy_to_user(ifr->ifr_data, &config,
  5270. sizeof(config)) ? -EFAULT : 0;
  5271. }
  5272. static int e1000e_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr)
  5273. {
  5274. struct e1000_adapter *adapter = netdev_priv(netdev);
  5275. return copy_to_user(ifr->ifr_data, &adapter->hwtstamp_config,
  5276. sizeof(adapter->hwtstamp_config)) ? -EFAULT : 0;
  5277. }
  5278. static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  5279. {
  5280. switch (cmd) {
  5281. case SIOCGMIIPHY:
  5282. case SIOCGMIIREG:
  5283. case SIOCSMIIREG:
  5284. return e1000_mii_ioctl(netdev, ifr, cmd);
  5285. case SIOCSHWTSTAMP:
  5286. return e1000e_hwtstamp_set(netdev, ifr);
  5287. case SIOCGHWTSTAMP:
  5288. return e1000e_hwtstamp_get(netdev, ifr);
  5289. default:
  5290. return -EOPNOTSUPP;
  5291. }
  5292. }
  5293. static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
  5294. {
  5295. struct e1000_hw *hw = &adapter->hw;
  5296. u32 i, mac_reg, wuc;
  5297. u16 phy_reg, wuc_enable;
  5298. int retval;
  5299. /* copy MAC RARs to PHY RARs */
  5300. e1000_copy_rx_addrs_to_phy_ich8lan(hw);
  5301. retval = hw->phy.ops.acquire(hw);
  5302. if (retval) {
  5303. e_err("Could not acquire PHY\n");
  5304. return retval;
  5305. }
  5306. /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
  5307. retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
  5308. if (retval)
  5309. goto release;
  5310. /* copy MAC MTA to PHY MTA - only needed for pchlan */
  5311. for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
  5312. mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
  5313. hw->phy.ops.write_reg_page(hw, BM_MTA(i),
  5314. (u16)(mac_reg & 0xFFFF));
  5315. hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
  5316. (u16)((mac_reg >> 16) & 0xFFFF));
  5317. }
  5318. /* configure PHY Rx Control register */
  5319. hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
  5320. mac_reg = er32(RCTL);
  5321. if (mac_reg & E1000_RCTL_UPE)
  5322. phy_reg |= BM_RCTL_UPE;
  5323. if (mac_reg & E1000_RCTL_MPE)
  5324. phy_reg |= BM_RCTL_MPE;
  5325. phy_reg &= ~(BM_RCTL_MO_MASK);
  5326. if (mac_reg & E1000_RCTL_MO_3)
  5327. phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
  5328. << BM_RCTL_MO_SHIFT);
  5329. if (mac_reg & E1000_RCTL_BAM)
  5330. phy_reg |= BM_RCTL_BAM;
  5331. if (mac_reg & E1000_RCTL_PMCF)
  5332. phy_reg |= BM_RCTL_PMCF;
  5333. mac_reg = er32(CTRL);
  5334. if (mac_reg & E1000_CTRL_RFCE)
  5335. phy_reg |= BM_RCTL_RFCE;
  5336. hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
  5337. wuc = E1000_WUC_PME_EN;
  5338. if (wufc & (E1000_WUFC_MAG | E1000_WUFC_LNKC))
  5339. wuc |= E1000_WUC_APME;
  5340. /* enable PHY wakeup in MAC register */
  5341. ew32(WUFC, wufc);
  5342. ew32(WUC, (E1000_WUC_PHY_WAKE | E1000_WUC_APMPME |
  5343. E1000_WUC_PME_STATUS | wuc));
  5344. /* configure and enable PHY wakeup in PHY registers */
  5345. hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
  5346. hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, wuc);
  5347. /* activate PHY wakeup */
  5348. wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
  5349. retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
  5350. if (retval)
  5351. e_err("Could not set PHY Host Wakeup bit\n");
  5352. release:
  5353. hw->phy.ops.release(hw);
  5354. return retval;
  5355. }
  5356. static void e1000e_flush_lpic(struct pci_dev *pdev)
  5357. {
  5358. struct net_device *netdev = pci_get_drvdata(pdev);
  5359. struct e1000_adapter *adapter = netdev_priv(netdev);
  5360. struct e1000_hw *hw = &adapter->hw;
  5361. u32 ret_val;
  5362. pm_runtime_get_sync(netdev->dev.parent);
  5363. ret_val = hw->phy.ops.acquire(hw);
  5364. if (ret_val)
  5365. goto fl_out;
  5366. pr_info("EEE TX LPI TIMER: %08X\n",
  5367. er32(LPIC) >> E1000_LPIC_LPIET_SHIFT);
  5368. hw->phy.ops.release(hw);
  5369. fl_out:
  5370. pm_runtime_put_sync(netdev->dev.parent);
  5371. }
  5372. static int e1000e_pm_freeze(struct device *dev)
  5373. {
  5374. struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
  5375. struct e1000_adapter *adapter = netdev_priv(netdev);
  5376. netif_device_detach(netdev);
  5377. if (netif_running(netdev)) {
  5378. int count = E1000_CHECK_RESET_COUNT;
  5379. while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
  5380. usleep_range(10000, 20000);
  5381. WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
  5382. /* Quiesce the device without resetting the hardware */
  5383. e1000e_down(adapter, false);
  5384. e1000_free_irq(adapter);
  5385. }
  5386. e1000e_reset_interrupt_capability(adapter);
  5387. /* Allow time for pending master requests to run */
  5388. e1000e_disable_pcie_master(&adapter->hw);
  5389. return 0;
  5390. }
  5391. static int __e1000_shutdown(struct pci_dev *pdev, bool runtime)
  5392. {
  5393. struct net_device *netdev = pci_get_drvdata(pdev);
  5394. struct e1000_adapter *adapter = netdev_priv(netdev);
  5395. struct e1000_hw *hw = &adapter->hw;
  5396. u32 ctrl, ctrl_ext, rctl, status, wufc;
  5397. int retval = 0;
  5398. /* Runtime suspend should only enable wakeup for link changes */
  5399. if (runtime)
  5400. wufc = E1000_WUFC_LNKC;
  5401. else if (device_may_wakeup(&pdev->dev))
  5402. wufc = adapter->wol;
  5403. else
  5404. wufc = 0;
  5405. status = er32(STATUS);
  5406. if (status & E1000_STATUS_LU)
  5407. wufc &= ~E1000_WUFC_LNKC;
  5408. if (wufc) {
  5409. e1000_setup_rctl(adapter);
  5410. e1000e_set_rx_mode(netdev);
  5411. /* turn on all-multi mode if wake on multicast is enabled */
  5412. if (wufc & E1000_WUFC_MC) {
  5413. rctl = er32(RCTL);
  5414. rctl |= E1000_RCTL_MPE;
  5415. ew32(RCTL, rctl);
  5416. }
  5417. ctrl = er32(CTRL);
  5418. ctrl |= E1000_CTRL_ADVD3WUC;
  5419. if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
  5420. ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
  5421. ew32(CTRL, ctrl);
  5422. if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
  5423. adapter->hw.phy.media_type ==
  5424. e1000_media_type_internal_serdes) {
  5425. /* keep the laser running in D3 */
  5426. ctrl_ext = er32(CTRL_EXT);
  5427. ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
  5428. ew32(CTRL_EXT, ctrl_ext);
  5429. }
  5430. if (!runtime)
  5431. e1000e_power_up_phy(adapter);
  5432. if (adapter->flags & FLAG_IS_ICH)
  5433. e1000_suspend_workarounds_ich8lan(&adapter->hw);
  5434. if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
  5435. /* enable wakeup by the PHY */
  5436. retval = e1000_init_phy_wakeup(adapter, wufc);
  5437. if (retval)
  5438. return retval;
  5439. } else {
  5440. /* enable wakeup by the MAC */
  5441. ew32(WUFC, wufc);
  5442. ew32(WUC, E1000_WUC_PME_EN);
  5443. }
  5444. } else {
  5445. ew32(WUC, 0);
  5446. ew32(WUFC, 0);
  5447. e1000_power_down_phy(adapter);
  5448. }
  5449. if (adapter->hw.phy.type == e1000_phy_igp_3) {
  5450. e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
  5451. } else if (hw->mac.type >= e1000_pch_lpt) {
  5452. if (wufc && !(wufc & (E1000_WUFC_EX | E1000_WUFC_MC | E1000_WUFC_BC)))
  5453. /* ULP does not support wake from unicast, multicast
  5454. * or broadcast.
  5455. */
  5456. retval = e1000_enable_ulp_lpt_lp(hw, !runtime);
  5457. if (retval)
  5458. return retval;
  5459. }
  5460. /* Ensure that the appropriate bits are set in LPI_CTRL
  5461. * for EEE in Sx
  5462. */
  5463. if ((hw->phy.type >= e1000_phy_i217) &&
  5464. adapter->eee_advert && hw->dev_spec.ich8lan.eee_lp_ability) {
  5465. u16 lpi_ctrl = 0;
  5466. retval = hw->phy.ops.acquire(hw);
  5467. if (!retval) {
  5468. retval = e1e_rphy_locked(hw, I82579_LPI_CTRL,
  5469. &lpi_ctrl);
  5470. if (!retval) {
  5471. if (adapter->eee_advert &
  5472. hw->dev_spec.ich8lan.eee_lp_ability &
  5473. I82579_EEE_100_SUPPORTED)
  5474. lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
  5475. if (adapter->eee_advert &
  5476. hw->dev_spec.ich8lan.eee_lp_ability &
  5477. I82579_EEE_1000_SUPPORTED)
  5478. lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
  5479. retval = e1e_wphy_locked(hw, I82579_LPI_CTRL,
  5480. lpi_ctrl);
  5481. }
  5482. }
  5483. hw->phy.ops.release(hw);
  5484. }
  5485. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  5486. * would have already happened in close and is redundant.
  5487. */
  5488. e1000e_release_hw_control(adapter);
  5489. pci_clear_master(pdev);
  5490. /* The pci-e switch on some quad port adapters will report a
  5491. * correctable error when the MAC transitions from D0 to D3. To
  5492. * prevent this we need to mask off the correctable errors on the
  5493. * downstream port of the pci-e switch.
  5494. *
  5495. * We don't have the associated upstream bridge while assigning
  5496. * the PCI device into guest. For example, the KVM on power is
  5497. * one of the cases.
  5498. */
  5499. if (adapter->flags & FLAG_IS_QUAD_PORT) {
  5500. struct pci_dev *us_dev = pdev->bus->self;
  5501. u16 devctl;
  5502. if (!us_dev)
  5503. return 0;
  5504. pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
  5505. pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
  5506. (devctl & ~PCI_EXP_DEVCTL_CERE));
  5507. pci_save_state(pdev);
  5508. pci_prepare_to_sleep(pdev);
  5509. pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
  5510. }
  5511. return 0;
  5512. }
  5513. /**
  5514. * __e1000e_disable_aspm - Disable ASPM states
  5515. * @pdev: pointer to PCI device struct
  5516. * @state: bit-mask of ASPM states to disable
  5517. * @locked: indication if this context holds pci_bus_sem locked.
  5518. *
  5519. * Some devices *must* have certain ASPM states disabled per hardware errata.
  5520. **/
  5521. static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state, int locked)
  5522. {
  5523. struct pci_dev *parent = pdev->bus->self;
  5524. u16 aspm_dis_mask = 0;
  5525. u16 pdev_aspmc, parent_aspmc;
  5526. switch (state) {
  5527. case PCIE_LINK_STATE_L0S:
  5528. case PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1:
  5529. aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L0S;
  5530. /* fall-through - can't have L1 without L0s */
  5531. case PCIE_LINK_STATE_L1:
  5532. aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L1;
  5533. break;
  5534. default:
  5535. return;
  5536. }
  5537. pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
  5538. pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
  5539. if (parent) {
  5540. pcie_capability_read_word(parent, PCI_EXP_LNKCTL,
  5541. &parent_aspmc);
  5542. parent_aspmc &= PCI_EXP_LNKCTL_ASPMC;
  5543. }
  5544. /* Nothing to do if the ASPM states to be disabled already are */
  5545. if (!(pdev_aspmc & aspm_dis_mask) &&
  5546. (!parent || !(parent_aspmc & aspm_dis_mask)))
  5547. return;
  5548. dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
  5549. (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L0S) ?
  5550. "L0s" : "",
  5551. (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L1) ?
  5552. "L1" : "");
  5553. #ifdef CONFIG_PCIEASPM
  5554. if (locked)
  5555. pci_disable_link_state_locked(pdev, state);
  5556. else
  5557. pci_disable_link_state(pdev, state);
  5558. /* Double-check ASPM control. If not disabled by the above, the
  5559. * BIOS is preventing that from happening (or CONFIG_PCIEASPM is
  5560. * not enabled); override by writing PCI config space directly.
  5561. */
  5562. pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
  5563. pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
  5564. if (!(aspm_dis_mask & pdev_aspmc))
  5565. return;
  5566. #endif
  5567. /* Both device and parent should have the same ASPM setting.
  5568. * Disable ASPM in downstream component first and then upstream.
  5569. */
  5570. pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_dis_mask);
  5571. if (parent)
  5572. pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
  5573. aspm_dis_mask);
  5574. }
  5575. /**
  5576. * e1000e_disable_aspm - Disable ASPM states.
  5577. * @pdev: pointer to PCI device struct
  5578. * @state: bit-mask of ASPM states to disable
  5579. *
  5580. * This function acquires the pci_bus_sem!
  5581. * Some devices *must* have certain ASPM states disabled per hardware errata.
  5582. **/
  5583. static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
  5584. {
  5585. __e1000e_disable_aspm(pdev, state, 0);
  5586. }
  5587. /**
  5588. * e1000e_disable_aspm_locked Disable ASPM states.
  5589. * @pdev: pointer to PCI device struct
  5590. * @state: bit-mask of ASPM states to disable
  5591. *
  5592. * This function must be called with pci_bus_sem acquired!
  5593. * Some devices *must* have certain ASPM states disabled per hardware errata.
  5594. **/
  5595. static void e1000e_disable_aspm_locked(struct pci_dev *pdev, u16 state)
  5596. {
  5597. __e1000e_disable_aspm(pdev, state, 1);
  5598. }
  5599. #ifdef CONFIG_PM
  5600. static int __e1000_resume(struct pci_dev *pdev)
  5601. {
  5602. struct net_device *netdev = pci_get_drvdata(pdev);
  5603. struct e1000_adapter *adapter = netdev_priv(netdev);
  5604. struct e1000_hw *hw = &adapter->hw;
  5605. u16 aspm_disable_flag = 0;
  5606. if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
  5607. aspm_disable_flag = PCIE_LINK_STATE_L0S;
  5608. if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
  5609. aspm_disable_flag |= PCIE_LINK_STATE_L1;
  5610. if (aspm_disable_flag)
  5611. e1000e_disable_aspm(pdev, aspm_disable_flag);
  5612. pci_set_master(pdev);
  5613. if (hw->mac.type >= e1000_pch2lan)
  5614. e1000_resume_workarounds_pchlan(&adapter->hw);
  5615. e1000e_power_up_phy(adapter);
  5616. /* report the system wakeup cause from S3/S4 */
  5617. if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
  5618. u16 phy_data;
  5619. e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
  5620. if (phy_data) {
  5621. e_info("PHY Wakeup cause - %s\n",
  5622. phy_data & E1000_WUS_EX ? "Unicast Packet" :
  5623. phy_data & E1000_WUS_MC ? "Multicast Packet" :
  5624. phy_data & E1000_WUS_BC ? "Broadcast Packet" :
  5625. phy_data & E1000_WUS_MAG ? "Magic Packet" :
  5626. phy_data & E1000_WUS_LNKC ?
  5627. "Link Status Change" : "other");
  5628. }
  5629. e1e_wphy(&adapter->hw, BM_WUS, ~0);
  5630. } else {
  5631. u32 wus = er32(WUS);
  5632. if (wus) {
  5633. e_info("MAC Wakeup cause - %s\n",
  5634. wus & E1000_WUS_EX ? "Unicast Packet" :
  5635. wus & E1000_WUS_MC ? "Multicast Packet" :
  5636. wus & E1000_WUS_BC ? "Broadcast Packet" :
  5637. wus & E1000_WUS_MAG ? "Magic Packet" :
  5638. wus & E1000_WUS_LNKC ? "Link Status Change" :
  5639. "other");
  5640. }
  5641. ew32(WUS, ~0);
  5642. }
  5643. e1000e_reset(adapter);
  5644. e1000_init_manageability_pt(adapter);
  5645. /* If the controller has AMT, do not set DRV_LOAD until the interface
  5646. * is up. For all other cases, let the f/w know that the h/w is now
  5647. * under the control of the driver.
  5648. */
  5649. if (!(adapter->flags & FLAG_HAS_AMT))
  5650. e1000e_get_hw_control(adapter);
  5651. return 0;
  5652. }
  5653. #ifdef CONFIG_PM_SLEEP
  5654. static int e1000e_pm_thaw(struct device *dev)
  5655. {
  5656. struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
  5657. struct e1000_adapter *adapter = netdev_priv(netdev);
  5658. e1000e_set_interrupt_capability(adapter);
  5659. if (netif_running(netdev)) {
  5660. u32 err = e1000_request_irq(adapter);
  5661. if (err)
  5662. return err;
  5663. e1000e_up(adapter);
  5664. }
  5665. netif_device_attach(netdev);
  5666. return 0;
  5667. }
  5668. static int e1000e_pm_suspend(struct device *dev)
  5669. {
  5670. struct pci_dev *pdev = to_pci_dev(dev);
  5671. int rc;
  5672. e1000e_flush_lpic(pdev);
  5673. e1000e_pm_freeze(dev);
  5674. rc = __e1000_shutdown(pdev, false);
  5675. if (rc)
  5676. e1000e_pm_thaw(dev);
  5677. return rc;
  5678. }
  5679. static int e1000e_pm_resume(struct device *dev)
  5680. {
  5681. struct pci_dev *pdev = to_pci_dev(dev);
  5682. int rc;
  5683. rc = __e1000_resume(pdev);
  5684. if (rc)
  5685. return rc;
  5686. return e1000e_pm_thaw(dev);
  5687. }
  5688. #endif /* CONFIG_PM_SLEEP */
  5689. static int e1000e_pm_runtime_idle(struct device *dev)
  5690. {
  5691. struct pci_dev *pdev = to_pci_dev(dev);
  5692. struct net_device *netdev = pci_get_drvdata(pdev);
  5693. struct e1000_adapter *adapter = netdev_priv(netdev);
  5694. u16 eee_lp;
  5695. eee_lp = adapter->hw.dev_spec.ich8lan.eee_lp_ability;
  5696. if (!e1000e_has_link(adapter)) {
  5697. adapter->hw.dev_spec.ich8lan.eee_lp_ability = eee_lp;
  5698. pm_schedule_suspend(dev, 5 * MSEC_PER_SEC);
  5699. }
  5700. return -EBUSY;
  5701. }
  5702. static int e1000e_pm_runtime_resume(struct device *dev)
  5703. {
  5704. struct pci_dev *pdev = to_pci_dev(dev);
  5705. struct net_device *netdev = pci_get_drvdata(pdev);
  5706. struct e1000_adapter *adapter = netdev_priv(netdev);
  5707. int rc;
  5708. rc = __e1000_resume(pdev);
  5709. if (rc)
  5710. return rc;
  5711. if (netdev->flags & IFF_UP)
  5712. e1000e_up(adapter);
  5713. return rc;
  5714. }
  5715. static int e1000e_pm_runtime_suspend(struct device *dev)
  5716. {
  5717. struct pci_dev *pdev = to_pci_dev(dev);
  5718. struct net_device *netdev = pci_get_drvdata(pdev);
  5719. struct e1000_adapter *adapter = netdev_priv(netdev);
  5720. if (netdev->flags & IFF_UP) {
  5721. int count = E1000_CHECK_RESET_COUNT;
  5722. while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
  5723. usleep_range(10000, 20000);
  5724. WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
  5725. /* Down the device without resetting the hardware */
  5726. e1000e_down(adapter, false);
  5727. }
  5728. if (__e1000_shutdown(pdev, true)) {
  5729. e1000e_pm_runtime_resume(dev);
  5730. return -EBUSY;
  5731. }
  5732. return 0;
  5733. }
  5734. #endif /* CONFIG_PM */
  5735. static void e1000_shutdown(struct pci_dev *pdev)
  5736. {
  5737. e1000e_flush_lpic(pdev);
  5738. e1000e_pm_freeze(&pdev->dev);
  5739. __e1000_shutdown(pdev, false);
  5740. }
  5741. #ifdef CONFIG_NET_POLL_CONTROLLER
  5742. static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
  5743. {
  5744. struct net_device *netdev = data;
  5745. struct e1000_adapter *adapter = netdev_priv(netdev);
  5746. if (adapter->msix_entries) {
  5747. int vector, msix_irq;
  5748. vector = 0;
  5749. msix_irq = adapter->msix_entries[vector].vector;
  5750. if (disable_hardirq(msix_irq))
  5751. e1000_intr_msix_rx(msix_irq, netdev);
  5752. enable_irq(msix_irq);
  5753. vector++;
  5754. msix_irq = adapter->msix_entries[vector].vector;
  5755. if (disable_hardirq(msix_irq))
  5756. e1000_intr_msix_tx(msix_irq, netdev);
  5757. enable_irq(msix_irq);
  5758. vector++;
  5759. msix_irq = adapter->msix_entries[vector].vector;
  5760. if (disable_hardirq(msix_irq))
  5761. e1000_msix_other(msix_irq, netdev);
  5762. enable_irq(msix_irq);
  5763. }
  5764. return IRQ_HANDLED;
  5765. }
  5766. /**
  5767. * e1000_netpoll
  5768. * @netdev: network interface device structure
  5769. *
  5770. * Polling 'interrupt' - used by things like netconsole to send skbs
  5771. * without having to re-enable interrupts. It's not called while
  5772. * the interrupt routine is executing.
  5773. */
  5774. static void e1000_netpoll(struct net_device *netdev)
  5775. {
  5776. struct e1000_adapter *adapter = netdev_priv(netdev);
  5777. switch (adapter->int_mode) {
  5778. case E1000E_INT_MODE_MSIX:
  5779. e1000_intr_msix(adapter->pdev->irq, netdev);
  5780. break;
  5781. case E1000E_INT_MODE_MSI:
  5782. if (disable_hardirq(adapter->pdev->irq))
  5783. e1000_intr_msi(adapter->pdev->irq, netdev);
  5784. enable_irq(adapter->pdev->irq);
  5785. break;
  5786. default: /* E1000E_INT_MODE_LEGACY */
  5787. if (disable_hardirq(adapter->pdev->irq))
  5788. e1000_intr(adapter->pdev->irq, netdev);
  5789. enable_irq(adapter->pdev->irq);
  5790. break;
  5791. }
  5792. }
  5793. #endif
  5794. /**
  5795. * e1000_io_error_detected - called when PCI error is detected
  5796. * @pdev: Pointer to PCI device
  5797. * @state: The current pci connection state
  5798. *
  5799. * This function is called after a PCI bus error affecting
  5800. * this device has been detected.
  5801. */
  5802. static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
  5803. pci_channel_state_t state)
  5804. {
  5805. struct net_device *netdev = pci_get_drvdata(pdev);
  5806. struct e1000_adapter *adapter = netdev_priv(netdev);
  5807. netif_device_detach(netdev);
  5808. if (state == pci_channel_io_perm_failure)
  5809. return PCI_ERS_RESULT_DISCONNECT;
  5810. if (netif_running(netdev))
  5811. e1000e_down(adapter, true);
  5812. pci_disable_device(pdev);
  5813. /* Request a slot slot reset. */
  5814. return PCI_ERS_RESULT_NEED_RESET;
  5815. }
  5816. /**
  5817. * e1000_io_slot_reset - called after the pci bus has been reset.
  5818. * @pdev: Pointer to PCI device
  5819. *
  5820. * Restart the card from scratch, as if from a cold-boot. Implementation
  5821. * resembles the first-half of the e1000e_pm_resume routine.
  5822. */
  5823. static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
  5824. {
  5825. struct net_device *netdev = pci_get_drvdata(pdev);
  5826. struct e1000_adapter *adapter = netdev_priv(netdev);
  5827. struct e1000_hw *hw = &adapter->hw;
  5828. u16 aspm_disable_flag = 0;
  5829. int err;
  5830. pci_ers_result_t result;
  5831. if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
  5832. aspm_disable_flag = PCIE_LINK_STATE_L0S;
  5833. if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
  5834. aspm_disable_flag |= PCIE_LINK_STATE_L1;
  5835. if (aspm_disable_flag)
  5836. e1000e_disable_aspm_locked(pdev, aspm_disable_flag);
  5837. err = pci_enable_device_mem(pdev);
  5838. if (err) {
  5839. dev_err(&pdev->dev,
  5840. "Cannot re-enable PCI device after reset.\n");
  5841. result = PCI_ERS_RESULT_DISCONNECT;
  5842. } else {
  5843. pdev->state_saved = true;
  5844. pci_restore_state(pdev);
  5845. pci_set_master(pdev);
  5846. pci_enable_wake(pdev, PCI_D3hot, 0);
  5847. pci_enable_wake(pdev, PCI_D3cold, 0);
  5848. e1000e_reset(adapter);
  5849. ew32(WUS, ~0);
  5850. result = PCI_ERS_RESULT_RECOVERED;
  5851. }
  5852. pci_cleanup_aer_uncorrect_error_status(pdev);
  5853. return result;
  5854. }
  5855. /**
  5856. * e1000_io_resume - called when traffic can start flowing again.
  5857. * @pdev: Pointer to PCI device
  5858. *
  5859. * This callback is called when the error recovery driver tells us that
  5860. * its OK to resume normal operation. Implementation resembles the
  5861. * second-half of the e1000e_pm_resume routine.
  5862. */
  5863. static void e1000_io_resume(struct pci_dev *pdev)
  5864. {
  5865. struct net_device *netdev = pci_get_drvdata(pdev);
  5866. struct e1000_adapter *adapter = netdev_priv(netdev);
  5867. e1000_init_manageability_pt(adapter);
  5868. if (netif_running(netdev))
  5869. e1000e_up(adapter);
  5870. netif_device_attach(netdev);
  5871. /* If the controller has AMT, do not set DRV_LOAD until the interface
  5872. * is up. For all other cases, let the f/w know that the h/w is now
  5873. * under the control of the driver.
  5874. */
  5875. if (!(adapter->flags & FLAG_HAS_AMT))
  5876. e1000e_get_hw_control(adapter);
  5877. }
  5878. static void e1000_print_device_info(struct e1000_adapter *adapter)
  5879. {
  5880. struct e1000_hw *hw = &adapter->hw;
  5881. struct net_device *netdev = adapter->netdev;
  5882. u32 ret_val;
  5883. u8 pba_str[E1000_PBANUM_LENGTH];
  5884. /* print bus type/speed/width info */
  5885. e_info("(PCI Express:2.5GT/s:%s) %pM\n",
  5886. /* bus width */
  5887. ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
  5888. "Width x1"),
  5889. /* MAC address */
  5890. netdev->dev_addr);
  5891. e_info("Intel(R) PRO/%s Network Connection\n",
  5892. (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
  5893. ret_val = e1000_read_pba_string_generic(hw, pba_str,
  5894. E1000_PBANUM_LENGTH);
  5895. if (ret_val)
  5896. strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
  5897. e_info("MAC: %d, PHY: %d, PBA No: %s\n",
  5898. hw->mac.type, hw->phy.type, pba_str);
  5899. }
  5900. static void e1000_eeprom_checks(struct e1000_adapter *adapter)
  5901. {
  5902. struct e1000_hw *hw = &adapter->hw;
  5903. int ret_val;
  5904. u16 buf = 0;
  5905. if (hw->mac.type != e1000_82573)
  5906. return;
  5907. ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
  5908. le16_to_cpus(&buf);
  5909. if (!ret_val && (!(buf & BIT(0)))) {
  5910. /* Deep Smart Power Down (DSPD) */
  5911. dev_warn(&adapter->pdev->dev,
  5912. "Warning: detected DSPD enabled in EEPROM\n");
  5913. }
  5914. }
  5915. static netdev_features_t e1000_fix_features(struct net_device *netdev,
  5916. netdev_features_t features)
  5917. {
  5918. struct e1000_adapter *adapter = netdev_priv(netdev);
  5919. struct e1000_hw *hw = &adapter->hw;
  5920. /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
  5921. if ((hw->mac.type >= e1000_pch2lan) && (netdev->mtu > ETH_DATA_LEN))
  5922. features &= ~NETIF_F_RXFCS;
  5923. /* Since there is no support for separate Rx/Tx vlan accel
  5924. * enable/disable make sure Tx flag is always in same state as Rx.
  5925. */
  5926. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  5927. features |= NETIF_F_HW_VLAN_CTAG_TX;
  5928. else
  5929. features &= ~NETIF_F_HW_VLAN_CTAG_TX;
  5930. return features;
  5931. }
  5932. static int e1000_set_features(struct net_device *netdev,
  5933. netdev_features_t features)
  5934. {
  5935. struct e1000_adapter *adapter = netdev_priv(netdev);
  5936. netdev_features_t changed = features ^ netdev->features;
  5937. if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
  5938. adapter->flags |= FLAG_TSO_FORCE;
  5939. if (!(changed & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
  5940. NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
  5941. NETIF_F_RXALL)))
  5942. return 0;
  5943. if (changed & NETIF_F_RXFCS) {
  5944. if (features & NETIF_F_RXFCS) {
  5945. adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
  5946. } else {
  5947. /* We need to take it back to defaults, which might mean
  5948. * stripping is still disabled at the adapter level.
  5949. */
  5950. if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
  5951. adapter->flags2 |= FLAG2_CRC_STRIPPING;
  5952. else
  5953. adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
  5954. }
  5955. }
  5956. netdev->features = features;
  5957. if (netif_running(netdev))
  5958. e1000e_reinit_locked(adapter);
  5959. else
  5960. e1000e_reset(adapter);
  5961. return 0;
  5962. }
  5963. static const struct net_device_ops e1000e_netdev_ops = {
  5964. .ndo_open = e1000e_open,
  5965. .ndo_stop = e1000e_close,
  5966. .ndo_start_xmit = e1000_xmit_frame,
  5967. .ndo_get_stats64 = e1000e_get_stats64,
  5968. .ndo_set_rx_mode = e1000e_set_rx_mode,
  5969. .ndo_set_mac_address = e1000_set_mac,
  5970. .ndo_change_mtu = e1000_change_mtu,
  5971. .ndo_do_ioctl = e1000_ioctl,
  5972. .ndo_tx_timeout = e1000_tx_timeout,
  5973. .ndo_validate_addr = eth_validate_addr,
  5974. .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
  5975. .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
  5976. #ifdef CONFIG_NET_POLL_CONTROLLER
  5977. .ndo_poll_controller = e1000_netpoll,
  5978. #endif
  5979. .ndo_set_features = e1000_set_features,
  5980. .ndo_fix_features = e1000_fix_features,
  5981. .ndo_features_check = passthru_features_check,
  5982. };
  5983. /**
  5984. * e1000_probe - Device Initialization Routine
  5985. * @pdev: PCI device information struct
  5986. * @ent: entry in e1000_pci_tbl
  5987. *
  5988. * Returns 0 on success, negative on failure
  5989. *
  5990. * e1000_probe initializes an adapter identified by a pci_dev structure.
  5991. * The OS initialization, configuring of the adapter private structure,
  5992. * and a hardware reset occur.
  5993. **/
  5994. static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  5995. {
  5996. struct net_device *netdev;
  5997. struct e1000_adapter *adapter;
  5998. struct e1000_hw *hw;
  5999. const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
  6000. resource_size_t mmio_start, mmio_len;
  6001. resource_size_t flash_start, flash_len;
  6002. static int cards_found;
  6003. u16 aspm_disable_flag = 0;
  6004. int bars, i, err, pci_using_dac;
  6005. u16 eeprom_data = 0;
  6006. u16 eeprom_apme_mask = E1000_EEPROM_APME;
  6007. s32 ret_val = 0;
  6008. if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
  6009. aspm_disable_flag = PCIE_LINK_STATE_L0S;
  6010. if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
  6011. aspm_disable_flag |= PCIE_LINK_STATE_L1;
  6012. if (aspm_disable_flag)
  6013. e1000e_disable_aspm(pdev, aspm_disable_flag);
  6014. err = pci_enable_device_mem(pdev);
  6015. if (err)
  6016. return err;
  6017. pci_using_dac = 0;
  6018. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  6019. if (!err) {
  6020. pci_using_dac = 1;
  6021. } else {
  6022. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  6023. if (err) {
  6024. dev_err(&pdev->dev,
  6025. "No usable DMA configuration, aborting\n");
  6026. goto err_dma;
  6027. }
  6028. }
  6029. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  6030. err = pci_request_selected_regions_exclusive(pdev, bars,
  6031. e1000e_driver_name);
  6032. if (err)
  6033. goto err_pci_reg;
  6034. /* AER (Advanced Error Reporting) hooks */
  6035. pci_enable_pcie_error_reporting(pdev);
  6036. pci_set_master(pdev);
  6037. /* PCI config space info */
  6038. err = pci_save_state(pdev);
  6039. if (err)
  6040. goto err_alloc_etherdev;
  6041. err = -ENOMEM;
  6042. netdev = alloc_etherdev(sizeof(struct e1000_adapter));
  6043. if (!netdev)
  6044. goto err_alloc_etherdev;
  6045. SET_NETDEV_DEV(netdev, &pdev->dev);
  6046. netdev->irq = pdev->irq;
  6047. pci_set_drvdata(pdev, netdev);
  6048. adapter = netdev_priv(netdev);
  6049. hw = &adapter->hw;
  6050. adapter->netdev = netdev;
  6051. adapter->pdev = pdev;
  6052. adapter->ei = ei;
  6053. adapter->pba = ei->pba;
  6054. adapter->flags = ei->flags;
  6055. adapter->flags2 = ei->flags2;
  6056. adapter->hw.adapter = adapter;
  6057. adapter->hw.mac.type = ei->mac;
  6058. adapter->max_hw_frame_size = ei->max_hw_frame_size;
  6059. adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
  6060. mmio_start = pci_resource_start(pdev, 0);
  6061. mmio_len = pci_resource_len(pdev, 0);
  6062. err = -EIO;
  6063. adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
  6064. if (!adapter->hw.hw_addr)
  6065. goto err_ioremap;
  6066. if ((adapter->flags & FLAG_HAS_FLASH) &&
  6067. (pci_resource_flags(pdev, 1) & IORESOURCE_MEM) &&
  6068. (hw->mac.type < e1000_pch_spt)) {
  6069. flash_start = pci_resource_start(pdev, 1);
  6070. flash_len = pci_resource_len(pdev, 1);
  6071. adapter->hw.flash_address = ioremap(flash_start, flash_len);
  6072. if (!adapter->hw.flash_address)
  6073. goto err_flashmap;
  6074. }
  6075. /* Set default EEE advertisement */
  6076. if (adapter->flags2 & FLAG2_HAS_EEE)
  6077. adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
  6078. /* construct the net_device struct */
  6079. netdev->netdev_ops = &e1000e_netdev_ops;
  6080. e1000e_set_ethtool_ops(netdev);
  6081. netdev->watchdog_timeo = 5 * HZ;
  6082. netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
  6083. strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
  6084. netdev->mem_start = mmio_start;
  6085. netdev->mem_end = mmio_start + mmio_len;
  6086. adapter->bd_number = cards_found++;
  6087. e1000e_check_options(adapter);
  6088. /* setup adapter struct */
  6089. err = e1000_sw_init(adapter);
  6090. if (err)
  6091. goto err_sw_init;
  6092. memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
  6093. memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
  6094. memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
  6095. err = ei->get_variants(adapter);
  6096. if (err)
  6097. goto err_hw_init;
  6098. if ((adapter->flags & FLAG_IS_ICH) &&
  6099. (adapter->flags & FLAG_READ_ONLY_NVM) &&
  6100. (hw->mac.type < e1000_pch_spt))
  6101. e1000e_write_protect_nvm_ich8lan(&adapter->hw);
  6102. hw->mac.ops.get_bus_info(&adapter->hw);
  6103. adapter->hw.phy.autoneg_wait_to_complete = 0;
  6104. /* Copper options */
  6105. if (adapter->hw.phy.media_type == e1000_media_type_copper) {
  6106. adapter->hw.phy.mdix = AUTO_ALL_MODES;
  6107. adapter->hw.phy.disable_polarity_correction = 0;
  6108. adapter->hw.phy.ms_type = e1000_ms_hw_default;
  6109. }
  6110. if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
  6111. dev_info(&pdev->dev,
  6112. "PHY reset is blocked due to SOL/IDER session.\n");
  6113. /* Set initial default active device features */
  6114. netdev->features = (NETIF_F_SG |
  6115. NETIF_F_HW_VLAN_CTAG_RX |
  6116. NETIF_F_HW_VLAN_CTAG_TX |
  6117. NETIF_F_TSO |
  6118. NETIF_F_TSO6 |
  6119. NETIF_F_RXHASH |
  6120. NETIF_F_RXCSUM |
  6121. NETIF_F_HW_CSUM);
  6122. /* Set user-changeable features (subset of all device features) */
  6123. netdev->hw_features = netdev->features;
  6124. netdev->hw_features |= NETIF_F_RXFCS;
  6125. netdev->priv_flags |= IFF_SUPP_NOFCS;
  6126. netdev->hw_features |= NETIF_F_RXALL;
  6127. if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
  6128. netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  6129. netdev->vlan_features |= (NETIF_F_SG |
  6130. NETIF_F_TSO |
  6131. NETIF_F_TSO6 |
  6132. NETIF_F_HW_CSUM);
  6133. netdev->priv_flags |= IFF_UNICAST_FLT;
  6134. if (pci_using_dac) {
  6135. netdev->features |= NETIF_F_HIGHDMA;
  6136. netdev->vlan_features |= NETIF_F_HIGHDMA;
  6137. }
  6138. /* MTU range: 68 - max_hw_frame_size */
  6139. netdev->min_mtu = ETH_MIN_MTU;
  6140. netdev->max_mtu = adapter->max_hw_frame_size -
  6141. (VLAN_ETH_HLEN + ETH_FCS_LEN);
  6142. if (e1000e_enable_mng_pass_thru(&adapter->hw))
  6143. adapter->flags |= FLAG_MNG_PT_ENABLED;
  6144. /* before reading the NVM, reset the controller to
  6145. * put the device in a known good starting state
  6146. */
  6147. adapter->hw.mac.ops.reset_hw(&adapter->hw);
  6148. /* systems with ASPM and others may see the checksum fail on the first
  6149. * attempt. Let's give it a few tries
  6150. */
  6151. for (i = 0;; i++) {
  6152. if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
  6153. break;
  6154. if (i == 2) {
  6155. dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
  6156. err = -EIO;
  6157. goto err_eeprom;
  6158. }
  6159. }
  6160. e1000_eeprom_checks(adapter);
  6161. /* copy the MAC address */
  6162. if (e1000e_read_mac_addr(&adapter->hw))
  6163. dev_err(&pdev->dev,
  6164. "NVM Read Error while reading MAC address\n");
  6165. memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
  6166. if (!is_valid_ether_addr(netdev->dev_addr)) {
  6167. dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
  6168. netdev->dev_addr);
  6169. err = -EIO;
  6170. goto err_eeprom;
  6171. }
  6172. timer_setup(&adapter->watchdog_timer, e1000_watchdog, 0);
  6173. timer_setup(&adapter->phy_info_timer, e1000_update_phy_info, 0);
  6174. INIT_WORK(&adapter->reset_task, e1000_reset_task);
  6175. INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
  6176. INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
  6177. INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
  6178. INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
  6179. /* Initialize link parameters. User can change them with ethtool */
  6180. adapter->hw.mac.autoneg = 1;
  6181. adapter->fc_autoneg = true;
  6182. adapter->hw.fc.requested_mode = e1000_fc_default;
  6183. adapter->hw.fc.current_mode = e1000_fc_default;
  6184. adapter->hw.phy.autoneg_advertised = 0x2f;
  6185. /* Initial Wake on LAN setting - If APM wake is enabled in
  6186. * the EEPROM, enable the ACPI Magic Packet filter
  6187. */
  6188. if (adapter->flags & FLAG_APME_IN_WUC) {
  6189. /* APME bit in EEPROM is mapped to WUC.APME */
  6190. eeprom_data = er32(WUC);
  6191. eeprom_apme_mask = E1000_WUC_APME;
  6192. if ((hw->mac.type > e1000_ich10lan) &&
  6193. (eeprom_data & E1000_WUC_PHY_WAKE))
  6194. adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
  6195. } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
  6196. if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
  6197. (adapter->hw.bus.func == 1))
  6198. ret_val = e1000_read_nvm(&adapter->hw,
  6199. NVM_INIT_CONTROL3_PORT_B,
  6200. 1, &eeprom_data);
  6201. else
  6202. ret_val = e1000_read_nvm(&adapter->hw,
  6203. NVM_INIT_CONTROL3_PORT_A,
  6204. 1, &eeprom_data);
  6205. }
  6206. /* fetch WoL from EEPROM */
  6207. if (ret_val)
  6208. e_dbg("NVM read error getting WoL initial values: %d\n", ret_val);
  6209. else if (eeprom_data & eeprom_apme_mask)
  6210. adapter->eeprom_wol |= E1000_WUFC_MAG;
  6211. /* now that we have the eeprom settings, apply the special cases
  6212. * where the eeprom may be wrong or the board simply won't support
  6213. * wake on lan on a particular port
  6214. */
  6215. if (!(adapter->flags & FLAG_HAS_WOL))
  6216. adapter->eeprom_wol = 0;
  6217. /* initialize the wol settings based on the eeprom settings */
  6218. adapter->wol = adapter->eeprom_wol;
  6219. /* make sure adapter isn't asleep if manageability is enabled */
  6220. if (adapter->wol || (adapter->flags & FLAG_MNG_PT_ENABLED) ||
  6221. (hw->mac.ops.check_mng_mode(hw)))
  6222. device_wakeup_enable(&pdev->dev);
  6223. /* save off EEPROM version number */
  6224. ret_val = e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
  6225. if (ret_val) {
  6226. e_dbg("NVM read error getting EEPROM version: %d\n", ret_val);
  6227. adapter->eeprom_vers = 0;
  6228. }
  6229. /* init PTP hardware clock */
  6230. e1000e_ptp_init(adapter);
  6231. /* reset the hardware with the new settings */
  6232. e1000e_reset(adapter);
  6233. /* If the controller has AMT, do not set DRV_LOAD until the interface
  6234. * is up. For all other cases, let the f/w know that the h/w is now
  6235. * under the control of the driver.
  6236. */
  6237. if (!(adapter->flags & FLAG_HAS_AMT))
  6238. e1000e_get_hw_control(adapter);
  6239. strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
  6240. err = register_netdev(netdev);
  6241. if (err)
  6242. goto err_register;
  6243. /* carrier off reporting is important to ethtool even BEFORE open */
  6244. netif_carrier_off(netdev);
  6245. e1000_print_device_info(adapter);
  6246. dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NEVER_SKIP);
  6247. if (pci_dev_run_wake(pdev) && hw->mac.type < e1000_pch_cnp)
  6248. pm_runtime_put_noidle(&pdev->dev);
  6249. return 0;
  6250. err_register:
  6251. if (!(adapter->flags & FLAG_HAS_AMT))
  6252. e1000e_release_hw_control(adapter);
  6253. err_eeprom:
  6254. if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
  6255. e1000_phy_hw_reset(&adapter->hw);
  6256. err_hw_init:
  6257. kfree(adapter->tx_ring);
  6258. kfree(adapter->rx_ring);
  6259. err_sw_init:
  6260. if ((adapter->hw.flash_address) && (hw->mac.type < e1000_pch_spt))
  6261. iounmap(adapter->hw.flash_address);
  6262. e1000e_reset_interrupt_capability(adapter);
  6263. err_flashmap:
  6264. iounmap(adapter->hw.hw_addr);
  6265. err_ioremap:
  6266. free_netdev(netdev);
  6267. err_alloc_etherdev:
  6268. pci_release_mem_regions(pdev);
  6269. err_pci_reg:
  6270. err_dma:
  6271. pci_disable_device(pdev);
  6272. return err;
  6273. }
  6274. /**
  6275. * e1000_remove - Device Removal Routine
  6276. * @pdev: PCI device information struct
  6277. *
  6278. * e1000_remove is called by the PCI subsystem to alert the driver
  6279. * that it should release a PCI device. The could be caused by a
  6280. * Hot-Plug event, or because the driver is going to be removed from
  6281. * memory.
  6282. **/
  6283. static void e1000_remove(struct pci_dev *pdev)
  6284. {
  6285. struct net_device *netdev = pci_get_drvdata(pdev);
  6286. struct e1000_adapter *adapter = netdev_priv(netdev);
  6287. bool down = test_bit(__E1000_DOWN, &adapter->state);
  6288. e1000e_ptp_remove(adapter);
  6289. /* The timers may be rescheduled, so explicitly disable them
  6290. * from being rescheduled.
  6291. */
  6292. if (!down)
  6293. set_bit(__E1000_DOWN, &adapter->state);
  6294. del_timer_sync(&adapter->watchdog_timer);
  6295. del_timer_sync(&adapter->phy_info_timer);
  6296. cancel_work_sync(&adapter->reset_task);
  6297. cancel_work_sync(&adapter->watchdog_task);
  6298. cancel_work_sync(&adapter->downshift_task);
  6299. cancel_work_sync(&adapter->update_phy_task);
  6300. cancel_work_sync(&adapter->print_hang_task);
  6301. if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
  6302. cancel_work_sync(&adapter->tx_hwtstamp_work);
  6303. if (adapter->tx_hwtstamp_skb) {
  6304. dev_consume_skb_any(adapter->tx_hwtstamp_skb);
  6305. adapter->tx_hwtstamp_skb = NULL;
  6306. }
  6307. }
  6308. /* Don't lie to e1000_close() down the road. */
  6309. if (!down)
  6310. clear_bit(__E1000_DOWN, &adapter->state);
  6311. unregister_netdev(netdev);
  6312. if (pci_dev_run_wake(pdev))
  6313. pm_runtime_get_noresume(&pdev->dev);
  6314. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  6315. * would have already happened in close and is redundant.
  6316. */
  6317. e1000e_release_hw_control(adapter);
  6318. e1000e_reset_interrupt_capability(adapter);
  6319. kfree(adapter->tx_ring);
  6320. kfree(adapter->rx_ring);
  6321. iounmap(adapter->hw.hw_addr);
  6322. if ((adapter->hw.flash_address) &&
  6323. (adapter->hw.mac.type < e1000_pch_spt))
  6324. iounmap(adapter->hw.flash_address);
  6325. pci_release_mem_regions(pdev);
  6326. free_netdev(netdev);
  6327. /* AER disable */
  6328. pci_disable_pcie_error_reporting(pdev);
  6329. pci_disable_device(pdev);
  6330. }
  6331. /* PCI Error Recovery (ERS) */
  6332. static const struct pci_error_handlers e1000_err_handler = {
  6333. .error_detected = e1000_io_error_detected,
  6334. .slot_reset = e1000_io_slot_reset,
  6335. .resume = e1000_io_resume,
  6336. };
  6337. static const struct pci_device_id e1000_pci_tbl[] = {
  6338. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
  6339. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
  6340. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
  6341. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP),
  6342. board_82571 },
  6343. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
  6344. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
  6345. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
  6346. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
  6347. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
  6348. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
  6349. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
  6350. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
  6351. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
  6352. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
  6353. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
  6354. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
  6355. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
  6356. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
  6357. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
  6358. { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
  6359. board_80003es2lan },
  6360. { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
  6361. board_80003es2lan },
  6362. { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
  6363. board_80003es2lan },
  6364. { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
  6365. board_80003es2lan },
  6366. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
  6367. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
  6368. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
  6369. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
  6370. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
  6371. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
  6372. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
  6373. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
  6374. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
  6375. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
  6376. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
  6377. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
  6378. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
  6379. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
  6380. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
  6381. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
  6382. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
  6383. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
  6384. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
  6385. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
  6386. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
  6387. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
  6388. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
  6389. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
  6390. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
  6391. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
  6392. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
  6393. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
  6394. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
  6395. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
  6396. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
  6397. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
  6398. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
  6399. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM2), board_pch_lpt },
  6400. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V2), board_pch_lpt },
  6401. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM3), board_pch_lpt },
  6402. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V3), board_pch_lpt },
  6403. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM), board_pch_spt },
  6404. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V), board_pch_spt },
  6405. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM2), board_pch_spt },
  6406. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V2), board_pch_spt },
  6407. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LBG_I219_LM3), board_pch_spt },
  6408. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM4), board_pch_spt },
  6409. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V4), board_pch_spt },
  6410. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM5), board_pch_spt },
  6411. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V5), board_pch_spt },
  6412. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM6), board_pch_cnp },
  6413. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V6), board_pch_cnp },
  6414. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM7), board_pch_cnp },
  6415. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V7), board_pch_cnp },
  6416. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM8), board_pch_cnp },
  6417. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V8), board_pch_cnp },
  6418. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM9), board_pch_cnp },
  6419. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V9), board_pch_cnp },
  6420. { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
  6421. };
  6422. MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
  6423. static const struct dev_pm_ops e1000_pm_ops = {
  6424. #ifdef CONFIG_PM_SLEEP
  6425. .suspend = e1000e_pm_suspend,
  6426. .resume = e1000e_pm_resume,
  6427. .freeze = e1000e_pm_freeze,
  6428. .thaw = e1000e_pm_thaw,
  6429. .poweroff = e1000e_pm_suspend,
  6430. .restore = e1000e_pm_resume,
  6431. #endif
  6432. SET_RUNTIME_PM_OPS(e1000e_pm_runtime_suspend, e1000e_pm_runtime_resume,
  6433. e1000e_pm_runtime_idle)
  6434. };
  6435. /* PCI Device API Driver */
  6436. static struct pci_driver e1000_driver = {
  6437. .name = e1000e_driver_name,
  6438. .id_table = e1000_pci_tbl,
  6439. .probe = e1000_probe,
  6440. .remove = e1000_remove,
  6441. .driver = {
  6442. .pm = &e1000_pm_ops,
  6443. },
  6444. .shutdown = e1000_shutdown,
  6445. .err_handler = &e1000_err_handler
  6446. };
  6447. /**
  6448. * e1000_init_module - Driver Registration Routine
  6449. *
  6450. * e1000_init_module is the first routine called when the driver is
  6451. * loaded. All it does is register with the PCI subsystem.
  6452. **/
  6453. static int __init e1000_init_module(void)
  6454. {
  6455. pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
  6456. e1000e_driver_version);
  6457. pr_info("Copyright(c) 1999 - 2015 Intel Corporation.\n");
  6458. return pci_register_driver(&e1000_driver);
  6459. }
  6460. module_init(e1000_init_module);
  6461. /**
  6462. * e1000_exit_module - Driver Exit Cleanup Routine
  6463. *
  6464. * e1000_exit_module is called just before the driver is removed
  6465. * from memory.
  6466. **/
  6467. static void __exit e1000_exit_module(void)
  6468. {
  6469. pci_unregister_driver(&e1000_driver);
  6470. }
  6471. module_exit(e1000_exit_module);
  6472. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  6473. MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
  6474. MODULE_LICENSE("GPL");
  6475. MODULE_VERSION(DRV_VERSION);
  6476. /* netdev.c */