netdev.c 181 KB

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