PageRenderTime 161ms CodeModel.GetById 32ms RepoModel.GetById 6ms app.codeStats 1ms

/drivers/net/ethernet/intel/e1000e/ich8lan.c

http://github.com/mirrors/linux
C | 5952 lines | 3689 code | 779 blank | 1484 comment | 789 complexity | 03598df2fc875c966397072596100a82 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 1999 - 2018 Intel Corporation. */
  3. /* 82562G 10/100 Network Connection
  4. * 82562G-2 10/100 Network Connection
  5. * 82562GT 10/100 Network Connection
  6. * 82562GT-2 10/100 Network Connection
  7. * 82562V 10/100 Network Connection
  8. * 82562V-2 10/100 Network Connection
  9. * 82566DC-2 Gigabit Network Connection
  10. * 82566DC Gigabit Network Connection
  11. * 82566DM-2 Gigabit Network Connection
  12. * 82566DM Gigabit Network Connection
  13. * 82566MC Gigabit Network Connection
  14. * 82566MM Gigabit Network Connection
  15. * 82567LM Gigabit Network Connection
  16. * 82567LF Gigabit Network Connection
  17. * 82567V Gigabit Network Connection
  18. * 82567LM-2 Gigabit Network Connection
  19. * 82567LF-2 Gigabit Network Connection
  20. * 82567V-2 Gigabit Network Connection
  21. * 82567LF-3 Gigabit Network Connection
  22. * 82567LM-3 Gigabit Network Connection
  23. * 82567LM-4 Gigabit Network Connection
  24. * 82577LM Gigabit Network Connection
  25. * 82577LC Gigabit Network Connection
  26. * 82578DM Gigabit Network Connection
  27. * 82578DC Gigabit Network Connection
  28. * 82579LM Gigabit Network Connection
  29. * 82579V Gigabit Network Connection
  30. * Ethernet Connection I217-LM
  31. * Ethernet Connection I217-V
  32. * Ethernet Connection I218-V
  33. * Ethernet Connection I218-LM
  34. * Ethernet Connection (2) I218-LM
  35. * Ethernet Connection (2) I218-V
  36. * Ethernet Connection (3) I218-LM
  37. * Ethernet Connection (3) I218-V
  38. */
  39. #include "e1000.h"
  40. /* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
  41. /* Offset 04h HSFSTS */
  42. union ich8_hws_flash_status {
  43. struct ich8_hsfsts {
  44. u16 flcdone:1; /* bit 0 Flash Cycle Done */
  45. u16 flcerr:1; /* bit 1 Flash Cycle Error */
  46. u16 dael:1; /* bit 2 Direct Access error Log */
  47. u16 berasesz:2; /* bit 4:3 Sector Erase Size */
  48. u16 flcinprog:1; /* bit 5 flash cycle in Progress */
  49. u16 reserved1:2; /* bit 13:6 Reserved */
  50. u16 reserved2:6; /* bit 13:6 Reserved */
  51. u16 fldesvalid:1; /* bit 14 Flash Descriptor Valid */
  52. u16 flockdn:1; /* bit 15 Flash Config Lock-Down */
  53. } hsf_status;
  54. u16 regval;
  55. };
  56. /* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
  57. /* Offset 06h FLCTL */
  58. union ich8_hws_flash_ctrl {
  59. struct ich8_hsflctl {
  60. u16 flcgo:1; /* 0 Flash Cycle Go */
  61. u16 flcycle:2; /* 2:1 Flash Cycle */
  62. u16 reserved:5; /* 7:3 Reserved */
  63. u16 fldbcount:2; /* 9:8 Flash Data Byte Count */
  64. u16 flockdn:6; /* 15:10 Reserved */
  65. } hsf_ctrl;
  66. u16 regval;
  67. };
  68. /* ICH Flash Region Access Permissions */
  69. union ich8_hws_flash_regacc {
  70. struct ich8_flracc {
  71. u32 grra:8; /* 0:7 GbE region Read Access */
  72. u32 grwa:8; /* 8:15 GbE region Write Access */
  73. u32 gmrag:8; /* 23:16 GbE Master Read Access Grant */
  74. u32 gmwag:8; /* 31:24 GbE Master Write Access Grant */
  75. } hsf_flregacc;
  76. u16 regval;
  77. };
  78. /* ICH Flash Protected Region */
  79. union ich8_flash_protected_range {
  80. struct ich8_pr {
  81. u32 base:13; /* 0:12 Protected Range Base */
  82. u32 reserved1:2; /* 13:14 Reserved */
  83. u32 rpe:1; /* 15 Read Protection Enable */
  84. u32 limit:13; /* 16:28 Protected Range Limit */
  85. u32 reserved2:2; /* 29:30 Reserved */
  86. u32 wpe:1; /* 31 Write Protection Enable */
  87. } range;
  88. u32 regval;
  89. };
  90. static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
  91. static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
  92. static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
  93. static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
  94. u32 offset, u8 byte);
  95. static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
  96. u8 *data);
  97. static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
  98. u16 *data);
  99. static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
  100. u8 size, u16 *data);
  101. static s32 e1000_read_flash_data32_ich8lan(struct e1000_hw *hw, u32 offset,
  102. u32 *data);
  103. static s32 e1000_read_flash_dword_ich8lan(struct e1000_hw *hw,
  104. u32 offset, u32 *data);
  105. static s32 e1000_write_flash_data32_ich8lan(struct e1000_hw *hw,
  106. u32 offset, u32 data);
  107. static s32 e1000_retry_write_flash_dword_ich8lan(struct e1000_hw *hw,
  108. u32 offset, u32 dword);
  109. static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
  110. static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
  111. static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
  112. static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
  113. static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
  114. static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
  115. static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
  116. static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
  117. static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
  118. static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
  119. static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
  120. static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
  121. static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
  122. static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
  123. static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
  124. static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
  125. static int e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index);
  126. static int e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index);
  127. static u32 e1000_rar_get_count_pch_lpt(struct e1000_hw *hw);
  128. static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
  129. static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
  130. static s32 e1000_disable_ulp_lpt_lp(struct e1000_hw *hw, bool force);
  131. static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw);
  132. static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state);
  133. static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
  134. {
  135. return readw(hw->flash_address + reg);
  136. }
  137. static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
  138. {
  139. return readl(hw->flash_address + reg);
  140. }
  141. static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
  142. {
  143. writew(val, hw->flash_address + reg);
  144. }
  145. static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
  146. {
  147. writel(val, hw->flash_address + reg);
  148. }
  149. #define er16flash(reg) __er16flash(hw, (reg))
  150. #define er32flash(reg) __er32flash(hw, (reg))
  151. #define ew16flash(reg, val) __ew16flash(hw, (reg), (val))
  152. #define ew32flash(reg, val) __ew32flash(hw, (reg), (val))
  153. /**
  154. * e1000_phy_is_accessible_pchlan - Check if able to access PHY registers
  155. * @hw: pointer to the HW structure
  156. *
  157. * Test access to the PHY registers by reading the PHY ID registers. If
  158. * the PHY ID is already known (e.g. resume path) compare it with known ID,
  159. * otherwise assume the read PHY ID is correct if it is valid.
  160. *
  161. * Assumes the sw/fw/hw semaphore is already acquired.
  162. **/
  163. static bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
  164. {
  165. u16 phy_reg = 0;
  166. u32 phy_id = 0;
  167. s32 ret_val = 0;
  168. u16 retry_count;
  169. u32 mac_reg = 0;
  170. for (retry_count = 0; retry_count < 2; retry_count++) {
  171. ret_val = e1e_rphy_locked(hw, MII_PHYSID1, &phy_reg);
  172. if (ret_val || (phy_reg == 0xFFFF))
  173. continue;
  174. phy_id = (u32)(phy_reg << 16);
  175. ret_val = e1e_rphy_locked(hw, MII_PHYSID2, &phy_reg);
  176. if (ret_val || (phy_reg == 0xFFFF)) {
  177. phy_id = 0;
  178. continue;
  179. }
  180. phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
  181. break;
  182. }
  183. if (hw->phy.id) {
  184. if (hw->phy.id == phy_id)
  185. goto out;
  186. } else if (phy_id) {
  187. hw->phy.id = phy_id;
  188. hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
  189. goto out;
  190. }
  191. /* In case the PHY needs to be in mdio slow mode,
  192. * set slow mode and try to get the PHY id again.
  193. */
  194. if (hw->mac.type < e1000_pch_lpt) {
  195. hw->phy.ops.release(hw);
  196. ret_val = e1000_set_mdio_slow_mode_hv(hw);
  197. if (!ret_val)
  198. ret_val = e1000e_get_phy_id(hw);
  199. hw->phy.ops.acquire(hw);
  200. }
  201. if (ret_val)
  202. return false;
  203. out:
  204. if (hw->mac.type >= e1000_pch_lpt) {
  205. /* Only unforce SMBus if ME is not active */
  206. if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
  207. /* Unforce SMBus mode in PHY */
  208. e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
  209. phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
  210. e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
  211. /* Unforce SMBus mode in MAC */
  212. mac_reg = er32(CTRL_EXT);
  213. mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
  214. ew32(CTRL_EXT, mac_reg);
  215. }
  216. }
  217. return true;
  218. }
  219. /**
  220. * e1000_toggle_lanphypc_pch_lpt - toggle the LANPHYPC pin value
  221. * @hw: pointer to the HW structure
  222. *
  223. * Toggling the LANPHYPC pin value fully power-cycles the PHY and is
  224. * used to reset the PHY to a quiescent state when necessary.
  225. **/
  226. static void e1000_toggle_lanphypc_pch_lpt(struct e1000_hw *hw)
  227. {
  228. u32 mac_reg;
  229. /* Set Phy Config Counter to 50msec */
  230. mac_reg = er32(FEXTNVM3);
  231. mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
  232. mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
  233. ew32(FEXTNVM3, mac_reg);
  234. /* Toggle LANPHYPC Value bit */
  235. mac_reg = er32(CTRL);
  236. mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
  237. mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
  238. ew32(CTRL, mac_reg);
  239. e1e_flush();
  240. usleep_range(10, 20);
  241. mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
  242. ew32(CTRL, mac_reg);
  243. e1e_flush();
  244. if (hw->mac.type < e1000_pch_lpt) {
  245. msleep(50);
  246. } else {
  247. u16 count = 20;
  248. do {
  249. usleep_range(5000, 6000);
  250. } while (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LPCD) && count--);
  251. msleep(30);
  252. }
  253. }
  254. /**
  255. * e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
  256. * @hw: pointer to the HW structure
  257. *
  258. * Workarounds/flow necessary for PHY initialization during driver load
  259. * and resume paths.
  260. **/
  261. static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
  262. {
  263. struct e1000_adapter *adapter = hw->adapter;
  264. u32 mac_reg, fwsm = er32(FWSM);
  265. s32 ret_val;
  266. /* Gate automatic PHY configuration by hardware on managed and
  267. * non-managed 82579 and newer adapters.
  268. */
  269. e1000_gate_hw_phy_config_ich8lan(hw, true);
  270. /* It is not possible to be certain of the current state of ULP
  271. * so forcibly disable it.
  272. */
  273. hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_unknown;
  274. e1000_disable_ulp_lpt_lp(hw, true);
  275. ret_val = hw->phy.ops.acquire(hw);
  276. if (ret_val) {
  277. e_dbg("Failed to initialize PHY flow\n");
  278. goto out;
  279. }
  280. /* The MAC-PHY interconnect may be in SMBus mode. If the PHY is
  281. * inaccessible and resetting the PHY is not blocked, toggle the
  282. * LANPHYPC Value bit to force the interconnect to PCIe mode.
  283. */
  284. switch (hw->mac.type) {
  285. case e1000_pch_lpt:
  286. case e1000_pch_spt:
  287. case e1000_pch_cnp:
  288. case e1000_pch_tgp:
  289. case e1000_pch_adp:
  290. if (e1000_phy_is_accessible_pchlan(hw))
  291. break;
  292. /* Before toggling LANPHYPC, see if PHY is accessible by
  293. * forcing MAC to SMBus mode first.
  294. */
  295. mac_reg = er32(CTRL_EXT);
  296. mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
  297. ew32(CTRL_EXT, mac_reg);
  298. /* Wait 50 milliseconds for MAC to finish any retries
  299. * that it might be trying to perform from previous
  300. * attempts to acknowledge any phy read requests.
  301. */
  302. msleep(50);
  303. /* fall-through */
  304. case e1000_pch2lan:
  305. if (e1000_phy_is_accessible_pchlan(hw))
  306. break;
  307. /* fall-through */
  308. case e1000_pchlan:
  309. if ((hw->mac.type == e1000_pchlan) &&
  310. (fwsm & E1000_ICH_FWSM_FW_VALID))
  311. break;
  312. if (hw->phy.ops.check_reset_block(hw)) {
  313. e_dbg("Required LANPHYPC toggle blocked by ME\n");
  314. ret_val = -E1000_ERR_PHY;
  315. break;
  316. }
  317. /* Toggle LANPHYPC Value bit */
  318. e1000_toggle_lanphypc_pch_lpt(hw);
  319. if (hw->mac.type >= e1000_pch_lpt) {
  320. if (e1000_phy_is_accessible_pchlan(hw))
  321. break;
  322. /* Toggling LANPHYPC brings the PHY out of SMBus mode
  323. * so ensure that the MAC is also out of SMBus mode
  324. */
  325. mac_reg = er32(CTRL_EXT);
  326. mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
  327. ew32(CTRL_EXT, mac_reg);
  328. if (e1000_phy_is_accessible_pchlan(hw))
  329. break;
  330. ret_val = -E1000_ERR_PHY;
  331. }
  332. break;
  333. default:
  334. break;
  335. }
  336. hw->phy.ops.release(hw);
  337. if (!ret_val) {
  338. /* Check to see if able to reset PHY. Print error if not */
  339. if (hw->phy.ops.check_reset_block(hw)) {
  340. e_err("Reset blocked by ME\n");
  341. goto out;
  342. }
  343. /* Reset the PHY before any access to it. Doing so, ensures
  344. * that the PHY is in a known good state before we read/write
  345. * PHY registers. The generic reset is sufficient here,
  346. * because we haven't determined the PHY type yet.
  347. */
  348. ret_val = e1000e_phy_hw_reset_generic(hw);
  349. if (ret_val)
  350. goto out;
  351. /* On a successful reset, possibly need to wait for the PHY
  352. * to quiesce to an accessible state before returning control
  353. * to the calling function. If the PHY does not quiesce, then
  354. * return E1000E_BLK_PHY_RESET, as this is the condition that
  355. * the PHY is in.
  356. */
  357. ret_val = hw->phy.ops.check_reset_block(hw);
  358. if (ret_val)
  359. e_err("ME blocked access to PHY after reset\n");
  360. }
  361. out:
  362. /* Ungate automatic PHY configuration on non-managed 82579 */
  363. if ((hw->mac.type == e1000_pch2lan) &&
  364. !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
  365. usleep_range(10000, 11000);
  366. e1000_gate_hw_phy_config_ich8lan(hw, false);
  367. }
  368. return ret_val;
  369. }
  370. /**
  371. * e1000_init_phy_params_pchlan - Initialize PHY function pointers
  372. * @hw: pointer to the HW structure
  373. *
  374. * Initialize family-specific PHY parameters and function pointers.
  375. **/
  376. static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
  377. {
  378. struct e1000_phy_info *phy = &hw->phy;
  379. s32 ret_val;
  380. phy->addr = 1;
  381. phy->reset_delay_us = 100;
  382. phy->ops.set_page = e1000_set_page_igp;
  383. phy->ops.read_reg = e1000_read_phy_reg_hv;
  384. phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
  385. phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
  386. phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
  387. phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
  388. phy->ops.write_reg = e1000_write_phy_reg_hv;
  389. phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
  390. phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
  391. phy->ops.power_up = e1000_power_up_phy_copper;
  392. phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
  393. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  394. phy->id = e1000_phy_unknown;
  395. ret_val = e1000_init_phy_workarounds_pchlan(hw);
  396. if (ret_val)
  397. return ret_val;
  398. if (phy->id == e1000_phy_unknown)
  399. switch (hw->mac.type) {
  400. default:
  401. ret_val = e1000e_get_phy_id(hw);
  402. if (ret_val)
  403. return ret_val;
  404. if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
  405. break;
  406. /* fall-through */
  407. case e1000_pch2lan:
  408. case e1000_pch_lpt:
  409. case e1000_pch_spt:
  410. case e1000_pch_cnp:
  411. case e1000_pch_tgp:
  412. case e1000_pch_adp:
  413. /* In case the PHY needs to be in mdio slow mode,
  414. * set slow mode and try to get the PHY id again.
  415. */
  416. ret_val = e1000_set_mdio_slow_mode_hv(hw);
  417. if (ret_val)
  418. return ret_val;
  419. ret_val = e1000e_get_phy_id(hw);
  420. if (ret_val)
  421. return ret_val;
  422. break;
  423. }
  424. phy->type = e1000e_get_phy_type_from_id(phy->id);
  425. switch (phy->type) {
  426. case e1000_phy_82577:
  427. case e1000_phy_82579:
  428. case e1000_phy_i217:
  429. phy->ops.check_polarity = e1000_check_polarity_82577;
  430. phy->ops.force_speed_duplex =
  431. e1000_phy_force_speed_duplex_82577;
  432. phy->ops.get_cable_length = e1000_get_cable_length_82577;
  433. phy->ops.get_info = e1000_get_phy_info_82577;
  434. phy->ops.commit = e1000e_phy_sw_reset;
  435. break;
  436. case e1000_phy_82578:
  437. phy->ops.check_polarity = e1000_check_polarity_m88;
  438. phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
  439. phy->ops.get_cable_length = e1000e_get_cable_length_m88;
  440. phy->ops.get_info = e1000e_get_phy_info_m88;
  441. break;
  442. default:
  443. ret_val = -E1000_ERR_PHY;
  444. break;
  445. }
  446. return ret_val;
  447. }
  448. /**
  449. * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
  450. * @hw: pointer to the HW structure
  451. *
  452. * Initialize family-specific PHY parameters and function pointers.
  453. **/
  454. static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
  455. {
  456. struct e1000_phy_info *phy = &hw->phy;
  457. s32 ret_val;
  458. u16 i = 0;
  459. phy->addr = 1;
  460. phy->reset_delay_us = 100;
  461. phy->ops.power_up = e1000_power_up_phy_copper;
  462. phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
  463. /* We may need to do this twice - once for IGP and if that fails,
  464. * we'll set BM func pointers and try again
  465. */
  466. ret_val = e1000e_determine_phy_address(hw);
  467. if (ret_val) {
  468. phy->ops.write_reg = e1000e_write_phy_reg_bm;
  469. phy->ops.read_reg = e1000e_read_phy_reg_bm;
  470. ret_val = e1000e_determine_phy_address(hw);
  471. if (ret_val) {
  472. e_dbg("Cannot determine PHY addr. Erroring out\n");
  473. return ret_val;
  474. }
  475. }
  476. phy->id = 0;
  477. while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
  478. (i++ < 100)) {
  479. usleep_range(1000, 1100);
  480. ret_val = e1000e_get_phy_id(hw);
  481. if (ret_val)
  482. return ret_val;
  483. }
  484. /* Verify phy id */
  485. switch (phy->id) {
  486. case IGP03E1000_E_PHY_ID:
  487. phy->type = e1000_phy_igp_3;
  488. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  489. phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
  490. phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
  491. phy->ops.get_info = e1000e_get_phy_info_igp;
  492. phy->ops.check_polarity = e1000_check_polarity_igp;
  493. phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
  494. break;
  495. case IFE_E_PHY_ID:
  496. case IFE_PLUS_E_PHY_ID:
  497. case IFE_C_E_PHY_ID:
  498. phy->type = e1000_phy_ife;
  499. phy->autoneg_mask = E1000_ALL_NOT_GIG;
  500. phy->ops.get_info = e1000_get_phy_info_ife;
  501. phy->ops.check_polarity = e1000_check_polarity_ife;
  502. phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
  503. break;
  504. case BME1000_E_PHY_ID:
  505. phy->type = e1000_phy_bm;
  506. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  507. phy->ops.read_reg = e1000e_read_phy_reg_bm;
  508. phy->ops.write_reg = e1000e_write_phy_reg_bm;
  509. phy->ops.commit = e1000e_phy_sw_reset;
  510. phy->ops.get_info = e1000e_get_phy_info_m88;
  511. phy->ops.check_polarity = e1000_check_polarity_m88;
  512. phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
  513. break;
  514. default:
  515. return -E1000_ERR_PHY;
  516. }
  517. return 0;
  518. }
  519. /**
  520. * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
  521. * @hw: pointer to the HW structure
  522. *
  523. * Initialize family-specific NVM parameters and function
  524. * pointers.
  525. **/
  526. static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
  527. {
  528. struct e1000_nvm_info *nvm = &hw->nvm;
  529. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  530. u32 gfpreg, sector_base_addr, sector_end_addr;
  531. u16 i;
  532. u32 nvm_size;
  533. nvm->type = e1000_nvm_flash_sw;
  534. if (hw->mac.type >= e1000_pch_spt) {
  535. /* in SPT, gfpreg doesn't exist. NVM size is taken from the
  536. * STRAP register. This is because in SPT the GbE Flash region
  537. * is no longer accessed through the flash registers. Instead,
  538. * the mechanism has changed, and the Flash region access
  539. * registers are now implemented in GbE memory space.
  540. */
  541. nvm->flash_base_addr = 0;
  542. nvm_size = (((er32(STRAP) >> 1) & 0x1F) + 1)
  543. * NVM_SIZE_MULTIPLIER;
  544. nvm->flash_bank_size = nvm_size / 2;
  545. /* Adjust to word count */
  546. nvm->flash_bank_size /= sizeof(u16);
  547. /* Set the base address for flash register access */
  548. hw->flash_address = hw->hw_addr + E1000_FLASH_BASE_ADDR;
  549. } else {
  550. /* Can't read flash registers if register set isn't mapped. */
  551. if (!hw->flash_address) {
  552. e_dbg("ERROR: Flash registers not mapped\n");
  553. return -E1000_ERR_CONFIG;
  554. }
  555. gfpreg = er32flash(ICH_FLASH_GFPREG);
  556. /* sector_X_addr is a "sector"-aligned address (4096 bytes)
  557. * Add 1 to sector_end_addr since this sector is included in
  558. * the overall size.
  559. */
  560. sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
  561. sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
  562. /* flash_base_addr is byte-aligned */
  563. nvm->flash_base_addr = sector_base_addr
  564. << FLASH_SECTOR_ADDR_SHIFT;
  565. /* find total size of the NVM, then cut in half since the total
  566. * size represents two separate NVM banks.
  567. */
  568. nvm->flash_bank_size = ((sector_end_addr - sector_base_addr)
  569. << FLASH_SECTOR_ADDR_SHIFT);
  570. nvm->flash_bank_size /= 2;
  571. /* Adjust to word count */
  572. nvm->flash_bank_size /= sizeof(u16);
  573. }
  574. nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
  575. /* Clear shadow ram */
  576. for (i = 0; i < nvm->word_size; i++) {
  577. dev_spec->shadow_ram[i].modified = false;
  578. dev_spec->shadow_ram[i].value = 0xFFFF;
  579. }
  580. return 0;
  581. }
  582. /**
  583. * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
  584. * @hw: pointer to the HW structure
  585. *
  586. * Initialize family-specific MAC parameters and function
  587. * pointers.
  588. **/
  589. static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
  590. {
  591. struct e1000_mac_info *mac = &hw->mac;
  592. /* Set media type function pointer */
  593. hw->phy.media_type = e1000_media_type_copper;
  594. /* Set mta register count */
  595. mac->mta_reg_count = 32;
  596. /* Set rar entry count */
  597. mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
  598. if (mac->type == e1000_ich8lan)
  599. mac->rar_entry_count--;
  600. /* FWSM register */
  601. mac->has_fwsm = true;
  602. /* ARC subsystem not supported */
  603. mac->arc_subsystem_valid = false;
  604. /* Adaptive IFS supported */
  605. mac->adaptive_ifs = true;
  606. /* LED and other operations */
  607. switch (mac->type) {
  608. case e1000_ich8lan:
  609. case e1000_ich9lan:
  610. case e1000_ich10lan:
  611. /* check management mode */
  612. mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
  613. /* ID LED init */
  614. mac->ops.id_led_init = e1000e_id_led_init_generic;
  615. /* blink LED */
  616. mac->ops.blink_led = e1000e_blink_led_generic;
  617. /* setup LED */
  618. mac->ops.setup_led = e1000e_setup_led_generic;
  619. /* cleanup LED */
  620. mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
  621. /* turn on/off LED */
  622. mac->ops.led_on = e1000_led_on_ich8lan;
  623. mac->ops.led_off = e1000_led_off_ich8lan;
  624. break;
  625. case e1000_pch2lan:
  626. mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
  627. mac->ops.rar_set = e1000_rar_set_pch2lan;
  628. /* fall-through */
  629. case e1000_pch_lpt:
  630. case e1000_pch_spt:
  631. case e1000_pch_cnp:
  632. case e1000_pch_tgp:
  633. case e1000_pch_adp:
  634. case e1000_pchlan:
  635. /* check management mode */
  636. mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
  637. /* ID LED init */
  638. mac->ops.id_led_init = e1000_id_led_init_pchlan;
  639. /* setup LED */
  640. mac->ops.setup_led = e1000_setup_led_pchlan;
  641. /* cleanup LED */
  642. mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
  643. /* turn on/off LED */
  644. mac->ops.led_on = e1000_led_on_pchlan;
  645. mac->ops.led_off = e1000_led_off_pchlan;
  646. break;
  647. default:
  648. break;
  649. }
  650. if (mac->type >= e1000_pch_lpt) {
  651. mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
  652. mac->ops.rar_set = e1000_rar_set_pch_lpt;
  653. mac->ops.setup_physical_interface =
  654. e1000_setup_copper_link_pch_lpt;
  655. mac->ops.rar_get_count = e1000_rar_get_count_pch_lpt;
  656. }
  657. /* Enable PCS Lock-loss workaround for ICH8 */
  658. if (mac->type == e1000_ich8lan)
  659. e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
  660. return 0;
  661. }
  662. /**
  663. * __e1000_access_emi_reg_locked - Read/write EMI register
  664. * @hw: pointer to the HW structure
  665. * @addr: EMI address to program
  666. * @data: pointer to value to read/write from/to the EMI address
  667. * @read: boolean flag to indicate read or write
  668. *
  669. * This helper function assumes the SW/FW/HW Semaphore is already acquired.
  670. **/
  671. static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
  672. u16 *data, bool read)
  673. {
  674. s32 ret_val;
  675. ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
  676. if (ret_val)
  677. return ret_val;
  678. if (read)
  679. ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
  680. else
  681. ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);
  682. return ret_val;
  683. }
  684. /**
  685. * e1000_read_emi_reg_locked - Read Extended Management Interface register
  686. * @hw: pointer to the HW structure
  687. * @addr: EMI address to program
  688. * @data: value to be read from the EMI address
  689. *
  690. * Assumes the SW/FW/HW Semaphore is already acquired.
  691. **/
  692. s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
  693. {
  694. return __e1000_access_emi_reg_locked(hw, addr, data, true);
  695. }
  696. /**
  697. * e1000_write_emi_reg_locked - Write Extended Management Interface register
  698. * @hw: pointer to the HW structure
  699. * @addr: EMI address to program
  700. * @data: value to be written to the EMI address
  701. *
  702. * Assumes the SW/FW/HW Semaphore is already acquired.
  703. **/
  704. s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
  705. {
  706. return __e1000_access_emi_reg_locked(hw, addr, &data, false);
  707. }
  708. /**
  709. * e1000_set_eee_pchlan - Enable/disable EEE support
  710. * @hw: pointer to the HW structure
  711. *
  712. * Enable/disable EEE based on setting in dev_spec structure, the duplex of
  713. * the link and the EEE capabilities of the link partner. The LPI Control
  714. * register bits will remain set only if/when link is up.
  715. *
  716. * EEE LPI must not be asserted earlier than one second after link is up.
  717. * On 82579, EEE LPI should not be enabled until such time otherwise there
  718. * can be link issues with some switches. Other devices can have EEE LPI
  719. * enabled immediately upon link up since they have a timer in hardware which
  720. * prevents LPI from being asserted too early.
  721. **/
  722. s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
  723. {
  724. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  725. s32 ret_val;
  726. u16 lpa, pcs_status, adv, adv_addr, lpi_ctrl, data;
  727. switch (hw->phy.type) {
  728. case e1000_phy_82579:
  729. lpa = I82579_EEE_LP_ABILITY;
  730. pcs_status = I82579_EEE_PCS_STATUS;
  731. adv_addr = I82579_EEE_ADVERTISEMENT;
  732. break;
  733. case e1000_phy_i217:
  734. lpa = I217_EEE_LP_ABILITY;
  735. pcs_status = I217_EEE_PCS_STATUS;
  736. adv_addr = I217_EEE_ADVERTISEMENT;
  737. break;
  738. default:
  739. return 0;
  740. }
  741. ret_val = hw->phy.ops.acquire(hw);
  742. if (ret_val)
  743. return ret_val;
  744. ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
  745. if (ret_val)
  746. goto release;
  747. /* Clear bits that enable EEE in various speeds */
  748. lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
  749. /* Enable EEE if not disabled by user */
  750. if (!dev_spec->eee_disable) {
  751. /* Save off link partner's EEE ability */
  752. ret_val = e1000_read_emi_reg_locked(hw, lpa,
  753. &dev_spec->eee_lp_ability);
  754. if (ret_val)
  755. goto release;
  756. /* Read EEE advertisement */
  757. ret_val = e1000_read_emi_reg_locked(hw, adv_addr, &adv);
  758. if (ret_val)
  759. goto release;
  760. /* Enable EEE only for speeds in which the link partner is
  761. * EEE capable and for which we advertise EEE.
  762. */
  763. if (adv & dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
  764. lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
  765. if (adv & dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
  766. e1e_rphy_locked(hw, MII_LPA, &data);
  767. if (data & LPA_100FULL)
  768. lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
  769. else
  770. /* EEE is not supported in 100Half, so ignore
  771. * partner's EEE in 100 ability if full-duplex
  772. * is not advertised.
  773. */
  774. dev_spec->eee_lp_ability &=
  775. ~I82579_EEE_100_SUPPORTED;
  776. }
  777. }
  778. if (hw->phy.type == e1000_phy_82579) {
  779. ret_val = e1000_read_emi_reg_locked(hw, I82579_LPI_PLL_SHUT,
  780. &data);
  781. if (ret_val)
  782. goto release;
  783. data &= ~I82579_LPI_100_PLL_SHUT;
  784. ret_val = e1000_write_emi_reg_locked(hw, I82579_LPI_PLL_SHUT,
  785. data);
  786. }
  787. /* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
  788. ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
  789. if (ret_val)
  790. goto release;
  791. ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
  792. release:
  793. hw->phy.ops.release(hw);
  794. return ret_val;
  795. }
  796. /**
  797. * e1000_k1_workaround_lpt_lp - K1 workaround on Lynxpoint-LP
  798. * @hw: pointer to the HW structure
  799. * @link: link up bool flag
  800. *
  801. * When K1 is enabled for 1Gbps, the MAC can miss 2 DMA completion indications
  802. * preventing further DMA write requests. Workaround the issue by disabling
  803. * the de-assertion of the clock request when in 1Gpbs mode.
  804. * Also, set appropriate Tx re-transmission timeouts for 10 and 100Half link
  805. * speeds in order to avoid Tx hangs.
  806. **/
  807. static s32 e1000_k1_workaround_lpt_lp(struct e1000_hw *hw, bool link)
  808. {
  809. u32 fextnvm6 = er32(FEXTNVM6);
  810. u32 status = er32(STATUS);
  811. s32 ret_val = 0;
  812. u16 reg;
  813. if (link && (status & E1000_STATUS_SPEED_1000)) {
  814. ret_val = hw->phy.ops.acquire(hw);
  815. if (ret_val)
  816. return ret_val;
  817. ret_val =
  818. e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
  819. &reg);
  820. if (ret_val)
  821. goto release;
  822. ret_val =
  823. e1000e_write_kmrn_reg_locked(hw,
  824. E1000_KMRNCTRLSTA_K1_CONFIG,
  825. reg &
  826. ~E1000_KMRNCTRLSTA_K1_ENABLE);
  827. if (ret_val)
  828. goto release;
  829. usleep_range(10, 20);
  830. ew32(FEXTNVM6, fextnvm6 | E1000_FEXTNVM6_REQ_PLL_CLK);
  831. ret_val =
  832. e1000e_write_kmrn_reg_locked(hw,
  833. E1000_KMRNCTRLSTA_K1_CONFIG,
  834. reg);
  835. release:
  836. hw->phy.ops.release(hw);
  837. } else {
  838. /* clear FEXTNVM6 bit 8 on link down or 10/100 */
  839. fextnvm6 &= ~E1000_FEXTNVM6_REQ_PLL_CLK;
  840. if ((hw->phy.revision > 5) || !link ||
  841. ((status & E1000_STATUS_SPEED_100) &&
  842. (status & E1000_STATUS_FD)))
  843. goto update_fextnvm6;
  844. ret_val = e1e_rphy(hw, I217_INBAND_CTRL, &reg);
  845. if (ret_val)
  846. return ret_val;
  847. /* Clear link status transmit timeout */
  848. reg &= ~I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_MASK;
  849. if (status & E1000_STATUS_SPEED_100) {
  850. /* Set inband Tx timeout to 5x10us for 100Half */
  851. reg |= 5 << I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
  852. /* Do not extend the K1 entry latency for 100Half */
  853. fextnvm6 &= ~E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
  854. } else {
  855. /* Set inband Tx timeout to 50x10us for 10Full/Half */
  856. reg |= 50 <<
  857. I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
  858. /* Extend the K1 entry latency for 10 Mbps */
  859. fextnvm6 |= E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
  860. }
  861. ret_val = e1e_wphy(hw, I217_INBAND_CTRL, reg);
  862. if (ret_val)
  863. return ret_val;
  864. update_fextnvm6:
  865. ew32(FEXTNVM6, fextnvm6);
  866. }
  867. return ret_val;
  868. }
  869. /**
  870. * e1000_platform_pm_pch_lpt - Set platform power management values
  871. * @hw: pointer to the HW structure
  872. * @link: bool indicating link status
  873. *
  874. * Set the Latency Tolerance Reporting (LTR) values for the "PCIe-like"
  875. * GbE MAC in the Lynx Point PCH based on Rx buffer size and link speed
  876. * when link is up (which must not exceed the maximum latency supported
  877. * by the platform), otherwise specify there is no LTR requirement.
  878. * Unlike true-PCIe devices which set the LTR maximum snoop/no-snoop
  879. * latencies in the LTR Extended Capability Structure in the PCIe Extended
  880. * Capability register set, on this device LTR is set by writing the
  881. * equivalent snoop/no-snoop latencies in the LTRV register in the MAC and
  882. * set the SEND bit to send an Intel On-chip System Fabric sideband (IOSF-SB)
  883. * message to the PMC.
  884. **/
  885. static s32 e1000_platform_pm_pch_lpt(struct e1000_hw *hw, bool link)
  886. {
  887. u32 reg = link << (E1000_LTRV_REQ_SHIFT + E1000_LTRV_NOSNOOP_SHIFT) |
  888. link << E1000_LTRV_REQ_SHIFT | E1000_LTRV_SEND;
  889. u16 lat_enc = 0; /* latency encoded */
  890. if (link) {
  891. u16 speed, duplex, scale = 0;
  892. u16 max_snoop, max_nosnoop;
  893. u16 max_ltr_enc; /* max LTR latency encoded */
  894. u64 value;
  895. u32 rxa;
  896. if (!hw->adapter->max_frame_size) {
  897. e_dbg("max_frame_size not set.\n");
  898. return -E1000_ERR_CONFIG;
  899. }
  900. hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
  901. if (!speed) {
  902. e_dbg("Speed not set.\n");
  903. return -E1000_ERR_CONFIG;
  904. }
  905. /* Rx Packet Buffer Allocation size (KB) */
  906. rxa = er32(PBA) & E1000_PBA_RXA_MASK;
  907. /* Determine the maximum latency tolerated by the device.
  908. *
  909. * Per the PCIe spec, the tolerated latencies are encoded as
  910. * a 3-bit encoded scale (only 0-5 are valid) multiplied by
  911. * a 10-bit value (0-1023) to provide a range from 1 ns to
  912. * 2^25*(2^10-1) ns. The scale is encoded as 0=2^0ns,
  913. * 1=2^5ns, 2=2^10ns,...5=2^25ns.
  914. */
  915. rxa *= 512;
  916. value = (rxa > hw->adapter->max_frame_size) ?
  917. (rxa - hw->adapter->max_frame_size) * (16000 / speed) :
  918. 0;
  919. while (value > PCI_LTR_VALUE_MASK) {
  920. scale++;
  921. value = DIV_ROUND_UP(value, BIT(5));
  922. }
  923. if (scale > E1000_LTRV_SCALE_MAX) {
  924. e_dbg("Invalid LTR latency scale %d\n", scale);
  925. return -E1000_ERR_CONFIG;
  926. }
  927. lat_enc = (u16)((scale << PCI_LTR_SCALE_SHIFT) | value);
  928. /* Determine the maximum latency tolerated by the platform */
  929. pci_read_config_word(hw->adapter->pdev, E1000_PCI_LTR_CAP_LPT,
  930. &max_snoop);
  931. pci_read_config_word(hw->adapter->pdev,
  932. E1000_PCI_LTR_CAP_LPT + 2, &max_nosnoop);
  933. max_ltr_enc = max_t(u16, max_snoop, max_nosnoop);
  934. if (lat_enc > max_ltr_enc)
  935. lat_enc = max_ltr_enc;
  936. }
  937. /* Set Snoop and No-Snoop latencies the same */
  938. reg |= lat_enc | (lat_enc << E1000_LTRV_NOSNOOP_SHIFT);
  939. ew32(LTRV, reg);
  940. return 0;
  941. }
  942. /**
  943. * e1000_enable_ulp_lpt_lp - configure Ultra Low Power mode for LynxPoint-LP
  944. * @hw: pointer to the HW structure
  945. * @to_sx: boolean indicating a system power state transition to Sx
  946. *
  947. * When link is down, configure ULP mode to significantly reduce the power
  948. * to the PHY. If on a Manageability Engine (ME) enabled system, tell the
  949. * ME firmware to start the ULP configuration. If not on an ME enabled
  950. * system, configure the ULP mode by software.
  951. */
  952. s32 e1000_enable_ulp_lpt_lp(struct e1000_hw *hw, bool to_sx)
  953. {
  954. u32 mac_reg;
  955. s32 ret_val = 0;
  956. u16 phy_reg;
  957. u16 oem_reg = 0;
  958. if ((hw->mac.type < e1000_pch_lpt) ||
  959. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_LM) ||
  960. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_V) ||
  961. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM2) ||
  962. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V2) ||
  963. (hw->dev_spec.ich8lan.ulp_state == e1000_ulp_state_on))
  964. return 0;
  965. if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) {
  966. /* Request ME configure ULP mode in the PHY */
  967. mac_reg = er32(H2ME);
  968. mac_reg |= E1000_H2ME_ULP | E1000_H2ME_ENFORCE_SETTINGS;
  969. ew32(H2ME, mac_reg);
  970. goto out;
  971. }
  972. if (!to_sx) {
  973. int i = 0;
  974. /* Poll up to 5 seconds for Cable Disconnected indication */
  975. while (!(er32(FEXT) & E1000_FEXT_PHY_CABLE_DISCONNECTED)) {
  976. /* Bail if link is re-acquired */
  977. if (er32(STATUS) & E1000_STATUS_LU)
  978. return -E1000_ERR_PHY;
  979. if (i++ == 100)
  980. break;
  981. msleep(50);
  982. }
  983. e_dbg("CABLE_DISCONNECTED %s set after %dmsec\n",
  984. (er32(FEXT) &
  985. E1000_FEXT_PHY_CABLE_DISCONNECTED) ? "" : "not", i * 50);
  986. }
  987. ret_val = hw->phy.ops.acquire(hw);
  988. if (ret_val)
  989. goto out;
  990. /* Force SMBus mode in PHY */
  991. ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL, &phy_reg);
  992. if (ret_val)
  993. goto release;
  994. phy_reg |= CV_SMB_CTRL_FORCE_SMBUS;
  995. e1000_write_phy_reg_hv_locked(hw, CV_SMB_CTRL, phy_reg);
  996. /* Force SMBus mode in MAC */
  997. mac_reg = er32(CTRL_EXT);
  998. mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
  999. ew32(CTRL_EXT, mac_reg);
  1000. /* Si workaround for ULP entry flow on i127/rev6 h/w. Enable
  1001. * LPLU and disable Gig speed when entering ULP
  1002. */
  1003. if ((hw->phy.type == e1000_phy_i217) && (hw->phy.revision == 6)) {
  1004. ret_val = e1000_read_phy_reg_hv_locked(hw, HV_OEM_BITS,
  1005. &oem_reg);
  1006. if (ret_val)
  1007. goto release;
  1008. phy_reg = oem_reg;
  1009. phy_reg |= HV_OEM_BITS_LPLU | HV_OEM_BITS_GBE_DIS;
  1010. ret_val = e1000_write_phy_reg_hv_locked(hw, HV_OEM_BITS,
  1011. phy_reg);
  1012. if (ret_val)
  1013. goto release;
  1014. }
  1015. /* Set Inband ULP Exit, Reset to SMBus mode and
  1016. * Disable SMBus Release on PERST# in PHY
  1017. */
  1018. ret_val = e1000_read_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, &phy_reg);
  1019. if (ret_val)
  1020. goto release;
  1021. phy_reg |= (I218_ULP_CONFIG1_RESET_TO_SMBUS |
  1022. I218_ULP_CONFIG1_DISABLE_SMB_PERST);
  1023. if (to_sx) {
  1024. if (er32(WUFC) & E1000_WUFC_LNKC)
  1025. phy_reg |= I218_ULP_CONFIG1_WOL_HOST;
  1026. else
  1027. phy_reg &= ~I218_ULP_CONFIG1_WOL_HOST;
  1028. phy_reg |= I218_ULP_CONFIG1_STICKY_ULP;
  1029. phy_reg &= ~I218_ULP_CONFIG1_INBAND_EXIT;
  1030. } else {
  1031. phy_reg |= I218_ULP_CONFIG1_INBAND_EXIT;
  1032. phy_reg &= ~I218_ULP_CONFIG1_STICKY_ULP;
  1033. phy_reg &= ~I218_ULP_CONFIG1_WOL_HOST;
  1034. }
  1035. e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
  1036. /* Set Disable SMBus Release on PERST# in MAC */
  1037. mac_reg = er32(FEXTNVM7);
  1038. mac_reg |= E1000_FEXTNVM7_DISABLE_SMB_PERST;
  1039. ew32(FEXTNVM7, mac_reg);
  1040. /* Commit ULP changes in PHY by starting auto ULP configuration */
  1041. phy_reg |= I218_ULP_CONFIG1_START;
  1042. e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
  1043. if ((hw->phy.type == e1000_phy_i217) && (hw->phy.revision == 6) &&
  1044. to_sx && (er32(STATUS) & E1000_STATUS_LU)) {
  1045. ret_val = e1000_write_phy_reg_hv_locked(hw, HV_OEM_BITS,
  1046. oem_reg);
  1047. if (ret_val)
  1048. goto release;
  1049. }
  1050. release:
  1051. hw->phy.ops.release(hw);
  1052. out:
  1053. if (ret_val)
  1054. e_dbg("Error in ULP enable flow: %d\n", ret_val);
  1055. else
  1056. hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_on;
  1057. return ret_val;
  1058. }
  1059. /**
  1060. * e1000_disable_ulp_lpt_lp - unconfigure Ultra Low Power mode for LynxPoint-LP
  1061. * @hw: pointer to the HW structure
  1062. * @force: boolean indicating whether or not to force disabling ULP
  1063. *
  1064. * Un-configure ULP mode when link is up, the system is transitioned from
  1065. * Sx or the driver is unloaded. If on a Manageability Engine (ME) enabled
  1066. * system, poll for an indication from ME that ULP has been un-configured.
  1067. * If not on an ME enabled system, un-configure the ULP mode by software.
  1068. *
  1069. * During nominal operation, this function is called when link is acquired
  1070. * to disable ULP mode (force=false); otherwise, for example when unloading
  1071. * the driver or during Sx->S0 transitions, this is called with force=true
  1072. * to forcibly disable ULP.
  1073. */
  1074. static s32 e1000_disable_ulp_lpt_lp(struct e1000_hw *hw, bool force)
  1075. {
  1076. s32 ret_val = 0;
  1077. u32 mac_reg;
  1078. u16 phy_reg;
  1079. int i = 0;
  1080. if ((hw->mac.type < e1000_pch_lpt) ||
  1081. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_LM) ||
  1082. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_V) ||
  1083. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM2) ||
  1084. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V2) ||
  1085. (hw->dev_spec.ich8lan.ulp_state == e1000_ulp_state_off))
  1086. return 0;
  1087. if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) {
  1088. if (force) {
  1089. /* Request ME un-configure ULP mode in the PHY */
  1090. mac_reg = er32(H2ME);
  1091. mac_reg &= ~E1000_H2ME_ULP;
  1092. mac_reg |= E1000_H2ME_ENFORCE_SETTINGS;
  1093. ew32(H2ME, mac_reg);
  1094. }
  1095. /* Poll up to 300msec for ME to clear ULP_CFG_DONE. */
  1096. while (er32(FWSM) & E1000_FWSM_ULP_CFG_DONE) {
  1097. if (i++ == 30) {
  1098. ret_val = -E1000_ERR_PHY;
  1099. goto out;
  1100. }
  1101. usleep_range(10000, 11000);
  1102. }
  1103. e_dbg("ULP_CONFIG_DONE cleared after %dmsec\n", i * 10);
  1104. if (force) {
  1105. mac_reg = er32(H2ME);
  1106. mac_reg &= ~E1000_H2ME_ENFORCE_SETTINGS;
  1107. ew32(H2ME, mac_reg);
  1108. } else {
  1109. /* Clear H2ME.ULP after ME ULP configuration */
  1110. mac_reg = er32(H2ME);
  1111. mac_reg &= ~E1000_H2ME_ULP;
  1112. ew32(H2ME, mac_reg);
  1113. }
  1114. goto out;
  1115. }
  1116. ret_val = hw->phy.ops.acquire(hw);
  1117. if (ret_val)
  1118. goto out;
  1119. if (force)
  1120. /* Toggle LANPHYPC Value bit */
  1121. e1000_toggle_lanphypc_pch_lpt(hw);
  1122. /* Unforce SMBus mode in PHY */
  1123. ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL, &phy_reg);
  1124. if (ret_val) {
  1125. /* The MAC might be in PCIe mode, so temporarily force to
  1126. * SMBus mode in order to access the PHY.
  1127. */
  1128. mac_reg = er32(CTRL_EXT);
  1129. mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
  1130. ew32(CTRL_EXT, mac_reg);
  1131. msleep(50);
  1132. ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL,
  1133. &phy_reg);
  1134. if (ret_val)
  1135. goto release;
  1136. }
  1137. phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
  1138. e1000_write_phy_reg_hv_locked(hw, CV_SMB_CTRL, phy_reg);
  1139. /* Unforce SMBus mode in MAC */
  1140. mac_reg = er32(CTRL_EXT);
  1141. mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
  1142. ew32(CTRL_EXT, mac_reg);
  1143. /* When ULP mode was previously entered, K1 was disabled by the
  1144. * hardware. Re-Enable K1 in the PHY when exiting ULP.
  1145. */
  1146. ret_val = e1000_read_phy_reg_hv_locked(hw, HV_PM_CTRL, &phy_reg);
  1147. if (ret_val)
  1148. goto release;
  1149. phy_reg |= HV_PM_CTRL_K1_ENABLE;
  1150. e1000_write_phy_reg_hv_locked(hw, HV_PM_CTRL, phy_reg);
  1151. /* Clear ULP enabled configuration */
  1152. ret_val = e1000_read_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, &phy_reg);
  1153. if (ret_val)
  1154. goto release;
  1155. phy_reg &= ~(I218_ULP_CONFIG1_IND |
  1156. I218_ULP_CONFIG1_STICKY_ULP |
  1157. I218_ULP_CONFIG1_RESET_TO_SMBUS |
  1158. I218_ULP_CONFIG1_WOL_HOST |
  1159. I218_ULP_CONFIG1_INBAND_EXIT |
  1160. I218_ULP_CONFIG1_EN_ULP_LANPHYPC |
  1161. I218_ULP_CONFIG1_DIS_CLR_STICKY_ON_PERST |
  1162. I218_ULP_CONFIG1_DISABLE_SMB_PERST);
  1163. e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
  1164. /* Commit ULP changes by starting auto ULP configuration */
  1165. phy_reg |= I218_ULP_CONFIG1_START;
  1166. e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
  1167. /* Clear Disable SMBus Release on PERST# in MAC */
  1168. mac_reg = er32(FEXTNVM7);
  1169. mac_reg &= ~E1000_FEXTNVM7_DISABLE_SMB_PERST;
  1170. ew32(FEXTNVM7, mac_reg);
  1171. release:
  1172. hw->phy.ops.release(hw);
  1173. if (force) {
  1174. e1000_phy_hw_reset(hw);
  1175. msleep(50);
  1176. }
  1177. out:
  1178. if (ret_val)
  1179. e_dbg("Error in ULP disable flow: %d\n", ret_val);
  1180. else
  1181. hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_off;
  1182. return ret_val;
  1183. }
  1184. /**
  1185. * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
  1186. * @hw: pointer to the HW structure
  1187. *
  1188. * Checks to see of the link status of the hardware has changed. If a
  1189. * change in link status has been detected, then we read the PHY registers
  1190. * to get the current speed/duplex if link exists.
  1191. **/
  1192. static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
  1193. {
  1194. struct e1000_mac_info *mac = &hw->mac;
  1195. s32 ret_val, tipg_reg = 0;
  1196. u16 emi_addr, emi_val = 0;
  1197. bool link;
  1198. u16 phy_reg;
  1199. /* We only want to go out to the PHY registers to see if Auto-Neg
  1200. * has completed and/or if our link status has changed. The
  1201. * get_link_status flag is set upon receiving a Link Status
  1202. * Change or Rx Sequence Error interrupt.
  1203. */
  1204. if (!mac->get_link_status)
  1205. return 0;
  1206. mac->get_link_status = false;
  1207. /* First we want to see if the MII Status Register reports
  1208. * link. If so, then we want to get the current speed/duplex
  1209. * of the PHY.
  1210. */
  1211. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  1212. if (ret_val)
  1213. goto out;
  1214. if (hw->mac.type == e1000_pchlan) {
  1215. ret_val = e1000_k1_gig_workaround_hv(hw, link);
  1216. if (ret_val)
  1217. goto out;
  1218. }
  1219. /* When connected at 10Mbps half-duplex, some parts are excessively
  1220. * aggressive resulting in many collisions. To avoid this, increase
  1221. * the IPG and reduce Rx latency in the PHY.
  1222. */
  1223. if ((hw->mac.type >= e1000_pch2lan) && link) {
  1224. u16 speed, duplex;
  1225. e1000e_get_speed_and_duplex_copper(hw, &speed, &duplex);
  1226. tipg_reg = er32(TIPG);
  1227. tipg_reg &= ~E1000_TIPG_IPGT_MASK;
  1228. if (duplex == HALF_DUPLEX && speed == SPEED_10) {
  1229. tipg_reg |= 0xFF;
  1230. /* Reduce Rx latency in analog PHY */
  1231. emi_val = 0;
  1232. } else if (hw->mac.type >= e1000_pch_spt &&
  1233. duplex == FULL_DUPLEX && speed != SPEED_1000) {
  1234. tipg_reg |= 0xC;
  1235. emi_val = 1;
  1236. } else {
  1237. /* Roll back the default values */
  1238. tipg_reg |= 0x08;
  1239. emi_val = 1;
  1240. }
  1241. ew32(TIPG, tipg_reg);
  1242. ret_val = hw->phy.ops.acquire(hw);
  1243. if (ret_val)
  1244. goto out;
  1245. if (hw->mac.type == e1000_pch2lan)
  1246. emi_addr = I82579_RX_CONFIG;
  1247. else
  1248. emi_addr = I217_RX_CONFIG;
  1249. ret_val = e1000_write_emi_reg_locked(hw, emi_addr, emi_val);
  1250. if (hw->mac.type >= e1000_pch_lpt) {
  1251. u16 phy_reg;
  1252. e1e_rphy_locked(hw, I217_PLL_CLOCK_GATE_REG, &phy_reg);
  1253. phy_reg &= ~I217_PLL_CLOCK_GATE_MASK;
  1254. if (speed == SPEED_100 || speed == SPEED_10)
  1255. phy_reg |= 0x3E8;
  1256. else
  1257. phy_reg |= 0xFA;
  1258. e1e_wphy_locked(hw, I217_PLL_CLOCK_GATE_REG, phy_reg);
  1259. if (speed == SPEED_1000) {
  1260. hw->phy.ops.read_reg_locked(hw, HV_PM_CTRL,
  1261. &phy_reg);
  1262. phy_reg |= HV_PM_CTRL_K1_CLK_REQ;
  1263. hw->phy.ops.write_reg_locked(hw, HV_PM_CTRL,
  1264. phy_reg);
  1265. }
  1266. }
  1267. hw->phy.ops.release(hw);
  1268. if (ret_val)
  1269. goto out;
  1270. if (hw->mac.type >= e1000_pch_spt) {
  1271. u16 data;
  1272. u16 ptr_gap;
  1273. if (speed == SPEED_1000) {
  1274. ret_val = hw->phy.ops.acquire(hw);
  1275. if (ret_val)
  1276. goto out;
  1277. ret_val = e1e_rphy_locked(hw,
  1278. PHY_REG(776, 20),
  1279. &data);
  1280. if (ret_val) {
  1281. hw->phy.ops.release(hw);
  1282. goto out;
  1283. }
  1284. ptr_gap = (data & (0x3FF << 2)) >> 2;
  1285. if (ptr_gap < 0x18) {
  1286. data &= ~(0x3FF << 2);
  1287. data |= (0x18 << 2);
  1288. ret_val =
  1289. e1e_wphy_locked(hw,
  1290. PHY_REG(776, 20),
  1291. data);
  1292. }
  1293. hw->phy.ops.release(hw);
  1294. if (ret_val)
  1295. goto out;
  1296. } else {
  1297. ret_val = hw->phy.ops.acquire(hw);
  1298. if (ret_val)
  1299. goto out;
  1300. ret_val = e1e_wphy_locked(hw,
  1301. PHY_REG(776, 20),
  1302. 0xC023);
  1303. hw->phy.ops.release(hw);
  1304. if (ret_val)
  1305. goto out;
  1306. }
  1307. }
  1308. }
  1309. /* I217 Packet Loss issue:
  1310. * ensure that FEXTNVM4 Beacon Duration is set correctly
  1311. * on power up.
  1312. * Set the Beacon Duration for I217 to 8 usec
  1313. */
  1314. if (hw->mac.type >= e1000_pch_lpt) {
  1315. u32 mac_reg;
  1316. mac_reg = er32(FEXTNVM4);
  1317. mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
  1318. mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
  1319. ew32(FEXTNVM4, mac_reg);
  1320. }
  1321. /* Work-around I218 hang issue */
  1322. if ((hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
  1323. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
  1324. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM3) ||
  1325. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V3)) {
  1326. ret_val = e1000_k1_workaround_lpt_lp(hw, link);
  1327. if (ret_val)
  1328. goto out;
  1329. }
  1330. if (hw->mac.type >= e1000_pch_lpt) {
  1331. /* Set platform power management values for
  1332. * Latency Tolerance Reporting (LTR)
  1333. */
  1334. ret_val = e1000_platform_pm_pch_lpt(hw, link);
  1335. if (ret_val)
  1336. goto out;
  1337. }
  1338. /* Clear link partner's EEE ability */
  1339. hw->dev_spec.ich8lan.eee_lp_ability = 0;
  1340. if (hw->mac.type >= e1000_pch_lpt) {
  1341. u32 fextnvm6 = er32(FEXTNVM6);
  1342. if (hw->mac.type == e1000_pch_spt) {
  1343. /* FEXTNVM6 K1-off workaround - for SPT only */
  1344. u32 pcieanacfg = er32(PCIEANACFG);
  1345. if (pcieanacfg & E1000_FEXTNVM6_K1_OFF_ENABLE)
  1346. fextnvm6 |= E1000_FEXTNVM6_K1_OFF_ENABLE;
  1347. else
  1348. fextnvm6 &= ~E1000_FEXTNVM6_K1_OFF_ENABLE;
  1349. }
  1350. ew32(FEXTNVM6, fextnvm6);
  1351. }
  1352. if (!link)
  1353. goto out;
  1354. switch (hw->mac.type) {
  1355. case e1000_pch2lan:
  1356. ret_val = e1000_k1_workaround_lv(hw);
  1357. if (ret_val)
  1358. return ret_val;
  1359. /* fall-thru */
  1360. case e1000_pchlan:
  1361. if (hw->phy.type == e1000_phy_82578) {
  1362. ret_val = e1000_link_stall_workaround_hv(hw);
  1363. if (ret_val)
  1364. return ret_val;
  1365. }
  1366. /* Workaround for PCHx parts in half-duplex:
  1367. * Set the number of preambles removed from the packet
  1368. * when it is passed from the PHY to the MAC to prevent
  1369. * the MAC from misinterpreting the packet type.
  1370. */
  1371. e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
  1372. phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
  1373. if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
  1374. phy_reg |= BIT(HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
  1375. e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
  1376. break;
  1377. default:
  1378. break;
  1379. }
  1380. /* Check if there was DownShift, must be checked
  1381. * immediately after link-up
  1382. */
  1383. e1000e_check_downshift(hw);
  1384. /* Enable/Disable EEE after link up */
  1385. if (hw->phy.type > e1000_phy_82579) {
  1386. ret_val = e1000_set_eee_pchlan(hw);
  1387. if (ret_val)
  1388. return ret_val;
  1389. }
  1390. /* If we are forcing speed/duplex, then we simply return since
  1391. * we have already determined whether we have link or not.
  1392. */
  1393. if (!mac->autoneg)
  1394. return -E1000_ERR_CONFIG;
  1395. /* Auto-Neg is enabled. Auto Speed Detection takes care
  1396. * of MAC speed/duplex configuration. So we only need to
  1397. * configure Collision Distance in the MAC.
  1398. */
  1399. mac->ops.config_collision_dist(hw);
  1400. /* Configure Flow Control now that Auto-Neg has completed.
  1401. * First, we need to restore the desired flow control
  1402. * settings because we may have had to re-autoneg with a
  1403. * different link partner.
  1404. */
  1405. ret_val = e1000e_config_fc_after_link_up(hw);
  1406. if (ret_val)
  1407. e_dbg("Error configuring flow control\n");
  1408. return ret_val;
  1409. out:
  1410. mac->get_link_status = true;
  1411. return ret_val;
  1412. }
  1413. static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
  1414. {
  1415. struct e1000_hw *hw = &adapter->hw;
  1416. s32 rc;
  1417. rc = e1000_init_mac_params_ich8lan(hw);
  1418. if (rc)
  1419. return rc;
  1420. rc = e1000_init_nvm_params_ich8lan(hw);
  1421. if (rc)
  1422. return rc;
  1423. switch (hw->mac.type) {
  1424. case e1000_ich8lan:
  1425. case e1000_ich9lan:
  1426. case e1000_ich10lan:
  1427. rc = e1000_init_phy_params_ich8lan(hw);
  1428. break;
  1429. case e1000_pchlan:
  1430. case e1000_pch2lan:
  1431. case e1000_pch_lpt:
  1432. case e1000_pch_spt:
  1433. case e1000_pch_cnp:
  1434. case e1000_pch_tgp:
  1435. case e1000_pch_adp:
  1436. rc = e1000_init_phy_params_pchlan(hw);
  1437. break;
  1438. default:
  1439. break;
  1440. }
  1441. if (rc)
  1442. return rc;
  1443. /* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
  1444. * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
  1445. */
  1446. if ((adapter->hw.phy.type == e1000_phy_ife) ||
  1447. ((adapter->hw.mac.type >= e1000_pch2lan) &&
  1448. (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
  1449. adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
  1450. adapter->max_hw_frame_size = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN;
  1451. hw->mac.ops.blink_led = NULL;
  1452. }
  1453. if ((adapter->hw.mac.type == e1000_ich8lan) &&
  1454. (adapter->hw.phy.type != e1000_phy_ife))
  1455. adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
  1456. /* Enable workaround for 82579 w/ ME enabled */
  1457. if ((adapter->hw.mac.type == e1000_pch2lan) &&
  1458. (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
  1459. adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
  1460. return 0;
  1461. }
  1462. static DEFINE_MUTEX(nvm_mutex);
  1463. /**
  1464. * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
  1465. * @hw: pointer to the HW structure
  1466. *
  1467. * Acquires the mutex for performing NVM operations.
  1468. **/
  1469. static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw __always_unused *hw)
  1470. {
  1471. mutex_lock(&nvm_mutex);
  1472. return 0;
  1473. }
  1474. /**
  1475. * e1000_release_nvm_ich8lan - Release NVM mutex
  1476. * @hw: pointer to the HW structure
  1477. *
  1478. * Releases the mutex used while performing NVM operations.
  1479. **/
  1480. static void e1000_release_nvm_ich8lan(struct e1000_hw __always_unused *hw)
  1481. {
  1482. mutex_unlock(&nvm_mutex);
  1483. }
  1484. /**
  1485. * e1000_acquire_swflag_ich8lan - Acquire software control flag
  1486. * @hw: pointer to the HW structure
  1487. *
  1488. * Acquires the software control flag for performing PHY and select
  1489. * MAC CSR accesses.
  1490. **/
  1491. static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
  1492. {
  1493. u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
  1494. s32 ret_val = 0;
  1495. if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
  1496. &hw->adapter->state)) {
  1497. e_dbg("contention for Phy access\n");
  1498. return -E1000_ERR_PHY;
  1499. }
  1500. while (timeout) {
  1501. extcnf_ctrl = er32(EXTCNF_CTRL);
  1502. if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
  1503. break;
  1504. mdelay(1);
  1505. timeout--;
  1506. }
  1507. if (!timeout) {
  1508. e_dbg("SW has already locked the resource.\n");
  1509. ret_val = -E1000_ERR_CONFIG;
  1510. goto out;
  1511. }
  1512. timeout = SW_FLAG_TIMEOUT;
  1513. extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
  1514. ew32(EXTCNF_CTRL, extcnf_ctrl);
  1515. while (timeout) {
  1516. extcnf_ctrl = er32(EXTCNF_CTRL);
  1517. if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
  1518. break;
  1519. mdelay(1);
  1520. timeout--;
  1521. }
  1522. if (!timeout) {
  1523. e_dbg("Failed to acquire the semaphore, FW or HW has it: FWSM=0x%8.8x EXTCNF_CTRL=0x%8.8x)\n",
  1524. er32(FWSM), extcnf_ctrl);
  1525. extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
  1526. ew32(EXTCNF_CTRL, extcnf_ctrl);
  1527. ret_val = -E1000_ERR_CONFIG;
  1528. goto out;
  1529. }
  1530. out:
  1531. if (ret_val)
  1532. clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
  1533. return ret_val;
  1534. }
  1535. /**
  1536. * e1000_release_swflag_ich8lan - Release software control flag
  1537. * @hw: pointer to the HW structure
  1538. *
  1539. * Releases the software control flag for performing PHY and select
  1540. * MAC CSR accesses.
  1541. **/
  1542. static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
  1543. {
  1544. u32 extcnf_ctrl;
  1545. extcnf_ctrl = er32(EXTCNF_CTRL);
  1546. if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
  1547. extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
  1548. ew32(EXTCNF_CTRL, extcnf_ctrl);
  1549. } else {
  1550. e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
  1551. }
  1552. clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
  1553. }
  1554. /**
  1555. * e1000_check_mng_mode_ich8lan - Checks management mode
  1556. * @hw: pointer to the HW structure
  1557. *
  1558. * This checks if the adapter has any manageability enabled.
  1559. * This is a function pointer entry point only called by read/write
  1560. * routines for the PHY and NVM parts.
  1561. **/
  1562. static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
  1563. {
  1564. u32 fwsm;
  1565. fwsm = er32(FWSM);
  1566. return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
  1567. ((fwsm & E1000_FWSM_MODE_MASK) ==
  1568. (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
  1569. }
  1570. /**
  1571. * e1000_check_mng_mode_pchlan - Checks management mode
  1572. * @hw: pointer to the HW structure
  1573. *
  1574. * This checks if the adapter has iAMT enabled.
  1575. * This is a function pointer entry point only called by read/write
  1576. * routines for the PHY and NVM parts.
  1577. **/
  1578. static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
  1579. {
  1580. u32 fwsm;
  1581. fwsm = er32(FWSM);
  1582. return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
  1583. (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
  1584. }
  1585. /**
  1586. * e1000_rar_set_pch2lan - Set receive address register
  1587. * @hw: pointer to the HW structure
  1588. * @addr: pointer to the receive address
  1589. * @index: receive address array register
  1590. *
  1591. * Sets the receive address array register at index to the address passed
  1592. * in by addr. For 82579, RAR[0] is the base address register that is to
  1593. * contain the MAC address but RAR[1-6] are reserved for manageability (ME).
  1594. * Use SHRA[0-3] in place of those reserved for ME.
  1595. **/
  1596. static int e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
  1597. {
  1598. u32 rar_low, rar_high;
  1599. /* HW expects these in little endian so we reverse the byte order
  1600. * from network order (big endian) to little endian
  1601. */
  1602. rar_low = ((u32)addr[0] |
  1603. ((u32)addr[1] << 8) |
  1604. ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
  1605. rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
  1606. /* If MAC address zero, no need to set the AV bit */
  1607. if (rar_low || rar_high)
  1608. rar_high |= E1000_RAH_AV;
  1609. if (index == 0) {
  1610. ew32(RAL(index), rar_low);
  1611. e1e_flush();
  1612. ew32(RAH(index), rar_high);
  1613. e1e_flush();
  1614. return 0;
  1615. }
  1616. /* RAR[1-6] are owned by manageability. Skip those and program the
  1617. * next address into the SHRA register array.
  1618. */
  1619. if (index < (u32)(hw->mac.rar_entry_count)) {
  1620. s32 ret_val;
  1621. ret_val = e1000_acquire_swflag_ich8lan(hw);
  1622. if (ret_val)
  1623. goto out;
  1624. ew32(SHRAL(index - 1), rar_low);
  1625. e1e_flush();
  1626. ew32(SHRAH(index - 1), rar_high);
  1627. e1e_flush();
  1628. e1000_release_swflag_ich8lan(hw);
  1629. /* verify the register updates */
  1630. if ((er32(SHRAL(index - 1)) == rar_low) &&
  1631. (er32(SHRAH(index - 1)) == rar_high))
  1632. return 0;
  1633. e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
  1634. (index - 1), er32(FWSM));
  1635. }
  1636. out:
  1637. e_dbg("Failed to write receive address at index %d\n", index);
  1638. return -E1000_ERR_CONFIG;
  1639. }
  1640. /**
  1641. * e1000_rar_get_count_pch_lpt - Get the number of available SHRA
  1642. * @hw: pointer to the HW structure
  1643. *
  1644. * Get the number of available receive registers that the Host can
  1645. * program. SHRA[0-10] are the shared receive address registers
  1646. * that are shared between the Host and manageability engine (ME).
  1647. * ME can reserve any number of addresses and the host needs to be
  1648. * able to tell how many available registers it has access to.
  1649. **/
  1650. static u32 e1000_rar_get_count_pch_lpt(struct e1000_hw *hw)
  1651. {
  1652. u32 wlock_mac;
  1653. u32 num_entries;
  1654. wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
  1655. wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
  1656. switch (wlock_mac) {
  1657. case 0:
  1658. /* All SHRA[0..10] and RAR[0] available */
  1659. num_entries = hw->mac.rar_entry_count;
  1660. break;
  1661. case 1:
  1662. /* Only RAR[0] available */
  1663. num_entries = 1;
  1664. break;
  1665. default:
  1666. /* SHRA[0..(wlock_mac - 1)] available + RAR[0] */
  1667. num_entries = wlock_mac + 1;
  1668. break;
  1669. }
  1670. return num_entries;
  1671. }
  1672. /**
  1673. * e1000_rar_set_pch_lpt - Set receive address registers
  1674. * @hw: pointer to the HW structure
  1675. * @addr: pointer to the receive address
  1676. * @index: receive address array register
  1677. *
  1678. * Sets the receive address register array at index to the address passed
  1679. * in by addr. For LPT, RAR[0] is the base address register that is to
  1680. * contain the MAC address. SHRA[0-10] are the shared receive address
  1681. * registers that are shared between the Host and manageability engine (ME).
  1682. **/
  1683. static int e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
  1684. {
  1685. u32 rar_low, rar_high;
  1686. u32 wlock_mac;
  1687. /* HW expects these in little endian so we reverse the byte order
  1688. * from network order (big endian) to little endian
  1689. */
  1690. rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
  1691. ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
  1692. rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
  1693. /* If MAC address zero, no need to set the AV bit */
  1694. if (rar_low || rar_high)
  1695. rar_high |= E1000_RAH_AV;
  1696. if (index == 0) {
  1697. ew32(RAL(index), rar_low);
  1698. e1e_flush();
  1699. ew32(RAH(index), rar_high);
  1700. e1e_flush();
  1701. return 0;
  1702. }
  1703. /* The manageability engine (ME) can lock certain SHRAR registers that
  1704. * it is using - those registers are unavailable for use.
  1705. */
  1706. if (index < hw->mac.rar_entry_count) {
  1707. wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
  1708. wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
  1709. /* Check if all SHRAR registers are locked */
  1710. if (wlock_mac == 1)
  1711. goto out;
  1712. if ((wlock_mac == 0) || (index <= wlock_mac)) {
  1713. s32 ret_val;
  1714. ret_val = e1000_acquire_swflag_ich8lan(hw);
  1715. if (ret_val)
  1716. goto out;
  1717. ew32(SHRAL_PCH_LPT(index - 1), rar_low);
  1718. e1e_flush();
  1719. ew32(SHRAH_PCH_LPT(index - 1), rar_high);
  1720. e1e_flush();
  1721. e1000_release_swflag_ich8lan(hw);
  1722. /* verify the register updates */
  1723. if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
  1724. (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
  1725. return 0;
  1726. }
  1727. }
  1728. out:
  1729. e_dbg("Failed to write receive address at index %d\n", index);
  1730. return -E1000_ERR_CONFIG;
  1731. }
  1732. /**
  1733. * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
  1734. * @hw: pointer to the HW structure
  1735. *
  1736. * Checks if firmware is blocking the reset of the PHY.
  1737. * This is a function pointer entry point only called by
  1738. * reset routines.
  1739. **/
  1740. static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
  1741. {
  1742. bool blocked = false;
  1743. int i = 0;
  1744. while ((blocked = !(er32(FWSM) & E1000_ICH_FWSM_RSPCIPHY)) &&
  1745. (i++ < 30))
  1746. usleep_range(10000, 11000);
  1747. return blocked ? E1000_BLK_PHY_RESET : 0;
  1748. }
  1749. /**
  1750. * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
  1751. * @hw: pointer to the HW structure
  1752. *
  1753. * Assumes semaphore already acquired.
  1754. *
  1755. **/
  1756. static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
  1757. {
  1758. u16 phy_data;
  1759. u32 strap = er32(STRAP);
  1760. u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
  1761. E1000_STRAP_SMT_FREQ_SHIFT;
  1762. s32 ret_val;
  1763. strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
  1764. ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
  1765. if (ret_val)
  1766. return ret_val;
  1767. phy_data &= ~HV_SMB_ADDR_MASK;
  1768. phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
  1769. phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
  1770. if (hw->phy.type == e1000_phy_i217) {
  1771. /* Restore SMBus frequency */
  1772. if (freq--) {
  1773. phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
  1774. phy_data |= (freq & BIT(0)) <<
  1775. HV_SMB_ADDR_FREQ_LOW_SHIFT;
  1776. phy_data |= (freq & BIT(1)) <<
  1777. (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
  1778. } else {
  1779. e_dbg("Unsupported SMB frequency in PHY\n");
  1780. }
  1781. }
  1782. return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
  1783. }
  1784. /**
  1785. * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
  1786. * @hw: pointer to the HW structure
  1787. *
  1788. * SW should configure the LCD from the NVM extended configuration region
  1789. * as a workaround for certain parts.
  1790. **/
  1791. static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
  1792. {
  1793. struct e1000_phy_info *phy = &hw->phy;
  1794. u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
  1795. s32 ret_val = 0;
  1796. u16 word_addr, reg_data, reg_addr, phy_page = 0;
  1797. /* Initialize the PHY from the NVM on ICH platforms. This
  1798. * is needed due to an issue where the NVM configuration is
  1799. * not properly autoloaded after power transitions.
  1800. * Therefore, after each PHY reset, we will load the
  1801. * configuration data out of the NVM manually.
  1802. */
  1803. switch (hw->mac.type) {
  1804. case e1000_ich8lan:
  1805. if (phy->type != e1000_phy_igp_3)
  1806. return ret_val;
  1807. if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
  1808. (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
  1809. sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
  1810. break;
  1811. }
  1812. /* Fall-thru */
  1813. case e1000_pchlan:
  1814. case e1000_pch2lan:
  1815. case e1000_pch_lpt:
  1816. case e1000_pch_spt:
  1817. case e1000_pch_cnp:
  1818. case e1000_pch_tgp:
  1819. case e1000_pch_adp:
  1820. sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
  1821. break;
  1822. default:
  1823. return ret_val;
  1824. }
  1825. ret_val = hw->phy.ops.acquire(hw);
  1826. if (ret_val)
  1827. return ret_val;
  1828. data = er32(FEXTNVM);
  1829. if (!(data & sw_cfg_mask))
  1830. goto release;
  1831. /* Make sure HW does not configure LCD from PHY
  1832. * extended configuration before SW configuration
  1833. */
  1834. data = er32(EXTCNF_CTRL);
  1835. if ((hw->mac.type < e1000_pch2lan) &&
  1836. (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
  1837. goto release;
  1838. cnf_size = er32(EXTCNF_SIZE);
  1839. cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
  1840. cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
  1841. if (!cnf_size)
  1842. goto release;
  1843. cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
  1844. cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
  1845. if (((hw->mac.type == e1000_pchlan) &&
  1846. !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
  1847. (hw->mac.type > e1000_pchlan)) {
  1848. /* HW configures the SMBus address and LEDs when the
  1849. * OEM and LCD Write Enable bits are set in the NVM.
  1850. * When both NVM bits are cleared, SW will configure
  1851. * them instead.
  1852. */
  1853. ret_val = e1000_write_smbus_addr(hw);
  1854. if (ret_val)
  1855. goto release;
  1856. data = er32(LEDCTL);
  1857. ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
  1858. (u16)data);
  1859. if (ret_val)
  1860. goto release;
  1861. }
  1862. /* Configure LCD from extended configuration region. */
  1863. /* cnf_base_addr is in DWORD */
  1864. word_addr = (u16)(cnf_base_addr << 1);
  1865. for (i = 0; i < cnf_size; i++) {
  1866. ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1, &reg_data);
  1867. if (ret_val)
  1868. goto release;
  1869. ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
  1870. 1, &reg_addr);
  1871. if (ret_val)
  1872. goto release;
  1873. /* Save off the PHY page for future writes. */
  1874. if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
  1875. phy_page = reg_data;
  1876. continue;
  1877. }
  1878. reg_addr &= PHY_REG_MASK;
  1879. reg_addr |= phy_page;
  1880. ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
  1881. if (ret_val)
  1882. goto release;
  1883. }
  1884. release:
  1885. hw->phy.ops.release(hw);
  1886. return ret_val;
  1887. }
  1888. /**
  1889. * e1000_k1_gig_workaround_hv - K1 Si workaround
  1890. * @hw: pointer to the HW structure
  1891. * @link: link up bool flag
  1892. *
  1893. * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
  1894. * from a lower speed. This workaround disables K1 whenever link is at 1Gig
  1895. * If link is down, the function will restore the default K1 setting located
  1896. * in the NVM.
  1897. **/
  1898. static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
  1899. {
  1900. s32 ret_val = 0;
  1901. u16 status_reg = 0;
  1902. bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
  1903. if (hw->mac.type != e1000_pchlan)
  1904. return 0;
  1905. /* Wrap the whole flow with the sw flag */
  1906. ret_val = hw->phy.ops.acquire(hw);
  1907. if (ret_val)
  1908. return ret_val;
  1909. /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
  1910. if (link) {
  1911. if (hw->phy.type == e1000_phy_82578) {
  1912. ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
  1913. &status_reg);
  1914. if (ret_val)
  1915. goto release;
  1916. status_reg &= (BM_CS_STATUS_LINK_UP |
  1917. BM_CS_STATUS_RESOLVED |
  1918. BM_CS_STATUS_SPEED_MASK);
  1919. if (status_reg == (BM_CS_STATUS_LINK_UP |
  1920. BM_CS_STATUS_RESOLVED |
  1921. BM_CS_STATUS_SPEED_1000))
  1922. k1_enable = false;
  1923. }
  1924. if (hw->phy.type == e1000_phy_82577) {
  1925. ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
  1926. if (ret_val)
  1927. goto release;
  1928. status_reg &= (HV_M_STATUS_LINK_UP |
  1929. HV_M_STATUS_AUTONEG_COMPLETE |
  1930. HV_M_STATUS_SPEED_MASK);
  1931. if (status_reg == (HV_M_STATUS_LINK_UP |
  1932. HV_M_STATUS_AUTONEG_COMPLETE |
  1933. HV_M_STATUS_SPEED_1000))
  1934. k1_enable = false;
  1935. }
  1936. /* Link stall fix for link up */
  1937. ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
  1938. if (ret_val)
  1939. goto release;
  1940. } else {
  1941. /* Link stall fix for link down */
  1942. ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
  1943. if (ret_val)
  1944. goto release;
  1945. }
  1946. ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
  1947. release:
  1948. hw->phy.ops.release(hw);
  1949. return ret_val;
  1950. }
  1951. /**
  1952. * e1000_configure_k1_ich8lan - Configure K1 power state
  1953. * @hw: pointer to the HW structure
  1954. * @enable: K1 state to configure
  1955. *
  1956. * Configure the K1 power state based on the provided parameter.
  1957. * Assumes semaphore already acquired.
  1958. *
  1959. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1960. **/
  1961. s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
  1962. {
  1963. s32 ret_val;
  1964. u32 ctrl_reg = 0;
  1965. u32 ctrl_ext = 0;
  1966. u32 reg = 0;
  1967. u16 kmrn_reg = 0;
  1968. ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
  1969. &kmrn_reg);
  1970. if (ret_val)
  1971. return ret_val;
  1972. if (k1_enable)
  1973. kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
  1974. else
  1975. kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
  1976. ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
  1977. kmrn_reg);
  1978. if (ret_val)
  1979. return ret_val;
  1980. usleep_range(20, 40);
  1981. ctrl_ext = er32(CTRL_EXT);
  1982. ctrl_reg = er32(CTRL);
  1983. reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  1984. reg |= E1000_CTRL_FRCSPD;
  1985. ew32(CTRL, reg);
  1986. ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
  1987. e1e_flush();
  1988. usleep_range(20, 40);
  1989. ew32(CTRL, ctrl_reg);
  1990. ew32(CTRL_EXT, ctrl_ext);
  1991. e1e_flush();
  1992. usleep_range(20, 40);
  1993. return 0;
  1994. }
  1995. /**
  1996. * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
  1997. * @hw: pointer to the HW structure
  1998. * @d0_state: boolean if entering d0 or d3 device state
  1999. *
  2000. * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
  2001. * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
  2002. * in NVM determines whether HW should configure LPLU and Gbe Disable.
  2003. **/
  2004. static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
  2005. {
  2006. s32 ret_val = 0;
  2007. u32 mac_reg;
  2008. u16 oem_reg;
  2009. if (hw->mac.type < e1000_pchlan)
  2010. return ret_val;
  2011. ret_val = hw->phy.ops.acquire(hw);
  2012. if (ret_val)
  2013. return ret_val;
  2014. if (hw->mac.type == e1000_pchlan) {
  2015. mac_reg = er32(EXTCNF_CTRL);
  2016. if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
  2017. goto release;
  2018. }
  2019. mac_reg = er32(FEXTNVM);
  2020. if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
  2021. goto release;
  2022. mac_reg = er32(PHY_CTRL);
  2023. ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
  2024. if (ret_val)
  2025. goto release;
  2026. oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
  2027. if (d0_state) {
  2028. if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
  2029. oem_reg |= HV_OEM_BITS_GBE_DIS;
  2030. if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
  2031. oem_reg |= HV_OEM_BITS_LPLU;
  2032. } else {
  2033. if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
  2034. E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
  2035. oem_reg |= HV_OEM_BITS_GBE_DIS;
  2036. if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
  2037. E1000_PHY_CTRL_NOND0A_LPLU))
  2038. oem_reg |= HV_OEM_BITS_LPLU;
  2039. }
  2040. /* Set Restart auto-neg to activate the bits */
  2041. if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
  2042. !hw->phy.ops.check_reset_block(hw))
  2043. oem_reg |= HV_OEM_BITS_RESTART_AN;
  2044. ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
  2045. release:
  2046. hw->phy.ops.release(hw);
  2047. return ret_val;
  2048. }
  2049. /**
  2050. * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
  2051. * @hw: pointer to the HW structure
  2052. **/
  2053. static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
  2054. {
  2055. s32 ret_val;
  2056. u16 data;
  2057. ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
  2058. if (ret_val)
  2059. return ret_val;
  2060. data |= HV_KMRN_MDIO_SLOW;
  2061. ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
  2062. return ret_val;
  2063. }
  2064. /**
  2065. * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
  2066. * done after every PHY reset.
  2067. **/
  2068. static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
  2069. {
  2070. s32 ret_val = 0;
  2071. u16 phy_data;
  2072. if (hw->mac.type != e1000_pchlan)
  2073. return 0;
  2074. /* Set MDIO slow mode before any other MDIO access */
  2075. if (hw->phy.type == e1000_phy_82577) {
  2076. ret_val = e1000_set_mdio_slow_mode_hv(hw);
  2077. if (ret_val)
  2078. return ret_val;
  2079. }
  2080. if (((hw->phy.type == e1000_phy_82577) &&
  2081. ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
  2082. ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
  2083. /* Disable generation of early preamble */
  2084. ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
  2085. if (ret_val)
  2086. return ret_val;
  2087. /* Preamble tuning for SSC */
  2088. ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
  2089. if (ret_val)
  2090. return ret_val;
  2091. }
  2092. if (hw->phy.type == e1000_phy_82578) {
  2093. /* Return registers to default by doing a soft reset then
  2094. * writing 0x3140 to the control register.
  2095. */
  2096. if (hw->phy.revision < 2) {
  2097. e1000e_phy_sw_reset(hw);
  2098. ret_val = e1e_wphy(hw, MII_BMCR, 0x3140);
  2099. if (ret_val)
  2100. return ret_val;
  2101. }
  2102. }
  2103. /* Select page 0 */
  2104. ret_val = hw->phy.ops.acquire(hw);
  2105. if (ret_val)
  2106. return ret_val;
  2107. hw->phy.addr = 1;
  2108. ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
  2109. hw->phy.ops.release(hw);
  2110. if (ret_val)
  2111. return ret_val;
  2112. /* Configure the K1 Si workaround during phy reset assuming there is
  2113. * link so that it disables K1 if link is in 1Gbps.
  2114. */
  2115. ret_val = e1000_k1_gig_workaround_hv(hw, true);
  2116. if (ret_val)
  2117. return ret_val;
  2118. /* Workaround for link disconnects on a busy hub in half duplex */
  2119. ret_val = hw->phy.ops.acquire(hw);
  2120. if (ret_val)
  2121. return ret_val;
  2122. ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
  2123. if (ret_val)
  2124. goto release;
  2125. ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
  2126. if (ret_val)
  2127. goto release;
  2128. /* set MSE higher to enable link to stay up when noise is high */
  2129. ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
  2130. release:
  2131. hw->phy.ops.release(hw);
  2132. return ret_val;
  2133. }
  2134. /**
  2135. * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
  2136. * @hw: pointer to the HW structure
  2137. **/
  2138. void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
  2139. {
  2140. u32 mac_reg;
  2141. u16 i, phy_reg = 0;
  2142. s32 ret_val;
  2143. ret_val = hw->phy.ops.acquire(hw);
  2144. if (ret_val)
  2145. return;
  2146. ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
  2147. if (ret_val)
  2148. goto release;
  2149. /* Copy both RAL/H (rar_entry_count) and SHRAL/H to PHY */
  2150. for (i = 0; i < (hw->mac.rar_entry_count); i++) {
  2151. mac_reg = er32(RAL(i));
  2152. hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
  2153. (u16)(mac_reg & 0xFFFF));
  2154. hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
  2155. (u16)((mac_reg >> 16) & 0xFFFF));
  2156. mac_reg = er32(RAH(i));
  2157. hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
  2158. (u16)(mac_reg & 0xFFFF));
  2159. hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
  2160. (u16)((mac_reg & E1000_RAH_AV)
  2161. >> 16));
  2162. }
  2163. e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
  2164. release:
  2165. hw->phy.ops.release(hw);
  2166. }
  2167. /**
  2168. * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
  2169. * with 82579 PHY
  2170. * @hw: pointer to the HW structure
  2171. * @enable: flag to enable/disable workaround when enabling/disabling jumbos
  2172. **/
  2173. s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
  2174. {
  2175. s32 ret_val = 0;
  2176. u16 phy_reg, data;
  2177. u32 mac_reg;
  2178. u16 i;
  2179. if (hw->mac.type < e1000_pch2lan)
  2180. return 0;
  2181. /* disable Rx path while enabling/disabling workaround */
  2182. e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
  2183. ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | BIT(14));
  2184. if (ret_val)
  2185. return ret_val;
  2186. if (enable) {
  2187. /* Write Rx addresses (rar_entry_count for RAL/H, and
  2188. * SHRAL/H) and initial CRC values to the MAC
  2189. */
  2190. for (i = 0; i < hw->mac.rar_entry_count; i++) {
  2191. u8 mac_addr[ETH_ALEN] = { 0 };
  2192. u32 addr_high, addr_low;
  2193. addr_high = er32(RAH(i));
  2194. if (!(addr_high & E1000_RAH_AV))
  2195. continue;
  2196. addr_low = er32(RAL(i));
  2197. mac_addr[0] = (addr_low & 0xFF);
  2198. mac_addr[1] = ((addr_low >> 8) & 0xFF);
  2199. mac_addr[2] = ((addr_low >> 16) & 0xFF);
  2200. mac_addr[3] = ((addr_low >> 24) & 0xFF);
  2201. mac_addr[4] = (addr_high & 0xFF);
  2202. mac_addr[5] = ((addr_high >> 8) & 0xFF);
  2203. ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
  2204. }
  2205. /* Write Rx addresses to the PHY */
  2206. e1000_copy_rx_addrs_to_phy_ich8lan(hw);
  2207. /* Enable jumbo frame workaround in the MAC */
  2208. mac_reg = er32(FFLT_DBG);
  2209. mac_reg &= ~BIT(14);
  2210. mac_reg |= (7 << 15);
  2211. ew32(FFLT_DBG, mac_reg);
  2212. mac_reg = er32(RCTL);
  2213. mac_reg |= E1000_RCTL_SECRC;
  2214. ew32(RCTL, mac_reg);
  2215. ret_val = e1000e_read_kmrn_reg(hw,
  2216. E1000_KMRNCTRLSTA_CTRL_OFFSET,
  2217. &data);
  2218. if (ret_val)
  2219. return ret_val;
  2220. ret_val = e1000e_write_kmrn_reg(hw,
  2221. E1000_KMRNCTRLSTA_CTRL_OFFSET,
  2222. data | BIT(0));
  2223. if (ret_val)
  2224. return ret_val;
  2225. ret_val = e1000e_read_kmrn_reg(hw,
  2226. E1000_KMRNCTRLSTA_HD_CTRL,
  2227. &data);
  2228. if (ret_val)
  2229. return ret_val;
  2230. data &= ~(0xF << 8);
  2231. data |= (0xB << 8);
  2232. ret_val = e1000e_write_kmrn_reg(hw,
  2233. E1000_KMRNCTRLSTA_HD_CTRL,
  2234. data);
  2235. if (ret_val)
  2236. return ret_val;
  2237. /* Enable jumbo frame workaround in the PHY */
  2238. e1e_rphy(hw, PHY_REG(769, 23), &data);
  2239. data &= ~(0x7F << 5);
  2240. data |= (0x37 << 5);
  2241. ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
  2242. if (ret_val)
  2243. return ret_val;
  2244. e1e_rphy(hw, PHY_REG(769, 16), &data);
  2245. data &= ~BIT(13);
  2246. ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
  2247. if (ret_val)
  2248. return ret_val;
  2249. e1e_rphy(hw, PHY_REG(776, 20), &data);
  2250. data &= ~(0x3FF << 2);
  2251. data |= (E1000_TX_PTR_GAP << 2);
  2252. ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
  2253. if (ret_val)
  2254. return ret_val;
  2255. ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
  2256. if (ret_val)
  2257. return ret_val;
  2258. e1e_rphy(hw, HV_PM_CTRL, &data);
  2259. ret_val = e1e_wphy(hw, HV_PM_CTRL, data | BIT(10));
  2260. if (ret_val)
  2261. return ret_val;
  2262. } else {
  2263. /* Write MAC register values back to h/w defaults */
  2264. mac_reg = er32(FFLT_DBG);
  2265. mac_reg &= ~(0xF << 14);
  2266. ew32(FFLT_DBG, mac_reg);
  2267. mac_reg = er32(RCTL);
  2268. mac_reg &= ~E1000_RCTL_SECRC;
  2269. ew32(RCTL, mac_reg);
  2270. ret_val = e1000e_read_kmrn_reg(hw,
  2271. E1000_KMRNCTRLSTA_CTRL_OFFSET,
  2272. &data);
  2273. if (ret_val)
  2274. return ret_val;
  2275. ret_val = e1000e_write_kmrn_reg(hw,
  2276. E1000_KMRNCTRLSTA_CTRL_OFFSET,
  2277. data & ~BIT(0));
  2278. if (ret_val)
  2279. return ret_val;
  2280. ret_val = e1000e_read_kmrn_reg(hw,
  2281. E1000_KMRNCTRLSTA_HD_CTRL,
  2282. &data);
  2283. if (ret_val)
  2284. return ret_val;
  2285. data &= ~(0xF << 8);
  2286. data |= (0xB << 8);
  2287. ret_val = e1000e_write_kmrn_reg(hw,
  2288. E1000_KMRNCTRLSTA_HD_CTRL,
  2289. data);
  2290. if (ret_val)
  2291. return ret_val;
  2292. /* Write PHY register values back to h/w defaults */
  2293. e1e_rphy(hw, PHY_REG(769, 23), &data);
  2294. data &= ~(0x7F << 5);
  2295. ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
  2296. if (ret_val)
  2297. return ret_val;
  2298. e1e_rphy(hw, PHY_REG(769, 16), &data);
  2299. data |= BIT(13);
  2300. ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
  2301. if (ret_val)
  2302. return ret_val;
  2303. e1e_rphy(hw, PHY_REG(776, 20), &data);
  2304. data &= ~(0x3FF << 2);
  2305. data |= (0x8 << 2);
  2306. ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
  2307. if (ret_val)
  2308. return ret_val;
  2309. ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
  2310. if (ret_val)
  2311. return ret_val;
  2312. e1e_rphy(hw, HV_PM_CTRL, &data);
  2313. ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~BIT(10));
  2314. if (ret_val)
  2315. return ret_val;
  2316. }
  2317. /* re-enable Rx path after enabling/disabling workaround */
  2318. return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~BIT(14));
  2319. }
  2320. /**
  2321. * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
  2322. * done after every PHY reset.
  2323. **/
  2324. static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
  2325. {
  2326. s32 ret_val = 0;
  2327. if (hw->mac.type != e1000_pch2lan)
  2328. return 0;
  2329. /* Set MDIO slow mode before any other MDIO access */
  2330. ret_val = e1000_set_mdio_slow_mode_hv(hw);
  2331. if (ret_val)
  2332. return ret_val;
  2333. ret_val = hw->phy.ops.acquire(hw);
  2334. if (ret_val)
  2335. return ret_val;
  2336. /* set MSE higher to enable link to stay up when noise is high */
  2337. ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
  2338. if (ret_val)
  2339. goto release;
  2340. /* drop link after 5 times MSE threshold was reached */
  2341. ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
  2342. release:
  2343. hw->phy.ops.release(hw);
  2344. return ret_val;
  2345. }
  2346. /**
  2347. * e1000_k1_gig_workaround_lv - K1 Si workaround
  2348. * @hw: pointer to the HW structure
  2349. *
  2350. * Workaround to set the K1 beacon duration for 82579 parts in 10Mbps
  2351. * Disable K1 in 1000Mbps and 100Mbps
  2352. **/
  2353. static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
  2354. {
  2355. s32 ret_val = 0;
  2356. u16 status_reg = 0;
  2357. if (hw->mac.type != e1000_pch2lan)
  2358. return 0;
  2359. /* Set K1 beacon duration based on 10Mbs speed */
  2360. ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
  2361. if (ret_val)
  2362. return ret_val;
  2363. if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
  2364. == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
  2365. if (status_reg &
  2366. (HV_M_STATUS_SPEED_1000 | HV_M_STATUS_SPEED_100)) {
  2367. u16 pm_phy_reg;
  2368. /* LV 1G/100 Packet drop issue wa */
  2369. ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
  2370. if (ret_val)
  2371. return ret_val;
  2372. pm_phy_reg &= ~HV_PM_CTRL_K1_ENABLE;
  2373. ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
  2374. if (ret_val)
  2375. return ret_val;
  2376. } else {
  2377. u32 mac_reg;
  2378. mac_reg = er32(FEXTNVM4);
  2379. mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
  2380. mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
  2381. ew32(FEXTNVM4, mac_reg);
  2382. }
  2383. }
  2384. return ret_val;
  2385. }
  2386. /**
  2387. * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
  2388. * @hw: pointer to the HW structure
  2389. * @gate: boolean set to true to gate, false to ungate
  2390. *
  2391. * Gate/ungate the automatic PHY configuration via hardware; perform
  2392. * the configuration via software instead.
  2393. **/
  2394. static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
  2395. {
  2396. u32 extcnf_ctrl;
  2397. if (hw->mac.type < e1000_pch2lan)
  2398. return;
  2399. extcnf_ctrl = er32(EXTCNF_CTRL);
  2400. if (gate)
  2401. extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
  2402. else
  2403. extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
  2404. ew32(EXTCNF_CTRL, extcnf_ctrl);
  2405. }
  2406. /**
  2407. * e1000_lan_init_done_ich8lan - Check for PHY config completion
  2408. * @hw: pointer to the HW structure
  2409. *
  2410. * Check the appropriate indication the MAC has finished configuring the
  2411. * PHY after a software reset.
  2412. **/
  2413. static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
  2414. {
  2415. u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
  2416. /* Wait for basic configuration completes before proceeding */
  2417. do {
  2418. data = er32(STATUS);
  2419. data &= E1000_STATUS_LAN_INIT_DONE;
  2420. usleep_range(100, 200);
  2421. } while ((!data) && --loop);
  2422. /* If basic configuration is incomplete before the above loop
  2423. * count reaches 0, loading the configuration from NVM will
  2424. * leave the PHY in a bad state possibly resulting in no link.
  2425. */
  2426. if (loop == 0)
  2427. e_dbg("LAN_INIT_DONE not set, increase timeout\n");
  2428. /* Clear the Init Done bit for the next init event */
  2429. data = er32(STATUS);
  2430. data &= ~E1000_STATUS_LAN_INIT_DONE;
  2431. ew32(STATUS, data);
  2432. }
  2433. /**
  2434. * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
  2435. * @hw: pointer to the HW structure
  2436. **/
  2437. static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
  2438. {
  2439. s32 ret_val = 0;
  2440. u16 reg;
  2441. if (hw->phy.ops.check_reset_block(hw))
  2442. return 0;
  2443. /* Allow time for h/w to get to quiescent state after reset */
  2444. usleep_range(10000, 11000);
  2445. /* Perform any necessary post-reset workarounds */
  2446. switch (hw->mac.type) {
  2447. case e1000_pchlan:
  2448. ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
  2449. if (ret_val)
  2450. return ret_val;
  2451. break;
  2452. case e1000_pch2lan:
  2453. ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
  2454. if (ret_val)
  2455. return ret_val;
  2456. break;
  2457. default:
  2458. break;
  2459. }
  2460. /* Clear the host wakeup bit after lcd reset */
  2461. if (hw->mac.type >= e1000_pchlan) {
  2462. e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
  2463. reg &= ~BM_WUC_HOST_WU_BIT;
  2464. e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
  2465. }
  2466. /* Configure the LCD with the extended configuration region in NVM */
  2467. ret_val = e1000_sw_lcd_config_ich8lan(hw);
  2468. if (ret_val)
  2469. return ret_val;
  2470. /* Configure the LCD with the OEM bits in NVM */
  2471. ret_val = e1000_oem_bits_config_ich8lan(hw, true);
  2472. if (hw->mac.type == e1000_pch2lan) {
  2473. /* Ungate automatic PHY configuration on non-managed 82579 */
  2474. if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
  2475. usleep_range(10000, 11000);
  2476. e1000_gate_hw_phy_config_ich8lan(hw, false);
  2477. }
  2478. /* Set EEE LPI Update Timer to 200usec */
  2479. ret_val = hw->phy.ops.acquire(hw);
  2480. if (ret_val)
  2481. return ret_val;
  2482. ret_val = e1000_write_emi_reg_locked(hw,
  2483. I82579_LPI_UPDATE_TIMER,
  2484. 0x1387);
  2485. hw->phy.ops.release(hw);
  2486. }
  2487. return ret_val;
  2488. }
  2489. /**
  2490. * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
  2491. * @hw: pointer to the HW structure
  2492. *
  2493. * Resets the PHY
  2494. * This is a function pointer entry point called by drivers
  2495. * or other shared routines.
  2496. **/
  2497. static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
  2498. {
  2499. s32 ret_val = 0;
  2500. /* Gate automatic PHY configuration by hardware on non-managed 82579 */
  2501. if ((hw->mac.type == e1000_pch2lan) &&
  2502. !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
  2503. e1000_gate_hw_phy_config_ich8lan(hw, true);
  2504. ret_val = e1000e_phy_hw_reset_generic(hw);
  2505. if (ret_val)
  2506. return ret_val;
  2507. return e1000_post_phy_reset_ich8lan(hw);
  2508. }
  2509. /**
  2510. * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
  2511. * @hw: pointer to the HW structure
  2512. * @active: true to enable LPLU, false to disable
  2513. *
  2514. * Sets the LPLU state according to the active flag. For PCH, if OEM write
  2515. * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
  2516. * the phy speed. This function will manually set the LPLU bit and restart
  2517. * auto-neg as hw would do. D3 and D0 LPLU will call the same function
  2518. * since it configures the same bit.
  2519. **/
  2520. static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
  2521. {
  2522. s32 ret_val;
  2523. u16 oem_reg;
  2524. ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
  2525. if (ret_val)
  2526. return ret_val;
  2527. if (active)
  2528. oem_reg |= HV_OEM_BITS_LPLU;
  2529. else
  2530. oem_reg &= ~HV_OEM_BITS_LPLU;
  2531. if (!hw->phy.ops.check_reset_block(hw))
  2532. oem_reg |= HV_OEM_BITS_RESTART_AN;
  2533. return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
  2534. }
  2535. /**
  2536. * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
  2537. * @hw: pointer to the HW structure
  2538. * @active: true to enable LPLU, false to disable
  2539. *
  2540. * Sets the LPLU D0 state according to the active flag. When
  2541. * activating LPLU this function also disables smart speed
  2542. * and vice versa. LPLU will not be activated unless the
  2543. * device autonegotiation advertisement meets standards of
  2544. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  2545. * This is a function pointer entry point only called by
  2546. * PHY setup routines.
  2547. **/
  2548. static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
  2549. {
  2550. struct e1000_phy_info *phy = &hw->phy;
  2551. u32 phy_ctrl;
  2552. s32 ret_val = 0;
  2553. u16 data;
  2554. if (phy->type == e1000_phy_ife)
  2555. return 0;
  2556. phy_ctrl = er32(PHY_CTRL);
  2557. if (active) {
  2558. phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
  2559. ew32(PHY_CTRL, phy_ctrl);
  2560. if (phy->type != e1000_phy_igp_3)
  2561. return 0;
  2562. /* Call gig speed drop workaround on LPLU before accessing
  2563. * any PHY registers
  2564. */
  2565. if (hw->mac.type == e1000_ich8lan)
  2566. e1000e_gig_downshift_workaround_ich8lan(hw);
  2567. /* When LPLU is enabled, we should disable SmartSpeed */
  2568. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
  2569. if (ret_val)
  2570. return ret_val;
  2571. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2572. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
  2573. if (ret_val)
  2574. return ret_val;
  2575. } else {
  2576. phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
  2577. ew32(PHY_CTRL, phy_ctrl);
  2578. if (phy->type != e1000_phy_igp_3)
  2579. return 0;
  2580. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  2581. * during Dx states where the power conservation is most
  2582. * important. During driver activity we should enable
  2583. * SmartSpeed, so performance is maintained.
  2584. */
  2585. if (phy->smart_speed == e1000_smart_speed_on) {
  2586. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2587. &data);
  2588. if (ret_val)
  2589. return ret_val;
  2590. data |= IGP01E1000_PSCFR_SMART_SPEED;
  2591. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2592. data);
  2593. if (ret_val)
  2594. return ret_val;
  2595. } else if (phy->smart_speed == e1000_smart_speed_off) {
  2596. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2597. &data);
  2598. if (ret_val)
  2599. return ret_val;
  2600. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2601. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2602. data);
  2603. if (ret_val)
  2604. return ret_val;
  2605. }
  2606. }
  2607. return 0;
  2608. }
  2609. /**
  2610. * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
  2611. * @hw: pointer to the HW structure
  2612. * @active: true to enable LPLU, false to disable
  2613. *
  2614. * Sets the LPLU D3 state according to the active flag. When
  2615. * activating LPLU this function also disables smart speed
  2616. * and vice versa. LPLU will not be activated unless the
  2617. * device autonegotiation advertisement meets standards of
  2618. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  2619. * This is a function pointer entry point only called by
  2620. * PHY setup routines.
  2621. **/
  2622. static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
  2623. {
  2624. struct e1000_phy_info *phy = &hw->phy;
  2625. u32 phy_ctrl;
  2626. s32 ret_val = 0;
  2627. u16 data;
  2628. phy_ctrl = er32(PHY_CTRL);
  2629. if (!active) {
  2630. phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
  2631. ew32(PHY_CTRL, phy_ctrl);
  2632. if (phy->type != e1000_phy_igp_3)
  2633. return 0;
  2634. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  2635. * during Dx states where the power conservation is most
  2636. * important. During driver activity we should enable
  2637. * SmartSpeed, so performance is maintained.
  2638. */
  2639. if (phy->smart_speed == e1000_smart_speed_on) {
  2640. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2641. &data);
  2642. if (ret_val)
  2643. return ret_val;
  2644. data |= IGP01E1000_PSCFR_SMART_SPEED;
  2645. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2646. data);
  2647. if (ret_val)
  2648. return ret_val;
  2649. } else if (phy->smart_speed == e1000_smart_speed_off) {
  2650. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2651. &data);
  2652. if (ret_val)
  2653. return ret_val;
  2654. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2655. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2656. data);
  2657. if (ret_val)
  2658. return ret_val;
  2659. }
  2660. } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
  2661. (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
  2662. (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
  2663. phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
  2664. ew32(PHY_CTRL, phy_ctrl);
  2665. if (phy->type != e1000_phy_igp_3)
  2666. return 0;
  2667. /* Call gig speed drop workaround on LPLU before accessing
  2668. * any PHY registers
  2669. */
  2670. if (hw->mac.type == e1000_ich8lan)
  2671. e1000e_gig_downshift_workaround_ich8lan(hw);
  2672. /* When LPLU is enabled, we should disable SmartSpeed */
  2673. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
  2674. if (ret_val)
  2675. return ret_val;
  2676. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2677. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
  2678. }
  2679. return ret_val;
  2680. }
  2681. /**
  2682. * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
  2683. * @hw: pointer to the HW structure
  2684. * @bank: pointer to the variable that returns the active bank
  2685. *
  2686. * Reads signature byte from the NVM using the flash access registers.
  2687. * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
  2688. **/
  2689. static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
  2690. {
  2691. u32 eecd;
  2692. struct e1000_nvm_info *nvm = &hw->nvm;
  2693. u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
  2694. u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
  2695. u32 nvm_dword = 0;
  2696. u8 sig_byte = 0;
  2697. s32 ret_val;
  2698. switch (hw->mac.type) {
  2699. case e1000_pch_spt:
  2700. case e1000_pch_cnp:
  2701. case e1000_pch_tgp:
  2702. case e1000_pch_adp:
  2703. bank1_offset = nvm->flash_bank_size;
  2704. act_offset = E1000_ICH_NVM_SIG_WORD;
  2705. /* set bank to 0 in case flash read fails */
  2706. *bank = 0;
  2707. /* Check bank 0 */
  2708. ret_val = e1000_read_flash_dword_ich8lan(hw, act_offset,
  2709. &nvm_dword);
  2710. if (ret_val)
  2711. return ret_val;
  2712. sig_byte = (u8)((nvm_dword & 0xFF00) >> 8);
  2713. if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
  2714. E1000_ICH_NVM_SIG_VALUE) {
  2715. *bank = 0;
  2716. return 0;
  2717. }
  2718. /* Check bank 1 */
  2719. ret_val = e1000_read_flash_dword_ich8lan(hw, act_offset +
  2720. bank1_offset,
  2721. &nvm_dword);
  2722. if (ret_val)
  2723. return ret_val;
  2724. sig_byte = (u8)((nvm_dword & 0xFF00) >> 8);
  2725. if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
  2726. E1000_ICH_NVM_SIG_VALUE) {
  2727. *bank = 1;
  2728. return 0;
  2729. }
  2730. e_dbg("ERROR: No valid NVM bank present\n");
  2731. return -E1000_ERR_NVM;
  2732. case e1000_ich8lan:
  2733. case e1000_ich9lan:
  2734. eecd = er32(EECD);
  2735. if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
  2736. E1000_EECD_SEC1VAL_VALID_MASK) {
  2737. if (eecd & E1000_EECD_SEC1VAL)
  2738. *bank = 1;
  2739. else
  2740. *bank = 0;
  2741. return 0;
  2742. }
  2743. e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
  2744. /* fall-thru */
  2745. default:
  2746. /* set bank to 0 in case flash read fails */
  2747. *bank = 0;
  2748. /* Check bank 0 */
  2749. ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
  2750. &sig_byte);
  2751. if (ret_val)
  2752. return ret_val;
  2753. if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
  2754. E1000_ICH_NVM_SIG_VALUE) {
  2755. *bank = 0;
  2756. return 0;
  2757. }
  2758. /* Check bank 1 */
  2759. ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
  2760. bank1_offset,
  2761. &sig_byte);
  2762. if (ret_val)
  2763. return ret_val;
  2764. if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
  2765. E1000_ICH_NVM_SIG_VALUE) {
  2766. *bank = 1;
  2767. return 0;
  2768. }
  2769. e_dbg("ERROR: No valid NVM bank present\n");
  2770. return -E1000_ERR_NVM;
  2771. }
  2772. }
  2773. /**
  2774. * e1000_read_nvm_spt - NVM access for SPT
  2775. * @hw: pointer to the HW structure
  2776. * @offset: The offset (in bytes) of the word(s) to read.
  2777. * @words: Size of data to read in words.
  2778. * @data: pointer to the word(s) to read at offset.
  2779. *
  2780. * Reads a word(s) from the NVM
  2781. **/
  2782. static s32 e1000_read_nvm_spt(struct e1000_hw *hw, u16 offset, u16 words,
  2783. u16 *data)
  2784. {
  2785. struct e1000_nvm_info *nvm = &hw->nvm;
  2786. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  2787. u32 act_offset;
  2788. s32 ret_val = 0;
  2789. u32 bank = 0;
  2790. u32 dword = 0;
  2791. u16 offset_to_read;
  2792. u16 i;
  2793. if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
  2794. (words == 0)) {
  2795. e_dbg("nvm parameter(s) out of bounds\n");
  2796. ret_val = -E1000_ERR_NVM;
  2797. goto out;
  2798. }
  2799. nvm->ops.acquire(hw);
  2800. ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
  2801. if (ret_val) {
  2802. e_dbg("Could not detect valid bank, assuming bank 0\n");
  2803. bank = 0;
  2804. }
  2805. act_offset = (bank) ? nvm->flash_bank_size : 0;
  2806. act_offset += offset;
  2807. ret_val = 0;
  2808. for (i = 0; i < words; i += 2) {
  2809. if (words - i == 1) {
  2810. if (dev_spec->shadow_ram[offset + i].modified) {
  2811. data[i] =
  2812. dev_spec->shadow_ram[offset + i].value;
  2813. } else {
  2814. offset_to_read = act_offset + i -
  2815. ((act_offset + i) % 2);
  2816. ret_val =
  2817. e1000_read_flash_dword_ich8lan(hw,
  2818. offset_to_read,
  2819. &dword);
  2820. if (ret_val)
  2821. break;
  2822. if ((act_offset + i) % 2 == 0)
  2823. data[i] = (u16)(dword & 0xFFFF);
  2824. else
  2825. data[i] = (u16)((dword >> 16) & 0xFFFF);
  2826. }
  2827. } else {
  2828. offset_to_read = act_offset + i;
  2829. if (!(dev_spec->shadow_ram[offset + i].modified) ||
  2830. !(dev_spec->shadow_ram[offset + i + 1].modified)) {
  2831. ret_val =
  2832. e1000_read_flash_dword_ich8lan(hw,
  2833. offset_to_read,
  2834. &dword);
  2835. if (ret_val)
  2836. break;
  2837. }
  2838. if (dev_spec->shadow_ram[offset + i].modified)
  2839. data[i] =
  2840. dev_spec->shadow_ram[offset + i].value;
  2841. else
  2842. data[i] = (u16)(dword & 0xFFFF);
  2843. if (dev_spec->shadow_ram[offset + i].modified)
  2844. data[i + 1] =
  2845. dev_spec->shadow_ram[offset + i + 1].value;
  2846. else
  2847. data[i + 1] = (u16)(dword >> 16 & 0xFFFF);
  2848. }
  2849. }
  2850. nvm->ops.release(hw);
  2851. out:
  2852. if (ret_val)
  2853. e_dbg("NVM read error: %d\n", ret_val);
  2854. return ret_val;
  2855. }
  2856. /**
  2857. * e1000_read_nvm_ich8lan - Read word(s) from the NVM
  2858. * @hw: pointer to the HW structure
  2859. * @offset: The offset (in bytes) of the word(s) to read.
  2860. * @words: Size of data to read in words
  2861. * @data: Pointer to the word(s) to read at offset.
  2862. *
  2863. * Reads a word(s) from the NVM using the flash access registers.
  2864. **/
  2865. static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
  2866. u16 *data)
  2867. {
  2868. struct e1000_nvm_info *nvm = &hw->nvm;
  2869. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  2870. u32 act_offset;
  2871. s32 ret_val = 0;
  2872. u32 bank = 0;
  2873. u16 i, word;
  2874. if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
  2875. (words == 0)) {
  2876. e_dbg("nvm parameter(s) out of bounds\n");
  2877. ret_val = -E1000_ERR_NVM;
  2878. goto out;
  2879. }
  2880. nvm->ops.acquire(hw);
  2881. ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
  2882. if (ret_val) {
  2883. e_dbg("Could not detect valid bank, assuming bank 0\n");
  2884. bank = 0;
  2885. }
  2886. act_offset = (bank) ? nvm->flash_bank_size : 0;
  2887. act_offset += offset;
  2888. ret_val = 0;
  2889. for (i = 0; i < words; i++) {
  2890. if (dev_spec->shadow_ram[offset + i].modified) {
  2891. data[i] = dev_spec->shadow_ram[offset + i].value;
  2892. } else {
  2893. ret_val = e1000_read_flash_word_ich8lan(hw,
  2894. act_offset + i,
  2895. &word);
  2896. if (ret_val)
  2897. break;
  2898. data[i] = word;
  2899. }
  2900. }
  2901. nvm->ops.release(hw);
  2902. out:
  2903. if (ret_val)
  2904. e_dbg("NVM read error: %d\n", ret_val);
  2905. return ret_val;
  2906. }
  2907. /**
  2908. * e1000_flash_cycle_init_ich8lan - Initialize flash
  2909. * @hw: pointer to the HW structure
  2910. *
  2911. * This function does initial flash setup so that a new read/write/erase cycle
  2912. * can be started.
  2913. **/
  2914. static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
  2915. {
  2916. union ich8_hws_flash_status hsfsts;
  2917. s32 ret_val = -E1000_ERR_NVM;
  2918. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2919. /* Check if the flash descriptor is valid */
  2920. if (!hsfsts.hsf_status.fldesvalid) {
  2921. e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
  2922. return -E1000_ERR_NVM;
  2923. }
  2924. /* Clear FCERR and DAEL in hw status by writing 1 */
  2925. hsfsts.hsf_status.flcerr = 1;
  2926. hsfsts.hsf_status.dael = 1;
  2927. if (hw->mac.type >= e1000_pch_spt)
  2928. ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval & 0xFFFF);
  2929. else
  2930. ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  2931. /* Either we should have a hardware SPI cycle in progress
  2932. * bit to check against, in order to start a new cycle or
  2933. * FDONE bit should be changed in the hardware so that it
  2934. * is 1 after hardware reset, which can then be used as an
  2935. * indication whether a cycle is in progress or has been
  2936. * completed.
  2937. */
  2938. if (!hsfsts.hsf_status.flcinprog) {
  2939. /* There is no cycle running at present,
  2940. * so we can start a cycle.
  2941. * Begin by setting Flash Cycle Done.
  2942. */
  2943. hsfsts.hsf_status.flcdone = 1;
  2944. if (hw->mac.type >= e1000_pch_spt)
  2945. ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval & 0xFFFF);
  2946. else
  2947. ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  2948. ret_val = 0;
  2949. } else {
  2950. s32 i;
  2951. /* Otherwise poll for sometime so the current
  2952. * cycle has a chance to end before giving up.
  2953. */
  2954. for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
  2955. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2956. if (!hsfsts.hsf_status.flcinprog) {
  2957. ret_val = 0;
  2958. break;
  2959. }
  2960. udelay(1);
  2961. }
  2962. if (!ret_val) {
  2963. /* Successful in waiting for previous cycle to timeout,
  2964. * now set the Flash Cycle Done.
  2965. */
  2966. hsfsts.hsf_status.flcdone = 1;
  2967. if (hw->mac.type >= e1000_pch_spt)
  2968. ew32flash(ICH_FLASH_HSFSTS,
  2969. hsfsts.regval & 0xFFFF);
  2970. else
  2971. ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  2972. } else {
  2973. e_dbg("Flash controller busy, cannot get access\n");
  2974. }
  2975. }
  2976. return ret_val;
  2977. }
  2978. /**
  2979. * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
  2980. * @hw: pointer to the HW structure
  2981. * @timeout: maximum time to wait for completion
  2982. *
  2983. * This function starts a flash cycle and waits for its completion.
  2984. **/
  2985. static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
  2986. {
  2987. union ich8_hws_flash_ctrl hsflctl;
  2988. union ich8_hws_flash_status hsfsts;
  2989. u32 i = 0;
  2990. /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
  2991. if (hw->mac.type >= e1000_pch_spt)
  2992. hsflctl.regval = er32flash(ICH_FLASH_HSFSTS) >> 16;
  2993. else
  2994. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  2995. hsflctl.hsf_ctrl.flcgo = 1;
  2996. if (hw->mac.type >= e1000_pch_spt)
  2997. ew32flash(ICH_FLASH_HSFSTS, hsflctl.regval << 16);
  2998. else
  2999. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  3000. /* wait till FDONE bit is set to 1 */
  3001. do {
  3002. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3003. if (hsfsts.hsf_status.flcdone)
  3004. break;
  3005. udelay(1);
  3006. } while (i++ < timeout);
  3007. if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
  3008. return 0;
  3009. return -E1000_ERR_NVM;
  3010. }
  3011. /**
  3012. * e1000_read_flash_dword_ich8lan - Read dword from flash
  3013. * @hw: pointer to the HW structure
  3014. * @offset: offset to data location
  3015. * @data: pointer to the location for storing the data
  3016. *
  3017. * Reads the flash dword at offset into data. Offset is converted
  3018. * to bytes before read.
  3019. **/
  3020. static s32 e1000_read_flash_dword_ich8lan(struct e1000_hw *hw, u32 offset,
  3021. u32 *data)
  3022. {
  3023. /* Must convert word offset into bytes. */
  3024. offset <<= 1;
  3025. return e1000_read_flash_data32_ich8lan(hw, offset, data);
  3026. }
  3027. /**
  3028. * e1000_read_flash_word_ich8lan - Read word from flash
  3029. * @hw: pointer to the HW structure
  3030. * @offset: offset to data location
  3031. * @data: pointer to the location for storing the data
  3032. *
  3033. * Reads the flash word at offset into data. Offset is converted
  3034. * to bytes before read.
  3035. **/
  3036. static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
  3037. u16 *data)
  3038. {
  3039. /* Must convert offset into bytes. */
  3040. offset <<= 1;
  3041. return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
  3042. }
  3043. /**
  3044. * e1000_read_flash_byte_ich8lan - Read byte from flash
  3045. * @hw: pointer to the HW structure
  3046. * @offset: The offset of the byte to read.
  3047. * @data: Pointer to a byte to store the value read.
  3048. *
  3049. * Reads a single byte from the NVM using the flash access registers.
  3050. **/
  3051. static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
  3052. u8 *data)
  3053. {
  3054. s32 ret_val;
  3055. u16 word = 0;
  3056. /* In SPT, only 32 bits access is supported,
  3057. * so this function should not be called.
  3058. */
  3059. if (hw->mac.type >= e1000_pch_spt)
  3060. return -E1000_ERR_NVM;
  3061. else
  3062. ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
  3063. if (ret_val)
  3064. return ret_val;
  3065. *data = (u8)word;
  3066. return 0;
  3067. }
  3068. /**
  3069. * e1000_read_flash_data_ich8lan - Read byte or word from NVM
  3070. * @hw: pointer to the HW structure
  3071. * @offset: The offset (in bytes) of the byte or word to read.
  3072. * @size: Size of data to read, 1=byte 2=word
  3073. * @data: Pointer to the word to store the value read.
  3074. *
  3075. * Reads a byte or word from the NVM using the flash access registers.
  3076. **/
  3077. static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
  3078. u8 size, u16 *data)
  3079. {
  3080. union ich8_hws_flash_status hsfsts;
  3081. union ich8_hws_flash_ctrl hsflctl;
  3082. u32 flash_linear_addr;
  3083. u32 flash_data = 0;
  3084. s32 ret_val = -E1000_ERR_NVM;
  3085. u8 count = 0;
  3086. if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
  3087. return -E1000_ERR_NVM;
  3088. flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
  3089. hw->nvm.flash_base_addr);
  3090. do {
  3091. udelay(1);
  3092. /* Steps */
  3093. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  3094. if (ret_val)
  3095. break;
  3096. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  3097. /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
  3098. hsflctl.hsf_ctrl.fldbcount = size - 1;
  3099. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
  3100. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  3101. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  3102. ret_val =
  3103. e1000_flash_cycle_ich8lan(hw,
  3104. ICH_FLASH_READ_COMMAND_TIMEOUT);
  3105. /* Check if FCERR is set to 1, if set to 1, clear it
  3106. * and try the whole sequence a few more times, else
  3107. * read in (shift in) the Flash Data0, the order is
  3108. * least significant byte first msb to lsb
  3109. */
  3110. if (!ret_val) {
  3111. flash_data = er32flash(ICH_FLASH_FDATA0);
  3112. if (size == 1)
  3113. *data = (u8)(flash_data & 0x000000FF);
  3114. else if (size == 2)
  3115. *data = (u16)(flash_data & 0x0000FFFF);
  3116. break;
  3117. } else {
  3118. /* If we've gotten here, then things are probably
  3119. * completely hosed, but if the error condition is
  3120. * detected, it won't hurt to give it another try...
  3121. * ICH_FLASH_CYCLE_REPEAT_COUNT times.
  3122. */
  3123. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3124. if (hsfsts.hsf_status.flcerr) {
  3125. /* Repeat for some time before giving up. */
  3126. continue;
  3127. } else if (!hsfsts.hsf_status.flcdone) {
  3128. e_dbg("Timeout error - flash cycle did not complete.\n");
  3129. break;
  3130. }
  3131. }
  3132. } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
  3133. return ret_val;
  3134. }
  3135. /**
  3136. * e1000_read_flash_data32_ich8lan - Read dword from NVM
  3137. * @hw: pointer to the HW structure
  3138. * @offset: The offset (in bytes) of the dword to read.
  3139. * @data: Pointer to the dword to store the value read.
  3140. *
  3141. * Reads a byte or word from the NVM using the flash access registers.
  3142. **/
  3143. static s32 e1000_read_flash_data32_ich8lan(struct e1000_hw *hw, u32 offset,
  3144. u32 *data)
  3145. {
  3146. union ich8_hws_flash_status hsfsts;
  3147. union ich8_hws_flash_ctrl hsflctl;
  3148. u32 flash_linear_addr;
  3149. s32 ret_val = -E1000_ERR_NVM;
  3150. u8 count = 0;
  3151. if (offset > ICH_FLASH_LINEAR_ADDR_MASK || hw->mac.type < e1000_pch_spt)
  3152. return -E1000_ERR_NVM;
  3153. flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
  3154. hw->nvm.flash_base_addr);
  3155. do {
  3156. udelay(1);
  3157. /* Steps */
  3158. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  3159. if (ret_val)
  3160. break;
  3161. /* In SPT, This register is in Lan memory space, not flash.
  3162. * Therefore, only 32 bit access is supported
  3163. */
  3164. hsflctl.regval = er32flash(ICH_FLASH_HSFSTS) >> 16;
  3165. /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
  3166. hsflctl.hsf_ctrl.fldbcount = sizeof(u32) - 1;
  3167. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
  3168. /* In SPT, This register is in Lan memory space, not flash.
  3169. * Therefore, only 32 bit access is supported
  3170. */
  3171. ew32flash(ICH_FLASH_HSFSTS, (u32)hsflctl.regval << 16);
  3172. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  3173. ret_val =
  3174. e1000_flash_cycle_ich8lan(hw,
  3175. ICH_FLASH_READ_COMMAND_TIMEOUT);
  3176. /* Check if FCERR is set to 1, if set to 1, clear it
  3177. * and try the whole sequence a few more times, else
  3178. * read in (shift in) the Flash Data0, the order is
  3179. * least significant byte first msb to lsb
  3180. */
  3181. if (!ret_val) {
  3182. *data = er32flash(ICH_FLASH_FDATA0);
  3183. break;
  3184. } else {
  3185. /* If we've gotten here, then things are probably
  3186. * completely hosed, but if the error condition is
  3187. * detected, it won't hurt to give it another try...
  3188. * ICH_FLASH_CYCLE_REPEAT_COUNT times.
  3189. */
  3190. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3191. if (hsfsts.hsf_status.flcerr) {
  3192. /* Repeat for some time before giving up. */
  3193. continue;
  3194. } else if (!hsfsts.hsf_status.flcdone) {
  3195. e_dbg("Timeout error - flash cycle did not complete.\n");
  3196. break;
  3197. }
  3198. }
  3199. } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
  3200. return ret_val;
  3201. }
  3202. /**
  3203. * e1000_write_nvm_ich8lan - Write word(s) to the NVM
  3204. * @hw: pointer to the HW structure
  3205. * @offset: The offset (in bytes) of the word(s) to write.
  3206. * @words: Size of data to write in words
  3207. * @data: Pointer to the word(s) to write at offset.
  3208. *
  3209. * Writes a byte or word to the NVM using the flash access registers.
  3210. **/
  3211. static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
  3212. u16 *data)
  3213. {
  3214. struct e1000_nvm_info *nvm = &hw->nvm;
  3215. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  3216. u16 i;
  3217. if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
  3218. (words == 0)) {
  3219. e_dbg("nvm parameter(s) out of bounds\n");
  3220. return -E1000_ERR_NVM;
  3221. }
  3222. nvm->ops.acquire(hw);
  3223. for (i = 0; i < words; i++) {
  3224. dev_spec->shadow_ram[offset + i].modified = true;
  3225. dev_spec->shadow_ram[offset + i].value = data[i];
  3226. }
  3227. nvm->ops.release(hw);
  3228. return 0;
  3229. }
  3230. /**
  3231. * e1000_update_nvm_checksum_spt - Update the checksum for NVM
  3232. * @hw: pointer to the HW structure
  3233. *
  3234. * The NVM checksum is updated by calling the generic update_nvm_checksum,
  3235. * which writes the checksum to the shadow ram. The changes in the shadow
  3236. * ram are then committed to the EEPROM by processing each bank at a time
  3237. * checking for the modified bit and writing only the pending changes.
  3238. * After a successful commit, the shadow ram is cleared and is ready for
  3239. * future writes.
  3240. **/
  3241. static s32 e1000_update_nvm_checksum_spt(struct e1000_hw *hw)
  3242. {
  3243. struct e1000_nvm_info *nvm = &hw->nvm;
  3244. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  3245. u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
  3246. s32 ret_val;
  3247. u32 dword = 0;
  3248. ret_val = e1000e_update_nvm_checksum_generic(hw);
  3249. if (ret_val)
  3250. goto out;
  3251. if (nvm->type != e1000_nvm_flash_sw)
  3252. goto out;
  3253. nvm->ops.acquire(hw);
  3254. /* We're writing to the opposite bank so if we're on bank 1,
  3255. * write to bank 0 etc. We also need to erase the segment that
  3256. * is going to be written
  3257. */
  3258. ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
  3259. if (ret_val) {
  3260. e_dbg("Could not detect valid bank, assuming bank 0\n");
  3261. bank = 0;
  3262. }
  3263. if (bank == 0) {
  3264. new_bank_offset = nvm->flash_bank_size;
  3265. old_bank_offset = 0;
  3266. ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
  3267. if (ret_val)
  3268. goto release;
  3269. } else {
  3270. old_bank_offset = nvm->flash_bank_size;
  3271. new_bank_offset = 0;
  3272. ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
  3273. if (ret_val)
  3274. goto release;
  3275. }
  3276. for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i += 2) {
  3277. /* Determine whether to write the value stored
  3278. * in the other NVM bank or a modified value stored
  3279. * in the shadow RAM
  3280. */
  3281. ret_val = e1000_read_flash_dword_ich8lan(hw,
  3282. i + old_bank_offset,
  3283. &dword);
  3284. if (dev_spec->shadow_ram[i].modified) {
  3285. dword &= 0xffff0000;
  3286. dword |= (dev_spec->shadow_ram[i].value & 0xffff);
  3287. }
  3288. if (dev_spec->shadow_ram[i + 1].modified) {
  3289. dword &= 0x0000ffff;
  3290. dword |= ((dev_spec->shadow_ram[i + 1].value & 0xffff)
  3291. << 16);
  3292. }
  3293. if (ret_val)
  3294. break;
  3295. /* If the word is 0x13, then make sure the signature bits
  3296. * (15:14) are 11b until the commit has completed.
  3297. * This will allow us to write 10b which indicates the
  3298. * signature is valid. We want to do this after the write
  3299. * has completed so that we don't mark the segment valid
  3300. * while the write is still in progress
  3301. */
  3302. if (i == E1000_ICH_NVM_SIG_WORD - 1)
  3303. dword |= E1000_ICH_NVM_SIG_MASK << 16;
  3304. /* Convert offset to bytes. */
  3305. act_offset = (i + new_bank_offset) << 1;
  3306. usleep_range(100, 200);
  3307. /* Write the data to the new bank. Offset in words */
  3308. act_offset = i + new_bank_offset;
  3309. ret_val = e1000_retry_write_flash_dword_ich8lan(hw, act_offset,
  3310. dword);
  3311. if (ret_val)
  3312. break;
  3313. }
  3314. /* Don't bother writing the segment valid bits if sector
  3315. * programming failed.
  3316. */
  3317. if (ret_val) {
  3318. /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
  3319. e_dbg("Flash commit failed.\n");
  3320. goto release;
  3321. }
  3322. /* Finally validate the new segment by setting bit 15:14
  3323. * to 10b in word 0x13 , this can be done without an
  3324. * erase as well since these bits are 11 to start with
  3325. * and we need to change bit 14 to 0b
  3326. */
  3327. act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
  3328. /*offset in words but we read dword */
  3329. --act_offset;
  3330. ret_val = e1000_read_flash_dword_ich8lan(hw, act_offset, &dword);
  3331. if (ret_val)
  3332. goto release;
  3333. dword &= 0xBFFFFFFF;
  3334. ret_val = e1000_retry_write_flash_dword_ich8lan(hw, act_offset, dword);
  3335. if (ret_val)
  3336. goto release;
  3337. /* And invalidate the previously valid segment by setting
  3338. * its signature word (0x13) high_byte to 0b. This can be
  3339. * done without an erase because flash erase sets all bits
  3340. * to 1's. We can write 1's to 0's without an erase
  3341. */
  3342. act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
  3343. /* offset in words but we read dword */
  3344. act_offset = old_bank_offset + E1000_ICH_NVM_SIG_WORD - 1;
  3345. ret_val = e1000_read_flash_dword_ich8lan(hw, act_offset, &dword);
  3346. if (ret_val)
  3347. goto release;
  3348. dword &= 0x00FFFFFF;
  3349. ret_val = e1000_retry_write_flash_dword_ich8lan(hw, act_offset, dword);
  3350. if (ret_val)
  3351. goto release;
  3352. /* Great! Everything worked, we can now clear the cached entries. */
  3353. for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
  3354. dev_spec->shadow_ram[i].modified = false;
  3355. dev_spec->shadow_ram[i].value = 0xFFFF;
  3356. }
  3357. release:
  3358. nvm->ops.release(hw);
  3359. /* Reload the EEPROM, or else modifications will not appear
  3360. * until after the next adapter reset.
  3361. */
  3362. if (!ret_val) {
  3363. nvm->ops.reload(hw);
  3364. usleep_range(10000, 11000);
  3365. }
  3366. out:
  3367. if (ret_val)
  3368. e_dbg("NVM update error: %d\n", ret_val);
  3369. return ret_val;
  3370. }
  3371. /**
  3372. * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
  3373. * @hw: pointer to the HW structure
  3374. *
  3375. * The NVM checksum is updated by calling the generic update_nvm_checksum,
  3376. * which writes the checksum to the shadow ram. The changes in the shadow
  3377. * ram are then committed to the EEPROM by processing each bank at a time
  3378. * checking for the modified bit and writing only the pending changes.
  3379. * After a successful commit, the shadow ram is cleared and is ready for
  3380. * future writes.
  3381. **/
  3382. static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
  3383. {
  3384. struct e1000_nvm_info *nvm = &hw->nvm;
  3385. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  3386. u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
  3387. s32 ret_val;
  3388. u16 data = 0;
  3389. ret_val = e1000e_update_nvm_checksum_generic(hw);
  3390. if (ret_val)
  3391. goto out;
  3392. if (nvm->type != e1000_nvm_flash_sw)
  3393. goto out;
  3394. nvm->ops.acquire(hw);
  3395. /* We're writing to the opposite bank so if we're on bank 1,
  3396. * write to bank 0 etc. We also need to erase the segment that
  3397. * is going to be written
  3398. */
  3399. ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
  3400. if (ret_val) {
  3401. e_dbg("Could not detect valid bank, assuming bank 0\n");
  3402. bank = 0;
  3403. }
  3404. if (bank == 0) {
  3405. new_bank_offset = nvm->flash_bank_size;
  3406. old_bank_offset = 0;
  3407. ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
  3408. if (ret_val)
  3409. goto release;
  3410. } else {
  3411. old_bank_offset = nvm->flash_bank_size;
  3412. new_bank_offset = 0;
  3413. ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
  3414. if (ret_val)
  3415. goto release;
  3416. }
  3417. for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
  3418. if (dev_spec->shadow_ram[i].modified) {
  3419. data = dev_spec->shadow_ram[i].value;
  3420. } else {
  3421. ret_val = e1000_read_flash_word_ich8lan(hw, i +
  3422. old_bank_offset,
  3423. &data);
  3424. if (ret_val)
  3425. break;
  3426. }
  3427. /* If the word is 0x13, then make sure the signature bits
  3428. * (15:14) are 11b until the commit has completed.
  3429. * This will allow us to write 10b which indicates the
  3430. * signature is valid. We want to do this after the write
  3431. * has completed so that we don't mark the segment valid
  3432. * while the write is still in progress
  3433. */
  3434. if (i == E1000_ICH_NVM_SIG_WORD)
  3435. data |= E1000_ICH_NVM_SIG_MASK;
  3436. /* Convert offset to bytes. */
  3437. act_offset = (i + new_bank_offset) << 1;
  3438. usleep_range(100, 200);
  3439. /* Write the bytes to the new bank. */
  3440. ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
  3441. act_offset,
  3442. (u8)data);
  3443. if (ret_val)
  3444. break;
  3445. usleep_range(100, 200);
  3446. ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
  3447. act_offset + 1,
  3448. (u8)(data >> 8));
  3449. if (ret_val)
  3450. break;
  3451. }
  3452. /* Don't bother writing the segment valid bits if sector
  3453. * programming failed.
  3454. */
  3455. if (ret_val) {
  3456. /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
  3457. e_dbg("Flash commit failed.\n");
  3458. goto release;
  3459. }
  3460. /* Finally validate the new segment by setting bit 15:14
  3461. * to 10b in word 0x13 , this can be done without an
  3462. * erase as well since these bits are 11 to start with
  3463. * and we need to change bit 14 to 0b
  3464. */
  3465. act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
  3466. ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
  3467. if (ret_val)
  3468. goto release;
  3469. data &= 0xBFFF;
  3470. ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
  3471. act_offset * 2 + 1,
  3472. (u8)(data >> 8));
  3473. if (ret_val)
  3474. goto release;
  3475. /* And invalidate the previously valid segment by setting
  3476. * its signature word (0x13) high_byte to 0b. This can be
  3477. * done without an erase because flash erase sets all bits
  3478. * to 1's. We can write 1's to 0's without an erase
  3479. */
  3480. act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
  3481. ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
  3482. if (ret_val)
  3483. goto release;
  3484. /* Great! Everything worked, we can now clear the cached entries. */
  3485. for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
  3486. dev_spec->shadow_ram[i].modified = false;
  3487. dev_spec->shadow_ram[i].value = 0xFFFF;
  3488. }
  3489. release:
  3490. nvm->ops.release(hw);
  3491. /* Reload the EEPROM, or else modifications will not appear
  3492. * until after the next adapter reset.
  3493. */
  3494. if (!ret_val) {
  3495. nvm->ops.reload(hw);
  3496. usleep_range(10000, 11000);
  3497. }
  3498. out:
  3499. if (ret_val)
  3500. e_dbg("NVM update error: %d\n", ret_val);
  3501. return ret_val;
  3502. }
  3503. /**
  3504. * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
  3505. * @hw: pointer to the HW structure
  3506. *
  3507. * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
  3508. * If the bit is 0, that the EEPROM had been modified, but the checksum was not
  3509. * calculated, in which case we need to calculate the checksum and set bit 6.
  3510. **/
  3511. static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
  3512. {
  3513. s32 ret_val;
  3514. u16 data;
  3515. u16 word;
  3516. u16 valid_csum_mask;
  3517. /* Read NVM and check Invalid Image CSUM bit. If this bit is 0,
  3518. * the checksum needs to be fixed. This bit is an indication that
  3519. * the NVM was prepared by OEM software and did not calculate
  3520. * the checksum...a likely scenario.
  3521. */
  3522. switch (hw->mac.type) {
  3523. case e1000_pch_lpt:
  3524. case e1000_pch_spt:
  3525. case e1000_pch_cnp:
  3526. case e1000_pch_tgp:
  3527. case e1000_pch_adp:
  3528. word = NVM_COMPAT;
  3529. valid_csum_mask = NVM_COMPAT_VALID_CSUM;
  3530. break;
  3531. default:
  3532. word = NVM_FUTURE_INIT_WORD1;
  3533. valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
  3534. break;
  3535. }
  3536. ret_val = e1000_read_nvm(hw, word, 1, &data);
  3537. if (ret_val)
  3538. return ret_val;
  3539. if (!(data & valid_csum_mask)) {
  3540. data |= valid_csum_mask;
  3541. ret_val = e1000_write_nvm(hw, word, 1, &data);
  3542. if (ret_val)
  3543. return ret_val;
  3544. ret_val = e1000e_update_nvm_checksum(hw);
  3545. if (ret_val)
  3546. return ret_val;
  3547. }
  3548. return e1000e_validate_nvm_checksum_generic(hw);
  3549. }
  3550. /**
  3551. * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
  3552. * @hw: pointer to the HW structure
  3553. *
  3554. * To prevent malicious write/erase of the NVM, set it to be read-only
  3555. * so that the hardware ignores all write/erase cycles of the NVM via
  3556. * the flash control registers. The shadow-ram copy of the NVM will
  3557. * still be updated, however any updates to this copy will not stick
  3558. * across driver reloads.
  3559. **/
  3560. void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
  3561. {
  3562. struct e1000_nvm_info *nvm = &hw->nvm;
  3563. union ich8_flash_protected_range pr0;
  3564. union ich8_hws_flash_status hsfsts;
  3565. u32 gfpreg;
  3566. nvm->ops.acquire(hw);
  3567. gfpreg = er32flash(ICH_FLASH_GFPREG);
  3568. /* Write-protect GbE Sector of NVM */
  3569. pr0.regval = er32flash(ICH_FLASH_PR0);
  3570. pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
  3571. pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
  3572. pr0.range.wpe = true;
  3573. ew32flash(ICH_FLASH_PR0, pr0.regval);
  3574. /* Lock down a subset of GbE Flash Control Registers, e.g.
  3575. * PR0 to prevent the write-protection from being lifted.
  3576. * Once FLOCKDN is set, the registers protected by it cannot
  3577. * be written until FLOCKDN is cleared by a hardware reset.
  3578. */
  3579. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3580. hsfsts.hsf_status.flockdn = true;
  3581. ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  3582. nvm->ops.release(hw);
  3583. }
  3584. /**
  3585. * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
  3586. * @hw: pointer to the HW structure
  3587. * @offset: The offset (in bytes) of the byte/word to read.
  3588. * @size: Size of data to read, 1=byte 2=word
  3589. * @data: The byte(s) to write to the NVM.
  3590. *
  3591. * Writes one/two bytes to the NVM using the flash access registers.
  3592. **/
  3593. static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
  3594. u8 size, u16 data)
  3595. {
  3596. union ich8_hws_flash_status hsfsts;
  3597. union ich8_hws_flash_ctrl hsflctl;
  3598. u32 flash_linear_addr;
  3599. u32 flash_data = 0;
  3600. s32 ret_val;
  3601. u8 count = 0;
  3602. if (hw->mac.type >= e1000_pch_spt) {
  3603. if (size != 4 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
  3604. return -E1000_ERR_NVM;
  3605. } else {
  3606. if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
  3607. return -E1000_ERR_NVM;
  3608. }
  3609. flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
  3610. hw->nvm.flash_base_addr);
  3611. do {
  3612. udelay(1);
  3613. /* Steps */
  3614. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  3615. if (ret_val)
  3616. break;
  3617. /* In SPT, This register is in Lan memory space, not
  3618. * flash. Therefore, only 32 bit access is supported
  3619. */
  3620. if (hw->mac.type >= e1000_pch_spt)
  3621. hsflctl.regval = er32flash(ICH_FLASH_HSFSTS) >> 16;
  3622. else
  3623. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  3624. /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
  3625. hsflctl.hsf_ctrl.fldbcount = size - 1;
  3626. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
  3627. /* In SPT, This register is in Lan memory space,
  3628. * not flash. Therefore, only 32 bit access is
  3629. * supported
  3630. */
  3631. if (hw->mac.type >= e1000_pch_spt)
  3632. ew32flash(ICH_FLASH_HSFSTS, hsflctl.regval << 16);
  3633. else
  3634. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  3635. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  3636. if (size == 1)
  3637. flash_data = (u32)data & 0x00FF;
  3638. else
  3639. flash_data = (u32)data;
  3640. ew32flash(ICH_FLASH_FDATA0, flash_data);
  3641. /* check if FCERR is set to 1 , if set to 1, clear it
  3642. * and try the whole sequence a few more times else done
  3643. */
  3644. ret_val =
  3645. e1000_flash_cycle_ich8lan(hw,
  3646. ICH_FLASH_WRITE_COMMAND_TIMEOUT);
  3647. if (!ret_val)
  3648. break;
  3649. /* If we're here, then things are most likely
  3650. * completely hosed, but if the error condition
  3651. * is detected, it won't hurt to give it another
  3652. * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
  3653. */
  3654. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3655. if (hsfsts.hsf_status.flcerr)
  3656. /* Repeat for some time before giving up. */
  3657. continue;
  3658. if (!hsfsts.hsf_status.flcdone) {
  3659. e_dbg("Timeout error - flash cycle did not complete.\n");
  3660. break;
  3661. }
  3662. } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
  3663. return ret_val;
  3664. }
  3665. /**
  3666. * e1000_write_flash_data32_ich8lan - Writes 4 bytes to the NVM
  3667. * @hw: pointer to the HW structure
  3668. * @offset: The offset (in bytes) of the dwords to read.
  3669. * @data: The 4 bytes to write to the NVM.
  3670. *
  3671. * Writes one/two/four bytes to the NVM using the flash access registers.
  3672. **/
  3673. static s32 e1000_write_flash_data32_ich8lan(struct e1000_hw *hw, u32 offset,
  3674. u32 data)
  3675. {
  3676. union ich8_hws_flash_status hsfsts;
  3677. union ich8_hws_flash_ctrl hsflctl;
  3678. u32 flash_linear_addr;
  3679. s32 ret_val;
  3680. u8 count = 0;
  3681. if (hw->mac.type >= e1000_pch_spt) {
  3682. if (offset > ICH_FLASH_LINEAR_ADDR_MASK)
  3683. return -E1000_ERR_NVM;
  3684. }
  3685. flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
  3686. hw->nvm.flash_base_addr);
  3687. do {
  3688. udelay(1);
  3689. /* Steps */
  3690. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  3691. if (ret_val)
  3692. break;
  3693. /* In SPT, This register is in Lan memory space, not
  3694. * flash. Therefore, only 32 bit access is supported
  3695. */
  3696. if (hw->mac.type >= e1000_pch_spt)
  3697. hsflctl.regval = er32flash(ICH_FLASH_HSFSTS)
  3698. >> 16;
  3699. else
  3700. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  3701. hsflctl.hsf_ctrl.fldbcount = sizeof(u32) - 1;
  3702. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
  3703. /* In SPT, This register is in Lan memory space,
  3704. * not flash. Therefore, only 32 bit access is
  3705. * supported
  3706. */
  3707. if (hw->mac.type >= e1000_pch_spt)
  3708. ew32flash(ICH_FLASH_HSFSTS, hsflctl.regval << 16);
  3709. else
  3710. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  3711. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  3712. ew32flash(ICH_FLASH_FDATA0, data);
  3713. /* check if FCERR is set to 1 , if set to 1, clear it
  3714. * and try the whole sequence a few more times else done
  3715. */
  3716. ret_val =
  3717. e1000_flash_cycle_ich8lan(hw,
  3718. ICH_FLASH_WRITE_COMMAND_TIMEOUT);
  3719. if (!ret_val)
  3720. break;
  3721. /* If we're here, then things are most likely
  3722. * completely hosed, but if the error condition
  3723. * is detected, it won't hurt to give it another
  3724. * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
  3725. */
  3726. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3727. if (hsfsts.hsf_status.flcerr)
  3728. /* Repeat for some time before giving up. */
  3729. continue;
  3730. if (!hsfsts.hsf_status.flcdone) {
  3731. e_dbg("Timeout error - flash cycle did not complete.\n");
  3732. break;
  3733. }
  3734. } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
  3735. return ret_val;
  3736. }
  3737. /**
  3738. * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
  3739. * @hw: pointer to the HW structure
  3740. * @offset: The index of the byte to read.
  3741. * @data: The byte to write to the NVM.
  3742. *
  3743. * Writes a single byte to the NVM using the flash access registers.
  3744. **/
  3745. static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
  3746. u8 data)
  3747. {
  3748. u16 word = (u16)data;
  3749. return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
  3750. }
  3751. /**
  3752. * e1000_retry_write_flash_dword_ich8lan - Writes a dword to NVM
  3753. * @hw: pointer to the HW structure
  3754. * @offset: The offset of the word to write.
  3755. * @dword: The dword to write to the NVM.
  3756. *
  3757. * Writes a single dword to the NVM using the flash access registers.
  3758. * Goes through a retry algorithm before giving up.
  3759. **/
  3760. static s32 e1000_retry_write_flash_dword_ich8lan(struct e1000_hw *hw,
  3761. u32 offset, u32 dword)
  3762. {
  3763. s32 ret_val;
  3764. u16 program_retries;
  3765. /* Must convert word offset into bytes. */
  3766. offset <<= 1;
  3767. ret_val = e1000_write_flash_data32_ich8lan(hw, offset, dword);
  3768. if (!ret_val)
  3769. return ret_val;
  3770. for (program_retries = 0; program_retries < 100; program_retries++) {
  3771. e_dbg("Retrying Byte %8.8X at offset %u\n", dword, offset);
  3772. usleep_range(100, 200);
  3773. ret_val = e1000_write_flash_data32_ich8lan(hw, offset, dword);
  3774. if (!ret_val)
  3775. break;
  3776. }
  3777. if (program_retries == 100)
  3778. return -E1000_ERR_NVM;
  3779. return 0;
  3780. }
  3781. /**
  3782. * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
  3783. * @hw: pointer to the HW structure
  3784. * @offset: The offset of the byte to write.
  3785. * @byte: The byte to write to the NVM.
  3786. *
  3787. * Writes a single byte to the NVM using the flash access registers.
  3788. * Goes through a retry algorithm before giving up.
  3789. **/
  3790. static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
  3791. u32 offset, u8 byte)
  3792. {
  3793. s32 ret_val;
  3794. u16 program_retries;
  3795. ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
  3796. if (!ret_val)
  3797. return ret_val;
  3798. for (program_retries = 0; program_retries < 100; program_retries++) {
  3799. e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
  3800. usleep_range(100, 200);
  3801. ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
  3802. if (!ret_val)
  3803. break;
  3804. }
  3805. if (program_retries == 100)
  3806. return -E1000_ERR_NVM;
  3807. return 0;
  3808. }
  3809. /**
  3810. * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
  3811. * @hw: pointer to the HW structure
  3812. * @bank: 0 for first bank, 1 for second bank, etc.
  3813. *
  3814. * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
  3815. * bank N is 4096 * N + flash_reg_addr.
  3816. **/
  3817. static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
  3818. {
  3819. struct e1000_nvm_info *nvm = &hw->nvm;
  3820. union ich8_hws_flash_status hsfsts;
  3821. union ich8_hws_flash_ctrl hsflctl;
  3822. u32 flash_linear_addr;
  3823. /* bank size is in 16bit words - adjust to bytes */
  3824. u32 flash_bank_size = nvm->flash_bank_size * 2;
  3825. s32 ret_val;
  3826. s32 count = 0;
  3827. s32 j, iteration, sector_size;
  3828. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3829. /* Determine HW Sector size: Read BERASE bits of hw flash status
  3830. * register
  3831. * 00: The Hw sector is 256 bytes, hence we need to erase 16
  3832. * consecutive sectors. The start index for the nth Hw sector
  3833. * can be calculated as = bank * 4096 + n * 256
  3834. * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
  3835. * The start index for the nth Hw sector can be calculated
  3836. * as = bank * 4096
  3837. * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
  3838. * (ich9 only, otherwise error condition)
  3839. * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
  3840. */
  3841. switch (hsfsts.hsf_status.berasesz) {
  3842. case 0:
  3843. /* Hw sector size 256 */
  3844. sector_size = ICH_FLASH_SEG_SIZE_256;
  3845. iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
  3846. break;
  3847. case 1:
  3848. sector_size = ICH_FLASH_SEG_SIZE_4K;
  3849. iteration = 1;
  3850. break;
  3851. case 2:
  3852. sector_size = ICH_FLASH_SEG_SIZE_8K;
  3853. iteration = 1;
  3854. break;
  3855. case 3:
  3856. sector_size = ICH_FLASH_SEG_SIZE_64K;
  3857. iteration = 1;
  3858. break;
  3859. default:
  3860. return -E1000_ERR_NVM;
  3861. }
  3862. /* Start with the base address, then add the sector offset. */
  3863. flash_linear_addr = hw->nvm.flash_base_addr;
  3864. flash_linear_addr += (bank) ? flash_bank_size : 0;
  3865. for (j = 0; j < iteration; j++) {
  3866. do {
  3867. u32 timeout = ICH_FLASH_ERASE_COMMAND_TIMEOUT;
  3868. /* Steps */
  3869. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  3870. if (ret_val)
  3871. return ret_val;
  3872. /* Write a value 11 (block Erase) in Flash
  3873. * Cycle field in hw flash control
  3874. */
  3875. if (hw->mac.type >= e1000_pch_spt)
  3876. hsflctl.regval =
  3877. er32flash(ICH_FLASH_HSFSTS) >> 16;
  3878. else
  3879. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  3880. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
  3881. if (hw->mac.type >= e1000_pch_spt)
  3882. ew32flash(ICH_FLASH_HSFSTS,
  3883. hsflctl.regval << 16);
  3884. else
  3885. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  3886. /* Write the last 24 bits of an index within the
  3887. * block into Flash Linear address field in Flash
  3888. * Address.
  3889. */
  3890. flash_linear_addr += (j * sector_size);
  3891. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  3892. ret_val = e1000_flash_cycle_ich8lan(hw, timeout);
  3893. if (!ret_val)
  3894. break;
  3895. /* Check if FCERR is set to 1. If 1,
  3896. * clear it and try the whole sequence
  3897. * a few more times else Done
  3898. */
  3899. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3900. if (hsfsts.hsf_status.flcerr)
  3901. /* repeat for some time before giving up */
  3902. continue;
  3903. else if (!hsfsts.hsf_status.flcdone)
  3904. return ret_val;
  3905. } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
  3906. }
  3907. return 0;
  3908. }
  3909. /**
  3910. * e1000_valid_led_default_ich8lan - Set the default LED settings
  3911. * @hw: pointer to the HW structure
  3912. * @data: Pointer to the LED settings
  3913. *
  3914. * Reads the LED default settings from the NVM to data. If the NVM LED
  3915. * settings is all 0's or F's, set the LED default to a valid LED default
  3916. * setting.
  3917. **/
  3918. static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
  3919. {
  3920. s32 ret_val;
  3921. ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
  3922. if (ret_val) {
  3923. e_dbg("NVM Read Error\n");
  3924. return ret_val;
  3925. }
  3926. if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
  3927. *data = ID_LED_DEFAULT_ICH8LAN;
  3928. return 0;
  3929. }
  3930. /**
  3931. * e1000_id_led_init_pchlan - store LED configurations
  3932. * @hw: pointer to the HW structure
  3933. *
  3934. * PCH does not control LEDs via the LEDCTL register, rather it uses
  3935. * the PHY LED configuration register.
  3936. *
  3937. * PCH also does not have an "always on" or "always off" mode which
  3938. * complicates the ID feature. Instead of using the "on" mode to indicate
  3939. * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
  3940. * use "link_up" mode. The LEDs will still ID on request if there is no
  3941. * link based on logic in e1000_led_[on|off]_pchlan().
  3942. **/
  3943. static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
  3944. {
  3945. struct e1000_mac_info *mac = &hw->mac;
  3946. s32 ret_val;
  3947. const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
  3948. const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
  3949. u16 data, i, temp, shift;
  3950. /* Get default ID LED modes */
  3951. ret_val = hw->nvm.ops.valid_led_default(hw, &data);
  3952. if (ret_val)
  3953. return ret_val;
  3954. mac->ledctl_default = er32(LEDCTL);
  3955. mac->ledctl_mode1 = mac->ledctl_default;
  3956. mac->ledctl_mode2 = mac->ledctl_default;
  3957. for (i = 0; i < 4; i++) {
  3958. temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
  3959. shift = (i * 5);
  3960. switch (temp) {
  3961. case ID_LED_ON1_DEF2:
  3962. case ID_LED_ON1_ON2:
  3963. case ID_LED_ON1_OFF2:
  3964. mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
  3965. mac->ledctl_mode1 |= (ledctl_on << shift);
  3966. break;
  3967. case ID_LED_OFF1_DEF2:
  3968. case ID_LED_OFF1_ON2:
  3969. case ID_LED_OFF1_OFF2:
  3970. mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
  3971. mac->ledctl_mode1 |= (ledctl_off << shift);
  3972. break;
  3973. default:
  3974. /* Do nothing */
  3975. break;
  3976. }
  3977. switch (temp) {
  3978. case ID_LED_DEF1_ON2:
  3979. case ID_LED_ON1_ON2:
  3980. case ID_LED_OFF1_ON2:
  3981. mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
  3982. mac->ledctl_mode2 |= (ledctl_on << shift);
  3983. break;
  3984. case ID_LED_DEF1_OFF2:
  3985. case ID_LED_ON1_OFF2:
  3986. case ID_LED_OFF1_OFF2:
  3987. mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
  3988. mac->ledctl_mode2 |= (ledctl_off << shift);
  3989. break;
  3990. default:
  3991. /* Do nothing */
  3992. break;
  3993. }
  3994. }
  3995. return 0;
  3996. }
  3997. /**
  3998. * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
  3999. * @hw: pointer to the HW structure
  4000. *
  4001. * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
  4002. * register, so the the bus width is hard coded.
  4003. **/
  4004. static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
  4005. {
  4006. struct e1000_bus_info *bus = &hw->bus;
  4007. s32 ret_val;
  4008. ret_val = e1000e_get_bus_info_pcie(hw);
  4009. /* ICH devices are "PCI Express"-ish. They have
  4010. * a configuration space, but do not contain
  4011. * PCI Express Capability registers, so bus width
  4012. * must be hardcoded.
  4013. */
  4014. if (bus->width == e1000_bus_width_unknown)
  4015. bus->width = e1000_bus_width_pcie_x1;
  4016. return ret_val;
  4017. }
  4018. /**
  4019. * e1000_reset_hw_ich8lan - Reset the hardware
  4020. * @hw: pointer to the HW structure
  4021. *
  4022. * Does a full reset of the hardware which includes a reset of the PHY and
  4023. * MAC.
  4024. **/
  4025. static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
  4026. {
  4027. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  4028. u16 kum_cfg;
  4029. u32 ctrl, reg;
  4030. s32 ret_val;
  4031. /* Prevent the PCI-E bus from sticking if there is no TLP connection
  4032. * on the last TLP read/write transaction when MAC is reset.
  4033. */
  4034. ret_val = e1000e_disable_pcie_master(hw);
  4035. if (ret_val)
  4036. e_dbg("PCI-E Master disable polling has failed.\n");
  4037. e_dbg("Masking off all interrupts\n");
  4038. ew32(IMC, 0xffffffff);
  4039. /* Disable the Transmit and Receive units. Then delay to allow
  4040. * any pending transactions to complete before we hit the MAC
  4041. * with the global reset.
  4042. */
  4043. ew32(RCTL, 0);
  4044. ew32(TCTL, E1000_TCTL_PSP);
  4045. e1e_flush();
  4046. usleep_range(10000, 11000);
  4047. /* Workaround for ICH8 bit corruption issue in FIFO memory */
  4048. if (hw->mac.type == e1000_ich8lan) {
  4049. /* Set Tx and Rx buffer allocation to 8k apiece. */
  4050. ew32(PBA, E1000_PBA_8K);
  4051. /* Set Packet Buffer Size to 16k. */
  4052. ew32(PBS, E1000_PBS_16K);
  4053. }
  4054. if (hw->mac.type == e1000_pchlan) {
  4055. /* Save the NVM K1 bit setting */
  4056. ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
  4057. if (ret_val)
  4058. return ret_val;
  4059. if (kum_cfg & E1000_NVM_K1_ENABLE)
  4060. dev_spec->nvm_k1_enabled = true;
  4061. else
  4062. dev_spec->nvm_k1_enabled = false;
  4063. }
  4064. ctrl = er32(CTRL);
  4065. if (!hw->phy.ops.check_reset_block(hw)) {
  4066. /* Full-chip reset requires MAC and PHY reset at the same
  4067. * time to make sure the interface between MAC and the
  4068. * external PHY is reset.
  4069. */
  4070. ctrl |= E1000_CTRL_PHY_RST;
  4071. /* Gate automatic PHY configuration by hardware on
  4072. * non-managed 82579
  4073. */
  4074. if ((hw->mac.type == e1000_pch2lan) &&
  4075. !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
  4076. e1000_gate_hw_phy_config_ich8lan(hw, true);
  4077. }
  4078. ret_val = e1000_acquire_swflag_ich8lan(hw);
  4079. e_dbg("Issuing a global reset to ich8lan\n");
  4080. ew32(CTRL, (ctrl | E1000_CTRL_RST));
  4081. /* cannot issue a flush here because it hangs the hardware */
  4082. msleep(20);
  4083. /* Set Phy Config Counter to 50msec */
  4084. if (hw->mac.type == e1000_pch2lan) {
  4085. reg = er32(FEXTNVM3);
  4086. reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
  4087. reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
  4088. ew32(FEXTNVM3, reg);
  4089. }
  4090. if (!ret_val)
  4091. clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
  4092. if (ctrl & E1000_CTRL_PHY_RST) {
  4093. ret_val = hw->phy.ops.get_cfg_done(hw);
  4094. if (ret_val)
  4095. return ret_val;
  4096. ret_val = e1000_post_phy_reset_ich8lan(hw);
  4097. if (ret_val)
  4098. return ret_val;
  4099. }
  4100. /* For PCH, this write will make sure that any noise
  4101. * will be detected as a CRC error and be dropped rather than show up
  4102. * as a bad packet to the DMA engine.
  4103. */
  4104. if (hw->mac.type == e1000_pchlan)
  4105. ew32(CRC_OFFSET, 0x65656565);
  4106. ew32(IMC, 0xffffffff);
  4107. er32(ICR);
  4108. reg = er32(KABGTXD);
  4109. reg |= E1000_KABGTXD_BGSQLBIAS;
  4110. ew32(KABGTXD, reg);
  4111. return 0;
  4112. }
  4113. /**
  4114. * e1000_init_hw_ich8lan - Initialize the hardware
  4115. * @hw: pointer to the HW structure
  4116. *
  4117. * Prepares the hardware for transmit and receive by doing the following:
  4118. * - initialize hardware bits
  4119. * - initialize LED identification
  4120. * - setup receive address registers
  4121. * - setup flow control
  4122. * - setup transmit descriptors
  4123. * - clear statistics
  4124. **/
  4125. static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
  4126. {
  4127. struct e1000_mac_info *mac = &hw->mac;
  4128. u32 ctrl_ext, txdctl, snoop;
  4129. s32 ret_val;
  4130. u16 i;
  4131. e1000_initialize_hw_bits_ich8lan(hw);
  4132. /* Initialize identification LED */
  4133. ret_val = mac->ops.id_led_init(hw);
  4134. /* An error is not fatal and we should not stop init due to this */
  4135. if (ret_val)
  4136. e_dbg("Error initializing identification LED\n");
  4137. /* Setup the receive address. */
  4138. e1000e_init_rx_addrs(hw, mac->rar_entry_count);
  4139. /* Zero out the Multicast HASH table */
  4140. e_dbg("Zeroing the MTA\n");
  4141. for (i = 0; i < mac->mta_reg_count; i++)
  4142. E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
  4143. /* The 82578 Rx buffer will stall if wakeup is enabled in host and
  4144. * the ME. Disable wakeup by clearing the host wakeup bit.
  4145. * Reset the phy after disabling host wakeup to reset the Rx buffer.
  4146. */
  4147. if (hw->phy.type == e1000_phy_82578) {
  4148. e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
  4149. i &= ~BM_WUC_HOST_WU_BIT;
  4150. e1e_wphy(hw, BM_PORT_GEN_CFG, i);
  4151. ret_val = e1000_phy_hw_reset_ich8lan(hw);
  4152. if (ret_val)
  4153. return ret_val;
  4154. }
  4155. /* Setup link and flow control */
  4156. ret_val = mac->ops.setup_link(hw);
  4157. /* Set the transmit descriptor write-back policy for both queues */
  4158. txdctl = er32(TXDCTL(0));
  4159. txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
  4160. E1000_TXDCTL_FULL_TX_DESC_WB);
  4161. txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
  4162. E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
  4163. ew32(TXDCTL(0), txdctl);
  4164. txdctl = er32(TXDCTL(1));
  4165. txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
  4166. E1000_TXDCTL_FULL_TX_DESC_WB);
  4167. txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
  4168. E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
  4169. ew32(TXDCTL(1), txdctl);
  4170. /* ICH8 has opposite polarity of no_snoop bits.
  4171. * By default, we should use snoop behavior.
  4172. */
  4173. if (mac->type == e1000_ich8lan)
  4174. snoop = PCIE_ICH8_SNOOP_ALL;
  4175. else
  4176. snoop = (u32)~(PCIE_NO_SNOOP_ALL);
  4177. e1000e_set_pcie_no_snoop(hw, snoop);
  4178. ctrl_ext = er32(CTRL_EXT);
  4179. ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
  4180. ew32(CTRL_EXT, ctrl_ext);
  4181. /* Clear all of the statistics registers (clear on read). It is
  4182. * important that we do this after we have tried to establish link
  4183. * because the symbol error count will increment wildly if there
  4184. * is no link.
  4185. */
  4186. e1000_clear_hw_cntrs_ich8lan(hw);
  4187. return ret_val;
  4188. }
  4189. /**
  4190. * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
  4191. * @hw: pointer to the HW structure
  4192. *
  4193. * Sets/Clears required hardware bits necessary for correctly setting up the
  4194. * hardware for transmit and receive.
  4195. **/
  4196. static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
  4197. {
  4198. u32 reg;
  4199. /* Extended Device Control */
  4200. reg = er32(CTRL_EXT);
  4201. reg |= BIT(22);
  4202. /* Enable PHY low-power state when MAC is at D3 w/o WoL */
  4203. if (hw->mac.type >= e1000_pchlan)
  4204. reg |= E1000_CTRL_EXT_PHYPDEN;
  4205. ew32(CTRL_EXT, reg);
  4206. /* Transmit Descriptor Control 0 */
  4207. reg = er32(TXDCTL(0));
  4208. reg |= BIT(22);
  4209. ew32(TXDCTL(0), reg);
  4210. /* Transmit Descriptor Control 1 */
  4211. reg = er32(TXDCTL(1));
  4212. reg |= BIT(22);
  4213. ew32(TXDCTL(1), reg);
  4214. /* Transmit Arbitration Control 0 */
  4215. reg = er32(TARC(0));
  4216. if (hw->mac.type == e1000_ich8lan)
  4217. reg |= BIT(28) | BIT(29);
  4218. reg |= BIT(23) | BIT(24) | BIT(26) | BIT(27);
  4219. ew32(TARC(0), reg);
  4220. /* Transmit Arbitration Control 1 */
  4221. reg = er32(TARC(1));
  4222. if (er32(TCTL) & E1000_TCTL_MULR)
  4223. reg &= ~BIT(28);
  4224. else
  4225. reg |= BIT(28);
  4226. reg |= BIT(24) | BIT(26) | BIT(30);
  4227. ew32(TARC(1), reg);
  4228. /* Device Status */
  4229. if (hw->mac.type == e1000_ich8lan) {
  4230. reg = er32(STATUS);
  4231. reg &= ~BIT(31);
  4232. ew32(STATUS, reg);
  4233. }
  4234. /* work-around descriptor data corruption issue during nfs v2 udp
  4235. * traffic, just disable the nfs filtering capability
  4236. */
  4237. reg = er32(RFCTL);
  4238. reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
  4239. /* Disable IPv6 extension header parsing because some malformed
  4240. * IPv6 headers can hang the Rx.
  4241. */
  4242. if (hw->mac.type == e1000_ich8lan)
  4243. reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
  4244. ew32(RFCTL, reg);
  4245. /* Enable ECC on Lynxpoint */
  4246. if (hw->mac.type >= e1000_pch_lpt) {
  4247. reg = er32(PBECCSTS);
  4248. reg |= E1000_PBECCSTS_ECC_ENABLE;
  4249. ew32(PBECCSTS, reg);
  4250. reg = er32(CTRL);
  4251. reg |= E1000_CTRL_MEHE;
  4252. ew32(CTRL, reg);
  4253. }
  4254. }
  4255. /**
  4256. * e1000_setup_link_ich8lan - Setup flow control and link settings
  4257. * @hw: pointer to the HW structure
  4258. *
  4259. * Determines which flow control settings to use, then configures flow
  4260. * control. Calls the appropriate media-specific link configuration
  4261. * function. Assuming the adapter has a valid link partner, a valid link
  4262. * should be established. Assumes the hardware has previously been reset
  4263. * and the transmitter and receiver are not enabled.
  4264. **/
  4265. static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
  4266. {
  4267. s32 ret_val;
  4268. if (hw->phy.ops.check_reset_block(hw))
  4269. return 0;
  4270. /* ICH parts do not have a word in the NVM to determine
  4271. * the default flow control setting, so we explicitly
  4272. * set it to full.
  4273. */
  4274. if (hw->fc.requested_mode == e1000_fc_default) {
  4275. /* Workaround h/w hang when Tx flow control enabled */
  4276. if (hw->mac.type == e1000_pchlan)
  4277. hw->fc.requested_mode = e1000_fc_rx_pause;
  4278. else
  4279. hw->fc.requested_mode = e1000_fc_full;
  4280. }
  4281. /* Save off the requested flow control mode for use later. Depending
  4282. * on the link partner's capabilities, we may or may not use this mode.
  4283. */
  4284. hw->fc.current_mode = hw->fc.requested_mode;
  4285. e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
  4286. /* Continue to configure the copper link. */
  4287. ret_val = hw->mac.ops.setup_physical_interface(hw);
  4288. if (ret_val)
  4289. return ret_val;
  4290. ew32(FCTTV, hw->fc.pause_time);
  4291. if ((hw->phy.type == e1000_phy_82578) ||
  4292. (hw->phy.type == e1000_phy_82579) ||
  4293. (hw->phy.type == e1000_phy_i217) ||
  4294. (hw->phy.type == e1000_phy_82577)) {
  4295. ew32(FCRTV_PCH, hw->fc.refresh_time);
  4296. ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
  4297. hw->fc.pause_time);
  4298. if (ret_val)
  4299. return ret_val;
  4300. }
  4301. return e1000e_set_fc_watermarks(hw);
  4302. }
  4303. /**
  4304. * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
  4305. * @hw: pointer to the HW structure
  4306. *
  4307. * Configures the kumeran interface to the PHY to wait the appropriate time
  4308. * when polling the PHY, then call the generic setup_copper_link to finish
  4309. * configuring the copper link.
  4310. **/
  4311. static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
  4312. {
  4313. u32 ctrl;
  4314. s32 ret_val;
  4315. u16 reg_data;
  4316. ctrl = er32(CTRL);
  4317. ctrl |= E1000_CTRL_SLU;
  4318. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  4319. ew32(CTRL, ctrl);
  4320. /* Set the mac to wait the maximum time between each iteration
  4321. * and increase the max iterations when polling the phy;
  4322. * this fixes erroneous timeouts at 10Mbps.
  4323. */
  4324. ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
  4325. if (ret_val)
  4326. return ret_val;
  4327. ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
  4328. &reg_data);
  4329. if (ret_val)
  4330. return ret_val;
  4331. reg_data |= 0x3F;
  4332. ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
  4333. reg_data);
  4334. if (ret_val)
  4335. return ret_val;
  4336. switch (hw->phy.type) {
  4337. case e1000_phy_igp_3:
  4338. ret_val = e1000e_copper_link_setup_igp(hw);
  4339. if (ret_val)
  4340. return ret_val;
  4341. break;
  4342. case e1000_phy_bm:
  4343. case e1000_phy_82578:
  4344. ret_val = e1000e_copper_link_setup_m88(hw);
  4345. if (ret_val)
  4346. return ret_val;
  4347. break;
  4348. case e1000_phy_82577:
  4349. case e1000_phy_82579:
  4350. ret_val = e1000_copper_link_setup_82577(hw);
  4351. if (ret_val)
  4352. return ret_val;
  4353. break;
  4354. case e1000_phy_ife:
  4355. ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
  4356. if (ret_val)
  4357. return ret_val;
  4358. reg_data &= ~IFE_PMC_AUTO_MDIX;
  4359. switch (hw->phy.mdix) {
  4360. case 1:
  4361. reg_data &= ~IFE_PMC_FORCE_MDIX;
  4362. break;
  4363. case 2:
  4364. reg_data |= IFE_PMC_FORCE_MDIX;
  4365. break;
  4366. case 0:
  4367. default:
  4368. reg_data |= IFE_PMC_AUTO_MDIX;
  4369. break;
  4370. }
  4371. ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
  4372. if (ret_val)
  4373. return ret_val;
  4374. break;
  4375. default:
  4376. break;
  4377. }
  4378. return e1000e_setup_copper_link(hw);
  4379. }
  4380. /**
  4381. * e1000_setup_copper_link_pch_lpt - Configure MAC/PHY interface
  4382. * @hw: pointer to the HW structure
  4383. *
  4384. * Calls the PHY specific link setup function and then calls the
  4385. * generic setup_copper_link to finish configuring the link for
  4386. * Lynxpoint PCH devices
  4387. **/
  4388. static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw)
  4389. {
  4390. u32 ctrl;
  4391. s32 ret_val;
  4392. ctrl = er32(CTRL);
  4393. ctrl |= E1000_CTRL_SLU;
  4394. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  4395. ew32(CTRL, ctrl);
  4396. ret_val = e1000_copper_link_setup_82577(hw);
  4397. if (ret_val)
  4398. return ret_val;
  4399. return e1000e_setup_copper_link(hw);
  4400. }
  4401. /**
  4402. * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
  4403. * @hw: pointer to the HW structure
  4404. * @speed: pointer to store current link speed
  4405. * @duplex: pointer to store the current link duplex
  4406. *
  4407. * Calls the generic get_speed_and_duplex to retrieve the current link
  4408. * information and then calls the Kumeran lock loss workaround for links at
  4409. * gigabit speeds.
  4410. **/
  4411. static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
  4412. u16 *duplex)
  4413. {
  4414. s32 ret_val;
  4415. ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
  4416. if (ret_val)
  4417. return ret_val;
  4418. if ((hw->mac.type == e1000_ich8lan) &&
  4419. (hw->phy.type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
  4420. ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
  4421. }
  4422. return ret_val;
  4423. }
  4424. /**
  4425. * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
  4426. * @hw: pointer to the HW structure
  4427. *
  4428. * Work-around for 82566 Kumeran PCS lock loss:
  4429. * On link status change (i.e. PCI reset, speed change) and link is up and
  4430. * speed is gigabit-
  4431. * 0) if workaround is optionally disabled do nothing
  4432. * 1) wait 1ms for Kumeran link to come up
  4433. * 2) check Kumeran Diagnostic register PCS lock loss bit
  4434. * 3) if not set the link is locked (all is good), otherwise...
  4435. * 4) reset the PHY
  4436. * 5) repeat up to 10 times
  4437. * Note: this is only called for IGP3 copper when speed is 1gb.
  4438. **/
  4439. static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
  4440. {
  4441. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  4442. u32 phy_ctrl;
  4443. s32 ret_val;
  4444. u16 i, data;
  4445. bool link;
  4446. if (!dev_spec->kmrn_lock_loss_workaround_enabled)
  4447. return 0;
  4448. /* Make sure link is up before proceeding. If not just return.
  4449. * Attempting this while link is negotiating fouled up link
  4450. * stability
  4451. */
  4452. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  4453. if (!link)
  4454. return 0;
  4455. for (i = 0; i < 10; i++) {
  4456. /* read once to clear */
  4457. ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
  4458. if (ret_val)
  4459. return ret_val;
  4460. /* and again to get new status */
  4461. ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
  4462. if (ret_val)
  4463. return ret_val;
  4464. /* check for PCS lock */
  4465. if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
  4466. return 0;
  4467. /* Issue PHY reset */
  4468. e1000_phy_hw_reset(hw);
  4469. mdelay(5);
  4470. }
  4471. /* Disable GigE link negotiation */
  4472. phy_ctrl = er32(PHY_CTRL);
  4473. phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
  4474. E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
  4475. ew32(PHY_CTRL, phy_ctrl);
  4476. /* Call gig speed drop workaround on Gig disable before accessing
  4477. * any PHY registers
  4478. */
  4479. e1000e_gig_downshift_workaround_ich8lan(hw);
  4480. /* unable to acquire PCS lock */
  4481. return -E1000_ERR_PHY;
  4482. }
  4483. /**
  4484. * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
  4485. * @hw: pointer to the HW structure
  4486. * @state: boolean value used to set the current Kumeran workaround state
  4487. *
  4488. * If ICH8, set the current Kumeran workaround state (enabled - true
  4489. * /disabled - false).
  4490. **/
  4491. void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
  4492. bool state)
  4493. {
  4494. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  4495. if (hw->mac.type != e1000_ich8lan) {
  4496. e_dbg("Workaround applies to ICH8 only.\n");
  4497. return;
  4498. }
  4499. dev_spec->kmrn_lock_loss_workaround_enabled = state;
  4500. }
  4501. /**
  4502. * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
  4503. * @hw: pointer to the HW structure
  4504. *
  4505. * Workaround for 82566 power-down on D3 entry:
  4506. * 1) disable gigabit link
  4507. * 2) write VR power-down enable
  4508. * 3) read it back
  4509. * Continue if successful, else issue LCD reset and repeat
  4510. **/
  4511. void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
  4512. {
  4513. u32 reg;
  4514. u16 data;
  4515. u8 retry = 0;
  4516. if (hw->phy.type != e1000_phy_igp_3)
  4517. return;
  4518. /* Try the workaround twice (if needed) */
  4519. do {
  4520. /* Disable link */
  4521. reg = er32(PHY_CTRL);
  4522. reg |= (E1000_PHY_CTRL_GBE_DISABLE |
  4523. E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
  4524. ew32(PHY_CTRL, reg);
  4525. /* Call gig speed drop workaround on Gig disable before
  4526. * accessing any PHY registers
  4527. */
  4528. if (hw->mac.type == e1000_ich8lan)
  4529. e1000e_gig_downshift_workaround_ich8lan(hw);
  4530. /* Write VR power-down enable */
  4531. e1e_rphy(hw, IGP3_VR_CTRL, &data);
  4532. data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
  4533. e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
  4534. /* Read it back and test */
  4535. e1e_rphy(hw, IGP3_VR_CTRL, &data);
  4536. data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
  4537. if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
  4538. break;
  4539. /* Issue PHY reset and repeat at most one more time */
  4540. reg = er32(CTRL);
  4541. ew32(CTRL, reg | E1000_CTRL_PHY_RST);
  4542. retry++;
  4543. } while (retry);
  4544. }
  4545. /**
  4546. * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
  4547. * @hw: pointer to the HW structure
  4548. *
  4549. * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
  4550. * LPLU, Gig disable, MDIC PHY reset):
  4551. * 1) Set Kumeran Near-end loopback
  4552. * 2) Clear Kumeran Near-end loopback
  4553. * Should only be called for ICH8[m] devices with any 1G Phy.
  4554. **/
  4555. void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
  4556. {
  4557. s32 ret_val;
  4558. u16 reg_data;
  4559. if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
  4560. return;
  4561. ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
  4562. &reg_data);
  4563. if (ret_val)
  4564. return;
  4565. reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
  4566. ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
  4567. reg_data);
  4568. if (ret_val)
  4569. return;
  4570. reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
  4571. e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET, reg_data);
  4572. }
  4573. /**
  4574. * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
  4575. * @hw: pointer to the HW structure
  4576. *
  4577. * During S0 to Sx transition, it is possible the link remains at gig
  4578. * instead of negotiating to a lower speed. Before going to Sx, set
  4579. * 'Gig Disable' to force link speed negotiation to a lower speed based on
  4580. * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
  4581. * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
  4582. * needs to be written.
  4583. * Parts that support (and are linked to a partner which support) EEE in
  4584. * 100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
  4585. * than 10Mbps w/o EEE.
  4586. **/
  4587. void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
  4588. {
  4589. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  4590. u32 phy_ctrl;
  4591. s32 ret_val;
  4592. phy_ctrl = er32(PHY_CTRL);
  4593. phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
  4594. if (hw->phy.type == e1000_phy_i217) {
  4595. u16 phy_reg, device_id = hw->adapter->pdev->device;
  4596. if ((device_id == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
  4597. (device_id == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
  4598. (device_id == E1000_DEV_ID_PCH_I218_LM3) ||
  4599. (device_id == E1000_DEV_ID_PCH_I218_V3) ||
  4600. (hw->mac.type >= e1000_pch_spt)) {
  4601. u32 fextnvm6 = er32(FEXTNVM6);
  4602. ew32(FEXTNVM6, fextnvm6 & ~E1000_FEXTNVM6_REQ_PLL_CLK);
  4603. }
  4604. ret_val = hw->phy.ops.acquire(hw);
  4605. if (ret_val)
  4606. goto out;
  4607. if (!dev_spec->eee_disable) {
  4608. u16 eee_advert;
  4609. ret_val =
  4610. e1000_read_emi_reg_locked(hw,
  4611. I217_EEE_ADVERTISEMENT,
  4612. &eee_advert);
  4613. if (ret_val)
  4614. goto release;
  4615. /* Disable LPLU if both link partners support 100BaseT
  4616. * EEE and 100Full is advertised on both ends of the
  4617. * link, and enable Auto Enable LPI since there will
  4618. * be no driver to enable LPI while in Sx.
  4619. */
  4620. if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
  4621. (dev_spec->eee_lp_ability &
  4622. I82579_EEE_100_SUPPORTED) &&
  4623. (hw->phy.autoneg_advertised & ADVERTISE_100_FULL)) {
  4624. phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
  4625. E1000_PHY_CTRL_NOND0A_LPLU);
  4626. /* Set Auto Enable LPI after link up */
  4627. e1e_rphy_locked(hw,
  4628. I217_LPI_GPIO_CTRL, &phy_reg);
  4629. phy_reg |= I217_LPI_GPIO_CTRL_AUTO_EN_LPI;
  4630. e1e_wphy_locked(hw,
  4631. I217_LPI_GPIO_CTRL, phy_reg);
  4632. }
  4633. }
  4634. /* For i217 Intel Rapid Start Technology support,
  4635. * when the system is going into Sx and no manageability engine
  4636. * is present, the driver must configure proxy to reset only on
  4637. * power good. LPI (Low Power Idle) state must also reset only
  4638. * on power good, as well as the MTA (Multicast table array).
  4639. * The SMBus release must also be disabled on LCD reset.
  4640. */
  4641. if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
  4642. /* Enable proxy to reset only on power good. */
  4643. e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
  4644. phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
  4645. e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
  4646. /* Set bit enable LPI (EEE) to reset only on
  4647. * power good.
  4648. */
  4649. e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
  4650. phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
  4651. e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
  4652. /* Disable the SMB release on LCD reset. */
  4653. e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
  4654. phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
  4655. e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
  4656. }
  4657. /* Enable MTA to reset for Intel Rapid Start Technology
  4658. * Support
  4659. */
  4660. e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
  4661. phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
  4662. e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
  4663. release:
  4664. hw->phy.ops.release(hw);
  4665. }
  4666. out:
  4667. ew32(PHY_CTRL, phy_ctrl);
  4668. if (hw->mac.type == e1000_ich8lan)
  4669. e1000e_gig_downshift_workaround_ich8lan(hw);
  4670. if (hw->mac.type >= e1000_pchlan) {
  4671. e1000_oem_bits_config_ich8lan(hw, false);
  4672. /* Reset PHY to activate OEM bits on 82577/8 */
  4673. if (hw->mac.type == e1000_pchlan)
  4674. e1000e_phy_hw_reset_generic(hw);
  4675. ret_val = hw->phy.ops.acquire(hw);
  4676. if (ret_val)
  4677. return;
  4678. e1000_write_smbus_addr(hw);
  4679. hw->phy.ops.release(hw);
  4680. }
  4681. }
  4682. /**
  4683. * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
  4684. * @hw: pointer to the HW structure
  4685. *
  4686. * During Sx to S0 transitions on non-managed devices or managed devices
  4687. * on which PHY resets are not blocked, if the PHY registers cannot be
  4688. * accessed properly by the s/w toggle the LANPHYPC value to power cycle
  4689. * the PHY.
  4690. * On i217, setup Intel Rapid Start Technology.
  4691. **/
  4692. void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
  4693. {
  4694. s32 ret_val;
  4695. if (hw->mac.type < e1000_pch2lan)
  4696. return;
  4697. ret_val = e1000_init_phy_workarounds_pchlan(hw);
  4698. if (ret_val) {
  4699. e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
  4700. return;
  4701. }
  4702. /* For i217 Intel Rapid Start Technology support when the system
  4703. * is transitioning from Sx and no manageability engine is present
  4704. * configure SMBus to restore on reset, disable proxy, and enable
  4705. * the reset on MTA (Multicast table array).
  4706. */
  4707. if (hw->phy.type == e1000_phy_i217) {
  4708. u16 phy_reg;
  4709. ret_val = hw->phy.ops.acquire(hw);
  4710. if (ret_val) {
  4711. e_dbg("Failed to setup iRST\n");
  4712. return;
  4713. }
  4714. /* Clear Auto Enable LPI after link up */
  4715. e1e_rphy_locked(hw, I217_LPI_GPIO_CTRL, &phy_reg);
  4716. phy_reg &= ~I217_LPI_GPIO_CTRL_AUTO_EN_LPI;
  4717. e1e_wphy_locked(hw, I217_LPI_GPIO_CTRL, phy_reg);
  4718. if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
  4719. /* Restore clear on SMB if no manageability engine
  4720. * is present
  4721. */
  4722. ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
  4723. if (ret_val)
  4724. goto release;
  4725. phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
  4726. e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
  4727. /* Disable Proxy */
  4728. e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
  4729. }
  4730. /* Enable reset on MTA */
  4731. ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
  4732. if (ret_val)
  4733. goto release;
  4734. phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
  4735. e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
  4736. release:
  4737. if (ret_val)
  4738. e_dbg("Error %d in resume workarounds\n", ret_val);
  4739. hw->phy.ops.release(hw);
  4740. }
  4741. }
  4742. /**
  4743. * e1000_cleanup_led_ich8lan - Restore the default LED operation
  4744. * @hw: pointer to the HW structure
  4745. *
  4746. * Return the LED back to the default configuration.
  4747. **/
  4748. static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
  4749. {
  4750. if (hw->phy.type == e1000_phy_ife)
  4751. return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
  4752. ew32(LEDCTL, hw->mac.ledctl_default);
  4753. return 0;
  4754. }
  4755. /**
  4756. * e1000_led_on_ich8lan - Turn LEDs on
  4757. * @hw: pointer to the HW structure
  4758. *
  4759. * Turn on the LEDs.
  4760. **/
  4761. static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
  4762. {
  4763. if (hw->phy.type == e1000_phy_ife)
  4764. return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
  4765. (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
  4766. ew32(LEDCTL, hw->mac.ledctl_mode2);
  4767. return 0;
  4768. }
  4769. /**
  4770. * e1000_led_off_ich8lan - Turn LEDs off
  4771. * @hw: pointer to the HW structure
  4772. *
  4773. * Turn off the LEDs.
  4774. **/
  4775. static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
  4776. {
  4777. if (hw->phy.type == e1000_phy_ife)
  4778. return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
  4779. (IFE_PSCL_PROBE_MODE |
  4780. IFE_PSCL_PROBE_LEDS_OFF));
  4781. ew32(LEDCTL, hw->mac.ledctl_mode1);
  4782. return 0;
  4783. }
  4784. /**
  4785. * e1000_setup_led_pchlan - Configures SW controllable LED
  4786. * @hw: pointer to the HW structure
  4787. *
  4788. * This prepares the SW controllable LED for use.
  4789. **/
  4790. static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
  4791. {
  4792. return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
  4793. }
  4794. /**
  4795. * e1000_cleanup_led_pchlan - Restore the default LED operation
  4796. * @hw: pointer to the HW structure
  4797. *
  4798. * Return the LED back to the default configuration.
  4799. **/
  4800. static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
  4801. {
  4802. return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
  4803. }
  4804. /**
  4805. * e1000_led_on_pchlan - Turn LEDs on
  4806. * @hw: pointer to the HW structure
  4807. *
  4808. * Turn on the LEDs.
  4809. **/
  4810. static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
  4811. {
  4812. u16 data = (u16)hw->mac.ledctl_mode2;
  4813. u32 i, led;
  4814. /* If no link, then turn LED on by setting the invert bit
  4815. * for each LED that's mode is "link_up" in ledctl_mode2.
  4816. */
  4817. if (!(er32(STATUS) & E1000_STATUS_LU)) {
  4818. for (i = 0; i < 3; i++) {
  4819. led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
  4820. if ((led & E1000_PHY_LED0_MODE_MASK) !=
  4821. E1000_LEDCTL_MODE_LINK_UP)
  4822. continue;
  4823. if (led & E1000_PHY_LED0_IVRT)
  4824. data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
  4825. else
  4826. data |= (E1000_PHY_LED0_IVRT << (i * 5));
  4827. }
  4828. }
  4829. return e1e_wphy(hw, HV_LED_CONFIG, data);
  4830. }
  4831. /**
  4832. * e1000_led_off_pchlan - Turn LEDs off
  4833. * @hw: pointer to the HW structure
  4834. *
  4835. * Turn off the LEDs.
  4836. **/
  4837. static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
  4838. {
  4839. u16 data = (u16)hw->mac.ledctl_mode1;
  4840. u32 i, led;
  4841. /* If no link, then turn LED off by clearing the invert bit
  4842. * for each LED that's mode is "link_up" in ledctl_mode1.
  4843. */
  4844. if (!(er32(STATUS) & E1000_STATUS_LU)) {
  4845. for (i = 0; i < 3; i++) {
  4846. led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
  4847. if ((led & E1000_PHY_LED0_MODE_MASK) !=
  4848. E1000_LEDCTL_MODE_LINK_UP)
  4849. continue;
  4850. if (led & E1000_PHY_LED0_IVRT)
  4851. data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
  4852. else
  4853. data |= (E1000_PHY_LED0_IVRT << (i * 5));
  4854. }
  4855. }
  4856. return e1e_wphy(hw, HV_LED_CONFIG, data);
  4857. }
  4858. /**
  4859. * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
  4860. * @hw: pointer to the HW structure
  4861. *
  4862. * Read appropriate register for the config done bit for completion status
  4863. * and configure the PHY through s/w for EEPROM-less parts.
  4864. *
  4865. * NOTE: some silicon which is EEPROM-less will fail trying to read the
  4866. * config done bit, so only an error is logged and continues. If we were
  4867. * to return with error, EEPROM-less silicon would not be able to be reset
  4868. * or change link.
  4869. **/
  4870. static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
  4871. {
  4872. s32 ret_val = 0;
  4873. u32 bank = 0;
  4874. u32 status;
  4875. e1000e_get_cfg_done_generic(hw);
  4876. /* Wait for indication from h/w that it has completed basic config */
  4877. if (hw->mac.type >= e1000_ich10lan) {
  4878. e1000_lan_init_done_ich8lan(hw);
  4879. } else {
  4880. ret_val = e1000e_get_auto_rd_done(hw);
  4881. if (ret_val) {
  4882. /* When auto config read does not complete, do not
  4883. * return with an error. This can happen in situations
  4884. * where there is no eeprom and prevents getting link.
  4885. */
  4886. e_dbg("Auto Read Done did not complete\n");
  4887. ret_val = 0;
  4888. }
  4889. }
  4890. /* Clear PHY Reset Asserted bit */
  4891. status = er32(STATUS);
  4892. if (status & E1000_STATUS_PHYRA)
  4893. ew32(STATUS, status & ~E1000_STATUS_PHYRA);
  4894. else
  4895. e_dbg("PHY Reset Asserted not set - needs delay\n");
  4896. /* If EEPROM is not marked present, init the IGP 3 PHY manually */
  4897. if (hw->mac.type <= e1000_ich9lan) {
  4898. if (!(er32(EECD) & E1000_EECD_PRES) &&
  4899. (hw->phy.type == e1000_phy_igp_3)) {
  4900. e1000e_phy_init_script_igp3(hw);
  4901. }
  4902. } else {
  4903. if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
  4904. /* Maybe we should do a basic PHY config */
  4905. e_dbg("EEPROM not present\n");
  4906. ret_val = -E1000_ERR_CONFIG;
  4907. }
  4908. }
  4909. return ret_val;
  4910. }
  4911. /**
  4912. * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
  4913. * @hw: pointer to the HW structure
  4914. *
  4915. * In the case of a PHY power down to save power, or to turn off link during a
  4916. * driver unload, or wake on lan is not enabled, remove the link.
  4917. **/
  4918. static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
  4919. {
  4920. /* If the management interface is not enabled, then power down */
  4921. if (!(hw->mac.ops.check_mng_mode(hw) ||
  4922. hw->phy.ops.check_reset_block(hw)))
  4923. e1000_power_down_phy_copper(hw);
  4924. }
  4925. /**
  4926. * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
  4927. * @hw: pointer to the HW structure
  4928. *
  4929. * Clears hardware counters specific to the silicon family and calls
  4930. * clear_hw_cntrs_generic to clear all general purpose counters.
  4931. **/
  4932. static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
  4933. {
  4934. u16 phy_data;
  4935. s32 ret_val;
  4936. e1000e_clear_hw_cntrs_base(hw);
  4937. er32(ALGNERRC);
  4938. er32(RXERRC);
  4939. er32(TNCRS);
  4940. er32(CEXTERR);
  4941. er32(TSCTC);
  4942. er32(TSCTFC);
  4943. er32(MGTPRC);
  4944. er32(MGTPDC);
  4945. er32(MGTPTC);
  4946. er32(IAC);
  4947. er32(ICRXOC);
  4948. /* Clear PHY statistics registers */
  4949. if ((hw->phy.type == e1000_phy_82578) ||
  4950. (hw->phy.type == e1000_phy_82579) ||
  4951. (hw->phy.type == e1000_phy_i217) ||
  4952. (hw->phy.type == e1000_phy_82577)) {
  4953. ret_val = hw->phy.ops.acquire(hw);
  4954. if (ret_val)
  4955. return;
  4956. ret_val = hw->phy.ops.set_page(hw,
  4957. HV_STATS_PAGE << IGP_PAGE_SHIFT);
  4958. if (ret_val)
  4959. goto release;
  4960. hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
  4961. hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
  4962. hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
  4963. hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
  4964. hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
  4965. hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
  4966. hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
  4967. hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
  4968. hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
  4969. hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
  4970. hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
  4971. hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
  4972. hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
  4973. hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
  4974. release:
  4975. hw->phy.ops.release(hw);
  4976. }
  4977. }
  4978. static const struct e1000_mac_operations ich8_mac_ops = {
  4979. /* check_mng_mode dependent on mac type */
  4980. .check_for_link = e1000_check_for_copper_link_ich8lan,
  4981. /* cleanup_led dependent on mac type */
  4982. .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
  4983. .get_bus_info = e1000_get_bus_info_ich8lan,
  4984. .set_lan_id = e1000_set_lan_id_single_port,
  4985. .get_link_up_info = e1000_get_link_up_info_ich8lan,
  4986. /* led_on dependent on mac type */
  4987. /* led_off dependent on mac type */
  4988. .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
  4989. .reset_hw = e1000_reset_hw_ich8lan,
  4990. .init_hw = e1000_init_hw_ich8lan,
  4991. .setup_link = e1000_setup_link_ich8lan,
  4992. .setup_physical_interface = e1000_setup_copper_link_ich8lan,
  4993. /* id_led_init dependent on mac type */
  4994. .config_collision_dist = e1000e_config_collision_dist_generic,
  4995. .rar_set = e1000e_rar_set_generic,
  4996. .rar_get_count = e1000e_rar_get_count_generic,
  4997. };
  4998. static const struct e1000_phy_operations ich8_phy_ops = {
  4999. .acquire = e1000_acquire_swflag_ich8lan,
  5000. .check_reset_block = e1000_check_reset_block_ich8lan,
  5001. .commit = NULL,
  5002. .get_cfg_done = e1000_get_cfg_done_ich8lan,
  5003. .get_cable_length = e1000e_get_cable_length_igp_2,
  5004. .read_reg = e1000e_read_phy_reg_igp,
  5005. .release = e1000_release_swflag_ich8lan,
  5006. .reset = e1000_phy_hw_reset_ich8lan,
  5007. .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
  5008. .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
  5009. .write_reg = e1000e_write_phy_reg_igp,
  5010. };
  5011. static const struct e1000_nvm_operations ich8_nvm_ops = {
  5012. .acquire = e1000_acquire_nvm_ich8lan,
  5013. .read = e1000_read_nvm_ich8lan,
  5014. .release = e1000_release_nvm_ich8lan,
  5015. .reload = e1000e_reload_nvm_generic,
  5016. .update = e1000_update_nvm_checksum_ich8lan,
  5017. .valid_led_default = e1000_valid_led_default_ich8lan,
  5018. .validate = e1000_validate_nvm_checksum_ich8lan,
  5019. .write = e1000_write_nvm_ich8lan,
  5020. };
  5021. static const struct e1000_nvm_operations spt_nvm_ops = {
  5022. .acquire = e1000_acquire_nvm_ich8lan,
  5023. .release = e1000_release_nvm_ich8lan,
  5024. .read = e1000_read_nvm_spt,
  5025. .update = e1000_update_nvm_checksum_spt,
  5026. .reload = e1000e_reload_nvm_generic,
  5027. .valid_led_default = e1000_valid_led_default_ich8lan,
  5028. .validate = e1000_validate_nvm_checksum_ich8lan,
  5029. .write = e1000_write_nvm_ich8lan,
  5030. };
  5031. const struct e1000_info e1000_ich8_info = {
  5032. .mac = e1000_ich8lan,
  5033. .flags = FLAG_HAS_WOL
  5034. | FLAG_IS_ICH
  5035. | FLAG_HAS_CTRLEXT_ON_LOAD
  5036. | FLAG_HAS_AMT
  5037. | FLAG_HAS_FLASH
  5038. | FLAG_APME_IN_WUC,
  5039. .pba = 8,
  5040. .max_hw_frame_size = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN,
  5041. .get_variants = e1000_get_variants_ich8lan,
  5042. .mac_ops = &ich8_mac_ops,
  5043. .phy_ops = &ich8_phy_ops,
  5044. .nvm_ops = &ich8_nvm_ops,
  5045. };
  5046. const struct e1000_info e1000_ich9_info = {
  5047. .mac = e1000_ich9lan,
  5048. .flags = FLAG_HAS_JUMBO_FRAMES
  5049. | FLAG_IS_ICH
  5050. | FLAG_HAS_WOL
  5051. | FLAG_HAS_CTRLEXT_ON_LOAD
  5052. | FLAG_HAS_AMT
  5053. | FLAG_HAS_FLASH
  5054. | FLAG_APME_IN_WUC,
  5055. .pba = 18,
  5056. .max_hw_frame_size = DEFAULT_JUMBO,
  5057. .get_variants = e1000_get_variants_ich8lan,
  5058. .mac_ops = &ich8_mac_ops,
  5059. .phy_ops = &ich8_phy_ops,
  5060. .nvm_ops = &ich8_nvm_ops,
  5061. };
  5062. const struct e1000_info e1000_ich10_info = {
  5063. .mac = e1000_ich10lan,
  5064. .flags = FLAG_HAS_JUMBO_FRAMES
  5065. | FLAG_IS_ICH
  5066. | FLAG_HAS_WOL
  5067. | FLAG_HAS_CTRLEXT_ON_LOAD
  5068. | FLAG_HAS_AMT
  5069. | FLAG_HAS_FLASH
  5070. | FLAG_APME_IN_WUC,
  5071. .pba = 18,
  5072. .max_hw_frame_size = DEFAULT_JUMBO,
  5073. .get_variants = e1000_get_variants_ich8lan,
  5074. .mac_ops = &ich8_mac_ops,
  5075. .phy_ops = &ich8_phy_ops,
  5076. .nvm_ops = &ich8_nvm_ops,
  5077. };
  5078. const struct e1000_info e1000_pch_info = {
  5079. .mac = e1000_pchlan,
  5080. .flags = FLAG_IS_ICH
  5081. | FLAG_HAS_WOL
  5082. | FLAG_HAS_CTRLEXT_ON_LOAD
  5083. | FLAG_HAS_AMT
  5084. | FLAG_HAS_FLASH
  5085. | FLAG_HAS_JUMBO_FRAMES
  5086. | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
  5087. | FLAG_APME_IN_WUC,
  5088. .flags2 = FLAG2_HAS_PHY_STATS,
  5089. .pba = 26,
  5090. .max_hw_frame_size = 4096,
  5091. .get_variants = e1000_get_variants_ich8lan,
  5092. .mac_ops = &ich8_mac_ops,
  5093. .phy_ops = &ich8_phy_ops,
  5094. .nvm_ops = &ich8_nvm_ops,
  5095. };
  5096. const struct e1000_info e1000_pch2_info = {
  5097. .mac = e1000_pch2lan,
  5098. .flags = FLAG_IS_ICH
  5099. | FLAG_HAS_WOL
  5100. | FLAG_HAS_HW_TIMESTAMP
  5101. | FLAG_HAS_CTRLEXT_ON_LOAD
  5102. | FLAG_HAS_AMT
  5103. | FLAG_HAS_FLASH
  5104. | FLAG_HAS_JUMBO_FRAMES
  5105. | FLAG_APME_IN_WUC,
  5106. .flags2 = FLAG2_HAS_PHY_STATS
  5107. | FLAG2_HAS_EEE
  5108. | FLAG2_CHECK_SYSTIM_OVERFLOW,
  5109. .pba = 26,
  5110. .max_hw_frame_size = 9022,
  5111. .get_variants = e1000_get_variants_ich8lan,
  5112. .mac_ops = &ich8_mac_ops,
  5113. .phy_ops = &ich8_phy_ops,
  5114. .nvm_ops = &ich8_nvm_ops,
  5115. };
  5116. const struct e1000_info e1000_pch_lpt_info = {
  5117. .mac = e1000_pch_lpt,
  5118. .flags = FLAG_IS_ICH
  5119. | FLAG_HAS_WOL
  5120. | FLAG_HAS_HW_TIMESTAMP
  5121. | FLAG_HAS_CTRLEXT_ON_LOAD
  5122. | FLAG_HAS_AMT
  5123. | FLAG_HAS_FLASH
  5124. | FLAG_HAS_JUMBO_FRAMES
  5125. | FLAG_APME_IN_WUC,
  5126. .flags2 = FLAG2_HAS_PHY_STATS
  5127. | FLAG2_HAS_EEE
  5128. | FLAG2_CHECK_SYSTIM_OVERFLOW,
  5129. .pba = 26,
  5130. .max_hw_frame_size = 9022,
  5131. .get_variants = e1000_get_variants_ich8lan,
  5132. .mac_ops = &ich8_mac_ops,
  5133. .phy_ops = &ich8_phy_ops,
  5134. .nvm_ops = &ich8_nvm_ops,
  5135. };
  5136. const struct e1000_info e1000_pch_spt_info = {
  5137. .mac = e1000_pch_spt,
  5138. .flags = FLAG_IS_ICH
  5139. | FLAG_HAS_WOL
  5140. | FLAG_HAS_HW_TIMESTAMP
  5141. | FLAG_HAS_CTRLEXT_ON_LOAD
  5142. | FLAG_HAS_AMT
  5143. | FLAG_HAS_FLASH
  5144. | FLAG_HAS_JUMBO_FRAMES
  5145. | FLAG_APME_IN_WUC,
  5146. .flags2 = FLAG2_HAS_PHY_STATS
  5147. | FLAG2_HAS_EEE,
  5148. .pba = 26,
  5149. .max_hw_frame_size = 9022,
  5150. .get_variants = e1000_get_variants_ich8lan,
  5151. .mac_ops = &ich8_mac_ops,
  5152. .phy_ops = &ich8_phy_ops,
  5153. .nvm_ops = &spt_nvm_ops,
  5154. };
  5155. const struct e1000_info e1000_pch_cnp_info = {
  5156. .mac = e1000_pch_cnp,
  5157. .flags = FLAG_IS_ICH
  5158. | FLAG_HAS_WOL
  5159. | FLAG_HAS_HW_TIMESTAMP
  5160. | FLAG_HAS_CTRLEXT_ON_LOAD
  5161. | FLAG_HAS_AMT
  5162. | FLAG_HAS_FLASH
  5163. | FLAG_HAS_JUMBO_FRAMES
  5164. | FLAG_APME_IN_WUC,
  5165. .flags2 = FLAG2_HAS_PHY_STATS
  5166. | FLAG2_HAS_EEE,
  5167. .pba = 26,
  5168. .max_hw_frame_size = 9022,
  5169. .get_variants = e1000_get_variants_ich8lan,
  5170. .mac_ops = &ich8_mac_ops,
  5171. .phy_ops = &ich8_phy_ops,
  5172. .nvm_ops = &spt_nvm_ops,
  5173. };