e1000_hw.c 313 KB

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