netdev.c 182 KB

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