netdev.c 181 KB

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