e1000_hw.c 258 KB

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