e1000_hw.c 260 KB

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