e1000.c 158 KB

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