e1000.c 163 KB

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