netdev.c 173 KB

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