e1000.c 165 KB

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