netdev.c 214 KB

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