e1000_hw.c 259 KB

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