PageRenderTime 42ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/bhesmans/click
C | 3590 lines | 2086 code | 367 blank | 1137 comment | 376 complexity | c2a0dd98e1f79d544cf2989f097ca85c MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. /*******************************************************************************
  2. Copyright(c) 1999 - 2002 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_setup_fiber_link(struct e1000_hw *hw);
  25. static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
  26. static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
  27. static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
  28. static int32_t e1000_force_mac_fc(struct e1000_hw *hw);
  29. static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
  30. static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
  31. static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count);
  32. static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
  33. static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
  34. static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
  35. static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
  36. static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count);
  37. static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw);
  38. static void e1000_setup_eeprom(struct e1000_hw *hw);
  39. static void e1000_standby_eeprom(struct e1000_hw *hw);
  40. static void e1000_clock_eeprom(struct e1000_hw *hw);
  41. static void e1000_cleanup_eeprom(struct e1000_hw *hw);
  42. static int32_t e1000_id_led_init(struct e1000_hw * hw);
  43. /******************************************************************************
  44. * Set the mac type member in the hw struct.
  45. *
  46. * hw - Struct containing variables accessed by shared code
  47. *****************************************************************************/
  48. int32_t
  49. e1000_set_mac_type(struct e1000_hw *hw)
  50. {
  51. DEBUGFUNC("e1000_set_mac_type");
  52. switch (hw->device_id) {
  53. case E1000_DEV_ID_82542:
  54. switch (hw->revision_id) {
  55. case E1000_82542_2_0_REV_ID:
  56. hw->mac_type = e1000_82542_rev2_0;
  57. break;
  58. case E1000_82542_2_1_REV_ID:
  59. hw->mac_type = e1000_82542_rev2_1;
  60. break;
  61. default:
  62. /* Invalid 82542 revision ID */
  63. return -E1000_ERR_MAC_TYPE;
  64. }
  65. break;
  66. case E1000_DEV_ID_82543GC_FIBER:
  67. case E1000_DEV_ID_82543GC_COPPER:
  68. hw->mac_type = e1000_82543;
  69. break;
  70. case E1000_DEV_ID_82544EI_COPPER:
  71. case E1000_DEV_ID_82544EI_FIBER:
  72. case E1000_DEV_ID_82544GC_COPPER:
  73. case E1000_DEV_ID_82544GC_LOM:
  74. hw->mac_type = e1000_82544;
  75. break;
  76. case E1000_DEV_ID_82540EM:
  77. case E1000_DEV_ID_82540EM_LOM:
  78. hw->mac_type = e1000_82540;
  79. break;
  80. case E1000_DEV_ID_82545EM_COPPER:
  81. case E1000_DEV_ID_82545EM_FIBER:
  82. hw->mac_type = e1000_82545;
  83. break;
  84. case E1000_DEV_ID_82546EB_COPPER:
  85. case E1000_DEV_ID_82546EB_FIBER:
  86. hw->mac_type = e1000_82546;
  87. break;
  88. default:
  89. /* Should never have loaded on this device */
  90. return -E1000_ERR_MAC_TYPE;
  91. }
  92. return E1000_SUCCESS;
  93. }
  94. /******************************************************************************
  95. * Reset the transmit and receive units; mask and clear all interrupts.
  96. *
  97. * hw - Struct containing variables accessed by shared code
  98. *****************************************************************************/
  99. void
  100. e1000_reset_hw(struct e1000_hw *hw)
  101. {
  102. uint32_t ctrl;
  103. uint32_t ctrl_ext;
  104. uint32_t icr;
  105. uint32_t manc;
  106. DEBUGFUNC("e1000_reset_hw");
  107. /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
  108. if(hw->mac_type == e1000_82542_rev2_0) {
  109. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  110. e1000_pci_clear_mwi(hw);
  111. }
  112. /* Clear interrupt mask to stop board from generating interrupts */
  113. DEBUGOUT("Masking off all interrupts\n");
  114. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  115. /* Disable the Transmit and Receive units. Then delay to allow
  116. * any pending transactions to complete before we hit the MAC with
  117. * the global reset.
  118. */
  119. E1000_WRITE_REG(hw, RCTL, 0);
  120. E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
  121. E1000_WRITE_FLUSH(hw);
  122. /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
  123. hw->tbi_compatibility_on = FALSE;
  124. /* Delay to allow any outstanding PCI transactions to complete before
  125. * resetting the device
  126. */
  127. msec_delay(10);
  128. /* Issue a global reset to the MAC. This will reset the chip's
  129. * transmit, receive, DMA, and link units. It will not effect
  130. * the current PCI configuration. The global reset bit is self-
  131. * clearing, and should clear within a microsecond.
  132. */
  133. DEBUGOUT("Issuing a global reset to MAC\n");
  134. ctrl = E1000_READ_REG(hw, CTRL);
  135. if(hw->mac_type > e1000_82543)
  136. E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
  137. else
  138. E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
  139. /* Force a reload from the EEPROM if necessary */
  140. if(hw->mac_type < e1000_82540) {
  141. /* Wait for reset to complete */
  142. usec_delay(10);
  143. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  144. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  145. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  146. E1000_WRITE_FLUSH(hw);
  147. /* Wait for EEPROM reload */
  148. msec_delay(2);
  149. } else {
  150. /* Wait for EEPROM reload (it happens automatically) */
  151. msec_delay(4);
  152. /* Dissable HW ARPs on ASF enabled adapters */
  153. manc = E1000_READ_REG(hw, MANC);
  154. manc &= ~(E1000_MANC_ARP_EN);
  155. E1000_WRITE_REG(hw, MANC, manc);
  156. }
  157. /* Clear interrupt mask to stop board from generating interrupts */
  158. DEBUGOUT("Masking off all interrupts\n");
  159. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  160. /* Clear any pending interrupt events. */
  161. icr = E1000_READ_REG(hw, ICR);
  162. /* If MWI was previously enabled, reenable it. */
  163. if(hw->mac_type == e1000_82542_rev2_0) {
  164. if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
  165. e1000_pci_set_mwi(hw);
  166. }
  167. }
  168. /******************************************************************************
  169. * Performs basic configuration of the adapter.
  170. *
  171. * hw - Struct containing variables accessed by shared code
  172. *
  173. * Assumes that the controller has previously been reset and is in a
  174. * post-reset uninitialized state. Initializes the receive address registers,
  175. * multicast table, and VLAN filter table. Calls routines to setup link
  176. * configuration and flow control settings. Clears all on-chip counters. Leaves
  177. * the transmit and receive units disabled and uninitialized.
  178. *****************************************************************************/
  179. int32_t
  180. e1000_init_hw(struct e1000_hw *hw)
  181. {
  182. uint32_t ctrl, status;
  183. uint32_t i;
  184. int32_t ret_val;
  185. uint16_t pcix_cmd_word;
  186. uint16_t pcix_stat_hi_word;
  187. uint16_t cmd_mmrbc;
  188. uint16_t stat_mmrbc;
  189. DEBUGFUNC("e1000_init_hw");
  190. /* Initialize Identification LED */
  191. ret_val = e1000_id_led_init(hw);
  192. if(ret_val < 0) {
  193. DEBUGOUT("Error Initializing Identification LED\n");
  194. return ret_val;
  195. }
  196. /* Set the Media Type and exit with error if it is not valid. */
  197. if(hw->mac_type != e1000_82543) {
  198. /* tbi_compatibility is only valid on 82543 */
  199. hw->tbi_compatibility_en = FALSE;
  200. }
  201. if(hw->mac_type >= e1000_82543) {
  202. status = E1000_READ_REG(hw, STATUS);
  203. if(status & E1000_STATUS_TBIMODE) {
  204. hw->media_type = e1000_media_type_fiber;
  205. /* tbi_compatibility not valid on fiber */
  206. hw->tbi_compatibility_en = FALSE;
  207. } else {
  208. hw->media_type = e1000_media_type_copper;
  209. }
  210. } else {
  211. /* This is an 82542 (fiber only) */
  212. hw->media_type = e1000_media_type_fiber;
  213. }
  214. /* Disabling VLAN filtering. */
  215. DEBUGOUT("Initializing the IEEE VLAN\n");
  216. E1000_WRITE_REG(hw, VET, 0);
  217. e1000_clear_vfta(hw);
  218. /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
  219. if(hw->mac_type == e1000_82542_rev2_0) {
  220. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  221. e1000_pci_clear_mwi(hw);
  222. E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
  223. E1000_WRITE_FLUSH(hw);
  224. msec_delay(5);
  225. }
  226. /* Setup the receive address. This involves initializing all of the Receive
  227. * Address Registers (RARs 0 - 15).
  228. */
  229. e1000_init_rx_addrs(hw);
  230. /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
  231. if(hw->mac_type == e1000_82542_rev2_0) {
  232. E1000_WRITE_REG(hw, RCTL, 0);
  233. E1000_WRITE_FLUSH(hw);
  234. msec_delay(1);
  235. if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
  236. e1000_pci_set_mwi(hw);
  237. }
  238. /* Zero out the Multicast HASH table */
  239. DEBUGOUT("Zeroing the MTA\n");
  240. for(i = 0; i < E1000_MC_TBL_SIZE; i++)
  241. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  242. /* Set the PCI priority bit correctly in the CTRL register. This
  243. * determines if the adapter gives priority to receives, or if it
  244. * gives equal priority to transmits and receives.
  245. */
  246. if(hw->dma_fairness) {
  247. ctrl = E1000_READ_REG(hw, CTRL);
  248. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
  249. }
  250. /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
  251. if(hw->bus_type == e1000_bus_type_pcix) {
  252. e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
  253. e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI, &pcix_stat_hi_word);
  254. cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
  255. PCIX_COMMAND_MMRBC_SHIFT;
  256. stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
  257. PCIX_STATUS_HI_MMRBC_SHIFT;
  258. if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
  259. stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
  260. if(cmd_mmrbc > stat_mmrbc) {
  261. pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
  262. pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
  263. e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
  264. }
  265. }
  266. /* Call a subroutine to configure the link and setup flow control. */
  267. ret_val = e1000_setup_link(hw);
  268. /* Set the transmit descriptor write-back policy */
  269. if(hw->mac_type > e1000_82544) {
  270. ctrl = E1000_READ_REG(hw, TXDCTL);
  271. ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
  272. E1000_WRITE_REG(hw, TXDCTL, ctrl);
  273. }
  274. /* Clear all of the statistics registers (clear on read). It is
  275. * important that we do this after we have tried to establish link
  276. * because the symbol error count will increment wildly if there
  277. * is no link.
  278. */
  279. e1000_clear_hw_cntrs(hw);
  280. return ret_val;
  281. }
  282. /******************************************************************************
  283. * Configures flow control and link settings.
  284. *
  285. * hw - Struct containing variables accessed by shared code
  286. *
  287. * Determines which flow control settings to use. Calls the apropriate media-
  288. * specific link configuration function. Configures the flow control settings.
  289. * Assuming the adapter has a valid link partner, a valid link should be
  290. * established. Assumes the hardware has previously been reset and the
  291. * transmitter and receiver are not enabled.
  292. *****************************************************************************/
  293. int32_t
  294. e1000_setup_link(struct e1000_hw *hw)
  295. {
  296. uint32_t ctrl_ext;
  297. int32_t ret_val;
  298. uint16_t eeprom_data;
  299. DEBUGFUNC("e1000_setup_link");
  300. /* Read and store word 0x0F of the EEPROM. This word contains bits
  301. * that determine the hardware's default PAUSE (flow control) mode,
  302. * a bit that determines whether the HW defaults to enabling or
  303. * disabling auto-negotiation, and the direction of the
  304. * SW defined pins. If there is no SW over-ride of the flow
  305. * control setting, then the variable hw->fc will
  306. * be initialized based on a value in the EEPROM.
  307. */
  308. if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, &eeprom_data) < 0) {
  309. DEBUGOUT("EEPROM Read Error\n");
  310. return -E1000_ERR_EEPROM;
  311. }
  312. if(hw->fc == e1000_fc_default) {
  313. if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
  314. hw->fc = e1000_fc_none;
  315. else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
  316. EEPROM_WORD0F_ASM_DIR)
  317. hw->fc = e1000_fc_tx_pause;
  318. else
  319. hw->fc = e1000_fc_full;
  320. }
  321. /* We want to save off the original Flow Control configuration just
  322. * in case we get disconnected and then reconnected into a different
  323. * hub or switch with different Flow Control capabilities.
  324. */
  325. if(hw->mac_type == e1000_82542_rev2_0)
  326. hw->fc &= (~e1000_fc_tx_pause);
  327. if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
  328. hw->fc &= (~e1000_fc_rx_pause);
  329. hw->original_fc = hw->fc;
  330. DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
  331. /* Take the 4 bits from EEPROM word 0x0F that determine the initial
  332. * polarity value for the SW controlled pins, and setup the
  333. * Extended Device Control reg with that info.
  334. * This is needed because one of the SW controlled pins is used for
  335. * signal detection. So this should be done before e1000_setup_pcs_link()
  336. * or e1000_phy_setup() is called.
  337. */
  338. if(hw->mac_type == e1000_82543) {
  339. ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
  340. SWDPIO__EXT_SHIFT);
  341. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  342. }
  343. /* Call the necessary subroutine to configure the link. */
  344. ret_val = (hw->media_type == e1000_media_type_fiber) ?
  345. e1000_setup_fiber_link(hw) :
  346. e1000_setup_copper_link(hw);
  347. /* Initialize the flow control address, type, and PAUSE timer
  348. * registers to their default values. This is done even if flow
  349. * control is disabled, because it does not hurt anything to
  350. * initialize these registers.
  351. */
  352. DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
  353. E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
  354. E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  355. E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
  356. E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
  357. /* Set the flow control receive threshold registers. Normally,
  358. * these registers will be set to a default threshold that may be
  359. * adjusted later by the driver's runtime code. However, if the
  360. * ability to transmit pause frames in not enabled, then these
  361. * registers will be set to 0.
  362. */
  363. if(!(hw->fc & e1000_fc_tx_pause)) {
  364. E1000_WRITE_REG(hw, FCRTL, 0);
  365. E1000_WRITE_REG(hw, FCRTH, 0);
  366. } else {
  367. /* We need to set up the Receive Threshold high and low water marks
  368. * as well as (optionally) enabling the transmission of XON frames.
  369. */
  370. if(hw->fc_send_xon) {
  371. E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
  372. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  373. } else {
  374. E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
  375. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  376. }
  377. }
  378. return ret_val;
  379. }
  380. /******************************************************************************
  381. * Sets up link for a fiber based adapter
  382. *
  383. * hw - Struct containing variables accessed by shared code
  384. *
  385. * Manipulates Physical Coding Sublayer functions in order to configure
  386. * link. Assumes the hardware has been previously reset and the transmitter
  387. * and receiver are not enabled.
  388. *****************************************************************************/
  389. static int32_t
  390. e1000_setup_fiber_link(struct e1000_hw *hw)
  391. {
  392. uint32_t ctrl;
  393. uint32_t status;
  394. uint32_t txcw = 0;
  395. uint32_t i;
  396. uint32_t signal;
  397. int32_t ret_val;
  398. DEBUGFUNC("e1000_setup_fiber_link");
  399. /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
  400. * set when the optics detect a signal. On older adapters, it will be
  401. * cleared when there is a signal
  402. */
  403. ctrl = E1000_READ_REG(hw, CTRL);
  404. if(hw->mac_type > e1000_82544) signal = E1000_CTRL_SWDPIN1;
  405. else signal = 0;
  406. /* Take the link out of reset */
  407. ctrl &= ~(E1000_CTRL_LRST);
  408. e1000_config_collision_dist(hw);
  409. /* Check for a software override of the flow control settings, and setup
  410. * the device accordingly. If auto-negotiation is enabled, then software
  411. * will have to set the "PAUSE" bits to the correct value in the Tranmsit
  412. * Config Word Register (TXCW) and re-start auto-negotiation. However, if
  413. * auto-negotiation is disabled, then software will have to manually
  414. * configure the two flow control enable bits in the CTRL register.
  415. *
  416. * The possible values of the "fc" parameter are:
  417. * 0: Flow control is completely disabled
  418. * 1: Rx flow control is enabled (we can receive pause frames, but
  419. * not send pause frames).
  420. * 2: Tx flow control is enabled (we can send pause frames but we do
  421. * not support receiving pause frames).
  422. * 3: Both Rx and TX flow control (symmetric) are enabled.
  423. */
  424. switch (hw->fc) {
  425. case e1000_fc_none:
  426. /* Flow control is completely disabled by a software over-ride. */
  427. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
  428. break;
  429. case e1000_fc_rx_pause:
  430. /* RX Flow control is enabled and TX Flow control is disabled by a
  431. * software over-ride. Since there really isn't a way to advertise
  432. * that we are capable of RX Pause ONLY, we will advertise that we
  433. * support both symmetric and asymmetric RX PAUSE. Later, we will
  434. * disable the adapter's ability to send PAUSE frames.
  435. */
  436. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  437. break;
  438. case e1000_fc_tx_pause:
  439. /* TX Flow control is enabled, and RX Flow control is disabled, by a
  440. * software over-ride.
  441. */
  442. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
  443. break;
  444. case e1000_fc_full:
  445. /* Flow control (both RX and TX) is enabled by a software over-ride. */
  446. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  447. break;
  448. default:
  449. DEBUGOUT("Flow control param set incorrectly\n");
  450. return -E1000_ERR_CONFIG;
  451. break;
  452. }
  453. /* Since auto-negotiation is enabled, take the link out of reset (the link
  454. * will be in reset, because we previously reset the chip). This will
  455. * restart auto-negotiation. If auto-neogtiation is successful then the
  456. * link-up status bit will be set and the flow control enable bits (RFCE
  457. * and TFCE) will be set according to their negotiated value.
  458. */
  459. DEBUGOUT("Auto-negotiation enabled\n");
  460. E1000_WRITE_REG(hw, TXCW, txcw);
  461. E1000_WRITE_REG(hw, CTRL, ctrl);
  462. E1000_WRITE_FLUSH(hw);
  463. hw->txcw = txcw;
  464. msec_delay(1);
  465. /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
  466. * indication in the Device Status Register. Time-out if a link isn't
  467. * seen in 500 milliseconds seconds (Auto-negotiation should complete in
  468. * less than 500 milliseconds even if the other end is doing it in SW).
  469. */
  470. if((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
  471. DEBUGOUT("Looking for Link\n");
  472. for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
  473. msec_delay(10);
  474. status = E1000_READ_REG(hw, STATUS);
  475. if(status & E1000_STATUS_LU) break;
  476. }
  477. if(i == (LINK_UP_TIMEOUT / 10)) {
  478. /* AutoNeg failed to achieve a link, so we'll call
  479. * e1000_check_for_link. This routine will force the link up if we
  480. * detect a signal. This will allow us to communicate with
  481. * non-autonegotiating link partners.
  482. */
  483. DEBUGOUT("Never got a valid link from auto-neg!!!\n");
  484. hw->autoneg_failed = 1;
  485. ret_val = e1000_check_for_link(hw);
  486. if(ret_val < 0) {
  487. DEBUGOUT("Error while checking for link\n");
  488. return ret_val;
  489. }
  490. hw->autoneg_failed = 0;
  491. } else {
  492. hw->autoneg_failed = 0;
  493. DEBUGOUT("Valid Link Found\n");
  494. }
  495. } else {
  496. DEBUGOUT("No Signal Detected\n");
  497. }
  498. return 0;
  499. }
  500. /******************************************************************************
  501. * Detects which PHY is present and the speed and duplex
  502. *
  503. * hw - Struct containing variables accessed by shared code
  504. ******************************************************************************/
  505. static int32_t
  506. e1000_setup_copper_link(struct e1000_hw *hw)
  507. {
  508. uint32_t ctrl;
  509. int32_t ret_val;
  510. uint16_t i;
  511. uint16_t phy_data;
  512. DEBUGFUNC("e1000_setup_copper_link");
  513. ctrl = E1000_READ_REG(hw, CTRL);
  514. /* With 82543, we need to force speed and duplex on the MAC equal to what
  515. * the PHY speed and duplex configuration is. In addition, we need to
  516. * perform a hardware reset on the PHY to take it out of reset.
  517. */
  518. if(hw->mac_type > e1000_82543) {
  519. ctrl |= E1000_CTRL_SLU;
  520. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  521. E1000_WRITE_REG(hw, CTRL, ctrl);
  522. } else {
  523. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
  524. E1000_WRITE_REG(hw, CTRL, ctrl);
  525. e1000_phy_hw_reset(hw);
  526. }
  527. /* Make sure we have a valid PHY */
  528. ret_val = e1000_detect_gig_phy(hw);
  529. if(ret_val < 0) {
  530. DEBUGOUT("Error, did not detect valid phy.\n");
  531. return ret_val;
  532. }
  533. DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
  534. /* Enable CRS on TX. This must be set for half-duplex operation. */
  535. if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data) < 0) {
  536. DEBUGOUT("PHY Read Error\n");
  537. return -E1000_ERR_PHY;
  538. }
  539. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  540. /* Options:
  541. * MDI/MDI-X = 0 (default)
  542. * 0 - Auto for all speeds
  543. * 1 - MDI mode
  544. * 2 - MDI-X mode
  545. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  546. */
  547. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  548. switch (hw->mdix) {
  549. case 1:
  550. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  551. break;
  552. case 2:
  553. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  554. break;
  555. case 3:
  556. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  557. break;
  558. case 0:
  559. default:
  560. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  561. break;
  562. }
  563. /* Options:
  564. * disable_polarity_correction = 0 (default)
  565. * Automatic Correction for Reversed Cable Polarity
  566. * 0 - Disabled
  567. * 1 - Enabled
  568. */
  569. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  570. if(hw->disable_polarity_correction == 1)
  571. phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
  572. if(e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data) < 0) {
  573. DEBUGOUT("PHY Write Error\n");
  574. return -E1000_ERR_PHY;
  575. }
  576. /* Force TX_CLK in the Extended PHY Specific Control Register
  577. * to 25MHz clock.
  578. */
  579. if(e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data) < 0) {
  580. DEBUGOUT("PHY Read Error\n");
  581. return -E1000_ERR_PHY;
  582. }
  583. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  584. /* Configure Master and Slave downshift values */
  585. phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
  586. M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  587. phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
  588. M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  589. if(e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data) < 0) {
  590. DEBUGOUT("PHY Write Error\n");
  591. return -E1000_ERR_PHY;
  592. }
  593. /* SW Reset the PHY so all changes take effect */
  594. ret_val = e1000_phy_reset(hw);
  595. if(ret_val < 0) {
  596. DEBUGOUT("Error Resetting the PHY\n");
  597. return ret_val;
  598. }
  599. /* Options:
  600. * autoneg = 1 (default)
  601. * PHY will advertise value(s) parsed from
  602. * autoneg_advertised and fc
  603. * autoneg = 0
  604. * PHY will be set to 10H, 10F, 100H, or 100F
  605. * depending on value parsed from forced_speed_duplex.
  606. */
  607. /* Is autoneg enabled? This is enabled by default or by software override.
  608. * If so, call e1000_phy_setup_autoneg routine to parse the
  609. * autoneg_advertised and fc options. If autoneg is NOT enabled, then the
  610. * user should have provided a speed/duplex override. If so, then call
  611. * e1000_phy_force_speed_duplex to parse and set this up.
  612. */
  613. if(hw->autoneg) {
  614. /* Perform some bounds checking on the hw->autoneg_advertised
  615. * parameter. If this variable is zero, then set it to the default.
  616. */
  617. hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
  618. /* If autoneg_advertised is zero, we assume it was not defaulted
  619. * by the calling code so we set to advertise full capability.
  620. */
  621. if(hw->autoneg_advertised == 0)
  622. hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  623. DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
  624. ret_val = e1000_phy_setup_autoneg(hw);
  625. if(ret_val < 0) {
  626. DEBUGOUT("Error Setting up Auto-Negotiation\n");
  627. return ret_val;
  628. }
  629. DEBUGOUT("Restarting Auto-Neg\n");
  630. /* Restart auto-negotiation by setting the Auto Neg Enable bit and
  631. * the Auto Neg Restart bit in the PHY control register.
  632. */
  633. if(e1000_read_phy_reg(hw, PHY_CTRL, &phy_data) < 0) {
  634. DEBUGOUT("PHY Read Error\n");
  635. return -E1000_ERR_PHY;
  636. }
  637. phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
  638. if(e1000_write_phy_reg(hw, PHY_CTRL, phy_data) < 0) {
  639. DEBUGOUT("PHY Write Error\n");
  640. return -E1000_ERR_PHY;
  641. }
  642. /* Does the user want to wait for Auto-Neg to complete here, or
  643. * check at a later time (for example, callback routine).
  644. */
  645. if(hw->wait_autoneg_complete) {
  646. ret_val = e1000_wait_autoneg(hw);
  647. if(ret_val < 0) {
  648. DEBUGOUT("Error while waiting for autoneg to complete\n");
  649. return ret_val;
  650. }
  651. }
  652. } else {
  653. DEBUGOUT("Forcing speed and duplex\n");
  654. ret_val = e1000_phy_force_speed_duplex(hw);
  655. if(ret_val < 0) {
  656. DEBUGOUT("Error Forcing Speed and Duplex\n");
  657. return ret_val;
  658. }
  659. }
  660. /* Check link status. Wait up to 100 microseconds for link to become
  661. * valid.
  662. */
  663. for(i = 0; i < 10; i++) {
  664. if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  665. DEBUGOUT("PHY Read Error\n");
  666. return -E1000_ERR_PHY;
  667. }
  668. if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  669. DEBUGOUT("PHY Read Error\n");
  670. return -E1000_ERR_PHY;
  671. }
  672. if(phy_data & MII_SR_LINK_STATUS) {
  673. /* We have link, so we need to finish the config process:
  674. * 1) Set up the MAC to the current PHY speed/duplex
  675. * if we are on 82543. If we
  676. * are on newer silicon, we only need to configure
  677. * collision distance in the Transmit Control Register.
  678. * 2) Set up flow control on the MAC to that established with
  679. * the link partner.
  680. */
  681. if(hw->mac_type >= e1000_82544) {
  682. e1000_config_collision_dist(hw);
  683. } else {
  684. ret_val = e1000_config_mac_to_phy(hw);
  685. if(ret_val < 0) {
  686. DEBUGOUT("Error configuring MAC to PHY settings\n");
  687. return ret_val;
  688. }
  689. }
  690. ret_val = e1000_config_fc_after_link_up(hw);
  691. if(ret_val < 0) {
  692. DEBUGOUT("Error Configuring Flow Control\n");
  693. return ret_val;
  694. }
  695. DEBUGOUT("Valid link established!!!\n");
  696. return 0;
  697. }
  698. usec_delay(10);
  699. }
  700. DEBUGOUT("Unable to establish link!!!\n");
  701. return 0;
  702. }
  703. /******************************************************************************
  704. * Configures PHY autoneg and flow control advertisement settings
  705. *
  706. * hw - Struct containing variables accessed by shared code
  707. ******************************************************************************/
  708. int32_t
  709. e1000_phy_setup_autoneg(struct e1000_hw *hw)
  710. {
  711. uint16_t mii_autoneg_adv_reg;
  712. uint16_t mii_1000t_ctrl_reg;
  713. DEBUGFUNC("e1000_phy_setup_autoneg");
  714. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  715. if(e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg) < 0) {
  716. DEBUGOUT("PHY Read Error\n");
  717. return -E1000_ERR_PHY;
  718. }
  719. /* Read the MII 1000Base-T Control Register (Address 9). */
  720. if(e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg) < 0) {
  721. DEBUGOUT("PHY Read Error\n");
  722. return -E1000_ERR_PHY;
  723. }
  724. /* Need to parse both autoneg_advertised and fc and set up
  725. * the appropriate PHY registers. First we will parse for
  726. * autoneg_advertised software override. Since we can advertise
  727. * a plethora of combinations, we need to check each bit
  728. * individually.
  729. */
  730. /* First we clear all the 10/100 mb speed bits in the Auto-Neg
  731. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  732. * the 1000Base-T Control Register (Address 9).
  733. */
  734. mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
  735. mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
  736. DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
  737. /* Do we want to advertise 10 Mb Half Duplex? */
  738. if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
  739. DEBUGOUT("Advertise 10mb Half duplex\n");
  740. mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
  741. }
  742. /* Do we want to advertise 10 Mb Full Duplex? */
  743. if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
  744. DEBUGOUT("Advertise 10mb Full duplex\n");
  745. mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
  746. }
  747. /* Do we want to advertise 100 Mb Half Duplex? */
  748. if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
  749. DEBUGOUT("Advertise 100mb Half duplex\n");
  750. mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
  751. }
  752. /* Do we want to advertise 100 Mb Full Duplex? */
  753. if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
  754. DEBUGOUT("Advertise 100mb Full duplex\n");
  755. mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
  756. }
  757. /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  758. if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
  759. DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
  760. }
  761. /* Do we want to advertise 1000 Mb Full Duplex? */
  762. if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
  763. DEBUGOUT("Advertise 1000mb Full duplex\n");
  764. mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
  765. }
  766. /* Check for a software override of the flow control settings, and
  767. * setup the PHY advertisement registers accordingly. If
  768. * auto-negotiation is enabled, then software will have to set the
  769. * "PAUSE" bits to the correct value in the Auto-Negotiation
  770. * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
  771. *
  772. * The possible values of the "fc" parameter are:
  773. * 0: Flow control is completely disabled
  774. * 1: Rx flow control is enabled (we can receive pause frames
  775. * but not send pause frames).
  776. * 2: Tx flow control is enabled (we can send pause frames
  777. * but we do not support receiving pause frames).
  778. * 3: Both Rx and TX flow control (symmetric) are enabled.
  779. * other: No software override. The flow control configuration
  780. * in the EEPROM is used.
  781. */
  782. switch (hw->fc) {
  783. case e1000_fc_none: /* 0 */
  784. /* Flow control (RX & TX) is completely disabled by a
  785. * software over-ride.
  786. */
  787. mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  788. break;
  789. case e1000_fc_rx_pause: /* 1 */
  790. /* RX Flow control is enabled, and TX Flow control is
  791. * disabled, by a software over-ride.
  792. */
  793. /* Since there really isn't a way to advertise that we are
  794. * capable of RX Pause ONLY, we will advertise that we
  795. * support both symmetric and asymmetric RX PAUSE. Later
  796. * (in e1000_config_fc_after_link_up) we will disable the
  797. *hw's ability to send PAUSE frames.
  798. */
  799. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  800. break;
  801. case e1000_fc_tx_pause: /* 2 */
  802. /* TX Flow control is enabled, and RX Flow control is
  803. * disabled, by a software over-ride.
  804. */
  805. mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
  806. mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
  807. break;
  808. case e1000_fc_full: /* 3 */
  809. /* Flow control (both RX and TX) is enabled by a software
  810. * over-ride.
  811. */
  812. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  813. break;
  814. default:
  815. DEBUGOUT("Flow control param set incorrectly\n");
  816. return -E1000_ERR_CONFIG;
  817. }
  818. if(e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg) < 0) {
  819. DEBUGOUT("PHY Write Error\n");
  820. return -E1000_ERR_PHY;
  821. }
  822. DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  823. if(e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg) < 0) {
  824. DEBUGOUT("PHY Write Error\n");
  825. return -E1000_ERR_PHY;
  826. }
  827. return 0;
  828. }
  829. /******************************************************************************
  830. * Force PHY speed and duplex settings to hw->forced_speed_duplex
  831. *
  832. * hw - Struct containing variables accessed by shared code
  833. ******************************************************************************/
  834. static int32_t
  835. e1000_phy_force_speed_duplex(struct e1000_hw *hw)
  836. {
  837. uint32_t ctrl;
  838. int32_t ret_val;
  839. uint16_t mii_ctrl_reg;
  840. uint16_t mii_status_reg;
  841. uint16_t phy_data;
  842. uint16_t i;
  843. DEBUGFUNC("e1000_phy_force_speed_duplex");
  844. /* Turn off Flow control if we are forcing speed and duplex. */
  845. hw->fc = e1000_fc_none;
  846. DEBUGOUT1("hw->fc = %d\n", hw->fc);
  847. /* Read the Device Control Register. */
  848. ctrl = E1000_READ_REG(hw, CTRL);
  849. /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
  850. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  851. ctrl &= ~(DEVICE_SPEED_MASK);
  852. /* Clear the Auto Speed Detect Enable bit. */
  853. ctrl &= ~E1000_CTRL_ASDE;
  854. /* Read the MII Control Register. */
  855. if(e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg) < 0) {
  856. DEBUGOUT("PHY Read Error\n");
  857. return -E1000_ERR_PHY;
  858. }
  859. /* We need to disable autoneg in order to force link and duplex. */
  860. mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
  861. /* Are we forcing Full or Half Duplex? */
  862. if(hw->forced_speed_duplex == e1000_100_full ||
  863. hw->forced_speed_duplex == e1000_10_full) {
  864. /* We want to force full duplex so we SET the full duplex bits in the
  865. * Device and MII Control Registers.
  866. */
  867. ctrl |= E1000_CTRL_FD;
  868. mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
  869. DEBUGOUT("Full Duplex\n");
  870. } else {
  871. /* We want to force half duplex so we CLEAR the full duplex bits in
  872. * the Device and MII Control Registers.
  873. */
  874. ctrl &= ~E1000_CTRL_FD;
  875. mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
  876. DEBUGOUT("Half Duplex\n");
  877. }
  878. /* Are we forcing 100Mbps??? */
  879. if(hw->forced_speed_duplex == e1000_100_full ||
  880. hw->forced_speed_duplex == e1000_100_half) {
  881. /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
  882. ctrl |= E1000_CTRL_SPD_100;
  883. mii_ctrl_reg |= MII_CR_SPEED_100;
  884. mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
  885. DEBUGOUT("Forcing 100mb ");
  886. } else {
  887. /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
  888. ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  889. mii_ctrl_reg |= MII_CR_SPEED_10;
  890. mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
  891. DEBUGOUT("Forcing 10mb ");
  892. }
  893. e1000_config_collision_dist(hw);
  894. /* Write the configured values back to the Device Control Reg. */
  895. E1000_WRITE_REG(hw, CTRL, ctrl);
  896. /* Write the MII Control Register with the new PHY configuration. */
  897. if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data) < 0) {
  898. DEBUGOUT("PHY Read Error\n");
  899. return -E1000_ERR_PHY;
  900. }
  901. /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
  902. * forced whenever speed are duplex are forced.
  903. */
  904. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  905. if(e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data) < 0) {
  906. DEBUGOUT("PHY Write Error\n");
  907. return -E1000_ERR_PHY;
  908. }
  909. DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
  910. /* Need to reset the PHY or these changes will be ignored */
  911. mii_ctrl_reg |= MII_CR_RESET;
  912. if(e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg) < 0) {
  913. DEBUGOUT("PHY Write Error\n");
  914. return -E1000_ERR_PHY;
  915. }
  916. usec_delay(1);
  917. /* The wait_autoneg_complete flag may be a little misleading here.
  918. * Since we are forcing speed and duplex, Auto-Neg is not enabled.
  919. * But we do want to delay for a period while forcing only so we
  920. * don't generate false No Link messages. So we will wait here
  921. * only if the user has set wait_autoneg_complete to 1, which is
  922. * the default.
  923. */
  924. if(hw->wait_autoneg_complete) {
  925. /* We will wait for autoneg to complete. */
  926. DEBUGOUT("Waiting for forced speed/duplex link.\n");
  927. mii_status_reg = 0;
  928. /* We will wait for autoneg to complete or 4.5 seconds to expire. */
  929. for(i = PHY_FORCE_TIME; i > 0; i--) {
  930. /* Read the MII Status Register and wait for Auto-Neg Complete bit
  931. * to be set.
  932. */
  933. if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
  934. DEBUGOUT("PHY Read Error\n");
  935. return -E1000_ERR_PHY;
  936. }
  937. if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
  938. DEBUGOUT("PHY Read Error\n");
  939. return -E1000_ERR_PHY;
  940. }
  941. if(mii_status_reg & MII_SR_LINK_STATUS) break;
  942. msec_delay(100);
  943. }
  944. if(i == 0) { /* We didn't get link */
  945. /* Reset the DSP and wait again for link. */
  946. ret_val = e1000_phy_reset_dsp(hw);
  947. if(ret_val < 0) {
  948. DEBUGOUT("Error Resetting PHY DSP\n");
  949. return ret_val;
  950. }
  951. }
  952. /* This loop will early-out if the link condition has been met. */
  953. for(i = PHY_FORCE_TIME; i > 0; i--) {
  954. if(mii_status_reg & MII_SR_LINK_STATUS) break;
  955. msec_delay(100);
  956. /* Read the MII Status Register and wait for Auto-Neg Complete bit
  957. * to be set.
  958. */
  959. if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
  960. DEBUGOUT("PHY Read Error\n");
  961. return -E1000_ERR_PHY;
  962. }
  963. if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
  964. DEBUGOUT("PHY Read Error\n");
  965. return -E1000_ERR_PHY;
  966. }
  967. }
  968. }
  969. /* Because we reset the PHY above, we need to re-force TX_CLK in the
  970. * Extended PHY Specific Control Register to 25MHz clock. This value
  971. * defaults back to a 2.5MHz clock when the PHY is reset.
  972. */
  973. if(e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data) < 0) {
  974. DEBUGOUT("PHY Read Error\n");
  975. return -E1000_ERR_PHY;
  976. }
  977. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  978. if(e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data) < 0) {
  979. DEBUGOUT("PHY Write Error\n");
  980. return -E1000_ERR_PHY;
  981. }
  982. /* In addition, because of the s/w reset above, we need to enable CRS on
  983. * TX. This must be set for both full and half duplex operation.
  984. */
  985. if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data) < 0) {
  986. DEBUGOUT("PHY Read Error\n");
  987. return -E1000_ERR_PHY;
  988. }
  989. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  990. if(e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data) < 0) {
  991. DEBUGOUT("PHY Write Error\n");
  992. return -E1000_ERR_PHY;
  993. }
  994. return 0;
  995. }
  996. /******************************************************************************
  997. * Sets the collision distance in the Transmit Control register
  998. *
  999. * hw - Struct containing variables accessed by shared code
  1000. *
  1001. * Link should have been established previously. Reads the speed and duplex
  1002. * information from the Device Status register.
  1003. ******************************************************************************/
  1004. void
  1005. e1000_config_collision_dist(struct e1000_hw *hw)
  1006. {
  1007. uint32_t tctl;
  1008. tctl = E1000_READ_REG(hw, TCTL);
  1009. tctl &= ~E1000_TCTL_COLD;
  1010. tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
  1011. E1000_WRITE_REG(hw, TCTL, tctl);
  1012. E1000_WRITE_FLUSH(hw);
  1013. }
  1014. /******************************************************************************
  1015. * Sets MAC speed and duplex settings to reflect the those in the PHY
  1016. *
  1017. * hw - Struct containing variables accessed by shared code
  1018. * mii_reg - data to write to the MII control register
  1019. *
  1020. * The contents of the PHY register containing the needed information need to
  1021. * be passed in.
  1022. ******************************************************************************/
  1023. static int32_t
  1024. e1000_config_mac_to_phy(struct e1000_hw *hw)
  1025. {
  1026. uint32_t ctrl;
  1027. uint16_t phy_data;
  1028. DEBUGFUNC("e1000_config_mac_to_phy");
  1029. /* Read the Device Control Register and set the bits to Force Speed
  1030. * and Duplex.
  1031. */
  1032. ctrl = E1000_READ_REG(hw, CTRL);
  1033. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1034. ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
  1035. /* Set up duplex in the Device Control and Transmit Control
  1036. * registers depending on negotiated values.
  1037. */
  1038. if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
  1039. DEBUGOUT("PHY Read Error\n");
  1040. return -E1000_ERR_PHY;
  1041. }
  1042. if(phy_data & M88E1000_PSSR_DPLX) ctrl |= E1000_CTRL_FD;
  1043. else ctrl &= ~E1000_CTRL_FD;
  1044. e1000_config_collision_dist(hw);
  1045. /* Set up speed in the Device Control register depending on
  1046. * negotiated values.
  1047. */
  1048. if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
  1049. ctrl |= E1000_CTRL_SPD_1000;
  1050. else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
  1051. ctrl |= E1000_CTRL_SPD_100;
  1052. /* Write the configured values back to the Device Control Reg. */
  1053. E1000_WRITE_REG(hw, CTRL, ctrl);
  1054. return 0;
  1055. }
  1056. /******************************************************************************
  1057. * Forces the MAC's flow control settings.
  1058. *
  1059. * hw - Struct containing variables accessed by shared code
  1060. *
  1061. * Sets the TFCE and RFCE bits in the device control register to reflect
  1062. * the adapter settings. TFCE and RFCE need to be explicitly set by
  1063. * software when a Copper PHY is used because autonegotiation is managed
  1064. * by the PHY rather than the MAC. Software must also configure these
  1065. * bits when link is forced on a fiber connection.
  1066. *****************************************************************************/
  1067. static int32_t
  1068. e1000_force_mac_fc(struct e1000_hw *hw)
  1069. {
  1070. uint32_t ctrl;
  1071. DEBUGFUNC("e1000_force_mac_fc");
  1072. /* Get the current configuration of the Device Control Register */
  1073. ctrl = E1000_READ_REG(hw, CTRL);
  1074. /* Because we didn't get link via the internal auto-negotiation
  1075. * mechanism (we either forced link or we got link via PHY
  1076. * auto-neg), we have to manually enable/disable transmit an
  1077. * receive flow control.
  1078. *
  1079. * The "Case" statement below enables/disable flow control
  1080. * according to the "hw->fc" parameter.
  1081. *
  1082. * The possible values of the "fc" parameter are:
  1083. * 0: Flow control is completely disabled
  1084. * 1: Rx flow control is enabled (we can receive pause
  1085. * frames but not send pause frames).
  1086. * 2: Tx flow control is enabled (we can send pause frames
  1087. * frames but we do not receive pause frames).
  1088. * 3: Both Rx and TX flow control (symmetric) is enabled.
  1089. * other: No other values should be possible at this point.
  1090. */
  1091. switch (hw->fc) {
  1092. case e1000_fc_none:
  1093. ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
  1094. break;
  1095. case e1000_fc_rx_pause:
  1096. ctrl &= (~E1000_CTRL_TFCE);
  1097. ctrl |= E1000_CTRL_RFCE;
  1098. break;
  1099. case e1000_fc_tx_pause:
  1100. ctrl &= (~E1000_CTRL_RFCE);
  1101. ctrl |= E1000_CTRL_TFCE;
  1102. break;
  1103. case e1000_fc_full:
  1104. ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
  1105. break;
  1106. default:
  1107. DEBUGOUT("Flow control param set incorrectly\n");
  1108. return -E1000_ERR_CONFIG;
  1109. }
  1110. /* Disable TX Flow Control for 82542 (rev 2.0) */
  1111. if(hw->mac_type == e1000_82542_rev2_0)
  1112. ctrl &= (~E1000_CTRL_TFCE);
  1113. E1000_WRITE_REG(hw, CTRL, ctrl);
  1114. return 0;
  1115. }
  1116. /******************************************************************************
  1117. * Configures flow control settings after link is established
  1118. *
  1119. * hw - Struct containing variables accessed by shared code
  1120. *
  1121. * Should be called immediately after a valid link has been established.
  1122. * Forces MAC flow control settings if link was forced. When in MII/GMII mode
  1123. * and autonegotiation is enabled, the MAC flow control settings will be set
  1124. * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
  1125. * and RFCE bits will be automaticaly set to the negotiated flow control mode.
  1126. *****************************************************************************/
  1127. int32_t
  1128. e1000_config_fc_after_link_up(struct e1000_hw *hw)
  1129. {
  1130. int32_t ret_val;
  1131. uint16_t mii_status_reg;
  1132. uint16_t mii_nway_adv_reg;
  1133. uint16_t mii_nway_lp_ability_reg;
  1134. uint16_t speed;
  1135. uint16_t duplex;
  1136. DEBUGFUNC("e1000_config_fc_after_link_up");
  1137. /* Check for the case where we have fiber media and auto-neg failed
  1138. * so we had to force link. In this case, we need to force the
  1139. * configuration of the MAC to match the "fc" parameter.
  1140. */
  1141. if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
  1142. ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
  1143. ret_val = e1000_force_mac_fc(hw);
  1144. if(ret_val < 0) {
  1145. DEBUGOUT("Error forcing flow control settings\n");
  1146. return ret_val;
  1147. }
  1148. }
  1149. /* Check for the case where we have copper media and auto-neg is
  1150. * enabled. In this case, we need to check and see if Auto-Neg
  1151. * has completed, and if so, how the PHY and link partner has
  1152. * flow control configured.
  1153. */
  1154. if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
  1155. /* Read the MII Status Register and check to see if AutoNeg
  1156. * has completed. We read this twice because this reg has
  1157. * some "sticky" (latched) bits.
  1158. */
  1159. if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
  1160. DEBUGOUT("PHY Read Error \n");
  1161. return -E1000_ERR_PHY;
  1162. }
  1163. if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
  1164. DEBUGOUT("PHY Read Error \n");
  1165. return -E1000_ERR_PHY;
  1166. }
  1167. if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
  1168. /* The AutoNeg process has completed, so we now need to
  1169. * read both the Auto Negotiation Advertisement Register
  1170. * (Address 4) and the Auto_Negotiation Base Page Ability
  1171. * Register (Address 5) to determine how flow control was
  1172. * negotiated.
  1173. */
  1174. if(e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
  1175. DEBUGOUT("PHY Read Error\n");
  1176. return -E1000_ERR_PHY;
  1177. }
  1178. if(e1000_read_phy_reg(hw, PHY_LP_ABILITY, &mii_nway_lp_ability_reg) < 0) {
  1179. DEBUGOUT("PHY Read Error\n");
  1180. return -E1000_ERR_PHY;
  1181. }
  1182. /* Two bits in the Auto Negotiation Advertisement Register
  1183. * (Address 4) and two bits in the Auto Negotiation Base
  1184. * Page Ability Register (Address 5) determine flow control
  1185. * for both the PHY and the link partner. The following
  1186. * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
  1187. * 1999, describes these PAUSE resolution bits and how flow
  1188. * control is determined based upon these settings.
  1189. * NOTE: DC = Don't Care
  1190. *
  1191. * LOCAL DEVICE | LINK PARTNER
  1192. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  1193. *-------|---------|-------|---------|--------------------
  1194. * 0 | 0 | DC | DC | e1000_fc_none
  1195. * 0 | 1 | 0 | DC | e1000_fc_none
  1196. * 0 | 1 | 1 | 0 | e1000_fc_none
  1197. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  1198. * 1 | 0 | 0 | DC | e1000_fc_none
  1199. * 1 | DC | 1 | DC | e1000_fc_full
  1200. * 1 | 1 | 0 | 0 | e1000_fc_none
  1201. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  1202. *
  1203. */
  1204. /* Are both PAUSE bits set to 1? If so, this implies
  1205. * Symmetric Flow Control is enabled at both ends. The
  1206. * ASM_DIR bits are irrelevant per the spec.
  1207. *
  1208. * For Symmetric Flow Control:
  1209. *
  1210. * LOCAL DEVICE | LINK PARTNER
  1211. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1212. *-------|---------|-------|---------|--------------------
  1213. * 1 | DC | 1 | DC | e1000_fc_full
  1214. *
  1215. */
  1216. if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1217. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
  1218. /* Now we need to check if the user selected RX ONLY
  1219. * of pause frames. In this case, we had to advertise
  1220. * FULL flow control because we could not advertise RX
  1221. * ONLY. Hence, we must now check to see if we need to
  1222. * turn OFF the TRANSMISSION of PAUSE frames.
  1223. */
  1224. if(hw->original_fc == e1000_fc_full) {
  1225. hw->fc = e1000_fc_full;
  1226. DEBUGOUT("Flow Control = FULL.\r\n");
  1227. } else {
  1228. hw->fc = e1000_fc_rx_pause;
  1229. DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
  1230. }
  1231. }
  1232. /* For receiving PAUSE frames ONLY.
  1233. *
  1234. * LOCAL DEVICE | LINK PARTNER
  1235. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1236. *-------|---------|-------|---------|--------------------
  1237. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  1238. *
  1239. */
  1240. else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1241. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  1242. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  1243. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  1244. hw->fc = e1000_fc_tx_pause;
  1245. DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
  1246. }
  1247. /* For transmitting PAUSE frames ONLY.
  1248. *
  1249. * LOCAL DEVICE | LINK PARTNER
  1250. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1251. *-------|---------|-------|---------|--------------------
  1252. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  1253. *
  1254. */
  1255. else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1256. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  1257. !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  1258. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  1259. hw->fc = e1000_fc_rx_pause;
  1260. DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
  1261. }
  1262. /* Per the IEEE spec, at this point flow control should be
  1263. * disabled. However, we want to consider that we could
  1264. * be connected to a legacy switch that doesn't advertise
  1265. * desired flow control, but can be forced on the link
  1266. * partner. So if we advertised no flow control, that is
  1267. * what we will resolve to. If we advertised some kind of
  1268. * receive capability (Rx Pause Only or Full Flow Control)
  1269. * and the link partner advertised none, we will configure
  1270. * ourselves to enable Rx Flow Control only. We can do
  1271. * this safely for two reasons: If the link partner really
  1272. * didn't want flow control enabled, and we enable Rx, no
  1273. * harm done since we won't be receiving any PAUSE frames
  1274. * anyway. If the intent on the link partner was to have
  1275. * flow control enabled, then by us enabling RX only, we
  1276. * can at least receive pause frames and process them.
  1277. * This is a good idea because in most cases, since we are
  1278. * predominantly a server NIC, more times than not we will
  1279. * be asked to delay transmission of packets than asking
  1280. * our link partner to pause transmission of frames.
  1281. */
  1282. else if(hw->original_fc == e1000_fc_none ||
  1283. hw->original_fc == e1000_fc_tx_pause) {
  1284. hw->fc = e1000_fc_none;
  1285. DEBUGOUT("Flow Control = NONE.\r\n");
  1286. } else {
  1287. hw->fc = e1000_fc_rx_pause;
  1288. DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
  1289. }
  1290. /* Now we need to do one last check... If we auto-
  1291. * negotiated to HALF DUPLEX, flow control should not be
  1292. * enabled per IEEE 802.3 spec.
  1293. */
  1294. e1000_get_speed_and_duplex(hw, &speed, &duplex);
  1295. if(duplex == HALF_DUPLEX)
  1296. hw->fc = e1000_fc_none;
  1297. /* Now we call a subroutine to actually force the MAC
  1298. * controller to use the correct flow control settings.
  1299. */
  1300. ret_val = e1000_force_mac_fc(hw);
  1301. if(ret_val < 0) {
  1302. DEBUGOUT("Error forcing flow control settings\n");
  1303. return ret_val;
  1304. }
  1305. } else {
  1306. DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
  1307. }
  1308. }
  1309. return 0;
  1310. }
  1311. /******************************************************************************
  1312. * Checks to see if the link status of the hardware has changed.
  1313. *
  1314. * hw - Struct containing variables accessed by shared code
  1315. *
  1316. * Called by any function that needs to check the link status of the adapter.
  1317. *****************************************************************************/
  1318. int32_t
  1319. e1000_check_for_link(struct e1000_hw *hw)
  1320. {
  1321. uint32_t rxcw;
  1322. uint32_t ctrl;
  1323. uint32_t status;
  1324. uint32_t rctl;
  1325. uint32_t signal;
  1326. int32_t ret_val;
  1327. uint16_t phy_data;
  1328. uint16_t lp_capability;
  1329. DEBUGFUNC("e1000_check_for_link");
  1330. /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
  1331. * set when the optics detect a signal. On older adapters, it will be
  1332. * cleared when there is a signal
  1333. */
  1334. if(hw->mac_type > e1000_82544) signal = E1000_CTRL_SWDPIN1;
  1335. else signal = 0;
  1336. ctrl = E1000_READ_REG(hw, CTRL);
  1337. status = E1000_READ_REG(hw, STATUS);
  1338. rxcw = E1000_READ_REG(hw, RXCW);
  1339. /* If we have a copper PHY then we only want to go out to the PHY
  1340. * registers to see if Auto-Neg has completed and/or if our link
  1341. * status has changed. The get_link_status flag will be set if we
  1342. * receive a Link Status Change interrupt or we have Rx Sequence
  1343. * Errors.
  1344. */
  1345. if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
  1346. /* First we want to see if the MII Status Register reports
  1347. * link. If so, then we want to get the current speed/duplex
  1348. * of the PHY.
  1349. * Read the register twice since the link bit is sticky.
  1350. */
  1351. if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  1352. DEBUGOUT("PHY Read Error\n");
  1353. return -E1000_ERR_PHY;
  1354. }
  1355. if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  1356. DEBUGOUT("PHY Read Error\n");
  1357. return -E1000_ERR_PHY;
  1358. }
  1359. if(phy_data & MII_SR_LINK_STATUS) {
  1360. hw->get_link_status = FALSE;
  1361. } else {
  1362. /* No link detected */
  1363. return 0;
  1364. }
  1365. /* If we are forcing speed/duplex, then we simply return since
  1366. * we have already determined whether we have link or not.
  1367. */
  1368. if(!hw->autoneg) return -E1000_ERR_CONFIG;
  1369. /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
  1370. * have Si on board that is 82544 or newer, Auto
  1371. * Speed Detection takes care of MAC speed/duplex
  1372. * configuration. So we only need to configure Collision
  1373. * Distance in the MAC. Otherwise, we need to force
  1374. * speed/duplex on the MAC to the current PHY speed/duplex
  1375. * settings.
  1376. */
  1377. if(hw->mac_type >= e1000_82544)
  1378. e1000_config_collision_dist(hw);
  1379. else {
  1380. ret_val = e1000_config_mac_to_phy(hw);
  1381. if(ret_val < 0) {
  1382. DEBUGOUT("Error configuring MAC to PHY settings\n");
  1383. return ret_val;
  1384. }
  1385. }
  1386. /* Configure Flow Control now that Auto-Neg has completed. First, we
  1387. * need to restore the desired flow control settings because we may
  1388. * have had to re-autoneg with a different link partner.
  1389. */
  1390. ret_val = e1000_config_fc_after_link_up(hw);
  1391. if(ret_val < 0) {
  1392. DEBUGOUT("Error configuring flow control\n");
  1393. return ret_val;
  1394. }
  1395. /* At this point we know that we are on copper and we have
  1396. * auto-negotiated link. These are conditions for checking the link
  1397. * parter capability register. We use the link partner capability to
  1398. * determine if TBI Compatibility needs to be turned on or off. If
  1399. * the link partner advertises any speed in addition to Gigabit, then
  1400. * we assume that they are GMII-based, and TBI compatibility is not
  1401. * needed. If no other speeds are advertised, we assume the link
  1402. * partner is TBI-based, and we turn on TBI Compatibility.
  1403. */
  1404. if(hw->tbi_compatibility_en) {
  1405. if(e1000_read_phy_reg(hw, PHY_LP_ABILITY, &lp_capability) < 0) {
  1406. DEBUGOUT("PHY Read Error\n");
  1407. return -E1000_ERR_PHY;
  1408. }
  1409. if(lp_capability & (NWAY_LPAR_10T_HD_CAPS |
  1410. NWAY_LPAR_10T_FD_CAPS |
  1411. NWAY_LPAR_100TX_HD_CAPS |
  1412. NWAY_LPAR_100TX_FD_CAPS |
  1413. NWAY_LPAR_100T4_CAPS)) {
  1414. /* If our link partner advertises anything in addition to
  1415. * gigabit, we do not need to enable TBI compatibility.
  1416. */
  1417. if(hw->tbi_compatibility_on) {
  1418. /* If we previously were in the mode, turn it off. */
  1419. rctl = E1000_READ_REG(hw, RCTL);
  1420. rctl &= ~E1000_RCTL_SBP;
  1421. E1000_WRITE_REG(hw, RCTL, rctl);
  1422. hw->tbi_compatibility_on = FALSE;
  1423. }
  1424. } else {
  1425. /* If TBI compatibility is was previously off, turn it on. For
  1426. * compatibility with a TBI link partner, we will store bad
  1427. * packets. Some frames have an additional byte on the end and
  1428. * will look like CRC errors to to the hardware.
  1429. */
  1430. if(!hw->tbi_compatibility_on) {
  1431. hw->tbi_compatibility_on = TRUE;
  1432. rctl = E1000_READ_REG(hw, RCTL);
  1433. rctl |= E1000_RCTL_SBP;
  1434. E1000_WRITE_REG(hw, RCTL, rctl);
  1435. }
  1436. }
  1437. }
  1438. }
  1439. /* If we don't have link (auto-negotiation failed or link partner cannot
  1440. * auto-negotiate), the cable is plugged in (we have signal), and our
  1441. * link partner is not trying to auto-negotiate with us (we are receiving
  1442. * idles or data), we need to force link up. We also need to give
  1443. * auto-negotiation time to complete, in case the cable was just plugged
  1444. * in. The autoneg_failed flag does this.
  1445. */
  1446. else if((hw->media_type == e1000_media_type_fiber) &&
  1447. (!(status & E1000_STATUS_LU)) &&
  1448. ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
  1449. (!(rxcw & E1000_RXCW_C))) {
  1450. if(hw->autoneg_failed == 0) {
  1451. hw->autoneg_failed = 1;
  1452. return 0;
  1453. }
  1454. DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
  1455. /* Disable auto-negotiation in the TXCW register */
  1456. E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
  1457. /* Force link-up and also force full-duplex. */
  1458. ctrl = E1000_READ_REG(hw, CTRL);
  1459. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  1460. E1000_WRITE_REG(hw, CTRL, ctrl);
  1461. /* Configure Flow Control after forcing link up. */
  1462. ret_val = e1000_config_fc_after_link_up(hw);
  1463. if(ret_val < 0) {
  1464. DEBUGOUT("Error configuring flow control\n");
  1465. return ret_val;
  1466. }
  1467. }
  1468. /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
  1469. * auto-negotiation in the TXCW register and disable forced link in the
  1470. * Device Control register in an attempt to auto-negotiate with our link
  1471. * partner.
  1472. */
  1473. else if((hw->media_type == e1000_media_type_fiber) &&
  1474. (ctrl & E1000_CTRL_SLU) &&
  1475. (rxcw & E1000_RXCW_C)) {
  1476. DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
  1477. E1000_WRITE_REG(hw, TXCW, hw->txcw);
  1478. E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
  1479. }
  1480. return 0;
  1481. }
  1482. /******************************************************************************
  1483. * Detects the current speed and duplex settings of the hardware.
  1484. *
  1485. * hw - Struct containing variables accessed by shared code
  1486. * speed - Speed of the connection
  1487. * duplex - Duplex setting of the connection
  1488. *****************************************************************************/
  1489. void
  1490. e1000_get_speed_and_duplex(struct e1000_hw *hw,
  1491. uint16_t *speed,
  1492. uint16_t *duplex)
  1493. {
  1494. uint32_t status;
  1495. DEBUGFUNC("e1000_get_speed_and_duplex");
  1496. if(hw->mac_type >= e1000_82543) {
  1497. status = E1000_READ_REG(hw, STATUS);
  1498. if(status & E1000_STATUS_SPEED_1000) {
  1499. *speed = SPEED_1000;
  1500. DEBUGOUT("1000 Mbs, ");
  1501. } else if(status & E1000_STATUS_SPEED_100) {
  1502. *speed = SPEED_100;
  1503. DEBUGOUT("100 Mbs, ");
  1504. } else {
  1505. *speed = SPEED_10;
  1506. DEBUGOUT("10 Mbs, ");
  1507. }
  1508. if(status & E1000_STATUS_FD) {
  1509. *duplex = FULL_DUPLEX;
  1510. DEBUGOUT("Full Duplex\r\n");
  1511. } else {
  1512. *duplex = HALF_DUPLEX;
  1513. DEBUGOUT(" Half Duplex\r\n");
  1514. }
  1515. } else {
  1516. DEBUGOUT("1000 Mbs, Full Duplex\r\n");
  1517. *speed = SPEED_1000;
  1518. *duplex = FULL_DUPLEX;
  1519. }
  1520. }
  1521. /******************************************************************************
  1522. * Blocks until autoneg completes or times out (~4.5 seconds)
  1523. *
  1524. * hw - Struct containing variables accessed by shared code
  1525. ******************************************************************************/
  1526. int32_t
  1527. e1000_wait_autoneg(struct e1000_hw *hw)
  1528. {
  1529. uint16_t i;
  1530. uint16_t phy_data;
  1531. DEBUGFUNC("e1000_wait_autoneg");
  1532. DEBUGOUT("Waiting for Auto-Neg to complete.\n");
  1533. /* We will wait for autoneg to complete or 4.5 seconds to expire. */
  1534. for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
  1535. /* Read the MII Status Register and wait for Auto-Neg
  1536. * Complete bit to be set.
  1537. */
  1538. if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  1539. DEBUGOUT("PHY Read Error\n");
  1540. return -E1000_ERR_PHY;
  1541. }
  1542. if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  1543. DEBUGOUT("PHY Read Error\n");
  1544. return -E1000_ERR_PHY;
  1545. }
  1546. if(phy_data & MII_SR_AUTONEG_COMPLETE) {
  1547. return 0;
  1548. }
  1549. msec_delay(100);
  1550. }
  1551. return 0;
  1552. }
  1553. /******************************************************************************
  1554. * Raises the Management Data Clock
  1555. *
  1556. * hw - Struct containing variables accessed by shared code
  1557. * ctrl - Device control register's current value
  1558. ******************************************************************************/
  1559. static void
  1560. e1000_raise_mdi_clk(struct e1000_hw *hw,
  1561. uint32_t *ctrl)
  1562. {
  1563. /* Raise the clock input to the Management Data Clock (by setting the MDC
  1564. * bit), and then delay 2 microseconds.
  1565. */
  1566. E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
  1567. E1000_WRITE_FLUSH(hw);
  1568. usec_delay(2);
  1569. }
  1570. /******************************************************************************
  1571. * Lowers the Management Data Clock
  1572. *
  1573. * hw - Struct containing variables accessed by shared code
  1574. * ctrl - Device control register's current value
  1575. ******************************************************************************/
  1576. static void
  1577. e1000_lower_mdi_clk(struct e1000_hw *hw,
  1578. uint32_t *ctrl)
  1579. {
  1580. /* Lower the clock input to the Management Data Clock (by clearing the MDC
  1581. * bit), and then delay 2 microseconds.
  1582. */
  1583. E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
  1584. E1000_WRITE_FLUSH(hw);
  1585. usec_delay(2);
  1586. }
  1587. /******************************************************************************
  1588. * Shifts data bits out to the PHY
  1589. *
  1590. * hw - Struct containing variables accessed by shared code
  1591. * data - Data to send out to the PHY
  1592. * count - Number of bits to shift out
  1593. *
  1594. * Bits are shifted out in MSB to LSB order.
  1595. ******************************************************************************/
  1596. static void
  1597. e1000_shift_out_mdi_bits(struct e1000_hw *hw,
  1598. uint32_t data,
  1599. uint16_t count)
  1600. {
  1601. uint32_t ctrl;
  1602. uint32_t mask;
  1603. /* We need to shift "count" number of bits out to the PHY. So, the value
  1604. * in the "data" parameter will be shifted out to the PHY one bit at a
  1605. * time. In order to do this, "data" must be broken down into bits.
  1606. */
  1607. mask = 0x01;
  1608. mask <<= (count - 1);
  1609. ctrl = E1000_READ_REG(hw, CTRL);
  1610. /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
  1611. ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
  1612. while(mask) {
  1613. /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
  1614. * then raising and lowering the Management Data Clock. A "0" is
  1615. * shifted out to the PHY by setting the MDIO bit to "0" and then
  1616. * raising and lowering the clock.
  1617. */
  1618. if(data & mask) ctrl |= E1000_CTRL_MDIO;
  1619. else ctrl &= ~E1000_CTRL_MDIO;
  1620. E1000_WRITE_REG(hw, CTRL, ctrl);
  1621. E1000_WRITE_FLUSH(hw);
  1622. usec_delay(2);
  1623. e1000_raise_mdi_clk(hw, &ctrl);
  1624. e1000_lower_mdi_clk(hw, &ctrl);
  1625. mask = mask >> 1;
  1626. }
  1627. }
  1628. /******************************************************************************
  1629. * Shifts data bits in from the PHY
  1630. *
  1631. * hw - Struct containing variables accessed by shared code
  1632. *
  1633. * Bits are shifted in in MSB to LSB order.
  1634. ******************************************************************************/
  1635. static uint16_t
  1636. e1000_shift_in_mdi_bits(struct e1000_hw *hw)
  1637. {
  1638. uint32_t ctrl;
  1639. uint16_t data = 0;
  1640. uint8_t i;
  1641. /* In order to read a register from the PHY, we need to shift in a total
  1642. * of 18 bits from the PHY. The first two bit (turnaround) times are used
  1643. * to avoid contention on the MDIO pin when a read operation is performed.
  1644. * These two bits are ignored by us and thrown away. Bits are "shifted in"
  1645. * by raising the input to the Management Data Clock (setting the MDC bit),
  1646. * and then reading the value of the MDIO bit.
  1647. */
  1648. ctrl = E1000_READ_REG(hw, CTRL);
  1649. /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
  1650. ctrl &= ~E1000_CTRL_MDIO_DIR;
  1651. ctrl &= ~E1000_CTRL_MDIO;
  1652. E1000_WRITE_REG(hw, CTRL, ctrl);
  1653. E1000_WRITE_FLUSH(hw);
  1654. /* Raise and Lower the clock before reading in the data. This accounts for
  1655. * the turnaround bits. The first clock occurred when we clocked out the
  1656. * last bit of the Register Address.
  1657. */
  1658. e1000_raise_mdi_clk(hw, &ctrl);
  1659. e1000_lower_mdi_clk(hw, &ctrl);
  1660. for(data = 0, i = 0; i < 16; i++) {
  1661. data = data << 1;
  1662. e1000_raise_mdi_clk(hw, &ctrl);
  1663. ctrl = E1000_READ_REG(hw, CTRL);
  1664. /* Check to see if we shifted in a "1". */
  1665. if(ctrl & E1000_CTRL_MDIO) data |= 1;
  1666. e1000_lower_mdi_clk(hw, &ctrl);
  1667. }
  1668. e1000_raise_mdi_clk(hw, &ctrl);
  1669. e1000_lower_mdi_clk(hw, &ctrl);
  1670. return data;
  1671. }
  1672. /*****************************************************************************
  1673. * Reads the value from a PHY register
  1674. *
  1675. * hw - Struct containing variables accessed by shared code
  1676. * reg_addr - address of the PHY register to read
  1677. ******************************************************************************/
  1678. int32_t
  1679. e1000_read_phy_reg(struct e1000_hw *hw,
  1680. uint32_t reg_addr,
  1681. uint16_t *phy_data)
  1682. {
  1683. uint32_t i;
  1684. uint32_t mdic = 0;
  1685. const uint32_t phy_addr = 1;
  1686. DEBUGFUNC("e1000_read_phy_reg");
  1687. if(reg_addr > MAX_PHY_REG_ADDRESS) {
  1688. DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
  1689. return -E1000_ERR_PARAM;
  1690. }
  1691. if(hw->mac_type > e1000_82543) {
  1692. /* Set up Op-code, Phy Address, and register address in the MDI
  1693. * Control register. The MAC will take care of interfacing with the
  1694. * PHY to retrieve the desired data.
  1695. */
  1696. mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
  1697. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  1698. (E1000_MDIC_OP_READ));
  1699. E1000_WRITE_REG(hw, MDIC, mdic);
  1700. /* Poll the ready bit to see if the MDI read completed */
  1701. for(i = 0; i < 64; i++) {
  1702. usec_delay(10);
  1703. mdic = E1000_READ_REG(hw, MDIC);
  1704. if(mdic & E1000_MDIC_READY) break;
  1705. }
  1706. if(!(mdic & E1000_MDIC_READY)) {
  1707. DEBUGOUT("MDI Read did not complete\n");
  1708. return -E1000_ERR_PHY;
  1709. }
  1710. if(mdic & E1000_MDIC_ERROR) {
  1711. DEBUGOUT("MDI Error\n");
  1712. return -E1000_ERR_PHY;
  1713. }
  1714. *phy_data = (uint16_t) mdic;
  1715. } else {
  1716. /* We must first send a preamble through the MDIO pin to signal the
  1717. * beginning of an MII instruction. This is done by sending 32
  1718. * consecutive "1" bits.
  1719. */
  1720. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  1721. /* Now combine the next few fields that are required for a read
  1722. * operation. We use this method instead of calling the
  1723. * e1000_shift_out_mdi_bits routine five different times. The format of
  1724. * a MII read instruction consists of a shift out of 14 bits and is
  1725. * defined as follows:
  1726. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
  1727. * followed by a shift in of 18 bits. This first two bits shifted in
  1728. * are TurnAround bits used to avoid contention on the MDIO pin when a
  1729. * READ operation is performed. These two bits are thrown away
  1730. * followed by a shift in of 16 bits which contains the desired data.
  1731. */
  1732. mdic = ((reg_addr) | (phy_addr << 5) |
  1733. (PHY_OP_READ << 10) | (PHY_SOF << 12));
  1734. e1000_shift_out_mdi_bits(hw, mdic, 14);
  1735. /* Now that we've shifted out the read command to the MII, we need to
  1736. * "shift in" the 16-bit value (18 total bits) of the requested PHY
  1737. * register address.
  1738. */
  1739. *phy_data = e1000_shift_in_mdi_bits(hw);
  1740. }
  1741. return 0;
  1742. }
  1743. /******************************************************************************
  1744. * Writes a value to a PHY register
  1745. *
  1746. * hw - Struct containing variables accessed by shared code
  1747. * reg_addr - address of the PHY register to write
  1748. * data - data to write to the PHY
  1749. ******************************************************************************/
  1750. int32_t
  1751. e1000_write_phy_reg(struct e1000_hw *hw,
  1752. uint32_t reg_addr,
  1753. uint16_t phy_data)
  1754. {
  1755. uint32_t i;
  1756. uint32_t mdic = 0;
  1757. const uint32_t phy_addr = 1;
  1758. DEBUGFUNC("e1000_write_phy_reg");
  1759. if(reg_addr > MAX_PHY_REG_ADDRESS) {
  1760. DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
  1761. return -E1000_ERR_PARAM;
  1762. }
  1763. if(hw->mac_type > e1000_82543) {
  1764. /* Set up Op-code, Phy Address, register address, and data intended
  1765. * for the PHY register in the MDI Control register. The MAC will take
  1766. * care of interfacing with the PHY to send the desired data.
  1767. */
  1768. mdic = (((uint32_t) phy_data) |
  1769. (reg_addr << E1000_MDIC_REG_SHIFT) |
  1770. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  1771. (E1000_MDIC_OP_WRITE));
  1772. E1000_WRITE_REG(hw, MDIC, mdic);
  1773. /* Poll the ready bit to see if the MDI read completed */
  1774. for(i = 0; i < 64; i++) {
  1775. usec_delay(10);
  1776. mdic = E1000_READ_REG(hw, MDIC);
  1777. if(mdic & E1000_MDIC_READY) break;
  1778. }
  1779. if(!(mdic & E1000_MDIC_READY)) {
  1780. DEBUGOUT("MDI Write did not complete\n");
  1781. return -E1000_ERR_PHY;
  1782. }
  1783. } else {
  1784. /* We'll need to use the SW defined pins to shift the write command
  1785. * out to the PHY. We first send a preamble to the PHY to signal the
  1786. * beginning of the MII instruction. This is done by sending 32
  1787. * consecutive "1" bits.
  1788. */
  1789. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  1790. /* Now combine the remaining required fields that will indicate a
  1791. * write operation. We use this method instead of calling the
  1792. * e1000_shift_out_mdi_bits routine for each field in the command. The
  1793. * format of a MII write instruction is as follows:
  1794. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
  1795. */
  1796. mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
  1797. (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
  1798. mdic <<= 16;
  1799. mdic |= (uint32_t) phy_data;
  1800. e1000_shift_out_mdi_bits(hw, mdic, 32);
  1801. }
  1802. return 0;
  1803. }
  1804. /******************************************************************************
  1805. * Returns the PHY to the power-on reset state
  1806. *
  1807. * hw - Struct containing variables accessed by shared code
  1808. ******************************************************************************/
  1809. void
  1810. e1000_phy_hw_reset(struct e1000_hw *hw)
  1811. {
  1812. uint32_t ctrl;
  1813. uint32_t ctrl_ext;
  1814. DEBUGFUNC("e1000_phy_hw_reset");
  1815. DEBUGOUT("Resetting Phy...\n");
  1816. if(hw->mac_type > e1000_82543) {
  1817. /* Read the device control register and assert the E1000_CTRL_PHY_RST
  1818. * bit. Then, take it out of reset.
  1819. */
  1820. ctrl = E1000_READ_REG(hw, CTRL);
  1821. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
  1822. E1000_WRITE_FLUSH(hw);
  1823. msec_delay(10);
  1824. E1000_WRITE_REG(hw, CTRL, ctrl);
  1825. E1000_WRITE_FLUSH(hw);
  1826. } else {
  1827. /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
  1828. * bit to put the PHY into reset. Then, take it out of reset.
  1829. */
  1830. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  1831. ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
  1832. ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
  1833. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  1834. E1000_WRITE_FLUSH(hw);
  1835. msec_delay(10);
  1836. ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
  1837. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  1838. E1000_WRITE_FLUSH(hw);
  1839. }
  1840. usec_delay(150);
  1841. }
  1842. /******************************************************************************
  1843. * Resets the PHY
  1844. *
  1845. * hw - Struct containing variables accessed by shared code
  1846. *
  1847. * Sets bit 15 of the MII Control regiser
  1848. ******************************************************************************/
  1849. int32_t
  1850. e1000_phy_reset(struct e1000_hw *hw)
  1851. {
  1852. uint16_t phy_data;
  1853. DEBUGFUNC("e1000_phy_reset");
  1854. if(e1000_read_phy_reg(hw, PHY_CTRL, &phy_data) < 0) {
  1855. DEBUGOUT("PHY Read Error\n");
  1856. return -E1000_ERR_PHY;
  1857. }
  1858. phy_data |= MII_CR_RESET;
  1859. if(e1000_write_phy_reg(hw, PHY_CTRL, phy_data) < 0) {
  1860. DEBUGOUT("PHY Write Error\n");
  1861. return -E1000_ERR_PHY;
  1862. }
  1863. usec_delay(1);
  1864. return 0;
  1865. }
  1866. /******************************************************************************
  1867. * Probes the expected PHY address for known PHY IDs
  1868. *
  1869. * hw - Struct containing variables accessed by shared code
  1870. ******************************************************************************/
  1871. int32_t
  1872. e1000_detect_gig_phy(struct e1000_hw *hw)
  1873. {
  1874. uint16_t phy_id_high, phy_id_low;
  1875. boolean_t match = FALSE;
  1876. DEBUGFUNC("e1000_detect_gig_phy");
  1877. /* Read the PHY ID Registers to identify which PHY is onboard. */
  1878. if(e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high) < 0) {
  1879. DEBUGOUT("PHY Read Error\n");
  1880. return -E1000_ERR_PHY;
  1881. }
  1882. hw->phy_id = (uint32_t) (phy_id_high << 16);
  1883. usec_delay(2);
  1884. if(e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low) < 0) {
  1885. DEBUGOUT("PHY Read Error\n");
  1886. return -E1000_ERR_PHY;
  1887. }
  1888. hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
  1889. switch(hw->mac_type) {
  1890. case e1000_82543:
  1891. if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
  1892. break;
  1893. case e1000_82544:
  1894. if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
  1895. break;
  1896. case e1000_82540:
  1897. case e1000_82545:
  1898. case e1000_82546:
  1899. if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
  1900. break;
  1901. default:
  1902. DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
  1903. return -E1000_ERR_CONFIG;
  1904. }
  1905. if(match) {
  1906. DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
  1907. return 0;
  1908. }
  1909. DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
  1910. return -E1000_ERR_PHY;
  1911. }
  1912. /******************************************************************************
  1913. * Resets the PHY's DSP
  1914. *
  1915. * hw - Struct containing variables accessed by shared code
  1916. ******************************************************************************/
  1917. static int32_t
  1918. e1000_phy_reset_dsp(struct e1000_hw *hw)
  1919. {
  1920. int32_t ret_val = -E1000_ERR_PHY;
  1921. DEBUGFUNC("e1000_phy_reset_dsp");
  1922. do {
  1923. if(e1000_write_phy_reg(hw, 29, 0x001d) < 0) break;
  1924. if(e1000_write_phy_reg(hw, 30, 0x00c1) < 0) break;
  1925. if(e1000_write_phy_reg(hw, 30, 0x0000) < 0) break;
  1926. ret_val = 0;
  1927. } while(0);
  1928. if(ret_val < 0) DEBUGOUT("PHY Write Error\n");
  1929. return ret_val;
  1930. }
  1931. /******************************************************************************
  1932. * Get PHY information from various PHY registers
  1933. *
  1934. * hw - Struct containing variables accessed by shared code
  1935. * phy_info - PHY information structure
  1936. ******************************************************************************/
  1937. int32_t
  1938. e1000_phy_get_info(struct e1000_hw *hw,
  1939. struct e1000_phy_info *phy_info)
  1940. {
  1941. int32_t ret_val = -E1000_ERR_PHY;
  1942. uint16_t phy_data;
  1943. DEBUGFUNC("e1000_phy_get_info");
  1944. phy_info->cable_length = e1000_cable_length_undefined;
  1945. phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
  1946. phy_info->cable_polarity = e1000_rev_polarity_undefined;
  1947. phy_info->polarity_correction = e1000_polarity_reversal_undefined;
  1948. phy_info->mdix_mode = e1000_auto_x_mode_undefined;
  1949. phy_info->local_rx = e1000_1000t_rx_status_undefined;
  1950. phy_info->remote_rx = e1000_1000t_rx_status_undefined;
  1951. if(hw->media_type != e1000_media_type_copper) {
  1952. DEBUGOUT("PHY info is only valid for copper media\n");
  1953. return -E1000_ERR_CONFIG;
  1954. }
  1955. do {
  1956. if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) break;
  1957. if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) break;
  1958. if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
  1959. DEBUGOUT("PHY info is only valid if link is up\n");
  1960. return -E1000_ERR_CONFIG;
  1961. }
  1962. if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data) < 0)
  1963. break;
  1964. phy_info->extended_10bt_distance =
  1965. (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
  1966. M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
  1967. phy_info->polarity_correction =
  1968. (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
  1969. M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
  1970. if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0)
  1971. break;
  1972. phy_info->cable_polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
  1973. M88E1000_PSSR_REV_POLARITY_SHIFT;
  1974. phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
  1975. M88E1000_PSSR_MDIX_SHIFT;
  1976. if(phy_data & M88E1000_PSSR_1000MBS) {
  1977. /* Cable Length Estimation and Local/Remote Receiver Informatoion
  1978. * are only valid at 1000 Mbps
  1979. */
  1980. phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
  1981. M88E1000_PSSR_CABLE_LENGTH_SHIFT);
  1982. if(e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data) < 0)
  1983. break;
  1984. phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
  1985. SR_1000T_LOCAL_RX_STATUS_SHIFT;
  1986. phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
  1987. SR_1000T_REMOTE_RX_STATUS_SHIFT;
  1988. }
  1989. ret_val = 0;
  1990. } while(0);
  1991. if(ret_val < 0) DEBUGOUT("PHY Read Error\n");
  1992. return ret_val;
  1993. }
  1994. int32_t
  1995. e1000_validate_mdi_setting(struct e1000_hw *hw)
  1996. {
  1997. DEBUGFUNC("e1000_validate_mdi_settings");
  1998. if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
  1999. DEBUGOUT("Invalid MDI setting detected\n");
  2000. hw->mdix = 1;
  2001. return -E1000_ERR_CONFIG;
  2002. }
  2003. return 0;
  2004. }
  2005. /******************************************************************************
  2006. * Raises the EEPROM's clock input.
  2007. *
  2008. * hw - Struct containing variables accessed by shared code
  2009. * eecd - EECD's current value
  2010. *****************************************************************************/
  2011. static void
  2012. e1000_raise_ee_clk(struct e1000_hw *hw,
  2013. uint32_t *eecd)
  2014. {
  2015. /* Raise the clock input to the EEPROM (by setting the SK bit), and then
  2016. * wait 50 microseconds.
  2017. */
  2018. *eecd = *eecd | E1000_EECD_SK;
  2019. E1000_WRITE_REG(hw, EECD, *eecd);
  2020. E1000_WRITE_FLUSH(hw);
  2021. usec_delay(50);
  2022. }
  2023. /******************************************************************************
  2024. * Lowers the EEPROM's clock input.
  2025. *
  2026. * hw - Struct containing variables accessed by shared code
  2027. * eecd - EECD's current value
  2028. *****************************************************************************/
  2029. static void
  2030. e1000_lower_ee_clk(struct e1000_hw *hw,
  2031. uint32_t *eecd)
  2032. {
  2033. /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
  2034. * wait 50 microseconds.
  2035. */
  2036. *eecd = *eecd & ~E1000_EECD_SK;
  2037. E1000_WRITE_REG(hw, EECD, *eecd);
  2038. E1000_WRITE_FLUSH(hw);
  2039. usec_delay(50);
  2040. }
  2041. /******************************************************************************
  2042. * Shift data bits out to the EEPROM.
  2043. *
  2044. * hw - Struct containing variables accessed by shared code
  2045. * data - data to send to the EEPROM
  2046. * count - number of bits to shift out
  2047. *****************************************************************************/
  2048. static void
  2049. e1000_shift_out_ee_bits(struct e1000_hw *hw,
  2050. uint16_t data,
  2051. uint16_t count)
  2052. {
  2053. uint32_t eecd;
  2054. uint32_t mask;
  2055. /* We need to shift "count" bits out to the EEPROM. So, value in the
  2056. * "data" parameter will be shifted out to the EEPROM one bit at a time.
  2057. * In order to do this, "data" must be broken down into bits.
  2058. */
  2059. mask = 0x01 << (count - 1);
  2060. eecd = E1000_READ_REG(hw, EECD);
  2061. eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
  2062. do {
  2063. /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
  2064. * and then raising and then lowering the clock (the SK bit controls
  2065. * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
  2066. * by setting "DI" to "0" and then raising and then lowering the clock.
  2067. */
  2068. eecd &= ~E1000_EECD_DI;
  2069. if(data & mask)
  2070. eecd |= E1000_EECD_DI;
  2071. E1000_WRITE_REG(hw, EECD, eecd);
  2072. E1000_WRITE_FLUSH(hw);
  2073. usec_delay(50);
  2074. e1000_raise_ee_clk(hw, &eecd);
  2075. e1000_lower_ee_clk(hw, &eecd);
  2076. mask = mask >> 1;
  2077. } while(mask);
  2078. /* We leave the "DI" bit set to "0" when we leave this routine. */
  2079. eecd &= ~E1000_EECD_DI;
  2080. E1000_WRITE_REG(hw, EECD, eecd);
  2081. }
  2082. /******************************************************************************
  2083. * Shift data bits in from the EEPROM
  2084. *
  2085. * hw - Struct containing variables accessed by shared code
  2086. *****************************************************************************/
  2087. static uint16_t
  2088. e1000_shift_in_ee_bits(struct e1000_hw *hw)
  2089. {
  2090. uint32_t eecd;
  2091. uint32_t i;
  2092. uint16_t data;
  2093. /* In order to read a register from the EEPROM, we need to shift 16 bits
  2094. * in from the EEPROM. Bits are "shifted in" by raising the clock input to
  2095. * the EEPROM (setting the SK bit), and then reading the value of the "DO"
  2096. * bit. During this "shifting in" process the "DI" bit should always be
  2097. * clear..
  2098. */
  2099. eecd = E1000_READ_REG(hw, EECD);
  2100. eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
  2101. data = 0;
  2102. for(i = 0; i < 16; i++) {
  2103. data = data << 1;
  2104. e1000_raise_ee_clk(hw, &eecd);
  2105. eecd = E1000_READ_REG(hw, EECD);
  2106. eecd &= ~(E1000_EECD_DI);
  2107. if(eecd & E1000_EECD_DO)
  2108. data |= 1;
  2109. e1000_lower_ee_clk(hw, &eecd);
  2110. }
  2111. return data;
  2112. }
  2113. /******************************************************************************
  2114. * Prepares EEPROM for access
  2115. *
  2116. * hw - Struct containing variables accessed by shared code
  2117. *
  2118. * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
  2119. * function should be called before issuing a command to the EEPROM.
  2120. *****************************************************************************/
  2121. static void
  2122. e1000_setup_eeprom(struct e1000_hw *hw)
  2123. {
  2124. uint32_t eecd;
  2125. eecd = E1000_READ_REG(hw, EECD);
  2126. /* Clear SK and DI */
  2127. eecd &= ~(E1000_EECD_SK | E1000_EECD_DI);
  2128. E1000_WRITE_REG(hw, EECD, eecd);
  2129. /* Set CS */
  2130. eecd |= E1000_EECD_CS;
  2131. E1000_WRITE_REG(hw, EECD, eecd);
  2132. }
  2133. /******************************************************************************
  2134. * Returns EEPROM to a "standby" state
  2135. *
  2136. * hw - Struct containing variables accessed by shared code
  2137. *****************************************************************************/
  2138. static void
  2139. e1000_standby_eeprom(struct e1000_hw *hw)
  2140. {
  2141. uint32_t eecd;
  2142. eecd = E1000_READ_REG(hw, EECD);
  2143. /* Deselct EEPROM */
  2144. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  2145. E1000_WRITE_REG(hw, EECD, eecd);
  2146. E1000_WRITE_FLUSH(hw);
  2147. usec_delay(50);
  2148. /* Clock high */
  2149. eecd |= E1000_EECD_SK;
  2150. E1000_WRITE_REG(hw, EECD, eecd);
  2151. E1000_WRITE_FLUSH(hw);
  2152. usec_delay(50);
  2153. /* Select EEPROM */
  2154. eecd |= E1000_EECD_CS;
  2155. E1000_WRITE_REG(hw, EECD, eecd);
  2156. E1000_WRITE_FLUSH(hw);
  2157. usec_delay(50);
  2158. /* Clock low */
  2159. eecd &= ~E1000_EECD_SK;
  2160. E1000_WRITE_REG(hw, EECD, eecd);
  2161. E1000_WRITE_FLUSH(hw);
  2162. usec_delay(50);
  2163. }
  2164. /******************************************************************************
  2165. * Raises then lowers the EEPROM's clock pin
  2166. *
  2167. * hw - Struct containing variables accessed by shared code
  2168. *****************************************************************************/
  2169. static void
  2170. e1000_clock_eeprom(struct e1000_hw *hw)
  2171. {
  2172. uint32_t eecd;
  2173. eecd = E1000_READ_REG(hw, EECD);
  2174. /* Rising edge of clock */
  2175. eecd |= E1000_EECD_SK;
  2176. E1000_WRITE_REG(hw, EECD, eecd);
  2177. E1000_WRITE_FLUSH(hw);
  2178. usec_delay(50);
  2179. /* Falling edge of clock */
  2180. eecd &= ~E1000_EECD_SK;
  2181. E1000_WRITE_REG(hw, EECD, eecd);
  2182. E1000_WRITE_FLUSH(hw);
  2183. usec_delay(50);
  2184. }
  2185. /******************************************************************************
  2186. * Terminates a command by lowering the EEPROM's chip select pin
  2187. *
  2188. * hw - Struct containing variables accessed by shared code
  2189. *****************************************************************************/
  2190. static void
  2191. e1000_cleanup_eeprom(struct e1000_hw *hw)
  2192. {
  2193. uint32_t eecd;
  2194. eecd = E1000_READ_REG(hw, EECD);
  2195. eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
  2196. E1000_WRITE_REG(hw, EECD, eecd);
  2197. e1000_clock_eeprom(hw);
  2198. }
  2199. /******************************************************************************
  2200. * Reads a 16 bit word from the EEPROM.
  2201. *
  2202. * hw - Struct containing variables accessed by shared code
  2203. * offset - offset of word in the EEPROM to read
  2204. * data - word read from the EEPROM
  2205. *****************************************************************************/
  2206. int32_t
  2207. e1000_read_eeprom(struct e1000_hw *hw,
  2208. uint16_t offset,
  2209. uint16_t *data)
  2210. {
  2211. uint32_t eecd;
  2212. uint32_t i = 0;
  2213. boolean_t large_eeprom = FALSE;
  2214. DEBUGFUNC("e1000_read_eeprom");
  2215. /* Request EEPROM Access */
  2216. if(hw->mac_type > e1000_82544) {
  2217. eecd = E1000_READ_REG(hw, EECD);
  2218. if(eecd & E1000_EECD_SIZE) large_eeprom = TRUE;
  2219. eecd |= E1000_EECD_REQ;
  2220. E1000_WRITE_REG(hw, EECD, eecd);
  2221. eecd = E1000_READ_REG(hw, EECD);
  2222. while((!(eecd & E1000_EECD_GNT)) && (i < 100)) {
  2223. i++;
  2224. usec_delay(5);
  2225. eecd = E1000_READ_REG(hw, EECD);
  2226. }
  2227. if(!(eecd & E1000_EECD_GNT)) {
  2228. eecd &= ~E1000_EECD_REQ;
  2229. E1000_WRITE_REG(hw, EECD, eecd);
  2230. DEBUGOUT("Could not acquire EEPROM grant\n");
  2231. return -E1000_ERR_EEPROM;
  2232. }
  2233. }
  2234. /* Prepare the EEPROM for reading */
  2235. e1000_setup_eeprom(hw);
  2236. /* Send the READ command (opcode + addr) */
  2237. e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE, 3);
  2238. if(large_eeprom) {
  2239. /* If we have a 256 word EEPROM, there are 8 address bits */
  2240. e1000_shift_out_ee_bits(hw, offset, 8);
  2241. } else {
  2242. /* If we have a 64 word EEPROM, there are 6 address bits */
  2243. e1000_shift_out_ee_bits(hw, offset, 6);
  2244. }
  2245. /* Read the data */
  2246. *data = e1000_shift_in_ee_bits(hw);
  2247. /* End this read operation */
  2248. e1000_standby_eeprom(hw);
  2249. /* Stop requesting EEPROM access */
  2250. if(hw->mac_type > e1000_82544) {
  2251. eecd = E1000_READ_REG(hw, EECD);
  2252. eecd &= ~E1000_EECD_REQ;
  2253. E1000_WRITE_REG(hw, EECD, eecd);
  2254. }
  2255. return 0;
  2256. }
  2257. /******************************************************************************
  2258. * Verifies that the EEPROM has a valid checksum
  2259. *
  2260. * hw - Struct containing variables accessed by shared code
  2261. *
  2262. * Reads the first 64 16 bit words of the EEPROM and sums the values read.
  2263. * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
  2264. * valid.
  2265. *****************************************************************************/
  2266. int32_t
  2267. e1000_validate_eeprom_checksum(struct e1000_hw *hw)
  2268. {
  2269. uint16_t checksum = 0;
  2270. uint16_t i, eeprom_data;
  2271. DEBUGFUNC("e1000_validate_eeprom_checksum");
  2272. for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
  2273. if(e1000_read_eeprom(hw, i, &eeprom_data) < 0) {
  2274. DEBUGOUT("EEPROM Read Error\n");
  2275. return -E1000_ERR_EEPROM;
  2276. }
  2277. checksum += eeprom_data;
  2278. }
  2279. if(checksum == (uint16_t) EEPROM_SUM) {
  2280. return 0;
  2281. } else {
  2282. DEBUGOUT("EEPROM Checksum Invalid\n");
  2283. return -E1000_ERR_EEPROM;
  2284. }
  2285. }
  2286. /******************************************************************************
  2287. * Calculates the EEPROM checksum and writes it to the EEPROM
  2288. *
  2289. * hw - Struct containing variables accessed by shared code
  2290. *
  2291. * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
  2292. * Writes the difference to word offset 63 of the EEPROM.
  2293. *****************************************************************************/
  2294. int32_t
  2295. e1000_update_eeprom_checksum(struct e1000_hw *hw)
  2296. {
  2297. uint16_t checksum = 0;
  2298. uint16_t i, eeprom_data;
  2299. DEBUGFUNC("e1000_update_eeprom_checksum");
  2300. for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
  2301. if(e1000_read_eeprom(hw, i, &eeprom_data) < 0) {
  2302. DEBUGOUT("EEPROM Read Error\n");
  2303. return -E1000_ERR_EEPROM;
  2304. }
  2305. checksum += eeprom_data;
  2306. }
  2307. checksum = (uint16_t) EEPROM_SUM - checksum;
  2308. if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, checksum) < 0) {
  2309. DEBUGOUT("EEPROM Write Error\n");
  2310. return -E1000_ERR_EEPROM;
  2311. }
  2312. return 0;
  2313. }
  2314. /******************************************************************************
  2315. * Writes a 16 bit word to a given offset in the EEPROM.
  2316. *
  2317. * hw - Struct containing variables accessed by shared code
  2318. * offset - offset within the EEPROM to be written to
  2319. * data - 16 bit word to be writen to the EEPROM
  2320. *
  2321. * If e1000_update_eeprom_checksum is not called after this function, the
  2322. * EEPROM will most likely contain an invalid checksum.
  2323. *****************************************************************************/
  2324. int32_t
  2325. e1000_write_eeprom(struct e1000_hw *hw,
  2326. uint16_t offset,
  2327. uint16_t data)
  2328. {
  2329. uint32_t eecd;
  2330. uint32_t i = 0;
  2331. int32_t status = 0;
  2332. boolean_t large_eeprom = FALSE;
  2333. DEBUGFUNC("e1000_write_eeprom");
  2334. /* Request EEPROM Access */
  2335. if(hw->mac_type > e1000_82544) {
  2336. eecd = E1000_READ_REG(hw, EECD);
  2337. if(eecd & E1000_EECD_SIZE) large_eeprom = TRUE;
  2338. eecd |= E1000_EECD_REQ;
  2339. E1000_WRITE_REG(hw, EECD, eecd);
  2340. eecd = E1000_READ_REG(hw, EECD);
  2341. while((!(eecd & E1000_EECD_GNT)) && (i < 100)) {
  2342. i++;
  2343. usec_delay(5);
  2344. eecd = E1000_READ_REG(hw, EECD);
  2345. }
  2346. if(!(eecd & E1000_EECD_GNT)) {
  2347. eecd &= ~E1000_EECD_REQ;
  2348. E1000_WRITE_REG(hw, EECD, eecd);
  2349. DEBUGOUT("Could not acquire EEPROM grant\n");
  2350. return -E1000_ERR_EEPROM;
  2351. }
  2352. }
  2353. /* Prepare the EEPROM for writing */
  2354. e1000_setup_eeprom(hw);
  2355. /* Send the 9-bit (or 11-bit on large EEPROM) EWEN (write enable) command
  2356. * to the EEPROM (5-bit opcode plus 4/6-bit dummy). This puts the EEPROM
  2357. * into write/erase mode.
  2358. */
  2359. e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE, 5);
  2360. if(large_eeprom)
  2361. e1000_shift_out_ee_bits(hw, 0, 6);
  2362. else
  2363. e1000_shift_out_ee_bits(hw, 0, 4);
  2364. /* Prepare the EEPROM */
  2365. e1000_standby_eeprom(hw);
  2366. /* Send the Write command (3-bit opcode + addr) */
  2367. e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE, 3);
  2368. if(large_eeprom)
  2369. /* If we have a 256 word EEPROM, there are 8 address bits */
  2370. e1000_shift_out_ee_bits(hw, offset, 8);
  2371. else
  2372. /* If we have a 64 word EEPROM, there are 6 address bits */
  2373. e1000_shift_out_ee_bits(hw, offset, 6);
  2374. /* Send the data */
  2375. e1000_shift_out_ee_bits(hw, data, 16);
  2376. /* Toggle the CS line. This in effect tells to EEPROM to actually execute
  2377. * the command in question.
  2378. */
  2379. e1000_standby_eeprom(hw);
  2380. /* Now read DO repeatedly until is high (equal to '1'). The EEEPROM will
  2381. * signal that the command has been completed by raising the DO signal.
  2382. * If DO does not go high in 10 milliseconds, then error out.
  2383. */
  2384. for(i = 0; i < 200; i++) {
  2385. eecd = E1000_READ_REG(hw, EECD);
  2386. if(eecd & E1000_EECD_DO) break;
  2387. usec_delay(50);
  2388. }
  2389. if(i == 200) {
  2390. DEBUGOUT("EEPROM Write did not complete\n");
  2391. status = -E1000_ERR_EEPROM;
  2392. }
  2393. /* Recover from write */
  2394. e1000_standby_eeprom(hw);
  2395. /* Send the 9-bit (or 11-bit on large EEPROM) EWDS (write disable) command
  2396. * to the EEPROM (5-bit opcode plus 4/6-bit dummy). This takes the EEPROM
  2397. * out of write/erase mode.
  2398. */
  2399. e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE, 5);
  2400. if(large_eeprom)
  2401. e1000_shift_out_ee_bits(hw, 0, 6);
  2402. else
  2403. e1000_shift_out_ee_bits(hw, 0, 4);
  2404. /* Done with writing */
  2405. e1000_cleanup_eeprom(hw);
  2406. /* Stop requesting EEPROM access */
  2407. if(hw->mac_type > e1000_82544) {
  2408. eecd = E1000_READ_REG(hw, EECD);
  2409. eecd &= ~E1000_EECD_REQ;
  2410. E1000_WRITE_REG(hw, EECD, eecd);
  2411. }
  2412. return status;
  2413. }
  2414. /******************************************************************************
  2415. * Reads the adapter's part number from the EEPROM
  2416. *
  2417. * hw - Struct containing variables accessed by shared code
  2418. * part_num - Adapter's part number
  2419. *****************************************************************************/
  2420. int32_t
  2421. e1000_read_part_num(struct e1000_hw *hw,
  2422. uint32_t *part_num)
  2423. {
  2424. uint16_t offset = EEPROM_PBA_BYTE_1;
  2425. uint16_t eeprom_data;
  2426. DEBUGFUNC("e1000_read_part_num");
  2427. /* Get word 0 from EEPROM */
  2428. if(e1000_read_eeprom(hw, offset, &eeprom_data) < 0) {
  2429. DEBUGOUT("EEPROM Read Error\n");
  2430. return -E1000_ERR_EEPROM;
  2431. }
  2432. /* Save word 0 in upper half of part_num */
  2433. *part_num = (uint32_t) (eeprom_data << 16);
  2434. /* Get word 1 from EEPROM */
  2435. if(e1000_read_eeprom(hw, ++offset, &eeprom_data) < 0) {
  2436. DEBUGOUT("EEPROM Read Error\n");
  2437. return -E1000_ERR_EEPROM;
  2438. }
  2439. /* Save word 1 in lower half of part_num */
  2440. *part_num |= eeprom_data;
  2441. return 0;
  2442. }
  2443. /******************************************************************************
  2444. * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
  2445. * second function of dual function devices
  2446. *
  2447. * hw - Struct containing variables accessed by shared code
  2448. *****************************************************************************/
  2449. int32_t
  2450. e1000_read_mac_addr(struct e1000_hw * hw)
  2451. {
  2452. uint16_t offset;
  2453. uint16_t eeprom_data, i;
  2454. DEBUGFUNC("e1000_read_mac_addr");
  2455. for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
  2456. offset = i >> 1;
  2457. if(e1000_read_eeprom(hw, offset, &eeprom_data) < 0) {
  2458. DEBUGOUT("EEPROM Read Error\n");
  2459. return -E1000_ERR_EEPROM;
  2460. }
  2461. hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
  2462. hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
  2463. }
  2464. if((hw->mac_type == e1000_82546) &&
  2465. (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
  2466. if(hw->perm_mac_addr[5] & 0x01)
  2467. hw->perm_mac_addr[5] &= ~(0x01);
  2468. else
  2469. hw->perm_mac_addr[5] |= 0x01;
  2470. }
  2471. for(i = 0; i < NODE_ADDRESS_SIZE; i++)
  2472. hw->mac_addr[i] = hw->perm_mac_addr[i];
  2473. return 0;
  2474. }
  2475. /******************************************************************************
  2476. * Initializes receive address filters.
  2477. *
  2478. * hw - Struct containing variables accessed by shared code
  2479. *
  2480. * Places the MAC address in receive address register 0 and clears the rest
  2481. * of the receive addresss registers. Clears the multicast table. Assumes
  2482. * the receiver is in reset when the routine is called.
  2483. *****************************************************************************/
  2484. void
  2485. e1000_init_rx_addrs(struct e1000_hw *hw)
  2486. {
  2487. uint32_t i;
  2488. uint32_t addr_low;
  2489. uint32_t addr_high;
  2490. DEBUGFUNC("e1000_init_rx_addrs");
  2491. /* Setup the receive address. */
  2492. DEBUGOUT("Programming MAC Address into RAR[0]\n");
  2493. addr_low = (hw->mac_addr[0] |
  2494. (hw->mac_addr[1] << 8) |
  2495. (hw->mac_addr[2] << 16) | (hw->mac_addr[3] << 24));
  2496. addr_high = (hw->mac_addr[4] |
  2497. (hw->mac_addr[5] << 8) | E1000_RAH_AV);
  2498. E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
  2499. E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
  2500. /* Zero out the other 15 receive addresses. */
  2501. DEBUGOUT("Clearing RAR[1-15]\n");
  2502. for(i = 1; i < E1000_RAR_ENTRIES; i++) {
  2503. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
  2504. E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
  2505. }
  2506. }
  2507. /******************************************************************************
  2508. * Updates the MAC's list of multicast addresses.
  2509. *
  2510. * hw - Struct containing variables accessed by shared code
  2511. * mc_addr_list - the list of new multicast addresses
  2512. * mc_addr_count - number of addresses
  2513. * pad - number of bytes between addresses in the list
  2514. *
  2515. * The given list replaces any existing list. Clears the last 15 receive
  2516. * address registers and the multicast table. Uses receive address registers
  2517. * for the first 15 multicast addresses, and hashes the rest into the
  2518. * multicast table.
  2519. *****************************************************************************/
  2520. void
  2521. e1000_mc_addr_list_update(struct e1000_hw *hw,
  2522. uint8_t *mc_addr_list,
  2523. uint32_t mc_addr_count,
  2524. uint32_t pad)
  2525. {
  2526. uint32_t hash_value;
  2527. uint32_t i;
  2528. uint32_t rar_used_count = 1; /* RAR[0] is used for our MAC address */
  2529. DEBUGFUNC("e1000_mc_addr_list_update");
  2530. /* Set the new number of MC addresses that we are being requested to use. */
  2531. hw->num_mc_addrs = mc_addr_count;
  2532. /* Clear RAR[1-15] */
  2533. DEBUGOUT(" Clearing RAR[1-15]\n");
  2534. for(i = rar_used_count; i < E1000_RAR_ENTRIES; i++) {
  2535. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
  2536. E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
  2537. }
  2538. /* Clear the MTA */
  2539. DEBUGOUT(" Clearing MTA\n");
  2540. for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++) {
  2541. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  2542. }
  2543. /* Add the new addresses */
  2544. for(i = 0; i < mc_addr_count; i++) {
  2545. DEBUGOUT(" Adding the multicast addresses:\n");
  2546. DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
  2547. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
  2548. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
  2549. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
  2550. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
  2551. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
  2552. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
  2553. hash_value = e1000_hash_mc_addr(hw,
  2554. mc_addr_list +
  2555. (i * (ETH_LENGTH_OF_ADDRESS + pad)));
  2556. DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
  2557. /* Place this multicast address in the RAR if there is room, *
  2558. * else put it in the MTA
  2559. */
  2560. if(rar_used_count < E1000_RAR_ENTRIES) {
  2561. e1000_rar_set(hw,
  2562. mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
  2563. rar_used_count);
  2564. rar_used_count++;
  2565. } else {
  2566. e1000_mta_set(hw, hash_value);
  2567. }
  2568. }
  2569. DEBUGOUT("MC Update Complete\n");
  2570. }
  2571. /******************************************************************************
  2572. * Hashes an address to determine its location in the multicast table
  2573. *
  2574. * hw - Struct containing variables accessed by shared code
  2575. * mc_addr - the multicast address to hash
  2576. *****************************************************************************/
  2577. uint32_t
  2578. e1000_hash_mc_addr(struct e1000_hw *hw,
  2579. uint8_t *mc_addr)
  2580. {
  2581. uint32_t hash_value = 0;
  2582. /* The portion of the address that is used for the hash table is
  2583. * determined by the mc_filter_type setting.
  2584. */
  2585. switch (hw->mc_filter_type) {
  2586. /* [0] [1] [2] [3] [4] [5]
  2587. * 01 AA 00 12 34 56
  2588. * LSB MSB
  2589. */
  2590. case 0:
  2591. /* [47:36] i.e. 0x563 for above example address */
  2592. hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
  2593. break;
  2594. case 1:
  2595. /* [46:35] i.e. 0xAC6 for above example address */
  2596. hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
  2597. break;
  2598. case 2:
  2599. /* [45:34] i.e. 0x5D8 for above example address */
  2600. hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
  2601. break;
  2602. case 3:
  2603. /* [43:32] i.e. 0x634 for above example address */
  2604. hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
  2605. break;
  2606. }
  2607. hash_value &= 0xFFF;
  2608. return hash_value;
  2609. }
  2610. /******************************************************************************
  2611. * Sets the bit in the multicast table corresponding to the hash value.
  2612. *
  2613. * hw - Struct containing variables accessed by shared code
  2614. * hash_value - Multicast address hash value
  2615. *****************************************************************************/
  2616. void
  2617. e1000_mta_set(struct e1000_hw *hw,
  2618. uint32_t hash_value)
  2619. {
  2620. uint32_t hash_bit, hash_reg;
  2621. uint32_t mta;
  2622. uint32_t temp;
  2623. /* The MTA is a register array of 128 32-bit registers.
  2624. * It is treated like an array of 4096 bits. We want to set
  2625. * bit BitArray[hash_value]. So we figure out what register
  2626. * the bit is in, read it, OR in the new bit, then write
  2627. * back the new value. The register is determined by the
  2628. * upper 7 bits of the hash value and the bit within that
  2629. * register are determined by the lower 5 bits of the value.
  2630. */
  2631. hash_reg = (hash_value >> 5) & 0x7F;
  2632. hash_bit = hash_value & 0x1F;
  2633. mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
  2634. mta |= (1 << hash_bit);
  2635. /* If we are on an 82544 and we are trying to write an odd offset
  2636. * in the MTA, save off the previous entry before writing and
  2637. * restore the old value after writing.
  2638. */
  2639. if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
  2640. temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
  2641. E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
  2642. E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
  2643. } else {
  2644. E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
  2645. }
  2646. }
  2647. /******************************************************************************
  2648. * Puts an ethernet address into a receive address register.
  2649. *
  2650. * hw - Struct containing variables accessed by shared code
  2651. * addr - Address to put into receive address register
  2652. * index - Receive address register to write
  2653. *****************************************************************************/
  2654. void
  2655. e1000_rar_set(struct e1000_hw *hw,
  2656. uint8_t *addr,
  2657. uint32_t index)
  2658. {
  2659. uint32_t rar_low, rar_high;
  2660. /* HW expects these in little endian so we reverse the byte order
  2661. * from network order (big endian) to little endian
  2662. */
  2663. rar_low = ((uint32_t) addr[0] |
  2664. ((uint32_t) addr[1] << 8) |
  2665. ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
  2666. rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8) | E1000_RAH_AV);
  2667. E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
  2668. E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
  2669. }
  2670. /******************************************************************************
  2671. * Writes a value to the specified offset in the VLAN filter table.
  2672. *
  2673. * hw - Struct containing variables accessed by shared code
  2674. * offset - Offset in VLAN filer table to write
  2675. * value - Value to write into VLAN filter table
  2676. *****************************************************************************/
  2677. void
  2678. e1000_write_vfta(struct e1000_hw *hw,
  2679. uint32_t offset,
  2680. uint32_t value)
  2681. {
  2682. uint32_t temp;
  2683. if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
  2684. temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
  2685. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
  2686. E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
  2687. } else {
  2688. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
  2689. }
  2690. }
  2691. /******************************************************************************
  2692. * Clears the VLAN filer table
  2693. *
  2694. * hw - Struct containing variables accessed by shared code
  2695. *****************************************************************************/
  2696. void
  2697. e1000_clear_vfta(struct e1000_hw *hw)
  2698. {
  2699. uint32_t offset;
  2700. for(offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
  2701. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
  2702. }
  2703. static int32_t
  2704. e1000_id_led_init(struct e1000_hw * hw)
  2705. {
  2706. uint32_t ledctl;
  2707. const uint32_t ledctl_mask = 0x000000FF;
  2708. const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
  2709. const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
  2710. uint16_t eeprom_data, i, temp;
  2711. const uint16_t led_mask = 0x0F;
  2712. DEBUGFUNC("e1000_id_led_init");
  2713. if(hw->mac_type < e1000_82540) {
  2714. /* Nothing to do */
  2715. return 0;
  2716. }
  2717. ledctl = E1000_READ_REG(hw, LEDCTL);
  2718. hw->ledctl_default = ledctl;
  2719. hw->ledctl_mode1 = hw->ledctl_default;
  2720. hw->ledctl_mode2 = hw->ledctl_default;
  2721. if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, &eeprom_data) < 0) {
  2722. DEBUGOUT("EEPROM Read Error\n");
  2723. return -E1000_ERR_EEPROM;
  2724. }
  2725. if((eeprom_data== ID_LED_RESERVED_0000) ||
  2726. (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
  2727. for(i = 0; i < 4; i++) {
  2728. temp = (eeprom_data >> (i << 2)) & led_mask;
  2729. switch(temp) {
  2730. case ID_LED_ON1_DEF2:
  2731. case ID_LED_ON1_ON2:
  2732. case ID_LED_ON1_OFF2:
  2733. hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  2734. hw->ledctl_mode1 |= ledctl_on << (i << 3);
  2735. break;
  2736. case ID_LED_OFF1_DEF2:
  2737. case ID_LED_OFF1_ON2:
  2738. case ID_LED_OFF1_OFF2:
  2739. hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  2740. hw->ledctl_mode1 |= ledctl_off << (i << 3);
  2741. break;
  2742. default:
  2743. /* Do nothing */
  2744. break;
  2745. }
  2746. switch(temp) {
  2747. case ID_LED_DEF1_ON2:
  2748. case ID_LED_ON1_ON2:
  2749. case ID_LED_OFF1_ON2:
  2750. hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  2751. hw->ledctl_mode2 |= ledctl_on << (i << 3);
  2752. break;
  2753. case ID_LED_DEF1_OFF2:
  2754. case ID_LED_ON1_OFF2:
  2755. case ID_LED_OFF1_OFF2:
  2756. hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  2757. hw->ledctl_mode2 |= ledctl_off << (i << 3);
  2758. break;
  2759. default:
  2760. /* Do nothing */
  2761. break;
  2762. }
  2763. }
  2764. return 0;
  2765. }
  2766. /******************************************************************************
  2767. * Prepares SW controlable LED for use and saves the current state of the LED.
  2768. *
  2769. * hw - Struct containing variables accessed by shared code
  2770. *****************************************************************************/
  2771. int32_t
  2772. e1000_setup_led(struct e1000_hw *hw)
  2773. {
  2774. uint32_t ledctl;
  2775. DEBUGFUNC("e1000_setup_led");
  2776. switch(hw->device_id) {
  2777. case E1000_DEV_ID_82542:
  2778. case E1000_DEV_ID_82543GC_FIBER:
  2779. case E1000_DEV_ID_82543GC_COPPER:
  2780. case E1000_DEV_ID_82544EI_COPPER:
  2781. case E1000_DEV_ID_82544EI_FIBER:
  2782. case E1000_DEV_ID_82544GC_COPPER:
  2783. case E1000_DEV_ID_82544GC_LOM:
  2784. /* No setup necessary */
  2785. break;
  2786. case E1000_DEV_ID_82545EM_FIBER:
  2787. case E1000_DEV_ID_82546EB_FIBER:
  2788. ledctl = E1000_READ_REG(hw, LEDCTL);
  2789. /* Save current LEDCTL settings */
  2790. hw->ledctl_default = ledctl;
  2791. /* Turn off LED0 */
  2792. ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
  2793. E1000_LEDCTL_LED0_BLINK |
  2794. E1000_LEDCTL_LED0_MODE_MASK);
  2795. ledctl |= (E1000_LEDCTL_MODE_LED_OFF << E1000_LEDCTL_LED0_MODE_SHIFT);
  2796. E1000_WRITE_REG(hw, LEDCTL, ledctl);
  2797. break;
  2798. case E1000_DEV_ID_82540EM:
  2799. case E1000_DEV_ID_82540EM_LOM:
  2800. case E1000_DEV_ID_82545EM_COPPER:
  2801. case E1000_DEV_ID_82546EB_COPPER:
  2802. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
  2803. break;
  2804. default:
  2805. DEBUGOUT("Invalid device ID\n");
  2806. return -E1000_ERR_CONFIG;
  2807. }
  2808. return 0;
  2809. }
  2810. /******************************************************************************
  2811. * Restores the saved state of the SW controlable LED.
  2812. *
  2813. * hw - Struct containing variables accessed by shared code
  2814. *****************************************************************************/
  2815. int32_t
  2816. e1000_cleanup_led(struct e1000_hw *hw)
  2817. {
  2818. DEBUGFUNC("e1000_cleanup_led");
  2819. switch(hw->device_id) {
  2820. case E1000_DEV_ID_82542:
  2821. case E1000_DEV_ID_82543GC_FIBER:
  2822. case E1000_DEV_ID_82543GC_COPPER:
  2823. case E1000_DEV_ID_82544EI_COPPER:
  2824. case E1000_DEV_ID_82544EI_FIBER:
  2825. case E1000_DEV_ID_82544GC_COPPER:
  2826. case E1000_DEV_ID_82544GC_LOM:
  2827. /* No cleanup necessary */
  2828. break;
  2829. case E1000_DEV_ID_82540EM:
  2830. case E1000_DEV_ID_82540EM_LOM:
  2831. case E1000_DEV_ID_82545EM_COPPER:
  2832. case E1000_DEV_ID_82545EM_FIBER:
  2833. case E1000_DEV_ID_82546EB_COPPER:
  2834. case E1000_DEV_ID_82546EB_FIBER:
  2835. /* Restore LEDCTL settings */
  2836. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
  2837. break;
  2838. default:
  2839. DEBUGOUT("Invalid device ID\n");
  2840. return -E1000_ERR_CONFIG;
  2841. }
  2842. return 0;
  2843. }
  2844. /******************************************************************************
  2845. * Turns on the software controllable LED
  2846. *
  2847. * hw - Struct containing variables accessed by shared code
  2848. *****************************************************************************/
  2849. int32_t
  2850. e1000_led_on(struct e1000_hw *hw)
  2851. {
  2852. uint32_t ctrl;
  2853. DEBUGFUNC("e1000_led_on");
  2854. switch(hw->device_id) {
  2855. case E1000_DEV_ID_82542:
  2856. case E1000_DEV_ID_82543GC_FIBER:
  2857. case E1000_DEV_ID_82543GC_COPPER:
  2858. case E1000_DEV_ID_82544EI_FIBER:
  2859. ctrl = E1000_READ_REG(hw, CTRL);
  2860. /* Set SW Defineable Pin 0 to turn on the LED */
  2861. ctrl |= E1000_CTRL_SWDPIN0;
  2862. ctrl |= E1000_CTRL_SWDPIO0;
  2863. E1000_WRITE_REG(hw, CTRL, ctrl);
  2864. break;
  2865. case E1000_DEV_ID_82544EI_COPPER:
  2866. case E1000_DEV_ID_82544GC_COPPER:
  2867. case E1000_DEV_ID_82544GC_LOM:
  2868. case E1000_DEV_ID_82545EM_FIBER:
  2869. case E1000_DEV_ID_82546EB_FIBER:
  2870. ctrl = E1000_READ_REG(hw, CTRL);
  2871. /* Clear SW Defineable Pin 0 to turn on the LED */
  2872. ctrl &= ~E1000_CTRL_SWDPIN0;
  2873. ctrl |= E1000_CTRL_SWDPIO0;
  2874. E1000_WRITE_REG(hw, CTRL, ctrl);
  2875. break;
  2876. case E1000_DEV_ID_82540EM:
  2877. case E1000_DEV_ID_82540EM_LOM:
  2878. case E1000_DEV_ID_82545EM_COPPER:
  2879. case E1000_DEV_ID_82546EB_COPPER:
  2880. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
  2881. break;
  2882. default:
  2883. DEBUGOUT("Invalid device ID\n");
  2884. return -E1000_ERR_CONFIG;
  2885. }
  2886. return 0;
  2887. }
  2888. /******************************************************************************
  2889. * Turns off the software controllable LED
  2890. *
  2891. * hw - Struct containing variables accessed by shared code
  2892. *****************************************************************************/
  2893. int32_t
  2894. e1000_led_off(struct e1000_hw *hw)
  2895. {
  2896. uint32_t ctrl;
  2897. DEBUGFUNC("e1000_led_off");
  2898. switch(hw->device_id) {
  2899. case E1000_DEV_ID_82542:
  2900. case E1000_DEV_ID_82543GC_FIBER:
  2901. case E1000_DEV_ID_82543GC_COPPER:
  2902. case E1000_DEV_ID_82544EI_FIBER:
  2903. ctrl = E1000_READ_REG(hw, CTRL);
  2904. /* Clear SW Defineable Pin 0 to turn off the LED */
  2905. ctrl &= ~E1000_CTRL_SWDPIN0;
  2906. ctrl |= E1000_CTRL_SWDPIO0;
  2907. E1000_WRITE_REG(hw, CTRL, ctrl);
  2908. break;
  2909. case E1000_DEV_ID_82544EI_COPPER:
  2910. case E1000_DEV_ID_82544GC_COPPER:
  2911. case E1000_DEV_ID_82544GC_LOM:
  2912. case E1000_DEV_ID_82545EM_FIBER:
  2913. case E1000_DEV_ID_82546EB_FIBER:
  2914. ctrl = E1000_READ_REG(hw, CTRL);
  2915. /* Set SW Defineable Pin 0 to turn off the LED */
  2916. ctrl |= E1000_CTRL_SWDPIN0;
  2917. ctrl |= E1000_CTRL_SWDPIO0;
  2918. E1000_WRITE_REG(hw, CTRL, ctrl);
  2919. break;
  2920. case E1000_DEV_ID_82540EM:
  2921. case E1000_DEV_ID_82540EM_LOM:
  2922. case E1000_DEV_ID_82545EM_COPPER:
  2923. case E1000_DEV_ID_82546EB_COPPER:
  2924. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
  2925. break;
  2926. default:
  2927. DEBUGOUT("Invalid device ID\n");
  2928. return -E1000_ERR_CONFIG;
  2929. }
  2930. return 0;
  2931. }
  2932. /******************************************************************************
  2933. * Clears all hardware statistics counters.
  2934. *
  2935. * hw - Struct containing variables accessed by shared code
  2936. *****************************************************************************/
  2937. void
  2938. e1000_clear_hw_cntrs(struct e1000_hw *hw)
  2939. {
  2940. volatile uint32_t temp;
  2941. temp = E1000_READ_REG(hw, CRCERRS);
  2942. temp = E1000_READ_REG(hw, SYMERRS);
  2943. temp = E1000_READ_REG(hw, MPC);
  2944. temp = E1000_READ_REG(hw, SCC);
  2945. temp = E1000_READ_REG(hw, ECOL);
  2946. temp = E1000_READ_REG(hw, MCC);
  2947. temp = E1000_READ_REG(hw, LATECOL);
  2948. temp = E1000_READ_REG(hw, COLC);
  2949. temp = E1000_READ_REG(hw, DC);
  2950. temp = E1000_READ_REG(hw, SEC);
  2951. temp = E1000_READ_REG(hw, RLEC);
  2952. temp = E1000_READ_REG(hw, XONRXC);
  2953. temp = E1000_READ_REG(hw, XONTXC);
  2954. temp = E1000_READ_REG(hw, XOFFRXC);
  2955. temp = E1000_READ_REG(hw, XOFFTXC);
  2956. temp = E1000_READ_REG(hw, FCRUC);
  2957. temp = E1000_READ_REG(hw, PRC64);
  2958. temp = E1000_READ_REG(hw, PRC127);
  2959. temp = E1000_READ_REG(hw, PRC255);
  2960. temp = E1000_READ_REG(hw, PRC511);
  2961. temp = E1000_READ_REG(hw, PRC1023);
  2962. temp = E1000_READ_REG(hw, PRC1522);
  2963. temp = E1000_READ_REG(hw, GPRC);
  2964. temp = E1000_READ_REG(hw, BPRC);
  2965. temp = E1000_READ_REG(hw, MPRC);
  2966. temp = E1000_READ_REG(hw, GPTC);
  2967. temp = E1000_READ_REG(hw, GORCL);
  2968. temp = E1000_READ_REG(hw, GORCH);
  2969. temp = E1000_READ_REG(hw, GOTCL);
  2970. temp = E1000_READ_REG(hw, GOTCH);
  2971. temp = E1000_READ_REG(hw, RNBC);
  2972. temp = E1000_READ_REG(hw, RUC);
  2973. temp = E1000_READ_REG(hw, RFC);
  2974. temp = E1000_READ_REG(hw, ROC);
  2975. temp = E1000_READ_REG(hw, RJC);
  2976. temp = E1000_READ_REG(hw, TORL);
  2977. temp = E1000_READ_REG(hw, TORH);
  2978. temp = E1000_READ_REG(hw, TOTL);
  2979. temp = E1000_READ_REG(hw, TOTH);
  2980. temp = E1000_READ_REG(hw, TPR);
  2981. temp = E1000_READ_REG(hw, TPT);
  2982. temp = E1000_READ_REG(hw, PTC64);
  2983. temp = E1000_READ_REG(hw, PTC127);
  2984. temp = E1000_READ_REG(hw, PTC255);
  2985. temp = E1000_READ_REG(hw, PTC511);
  2986. temp = E1000_READ_REG(hw, PTC1023);
  2987. temp = E1000_READ_REG(hw, PTC1522);
  2988. temp = E1000_READ_REG(hw, MPTC);
  2989. temp = E1000_READ_REG(hw, BPTC);
  2990. if(hw->mac_type < e1000_82543) return;
  2991. temp = E1000_READ_REG(hw, ALGNERRC);
  2992. temp = E1000_READ_REG(hw, RXERRC);
  2993. temp = E1000_READ_REG(hw, TNCRS);
  2994. temp = E1000_READ_REG(hw, CEXTERR);
  2995. temp = E1000_READ_REG(hw, TSCTC);
  2996. temp = E1000_READ_REG(hw, TSCTFC);
  2997. if(hw->mac_type <= e1000_82544) return;
  2998. temp = E1000_READ_REG(hw, MGTPRC);
  2999. temp = E1000_READ_REG(hw, MGTPDC);
  3000. temp = E1000_READ_REG(hw, MGTPTC);
  3001. }
  3002. /******************************************************************************
  3003. * Resets Adaptive IFS to its default state.
  3004. *
  3005. * hw - Struct containing variables accessed by shared code
  3006. *
  3007. * Call this after e1000_init_hw. You may override the IFS defaults by setting
  3008. * hw->ifs_params_forced to TRUE. However, you must initialize hw->
  3009. * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
  3010. * before calling this function.
  3011. *****************************************************************************/
  3012. void
  3013. e1000_reset_adaptive(struct e1000_hw *hw)
  3014. {
  3015. DEBUGFUNC("e1000_reset_adaptive");
  3016. if(hw->adaptive_ifs) {
  3017. if(!hw->ifs_params_forced) {
  3018. hw->current_ifs_val = 0;
  3019. hw->ifs_min_val = IFS_MIN;
  3020. hw->ifs_max_val = IFS_MAX;
  3021. hw->ifs_step_size = IFS_STEP;
  3022. hw->ifs_ratio = IFS_RATIO;
  3023. }
  3024. hw->in_ifs_mode = FALSE;
  3025. E1000_WRITE_REG(hw, AIT, 0);
  3026. } else {
  3027. DEBUGOUT("Not in Adaptive IFS mode!\n");
  3028. }
  3029. }
  3030. /******************************************************************************
  3031. * Called during the callback/watchdog routine to update IFS value based on
  3032. * the ratio of transmits to collisions.
  3033. *
  3034. * hw - Struct containing variables accessed by shared code
  3035. * tx_packets - Number of transmits since last callback
  3036. * total_collisions - Number of collisions since last callback
  3037. *****************************************************************************/
  3038. void
  3039. e1000_update_adaptive(struct e1000_hw *hw)
  3040. {
  3041. DEBUGFUNC("e1000_update_adaptive");
  3042. if(hw->adaptive_ifs) {
  3043. if((hw->collision_delta * hw->ifs_ratio) >
  3044. hw->tx_packet_delta) {
  3045. if(hw->tx_packet_delta > MIN_NUM_XMITS) {
  3046. hw->in_ifs_mode = TRUE;
  3047. if(hw->current_ifs_val < hw->ifs_max_val) {
  3048. if(hw->current_ifs_val == 0)
  3049. hw->current_ifs_val = hw->ifs_min_val;
  3050. else
  3051. hw->current_ifs_val += hw->ifs_step_size;
  3052. E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
  3053. }
  3054. }
  3055. } else {
  3056. if((hw->in_ifs_mode == TRUE) &&
  3057. (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
  3058. hw->current_ifs_val = 0;
  3059. hw->in_ifs_mode = FALSE;
  3060. E1000_WRITE_REG(hw, AIT, 0);
  3061. }
  3062. }
  3063. } else {
  3064. DEBUGOUT("Not in Adaptive IFS mode!\n");
  3065. }
  3066. }
  3067. /******************************************************************************
  3068. * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
  3069. *
  3070. * hw - Struct containing variables accessed by shared code
  3071. * frame_len - The length of the frame in question
  3072. * mac_addr - The Ethernet destination address of the frame in question
  3073. *****************************************************************************/
  3074. void
  3075. e1000_tbi_adjust_stats(struct e1000_hw *hw,
  3076. struct e1000_hw_stats *stats,
  3077. uint32_t frame_len,
  3078. uint8_t *mac_addr)
  3079. {
  3080. uint64_t carry_bit;
  3081. /* First adjust the frame length. */
  3082. frame_len--;
  3083. /* We need to adjust the statistics counters, since the hardware
  3084. * counters overcount this packet as a CRC error and undercount
  3085. * the packet as a good packet
  3086. */
  3087. /* This packet should not be counted as a CRC error. */
  3088. stats->crcerrs--;
  3089. /* This packet does count as a Good Packet Received. */
  3090. stats->gprc++;
  3091. /* Adjust the Good Octets received counters */
  3092. carry_bit = 0x80000000 & stats->gorcl;
  3093. stats->gorcl += frame_len;
  3094. /* If the high bit of Gorcl (the low 32 bits of the Good Octets
  3095. * Received Count) was one before the addition,
  3096. * AND it is zero after, then we lost the carry out,
  3097. * need to add one to Gorch (Good Octets Received Count High).
  3098. * This could be simplified if all environments supported
  3099. * 64-bit integers.
  3100. */
  3101. if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
  3102. stats->gorch++;
  3103. /* Is this a broadcast or multicast? Check broadcast first,
  3104. * since the test for a multicast frame will test positive on
  3105. * a broadcast frame.
  3106. */
  3107. if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
  3108. /* Broadcast packet */
  3109. stats->bprc++;
  3110. else if(*mac_addr & 0x01)
  3111. /* Multicast packet */
  3112. stats->mprc++;
  3113. if(frame_len == hw->max_frame_size) {
  3114. /* In this case, the hardware has overcounted the number of
  3115. * oversize frames.
  3116. */
  3117. if(stats->roc > 0)
  3118. stats->roc--;
  3119. }
  3120. /* Adjust the bin counters when the extra byte put the frame in the
  3121. * wrong bin. Remember that the frame_len was adjusted above.
  3122. */
  3123. if(frame_len == 64) {
  3124. stats->prc64++;
  3125. stats->prc127--;
  3126. } else if(frame_len == 127) {
  3127. stats->prc127++;
  3128. stats->prc255--;
  3129. } else if(frame_len == 255) {
  3130. stats->prc255++;
  3131. stats->prc511--;
  3132. } else if(frame_len == 511) {
  3133. stats->prc511++;
  3134. stats->prc1023--;
  3135. } else if(frame_len == 1023) {
  3136. stats->prc1023++;
  3137. stats->prc1522--;
  3138. } else if(frame_len == 1522) {
  3139. stats->prc1522++;
  3140. }
  3141. }
  3142. /******************************************************************************
  3143. * Gets the current PCI bus type, speed, and width of the hardware
  3144. *
  3145. * hw - Struct containing variables accessed by shared code
  3146. *****************************************************************************/
  3147. void
  3148. e1000_get_bus_info(struct e1000_hw *hw)
  3149. {
  3150. uint32_t status;
  3151. if(hw->mac_type < e1000_82543) {
  3152. hw->bus_type = e1000_bus_type_unknown;
  3153. hw->bus_speed = e1000_bus_speed_unknown;
  3154. hw->bus_width = e1000_bus_width_unknown;
  3155. return;
  3156. }
  3157. status = E1000_READ_REG(hw, STATUS);
  3158. hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
  3159. e1000_bus_type_pcix : e1000_bus_type_pci;
  3160. if(hw->bus_type == e1000_bus_type_pci) {
  3161. hw->bus_speed = (status & E1000_STATUS_PCI66) ?
  3162. e1000_bus_speed_66 : e1000_bus_speed_33;
  3163. } else {
  3164. switch (status & E1000_STATUS_PCIX_SPEED) {
  3165. case E1000_STATUS_PCIX_SPEED_66:
  3166. hw->bus_speed = e1000_bus_speed_66;
  3167. break;
  3168. case E1000_STATUS_PCIX_SPEED_100:
  3169. hw->bus_speed = e1000_bus_speed_100;
  3170. break;
  3171. case E1000_STATUS_PCIX_SPEED_133:
  3172. hw->bus_speed = e1000_bus_speed_133;
  3173. break;
  3174. default:
  3175. hw->bus_speed = e1000_bus_speed_reserved;
  3176. break;
  3177. }
  3178. }
  3179. hw->bus_width = (status & E1000_STATUS_BUS64) ?
  3180. e1000_bus_width_64 : e1000_bus_width_32;
  3181. }
  3182. /******************************************************************************
  3183. * Reads a value from one of the devices registers using port I/O (as opposed
  3184. * memory mapped I/O). Only 82544 and newer devices support port I/O.
  3185. *
  3186. * hw - Struct containing variables accessed by shared code
  3187. * offset - offset to read from
  3188. *****************************************************************************/
  3189. uint32_t
  3190. e1000_read_reg_io(struct e1000_hw *hw,
  3191. uint32_t offset)
  3192. {
  3193. uint32_t io_addr = hw->io_base;
  3194. uint32_t io_data = hw->io_base + 4;
  3195. e1000_io_write(hw, io_addr, offset);
  3196. return e1000_io_read(hw, io_data);
  3197. }
  3198. /******************************************************************************
  3199. * Writes a value to one of the devices registers using port I/O (as opposed to
  3200. * memory mapped I/O). Only 82544 and newer devices support port I/O.
  3201. *
  3202. * hw - Struct containing variables accessed by shared code
  3203. * offset - offset to write to
  3204. * value - value to write
  3205. *****************************************************************************/
  3206. void
  3207. e1000_write_reg_io(struct e1000_hw *hw,
  3208. uint32_t offset,
  3209. uint32_t value)
  3210. {
  3211. uint32_t io_addr = hw->io_base;
  3212. uint32_t io_data = hw->io_base + 4;
  3213. e1000_io_write(hw, io_addr, offset);
  3214. e1000_io_write(hw, io_data, value);
  3215. }