e1000_hw.c 157 KB

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