netdev.c 225 KB

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