ich8lan.c 86 KB

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