e1000_hw.c 225 KB

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