netdev.c 201 KB

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