e1000_hw.c 160 KB

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