netdev.c 180 KB

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