netdev.c 179 KB

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