e1000_hw.c 233 KB

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