e1000.c 155 KB

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