ich8lan.c 110 KB

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