e1000_hw.c 234 KB

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