netdev.c 214 KB

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