netdev.c 213 KB

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