e1000_hw.c 234 KB

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