e1000_hw.c 157 KB

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