e1000.c 153 KB

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