e1000_hw.c 232 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814
  1. /*******************************************************************************
  2. Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the Free
  5. Software Foundation; either version 2 of the License, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that 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., 59
  13. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. The full GNU General Public License is included in this distribution in the
  15. file called LICENSE.
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. /* e1000_hw.c
  21. * Shared functions for accessing and configuring the MAC
  22. */
  23. #include "e1000_hw.h"
  24. static int32_t e1000_set_phy_type(struct e1000_hw *hw);
  25. static void e1000_phy_init_script(struct e1000_hw *hw);
  26. static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
  27. static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
  28. static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
  29. static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
  30. static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
  31. static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
  32. static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
  33. static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
  34. uint16_t count);
  35. static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
  36. static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
  37. static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
  38. uint16_t words, uint16_t *data);
  39. static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
  40. uint16_t offset, uint16_t words,
  41. uint16_t *data);
  42. static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
  43. static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
  44. static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
  45. static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
  46. uint16_t count);
  47. static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
  48. uint16_t phy_data);
  49. static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
  50. uint16_t *phy_data);
  51. static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
  52. static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
  53. static void e1000_release_eeprom(struct e1000_hw *hw);
  54. static void e1000_standby_eeprom(struct e1000_hw *hw);
  55. static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
  56. static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
  57. static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
  58. static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
  59. static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
  60. static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
  61. static int32_t e1000_check_downshift(struct e1000_hw *hw);
  62. static int32_t e1000_check_polarity(struct e1000_hw *hw, uint16_t *polarity);
  63. static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
  64. static void e1000_clear_vfta(struct e1000_hw *hw);
  65. static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
  66. static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw,
  67. boolean_t link_up);
  68. static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
  69. static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
  70. static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
  71. static int32_t e1000_get_cable_length(struct e1000_hw *hw,
  72. uint16_t *min_length,
  73. uint16_t *max_length);
  74. static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
  75. static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
  76. static int32_t e1000_id_led_init(struct e1000_hw * hw);
  77. static void e1000_init_rx_addrs(struct e1000_hw *hw);
  78. static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
  79. static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
  80. static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
  81. static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset,
  82. uint16_t words, uint16_t *data);
  83. static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
  84. static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
  85. static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
  86. static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset,
  87. uint32_t value);
  88. #define E1000_WRITE_REG_IO(a, reg, val) \
  89. e1000_write_reg_io((a), E1000_##reg, val)
  90. /* IGP cable length table */
  91. static const
  92. uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
  93. { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  94. 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
  95. 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
  96. 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
  97. 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
  98. 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
  99. 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
  100. 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
  101. static const
  102. uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
  103. { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
  104. 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
  105. 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
  106. 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
  107. 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
  108. 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
  109. 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
  110. 104, 109, 114, 118, 121, 124};
  111. /******************************************************************************
  112. * Set the phy type member in the hw struct.
  113. *
  114. * hw - Struct containing variables accessed by shared code
  115. *****************************************************************************/
  116. int32_t
  117. e1000_set_phy_type(struct e1000_hw *hw)
  118. {
  119. DEBUGFUNC("e1000_set_phy_type");
  120. if(hw->mac_type == e1000_undefined)
  121. return -E1000_ERR_PHY_TYPE;
  122. switch(hw->phy_id) {
  123. case M88E1000_E_PHY_ID:
  124. case M88E1000_I_PHY_ID:
  125. case M88E1011_I_PHY_ID:
  126. case M88E1111_I_PHY_ID:
  127. hw->phy_type = e1000_phy_m88;
  128. break;
  129. case IGP01E1000_I_PHY_ID:
  130. if(hw->mac_type == e1000_82541 ||
  131. hw->mac_type == e1000_82541_rev_2 ||
  132. hw->mac_type == e1000_82547 ||
  133. hw->mac_type == e1000_82547_rev_2) {
  134. hw->phy_type = e1000_phy_igp;
  135. break;
  136. }
  137. /* Fall Through */
  138. default:
  139. /* Should never have loaded on this device */
  140. hw->phy_type = e1000_phy_undefined;
  141. return -E1000_ERR_PHY_TYPE;
  142. }
  143. return E1000_SUCCESS;
  144. }
  145. /******************************************************************************
  146. * IGP phy init script - initializes the GbE PHY
  147. *
  148. * hw - Struct containing variables accessed by shared code
  149. *****************************************************************************/
  150. static void
  151. e1000_phy_init_script(struct e1000_hw *hw)
  152. {
  153. uint32_t ret_val;
  154. uint16_t phy_saved_data;
  155. DEBUGFUNC("e1000_phy_init_script");
  156. if(hw->phy_init_script) {
  157. msec_delay(20);
  158. /* Save off the current value of register 0x2F5B to be restored at
  159. * the end of this routine. */
  160. ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  161. /* Disabled the PHY transmitter */
  162. e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  163. msec_delay(20);
  164. e1000_write_phy_reg(hw,0x0000,0x0140);
  165. msec_delay(5);
  166. switch(hw->mac_type) {
  167. case e1000_82541:
  168. case e1000_82547:
  169. e1000_write_phy_reg(hw, 0x1F95, 0x0001);
  170. e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
  171. e1000_write_phy_reg(hw, 0x1F79, 0x0018);
  172. e1000_write_phy_reg(hw, 0x1F30, 0x1600);
  173. e1000_write_phy_reg(hw, 0x1F31, 0x0014);
  174. e1000_write_phy_reg(hw, 0x1F32, 0x161C);
  175. e1000_write_phy_reg(hw, 0x1F94, 0x0003);
  176. e1000_write_phy_reg(hw, 0x1F96, 0x003F);
  177. e1000_write_phy_reg(hw, 0x2010, 0x0008);
  178. break;
  179. case e1000_82541_rev_2:
  180. case e1000_82547_rev_2:
  181. e1000_write_phy_reg(hw, 0x1F73, 0x0099);
  182. break;
  183. default:
  184. break;
  185. }
  186. e1000_write_phy_reg(hw, 0x0000, 0x3300);
  187. msec_delay(20);
  188. /* Now enable the transmitter */
  189. e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  190. if(hw->mac_type == e1000_82547) {
  191. uint16_t fused, fine, coarse;
  192. /* Move to analog registers page */
  193. e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
  194. if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
  195. e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
  196. fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
  197. coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
  198. if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
  199. coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
  200. fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
  201. } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
  202. fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
  203. fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
  204. (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
  205. (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
  206. e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
  207. e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
  208. IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
  209. }
  210. }
  211. }
  212. }
  213. /******************************************************************************
  214. * Set the mac type member in the hw struct.
  215. *
  216. * hw - Struct containing variables accessed by shared code
  217. *****************************************************************************/
  218. int32_t
  219. e1000_set_mac_type(struct e1000_hw *hw)
  220. {
  221. DEBUGFUNC("e1000_set_mac_type");
  222. switch (hw->device_id) {
  223. case E1000_DEV_ID_82542:
  224. switch (hw->revision_id) {
  225. case E1000_82542_2_0_REV_ID:
  226. hw->mac_type = e1000_82542_rev2_0;
  227. break;
  228. case E1000_82542_2_1_REV_ID:
  229. hw->mac_type = e1000_82542_rev2_1;
  230. break;
  231. default:
  232. /* Invalid 82542 revision ID */
  233. return -E1000_ERR_MAC_TYPE;
  234. }
  235. break;
  236. case E1000_DEV_ID_82543GC_FIBER:
  237. case E1000_DEV_ID_82543GC_COPPER:
  238. hw->mac_type = e1000_82543;
  239. break;
  240. case E1000_DEV_ID_82544EI_COPPER:
  241. case E1000_DEV_ID_82544EI_FIBER:
  242. case E1000_DEV_ID_82544GC_COPPER:
  243. case E1000_DEV_ID_82544GC_LOM:
  244. hw->mac_type = e1000_82544;
  245. break;
  246. case E1000_DEV_ID_82540EM:
  247. case E1000_DEV_ID_82540EM_LOM:
  248. case E1000_DEV_ID_82540EP:
  249. case E1000_DEV_ID_82540EP_LOM:
  250. case E1000_DEV_ID_82540EP_LP:
  251. hw->mac_type = e1000_82540;
  252. break;
  253. case E1000_DEV_ID_82545EM_COPPER:
  254. case E1000_DEV_ID_82545EM_FIBER:
  255. hw->mac_type = e1000_82545;
  256. break;
  257. case E1000_DEV_ID_82545GM_COPPER:
  258. case E1000_DEV_ID_82545GM_FIBER:
  259. case E1000_DEV_ID_82545GM_SERDES:
  260. hw->mac_type = e1000_82545_rev_3;
  261. break;
  262. case E1000_DEV_ID_82546EB_COPPER:
  263. case E1000_DEV_ID_82546EB_FIBER:
  264. case E1000_DEV_ID_82546EB_QUAD_COPPER:
  265. hw->mac_type = e1000_82546;
  266. break;
  267. case E1000_DEV_ID_82546GB_COPPER:
  268. case E1000_DEV_ID_82546GB_FIBER:
  269. case E1000_DEV_ID_82546GB_SERDES:
  270. case E1000_DEV_ID_82546GB_PCIE:
  271. hw->mac_type = e1000_82546_rev_3;
  272. break;
  273. case E1000_DEV_ID_82541EI:
  274. case E1000_DEV_ID_82541EI_MOBILE:
  275. hw->mac_type = e1000_82541;
  276. break;
  277. case E1000_DEV_ID_82541ER:
  278. case E1000_DEV_ID_82541GI:
  279. case E1000_DEV_ID_82541GI_LF:
  280. case E1000_DEV_ID_82541GI_MOBILE:
  281. hw->mac_type = e1000_82541_rev_2;
  282. break;
  283. case E1000_DEV_ID_82547EI:
  284. hw->mac_type = e1000_82547;
  285. break;
  286. case E1000_DEV_ID_82547GI:
  287. hw->mac_type = e1000_82547_rev_2;
  288. break;
  289. case E1000_DEV_ID_82571EB_COPPER:
  290. case E1000_DEV_ID_82571EB_FIBER:
  291. case E1000_DEV_ID_82571EB_SERDES:
  292. hw->mac_type = e1000_82571;
  293. break;
  294. case E1000_DEV_ID_82572EI_COPPER:
  295. case E1000_DEV_ID_82572EI_FIBER:
  296. case E1000_DEV_ID_82572EI_SERDES:
  297. hw->mac_type = e1000_82572;
  298. break;
  299. case E1000_DEV_ID_82573E:
  300. case E1000_DEV_ID_82573E_IAMT:
  301. case E1000_DEV_ID_82573L:
  302. hw->mac_type = e1000_82573;
  303. break;
  304. default:
  305. /* Should never have loaded on this device */
  306. return -E1000_ERR_MAC_TYPE;
  307. }
  308. switch(hw->mac_type) {
  309. case e1000_82571:
  310. case e1000_82572:
  311. case e1000_82573:
  312. hw->eeprom_semaphore_present = TRUE;
  313. /* fall through */
  314. case e1000_82541:
  315. case e1000_82547:
  316. case e1000_82541_rev_2:
  317. case e1000_82547_rev_2:
  318. hw->asf_firmware_present = TRUE;
  319. break;
  320. default:
  321. break;
  322. }
  323. return E1000_SUCCESS;
  324. }
  325. /*****************************************************************************
  326. * Set media type and TBI compatibility.
  327. *
  328. * hw - Struct containing variables accessed by shared code
  329. * **************************************************************************/
  330. void
  331. e1000_set_media_type(struct e1000_hw *hw)
  332. {
  333. uint32_t status;
  334. DEBUGFUNC("e1000_set_media_type");
  335. if(hw->mac_type != e1000_82543) {
  336. /* tbi_compatibility is only valid on 82543 */
  337. hw->tbi_compatibility_en = FALSE;
  338. }
  339. switch (hw->device_id) {
  340. case E1000_DEV_ID_82545GM_SERDES:
  341. case E1000_DEV_ID_82546GB_SERDES:
  342. case E1000_DEV_ID_82571EB_SERDES:
  343. case E1000_DEV_ID_82572EI_SERDES:
  344. hw->media_type = e1000_media_type_internal_serdes;
  345. break;
  346. default:
  347. switch (hw->mac_type) {
  348. case e1000_82542_rev2_0:
  349. case e1000_82542_rev2_1:
  350. hw->media_type = e1000_media_type_fiber;
  351. break;
  352. case e1000_82573:
  353. /* The STATUS_TBIMODE bit is reserved or reused for the this
  354. * device.
  355. */
  356. hw->media_type = e1000_media_type_copper;
  357. break;
  358. default:
  359. status = E1000_READ_REG(hw, STATUS);
  360. if (status & E1000_STATUS_TBIMODE) {
  361. hw->media_type = e1000_media_type_fiber;
  362. /* tbi_compatibility not valid on fiber */
  363. hw->tbi_compatibility_en = FALSE;
  364. } else {
  365. hw->media_type = e1000_media_type_copper;
  366. }
  367. break;
  368. }
  369. }
  370. }
  371. /******************************************************************************
  372. * Reset the transmit and receive units; mask and clear all interrupts.
  373. *
  374. * hw - Struct containing variables accessed by shared code
  375. *****************************************************************************/
  376. int32_t
  377. e1000_reset_hw(struct e1000_hw *hw)
  378. {
  379. uint32_t ctrl;
  380. uint32_t ctrl_ext;
  381. uint32_t icr;
  382. uint32_t manc;
  383. uint32_t led_ctrl;
  384. uint32_t timeout;
  385. uint32_t extcnf_ctrl;
  386. int32_t ret_val;
  387. DEBUGFUNC("e1000_reset_hw");
  388. /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
  389. if(hw->mac_type == e1000_82542_rev2_0) {
  390. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  391. e1000_pci_clear_mwi(hw);
  392. }
  393. if(hw->bus_type == e1000_bus_type_pci_express) {
  394. /* Prevent the PCI-E bus from sticking if there is no TLP connection
  395. * on the last TLP read/write transaction when MAC is reset.
  396. */
  397. if(e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
  398. DEBUGOUT("PCI-E Master disable polling has failed.\n");
  399. }
  400. }
  401. /* Clear interrupt mask to stop board from generating interrupts */
  402. DEBUGOUT("Masking off all interrupts\n");
  403. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  404. /* Disable the Transmit and Receive units. Then delay to allow
  405. * any pending transactions to complete before we hit the MAC with
  406. * the global reset.
  407. */
  408. E1000_WRITE_REG(hw, RCTL, 0);
  409. E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
  410. E1000_WRITE_FLUSH(hw);
  411. /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
  412. hw->tbi_compatibility_on = FALSE;
  413. /* Delay to allow any outstanding PCI transactions to complete before
  414. * resetting the device
  415. */
  416. msec_delay(10);
  417. ctrl = E1000_READ_REG(hw, CTRL);
  418. /* Must reset the PHY before resetting the MAC */
  419. if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  420. E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
  421. msec_delay(5);
  422. }
  423. /* Must acquire the MDIO ownership before MAC reset.
  424. * Ownership defaults to firmware after a reset. */
  425. if(hw->mac_type == e1000_82573) {
  426. timeout = 10;
  427. extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
  428. extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
  429. do {
  430. E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
  431. extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
  432. if(extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
  433. break;
  434. else
  435. extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
  436. msec_delay(2);
  437. timeout--;
  438. } while(timeout);
  439. }
  440. /* Issue a global reset to the MAC. This will reset the chip's
  441. * transmit, receive, DMA, and link units. It will not effect
  442. * the current PCI configuration. The global reset bit is self-
  443. * clearing, and should clear within a microsecond.
  444. */
  445. DEBUGOUT("Issuing a global reset to MAC\n");
  446. switch(hw->mac_type) {
  447. case e1000_82544:
  448. case e1000_82540:
  449. case e1000_82545:
  450. case e1000_82546:
  451. case e1000_82541:
  452. case e1000_82541_rev_2:
  453. /* These controllers can't ack the 64-bit write when issuing the
  454. * reset, so use IO-mapping as a workaround to issue the reset */
  455. E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
  456. break;
  457. case e1000_82545_rev_3:
  458. case e1000_82546_rev_3:
  459. /* Reset is performed on a shadow of the control register */
  460. E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
  461. break;
  462. default:
  463. E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
  464. break;
  465. }
  466. /* After MAC reset, force reload of EEPROM to restore power-on settings to
  467. * device. Later controllers reload the EEPROM automatically, so just wait
  468. * for reload to complete.
  469. */
  470. switch(hw->mac_type) {
  471. case e1000_82542_rev2_0:
  472. case e1000_82542_rev2_1:
  473. case e1000_82543:
  474. case e1000_82544:
  475. /* Wait for reset to complete */
  476. udelay(10);
  477. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  478. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  479. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  480. E1000_WRITE_FLUSH(hw);
  481. /* Wait for EEPROM reload */
  482. msec_delay(2);
  483. break;
  484. case e1000_82541:
  485. case e1000_82541_rev_2:
  486. case e1000_82547:
  487. case e1000_82547_rev_2:
  488. /* Wait for EEPROM reload */
  489. msec_delay(20);
  490. break;
  491. case e1000_82573:
  492. udelay(10);
  493. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  494. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  495. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  496. E1000_WRITE_FLUSH(hw);
  497. /* fall through */
  498. case e1000_82571:
  499. case e1000_82572:
  500. ret_val = e1000_get_auto_rd_done(hw);
  501. if(ret_val)
  502. /* We don't want to continue accessing MAC registers. */
  503. return ret_val;
  504. break;
  505. default:
  506. /* Wait for EEPROM reload (it happens automatically) */
  507. msec_delay(5);
  508. break;
  509. }
  510. /* Disable HW ARPs on ASF enabled adapters */
  511. if(hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
  512. manc = E1000_READ_REG(hw, MANC);
  513. manc &= ~(E1000_MANC_ARP_EN);
  514. E1000_WRITE_REG(hw, MANC, manc);
  515. }
  516. if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  517. e1000_phy_init_script(hw);
  518. /* Configure activity LED after PHY reset */
  519. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  520. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  521. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  522. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  523. }
  524. /* Clear interrupt mask to stop board from generating interrupts */
  525. DEBUGOUT("Masking off all interrupts\n");
  526. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  527. /* Clear any pending interrupt events. */
  528. icr = E1000_READ_REG(hw, ICR);
  529. /* If MWI was previously enabled, reenable it. */
  530. if(hw->mac_type == e1000_82542_rev2_0) {
  531. if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
  532. e1000_pci_set_mwi(hw);
  533. }
  534. return E1000_SUCCESS;
  535. }
  536. /******************************************************************************
  537. * Performs basic configuration of the adapter.
  538. *
  539. * hw - Struct containing variables accessed by shared code
  540. *
  541. * Assumes that the controller has previously been reset and is in a
  542. * post-reset uninitialized state. Initializes the receive address registers,
  543. * multicast table, and VLAN filter table. Calls routines to setup link
  544. * configuration and flow control settings. Clears all on-chip counters. Leaves
  545. * the transmit and receive units disabled and uninitialized.
  546. *****************************************************************************/
  547. int32_t
  548. e1000_init_hw(struct e1000_hw *hw)
  549. {
  550. uint32_t ctrl;
  551. uint32_t i;
  552. int32_t ret_val;
  553. uint16_t pcix_cmd_word;
  554. uint16_t pcix_stat_hi_word;
  555. uint16_t cmd_mmrbc;
  556. uint16_t stat_mmrbc;
  557. uint32_t mta_size;
  558. DEBUGFUNC("e1000_init_hw");
  559. /* Initialize Identification LED */
  560. ret_val = e1000_id_led_init(hw);
  561. if(ret_val) {
  562. DEBUGOUT("Error Initializing Identification LED\n");
  563. return ret_val;
  564. }
  565. /* Set the media type and TBI compatibility */
  566. e1000_set_media_type(hw);
  567. /* Disabling VLAN filtering. */
  568. DEBUGOUT("Initializing the IEEE VLAN\n");
  569. if (hw->mac_type < e1000_82545_rev_3)
  570. E1000_WRITE_REG(hw, VET, 0);
  571. e1000_clear_vfta(hw);
  572. /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
  573. if(hw->mac_type == e1000_82542_rev2_0) {
  574. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  575. e1000_pci_clear_mwi(hw);
  576. E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
  577. E1000_WRITE_FLUSH(hw);
  578. msec_delay(5);
  579. }
  580. /* Setup the receive address. This involves initializing all of the Receive
  581. * Address Registers (RARs 0 - 15).
  582. */
  583. e1000_init_rx_addrs(hw);
  584. /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
  585. if(hw->mac_type == e1000_82542_rev2_0) {
  586. E1000_WRITE_REG(hw, RCTL, 0);
  587. E1000_WRITE_FLUSH(hw);
  588. msec_delay(1);
  589. if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
  590. e1000_pci_set_mwi(hw);
  591. }
  592. /* Zero out the Multicast HASH table */
  593. DEBUGOUT("Zeroing the MTA\n");
  594. mta_size = E1000_MC_TBL_SIZE;
  595. for(i = 0; i < mta_size; i++)
  596. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  597. /* Set the PCI priority bit correctly in the CTRL register. This
  598. * determines if the adapter gives priority to receives, or if it
  599. * gives equal priority to transmits and receives. Valid only on
  600. * 82542 and 82543 silicon.
  601. */
  602. if(hw->dma_fairness && hw->mac_type <= e1000_82543) {
  603. ctrl = E1000_READ_REG(hw, CTRL);
  604. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
  605. }
  606. switch(hw->mac_type) {
  607. case e1000_82545_rev_3:
  608. case e1000_82546_rev_3:
  609. break;
  610. default:
  611. /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
  612. if(hw->bus_type == e1000_bus_type_pcix) {
  613. e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
  614. e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
  615. &pcix_stat_hi_word);
  616. cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
  617. PCIX_COMMAND_MMRBC_SHIFT;
  618. stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
  619. PCIX_STATUS_HI_MMRBC_SHIFT;
  620. if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
  621. stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
  622. if(cmd_mmrbc > stat_mmrbc) {
  623. pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
  624. pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
  625. e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
  626. &pcix_cmd_word);
  627. }
  628. }
  629. break;
  630. }
  631. /* Call a subroutine to configure the link and setup flow control. */
  632. ret_val = e1000_setup_link(hw);
  633. /* Set the transmit descriptor write-back policy */
  634. if(hw->mac_type > e1000_82544) {
  635. ctrl = E1000_READ_REG(hw, TXDCTL);
  636. ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
  637. switch (hw->mac_type) {
  638. default:
  639. break;
  640. case e1000_82571:
  641. case e1000_82572:
  642. ctrl |= (1 << 22);
  643. case e1000_82573:
  644. ctrl |= E1000_TXDCTL_COUNT_DESC;
  645. break;
  646. }
  647. E1000_WRITE_REG(hw, TXDCTL, ctrl);
  648. }
  649. if (hw->mac_type == e1000_82573) {
  650. e1000_enable_tx_pkt_filtering(hw);
  651. }
  652. switch (hw->mac_type) {
  653. default:
  654. break;
  655. case e1000_82571:
  656. case e1000_82572:
  657. ctrl = E1000_READ_REG(hw, TXDCTL1);
  658. ctrl &= ~E1000_TXDCTL_WTHRESH;
  659. ctrl |= E1000_TXDCTL_COUNT_DESC | E1000_TXDCTL_FULL_TX_DESC_WB;
  660. ctrl |= (1 << 22);
  661. E1000_WRITE_REG(hw, TXDCTL1, ctrl);
  662. break;
  663. }
  664. if (hw->mac_type == e1000_82573) {
  665. uint32_t gcr = E1000_READ_REG(hw, GCR);
  666. gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
  667. E1000_WRITE_REG(hw, GCR, gcr);
  668. }
  669. /* Clear all of the statistics registers (clear on read). It is
  670. * important that we do this after we have tried to establish link
  671. * because the symbol error count will increment wildly if there
  672. * is no link.
  673. */
  674. e1000_clear_hw_cntrs(hw);
  675. return ret_val;
  676. }
  677. /******************************************************************************
  678. * Adjust SERDES output amplitude based on EEPROM setting.
  679. *
  680. * hw - Struct containing variables accessed by shared code.
  681. *****************************************************************************/
  682. static int32_t
  683. e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
  684. {
  685. uint16_t eeprom_data;
  686. int32_t ret_val;
  687. DEBUGFUNC("e1000_adjust_serdes_amplitude");
  688. if(hw->media_type != e1000_media_type_internal_serdes)
  689. return E1000_SUCCESS;
  690. switch(hw->mac_type) {
  691. case e1000_82545_rev_3:
  692. case e1000_82546_rev_3:
  693. break;
  694. default:
  695. return E1000_SUCCESS;
  696. }
  697. ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
  698. if (ret_val) {
  699. return ret_val;
  700. }
  701. if(eeprom_data != EEPROM_RESERVED_WORD) {
  702. /* Adjust SERDES output amplitude only. */
  703. eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
  704. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
  705. if(ret_val)
  706. return ret_val;
  707. }
  708. return E1000_SUCCESS;
  709. }
  710. /******************************************************************************
  711. * Configures flow control and link settings.
  712. *
  713. * hw - Struct containing variables accessed by shared code
  714. *
  715. * Determines which flow control settings to use. Calls the apropriate media-
  716. * specific link configuration function. Configures the flow control settings.
  717. * Assuming the adapter has a valid link partner, a valid link should be
  718. * established. Assumes the hardware has previously been reset and the
  719. * transmitter and receiver are not enabled.
  720. *****************************************************************************/
  721. int32_t
  722. e1000_setup_link(struct e1000_hw *hw)
  723. {
  724. uint32_t ctrl_ext;
  725. int32_t ret_val;
  726. uint16_t eeprom_data;
  727. DEBUGFUNC("e1000_setup_link");
  728. /* Read and store word 0x0F of the EEPROM. This word contains bits
  729. * that determine the hardware's default PAUSE (flow control) mode,
  730. * a bit that determines whether the HW defaults to enabling or
  731. * disabling auto-negotiation, and the direction of the
  732. * SW defined pins. If there is no SW over-ride of the flow
  733. * control setting, then the variable hw->fc will
  734. * be initialized based on a value in the EEPROM.
  735. */
  736. if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data)) {
  737. DEBUGOUT("EEPROM Read Error\n");
  738. return -E1000_ERR_EEPROM;
  739. }
  740. if(hw->fc == e1000_fc_default) {
  741. if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
  742. hw->fc = e1000_fc_none;
  743. else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
  744. EEPROM_WORD0F_ASM_DIR)
  745. hw->fc = e1000_fc_tx_pause;
  746. else
  747. hw->fc = e1000_fc_full;
  748. }
  749. /* We want to save off the original Flow Control configuration just
  750. * in case we get disconnected and then reconnected into a different
  751. * hub or switch with different Flow Control capabilities.
  752. */
  753. if(hw->mac_type == e1000_82542_rev2_0)
  754. hw->fc &= (~e1000_fc_tx_pause);
  755. if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
  756. hw->fc &= (~e1000_fc_rx_pause);
  757. hw->original_fc = hw->fc;
  758. DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
  759. /* Take the 4 bits from EEPROM word 0x0F that determine the initial
  760. * polarity value for the SW controlled pins, and setup the
  761. * Extended Device Control reg with that info.
  762. * This is needed because one of the SW controlled pins is used for
  763. * signal detection. So this should be done before e1000_setup_pcs_link()
  764. * or e1000_phy_setup() is called.
  765. */
  766. if(hw->mac_type == e1000_82543) {
  767. ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
  768. SWDPIO__EXT_SHIFT);
  769. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  770. }
  771. /* Call the necessary subroutine to configure the link. */
  772. ret_val = (hw->media_type == e1000_media_type_copper) ?
  773. e1000_setup_copper_link(hw) :
  774. e1000_setup_fiber_serdes_link(hw);
  775. /* Initialize the flow control address, type, and PAUSE timer
  776. * registers to their default values. This is done even if flow
  777. * control is disabled, because it does not hurt anything to
  778. * initialize these registers.
  779. */
  780. DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
  781. E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
  782. E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  783. E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
  784. E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
  785. /* Set the flow control receive threshold registers. Normally,
  786. * these registers will be set to a default threshold that may be
  787. * adjusted later by the driver's runtime code. However, if the
  788. * ability to transmit pause frames in not enabled, then these
  789. * registers will be set to 0.
  790. */
  791. if(!(hw->fc & e1000_fc_tx_pause)) {
  792. E1000_WRITE_REG(hw, FCRTL, 0);
  793. E1000_WRITE_REG(hw, FCRTH, 0);
  794. } else {
  795. /* We need to set up the Receive Threshold high and low water marks
  796. * as well as (optionally) enabling the transmission of XON frames.
  797. */
  798. if(hw->fc_send_xon) {
  799. E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
  800. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  801. } else {
  802. E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
  803. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  804. }
  805. }
  806. return ret_val;
  807. }
  808. /******************************************************************************
  809. * Sets up link for a fiber based or serdes based adapter
  810. *
  811. * hw - Struct containing variables accessed by shared code
  812. *
  813. * Manipulates Physical Coding Sublayer functions in order to configure
  814. * link. Assumes the hardware has been previously reset and the transmitter
  815. * and receiver are not enabled.
  816. *****************************************************************************/
  817. static int32_t
  818. e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
  819. {
  820. uint32_t ctrl;
  821. uint32_t status;
  822. uint32_t txcw = 0;
  823. uint32_t i;
  824. uint32_t signal = 0;
  825. int32_t ret_val;
  826. DEBUGFUNC("e1000_setup_fiber_serdes_link");
  827. /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
  828. * until explicitly turned off or a power cycle is performed. A read to
  829. * the register does not indicate its status. Therefore, we ensure
  830. * loopback mode is disabled during initialization.
  831. */
  832. if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
  833. E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
  834. /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
  835. * set when the optics detect a signal. On older adapters, it will be
  836. * cleared when there is a signal. This applies to fiber media only.
  837. * If we're on serdes media, adjust the output amplitude to value set in
  838. * the EEPROM.
  839. */
  840. ctrl = E1000_READ_REG(hw, CTRL);
  841. if(hw->media_type == e1000_media_type_fiber)
  842. signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
  843. ret_val = e1000_adjust_serdes_amplitude(hw);
  844. if(ret_val)
  845. return ret_val;
  846. /* Take the link out of reset */
  847. ctrl &= ~(E1000_CTRL_LRST);
  848. /* Adjust VCO speed to improve BER performance */
  849. ret_val = e1000_set_vco_speed(hw);
  850. if(ret_val)
  851. return ret_val;
  852. e1000_config_collision_dist(hw);
  853. /* Check for a software override of the flow control settings, and setup
  854. * the device accordingly. If auto-negotiation is enabled, then software
  855. * will have to set the "PAUSE" bits to the correct value in the Tranmsit
  856. * Config Word Register (TXCW) and re-start auto-negotiation. However, if
  857. * auto-negotiation is disabled, then software will have to manually
  858. * configure the two flow control enable bits in the CTRL register.
  859. *
  860. * The possible values of the "fc" parameter are:
  861. * 0: Flow control is completely disabled
  862. * 1: Rx flow control is enabled (we can receive pause frames, but
  863. * not send pause frames).
  864. * 2: Tx flow control is enabled (we can send pause frames but we do
  865. * not support receiving pause frames).
  866. * 3: Both Rx and TX flow control (symmetric) are enabled.
  867. */
  868. switch (hw->fc) {
  869. case e1000_fc_none:
  870. /* Flow control is completely disabled by a software over-ride. */
  871. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
  872. break;
  873. case e1000_fc_rx_pause:
  874. /* RX Flow control is enabled and TX Flow control is disabled by a
  875. * software over-ride. Since there really isn't a way to advertise
  876. * that we are capable of RX Pause ONLY, we will advertise that we
  877. * support both symmetric and asymmetric RX PAUSE. Later, we will
  878. * disable the adapter's ability to send PAUSE frames.
  879. */
  880. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  881. break;
  882. case e1000_fc_tx_pause:
  883. /* TX Flow control is enabled, and RX Flow control is disabled, by a
  884. * software over-ride.
  885. */
  886. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
  887. break;
  888. case e1000_fc_full:
  889. /* Flow control (both RX and TX) is enabled by a software over-ride. */
  890. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  891. break;
  892. default:
  893. DEBUGOUT("Flow control param set incorrectly\n");
  894. return -E1000_ERR_CONFIG;
  895. break;
  896. }
  897. /* Since auto-negotiation is enabled, take the link out of reset (the link
  898. * will be in reset, because we previously reset the chip). This will
  899. * restart auto-negotiation. If auto-neogtiation is successful then the
  900. * link-up status bit will be set and the flow control enable bits (RFCE
  901. * and TFCE) will be set according to their negotiated value.
  902. */
  903. DEBUGOUT("Auto-negotiation enabled\n");
  904. E1000_WRITE_REG(hw, TXCW, txcw);
  905. E1000_WRITE_REG(hw, CTRL, ctrl);
  906. E1000_WRITE_FLUSH(hw);
  907. hw->txcw = txcw;
  908. msec_delay(1);
  909. /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
  910. * indication in the Device Status Register. Time-out if a link isn't
  911. * seen in 500 milliseconds seconds (Auto-negotiation should complete in
  912. * less than 500 milliseconds even if the other end is doing it in SW).
  913. * For internal serdes, we just assume a signal is present, then poll.
  914. */
  915. if(hw->media_type == e1000_media_type_internal_serdes ||
  916. (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
  917. DEBUGOUT("Looking for Link\n");
  918. for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
  919. msec_delay(10);
  920. status = E1000_READ_REG(hw, STATUS);
  921. if(status & E1000_STATUS_LU) break;
  922. }
  923. if(i == (LINK_UP_TIMEOUT / 10)) {
  924. DEBUGOUT("Never got a valid link from auto-neg!!!\n");
  925. hw->autoneg_failed = 1;
  926. /* AutoNeg failed to achieve a link, so we'll call
  927. * e1000_check_for_link. This routine will force the link up if
  928. * we detect a signal. This will allow us to communicate with
  929. * non-autonegotiating link partners.
  930. */
  931. ret_val = e1000_check_for_link(hw);
  932. if(ret_val) {
  933. DEBUGOUT("Error while checking for link\n");
  934. return ret_val;
  935. }
  936. hw->autoneg_failed = 0;
  937. } else {
  938. hw->autoneg_failed = 0;
  939. DEBUGOUT("Valid Link Found\n");
  940. }
  941. } else {
  942. DEBUGOUT("No Signal Detected\n");
  943. }
  944. return E1000_SUCCESS;
  945. }
  946. /******************************************************************************
  947. * Make sure we have a valid PHY and change PHY mode before link setup.
  948. *
  949. * hw - Struct containing variables accessed by shared code
  950. ******************************************************************************/
  951. static int32_t
  952. e1000_copper_link_preconfig(struct e1000_hw *hw)
  953. {
  954. uint32_t ctrl;
  955. int32_t ret_val;
  956. uint16_t phy_data;
  957. DEBUGFUNC("e1000_copper_link_preconfig");
  958. ctrl = E1000_READ_REG(hw, CTRL);
  959. /* With 82543, we need to force speed and duplex on the MAC equal to what
  960. * the PHY speed and duplex configuration is. In addition, we need to
  961. * perform a hardware reset on the PHY to take it out of reset.
  962. */
  963. if(hw->mac_type > e1000_82543) {
  964. ctrl |= E1000_CTRL_SLU;
  965. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  966. E1000_WRITE_REG(hw, CTRL, ctrl);
  967. } else {
  968. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
  969. E1000_WRITE_REG(hw, CTRL, ctrl);
  970. ret_val = e1000_phy_hw_reset(hw);
  971. if(ret_val)
  972. return ret_val;
  973. }
  974. /* Make sure we have a valid PHY */
  975. ret_val = e1000_detect_gig_phy(hw);
  976. if(ret_val) {
  977. DEBUGOUT("Error, did not detect valid phy.\n");
  978. return ret_val;
  979. }
  980. DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
  981. /* Set PHY to class A mode (if necessary) */
  982. ret_val = e1000_set_phy_mode(hw);
  983. if(ret_val)
  984. return ret_val;
  985. if((hw->mac_type == e1000_82545_rev_3) ||
  986. (hw->mac_type == e1000_82546_rev_3)) {
  987. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  988. phy_data |= 0x00000008;
  989. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  990. }
  991. if(hw->mac_type <= e1000_82543 ||
  992. hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
  993. hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
  994. hw->phy_reset_disable = FALSE;
  995. return E1000_SUCCESS;
  996. }
  997. /********************************************************************
  998. * Copper link setup for e1000_phy_igp series.
  999. *
  1000. * hw - Struct containing variables accessed by shared code
  1001. *********************************************************************/
  1002. static int32_t
  1003. e1000_copper_link_igp_setup(struct e1000_hw *hw)
  1004. {
  1005. uint32_t led_ctrl;
  1006. int32_t ret_val;
  1007. uint16_t phy_data;
  1008. DEBUGFUNC("e1000_copper_link_igp_setup");
  1009. if (hw->phy_reset_disable)
  1010. return E1000_SUCCESS;
  1011. ret_val = e1000_phy_reset(hw);
  1012. if (ret_val) {
  1013. DEBUGOUT("Error Resetting the PHY\n");
  1014. return ret_val;
  1015. }
  1016. /* Wait 10ms for MAC to configure PHY from eeprom settings */
  1017. msec_delay(15);
  1018. /* Configure activity LED after PHY reset */
  1019. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  1020. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  1021. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  1022. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  1023. /* disable lplu d3 during driver init */
  1024. ret_val = e1000_set_d3_lplu_state(hw, FALSE);
  1025. if (ret_val) {
  1026. DEBUGOUT("Error Disabling LPLU D3\n");
  1027. return ret_val;
  1028. }
  1029. /* disable lplu d0 during driver init */
  1030. ret_val = e1000_set_d0_lplu_state(hw, FALSE);
  1031. if (ret_val) {
  1032. DEBUGOUT("Error Disabling LPLU D0\n");
  1033. return ret_val;
  1034. }
  1035. /* Configure mdi-mdix settings */
  1036. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  1037. if (ret_val)
  1038. return ret_val;
  1039. if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  1040. hw->dsp_config_state = e1000_dsp_config_disabled;
  1041. /* Force MDI for earlier revs of the IGP PHY */
  1042. phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
  1043. hw->mdix = 1;
  1044. } else {
  1045. hw->dsp_config_state = e1000_dsp_config_enabled;
  1046. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  1047. switch (hw->mdix) {
  1048. case 1:
  1049. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1050. break;
  1051. case 2:
  1052. phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1053. break;
  1054. case 0:
  1055. default:
  1056. phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
  1057. break;
  1058. }
  1059. }
  1060. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  1061. if(ret_val)
  1062. return ret_val;
  1063. /* set auto-master slave resolution settings */
  1064. if(hw->autoneg) {
  1065. e1000_ms_type phy_ms_setting = hw->master_slave;
  1066. if(hw->ffe_config_state == e1000_ffe_config_active)
  1067. hw->ffe_config_state = e1000_ffe_config_enabled;
  1068. if(hw->dsp_config_state == e1000_dsp_config_activated)
  1069. hw->dsp_config_state = e1000_dsp_config_enabled;
  1070. /* when autonegotiation advertisment is only 1000Mbps then we
  1071. * should disable SmartSpeed and enable Auto MasterSlave
  1072. * resolution as hardware default. */
  1073. if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
  1074. /* Disable SmartSpeed */
  1075. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  1076. if(ret_val)
  1077. return ret_val;
  1078. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1079. ret_val = e1000_write_phy_reg(hw,
  1080. IGP01E1000_PHY_PORT_CONFIG,
  1081. phy_data);
  1082. if(ret_val)
  1083. return ret_val;
  1084. /* Set auto Master/Slave resolution process */
  1085. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
  1086. if(ret_val)
  1087. return ret_val;
  1088. phy_data &= ~CR_1000T_MS_ENABLE;
  1089. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
  1090. if(ret_val)
  1091. return ret_val;
  1092. }
  1093. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
  1094. if(ret_val)
  1095. return ret_val;
  1096. /* load defaults for future use */
  1097. hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
  1098. ((phy_data & CR_1000T_MS_VALUE) ?
  1099. e1000_ms_force_master :
  1100. e1000_ms_force_slave) :
  1101. e1000_ms_auto;
  1102. switch (phy_ms_setting) {
  1103. case e1000_ms_force_master:
  1104. phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
  1105. break;
  1106. case e1000_ms_force_slave:
  1107. phy_data |= CR_1000T_MS_ENABLE;
  1108. phy_data &= ~(CR_1000T_MS_VALUE);
  1109. break;
  1110. case e1000_ms_auto:
  1111. phy_data &= ~CR_1000T_MS_ENABLE;
  1112. default:
  1113. break;
  1114. }
  1115. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
  1116. if(ret_val)
  1117. return ret_val;
  1118. }
  1119. return E1000_SUCCESS;
  1120. }
  1121. /********************************************************************
  1122. * Copper link setup for e1000_phy_m88 series.
  1123. *
  1124. * hw - Struct containing variables accessed by shared code
  1125. *********************************************************************/
  1126. static int32_t
  1127. e1000_copper_link_mgp_setup(struct e1000_hw *hw)
  1128. {
  1129. int32_t ret_val;
  1130. uint16_t phy_data;
  1131. DEBUGFUNC("e1000_copper_link_mgp_setup");
  1132. if(hw->phy_reset_disable)
  1133. return E1000_SUCCESS;
  1134. /* Enable CRS on TX. This must be set for half-duplex operation. */
  1135. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1136. if(ret_val)
  1137. return ret_val;
  1138. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  1139. /* Options:
  1140. * MDI/MDI-X = 0 (default)
  1141. * 0 - Auto for all speeds
  1142. * 1 - MDI mode
  1143. * 2 - MDI-X mode
  1144. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  1145. */
  1146. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  1147. switch (hw->mdix) {
  1148. case 1:
  1149. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  1150. break;
  1151. case 2:
  1152. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  1153. break;
  1154. case 3:
  1155. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  1156. break;
  1157. case 0:
  1158. default:
  1159. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  1160. break;
  1161. }
  1162. /* Options:
  1163. * disable_polarity_correction = 0 (default)
  1164. * Automatic Correction for Reversed Cable Polarity
  1165. * 0 - Disabled
  1166. * 1 - Enabled
  1167. */
  1168. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  1169. if(hw->disable_polarity_correction == 1)
  1170. phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
  1171. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1172. if(ret_val)
  1173. return ret_val;
  1174. /* Force TX_CLK in the Extended PHY Specific Control Register
  1175. * to 25MHz clock.
  1176. */
  1177. ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  1178. if(ret_val)
  1179. return ret_val;
  1180. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  1181. if (hw->phy_revision < M88E1011_I_REV_4) {
  1182. /* Configure Master and Slave downshift values */
  1183. phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
  1184. M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  1185. phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
  1186. M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  1187. ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  1188. if(ret_val)
  1189. return ret_val;
  1190. }
  1191. /* SW Reset the PHY so all changes take effect */
  1192. ret_val = e1000_phy_reset(hw);
  1193. if(ret_val) {
  1194. DEBUGOUT("Error Resetting the PHY\n");
  1195. return ret_val;
  1196. }
  1197. return E1000_SUCCESS;
  1198. }
  1199. /********************************************************************
  1200. * Setup auto-negotiation and flow control advertisements,
  1201. * and then perform auto-negotiation.
  1202. *
  1203. * hw - Struct containing variables accessed by shared code
  1204. *********************************************************************/
  1205. static int32_t
  1206. e1000_copper_link_autoneg(struct e1000_hw *hw)
  1207. {
  1208. int32_t ret_val;
  1209. uint16_t phy_data;
  1210. DEBUGFUNC("e1000_copper_link_autoneg");
  1211. /* Perform some bounds checking on the hw->autoneg_advertised
  1212. * parameter. If this variable is zero, then set it to the default.
  1213. */
  1214. hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
  1215. /* If autoneg_advertised is zero, we assume it was not defaulted
  1216. * by the calling code so we set to advertise full capability.
  1217. */
  1218. if(hw->autoneg_advertised == 0)
  1219. hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  1220. DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
  1221. ret_val = e1000_phy_setup_autoneg(hw);
  1222. if(ret_val) {
  1223. DEBUGOUT("Error Setting up Auto-Negotiation\n");
  1224. return ret_val;
  1225. }
  1226. DEBUGOUT("Restarting Auto-Neg\n");
  1227. /* Restart auto-negotiation by setting the Auto Neg Enable bit and
  1228. * the Auto Neg Restart bit in the PHY control register.
  1229. */
  1230. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
  1231. if(ret_val)
  1232. return ret_val;
  1233. phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
  1234. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
  1235. if(ret_val)
  1236. return ret_val;
  1237. /* Does the user want to wait for Auto-Neg to complete here, or
  1238. * check at a later time (for example, callback routine).
  1239. */
  1240. if(hw->wait_autoneg_complete) {
  1241. ret_val = e1000_wait_autoneg(hw);
  1242. if(ret_val) {
  1243. DEBUGOUT("Error while waiting for autoneg to complete\n");
  1244. return ret_val;
  1245. }
  1246. }
  1247. hw->get_link_status = TRUE;
  1248. return E1000_SUCCESS;
  1249. }
  1250. /******************************************************************************
  1251. * Config the MAC and the PHY after link is up.
  1252. * 1) Set up the MAC to the current PHY speed/duplex
  1253. * if we are on 82543. If we
  1254. * are on newer silicon, we only need to configure
  1255. * collision distance in the Transmit Control Register.
  1256. * 2) Set up flow control on the MAC to that established with
  1257. * the link partner.
  1258. * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
  1259. *
  1260. * hw - Struct containing variables accessed by shared code
  1261. ******************************************************************************/
  1262. static int32_t
  1263. e1000_copper_link_postconfig(struct e1000_hw *hw)
  1264. {
  1265. int32_t ret_val;
  1266. DEBUGFUNC("e1000_copper_link_postconfig");
  1267. if(hw->mac_type >= e1000_82544) {
  1268. e1000_config_collision_dist(hw);
  1269. } else {
  1270. ret_val = e1000_config_mac_to_phy(hw);
  1271. if(ret_val) {
  1272. DEBUGOUT("Error configuring MAC to PHY settings\n");
  1273. return ret_val;
  1274. }
  1275. }
  1276. ret_val = e1000_config_fc_after_link_up(hw);
  1277. if(ret_val) {
  1278. DEBUGOUT("Error Configuring Flow Control\n");
  1279. return ret_val;
  1280. }
  1281. /* Config DSP to improve Giga link quality */
  1282. if(hw->phy_type == e1000_phy_igp) {
  1283. ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
  1284. if(ret_val) {
  1285. DEBUGOUT("Error Configuring DSP after link up\n");
  1286. return ret_val;
  1287. }
  1288. }
  1289. return E1000_SUCCESS;
  1290. }
  1291. /******************************************************************************
  1292. * Detects which PHY is present and setup the speed and duplex
  1293. *
  1294. * hw - Struct containing variables accessed by shared code
  1295. ******************************************************************************/
  1296. static int32_t
  1297. e1000_setup_copper_link(struct e1000_hw *hw)
  1298. {
  1299. int32_t ret_val;
  1300. uint16_t i;
  1301. uint16_t phy_data;
  1302. DEBUGFUNC("e1000_setup_copper_link");
  1303. /* Check if it is a valid PHY and set PHY mode if necessary. */
  1304. ret_val = e1000_copper_link_preconfig(hw);
  1305. if(ret_val)
  1306. return ret_val;
  1307. if (hw->phy_type == e1000_phy_igp ||
  1308. hw->phy_type == e1000_phy_igp_2) {
  1309. ret_val = e1000_copper_link_igp_setup(hw);
  1310. if(ret_val)
  1311. return ret_val;
  1312. } else if (hw->phy_type == e1000_phy_m88) {
  1313. ret_val = e1000_copper_link_mgp_setup(hw);
  1314. if(ret_val)
  1315. return ret_val;
  1316. }
  1317. if(hw->autoneg) {
  1318. /* Setup autoneg and flow control advertisement
  1319. * and perform autonegotiation */
  1320. ret_val = e1000_copper_link_autoneg(hw);
  1321. if(ret_val)
  1322. return ret_val;
  1323. } else {
  1324. /* PHY will be set to 10H, 10F, 100H,or 100F
  1325. * depending on value from forced_speed_duplex. */
  1326. DEBUGOUT("Forcing speed and duplex\n");
  1327. ret_val = e1000_phy_force_speed_duplex(hw);
  1328. if(ret_val) {
  1329. DEBUGOUT("Error Forcing Speed and Duplex\n");
  1330. return ret_val;
  1331. }
  1332. }
  1333. /* Check link status. Wait up to 100 microseconds for link to become
  1334. * valid.
  1335. */
  1336. for(i = 0; i < 10; i++) {
  1337. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  1338. if(ret_val)
  1339. return ret_val;
  1340. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  1341. if(ret_val)
  1342. return ret_val;
  1343. if(phy_data & MII_SR_LINK_STATUS) {
  1344. /* Config the MAC and PHY after link is up */
  1345. ret_val = e1000_copper_link_postconfig(hw);
  1346. if(ret_val)
  1347. return ret_val;
  1348. DEBUGOUT("Valid link established!!!\n");
  1349. return E1000_SUCCESS;
  1350. }
  1351. udelay(10);
  1352. }
  1353. DEBUGOUT("Unable to establish link!!!\n");
  1354. return E1000_SUCCESS;
  1355. }
  1356. /******************************************************************************
  1357. * Configures PHY autoneg and flow control advertisement settings
  1358. *
  1359. * hw - Struct containing variables accessed by shared code
  1360. ******************************************************************************/
  1361. int32_t
  1362. e1000_phy_setup_autoneg(struct e1000_hw *hw)
  1363. {
  1364. int32_t ret_val;
  1365. uint16_t mii_autoneg_adv_reg;
  1366. uint16_t mii_1000t_ctrl_reg;
  1367. DEBUGFUNC("e1000_phy_setup_autoneg");
  1368. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  1369. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
  1370. if(ret_val)
  1371. return ret_val;
  1372. /* Read the MII 1000Base-T Control Register (Address 9). */
  1373. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
  1374. if(ret_val)
  1375. return ret_val;
  1376. /* Need to parse both autoneg_advertised and fc and set up
  1377. * the appropriate PHY registers. First we will parse for
  1378. * autoneg_advertised software override. Since we can advertise
  1379. * a plethora of combinations, we need to check each bit
  1380. * individually.
  1381. */
  1382. /* First we clear all the 10/100 mb speed bits in the Auto-Neg
  1383. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  1384. * the 1000Base-T Control Register (Address 9).
  1385. */
  1386. mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
  1387. mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
  1388. DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
  1389. /* Do we want to advertise 10 Mb Half Duplex? */
  1390. if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
  1391. DEBUGOUT("Advertise 10mb Half duplex\n");
  1392. mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
  1393. }
  1394. /* Do we want to advertise 10 Mb Full Duplex? */
  1395. if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
  1396. DEBUGOUT("Advertise 10mb Full duplex\n");
  1397. mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
  1398. }
  1399. /* Do we want to advertise 100 Mb Half Duplex? */
  1400. if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
  1401. DEBUGOUT("Advertise 100mb Half duplex\n");
  1402. mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
  1403. }
  1404. /* Do we want to advertise 100 Mb Full Duplex? */
  1405. if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
  1406. DEBUGOUT("Advertise 100mb Full duplex\n");
  1407. mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
  1408. }
  1409. /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  1410. if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
  1411. DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
  1412. }
  1413. /* Do we want to advertise 1000 Mb Full Duplex? */
  1414. if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
  1415. DEBUGOUT("Advertise 1000mb Full duplex\n");
  1416. mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
  1417. }
  1418. /* Check for a software override of the flow control settings, and
  1419. * setup the PHY advertisement registers accordingly. If
  1420. * auto-negotiation is enabled, then software will have to set the
  1421. * "PAUSE" bits to the correct value in the Auto-Negotiation
  1422. * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
  1423. *
  1424. * The possible values of the "fc" parameter are:
  1425. * 0: Flow control is completely disabled
  1426. * 1: Rx flow control is enabled (we can receive pause frames
  1427. * but not send pause frames).
  1428. * 2: Tx flow control is enabled (we can send pause frames
  1429. * but we do not support receiving pause frames).
  1430. * 3: Both Rx and TX flow control (symmetric) are enabled.
  1431. * other: No software override. The flow control configuration
  1432. * in the EEPROM is used.
  1433. */
  1434. switch (hw->fc) {
  1435. case e1000_fc_none: /* 0 */
  1436. /* Flow control (RX & TX) is completely disabled by a
  1437. * software over-ride.
  1438. */
  1439. mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1440. break;
  1441. case e1000_fc_rx_pause: /* 1 */
  1442. /* RX Flow control is enabled, and TX Flow control is
  1443. * disabled, by a software over-ride.
  1444. */
  1445. /* Since there really isn't a way to advertise that we are
  1446. * capable of RX Pause ONLY, we will advertise that we
  1447. * support both symmetric and asymmetric RX PAUSE. Later
  1448. * (in e1000_config_fc_after_link_up) we will disable the
  1449. *hw's ability to send PAUSE frames.
  1450. */
  1451. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1452. break;
  1453. case e1000_fc_tx_pause: /* 2 */
  1454. /* TX Flow control is enabled, and RX Flow control is
  1455. * disabled, by a software over-ride.
  1456. */
  1457. mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
  1458. mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
  1459. break;
  1460. case e1000_fc_full: /* 3 */
  1461. /* Flow control (both RX and TX) is enabled by a software
  1462. * over-ride.
  1463. */
  1464. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1465. break;
  1466. default:
  1467. DEBUGOUT("Flow control param set incorrectly\n");
  1468. return -E1000_ERR_CONFIG;
  1469. }
  1470. ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
  1471. if(ret_val)
  1472. return ret_val;
  1473. DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  1474. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
  1475. if(ret_val)
  1476. return ret_val;
  1477. return E1000_SUCCESS;
  1478. }
  1479. /******************************************************************************
  1480. * Force PHY speed and duplex settings to hw->forced_speed_duplex
  1481. *
  1482. * hw - Struct containing variables accessed by shared code
  1483. ******************************************************************************/
  1484. static int32_t
  1485. e1000_phy_force_speed_duplex(struct e1000_hw *hw)
  1486. {
  1487. uint32_t ctrl;
  1488. int32_t ret_val;
  1489. uint16_t mii_ctrl_reg;
  1490. uint16_t mii_status_reg;
  1491. uint16_t phy_data;
  1492. uint16_t i;
  1493. DEBUGFUNC("e1000_phy_force_speed_duplex");
  1494. /* Turn off Flow control if we are forcing speed and duplex. */
  1495. hw->fc = e1000_fc_none;
  1496. DEBUGOUT1("hw->fc = %d\n", hw->fc);
  1497. /* Read the Device Control Register. */
  1498. ctrl = E1000_READ_REG(hw, CTRL);
  1499. /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
  1500. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1501. ctrl &= ~(DEVICE_SPEED_MASK);
  1502. /* Clear the Auto Speed Detect Enable bit. */
  1503. ctrl &= ~E1000_CTRL_ASDE;
  1504. /* Read the MII Control Register. */
  1505. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
  1506. if(ret_val)
  1507. return ret_val;
  1508. /* We need to disable autoneg in order to force link and duplex. */
  1509. mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
  1510. /* Are we forcing Full or Half Duplex? */
  1511. if(hw->forced_speed_duplex == e1000_100_full ||
  1512. hw->forced_speed_duplex == e1000_10_full) {
  1513. /* We want to force full duplex so we SET the full duplex bits in the
  1514. * Device and MII Control Registers.
  1515. */
  1516. ctrl |= E1000_CTRL_FD;
  1517. mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
  1518. DEBUGOUT("Full Duplex\n");
  1519. } else {
  1520. /* We want to force half duplex so we CLEAR the full duplex bits in
  1521. * the Device and MII Control Registers.
  1522. */
  1523. ctrl &= ~E1000_CTRL_FD;
  1524. mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
  1525. DEBUGOUT("Half Duplex\n");
  1526. }
  1527. /* Are we forcing 100Mbps??? */
  1528. if(hw->forced_speed_duplex == e1000_100_full ||
  1529. hw->forced_speed_duplex == e1000_100_half) {
  1530. /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
  1531. ctrl |= E1000_CTRL_SPD_100;
  1532. mii_ctrl_reg |= MII_CR_SPEED_100;
  1533. mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
  1534. DEBUGOUT("Forcing 100mb ");
  1535. } else {
  1536. /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
  1537. ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  1538. mii_ctrl_reg |= MII_CR_SPEED_10;
  1539. mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
  1540. DEBUGOUT("Forcing 10mb ");
  1541. }
  1542. e1000_config_collision_dist(hw);
  1543. /* Write the configured values back to the Device Control Reg. */
  1544. E1000_WRITE_REG(hw, CTRL, ctrl);
  1545. if (hw->phy_type == e1000_phy_m88) {
  1546. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1547. if(ret_val)
  1548. return ret_val;
  1549. /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
  1550. * forced whenever speed are duplex are forced.
  1551. */
  1552. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  1553. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1554. if(ret_val)
  1555. return ret_val;
  1556. DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
  1557. /* Need to reset the PHY or these changes will be ignored */
  1558. mii_ctrl_reg |= MII_CR_RESET;
  1559. } else {
  1560. /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
  1561. * forced whenever speed or duplex are forced.
  1562. */
  1563. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  1564. if(ret_val)
  1565. return ret_val;
  1566. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  1567. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1568. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  1569. if(ret_val)
  1570. return ret_val;
  1571. }
  1572. /* Write back the modified PHY MII control register. */
  1573. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
  1574. if(ret_val)
  1575. return ret_val;
  1576. udelay(1);
  1577. /* The wait_autoneg_complete flag may be a little misleading here.
  1578. * Since we are forcing speed and duplex, Auto-Neg is not enabled.
  1579. * But we do want to delay for a period while forcing only so we
  1580. * don't generate false No Link messages. So we will wait here
  1581. * only if the user has set wait_autoneg_complete to 1, which is
  1582. * the default.
  1583. */
  1584. if(hw->wait_autoneg_complete) {
  1585. /* We will wait for autoneg to complete. */
  1586. DEBUGOUT("Waiting for forced speed/duplex link.\n");
  1587. mii_status_reg = 0;
  1588. /* We will wait for autoneg to complete or 4.5 seconds to expire. */
  1589. for(i = PHY_FORCE_TIME; i > 0; i--) {
  1590. /* Read the MII Status Register and wait for Auto-Neg Complete bit
  1591. * to be set.
  1592. */
  1593. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1594. if(ret_val)
  1595. return ret_val;
  1596. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1597. if(ret_val)
  1598. return ret_val;
  1599. if(mii_status_reg & MII_SR_LINK_STATUS) break;
  1600. msec_delay(100);
  1601. }
  1602. if((i == 0) &&
  1603. (hw->phy_type == e1000_phy_m88)) {
  1604. /* We didn't get link. Reset the DSP and wait again for link. */
  1605. ret_val = e1000_phy_reset_dsp(hw);
  1606. if(ret_val) {
  1607. DEBUGOUT("Error Resetting PHY DSP\n");
  1608. return ret_val;
  1609. }
  1610. }
  1611. /* This loop will early-out if the link condition has been met. */
  1612. for(i = PHY_FORCE_TIME; i > 0; i--) {
  1613. if(mii_status_reg & MII_SR_LINK_STATUS) break;
  1614. msec_delay(100);
  1615. /* Read the MII Status Register and wait for Auto-Neg Complete bit
  1616. * to be set.
  1617. */
  1618. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1619. if(ret_val)
  1620. return ret_val;
  1621. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1622. if(ret_val)
  1623. return ret_val;
  1624. }
  1625. }
  1626. if (hw->phy_type == e1000_phy_m88) {
  1627. /* Because we reset the PHY above, we need to re-force TX_CLK in the
  1628. * Extended PHY Specific Control Register to 25MHz clock. This value
  1629. * defaults back to a 2.5MHz clock when the PHY is reset.
  1630. */
  1631. ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  1632. if(ret_val)
  1633. return ret_val;
  1634. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  1635. ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  1636. if(ret_val)
  1637. return ret_val;
  1638. /* In addition, because of the s/w reset above, we need to enable CRS on
  1639. * TX. This must be set for both full and half duplex operation.
  1640. */
  1641. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1642. if(ret_val)
  1643. return ret_val;
  1644. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  1645. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1646. if(ret_val)
  1647. return ret_val;
  1648. if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
  1649. (!hw->autoneg) &&
  1650. (hw->forced_speed_duplex == e1000_10_full ||
  1651. hw->forced_speed_duplex == e1000_10_half)) {
  1652. ret_val = e1000_polarity_reversal_workaround(hw);
  1653. if(ret_val)
  1654. return ret_val;
  1655. }
  1656. }
  1657. return E1000_SUCCESS;
  1658. }
  1659. /******************************************************************************
  1660. * Sets the collision distance in the Transmit Control register
  1661. *
  1662. * hw - Struct containing variables accessed by shared code
  1663. *
  1664. * Link should have been established previously. Reads the speed and duplex
  1665. * information from the Device Status register.
  1666. ******************************************************************************/
  1667. void
  1668. e1000_config_collision_dist(struct e1000_hw *hw)
  1669. {
  1670. uint32_t tctl;
  1671. DEBUGFUNC("e1000_config_collision_dist");
  1672. tctl = E1000_READ_REG(hw, TCTL);
  1673. tctl &= ~E1000_TCTL_COLD;
  1674. tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
  1675. E1000_WRITE_REG(hw, TCTL, tctl);
  1676. E1000_WRITE_FLUSH(hw);
  1677. }
  1678. /******************************************************************************
  1679. * Sets MAC speed and duplex settings to reflect the those in the PHY
  1680. *
  1681. * hw - Struct containing variables accessed by shared code
  1682. * mii_reg - data to write to the MII control register
  1683. *
  1684. * The contents of the PHY register containing the needed information need to
  1685. * be passed in.
  1686. ******************************************************************************/
  1687. static int32_t
  1688. e1000_config_mac_to_phy(struct e1000_hw *hw)
  1689. {
  1690. uint32_t ctrl;
  1691. int32_t ret_val;
  1692. uint16_t phy_data;
  1693. DEBUGFUNC("e1000_config_mac_to_phy");
  1694. /* 82544 or newer MAC, Auto Speed Detection takes care of
  1695. * MAC speed/duplex configuration.*/
  1696. if (hw->mac_type >= e1000_82544)
  1697. return E1000_SUCCESS;
  1698. /* Read the Device Control Register and set the bits to Force Speed
  1699. * and Duplex.
  1700. */
  1701. ctrl = E1000_READ_REG(hw, CTRL);
  1702. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1703. ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
  1704. /* Set up duplex in the Device Control and Transmit Control
  1705. * registers depending on negotiated values.
  1706. */
  1707. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  1708. if(ret_val)
  1709. return ret_val;
  1710. if(phy_data & M88E1000_PSSR_DPLX)
  1711. ctrl |= E1000_CTRL_FD;
  1712. else
  1713. ctrl &= ~E1000_CTRL_FD;
  1714. e1000_config_collision_dist(hw);
  1715. /* Set up speed in the Device Control register depending on
  1716. * negotiated values.
  1717. */
  1718. if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
  1719. ctrl |= E1000_CTRL_SPD_1000;
  1720. else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
  1721. ctrl |= E1000_CTRL_SPD_100;
  1722. /* Write the configured values back to the Device Control Reg. */
  1723. E1000_WRITE_REG(hw, CTRL, ctrl);
  1724. return E1000_SUCCESS;
  1725. }
  1726. /******************************************************************************
  1727. * Forces the MAC's flow control settings.
  1728. *
  1729. * hw - Struct containing variables accessed by shared code
  1730. *
  1731. * Sets the TFCE and RFCE bits in the device control register to reflect
  1732. * the adapter settings. TFCE and RFCE need to be explicitly set by
  1733. * software when a Copper PHY is used because autonegotiation is managed
  1734. * by the PHY rather than the MAC. Software must also configure these
  1735. * bits when link is forced on a fiber connection.
  1736. *****************************************************************************/
  1737. int32_t
  1738. e1000_force_mac_fc(struct e1000_hw *hw)
  1739. {
  1740. uint32_t ctrl;
  1741. DEBUGFUNC("e1000_force_mac_fc");
  1742. /* Get the current configuration of the Device Control Register */
  1743. ctrl = E1000_READ_REG(hw, CTRL);
  1744. /* Because we didn't get link via the internal auto-negotiation
  1745. * mechanism (we either forced link or we got link via PHY
  1746. * auto-neg), we have to manually enable/disable transmit an
  1747. * receive flow control.
  1748. *
  1749. * The "Case" statement below enables/disable flow control
  1750. * according to the "hw->fc" parameter.
  1751. *
  1752. * The possible values of the "fc" parameter are:
  1753. * 0: Flow control is completely disabled
  1754. * 1: Rx flow control is enabled (we can receive pause
  1755. * frames but not send pause frames).
  1756. * 2: Tx flow control is enabled (we can send pause frames
  1757. * frames but we do not receive pause frames).
  1758. * 3: Both Rx and TX flow control (symmetric) is enabled.
  1759. * other: No other values should be possible at this point.
  1760. */
  1761. switch (hw->fc) {
  1762. case e1000_fc_none:
  1763. ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
  1764. break;
  1765. case e1000_fc_rx_pause:
  1766. ctrl &= (~E1000_CTRL_TFCE);
  1767. ctrl |= E1000_CTRL_RFCE;
  1768. break;
  1769. case e1000_fc_tx_pause:
  1770. ctrl &= (~E1000_CTRL_RFCE);
  1771. ctrl |= E1000_CTRL_TFCE;
  1772. break;
  1773. case e1000_fc_full:
  1774. ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
  1775. break;
  1776. default:
  1777. DEBUGOUT("Flow control param set incorrectly\n");
  1778. return -E1000_ERR_CONFIG;
  1779. }
  1780. /* Disable TX Flow Control for 82542 (rev 2.0) */
  1781. if(hw->mac_type == e1000_82542_rev2_0)
  1782. ctrl &= (~E1000_CTRL_TFCE);
  1783. E1000_WRITE_REG(hw, CTRL, ctrl);
  1784. return E1000_SUCCESS;
  1785. }
  1786. /******************************************************************************
  1787. * Configures flow control settings after link is established
  1788. *
  1789. * hw - Struct containing variables accessed by shared code
  1790. *
  1791. * Should be called immediately after a valid link has been established.
  1792. * Forces MAC flow control settings if link was forced. When in MII/GMII mode
  1793. * and autonegotiation is enabled, the MAC flow control settings will be set
  1794. * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
  1795. * and RFCE bits will be automaticaly set to the negotiated flow control mode.
  1796. *****************************************************************************/
  1797. static int32_t
  1798. e1000_config_fc_after_link_up(struct e1000_hw *hw)
  1799. {
  1800. int32_t ret_val;
  1801. uint16_t mii_status_reg;
  1802. uint16_t mii_nway_adv_reg;
  1803. uint16_t mii_nway_lp_ability_reg;
  1804. uint16_t speed;
  1805. uint16_t duplex;
  1806. DEBUGFUNC("e1000_config_fc_after_link_up");
  1807. /* Check for the case where we have fiber media and auto-neg failed
  1808. * so we had to force link. In this case, we need to force the
  1809. * configuration of the MAC to match the "fc" parameter.
  1810. */
  1811. if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
  1812. ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
  1813. ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
  1814. ret_val = e1000_force_mac_fc(hw);
  1815. if(ret_val) {
  1816. DEBUGOUT("Error forcing flow control settings\n");
  1817. return ret_val;
  1818. }
  1819. }
  1820. /* Check for the case where we have copper media and auto-neg is
  1821. * enabled. In this case, we need to check and see if Auto-Neg
  1822. * has completed, and if so, how the PHY and link partner has
  1823. * flow control configured.
  1824. */
  1825. if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
  1826. /* Read the MII Status Register and check to see if AutoNeg
  1827. * has completed. We read this twice because this reg has
  1828. * some "sticky" (latched) bits.
  1829. */
  1830. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1831. if(ret_val)
  1832. return ret_val;
  1833. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1834. if(ret_val)
  1835. return ret_val;
  1836. if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
  1837. /* The AutoNeg process has completed, so we now need to
  1838. * read both the Auto Negotiation Advertisement Register
  1839. * (Address 4) and the Auto_Negotiation Base Page Ability
  1840. * Register (Address 5) to determine how flow control was
  1841. * negotiated.
  1842. */
  1843. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
  1844. &mii_nway_adv_reg);
  1845. if(ret_val)
  1846. return ret_val;
  1847. ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
  1848. &mii_nway_lp_ability_reg);
  1849. if(ret_val)
  1850. return ret_val;
  1851. /* Two bits in the Auto Negotiation Advertisement Register
  1852. * (Address 4) and two bits in the Auto Negotiation Base
  1853. * Page Ability Register (Address 5) determine flow control
  1854. * for both the PHY and the link partner. The following
  1855. * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
  1856. * 1999, describes these PAUSE resolution bits and how flow
  1857. * control is determined based upon these settings.
  1858. * NOTE: DC = Don't Care
  1859. *
  1860. * LOCAL DEVICE | LINK PARTNER
  1861. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  1862. *-------|---------|-------|---------|--------------------
  1863. * 0 | 0 | DC | DC | e1000_fc_none
  1864. * 0 | 1 | 0 | DC | e1000_fc_none
  1865. * 0 | 1 | 1 | 0 | e1000_fc_none
  1866. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  1867. * 1 | 0 | 0 | DC | e1000_fc_none
  1868. * 1 | DC | 1 | DC | e1000_fc_full
  1869. * 1 | 1 | 0 | 0 | e1000_fc_none
  1870. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  1871. *
  1872. */
  1873. /* Are both PAUSE bits set to 1? If so, this implies
  1874. * Symmetric Flow Control is enabled at both ends. The
  1875. * ASM_DIR bits are irrelevant per the spec.
  1876. *
  1877. * For Symmetric Flow Control:
  1878. *
  1879. * LOCAL DEVICE | LINK PARTNER
  1880. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1881. *-------|---------|-------|---------|--------------------
  1882. * 1 | DC | 1 | DC | e1000_fc_full
  1883. *
  1884. */
  1885. if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1886. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
  1887. /* Now we need to check if the user selected RX ONLY
  1888. * of pause frames. In this case, we had to advertise
  1889. * FULL flow control because we could not advertise RX
  1890. * ONLY. Hence, we must now check to see if we need to
  1891. * turn OFF the TRANSMISSION of PAUSE frames.
  1892. */
  1893. if(hw->original_fc == e1000_fc_full) {
  1894. hw->fc = e1000_fc_full;
  1895. DEBUGOUT("Flow Control = FULL.\r\n");
  1896. } else {
  1897. hw->fc = e1000_fc_rx_pause;
  1898. DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
  1899. }
  1900. }
  1901. /* For receiving PAUSE frames ONLY.
  1902. *
  1903. * LOCAL DEVICE | LINK PARTNER
  1904. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1905. *-------|---------|-------|---------|--------------------
  1906. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  1907. *
  1908. */
  1909. else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1910. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  1911. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  1912. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  1913. hw->fc = e1000_fc_tx_pause;
  1914. DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
  1915. }
  1916. /* For transmitting PAUSE frames ONLY.
  1917. *
  1918. * LOCAL DEVICE | LINK PARTNER
  1919. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1920. *-------|---------|-------|---------|--------------------
  1921. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  1922. *
  1923. */
  1924. else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1925. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  1926. !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  1927. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  1928. hw->fc = e1000_fc_rx_pause;
  1929. DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
  1930. }
  1931. /* Per the IEEE spec, at this point flow control should be
  1932. * disabled. However, we want to consider that we could
  1933. * be connected to a legacy switch that doesn't advertise
  1934. * desired flow control, but can be forced on the link
  1935. * partner. So if we advertised no flow control, that is
  1936. * what we will resolve to. If we advertised some kind of
  1937. * receive capability (Rx Pause Only or Full Flow Control)
  1938. * and the link partner advertised none, we will configure
  1939. * ourselves to enable Rx Flow Control only. We can do
  1940. * this safely for two reasons: If the link partner really
  1941. * didn't want flow control enabled, and we enable Rx, no
  1942. * harm done since we won't be receiving any PAUSE frames
  1943. * anyway. If the intent on the link partner was to have
  1944. * flow control enabled, then by us enabling RX only, we
  1945. * can at least receive pause frames and process them.
  1946. * This is a good idea because in most cases, since we are
  1947. * predominantly a server NIC, more times than not we will
  1948. * be asked to delay transmission of packets than asking
  1949. * our link partner to pause transmission of frames.
  1950. */
  1951. else if((hw->original_fc == e1000_fc_none ||
  1952. hw->original_fc == e1000_fc_tx_pause) ||
  1953. hw->fc_strict_ieee) {
  1954. hw->fc = e1000_fc_none;
  1955. DEBUGOUT("Flow Control = NONE.\r\n");
  1956. } else {
  1957. hw->fc = e1000_fc_rx_pause;
  1958. DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
  1959. }
  1960. /* Now we need to do one last check... If we auto-
  1961. * negotiated to HALF DUPLEX, flow control should not be
  1962. * enabled per IEEE 802.3 spec.
  1963. */
  1964. ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
  1965. if(ret_val) {
  1966. DEBUGOUT("Error getting link speed and duplex\n");
  1967. return ret_val;
  1968. }
  1969. if(duplex == HALF_DUPLEX)
  1970. hw->fc = e1000_fc_none;
  1971. /* Now we call a subroutine to actually force the MAC
  1972. * controller to use the correct flow control settings.
  1973. */
  1974. ret_val = e1000_force_mac_fc(hw);
  1975. if(ret_val) {
  1976. DEBUGOUT("Error forcing flow control settings\n");
  1977. return ret_val;
  1978. }
  1979. } else {
  1980. DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
  1981. }
  1982. }
  1983. return E1000_SUCCESS;
  1984. }
  1985. /******************************************************************************
  1986. * Checks to see if the link status of the hardware has changed.
  1987. *
  1988. * hw - Struct containing variables accessed by shared code
  1989. *
  1990. * Called by any function that needs to check the link status of the adapter.
  1991. *****************************************************************************/
  1992. int32_t
  1993. e1000_check_for_link(struct e1000_hw *hw)
  1994. {
  1995. uint32_t rxcw = 0;
  1996. uint32_t ctrl;
  1997. uint32_t status;
  1998. uint32_t rctl;
  1999. uint32_t icr;
  2000. uint32_t signal = 0;
  2001. int32_t ret_val;
  2002. uint16_t phy_data;
  2003. DEBUGFUNC("e1000_check_for_link");
  2004. ctrl = E1000_READ_REG(hw, CTRL);
  2005. status = E1000_READ_REG(hw, STATUS);
  2006. /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
  2007. * set when the optics detect a signal. On older adapters, it will be
  2008. * cleared when there is a signal. This applies to fiber media only.
  2009. */
  2010. if((hw->media_type == e1000_media_type_fiber) ||
  2011. (hw->media_type == e1000_media_type_internal_serdes)) {
  2012. rxcw = E1000_READ_REG(hw, RXCW);
  2013. if(hw->media_type == e1000_media_type_fiber) {
  2014. signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
  2015. if(status & E1000_STATUS_LU)
  2016. hw->get_link_status = FALSE;
  2017. }
  2018. }
  2019. /* If we have a copper PHY then we only want to go out to the PHY
  2020. * registers to see if Auto-Neg has completed and/or if our link
  2021. * status has changed. The get_link_status flag will be set if we
  2022. * receive a Link Status Change interrupt or we have Rx Sequence
  2023. * Errors.
  2024. */
  2025. if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
  2026. /* First we want to see if the MII Status Register reports
  2027. * link. If so, then we want to get the current speed/duplex
  2028. * of the PHY.
  2029. * Read the register twice since the link bit is sticky.
  2030. */
  2031. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2032. if(ret_val)
  2033. return ret_val;
  2034. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2035. if(ret_val)
  2036. return ret_val;
  2037. if(phy_data & MII_SR_LINK_STATUS) {
  2038. hw->get_link_status = FALSE;
  2039. /* Check if there was DownShift, must be checked immediately after
  2040. * link-up */
  2041. e1000_check_downshift(hw);
  2042. /* If we are on 82544 or 82543 silicon and speed/duplex
  2043. * are forced to 10H or 10F, then we will implement the polarity
  2044. * reversal workaround. We disable interrupts first, and upon
  2045. * returning, place the devices interrupt state to its previous
  2046. * value except for the link status change interrupt which will
  2047. * happen due to the execution of this workaround.
  2048. */
  2049. if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
  2050. (!hw->autoneg) &&
  2051. (hw->forced_speed_duplex == e1000_10_full ||
  2052. hw->forced_speed_duplex == e1000_10_half)) {
  2053. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  2054. ret_val = e1000_polarity_reversal_workaround(hw);
  2055. icr = E1000_READ_REG(hw, ICR);
  2056. E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
  2057. E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
  2058. }
  2059. } else {
  2060. /* No link detected */
  2061. e1000_config_dsp_after_link_change(hw, FALSE);
  2062. return 0;
  2063. }
  2064. /* If we are forcing speed/duplex, then we simply return since
  2065. * we have already determined whether we have link or not.
  2066. */
  2067. if(!hw->autoneg) return -E1000_ERR_CONFIG;
  2068. /* optimize the dsp settings for the igp phy */
  2069. e1000_config_dsp_after_link_change(hw, TRUE);
  2070. /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
  2071. * have Si on board that is 82544 or newer, Auto
  2072. * Speed Detection takes care of MAC speed/duplex
  2073. * configuration. So we only need to configure Collision
  2074. * Distance in the MAC. Otherwise, we need to force
  2075. * speed/duplex on the MAC to the current PHY speed/duplex
  2076. * settings.
  2077. */
  2078. if(hw->mac_type >= e1000_82544)
  2079. e1000_config_collision_dist(hw);
  2080. else {
  2081. ret_val = e1000_config_mac_to_phy(hw);
  2082. if(ret_val) {
  2083. DEBUGOUT("Error configuring MAC to PHY settings\n");
  2084. return ret_val;
  2085. }
  2086. }
  2087. /* Configure Flow Control now that Auto-Neg has completed. First, we
  2088. * need to restore the desired flow control settings because we may
  2089. * have had to re-autoneg with a different link partner.
  2090. */
  2091. ret_val = e1000_config_fc_after_link_up(hw);
  2092. if(ret_val) {
  2093. DEBUGOUT("Error configuring flow control\n");
  2094. return ret_val;
  2095. }
  2096. /* At this point we know that we are on copper and we have
  2097. * auto-negotiated link. These are conditions for checking the link
  2098. * partner capability register. We use the link speed to determine if
  2099. * TBI compatibility needs to be turned on or off. If the link is not
  2100. * at gigabit speed, then TBI compatibility is not needed. If we are
  2101. * at gigabit speed, we turn on TBI compatibility.
  2102. */
  2103. if(hw->tbi_compatibility_en) {
  2104. uint16_t speed, duplex;
  2105. e1000_get_speed_and_duplex(hw, &speed, &duplex);
  2106. if(speed != SPEED_1000) {
  2107. /* If link speed is not set to gigabit speed, we do not need
  2108. * to enable TBI compatibility.
  2109. */
  2110. if(hw->tbi_compatibility_on) {
  2111. /* If we previously were in the mode, turn it off. */
  2112. rctl = E1000_READ_REG(hw, RCTL);
  2113. rctl &= ~E1000_RCTL_SBP;
  2114. E1000_WRITE_REG(hw, RCTL, rctl);
  2115. hw->tbi_compatibility_on = FALSE;
  2116. }
  2117. } else {
  2118. /* If TBI compatibility is was previously off, turn it on. For
  2119. * compatibility with a TBI link partner, we will store bad
  2120. * packets. Some frames have an additional byte on the end and
  2121. * will look like CRC errors to to the hardware.
  2122. */
  2123. if(!hw->tbi_compatibility_on) {
  2124. hw->tbi_compatibility_on = TRUE;
  2125. rctl = E1000_READ_REG(hw, RCTL);
  2126. rctl |= E1000_RCTL_SBP;
  2127. E1000_WRITE_REG(hw, RCTL, rctl);
  2128. }
  2129. }
  2130. }
  2131. }
  2132. /* If we don't have link (auto-negotiation failed or link partner cannot
  2133. * auto-negotiate), the cable is plugged in (we have signal), and our
  2134. * link partner is not trying to auto-negotiate with us (we are receiving
  2135. * idles or data), we need to force link up. We also need to give
  2136. * auto-negotiation time to complete, in case the cable was just plugged
  2137. * in. The autoneg_failed flag does this.
  2138. */
  2139. else if((((hw->media_type == e1000_media_type_fiber) &&
  2140. ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
  2141. (hw->media_type == e1000_media_type_internal_serdes)) &&
  2142. (!(status & E1000_STATUS_LU)) &&
  2143. (!(rxcw & E1000_RXCW_C))) {
  2144. if(hw->autoneg_failed == 0) {
  2145. hw->autoneg_failed = 1;
  2146. return 0;
  2147. }
  2148. DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
  2149. /* Disable auto-negotiation in the TXCW register */
  2150. E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
  2151. /* Force link-up and also force full-duplex. */
  2152. ctrl = E1000_READ_REG(hw, CTRL);
  2153. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  2154. E1000_WRITE_REG(hw, CTRL, ctrl);
  2155. /* Configure Flow Control after forcing link up. */
  2156. ret_val = e1000_config_fc_after_link_up(hw);
  2157. if(ret_val) {
  2158. DEBUGOUT("Error configuring flow control\n");
  2159. return ret_val;
  2160. }
  2161. }
  2162. /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
  2163. * auto-negotiation in the TXCW register and disable forced link in the
  2164. * Device Control register in an attempt to auto-negotiate with our link
  2165. * partner.
  2166. */
  2167. else if(((hw->media_type == e1000_media_type_fiber) ||
  2168. (hw->media_type == e1000_media_type_internal_serdes)) &&
  2169. (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
  2170. DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
  2171. E1000_WRITE_REG(hw, TXCW, hw->txcw);
  2172. E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
  2173. hw->serdes_link_down = FALSE;
  2174. }
  2175. /* If we force link for non-auto-negotiation switch, check link status
  2176. * based on MAC synchronization for internal serdes media type.
  2177. */
  2178. else if((hw->media_type == e1000_media_type_internal_serdes) &&
  2179. !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
  2180. /* SYNCH bit and IV bit are sticky. */
  2181. udelay(10);
  2182. if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
  2183. if(!(rxcw & E1000_RXCW_IV)) {
  2184. hw->serdes_link_down = FALSE;
  2185. DEBUGOUT("SERDES: Link is up.\n");
  2186. }
  2187. } else {
  2188. hw->serdes_link_down = TRUE;
  2189. DEBUGOUT("SERDES: Link is down.\n");
  2190. }
  2191. }
  2192. if((hw->media_type == e1000_media_type_internal_serdes) &&
  2193. (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
  2194. hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
  2195. }
  2196. return E1000_SUCCESS;
  2197. }
  2198. /******************************************************************************
  2199. * Detects the current speed and duplex settings of the hardware.
  2200. *
  2201. * hw - Struct containing variables accessed by shared code
  2202. * speed - Speed of the connection
  2203. * duplex - Duplex setting of the connection
  2204. *****************************************************************************/
  2205. int32_t
  2206. e1000_get_speed_and_duplex(struct e1000_hw *hw,
  2207. uint16_t *speed,
  2208. uint16_t *duplex)
  2209. {
  2210. uint32_t status;
  2211. int32_t ret_val;
  2212. uint16_t phy_data;
  2213. DEBUGFUNC("e1000_get_speed_and_duplex");
  2214. if(hw->mac_type >= e1000_82543) {
  2215. status = E1000_READ_REG(hw, STATUS);
  2216. if(status & E1000_STATUS_SPEED_1000) {
  2217. *speed = SPEED_1000;
  2218. DEBUGOUT("1000 Mbs, ");
  2219. } else if(status & E1000_STATUS_SPEED_100) {
  2220. *speed = SPEED_100;
  2221. DEBUGOUT("100 Mbs, ");
  2222. } else {
  2223. *speed = SPEED_10;
  2224. DEBUGOUT("10 Mbs, ");
  2225. }
  2226. if(status & E1000_STATUS_FD) {
  2227. *duplex = FULL_DUPLEX;
  2228. DEBUGOUT("Full Duplex\r\n");
  2229. } else {
  2230. *duplex = HALF_DUPLEX;
  2231. DEBUGOUT(" Half Duplex\r\n");
  2232. }
  2233. } else {
  2234. DEBUGOUT("1000 Mbs, Full Duplex\r\n");
  2235. *speed = SPEED_1000;
  2236. *duplex = FULL_DUPLEX;
  2237. }
  2238. /* IGP01 PHY may advertise full duplex operation after speed downgrade even
  2239. * if it is operating at half duplex. Here we set the duplex settings to
  2240. * match the duplex in the link partner's capabilities.
  2241. */
  2242. if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
  2243. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
  2244. if(ret_val)
  2245. return ret_val;
  2246. if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
  2247. *duplex = HALF_DUPLEX;
  2248. else {
  2249. ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
  2250. if(ret_val)
  2251. return ret_val;
  2252. if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
  2253. (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
  2254. *duplex = HALF_DUPLEX;
  2255. }
  2256. }
  2257. return E1000_SUCCESS;
  2258. }
  2259. /******************************************************************************
  2260. * Blocks until autoneg completes or times out (~4.5 seconds)
  2261. *
  2262. * hw - Struct containing variables accessed by shared code
  2263. ******************************************************************************/
  2264. static int32_t
  2265. e1000_wait_autoneg(struct e1000_hw *hw)
  2266. {
  2267. int32_t ret_val;
  2268. uint16_t i;
  2269. uint16_t phy_data;
  2270. DEBUGFUNC("e1000_wait_autoneg");
  2271. DEBUGOUT("Waiting for Auto-Neg to complete.\n");
  2272. /* We will wait for autoneg to complete or 4.5 seconds to expire. */
  2273. for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
  2274. /* Read the MII Status Register and wait for Auto-Neg
  2275. * Complete bit to be set.
  2276. */
  2277. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2278. if(ret_val)
  2279. return ret_val;
  2280. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2281. if(ret_val)
  2282. return ret_val;
  2283. if(phy_data & MII_SR_AUTONEG_COMPLETE) {
  2284. return E1000_SUCCESS;
  2285. }
  2286. msec_delay(100);
  2287. }
  2288. return E1000_SUCCESS;
  2289. }
  2290. /******************************************************************************
  2291. * Raises the Management Data Clock
  2292. *
  2293. * hw - Struct containing variables accessed by shared code
  2294. * ctrl - Device control register's current value
  2295. ******************************************************************************/
  2296. static void
  2297. e1000_raise_mdi_clk(struct e1000_hw *hw,
  2298. uint32_t *ctrl)
  2299. {
  2300. /* Raise the clock input to the Management Data Clock (by setting the MDC
  2301. * bit), and then delay 10 microseconds.
  2302. */
  2303. E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
  2304. E1000_WRITE_FLUSH(hw);
  2305. udelay(10);
  2306. }
  2307. /******************************************************************************
  2308. * Lowers the Management Data Clock
  2309. *
  2310. * hw - Struct containing variables accessed by shared code
  2311. * ctrl - Device control register's current value
  2312. ******************************************************************************/
  2313. static void
  2314. e1000_lower_mdi_clk(struct e1000_hw *hw,
  2315. uint32_t *ctrl)
  2316. {
  2317. /* Lower the clock input to the Management Data Clock (by clearing the MDC
  2318. * bit), and then delay 10 microseconds.
  2319. */
  2320. E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
  2321. E1000_WRITE_FLUSH(hw);
  2322. udelay(10);
  2323. }
  2324. /******************************************************************************
  2325. * Shifts data bits out to the PHY
  2326. *
  2327. * hw - Struct containing variables accessed by shared code
  2328. * data - Data to send out to the PHY
  2329. * count - Number of bits to shift out
  2330. *
  2331. * Bits are shifted out in MSB to LSB order.
  2332. ******************************************************************************/
  2333. static void
  2334. e1000_shift_out_mdi_bits(struct e1000_hw *hw,
  2335. uint32_t data,
  2336. uint16_t count)
  2337. {
  2338. uint32_t ctrl;
  2339. uint32_t mask;
  2340. /* We need to shift "count" number of bits out to the PHY. So, the value
  2341. * in the "data" parameter will be shifted out to the PHY one bit at a
  2342. * time. In order to do this, "data" must be broken down into bits.
  2343. */
  2344. mask = 0x01;
  2345. mask <<= (count - 1);
  2346. ctrl = E1000_READ_REG(hw, CTRL);
  2347. /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
  2348. ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
  2349. while(mask) {
  2350. /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
  2351. * then raising and lowering the Management Data Clock. A "0" is
  2352. * shifted out to the PHY by setting the MDIO bit to "0" and then
  2353. * raising and lowering the clock.
  2354. */
  2355. if(data & mask) ctrl |= E1000_CTRL_MDIO;
  2356. else ctrl &= ~E1000_CTRL_MDIO;
  2357. E1000_WRITE_REG(hw, CTRL, ctrl);
  2358. E1000_WRITE_FLUSH(hw);
  2359. udelay(10);
  2360. e1000_raise_mdi_clk(hw, &ctrl);
  2361. e1000_lower_mdi_clk(hw, &ctrl);
  2362. mask = mask >> 1;
  2363. }
  2364. }
  2365. /******************************************************************************
  2366. * Shifts data bits in from the PHY
  2367. *
  2368. * hw - Struct containing variables accessed by shared code
  2369. *
  2370. * Bits are shifted in in MSB to LSB order.
  2371. ******************************************************************************/
  2372. static uint16_t
  2373. e1000_shift_in_mdi_bits(struct e1000_hw *hw)
  2374. {
  2375. uint32_t ctrl;
  2376. uint16_t data = 0;
  2377. uint8_t i;
  2378. /* In order to read a register from the PHY, we need to shift in a total
  2379. * of 18 bits from the PHY. The first two bit (turnaround) times are used
  2380. * to avoid contention on the MDIO pin when a read operation is performed.
  2381. * These two bits are ignored by us and thrown away. Bits are "shifted in"
  2382. * by raising the input to the Management Data Clock (setting the MDC bit),
  2383. * and then reading the value of the MDIO bit.
  2384. */
  2385. ctrl = E1000_READ_REG(hw, CTRL);
  2386. /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
  2387. ctrl &= ~E1000_CTRL_MDIO_DIR;
  2388. ctrl &= ~E1000_CTRL_MDIO;
  2389. E1000_WRITE_REG(hw, CTRL, ctrl);
  2390. E1000_WRITE_FLUSH(hw);
  2391. /* Raise and Lower the clock before reading in the data. This accounts for
  2392. * the turnaround bits. The first clock occurred when we clocked out the
  2393. * last bit of the Register Address.
  2394. */
  2395. e1000_raise_mdi_clk(hw, &ctrl);
  2396. e1000_lower_mdi_clk(hw, &ctrl);
  2397. for(data = 0, i = 0; i < 16; i++) {
  2398. data = data << 1;
  2399. e1000_raise_mdi_clk(hw, &ctrl);
  2400. ctrl = E1000_READ_REG(hw, CTRL);
  2401. /* Check to see if we shifted in a "1". */
  2402. if(ctrl & E1000_CTRL_MDIO) data |= 1;
  2403. e1000_lower_mdi_clk(hw, &ctrl);
  2404. }
  2405. e1000_raise_mdi_clk(hw, &ctrl);
  2406. e1000_lower_mdi_clk(hw, &ctrl);
  2407. return data;
  2408. }
  2409. /*****************************************************************************
  2410. * Reads the value from a PHY register, if the value is on a specific non zero
  2411. * page, sets the page first.
  2412. * hw - Struct containing variables accessed by shared code
  2413. * reg_addr - address of the PHY register to read
  2414. ******************************************************************************/
  2415. int32_t
  2416. e1000_read_phy_reg(struct e1000_hw *hw,
  2417. uint32_t reg_addr,
  2418. uint16_t *phy_data)
  2419. {
  2420. uint32_t ret_val;
  2421. DEBUGFUNC("e1000_read_phy_reg");
  2422. if((hw->phy_type == e1000_phy_igp ||
  2423. hw->phy_type == e1000_phy_igp_2) &&
  2424. (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
  2425. ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
  2426. (uint16_t)reg_addr);
  2427. if(ret_val) {
  2428. return ret_val;
  2429. }
  2430. }
  2431. ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
  2432. phy_data);
  2433. return ret_val;
  2434. }
  2435. int32_t
  2436. e1000_read_phy_reg_ex(struct e1000_hw *hw,
  2437. uint32_t reg_addr,
  2438. uint16_t *phy_data)
  2439. {
  2440. uint32_t i;
  2441. uint32_t mdic = 0;
  2442. const uint32_t phy_addr = 1;
  2443. DEBUGFUNC("e1000_read_phy_reg_ex");
  2444. if(reg_addr > MAX_PHY_REG_ADDRESS) {
  2445. DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
  2446. return -E1000_ERR_PARAM;
  2447. }
  2448. if(hw->mac_type > e1000_82543) {
  2449. /* Set up Op-code, Phy Address, and register address in the MDI
  2450. * Control register. The MAC will take care of interfacing with the
  2451. * PHY to retrieve the desired data.
  2452. */
  2453. mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
  2454. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  2455. (E1000_MDIC_OP_READ));
  2456. E1000_WRITE_REG(hw, MDIC, mdic);
  2457. /* Poll the ready bit to see if the MDI read completed */
  2458. for(i = 0; i < 64; i++) {
  2459. udelay(50);
  2460. mdic = E1000_READ_REG(hw, MDIC);
  2461. if(mdic & E1000_MDIC_READY) break;
  2462. }
  2463. if(!(mdic & E1000_MDIC_READY)) {
  2464. DEBUGOUT("MDI Read did not complete\n");
  2465. return -E1000_ERR_PHY;
  2466. }
  2467. if(mdic & E1000_MDIC_ERROR) {
  2468. DEBUGOUT("MDI Error\n");
  2469. return -E1000_ERR_PHY;
  2470. }
  2471. *phy_data = (uint16_t) mdic;
  2472. } else {
  2473. /* We must first send a preamble through the MDIO pin to signal the
  2474. * beginning of an MII instruction. This is done by sending 32
  2475. * consecutive "1" bits.
  2476. */
  2477. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  2478. /* Now combine the next few fields that are required for a read
  2479. * operation. We use this method instead of calling the
  2480. * e1000_shift_out_mdi_bits routine five different times. The format of
  2481. * a MII read instruction consists of a shift out of 14 bits and is
  2482. * defined as follows:
  2483. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
  2484. * followed by a shift in of 18 bits. This first two bits shifted in
  2485. * are TurnAround bits used to avoid contention on the MDIO pin when a
  2486. * READ operation is performed. These two bits are thrown away
  2487. * followed by a shift in of 16 bits which contains the desired data.
  2488. */
  2489. mdic = ((reg_addr) | (phy_addr << 5) |
  2490. (PHY_OP_READ << 10) | (PHY_SOF << 12));
  2491. e1000_shift_out_mdi_bits(hw, mdic, 14);
  2492. /* Now that we've shifted out the read command to the MII, we need to
  2493. * "shift in" the 16-bit value (18 total bits) of the requested PHY
  2494. * register address.
  2495. */
  2496. *phy_data = e1000_shift_in_mdi_bits(hw);
  2497. }
  2498. return E1000_SUCCESS;
  2499. }
  2500. /******************************************************************************
  2501. * Writes a value to a PHY register
  2502. *
  2503. * hw - Struct containing variables accessed by shared code
  2504. * reg_addr - address of the PHY register to write
  2505. * data - data to write to the PHY
  2506. ******************************************************************************/
  2507. int32_t
  2508. e1000_write_phy_reg(struct e1000_hw *hw,
  2509. uint32_t reg_addr,
  2510. uint16_t phy_data)
  2511. {
  2512. uint32_t ret_val;
  2513. DEBUGFUNC("e1000_write_phy_reg");
  2514. if((hw->phy_type == e1000_phy_igp ||
  2515. hw->phy_type == e1000_phy_igp_2) &&
  2516. (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
  2517. ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
  2518. (uint16_t)reg_addr);
  2519. if(ret_val) {
  2520. return ret_val;
  2521. }
  2522. }
  2523. ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
  2524. phy_data);
  2525. return ret_val;
  2526. }
  2527. int32_t
  2528. e1000_write_phy_reg_ex(struct e1000_hw *hw,
  2529. uint32_t reg_addr,
  2530. uint16_t phy_data)
  2531. {
  2532. uint32_t i;
  2533. uint32_t mdic = 0;
  2534. const uint32_t phy_addr = 1;
  2535. DEBUGFUNC("e1000_write_phy_reg_ex");
  2536. if(reg_addr > MAX_PHY_REG_ADDRESS) {
  2537. DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
  2538. return -E1000_ERR_PARAM;
  2539. }
  2540. if(hw->mac_type > e1000_82543) {
  2541. /* Set up Op-code, Phy Address, register address, and data intended
  2542. * for the PHY register in the MDI Control register. The MAC will take
  2543. * care of interfacing with the PHY to send the desired data.
  2544. */
  2545. mdic = (((uint32_t) phy_data) |
  2546. (reg_addr << E1000_MDIC_REG_SHIFT) |
  2547. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  2548. (E1000_MDIC_OP_WRITE));
  2549. E1000_WRITE_REG(hw, MDIC, mdic);
  2550. /* Poll the ready bit to see if the MDI read completed */
  2551. for(i = 0; i < 640; i++) {
  2552. udelay(5);
  2553. mdic = E1000_READ_REG(hw, MDIC);
  2554. if(mdic & E1000_MDIC_READY) break;
  2555. }
  2556. if(!(mdic & E1000_MDIC_READY)) {
  2557. DEBUGOUT("MDI Write did not complete\n");
  2558. return -E1000_ERR_PHY;
  2559. }
  2560. } else {
  2561. /* We'll need to use the SW defined pins to shift the write command
  2562. * out to the PHY. We first send a preamble to the PHY to signal the
  2563. * beginning of the MII instruction. This is done by sending 32
  2564. * consecutive "1" bits.
  2565. */
  2566. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  2567. /* Now combine the remaining required fields that will indicate a
  2568. * write operation. We use this method instead of calling the
  2569. * e1000_shift_out_mdi_bits routine for each field in the command. The
  2570. * format of a MII write instruction is as follows:
  2571. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
  2572. */
  2573. mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
  2574. (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
  2575. mdic <<= 16;
  2576. mdic |= (uint32_t) phy_data;
  2577. e1000_shift_out_mdi_bits(hw, mdic, 32);
  2578. }
  2579. return E1000_SUCCESS;
  2580. }
  2581. /******************************************************************************
  2582. * Returns the PHY to the power-on reset state
  2583. *
  2584. * hw - Struct containing variables accessed by shared code
  2585. ******************************************************************************/
  2586. int32_t
  2587. e1000_phy_hw_reset(struct e1000_hw *hw)
  2588. {
  2589. uint32_t ctrl, ctrl_ext;
  2590. uint32_t led_ctrl;
  2591. int32_t ret_val;
  2592. DEBUGFUNC("e1000_phy_hw_reset");
  2593. /* In the case of the phy reset being blocked, it's not an error, we
  2594. * simply return success without performing the reset. */
  2595. ret_val = e1000_check_phy_reset_block(hw);
  2596. if (ret_val)
  2597. return E1000_SUCCESS;
  2598. DEBUGOUT("Resetting Phy...\n");
  2599. if(hw->mac_type > e1000_82543) {
  2600. /* Read the device control register and assert the E1000_CTRL_PHY_RST
  2601. * bit. Then, take it out of reset.
  2602. */
  2603. ctrl = E1000_READ_REG(hw, CTRL);
  2604. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
  2605. E1000_WRITE_FLUSH(hw);
  2606. msec_delay(10);
  2607. E1000_WRITE_REG(hw, CTRL, ctrl);
  2608. E1000_WRITE_FLUSH(hw);
  2609. } else {
  2610. /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
  2611. * bit to put the PHY into reset. Then, take it out of reset.
  2612. */
  2613. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  2614. ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
  2615. ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
  2616. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  2617. E1000_WRITE_FLUSH(hw);
  2618. msec_delay(10);
  2619. ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
  2620. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  2621. E1000_WRITE_FLUSH(hw);
  2622. }
  2623. udelay(150);
  2624. if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  2625. /* Configure activity LED after PHY reset */
  2626. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  2627. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  2628. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  2629. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  2630. }
  2631. /* Wait for FW to finish PHY configuration. */
  2632. ret_val = e1000_get_phy_cfg_done(hw);
  2633. return ret_val;
  2634. }
  2635. /******************************************************************************
  2636. * Resets the PHY
  2637. *
  2638. * hw - Struct containing variables accessed by shared code
  2639. *
  2640. * Sets bit 15 of the MII Control regiser
  2641. ******************************************************************************/
  2642. int32_t
  2643. e1000_phy_reset(struct e1000_hw *hw)
  2644. {
  2645. int32_t ret_val;
  2646. uint16_t phy_data;
  2647. DEBUGFUNC("e1000_phy_reset");
  2648. /* In the case of the phy reset being blocked, it's not an error, we
  2649. * simply return success without performing the reset. */
  2650. ret_val = e1000_check_phy_reset_block(hw);
  2651. if (ret_val)
  2652. return E1000_SUCCESS;
  2653. switch (hw->mac_type) {
  2654. case e1000_82541_rev_2:
  2655. case e1000_82571:
  2656. case e1000_82572:
  2657. ret_val = e1000_phy_hw_reset(hw);
  2658. if(ret_val)
  2659. return ret_val;
  2660. break;
  2661. default:
  2662. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
  2663. if(ret_val)
  2664. return ret_val;
  2665. phy_data |= MII_CR_RESET;
  2666. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
  2667. if(ret_val)
  2668. return ret_val;
  2669. udelay(1);
  2670. break;
  2671. }
  2672. if(hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
  2673. e1000_phy_init_script(hw);
  2674. return E1000_SUCCESS;
  2675. }
  2676. /******************************************************************************
  2677. * Probes the expected PHY address for known PHY IDs
  2678. *
  2679. * hw - Struct containing variables accessed by shared code
  2680. ******************************************************************************/
  2681. static int32_t
  2682. e1000_detect_gig_phy(struct e1000_hw *hw)
  2683. {
  2684. int32_t phy_init_status, ret_val;
  2685. uint16_t phy_id_high, phy_id_low;
  2686. boolean_t match = FALSE;
  2687. DEBUGFUNC("e1000_detect_gig_phy");
  2688. /* The 82571 firmware may still be configuring the PHY. In this
  2689. * case, we cannot access the PHY until the configuration is done. So
  2690. * we explicitly set the PHY values. */
  2691. if(hw->mac_type == e1000_82571 ||
  2692. hw->mac_type == e1000_82572) {
  2693. hw->phy_id = IGP01E1000_I_PHY_ID;
  2694. hw->phy_type = e1000_phy_igp_2;
  2695. return E1000_SUCCESS;
  2696. }
  2697. /* Read the PHY ID Registers to identify which PHY is onboard. */
  2698. ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
  2699. if(ret_val)
  2700. return ret_val;
  2701. hw->phy_id = (uint32_t) (phy_id_high << 16);
  2702. udelay(20);
  2703. ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
  2704. if(ret_val)
  2705. return ret_val;
  2706. hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
  2707. hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
  2708. switch(hw->mac_type) {
  2709. case e1000_82543:
  2710. if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
  2711. break;
  2712. case e1000_82544:
  2713. if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
  2714. break;
  2715. case e1000_82540:
  2716. case e1000_82545:
  2717. case e1000_82545_rev_3:
  2718. case e1000_82546:
  2719. case e1000_82546_rev_3:
  2720. if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
  2721. break;
  2722. case e1000_82541:
  2723. case e1000_82541_rev_2:
  2724. case e1000_82547:
  2725. case e1000_82547_rev_2:
  2726. if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
  2727. break;
  2728. case e1000_82573:
  2729. if(hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
  2730. break;
  2731. default:
  2732. DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
  2733. return -E1000_ERR_CONFIG;
  2734. }
  2735. phy_init_status = e1000_set_phy_type(hw);
  2736. if ((match) && (phy_init_status == E1000_SUCCESS)) {
  2737. DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
  2738. return E1000_SUCCESS;
  2739. }
  2740. DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
  2741. return -E1000_ERR_PHY;
  2742. }
  2743. /******************************************************************************
  2744. * Resets the PHY's DSP
  2745. *
  2746. * hw - Struct containing variables accessed by shared code
  2747. ******************************************************************************/
  2748. static int32_t
  2749. e1000_phy_reset_dsp(struct e1000_hw *hw)
  2750. {
  2751. int32_t ret_val;
  2752. DEBUGFUNC("e1000_phy_reset_dsp");
  2753. do {
  2754. ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
  2755. if(ret_val) break;
  2756. ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
  2757. if(ret_val) break;
  2758. ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
  2759. if(ret_val) break;
  2760. ret_val = E1000_SUCCESS;
  2761. } while(0);
  2762. return ret_val;
  2763. }
  2764. /******************************************************************************
  2765. * Get PHY information from various PHY registers for igp PHY only.
  2766. *
  2767. * hw - Struct containing variables accessed by shared code
  2768. * phy_info - PHY information structure
  2769. ******************************************************************************/
  2770. static int32_t
  2771. e1000_phy_igp_get_info(struct e1000_hw *hw,
  2772. struct e1000_phy_info *phy_info)
  2773. {
  2774. int32_t ret_val;
  2775. uint16_t phy_data, polarity, min_length, max_length, average;
  2776. DEBUGFUNC("e1000_phy_igp_get_info");
  2777. /* The downshift status is checked only once, after link is established,
  2778. * and it stored in the hw->speed_downgraded parameter. */
  2779. phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
  2780. /* IGP01E1000 does not need to support it. */
  2781. phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
  2782. /* IGP01E1000 always correct polarity reversal */
  2783. phy_info->polarity_correction = e1000_polarity_reversal_enabled;
  2784. /* Check polarity status */
  2785. ret_val = e1000_check_polarity(hw, &polarity);
  2786. if(ret_val)
  2787. return ret_val;
  2788. phy_info->cable_polarity = polarity;
  2789. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
  2790. if(ret_val)
  2791. return ret_val;
  2792. phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
  2793. IGP01E1000_PSSR_MDIX_SHIFT;
  2794. if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
  2795. IGP01E1000_PSSR_SPEED_1000MBPS) {
  2796. /* Local/Remote Receiver Information are only valid at 1000 Mbps */
  2797. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
  2798. if(ret_val)
  2799. return ret_val;
  2800. phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
  2801. SR_1000T_LOCAL_RX_STATUS_SHIFT;
  2802. phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
  2803. SR_1000T_REMOTE_RX_STATUS_SHIFT;
  2804. /* Get cable length */
  2805. ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
  2806. if(ret_val)
  2807. return ret_val;
  2808. /* Translate to old method */
  2809. average = (max_length + min_length) / 2;
  2810. if(average <= e1000_igp_cable_length_50)
  2811. phy_info->cable_length = e1000_cable_length_50;
  2812. else if(average <= e1000_igp_cable_length_80)
  2813. phy_info->cable_length = e1000_cable_length_50_80;
  2814. else if(average <= e1000_igp_cable_length_110)
  2815. phy_info->cable_length = e1000_cable_length_80_110;
  2816. else if(average <= e1000_igp_cable_length_140)
  2817. phy_info->cable_length = e1000_cable_length_110_140;
  2818. else
  2819. phy_info->cable_length = e1000_cable_length_140;
  2820. }
  2821. return E1000_SUCCESS;
  2822. }
  2823. /******************************************************************************
  2824. * Get PHY information from various PHY registers fot m88 PHY only.
  2825. *
  2826. * hw - Struct containing variables accessed by shared code
  2827. * phy_info - PHY information structure
  2828. ******************************************************************************/
  2829. static int32_t
  2830. e1000_phy_m88_get_info(struct e1000_hw *hw,
  2831. struct e1000_phy_info *phy_info)
  2832. {
  2833. int32_t ret_val;
  2834. uint16_t phy_data, polarity;
  2835. DEBUGFUNC("e1000_phy_m88_get_info");
  2836. /* The downshift status is checked only once, after link is established,
  2837. * and it stored in the hw->speed_downgraded parameter. */
  2838. phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
  2839. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  2840. if(ret_val)
  2841. return ret_val;
  2842. phy_info->extended_10bt_distance =
  2843. (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
  2844. M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
  2845. phy_info->polarity_correction =
  2846. (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
  2847. M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
  2848. /* Check polarity status */
  2849. ret_val = e1000_check_polarity(hw, &polarity);
  2850. if(ret_val)
  2851. return ret_val;
  2852. phy_info->cable_polarity = polarity;
  2853. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  2854. if(ret_val)
  2855. return ret_val;
  2856. phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
  2857. M88E1000_PSSR_MDIX_SHIFT;
  2858. if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
  2859. /* Cable Length Estimation and Local/Remote Receiver Information
  2860. * are only valid at 1000 Mbps.
  2861. */
  2862. phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
  2863. M88E1000_PSSR_CABLE_LENGTH_SHIFT);
  2864. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
  2865. if(ret_val)
  2866. return ret_val;
  2867. phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
  2868. SR_1000T_LOCAL_RX_STATUS_SHIFT;
  2869. phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
  2870. SR_1000T_REMOTE_RX_STATUS_SHIFT;
  2871. }
  2872. return E1000_SUCCESS;
  2873. }
  2874. /******************************************************************************
  2875. * Get PHY information from various PHY registers
  2876. *
  2877. * hw - Struct containing variables accessed by shared code
  2878. * phy_info - PHY information structure
  2879. ******************************************************************************/
  2880. int32_t
  2881. e1000_phy_get_info(struct e1000_hw *hw,
  2882. struct e1000_phy_info *phy_info)
  2883. {
  2884. int32_t ret_val;
  2885. uint16_t phy_data;
  2886. DEBUGFUNC("e1000_phy_get_info");
  2887. phy_info->cable_length = e1000_cable_length_undefined;
  2888. phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
  2889. phy_info->cable_polarity = e1000_rev_polarity_undefined;
  2890. phy_info->downshift = e1000_downshift_undefined;
  2891. phy_info->polarity_correction = e1000_polarity_reversal_undefined;
  2892. phy_info->mdix_mode = e1000_auto_x_mode_undefined;
  2893. phy_info->local_rx = e1000_1000t_rx_status_undefined;
  2894. phy_info->remote_rx = e1000_1000t_rx_status_undefined;
  2895. if(hw->media_type != e1000_media_type_copper) {
  2896. DEBUGOUT("PHY info is only valid for copper media\n");
  2897. return -E1000_ERR_CONFIG;
  2898. }
  2899. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2900. if(ret_val)
  2901. return ret_val;
  2902. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2903. if(ret_val)
  2904. return ret_val;
  2905. if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
  2906. DEBUGOUT("PHY info is only valid if link is up\n");
  2907. return -E1000_ERR_CONFIG;
  2908. }
  2909. if(hw->phy_type == e1000_phy_igp ||
  2910. hw->phy_type == e1000_phy_igp_2)
  2911. return e1000_phy_igp_get_info(hw, phy_info);
  2912. else
  2913. return e1000_phy_m88_get_info(hw, phy_info);
  2914. }
  2915. int32_t
  2916. e1000_validate_mdi_setting(struct e1000_hw *hw)
  2917. {
  2918. DEBUGFUNC("e1000_validate_mdi_settings");
  2919. if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
  2920. DEBUGOUT("Invalid MDI setting detected\n");
  2921. hw->mdix = 1;
  2922. return -E1000_ERR_CONFIG;
  2923. }
  2924. return E1000_SUCCESS;
  2925. }
  2926. /******************************************************************************
  2927. * Sets up eeprom variables in the hw struct. Must be called after mac_type
  2928. * is configured.
  2929. *
  2930. * hw - Struct containing variables accessed by shared code
  2931. *****************************************************************************/
  2932. int32_t
  2933. e1000_init_eeprom_params(struct e1000_hw *hw)
  2934. {
  2935. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  2936. uint32_t eecd = E1000_READ_REG(hw, EECD);
  2937. int32_t ret_val = E1000_SUCCESS;
  2938. uint16_t eeprom_size;
  2939. DEBUGFUNC("e1000_init_eeprom_params");
  2940. switch (hw->mac_type) {
  2941. case e1000_82542_rev2_0:
  2942. case e1000_82542_rev2_1:
  2943. case e1000_82543:
  2944. case e1000_82544:
  2945. eeprom->type = e1000_eeprom_microwire;
  2946. eeprom->word_size = 64;
  2947. eeprom->opcode_bits = 3;
  2948. eeprom->address_bits = 6;
  2949. eeprom->delay_usec = 50;
  2950. eeprom->use_eerd = FALSE;
  2951. eeprom->use_eewr = FALSE;
  2952. break;
  2953. case e1000_82540:
  2954. case e1000_82545:
  2955. case e1000_82545_rev_3:
  2956. case e1000_82546:
  2957. case e1000_82546_rev_3:
  2958. eeprom->type = e1000_eeprom_microwire;
  2959. eeprom->opcode_bits = 3;
  2960. eeprom->delay_usec = 50;
  2961. if(eecd & E1000_EECD_SIZE) {
  2962. eeprom->word_size = 256;
  2963. eeprom->address_bits = 8;
  2964. } else {
  2965. eeprom->word_size = 64;
  2966. eeprom->address_bits = 6;
  2967. }
  2968. eeprom->use_eerd = FALSE;
  2969. eeprom->use_eewr = FALSE;
  2970. break;
  2971. case e1000_82541:
  2972. case e1000_82541_rev_2:
  2973. case e1000_82547:
  2974. case e1000_82547_rev_2:
  2975. if (eecd & E1000_EECD_TYPE) {
  2976. eeprom->type = e1000_eeprom_spi;
  2977. eeprom->opcode_bits = 8;
  2978. eeprom->delay_usec = 1;
  2979. if (eecd & E1000_EECD_ADDR_BITS) {
  2980. eeprom->page_size = 32;
  2981. eeprom->address_bits = 16;
  2982. } else {
  2983. eeprom->page_size = 8;
  2984. eeprom->address_bits = 8;
  2985. }
  2986. } else {
  2987. eeprom->type = e1000_eeprom_microwire;
  2988. eeprom->opcode_bits = 3;
  2989. eeprom->delay_usec = 50;
  2990. if (eecd & E1000_EECD_ADDR_BITS) {
  2991. eeprom->word_size = 256;
  2992. eeprom->address_bits = 8;
  2993. } else {
  2994. eeprom->word_size = 64;
  2995. eeprom->address_bits = 6;
  2996. }
  2997. }
  2998. eeprom->use_eerd = FALSE;
  2999. eeprom->use_eewr = FALSE;
  3000. break;
  3001. case e1000_82571:
  3002. case e1000_82572:
  3003. eeprom->type = e1000_eeprom_spi;
  3004. eeprom->opcode_bits = 8;
  3005. eeprom->delay_usec = 1;
  3006. if (eecd & E1000_EECD_ADDR_BITS) {
  3007. eeprom->page_size = 32;
  3008. eeprom->address_bits = 16;
  3009. } else {
  3010. eeprom->page_size = 8;
  3011. eeprom->address_bits = 8;
  3012. }
  3013. eeprom->use_eerd = FALSE;
  3014. eeprom->use_eewr = FALSE;
  3015. break;
  3016. case e1000_82573:
  3017. eeprom->type = e1000_eeprom_spi;
  3018. eeprom->opcode_bits = 8;
  3019. eeprom->delay_usec = 1;
  3020. if (eecd & E1000_EECD_ADDR_BITS) {
  3021. eeprom->page_size = 32;
  3022. eeprom->address_bits = 16;
  3023. } else {
  3024. eeprom->page_size = 8;
  3025. eeprom->address_bits = 8;
  3026. }
  3027. eeprom->use_eerd = TRUE;
  3028. eeprom->use_eewr = TRUE;
  3029. if(e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
  3030. eeprom->type = e1000_eeprom_flash;
  3031. eeprom->word_size = 2048;
  3032. /* Ensure that the Autonomous FLASH update bit is cleared due to
  3033. * Flash update issue on parts which use a FLASH for NVM. */
  3034. eecd &= ~E1000_EECD_AUPDEN;
  3035. E1000_WRITE_REG(hw, EECD, eecd);
  3036. }
  3037. break;
  3038. default:
  3039. break;
  3040. }
  3041. if (eeprom->type == e1000_eeprom_spi) {
  3042. /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
  3043. * 32KB (incremented by powers of 2).
  3044. */
  3045. if(hw->mac_type <= e1000_82547_rev_2) {
  3046. /* Set to default value for initial eeprom read. */
  3047. eeprom->word_size = 64;
  3048. ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
  3049. if(ret_val)
  3050. return ret_val;
  3051. eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
  3052. /* 256B eeprom size was not supported in earlier hardware, so we
  3053. * bump eeprom_size up one to ensure that "1" (which maps to 256B)
  3054. * is never the result used in the shifting logic below. */
  3055. if(eeprom_size)
  3056. eeprom_size++;
  3057. } else {
  3058. eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
  3059. E1000_EECD_SIZE_EX_SHIFT);
  3060. }
  3061. eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
  3062. }
  3063. return ret_val;
  3064. }
  3065. /******************************************************************************
  3066. * Raises the EEPROM's clock input.
  3067. *
  3068. * hw - Struct containing variables accessed by shared code
  3069. * eecd - EECD's current value
  3070. *****************************************************************************/
  3071. static void
  3072. e1000_raise_ee_clk(struct e1000_hw *hw,
  3073. uint32_t *eecd)
  3074. {
  3075. /* Raise the clock input to the EEPROM (by setting the SK bit), and then
  3076. * wait <delay> microseconds.
  3077. */
  3078. *eecd = *eecd | E1000_EECD_SK;
  3079. E1000_WRITE_REG(hw, EECD, *eecd);
  3080. E1000_WRITE_FLUSH(hw);
  3081. udelay(hw->eeprom.delay_usec);
  3082. }
  3083. /******************************************************************************
  3084. * Lowers the EEPROM's clock input.
  3085. *
  3086. * hw - Struct containing variables accessed by shared code
  3087. * eecd - EECD's current value
  3088. *****************************************************************************/
  3089. static void
  3090. e1000_lower_ee_clk(struct e1000_hw *hw,
  3091. uint32_t *eecd)
  3092. {
  3093. /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
  3094. * wait 50 microseconds.
  3095. */
  3096. *eecd = *eecd & ~E1000_EECD_SK;
  3097. E1000_WRITE_REG(hw, EECD, *eecd);
  3098. E1000_WRITE_FLUSH(hw);
  3099. udelay(hw->eeprom.delay_usec);
  3100. }
  3101. /******************************************************************************
  3102. * Shift data bits out to the EEPROM.
  3103. *
  3104. * hw - Struct containing variables accessed by shared code
  3105. * data - data to send to the EEPROM
  3106. * count - number of bits to shift out
  3107. *****************************************************************************/
  3108. static void
  3109. e1000_shift_out_ee_bits(struct e1000_hw *hw,
  3110. uint16_t data,
  3111. uint16_t count)
  3112. {
  3113. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3114. uint32_t eecd;
  3115. uint32_t mask;
  3116. /* We need to shift "count" bits out to the EEPROM. So, value in the
  3117. * "data" parameter will be shifted out to the EEPROM one bit at a time.
  3118. * In order to do this, "data" must be broken down into bits.
  3119. */
  3120. mask = 0x01 << (count - 1);
  3121. eecd = E1000_READ_REG(hw, EECD);
  3122. if (eeprom->type == e1000_eeprom_microwire) {
  3123. eecd &= ~E1000_EECD_DO;
  3124. } else if (eeprom->type == e1000_eeprom_spi) {
  3125. eecd |= E1000_EECD_DO;
  3126. }
  3127. do {
  3128. /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
  3129. * and then raising and then lowering the clock (the SK bit controls
  3130. * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
  3131. * by setting "DI" to "0" and then raising and then lowering the clock.
  3132. */
  3133. eecd &= ~E1000_EECD_DI;
  3134. if(data & mask)
  3135. eecd |= E1000_EECD_DI;
  3136. E1000_WRITE_REG(hw, EECD, eecd);
  3137. E1000_WRITE_FLUSH(hw);
  3138. udelay(eeprom->delay_usec);
  3139. e1000_raise_ee_clk(hw, &eecd);
  3140. e1000_lower_ee_clk(hw, &eecd);
  3141. mask = mask >> 1;
  3142. } while(mask);
  3143. /* We leave the "DI" bit set to "0" when we leave this routine. */
  3144. eecd &= ~E1000_EECD_DI;
  3145. E1000_WRITE_REG(hw, EECD, eecd);
  3146. }
  3147. /******************************************************************************
  3148. * Shift data bits in from the EEPROM
  3149. *
  3150. * hw - Struct containing variables accessed by shared code
  3151. *****************************************************************************/
  3152. static uint16_t
  3153. e1000_shift_in_ee_bits(struct e1000_hw *hw,
  3154. uint16_t count)
  3155. {
  3156. uint32_t eecd;
  3157. uint32_t i;
  3158. uint16_t data;
  3159. /* In order to read a register from the EEPROM, we need to shift 'count'
  3160. * bits in from the EEPROM. Bits are "shifted in" by raising the clock
  3161. * input to the EEPROM (setting the SK bit), and then reading the value of
  3162. * the "DO" bit. During this "shifting in" process the "DI" bit should
  3163. * always be clear.
  3164. */
  3165. eecd = E1000_READ_REG(hw, EECD);
  3166. eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
  3167. data = 0;
  3168. for(i = 0; i < count; i++) {
  3169. data = data << 1;
  3170. e1000_raise_ee_clk(hw, &eecd);
  3171. eecd = E1000_READ_REG(hw, EECD);
  3172. eecd &= ~(E1000_EECD_DI);
  3173. if(eecd & E1000_EECD_DO)
  3174. data |= 1;
  3175. e1000_lower_ee_clk(hw, &eecd);
  3176. }
  3177. return data;
  3178. }
  3179. /******************************************************************************
  3180. * Prepares EEPROM for access
  3181. *
  3182. * hw - Struct containing variables accessed by shared code
  3183. *
  3184. * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
  3185. * function should be called before issuing a command to the EEPROM.
  3186. *****************************************************************************/
  3187. static int32_t
  3188. e1000_acquire_eeprom(struct e1000_hw *hw)
  3189. {
  3190. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3191. uint32_t eecd, i=0;
  3192. DEBUGFUNC("e1000_acquire_eeprom");
  3193. if(e1000_get_hw_eeprom_semaphore(hw))
  3194. return -E1000_ERR_EEPROM;
  3195. eecd = E1000_READ_REG(hw, EECD);
  3196. if (hw->mac_type != e1000_82573) {
  3197. /* Request EEPROM Access */
  3198. if(hw->mac_type > e1000_82544) {
  3199. eecd |= E1000_EECD_REQ;
  3200. E1000_WRITE_REG(hw, EECD, eecd);
  3201. eecd = E1000_READ_REG(hw, EECD);
  3202. while((!(eecd & E1000_EECD_GNT)) &&
  3203. (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
  3204. i++;
  3205. udelay(5);
  3206. eecd = E1000_READ_REG(hw, EECD);
  3207. }
  3208. if(!(eecd & E1000_EECD_GNT)) {
  3209. eecd &= ~E1000_EECD_REQ;
  3210. E1000_WRITE_REG(hw, EECD, eecd);
  3211. DEBUGOUT("Could not acquire EEPROM grant\n");
  3212. e1000_put_hw_eeprom_semaphore(hw);
  3213. return -E1000_ERR_EEPROM;
  3214. }
  3215. }
  3216. }
  3217. /* Setup EEPROM for Read/Write */
  3218. if (eeprom->type == e1000_eeprom_microwire) {
  3219. /* Clear SK and DI */
  3220. eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
  3221. E1000_WRITE_REG(hw, EECD, eecd);
  3222. /* Set CS */
  3223. eecd |= E1000_EECD_CS;
  3224. E1000_WRITE_REG(hw, EECD, eecd);
  3225. } else if (eeprom->type == e1000_eeprom_spi) {
  3226. /* Clear SK and CS */
  3227. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  3228. E1000_WRITE_REG(hw, EECD, eecd);
  3229. udelay(1);
  3230. }
  3231. return E1000_SUCCESS;
  3232. }
  3233. /******************************************************************************
  3234. * Returns EEPROM to a "standby" state
  3235. *
  3236. * hw - Struct containing variables accessed by shared code
  3237. *****************************************************************************/
  3238. static void
  3239. e1000_standby_eeprom(struct e1000_hw *hw)
  3240. {
  3241. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3242. uint32_t eecd;
  3243. eecd = E1000_READ_REG(hw, EECD);
  3244. if(eeprom->type == e1000_eeprom_microwire) {
  3245. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  3246. E1000_WRITE_REG(hw, EECD, eecd);
  3247. E1000_WRITE_FLUSH(hw);
  3248. udelay(eeprom->delay_usec);
  3249. /* Clock high */
  3250. eecd |= E1000_EECD_SK;
  3251. E1000_WRITE_REG(hw, EECD, eecd);
  3252. E1000_WRITE_FLUSH(hw);
  3253. udelay(eeprom->delay_usec);
  3254. /* Select EEPROM */
  3255. eecd |= E1000_EECD_CS;
  3256. E1000_WRITE_REG(hw, EECD, eecd);
  3257. E1000_WRITE_FLUSH(hw);
  3258. udelay(eeprom->delay_usec);
  3259. /* Clock low */
  3260. eecd &= ~E1000_EECD_SK;
  3261. E1000_WRITE_REG(hw, EECD, eecd);
  3262. E1000_WRITE_FLUSH(hw);
  3263. udelay(eeprom->delay_usec);
  3264. } else if(eeprom->type == e1000_eeprom_spi) {
  3265. /* Toggle CS to flush commands */
  3266. eecd |= E1000_EECD_CS;
  3267. E1000_WRITE_REG(hw, EECD, eecd);
  3268. E1000_WRITE_FLUSH(hw);
  3269. udelay(eeprom->delay_usec);
  3270. eecd &= ~E1000_EECD_CS;
  3271. E1000_WRITE_REG(hw, EECD, eecd);
  3272. E1000_WRITE_FLUSH(hw);
  3273. udelay(eeprom->delay_usec);
  3274. }
  3275. }
  3276. /******************************************************************************
  3277. * Terminates a command by inverting the EEPROM's chip select pin
  3278. *
  3279. * hw - Struct containing variables accessed by shared code
  3280. *****************************************************************************/
  3281. static void
  3282. e1000_release_eeprom(struct e1000_hw *hw)
  3283. {
  3284. uint32_t eecd;
  3285. DEBUGFUNC("e1000_release_eeprom");
  3286. eecd = E1000_READ_REG(hw, EECD);
  3287. if (hw->eeprom.type == e1000_eeprom_spi) {
  3288. eecd |= E1000_EECD_CS; /* Pull CS high */
  3289. eecd &= ~E1000_EECD_SK; /* Lower SCK */
  3290. E1000_WRITE_REG(hw, EECD, eecd);
  3291. udelay(hw->eeprom.delay_usec);
  3292. } else if(hw->eeprom.type == e1000_eeprom_microwire) {
  3293. /* cleanup eeprom */
  3294. /* CS on Microwire is active-high */
  3295. eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
  3296. E1000_WRITE_REG(hw, EECD, eecd);
  3297. /* Rising edge of clock */
  3298. eecd |= E1000_EECD_SK;
  3299. E1000_WRITE_REG(hw, EECD, eecd);
  3300. E1000_WRITE_FLUSH(hw);
  3301. udelay(hw->eeprom.delay_usec);
  3302. /* Falling edge of clock */
  3303. eecd &= ~E1000_EECD_SK;
  3304. E1000_WRITE_REG(hw, EECD, eecd);
  3305. E1000_WRITE_FLUSH(hw);
  3306. udelay(hw->eeprom.delay_usec);
  3307. }
  3308. /* Stop requesting EEPROM access */
  3309. if(hw->mac_type > e1000_82544) {
  3310. eecd &= ~E1000_EECD_REQ;
  3311. E1000_WRITE_REG(hw, EECD, eecd);
  3312. }
  3313. e1000_put_hw_eeprom_semaphore(hw);
  3314. }
  3315. /******************************************************************************
  3316. * Reads a 16 bit word from the EEPROM.
  3317. *
  3318. * hw - Struct containing variables accessed by shared code
  3319. *****************************************************************************/
  3320. int32_t
  3321. e1000_spi_eeprom_ready(struct e1000_hw *hw)
  3322. {
  3323. uint16_t retry_count = 0;
  3324. uint8_t spi_stat_reg;
  3325. DEBUGFUNC("e1000_spi_eeprom_ready");
  3326. /* Read "Status Register" repeatedly until the LSB is cleared. The
  3327. * EEPROM will signal that the command has been completed by clearing
  3328. * bit 0 of the internal status register. If it's not cleared within
  3329. * 5 milliseconds, then error out.
  3330. */
  3331. retry_count = 0;
  3332. do {
  3333. e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
  3334. hw->eeprom.opcode_bits);
  3335. spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
  3336. if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
  3337. break;
  3338. udelay(5);
  3339. retry_count += 5;
  3340. e1000_standby_eeprom(hw);
  3341. } while(retry_count < EEPROM_MAX_RETRY_SPI);
  3342. /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
  3343. * only 0-5mSec on 5V devices)
  3344. */
  3345. if(retry_count >= EEPROM_MAX_RETRY_SPI) {
  3346. DEBUGOUT("SPI EEPROM Status error\n");
  3347. return -E1000_ERR_EEPROM;
  3348. }
  3349. return E1000_SUCCESS;
  3350. }
  3351. /******************************************************************************
  3352. * Reads a 16 bit word from the EEPROM.
  3353. *
  3354. * hw - Struct containing variables accessed by shared code
  3355. * offset - offset of word in the EEPROM to read
  3356. * data - word read from the EEPROM
  3357. * words - number of words to read
  3358. *****************************************************************************/
  3359. int32_t
  3360. e1000_read_eeprom(struct e1000_hw *hw,
  3361. uint16_t offset,
  3362. uint16_t words,
  3363. uint16_t *data)
  3364. {
  3365. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3366. uint32_t i = 0;
  3367. int32_t ret_val;
  3368. DEBUGFUNC("e1000_read_eeprom");
  3369. /* A check for invalid values: offset too large, too many words, and not
  3370. * enough words.
  3371. */
  3372. if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
  3373. (words == 0)) {
  3374. DEBUGOUT("\"words\" parameter out of bounds\n");
  3375. return -E1000_ERR_EEPROM;
  3376. }
  3377. /* FLASH reads without acquiring the semaphore are safe in 82573-based
  3378. * controllers.
  3379. */
  3380. if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
  3381. (hw->mac_type != e1000_82573)) {
  3382. /* Prepare the EEPROM for reading */
  3383. if(e1000_acquire_eeprom(hw) != E1000_SUCCESS)
  3384. return -E1000_ERR_EEPROM;
  3385. }
  3386. if(eeprom->use_eerd == TRUE) {
  3387. ret_val = e1000_read_eeprom_eerd(hw, offset, words, data);
  3388. if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
  3389. (hw->mac_type != e1000_82573))
  3390. e1000_release_eeprom(hw);
  3391. return ret_val;
  3392. }
  3393. if(eeprom->type == e1000_eeprom_spi) {
  3394. uint16_t word_in;
  3395. uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
  3396. if(e1000_spi_eeprom_ready(hw)) {
  3397. e1000_release_eeprom(hw);
  3398. return -E1000_ERR_EEPROM;
  3399. }
  3400. e1000_standby_eeprom(hw);
  3401. /* Some SPI eeproms use the 8th address bit embedded in the opcode */
  3402. if((eeprom->address_bits == 8) && (offset >= 128))
  3403. read_opcode |= EEPROM_A8_OPCODE_SPI;
  3404. /* Send the READ command (opcode + addr) */
  3405. e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
  3406. e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
  3407. /* Read the data. The address of the eeprom internally increments with
  3408. * each byte (spi) being read, saving on the overhead of eeprom setup
  3409. * and tear-down. The address counter will roll over if reading beyond
  3410. * the size of the eeprom, thus allowing the entire memory to be read
  3411. * starting from any offset. */
  3412. for (i = 0; i < words; i++) {
  3413. word_in = e1000_shift_in_ee_bits(hw, 16);
  3414. data[i] = (word_in >> 8) | (word_in << 8);
  3415. }
  3416. } else if(eeprom->type == e1000_eeprom_microwire) {
  3417. for (i = 0; i < words; i++) {
  3418. /* Send the READ command (opcode + addr) */
  3419. e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
  3420. eeprom->opcode_bits);
  3421. e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
  3422. eeprom->address_bits);
  3423. /* Read the data. For microwire, each word requires the overhead
  3424. * of eeprom setup and tear-down. */
  3425. data[i] = e1000_shift_in_ee_bits(hw, 16);
  3426. e1000_standby_eeprom(hw);
  3427. }
  3428. }
  3429. /* End this read operation */
  3430. e1000_release_eeprom(hw);
  3431. return E1000_SUCCESS;
  3432. }
  3433. /******************************************************************************
  3434. * Reads a 16 bit word from the EEPROM using the EERD register.
  3435. *
  3436. * hw - Struct containing variables accessed by shared code
  3437. * offset - offset of word in the EEPROM to read
  3438. * data - word read from the EEPROM
  3439. * words - number of words to read
  3440. *****************************************************************************/
  3441. static int32_t
  3442. e1000_read_eeprom_eerd(struct e1000_hw *hw,
  3443. uint16_t offset,
  3444. uint16_t words,
  3445. uint16_t *data)
  3446. {
  3447. uint32_t i, eerd = 0;
  3448. int32_t error = 0;
  3449. for (i = 0; i < words; i++) {
  3450. eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
  3451. E1000_EEPROM_RW_REG_START;
  3452. E1000_WRITE_REG(hw, EERD, eerd);
  3453. error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
  3454. if(error) {
  3455. break;
  3456. }
  3457. data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
  3458. }
  3459. return error;
  3460. }
  3461. /******************************************************************************
  3462. * Writes a 16 bit word from the EEPROM using the EEWR register.
  3463. *
  3464. * hw - Struct containing variables accessed by shared code
  3465. * offset - offset of word in the EEPROM to read
  3466. * data - word read from the EEPROM
  3467. * words - number of words to read
  3468. *****************************************************************************/
  3469. static int32_t
  3470. e1000_write_eeprom_eewr(struct e1000_hw *hw,
  3471. uint16_t offset,
  3472. uint16_t words,
  3473. uint16_t *data)
  3474. {
  3475. uint32_t register_value = 0;
  3476. uint32_t i = 0;
  3477. int32_t error = 0;
  3478. for (i = 0; i < words; i++) {
  3479. register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
  3480. ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
  3481. E1000_EEPROM_RW_REG_START;
  3482. error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
  3483. if(error) {
  3484. break;
  3485. }
  3486. E1000_WRITE_REG(hw, EEWR, register_value);
  3487. error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
  3488. if(error) {
  3489. break;
  3490. }
  3491. }
  3492. return error;
  3493. }
  3494. /******************************************************************************
  3495. * Polls the status bit (bit 1) of the EERD to determine when the read is done.
  3496. *
  3497. * hw - Struct containing variables accessed by shared code
  3498. *****************************************************************************/
  3499. static int32_t
  3500. e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
  3501. {
  3502. uint32_t attempts = 100000;
  3503. uint32_t i, reg = 0;
  3504. int32_t done = E1000_ERR_EEPROM;
  3505. for(i = 0; i < attempts; i++) {
  3506. if(eerd == E1000_EEPROM_POLL_READ)
  3507. reg = E1000_READ_REG(hw, EERD);
  3508. else
  3509. reg = E1000_READ_REG(hw, EEWR);
  3510. if(reg & E1000_EEPROM_RW_REG_DONE) {
  3511. done = E1000_SUCCESS;
  3512. break;
  3513. }
  3514. udelay(5);
  3515. }
  3516. return done;
  3517. }
  3518. /***************************************************************************
  3519. * Description: Determines if the onboard NVM is FLASH or EEPROM.
  3520. *
  3521. * hw - Struct containing variables accessed by shared code
  3522. ****************************************************************************/
  3523. static boolean_t
  3524. e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
  3525. {
  3526. uint32_t eecd = 0;
  3527. if(hw->mac_type == e1000_82573) {
  3528. eecd = E1000_READ_REG(hw, EECD);
  3529. /* Isolate bits 15 & 16 */
  3530. eecd = ((eecd >> 15) & 0x03);
  3531. /* If both bits are set, device is Flash type */
  3532. if(eecd == 0x03) {
  3533. return FALSE;
  3534. }
  3535. }
  3536. return TRUE;
  3537. }
  3538. /******************************************************************************
  3539. * Verifies that the EEPROM has a valid checksum
  3540. *
  3541. * hw - Struct containing variables accessed by shared code
  3542. *
  3543. * Reads the first 64 16 bit words of the EEPROM and sums the values read.
  3544. * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
  3545. * valid.
  3546. *****************************************************************************/
  3547. int32_t
  3548. e1000_validate_eeprom_checksum(struct e1000_hw *hw)
  3549. {
  3550. uint16_t checksum = 0;
  3551. uint16_t i, eeprom_data;
  3552. DEBUGFUNC("e1000_validate_eeprom_checksum");
  3553. if ((hw->mac_type == e1000_82573) &&
  3554. (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
  3555. /* Check bit 4 of word 10h. If it is 0, firmware is done updating
  3556. * 10h-12h. Checksum may need to be fixed. */
  3557. e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
  3558. if ((eeprom_data & 0x10) == 0) {
  3559. /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
  3560. * has already been fixed. If the checksum is still wrong and this
  3561. * bit is a 1, we need to return bad checksum. Otherwise, we need
  3562. * to set this bit to a 1 and update the checksum. */
  3563. e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
  3564. if ((eeprom_data & 0x8000) == 0) {
  3565. eeprom_data |= 0x8000;
  3566. e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
  3567. e1000_update_eeprom_checksum(hw);
  3568. }
  3569. }
  3570. }
  3571. for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
  3572. if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
  3573. DEBUGOUT("EEPROM Read Error\n");
  3574. return -E1000_ERR_EEPROM;
  3575. }
  3576. checksum += eeprom_data;
  3577. }
  3578. if(checksum == (uint16_t) EEPROM_SUM)
  3579. return E1000_SUCCESS;
  3580. else {
  3581. DEBUGOUT("EEPROM Checksum Invalid\n");
  3582. return -E1000_ERR_EEPROM;
  3583. }
  3584. }
  3585. /******************************************************************************
  3586. * Calculates the EEPROM checksum and writes it to the EEPROM
  3587. *
  3588. * hw - Struct containing variables accessed by shared code
  3589. *
  3590. * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
  3591. * Writes the difference to word offset 63 of the EEPROM.
  3592. *****************************************************************************/
  3593. int32_t
  3594. e1000_update_eeprom_checksum(struct e1000_hw *hw)
  3595. {
  3596. uint16_t checksum = 0;
  3597. uint16_t i, eeprom_data;
  3598. DEBUGFUNC("e1000_update_eeprom_checksum");
  3599. for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
  3600. if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
  3601. DEBUGOUT("EEPROM Read Error\n");
  3602. return -E1000_ERR_EEPROM;
  3603. }
  3604. checksum += eeprom_data;
  3605. }
  3606. checksum = (uint16_t) EEPROM_SUM - checksum;
  3607. if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
  3608. DEBUGOUT("EEPROM Write Error\n");
  3609. return -E1000_ERR_EEPROM;
  3610. } else if (hw->eeprom.type == e1000_eeprom_flash) {
  3611. e1000_commit_shadow_ram(hw);
  3612. }
  3613. return E1000_SUCCESS;
  3614. }
  3615. /******************************************************************************
  3616. * Parent function for writing words to the different EEPROM types.
  3617. *
  3618. * hw - Struct containing variables accessed by shared code
  3619. * offset - offset within the EEPROM to be written to
  3620. * words - number of words to write
  3621. * data - 16 bit word to be written to the EEPROM
  3622. *
  3623. * If e1000_update_eeprom_checksum is not called after this function, the
  3624. * EEPROM will most likely contain an invalid checksum.
  3625. *****************************************************************************/
  3626. int32_t
  3627. e1000_write_eeprom(struct e1000_hw *hw,
  3628. uint16_t offset,
  3629. uint16_t words,
  3630. uint16_t *data)
  3631. {
  3632. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3633. int32_t status = 0;
  3634. DEBUGFUNC("e1000_write_eeprom");
  3635. /* A check for invalid values: offset too large, too many words, and not
  3636. * enough words.
  3637. */
  3638. if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
  3639. (words == 0)) {
  3640. DEBUGOUT("\"words\" parameter out of bounds\n");
  3641. return -E1000_ERR_EEPROM;
  3642. }
  3643. /* 82573 writes only through eewr */
  3644. if(eeprom->use_eewr == TRUE)
  3645. return e1000_write_eeprom_eewr(hw, offset, words, data);
  3646. /* Prepare the EEPROM for writing */
  3647. if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
  3648. return -E1000_ERR_EEPROM;
  3649. if(eeprom->type == e1000_eeprom_microwire) {
  3650. status = e1000_write_eeprom_microwire(hw, offset, words, data);
  3651. } else {
  3652. status = e1000_write_eeprom_spi(hw, offset, words, data);
  3653. msec_delay(10);
  3654. }
  3655. /* Done with writing */
  3656. e1000_release_eeprom(hw);
  3657. return status;
  3658. }
  3659. /******************************************************************************
  3660. * Writes a 16 bit word to a given offset in an SPI EEPROM.
  3661. *
  3662. * hw - Struct containing variables accessed by shared code
  3663. * offset - offset within the EEPROM to be written to
  3664. * words - number of words to write
  3665. * data - pointer to array of 8 bit words to be written to the EEPROM
  3666. *
  3667. *****************************************************************************/
  3668. int32_t
  3669. e1000_write_eeprom_spi(struct e1000_hw *hw,
  3670. uint16_t offset,
  3671. uint16_t words,
  3672. uint16_t *data)
  3673. {
  3674. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3675. uint16_t widx = 0;
  3676. DEBUGFUNC("e1000_write_eeprom_spi");
  3677. while (widx < words) {
  3678. uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
  3679. if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
  3680. e1000_standby_eeprom(hw);
  3681. /* Send the WRITE ENABLE command (8 bit opcode ) */
  3682. e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
  3683. eeprom->opcode_bits);
  3684. e1000_standby_eeprom(hw);
  3685. /* Some SPI eeproms use the 8th address bit embedded in the opcode */
  3686. if((eeprom->address_bits == 8) && (offset >= 128))
  3687. write_opcode |= EEPROM_A8_OPCODE_SPI;
  3688. /* Send the Write command (8-bit opcode + addr) */
  3689. e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
  3690. e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
  3691. eeprom->address_bits);
  3692. /* Send the data */
  3693. /* Loop to allow for up to whole page write (32 bytes) of eeprom */
  3694. while (widx < words) {
  3695. uint16_t word_out = data[widx];
  3696. word_out = (word_out >> 8) | (word_out << 8);
  3697. e1000_shift_out_ee_bits(hw, word_out, 16);
  3698. widx++;
  3699. /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
  3700. * operation, while the smaller eeproms are capable of an 8-byte
  3701. * PAGE WRITE operation. Break the inner loop to pass new address
  3702. */
  3703. if((((offset + widx)*2) % eeprom->page_size) == 0) {
  3704. e1000_standby_eeprom(hw);
  3705. break;
  3706. }
  3707. }
  3708. }
  3709. return E1000_SUCCESS;
  3710. }
  3711. /******************************************************************************
  3712. * Writes a 16 bit word to a given offset in a Microwire EEPROM.
  3713. *
  3714. * hw - Struct containing variables accessed by shared code
  3715. * offset - offset within the EEPROM to be written to
  3716. * words - number of words to write
  3717. * data - pointer to array of 16 bit words to be written to the EEPROM
  3718. *
  3719. *****************************************************************************/
  3720. int32_t
  3721. e1000_write_eeprom_microwire(struct e1000_hw *hw,
  3722. uint16_t offset,
  3723. uint16_t words,
  3724. uint16_t *data)
  3725. {
  3726. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3727. uint32_t eecd;
  3728. uint16_t words_written = 0;
  3729. uint16_t i = 0;
  3730. DEBUGFUNC("e1000_write_eeprom_microwire");
  3731. /* Send the write enable command to the EEPROM (3-bit opcode plus
  3732. * 6/8-bit dummy address beginning with 11). It's less work to include
  3733. * the 11 of the dummy address as part of the opcode than it is to shift
  3734. * it over the correct number of bits for the address. This puts the
  3735. * EEPROM into write/erase mode.
  3736. */
  3737. e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
  3738. (uint16_t)(eeprom->opcode_bits + 2));
  3739. e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
  3740. /* Prepare the EEPROM */
  3741. e1000_standby_eeprom(hw);
  3742. while (words_written < words) {
  3743. /* Send the Write command (3-bit opcode + addr) */
  3744. e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
  3745. eeprom->opcode_bits);
  3746. e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
  3747. eeprom->address_bits);
  3748. /* Send the data */
  3749. e1000_shift_out_ee_bits(hw, data[words_written], 16);
  3750. /* Toggle the CS line. This in effect tells the EEPROM to execute
  3751. * the previous command.
  3752. */
  3753. e1000_standby_eeprom(hw);
  3754. /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
  3755. * signal that the command has been completed by raising the DO signal.
  3756. * If DO does not go high in 10 milliseconds, then error out.
  3757. */
  3758. for(i = 0; i < 200; i++) {
  3759. eecd = E1000_READ_REG(hw, EECD);
  3760. if(eecd & E1000_EECD_DO) break;
  3761. udelay(50);
  3762. }
  3763. if(i == 200) {
  3764. DEBUGOUT("EEPROM Write did not complete\n");
  3765. return -E1000_ERR_EEPROM;
  3766. }
  3767. /* Recover from write */
  3768. e1000_standby_eeprom(hw);
  3769. words_written++;
  3770. }
  3771. /* Send the write disable command to the EEPROM (3-bit opcode plus
  3772. * 6/8-bit dummy address beginning with 10). It's less work to include
  3773. * the 10 of the dummy address as part of the opcode than it is to shift
  3774. * it over the correct number of bits for the address. This takes the
  3775. * EEPROM out of write/erase mode.
  3776. */
  3777. e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
  3778. (uint16_t)(eeprom->opcode_bits + 2));
  3779. e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
  3780. return E1000_SUCCESS;
  3781. }
  3782. /******************************************************************************
  3783. * Flushes the cached eeprom to NVM. This is done by saving the modified values
  3784. * in the eeprom cache and the non modified values in the currently active bank
  3785. * to the new bank.
  3786. *
  3787. * hw - Struct containing variables accessed by shared code
  3788. * offset - offset of word in the EEPROM to read
  3789. * data - word read from the EEPROM
  3790. * words - number of words to read
  3791. *****************************************************************************/
  3792. static int32_t
  3793. e1000_commit_shadow_ram(struct e1000_hw *hw)
  3794. {
  3795. uint32_t attempts = 100000;
  3796. uint32_t eecd = 0;
  3797. uint32_t flop = 0;
  3798. uint32_t i = 0;
  3799. int32_t error = E1000_SUCCESS;
  3800. /* The flop register will be used to determine if flash type is STM */
  3801. flop = E1000_READ_REG(hw, FLOP);
  3802. if (hw->mac_type == e1000_82573) {
  3803. for (i=0; i < attempts; i++) {
  3804. eecd = E1000_READ_REG(hw, EECD);
  3805. if ((eecd & E1000_EECD_FLUPD) == 0) {
  3806. break;
  3807. }
  3808. udelay(5);
  3809. }
  3810. if (i == attempts) {
  3811. return -E1000_ERR_EEPROM;
  3812. }
  3813. /* If STM opcode located in bits 15:8 of flop, reset firmware */
  3814. if ((flop & 0xFF00) == E1000_STM_OPCODE) {
  3815. E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
  3816. }
  3817. /* Perform the flash update */
  3818. E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
  3819. for (i=0; i < attempts; i++) {
  3820. eecd = E1000_READ_REG(hw, EECD);
  3821. if ((eecd & E1000_EECD_FLUPD) == 0) {
  3822. break;
  3823. }
  3824. udelay(5);
  3825. }
  3826. if (i == attempts) {
  3827. return -E1000_ERR_EEPROM;
  3828. }
  3829. }
  3830. return error;
  3831. }
  3832. /******************************************************************************
  3833. * Reads the adapter's part number from the EEPROM
  3834. *
  3835. * hw - Struct containing variables accessed by shared code
  3836. * part_num - Adapter's part number
  3837. *****************************************************************************/
  3838. int32_t
  3839. e1000_read_part_num(struct e1000_hw *hw,
  3840. uint32_t *part_num)
  3841. {
  3842. uint16_t offset = EEPROM_PBA_BYTE_1;
  3843. uint16_t eeprom_data;
  3844. DEBUGFUNC("e1000_read_part_num");
  3845. /* Get word 0 from EEPROM */
  3846. if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
  3847. DEBUGOUT("EEPROM Read Error\n");
  3848. return -E1000_ERR_EEPROM;
  3849. }
  3850. /* Save word 0 in upper half of part_num */
  3851. *part_num = (uint32_t) (eeprom_data << 16);
  3852. /* Get word 1 from EEPROM */
  3853. if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
  3854. DEBUGOUT("EEPROM Read Error\n");
  3855. return -E1000_ERR_EEPROM;
  3856. }
  3857. /* Save word 1 in lower half of part_num */
  3858. *part_num |= eeprom_data;
  3859. return E1000_SUCCESS;
  3860. }
  3861. /******************************************************************************
  3862. * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
  3863. * second function of dual function devices
  3864. *
  3865. * hw - Struct containing variables accessed by shared code
  3866. *****************************************************************************/
  3867. int32_t
  3868. e1000_read_mac_addr(struct e1000_hw * hw)
  3869. {
  3870. uint16_t offset;
  3871. uint16_t eeprom_data, i;
  3872. DEBUGFUNC("e1000_read_mac_addr");
  3873. for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
  3874. offset = i >> 1;
  3875. if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
  3876. DEBUGOUT("EEPROM Read Error\n");
  3877. return -E1000_ERR_EEPROM;
  3878. }
  3879. hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
  3880. hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
  3881. }
  3882. switch (hw->mac_type) {
  3883. default:
  3884. break;
  3885. case e1000_82546:
  3886. case e1000_82546_rev_3:
  3887. case e1000_82571:
  3888. if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
  3889. hw->perm_mac_addr[5] ^= 0x01;
  3890. break;
  3891. }
  3892. for(i = 0; i < NODE_ADDRESS_SIZE; i++)
  3893. hw->mac_addr[i] = hw->perm_mac_addr[i];
  3894. return E1000_SUCCESS;
  3895. }
  3896. /******************************************************************************
  3897. * Initializes receive address filters.
  3898. *
  3899. * hw - Struct containing variables accessed by shared code
  3900. *
  3901. * Places the MAC address in receive address register 0 and clears the rest
  3902. * of the receive addresss registers. Clears the multicast table. Assumes
  3903. * the receiver is in reset when the routine is called.
  3904. *****************************************************************************/
  3905. static void
  3906. e1000_init_rx_addrs(struct e1000_hw *hw)
  3907. {
  3908. uint32_t i;
  3909. uint32_t rar_num;
  3910. DEBUGFUNC("e1000_init_rx_addrs");
  3911. /* Setup the receive address. */
  3912. DEBUGOUT("Programming MAC Address into RAR[0]\n");
  3913. e1000_rar_set(hw, hw->mac_addr, 0);
  3914. rar_num = E1000_RAR_ENTRIES;
  3915. /* Reserve a spot for the Locally Administered Address to work around
  3916. * an 82571 issue in which a reset on one port will reload the MAC on
  3917. * the other port. */
  3918. if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
  3919. rar_num -= 1;
  3920. /* Zero out the other 15 receive addresses. */
  3921. DEBUGOUT("Clearing RAR[1-15]\n");
  3922. for(i = 1; i < rar_num; i++) {
  3923. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
  3924. E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
  3925. }
  3926. }
  3927. #if 0
  3928. /******************************************************************************
  3929. * Updates the MAC's list of multicast addresses.
  3930. *
  3931. * hw - Struct containing variables accessed by shared code
  3932. * mc_addr_list - the list of new multicast addresses
  3933. * mc_addr_count - number of addresses
  3934. * pad - number of bytes between addresses in the list
  3935. * rar_used_count - offset where to start adding mc addresses into the RAR's
  3936. *
  3937. * The given list replaces any existing list. Clears the last 15 receive
  3938. * address registers and the multicast table. Uses receive address registers
  3939. * for the first 15 multicast addresses, and hashes the rest into the
  3940. * multicast table.
  3941. *****************************************************************************/
  3942. void
  3943. e1000_mc_addr_list_update(struct e1000_hw *hw,
  3944. uint8_t *mc_addr_list,
  3945. uint32_t mc_addr_count,
  3946. uint32_t pad,
  3947. uint32_t rar_used_count)
  3948. {
  3949. uint32_t hash_value;
  3950. uint32_t i;
  3951. uint32_t num_rar_entry;
  3952. uint32_t num_mta_entry;
  3953. DEBUGFUNC("e1000_mc_addr_list_update");
  3954. /* Set the new number of MC addresses that we are being requested to use. */
  3955. hw->num_mc_addrs = mc_addr_count;
  3956. /* Clear RAR[1-15] */
  3957. DEBUGOUT(" Clearing RAR[1-15]\n");
  3958. num_rar_entry = E1000_RAR_ENTRIES;
  3959. /* Reserve a spot for the Locally Administered Address to work around
  3960. * an 82571 issue in which a reset on one port will reload the MAC on
  3961. * the other port. */
  3962. if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
  3963. num_rar_entry -= 1;
  3964. for(i = rar_used_count; i < num_rar_entry; i++) {
  3965. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
  3966. E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
  3967. }
  3968. /* Clear the MTA */
  3969. DEBUGOUT(" Clearing MTA\n");
  3970. num_mta_entry = E1000_NUM_MTA_REGISTERS;
  3971. for(i = 0; i < num_mta_entry; i++) {
  3972. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  3973. }
  3974. /* Add the new addresses */
  3975. for(i = 0; i < mc_addr_count; i++) {
  3976. DEBUGOUT(" Adding the multicast addresses:\n");
  3977. DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
  3978. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
  3979. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
  3980. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
  3981. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
  3982. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
  3983. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
  3984. hash_value = e1000_hash_mc_addr(hw,
  3985. mc_addr_list +
  3986. (i * (ETH_LENGTH_OF_ADDRESS + pad)));
  3987. DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
  3988. /* Place this multicast address in the RAR if there is room, *
  3989. * else put it in the MTA
  3990. */
  3991. if (rar_used_count < num_rar_entry) {
  3992. e1000_rar_set(hw,
  3993. mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
  3994. rar_used_count);
  3995. rar_used_count++;
  3996. } else {
  3997. e1000_mta_set(hw, hash_value);
  3998. }
  3999. }
  4000. DEBUGOUT("MC Update Complete\n");
  4001. }
  4002. #endif /* 0 */
  4003. /******************************************************************************
  4004. * Hashes an address to determine its location in the multicast table
  4005. *
  4006. * hw - Struct containing variables accessed by shared code
  4007. * mc_addr - the multicast address to hash
  4008. *****************************************************************************/
  4009. uint32_t
  4010. e1000_hash_mc_addr(struct e1000_hw *hw,
  4011. uint8_t *mc_addr)
  4012. {
  4013. uint32_t hash_value = 0;
  4014. /* The portion of the address that is used for the hash table is
  4015. * determined by the mc_filter_type setting.
  4016. */
  4017. switch (hw->mc_filter_type) {
  4018. /* [0] [1] [2] [3] [4] [5]
  4019. * 01 AA 00 12 34 56
  4020. * LSB MSB
  4021. */
  4022. case 0:
  4023. /* [47:36] i.e. 0x563 for above example address */
  4024. hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
  4025. break;
  4026. case 1:
  4027. /* [46:35] i.e. 0xAC6 for above example address */
  4028. hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
  4029. break;
  4030. case 2:
  4031. /* [45:34] i.e. 0x5D8 for above example address */
  4032. hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
  4033. break;
  4034. case 3:
  4035. /* [43:32] i.e. 0x634 for above example address */
  4036. hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
  4037. break;
  4038. }
  4039. hash_value &= 0xFFF;
  4040. return hash_value;
  4041. }
  4042. /******************************************************************************
  4043. * Sets the bit in the multicast table corresponding to the hash value.
  4044. *
  4045. * hw - Struct containing variables accessed by shared code
  4046. * hash_value - Multicast address hash value
  4047. *****************************************************************************/
  4048. void
  4049. e1000_mta_set(struct e1000_hw *hw,
  4050. uint32_t hash_value)
  4051. {
  4052. uint32_t hash_bit, hash_reg;
  4053. uint32_t mta;
  4054. uint32_t temp;
  4055. /* The MTA is a register array of 128 32-bit registers.
  4056. * It is treated like an array of 4096 bits. We want to set
  4057. * bit BitArray[hash_value]. So we figure out what register
  4058. * the bit is in, read it, OR in the new bit, then write
  4059. * back the new value. The register is determined by the
  4060. * upper 7 bits of the hash value and the bit within that
  4061. * register are determined by the lower 5 bits of the value.
  4062. */
  4063. hash_reg = (hash_value >> 5) & 0x7F;
  4064. hash_bit = hash_value & 0x1F;
  4065. mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
  4066. mta |= (1 << hash_bit);
  4067. /* If we are on an 82544 and we are trying to write an odd offset
  4068. * in the MTA, save off the previous entry before writing and
  4069. * restore the old value after writing.
  4070. */
  4071. if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
  4072. temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
  4073. E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
  4074. E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
  4075. } else {
  4076. E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
  4077. }
  4078. }
  4079. /******************************************************************************
  4080. * Puts an ethernet address into a receive address register.
  4081. *
  4082. * hw - Struct containing variables accessed by shared code
  4083. * addr - Address to put into receive address register
  4084. * index - Receive address register to write
  4085. *****************************************************************************/
  4086. void
  4087. e1000_rar_set(struct e1000_hw *hw,
  4088. uint8_t *addr,
  4089. uint32_t index)
  4090. {
  4091. uint32_t rar_low, rar_high;
  4092. /* HW expects these in little endian so we reverse the byte order
  4093. * from network order (big endian) to little endian
  4094. */
  4095. rar_low = ((uint32_t) addr[0] |
  4096. ((uint32_t) addr[1] << 8) |
  4097. ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
  4098. rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8) | E1000_RAH_AV);
  4099. E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
  4100. E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
  4101. }
  4102. /******************************************************************************
  4103. * Writes a value to the specified offset in the VLAN filter table.
  4104. *
  4105. * hw - Struct containing variables accessed by shared code
  4106. * offset - Offset in VLAN filer table to write
  4107. * value - Value to write into VLAN filter table
  4108. *****************************************************************************/
  4109. void
  4110. e1000_write_vfta(struct e1000_hw *hw,
  4111. uint32_t offset,
  4112. uint32_t value)
  4113. {
  4114. uint32_t temp;
  4115. if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
  4116. temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
  4117. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
  4118. E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
  4119. } else {
  4120. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
  4121. }
  4122. }
  4123. /******************************************************************************
  4124. * Clears the VLAN filer table
  4125. *
  4126. * hw - Struct containing variables accessed by shared code
  4127. *****************************************************************************/
  4128. static void
  4129. e1000_clear_vfta(struct e1000_hw *hw)
  4130. {
  4131. uint32_t offset;
  4132. uint32_t vfta_value = 0;
  4133. uint32_t vfta_offset = 0;
  4134. uint32_t vfta_bit_in_reg = 0;
  4135. if (hw->mac_type == e1000_82573) {
  4136. if (hw->mng_cookie.vlan_id != 0) {
  4137. /* The VFTA is a 4096b bit-field, each identifying a single VLAN
  4138. * ID. The following operations determine which 32b entry
  4139. * (i.e. offset) into the array we want to set the VLAN ID
  4140. * (i.e. bit) of the manageability unit. */
  4141. vfta_offset = (hw->mng_cookie.vlan_id >>
  4142. E1000_VFTA_ENTRY_SHIFT) &
  4143. E1000_VFTA_ENTRY_MASK;
  4144. vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
  4145. E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
  4146. }
  4147. }
  4148. for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
  4149. /* If the offset we want to clear is the same offset of the
  4150. * manageability VLAN ID, then clear all bits except that of the
  4151. * manageability unit */
  4152. vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
  4153. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
  4154. }
  4155. }
  4156. static int32_t
  4157. e1000_id_led_init(struct e1000_hw * hw)
  4158. {
  4159. uint32_t ledctl;
  4160. const uint32_t ledctl_mask = 0x000000FF;
  4161. const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
  4162. const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
  4163. uint16_t eeprom_data, i, temp;
  4164. const uint16_t led_mask = 0x0F;
  4165. DEBUGFUNC("e1000_id_led_init");
  4166. if(hw->mac_type < e1000_82540) {
  4167. /* Nothing to do */
  4168. return E1000_SUCCESS;
  4169. }
  4170. ledctl = E1000_READ_REG(hw, LEDCTL);
  4171. hw->ledctl_default = ledctl;
  4172. hw->ledctl_mode1 = hw->ledctl_default;
  4173. hw->ledctl_mode2 = hw->ledctl_default;
  4174. if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
  4175. DEBUGOUT("EEPROM Read Error\n");
  4176. return -E1000_ERR_EEPROM;
  4177. }
  4178. if((eeprom_data== ID_LED_RESERVED_0000) ||
  4179. (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
  4180. for(i = 0; i < 4; i++) {
  4181. temp = (eeprom_data >> (i << 2)) & led_mask;
  4182. switch(temp) {
  4183. case ID_LED_ON1_DEF2:
  4184. case ID_LED_ON1_ON2:
  4185. case ID_LED_ON1_OFF2:
  4186. hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  4187. hw->ledctl_mode1 |= ledctl_on << (i << 3);
  4188. break;
  4189. case ID_LED_OFF1_DEF2:
  4190. case ID_LED_OFF1_ON2:
  4191. case ID_LED_OFF1_OFF2:
  4192. hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  4193. hw->ledctl_mode1 |= ledctl_off << (i << 3);
  4194. break;
  4195. default:
  4196. /* Do nothing */
  4197. break;
  4198. }
  4199. switch(temp) {
  4200. case ID_LED_DEF1_ON2:
  4201. case ID_LED_ON1_ON2:
  4202. case ID_LED_OFF1_ON2:
  4203. hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  4204. hw->ledctl_mode2 |= ledctl_on << (i << 3);
  4205. break;
  4206. case ID_LED_DEF1_OFF2:
  4207. case ID_LED_ON1_OFF2:
  4208. case ID_LED_OFF1_OFF2:
  4209. hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  4210. hw->ledctl_mode2 |= ledctl_off << (i << 3);
  4211. break;
  4212. default:
  4213. /* Do nothing */
  4214. break;
  4215. }
  4216. }
  4217. return E1000_SUCCESS;
  4218. }
  4219. /******************************************************************************
  4220. * Prepares SW controlable LED for use and saves the current state of the LED.
  4221. *
  4222. * hw - Struct containing variables accessed by shared code
  4223. *****************************************************************************/
  4224. int32_t
  4225. e1000_setup_led(struct e1000_hw *hw)
  4226. {
  4227. uint32_t ledctl;
  4228. int32_t ret_val = E1000_SUCCESS;
  4229. DEBUGFUNC("e1000_setup_led");
  4230. switch(hw->mac_type) {
  4231. case e1000_82542_rev2_0:
  4232. case e1000_82542_rev2_1:
  4233. case e1000_82543:
  4234. case e1000_82544:
  4235. /* No setup necessary */
  4236. break;
  4237. case e1000_82541:
  4238. case e1000_82547:
  4239. case e1000_82541_rev_2:
  4240. case e1000_82547_rev_2:
  4241. /* Turn off PHY Smart Power Down (if enabled) */
  4242. ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
  4243. &hw->phy_spd_default);
  4244. if(ret_val)
  4245. return ret_val;
  4246. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
  4247. (uint16_t)(hw->phy_spd_default &
  4248. ~IGP01E1000_GMII_SPD));
  4249. if(ret_val)
  4250. return ret_val;
  4251. /* Fall Through */
  4252. default:
  4253. if(hw->media_type == e1000_media_type_fiber) {
  4254. ledctl = E1000_READ_REG(hw, LEDCTL);
  4255. /* Save current LEDCTL settings */
  4256. hw->ledctl_default = ledctl;
  4257. /* Turn off LED0 */
  4258. ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
  4259. E1000_LEDCTL_LED0_BLINK |
  4260. E1000_LEDCTL_LED0_MODE_MASK);
  4261. ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
  4262. E1000_LEDCTL_LED0_MODE_SHIFT);
  4263. E1000_WRITE_REG(hw, LEDCTL, ledctl);
  4264. } else if(hw->media_type == e1000_media_type_copper)
  4265. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
  4266. break;
  4267. }
  4268. return E1000_SUCCESS;
  4269. }
  4270. /******************************************************************************
  4271. * Restores the saved state of the SW controlable LED.
  4272. *
  4273. * hw - Struct containing variables accessed by shared code
  4274. *****************************************************************************/
  4275. int32_t
  4276. e1000_cleanup_led(struct e1000_hw *hw)
  4277. {
  4278. int32_t ret_val = E1000_SUCCESS;
  4279. DEBUGFUNC("e1000_cleanup_led");
  4280. switch(hw->mac_type) {
  4281. case e1000_82542_rev2_0:
  4282. case e1000_82542_rev2_1:
  4283. case e1000_82543:
  4284. case e1000_82544:
  4285. /* No cleanup necessary */
  4286. break;
  4287. case e1000_82541:
  4288. case e1000_82547:
  4289. case e1000_82541_rev_2:
  4290. case e1000_82547_rev_2:
  4291. /* Turn on PHY Smart Power Down (if previously enabled) */
  4292. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
  4293. hw->phy_spd_default);
  4294. if(ret_val)
  4295. return ret_val;
  4296. /* Fall Through */
  4297. default:
  4298. /* Restore LEDCTL settings */
  4299. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
  4300. break;
  4301. }
  4302. return E1000_SUCCESS;
  4303. }
  4304. /******************************************************************************
  4305. * Turns on the software controllable LED
  4306. *
  4307. * hw - Struct containing variables accessed by shared code
  4308. *****************************************************************************/
  4309. int32_t
  4310. e1000_led_on(struct e1000_hw *hw)
  4311. {
  4312. uint32_t ctrl = E1000_READ_REG(hw, CTRL);
  4313. DEBUGFUNC("e1000_led_on");
  4314. switch(hw->mac_type) {
  4315. case e1000_82542_rev2_0:
  4316. case e1000_82542_rev2_1:
  4317. case e1000_82543:
  4318. /* Set SW Defineable Pin 0 to turn on the LED */
  4319. ctrl |= E1000_CTRL_SWDPIN0;
  4320. ctrl |= E1000_CTRL_SWDPIO0;
  4321. break;
  4322. case e1000_82544:
  4323. if(hw->media_type == e1000_media_type_fiber) {
  4324. /* Set SW Defineable Pin 0 to turn on the LED */
  4325. ctrl |= E1000_CTRL_SWDPIN0;
  4326. ctrl |= E1000_CTRL_SWDPIO0;
  4327. } else {
  4328. /* Clear SW Defineable Pin 0 to turn on the LED */
  4329. ctrl &= ~E1000_CTRL_SWDPIN0;
  4330. ctrl |= E1000_CTRL_SWDPIO0;
  4331. }
  4332. break;
  4333. default:
  4334. if(hw->media_type == e1000_media_type_fiber) {
  4335. /* Clear SW Defineable Pin 0 to turn on the LED */
  4336. ctrl &= ~E1000_CTRL_SWDPIN0;
  4337. ctrl |= E1000_CTRL_SWDPIO0;
  4338. } else if(hw->media_type == e1000_media_type_copper) {
  4339. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
  4340. return E1000_SUCCESS;
  4341. }
  4342. break;
  4343. }
  4344. E1000_WRITE_REG(hw, CTRL, ctrl);
  4345. return E1000_SUCCESS;
  4346. }
  4347. /******************************************************************************
  4348. * Turns off the software controllable LED
  4349. *
  4350. * hw - Struct containing variables accessed by shared code
  4351. *****************************************************************************/
  4352. int32_t
  4353. e1000_led_off(struct e1000_hw *hw)
  4354. {
  4355. uint32_t ctrl = E1000_READ_REG(hw, CTRL);
  4356. DEBUGFUNC("e1000_led_off");
  4357. switch(hw->mac_type) {
  4358. case e1000_82542_rev2_0:
  4359. case e1000_82542_rev2_1:
  4360. case e1000_82543:
  4361. /* Clear SW Defineable Pin 0 to turn off the LED */
  4362. ctrl &= ~E1000_CTRL_SWDPIN0;
  4363. ctrl |= E1000_CTRL_SWDPIO0;
  4364. break;
  4365. case e1000_82544:
  4366. if(hw->media_type == e1000_media_type_fiber) {
  4367. /* Clear SW Defineable Pin 0 to turn off the LED */
  4368. ctrl &= ~E1000_CTRL_SWDPIN0;
  4369. ctrl |= E1000_CTRL_SWDPIO0;
  4370. } else {
  4371. /* Set SW Defineable Pin 0 to turn off the LED */
  4372. ctrl |= E1000_CTRL_SWDPIN0;
  4373. ctrl |= E1000_CTRL_SWDPIO0;
  4374. }
  4375. break;
  4376. default:
  4377. if(hw->media_type == e1000_media_type_fiber) {
  4378. /* Set SW Defineable Pin 0 to turn off the LED */
  4379. ctrl |= E1000_CTRL_SWDPIN0;
  4380. ctrl |= E1000_CTRL_SWDPIO0;
  4381. } else if(hw->media_type == e1000_media_type_copper) {
  4382. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
  4383. return E1000_SUCCESS;
  4384. }
  4385. break;
  4386. }
  4387. E1000_WRITE_REG(hw, CTRL, ctrl);
  4388. return E1000_SUCCESS;
  4389. }
  4390. /******************************************************************************
  4391. * Clears all hardware statistics counters.
  4392. *
  4393. * hw - Struct containing variables accessed by shared code
  4394. *****************************************************************************/
  4395. static void
  4396. e1000_clear_hw_cntrs(struct e1000_hw *hw)
  4397. {
  4398. volatile uint32_t temp;
  4399. temp = E1000_READ_REG(hw, CRCERRS);
  4400. temp = E1000_READ_REG(hw, SYMERRS);
  4401. temp = E1000_READ_REG(hw, MPC);
  4402. temp = E1000_READ_REG(hw, SCC);
  4403. temp = E1000_READ_REG(hw, ECOL);
  4404. temp = E1000_READ_REG(hw, MCC);
  4405. temp = E1000_READ_REG(hw, LATECOL);
  4406. temp = E1000_READ_REG(hw, COLC);
  4407. temp = E1000_READ_REG(hw, DC);
  4408. temp = E1000_READ_REG(hw, SEC);
  4409. temp = E1000_READ_REG(hw, RLEC);
  4410. temp = E1000_READ_REG(hw, XONRXC);
  4411. temp = E1000_READ_REG(hw, XONTXC);
  4412. temp = E1000_READ_REG(hw, XOFFRXC);
  4413. temp = E1000_READ_REG(hw, XOFFTXC);
  4414. temp = E1000_READ_REG(hw, FCRUC);
  4415. temp = E1000_READ_REG(hw, PRC64);
  4416. temp = E1000_READ_REG(hw, PRC127);
  4417. temp = E1000_READ_REG(hw, PRC255);
  4418. temp = E1000_READ_REG(hw, PRC511);
  4419. temp = E1000_READ_REG(hw, PRC1023);
  4420. temp = E1000_READ_REG(hw, PRC1522);
  4421. temp = E1000_READ_REG(hw, GPRC);
  4422. temp = E1000_READ_REG(hw, BPRC);
  4423. temp = E1000_READ_REG(hw, MPRC);
  4424. temp = E1000_READ_REG(hw, GPTC);
  4425. temp = E1000_READ_REG(hw, GORCL);
  4426. temp = E1000_READ_REG(hw, GORCH);
  4427. temp = E1000_READ_REG(hw, GOTCL);
  4428. temp = E1000_READ_REG(hw, GOTCH);
  4429. temp = E1000_READ_REG(hw, RNBC);
  4430. temp = E1000_READ_REG(hw, RUC);
  4431. temp = E1000_READ_REG(hw, RFC);
  4432. temp = E1000_READ_REG(hw, ROC);
  4433. temp = E1000_READ_REG(hw, RJC);
  4434. temp = E1000_READ_REG(hw, TORL);
  4435. temp = E1000_READ_REG(hw, TORH);
  4436. temp = E1000_READ_REG(hw, TOTL);
  4437. temp = E1000_READ_REG(hw, TOTH);
  4438. temp = E1000_READ_REG(hw, TPR);
  4439. temp = E1000_READ_REG(hw, TPT);
  4440. temp = E1000_READ_REG(hw, PTC64);
  4441. temp = E1000_READ_REG(hw, PTC127);
  4442. temp = E1000_READ_REG(hw, PTC255);
  4443. temp = E1000_READ_REG(hw, PTC511);
  4444. temp = E1000_READ_REG(hw, PTC1023);
  4445. temp = E1000_READ_REG(hw, PTC1522);
  4446. temp = E1000_READ_REG(hw, MPTC);
  4447. temp = E1000_READ_REG(hw, BPTC);
  4448. if(hw->mac_type < e1000_82543) return;
  4449. temp = E1000_READ_REG(hw, ALGNERRC);
  4450. temp = E1000_READ_REG(hw, RXERRC);
  4451. temp = E1000_READ_REG(hw, TNCRS);
  4452. temp = E1000_READ_REG(hw, CEXTERR);
  4453. temp = E1000_READ_REG(hw, TSCTC);
  4454. temp = E1000_READ_REG(hw, TSCTFC);
  4455. if(hw->mac_type <= e1000_82544) return;
  4456. temp = E1000_READ_REG(hw, MGTPRC);
  4457. temp = E1000_READ_REG(hw, MGTPDC);
  4458. temp = E1000_READ_REG(hw, MGTPTC);
  4459. if(hw->mac_type <= e1000_82547_rev_2) return;
  4460. temp = E1000_READ_REG(hw, IAC);
  4461. temp = E1000_READ_REG(hw, ICRXOC);
  4462. temp = E1000_READ_REG(hw, ICRXPTC);
  4463. temp = E1000_READ_REG(hw, ICRXATC);
  4464. temp = E1000_READ_REG(hw, ICTXPTC);
  4465. temp = E1000_READ_REG(hw, ICTXATC);
  4466. temp = E1000_READ_REG(hw, ICTXQEC);
  4467. temp = E1000_READ_REG(hw, ICTXQMTC);
  4468. temp = E1000_READ_REG(hw, ICRXDMTC);
  4469. }
  4470. /******************************************************************************
  4471. * Resets Adaptive IFS to its default state.
  4472. *
  4473. * hw - Struct containing variables accessed by shared code
  4474. *
  4475. * Call this after e1000_init_hw. You may override the IFS defaults by setting
  4476. * hw->ifs_params_forced to TRUE. However, you must initialize hw->
  4477. * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
  4478. * before calling this function.
  4479. *****************************************************************************/
  4480. void
  4481. e1000_reset_adaptive(struct e1000_hw *hw)
  4482. {
  4483. DEBUGFUNC("e1000_reset_adaptive");
  4484. if(hw->adaptive_ifs) {
  4485. if(!hw->ifs_params_forced) {
  4486. hw->current_ifs_val = 0;
  4487. hw->ifs_min_val = IFS_MIN;
  4488. hw->ifs_max_val = IFS_MAX;
  4489. hw->ifs_step_size = IFS_STEP;
  4490. hw->ifs_ratio = IFS_RATIO;
  4491. }
  4492. hw->in_ifs_mode = FALSE;
  4493. E1000_WRITE_REG(hw, AIT, 0);
  4494. } else {
  4495. DEBUGOUT("Not in Adaptive IFS mode!\n");
  4496. }
  4497. }
  4498. /******************************************************************************
  4499. * Called during the callback/watchdog routine to update IFS value based on
  4500. * the ratio of transmits to collisions.
  4501. *
  4502. * hw - Struct containing variables accessed by shared code
  4503. * tx_packets - Number of transmits since last callback
  4504. * total_collisions - Number of collisions since last callback
  4505. *****************************************************************************/
  4506. void
  4507. e1000_update_adaptive(struct e1000_hw *hw)
  4508. {
  4509. DEBUGFUNC("e1000_update_adaptive");
  4510. if(hw->adaptive_ifs) {
  4511. if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
  4512. if(hw->tx_packet_delta > MIN_NUM_XMITS) {
  4513. hw->in_ifs_mode = TRUE;
  4514. if(hw->current_ifs_val < hw->ifs_max_val) {
  4515. if(hw->current_ifs_val == 0)
  4516. hw->current_ifs_val = hw->ifs_min_val;
  4517. else
  4518. hw->current_ifs_val += hw->ifs_step_size;
  4519. E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
  4520. }
  4521. }
  4522. } else {
  4523. if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
  4524. hw->current_ifs_val = 0;
  4525. hw->in_ifs_mode = FALSE;
  4526. E1000_WRITE_REG(hw, AIT, 0);
  4527. }
  4528. }
  4529. } else {
  4530. DEBUGOUT("Not in Adaptive IFS mode!\n");
  4531. }
  4532. }
  4533. /******************************************************************************
  4534. * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
  4535. *
  4536. * hw - Struct containing variables accessed by shared code
  4537. * frame_len - The length of the frame in question
  4538. * mac_addr - The Ethernet destination address of the frame in question
  4539. *****************************************************************************/
  4540. void
  4541. e1000_tbi_adjust_stats(struct e1000_hw *hw,
  4542. struct e1000_hw_stats *stats,
  4543. uint32_t frame_len,
  4544. uint8_t *mac_addr)
  4545. {
  4546. uint64_t carry_bit;
  4547. /* First adjust the frame length. */
  4548. frame_len--;
  4549. /* We need to adjust the statistics counters, since the hardware
  4550. * counters overcount this packet as a CRC error and undercount
  4551. * the packet as a good packet
  4552. */
  4553. /* This packet should not be counted as a CRC error. */
  4554. stats->crcerrs--;
  4555. /* This packet does count as a Good Packet Received. */
  4556. stats->gprc++;
  4557. /* Adjust the Good Octets received counters */
  4558. carry_bit = 0x80000000 & stats->gorcl;
  4559. stats->gorcl += frame_len;
  4560. /* If the high bit of Gorcl (the low 32 bits of the Good Octets
  4561. * Received Count) was one before the addition,
  4562. * AND it is zero after, then we lost the carry out,
  4563. * need to add one to Gorch (Good Octets Received Count High).
  4564. * This could be simplified if all environments supported
  4565. * 64-bit integers.
  4566. */
  4567. if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
  4568. stats->gorch++;
  4569. /* Is this a broadcast or multicast? Check broadcast first,
  4570. * since the test for a multicast frame will test positive on
  4571. * a broadcast frame.
  4572. */
  4573. if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
  4574. /* Broadcast packet */
  4575. stats->bprc++;
  4576. else if(*mac_addr & 0x01)
  4577. /* Multicast packet */
  4578. stats->mprc++;
  4579. if(frame_len == hw->max_frame_size) {
  4580. /* In this case, the hardware has overcounted the number of
  4581. * oversize frames.
  4582. */
  4583. if(stats->roc > 0)
  4584. stats->roc--;
  4585. }
  4586. /* Adjust the bin counters when the extra byte put the frame in the
  4587. * wrong bin. Remember that the frame_len was adjusted above.
  4588. */
  4589. if(frame_len == 64) {
  4590. stats->prc64++;
  4591. stats->prc127--;
  4592. } else if(frame_len == 127) {
  4593. stats->prc127++;
  4594. stats->prc255--;
  4595. } else if(frame_len == 255) {
  4596. stats->prc255++;
  4597. stats->prc511--;
  4598. } else if(frame_len == 511) {
  4599. stats->prc511++;
  4600. stats->prc1023--;
  4601. } else if(frame_len == 1023) {
  4602. stats->prc1023++;
  4603. stats->prc1522--;
  4604. } else if(frame_len == 1522) {
  4605. stats->prc1522++;
  4606. }
  4607. }
  4608. /******************************************************************************
  4609. * Gets the current PCI bus type, speed, and width of the hardware
  4610. *
  4611. * hw - Struct containing variables accessed by shared code
  4612. *****************************************************************************/
  4613. void
  4614. e1000_get_bus_info(struct e1000_hw *hw)
  4615. {
  4616. uint32_t status;
  4617. switch (hw->mac_type) {
  4618. case e1000_82542_rev2_0:
  4619. case e1000_82542_rev2_1:
  4620. hw->bus_type = e1000_bus_type_unknown;
  4621. hw->bus_speed = e1000_bus_speed_unknown;
  4622. hw->bus_width = e1000_bus_width_unknown;
  4623. break;
  4624. case e1000_82571:
  4625. case e1000_82572:
  4626. case e1000_82573:
  4627. hw->bus_type = e1000_bus_type_pci_express;
  4628. hw->bus_speed = e1000_bus_speed_2500;
  4629. hw->bus_width = e1000_bus_width_pciex_4;
  4630. break;
  4631. default:
  4632. status = E1000_READ_REG(hw, STATUS);
  4633. hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
  4634. e1000_bus_type_pcix : e1000_bus_type_pci;
  4635. if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
  4636. hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
  4637. e1000_bus_speed_66 : e1000_bus_speed_120;
  4638. } else if(hw->bus_type == e1000_bus_type_pci) {
  4639. hw->bus_speed = (status & E1000_STATUS_PCI66) ?
  4640. e1000_bus_speed_66 : e1000_bus_speed_33;
  4641. } else {
  4642. switch (status & E1000_STATUS_PCIX_SPEED) {
  4643. case E1000_STATUS_PCIX_SPEED_66:
  4644. hw->bus_speed = e1000_bus_speed_66;
  4645. break;
  4646. case E1000_STATUS_PCIX_SPEED_100:
  4647. hw->bus_speed = e1000_bus_speed_100;
  4648. break;
  4649. case E1000_STATUS_PCIX_SPEED_133:
  4650. hw->bus_speed = e1000_bus_speed_133;
  4651. break;
  4652. default:
  4653. hw->bus_speed = e1000_bus_speed_reserved;
  4654. break;
  4655. }
  4656. }
  4657. hw->bus_width = (status & E1000_STATUS_BUS64) ?
  4658. e1000_bus_width_64 : e1000_bus_width_32;
  4659. break;
  4660. }
  4661. }
  4662. #if 0
  4663. /******************************************************************************
  4664. * Reads a value from one of the devices registers using port I/O (as opposed
  4665. * memory mapped I/O). Only 82544 and newer devices support port I/O.
  4666. *
  4667. * hw - Struct containing variables accessed by shared code
  4668. * offset - offset to read from
  4669. *****************************************************************************/
  4670. uint32_t
  4671. e1000_read_reg_io(struct e1000_hw *hw,
  4672. uint32_t offset)
  4673. {
  4674. unsigned long io_addr = hw->io_base;
  4675. unsigned long io_data = hw->io_base + 4;
  4676. e1000_io_write(hw, io_addr, offset);
  4677. return e1000_io_read(hw, io_data);
  4678. }
  4679. #endif /* 0 */
  4680. /******************************************************************************
  4681. * Writes a value to one of the devices registers using port I/O (as opposed to
  4682. * memory mapped I/O). Only 82544 and newer devices support port I/O.
  4683. *
  4684. * hw - Struct containing variables accessed by shared code
  4685. * offset - offset to write to
  4686. * value - value to write
  4687. *****************************************************************************/
  4688. static void
  4689. e1000_write_reg_io(struct e1000_hw *hw,
  4690. uint32_t offset,
  4691. uint32_t value)
  4692. {
  4693. unsigned long io_addr = hw->io_base;
  4694. unsigned long io_data = hw->io_base + 4;
  4695. e1000_io_write(hw, io_addr, offset);
  4696. e1000_io_write(hw, io_data, value);
  4697. }
  4698. /******************************************************************************
  4699. * Estimates the cable length.
  4700. *
  4701. * hw - Struct containing variables accessed by shared code
  4702. * min_length - The estimated minimum length
  4703. * max_length - The estimated maximum length
  4704. *
  4705. * returns: - E1000_ERR_XXX
  4706. * E1000_SUCCESS
  4707. *
  4708. * This function always returns a ranged length (minimum & maximum).
  4709. * So for M88 phy's, this function interprets the one value returned from the
  4710. * register to the minimum and maximum range.
  4711. * For IGP phy's, the function calculates the range by the AGC registers.
  4712. *****************************************************************************/
  4713. static int32_t
  4714. e1000_get_cable_length(struct e1000_hw *hw,
  4715. uint16_t *min_length,
  4716. uint16_t *max_length)
  4717. {
  4718. int32_t ret_val;
  4719. uint16_t agc_value = 0;
  4720. uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
  4721. uint16_t max_agc = 0;
  4722. uint16_t i, phy_data;
  4723. uint16_t cable_length;
  4724. DEBUGFUNC("e1000_get_cable_length");
  4725. *min_length = *max_length = 0;
  4726. /* Use old method for Phy older than IGP */
  4727. if(hw->phy_type == e1000_phy_m88) {
  4728. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  4729. &phy_data);
  4730. if(ret_val)
  4731. return ret_val;
  4732. cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
  4733. M88E1000_PSSR_CABLE_LENGTH_SHIFT;
  4734. /* Convert the enum value to ranged values */
  4735. switch (cable_length) {
  4736. case e1000_cable_length_50:
  4737. *min_length = 0;
  4738. *max_length = e1000_igp_cable_length_50;
  4739. break;
  4740. case e1000_cable_length_50_80:
  4741. *min_length = e1000_igp_cable_length_50;
  4742. *max_length = e1000_igp_cable_length_80;
  4743. break;
  4744. case e1000_cable_length_80_110:
  4745. *min_length = e1000_igp_cable_length_80;
  4746. *max_length = e1000_igp_cable_length_110;
  4747. break;
  4748. case e1000_cable_length_110_140:
  4749. *min_length = e1000_igp_cable_length_110;
  4750. *max_length = e1000_igp_cable_length_140;
  4751. break;
  4752. case e1000_cable_length_140:
  4753. *min_length = e1000_igp_cable_length_140;
  4754. *max_length = e1000_igp_cable_length_170;
  4755. break;
  4756. default:
  4757. return -E1000_ERR_PHY;
  4758. break;
  4759. }
  4760. } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
  4761. uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
  4762. {IGP01E1000_PHY_AGC_A,
  4763. IGP01E1000_PHY_AGC_B,
  4764. IGP01E1000_PHY_AGC_C,
  4765. IGP01E1000_PHY_AGC_D};
  4766. /* Read the AGC registers for all channels */
  4767. for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
  4768. ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
  4769. if(ret_val)
  4770. return ret_val;
  4771. cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
  4772. /* Array bound check. */
  4773. if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
  4774. (cur_agc == 0))
  4775. return -E1000_ERR_PHY;
  4776. agc_value += cur_agc;
  4777. /* Update minimal AGC value. */
  4778. if(min_agc > cur_agc)
  4779. min_agc = cur_agc;
  4780. }
  4781. /* Remove the minimal AGC result for length < 50m */
  4782. if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
  4783. agc_value -= min_agc;
  4784. /* Get the average length of the remaining 3 channels */
  4785. agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
  4786. } else {
  4787. /* Get the average length of all the 4 channels. */
  4788. agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
  4789. }
  4790. /* Set the range of the calculated length. */
  4791. *min_length = ((e1000_igp_cable_length_table[agc_value] -
  4792. IGP01E1000_AGC_RANGE) > 0) ?
  4793. (e1000_igp_cable_length_table[agc_value] -
  4794. IGP01E1000_AGC_RANGE) : 0;
  4795. *max_length = e1000_igp_cable_length_table[agc_value] +
  4796. IGP01E1000_AGC_RANGE;
  4797. } else if (hw->phy_type == e1000_phy_igp_2) {
  4798. uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
  4799. {IGP02E1000_PHY_AGC_A,
  4800. IGP02E1000_PHY_AGC_B,
  4801. IGP02E1000_PHY_AGC_C,
  4802. IGP02E1000_PHY_AGC_D};
  4803. /* Read the AGC registers for all channels */
  4804. for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
  4805. ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
  4806. if (ret_val)
  4807. return ret_val;
  4808. /* Getting bits 15:9, which represent the combination of course and
  4809. * fine gain values. The result is a number that can be put into
  4810. * the lookup table to obtain the approximate cable length. */
  4811. cur_agc = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
  4812. IGP02E1000_AGC_LENGTH_MASK;
  4813. /* Remove min & max AGC values from calculation. */
  4814. if (e1000_igp_2_cable_length_table[min_agc] > e1000_igp_2_cable_length_table[cur_agc])
  4815. min_agc = cur_agc;
  4816. if (e1000_igp_2_cable_length_table[max_agc] < e1000_igp_2_cable_length_table[cur_agc])
  4817. max_agc = cur_agc;
  4818. agc_value += e1000_igp_2_cable_length_table[cur_agc];
  4819. }
  4820. agc_value -= (e1000_igp_2_cable_length_table[min_agc] + e1000_igp_2_cable_length_table[max_agc]);
  4821. agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
  4822. /* Calculate cable length with the error range of +/- 10 meters. */
  4823. *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
  4824. (agc_value - IGP02E1000_AGC_RANGE) : 0;
  4825. *max_length = agc_value + IGP02E1000_AGC_RANGE;
  4826. }
  4827. return E1000_SUCCESS;
  4828. }
  4829. /******************************************************************************
  4830. * Check the cable polarity
  4831. *
  4832. * hw - Struct containing variables accessed by shared code
  4833. * polarity - output parameter : 0 - Polarity is not reversed
  4834. * 1 - Polarity is reversed.
  4835. *
  4836. * returns: - E1000_ERR_XXX
  4837. * E1000_SUCCESS
  4838. *
  4839. * For phy's older then IGP, this function simply reads the polarity bit in the
  4840. * Phy Status register. For IGP phy's, this bit is valid only if link speed is
  4841. * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
  4842. * return 0. If the link speed is 1000 Mbps the polarity status is in the
  4843. * IGP01E1000_PHY_PCS_INIT_REG.
  4844. *****************************************************************************/
  4845. static int32_t
  4846. e1000_check_polarity(struct e1000_hw *hw,
  4847. uint16_t *polarity)
  4848. {
  4849. int32_t ret_val;
  4850. uint16_t phy_data;
  4851. DEBUGFUNC("e1000_check_polarity");
  4852. if(hw->phy_type == e1000_phy_m88) {
  4853. /* return the Polarity bit in the Status register. */
  4854. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  4855. &phy_data);
  4856. if(ret_val)
  4857. return ret_val;
  4858. *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
  4859. M88E1000_PSSR_REV_POLARITY_SHIFT;
  4860. } else if(hw->phy_type == e1000_phy_igp ||
  4861. hw->phy_type == e1000_phy_igp_2) {
  4862. /* Read the Status register to check the speed */
  4863. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
  4864. &phy_data);
  4865. if(ret_val)
  4866. return ret_val;
  4867. /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
  4868. * find the polarity status */
  4869. if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
  4870. IGP01E1000_PSSR_SPEED_1000MBPS) {
  4871. /* Read the GIG initialization PCS register (0x00B4) */
  4872. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
  4873. &phy_data);
  4874. if(ret_val)
  4875. return ret_val;
  4876. /* Check the polarity bits */
  4877. *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
  4878. } else {
  4879. /* For 10 Mbps, read the polarity bit in the status register. (for
  4880. * 100 Mbps this bit is always 0) */
  4881. *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
  4882. }
  4883. }
  4884. return E1000_SUCCESS;
  4885. }
  4886. /******************************************************************************
  4887. * Check if Downshift occured
  4888. *
  4889. * hw - Struct containing variables accessed by shared code
  4890. * downshift - output parameter : 0 - No Downshift ocured.
  4891. * 1 - Downshift ocured.
  4892. *
  4893. * returns: - E1000_ERR_XXX
  4894. * E1000_SUCCESS
  4895. *
  4896. * For phy's older then IGP, this function reads the Downshift bit in the Phy
  4897. * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
  4898. * Link Health register. In IGP this bit is latched high, so the driver must
  4899. * read it immediately after link is established.
  4900. *****************************************************************************/
  4901. static int32_t
  4902. e1000_check_downshift(struct e1000_hw *hw)
  4903. {
  4904. int32_t ret_val;
  4905. uint16_t phy_data;
  4906. DEBUGFUNC("e1000_check_downshift");
  4907. if(hw->phy_type == e1000_phy_igp ||
  4908. hw->phy_type == e1000_phy_igp_2) {
  4909. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
  4910. &phy_data);
  4911. if(ret_val)
  4912. return ret_val;
  4913. hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
  4914. } else if(hw->phy_type == e1000_phy_m88) {
  4915. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  4916. &phy_data);
  4917. if(ret_val)
  4918. return ret_val;
  4919. hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
  4920. M88E1000_PSSR_DOWNSHIFT_SHIFT;
  4921. }
  4922. return E1000_SUCCESS;
  4923. }
  4924. /*****************************************************************************
  4925. *
  4926. * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
  4927. * gigabit link is achieved to improve link quality.
  4928. *
  4929. * hw: Struct containing variables accessed by shared code
  4930. *
  4931. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  4932. * E1000_SUCCESS at any other case.
  4933. *
  4934. ****************************************************************************/
  4935. static int32_t
  4936. e1000_config_dsp_after_link_change(struct e1000_hw *hw,
  4937. boolean_t link_up)
  4938. {
  4939. int32_t ret_val;
  4940. uint16_t phy_data, phy_saved_data, speed, duplex, i;
  4941. uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
  4942. {IGP01E1000_PHY_AGC_PARAM_A,
  4943. IGP01E1000_PHY_AGC_PARAM_B,
  4944. IGP01E1000_PHY_AGC_PARAM_C,
  4945. IGP01E1000_PHY_AGC_PARAM_D};
  4946. uint16_t min_length, max_length;
  4947. DEBUGFUNC("e1000_config_dsp_after_link_change");
  4948. if(hw->phy_type != e1000_phy_igp)
  4949. return E1000_SUCCESS;
  4950. if(link_up) {
  4951. ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
  4952. if(ret_val) {
  4953. DEBUGOUT("Error getting link speed and duplex\n");
  4954. return ret_val;
  4955. }
  4956. if(speed == SPEED_1000) {
  4957. e1000_get_cable_length(hw, &min_length, &max_length);
  4958. if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
  4959. min_length >= e1000_igp_cable_length_50) {
  4960. for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
  4961. ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
  4962. &phy_data);
  4963. if(ret_val)
  4964. return ret_val;
  4965. phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
  4966. ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
  4967. phy_data);
  4968. if(ret_val)
  4969. return ret_val;
  4970. }
  4971. hw->dsp_config_state = e1000_dsp_config_activated;
  4972. }
  4973. if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
  4974. (min_length < e1000_igp_cable_length_50)) {
  4975. uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
  4976. uint32_t idle_errs = 0;
  4977. /* clear previous idle error counts */
  4978. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
  4979. &phy_data);
  4980. if(ret_val)
  4981. return ret_val;
  4982. for(i = 0; i < ffe_idle_err_timeout; i++) {
  4983. udelay(1000);
  4984. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
  4985. &phy_data);
  4986. if(ret_val)
  4987. return ret_val;
  4988. idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
  4989. if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
  4990. hw->ffe_config_state = e1000_ffe_config_active;
  4991. ret_val = e1000_write_phy_reg(hw,
  4992. IGP01E1000_PHY_DSP_FFE,
  4993. IGP01E1000_PHY_DSP_FFE_CM_CP);
  4994. if(ret_val)
  4995. return ret_val;
  4996. break;
  4997. }
  4998. if(idle_errs)
  4999. ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
  5000. }
  5001. }
  5002. }
  5003. } else {
  5004. if(hw->dsp_config_state == e1000_dsp_config_activated) {
  5005. /* Save off the current value of register 0x2F5B to be restored at
  5006. * the end of the routines. */
  5007. ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  5008. if(ret_val)
  5009. return ret_val;
  5010. /* Disable the PHY transmitter */
  5011. ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  5012. if(ret_val)
  5013. return ret_val;
  5014. msec_delay_irq(20);
  5015. ret_val = e1000_write_phy_reg(hw, 0x0000,
  5016. IGP01E1000_IEEE_FORCE_GIGA);
  5017. if(ret_val)
  5018. return ret_val;
  5019. for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
  5020. ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
  5021. if(ret_val)
  5022. return ret_val;
  5023. phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
  5024. phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
  5025. ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
  5026. if(ret_val)
  5027. return ret_val;
  5028. }
  5029. ret_val = e1000_write_phy_reg(hw, 0x0000,
  5030. IGP01E1000_IEEE_RESTART_AUTONEG);
  5031. if(ret_val)
  5032. return ret_val;
  5033. msec_delay_irq(20);
  5034. /* Now enable the transmitter */
  5035. ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  5036. if(ret_val)
  5037. return ret_val;
  5038. hw->dsp_config_state = e1000_dsp_config_enabled;
  5039. }
  5040. if(hw->ffe_config_state == e1000_ffe_config_active) {
  5041. /* Save off the current value of register 0x2F5B to be restored at
  5042. * the end of the routines. */
  5043. ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  5044. if(ret_val)
  5045. return ret_val;
  5046. /* Disable the PHY transmitter */
  5047. ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  5048. if(ret_val)
  5049. return ret_val;
  5050. msec_delay_irq(20);
  5051. ret_val = e1000_write_phy_reg(hw, 0x0000,
  5052. IGP01E1000_IEEE_FORCE_GIGA);
  5053. if(ret_val)
  5054. return ret_val;
  5055. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
  5056. IGP01E1000_PHY_DSP_FFE_DEFAULT);
  5057. if(ret_val)
  5058. return ret_val;
  5059. ret_val = e1000_write_phy_reg(hw, 0x0000,
  5060. IGP01E1000_IEEE_RESTART_AUTONEG);
  5061. if(ret_val)
  5062. return ret_val;
  5063. msec_delay_irq(20);
  5064. /* Now enable the transmitter */
  5065. ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  5066. if(ret_val)
  5067. return ret_val;
  5068. hw->ffe_config_state = e1000_ffe_config_enabled;
  5069. }
  5070. }
  5071. return E1000_SUCCESS;
  5072. }
  5073. /*****************************************************************************
  5074. * Set PHY to class A mode
  5075. * Assumes the following operations will follow to enable the new class mode.
  5076. * 1. Do a PHY soft reset
  5077. * 2. Restart auto-negotiation or force link.
  5078. *
  5079. * hw - Struct containing variables accessed by shared code
  5080. ****************************************************************************/
  5081. static int32_t
  5082. e1000_set_phy_mode(struct e1000_hw *hw)
  5083. {
  5084. int32_t ret_val;
  5085. uint16_t eeprom_data;
  5086. DEBUGFUNC("e1000_set_phy_mode");
  5087. if((hw->mac_type == e1000_82545_rev_3) &&
  5088. (hw->media_type == e1000_media_type_copper)) {
  5089. ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
  5090. if(ret_val) {
  5091. return ret_val;
  5092. }
  5093. if((eeprom_data != EEPROM_RESERVED_WORD) &&
  5094. (eeprom_data & EEPROM_PHY_CLASS_A)) {
  5095. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
  5096. if(ret_val)
  5097. return ret_val;
  5098. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
  5099. if(ret_val)
  5100. return ret_val;
  5101. hw->phy_reset_disable = FALSE;
  5102. }
  5103. }
  5104. return E1000_SUCCESS;
  5105. }
  5106. /*****************************************************************************
  5107. *
  5108. * This function sets the lplu state according to the active flag. When
  5109. * activating lplu this function also disables smart speed and vise versa.
  5110. * lplu will not be activated unless the device autonegotiation advertisment
  5111. * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
  5112. * hw: Struct containing variables accessed by shared code
  5113. * active - true to enable lplu false to disable lplu.
  5114. *
  5115. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  5116. * E1000_SUCCESS at any other case.
  5117. *
  5118. ****************************************************************************/
  5119. static int32_t
  5120. e1000_set_d3_lplu_state(struct e1000_hw *hw,
  5121. boolean_t active)
  5122. {
  5123. int32_t ret_val;
  5124. uint16_t phy_data;
  5125. DEBUGFUNC("e1000_set_d3_lplu_state");
  5126. if(hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2)
  5127. return E1000_SUCCESS;
  5128. /* During driver activity LPLU should not be used or it will attain link
  5129. * from the lowest speeds starting from 10Mbps. The capability is used for
  5130. * Dx transitions and states */
  5131. if(hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
  5132. ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
  5133. if(ret_val)
  5134. return ret_val;
  5135. } else {
  5136. ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
  5137. if(ret_val)
  5138. return ret_val;
  5139. }
  5140. if(!active) {
  5141. if(hw->mac_type == e1000_82541_rev_2 ||
  5142. hw->mac_type == e1000_82547_rev_2) {
  5143. phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
  5144. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
  5145. if(ret_val)
  5146. return ret_val;
  5147. } else {
  5148. phy_data &= ~IGP02E1000_PM_D3_LPLU;
  5149. ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  5150. phy_data);
  5151. if (ret_val)
  5152. return ret_val;
  5153. }
  5154. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
  5155. * Dx states where the power conservation is most important. During
  5156. * driver activity we should enable SmartSpeed, so performance is
  5157. * maintained. */
  5158. if (hw->smart_speed == e1000_smart_speed_on) {
  5159. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5160. &phy_data);
  5161. if(ret_val)
  5162. return ret_val;
  5163. phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
  5164. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5165. phy_data);
  5166. if(ret_val)
  5167. return ret_val;
  5168. } else if (hw->smart_speed == e1000_smart_speed_off) {
  5169. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5170. &phy_data);
  5171. if (ret_val)
  5172. return ret_val;
  5173. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  5174. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5175. phy_data);
  5176. if(ret_val)
  5177. return ret_val;
  5178. }
  5179. } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
  5180. (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
  5181. (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
  5182. if(hw->mac_type == e1000_82541_rev_2 ||
  5183. hw->mac_type == e1000_82547_rev_2) {
  5184. phy_data |= IGP01E1000_GMII_FLEX_SPD;
  5185. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
  5186. if(ret_val)
  5187. return ret_val;
  5188. } else {
  5189. phy_data |= IGP02E1000_PM_D3_LPLU;
  5190. ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  5191. phy_data);
  5192. if (ret_val)
  5193. return ret_val;
  5194. }
  5195. /* When LPLU is enabled we should disable SmartSpeed */
  5196. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  5197. if(ret_val)
  5198. return ret_val;
  5199. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  5200. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
  5201. if(ret_val)
  5202. return ret_val;
  5203. }
  5204. return E1000_SUCCESS;
  5205. }
  5206. /*****************************************************************************
  5207. *
  5208. * This function sets the lplu d0 state according to the active flag. When
  5209. * activating lplu this function also disables smart speed and vise versa.
  5210. * lplu will not be activated unless the device autonegotiation advertisment
  5211. * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
  5212. * hw: Struct containing variables accessed by shared code
  5213. * active - true to enable lplu false to disable lplu.
  5214. *
  5215. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  5216. * E1000_SUCCESS at any other case.
  5217. *
  5218. ****************************************************************************/
  5219. static int32_t
  5220. e1000_set_d0_lplu_state(struct e1000_hw *hw,
  5221. boolean_t active)
  5222. {
  5223. int32_t ret_val;
  5224. uint16_t phy_data;
  5225. DEBUGFUNC("e1000_set_d0_lplu_state");
  5226. if(hw->mac_type <= e1000_82547_rev_2)
  5227. return E1000_SUCCESS;
  5228. ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
  5229. if(ret_val)
  5230. return ret_val;
  5231. if (!active) {
  5232. phy_data &= ~IGP02E1000_PM_D0_LPLU;
  5233. ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
  5234. if (ret_val)
  5235. return ret_val;
  5236. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
  5237. * Dx states where the power conservation is most important. During
  5238. * driver activity we should enable SmartSpeed, so performance is
  5239. * maintained. */
  5240. if (hw->smart_speed == e1000_smart_speed_on) {
  5241. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5242. &phy_data);
  5243. if(ret_val)
  5244. return ret_val;
  5245. phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
  5246. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5247. phy_data);
  5248. if(ret_val)
  5249. return ret_val;
  5250. } else if (hw->smart_speed == e1000_smart_speed_off) {
  5251. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5252. &phy_data);
  5253. if (ret_val)
  5254. return ret_val;
  5255. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  5256. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5257. phy_data);
  5258. if(ret_val)
  5259. return ret_val;
  5260. }
  5261. } else {
  5262. phy_data |= IGP02E1000_PM_D0_LPLU;
  5263. ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
  5264. if (ret_val)
  5265. return ret_val;
  5266. /* When LPLU is enabled we should disable SmartSpeed */
  5267. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  5268. if(ret_val)
  5269. return ret_val;
  5270. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  5271. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
  5272. if(ret_val)
  5273. return ret_val;
  5274. }
  5275. return E1000_SUCCESS;
  5276. }
  5277. /******************************************************************************
  5278. * Change VCO speed register to improve Bit Error Rate performance of SERDES.
  5279. *
  5280. * hw - Struct containing variables accessed by shared code
  5281. *****************************************************************************/
  5282. static int32_t
  5283. e1000_set_vco_speed(struct e1000_hw *hw)
  5284. {
  5285. int32_t ret_val;
  5286. uint16_t default_page = 0;
  5287. uint16_t phy_data;
  5288. DEBUGFUNC("e1000_set_vco_speed");
  5289. switch(hw->mac_type) {
  5290. case e1000_82545_rev_3:
  5291. case e1000_82546_rev_3:
  5292. break;
  5293. default:
  5294. return E1000_SUCCESS;
  5295. }
  5296. /* Set PHY register 30, page 5, bit 8 to 0 */
  5297. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
  5298. if(ret_val)
  5299. return ret_val;
  5300. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
  5301. if(ret_val)
  5302. return ret_val;
  5303. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
  5304. if(ret_val)
  5305. return ret_val;
  5306. phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
  5307. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
  5308. if(ret_val)
  5309. return ret_val;
  5310. /* Set PHY register 30, page 4, bit 11 to 1 */
  5311. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
  5312. if(ret_val)
  5313. return ret_val;
  5314. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
  5315. if(ret_val)
  5316. return ret_val;
  5317. phy_data |= M88E1000_PHY_VCO_REG_BIT11;
  5318. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
  5319. if(ret_val)
  5320. return ret_val;
  5321. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
  5322. if(ret_val)
  5323. return ret_val;
  5324. return E1000_SUCCESS;
  5325. }
  5326. /*****************************************************************************
  5327. * This function reads the cookie from ARC ram.
  5328. *
  5329. * returns: - E1000_SUCCESS .
  5330. ****************************************************************************/
  5331. int32_t
  5332. e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
  5333. {
  5334. uint8_t i;
  5335. uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
  5336. uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
  5337. length = (length >> 2);
  5338. offset = (offset >> 2);
  5339. for (i = 0; i < length; i++) {
  5340. *((uint32_t *) buffer + i) =
  5341. E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
  5342. }
  5343. return E1000_SUCCESS;
  5344. }
  5345. /*****************************************************************************
  5346. * This function checks whether the HOST IF is enabled for command operaton
  5347. * and also checks whether the previous command is completed.
  5348. * It busy waits in case of previous command is not completed.
  5349. *
  5350. * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
  5351. * timeout
  5352. * - E1000_SUCCESS for success.
  5353. ****************************************************************************/
  5354. static int32_t
  5355. e1000_mng_enable_host_if(struct e1000_hw * hw)
  5356. {
  5357. uint32_t hicr;
  5358. uint8_t i;
  5359. /* Check that the host interface is enabled. */
  5360. hicr = E1000_READ_REG(hw, HICR);
  5361. if ((hicr & E1000_HICR_EN) == 0) {
  5362. DEBUGOUT("E1000_HOST_EN bit disabled.\n");
  5363. return -E1000_ERR_HOST_INTERFACE_COMMAND;
  5364. }
  5365. /* check the previous command is completed */
  5366. for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
  5367. hicr = E1000_READ_REG(hw, HICR);
  5368. if (!(hicr & E1000_HICR_C))
  5369. break;
  5370. msec_delay_irq(1);
  5371. }
  5372. if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
  5373. DEBUGOUT("Previous command timeout failed .\n");
  5374. return -E1000_ERR_HOST_INTERFACE_COMMAND;
  5375. }
  5376. return E1000_SUCCESS;
  5377. }
  5378. /*****************************************************************************
  5379. * This function writes the buffer content at the offset given on the host if.
  5380. * It also does alignment considerations to do the writes in most efficient way.
  5381. * Also fills up the sum of the buffer in *buffer parameter.
  5382. *
  5383. * returns - E1000_SUCCESS for success.
  5384. ****************************************************************************/
  5385. static int32_t
  5386. e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
  5387. uint16_t length, uint16_t offset, uint8_t *sum)
  5388. {
  5389. uint8_t *tmp;
  5390. uint8_t *bufptr = buffer;
  5391. uint32_t data;
  5392. uint16_t remaining, i, j, prev_bytes;
  5393. /* sum = only sum of the data and it is not checksum */
  5394. if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
  5395. return -E1000_ERR_PARAM;
  5396. }
  5397. tmp = (uint8_t *)&data;
  5398. prev_bytes = offset & 0x3;
  5399. offset &= 0xFFFC;
  5400. offset >>= 2;
  5401. if (prev_bytes) {
  5402. data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
  5403. for (j = prev_bytes; j < sizeof(uint32_t); j++) {
  5404. *(tmp + j) = *bufptr++;
  5405. *sum += *(tmp + j);
  5406. }
  5407. E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
  5408. length -= j - prev_bytes;
  5409. offset++;
  5410. }
  5411. remaining = length & 0x3;
  5412. length -= remaining;
  5413. /* Calculate length in DWORDs */
  5414. length >>= 2;
  5415. /* The device driver writes the relevant command block into the
  5416. * ram area. */
  5417. for (i = 0; i < length; i++) {
  5418. for (j = 0; j < sizeof(uint32_t); j++) {
  5419. *(tmp + j) = *bufptr++;
  5420. *sum += *(tmp + j);
  5421. }
  5422. E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
  5423. }
  5424. if (remaining) {
  5425. for (j = 0; j < sizeof(uint32_t); j++) {
  5426. if (j < remaining)
  5427. *(tmp + j) = *bufptr++;
  5428. else
  5429. *(tmp + j) = 0;
  5430. *sum += *(tmp + j);
  5431. }
  5432. E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
  5433. }
  5434. return E1000_SUCCESS;
  5435. }
  5436. /*****************************************************************************
  5437. * This function writes the command header after does the checksum calculation.
  5438. *
  5439. * returns - E1000_SUCCESS for success.
  5440. ****************************************************************************/
  5441. static int32_t
  5442. e1000_mng_write_cmd_header(struct e1000_hw * hw,
  5443. struct e1000_host_mng_command_header * hdr)
  5444. {
  5445. uint16_t i;
  5446. uint8_t sum;
  5447. uint8_t *buffer;
  5448. /* Write the whole command header structure which includes sum of
  5449. * the buffer */
  5450. uint16_t length = sizeof(struct e1000_host_mng_command_header);
  5451. sum = hdr->checksum;
  5452. hdr->checksum = 0;
  5453. buffer = (uint8_t *) hdr;
  5454. i = length;
  5455. while(i--)
  5456. sum += buffer[i];
  5457. hdr->checksum = 0 - sum;
  5458. length >>= 2;
  5459. /* The device driver writes the relevant command block into the ram area. */
  5460. for (i = 0; i < length; i++)
  5461. E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
  5462. return E1000_SUCCESS;
  5463. }
  5464. /*****************************************************************************
  5465. * This function indicates to ARC that a new command is pending which completes
  5466. * one write operation by the driver.
  5467. *
  5468. * returns - E1000_SUCCESS for success.
  5469. ****************************************************************************/
  5470. static int32_t
  5471. e1000_mng_write_commit(
  5472. struct e1000_hw * hw)
  5473. {
  5474. uint32_t hicr;
  5475. hicr = E1000_READ_REG(hw, HICR);
  5476. /* Setting this bit tells the ARC that a new command is pending. */
  5477. E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
  5478. return E1000_SUCCESS;
  5479. }
  5480. /*****************************************************************************
  5481. * This function checks the mode of the firmware.
  5482. *
  5483. * returns - TRUE when the mode is IAMT or FALSE.
  5484. ****************************************************************************/
  5485. boolean_t
  5486. e1000_check_mng_mode(
  5487. struct e1000_hw *hw)
  5488. {
  5489. uint32_t fwsm;
  5490. fwsm = E1000_READ_REG(hw, FWSM);
  5491. if((fwsm & E1000_FWSM_MODE_MASK) ==
  5492. (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
  5493. return TRUE;
  5494. return FALSE;
  5495. }
  5496. /*****************************************************************************
  5497. * This function writes the dhcp info .
  5498. ****************************************************************************/
  5499. int32_t
  5500. e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
  5501. uint16_t length)
  5502. {
  5503. int32_t ret_val;
  5504. struct e1000_host_mng_command_header hdr;
  5505. hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
  5506. hdr.command_length = length;
  5507. hdr.reserved1 = 0;
  5508. hdr.reserved2 = 0;
  5509. hdr.checksum = 0;
  5510. ret_val = e1000_mng_enable_host_if(hw);
  5511. if (ret_val == E1000_SUCCESS) {
  5512. ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
  5513. &(hdr.checksum));
  5514. if (ret_val == E1000_SUCCESS) {
  5515. ret_val = e1000_mng_write_cmd_header(hw, &hdr);
  5516. if (ret_val == E1000_SUCCESS)
  5517. ret_val = e1000_mng_write_commit(hw);
  5518. }
  5519. }
  5520. return ret_val;
  5521. }
  5522. /*****************************************************************************
  5523. * This function calculates the checksum.
  5524. *
  5525. * returns - checksum of buffer contents.
  5526. ****************************************************************************/
  5527. uint8_t
  5528. e1000_calculate_mng_checksum(char *buffer, uint32_t length)
  5529. {
  5530. uint8_t sum = 0;
  5531. uint32_t i;
  5532. if (!buffer)
  5533. return 0;
  5534. for (i=0; i < length; i++)
  5535. sum += buffer[i];
  5536. return (uint8_t) (0 - sum);
  5537. }
  5538. /*****************************************************************************
  5539. * This function checks whether tx pkt filtering needs to be enabled or not.
  5540. *
  5541. * returns - TRUE for packet filtering or FALSE.
  5542. ****************************************************************************/
  5543. boolean_t
  5544. e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
  5545. {
  5546. /* called in init as well as watchdog timer functions */
  5547. int32_t ret_val, checksum;
  5548. boolean_t tx_filter = FALSE;
  5549. struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
  5550. uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
  5551. if (e1000_check_mng_mode(hw)) {
  5552. ret_val = e1000_mng_enable_host_if(hw);
  5553. if (ret_val == E1000_SUCCESS) {
  5554. ret_val = e1000_host_if_read_cookie(hw, buffer);
  5555. if (ret_val == E1000_SUCCESS) {
  5556. checksum = hdr->checksum;
  5557. hdr->checksum = 0;
  5558. if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
  5559. checksum == e1000_calculate_mng_checksum((char *)buffer,
  5560. E1000_MNG_DHCP_COOKIE_LENGTH)) {
  5561. if (hdr->status &
  5562. E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
  5563. tx_filter = TRUE;
  5564. } else
  5565. tx_filter = TRUE;
  5566. } else
  5567. tx_filter = TRUE;
  5568. }
  5569. }
  5570. hw->tx_pkt_filtering = tx_filter;
  5571. return tx_filter;
  5572. }
  5573. /******************************************************************************
  5574. * Verifies the hardware needs to allow ARPs to be processed by the host
  5575. *
  5576. * hw - Struct containing variables accessed by shared code
  5577. *
  5578. * returns: - TRUE/FALSE
  5579. *
  5580. *****************************************************************************/
  5581. uint32_t
  5582. e1000_enable_mng_pass_thru(struct e1000_hw *hw)
  5583. {
  5584. uint32_t manc;
  5585. uint32_t fwsm, factps;
  5586. if (hw->asf_firmware_present) {
  5587. manc = E1000_READ_REG(hw, MANC);
  5588. if (!(manc & E1000_MANC_RCV_TCO_EN) ||
  5589. !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
  5590. return FALSE;
  5591. if (e1000_arc_subsystem_valid(hw) == TRUE) {
  5592. fwsm = E1000_READ_REG(hw, FWSM);
  5593. factps = E1000_READ_REG(hw, FACTPS);
  5594. if (((fwsm & E1000_FWSM_MODE_MASK) ==
  5595. (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
  5596. (factps & E1000_FACTPS_MNGCG))
  5597. return TRUE;
  5598. } else
  5599. if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
  5600. return TRUE;
  5601. }
  5602. return FALSE;
  5603. }
  5604. static int32_t
  5605. e1000_polarity_reversal_workaround(struct e1000_hw *hw)
  5606. {
  5607. int32_t ret_val;
  5608. uint16_t mii_status_reg;
  5609. uint16_t i;
  5610. /* Polarity reversal workaround for forced 10F/10H links. */
  5611. /* Disable the transmitter on the PHY */
  5612. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
  5613. if(ret_val)
  5614. return ret_val;
  5615. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
  5616. if(ret_val)
  5617. return ret_val;
  5618. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
  5619. if(ret_val)
  5620. return ret_val;
  5621. /* This loop will early-out if the NO link condition has been met. */
  5622. for(i = PHY_FORCE_TIME; i > 0; i--) {
  5623. /* Read the MII Status Register and wait for Link Status bit
  5624. * to be clear.
  5625. */
  5626. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  5627. if(ret_val)
  5628. return ret_val;
  5629. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  5630. if(ret_val)
  5631. return ret_val;
  5632. if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
  5633. msec_delay_irq(100);
  5634. }
  5635. /* Recommended delay time after link has been lost */
  5636. msec_delay_irq(1000);
  5637. /* Now we will re-enable th transmitter on the PHY */
  5638. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
  5639. if(ret_val)
  5640. return ret_val;
  5641. msec_delay_irq(50);
  5642. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
  5643. if(ret_val)
  5644. return ret_val;
  5645. msec_delay_irq(50);
  5646. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
  5647. if(ret_val)
  5648. return ret_val;
  5649. msec_delay_irq(50);
  5650. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
  5651. if(ret_val)
  5652. return ret_val;
  5653. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
  5654. if(ret_val)
  5655. return ret_val;
  5656. /* This loop will early-out if the link condition has been met. */
  5657. for(i = PHY_FORCE_TIME; i > 0; i--) {
  5658. /* Read the MII Status Register and wait for Link Status bit
  5659. * to be set.
  5660. */
  5661. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  5662. if(ret_val)
  5663. return ret_val;
  5664. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  5665. if(ret_val)
  5666. return ret_val;
  5667. if(mii_status_reg & MII_SR_LINK_STATUS) break;
  5668. msec_delay_irq(100);
  5669. }
  5670. return E1000_SUCCESS;
  5671. }
  5672. /***************************************************************************
  5673. *
  5674. * Disables PCI-Express master access.
  5675. *
  5676. * hw: Struct containing variables accessed by shared code
  5677. *
  5678. * returns: - none.
  5679. *
  5680. ***************************************************************************/
  5681. static void
  5682. e1000_set_pci_express_master_disable(struct e1000_hw *hw)
  5683. {
  5684. uint32_t ctrl;
  5685. DEBUGFUNC("e1000_set_pci_express_master_disable");
  5686. if (hw->bus_type != e1000_bus_type_pci_express)
  5687. return;
  5688. ctrl = E1000_READ_REG(hw, CTRL);
  5689. ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
  5690. E1000_WRITE_REG(hw, CTRL, ctrl);
  5691. }
  5692. #if 0
  5693. /***************************************************************************
  5694. *
  5695. * Enables PCI-Express master access.
  5696. *
  5697. * hw: Struct containing variables accessed by shared code
  5698. *
  5699. * returns: - none.
  5700. *
  5701. ***************************************************************************/
  5702. void
  5703. e1000_enable_pciex_master(struct e1000_hw *hw)
  5704. {
  5705. uint32_t ctrl;
  5706. DEBUGFUNC("e1000_enable_pciex_master");
  5707. if (hw->bus_type != e1000_bus_type_pci_express)
  5708. return;
  5709. ctrl = E1000_READ_REG(hw, CTRL);
  5710. ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
  5711. E1000_WRITE_REG(hw, CTRL, ctrl);
  5712. }
  5713. #endif /* 0 */
  5714. /*******************************************************************************
  5715. *
  5716. * Disables PCI-Express master access and verifies there are no pending requests
  5717. *
  5718. * hw: Struct containing variables accessed by shared code
  5719. *
  5720. * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
  5721. * caused the master requests to be disabled.
  5722. * E1000_SUCCESS master requests disabled.
  5723. *
  5724. ******************************************************************************/
  5725. int32_t
  5726. e1000_disable_pciex_master(struct e1000_hw *hw)
  5727. {
  5728. int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
  5729. DEBUGFUNC("e1000_disable_pciex_master");
  5730. if (hw->bus_type != e1000_bus_type_pci_express)
  5731. return E1000_SUCCESS;
  5732. e1000_set_pci_express_master_disable(hw);
  5733. while(timeout) {
  5734. if(!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
  5735. break;
  5736. else
  5737. udelay(100);
  5738. timeout--;
  5739. }
  5740. if(!timeout) {
  5741. DEBUGOUT("Master requests are pending.\n");
  5742. return -E1000_ERR_MASTER_REQUESTS_PENDING;
  5743. }
  5744. return E1000_SUCCESS;
  5745. }
  5746. /*******************************************************************************
  5747. *
  5748. * Check for EEPROM Auto Read bit done.
  5749. *
  5750. * hw: Struct containing variables accessed by shared code
  5751. *
  5752. * returns: - E1000_ERR_RESET if fail to reset MAC
  5753. * E1000_SUCCESS at any other case.
  5754. *
  5755. ******************************************************************************/
  5756. static int32_t
  5757. e1000_get_auto_rd_done(struct e1000_hw *hw)
  5758. {
  5759. int32_t timeout = AUTO_READ_DONE_TIMEOUT;
  5760. DEBUGFUNC("e1000_get_auto_rd_done");
  5761. switch (hw->mac_type) {
  5762. default:
  5763. msec_delay(5);
  5764. break;
  5765. case e1000_82571:
  5766. case e1000_82572:
  5767. case e1000_82573:
  5768. while(timeout) {
  5769. if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) break;
  5770. else msec_delay(1);
  5771. timeout--;
  5772. }
  5773. if(!timeout) {
  5774. DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
  5775. return -E1000_ERR_RESET;
  5776. }
  5777. break;
  5778. }
  5779. return E1000_SUCCESS;
  5780. }
  5781. /***************************************************************************
  5782. * Checks if the PHY configuration is done
  5783. *
  5784. * hw: Struct containing variables accessed by shared code
  5785. *
  5786. * returns: - E1000_ERR_RESET if fail to reset MAC
  5787. * E1000_SUCCESS at any other case.
  5788. *
  5789. ***************************************************************************/
  5790. static int32_t
  5791. e1000_get_phy_cfg_done(struct e1000_hw *hw)
  5792. {
  5793. int32_t timeout = PHY_CFG_TIMEOUT;
  5794. uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
  5795. DEBUGFUNC("e1000_get_phy_cfg_done");
  5796. switch (hw->mac_type) {
  5797. default:
  5798. msec_delay(10);
  5799. break;
  5800. case e1000_82571:
  5801. case e1000_82572:
  5802. while (timeout) {
  5803. if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
  5804. break;
  5805. else
  5806. msec_delay(1);
  5807. timeout--;
  5808. }
  5809. if (!timeout) {
  5810. DEBUGOUT("MNG configuration cycle has not completed.\n");
  5811. return -E1000_ERR_RESET;
  5812. }
  5813. break;
  5814. }
  5815. return E1000_SUCCESS;
  5816. }
  5817. /***************************************************************************
  5818. *
  5819. * Using the combination of SMBI and SWESMBI semaphore bits when resetting
  5820. * adapter or Eeprom access.
  5821. *
  5822. * hw: Struct containing variables accessed by shared code
  5823. *
  5824. * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
  5825. * E1000_SUCCESS at any other case.
  5826. *
  5827. ***************************************************************************/
  5828. static int32_t
  5829. e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
  5830. {
  5831. int32_t timeout;
  5832. uint32_t swsm;
  5833. DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
  5834. if(!hw->eeprom_semaphore_present)
  5835. return E1000_SUCCESS;
  5836. /* Get the FW semaphore. */
  5837. timeout = hw->eeprom.word_size + 1;
  5838. while(timeout) {
  5839. swsm = E1000_READ_REG(hw, SWSM);
  5840. swsm |= E1000_SWSM_SWESMBI;
  5841. E1000_WRITE_REG(hw, SWSM, swsm);
  5842. /* if we managed to set the bit we got the semaphore. */
  5843. swsm = E1000_READ_REG(hw, SWSM);
  5844. if(swsm & E1000_SWSM_SWESMBI)
  5845. break;
  5846. udelay(50);
  5847. timeout--;
  5848. }
  5849. if(!timeout) {
  5850. /* Release semaphores */
  5851. e1000_put_hw_eeprom_semaphore(hw);
  5852. DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
  5853. return -E1000_ERR_EEPROM;
  5854. }
  5855. return E1000_SUCCESS;
  5856. }
  5857. /***************************************************************************
  5858. * This function clears HW semaphore bits.
  5859. *
  5860. * hw: Struct containing variables accessed by shared code
  5861. *
  5862. * returns: - None.
  5863. *
  5864. ***************************************************************************/
  5865. static void
  5866. e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
  5867. {
  5868. uint32_t swsm;
  5869. DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
  5870. if(!hw->eeprom_semaphore_present)
  5871. return;
  5872. swsm = E1000_READ_REG(hw, SWSM);
  5873. swsm &= ~(E1000_SWSM_SWESMBI);
  5874. E1000_WRITE_REG(hw, SWSM, swsm);
  5875. }
  5876. /******************************************************************************
  5877. * Checks if PHY reset is blocked due to SOL/IDER session, for example.
  5878. * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
  5879. * the caller to figure out how to deal with it.
  5880. *
  5881. * hw - Struct containing variables accessed by shared code
  5882. *
  5883. * returns: - E1000_BLK_PHY_RESET
  5884. * E1000_SUCCESS
  5885. *
  5886. *****************************************************************************/
  5887. int32_t
  5888. e1000_check_phy_reset_block(struct e1000_hw *hw)
  5889. {
  5890. uint32_t manc = 0;
  5891. if(hw->mac_type > e1000_82547_rev_2)
  5892. manc = E1000_READ_REG(hw, MANC);
  5893. return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
  5894. E1000_BLK_PHY_RESET : E1000_SUCCESS;
  5895. }
  5896. static uint8_t
  5897. e1000_arc_subsystem_valid(struct e1000_hw *hw)
  5898. {
  5899. uint32_t fwsm;
  5900. /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
  5901. * may not be provided a DMA clock when no manageability features are
  5902. * enabled. We do not want to perform any reads/writes to these registers
  5903. * if this is the case. We read FWSM to determine the manageability mode.
  5904. */
  5905. switch (hw->mac_type) {
  5906. case e1000_82571:
  5907. case e1000_82572:
  5908. case e1000_82573:
  5909. fwsm = E1000_READ_REG(hw, FWSM);
  5910. if((fwsm & E1000_FWSM_MODE_MASK) != 0)
  5911. return TRUE;
  5912. break;
  5913. default:
  5914. break;
  5915. }
  5916. return FALSE;
  5917. }