netdev.c 211 KB

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