e1000_hw.c 236 KB

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