ich8lan.c 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555
  1. /*******************************************************************************
  2. Intel PRO/1000 Linux driver
  3. Copyright(c) 1999 - 2012 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. /* 82562G 10/100 Network Connection
  22. * 82562G-2 10/100 Network Connection
  23. * 82562GT 10/100 Network Connection
  24. * 82562GT-2 10/100 Network Connection
  25. * 82562V 10/100 Network Connection
  26. * 82562V-2 10/100 Network Connection
  27. * 82566DC-2 Gigabit Network Connection
  28. * 82566DC Gigabit Network Connection
  29. * 82566DM-2 Gigabit Network Connection
  30. * 82566DM Gigabit Network Connection
  31. * 82566MC Gigabit Network Connection
  32. * 82566MM Gigabit Network Connection
  33. * 82567LM Gigabit Network Connection
  34. * 82567LF Gigabit Network Connection
  35. * 82567V Gigabit Network Connection
  36. * 82567LM-2 Gigabit Network Connection
  37. * 82567LF-2 Gigabit Network Connection
  38. * 82567V-2 Gigabit Network Connection
  39. * 82567LF-3 Gigabit Network Connection
  40. * 82567LM-3 Gigabit Network Connection
  41. * 82567LM-4 Gigabit Network Connection
  42. * 82577LM Gigabit Network Connection
  43. * 82577LC Gigabit Network Connection
  44. * 82578DM Gigabit Network Connection
  45. * 82578DC Gigabit Network Connection
  46. * 82579LM Gigabit Network Connection
  47. * 82579V Gigabit Network Connection
  48. */
  49. #include "e1000.h"
  50. #define ICH_FLASH_GFPREG 0x0000
  51. #define ICH_FLASH_HSFSTS 0x0004
  52. #define ICH_FLASH_HSFCTL 0x0006
  53. #define ICH_FLASH_FADDR 0x0008
  54. #define ICH_FLASH_FDATA0 0x0010
  55. #define ICH_FLASH_PR0 0x0074
  56. #define ICH_FLASH_READ_COMMAND_TIMEOUT 500
  57. #define ICH_FLASH_WRITE_COMMAND_TIMEOUT 500
  58. #define ICH_FLASH_ERASE_COMMAND_TIMEOUT 3000000
  59. #define ICH_FLASH_LINEAR_ADDR_MASK 0x00FFFFFF
  60. #define ICH_FLASH_CYCLE_REPEAT_COUNT 10
  61. #define ICH_CYCLE_READ 0
  62. #define ICH_CYCLE_WRITE 2
  63. #define ICH_CYCLE_ERASE 3
  64. #define FLASH_GFPREG_BASE_MASK 0x1FFF
  65. #define FLASH_SECTOR_ADDR_SHIFT 12
  66. #define ICH_FLASH_SEG_SIZE_256 256
  67. #define ICH_FLASH_SEG_SIZE_4K 4096
  68. #define ICH_FLASH_SEG_SIZE_8K 8192
  69. #define ICH_FLASH_SEG_SIZE_64K 65536
  70. #define E1000_ICH_FWSM_RSPCIPHY 0x00000040 /* Reset PHY on PCI Reset */
  71. /* FW established a valid mode */
  72. #define E1000_ICH_FWSM_FW_VALID 0x00008000
  73. #define E1000_ICH_MNG_IAMT_MODE 0x2
  74. #define ID_LED_DEFAULT_ICH8LAN ((ID_LED_DEF1_DEF2 << 12) | \
  75. (ID_LED_DEF1_OFF2 << 8) | \
  76. (ID_LED_DEF1_ON2 << 4) | \
  77. (ID_LED_DEF1_DEF2))
  78. #define E1000_ICH_NVM_SIG_WORD 0x13
  79. #define E1000_ICH_NVM_SIG_MASK 0xC000
  80. #define E1000_ICH_NVM_VALID_SIG_MASK 0xC0
  81. #define E1000_ICH_NVM_SIG_VALUE 0x80
  82. #define E1000_ICH8_LAN_INIT_TIMEOUT 1500
  83. #define E1000_FEXTNVM_SW_CONFIG 1
  84. #define E1000_FEXTNVM_SW_CONFIG_ICH8M (1 << 27) /* Bit redefined for ICH8M :/ */
  85. #define E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK 0x0C000000
  86. #define E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC 0x08000000
  87. #define E1000_FEXTNVM4_BEACON_DURATION_MASK 0x7
  88. #define E1000_FEXTNVM4_BEACON_DURATION_8USEC 0x7
  89. #define E1000_FEXTNVM4_BEACON_DURATION_16USEC 0x3
  90. #define PCIE_ICH8_SNOOP_ALL PCIE_NO_SNOOP_ALL
  91. #define E1000_ICH_RAR_ENTRIES 7
  92. #define E1000_PCH2_RAR_ENTRIES 5 /* RAR[0], SHRA[0-3] */
  93. #define E1000_PCH_LPT_RAR_ENTRIES 12 /* RAR[0], SHRA[0-10] */
  94. #define PHY_PAGE_SHIFT 5
  95. #define PHY_REG(page, reg) (((page) << PHY_PAGE_SHIFT) | \
  96. ((reg) & MAX_PHY_REG_ADDRESS))
  97. #define IGP3_KMRN_DIAG PHY_REG(770, 19) /* KMRN Diagnostic */
  98. #define IGP3_VR_CTRL PHY_REG(776, 18) /* Voltage Regulator Control */
  99. #define IGP3_KMRN_DIAG_PCS_LOCK_LOSS 0x0002
  100. #define IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK 0x0300
  101. #define IGP3_VR_CTRL_MODE_SHUTDOWN 0x0200
  102. #define HV_LED_CONFIG PHY_REG(768, 30) /* LED Configuration */
  103. #define SW_FLAG_TIMEOUT 1000 /* SW Semaphore flag timeout in milliseconds */
  104. /* SMBus Control Phy Register */
  105. #define CV_SMB_CTRL PHY_REG(769, 23)
  106. #define CV_SMB_CTRL_FORCE_SMBUS 0x0001
  107. /* SMBus Address Phy Register */
  108. #define HV_SMB_ADDR PHY_REG(768, 26)
  109. #define HV_SMB_ADDR_MASK 0x007F
  110. #define HV_SMB_ADDR_PEC_EN 0x0200
  111. #define HV_SMB_ADDR_VALID 0x0080
  112. #define HV_SMB_ADDR_FREQ_MASK 0x1100
  113. #define HV_SMB_ADDR_FREQ_LOW_SHIFT 8
  114. #define HV_SMB_ADDR_FREQ_HIGH_SHIFT 12
  115. /* PHY Power Management Control */
  116. #define HV_PM_CTRL PHY_REG(770, 17)
  117. #define HV_PM_CTRL_PLL_STOP_IN_K1_GIGA 0x100
  118. /* PHY Low Power Idle Control */
  119. #define I82579_LPI_CTRL PHY_REG(772, 20)
  120. #define I82579_LPI_CTRL_ENABLE_MASK 0x6000
  121. #define I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT 0x80
  122. /* EMI Registers */
  123. #define I82579_EMI_ADDR 0x10
  124. #define I82579_EMI_DATA 0x11
  125. #define I82579_LPI_UPDATE_TIMER 0x4805 /* in 40ns units + 40 ns base value */
  126. #define I82579_MSE_THRESHOLD 0x084F /* Mean Square Error Threshold */
  127. #define I82579_MSE_LINK_DOWN 0x2411 /* MSE count before dropping link */
  128. #define I217_EEE_ADVERTISEMENT 0x8001 /* IEEE MMD Register 7.60 */
  129. #define I217_EEE_LP_ABILITY 0x8002 /* IEEE MMD Register 7.61 */
  130. #define I217_EEE_100_SUPPORTED (1 << 1) /* 100BaseTx EEE supported */
  131. /* Intel Rapid Start Technology Support */
  132. #define I217_PROXY_CTRL BM_PHY_REG(BM_WUC_PAGE, 70)
  133. #define I217_PROXY_CTRL_AUTO_DISABLE 0x0080
  134. #define I217_SxCTRL PHY_REG(BM_PORT_CTRL_PAGE, 28)
  135. #define I217_SxCTRL_ENABLE_LPI_RESET 0x1000
  136. #define I217_CGFREG PHY_REG(772, 29)
  137. #define I217_CGFREG_ENABLE_MTA_RESET 0x0002
  138. #define I217_MEMPWR PHY_REG(772, 26)
  139. #define I217_MEMPWR_DISABLE_SMB_RELEASE 0x0010
  140. /* Strapping Option Register - RO */
  141. #define E1000_STRAP 0x0000C
  142. #define E1000_STRAP_SMBUS_ADDRESS_MASK 0x00FE0000
  143. #define E1000_STRAP_SMBUS_ADDRESS_SHIFT 17
  144. #define E1000_STRAP_SMT_FREQ_MASK 0x00003000
  145. #define E1000_STRAP_SMT_FREQ_SHIFT 12
  146. /* OEM Bits Phy Register */
  147. #define HV_OEM_BITS PHY_REG(768, 25)
  148. #define HV_OEM_BITS_LPLU 0x0004 /* Low Power Link Up */
  149. #define HV_OEM_BITS_GBE_DIS 0x0040 /* Gigabit Disable */
  150. #define HV_OEM_BITS_RESTART_AN 0x0400 /* Restart Auto-negotiation */
  151. #define E1000_NVM_K1_CONFIG 0x1B /* NVM K1 Config Word */
  152. #define E1000_NVM_K1_ENABLE 0x1 /* NVM Enable K1 bit */
  153. /* KMRN Mode Control */
  154. #define HV_KMRN_MODE_CTRL PHY_REG(769, 16)
  155. #define HV_KMRN_MDIO_SLOW 0x0400
  156. /* KMRN FIFO Control and Status */
  157. #define HV_KMRN_FIFO_CTRLSTA PHY_REG(770, 16)
  158. #define HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK 0x7000
  159. #define HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT 12
  160. /* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
  161. /* Offset 04h HSFSTS */
  162. union ich8_hws_flash_status {
  163. struct ich8_hsfsts {
  164. u16 flcdone :1; /* bit 0 Flash Cycle Done */
  165. u16 flcerr :1; /* bit 1 Flash Cycle Error */
  166. u16 dael :1; /* bit 2 Direct Access error Log */
  167. u16 berasesz :2; /* bit 4:3 Sector Erase Size */
  168. u16 flcinprog :1; /* bit 5 flash cycle in Progress */
  169. u16 reserved1 :2; /* bit 13:6 Reserved */
  170. u16 reserved2 :6; /* bit 13:6 Reserved */
  171. u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
  172. u16 flockdn :1; /* bit 15 Flash Config Lock-Down */
  173. } hsf_status;
  174. u16 regval;
  175. };
  176. /* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
  177. /* Offset 06h FLCTL */
  178. union ich8_hws_flash_ctrl {
  179. struct ich8_hsflctl {
  180. u16 flcgo :1; /* 0 Flash Cycle Go */
  181. u16 flcycle :2; /* 2:1 Flash Cycle */
  182. u16 reserved :5; /* 7:3 Reserved */
  183. u16 fldbcount :2; /* 9:8 Flash Data Byte Count */
  184. u16 flockdn :6; /* 15:10 Reserved */
  185. } hsf_ctrl;
  186. u16 regval;
  187. };
  188. /* ICH Flash Region Access Permissions */
  189. union ich8_hws_flash_regacc {
  190. struct ich8_flracc {
  191. u32 grra :8; /* 0:7 GbE region Read Access */
  192. u32 grwa :8; /* 8:15 GbE region Write Access */
  193. u32 gmrag :8; /* 23:16 GbE Master Read Access Grant */
  194. u32 gmwag :8; /* 31:24 GbE Master Write Access Grant */
  195. } hsf_flregacc;
  196. u16 regval;
  197. };
  198. /* ICH Flash Protected Region */
  199. union ich8_flash_protected_range {
  200. struct ich8_pr {
  201. u32 base:13; /* 0:12 Protected Range Base */
  202. u32 reserved1:2; /* 13:14 Reserved */
  203. u32 rpe:1; /* 15 Read Protection Enable */
  204. u32 limit:13; /* 16:28 Protected Range Limit */
  205. u32 reserved2:2; /* 29:30 Reserved */
  206. u32 wpe:1; /* 31 Write Protection Enable */
  207. } range;
  208. u32 regval;
  209. };
  210. static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw);
  211. static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
  212. static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
  213. static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
  214. static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
  215. u32 offset, u8 byte);
  216. static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
  217. u8 *data);
  218. static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
  219. u16 *data);
  220. static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
  221. u8 size, u16 *data);
  222. static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
  223. static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
  224. static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
  225. static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
  226. static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
  227. static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
  228. static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
  229. static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
  230. static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
  231. static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
  232. static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
  233. static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
  234. static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
  235. static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
  236. static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
  237. static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
  238. static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
  239. static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
  240. static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index);
  241. static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index);
  242. static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
  243. static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
  244. static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
  245. {
  246. return readw(hw->flash_address + reg);
  247. }
  248. static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
  249. {
  250. return readl(hw->flash_address + reg);
  251. }
  252. static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
  253. {
  254. writew(val, hw->flash_address + reg);
  255. }
  256. static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
  257. {
  258. writel(val, hw->flash_address + reg);
  259. }
  260. #define er16flash(reg) __er16flash(hw, (reg))
  261. #define er32flash(reg) __er32flash(hw, (reg))
  262. #define ew16flash(reg, val) __ew16flash(hw, (reg), (val))
  263. #define ew32flash(reg, val) __ew32flash(hw, (reg), (val))
  264. /**
  265. * e1000_phy_is_accessible_pchlan - Check if able to access PHY registers
  266. * @hw: pointer to the HW structure
  267. *
  268. * Test access to the PHY registers by reading the PHY ID registers. If
  269. * the PHY ID is already known (e.g. resume path) compare it with known ID,
  270. * otherwise assume the read PHY ID is correct if it is valid.
  271. *
  272. * Assumes the sw/fw/hw semaphore is already acquired.
  273. **/
  274. static bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
  275. {
  276. u16 phy_reg = 0;
  277. u32 phy_id = 0;
  278. s32 ret_val;
  279. u16 retry_count;
  280. for (retry_count = 0; retry_count < 2; retry_count++) {
  281. ret_val = e1e_rphy_locked(hw, PHY_ID1, &phy_reg);
  282. if (ret_val || (phy_reg == 0xFFFF))
  283. continue;
  284. phy_id = (u32)(phy_reg << 16);
  285. ret_val = e1e_rphy_locked(hw, PHY_ID2, &phy_reg);
  286. if (ret_val || (phy_reg == 0xFFFF)) {
  287. phy_id = 0;
  288. continue;
  289. }
  290. phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
  291. break;
  292. }
  293. if (hw->phy.id) {
  294. if (hw->phy.id == phy_id)
  295. return true;
  296. } else if (phy_id) {
  297. hw->phy.id = phy_id;
  298. hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
  299. return true;
  300. }
  301. /* In case the PHY needs to be in mdio slow mode,
  302. * set slow mode and try to get the PHY id again.
  303. */
  304. hw->phy.ops.release(hw);
  305. ret_val = e1000_set_mdio_slow_mode_hv(hw);
  306. if (!ret_val)
  307. ret_val = e1000e_get_phy_id(hw);
  308. hw->phy.ops.acquire(hw);
  309. return !ret_val;
  310. }
  311. /**
  312. * e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
  313. * @hw: pointer to the HW structure
  314. *
  315. * Workarounds/flow necessary for PHY initialization during driver load
  316. * and resume paths.
  317. **/
  318. static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
  319. {
  320. u32 mac_reg, fwsm = er32(FWSM);
  321. s32 ret_val;
  322. u16 phy_reg;
  323. ret_val = hw->phy.ops.acquire(hw);
  324. if (ret_val) {
  325. e_dbg("Failed to initialize PHY flow\n");
  326. return ret_val;
  327. }
  328. /* The MAC-PHY interconnect may be in SMBus mode. If the PHY is
  329. * inaccessible and resetting the PHY is not blocked, toggle the
  330. * LANPHYPC Value bit to force the interconnect to PCIe mode.
  331. */
  332. switch (hw->mac.type) {
  333. case e1000_pch_lpt:
  334. if (e1000_phy_is_accessible_pchlan(hw))
  335. break;
  336. /* Before toggling LANPHYPC, see if PHY is accessible by
  337. * forcing MAC to SMBus mode first.
  338. */
  339. mac_reg = er32(CTRL_EXT);
  340. mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
  341. ew32(CTRL_EXT, mac_reg);
  342. /* fall-through */
  343. case e1000_pch2lan:
  344. /* Gate automatic PHY configuration by hardware on
  345. * non-managed 82579
  346. */
  347. if ((hw->mac.type == e1000_pch2lan) &&
  348. !(fwsm & E1000_ICH_FWSM_FW_VALID))
  349. e1000_gate_hw_phy_config_ich8lan(hw, true);
  350. if (e1000_phy_is_accessible_pchlan(hw)) {
  351. if (hw->mac.type == e1000_pch_lpt) {
  352. /* Unforce SMBus mode in PHY */
  353. e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
  354. phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
  355. e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
  356. /* Unforce SMBus mode in MAC */
  357. mac_reg = er32(CTRL_EXT);
  358. mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
  359. ew32(CTRL_EXT, mac_reg);
  360. }
  361. break;
  362. }
  363. /* fall-through */
  364. case e1000_pchlan:
  365. if ((hw->mac.type == e1000_pchlan) &&
  366. (fwsm & E1000_ICH_FWSM_FW_VALID))
  367. break;
  368. if (hw->phy.ops.check_reset_block(hw)) {
  369. e_dbg("Required LANPHYPC toggle blocked by ME\n");
  370. break;
  371. }
  372. e_dbg("Toggling LANPHYPC\n");
  373. /* Set Phy Config Counter to 50msec */
  374. mac_reg = er32(FEXTNVM3);
  375. mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
  376. mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
  377. ew32(FEXTNVM3, mac_reg);
  378. /* Toggle LANPHYPC Value bit */
  379. mac_reg = er32(CTRL);
  380. mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
  381. mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
  382. ew32(CTRL, mac_reg);
  383. e1e_flush();
  384. udelay(10);
  385. mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
  386. ew32(CTRL, mac_reg);
  387. e1e_flush();
  388. if (hw->mac.type < e1000_pch_lpt) {
  389. msleep(50);
  390. } else {
  391. u16 count = 20;
  392. do {
  393. usleep_range(5000, 10000);
  394. } while (!(er32(CTRL_EXT) &
  395. E1000_CTRL_EXT_LPCD) && count--);
  396. }
  397. break;
  398. default:
  399. break;
  400. }
  401. hw->phy.ops.release(hw);
  402. /* Reset the PHY before any access to it. Doing so, ensures
  403. * that the PHY is in a known good state before we read/write
  404. * PHY registers. The generic reset is sufficient here,
  405. * because we haven't determined the PHY type yet.
  406. */
  407. ret_val = e1000e_phy_hw_reset_generic(hw);
  408. /* Ungate automatic PHY configuration on non-managed 82579 */
  409. if ((hw->mac.type == e1000_pch2lan) &&
  410. !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
  411. usleep_range(10000, 20000);
  412. e1000_gate_hw_phy_config_ich8lan(hw, false);
  413. }
  414. return ret_val;
  415. }
  416. /**
  417. * e1000_init_phy_params_pchlan - Initialize PHY function pointers
  418. * @hw: pointer to the HW structure
  419. *
  420. * Initialize family-specific PHY parameters and function pointers.
  421. **/
  422. static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
  423. {
  424. struct e1000_phy_info *phy = &hw->phy;
  425. s32 ret_val = 0;
  426. phy->addr = 1;
  427. phy->reset_delay_us = 100;
  428. phy->ops.set_page = e1000_set_page_igp;
  429. phy->ops.read_reg = e1000_read_phy_reg_hv;
  430. phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
  431. phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
  432. phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
  433. phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
  434. phy->ops.write_reg = e1000_write_phy_reg_hv;
  435. phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
  436. phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
  437. phy->ops.power_up = e1000_power_up_phy_copper;
  438. phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
  439. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  440. phy->id = e1000_phy_unknown;
  441. ret_val = e1000_init_phy_workarounds_pchlan(hw);
  442. if (ret_val)
  443. return ret_val;
  444. if (phy->id == e1000_phy_unknown)
  445. switch (hw->mac.type) {
  446. default:
  447. ret_val = e1000e_get_phy_id(hw);
  448. if (ret_val)
  449. return ret_val;
  450. if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
  451. break;
  452. /* fall-through */
  453. case e1000_pch2lan:
  454. case e1000_pch_lpt:
  455. /* In case the PHY needs to be in mdio slow mode,
  456. * set slow mode and try to get the PHY id again.
  457. */
  458. ret_val = e1000_set_mdio_slow_mode_hv(hw);
  459. if (ret_val)
  460. return ret_val;
  461. ret_val = e1000e_get_phy_id(hw);
  462. if (ret_val)
  463. return ret_val;
  464. break;
  465. }
  466. phy->type = e1000e_get_phy_type_from_id(phy->id);
  467. switch (phy->type) {
  468. case e1000_phy_82577:
  469. case e1000_phy_82579:
  470. case e1000_phy_i217:
  471. phy->ops.check_polarity = e1000_check_polarity_82577;
  472. phy->ops.force_speed_duplex =
  473. e1000_phy_force_speed_duplex_82577;
  474. phy->ops.get_cable_length = e1000_get_cable_length_82577;
  475. phy->ops.get_info = e1000_get_phy_info_82577;
  476. phy->ops.commit = e1000e_phy_sw_reset;
  477. break;
  478. case e1000_phy_82578:
  479. phy->ops.check_polarity = e1000_check_polarity_m88;
  480. phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
  481. phy->ops.get_cable_length = e1000e_get_cable_length_m88;
  482. phy->ops.get_info = e1000e_get_phy_info_m88;
  483. break;
  484. default:
  485. ret_val = -E1000_ERR_PHY;
  486. break;
  487. }
  488. return ret_val;
  489. }
  490. /**
  491. * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
  492. * @hw: pointer to the HW structure
  493. *
  494. * Initialize family-specific PHY parameters and function pointers.
  495. **/
  496. static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
  497. {
  498. struct e1000_phy_info *phy = &hw->phy;
  499. s32 ret_val;
  500. u16 i = 0;
  501. phy->addr = 1;
  502. phy->reset_delay_us = 100;
  503. phy->ops.power_up = e1000_power_up_phy_copper;
  504. phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
  505. /* We may need to do this twice - once for IGP and if that fails,
  506. * we'll set BM func pointers and try again
  507. */
  508. ret_val = e1000e_determine_phy_address(hw);
  509. if (ret_val) {
  510. phy->ops.write_reg = e1000e_write_phy_reg_bm;
  511. phy->ops.read_reg = e1000e_read_phy_reg_bm;
  512. ret_val = e1000e_determine_phy_address(hw);
  513. if (ret_val) {
  514. e_dbg("Cannot determine PHY addr. Erroring out\n");
  515. return ret_val;
  516. }
  517. }
  518. phy->id = 0;
  519. while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
  520. (i++ < 100)) {
  521. usleep_range(1000, 2000);
  522. ret_val = e1000e_get_phy_id(hw);
  523. if (ret_val)
  524. return ret_val;
  525. }
  526. /* Verify phy id */
  527. switch (phy->id) {
  528. case IGP03E1000_E_PHY_ID:
  529. phy->type = e1000_phy_igp_3;
  530. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  531. phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
  532. phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
  533. phy->ops.get_info = e1000e_get_phy_info_igp;
  534. phy->ops.check_polarity = e1000_check_polarity_igp;
  535. phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
  536. break;
  537. case IFE_E_PHY_ID:
  538. case IFE_PLUS_E_PHY_ID:
  539. case IFE_C_E_PHY_ID:
  540. phy->type = e1000_phy_ife;
  541. phy->autoneg_mask = E1000_ALL_NOT_GIG;
  542. phy->ops.get_info = e1000_get_phy_info_ife;
  543. phy->ops.check_polarity = e1000_check_polarity_ife;
  544. phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
  545. break;
  546. case BME1000_E_PHY_ID:
  547. phy->type = e1000_phy_bm;
  548. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  549. phy->ops.read_reg = e1000e_read_phy_reg_bm;
  550. phy->ops.write_reg = e1000e_write_phy_reg_bm;
  551. phy->ops.commit = e1000e_phy_sw_reset;
  552. phy->ops.get_info = e1000e_get_phy_info_m88;
  553. phy->ops.check_polarity = e1000_check_polarity_m88;
  554. phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
  555. break;
  556. default:
  557. return -E1000_ERR_PHY;
  558. break;
  559. }
  560. return 0;
  561. }
  562. /**
  563. * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
  564. * @hw: pointer to the HW structure
  565. *
  566. * Initialize family-specific NVM parameters and function
  567. * pointers.
  568. **/
  569. static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
  570. {
  571. struct e1000_nvm_info *nvm = &hw->nvm;
  572. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  573. u32 gfpreg, sector_base_addr, sector_end_addr;
  574. u16 i;
  575. /* Can't read flash registers if the register set isn't mapped. */
  576. if (!hw->flash_address) {
  577. e_dbg("ERROR: Flash registers not mapped\n");
  578. return -E1000_ERR_CONFIG;
  579. }
  580. nvm->type = e1000_nvm_flash_sw;
  581. gfpreg = er32flash(ICH_FLASH_GFPREG);
  582. /* sector_X_addr is a "sector"-aligned address (4096 bytes)
  583. * Add 1 to sector_end_addr since this sector is included in
  584. * the overall size.
  585. */
  586. sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
  587. sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
  588. /* flash_base_addr is byte-aligned */
  589. nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
  590. /* find total size of the NVM, then cut in half since the total
  591. * size represents two separate NVM banks.
  592. */
  593. nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
  594. << FLASH_SECTOR_ADDR_SHIFT;
  595. nvm->flash_bank_size /= 2;
  596. /* Adjust to word count */
  597. nvm->flash_bank_size /= sizeof(u16);
  598. nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
  599. /* Clear shadow ram */
  600. for (i = 0; i < nvm->word_size; i++) {
  601. dev_spec->shadow_ram[i].modified = false;
  602. dev_spec->shadow_ram[i].value = 0xFFFF;
  603. }
  604. return 0;
  605. }
  606. /**
  607. * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
  608. * @hw: pointer to the HW structure
  609. *
  610. * Initialize family-specific MAC parameters and function
  611. * pointers.
  612. **/
  613. static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
  614. {
  615. struct e1000_mac_info *mac = &hw->mac;
  616. /* Set media type function pointer */
  617. hw->phy.media_type = e1000_media_type_copper;
  618. /* Set mta register count */
  619. mac->mta_reg_count = 32;
  620. /* Set rar entry count */
  621. mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
  622. if (mac->type == e1000_ich8lan)
  623. mac->rar_entry_count--;
  624. /* FWSM register */
  625. mac->has_fwsm = true;
  626. /* ARC subsystem not supported */
  627. mac->arc_subsystem_valid = false;
  628. /* Adaptive IFS supported */
  629. mac->adaptive_ifs = true;
  630. /* LED and other operations */
  631. switch (mac->type) {
  632. case e1000_ich8lan:
  633. case e1000_ich9lan:
  634. case e1000_ich10lan:
  635. /* check management mode */
  636. mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
  637. /* ID LED init */
  638. mac->ops.id_led_init = e1000e_id_led_init_generic;
  639. /* blink LED */
  640. mac->ops.blink_led = e1000e_blink_led_generic;
  641. /* setup LED */
  642. mac->ops.setup_led = e1000e_setup_led_generic;
  643. /* cleanup LED */
  644. mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
  645. /* turn on/off LED */
  646. mac->ops.led_on = e1000_led_on_ich8lan;
  647. mac->ops.led_off = e1000_led_off_ich8lan;
  648. break;
  649. case e1000_pch2lan:
  650. mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
  651. mac->ops.rar_set = e1000_rar_set_pch2lan;
  652. /* fall-through */
  653. case e1000_pch_lpt:
  654. case e1000_pchlan:
  655. /* check management mode */
  656. mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
  657. /* ID LED init */
  658. mac->ops.id_led_init = e1000_id_led_init_pchlan;
  659. /* setup LED */
  660. mac->ops.setup_led = e1000_setup_led_pchlan;
  661. /* cleanup LED */
  662. mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
  663. /* turn on/off LED */
  664. mac->ops.led_on = e1000_led_on_pchlan;
  665. mac->ops.led_off = e1000_led_off_pchlan;
  666. break;
  667. default:
  668. break;
  669. }
  670. if (mac->type == e1000_pch_lpt) {
  671. mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
  672. mac->ops.rar_set = e1000_rar_set_pch_lpt;
  673. }
  674. /* Enable PCS Lock-loss workaround for ICH8 */
  675. if (mac->type == e1000_ich8lan)
  676. e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
  677. /* Gate automatic PHY configuration by hardware on managed
  678. * 82579 and i217
  679. */
  680. if ((mac->type == e1000_pch2lan || mac->type == e1000_pch_lpt) &&
  681. (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
  682. e1000_gate_hw_phy_config_ich8lan(hw, true);
  683. return 0;
  684. }
  685. /**
  686. * e1000_set_eee_pchlan - Enable/disable EEE support
  687. * @hw: pointer to the HW structure
  688. *
  689. * Enable/disable EEE based on setting in dev_spec structure. The bits in
  690. * the LPI Control register will remain set only if/when link is up.
  691. **/
  692. static s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
  693. {
  694. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  695. s32 ret_val = 0;
  696. u16 phy_reg;
  697. if ((hw->phy.type != e1000_phy_82579) &&
  698. (hw->phy.type != e1000_phy_i217))
  699. return 0;
  700. ret_val = e1e_rphy(hw, I82579_LPI_CTRL, &phy_reg);
  701. if (ret_val)
  702. return ret_val;
  703. if (dev_spec->eee_disable)
  704. phy_reg &= ~I82579_LPI_CTRL_ENABLE_MASK;
  705. else
  706. phy_reg |= I82579_LPI_CTRL_ENABLE_MASK;
  707. ret_val = e1e_wphy(hw, I82579_LPI_CTRL, phy_reg);
  708. if (ret_val)
  709. return ret_val;
  710. if ((hw->phy.type == e1000_phy_i217) && !dev_spec->eee_disable) {
  711. /* Save off link partner's EEE ability */
  712. ret_val = hw->phy.ops.acquire(hw);
  713. if (ret_val)
  714. return ret_val;
  715. ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR,
  716. I217_EEE_LP_ABILITY);
  717. if (ret_val)
  718. goto release;
  719. e1e_rphy_locked(hw, I82579_EMI_DATA, &dev_spec->eee_lp_ability);
  720. /* EEE is not supported in 100Half, so ignore partner's EEE
  721. * in 100 ability if full-duplex is not advertised.
  722. */
  723. e1e_rphy_locked(hw, PHY_LP_ABILITY, &phy_reg);
  724. if (!(phy_reg & NWAY_LPAR_100TX_FD_CAPS))
  725. dev_spec->eee_lp_ability &= ~I217_EEE_100_SUPPORTED;
  726. release:
  727. hw->phy.ops.release(hw);
  728. }
  729. return 0;
  730. }
  731. /**
  732. * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
  733. * @hw: pointer to the HW structure
  734. *
  735. * Checks to see of the link status of the hardware has changed. If a
  736. * change in link status has been detected, then we read the PHY registers
  737. * to get the current speed/duplex if link exists.
  738. **/
  739. static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
  740. {
  741. struct e1000_mac_info *mac = &hw->mac;
  742. s32 ret_val;
  743. bool link;
  744. u16 phy_reg;
  745. /* We only want to go out to the PHY registers to see if Auto-Neg
  746. * has completed and/or if our link status has changed. The
  747. * get_link_status flag is set upon receiving a Link Status
  748. * Change or Rx Sequence Error interrupt.
  749. */
  750. if (!mac->get_link_status)
  751. return 0;
  752. /* First we want to see if the MII Status Register reports
  753. * link. If so, then we want to get the current speed/duplex
  754. * of the PHY.
  755. */
  756. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  757. if (ret_val)
  758. return ret_val;
  759. if (hw->mac.type == e1000_pchlan) {
  760. ret_val = e1000_k1_gig_workaround_hv(hw, link);
  761. if (ret_val)
  762. return ret_val;
  763. }
  764. /* Clear link partner's EEE ability */
  765. hw->dev_spec.ich8lan.eee_lp_ability = 0;
  766. if (!link)
  767. return 0; /* No link detected */
  768. mac->get_link_status = false;
  769. switch (hw->mac.type) {
  770. case e1000_pch2lan:
  771. ret_val = e1000_k1_workaround_lv(hw);
  772. if (ret_val)
  773. return ret_val;
  774. /* fall-thru */
  775. case e1000_pchlan:
  776. if (hw->phy.type == e1000_phy_82578) {
  777. ret_val = e1000_link_stall_workaround_hv(hw);
  778. if (ret_val)
  779. return ret_val;
  780. }
  781. /* Workaround for PCHx parts in half-duplex:
  782. * Set the number of preambles removed from the packet
  783. * when it is passed from the PHY to the MAC to prevent
  784. * the MAC from misinterpreting the packet type.
  785. */
  786. e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
  787. phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
  788. if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
  789. phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
  790. e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
  791. break;
  792. default:
  793. break;
  794. }
  795. /* Check if there was DownShift, must be checked
  796. * immediately after link-up
  797. */
  798. e1000e_check_downshift(hw);
  799. /* Enable/Disable EEE after link up */
  800. ret_val = e1000_set_eee_pchlan(hw);
  801. if (ret_val)
  802. return ret_val;
  803. /* If we are forcing speed/duplex, then we simply return since
  804. * we have already determined whether we have link or not.
  805. */
  806. if (!mac->autoneg)
  807. return -E1000_ERR_CONFIG;
  808. /* Auto-Neg is enabled. Auto Speed Detection takes care
  809. * of MAC speed/duplex configuration. So we only need to
  810. * configure Collision Distance in the MAC.
  811. */
  812. mac->ops.config_collision_dist(hw);
  813. /* Configure Flow Control now that Auto-Neg has completed.
  814. * First, we need to restore the desired flow control
  815. * settings because we may have had to re-autoneg with a
  816. * different link partner.
  817. */
  818. ret_val = e1000e_config_fc_after_link_up(hw);
  819. if (ret_val)
  820. e_dbg("Error configuring flow control\n");
  821. return ret_val;
  822. }
  823. static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
  824. {
  825. struct e1000_hw *hw = &adapter->hw;
  826. s32 rc;
  827. rc = e1000_init_mac_params_ich8lan(hw);
  828. if (rc)
  829. return rc;
  830. rc = e1000_init_nvm_params_ich8lan(hw);
  831. if (rc)
  832. return rc;
  833. switch (hw->mac.type) {
  834. case e1000_ich8lan:
  835. case e1000_ich9lan:
  836. case e1000_ich10lan:
  837. rc = e1000_init_phy_params_ich8lan(hw);
  838. break;
  839. case e1000_pchlan:
  840. case e1000_pch2lan:
  841. case e1000_pch_lpt:
  842. rc = e1000_init_phy_params_pchlan(hw);
  843. break;
  844. default:
  845. break;
  846. }
  847. if (rc)
  848. return rc;
  849. /* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
  850. * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
  851. */
  852. if ((adapter->hw.phy.type == e1000_phy_ife) ||
  853. ((adapter->hw.mac.type >= e1000_pch2lan) &&
  854. (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
  855. adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
  856. adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
  857. hw->mac.ops.blink_led = NULL;
  858. }
  859. if ((adapter->hw.mac.type == e1000_ich8lan) &&
  860. (adapter->hw.phy.type != e1000_phy_ife))
  861. adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
  862. /* Enable workaround for 82579 w/ ME enabled */
  863. if ((adapter->hw.mac.type == e1000_pch2lan) &&
  864. (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
  865. adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
  866. /* Disable EEE by default until IEEE802.3az spec is finalized */
  867. if (adapter->flags2 & FLAG2_HAS_EEE)
  868. adapter->hw.dev_spec.ich8lan.eee_disable = true;
  869. return 0;
  870. }
  871. static DEFINE_MUTEX(nvm_mutex);
  872. /**
  873. * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
  874. * @hw: pointer to the HW structure
  875. *
  876. * Acquires the mutex for performing NVM operations.
  877. **/
  878. static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw)
  879. {
  880. mutex_lock(&nvm_mutex);
  881. return 0;
  882. }
  883. /**
  884. * e1000_release_nvm_ich8lan - Release NVM mutex
  885. * @hw: pointer to the HW structure
  886. *
  887. * Releases the mutex used while performing NVM operations.
  888. **/
  889. static void e1000_release_nvm_ich8lan(struct e1000_hw *hw)
  890. {
  891. mutex_unlock(&nvm_mutex);
  892. }
  893. /**
  894. * e1000_acquire_swflag_ich8lan - Acquire software control flag
  895. * @hw: pointer to the HW structure
  896. *
  897. * Acquires the software control flag for performing PHY and select
  898. * MAC CSR accesses.
  899. **/
  900. static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
  901. {
  902. u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
  903. s32 ret_val = 0;
  904. if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
  905. &hw->adapter->state)) {
  906. e_dbg("contention for Phy access\n");
  907. return -E1000_ERR_PHY;
  908. }
  909. while (timeout) {
  910. extcnf_ctrl = er32(EXTCNF_CTRL);
  911. if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
  912. break;
  913. mdelay(1);
  914. timeout--;
  915. }
  916. if (!timeout) {
  917. e_dbg("SW has already locked the resource.\n");
  918. ret_val = -E1000_ERR_CONFIG;
  919. goto out;
  920. }
  921. timeout = SW_FLAG_TIMEOUT;
  922. extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
  923. ew32(EXTCNF_CTRL, extcnf_ctrl);
  924. while (timeout) {
  925. extcnf_ctrl = er32(EXTCNF_CTRL);
  926. if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
  927. break;
  928. mdelay(1);
  929. timeout--;
  930. }
  931. if (!timeout) {
  932. e_dbg("Failed to acquire the semaphore, FW or HW has it: FWSM=0x%8.8x EXTCNF_CTRL=0x%8.8x)\n",
  933. er32(FWSM), extcnf_ctrl);
  934. extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
  935. ew32(EXTCNF_CTRL, extcnf_ctrl);
  936. ret_val = -E1000_ERR_CONFIG;
  937. goto out;
  938. }
  939. out:
  940. if (ret_val)
  941. clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
  942. return ret_val;
  943. }
  944. /**
  945. * e1000_release_swflag_ich8lan - Release software control flag
  946. * @hw: pointer to the HW structure
  947. *
  948. * Releases the software control flag for performing PHY and select
  949. * MAC CSR accesses.
  950. **/
  951. static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
  952. {
  953. u32 extcnf_ctrl;
  954. extcnf_ctrl = er32(EXTCNF_CTRL);
  955. if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
  956. extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
  957. ew32(EXTCNF_CTRL, extcnf_ctrl);
  958. } else {
  959. e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
  960. }
  961. clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
  962. }
  963. /**
  964. * e1000_check_mng_mode_ich8lan - Checks management mode
  965. * @hw: pointer to the HW structure
  966. *
  967. * This checks if the adapter has any manageability enabled.
  968. * This is a function pointer entry point only called by read/write
  969. * routines for the PHY and NVM parts.
  970. **/
  971. static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
  972. {
  973. u32 fwsm;
  974. fwsm = er32(FWSM);
  975. return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
  976. ((fwsm & E1000_FWSM_MODE_MASK) ==
  977. (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
  978. }
  979. /**
  980. * e1000_check_mng_mode_pchlan - Checks management mode
  981. * @hw: pointer to the HW structure
  982. *
  983. * This checks if the adapter has iAMT enabled.
  984. * This is a function pointer entry point only called by read/write
  985. * routines for the PHY and NVM parts.
  986. **/
  987. static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
  988. {
  989. u32 fwsm;
  990. fwsm = er32(FWSM);
  991. return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
  992. (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
  993. }
  994. /**
  995. * e1000_rar_set_pch2lan - Set receive address register
  996. * @hw: pointer to the HW structure
  997. * @addr: pointer to the receive address
  998. * @index: receive address array register
  999. *
  1000. * Sets the receive address array register at index to the address passed
  1001. * in by addr. For 82579, RAR[0] is the base address register that is to
  1002. * contain the MAC address but RAR[1-6] are reserved for manageability (ME).
  1003. * Use SHRA[0-3] in place of those reserved for ME.
  1004. **/
  1005. static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
  1006. {
  1007. u32 rar_low, rar_high;
  1008. /* HW expects these in little endian so we reverse the byte order
  1009. * from network order (big endian) to little endian
  1010. */
  1011. rar_low = ((u32)addr[0] |
  1012. ((u32)addr[1] << 8) |
  1013. ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
  1014. rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
  1015. /* If MAC address zero, no need to set the AV bit */
  1016. if (rar_low || rar_high)
  1017. rar_high |= E1000_RAH_AV;
  1018. if (index == 0) {
  1019. ew32(RAL(index), rar_low);
  1020. e1e_flush();
  1021. ew32(RAH(index), rar_high);
  1022. e1e_flush();
  1023. return;
  1024. }
  1025. if (index < hw->mac.rar_entry_count) {
  1026. s32 ret_val;
  1027. ret_val = e1000_acquire_swflag_ich8lan(hw);
  1028. if (ret_val)
  1029. goto out;
  1030. ew32(SHRAL(index - 1), rar_low);
  1031. e1e_flush();
  1032. ew32(SHRAH(index - 1), rar_high);
  1033. e1e_flush();
  1034. e1000_release_swflag_ich8lan(hw);
  1035. /* verify the register updates */
  1036. if ((er32(SHRAL(index - 1)) == rar_low) &&
  1037. (er32(SHRAH(index - 1)) == rar_high))
  1038. return;
  1039. e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
  1040. (index - 1), er32(FWSM));
  1041. }
  1042. out:
  1043. e_dbg("Failed to write receive address at index %d\n", index);
  1044. }
  1045. /**
  1046. * e1000_rar_set_pch_lpt - Set receive address registers
  1047. * @hw: pointer to the HW structure
  1048. * @addr: pointer to the receive address
  1049. * @index: receive address array register
  1050. *
  1051. * Sets the receive address register array at index to the address passed
  1052. * in by addr. For LPT, RAR[0] is the base address register that is to
  1053. * contain the MAC address. SHRA[0-10] are the shared receive address
  1054. * registers that are shared between the Host and manageability engine (ME).
  1055. **/
  1056. static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
  1057. {
  1058. u32 rar_low, rar_high;
  1059. u32 wlock_mac;
  1060. /* HW expects these in little endian so we reverse the byte order
  1061. * from network order (big endian) to little endian
  1062. */
  1063. rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
  1064. ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
  1065. rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
  1066. /* If MAC address zero, no need to set the AV bit */
  1067. if (rar_low || rar_high)
  1068. rar_high |= E1000_RAH_AV;
  1069. if (index == 0) {
  1070. ew32(RAL(index), rar_low);
  1071. e1e_flush();
  1072. ew32(RAH(index), rar_high);
  1073. e1e_flush();
  1074. return;
  1075. }
  1076. /* The manageability engine (ME) can lock certain SHRAR registers that
  1077. * it is using - those registers are unavailable for use.
  1078. */
  1079. if (index < hw->mac.rar_entry_count) {
  1080. wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
  1081. wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
  1082. /* Check if all SHRAR registers are locked */
  1083. if (wlock_mac == 1)
  1084. goto out;
  1085. if ((wlock_mac == 0) || (index <= wlock_mac)) {
  1086. s32 ret_val;
  1087. ret_val = e1000_acquire_swflag_ich8lan(hw);
  1088. if (ret_val)
  1089. goto out;
  1090. ew32(SHRAL_PCH_LPT(index - 1), rar_low);
  1091. e1e_flush();
  1092. ew32(SHRAH_PCH_LPT(index - 1), rar_high);
  1093. e1e_flush();
  1094. e1000_release_swflag_ich8lan(hw);
  1095. /* verify the register updates */
  1096. if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
  1097. (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
  1098. return;
  1099. }
  1100. }
  1101. out:
  1102. e_dbg("Failed to write receive address at index %d\n", index);
  1103. }
  1104. /**
  1105. * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
  1106. * @hw: pointer to the HW structure
  1107. *
  1108. * Checks if firmware is blocking the reset of the PHY.
  1109. * This is a function pointer entry point only called by
  1110. * reset routines.
  1111. **/
  1112. static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
  1113. {
  1114. u32 fwsm;
  1115. fwsm = er32(FWSM);
  1116. return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
  1117. }
  1118. /**
  1119. * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
  1120. * @hw: pointer to the HW structure
  1121. *
  1122. * Assumes semaphore already acquired.
  1123. *
  1124. **/
  1125. static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
  1126. {
  1127. u16 phy_data;
  1128. u32 strap = er32(STRAP);
  1129. u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
  1130. E1000_STRAP_SMT_FREQ_SHIFT;
  1131. s32 ret_val = 0;
  1132. strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
  1133. ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
  1134. if (ret_val)
  1135. return ret_val;
  1136. phy_data &= ~HV_SMB_ADDR_MASK;
  1137. phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
  1138. phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
  1139. if (hw->phy.type == e1000_phy_i217) {
  1140. /* Restore SMBus frequency */
  1141. if (freq--) {
  1142. phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
  1143. phy_data |= (freq & (1 << 0)) <<
  1144. HV_SMB_ADDR_FREQ_LOW_SHIFT;
  1145. phy_data |= (freq & (1 << 1)) <<
  1146. (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
  1147. } else {
  1148. e_dbg("Unsupported SMB frequency in PHY\n");
  1149. }
  1150. }
  1151. return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
  1152. }
  1153. /**
  1154. * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
  1155. * @hw: pointer to the HW structure
  1156. *
  1157. * SW should configure the LCD from the NVM extended configuration region
  1158. * as a workaround for certain parts.
  1159. **/
  1160. static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
  1161. {
  1162. struct e1000_phy_info *phy = &hw->phy;
  1163. u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
  1164. s32 ret_val = 0;
  1165. u16 word_addr, reg_data, reg_addr, phy_page = 0;
  1166. /* Initialize the PHY from the NVM on ICH platforms. This
  1167. * is needed due to an issue where the NVM configuration is
  1168. * not properly autoloaded after power transitions.
  1169. * Therefore, after each PHY reset, we will load the
  1170. * configuration data out of the NVM manually.
  1171. */
  1172. switch (hw->mac.type) {
  1173. case e1000_ich8lan:
  1174. if (phy->type != e1000_phy_igp_3)
  1175. return ret_val;
  1176. if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
  1177. (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
  1178. sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
  1179. break;
  1180. }
  1181. /* Fall-thru */
  1182. case e1000_pchlan:
  1183. case e1000_pch2lan:
  1184. case e1000_pch_lpt:
  1185. sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
  1186. break;
  1187. default:
  1188. return ret_val;
  1189. }
  1190. ret_val = hw->phy.ops.acquire(hw);
  1191. if (ret_val)
  1192. return ret_val;
  1193. data = er32(FEXTNVM);
  1194. if (!(data & sw_cfg_mask))
  1195. goto release;
  1196. /* Make sure HW does not configure LCD from PHY
  1197. * extended configuration before SW configuration
  1198. */
  1199. data = er32(EXTCNF_CTRL);
  1200. if ((hw->mac.type < e1000_pch2lan) &&
  1201. (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
  1202. goto release;
  1203. cnf_size = er32(EXTCNF_SIZE);
  1204. cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
  1205. cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
  1206. if (!cnf_size)
  1207. goto release;
  1208. cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
  1209. cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
  1210. if (((hw->mac.type == e1000_pchlan) &&
  1211. !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
  1212. (hw->mac.type > e1000_pchlan)) {
  1213. /* HW configures the SMBus address and LEDs when the
  1214. * OEM and LCD Write Enable bits are set in the NVM.
  1215. * When both NVM bits are cleared, SW will configure
  1216. * them instead.
  1217. */
  1218. ret_val = e1000_write_smbus_addr(hw);
  1219. if (ret_val)
  1220. goto release;
  1221. data = er32(LEDCTL);
  1222. ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
  1223. (u16)data);
  1224. if (ret_val)
  1225. goto release;
  1226. }
  1227. /* Configure LCD from extended configuration region. */
  1228. /* cnf_base_addr is in DWORD */
  1229. word_addr = (u16)(cnf_base_addr << 1);
  1230. for (i = 0; i < cnf_size; i++) {
  1231. ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1,
  1232. &reg_data);
  1233. if (ret_val)
  1234. goto release;
  1235. ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
  1236. 1, &reg_addr);
  1237. if (ret_val)
  1238. goto release;
  1239. /* Save off the PHY page for future writes. */
  1240. if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
  1241. phy_page = reg_data;
  1242. continue;
  1243. }
  1244. reg_addr &= PHY_REG_MASK;
  1245. reg_addr |= phy_page;
  1246. ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
  1247. if (ret_val)
  1248. goto release;
  1249. }
  1250. release:
  1251. hw->phy.ops.release(hw);
  1252. return ret_val;
  1253. }
  1254. /**
  1255. * e1000_k1_gig_workaround_hv - K1 Si workaround
  1256. * @hw: pointer to the HW structure
  1257. * @link: link up bool flag
  1258. *
  1259. * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
  1260. * from a lower speed. This workaround disables K1 whenever link is at 1Gig
  1261. * If link is down, the function will restore the default K1 setting located
  1262. * in the NVM.
  1263. **/
  1264. static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
  1265. {
  1266. s32 ret_val = 0;
  1267. u16 status_reg = 0;
  1268. bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
  1269. if (hw->mac.type != e1000_pchlan)
  1270. return 0;
  1271. /* Wrap the whole flow with the sw flag */
  1272. ret_val = hw->phy.ops.acquire(hw);
  1273. if (ret_val)
  1274. return ret_val;
  1275. /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
  1276. if (link) {
  1277. if (hw->phy.type == e1000_phy_82578) {
  1278. ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
  1279. &status_reg);
  1280. if (ret_val)
  1281. goto release;
  1282. status_reg &= BM_CS_STATUS_LINK_UP |
  1283. BM_CS_STATUS_RESOLVED |
  1284. BM_CS_STATUS_SPEED_MASK;
  1285. if (status_reg == (BM_CS_STATUS_LINK_UP |
  1286. BM_CS_STATUS_RESOLVED |
  1287. BM_CS_STATUS_SPEED_1000))
  1288. k1_enable = false;
  1289. }
  1290. if (hw->phy.type == e1000_phy_82577) {
  1291. ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
  1292. if (ret_val)
  1293. goto release;
  1294. status_reg &= HV_M_STATUS_LINK_UP |
  1295. HV_M_STATUS_AUTONEG_COMPLETE |
  1296. HV_M_STATUS_SPEED_MASK;
  1297. if (status_reg == (HV_M_STATUS_LINK_UP |
  1298. HV_M_STATUS_AUTONEG_COMPLETE |
  1299. HV_M_STATUS_SPEED_1000))
  1300. k1_enable = false;
  1301. }
  1302. /* Link stall fix for link up */
  1303. ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
  1304. if (ret_val)
  1305. goto release;
  1306. } else {
  1307. /* Link stall fix for link down */
  1308. ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
  1309. if (ret_val)
  1310. goto release;
  1311. }
  1312. ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
  1313. release:
  1314. hw->phy.ops.release(hw);
  1315. return ret_val;
  1316. }
  1317. /**
  1318. * e1000_configure_k1_ich8lan - Configure K1 power state
  1319. * @hw: pointer to the HW structure
  1320. * @enable: K1 state to configure
  1321. *
  1322. * Configure the K1 power state based on the provided parameter.
  1323. * Assumes semaphore already acquired.
  1324. *
  1325. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1326. **/
  1327. s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
  1328. {
  1329. s32 ret_val = 0;
  1330. u32 ctrl_reg = 0;
  1331. u32 ctrl_ext = 0;
  1332. u32 reg = 0;
  1333. u16 kmrn_reg = 0;
  1334. ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
  1335. &kmrn_reg);
  1336. if (ret_val)
  1337. return ret_val;
  1338. if (k1_enable)
  1339. kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
  1340. else
  1341. kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
  1342. ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
  1343. kmrn_reg);
  1344. if (ret_val)
  1345. return ret_val;
  1346. udelay(20);
  1347. ctrl_ext = er32(CTRL_EXT);
  1348. ctrl_reg = er32(CTRL);
  1349. reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  1350. reg |= E1000_CTRL_FRCSPD;
  1351. ew32(CTRL, reg);
  1352. ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
  1353. e1e_flush();
  1354. udelay(20);
  1355. ew32(CTRL, ctrl_reg);
  1356. ew32(CTRL_EXT, ctrl_ext);
  1357. e1e_flush();
  1358. udelay(20);
  1359. return 0;
  1360. }
  1361. /**
  1362. * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
  1363. * @hw: pointer to the HW structure
  1364. * @d0_state: boolean if entering d0 or d3 device state
  1365. *
  1366. * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
  1367. * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
  1368. * in NVM determines whether HW should configure LPLU and Gbe Disable.
  1369. **/
  1370. static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
  1371. {
  1372. s32 ret_val = 0;
  1373. u32 mac_reg;
  1374. u16 oem_reg;
  1375. if (hw->mac.type < e1000_pchlan)
  1376. return ret_val;
  1377. ret_val = hw->phy.ops.acquire(hw);
  1378. if (ret_val)
  1379. return ret_val;
  1380. if (hw->mac.type == e1000_pchlan) {
  1381. mac_reg = er32(EXTCNF_CTRL);
  1382. if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
  1383. goto release;
  1384. }
  1385. mac_reg = er32(FEXTNVM);
  1386. if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
  1387. goto release;
  1388. mac_reg = er32(PHY_CTRL);
  1389. ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
  1390. if (ret_val)
  1391. goto release;
  1392. oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
  1393. if (d0_state) {
  1394. if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
  1395. oem_reg |= HV_OEM_BITS_GBE_DIS;
  1396. if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
  1397. oem_reg |= HV_OEM_BITS_LPLU;
  1398. } else {
  1399. if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
  1400. E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
  1401. oem_reg |= HV_OEM_BITS_GBE_DIS;
  1402. if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
  1403. E1000_PHY_CTRL_NOND0A_LPLU))
  1404. oem_reg |= HV_OEM_BITS_LPLU;
  1405. }
  1406. /* Set Restart auto-neg to activate the bits */
  1407. if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
  1408. !hw->phy.ops.check_reset_block(hw))
  1409. oem_reg |= HV_OEM_BITS_RESTART_AN;
  1410. ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
  1411. release:
  1412. hw->phy.ops.release(hw);
  1413. return ret_val;
  1414. }
  1415. /**
  1416. * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
  1417. * @hw: pointer to the HW structure
  1418. **/
  1419. static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
  1420. {
  1421. s32 ret_val;
  1422. u16 data;
  1423. ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
  1424. if (ret_val)
  1425. return ret_val;
  1426. data |= HV_KMRN_MDIO_SLOW;
  1427. ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
  1428. return ret_val;
  1429. }
  1430. /**
  1431. * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
  1432. * done after every PHY reset.
  1433. **/
  1434. static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
  1435. {
  1436. s32 ret_val = 0;
  1437. u16 phy_data;
  1438. if (hw->mac.type != e1000_pchlan)
  1439. return 0;
  1440. /* Set MDIO slow mode before any other MDIO access */
  1441. if (hw->phy.type == e1000_phy_82577) {
  1442. ret_val = e1000_set_mdio_slow_mode_hv(hw);
  1443. if (ret_val)
  1444. return ret_val;
  1445. }
  1446. if (((hw->phy.type == e1000_phy_82577) &&
  1447. ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
  1448. ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
  1449. /* Disable generation of early preamble */
  1450. ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
  1451. if (ret_val)
  1452. return ret_val;
  1453. /* Preamble tuning for SSC */
  1454. ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
  1455. if (ret_val)
  1456. return ret_val;
  1457. }
  1458. if (hw->phy.type == e1000_phy_82578) {
  1459. /* Return registers to default by doing a soft reset then
  1460. * writing 0x3140 to the control register.
  1461. */
  1462. if (hw->phy.revision < 2) {
  1463. e1000e_phy_sw_reset(hw);
  1464. ret_val = e1e_wphy(hw, PHY_CONTROL, 0x3140);
  1465. }
  1466. }
  1467. /* Select page 0 */
  1468. ret_val = hw->phy.ops.acquire(hw);
  1469. if (ret_val)
  1470. return ret_val;
  1471. hw->phy.addr = 1;
  1472. ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
  1473. hw->phy.ops.release(hw);
  1474. if (ret_val)
  1475. return ret_val;
  1476. /* Configure the K1 Si workaround during phy reset assuming there is
  1477. * link so that it disables K1 if link is in 1Gbps.
  1478. */
  1479. ret_val = e1000_k1_gig_workaround_hv(hw, true);
  1480. if (ret_val)
  1481. return ret_val;
  1482. /* Workaround for link disconnects on a busy hub in half duplex */
  1483. ret_val = hw->phy.ops.acquire(hw);
  1484. if (ret_val)
  1485. return ret_val;
  1486. ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
  1487. if (ret_val)
  1488. goto release;
  1489. ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
  1490. release:
  1491. hw->phy.ops.release(hw);
  1492. return ret_val;
  1493. }
  1494. /**
  1495. * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
  1496. * @hw: pointer to the HW structure
  1497. **/
  1498. void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
  1499. {
  1500. u32 mac_reg;
  1501. u16 i, phy_reg = 0;
  1502. s32 ret_val;
  1503. ret_val = hw->phy.ops.acquire(hw);
  1504. if (ret_val)
  1505. return;
  1506. ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
  1507. if (ret_val)
  1508. goto release;
  1509. /* Copy both RAL/H (rar_entry_count) and SHRAL/H (+4) to PHY */
  1510. for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
  1511. mac_reg = er32(RAL(i));
  1512. hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
  1513. (u16)(mac_reg & 0xFFFF));
  1514. hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
  1515. (u16)((mac_reg >> 16) & 0xFFFF));
  1516. mac_reg = er32(RAH(i));
  1517. hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
  1518. (u16)(mac_reg & 0xFFFF));
  1519. hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
  1520. (u16)((mac_reg & E1000_RAH_AV)
  1521. >> 16));
  1522. }
  1523. e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
  1524. release:
  1525. hw->phy.ops.release(hw);
  1526. }
  1527. /**
  1528. * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
  1529. * with 82579 PHY
  1530. * @hw: pointer to the HW structure
  1531. * @enable: flag to enable/disable workaround when enabling/disabling jumbos
  1532. **/
  1533. s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
  1534. {
  1535. s32 ret_val = 0;
  1536. u16 phy_reg, data;
  1537. u32 mac_reg;
  1538. u16 i;
  1539. if (hw->mac.type < e1000_pch2lan)
  1540. return 0;
  1541. /* disable Rx path while enabling/disabling workaround */
  1542. e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
  1543. ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
  1544. if (ret_val)
  1545. return ret_val;
  1546. if (enable) {
  1547. /* Write Rx addresses (rar_entry_count for RAL/H, +4 for
  1548. * SHRAL/H) and initial CRC values to the MAC
  1549. */
  1550. for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
  1551. u8 mac_addr[ETH_ALEN] = {0};
  1552. u32 addr_high, addr_low;
  1553. addr_high = er32(RAH(i));
  1554. if (!(addr_high & E1000_RAH_AV))
  1555. continue;
  1556. addr_low = er32(RAL(i));
  1557. mac_addr[0] = (addr_low & 0xFF);
  1558. mac_addr[1] = ((addr_low >> 8) & 0xFF);
  1559. mac_addr[2] = ((addr_low >> 16) & 0xFF);
  1560. mac_addr[3] = ((addr_low >> 24) & 0xFF);
  1561. mac_addr[4] = (addr_high & 0xFF);
  1562. mac_addr[5] = ((addr_high >> 8) & 0xFF);
  1563. ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
  1564. }
  1565. /* Write Rx addresses to the PHY */
  1566. e1000_copy_rx_addrs_to_phy_ich8lan(hw);
  1567. /* Enable jumbo frame workaround in the MAC */
  1568. mac_reg = er32(FFLT_DBG);
  1569. mac_reg &= ~(1 << 14);
  1570. mac_reg |= (7 << 15);
  1571. ew32(FFLT_DBG, mac_reg);
  1572. mac_reg = er32(RCTL);
  1573. mac_reg |= E1000_RCTL_SECRC;
  1574. ew32(RCTL, mac_reg);
  1575. ret_val = e1000e_read_kmrn_reg(hw,
  1576. E1000_KMRNCTRLSTA_CTRL_OFFSET,
  1577. &data);
  1578. if (ret_val)
  1579. return ret_val;
  1580. ret_val = e1000e_write_kmrn_reg(hw,
  1581. E1000_KMRNCTRLSTA_CTRL_OFFSET,
  1582. data | (1 << 0));
  1583. if (ret_val)
  1584. return ret_val;
  1585. ret_val = e1000e_read_kmrn_reg(hw,
  1586. E1000_KMRNCTRLSTA_HD_CTRL,
  1587. &data);
  1588. if (ret_val)
  1589. return ret_val;
  1590. data &= ~(0xF << 8);
  1591. data |= (0xB << 8);
  1592. ret_val = e1000e_write_kmrn_reg(hw,
  1593. E1000_KMRNCTRLSTA_HD_CTRL,
  1594. data);
  1595. if (ret_val)
  1596. return ret_val;
  1597. /* Enable jumbo frame workaround in the PHY */
  1598. e1e_rphy(hw, PHY_REG(769, 23), &data);
  1599. data &= ~(0x7F << 5);
  1600. data |= (0x37 << 5);
  1601. ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
  1602. if (ret_val)
  1603. return ret_val;
  1604. e1e_rphy(hw, PHY_REG(769, 16), &data);
  1605. data &= ~(1 << 13);
  1606. ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
  1607. if (ret_val)
  1608. return ret_val;
  1609. e1e_rphy(hw, PHY_REG(776, 20), &data);
  1610. data &= ~(0x3FF << 2);
  1611. data |= (0x1A << 2);
  1612. ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
  1613. if (ret_val)
  1614. return ret_val;
  1615. ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
  1616. if (ret_val)
  1617. return ret_val;
  1618. e1e_rphy(hw, HV_PM_CTRL, &data);
  1619. ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
  1620. if (ret_val)
  1621. return ret_val;
  1622. } else {
  1623. /* Write MAC register values back to h/w defaults */
  1624. mac_reg = er32(FFLT_DBG);
  1625. mac_reg &= ~(0xF << 14);
  1626. ew32(FFLT_DBG, mac_reg);
  1627. mac_reg = er32(RCTL);
  1628. mac_reg &= ~E1000_RCTL_SECRC;
  1629. ew32(RCTL, mac_reg);
  1630. ret_val = e1000e_read_kmrn_reg(hw,
  1631. E1000_KMRNCTRLSTA_CTRL_OFFSET,
  1632. &data);
  1633. if (ret_val)
  1634. return ret_val;
  1635. ret_val = e1000e_write_kmrn_reg(hw,
  1636. E1000_KMRNCTRLSTA_CTRL_OFFSET,
  1637. data & ~(1 << 0));
  1638. if (ret_val)
  1639. return ret_val;
  1640. ret_val = e1000e_read_kmrn_reg(hw,
  1641. E1000_KMRNCTRLSTA_HD_CTRL,
  1642. &data);
  1643. if (ret_val)
  1644. return ret_val;
  1645. data &= ~(0xF << 8);
  1646. data |= (0xB << 8);
  1647. ret_val = e1000e_write_kmrn_reg(hw,
  1648. E1000_KMRNCTRLSTA_HD_CTRL,
  1649. data);
  1650. if (ret_val)
  1651. return ret_val;
  1652. /* Write PHY register values back to h/w defaults */
  1653. e1e_rphy(hw, PHY_REG(769, 23), &data);
  1654. data &= ~(0x7F << 5);
  1655. ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
  1656. if (ret_val)
  1657. return ret_val;
  1658. e1e_rphy(hw, PHY_REG(769, 16), &data);
  1659. data |= (1 << 13);
  1660. ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
  1661. if (ret_val)
  1662. return ret_val;
  1663. e1e_rphy(hw, PHY_REG(776, 20), &data);
  1664. data &= ~(0x3FF << 2);
  1665. data |= (0x8 << 2);
  1666. ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
  1667. if (ret_val)
  1668. return ret_val;
  1669. ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
  1670. if (ret_val)
  1671. return ret_val;
  1672. e1e_rphy(hw, HV_PM_CTRL, &data);
  1673. ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
  1674. if (ret_val)
  1675. return ret_val;
  1676. }
  1677. /* re-enable Rx path after enabling/disabling workaround */
  1678. return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
  1679. }
  1680. /**
  1681. * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
  1682. * done after every PHY reset.
  1683. **/
  1684. static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
  1685. {
  1686. s32 ret_val = 0;
  1687. if (hw->mac.type != e1000_pch2lan)
  1688. return 0;
  1689. /* Set MDIO slow mode before any other MDIO access */
  1690. ret_val = e1000_set_mdio_slow_mode_hv(hw);
  1691. ret_val = hw->phy.ops.acquire(hw);
  1692. if (ret_val)
  1693. return ret_val;
  1694. ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, I82579_MSE_THRESHOLD);
  1695. if (ret_val)
  1696. goto release;
  1697. /* set MSE higher to enable link to stay up when noise is high */
  1698. ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, 0x0034);
  1699. if (ret_val)
  1700. goto release;
  1701. ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, I82579_MSE_LINK_DOWN);
  1702. if (ret_val)
  1703. goto release;
  1704. /* drop link after 5 times MSE threshold was reached */
  1705. ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, 0x0005);
  1706. release:
  1707. hw->phy.ops.release(hw);
  1708. return ret_val;
  1709. }
  1710. /**
  1711. * e1000_k1_gig_workaround_lv - K1 Si workaround
  1712. * @hw: pointer to the HW structure
  1713. *
  1714. * Workaround to set the K1 beacon duration for 82579 parts
  1715. **/
  1716. static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
  1717. {
  1718. s32 ret_val = 0;
  1719. u16 status_reg = 0;
  1720. u32 mac_reg;
  1721. u16 phy_reg;
  1722. if (hw->mac.type != e1000_pch2lan)
  1723. return 0;
  1724. /* Set K1 beacon duration based on 1Gbps speed or otherwise */
  1725. ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
  1726. if (ret_val)
  1727. return ret_val;
  1728. if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
  1729. == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
  1730. mac_reg = er32(FEXTNVM4);
  1731. mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
  1732. ret_val = e1e_rphy(hw, I82579_LPI_CTRL, &phy_reg);
  1733. if (ret_val)
  1734. return ret_val;
  1735. if (status_reg & HV_M_STATUS_SPEED_1000) {
  1736. u16 pm_phy_reg;
  1737. mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
  1738. phy_reg &= ~I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
  1739. /* LV 1G Packet drop issue wa */
  1740. ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
  1741. if (ret_val)
  1742. return ret_val;
  1743. pm_phy_reg &= ~HV_PM_CTRL_PLL_STOP_IN_K1_GIGA;
  1744. ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
  1745. if (ret_val)
  1746. return ret_val;
  1747. } else {
  1748. mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
  1749. phy_reg |= I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
  1750. }
  1751. ew32(FEXTNVM4, mac_reg);
  1752. ret_val = e1e_wphy(hw, I82579_LPI_CTRL, phy_reg);
  1753. }
  1754. return ret_val;
  1755. }
  1756. /**
  1757. * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
  1758. * @hw: pointer to the HW structure
  1759. * @gate: boolean set to true to gate, false to ungate
  1760. *
  1761. * Gate/ungate the automatic PHY configuration via hardware; perform
  1762. * the configuration via software instead.
  1763. **/
  1764. static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
  1765. {
  1766. u32 extcnf_ctrl;
  1767. if (hw->mac.type < e1000_pch2lan)
  1768. return;
  1769. extcnf_ctrl = er32(EXTCNF_CTRL);
  1770. if (gate)
  1771. extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
  1772. else
  1773. extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
  1774. ew32(EXTCNF_CTRL, extcnf_ctrl);
  1775. }
  1776. /**
  1777. * e1000_lan_init_done_ich8lan - Check for PHY config completion
  1778. * @hw: pointer to the HW structure
  1779. *
  1780. * Check the appropriate indication the MAC has finished configuring the
  1781. * PHY after a software reset.
  1782. **/
  1783. static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
  1784. {
  1785. u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
  1786. /* Wait for basic configuration completes before proceeding */
  1787. do {
  1788. data = er32(STATUS);
  1789. data &= E1000_STATUS_LAN_INIT_DONE;
  1790. udelay(100);
  1791. } while ((!data) && --loop);
  1792. /* If basic configuration is incomplete before the above loop
  1793. * count reaches 0, loading the configuration from NVM will
  1794. * leave the PHY in a bad state possibly resulting in no link.
  1795. */
  1796. if (loop == 0)
  1797. e_dbg("LAN_INIT_DONE not set, increase timeout\n");
  1798. /* Clear the Init Done bit for the next init event */
  1799. data = er32(STATUS);
  1800. data &= ~E1000_STATUS_LAN_INIT_DONE;
  1801. ew32(STATUS, data);
  1802. }
  1803. /**
  1804. * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
  1805. * @hw: pointer to the HW structure
  1806. **/
  1807. static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
  1808. {
  1809. s32 ret_val = 0;
  1810. u16 reg;
  1811. if (hw->phy.ops.check_reset_block(hw))
  1812. return 0;
  1813. /* Allow time for h/w to get to quiescent state after reset */
  1814. usleep_range(10000, 20000);
  1815. /* Perform any necessary post-reset workarounds */
  1816. switch (hw->mac.type) {
  1817. case e1000_pchlan:
  1818. ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
  1819. if (ret_val)
  1820. return ret_val;
  1821. break;
  1822. case e1000_pch2lan:
  1823. ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
  1824. if (ret_val)
  1825. return ret_val;
  1826. break;
  1827. default:
  1828. break;
  1829. }
  1830. /* Clear the host wakeup bit after lcd reset */
  1831. if (hw->mac.type >= e1000_pchlan) {
  1832. e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
  1833. reg &= ~BM_WUC_HOST_WU_BIT;
  1834. e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
  1835. }
  1836. /* Configure the LCD with the extended configuration region in NVM */
  1837. ret_val = e1000_sw_lcd_config_ich8lan(hw);
  1838. if (ret_val)
  1839. return ret_val;
  1840. /* Configure the LCD with the OEM bits in NVM */
  1841. ret_val = e1000_oem_bits_config_ich8lan(hw, true);
  1842. if (hw->mac.type == e1000_pch2lan) {
  1843. /* Ungate automatic PHY configuration on non-managed 82579 */
  1844. if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
  1845. usleep_range(10000, 20000);
  1846. e1000_gate_hw_phy_config_ich8lan(hw, false);
  1847. }
  1848. /* Set EEE LPI Update Timer to 200usec */
  1849. ret_val = hw->phy.ops.acquire(hw);
  1850. if (ret_val)
  1851. return ret_val;
  1852. ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR,
  1853. I82579_LPI_UPDATE_TIMER);
  1854. if (!ret_val)
  1855. ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, 0x1387);
  1856. hw->phy.ops.release(hw);
  1857. }
  1858. return ret_val;
  1859. }
  1860. /**
  1861. * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
  1862. * @hw: pointer to the HW structure
  1863. *
  1864. * Resets the PHY
  1865. * This is a function pointer entry point called by drivers
  1866. * or other shared routines.
  1867. **/
  1868. static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
  1869. {
  1870. s32 ret_val = 0;
  1871. /* Gate automatic PHY configuration by hardware on non-managed 82579 */
  1872. if ((hw->mac.type == e1000_pch2lan) &&
  1873. !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
  1874. e1000_gate_hw_phy_config_ich8lan(hw, true);
  1875. ret_val = e1000e_phy_hw_reset_generic(hw);
  1876. if (ret_val)
  1877. return ret_val;
  1878. return e1000_post_phy_reset_ich8lan(hw);
  1879. }
  1880. /**
  1881. * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
  1882. * @hw: pointer to the HW structure
  1883. * @active: true to enable LPLU, false to disable
  1884. *
  1885. * Sets the LPLU state according to the active flag. For PCH, if OEM write
  1886. * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
  1887. * the phy speed. This function will manually set the LPLU bit and restart
  1888. * auto-neg as hw would do. D3 and D0 LPLU will call the same function
  1889. * since it configures the same bit.
  1890. **/
  1891. static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
  1892. {
  1893. s32 ret_val = 0;
  1894. u16 oem_reg;
  1895. ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
  1896. if (ret_val)
  1897. return ret_val;
  1898. if (active)
  1899. oem_reg |= HV_OEM_BITS_LPLU;
  1900. else
  1901. oem_reg &= ~HV_OEM_BITS_LPLU;
  1902. if (!hw->phy.ops.check_reset_block(hw))
  1903. oem_reg |= HV_OEM_BITS_RESTART_AN;
  1904. return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
  1905. }
  1906. /**
  1907. * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
  1908. * @hw: pointer to the HW structure
  1909. * @active: true to enable LPLU, false to disable
  1910. *
  1911. * Sets the LPLU D0 state according to the active flag. When
  1912. * activating LPLU this function also disables smart speed
  1913. * and vice versa. LPLU will not be activated unless the
  1914. * device autonegotiation advertisement meets standards of
  1915. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  1916. * This is a function pointer entry point only called by
  1917. * PHY setup routines.
  1918. **/
  1919. static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
  1920. {
  1921. struct e1000_phy_info *phy = &hw->phy;
  1922. u32 phy_ctrl;
  1923. s32 ret_val = 0;
  1924. u16 data;
  1925. if (phy->type == e1000_phy_ife)
  1926. return 0;
  1927. phy_ctrl = er32(PHY_CTRL);
  1928. if (active) {
  1929. phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
  1930. ew32(PHY_CTRL, phy_ctrl);
  1931. if (phy->type != e1000_phy_igp_3)
  1932. return 0;
  1933. /* Call gig speed drop workaround on LPLU before accessing
  1934. * any PHY registers
  1935. */
  1936. if (hw->mac.type == e1000_ich8lan)
  1937. e1000e_gig_downshift_workaround_ich8lan(hw);
  1938. /* When LPLU is enabled, we should disable SmartSpeed */
  1939. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
  1940. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1941. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
  1942. if (ret_val)
  1943. return ret_val;
  1944. } else {
  1945. phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
  1946. ew32(PHY_CTRL, phy_ctrl);
  1947. if (phy->type != e1000_phy_igp_3)
  1948. return 0;
  1949. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  1950. * during Dx states where the power conservation is most
  1951. * important. During driver activity we should enable
  1952. * SmartSpeed, so performance is maintained.
  1953. */
  1954. if (phy->smart_speed == e1000_smart_speed_on) {
  1955. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1956. &data);
  1957. if (ret_val)
  1958. return ret_val;
  1959. data |= IGP01E1000_PSCFR_SMART_SPEED;
  1960. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1961. data);
  1962. if (ret_val)
  1963. return ret_val;
  1964. } else if (phy->smart_speed == e1000_smart_speed_off) {
  1965. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1966. &data);
  1967. if (ret_val)
  1968. return ret_val;
  1969. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1970. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1971. data);
  1972. if (ret_val)
  1973. return ret_val;
  1974. }
  1975. }
  1976. return 0;
  1977. }
  1978. /**
  1979. * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
  1980. * @hw: pointer to the HW structure
  1981. * @active: true to enable LPLU, false to disable
  1982. *
  1983. * Sets the LPLU D3 state according to the active flag. When
  1984. * activating LPLU this function also disables smart speed
  1985. * and vice versa. LPLU will not be activated unless the
  1986. * device autonegotiation advertisement meets standards of
  1987. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  1988. * This is a function pointer entry point only called by
  1989. * PHY setup routines.
  1990. **/
  1991. static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
  1992. {
  1993. struct e1000_phy_info *phy = &hw->phy;
  1994. u32 phy_ctrl;
  1995. s32 ret_val = 0;
  1996. u16 data;
  1997. phy_ctrl = er32(PHY_CTRL);
  1998. if (!active) {
  1999. phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
  2000. ew32(PHY_CTRL, phy_ctrl);
  2001. if (phy->type != e1000_phy_igp_3)
  2002. return 0;
  2003. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  2004. * during Dx states where the power conservation is most
  2005. * important. During driver activity we should enable
  2006. * SmartSpeed, so performance is maintained.
  2007. */
  2008. if (phy->smart_speed == e1000_smart_speed_on) {
  2009. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2010. &data);
  2011. if (ret_val)
  2012. return ret_val;
  2013. data |= IGP01E1000_PSCFR_SMART_SPEED;
  2014. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2015. data);
  2016. if (ret_val)
  2017. return ret_val;
  2018. } else if (phy->smart_speed == e1000_smart_speed_off) {
  2019. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2020. &data);
  2021. if (ret_val)
  2022. return ret_val;
  2023. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2024. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2025. data);
  2026. if (ret_val)
  2027. return ret_val;
  2028. }
  2029. } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
  2030. (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
  2031. (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
  2032. phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
  2033. ew32(PHY_CTRL, phy_ctrl);
  2034. if (phy->type != e1000_phy_igp_3)
  2035. return 0;
  2036. /* Call gig speed drop workaround on LPLU before accessing
  2037. * any PHY registers
  2038. */
  2039. if (hw->mac.type == e1000_ich8lan)
  2040. e1000e_gig_downshift_workaround_ich8lan(hw);
  2041. /* When LPLU is enabled, we should disable SmartSpeed */
  2042. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
  2043. if (ret_val)
  2044. return ret_val;
  2045. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2046. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
  2047. }
  2048. return ret_val;
  2049. }
  2050. /**
  2051. * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
  2052. * @hw: pointer to the HW structure
  2053. * @bank: pointer to the variable that returns the active bank
  2054. *
  2055. * Reads signature byte from the NVM using the flash access registers.
  2056. * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
  2057. **/
  2058. static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
  2059. {
  2060. u32 eecd;
  2061. struct e1000_nvm_info *nvm = &hw->nvm;
  2062. u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
  2063. u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
  2064. u8 sig_byte = 0;
  2065. s32 ret_val;
  2066. switch (hw->mac.type) {
  2067. case e1000_ich8lan:
  2068. case e1000_ich9lan:
  2069. eecd = er32(EECD);
  2070. if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
  2071. E1000_EECD_SEC1VAL_VALID_MASK) {
  2072. if (eecd & E1000_EECD_SEC1VAL)
  2073. *bank = 1;
  2074. else
  2075. *bank = 0;
  2076. return 0;
  2077. }
  2078. e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
  2079. /* fall-thru */
  2080. default:
  2081. /* set bank to 0 in case flash read fails */
  2082. *bank = 0;
  2083. /* Check bank 0 */
  2084. ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
  2085. &sig_byte);
  2086. if (ret_val)
  2087. return ret_val;
  2088. if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
  2089. E1000_ICH_NVM_SIG_VALUE) {
  2090. *bank = 0;
  2091. return 0;
  2092. }
  2093. /* Check bank 1 */
  2094. ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
  2095. bank1_offset,
  2096. &sig_byte);
  2097. if (ret_val)
  2098. return ret_val;
  2099. if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
  2100. E1000_ICH_NVM_SIG_VALUE) {
  2101. *bank = 1;
  2102. return 0;
  2103. }
  2104. e_dbg("ERROR: No valid NVM bank present\n");
  2105. return -E1000_ERR_NVM;
  2106. }
  2107. }
  2108. /**
  2109. * e1000_read_nvm_ich8lan - Read word(s) from the NVM
  2110. * @hw: pointer to the HW structure
  2111. * @offset: The offset (in bytes) of the word(s) to read.
  2112. * @words: Size of data to read in words
  2113. * @data: Pointer to the word(s) to read at offset.
  2114. *
  2115. * Reads a word(s) from the NVM using the flash access registers.
  2116. **/
  2117. static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
  2118. u16 *data)
  2119. {
  2120. struct e1000_nvm_info *nvm = &hw->nvm;
  2121. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  2122. u32 act_offset;
  2123. s32 ret_val = 0;
  2124. u32 bank = 0;
  2125. u16 i, word;
  2126. if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
  2127. (words == 0)) {
  2128. e_dbg("nvm parameter(s) out of bounds\n");
  2129. ret_val = -E1000_ERR_NVM;
  2130. goto out;
  2131. }
  2132. nvm->ops.acquire(hw);
  2133. ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
  2134. if (ret_val) {
  2135. e_dbg("Could not detect valid bank, assuming bank 0\n");
  2136. bank = 0;
  2137. }
  2138. act_offset = (bank) ? nvm->flash_bank_size : 0;
  2139. act_offset += offset;
  2140. ret_val = 0;
  2141. for (i = 0; i < words; i++) {
  2142. if (dev_spec->shadow_ram[offset+i].modified) {
  2143. data[i] = dev_spec->shadow_ram[offset+i].value;
  2144. } else {
  2145. ret_val = e1000_read_flash_word_ich8lan(hw,
  2146. act_offset + i,
  2147. &word);
  2148. if (ret_val)
  2149. break;
  2150. data[i] = word;
  2151. }
  2152. }
  2153. nvm->ops.release(hw);
  2154. out:
  2155. if (ret_val)
  2156. e_dbg("NVM read error: %d\n", ret_val);
  2157. return ret_val;
  2158. }
  2159. /**
  2160. * e1000_flash_cycle_init_ich8lan - Initialize flash
  2161. * @hw: pointer to the HW structure
  2162. *
  2163. * This function does initial flash setup so that a new read/write/erase cycle
  2164. * can be started.
  2165. **/
  2166. static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
  2167. {
  2168. union ich8_hws_flash_status hsfsts;
  2169. s32 ret_val = -E1000_ERR_NVM;
  2170. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2171. /* Check if the flash descriptor is valid */
  2172. if (!hsfsts.hsf_status.fldesvalid) {
  2173. e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
  2174. return -E1000_ERR_NVM;
  2175. }
  2176. /* Clear FCERR and DAEL in hw status by writing 1 */
  2177. hsfsts.hsf_status.flcerr = 1;
  2178. hsfsts.hsf_status.dael = 1;
  2179. ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  2180. /* Either we should have a hardware SPI cycle in progress
  2181. * bit to check against, in order to start a new cycle or
  2182. * FDONE bit should be changed in the hardware so that it
  2183. * is 1 after hardware reset, which can then be used as an
  2184. * indication whether a cycle is in progress or has been
  2185. * completed.
  2186. */
  2187. if (!hsfsts.hsf_status.flcinprog) {
  2188. /* There is no cycle running at present,
  2189. * so we can start a cycle.
  2190. * Begin by setting Flash Cycle Done.
  2191. */
  2192. hsfsts.hsf_status.flcdone = 1;
  2193. ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  2194. ret_val = 0;
  2195. } else {
  2196. s32 i;
  2197. /* Otherwise poll for sometime so the current
  2198. * cycle has a chance to end before giving up.
  2199. */
  2200. for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
  2201. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2202. if (!hsfsts.hsf_status.flcinprog) {
  2203. ret_val = 0;
  2204. break;
  2205. }
  2206. udelay(1);
  2207. }
  2208. if (!ret_val) {
  2209. /* Successful in waiting for previous cycle to timeout,
  2210. * now set the Flash Cycle Done.
  2211. */
  2212. hsfsts.hsf_status.flcdone = 1;
  2213. ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  2214. } else {
  2215. e_dbg("Flash controller busy, cannot get access\n");
  2216. }
  2217. }
  2218. return ret_val;
  2219. }
  2220. /**
  2221. * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
  2222. * @hw: pointer to the HW structure
  2223. * @timeout: maximum time to wait for completion
  2224. *
  2225. * This function starts a flash cycle and waits for its completion.
  2226. **/
  2227. static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
  2228. {
  2229. union ich8_hws_flash_ctrl hsflctl;
  2230. union ich8_hws_flash_status hsfsts;
  2231. u32 i = 0;
  2232. /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
  2233. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  2234. hsflctl.hsf_ctrl.flcgo = 1;
  2235. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  2236. /* wait till FDONE bit is set to 1 */
  2237. do {
  2238. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2239. if (hsfsts.hsf_status.flcdone)
  2240. break;
  2241. udelay(1);
  2242. } while (i++ < timeout);
  2243. if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
  2244. return 0;
  2245. return -E1000_ERR_NVM;
  2246. }
  2247. /**
  2248. * e1000_read_flash_word_ich8lan - Read word from flash
  2249. * @hw: pointer to the HW structure
  2250. * @offset: offset to data location
  2251. * @data: pointer to the location for storing the data
  2252. *
  2253. * Reads the flash word at offset into data. Offset is converted
  2254. * to bytes before read.
  2255. **/
  2256. static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
  2257. u16 *data)
  2258. {
  2259. /* Must convert offset into bytes. */
  2260. offset <<= 1;
  2261. return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
  2262. }
  2263. /**
  2264. * e1000_read_flash_byte_ich8lan - Read byte from flash
  2265. * @hw: pointer to the HW structure
  2266. * @offset: The offset of the byte to read.
  2267. * @data: Pointer to a byte to store the value read.
  2268. *
  2269. * Reads a single byte from the NVM using the flash access registers.
  2270. **/
  2271. static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
  2272. u8 *data)
  2273. {
  2274. s32 ret_val;
  2275. u16 word = 0;
  2276. ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
  2277. if (ret_val)
  2278. return ret_val;
  2279. *data = (u8)word;
  2280. return 0;
  2281. }
  2282. /**
  2283. * e1000_read_flash_data_ich8lan - Read byte or word from NVM
  2284. * @hw: pointer to the HW structure
  2285. * @offset: The offset (in bytes) of the byte or word to read.
  2286. * @size: Size of data to read, 1=byte 2=word
  2287. * @data: Pointer to the word to store the value read.
  2288. *
  2289. * Reads a byte or word from the NVM using the flash access registers.
  2290. **/
  2291. static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
  2292. u8 size, u16 *data)
  2293. {
  2294. union ich8_hws_flash_status hsfsts;
  2295. union ich8_hws_flash_ctrl hsflctl;
  2296. u32 flash_linear_addr;
  2297. u32 flash_data = 0;
  2298. s32 ret_val = -E1000_ERR_NVM;
  2299. u8 count = 0;
  2300. if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
  2301. return -E1000_ERR_NVM;
  2302. flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
  2303. hw->nvm.flash_base_addr;
  2304. do {
  2305. udelay(1);
  2306. /* Steps */
  2307. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  2308. if (ret_val)
  2309. break;
  2310. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  2311. /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
  2312. hsflctl.hsf_ctrl.fldbcount = size - 1;
  2313. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
  2314. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  2315. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  2316. ret_val = e1000_flash_cycle_ich8lan(hw,
  2317. ICH_FLASH_READ_COMMAND_TIMEOUT);
  2318. /* Check if FCERR is set to 1, if set to 1, clear it
  2319. * and try the whole sequence a few more times, else
  2320. * read in (shift in) the Flash Data0, the order is
  2321. * least significant byte first msb to lsb
  2322. */
  2323. if (!ret_val) {
  2324. flash_data = er32flash(ICH_FLASH_FDATA0);
  2325. if (size == 1)
  2326. *data = (u8)(flash_data & 0x000000FF);
  2327. else if (size == 2)
  2328. *data = (u16)(flash_data & 0x0000FFFF);
  2329. break;
  2330. } else {
  2331. /* If we've gotten here, then things are probably
  2332. * completely hosed, but if the error condition is
  2333. * detected, it won't hurt to give it another try...
  2334. * ICH_FLASH_CYCLE_REPEAT_COUNT times.
  2335. */
  2336. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2337. if (hsfsts.hsf_status.flcerr) {
  2338. /* Repeat for some time before giving up. */
  2339. continue;
  2340. } else if (!hsfsts.hsf_status.flcdone) {
  2341. e_dbg("Timeout error - flash cycle did not complete.\n");
  2342. break;
  2343. }
  2344. }
  2345. } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
  2346. return ret_val;
  2347. }
  2348. /**
  2349. * e1000_write_nvm_ich8lan - Write word(s) to the NVM
  2350. * @hw: pointer to the HW structure
  2351. * @offset: The offset (in bytes) of the word(s) to write.
  2352. * @words: Size of data to write in words
  2353. * @data: Pointer to the word(s) to write at offset.
  2354. *
  2355. * Writes a byte or word to the NVM using the flash access registers.
  2356. **/
  2357. static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
  2358. u16 *data)
  2359. {
  2360. struct e1000_nvm_info *nvm = &hw->nvm;
  2361. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  2362. u16 i;
  2363. if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
  2364. (words == 0)) {
  2365. e_dbg("nvm parameter(s) out of bounds\n");
  2366. return -E1000_ERR_NVM;
  2367. }
  2368. nvm->ops.acquire(hw);
  2369. for (i = 0; i < words; i++) {
  2370. dev_spec->shadow_ram[offset+i].modified = true;
  2371. dev_spec->shadow_ram[offset+i].value = data[i];
  2372. }
  2373. nvm->ops.release(hw);
  2374. return 0;
  2375. }
  2376. /**
  2377. * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
  2378. * @hw: pointer to the HW structure
  2379. *
  2380. * The NVM checksum is updated by calling the generic update_nvm_checksum,
  2381. * which writes the checksum to the shadow ram. The changes in the shadow
  2382. * ram are then committed to the EEPROM by processing each bank at a time
  2383. * checking for the modified bit and writing only the pending changes.
  2384. * After a successful commit, the shadow ram is cleared and is ready for
  2385. * future writes.
  2386. **/
  2387. static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
  2388. {
  2389. struct e1000_nvm_info *nvm = &hw->nvm;
  2390. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  2391. u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
  2392. s32 ret_val;
  2393. u16 data;
  2394. ret_val = e1000e_update_nvm_checksum_generic(hw);
  2395. if (ret_val)
  2396. goto out;
  2397. if (nvm->type != e1000_nvm_flash_sw)
  2398. goto out;
  2399. nvm->ops.acquire(hw);
  2400. /* We're writing to the opposite bank so if we're on bank 1,
  2401. * write to bank 0 etc. We also need to erase the segment that
  2402. * is going to be written
  2403. */
  2404. ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
  2405. if (ret_val) {
  2406. e_dbg("Could not detect valid bank, assuming bank 0\n");
  2407. bank = 0;
  2408. }
  2409. if (bank == 0) {
  2410. new_bank_offset = nvm->flash_bank_size;
  2411. old_bank_offset = 0;
  2412. ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
  2413. if (ret_val)
  2414. goto release;
  2415. } else {
  2416. old_bank_offset = nvm->flash_bank_size;
  2417. new_bank_offset = 0;
  2418. ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
  2419. if (ret_val)
  2420. goto release;
  2421. }
  2422. for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
  2423. /* Determine whether to write the value stored
  2424. * in the other NVM bank or a modified value stored
  2425. * in the shadow RAM
  2426. */
  2427. if (dev_spec->shadow_ram[i].modified) {
  2428. data = dev_spec->shadow_ram[i].value;
  2429. } else {
  2430. ret_val = e1000_read_flash_word_ich8lan(hw, i +
  2431. old_bank_offset,
  2432. &data);
  2433. if (ret_val)
  2434. break;
  2435. }
  2436. /* If the word is 0x13, then make sure the signature bits
  2437. * (15:14) are 11b until the commit has completed.
  2438. * This will allow us to write 10b which indicates the
  2439. * signature is valid. We want to do this after the write
  2440. * has completed so that we don't mark the segment valid
  2441. * while the write is still in progress
  2442. */
  2443. if (i == E1000_ICH_NVM_SIG_WORD)
  2444. data |= E1000_ICH_NVM_SIG_MASK;
  2445. /* Convert offset to bytes. */
  2446. act_offset = (i + new_bank_offset) << 1;
  2447. udelay(100);
  2448. /* Write the bytes to the new bank. */
  2449. ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
  2450. act_offset,
  2451. (u8)data);
  2452. if (ret_val)
  2453. break;
  2454. udelay(100);
  2455. ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
  2456. act_offset + 1,
  2457. (u8)(data >> 8));
  2458. if (ret_val)
  2459. break;
  2460. }
  2461. /* Don't bother writing the segment valid bits if sector
  2462. * programming failed.
  2463. */
  2464. if (ret_val) {
  2465. /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
  2466. e_dbg("Flash commit failed.\n");
  2467. goto release;
  2468. }
  2469. /* Finally validate the new segment by setting bit 15:14
  2470. * to 10b in word 0x13 , this can be done without an
  2471. * erase as well since these bits are 11 to start with
  2472. * and we need to change bit 14 to 0b
  2473. */
  2474. act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
  2475. ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
  2476. if (ret_val)
  2477. goto release;
  2478. data &= 0xBFFF;
  2479. ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
  2480. act_offset * 2 + 1,
  2481. (u8)(data >> 8));
  2482. if (ret_val)
  2483. goto release;
  2484. /* And invalidate the previously valid segment by setting
  2485. * its signature word (0x13) high_byte to 0b. This can be
  2486. * done without an erase because flash erase sets all bits
  2487. * to 1's. We can write 1's to 0's without an erase
  2488. */
  2489. act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
  2490. ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
  2491. if (ret_val)
  2492. goto release;
  2493. /* Great! Everything worked, we can now clear the cached entries. */
  2494. for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
  2495. dev_spec->shadow_ram[i].modified = false;
  2496. dev_spec->shadow_ram[i].value = 0xFFFF;
  2497. }
  2498. release:
  2499. nvm->ops.release(hw);
  2500. /* Reload the EEPROM, or else modifications will not appear
  2501. * until after the next adapter reset.
  2502. */
  2503. if (!ret_val) {
  2504. nvm->ops.reload(hw);
  2505. usleep_range(10000, 20000);
  2506. }
  2507. out:
  2508. if (ret_val)
  2509. e_dbg("NVM update error: %d\n", ret_val);
  2510. return ret_val;
  2511. }
  2512. /**
  2513. * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
  2514. * @hw: pointer to the HW structure
  2515. *
  2516. * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
  2517. * If the bit is 0, that the EEPROM had been modified, but the checksum was not
  2518. * calculated, in which case we need to calculate the checksum and set bit 6.
  2519. **/
  2520. static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
  2521. {
  2522. s32 ret_val;
  2523. u16 data;
  2524. /* Read 0x19 and check bit 6. If this bit is 0, the checksum
  2525. * needs to be fixed. This bit is an indication that the NVM
  2526. * was prepared by OEM software and did not calculate the
  2527. * checksum...a likely scenario.
  2528. */
  2529. ret_val = e1000_read_nvm(hw, 0x19, 1, &data);
  2530. if (ret_val)
  2531. return ret_val;
  2532. if (!(data & 0x40)) {
  2533. data |= 0x40;
  2534. ret_val = e1000_write_nvm(hw, 0x19, 1, &data);
  2535. if (ret_val)
  2536. return ret_val;
  2537. ret_val = e1000e_update_nvm_checksum(hw);
  2538. if (ret_val)
  2539. return ret_val;
  2540. }
  2541. return e1000e_validate_nvm_checksum_generic(hw);
  2542. }
  2543. /**
  2544. * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
  2545. * @hw: pointer to the HW structure
  2546. *
  2547. * To prevent malicious write/erase of the NVM, set it to be read-only
  2548. * so that the hardware ignores all write/erase cycles of the NVM via
  2549. * the flash control registers. The shadow-ram copy of the NVM will
  2550. * still be updated, however any updates to this copy will not stick
  2551. * across driver reloads.
  2552. **/
  2553. void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
  2554. {
  2555. struct e1000_nvm_info *nvm = &hw->nvm;
  2556. union ich8_flash_protected_range pr0;
  2557. union ich8_hws_flash_status hsfsts;
  2558. u32 gfpreg;
  2559. nvm->ops.acquire(hw);
  2560. gfpreg = er32flash(ICH_FLASH_GFPREG);
  2561. /* Write-protect GbE Sector of NVM */
  2562. pr0.regval = er32flash(ICH_FLASH_PR0);
  2563. pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
  2564. pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
  2565. pr0.range.wpe = true;
  2566. ew32flash(ICH_FLASH_PR0, pr0.regval);
  2567. /* Lock down a subset of GbE Flash Control Registers, e.g.
  2568. * PR0 to prevent the write-protection from being lifted.
  2569. * Once FLOCKDN is set, the registers protected by it cannot
  2570. * be written until FLOCKDN is cleared by a hardware reset.
  2571. */
  2572. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2573. hsfsts.hsf_status.flockdn = true;
  2574. ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  2575. nvm->ops.release(hw);
  2576. }
  2577. /**
  2578. * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
  2579. * @hw: pointer to the HW structure
  2580. * @offset: The offset (in bytes) of the byte/word to read.
  2581. * @size: Size of data to read, 1=byte 2=word
  2582. * @data: The byte(s) to write to the NVM.
  2583. *
  2584. * Writes one/two bytes to the NVM using the flash access registers.
  2585. **/
  2586. static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
  2587. u8 size, u16 data)
  2588. {
  2589. union ich8_hws_flash_status hsfsts;
  2590. union ich8_hws_flash_ctrl hsflctl;
  2591. u32 flash_linear_addr;
  2592. u32 flash_data = 0;
  2593. s32 ret_val;
  2594. u8 count = 0;
  2595. if (size < 1 || size > 2 || data > size * 0xff ||
  2596. offset > ICH_FLASH_LINEAR_ADDR_MASK)
  2597. return -E1000_ERR_NVM;
  2598. flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
  2599. hw->nvm.flash_base_addr;
  2600. do {
  2601. udelay(1);
  2602. /* Steps */
  2603. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  2604. if (ret_val)
  2605. break;
  2606. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  2607. /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
  2608. hsflctl.hsf_ctrl.fldbcount = size -1;
  2609. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
  2610. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  2611. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  2612. if (size == 1)
  2613. flash_data = (u32)data & 0x00FF;
  2614. else
  2615. flash_data = (u32)data;
  2616. ew32flash(ICH_FLASH_FDATA0, flash_data);
  2617. /* check if FCERR is set to 1 , if set to 1, clear it
  2618. * and try the whole sequence a few more times else done
  2619. */
  2620. ret_val = e1000_flash_cycle_ich8lan(hw,
  2621. ICH_FLASH_WRITE_COMMAND_TIMEOUT);
  2622. if (!ret_val)
  2623. break;
  2624. /* If we're here, then things are most likely
  2625. * completely hosed, but if the error condition
  2626. * is detected, it won't hurt to give it another
  2627. * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
  2628. */
  2629. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2630. if (hsfsts.hsf_status.flcerr)
  2631. /* Repeat for some time before giving up. */
  2632. continue;
  2633. if (!hsfsts.hsf_status.flcdone) {
  2634. e_dbg("Timeout error - flash cycle did not complete.\n");
  2635. break;
  2636. }
  2637. } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
  2638. return ret_val;
  2639. }
  2640. /**
  2641. * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
  2642. * @hw: pointer to the HW structure
  2643. * @offset: The index of the byte to read.
  2644. * @data: The byte to write to the NVM.
  2645. *
  2646. * Writes a single byte to the NVM using the flash access registers.
  2647. **/
  2648. static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
  2649. u8 data)
  2650. {
  2651. u16 word = (u16)data;
  2652. return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
  2653. }
  2654. /**
  2655. * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
  2656. * @hw: pointer to the HW structure
  2657. * @offset: The offset of the byte to write.
  2658. * @byte: The byte to write to the NVM.
  2659. *
  2660. * Writes a single byte to the NVM using the flash access registers.
  2661. * Goes through a retry algorithm before giving up.
  2662. **/
  2663. static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
  2664. u32 offset, u8 byte)
  2665. {
  2666. s32 ret_val;
  2667. u16 program_retries;
  2668. ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
  2669. if (!ret_val)
  2670. return ret_val;
  2671. for (program_retries = 0; program_retries < 100; program_retries++) {
  2672. e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
  2673. udelay(100);
  2674. ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
  2675. if (!ret_val)
  2676. break;
  2677. }
  2678. if (program_retries == 100)
  2679. return -E1000_ERR_NVM;
  2680. return 0;
  2681. }
  2682. /**
  2683. * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
  2684. * @hw: pointer to the HW structure
  2685. * @bank: 0 for first bank, 1 for second bank, etc.
  2686. *
  2687. * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
  2688. * bank N is 4096 * N + flash_reg_addr.
  2689. **/
  2690. static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
  2691. {
  2692. struct e1000_nvm_info *nvm = &hw->nvm;
  2693. union ich8_hws_flash_status hsfsts;
  2694. union ich8_hws_flash_ctrl hsflctl;
  2695. u32 flash_linear_addr;
  2696. /* bank size is in 16bit words - adjust to bytes */
  2697. u32 flash_bank_size = nvm->flash_bank_size * 2;
  2698. s32 ret_val;
  2699. s32 count = 0;
  2700. s32 j, iteration, sector_size;
  2701. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2702. /* Determine HW Sector size: Read BERASE bits of hw flash status
  2703. * register
  2704. * 00: The Hw sector is 256 bytes, hence we need to erase 16
  2705. * consecutive sectors. The start index for the nth Hw sector
  2706. * can be calculated as = bank * 4096 + n * 256
  2707. * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
  2708. * The start index for the nth Hw sector can be calculated
  2709. * as = bank * 4096
  2710. * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
  2711. * (ich9 only, otherwise error condition)
  2712. * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
  2713. */
  2714. switch (hsfsts.hsf_status.berasesz) {
  2715. case 0:
  2716. /* Hw sector size 256 */
  2717. sector_size = ICH_FLASH_SEG_SIZE_256;
  2718. iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
  2719. break;
  2720. case 1:
  2721. sector_size = ICH_FLASH_SEG_SIZE_4K;
  2722. iteration = 1;
  2723. break;
  2724. case 2:
  2725. sector_size = ICH_FLASH_SEG_SIZE_8K;
  2726. iteration = 1;
  2727. break;
  2728. case 3:
  2729. sector_size = ICH_FLASH_SEG_SIZE_64K;
  2730. iteration = 1;
  2731. break;
  2732. default:
  2733. return -E1000_ERR_NVM;
  2734. }
  2735. /* Start with the base address, then add the sector offset. */
  2736. flash_linear_addr = hw->nvm.flash_base_addr;
  2737. flash_linear_addr += (bank) ? flash_bank_size : 0;
  2738. for (j = 0; j < iteration ; j++) {
  2739. do {
  2740. /* Steps */
  2741. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  2742. if (ret_val)
  2743. return ret_val;
  2744. /* Write a value 11 (block Erase) in Flash
  2745. * Cycle field in hw flash control
  2746. */
  2747. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  2748. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
  2749. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  2750. /* Write the last 24 bits of an index within the
  2751. * block into Flash Linear address field in Flash
  2752. * Address.
  2753. */
  2754. flash_linear_addr += (j * sector_size);
  2755. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  2756. ret_val = e1000_flash_cycle_ich8lan(hw,
  2757. ICH_FLASH_ERASE_COMMAND_TIMEOUT);
  2758. if (!ret_val)
  2759. break;
  2760. /* Check if FCERR is set to 1. If 1,
  2761. * clear it and try the whole sequence
  2762. * a few more times else Done
  2763. */
  2764. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2765. if (hsfsts.hsf_status.flcerr)
  2766. /* repeat for some time before giving up */
  2767. continue;
  2768. else if (!hsfsts.hsf_status.flcdone)
  2769. return ret_val;
  2770. } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
  2771. }
  2772. return 0;
  2773. }
  2774. /**
  2775. * e1000_valid_led_default_ich8lan - Set the default LED settings
  2776. * @hw: pointer to the HW structure
  2777. * @data: Pointer to the LED settings
  2778. *
  2779. * Reads the LED default settings from the NVM to data. If the NVM LED
  2780. * settings is all 0's or F's, set the LED default to a valid LED default
  2781. * setting.
  2782. **/
  2783. static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
  2784. {
  2785. s32 ret_val;
  2786. ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
  2787. if (ret_val) {
  2788. e_dbg("NVM Read Error\n");
  2789. return ret_val;
  2790. }
  2791. if (*data == ID_LED_RESERVED_0000 ||
  2792. *data == ID_LED_RESERVED_FFFF)
  2793. *data = ID_LED_DEFAULT_ICH8LAN;
  2794. return 0;
  2795. }
  2796. /**
  2797. * e1000_id_led_init_pchlan - store LED configurations
  2798. * @hw: pointer to the HW structure
  2799. *
  2800. * PCH does not control LEDs via the LEDCTL register, rather it uses
  2801. * the PHY LED configuration register.
  2802. *
  2803. * PCH also does not have an "always on" or "always off" mode which
  2804. * complicates the ID feature. Instead of using the "on" mode to indicate
  2805. * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
  2806. * use "link_up" mode. The LEDs will still ID on request if there is no
  2807. * link based on logic in e1000_led_[on|off]_pchlan().
  2808. **/
  2809. static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
  2810. {
  2811. struct e1000_mac_info *mac = &hw->mac;
  2812. s32 ret_val;
  2813. const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
  2814. const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
  2815. u16 data, i, temp, shift;
  2816. /* Get default ID LED modes */
  2817. ret_val = hw->nvm.ops.valid_led_default(hw, &data);
  2818. if (ret_val)
  2819. return ret_val;
  2820. mac->ledctl_default = er32(LEDCTL);
  2821. mac->ledctl_mode1 = mac->ledctl_default;
  2822. mac->ledctl_mode2 = mac->ledctl_default;
  2823. for (i = 0; i < 4; i++) {
  2824. temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
  2825. shift = (i * 5);
  2826. switch (temp) {
  2827. case ID_LED_ON1_DEF2:
  2828. case ID_LED_ON1_ON2:
  2829. case ID_LED_ON1_OFF2:
  2830. mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
  2831. mac->ledctl_mode1 |= (ledctl_on << shift);
  2832. break;
  2833. case ID_LED_OFF1_DEF2:
  2834. case ID_LED_OFF1_ON2:
  2835. case ID_LED_OFF1_OFF2:
  2836. mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
  2837. mac->ledctl_mode1 |= (ledctl_off << shift);
  2838. break;
  2839. default:
  2840. /* Do nothing */
  2841. break;
  2842. }
  2843. switch (temp) {
  2844. case ID_LED_DEF1_ON2:
  2845. case ID_LED_ON1_ON2:
  2846. case ID_LED_OFF1_ON2:
  2847. mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
  2848. mac->ledctl_mode2 |= (ledctl_on << shift);
  2849. break;
  2850. case ID_LED_DEF1_OFF2:
  2851. case ID_LED_ON1_OFF2:
  2852. case ID_LED_OFF1_OFF2:
  2853. mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
  2854. mac->ledctl_mode2 |= (ledctl_off << shift);
  2855. break;
  2856. default:
  2857. /* Do nothing */
  2858. break;
  2859. }
  2860. }
  2861. return 0;
  2862. }
  2863. /**
  2864. * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
  2865. * @hw: pointer to the HW structure
  2866. *
  2867. * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
  2868. * register, so the the bus width is hard coded.
  2869. **/
  2870. static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
  2871. {
  2872. struct e1000_bus_info *bus = &hw->bus;
  2873. s32 ret_val;
  2874. ret_val = e1000e_get_bus_info_pcie(hw);
  2875. /* ICH devices are "PCI Express"-ish. They have
  2876. * a configuration space, but do not contain
  2877. * PCI Express Capability registers, so bus width
  2878. * must be hardcoded.
  2879. */
  2880. if (bus->width == e1000_bus_width_unknown)
  2881. bus->width = e1000_bus_width_pcie_x1;
  2882. return ret_val;
  2883. }
  2884. /**
  2885. * e1000_reset_hw_ich8lan - Reset the hardware
  2886. * @hw: pointer to the HW structure
  2887. *
  2888. * Does a full reset of the hardware which includes a reset of the PHY and
  2889. * MAC.
  2890. **/
  2891. static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
  2892. {
  2893. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  2894. u16 kum_cfg;
  2895. u32 ctrl, reg;
  2896. s32 ret_val;
  2897. /* Prevent the PCI-E bus from sticking if there is no TLP connection
  2898. * on the last TLP read/write transaction when MAC is reset.
  2899. */
  2900. ret_val = e1000e_disable_pcie_master(hw);
  2901. if (ret_val)
  2902. e_dbg("PCI-E Master disable polling has failed.\n");
  2903. e_dbg("Masking off all interrupts\n");
  2904. ew32(IMC, 0xffffffff);
  2905. /* Disable the Transmit and Receive units. Then delay to allow
  2906. * any pending transactions to complete before we hit the MAC
  2907. * with the global reset.
  2908. */
  2909. ew32(RCTL, 0);
  2910. ew32(TCTL, E1000_TCTL_PSP);
  2911. e1e_flush();
  2912. usleep_range(10000, 20000);
  2913. /* Workaround for ICH8 bit corruption issue in FIFO memory */
  2914. if (hw->mac.type == e1000_ich8lan) {
  2915. /* Set Tx and Rx buffer allocation to 8k apiece. */
  2916. ew32(PBA, E1000_PBA_8K);
  2917. /* Set Packet Buffer Size to 16k. */
  2918. ew32(PBS, E1000_PBS_16K);
  2919. }
  2920. if (hw->mac.type == e1000_pchlan) {
  2921. /* Save the NVM K1 bit setting */
  2922. ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
  2923. if (ret_val)
  2924. return ret_val;
  2925. if (kum_cfg & E1000_NVM_K1_ENABLE)
  2926. dev_spec->nvm_k1_enabled = true;
  2927. else
  2928. dev_spec->nvm_k1_enabled = false;
  2929. }
  2930. ctrl = er32(CTRL);
  2931. if (!hw->phy.ops.check_reset_block(hw)) {
  2932. /* Full-chip reset requires MAC and PHY reset at the same
  2933. * time to make sure the interface between MAC and the
  2934. * external PHY is reset.
  2935. */
  2936. ctrl |= E1000_CTRL_PHY_RST;
  2937. /* Gate automatic PHY configuration by hardware on
  2938. * non-managed 82579
  2939. */
  2940. if ((hw->mac.type == e1000_pch2lan) &&
  2941. !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
  2942. e1000_gate_hw_phy_config_ich8lan(hw, true);
  2943. }
  2944. ret_val = e1000_acquire_swflag_ich8lan(hw);
  2945. e_dbg("Issuing a global reset to ich8lan\n");
  2946. ew32(CTRL, (ctrl | E1000_CTRL_RST));
  2947. /* cannot issue a flush here because it hangs the hardware */
  2948. msleep(20);
  2949. /* Set Phy Config Counter to 50msec */
  2950. if (hw->mac.type == e1000_pch2lan) {
  2951. reg = er32(FEXTNVM3);
  2952. reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
  2953. reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
  2954. ew32(FEXTNVM3, reg);
  2955. }
  2956. if (!ret_val)
  2957. clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
  2958. if (ctrl & E1000_CTRL_PHY_RST) {
  2959. ret_val = hw->phy.ops.get_cfg_done(hw);
  2960. if (ret_val)
  2961. return ret_val;
  2962. ret_val = e1000_post_phy_reset_ich8lan(hw);
  2963. if (ret_val)
  2964. return ret_val;
  2965. }
  2966. /* For PCH, this write will make sure that any noise
  2967. * will be detected as a CRC error and be dropped rather than show up
  2968. * as a bad packet to the DMA engine.
  2969. */
  2970. if (hw->mac.type == e1000_pchlan)
  2971. ew32(CRC_OFFSET, 0x65656565);
  2972. ew32(IMC, 0xffffffff);
  2973. er32(ICR);
  2974. reg = er32(KABGTXD);
  2975. reg |= E1000_KABGTXD_BGSQLBIAS;
  2976. ew32(KABGTXD, reg);
  2977. return 0;
  2978. }
  2979. /**
  2980. * e1000_init_hw_ich8lan - Initialize the hardware
  2981. * @hw: pointer to the HW structure
  2982. *
  2983. * Prepares the hardware for transmit and receive by doing the following:
  2984. * - initialize hardware bits
  2985. * - initialize LED identification
  2986. * - setup receive address registers
  2987. * - setup flow control
  2988. * - setup transmit descriptors
  2989. * - clear statistics
  2990. **/
  2991. static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
  2992. {
  2993. struct e1000_mac_info *mac = &hw->mac;
  2994. u32 ctrl_ext, txdctl, snoop;
  2995. s32 ret_val;
  2996. u16 i;
  2997. e1000_initialize_hw_bits_ich8lan(hw);
  2998. /* Initialize identification LED */
  2999. ret_val = mac->ops.id_led_init(hw);
  3000. if (ret_val)
  3001. e_dbg("Error initializing identification LED\n");
  3002. /* This is not fatal and we should not stop init due to this */
  3003. /* Setup the receive address. */
  3004. e1000e_init_rx_addrs(hw, mac->rar_entry_count);
  3005. /* Zero out the Multicast HASH table */
  3006. e_dbg("Zeroing the MTA\n");
  3007. for (i = 0; i < mac->mta_reg_count; i++)
  3008. E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
  3009. /* The 82578 Rx buffer will stall if wakeup is enabled in host and
  3010. * the ME. Disable wakeup by clearing the host wakeup bit.
  3011. * Reset the phy after disabling host wakeup to reset the Rx buffer.
  3012. */
  3013. if (hw->phy.type == e1000_phy_82578) {
  3014. e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
  3015. i &= ~BM_WUC_HOST_WU_BIT;
  3016. e1e_wphy(hw, BM_PORT_GEN_CFG, i);
  3017. ret_val = e1000_phy_hw_reset_ich8lan(hw);
  3018. if (ret_val)
  3019. return ret_val;
  3020. }
  3021. /* Setup link and flow control */
  3022. ret_val = mac->ops.setup_link(hw);
  3023. /* Set the transmit descriptor write-back policy for both queues */
  3024. txdctl = er32(TXDCTL(0));
  3025. txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
  3026. E1000_TXDCTL_FULL_TX_DESC_WB;
  3027. txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
  3028. E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
  3029. ew32(TXDCTL(0), txdctl);
  3030. txdctl = er32(TXDCTL(1));
  3031. txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
  3032. E1000_TXDCTL_FULL_TX_DESC_WB;
  3033. txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
  3034. E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
  3035. ew32(TXDCTL(1), txdctl);
  3036. /* ICH8 has opposite polarity of no_snoop bits.
  3037. * By default, we should use snoop behavior.
  3038. */
  3039. if (mac->type == e1000_ich8lan)
  3040. snoop = PCIE_ICH8_SNOOP_ALL;
  3041. else
  3042. snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
  3043. e1000e_set_pcie_no_snoop(hw, snoop);
  3044. ctrl_ext = er32(CTRL_EXT);
  3045. ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
  3046. ew32(CTRL_EXT, ctrl_ext);
  3047. /* Clear all of the statistics registers (clear on read). It is
  3048. * important that we do this after we have tried to establish link
  3049. * because the symbol error count will increment wildly if there
  3050. * is no link.
  3051. */
  3052. e1000_clear_hw_cntrs_ich8lan(hw);
  3053. return ret_val;
  3054. }
  3055. /**
  3056. * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
  3057. * @hw: pointer to the HW structure
  3058. *
  3059. * Sets/Clears required hardware bits necessary for correctly setting up the
  3060. * hardware for transmit and receive.
  3061. **/
  3062. static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
  3063. {
  3064. u32 reg;
  3065. /* Extended Device Control */
  3066. reg = er32(CTRL_EXT);
  3067. reg |= (1 << 22);
  3068. /* Enable PHY low-power state when MAC is at D3 w/o WoL */
  3069. if (hw->mac.type >= e1000_pchlan)
  3070. reg |= E1000_CTRL_EXT_PHYPDEN;
  3071. ew32(CTRL_EXT, reg);
  3072. /* Transmit Descriptor Control 0 */
  3073. reg = er32(TXDCTL(0));
  3074. reg |= (1 << 22);
  3075. ew32(TXDCTL(0), reg);
  3076. /* Transmit Descriptor Control 1 */
  3077. reg = er32(TXDCTL(1));
  3078. reg |= (1 << 22);
  3079. ew32(TXDCTL(1), reg);
  3080. /* Transmit Arbitration Control 0 */
  3081. reg = er32(TARC(0));
  3082. if (hw->mac.type == e1000_ich8lan)
  3083. reg |= (1 << 28) | (1 << 29);
  3084. reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
  3085. ew32(TARC(0), reg);
  3086. /* Transmit Arbitration Control 1 */
  3087. reg = er32(TARC(1));
  3088. if (er32(TCTL) & E1000_TCTL_MULR)
  3089. reg &= ~(1 << 28);
  3090. else
  3091. reg |= (1 << 28);
  3092. reg |= (1 << 24) | (1 << 26) | (1 << 30);
  3093. ew32(TARC(1), reg);
  3094. /* Device Status */
  3095. if (hw->mac.type == e1000_ich8lan) {
  3096. reg = er32(STATUS);
  3097. reg &= ~(1 << 31);
  3098. ew32(STATUS, reg);
  3099. }
  3100. /* work-around descriptor data corruption issue during nfs v2 udp
  3101. * traffic, just disable the nfs filtering capability
  3102. */
  3103. reg = er32(RFCTL);
  3104. reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
  3105. /* Disable IPv6 extension header parsing because some malformed
  3106. * IPv6 headers can hang the Rx.
  3107. */
  3108. if (hw->mac.type == e1000_ich8lan)
  3109. reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
  3110. ew32(RFCTL, reg);
  3111. }
  3112. /**
  3113. * e1000_setup_link_ich8lan - Setup flow control and link settings
  3114. * @hw: pointer to the HW structure
  3115. *
  3116. * Determines which flow control settings to use, then configures flow
  3117. * control. Calls the appropriate media-specific link configuration
  3118. * function. Assuming the adapter has a valid link partner, a valid link
  3119. * should be established. Assumes the hardware has previously been reset
  3120. * and the transmitter and receiver are not enabled.
  3121. **/
  3122. static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
  3123. {
  3124. s32 ret_val;
  3125. if (hw->phy.ops.check_reset_block(hw))
  3126. return 0;
  3127. /* ICH parts do not have a word in the NVM to determine
  3128. * the default flow control setting, so we explicitly
  3129. * set it to full.
  3130. */
  3131. if (hw->fc.requested_mode == e1000_fc_default) {
  3132. /* Workaround h/w hang when Tx flow control enabled */
  3133. if (hw->mac.type == e1000_pchlan)
  3134. hw->fc.requested_mode = e1000_fc_rx_pause;
  3135. else
  3136. hw->fc.requested_mode = e1000_fc_full;
  3137. }
  3138. /* Save off the requested flow control mode for use later. Depending
  3139. * on the link partner's capabilities, we may or may not use this mode.
  3140. */
  3141. hw->fc.current_mode = hw->fc.requested_mode;
  3142. e_dbg("After fix-ups FlowControl is now = %x\n",
  3143. hw->fc.current_mode);
  3144. /* Continue to configure the copper link. */
  3145. ret_val = hw->mac.ops.setup_physical_interface(hw);
  3146. if (ret_val)
  3147. return ret_val;
  3148. ew32(FCTTV, hw->fc.pause_time);
  3149. if ((hw->phy.type == e1000_phy_82578) ||
  3150. (hw->phy.type == e1000_phy_82579) ||
  3151. (hw->phy.type == e1000_phy_i217) ||
  3152. (hw->phy.type == e1000_phy_82577)) {
  3153. ew32(FCRTV_PCH, hw->fc.refresh_time);
  3154. ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
  3155. hw->fc.pause_time);
  3156. if (ret_val)
  3157. return ret_val;
  3158. }
  3159. return e1000e_set_fc_watermarks(hw);
  3160. }
  3161. /**
  3162. * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
  3163. * @hw: pointer to the HW structure
  3164. *
  3165. * Configures the kumeran interface to the PHY to wait the appropriate time
  3166. * when polling the PHY, then call the generic setup_copper_link to finish
  3167. * configuring the copper link.
  3168. **/
  3169. static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
  3170. {
  3171. u32 ctrl;
  3172. s32 ret_val;
  3173. u16 reg_data;
  3174. ctrl = er32(CTRL);
  3175. ctrl |= E1000_CTRL_SLU;
  3176. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  3177. ew32(CTRL, ctrl);
  3178. /* Set the mac to wait the maximum time between each iteration
  3179. * and increase the max iterations when polling the phy;
  3180. * this fixes erroneous timeouts at 10Mbps.
  3181. */
  3182. ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
  3183. if (ret_val)
  3184. return ret_val;
  3185. ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
  3186. &reg_data);
  3187. if (ret_val)
  3188. return ret_val;
  3189. reg_data |= 0x3F;
  3190. ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
  3191. reg_data);
  3192. if (ret_val)
  3193. return ret_val;
  3194. switch (hw->phy.type) {
  3195. case e1000_phy_igp_3:
  3196. ret_val = e1000e_copper_link_setup_igp(hw);
  3197. if (ret_val)
  3198. return ret_val;
  3199. break;
  3200. case e1000_phy_bm:
  3201. case e1000_phy_82578:
  3202. ret_val = e1000e_copper_link_setup_m88(hw);
  3203. if (ret_val)
  3204. return ret_val;
  3205. break;
  3206. case e1000_phy_82577:
  3207. case e1000_phy_82579:
  3208. case e1000_phy_i217:
  3209. ret_val = e1000_copper_link_setup_82577(hw);
  3210. if (ret_val)
  3211. return ret_val;
  3212. break;
  3213. case e1000_phy_ife:
  3214. ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
  3215. if (ret_val)
  3216. return ret_val;
  3217. reg_data &= ~IFE_PMC_AUTO_MDIX;
  3218. switch (hw->phy.mdix) {
  3219. case 1:
  3220. reg_data &= ~IFE_PMC_FORCE_MDIX;
  3221. break;
  3222. case 2:
  3223. reg_data |= IFE_PMC_FORCE_MDIX;
  3224. break;
  3225. case 0:
  3226. default:
  3227. reg_data |= IFE_PMC_AUTO_MDIX;
  3228. break;
  3229. }
  3230. ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
  3231. if (ret_val)
  3232. return ret_val;
  3233. break;
  3234. default:
  3235. break;
  3236. }
  3237. return e1000e_setup_copper_link(hw);
  3238. }
  3239. /**
  3240. * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
  3241. * @hw: pointer to the HW structure
  3242. * @speed: pointer to store current link speed
  3243. * @duplex: pointer to store the current link duplex
  3244. *
  3245. * Calls the generic get_speed_and_duplex to retrieve the current link
  3246. * information and then calls the Kumeran lock loss workaround for links at
  3247. * gigabit speeds.
  3248. **/
  3249. static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
  3250. u16 *duplex)
  3251. {
  3252. s32 ret_val;
  3253. ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
  3254. if (ret_val)
  3255. return ret_val;
  3256. if ((hw->mac.type == e1000_ich8lan) &&
  3257. (hw->phy.type == e1000_phy_igp_3) &&
  3258. (*speed == SPEED_1000)) {
  3259. ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
  3260. }
  3261. return ret_val;
  3262. }
  3263. /**
  3264. * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
  3265. * @hw: pointer to the HW structure
  3266. *
  3267. * Work-around for 82566 Kumeran PCS lock loss:
  3268. * On link status change (i.e. PCI reset, speed change) and link is up and
  3269. * speed is gigabit-
  3270. * 0) if workaround is optionally disabled do nothing
  3271. * 1) wait 1ms for Kumeran link to come up
  3272. * 2) check Kumeran Diagnostic register PCS lock loss bit
  3273. * 3) if not set the link is locked (all is good), otherwise...
  3274. * 4) reset the PHY
  3275. * 5) repeat up to 10 times
  3276. * Note: this is only called for IGP3 copper when speed is 1gb.
  3277. **/
  3278. static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
  3279. {
  3280. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  3281. u32 phy_ctrl;
  3282. s32 ret_val;
  3283. u16 i, data;
  3284. bool link;
  3285. if (!dev_spec->kmrn_lock_loss_workaround_enabled)
  3286. return 0;
  3287. /* Make sure link is up before proceeding. If not just return.
  3288. * Attempting this while link is negotiating fouled up link
  3289. * stability
  3290. */
  3291. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  3292. if (!link)
  3293. return 0;
  3294. for (i = 0; i < 10; i++) {
  3295. /* read once to clear */
  3296. ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
  3297. if (ret_val)
  3298. return ret_val;
  3299. /* and again to get new status */
  3300. ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
  3301. if (ret_val)
  3302. return ret_val;
  3303. /* check for PCS lock */
  3304. if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
  3305. return 0;
  3306. /* Issue PHY reset */
  3307. e1000_phy_hw_reset(hw);
  3308. mdelay(5);
  3309. }
  3310. /* Disable GigE link negotiation */
  3311. phy_ctrl = er32(PHY_CTRL);
  3312. phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
  3313. E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
  3314. ew32(PHY_CTRL, phy_ctrl);
  3315. /* Call gig speed drop workaround on Gig disable before accessing
  3316. * any PHY registers
  3317. */
  3318. e1000e_gig_downshift_workaround_ich8lan(hw);
  3319. /* unable to acquire PCS lock */
  3320. return -E1000_ERR_PHY;
  3321. }
  3322. /**
  3323. * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
  3324. * @hw: pointer to the HW structure
  3325. * @state: boolean value used to set the current Kumeran workaround state
  3326. *
  3327. * If ICH8, set the current Kumeran workaround state (enabled - true
  3328. * /disabled - false).
  3329. **/
  3330. void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
  3331. bool state)
  3332. {
  3333. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  3334. if (hw->mac.type != e1000_ich8lan) {
  3335. e_dbg("Workaround applies to ICH8 only.\n");
  3336. return;
  3337. }
  3338. dev_spec->kmrn_lock_loss_workaround_enabled = state;
  3339. }
  3340. /**
  3341. * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
  3342. * @hw: pointer to the HW structure
  3343. *
  3344. * Workaround for 82566 power-down on D3 entry:
  3345. * 1) disable gigabit link
  3346. * 2) write VR power-down enable
  3347. * 3) read it back
  3348. * Continue if successful, else issue LCD reset and repeat
  3349. **/
  3350. void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
  3351. {
  3352. u32 reg;
  3353. u16 data;
  3354. u8 retry = 0;
  3355. if (hw->phy.type != e1000_phy_igp_3)
  3356. return;
  3357. /* Try the workaround twice (if needed) */
  3358. do {
  3359. /* Disable link */
  3360. reg = er32(PHY_CTRL);
  3361. reg |= (E1000_PHY_CTRL_GBE_DISABLE |
  3362. E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
  3363. ew32(PHY_CTRL, reg);
  3364. /* Call gig speed drop workaround on Gig disable before
  3365. * accessing any PHY registers
  3366. */
  3367. if (hw->mac.type == e1000_ich8lan)
  3368. e1000e_gig_downshift_workaround_ich8lan(hw);
  3369. /* Write VR power-down enable */
  3370. e1e_rphy(hw, IGP3_VR_CTRL, &data);
  3371. data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
  3372. e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
  3373. /* Read it back and test */
  3374. e1e_rphy(hw, IGP3_VR_CTRL, &data);
  3375. data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
  3376. if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
  3377. break;
  3378. /* Issue PHY reset and repeat at most one more time */
  3379. reg = er32(CTRL);
  3380. ew32(CTRL, reg | E1000_CTRL_PHY_RST);
  3381. retry++;
  3382. } while (retry);
  3383. }
  3384. /**
  3385. * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
  3386. * @hw: pointer to the HW structure
  3387. *
  3388. * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
  3389. * LPLU, Gig disable, MDIC PHY reset):
  3390. * 1) Set Kumeran Near-end loopback
  3391. * 2) Clear Kumeran Near-end loopback
  3392. * Should only be called for ICH8[m] devices with any 1G Phy.
  3393. **/
  3394. void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
  3395. {
  3396. s32 ret_val;
  3397. u16 reg_data;
  3398. if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
  3399. return;
  3400. ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
  3401. &reg_data);
  3402. if (ret_val)
  3403. return;
  3404. reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
  3405. ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
  3406. reg_data);
  3407. if (ret_val)
  3408. return;
  3409. reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
  3410. ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
  3411. reg_data);
  3412. }
  3413. /**
  3414. * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
  3415. * @hw: pointer to the HW structure
  3416. *
  3417. * During S0 to Sx transition, it is possible the link remains at gig
  3418. * instead of negotiating to a lower speed. Before going to Sx, set
  3419. * 'Gig Disable' to force link speed negotiation to a lower speed based on
  3420. * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
  3421. * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
  3422. * needs to be written.
  3423. * Parts that support (and are linked to a partner which support) EEE in
  3424. * 100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
  3425. * than 10Mbps w/o EEE.
  3426. **/
  3427. void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
  3428. {
  3429. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  3430. u32 phy_ctrl;
  3431. s32 ret_val;
  3432. phy_ctrl = er32(PHY_CTRL);
  3433. phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
  3434. if (hw->phy.type == e1000_phy_i217) {
  3435. u16 phy_reg;
  3436. ret_val = hw->phy.ops.acquire(hw);
  3437. if (ret_val)
  3438. goto out;
  3439. if (!dev_spec->eee_disable) {
  3440. u16 eee_advert;
  3441. ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR,
  3442. I217_EEE_ADVERTISEMENT);
  3443. if (ret_val)
  3444. goto release;
  3445. e1e_rphy_locked(hw, I82579_EMI_DATA, &eee_advert);
  3446. /* Disable LPLU if both link partners support 100BaseT
  3447. * EEE and 100Full is advertised on both ends of the
  3448. * link.
  3449. */
  3450. if ((eee_advert & I217_EEE_100_SUPPORTED) &&
  3451. (dev_spec->eee_lp_ability &
  3452. I217_EEE_100_SUPPORTED) &&
  3453. (hw->phy.autoneg_advertised & ADVERTISE_100_FULL))
  3454. phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
  3455. E1000_PHY_CTRL_NOND0A_LPLU);
  3456. }
  3457. /* For i217 Intel Rapid Start Technology support,
  3458. * when the system is going into Sx and no manageability engine
  3459. * is present, the driver must configure proxy to reset only on
  3460. * power good. LPI (Low Power Idle) state must also reset only
  3461. * on power good, as well as the MTA (Multicast table array).
  3462. * The SMBus release must also be disabled on LCD reset.
  3463. */
  3464. if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
  3465. /* Enable proxy to reset only on power good. */
  3466. e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
  3467. phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
  3468. e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
  3469. /* Set bit enable LPI (EEE) to reset only on
  3470. * power good.
  3471. */
  3472. e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
  3473. phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
  3474. e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
  3475. /* Disable the SMB release on LCD reset. */
  3476. e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
  3477. phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
  3478. e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
  3479. }
  3480. /* Enable MTA to reset for Intel Rapid Start Technology
  3481. * Support
  3482. */
  3483. e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
  3484. phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
  3485. e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
  3486. release:
  3487. hw->phy.ops.release(hw);
  3488. }
  3489. out:
  3490. ew32(PHY_CTRL, phy_ctrl);
  3491. if (hw->mac.type == e1000_ich8lan)
  3492. e1000e_gig_downshift_workaround_ich8lan(hw);
  3493. if (hw->mac.type >= e1000_pchlan) {
  3494. e1000_oem_bits_config_ich8lan(hw, false);
  3495. /* Reset PHY to activate OEM bits on 82577/8 */
  3496. if (hw->mac.type == e1000_pchlan)
  3497. e1000e_phy_hw_reset_generic(hw);
  3498. ret_val = hw->phy.ops.acquire(hw);
  3499. if (ret_val)
  3500. return;
  3501. e1000_write_smbus_addr(hw);
  3502. hw->phy.ops.release(hw);
  3503. }
  3504. }
  3505. /**
  3506. * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
  3507. * @hw: pointer to the HW structure
  3508. *
  3509. * During Sx to S0 transitions on non-managed devices or managed devices
  3510. * on which PHY resets are not blocked, if the PHY registers cannot be
  3511. * accessed properly by the s/w toggle the LANPHYPC value to power cycle
  3512. * the PHY.
  3513. * On i217, setup Intel Rapid Start Technology.
  3514. **/
  3515. void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
  3516. {
  3517. s32 ret_val;
  3518. if (hw->mac.type < e1000_pch2lan)
  3519. return;
  3520. ret_val = e1000_init_phy_workarounds_pchlan(hw);
  3521. if (ret_val) {
  3522. e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
  3523. return;
  3524. }
  3525. /* For i217 Intel Rapid Start Technology support when the system
  3526. * is transitioning from Sx and no manageability engine is present
  3527. * configure SMBus to restore on reset, disable proxy, and enable
  3528. * the reset on MTA (Multicast table array).
  3529. */
  3530. if (hw->phy.type == e1000_phy_i217) {
  3531. u16 phy_reg;
  3532. ret_val = hw->phy.ops.acquire(hw);
  3533. if (ret_val) {
  3534. e_dbg("Failed to setup iRST\n");
  3535. return;
  3536. }
  3537. if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
  3538. /* Restore clear on SMB if no manageability engine
  3539. * is present
  3540. */
  3541. ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
  3542. if (ret_val)
  3543. goto release;
  3544. phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
  3545. e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
  3546. /* Disable Proxy */
  3547. e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
  3548. }
  3549. /* Enable reset on MTA */
  3550. ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
  3551. if (ret_val)
  3552. goto release;
  3553. phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
  3554. e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
  3555. release:
  3556. if (ret_val)
  3557. e_dbg("Error %d in resume workarounds\n", ret_val);
  3558. hw->phy.ops.release(hw);
  3559. }
  3560. }
  3561. /**
  3562. * e1000_cleanup_led_ich8lan - Restore the default LED operation
  3563. * @hw: pointer to the HW structure
  3564. *
  3565. * Return the LED back to the default configuration.
  3566. **/
  3567. static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
  3568. {
  3569. if (hw->phy.type == e1000_phy_ife)
  3570. return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
  3571. ew32(LEDCTL, hw->mac.ledctl_default);
  3572. return 0;
  3573. }
  3574. /**
  3575. * e1000_led_on_ich8lan - Turn LEDs on
  3576. * @hw: pointer to the HW structure
  3577. *
  3578. * Turn on the LEDs.
  3579. **/
  3580. static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
  3581. {
  3582. if (hw->phy.type == e1000_phy_ife)
  3583. return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
  3584. (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
  3585. ew32(LEDCTL, hw->mac.ledctl_mode2);
  3586. return 0;
  3587. }
  3588. /**
  3589. * e1000_led_off_ich8lan - Turn LEDs off
  3590. * @hw: pointer to the HW structure
  3591. *
  3592. * Turn off the LEDs.
  3593. **/
  3594. static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
  3595. {
  3596. if (hw->phy.type == e1000_phy_ife)
  3597. return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
  3598. (IFE_PSCL_PROBE_MODE |
  3599. IFE_PSCL_PROBE_LEDS_OFF));
  3600. ew32(LEDCTL, hw->mac.ledctl_mode1);
  3601. return 0;
  3602. }
  3603. /**
  3604. * e1000_setup_led_pchlan - Configures SW controllable LED
  3605. * @hw: pointer to the HW structure
  3606. *
  3607. * This prepares the SW controllable LED for use.
  3608. **/
  3609. static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
  3610. {
  3611. return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
  3612. }
  3613. /**
  3614. * e1000_cleanup_led_pchlan - Restore the default LED operation
  3615. * @hw: pointer to the HW structure
  3616. *
  3617. * Return the LED back to the default configuration.
  3618. **/
  3619. static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
  3620. {
  3621. return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
  3622. }
  3623. /**
  3624. * e1000_led_on_pchlan - Turn LEDs on
  3625. * @hw: pointer to the HW structure
  3626. *
  3627. * Turn on the LEDs.
  3628. **/
  3629. static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
  3630. {
  3631. u16 data = (u16)hw->mac.ledctl_mode2;
  3632. u32 i, led;
  3633. /* If no link, then turn LED on by setting the invert bit
  3634. * for each LED that's mode is "link_up" in ledctl_mode2.
  3635. */
  3636. if (!(er32(STATUS) & E1000_STATUS_LU)) {
  3637. for (i = 0; i < 3; i++) {
  3638. led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
  3639. if ((led & E1000_PHY_LED0_MODE_MASK) !=
  3640. E1000_LEDCTL_MODE_LINK_UP)
  3641. continue;
  3642. if (led & E1000_PHY_LED0_IVRT)
  3643. data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
  3644. else
  3645. data |= (E1000_PHY_LED0_IVRT << (i * 5));
  3646. }
  3647. }
  3648. return e1e_wphy(hw, HV_LED_CONFIG, data);
  3649. }
  3650. /**
  3651. * e1000_led_off_pchlan - Turn LEDs off
  3652. * @hw: pointer to the HW structure
  3653. *
  3654. * Turn off the LEDs.
  3655. **/
  3656. static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
  3657. {
  3658. u16 data = (u16)hw->mac.ledctl_mode1;
  3659. u32 i, led;
  3660. /* If no link, then turn LED off by clearing the invert bit
  3661. * for each LED that's mode is "link_up" in ledctl_mode1.
  3662. */
  3663. if (!(er32(STATUS) & E1000_STATUS_LU)) {
  3664. for (i = 0; i < 3; i++) {
  3665. led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
  3666. if ((led & E1000_PHY_LED0_MODE_MASK) !=
  3667. E1000_LEDCTL_MODE_LINK_UP)
  3668. continue;
  3669. if (led & E1000_PHY_LED0_IVRT)
  3670. data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
  3671. else
  3672. data |= (E1000_PHY_LED0_IVRT << (i * 5));
  3673. }
  3674. }
  3675. return e1e_wphy(hw, HV_LED_CONFIG, data);
  3676. }
  3677. /**
  3678. * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
  3679. * @hw: pointer to the HW structure
  3680. *
  3681. * Read appropriate register for the config done bit for completion status
  3682. * and configure the PHY through s/w for EEPROM-less parts.
  3683. *
  3684. * NOTE: some silicon which is EEPROM-less will fail trying to read the
  3685. * config done bit, so only an error is logged and continues. If we were
  3686. * to return with error, EEPROM-less silicon would not be able to be reset
  3687. * or change link.
  3688. **/
  3689. static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
  3690. {
  3691. s32 ret_val = 0;
  3692. u32 bank = 0;
  3693. u32 status;
  3694. e1000e_get_cfg_done(hw);
  3695. /* Wait for indication from h/w that it has completed basic config */
  3696. if (hw->mac.type >= e1000_ich10lan) {
  3697. e1000_lan_init_done_ich8lan(hw);
  3698. } else {
  3699. ret_val = e1000e_get_auto_rd_done(hw);
  3700. if (ret_val) {
  3701. /* When auto config read does not complete, do not
  3702. * return with an error. This can happen in situations
  3703. * where there is no eeprom and prevents getting link.
  3704. */
  3705. e_dbg("Auto Read Done did not complete\n");
  3706. ret_val = 0;
  3707. }
  3708. }
  3709. /* Clear PHY Reset Asserted bit */
  3710. status = er32(STATUS);
  3711. if (status & E1000_STATUS_PHYRA)
  3712. ew32(STATUS, status & ~E1000_STATUS_PHYRA);
  3713. else
  3714. e_dbg("PHY Reset Asserted not set - needs delay\n");
  3715. /* If EEPROM is not marked present, init the IGP 3 PHY manually */
  3716. if (hw->mac.type <= e1000_ich9lan) {
  3717. if (!(er32(EECD) & E1000_EECD_PRES) &&
  3718. (hw->phy.type == e1000_phy_igp_3)) {
  3719. e1000e_phy_init_script_igp3(hw);
  3720. }
  3721. } else {
  3722. if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
  3723. /* Maybe we should do a basic PHY config */
  3724. e_dbg("EEPROM not present\n");
  3725. ret_val = -E1000_ERR_CONFIG;
  3726. }
  3727. }
  3728. return ret_val;
  3729. }
  3730. /**
  3731. * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
  3732. * @hw: pointer to the HW structure
  3733. *
  3734. * In the case of a PHY power down to save power, or to turn off link during a
  3735. * driver unload, or wake on lan is not enabled, remove the link.
  3736. **/
  3737. static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
  3738. {
  3739. /* If the management interface is not enabled, then power down */
  3740. if (!(hw->mac.ops.check_mng_mode(hw) ||
  3741. hw->phy.ops.check_reset_block(hw)))
  3742. e1000_power_down_phy_copper(hw);
  3743. }
  3744. /**
  3745. * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
  3746. * @hw: pointer to the HW structure
  3747. *
  3748. * Clears hardware counters specific to the silicon family and calls
  3749. * clear_hw_cntrs_generic to clear all general purpose counters.
  3750. **/
  3751. static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
  3752. {
  3753. u16 phy_data;
  3754. s32 ret_val;
  3755. e1000e_clear_hw_cntrs_base(hw);
  3756. er32(ALGNERRC);
  3757. er32(RXERRC);
  3758. er32(TNCRS);
  3759. er32(CEXTERR);
  3760. er32(TSCTC);
  3761. er32(TSCTFC);
  3762. er32(MGTPRC);
  3763. er32(MGTPDC);
  3764. er32(MGTPTC);
  3765. er32(IAC);
  3766. er32(ICRXOC);
  3767. /* Clear PHY statistics registers */
  3768. if ((hw->phy.type == e1000_phy_82578) ||
  3769. (hw->phy.type == e1000_phy_82579) ||
  3770. (hw->phy.type == e1000_phy_i217) ||
  3771. (hw->phy.type == e1000_phy_82577)) {
  3772. ret_val = hw->phy.ops.acquire(hw);
  3773. if (ret_val)
  3774. return;
  3775. ret_val = hw->phy.ops.set_page(hw,
  3776. HV_STATS_PAGE << IGP_PAGE_SHIFT);
  3777. if (ret_val)
  3778. goto release;
  3779. hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
  3780. hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
  3781. hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
  3782. hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
  3783. hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
  3784. hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
  3785. hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
  3786. hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
  3787. hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
  3788. hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
  3789. hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
  3790. hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
  3791. hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
  3792. hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
  3793. release:
  3794. hw->phy.ops.release(hw);
  3795. }
  3796. }
  3797. static const struct e1000_mac_operations ich8_mac_ops = {
  3798. /* check_mng_mode dependent on mac type */
  3799. .check_for_link = e1000_check_for_copper_link_ich8lan,
  3800. /* cleanup_led dependent on mac type */
  3801. .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
  3802. .get_bus_info = e1000_get_bus_info_ich8lan,
  3803. .set_lan_id = e1000_set_lan_id_single_port,
  3804. .get_link_up_info = e1000_get_link_up_info_ich8lan,
  3805. /* led_on dependent on mac type */
  3806. /* led_off dependent on mac type */
  3807. .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
  3808. .reset_hw = e1000_reset_hw_ich8lan,
  3809. .init_hw = e1000_init_hw_ich8lan,
  3810. .setup_link = e1000_setup_link_ich8lan,
  3811. .setup_physical_interface= e1000_setup_copper_link_ich8lan,
  3812. /* id_led_init dependent on mac type */
  3813. .config_collision_dist = e1000e_config_collision_dist_generic,
  3814. .rar_set = e1000e_rar_set_generic,
  3815. };
  3816. static const struct e1000_phy_operations ich8_phy_ops = {
  3817. .acquire = e1000_acquire_swflag_ich8lan,
  3818. .check_reset_block = e1000_check_reset_block_ich8lan,
  3819. .commit = NULL,
  3820. .get_cfg_done = e1000_get_cfg_done_ich8lan,
  3821. .get_cable_length = e1000e_get_cable_length_igp_2,
  3822. .read_reg = e1000e_read_phy_reg_igp,
  3823. .release = e1000_release_swflag_ich8lan,
  3824. .reset = e1000_phy_hw_reset_ich8lan,
  3825. .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
  3826. .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
  3827. .write_reg = e1000e_write_phy_reg_igp,
  3828. };
  3829. static const struct e1000_nvm_operations ich8_nvm_ops = {
  3830. .acquire = e1000_acquire_nvm_ich8lan,
  3831. .read = e1000_read_nvm_ich8lan,
  3832. .release = e1000_release_nvm_ich8lan,
  3833. .reload = e1000e_reload_nvm_generic,
  3834. .update = e1000_update_nvm_checksum_ich8lan,
  3835. .valid_led_default = e1000_valid_led_default_ich8lan,
  3836. .validate = e1000_validate_nvm_checksum_ich8lan,
  3837. .write = e1000_write_nvm_ich8lan,
  3838. };
  3839. const struct e1000_info e1000_ich8_info = {
  3840. .mac = e1000_ich8lan,
  3841. .flags = FLAG_HAS_WOL
  3842. | FLAG_IS_ICH
  3843. | FLAG_HAS_CTRLEXT_ON_LOAD
  3844. | FLAG_HAS_AMT
  3845. | FLAG_HAS_FLASH
  3846. | FLAG_APME_IN_WUC,
  3847. .pba = 8,
  3848. .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
  3849. .get_variants = e1000_get_variants_ich8lan,
  3850. .mac_ops = &ich8_mac_ops,
  3851. .phy_ops = &ich8_phy_ops,
  3852. .nvm_ops = &ich8_nvm_ops,
  3853. };
  3854. const struct e1000_info e1000_ich9_info = {
  3855. .mac = e1000_ich9lan,
  3856. .flags = FLAG_HAS_JUMBO_FRAMES
  3857. | FLAG_IS_ICH
  3858. | FLAG_HAS_WOL
  3859. | FLAG_HAS_CTRLEXT_ON_LOAD
  3860. | FLAG_HAS_AMT
  3861. | FLAG_HAS_FLASH
  3862. | FLAG_APME_IN_WUC,
  3863. .pba = 18,
  3864. .max_hw_frame_size = DEFAULT_JUMBO,
  3865. .get_variants = e1000_get_variants_ich8lan,
  3866. .mac_ops = &ich8_mac_ops,
  3867. .phy_ops = &ich8_phy_ops,
  3868. .nvm_ops = &ich8_nvm_ops,
  3869. };
  3870. const struct e1000_info e1000_ich10_info = {
  3871. .mac = e1000_ich10lan,
  3872. .flags = FLAG_HAS_JUMBO_FRAMES
  3873. | FLAG_IS_ICH
  3874. | FLAG_HAS_WOL
  3875. | FLAG_HAS_CTRLEXT_ON_LOAD
  3876. | FLAG_HAS_AMT
  3877. | FLAG_HAS_FLASH
  3878. | FLAG_APME_IN_WUC,
  3879. .pba = 18,
  3880. .max_hw_frame_size = DEFAULT_JUMBO,
  3881. .get_variants = e1000_get_variants_ich8lan,
  3882. .mac_ops = &ich8_mac_ops,
  3883. .phy_ops = &ich8_phy_ops,
  3884. .nvm_ops = &ich8_nvm_ops,
  3885. };
  3886. const struct e1000_info e1000_pch_info = {
  3887. .mac = e1000_pchlan,
  3888. .flags = FLAG_IS_ICH
  3889. | FLAG_HAS_WOL
  3890. | FLAG_HAS_CTRLEXT_ON_LOAD
  3891. | FLAG_HAS_AMT
  3892. | FLAG_HAS_FLASH
  3893. | FLAG_HAS_JUMBO_FRAMES
  3894. | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
  3895. | FLAG_APME_IN_WUC,
  3896. .flags2 = FLAG2_HAS_PHY_STATS,
  3897. .pba = 26,
  3898. .max_hw_frame_size = 4096,
  3899. .get_variants = e1000_get_variants_ich8lan,
  3900. .mac_ops = &ich8_mac_ops,
  3901. .phy_ops = &ich8_phy_ops,
  3902. .nvm_ops = &ich8_nvm_ops,
  3903. };
  3904. const struct e1000_info e1000_pch2_info = {
  3905. .mac = e1000_pch2lan,
  3906. .flags = FLAG_IS_ICH
  3907. | FLAG_HAS_WOL
  3908. | FLAG_HAS_CTRLEXT_ON_LOAD
  3909. | FLAG_HAS_AMT
  3910. | FLAG_HAS_FLASH
  3911. | FLAG_HAS_JUMBO_FRAMES
  3912. | FLAG_APME_IN_WUC,
  3913. .flags2 = FLAG2_HAS_PHY_STATS
  3914. | FLAG2_HAS_EEE,
  3915. .pba = 26,
  3916. .max_hw_frame_size = DEFAULT_JUMBO,
  3917. .get_variants = e1000_get_variants_ich8lan,
  3918. .mac_ops = &ich8_mac_ops,
  3919. .phy_ops = &ich8_phy_ops,
  3920. .nvm_ops = &ich8_nvm_ops,
  3921. };
  3922. const struct e1000_info e1000_pch_lpt_info = {
  3923. .mac = e1000_pch_lpt,
  3924. .flags = FLAG_IS_ICH
  3925. | FLAG_HAS_WOL
  3926. | FLAG_HAS_CTRLEXT_ON_LOAD
  3927. | FLAG_HAS_AMT
  3928. | FLAG_HAS_FLASH
  3929. | FLAG_HAS_JUMBO_FRAMES
  3930. | FLAG_APME_IN_WUC,
  3931. .flags2 = FLAG2_HAS_PHY_STATS
  3932. | FLAG2_HAS_EEE,
  3933. .pba = 26,
  3934. .max_hw_frame_size = DEFAULT_JUMBO,
  3935. .get_variants = e1000_get_variants_ich8lan,
  3936. .mac_ops = &ich8_mac_ops,
  3937. .phy_ops = &ich8_phy_ops,
  3938. .nvm_ops = &ich8_nvm_ops,
  3939. };