PageRenderTime 59ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 2ms

/drivers/e1000-6.x/src/e1000_hw.c

https://github.com/bhesmans/click
C | 6799 lines | 4176 code | 892 blank | 1731 comment | 971 complexity | f88ba4463527bca500ac784f75add5ff MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. /*******************************************************************************
  2. Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the Free
  5. Software Foundation; either version 2 of the License, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc., 59
  13. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. The full GNU General Public License is included in this distribution in the
  15. file called LICENSE.
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. /* e1000_hw.c
  21. * Shared functions for accessing and configuring the MAC
  22. */
  23. #include "e1000_hw.h"
  24. static int32_t e1000_set_phy_type(struct e1000_hw *hw);
  25. static void e1000_phy_init_script(struct e1000_hw *hw);
  26. static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
  27. static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
  28. static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
  29. static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
  30. static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
  31. static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
  32. static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
  33. static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
  34. uint16_t count);
  35. static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
  36. static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
  37. static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
  38. uint16_t words, uint16_t *data);
  39. static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
  40. uint16_t offset, uint16_t words,
  41. uint16_t *data);
  42. static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
  43. static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
  44. static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
  45. static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
  46. uint16_t count);
  47. static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
  48. uint16_t phy_data);
  49. static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
  50. uint16_t *phy_data);
  51. static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
  52. static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
  53. static void e1000_release_eeprom(struct e1000_hw *hw);
  54. static void e1000_standby_eeprom(struct e1000_hw *hw);
  55. static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
  56. static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
  57. static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
  58. static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
  59. static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
  60. /* IGP cable length table */
  61. static const
  62. uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
  63. { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  64. 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
  65. 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
  66. 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
  67. 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
  68. 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
  69. 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
  70. 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
  71. static const
  72. uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
  73. { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
  74. 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
  75. 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
  76. 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
  77. 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
  78. 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
  79. 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
  80. 104, 109, 114, 118, 121, 124};
  81. /******************************************************************************
  82. * Set the phy type member in the hw struct.
  83. *
  84. * hw - Struct containing variables accessed by shared code
  85. *****************************************************************************/
  86. int32_t
  87. e1000_set_phy_type(struct e1000_hw *hw)
  88. {
  89. DEBUGFUNC("e1000_set_phy_type");
  90. if(hw->mac_type == e1000_undefined)
  91. return -E1000_ERR_PHY_TYPE;
  92. switch(hw->phy_id) {
  93. case M88E1000_E_PHY_ID:
  94. case M88E1000_I_PHY_ID:
  95. case M88E1011_I_PHY_ID:
  96. case M88E1111_I_PHY_ID:
  97. hw->phy_type = e1000_phy_m88;
  98. break;
  99. case IGP01E1000_I_PHY_ID:
  100. if(hw->mac_type == e1000_82541 ||
  101. hw->mac_type == e1000_82541_rev_2 ||
  102. hw->mac_type == e1000_82547 ||
  103. hw->mac_type == e1000_82547_rev_2) {
  104. hw->phy_type = e1000_phy_igp;
  105. break;
  106. }
  107. /* Fall Through */
  108. default:
  109. /* Should never have loaded on this device */
  110. hw->phy_type = e1000_phy_undefined;
  111. return -E1000_ERR_PHY_TYPE;
  112. }
  113. return E1000_SUCCESS;
  114. }
  115. /******************************************************************************
  116. * IGP phy init script - initializes the GbE PHY
  117. *
  118. * hw - Struct containing variables accessed by shared code
  119. *****************************************************************************/
  120. static void
  121. e1000_phy_init_script(struct e1000_hw *hw)
  122. {
  123. uint32_t ret_val;
  124. uint16_t phy_saved_data;
  125. DEBUGFUNC("e1000_phy_init_script");
  126. if(hw->phy_init_script) {
  127. msec_delay(20);
  128. /* Save off the current value of register 0x2F5B to be restored at
  129. * the end of this routine. */
  130. ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  131. /* Disabled the PHY transmitter */
  132. e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  133. msec_delay(20);
  134. e1000_write_phy_reg(hw,0x0000,0x0140);
  135. msec_delay(5);
  136. switch(hw->mac_type) {
  137. case e1000_82541:
  138. case e1000_82547:
  139. e1000_write_phy_reg(hw, 0x1F95, 0x0001);
  140. e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
  141. e1000_write_phy_reg(hw, 0x1F79, 0x0018);
  142. e1000_write_phy_reg(hw, 0x1F30, 0x1600);
  143. e1000_write_phy_reg(hw, 0x1F31, 0x0014);
  144. e1000_write_phy_reg(hw, 0x1F32, 0x161C);
  145. e1000_write_phy_reg(hw, 0x1F94, 0x0003);
  146. e1000_write_phy_reg(hw, 0x1F96, 0x003F);
  147. e1000_write_phy_reg(hw, 0x2010, 0x0008);
  148. break;
  149. case e1000_82541_rev_2:
  150. case e1000_82547_rev_2:
  151. e1000_write_phy_reg(hw, 0x1F73, 0x0099);
  152. break;
  153. default:
  154. break;
  155. }
  156. e1000_write_phy_reg(hw, 0x0000, 0x3300);
  157. msec_delay(20);
  158. /* Now enable the transmitter */
  159. e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  160. if(hw->mac_type == e1000_82547) {
  161. uint16_t fused, fine, coarse;
  162. /* Move to analog registers page */
  163. e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
  164. if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
  165. e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
  166. fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
  167. coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
  168. if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
  169. coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
  170. fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
  171. } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
  172. fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
  173. fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
  174. (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
  175. (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
  176. e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
  177. e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
  178. IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
  179. }
  180. }
  181. }
  182. }
  183. /******************************************************************************
  184. * Set the mac type member in the hw struct.
  185. *
  186. * hw - Struct containing variables accessed by shared code
  187. *****************************************************************************/
  188. int32_t
  189. e1000_set_mac_type(struct e1000_hw *hw)
  190. {
  191. DEBUGFUNC("e1000_set_mac_type");
  192. switch (hw->device_id) {
  193. case E1000_DEV_ID_82542:
  194. switch (hw->revision_id) {
  195. case E1000_82542_2_0_REV_ID:
  196. hw->mac_type = e1000_82542_rev2_0;
  197. break;
  198. case E1000_82542_2_1_REV_ID:
  199. hw->mac_type = e1000_82542_rev2_1;
  200. break;
  201. default:
  202. /* Invalid 82542 revision ID */
  203. return -E1000_ERR_MAC_TYPE;
  204. }
  205. break;
  206. case E1000_DEV_ID_82543GC_FIBER:
  207. case E1000_DEV_ID_82543GC_COPPER:
  208. hw->mac_type = e1000_82543;
  209. break;
  210. case E1000_DEV_ID_82544EI_COPPER:
  211. case E1000_DEV_ID_82544EI_FIBER:
  212. case E1000_DEV_ID_82544GC_COPPER:
  213. case E1000_DEV_ID_82544GC_LOM:
  214. hw->mac_type = e1000_82544;
  215. break;
  216. case E1000_DEV_ID_82540EM:
  217. case E1000_DEV_ID_82540EM_LOM:
  218. case E1000_DEV_ID_82540EP:
  219. case E1000_DEV_ID_82540EP_LOM:
  220. case E1000_DEV_ID_82540EP_LP:
  221. hw->mac_type = e1000_82540;
  222. break;
  223. case E1000_DEV_ID_82545EM_COPPER:
  224. case E1000_DEV_ID_82545EM_FIBER:
  225. hw->mac_type = e1000_82545;
  226. break;
  227. case E1000_DEV_ID_82545GM_COPPER:
  228. case E1000_DEV_ID_82545GM_FIBER:
  229. case E1000_DEV_ID_82545GM_SERDES:
  230. hw->mac_type = e1000_82545_rev_3;
  231. break;
  232. case E1000_DEV_ID_82546EB_COPPER:
  233. case E1000_DEV_ID_82546EB_FIBER:
  234. case E1000_DEV_ID_82546EB_QUAD_COPPER:
  235. hw->mac_type = e1000_82546;
  236. break;
  237. case E1000_DEV_ID_82546GB_COPPER:
  238. case E1000_DEV_ID_82546GB_FIBER:
  239. case E1000_DEV_ID_82546GB_SERDES:
  240. case E1000_DEV_ID_82546GB_PCIE:
  241. hw->mac_type = e1000_82546_rev_3;
  242. break;
  243. case E1000_DEV_ID_82541EI:
  244. case E1000_DEV_ID_82541EI_MOBILE:
  245. hw->mac_type = e1000_82541;
  246. break;
  247. case E1000_DEV_ID_82541ER:
  248. case E1000_DEV_ID_82541GI:
  249. case E1000_DEV_ID_82541GI_LF:
  250. case E1000_DEV_ID_82541GI_MOBILE:
  251. hw->mac_type = e1000_82541_rev_2;
  252. break;
  253. case E1000_DEV_ID_82547EI:
  254. hw->mac_type = e1000_82547;
  255. break;
  256. case E1000_DEV_ID_82547GI:
  257. hw->mac_type = e1000_82547_rev_2;
  258. break;
  259. case E1000_DEV_ID_82571EB_COPPER:
  260. case E1000_DEV_ID_82571EB_FIBER:
  261. case E1000_DEV_ID_82571EB_SERDES:
  262. hw->mac_type = e1000_82571;
  263. break;
  264. case E1000_DEV_ID_82572EI_COPPER:
  265. case E1000_DEV_ID_82572EI_FIBER:
  266. case E1000_DEV_ID_82572EI_SERDES:
  267. hw->mac_type = e1000_82572;
  268. break;
  269. case E1000_DEV_ID_82573E:
  270. case E1000_DEV_ID_82573E_IAMT:
  271. case E1000_DEV_ID_82573L:
  272. hw->mac_type = e1000_82573;
  273. break;
  274. default:
  275. /* Should never have loaded on this device */
  276. return -E1000_ERR_MAC_TYPE;
  277. }
  278. switch(hw->mac_type) {
  279. case e1000_82571:
  280. case e1000_82572:
  281. case e1000_82573:
  282. hw->eeprom_semaphore_present = TRUE;
  283. /* fall through */
  284. case e1000_82541:
  285. case e1000_82547:
  286. case e1000_82541_rev_2:
  287. case e1000_82547_rev_2:
  288. hw->asf_firmware_present = TRUE;
  289. break;
  290. default:
  291. break;
  292. }
  293. return E1000_SUCCESS;
  294. }
  295. /*****************************************************************************
  296. * Set media type and TBI compatibility.
  297. *
  298. * hw - Struct containing variables accessed by shared code
  299. * **************************************************************************/
  300. void
  301. e1000_set_media_type(struct e1000_hw *hw)
  302. {
  303. uint32_t status;
  304. DEBUGFUNC("e1000_set_media_type");
  305. if(hw->mac_type != e1000_82543) {
  306. /* tbi_compatibility is only valid on 82543 */
  307. hw->tbi_compatibility_en = FALSE;
  308. }
  309. switch (hw->device_id) {
  310. case E1000_DEV_ID_82545GM_SERDES:
  311. case E1000_DEV_ID_82546GB_SERDES:
  312. case E1000_DEV_ID_82571EB_SERDES:
  313. case E1000_DEV_ID_82572EI_SERDES:
  314. hw->media_type = e1000_media_type_internal_serdes;
  315. break;
  316. default:
  317. switch (hw->mac_type) {
  318. case e1000_82542_rev2_0:
  319. case e1000_82542_rev2_1:
  320. hw->media_type = e1000_media_type_fiber;
  321. break;
  322. case e1000_82573:
  323. /* The STATUS_TBIMODE bit is reserved or reused for the this
  324. * device.
  325. */
  326. hw->media_type = e1000_media_type_copper;
  327. break;
  328. default:
  329. status = E1000_READ_REG(hw, STATUS);
  330. if (status & E1000_STATUS_TBIMODE) {
  331. hw->media_type = e1000_media_type_fiber;
  332. /* tbi_compatibility not valid on fiber */
  333. hw->tbi_compatibility_en = FALSE;
  334. } else {
  335. hw->media_type = e1000_media_type_copper;
  336. }
  337. break;
  338. }
  339. }
  340. }
  341. /******************************************************************************
  342. * Reset the transmit and receive units; mask and clear all interrupts.
  343. *
  344. * hw - Struct containing variables accessed by shared code
  345. *****************************************************************************/
  346. int32_t
  347. e1000_reset_hw(struct e1000_hw *hw)
  348. {
  349. uint32_t ctrl;
  350. uint32_t ctrl_ext;
  351. uint32_t icr;
  352. uint32_t manc;
  353. uint32_t led_ctrl;
  354. uint32_t timeout;
  355. uint32_t extcnf_ctrl;
  356. int32_t ret_val;
  357. DEBUGFUNC("e1000_reset_hw");
  358. /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
  359. if(hw->mac_type == e1000_82542_rev2_0) {
  360. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  361. e1000_pci_clear_mwi(hw);
  362. }
  363. if(hw->bus_type == e1000_bus_type_pci_express) {
  364. /* Prevent the PCI-E bus from sticking if there is no TLP connection
  365. * on the last TLP read/write transaction when MAC is reset.
  366. */
  367. if(e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
  368. DEBUGOUT("PCI-E Master disable polling has failed.\n");
  369. }
  370. }
  371. /* Clear interrupt mask to stop board from generating interrupts */
  372. DEBUGOUT("Masking off all interrupts\n");
  373. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  374. /* Disable the Transmit and Receive units. Then delay to allow
  375. * any pending transactions to complete before we hit the MAC with
  376. * the global reset.
  377. */
  378. E1000_WRITE_REG(hw, RCTL, 0);
  379. E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
  380. E1000_WRITE_FLUSH(hw);
  381. /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
  382. hw->tbi_compatibility_on = FALSE;
  383. /* Delay to allow any outstanding PCI transactions to complete before
  384. * resetting the device
  385. */
  386. msec_delay(10);
  387. ctrl = E1000_READ_REG(hw, CTRL);
  388. /* Must reset the PHY before resetting the MAC */
  389. if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  390. E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
  391. msec_delay(5);
  392. }
  393. /* Must acquire the MDIO ownership before MAC reset.
  394. * Ownership defaults to firmware after a reset. */
  395. if(hw->mac_type == e1000_82573) {
  396. timeout = 10;
  397. extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
  398. extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
  399. do {
  400. E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
  401. extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
  402. if(extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
  403. break;
  404. else
  405. extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
  406. msec_delay(2);
  407. timeout--;
  408. } while(timeout);
  409. }
  410. /* Issue a global reset to the MAC. This will reset the chip's
  411. * transmit, receive, DMA, and link units. It will not effect
  412. * the current PCI configuration. The global reset bit is self-
  413. * clearing, and should clear within a microsecond.
  414. */
  415. DEBUGOUT("Issuing a global reset to MAC\n");
  416. switch(hw->mac_type) {
  417. case e1000_82544:
  418. case e1000_82540:
  419. case e1000_82545:
  420. case e1000_82546:
  421. case e1000_82541:
  422. case e1000_82541_rev_2:
  423. /* These controllers can't ack the 64-bit write when issuing the
  424. * reset, so use IO-mapping as a workaround to issue the reset */
  425. E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
  426. break;
  427. case e1000_82545_rev_3:
  428. case e1000_82546_rev_3:
  429. /* Reset is performed on a shadow of the control register */
  430. E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
  431. break;
  432. default:
  433. E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
  434. break;
  435. }
  436. /* After MAC reset, force reload of EEPROM to restore power-on settings to
  437. * device. Later controllers reload the EEPROM automatically, so just wait
  438. * for reload to complete.
  439. */
  440. switch(hw->mac_type) {
  441. case e1000_82542_rev2_0:
  442. case e1000_82542_rev2_1:
  443. case e1000_82543:
  444. case e1000_82544:
  445. /* Wait for reset to complete */
  446. usec_delay(10);
  447. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  448. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  449. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  450. E1000_WRITE_FLUSH(hw);
  451. /* Wait for EEPROM reload */
  452. msec_delay(2);
  453. break;
  454. case e1000_82541:
  455. case e1000_82541_rev_2:
  456. case e1000_82547:
  457. case e1000_82547_rev_2:
  458. /* Wait for EEPROM reload */
  459. msec_delay(20);
  460. break;
  461. case e1000_82573:
  462. usec_delay(10);
  463. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  464. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  465. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  466. E1000_WRITE_FLUSH(hw);
  467. /* fall through */
  468. case e1000_82571:
  469. case e1000_82572:
  470. ret_val = e1000_get_auto_rd_done(hw);
  471. if(ret_val)
  472. /* We don't want to continue accessing MAC registers. */
  473. return ret_val;
  474. break;
  475. default:
  476. /* Wait for EEPROM reload (it happens automatically) */
  477. msec_delay(5);
  478. break;
  479. }
  480. /* Disable HW ARPs on ASF enabled adapters */
  481. if(hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
  482. manc = E1000_READ_REG(hw, MANC);
  483. manc &= ~(E1000_MANC_ARP_EN);
  484. E1000_WRITE_REG(hw, MANC, manc);
  485. }
  486. if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  487. e1000_phy_init_script(hw);
  488. /* Configure activity LED after PHY reset */
  489. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  490. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  491. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  492. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  493. }
  494. /* Clear interrupt mask to stop board from generating interrupts */
  495. DEBUGOUT("Masking off all interrupts\n");
  496. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  497. /* Clear any pending interrupt events. */
  498. icr = E1000_READ_REG(hw, ICR);
  499. /* If MWI was previously enabled, reenable it. */
  500. if(hw->mac_type == e1000_82542_rev2_0) {
  501. if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
  502. e1000_pci_set_mwi(hw);
  503. }
  504. return E1000_SUCCESS;
  505. }
  506. /******************************************************************************
  507. * Performs basic configuration of the adapter.
  508. *
  509. * hw - Struct containing variables accessed by shared code
  510. *
  511. * Assumes that the controller has previously been reset and is in a
  512. * post-reset uninitialized state. Initializes the receive address registers,
  513. * multicast table, and VLAN filter table. Calls routines to setup link
  514. * configuration and flow control settings. Clears all on-chip counters. Leaves
  515. * the transmit and receive units disabled and uninitialized.
  516. *****************************************************************************/
  517. int32_t
  518. e1000_init_hw(struct e1000_hw *hw)
  519. {
  520. uint32_t ctrl;
  521. uint32_t i;
  522. int32_t ret_val;
  523. uint16_t pcix_cmd_word;
  524. uint16_t pcix_stat_hi_word;
  525. uint16_t cmd_mmrbc;
  526. uint16_t stat_mmrbc;
  527. uint32_t mta_size;
  528. DEBUGFUNC("e1000_init_hw");
  529. /* Initialize Identification LED */
  530. ret_val = e1000_id_led_init(hw);
  531. if(ret_val) {
  532. DEBUGOUT("Error Initializing Identification LED\n");
  533. return ret_val;
  534. }
  535. /* Set the media type and TBI compatibility */
  536. e1000_set_media_type(hw);
  537. /* Disabling VLAN filtering. */
  538. DEBUGOUT("Initializing the IEEE VLAN\n");
  539. if (hw->mac_type < e1000_82545_rev_3)
  540. E1000_WRITE_REG(hw, VET, 0);
  541. e1000_clear_vfta(hw);
  542. /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
  543. if(hw->mac_type == e1000_82542_rev2_0) {
  544. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  545. e1000_pci_clear_mwi(hw);
  546. E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
  547. E1000_WRITE_FLUSH(hw);
  548. msec_delay(5);
  549. }
  550. /* Setup the receive address. This involves initializing all of the Receive
  551. * Address Registers (RARs 0 - 15).
  552. */
  553. e1000_init_rx_addrs(hw);
  554. /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
  555. if(hw->mac_type == e1000_82542_rev2_0) {
  556. E1000_WRITE_REG(hw, RCTL, 0);
  557. E1000_WRITE_FLUSH(hw);
  558. msec_delay(1);
  559. if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
  560. e1000_pci_set_mwi(hw);
  561. }
  562. /* Zero out the Multicast HASH table */
  563. DEBUGOUT("Zeroing the MTA\n");
  564. mta_size = E1000_MC_TBL_SIZE;
  565. for(i = 0; i < mta_size; i++)
  566. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  567. /* Set the PCI priority bit correctly in the CTRL register. This
  568. * determines if the adapter gives priority to receives, or if it
  569. * gives equal priority to transmits and receives. Valid only on
  570. * 82542 and 82543 silicon.
  571. */
  572. if(hw->dma_fairness && hw->mac_type <= e1000_82543) {
  573. ctrl = E1000_READ_REG(hw, CTRL);
  574. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
  575. }
  576. switch(hw->mac_type) {
  577. case e1000_82545_rev_3:
  578. case e1000_82546_rev_3:
  579. break;
  580. default:
  581. /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
  582. if(hw->bus_type == e1000_bus_type_pcix) {
  583. e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
  584. e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
  585. &pcix_stat_hi_word);
  586. cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
  587. PCIX_COMMAND_MMRBC_SHIFT;
  588. stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
  589. PCIX_STATUS_HI_MMRBC_SHIFT;
  590. if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
  591. stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
  592. if(cmd_mmrbc > stat_mmrbc) {
  593. pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
  594. pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
  595. e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
  596. &pcix_cmd_word);
  597. }
  598. }
  599. break;
  600. }
  601. /* Call a subroutine to configure the link and setup flow control. */
  602. ret_val = e1000_setup_link(hw);
  603. /* Set the transmit descriptor write-back policy */
  604. if(hw->mac_type > e1000_82544) {
  605. ctrl = E1000_READ_REG(hw, TXDCTL);
  606. ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
  607. switch (hw->mac_type) {
  608. default:
  609. break;
  610. case e1000_82571:
  611. case e1000_82572:
  612. ctrl |= (1 << 22);
  613. case e1000_82573:
  614. ctrl |= E1000_TXDCTL_COUNT_DESC;
  615. break;
  616. }
  617. E1000_WRITE_REG(hw, TXDCTL, ctrl);
  618. }
  619. if (hw->mac_type == e1000_82573) {
  620. e1000_enable_tx_pkt_filtering(hw);
  621. }
  622. switch (hw->mac_type) {
  623. default:
  624. break;
  625. case e1000_82571:
  626. case e1000_82572:
  627. ctrl = E1000_READ_REG(hw, TXDCTL1);
  628. ctrl &= ~E1000_TXDCTL_WTHRESH;
  629. ctrl |= E1000_TXDCTL_COUNT_DESC | E1000_TXDCTL_FULL_TX_DESC_WB;
  630. ctrl |= (1 << 22);
  631. E1000_WRITE_REG(hw, TXDCTL1, ctrl);
  632. break;
  633. }
  634. if (hw->mac_type == e1000_82573) {
  635. uint32_t gcr = E1000_READ_REG(hw, GCR);
  636. gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
  637. E1000_WRITE_REG(hw, GCR, gcr);
  638. }
  639. /* Clear all of the statistics registers (clear on read). It is
  640. * important that we do this after we have tried to establish link
  641. * because the symbol error count will increment wildly if there
  642. * is no link.
  643. */
  644. e1000_clear_hw_cntrs(hw);
  645. return ret_val;
  646. }
  647. /******************************************************************************
  648. * Adjust SERDES output amplitude based on EEPROM setting.
  649. *
  650. * hw - Struct containing variables accessed by shared code.
  651. *****************************************************************************/
  652. static int32_t
  653. e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
  654. {
  655. uint16_t eeprom_data;
  656. int32_t ret_val;
  657. DEBUGFUNC("e1000_adjust_serdes_amplitude");
  658. if(hw->media_type != e1000_media_type_internal_serdes)
  659. return E1000_SUCCESS;
  660. switch(hw->mac_type) {
  661. case e1000_82545_rev_3:
  662. case e1000_82546_rev_3:
  663. break;
  664. default:
  665. return E1000_SUCCESS;
  666. }
  667. ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
  668. if (ret_val) {
  669. return ret_val;
  670. }
  671. if(eeprom_data != EEPROM_RESERVED_WORD) {
  672. /* Adjust SERDES output amplitude only. */
  673. eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
  674. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
  675. if(ret_val)
  676. return ret_val;
  677. }
  678. return E1000_SUCCESS;
  679. }
  680. /******************************************************************************
  681. * Configures flow control and link settings.
  682. *
  683. * hw - Struct containing variables accessed by shared code
  684. *
  685. * Determines which flow control settings to use. Calls the apropriate media-
  686. * specific link configuration function. Configures the flow control settings.
  687. * Assuming the adapter has a valid link partner, a valid link should be
  688. * established. Assumes the hardware has previously been reset and the
  689. * transmitter and receiver are not enabled.
  690. *****************************************************************************/
  691. int32_t
  692. e1000_setup_link(struct e1000_hw *hw)
  693. {
  694. uint32_t ctrl_ext;
  695. int32_t ret_val;
  696. uint16_t eeprom_data;
  697. DEBUGFUNC("e1000_setup_link");
  698. /* Read and store word 0x0F of the EEPROM. This word contains bits
  699. * that determine the hardware's default PAUSE (flow control) mode,
  700. * a bit that determines whether the HW defaults to enabling or
  701. * disabling auto-negotiation, and the direction of the
  702. * SW defined pins. If there is no SW over-ride of the flow
  703. * control setting, then the variable hw->fc will
  704. * be initialized based on a value in the EEPROM.
  705. */
  706. if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data)) {
  707. DEBUGOUT("EEPROM Read Error\n");
  708. return -E1000_ERR_EEPROM;
  709. }
  710. if(hw->fc == e1000_fc_default) {
  711. if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
  712. hw->fc = e1000_fc_none;
  713. else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
  714. EEPROM_WORD0F_ASM_DIR)
  715. hw->fc = e1000_fc_tx_pause;
  716. else
  717. hw->fc = e1000_fc_full;
  718. }
  719. /* We want to save off the original Flow Control configuration just
  720. * in case we get disconnected and then reconnected into a different
  721. * hub or switch with different Flow Control capabilities.
  722. */
  723. if(hw->mac_type == e1000_82542_rev2_0)
  724. hw->fc &= (~e1000_fc_tx_pause);
  725. if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
  726. hw->fc &= (~e1000_fc_rx_pause);
  727. hw->original_fc = hw->fc;
  728. DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
  729. /* Take the 4 bits from EEPROM word 0x0F that determine the initial
  730. * polarity value for the SW controlled pins, and setup the
  731. * Extended Device Control reg with that info.
  732. * This is needed because one of the SW controlled pins is used for
  733. * signal detection. So this should be done before e1000_setup_pcs_link()
  734. * or e1000_phy_setup() is called.
  735. */
  736. if(hw->mac_type == e1000_82543) {
  737. ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
  738. SWDPIO__EXT_SHIFT);
  739. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  740. }
  741. /* Call the necessary subroutine to configure the link. */
  742. ret_val = (hw->media_type == e1000_media_type_copper) ?
  743. e1000_setup_copper_link(hw) :
  744. e1000_setup_fiber_serdes_link(hw);
  745. /* Initialize the flow control address, type, and PAUSE timer
  746. * registers to their default values. This is done even if flow
  747. * control is disabled, because it does not hurt anything to
  748. * initialize these registers.
  749. */
  750. DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
  751. E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
  752. E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  753. E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
  754. E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
  755. /* Set the flow control receive threshold registers. Normally,
  756. * these registers will be set to a default threshold that may be
  757. * adjusted later by the driver's runtime code. However, if the
  758. * ability to transmit pause frames in not enabled, then these
  759. * registers will be set to 0.
  760. */
  761. if(!(hw->fc & e1000_fc_tx_pause)) {
  762. E1000_WRITE_REG(hw, FCRTL, 0);
  763. E1000_WRITE_REG(hw, FCRTH, 0);
  764. } else {
  765. /* We need to set up the Receive Threshold high and low water marks
  766. * as well as (optionally) enabling the transmission of XON frames.
  767. */
  768. if(hw->fc_send_xon) {
  769. E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
  770. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  771. } else {
  772. E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
  773. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  774. }
  775. }
  776. return ret_val;
  777. }
  778. /******************************************************************************
  779. * Sets up link for a fiber based or serdes based adapter
  780. *
  781. * hw - Struct containing variables accessed by shared code
  782. *
  783. * Manipulates Physical Coding Sublayer functions in order to configure
  784. * link. Assumes the hardware has been previously reset and the transmitter
  785. * and receiver are not enabled.
  786. *****************************************************************************/
  787. static int32_t
  788. e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
  789. {
  790. uint32_t ctrl;
  791. uint32_t status;
  792. uint32_t txcw = 0;
  793. uint32_t i;
  794. uint32_t signal = 0;
  795. int32_t ret_val;
  796. DEBUGFUNC("e1000_setup_fiber_serdes_link");
  797. /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
  798. * until explicitly turned off or a power cycle is performed. A read to
  799. * the register does not indicate its status. Therefore, we ensure
  800. * loopback mode is disabled during initialization.
  801. */
  802. if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
  803. E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
  804. /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
  805. * set when the optics detect a signal. On older adapters, it will be
  806. * cleared when there is a signal. This applies to fiber media only.
  807. * If we're on serdes media, adjust the output amplitude to value set in
  808. * the EEPROM.
  809. */
  810. ctrl = E1000_READ_REG(hw, CTRL);
  811. if(hw->media_type == e1000_media_type_fiber)
  812. signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
  813. ret_val = e1000_adjust_serdes_amplitude(hw);
  814. if(ret_val)
  815. return ret_val;
  816. /* Take the link out of reset */
  817. ctrl &= ~(E1000_CTRL_LRST);
  818. /* Adjust VCO speed to improve BER performance */
  819. ret_val = e1000_set_vco_speed(hw);
  820. if(ret_val)
  821. return ret_val;
  822. e1000_config_collision_dist(hw);
  823. /* Check for a software override of the flow control settings, and setup
  824. * the device accordingly. If auto-negotiation is enabled, then software
  825. * will have to set the "PAUSE" bits to the correct value in the Tranmsit
  826. * Config Word Register (TXCW) and re-start auto-negotiation. However, if
  827. * auto-negotiation is disabled, then software will have to manually
  828. * configure the two flow control enable bits in the CTRL register.
  829. *
  830. * The possible values of the "fc" parameter are:
  831. * 0: Flow control is completely disabled
  832. * 1: Rx flow control is enabled (we can receive pause frames, but
  833. * not send pause frames).
  834. * 2: Tx flow control is enabled (we can send pause frames but we do
  835. * not support receiving pause frames).
  836. * 3: Both Rx and TX flow control (symmetric) are enabled.
  837. */
  838. switch (hw->fc) {
  839. case e1000_fc_none:
  840. /* Flow control is completely disabled by a software over-ride. */
  841. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
  842. break;
  843. case e1000_fc_rx_pause:
  844. /* RX Flow control is enabled and TX Flow control is disabled by a
  845. * software over-ride. Since there really isn't a way to advertise
  846. * that we are capable of RX Pause ONLY, we will advertise that we
  847. * support both symmetric and asymmetric RX PAUSE. Later, we will
  848. * disable the adapter's ability to send PAUSE frames.
  849. */
  850. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  851. break;
  852. case e1000_fc_tx_pause:
  853. /* TX Flow control is enabled, and RX Flow control is disabled, by a
  854. * software over-ride.
  855. */
  856. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
  857. break;
  858. case e1000_fc_full:
  859. /* Flow control (both RX and TX) is enabled by a software over-ride. */
  860. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  861. break;
  862. default:
  863. DEBUGOUT("Flow control param set incorrectly\n");
  864. return -E1000_ERR_CONFIG;
  865. break;
  866. }
  867. /* Since auto-negotiation is enabled, take the link out of reset (the link
  868. * will be in reset, because we previously reset the chip). This will
  869. * restart auto-negotiation. If auto-neogtiation is successful then the
  870. * link-up status bit will be set and the flow control enable bits (RFCE
  871. * and TFCE) will be set according to their negotiated value.
  872. */
  873. DEBUGOUT("Auto-negotiation enabled\n");
  874. E1000_WRITE_REG(hw, TXCW, txcw);
  875. E1000_WRITE_REG(hw, CTRL, ctrl);
  876. E1000_WRITE_FLUSH(hw);
  877. hw->txcw = txcw;
  878. msec_delay(1);
  879. /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
  880. * indication in the Device Status Register. Time-out if a link isn't
  881. * seen in 500 milliseconds seconds (Auto-negotiation should complete in
  882. * less than 500 milliseconds even if the other end is doing it in SW).
  883. * For internal serdes, we just assume a signal is present, then poll.
  884. */
  885. if(hw->media_type == e1000_media_type_internal_serdes ||
  886. (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
  887. DEBUGOUT("Looking for Link\n");
  888. for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
  889. msec_delay(10);
  890. status = E1000_READ_REG(hw, STATUS);
  891. if(status & E1000_STATUS_LU) break;
  892. }
  893. if(i == (LINK_UP_TIMEOUT / 10)) {
  894. DEBUGOUT("Never got a valid link from auto-neg!!!\n");
  895. hw->autoneg_failed = 1;
  896. /* AutoNeg failed to achieve a link, so we'll call
  897. * e1000_check_for_link. This routine will force the link up if
  898. * we detect a signal. This will allow us to communicate with
  899. * non-autonegotiating link partners.
  900. */
  901. ret_val = e1000_check_for_link(hw);
  902. if(ret_val) {
  903. DEBUGOUT("Error while checking for link\n");
  904. return ret_val;
  905. }
  906. hw->autoneg_failed = 0;
  907. } else {
  908. hw->autoneg_failed = 0;
  909. DEBUGOUT("Valid Link Found\n");
  910. }
  911. } else {
  912. DEBUGOUT("No Signal Detected\n");
  913. }
  914. return E1000_SUCCESS;
  915. }
  916. /******************************************************************************
  917. * Make sure we have a valid PHY and change PHY mode before link setup.
  918. *
  919. * hw - Struct containing variables accessed by shared code
  920. ******************************************************************************/
  921. static int32_t
  922. e1000_copper_link_preconfig(struct e1000_hw *hw)
  923. {
  924. uint32_t ctrl;
  925. int32_t ret_val;
  926. uint16_t phy_data;
  927. DEBUGFUNC("e1000_copper_link_preconfig");
  928. ctrl = E1000_READ_REG(hw, CTRL);
  929. /* With 82543, we need to force speed and duplex on the MAC equal to what
  930. * the PHY speed and duplex configuration is. In addition, we need to
  931. * perform a hardware reset on the PHY to take it out of reset.
  932. */
  933. if(hw->mac_type > e1000_82543) {
  934. ctrl |= E1000_CTRL_SLU;
  935. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  936. E1000_WRITE_REG(hw, CTRL, ctrl);
  937. } else {
  938. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
  939. E1000_WRITE_REG(hw, CTRL, ctrl);
  940. ret_val = e1000_phy_hw_reset(hw);
  941. if(ret_val)
  942. return ret_val;
  943. }
  944. /* Make sure we have a valid PHY */
  945. ret_val = e1000_detect_gig_phy(hw);
  946. if(ret_val) {
  947. DEBUGOUT("Error, did not detect valid phy.\n");
  948. return ret_val;
  949. }
  950. DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
  951. /* Set PHY to class A mode (if necessary) */
  952. ret_val = e1000_set_phy_mode(hw);
  953. if(ret_val)
  954. return ret_val;
  955. if((hw->mac_type == e1000_82545_rev_3) ||
  956. (hw->mac_type == e1000_82546_rev_3)) {
  957. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  958. phy_data |= 0x00000008;
  959. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  960. }
  961. if(hw->mac_type <= e1000_82543 ||
  962. hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
  963. hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
  964. hw->phy_reset_disable = FALSE;
  965. return E1000_SUCCESS;
  966. }
  967. /********************************************************************
  968. * Copper link setup for e1000_phy_igp series.
  969. *
  970. * hw - Struct containing variables accessed by shared code
  971. *********************************************************************/
  972. static int32_t
  973. e1000_copper_link_igp_setup(struct e1000_hw *hw)
  974. {
  975. uint32_t led_ctrl;
  976. int32_t ret_val;
  977. uint16_t phy_data;
  978. DEBUGFUNC("e1000_copper_link_igp_setup");
  979. if (hw->phy_reset_disable)
  980. return E1000_SUCCESS;
  981. ret_val = e1000_phy_reset(hw);
  982. if (ret_val) {
  983. DEBUGOUT("Error Resetting the PHY\n");
  984. return ret_val;
  985. }
  986. /* Wait 10ms for MAC to configure PHY from eeprom settings */
  987. msec_delay(15);
  988. /* Configure activity LED after PHY reset */
  989. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  990. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  991. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  992. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  993. /* disable lplu d3 during driver init */
  994. ret_val = e1000_set_d3_lplu_state(hw, FALSE);
  995. if (ret_val) {
  996. DEBUGOUT("Error Disabling LPLU D3\n");
  997. return ret_val;
  998. }
  999. /* disable lplu d0 during driver init */
  1000. ret_val = e1000_set_d0_lplu_state(hw, FALSE);
  1001. if (ret_val) {
  1002. DEBUGOUT("Error Disabling LPLU D0\n");
  1003. return ret_val;
  1004. }
  1005. /* Configure mdi-mdix settings */
  1006. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  1007. if (ret_val)
  1008. return ret_val;
  1009. if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  1010. hw->dsp_config_state = e1000_dsp_config_disabled;
  1011. /* Force MDI for earlier revs of the IGP PHY */
  1012. phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
  1013. hw->mdix = 1;
  1014. } else {
  1015. hw->dsp_config_state = e1000_dsp_config_enabled;
  1016. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  1017. switch (hw->mdix) {
  1018. case 1:
  1019. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1020. break;
  1021. case 2:
  1022. phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1023. break;
  1024. case 0:
  1025. default:
  1026. phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
  1027. break;
  1028. }
  1029. }
  1030. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  1031. if(ret_val)
  1032. return ret_val;
  1033. /* set auto-master slave resolution settings */
  1034. if(hw->autoneg) {
  1035. e1000_ms_type phy_ms_setting = hw->master_slave;
  1036. if(hw->ffe_config_state == e1000_ffe_config_active)
  1037. hw->ffe_config_state = e1000_ffe_config_enabled;
  1038. if(hw->dsp_config_state == e1000_dsp_config_activated)
  1039. hw->dsp_config_state = e1000_dsp_config_enabled;
  1040. /* when autonegotiation advertisment is only 1000Mbps then we
  1041. * should disable SmartSpeed and enable Auto MasterSlave
  1042. * resolution as hardware default. */
  1043. if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
  1044. /* Disable SmartSpeed */
  1045. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  1046. if(ret_val)
  1047. return ret_val;
  1048. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1049. ret_val = e1000_write_phy_reg(hw,
  1050. IGP01E1000_PHY_PORT_CONFIG,
  1051. phy_data);
  1052. if(ret_val)
  1053. return ret_val;
  1054. /* Set auto Master/Slave resolution process */
  1055. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
  1056. if(ret_val)
  1057. return ret_val;
  1058. phy_data &= ~CR_1000T_MS_ENABLE;
  1059. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
  1060. if(ret_val)
  1061. return ret_val;
  1062. }
  1063. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
  1064. if(ret_val)
  1065. return ret_val;
  1066. /* load defaults for future use */
  1067. hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
  1068. ((phy_data & CR_1000T_MS_VALUE) ?
  1069. e1000_ms_force_master :
  1070. e1000_ms_force_slave) :
  1071. e1000_ms_auto;
  1072. switch (phy_ms_setting) {
  1073. case e1000_ms_force_master:
  1074. phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
  1075. break;
  1076. case e1000_ms_force_slave:
  1077. phy_data |= CR_1000T_MS_ENABLE;
  1078. phy_data &= ~(CR_1000T_MS_VALUE);
  1079. break;
  1080. case e1000_ms_auto:
  1081. phy_data &= ~CR_1000T_MS_ENABLE;
  1082. default:
  1083. break;
  1084. }
  1085. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
  1086. if(ret_val)
  1087. return ret_val;
  1088. }
  1089. return E1000_SUCCESS;
  1090. }
  1091. /********************************************************************
  1092. * Copper link setup for e1000_phy_m88 series.
  1093. *
  1094. * hw - Struct containing variables accessed by shared code
  1095. *********************************************************************/
  1096. static int32_t
  1097. e1000_copper_link_mgp_setup(struct e1000_hw *hw)
  1098. {
  1099. int32_t ret_val;
  1100. uint16_t phy_data;
  1101. DEBUGFUNC("e1000_copper_link_mgp_setup");
  1102. if(hw->phy_reset_disable)
  1103. return E1000_SUCCESS;
  1104. /* Enable CRS on TX. This must be set for half-duplex operation. */
  1105. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1106. if(ret_val)
  1107. return ret_val;
  1108. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  1109. /* Options:
  1110. * MDI/MDI-X = 0 (default)
  1111. * 0 - Auto for all speeds
  1112. * 1 - MDI mode
  1113. * 2 - MDI-X mode
  1114. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  1115. */
  1116. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  1117. switch (hw->mdix) {
  1118. case 1:
  1119. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  1120. break;
  1121. case 2:
  1122. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  1123. break;
  1124. case 3:
  1125. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  1126. break;
  1127. case 0:
  1128. default:
  1129. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  1130. break;
  1131. }
  1132. /* Options:
  1133. * disable_polarity_correction = 0 (default)
  1134. * Automatic Correction for Reversed Cable Polarity
  1135. * 0 - Disabled
  1136. * 1 - Enabled
  1137. */
  1138. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  1139. if(hw->disable_polarity_correction == 1)
  1140. phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
  1141. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1142. if(ret_val)
  1143. return ret_val;
  1144. /* Force TX_CLK in the Extended PHY Specific Control Register
  1145. * to 25MHz clock.
  1146. */
  1147. ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  1148. if(ret_val)
  1149. return ret_val;
  1150. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  1151. if (hw->phy_revision < M88E1011_I_REV_4) {
  1152. /* Configure Master and Slave downshift values */
  1153. phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
  1154. M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  1155. phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
  1156. M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  1157. ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  1158. if(ret_val)
  1159. return ret_val;
  1160. }
  1161. /* SW Reset the PHY so all changes take effect */
  1162. ret_val = e1000_phy_reset(hw);
  1163. if(ret_val) {
  1164. DEBUGOUT("Error Resetting the PHY\n");
  1165. return ret_val;
  1166. }
  1167. return E1000_SUCCESS;
  1168. }
  1169. /********************************************************************
  1170. * Setup auto-negotiation and flow control advertisements,
  1171. * and then perform auto-negotiation.
  1172. *
  1173. * hw - Struct containing variables accessed by shared code
  1174. *********************************************************************/
  1175. static int32_t
  1176. e1000_copper_link_autoneg(struct e1000_hw *hw)
  1177. {
  1178. int32_t ret_val;
  1179. uint16_t phy_data;
  1180. DEBUGFUNC("e1000_copper_link_autoneg");
  1181. /* Perform some bounds checking on the hw->autoneg_advertised
  1182. * parameter. If this variable is zero, then set it to the default.
  1183. */
  1184. hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
  1185. /* If autoneg_advertised is zero, we assume it was not defaulted
  1186. * by the calling code so we set to advertise full capability.
  1187. */
  1188. if(hw->autoneg_advertised == 0)
  1189. hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  1190. DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
  1191. ret_val = e1000_phy_setup_autoneg(hw);
  1192. if(ret_val) {
  1193. DEBUGOUT("Error Setting up Auto-Negotiation\n");
  1194. return ret_val;
  1195. }
  1196. DEBUGOUT("Restarting Auto-Neg\n");
  1197. /* Restart auto-negotiation by setting the Auto Neg Enable bit and
  1198. * the Auto Neg Restart bit in the PHY control register.
  1199. */
  1200. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
  1201. if(ret_val)
  1202. return ret_val;
  1203. phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
  1204. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
  1205. if(ret_val)
  1206. return ret_val;
  1207. /* Does the user want to wait for Auto-Neg to complete here, or
  1208. * check at a later time (for example, callback routine).
  1209. */
  1210. if(hw->wait_autoneg_complete) {
  1211. ret_val = e1000_wait_autoneg(hw);
  1212. if(ret_val) {
  1213. DEBUGOUT("Error while waiting for autoneg to complete\n");
  1214. return ret_val;
  1215. }
  1216. }
  1217. hw->get_link_status = TRUE;
  1218. return E1000_SUCCESS;
  1219. }
  1220. /******************************************************************************
  1221. * Config the MAC and the PHY after link is up.
  1222. * 1) Set up the MAC to the current PHY speed/duplex
  1223. * if we are on 82543. If we
  1224. * are on newer silicon, we only need to configure
  1225. * collision distance in the Transmit Control Register.
  1226. * 2) Set up flow control on the MAC to that established with
  1227. * the link partner.
  1228. * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
  1229. *
  1230. * hw - Struct containing va…

Large files files are truncated, but you can click here to view the full file