netdev.c 213 KB

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