ich8lan.c 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512
  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-2 10/100 Network Connection
  23. * 82562GT 10/100 Network Connection
  24. * 82562GT-2 10/100 Network Connection
  25. * 82562V 10/100 Network Connection
  26. * 82562V-2 10/100 Network Connection
  27. * 82566DC-2 Gigabit Network Connection
  28. * 82566DC Gigabit Network Connection
  29. * 82566DM-2 Gigabit Network Connection
  30. * 82566DM Gigabit Network Connection
  31. * 82566MC Gigabit Network Connection
  32. * 82566MM Gigabit Network Connection
  33. * 82567LM Gigabit Network Connection
  34. * 82567LF Gigabit Network Connection
  35. * 82567LM-2 Gigabit Network Connection
  36. * 82567LF-2 Gigabit Network Connection
  37. * 82567V-2 Gigabit Network Connection
  38. * 82567LF-3 Gigabit Network Connection
  39. * 82567LM-3 Gigabit Network Connection
  40. * 82567LM-4 Gigabit Network Connection
  41. */
  42. #include <linux/netdevice.h>
  43. #include <linux/ethtool.h>
  44. #include <linux/delay.h>
  45. #include <linux/pci.h>
  46. #include "e1000.h"
  47. #define ICH_FLASH_GFPREG 0x0000
  48. #define ICH_FLASH_HSFSTS 0x0004
  49. #define ICH_FLASH_HSFCTL 0x0006
  50. #define ICH_FLASH_FADDR 0x0008
  51. #define ICH_FLASH_FDATA0 0x0010
  52. #define ICH_FLASH_READ_COMMAND_TIMEOUT 500
  53. #define ICH_FLASH_WRITE_COMMAND_TIMEOUT 500
  54. #define ICH_FLASH_ERASE_COMMAND_TIMEOUT 3000000
  55. #define ICH_FLASH_LINEAR_ADDR_MASK 0x00FFFFFF
  56. #define ICH_FLASH_CYCLE_REPEAT_COUNT 10
  57. #define ICH_CYCLE_READ 0
  58. #define ICH_CYCLE_WRITE 2
  59. #define ICH_CYCLE_ERASE 3
  60. #define FLASH_GFPREG_BASE_MASK 0x1FFF
  61. #define FLASH_SECTOR_ADDR_SHIFT 12
  62. #define ICH_FLASH_SEG_SIZE_256 256
  63. #define ICH_FLASH_SEG_SIZE_4K 4096
  64. #define ICH_FLASH_SEG_SIZE_8K 8192
  65. #define ICH_FLASH_SEG_SIZE_64K 65536
  66. #define E1000_ICH_FWSM_RSPCIPHY 0x00000040 /* Reset PHY on PCI Reset */
  67. #define E1000_ICH_MNG_IAMT_MODE 0x2
  68. #define ID_LED_DEFAULT_ICH8LAN ((ID_LED_DEF1_DEF2 << 12) | \
  69. (ID_LED_DEF1_OFF2 << 8) | \
  70. (ID_LED_DEF1_ON2 << 4) | \
  71. (ID_LED_DEF1_DEF2))
  72. #define E1000_ICH_NVM_SIG_WORD 0x13
  73. #define E1000_ICH_NVM_SIG_MASK 0xC000
  74. #define E1000_ICH8_LAN_INIT_TIMEOUT 1500
  75. #define E1000_FEXTNVM_SW_CONFIG 1
  76. #define E1000_FEXTNVM_SW_CONFIG_ICH8M (1 << 27) /* Bit redefined for ICH8M :/ */
  77. #define PCIE_ICH8_SNOOP_ALL PCIE_NO_SNOOP_ALL
  78. #define E1000_ICH_RAR_ENTRIES 7
  79. #define PHY_PAGE_SHIFT 5
  80. #define PHY_REG(page, reg) (((page) << PHY_PAGE_SHIFT) | \
  81. ((reg) & MAX_PHY_REG_ADDRESS))
  82. #define IGP3_KMRN_DIAG PHY_REG(770, 19) /* KMRN Diagnostic */
  83. #define IGP3_VR_CTRL PHY_REG(776, 18) /* Voltage Regulator Control */
  84. #define IGP3_KMRN_DIAG_PCS_LOCK_LOSS 0x0002
  85. #define IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK 0x0300
  86. #define IGP3_VR_CTRL_MODE_SHUTDOWN 0x0200
  87. /* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
  88. /* Offset 04h HSFSTS */
  89. union ich8_hws_flash_status {
  90. struct ich8_hsfsts {
  91. u16 flcdone :1; /* bit 0 Flash Cycle Done */
  92. u16 flcerr :1; /* bit 1 Flash Cycle Error */
  93. u16 dael :1; /* bit 2 Direct Access error Log */
  94. u16 berasesz :2; /* bit 4:3 Sector Erase Size */
  95. u16 flcinprog :1; /* bit 5 flash cycle in Progress */
  96. u16 reserved1 :2; /* bit 13:6 Reserved */
  97. u16 reserved2 :6; /* bit 13:6 Reserved */
  98. u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
  99. u16 flockdn :1; /* bit 15 Flash Config Lock-Down */
  100. } hsf_status;
  101. u16 regval;
  102. };
  103. /* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
  104. /* Offset 06h FLCTL */
  105. union ich8_hws_flash_ctrl {
  106. struct ich8_hsflctl {
  107. u16 flcgo :1; /* 0 Flash Cycle Go */
  108. u16 flcycle :2; /* 2:1 Flash Cycle */
  109. u16 reserved :5; /* 7:3 Reserved */
  110. u16 fldbcount :2; /* 9:8 Flash Data Byte Count */
  111. u16 flockdn :6; /* 15:10 Reserved */
  112. } hsf_ctrl;
  113. u16 regval;
  114. };
  115. /* ICH Flash Region Access Permissions */
  116. union ich8_hws_flash_regacc {
  117. struct ich8_flracc {
  118. u32 grra :8; /* 0:7 GbE region Read Access */
  119. u32 grwa :8; /* 8:15 GbE region Write Access */
  120. u32 gmrag :8; /* 23:16 GbE Master Read Access Grant */
  121. u32 gmwag :8; /* 31:24 GbE Master Write Access Grant */
  122. } hsf_flregacc;
  123. u16 regval;
  124. };
  125. static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw);
  126. static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
  127. static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
  128. static s32 e1000_check_polarity_ife_ich8lan(struct e1000_hw *hw);
  129. static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
  130. static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
  131. u32 offset, u8 byte);
  132. static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
  133. u8 *data);
  134. static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
  135. u16 *data);
  136. static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
  137. u8 size, u16 *data);
  138. static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
  139. static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
  140. static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
  141. static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
  142. {
  143. return readw(hw->flash_address + reg);
  144. }
  145. static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
  146. {
  147. return readl(hw->flash_address + reg);
  148. }
  149. static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
  150. {
  151. writew(val, hw->flash_address + reg);
  152. }
  153. static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
  154. {
  155. writel(val, hw->flash_address + reg);
  156. }
  157. #define er16flash(reg) __er16flash(hw, (reg))
  158. #define er32flash(reg) __er32flash(hw, (reg))
  159. #define ew16flash(reg,val) __ew16flash(hw, (reg), (val))
  160. #define ew32flash(reg,val) __ew32flash(hw, (reg), (val))
  161. /**
  162. * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
  163. * @hw: pointer to the HW structure
  164. *
  165. * Initialize family-specific PHY parameters and function pointers.
  166. **/
  167. static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
  168. {
  169. struct e1000_phy_info *phy = &hw->phy;
  170. s32 ret_val;
  171. u16 i = 0;
  172. phy->addr = 1;
  173. phy->reset_delay_us = 100;
  174. /*
  175. * We may need to do this twice - once for IGP and if that fails,
  176. * we'll set BM func pointers and try again
  177. */
  178. ret_val = e1000e_determine_phy_address(hw);
  179. if (ret_val) {
  180. hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;
  181. hw->phy.ops.read_phy_reg = e1000e_read_phy_reg_bm;
  182. ret_val = e1000e_determine_phy_address(hw);
  183. if (ret_val)
  184. return ret_val;
  185. }
  186. phy->id = 0;
  187. while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
  188. (i++ < 100)) {
  189. msleep(1);
  190. ret_val = e1000e_get_phy_id(hw);
  191. if (ret_val)
  192. return ret_val;
  193. }
  194. /* Verify phy id */
  195. switch (phy->id) {
  196. case IGP03E1000_E_PHY_ID:
  197. phy->type = e1000_phy_igp_3;
  198. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  199. break;
  200. case IFE_E_PHY_ID:
  201. case IFE_PLUS_E_PHY_ID:
  202. case IFE_C_E_PHY_ID:
  203. phy->type = e1000_phy_ife;
  204. phy->autoneg_mask = E1000_ALL_NOT_GIG;
  205. break;
  206. case BME1000_E_PHY_ID:
  207. phy->type = e1000_phy_bm;
  208. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  209. hw->phy.ops.read_phy_reg = e1000e_read_phy_reg_bm;
  210. hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;
  211. hw->phy.ops.commit_phy = e1000e_phy_sw_reset;
  212. break;
  213. default:
  214. return -E1000_ERR_PHY;
  215. break;
  216. }
  217. return 0;
  218. }
  219. /**
  220. * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
  221. * @hw: pointer to the HW structure
  222. *
  223. * Initialize family-specific NVM parameters and function
  224. * pointers.
  225. **/
  226. static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
  227. {
  228. struct e1000_nvm_info *nvm = &hw->nvm;
  229. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  230. u32 gfpreg;
  231. u32 sector_base_addr;
  232. u32 sector_end_addr;
  233. u16 i;
  234. /* Can't read flash registers if the register set isn't mapped. */
  235. if (!hw->flash_address) {
  236. hw_dbg(hw, "ERROR: Flash registers not mapped\n");
  237. return -E1000_ERR_CONFIG;
  238. }
  239. nvm->type = e1000_nvm_flash_sw;
  240. gfpreg = er32flash(ICH_FLASH_GFPREG);
  241. /*
  242. * sector_X_addr is a "sector"-aligned address (4096 bytes)
  243. * Add 1 to sector_end_addr since this sector is included in
  244. * the overall size.
  245. */
  246. sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
  247. sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
  248. /* flash_base_addr is byte-aligned */
  249. nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
  250. /*
  251. * find total size of the NVM, then cut in half since the total
  252. * size represents two separate NVM banks.
  253. */
  254. nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
  255. << FLASH_SECTOR_ADDR_SHIFT;
  256. nvm->flash_bank_size /= 2;
  257. /* Adjust to word count */
  258. nvm->flash_bank_size /= sizeof(u16);
  259. nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
  260. /* Clear shadow ram */
  261. for (i = 0; i < nvm->word_size; i++) {
  262. dev_spec->shadow_ram[i].modified = 0;
  263. dev_spec->shadow_ram[i].value = 0xFFFF;
  264. }
  265. return 0;
  266. }
  267. /**
  268. * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
  269. * @hw: pointer to the HW structure
  270. *
  271. * Initialize family-specific MAC parameters and function
  272. * pointers.
  273. **/
  274. static s32 e1000_init_mac_params_ich8lan(struct e1000_adapter *adapter)
  275. {
  276. struct e1000_hw *hw = &adapter->hw;
  277. struct e1000_mac_info *mac = &hw->mac;
  278. /* Set media type function pointer */
  279. hw->phy.media_type = e1000_media_type_copper;
  280. /* Set mta register count */
  281. mac->mta_reg_count = 32;
  282. /* Set rar entry count */
  283. mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
  284. if (mac->type == e1000_ich8lan)
  285. mac->rar_entry_count--;
  286. /* Set if manageability features are enabled. */
  287. mac->arc_subsystem_valid = 1;
  288. /* Enable PCS Lock-loss workaround for ICH8 */
  289. if (mac->type == e1000_ich8lan)
  290. e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, 1);
  291. return 0;
  292. }
  293. static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
  294. {
  295. struct e1000_hw *hw = &adapter->hw;
  296. s32 rc;
  297. rc = e1000_init_mac_params_ich8lan(adapter);
  298. if (rc)
  299. return rc;
  300. rc = e1000_init_nvm_params_ich8lan(hw);
  301. if (rc)
  302. return rc;
  303. rc = e1000_init_phy_params_ich8lan(hw);
  304. if (rc)
  305. return rc;
  306. if ((adapter->hw.mac.type == e1000_ich8lan) &&
  307. (adapter->hw.phy.type == e1000_phy_igp_3))
  308. adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
  309. return 0;
  310. }
  311. /**
  312. * e1000_acquire_swflag_ich8lan - Acquire software control flag
  313. * @hw: pointer to the HW structure
  314. *
  315. * Acquires the software control flag for performing NVM and PHY
  316. * operations. This is a function pointer entry point only called by
  317. * read/write routines for the PHY and NVM parts.
  318. **/
  319. static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
  320. {
  321. u32 extcnf_ctrl;
  322. u32 timeout = PHY_CFG_TIMEOUT;
  323. while (timeout) {
  324. extcnf_ctrl = er32(EXTCNF_CTRL);
  325. extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
  326. ew32(EXTCNF_CTRL, extcnf_ctrl);
  327. extcnf_ctrl = er32(EXTCNF_CTRL);
  328. if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
  329. break;
  330. mdelay(1);
  331. timeout--;
  332. }
  333. if (!timeout) {
  334. hw_dbg(hw, "FW or HW has locked the resource for too long.\n");
  335. extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
  336. ew32(EXTCNF_CTRL, extcnf_ctrl);
  337. return -E1000_ERR_CONFIG;
  338. }
  339. return 0;
  340. }
  341. /**
  342. * e1000_release_swflag_ich8lan - Release software control flag
  343. * @hw: pointer to the HW structure
  344. *
  345. * Releases the software control flag for performing NVM and PHY operations.
  346. * This is a function pointer entry point only called by read/write
  347. * routines for the PHY and NVM parts.
  348. **/
  349. static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
  350. {
  351. u32 extcnf_ctrl;
  352. extcnf_ctrl = er32(EXTCNF_CTRL);
  353. extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
  354. ew32(EXTCNF_CTRL, extcnf_ctrl);
  355. }
  356. /**
  357. * e1000_check_mng_mode_ich8lan - Checks management mode
  358. * @hw: pointer to the HW structure
  359. *
  360. * This checks if the adapter has manageability enabled.
  361. * This is a function pointer entry point only called by read/write
  362. * routines for the PHY and NVM parts.
  363. **/
  364. static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
  365. {
  366. u32 fwsm = er32(FWSM);
  367. return (fwsm & E1000_FWSM_MODE_MASK) ==
  368. (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT);
  369. }
  370. /**
  371. * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
  372. * @hw: pointer to the HW structure
  373. *
  374. * Checks if firmware is blocking the reset of the PHY.
  375. * This is a function pointer entry point only called by
  376. * reset routines.
  377. **/
  378. static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
  379. {
  380. u32 fwsm;
  381. fwsm = er32(FWSM);
  382. return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
  383. }
  384. /**
  385. * e1000_phy_force_speed_duplex_ich8lan - Force PHY speed & duplex
  386. * @hw: pointer to the HW structure
  387. *
  388. * Forces the speed and duplex settings of the PHY.
  389. * This is a function pointer entry point only called by
  390. * PHY setup routines.
  391. **/
  392. static s32 e1000_phy_force_speed_duplex_ich8lan(struct e1000_hw *hw)
  393. {
  394. struct e1000_phy_info *phy = &hw->phy;
  395. s32 ret_val;
  396. u16 data;
  397. bool link;
  398. if (phy->type != e1000_phy_ife) {
  399. ret_val = e1000e_phy_force_speed_duplex_igp(hw);
  400. return ret_val;
  401. }
  402. ret_val = e1e_rphy(hw, PHY_CONTROL, &data);
  403. if (ret_val)
  404. return ret_val;
  405. e1000e_phy_force_speed_duplex_setup(hw, &data);
  406. ret_val = e1e_wphy(hw, PHY_CONTROL, data);
  407. if (ret_val)
  408. return ret_val;
  409. /* Disable MDI-X support for 10/100 */
  410. ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
  411. if (ret_val)
  412. return ret_val;
  413. data &= ~IFE_PMC_AUTO_MDIX;
  414. data &= ~IFE_PMC_FORCE_MDIX;
  415. ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, data);
  416. if (ret_val)
  417. return ret_val;
  418. hw_dbg(hw, "IFE PMC: %X\n", data);
  419. udelay(1);
  420. if (phy->autoneg_wait_to_complete) {
  421. hw_dbg(hw, "Waiting for forced speed/duplex link on IFE phy.\n");
  422. ret_val = e1000e_phy_has_link_generic(hw,
  423. PHY_FORCE_LIMIT,
  424. 100000,
  425. &link);
  426. if (ret_val)
  427. return ret_val;
  428. if (!link)
  429. hw_dbg(hw, "Link taking longer than expected.\n");
  430. /* Try once more */
  431. ret_val = e1000e_phy_has_link_generic(hw,
  432. PHY_FORCE_LIMIT,
  433. 100000,
  434. &link);
  435. if (ret_val)
  436. return ret_val;
  437. }
  438. return 0;
  439. }
  440. /**
  441. * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
  442. * @hw: pointer to the HW structure
  443. *
  444. * Resets the PHY
  445. * This is a function pointer entry point called by drivers
  446. * or other shared routines.
  447. **/
  448. static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
  449. {
  450. struct e1000_phy_info *phy = &hw->phy;
  451. u32 i;
  452. u32 data, cnf_size, cnf_base_addr, sw_cfg_mask;
  453. s32 ret_val;
  454. u16 loop = E1000_ICH8_LAN_INIT_TIMEOUT;
  455. u16 word_addr, reg_data, reg_addr, phy_page = 0;
  456. ret_val = e1000e_phy_hw_reset_generic(hw);
  457. if (ret_val)
  458. return ret_val;
  459. /*
  460. * Initialize the PHY from the NVM on ICH platforms. This
  461. * is needed due to an issue where the NVM configuration is
  462. * not properly autoloaded after power transitions.
  463. * Therefore, after each PHY reset, we will load the
  464. * configuration data out of the NVM manually.
  465. */
  466. if (hw->mac.type == e1000_ich8lan && phy->type == e1000_phy_igp_3) {
  467. struct e1000_adapter *adapter = hw->adapter;
  468. /* Check if SW needs configure the PHY */
  469. if ((adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_M_AMT) ||
  470. (adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_M))
  471. sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
  472. else
  473. sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
  474. data = er32(FEXTNVM);
  475. if (!(data & sw_cfg_mask))
  476. return 0;
  477. /* Wait for basic configuration completes before proceeding*/
  478. do {
  479. data = er32(STATUS);
  480. data &= E1000_STATUS_LAN_INIT_DONE;
  481. udelay(100);
  482. } while ((!data) && --loop);
  483. /*
  484. * If basic configuration is incomplete before the above loop
  485. * count reaches 0, loading the configuration from NVM will
  486. * leave the PHY in a bad state possibly resulting in no link.
  487. */
  488. if (loop == 0) {
  489. hw_dbg(hw, "LAN_INIT_DONE not set, increase timeout\n");
  490. }
  491. /* Clear the Init Done bit for the next init event */
  492. data = er32(STATUS);
  493. data &= ~E1000_STATUS_LAN_INIT_DONE;
  494. ew32(STATUS, data);
  495. /*
  496. * Make sure HW does not configure LCD from PHY
  497. * extended configuration before SW configuration
  498. */
  499. data = er32(EXTCNF_CTRL);
  500. if (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE)
  501. return 0;
  502. cnf_size = er32(EXTCNF_SIZE);
  503. cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
  504. cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
  505. if (!cnf_size)
  506. return 0;
  507. cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
  508. cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
  509. /* Configure LCD from extended configuration region. */
  510. /* cnf_base_addr is in DWORD */
  511. word_addr = (u16)(cnf_base_addr << 1);
  512. for (i = 0; i < cnf_size; i++) {
  513. ret_val = e1000_read_nvm(hw,
  514. (word_addr + i * 2),
  515. 1,
  516. &reg_data);
  517. if (ret_val)
  518. return ret_val;
  519. ret_val = e1000_read_nvm(hw,
  520. (word_addr + i * 2 + 1),
  521. 1,
  522. &reg_addr);
  523. if (ret_val)
  524. return ret_val;
  525. /* Save off the PHY page for future writes. */
  526. if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
  527. phy_page = reg_data;
  528. continue;
  529. }
  530. reg_addr |= phy_page;
  531. ret_val = e1e_wphy(hw, (u32)reg_addr, reg_data);
  532. if (ret_val)
  533. return ret_val;
  534. }
  535. }
  536. return 0;
  537. }
  538. /**
  539. * e1000_get_phy_info_ife_ich8lan - Retrieves various IFE PHY states
  540. * @hw: pointer to the HW structure
  541. *
  542. * Populates "phy" structure with various feature states.
  543. * This function is only called by other family-specific
  544. * routines.
  545. **/
  546. static s32 e1000_get_phy_info_ife_ich8lan(struct e1000_hw *hw)
  547. {
  548. struct e1000_phy_info *phy = &hw->phy;
  549. s32 ret_val;
  550. u16 data;
  551. bool link;
  552. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  553. if (ret_val)
  554. return ret_val;
  555. if (!link) {
  556. hw_dbg(hw, "Phy info is only valid if link is up\n");
  557. return -E1000_ERR_CONFIG;
  558. }
  559. ret_val = e1e_rphy(hw, IFE_PHY_SPECIAL_CONTROL, &data);
  560. if (ret_val)
  561. return ret_val;
  562. phy->polarity_correction = (!(data & IFE_PSC_AUTO_POLARITY_DISABLE));
  563. if (phy->polarity_correction) {
  564. ret_val = e1000_check_polarity_ife_ich8lan(hw);
  565. if (ret_val)
  566. return ret_val;
  567. } else {
  568. /* Polarity is forced */
  569. phy->cable_polarity = (data & IFE_PSC_FORCE_POLARITY)
  570. ? e1000_rev_polarity_reversed
  571. : e1000_rev_polarity_normal;
  572. }
  573. ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
  574. if (ret_val)
  575. return ret_val;
  576. phy->is_mdix = (data & IFE_PMC_MDIX_STATUS);
  577. /* The following parameters are undefined for 10/100 operation. */
  578. phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
  579. phy->local_rx = e1000_1000t_rx_status_undefined;
  580. phy->remote_rx = e1000_1000t_rx_status_undefined;
  581. return 0;
  582. }
  583. /**
  584. * e1000_get_phy_info_ich8lan - Calls appropriate PHY type get_phy_info
  585. * @hw: pointer to the HW structure
  586. *
  587. * Wrapper for calling the get_phy_info routines for the appropriate phy type.
  588. * This is a function pointer entry point called by drivers
  589. * or other shared routines.
  590. **/
  591. static s32 e1000_get_phy_info_ich8lan(struct e1000_hw *hw)
  592. {
  593. switch (hw->phy.type) {
  594. case e1000_phy_ife:
  595. return e1000_get_phy_info_ife_ich8lan(hw);
  596. break;
  597. case e1000_phy_igp_3:
  598. case e1000_phy_bm:
  599. return e1000e_get_phy_info_igp(hw);
  600. break;
  601. default:
  602. break;
  603. }
  604. return -E1000_ERR_PHY_TYPE;
  605. }
  606. /**
  607. * e1000_check_polarity_ife_ich8lan - Check cable polarity for IFE PHY
  608. * @hw: pointer to the HW structure
  609. *
  610. * Polarity is determined on the polarity reversal feature being enabled.
  611. * This function is only called by other family-specific
  612. * routines.
  613. **/
  614. static s32 e1000_check_polarity_ife_ich8lan(struct e1000_hw *hw)
  615. {
  616. struct e1000_phy_info *phy = &hw->phy;
  617. s32 ret_val;
  618. u16 phy_data, offset, mask;
  619. /*
  620. * Polarity is determined based on the reversal feature being enabled.
  621. */
  622. if (phy->polarity_correction) {
  623. offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
  624. mask = IFE_PESC_POLARITY_REVERSED;
  625. } else {
  626. offset = IFE_PHY_SPECIAL_CONTROL;
  627. mask = IFE_PSC_FORCE_POLARITY;
  628. }
  629. ret_val = e1e_rphy(hw, offset, &phy_data);
  630. if (!ret_val)
  631. phy->cable_polarity = (phy_data & mask)
  632. ? e1000_rev_polarity_reversed
  633. : e1000_rev_polarity_normal;
  634. return ret_val;
  635. }
  636. /**
  637. * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
  638. * @hw: pointer to the HW structure
  639. * @active: TRUE to enable LPLU, FALSE to disable
  640. *
  641. * Sets the LPLU D0 state according to the active flag. When
  642. * activating LPLU this function also disables smart speed
  643. * and vice versa. LPLU will not be activated unless the
  644. * device autonegotiation advertisement meets standards of
  645. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  646. * This is a function pointer entry point only called by
  647. * PHY setup routines.
  648. **/
  649. static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
  650. {
  651. struct e1000_phy_info *phy = &hw->phy;
  652. u32 phy_ctrl;
  653. s32 ret_val = 0;
  654. u16 data;
  655. if (phy->type == e1000_phy_ife)
  656. return ret_val;
  657. phy_ctrl = er32(PHY_CTRL);
  658. if (active) {
  659. phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
  660. ew32(PHY_CTRL, phy_ctrl);
  661. /*
  662. * Call gig speed drop workaround on LPLU before accessing
  663. * any PHY registers
  664. */
  665. if ((hw->mac.type == e1000_ich8lan) &&
  666. (hw->phy.type == e1000_phy_igp_3))
  667. e1000e_gig_downshift_workaround_ich8lan(hw);
  668. /* When LPLU is enabled, we should disable SmartSpeed */
  669. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
  670. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  671. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
  672. if (ret_val)
  673. return ret_val;
  674. } else {
  675. phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
  676. ew32(PHY_CTRL, phy_ctrl);
  677. /*
  678. * LPLU and SmartSpeed are mutually exclusive. LPLU is used
  679. * during Dx states where the power conservation is most
  680. * important. During driver activity we should enable
  681. * SmartSpeed, so performance is maintained.
  682. */
  683. if (phy->smart_speed == e1000_smart_speed_on) {
  684. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  685. &data);
  686. if (ret_val)
  687. return ret_val;
  688. data |= IGP01E1000_PSCFR_SMART_SPEED;
  689. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  690. data);
  691. if (ret_val)
  692. return ret_val;
  693. } else if (phy->smart_speed == e1000_smart_speed_off) {
  694. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  695. &data);
  696. if (ret_val)
  697. return ret_val;
  698. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  699. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  700. data);
  701. if (ret_val)
  702. return ret_val;
  703. }
  704. }
  705. return 0;
  706. }
  707. /**
  708. * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
  709. * @hw: pointer to the HW structure
  710. * @active: TRUE to enable LPLU, FALSE to disable
  711. *
  712. * Sets the LPLU D3 state according to the active flag. When
  713. * activating LPLU this function also disables smart speed
  714. * and vice versa. LPLU will not be activated unless the
  715. * device autonegotiation advertisement meets standards of
  716. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  717. * This is a function pointer entry point only called by
  718. * PHY setup routines.
  719. **/
  720. static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
  721. {
  722. struct e1000_phy_info *phy = &hw->phy;
  723. u32 phy_ctrl;
  724. s32 ret_val;
  725. u16 data;
  726. phy_ctrl = er32(PHY_CTRL);
  727. if (!active) {
  728. phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
  729. ew32(PHY_CTRL, phy_ctrl);
  730. /*
  731. * LPLU and SmartSpeed are mutually exclusive. LPLU is used
  732. * during Dx states where the power conservation is most
  733. * important. During driver activity we should enable
  734. * SmartSpeed, so performance is maintained.
  735. */
  736. if (phy->smart_speed == e1000_smart_speed_on) {
  737. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  738. &data);
  739. if (ret_val)
  740. return ret_val;
  741. data |= IGP01E1000_PSCFR_SMART_SPEED;
  742. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  743. data);
  744. if (ret_val)
  745. return ret_val;
  746. } else if (phy->smart_speed == e1000_smart_speed_off) {
  747. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  748. &data);
  749. if (ret_val)
  750. return ret_val;
  751. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  752. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  753. data);
  754. if (ret_val)
  755. return ret_val;
  756. }
  757. } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
  758. (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
  759. (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
  760. phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
  761. ew32(PHY_CTRL, phy_ctrl);
  762. /*
  763. * Call gig speed drop workaround on LPLU before accessing
  764. * any PHY registers
  765. */
  766. if ((hw->mac.type == e1000_ich8lan) &&
  767. (hw->phy.type == e1000_phy_igp_3))
  768. e1000e_gig_downshift_workaround_ich8lan(hw);
  769. /* When LPLU is enabled, we should disable SmartSpeed */
  770. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
  771. if (ret_val)
  772. return ret_val;
  773. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  774. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
  775. }
  776. return 0;
  777. }
  778. /**
  779. * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
  780. * @hw: pointer to the HW structure
  781. * @bank: pointer to the variable that returns the active bank
  782. *
  783. * Reads signature byte from the NVM using the flash access registers.
  784. **/
  785. static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
  786. {
  787. struct e1000_nvm_info *nvm = &hw->nvm;
  788. /* flash bank size is in words */
  789. u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
  790. u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
  791. u8 bank_high_byte = 0;
  792. if (hw->mac.type != e1000_ich10lan) {
  793. if (er32(EECD) & E1000_EECD_SEC1VAL)
  794. *bank = 1;
  795. else
  796. *bank = 0;
  797. } else {
  798. /*
  799. * Make sure the signature for bank 0 is valid,
  800. * if not check for bank1
  801. */
  802. e1000_read_flash_byte_ich8lan(hw, act_offset, &bank_high_byte);
  803. if ((bank_high_byte & 0xC0) == 0x80) {
  804. *bank = 0;
  805. } else {
  806. /*
  807. * find if segment 1 is valid by verifying
  808. * bit 15:14 = 10b in word 0x13
  809. */
  810. e1000_read_flash_byte_ich8lan(hw,
  811. act_offset + bank1_offset,
  812. &bank_high_byte);
  813. /* bank1 has a valid signature equivalent to SEC1V */
  814. if ((bank_high_byte & 0xC0) == 0x80) {
  815. *bank = 1;
  816. } else {
  817. hw_dbg(hw, "ERROR: EEPROM not present\n");
  818. return -E1000_ERR_NVM;
  819. }
  820. }
  821. }
  822. return 0;
  823. }
  824. /**
  825. * e1000_read_nvm_ich8lan - Read word(s) from the NVM
  826. * @hw: pointer to the HW structure
  827. * @offset: The offset (in bytes) of the word(s) to read.
  828. * @words: Size of data to read in words
  829. * @data: Pointer to the word(s) to read at offset.
  830. *
  831. * Reads a word(s) from the NVM using the flash access registers.
  832. **/
  833. static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
  834. u16 *data)
  835. {
  836. struct e1000_nvm_info *nvm = &hw->nvm;
  837. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  838. u32 act_offset;
  839. s32 ret_val;
  840. u32 bank = 0;
  841. u16 i, word;
  842. if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
  843. (words == 0)) {
  844. hw_dbg(hw, "nvm parameter(s) out of bounds\n");
  845. return -E1000_ERR_NVM;
  846. }
  847. ret_val = e1000_acquire_swflag_ich8lan(hw);
  848. if (ret_val)
  849. return ret_val;
  850. ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
  851. if (ret_val)
  852. return ret_val;
  853. act_offset = (bank) ? nvm->flash_bank_size : 0;
  854. act_offset += offset;
  855. for (i = 0; i < words; i++) {
  856. if ((dev_spec->shadow_ram) &&
  857. (dev_spec->shadow_ram[offset+i].modified)) {
  858. data[i] = dev_spec->shadow_ram[offset+i].value;
  859. } else {
  860. ret_val = e1000_read_flash_word_ich8lan(hw,
  861. act_offset + i,
  862. &word);
  863. if (ret_val)
  864. break;
  865. data[i] = word;
  866. }
  867. }
  868. e1000_release_swflag_ich8lan(hw);
  869. return ret_val;
  870. }
  871. /**
  872. * e1000_flash_cycle_init_ich8lan - Initialize flash
  873. * @hw: pointer to the HW structure
  874. *
  875. * This function does initial flash setup so that a new read/write/erase cycle
  876. * can be started.
  877. **/
  878. static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
  879. {
  880. union ich8_hws_flash_status hsfsts;
  881. s32 ret_val = -E1000_ERR_NVM;
  882. s32 i = 0;
  883. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  884. /* Check if the flash descriptor is valid */
  885. if (hsfsts.hsf_status.fldesvalid == 0) {
  886. hw_dbg(hw, "Flash descriptor invalid. "
  887. "SW Sequencing must be used.");
  888. return -E1000_ERR_NVM;
  889. }
  890. /* Clear FCERR and DAEL in hw status by writing 1 */
  891. hsfsts.hsf_status.flcerr = 1;
  892. hsfsts.hsf_status.dael = 1;
  893. ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  894. /*
  895. * Either we should have a hardware SPI cycle in progress
  896. * bit to check against, in order to start a new cycle or
  897. * FDONE bit should be changed in the hardware so that it
  898. * is 1 after hardware reset, which can then be used as an
  899. * indication whether a cycle is in progress or has been
  900. * completed.
  901. */
  902. if (hsfsts.hsf_status.flcinprog == 0) {
  903. /*
  904. * There is no cycle running at present,
  905. * so we can start a cycle
  906. * Begin by setting Flash Cycle Done.
  907. */
  908. hsfsts.hsf_status.flcdone = 1;
  909. ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  910. ret_val = 0;
  911. } else {
  912. /*
  913. * otherwise poll for sometime so the current
  914. * cycle has a chance to end before giving up.
  915. */
  916. for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
  917. hsfsts.regval = __er16flash(hw, ICH_FLASH_HSFSTS);
  918. if (hsfsts.hsf_status.flcinprog == 0) {
  919. ret_val = 0;
  920. break;
  921. }
  922. udelay(1);
  923. }
  924. if (ret_val == 0) {
  925. /*
  926. * Successful in waiting for previous cycle to timeout,
  927. * now set the Flash Cycle Done.
  928. */
  929. hsfsts.hsf_status.flcdone = 1;
  930. ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  931. } else {
  932. hw_dbg(hw, "Flash controller busy, cannot get access");
  933. }
  934. }
  935. return ret_val;
  936. }
  937. /**
  938. * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
  939. * @hw: pointer to the HW structure
  940. * @timeout: maximum time to wait for completion
  941. *
  942. * This function starts a flash cycle and waits for its completion.
  943. **/
  944. static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
  945. {
  946. union ich8_hws_flash_ctrl hsflctl;
  947. union ich8_hws_flash_status hsfsts;
  948. s32 ret_val = -E1000_ERR_NVM;
  949. u32 i = 0;
  950. /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
  951. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  952. hsflctl.hsf_ctrl.flcgo = 1;
  953. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  954. /* wait till FDONE bit is set to 1 */
  955. do {
  956. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  957. if (hsfsts.hsf_status.flcdone == 1)
  958. break;
  959. udelay(1);
  960. } while (i++ < timeout);
  961. if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0)
  962. return 0;
  963. return ret_val;
  964. }
  965. /**
  966. * e1000_read_flash_word_ich8lan - Read word from flash
  967. * @hw: pointer to the HW structure
  968. * @offset: offset to data location
  969. * @data: pointer to the location for storing the data
  970. *
  971. * Reads the flash word at offset into data. Offset is converted
  972. * to bytes before read.
  973. **/
  974. static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
  975. u16 *data)
  976. {
  977. /* Must convert offset into bytes. */
  978. offset <<= 1;
  979. return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
  980. }
  981. /**
  982. * e1000_read_flash_byte_ich8lan - Read byte from flash
  983. * @hw: pointer to the HW structure
  984. * @offset: The offset of the byte to read.
  985. * @data: Pointer to a byte to store the value read.
  986. *
  987. * Reads a single byte from the NVM using the flash access registers.
  988. **/
  989. static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
  990. u8 *data)
  991. {
  992. s32 ret_val;
  993. u16 word = 0;
  994. ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
  995. if (ret_val)
  996. return ret_val;
  997. *data = (u8)word;
  998. return 0;
  999. }
  1000. /**
  1001. * e1000_read_flash_data_ich8lan - Read byte or word from NVM
  1002. * @hw: pointer to the HW structure
  1003. * @offset: The offset (in bytes) of the byte or word to read.
  1004. * @size: Size of data to read, 1=byte 2=word
  1005. * @data: Pointer to the word to store the value read.
  1006. *
  1007. * Reads a byte or word from the NVM using the flash access registers.
  1008. **/
  1009. static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
  1010. u8 size, u16 *data)
  1011. {
  1012. union ich8_hws_flash_status hsfsts;
  1013. union ich8_hws_flash_ctrl hsflctl;
  1014. u32 flash_linear_addr;
  1015. u32 flash_data = 0;
  1016. s32 ret_val = -E1000_ERR_NVM;
  1017. u8 count = 0;
  1018. if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
  1019. return -E1000_ERR_NVM;
  1020. flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
  1021. hw->nvm.flash_base_addr;
  1022. do {
  1023. udelay(1);
  1024. /* Steps */
  1025. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  1026. if (ret_val != 0)
  1027. break;
  1028. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  1029. /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
  1030. hsflctl.hsf_ctrl.fldbcount = size - 1;
  1031. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
  1032. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  1033. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  1034. ret_val = e1000_flash_cycle_ich8lan(hw,
  1035. ICH_FLASH_READ_COMMAND_TIMEOUT);
  1036. /*
  1037. * Check if FCERR is set to 1, if set to 1, clear it
  1038. * and try the whole sequence a few more times, else
  1039. * read in (shift in) the Flash Data0, the order is
  1040. * least significant byte first msb to lsb
  1041. */
  1042. if (ret_val == 0) {
  1043. flash_data = er32flash(ICH_FLASH_FDATA0);
  1044. if (size == 1) {
  1045. *data = (u8)(flash_data & 0x000000FF);
  1046. } else if (size == 2) {
  1047. *data = (u16)(flash_data & 0x0000FFFF);
  1048. }
  1049. break;
  1050. } else {
  1051. /*
  1052. * If we've gotten here, then things are probably
  1053. * completely hosed, but if the error condition is
  1054. * detected, it won't hurt to give it another try...
  1055. * ICH_FLASH_CYCLE_REPEAT_COUNT times.
  1056. */
  1057. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  1058. if (hsfsts.hsf_status.flcerr == 1) {
  1059. /* Repeat for some time before giving up. */
  1060. continue;
  1061. } else if (hsfsts.hsf_status.flcdone == 0) {
  1062. hw_dbg(hw, "Timeout error - flash cycle "
  1063. "did not complete.");
  1064. break;
  1065. }
  1066. }
  1067. } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
  1068. return ret_val;
  1069. }
  1070. /**
  1071. * e1000_write_nvm_ich8lan - Write word(s) to the NVM
  1072. * @hw: pointer to the HW structure
  1073. * @offset: The offset (in bytes) of the word(s) to write.
  1074. * @words: Size of data to write in words
  1075. * @data: Pointer to the word(s) to write at offset.
  1076. *
  1077. * Writes a byte or word to the NVM using the flash access registers.
  1078. **/
  1079. static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
  1080. u16 *data)
  1081. {
  1082. struct e1000_nvm_info *nvm = &hw->nvm;
  1083. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  1084. s32 ret_val;
  1085. u16 i;
  1086. if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
  1087. (words == 0)) {
  1088. hw_dbg(hw, "nvm parameter(s) out of bounds\n");
  1089. return -E1000_ERR_NVM;
  1090. }
  1091. ret_val = e1000_acquire_swflag_ich8lan(hw);
  1092. if (ret_val)
  1093. return ret_val;
  1094. for (i = 0; i < words; i++) {
  1095. dev_spec->shadow_ram[offset+i].modified = 1;
  1096. dev_spec->shadow_ram[offset+i].value = data[i];
  1097. }
  1098. e1000_release_swflag_ich8lan(hw);
  1099. return 0;
  1100. }
  1101. /**
  1102. * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
  1103. * @hw: pointer to the HW structure
  1104. *
  1105. * The NVM checksum is updated by calling the generic update_nvm_checksum,
  1106. * which writes the checksum to the shadow ram. The changes in the shadow
  1107. * ram are then committed to the EEPROM by processing each bank at a time
  1108. * checking for the modified bit and writing only the pending changes.
  1109. * After a successful commit, the shadow ram is cleared and is ready for
  1110. * future writes.
  1111. **/
  1112. static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
  1113. {
  1114. struct e1000_nvm_info *nvm = &hw->nvm;
  1115. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  1116. u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
  1117. s32 ret_val;
  1118. u16 data;
  1119. ret_val = e1000e_update_nvm_checksum_generic(hw);
  1120. if (ret_val)
  1121. return ret_val;
  1122. if (nvm->type != e1000_nvm_flash_sw)
  1123. return ret_val;
  1124. ret_val = e1000_acquire_swflag_ich8lan(hw);
  1125. if (ret_val)
  1126. return ret_val;
  1127. /*
  1128. * We're writing to the opposite bank so if we're on bank 1,
  1129. * write to bank 0 etc. We also need to erase the segment that
  1130. * is going to be written
  1131. */
  1132. ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
  1133. if (ret_val)
  1134. return ret_val;
  1135. if (bank == 0) {
  1136. new_bank_offset = nvm->flash_bank_size;
  1137. old_bank_offset = 0;
  1138. e1000_erase_flash_bank_ich8lan(hw, 1);
  1139. } else {
  1140. old_bank_offset = nvm->flash_bank_size;
  1141. new_bank_offset = 0;
  1142. e1000_erase_flash_bank_ich8lan(hw, 0);
  1143. }
  1144. for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
  1145. /*
  1146. * Determine whether to write the value stored
  1147. * in the other NVM bank or a modified value stored
  1148. * in the shadow RAM
  1149. */
  1150. if (dev_spec->shadow_ram[i].modified) {
  1151. data = dev_spec->shadow_ram[i].value;
  1152. } else {
  1153. e1000_read_flash_word_ich8lan(hw,
  1154. i + old_bank_offset,
  1155. &data);
  1156. }
  1157. /*
  1158. * If the word is 0x13, then make sure the signature bits
  1159. * (15:14) are 11b until the commit has completed.
  1160. * This will allow us to write 10b which indicates the
  1161. * signature is valid. We want to do this after the write
  1162. * has completed so that we don't mark the segment valid
  1163. * while the write is still in progress
  1164. */
  1165. if (i == E1000_ICH_NVM_SIG_WORD)
  1166. data |= E1000_ICH_NVM_SIG_MASK;
  1167. /* Convert offset to bytes. */
  1168. act_offset = (i + new_bank_offset) << 1;
  1169. udelay(100);
  1170. /* Write the bytes to the new bank. */
  1171. ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
  1172. act_offset,
  1173. (u8)data);
  1174. if (ret_val)
  1175. break;
  1176. udelay(100);
  1177. ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
  1178. act_offset + 1,
  1179. (u8)(data >> 8));
  1180. if (ret_val)
  1181. break;
  1182. }
  1183. /*
  1184. * Don't bother writing the segment valid bits if sector
  1185. * programming failed.
  1186. */
  1187. if (ret_val) {
  1188. hw_dbg(hw, "Flash commit failed.\n");
  1189. e1000_release_swflag_ich8lan(hw);
  1190. return ret_val;
  1191. }
  1192. /*
  1193. * Finally validate the new segment by setting bit 15:14
  1194. * to 10b in word 0x13 , this can be done without an
  1195. * erase as well since these bits are 11 to start with
  1196. * and we need to change bit 14 to 0b
  1197. */
  1198. act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
  1199. e1000_read_flash_word_ich8lan(hw, act_offset, &data);
  1200. data &= 0xBFFF;
  1201. ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
  1202. act_offset * 2 + 1,
  1203. (u8)(data >> 8));
  1204. if (ret_val) {
  1205. e1000_release_swflag_ich8lan(hw);
  1206. return ret_val;
  1207. }
  1208. /*
  1209. * And invalidate the previously valid segment by setting
  1210. * its signature word (0x13) high_byte to 0b. This can be
  1211. * done without an erase because flash erase sets all bits
  1212. * to 1's. We can write 1's to 0's without an erase
  1213. */
  1214. act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
  1215. ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
  1216. if (ret_val) {
  1217. e1000_release_swflag_ich8lan(hw);
  1218. return ret_val;
  1219. }
  1220. /* Great! Everything worked, we can now clear the cached entries. */
  1221. for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
  1222. dev_spec->shadow_ram[i].modified = 0;
  1223. dev_spec->shadow_ram[i].value = 0xFFFF;
  1224. }
  1225. e1000_release_swflag_ich8lan(hw);
  1226. /*
  1227. * Reload the EEPROM, or else modifications will not appear
  1228. * until after the next adapter reset.
  1229. */
  1230. e1000e_reload_nvm(hw);
  1231. msleep(10);
  1232. return ret_val;
  1233. }
  1234. /**
  1235. * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
  1236. * @hw: pointer to the HW structure
  1237. *
  1238. * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
  1239. * If the bit is 0, that the EEPROM had been modified, but the checksum was not
  1240. * calculated, in which case we need to calculate the checksum and set bit 6.
  1241. **/
  1242. static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
  1243. {
  1244. s32 ret_val;
  1245. u16 data;
  1246. /*
  1247. * Read 0x19 and check bit 6. If this bit is 0, the checksum
  1248. * needs to be fixed. This bit is an indication that the NVM
  1249. * was prepared by OEM software and did not calculate the
  1250. * checksum...a likely scenario.
  1251. */
  1252. ret_val = e1000_read_nvm(hw, 0x19, 1, &data);
  1253. if (ret_val)
  1254. return ret_val;
  1255. if ((data & 0x40) == 0) {
  1256. data |= 0x40;
  1257. ret_val = e1000_write_nvm(hw, 0x19, 1, &data);
  1258. if (ret_val)
  1259. return ret_val;
  1260. ret_val = e1000e_update_nvm_checksum(hw);
  1261. if (ret_val)
  1262. return ret_val;
  1263. }
  1264. return e1000e_validate_nvm_checksum_generic(hw);
  1265. }
  1266. /**
  1267. * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
  1268. * @hw: pointer to the HW structure
  1269. * @offset: The offset (in bytes) of the byte/word to read.
  1270. * @size: Size of data to read, 1=byte 2=word
  1271. * @data: The byte(s) to write to the NVM.
  1272. *
  1273. * Writes one/two bytes to the NVM using the flash access registers.
  1274. **/
  1275. static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
  1276. u8 size, u16 data)
  1277. {
  1278. union ich8_hws_flash_status hsfsts;
  1279. union ich8_hws_flash_ctrl hsflctl;
  1280. u32 flash_linear_addr;
  1281. u32 flash_data = 0;
  1282. s32 ret_val;
  1283. u8 count = 0;
  1284. if (size < 1 || size > 2 || data > size * 0xff ||
  1285. offset > ICH_FLASH_LINEAR_ADDR_MASK)
  1286. return -E1000_ERR_NVM;
  1287. flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
  1288. hw->nvm.flash_base_addr;
  1289. do {
  1290. udelay(1);
  1291. /* Steps */
  1292. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  1293. if (ret_val)
  1294. break;
  1295. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  1296. /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
  1297. hsflctl.hsf_ctrl.fldbcount = size -1;
  1298. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
  1299. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  1300. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  1301. if (size == 1)
  1302. flash_data = (u32)data & 0x00FF;
  1303. else
  1304. flash_data = (u32)data;
  1305. ew32flash(ICH_FLASH_FDATA0, flash_data);
  1306. /*
  1307. * check if FCERR is set to 1 , if set to 1, clear it
  1308. * and try the whole sequence a few more times else done
  1309. */
  1310. ret_val = e1000_flash_cycle_ich8lan(hw,
  1311. ICH_FLASH_WRITE_COMMAND_TIMEOUT);
  1312. if (!ret_val)
  1313. break;
  1314. /*
  1315. * If we're here, then things are most likely
  1316. * completely hosed, but if the error condition
  1317. * is detected, it won't hurt to give it another
  1318. * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
  1319. */
  1320. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  1321. if (hsfsts.hsf_status.flcerr == 1)
  1322. /* Repeat for some time before giving up. */
  1323. continue;
  1324. if (hsfsts.hsf_status.flcdone == 0) {
  1325. hw_dbg(hw, "Timeout error - flash cycle "
  1326. "did not complete.");
  1327. break;
  1328. }
  1329. } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
  1330. return ret_val;
  1331. }
  1332. /**
  1333. * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
  1334. * @hw: pointer to the HW structure
  1335. * @offset: The index of the byte to read.
  1336. * @data: The byte to write to the NVM.
  1337. *
  1338. * Writes a single byte to the NVM using the flash access registers.
  1339. **/
  1340. static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
  1341. u8 data)
  1342. {
  1343. u16 word = (u16)data;
  1344. return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
  1345. }
  1346. /**
  1347. * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
  1348. * @hw: pointer to the HW structure
  1349. * @offset: The offset of the byte to write.
  1350. * @byte: The byte to write to the NVM.
  1351. *
  1352. * Writes a single byte to the NVM using the flash access registers.
  1353. * Goes through a retry algorithm before giving up.
  1354. **/
  1355. static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
  1356. u32 offset, u8 byte)
  1357. {
  1358. s32 ret_val;
  1359. u16 program_retries;
  1360. ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
  1361. if (!ret_val)
  1362. return ret_val;
  1363. for (program_retries = 0; program_retries < 100; program_retries++) {
  1364. hw_dbg(hw, "Retrying Byte %2.2X at offset %u\n", byte, offset);
  1365. udelay(100);
  1366. ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
  1367. if (!ret_val)
  1368. break;
  1369. }
  1370. if (program_retries == 100)
  1371. return -E1000_ERR_NVM;
  1372. return 0;
  1373. }
  1374. /**
  1375. * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
  1376. * @hw: pointer to the HW structure
  1377. * @bank: 0 for first bank, 1 for second bank, etc.
  1378. *
  1379. * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
  1380. * bank N is 4096 * N + flash_reg_addr.
  1381. **/
  1382. static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
  1383. {
  1384. struct e1000_nvm_info *nvm = &hw->nvm;
  1385. union ich8_hws_flash_status hsfsts;
  1386. union ich8_hws_flash_ctrl hsflctl;
  1387. u32 flash_linear_addr;
  1388. /* bank size is in 16bit words - adjust to bytes */
  1389. u32 flash_bank_size = nvm->flash_bank_size * 2;
  1390. s32 ret_val;
  1391. s32 count = 0;
  1392. s32 iteration;
  1393. s32 sector_size;
  1394. s32 j;
  1395. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  1396. /*
  1397. * Determine HW Sector size: Read BERASE bits of hw flash status
  1398. * register
  1399. * 00: The Hw sector is 256 bytes, hence we need to erase 16
  1400. * consecutive sectors. The start index for the nth Hw sector
  1401. * can be calculated as = bank * 4096 + n * 256
  1402. * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
  1403. * The start index for the nth Hw sector can be calculated
  1404. * as = bank * 4096
  1405. * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
  1406. * (ich9 only, otherwise error condition)
  1407. * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
  1408. */
  1409. switch (hsfsts.hsf_status.berasesz) {
  1410. case 0:
  1411. /* Hw sector size 256 */
  1412. sector_size = ICH_FLASH_SEG_SIZE_256;
  1413. iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
  1414. break;
  1415. case 1:
  1416. sector_size = ICH_FLASH_SEG_SIZE_4K;
  1417. iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_4K;
  1418. break;
  1419. case 2:
  1420. if (hw->mac.type == e1000_ich9lan) {
  1421. sector_size = ICH_FLASH_SEG_SIZE_8K;
  1422. iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_8K;
  1423. } else {
  1424. return -E1000_ERR_NVM;
  1425. }
  1426. break;
  1427. case 3:
  1428. sector_size = ICH_FLASH_SEG_SIZE_64K;
  1429. iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_64K;
  1430. break;
  1431. default:
  1432. return -E1000_ERR_NVM;
  1433. }
  1434. /* Start with the base address, then add the sector offset. */
  1435. flash_linear_addr = hw->nvm.flash_base_addr;
  1436. flash_linear_addr += (bank) ? (sector_size * iteration) : 0;
  1437. for (j = 0; j < iteration ; j++) {
  1438. do {
  1439. /* Steps */
  1440. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  1441. if (ret_val)
  1442. return ret_val;
  1443. /*
  1444. * Write a value 11 (block Erase) in Flash
  1445. * Cycle field in hw flash control
  1446. */
  1447. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  1448. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
  1449. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  1450. /*
  1451. * Write the last 24 bits of an index within the
  1452. * block into Flash Linear address field in Flash
  1453. * Address.
  1454. */
  1455. flash_linear_addr += (j * sector_size);
  1456. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  1457. ret_val = e1000_flash_cycle_ich8lan(hw,
  1458. ICH_FLASH_ERASE_COMMAND_TIMEOUT);
  1459. if (ret_val == 0)
  1460. break;
  1461. /*
  1462. * Check if FCERR is set to 1. If 1,
  1463. * clear it and try the whole sequence
  1464. * a few more times else Done
  1465. */
  1466. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  1467. if (hsfsts.hsf_status.flcerr == 1)
  1468. /* repeat for some time before giving up */
  1469. continue;
  1470. else if (hsfsts.hsf_status.flcdone == 0)
  1471. return ret_val;
  1472. } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
  1473. }
  1474. return 0;
  1475. }
  1476. /**
  1477. * e1000_valid_led_default_ich8lan - Set the default LED settings
  1478. * @hw: pointer to the HW structure
  1479. * @data: Pointer to the LED settings
  1480. *
  1481. * Reads the LED default settings from the NVM to data. If the NVM LED
  1482. * settings is all 0's or F's, set the LED default to a valid LED default
  1483. * setting.
  1484. **/
  1485. static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
  1486. {
  1487. s32 ret_val;
  1488. ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
  1489. if (ret_val) {
  1490. hw_dbg(hw, "NVM Read Error\n");
  1491. return ret_val;
  1492. }
  1493. if (*data == ID_LED_RESERVED_0000 ||
  1494. *data == ID_LED_RESERVED_FFFF)
  1495. *data = ID_LED_DEFAULT_ICH8LAN;
  1496. return 0;
  1497. }
  1498. /**
  1499. * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
  1500. * @hw: pointer to the HW structure
  1501. *
  1502. * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
  1503. * register, so the the bus width is hard coded.
  1504. **/
  1505. static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
  1506. {
  1507. struct e1000_bus_info *bus = &hw->bus;
  1508. s32 ret_val;
  1509. ret_val = e1000e_get_bus_info_pcie(hw);
  1510. /*
  1511. * ICH devices are "PCI Express"-ish. They have
  1512. * a configuration space, but do not contain
  1513. * PCI Express Capability registers, so bus width
  1514. * must be hardcoded.
  1515. */
  1516. if (bus->width == e1000_bus_width_unknown)
  1517. bus->width = e1000_bus_width_pcie_x1;
  1518. return ret_val;
  1519. }
  1520. /**
  1521. * e1000_reset_hw_ich8lan - Reset the hardware
  1522. * @hw: pointer to the HW structure
  1523. *
  1524. * Does a full reset of the hardware which includes a reset of the PHY and
  1525. * MAC.
  1526. **/
  1527. static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
  1528. {
  1529. u32 ctrl, icr, kab;
  1530. s32 ret_val;
  1531. /*
  1532. * Prevent the PCI-E bus from sticking if there is no TLP connection
  1533. * on the last TLP read/write transaction when MAC is reset.
  1534. */
  1535. ret_val = e1000e_disable_pcie_master(hw);
  1536. if (ret_val) {
  1537. hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
  1538. }
  1539. hw_dbg(hw, "Masking off all interrupts\n");
  1540. ew32(IMC, 0xffffffff);
  1541. /*
  1542. * Disable the Transmit and Receive units. Then delay to allow
  1543. * any pending transactions to complete before we hit the MAC
  1544. * with the global reset.
  1545. */
  1546. ew32(RCTL, 0);
  1547. ew32(TCTL, E1000_TCTL_PSP);
  1548. e1e_flush();
  1549. msleep(10);
  1550. /* Workaround for ICH8 bit corruption issue in FIFO memory */
  1551. if (hw->mac.type == e1000_ich8lan) {
  1552. /* Set Tx and Rx buffer allocation to 8k apiece. */
  1553. ew32(PBA, E1000_PBA_8K);
  1554. /* Set Packet Buffer Size to 16k. */
  1555. ew32(PBS, E1000_PBS_16K);
  1556. }
  1557. ctrl = er32(CTRL);
  1558. if (!e1000_check_reset_block(hw)) {
  1559. /*
  1560. * PHY HW reset requires MAC CORE reset at the same
  1561. * time to make sure the interface between MAC and the
  1562. * external PHY is reset.
  1563. */
  1564. ctrl |= E1000_CTRL_PHY_RST;
  1565. }
  1566. ret_val = e1000_acquire_swflag_ich8lan(hw);
  1567. hw_dbg(hw, "Issuing a global reset to ich8lan");
  1568. ew32(CTRL, (ctrl | E1000_CTRL_RST));
  1569. msleep(20);
  1570. ret_val = e1000e_get_auto_rd_done(hw);
  1571. if (ret_val) {
  1572. /*
  1573. * When auto config read does not complete, do not
  1574. * return with an error. This can happen in situations
  1575. * where there is no eeprom and prevents getting link.
  1576. */
  1577. hw_dbg(hw, "Auto Read Done did not complete\n");
  1578. }
  1579. ew32(IMC, 0xffffffff);
  1580. icr = er32(ICR);
  1581. kab = er32(KABGTXD);
  1582. kab |= E1000_KABGTXD_BGSQLBIAS;
  1583. ew32(KABGTXD, kab);
  1584. return ret_val;
  1585. }
  1586. /**
  1587. * e1000_init_hw_ich8lan - Initialize the hardware
  1588. * @hw: pointer to the HW structure
  1589. *
  1590. * Prepares the hardware for transmit and receive by doing the following:
  1591. * - initialize hardware bits
  1592. * - initialize LED identification
  1593. * - setup receive address registers
  1594. * - setup flow control
  1595. * - setup transmit descriptors
  1596. * - clear statistics
  1597. **/
  1598. static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
  1599. {
  1600. struct e1000_mac_info *mac = &hw->mac;
  1601. u32 ctrl_ext, txdctl, snoop;
  1602. s32 ret_val;
  1603. u16 i;
  1604. e1000_initialize_hw_bits_ich8lan(hw);
  1605. /* Initialize identification LED */
  1606. ret_val = e1000e_id_led_init(hw);
  1607. if (ret_val) {
  1608. hw_dbg(hw, "Error initializing identification LED\n");
  1609. return ret_val;
  1610. }
  1611. /* Setup the receive address. */
  1612. e1000e_init_rx_addrs(hw, mac->rar_entry_count);
  1613. /* Zero out the Multicast HASH table */
  1614. hw_dbg(hw, "Zeroing the MTA\n");
  1615. for (i = 0; i < mac->mta_reg_count; i++)
  1616. E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
  1617. /* Setup link and flow control */
  1618. ret_val = e1000_setup_link_ich8lan(hw);
  1619. /* Set the transmit descriptor write-back policy for both queues */
  1620. txdctl = er32(TXDCTL(0));
  1621. txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
  1622. E1000_TXDCTL_FULL_TX_DESC_WB;
  1623. txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
  1624. E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
  1625. ew32(TXDCTL(0), txdctl);
  1626. txdctl = er32(TXDCTL(1));
  1627. txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
  1628. E1000_TXDCTL_FULL_TX_DESC_WB;
  1629. txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
  1630. E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
  1631. ew32(TXDCTL(1), txdctl);
  1632. /*
  1633. * ICH8 has opposite polarity of no_snoop bits.
  1634. * By default, we should use snoop behavior.
  1635. */
  1636. if (mac->type == e1000_ich8lan)
  1637. snoop = PCIE_ICH8_SNOOP_ALL;
  1638. else
  1639. snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
  1640. e1000e_set_pcie_no_snoop(hw, snoop);
  1641. ctrl_ext = er32(CTRL_EXT);
  1642. ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
  1643. ew32(CTRL_EXT, ctrl_ext);
  1644. /*
  1645. * Clear all of the statistics registers (clear on read). It is
  1646. * important that we do this after we have tried to establish link
  1647. * because the symbol error count will increment wildly if there
  1648. * is no link.
  1649. */
  1650. e1000_clear_hw_cntrs_ich8lan(hw);
  1651. return 0;
  1652. }
  1653. /**
  1654. * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
  1655. * @hw: pointer to the HW structure
  1656. *
  1657. * Sets/Clears required hardware bits necessary for correctly setting up the
  1658. * hardware for transmit and receive.
  1659. **/
  1660. static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
  1661. {
  1662. u32 reg;
  1663. /* Extended Device Control */
  1664. reg = er32(CTRL_EXT);
  1665. reg |= (1 << 22);
  1666. ew32(CTRL_EXT, reg);
  1667. /* Transmit Descriptor Control 0 */
  1668. reg = er32(TXDCTL(0));
  1669. reg |= (1 << 22);
  1670. ew32(TXDCTL(0), reg);
  1671. /* Transmit Descriptor Control 1 */
  1672. reg = er32(TXDCTL(1));
  1673. reg |= (1 << 22);
  1674. ew32(TXDCTL(1), reg);
  1675. /* Transmit Arbitration Control 0 */
  1676. reg = er32(TARC(0));
  1677. if (hw->mac.type == e1000_ich8lan)
  1678. reg |= (1 << 28) | (1 << 29);
  1679. reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
  1680. ew32(TARC(0), reg);
  1681. /* Transmit Arbitration Control 1 */
  1682. reg = er32(TARC(1));
  1683. if (er32(TCTL) & E1000_TCTL_MULR)
  1684. reg &= ~(1 << 28);
  1685. else
  1686. reg |= (1 << 28);
  1687. reg |= (1 << 24) | (1 << 26) | (1 << 30);
  1688. ew32(TARC(1), reg);
  1689. /* Device Status */
  1690. if (hw->mac.type == e1000_ich8lan) {
  1691. reg = er32(STATUS);
  1692. reg &= ~(1 << 31);
  1693. ew32(STATUS, reg);
  1694. }
  1695. }
  1696. /**
  1697. * e1000_setup_link_ich8lan - Setup flow control and link settings
  1698. * @hw: pointer to the HW structure
  1699. *
  1700. * Determines which flow control settings to use, then configures flow
  1701. * control. Calls the appropriate media-specific link configuration
  1702. * function. Assuming the adapter has a valid link partner, a valid link
  1703. * should be established. Assumes the hardware has previously been reset
  1704. * and the transmitter and receiver are not enabled.
  1705. **/
  1706. static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
  1707. {
  1708. s32 ret_val;
  1709. if (e1000_check_reset_block(hw))
  1710. return 0;
  1711. /*
  1712. * ICH parts do not have a word in the NVM to determine
  1713. * the default flow control setting, so we explicitly
  1714. * set it to full.
  1715. */
  1716. if (hw->fc.type == e1000_fc_default)
  1717. hw->fc.type = e1000_fc_full;
  1718. hw->fc.original_type = hw->fc.type;
  1719. hw_dbg(hw, "After fix-ups FlowControl is now = %x\n", hw->fc.type);
  1720. /* Continue to configure the copper link. */
  1721. ret_val = e1000_setup_copper_link_ich8lan(hw);
  1722. if (ret_val)
  1723. return ret_val;
  1724. ew32(FCTTV, hw->fc.pause_time);
  1725. return e1000e_set_fc_watermarks(hw);
  1726. }
  1727. /**
  1728. * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
  1729. * @hw: pointer to the HW structure
  1730. *
  1731. * Configures the kumeran interface to the PHY to wait the appropriate time
  1732. * when polling the PHY, then call the generic setup_copper_link to finish
  1733. * configuring the copper link.
  1734. **/
  1735. static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
  1736. {
  1737. u32 ctrl;
  1738. s32 ret_val;
  1739. u16 reg_data;
  1740. ctrl = er32(CTRL);
  1741. ctrl |= E1000_CTRL_SLU;
  1742. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1743. ew32(CTRL, ctrl);
  1744. /*
  1745. * Set the mac to wait the maximum time between each iteration
  1746. * and increase the max iterations when polling the phy;
  1747. * this fixes erroneous timeouts at 10Mbps.
  1748. */
  1749. ret_val = e1000e_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
  1750. if (ret_val)
  1751. return ret_val;
  1752. ret_val = e1000e_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
  1753. if (ret_val)
  1754. return ret_val;
  1755. reg_data |= 0x3F;
  1756. ret_val = e1000e_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
  1757. if (ret_val)
  1758. return ret_val;
  1759. if (hw->phy.type == e1000_phy_igp_3) {
  1760. ret_val = e1000e_copper_link_setup_igp(hw);
  1761. if (ret_val)
  1762. return ret_val;
  1763. } else if (hw->phy.type == e1000_phy_bm) {
  1764. ret_val = e1000e_copper_link_setup_m88(hw);
  1765. if (ret_val)
  1766. return ret_val;
  1767. }
  1768. if (hw->phy.type == e1000_phy_ife) {
  1769. ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
  1770. if (ret_val)
  1771. return ret_val;
  1772. reg_data &= ~IFE_PMC_AUTO_MDIX;
  1773. switch (hw->phy.mdix) {
  1774. case 1:
  1775. reg_data &= ~IFE_PMC_FORCE_MDIX;
  1776. break;
  1777. case 2:
  1778. reg_data |= IFE_PMC_FORCE_MDIX;
  1779. break;
  1780. case 0:
  1781. default:
  1782. reg_data |= IFE_PMC_AUTO_MDIX;
  1783. break;
  1784. }
  1785. ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
  1786. if (ret_val)
  1787. return ret_val;
  1788. }
  1789. return e1000e_setup_copper_link(hw);
  1790. }
  1791. /**
  1792. * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
  1793. * @hw: pointer to the HW structure
  1794. * @speed: pointer to store current link speed
  1795. * @duplex: pointer to store the current link duplex
  1796. *
  1797. * Calls the generic get_speed_and_duplex to retrieve the current link
  1798. * information and then calls the Kumeran lock loss workaround for links at
  1799. * gigabit speeds.
  1800. **/
  1801. static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
  1802. u16 *duplex)
  1803. {
  1804. s32 ret_val;
  1805. ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
  1806. if (ret_val)
  1807. return ret_val;
  1808. if ((hw->mac.type == e1000_ich8lan) &&
  1809. (hw->phy.type == e1000_phy_igp_3) &&
  1810. (*speed == SPEED_1000)) {
  1811. ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
  1812. }
  1813. return ret_val;
  1814. }
  1815. /**
  1816. * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
  1817. * @hw: pointer to the HW structure
  1818. *
  1819. * Work-around for 82566 Kumeran PCS lock loss:
  1820. * On link status change (i.e. PCI reset, speed change) and link is up and
  1821. * speed is gigabit-
  1822. * 0) if workaround is optionally disabled do nothing
  1823. * 1) wait 1ms for Kumeran link to come up
  1824. * 2) check Kumeran Diagnostic register PCS lock loss bit
  1825. * 3) if not set the link is locked (all is good), otherwise...
  1826. * 4) reset the PHY
  1827. * 5) repeat up to 10 times
  1828. * Note: this is only called for IGP3 copper when speed is 1gb.
  1829. **/
  1830. static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
  1831. {
  1832. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  1833. u32 phy_ctrl;
  1834. s32 ret_val;
  1835. u16 i, data;
  1836. bool link;
  1837. if (!dev_spec->kmrn_lock_loss_workaround_enabled)
  1838. return 0;
  1839. /*
  1840. * Make sure link is up before proceeding. If not just return.
  1841. * Attempting this while link is negotiating fouled up link
  1842. * stability
  1843. */
  1844. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  1845. if (!link)
  1846. return 0;
  1847. for (i = 0; i < 10; i++) {
  1848. /* read once to clear */
  1849. ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
  1850. if (ret_val)
  1851. return ret_val;
  1852. /* and again to get new status */
  1853. ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
  1854. if (ret_val)
  1855. return ret_val;
  1856. /* check for PCS lock */
  1857. if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
  1858. return 0;
  1859. /* Issue PHY reset */
  1860. e1000_phy_hw_reset(hw);
  1861. mdelay(5);
  1862. }
  1863. /* Disable GigE link negotiation */
  1864. phy_ctrl = er32(PHY_CTRL);
  1865. phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
  1866. E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
  1867. ew32(PHY_CTRL, phy_ctrl);
  1868. /*
  1869. * Call gig speed drop workaround on Gig disable before accessing
  1870. * any PHY registers
  1871. */
  1872. e1000e_gig_downshift_workaround_ich8lan(hw);
  1873. /* unable to acquire PCS lock */
  1874. return -E1000_ERR_PHY;
  1875. }
  1876. /**
  1877. * e1000_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
  1878. * @hw: pointer to the HW structure
  1879. * @state: boolean value used to set the current Kumeran workaround state
  1880. *
  1881. * If ICH8, set the current Kumeran workaround state (enabled - TRUE
  1882. * /disabled - FALSE).
  1883. **/
  1884. void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
  1885. bool state)
  1886. {
  1887. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  1888. if (hw->mac.type != e1000_ich8lan) {
  1889. hw_dbg(hw, "Workaround applies to ICH8 only.\n");
  1890. return;
  1891. }
  1892. dev_spec->kmrn_lock_loss_workaround_enabled = state;
  1893. }
  1894. /**
  1895. * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
  1896. * @hw: pointer to the HW structure
  1897. *
  1898. * Workaround for 82566 power-down on D3 entry:
  1899. * 1) disable gigabit link
  1900. * 2) write VR power-down enable
  1901. * 3) read it back
  1902. * Continue if successful, else issue LCD reset and repeat
  1903. **/
  1904. void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
  1905. {
  1906. u32 reg;
  1907. u16 data;
  1908. u8 retry = 0;
  1909. if (hw->phy.type != e1000_phy_igp_3)
  1910. return;
  1911. /* Try the workaround twice (if needed) */
  1912. do {
  1913. /* Disable link */
  1914. reg = er32(PHY_CTRL);
  1915. reg |= (E1000_PHY_CTRL_GBE_DISABLE |
  1916. E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
  1917. ew32(PHY_CTRL, reg);
  1918. /*
  1919. * Call gig speed drop workaround on Gig disable before
  1920. * accessing any PHY registers
  1921. */
  1922. if (hw->mac.type == e1000_ich8lan)
  1923. e1000e_gig_downshift_workaround_ich8lan(hw);
  1924. /* Write VR power-down enable */
  1925. e1e_rphy(hw, IGP3_VR_CTRL, &data);
  1926. data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
  1927. e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
  1928. /* Read it back and test */
  1929. e1e_rphy(hw, IGP3_VR_CTRL, &data);
  1930. data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
  1931. if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
  1932. break;
  1933. /* Issue PHY reset and repeat at most one more time */
  1934. reg = er32(CTRL);
  1935. ew32(CTRL, reg | E1000_CTRL_PHY_RST);
  1936. retry++;
  1937. } while (retry);
  1938. }
  1939. /**
  1940. * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
  1941. * @hw: pointer to the HW structure
  1942. *
  1943. * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
  1944. * LPLU, Gig disable, MDIC PHY reset):
  1945. * 1) Set Kumeran Near-end loopback
  1946. * 2) Clear Kumeran Near-end loopback
  1947. * Should only be called for ICH8[m] devices with IGP_3 Phy.
  1948. **/
  1949. void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
  1950. {
  1951. s32 ret_val;
  1952. u16 reg_data;
  1953. if ((hw->mac.type != e1000_ich8lan) ||
  1954. (hw->phy.type != e1000_phy_igp_3))
  1955. return;
  1956. ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
  1957. &reg_data);
  1958. if (ret_val)
  1959. return;
  1960. reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
  1961. ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
  1962. reg_data);
  1963. if (ret_val)
  1964. return;
  1965. reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
  1966. ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
  1967. reg_data);
  1968. }
  1969. /**
  1970. * e1000e_disable_gig_wol_ich8lan - disable gig during WoL
  1971. * @hw: pointer to the HW structure
  1972. *
  1973. * During S0 to Sx transition, it is possible the link remains at gig
  1974. * instead of negotiating to a lower speed. Before going to Sx, set
  1975. * 'LPLU Enabled' and 'Gig Disable' to force link speed negotiation
  1976. * to a lower speed.
  1977. *
  1978. * Should only be called for ICH9 and ICH10 devices.
  1979. **/
  1980. void e1000e_disable_gig_wol_ich8lan(struct e1000_hw *hw)
  1981. {
  1982. u32 phy_ctrl;
  1983. if ((hw->mac.type == e1000_ich10lan) ||
  1984. (hw->mac.type == e1000_ich9lan)) {
  1985. phy_ctrl = er32(PHY_CTRL);
  1986. phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU |
  1987. E1000_PHY_CTRL_GBE_DISABLE;
  1988. ew32(PHY_CTRL, phy_ctrl);
  1989. }
  1990. return;
  1991. }
  1992. /**
  1993. * e1000_cleanup_led_ich8lan - Restore the default LED operation
  1994. * @hw: pointer to the HW structure
  1995. *
  1996. * Return the LED back to the default configuration.
  1997. **/
  1998. static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
  1999. {
  2000. if (hw->phy.type == e1000_phy_ife)
  2001. return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
  2002. ew32(LEDCTL, hw->mac.ledctl_default);
  2003. return 0;
  2004. }
  2005. /**
  2006. * e1000_led_on_ich8lan - Turn LEDs on
  2007. * @hw: pointer to the HW structure
  2008. *
  2009. * Turn on the LEDs.
  2010. **/
  2011. static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
  2012. {
  2013. if (hw->phy.type == e1000_phy_ife)
  2014. return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
  2015. (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
  2016. ew32(LEDCTL, hw->mac.ledctl_mode2);
  2017. return 0;
  2018. }
  2019. /**
  2020. * e1000_led_off_ich8lan - Turn LEDs off
  2021. * @hw: pointer to the HW structure
  2022. *
  2023. * Turn off the LEDs.
  2024. **/
  2025. static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
  2026. {
  2027. if (hw->phy.type == e1000_phy_ife)
  2028. return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
  2029. (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
  2030. ew32(LEDCTL, hw->mac.ledctl_mode1);
  2031. return 0;
  2032. }
  2033. /**
  2034. * e1000_get_cfg_done_ich8lan - Read config done bit
  2035. * @hw: pointer to the HW structure
  2036. *
  2037. * Read the management control register for the config done bit for
  2038. * completion status. NOTE: silicon which is EEPROM-less will fail trying
  2039. * to read the config done bit, so an error is *ONLY* logged and returns
  2040. * E1000_SUCCESS. If we were to return with error, EEPROM-less silicon
  2041. * would not be able to be reset or change link.
  2042. **/
  2043. static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
  2044. {
  2045. u32 bank = 0;
  2046. e1000e_get_cfg_done(hw);
  2047. /* If EEPROM is not marked present, init the IGP 3 PHY manually */
  2048. if (hw->mac.type != e1000_ich10lan) {
  2049. if (((er32(EECD) & E1000_EECD_PRES) == 0) &&
  2050. (hw->phy.type == e1000_phy_igp_3)) {
  2051. e1000e_phy_init_script_igp3(hw);
  2052. }
  2053. } else {
  2054. if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
  2055. /* Maybe we should do a basic PHY config */
  2056. hw_dbg(hw, "EEPROM not present\n");
  2057. return -E1000_ERR_CONFIG;
  2058. }
  2059. }
  2060. return 0;
  2061. }
  2062. /**
  2063. * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
  2064. * @hw: pointer to the HW structure
  2065. *
  2066. * Clears hardware counters specific to the silicon family and calls
  2067. * clear_hw_cntrs_generic to clear all general purpose counters.
  2068. **/
  2069. static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
  2070. {
  2071. u32 temp;
  2072. e1000e_clear_hw_cntrs_base(hw);
  2073. temp = er32(ALGNERRC);
  2074. temp = er32(RXERRC);
  2075. temp = er32(TNCRS);
  2076. temp = er32(CEXTERR);
  2077. temp = er32(TSCTC);
  2078. temp = er32(TSCTFC);
  2079. temp = er32(MGTPRC);
  2080. temp = er32(MGTPDC);
  2081. temp = er32(MGTPTC);
  2082. temp = er32(IAC);
  2083. temp = er32(ICRXOC);
  2084. }
  2085. static struct e1000_mac_operations ich8_mac_ops = {
  2086. .check_mng_mode = e1000_check_mng_mode_ich8lan,
  2087. .check_for_link = e1000e_check_for_copper_link,
  2088. .cleanup_led = e1000_cleanup_led_ich8lan,
  2089. .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
  2090. .get_bus_info = e1000_get_bus_info_ich8lan,
  2091. .get_link_up_info = e1000_get_link_up_info_ich8lan,
  2092. .led_on = e1000_led_on_ich8lan,
  2093. .led_off = e1000_led_off_ich8lan,
  2094. .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
  2095. .reset_hw = e1000_reset_hw_ich8lan,
  2096. .init_hw = e1000_init_hw_ich8lan,
  2097. .setup_link = e1000_setup_link_ich8lan,
  2098. .setup_physical_interface= e1000_setup_copper_link_ich8lan,
  2099. };
  2100. static struct e1000_phy_operations ich8_phy_ops = {
  2101. .acquire_phy = e1000_acquire_swflag_ich8lan,
  2102. .check_reset_block = e1000_check_reset_block_ich8lan,
  2103. .commit_phy = NULL,
  2104. .force_speed_duplex = e1000_phy_force_speed_duplex_ich8lan,
  2105. .get_cfg_done = e1000_get_cfg_done_ich8lan,
  2106. .get_cable_length = e1000e_get_cable_length_igp_2,
  2107. .get_phy_info = e1000_get_phy_info_ich8lan,
  2108. .read_phy_reg = e1000e_read_phy_reg_igp,
  2109. .release_phy = e1000_release_swflag_ich8lan,
  2110. .reset_phy = e1000_phy_hw_reset_ich8lan,
  2111. .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
  2112. .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
  2113. .write_phy_reg = e1000e_write_phy_reg_igp,
  2114. };
  2115. static struct e1000_nvm_operations ich8_nvm_ops = {
  2116. .acquire_nvm = e1000_acquire_swflag_ich8lan,
  2117. .read_nvm = e1000_read_nvm_ich8lan,
  2118. .release_nvm = e1000_release_swflag_ich8lan,
  2119. .update_nvm = e1000_update_nvm_checksum_ich8lan,
  2120. .valid_led_default = e1000_valid_led_default_ich8lan,
  2121. .validate_nvm = e1000_validate_nvm_checksum_ich8lan,
  2122. .write_nvm = e1000_write_nvm_ich8lan,
  2123. };
  2124. struct e1000_info e1000_ich8_info = {
  2125. .mac = e1000_ich8lan,
  2126. .flags = FLAG_HAS_WOL
  2127. | FLAG_IS_ICH
  2128. | FLAG_RX_CSUM_ENABLED
  2129. | FLAG_HAS_CTRLEXT_ON_LOAD
  2130. | FLAG_HAS_AMT
  2131. | FLAG_HAS_FLASH
  2132. | FLAG_APME_IN_WUC,
  2133. .pba = 8,
  2134. .get_variants = e1000_get_variants_ich8lan,
  2135. .mac_ops = &ich8_mac_ops,
  2136. .phy_ops = &ich8_phy_ops,
  2137. .nvm_ops = &ich8_nvm_ops,
  2138. };
  2139. struct e1000_info e1000_ich9_info = {
  2140. .mac = e1000_ich9lan,
  2141. .flags = FLAG_HAS_JUMBO_FRAMES
  2142. | FLAG_IS_ICH
  2143. | FLAG_HAS_WOL
  2144. | FLAG_RX_CSUM_ENABLED
  2145. | FLAG_HAS_CTRLEXT_ON_LOAD
  2146. | FLAG_HAS_AMT
  2147. | FLAG_HAS_ERT
  2148. | FLAG_HAS_FLASH
  2149. | FLAG_APME_IN_WUC,
  2150. .pba = 10,
  2151. .get_variants = e1000_get_variants_ich8lan,
  2152. .mac_ops = &ich8_mac_ops,
  2153. .phy_ops = &ich8_phy_ops,
  2154. .nvm_ops = &ich8_nvm_ops,
  2155. };
  2156. struct e1000_info e1000_ich10_info = {
  2157. .mac = e1000_ich10lan,
  2158. .flags = FLAG_HAS_JUMBO_FRAMES
  2159. | FLAG_IS_ICH
  2160. | FLAG_HAS_WOL
  2161. | FLAG_RX_CSUM_ENABLED
  2162. | FLAG_HAS_CTRLEXT_ON_LOAD
  2163. | FLAG_HAS_AMT
  2164. | FLAG_HAS_ERT
  2165. | FLAG_HAS_FLASH
  2166. | FLAG_APME_IN_WUC,
  2167. .pba = 10,
  2168. .get_variants = e1000_get_variants_ich8lan,
  2169. .mac_ops = &ich8_mac_ops,
  2170. .phy_ops = &ich8_phy_ops,
  2171. .nvm_ops = &ich8_nvm_ops,
  2172. };