ich8lan.c 95 KB

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