e1000_hw.c 303 KB

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