e1000_hw.c 225 KB

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