e1000.c 152 KB

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