ab@2201: /******************************************************************************* ab@2201: ab@2201: Intel PRO/1000 Linux driver ab@2201: Copyright(c) 1999 - 2006 Intel Corporation. ab@2201: ab@2201: This program is free software; you can redistribute it and/or modify it ab@2201: under the terms and conditions of the GNU General Public License, ab@2201: version 2, as published by the Free Software Foundation. ab@2201: ab@2201: This program is distributed in the hope it will be useful, but WITHOUT ab@2201: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ab@2201: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for ab@2201: more details. ab@2201: ab@2201: You should have received a copy of the GNU General Public License along with ab@2201: this program; if not, write to the Free Software Foundation, Inc., ab@2201: 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. ab@2201: ab@2201: The full GNU General Public License is included in this distribution in ab@2201: the file called "COPYING". ab@2201: ab@2201: Contact Information: ab@2201: Linux NICS ab@2201: e1000-devel Mailing List ab@2201: Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 ab@2201: ab@2201: */ ab@2201: ab@2201: /* e1000_hw.c ab@2201: * Shared functions for accessing and configuring the MAC ab@2201: */ ab@2201: ab@2201: #include "e1000_hw.h" ab@2201: ab@2201: static s32 e1000_check_downshift(struct e1000_hw *hw); ab@2201: static s32 e1000_check_polarity(struct e1000_hw *hw, ab@2201: e1000_rev_polarity *polarity); ab@2201: static void e1000_clear_hw_cntrs(struct e1000_hw *hw); ab@2201: static void e1000_clear_vfta(struct e1000_hw *hw); ab@2201: static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, ab@2201: bool link_up); ab@2201: static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw); ab@2201: static s32 e1000_detect_gig_phy(struct e1000_hw *hw); ab@2201: static s32 e1000_get_auto_rd_done(struct e1000_hw *hw); ab@2201: static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length, ab@2201: u16 *max_length); ab@2201: static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw); ab@2201: static s32 e1000_id_led_init(struct e1000_hw *hw); ab@2201: static void e1000_init_rx_addrs(struct e1000_hw *hw); ab@2201: static s32 e1000_phy_igp_get_info(struct e1000_hw *hw, ab@2201: struct e1000_phy_info *phy_info); ab@2201: static s32 e1000_phy_m88_get_info(struct e1000_hw *hw, ab@2201: struct e1000_phy_info *phy_info); ab@2201: static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active); ab@2201: static s32 e1000_wait_autoneg(struct e1000_hw *hw); ab@2201: static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value); ab@2201: static s32 e1000_set_phy_type(struct e1000_hw *hw); ab@2201: static void e1000_phy_init_script(struct e1000_hw *hw); ab@2201: static s32 e1000_setup_copper_link(struct e1000_hw *hw); ab@2201: static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw); ab@2201: static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw); ab@2201: static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw); ab@2201: static s32 e1000_config_mac_to_phy(struct e1000_hw *hw); ab@2201: static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl); ab@2201: static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl); ab@2201: static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count); ab@2201: static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw); ab@2201: static s32 e1000_phy_reset_dsp(struct e1000_hw *hw); ab@2201: static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, ab@2201: u16 words, u16 *data); ab@2201: static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset, ab@2201: u16 words, u16 *data); ab@2201: static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw); ab@2201: static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd); ab@2201: static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd); ab@2201: static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count); ab@2201: static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, ab@2201: u16 phy_data); ab@2201: static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, ab@2201: u16 *phy_data); ab@2201: static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count); ab@2201: static s32 e1000_acquire_eeprom(struct e1000_hw *hw); ab@2201: static void e1000_release_eeprom(struct e1000_hw *hw); ab@2201: static void e1000_standby_eeprom(struct e1000_hw *hw); ab@2201: static s32 e1000_set_vco_speed(struct e1000_hw *hw); ab@2201: static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw); ab@2201: static s32 e1000_set_phy_mode(struct e1000_hw *hw); ab@2201: static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, ab@2201: u16 *data); ab@2201: static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, ab@2201: u16 *data); ab@2201: ab@2201: /* IGP cable length table */ ab@2201: static const ab@2201: u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = { ab@2201: 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, ab@2201: 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25, ab@2201: 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40, ab@2201: 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, ab@2201: 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90, ab@2201: 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, ab@2201: 100, ab@2201: 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, ab@2201: 110, 110, ab@2201: 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, ab@2201: 120, 120 ab@2201: }; ab@2201: ab@2201: static DEFINE_SPINLOCK(e1000_eeprom_lock); ab@2201: ab@2201: /** ab@2201: * e1000_set_phy_type - Set the phy type member in the hw struct. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: */ ab@2201: static s32 e1000_set_phy_type(struct e1000_hw *hw) ab@2201: { ab@2201: DEBUGFUNC("e1000_set_phy_type"); ab@2201: ab@2201: if (hw->mac_type == e1000_undefined) ab@2201: return -E1000_ERR_PHY_TYPE; ab@2201: ab@2201: switch (hw->phy_id) { ab@2201: case M88E1000_E_PHY_ID: ab@2201: case M88E1000_I_PHY_ID: ab@2201: case M88E1011_I_PHY_ID: ab@2201: case M88E1111_I_PHY_ID: ab@2201: hw->phy_type = e1000_phy_m88; ab@2201: break; ab@2201: case IGP01E1000_I_PHY_ID: ab@2201: if (hw->mac_type == e1000_82541 || ab@2201: hw->mac_type == e1000_82541_rev_2 || ab@2201: hw->mac_type == e1000_82547 || ab@2201: hw->mac_type == e1000_82547_rev_2) { ab@2201: hw->phy_type = e1000_phy_igp; ab@2201: break; ab@2201: } ab@2201: default: ab@2201: /* Should never have loaded on this device */ ab@2201: hw->phy_type = e1000_phy_undefined; ab@2201: return -E1000_ERR_PHY_TYPE; ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_phy_init_script - IGP phy init script - initializes the GbE PHY ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: */ ab@2201: static void e1000_phy_init_script(struct e1000_hw *hw) ab@2201: { ab@2201: u32 ret_val; ab@2201: u16 phy_saved_data; ab@2201: ab@2201: DEBUGFUNC("e1000_phy_init_script"); ab@2201: ab@2201: if (hw->phy_init_script) { ab@2201: msleep(20); ab@2201: ab@2201: /* Save off the current value of register 0x2F5B to be restored at ab@2201: * the end of this routine. */ ab@2201: ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); ab@2201: ab@2201: /* Disabled the PHY transmitter */ ab@2201: e1000_write_phy_reg(hw, 0x2F5B, 0x0003); ab@2201: msleep(20); ab@2201: ab@2201: e1000_write_phy_reg(hw, 0x0000, 0x0140); ab@2201: msleep(5); ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82541: ab@2201: case e1000_82547: ab@2201: e1000_write_phy_reg(hw, 0x1F95, 0x0001); ab@2201: e1000_write_phy_reg(hw, 0x1F71, 0xBD21); ab@2201: e1000_write_phy_reg(hw, 0x1F79, 0x0018); ab@2201: e1000_write_phy_reg(hw, 0x1F30, 0x1600); ab@2201: e1000_write_phy_reg(hw, 0x1F31, 0x0014); ab@2201: e1000_write_phy_reg(hw, 0x1F32, 0x161C); ab@2201: e1000_write_phy_reg(hw, 0x1F94, 0x0003); ab@2201: e1000_write_phy_reg(hw, 0x1F96, 0x003F); ab@2201: e1000_write_phy_reg(hw, 0x2010, 0x0008); ab@2201: break; ab@2201: ab@2201: case e1000_82541_rev_2: ab@2201: case e1000_82547_rev_2: ab@2201: e1000_write_phy_reg(hw, 0x1F73, 0x0099); ab@2201: break; ab@2201: default: ab@2201: break; ab@2201: } ab@2201: ab@2201: e1000_write_phy_reg(hw, 0x0000, 0x3300); ab@2201: msleep(20); ab@2201: ab@2201: /* Now enable the transmitter */ ab@2201: e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); ab@2201: ab@2201: if (hw->mac_type == e1000_82547) { ab@2201: u16 fused, fine, coarse; ab@2201: ab@2201: /* Move to analog registers page */ ab@2201: e1000_read_phy_reg(hw, ab@2201: IGP01E1000_ANALOG_SPARE_FUSE_STATUS, ab@2201: &fused); ab@2201: ab@2201: if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) { ab@2201: e1000_read_phy_reg(hw, ab@2201: IGP01E1000_ANALOG_FUSE_STATUS, ab@2201: &fused); ab@2201: ab@2201: fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK; ab@2201: coarse = ab@2201: fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK; ab@2201: ab@2201: if (coarse > ab@2201: IGP01E1000_ANALOG_FUSE_COARSE_THRESH) { ab@2201: coarse -= ab@2201: IGP01E1000_ANALOG_FUSE_COARSE_10; ab@2201: fine -= IGP01E1000_ANALOG_FUSE_FINE_1; ab@2201: } else if (coarse == ab@2201: IGP01E1000_ANALOG_FUSE_COARSE_THRESH) ab@2201: fine -= IGP01E1000_ANALOG_FUSE_FINE_10; ab@2201: ab@2201: fused = ab@2201: (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) | ab@2201: (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) | ab@2201: (coarse & ab@2201: IGP01E1000_ANALOG_FUSE_COARSE_MASK); ab@2201: ab@2201: e1000_write_phy_reg(hw, ab@2201: IGP01E1000_ANALOG_FUSE_CONTROL, ab@2201: fused); ab@2201: e1000_write_phy_reg(hw, ab@2201: IGP01E1000_ANALOG_FUSE_BYPASS, ab@2201: IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL); ab@2201: } ab@2201: } ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_set_mac_type - Set the mac type member in the hw struct. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: */ ab@2201: s32 e1000_set_mac_type(struct e1000_hw *hw) ab@2201: { ab@2201: DEBUGFUNC("e1000_set_mac_type"); ab@2201: ab@2201: switch (hw->device_id) { ab@2201: case E1000_DEV_ID_82542: ab@2201: switch (hw->revision_id) { ab@2201: case E1000_82542_2_0_REV_ID: ab@2201: hw->mac_type = e1000_82542_rev2_0; ab@2201: break; ab@2201: case E1000_82542_2_1_REV_ID: ab@2201: hw->mac_type = e1000_82542_rev2_1; ab@2201: break; ab@2201: default: ab@2201: /* Invalid 82542 revision ID */ ab@2201: return -E1000_ERR_MAC_TYPE; ab@2201: } ab@2201: break; ab@2201: case E1000_DEV_ID_82543GC_FIBER: ab@2201: case E1000_DEV_ID_82543GC_COPPER: ab@2201: hw->mac_type = e1000_82543; ab@2201: break; ab@2201: case E1000_DEV_ID_82544EI_COPPER: ab@2201: case E1000_DEV_ID_82544EI_FIBER: ab@2201: case E1000_DEV_ID_82544GC_COPPER: ab@2201: case E1000_DEV_ID_82544GC_LOM: ab@2201: hw->mac_type = e1000_82544; ab@2201: break; ab@2201: case E1000_DEV_ID_82540EM: ab@2201: case E1000_DEV_ID_82540EM_LOM: ab@2201: case E1000_DEV_ID_82540EP: ab@2201: case E1000_DEV_ID_82540EP_LOM: ab@2201: case E1000_DEV_ID_82540EP_LP: ab@2201: hw->mac_type = e1000_82540; ab@2201: break; ab@2201: case E1000_DEV_ID_82545EM_COPPER: ab@2201: case E1000_DEV_ID_82545EM_FIBER: ab@2201: hw->mac_type = e1000_82545; ab@2201: break; ab@2201: case E1000_DEV_ID_82545GM_COPPER: ab@2201: case E1000_DEV_ID_82545GM_FIBER: ab@2201: case E1000_DEV_ID_82545GM_SERDES: ab@2201: hw->mac_type = e1000_82545_rev_3; ab@2201: break; ab@2201: case E1000_DEV_ID_82546EB_COPPER: ab@2201: case E1000_DEV_ID_82546EB_FIBER: ab@2201: case E1000_DEV_ID_82546EB_QUAD_COPPER: ab@2201: hw->mac_type = e1000_82546; ab@2201: break; ab@2201: case E1000_DEV_ID_82546GB_COPPER: ab@2201: case E1000_DEV_ID_82546GB_FIBER: ab@2201: case E1000_DEV_ID_82546GB_SERDES: ab@2201: case E1000_DEV_ID_82546GB_PCIE: ab@2201: case E1000_DEV_ID_82546GB_QUAD_COPPER: ab@2201: case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: ab@2201: hw->mac_type = e1000_82546_rev_3; ab@2201: break; ab@2201: case E1000_DEV_ID_82541EI: ab@2201: case E1000_DEV_ID_82541EI_MOBILE: ab@2201: case E1000_DEV_ID_82541ER_LOM: ab@2201: hw->mac_type = e1000_82541; ab@2201: break; ab@2201: case E1000_DEV_ID_82541ER: ab@2201: case E1000_DEV_ID_82541GI: ab@2201: case E1000_DEV_ID_82541GI_LF: ab@2201: case E1000_DEV_ID_82541GI_MOBILE: ab@2201: hw->mac_type = e1000_82541_rev_2; ab@2201: break; ab@2201: case E1000_DEV_ID_82547EI: ab@2201: case E1000_DEV_ID_82547EI_MOBILE: ab@2201: hw->mac_type = e1000_82547; ab@2201: break; ab@2201: case E1000_DEV_ID_82547GI: ab@2201: hw->mac_type = e1000_82547_rev_2; ab@2201: break; ab@2201: default: ab@2201: /* Should never have loaded on this device */ ab@2201: return -E1000_ERR_MAC_TYPE; ab@2201: } ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82541: ab@2201: case e1000_82547: ab@2201: case e1000_82541_rev_2: ab@2201: case e1000_82547_rev_2: ab@2201: hw->asf_firmware_present = true; ab@2201: break; ab@2201: default: ab@2201: break; ab@2201: } ab@2201: ab@2201: /* The 82543 chip does not count tx_carrier_errors properly in ab@2201: * FD mode ab@2201: */ ab@2201: if (hw->mac_type == e1000_82543) ab@2201: hw->bad_tx_carr_stats_fd = true; ab@2201: ab@2201: if (hw->mac_type > e1000_82544) ab@2201: hw->has_smbus = true; ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_set_media_type - Set media type and TBI compatibility. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: */ ab@2201: void e1000_set_media_type(struct e1000_hw *hw) ab@2201: { ab@2201: u32 status; ab@2201: ab@2201: DEBUGFUNC("e1000_set_media_type"); ab@2201: ab@2201: if (hw->mac_type != e1000_82543) { ab@2201: /* tbi_compatibility is only valid on 82543 */ ab@2201: hw->tbi_compatibility_en = false; ab@2201: } ab@2201: ab@2201: switch (hw->device_id) { ab@2201: case E1000_DEV_ID_82545GM_SERDES: ab@2201: case E1000_DEV_ID_82546GB_SERDES: ab@2201: hw->media_type = e1000_media_type_internal_serdes; ab@2201: break; ab@2201: default: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82542_rev2_0: ab@2201: case e1000_82542_rev2_1: ab@2201: hw->media_type = e1000_media_type_fiber; ab@2201: break; ab@2201: default: ab@2201: status = er32(STATUS); ab@2201: if (status & E1000_STATUS_TBIMODE) { ab@2201: hw->media_type = e1000_media_type_fiber; ab@2201: /* tbi_compatibility not valid on fiber */ ab@2201: hw->tbi_compatibility_en = false; ab@2201: } else { ab@2201: hw->media_type = e1000_media_type_copper; ab@2201: } ab@2201: break; ab@2201: } ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_reset_hw: reset the hardware completely ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Reset the transmit and receive units; mask and clear all interrupts. ab@2201: */ ab@2201: s32 e1000_reset_hw(struct e1000_hw *hw) ab@2201: { ab@2201: u32 ctrl; ab@2201: u32 ctrl_ext; ab@2201: u32 icr; ab@2201: u32 manc; ab@2201: u32 led_ctrl; ab@2201: s32 ret_val; ab@2201: ab@2201: DEBUGFUNC("e1000_reset_hw"); ab@2201: ab@2201: /* For 82542 (rev 2.0), disable MWI before issuing a device reset */ ab@2201: if (hw->mac_type == e1000_82542_rev2_0) { ab@2201: DEBUGOUT("Disabling MWI on 82542 rev 2.0\n"); ab@2201: e1000_pci_clear_mwi(hw); ab@2201: } ab@2201: ab@2201: /* Clear interrupt mask to stop board from generating interrupts */ ab@2201: DEBUGOUT("Masking off all interrupts\n"); ab@2201: ew32(IMC, 0xffffffff); ab@2201: ab@2201: /* Disable the Transmit and Receive units. Then delay to allow ab@2201: * any pending transactions to complete before we hit the MAC with ab@2201: * the global reset. ab@2201: */ ab@2201: ew32(RCTL, 0); ab@2201: ew32(TCTL, E1000_TCTL_PSP); ab@2201: E1000_WRITE_FLUSH(); ab@2201: ab@2201: /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */ ab@2201: hw->tbi_compatibility_on = false; ab@2201: ab@2201: /* Delay to allow any outstanding PCI transactions to complete before ab@2201: * resetting the device ab@2201: */ ab@2201: msleep(10); ab@2201: ab@2201: ctrl = er32(CTRL); ab@2201: ab@2201: /* Must reset the PHY before resetting the MAC */ ab@2201: if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { ab@2201: ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST)); ab@2201: msleep(5); ab@2201: } ab@2201: ab@2201: /* Issue a global reset to the MAC. This will reset the chip's ab@2201: * transmit, receive, DMA, and link units. It will not effect ab@2201: * the current PCI configuration. The global reset bit is self- ab@2201: * clearing, and should clear within a microsecond. ab@2201: */ ab@2201: DEBUGOUT("Issuing a global reset to MAC\n"); ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82544: ab@2201: case e1000_82540: ab@2201: case e1000_82545: ab@2201: case e1000_82546: ab@2201: case e1000_82541: ab@2201: case e1000_82541_rev_2: ab@2201: /* These controllers can't ack the 64-bit write when issuing the ab@2201: * reset, so use IO-mapping as a workaround to issue the reset */ ab@2201: E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST)); ab@2201: break; ab@2201: case e1000_82545_rev_3: ab@2201: case e1000_82546_rev_3: ab@2201: /* Reset is performed on a shadow of the control register */ ab@2201: ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST)); ab@2201: break; ab@2201: default: ab@2201: ew32(CTRL, (ctrl | E1000_CTRL_RST)); ab@2201: break; ab@2201: } ab@2201: ab@2201: /* After MAC reset, force reload of EEPROM to restore power-on settings to ab@2201: * device. Later controllers reload the EEPROM automatically, so just wait ab@2201: * for reload to complete. ab@2201: */ ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82542_rev2_0: ab@2201: case e1000_82542_rev2_1: ab@2201: case e1000_82543: ab@2201: case e1000_82544: ab@2201: /* Wait for reset to complete */ ab@2201: udelay(10); ab@2201: ctrl_ext = er32(CTRL_EXT); ab@2201: ctrl_ext |= E1000_CTRL_EXT_EE_RST; ab@2201: ew32(CTRL_EXT, ctrl_ext); ab@2201: E1000_WRITE_FLUSH(); ab@2201: /* Wait for EEPROM reload */ ab@2201: msleep(2); ab@2201: break; ab@2201: case e1000_82541: ab@2201: case e1000_82541_rev_2: ab@2201: case e1000_82547: ab@2201: case e1000_82547_rev_2: ab@2201: /* Wait for EEPROM reload */ ab@2201: msleep(20); ab@2201: break; ab@2201: default: ab@2201: /* Auto read done will delay 5ms or poll based on mac type */ ab@2201: ret_val = e1000_get_auto_rd_done(hw); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: break; ab@2201: } ab@2201: ab@2201: /* Disable HW ARPs on ASF enabled adapters */ ab@2201: if (hw->mac_type >= e1000_82540) { ab@2201: manc = er32(MANC); ab@2201: manc &= ~(E1000_MANC_ARP_EN); ab@2201: ew32(MANC, manc); ab@2201: } ab@2201: ab@2201: if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { ab@2201: e1000_phy_init_script(hw); ab@2201: ab@2201: /* Configure activity LED after PHY reset */ ab@2201: led_ctrl = er32(LEDCTL); ab@2201: led_ctrl &= IGP_ACTIVITY_LED_MASK; ab@2201: led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); ab@2201: ew32(LEDCTL, led_ctrl); ab@2201: } ab@2201: ab@2201: /* Clear interrupt mask to stop board from generating interrupts */ ab@2201: DEBUGOUT("Masking off all interrupts\n"); ab@2201: ew32(IMC, 0xffffffff); ab@2201: ab@2201: /* Clear any pending interrupt events. */ ab@2201: icr = er32(ICR); ab@2201: ab@2201: /* If MWI was previously enabled, reenable it. */ ab@2201: if (hw->mac_type == e1000_82542_rev2_0) { ab@2201: if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) ab@2201: e1000_pci_set_mwi(hw); ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_init_hw: Performs basic configuration of the adapter. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Assumes that the controller has previously been reset and is in a ab@2201: * post-reset uninitialized state. Initializes the receive address registers, ab@2201: * multicast table, and VLAN filter table. Calls routines to setup link ab@2201: * configuration and flow control settings. Clears all on-chip counters. Leaves ab@2201: * the transmit and receive units disabled and uninitialized. ab@2201: */ ab@2201: s32 e1000_init_hw(struct e1000_hw *hw) ab@2201: { ab@2201: u32 ctrl; ab@2201: u32 i; ab@2201: s32 ret_val; ab@2201: u32 mta_size; ab@2201: u32 ctrl_ext; ab@2201: ab@2201: DEBUGFUNC("e1000_init_hw"); ab@2201: ab@2201: /* Initialize Identification LED */ ab@2201: ret_val = e1000_id_led_init(hw); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("Error Initializing Identification LED\n"); ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: /* Set the media type and TBI compatibility */ ab@2201: e1000_set_media_type(hw); ab@2201: ab@2201: /* Disabling VLAN filtering. */ ab@2201: DEBUGOUT("Initializing the IEEE VLAN\n"); ab@2201: if (hw->mac_type < e1000_82545_rev_3) ab@2201: ew32(VET, 0); ab@2201: e1000_clear_vfta(hw); ab@2201: ab@2201: /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */ ab@2201: if (hw->mac_type == e1000_82542_rev2_0) { ab@2201: DEBUGOUT("Disabling MWI on 82542 rev 2.0\n"); ab@2201: e1000_pci_clear_mwi(hw); ab@2201: ew32(RCTL, E1000_RCTL_RST); ab@2201: E1000_WRITE_FLUSH(); ab@2201: msleep(5); ab@2201: } ab@2201: ab@2201: /* Setup the receive address. This involves initializing all of the Receive ab@2201: * Address Registers (RARs 0 - 15). ab@2201: */ ab@2201: e1000_init_rx_addrs(hw); ab@2201: ab@2201: /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */ ab@2201: if (hw->mac_type == e1000_82542_rev2_0) { ab@2201: ew32(RCTL, 0); ab@2201: E1000_WRITE_FLUSH(); ab@2201: msleep(1); ab@2201: if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) ab@2201: e1000_pci_set_mwi(hw); ab@2201: } ab@2201: ab@2201: /* Zero out the Multicast HASH table */ ab@2201: DEBUGOUT("Zeroing the MTA\n"); ab@2201: mta_size = E1000_MC_TBL_SIZE; ab@2201: for (i = 0; i < mta_size; i++) { ab@2201: E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); ab@2201: /* use write flush to prevent Memory Write Block (MWB) from ab@2201: * occurring when accessing our register space */ ab@2201: E1000_WRITE_FLUSH(); ab@2201: } ab@2201: ab@2201: /* Set the PCI priority bit correctly in the CTRL register. This ab@2201: * determines if the adapter gives priority to receives, or if it ab@2201: * gives equal priority to transmits and receives. Valid only on ab@2201: * 82542 and 82543 silicon. ab@2201: */ ab@2201: if (hw->dma_fairness && hw->mac_type <= e1000_82543) { ab@2201: ctrl = er32(CTRL); ab@2201: ew32(CTRL, ctrl | E1000_CTRL_PRIOR); ab@2201: } ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82545_rev_3: ab@2201: case e1000_82546_rev_3: ab@2201: break; ab@2201: default: ab@2201: /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */ ab@2201: if (hw->bus_type == e1000_bus_type_pcix ab@2201: && e1000_pcix_get_mmrbc(hw) > 2048) ab@2201: e1000_pcix_set_mmrbc(hw, 2048); ab@2201: break; ab@2201: } ab@2201: ab@2201: /* Call a subroutine to configure the link and setup flow control. */ ab@2201: ret_val = e1000_setup_link(hw); ab@2201: ab@2201: /* Set the transmit descriptor write-back policy */ ab@2201: if (hw->mac_type > e1000_82544) { ab@2201: ctrl = er32(TXDCTL); ab@2201: ctrl = ab@2201: (ctrl & ~E1000_TXDCTL_WTHRESH) | ab@2201: E1000_TXDCTL_FULL_TX_DESC_WB; ab@2201: ew32(TXDCTL, ctrl); ab@2201: } ab@2201: ab@2201: /* Clear all of the statistics registers (clear on read). It is ab@2201: * important that we do this after we have tried to establish link ab@2201: * because the symbol error count will increment wildly if there ab@2201: * is no link. ab@2201: */ ab@2201: e1000_clear_hw_cntrs(hw); ab@2201: ab@2201: if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER || ab@2201: hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) { ab@2201: ctrl_ext = er32(CTRL_EXT); ab@2201: /* Relaxed ordering must be disabled to avoid a parity ab@2201: * error crash in a PCI slot. */ ab@2201: ctrl_ext |= E1000_CTRL_EXT_RO_DIS; ab@2201: ew32(CTRL_EXT, ctrl_ext); ab@2201: } ab@2201: ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_adjust_serdes_amplitude - Adjust SERDES output amplitude based on EEPROM setting. ab@2201: * @hw: Struct containing variables accessed by shared code. ab@2201: */ ab@2201: static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw) ab@2201: { ab@2201: u16 eeprom_data; ab@2201: s32 ret_val; ab@2201: ab@2201: DEBUGFUNC("e1000_adjust_serdes_amplitude"); ab@2201: ab@2201: if (hw->media_type != e1000_media_type_internal_serdes) ab@2201: return E1000_SUCCESS; ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82545_rev_3: ab@2201: case e1000_82546_rev_3: ab@2201: break; ab@2201: default: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, ab@2201: &eeprom_data); ab@2201: if (ret_val) { ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: if (eeprom_data != EEPROM_RESERVED_WORD) { ab@2201: /* Adjust SERDES output amplitude only. */ ab@2201: eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK; ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_setup_link - Configures flow control and link settings. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Determines which flow control settings to use. Calls the appropriate media- ab@2201: * specific link configuration function. Configures the flow control settings. ab@2201: * Assuming the adapter has a valid link partner, a valid link should be ab@2201: * established. Assumes the hardware has previously been reset and the ab@2201: * transmitter and receiver are not enabled. ab@2201: */ ab@2201: s32 e1000_setup_link(struct e1000_hw *hw) ab@2201: { ab@2201: u32 ctrl_ext; ab@2201: s32 ret_val; ab@2201: u16 eeprom_data; ab@2201: ab@2201: DEBUGFUNC("e1000_setup_link"); ab@2201: ab@2201: /* Read and store word 0x0F of the EEPROM. This word contains bits ab@2201: * that determine the hardware's default PAUSE (flow control) mode, ab@2201: * a bit that determines whether the HW defaults to enabling or ab@2201: * disabling auto-negotiation, and the direction of the ab@2201: * SW defined pins. If there is no SW over-ride of the flow ab@2201: * control setting, then the variable hw->fc will ab@2201: * be initialized based on a value in the EEPROM. ab@2201: */ ab@2201: if (hw->fc == E1000_FC_DEFAULT) { ab@2201: ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, ab@2201: 1, &eeprom_data); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("EEPROM Read Error\n"); ab@2201: return -E1000_ERR_EEPROM; ab@2201: } ab@2201: if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0) ab@2201: hw->fc = E1000_FC_NONE; ab@2201: else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == ab@2201: EEPROM_WORD0F_ASM_DIR) ab@2201: hw->fc = E1000_FC_TX_PAUSE; ab@2201: else ab@2201: hw->fc = E1000_FC_FULL; ab@2201: } ab@2201: ab@2201: /* We want to save off the original Flow Control configuration just ab@2201: * in case we get disconnected and then reconnected into a different ab@2201: * hub or switch with different Flow Control capabilities. ab@2201: */ ab@2201: if (hw->mac_type == e1000_82542_rev2_0) ab@2201: hw->fc &= (~E1000_FC_TX_PAUSE); ab@2201: ab@2201: if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1)) ab@2201: hw->fc &= (~E1000_FC_RX_PAUSE); ab@2201: ab@2201: hw->original_fc = hw->fc; ab@2201: ab@2201: DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc); ab@2201: ab@2201: /* Take the 4 bits from EEPROM word 0x0F that determine the initial ab@2201: * polarity value for the SW controlled pins, and setup the ab@2201: * Extended Device Control reg with that info. ab@2201: * This is needed because one of the SW controlled pins is used for ab@2201: * signal detection. So this should be done before e1000_setup_pcs_link() ab@2201: * or e1000_phy_setup() is called. ab@2201: */ ab@2201: if (hw->mac_type == e1000_82543) { ab@2201: ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, ab@2201: 1, &eeprom_data); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("EEPROM Read Error\n"); ab@2201: return -E1000_ERR_EEPROM; ab@2201: } ab@2201: ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) << ab@2201: SWDPIO__EXT_SHIFT); ab@2201: ew32(CTRL_EXT, ctrl_ext); ab@2201: } ab@2201: ab@2201: /* Call the necessary subroutine to configure the link. */ ab@2201: ret_val = (hw->media_type == e1000_media_type_copper) ? ab@2201: e1000_setup_copper_link(hw) : e1000_setup_fiber_serdes_link(hw); ab@2201: ab@2201: /* Initialize the flow control address, type, and PAUSE timer ab@2201: * registers to their default values. This is done even if flow ab@2201: * control is disabled, because it does not hurt anything to ab@2201: * initialize these registers. ab@2201: */ ab@2201: DEBUGOUT ab@2201: ("Initializing the Flow Control address, type and timer regs\n"); ab@2201: ab@2201: ew32(FCT, FLOW_CONTROL_TYPE); ab@2201: ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH); ab@2201: ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW); ab@2201: ab@2201: ew32(FCTTV, hw->fc_pause_time); ab@2201: ab@2201: /* Set the flow control receive threshold registers. Normally, ab@2201: * these registers will be set to a default threshold that may be ab@2201: * adjusted later by the driver's runtime code. However, if the ab@2201: * ability to transmit pause frames in not enabled, then these ab@2201: * registers will be set to 0. ab@2201: */ ab@2201: if (!(hw->fc & E1000_FC_TX_PAUSE)) { ab@2201: ew32(FCRTL, 0); ab@2201: ew32(FCRTH, 0); ab@2201: } else { ab@2201: /* We need to set up the Receive Threshold high and low water marks ab@2201: * as well as (optionally) enabling the transmission of XON frames. ab@2201: */ ab@2201: if (hw->fc_send_xon) { ab@2201: ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE)); ab@2201: ew32(FCRTH, hw->fc_high_water); ab@2201: } else { ab@2201: ew32(FCRTL, hw->fc_low_water); ab@2201: ew32(FCRTH, hw->fc_high_water); ab@2201: } ab@2201: } ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_setup_fiber_serdes_link - prepare fiber or serdes link ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Manipulates Physical Coding Sublayer functions in order to configure ab@2201: * link. Assumes the hardware has been previously reset and the transmitter ab@2201: * and receiver are not enabled. ab@2201: */ ab@2201: static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw) ab@2201: { ab@2201: u32 ctrl; ab@2201: u32 status; ab@2201: u32 txcw = 0; ab@2201: u32 i; ab@2201: u32 signal = 0; ab@2201: s32 ret_val; ab@2201: ab@2201: DEBUGFUNC("e1000_setup_fiber_serdes_link"); ab@2201: ab@2201: /* On adapters with a MAC newer than 82544, SWDP 1 will be ab@2201: * set when the optics detect a signal. On older adapters, it will be ab@2201: * cleared when there is a signal. This applies to fiber media only. ab@2201: * If we're on serdes media, adjust the output amplitude to value ab@2201: * set in the EEPROM. ab@2201: */ ab@2201: ctrl = er32(CTRL); ab@2201: if (hw->media_type == e1000_media_type_fiber) ab@2201: signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; ab@2201: ab@2201: ret_val = e1000_adjust_serdes_amplitude(hw); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* Take the link out of reset */ ab@2201: ctrl &= ~(E1000_CTRL_LRST); ab@2201: ab@2201: /* Adjust VCO speed to improve BER performance */ ab@2201: ret_val = e1000_set_vco_speed(hw); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: e1000_config_collision_dist(hw); ab@2201: ab@2201: /* Check for a software override of the flow control settings, and setup ab@2201: * the device accordingly. If auto-negotiation is enabled, then software ab@2201: * will have to set the "PAUSE" bits to the correct value in the Tranmsit ab@2201: * Config Word Register (TXCW) and re-start auto-negotiation. However, if ab@2201: * auto-negotiation is disabled, then software will have to manually ab@2201: * configure the two flow control enable bits in the CTRL register. ab@2201: * ab@2201: * The possible values of the "fc" parameter are: ab@2201: * 0: Flow control is completely disabled ab@2201: * 1: Rx flow control is enabled (we can receive pause frames, but ab@2201: * not send pause frames). ab@2201: * 2: Tx flow control is enabled (we can send pause frames but we do ab@2201: * not support receiving pause frames). ab@2201: * 3: Both Rx and TX flow control (symmetric) are enabled. ab@2201: */ ab@2201: switch (hw->fc) { ab@2201: case E1000_FC_NONE: ab@2201: /* Flow control is completely disabled by a software over-ride. */ ab@2201: txcw = (E1000_TXCW_ANE | E1000_TXCW_FD); ab@2201: break; ab@2201: case E1000_FC_RX_PAUSE: ab@2201: /* RX Flow control is enabled and TX Flow control is disabled by a ab@2201: * software over-ride. Since there really isn't a way to advertise ab@2201: * that we are capable of RX Pause ONLY, we will advertise that we ab@2201: * support both symmetric and asymmetric RX PAUSE. Later, we will ab@2201: * disable the adapter's ability to send PAUSE frames. ab@2201: */ ab@2201: txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); ab@2201: break; ab@2201: case E1000_FC_TX_PAUSE: ab@2201: /* TX Flow control is enabled, and RX Flow control is disabled, by a ab@2201: * software over-ride. ab@2201: */ ab@2201: txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR); ab@2201: break; ab@2201: case E1000_FC_FULL: ab@2201: /* Flow control (both RX and TX) is enabled by a software over-ride. */ ab@2201: txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); ab@2201: break; ab@2201: default: ab@2201: DEBUGOUT("Flow control param set incorrectly\n"); ab@2201: return -E1000_ERR_CONFIG; ab@2201: break; ab@2201: } ab@2201: ab@2201: /* Since auto-negotiation is enabled, take the link out of reset (the link ab@2201: * will be in reset, because we previously reset the chip). This will ab@2201: * restart auto-negotiation. If auto-negotiation is successful then the ab@2201: * link-up status bit will be set and the flow control enable bits (RFCE ab@2201: * and TFCE) will be set according to their negotiated value. ab@2201: */ ab@2201: DEBUGOUT("Auto-negotiation enabled\n"); ab@2201: ab@2201: ew32(TXCW, txcw); ab@2201: ew32(CTRL, ctrl); ab@2201: E1000_WRITE_FLUSH(); ab@2201: ab@2201: hw->txcw = txcw; ab@2201: msleep(1); ab@2201: ab@2201: /* If we have a signal (the cable is plugged in) then poll for a "Link-Up" ab@2201: * indication in the Device Status Register. Time-out if a link isn't ab@2201: * seen in 500 milliseconds seconds (Auto-negotiation should complete in ab@2201: * less than 500 milliseconds even if the other end is doing it in SW). ab@2201: * For internal serdes, we just assume a signal is present, then poll. ab@2201: */ ab@2201: if (hw->media_type == e1000_media_type_internal_serdes || ab@2201: (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) { ab@2201: DEBUGOUT("Looking for Link\n"); ab@2201: for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) { ab@2201: msleep(10); ab@2201: status = er32(STATUS); ab@2201: if (status & E1000_STATUS_LU) ab@2201: break; ab@2201: } ab@2201: if (i == (LINK_UP_TIMEOUT / 10)) { ab@2201: DEBUGOUT("Never got a valid link from auto-neg!!!\n"); ab@2201: hw->autoneg_failed = 1; ab@2201: /* AutoNeg failed to achieve a link, so we'll call ab@2201: * e1000_check_for_link. This routine will force the link up if ab@2201: * we detect a signal. This will allow us to communicate with ab@2201: * non-autonegotiating link partners. ab@2201: */ ab@2201: ret_val = e1000_check_for_link(hw); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("Error while checking for link\n"); ab@2201: return ret_val; ab@2201: } ab@2201: hw->autoneg_failed = 0; ab@2201: } else { ab@2201: hw->autoneg_failed = 0; ab@2201: DEBUGOUT("Valid Link Found\n"); ab@2201: } ab@2201: } else { ab@2201: DEBUGOUT("No Signal Detected\n"); ab@2201: } ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_copper_link_preconfig - early configuration for copper ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Make sure we have a valid PHY and change PHY mode before link setup. ab@2201: */ ab@2201: static s32 e1000_copper_link_preconfig(struct e1000_hw *hw) ab@2201: { ab@2201: u32 ctrl; ab@2201: s32 ret_val; ab@2201: u16 phy_data; ab@2201: ab@2201: DEBUGFUNC("e1000_copper_link_preconfig"); ab@2201: ab@2201: ctrl = er32(CTRL); ab@2201: /* With 82543, we need to force speed and duplex on the MAC equal to what ab@2201: * the PHY speed and duplex configuration is. In addition, we need to ab@2201: * perform a hardware reset on the PHY to take it out of reset. ab@2201: */ ab@2201: if (hw->mac_type > e1000_82543) { ab@2201: ctrl |= E1000_CTRL_SLU; ab@2201: ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); ab@2201: ew32(CTRL, ctrl); ab@2201: } else { ab@2201: ctrl |= ab@2201: (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU); ab@2201: ew32(CTRL, ctrl); ab@2201: ret_val = e1000_phy_hw_reset(hw); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: /* Make sure we have a valid PHY */ ab@2201: ret_val = e1000_detect_gig_phy(hw); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("Error, did not detect valid phy.\n"); ab@2201: return ret_val; ab@2201: } ab@2201: DEBUGOUT1("Phy ID = %x \n", hw->phy_id); ab@2201: ab@2201: /* Set PHY to class A mode (if necessary) */ ab@2201: ret_val = e1000_set_phy_mode(hw); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: if ((hw->mac_type == e1000_82545_rev_3) || ab@2201: (hw->mac_type == e1000_82546_rev_3)) { ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); ab@2201: phy_data |= 0x00000008; ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); ab@2201: } ab@2201: ab@2201: if (hw->mac_type <= e1000_82543 || ab@2201: hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 || ab@2201: hw->mac_type == e1000_82541_rev_2 ab@2201: || hw->mac_type == e1000_82547_rev_2) ab@2201: hw->phy_reset_disable = false; ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_copper_link_igp_setup - Copper link setup for e1000_phy_igp series. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: */ ab@2201: static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw) ab@2201: { ab@2201: u32 led_ctrl; ab@2201: s32 ret_val; ab@2201: u16 phy_data; ab@2201: ab@2201: DEBUGFUNC("e1000_copper_link_igp_setup"); ab@2201: ab@2201: if (hw->phy_reset_disable) ab@2201: return E1000_SUCCESS; ab@2201: ab@2201: ret_val = e1000_phy_reset(hw); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("Error Resetting the PHY\n"); ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: /* Wait 15ms for MAC to configure PHY from eeprom settings */ ab@2201: msleep(15); ab@2201: /* Configure activity LED after PHY reset */ ab@2201: led_ctrl = er32(LEDCTL); ab@2201: led_ctrl &= IGP_ACTIVITY_LED_MASK; ab@2201: led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); ab@2201: ew32(LEDCTL, led_ctrl); ab@2201: ab@2201: /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */ ab@2201: if (hw->phy_type == e1000_phy_igp) { ab@2201: /* disable lplu d3 during driver init */ ab@2201: ret_val = e1000_set_d3_lplu_state(hw, false); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("Error Disabling LPLU D3\n"); ab@2201: return ret_val; ab@2201: } ab@2201: } ab@2201: ab@2201: /* Configure mdi-mdix settings */ ab@2201: ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { ab@2201: hw->dsp_config_state = e1000_dsp_config_disabled; ab@2201: /* Force MDI for earlier revs of the IGP PHY */ ab@2201: phy_data &= ab@2201: ~(IGP01E1000_PSCR_AUTO_MDIX | ab@2201: IGP01E1000_PSCR_FORCE_MDI_MDIX); ab@2201: hw->mdix = 1; ab@2201: ab@2201: } else { ab@2201: hw->dsp_config_state = e1000_dsp_config_enabled; ab@2201: phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; ab@2201: ab@2201: switch (hw->mdix) { ab@2201: case 1: ab@2201: phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; ab@2201: break; ab@2201: case 2: ab@2201: phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX; ab@2201: break; ab@2201: case 0: ab@2201: default: ab@2201: phy_data |= IGP01E1000_PSCR_AUTO_MDIX; ab@2201: break; ab@2201: } ab@2201: } ab@2201: ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* set auto-master slave resolution settings */ ab@2201: if (hw->autoneg) { ab@2201: e1000_ms_type phy_ms_setting = hw->master_slave; ab@2201: ab@2201: if (hw->ffe_config_state == e1000_ffe_config_active) ab@2201: hw->ffe_config_state = e1000_ffe_config_enabled; ab@2201: ab@2201: if (hw->dsp_config_state == e1000_dsp_config_activated) ab@2201: hw->dsp_config_state = e1000_dsp_config_enabled; ab@2201: ab@2201: /* when autonegotiation advertisement is only 1000Mbps then we ab@2201: * should disable SmartSpeed and enable Auto MasterSlave ab@2201: * resolution as hardware default. */ ab@2201: if (hw->autoneg_advertised == ADVERTISE_1000_FULL) { ab@2201: /* Disable SmartSpeed */ ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, ab@2201: &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, ab@2201: phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: /* Set auto Master/Slave resolution process */ ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: phy_data &= ~CR_1000T_MS_ENABLE; ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* load defaults for future use */ ab@2201: hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ? ab@2201: ((phy_data & CR_1000T_MS_VALUE) ? ab@2201: e1000_ms_force_master : ab@2201: e1000_ms_force_slave) : e1000_ms_auto; ab@2201: ab@2201: switch (phy_ms_setting) { ab@2201: case e1000_ms_force_master: ab@2201: phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE); ab@2201: break; ab@2201: case e1000_ms_force_slave: ab@2201: phy_data |= CR_1000T_MS_ENABLE; ab@2201: phy_data &= ~(CR_1000T_MS_VALUE); ab@2201: break; ab@2201: case e1000_ms_auto: ab@2201: phy_data &= ~CR_1000T_MS_ENABLE; ab@2201: default: ab@2201: break; ab@2201: } ab@2201: ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_copper_link_mgp_setup - Copper link setup for e1000_phy_m88 series. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: */ ab@2201: static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 phy_data; ab@2201: ab@2201: DEBUGFUNC("e1000_copper_link_mgp_setup"); ab@2201: ab@2201: if (hw->phy_reset_disable) ab@2201: return E1000_SUCCESS; ab@2201: ab@2201: /* Enable CRS on TX. This must be set for half-duplex operation. */ ab@2201: ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; ab@2201: ab@2201: /* Options: ab@2201: * MDI/MDI-X = 0 (default) ab@2201: * 0 - Auto for all speeds ab@2201: * 1 - MDI mode ab@2201: * 2 - MDI-X mode ab@2201: * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) ab@2201: */ ab@2201: phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; ab@2201: ab@2201: switch (hw->mdix) { ab@2201: case 1: ab@2201: phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE; ab@2201: break; ab@2201: case 2: ab@2201: phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE; ab@2201: break; ab@2201: case 3: ab@2201: phy_data |= M88E1000_PSCR_AUTO_X_1000T; ab@2201: break; ab@2201: case 0: ab@2201: default: ab@2201: phy_data |= M88E1000_PSCR_AUTO_X_MODE; ab@2201: break; ab@2201: } ab@2201: ab@2201: /* Options: ab@2201: * disable_polarity_correction = 0 (default) ab@2201: * Automatic Correction for Reversed Cable Polarity ab@2201: * 0 - Disabled ab@2201: * 1 - Enabled ab@2201: */ ab@2201: phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL; ab@2201: if (hw->disable_polarity_correction == 1) ab@2201: phy_data |= M88E1000_PSCR_POLARITY_REVERSAL; ab@2201: ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: if (hw->phy_revision < M88E1011_I_REV_4) { ab@2201: /* Force TX_CLK in the Extended PHY Specific Control Register ab@2201: * to 25MHz clock. ab@2201: */ ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, ab@2201: &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_data |= M88E1000_EPSCR_TX_CLK_25; ab@2201: ab@2201: if ((hw->phy_revision == E1000_REVISION_2) && ab@2201: (hw->phy_id == M88E1111_I_PHY_ID)) { ab@2201: /* Vidalia Phy, set the downshift counter to 5x */ ab@2201: phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK); ab@2201: phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X; ab@2201: ret_val = e1000_write_phy_reg(hw, ab@2201: M88E1000_EXT_PHY_SPEC_CTRL, ab@2201: phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } else { ab@2201: /* Configure Master and Slave downshift values */ ab@2201: phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK | ab@2201: M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK); ab@2201: phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X | ab@2201: M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X); ab@2201: ret_val = e1000_write_phy_reg(hw, ab@2201: M88E1000_EXT_PHY_SPEC_CTRL, ab@2201: phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: } ab@2201: ab@2201: /* SW Reset the PHY so all changes take effect */ ab@2201: ret_val = e1000_phy_reset(hw); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("Error Resetting the PHY\n"); ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_copper_link_autoneg - setup auto-neg ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Setup auto-negotiation and flow control advertisements, ab@2201: * and then perform auto-negotiation. ab@2201: */ ab@2201: static s32 e1000_copper_link_autoneg(struct e1000_hw *hw) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 phy_data; ab@2201: ab@2201: DEBUGFUNC("e1000_copper_link_autoneg"); ab@2201: ab@2201: /* Perform some bounds checking on the hw->autoneg_advertised ab@2201: * parameter. If this variable is zero, then set it to the default. ab@2201: */ ab@2201: hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT; ab@2201: ab@2201: /* If autoneg_advertised is zero, we assume it was not defaulted ab@2201: * by the calling code so we set to advertise full capability. ab@2201: */ ab@2201: if (hw->autoneg_advertised == 0) ab@2201: hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT; ab@2201: ab@2201: DEBUGOUT("Reconfiguring auto-neg advertisement params\n"); ab@2201: ret_val = e1000_phy_setup_autoneg(hw); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("Error Setting up Auto-Negotiation\n"); ab@2201: return ret_val; ab@2201: } ab@2201: DEBUGOUT("Restarting Auto-Neg\n"); ab@2201: ab@2201: /* Restart auto-negotiation by setting the Auto Neg Enable bit and ab@2201: * the Auto Neg Restart bit in the PHY control register. ab@2201: */ ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); ab@2201: ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* Does the user want to wait for Auto-Neg to complete here, or ab@2201: * check at a later time (for example, callback routine). ab@2201: */ ab@2201: if (hw->wait_autoneg_complete) { ab@2201: ret_val = e1000_wait_autoneg(hw); ab@2201: if (ret_val) { ab@2201: DEBUGOUT ab@2201: ("Error while waiting for autoneg to complete\n"); ab@2201: return ret_val; ab@2201: } ab@2201: } ab@2201: ab@2201: hw->get_link_status = true; ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_copper_link_postconfig - post link setup ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Config the MAC and the PHY after link is up. ab@2201: * 1) Set up the MAC to the current PHY speed/duplex ab@2201: * if we are on 82543. If we ab@2201: * are on newer silicon, we only need to configure ab@2201: * collision distance in the Transmit Control Register. ab@2201: * 2) Set up flow control on the MAC to that established with ab@2201: * the link partner. ab@2201: * 3) Config DSP to improve Gigabit link quality for some PHY revisions. ab@2201: */ ab@2201: static s32 e1000_copper_link_postconfig(struct e1000_hw *hw) ab@2201: { ab@2201: s32 ret_val; ab@2201: DEBUGFUNC("e1000_copper_link_postconfig"); ab@2201: ab@2201: if (hw->mac_type >= e1000_82544) { ab@2201: e1000_config_collision_dist(hw); ab@2201: } else { ab@2201: ret_val = e1000_config_mac_to_phy(hw); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("Error configuring MAC to PHY settings\n"); ab@2201: return ret_val; ab@2201: } ab@2201: } ab@2201: ret_val = e1000_config_fc_after_link_up(hw); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("Error Configuring Flow Control\n"); ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: /* Config DSP to improve Giga link quality */ ab@2201: if (hw->phy_type == e1000_phy_igp) { ab@2201: ret_val = e1000_config_dsp_after_link_change(hw, true); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("Error Configuring DSP after link up\n"); ab@2201: return ret_val; ab@2201: } ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_setup_copper_link - phy/speed/duplex setting ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Detects which PHY is present and sets up the speed and duplex ab@2201: */ ab@2201: static s32 e1000_setup_copper_link(struct e1000_hw *hw) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 i; ab@2201: u16 phy_data; ab@2201: ab@2201: DEBUGFUNC("e1000_setup_copper_link"); ab@2201: ab@2201: /* Check if it is a valid PHY and set PHY mode if necessary. */ ab@2201: ret_val = e1000_copper_link_preconfig(hw); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: if (hw->phy_type == e1000_phy_igp) { ab@2201: ret_val = e1000_copper_link_igp_setup(hw); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } else if (hw->phy_type == e1000_phy_m88) { ab@2201: ret_val = e1000_copper_link_mgp_setup(hw); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: if (hw->autoneg) { ab@2201: /* Setup autoneg and flow control advertisement ab@2201: * and perform autonegotiation */ ab@2201: ret_val = e1000_copper_link_autoneg(hw); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } else { ab@2201: /* PHY will be set to 10H, 10F, 100H,or 100F ab@2201: * depending on value from forced_speed_duplex. */ ab@2201: DEBUGOUT("Forcing speed and duplex\n"); ab@2201: ret_val = e1000_phy_force_speed_duplex(hw); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("Error Forcing Speed and Duplex\n"); ab@2201: return ret_val; ab@2201: } ab@2201: } ab@2201: ab@2201: /* Check link status. Wait up to 100 microseconds for link to become ab@2201: * valid. ab@2201: */ ab@2201: for (i = 0; i < 10; i++) { ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: if (phy_data & MII_SR_LINK_STATUS) { ab@2201: /* Config the MAC and PHY after link is up */ ab@2201: ret_val = e1000_copper_link_postconfig(hw); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: DEBUGOUT("Valid link established!!!\n"); ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: udelay(10); ab@2201: } ab@2201: ab@2201: DEBUGOUT("Unable to establish link!!!\n"); ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_phy_setup_autoneg - phy settings ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Configures PHY autoneg and flow control advertisement settings ab@2201: */ ab@2201: s32 e1000_phy_setup_autoneg(struct e1000_hw *hw) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 mii_autoneg_adv_reg; ab@2201: u16 mii_1000t_ctrl_reg; ab@2201: ab@2201: DEBUGFUNC("e1000_phy_setup_autoneg"); ab@2201: ab@2201: /* Read the MII Auto-Neg Advertisement Register (Address 4). */ ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* Read the MII 1000Base-T Control Register (Address 9). */ ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* Need to parse both autoneg_advertised and fc and set up ab@2201: * the appropriate PHY registers. First we will parse for ab@2201: * autoneg_advertised software override. Since we can advertise ab@2201: * a plethora of combinations, we need to check each bit ab@2201: * individually. ab@2201: */ ab@2201: ab@2201: /* First we clear all the 10/100 mb speed bits in the Auto-Neg ab@2201: * Advertisement Register (Address 4) and the 1000 mb speed bits in ab@2201: * the 1000Base-T Control Register (Address 9). ab@2201: */ ab@2201: mii_autoneg_adv_reg &= ~REG4_SPEED_MASK; ab@2201: mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK; ab@2201: ab@2201: DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised); ab@2201: ab@2201: /* Do we want to advertise 10 Mb Half Duplex? */ ab@2201: if (hw->autoneg_advertised & ADVERTISE_10_HALF) { ab@2201: DEBUGOUT("Advertise 10mb Half duplex\n"); ab@2201: mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS; ab@2201: } ab@2201: ab@2201: /* Do we want to advertise 10 Mb Full Duplex? */ ab@2201: if (hw->autoneg_advertised & ADVERTISE_10_FULL) { ab@2201: DEBUGOUT("Advertise 10mb Full duplex\n"); ab@2201: mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS; ab@2201: } ab@2201: ab@2201: /* Do we want to advertise 100 Mb Half Duplex? */ ab@2201: if (hw->autoneg_advertised & ADVERTISE_100_HALF) { ab@2201: DEBUGOUT("Advertise 100mb Half duplex\n"); ab@2201: mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS; ab@2201: } ab@2201: ab@2201: /* Do we want to advertise 100 Mb Full Duplex? */ ab@2201: if (hw->autoneg_advertised & ADVERTISE_100_FULL) { ab@2201: DEBUGOUT("Advertise 100mb Full duplex\n"); ab@2201: mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS; ab@2201: } ab@2201: ab@2201: /* We do not allow the Phy to advertise 1000 Mb Half Duplex */ ab@2201: if (hw->autoneg_advertised & ADVERTISE_1000_HALF) { ab@2201: DEBUGOUT ab@2201: ("Advertise 1000mb Half duplex requested, request denied!\n"); ab@2201: } ab@2201: ab@2201: /* Do we want to advertise 1000 Mb Full Duplex? */ ab@2201: if (hw->autoneg_advertised & ADVERTISE_1000_FULL) { ab@2201: DEBUGOUT("Advertise 1000mb Full duplex\n"); ab@2201: mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS; ab@2201: } ab@2201: ab@2201: /* Check for a software override of the flow control settings, and ab@2201: * setup the PHY advertisement registers accordingly. If ab@2201: * auto-negotiation is enabled, then software will have to set the ab@2201: * "PAUSE" bits to the correct value in the Auto-Negotiation ab@2201: * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation. ab@2201: * ab@2201: * The possible values of the "fc" parameter are: ab@2201: * 0: Flow control is completely disabled ab@2201: * 1: Rx flow control is enabled (we can receive pause frames ab@2201: * but not send pause frames). ab@2201: * 2: Tx flow control is enabled (we can send pause frames ab@2201: * but we do not support receiving pause frames). ab@2201: * 3: Both Rx and TX flow control (symmetric) are enabled. ab@2201: * other: No software override. The flow control configuration ab@2201: * in the EEPROM is used. ab@2201: */ ab@2201: switch (hw->fc) { ab@2201: case E1000_FC_NONE: /* 0 */ ab@2201: /* Flow control (RX & TX) is completely disabled by a ab@2201: * software over-ride. ab@2201: */ ab@2201: mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); ab@2201: break; ab@2201: case E1000_FC_RX_PAUSE: /* 1 */ ab@2201: /* RX Flow control is enabled, and TX Flow control is ab@2201: * disabled, by a software over-ride. ab@2201: */ ab@2201: /* Since there really isn't a way to advertise that we are ab@2201: * capable of RX Pause ONLY, we will advertise that we ab@2201: * support both symmetric and asymmetric RX PAUSE. Later ab@2201: * (in e1000_config_fc_after_link_up) we will disable the ab@2201: *hw's ability to send PAUSE frames. ab@2201: */ ab@2201: mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); ab@2201: break; ab@2201: case E1000_FC_TX_PAUSE: /* 2 */ ab@2201: /* TX Flow control is enabled, and RX Flow control is ab@2201: * disabled, by a software over-ride. ab@2201: */ ab@2201: mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR; ab@2201: mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE; ab@2201: break; ab@2201: case E1000_FC_FULL: /* 3 */ ab@2201: /* Flow control (both RX and TX) is enabled by a software ab@2201: * over-ride. ab@2201: */ ab@2201: mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); ab@2201: break; ab@2201: default: ab@2201: DEBUGOUT("Flow control param set incorrectly\n"); ab@2201: return -E1000_ERR_CONFIG; ab@2201: } ab@2201: ab@2201: ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg); ab@2201: ab@2201: ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_phy_force_speed_duplex - force link settings ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Force PHY speed and duplex settings to hw->forced_speed_duplex ab@2201: */ ab@2201: static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw) ab@2201: { ab@2201: u32 ctrl; ab@2201: s32 ret_val; ab@2201: u16 mii_ctrl_reg; ab@2201: u16 mii_status_reg; ab@2201: u16 phy_data; ab@2201: u16 i; ab@2201: ab@2201: DEBUGFUNC("e1000_phy_force_speed_duplex"); ab@2201: ab@2201: /* Turn off Flow control if we are forcing speed and duplex. */ ab@2201: hw->fc = E1000_FC_NONE; ab@2201: ab@2201: DEBUGOUT1("hw->fc = %d\n", hw->fc); ab@2201: ab@2201: /* Read the Device Control Register. */ ab@2201: ctrl = er32(CTRL); ab@2201: ab@2201: /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */ ab@2201: ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); ab@2201: ctrl &= ~(DEVICE_SPEED_MASK); ab@2201: ab@2201: /* Clear the Auto Speed Detect Enable bit. */ ab@2201: ctrl &= ~E1000_CTRL_ASDE; ab@2201: ab@2201: /* Read the MII Control Register. */ ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* We need to disable autoneg in order to force link and duplex. */ ab@2201: ab@2201: mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN; ab@2201: ab@2201: /* Are we forcing Full or Half Duplex? */ ab@2201: if (hw->forced_speed_duplex == e1000_100_full || ab@2201: hw->forced_speed_duplex == e1000_10_full) { ab@2201: /* We want to force full duplex so we SET the full duplex bits in the ab@2201: * Device and MII Control Registers. ab@2201: */ ab@2201: ctrl |= E1000_CTRL_FD; ab@2201: mii_ctrl_reg |= MII_CR_FULL_DUPLEX; ab@2201: DEBUGOUT("Full Duplex\n"); ab@2201: } else { ab@2201: /* We want to force half duplex so we CLEAR the full duplex bits in ab@2201: * the Device and MII Control Registers. ab@2201: */ ab@2201: ctrl &= ~E1000_CTRL_FD; ab@2201: mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX; ab@2201: DEBUGOUT("Half Duplex\n"); ab@2201: } ab@2201: ab@2201: /* Are we forcing 100Mbps??? */ ab@2201: if (hw->forced_speed_duplex == e1000_100_full || ab@2201: hw->forced_speed_duplex == e1000_100_half) { ab@2201: /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */ ab@2201: ctrl |= E1000_CTRL_SPD_100; ab@2201: mii_ctrl_reg |= MII_CR_SPEED_100; ab@2201: mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10); ab@2201: DEBUGOUT("Forcing 100mb "); ab@2201: } else { ab@2201: /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */ ab@2201: ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100); ab@2201: mii_ctrl_reg |= MII_CR_SPEED_10; ab@2201: mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100); ab@2201: DEBUGOUT("Forcing 10mb "); ab@2201: } ab@2201: ab@2201: e1000_config_collision_dist(hw); ab@2201: ab@2201: /* Write the configured values back to the Device Control Reg. */ ab@2201: ew32(CTRL, ctrl); ab@2201: ab@2201: if (hw->phy_type == e1000_phy_m88) { ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI ab@2201: * forced whenever speed are duplex are forced. ab@2201: */ ab@2201: phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data); ab@2201: ab@2201: /* Need to reset the PHY or these changes will be ignored */ ab@2201: mii_ctrl_reg |= MII_CR_RESET; ab@2201: ab@2201: /* Disable MDI-X support for 10/100 */ ab@2201: } else { ab@2201: /* Clear Auto-Crossover to force MDI manually. IGP requires MDI ab@2201: * forced whenever speed or duplex are forced. ab@2201: */ ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; ab@2201: phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; ab@2201: ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: /* Write back the modified PHY MII control register. */ ab@2201: ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: udelay(1); ab@2201: ab@2201: /* The wait_autoneg_complete flag may be a little misleading here. ab@2201: * Since we are forcing speed and duplex, Auto-Neg is not enabled. ab@2201: * But we do want to delay for a period while forcing only so we ab@2201: * don't generate false No Link messages. So we will wait here ab@2201: * only if the user has set wait_autoneg_complete to 1, which is ab@2201: * the default. ab@2201: */ ab@2201: if (hw->wait_autoneg_complete) { ab@2201: /* We will wait for autoneg to complete. */ ab@2201: DEBUGOUT("Waiting for forced speed/duplex link.\n"); ab@2201: mii_status_reg = 0; ab@2201: ab@2201: /* We will wait for autoneg to complete or 4.5 seconds to expire. */ ab@2201: for (i = PHY_FORCE_TIME; i > 0; i--) { ab@2201: /* Read the MII Status Register and wait for Auto-Neg Complete bit ab@2201: * to be set. ab@2201: */ ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: if (mii_status_reg & MII_SR_LINK_STATUS) ab@2201: break; ab@2201: msleep(100); ab@2201: } ab@2201: if ((i == 0) && (hw->phy_type == e1000_phy_m88)) { ab@2201: /* We didn't get link. Reset the DSP and wait again for link. */ ab@2201: ret_val = e1000_phy_reset_dsp(hw); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("Error Resetting PHY DSP\n"); ab@2201: return ret_val; ab@2201: } ab@2201: } ab@2201: /* This loop will early-out if the link condition has been met. */ ab@2201: for (i = PHY_FORCE_TIME; i > 0; i--) { ab@2201: if (mii_status_reg & MII_SR_LINK_STATUS) ab@2201: break; ab@2201: msleep(100); ab@2201: /* Read the MII Status Register and wait for Auto-Neg Complete bit ab@2201: * to be set. ab@2201: */ ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: } ab@2201: ab@2201: if (hw->phy_type == e1000_phy_m88) { ab@2201: /* Because we reset the PHY above, we need to re-force TX_CLK in the ab@2201: * Extended PHY Specific Control Register to 25MHz clock. This value ab@2201: * defaults back to a 2.5MHz clock when the PHY is reset. ab@2201: */ ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, ab@2201: &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_data |= M88E1000_EPSCR_TX_CLK_25; ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, ab@2201: phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* In addition, because of the s/w reset above, we need to enable CRS on ab@2201: * TX. This must be set for both full and half duplex operation. ab@2201: */ ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) ab@2201: && (!hw->autoneg) ab@2201: && (hw->forced_speed_duplex == e1000_10_full ab@2201: || hw->forced_speed_duplex == e1000_10_half)) { ab@2201: ret_val = e1000_polarity_reversal_workaround(hw); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: } ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_config_collision_dist - set collision distance register ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Sets the collision distance in the Transmit Control register. ab@2201: * Link should have been established previously. Reads the speed and duplex ab@2201: * information from the Device Status register. ab@2201: */ ab@2201: void e1000_config_collision_dist(struct e1000_hw *hw) ab@2201: { ab@2201: u32 tctl, coll_dist; ab@2201: ab@2201: DEBUGFUNC("e1000_config_collision_dist"); ab@2201: ab@2201: if (hw->mac_type < e1000_82543) ab@2201: coll_dist = E1000_COLLISION_DISTANCE_82542; ab@2201: else ab@2201: coll_dist = E1000_COLLISION_DISTANCE; ab@2201: ab@2201: tctl = er32(TCTL); ab@2201: ab@2201: tctl &= ~E1000_TCTL_COLD; ab@2201: tctl |= coll_dist << E1000_COLD_SHIFT; ab@2201: ab@2201: ew32(TCTL, tctl); ab@2201: E1000_WRITE_FLUSH(); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_config_mac_to_phy - sync phy and mac settings ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @mii_reg: data to write to the MII control register ab@2201: * ab@2201: * Sets MAC speed and duplex settings to reflect the those in the PHY ab@2201: * The contents of the PHY register containing the needed information need to ab@2201: * be passed in. ab@2201: */ ab@2201: static s32 e1000_config_mac_to_phy(struct e1000_hw *hw) ab@2201: { ab@2201: u32 ctrl; ab@2201: s32 ret_val; ab@2201: u16 phy_data; ab@2201: ab@2201: DEBUGFUNC("e1000_config_mac_to_phy"); ab@2201: ab@2201: /* 82544 or newer MAC, Auto Speed Detection takes care of ab@2201: * MAC speed/duplex configuration.*/ ab@2201: if (hw->mac_type >= e1000_82544) ab@2201: return E1000_SUCCESS; ab@2201: ab@2201: /* Read the Device Control Register and set the bits to Force Speed ab@2201: * and Duplex. ab@2201: */ ab@2201: ctrl = er32(CTRL); ab@2201: ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); ab@2201: ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS); ab@2201: ab@2201: /* Set up duplex in the Device Control and Transmit Control ab@2201: * registers depending on negotiated values. ab@2201: */ ab@2201: ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: if (phy_data & M88E1000_PSSR_DPLX) ab@2201: ctrl |= E1000_CTRL_FD; ab@2201: else ab@2201: ctrl &= ~E1000_CTRL_FD; ab@2201: ab@2201: e1000_config_collision_dist(hw); ab@2201: ab@2201: /* Set up speed in the Device Control register depending on ab@2201: * negotiated values. ab@2201: */ ab@2201: if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) ab@2201: ctrl |= E1000_CTRL_SPD_1000; ab@2201: else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS) ab@2201: ctrl |= E1000_CTRL_SPD_100; ab@2201: ab@2201: /* Write the configured values back to the Device Control Reg. */ ab@2201: ew32(CTRL, ctrl); ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_force_mac_fc - force flow control settings ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Forces the MAC's flow control settings. ab@2201: * Sets the TFCE and RFCE bits in the device control register to reflect ab@2201: * the adapter settings. TFCE and RFCE need to be explicitly set by ab@2201: * software when a Copper PHY is used because autonegotiation is managed ab@2201: * by the PHY rather than the MAC. Software must also configure these ab@2201: * bits when link is forced on a fiber connection. ab@2201: */ ab@2201: s32 e1000_force_mac_fc(struct e1000_hw *hw) ab@2201: { ab@2201: u32 ctrl; ab@2201: ab@2201: DEBUGFUNC("e1000_force_mac_fc"); ab@2201: ab@2201: /* Get the current configuration of the Device Control Register */ ab@2201: ctrl = er32(CTRL); ab@2201: ab@2201: /* Because we didn't get link via the internal auto-negotiation ab@2201: * mechanism (we either forced link or we got link via PHY ab@2201: * auto-neg), we have to manually enable/disable transmit an ab@2201: * receive flow control. ab@2201: * ab@2201: * The "Case" statement below enables/disable flow control ab@2201: * according to the "hw->fc" parameter. ab@2201: * ab@2201: * The possible values of the "fc" parameter are: ab@2201: * 0: Flow control is completely disabled ab@2201: * 1: Rx flow control is enabled (we can receive pause ab@2201: * frames but not send pause frames). ab@2201: * 2: Tx flow control is enabled (we can send pause frames ab@2201: * frames but we do not receive pause frames). ab@2201: * 3: Both Rx and TX flow control (symmetric) is enabled. ab@2201: * other: No other values should be possible at this point. ab@2201: */ ab@2201: ab@2201: switch (hw->fc) { ab@2201: case E1000_FC_NONE: ab@2201: ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); ab@2201: break; ab@2201: case E1000_FC_RX_PAUSE: ab@2201: ctrl &= (~E1000_CTRL_TFCE); ab@2201: ctrl |= E1000_CTRL_RFCE; ab@2201: break; ab@2201: case E1000_FC_TX_PAUSE: ab@2201: ctrl &= (~E1000_CTRL_RFCE); ab@2201: ctrl |= E1000_CTRL_TFCE; ab@2201: break; ab@2201: case E1000_FC_FULL: ab@2201: ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); ab@2201: break; ab@2201: default: ab@2201: DEBUGOUT("Flow control param set incorrectly\n"); ab@2201: return -E1000_ERR_CONFIG; ab@2201: } ab@2201: ab@2201: /* Disable TX Flow Control for 82542 (rev 2.0) */ ab@2201: if (hw->mac_type == e1000_82542_rev2_0) ab@2201: ctrl &= (~E1000_CTRL_TFCE); ab@2201: ab@2201: ew32(CTRL, ctrl); ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_config_fc_after_link_up - configure flow control after autoneg ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Configures flow control settings after link is established ab@2201: * Should be called immediately after a valid link has been established. ab@2201: * Forces MAC flow control settings if link was forced. When in MII/GMII mode ab@2201: * and autonegotiation is enabled, the MAC flow control settings will be set ab@2201: * based on the flow control negotiated by the PHY. In TBI mode, the TFCE ab@2201: * and RFCE bits will be automatically set to the negotiated flow control mode. ab@2201: */ ab@2201: static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 mii_status_reg; ab@2201: u16 mii_nway_adv_reg; ab@2201: u16 mii_nway_lp_ability_reg; ab@2201: u16 speed; ab@2201: u16 duplex; ab@2201: ab@2201: DEBUGFUNC("e1000_config_fc_after_link_up"); ab@2201: ab@2201: /* Check for the case where we have fiber media and auto-neg failed ab@2201: * so we had to force link. In this case, we need to force the ab@2201: * configuration of the MAC to match the "fc" parameter. ab@2201: */ ab@2201: if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ab@2201: || ((hw->media_type == e1000_media_type_internal_serdes) ab@2201: && (hw->autoneg_failed)) ab@2201: || ((hw->media_type == e1000_media_type_copper) ab@2201: && (!hw->autoneg))) { ab@2201: ret_val = e1000_force_mac_fc(hw); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("Error forcing flow control settings\n"); ab@2201: return ret_val; ab@2201: } ab@2201: } ab@2201: ab@2201: /* Check for the case where we have copper media and auto-neg is ab@2201: * enabled. In this case, we need to check and see if Auto-Neg ab@2201: * has completed, and if so, how the PHY and link partner has ab@2201: * flow control configured. ab@2201: */ ab@2201: if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) { ab@2201: /* Read the MII Status Register and check to see if AutoNeg ab@2201: * has completed. We read this twice because this reg has ab@2201: * some "sticky" (latched) bits. ab@2201: */ ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) { ab@2201: /* The AutoNeg process has completed, so we now need to ab@2201: * read both the Auto Negotiation Advertisement Register ab@2201: * (Address 4) and the Auto_Negotiation Base Page Ability ab@2201: * Register (Address 5) to determine how flow control was ab@2201: * negotiated. ab@2201: */ ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, ab@2201: &mii_nway_adv_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, ab@2201: &mii_nway_lp_ability_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* Two bits in the Auto Negotiation Advertisement Register ab@2201: * (Address 4) and two bits in the Auto Negotiation Base ab@2201: * Page Ability Register (Address 5) determine flow control ab@2201: * for both the PHY and the link partner. The following ab@2201: * table, taken out of the IEEE 802.3ab/D6.0 dated March 25, ab@2201: * 1999, describes these PAUSE resolution bits and how flow ab@2201: * control is determined based upon these settings. ab@2201: * NOTE: DC = Don't Care ab@2201: * ab@2201: * LOCAL DEVICE | LINK PARTNER ab@2201: * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution ab@2201: *-------|---------|-------|---------|-------------------- ab@2201: * 0 | 0 | DC | DC | E1000_FC_NONE ab@2201: * 0 | 1 | 0 | DC | E1000_FC_NONE ab@2201: * 0 | 1 | 1 | 0 | E1000_FC_NONE ab@2201: * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE ab@2201: * 1 | 0 | 0 | DC | E1000_FC_NONE ab@2201: * 1 | DC | 1 | DC | E1000_FC_FULL ab@2201: * 1 | 1 | 0 | 0 | E1000_FC_NONE ab@2201: * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE ab@2201: * ab@2201: */ ab@2201: /* Are both PAUSE bits set to 1? If so, this implies ab@2201: * Symmetric Flow Control is enabled at both ends. The ab@2201: * ASM_DIR bits are irrelevant per the spec. ab@2201: * ab@2201: * For Symmetric Flow Control: ab@2201: * ab@2201: * LOCAL DEVICE | LINK PARTNER ab@2201: * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result ab@2201: *-------|---------|-------|---------|-------------------- ab@2201: * 1 | DC | 1 | DC | E1000_FC_FULL ab@2201: * ab@2201: */ ab@2201: if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && ab@2201: (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { ab@2201: /* Now we need to check if the user selected RX ONLY ab@2201: * of pause frames. In this case, we had to advertise ab@2201: * FULL flow control because we could not advertise RX ab@2201: * ONLY. Hence, we must now check to see if we need to ab@2201: * turn OFF the TRANSMISSION of PAUSE frames. ab@2201: */ ab@2201: if (hw->original_fc == E1000_FC_FULL) { ab@2201: hw->fc = E1000_FC_FULL; ab@2201: DEBUGOUT("Flow Control = FULL.\n"); ab@2201: } else { ab@2201: hw->fc = E1000_FC_RX_PAUSE; ab@2201: DEBUGOUT ab@2201: ("Flow Control = RX PAUSE frames only.\n"); ab@2201: } ab@2201: } ab@2201: /* For receiving PAUSE frames ONLY. ab@2201: * ab@2201: * LOCAL DEVICE | LINK PARTNER ab@2201: * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result ab@2201: *-------|---------|-------|---------|-------------------- ab@2201: * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE ab@2201: * ab@2201: */ ab@2201: else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && ab@2201: (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && ab@2201: (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && ab@2201: (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) ab@2201: { ab@2201: hw->fc = E1000_FC_TX_PAUSE; ab@2201: DEBUGOUT ab@2201: ("Flow Control = TX PAUSE frames only.\n"); ab@2201: } ab@2201: /* For transmitting PAUSE frames ONLY. ab@2201: * ab@2201: * LOCAL DEVICE | LINK PARTNER ab@2201: * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result ab@2201: *-------|---------|-------|---------|-------------------- ab@2201: * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE ab@2201: * ab@2201: */ ab@2201: else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && ab@2201: (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && ab@2201: !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && ab@2201: (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) ab@2201: { ab@2201: hw->fc = E1000_FC_RX_PAUSE; ab@2201: DEBUGOUT ab@2201: ("Flow Control = RX PAUSE frames only.\n"); ab@2201: } ab@2201: /* Per the IEEE spec, at this point flow control should be ab@2201: * disabled. However, we want to consider that we could ab@2201: * be connected to a legacy switch that doesn't advertise ab@2201: * desired flow control, but can be forced on the link ab@2201: * partner. So if we advertised no flow control, that is ab@2201: * what we will resolve to. If we advertised some kind of ab@2201: * receive capability (Rx Pause Only or Full Flow Control) ab@2201: * and the link partner advertised none, we will configure ab@2201: * ourselves to enable Rx Flow Control only. We can do ab@2201: * this safely for two reasons: If the link partner really ab@2201: * didn't want flow control enabled, and we enable Rx, no ab@2201: * harm done since we won't be receiving any PAUSE frames ab@2201: * anyway. If the intent on the link partner was to have ab@2201: * flow control enabled, then by us enabling RX only, we ab@2201: * can at least receive pause frames and process them. ab@2201: * This is a good idea because in most cases, since we are ab@2201: * predominantly a server NIC, more times than not we will ab@2201: * be asked to delay transmission of packets than asking ab@2201: * our link partner to pause transmission of frames. ab@2201: */ ab@2201: else if ((hw->original_fc == E1000_FC_NONE || ab@2201: hw->original_fc == E1000_FC_TX_PAUSE) || ab@2201: hw->fc_strict_ieee) { ab@2201: hw->fc = E1000_FC_NONE; ab@2201: DEBUGOUT("Flow Control = NONE.\n"); ab@2201: } else { ab@2201: hw->fc = E1000_FC_RX_PAUSE; ab@2201: DEBUGOUT ab@2201: ("Flow Control = RX PAUSE frames only.\n"); ab@2201: } ab@2201: ab@2201: /* Now we need to do one last check... If we auto- ab@2201: * negotiated to HALF DUPLEX, flow control should not be ab@2201: * enabled per IEEE 802.3 spec. ab@2201: */ ab@2201: ret_val = ab@2201: e1000_get_speed_and_duplex(hw, &speed, &duplex); ab@2201: if (ret_val) { ab@2201: DEBUGOUT ab@2201: ("Error getting link speed and duplex\n"); ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: if (duplex == HALF_DUPLEX) ab@2201: hw->fc = E1000_FC_NONE; ab@2201: ab@2201: /* Now we call a subroutine to actually force the MAC ab@2201: * controller to use the correct flow control settings. ab@2201: */ ab@2201: ret_val = e1000_force_mac_fc(hw); ab@2201: if (ret_val) { ab@2201: DEBUGOUT ab@2201: ("Error forcing flow control settings\n"); ab@2201: return ret_val; ab@2201: } ab@2201: } else { ab@2201: DEBUGOUT ab@2201: ("Copper PHY and Auto Neg has not completed.\n"); ab@2201: } ab@2201: } ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_check_for_serdes_link_generic - Check for link (Serdes) ab@2201: * @hw: pointer to the HW structure ab@2201: * ab@2201: * Checks for link up on the hardware. If link is not up and we have ab@2201: * a signal, then we need to force link up. ab@2201: */ ab@2201: static s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw) ab@2201: { ab@2201: u32 rxcw; ab@2201: u32 ctrl; ab@2201: u32 status; ab@2201: s32 ret_val = E1000_SUCCESS; ab@2201: ab@2201: DEBUGFUNC("e1000_check_for_serdes_link_generic"); ab@2201: ab@2201: ctrl = er32(CTRL); ab@2201: status = er32(STATUS); ab@2201: rxcw = er32(RXCW); ab@2201: ab@2201: /* ab@2201: * If we don't have link (auto-negotiation failed or link partner ab@2201: * cannot auto-negotiate), and our link partner is not trying to ab@2201: * auto-negotiate with us (we are receiving idles or data), ab@2201: * we need to force link up. We also need to give auto-negotiation ab@2201: * time to complete. ab@2201: */ ab@2201: /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */ ab@2201: if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) { ab@2201: if (hw->autoneg_failed == 0) { ab@2201: hw->autoneg_failed = 1; ab@2201: goto out; ab@2201: } ab@2201: DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n"); ab@2201: ab@2201: /* Disable auto-negotiation in the TXCW register */ ab@2201: ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE)); ab@2201: ab@2201: /* Force link-up and also force full-duplex. */ ab@2201: ctrl = er32(CTRL); ab@2201: ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); ab@2201: ew32(CTRL, ctrl); ab@2201: ab@2201: /* Configure Flow Control after forcing link up. */ ab@2201: ret_val = e1000_config_fc_after_link_up(hw); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("Error configuring flow control\n"); ab@2201: goto out; ab@2201: } ab@2201: } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { ab@2201: /* ab@2201: * If we are forcing link and we are receiving /C/ ordered ab@2201: * sets, re-enable auto-negotiation in the TXCW register ab@2201: * and disable forced link in the Device Control register ab@2201: * in an attempt to auto-negotiate with our link partner. ab@2201: */ ab@2201: DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n"); ab@2201: ew32(TXCW, hw->txcw); ab@2201: ew32(CTRL, (ctrl & ~E1000_CTRL_SLU)); ab@2201: ab@2201: hw->serdes_has_link = true; ab@2201: } else if (!(E1000_TXCW_ANE & er32(TXCW))) { ab@2201: /* ab@2201: * If we force link for non-auto-negotiation switch, check ab@2201: * link status based on MAC synchronization for internal ab@2201: * serdes media type. ab@2201: */ ab@2201: /* SYNCH bit and IV bit are sticky. */ ab@2201: udelay(10); ab@2201: rxcw = er32(RXCW); ab@2201: if (rxcw & E1000_RXCW_SYNCH) { ab@2201: if (!(rxcw & E1000_RXCW_IV)) { ab@2201: hw->serdes_has_link = true; ab@2201: DEBUGOUT("SERDES: Link up - forced.\n"); ab@2201: } ab@2201: } else { ab@2201: hw->serdes_has_link = false; ab@2201: DEBUGOUT("SERDES: Link down - force failed.\n"); ab@2201: } ab@2201: } ab@2201: ab@2201: if (E1000_TXCW_ANE & er32(TXCW)) { ab@2201: status = er32(STATUS); ab@2201: if (status & E1000_STATUS_LU) { ab@2201: /* SYNCH bit and IV bit are sticky, so reread rxcw. */ ab@2201: udelay(10); ab@2201: rxcw = er32(RXCW); ab@2201: if (rxcw & E1000_RXCW_SYNCH) { ab@2201: if (!(rxcw & E1000_RXCW_IV)) { ab@2201: hw->serdes_has_link = true; ab@2201: DEBUGOUT("SERDES: Link up - autoneg " ab@2201: "completed successfully.\n"); ab@2201: } else { ab@2201: hw->serdes_has_link = false; ab@2201: DEBUGOUT("SERDES: Link down - invalid" ab@2201: "codewords detected in autoneg.\n"); ab@2201: } ab@2201: } else { ab@2201: hw->serdes_has_link = false; ab@2201: DEBUGOUT("SERDES: Link down - no sync.\n"); ab@2201: } ab@2201: } else { ab@2201: hw->serdes_has_link = false; ab@2201: DEBUGOUT("SERDES: Link down - autoneg failed\n"); ab@2201: } ab@2201: } ab@2201: ab@2201: out: ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_check_for_link ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Checks to see if the link status of the hardware has changed. ab@2201: * Called by any function that needs to check the link status of the adapter. ab@2201: */ ab@2201: s32 e1000_check_for_link(struct e1000_hw *hw) ab@2201: { ab@2201: u32 rxcw = 0; ab@2201: u32 ctrl; ab@2201: u32 status; ab@2201: u32 rctl; ab@2201: u32 icr; ab@2201: u32 signal = 0; ab@2201: s32 ret_val; ab@2201: u16 phy_data; ab@2201: ab@2201: DEBUGFUNC("e1000_check_for_link"); ab@2201: ab@2201: ctrl = er32(CTRL); ab@2201: status = er32(STATUS); ab@2201: ab@2201: /* On adapters with a MAC newer than 82544, SW Definable pin 1 will be ab@2201: * set when the optics detect a signal. On older adapters, it will be ab@2201: * cleared when there is a signal. This applies to fiber media only. ab@2201: */ ab@2201: if ((hw->media_type == e1000_media_type_fiber) || ab@2201: (hw->media_type == e1000_media_type_internal_serdes)) { ab@2201: rxcw = er32(RXCW); ab@2201: ab@2201: if (hw->media_type == e1000_media_type_fiber) { ab@2201: signal = ab@2201: (hw->mac_type > ab@2201: e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; ab@2201: if (status & E1000_STATUS_LU) ab@2201: hw->get_link_status = false; ab@2201: } ab@2201: } ab@2201: ab@2201: /* If we have a copper PHY then we only want to go out to the PHY ab@2201: * registers to see if Auto-Neg has completed and/or if our link ab@2201: * status has changed. The get_link_status flag will be set if we ab@2201: * receive a Link Status Change interrupt or we have Rx Sequence ab@2201: * Errors. ab@2201: */ ab@2201: if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) { ab@2201: /* First we want to see if the MII Status Register reports ab@2201: * link. If so, then we want to get the current speed/duplex ab@2201: * of the PHY. ab@2201: * Read the register twice since the link bit is sticky. ab@2201: */ ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: if (phy_data & MII_SR_LINK_STATUS) { ab@2201: hw->get_link_status = false; ab@2201: /* Check if there was DownShift, must be checked immediately after ab@2201: * link-up */ ab@2201: e1000_check_downshift(hw); ab@2201: ab@2201: /* If we are on 82544 or 82543 silicon and speed/duplex ab@2201: * are forced to 10H or 10F, then we will implement the polarity ab@2201: * reversal workaround. We disable interrupts first, and upon ab@2201: * returning, place the devices interrupt state to its previous ab@2201: * value except for the link status change interrupt which will ab@2201: * happen due to the execution of this workaround. ab@2201: */ ab@2201: ab@2201: if ((hw->mac_type == e1000_82544 ab@2201: || hw->mac_type == e1000_82543) && (!hw->autoneg) ab@2201: && (hw->forced_speed_duplex == e1000_10_full ab@2201: || hw->forced_speed_duplex == e1000_10_half)) { ab@2201: ew32(IMC, 0xffffffff); ab@2201: ret_val = ab@2201: e1000_polarity_reversal_workaround(hw); ab@2201: icr = er32(ICR); ab@2201: ew32(ICS, (icr & ~E1000_ICS_LSC)); ab@2201: ew32(IMS, IMS_ENABLE_MASK); ab@2201: } ab@2201: ab@2201: } else { ab@2201: /* No link detected */ ab@2201: e1000_config_dsp_after_link_change(hw, false); ab@2201: return 0; ab@2201: } ab@2201: ab@2201: /* If we are forcing speed/duplex, then we simply return since ab@2201: * we have already determined whether we have link or not. ab@2201: */ ab@2201: if (!hw->autoneg) ab@2201: return -E1000_ERR_CONFIG; ab@2201: ab@2201: /* optimize the dsp settings for the igp phy */ ab@2201: e1000_config_dsp_after_link_change(hw, true); ab@2201: ab@2201: /* We have a M88E1000 PHY and Auto-Neg is enabled. If we ab@2201: * have Si on board that is 82544 or newer, Auto ab@2201: * Speed Detection takes care of MAC speed/duplex ab@2201: * configuration. So we only need to configure Collision ab@2201: * Distance in the MAC. Otherwise, we need to force ab@2201: * speed/duplex on the MAC to the current PHY speed/duplex ab@2201: * settings. ab@2201: */ ab@2201: if (hw->mac_type >= e1000_82544) ab@2201: e1000_config_collision_dist(hw); ab@2201: else { ab@2201: ret_val = e1000_config_mac_to_phy(hw); ab@2201: if (ret_val) { ab@2201: DEBUGOUT ab@2201: ("Error configuring MAC to PHY settings\n"); ab@2201: return ret_val; ab@2201: } ab@2201: } ab@2201: ab@2201: /* Configure Flow Control now that Auto-Neg has completed. First, we ab@2201: * need to restore the desired flow control settings because we may ab@2201: * have had to re-autoneg with a different link partner. ab@2201: */ ab@2201: ret_val = e1000_config_fc_after_link_up(hw); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("Error configuring flow control\n"); ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: /* At this point we know that we are on copper and we have ab@2201: * auto-negotiated link. These are conditions for checking the link ab@2201: * partner capability register. We use the link speed to determine if ab@2201: * TBI compatibility needs to be turned on or off. If the link is not ab@2201: * at gigabit speed, then TBI compatibility is not needed. If we are ab@2201: * at gigabit speed, we turn on TBI compatibility. ab@2201: */ ab@2201: if (hw->tbi_compatibility_en) { ab@2201: u16 speed, duplex; ab@2201: ret_val = ab@2201: e1000_get_speed_and_duplex(hw, &speed, &duplex); ab@2201: if (ret_val) { ab@2201: DEBUGOUT ab@2201: ("Error getting link speed and duplex\n"); ab@2201: return ret_val; ab@2201: } ab@2201: if (speed != SPEED_1000) { ab@2201: /* If link speed is not set to gigabit speed, we do not need ab@2201: * to enable TBI compatibility. ab@2201: */ ab@2201: if (hw->tbi_compatibility_on) { ab@2201: /* If we previously were in the mode, turn it off. */ ab@2201: rctl = er32(RCTL); ab@2201: rctl &= ~E1000_RCTL_SBP; ab@2201: ew32(RCTL, rctl); ab@2201: hw->tbi_compatibility_on = false; ab@2201: } ab@2201: } else { ab@2201: /* If TBI compatibility is was previously off, turn it on. For ab@2201: * compatibility with a TBI link partner, we will store bad ab@2201: * packets. Some frames have an additional byte on the end and ab@2201: * will look like CRC errors to to the hardware. ab@2201: */ ab@2201: if (!hw->tbi_compatibility_on) { ab@2201: hw->tbi_compatibility_on = true; ab@2201: rctl = er32(RCTL); ab@2201: rctl |= E1000_RCTL_SBP; ab@2201: ew32(RCTL, rctl); ab@2201: } ab@2201: } ab@2201: } ab@2201: } ab@2201: ab@2201: if ((hw->media_type == e1000_media_type_fiber) || ab@2201: (hw->media_type == e1000_media_type_internal_serdes)) ab@2201: e1000_check_for_serdes_link_generic(hw); ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_get_speed_and_duplex ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @speed: Speed of the connection ab@2201: * @duplex: Duplex setting of the connection ab@2201: ab@2201: * Detects the current speed and duplex settings of the hardware. ab@2201: */ ab@2201: s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex) ab@2201: { ab@2201: u32 status; ab@2201: s32 ret_val; ab@2201: u16 phy_data; ab@2201: ab@2201: DEBUGFUNC("e1000_get_speed_and_duplex"); ab@2201: ab@2201: if (hw->mac_type >= e1000_82543) { ab@2201: status = er32(STATUS); ab@2201: if (status & E1000_STATUS_SPEED_1000) { ab@2201: *speed = SPEED_1000; ab@2201: DEBUGOUT("1000 Mbs, "); ab@2201: } else if (status & E1000_STATUS_SPEED_100) { ab@2201: *speed = SPEED_100; ab@2201: DEBUGOUT("100 Mbs, "); ab@2201: } else { ab@2201: *speed = SPEED_10; ab@2201: DEBUGOUT("10 Mbs, "); ab@2201: } ab@2201: ab@2201: if (status & E1000_STATUS_FD) { ab@2201: *duplex = FULL_DUPLEX; ab@2201: DEBUGOUT("Full Duplex\n"); ab@2201: } else { ab@2201: *duplex = HALF_DUPLEX; ab@2201: DEBUGOUT(" Half Duplex\n"); ab@2201: } ab@2201: } else { ab@2201: DEBUGOUT("1000 Mbs, Full Duplex\n"); ab@2201: *speed = SPEED_1000; ab@2201: *duplex = FULL_DUPLEX; ab@2201: } ab@2201: ab@2201: /* IGP01 PHY may advertise full duplex operation after speed downgrade even ab@2201: * if it is operating at half duplex. Here we set the duplex settings to ab@2201: * match the duplex in the link partner's capabilities. ab@2201: */ ab@2201: if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) { ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: if (!(phy_data & NWAY_ER_LP_NWAY_CAPS)) ab@2201: *duplex = HALF_DUPLEX; ab@2201: else { ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: if ((*speed == SPEED_100 ab@2201: && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ab@2201: || (*speed == SPEED_10 ab@2201: && !(phy_data & NWAY_LPAR_10T_FD_CAPS))) ab@2201: *duplex = HALF_DUPLEX; ab@2201: } ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_wait_autoneg ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Blocks until autoneg completes or times out (~4.5 seconds) ab@2201: */ ab@2201: static s32 e1000_wait_autoneg(struct e1000_hw *hw) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 i; ab@2201: u16 phy_data; ab@2201: ab@2201: DEBUGFUNC("e1000_wait_autoneg"); ab@2201: DEBUGOUT("Waiting for Auto-Neg to complete.\n"); ab@2201: ab@2201: /* We will wait for autoneg to complete or 4.5 seconds to expire. */ ab@2201: for (i = PHY_AUTO_NEG_TIME; i > 0; i--) { ab@2201: /* Read the MII Status Register and wait for Auto-Neg ab@2201: * Complete bit to be set. ab@2201: */ ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: if (phy_data & MII_SR_AUTONEG_COMPLETE) { ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: msleep(100); ab@2201: } ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_raise_mdi_clk - Raises the Management Data Clock ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @ctrl: Device control register's current value ab@2201: */ ab@2201: static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl) ab@2201: { ab@2201: /* Raise the clock input to the Management Data Clock (by setting the MDC ab@2201: * bit), and then delay 10 microseconds. ab@2201: */ ab@2201: ew32(CTRL, (*ctrl | E1000_CTRL_MDC)); ab@2201: E1000_WRITE_FLUSH(); ab@2201: udelay(10); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_lower_mdi_clk - Lowers the Management Data Clock ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @ctrl: Device control register's current value ab@2201: */ ab@2201: static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl) ab@2201: { ab@2201: /* Lower the clock input to the Management Data Clock (by clearing the MDC ab@2201: * bit), and then delay 10 microseconds. ab@2201: */ ab@2201: ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC)); ab@2201: E1000_WRITE_FLUSH(); ab@2201: udelay(10); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_shift_out_mdi_bits - Shifts data bits out to the PHY ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @data: Data to send out to the PHY ab@2201: * @count: Number of bits to shift out ab@2201: * ab@2201: * Bits are shifted out in MSB to LSB order. ab@2201: */ ab@2201: static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count) ab@2201: { ab@2201: u32 ctrl; ab@2201: u32 mask; ab@2201: ab@2201: /* We need to shift "count" number of bits out to the PHY. So, the value ab@2201: * in the "data" parameter will be shifted out to the PHY one bit at a ab@2201: * time. In order to do this, "data" must be broken down into bits. ab@2201: */ ab@2201: mask = 0x01; ab@2201: mask <<= (count - 1); ab@2201: ab@2201: ctrl = er32(CTRL); ab@2201: ab@2201: /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */ ab@2201: ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR); ab@2201: ab@2201: while (mask) { ab@2201: /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and ab@2201: * then raising and lowering the Management Data Clock. A "0" is ab@2201: * shifted out to the PHY by setting the MDIO bit to "0" and then ab@2201: * raising and lowering the clock. ab@2201: */ ab@2201: if (data & mask) ab@2201: ctrl |= E1000_CTRL_MDIO; ab@2201: else ab@2201: ctrl &= ~E1000_CTRL_MDIO; ab@2201: ab@2201: ew32(CTRL, ctrl); ab@2201: E1000_WRITE_FLUSH(); ab@2201: ab@2201: udelay(10); ab@2201: ab@2201: e1000_raise_mdi_clk(hw, &ctrl); ab@2201: e1000_lower_mdi_clk(hw, &ctrl); ab@2201: ab@2201: mask = mask >> 1; ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_shift_in_mdi_bits - Shifts data bits in from the PHY ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Bits are shifted in in MSB to LSB order. ab@2201: */ ab@2201: static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw) ab@2201: { ab@2201: u32 ctrl; ab@2201: u16 data = 0; ab@2201: u8 i; ab@2201: ab@2201: /* In order to read a register from the PHY, we need to shift in a total ab@2201: * of 18 bits from the PHY. The first two bit (turnaround) times are used ab@2201: * to avoid contention on the MDIO pin when a read operation is performed. ab@2201: * These two bits are ignored by us and thrown away. Bits are "shifted in" ab@2201: * by raising the input to the Management Data Clock (setting the MDC bit), ab@2201: * and then reading the value of the MDIO bit. ab@2201: */ ab@2201: ctrl = er32(CTRL); ab@2201: ab@2201: /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */ ab@2201: ctrl &= ~E1000_CTRL_MDIO_DIR; ab@2201: ctrl &= ~E1000_CTRL_MDIO; ab@2201: ab@2201: ew32(CTRL, ctrl); ab@2201: E1000_WRITE_FLUSH(); ab@2201: ab@2201: /* Raise and Lower the clock before reading in the data. This accounts for ab@2201: * the turnaround bits. The first clock occurred when we clocked out the ab@2201: * last bit of the Register Address. ab@2201: */ ab@2201: e1000_raise_mdi_clk(hw, &ctrl); ab@2201: e1000_lower_mdi_clk(hw, &ctrl); ab@2201: ab@2201: for (data = 0, i = 0; i < 16; i++) { ab@2201: data = data << 1; ab@2201: e1000_raise_mdi_clk(hw, &ctrl); ab@2201: ctrl = er32(CTRL); ab@2201: /* Check to see if we shifted in a "1". */ ab@2201: if (ctrl & E1000_CTRL_MDIO) ab@2201: data |= 1; ab@2201: e1000_lower_mdi_clk(hw, &ctrl); ab@2201: } ab@2201: ab@2201: e1000_raise_mdi_clk(hw, &ctrl); ab@2201: e1000_lower_mdi_clk(hw, &ctrl); ab@2201: ab@2201: return data; ab@2201: } ab@2201: ab@2201: ab@2201: /** ab@2201: * e1000_read_phy_reg - read a phy register ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @reg_addr: address of the PHY register to read ab@2201: * ab@2201: * Reads the value from a PHY register, if the value is on a specific non zero ab@2201: * page, sets the page first. ab@2201: */ ab@2201: s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data) ab@2201: { ab@2201: u32 ret_val; ab@2201: ab@2201: DEBUGFUNC("e1000_read_phy_reg"); ab@2201: ab@2201: if ((hw->phy_type == e1000_phy_igp) && ab@2201: (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { ab@2201: ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, ab@2201: (u16) reg_addr); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, ab@2201: phy_data); ab@2201: ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, ab@2201: u16 *phy_data) ab@2201: { ab@2201: u32 i; ab@2201: u32 mdic = 0; ab@2201: const u32 phy_addr = 1; ab@2201: ab@2201: DEBUGFUNC("e1000_read_phy_reg_ex"); ab@2201: ab@2201: if (reg_addr > MAX_PHY_REG_ADDRESS) { ab@2201: DEBUGOUT1("PHY Address %d is out of range\n", reg_addr); ab@2201: return -E1000_ERR_PARAM; ab@2201: } ab@2201: ab@2201: if (hw->mac_type > e1000_82543) { ab@2201: /* Set up Op-code, Phy Address, and register address in the MDI ab@2201: * Control register. The MAC will take care of interfacing with the ab@2201: * PHY to retrieve the desired data. ab@2201: */ ab@2201: mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) | ab@2201: (phy_addr << E1000_MDIC_PHY_SHIFT) | ab@2201: (E1000_MDIC_OP_READ)); ab@2201: ab@2201: ew32(MDIC, mdic); ab@2201: ab@2201: /* Poll the ready bit to see if the MDI read completed */ ab@2201: for (i = 0; i < 64; i++) { ab@2201: udelay(50); ab@2201: mdic = er32(MDIC); ab@2201: if (mdic & E1000_MDIC_READY) ab@2201: break; ab@2201: } ab@2201: if (!(mdic & E1000_MDIC_READY)) { ab@2201: DEBUGOUT("MDI Read did not complete\n"); ab@2201: return -E1000_ERR_PHY; ab@2201: } ab@2201: if (mdic & E1000_MDIC_ERROR) { ab@2201: DEBUGOUT("MDI Error\n"); ab@2201: return -E1000_ERR_PHY; ab@2201: } ab@2201: *phy_data = (u16) mdic; ab@2201: } else { ab@2201: /* We must first send a preamble through the MDIO pin to signal the ab@2201: * beginning of an MII instruction. This is done by sending 32 ab@2201: * consecutive "1" bits. ab@2201: */ ab@2201: e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); ab@2201: ab@2201: /* Now combine the next few fields that are required for a read ab@2201: * operation. We use this method instead of calling the ab@2201: * e1000_shift_out_mdi_bits routine five different times. The format of ab@2201: * a MII read instruction consists of a shift out of 14 bits and is ab@2201: * defined as follows: ab@2201: * ab@2201: * followed by a shift in of 18 bits. This first two bits shifted in ab@2201: * are TurnAround bits used to avoid contention on the MDIO pin when a ab@2201: * READ operation is performed. These two bits are thrown away ab@2201: * followed by a shift in of 16 bits which contains the desired data. ab@2201: */ ab@2201: mdic = ((reg_addr) | (phy_addr << 5) | ab@2201: (PHY_OP_READ << 10) | (PHY_SOF << 12)); ab@2201: ab@2201: e1000_shift_out_mdi_bits(hw, mdic, 14); ab@2201: ab@2201: /* Now that we've shifted out the read command to the MII, we need to ab@2201: * "shift in" the 16-bit value (18 total bits) of the requested PHY ab@2201: * register address. ab@2201: */ ab@2201: *phy_data = e1000_shift_in_mdi_bits(hw); ab@2201: } ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_write_phy_reg - write a phy register ab@2201: * ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @reg_addr: address of the PHY register to write ab@2201: * @data: data to write to the PHY ab@2201: ab@2201: * Writes a value to a PHY register ab@2201: */ ab@2201: s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data) ab@2201: { ab@2201: u32 ret_val; ab@2201: ab@2201: DEBUGFUNC("e1000_write_phy_reg"); ab@2201: ab@2201: if ((hw->phy_type == e1000_phy_igp) && ab@2201: (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { ab@2201: ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, ab@2201: (u16) reg_addr); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, ab@2201: phy_data); ab@2201: ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, ab@2201: u16 phy_data) ab@2201: { ab@2201: u32 i; ab@2201: u32 mdic = 0; ab@2201: const u32 phy_addr = 1; ab@2201: ab@2201: DEBUGFUNC("e1000_write_phy_reg_ex"); ab@2201: ab@2201: if (reg_addr > MAX_PHY_REG_ADDRESS) { ab@2201: DEBUGOUT1("PHY Address %d is out of range\n", reg_addr); ab@2201: return -E1000_ERR_PARAM; ab@2201: } ab@2201: ab@2201: if (hw->mac_type > e1000_82543) { ab@2201: /* Set up Op-code, Phy Address, register address, and data intended ab@2201: * for the PHY register in the MDI Control register. The MAC will take ab@2201: * care of interfacing with the PHY to send the desired data. ab@2201: */ ab@2201: mdic = (((u32) phy_data) | ab@2201: (reg_addr << E1000_MDIC_REG_SHIFT) | ab@2201: (phy_addr << E1000_MDIC_PHY_SHIFT) | ab@2201: (E1000_MDIC_OP_WRITE)); ab@2201: ab@2201: ew32(MDIC, mdic); ab@2201: ab@2201: /* Poll the ready bit to see if the MDI read completed */ ab@2201: for (i = 0; i < 641; i++) { ab@2201: udelay(5); ab@2201: mdic = er32(MDIC); ab@2201: if (mdic & E1000_MDIC_READY) ab@2201: break; ab@2201: } ab@2201: if (!(mdic & E1000_MDIC_READY)) { ab@2201: DEBUGOUT("MDI Write did not complete\n"); ab@2201: return -E1000_ERR_PHY; ab@2201: } ab@2201: } else { ab@2201: /* We'll need to use the SW defined pins to shift the write command ab@2201: * out to the PHY. We first send a preamble to the PHY to signal the ab@2201: * beginning of the MII instruction. This is done by sending 32 ab@2201: * consecutive "1" bits. ab@2201: */ ab@2201: e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); ab@2201: ab@2201: /* Now combine the remaining required fields that will indicate a ab@2201: * write operation. We use this method instead of calling the ab@2201: * e1000_shift_out_mdi_bits routine for each field in the command. The ab@2201: * format of a MII write instruction is as follows: ab@2201: * . ab@2201: */ ab@2201: mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) | ab@2201: (PHY_OP_WRITE << 12) | (PHY_SOF << 14)); ab@2201: mdic <<= 16; ab@2201: mdic |= (u32) phy_data; ab@2201: ab@2201: e1000_shift_out_mdi_bits(hw, mdic, 32); ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_phy_hw_reset - reset the phy, hardware style ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Returns the PHY to the power-on reset state ab@2201: */ ab@2201: s32 e1000_phy_hw_reset(struct e1000_hw *hw) ab@2201: { ab@2201: u32 ctrl, ctrl_ext; ab@2201: u32 led_ctrl; ab@2201: s32 ret_val; ab@2201: ab@2201: DEBUGFUNC("e1000_phy_hw_reset"); ab@2201: ab@2201: DEBUGOUT("Resetting Phy...\n"); ab@2201: ab@2201: if (hw->mac_type > e1000_82543) { ab@2201: /* Read the device control register and assert the E1000_CTRL_PHY_RST ab@2201: * bit. Then, take it out of reset. ab@2201: * For e1000 hardware, we delay for 10ms between the assert ab@2201: * and deassert. ab@2201: */ ab@2201: ctrl = er32(CTRL); ab@2201: ew32(CTRL, ctrl | E1000_CTRL_PHY_RST); ab@2201: E1000_WRITE_FLUSH(); ab@2201: ab@2201: msleep(10); ab@2201: ab@2201: ew32(CTRL, ctrl); ab@2201: E1000_WRITE_FLUSH(); ab@2201: ab@2201: } else { ab@2201: /* Read the Extended Device Control Register, assert the PHY_RESET_DIR ab@2201: * bit to put the PHY into reset. Then, take it out of reset. ab@2201: */ ab@2201: ctrl_ext = er32(CTRL_EXT); ab@2201: ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR; ab@2201: ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA; ab@2201: ew32(CTRL_EXT, ctrl_ext); ab@2201: E1000_WRITE_FLUSH(); ab@2201: msleep(10); ab@2201: ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA; ab@2201: ew32(CTRL_EXT, ctrl_ext); ab@2201: E1000_WRITE_FLUSH(); ab@2201: } ab@2201: udelay(150); ab@2201: ab@2201: if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { ab@2201: /* Configure activity LED after PHY reset */ ab@2201: led_ctrl = er32(LEDCTL); ab@2201: led_ctrl &= IGP_ACTIVITY_LED_MASK; ab@2201: led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); ab@2201: ew32(LEDCTL, led_ctrl); ab@2201: } ab@2201: ab@2201: /* Wait for FW to finish PHY configuration. */ ab@2201: ret_val = e1000_get_phy_cfg_done(hw); ab@2201: if (ret_val != E1000_SUCCESS) ab@2201: return ret_val; ab@2201: ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_phy_reset - reset the phy to commit settings ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Resets the PHY ab@2201: * Sets bit 15 of the MII Control register ab@2201: */ ab@2201: s32 e1000_phy_reset(struct e1000_hw *hw) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 phy_data; ab@2201: ab@2201: DEBUGFUNC("e1000_phy_reset"); ab@2201: ab@2201: switch (hw->phy_type) { ab@2201: case e1000_phy_igp: ab@2201: ret_val = e1000_phy_hw_reset(hw); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: break; ab@2201: default: ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_data |= MII_CR_RESET; ab@2201: ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: udelay(1); ab@2201: break; ab@2201: } ab@2201: ab@2201: if (hw->phy_type == e1000_phy_igp) ab@2201: e1000_phy_init_script(hw); ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_detect_gig_phy - check the phy type ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Probes the expected PHY address for known PHY IDs ab@2201: */ ab@2201: static s32 e1000_detect_gig_phy(struct e1000_hw *hw) ab@2201: { ab@2201: s32 phy_init_status, ret_val; ab@2201: u16 phy_id_high, phy_id_low; ab@2201: bool match = false; ab@2201: ab@2201: DEBUGFUNC("e1000_detect_gig_phy"); ab@2201: ab@2201: if (hw->phy_id != 0) ab@2201: return E1000_SUCCESS; ab@2201: ab@2201: /* Read the PHY ID Registers to identify which PHY is onboard. */ ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: hw->phy_id = (u32) (phy_id_high << 16); ab@2201: udelay(20); ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: hw->phy_id |= (u32) (phy_id_low & PHY_REVISION_MASK); ab@2201: hw->phy_revision = (u32) phy_id_low & ~PHY_REVISION_MASK; ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82543: ab@2201: if (hw->phy_id == M88E1000_E_PHY_ID) ab@2201: match = true; ab@2201: break; ab@2201: case e1000_82544: ab@2201: if (hw->phy_id == M88E1000_I_PHY_ID) ab@2201: match = true; ab@2201: break; ab@2201: case e1000_82540: ab@2201: case e1000_82545: ab@2201: case e1000_82545_rev_3: ab@2201: case e1000_82546: ab@2201: case e1000_82546_rev_3: ab@2201: if (hw->phy_id == M88E1011_I_PHY_ID) ab@2201: match = true; ab@2201: break; ab@2201: case e1000_82541: ab@2201: case e1000_82541_rev_2: ab@2201: case e1000_82547: ab@2201: case e1000_82547_rev_2: ab@2201: if (hw->phy_id == IGP01E1000_I_PHY_ID) ab@2201: match = true; ab@2201: break; ab@2201: default: ab@2201: DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type); ab@2201: return -E1000_ERR_CONFIG; ab@2201: } ab@2201: phy_init_status = e1000_set_phy_type(hw); ab@2201: ab@2201: if ((match) && (phy_init_status == E1000_SUCCESS)) { ab@2201: DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id); ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id); ab@2201: return -E1000_ERR_PHY; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_phy_reset_dsp - reset DSP ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Resets the PHY's DSP ab@2201: */ ab@2201: static s32 e1000_phy_reset_dsp(struct e1000_hw *hw) ab@2201: { ab@2201: s32 ret_val; ab@2201: DEBUGFUNC("e1000_phy_reset_dsp"); ab@2201: ab@2201: do { ab@2201: ret_val = e1000_write_phy_reg(hw, 29, 0x001d); ab@2201: if (ret_val) ab@2201: break; ab@2201: ret_val = e1000_write_phy_reg(hw, 30, 0x00c1); ab@2201: if (ret_val) ab@2201: break; ab@2201: ret_val = e1000_write_phy_reg(hw, 30, 0x0000); ab@2201: if (ret_val) ab@2201: break; ab@2201: ret_val = E1000_SUCCESS; ab@2201: } while (0); ab@2201: ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_phy_igp_get_info - get igp specific registers ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @phy_info: PHY information structure ab@2201: * ab@2201: * Get PHY information from various PHY registers for igp PHY only. ab@2201: */ ab@2201: static s32 e1000_phy_igp_get_info(struct e1000_hw *hw, ab@2201: struct e1000_phy_info *phy_info) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 phy_data, min_length, max_length, average; ab@2201: e1000_rev_polarity polarity; ab@2201: ab@2201: DEBUGFUNC("e1000_phy_igp_get_info"); ab@2201: ab@2201: /* The downshift status is checked only once, after link is established, ab@2201: * and it stored in the hw->speed_downgraded parameter. */ ab@2201: phy_info->downshift = (e1000_downshift) hw->speed_downgraded; ab@2201: ab@2201: /* IGP01E1000 does not need to support it. */ ab@2201: phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal; ab@2201: ab@2201: /* IGP01E1000 always correct polarity reversal */ ab@2201: phy_info->polarity_correction = e1000_polarity_reversal_enabled; ab@2201: ab@2201: /* Check polarity status */ ab@2201: ret_val = e1000_check_polarity(hw, &polarity); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_info->cable_polarity = polarity; ab@2201: ab@2201: ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_info->mdix_mode = ab@2201: (e1000_auto_x_mode) ((phy_data & IGP01E1000_PSSR_MDIX) >> ab@2201: IGP01E1000_PSSR_MDIX_SHIFT); ab@2201: ab@2201: if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == ab@2201: IGP01E1000_PSSR_SPEED_1000MBPS) { ab@2201: /* Local/Remote Receiver Information are only valid at 1000 Mbps */ ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> ab@2201: SR_1000T_LOCAL_RX_STATUS_SHIFT) ? ab@2201: e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; ab@2201: phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> ab@2201: SR_1000T_REMOTE_RX_STATUS_SHIFT) ? ab@2201: e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; ab@2201: ab@2201: /* Get cable length */ ab@2201: ret_val = e1000_get_cable_length(hw, &min_length, &max_length); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* Translate to old method */ ab@2201: average = (max_length + min_length) / 2; ab@2201: ab@2201: if (average <= e1000_igp_cable_length_50) ab@2201: phy_info->cable_length = e1000_cable_length_50; ab@2201: else if (average <= e1000_igp_cable_length_80) ab@2201: phy_info->cable_length = e1000_cable_length_50_80; ab@2201: else if (average <= e1000_igp_cable_length_110) ab@2201: phy_info->cable_length = e1000_cable_length_80_110; ab@2201: else if (average <= e1000_igp_cable_length_140) ab@2201: phy_info->cable_length = e1000_cable_length_110_140; ab@2201: else ab@2201: phy_info->cable_length = e1000_cable_length_140; ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_phy_m88_get_info - get m88 specific registers ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @phy_info: PHY information structure ab@2201: * ab@2201: * Get PHY information from various PHY registers for m88 PHY only. ab@2201: */ ab@2201: static s32 e1000_phy_m88_get_info(struct e1000_hw *hw, ab@2201: struct e1000_phy_info *phy_info) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 phy_data; ab@2201: e1000_rev_polarity polarity; ab@2201: ab@2201: DEBUGFUNC("e1000_phy_m88_get_info"); ab@2201: ab@2201: /* The downshift status is checked only once, after link is established, ab@2201: * and it stored in the hw->speed_downgraded parameter. */ ab@2201: phy_info->downshift = (e1000_downshift) hw->speed_downgraded; ab@2201: ab@2201: ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_info->extended_10bt_distance = ab@2201: ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >> ab@2201: M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ? ab@2201: e1000_10bt_ext_dist_enable_lower : ab@2201: e1000_10bt_ext_dist_enable_normal; ab@2201: ab@2201: phy_info->polarity_correction = ab@2201: ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >> ab@2201: M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ? ab@2201: e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled; ab@2201: ab@2201: /* Check polarity status */ ab@2201: ret_val = e1000_check_polarity(hw, &polarity); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: phy_info->cable_polarity = polarity; ab@2201: ab@2201: ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_info->mdix_mode = ab@2201: (e1000_auto_x_mode) ((phy_data & M88E1000_PSSR_MDIX) >> ab@2201: M88E1000_PSSR_MDIX_SHIFT); ab@2201: ab@2201: if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) { ab@2201: /* Cable Length Estimation and Local/Remote Receiver Information ab@2201: * are only valid at 1000 Mbps. ab@2201: */ ab@2201: phy_info->cable_length = ab@2201: (e1000_cable_length) ((phy_data & ab@2201: M88E1000_PSSR_CABLE_LENGTH) >> ab@2201: M88E1000_PSSR_CABLE_LENGTH_SHIFT); ab@2201: ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> ab@2201: SR_1000T_LOCAL_RX_STATUS_SHIFT) ? ab@2201: e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; ab@2201: phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> ab@2201: SR_1000T_REMOTE_RX_STATUS_SHIFT) ? ab@2201: e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; ab@2201: ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_phy_get_info - request phy info ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @phy_info: PHY information structure ab@2201: * ab@2201: * Get PHY information from various PHY registers ab@2201: */ ab@2201: s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 phy_data; ab@2201: ab@2201: DEBUGFUNC("e1000_phy_get_info"); ab@2201: ab@2201: phy_info->cable_length = e1000_cable_length_undefined; ab@2201: phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined; ab@2201: phy_info->cable_polarity = e1000_rev_polarity_undefined; ab@2201: phy_info->downshift = e1000_downshift_undefined; ab@2201: phy_info->polarity_correction = e1000_polarity_reversal_undefined; ab@2201: phy_info->mdix_mode = e1000_auto_x_mode_undefined; ab@2201: phy_info->local_rx = e1000_1000t_rx_status_undefined; ab@2201: phy_info->remote_rx = e1000_1000t_rx_status_undefined; ab@2201: ab@2201: if (hw->media_type != e1000_media_type_copper) { ab@2201: DEBUGOUT("PHY info is only valid for copper media\n"); ab@2201: return -E1000_ERR_CONFIG; ab@2201: } ab@2201: ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) { ab@2201: DEBUGOUT("PHY info is only valid if link is up\n"); ab@2201: return -E1000_ERR_CONFIG; ab@2201: } ab@2201: ab@2201: if (hw->phy_type == e1000_phy_igp) ab@2201: return e1000_phy_igp_get_info(hw, phy_info); ab@2201: else ab@2201: return e1000_phy_m88_get_info(hw, phy_info); ab@2201: } ab@2201: ab@2201: s32 e1000_validate_mdi_setting(struct e1000_hw *hw) ab@2201: { ab@2201: DEBUGFUNC("e1000_validate_mdi_settings"); ab@2201: ab@2201: if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) { ab@2201: DEBUGOUT("Invalid MDI setting detected\n"); ab@2201: hw->mdix = 1; ab@2201: return -E1000_ERR_CONFIG; ab@2201: } ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_init_eeprom_params - initialize sw eeprom vars ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Sets up eeprom variables in the hw struct. Must be called after mac_type ab@2201: * is configured. ab@2201: */ ab@2201: s32 e1000_init_eeprom_params(struct e1000_hw *hw) ab@2201: { ab@2201: struct e1000_eeprom_info *eeprom = &hw->eeprom; ab@2201: u32 eecd = er32(EECD); ab@2201: s32 ret_val = E1000_SUCCESS; ab@2201: u16 eeprom_size; ab@2201: ab@2201: DEBUGFUNC("e1000_init_eeprom_params"); ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82542_rev2_0: ab@2201: case e1000_82542_rev2_1: ab@2201: case e1000_82543: ab@2201: case e1000_82544: ab@2201: eeprom->type = e1000_eeprom_microwire; ab@2201: eeprom->word_size = 64; ab@2201: eeprom->opcode_bits = 3; ab@2201: eeprom->address_bits = 6; ab@2201: eeprom->delay_usec = 50; ab@2201: break; ab@2201: case e1000_82540: ab@2201: case e1000_82545: ab@2201: case e1000_82545_rev_3: ab@2201: case e1000_82546: ab@2201: case e1000_82546_rev_3: ab@2201: eeprom->type = e1000_eeprom_microwire; ab@2201: eeprom->opcode_bits = 3; ab@2201: eeprom->delay_usec = 50; ab@2201: if (eecd & E1000_EECD_SIZE) { ab@2201: eeprom->word_size = 256; ab@2201: eeprom->address_bits = 8; ab@2201: } else { ab@2201: eeprom->word_size = 64; ab@2201: eeprom->address_bits = 6; ab@2201: } ab@2201: break; ab@2201: case e1000_82541: ab@2201: case e1000_82541_rev_2: ab@2201: case e1000_82547: ab@2201: case e1000_82547_rev_2: ab@2201: if (eecd & E1000_EECD_TYPE) { ab@2201: eeprom->type = e1000_eeprom_spi; ab@2201: eeprom->opcode_bits = 8; ab@2201: eeprom->delay_usec = 1; ab@2201: if (eecd & E1000_EECD_ADDR_BITS) { ab@2201: eeprom->page_size = 32; ab@2201: eeprom->address_bits = 16; ab@2201: } else { ab@2201: eeprom->page_size = 8; ab@2201: eeprom->address_bits = 8; ab@2201: } ab@2201: } else { ab@2201: eeprom->type = e1000_eeprom_microwire; ab@2201: eeprom->opcode_bits = 3; ab@2201: eeprom->delay_usec = 50; ab@2201: if (eecd & E1000_EECD_ADDR_BITS) { ab@2201: eeprom->word_size = 256; ab@2201: eeprom->address_bits = 8; ab@2201: } else { ab@2201: eeprom->word_size = 64; ab@2201: eeprom->address_bits = 6; ab@2201: } ab@2201: } ab@2201: break; ab@2201: default: ab@2201: break; ab@2201: } ab@2201: ab@2201: if (eeprom->type == e1000_eeprom_spi) { ab@2201: /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to ab@2201: * 32KB (incremented by powers of 2). ab@2201: */ ab@2201: /* Set to default value for initial eeprom read. */ ab@2201: eeprom->word_size = 64; ab@2201: ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: eeprom_size = ab@2201: (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT; ab@2201: /* 256B eeprom size was not supported in earlier hardware, so we ab@2201: * bump eeprom_size up one to ensure that "1" (which maps to 256B) ab@2201: * is never the result used in the shifting logic below. */ ab@2201: if (eeprom_size) ab@2201: eeprom_size++; ab@2201: ab@2201: eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT); ab@2201: } ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_raise_ee_clk - Raises the EEPROM's clock input. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @eecd: EECD's current value ab@2201: */ ab@2201: static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd) ab@2201: { ab@2201: /* Raise the clock input to the EEPROM (by setting the SK bit), and then ab@2201: * wait microseconds. ab@2201: */ ab@2201: *eecd = *eecd | E1000_EECD_SK; ab@2201: ew32(EECD, *eecd); ab@2201: E1000_WRITE_FLUSH(); ab@2201: udelay(hw->eeprom.delay_usec); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_lower_ee_clk - Lowers the EEPROM's clock input. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @eecd: EECD's current value ab@2201: */ ab@2201: static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd) ab@2201: { ab@2201: /* Lower the clock input to the EEPROM (by clearing the SK bit), and then ab@2201: * wait 50 microseconds. ab@2201: */ ab@2201: *eecd = *eecd & ~E1000_EECD_SK; ab@2201: ew32(EECD, *eecd); ab@2201: E1000_WRITE_FLUSH(); ab@2201: udelay(hw->eeprom.delay_usec); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_shift_out_ee_bits - Shift data bits out to the EEPROM. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @data: data to send to the EEPROM ab@2201: * @count: number of bits to shift out ab@2201: */ ab@2201: static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count) ab@2201: { ab@2201: struct e1000_eeprom_info *eeprom = &hw->eeprom; ab@2201: u32 eecd; ab@2201: u32 mask; ab@2201: ab@2201: /* We need to shift "count" bits out to the EEPROM. So, value in the ab@2201: * "data" parameter will be shifted out to the EEPROM one bit at a time. ab@2201: * In order to do this, "data" must be broken down into bits. ab@2201: */ ab@2201: mask = 0x01 << (count - 1); ab@2201: eecd = er32(EECD); ab@2201: if (eeprom->type == e1000_eeprom_microwire) { ab@2201: eecd &= ~E1000_EECD_DO; ab@2201: } else if (eeprom->type == e1000_eeprom_spi) { ab@2201: eecd |= E1000_EECD_DO; ab@2201: } ab@2201: do { ab@2201: /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1", ab@2201: * and then raising and then lowering the clock (the SK bit controls ab@2201: * the clock input to the EEPROM). A "0" is shifted out to the EEPROM ab@2201: * by setting "DI" to "0" and then raising and then lowering the clock. ab@2201: */ ab@2201: eecd &= ~E1000_EECD_DI; ab@2201: ab@2201: if (data & mask) ab@2201: eecd |= E1000_EECD_DI; ab@2201: ab@2201: ew32(EECD, eecd); ab@2201: E1000_WRITE_FLUSH(); ab@2201: ab@2201: udelay(eeprom->delay_usec); ab@2201: ab@2201: e1000_raise_ee_clk(hw, &eecd); ab@2201: e1000_lower_ee_clk(hw, &eecd); ab@2201: ab@2201: mask = mask >> 1; ab@2201: ab@2201: } while (mask); ab@2201: ab@2201: /* We leave the "DI" bit set to "0" when we leave this routine. */ ab@2201: eecd &= ~E1000_EECD_DI; ab@2201: ew32(EECD, eecd); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_shift_in_ee_bits - Shift data bits in from the EEPROM ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @count: number of bits to shift in ab@2201: */ ab@2201: static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count) ab@2201: { ab@2201: u32 eecd; ab@2201: u32 i; ab@2201: u16 data; ab@2201: ab@2201: /* In order to read a register from the EEPROM, we need to shift 'count' ab@2201: * bits in from the EEPROM. Bits are "shifted in" by raising the clock ab@2201: * input to the EEPROM (setting the SK bit), and then reading the value of ab@2201: * the "DO" bit. During this "shifting in" process the "DI" bit should ab@2201: * always be clear. ab@2201: */ ab@2201: ab@2201: eecd = er32(EECD); ab@2201: ab@2201: eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); ab@2201: data = 0; ab@2201: ab@2201: for (i = 0; i < count; i++) { ab@2201: data = data << 1; ab@2201: e1000_raise_ee_clk(hw, &eecd); ab@2201: ab@2201: eecd = er32(EECD); ab@2201: ab@2201: eecd &= ~(E1000_EECD_DI); ab@2201: if (eecd & E1000_EECD_DO) ab@2201: data |= 1; ab@2201: ab@2201: e1000_lower_ee_clk(hw, &eecd); ab@2201: } ab@2201: ab@2201: return data; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_acquire_eeprom - Prepares EEPROM for access ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This ab@2201: * function should be called before issuing a command to the EEPROM. ab@2201: */ ab@2201: static s32 e1000_acquire_eeprom(struct e1000_hw *hw) ab@2201: { ab@2201: struct e1000_eeprom_info *eeprom = &hw->eeprom; ab@2201: u32 eecd, i = 0; ab@2201: ab@2201: DEBUGFUNC("e1000_acquire_eeprom"); ab@2201: ab@2201: eecd = er32(EECD); ab@2201: ab@2201: /* Request EEPROM Access */ ab@2201: if (hw->mac_type > e1000_82544) { ab@2201: eecd |= E1000_EECD_REQ; ab@2201: ew32(EECD, eecd); ab@2201: eecd = er32(EECD); ab@2201: while ((!(eecd & E1000_EECD_GNT)) && ab@2201: (i < E1000_EEPROM_GRANT_ATTEMPTS)) { ab@2201: i++; ab@2201: udelay(5); ab@2201: eecd = er32(EECD); ab@2201: } ab@2201: if (!(eecd & E1000_EECD_GNT)) { ab@2201: eecd &= ~E1000_EECD_REQ; ab@2201: ew32(EECD, eecd); ab@2201: DEBUGOUT("Could not acquire EEPROM grant\n"); ab@2201: return -E1000_ERR_EEPROM; ab@2201: } ab@2201: } ab@2201: ab@2201: /* Setup EEPROM for Read/Write */ ab@2201: ab@2201: if (eeprom->type == e1000_eeprom_microwire) { ab@2201: /* Clear SK and DI */ ab@2201: eecd &= ~(E1000_EECD_DI | E1000_EECD_SK); ab@2201: ew32(EECD, eecd); ab@2201: ab@2201: /* Set CS */ ab@2201: eecd |= E1000_EECD_CS; ab@2201: ew32(EECD, eecd); ab@2201: } else if (eeprom->type == e1000_eeprom_spi) { ab@2201: /* Clear SK and CS */ ab@2201: eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); ab@2201: ew32(EECD, eecd); ab@2201: udelay(1); ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_standby_eeprom - Returns EEPROM to a "standby" state ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: */ ab@2201: static void e1000_standby_eeprom(struct e1000_hw *hw) ab@2201: { ab@2201: struct e1000_eeprom_info *eeprom = &hw->eeprom; ab@2201: u32 eecd; ab@2201: ab@2201: eecd = er32(EECD); ab@2201: ab@2201: if (eeprom->type == e1000_eeprom_microwire) { ab@2201: eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); ab@2201: ew32(EECD, eecd); ab@2201: E1000_WRITE_FLUSH(); ab@2201: udelay(eeprom->delay_usec); ab@2201: ab@2201: /* Clock high */ ab@2201: eecd |= E1000_EECD_SK; ab@2201: ew32(EECD, eecd); ab@2201: E1000_WRITE_FLUSH(); ab@2201: udelay(eeprom->delay_usec); ab@2201: ab@2201: /* Select EEPROM */ ab@2201: eecd |= E1000_EECD_CS; ab@2201: ew32(EECD, eecd); ab@2201: E1000_WRITE_FLUSH(); ab@2201: udelay(eeprom->delay_usec); ab@2201: ab@2201: /* Clock low */ ab@2201: eecd &= ~E1000_EECD_SK; ab@2201: ew32(EECD, eecd); ab@2201: E1000_WRITE_FLUSH(); ab@2201: udelay(eeprom->delay_usec); ab@2201: } else if (eeprom->type == e1000_eeprom_spi) { ab@2201: /* Toggle CS to flush commands */ ab@2201: eecd |= E1000_EECD_CS; ab@2201: ew32(EECD, eecd); ab@2201: E1000_WRITE_FLUSH(); ab@2201: udelay(eeprom->delay_usec); ab@2201: eecd &= ~E1000_EECD_CS; ab@2201: ew32(EECD, eecd); ab@2201: E1000_WRITE_FLUSH(); ab@2201: udelay(eeprom->delay_usec); ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_release_eeprom - drop chip select ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Terminates a command by inverting the EEPROM's chip select pin ab@2201: */ ab@2201: static void e1000_release_eeprom(struct e1000_hw *hw) ab@2201: { ab@2201: u32 eecd; ab@2201: ab@2201: DEBUGFUNC("e1000_release_eeprom"); ab@2201: ab@2201: eecd = er32(EECD); ab@2201: ab@2201: if (hw->eeprom.type == e1000_eeprom_spi) { ab@2201: eecd |= E1000_EECD_CS; /* Pull CS high */ ab@2201: eecd &= ~E1000_EECD_SK; /* Lower SCK */ ab@2201: ab@2201: ew32(EECD, eecd); ab@2201: ab@2201: udelay(hw->eeprom.delay_usec); ab@2201: } else if (hw->eeprom.type == e1000_eeprom_microwire) { ab@2201: /* cleanup eeprom */ ab@2201: ab@2201: /* CS on Microwire is active-high */ ab@2201: eecd &= ~(E1000_EECD_CS | E1000_EECD_DI); ab@2201: ab@2201: ew32(EECD, eecd); ab@2201: ab@2201: /* Rising edge of clock */ ab@2201: eecd |= E1000_EECD_SK; ab@2201: ew32(EECD, eecd); ab@2201: E1000_WRITE_FLUSH(); ab@2201: udelay(hw->eeprom.delay_usec); ab@2201: ab@2201: /* Falling edge of clock */ ab@2201: eecd &= ~E1000_EECD_SK; ab@2201: ew32(EECD, eecd); ab@2201: E1000_WRITE_FLUSH(); ab@2201: udelay(hw->eeprom.delay_usec); ab@2201: } ab@2201: ab@2201: /* Stop requesting EEPROM access */ ab@2201: if (hw->mac_type > e1000_82544) { ab@2201: eecd &= ~E1000_EECD_REQ; ab@2201: ew32(EECD, eecd); ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_spi_eeprom_ready - Reads a 16 bit word from the EEPROM. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: */ ab@2201: static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw) ab@2201: { ab@2201: u16 retry_count = 0; ab@2201: u8 spi_stat_reg; ab@2201: ab@2201: DEBUGFUNC("e1000_spi_eeprom_ready"); ab@2201: ab@2201: /* Read "Status Register" repeatedly until the LSB is cleared. The ab@2201: * EEPROM will signal that the command has been completed by clearing ab@2201: * bit 0 of the internal status register. If it's not cleared within ab@2201: * 5 milliseconds, then error out. ab@2201: */ ab@2201: retry_count = 0; ab@2201: do { ab@2201: e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI, ab@2201: hw->eeprom.opcode_bits); ab@2201: spi_stat_reg = (u8) e1000_shift_in_ee_bits(hw, 8); ab@2201: if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI)) ab@2201: break; ab@2201: ab@2201: udelay(5); ab@2201: retry_count += 5; ab@2201: ab@2201: e1000_standby_eeprom(hw); ab@2201: } while (retry_count < EEPROM_MAX_RETRY_SPI); ab@2201: ab@2201: /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and ab@2201: * only 0-5mSec on 5V devices) ab@2201: */ ab@2201: if (retry_count >= EEPROM_MAX_RETRY_SPI) { ab@2201: DEBUGOUT("SPI EEPROM Status error\n"); ab@2201: return -E1000_ERR_EEPROM; ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_read_eeprom - Reads a 16 bit word from the EEPROM. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @offset: offset of word in the EEPROM to read ab@2201: * @data: word read from the EEPROM ab@2201: * @words: number of words to read ab@2201: */ ab@2201: s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) ab@2201: { ab@2201: s32 ret; ab@2201: spin_lock(&e1000_eeprom_lock); ab@2201: ret = e1000_do_read_eeprom(hw, offset, words, data); ab@2201: spin_unlock(&e1000_eeprom_lock); ab@2201: return ret; ab@2201: } ab@2201: ab@2201: static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, ab@2201: u16 *data) ab@2201: { ab@2201: struct e1000_eeprom_info *eeprom = &hw->eeprom; ab@2201: u32 i = 0; ab@2201: ab@2201: DEBUGFUNC("e1000_read_eeprom"); ab@2201: ab@2201: /* If eeprom is not yet detected, do so now */ ab@2201: if (eeprom->word_size == 0) ab@2201: e1000_init_eeprom_params(hw); ab@2201: ab@2201: /* A check for invalid values: offset too large, too many words, and not ab@2201: * enough words. ab@2201: */ ab@2201: if ((offset >= eeprom->word_size) ab@2201: || (words > eeprom->word_size - offset) || (words == 0)) { ab@2201: DEBUGOUT2 ab@2201: ("\"words\" parameter out of bounds. Words = %d, size = %d\n", ab@2201: offset, eeprom->word_size); ab@2201: return -E1000_ERR_EEPROM; ab@2201: } ab@2201: ab@2201: /* EEPROM's that don't use EERD to read require us to bit-bang the SPI ab@2201: * directly. In this case, we need to acquire the EEPROM so that ab@2201: * FW or other port software does not interrupt. ab@2201: */ ab@2201: /* Prepare the EEPROM for bit-bang reading */ ab@2201: if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) ab@2201: return -E1000_ERR_EEPROM; ab@2201: ab@2201: /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have ab@2201: * acquired the EEPROM at this point, so any returns should release it */ ab@2201: if (eeprom->type == e1000_eeprom_spi) { ab@2201: u16 word_in; ab@2201: u8 read_opcode = EEPROM_READ_OPCODE_SPI; ab@2201: ab@2201: if (e1000_spi_eeprom_ready(hw)) { ab@2201: e1000_release_eeprom(hw); ab@2201: return -E1000_ERR_EEPROM; ab@2201: } ab@2201: ab@2201: e1000_standby_eeprom(hw); ab@2201: ab@2201: /* Some SPI eeproms use the 8th address bit embedded in the opcode */ ab@2201: if ((eeprom->address_bits == 8) && (offset >= 128)) ab@2201: read_opcode |= EEPROM_A8_OPCODE_SPI; ab@2201: ab@2201: /* Send the READ command (opcode + addr) */ ab@2201: e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits); ab@2201: e1000_shift_out_ee_bits(hw, (u16) (offset * 2), ab@2201: eeprom->address_bits); ab@2201: ab@2201: /* Read the data. The address of the eeprom internally increments with ab@2201: * each byte (spi) being read, saving on the overhead of eeprom setup ab@2201: * and tear-down. The address counter will roll over if reading beyond ab@2201: * the size of the eeprom, thus allowing the entire memory to be read ab@2201: * starting from any offset. */ ab@2201: for (i = 0; i < words; i++) { ab@2201: word_in = e1000_shift_in_ee_bits(hw, 16); ab@2201: data[i] = (word_in >> 8) | (word_in << 8); ab@2201: } ab@2201: } else if (eeprom->type == e1000_eeprom_microwire) { ab@2201: for (i = 0; i < words; i++) { ab@2201: /* Send the READ command (opcode + addr) */ ab@2201: e1000_shift_out_ee_bits(hw, ab@2201: EEPROM_READ_OPCODE_MICROWIRE, ab@2201: eeprom->opcode_bits); ab@2201: e1000_shift_out_ee_bits(hw, (u16) (offset + i), ab@2201: eeprom->address_bits); ab@2201: ab@2201: /* Read the data. For microwire, each word requires the overhead ab@2201: * of eeprom setup and tear-down. */ ab@2201: data[i] = e1000_shift_in_ee_bits(hw, 16); ab@2201: e1000_standby_eeprom(hw); ab@2201: } ab@2201: } ab@2201: ab@2201: /* End this read operation */ ab@2201: e1000_release_eeprom(hw); ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_validate_eeprom_checksum - Verifies that the EEPROM has a valid checksum ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Reads the first 64 16 bit words of the EEPROM and sums the values read. ab@2201: * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is ab@2201: * valid. ab@2201: */ ab@2201: s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw) ab@2201: { ab@2201: u16 checksum = 0; ab@2201: u16 i, eeprom_data; ab@2201: ab@2201: DEBUGFUNC("e1000_validate_eeprom_checksum"); ab@2201: ab@2201: for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) { ab@2201: if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { ab@2201: DEBUGOUT("EEPROM Read Error\n"); ab@2201: return -E1000_ERR_EEPROM; ab@2201: } ab@2201: checksum += eeprom_data; ab@2201: } ab@2201: ab@2201: if (checksum == (u16) EEPROM_SUM) ab@2201: return E1000_SUCCESS; ab@2201: else { ab@2201: DEBUGOUT("EEPROM Checksum Invalid\n"); ab@2201: return -E1000_ERR_EEPROM; ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_update_eeprom_checksum - Calculates/writes the EEPROM checksum ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA. ab@2201: * Writes the difference to word offset 63 of the EEPROM. ab@2201: */ ab@2201: s32 e1000_update_eeprom_checksum(struct e1000_hw *hw) ab@2201: { ab@2201: u16 checksum = 0; ab@2201: u16 i, eeprom_data; ab@2201: ab@2201: DEBUGFUNC("e1000_update_eeprom_checksum"); ab@2201: ab@2201: for (i = 0; i < EEPROM_CHECKSUM_REG; i++) { ab@2201: if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { ab@2201: DEBUGOUT("EEPROM Read Error\n"); ab@2201: return -E1000_ERR_EEPROM; ab@2201: } ab@2201: checksum += eeprom_data; ab@2201: } ab@2201: checksum = (u16) EEPROM_SUM - checksum; ab@2201: if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) { ab@2201: DEBUGOUT("EEPROM Write Error\n"); ab@2201: return -E1000_ERR_EEPROM; ab@2201: } ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_write_eeprom - write words to the different EEPROM types. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @offset: offset within the EEPROM to be written to ab@2201: * @words: number of words to write ab@2201: * @data: 16 bit word to be written to the EEPROM ab@2201: * ab@2201: * If e1000_update_eeprom_checksum is not called after this function, the ab@2201: * EEPROM will most likely contain an invalid checksum. ab@2201: */ ab@2201: s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) ab@2201: { ab@2201: s32 ret; ab@2201: spin_lock(&e1000_eeprom_lock); ab@2201: ret = e1000_do_write_eeprom(hw, offset, words, data); ab@2201: spin_unlock(&e1000_eeprom_lock); ab@2201: return ret; ab@2201: } ab@2201: ab@2201: static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, ab@2201: u16 *data) ab@2201: { ab@2201: struct e1000_eeprom_info *eeprom = &hw->eeprom; ab@2201: s32 status = 0; ab@2201: ab@2201: DEBUGFUNC("e1000_write_eeprom"); ab@2201: ab@2201: /* If eeprom is not yet detected, do so now */ ab@2201: if (eeprom->word_size == 0) ab@2201: e1000_init_eeprom_params(hw); ab@2201: ab@2201: /* A check for invalid values: offset too large, too many words, and not ab@2201: * enough words. ab@2201: */ ab@2201: if ((offset >= eeprom->word_size) ab@2201: || (words > eeprom->word_size - offset) || (words == 0)) { ab@2201: DEBUGOUT("\"words\" parameter out of bounds\n"); ab@2201: return -E1000_ERR_EEPROM; ab@2201: } ab@2201: ab@2201: /* Prepare the EEPROM for writing */ ab@2201: if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) ab@2201: return -E1000_ERR_EEPROM; ab@2201: ab@2201: if (eeprom->type == e1000_eeprom_microwire) { ab@2201: status = e1000_write_eeprom_microwire(hw, offset, words, data); ab@2201: } else { ab@2201: status = e1000_write_eeprom_spi(hw, offset, words, data); ab@2201: msleep(10); ab@2201: } ab@2201: ab@2201: /* Done with writing */ ab@2201: e1000_release_eeprom(hw); ab@2201: ab@2201: return status; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_write_eeprom_spi - Writes a 16 bit word to a given offset in an SPI EEPROM. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @offset: offset within the EEPROM to be written to ab@2201: * @words: number of words to write ab@2201: * @data: pointer to array of 8 bit words to be written to the EEPROM ab@2201: */ ab@2201: static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words, ab@2201: u16 *data) ab@2201: { ab@2201: struct e1000_eeprom_info *eeprom = &hw->eeprom; ab@2201: u16 widx = 0; ab@2201: ab@2201: DEBUGFUNC("e1000_write_eeprom_spi"); ab@2201: ab@2201: while (widx < words) { ab@2201: u8 write_opcode = EEPROM_WRITE_OPCODE_SPI; ab@2201: ab@2201: if (e1000_spi_eeprom_ready(hw)) ab@2201: return -E1000_ERR_EEPROM; ab@2201: ab@2201: e1000_standby_eeprom(hw); ab@2201: ab@2201: /* Send the WRITE ENABLE command (8 bit opcode ) */ ab@2201: e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI, ab@2201: eeprom->opcode_bits); ab@2201: ab@2201: e1000_standby_eeprom(hw); ab@2201: ab@2201: /* Some SPI eeproms use the 8th address bit embedded in the opcode */ ab@2201: if ((eeprom->address_bits == 8) && (offset >= 128)) ab@2201: write_opcode |= EEPROM_A8_OPCODE_SPI; ab@2201: ab@2201: /* Send the Write command (8-bit opcode + addr) */ ab@2201: e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits); ab@2201: ab@2201: e1000_shift_out_ee_bits(hw, (u16) ((offset + widx) * 2), ab@2201: eeprom->address_bits); ab@2201: ab@2201: /* Send the data */ ab@2201: ab@2201: /* Loop to allow for up to whole page write (32 bytes) of eeprom */ ab@2201: while (widx < words) { ab@2201: u16 word_out = data[widx]; ab@2201: word_out = (word_out >> 8) | (word_out << 8); ab@2201: e1000_shift_out_ee_bits(hw, word_out, 16); ab@2201: widx++; ab@2201: ab@2201: /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE ab@2201: * operation, while the smaller eeproms are capable of an 8-byte ab@2201: * PAGE WRITE operation. Break the inner loop to pass new address ab@2201: */ ab@2201: if ((((offset + widx) * 2) % eeprom->page_size) == 0) { ab@2201: e1000_standby_eeprom(hw); ab@2201: break; ab@2201: } ab@2201: } ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_write_eeprom_microwire - Writes a 16 bit word to a given offset in a Microwire EEPROM. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @offset: offset within the EEPROM to be written to ab@2201: * @words: number of words to write ab@2201: * @data: pointer to array of 8 bit words to be written to the EEPROM ab@2201: */ ab@2201: static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset, ab@2201: u16 words, u16 *data) ab@2201: { ab@2201: struct e1000_eeprom_info *eeprom = &hw->eeprom; ab@2201: u32 eecd; ab@2201: u16 words_written = 0; ab@2201: u16 i = 0; ab@2201: ab@2201: DEBUGFUNC("e1000_write_eeprom_microwire"); ab@2201: ab@2201: /* Send the write enable command to the EEPROM (3-bit opcode plus ab@2201: * 6/8-bit dummy address beginning with 11). It's less work to include ab@2201: * the 11 of the dummy address as part of the opcode than it is to shift ab@2201: * it over the correct number of bits for the address. This puts the ab@2201: * EEPROM into write/erase mode. ab@2201: */ ab@2201: e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE, ab@2201: (u16) (eeprom->opcode_bits + 2)); ab@2201: ab@2201: e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2)); ab@2201: ab@2201: /* Prepare the EEPROM */ ab@2201: e1000_standby_eeprom(hw); ab@2201: ab@2201: while (words_written < words) { ab@2201: /* Send the Write command (3-bit opcode + addr) */ ab@2201: e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE, ab@2201: eeprom->opcode_bits); ab@2201: ab@2201: e1000_shift_out_ee_bits(hw, (u16) (offset + words_written), ab@2201: eeprom->address_bits); ab@2201: ab@2201: /* Send the data */ ab@2201: e1000_shift_out_ee_bits(hw, data[words_written], 16); ab@2201: ab@2201: /* Toggle the CS line. This in effect tells the EEPROM to execute ab@2201: * the previous command. ab@2201: */ ab@2201: e1000_standby_eeprom(hw); ab@2201: ab@2201: /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will ab@2201: * signal that the command has been completed by raising the DO signal. ab@2201: * If DO does not go high in 10 milliseconds, then error out. ab@2201: */ ab@2201: for (i = 0; i < 200; i++) { ab@2201: eecd = er32(EECD); ab@2201: if (eecd & E1000_EECD_DO) ab@2201: break; ab@2201: udelay(50); ab@2201: } ab@2201: if (i == 200) { ab@2201: DEBUGOUT("EEPROM Write did not complete\n"); ab@2201: return -E1000_ERR_EEPROM; ab@2201: } ab@2201: ab@2201: /* Recover from write */ ab@2201: e1000_standby_eeprom(hw); ab@2201: ab@2201: words_written++; ab@2201: } ab@2201: ab@2201: /* Send the write disable command to the EEPROM (3-bit opcode plus ab@2201: * 6/8-bit dummy address beginning with 10). It's less work to include ab@2201: * the 10 of the dummy address as part of the opcode than it is to shift ab@2201: * it over the correct number of bits for the address. This takes the ab@2201: * EEPROM out of write/erase mode. ab@2201: */ ab@2201: e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE, ab@2201: (u16) (eeprom->opcode_bits + 2)); ab@2201: ab@2201: e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2)); ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_read_mac_addr - read the adapters MAC from eeprom ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the ab@2201: * second function of dual function devices ab@2201: */ ab@2201: s32 e1000_read_mac_addr(struct e1000_hw *hw) ab@2201: { ab@2201: u16 offset; ab@2201: u16 eeprom_data, i; ab@2201: ab@2201: DEBUGFUNC("e1000_read_mac_addr"); ab@2201: ab@2201: for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) { ab@2201: offset = i >> 1; ab@2201: if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) { ab@2201: DEBUGOUT("EEPROM Read Error\n"); ab@2201: return -E1000_ERR_EEPROM; ab@2201: } ab@2201: hw->perm_mac_addr[i] = (u8) (eeprom_data & 0x00FF); ab@2201: hw->perm_mac_addr[i + 1] = (u8) (eeprom_data >> 8); ab@2201: } ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: default: ab@2201: break; ab@2201: case e1000_82546: ab@2201: case e1000_82546_rev_3: ab@2201: if (er32(STATUS) & E1000_STATUS_FUNC_1) ab@2201: hw->perm_mac_addr[5] ^= 0x01; ab@2201: break; ab@2201: } ab@2201: ab@2201: for (i = 0; i < NODE_ADDRESS_SIZE; i++) ab@2201: hw->mac_addr[i] = hw->perm_mac_addr[i]; ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_init_rx_addrs - Initializes receive address filters. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Places the MAC address in receive address register 0 and clears the rest ab@2201: * of the receive address registers. Clears the multicast table. Assumes ab@2201: * the receiver is in reset when the routine is called. ab@2201: */ ab@2201: static void e1000_init_rx_addrs(struct e1000_hw *hw) ab@2201: { ab@2201: u32 i; ab@2201: u32 rar_num; ab@2201: ab@2201: DEBUGFUNC("e1000_init_rx_addrs"); ab@2201: ab@2201: /* Setup the receive address. */ ab@2201: DEBUGOUT("Programming MAC Address into RAR[0]\n"); ab@2201: ab@2201: e1000_rar_set(hw, hw->mac_addr, 0); ab@2201: ab@2201: rar_num = E1000_RAR_ENTRIES; ab@2201: ab@2201: /* Zero out the other 15 receive addresses. */ ab@2201: DEBUGOUT("Clearing RAR[1-15]\n"); ab@2201: for (i = 1; i < rar_num; i++) { ab@2201: E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0); ab@2201: E1000_WRITE_FLUSH(); ab@2201: E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0); ab@2201: E1000_WRITE_FLUSH(); ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_hash_mc_addr - Hashes an address to determine its location in the multicast table ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @mc_addr: the multicast address to hash ab@2201: */ ab@2201: u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr) ab@2201: { ab@2201: u32 hash_value = 0; ab@2201: ab@2201: /* The portion of the address that is used for the hash table is ab@2201: * determined by the mc_filter_type setting. ab@2201: */ ab@2201: switch (hw->mc_filter_type) { ab@2201: /* [0] [1] [2] [3] [4] [5] ab@2201: * 01 AA 00 12 34 56 ab@2201: * LSB MSB ab@2201: */ ab@2201: case 0: ab@2201: /* [47:36] i.e. 0x563 for above example address */ ab@2201: hash_value = ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4)); ab@2201: break; ab@2201: case 1: ab@2201: /* [46:35] i.e. 0xAC6 for above example address */ ab@2201: hash_value = ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5)); ab@2201: break; ab@2201: case 2: ab@2201: /* [45:34] i.e. 0x5D8 for above example address */ ab@2201: hash_value = ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6)); ab@2201: break; ab@2201: case 3: ab@2201: /* [43:32] i.e. 0x634 for above example address */ ab@2201: hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8)); ab@2201: break; ab@2201: } ab@2201: ab@2201: hash_value &= 0xFFF; ab@2201: return hash_value; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_rar_set - Puts an ethernet address into a receive address register. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @addr: Address to put into receive address register ab@2201: * @index: Receive address register to write ab@2201: */ ab@2201: void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index) ab@2201: { ab@2201: u32 rar_low, rar_high; ab@2201: ab@2201: /* HW expects these in little endian so we reverse the byte order ab@2201: * from network order (big endian) to little endian ab@2201: */ ab@2201: rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) | ab@2201: ((u32) addr[2] << 16) | ((u32) addr[3] << 24)); ab@2201: rar_high = ((u32) addr[4] | ((u32) addr[5] << 8)); ab@2201: ab@2201: /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx ab@2201: * unit hang. ab@2201: * ab@2201: * Description: ab@2201: * If there are any Rx frames queued up or otherwise present in the HW ab@2201: * before RSS is enabled, and then we enable RSS, the HW Rx unit will ab@2201: * hang. To work around this issue, we have to disable receives and ab@2201: * flush out all Rx frames before we enable RSS. To do so, we modify we ab@2201: * redirect all Rx traffic to manageability and then reset the HW. ab@2201: * This flushes away Rx frames, and (since the redirections to ab@2201: * manageability persists across resets) keeps new ones from coming in ab@2201: * while we work. Then, we clear the Address Valid AV bit for all MAC ab@2201: * addresses and undo the re-direction to manageability. ab@2201: * Now, frames are coming in again, but the MAC won't accept them, so ab@2201: * far so good. We now proceed to initialize RSS (if necessary) and ab@2201: * configure the Rx unit. Last, we re-enable the AV bits and continue ab@2201: * on our merry way. ab@2201: */ ab@2201: switch (hw->mac_type) { ab@2201: default: ab@2201: /* Indicate to hardware the Address is Valid. */ ab@2201: rar_high |= E1000_RAH_AV; ab@2201: break; ab@2201: } ab@2201: ab@2201: E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low); ab@2201: E1000_WRITE_FLUSH(); ab@2201: E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high); ab@2201: E1000_WRITE_FLUSH(); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_write_vfta - Writes a value to the specified offset in the VLAN filter table. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @offset: Offset in VLAN filer table to write ab@2201: * @value: Value to write into VLAN filter table ab@2201: */ ab@2201: void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value) ab@2201: { ab@2201: u32 temp; ab@2201: ab@2201: if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) { ab@2201: temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1)); ab@2201: E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); ab@2201: E1000_WRITE_FLUSH(); ab@2201: E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp); ab@2201: E1000_WRITE_FLUSH(); ab@2201: } else { ab@2201: E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); ab@2201: E1000_WRITE_FLUSH(); ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_clear_vfta - Clears the VLAN filer table ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: */ ab@2201: static void e1000_clear_vfta(struct e1000_hw *hw) ab@2201: { ab@2201: u32 offset; ab@2201: u32 vfta_value = 0; ab@2201: u32 vfta_offset = 0; ab@2201: u32 vfta_bit_in_reg = 0; ab@2201: ab@2201: for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) { ab@2201: /* If the offset we want to clear is the same offset of the ab@2201: * manageability VLAN ID, then clear all bits except that of the ab@2201: * manageability unit */ ab@2201: vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0; ab@2201: E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value); ab@2201: E1000_WRITE_FLUSH(); ab@2201: } ab@2201: } ab@2201: ab@2201: static s32 e1000_id_led_init(struct e1000_hw *hw) ab@2201: { ab@2201: u32 ledctl; ab@2201: const u32 ledctl_mask = 0x000000FF; ab@2201: const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON; ab@2201: const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF; ab@2201: u16 eeprom_data, i, temp; ab@2201: const u16 led_mask = 0x0F; ab@2201: ab@2201: DEBUGFUNC("e1000_id_led_init"); ab@2201: ab@2201: if (hw->mac_type < e1000_82540) { ab@2201: /* Nothing to do */ ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: ledctl = er32(LEDCTL); ab@2201: hw->ledctl_default = ledctl; ab@2201: hw->ledctl_mode1 = hw->ledctl_default; ab@2201: hw->ledctl_mode2 = hw->ledctl_default; ab@2201: ab@2201: if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) { ab@2201: DEBUGOUT("EEPROM Read Error\n"); ab@2201: return -E1000_ERR_EEPROM; ab@2201: } ab@2201: ab@2201: if ((eeprom_data == ID_LED_RESERVED_0000) || ab@2201: (eeprom_data == ID_LED_RESERVED_FFFF)) { ab@2201: eeprom_data = ID_LED_DEFAULT; ab@2201: } ab@2201: ab@2201: for (i = 0; i < 4; i++) { ab@2201: temp = (eeprom_data >> (i << 2)) & led_mask; ab@2201: switch (temp) { ab@2201: case ID_LED_ON1_DEF2: ab@2201: case ID_LED_ON1_ON2: ab@2201: case ID_LED_ON1_OFF2: ab@2201: hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); ab@2201: hw->ledctl_mode1 |= ledctl_on << (i << 3); ab@2201: break; ab@2201: case ID_LED_OFF1_DEF2: ab@2201: case ID_LED_OFF1_ON2: ab@2201: case ID_LED_OFF1_OFF2: ab@2201: hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); ab@2201: hw->ledctl_mode1 |= ledctl_off << (i << 3); ab@2201: break; ab@2201: default: ab@2201: /* Do nothing */ ab@2201: break; ab@2201: } ab@2201: switch (temp) { ab@2201: case ID_LED_DEF1_ON2: ab@2201: case ID_LED_ON1_ON2: ab@2201: case ID_LED_OFF1_ON2: ab@2201: hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); ab@2201: hw->ledctl_mode2 |= ledctl_on << (i << 3); ab@2201: break; ab@2201: case ID_LED_DEF1_OFF2: ab@2201: case ID_LED_ON1_OFF2: ab@2201: case ID_LED_OFF1_OFF2: ab@2201: hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); ab@2201: hw->ledctl_mode2 |= ledctl_off << (i << 3); ab@2201: break; ab@2201: default: ab@2201: /* Do nothing */ ab@2201: break; ab@2201: } ab@2201: } ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_setup_led ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Prepares SW controlable LED for use and saves the current state of the LED. ab@2201: */ ab@2201: s32 e1000_setup_led(struct e1000_hw *hw) ab@2201: { ab@2201: u32 ledctl; ab@2201: s32 ret_val = E1000_SUCCESS; ab@2201: ab@2201: DEBUGFUNC("e1000_setup_led"); ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82542_rev2_0: ab@2201: case e1000_82542_rev2_1: ab@2201: case e1000_82543: ab@2201: case e1000_82544: ab@2201: /* No setup necessary */ ab@2201: break; ab@2201: case e1000_82541: ab@2201: case e1000_82547: ab@2201: case e1000_82541_rev_2: ab@2201: case e1000_82547_rev_2: ab@2201: /* Turn off PHY Smart Power Down (if enabled) */ ab@2201: ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, ab@2201: &hw->phy_spd_default); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, ab@2201: (u16) (hw->phy_spd_default & ab@2201: ~IGP01E1000_GMII_SPD)); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: /* Fall Through */ ab@2201: default: ab@2201: if (hw->media_type == e1000_media_type_fiber) { ab@2201: ledctl = er32(LEDCTL); ab@2201: /* Save current LEDCTL settings */ ab@2201: hw->ledctl_default = ledctl; ab@2201: /* Turn off LED0 */ ab@2201: ledctl &= ~(E1000_LEDCTL_LED0_IVRT | ab@2201: E1000_LEDCTL_LED0_BLINK | ab@2201: E1000_LEDCTL_LED0_MODE_MASK); ab@2201: ledctl |= (E1000_LEDCTL_MODE_LED_OFF << ab@2201: E1000_LEDCTL_LED0_MODE_SHIFT); ab@2201: ew32(LEDCTL, ledctl); ab@2201: } else if (hw->media_type == e1000_media_type_copper) ab@2201: ew32(LEDCTL, hw->ledctl_mode1); ab@2201: break; ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_cleanup_led - Restores the saved state of the SW controlable LED. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: */ ab@2201: s32 e1000_cleanup_led(struct e1000_hw *hw) ab@2201: { ab@2201: s32 ret_val = E1000_SUCCESS; ab@2201: ab@2201: DEBUGFUNC("e1000_cleanup_led"); ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82542_rev2_0: ab@2201: case e1000_82542_rev2_1: ab@2201: case e1000_82543: ab@2201: case e1000_82544: ab@2201: /* No cleanup necessary */ ab@2201: break; ab@2201: case e1000_82541: ab@2201: case e1000_82547: ab@2201: case e1000_82541_rev_2: ab@2201: case e1000_82547_rev_2: ab@2201: /* Turn on PHY Smart Power Down (if previously enabled) */ ab@2201: ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, ab@2201: hw->phy_spd_default); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: /* Fall Through */ ab@2201: default: ab@2201: /* Restore LEDCTL settings */ ab@2201: ew32(LEDCTL, hw->ledctl_default); ab@2201: break; ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_led_on - Turns on the software controllable LED ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: */ ab@2201: s32 e1000_led_on(struct e1000_hw *hw) ab@2201: { ab@2201: u32 ctrl = er32(CTRL); ab@2201: ab@2201: DEBUGFUNC("e1000_led_on"); ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82542_rev2_0: ab@2201: case e1000_82542_rev2_1: ab@2201: case e1000_82543: ab@2201: /* Set SW Defineable Pin 0 to turn on the LED */ ab@2201: ctrl |= E1000_CTRL_SWDPIN0; ab@2201: ctrl |= E1000_CTRL_SWDPIO0; ab@2201: break; ab@2201: case e1000_82544: ab@2201: if (hw->media_type == e1000_media_type_fiber) { ab@2201: /* Set SW Defineable Pin 0 to turn on the LED */ ab@2201: ctrl |= E1000_CTRL_SWDPIN0; ab@2201: ctrl |= E1000_CTRL_SWDPIO0; ab@2201: } else { ab@2201: /* Clear SW Defineable Pin 0 to turn on the LED */ ab@2201: ctrl &= ~E1000_CTRL_SWDPIN0; ab@2201: ctrl |= E1000_CTRL_SWDPIO0; ab@2201: } ab@2201: break; ab@2201: default: ab@2201: if (hw->media_type == e1000_media_type_fiber) { ab@2201: /* Clear SW Defineable Pin 0 to turn on the LED */ ab@2201: ctrl &= ~E1000_CTRL_SWDPIN0; ab@2201: ctrl |= E1000_CTRL_SWDPIO0; ab@2201: } else if (hw->media_type == e1000_media_type_copper) { ab@2201: ew32(LEDCTL, hw->ledctl_mode2); ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: break; ab@2201: } ab@2201: ab@2201: ew32(CTRL, ctrl); ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_led_off - Turns off the software controllable LED ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: */ ab@2201: s32 e1000_led_off(struct e1000_hw *hw) ab@2201: { ab@2201: u32 ctrl = er32(CTRL); ab@2201: ab@2201: DEBUGFUNC("e1000_led_off"); ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82542_rev2_0: ab@2201: case e1000_82542_rev2_1: ab@2201: case e1000_82543: ab@2201: /* Clear SW Defineable Pin 0 to turn off the LED */ ab@2201: ctrl &= ~E1000_CTRL_SWDPIN0; ab@2201: ctrl |= E1000_CTRL_SWDPIO0; ab@2201: break; ab@2201: case e1000_82544: ab@2201: if (hw->media_type == e1000_media_type_fiber) { ab@2201: /* Clear SW Defineable Pin 0 to turn off the LED */ ab@2201: ctrl &= ~E1000_CTRL_SWDPIN0; ab@2201: ctrl |= E1000_CTRL_SWDPIO0; ab@2201: } else { ab@2201: /* Set SW Defineable Pin 0 to turn off the LED */ ab@2201: ctrl |= E1000_CTRL_SWDPIN0; ab@2201: ctrl |= E1000_CTRL_SWDPIO0; ab@2201: } ab@2201: break; ab@2201: default: ab@2201: if (hw->media_type == e1000_media_type_fiber) { ab@2201: /* Set SW Defineable Pin 0 to turn off the LED */ ab@2201: ctrl |= E1000_CTRL_SWDPIN0; ab@2201: ctrl |= E1000_CTRL_SWDPIO0; ab@2201: } else if (hw->media_type == e1000_media_type_copper) { ab@2201: ew32(LEDCTL, hw->ledctl_mode1); ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: break; ab@2201: } ab@2201: ab@2201: ew32(CTRL, ctrl); ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_clear_hw_cntrs - Clears all hardware statistics counters. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: */ ab@2201: static void e1000_clear_hw_cntrs(struct e1000_hw *hw) ab@2201: { ab@2201: volatile u32 temp; ab@2201: ab@2201: temp = er32(CRCERRS); ab@2201: temp = er32(SYMERRS); ab@2201: temp = er32(MPC); ab@2201: temp = er32(SCC); ab@2201: temp = er32(ECOL); ab@2201: temp = er32(MCC); ab@2201: temp = er32(LATECOL); ab@2201: temp = er32(COLC); ab@2201: temp = er32(DC); ab@2201: temp = er32(SEC); ab@2201: temp = er32(RLEC); ab@2201: temp = er32(XONRXC); ab@2201: temp = er32(XONTXC); ab@2201: temp = er32(XOFFRXC); ab@2201: temp = er32(XOFFTXC); ab@2201: temp = er32(FCRUC); ab@2201: ab@2201: temp = er32(PRC64); ab@2201: temp = er32(PRC127); ab@2201: temp = er32(PRC255); ab@2201: temp = er32(PRC511); ab@2201: temp = er32(PRC1023); ab@2201: temp = er32(PRC1522); ab@2201: ab@2201: temp = er32(GPRC); ab@2201: temp = er32(BPRC); ab@2201: temp = er32(MPRC); ab@2201: temp = er32(GPTC); ab@2201: temp = er32(GORCL); ab@2201: temp = er32(GORCH); ab@2201: temp = er32(GOTCL); ab@2201: temp = er32(GOTCH); ab@2201: temp = er32(RNBC); ab@2201: temp = er32(RUC); ab@2201: temp = er32(RFC); ab@2201: temp = er32(ROC); ab@2201: temp = er32(RJC); ab@2201: temp = er32(TORL); ab@2201: temp = er32(TORH); ab@2201: temp = er32(TOTL); ab@2201: temp = er32(TOTH); ab@2201: temp = er32(TPR); ab@2201: temp = er32(TPT); ab@2201: ab@2201: temp = er32(PTC64); ab@2201: temp = er32(PTC127); ab@2201: temp = er32(PTC255); ab@2201: temp = er32(PTC511); ab@2201: temp = er32(PTC1023); ab@2201: temp = er32(PTC1522); ab@2201: ab@2201: temp = er32(MPTC); ab@2201: temp = er32(BPTC); ab@2201: ab@2201: if (hw->mac_type < e1000_82543) ab@2201: return; ab@2201: ab@2201: temp = er32(ALGNERRC); ab@2201: temp = er32(RXERRC); ab@2201: temp = er32(TNCRS); ab@2201: temp = er32(CEXTERR); ab@2201: temp = er32(TSCTC); ab@2201: temp = er32(TSCTFC); ab@2201: ab@2201: if (hw->mac_type <= e1000_82544) ab@2201: return; ab@2201: ab@2201: temp = er32(MGTPRC); ab@2201: temp = er32(MGTPDC); ab@2201: temp = er32(MGTPTC); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_reset_adaptive - Resets Adaptive IFS to its default state. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Call this after e1000_init_hw. You may override the IFS defaults by setting ab@2201: * hw->ifs_params_forced to true. However, you must initialize hw-> ab@2201: * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio ab@2201: * before calling this function. ab@2201: */ ab@2201: void e1000_reset_adaptive(struct e1000_hw *hw) ab@2201: { ab@2201: DEBUGFUNC("e1000_reset_adaptive"); ab@2201: ab@2201: if (hw->adaptive_ifs) { ab@2201: if (!hw->ifs_params_forced) { ab@2201: hw->current_ifs_val = 0; ab@2201: hw->ifs_min_val = IFS_MIN; ab@2201: hw->ifs_max_val = IFS_MAX; ab@2201: hw->ifs_step_size = IFS_STEP; ab@2201: hw->ifs_ratio = IFS_RATIO; ab@2201: } ab@2201: hw->in_ifs_mode = false; ab@2201: ew32(AIT, 0); ab@2201: } else { ab@2201: DEBUGOUT("Not in Adaptive IFS mode!\n"); ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_update_adaptive - update adaptive IFS ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @tx_packets: Number of transmits since last callback ab@2201: * @total_collisions: Number of collisions since last callback ab@2201: * ab@2201: * Called during the callback/watchdog routine to update IFS value based on ab@2201: * the ratio of transmits to collisions. ab@2201: */ ab@2201: void e1000_update_adaptive(struct e1000_hw *hw) ab@2201: { ab@2201: DEBUGFUNC("e1000_update_adaptive"); ab@2201: ab@2201: if (hw->adaptive_ifs) { ab@2201: if ((hw->collision_delta *hw->ifs_ratio) > hw->tx_packet_delta) { ab@2201: if (hw->tx_packet_delta > MIN_NUM_XMITS) { ab@2201: hw->in_ifs_mode = true; ab@2201: if (hw->current_ifs_val < hw->ifs_max_val) { ab@2201: if (hw->current_ifs_val == 0) ab@2201: hw->current_ifs_val = ab@2201: hw->ifs_min_val; ab@2201: else ab@2201: hw->current_ifs_val += ab@2201: hw->ifs_step_size; ab@2201: ew32(AIT, hw->current_ifs_val); ab@2201: } ab@2201: } ab@2201: } else { ab@2201: if (hw->in_ifs_mode ab@2201: && (hw->tx_packet_delta <= MIN_NUM_XMITS)) { ab@2201: hw->current_ifs_val = 0; ab@2201: hw->in_ifs_mode = false; ab@2201: ew32(AIT, 0); ab@2201: } ab@2201: } ab@2201: } else { ab@2201: DEBUGOUT("Not in Adaptive IFS mode!\n"); ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_tbi_adjust_stats ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @frame_len: The length of the frame in question ab@2201: * @mac_addr: The Ethernet destination address of the frame in question ab@2201: * ab@2201: * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT ab@2201: */ ab@2201: void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats, ab@2201: u32 frame_len, u8 *mac_addr) ab@2201: { ab@2201: u64 carry_bit; ab@2201: ab@2201: /* First adjust the frame length. */ ab@2201: frame_len--; ab@2201: /* We need to adjust the statistics counters, since the hardware ab@2201: * counters overcount this packet as a CRC error and undercount ab@2201: * the packet as a good packet ab@2201: */ ab@2201: /* This packet should not be counted as a CRC error. */ ab@2201: stats->crcerrs--; ab@2201: /* This packet does count as a Good Packet Received. */ ab@2201: stats->gprc++; ab@2201: ab@2201: /* Adjust the Good Octets received counters */ ab@2201: carry_bit = 0x80000000 & stats->gorcl; ab@2201: stats->gorcl += frame_len; ab@2201: /* If the high bit of Gorcl (the low 32 bits of the Good Octets ab@2201: * Received Count) was one before the addition, ab@2201: * AND it is zero after, then we lost the carry out, ab@2201: * need to add one to Gorch (Good Octets Received Count High). ab@2201: * This could be simplified if all environments supported ab@2201: * 64-bit integers. ab@2201: */ ab@2201: if (carry_bit && ((stats->gorcl & 0x80000000) == 0)) ab@2201: stats->gorch++; ab@2201: /* Is this a broadcast or multicast? Check broadcast first, ab@2201: * since the test for a multicast frame will test positive on ab@2201: * a broadcast frame. ab@2201: */ ab@2201: if ((mac_addr[0] == (u8) 0xff) && (mac_addr[1] == (u8) 0xff)) ab@2201: /* Broadcast packet */ ab@2201: stats->bprc++; ab@2201: else if (*mac_addr & 0x01) ab@2201: /* Multicast packet */ ab@2201: stats->mprc++; ab@2201: ab@2201: if (frame_len == hw->max_frame_size) { ab@2201: /* In this case, the hardware has overcounted the number of ab@2201: * oversize frames. ab@2201: */ ab@2201: if (stats->roc > 0) ab@2201: stats->roc--; ab@2201: } ab@2201: ab@2201: /* Adjust the bin counters when the extra byte put the frame in the ab@2201: * wrong bin. Remember that the frame_len was adjusted above. ab@2201: */ ab@2201: if (frame_len == 64) { ab@2201: stats->prc64++; ab@2201: stats->prc127--; ab@2201: } else if (frame_len == 127) { ab@2201: stats->prc127++; ab@2201: stats->prc255--; ab@2201: } else if (frame_len == 255) { ab@2201: stats->prc255++; ab@2201: stats->prc511--; ab@2201: } else if (frame_len == 511) { ab@2201: stats->prc511++; ab@2201: stats->prc1023--; ab@2201: } else if (frame_len == 1023) { ab@2201: stats->prc1023++; ab@2201: stats->prc1522--; ab@2201: } else if (frame_len == 1522) { ab@2201: stats->prc1522++; ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_get_bus_info ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Gets the current PCI bus type, speed, and width of the hardware ab@2201: */ ab@2201: void e1000_get_bus_info(struct e1000_hw *hw) ab@2201: { ab@2201: u32 status; ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82542_rev2_0: ab@2201: case e1000_82542_rev2_1: ab@2201: hw->bus_type = e1000_bus_type_pci; ab@2201: hw->bus_speed = e1000_bus_speed_unknown; ab@2201: hw->bus_width = e1000_bus_width_unknown; ab@2201: break; ab@2201: default: ab@2201: status = er32(STATUS); ab@2201: hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ? ab@2201: e1000_bus_type_pcix : e1000_bus_type_pci; ab@2201: ab@2201: if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) { ab@2201: hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ? ab@2201: e1000_bus_speed_66 : e1000_bus_speed_120; ab@2201: } else if (hw->bus_type == e1000_bus_type_pci) { ab@2201: hw->bus_speed = (status & E1000_STATUS_PCI66) ? ab@2201: e1000_bus_speed_66 : e1000_bus_speed_33; ab@2201: } else { ab@2201: switch (status & E1000_STATUS_PCIX_SPEED) { ab@2201: case E1000_STATUS_PCIX_SPEED_66: ab@2201: hw->bus_speed = e1000_bus_speed_66; ab@2201: break; ab@2201: case E1000_STATUS_PCIX_SPEED_100: ab@2201: hw->bus_speed = e1000_bus_speed_100; ab@2201: break; ab@2201: case E1000_STATUS_PCIX_SPEED_133: ab@2201: hw->bus_speed = e1000_bus_speed_133; ab@2201: break; ab@2201: default: ab@2201: hw->bus_speed = e1000_bus_speed_reserved; ab@2201: break; ab@2201: } ab@2201: } ab@2201: hw->bus_width = (status & E1000_STATUS_BUS64) ? ab@2201: e1000_bus_width_64 : e1000_bus_width_32; ab@2201: break; ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_write_reg_io ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @offset: offset to write to ab@2201: * @value: value to write ab@2201: * ab@2201: * Writes a value to one of the devices registers using port I/O (as opposed to ab@2201: * memory mapped I/O). Only 82544 and newer devices support port I/O. ab@2201: */ ab@2201: static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value) ab@2201: { ab@2201: unsigned long io_addr = hw->io_base; ab@2201: unsigned long io_data = hw->io_base + 4; ab@2201: ab@2201: e1000_io_write(hw, io_addr, offset); ab@2201: e1000_io_write(hw, io_data, value); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_get_cable_length - Estimates the cable length. ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @min_length: The estimated minimum length ab@2201: * @max_length: The estimated maximum length ab@2201: * ab@2201: * returns: - E1000_ERR_XXX ab@2201: * E1000_SUCCESS ab@2201: * ab@2201: * This function always returns a ranged length (minimum & maximum). ab@2201: * So for M88 phy's, this function interprets the one value returned from the ab@2201: * register to the minimum and maximum range. ab@2201: * For IGP phy's, the function calculates the range by the AGC registers. ab@2201: */ ab@2201: static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length, ab@2201: u16 *max_length) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 agc_value = 0; ab@2201: u16 i, phy_data; ab@2201: u16 cable_length; ab@2201: ab@2201: DEBUGFUNC("e1000_get_cable_length"); ab@2201: ab@2201: *min_length = *max_length = 0; ab@2201: ab@2201: /* Use old method for Phy older than IGP */ ab@2201: if (hw->phy_type == e1000_phy_m88) { ab@2201: ab@2201: ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, ab@2201: &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >> ab@2201: M88E1000_PSSR_CABLE_LENGTH_SHIFT; ab@2201: ab@2201: /* Convert the enum value to ranged values */ ab@2201: switch (cable_length) { ab@2201: case e1000_cable_length_50: ab@2201: *min_length = 0; ab@2201: *max_length = e1000_igp_cable_length_50; ab@2201: break; ab@2201: case e1000_cable_length_50_80: ab@2201: *min_length = e1000_igp_cable_length_50; ab@2201: *max_length = e1000_igp_cable_length_80; ab@2201: break; ab@2201: case e1000_cable_length_80_110: ab@2201: *min_length = e1000_igp_cable_length_80; ab@2201: *max_length = e1000_igp_cable_length_110; ab@2201: break; ab@2201: case e1000_cable_length_110_140: ab@2201: *min_length = e1000_igp_cable_length_110; ab@2201: *max_length = e1000_igp_cable_length_140; ab@2201: break; ab@2201: case e1000_cable_length_140: ab@2201: *min_length = e1000_igp_cable_length_140; ab@2201: *max_length = e1000_igp_cable_length_170; ab@2201: break; ab@2201: default: ab@2201: return -E1000_ERR_PHY; ab@2201: break; ab@2201: } ab@2201: } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */ ab@2201: u16 cur_agc_value; ab@2201: u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE; ab@2201: u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = ab@2201: { IGP01E1000_PHY_AGC_A, ab@2201: IGP01E1000_PHY_AGC_B, ab@2201: IGP01E1000_PHY_AGC_C, ab@2201: IGP01E1000_PHY_AGC_D ab@2201: }; ab@2201: /* Read the AGC registers for all channels */ ab@2201: for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { ab@2201: ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT; ab@2201: ab@2201: /* Value bound check. */ ab@2201: if ((cur_agc_value >= ab@2201: IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ab@2201: || (cur_agc_value == 0)) ab@2201: return -E1000_ERR_PHY; ab@2201: ab@2201: agc_value += cur_agc_value; ab@2201: ab@2201: /* Update minimal AGC value. */ ab@2201: if (min_agc_value > cur_agc_value) ab@2201: min_agc_value = cur_agc_value; ab@2201: } ab@2201: ab@2201: /* Remove the minimal AGC result for length < 50m */ ab@2201: if (agc_value < ab@2201: IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) { ab@2201: agc_value -= min_agc_value; ab@2201: ab@2201: /* Get the average length of the remaining 3 channels */ ab@2201: agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1); ab@2201: } else { ab@2201: /* Get the average length of all the 4 channels. */ ab@2201: agc_value /= IGP01E1000_PHY_CHANNEL_NUM; ab@2201: } ab@2201: ab@2201: /* Set the range of the calculated length. */ ab@2201: *min_length = ((e1000_igp_cable_length_table[agc_value] - ab@2201: IGP01E1000_AGC_RANGE) > 0) ? ab@2201: (e1000_igp_cable_length_table[agc_value] - ab@2201: IGP01E1000_AGC_RANGE) : 0; ab@2201: *max_length = e1000_igp_cable_length_table[agc_value] + ab@2201: IGP01E1000_AGC_RANGE; ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_check_polarity - Check the cable polarity ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @polarity: output parameter : 0 - Polarity is not reversed ab@2201: * 1 - Polarity is reversed. ab@2201: * ab@2201: * returns: - E1000_ERR_XXX ab@2201: * E1000_SUCCESS ab@2201: * ab@2201: * For phy's older than IGP, this function simply reads the polarity bit in the ab@2201: * Phy Status register. For IGP phy's, this bit is valid only if link speed is ab@2201: * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will ab@2201: * return 0. If the link speed is 1000 Mbps the polarity status is in the ab@2201: * IGP01E1000_PHY_PCS_INIT_REG. ab@2201: */ ab@2201: static s32 e1000_check_polarity(struct e1000_hw *hw, ab@2201: e1000_rev_polarity *polarity) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 phy_data; ab@2201: ab@2201: DEBUGFUNC("e1000_check_polarity"); ab@2201: ab@2201: if (hw->phy_type == e1000_phy_m88) { ab@2201: /* return the Polarity bit in the Status register. */ ab@2201: ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, ab@2201: &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >> ab@2201: M88E1000_PSSR_REV_POLARITY_SHIFT) ? ab@2201: e1000_rev_polarity_reversed : e1000_rev_polarity_normal; ab@2201: ab@2201: } else if (hw->phy_type == e1000_phy_igp) { ab@2201: /* Read the Status register to check the speed */ ab@2201: ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, ab@2201: &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to ab@2201: * find the polarity status */ ab@2201: if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == ab@2201: IGP01E1000_PSSR_SPEED_1000MBPS) { ab@2201: ab@2201: /* Read the GIG initialization PCS register (0x00B4) */ ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG, ab@2201: &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* Check the polarity bits */ ab@2201: *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? ab@2201: e1000_rev_polarity_reversed : ab@2201: e1000_rev_polarity_normal; ab@2201: } else { ab@2201: /* For 10 Mbps, read the polarity bit in the status register. (for ab@2201: * 100 Mbps this bit is always 0) */ ab@2201: *polarity = ab@2201: (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ? ab@2201: e1000_rev_polarity_reversed : ab@2201: e1000_rev_polarity_normal; ab@2201: } ab@2201: } ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_check_downshift - Check if Downshift occurred ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @downshift: output parameter : 0 - No Downshift occurred. ab@2201: * 1 - Downshift occurred. ab@2201: * ab@2201: * returns: - E1000_ERR_XXX ab@2201: * E1000_SUCCESS ab@2201: * ab@2201: * For phy's older than IGP, this function reads the Downshift bit in the Phy ab@2201: * Specific Status register. For IGP phy's, it reads the Downgrade bit in the ab@2201: * Link Health register. In IGP this bit is latched high, so the driver must ab@2201: * read it immediately after link is established. ab@2201: */ ab@2201: static s32 e1000_check_downshift(struct e1000_hw *hw) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 phy_data; ab@2201: ab@2201: DEBUGFUNC("e1000_check_downshift"); ab@2201: ab@2201: if (hw->phy_type == e1000_phy_igp) { ab@2201: ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH, ab@2201: &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: hw->speed_downgraded = ab@2201: (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0; ab@2201: } else if (hw->phy_type == e1000_phy_m88) { ab@2201: ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, ab@2201: &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >> ab@2201: M88E1000_PSSR_DOWNSHIFT_SHIFT; ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_config_dsp_after_link_change ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @link_up: was link up at the time this was called ab@2201: * ab@2201: * returns: - E1000_ERR_PHY if fail to read/write the PHY ab@2201: * E1000_SUCCESS at any other case. ab@2201: * ab@2201: * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a ab@2201: * gigabit link is achieved to improve link quality. ab@2201: */ ab@2201: ab@2201: static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 phy_data, phy_saved_data, speed, duplex, i; ab@2201: u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = ab@2201: { IGP01E1000_PHY_AGC_PARAM_A, ab@2201: IGP01E1000_PHY_AGC_PARAM_B, ab@2201: IGP01E1000_PHY_AGC_PARAM_C, ab@2201: IGP01E1000_PHY_AGC_PARAM_D ab@2201: }; ab@2201: u16 min_length, max_length; ab@2201: ab@2201: DEBUGFUNC("e1000_config_dsp_after_link_change"); ab@2201: ab@2201: if (hw->phy_type != e1000_phy_igp) ab@2201: return E1000_SUCCESS; ab@2201: ab@2201: if (link_up) { ab@2201: ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); ab@2201: if (ret_val) { ab@2201: DEBUGOUT("Error getting link speed and duplex\n"); ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: if (speed == SPEED_1000) { ab@2201: ab@2201: ret_val = ab@2201: e1000_get_cable_length(hw, &min_length, ab@2201: &max_length); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: if ((hw->dsp_config_state == e1000_dsp_config_enabled) ab@2201: && min_length >= e1000_igp_cable_length_50) { ab@2201: ab@2201: for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, ab@2201: dsp_reg_array[i], ab@2201: &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_data &= ab@2201: ~IGP01E1000_PHY_EDAC_MU_INDEX; ab@2201: ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, ab@2201: dsp_reg_array ab@2201: [i], phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: hw->dsp_config_state = ab@2201: e1000_dsp_config_activated; ab@2201: } ab@2201: ab@2201: if ((hw->ffe_config_state == e1000_ffe_config_enabled) ab@2201: && (min_length < e1000_igp_cable_length_50)) { ab@2201: ab@2201: u16 ffe_idle_err_timeout = ab@2201: FFE_IDLE_ERR_COUNT_TIMEOUT_20; ab@2201: u32 idle_errs = 0; ab@2201: ab@2201: /* clear previous idle error counts */ ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, PHY_1000T_STATUS, ab@2201: &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: for (i = 0; i < ffe_idle_err_timeout; i++) { ab@2201: udelay(1000); ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, ab@2201: PHY_1000T_STATUS, ab@2201: &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: idle_errs += ab@2201: (phy_data & ab@2201: SR_1000T_IDLE_ERROR_CNT); ab@2201: if (idle_errs > ab@2201: SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) ab@2201: { ab@2201: hw->ffe_config_state = ab@2201: e1000_ffe_config_active; ab@2201: ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, ab@2201: IGP01E1000_PHY_DSP_FFE, ab@2201: IGP01E1000_PHY_DSP_FFE_CM_CP); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: break; ab@2201: } ab@2201: ab@2201: if (idle_errs) ab@2201: ffe_idle_err_timeout = ab@2201: FFE_IDLE_ERR_COUNT_TIMEOUT_100; ab@2201: } ab@2201: } ab@2201: } ab@2201: } else { ab@2201: if (hw->dsp_config_state == e1000_dsp_config_activated) { ab@2201: /* Save off the current value of register 0x2F5B to be restored at ab@2201: * the end of the routines. */ ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); ab@2201: ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* Disable the PHY transmitter */ ab@2201: ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); ab@2201: ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: mdelay(20); ab@2201: ab@2201: ret_val = e1000_write_phy_reg(hw, 0x0000, ab@2201: IGP01E1000_IEEE_FORCE_GIGA); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, dsp_reg_array[i], ab@2201: &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX; ab@2201: phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS; ab@2201: ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, dsp_reg_array[i], ab@2201: phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: ret_val = e1000_write_phy_reg(hw, 0x0000, ab@2201: IGP01E1000_IEEE_RESTART_AUTONEG); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: mdelay(20); ab@2201: ab@2201: /* Now enable the transmitter */ ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); ab@2201: ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: hw->dsp_config_state = e1000_dsp_config_enabled; ab@2201: } ab@2201: ab@2201: if (hw->ffe_config_state == e1000_ffe_config_active) { ab@2201: /* Save off the current value of register 0x2F5B to be restored at ab@2201: * the end of the routines. */ ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); ab@2201: ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* Disable the PHY transmitter */ ab@2201: ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); ab@2201: ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: mdelay(20); ab@2201: ab@2201: ret_val = e1000_write_phy_reg(hw, 0x0000, ab@2201: IGP01E1000_IEEE_FORCE_GIGA); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE, ab@2201: IGP01E1000_PHY_DSP_FFE_DEFAULT); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: ret_val = e1000_write_phy_reg(hw, 0x0000, ab@2201: IGP01E1000_IEEE_RESTART_AUTONEG); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: mdelay(20); ab@2201: ab@2201: /* Now enable the transmitter */ ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); ab@2201: ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: hw->ffe_config_state = e1000_ffe_config_enabled; ab@2201: } ab@2201: } ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_set_phy_mode - Set PHY to class A mode ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Assumes the following operations will follow to enable the new class mode. ab@2201: * 1. Do a PHY soft reset ab@2201: * 2. Restart auto-negotiation or force link. ab@2201: */ ab@2201: static s32 e1000_set_phy_mode(struct e1000_hw *hw) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 eeprom_data; ab@2201: ab@2201: DEBUGFUNC("e1000_set_phy_mode"); ab@2201: ab@2201: if ((hw->mac_type == e1000_82545_rev_3) && ab@2201: (hw->media_type == e1000_media_type_copper)) { ab@2201: ret_val = ab@2201: e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, ab@2201: &eeprom_data); ab@2201: if (ret_val) { ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: if ((eeprom_data != EEPROM_RESERVED_WORD) && ab@2201: (eeprom_data & EEPROM_PHY_CLASS_A)) { ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, ab@2201: 0x000B); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, ab@2201: 0x8104); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: hw->phy_reset_disable = false; ab@2201: } ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_set_d3_lplu_state - set d3 link power state ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * @active: true to enable lplu false to disable lplu. ab@2201: * ab@2201: * This function sets the lplu state according to the active flag. When ab@2201: * activating lplu this function also disables smart speed and vise versa. ab@2201: * lplu will not be activated unless the device autonegotiation advertisement ab@2201: * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes. ab@2201: * ab@2201: * returns: - E1000_ERR_PHY if fail to read/write the PHY ab@2201: * E1000_SUCCESS at any other case. ab@2201: */ ab@2201: static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 phy_data; ab@2201: DEBUGFUNC("e1000_set_d3_lplu_state"); ab@2201: ab@2201: if (hw->phy_type != e1000_phy_igp) ab@2201: return E1000_SUCCESS; ab@2201: ab@2201: /* During driver activity LPLU should not be used or it will attain link ab@2201: * from the lowest speeds starting from 10Mbps. The capability is used for ab@2201: * Dx transitions and states */ ab@2201: if (hw->mac_type == e1000_82541_rev_2 ab@2201: || hw->mac_type == e1000_82547_rev_2) { ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: if (!active) { ab@2201: if (hw->mac_type == e1000_82541_rev_2 || ab@2201: hw->mac_type == e1000_82547_rev_2) { ab@2201: phy_data &= ~IGP01E1000_GMII_FLEX_SPD; ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, ab@2201: phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during ab@2201: * Dx states where the power conservation is most important. During ab@2201: * driver activity we should enable SmartSpeed, so performance is ab@2201: * maintained. */ ab@2201: if (hw->smart_speed == e1000_smart_speed_on) { ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, ab@2201: &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_data |= IGP01E1000_PSCFR_SMART_SPEED; ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, ab@2201: phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } else if (hw->smart_speed == e1000_smart_speed_off) { ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, ab@2201: &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, ab@2201: phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ab@2201: || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) ab@2201: || (hw->autoneg_advertised == ab@2201: AUTONEG_ADVERTISE_10_100_ALL)) { ab@2201: ab@2201: if (hw->mac_type == e1000_82541_rev_2 || ab@2201: hw->mac_type == e1000_82547_rev_2) { ab@2201: phy_data |= IGP01E1000_GMII_FLEX_SPD; ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, ab@2201: phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: } ab@2201: ab@2201: /* When LPLU is enabled we should disable SmartSpeed */ ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, ab@2201: &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, ab@2201: phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: } ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_set_vco_speed ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Change VCO speed register to improve Bit Error Rate performance of SERDES. ab@2201: */ ab@2201: static s32 e1000_set_vco_speed(struct e1000_hw *hw) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 default_page = 0; ab@2201: u16 phy_data; ab@2201: ab@2201: DEBUGFUNC("e1000_set_vco_speed"); ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82545_rev_3: ab@2201: case e1000_82546_rev_3: ab@2201: break; ab@2201: default: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /* Set PHY register 30, page 5, bit 8 to 0 */ ab@2201: ab@2201: ret_val = ab@2201: e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_data &= ~M88E1000_PHY_VCO_REG_BIT8; ab@2201: ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* Set PHY register 30, page 4, bit 11 to 1 */ ab@2201: ab@2201: ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: phy_data |= M88E1000_PHY_VCO_REG_BIT11; ab@2201: ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: ret_val = ab@2201: e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: ab@2201: /** ab@2201: * e1000_enable_mng_pass_thru - check for bmc pass through ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Verifies the hardware needs to allow ARPs to be processed by the host ab@2201: * returns: - true/false ab@2201: */ ab@2201: u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw) ab@2201: { ab@2201: u32 manc; ab@2201: ab@2201: if (hw->asf_firmware_present) { ab@2201: manc = er32(MANC); ab@2201: ab@2201: if (!(manc & E1000_MANC_RCV_TCO_EN) || ab@2201: !(manc & E1000_MANC_EN_MAC_ADDR_FILTER)) ab@2201: return false; ab@2201: if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN)) ab@2201: return true; ab@2201: } ab@2201: return false; ab@2201: } ab@2201: ab@2201: static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw) ab@2201: { ab@2201: s32 ret_val; ab@2201: u16 mii_status_reg; ab@2201: u16 i; ab@2201: ab@2201: /* Polarity reversal workaround for forced 10F/10H links. */ ab@2201: ab@2201: /* Disable the transmitter on the PHY */ ab@2201: ab@2201: ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* This loop will early-out if the NO link condition has been met. */ ab@2201: for (i = PHY_FORCE_TIME; i > 0; i--) { ab@2201: /* Read the MII Status Register and wait for Link Status bit ab@2201: * to be clear. ab@2201: */ ab@2201: ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) ab@2201: break; ab@2201: mdelay(100); ab@2201: } ab@2201: ab@2201: /* Recommended delay time after link has been lost */ ab@2201: mdelay(1000); ab@2201: ab@2201: /* Now we will re-enable th transmitter on the PHY */ ab@2201: ab@2201: ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: mdelay(50); ab@2201: ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: mdelay(50); ab@2201: ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: mdelay(50); ab@2201: ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: /* This loop will early-out if the link condition has been met. */ ab@2201: for (i = PHY_FORCE_TIME; i > 0; i--) { ab@2201: /* Read the MII Status Register and wait for Link Status bit ab@2201: * to be set. ab@2201: */ ab@2201: ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); ab@2201: if (ret_val) ab@2201: return ret_val; ab@2201: ab@2201: if (mii_status_reg & MII_SR_LINK_STATUS) ab@2201: break; ab@2201: mdelay(100); ab@2201: } ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_get_auto_rd_done ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Check for EEPROM Auto Read bit done. ab@2201: * returns: - E1000_ERR_RESET if fail to reset MAC ab@2201: * E1000_SUCCESS at any other case. ab@2201: */ ab@2201: static s32 e1000_get_auto_rd_done(struct e1000_hw *hw) ab@2201: { ab@2201: DEBUGFUNC("e1000_get_auto_rd_done"); ab@2201: msleep(5); ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_get_phy_cfg_done ab@2201: * @hw: Struct containing variables accessed by shared code ab@2201: * ab@2201: * Checks if the PHY configuration is done ab@2201: * returns: - E1000_ERR_RESET if fail to reset MAC ab@2201: * E1000_SUCCESS at any other case. ab@2201: */ ab@2201: static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw) ab@2201: { ab@2201: DEBUGFUNC("e1000_get_phy_cfg_done"); ab@2201: mdelay(10); ab@2201: return E1000_SUCCESS; ab@2201: }