e1000.c 153 KB

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