netdev.c 224 KB

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