e1000_hw.c 257 KB

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