e1000_hw.c 234 KB

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