netdev.c 212 KB

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