PageRenderTime 100ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 1ms

/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
  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 variables accessed by shared code
  1231. ******************************************************************************/
  1232. static int32_t
  1233. e1000_copper_link_postconfig(struct e1000_hw *hw)
  1234. {
  1235. int32_t ret_val;
  1236. DEBUGFUNC("e1000_copper_link_postconfig");
  1237. if(hw->mac_type >= e1000_82544) {
  1238. e1000_config_collision_dist(hw);
  1239. } else {
  1240. ret_val = e1000_config_mac_to_phy(hw);
  1241. if(ret_val) {
  1242. DEBUGOUT("Error configuring MAC to PHY settings\n");
  1243. return ret_val;
  1244. }
  1245. }
  1246. ret_val = e1000_config_fc_after_link_up(hw);
  1247. if(ret_val) {
  1248. DEBUGOUT("Error Configuring Flow Control\n");
  1249. return ret_val;
  1250. }
  1251. /* Config DSP to improve Giga link quality */
  1252. if(hw->phy_type == e1000_phy_igp) {
  1253. ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
  1254. if(ret_val) {
  1255. DEBUGOUT("Error Configuring DSP after link up\n");
  1256. return ret_val;
  1257. }
  1258. }
  1259. return E1000_SUCCESS;
  1260. }
  1261. /******************************************************************************
  1262. * Detects which PHY is present and setup the speed and duplex
  1263. *
  1264. * hw - Struct containing variables accessed by shared code
  1265. ******************************************************************************/
  1266. static int32_t
  1267. e1000_setup_copper_link(struct e1000_hw *hw)
  1268. {
  1269. int32_t ret_val;
  1270. uint16_t i;
  1271. uint16_t phy_data;
  1272. DEBUGFUNC("e1000_setup_copper_link");
  1273. /* Check if it is a valid PHY and set PHY mode if necessary. */
  1274. ret_val = e1000_copper_link_preconfig(hw);
  1275. if(ret_val)
  1276. return ret_val;
  1277. if (hw->phy_type == e1000_phy_igp ||
  1278. hw->phy_type == e1000_phy_igp_2) {
  1279. ret_val = e1000_copper_link_igp_setup(hw);
  1280. if(ret_val)
  1281. return ret_val;
  1282. } else if (hw->phy_type == e1000_phy_m88) {
  1283. ret_val = e1000_copper_link_mgp_setup(hw);
  1284. if(ret_val)
  1285. return ret_val;
  1286. }
  1287. if(hw->autoneg) {
  1288. /* Setup autoneg and flow control advertisement
  1289. * and perform autonegotiation */
  1290. ret_val = e1000_copper_link_autoneg(hw);
  1291. if(ret_val)
  1292. return ret_val;
  1293. } else {
  1294. /* PHY will be set to 10H, 10F, 100H,or 100F
  1295. * depending on value from forced_speed_duplex. */
  1296. DEBUGOUT("Forcing speed and duplex\n");
  1297. ret_val = e1000_phy_force_speed_duplex(hw);
  1298. if(ret_val) {
  1299. DEBUGOUT("Error Forcing Speed and Duplex\n");
  1300. return ret_val;
  1301. }
  1302. }
  1303. /* Check link status. Wait up to 100 microseconds for link to become
  1304. * valid.
  1305. */
  1306. for(i = 0; i < 10; i++) {
  1307. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  1308. if(ret_val)
  1309. return ret_val;
  1310. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  1311. if(ret_val)
  1312. return ret_val;
  1313. if(phy_data & MII_SR_LINK_STATUS) {
  1314. /* Config the MAC and PHY after link is up */
  1315. ret_val = e1000_copper_link_postconfig(hw);
  1316. if(ret_val)
  1317. return ret_val;
  1318. DEBUGOUT("Valid link established!!!\n");
  1319. return E1000_SUCCESS;
  1320. }
  1321. usec_delay(10);
  1322. }
  1323. DEBUGOUT("Unable to establish link!!!\n");
  1324. return E1000_SUCCESS;
  1325. }
  1326. /******************************************************************************
  1327. * Configures PHY autoneg and flow control advertisement settings
  1328. *
  1329. * hw - Struct containing variables accessed by shared code
  1330. ******************************************************************************/
  1331. int32_t
  1332. e1000_phy_setup_autoneg(struct e1000_hw *hw)
  1333. {
  1334. int32_t ret_val;
  1335. uint16_t mii_autoneg_adv_reg;
  1336. uint16_t mii_1000t_ctrl_reg;
  1337. DEBUGFUNC("e1000_phy_setup_autoneg");
  1338. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  1339. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
  1340. if(ret_val)
  1341. return ret_val;
  1342. /* Read the MII 1000Base-T Control Register (Address 9). */
  1343. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
  1344. if(ret_val)
  1345. return ret_val;
  1346. /* Need to parse both autoneg_advertised and fc and set up
  1347. * the appropriate PHY registers. First we will parse for
  1348. * autoneg_advertised software override. Since we can advertise
  1349. * a plethora of combinations, we need to check each bit
  1350. * individually.
  1351. */
  1352. /* First we clear all the 10/100 mb speed bits in the Auto-Neg
  1353. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  1354. * the 1000Base-T Control Register (Address 9).
  1355. */
  1356. mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
  1357. mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
  1358. DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
  1359. /* Do we want to advertise 10 Mb Half Duplex? */
  1360. if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
  1361. DEBUGOUT("Advertise 10mb Half duplex\n");
  1362. mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
  1363. }
  1364. /* Do we want to advertise 10 Mb Full Duplex? */
  1365. if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
  1366. DEBUGOUT("Advertise 10mb Full duplex\n");
  1367. mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
  1368. }
  1369. /* Do we want to advertise 100 Mb Half Duplex? */
  1370. if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
  1371. DEBUGOUT("Advertise 100mb Half duplex\n");
  1372. mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
  1373. }
  1374. /* Do we want to advertise 100 Mb Full Duplex? */
  1375. if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
  1376. DEBUGOUT("Advertise 100mb Full duplex\n");
  1377. mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
  1378. }
  1379. /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  1380. if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
  1381. DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
  1382. }
  1383. /* Do we want to advertise 1000 Mb Full Duplex? */
  1384. if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
  1385. DEBUGOUT("Advertise 1000mb Full duplex\n");
  1386. mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
  1387. }
  1388. /* Check for a software override of the flow control settings, and
  1389. * setup the PHY advertisement registers accordingly. If
  1390. * auto-negotiation is enabled, then software will have to set the
  1391. * "PAUSE" bits to the correct value in the Auto-Negotiation
  1392. * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
  1393. *
  1394. * The possible values of the "fc" parameter are:
  1395. * 0: Flow control is completely disabled
  1396. * 1: Rx flow control is enabled (we can receive pause frames
  1397. * but not send pause frames).
  1398. * 2: Tx flow control is enabled (we can send pause frames
  1399. * but we do not support receiving pause frames).
  1400. * 3: Both Rx and TX flow control (symmetric) are enabled.
  1401. * other: No software override. The flow control configuration
  1402. * in the EEPROM is used.
  1403. */
  1404. switch (hw->fc) {
  1405. case e1000_fc_none: /* 0 */
  1406. /* Flow control (RX & TX) is completely disabled by a
  1407. * software over-ride.
  1408. */
  1409. mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1410. break;
  1411. case e1000_fc_rx_pause: /* 1 */
  1412. /* RX Flow control is enabled, and TX Flow control is
  1413. * disabled, by a software over-ride.
  1414. */
  1415. /* Since there really isn't a way to advertise that we are
  1416. * capable of RX Pause ONLY, we will advertise that we
  1417. * support both symmetric and asymmetric RX PAUSE. Later
  1418. * (in e1000_config_fc_after_link_up) we will disable the
  1419. *hw's ability to send PAUSE frames.
  1420. */
  1421. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1422. break;
  1423. case e1000_fc_tx_pause: /* 2 */
  1424. /* TX Flow control is enabled, and RX Flow control is
  1425. * disabled, by a software over-ride.
  1426. */
  1427. mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
  1428. mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
  1429. break;
  1430. case e1000_fc_full: /* 3 */
  1431. /* Flow control (both RX and TX) is enabled by a software
  1432. * over-ride.
  1433. */
  1434. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1435. break;
  1436. default:
  1437. DEBUGOUT("Flow control param set incorrectly\n");
  1438. return -E1000_ERR_CONFIG;
  1439. }
  1440. ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
  1441. if(ret_val)
  1442. return ret_val;
  1443. DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  1444. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
  1445. if(ret_val)
  1446. return ret_val;
  1447. return E1000_SUCCESS;
  1448. }
  1449. /******************************************************************************
  1450. * Force PHY speed and duplex settings to hw->forced_speed_duplex
  1451. *
  1452. * hw - Struct containing variables accessed by shared code
  1453. ******************************************************************************/
  1454. static int32_t
  1455. e1000_phy_force_speed_duplex(struct e1000_hw *hw)
  1456. {
  1457. uint32_t ctrl;
  1458. int32_t ret_val;
  1459. uint16_t mii_ctrl_reg;
  1460. uint16_t mii_status_reg;
  1461. uint16_t phy_data;
  1462. uint16_t i;
  1463. DEBUGFUNC("e1000_phy_force_speed_duplex");
  1464. /* Turn off Flow control if we are forcing speed and duplex. */
  1465. hw->fc = e1000_fc_none;
  1466. DEBUGOUT1("hw->fc = %d\n", hw->fc);
  1467. /* Read the Device Control Register. */
  1468. ctrl = E1000_READ_REG(hw, CTRL);
  1469. /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
  1470. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1471. ctrl &= ~(DEVICE_SPEED_MASK);
  1472. /* Clear the Auto Speed Detect Enable bit. */
  1473. ctrl &= ~E1000_CTRL_ASDE;
  1474. /* Read the MII Control Register. */
  1475. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
  1476. if(ret_val)
  1477. return ret_val;
  1478. /* We need to disable autoneg in order to force link and duplex. */
  1479. mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
  1480. /* Are we forcing Full or Half Duplex? */
  1481. if(hw->forced_speed_duplex == e1000_100_full ||
  1482. hw->forced_speed_duplex == e1000_10_full) {
  1483. /* We want to force full duplex so we SET the full duplex bits in the
  1484. * Device and MII Control Registers.
  1485. */
  1486. ctrl |= E1000_CTRL_FD;
  1487. mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
  1488. DEBUGOUT("Full Duplex\n");
  1489. } else {
  1490. /* We want to force half duplex so we CLEAR the full duplex bits in
  1491. * the Device and MII Control Registers.
  1492. */
  1493. ctrl &= ~E1000_CTRL_FD;
  1494. mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
  1495. DEBUGOUT("Half Duplex\n");
  1496. }
  1497. /* Are we forcing 100Mbps??? */
  1498. if(hw->forced_speed_duplex == e1000_100_full ||
  1499. hw->forced_speed_duplex == e1000_100_half) {
  1500. /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
  1501. ctrl |= E1000_CTRL_SPD_100;
  1502. mii_ctrl_reg |= MII_CR_SPEED_100;
  1503. mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
  1504. DEBUGOUT("Forcing 100mb ");
  1505. } else {
  1506. /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
  1507. ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  1508. mii_ctrl_reg |= MII_CR_SPEED_10;
  1509. mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
  1510. DEBUGOUT("Forcing 10mb ");
  1511. }
  1512. e1000_config_collision_dist(hw);
  1513. /* Write the configured values back to the Device Control Reg. */
  1514. E1000_WRITE_REG(hw, CTRL, ctrl);
  1515. if (hw->phy_type == e1000_phy_m88) {
  1516. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1517. if(ret_val)
  1518. return ret_val;
  1519. /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
  1520. * forced whenever speed are duplex are forced.
  1521. */
  1522. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  1523. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1524. if(ret_val)
  1525. return ret_val;
  1526. DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
  1527. /* Need to reset the PHY or these changes will be ignored */
  1528. mii_ctrl_reg |= MII_CR_RESET;
  1529. } else {
  1530. /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
  1531. * forced whenever speed or duplex are forced.
  1532. */
  1533. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  1534. if(ret_val)
  1535. return ret_val;
  1536. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  1537. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1538. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  1539. if(ret_val)
  1540. return ret_val;
  1541. }
  1542. /* Write back the modified PHY MII control register. */
  1543. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
  1544. if(ret_val)
  1545. return ret_val;
  1546. usec_delay(1);
  1547. /* The wait_autoneg_complete flag may be a little misleading here.
  1548. * Since we are forcing speed and duplex, Auto-Neg is not enabled.
  1549. * But we do want to delay for a period while forcing only so we
  1550. * don't generate false No Link messages. So we will wait here
  1551. * only if the user has set wait_autoneg_complete to 1, which is
  1552. * the default.
  1553. */
  1554. if(hw->wait_autoneg_complete) {
  1555. /* We will wait for autoneg to complete. */
  1556. DEBUGOUT("Waiting for forced speed/duplex link.\n");
  1557. mii_status_reg = 0;
  1558. /* We will wait for autoneg to complete or 4.5 seconds to expire. */
  1559. for(i = PHY_FORCE_TIME; i > 0; i--) {
  1560. /* Read the MII Status Register and wait for Auto-Neg Complete bit
  1561. * to be set.
  1562. */
  1563. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1564. if(ret_val)
  1565. return ret_val;
  1566. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1567. if(ret_val)
  1568. return ret_val;
  1569. if(mii_status_reg & MII_SR_LINK_STATUS) break;
  1570. msec_delay(100);
  1571. }
  1572. if((i == 0) &&
  1573. (hw->phy_type == e1000_phy_m88)) {
  1574. /* We didn't get link. Reset the DSP and wait again for link. */
  1575. ret_val = e1000_phy_reset_dsp(hw);
  1576. if(ret_val) {
  1577. DEBUGOUT("Error Resetting PHY DSP\n");
  1578. return ret_val;
  1579. }
  1580. }
  1581. /* This loop will early-out if the link condition has been met. */
  1582. for(i = PHY_FORCE_TIME; i > 0; i--) {
  1583. if(mii_status_reg & MII_SR_LINK_STATUS) break;
  1584. msec_delay(100);
  1585. /* Read the MII Status Register and wait for Auto-Neg Complete bit
  1586. * to be set.
  1587. */
  1588. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1589. if(ret_val)
  1590. return ret_val;
  1591. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1592. if(ret_val)
  1593. return ret_val;
  1594. }
  1595. }
  1596. if (hw->phy_type == e1000_phy_m88) {
  1597. /* Because we reset the PHY above, we need to re-force TX_CLK in the
  1598. * Extended PHY Specific Control Register to 25MHz clock. This value
  1599. * defaults back to a 2.5MHz clock when the PHY is reset.
  1600. */
  1601. ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  1602. if(ret_val)
  1603. return ret_val;
  1604. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  1605. ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  1606. if(ret_val)
  1607. return ret_val;
  1608. /* In addition, because of the s/w reset above, we need to enable CRS on
  1609. * TX. This must be set for both full and half duplex operation.
  1610. */
  1611. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1612. if(ret_val)
  1613. return ret_val;
  1614. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  1615. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1616. if(ret_val)
  1617. return ret_val;
  1618. if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
  1619. (!hw->autoneg) &&
  1620. (hw->forced_speed_duplex == e1000_10_full ||
  1621. hw->forced_speed_duplex == e1000_10_half)) {
  1622. ret_val = e1000_polarity_reversal_workaround(hw);
  1623. if(ret_val)
  1624. return ret_val;
  1625. }
  1626. }
  1627. return E1000_SUCCESS;
  1628. }
  1629. /******************************************************************************
  1630. * Sets the collision distance in the Transmit Control register
  1631. *
  1632. * hw - Struct containing variables accessed by shared code
  1633. *
  1634. * Link should have been established previously. Reads the speed and duplex
  1635. * information from the Device Status register.
  1636. ******************************************************************************/
  1637. void
  1638. e1000_config_collision_dist(struct e1000_hw *hw)
  1639. {
  1640. uint32_t tctl;
  1641. DEBUGFUNC("e1000_config_collision_dist");
  1642. tctl = E1000_READ_REG(hw, TCTL);
  1643. tctl &= ~E1000_TCTL_COLD;
  1644. tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
  1645. E1000_WRITE_REG(hw, TCTL, tctl);
  1646. E1000_WRITE_FLUSH(hw);
  1647. }
  1648. /******************************************************************************
  1649. * Sets MAC speed and duplex settings to reflect the those in the PHY
  1650. *
  1651. * hw - Struct containing variables accessed by shared code
  1652. * mii_reg - data to write to the MII control register
  1653. *
  1654. * The contents of the PHY register containing the needed information need to
  1655. * be passed in.
  1656. ******************************************************************************/
  1657. static int32_t
  1658. e1000_config_mac_to_phy(struct e1000_hw *hw)
  1659. {
  1660. uint32_t ctrl;
  1661. int32_t ret_val;
  1662. uint16_t phy_data;
  1663. DEBUGFUNC("e1000_config_mac_to_phy");
  1664. /* 82544 or newer MAC, Auto Speed Detection takes care of
  1665. * MAC speed/duplex configuration.*/
  1666. if (hw->mac_type >= e1000_82544)
  1667. return E1000_SUCCESS;
  1668. /* Read the Device Control Register and set the bits to Force Speed
  1669. * and Duplex.
  1670. */
  1671. ctrl = E1000_READ_REG(hw, CTRL);
  1672. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1673. ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
  1674. /* Set up duplex in the Device Control and Transmit Control
  1675. * registers depending on negotiated values.
  1676. */
  1677. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  1678. if(ret_val)
  1679. return ret_val;
  1680. if(phy_data & M88E1000_PSSR_DPLX)
  1681. ctrl |= E1000_CTRL_FD;
  1682. else
  1683. ctrl &= ~E1000_CTRL_FD;
  1684. e1000_config_collision_dist(hw);
  1685. /* Set up speed in the Device Control register depending on
  1686. * negotiated values.
  1687. */
  1688. if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
  1689. ctrl |= E1000_CTRL_SPD_1000;
  1690. else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
  1691. ctrl |= E1000_CTRL_SPD_100;
  1692. /* Write the configured values back to the Device Control Reg. */
  1693. E1000_WRITE_REG(hw, CTRL, ctrl);
  1694. return E1000_SUCCESS;
  1695. }
  1696. /******************************************************************************
  1697. * Forces the MAC's flow control settings.
  1698. *
  1699. * hw - Struct containing variables accessed by shared code
  1700. *
  1701. * Sets the TFCE and RFCE bits in the device control register to reflect
  1702. * the adapter settings. TFCE and RFCE need to be explicitly set by
  1703. * software when a Copper PHY is used because autonegotiation is managed
  1704. * by the PHY rather than the MAC. Software must also configure these
  1705. * bits when link is forced on a fiber connection.
  1706. *****************************************************************************/
  1707. int32_t
  1708. e1000_force_mac_fc(struct e1000_hw *hw)
  1709. {
  1710. uint32_t ctrl;
  1711. DEBUGFUNC("e1000_force_mac_fc");
  1712. /* Get the current configuration of the Device Control Register */
  1713. ctrl = E1000_READ_REG(hw, CTRL);
  1714. /* Because we didn't get link via the internal auto-negotiation
  1715. * mechanism (we either forced link or we got link via PHY
  1716. * auto-neg), we have to manually enable/disable transmit an
  1717. * receive flow control.
  1718. *
  1719. * The "Case" statement below enables/disable flow control
  1720. * according to the "hw->fc" parameter.
  1721. *
  1722. * The possible values of the "fc" parameter are:
  1723. * 0: Flow control is completely disabled
  1724. * 1: Rx flow control is enabled (we can receive pause
  1725. * frames but not send pause frames).
  1726. * 2: Tx flow control is enabled (we can send pause frames
  1727. * frames but we do not receive pause frames).
  1728. * 3: Both Rx and TX flow control (symmetric) is enabled.
  1729. * other: No other values should be possible at this point.
  1730. */
  1731. switch (hw->fc) {
  1732. case e1000_fc_none:
  1733. ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
  1734. break;
  1735. case e1000_fc_rx_pause:
  1736. ctrl &= (~E1000_CTRL_TFCE);
  1737. ctrl |= E1000_CTRL_RFCE;
  1738. break;
  1739. case e1000_fc_tx_pause:
  1740. ctrl &= (~E1000_CTRL_RFCE);
  1741. ctrl |= E1000_CTRL_TFCE;
  1742. break;
  1743. case e1000_fc_full:
  1744. ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
  1745. break;
  1746. default:
  1747. DEBUGOUT("Flow control param set incorrectly\n");
  1748. return -E1000_ERR_CONFIG;
  1749. }
  1750. /* Disable TX Flow Control for 82542 (rev 2.0) */
  1751. if(hw->mac_type == e1000_82542_rev2_0)
  1752. ctrl &= (~E1000_CTRL_TFCE);
  1753. E1000_WRITE_REG(hw, CTRL, ctrl);
  1754. return E1000_SUCCESS;
  1755. }
  1756. /******************************************************************************
  1757. * Configures flow control settings after link is established
  1758. *
  1759. * hw - Struct containing variables accessed by shared code
  1760. *
  1761. * Should be called immediately after a valid link has been established.
  1762. * Forces MAC flow control settings if link was forced. When in MII/GMII mode
  1763. * and autonegotiation is enabled, the MAC flow control settings will be set
  1764. * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
  1765. * and RFCE bits will be automaticaly set to the negotiated flow control mode.
  1766. *****************************************************************************/
  1767. int32_t
  1768. e1000_config_fc_after_link_up(struct e1000_hw *hw)
  1769. {
  1770. int32_t ret_val;
  1771. uint16_t mii_status_reg;
  1772. uint16_t mii_nway_adv_reg;
  1773. uint16_t mii_nway_lp_ability_reg;
  1774. uint16_t speed;
  1775. uint16_t duplex;
  1776. DEBUGFUNC("e1000_config_fc_after_link_up");
  1777. /* Check for the case where we have fiber media and auto-neg failed
  1778. * so we had to force link. In this case, we need to force the
  1779. * configuration of the MAC to match the "fc" parameter.
  1780. */
  1781. if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
  1782. ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
  1783. ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
  1784. ret_val = e1000_force_mac_fc(hw);
  1785. if(ret_val) {
  1786. DEBUGOUT("Error forcing flow control settings\n");
  1787. return ret_val;
  1788. }
  1789. }
  1790. /* Check for the case where we have copper media and auto-neg is
  1791. * enabled. In this case, we need to check and see if Auto-Neg
  1792. * has completed, and if so, how the PHY and link partner has
  1793. * flow control configured.
  1794. */
  1795. if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
  1796. /* Read the MII Status Register and check to see if AutoNeg
  1797. * has completed. We read this twice because this reg has
  1798. * some "sticky" (latched) bits.
  1799. */
  1800. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1801. if(ret_val)
  1802. return ret_val;
  1803. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1804. if(ret_val)
  1805. return ret_val;
  1806. if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
  1807. /* The AutoNeg process has completed, so we now need to
  1808. * read both the Auto Negotiation Advertisement Register
  1809. * (Address 4) and the Auto_Negotiation Base Page Ability
  1810. * Register (Address 5) to determine how flow control was
  1811. * negotiated.
  1812. */
  1813. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
  1814. &mii_nway_adv_reg);
  1815. if(ret_val)
  1816. return ret_val;
  1817. ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
  1818. &mii_nway_lp_ability_reg);
  1819. if(ret_val)
  1820. return ret_val;
  1821. /* Two bits in the Auto Negotiation Advertisement Register
  1822. * (Address 4) and two bits in the Auto Negotiation Base
  1823. * Page Ability Register (Address 5) determine flow control
  1824. * for both the PHY and the link partner. The following
  1825. * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
  1826. * 1999, describes these PAUSE resolution bits and how flow
  1827. * control is determined based upon these settings.
  1828. * NOTE: DC = Don't Care
  1829. *
  1830. * LOCAL DEVICE | LINK PARTNER
  1831. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  1832. *-------|---------|-------|---------|--------------------
  1833. * 0 | 0 | DC | DC | e1000_fc_none
  1834. * 0 | 1 | 0 | DC | e1000_fc_none
  1835. * 0 | 1 | 1 | 0 | e1000_fc_none
  1836. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  1837. * 1 | 0 | 0 | DC | e1000_fc_none
  1838. * 1 | DC | 1 | DC | e1000_fc_full
  1839. * 1 | 1 | 0 | 0 | e1000_fc_none
  1840. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  1841. *
  1842. */
  1843. /* Are both PAUSE bits set to 1? If so, this implies
  1844. * Symmetric Flow Control is enabled at both ends. The
  1845. * ASM_DIR bits are irrelevant per the spec.
  1846. *
  1847. * For Symmetric Flow Control:
  1848. *
  1849. * LOCAL DEVICE | LINK PARTNER
  1850. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1851. *-------|---------|-------|---------|--------------------
  1852. * 1 | DC | 1 | DC | e1000_fc_full
  1853. *
  1854. */
  1855. if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1856. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
  1857. /* Now we need to check if the user selected RX ONLY
  1858. * of pause frames. In this case, we had to advertise
  1859. * FULL flow control because we could not advertise RX
  1860. * ONLY. Hence, we must now check to see if we need to
  1861. * turn OFF the TRANSMISSION of PAUSE frames.
  1862. */
  1863. if(hw->original_fc == e1000_fc_full) {
  1864. hw->fc = e1000_fc_full;
  1865. DEBUGOUT("Flow Control = FULL.\r\n");
  1866. } else {
  1867. hw->fc = e1000_fc_rx_pause;
  1868. DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
  1869. }
  1870. }
  1871. /* For receiving PAUSE frames ONLY.
  1872. *
  1873. * LOCAL DEVICE | LINK PARTNER
  1874. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1875. *-------|---------|-------|---------|--------------------
  1876. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  1877. *
  1878. */
  1879. else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1880. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  1881. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  1882. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  1883. hw->fc = e1000_fc_tx_pause;
  1884. DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
  1885. }
  1886. /* For transmitting PAUSE frames ONLY.
  1887. *
  1888. * LOCAL DEVICE | LINK PARTNER
  1889. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1890. *-------|---------|-------|---------|--------------------
  1891. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  1892. *
  1893. */
  1894. else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1895. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  1896. !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  1897. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  1898. hw->fc = e1000_fc_rx_pause;
  1899. DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
  1900. }
  1901. /* Per the IEEE spec, at this point flow control should be
  1902. * disabled. However, we want to consider that we could
  1903. * be connected to a legacy switch that doesn't advertise
  1904. * desired flow control, but can be forced on the link
  1905. * partner. So if we advertised no flow control, that is
  1906. * what we will resolve to. If we advertised some kind of
  1907. * receive capability (Rx Pause Only or Full Flow Control)
  1908. * and the link partner advertised none, we will configure
  1909. * ourselves to enable Rx Flow Control only. We can do
  1910. * this safely for two reasons: If the link partner really
  1911. * didn't want flow control enabled, and we enable Rx, no
  1912. * harm done since we won't be receiving any PAUSE frames
  1913. * anyway. If the intent on the link partner was to have
  1914. * flow control enabled, then by us enabling RX only, we
  1915. * can at least receive pause frames and process them.
  1916. * This is a good idea because in most cases, since we are
  1917. * predominantly a server NIC, more times than not we will
  1918. * be asked to delay transmission of packets than asking
  1919. * our link partner to pause transmission of frames.
  1920. */
  1921. else if((hw->original_fc == e1000_fc_none ||
  1922. hw->original_fc == e1000_fc_tx_pause) ||
  1923. hw->fc_strict_ieee) {
  1924. hw->fc = e1000_fc_none;
  1925. DEBUGOUT("Flow Control = NONE.\r\n");
  1926. } else {
  1927. hw->fc = e1000_fc_rx_pause;
  1928. DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
  1929. }
  1930. /* Now we need to do one last check... If we auto-
  1931. * negotiated to HALF DUPLEX, flow control should not be
  1932. * enabled per IEEE 802.3 spec.
  1933. */
  1934. ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
  1935. if(ret_val) {
  1936. DEBUGOUT("Error getting link speed and duplex\n");
  1937. return ret_val;
  1938. }
  1939. if(duplex == HALF_DUPLEX)
  1940. hw->fc = e1000_fc_none;
  1941. /* Now we call a subroutine to actually force the MAC
  1942. * controller to use the correct flow control settings.
  1943. */
  1944. ret_val = e1000_force_mac_fc(hw);
  1945. if(ret_val) {
  1946. DEBUGOUT("Error forcing flow control settings\n");
  1947. return ret_val;
  1948. }
  1949. } else {
  1950. DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
  1951. }
  1952. }
  1953. return E1000_SUCCESS;
  1954. }
  1955. /******************************************************************************
  1956. * Checks to see if the link status of the hardware has changed.
  1957. *
  1958. * hw - Struct containing variables accessed by shared code
  1959. *
  1960. * Called by any function that needs to check the link status of the adapter.
  1961. *****************************************************************************/
  1962. int32_t
  1963. e1000_check_for_link(struct e1000_hw *hw)
  1964. {
  1965. uint32_t rxcw = 0;
  1966. uint32_t ctrl;
  1967. uint32_t status;
  1968. uint32_t rctl;
  1969. uint32_t icr;
  1970. uint32_t signal = 0;
  1971. int32_t ret_val;
  1972. uint16_t phy_data;
  1973. DEBUGFUNC("e1000_check_for_link");
  1974. ctrl = E1000_READ_REG(hw, CTRL);
  1975. status = E1000_READ_REG(hw, STATUS);
  1976. /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
  1977. * set when the optics detect a signal. On older adapters, it will be
  1978. * cleared when there is a signal. This applies to fiber media only.
  1979. */
  1980. if((hw->media_type == e1000_media_type_fiber) ||
  1981. (hw->media_type == e1000_media_type_internal_serdes)) {
  1982. rxcw = E1000_READ_REG(hw, RXCW);
  1983. if(hw->media_type == e1000_media_type_fiber) {
  1984. signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
  1985. if(status & E1000_STATUS_LU)
  1986. hw->get_link_status = FALSE;
  1987. }
  1988. }
  1989. /* If we have a copper PHY then we only want to go out to the PHY
  1990. * registers to see if Auto-Neg has completed and/or if our link
  1991. * status has changed. The get_link_status flag will be set if we
  1992. * receive a Link Status Change interrupt or we have Rx Sequence
  1993. * Errors.
  1994. */
  1995. if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
  1996. /* First we want to see if the MII Status Register reports
  1997. * link. If so, then we want to get the current speed/duplex
  1998. * of the PHY.
  1999. * Read the register twice since the link bit is sticky.
  2000. */
  2001. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2002. if(ret_val)
  2003. return ret_val;
  2004. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2005. if(ret_val)
  2006. return ret_val;
  2007. if(phy_data & MII_SR_LINK_STATUS) {
  2008. hw->get_link_status = FALSE;
  2009. /* Check if there was DownShift, must be checked immediately after
  2010. * link-up */
  2011. e1000_check_downshift(hw);
  2012. /* If we are on 82544 or 82543 silicon and speed/duplex
  2013. * are forced to 10H or 10F, then we will implement the polarity
  2014. * reversal workaround. We disable interrupts first, and upon
  2015. * returning, place the devices interrupt state to its previous
  2016. * value except for the link status change interrupt which will
  2017. * happen due to the execution of this workaround.
  2018. */
  2019. if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
  2020. (!hw->autoneg) &&
  2021. (hw->forced_speed_duplex == e1000_10_full ||
  2022. hw->forced_speed_duplex == e1000_10_half)) {
  2023. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  2024. ret_val = e1000_polarity_reversal_workaround(hw);
  2025. icr = E1000_READ_REG(hw, ICR);
  2026. E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
  2027. E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
  2028. }
  2029. } else {
  2030. /* No link detected */
  2031. e1000_config_dsp_after_link_change(hw, FALSE);
  2032. return 0;
  2033. }
  2034. /* If we are forcing speed/duplex, then we simply return since
  2035. * we have already determined whether we have link or not.
  2036. */
  2037. if(!hw->autoneg) return -E1000_ERR_CONFIG;
  2038. /* optimize the dsp settings for the igp phy */
  2039. e1000_config_dsp_after_link_change(hw, TRUE);
  2040. /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
  2041. * have Si on board that is 82544 or newer, Auto
  2042. * Speed Detection takes care of MAC speed/duplex
  2043. * configuration. So we only need to configure Collision
  2044. * Distance in the MAC. Otherwise, we need to force
  2045. * speed/duplex on the MAC to the current PHY speed/duplex
  2046. * settings.
  2047. */
  2048. if(hw->mac_type >= e1000_82544)
  2049. e1000_config_collision_dist(hw);
  2050. else {
  2051. ret_val = e1000_config_mac_to_phy(hw);
  2052. if(ret_val) {
  2053. DEBUGOUT("Error configuring MAC to PHY settings\n");
  2054. return ret_val;
  2055. }
  2056. }
  2057. /* Configure Flow Control now that Auto-Neg has completed. First, we
  2058. * need to restore the desired flow control settings because we may
  2059. * have had to re-autoneg with a different link partner.
  2060. */
  2061. ret_val = e1000_config_fc_after_link_up(hw);
  2062. if(ret_val) {
  2063. DEBUGOUT("Error configuring flow control\n");
  2064. return ret_val;
  2065. }
  2066. /* At this point we know that we are on copper and we have
  2067. * auto-negotiated link. These are conditions for checking the link
  2068. * partner capability register. We use the link speed to determine if
  2069. * TBI compatibility needs to be turned on or off. If the link is not
  2070. * at gigabit speed, then TBI compatibility is not needed. If we are
  2071. * at gigabit speed, we turn on TBI compatibility.
  2072. */
  2073. if(hw->tbi_compatibility_en) {
  2074. uint16_t speed, duplex;
  2075. e1000_get_speed_and_duplex(hw, &speed, &duplex);
  2076. if(speed != SPEED_1000) {
  2077. /* If link speed is not set to gigabit speed, we do not need
  2078. * to enable TBI compatibility.
  2079. */
  2080. if(hw->tbi_compatibility_on) {
  2081. /* If we previously were in the mode, turn it off. */
  2082. rctl = E1000_READ_REG(hw, RCTL);
  2083. rctl &= ~E1000_RCTL_SBP;
  2084. E1000_WRITE_REG(hw, RCTL, rctl);
  2085. hw->tbi_compatibility_on = FALSE;
  2086. }
  2087. } else {
  2088. /* If TBI compatibility is was previously off, turn it on. For
  2089. * compatibility with a TBI link partner, we will store bad
  2090. * packets. Some frames have an additional byte on the end and
  2091. * will look like CRC errors to to the hardware.
  2092. */
  2093. if(!hw->tbi_compatibility_on) {
  2094. hw->tbi_compatibility_on = TRUE;
  2095. rctl = E1000_READ_REG(hw, RCTL);
  2096. rctl |= E1000_RCTL_SBP;
  2097. E1000_WRITE_REG(hw, RCTL, rctl);
  2098. }
  2099. }
  2100. }
  2101. }
  2102. /* If we don't have link (auto-negotiation failed or link partner cannot
  2103. * auto-negotiate), the cable is plugged in (we have signal), and our
  2104. * link partner is not trying to auto-negotiate with us (we are receiving
  2105. * idles or data), we need to force link up. We also need to give
  2106. * auto-negotiation time to complete, in case the cable was just plugged
  2107. * in. The autoneg_failed flag does this.
  2108. */
  2109. else if((((hw->media_type == e1000_media_type_fiber) &&
  2110. ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
  2111. (hw->media_type == e1000_media_type_internal_serdes)) &&
  2112. (!(status & E1000_STATUS_LU)) &&
  2113. (!(rxcw & E1000_RXCW_C))) {
  2114. if(hw->autoneg_failed == 0) {
  2115. hw->autoneg_failed = 1;
  2116. return 0;
  2117. }
  2118. DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
  2119. /* Disable auto-negotiation in the TXCW register */
  2120. E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
  2121. /* Force link-up and also force full-duplex. */
  2122. ctrl = E1000_READ_REG(hw, CTRL);
  2123. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  2124. E1000_WRITE_REG(hw, CTRL, ctrl);
  2125. /* Configure Flow Control after forcing link up. */
  2126. ret_val = e1000_config_fc_after_link_up(hw);
  2127. if(ret_val) {
  2128. DEBUGOUT("Error configuring flow control\n");
  2129. return ret_val;
  2130. }
  2131. }
  2132. /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
  2133. * auto-negotiation in the TXCW register and disable forced link in the
  2134. * Device Control register in an attempt to auto-negotiate with our link
  2135. * partner.
  2136. */
  2137. else if(((hw->media_type == e1000_media_type_fiber) ||
  2138. (hw->media_type == e1000_media_type_internal_serdes)) &&
  2139. (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
  2140. DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
  2141. E1000_WRITE_REG(hw, TXCW, hw->txcw);
  2142. E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
  2143. hw->serdes_link_down = FALSE;
  2144. }
  2145. /* If we force link for non-auto-negotiation switch, check link status
  2146. * based on MAC synchronization for internal serdes media type.
  2147. */
  2148. else if((hw->media_type == e1000_media_type_internal_serdes) &&
  2149. !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
  2150. /* SYNCH bit and IV bit are sticky. */
  2151. usec_delay(10);
  2152. if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
  2153. if(!(rxcw & E1000_RXCW_IV)) {
  2154. hw->serdes_link_down = FALSE;
  2155. DEBUGOUT("SERDES: Link is up.\n");
  2156. }
  2157. } else {
  2158. hw->serdes_link_down = TRUE;
  2159. DEBUGOUT("SERDES: Link is down.\n");
  2160. }
  2161. }
  2162. if((hw->media_type == e1000_media_type_internal_serdes) &&
  2163. (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
  2164. hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
  2165. }
  2166. return E1000_SUCCESS;
  2167. }
  2168. /******************************************************************************
  2169. * Detects the current speed and duplex settings of the hardware.
  2170. *
  2171. * hw - Struct containing variables accessed by shared code
  2172. * speed - Speed of the connection
  2173. * duplex - Duplex setting of the connection
  2174. *****************************************************************************/
  2175. int32_t
  2176. e1000_get_speed_and_duplex(struct e1000_hw *hw,
  2177. uint16_t *speed,
  2178. uint16_t *duplex)
  2179. {
  2180. uint32_t status;
  2181. int32_t ret_val;
  2182. uint16_t phy_data;
  2183. DEBUGFUNC("e1000_get_speed_and_duplex");
  2184. if(hw->mac_type >= e1000_82543) {
  2185. status = E1000_READ_REG(hw, STATUS);
  2186. if(status & E1000_STATUS_SPEED_1000) {
  2187. *speed = SPEED_1000;
  2188. DEBUGOUT("1000 Mbs, ");
  2189. } else if(status & E1000_STATUS_SPEED_100) {
  2190. *speed = SPEED_100;
  2191. DEBUGOUT("100 Mbs, ");
  2192. } else {
  2193. *speed = SPEED_10;
  2194. DEBUGOUT("10 Mbs, ");
  2195. }
  2196. if(status & E1000_STATUS_FD) {
  2197. *duplex = FULL_DUPLEX;
  2198. DEBUGOUT("Full Duplex\r\n");
  2199. } else {
  2200. *duplex = HALF_DUPLEX;
  2201. DEBUGOUT(" Half Duplex\r\n");
  2202. }
  2203. } else {
  2204. DEBUGOUT("1000 Mbs, Full Duplex\r\n");
  2205. *speed = SPEED_1000;
  2206. *duplex = FULL_DUPLEX;
  2207. }
  2208. /* IGP01 PHY may advertise full duplex operation after speed downgrade even
  2209. * if it is operating at half duplex. Here we set the duplex settings to
  2210. * match the duplex in the link partner's capabilities.
  2211. */
  2212. if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
  2213. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
  2214. if(ret_val)
  2215. return ret_val;
  2216. if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
  2217. *duplex = HALF_DUPLEX;
  2218. else {
  2219. ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
  2220. if(ret_val)
  2221. return ret_val;
  2222. if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
  2223. (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
  2224. *duplex = HALF_DUPLEX;
  2225. }
  2226. }
  2227. return E1000_SUCCESS;
  2228. }
  2229. /******************************************************************************
  2230. * Blocks until autoneg completes or times out (~4.5 seconds)
  2231. *
  2232. * hw - Struct containing variables accessed by shared code
  2233. ******************************************************************************/
  2234. int32_t
  2235. e1000_wait_autoneg(struct e1000_hw *hw)
  2236. {
  2237. int32_t ret_val;
  2238. uint16_t i;
  2239. uint16_t phy_data;
  2240. DEBUGFUNC("e1000_wait_autoneg");
  2241. DEBUGOUT("Waiting for Auto-Neg to complete.\n");
  2242. /* We will wait for autoneg to complete or 4.5 seconds to expire. */
  2243. for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
  2244. /* Read the MII Status Register and wait for Auto-Neg
  2245. * Complete bit to be set.
  2246. */
  2247. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2248. if(ret_val)
  2249. return ret_val;
  2250. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2251. if(ret_val)
  2252. return ret_val;
  2253. if(phy_data & MII_SR_AUTONEG_COMPLETE) {
  2254. return E1000_SUCCESS;
  2255. }
  2256. msec_delay(100);
  2257. }
  2258. return E1000_SUCCESS;
  2259. }
  2260. /******************************************************************************
  2261. * Raises the Management Data Clock
  2262. *
  2263. * hw - Struct containing variables accessed by shared code
  2264. * ctrl - Device control register's current value
  2265. ******************************************************************************/
  2266. static void
  2267. e1000_raise_mdi_clk(struct e1000_hw *hw,
  2268. uint32_t *ctrl)
  2269. {
  2270. /* Raise the clock input to the Management Data Clock (by setting the MDC
  2271. * bit), and then delay 10 microseconds.
  2272. */
  2273. E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
  2274. E1000_WRITE_FLUSH(hw);
  2275. usec_delay(10);
  2276. }
  2277. /******************************************************************************
  2278. * Lowers the Management Data Clock
  2279. *
  2280. * hw - Struct containing variables accessed by shared code
  2281. * ctrl - Device control register's current value
  2282. ******************************************************************************/
  2283. static void
  2284. e1000_lower_mdi_clk(struct e1000_hw *hw,
  2285. uint32_t *ctrl)
  2286. {
  2287. /* Lower the clock input to the Management Data Clock (by clearing the MDC
  2288. * bit), and then delay 10 microseconds.
  2289. */
  2290. E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
  2291. E1000_WRITE_FLUSH(hw);
  2292. usec_delay(10);
  2293. }
  2294. /******************************************************************************
  2295. * Shifts data bits out to the PHY
  2296. *
  2297. * hw - Struct containing variables accessed by shared code
  2298. * data - Data to send out to the PHY
  2299. * count - Number of bits to shift out
  2300. *
  2301. * Bits are shifted out in MSB to LSB order.
  2302. ******************************************************************************/
  2303. static void
  2304. e1000_shift_out_mdi_bits(struct e1000_hw *hw,
  2305. uint32_t data,
  2306. uint16_t count)
  2307. {
  2308. uint32_t ctrl;
  2309. uint32_t mask;
  2310. /* We need to shift "count" number of bits out to the PHY. So, the value
  2311. * in the "data" parameter will be shifted out to the PHY one bit at a
  2312. * time. In order to do this, "data" must be broken down into bits.
  2313. */
  2314. mask = 0x01;
  2315. mask <<= (count - 1);
  2316. ctrl = E1000_READ_REG(hw, CTRL);
  2317. /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
  2318. ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
  2319. while(mask) {
  2320. /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
  2321. * then raising and lowering the Management Data Clock. A "0" is
  2322. * shifted out to the PHY by setting the MDIO bit to "0" and then
  2323. * raising and lowering the clock.
  2324. */
  2325. if(data & mask) ctrl |= E1000_CTRL_MDIO;
  2326. else ctrl &= ~E1000_CTRL_MDIO;
  2327. E1000_WRITE_REG(hw, CTRL, ctrl);
  2328. E1000_WRITE_FLUSH(hw);
  2329. usec_delay(10);
  2330. e1000_raise_mdi_clk(hw, &ctrl);
  2331. e1000_lower_mdi_clk(hw, &ctrl);
  2332. mask = mask >> 1;
  2333. }
  2334. }
  2335. /******************************************************************************
  2336. * Shifts data bits in from the PHY
  2337. *
  2338. * hw - Struct containing variables accessed by shared code
  2339. *
  2340. * Bits are shifted in in MSB to LSB order.
  2341. ******************************************************************************/
  2342. static uint16_t
  2343. e1000_shift_in_mdi_bits(struct e1000_hw *hw)
  2344. {
  2345. uint32_t ctrl;
  2346. uint16_t data = 0;
  2347. uint8_t i;
  2348. /* In order to read a register from the PHY, we need to shift in a total
  2349. * of 18 bits from the PHY. The first two bit (turnaround) times are used
  2350. * to avoid contention on the MDIO pin when a read operation is performed.
  2351. * These two bits are ignored by us and thrown away. Bits are "shifted in"
  2352. * by raising the input to the Management Data Clock (setting the MDC bit),
  2353. * and then reading the value of the MDIO bit.
  2354. */
  2355. ctrl = E1000_READ_REG(hw, CTRL);
  2356. /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
  2357. ctrl &= ~E1000_CTRL_MDIO_DIR;
  2358. ctrl &= ~E1000_CTRL_MDIO;
  2359. E1000_WRITE_REG(hw, CTRL, ctrl);
  2360. E1000_WRITE_FLUSH(hw);
  2361. /* Raise and Lower the clock before reading in the data. This accounts for
  2362. * the turnaround bits. The first clock occurred when we clocked out the
  2363. * last bit of the Register Address.
  2364. */
  2365. e1000_raise_mdi_clk(hw, &ctrl);
  2366. e1000_lower_mdi_clk(hw, &ctrl);
  2367. for(data = 0, i = 0; i < 16; i++) {
  2368. data = data << 1;
  2369. e1000_raise_mdi_clk(hw, &ctrl);
  2370. ctrl = E1000_READ_REG(hw, CTRL);
  2371. /* Check to see if we shifted in a "1". */
  2372. if(ctrl & E1000_CTRL_MDIO) data |= 1;
  2373. e1000_lower_mdi_clk(hw, &ctrl);
  2374. }
  2375. e1000_raise_mdi_clk(hw, &ctrl);
  2376. e1000_lower_mdi_clk(hw, &ctrl);
  2377. return data;
  2378. }
  2379. /*****************************************************************************
  2380. * Reads the value from a PHY register, if the value is on a specific non zero
  2381. * page, sets the page first.
  2382. * hw - Struct containing variables accessed by shared code
  2383. * reg_addr - address of the PHY register to read
  2384. ******************************************************************************/
  2385. int32_t
  2386. e1000_read_phy_reg(struct e1000_hw *hw,
  2387. uint32_t reg_addr,
  2388. uint16_t *phy_data)
  2389. {
  2390. uint32_t ret_val;
  2391. DEBUGFUNC("e1000_read_phy_reg");
  2392. if((hw->phy_type == e1000_phy_igp ||
  2393. hw->phy_type == e1000_phy_igp_2) &&
  2394. (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
  2395. ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
  2396. (uint16_t)reg_addr);
  2397. if(ret_val) {
  2398. return ret_val;
  2399. }
  2400. }
  2401. ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
  2402. phy_data);
  2403. return ret_val;
  2404. }
  2405. int32_t
  2406. e1000_read_phy_reg_ex(struct e1000_hw *hw,
  2407. uint32_t reg_addr,
  2408. uint16_t *phy_data)
  2409. {
  2410. uint32_t i;
  2411. uint32_t mdic = 0;
  2412. const uint32_t phy_addr = 1;
  2413. DEBUGFUNC("e1000_read_phy_reg_ex");
  2414. if(reg_addr > MAX_PHY_REG_ADDRESS) {
  2415. DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
  2416. return -E1000_ERR_PARAM;
  2417. }
  2418. if(hw->mac_type > e1000_82543) {
  2419. /* Set up Op-code, Phy Address, and register address in the MDI
  2420. * Control register. The MAC will take care of interfacing with the
  2421. * PHY to retrieve the desired data.
  2422. */
  2423. mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
  2424. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  2425. (E1000_MDIC_OP_READ));
  2426. E1000_WRITE_REG(hw, MDIC, mdic);
  2427. /* Poll the ready bit to see if the MDI read completed */
  2428. for(i = 0; i < 64; i++) {
  2429. usec_delay(50);
  2430. mdic = E1000_READ_REG(hw, MDIC);
  2431. if(mdic & E1000_MDIC_READY) break;
  2432. }
  2433. if(!(mdic & E1000_MDIC_READY)) {
  2434. DEBUGOUT("MDI Read did not complete\n");
  2435. return -E1000_ERR_PHY;
  2436. }
  2437. if(mdic & E1000_MDIC_ERROR) {
  2438. DEBUGOUT("MDI Error\n");
  2439. return -E1000_ERR_PHY;
  2440. }
  2441. *phy_data = (uint16_t) mdic;
  2442. } else {
  2443. /* We must first send a preamble through the MDIO pin to signal the
  2444. * beginning of an MII instruction. This is done by sending 32
  2445. * consecutive "1" bits.
  2446. */
  2447. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  2448. /* Now combine the next few fields that are required for a read
  2449. * operation. We use this method instead of calling the
  2450. * e1000_shift_out_mdi_bits routine five different times. The format of
  2451. * a MII read instruction consists of a shift out of 14 bits and is
  2452. * defined as follows:
  2453. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
  2454. * followed by a shift in of 18 bits. This first two bits shifted in
  2455. * are TurnAround bits used to avoid contention on the MDIO pin when a
  2456. * READ operation is performed. These two bits are thrown away
  2457. * followed by a shift in of 16 bits which contains the desired data.
  2458. */
  2459. mdic = ((reg_addr) | (phy_addr << 5) |
  2460. (PHY_OP_READ << 10) | (PHY_SOF << 12));
  2461. e1000_shift_out_mdi_bits(hw, mdic, 14);
  2462. /* Now that we've shifted out the read command to the MII, we need to
  2463. * "shift in" the 16-bit value (18 total bits) of the requested PHY
  2464. * register address.
  2465. */
  2466. *phy_data = e1000_shift_in_mdi_bits(hw);
  2467. }
  2468. return E1000_SUCCESS;
  2469. }
  2470. /******************************************************************************
  2471. * Writes a value to a PHY register
  2472. *
  2473. * hw - Struct containing variables accessed by shared code
  2474. * reg_addr - address of the PHY register to write
  2475. * data - data to write to the PHY
  2476. ******************************************************************************/
  2477. int32_t
  2478. e1000_write_phy_reg(struct e1000_hw *hw,
  2479. uint32_t reg_addr,
  2480. uint16_t phy_data)
  2481. {
  2482. uint32_t ret_val;
  2483. DEBUGFUNC("e1000_write_phy_reg");
  2484. if((hw->phy_type == e1000_phy_igp ||
  2485. hw->phy_type == e1000_phy_igp_2) &&
  2486. (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
  2487. ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
  2488. (uint16_t)reg_addr);
  2489. if(ret_val) {
  2490. return ret_val;
  2491. }
  2492. }
  2493. ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
  2494. phy_data);
  2495. return ret_val;
  2496. }
  2497. int32_t
  2498. e1000_write_phy_reg_ex(struct e1000_hw *hw,
  2499. uint32_t reg_addr,
  2500. uint16_t phy_data)
  2501. {
  2502. uint32_t i;
  2503. uint32_t mdic = 0;
  2504. const uint32_t phy_addr = 1;
  2505. DEBUGFUNC("e1000_write_phy_reg_ex");
  2506. if(reg_addr > MAX_PHY_REG_ADDRESS) {
  2507. DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
  2508. return -E1000_ERR_PARAM;
  2509. }
  2510. if(hw->mac_type > e1000_82543) {
  2511. /* Set up Op-code, Phy Address, register address, and data intended
  2512. * for the PHY register in the MDI Control register. The MAC will take
  2513. * care of interfacing with the PHY to send the desired data.
  2514. */
  2515. mdic = (((uint32_t) phy_data) |
  2516. (reg_addr << E1000_MDIC_REG_SHIFT) |
  2517. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  2518. (E1000_MDIC_OP_WRITE));
  2519. E1000_WRITE_REG(hw, MDIC, mdic);
  2520. /* Poll the ready bit to see if the MDI read completed */
  2521. for(i = 0; i < 640; i++) {
  2522. usec_delay(5);
  2523. mdic = E1000_READ_REG(hw, MDIC);
  2524. if(mdic & E1000_MDIC_READY) break;
  2525. }
  2526. if(!(mdic & E1000_MDIC_READY)) {
  2527. DEBUGOUT("MDI Write did not complete\n");
  2528. return -E1000_ERR_PHY;
  2529. }
  2530. } else {
  2531. /* We'll need to use the SW defined pins to shift the write command
  2532. * out to the PHY. We first send a preamble to the PHY to signal the
  2533. * beginning of the MII instruction. This is done by sending 32
  2534. * consecutive "1" bits.
  2535. */
  2536. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  2537. /* Now combine the remaining required fields that will indicate a
  2538. * write operation. We use this method instead of calling the
  2539. * e1000_shift_out_mdi_bits routine for each field in the command. The
  2540. * format of a MII write instruction is as follows:
  2541. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
  2542. */
  2543. mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
  2544. (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
  2545. mdic <<= 16;
  2546. mdic |= (uint32_t) phy_data;
  2547. e1000_shift_out_mdi_bits(hw, mdic, 32);
  2548. }
  2549. return E1000_SUCCESS;
  2550. }
  2551. /******************************************************************************
  2552. * Returns the PHY to the power-on reset state
  2553. *
  2554. * hw - Struct containing variables accessed by shared code
  2555. ******************************************************************************/
  2556. int32_t
  2557. e1000_phy_hw_reset(struct e1000_hw *hw)
  2558. {
  2559. uint32_t ctrl, ctrl_ext;
  2560. uint32_t led_ctrl;
  2561. int32_t ret_val;
  2562. DEBUGFUNC("e1000_phy_hw_reset");
  2563. /* In the case of the phy reset being blocked, it's not an error, we
  2564. * simply return success without performing the reset. */
  2565. ret_val = e1000_check_phy_reset_block(hw);
  2566. if (ret_val)
  2567. return E1000_SUCCESS;
  2568. DEBUGOUT("Resetting Phy...\n");
  2569. if(hw->mac_type > e1000_82543) {
  2570. /* Read the device control register and assert the E1000_CTRL_PHY_RST
  2571. * bit. Then, take it out of reset.
  2572. */
  2573. ctrl = E1000_READ_REG(hw, CTRL);
  2574. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
  2575. E1000_WRITE_FLUSH(hw);
  2576. msec_delay(10);
  2577. E1000_WRITE_REG(hw, CTRL, ctrl);
  2578. E1000_WRITE_FLUSH(hw);
  2579. } else {
  2580. /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
  2581. * bit to put the PHY into reset. Then, take it out of reset.
  2582. */
  2583. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  2584. ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
  2585. ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
  2586. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  2587. E1000_WRITE_FLUSH(hw);
  2588. msec_delay(10);
  2589. ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
  2590. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  2591. E1000_WRITE_FLUSH(hw);
  2592. }
  2593. usec_delay(150);
  2594. if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  2595. /* Configure activity LED after PHY reset */
  2596. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  2597. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  2598. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  2599. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  2600. }
  2601. /* Wait for FW to finish PHY configuration. */
  2602. ret_val = e1000_get_phy_cfg_done(hw);
  2603. return ret_val;
  2604. }
  2605. /******************************************************************************
  2606. * Resets the PHY
  2607. *
  2608. * hw - Struct containing variables accessed by shared code
  2609. *
  2610. * Sets bit 15 of the MII Control regiser
  2611. ******************************************************************************/
  2612. int32_t
  2613. e1000_phy_reset(struct e1000_hw *hw)
  2614. {
  2615. int32_t ret_val;
  2616. uint16_t phy_data;
  2617. DEBUGFUNC("e1000_phy_reset");
  2618. /* In the case of the phy reset being blocked, it's not an error, we
  2619. * simply return success without performing the reset. */
  2620. ret_val = e1000_check_phy_reset_block(hw);
  2621. if (ret_val)
  2622. return E1000_SUCCESS;
  2623. switch (hw->mac_type) {
  2624. case e1000_82541_rev_2:
  2625. case e1000_82571:
  2626. case e1000_82572:
  2627. ret_val = e1000_phy_hw_reset(hw);
  2628. if(ret_val)
  2629. return ret_val;
  2630. break;
  2631. default:
  2632. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
  2633. if(ret_val)
  2634. return ret_val;
  2635. phy_data |= MII_CR_RESET;
  2636. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
  2637. if(ret_val)
  2638. return ret_val;
  2639. usec_delay(1);
  2640. break;
  2641. }
  2642. if(hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
  2643. e1000_phy_init_script(hw);
  2644. return E1000_SUCCESS;
  2645. }
  2646. /******************************************************************************
  2647. * Probes the expected PHY address for known PHY IDs
  2648. *
  2649. * hw - Struct containing variables accessed by shared code
  2650. ******************************************************************************/
  2651. int32_t
  2652. e1000_detect_gig_phy(struct e1000_hw *hw)
  2653. {
  2654. int32_t phy_init_status, ret_val;
  2655. uint16_t phy_id_high, phy_id_low;
  2656. boolean_t match = FALSE;
  2657. DEBUGFUNC("e1000_detect_gig_phy");
  2658. /* The 82571 firmware may still be configuring the PHY. In this
  2659. * case, we cannot access the PHY until the configuration is done. So
  2660. * we explicitly set the PHY values. */
  2661. if(hw->mac_type == e1000_82571 ||
  2662. hw->mac_type == e1000_82572) {
  2663. hw->phy_id = IGP01E1000_I_PHY_ID;
  2664. hw->phy_type = e1000_phy_igp_2;
  2665. return E1000_SUCCESS;
  2666. }
  2667. /* Read the PHY ID Registers to identify which PHY is onboard. */
  2668. ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
  2669. if(ret_val)
  2670. return ret_val;
  2671. hw->phy_id = (uint32_t) (phy_id_high << 16);
  2672. usec_delay(20);
  2673. ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
  2674. if(ret_val)
  2675. return ret_val;
  2676. hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
  2677. hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
  2678. switch(hw->mac_type) {
  2679. case e1000_82543:
  2680. if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
  2681. break;
  2682. case e1000_82544:
  2683. if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
  2684. break;
  2685. case e1000_82540:
  2686. case e1000_82545:
  2687. case e1000_82545_rev_3:
  2688. case e1000_82546:
  2689. case e1000_82546_rev_3:
  2690. if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
  2691. break;
  2692. case e1000_82541:
  2693. case e1000_82541_rev_2:
  2694. case e1000_82547:
  2695. case e1000_82547_rev_2:
  2696. if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
  2697. break;
  2698. case e1000_82573:
  2699. if(hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
  2700. break;
  2701. default:
  2702. DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
  2703. return -E1000_ERR_CONFIG;
  2704. }
  2705. phy_init_status = e1000_set_phy_type(hw);
  2706. if ((match) && (phy_init_status == E1000_SUCCESS)) {
  2707. DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
  2708. return E1000_SUCCESS;
  2709. }
  2710. DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
  2711. return -E1000_ERR_PHY;
  2712. }
  2713. /******************************************************************************
  2714. * Resets the PHY's DSP
  2715. *
  2716. * hw - Struct containing variables accessed by shared code
  2717. ******************************************************************************/
  2718. static int32_t
  2719. e1000_phy_reset_dsp(struct e1000_hw *hw)
  2720. {
  2721. int32_t ret_val;
  2722. DEBUGFUNC("e1000_phy_reset_dsp");
  2723. do {
  2724. ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
  2725. if(ret_val) break;
  2726. ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
  2727. if(ret_val) break;
  2728. ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
  2729. if(ret_val) break;
  2730. ret_val = E1000_SUCCESS;
  2731. } while(0);
  2732. return ret_val;
  2733. }
  2734. /******************************************************************************
  2735. * Get PHY information from various PHY registers for igp PHY only.
  2736. *
  2737. * hw - Struct containing variables accessed by shared code
  2738. * phy_info - PHY information structure
  2739. ******************************************************************************/
  2740. int32_t
  2741. e1000_phy_igp_get_info(struct e1000_hw *hw,
  2742. struct e1000_phy_info *phy_info)
  2743. {
  2744. int32_t ret_val;
  2745. uint16_t phy_data, polarity, min_length, max_length, average;
  2746. DEBUGFUNC("e1000_phy_igp_get_info");
  2747. /* The downshift status is checked only once, after link is established,
  2748. * and it stored in the hw->speed_downgraded parameter. */
  2749. phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
  2750. /* IGP01E1000 does not need to support it. */
  2751. phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
  2752. /* IGP01E1000 always correct polarity reversal */
  2753. phy_info->polarity_correction = e1000_polarity_reversal_enabled;
  2754. /* Check polarity status */
  2755. ret_val = e1000_check_polarity(hw, &polarity);
  2756. if(ret_val)
  2757. return ret_val;
  2758. phy_info->cable_polarity = polarity;
  2759. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
  2760. if(ret_val)
  2761. return ret_val;
  2762. phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
  2763. IGP01E1000_PSSR_MDIX_SHIFT;
  2764. if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
  2765. IGP01E1000_PSSR_SPEED_1000MBPS) {
  2766. /* Local/Remote Receiver Information are only valid at 1000 Mbps */
  2767. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
  2768. if(ret_val)
  2769. return ret_val;
  2770. phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
  2771. SR_1000T_LOCAL_RX_STATUS_SHIFT;
  2772. phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
  2773. SR_1000T_REMOTE_RX_STATUS_SHIFT;
  2774. /* Get cable length */
  2775. ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
  2776. if(ret_val)
  2777. return ret_val;
  2778. /* Translate to old method */
  2779. average = (max_length + min_length) / 2;
  2780. if(average <= e1000_igp_cable_length_50)
  2781. phy_info->cable_length = e1000_cable_length_50;
  2782. else if(average <= e1000_igp_cable_length_80)
  2783. phy_info->cable_length = e1000_cable_length_50_80;
  2784. else if(average <= e1000_igp_cable_length_110)
  2785. phy_info->cable_length = e1000_cable_length_80_110;
  2786. else if(average <= e1000_igp_cable_length_140)
  2787. phy_info->cable_length = e1000_cable_length_110_140;
  2788. else
  2789. phy_info->cable_length = e1000_cable_length_140;
  2790. }
  2791. return E1000_SUCCESS;
  2792. }
  2793. /******************************************************************************
  2794. * Get PHY information from various PHY registers fot m88 PHY only.
  2795. *
  2796. * hw - Struct containing variables accessed by shared code
  2797. * phy_info - PHY information structure
  2798. ******************************************************************************/
  2799. int32_t
  2800. e1000_phy_m88_get_info(struct e1000_hw *hw,
  2801. struct e1000_phy_info *phy_info)
  2802. {
  2803. int32_t ret_val;
  2804. uint16_t phy_data, polarity;
  2805. DEBUGFUNC("e1000_phy_m88_get_info");
  2806. /* The downshift status is checked only once, after link is established,
  2807. * and it stored in the hw->speed_downgraded parameter. */
  2808. phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
  2809. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  2810. if(ret_val)
  2811. return ret_val;
  2812. phy_info->extended_10bt_distance =
  2813. (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
  2814. M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
  2815. phy_info->polarity_correction =
  2816. (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
  2817. M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
  2818. /* Check polarity status */
  2819. ret_val = e1000_check_polarity(hw, &polarity);
  2820. if(ret_val)
  2821. return ret_val;
  2822. phy_info->cable_polarity = polarity;
  2823. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  2824. if(ret_val)
  2825. return ret_val;
  2826. phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
  2827. M88E1000_PSSR_MDIX_SHIFT;
  2828. if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
  2829. /* Cable Length Estimation and Local/Remote Receiver Information
  2830. * are only valid at 1000 Mbps.
  2831. */
  2832. phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
  2833. M88E1000_PSSR_CABLE_LENGTH_SHIFT);
  2834. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
  2835. if(ret_val)
  2836. return ret_val;
  2837. phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
  2838. SR_1000T_LOCAL_RX_STATUS_SHIFT;
  2839. phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
  2840. SR_1000T_REMOTE_RX_STATUS_SHIFT;
  2841. }
  2842. return E1000_SUCCESS;
  2843. }
  2844. /******************************************************************************
  2845. * Get PHY information from various PHY registers
  2846. *
  2847. * hw - Struct containing variables accessed by shared code
  2848. * phy_info - PHY information structure
  2849. ******************************************************************************/
  2850. int32_t
  2851. e1000_phy_get_info(struct e1000_hw *hw,
  2852. struct e1000_phy_info *phy_info)
  2853. {
  2854. int32_t ret_val;
  2855. uint16_t phy_data;
  2856. DEBUGFUNC("e1000_phy_get_info");
  2857. phy_info->cable_length = e1000_cable_length_undefined;
  2858. phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
  2859. phy_info->cable_polarity = e1000_rev_polarity_undefined;
  2860. phy_info->downshift = e1000_downshift_undefined;
  2861. phy_info->polarity_correction = e1000_polarity_reversal_undefined;
  2862. phy_info->mdix_mode = e1000_auto_x_mode_undefined;
  2863. phy_info->local_rx = e1000_1000t_rx_status_undefined;
  2864. phy_info->remote_rx = e1000_1000t_rx_status_undefined;
  2865. if(hw->media_type != e1000_media_type_copper) {
  2866. DEBUGOUT("PHY info is only valid for copper media\n");
  2867. return -E1000_ERR_CONFIG;
  2868. }
  2869. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2870. if(ret_val)
  2871. return ret_val;
  2872. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2873. if(ret_val)
  2874. return ret_val;
  2875. if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
  2876. DEBUGOUT("PHY info is only valid if link is up\n");
  2877. return -E1000_ERR_CONFIG;
  2878. }
  2879. if(hw->phy_type == e1000_phy_igp ||
  2880. hw->phy_type == e1000_phy_igp_2)
  2881. return e1000_phy_igp_get_info(hw, phy_info);
  2882. else
  2883. return e1000_phy_m88_get_info(hw, phy_info);
  2884. }
  2885. int32_t
  2886. e1000_validate_mdi_setting(struct e1000_hw *hw)
  2887. {
  2888. DEBUGFUNC("e1000_validate_mdi_settings");
  2889. if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
  2890. DEBUGOUT("Invalid MDI setting detected\n");
  2891. hw->mdix = 1;
  2892. return -E1000_ERR_CONFIG;
  2893. }
  2894. return E1000_SUCCESS;
  2895. }
  2896. /******************************************************************************
  2897. * Sets up eeprom variables in the hw struct. Must be called after mac_type
  2898. * is configured.
  2899. *
  2900. * hw - Struct containing variables accessed by shared code
  2901. *****************************************************************************/
  2902. int32_t
  2903. e1000_init_eeprom_params(struct e1000_hw *hw)
  2904. {
  2905. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  2906. uint32_t eecd = E1000_READ_REG(hw, EECD);
  2907. int32_t ret_val = E1000_SUCCESS;
  2908. uint16_t eeprom_size;
  2909. DEBUGFUNC("e1000_init_eeprom_params");
  2910. switch (hw->mac_type) {
  2911. case e1000_82542_rev2_0:
  2912. case e1000_82542_rev2_1:
  2913. case e1000_82543:
  2914. case e1000_82544:
  2915. eeprom->type = e1000_eeprom_microwire;
  2916. eeprom->word_size = 64;
  2917. eeprom->opcode_bits = 3;
  2918. eeprom->address_bits = 6;
  2919. eeprom->delay_usec = 50;
  2920. eeprom->use_eerd = FALSE;
  2921. eeprom->use_eewr = FALSE;
  2922. break;
  2923. case e1000_82540:
  2924. case e1000_82545:
  2925. case e1000_82545_rev_3:
  2926. case e1000_82546:
  2927. case e1000_82546_rev_3:
  2928. eeprom->type = e1000_eeprom_microwire;
  2929. eeprom->opcode_bits = 3;
  2930. eeprom->delay_usec = 50;
  2931. if(eecd & E1000_EECD_SIZE) {
  2932. eeprom->word_size = 256;
  2933. eeprom->address_bits = 8;
  2934. } else {
  2935. eeprom->word_size = 64;
  2936. eeprom->address_bits = 6;
  2937. }
  2938. eeprom->use_eerd = FALSE;
  2939. eeprom->use_eewr = FALSE;
  2940. break;
  2941. case e1000_82541:
  2942. case e1000_82541_rev_2:
  2943. case e1000_82547:
  2944. case e1000_82547_rev_2:
  2945. if (eecd & E1000_EECD_TYPE) {
  2946. eeprom->type = e1000_eeprom_spi;
  2947. eeprom->opcode_bits = 8;
  2948. eeprom->delay_usec = 1;
  2949. if (eecd & E1000_EECD_ADDR_BITS) {
  2950. eeprom->page_size = 32;
  2951. eeprom->address_bits = 16;
  2952. } else {
  2953. eeprom->page_size = 8;
  2954. eeprom->address_bits = 8;
  2955. }
  2956. } else {
  2957. eeprom->type = e1000_eeprom_microwire;
  2958. eeprom->opcode_bits = 3;
  2959. eeprom->delay_usec = 50;
  2960. if (eecd & E1000_EECD_ADDR_BITS) {
  2961. eeprom->word_size = 256;
  2962. eeprom->address_bits = 8;
  2963. } else {
  2964. eeprom->word_size = 64;
  2965. eeprom->address_bits = 6;
  2966. }
  2967. }
  2968. eeprom->use_eerd = FALSE;
  2969. eeprom->use_eewr = FALSE;
  2970. break;
  2971. case e1000_82571:
  2972. case e1000_82572:
  2973. eeprom->type = e1000_eeprom_spi;
  2974. eeprom->opcode_bits = 8;
  2975. eeprom->delay_usec = 1;
  2976. if (eecd & E1000_EECD_ADDR_BITS) {
  2977. eeprom->page_size = 32;
  2978. eeprom->address_bits = 16;
  2979. } else {
  2980. eeprom->page_size = 8;
  2981. eeprom->address_bits = 8;
  2982. }
  2983. eeprom->use_eerd = FALSE;
  2984. eeprom->use_eewr = FALSE;
  2985. break;
  2986. case e1000_82573:
  2987. eeprom->type = e1000_eeprom_spi;
  2988. eeprom->opcode_bits = 8;
  2989. eeprom->delay_usec = 1;
  2990. if (eecd & E1000_EECD_ADDR_BITS) {
  2991. eeprom->page_size = 32;
  2992. eeprom->address_bits = 16;
  2993. } else {
  2994. eeprom->page_size = 8;
  2995. eeprom->address_bits = 8;
  2996. }
  2997. eeprom->use_eerd = TRUE;
  2998. eeprom->use_eewr = TRUE;
  2999. if(e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
  3000. eeprom->type = e1000_eeprom_flash;
  3001. eeprom->word_size = 2048;
  3002. /* Ensure that the Autonomous FLASH update bit is cleared due to
  3003. * Flash update issue on parts which use a FLASH for NVM. */
  3004. eecd &= ~E1000_EECD_AUPDEN;
  3005. E1000_WRITE_REG(hw, EECD, eecd);
  3006. }
  3007. break;
  3008. default:
  3009. break;
  3010. }
  3011. if (eeprom->type == e1000_eeprom_spi) {
  3012. /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
  3013. * 32KB (incremented by powers of 2).
  3014. */
  3015. if(hw->mac_type <= e1000_82547_rev_2) {
  3016. /* Set to default value for initial eeprom read. */
  3017. eeprom->word_size = 64;
  3018. ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
  3019. if(ret_val)
  3020. return ret_val;
  3021. eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
  3022. /* 256B eeprom size was not supported in earlier hardware, so we
  3023. * bump eeprom_size up one to ensure that "1" (which maps to 256B)
  3024. * is never the result used in the shifting logic below. */
  3025. if(eeprom_size)
  3026. eeprom_size++;
  3027. } else {
  3028. eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
  3029. E1000_EECD_SIZE_EX_SHIFT);
  3030. }
  3031. eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
  3032. }
  3033. return ret_val;
  3034. }
  3035. /******************************************************************************
  3036. * Raises the EEPROM's clock input.
  3037. *
  3038. * hw - Struct containing variables accessed by shared code
  3039. * eecd - EECD's current value
  3040. *****************************************************************************/
  3041. static void
  3042. e1000_raise_ee_clk(struct e1000_hw *hw,
  3043. uint32_t *eecd)
  3044. {
  3045. /* Raise the clock input to the EEPROM (by setting the SK bit), and then
  3046. * wait <delay> microseconds.
  3047. */
  3048. *eecd = *eecd | E1000_EECD_SK;
  3049. E1000_WRITE_REG(hw, EECD, *eecd);
  3050. E1000_WRITE_FLUSH(hw);
  3051. usec_delay(hw->eeprom.delay_usec);
  3052. }
  3053. /******************************************************************************
  3054. * Lowers the EEPROM's clock input.
  3055. *
  3056. * hw - Struct containing variables accessed by shared code
  3057. * eecd - EECD's current value
  3058. *****************************************************************************/
  3059. static void
  3060. e1000_lower_ee_clk(struct e1000_hw *hw,
  3061. uint32_t *eecd)
  3062. {
  3063. /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
  3064. * wait 50 microseconds.
  3065. */
  3066. *eecd = *eecd & ~E1000_EECD_SK;
  3067. E1000_WRITE_REG(hw, EECD, *eecd);
  3068. E1000_WRITE_FLUSH(hw);
  3069. usec_delay(hw->eeprom.delay_usec);
  3070. }
  3071. /******************************************************************************
  3072. * Shift data bits out to the EEPROM.
  3073. *
  3074. * hw - Struct containing variables accessed by shared code
  3075. * data - data to send to the EEPROM
  3076. * count - number of bits to shift out
  3077. *****************************************************************************/
  3078. static void
  3079. e1000_shift_out_ee_bits(struct e1000_hw *hw,
  3080. uint16_t data,
  3081. uint16_t count)
  3082. {
  3083. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3084. uint32_t eecd;
  3085. uint32_t mask;
  3086. /* We need to shift "count" bits out to the EEPROM. So, value in the
  3087. * "data" parameter will be shifted out to the EEPROM one bit at a time.
  3088. * In order to do this, "data" must be broken down into bits.
  3089. */
  3090. mask = 0x01 << (count - 1);
  3091. eecd = E1000_READ_REG(hw, EECD);
  3092. if (eeprom->type == e1000_eeprom_microwire) {
  3093. eecd &= ~E1000_EECD_DO;
  3094. } else if (eeprom->type == e1000_eeprom_spi) {
  3095. eecd |= E1000_EECD_DO;
  3096. }
  3097. do {
  3098. /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
  3099. * and then raising and then lowering the clock (the SK bit controls
  3100. * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
  3101. * by setting "DI" to "0" and then raising and then lowering the clock.
  3102. */
  3103. eecd &= ~E1000_EECD_DI;
  3104. if(data & mask)
  3105. eecd |= E1000_EECD_DI;
  3106. E1000_WRITE_REG(hw, EECD, eecd);
  3107. E1000_WRITE_FLUSH(hw);
  3108. usec_delay(eeprom->delay_usec);
  3109. e1000_raise_ee_clk(hw, &eecd);
  3110. e1000_lower_ee_clk(hw, &eecd);
  3111. mask = mask >> 1;
  3112. } while(mask);
  3113. /* We leave the "DI" bit set to "0" when we leave this routine. */
  3114. eecd &= ~E1000_EECD_DI;
  3115. E1000_WRITE_REG(hw, EECD, eecd);
  3116. }
  3117. /******************************************************************************
  3118. * Shift data bits in from the EEPROM
  3119. *
  3120. * hw - Struct containing variables accessed by shared code
  3121. *****************************************************************************/
  3122. static uint16_t
  3123. e1000_shift_in_ee_bits(struct e1000_hw *hw,
  3124. uint16_t count)
  3125. {
  3126. uint32_t eecd;
  3127. uint32_t i;
  3128. uint16_t data;
  3129. /* In order to read a register from the EEPROM, we need to shift 'count'
  3130. * bits in from the EEPROM. Bits are "shifted in" by raising the clock
  3131. * input to the EEPROM (setting the SK bit), and then reading the value of
  3132. * the "DO" bit. During this "shifting in" process the "DI" bit should
  3133. * always be clear.
  3134. */
  3135. eecd = E1000_READ_REG(hw, EECD);
  3136. eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
  3137. data = 0;
  3138. for(i = 0; i < count; i++) {
  3139. data = data << 1;
  3140. e1000_raise_ee_clk(hw, &eecd);
  3141. eecd = E1000_READ_REG(hw, EECD);
  3142. eecd &= ~(E1000_EECD_DI);
  3143. if(eecd & E1000_EECD_DO)
  3144. data |= 1;
  3145. e1000_lower_ee_clk(hw, &eecd);
  3146. }
  3147. return data;
  3148. }
  3149. /******************************************************************************
  3150. * Prepares EEPROM for access
  3151. *
  3152. * hw - Struct containing variables accessed by shared code
  3153. *
  3154. * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
  3155. * function should be called before issuing a command to the EEPROM.
  3156. *****************************************************************************/
  3157. static int32_t
  3158. e1000_acquire_eeprom(struct e1000_hw *hw)
  3159. {
  3160. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3161. uint32_t eecd, i=0;
  3162. DEBUGFUNC("e1000_acquire_eeprom");
  3163. if(e1000_get_hw_eeprom_semaphore(hw))
  3164. return -E1000_ERR_EEPROM;
  3165. eecd = E1000_READ_REG(hw, EECD);
  3166. if (hw->mac_type != e1000_82573) {
  3167. /* Request EEPROM Access */
  3168. if(hw->mac_type > e1000_82544) {
  3169. eecd |= E1000_EECD_REQ;
  3170. E1000_WRITE_REG(hw, EECD, eecd);
  3171. eecd = E1000_READ_REG(hw, EECD);
  3172. while((!(eecd & E1000_EECD_GNT)) &&
  3173. (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
  3174. i++;
  3175. usec_delay(5);
  3176. eecd = E1000_READ_REG(hw, EECD);
  3177. }
  3178. if(!(eecd & E1000_EECD_GNT)) {
  3179. eecd &= ~E1000_EECD_REQ;
  3180. E1000_WRITE_REG(hw, EECD, eecd);
  3181. DEBUGOUT("Could not acquire EEPROM grant\n");
  3182. e1000_put_hw_eeprom_semaphore(hw);
  3183. return -E1000_ERR_EEPROM;
  3184. }
  3185. }
  3186. }
  3187. /* Setup EEPROM for Read/Write */
  3188. if (eeprom->type == e1000_eeprom_microwire) {
  3189. /* Clear SK and DI */
  3190. eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
  3191. E1000_WRITE_REG(hw, EECD, eecd);
  3192. /* Set CS */
  3193. eecd |= E1000_EECD_CS;
  3194. E1000_WRITE_REG(hw, EECD, eecd);
  3195. } else if (eeprom->type == e1000_eeprom_spi) {
  3196. /* Clear SK and CS */
  3197. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  3198. E1000_WRITE_REG(hw, EECD, eecd);
  3199. usec_delay(1);
  3200. }
  3201. return E1000_SUCCESS;
  3202. }
  3203. /******************************************************************************
  3204. * Returns EEPROM to a "standby" state
  3205. *
  3206. * hw - Struct containing variables accessed by shared code
  3207. *****************************************************************************/
  3208. static void
  3209. e1000_standby_eeprom(struct e1000_hw *hw)
  3210. {
  3211. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3212. uint32_t eecd;
  3213. eecd = E1000_READ_REG(hw, EECD);
  3214. if(eeprom->type == e1000_eeprom_microwire) {
  3215. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  3216. E1000_WRITE_REG(hw, EECD, eecd);
  3217. E1000_WRITE_FLUSH(hw);
  3218. usec_delay(eeprom->delay_usec);
  3219. /* Clock high */
  3220. eecd |= E1000_EECD_SK;
  3221. E1000_WRITE_REG(hw, EECD, eecd);
  3222. E1000_WRITE_FLUSH(hw);
  3223. usec_delay(eeprom->delay_usec);
  3224. /* Select EEPROM */
  3225. eecd |= E1000_EECD_CS;
  3226. E1000_WRITE_REG(hw, EECD, eecd);
  3227. E1000_WRITE_FLUSH(hw);
  3228. usec_delay(eeprom->delay_usec);
  3229. /* Clock low */
  3230. eecd &= ~E1000_EECD_SK;
  3231. E1000_WRITE_REG(hw, EECD, eecd);
  3232. E1000_WRITE_FLUSH(hw);
  3233. usec_delay(eeprom->delay_usec);
  3234. } else if(eeprom->type == e1000_eeprom_spi) {
  3235. /* Toggle CS to flush commands */
  3236. eecd |= E1000_EECD_CS;
  3237. E1000_WRITE_REG(hw, EECD, eecd);
  3238. E1000_WRITE_FLUSH(hw);
  3239. usec_delay(eeprom->delay_usec);
  3240. eecd &= ~E1000_EECD_CS;
  3241. E1000_WRITE_REG(hw, EECD, eecd);
  3242. E1000_WRITE_FLUSH(hw);
  3243. usec_delay(eeprom->delay_usec);
  3244. }
  3245. }
  3246. /******************************************************************************
  3247. * Terminates a command by inverting the EEPROM's chip select pin
  3248. *
  3249. * hw - Struct containing variables accessed by shared code
  3250. *****************************************************************************/
  3251. static void
  3252. e1000_release_eeprom(struct e1000_hw *hw)
  3253. {
  3254. uint32_t eecd;
  3255. DEBUGFUNC("e1000_release_eeprom");
  3256. eecd = E1000_READ_REG(hw, EECD);
  3257. if (hw->eeprom.type == e1000_eeprom_spi) {
  3258. eecd |= E1000_EECD_CS; /* Pull CS high */
  3259. eecd &= ~E1000_EECD_SK; /* Lower SCK */
  3260. E1000_WRITE_REG(hw, EECD, eecd);
  3261. usec_delay(hw->eeprom.delay_usec);
  3262. } else if(hw->eeprom.type == e1000_eeprom_microwire) {
  3263. /* cleanup eeprom */
  3264. /* CS on Microwire is active-high */
  3265. eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
  3266. E1000_WRITE_REG(hw, EECD, eecd);
  3267. /* Rising edge of clock */
  3268. eecd |= E1000_EECD_SK;
  3269. E1000_WRITE_REG(hw, EECD, eecd);
  3270. E1000_WRITE_FLUSH(hw);
  3271. usec_delay(hw->eeprom.delay_usec);
  3272. /* Falling edge of clock */
  3273. eecd &= ~E1000_EECD_SK;
  3274. E1000_WRITE_REG(hw, EECD, eecd);
  3275. E1000_WRITE_FLUSH(hw);
  3276. usec_delay(hw->eeprom.delay_usec);
  3277. }
  3278. /* Stop requesting EEPROM access */
  3279. if(hw->mac_type > e1000_82544) {
  3280. eecd &= ~E1000_EECD_REQ;
  3281. E1000_WRITE_REG(hw, EECD, eecd);
  3282. }
  3283. e1000_put_hw_eeprom_semaphore(hw);
  3284. }
  3285. /******************************************************************************
  3286. * Reads a 16 bit word from the EEPROM.
  3287. *
  3288. * hw - Struct containing variables accessed by shared code
  3289. *****************************************************************************/
  3290. int32_t
  3291. e1000_spi_eeprom_ready(struct e1000_hw *hw)
  3292. {
  3293. uint16_t retry_count = 0;
  3294. uint8_t spi_stat_reg;
  3295. DEBUGFUNC("e1000_spi_eeprom_ready");
  3296. /* Read "Status Register" repeatedly until the LSB is cleared. The
  3297. * EEPROM will signal that the command has been completed by clearing
  3298. * bit 0 of the internal status register. If it's not cleared within
  3299. * 5 milliseconds, then error out.
  3300. */
  3301. retry_count = 0;
  3302. do {
  3303. e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
  3304. hw->eeprom.opcode_bits);
  3305. spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
  3306. if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
  3307. break;
  3308. usec_delay(5);
  3309. retry_count += 5;
  3310. e1000_standby_eeprom(hw);
  3311. } while(retry_count < EEPROM_MAX_RETRY_SPI);
  3312. /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
  3313. * only 0-5mSec on 5V devices)
  3314. */
  3315. if(retry_count >= EEPROM_MAX_RETRY_SPI) {
  3316. DEBUGOUT("SPI EEPROM Status error\n");
  3317. return -E1000_ERR_EEPROM;
  3318. }
  3319. return E1000_SUCCESS;
  3320. }
  3321. /******************************************************************************
  3322. * Reads a 16 bit word from the EEPROM.
  3323. *
  3324. * hw - Struct containing variables accessed by shared code
  3325. * offset - offset of word in the EEPROM to read
  3326. * data - word read from the EEPROM
  3327. * words - number of words to read
  3328. *****************************************************************************/
  3329. int32_t
  3330. e1000_read_eeprom(struct e1000_hw *hw,
  3331. uint16_t offset,
  3332. uint16_t words,
  3333. uint16_t *data)
  3334. {
  3335. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3336. uint32_t i = 0;
  3337. int32_t ret_val;
  3338. DEBUGFUNC("e1000_read_eeprom");
  3339. /* A check for invalid values: offset too large, too many words, and not
  3340. * enough words.
  3341. */
  3342. if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
  3343. (words == 0)) {
  3344. DEBUGOUT("\"words\" parameter out of bounds\n");
  3345. return -E1000_ERR_EEPROM;
  3346. }
  3347. /* FLASH reads without acquiring the semaphore are safe in 82573-based
  3348. * controllers.
  3349. */
  3350. if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
  3351. (hw->mac_type != e1000_82573)) {
  3352. /* Prepare the EEPROM for reading */
  3353. if(e1000_acquire_eeprom(hw) != E1000_SUCCESS)
  3354. return -E1000_ERR_EEPROM;
  3355. }
  3356. if(eeprom->use_eerd == TRUE) {
  3357. ret_val = e1000_read_eeprom_eerd(hw, offset, words, data);
  3358. if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
  3359. (hw->mac_type != e1000_82573))
  3360. e1000_release_eeprom(hw);
  3361. return ret_val;
  3362. }
  3363. if(eeprom->type == e1000_eeprom_spi) {
  3364. uint16_t word_in;
  3365. uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
  3366. if(e1000_spi_eeprom_ready(hw)) {
  3367. e1000_release_eeprom(hw);
  3368. return -E1000_ERR_EEPROM;
  3369. }
  3370. e1000_standby_eeprom(hw);
  3371. /* Some SPI eeproms use the 8th address bit embedded in the opcode */
  3372. if((eeprom->address_bits == 8) && (offset >= 128))
  3373. read_opcode |= EEPROM_A8_OPCODE_SPI;
  3374. /* Send the READ command (opcode + addr) */
  3375. e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
  3376. e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
  3377. /* Read the data. The address of the eeprom internally increments with
  3378. * each byte (spi) being read, saving on the overhead of eeprom setup
  3379. * and tear-down. The address counter will roll over if reading beyond
  3380. * the size of the eeprom, thus allowing the entire memory to be read
  3381. * starting from any offset. */
  3382. for (i = 0; i < words; i++) {
  3383. word_in = e1000_shift_in_ee_bits(hw, 16);
  3384. data[i] = (word_in >> 8) | (word_in << 8);
  3385. }
  3386. } else if(eeprom->type == e1000_eeprom_microwire) {
  3387. for (i = 0; i < words; i++) {
  3388. /* Send the READ command (opcode + addr) */
  3389. e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
  3390. eeprom->opcode_bits);
  3391. e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
  3392. eeprom->address_bits);
  3393. /* Read the data. For microwire, each word requires the overhead
  3394. * of eeprom setup and tear-down. */
  3395. data[i] = e1000_shift_in_ee_bits(hw, 16);
  3396. e1000_standby_eeprom(hw);
  3397. }
  3398. }
  3399. /* End this read operation */
  3400. e1000_release_eeprom(hw);
  3401. return E1000_SUCCESS;
  3402. }
  3403. /******************************************************************************
  3404. * Reads a 16 bit word from the EEPROM using the EERD register.
  3405. *
  3406. * hw - Struct containing variables accessed by shared code
  3407. * offset - offset of word in the EEPROM to read
  3408. * data - word read from the EEPROM
  3409. * words - number of words to read
  3410. *****************************************************************************/
  3411. int32_t
  3412. e1000_read_eeprom_eerd(struct e1000_hw *hw,
  3413. uint16_t offset,
  3414. uint16_t words,
  3415. uint16_t *data)
  3416. {
  3417. uint32_t i, eerd = 0;
  3418. int32_t error = 0;
  3419. for (i = 0; i < words; i++) {
  3420. eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
  3421. E1000_EEPROM_RW_REG_START;
  3422. E1000_WRITE_REG(hw, EERD, eerd);
  3423. error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
  3424. if(error) {
  3425. break;
  3426. }
  3427. data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
  3428. }
  3429. return error;
  3430. }
  3431. /******************************************************************************
  3432. * Writes a 16 bit word from the EEPROM using the EEWR register.
  3433. *
  3434. * hw - Struct containing variables accessed by shared code
  3435. * offset - offset of word in the EEPROM to read
  3436. * data - word read from the EEPROM
  3437. * words - number of words to read
  3438. *****************************************************************************/
  3439. int32_t
  3440. e1000_write_eeprom_eewr(struct e1000_hw *hw,
  3441. uint16_t offset,
  3442. uint16_t words,
  3443. uint16_t *data)
  3444. {
  3445. uint32_t register_value = 0;
  3446. uint32_t i = 0;
  3447. int32_t error = 0;
  3448. for (i = 0; i < words; i++) {
  3449. register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
  3450. ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
  3451. E1000_EEPROM_RW_REG_START;
  3452. error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
  3453. if(error) {
  3454. break;
  3455. }
  3456. E1000_WRITE_REG(hw, EEWR, register_value);
  3457. error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
  3458. if(error) {
  3459. break;
  3460. }
  3461. }
  3462. return error;
  3463. }
  3464. /******************************************************************************
  3465. * Polls the status bit (bit 1) of the EERD to determine when the read is done.
  3466. *
  3467. * hw - Struct containing variables accessed by shared code
  3468. *****************************************************************************/
  3469. int32_t
  3470. e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
  3471. {
  3472. uint32_t attempts = 100000;
  3473. uint32_t i, reg = 0;
  3474. int32_t done = E1000_ERR_EEPROM;
  3475. for(i = 0; i < attempts; i++) {
  3476. if(eerd == E1000_EEPROM_POLL_READ)
  3477. reg = E1000_READ_REG(hw, EERD);
  3478. else
  3479. reg = E1000_READ_REG(hw, EEWR);
  3480. if(reg & E1000_EEPROM_RW_REG_DONE) {
  3481. done = E1000_SUCCESS;
  3482. break;
  3483. }
  3484. usec_delay(5);
  3485. }
  3486. return done;
  3487. }
  3488. /***************************************************************************
  3489. * Description: Determines if the onboard NVM is FLASH or EEPROM.
  3490. *
  3491. * hw - Struct containing variables accessed by shared code
  3492. ****************************************************************************/
  3493. boolean_t
  3494. e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
  3495. {
  3496. uint32_t eecd = 0;
  3497. if(hw->mac_type == e1000_82573) {
  3498. eecd = E1000_READ_REG(hw, EECD);
  3499. /* Isolate bits 15 & 16 */
  3500. eecd = ((eecd >> 15) & 0x03);
  3501. /* If both bits are set, device is Flash type */
  3502. if(eecd == 0x03) {
  3503. return FALSE;
  3504. }
  3505. }
  3506. return TRUE;
  3507. }
  3508. /******************************************************************************
  3509. * Verifies that the EEPROM has a valid checksum
  3510. *
  3511. * hw - Struct containing variables accessed by shared code
  3512. *
  3513. * Reads the first 64 16 bit words of the EEPROM and sums the values read.
  3514. * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
  3515. * valid.
  3516. *****************************************************************************/
  3517. int32_t
  3518. e1000_validate_eeprom_checksum(struct e1000_hw *hw)
  3519. {
  3520. uint16_t checksum = 0;
  3521. uint16_t i, eeprom_data;
  3522. DEBUGFUNC("e1000_validate_eeprom_checksum");
  3523. if ((hw->mac_type == e1000_82573) &&
  3524. (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
  3525. /* Check bit 4 of word 10h. If it is 0, firmware is done updating
  3526. * 10h-12h. Checksum may need to be fixed. */
  3527. e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
  3528. if ((eeprom_data & 0x10) == 0) {
  3529. /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
  3530. * has already been fixed. If the checksum is still wrong and this
  3531. * bit is a 1, we need to return bad checksum. Otherwise, we need
  3532. * to set this bit to a 1 and update the checksum. */
  3533. e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
  3534. if ((eeprom_data & 0x8000) == 0) {
  3535. eeprom_data |= 0x8000;
  3536. e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
  3537. e1000_update_eeprom_checksum(hw);
  3538. }
  3539. }
  3540. }
  3541. for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
  3542. if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
  3543. DEBUGOUT("EEPROM Read Error\n");
  3544. return -E1000_ERR_EEPROM;
  3545. }
  3546. checksum += eeprom_data;
  3547. }
  3548. if(checksum == (uint16_t) EEPROM_SUM)
  3549. return E1000_SUCCESS;
  3550. else {
  3551. DEBUGOUT("EEPROM Checksum Invalid\n");
  3552. return -E1000_ERR_EEPROM;
  3553. }
  3554. }
  3555. /******************************************************************************
  3556. * Calculates the EEPROM checksum and writes it to the EEPROM
  3557. *
  3558. * hw - Struct containing variables accessed by shared code
  3559. *
  3560. * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
  3561. * Writes the difference to word offset 63 of the EEPROM.
  3562. *****************************************************************************/
  3563. int32_t
  3564. e1000_update_eeprom_checksum(struct e1000_hw *hw)
  3565. {
  3566. uint16_t checksum = 0;
  3567. uint16_t i, eeprom_data;
  3568. DEBUGFUNC("e1000_update_eeprom_checksum");
  3569. for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
  3570. if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
  3571. DEBUGOUT("EEPROM Read Error\n");
  3572. return -E1000_ERR_EEPROM;
  3573. }
  3574. checksum += eeprom_data;
  3575. }
  3576. checksum = (uint16_t) EEPROM_SUM - checksum;
  3577. if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
  3578. DEBUGOUT("EEPROM Write Error\n");
  3579. return -E1000_ERR_EEPROM;
  3580. } else if (hw->eeprom.type == e1000_eeprom_flash) {
  3581. e1000_commit_shadow_ram(hw);
  3582. }
  3583. return E1000_SUCCESS;
  3584. }
  3585. /******************************************************************************
  3586. * Parent function for writing words to the different EEPROM types.
  3587. *
  3588. * hw - Struct containing variables accessed by shared code
  3589. * offset - offset within the EEPROM to be written to
  3590. * words - number of words to write
  3591. * data - 16 bit word to be written to the EEPROM
  3592. *
  3593. * If e1000_update_eeprom_checksum is not called after this function, the
  3594. * EEPROM will most likely contain an invalid checksum.
  3595. *****************************************************************************/
  3596. int32_t
  3597. e1000_write_eeprom(struct e1000_hw *hw,
  3598. uint16_t offset,
  3599. uint16_t words,
  3600. uint16_t *data)
  3601. {
  3602. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3603. int32_t status = 0;
  3604. DEBUGFUNC("e1000_write_eeprom");
  3605. /* A check for invalid values: offset too large, too many words, and not
  3606. * enough words.
  3607. */
  3608. if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
  3609. (words == 0)) {
  3610. DEBUGOUT("\"words\" parameter out of bounds\n");
  3611. return -E1000_ERR_EEPROM;
  3612. }
  3613. /* 82573 writes only through eewr */
  3614. if(eeprom->use_eewr == TRUE)
  3615. return e1000_write_eeprom_eewr(hw, offset, words, data);
  3616. /* Prepare the EEPROM for writing */
  3617. if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
  3618. return -E1000_ERR_EEPROM;
  3619. if(eeprom->type == e1000_eeprom_microwire) {
  3620. status = e1000_write_eeprom_microwire(hw, offset, words, data);
  3621. } else {
  3622. status = e1000_write_eeprom_spi(hw, offset, words, data);
  3623. msec_delay(10);
  3624. }
  3625. /* Done with writing */
  3626. e1000_release_eeprom(hw);
  3627. return status;
  3628. }
  3629. /******************************************************************************
  3630. * Writes a 16 bit word to a given offset in an SPI EEPROM.
  3631. *
  3632. * hw - Struct containing variables accessed by shared code
  3633. * offset - offset within the EEPROM to be written to
  3634. * words - number of words to write
  3635. * data - pointer to array of 8 bit words to be written to the EEPROM
  3636. *
  3637. *****************************************************************************/
  3638. int32_t
  3639. e1000_write_eeprom_spi(struct e1000_hw *hw,
  3640. uint16_t offset,
  3641. uint16_t words,
  3642. uint16_t *data)
  3643. {
  3644. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3645. uint16_t widx = 0;
  3646. DEBUGFUNC("e1000_write_eeprom_spi");
  3647. while (widx < words) {
  3648. uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
  3649. if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
  3650. e1000_standby_eeprom(hw);
  3651. /* Send the WRITE ENABLE command (8 bit opcode ) */
  3652. e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
  3653. eeprom->opcode_bits);
  3654. e1000_standby_eeprom(hw);
  3655. /* Some SPI eeproms use the 8th address bit embedded in the opcode */
  3656. if((eeprom->address_bits == 8) && (offset >= 128))
  3657. write_opcode |= EEPROM_A8_OPCODE_SPI;
  3658. /* Send the Write command (8-bit opcode + addr) */
  3659. e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
  3660. e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
  3661. eeprom->address_bits);
  3662. /* Send the data */
  3663. /* Loop to allow for up to whole page write (32 bytes) of eeprom */
  3664. while (widx < words) {
  3665. uint16_t word_out = data[widx];
  3666. word_out = (word_out >> 8) | (word_out << 8);
  3667. e1000_shift_out_ee_bits(hw, word_out, 16);
  3668. widx++;
  3669. /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
  3670. * operation, while the smaller eeproms are capable of an 8-byte
  3671. * PAGE WRITE operation. Break the inner loop to pass new address
  3672. */
  3673. if((((offset + widx)*2) % eeprom->page_size) == 0) {
  3674. e1000_standby_eeprom(hw);
  3675. break;
  3676. }
  3677. }
  3678. }
  3679. return E1000_SUCCESS;
  3680. }
  3681. /******************************************************************************
  3682. * Writes a 16 bit word to a given offset in a Microwire EEPROM.
  3683. *
  3684. * hw - Struct containing variables accessed by shared code
  3685. * offset - offset within the EEPROM to be written to
  3686. * words - number of words to write
  3687. * data - pointer to array of 16 bit words to be written to the EEPROM
  3688. *
  3689. *****************************************************************************/
  3690. int32_t
  3691. e1000_write_eeprom_microwire(struct e1000_hw *hw,
  3692. uint16_t offset,
  3693. uint16_t words,
  3694. uint16_t *data)
  3695. {
  3696. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3697. uint32_t eecd;
  3698. uint16_t words_written = 0;
  3699. uint16_t i = 0;
  3700. DEBUGFUNC("e1000_write_eeprom_microwire");
  3701. /* Send the write enable command to the EEPROM (3-bit opcode plus
  3702. * 6/8-bit dummy address beginning with 11). It's less work to include
  3703. * the 11 of the dummy address as part of the opcode than it is to shift
  3704. * it over the correct number of bits for the address. This puts the
  3705. * EEPROM into write/erase mode.
  3706. */
  3707. e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
  3708. (uint16_t)(eeprom->opcode_bits + 2));
  3709. e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
  3710. /* Prepare the EEPROM */
  3711. e1000_standby_eeprom(hw);
  3712. while (words_written < words) {
  3713. /* Send the Write command (3-bit opcode + addr) */
  3714. e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
  3715. eeprom->opcode_bits);
  3716. e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
  3717. eeprom->address_bits);
  3718. /* Send the data */
  3719. e1000_shift_out_ee_bits(hw, data[words_written], 16);
  3720. /* Toggle the CS line. This in effect tells the EEPROM to execute
  3721. * the previous command.
  3722. */
  3723. e1000_standby_eeprom(hw);
  3724. /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
  3725. * signal that the command has been completed by raising the DO signal.
  3726. * If DO does not go high in 10 milliseconds, then error out.
  3727. */
  3728. for(i = 0; i < 200; i++) {
  3729. eecd = E1000_READ_REG(hw, EECD);
  3730. if(eecd & E1000_EECD_DO) break;
  3731. usec_delay(50);
  3732. }
  3733. if(i == 200) {
  3734. DEBUGOUT("EEPROM Write did not complete\n");
  3735. return -E1000_ERR_EEPROM;
  3736. }
  3737. /* Recover from write */
  3738. e1000_standby_eeprom(hw);
  3739. words_written++;
  3740. }
  3741. /* Send the write disable command to the EEPROM (3-bit opcode plus
  3742. * 6/8-bit dummy address beginning with 10). It's less work to include
  3743. * the 10 of the dummy address as part of the opcode than it is to shift
  3744. * it over the correct number of bits for the address. This takes the
  3745. * EEPROM out of write/erase mode.
  3746. */
  3747. e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
  3748. (uint16_t)(eeprom->opcode_bits + 2));
  3749. e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
  3750. return E1000_SUCCESS;
  3751. }
  3752. /******************************************************************************
  3753. * Flushes the cached eeprom to NVM. This is done by saving the modified values
  3754. * in the eeprom cache and the non modified values in the currently active bank
  3755. * to the new bank.
  3756. *
  3757. * hw - Struct containing variables accessed by shared code
  3758. * offset - offset of word in the EEPROM to read
  3759. * data - word read from the EEPROM
  3760. * words - number of words to read
  3761. *****************************************************************************/
  3762. int32_t
  3763. e1000_commit_shadow_ram(struct e1000_hw *hw)
  3764. {
  3765. uint32_t attempts = 100000;
  3766. uint32_t eecd = 0;
  3767. uint32_t flop = 0;
  3768. uint32_t i = 0;
  3769. int32_t error = E1000_SUCCESS;
  3770. /* The flop register will be used to determine if flash type is STM */
  3771. flop = E1000_READ_REG(hw, FLOP);
  3772. if (hw->mac_type == e1000_82573) {
  3773. for (i=0; i < attempts; i++) {
  3774. eecd = E1000_READ_REG(hw, EECD);
  3775. if ((eecd & E1000_EECD_FLUPD) == 0) {
  3776. break;
  3777. }
  3778. usec_delay(5);
  3779. }
  3780. if (i == attempts) {
  3781. return -E1000_ERR_EEPROM;
  3782. }
  3783. /* If STM opcode located in bits 15:8 of flop, reset firmware */
  3784. if ((flop & 0xFF00) == E1000_STM_OPCODE) {
  3785. E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
  3786. }
  3787. /* Perform the flash update */
  3788. E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
  3789. for (i=0; i < attempts; i++) {
  3790. eecd = E1000_READ_REG(hw, EECD);
  3791. if ((eecd & E1000_EECD_FLUPD) == 0) {
  3792. break;
  3793. }
  3794. usec_delay(5);
  3795. }
  3796. if (i == attempts) {
  3797. return -E1000_ERR_EEPROM;
  3798. }
  3799. }
  3800. return error;
  3801. }
  3802. /******************************************************************************
  3803. * Reads the adapter's part number from the EEPROM
  3804. *
  3805. * hw - Struct containing variables accessed by shared code
  3806. * part_num - Adapter's part number
  3807. *****************************************************************************/
  3808. int32_t
  3809. e1000_read_part_num(struct e1000_hw *hw,
  3810. uint32_t *part_num)
  3811. {
  3812. uint16_t offset = EEPROM_PBA_BYTE_1;
  3813. uint16_t eeprom_data;
  3814. DEBUGFUNC("e1000_read_part_num");
  3815. /* Get word 0 from EEPROM */
  3816. if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
  3817. DEBUGOUT("EEPROM Read Error\n");
  3818. return -E1000_ERR_EEPROM;
  3819. }
  3820. /* Save word 0 in upper half of part_num */
  3821. *part_num = (uint32_t) (eeprom_data << 16);
  3822. /* Get word 1 from EEPROM */
  3823. if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
  3824. DEBUGOUT("EEPROM Read Error\n");
  3825. return -E1000_ERR_EEPROM;
  3826. }
  3827. /* Save word 1 in lower half of part_num */
  3828. *part_num |= eeprom_data;
  3829. return E1000_SUCCESS;
  3830. }
  3831. /******************************************************************************
  3832. * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
  3833. * second function of dual function devices
  3834. *
  3835. * hw - Struct containing variables accessed by shared code
  3836. *****************************************************************************/
  3837. int32_t
  3838. e1000_read_mac_addr(struct e1000_hw * hw)
  3839. {
  3840. uint16_t offset;
  3841. uint16_t eeprom_data, i;
  3842. DEBUGFUNC("e1000_read_mac_addr");
  3843. for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
  3844. offset = i >> 1;
  3845. if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
  3846. DEBUGOUT("EEPROM Read Error\n");
  3847. return -E1000_ERR_EEPROM;
  3848. }
  3849. hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
  3850. hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
  3851. }
  3852. switch (hw->mac_type) {
  3853. default:
  3854. break;
  3855. case e1000_82546:
  3856. case e1000_82546_rev_3:
  3857. case e1000_82571:
  3858. if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
  3859. hw->perm_mac_addr[5] ^= 0x01;
  3860. break;
  3861. }
  3862. for(i = 0; i < NODE_ADDRESS_SIZE; i++)
  3863. hw->mac_addr[i] = hw->perm_mac_addr[i];
  3864. return E1000_SUCCESS;
  3865. }
  3866. /******************************************************************************
  3867. * Initializes receive address filters.
  3868. *
  3869. * hw - Struct containing variables accessed by shared code
  3870. *
  3871. * Places the MAC address in receive address register 0 and clears the rest
  3872. * of the receive addresss registers. Clears the multicast table. Assumes
  3873. * the receiver is in reset when the routine is called.
  3874. *****************************************************************************/
  3875. void
  3876. e1000_init_rx_addrs(struct e1000_hw *hw)
  3877. {
  3878. uint32_t i;
  3879. uint32_t rar_num;
  3880. DEBUGFUNC("e1000_init_rx_addrs");
  3881. /* Setup the receive address. */
  3882. DEBUGOUT("Programming MAC Address into RAR[0]\n");
  3883. e1000_rar_set(hw, hw->mac_addr, 0);
  3884. rar_num = E1000_RAR_ENTRIES;
  3885. /* Reserve a spot for the Locally Administered Address to work around
  3886. * an 82571 issue in which a reset on one port will reload the MAC on
  3887. * the other port. */
  3888. if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
  3889. rar_num -= 1;
  3890. /* Zero out the other 15 receive addresses. */
  3891. DEBUGOUT("Clearing RAR[1-15]\n");
  3892. for(i = 1; i < rar_num; i++) {
  3893. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
  3894. E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
  3895. }
  3896. }
  3897. /******************************************************************************
  3898. * Updates the MAC's list of multicast addresses.
  3899. *
  3900. * hw - Struct containing variables accessed by shared code
  3901. * mc_addr_list - the list of new multicast addresses
  3902. * mc_addr_count - number of addresses
  3903. * pad - number of bytes between addresses in the list
  3904. * rar_used_count - offset where to start adding mc addresses into the RAR's
  3905. *
  3906. * The given list replaces any existing list. Clears the last 15 receive
  3907. * address registers and the multicast table. Uses receive address registers
  3908. * for the first 15 multicast addresses, and hashes the rest into the
  3909. * multicast table.
  3910. *****************************************************************************/
  3911. void
  3912. e1000_mc_addr_list_update(struct e1000_hw *hw,
  3913. uint8_t *mc_addr_list,
  3914. uint32_t mc_addr_count,
  3915. uint32_t pad,
  3916. uint32_t rar_used_count)
  3917. {
  3918. uint32_t hash_value;
  3919. uint32_t i;
  3920. uint32_t num_rar_entry;
  3921. uint32_t num_mta_entry;
  3922. DEBUGFUNC("e1000_mc_addr_list_update");
  3923. /* Set the new number of MC addresses that we are being requested to use. */
  3924. hw->num_mc_addrs = mc_addr_count;
  3925. /* Clear RAR[1-15] */
  3926. DEBUGOUT(" Clearing RAR[1-15]\n");
  3927. num_rar_entry = E1000_RAR_ENTRIES;
  3928. /* Reserve a spot for the Locally Administered Address to work around
  3929. * an 82571 issue in which a reset on one port will reload the MAC on
  3930. * the other port. */
  3931. if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
  3932. num_rar_entry -= 1;
  3933. for(i = rar_used_count; i < num_rar_entry; i++) {
  3934. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
  3935. E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
  3936. }
  3937. /* Clear the MTA */
  3938. DEBUGOUT(" Clearing MTA\n");
  3939. num_mta_entry = E1000_NUM_MTA_REGISTERS;
  3940. for(i = 0; i < num_mta_entry; i++) {
  3941. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  3942. }
  3943. /* Add the new addresses */
  3944. for(i = 0; i < mc_addr_count; i++) {
  3945. DEBUGOUT(" Adding the multicast addresses:\n");
  3946. DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
  3947. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
  3948. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
  3949. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
  3950. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
  3951. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
  3952. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
  3953. hash_value = e1000_hash_mc_addr(hw,
  3954. mc_addr_list +
  3955. (i * (ETH_LENGTH_OF_ADDRESS + pad)));
  3956. DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
  3957. /* Place this multicast address in the RAR if there is room, *
  3958. * else put it in the MTA
  3959. */
  3960. if (rar_used_count < num_rar_entry) {
  3961. e1000_rar_set(hw,
  3962. mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
  3963. rar_used_count);
  3964. rar_used_count++;
  3965. } else {
  3966. e1000_mta_set(hw, hash_value);
  3967. }
  3968. }
  3969. DEBUGOUT("MC Update Complete\n");
  3970. }
  3971. /******************************************************************************
  3972. * Hashes an address to determine its location in the multicast table
  3973. *
  3974. * hw - Struct containing variables accessed by shared code
  3975. * mc_addr - the multicast address to hash
  3976. *****************************************************************************/
  3977. uint32_t
  3978. e1000_hash_mc_addr(struct e1000_hw *hw,
  3979. uint8_t *mc_addr)
  3980. {
  3981. uint32_t hash_value = 0;
  3982. /* The portion of the address that is used for the hash table is
  3983. * determined by the mc_filter_type setting.
  3984. */
  3985. switch (hw->mc_filter_type) {
  3986. /* [0] [1] [2] [3] [4] [5]
  3987. * 01 AA 00 12 34 56
  3988. * LSB MSB
  3989. */
  3990. case 0:
  3991. /* [47:36] i.e. 0x563 for above example address */
  3992. hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
  3993. break;
  3994. case 1:
  3995. /* [46:35] i.e. 0xAC6 for above example address */
  3996. hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
  3997. break;
  3998. case 2:
  3999. /* [45:34] i.e. 0x5D8 for above example address */
  4000. hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
  4001. break;
  4002. case 3:
  4003. /* [43:32] i.e. 0x634 for above example address */
  4004. hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
  4005. break;
  4006. }
  4007. hash_value &= 0xFFF;
  4008. return hash_value;
  4009. }
  4010. /******************************************************************************
  4011. * Sets the bit in the multicast table corresponding to the hash value.
  4012. *
  4013. * hw - Struct containing variables accessed by shared code
  4014. * hash_value - Multicast address hash value
  4015. *****************************************************************************/
  4016. void
  4017. e1000_mta_set(struct e1000_hw *hw,
  4018. uint32_t hash_value)
  4019. {
  4020. uint32_t hash_bit, hash_reg;
  4021. uint32_t mta;
  4022. uint32_t temp;
  4023. /* The MTA is a register array of 128 32-bit registers.
  4024. * It is treated like an array of 4096 bits. We want to set
  4025. * bit BitArray[hash_value]. So we figure out what register
  4026. * the bit is in, read it, OR in the new bit, then write
  4027. * back the new value. The register is determined by the
  4028. * upper 7 bits of the hash value and the bit within that
  4029. * register are determined by the lower 5 bits of the value.
  4030. */
  4031. hash_reg = (hash_value >> 5) & 0x7F;
  4032. hash_bit = hash_value & 0x1F;
  4033. mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
  4034. mta |= (1 << hash_bit);
  4035. /* If we are on an 82544 and we are trying to write an odd offset
  4036. * in the MTA, save off the previous entry before writing and
  4037. * restore the old value after writing.
  4038. */
  4039. if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
  4040. temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
  4041. E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
  4042. E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
  4043. } else {
  4044. E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
  4045. }
  4046. }
  4047. /******************************************************************************
  4048. * Puts an ethernet address into a receive address register.
  4049. *
  4050. * hw - Struct containing variables accessed by shared code
  4051. * addr - Address to put into receive address register
  4052. * index - Receive address register to write
  4053. *****************************************************************************/
  4054. void
  4055. e1000_rar_set(struct e1000_hw *hw,
  4056. uint8_t *addr,
  4057. uint32_t index)
  4058. {
  4059. uint32_t rar_low, rar_high;
  4060. /* HW expects these in little endian so we reverse the byte order
  4061. * from network order (big endian) to little endian
  4062. */
  4063. rar_low = ((uint32_t) addr[0] |
  4064. ((uint32_t) addr[1] << 8) |
  4065. ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
  4066. rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8) | E1000_RAH_AV);
  4067. E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
  4068. E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
  4069. }
  4070. /******************************************************************************
  4071. * Writes a value to the specified offset in the VLAN filter table.
  4072. *
  4073. * hw - Struct containing variables accessed by shared code
  4074. * offset - Offset in VLAN filer table to write
  4075. * value - Value to write into VLAN filter table
  4076. *****************************************************************************/
  4077. void
  4078. e1000_write_vfta(struct e1000_hw *hw,
  4079. uint32_t offset,
  4080. uint32_t value)
  4081. {
  4082. uint32_t temp;
  4083. if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
  4084. temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
  4085. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
  4086. E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
  4087. } else {
  4088. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
  4089. }
  4090. }
  4091. /******************************************************************************
  4092. * Clears the VLAN filer table
  4093. *
  4094. * hw - Struct containing variables accessed by shared code
  4095. *****************************************************************************/
  4096. void
  4097. e1000_clear_vfta(struct e1000_hw *hw)
  4098. {
  4099. uint32_t offset;
  4100. uint32_t vfta_value = 0;
  4101. uint32_t vfta_offset = 0;
  4102. uint32_t vfta_bit_in_reg = 0;
  4103. if (hw->mac_type == e1000_82573) {
  4104. if (hw->mng_cookie.vlan_id != 0) {
  4105. /* The VFTA is a 4096b bit-field, each identifying a single VLAN
  4106. * ID. The following operations determine which 32b entry
  4107. * (i.e. offset) into the array we want to set the VLAN ID
  4108. * (i.e. bit) of the manageability unit. */
  4109. vfta_offset = (hw->mng_cookie.vlan_id >>
  4110. E1000_VFTA_ENTRY_SHIFT) &
  4111. E1000_VFTA_ENTRY_MASK;
  4112. vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
  4113. E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
  4114. }
  4115. }
  4116. for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
  4117. /* If the offset we want to clear is the same offset of the
  4118. * manageability VLAN ID, then clear all bits except that of the
  4119. * manageability unit */
  4120. vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
  4121. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
  4122. }
  4123. }
  4124. int32_t
  4125. e1000_id_led_init(struct e1000_hw * hw)
  4126. {
  4127. uint32_t ledctl;
  4128. const uint32_t ledctl_mask = 0x000000FF;
  4129. const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
  4130. const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
  4131. uint16_t eeprom_data, i, temp;
  4132. const uint16_t led_mask = 0x0F;
  4133. DEBUGFUNC("e1000_id_led_init");
  4134. if(hw->mac_type < e1000_82540) {
  4135. /* Nothing to do */
  4136. return E1000_SUCCESS;
  4137. }
  4138. ledctl = E1000_READ_REG(hw, LEDCTL);
  4139. hw->ledctl_default = ledctl;
  4140. hw->ledctl_mode1 = hw->ledctl_default;
  4141. hw->ledctl_mode2 = hw->ledctl_default;
  4142. if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
  4143. DEBUGOUT("EEPROM Read Error\n");
  4144. return -E1000_ERR_EEPROM;
  4145. }
  4146. if((eeprom_data== ID_LED_RESERVED_0000) ||
  4147. (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
  4148. for(i = 0; i < 4; i++) {
  4149. temp = (eeprom_data >> (i << 2)) & led_mask;
  4150. switch(temp) {
  4151. case ID_LED_ON1_DEF2:
  4152. case ID_LED_ON1_ON2:
  4153. case ID_LED_ON1_OFF2:
  4154. hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  4155. hw->ledctl_mode1 |= ledctl_on << (i << 3);
  4156. break;
  4157. case ID_LED_OFF1_DEF2:
  4158. case ID_LED_OFF1_ON2:
  4159. case ID_LED_OFF1_OFF2:
  4160. hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  4161. hw->ledctl_mode1 |= ledctl_off << (i << 3);
  4162. break;
  4163. default:
  4164. /* Do nothing */
  4165. break;
  4166. }
  4167. switch(temp) {
  4168. case ID_LED_DEF1_ON2:
  4169. case ID_LED_ON1_ON2:
  4170. case ID_LED_OFF1_ON2:
  4171. hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  4172. hw->ledctl_mode2 |= ledctl_on << (i << 3);
  4173. break;
  4174. case ID_LED_DEF1_OFF2:
  4175. case ID_LED_ON1_OFF2:
  4176. case ID_LED_OFF1_OFF2:
  4177. hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  4178. hw->ledctl_mode2 |= ledctl_off << (i << 3);
  4179. break;
  4180. default:
  4181. /* Do nothing */
  4182. break;
  4183. }
  4184. }
  4185. return E1000_SUCCESS;
  4186. }
  4187. /******************************************************************************
  4188. * Prepares SW controlable LED for use and saves the current state of the LED.
  4189. *
  4190. * hw - Struct containing variables accessed by shared code
  4191. *****************************************************************************/
  4192. int32_t
  4193. e1000_setup_led(struct e1000_hw *hw)
  4194. {
  4195. uint32_t ledctl;
  4196. int32_t ret_val = E1000_SUCCESS;
  4197. DEBUGFUNC("e1000_setup_led");
  4198. switch(hw->mac_type) {
  4199. case e1000_82542_rev2_0:
  4200. case e1000_82542_rev2_1:
  4201. case e1000_82543:
  4202. case e1000_82544:
  4203. /* No setup necessary */
  4204. break;
  4205. case e1000_82541:
  4206. case e1000_82547:
  4207. case e1000_82541_rev_2:
  4208. case e1000_82547_rev_2:
  4209. /* Turn off PHY Smart Power Down (if enabled) */
  4210. ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
  4211. &hw->phy_spd_default);
  4212. if(ret_val)
  4213. return ret_val;
  4214. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
  4215. (uint16_t)(hw->phy_spd_default &
  4216. ~IGP01E1000_GMII_SPD));
  4217. if(ret_val)
  4218. return ret_val;
  4219. /* Fall Through */
  4220. default:
  4221. if(hw->media_type == e1000_media_type_fiber) {
  4222. ledctl = E1000_READ_REG(hw, LEDCTL);
  4223. /* Save current LEDCTL settings */
  4224. hw->ledctl_default = ledctl;
  4225. /* Turn off LED0 */
  4226. ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
  4227. E1000_LEDCTL_LED0_BLINK |
  4228. E1000_LEDCTL_LED0_MODE_MASK);
  4229. ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
  4230. E1000_LEDCTL_LED0_MODE_SHIFT);
  4231. E1000_WRITE_REG(hw, LEDCTL, ledctl);
  4232. } else if(hw->media_type == e1000_media_type_copper)
  4233. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
  4234. break;
  4235. }
  4236. return E1000_SUCCESS;
  4237. }
  4238. /******************************************************************************
  4239. * Restores the saved state of the SW controlable LED.
  4240. *
  4241. * hw - Struct containing variables accessed by shared code
  4242. *****************************************************************************/
  4243. int32_t
  4244. e1000_cleanup_led(struct e1000_hw *hw)
  4245. {
  4246. int32_t ret_val = E1000_SUCCESS;
  4247. DEBUGFUNC("e1000_cleanup_led");
  4248. switch(hw->mac_type) {
  4249. case e1000_82542_rev2_0:
  4250. case e1000_82542_rev2_1:
  4251. case e1000_82543:
  4252. case e1000_82544:
  4253. /* No cleanup necessary */
  4254. break;
  4255. case e1000_82541:
  4256. case e1000_82547:
  4257. case e1000_82541_rev_2:
  4258. case e1000_82547_rev_2:
  4259. /* Turn on PHY Smart Power Down (if previously enabled) */
  4260. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
  4261. hw->phy_spd_default);
  4262. if(ret_val)
  4263. return ret_val;
  4264. /* Fall Through */
  4265. default:
  4266. /* Restore LEDCTL settings */
  4267. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
  4268. break;
  4269. }
  4270. return E1000_SUCCESS;
  4271. }
  4272. /******************************************************************************
  4273. * Turns on the software controllable LED
  4274. *
  4275. * hw - Struct containing variables accessed by shared code
  4276. *****************************************************************************/
  4277. int32_t
  4278. e1000_led_on(struct e1000_hw *hw)
  4279. {
  4280. uint32_t ctrl = E1000_READ_REG(hw, CTRL);
  4281. DEBUGFUNC("e1000_led_on");
  4282. switch(hw->mac_type) {
  4283. case e1000_82542_rev2_0:
  4284. case e1000_82542_rev2_1:
  4285. case e1000_82543:
  4286. /* Set SW Defineable Pin 0 to turn on the LED */
  4287. ctrl |= E1000_CTRL_SWDPIN0;
  4288. ctrl |= E1000_CTRL_SWDPIO0;
  4289. break;
  4290. case e1000_82544:
  4291. if(hw->media_type == e1000_media_type_fiber) {
  4292. /* Set SW Defineable Pin 0 to turn on the LED */
  4293. ctrl |= E1000_CTRL_SWDPIN0;
  4294. ctrl |= E1000_CTRL_SWDPIO0;
  4295. } else {
  4296. /* Clear SW Defineable Pin 0 to turn on the LED */
  4297. ctrl &= ~E1000_CTRL_SWDPIN0;
  4298. ctrl |= E1000_CTRL_SWDPIO0;
  4299. }
  4300. break;
  4301. default:
  4302. if(hw->media_type == e1000_media_type_fiber) {
  4303. /* Clear SW Defineable Pin 0 to turn on the LED */
  4304. ctrl &= ~E1000_CTRL_SWDPIN0;
  4305. ctrl |= E1000_CTRL_SWDPIO0;
  4306. } else if(hw->media_type == e1000_media_type_copper) {
  4307. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
  4308. return E1000_SUCCESS;
  4309. }
  4310. break;
  4311. }
  4312. E1000_WRITE_REG(hw, CTRL, ctrl);
  4313. return E1000_SUCCESS;
  4314. }
  4315. /******************************************************************************
  4316. * Turns off the software controllable LED
  4317. *
  4318. * hw - Struct containing variables accessed by shared code
  4319. *****************************************************************************/
  4320. int32_t
  4321. e1000_led_off(struct e1000_hw *hw)
  4322. {
  4323. uint32_t ctrl = E1000_READ_REG(hw, CTRL);
  4324. DEBUGFUNC("e1000_led_off");
  4325. switch(hw->mac_type) {
  4326. case e1000_82542_rev2_0:
  4327. case e1000_82542_rev2_1:
  4328. case e1000_82543:
  4329. /* Clear SW Defineable Pin 0 to turn off the LED */
  4330. ctrl &= ~E1000_CTRL_SWDPIN0;
  4331. ctrl |= E1000_CTRL_SWDPIO0;
  4332. break;
  4333. case e1000_82544:
  4334. if(hw->media_type == e1000_media_type_fiber) {
  4335. /* Clear SW Defineable Pin 0 to turn off the LED */
  4336. ctrl &= ~E1000_CTRL_SWDPIN0;
  4337. ctrl |= E1000_CTRL_SWDPIO0;
  4338. } else {
  4339. /* Set SW Defineable Pin 0 to turn off the LED */
  4340. ctrl |= E1000_CTRL_SWDPIN0;
  4341. ctrl |= E1000_CTRL_SWDPIO0;
  4342. }
  4343. break;
  4344. default:
  4345. if(hw->media_type == e1000_media_type_fiber) {
  4346. /* Set SW Defineable Pin 0 to turn off the LED */
  4347. ctrl |= E1000_CTRL_SWDPIN0;
  4348. ctrl |= E1000_CTRL_SWDPIO0;
  4349. } else if(hw->media_type == e1000_media_type_copper) {
  4350. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
  4351. return E1000_SUCCESS;
  4352. }
  4353. break;
  4354. }
  4355. E1000_WRITE_REG(hw, CTRL, ctrl);
  4356. return E1000_SUCCESS;
  4357. }
  4358. /******************************************************************************
  4359. * Clears all hardware statistics counters.
  4360. *
  4361. * hw - Struct containing variables accessed by shared code
  4362. *****************************************************************************/
  4363. void
  4364. e1000_clear_hw_cntrs(struct e1000_hw *hw)
  4365. {
  4366. volatile uint32_t temp;
  4367. temp = E1000_READ_REG(hw, CRCERRS);
  4368. temp = E1000_READ_REG(hw, SYMERRS);
  4369. temp = E1000_READ_REG(hw, MPC);
  4370. temp = E1000_READ_REG(hw, SCC);
  4371. temp = E1000_READ_REG(hw, ECOL);
  4372. temp = E1000_READ_REG(hw, MCC);
  4373. temp = E1000_READ_REG(hw, LATECOL);
  4374. temp = E1000_READ_REG(hw, COLC);
  4375. temp = E1000_READ_REG(hw, DC);
  4376. temp = E1000_READ_REG(hw, SEC);
  4377. temp = E1000_READ_REG(hw, RLEC);
  4378. temp = E1000_READ_REG(hw, XONRXC);
  4379. temp = E1000_READ_REG(hw, XONTXC);
  4380. temp = E1000_READ_REG(hw, XOFFRXC);
  4381. temp = E1000_READ_REG(hw, XOFFTXC);
  4382. temp = E1000_READ_REG(hw, FCRUC);
  4383. temp = E1000_READ_REG(hw, PRC64);
  4384. temp = E1000_READ_REG(hw, PRC127);
  4385. temp = E1000_READ_REG(hw, PRC255);
  4386. temp = E1000_READ_REG(hw, PRC511);
  4387. temp = E1000_READ_REG(hw, PRC1023);
  4388. temp = E1000_READ_REG(hw, PRC1522);
  4389. temp = E1000_READ_REG(hw, GPRC);
  4390. temp = E1000_READ_REG(hw, BPRC);
  4391. temp = E1000_READ_REG(hw, MPRC);
  4392. temp = E1000_READ_REG(hw, GPTC);
  4393. temp = E1000_READ_REG(hw, GORCL);
  4394. temp = E1000_READ_REG(hw, GORCH);
  4395. temp = E1000_READ_REG(hw, GOTCL);
  4396. temp = E1000_READ_REG(hw, GOTCH);
  4397. temp = E1000_READ_REG(hw, RNBC);
  4398. temp = E1000_READ_REG(hw, RUC);
  4399. temp = E1000_READ_REG(hw, RFC);
  4400. temp = E1000_READ_REG(hw, ROC);
  4401. temp = E1000_READ_REG(hw, RJC);
  4402. temp = E1000_READ_REG(hw, TORL);
  4403. temp = E1000_READ_REG(hw, TORH);
  4404. temp = E1000_READ_REG(hw, TOTL);
  4405. temp = E1000_READ_REG(hw, TOTH);
  4406. temp = E1000_READ_REG(hw, TPR);
  4407. temp = E1000_READ_REG(hw, TPT);
  4408. temp = E1000_READ_REG(hw, PTC64);
  4409. temp = E1000_READ_REG(hw, PTC127);
  4410. temp = E1000_READ_REG(hw, PTC255);
  4411. temp = E1000_READ_REG(hw, PTC511);
  4412. temp = E1000_READ_REG(hw, PTC1023);
  4413. temp = E1000_READ_REG(hw, PTC1522);
  4414. temp = E1000_READ_REG(hw, MPTC);
  4415. temp = E1000_READ_REG(hw, BPTC);
  4416. if(hw->mac_type < e1000_82543) return;
  4417. temp = E1000_READ_REG(hw, ALGNERRC);
  4418. temp = E1000_READ_REG(hw, RXERRC);
  4419. temp = E1000_READ_REG(hw, TNCRS);
  4420. temp = E1000_READ_REG(hw, CEXTERR);
  4421. temp = E1000_READ_REG(hw, TSCTC);
  4422. temp = E1000_READ_REG(hw, TSCTFC);
  4423. if(hw->mac_type <= e1000_82544) return;
  4424. temp = E1000_READ_REG(hw, MGTPRC);
  4425. temp = E1000_READ_REG(hw, MGTPDC);
  4426. temp = E1000_READ_REG(hw, MGTPTC);
  4427. if(hw->mac_type <= e1000_82547_rev_2) return;
  4428. temp = E1000_READ_REG(hw, IAC);
  4429. temp = E1000_READ_REG(hw, ICRXOC);
  4430. temp = E1000_READ_REG(hw, ICRXPTC);
  4431. temp = E1000_READ_REG(hw, ICRXATC);
  4432. temp = E1000_READ_REG(hw, ICTXPTC);
  4433. temp = E1000_READ_REG(hw, ICTXATC);
  4434. temp = E1000_READ_REG(hw, ICTXQEC);
  4435. temp = E1000_READ_REG(hw, ICTXQMTC);
  4436. temp = E1000_READ_REG(hw, ICRXDMTC);
  4437. }
  4438. /******************************************************************************
  4439. * Resets Adaptive IFS to its default state.
  4440. *
  4441. * hw - Struct containing variables accessed by shared code
  4442. *
  4443. * Call this after e1000_init_hw. You may override the IFS defaults by setting
  4444. * hw->ifs_params_forced to TRUE. However, you must initialize hw->
  4445. * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
  4446. * before calling this function.
  4447. *****************************************************************************/
  4448. void
  4449. e1000_reset_adaptive(struct e1000_hw *hw)
  4450. {
  4451. DEBUGFUNC("e1000_reset_adaptive");
  4452. if(hw->adaptive_ifs) {
  4453. if(!hw->ifs_params_forced) {
  4454. hw->current_ifs_val = 0;
  4455. hw->ifs_min_val = IFS_MIN;
  4456. hw->ifs_max_val = IFS_MAX;
  4457. hw->ifs_step_size = IFS_STEP;
  4458. hw->ifs_ratio = IFS_RATIO;
  4459. }
  4460. hw->in_ifs_mode = FALSE;
  4461. E1000_WRITE_REG(hw, AIT, 0);
  4462. } else {
  4463. DEBUGOUT("Not in Adaptive IFS mode!\n");
  4464. }
  4465. }
  4466. /******************************************************************************
  4467. * Called during the callback/watchdog routine to update IFS value based on
  4468. * the ratio of transmits to collisions.
  4469. *
  4470. * hw - Struct containing variables accessed by shared code
  4471. * tx_packets - Number of transmits since last callback
  4472. * total_collisions - Number of collisions since last callback
  4473. *****************************************************************************/
  4474. void
  4475. e1000_update_adaptive(struct e1000_hw *hw)
  4476. {
  4477. DEBUGFUNC("e1000_update_adaptive");
  4478. if(hw->adaptive_ifs) {
  4479. if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
  4480. if(hw->tx_packet_delta > MIN_NUM_XMITS) {
  4481. hw->in_ifs_mode = TRUE;
  4482. if(hw->current_ifs_val < hw->ifs_max_val) {
  4483. if(hw->current_ifs_val == 0)
  4484. hw->current_ifs_val = hw->ifs_min_val;
  4485. else
  4486. hw->current_ifs_val += hw->ifs_step_size;
  4487. E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
  4488. }
  4489. }
  4490. } else {
  4491. if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
  4492. hw->current_ifs_val = 0;
  4493. hw->in_ifs_mode = FALSE;
  4494. E1000_WRITE_REG(hw, AIT, 0);
  4495. }
  4496. }
  4497. } else {
  4498. DEBUGOUT("Not in Adaptive IFS mode!\n");
  4499. }
  4500. }
  4501. /******************************************************************************
  4502. * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
  4503. *
  4504. * hw - Struct containing variables accessed by shared code
  4505. * frame_len - The length of the frame in question
  4506. * mac_addr - The Ethernet destination address of the frame in question
  4507. *****************************************************************************/
  4508. void
  4509. e1000_tbi_adjust_stats(struct e1000_hw *hw,
  4510. struct e1000_hw_stats *stats,
  4511. uint32_t frame_len,
  4512. uint8_t *mac_addr)
  4513. {
  4514. uint64_t carry_bit;
  4515. /* First adjust the frame length. */
  4516. frame_len--;
  4517. /* We need to adjust the statistics counters, since the hardware
  4518. * counters overcount this packet as a CRC error and undercount
  4519. * the packet as a good packet
  4520. */
  4521. /* This packet should not be counted as a CRC error. */
  4522. stats->crcerrs--;
  4523. /* This packet does count as a Good Packet Received. */
  4524. stats->gprc++;
  4525. /* Adjust the Good Octets received counters */
  4526. carry_bit = 0x80000000 & stats->gorcl;
  4527. stats->gorcl += frame_len;
  4528. /* If the high bit of Gorcl (the low 32 bits of the Good Octets
  4529. * Received Count) was one before the addition,
  4530. * AND it is zero after, then we lost the carry out,
  4531. * need to add one to Gorch (Good Octets Received Count High).
  4532. * This could be simplified if all environments supported
  4533. * 64-bit integers.
  4534. */
  4535. if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
  4536. stats->gorch++;
  4537. /* Is this a broadcast or multicast? Check broadcast first,
  4538. * since the test for a multicast frame will test positive on
  4539. * a broadcast frame.
  4540. */
  4541. if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
  4542. /* Broadcast packet */
  4543. stats->bprc++;
  4544. else if(*mac_addr & 0x01)
  4545. /* Multicast packet */
  4546. stats->mprc++;
  4547. if(frame_len == hw->max_frame_size) {
  4548. /* In this case, the hardware has overcounted the number of
  4549. * oversize frames.
  4550. */
  4551. if(stats->roc > 0)
  4552. stats->roc--;
  4553. }
  4554. /* Adjust the bin counters when the extra byte put the frame in the
  4555. * wrong bin. Remember that the frame_len was adjusted above.
  4556. */
  4557. if(frame_len == 64) {
  4558. stats->prc64++;
  4559. stats->prc127--;
  4560. } else if(frame_len == 127) {
  4561. stats->prc127++;
  4562. stats->prc255--;
  4563. } else if(frame_len == 255) {
  4564. stats->prc255++;
  4565. stats->prc511--;
  4566. } else if(frame_len == 511) {
  4567. stats->prc511++;
  4568. stats->prc1023--;
  4569. } else if(frame_len == 1023) {
  4570. stats->prc1023++;
  4571. stats->prc1522--;
  4572. } else if(frame_len == 1522) {
  4573. stats->prc1522++;
  4574. }
  4575. }
  4576. /******************************************************************************
  4577. * Gets the current PCI bus type, speed, and width of the hardware
  4578. *
  4579. * hw - Struct containing variables accessed by shared code
  4580. *****************************************************************************/
  4581. void
  4582. e1000_get_bus_info(struct e1000_hw *hw)
  4583. {
  4584. uint32_t status;
  4585. switch (hw->mac_type) {
  4586. case e1000_82542_rev2_0:
  4587. case e1000_82542_rev2_1:
  4588. hw->bus_type = e1000_bus_type_unknown;
  4589. hw->bus_speed = e1000_bus_speed_unknown;
  4590. hw->bus_width = e1000_bus_width_unknown;
  4591. break;
  4592. case e1000_82571:
  4593. case e1000_82572:
  4594. case e1000_82573:
  4595. hw->bus_type = e1000_bus_type_pci_express;
  4596. hw->bus_speed = e1000_bus_speed_2500;
  4597. hw->bus_width = e1000_bus_width_pciex_4;
  4598. break;
  4599. default:
  4600. status = E1000_READ_REG(hw, STATUS);
  4601. hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
  4602. e1000_bus_type_pcix : e1000_bus_type_pci;
  4603. if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
  4604. hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
  4605. e1000_bus_speed_66 : e1000_bus_speed_120;
  4606. } else if(hw->bus_type == e1000_bus_type_pci) {
  4607. hw->bus_speed = (status & E1000_STATUS_PCI66) ?
  4608. e1000_bus_speed_66 : e1000_bus_speed_33;
  4609. } else {
  4610. switch (status & E1000_STATUS_PCIX_SPEED) {
  4611. case E1000_STATUS_PCIX_SPEED_66:
  4612. hw->bus_speed = e1000_bus_speed_66;
  4613. break;
  4614. case E1000_STATUS_PCIX_SPEED_100:
  4615. hw->bus_speed = e1000_bus_speed_100;
  4616. break;
  4617. case E1000_STATUS_PCIX_SPEED_133:
  4618. hw->bus_speed = e1000_bus_speed_133;
  4619. break;
  4620. default:
  4621. hw->bus_speed = e1000_bus_speed_reserved;
  4622. break;
  4623. }
  4624. }
  4625. hw->bus_width = (status & E1000_STATUS_BUS64) ?
  4626. e1000_bus_width_64 : e1000_bus_width_32;
  4627. break;
  4628. }
  4629. }
  4630. /******************************************************************************
  4631. * Reads a value from one of the devices registers using port I/O (as opposed
  4632. * memory mapped I/O). Only 82544 and newer devices support port I/O.
  4633. *
  4634. * hw - Struct containing variables accessed by shared code
  4635. * offset - offset to read from
  4636. *****************************************************************************/
  4637. uint32_t
  4638. e1000_read_reg_io(struct e1000_hw *hw,
  4639. uint32_t offset)
  4640. {
  4641. unsigned long io_addr = hw->io_base;
  4642. unsigned long io_data = hw->io_base + 4;
  4643. e1000_io_write(hw, io_addr, offset);
  4644. return e1000_io_read(hw, io_data);
  4645. }
  4646. /******************************************************************************
  4647. * Writes a value to one of the devices registers using port I/O (as opposed to
  4648. * memory mapped I/O). Only 82544 and newer devices support port I/O.
  4649. *
  4650. * hw - Struct containing variables accessed by shared code
  4651. * offset - offset to write to
  4652. * value - value to write
  4653. *****************************************************************************/
  4654. void
  4655. e1000_write_reg_io(struct e1000_hw *hw,
  4656. uint32_t offset,
  4657. uint32_t value)
  4658. {
  4659. unsigned long io_addr = hw->io_base;
  4660. unsigned long io_data = hw->io_base + 4;
  4661. e1000_io_write(hw, io_addr, offset);
  4662. e1000_io_write(hw, io_data, value);
  4663. }
  4664. /******************************************************************************
  4665. * Estimates the cable length.
  4666. *
  4667. * hw - Struct containing variables accessed by shared code
  4668. * min_length - The estimated minimum length
  4669. * max_length - The estimated maximum length
  4670. *
  4671. * returns: - E1000_ERR_XXX
  4672. * E1000_SUCCESS
  4673. *
  4674. * This function always returns a ranged length (minimum & maximum).
  4675. * So for M88 phy's, this function interprets the one value returned from the
  4676. * register to the minimum and maximum range.
  4677. * For IGP phy's, the function calculates the range by the AGC registers.
  4678. *****************************************************************************/
  4679. int32_t
  4680. e1000_get_cable_length(struct e1000_hw *hw,
  4681. uint16_t *min_length,
  4682. uint16_t *max_length)
  4683. {
  4684. int32_t ret_val;
  4685. uint16_t agc_value = 0;
  4686. uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
  4687. uint16_t max_agc = 0;
  4688. uint16_t i, phy_data;
  4689. uint16_t cable_length;
  4690. DEBUGFUNC("e1000_get_cable_length");
  4691. *min_length = *max_length = 0;
  4692. /* Use old method for Phy older than IGP */
  4693. if(hw->phy_type == e1000_phy_m88) {
  4694. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  4695. &phy_data);
  4696. if(ret_val)
  4697. return ret_val;
  4698. cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
  4699. M88E1000_PSSR_CABLE_LENGTH_SHIFT;
  4700. /* Convert the enum value to ranged values */
  4701. switch (cable_length) {
  4702. case e1000_cable_length_50:
  4703. *min_length = 0;
  4704. *max_length = e1000_igp_cable_length_50;
  4705. break;
  4706. case e1000_cable_length_50_80:
  4707. *min_length = e1000_igp_cable_length_50;
  4708. *max_length = e1000_igp_cable_length_80;
  4709. break;
  4710. case e1000_cable_length_80_110:
  4711. *min_length = e1000_igp_cable_length_80;
  4712. *max_length = e1000_igp_cable_length_110;
  4713. break;
  4714. case e1000_cable_length_110_140:
  4715. *min_length = e1000_igp_cable_length_110;
  4716. *max_length = e1000_igp_cable_length_140;
  4717. break;
  4718. case e1000_cable_length_140:
  4719. *min_length = e1000_igp_cable_length_140;
  4720. *max_length = e1000_igp_cable_length_170;
  4721. break;
  4722. default:
  4723. return -E1000_ERR_PHY;
  4724. break;
  4725. }
  4726. } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
  4727. uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
  4728. {IGP01E1000_PHY_AGC_A,
  4729. IGP01E1000_PHY_AGC_B,
  4730. IGP01E1000_PHY_AGC_C,
  4731. IGP01E1000_PHY_AGC_D};
  4732. /* Read the AGC registers for all channels */
  4733. for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
  4734. ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
  4735. if(ret_val)
  4736. return ret_val;
  4737. cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
  4738. /* Array bound check. */
  4739. if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
  4740. (cur_agc == 0))
  4741. return -E1000_ERR_PHY;
  4742. agc_value += cur_agc;
  4743. /* Update minimal AGC value. */
  4744. if(min_agc > cur_agc)
  4745. min_agc = cur_agc;
  4746. }
  4747. /* Remove the minimal AGC result for length < 50m */
  4748. if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
  4749. agc_value -= min_agc;
  4750. /* Get the average length of the remaining 3 channels */
  4751. agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
  4752. } else {
  4753. /* Get the average length of all the 4 channels. */
  4754. agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
  4755. }
  4756. /* Set the range of the calculated length. */
  4757. *min_length = ((e1000_igp_cable_length_table[agc_value] -
  4758. IGP01E1000_AGC_RANGE) > 0) ?
  4759. (e1000_igp_cable_length_table[agc_value] -
  4760. IGP01E1000_AGC_RANGE) : 0;
  4761. *max_length = e1000_igp_cable_length_table[agc_value] +
  4762. IGP01E1000_AGC_RANGE;
  4763. } else if (hw->phy_type == e1000_phy_igp_2) {
  4764. uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
  4765. {IGP02E1000_PHY_AGC_A,
  4766. IGP02E1000_PHY_AGC_B,
  4767. IGP02E1000_PHY_AGC_C,
  4768. IGP02E1000_PHY_AGC_D};
  4769. /* Read the AGC registers for all channels */
  4770. for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
  4771. ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
  4772. if (ret_val)
  4773. return ret_val;
  4774. /* Getting bits 15:9, which represent the combination of course and
  4775. * fine gain values. The result is a number that can be put into
  4776. * the lookup table to obtain the approximate cable length. */
  4777. cur_agc = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
  4778. IGP02E1000_AGC_LENGTH_MASK;
  4779. /* Remove min & max AGC values from calculation. */
  4780. if (e1000_igp_2_cable_length_table[min_agc] > e1000_igp_2_cable_length_table[cur_agc])
  4781. min_agc = cur_agc;
  4782. if (e1000_igp_2_cable_length_table[max_agc] < e1000_igp_2_cable_length_table[cur_agc])
  4783. max_agc = cur_agc;
  4784. agc_value += e1000_igp_2_cable_length_table[cur_agc];
  4785. }
  4786. agc_value -= (e1000_igp_2_cable_length_table[min_agc] + e1000_igp_2_cable_length_table[max_agc]);
  4787. agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
  4788. /* Calculate cable length with the error range of +/- 10 meters. */
  4789. *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
  4790. (agc_value - IGP02E1000_AGC_RANGE) : 0;
  4791. *max_length = agc_value + IGP02E1000_AGC_RANGE;
  4792. }
  4793. return E1000_SUCCESS;
  4794. }
  4795. /******************************************************************************
  4796. * Check the cable polarity
  4797. *
  4798. * hw - Struct containing variables accessed by shared code
  4799. * polarity - output parameter : 0 - Polarity is not reversed
  4800. * 1 - Polarity is reversed.
  4801. *
  4802. * returns: - E1000_ERR_XXX
  4803. * E1000_SUCCESS
  4804. *
  4805. * For phy's older then IGP, this function simply reads the polarity bit in the
  4806. * Phy Status register. For IGP phy's, this bit is valid only if link speed is
  4807. * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
  4808. * return 0. If the link speed is 1000 Mbps the polarity status is in the
  4809. * IGP01E1000_PHY_PCS_INIT_REG.
  4810. *****************************************************************************/
  4811. int32_t
  4812. e1000_check_polarity(struct e1000_hw *hw,
  4813. uint16_t *polarity)
  4814. {
  4815. int32_t ret_val;
  4816. uint16_t phy_data;
  4817. DEBUGFUNC("e1000_check_polarity");
  4818. if(hw->phy_type == e1000_phy_m88) {
  4819. /* return the Polarity bit in the Status register. */
  4820. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  4821. &phy_data);
  4822. if(ret_val)
  4823. return ret_val;
  4824. *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
  4825. M88E1000_PSSR_REV_POLARITY_SHIFT;
  4826. } else if(hw->phy_type == e1000_phy_igp ||
  4827. hw->phy_type == e1000_phy_igp_2) {
  4828. /* Read the Status register to check the speed */
  4829. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
  4830. &phy_data);
  4831. if(ret_val)
  4832. return ret_val;
  4833. /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
  4834. * find the polarity status */
  4835. if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
  4836. IGP01E1000_PSSR_SPEED_1000MBPS) {
  4837. /* Read the GIG initialization PCS register (0x00B4) */
  4838. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
  4839. &phy_data);
  4840. if(ret_val)
  4841. return ret_val;
  4842. /* Check the polarity bits */
  4843. *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
  4844. } else {
  4845. /* For 10 Mbps, read the polarity bit in the status register. (for
  4846. * 100 Mbps this bit is always 0) */
  4847. *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
  4848. }
  4849. }
  4850. return E1000_SUCCESS;
  4851. }
  4852. /******************************************************************************
  4853. * Check if Downshift occured
  4854. *
  4855. * hw - Struct containing variables accessed by shared code
  4856. * downshift - output parameter : 0 - No Downshift ocured.
  4857. * 1 - Downshift ocured.
  4858. *
  4859. * returns: - E1000_ERR_XXX
  4860. * E1000_SUCCESS
  4861. *
  4862. * For phy's older then IGP, this function reads the Downshift bit in the Phy
  4863. * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
  4864. * Link Health register. In IGP this bit is latched high, so the driver must
  4865. * read it immediately after link is established.
  4866. *****************************************************************************/
  4867. int32_t
  4868. e1000_check_downshift(struct e1000_hw *hw)
  4869. {
  4870. int32_t ret_val;
  4871. uint16_t phy_data;
  4872. DEBUGFUNC("e1000_check_downshift");
  4873. if(hw->phy_type == e1000_phy_igp ||
  4874. hw->phy_type == e1000_phy_igp_2) {
  4875. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
  4876. &phy_data);
  4877. if(ret_val)
  4878. return ret_val;
  4879. hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
  4880. } else if(hw->phy_type == e1000_phy_m88) {
  4881. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  4882. &phy_data);
  4883. if(ret_val)
  4884. return ret_val;
  4885. hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
  4886. M88E1000_PSSR_DOWNSHIFT_SHIFT;
  4887. }
  4888. return E1000_SUCCESS;
  4889. }
  4890. /*****************************************************************************
  4891. *
  4892. * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
  4893. * gigabit link is achieved to improve link quality.
  4894. *
  4895. * hw: Struct containing variables accessed by shared code
  4896. *
  4897. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  4898. * E1000_SUCCESS at any other case.
  4899. *
  4900. ****************************************************************************/
  4901. int32_t
  4902. e1000_config_dsp_after_link_change(struct e1000_hw *hw,
  4903. boolean_t link_up)
  4904. {
  4905. int32_t ret_val;
  4906. uint16_t phy_data, phy_saved_data, speed, duplex, i;
  4907. uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
  4908. {IGP01E1000_PHY_AGC_PARAM_A,
  4909. IGP01E1000_PHY_AGC_PARAM_B,
  4910. IGP01E1000_PHY_AGC_PARAM_C,
  4911. IGP01E1000_PHY_AGC_PARAM_D};
  4912. uint16_t min_length, max_length;
  4913. DEBUGFUNC("e1000_config_dsp_after_link_change");
  4914. if(hw->phy_type != e1000_phy_igp)
  4915. return E1000_SUCCESS;
  4916. if(link_up) {
  4917. ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
  4918. if(ret_val) {
  4919. DEBUGOUT("Error getting link speed and duplex\n");
  4920. return ret_val;
  4921. }
  4922. if(speed == SPEED_1000) {
  4923. e1000_get_cable_length(hw, &min_length, &max_length);
  4924. if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
  4925. min_length >= e1000_igp_cable_length_50) {
  4926. for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
  4927. ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
  4928. &phy_data);
  4929. if(ret_val)
  4930. return ret_val;
  4931. phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
  4932. ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
  4933. phy_data);
  4934. if(ret_val)
  4935. return ret_val;
  4936. }
  4937. hw->dsp_config_state = e1000_dsp_config_activated;
  4938. }
  4939. if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
  4940. (min_length < e1000_igp_cable_length_50)) {
  4941. uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
  4942. uint32_t idle_errs = 0;
  4943. /* clear previous idle error counts */
  4944. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
  4945. &phy_data);
  4946. if(ret_val)
  4947. return ret_val;
  4948. for(i = 0; i < ffe_idle_err_timeout; i++) {
  4949. usec_delay(1000);
  4950. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
  4951. &phy_data);
  4952. if(ret_val)
  4953. return ret_val;
  4954. idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
  4955. if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
  4956. hw->ffe_config_state = e1000_ffe_config_active;
  4957. ret_val = e1000_write_phy_reg(hw,
  4958. IGP01E1000_PHY_DSP_FFE,
  4959. IGP01E1000_PHY_DSP_FFE_CM_CP);
  4960. if(ret_val)
  4961. return ret_val;
  4962. break;
  4963. }
  4964. if(idle_errs)
  4965. ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
  4966. }
  4967. }
  4968. }
  4969. } else {
  4970. if(hw->dsp_config_state == e1000_dsp_config_activated) {
  4971. /* Save off the current value of register 0x2F5B to be restored at
  4972. * the end of the routines. */
  4973. ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  4974. if(ret_val)
  4975. return ret_val;
  4976. /* Disable the PHY transmitter */
  4977. ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  4978. if(ret_val)
  4979. return ret_val;
  4980. msec_delay_irq(20);
  4981. ret_val = e1000_write_phy_reg(hw, 0x0000,
  4982. IGP01E1000_IEEE_FORCE_GIGA);
  4983. if(ret_val)
  4984. return ret_val;
  4985. for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
  4986. ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
  4987. if(ret_val)
  4988. return ret_val;
  4989. phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
  4990. phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
  4991. ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
  4992. if(ret_val)
  4993. return ret_val;
  4994. }
  4995. ret_val = e1000_write_phy_reg(hw, 0x0000,
  4996. IGP01E1000_IEEE_RESTART_AUTONEG);
  4997. if(ret_val)
  4998. return ret_val;
  4999. msec_delay_irq(20);
  5000. /* Now enable the transmitter */
  5001. ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  5002. if(ret_val)
  5003. return ret_val;
  5004. hw->dsp_config_state = e1000_dsp_config_enabled;
  5005. }
  5006. if(hw->ffe_config_state == e1000_ffe_config_active) {
  5007. /* Save off the current value of register 0x2F5B to be restored at
  5008. * the end of the routines. */
  5009. ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  5010. if(ret_val)
  5011. return ret_val;
  5012. /* Disable the PHY transmitter */
  5013. ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  5014. if(ret_val)
  5015. return ret_val;
  5016. msec_delay_irq(20);
  5017. ret_val = e1000_write_phy_reg(hw, 0x0000,
  5018. IGP01E1000_IEEE_FORCE_GIGA);
  5019. if(ret_val)
  5020. return ret_val;
  5021. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
  5022. IGP01E1000_PHY_DSP_FFE_DEFAULT);
  5023. if(ret_val)
  5024. return ret_val;
  5025. ret_val = e1000_write_phy_reg(hw, 0x0000,
  5026. IGP01E1000_IEEE_RESTART_AUTONEG);
  5027. if(ret_val)
  5028. return ret_val;
  5029. msec_delay_irq(20);
  5030. /* Now enable the transmitter */
  5031. ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  5032. if(ret_val)
  5033. return ret_val;
  5034. hw->ffe_config_state = e1000_ffe_config_enabled;
  5035. }
  5036. }
  5037. return E1000_SUCCESS;
  5038. }
  5039. /*****************************************************************************
  5040. * Set PHY to class A mode
  5041. * Assumes the following operations will follow to enable the new class mode.
  5042. * 1. Do a PHY soft reset
  5043. * 2. Restart auto-negotiation or force link.
  5044. *
  5045. * hw - Struct containing variables accessed by shared code
  5046. ****************************************************************************/
  5047. static int32_t
  5048. e1000_set_phy_mode(struct e1000_hw *hw)
  5049. {
  5050. int32_t ret_val;
  5051. uint16_t eeprom_data;
  5052. DEBUGFUNC("e1000_set_phy_mode");
  5053. if((hw->mac_type == e1000_82545_rev_3) &&
  5054. (hw->media_type == e1000_media_type_copper)) {
  5055. ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
  5056. if(ret_val) {
  5057. return ret_val;
  5058. }
  5059. if((eeprom_data != EEPROM_RESERVED_WORD) &&
  5060. (eeprom_data & EEPROM_PHY_CLASS_A)) {
  5061. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
  5062. if(ret_val)
  5063. return ret_val;
  5064. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
  5065. if(ret_val)
  5066. return ret_val;
  5067. hw->phy_reset_disable = FALSE;
  5068. }
  5069. }
  5070. return E1000_SUCCESS;
  5071. }
  5072. /*****************************************************************************
  5073. *
  5074. * This function sets the lplu state according to the active flag. When
  5075. * activating lplu this function also disables smart speed and vise versa.
  5076. * lplu will not be activated unless the device autonegotiation advertisment
  5077. * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
  5078. * hw: Struct containing variables accessed by shared code
  5079. * active - true to enable lplu false to disable lplu.
  5080. *
  5081. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  5082. * E1000_SUCCESS at any other case.
  5083. *
  5084. ****************************************************************************/
  5085. int32_t
  5086. e1000_set_d3_lplu_state(struct e1000_hw *hw,
  5087. boolean_t active)
  5088. {
  5089. int32_t ret_val;
  5090. uint16_t phy_data;
  5091. DEBUGFUNC("e1000_set_d3_lplu_state");
  5092. if(hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2)
  5093. return E1000_SUCCESS;
  5094. /* During driver activity LPLU should not be used or it will attain link
  5095. * from the lowest speeds starting from 10Mbps. The capability is used for
  5096. * Dx transitions and states */
  5097. if(hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
  5098. ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
  5099. if(ret_val)
  5100. return ret_val;
  5101. } else {
  5102. ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
  5103. if(ret_val)
  5104. return ret_val;
  5105. }
  5106. if(!active) {
  5107. if(hw->mac_type == e1000_82541_rev_2 ||
  5108. hw->mac_type == e1000_82547_rev_2) {
  5109. phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
  5110. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
  5111. if(ret_val)
  5112. return ret_val;
  5113. } else {
  5114. phy_data &= ~IGP02E1000_PM_D3_LPLU;
  5115. ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  5116. phy_data);
  5117. if (ret_val)
  5118. return ret_val;
  5119. }
  5120. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
  5121. * Dx states where the power conservation is most important. During
  5122. * driver activity we should enable SmartSpeed, so performance is
  5123. * maintained. */
  5124. if (hw->smart_speed == e1000_smart_speed_on) {
  5125. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5126. &phy_data);
  5127. if(ret_val)
  5128. return ret_val;
  5129. phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
  5130. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5131. phy_data);
  5132. if(ret_val)
  5133. return ret_val;
  5134. } else if (hw->smart_speed == e1000_smart_speed_off) {
  5135. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5136. &phy_data);
  5137. if (ret_val)
  5138. return ret_val;
  5139. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  5140. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5141. phy_data);
  5142. if(ret_val)
  5143. return ret_val;
  5144. }
  5145. } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
  5146. (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
  5147. (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
  5148. if(hw->mac_type == e1000_82541_rev_2 ||
  5149. hw->mac_type == e1000_82547_rev_2) {
  5150. phy_data |= IGP01E1000_GMII_FLEX_SPD;
  5151. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
  5152. if(ret_val)
  5153. return ret_val;
  5154. } else {
  5155. phy_data |= IGP02E1000_PM_D3_LPLU;
  5156. ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  5157. phy_data);
  5158. if (ret_val)
  5159. return ret_val;
  5160. }
  5161. /* When LPLU is enabled we should disable SmartSpeed */
  5162. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  5163. if(ret_val)
  5164. return ret_val;
  5165. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  5166. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
  5167. if(ret_val)
  5168. return ret_val;
  5169. }
  5170. return E1000_SUCCESS;
  5171. }
  5172. /*****************************************************************************
  5173. *
  5174. * This function sets the lplu d0 state according to the active flag. When
  5175. * activating lplu this function also disables smart speed and vise versa.
  5176. * lplu will not be activated unless the device autonegotiation advertisment
  5177. * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
  5178. * hw: Struct containing variables accessed by shared code
  5179. * active - true to enable lplu false to disable lplu.
  5180. *
  5181. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  5182. * E1000_SUCCESS at any other case.
  5183. *
  5184. ****************************************************************************/
  5185. int32_t
  5186. e1000_set_d0_lplu_state(struct e1000_hw *hw,
  5187. boolean_t active)
  5188. {
  5189. int32_t ret_val;
  5190. uint16_t phy_data;
  5191. DEBUGFUNC("e1000_set_d0_lplu_state");
  5192. if(hw->mac_type <= e1000_82547_rev_2)
  5193. return E1000_SUCCESS;
  5194. ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
  5195. if(ret_val)
  5196. return ret_val;
  5197. if (!active) {
  5198. phy_data &= ~IGP02E1000_PM_D0_LPLU;
  5199. ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
  5200. if (ret_val)
  5201. return ret_val;
  5202. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
  5203. * Dx states where the power conservation is most important. During
  5204. * driver activity we should enable SmartSpeed, so performance is
  5205. * maintained. */
  5206. if (hw->smart_speed == e1000_smart_speed_on) {
  5207. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5208. &phy_data);
  5209. if(ret_val)
  5210. return ret_val;
  5211. phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
  5212. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5213. phy_data);
  5214. if(ret_val)
  5215. return ret_val;
  5216. } else if (hw->smart_speed == e1000_smart_speed_off) {
  5217. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5218. &phy_data);
  5219. if (ret_val)
  5220. return ret_val;
  5221. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  5222. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5223. phy_data);
  5224. if(ret_val)
  5225. return ret_val;
  5226. }
  5227. } else {
  5228. phy_data |= IGP02E1000_PM_D0_LPLU;
  5229. ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
  5230. if (ret_val)
  5231. return ret_val;
  5232. /* When LPLU is enabled we should disable SmartSpeed */
  5233. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  5234. if(ret_val)
  5235. return ret_val;
  5236. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  5237. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
  5238. if(ret_val)
  5239. return ret_val;
  5240. }
  5241. return E1000_SUCCESS;
  5242. }
  5243. /******************************************************************************
  5244. * Change VCO speed register to improve Bit Error Rate performance of SERDES.
  5245. *
  5246. * hw - Struct containing variables accessed by shared code
  5247. *****************************************************************************/
  5248. static int32_t
  5249. e1000_set_vco_speed(struct e1000_hw *hw)
  5250. {
  5251. int32_t ret_val;
  5252. uint16_t default_page = 0;
  5253. uint16_t phy_data;
  5254. DEBUGFUNC("e1000_set_vco_speed");
  5255. switch(hw->mac_type) {
  5256. case e1000_82545_rev_3:
  5257. case e1000_82546_rev_3:
  5258. break;
  5259. default:
  5260. return E1000_SUCCESS;
  5261. }
  5262. /* Set PHY register 30, page 5, bit 8 to 0 */
  5263. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
  5264. if(ret_val)
  5265. return ret_val;
  5266. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
  5267. if(ret_val)
  5268. return ret_val;
  5269. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
  5270. if(ret_val)
  5271. return ret_val;
  5272. phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
  5273. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
  5274. if(ret_val)
  5275. return ret_val;
  5276. /* Set PHY register 30, page 4, bit 11 to 1 */
  5277. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
  5278. if(ret_val)
  5279. return ret_val;
  5280. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
  5281. if(ret_val)
  5282. return ret_val;
  5283. phy_data |= M88E1000_PHY_VCO_REG_BIT11;
  5284. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
  5285. if(ret_val)
  5286. return ret_val;
  5287. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
  5288. if(ret_val)
  5289. return ret_val;
  5290. return E1000_SUCCESS;
  5291. }
  5292. /*****************************************************************************
  5293. * This function reads the cookie from ARC ram.
  5294. *
  5295. * returns: - E1000_SUCCESS .
  5296. ****************************************************************************/
  5297. int32_t
  5298. e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
  5299. {
  5300. uint8_t i;
  5301. uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
  5302. uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
  5303. length = (length >> 2);
  5304. offset = (offset >> 2);
  5305. for (i = 0; i < length; i++) {
  5306. *((uint32_t *) buffer + i) =
  5307. E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
  5308. }
  5309. return E1000_SUCCESS;
  5310. }
  5311. /*****************************************************************************
  5312. * This function checks whether the HOST IF is enabled for command operaton
  5313. * and also checks whether the previous command is completed.
  5314. * It busy waits in case of previous command is not completed.
  5315. *
  5316. * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
  5317. * timeout
  5318. * - E1000_SUCCESS for success.
  5319. ****************************************************************************/
  5320. int32_t
  5321. e1000_mng_enable_host_if(struct e1000_hw * hw)
  5322. {
  5323. uint32_t hicr;
  5324. uint8_t i;
  5325. /* Check that the host interface is enabled. */
  5326. hicr = E1000_READ_REG(hw, HICR);
  5327. if ((hicr & E1000_HICR_EN) == 0) {
  5328. DEBUGOUT("E1000_HOST_EN bit disabled.\n");
  5329. return -E1000_ERR_HOST_INTERFACE_COMMAND;
  5330. }
  5331. /* check the previous command is completed */
  5332. for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
  5333. hicr = E1000_READ_REG(hw, HICR);
  5334. if (!(hicr & E1000_HICR_C))
  5335. break;
  5336. msec_delay_irq(1);
  5337. }
  5338. if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
  5339. DEBUGOUT("Previous command timeout failed .\n");
  5340. return -E1000_ERR_HOST_INTERFACE_COMMAND;
  5341. }
  5342. return E1000_SUCCESS;
  5343. }
  5344. /*****************************************************************************
  5345. * This function writes the buffer content at the offset given on the host if.
  5346. * It also does alignment considerations to do the writes in most efficient way.
  5347. * Also fills up the sum of the buffer in *buffer parameter.
  5348. *
  5349. * returns - E1000_SUCCESS for success.
  5350. ****************************************************************************/
  5351. int32_t
  5352. e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
  5353. uint16_t length, uint16_t offset, uint8_t *sum)
  5354. {
  5355. uint8_t *tmp;
  5356. uint8_t *bufptr = buffer;
  5357. uint32_t data;
  5358. uint16_t remaining, i, j, prev_bytes;
  5359. /* sum = only sum of the data and it is not checksum */
  5360. if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
  5361. return -E1000_ERR_PARAM;
  5362. }
  5363. tmp = (uint8_t *)&data;
  5364. prev_bytes = offset & 0x3;
  5365. offset &= 0xFFFC;
  5366. offset >>= 2;
  5367. if (prev_bytes) {
  5368. data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
  5369. for (j = prev_bytes; j < sizeof(uint32_t); j++) {
  5370. *(tmp + j) = *bufptr++;
  5371. *sum += *(tmp + j);
  5372. }
  5373. E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
  5374. length -= j - prev_bytes;
  5375. offset++;
  5376. }
  5377. remaining = length & 0x3;
  5378. length -= remaining;
  5379. /* Calculate length in DWORDs */
  5380. length >>= 2;
  5381. /* The device driver writes the relevant command block into the
  5382. * ram area. */
  5383. for (i = 0; i < length; i++) {
  5384. for (j = 0; j < sizeof(uint32_t); j++) {
  5385. *(tmp + j) = *bufptr++;
  5386. *sum += *(tmp + j);
  5387. }
  5388. E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
  5389. }
  5390. if (remaining) {
  5391. for (j = 0; j < sizeof(uint32_t); j++) {
  5392. if (j < remaining)
  5393. *(tmp + j) = *bufptr++;
  5394. else
  5395. *(tmp + j) = 0;
  5396. *sum += *(tmp + j);
  5397. }
  5398. E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
  5399. }
  5400. return E1000_SUCCESS;
  5401. }
  5402. /*****************************************************************************
  5403. * This function writes the command header after does the checksum calculation.
  5404. *
  5405. * returns - E1000_SUCCESS for success.
  5406. ****************************************************************************/
  5407. int32_t
  5408. e1000_mng_write_cmd_header(struct e1000_hw * hw,
  5409. struct e1000_host_mng_command_header * hdr)
  5410. {
  5411. uint16_t i;
  5412. uint8_t sum;
  5413. uint8_t *buffer;
  5414. /* Write the whole command header structure which includes sum of
  5415. * the buffer */
  5416. uint16_t length = sizeof(struct e1000_host_mng_command_header);
  5417. sum = hdr->checksum;
  5418. hdr->checksum = 0;
  5419. buffer = (uint8_t *) hdr;
  5420. i = length;
  5421. while(i--)
  5422. sum += buffer[i];
  5423. hdr->checksum = 0 - sum;
  5424. length >>= 2;
  5425. /* The device driver writes the relevant command block into the ram area. */
  5426. for (i = 0; i < length; i++)
  5427. E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
  5428. return E1000_SUCCESS;
  5429. }
  5430. /*****************************************************************************
  5431. * This function indicates to ARC that a new command is pending which completes
  5432. * one write operation by the driver.
  5433. *
  5434. * returns - E1000_SUCCESS for success.
  5435. ****************************************************************************/
  5436. int32_t
  5437. e1000_mng_write_commit(
  5438. struct e1000_hw * hw)
  5439. {
  5440. uint32_t hicr;
  5441. hicr = E1000_READ_REG(hw, HICR);
  5442. /* Setting this bit tells the ARC that a new command is pending. */
  5443. E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
  5444. return E1000_SUCCESS;
  5445. }
  5446. /*****************************************************************************
  5447. * This function checks the mode of the firmware.
  5448. *
  5449. * returns - TRUE when the mode is IAMT or FALSE.
  5450. ****************************************************************************/
  5451. boolean_t
  5452. e1000_check_mng_mode(
  5453. struct e1000_hw *hw)
  5454. {
  5455. uint32_t fwsm;
  5456. fwsm = E1000_READ_REG(hw, FWSM);
  5457. if((fwsm & E1000_FWSM_MODE_MASK) ==
  5458. (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
  5459. return TRUE;
  5460. return FALSE;
  5461. }
  5462. /*****************************************************************************
  5463. * This function writes the dhcp info .
  5464. ****************************************************************************/
  5465. int32_t
  5466. e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
  5467. uint16_t length)
  5468. {
  5469. int32_t ret_val;
  5470. struct e1000_host_mng_command_header hdr;
  5471. hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
  5472. hdr.command_length = length;
  5473. hdr.reserved1 = 0;
  5474. hdr.reserved2 = 0;
  5475. hdr.checksum = 0;
  5476. ret_val = e1000_mng_enable_host_if(hw);
  5477. if (ret_val == E1000_SUCCESS) {
  5478. ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
  5479. &(hdr.checksum));
  5480. if (ret_val == E1000_SUCCESS) {
  5481. ret_val = e1000_mng_write_cmd_header(hw, &hdr);
  5482. if (ret_val == E1000_SUCCESS)
  5483. ret_val = e1000_mng_write_commit(hw);
  5484. }
  5485. }
  5486. return ret_val;
  5487. }
  5488. /*****************************************************************************
  5489. * This function calculates the checksum.
  5490. *
  5491. * returns - checksum of buffer contents.
  5492. ****************************************************************************/
  5493. uint8_t
  5494. e1000_calculate_mng_checksum(char *buffer, uint32_t length)
  5495. {
  5496. uint8_t sum = 0;
  5497. uint32_t i;
  5498. if (!buffer)
  5499. return 0;
  5500. for (i=0; i < length; i++)
  5501. sum += buffer[i];
  5502. return (uint8_t) (0 - sum);
  5503. }
  5504. /*****************************************************************************
  5505. * This function checks whether tx pkt filtering needs to be enabled or not.
  5506. *
  5507. * returns - TRUE for packet filtering or FALSE.
  5508. ****************************************************************************/
  5509. boolean_t
  5510. e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
  5511. {
  5512. /* called in init as well as watchdog timer functions */
  5513. int32_t ret_val, checksum;
  5514. boolean_t tx_filter = FALSE;
  5515. struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
  5516. uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
  5517. if (e1000_check_mng_mode(hw)) {
  5518. ret_val = e1000_mng_enable_host_if(hw);
  5519. if (ret_val == E1000_SUCCESS) {
  5520. ret_val = e1000_host_if_read_cookie(hw, buffer);
  5521. if (ret_val == E1000_SUCCESS) {
  5522. checksum = hdr->checksum;
  5523. hdr->checksum = 0;
  5524. if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
  5525. checksum == e1000_calculate_mng_checksum((char *)buffer,
  5526. E1000_MNG_DHCP_COOKIE_LENGTH)) {
  5527. if (hdr->status &
  5528. E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
  5529. tx_filter = TRUE;
  5530. } else
  5531. tx_filter = TRUE;
  5532. } else
  5533. tx_filter = TRUE;
  5534. }
  5535. }
  5536. hw->tx_pkt_filtering = tx_filter;
  5537. return tx_filter;
  5538. }
  5539. /******************************************************************************
  5540. * Verifies the hardware needs to allow ARPs to be processed by the host
  5541. *
  5542. * hw - Struct containing variables accessed by shared code
  5543. *
  5544. * returns: - TRUE/FALSE
  5545. *
  5546. *****************************************************************************/
  5547. uint32_t
  5548. e1000_enable_mng_pass_thru(struct e1000_hw *hw)
  5549. {
  5550. uint32_t manc;
  5551. uint32_t fwsm, factps;
  5552. if (hw->asf_firmware_present) {
  5553. manc = E1000_READ_REG(hw, MANC);
  5554. if (!(manc & E1000_MANC_RCV_TCO_EN) ||
  5555. !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
  5556. return FALSE;
  5557. if (e1000_arc_subsystem_valid(hw) == TRUE) {
  5558. fwsm = E1000_READ_REG(hw, FWSM);
  5559. factps = E1000_READ_REG(hw, FACTPS);
  5560. if (((fwsm & E1000_FWSM_MODE_MASK) ==
  5561. (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
  5562. (factps & E1000_FACTPS_MNGCG))
  5563. return TRUE;
  5564. } else
  5565. if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
  5566. return TRUE;
  5567. }
  5568. return FALSE;
  5569. }
  5570. static int32_t
  5571. e1000_polarity_reversal_workaround(struct e1000_hw *hw)
  5572. {
  5573. int32_t ret_val;
  5574. uint16_t mii_status_reg;
  5575. uint16_t i;
  5576. /* Polarity reversal workaround for forced 10F/10H links. */
  5577. /* Disable the transmitter on the PHY */
  5578. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
  5579. if(ret_val)
  5580. return ret_val;
  5581. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
  5582. if(ret_val)
  5583. return ret_val;
  5584. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
  5585. if(ret_val)
  5586. return ret_val;
  5587. /* This loop will early-out if the NO link condition has been met. */
  5588. for(i = PHY_FORCE_TIME; i > 0; i--) {
  5589. /* Read the MII Status Register and wait for Link Status bit
  5590. * to be clear.
  5591. */
  5592. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  5593. if(ret_val)
  5594. return ret_val;
  5595. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  5596. if(ret_val)
  5597. return ret_val;
  5598. if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
  5599. msec_delay_irq(100);
  5600. }
  5601. /* Recommended delay time after link has been lost */
  5602. msec_delay_irq(1000);
  5603. /* Now we will re-enable th transmitter on the PHY */
  5604. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
  5605. if(ret_val)
  5606. return ret_val;
  5607. msec_delay_irq(50);
  5608. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
  5609. if(ret_val)
  5610. return ret_val;
  5611. msec_delay_irq(50);
  5612. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
  5613. if(ret_val)
  5614. return ret_val;
  5615. msec_delay_irq(50);
  5616. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
  5617. if(ret_val)
  5618. return ret_val;
  5619. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
  5620. if(ret_val)
  5621. return ret_val;
  5622. /* This loop will early-out if the link condition has been met. */
  5623. for(i = PHY_FORCE_TIME; i > 0; i--) {
  5624. /* Read the MII Status Register and wait for Link Status bit
  5625. * to be set.
  5626. */
  5627. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  5628. if(ret_val)
  5629. return ret_val;
  5630. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  5631. if(ret_val)
  5632. return ret_val;
  5633. if(mii_status_reg & MII_SR_LINK_STATUS) break;
  5634. msec_delay_irq(100);
  5635. }
  5636. return E1000_SUCCESS;
  5637. }
  5638. /***************************************************************************
  5639. *
  5640. * Disables PCI-Express master access.
  5641. *
  5642. * hw: Struct containing variables accessed by shared code
  5643. *
  5644. * returns: - none.
  5645. *
  5646. ***************************************************************************/
  5647. void
  5648. e1000_set_pci_express_master_disable(struct e1000_hw *hw)
  5649. {
  5650. uint32_t ctrl;
  5651. DEBUGFUNC("e1000_set_pci_express_master_disable");
  5652. if (hw->bus_type != e1000_bus_type_pci_express)
  5653. return;
  5654. ctrl = E1000_READ_REG(hw, CTRL);
  5655. ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
  5656. E1000_WRITE_REG(hw, CTRL, ctrl);
  5657. }
  5658. /***************************************************************************
  5659. *
  5660. * Enables PCI-Express master access.
  5661. *
  5662. * hw: Struct containing variables accessed by shared code
  5663. *
  5664. * returns: - none.
  5665. *
  5666. ***************************************************************************/
  5667. void
  5668. e1000_enable_pciex_master(struct e1000_hw *hw)
  5669. {
  5670. uint32_t ctrl;
  5671. DEBUGFUNC("e1000_enable_pciex_master");
  5672. if (hw->bus_type != e1000_bus_type_pci_express)
  5673. return;
  5674. ctrl = E1000_READ_REG(hw, CTRL);
  5675. ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
  5676. E1000_WRITE_REG(hw, CTRL, ctrl);
  5677. }
  5678. /*******************************************************************************
  5679. *
  5680. * Disables PCI-Express master access and verifies there are no pending requests
  5681. *
  5682. * hw: Struct containing variables accessed by shared code
  5683. *
  5684. * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
  5685. * caused the master requests to be disabled.
  5686. * E1000_SUCCESS master requests disabled.
  5687. *
  5688. ******************************************************************************/
  5689. int32_t
  5690. e1000_disable_pciex_master(struct e1000_hw *hw)
  5691. {
  5692. int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
  5693. DEBUGFUNC("e1000_disable_pciex_master");
  5694. if (hw->bus_type != e1000_bus_type_pci_express)
  5695. return E1000_SUCCESS;
  5696. e1000_set_pci_express_master_disable(hw);
  5697. while(timeout) {
  5698. if(!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
  5699. break;
  5700. else
  5701. usec_delay(100);
  5702. timeout--;
  5703. }
  5704. if(!timeout) {
  5705. DEBUGOUT("Master requests are pending.\n");
  5706. return -E1000_ERR_MASTER_REQUESTS_PENDING;
  5707. }
  5708. return E1000_SUCCESS;
  5709. }
  5710. /*******************************************************************************
  5711. *
  5712. * Check for EEPROM Auto Read bit done.
  5713. *
  5714. * hw: Struct containing variables accessed by shared code
  5715. *
  5716. * returns: - E1000_ERR_RESET if fail to reset MAC
  5717. * E1000_SUCCESS at any other case.
  5718. *
  5719. ******************************************************************************/
  5720. int32_t
  5721. e1000_get_auto_rd_done(struct e1000_hw *hw)
  5722. {
  5723. int32_t timeout = AUTO_READ_DONE_TIMEOUT;
  5724. DEBUGFUNC("e1000_get_auto_rd_done");
  5725. switch (hw->mac_type) {
  5726. default:
  5727. msec_delay(5);
  5728. break;
  5729. case e1000_82571:
  5730. case e1000_82572:
  5731. case e1000_82573:
  5732. while(timeout) {
  5733. if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) break;
  5734. else msec_delay(1);
  5735. timeout--;
  5736. }
  5737. if(!timeout) {
  5738. DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
  5739. return -E1000_ERR_RESET;
  5740. }
  5741. break;
  5742. }
  5743. return E1000_SUCCESS;
  5744. }
  5745. /***************************************************************************
  5746. * Checks if the PHY configuration is done
  5747. *
  5748. * hw: Struct containing variables accessed by shared code
  5749. *
  5750. * returns: - E1000_ERR_RESET if fail to reset MAC
  5751. * E1000_SUCCESS at any other case.
  5752. *
  5753. ***************************************************************************/
  5754. int32_t
  5755. e1000_get_phy_cfg_done(struct e1000_hw *hw)
  5756. {
  5757. int32_t timeout = PHY_CFG_TIMEOUT;
  5758. uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
  5759. DEBUGFUNC("e1000_get_phy_cfg_done");
  5760. switch (hw->mac_type) {
  5761. default:
  5762. msec_delay(10);
  5763. break;
  5764. case e1000_82571:
  5765. case e1000_82572:
  5766. while (timeout) {
  5767. if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
  5768. break;
  5769. else
  5770. msec_delay(1);
  5771. timeout--;
  5772. }
  5773. if (!timeout) {
  5774. DEBUGOUT("MNG configuration cycle has not completed.\n");
  5775. return -E1000_ERR_RESET;
  5776. }
  5777. break;
  5778. }
  5779. return E1000_SUCCESS;
  5780. }
  5781. /***************************************************************************
  5782. *
  5783. * Using the combination of SMBI and SWESMBI semaphore bits when resetting
  5784. * adapter or Eeprom access.
  5785. *
  5786. * hw: Struct containing variables accessed by shared code
  5787. *
  5788. * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
  5789. * E1000_SUCCESS at any other case.
  5790. *
  5791. ***************************************************************************/
  5792. int32_t
  5793. e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
  5794. {
  5795. int32_t timeout;
  5796. uint32_t swsm;
  5797. DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
  5798. if(!hw->eeprom_semaphore_present)
  5799. return E1000_SUCCESS;
  5800. /* Get the FW semaphore. */
  5801. timeout = hw->eeprom.word_size + 1;
  5802. while(timeout) {
  5803. swsm = E1000_READ_REG(hw, SWSM);
  5804. swsm |= E1000_SWSM_SWESMBI;
  5805. E1000_WRITE_REG(hw, SWSM, swsm);
  5806. /* if we managed to set the bit we got the semaphore. */
  5807. swsm = E1000_READ_REG(hw, SWSM);
  5808. if(swsm & E1000_SWSM_SWESMBI)
  5809. break;
  5810. usec_delay(50);
  5811. timeout--;
  5812. }
  5813. if(!timeout) {
  5814. /* Release semaphores */
  5815. e1000_put_hw_eeprom_semaphore(hw);
  5816. DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
  5817. return -E1000_ERR_EEPROM;
  5818. }
  5819. return E1000_SUCCESS;
  5820. }
  5821. /***************************************************************************
  5822. * This function clears HW semaphore bits.
  5823. *
  5824. * hw: Struct containing variables accessed by shared code
  5825. *
  5826. * returns: - None.
  5827. *
  5828. ***************************************************************************/
  5829. void
  5830. e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
  5831. {
  5832. uint32_t swsm;
  5833. DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
  5834. if(!hw->eeprom_semaphore_present)
  5835. return;
  5836. swsm = E1000_READ_REG(hw, SWSM);
  5837. swsm &= ~(E1000_SWSM_SWESMBI);
  5838. E1000_WRITE_REG(hw, SWSM, swsm);
  5839. }
  5840. /******************************************************************************
  5841. * Checks if PHY reset is blocked due to SOL/IDER session, for example.
  5842. * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
  5843. * the caller to figure out how to deal with it.
  5844. *
  5845. * hw - Struct containing variables accessed by shared code
  5846. *
  5847. * returns: - E1000_BLK_PHY_RESET
  5848. * E1000_SUCCESS
  5849. *
  5850. *****************************************************************************/
  5851. int32_t
  5852. e1000_check_phy_reset_block(struct e1000_hw *hw)
  5853. {
  5854. uint32_t manc = 0;
  5855. if (hw->mac_type > e1000_82547_rev_2)
  5856. manc = E1000_READ_REG(hw, MANC);
  5857. return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
  5858. E1000_BLK_PHY_RESET : E1000_SUCCESS;
  5859. }
  5860. uint8_t
  5861. e1000_arc_subsystem_valid(struct e1000_hw *hw)
  5862. {
  5863. uint32_t fwsm;
  5864. /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
  5865. * may not be provided a DMA clock when no manageability features are
  5866. * enabled. We do not want to perform any reads/writes to these registers
  5867. * if this is the case. We read FWSM to determine the manageability mode.
  5868. */
  5869. switch (hw->mac_type) {
  5870. case e1000_82571:
  5871. case e1000_82572:
  5872. case e1000_82573:
  5873. fwsm = E1000_READ_REG(hw, FWSM);
  5874. if((fwsm & E1000_FWSM_MODE_MASK) != 0)
  5875. return TRUE;
  5876. break;
  5877. default:
  5878. break;
  5879. }
  5880. return FALSE;
  5881. }
  5882. int32_t
  5883. e1000_phy_misctst_get_info(struct e1000_hw *hw, uint16_t *enabled)
  5884. {
  5885. int32_t ret_val;
  5886. uint16_t misctst_reg;
  5887. DEBUGFUNC("e1000_phy_misctst_get_info");
  5888. ret_val = e1000_read_phy_reg(hw, 0x0FF0, &misctst_reg);
  5889. if (ret_val)
  5890. return ret_val;
  5891. if (misctst_reg & 0x0002) {
  5892. DEBUGOUT("L1 ASPM disabled");
  5893. *enabled = FALSE;
  5894. } else {
  5895. DEBUGOUT("L1 ASPM enabled");
  5896. *enabled = TRUE;
  5897. }
  5898. return E1000_SUCCESS;
  5899. }