e1000_hw.c 313 KB

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