e1000_hw.c 156 KB

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