netdev.c 203 KB

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