e1000.c 159 KB

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