e1000_hw.c 234 KB

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