e1000.c 154 KB

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