175eba5b6SRobert Mustacchi /****************************************************************************** 275eba5b6SRobert Mustacchi 3*42cc51e0SRobert Mustacchi Copyright (c) 2001-2015, Intel Corporation 475eba5b6SRobert Mustacchi All rights reserved. 575eba5b6SRobert Mustacchi 675eba5b6SRobert Mustacchi Redistribution and use in source and binary forms, with or without 775eba5b6SRobert Mustacchi modification, are permitted provided that the following conditions are met: 875eba5b6SRobert Mustacchi 975eba5b6SRobert Mustacchi 1. Redistributions of source code must retain the above copyright notice, 1075eba5b6SRobert Mustacchi this list of conditions and the following disclaimer. 1175eba5b6SRobert Mustacchi 1275eba5b6SRobert Mustacchi 2. Redistributions in binary form must reproduce the above copyright 1375eba5b6SRobert Mustacchi notice, this list of conditions and the following disclaimer in the 1475eba5b6SRobert Mustacchi documentation and/or other materials provided with the distribution. 1575eba5b6SRobert Mustacchi 1675eba5b6SRobert Mustacchi 3. Neither the name of the Intel Corporation nor the names of its 1775eba5b6SRobert Mustacchi contributors may be used to endorse or promote products derived from 1875eba5b6SRobert Mustacchi this software without specific prior written permission. 1975eba5b6SRobert Mustacchi 2075eba5b6SRobert Mustacchi THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 2175eba5b6SRobert Mustacchi AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2275eba5b6SRobert Mustacchi IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2375eba5b6SRobert Mustacchi ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 2475eba5b6SRobert Mustacchi LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2575eba5b6SRobert Mustacchi CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2675eba5b6SRobert Mustacchi SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2775eba5b6SRobert Mustacchi INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2875eba5b6SRobert Mustacchi CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2975eba5b6SRobert Mustacchi ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3075eba5b6SRobert Mustacchi POSSIBILITY OF SUCH DAMAGE. 3175eba5b6SRobert Mustacchi 3275eba5b6SRobert Mustacchi ******************************************************************************/ 3375eba5b6SRobert Mustacchi /*$FreeBSD$*/ 3475eba5b6SRobert Mustacchi 3575eba5b6SRobert Mustacchi /* 3675eba5b6SRobert Mustacchi * 82543GC Gigabit Ethernet Controller (Fiber) 3775eba5b6SRobert Mustacchi * 82543GC Gigabit Ethernet Controller (Copper) 3875eba5b6SRobert Mustacchi * 82544EI Gigabit Ethernet Controller (Copper) 3975eba5b6SRobert Mustacchi * 82544EI Gigabit Ethernet Controller (Fiber) 4075eba5b6SRobert Mustacchi * 82544GC Gigabit Ethernet Controller (Copper) 4175eba5b6SRobert Mustacchi * 82544GC Gigabit Ethernet Controller (LOM) 4275eba5b6SRobert Mustacchi */ 4375eba5b6SRobert Mustacchi 4475eba5b6SRobert Mustacchi #include "e1000_api.h" 4575eba5b6SRobert Mustacchi 4675eba5b6SRobert Mustacchi static s32 e1000_init_phy_params_82543(struct e1000_hw *hw); 4775eba5b6SRobert Mustacchi static s32 e1000_init_nvm_params_82543(struct e1000_hw *hw); 4875eba5b6SRobert Mustacchi static s32 e1000_init_mac_params_82543(struct e1000_hw *hw); 4975eba5b6SRobert Mustacchi static s32 e1000_read_phy_reg_82543(struct e1000_hw *hw, u32 offset, 5075eba5b6SRobert Mustacchi u16 *data); 5175eba5b6SRobert Mustacchi static s32 e1000_write_phy_reg_82543(struct e1000_hw *hw, u32 offset, 5275eba5b6SRobert Mustacchi u16 data); 5375eba5b6SRobert Mustacchi static s32 e1000_phy_force_speed_duplex_82543(struct e1000_hw *hw); 5475eba5b6SRobert Mustacchi static s32 e1000_phy_hw_reset_82543(struct e1000_hw *hw); 5575eba5b6SRobert Mustacchi static s32 e1000_reset_hw_82543(struct e1000_hw *hw); 5675eba5b6SRobert Mustacchi static s32 e1000_init_hw_82543(struct e1000_hw *hw); 5775eba5b6SRobert Mustacchi static s32 e1000_setup_link_82543(struct e1000_hw *hw); 5875eba5b6SRobert Mustacchi static s32 e1000_setup_copper_link_82543(struct e1000_hw *hw); 5975eba5b6SRobert Mustacchi static s32 e1000_setup_fiber_link_82543(struct e1000_hw *hw); 6075eba5b6SRobert Mustacchi static s32 e1000_check_for_copper_link_82543(struct e1000_hw *hw); 6175eba5b6SRobert Mustacchi static s32 e1000_check_for_fiber_link_82543(struct e1000_hw *hw); 6275eba5b6SRobert Mustacchi static s32 e1000_led_on_82543(struct e1000_hw *hw); 6375eba5b6SRobert Mustacchi static s32 e1000_led_off_82543(struct e1000_hw *hw); 6475eba5b6SRobert Mustacchi static void e1000_write_vfta_82543(struct e1000_hw *hw, u32 offset, 6575eba5b6SRobert Mustacchi u32 value); 6675eba5b6SRobert Mustacchi static void e1000_clear_hw_cntrs_82543(struct e1000_hw *hw); 6775eba5b6SRobert Mustacchi static s32 e1000_config_mac_to_phy_82543(struct e1000_hw *hw); 6875eba5b6SRobert Mustacchi static bool e1000_init_phy_disabled_82543(struct e1000_hw *hw); 6975eba5b6SRobert Mustacchi static void e1000_lower_mdi_clk_82543(struct e1000_hw *hw, u32 *ctrl); 7075eba5b6SRobert Mustacchi static s32 e1000_polarity_reversal_workaround_82543(struct e1000_hw *hw); 7175eba5b6SRobert Mustacchi static void e1000_raise_mdi_clk_82543(struct e1000_hw *hw, u32 *ctrl); 7275eba5b6SRobert Mustacchi static u16 e1000_shift_in_mdi_bits_82543(struct e1000_hw *hw); 7375eba5b6SRobert Mustacchi static void e1000_shift_out_mdi_bits_82543(struct e1000_hw *hw, u32 data, 7475eba5b6SRobert Mustacchi u16 count); 7575eba5b6SRobert Mustacchi static bool e1000_tbi_compatibility_enabled_82543(struct e1000_hw *hw); 7675eba5b6SRobert Mustacchi static void e1000_set_tbi_sbp_82543(struct e1000_hw *hw, bool state); 7775eba5b6SRobert Mustacchi static s32 e1000_read_mac_addr_82543(struct e1000_hw *hw); 7875eba5b6SRobert Mustacchi 7975eba5b6SRobert Mustacchi 8075eba5b6SRobert Mustacchi /** 8175eba5b6SRobert Mustacchi * e1000_init_phy_params_82543 - Init PHY func ptrs. 8275eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 8375eba5b6SRobert Mustacchi **/ 8475eba5b6SRobert Mustacchi static s32 e1000_init_phy_params_82543(struct e1000_hw *hw) 8575eba5b6SRobert Mustacchi { 8675eba5b6SRobert Mustacchi struct e1000_phy_info *phy = &hw->phy; 8775eba5b6SRobert Mustacchi s32 ret_val = E1000_SUCCESS; 8875eba5b6SRobert Mustacchi 8975eba5b6SRobert Mustacchi DEBUGFUNC("e1000_init_phy_params_82543"); 9075eba5b6SRobert Mustacchi 9175eba5b6SRobert Mustacchi if (hw->phy.media_type != e1000_media_type_copper) { 9275eba5b6SRobert Mustacchi phy->type = e1000_phy_none; 9375eba5b6SRobert Mustacchi goto out; 9475eba5b6SRobert Mustacchi } else { 9575eba5b6SRobert Mustacchi phy->ops.power_up = e1000_power_up_phy_copper; 9675eba5b6SRobert Mustacchi phy->ops.power_down = e1000_power_down_phy_copper; 9775eba5b6SRobert Mustacchi } 9875eba5b6SRobert Mustacchi 9975eba5b6SRobert Mustacchi phy->addr = 1; 10075eba5b6SRobert Mustacchi phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT; 10175eba5b6SRobert Mustacchi phy->reset_delay_us = 10000; 10275eba5b6SRobert Mustacchi phy->type = e1000_phy_m88; 10375eba5b6SRobert Mustacchi 10475eba5b6SRobert Mustacchi /* Function Pointers */ 10575eba5b6SRobert Mustacchi phy->ops.check_polarity = e1000_check_polarity_m88; 10675eba5b6SRobert Mustacchi phy->ops.commit = e1000_phy_sw_reset_generic; 10775eba5b6SRobert Mustacchi phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_82543; 10875eba5b6SRobert Mustacchi phy->ops.get_cable_length = e1000_get_cable_length_m88; 10975eba5b6SRobert Mustacchi phy->ops.get_cfg_done = e1000_get_cfg_done_generic; 11075eba5b6SRobert Mustacchi phy->ops.read_reg = (hw->mac.type == e1000_82543) 11175eba5b6SRobert Mustacchi ? e1000_read_phy_reg_82543 11275eba5b6SRobert Mustacchi : e1000_read_phy_reg_m88; 11375eba5b6SRobert Mustacchi phy->ops.reset = (hw->mac.type == e1000_82543) 11475eba5b6SRobert Mustacchi ? e1000_phy_hw_reset_82543 11575eba5b6SRobert Mustacchi : e1000_phy_hw_reset_generic; 11675eba5b6SRobert Mustacchi phy->ops.write_reg = (hw->mac.type == e1000_82543) 11775eba5b6SRobert Mustacchi ? e1000_write_phy_reg_82543 11875eba5b6SRobert Mustacchi : e1000_write_phy_reg_m88; 11975eba5b6SRobert Mustacchi phy->ops.get_info = e1000_get_phy_info_m88; 12075eba5b6SRobert Mustacchi 12175eba5b6SRobert Mustacchi /* 12275eba5b6SRobert Mustacchi * The external PHY of the 82543 can be in a funky state. 12375eba5b6SRobert Mustacchi * Resetting helps us read the PHY registers for acquiring 12475eba5b6SRobert Mustacchi * the PHY ID. 12575eba5b6SRobert Mustacchi */ 12675eba5b6SRobert Mustacchi if (!e1000_init_phy_disabled_82543(hw)) { 12775eba5b6SRobert Mustacchi ret_val = phy->ops.reset(hw); 12875eba5b6SRobert Mustacchi if (ret_val) { 12975eba5b6SRobert Mustacchi DEBUGOUT("Resetting PHY during init failed.\n"); 13075eba5b6SRobert Mustacchi goto out; 13175eba5b6SRobert Mustacchi } 13275eba5b6SRobert Mustacchi msec_delay(20); 13375eba5b6SRobert Mustacchi } 13475eba5b6SRobert Mustacchi 13575eba5b6SRobert Mustacchi ret_val = e1000_get_phy_id(hw); 13675eba5b6SRobert Mustacchi if (ret_val) 13775eba5b6SRobert Mustacchi goto out; 13875eba5b6SRobert Mustacchi 13975eba5b6SRobert Mustacchi /* Verify phy id */ 14075eba5b6SRobert Mustacchi switch (hw->mac.type) { 14175eba5b6SRobert Mustacchi case e1000_82543: 14275eba5b6SRobert Mustacchi if (phy->id != M88E1000_E_PHY_ID) { 14375eba5b6SRobert Mustacchi ret_val = -E1000_ERR_PHY; 14475eba5b6SRobert Mustacchi goto out; 14575eba5b6SRobert Mustacchi } 14675eba5b6SRobert Mustacchi break; 14775eba5b6SRobert Mustacchi case e1000_82544: 14875eba5b6SRobert Mustacchi if (phy->id != M88E1000_I_PHY_ID) { 14975eba5b6SRobert Mustacchi ret_val = -E1000_ERR_PHY; 15075eba5b6SRobert Mustacchi goto out; 15175eba5b6SRobert Mustacchi } 15275eba5b6SRobert Mustacchi break; 15375eba5b6SRobert Mustacchi default: 15475eba5b6SRobert Mustacchi ret_val = -E1000_ERR_PHY; 15575eba5b6SRobert Mustacchi goto out; 15675eba5b6SRobert Mustacchi break; 15775eba5b6SRobert Mustacchi } 15875eba5b6SRobert Mustacchi 15975eba5b6SRobert Mustacchi out: 16075eba5b6SRobert Mustacchi return ret_val; 16175eba5b6SRobert Mustacchi } 16275eba5b6SRobert Mustacchi 16375eba5b6SRobert Mustacchi /** 16475eba5b6SRobert Mustacchi * e1000_init_nvm_params_82543 - Init NVM func ptrs. 16575eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 16675eba5b6SRobert Mustacchi **/ 16775eba5b6SRobert Mustacchi static s32 e1000_init_nvm_params_82543(struct e1000_hw *hw) 16875eba5b6SRobert Mustacchi { 16975eba5b6SRobert Mustacchi struct e1000_nvm_info *nvm = &hw->nvm; 17075eba5b6SRobert Mustacchi 17175eba5b6SRobert Mustacchi DEBUGFUNC("e1000_init_nvm_params_82543"); 17275eba5b6SRobert Mustacchi 17375eba5b6SRobert Mustacchi nvm->type = e1000_nvm_eeprom_microwire; 17475eba5b6SRobert Mustacchi nvm->word_size = 64; 17575eba5b6SRobert Mustacchi nvm->delay_usec = 50; 17675eba5b6SRobert Mustacchi nvm->address_bits = 6; 17775eba5b6SRobert Mustacchi nvm->opcode_bits = 3; 17875eba5b6SRobert Mustacchi 17975eba5b6SRobert Mustacchi /* Function Pointers */ 18075eba5b6SRobert Mustacchi nvm->ops.read = e1000_read_nvm_microwire; 18175eba5b6SRobert Mustacchi nvm->ops.update = e1000_update_nvm_checksum_generic; 18275eba5b6SRobert Mustacchi nvm->ops.valid_led_default = e1000_valid_led_default_generic; 18375eba5b6SRobert Mustacchi nvm->ops.validate = e1000_validate_nvm_checksum_generic; 18475eba5b6SRobert Mustacchi nvm->ops.write = e1000_write_nvm_microwire; 18575eba5b6SRobert Mustacchi 18675eba5b6SRobert Mustacchi return E1000_SUCCESS; 18775eba5b6SRobert Mustacchi } 18875eba5b6SRobert Mustacchi 18975eba5b6SRobert Mustacchi /** 19075eba5b6SRobert Mustacchi * e1000_init_mac_params_82543 - Init MAC func ptrs. 19175eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 19275eba5b6SRobert Mustacchi **/ 19375eba5b6SRobert Mustacchi static s32 e1000_init_mac_params_82543(struct e1000_hw *hw) 19475eba5b6SRobert Mustacchi { 19575eba5b6SRobert Mustacchi struct e1000_mac_info *mac = &hw->mac; 19675eba5b6SRobert Mustacchi 19775eba5b6SRobert Mustacchi DEBUGFUNC("e1000_init_mac_params_82543"); 19875eba5b6SRobert Mustacchi 19975eba5b6SRobert Mustacchi /* Set media type */ 20075eba5b6SRobert Mustacchi switch (hw->device_id) { 20175eba5b6SRobert Mustacchi case E1000_DEV_ID_82543GC_FIBER: 20275eba5b6SRobert Mustacchi case E1000_DEV_ID_82544EI_FIBER: 20375eba5b6SRobert Mustacchi hw->phy.media_type = e1000_media_type_fiber; 20475eba5b6SRobert Mustacchi break; 20575eba5b6SRobert Mustacchi default: 20675eba5b6SRobert Mustacchi hw->phy.media_type = e1000_media_type_copper; 20775eba5b6SRobert Mustacchi break; 20875eba5b6SRobert Mustacchi } 20975eba5b6SRobert Mustacchi 21075eba5b6SRobert Mustacchi /* Set mta register count */ 21175eba5b6SRobert Mustacchi mac->mta_reg_count = 128; 21275eba5b6SRobert Mustacchi /* Set rar entry count */ 21375eba5b6SRobert Mustacchi mac->rar_entry_count = E1000_RAR_ENTRIES; 21475eba5b6SRobert Mustacchi 21575eba5b6SRobert Mustacchi /* Function pointers */ 21675eba5b6SRobert Mustacchi 21775eba5b6SRobert Mustacchi /* bus type/speed/width */ 21875eba5b6SRobert Mustacchi mac->ops.get_bus_info = e1000_get_bus_info_pci_generic; 21975eba5b6SRobert Mustacchi /* function id */ 22075eba5b6SRobert Mustacchi mac->ops.set_lan_id = e1000_set_lan_id_multi_port_pci; 22175eba5b6SRobert Mustacchi /* reset */ 22275eba5b6SRobert Mustacchi mac->ops.reset_hw = e1000_reset_hw_82543; 22375eba5b6SRobert Mustacchi /* hw initialization */ 22475eba5b6SRobert Mustacchi mac->ops.init_hw = e1000_init_hw_82543; 22575eba5b6SRobert Mustacchi /* link setup */ 22675eba5b6SRobert Mustacchi mac->ops.setup_link = e1000_setup_link_82543; 22775eba5b6SRobert Mustacchi /* physical interface setup */ 22875eba5b6SRobert Mustacchi mac->ops.setup_physical_interface = 22975eba5b6SRobert Mustacchi (hw->phy.media_type == e1000_media_type_copper) 230*42cc51e0SRobert Mustacchi ? e1000_setup_copper_link_82543 : e1000_setup_fiber_link_82543; 23175eba5b6SRobert Mustacchi /* check for link */ 23275eba5b6SRobert Mustacchi mac->ops.check_for_link = 23375eba5b6SRobert Mustacchi (hw->phy.media_type == e1000_media_type_copper) 23475eba5b6SRobert Mustacchi ? e1000_check_for_copper_link_82543 23575eba5b6SRobert Mustacchi : e1000_check_for_fiber_link_82543; 23675eba5b6SRobert Mustacchi /* link info */ 23775eba5b6SRobert Mustacchi mac->ops.get_link_up_info = 23875eba5b6SRobert Mustacchi (hw->phy.media_type == e1000_media_type_copper) 23975eba5b6SRobert Mustacchi ? e1000_get_speed_and_duplex_copper_generic 24075eba5b6SRobert Mustacchi : e1000_get_speed_and_duplex_fiber_serdes_generic; 24175eba5b6SRobert Mustacchi /* multicast address update */ 24275eba5b6SRobert Mustacchi mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_generic; 24375eba5b6SRobert Mustacchi /* writing VFTA */ 24475eba5b6SRobert Mustacchi mac->ops.write_vfta = e1000_write_vfta_82543; 24575eba5b6SRobert Mustacchi /* clearing VFTA */ 24675eba5b6SRobert Mustacchi mac->ops.clear_vfta = e1000_clear_vfta_generic; 24775eba5b6SRobert Mustacchi /* read mac address */ 24875eba5b6SRobert Mustacchi mac->ops.read_mac_addr = e1000_read_mac_addr_82543; 24975eba5b6SRobert Mustacchi /* turn on/off LED */ 25075eba5b6SRobert Mustacchi mac->ops.led_on = e1000_led_on_82543; 25175eba5b6SRobert Mustacchi mac->ops.led_off = e1000_led_off_82543; 25275eba5b6SRobert Mustacchi /* clear hardware counters */ 25375eba5b6SRobert Mustacchi mac->ops.clear_hw_cntrs = e1000_clear_hw_cntrs_82543; 25475eba5b6SRobert Mustacchi 25575eba5b6SRobert Mustacchi /* Set tbi compatibility */ 25675eba5b6SRobert Mustacchi if ((hw->mac.type != e1000_82543) || 25775eba5b6SRobert Mustacchi (hw->phy.media_type == e1000_media_type_fiber)) 25875eba5b6SRobert Mustacchi e1000_set_tbi_compatibility_82543(hw, FALSE); 25975eba5b6SRobert Mustacchi 26075eba5b6SRobert Mustacchi return E1000_SUCCESS; 26175eba5b6SRobert Mustacchi } 26275eba5b6SRobert Mustacchi 26375eba5b6SRobert Mustacchi /** 26475eba5b6SRobert Mustacchi * e1000_init_function_pointers_82543 - Init func ptrs. 26575eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 26675eba5b6SRobert Mustacchi * 26775eba5b6SRobert Mustacchi * Called to initialize all function pointers and parameters. 26875eba5b6SRobert Mustacchi **/ 26975eba5b6SRobert Mustacchi void e1000_init_function_pointers_82543(struct e1000_hw *hw) 27075eba5b6SRobert Mustacchi { 27175eba5b6SRobert Mustacchi DEBUGFUNC("e1000_init_function_pointers_82543"); 27275eba5b6SRobert Mustacchi 27375eba5b6SRobert Mustacchi hw->mac.ops.init_params = e1000_init_mac_params_82543; 27475eba5b6SRobert Mustacchi hw->nvm.ops.init_params = e1000_init_nvm_params_82543; 27575eba5b6SRobert Mustacchi hw->phy.ops.init_params = e1000_init_phy_params_82543; 27675eba5b6SRobert Mustacchi } 27775eba5b6SRobert Mustacchi 27875eba5b6SRobert Mustacchi /** 27975eba5b6SRobert Mustacchi * e1000_tbi_compatibility_enabled_82543 - Returns TBI compat status 28075eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 28175eba5b6SRobert Mustacchi * 28275eba5b6SRobert Mustacchi * Returns the current status of 10-bit Interface (TBI) compatibility 28375eba5b6SRobert Mustacchi * (enabled/disabled). 28475eba5b6SRobert Mustacchi **/ 28575eba5b6SRobert Mustacchi static bool e1000_tbi_compatibility_enabled_82543(struct e1000_hw *hw) 28675eba5b6SRobert Mustacchi { 28775eba5b6SRobert Mustacchi struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543; 28875eba5b6SRobert Mustacchi bool state = FALSE; 28975eba5b6SRobert Mustacchi 29075eba5b6SRobert Mustacchi DEBUGFUNC("e1000_tbi_compatibility_enabled_82543"); 29175eba5b6SRobert Mustacchi 29275eba5b6SRobert Mustacchi if (hw->mac.type != e1000_82543) { 29375eba5b6SRobert Mustacchi DEBUGOUT("TBI compatibility workaround for 82543 only.\n"); 29475eba5b6SRobert Mustacchi goto out; 29575eba5b6SRobert Mustacchi } 29675eba5b6SRobert Mustacchi 297*42cc51e0SRobert Mustacchi state = !!(dev_spec->tbi_compatibility & TBI_COMPAT_ENABLED); 29875eba5b6SRobert Mustacchi 29975eba5b6SRobert Mustacchi out: 30075eba5b6SRobert Mustacchi return state; 30175eba5b6SRobert Mustacchi } 30275eba5b6SRobert Mustacchi 30375eba5b6SRobert Mustacchi /** 30475eba5b6SRobert Mustacchi * e1000_set_tbi_compatibility_82543 - Set TBI compatibility 30575eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 30675eba5b6SRobert Mustacchi * @state: enable/disable TBI compatibility 30775eba5b6SRobert Mustacchi * 30875eba5b6SRobert Mustacchi * Enables or disabled 10-bit Interface (TBI) compatibility. 30975eba5b6SRobert Mustacchi **/ 31075eba5b6SRobert Mustacchi void e1000_set_tbi_compatibility_82543(struct e1000_hw *hw, bool state) 31175eba5b6SRobert Mustacchi { 31275eba5b6SRobert Mustacchi struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543; 31375eba5b6SRobert Mustacchi 31475eba5b6SRobert Mustacchi DEBUGFUNC("e1000_set_tbi_compatibility_82543"); 31575eba5b6SRobert Mustacchi 31675eba5b6SRobert Mustacchi if (hw->mac.type != e1000_82543) { 31775eba5b6SRobert Mustacchi DEBUGOUT("TBI compatibility workaround for 82543 only.\n"); 31875eba5b6SRobert Mustacchi goto out; 31975eba5b6SRobert Mustacchi } 32075eba5b6SRobert Mustacchi 32175eba5b6SRobert Mustacchi if (state) 32275eba5b6SRobert Mustacchi dev_spec->tbi_compatibility |= TBI_COMPAT_ENABLED; 32375eba5b6SRobert Mustacchi else 32475eba5b6SRobert Mustacchi dev_spec->tbi_compatibility &= ~TBI_COMPAT_ENABLED; 32575eba5b6SRobert Mustacchi 32675eba5b6SRobert Mustacchi out: 32775eba5b6SRobert Mustacchi return; 32875eba5b6SRobert Mustacchi } 32975eba5b6SRobert Mustacchi 33075eba5b6SRobert Mustacchi /** 33175eba5b6SRobert Mustacchi * e1000_tbi_sbp_enabled_82543 - Returns TBI SBP status 33275eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 33375eba5b6SRobert Mustacchi * 33475eba5b6SRobert Mustacchi * Returns the current status of 10-bit Interface (TBI) store bad packet (SBP) 33575eba5b6SRobert Mustacchi * (enabled/disabled). 33675eba5b6SRobert Mustacchi **/ 33775eba5b6SRobert Mustacchi bool e1000_tbi_sbp_enabled_82543(struct e1000_hw *hw) 33875eba5b6SRobert Mustacchi { 33975eba5b6SRobert Mustacchi struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543; 34075eba5b6SRobert Mustacchi bool state = FALSE; 34175eba5b6SRobert Mustacchi 34275eba5b6SRobert Mustacchi DEBUGFUNC("e1000_tbi_sbp_enabled_82543"); 34375eba5b6SRobert Mustacchi 34475eba5b6SRobert Mustacchi if (hw->mac.type != e1000_82543) { 34575eba5b6SRobert Mustacchi DEBUGOUT("TBI compatibility workaround for 82543 only.\n"); 34675eba5b6SRobert Mustacchi goto out; 34775eba5b6SRobert Mustacchi } 34875eba5b6SRobert Mustacchi 349*42cc51e0SRobert Mustacchi state = !!(dev_spec->tbi_compatibility & TBI_SBP_ENABLED); 35075eba5b6SRobert Mustacchi 35175eba5b6SRobert Mustacchi out: 35275eba5b6SRobert Mustacchi return state; 35375eba5b6SRobert Mustacchi } 35475eba5b6SRobert Mustacchi 35575eba5b6SRobert Mustacchi /** 35675eba5b6SRobert Mustacchi * e1000_set_tbi_sbp_82543 - Set TBI SBP 35775eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 35875eba5b6SRobert Mustacchi * @state: enable/disable TBI store bad packet 35975eba5b6SRobert Mustacchi * 36075eba5b6SRobert Mustacchi * Enables or disabled 10-bit Interface (TBI) store bad packet (SBP). 36175eba5b6SRobert Mustacchi **/ 36275eba5b6SRobert Mustacchi static void e1000_set_tbi_sbp_82543(struct e1000_hw *hw, bool state) 36375eba5b6SRobert Mustacchi { 36475eba5b6SRobert Mustacchi struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543; 36575eba5b6SRobert Mustacchi 36675eba5b6SRobert Mustacchi DEBUGFUNC("e1000_set_tbi_sbp_82543"); 36775eba5b6SRobert Mustacchi 36875eba5b6SRobert Mustacchi if (state && e1000_tbi_compatibility_enabled_82543(hw)) 36975eba5b6SRobert Mustacchi dev_spec->tbi_compatibility |= TBI_SBP_ENABLED; 37075eba5b6SRobert Mustacchi else 37175eba5b6SRobert Mustacchi dev_spec->tbi_compatibility &= ~TBI_SBP_ENABLED; 37275eba5b6SRobert Mustacchi 37375eba5b6SRobert Mustacchi return; 37475eba5b6SRobert Mustacchi } 37575eba5b6SRobert Mustacchi 37675eba5b6SRobert Mustacchi /** 37775eba5b6SRobert Mustacchi * e1000_init_phy_disabled_82543 - Returns init PHY status 37875eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 37975eba5b6SRobert Mustacchi * 38075eba5b6SRobert Mustacchi * Returns the current status of whether PHY initialization is disabled. 38175eba5b6SRobert Mustacchi * True if PHY initialization is disabled else FALSE. 38275eba5b6SRobert Mustacchi **/ 38375eba5b6SRobert Mustacchi static bool e1000_init_phy_disabled_82543(struct e1000_hw *hw) 38475eba5b6SRobert Mustacchi { 38575eba5b6SRobert Mustacchi struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543; 38675eba5b6SRobert Mustacchi bool ret_val; 38775eba5b6SRobert Mustacchi 38875eba5b6SRobert Mustacchi DEBUGFUNC("e1000_init_phy_disabled_82543"); 38975eba5b6SRobert Mustacchi 39075eba5b6SRobert Mustacchi if (hw->mac.type != e1000_82543) { 39175eba5b6SRobert Mustacchi ret_val = FALSE; 39275eba5b6SRobert Mustacchi goto out; 39375eba5b6SRobert Mustacchi } 39475eba5b6SRobert Mustacchi 39575eba5b6SRobert Mustacchi ret_val = dev_spec->init_phy_disabled; 39675eba5b6SRobert Mustacchi 39775eba5b6SRobert Mustacchi out: 39875eba5b6SRobert Mustacchi return ret_val; 39975eba5b6SRobert Mustacchi } 40075eba5b6SRobert Mustacchi 40175eba5b6SRobert Mustacchi /** 40275eba5b6SRobert Mustacchi * e1000_tbi_adjust_stats_82543 - Adjust stats when TBI enabled 40375eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 40475eba5b6SRobert Mustacchi * @stats: Struct containing statistic register values 40575eba5b6SRobert Mustacchi * @frame_len: The length of the frame in question 40675eba5b6SRobert Mustacchi * @mac_addr: The Ethernet destination address of the frame in question 40775eba5b6SRobert Mustacchi * @max_frame_size: The maximum frame size 40875eba5b6SRobert Mustacchi * 40975eba5b6SRobert Mustacchi * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT 41075eba5b6SRobert Mustacchi **/ 41175eba5b6SRobert Mustacchi void e1000_tbi_adjust_stats_82543(struct e1000_hw *hw, 41275eba5b6SRobert Mustacchi struct e1000_hw_stats *stats, u32 frame_len, 41375eba5b6SRobert Mustacchi u8 *mac_addr, u32 max_frame_size) 41475eba5b6SRobert Mustacchi { 41575eba5b6SRobert Mustacchi if (!(e1000_tbi_sbp_enabled_82543(hw))) 41675eba5b6SRobert Mustacchi goto out; 41775eba5b6SRobert Mustacchi 41875eba5b6SRobert Mustacchi /* First adjust the frame length. */ 41975eba5b6SRobert Mustacchi frame_len--; 42075eba5b6SRobert Mustacchi /* 42175eba5b6SRobert Mustacchi * We need to adjust the statistics counters, since the hardware 42275eba5b6SRobert Mustacchi * counters overcount this packet as a CRC error and undercount 42375eba5b6SRobert Mustacchi * the packet as a good packet 42475eba5b6SRobert Mustacchi */ 42575eba5b6SRobert Mustacchi /* This packet should not be counted as a CRC error. */ 42675eba5b6SRobert Mustacchi stats->crcerrs--; 42775eba5b6SRobert Mustacchi /* This packet does count as a Good Packet Received. */ 42875eba5b6SRobert Mustacchi stats->gprc++; 42975eba5b6SRobert Mustacchi 43075eba5b6SRobert Mustacchi /* Adjust the Good Octets received counters */ 43175eba5b6SRobert Mustacchi stats->gorc += frame_len; 43275eba5b6SRobert Mustacchi 43375eba5b6SRobert Mustacchi /* 43475eba5b6SRobert Mustacchi * Is this a broadcast or multicast? Check broadcast first, 43575eba5b6SRobert Mustacchi * since the test for a multicast frame will test positive on 43675eba5b6SRobert Mustacchi * a broadcast frame. 43775eba5b6SRobert Mustacchi */ 43875eba5b6SRobert Mustacchi if ((mac_addr[0] == 0xff) && (mac_addr[1] == 0xff)) 43975eba5b6SRobert Mustacchi /* Broadcast packet */ 44075eba5b6SRobert Mustacchi stats->bprc++; 44175eba5b6SRobert Mustacchi else if (*mac_addr & 0x01) 44275eba5b6SRobert Mustacchi /* Multicast packet */ 44375eba5b6SRobert Mustacchi stats->mprc++; 44475eba5b6SRobert Mustacchi 44575eba5b6SRobert Mustacchi /* 44675eba5b6SRobert Mustacchi * In this case, the hardware has over counted the number of 44775eba5b6SRobert Mustacchi * oversize frames. 44875eba5b6SRobert Mustacchi */ 44975eba5b6SRobert Mustacchi if ((frame_len == max_frame_size) && (stats->roc > 0)) 45075eba5b6SRobert Mustacchi stats->roc--; 45175eba5b6SRobert Mustacchi 45275eba5b6SRobert Mustacchi /* 45375eba5b6SRobert Mustacchi * Adjust the bin counters when the extra byte put the frame in the 45475eba5b6SRobert Mustacchi * wrong bin. Remember that the frame_len was adjusted above. 45575eba5b6SRobert Mustacchi */ 45675eba5b6SRobert Mustacchi if (frame_len == 64) { 45775eba5b6SRobert Mustacchi stats->prc64++; 45875eba5b6SRobert Mustacchi stats->prc127--; 45975eba5b6SRobert Mustacchi } else if (frame_len == 127) { 46075eba5b6SRobert Mustacchi stats->prc127++; 46175eba5b6SRobert Mustacchi stats->prc255--; 46275eba5b6SRobert Mustacchi } else if (frame_len == 255) { 46375eba5b6SRobert Mustacchi stats->prc255++; 46475eba5b6SRobert Mustacchi stats->prc511--; 46575eba5b6SRobert Mustacchi } else if (frame_len == 511) { 46675eba5b6SRobert Mustacchi stats->prc511++; 46775eba5b6SRobert Mustacchi stats->prc1023--; 46875eba5b6SRobert Mustacchi } else if (frame_len == 1023) { 46975eba5b6SRobert Mustacchi stats->prc1023++; 47075eba5b6SRobert Mustacchi stats->prc1522--; 47175eba5b6SRobert Mustacchi } else if (frame_len == 1522) { 47275eba5b6SRobert Mustacchi stats->prc1522++; 47375eba5b6SRobert Mustacchi } 47475eba5b6SRobert Mustacchi 47575eba5b6SRobert Mustacchi out: 47675eba5b6SRobert Mustacchi return; 47775eba5b6SRobert Mustacchi } 47875eba5b6SRobert Mustacchi 47975eba5b6SRobert Mustacchi /** 48075eba5b6SRobert Mustacchi * e1000_read_phy_reg_82543 - Read PHY register 48175eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 48275eba5b6SRobert Mustacchi * @offset: register offset to be read 48375eba5b6SRobert Mustacchi * @data: pointer to the read data 48475eba5b6SRobert Mustacchi * 48575eba5b6SRobert Mustacchi * Reads the PHY at offset and stores the information read to data. 48675eba5b6SRobert Mustacchi **/ 48775eba5b6SRobert Mustacchi static s32 e1000_read_phy_reg_82543(struct e1000_hw *hw, u32 offset, u16 *data) 48875eba5b6SRobert Mustacchi { 48975eba5b6SRobert Mustacchi u32 mdic; 49075eba5b6SRobert Mustacchi s32 ret_val = E1000_SUCCESS; 49175eba5b6SRobert Mustacchi 49275eba5b6SRobert Mustacchi DEBUGFUNC("e1000_read_phy_reg_82543"); 49375eba5b6SRobert Mustacchi 49475eba5b6SRobert Mustacchi if (offset > MAX_PHY_REG_ADDRESS) { 49575eba5b6SRobert Mustacchi DEBUGOUT1("PHY Address %d is out of range\n", offset); 49675eba5b6SRobert Mustacchi ret_val = -E1000_ERR_PARAM; 49775eba5b6SRobert Mustacchi goto out; 49875eba5b6SRobert Mustacchi } 49975eba5b6SRobert Mustacchi 50075eba5b6SRobert Mustacchi /* 50175eba5b6SRobert Mustacchi * We must first send a preamble through the MDIO pin to signal the 50275eba5b6SRobert Mustacchi * beginning of an MII instruction. This is done by sending 32 50375eba5b6SRobert Mustacchi * consecutive "1" bits. 50475eba5b6SRobert Mustacchi */ 50575eba5b6SRobert Mustacchi e1000_shift_out_mdi_bits_82543(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); 50675eba5b6SRobert Mustacchi 50775eba5b6SRobert Mustacchi /* 50875eba5b6SRobert Mustacchi * Now combine the next few fields that are required for a read 50975eba5b6SRobert Mustacchi * operation. We use this method instead of calling the 51075eba5b6SRobert Mustacchi * e1000_shift_out_mdi_bits routine five different times. The format 51175eba5b6SRobert Mustacchi * of an MII read instruction consists of a shift out of 14 bits and 51275eba5b6SRobert Mustacchi * is defined as follows: 51375eba5b6SRobert Mustacchi * <Preamble><SOF><Op Code><Phy Addr><Offset> 51475eba5b6SRobert Mustacchi * followed by a shift in of 18 bits. This first two bits shifted in 51575eba5b6SRobert Mustacchi * are TurnAround bits used to avoid contention on the MDIO pin when a 51675eba5b6SRobert Mustacchi * READ operation is performed. These two bits are thrown away 51775eba5b6SRobert Mustacchi * followed by a shift in of 16 bits which contains the desired data. 51875eba5b6SRobert Mustacchi */ 51975eba5b6SRobert Mustacchi mdic = (offset | (hw->phy.addr << 5) | 52075eba5b6SRobert Mustacchi (PHY_OP_READ << 10) | (PHY_SOF << 12)); 52175eba5b6SRobert Mustacchi 52275eba5b6SRobert Mustacchi e1000_shift_out_mdi_bits_82543(hw, mdic, 14); 52375eba5b6SRobert Mustacchi 52475eba5b6SRobert Mustacchi /* 52575eba5b6SRobert Mustacchi * Now that we've shifted out the read command to the MII, we need to 52675eba5b6SRobert Mustacchi * "shift in" the 16-bit value (18 total bits) of the requested PHY 52775eba5b6SRobert Mustacchi * register address. 52875eba5b6SRobert Mustacchi */ 52975eba5b6SRobert Mustacchi *data = e1000_shift_in_mdi_bits_82543(hw); 53075eba5b6SRobert Mustacchi 53175eba5b6SRobert Mustacchi out: 53275eba5b6SRobert Mustacchi return ret_val; 53375eba5b6SRobert Mustacchi } 53475eba5b6SRobert Mustacchi 53575eba5b6SRobert Mustacchi /** 53675eba5b6SRobert Mustacchi * e1000_write_phy_reg_82543 - Write PHY register 53775eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 53875eba5b6SRobert Mustacchi * @offset: register offset to be written 53975eba5b6SRobert Mustacchi * @data: pointer to the data to be written at offset 54075eba5b6SRobert Mustacchi * 54175eba5b6SRobert Mustacchi * Writes data to the PHY at offset. 54275eba5b6SRobert Mustacchi **/ 54375eba5b6SRobert Mustacchi static s32 e1000_write_phy_reg_82543(struct e1000_hw *hw, u32 offset, u16 data) 54475eba5b6SRobert Mustacchi { 54575eba5b6SRobert Mustacchi u32 mdic; 54675eba5b6SRobert Mustacchi s32 ret_val = E1000_SUCCESS; 54775eba5b6SRobert Mustacchi 54875eba5b6SRobert Mustacchi DEBUGFUNC("e1000_write_phy_reg_82543"); 54975eba5b6SRobert Mustacchi 55075eba5b6SRobert Mustacchi if (offset > MAX_PHY_REG_ADDRESS) { 55175eba5b6SRobert Mustacchi DEBUGOUT1("PHY Address %d is out of range\n", offset); 55275eba5b6SRobert Mustacchi ret_val = -E1000_ERR_PARAM; 55375eba5b6SRobert Mustacchi goto out; 55475eba5b6SRobert Mustacchi } 55575eba5b6SRobert Mustacchi 55675eba5b6SRobert Mustacchi /* 55775eba5b6SRobert Mustacchi * We'll need to use the SW defined pins to shift the write command 55875eba5b6SRobert Mustacchi * out to the PHY. We first send a preamble to the PHY to signal the 55975eba5b6SRobert Mustacchi * beginning of the MII instruction. This is done by sending 32 56075eba5b6SRobert Mustacchi * consecutive "1" bits. 56175eba5b6SRobert Mustacchi */ 56275eba5b6SRobert Mustacchi e1000_shift_out_mdi_bits_82543(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); 56375eba5b6SRobert Mustacchi 56475eba5b6SRobert Mustacchi /* 56575eba5b6SRobert Mustacchi * Now combine the remaining required fields that will indicate a 56675eba5b6SRobert Mustacchi * write operation. We use this method instead of calling the 56775eba5b6SRobert Mustacchi * e1000_shift_out_mdi_bits routine for each field in the command. The 56875eba5b6SRobert Mustacchi * format of a MII write instruction is as follows: 56975eba5b6SRobert Mustacchi * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>. 57075eba5b6SRobert Mustacchi */ 57175eba5b6SRobert Mustacchi mdic = ((PHY_TURNAROUND) | (offset << 2) | (hw->phy.addr << 7) | 57275eba5b6SRobert Mustacchi (PHY_OP_WRITE << 12) | (PHY_SOF << 14)); 57375eba5b6SRobert Mustacchi mdic <<= 16; 57475eba5b6SRobert Mustacchi mdic |= (u32)data; 57575eba5b6SRobert Mustacchi 57675eba5b6SRobert Mustacchi e1000_shift_out_mdi_bits_82543(hw, mdic, 32); 57775eba5b6SRobert Mustacchi 57875eba5b6SRobert Mustacchi out: 57975eba5b6SRobert Mustacchi return ret_val; 58075eba5b6SRobert Mustacchi } 58175eba5b6SRobert Mustacchi 58275eba5b6SRobert Mustacchi /** 58375eba5b6SRobert Mustacchi * e1000_raise_mdi_clk_82543 - Raise Management Data Input clock 58475eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 58575eba5b6SRobert Mustacchi * @ctrl: pointer to the control register 58675eba5b6SRobert Mustacchi * 58775eba5b6SRobert Mustacchi * Raise the management data input clock by setting the MDC bit in the control 58875eba5b6SRobert Mustacchi * register. 58975eba5b6SRobert Mustacchi **/ 59075eba5b6SRobert Mustacchi static void e1000_raise_mdi_clk_82543(struct e1000_hw *hw, u32 *ctrl) 59175eba5b6SRobert Mustacchi { 59275eba5b6SRobert Mustacchi /* 59375eba5b6SRobert Mustacchi * Raise the clock input to the Management Data Clock (by setting the 59475eba5b6SRobert Mustacchi * MDC bit), and then delay a sufficient amount of time. 59575eba5b6SRobert Mustacchi */ 59675eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL, (*ctrl | E1000_CTRL_MDC)); 59775eba5b6SRobert Mustacchi E1000_WRITE_FLUSH(hw); 59875eba5b6SRobert Mustacchi usec_delay(10); 59975eba5b6SRobert Mustacchi } 60075eba5b6SRobert Mustacchi 60175eba5b6SRobert Mustacchi /** 60275eba5b6SRobert Mustacchi * e1000_lower_mdi_clk_82543 - Lower Management Data Input clock 60375eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 60475eba5b6SRobert Mustacchi * @ctrl: pointer to the control register 60575eba5b6SRobert Mustacchi * 60675eba5b6SRobert Mustacchi * Lower the management data input clock by clearing the MDC bit in the 60775eba5b6SRobert Mustacchi * control register. 60875eba5b6SRobert Mustacchi **/ 60975eba5b6SRobert Mustacchi static void e1000_lower_mdi_clk_82543(struct e1000_hw *hw, u32 *ctrl) 61075eba5b6SRobert Mustacchi { 61175eba5b6SRobert Mustacchi /* 61275eba5b6SRobert Mustacchi * Lower the clock input to the Management Data Clock (by clearing the 61375eba5b6SRobert Mustacchi * MDC bit), and then delay a sufficient amount of time. 61475eba5b6SRobert Mustacchi */ 61575eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL, (*ctrl & ~E1000_CTRL_MDC)); 61675eba5b6SRobert Mustacchi E1000_WRITE_FLUSH(hw); 61775eba5b6SRobert Mustacchi usec_delay(10); 61875eba5b6SRobert Mustacchi } 61975eba5b6SRobert Mustacchi 62075eba5b6SRobert Mustacchi /** 62175eba5b6SRobert Mustacchi * e1000_shift_out_mdi_bits_82543 - Shift data bits our to the PHY 62275eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 62375eba5b6SRobert Mustacchi * @data: data to send to the PHY 62475eba5b6SRobert Mustacchi * @count: number of bits to shift out 62575eba5b6SRobert Mustacchi * 62675eba5b6SRobert Mustacchi * We need to shift 'count' bits out to the PHY. So, the value in the 62775eba5b6SRobert Mustacchi * "data" parameter will be shifted out to the PHY one bit at a time. 62875eba5b6SRobert Mustacchi * In order to do this, "data" must be broken down into bits. 62975eba5b6SRobert Mustacchi **/ 63075eba5b6SRobert Mustacchi static void e1000_shift_out_mdi_bits_82543(struct e1000_hw *hw, u32 data, 63175eba5b6SRobert Mustacchi u16 count) 63275eba5b6SRobert Mustacchi { 63375eba5b6SRobert Mustacchi u32 ctrl, mask; 63475eba5b6SRobert Mustacchi 63575eba5b6SRobert Mustacchi /* 63675eba5b6SRobert Mustacchi * We need to shift "count" number of bits out to the PHY. So, the 63775eba5b6SRobert Mustacchi * value in the "data" parameter will be shifted out to the PHY one 63875eba5b6SRobert Mustacchi * bit at a time. In order to do this, "data" must be broken down 63975eba5b6SRobert Mustacchi * into bits. 64075eba5b6SRobert Mustacchi */ 64175eba5b6SRobert Mustacchi mask = 0x01; 64275eba5b6SRobert Mustacchi mask <<= (count - 1); 64375eba5b6SRobert Mustacchi 64475eba5b6SRobert Mustacchi ctrl = E1000_READ_REG(hw, E1000_CTRL); 64575eba5b6SRobert Mustacchi 64675eba5b6SRobert Mustacchi /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */ 64775eba5b6SRobert Mustacchi ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR); 64875eba5b6SRobert Mustacchi 64975eba5b6SRobert Mustacchi while (mask) { 65075eba5b6SRobert Mustacchi /* 65175eba5b6SRobert Mustacchi * A "1" is shifted out to the PHY by setting the MDIO bit to 65275eba5b6SRobert Mustacchi * "1" and then raising and lowering the Management Data Clock. 65375eba5b6SRobert Mustacchi * A "0" is shifted out to the PHY by setting the MDIO bit to 65475eba5b6SRobert Mustacchi * "0" and then raising and lowering the clock. 65575eba5b6SRobert Mustacchi */ 656*42cc51e0SRobert Mustacchi if (data & mask) 657*42cc51e0SRobert Mustacchi ctrl |= E1000_CTRL_MDIO; 658*42cc51e0SRobert Mustacchi else 659*42cc51e0SRobert Mustacchi ctrl &= ~E1000_CTRL_MDIO; 66075eba5b6SRobert Mustacchi 66175eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 66275eba5b6SRobert Mustacchi E1000_WRITE_FLUSH(hw); 66375eba5b6SRobert Mustacchi 66475eba5b6SRobert Mustacchi usec_delay(10); 66575eba5b6SRobert Mustacchi 66675eba5b6SRobert Mustacchi e1000_raise_mdi_clk_82543(hw, &ctrl); 66775eba5b6SRobert Mustacchi e1000_lower_mdi_clk_82543(hw, &ctrl); 66875eba5b6SRobert Mustacchi 66975eba5b6SRobert Mustacchi mask >>= 1; 67075eba5b6SRobert Mustacchi } 67175eba5b6SRobert Mustacchi } 67275eba5b6SRobert Mustacchi 67375eba5b6SRobert Mustacchi /** 67475eba5b6SRobert Mustacchi * e1000_shift_in_mdi_bits_82543 - Shift data bits in from the PHY 67575eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 67675eba5b6SRobert Mustacchi * 67775eba5b6SRobert Mustacchi * In order to read a register from the PHY, we need to shift 18 bits 67875eba5b6SRobert Mustacchi * in from the PHY. Bits are "shifted in" by raising the clock input to 67975eba5b6SRobert Mustacchi * the PHY (setting the MDC bit), and then reading the value of the data out 68075eba5b6SRobert Mustacchi * MDIO bit. 68175eba5b6SRobert Mustacchi **/ 68275eba5b6SRobert Mustacchi static u16 e1000_shift_in_mdi_bits_82543(struct e1000_hw *hw) 68375eba5b6SRobert Mustacchi { 68475eba5b6SRobert Mustacchi u32 ctrl; 68575eba5b6SRobert Mustacchi u16 data = 0; 68675eba5b6SRobert Mustacchi u8 i; 68775eba5b6SRobert Mustacchi 68875eba5b6SRobert Mustacchi /* 68975eba5b6SRobert Mustacchi * In order to read a register from the PHY, we need to shift in a 69075eba5b6SRobert Mustacchi * total of 18 bits from the PHY. The first two bit (turnaround) 69175eba5b6SRobert Mustacchi * times are used to avoid contention on the MDIO pin when a read 69275eba5b6SRobert Mustacchi * operation is performed. These two bits are ignored by us and 69375eba5b6SRobert Mustacchi * thrown away. Bits are "shifted in" by raising the input to the 69475eba5b6SRobert Mustacchi * Management Data Clock (setting the MDC bit) and then reading the 69575eba5b6SRobert Mustacchi * value of the MDIO bit. 69675eba5b6SRobert Mustacchi */ 69775eba5b6SRobert Mustacchi ctrl = E1000_READ_REG(hw, E1000_CTRL); 69875eba5b6SRobert Mustacchi 69975eba5b6SRobert Mustacchi /* 70075eba5b6SRobert Mustacchi * Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as 70175eba5b6SRobert Mustacchi * input. 70275eba5b6SRobert Mustacchi */ 70375eba5b6SRobert Mustacchi ctrl &= ~E1000_CTRL_MDIO_DIR; 70475eba5b6SRobert Mustacchi ctrl &= ~E1000_CTRL_MDIO; 70575eba5b6SRobert Mustacchi 70675eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 70775eba5b6SRobert Mustacchi E1000_WRITE_FLUSH(hw); 70875eba5b6SRobert Mustacchi 70975eba5b6SRobert Mustacchi /* 71075eba5b6SRobert Mustacchi * Raise and lower the clock before reading in the data. This accounts 71175eba5b6SRobert Mustacchi * for the turnaround bits. The first clock occurred when we clocked 71275eba5b6SRobert Mustacchi * out the last bit of the Register Address. 71375eba5b6SRobert Mustacchi */ 71475eba5b6SRobert Mustacchi e1000_raise_mdi_clk_82543(hw, &ctrl); 71575eba5b6SRobert Mustacchi e1000_lower_mdi_clk_82543(hw, &ctrl); 71675eba5b6SRobert Mustacchi 71775eba5b6SRobert Mustacchi for (data = 0, i = 0; i < 16; i++) { 71875eba5b6SRobert Mustacchi data <<= 1; 71975eba5b6SRobert Mustacchi e1000_raise_mdi_clk_82543(hw, &ctrl); 72075eba5b6SRobert Mustacchi ctrl = E1000_READ_REG(hw, E1000_CTRL); 72175eba5b6SRobert Mustacchi /* Check to see if we shifted in a "1". */ 72275eba5b6SRobert Mustacchi if (ctrl & E1000_CTRL_MDIO) 72375eba5b6SRobert Mustacchi data |= 1; 72475eba5b6SRobert Mustacchi e1000_lower_mdi_clk_82543(hw, &ctrl); 72575eba5b6SRobert Mustacchi } 72675eba5b6SRobert Mustacchi 72775eba5b6SRobert Mustacchi e1000_raise_mdi_clk_82543(hw, &ctrl); 72875eba5b6SRobert Mustacchi e1000_lower_mdi_clk_82543(hw, &ctrl); 72975eba5b6SRobert Mustacchi 73075eba5b6SRobert Mustacchi return data; 73175eba5b6SRobert Mustacchi } 73275eba5b6SRobert Mustacchi 73375eba5b6SRobert Mustacchi /** 73475eba5b6SRobert Mustacchi * e1000_phy_force_speed_duplex_82543 - Force speed/duplex for PHY 73575eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 73675eba5b6SRobert Mustacchi * 73775eba5b6SRobert Mustacchi * Calls the function to force speed and duplex for the m88 PHY, and 73875eba5b6SRobert Mustacchi * if the PHY is not auto-negotiating and the speed is forced to 10Mbit, 73975eba5b6SRobert Mustacchi * then call the function for polarity reversal workaround. 74075eba5b6SRobert Mustacchi **/ 74175eba5b6SRobert Mustacchi static s32 e1000_phy_force_speed_duplex_82543(struct e1000_hw *hw) 74275eba5b6SRobert Mustacchi { 74375eba5b6SRobert Mustacchi s32 ret_val; 74475eba5b6SRobert Mustacchi 74575eba5b6SRobert Mustacchi DEBUGFUNC("e1000_phy_force_speed_duplex_82543"); 74675eba5b6SRobert Mustacchi 74775eba5b6SRobert Mustacchi ret_val = e1000_phy_force_speed_duplex_m88(hw); 74875eba5b6SRobert Mustacchi if (ret_val) 74975eba5b6SRobert Mustacchi goto out; 75075eba5b6SRobert Mustacchi 751*42cc51e0SRobert Mustacchi if (!hw->mac.autoneg && (hw->mac.forced_speed_duplex & 752*42cc51e0SRobert Mustacchi E1000_ALL_10_SPEED)) 75375eba5b6SRobert Mustacchi ret_val = e1000_polarity_reversal_workaround_82543(hw); 75475eba5b6SRobert Mustacchi 75575eba5b6SRobert Mustacchi out: 75675eba5b6SRobert Mustacchi return ret_val; 75775eba5b6SRobert Mustacchi } 75875eba5b6SRobert Mustacchi 75975eba5b6SRobert Mustacchi /** 76075eba5b6SRobert Mustacchi * e1000_polarity_reversal_workaround_82543 - Workaround polarity reversal 76175eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 76275eba5b6SRobert Mustacchi * 76375eba5b6SRobert Mustacchi * When forcing link to 10 Full or 10 Half, the PHY can reverse the polarity 76475eba5b6SRobert Mustacchi * inadvertently. To workaround the issue, we disable the transmitter on 76575eba5b6SRobert Mustacchi * the PHY until we have established the link partner's link parameters. 76675eba5b6SRobert Mustacchi **/ 76775eba5b6SRobert Mustacchi static s32 e1000_polarity_reversal_workaround_82543(struct e1000_hw *hw) 76875eba5b6SRobert Mustacchi { 76975eba5b6SRobert Mustacchi s32 ret_val = E1000_SUCCESS; 77075eba5b6SRobert Mustacchi u16 mii_status_reg; 77175eba5b6SRobert Mustacchi u16 i; 77275eba5b6SRobert Mustacchi bool link; 77375eba5b6SRobert Mustacchi 77475eba5b6SRobert Mustacchi if (!(hw->phy.ops.write_reg)) 77575eba5b6SRobert Mustacchi goto out; 77675eba5b6SRobert Mustacchi 77775eba5b6SRobert Mustacchi /* Polarity reversal workaround for forced 10F/10H links. */ 77875eba5b6SRobert Mustacchi 77975eba5b6SRobert Mustacchi /* Disable the transmitter on the PHY */ 78075eba5b6SRobert Mustacchi 78175eba5b6SRobert Mustacchi ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); 78275eba5b6SRobert Mustacchi if (ret_val) 78375eba5b6SRobert Mustacchi goto out; 78475eba5b6SRobert Mustacchi ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF); 78575eba5b6SRobert Mustacchi if (ret_val) 78675eba5b6SRobert Mustacchi goto out; 78775eba5b6SRobert Mustacchi 78875eba5b6SRobert Mustacchi ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); 78975eba5b6SRobert Mustacchi if (ret_val) 79075eba5b6SRobert Mustacchi goto out; 79175eba5b6SRobert Mustacchi 79275eba5b6SRobert Mustacchi /* 79375eba5b6SRobert Mustacchi * This loop will early-out if the NO link condition has been met. 79475eba5b6SRobert Mustacchi * In other words, DO NOT use e1000_phy_has_link_generic() here. 79575eba5b6SRobert Mustacchi */ 79675eba5b6SRobert Mustacchi for (i = PHY_FORCE_TIME; i > 0; i--) { 79775eba5b6SRobert Mustacchi /* 79875eba5b6SRobert Mustacchi * Read the MII Status Register and wait for Link Status bit 79975eba5b6SRobert Mustacchi * to be clear. 80075eba5b6SRobert Mustacchi */ 80175eba5b6SRobert Mustacchi 80275eba5b6SRobert Mustacchi ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &mii_status_reg); 80375eba5b6SRobert Mustacchi if (ret_val) 80475eba5b6SRobert Mustacchi goto out; 80575eba5b6SRobert Mustacchi 80675eba5b6SRobert Mustacchi ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &mii_status_reg); 80775eba5b6SRobert Mustacchi if (ret_val) 80875eba5b6SRobert Mustacchi goto out; 80975eba5b6SRobert Mustacchi 810*42cc51e0SRobert Mustacchi if (!(mii_status_reg & ~MII_SR_LINK_STATUS)) 81175eba5b6SRobert Mustacchi break; 81275eba5b6SRobert Mustacchi msec_delay_irq(100); 81375eba5b6SRobert Mustacchi } 81475eba5b6SRobert Mustacchi 81575eba5b6SRobert Mustacchi /* Recommended delay time after link has been lost */ 81675eba5b6SRobert Mustacchi msec_delay_irq(1000); 81775eba5b6SRobert Mustacchi 81875eba5b6SRobert Mustacchi /* Now we will re-enable the transmitter on the PHY */ 81975eba5b6SRobert Mustacchi 82075eba5b6SRobert Mustacchi ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); 82175eba5b6SRobert Mustacchi if (ret_val) 82275eba5b6SRobert Mustacchi goto out; 82375eba5b6SRobert Mustacchi msec_delay_irq(50); 82475eba5b6SRobert Mustacchi ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0); 82575eba5b6SRobert Mustacchi if (ret_val) 82675eba5b6SRobert Mustacchi goto out; 82775eba5b6SRobert Mustacchi msec_delay_irq(50); 82875eba5b6SRobert Mustacchi ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00); 82975eba5b6SRobert Mustacchi if (ret_val) 83075eba5b6SRobert Mustacchi goto out; 83175eba5b6SRobert Mustacchi msec_delay_irq(50); 83275eba5b6SRobert Mustacchi ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000); 83375eba5b6SRobert Mustacchi if (ret_val) 83475eba5b6SRobert Mustacchi goto out; 83575eba5b6SRobert Mustacchi 83675eba5b6SRobert Mustacchi ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); 83775eba5b6SRobert Mustacchi if (ret_val) 83875eba5b6SRobert Mustacchi goto out; 83975eba5b6SRobert Mustacchi 84075eba5b6SRobert Mustacchi /* 84175eba5b6SRobert Mustacchi * Read the MII Status Register and wait for Link Status bit 84275eba5b6SRobert Mustacchi * to be set. 84375eba5b6SRobert Mustacchi */ 84475eba5b6SRobert Mustacchi ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_TIME, 100000, &link); 84575eba5b6SRobert Mustacchi if (ret_val) 84675eba5b6SRobert Mustacchi goto out; 84775eba5b6SRobert Mustacchi 84875eba5b6SRobert Mustacchi out: 84975eba5b6SRobert Mustacchi return ret_val; 85075eba5b6SRobert Mustacchi } 85175eba5b6SRobert Mustacchi 85275eba5b6SRobert Mustacchi /** 85375eba5b6SRobert Mustacchi * e1000_phy_hw_reset_82543 - PHY hardware reset 85475eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 85575eba5b6SRobert Mustacchi * 85675eba5b6SRobert Mustacchi * Sets the PHY_RESET_DIR bit in the extended device control register 85775eba5b6SRobert Mustacchi * to put the PHY into a reset and waits for completion. Once the reset 85875eba5b6SRobert Mustacchi * has been accomplished, clear the PHY_RESET_DIR bit to take the PHY out 85975eba5b6SRobert Mustacchi * of reset. 86075eba5b6SRobert Mustacchi **/ 86175eba5b6SRobert Mustacchi static s32 e1000_phy_hw_reset_82543(struct e1000_hw *hw) 86275eba5b6SRobert Mustacchi { 86375eba5b6SRobert Mustacchi u32 ctrl_ext; 86475eba5b6SRobert Mustacchi s32 ret_val; 86575eba5b6SRobert Mustacchi 86675eba5b6SRobert Mustacchi DEBUGFUNC("e1000_phy_hw_reset_82543"); 86775eba5b6SRobert Mustacchi 86875eba5b6SRobert Mustacchi /* 86975eba5b6SRobert Mustacchi * Read the Extended Device Control Register, assert the PHY_RESET_DIR 87075eba5b6SRobert Mustacchi * bit to put the PHY into reset... 87175eba5b6SRobert Mustacchi */ 87275eba5b6SRobert Mustacchi ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT); 87375eba5b6SRobert Mustacchi ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR; 87475eba5b6SRobert Mustacchi ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA; 87575eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext); 87675eba5b6SRobert Mustacchi E1000_WRITE_FLUSH(hw); 87775eba5b6SRobert Mustacchi 87875eba5b6SRobert Mustacchi msec_delay(10); 87975eba5b6SRobert Mustacchi 88075eba5b6SRobert Mustacchi /* ...then take it out of reset. */ 88175eba5b6SRobert Mustacchi ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA; 88275eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext); 88375eba5b6SRobert Mustacchi E1000_WRITE_FLUSH(hw); 88475eba5b6SRobert Mustacchi 88575eba5b6SRobert Mustacchi usec_delay(150); 88675eba5b6SRobert Mustacchi 88775eba5b6SRobert Mustacchi if (!(hw->phy.ops.get_cfg_done)) 88875eba5b6SRobert Mustacchi return E1000_SUCCESS; 88975eba5b6SRobert Mustacchi 89075eba5b6SRobert Mustacchi ret_val = hw->phy.ops.get_cfg_done(hw); 89175eba5b6SRobert Mustacchi 89275eba5b6SRobert Mustacchi return ret_val; 89375eba5b6SRobert Mustacchi } 89475eba5b6SRobert Mustacchi 89575eba5b6SRobert Mustacchi /** 89675eba5b6SRobert Mustacchi * e1000_reset_hw_82543 - Reset hardware 89775eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 89875eba5b6SRobert Mustacchi * 89975eba5b6SRobert Mustacchi * This resets the hardware into a known state. 90075eba5b6SRobert Mustacchi **/ 90175eba5b6SRobert Mustacchi static s32 e1000_reset_hw_82543(struct e1000_hw *hw) 90275eba5b6SRobert Mustacchi { 903*42cc51e0SRobert Mustacchi u32 ctrl; 90475eba5b6SRobert Mustacchi s32 ret_val = E1000_SUCCESS; 90575eba5b6SRobert Mustacchi 90675eba5b6SRobert Mustacchi DEBUGFUNC("e1000_reset_hw_82543"); 90775eba5b6SRobert Mustacchi 90875eba5b6SRobert Mustacchi DEBUGOUT("Masking off all interrupts\n"); 90975eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff); 91075eba5b6SRobert Mustacchi 91175eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_RCTL, 0); 91275eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP); 91375eba5b6SRobert Mustacchi E1000_WRITE_FLUSH(hw); 91475eba5b6SRobert Mustacchi 91575eba5b6SRobert Mustacchi e1000_set_tbi_sbp_82543(hw, FALSE); 91675eba5b6SRobert Mustacchi 91775eba5b6SRobert Mustacchi /* 91875eba5b6SRobert Mustacchi * Delay to allow any outstanding PCI transactions to complete before 91975eba5b6SRobert Mustacchi * resetting the device 92075eba5b6SRobert Mustacchi */ 92175eba5b6SRobert Mustacchi msec_delay(10); 92275eba5b6SRobert Mustacchi 92375eba5b6SRobert Mustacchi ctrl = E1000_READ_REG(hw, E1000_CTRL); 92475eba5b6SRobert Mustacchi 92575eba5b6SRobert Mustacchi DEBUGOUT("Issuing a global reset to 82543/82544 MAC\n"); 92675eba5b6SRobert Mustacchi if (hw->mac.type == e1000_82543) { 92775eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST); 92875eba5b6SRobert Mustacchi } else { 92975eba5b6SRobert Mustacchi /* 93075eba5b6SRobert Mustacchi * The 82544 can't ACK the 64-bit write when issuing the 93175eba5b6SRobert Mustacchi * reset, so use IO-mapping as a workaround. 93275eba5b6SRobert Mustacchi */ 93375eba5b6SRobert Mustacchi E1000_WRITE_REG_IO(hw, E1000_CTRL, ctrl | E1000_CTRL_RST); 93475eba5b6SRobert Mustacchi } 93575eba5b6SRobert Mustacchi 93675eba5b6SRobert Mustacchi /* 93775eba5b6SRobert Mustacchi * After MAC reset, force reload of NVM to restore power-on 93875eba5b6SRobert Mustacchi * settings to device. 93975eba5b6SRobert Mustacchi */ 94075eba5b6SRobert Mustacchi hw->nvm.ops.reload(hw); 94175eba5b6SRobert Mustacchi msec_delay(2); 94275eba5b6SRobert Mustacchi 94375eba5b6SRobert Mustacchi /* Masking off and clearing any pending interrupts */ 94475eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff); 945*42cc51e0SRobert Mustacchi E1000_READ_REG(hw, E1000_ICR); 94675eba5b6SRobert Mustacchi 94775eba5b6SRobert Mustacchi return ret_val; 94875eba5b6SRobert Mustacchi } 94975eba5b6SRobert Mustacchi 95075eba5b6SRobert Mustacchi /** 95175eba5b6SRobert Mustacchi * e1000_init_hw_82543 - Initialize hardware 95275eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 95375eba5b6SRobert Mustacchi * 95475eba5b6SRobert Mustacchi * This inits the hardware readying it for operation. 95575eba5b6SRobert Mustacchi **/ 95675eba5b6SRobert Mustacchi static s32 e1000_init_hw_82543(struct e1000_hw *hw) 95775eba5b6SRobert Mustacchi { 95875eba5b6SRobert Mustacchi struct e1000_mac_info *mac = &hw->mac; 95975eba5b6SRobert Mustacchi struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543; 96075eba5b6SRobert Mustacchi u32 ctrl; 96175eba5b6SRobert Mustacchi s32 ret_val; 96275eba5b6SRobert Mustacchi u16 i; 96375eba5b6SRobert Mustacchi 96475eba5b6SRobert Mustacchi DEBUGFUNC("e1000_init_hw_82543"); 96575eba5b6SRobert Mustacchi 96675eba5b6SRobert Mustacchi /* Disabling VLAN filtering */ 96775eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_VET, 0); 96875eba5b6SRobert Mustacchi mac->ops.clear_vfta(hw); 96975eba5b6SRobert Mustacchi 97075eba5b6SRobert Mustacchi /* Setup the receive address. */ 97175eba5b6SRobert Mustacchi e1000_init_rx_addrs_generic(hw, mac->rar_entry_count); 97275eba5b6SRobert Mustacchi 97375eba5b6SRobert Mustacchi /* Zero out the Multicast HASH table */ 97475eba5b6SRobert Mustacchi DEBUGOUT("Zeroing the MTA\n"); 97575eba5b6SRobert Mustacchi for (i = 0; i < mac->mta_reg_count; i++) { 97675eba5b6SRobert Mustacchi E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0); 97775eba5b6SRobert Mustacchi E1000_WRITE_FLUSH(hw); 97875eba5b6SRobert Mustacchi } 97975eba5b6SRobert Mustacchi 98075eba5b6SRobert Mustacchi /* 98175eba5b6SRobert Mustacchi * Set the PCI priority bit correctly in the CTRL register. This 98275eba5b6SRobert Mustacchi * determines if the adapter gives priority to receives, or if it 98375eba5b6SRobert Mustacchi * gives equal priority to transmits and receives. 98475eba5b6SRobert Mustacchi */ 98575eba5b6SRobert Mustacchi if (hw->mac.type == e1000_82543 && dev_spec->dma_fairness) { 98675eba5b6SRobert Mustacchi ctrl = E1000_READ_REG(hw, E1000_CTRL); 98775eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_PRIOR); 98875eba5b6SRobert Mustacchi } 98975eba5b6SRobert Mustacchi 99075eba5b6SRobert Mustacchi e1000_pcix_mmrbc_workaround_generic(hw); 99175eba5b6SRobert Mustacchi 99275eba5b6SRobert Mustacchi /* Setup link and flow control */ 99375eba5b6SRobert Mustacchi ret_val = mac->ops.setup_link(hw); 99475eba5b6SRobert Mustacchi 99575eba5b6SRobert Mustacchi /* 99675eba5b6SRobert Mustacchi * Clear all of the statistics registers (clear on read). It is 99775eba5b6SRobert Mustacchi * important that we do this after we have tried to establish link 99875eba5b6SRobert Mustacchi * because the symbol error count will increment wildly if there 99975eba5b6SRobert Mustacchi * is no link. 100075eba5b6SRobert Mustacchi */ 100175eba5b6SRobert Mustacchi e1000_clear_hw_cntrs_82543(hw); 100275eba5b6SRobert Mustacchi 100375eba5b6SRobert Mustacchi return ret_val; 100475eba5b6SRobert Mustacchi } 100575eba5b6SRobert Mustacchi 100675eba5b6SRobert Mustacchi /** 100775eba5b6SRobert Mustacchi * e1000_setup_link_82543 - Setup flow control and link settings 100875eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 100975eba5b6SRobert Mustacchi * 101075eba5b6SRobert Mustacchi * Read the EEPROM to determine the initial polarity value and write the 101175eba5b6SRobert Mustacchi * extended device control register with the information before calling 101275eba5b6SRobert Mustacchi * the generic setup link function, which does the following: 101375eba5b6SRobert Mustacchi * Determines which flow control settings to use, then configures flow 101475eba5b6SRobert Mustacchi * control. Calls the appropriate media-specific link configuration 101575eba5b6SRobert Mustacchi * function. Assuming the adapter has a valid link partner, a valid link 101675eba5b6SRobert Mustacchi * should be established. Assumes the hardware has previously been reset 101775eba5b6SRobert Mustacchi * and the transmitter and receiver are not enabled. 101875eba5b6SRobert Mustacchi **/ 101975eba5b6SRobert Mustacchi static s32 e1000_setup_link_82543(struct e1000_hw *hw) 102075eba5b6SRobert Mustacchi { 102175eba5b6SRobert Mustacchi u32 ctrl_ext; 102275eba5b6SRobert Mustacchi s32 ret_val; 102375eba5b6SRobert Mustacchi u16 data; 102475eba5b6SRobert Mustacchi 102575eba5b6SRobert Mustacchi DEBUGFUNC("e1000_setup_link_82543"); 102675eba5b6SRobert Mustacchi 102775eba5b6SRobert Mustacchi /* 102875eba5b6SRobert Mustacchi * Take the 4 bits from NVM word 0xF that determine the initial 102975eba5b6SRobert Mustacchi * polarity value for the SW controlled pins, and setup the 103075eba5b6SRobert Mustacchi * Extended Device Control reg with that info. 103175eba5b6SRobert Mustacchi * This is needed because one of the SW controlled pins is used for 103275eba5b6SRobert Mustacchi * signal detection. So this should be done before phy setup. 103375eba5b6SRobert Mustacchi */ 103475eba5b6SRobert Mustacchi if (hw->mac.type == e1000_82543) { 103575eba5b6SRobert Mustacchi ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG, 1, &data); 103675eba5b6SRobert Mustacchi if (ret_val) { 103775eba5b6SRobert Mustacchi DEBUGOUT("NVM Read Error\n"); 103875eba5b6SRobert Mustacchi ret_val = -E1000_ERR_NVM; 103975eba5b6SRobert Mustacchi goto out; 104075eba5b6SRobert Mustacchi } 104175eba5b6SRobert Mustacchi ctrl_ext = ((data & NVM_WORD0F_SWPDIO_EXT_MASK) << 104275eba5b6SRobert Mustacchi NVM_SWDPIO_EXT_SHIFT); 104375eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext); 104475eba5b6SRobert Mustacchi } 104575eba5b6SRobert Mustacchi 104675eba5b6SRobert Mustacchi ret_val = e1000_setup_link_generic(hw); 104775eba5b6SRobert Mustacchi 104875eba5b6SRobert Mustacchi out: 104975eba5b6SRobert Mustacchi return ret_val; 105075eba5b6SRobert Mustacchi } 105175eba5b6SRobert Mustacchi 105275eba5b6SRobert Mustacchi /** 105375eba5b6SRobert Mustacchi * e1000_setup_copper_link_82543 - Configure copper link settings 105475eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 105575eba5b6SRobert Mustacchi * 105675eba5b6SRobert Mustacchi * Configures the link for auto-neg or forced speed and duplex. Then we check 105775eba5b6SRobert Mustacchi * for link, once link is established calls to configure collision distance 105875eba5b6SRobert Mustacchi * and flow control are called. 105975eba5b6SRobert Mustacchi **/ 106075eba5b6SRobert Mustacchi static s32 e1000_setup_copper_link_82543(struct e1000_hw *hw) 106175eba5b6SRobert Mustacchi { 106275eba5b6SRobert Mustacchi u32 ctrl; 106375eba5b6SRobert Mustacchi s32 ret_val; 106475eba5b6SRobert Mustacchi bool link; 106575eba5b6SRobert Mustacchi 106675eba5b6SRobert Mustacchi DEBUGFUNC("e1000_setup_copper_link_82543"); 106775eba5b6SRobert Mustacchi 106875eba5b6SRobert Mustacchi ctrl = E1000_READ_REG(hw, E1000_CTRL) | E1000_CTRL_SLU; 106975eba5b6SRobert Mustacchi /* 107075eba5b6SRobert Mustacchi * With 82543, we need to force speed and duplex on the MAC 107175eba5b6SRobert Mustacchi * equal to what the PHY speed and duplex configuration is. 107275eba5b6SRobert Mustacchi * In addition, we need to perform a hardware reset on the 107375eba5b6SRobert Mustacchi * PHY to take it out of reset. 107475eba5b6SRobert Mustacchi */ 107575eba5b6SRobert Mustacchi if (hw->mac.type == e1000_82543) { 107675eba5b6SRobert Mustacchi ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); 107775eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 107875eba5b6SRobert Mustacchi ret_val = hw->phy.ops.reset(hw); 107975eba5b6SRobert Mustacchi if (ret_val) 108075eba5b6SRobert Mustacchi goto out; 108175eba5b6SRobert Mustacchi } else { 108275eba5b6SRobert Mustacchi ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); 108375eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 108475eba5b6SRobert Mustacchi } 108575eba5b6SRobert Mustacchi 108675eba5b6SRobert Mustacchi /* Set MDI/MDI-X, Polarity Reversal, and downshift settings */ 108775eba5b6SRobert Mustacchi ret_val = e1000_copper_link_setup_m88(hw); 108875eba5b6SRobert Mustacchi if (ret_val) 108975eba5b6SRobert Mustacchi goto out; 109075eba5b6SRobert Mustacchi 109175eba5b6SRobert Mustacchi if (hw->mac.autoneg) { 109275eba5b6SRobert Mustacchi /* 109375eba5b6SRobert Mustacchi * Setup autoneg and flow control advertisement and perform 109475eba5b6SRobert Mustacchi * autonegotiation. 109575eba5b6SRobert Mustacchi */ 109675eba5b6SRobert Mustacchi ret_val = e1000_copper_link_autoneg(hw); 109775eba5b6SRobert Mustacchi if (ret_val) 109875eba5b6SRobert Mustacchi goto out; 109975eba5b6SRobert Mustacchi } else { 110075eba5b6SRobert Mustacchi /* 110175eba5b6SRobert Mustacchi * PHY will be set to 10H, 10F, 100H or 100F 110275eba5b6SRobert Mustacchi * depending on user settings. 110375eba5b6SRobert Mustacchi */ 110475eba5b6SRobert Mustacchi DEBUGOUT("Forcing Speed and Duplex\n"); 110575eba5b6SRobert Mustacchi ret_val = e1000_phy_force_speed_duplex_82543(hw); 110675eba5b6SRobert Mustacchi if (ret_val) { 110775eba5b6SRobert Mustacchi DEBUGOUT("Error Forcing Speed and Duplex\n"); 110875eba5b6SRobert Mustacchi goto out; 110975eba5b6SRobert Mustacchi } 111075eba5b6SRobert Mustacchi } 111175eba5b6SRobert Mustacchi 111275eba5b6SRobert Mustacchi /* 111375eba5b6SRobert Mustacchi * Check link status. Wait up to 100 microseconds for link to become 111475eba5b6SRobert Mustacchi * valid. 111575eba5b6SRobert Mustacchi */ 1116*42cc51e0SRobert Mustacchi ret_val = e1000_phy_has_link_generic(hw, COPPER_LINK_UP_LIMIT, 10, 111775eba5b6SRobert Mustacchi &link); 111875eba5b6SRobert Mustacchi if (ret_val) 111975eba5b6SRobert Mustacchi goto out; 112075eba5b6SRobert Mustacchi 112175eba5b6SRobert Mustacchi 112275eba5b6SRobert Mustacchi if (link) { 112375eba5b6SRobert Mustacchi DEBUGOUT("Valid link established!!!\n"); 112475eba5b6SRobert Mustacchi /* Config the MAC and PHY after link is up */ 112575eba5b6SRobert Mustacchi if (hw->mac.type == e1000_82544) { 112675eba5b6SRobert Mustacchi hw->mac.ops.config_collision_dist(hw); 112775eba5b6SRobert Mustacchi } else { 112875eba5b6SRobert Mustacchi ret_val = e1000_config_mac_to_phy_82543(hw); 112975eba5b6SRobert Mustacchi if (ret_val) 113075eba5b6SRobert Mustacchi goto out; 113175eba5b6SRobert Mustacchi } 113275eba5b6SRobert Mustacchi ret_val = e1000_config_fc_after_link_up_generic(hw); 113375eba5b6SRobert Mustacchi } else { 113475eba5b6SRobert Mustacchi DEBUGOUT("Unable to establish link!!!\n"); 113575eba5b6SRobert Mustacchi } 113675eba5b6SRobert Mustacchi 113775eba5b6SRobert Mustacchi out: 113875eba5b6SRobert Mustacchi return ret_val; 113975eba5b6SRobert Mustacchi } 114075eba5b6SRobert Mustacchi 114175eba5b6SRobert Mustacchi /** 114275eba5b6SRobert Mustacchi * e1000_setup_fiber_link_82543 - Setup link for fiber 114375eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 114475eba5b6SRobert Mustacchi * 114575eba5b6SRobert Mustacchi * Configures collision distance and flow control for fiber links. Upon 114675eba5b6SRobert Mustacchi * successful setup, poll for link. 114775eba5b6SRobert Mustacchi **/ 114875eba5b6SRobert Mustacchi static s32 e1000_setup_fiber_link_82543(struct e1000_hw *hw) 114975eba5b6SRobert Mustacchi { 115075eba5b6SRobert Mustacchi u32 ctrl; 115175eba5b6SRobert Mustacchi s32 ret_val; 115275eba5b6SRobert Mustacchi 115375eba5b6SRobert Mustacchi DEBUGFUNC("e1000_setup_fiber_link_82543"); 115475eba5b6SRobert Mustacchi 115575eba5b6SRobert Mustacchi ctrl = E1000_READ_REG(hw, E1000_CTRL); 115675eba5b6SRobert Mustacchi 115775eba5b6SRobert Mustacchi /* Take the link out of reset */ 115875eba5b6SRobert Mustacchi ctrl &= ~E1000_CTRL_LRST; 115975eba5b6SRobert Mustacchi 116075eba5b6SRobert Mustacchi hw->mac.ops.config_collision_dist(hw); 116175eba5b6SRobert Mustacchi 116275eba5b6SRobert Mustacchi ret_val = e1000_commit_fc_settings_generic(hw); 116375eba5b6SRobert Mustacchi if (ret_val) 116475eba5b6SRobert Mustacchi goto out; 116575eba5b6SRobert Mustacchi 116675eba5b6SRobert Mustacchi DEBUGOUT("Auto-negotiation enabled\n"); 116775eba5b6SRobert Mustacchi 116875eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 116975eba5b6SRobert Mustacchi E1000_WRITE_FLUSH(hw); 117075eba5b6SRobert Mustacchi msec_delay(1); 117175eba5b6SRobert Mustacchi 117275eba5b6SRobert Mustacchi /* 117375eba5b6SRobert Mustacchi * For these adapters, the SW definable pin 1 is cleared when the 117475eba5b6SRobert Mustacchi * optics detect a signal. If we have a signal, then poll for a 117575eba5b6SRobert Mustacchi * "Link-Up" indication. 117675eba5b6SRobert Mustacchi */ 1177*42cc51e0SRobert Mustacchi if (!(E1000_READ_REG(hw, E1000_CTRL) & E1000_CTRL_SWDPIN1)) 117875eba5b6SRobert Mustacchi ret_val = e1000_poll_fiber_serdes_link_generic(hw); 1179*42cc51e0SRobert Mustacchi else 118075eba5b6SRobert Mustacchi DEBUGOUT("No signal detected\n"); 118175eba5b6SRobert Mustacchi 118275eba5b6SRobert Mustacchi out: 118375eba5b6SRobert Mustacchi return ret_val; 118475eba5b6SRobert Mustacchi } 118575eba5b6SRobert Mustacchi 118675eba5b6SRobert Mustacchi /** 118775eba5b6SRobert Mustacchi * e1000_check_for_copper_link_82543 - Check for link (Copper) 118875eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 118975eba5b6SRobert Mustacchi * 119075eba5b6SRobert Mustacchi * Checks the phy for link, if link exists, do the following: 119175eba5b6SRobert Mustacchi * - check for downshift 119275eba5b6SRobert Mustacchi * - do polarity workaround (if necessary) 119375eba5b6SRobert Mustacchi * - configure collision distance 119475eba5b6SRobert Mustacchi * - configure flow control after link up 119575eba5b6SRobert Mustacchi * - configure tbi compatibility 119675eba5b6SRobert Mustacchi **/ 119775eba5b6SRobert Mustacchi static s32 e1000_check_for_copper_link_82543(struct e1000_hw *hw) 119875eba5b6SRobert Mustacchi { 119975eba5b6SRobert Mustacchi struct e1000_mac_info *mac = &hw->mac; 120075eba5b6SRobert Mustacchi u32 icr, rctl; 120175eba5b6SRobert Mustacchi s32 ret_val; 120275eba5b6SRobert Mustacchi u16 speed, duplex; 120375eba5b6SRobert Mustacchi bool link; 120475eba5b6SRobert Mustacchi 120575eba5b6SRobert Mustacchi DEBUGFUNC("e1000_check_for_copper_link_82543"); 120675eba5b6SRobert Mustacchi 120775eba5b6SRobert Mustacchi if (!mac->get_link_status) { 120875eba5b6SRobert Mustacchi ret_val = E1000_SUCCESS; 120975eba5b6SRobert Mustacchi goto out; 121075eba5b6SRobert Mustacchi } 121175eba5b6SRobert Mustacchi 121275eba5b6SRobert Mustacchi ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link); 121375eba5b6SRobert Mustacchi if (ret_val) 121475eba5b6SRobert Mustacchi goto out; 121575eba5b6SRobert Mustacchi 121675eba5b6SRobert Mustacchi if (!link) 121775eba5b6SRobert Mustacchi goto out; /* No link detected */ 121875eba5b6SRobert Mustacchi 121975eba5b6SRobert Mustacchi mac->get_link_status = FALSE; 122075eba5b6SRobert Mustacchi 122175eba5b6SRobert Mustacchi e1000_check_downshift_generic(hw); 122275eba5b6SRobert Mustacchi 122375eba5b6SRobert Mustacchi /* 122475eba5b6SRobert Mustacchi * If we are forcing speed/duplex, then we can return since 122575eba5b6SRobert Mustacchi * we have already determined whether we have link or not. 122675eba5b6SRobert Mustacchi */ 122775eba5b6SRobert Mustacchi if (!mac->autoneg) { 122875eba5b6SRobert Mustacchi /* 122975eba5b6SRobert Mustacchi * If speed and duplex are forced to 10H or 10F, then we will 123075eba5b6SRobert Mustacchi * implement the polarity reversal workaround. We disable 123175eba5b6SRobert Mustacchi * interrupts first, and upon returning, place the devices 123275eba5b6SRobert Mustacchi * interrupt state to its previous value except for the link 123375eba5b6SRobert Mustacchi * status change interrupt which will happened due to the 123475eba5b6SRobert Mustacchi * execution of this workaround. 123575eba5b6SRobert Mustacchi */ 123675eba5b6SRobert Mustacchi if (mac->forced_speed_duplex & E1000_ALL_10_SPEED) { 123775eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_IMC, 0xFFFFFFFF); 123875eba5b6SRobert Mustacchi ret_val = e1000_polarity_reversal_workaround_82543(hw); 123975eba5b6SRobert Mustacchi icr = E1000_READ_REG(hw, E1000_ICR); 124075eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_ICS, (icr & ~E1000_ICS_LSC)); 124175eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_IMS, IMS_ENABLE_MASK); 124275eba5b6SRobert Mustacchi } 124375eba5b6SRobert Mustacchi 124475eba5b6SRobert Mustacchi ret_val = -E1000_ERR_CONFIG; 124575eba5b6SRobert Mustacchi goto out; 124675eba5b6SRobert Mustacchi } 124775eba5b6SRobert Mustacchi 124875eba5b6SRobert Mustacchi /* 124975eba5b6SRobert Mustacchi * We have a M88E1000 PHY and Auto-Neg is enabled. If we 125075eba5b6SRobert Mustacchi * have Si on board that is 82544 or newer, Auto 125175eba5b6SRobert Mustacchi * Speed Detection takes care of MAC speed/duplex 125275eba5b6SRobert Mustacchi * configuration. So we only need to configure Collision 125375eba5b6SRobert Mustacchi * Distance in the MAC. Otherwise, we need to force 125475eba5b6SRobert Mustacchi * speed/duplex on the MAC to the current PHY speed/duplex 125575eba5b6SRobert Mustacchi * settings. 125675eba5b6SRobert Mustacchi */ 125775eba5b6SRobert Mustacchi if (mac->type == e1000_82544) 125875eba5b6SRobert Mustacchi hw->mac.ops.config_collision_dist(hw); 125975eba5b6SRobert Mustacchi else { 126075eba5b6SRobert Mustacchi ret_val = e1000_config_mac_to_phy_82543(hw); 126175eba5b6SRobert Mustacchi if (ret_val) { 126275eba5b6SRobert Mustacchi DEBUGOUT("Error configuring MAC to PHY settings\n"); 126375eba5b6SRobert Mustacchi goto out; 126475eba5b6SRobert Mustacchi } 126575eba5b6SRobert Mustacchi } 126675eba5b6SRobert Mustacchi 126775eba5b6SRobert Mustacchi /* 126875eba5b6SRobert Mustacchi * Configure Flow Control now that Auto-Neg has completed. 126975eba5b6SRobert Mustacchi * First, we need to restore the desired flow control 127075eba5b6SRobert Mustacchi * settings because we may have had to re-autoneg with a 127175eba5b6SRobert Mustacchi * different link partner. 127275eba5b6SRobert Mustacchi */ 127375eba5b6SRobert Mustacchi ret_val = e1000_config_fc_after_link_up_generic(hw); 1274*42cc51e0SRobert Mustacchi if (ret_val) 127575eba5b6SRobert Mustacchi DEBUGOUT("Error configuring flow control\n"); 127675eba5b6SRobert Mustacchi 127775eba5b6SRobert Mustacchi /* 127875eba5b6SRobert Mustacchi * At this point we know that we are on copper and we have 127975eba5b6SRobert Mustacchi * auto-negotiated link. These are conditions for checking the link 128075eba5b6SRobert Mustacchi * partner capability register. We use the link speed to determine if 128175eba5b6SRobert Mustacchi * TBI compatibility needs to be turned on or off. If the link is not 128275eba5b6SRobert Mustacchi * at gigabit speed, then TBI compatibility is not needed. If we are 128375eba5b6SRobert Mustacchi * at gigabit speed, we turn on TBI compatibility. 128475eba5b6SRobert Mustacchi */ 128575eba5b6SRobert Mustacchi if (e1000_tbi_compatibility_enabled_82543(hw)) { 128675eba5b6SRobert Mustacchi ret_val = mac->ops.get_link_up_info(hw, &speed, &duplex); 128775eba5b6SRobert Mustacchi if (ret_val) { 128875eba5b6SRobert Mustacchi DEBUGOUT("Error getting link speed and duplex\n"); 128975eba5b6SRobert Mustacchi return ret_val; 129075eba5b6SRobert Mustacchi } 129175eba5b6SRobert Mustacchi if (speed != SPEED_1000) { 129275eba5b6SRobert Mustacchi /* 129375eba5b6SRobert Mustacchi * If link speed is not set to gigabit speed, 129475eba5b6SRobert Mustacchi * we do not need to enable TBI compatibility. 129575eba5b6SRobert Mustacchi */ 129675eba5b6SRobert Mustacchi if (e1000_tbi_sbp_enabled_82543(hw)) { 129775eba5b6SRobert Mustacchi /* 129875eba5b6SRobert Mustacchi * If we previously were in the mode, 129975eba5b6SRobert Mustacchi * turn it off. 130075eba5b6SRobert Mustacchi */ 130175eba5b6SRobert Mustacchi e1000_set_tbi_sbp_82543(hw, FALSE); 130275eba5b6SRobert Mustacchi rctl = E1000_READ_REG(hw, E1000_RCTL); 130375eba5b6SRobert Mustacchi rctl &= ~E1000_RCTL_SBP; 130475eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_RCTL, rctl); 130575eba5b6SRobert Mustacchi } 130675eba5b6SRobert Mustacchi } else { 130775eba5b6SRobert Mustacchi /* 130875eba5b6SRobert Mustacchi * If TBI compatibility is was previously off, 130975eba5b6SRobert Mustacchi * turn it on. For compatibility with a TBI link 131075eba5b6SRobert Mustacchi * partner, we will store bad packets. Some 131175eba5b6SRobert Mustacchi * frames have an additional byte on the end and 131275eba5b6SRobert Mustacchi * will look like CRC errors to to the hardware. 131375eba5b6SRobert Mustacchi */ 131475eba5b6SRobert Mustacchi if (!e1000_tbi_sbp_enabled_82543(hw)) { 131575eba5b6SRobert Mustacchi e1000_set_tbi_sbp_82543(hw, TRUE); 131675eba5b6SRobert Mustacchi rctl = E1000_READ_REG(hw, E1000_RCTL); 131775eba5b6SRobert Mustacchi rctl |= E1000_RCTL_SBP; 131875eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_RCTL, rctl); 131975eba5b6SRobert Mustacchi } 132075eba5b6SRobert Mustacchi } 132175eba5b6SRobert Mustacchi } 132275eba5b6SRobert Mustacchi out: 132375eba5b6SRobert Mustacchi return ret_val; 132475eba5b6SRobert Mustacchi } 132575eba5b6SRobert Mustacchi 132675eba5b6SRobert Mustacchi /** 132775eba5b6SRobert Mustacchi * e1000_check_for_fiber_link_82543 - Check for link (Fiber) 132875eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 132975eba5b6SRobert Mustacchi * 133075eba5b6SRobert Mustacchi * Checks for link up on the hardware. If link is not up and we have 133175eba5b6SRobert Mustacchi * a signal, then we need to force link up. 133275eba5b6SRobert Mustacchi **/ 133375eba5b6SRobert Mustacchi static s32 e1000_check_for_fiber_link_82543(struct e1000_hw *hw) 133475eba5b6SRobert Mustacchi { 133575eba5b6SRobert Mustacchi struct e1000_mac_info *mac = &hw->mac; 133675eba5b6SRobert Mustacchi u32 rxcw, ctrl, status; 133775eba5b6SRobert Mustacchi s32 ret_val = E1000_SUCCESS; 133875eba5b6SRobert Mustacchi 133975eba5b6SRobert Mustacchi DEBUGFUNC("e1000_check_for_fiber_link_82543"); 134075eba5b6SRobert Mustacchi 134175eba5b6SRobert Mustacchi ctrl = E1000_READ_REG(hw, E1000_CTRL); 134275eba5b6SRobert Mustacchi status = E1000_READ_REG(hw, E1000_STATUS); 134375eba5b6SRobert Mustacchi rxcw = E1000_READ_REG(hw, E1000_RXCW); 134475eba5b6SRobert Mustacchi 134575eba5b6SRobert Mustacchi /* 134675eba5b6SRobert Mustacchi * If we don't have link (auto-negotiation failed or link partner 134775eba5b6SRobert Mustacchi * cannot auto-negotiate), the cable is plugged in (we have signal), 134875eba5b6SRobert Mustacchi * and our link partner is not trying to auto-negotiate with us (we 134975eba5b6SRobert Mustacchi * are receiving idles or data), we need to force link up. We also 135075eba5b6SRobert Mustacchi * need to give auto-negotiation time to complete, in case the cable 135175eba5b6SRobert Mustacchi * was just plugged in. The autoneg_failed flag does this. 135275eba5b6SRobert Mustacchi */ 135375eba5b6SRobert Mustacchi /* (ctrl & E1000_CTRL_SWDPIN1) == 0 == have signal */ 135475eba5b6SRobert Mustacchi if ((!(ctrl & E1000_CTRL_SWDPIN1)) && 135575eba5b6SRobert Mustacchi (!(status & E1000_STATUS_LU)) && 135675eba5b6SRobert Mustacchi (!(rxcw & E1000_RXCW_C))) { 1357*42cc51e0SRobert Mustacchi if (!mac->autoneg_failed) { 1358*42cc51e0SRobert Mustacchi mac->autoneg_failed = TRUE; 135975eba5b6SRobert Mustacchi ret_val = 0; 136075eba5b6SRobert Mustacchi goto out; 136175eba5b6SRobert Mustacchi } 136275eba5b6SRobert Mustacchi DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n"); 136375eba5b6SRobert Mustacchi 136475eba5b6SRobert Mustacchi /* Disable auto-negotiation in the TXCW register */ 136575eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_TXCW, (mac->txcw & ~E1000_TXCW_ANE)); 136675eba5b6SRobert Mustacchi 136775eba5b6SRobert Mustacchi /* Force link-up and also force full-duplex. */ 136875eba5b6SRobert Mustacchi ctrl = E1000_READ_REG(hw, E1000_CTRL); 136975eba5b6SRobert Mustacchi ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); 137075eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 137175eba5b6SRobert Mustacchi 137275eba5b6SRobert Mustacchi /* Configure Flow Control after forcing link up. */ 137375eba5b6SRobert Mustacchi ret_val = e1000_config_fc_after_link_up_generic(hw); 137475eba5b6SRobert Mustacchi if (ret_val) { 137575eba5b6SRobert Mustacchi DEBUGOUT("Error configuring flow control\n"); 137675eba5b6SRobert Mustacchi goto out; 137775eba5b6SRobert Mustacchi } 137875eba5b6SRobert Mustacchi } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { 137975eba5b6SRobert Mustacchi /* 138075eba5b6SRobert Mustacchi * If we are forcing link and we are receiving /C/ ordered 138175eba5b6SRobert Mustacchi * sets, re-enable auto-negotiation in the TXCW register 138275eba5b6SRobert Mustacchi * and disable forced link in the Device Control register 138375eba5b6SRobert Mustacchi * in an attempt to auto-negotiate with our link partner. 138475eba5b6SRobert Mustacchi */ 138575eba5b6SRobert Mustacchi DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n"); 138675eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_TXCW, mac->txcw); 138775eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL, (ctrl & ~E1000_CTRL_SLU)); 138875eba5b6SRobert Mustacchi 138975eba5b6SRobert Mustacchi mac->serdes_has_link = TRUE; 139075eba5b6SRobert Mustacchi } 139175eba5b6SRobert Mustacchi 139275eba5b6SRobert Mustacchi out: 139375eba5b6SRobert Mustacchi return ret_val; 139475eba5b6SRobert Mustacchi } 139575eba5b6SRobert Mustacchi 139675eba5b6SRobert Mustacchi /** 139775eba5b6SRobert Mustacchi * e1000_config_mac_to_phy_82543 - Configure MAC to PHY settings 139875eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 139975eba5b6SRobert Mustacchi * 140075eba5b6SRobert Mustacchi * For the 82543 silicon, we need to set the MAC to match the settings 140175eba5b6SRobert Mustacchi * of the PHY, even if the PHY is auto-negotiating. 140275eba5b6SRobert Mustacchi **/ 140375eba5b6SRobert Mustacchi static s32 e1000_config_mac_to_phy_82543(struct e1000_hw *hw) 140475eba5b6SRobert Mustacchi { 140575eba5b6SRobert Mustacchi u32 ctrl; 140675eba5b6SRobert Mustacchi s32 ret_val = E1000_SUCCESS; 140775eba5b6SRobert Mustacchi u16 phy_data; 140875eba5b6SRobert Mustacchi 140975eba5b6SRobert Mustacchi DEBUGFUNC("e1000_config_mac_to_phy_82543"); 141075eba5b6SRobert Mustacchi 141175eba5b6SRobert Mustacchi if (!(hw->phy.ops.read_reg)) 141275eba5b6SRobert Mustacchi goto out; 141375eba5b6SRobert Mustacchi 141475eba5b6SRobert Mustacchi /* Set the bits to force speed and duplex */ 141575eba5b6SRobert Mustacchi ctrl = E1000_READ_REG(hw, E1000_CTRL); 141675eba5b6SRobert Mustacchi ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); 141775eba5b6SRobert Mustacchi ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS); 141875eba5b6SRobert Mustacchi 141975eba5b6SRobert Mustacchi /* 142075eba5b6SRobert Mustacchi * Set up duplex in the Device Control and Transmit Control 142175eba5b6SRobert Mustacchi * registers depending on negotiated values. 142275eba5b6SRobert Mustacchi */ 142375eba5b6SRobert Mustacchi ret_val = hw->phy.ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); 142475eba5b6SRobert Mustacchi if (ret_val) 142575eba5b6SRobert Mustacchi goto out; 142675eba5b6SRobert Mustacchi 142775eba5b6SRobert Mustacchi ctrl &= ~E1000_CTRL_FD; 142875eba5b6SRobert Mustacchi if (phy_data & M88E1000_PSSR_DPLX) 142975eba5b6SRobert Mustacchi ctrl |= E1000_CTRL_FD; 143075eba5b6SRobert Mustacchi 143175eba5b6SRobert Mustacchi hw->mac.ops.config_collision_dist(hw); 143275eba5b6SRobert Mustacchi 143375eba5b6SRobert Mustacchi /* 143475eba5b6SRobert Mustacchi * Set up speed in the Device Control register depending on 143575eba5b6SRobert Mustacchi * negotiated values. 143675eba5b6SRobert Mustacchi */ 143775eba5b6SRobert Mustacchi if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) 143875eba5b6SRobert Mustacchi ctrl |= E1000_CTRL_SPD_1000; 143975eba5b6SRobert Mustacchi else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS) 144075eba5b6SRobert Mustacchi ctrl |= E1000_CTRL_SPD_100; 144175eba5b6SRobert Mustacchi 144275eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 144375eba5b6SRobert Mustacchi 144475eba5b6SRobert Mustacchi out: 144575eba5b6SRobert Mustacchi return ret_val; 144675eba5b6SRobert Mustacchi } 144775eba5b6SRobert Mustacchi 144875eba5b6SRobert Mustacchi /** 144975eba5b6SRobert Mustacchi * e1000_write_vfta_82543 - Write value to VLAN filter table 145075eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 145175eba5b6SRobert Mustacchi * @offset: the 32-bit offset in which to write the value to. 145275eba5b6SRobert Mustacchi * @value: the 32-bit value to write at location offset. 145375eba5b6SRobert Mustacchi * 145475eba5b6SRobert Mustacchi * This writes a 32-bit value to a 32-bit offset in the VLAN filter 145575eba5b6SRobert Mustacchi * table. 145675eba5b6SRobert Mustacchi **/ 145775eba5b6SRobert Mustacchi static void e1000_write_vfta_82543(struct e1000_hw *hw, u32 offset, u32 value) 145875eba5b6SRobert Mustacchi { 145975eba5b6SRobert Mustacchi u32 temp; 146075eba5b6SRobert Mustacchi 146175eba5b6SRobert Mustacchi DEBUGFUNC("e1000_write_vfta_82543"); 146275eba5b6SRobert Mustacchi 146375eba5b6SRobert Mustacchi if ((hw->mac.type == e1000_82544) && (offset & 1)) { 146475eba5b6SRobert Mustacchi temp = E1000_READ_REG_ARRAY(hw, E1000_VFTA, offset - 1); 146575eba5b6SRobert Mustacchi E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value); 146675eba5b6SRobert Mustacchi E1000_WRITE_FLUSH(hw); 146775eba5b6SRobert Mustacchi E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset - 1, temp); 146875eba5b6SRobert Mustacchi E1000_WRITE_FLUSH(hw); 146975eba5b6SRobert Mustacchi } else { 147075eba5b6SRobert Mustacchi e1000_write_vfta_generic(hw, offset, value); 147175eba5b6SRobert Mustacchi } 147275eba5b6SRobert Mustacchi } 147375eba5b6SRobert Mustacchi 147475eba5b6SRobert Mustacchi /** 147575eba5b6SRobert Mustacchi * e1000_led_on_82543 - Turn on SW controllable LED 147675eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 147775eba5b6SRobert Mustacchi * 147875eba5b6SRobert Mustacchi * Turns the SW defined LED on. 147975eba5b6SRobert Mustacchi **/ 148075eba5b6SRobert Mustacchi static s32 e1000_led_on_82543(struct e1000_hw *hw) 148175eba5b6SRobert Mustacchi { 148275eba5b6SRobert Mustacchi u32 ctrl = E1000_READ_REG(hw, E1000_CTRL); 148375eba5b6SRobert Mustacchi 148475eba5b6SRobert Mustacchi DEBUGFUNC("e1000_led_on_82543"); 148575eba5b6SRobert Mustacchi 148675eba5b6SRobert Mustacchi if (hw->mac.type == e1000_82544 && 148775eba5b6SRobert Mustacchi hw->phy.media_type == e1000_media_type_copper) { 148875eba5b6SRobert Mustacchi /* Clear SW-definable Pin 0 to turn on the LED */ 148975eba5b6SRobert Mustacchi ctrl &= ~E1000_CTRL_SWDPIN0; 149075eba5b6SRobert Mustacchi ctrl |= E1000_CTRL_SWDPIO0; 149175eba5b6SRobert Mustacchi } else { 149275eba5b6SRobert Mustacchi /* Fiber 82544 and all 82543 use this method */ 149375eba5b6SRobert Mustacchi ctrl |= E1000_CTRL_SWDPIN0; 149475eba5b6SRobert Mustacchi ctrl |= E1000_CTRL_SWDPIO0; 149575eba5b6SRobert Mustacchi } 149675eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 149775eba5b6SRobert Mustacchi 149875eba5b6SRobert Mustacchi return E1000_SUCCESS; 149975eba5b6SRobert Mustacchi } 150075eba5b6SRobert Mustacchi 150175eba5b6SRobert Mustacchi /** 150275eba5b6SRobert Mustacchi * e1000_led_off_82543 - Turn off SW controllable LED 150375eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 150475eba5b6SRobert Mustacchi * 150575eba5b6SRobert Mustacchi * Turns the SW defined LED off. 150675eba5b6SRobert Mustacchi **/ 150775eba5b6SRobert Mustacchi static s32 e1000_led_off_82543(struct e1000_hw *hw) 150875eba5b6SRobert Mustacchi { 150975eba5b6SRobert Mustacchi u32 ctrl = E1000_READ_REG(hw, E1000_CTRL); 151075eba5b6SRobert Mustacchi 151175eba5b6SRobert Mustacchi DEBUGFUNC("e1000_led_off_82543"); 151275eba5b6SRobert Mustacchi 151375eba5b6SRobert Mustacchi if (hw->mac.type == e1000_82544 && 151475eba5b6SRobert Mustacchi hw->phy.media_type == e1000_media_type_copper) { 151575eba5b6SRobert Mustacchi /* Set SW-definable Pin 0 to turn off the LED */ 151675eba5b6SRobert Mustacchi ctrl |= E1000_CTRL_SWDPIN0; 151775eba5b6SRobert Mustacchi ctrl |= E1000_CTRL_SWDPIO0; 151875eba5b6SRobert Mustacchi } else { 151975eba5b6SRobert Mustacchi ctrl &= ~E1000_CTRL_SWDPIN0; 152075eba5b6SRobert Mustacchi ctrl |= E1000_CTRL_SWDPIO0; 152175eba5b6SRobert Mustacchi } 152275eba5b6SRobert Mustacchi E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 152375eba5b6SRobert Mustacchi 152475eba5b6SRobert Mustacchi return E1000_SUCCESS; 152575eba5b6SRobert Mustacchi } 152675eba5b6SRobert Mustacchi 152775eba5b6SRobert Mustacchi /** 152875eba5b6SRobert Mustacchi * e1000_clear_hw_cntrs_82543 - Clear device specific hardware counters 152975eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 153075eba5b6SRobert Mustacchi * 153175eba5b6SRobert Mustacchi * Clears the hardware counters by reading the counter registers. 153275eba5b6SRobert Mustacchi **/ 153375eba5b6SRobert Mustacchi static void e1000_clear_hw_cntrs_82543(struct e1000_hw *hw) 153475eba5b6SRobert Mustacchi { 153575eba5b6SRobert Mustacchi DEBUGFUNC("e1000_clear_hw_cntrs_82543"); 153675eba5b6SRobert Mustacchi 153775eba5b6SRobert Mustacchi e1000_clear_hw_cntrs_base_generic(hw); 153875eba5b6SRobert Mustacchi 153975eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_PRC64); 154075eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_PRC127); 154175eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_PRC255); 154275eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_PRC511); 154375eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_PRC1023); 154475eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_PRC1522); 154575eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_PTC64); 154675eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_PTC127); 154775eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_PTC255); 154875eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_PTC511); 154975eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_PTC1023); 155075eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_PTC1522); 155175eba5b6SRobert Mustacchi 155275eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_ALGNERRC); 155375eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_RXERRC); 155475eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_TNCRS); 155575eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_CEXTERR); 155675eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_TSCTC); 155775eba5b6SRobert Mustacchi E1000_READ_REG(hw, E1000_TSCTFC); 155875eba5b6SRobert Mustacchi } 155975eba5b6SRobert Mustacchi 156075eba5b6SRobert Mustacchi /** 156175eba5b6SRobert Mustacchi * e1000_read_mac_addr_82543 - Read device MAC address 156275eba5b6SRobert Mustacchi * @hw: pointer to the HW structure 156375eba5b6SRobert Mustacchi * 156475eba5b6SRobert Mustacchi * Reads the device MAC address from the EEPROM and stores the value. 156575eba5b6SRobert Mustacchi * Since devices with two ports use the same EEPROM, we increment the 156675eba5b6SRobert Mustacchi * last bit in the MAC address for the second port. 156775eba5b6SRobert Mustacchi * 156875eba5b6SRobert Mustacchi **/ 156975eba5b6SRobert Mustacchi s32 e1000_read_mac_addr_82543(struct e1000_hw *hw) 157075eba5b6SRobert Mustacchi { 157175eba5b6SRobert Mustacchi s32 ret_val = E1000_SUCCESS; 157275eba5b6SRobert Mustacchi u16 offset, nvm_data, i; 157375eba5b6SRobert Mustacchi 157475eba5b6SRobert Mustacchi DEBUGFUNC("e1000_read_mac_addr"); 157575eba5b6SRobert Mustacchi 157675eba5b6SRobert Mustacchi for (i = 0; i < ETH_ADDR_LEN; i += 2) { 157775eba5b6SRobert Mustacchi offset = i >> 1; 157875eba5b6SRobert Mustacchi ret_val = hw->nvm.ops.read(hw, offset, 1, &nvm_data); 157975eba5b6SRobert Mustacchi if (ret_val) { 158075eba5b6SRobert Mustacchi DEBUGOUT("NVM Read Error\n"); 158175eba5b6SRobert Mustacchi goto out; 158275eba5b6SRobert Mustacchi } 158375eba5b6SRobert Mustacchi hw->mac.perm_addr[i] = (u8)(nvm_data & 0xFF); 158475eba5b6SRobert Mustacchi hw->mac.perm_addr[i+1] = (u8)(nvm_data >> 8); 158575eba5b6SRobert Mustacchi } 158675eba5b6SRobert Mustacchi 158775eba5b6SRobert Mustacchi /* Flip last bit of mac address if we're on second port */ 158875eba5b6SRobert Mustacchi if (hw->bus.func == E1000_FUNC_1) 158975eba5b6SRobert Mustacchi hw->mac.perm_addr[5] ^= 1; 159075eba5b6SRobert Mustacchi 159175eba5b6SRobert Mustacchi for (i = 0; i < ETH_ADDR_LEN; i++) 159275eba5b6SRobert Mustacchi hw->mac.addr[i] = hw->mac.perm_addr[i]; 159375eba5b6SRobert Mustacchi 159475eba5b6SRobert Mustacchi out: 159575eba5b6SRobert Mustacchi return ret_val; 159675eba5b6SRobert Mustacchi } 1597