netdev.c 203 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285
  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. netdev_alloc_skb_ip_align(netdev, 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. int i;
  2976. static const u32 rsskey[10] = {
  2977. 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
  2978. 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
  2979. };
  2980. /* Fill out hash function seed */
  2981. for (i = 0; i < 10; i++)
  2982. ew32(RSSRK(i), rsskey[i]);
  2983. /* Direct all traffic to queue 0 */
  2984. for (i = 0; i < 32; i++)
  2985. ew32(RETA(i), 0);
  2986. /* Disable raw packet checksumming so that RSS hash is placed in
  2987. * descriptor on writeback.
  2988. */
  2989. rxcsum = er32(RXCSUM);
  2990. rxcsum |= E1000_RXCSUM_PCSD;
  2991. ew32(RXCSUM, rxcsum);
  2992. mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
  2993. E1000_MRQC_RSS_FIELD_IPV4_TCP |
  2994. E1000_MRQC_RSS_FIELD_IPV6 |
  2995. E1000_MRQC_RSS_FIELD_IPV6_TCP |
  2996. E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
  2997. ew32(MRQC, mrqc);
  2998. }
  2999. /**
  3000. * e1000e_get_base_timinca - get default SYSTIM time increment attributes
  3001. * @adapter: board private structure
  3002. * @timinca: pointer to returned time increment attributes
  3003. *
  3004. * Get attributes for incrementing the System Time Register SYSTIML/H at
  3005. * the default base frequency, and set the cyclecounter shift value.
  3006. **/
  3007. s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
  3008. {
  3009. struct e1000_hw *hw = &adapter->hw;
  3010. u32 incvalue, incperiod, shift;
  3011. /* Make sure clock is enabled on I217 before checking the frequency */
  3012. if ((hw->mac.type == e1000_pch_lpt) &&
  3013. !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
  3014. !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
  3015. u32 fextnvm7 = er32(FEXTNVM7);
  3016. if (!(fextnvm7 & (1 << 0))) {
  3017. ew32(FEXTNVM7, fextnvm7 | (1 << 0));
  3018. e1e_flush();
  3019. }
  3020. }
  3021. switch (hw->mac.type) {
  3022. case e1000_pch2lan:
  3023. case e1000_pch_lpt:
  3024. /* On I217, the clock frequency is 25MHz or 96MHz as
  3025. * indicated by the System Clock Frequency Indication
  3026. */
  3027. if ((hw->mac.type != e1000_pch_lpt) ||
  3028. (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)) {
  3029. /* Stable 96MHz frequency */
  3030. incperiod = INCPERIOD_96MHz;
  3031. incvalue = INCVALUE_96MHz;
  3032. shift = INCVALUE_SHIFT_96MHz;
  3033. adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHz;
  3034. break;
  3035. }
  3036. /* fall-through */
  3037. case e1000_82574:
  3038. case e1000_82583:
  3039. /* Stable 25MHz frequency */
  3040. incperiod = INCPERIOD_25MHz;
  3041. incvalue = INCVALUE_25MHz;
  3042. shift = INCVALUE_SHIFT_25MHz;
  3043. adapter->cc.shift = shift;
  3044. break;
  3045. default:
  3046. return -EINVAL;
  3047. }
  3048. *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
  3049. ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
  3050. return 0;
  3051. }
  3052. /**
  3053. * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
  3054. * @adapter: board private structure
  3055. *
  3056. * Outgoing time stamping can be enabled and disabled. Play nice and
  3057. * disable it when requested, although it shouldn't cause any overhead
  3058. * when no packet needs it. At most one packet in the queue may be
  3059. * marked for time stamping, otherwise it would be impossible to tell
  3060. * for sure to which packet the hardware time stamp belongs.
  3061. *
  3062. * Incoming time stamping has to be configured via the hardware filters.
  3063. * Not all combinations are supported, in particular event type has to be
  3064. * specified. Matching the kind of event packet is not supported, with the
  3065. * exception of "all V2 events regardless of level 2 or 4".
  3066. **/
  3067. static int e1000e_config_hwtstamp(struct e1000_adapter *adapter,
  3068. struct hwtstamp_config *config)
  3069. {
  3070. struct e1000_hw *hw = &adapter->hw;
  3071. u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
  3072. u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
  3073. u32 rxmtrl = 0;
  3074. u16 rxudp = 0;
  3075. bool is_l4 = false;
  3076. bool is_l2 = false;
  3077. u32 regval;
  3078. s32 ret_val;
  3079. if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
  3080. return -EINVAL;
  3081. /* flags reserved for future extensions - must be zero */
  3082. if (config->flags)
  3083. return -EINVAL;
  3084. switch (config->tx_type) {
  3085. case HWTSTAMP_TX_OFF:
  3086. tsync_tx_ctl = 0;
  3087. break;
  3088. case HWTSTAMP_TX_ON:
  3089. break;
  3090. default:
  3091. return -ERANGE;
  3092. }
  3093. switch (config->rx_filter) {
  3094. case HWTSTAMP_FILTER_NONE:
  3095. tsync_rx_ctl = 0;
  3096. break;
  3097. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  3098. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
  3099. rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
  3100. is_l4 = true;
  3101. break;
  3102. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  3103. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
  3104. rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
  3105. is_l4 = true;
  3106. break;
  3107. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  3108. /* Also time stamps V2 L2 Path Delay Request/Response */
  3109. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
  3110. rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
  3111. is_l2 = true;
  3112. break;
  3113. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  3114. /* Also time stamps V2 L2 Path Delay Request/Response. */
  3115. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
  3116. rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
  3117. is_l2 = true;
  3118. break;
  3119. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  3120. /* Hardware cannot filter just V2 L4 Sync messages;
  3121. * fall-through to V2 (both L2 and L4) Sync.
  3122. */
  3123. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  3124. /* Also time stamps V2 Path Delay Request/Response. */
  3125. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
  3126. rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
  3127. is_l2 = true;
  3128. is_l4 = true;
  3129. break;
  3130. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  3131. /* Hardware cannot filter just V2 L4 Delay Request messages;
  3132. * fall-through to V2 (both L2 and L4) Delay Request.
  3133. */
  3134. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  3135. /* Also time stamps V2 Path Delay Request/Response. */
  3136. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
  3137. rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
  3138. is_l2 = true;
  3139. is_l4 = true;
  3140. break;
  3141. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  3142. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  3143. /* Hardware cannot filter just V2 L4 or L2 Event messages;
  3144. * fall-through to all V2 (both L2 and L4) Events.
  3145. */
  3146. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  3147. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
  3148. config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  3149. is_l2 = true;
  3150. is_l4 = true;
  3151. break;
  3152. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  3153. /* For V1, the hardware can only filter Sync messages or
  3154. * Delay Request messages but not both so fall-through to
  3155. * time stamp all packets.
  3156. */
  3157. case HWTSTAMP_FILTER_ALL:
  3158. is_l2 = true;
  3159. is_l4 = true;
  3160. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
  3161. config->rx_filter = HWTSTAMP_FILTER_ALL;
  3162. break;
  3163. default:
  3164. return -ERANGE;
  3165. }
  3166. adapter->hwtstamp_config = *config;
  3167. /* enable/disable Tx h/w time stamping */
  3168. regval = er32(TSYNCTXCTL);
  3169. regval &= ~E1000_TSYNCTXCTL_ENABLED;
  3170. regval |= tsync_tx_ctl;
  3171. ew32(TSYNCTXCTL, regval);
  3172. if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
  3173. (regval & E1000_TSYNCTXCTL_ENABLED)) {
  3174. e_err("Timesync Tx Control register not set as expected\n");
  3175. return -EAGAIN;
  3176. }
  3177. /* enable/disable Rx h/w time stamping */
  3178. regval = er32(TSYNCRXCTL);
  3179. regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
  3180. regval |= tsync_rx_ctl;
  3181. ew32(TSYNCRXCTL, regval);
  3182. if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
  3183. E1000_TSYNCRXCTL_TYPE_MASK)) !=
  3184. (regval & (E1000_TSYNCRXCTL_ENABLED |
  3185. E1000_TSYNCRXCTL_TYPE_MASK))) {
  3186. e_err("Timesync Rx Control register not set as expected\n");
  3187. return -EAGAIN;
  3188. }
  3189. /* L2: define ethertype filter for time stamped packets */
  3190. if (is_l2)
  3191. rxmtrl |= ETH_P_1588;
  3192. /* define which PTP packets get time stamped */
  3193. ew32(RXMTRL, rxmtrl);
  3194. /* Filter by destination port */
  3195. if (is_l4) {
  3196. rxudp = PTP_EV_PORT;
  3197. cpu_to_be16s(&rxudp);
  3198. }
  3199. ew32(RXUDP, rxudp);
  3200. e1e_flush();
  3201. /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
  3202. er32(RXSTMPH);
  3203. er32(TXSTMPH);
  3204. /* Get and set the System Time Register SYSTIM base frequency */
  3205. ret_val = e1000e_get_base_timinca(adapter, &regval);
  3206. if (ret_val)
  3207. return ret_val;
  3208. ew32(TIMINCA, regval);
  3209. /* reset the ns time counter */
  3210. timecounter_init(&adapter->tc, &adapter->cc,
  3211. ktime_to_ns(ktime_get_real()));
  3212. return 0;
  3213. }
  3214. /**
  3215. * e1000_configure - configure the hardware for Rx and Tx
  3216. * @adapter: private board structure
  3217. **/
  3218. static void e1000_configure(struct e1000_adapter *adapter)
  3219. {
  3220. struct e1000_ring *rx_ring = adapter->rx_ring;
  3221. e1000e_set_rx_mode(adapter->netdev);
  3222. e1000_restore_vlan(adapter);
  3223. e1000_init_manageability_pt(adapter);
  3224. e1000_configure_tx(adapter);
  3225. if (adapter->netdev->features & NETIF_F_RXHASH)
  3226. e1000e_setup_rss_hash(adapter);
  3227. e1000_setup_rctl(adapter);
  3228. e1000_configure_rx(adapter);
  3229. adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
  3230. }
  3231. /**
  3232. * e1000e_power_up_phy - restore link in case the phy was powered down
  3233. * @adapter: address of board private structure
  3234. *
  3235. * The phy may be powered down to save power and turn off link when the
  3236. * driver is unloaded and wake on lan is not enabled (among others)
  3237. * *** this routine MUST be followed by a call to e1000e_reset ***
  3238. **/
  3239. void e1000e_power_up_phy(struct e1000_adapter *adapter)
  3240. {
  3241. if (adapter->hw.phy.ops.power_up)
  3242. adapter->hw.phy.ops.power_up(&adapter->hw);
  3243. adapter->hw.mac.ops.setup_link(&adapter->hw);
  3244. }
  3245. /**
  3246. * e1000_power_down_phy - Power down the PHY
  3247. *
  3248. * Power down the PHY so no link is implied when interface is down.
  3249. * The PHY cannot be powered down if management or WoL is active.
  3250. */
  3251. static void e1000_power_down_phy(struct e1000_adapter *adapter)
  3252. {
  3253. if (adapter->hw.phy.ops.power_down)
  3254. adapter->hw.phy.ops.power_down(&adapter->hw);
  3255. }
  3256. /**
  3257. * e1000e_reset - bring the hardware into a known good state
  3258. *
  3259. * This function boots the hardware and enables some settings that
  3260. * require a configuration cycle of the hardware - those cannot be
  3261. * set/changed during runtime. After reset the device needs to be
  3262. * properly configured for Rx, Tx etc.
  3263. */
  3264. void e1000e_reset(struct e1000_adapter *adapter)
  3265. {
  3266. struct e1000_mac_info *mac = &adapter->hw.mac;
  3267. struct e1000_fc_info *fc = &adapter->hw.fc;
  3268. struct e1000_hw *hw = &adapter->hw;
  3269. u32 tx_space, min_tx_space, min_rx_space;
  3270. u32 pba = adapter->pba;
  3271. u16 hwm;
  3272. /* reset Packet Buffer Allocation to default */
  3273. ew32(PBA, pba);
  3274. if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
  3275. /* To maintain wire speed transmits, the Tx FIFO should be
  3276. * large enough to accommodate two full transmit packets,
  3277. * rounded up to the next 1KB and expressed in KB. Likewise,
  3278. * the Rx FIFO should be large enough to accommodate at least
  3279. * one full receive packet and is similarly rounded up and
  3280. * expressed in KB.
  3281. */
  3282. pba = er32(PBA);
  3283. /* upper 16 bits has Tx packet buffer allocation size in KB */
  3284. tx_space = pba >> 16;
  3285. /* lower 16 bits has Rx packet buffer allocation size in KB */
  3286. pba &= 0xffff;
  3287. /* the Tx fifo also stores 16 bytes of information about the Tx
  3288. * but don't include ethernet FCS because hardware appends it
  3289. */
  3290. min_tx_space = (adapter->max_frame_size +
  3291. sizeof(struct e1000_tx_desc) - ETH_FCS_LEN) * 2;
  3292. min_tx_space = ALIGN(min_tx_space, 1024);
  3293. min_tx_space >>= 10;
  3294. /* software strips receive CRC, so leave room for it */
  3295. min_rx_space = adapter->max_frame_size;
  3296. min_rx_space = ALIGN(min_rx_space, 1024);
  3297. min_rx_space >>= 10;
  3298. /* If current Tx allocation is less than the min Tx FIFO size,
  3299. * and the min Tx FIFO size is less than the current Rx FIFO
  3300. * allocation, take space away from current Rx allocation
  3301. */
  3302. if ((tx_space < min_tx_space) &&
  3303. ((min_tx_space - tx_space) < pba)) {
  3304. pba -= min_tx_space - tx_space;
  3305. /* if short on Rx space, Rx wins and must trump Tx
  3306. * adjustment
  3307. */
  3308. if (pba < min_rx_space)
  3309. pba = min_rx_space;
  3310. }
  3311. ew32(PBA, pba);
  3312. }
  3313. /* flow control settings
  3314. *
  3315. * The high water mark must be low enough to fit one full frame
  3316. * (or the size used for early receive) above it in the Rx FIFO.
  3317. * Set it to the lower of:
  3318. * - 90% of the Rx FIFO size, and
  3319. * - the full Rx FIFO size minus one full frame
  3320. */
  3321. if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
  3322. fc->pause_time = 0xFFFF;
  3323. else
  3324. fc->pause_time = E1000_FC_PAUSE_TIME;
  3325. fc->send_xon = true;
  3326. fc->current_mode = fc->requested_mode;
  3327. switch (hw->mac.type) {
  3328. case e1000_ich9lan:
  3329. case e1000_ich10lan:
  3330. if (adapter->netdev->mtu > ETH_DATA_LEN) {
  3331. pba = 14;
  3332. ew32(PBA, pba);
  3333. fc->high_water = 0x2800;
  3334. fc->low_water = fc->high_water - 8;
  3335. break;
  3336. }
  3337. /* fall-through */
  3338. default:
  3339. hwm = min(((pba << 10) * 9 / 10),
  3340. ((pba << 10) - adapter->max_frame_size));
  3341. fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
  3342. fc->low_water = fc->high_water - 8;
  3343. break;
  3344. case e1000_pchlan:
  3345. /* Workaround PCH LOM adapter hangs with certain network
  3346. * loads. If hangs persist, try disabling Tx flow control.
  3347. */
  3348. if (adapter->netdev->mtu > ETH_DATA_LEN) {
  3349. fc->high_water = 0x3500;
  3350. fc->low_water = 0x1500;
  3351. } else {
  3352. fc->high_water = 0x5000;
  3353. fc->low_water = 0x3000;
  3354. }
  3355. fc->refresh_time = 0x1000;
  3356. break;
  3357. case e1000_pch2lan:
  3358. case e1000_pch_lpt:
  3359. fc->refresh_time = 0x0400;
  3360. if (adapter->netdev->mtu <= ETH_DATA_LEN) {
  3361. fc->high_water = 0x05C20;
  3362. fc->low_water = 0x05048;
  3363. fc->pause_time = 0x0650;
  3364. break;
  3365. }
  3366. pba = 14;
  3367. ew32(PBA, pba);
  3368. fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
  3369. fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
  3370. break;
  3371. }
  3372. /* Alignment of Tx data is on an arbitrary byte boundary with the
  3373. * maximum size per Tx descriptor limited only to the transmit
  3374. * allocation of the packet buffer minus 96 bytes with an upper
  3375. * limit of 24KB due to receive synchronization limitations.
  3376. */
  3377. adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
  3378. 24 << 10);
  3379. /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
  3380. * fit in receive buffer.
  3381. */
  3382. if (adapter->itr_setting & 0x3) {
  3383. if ((adapter->max_frame_size * 2) > (pba << 10)) {
  3384. if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
  3385. dev_info(&adapter->pdev->dev,
  3386. "Interrupt Throttle Rate off\n");
  3387. adapter->flags2 |= FLAG2_DISABLE_AIM;
  3388. e1000e_write_itr(adapter, 0);
  3389. }
  3390. } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
  3391. dev_info(&adapter->pdev->dev,
  3392. "Interrupt Throttle Rate on\n");
  3393. adapter->flags2 &= ~FLAG2_DISABLE_AIM;
  3394. adapter->itr = 20000;
  3395. e1000e_write_itr(adapter, adapter->itr);
  3396. }
  3397. }
  3398. /* Allow time for pending master requests to run */
  3399. mac->ops.reset_hw(hw);
  3400. /* For parts with AMT enabled, let the firmware know
  3401. * that the network interface is in control
  3402. */
  3403. if (adapter->flags & FLAG_HAS_AMT)
  3404. e1000e_get_hw_control(adapter);
  3405. ew32(WUC, 0);
  3406. if (mac->ops.init_hw(hw))
  3407. e_err("Hardware Error\n");
  3408. e1000_update_mng_vlan(adapter);
  3409. /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
  3410. ew32(VET, ETH_P_8021Q);
  3411. e1000e_reset_adaptive(hw);
  3412. /* initialize systim and reset the ns time counter */
  3413. e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config);
  3414. /* Set EEE advertisement as appropriate */
  3415. if (adapter->flags2 & FLAG2_HAS_EEE) {
  3416. s32 ret_val;
  3417. u16 adv_addr;
  3418. switch (hw->phy.type) {
  3419. case e1000_phy_82579:
  3420. adv_addr = I82579_EEE_ADVERTISEMENT;
  3421. break;
  3422. case e1000_phy_i217:
  3423. adv_addr = I217_EEE_ADVERTISEMENT;
  3424. break;
  3425. default:
  3426. dev_err(&adapter->pdev->dev,
  3427. "Invalid PHY type setting EEE advertisement\n");
  3428. return;
  3429. }
  3430. ret_val = hw->phy.ops.acquire(hw);
  3431. if (ret_val) {
  3432. dev_err(&adapter->pdev->dev,
  3433. "EEE advertisement - unable to acquire PHY\n");
  3434. return;
  3435. }
  3436. e1000_write_emi_reg_locked(hw, adv_addr,
  3437. hw->dev_spec.ich8lan.eee_disable ?
  3438. 0 : adapter->eee_advert);
  3439. hw->phy.ops.release(hw);
  3440. }
  3441. if (!netif_running(adapter->netdev) &&
  3442. !test_bit(__E1000_TESTING, &adapter->state))
  3443. e1000_power_down_phy(adapter);
  3444. e1000_get_phy_info(hw);
  3445. if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
  3446. !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
  3447. u16 phy_data = 0;
  3448. /* speed up time to link by disabling smart power down, ignore
  3449. * the return value of this function because there is nothing
  3450. * different we would do if it failed
  3451. */
  3452. e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
  3453. phy_data &= ~IGP02E1000_PM_SPD;
  3454. e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
  3455. }
  3456. }
  3457. int e1000e_up(struct e1000_adapter *adapter)
  3458. {
  3459. struct e1000_hw *hw = &adapter->hw;
  3460. /* hardware has been reset, we need to reload some things */
  3461. e1000_configure(adapter);
  3462. clear_bit(__E1000_DOWN, &adapter->state);
  3463. if (adapter->msix_entries)
  3464. e1000_configure_msix(adapter);
  3465. e1000_irq_enable(adapter);
  3466. netif_start_queue(adapter->netdev);
  3467. /* fire a link change interrupt to start the watchdog */
  3468. if (adapter->msix_entries)
  3469. ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
  3470. else
  3471. ew32(ICS, E1000_ICS_LSC);
  3472. return 0;
  3473. }
  3474. static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
  3475. {
  3476. struct e1000_hw *hw = &adapter->hw;
  3477. if (!(adapter->flags2 & FLAG2_DMA_BURST))
  3478. return;
  3479. /* flush pending descriptor writebacks to memory */
  3480. ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
  3481. ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
  3482. /* execute the writes immediately */
  3483. e1e_flush();
  3484. /* due to rare timing issues, write to TIDV/RDTR again to ensure the
  3485. * write is successful
  3486. */
  3487. ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
  3488. ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
  3489. /* execute the writes immediately */
  3490. e1e_flush();
  3491. }
  3492. static void e1000e_update_stats(struct e1000_adapter *adapter);
  3493. /**
  3494. * e1000e_down - quiesce the device and optionally reset the hardware
  3495. * @adapter: board private structure
  3496. * @reset: boolean flag to reset the hardware or not
  3497. */
  3498. void e1000e_down(struct e1000_adapter *adapter, bool reset)
  3499. {
  3500. struct net_device *netdev = adapter->netdev;
  3501. struct e1000_hw *hw = &adapter->hw;
  3502. u32 tctl, rctl;
  3503. /* signal that we're down so the interrupt handler does not
  3504. * reschedule our watchdog timer
  3505. */
  3506. set_bit(__E1000_DOWN, &adapter->state);
  3507. /* disable receives in the hardware */
  3508. rctl = er32(RCTL);
  3509. if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
  3510. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  3511. /* flush and sleep below */
  3512. netif_stop_queue(netdev);
  3513. /* disable transmits in the hardware */
  3514. tctl = er32(TCTL);
  3515. tctl &= ~E1000_TCTL_EN;
  3516. ew32(TCTL, tctl);
  3517. /* flush both disables and wait for them to finish */
  3518. e1e_flush();
  3519. usleep_range(10000, 20000);
  3520. e1000_irq_disable(adapter);
  3521. napi_synchronize(&adapter->napi);
  3522. del_timer_sync(&adapter->watchdog_timer);
  3523. del_timer_sync(&adapter->phy_info_timer);
  3524. netif_carrier_off(netdev);
  3525. spin_lock(&adapter->stats64_lock);
  3526. e1000e_update_stats(adapter);
  3527. spin_unlock(&adapter->stats64_lock);
  3528. e1000e_flush_descriptors(adapter);
  3529. e1000_clean_tx_ring(adapter->tx_ring);
  3530. e1000_clean_rx_ring(adapter->rx_ring);
  3531. adapter->link_speed = 0;
  3532. adapter->link_duplex = 0;
  3533. /* Disable Si errata workaround on PCHx for jumbo frame flow */
  3534. if ((hw->mac.type >= e1000_pch2lan) &&
  3535. (adapter->netdev->mtu > ETH_DATA_LEN) &&
  3536. e1000_lv_jumbo_workaround_ich8lan(hw, false))
  3537. e_dbg("failed to disable jumbo frame workaround mode\n");
  3538. if (reset && !pci_channel_offline(adapter->pdev))
  3539. e1000e_reset(adapter);
  3540. }
  3541. void e1000e_reinit_locked(struct e1000_adapter *adapter)
  3542. {
  3543. might_sleep();
  3544. while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
  3545. usleep_range(1000, 2000);
  3546. e1000e_down(adapter, true);
  3547. e1000e_up(adapter);
  3548. clear_bit(__E1000_RESETTING, &adapter->state);
  3549. }
  3550. /**
  3551. * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
  3552. * @cc: cyclecounter structure
  3553. **/
  3554. static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
  3555. {
  3556. struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
  3557. cc);
  3558. struct e1000_hw *hw = &adapter->hw;
  3559. cycle_t systim, systim_next;
  3560. /* latch SYSTIMH on read of SYSTIML */
  3561. systim = (cycle_t)er32(SYSTIML);
  3562. systim |= (cycle_t)er32(SYSTIMH) << 32;
  3563. if ((hw->mac.type == e1000_82574) || (hw->mac.type == e1000_82583)) {
  3564. u64 incvalue, time_delta, rem, temp;
  3565. int i;
  3566. /* errata for 82574/82583 possible bad bits read from SYSTIMH/L
  3567. * check to see that the time is incrementing at a reasonable
  3568. * rate and is a multiple of incvalue
  3569. */
  3570. incvalue = er32(TIMINCA) & E1000_TIMINCA_INCVALUE_MASK;
  3571. for (i = 0; i < E1000_MAX_82574_SYSTIM_REREADS; i++) {
  3572. /* latch SYSTIMH on read of SYSTIML */
  3573. systim_next = (cycle_t)er32(SYSTIML);
  3574. systim_next |= (cycle_t)er32(SYSTIMH) << 32;
  3575. time_delta = systim_next - systim;
  3576. temp = time_delta;
  3577. rem = do_div(temp, incvalue);
  3578. systim = systim_next;
  3579. if ((time_delta < E1000_82574_SYSTIM_EPSILON) &&
  3580. (rem == 0))
  3581. break;
  3582. }
  3583. }
  3584. return systim;
  3585. }
  3586. /**
  3587. * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
  3588. * @adapter: board private structure to initialize
  3589. *
  3590. * e1000_sw_init initializes the Adapter private data structure.
  3591. * Fields are initialized based on PCI device information and
  3592. * OS network device settings (MTU size).
  3593. **/
  3594. static int e1000_sw_init(struct e1000_adapter *adapter)
  3595. {
  3596. struct net_device *netdev = adapter->netdev;
  3597. adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
  3598. adapter->rx_ps_bsize0 = 128;
  3599. adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  3600. adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
  3601. adapter->tx_ring_count = E1000_DEFAULT_TXD;
  3602. adapter->rx_ring_count = E1000_DEFAULT_RXD;
  3603. spin_lock_init(&adapter->stats64_lock);
  3604. e1000e_set_interrupt_capability(adapter);
  3605. if (e1000_alloc_queues(adapter))
  3606. return -ENOMEM;
  3607. /* Setup hardware time stamping cyclecounter */
  3608. if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
  3609. adapter->cc.read = e1000e_cyclecounter_read;
  3610. adapter->cc.mask = CLOCKSOURCE_MASK(64);
  3611. adapter->cc.mult = 1;
  3612. /* cc.shift set in e1000e_get_base_tininca() */
  3613. spin_lock_init(&adapter->systim_lock);
  3614. INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
  3615. }
  3616. /* Explicitly disable IRQ since the NIC can be in any state. */
  3617. e1000_irq_disable(adapter);
  3618. set_bit(__E1000_DOWN, &adapter->state);
  3619. return 0;
  3620. }
  3621. /**
  3622. * e1000_intr_msi_test - Interrupt Handler
  3623. * @irq: interrupt number
  3624. * @data: pointer to a network interface device structure
  3625. **/
  3626. static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
  3627. {
  3628. struct net_device *netdev = data;
  3629. struct e1000_adapter *adapter = netdev_priv(netdev);
  3630. struct e1000_hw *hw = &adapter->hw;
  3631. u32 icr = er32(ICR);
  3632. e_dbg("icr is %08X\n", icr);
  3633. if (icr & E1000_ICR_RXSEQ) {
  3634. adapter->flags &= ~FLAG_MSI_TEST_FAILED;
  3635. /* Force memory writes to complete before acknowledging the
  3636. * interrupt is handled.
  3637. */
  3638. wmb();
  3639. }
  3640. return IRQ_HANDLED;
  3641. }
  3642. /**
  3643. * e1000_test_msi_interrupt - Returns 0 for successful test
  3644. * @adapter: board private struct
  3645. *
  3646. * code flow taken from tg3.c
  3647. **/
  3648. static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
  3649. {
  3650. struct net_device *netdev = adapter->netdev;
  3651. struct e1000_hw *hw = &adapter->hw;
  3652. int err;
  3653. /* poll_enable hasn't been called yet, so don't need disable */
  3654. /* clear any pending events */
  3655. er32(ICR);
  3656. /* free the real vector and request a test handler */
  3657. e1000_free_irq(adapter);
  3658. e1000e_reset_interrupt_capability(adapter);
  3659. /* Assume that the test fails, if it succeeds then the test
  3660. * MSI irq handler will unset this flag
  3661. */
  3662. adapter->flags |= FLAG_MSI_TEST_FAILED;
  3663. err = pci_enable_msi(adapter->pdev);
  3664. if (err)
  3665. goto msi_test_failed;
  3666. err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
  3667. netdev->name, netdev);
  3668. if (err) {
  3669. pci_disable_msi(adapter->pdev);
  3670. goto msi_test_failed;
  3671. }
  3672. /* Force memory writes to complete before enabling and firing an
  3673. * interrupt.
  3674. */
  3675. wmb();
  3676. e1000_irq_enable(adapter);
  3677. /* fire an unusual interrupt on the test handler */
  3678. ew32(ICS, E1000_ICS_RXSEQ);
  3679. e1e_flush();
  3680. msleep(100);
  3681. e1000_irq_disable(adapter);
  3682. rmb(); /* read flags after interrupt has been fired */
  3683. if (adapter->flags & FLAG_MSI_TEST_FAILED) {
  3684. adapter->int_mode = E1000E_INT_MODE_LEGACY;
  3685. e_info("MSI interrupt test failed, using legacy interrupt.\n");
  3686. } else {
  3687. e_dbg("MSI interrupt test succeeded!\n");
  3688. }
  3689. free_irq(adapter->pdev->irq, netdev);
  3690. pci_disable_msi(adapter->pdev);
  3691. msi_test_failed:
  3692. e1000e_set_interrupt_capability(adapter);
  3693. return e1000_request_irq(adapter);
  3694. }
  3695. /**
  3696. * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
  3697. * @adapter: board private struct
  3698. *
  3699. * code flow taken from tg3.c, called with e1000 interrupts disabled.
  3700. **/
  3701. static int e1000_test_msi(struct e1000_adapter *adapter)
  3702. {
  3703. int err;
  3704. u16 pci_cmd;
  3705. if (!(adapter->flags & FLAG_MSI_ENABLED))
  3706. return 0;
  3707. /* disable SERR in case the MSI write causes a master abort */
  3708. pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
  3709. if (pci_cmd & PCI_COMMAND_SERR)
  3710. pci_write_config_word(adapter->pdev, PCI_COMMAND,
  3711. pci_cmd & ~PCI_COMMAND_SERR);
  3712. err = e1000_test_msi_interrupt(adapter);
  3713. /* re-enable SERR */
  3714. if (pci_cmd & PCI_COMMAND_SERR) {
  3715. pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
  3716. pci_cmd |= PCI_COMMAND_SERR;
  3717. pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
  3718. }
  3719. return err;
  3720. }
  3721. /**
  3722. * e1000_open - Called when a network interface is made active
  3723. * @netdev: network interface device structure
  3724. *
  3725. * Returns 0 on success, negative value on failure
  3726. *
  3727. * The open entry point is called when a network interface is made
  3728. * active by the system (IFF_UP). At this point all resources needed
  3729. * for transmit and receive operations are allocated, the interrupt
  3730. * handler is registered with the OS, the watchdog timer is started,
  3731. * and the stack is notified that the interface is ready.
  3732. **/
  3733. static int e1000_open(struct net_device *netdev)
  3734. {
  3735. struct e1000_adapter *adapter = netdev_priv(netdev);
  3736. struct e1000_hw *hw = &adapter->hw;
  3737. struct pci_dev *pdev = adapter->pdev;
  3738. int err;
  3739. /* disallow open during test */
  3740. if (test_bit(__E1000_TESTING, &adapter->state))
  3741. return -EBUSY;
  3742. pm_runtime_get_sync(&pdev->dev);
  3743. netif_carrier_off(netdev);
  3744. /* allocate transmit descriptors */
  3745. err = e1000e_setup_tx_resources(adapter->tx_ring);
  3746. if (err)
  3747. goto err_setup_tx;
  3748. /* allocate receive descriptors */
  3749. err = e1000e_setup_rx_resources(adapter->rx_ring);
  3750. if (err)
  3751. goto err_setup_rx;
  3752. /* If AMT is enabled, let the firmware know that the network
  3753. * interface is now open and reset the part to a known state.
  3754. */
  3755. if (adapter->flags & FLAG_HAS_AMT) {
  3756. e1000e_get_hw_control(adapter);
  3757. e1000e_reset(adapter);
  3758. }
  3759. e1000e_power_up_phy(adapter);
  3760. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  3761. if ((adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
  3762. e1000_update_mng_vlan(adapter);
  3763. /* DMA latency requirement to workaround jumbo issue */
  3764. pm_qos_add_request(&adapter->netdev->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
  3765. PM_QOS_DEFAULT_VALUE);
  3766. /* before we allocate an interrupt, we must be ready to handle it.
  3767. * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
  3768. * as soon as we call pci_request_irq, so we have to setup our
  3769. * clean_rx handler before we do so.
  3770. */
  3771. e1000_configure(adapter);
  3772. err = e1000_request_irq(adapter);
  3773. if (err)
  3774. goto err_req_irq;
  3775. /* Work around PCIe errata with MSI interrupts causing some chipsets to
  3776. * ignore e1000e MSI messages, which means we need to test our MSI
  3777. * interrupt now
  3778. */
  3779. if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
  3780. err = e1000_test_msi(adapter);
  3781. if (err) {
  3782. e_err("Interrupt allocation failed\n");
  3783. goto err_req_irq;
  3784. }
  3785. }
  3786. /* From here on the code is the same as e1000e_up() */
  3787. clear_bit(__E1000_DOWN, &adapter->state);
  3788. napi_enable(&adapter->napi);
  3789. e1000_irq_enable(adapter);
  3790. adapter->tx_hang_recheck = false;
  3791. netif_start_queue(netdev);
  3792. hw->mac.get_link_status = true;
  3793. pm_runtime_put(&pdev->dev);
  3794. /* fire a link status change interrupt to start the watchdog */
  3795. if (adapter->msix_entries)
  3796. ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
  3797. else
  3798. ew32(ICS, E1000_ICS_LSC);
  3799. return 0;
  3800. err_req_irq:
  3801. e1000e_release_hw_control(adapter);
  3802. e1000_power_down_phy(adapter);
  3803. e1000e_free_rx_resources(adapter->rx_ring);
  3804. err_setup_rx:
  3805. e1000e_free_tx_resources(adapter->tx_ring);
  3806. err_setup_tx:
  3807. e1000e_reset(adapter);
  3808. pm_runtime_put_sync(&pdev->dev);
  3809. return err;
  3810. }
  3811. /**
  3812. * e1000_close - Disables a network interface
  3813. * @netdev: network interface device structure
  3814. *
  3815. * Returns 0, this is not allowed to fail
  3816. *
  3817. * The close entry point is called when an interface is de-activated
  3818. * by the OS. The hardware is still under the drivers control, but
  3819. * needs to be disabled. A global MAC reset is issued to stop the
  3820. * hardware, and all transmit and receive resources are freed.
  3821. **/
  3822. static int e1000_close(struct net_device *netdev)
  3823. {
  3824. struct e1000_adapter *adapter = netdev_priv(netdev);
  3825. struct pci_dev *pdev = adapter->pdev;
  3826. int count = E1000_CHECK_RESET_COUNT;
  3827. while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
  3828. usleep_range(10000, 20000);
  3829. WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
  3830. pm_runtime_get_sync(&pdev->dev);
  3831. if (!test_bit(__E1000_DOWN, &adapter->state)) {
  3832. e1000e_down(adapter, true);
  3833. e1000_free_irq(adapter);
  3834. /* Link status message must follow this format */
  3835. pr_info("%s NIC Link is Down\n", adapter->netdev->name);
  3836. }
  3837. napi_disable(&adapter->napi);
  3838. e1000e_free_tx_resources(adapter->tx_ring);
  3839. e1000e_free_rx_resources(adapter->rx_ring);
  3840. /* kill manageability vlan ID if supported, but not if a vlan with
  3841. * the same ID is registered on the host OS (let 8021q kill it)
  3842. */
  3843. if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
  3844. e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
  3845. adapter->mng_vlan_id);
  3846. /* If AMT is enabled, let the firmware know that the network
  3847. * interface is now closed
  3848. */
  3849. if ((adapter->flags & FLAG_HAS_AMT) &&
  3850. !test_bit(__E1000_TESTING, &adapter->state))
  3851. e1000e_release_hw_control(adapter);
  3852. pm_qos_remove_request(&adapter->netdev->pm_qos_req);
  3853. pm_runtime_put_sync(&pdev->dev);
  3854. return 0;
  3855. }
  3856. /**
  3857. * e1000_set_mac - Change the Ethernet Address of the NIC
  3858. * @netdev: network interface device structure
  3859. * @p: pointer to an address structure
  3860. *
  3861. * Returns 0 on success, negative on failure
  3862. **/
  3863. static int e1000_set_mac(struct net_device *netdev, void *p)
  3864. {
  3865. struct e1000_adapter *adapter = netdev_priv(netdev);
  3866. struct e1000_hw *hw = &adapter->hw;
  3867. struct sockaddr *addr = p;
  3868. if (!is_valid_ether_addr(addr->sa_data))
  3869. return -EADDRNOTAVAIL;
  3870. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  3871. memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
  3872. hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
  3873. if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
  3874. /* activate the work around */
  3875. e1000e_set_laa_state_82571(&adapter->hw, 1);
  3876. /* Hold a copy of the LAA in RAR[14] This is done so that
  3877. * between the time RAR[0] gets clobbered and the time it
  3878. * gets fixed (in e1000_watchdog), the actual LAA is in one
  3879. * of the RARs and no incoming packets directed to this port
  3880. * are dropped. Eventually the LAA will be in RAR[0] and
  3881. * RAR[14]
  3882. */
  3883. hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
  3884. adapter->hw.mac.rar_entry_count - 1);
  3885. }
  3886. return 0;
  3887. }
  3888. /**
  3889. * e1000e_update_phy_task - work thread to update phy
  3890. * @work: pointer to our work struct
  3891. *
  3892. * this worker thread exists because we must acquire a
  3893. * semaphore to read the phy, which we could msleep while
  3894. * waiting for it, and we can't msleep in a timer.
  3895. **/
  3896. static void e1000e_update_phy_task(struct work_struct *work)
  3897. {
  3898. struct e1000_adapter *adapter = container_of(work,
  3899. struct e1000_adapter,
  3900. update_phy_task);
  3901. struct e1000_hw *hw = &adapter->hw;
  3902. if (test_bit(__E1000_DOWN, &adapter->state))
  3903. return;
  3904. e1000_get_phy_info(hw);
  3905. /* Enable EEE on 82579 after link up */
  3906. if (hw->phy.type >= e1000_phy_82579)
  3907. e1000_set_eee_pchlan(hw);
  3908. }
  3909. /**
  3910. * e1000_update_phy_info - timre call-back to update PHY info
  3911. * @data: pointer to adapter cast into an unsigned long
  3912. *
  3913. * Need to wait a few seconds after link up to get diagnostic information from
  3914. * the phy
  3915. **/
  3916. static void e1000_update_phy_info(unsigned long data)
  3917. {
  3918. struct e1000_adapter *adapter = (struct e1000_adapter *)data;
  3919. if (test_bit(__E1000_DOWN, &adapter->state))
  3920. return;
  3921. schedule_work(&adapter->update_phy_task);
  3922. }
  3923. /**
  3924. * e1000e_update_phy_stats - Update the PHY statistics counters
  3925. * @adapter: board private structure
  3926. *
  3927. * Read/clear the upper 16-bit PHY registers and read/accumulate lower
  3928. **/
  3929. static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
  3930. {
  3931. struct e1000_hw *hw = &adapter->hw;
  3932. s32 ret_val;
  3933. u16 phy_data;
  3934. ret_val = hw->phy.ops.acquire(hw);
  3935. if (ret_val)
  3936. return;
  3937. /* A page set is expensive so check if already on desired page.
  3938. * If not, set to the page with the PHY status registers.
  3939. */
  3940. hw->phy.addr = 1;
  3941. ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
  3942. &phy_data);
  3943. if (ret_val)
  3944. goto release;
  3945. if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
  3946. ret_val = hw->phy.ops.set_page(hw,
  3947. HV_STATS_PAGE << IGP_PAGE_SHIFT);
  3948. if (ret_val)
  3949. goto release;
  3950. }
  3951. /* Single Collision Count */
  3952. hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
  3953. ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
  3954. if (!ret_val)
  3955. adapter->stats.scc += phy_data;
  3956. /* Excessive Collision Count */
  3957. hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
  3958. ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
  3959. if (!ret_val)
  3960. adapter->stats.ecol += phy_data;
  3961. /* Multiple Collision Count */
  3962. hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
  3963. ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
  3964. if (!ret_val)
  3965. adapter->stats.mcc += phy_data;
  3966. /* Late Collision Count */
  3967. hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
  3968. ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
  3969. if (!ret_val)
  3970. adapter->stats.latecol += phy_data;
  3971. /* Collision Count - also used for adaptive IFS */
  3972. hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
  3973. ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
  3974. if (!ret_val)
  3975. hw->mac.collision_delta = phy_data;
  3976. /* Defer Count */
  3977. hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
  3978. ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
  3979. if (!ret_val)
  3980. adapter->stats.dc += phy_data;
  3981. /* Transmit with no CRS */
  3982. hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
  3983. ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
  3984. if (!ret_val)
  3985. adapter->stats.tncrs += phy_data;
  3986. release:
  3987. hw->phy.ops.release(hw);
  3988. }
  3989. /**
  3990. * e1000e_update_stats - Update the board statistics counters
  3991. * @adapter: board private structure
  3992. **/
  3993. static void e1000e_update_stats(struct e1000_adapter *adapter)
  3994. {
  3995. struct net_device *netdev = adapter->netdev;
  3996. struct e1000_hw *hw = &adapter->hw;
  3997. struct pci_dev *pdev = adapter->pdev;
  3998. /* Prevent stats update while adapter is being reset, or if the pci
  3999. * connection is down.
  4000. */
  4001. if (adapter->link_speed == 0)
  4002. return;
  4003. if (pci_channel_offline(pdev))
  4004. return;
  4005. adapter->stats.crcerrs += er32(CRCERRS);
  4006. adapter->stats.gprc += er32(GPRC);
  4007. adapter->stats.gorc += er32(GORCL);
  4008. er32(GORCH); /* Clear gorc */
  4009. adapter->stats.bprc += er32(BPRC);
  4010. adapter->stats.mprc += er32(MPRC);
  4011. adapter->stats.roc += er32(ROC);
  4012. adapter->stats.mpc += er32(MPC);
  4013. /* Half-duplex statistics */
  4014. if (adapter->link_duplex == HALF_DUPLEX) {
  4015. if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
  4016. e1000e_update_phy_stats(adapter);
  4017. } else {
  4018. adapter->stats.scc += er32(SCC);
  4019. adapter->stats.ecol += er32(ECOL);
  4020. adapter->stats.mcc += er32(MCC);
  4021. adapter->stats.latecol += er32(LATECOL);
  4022. adapter->stats.dc += er32(DC);
  4023. hw->mac.collision_delta = er32(COLC);
  4024. if ((hw->mac.type != e1000_82574) &&
  4025. (hw->mac.type != e1000_82583))
  4026. adapter->stats.tncrs += er32(TNCRS);
  4027. }
  4028. adapter->stats.colc += hw->mac.collision_delta;
  4029. }
  4030. adapter->stats.xonrxc += er32(XONRXC);
  4031. adapter->stats.xontxc += er32(XONTXC);
  4032. adapter->stats.xoffrxc += er32(XOFFRXC);
  4033. adapter->stats.xofftxc += er32(XOFFTXC);
  4034. adapter->stats.gptc += er32(GPTC);
  4035. adapter->stats.gotc += er32(GOTCL);
  4036. er32(GOTCH); /* Clear gotc */
  4037. adapter->stats.rnbc += er32(RNBC);
  4038. adapter->stats.ruc += er32(RUC);
  4039. adapter->stats.mptc += er32(MPTC);
  4040. adapter->stats.bptc += er32(BPTC);
  4041. /* used for adaptive IFS */
  4042. hw->mac.tx_packet_delta = er32(TPT);
  4043. adapter->stats.tpt += hw->mac.tx_packet_delta;
  4044. adapter->stats.algnerrc += er32(ALGNERRC);
  4045. adapter->stats.rxerrc += er32(RXERRC);
  4046. adapter->stats.cexterr += er32(CEXTERR);
  4047. adapter->stats.tsctc += er32(TSCTC);
  4048. adapter->stats.tsctfc += er32(TSCTFC);
  4049. /* Fill out the OS statistics structure */
  4050. netdev->stats.multicast = adapter->stats.mprc;
  4051. netdev->stats.collisions = adapter->stats.colc;
  4052. /* Rx Errors */
  4053. /* RLEC on some newer hardware can be incorrect so build
  4054. * our own version based on RUC and ROC
  4055. */
  4056. netdev->stats.rx_errors = adapter->stats.rxerrc +
  4057. adapter->stats.crcerrs + adapter->stats.algnerrc +
  4058. adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
  4059. netdev->stats.rx_length_errors = adapter->stats.ruc +
  4060. adapter->stats.roc;
  4061. netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
  4062. netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
  4063. netdev->stats.rx_missed_errors = adapter->stats.mpc;
  4064. /* Tx Errors */
  4065. netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol;
  4066. netdev->stats.tx_aborted_errors = adapter->stats.ecol;
  4067. netdev->stats.tx_window_errors = adapter->stats.latecol;
  4068. netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
  4069. /* Tx Dropped needs to be maintained elsewhere */
  4070. /* Management Stats */
  4071. adapter->stats.mgptc += er32(MGTPTC);
  4072. adapter->stats.mgprc += er32(MGTPRC);
  4073. adapter->stats.mgpdc += er32(MGTPDC);
  4074. /* Correctable ECC Errors */
  4075. if (hw->mac.type == e1000_pch_lpt) {
  4076. u32 pbeccsts = er32(PBECCSTS);
  4077. adapter->corr_errors +=
  4078. pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
  4079. adapter->uncorr_errors +=
  4080. (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
  4081. E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
  4082. }
  4083. }
  4084. /**
  4085. * e1000_phy_read_status - Update the PHY register status snapshot
  4086. * @adapter: board private structure
  4087. **/
  4088. static void e1000_phy_read_status(struct e1000_adapter *adapter)
  4089. {
  4090. struct e1000_hw *hw = &adapter->hw;
  4091. struct e1000_phy_regs *phy = &adapter->phy_regs;
  4092. if (!pm_runtime_suspended((&adapter->pdev->dev)->parent) &&
  4093. (er32(STATUS) & E1000_STATUS_LU) &&
  4094. (adapter->hw.phy.media_type == e1000_media_type_copper)) {
  4095. int ret_val;
  4096. ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
  4097. ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
  4098. ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
  4099. ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
  4100. ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
  4101. ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
  4102. ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
  4103. ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
  4104. if (ret_val)
  4105. e_warn("Error reading PHY register\n");
  4106. } else {
  4107. /* Do not read PHY registers if link is not up
  4108. * Set values to typical power-on defaults
  4109. */
  4110. phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
  4111. phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
  4112. BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
  4113. BMSR_ERCAP);
  4114. phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
  4115. ADVERTISE_ALL | ADVERTISE_CSMA);
  4116. phy->lpa = 0;
  4117. phy->expansion = EXPANSION_ENABLENPAGE;
  4118. phy->ctrl1000 = ADVERTISE_1000FULL;
  4119. phy->stat1000 = 0;
  4120. phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
  4121. }
  4122. }
  4123. static void e1000_print_link_info(struct e1000_adapter *adapter)
  4124. {
  4125. struct e1000_hw *hw = &adapter->hw;
  4126. u32 ctrl = er32(CTRL);
  4127. /* Link status message must follow this format for user tools */
  4128. pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
  4129. adapter->netdev->name, adapter->link_speed,
  4130. adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
  4131. (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
  4132. (ctrl & E1000_CTRL_RFCE) ? "Rx" :
  4133. (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
  4134. }
  4135. static bool e1000e_has_link(struct e1000_adapter *adapter)
  4136. {
  4137. struct e1000_hw *hw = &adapter->hw;
  4138. bool link_active = false;
  4139. s32 ret_val = 0;
  4140. /* get_link_status is set on LSC (link status) interrupt or
  4141. * Rx sequence error interrupt. get_link_status will stay
  4142. * false until the check_for_link establishes link
  4143. * for copper adapters ONLY
  4144. */
  4145. switch (hw->phy.media_type) {
  4146. case e1000_media_type_copper:
  4147. if (hw->mac.get_link_status) {
  4148. ret_val = hw->mac.ops.check_for_link(hw);
  4149. link_active = !hw->mac.get_link_status;
  4150. } else {
  4151. link_active = true;
  4152. }
  4153. break;
  4154. case e1000_media_type_fiber:
  4155. ret_val = hw->mac.ops.check_for_link(hw);
  4156. link_active = !!(er32(STATUS) & E1000_STATUS_LU);
  4157. break;
  4158. case e1000_media_type_internal_serdes:
  4159. ret_val = hw->mac.ops.check_for_link(hw);
  4160. link_active = adapter->hw.mac.serdes_has_link;
  4161. break;
  4162. default:
  4163. case e1000_media_type_unknown:
  4164. break;
  4165. }
  4166. if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
  4167. (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
  4168. /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
  4169. e_info("Gigabit has been disabled, downgrading speed\n");
  4170. }
  4171. return link_active;
  4172. }
  4173. static void e1000e_enable_receives(struct e1000_adapter *adapter)
  4174. {
  4175. /* make sure the receive unit is started */
  4176. if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
  4177. (adapter->flags & FLAG_RESTART_NOW)) {
  4178. struct e1000_hw *hw = &adapter->hw;
  4179. u32 rctl = er32(RCTL);
  4180. ew32(RCTL, rctl | E1000_RCTL_EN);
  4181. adapter->flags &= ~FLAG_RESTART_NOW;
  4182. }
  4183. }
  4184. static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
  4185. {
  4186. struct e1000_hw *hw = &adapter->hw;
  4187. /* With 82574 controllers, PHY needs to be checked periodically
  4188. * for hung state and reset, if two calls return true
  4189. */
  4190. if (e1000_check_phy_82574(hw))
  4191. adapter->phy_hang_count++;
  4192. else
  4193. adapter->phy_hang_count = 0;
  4194. if (adapter->phy_hang_count > 1) {
  4195. adapter->phy_hang_count = 0;
  4196. e_dbg("PHY appears hung - resetting\n");
  4197. schedule_work(&adapter->reset_task);
  4198. }
  4199. }
  4200. /**
  4201. * e1000_watchdog - Timer Call-back
  4202. * @data: pointer to adapter cast into an unsigned long
  4203. **/
  4204. static void e1000_watchdog(unsigned long data)
  4205. {
  4206. struct e1000_adapter *adapter = (struct e1000_adapter *)data;
  4207. /* Do the rest outside of interrupt context */
  4208. schedule_work(&adapter->watchdog_task);
  4209. /* TODO: make this use queue_delayed_work() */
  4210. }
  4211. static void e1000_watchdog_task(struct work_struct *work)
  4212. {
  4213. struct e1000_adapter *adapter = container_of(work,
  4214. struct e1000_adapter,
  4215. watchdog_task);
  4216. struct net_device *netdev = adapter->netdev;
  4217. struct e1000_mac_info *mac = &adapter->hw.mac;
  4218. struct e1000_phy_info *phy = &adapter->hw.phy;
  4219. struct e1000_ring *tx_ring = adapter->tx_ring;
  4220. struct e1000_hw *hw = &adapter->hw;
  4221. u32 link, tctl;
  4222. if (test_bit(__E1000_DOWN, &adapter->state))
  4223. return;
  4224. link = e1000e_has_link(adapter);
  4225. if ((netif_carrier_ok(netdev)) && link) {
  4226. /* Cancel scheduled suspend requests. */
  4227. pm_runtime_resume(netdev->dev.parent);
  4228. e1000e_enable_receives(adapter);
  4229. goto link_up;
  4230. }
  4231. if ((e1000e_enable_tx_pkt_filtering(hw)) &&
  4232. (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
  4233. e1000_update_mng_vlan(adapter);
  4234. if (link) {
  4235. if (!netif_carrier_ok(netdev)) {
  4236. bool txb2b = true;
  4237. /* Cancel scheduled suspend requests. */
  4238. pm_runtime_resume(netdev->dev.parent);
  4239. /* update snapshot of PHY registers on LSC */
  4240. e1000_phy_read_status(adapter);
  4241. mac->ops.get_link_up_info(&adapter->hw,
  4242. &adapter->link_speed,
  4243. &adapter->link_duplex);
  4244. e1000_print_link_info(adapter);
  4245. /* check if SmartSpeed worked */
  4246. e1000e_check_downshift(hw);
  4247. if (phy->speed_downgraded)
  4248. netdev_warn(netdev,
  4249. "Link Speed was downgraded by SmartSpeed\n");
  4250. /* On supported PHYs, check for duplex mismatch only
  4251. * if link has autonegotiated at 10/100 half
  4252. */
  4253. if ((hw->phy.type == e1000_phy_igp_3 ||
  4254. hw->phy.type == e1000_phy_bm) &&
  4255. hw->mac.autoneg &&
  4256. (adapter->link_speed == SPEED_10 ||
  4257. adapter->link_speed == SPEED_100) &&
  4258. (adapter->link_duplex == HALF_DUPLEX)) {
  4259. u16 autoneg_exp;
  4260. e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
  4261. if (!(autoneg_exp & EXPANSION_NWAY))
  4262. e_info("Autonegotiated half duplex but link partner cannot autoneg. Try forcing full duplex if link gets many collisions.\n");
  4263. }
  4264. /* adjust timeout factor according to speed/duplex */
  4265. adapter->tx_timeout_factor = 1;
  4266. switch (adapter->link_speed) {
  4267. case SPEED_10:
  4268. txb2b = false;
  4269. adapter->tx_timeout_factor = 16;
  4270. break;
  4271. case SPEED_100:
  4272. txb2b = false;
  4273. adapter->tx_timeout_factor = 10;
  4274. break;
  4275. }
  4276. /* workaround: re-program speed mode bit after
  4277. * link-up event
  4278. */
  4279. if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
  4280. !txb2b) {
  4281. u32 tarc0;
  4282. tarc0 = er32(TARC(0));
  4283. tarc0 &= ~SPEED_MODE_BIT;
  4284. ew32(TARC(0), tarc0);
  4285. }
  4286. /* disable TSO for pcie and 10/100 speeds, to avoid
  4287. * some hardware issues
  4288. */
  4289. if (!(adapter->flags & FLAG_TSO_FORCE)) {
  4290. switch (adapter->link_speed) {
  4291. case SPEED_10:
  4292. case SPEED_100:
  4293. e_info("10/100 speed: disabling TSO\n");
  4294. netdev->features &= ~NETIF_F_TSO;
  4295. netdev->features &= ~NETIF_F_TSO6;
  4296. break;
  4297. case SPEED_1000:
  4298. netdev->features |= NETIF_F_TSO;
  4299. netdev->features |= NETIF_F_TSO6;
  4300. break;
  4301. default:
  4302. /* oops */
  4303. break;
  4304. }
  4305. }
  4306. /* enable transmits in the hardware, need to do this
  4307. * after setting TARC(0)
  4308. */
  4309. tctl = er32(TCTL);
  4310. tctl |= E1000_TCTL_EN;
  4311. ew32(TCTL, tctl);
  4312. /* Perform any post-link-up configuration before
  4313. * reporting link up.
  4314. */
  4315. if (phy->ops.cfg_on_link_up)
  4316. phy->ops.cfg_on_link_up(hw);
  4317. netif_carrier_on(netdev);
  4318. if (!test_bit(__E1000_DOWN, &adapter->state))
  4319. mod_timer(&adapter->phy_info_timer,
  4320. round_jiffies(jiffies + 2 * HZ));
  4321. }
  4322. } else {
  4323. if (netif_carrier_ok(netdev)) {
  4324. adapter->link_speed = 0;
  4325. adapter->link_duplex = 0;
  4326. /* Link status message must follow this format */
  4327. pr_info("%s NIC Link is Down\n", adapter->netdev->name);
  4328. netif_carrier_off(netdev);
  4329. if (!test_bit(__E1000_DOWN, &adapter->state))
  4330. mod_timer(&adapter->phy_info_timer,
  4331. round_jiffies(jiffies + 2 * HZ));
  4332. /* 8000ES2LAN requires a Rx packet buffer work-around
  4333. * on link down event; reset the controller to flush
  4334. * the Rx packet buffer.
  4335. */
  4336. if (adapter->flags & FLAG_RX_NEEDS_RESTART)
  4337. adapter->flags |= FLAG_RESTART_NOW;
  4338. else
  4339. pm_schedule_suspend(netdev->dev.parent,
  4340. LINK_TIMEOUT);
  4341. }
  4342. }
  4343. link_up:
  4344. spin_lock(&adapter->stats64_lock);
  4345. e1000e_update_stats(adapter);
  4346. mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
  4347. adapter->tpt_old = adapter->stats.tpt;
  4348. mac->collision_delta = adapter->stats.colc - adapter->colc_old;
  4349. adapter->colc_old = adapter->stats.colc;
  4350. adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
  4351. adapter->gorc_old = adapter->stats.gorc;
  4352. adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
  4353. adapter->gotc_old = adapter->stats.gotc;
  4354. spin_unlock(&adapter->stats64_lock);
  4355. /* If the link is lost the controller stops DMA, but
  4356. * if there is queued Tx work it cannot be done. So
  4357. * reset the controller to flush the Tx packet buffers.
  4358. */
  4359. if (!netif_carrier_ok(netdev) &&
  4360. (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
  4361. adapter->flags |= FLAG_RESTART_NOW;
  4362. /* If reset is necessary, do it outside of interrupt context. */
  4363. if (adapter->flags & FLAG_RESTART_NOW) {
  4364. schedule_work(&adapter->reset_task);
  4365. /* return immediately since reset is imminent */
  4366. return;
  4367. }
  4368. e1000e_update_adaptive(&adapter->hw);
  4369. /* Simple mode for Interrupt Throttle Rate (ITR) */
  4370. if (adapter->itr_setting == 4) {
  4371. /* Symmetric Tx/Rx gets a reduced ITR=2000;
  4372. * Total asymmetrical Tx or Rx gets ITR=8000;
  4373. * everyone else is between 2000-8000.
  4374. */
  4375. u32 goc = (adapter->gotc + adapter->gorc) / 10000;
  4376. u32 dif = (adapter->gotc > adapter->gorc ?
  4377. adapter->gotc - adapter->gorc :
  4378. adapter->gorc - adapter->gotc) / 10000;
  4379. u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
  4380. e1000e_write_itr(adapter, itr);
  4381. }
  4382. /* Cause software interrupt to ensure Rx ring is cleaned */
  4383. if (adapter->msix_entries)
  4384. ew32(ICS, adapter->rx_ring->ims_val);
  4385. else
  4386. ew32(ICS, E1000_ICS_RXDMT0);
  4387. /* flush pending descriptors to memory before detecting Tx hang */
  4388. e1000e_flush_descriptors(adapter);
  4389. /* Force detection of hung controller every watchdog period */
  4390. adapter->detect_tx_hung = true;
  4391. /* With 82571 controllers, LAA may be overwritten due to controller
  4392. * reset from the other port. Set the appropriate LAA in RAR[0]
  4393. */
  4394. if (e1000e_get_laa_state_82571(hw))
  4395. hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
  4396. if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
  4397. e1000e_check_82574_phy_workaround(adapter);
  4398. /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
  4399. if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
  4400. if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
  4401. (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
  4402. er32(RXSTMPH);
  4403. adapter->rx_hwtstamp_cleared++;
  4404. } else {
  4405. adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
  4406. }
  4407. }
  4408. /* Reset the timer */
  4409. if (!test_bit(__E1000_DOWN, &adapter->state))
  4410. mod_timer(&adapter->watchdog_timer,
  4411. round_jiffies(jiffies + 2 * HZ));
  4412. }
  4413. #define E1000_TX_FLAGS_CSUM 0x00000001
  4414. #define E1000_TX_FLAGS_VLAN 0x00000002
  4415. #define E1000_TX_FLAGS_TSO 0x00000004
  4416. #define E1000_TX_FLAGS_IPV4 0x00000008
  4417. #define E1000_TX_FLAGS_NO_FCS 0x00000010
  4418. #define E1000_TX_FLAGS_HWTSTAMP 0x00000020
  4419. #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
  4420. #define E1000_TX_FLAGS_VLAN_SHIFT 16
  4421. static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb,
  4422. __be16 protocol)
  4423. {
  4424. struct e1000_context_desc *context_desc;
  4425. struct e1000_buffer *buffer_info;
  4426. unsigned int i;
  4427. u32 cmd_length = 0;
  4428. u16 ipcse = 0, mss;
  4429. u8 ipcss, ipcso, tucss, tucso, hdr_len;
  4430. int err;
  4431. if (!skb_is_gso(skb))
  4432. return 0;
  4433. err = skb_cow_head(skb, 0);
  4434. if (err < 0)
  4435. return err;
  4436. hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  4437. mss = skb_shinfo(skb)->gso_size;
  4438. if (protocol == htons(ETH_P_IP)) {
  4439. struct iphdr *iph = ip_hdr(skb);
  4440. iph->tot_len = 0;
  4441. iph->check = 0;
  4442. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
  4443. 0, IPPROTO_TCP, 0);
  4444. cmd_length = E1000_TXD_CMD_IP;
  4445. ipcse = skb_transport_offset(skb) - 1;
  4446. } else if (skb_is_gso_v6(skb)) {
  4447. ipv6_hdr(skb)->payload_len = 0;
  4448. tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  4449. &ipv6_hdr(skb)->daddr,
  4450. 0, IPPROTO_TCP, 0);
  4451. ipcse = 0;
  4452. }
  4453. ipcss = skb_network_offset(skb);
  4454. ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
  4455. tucss = skb_transport_offset(skb);
  4456. tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
  4457. cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
  4458. E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
  4459. i = tx_ring->next_to_use;
  4460. context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
  4461. buffer_info = &tx_ring->buffer_info[i];
  4462. context_desc->lower_setup.ip_fields.ipcss = ipcss;
  4463. context_desc->lower_setup.ip_fields.ipcso = ipcso;
  4464. context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
  4465. context_desc->upper_setup.tcp_fields.tucss = tucss;
  4466. context_desc->upper_setup.tcp_fields.tucso = tucso;
  4467. context_desc->upper_setup.tcp_fields.tucse = 0;
  4468. context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
  4469. context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
  4470. context_desc->cmd_and_length = cpu_to_le32(cmd_length);
  4471. buffer_info->time_stamp = jiffies;
  4472. buffer_info->next_to_watch = i;
  4473. i++;
  4474. if (i == tx_ring->count)
  4475. i = 0;
  4476. tx_ring->next_to_use = i;
  4477. return 1;
  4478. }
  4479. static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb,
  4480. __be16 protocol)
  4481. {
  4482. struct e1000_adapter *adapter = tx_ring->adapter;
  4483. struct e1000_context_desc *context_desc;
  4484. struct e1000_buffer *buffer_info;
  4485. unsigned int i;
  4486. u8 css;
  4487. u32 cmd_len = E1000_TXD_CMD_DEXT;
  4488. if (skb->ip_summed != CHECKSUM_PARTIAL)
  4489. return false;
  4490. switch (protocol) {
  4491. case cpu_to_be16(ETH_P_IP):
  4492. if (ip_hdr(skb)->protocol == IPPROTO_TCP)
  4493. cmd_len |= E1000_TXD_CMD_TCP;
  4494. break;
  4495. case cpu_to_be16(ETH_P_IPV6):
  4496. /* XXX not handling all IPV6 headers */
  4497. if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
  4498. cmd_len |= E1000_TXD_CMD_TCP;
  4499. break;
  4500. default:
  4501. if (unlikely(net_ratelimit()))
  4502. e_warn("checksum_partial proto=%x!\n",
  4503. be16_to_cpu(protocol));
  4504. break;
  4505. }
  4506. css = skb_checksum_start_offset(skb);
  4507. i = tx_ring->next_to_use;
  4508. buffer_info = &tx_ring->buffer_info[i];
  4509. context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
  4510. context_desc->lower_setup.ip_config = 0;
  4511. context_desc->upper_setup.tcp_fields.tucss = css;
  4512. context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
  4513. context_desc->upper_setup.tcp_fields.tucse = 0;
  4514. context_desc->tcp_seg_setup.data = 0;
  4515. context_desc->cmd_and_length = cpu_to_le32(cmd_len);
  4516. buffer_info->time_stamp = jiffies;
  4517. buffer_info->next_to_watch = i;
  4518. i++;
  4519. if (i == tx_ring->count)
  4520. i = 0;
  4521. tx_ring->next_to_use = i;
  4522. return true;
  4523. }
  4524. static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
  4525. unsigned int first, unsigned int max_per_txd,
  4526. unsigned int nr_frags)
  4527. {
  4528. struct e1000_adapter *adapter = tx_ring->adapter;
  4529. struct pci_dev *pdev = adapter->pdev;
  4530. struct e1000_buffer *buffer_info;
  4531. unsigned int len = skb_headlen(skb);
  4532. unsigned int offset = 0, size, count = 0, i;
  4533. unsigned int f, bytecount, segs;
  4534. i = tx_ring->next_to_use;
  4535. while (len) {
  4536. buffer_info = &tx_ring->buffer_info[i];
  4537. size = min(len, max_per_txd);
  4538. buffer_info->length = size;
  4539. buffer_info->time_stamp = jiffies;
  4540. buffer_info->next_to_watch = i;
  4541. buffer_info->dma = dma_map_single(&pdev->dev,
  4542. skb->data + offset,
  4543. size, DMA_TO_DEVICE);
  4544. buffer_info->mapped_as_page = false;
  4545. if (dma_mapping_error(&pdev->dev, buffer_info->dma))
  4546. goto dma_error;
  4547. len -= size;
  4548. offset += size;
  4549. count++;
  4550. if (len) {
  4551. i++;
  4552. if (i == tx_ring->count)
  4553. i = 0;
  4554. }
  4555. }
  4556. for (f = 0; f < nr_frags; f++) {
  4557. const struct skb_frag_struct *frag;
  4558. frag = &skb_shinfo(skb)->frags[f];
  4559. len = skb_frag_size(frag);
  4560. offset = 0;
  4561. while (len) {
  4562. i++;
  4563. if (i == tx_ring->count)
  4564. i = 0;
  4565. buffer_info = &tx_ring->buffer_info[i];
  4566. size = min(len, max_per_txd);
  4567. buffer_info->length = size;
  4568. buffer_info->time_stamp = jiffies;
  4569. buffer_info->next_to_watch = i;
  4570. buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
  4571. offset, size,
  4572. DMA_TO_DEVICE);
  4573. buffer_info->mapped_as_page = true;
  4574. if (dma_mapping_error(&pdev->dev, buffer_info->dma))
  4575. goto dma_error;
  4576. len -= size;
  4577. offset += size;
  4578. count++;
  4579. }
  4580. }
  4581. segs = skb_shinfo(skb)->gso_segs ? : 1;
  4582. /* multiply data chunks by size of headers */
  4583. bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
  4584. tx_ring->buffer_info[i].skb = skb;
  4585. tx_ring->buffer_info[i].segs = segs;
  4586. tx_ring->buffer_info[i].bytecount = bytecount;
  4587. tx_ring->buffer_info[first].next_to_watch = i;
  4588. return count;
  4589. dma_error:
  4590. dev_err(&pdev->dev, "Tx DMA map failed\n");
  4591. buffer_info->dma = 0;
  4592. if (count)
  4593. count--;
  4594. while (count--) {
  4595. if (i == 0)
  4596. i += tx_ring->count;
  4597. i--;
  4598. buffer_info = &tx_ring->buffer_info[i];
  4599. e1000_put_txbuf(tx_ring, buffer_info);
  4600. }
  4601. return 0;
  4602. }
  4603. static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
  4604. {
  4605. struct e1000_adapter *adapter = tx_ring->adapter;
  4606. struct e1000_tx_desc *tx_desc = NULL;
  4607. struct e1000_buffer *buffer_info;
  4608. u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
  4609. unsigned int i;
  4610. if (tx_flags & E1000_TX_FLAGS_TSO) {
  4611. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
  4612. E1000_TXD_CMD_TSE;
  4613. txd_upper |= E1000_TXD_POPTS_TXSM << 8;
  4614. if (tx_flags & E1000_TX_FLAGS_IPV4)
  4615. txd_upper |= E1000_TXD_POPTS_IXSM << 8;
  4616. }
  4617. if (tx_flags & E1000_TX_FLAGS_CSUM) {
  4618. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
  4619. txd_upper |= E1000_TXD_POPTS_TXSM << 8;
  4620. }
  4621. if (tx_flags & E1000_TX_FLAGS_VLAN) {
  4622. txd_lower |= E1000_TXD_CMD_VLE;
  4623. txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
  4624. }
  4625. if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
  4626. txd_lower &= ~(E1000_TXD_CMD_IFCS);
  4627. if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
  4628. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
  4629. txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
  4630. }
  4631. i = tx_ring->next_to_use;
  4632. do {
  4633. buffer_info = &tx_ring->buffer_info[i];
  4634. tx_desc = E1000_TX_DESC(*tx_ring, i);
  4635. tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
  4636. tx_desc->lower.data = cpu_to_le32(txd_lower |
  4637. buffer_info->length);
  4638. tx_desc->upper.data = cpu_to_le32(txd_upper);
  4639. i++;
  4640. if (i == tx_ring->count)
  4641. i = 0;
  4642. } while (--count > 0);
  4643. tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
  4644. /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
  4645. if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
  4646. tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
  4647. /* Force memory writes to complete before letting h/w
  4648. * know there are new descriptors to fetch. (Only
  4649. * applicable for weak-ordered memory model archs,
  4650. * such as IA-64).
  4651. */
  4652. wmb();
  4653. tx_ring->next_to_use = i;
  4654. if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
  4655. e1000e_update_tdt_wa(tx_ring, i);
  4656. else
  4657. writel(i, tx_ring->tail);
  4658. /* we need this if more than one processor can write to our tail
  4659. * at a time, it synchronizes IO on IA64/Altix systems
  4660. */
  4661. mmiowb();
  4662. }
  4663. #define MINIMUM_DHCP_PACKET_SIZE 282
  4664. static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
  4665. struct sk_buff *skb)
  4666. {
  4667. struct e1000_hw *hw = &adapter->hw;
  4668. u16 length, offset;
  4669. if (vlan_tx_tag_present(skb) &&
  4670. !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
  4671. (adapter->hw.mng_cookie.status &
  4672. E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
  4673. return 0;
  4674. if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
  4675. return 0;
  4676. if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP))
  4677. return 0;
  4678. {
  4679. const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14);
  4680. struct udphdr *udp;
  4681. if (ip->protocol != IPPROTO_UDP)
  4682. return 0;
  4683. udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
  4684. if (ntohs(udp->dest) != 67)
  4685. return 0;
  4686. offset = (u8 *)udp + 8 - skb->data;
  4687. length = skb->len - offset;
  4688. return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
  4689. }
  4690. return 0;
  4691. }
  4692. static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
  4693. {
  4694. struct e1000_adapter *adapter = tx_ring->adapter;
  4695. netif_stop_queue(adapter->netdev);
  4696. /* Herbert's original patch had:
  4697. * smp_mb__after_netif_stop_queue();
  4698. * but since that doesn't exist yet, just open code it.
  4699. */
  4700. smp_mb();
  4701. /* We need to check again in a case another CPU has just
  4702. * made room available.
  4703. */
  4704. if (e1000_desc_unused(tx_ring) < size)
  4705. return -EBUSY;
  4706. /* A reprieve! */
  4707. netif_start_queue(adapter->netdev);
  4708. ++adapter->restart_queue;
  4709. return 0;
  4710. }
  4711. static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
  4712. {
  4713. BUG_ON(size > tx_ring->count);
  4714. if (e1000_desc_unused(tx_ring) >= size)
  4715. return 0;
  4716. return __e1000_maybe_stop_tx(tx_ring, size);
  4717. }
  4718. static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
  4719. struct net_device *netdev)
  4720. {
  4721. struct e1000_adapter *adapter = netdev_priv(netdev);
  4722. struct e1000_ring *tx_ring = adapter->tx_ring;
  4723. unsigned int first;
  4724. unsigned int tx_flags = 0;
  4725. unsigned int len = skb_headlen(skb);
  4726. unsigned int nr_frags;
  4727. unsigned int mss;
  4728. int count = 0;
  4729. int tso;
  4730. unsigned int f;
  4731. __be16 protocol = vlan_get_protocol(skb);
  4732. if (test_bit(__E1000_DOWN, &adapter->state)) {
  4733. dev_kfree_skb_any(skb);
  4734. return NETDEV_TX_OK;
  4735. }
  4736. if (skb->len <= 0) {
  4737. dev_kfree_skb_any(skb);
  4738. return NETDEV_TX_OK;
  4739. }
  4740. /* The minimum packet size with TCTL.PSP set is 17 bytes so
  4741. * pad skb in order to meet this minimum size requirement
  4742. */
  4743. if (unlikely(skb->len < 17)) {
  4744. if (skb_pad(skb, 17 - skb->len))
  4745. return NETDEV_TX_OK;
  4746. skb->len = 17;
  4747. skb_set_tail_pointer(skb, 17);
  4748. }
  4749. mss = skb_shinfo(skb)->gso_size;
  4750. if (mss) {
  4751. u8 hdr_len;
  4752. /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
  4753. * points to just header, pull a few bytes of payload from
  4754. * frags into skb->data
  4755. */
  4756. hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  4757. /* we do this workaround for ES2LAN, but it is un-necessary,
  4758. * avoiding it could save a lot of cycles
  4759. */
  4760. if (skb->data_len && (hdr_len == len)) {
  4761. unsigned int pull_size;
  4762. pull_size = min_t(unsigned int, 4, skb->data_len);
  4763. if (!__pskb_pull_tail(skb, pull_size)) {
  4764. e_err("__pskb_pull_tail failed.\n");
  4765. dev_kfree_skb_any(skb);
  4766. return NETDEV_TX_OK;
  4767. }
  4768. len = skb_headlen(skb);
  4769. }
  4770. }
  4771. /* reserve a descriptor for the offload context */
  4772. if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
  4773. count++;
  4774. count++;
  4775. count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
  4776. nr_frags = skb_shinfo(skb)->nr_frags;
  4777. for (f = 0; f < nr_frags; f++)
  4778. count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
  4779. adapter->tx_fifo_limit);
  4780. if (adapter->hw.mac.tx_pkt_filtering)
  4781. e1000_transfer_dhcp_info(adapter, skb);
  4782. /* need: count + 2 desc gap to keep tail from touching
  4783. * head, otherwise try next time
  4784. */
  4785. if (e1000_maybe_stop_tx(tx_ring, count + 2))
  4786. return NETDEV_TX_BUSY;
  4787. if (vlan_tx_tag_present(skb)) {
  4788. tx_flags |= E1000_TX_FLAGS_VLAN;
  4789. tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
  4790. }
  4791. first = tx_ring->next_to_use;
  4792. tso = e1000_tso(tx_ring, skb, protocol);
  4793. if (tso < 0) {
  4794. dev_kfree_skb_any(skb);
  4795. return NETDEV_TX_OK;
  4796. }
  4797. if (tso)
  4798. tx_flags |= E1000_TX_FLAGS_TSO;
  4799. else if (e1000_tx_csum(tx_ring, skb, protocol))
  4800. tx_flags |= E1000_TX_FLAGS_CSUM;
  4801. /* Old method was to assume IPv4 packet by default if TSO was enabled.
  4802. * 82571 hardware supports TSO capabilities for IPv6 as well...
  4803. * no longer assume, we must.
  4804. */
  4805. if (protocol == htons(ETH_P_IP))
  4806. tx_flags |= E1000_TX_FLAGS_IPV4;
  4807. if (unlikely(skb->no_fcs))
  4808. tx_flags |= E1000_TX_FLAGS_NO_FCS;
  4809. /* if count is 0 then mapping error has occurred */
  4810. count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
  4811. nr_frags);
  4812. if (count) {
  4813. if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
  4814. !adapter->tx_hwtstamp_skb)) {
  4815. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  4816. tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
  4817. adapter->tx_hwtstamp_skb = skb_get(skb);
  4818. adapter->tx_hwtstamp_start = jiffies;
  4819. schedule_work(&adapter->tx_hwtstamp_work);
  4820. } else {
  4821. skb_tx_timestamp(skb);
  4822. }
  4823. netdev_sent_queue(netdev, skb->len);
  4824. e1000_tx_queue(tx_ring, tx_flags, count);
  4825. /* Make sure there is space in the ring for the next send. */
  4826. e1000_maybe_stop_tx(tx_ring,
  4827. (MAX_SKB_FRAGS *
  4828. DIV_ROUND_UP(PAGE_SIZE,
  4829. adapter->tx_fifo_limit) + 2));
  4830. } else {
  4831. dev_kfree_skb_any(skb);
  4832. tx_ring->buffer_info[first].time_stamp = 0;
  4833. tx_ring->next_to_use = first;
  4834. }
  4835. return NETDEV_TX_OK;
  4836. }
  4837. /**
  4838. * e1000_tx_timeout - Respond to a Tx Hang
  4839. * @netdev: network interface device structure
  4840. **/
  4841. static void e1000_tx_timeout(struct net_device *netdev)
  4842. {
  4843. struct e1000_adapter *adapter = netdev_priv(netdev);
  4844. /* Do the reset outside of interrupt context */
  4845. adapter->tx_timeout_count++;
  4846. schedule_work(&adapter->reset_task);
  4847. }
  4848. static void e1000_reset_task(struct work_struct *work)
  4849. {
  4850. struct e1000_adapter *adapter;
  4851. adapter = container_of(work, struct e1000_adapter, reset_task);
  4852. /* don't run the task if already down */
  4853. if (test_bit(__E1000_DOWN, &adapter->state))
  4854. return;
  4855. if (!(adapter->flags & FLAG_RESTART_NOW)) {
  4856. e1000e_dump(adapter);
  4857. e_err("Reset adapter unexpectedly\n");
  4858. }
  4859. e1000e_reinit_locked(adapter);
  4860. }
  4861. /**
  4862. * e1000_get_stats64 - Get System Network Statistics
  4863. * @netdev: network interface device structure
  4864. * @stats: rtnl_link_stats64 pointer
  4865. *
  4866. * Returns the address of the device statistics structure.
  4867. **/
  4868. struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
  4869. struct rtnl_link_stats64 *stats)
  4870. {
  4871. struct e1000_adapter *adapter = netdev_priv(netdev);
  4872. memset(stats, 0, sizeof(struct rtnl_link_stats64));
  4873. spin_lock(&adapter->stats64_lock);
  4874. e1000e_update_stats(adapter);
  4875. /* Fill out the OS statistics structure */
  4876. stats->rx_bytes = adapter->stats.gorc;
  4877. stats->rx_packets = adapter->stats.gprc;
  4878. stats->tx_bytes = adapter->stats.gotc;
  4879. stats->tx_packets = adapter->stats.gptc;
  4880. stats->multicast = adapter->stats.mprc;
  4881. stats->collisions = adapter->stats.colc;
  4882. /* Rx Errors */
  4883. /* RLEC on some newer hardware can be incorrect so build
  4884. * our own version based on RUC and ROC
  4885. */
  4886. stats->rx_errors = adapter->stats.rxerrc +
  4887. adapter->stats.crcerrs + adapter->stats.algnerrc +
  4888. adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
  4889. stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc;
  4890. stats->rx_crc_errors = adapter->stats.crcerrs;
  4891. stats->rx_frame_errors = adapter->stats.algnerrc;
  4892. stats->rx_missed_errors = adapter->stats.mpc;
  4893. /* Tx Errors */
  4894. stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol;
  4895. stats->tx_aborted_errors = adapter->stats.ecol;
  4896. stats->tx_window_errors = adapter->stats.latecol;
  4897. stats->tx_carrier_errors = adapter->stats.tncrs;
  4898. /* Tx Dropped needs to be maintained elsewhere */
  4899. spin_unlock(&adapter->stats64_lock);
  4900. return stats;
  4901. }
  4902. /**
  4903. * e1000_change_mtu - Change the Maximum Transfer Unit
  4904. * @netdev: network interface device structure
  4905. * @new_mtu: new value for maximum frame size
  4906. *
  4907. * Returns 0 on success, negative on failure
  4908. **/
  4909. static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
  4910. {
  4911. struct e1000_adapter *adapter = netdev_priv(netdev);
  4912. int max_frame = new_mtu + VLAN_HLEN + ETH_HLEN + ETH_FCS_LEN;
  4913. /* Jumbo frame support */
  4914. if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
  4915. !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
  4916. e_err("Jumbo Frames not supported.\n");
  4917. return -EINVAL;
  4918. }
  4919. /* Supported frame sizes */
  4920. if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
  4921. (max_frame > adapter->max_hw_frame_size)) {
  4922. e_err("Unsupported MTU setting\n");
  4923. return -EINVAL;
  4924. }
  4925. /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
  4926. if ((adapter->hw.mac.type >= e1000_pch2lan) &&
  4927. !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
  4928. (new_mtu > ETH_DATA_LEN)) {
  4929. e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
  4930. return -EINVAL;
  4931. }
  4932. while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
  4933. usleep_range(1000, 2000);
  4934. /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
  4935. adapter->max_frame_size = max_frame;
  4936. e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
  4937. netdev->mtu = new_mtu;
  4938. pm_runtime_get_sync(netdev->dev.parent);
  4939. if (netif_running(netdev))
  4940. e1000e_down(adapter, true);
  4941. /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
  4942. * means we reserve 2 more, this pushes us to allocate from the next
  4943. * larger slab size.
  4944. * i.e. RXBUFFER_2048 --> size-4096 slab
  4945. * However with the new *_jumbo_rx* routines, jumbo receives will use
  4946. * fragmented skbs
  4947. */
  4948. if (max_frame <= 2048)
  4949. adapter->rx_buffer_len = 2048;
  4950. else
  4951. adapter->rx_buffer_len = 4096;
  4952. /* adjust allocation if LPE protects us, and we aren't using SBP */
  4953. if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
  4954. (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
  4955. adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
  4956. + ETH_FCS_LEN;
  4957. if (netif_running(netdev))
  4958. e1000e_up(adapter);
  4959. else
  4960. e1000e_reset(adapter);
  4961. pm_runtime_put_sync(netdev->dev.parent);
  4962. clear_bit(__E1000_RESETTING, &adapter->state);
  4963. return 0;
  4964. }
  4965. static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
  4966. int cmd)
  4967. {
  4968. struct e1000_adapter *adapter = netdev_priv(netdev);
  4969. struct mii_ioctl_data *data = if_mii(ifr);
  4970. if (adapter->hw.phy.media_type != e1000_media_type_copper)
  4971. return -EOPNOTSUPP;
  4972. switch (cmd) {
  4973. case SIOCGMIIPHY:
  4974. data->phy_id = adapter->hw.phy.addr;
  4975. break;
  4976. case SIOCGMIIREG:
  4977. e1000_phy_read_status(adapter);
  4978. switch (data->reg_num & 0x1F) {
  4979. case MII_BMCR:
  4980. data->val_out = adapter->phy_regs.bmcr;
  4981. break;
  4982. case MII_BMSR:
  4983. data->val_out = adapter->phy_regs.bmsr;
  4984. break;
  4985. case MII_PHYSID1:
  4986. data->val_out = (adapter->hw.phy.id >> 16);
  4987. break;
  4988. case MII_PHYSID2:
  4989. data->val_out = (adapter->hw.phy.id & 0xFFFF);
  4990. break;
  4991. case MII_ADVERTISE:
  4992. data->val_out = adapter->phy_regs.advertise;
  4993. break;
  4994. case MII_LPA:
  4995. data->val_out = adapter->phy_regs.lpa;
  4996. break;
  4997. case MII_EXPANSION:
  4998. data->val_out = adapter->phy_regs.expansion;
  4999. break;
  5000. case MII_CTRL1000:
  5001. data->val_out = adapter->phy_regs.ctrl1000;
  5002. break;
  5003. case MII_STAT1000:
  5004. data->val_out = adapter->phy_regs.stat1000;
  5005. break;
  5006. case MII_ESTATUS:
  5007. data->val_out = adapter->phy_regs.estatus;
  5008. break;
  5009. default:
  5010. return -EIO;
  5011. }
  5012. break;
  5013. case SIOCSMIIREG:
  5014. default:
  5015. return -EOPNOTSUPP;
  5016. }
  5017. return 0;
  5018. }
  5019. /**
  5020. * e1000e_hwtstamp_ioctl - control hardware time stamping
  5021. * @netdev: network interface device structure
  5022. * @ifreq: interface request
  5023. *
  5024. * Outgoing time stamping can be enabled and disabled. Play nice and
  5025. * disable it when requested, although it shouldn't cause any overhead
  5026. * when no packet needs it. At most one packet in the queue may be
  5027. * marked for time stamping, otherwise it would be impossible to tell
  5028. * for sure to which packet the hardware time stamp belongs.
  5029. *
  5030. * Incoming time stamping has to be configured via the hardware filters.
  5031. * Not all combinations are supported, in particular event type has to be
  5032. * specified. Matching the kind of event packet is not supported, with the
  5033. * exception of "all V2 events regardless of level 2 or 4".
  5034. **/
  5035. static int e1000e_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
  5036. {
  5037. struct e1000_adapter *adapter = netdev_priv(netdev);
  5038. struct hwtstamp_config config;
  5039. int ret_val;
  5040. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  5041. return -EFAULT;
  5042. ret_val = e1000e_config_hwtstamp(adapter, &config);
  5043. if (ret_val)
  5044. return ret_val;
  5045. switch (config.rx_filter) {
  5046. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  5047. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  5048. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  5049. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  5050. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  5051. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  5052. /* With V2 type filters which specify a Sync or Delay Request,
  5053. * Path Delay Request/Response messages are also time stamped
  5054. * by hardware so notify the caller the requested packets plus
  5055. * some others are time stamped.
  5056. */
  5057. config.rx_filter = HWTSTAMP_FILTER_SOME;
  5058. break;
  5059. default:
  5060. break;
  5061. }
  5062. return copy_to_user(ifr->ifr_data, &config,
  5063. sizeof(config)) ? -EFAULT : 0;
  5064. }
  5065. static int e1000e_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr)
  5066. {
  5067. struct e1000_adapter *adapter = netdev_priv(netdev);
  5068. return copy_to_user(ifr->ifr_data, &adapter->hwtstamp_config,
  5069. sizeof(adapter->hwtstamp_config)) ? -EFAULT : 0;
  5070. }
  5071. static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  5072. {
  5073. switch (cmd) {
  5074. case SIOCGMIIPHY:
  5075. case SIOCGMIIREG:
  5076. case SIOCSMIIREG:
  5077. return e1000_mii_ioctl(netdev, ifr, cmd);
  5078. case SIOCSHWTSTAMP:
  5079. return e1000e_hwtstamp_set(netdev, ifr);
  5080. case SIOCGHWTSTAMP:
  5081. return e1000e_hwtstamp_get(netdev, ifr);
  5082. default:
  5083. return -EOPNOTSUPP;
  5084. }
  5085. }
  5086. static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
  5087. {
  5088. struct e1000_hw *hw = &adapter->hw;
  5089. u32 i, mac_reg, wuc;
  5090. u16 phy_reg, wuc_enable;
  5091. int retval;
  5092. /* copy MAC RARs to PHY RARs */
  5093. e1000_copy_rx_addrs_to_phy_ich8lan(hw);
  5094. retval = hw->phy.ops.acquire(hw);
  5095. if (retval) {
  5096. e_err("Could not acquire PHY\n");
  5097. return retval;
  5098. }
  5099. /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
  5100. retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
  5101. if (retval)
  5102. goto release;
  5103. /* copy MAC MTA to PHY MTA - only needed for pchlan */
  5104. for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
  5105. mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
  5106. hw->phy.ops.write_reg_page(hw, BM_MTA(i),
  5107. (u16)(mac_reg & 0xFFFF));
  5108. hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
  5109. (u16)((mac_reg >> 16) & 0xFFFF));
  5110. }
  5111. /* configure PHY Rx Control register */
  5112. hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
  5113. mac_reg = er32(RCTL);
  5114. if (mac_reg & E1000_RCTL_UPE)
  5115. phy_reg |= BM_RCTL_UPE;
  5116. if (mac_reg & E1000_RCTL_MPE)
  5117. phy_reg |= BM_RCTL_MPE;
  5118. phy_reg &= ~(BM_RCTL_MO_MASK);
  5119. if (mac_reg & E1000_RCTL_MO_3)
  5120. phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
  5121. << BM_RCTL_MO_SHIFT);
  5122. if (mac_reg & E1000_RCTL_BAM)
  5123. phy_reg |= BM_RCTL_BAM;
  5124. if (mac_reg & E1000_RCTL_PMCF)
  5125. phy_reg |= BM_RCTL_PMCF;
  5126. mac_reg = er32(CTRL);
  5127. if (mac_reg & E1000_CTRL_RFCE)
  5128. phy_reg |= BM_RCTL_RFCE;
  5129. hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
  5130. wuc = E1000_WUC_PME_EN;
  5131. if (wufc & (E1000_WUFC_MAG | E1000_WUFC_LNKC))
  5132. wuc |= E1000_WUC_APME;
  5133. /* enable PHY wakeup in MAC register */
  5134. ew32(WUFC, wufc);
  5135. ew32(WUC, (E1000_WUC_PHY_WAKE | E1000_WUC_APMPME |
  5136. E1000_WUC_PME_STATUS | wuc));
  5137. /* configure and enable PHY wakeup in PHY registers */
  5138. hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
  5139. hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, wuc);
  5140. /* activate PHY wakeup */
  5141. wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
  5142. retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
  5143. if (retval)
  5144. e_err("Could not set PHY Host Wakeup bit\n");
  5145. release:
  5146. hw->phy.ops.release(hw);
  5147. return retval;
  5148. }
  5149. static void e1000e_flush_lpic(struct pci_dev *pdev)
  5150. {
  5151. struct net_device *netdev = pci_get_drvdata(pdev);
  5152. struct e1000_adapter *adapter = netdev_priv(netdev);
  5153. struct e1000_hw *hw = &adapter->hw;
  5154. u32 ret_val;
  5155. pm_runtime_get_sync(netdev->dev.parent);
  5156. ret_val = hw->phy.ops.acquire(hw);
  5157. if (ret_val)
  5158. goto fl_out;
  5159. pr_info("EEE TX LPI TIMER: %08X\n",
  5160. er32(LPIC) >> E1000_LPIC_LPIET_SHIFT);
  5161. hw->phy.ops.release(hw);
  5162. fl_out:
  5163. pm_runtime_put_sync(netdev->dev.parent);
  5164. }
  5165. static int e1000e_pm_freeze(struct device *dev)
  5166. {
  5167. struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
  5168. struct e1000_adapter *adapter = netdev_priv(netdev);
  5169. netif_device_detach(netdev);
  5170. if (netif_running(netdev)) {
  5171. int count = E1000_CHECK_RESET_COUNT;
  5172. while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
  5173. usleep_range(10000, 20000);
  5174. WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
  5175. /* Quiesce the device without resetting the hardware */
  5176. e1000e_down(adapter, false);
  5177. e1000_free_irq(adapter);
  5178. }
  5179. e1000e_reset_interrupt_capability(adapter);
  5180. /* Allow time for pending master requests to run */
  5181. e1000e_disable_pcie_master(&adapter->hw);
  5182. return 0;
  5183. }
  5184. static int __e1000_shutdown(struct pci_dev *pdev, bool runtime)
  5185. {
  5186. struct net_device *netdev = pci_get_drvdata(pdev);
  5187. struct e1000_adapter *adapter = netdev_priv(netdev);
  5188. struct e1000_hw *hw = &adapter->hw;
  5189. u32 ctrl, ctrl_ext, rctl, status;
  5190. /* Runtime suspend should only enable wakeup for link changes */
  5191. u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
  5192. int retval = 0;
  5193. status = er32(STATUS);
  5194. if (status & E1000_STATUS_LU)
  5195. wufc &= ~E1000_WUFC_LNKC;
  5196. if (wufc) {
  5197. e1000_setup_rctl(adapter);
  5198. e1000e_set_rx_mode(netdev);
  5199. /* turn on all-multi mode if wake on multicast is enabled */
  5200. if (wufc & E1000_WUFC_MC) {
  5201. rctl = er32(RCTL);
  5202. rctl |= E1000_RCTL_MPE;
  5203. ew32(RCTL, rctl);
  5204. }
  5205. ctrl = er32(CTRL);
  5206. ctrl |= E1000_CTRL_ADVD3WUC;
  5207. if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
  5208. ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
  5209. ew32(CTRL, ctrl);
  5210. if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
  5211. adapter->hw.phy.media_type ==
  5212. e1000_media_type_internal_serdes) {
  5213. /* keep the laser running in D3 */
  5214. ctrl_ext = er32(CTRL_EXT);
  5215. ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
  5216. ew32(CTRL_EXT, ctrl_ext);
  5217. }
  5218. if (!runtime)
  5219. e1000e_power_up_phy(adapter);
  5220. if (adapter->flags & FLAG_IS_ICH)
  5221. e1000_suspend_workarounds_ich8lan(&adapter->hw);
  5222. if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
  5223. /* enable wakeup by the PHY */
  5224. retval = e1000_init_phy_wakeup(adapter, wufc);
  5225. if (retval)
  5226. return retval;
  5227. } else {
  5228. /* enable wakeup by the MAC */
  5229. ew32(WUFC, wufc);
  5230. ew32(WUC, E1000_WUC_PME_EN);
  5231. }
  5232. } else {
  5233. ew32(WUC, 0);
  5234. ew32(WUFC, 0);
  5235. e1000_power_down_phy(adapter);
  5236. }
  5237. if (adapter->hw.phy.type == e1000_phy_igp_3) {
  5238. e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
  5239. } else if (hw->mac.type == e1000_pch_lpt) {
  5240. if (!(wufc & (E1000_WUFC_EX | E1000_WUFC_MC | E1000_WUFC_BC)))
  5241. /* ULP does not support wake from unicast, multicast
  5242. * or broadcast.
  5243. */
  5244. retval = e1000_enable_ulp_lpt_lp(hw, !runtime);
  5245. if (retval)
  5246. return retval;
  5247. }
  5248. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  5249. * would have already happened in close and is redundant.
  5250. */
  5251. e1000e_release_hw_control(adapter);
  5252. pci_clear_master(pdev);
  5253. /* The pci-e switch on some quad port adapters will report a
  5254. * correctable error when the MAC transitions from D0 to D3. To
  5255. * prevent this we need to mask off the correctable errors on the
  5256. * downstream port of the pci-e switch.
  5257. *
  5258. * We don't have the associated upstream bridge while assigning
  5259. * the PCI device into guest. For example, the KVM on power is
  5260. * one of the cases.
  5261. */
  5262. if (adapter->flags & FLAG_IS_QUAD_PORT) {
  5263. struct pci_dev *us_dev = pdev->bus->self;
  5264. u16 devctl;
  5265. if (!us_dev)
  5266. return 0;
  5267. pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
  5268. pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
  5269. (devctl & ~PCI_EXP_DEVCTL_CERE));
  5270. pci_save_state(pdev);
  5271. pci_prepare_to_sleep(pdev);
  5272. pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
  5273. }
  5274. return 0;
  5275. }
  5276. /**
  5277. * e1000e_disable_aspm - Disable ASPM states
  5278. * @pdev: pointer to PCI device struct
  5279. * @state: bit-mask of ASPM states to disable
  5280. *
  5281. * Some devices *must* have certain ASPM states disabled per hardware errata.
  5282. **/
  5283. static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
  5284. {
  5285. struct pci_dev *parent = pdev->bus->self;
  5286. u16 aspm_dis_mask = 0;
  5287. u16 pdev_aspmc, parent_aspmc;
  5288. switch (state) {
  5289. case PCIE_LINK_STATE_L0S:
  5290. case PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1:
  5291. aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L0S;
  5292. /* fall-through - can't have L1 without L0s */
  5293. case PCIE_LINK_STATE_L1:
  5294. aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L1;
  5295. break;
  5296. default:
  5297. return;
  5298. }
  5299. pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
  5300. pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
  5301. if (parent) {
  5302. pcie_capability_read_word(parent, PCI_EXP_LNKCTL,
  5303. &parent_aspmc);
  5304. parent_aspmc &= PCI_EXP_LNKCTL_ASPMC;
  5305. }
  5306. /* Nothing to do if the ASPM states to be disabled already are */
  5307. if (!(pdev_aspmc & aspm_dis_mask) &&
  5308. (!parent || !(parent_aspmc & aspm_dis_mask)))
  5309. return;
  5310. dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
  5311. (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L0S) ?
  5312. "L0s" : "",
  5313. (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L1) ?
  5314. "L1" : "");
  5315. #ifdef CONFIG_PCIEASPM
  5316. pci_disable_link_state_locked(pdev, state);
  5317. /* Double-check ASPM control. If not disabled by the above, the
  5318. * BIOS is preventing that from happening (or CONFIG_PCIEASPM is
  5319. * not enabled); override by writing PCI config space directly.
  5320. */
  5321. pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
  5322. pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
  5323. if (!(aspm_dis_mask & pdev_aspmc))
  5324. return;
  5325. #endif
  5326. /* Both device and parent should have the same ASPM setting.
  5327. * Disable ASPM in downstream component first and then upstream.
  5328. */
  5329. pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_dis_mask);
  5330. if (parent)
  5331. pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
  5332. aspm_dis_mask);
  5333. }
  5334. #ifdef CONFIG_PM
  5335. static int __e1000_resume(struct pci_dev *pdev)
  5336. {
  5337. struct net_device *netdev = pci_get_drvdata(pdev);
  5338. struct e1000_adapter *adapter = netdev_priv(netdev);
  5339. struct e1000_hw *hw = &adapter->hw;
  5340. u16 aspm_disable_flag = 0;
  5341. if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
  5342. aspm_disable_flag = PCIE_LINK_STATE_L0S;
  5343. if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
  5344. aspm_disable_flag |= PCIE_LINK_STATE_L1;
  5345. if (aspm_disable_flag)
  5346. e1000e_disable_aspm(pdev, aspm_disable_flag);
  5347. pci_set_master(pdev);
  5348. if (hw->mac.type >= e1000_pch2lan)
  5349. e1000_resume_workarounds_pchlan(&adapter->hw);
  5350. e1000e_power_up_phy(adapter);
  5351. /* report the system wakeup cause from S3/S4 */
  5352. if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
  5353. u16 phy_data;
  5354. e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
  5355. if (phy_data) {
  5356. e_info("PHY Wakeup cause - %s\n",
  5357. phy_data & E1000_WUS_EX ? "Unicast Packet" :
  5358. phy_data & E1000_WUS_MC ? "Multicast Packet" :
  5359. phy_data & E1000_WUS_BC ? "Broadcast Packet" :
  5360. phy_data & E1000_WUS_MAG ? "Magic Packet" :
  5361. phy_data & E1000_WUS_LNKC ?
  5362. "Link Status Change" : "other");
  5363. }
  5364. e1e_wphy(&adapter->hw, BM_WUS, ~0);
  5365. } else {
  5366. u32 wus = er32(WUS);
  5367. if (wus) {
  5368. e_info("MAC Wakeup cause - %s\n",
  5369. wus & E1000_WUS_EX ? "Unicast Packet" :
  5370. wus & E1000_WUS_MC ? "Multicast Packet" :
  5371. wus & E1000_WUS_BC ? "Broadcast Packet" :
  5372. wus & E1000_WUS_MAG ? "Magic Packet" :
  5373. wus & E1000_WUS_LNKC ? "Link Status Change" :
  5374. "other");
  5375. }
  5376. ew32(WUS, ~0);
  5377. }
  5378. e1000e_reset(adapter);
  5379. e1000_init_manageability_pt(adapter);
  5380. /* If the controller has AMT, do not set DRV_LOAD until the interface
  5381. * is up. For all other cases, let the f/w know that the h/w is now
  5382. * under the control of the driver.
  5383. */
  5384. if (!(adapter->flags & FLAG_HAS_AMT))
  5385. e1000e_get_hw_control(adapter);
  5386. return 0;
  5387. }
  5388. #ifdef CONFIG_PM_SLEEP
  5389. static int e1000e_pm_thaw(struct device *dev)
  5390. {
  5391. struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
  5392. struct e1000_adapter *adapter = netdev_priv(netdev);
  5393. e1000e_set_interrupt_capability(adapter);
  5394. if (netif_running(netdev)) {
  5395. u32 err = e1000_request_irq(adapter);
  5396. if (err)
  5397. return err;
  5398. e1000e_up(adapter);
  5399. }
  5400. netif_device_attach(netdev);
  5401. return 0;
  5402. }
  5403. static int e1000e_pm_suspend(struct device *dev)
  5404. {
  5405. struct pci_dev *pdev = to_pci_dev(dev);
  5406. e1000e_flush_lpic(pdev);
  5407. e1000e_pm_freeze(dev);
  5408. return __e1000_shutdown(pdev, false);
  5409. }
  5410. static int e1000e_pm_resume(struct device *dev)
  5411. {
  5412. struct pci_dev *pdev = to_pci_dev(dev);
  5413. int rc;
  5414. rc = __e1000_resume(pdev);
  5415. if (rc)
  5416. return rc;
  5417. return e1000e_pm_thaw(dev);
  5418. }
  5419. #endif /* CONFIG_PM_SLEEP */
  5420. #ifdef CONFIG_PM_RUNTIME
  5421. static int e1000e_pm_runtime_idle(struct device *dev)
  5422. {
  5423. struct pci_dev *pdev = to_pci_dev(dev);
  5424. struct net_device *netdev = pci_get_drvdata(pdev);
  5425. struct e1000_adapter *adapter = netdev_priv(netdev);
  5426. u16 eee_lp;
  5427. eee_lp = adapter->hw.dev_spec.ich8lan.eee_lp_ability;
  5428. if (!e1000e_has_link(adapter)) {
  5429. adapter->hw.dev_spec.ich8lan.eee_lp_ability = eee_lp;
  5430. pm_schedule_suspend(dev, 5 * MSEC_PER_SEC);
  5431. }
  5432. return -EBUSY;
  5433. }
  5434. static int e1000e_pm_runtime_resume(struct device *dev)
  5435. {
  5436. struct pci_dev *pdev = to_pci_dev(dev);
  5437. struct net_device *netdev = pci_get_drvdata(pdev);
  5438. struct e1000_adapter *adapter = netdev_priv(netdev);
  5439. int rc;
  5440. rc = __e1000_resume(pdev);
  5441. if (rc)
  5442. return rc;
  5443. if (netdev->flags & IFF_UP)
  5444. rc = e1000e_up(adapter);
  5445. return rc;
  5446. }
  5447. static int e1000e_pm_runtime_suspend(struct device *dev)
  5448. {
  5449. struct pci_dev *pdev = to_pci_dev(dev);
  5450. struct net_device *netdev = pci_get_drvdata(pdev);
  5451. struct e1000_adapter *adapter = netdev_priv(netdev);
  5452. if (netdev->flags & IFF_UP) {
  5453. int count = E1000_CHECK_RESET_COUNT;
  5454. while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
  5455. usleep_range(10000, 20000);
  5456. WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
  5457. /* Down the device without resetting the hardware */
  5458. e1000e_down(adapter, false);
  5459. }
  5460. if (__e1000_shutdown(pdev, true)) {
  5461. e1000e_pm_runtime_resume(dev);
  5462. return -EBUSY;
  5463. }
  5464. return 0;
  5465. }
  5466. #endif /* CONFIG_PM_RUNTIME */
  5467. #endif /* CONFIG_PM */
  5468. static void e1000_shutdown(struct pci_dev *pdev)
  5469. {
  5470. e1000e_flush_lpic(pdev);
  5471. e1000e_pm_freeze(&pdev->dev);
  5472. __e1000_shutdown(pdev, false);
  5473. }
  5474. #ifdef CONFIG_NET_POLL_CONTROLLER
  5475. static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
  5476. {
  5477. struct net_device *netdev = data;
  5478. struct e1000_adapter *adapter = netdev_priv(netdev);
  5479. if (adapter->msix_entries) {
  5480. int vector, msix_irq;
  5481. vector = 0;
  5482. msix_irq = adapter->msix_entries[vector].vector;
  5483. disable_irq(msix_irq);
  5484. e1000_intr_msix_rx(msix_irq, netdev);
  5485. enable_irq(msix_irq);
  5486. vector++;
  5487. msix_irq = adapter->msix_entries[vector].vector;
  5488. disable_irq(msix_irq);
  5489. e1000_intr_msix_tx(msix_irq, netdev);
  5490. enable_irq(msix_irq);
  5491. vector++;
  5492. msix_irq = adapter->msix_entries[vector].vector;
  5493. disable_irq(msix_irq);
  5494. e1000_msix_other(msix_irq, netdev);
  5495. enable_irq(msix_irq);
  5496. }
  5497. return IRQ_HANDLED;
  5498. }
  5499. /**
  5500. * e1000_netpoll
  5501. * @netdev: network interface device structure
  5502. *
  5503. * Polling 'interrupt' - used by things like netconsole to send skbs
  5504. * without having to re-enable interrupts. It's not called while
  5505. * the interrupt routine is executing.
  5506. */
  5507. static void e1000_netpoll(struct net_device *netdev)
  5508. {
  5509. struct e1000_adapter *adapter = netdev_priv(netdev);
  5510. switch (adapter->int_mode) {
  5511. case E1000E_INT_MODE_MSIX:
  5512. e1000_intr_msix(adapter->pdev->irq, netdev);
  5513. break;
  5514. case E1000E_INT_MODE_MSI:
  5515. disable_irq(adapter->pdev->irq);
  5516. e1000_intr_msi(adapter->pdev->irq, netdev);
  5517. enable_irq(adapter->pdev->irq);
  5518. break;
  5519. default: /* E1000E_INT_MODE_LEGACY */
  5520. disable_irq(adapter->pdev->irq);
  5521. e1000_intr(adapter->pdev->irq, netdev);
  5522. enable_irq(adapter->pdev->irq);
  5523. break;
  5524. }
  5525. }
  5526. #endif
  5527. /**
  5528. * e1000_io_error_detected - called when PCI error is detected
  5529. * @pdev: Pointer to PCI device
  5530. * @state: The current pci connection state
  5531. *
  5532. * This function is called after a PCI bus error affecting
  5533. * this device has been detected.
  5534. */
  5535. static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
  5536. pci_channel_state_t state)
  5537. {
  5538. struct net_device *netdev = pci_get_drvdata(pdev);
  5539. struct e1000_adapter *adapter = netdev_priv(netdev);
  5540. netif_device_detach(netdev);
  5541. if (state == pci_channel_io_perm_failure)
  5542. return PCI_ERS_RESULT_DISCONNECT;
  5543. if (netif_running(netdev))
  5544. e1000e_down(adapter, true);
  5545. pci_disable_device(pdev);
  5546. /* Request a slot slot reset. */
  5547. return PCI_ERS_RESULT_NEED_RESET;
  5548. }
  5549. /**
  5550. * e1000_io_slot_reset - called after the pci bus has been reset.
  5551. * @pdev: Pointer to PCI device
  5552. *
  5553. * Restart the card from scratch, as if from a cold-boot. Implementation
  5554. * resembles the first-half of the e1000e_pm_resume routine.
  5555. */
  5556. static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
  5557. {
  5558. struct net_device *netdev = pci_get_drvdata(pdev);
  5559. struct e1000_adapter *adapter = netdev_priv(netdev);
  5560. struct e1000_hw *hw = &adapter->hw;
  5561. u16 aspm_disable_flag = 0;
  5562. int err;
  5563. pci_ers_result_t result;
  5564. if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
  5565. aspm_disable_flag = PCIE_LINK_STATE_L0S;
  5566. if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
  5567. aspm_disable_flag |= PCIE_LINK_STATE_L1;
  5568. if (aspm_disable_flag)
  5569. e1000e_disable_aspm(pdev, aspm_disable_flag);
  5570. err = pci_enable_device_mem(pdev);
  5571. if (err) {
  5572. dev_err(&pdev->dev,
  5573. "Cannot re-enable PCI device after reset.\n");
  5574. result = PCI_ERS_RESULT_DISCONNECT;
  5575. } else {
  5576. pdev->state_saved = true;
  5577. pci_restore_state(pdev);
  5578. pci_set_master(pdev);
  5579. pci_enable_wake(pdev, PCI_D3hot, 0);
  5580. pci_enable_wake(pdev, PCI_D3cold, 0);
  5581. e1000e_reset(adapter);
  5582. ew32(WUS, ~0);
  5583. result = PCI_ERS_RESULT_RECOVERED;
  5584. }
  5585. pci_cleanup_aer_uncorrect_error_status(pdev);
  5586. return result;
  5587. }
  5588. /**
  5589. * e1000_io_resume - called when traffic can start flowing again.
  5590. * @pdev: Pointer to PCI device
  5591. *
  5592. * This callback is called when the error recovery driver tells us that
  5593. * its OK to resume normal operation. Implementation resembles the
  5594. * second-half of the e1000e_pm_resume routine.
  5595. */
  5596. static void e1000_io_resume(struct pci_dev *pdev)
  5597. {
  5598. struct net_device *netdev = pci_get_drvdata(pdev);
  5599. struct e1000_adapter *adapter = netdev_priv(netdev);
  5600. e1000_init_manageability_pt(adapter);
  5601. if (netif_running(netdev)) {
  5602. if (e1000e_up(adapter)) {
  5603. dev_err(&pdev->dev,
  5604. "can't bring device back up after reset\n");
  5605. return;
  5606. }
  5607. }
  5608. netif_device_attach(netdev);
  5609. /* If the controller has AMT, do not set DRV_LOAD until the interface
  5610. * is up. For all other cases, let the f/w know that the h/w is now
  5611. * under the control of the driver.
  5612. */
  5613. if (!(adapter->flags & FLAG_HAS_AMT))
  5614. e1000e_get_hw_control(adapter);
  5615. }
  5616. static void e1000_print_device_info(struct e1000_adapter *adapter)
  5617. {
  5618. struct e1000_hw *hw = &adapter->hw;
  5619. struct net_device *netdev = adapter->netdev;
  5620. u32 ret_val;
  5621. u8 pba_str[E1000_PBANUM_LENGTH];
  5622. /* print bus type/speed/width info */
  5623. e_info("(PCI Express:2.5GT/s:%s) %pM\n",
  5624. /* bus width */
  5625. ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
  5626. "Width x1"),
  5627. /* MAC address */
  5628. netdev->dev_addr);
  5629. e_info("Intel(R) PRO/%s Network Connection\n",
  5630. (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
  5631. ret_val = e1000_read_pba_string_generic(hw, pba_str,
  5632. E1000_PBANUM_LENGTH);
  5633. if (ret_val)
  5634. strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
  5635. e_info("MAC: %d, PHY: %d, PBA No: %s\n",
  5636. hw->mac.type, hw->phy.type, pba_str);
  5637. }
  5638. static void e1000_eeprom_checks(struct e1000_adapter *adapter)
  5639. {
  5640. struct e1000_hw *hw = &adapter->hw;
  5641. int ret_val;
  5642. u16 buf = 0;
  5643. if (hw->mac.type != e1000_82573)
  5644. return;
  5645. ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
  5646. le16_to_cpus(&buf);
  5647. if (!ret_val && (!(buf & (1 << 0)))) {
  5648. /* Deep Smart Power Down (DSPD) */
  5649. dev_warn(&adapter->pdev->dev,
  5650. "Warning: detected DSPD enabled in EEPROM\n");
  5651. }
  5652. }
  5653. static int e1000_set_features(struct net_device *netdev,
  5654. netdev_features_t features)
  5655. {
  5656. struct e1000_adapter *adapter = netdev_priv(netdev);
  5657. netdev_features_t changed = features ^ netdev->features;
  5658. if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
  5659. adapter->flags |= FLAG_TSO_FORCE;
  5660. if (!(changed & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
  5661. NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
  5662. NETIF_F_RXALL)))
  5663. return 0;
  5664. if (changed & NETIF_F_RXFCS) {
  5665. if (features & NETIF_F_RXFCS) {
  5666. adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
  5667. } else {
  5668. /* We need to take it back to defaults, which might mean
  5669. * stripping is still disabled at the adapter level.
  5670. */
  5671. if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
  5672. adapter->flags2 |= FLAG2_CRC_STRIPPING;
  5673. else
  5674. adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
  5675. }
  5676. }
  5677. netdev->features = features;
  5678. if (netif_running(netdev))
  5679. e1000e_reinit_locked(adapter);
  5680. else
  5681. e1000e_reset(adapter);
  5682. return 0;
  5683. }
  5684. static const struct net_device_ops e1000e_netdev_ops = {
  5685. .ndo_open = e1000_open,
  5686. .ndo_stop = e1000_close,
  5687. .ndo_start_xmit = e1000_xmit_frame,
  5688. .ndo_get_stats64 = e1000e_get_stats64,
  5689. .ndo_set_rx_mode = e1000e_set_rx_mode,
  5690. .ndo_set_mac_address = e1000_set_mac,
  5691. .ndo_change_mtu = e1000_change_mtu,
  5692. .ndo_do_ioctl = e1000_ioctl,
  5693. .ndo_tx_timeout = e1000_tx_timeout,
  5694. .ndo_validate_addr = eth_validate_addr,
  5695. .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
  5696. .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
  5697. #ifdef CONFIG_NET_POLL_CONTROLLER
  5698. .ndo_poll_controller = e1000_netpoll,
  5699. #endif
  5700. .ndo_set_features = e1000_set_features,
  5701. };
  5702. /**
  5703. * e1000_probe - Device Initialization Routine
  5704. * @pdev: PCI device information struct
  5705. * @ent: entry in e1000_pci_tbl
  5706. *
  5707. * Returns 0 on success, negative on failure
  5708. *
  5709. * e1000_probe initializes an adapter identified by a pci_dev structure.
  5710. * The OS initialization, configuring of the adapter private structure,
  5711. * and a hardware reset occur.
  5712. **/
  5713. static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  5714. {
  5715. struct net_device *netdev;
  5716. struct e1000_adapter *adapter;
  5717. struct e1000_hw *hw;
  5718. const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
  5719. resource_size_t mmio_start, mmio_len;
  5720. resource_size_t flash_start, flash_len;
  5721. static int cards_found;
  5722. u16 aspm_disable_flag = 0;
  5723. int bars, i, err, pci_using_dac;
  5724. u16 eeprom_data = 0;
  5725. u16 eeprom_apme_mask = E1000_EEPROM_APME;
  5726. s32 rval = 0;
  5727. if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
  5728. aspm_disable_flag = PCIE_LINK_STATE_L0S;
  5729. if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
  5730. aspm_disable_flag |= PCIE_LINK_STATE_L1;
  5731. if (aspm_disable_flag)
  5732. e1000e_disable_aspm(pdev, aspm_disable_flag);
  5733. err = pci_enable_device_mem(pdev);
  5734. if (err)
  5735. return err;
  5736. pci_using_dac = 0;
  5737. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  5738. if (!err) {
  5739. pci_using_dac = 1;
  5740. } else {
  5741. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  5742. if (err) {
  5743. dev_err(&pdev->dev,
  5744. "No usable DMA configuration, aborting\n");
  5745. goto err_dma;
  5746. }
  5747. }
  5748. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  5749. err = pci_request_selected_regions_exclusive(pdev, bars,
  5750. e1000e_driver_name);
  5751. if (err)
  5752. goto err_pci_reg;
  5753. /* AER (Advanced Error Reporting) hooks */
  5754. pci_enable_pcie_error_reporting(pdev);
  5755. pci_set_master(pdev);
  5756. /* PCI config space info */
  5757. err = pci_save_state(pdev);
  5758. if (err)
  5759. goto err_alloc_etherdev;
  5760. err = -ENOMEM;
  5761. netdev = alloc_etherdev(sizeof(struct e1000_adapter));
  5762. if (!netdev)
  5763. goto err_alloc_etherdev;
  5764. SET_NETDEV_DEV(netdev, &pdev->dev);
  5765. netdev->irq = pdev->irq;
  5766. pci_set_drvdata(pdev, netdev);
  5767. adapter = netdev_priv(netdev);
  5768. hw = &adapter->hw;
  5769. adapter->netdev = netdev;
  5770. adapter->pdev = pdev;
  5771. adapter->ei = ei;
  5772. adapter->pba = ei->pba;
  5773. adapter->flags = ei->flags;
  5774. adapter->flags2 = ei->flags2;
  5775. adapter->hw.adapter = adapter;
  5776. adapter->hw.mac.type = ei->mac;
  5777. adapter->max_hw_frame_size = ei->max_hw_frame_size;
  5778. adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
  5779. mmio_start = pci_resource_start(pdev, 0);
  5780. mmio_len = pci_resource_len(pdev, 0);
  5781. err = -EIO;
  5782. adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
  5783. if (!adapter->hw.hw_addr)
  5784. goto err_ioremap;
  5785. if ((adapter->flags & FLAG_HAS_FLASH) &&
  5786. (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
  5787. flash_start = pci_resource_start(pdev, 1);
  5788. flash_len = pci_resource_len(pdev, 1);
  5789. adapter->hw.flash_address = ioremap(flash_start, flash_len);
  5790. if (!adapter->hw.flash_address)
  5791. goto err_flashmap;
  5792. }
  5793. /* Set default EEE advertisement */
  5794. if (adapter->flags2 & FLAG2_HAS_EEE)
  5795. adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
  5796. /* construct the net_device struct */
  5797. netdev->netdev_ops = &e1000e_netdev_ops;
  5798. e1000e_set_ethtool_ops(netdev);
  5799. netdev->watchdog_timeo = 5 * HZ;
  5800. netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
  5801. strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
  5802. netdev->mem_start = mmio_start;
  5803. netdev->mem_end = mmio_start + mmio_len;
  5804. adapter->bd_number = cards_found++;
  5805. e1000e_check_options(adapter);
  5806. /* setup adapter struct */
  5807. err = e1000_sw_init(adapter);
  5808. if (err)
  5809. goto err_sw_init;
  5810. memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
  5811. memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
  5812. memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
  5813. err = ei->get_variants(adapter);
  5814. if (err)
  5815. goto err_hw_init;
  5816. if ((adapter->flags & FLAG_IS_ICH) &&
  5817. (adapter->flags & FLAG_READ_ONLY_NVM))
  5818. e1000e_write_protect_nvm_ich8lan(&adapter->hw);
  5819. hw->mac.ops.get_bus_info(&adapter->hw);
  5820. adapter->hw.phy.autoneg_wait_to_complete = 0;
  5821. /* Copper options */
  5822. if (adapter->hw.phy.media_type == e1000_media_type_copper) {
  5823. adapter->hw.phy.mdix = AUTO_ALL_MODES;
  5824. adapter->hw.phy.disable_polarity_correction = 0;
  5825. adapter->hw.phy.ms_type = e1000_ms_hw_default;
  5826. }
  5827. if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
  5828. dev_info(&pdev->dev,
  5829. "PHY reset is blocked due to SOL/IDER session.\n");
  5830. /* Set initial default active device features */
  5831. netdev->features = (NETIF_F_SG |
  5832. NETIF_F_HW_VLAN_CTAG_RX |
  5833. NETIF_F_HW_VLAN_CTAG_TX |
  5834. NETIF_F_TSO |
  5835. NETIF_F_TSO6 |
  5836. NETIF_F_RXHASH |
  5837. NETIF_F_RXCSUM |
  5838. NETIF_F_HW_CSUM);
  5839. /* Set user-changeable features (subset of all device features) */
  5840. netdev->hw_features = netdev->features;
  5841. netdev->hw_features |= NETIF_F_RXFCS;
  5842. netdev->priv_flags |= IFF_SUPP_NOFCS;
  5843. netdev->hw_features |= NETIF_F_RXALL;
  5844. if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
  5845. netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  5846. netdev->vlan_features |= (NETIF_F_SG |
  5847. NETIF_F_TSO |
  5848. NETIF_F_TSO6 |
  5849. NETIF_F_HW_CSUM);
  5850. netdev->priv_flags |= IFF_UNICAST_FLT;
  5851. if (pci_using_dac) {
  5852. netdev->features |= NETIF_F_HIGHDMA;
  5853. netdev->vlan_features |= NETIF_F_HIGHDMA;
  5854. }
  5855. if (e1000e_enable_mng_pass_thru(&adapter->hw))
  5856. adapter->flags |= FLAG_MNG_PT_ENABLED;
  5857. /* before reading the NVM, reset the controller to
  5858. * put the device in a known good starting state
  5859. */
  5860. adapter->hw.mac.ops.reset_hw(&adapter->hw);
  5861. /* systems with ASPM and others may see the checksum fail on the first
  5862. * attempt. Let's give it a few tries
  5863. */
  5864. for (i = 0;; i++) {
  5865. if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
  5866. break;
  5867. if (i == 2) {
  5868. dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
  5869. err = -EIO;
  5870. goto err_eeprom;
  5871. }
  5872. }
  5873. e1000_eeprom_checks(adapter);
  5874. /* copy the MAC address */
  5875. if (e1000e_read_mac_addr(&adapter->hw))
  5876. dev_err(&pdev->dev,
  5877. "NVM Read Error while reading MAC address\n");
  5878. memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
  5879. if (!is_valid_ether_addr(netdev->dev_addr)) {
  5880. dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
  5881. netdev->dev_addr);
  5882. err = -EIO;
  5883. goto err_eeprom;
  5884. }
  5885. init_timer(&adapter->watchdog_timer);
  5886. adapter->watchdog_timer.function = e1000_watchdog;
  5887. adapter->watchdog_timer.data = (unsigned long)adapter;
  5888. init_timer(&adapter->phy_info_timer);
  5889. adapter->phy_info_timer.function = e1000_update_phy_info;
  5890. adapter->phy_info_timer.data = (unsigned long)adapter;
  5891. INIT_WORK(&adapter->reset_task, e1000_reset_task);
  5892. INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
  5893. INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
  5894. INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
  5895. INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
  5896. /* Initialize link parameters. User can change them with ethtool */
  5897. adapter->hw.mac.autoneg = 1;
  5898. adapter->fc_autoneg = true;
  5899. adapter->hw.fc.requested_mode = e1000_fc_default;
  5900. adapter->hw.fc.current_mode = e1000_fc_default;
  5901. adapter->hw.phy.autoneg_advertised = 0x2f;
  5902. /* Initial Wake on LAN setting - If APM wake is enabled in
  5903. * the EEPROM, enable the ACPI Magic Packet filter
  5904. */
  5905. if (adapter->flags & FLAG_APME_IN_WUC) {
  5906. /* APME bit in EEPROM is mapped to WUC.APME */
  5907. eeprom_data = er32(WUC);
  5908. eeprom_apme_mask = E1000_WUC_APME;
  5909. if ((hw->mac.type > e1000_ich10lan) &&
  5910. (eeprom_data & E1000_WUC_PHY_WAKE))
  5911. adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
  5912. } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
  5913. if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
  5914. (adapter->hw.bus.func == 1))
  5915. rval = e1000_read_nvm(&adapter->hw,
  5916. NVM_INIT_CONTROL3_PORT_B,
  5917. 1, &eeprom_data);
  5918. else
  5919. rval = e1000_read_nvm(&adapter->hw,
  5920. NVM_INIT_CONTROL3_PORT_A,
  5921. 1, &eeprom_data);
  5922. }
  5923. /* fetch WoL from EEPROM */
  5924. if (rval)
  5925. e_dbg("NVM read error getting WoL initial values: %d\n", rval);
  5926. else if (eeprom_data & eeprom_apme_mask)
  5927. adapter->eeprom_wol |= E1000_WUFC_MAG;
  5928. /* now that we have the eeprom settings, apply the special cases
  5929. * where the eeprom may be wrong or the board simply won't support
  5930. * wake on lan on a particular port
  5931. */
  5932. if (!(adapter->flags & FLAG_HAS_WOL))
  5933. adapter->eeprom_wol = 0;
  5934. /* initialize the wol settings based on the eeprom settings */
  5935. adapter->wol = adapter->eeprom_wol;
  5936. /* make sure adapter isn't asleep if manageability is enabled */
  5937. if (adapter->wol || (adapter->flags & FLAG_MNG_PT_ENABLED) ||
  5938. (hw->mac.ops.check_mng_mode(hw)))
  5939. device_wakeup_enable(&pdev->dev);
  5940. /* save off EEPROM version number */
  5941. rval = e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
  5942. if (rval) {
  5943. e_dbg("NVM read error getting EEPROM version: %d\n", rval);
  5944. adapter->eeprom_vers = 0;
  5945. }
  5946. /* reset the hardware with the new settings */
  5947. e1000e_reset(adapter);
  5948. /* If the controller has AMT, do not set DRV_LOAD until the interface
  5949. * is up. For all other cases, let the f/w know that the h/w is now
  5950. * under the control of the driver.
  5951. */
  5952. if (!(adapter->flags & FLAG_HAS_AMT))
  5953. e1000e_get_hw_control(adapter);
  5954. strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
  5955. err = register_netdev(netdev);
  5956. if (err)
  5957. goto err_register;
  5958. /* carrier off reporting is important to ethtool even BEFORE open */
  5959. netif_carrier_off(netdev);
  5960. /* init PTP hardware clock */
  5961. e1000e_ptp_init(adapter);
  5962. e1000_print_device_info(adapter);
  5963. if (pci_dev_run_wake(pdev))
  5964. pm_runtime_put_noidle(&pdev->dev);
  5965. return 0;
  5966. err_register:
  5967. if (!(adapter->flags & FLAG_HAS_AMT))
  5968. e1000e_release_hw_control(adapter);
  5969. err_eeprom:
  5970. if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
  5971. e1000_phy_hw_reset(&adapter->hw);
  5972. err_hw_init:
  5973. kfree(adapter->tx_ring);
  5974. kfree(adapter->rx_ring);
  5975. err_sw_init:
  5976. if (adapter->hw.flash_address)
  5977. iounmap(adapter->hw.flash_address);
  5978. e1000e_reset_interrupt_capability(adapter);
  5979. err_flashmap:
  5980. iounmap(adapter->hw.hw_addr);
  5981. err_ioremap:
  5982. free_netdev(netdev);
  5983. err_alloc_etherdev:
  5984. pci_release_selected_regions(pdev,
  5985. pci_select_bars(pdev, IORESOURCE_MEM));
  5986. err_pci_reg:
  5987. err_dma:
  5988. pci_disable_device(pdev);
  5989. return err;
  5990. }
  5991. /**
  5992. * e1000_remove - Device Removal Routine
  5993. * @pdev: PCI device information struct
  5994. *
  5995. * e1000_remove is called by the PCI subsystem to alert the driver
  5996. * that it should release a PCI device. The could be caused by a
  5997. * Hot-Plug event, or because the driver is going to be removed from
  5998. * memory.
  5999. **/
  6000. static void e1000_remove(struct pci_dev *pdev)
  6001. {
  6002. struct net_device *netdev = pci_get_drvdata(pdev);
  6003. struct e1000_adapter *adapter = netdev_priv(netdev);
  6004. bool down = test_bit(__E1000_DOWN, &adapter->state);
  6005. e1000e_ptp_remove(adapter);
  6006. /* The timers may be rescheduled, so explicitly disable them
  6007. * from being rescheduled.
  6008. */
  6009. if (!down)
  6010. set_bit(__E1000_DOWN, &adapter->state);
  6011. del_timer_sync(&adapter->watchdog_timer);
  6012. del_timer_sync(&adapter->phy_info_timer);
  6013. cancel_work_sync(&adapter->reset_task);
  6014. cancel_work_sync(&adapter->watchdog_task);
  6015. cancel_work_sync(&adapter->downshift_task);
  6016. cancel_work_sync(&adapter->update_phy_task);
  6017. cancel_work_sync(&adapter->print_hang_task);
  6018. if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
  6019. cancel_work_sync(&adapter->tx_hwtstamp_work);
  6020. if (adapter->tx_hwtstamp_skb) {
  6021. dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
  6022. adapter->tx_hwtstamp_skb = NULL;
  6023. }
  6024. }
  6025. /* Don't lie to e1000_close() down the road. */
  6026. if (!down)
  6027. clear_bit(__E1000_DOWN, &adapter->state);
  6028. unregister_netdev(netdev);
  6029. if (pci_dev_run_wake(pdev))
  6030. pm_runtime_get_noresume(&pdev->dev);
  6031. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  6032. * would have already happened in close and is redundant.
  6033. */
  6034. e1000e_release_hw_control(adapter);
  6035. e1000e_reset_interrupt_capability(adapter);
  6036. kfree(adapter->tx_ring);
  6037. kfree(adapter->rx_ring);
  6038. iounmap(adapter->hw.hw_addr);
  6039. if (adapter->hw.flash_address)
  6040. iounmap(adapter->hw.flash_address);
  6041. pci_release_selected_regions(pdev,
  6042. pci_select_bars(pdev, IORESOURCE_MEM));
  6043. free_netdev(netdev);
  6044. /* AER disable */
  6045. pci_disable_pcie_error_reporting(pdev);
  6046. pci_disable_device(pdev);
  6047. }
  6048. /* PCI Error Recovery (ERS) */
  6049. static const struct pci_error_handlers e1000_err_handler = {
  6050. .error_detected = e1000_io_error_detected,
  6051. .slot_reset = e1000_io_slot_reset,
  6052. .resume = e1000_io_resume,
  6053. };
  6054. static const struct pci_device_id e1000_pci_tbl[] = {
  6055. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
  6056. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
  6057. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
  6058. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP),
  6059. board_82571 },
  6060. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
  6061. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
  6062. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
  6063. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
  6064. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
  6065. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
  6066. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
  6067. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
  6068. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
  6069. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
  6070. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
  6071. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
  6072. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
  6073. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
  6074. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
  6075. { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
  6076. board_80003es2lan },
  6077. { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
  6078. board_80003es2lan },
  6079. { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
  6080. board_80003es2lan },
  6081. { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
  6082. board_80003es2lan },
  6083. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
  6084. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
  6085. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
  6086. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
  6087. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
  6088. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
  6089. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
  6090. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
  6091. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
  6092. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
  6093. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
  6094. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
  6095. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
  6096. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
  6097. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
  6098. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
  6099. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
  6100. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
  6101. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
  6102. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
  6103. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
  6104. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
  6105. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
  6106. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
  6107. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
  6108. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
  6109. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
  6110. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
  6111. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
  6112. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
  6113. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
  6114. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
  6115. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
  6116. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM2), board_pch_lpt },
  6117. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V2), board_pch_lpt },
  6118. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM3), board_pch_lpt },
  6119. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V3), board_pch_lpt },
  6120. { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
  6121. };
  6122. MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
  6123. static const struct dev_pm_ops e1000_pm_ops = {
  6124. #ifdef CONFIG_PM_SLEEP
  6125. .suspend = e1000e_pm_suspend,
  6126. .resume = e1000e_pm_resume,
  6127. .freeze = e1000e_pm_freeze,
  6128. .thaw = e1000e_pm_thaw,
  6129. .poweroff = e1000e_pm_suspend,
  6130. .restore = e1000e_pm_resume,
  6131. #endif
  6132. SET_RUNTIME_PM_OPS(e1000e_pm_runtime_suspend, e1000e_pm_runtime_resume,
  6133. e1000e_pm_runtime_idle)
  6134. };
  6135. /* PCI Device API Driver */
  6136. static struct pci_driver e1000_driver = {
  6137. .name = e1000e_driver_name,
  6138. .id_table = e1000_pci_tbl,
  6139. .probe = e1000_probe,
  6140. .remove = e1000_remove,
  6141. .driver = {
  6142. .pm = &e1000_pm_ops,
  6143. },
  6144. .shutdown = e1000_shutdown,
  6145. .err_handler = &e1000_err_handler
  6146. };
  6147. /**
  6148. * e1000_init_module - Driver Registration Routine
  6149. *
  6150. * e1000_init_module is the first routine called when the driver is
  6151. * loaded. All it does is register with the PCI subsystem.
  6152. **/
  6153. static int __init e1000_init_module(void)
  6154. {
  6155. int ret;
  6156. pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
  6157. e1000e_driver_version);
  6158. pr_info("Copyright(c) 1999 - 2014 Intel Corporation.\n");
  6159. ret = pci_register_driver(&e1000_driver);
  6160. return ret;
  6161. }
  6162. module_init(e1000_init_module);
  6163. /**
  6164. * e1000_exit_module - Driver Exit Cleanup Routine
  6165. *
  6166. * e1000_exit_module is called just before the driver is removed
  6167. * from memory.
  6168. **/
  6169. static void __exit e1000_exit_module(void)
  6170. {
  6171. pci_unregister_driver(&e1000_driver);
  6172. }
  6173. module_exit(e1000_exit_module);
  6174. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  6175. MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
  6176. MODULE_LICENSE("GPL");
  6177. MODULE_VERSION(DRV_VERSION);
  6178. /* netdev.c */