fp@2285: /*******************************************************************************
fp@2285: 
fp@2285:   Intel PRO/1000 Linux driver
fp@2285:   Copyright(c) 1999 - 2009 Intel Corporation.
fp@2285: 
fp@2285:   This program is free software; you can redistribute it and/or modify it
fp@2285:   under the terms and conditions of the GNU General Public License,
fp@2285:   version 2, as published by the Free Software Foundation.
fp@2285: 
fp@2285:   This program is distributed in the hope it will be useful, but WITHOUT
fp@2285:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fp@2285:   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
fp@2285:   more details.
fp@2285: 
fp@2285:   You should have received a copy of the GNU General Public License along with
fp@2285:   this program; if not, write to the Free Software Foundation, Inc.,
fp@2285:   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
fp@2285: 
fp@2285:   The full GNU General Public License is included in this distribution in
fp@2285:   the file called "COPYING".
fp@2285: 
fp@2285:   Contact Information:
fp@2285:   Linux NICS <linux.nics@intel.com>
fp@2285:   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
fp@2285:   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
fp@2285: 
fp@2285: *******************************************************************************/
fp@2285: 
fp@2285: /*
fp@2285:  * 82571EB Gigabit Ethernet Controller
fp@2285:  * 82571EB Gigabit Ethernet Controller (Copper)
fp@2285:  * 82571EB Gigabit Ethernet Controller (Fiber)
fp@2285:  * 82571EB Dual Port Gigabit Mezzanine Adapter
fp@2285:  * 82571EB Quad Port Gigabit Mezzanine Adapter
fp@2285:  * 82571PT Gigabit PT Quad Port Server ExpressModule
fp@2285:  * 82572EI Gigabit Ethernet Controller (Copper)
fp@2285:  * 82572EI Gigabit Ethernet Controller (Fiber)
fp@2285:  * 82572EI Gigabit Ethernet Controller
fp@2285:  * 82573V Gigabit Ethernet Controller (Copper)
fp@2285:  * 82573E Gigabit Ethernet Controller (Copper)
fp@2285:  * 82573L Gigabit Ethernet Controller
fp@2285:  * 82574L Gigabit Network Connection
fp@2285:  * 82583V Gigabit Network Connection
fp@2285:  */
fp@2285: 
fp@2285: #include "e1000.h"
fp@2285: 
fp@2285: #define ID_LED_RESERVED_F746 0xF746
fp@2285: #define ID_LED_DEFAULT_82573 ((ID_LED_DEF1_DEF2 << 12) | \
fp@2285: 			      (ID_LED_OFF1_ON2  <<  8) | \
fp@2285: 			      (ID_LED_DEF1_DEF2 <<  4) | \
fp@2285: 			      (ID_LED_DEF1_DEF2))
fp@2285: 
fp@2285: #define E1000_GCR_L1_ACT_WITHOUT_L0S_RX 0x08000000
fp@2285: 
fp@2285: #define E1000_NVM_INIT_CTRL2_MNGM 0x6000 /* Manageability Operation Mode mask */
fp@2285: 
fp@2285: static s32 e1000_get_phy_id_82571(struct e1000_hw *hw);
fp@2285: static s32 e1000_setup_copper_link_82571(struct e1000_hw *hw);
fp@2285: static s32 e1000_setup_fiber_serdes_link_82571(struct e1000_hw *hw);
fp@2285: static s32 e1000_check_for_serdes_link_82571(struct e1000_hw *hw);
fp@2285: static s32 e1000_write_nvm_eewr_82571(struct e1000_hw *hw, u16 offset,
fp@2285: 				      u16 words, u16 *data);
fp@2285: static s32 e1000_fix_nvm_checksum_82571(struct e1000_hw *hw);
fp@2285: static void e1000_initialize_hw_bits_82571(struct e1000_hw *hw);
fp@2285: static s32 e1000_setup_link_82571(struct e1000_hw *hw);
fp@2285: static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw);
fp@2285: static void e1000_clear_vfta_82571(struct e1000_hw *hw);
fp@2285: static bool e1000_check_mng_mode_82574(struct e1000_hw *hw);
fp@2285: static s32 e1000_led_on_82574(struct e1000_hw *hw);
fp@2285: static void e1000_put_hw_semaphore_82571(struct e1000_hw *hw);
fp@2285: static void e1000_power_down_phy_copper_82571(struct e1000_hw *hw);
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_init_phy_params_82571 - Init PHY func ptrs.
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  **/
fp@2285: static s32 e1000_init_phy_params_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	struct e1000_phy_info *phy = &hw->phy;
fp@2285: 	s32 ret_val;
fp@2285: 
fp@2285: 	if (hw->phy.media_type != e1000_media_type_copper) {
fp@2285: 		phy->type = e1000_phy_none;
fp@2285: 		return 0;
fp@2285: 	}
fp@2285: 
fp@2285: 	phy->addr			 = 1;
fp@2285: 	phy->autoneg_mask		 = AUTONEG_ADVERTISE_SPEED_DEFAULT;
fp@2285: 	phy->reset_delay_us		 = 100;
fp@2285: 
fp@2285: 	phy->ops.power_up		 = e1000_power_up_phy_copper;
fp@2285: 	phy->ops.power_down		 = e1000_power_down_phy_copper_82571;
fp@2285: 
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82571:
fp@2285: 	case e1000_82572:
fp@2285: 		phy->type		 = e1000_phy_igp_2;
fp@2285: 		break;
fp@2285: 	case e1000_82573:
fp@2285: 		phy->type		 = e1000_phy_m88;
fp@2285: 		break;
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		phy->type		 = e1000_phy_bm;
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		return -E1000_ERR_PHY;
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	/* This can only be done after all function pointers are setup. */
fp@2285: 	ret_val = e1000_get_phy_id_82571(hw);
fp@2285: 
fp@2285: 	/* Verify phy id */
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82571:
fp@2285: 	case e1000_82572:
fp@2285: 		if (phy->id != IGP01E1000_I_PHY_ID)
fp@2285: 			return -E1000_ERR_PHY;
fp@2285: 		break;
fp@2285: 	case e1000_82573:
fp@2285: 		if (phy->id != M88E1111_I_PHY_ID)
fp@2285: 			return -E1000_ERR_PHY;
fp@2285: 		break;
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		if (phy->id != BME1000_E_PHY_ID_R2)
fp@2285: 			return -E1000_ERR_PHY;
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		return -E1000_ERR_PHY;
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	return 0;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_init_nvm_params_82571 - Init NVM func ptrs.
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  **/
fp@2285: static s32 e1000_init_nvm_params_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	struct e1000_nvm_info *nvm = &hw->nvm;
fp@2285: 	u32 eecd = er32(EECD);
fp@2285: 	u16 size;
fp@2285: 
fp@2285: 	nvm->opcode_bits = 8;
fp@2285: 	nvm->delay_usec = 1;
fp@2285: 	switch (nvm->override) {
fp@2285: 	case e1000_nvm_override_spi_large:
fp@2285: 		nvm->page_size = 32;
fp@2285: 		nvm->address_bits = 16;
fp@2285: 		break;
fp@2285: 	case e1000_nvm_override_spi_small:
fp@2285: 		nvm->page_size = 8;
fp@2285: 		nvm->address_bits = 8;
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
fp@2285: 		nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82573:
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		if (((eecd >> 15) & 0x3) == 0x3) {
fp@2285: 			nvm->type = e1000_nvm_flash_hw;
fp@2285: 			nvm->word_size = 2048;
fp@2285: 			/*
fp@2285: 			 * Autonomous Flash update bit must be cleared due
fp@2285: 			 * to Flash update issue.
fp@2285: 			 */
fp@2285: 			eecd &= ~E1000_EECD_AUPDEN;
fp@2285: 			ew32(EECD, eecd);
fp@2285: 			break;
fp@2285: 		}
fp@2285: 		/* Fall Through */
fp@2285: 	default:
fp@2285: 		nvm->type = e1000_nvm_eeprom_spi;
fp@2285: 		size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
fp@2285: 				  E1000_EECD_SIZE_EX_SHIFT);
fp@2285: 		/*
fp@2285: 		 * Added to a constant, "size" becomes the left-shift value
fp@2285: 		 * for setting word_size.
fp@2285: 		 */
fp@2285: 		size += NVM_WORD_SIZE_BASE_SHIFT;
fp@2285: 
fp@2285: 		/* EEPROM access above 16k is unsupported */
fp@2285: 		if (size > 14)
fp@2285: 			size = 14;
fp@2285: 		nvm->word_size	= 1 << size;
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	return 0;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_init_mac_params_82571 - Init MAC func ptrs.
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  **/
fp@2285: static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
fp@2285: {
fp@2285: 	struct e1000_hw *hw = &adapter->hw;
fp@2285: 	struct e1000_mac_info *mac = &hw->mac;
fp@2285: 	struct e1000_mac_operations *func = &mac->ops;
fp@2285: 	u32 swsm = 0;
fp@2285: 	u32 swsm2 = 0;
fp@2285: 	bool force_clear_smbi = false;
fp@2285: 
fp@2285: 	/* Set media type */
fp@2285: 	switch (adapter->pdev->device) {
fp@2285: 	case E1000_DEV_ID_82571EB_FIBER:
fp@2285: 	case E1000_DEV_ID_82572EI_FIBER:
fp@2285: 	case E1000_DEV_ID_82571EB_QUAD_FIBER:
fp@2285: 		hw->phy.media_type = e1000_media_type_fiber;
fp@2285: 		break;
fp@2285: 	case E1000_DEV_ID_82571EB_SERDES:
fp@2285: 	case E1000_DEV_ID_82572EI_SERDES:
fp@2285: 	case E1000_DEV_ID_82571EB_SERDES_DUAL:
fp@2285: 	case E1000_DEV_ID_82571EB_SERDES_QUAD:
fp@2285: 		hw->phy.media_type = e1000_media_type_internal_serdes;
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		hw->phy.media_type = e1000_media_type_copper;
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	/* Set mta register count */
fp@2285: 	mac->mta_reg_count = 128;
fp@2285: 	/* Set rar entry count */
fp@2285: 	mac->rar_entry_count = E1000_RAR_ENTRIES;
fp@2285: 	/* Adaptive IFS supported */
fp@2285: 	mac->adaptive_ifs = true;
fp@2285: 
fp@2285: 	/* check for link */
fp@2285: 	switch (hw->phy.media_type) {
fp@2285: 	case e1000_media_type_copper:
fp@2285: 		func->setup_physical_interface = e1000_setup_copper_link_82571;
fp@2285: 		func->check_for_link = e1000e_check_for_copper_link;
fp@2285: 		func->get_link_up_info = e1000e_get_speed_and_duplex_copper;
fp@2285: 		break;
fp@2285: 	case e1000_media_type_fiber:
fp@2285: 		func->setup_physical_interface =
fp@2285: 			e1000_setup_fiber_serdes_link_82571;
fp@2285: 		func->check_for_link = e1000e_check_for_fiber_link;
fp@2285: 		func->get_link_up_info =
fp@2285: 			e1000e_get_speed_and_duplex_fiber_serdes;
fp@2285: 		break;
fp@2285: 	case e1000_media_type_internal_serdes:
fp@2285: 		func->setup_physical_interface =
fp@2285: 			e1000_setup_fiber_serdes_link_82571;
fp@2285: 		func->check_for_link = e1000_check_for_serdes_link_82571;
fp@2285: 		func->get_link_up_info =
fp@2285: 			e1000e_get_speed_and_duplex_fiber_serdes;
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		return -E1000_ERR_CONFIG;
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82573:
fp@2285: 		func->set_lan_id = e1000_set_lan_id_single_port;
fp@2285: 		func->check_mng_mode = e1000e_check_mng_mode_generic;
fp@2285: 		func->led_on = e1000e_led_on_generic;
fp@2285: 
fp@2285: 		/* FWSM register */
fp@2285: 		mac->has_fwsm = true;
fp@2285: 		/*
fp@2285: 		 * ARC supported; valid only if manageability features are
fp@2285: 		 * enabled.
fp@2285: 		 */
fp@2285: 		mac->arc_subsystem_valid =
fp@2285: 			(er32(FWSM) & E1000_FWSM_MODE_MASK)
fp@2285: 			? true : false;
fp@2285: 		break;
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		func->set_lan_id = e1000_set_lan_id_single_port;
fp@2285: 		func->check_mng_mode = e1000_check_mng_mode_82574;
fp@2285: 		func->led_on = e1000_led_on_82574;
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		func->check_mng_mode = e1000e_check_mng_mode_generic;
fp@2285: 		func->led_on = e1000e_led_on_generic;
fp@2285: 
fp@2285: 		/* FWSM register */
fp@2285: 		mac->has_fwsm = true;
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	/*
fp@2285: 	 * Ensure that the inter-port SWSM.SMBI lock bit is clear before
fp@2285: 	 * first NVM or PHY acess. This should be done for single-port
fp@2285: 	 * devices, and for one port only on dual-port devices so that
fp@2285: 	 * for those devices we can still use the SMBI lock to synchronize
fp@2285: 	 * inter-port accesses to the PHY & NVM.
fp@2285: 	 */
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82571:
fp@2285: 	case e1000_82572:
fp@2285: 		swsm2 = er32(SWSM2);
fp@2285: 
fp@2285: 		if (!(swsm2 & E1000_SWSM2_LOCK)) {
fp@2285: 			/* Only do this for the first interface on this card */
fp@2285: 			ew32(SWSM2,
fp@2285: 			    swsm2 | E1000_SWSM2_LOCK);
fp@2285: 			force_clear_smbi = true;
fp@2285: 		} else
fp@2285: 			force_clear_smbi = false;
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		force_clear_smbi = true;
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	if (force_clear_smbi) {
fp@2285: 		/* Make sure SWSM.SMBI is clear */
fp@2285: 		swsm = er32(SWSM);
fp@2285: 		if (swsm & E1000_SWSM_SMBI) {
fp@2285: 			/* This bit should not be set on a first interface, and
fp@2285: 			 * indicates that the bootagent or EFI code has
fp@2285: 			 * improperly left this bit enabled
fp@2285: 			 */
fp@2285: 			e_dbg("Please update your 82571 Bootagent\n");
fp@2285: 		}
fp@2285: 		ew32(SWSM, swsm & ~E1000_SWSM_SMBI);
fp@2285: 	}
fp@2285: 
fp@2285: 	/*
fp@2285: 	 * Initialize device specific counter of SMBI acquisition
fp@2285: 	 * timeouts.
fp@2285: 	 */
fp@2285: 	 hw->dev_spec.e82571.smb_counter = 0;
fp@2285: 
fp@2285: 	return 0;
fp@2285: }
fp@2285: 
fp@2285: static s32 e1000_get_variants_82571(struct e1000_adapter *adapter)
fp@2285: {
fp@2285: 	struct e1000_hw *hw = &adapter->hw;
fp@2285: 	static int global_quad_port_a; /* global port a indication */
fp@2285: 	struct pci_dev *pdev = adapter->pdev;
fp@2285: 	int is_port_b = er32(STATUS) & E1000_STATUS_FUNC_1;
fp@2285: 	s32 rc;
fp@2285: 
fp@2285: 	rc = e1000_init_mac_params_82571(adapter);
fp@2285: 	if (rc)
fp@2285: 		return rc;
fp@2285: 
fp@2285: 	rc = e1000_init_nvm_params_82571(hw);
fp@2285: 	if (rc)
fp@2285: 		return rc;
fp@2285: 
fp@2285: 	rc = e1000_init_phy_params_82571(hw);
fp@2285: 	if (rc)
fp@2285: 		return rc;
fp@2285: 
fp@2285: 	/* tag quad port adapters first, it's used below */
fp@2285: 	switch (pdev->device) {
fp@2285: 	case E1000_DEV_ID_82571EB_QUAD_COPPER:
fp@2285: 	case E1000_DEV_ID_82571EB_QUAD_FIBER:
fp@2285: 	case E1000_DEV_ID_82571EB_QUAD_COPPER_LP:
fp@2285: 	case E1000_DEV_ID_82571PT_QUAD_COPPER:
fp@2285: 		adapter->flags |= FLAG_IS_QUAD_PORT;
fp@2285: 		/* mark the first port */
fp@2285: 		if (global_quad_port_a == 0)
fp@2285: 			adapter->flags |= FLAG_IS_QUAD_PORT_A;
fp@2285: 		/* Reset for multiple quad port adapters */
fp@2285: 		global_quad_port_a++;
fp@2285: 		if (global_quad_port_a == 4)
fp@2285: 			global_quad_port_a = 0;
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	switch (adapter->hw.mac.type) {
fp@2285: 	case e1000_82571:
fp@2285: 		/* these dual ports don't have WoL on port B at all */
fp@2285: 		if (((pdev->device == E1000_DEV_ID_82571EB_FIBER) ||
fp@2285: 		     (pdev->device == E1000_DEV_ID_82571EB_SERDES) ||
fp@2285: 		     (pdev->device == E1000_DEV_ID_82571EB_COPPER)) &&
fp@2285: 		    (is_port_b))
fp@2285: 			adapter->flags &= ~FLAG_HAS_WOL;
fp@2285: 		/* quad ports only support WoL on port A */
fp@2285: 		if (adapter->flags & FLAG_IS_QUAD_PORT &&
fp@2285: 		    (!(adapter->flags & FLAG_IS_QUAD_PORT_A)))
fp@2285: 			adapter->flags &= ~FLAG_HAS_WOL;
fp@2285: 		/* Does not support WoL on any port */
fp@2285: 		if (pdev->device == E1000_DEV_ID_82571EB_SERDES_QUAD)
fp@2285: 			adapter->flags &= ~FLAG_HAS_WOL;
fp@2285: 		break;
fp@2285: 	case e1000_82573:
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		/* Disable ASPM L0s due to hardware errata */
fp@2285: 		e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L0S);
fp@2285: 
fp@2285: 		if (pdev->device == E1000_DEV_ID_82573L) {
fp@2285: 			adapter->flags |= FLAG_HAS_JUMBO_FRAMES;
fp@2285: 			adapter->max_hw_frame_size = DEFAULT_JUMBO;
fp@2285: 		}
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	return 0;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_get_phy_id_82571 - Retrieve the PHY ID and revision
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Reads the PHY registers and stores the PHY ID and possibly the PHY
fp@2285:  *  revision in the hardware structure.
fp@2285:  **/
fp@2285: static s32 e1000_get_phy_id_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	struct e1000_phy_info *phy = &hw->phy;
fp@2285: 	s32 ret_val;
fp@2285: 	u16 phy_id = 0;
fp@2285: 
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82571:
fp@2285: 	case e1000_82572:
fp@2285: 		/*
fp@2285: 		 * The 82571 firmware may still be configuring the PHY.
fp@2285: 		 * In this case, we cannot access the PHY until the
fp@2285: 		 * configuration is done.  So we explicitly set the
fp@2285: 		 * PHY ID.
fp@2285: 		 */
fp@2285: 		phy->id = IGP01E1000_I_PHY_ID;
fp@2285: 		break;
fp@2285: 	case e1000_82573:
fp@2285: 		return e1000e_get_phy_id(hw);
fp@2285: 		break;
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		ret_val = e1e_rphy(hw, PHY_ID1, &phy_id);
fp@2285: 		if (ret_val)
fp@2285: 			return ret_val;
fp@2285: 
fp@2285: 		phy->id = (u32)(phy_id << 16);
fp@2285: 		udelay(20);
fp@2285: 		ret_val = e1e_rphy(hw, PHY_ID2, &phy_id);
fp@2285: 		if (ret_val)
fp@2285: 			return ret_val;
fp@2285: 
fp@2285: 		phy->id |= (u32)(phy_id);
fp@2285: 		phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		return -E1000_ERR_PHY;
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	return 0;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_get_hw_semaphore_82571 - Acquire hardware semaphore
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Acquire the HW semaphore to access the PHY or NVM
fp@2285:  **/
fp@2285: static s32 e1000_get_hw_semaphore_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	u32 swsm;
fp@2285: 	s32 sw_timeout = hw->nvm.word_size + 1;
fp@2285: 	s32 fw_timeout = hw->nvm.word_size + 1;
fp@2285: 	s32 i = 0;
fp@2285: 
fp@2285: 	/*
fp@2285: 	 * If we have timedout 3 times on trying to acquire
fp@2285: 	 * the inter-port SMBI semaphore, there is old code
fp@2285: 	 * operating on the other port, and it is not
fp@2285: 	 * releasing SMBI. Modify the number of times that
fp@2285: 	 * we try for the semaphore to interwork with this
fp@2285: 	 * older code.
fp@2285: 	 */
fp@2285: 	if (hw->dev_spec.e82571.smb_counter > 2)
fp@2285: 		sw_timeout = 1;
fp@2285: 
fp@2285: 	/* Get the SW semaphore */
fp@2285: 	while (i < sw_timeout) {
fp@2285: 		swsm = er32(SWSM);
fp@2285: 		if (!(swsm & E1000_SWSM_SMBI))
fp@2285: 			break;
fp@2285: 
fp@2285: 		udelay(50);
fp@2285: 		i++;
fp@2285: 	}
fp@2285: 
fp@2285: 	if (i == sw_timeout) {
fp@2285: 		e_dbg("Driver can't access device - SMBI bit is set.\n");
fp@2285: 		hw->dev_spec.e82571.smb_counter++;
fp@2285: 	}
fp@2285: 	/* Get the FW semaphore. */
fp@2285: 	for (i = 0; i < fw_timeout; i++) {
fp@2285: 		swsm = er32(SWSM);
fp@2285: 		ew32(SWSM, swsm | E1000_SWSM_SWESMBI);
fp@2285: 
fp@2285: 		/* Semaphore acquired if bit latched */
fp@2285: 		if (er32(SWSM) & E1000_SWSM_SWESMBI)
fp@2285: 			break;
fp@2285: 
fp@2285: 		udelay(50);
fp@2285: 	}
fp@2285: 
fp@2285: 	if (i == fw_timeout) {
fp@2285: 		/* Release semaphores */
fp@2285: 		e1000_put_hw_semaphore_82571(hw);
fp@2285: 		e_dbg("Driver can't access the NVM\n");
fp@2285: 		return -E1000_ERR_NVM;
fp@2285: 	}
fp@2285: 
fp@2285: 	return 0;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_put_hw_semaphore_82571 - Release hardware semaphore
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Release hardware semaphore used to access the PHY or NVM
fp@2285:  **/
fp@2285: static void e1000_put_hw_semaphore_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	u32 swsm;
fp@2285: 
fp@2285: 	swsm = er32(SWSM);
fp@2285: 	swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
fp@2285: 	ew32(SWSM, swsm);
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_acquire_nvm_82571 - Request for access to the EEPROM
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  To gain access to the EEPROM, first we must obtain a hardware semaphore.
fp@2285:  *  Then for non-82573 hardware, set the EEPROM access request bit and wait
fp@2285:  *  for EEPROM access grant bit.  If the access grant bit is not set, release
fp@2285:  *  hardware semaphore.
fp@2285:  **/
fp@2285: static s32 e1000_acquire_nvm_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	s32 ret_val;
fp@2285: 
fp@2285: 	ret_val = e1000_get_hw_semaphore_82571(hw);
fp@2285: 	if (ret_val)
fp@2285: 		return ret_val;
fp@2285: 
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82573:
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		ret_val = e1000e_acquire_nvm(hw);
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	if (ret_val)
fp@2285: 		e1000_put_hw_semaphore_82571(hw);
fp@2285: 
fp@2285: 	return ret_val;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_release_nvm_82571 - Release exclusive access to EEPROM
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Stop any current commands to the EEPROM and clear the EEPROM request bit.
fp@2285:  **/
fp@2285: static void e1000_release_nvm_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	e1000e_release_nvm(hw);
fp@2285: 	e1000_put_hw_semaphore_82571(hw);
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_write_nvm_82571 - Write to EEPROM using appropriate interface
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *  @offset: offset within the EEPROM to be written to
fp@2285:  *  @words: number of words to write
fp@2285:  *  @data: 16 bit word(s) to be written to the EEPROM
fp@2285:  *
fp@2285:  *  For non-82573 silicon, write data to EEPROM at offset using SPI interface.
fp@2285:  *
fp@2285:  *  If e1000e_update_nvm_checksum is not called after this function, the
fp@2285:  *  EEPROM will most likely contain an invalid checksum.
fp@2285:  **/
fp@2285: static s32 e1000_write_nvm_82571(struct e1000_hw *hw, u16 offset, u16 words,
fp@2285: 				 u16 *data)
fp@2285: {
fp@2285: 	s32 ret_val;
fp@2285: 
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82573:
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		ret_val = e1000_write_nvm_eewr_82571(hw, offset, words, data);
fp@2285: 		break;
fp@2285: 	case e1000_82571:
fp@2285: 	case e1000_82572:
fp@2285: 		ret_val = e1000e_write_nvm_spi(hw, offset, words, data);
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		ret_val = -E1000_ERR_NVM;
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	return ret_val;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_update_nvm_checksum_82571 - Update EEPROM checksum
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Updates the EEPROM checksum by reading/adding each word of the EEPROM
fp@2285:  *  up to the checksum.  Then calculates the EEPROM checksum and writes the
fp@2285:  *  value to the EEPROM.
fp@2285:  **/
fp@2285: static s32 e1000_update_nvm_checksum_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	u32 eecd;
fp@2285: 	s32 ret_val;
fp@2285: 	u16 i;
fp@2285: 
fp@2285: 	ret_val = e1000e_update_nvm_checksum_generic(hw);
fp@2285: 	if (ret_val)
fp@2285: 		return ret_val;
fp@2285: 
fp@2285: 	/*
fp@2285: 	 * If our nvm is an EEPROM, then we're done
fp@2285: 	 * otherwise, commit the checksum to the flash NVM.
fp@2285: 	 */
fp@2285: 	if (hw->nvm.type != e1000_nvm_flash_hw)
fp@2285: 		return ret_val;
fp@2285: 
fp@2285: 	/* Check for pending operations. */
fp@2285: 	for (i = 0; i < E1000_FLASH_UPDATES; i++) {
fp@2285: 		msleep(1);
fp@2285: 		if ((er32(EECD) & E1000_EECD_FLUPD) == 0)
fp@2285: 			break;
fp@2285: 	}
fp@2285: 
fp@2285: 	if (i == E1000_FLASH_UPDATES)
fp@2285: 		return -E1000_ERR_NVM;
fp@2285: 
fp@2285: 	/* Reset the firmware if using STM opcode. */
fp@2285: 	if ((er32(FLOP) & 0xFF00) == E1000_STM_OPCODE) {
fp@2285: 		/*
fp@2285: 		 * The enabling of and the actual reset must be done
fp@2285: 		 * in two write cycles.
fp@2285: 		 */
fp@2285: 		ew32(HICR, E1000_HICR_FW_RESET_ENABLE);
fp@2285: 		e1e_flush();
fp@2285: 		ew32(HICR, E1000_HICR_FW_RESET);
fp@2285: 	}
fp@2285: 
fp@2285: 	/* Commit the write to flash */
fp@2285: 	eecd = er32(EECD) | E1000_EECD_FLUPD;
fp@2285: 	ew32(EECD, eecd);
fp@2285: 
fp@2285: 	for (i = 0; i < E1000_FLASH_UPDATES; i++) {
fp@2285: 		msleep(1);
fp@2285: 		if ((er32(EECD) & E1000_EECD_FLUPD) == 0)
fp@2285: 			break;
fp@2285: 	}
fp@2285: 
fp@2285: 	if (i == E1000_FLASH_UPDATES)
fp@2285: 		return -E1000_ERR_NVM;
fp@2285: 
fp@2285: 	return 0;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_validate_nvm_checksum_82571 - Validate EEPROM checksum
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Calculates the EEPROM checksum by reading/adding each word of the EEPROM
fp@2285:  *  and then verifies that the sum of the EEPROM is equal to 0xBABA.
fp@2285:  **/
fp@2285: static s32 e1000_validate_nvm_checksum_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	if (hw->nvm.type == e1000_nvm_flash_hw)
fp@2285: 		e1000_fix_nvm_checksum_82571(hw);
fp@2285: 
fp@2285: 	return e1000e_validate_nvm_checksum_generic(hw);
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_write_nvm_eewr_82571 - Write to EEPROM for 82573 silicon
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *  @offset: offset within the EEPROM to be written to
fp@2285:  *  @words: number of words to write
fp@2285:  *  @data: 16 bit word(s) to be written to the EEPROM
fp@2285:  *
fp@2285:  *  After checking for invalid values, poll the EEPROM to ensure the previous
fp@2285:  *  command has completed before trying to write the next word.  After write
fp@2285:  *  poll for completion.
fp@2285:  *
fp@2285:  *  If e1000e_update_nvm_checksum is not called after this function, the
fp@2285:  *  EEPROM will most likely contain an invalid checksum.
fp@2285:  **/
fp@2285: static s32 e1000_write_nvm_eewr_82571(struct e1000_hw *hw, u16 offset,
fp@2285: 				      u16 words, u16 *data)
fp@2285: {
fp@2285: 	struct e1000_nvm_info *nvm = &hw->nvm;
fp@2285: 	u32 i, eewr = 0;
fp@2285: 	s32 ret_val = 0;
fp@2285: 
fp@2285: 	/*
fp@2285: 	 * A check for invalid values:  offset too large, too many words,
fp@2285: 	 * and not enough words.
fp@2285: 	 */
fp@2285: 	if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
fp@2285: 	    (words == 0)) {
fp@2285: 		e_dbg("nvm parameter(s) out of bounds\n");
fp@2285: 		return -E1000_ERR_NVM;
fp@2285: 	}
fp@2285: 
fp@2285: 	for (i = 0; i < words; i++) {
fp@2285: 		eewr = (data[i] << E1000_NVM_RW_REG_DATA) |
fp@2285: 		       ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) |
fp@2285: 		       E1000_NVM_RW_REG_START;
fp@2285: 
fp@2285: 		ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_WRITE);
fp@2285: 		if (ret_val)
fp@2285: 			break;
fp@2285: 
fp@2285: 		ew32(EEWR, eewr);
fp@2285: 
fp@2285: 		ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_WRITE);
fp@2285: 		if (ret_val)
fp@2285: 			break;
fp@2285: 	}
fp@2285: 
fp@2285: 	return ret_val;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_get_cfg_done_82571 - Poll for configuration done
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Reads the management control register for the config done bit to be set.
fp@2285:  **/
fp@2285: static s32 e1000_get_cfg_done_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	s32 timeout = PHY_CFG_TIMEOUT;
fp@2285: 
fp@2285: 	while (timeout) {
fp@2285: 		if (er32(EEMNGCTL) &
fp@2285: 		    E1000_NVM_CFG_DONE_PORT_0)
fp@2285: 			break;
fp@2285: 		msleep(1);
fp@2285: 		timeout--;
fp@2285: 	}
fp@2285: 	if (!timeout) {
fp@2285: 		e_dbg("MNG configuration cycle has not completed.\n");
fp@2285: 		return -E1000_ERR_RESET;
fp@2285: 	}
fp@2285: 
fp@2285: 	return 0;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_set_d0_lplu_state_82571 - Set Low Power Linkup D0 state
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *  @active: true to enable LPLU, false to disable
fp@2285:  *
fp@2285:  *  Sets the LPLU D0 state according to the active flag.  When activating LPLU
fp@2285:  *  this function also disables smart speed and vice versa.  LPLU will not be
fp@2285:  *  activated unless the device autonegotiation advertisement meets standards
fp@2285:  *  of either 10 or 10/100 or 10/100/1000 at all duplexes.  This is a function
fp@2285:  *  pointer entry point only called by PHY setup routines.
fp@2285:  **/
fp@2285: static s32 e1000_set_d0_lplu_state_82571(struct e1000_hw *hw, bool active)
fp@2285: {
fp@2285: 	struct e1000_phy_info *phy = &hw->phy;
fp@2285: 	s32 ret_val;
fp@2285: 	u16 data;
fp@2285: 
fp@2285: 	ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
fp@2285: 	if (ret_val)
fp@2285: 		return ret_val;
fp@2285: 
fp@2285: 	if (active) {
fp@2285: 		data |= IGP02E1000_PM_D0_LPLU;
fp@2285: 		ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
fp@2285: 		if (ret_val)
fp@2285: 			return ret_val;
fp@2285: 
fp@2285: 		/* When LPLU is enabled, we should disable SmartSpeed */
fp@2285: 		ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
fp@2285: 		data &= ~IGP01E1000_PSCFR_SMART_SPEED;
fp@2285: 		ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
fp@2285: 		if (ret_val)
fp@2285: 			return ret_val;
fp@2285: 	} else {
fp@2285: 		data &= ~IGP02E1000_PM_D0_LPLU;
fp@2285: 		ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
fp@2285: 		/*
fp@2285: 		 * LPLU and SmartSpeed are mutually exclusive.  LPLU is used
fp@2285: 		 * during Dx states where the power conservation is most
fp@2285: 		 * important.  During driver activity we should enable
fp@2285: 		 * SmartSpeed, so performance is maintained.
fp@2285: 		 */
fp@2285: 		if (phy->smart_speed == e1000_smart_speed_on) {
fp@2285: 			ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
fp@2285: 					   &data);
fp@2285: 			if (ret_val)
fp@2285: 				return ret_val;
fp@2285: 
fp@2285: 			data |= IGP01E1000_PSCFR_SMART_SPEED;
fp@2285: 			ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
fp@2285: 					   data);
fp@2285: 			if (ret_val)
fp@2285: 				return ret_val;
fp@2285: 		} else if (phy->smart_speed == e1000_smart_speed_off) {
fp@2285: 			ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
fp@2285: 					   &data);
fp@2285: 			if (ret_val)
fp@2285: 				return ret_val;
fp@2285: 
fp@2285: 			data &= ~IGP01E1000_PSCFR_SMART_SPEED;
fp@2285: 			ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
fp@2285: 					   data);
fp@2285: 			if (ret_val)
fp@2285: 				return ret_val;
fp@2285: 		}
fp@2285: 	}
fp@2285: 
fp@2285: 	return 0;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_reset_hw_82571 - Reset hardware
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  This resets the hardware into a known state.
fp@2285:  **/
fp@2285: static s32 e1000_reset_hw_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	u32 ctrl, extcnf_ctrl, ctrl_ext, icr;
fp@2285: 	s32 ret_val;
fp@2285: 	u16 i = 0;
fp@2285: 
fp@2285: 	/*
fp@2285: 	 * Prevent the PCI-E bus from sticking if there is no TLP connection
fp@2285: 	 * on the last TLP read/write transaction when MAC is reset.
fp@2285: 	 */
fp@2285: 	ret_val = e1000e_disable_pcie_master(hw);
fp@2285: 	if (ret_val)
fp@2285: 		e_dbg("PCI-E Master disable polling has failed.\n");
fp@2285: 
fp@2285: 	e_dbg("Masking off all interrupts\n");
fp@2285: 	ew32(IMC, 0xffffffff);
fp@2285: 
fp@2285: 	ew32(RCTL, 0);
fp@2285: 	ew32(TCTL, E1000_TCTL_PSP);
fp@2285: 	e1e_flush();
fp@2285: 
fp@2285: 	msleep(10);
fp@2285: 
fp@2285: 	/*
fp@2285: 	 * Must acquire the MDIO ownership before MAC reset.
fp@2285: 	 * Ownership defaults to firmware after a reset.
fp@2285: 	 */
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82573:
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		extcnf_ctrl = er32(EXTCNF_CTRL);
fp@2285: 		extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
fp@2285: 
fp@2285: 		do {
fp@2285: 			ew32(EXTCNF_CTRL, extcnf_ctrl);
fp@2285: 			extcnf_ctrl = er32(EXTCNF_CTRL);
fp@2285: 
fp@2285: 			if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
fp@2285: 				break;
fp@2285: 
fp@2285: 			extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
fp@2285: 
fp@2285: 			msleep(2);
fp@2285: 			i++;
fp@2285: 		} while (i < MDIO_OWNERSHIP_TIMEOUT);
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	ctrl = er32(CTRL);
fp@2285: 
fp@2285: 	e_dbg("Issuing a global reset to MAC\n");
fp@2285: 	ew32(CTRL, ctrl | E1000_CTRL_RST);
fp@2285: 
fp@2285: 	if (hw->nvm.type == e1000_nvm_flash_hw) {
fp@2285: 		udelay(10);
fp@2285: 		ctrl_ext = er32(CTRL_EXT);
fp@2285: 		ctrl_ext |= E1000_CTRL_EXT_EE_RST;
fp@2285: 		ew32(CTRL_EXT, ctrl_ext);
fp@2285: 		e1e_flush();
fp@2285: 	}
fp@2285: 
fp@2285: 	ret_val = e1000e_get_auto_rd_done(hw);
fp@2285: 	if (ret_val)
fp@2285: 		/* We don't want to continue accessing MAC registers. */
fp@2285: 		return ret_val;
fp@2285: 
fp@2285: 	/*
fp@2285: 	 * Phy configuration from NVM just starts after EECD_AUTO_RD is set.
fp@2285: 	 * Need to wait for Phy configuration completion before accessing
fp@2285: 	 * NVM and Phy.
fp@2285: 	 */
fp@2285: 
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82573:
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		msleep(25);
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	/* Clear any pending interrupt events. */
fp@2285: 	ew32(IMC, 0xffffffff);
fp@2285: 	icr = er32(ICR);
fp@2285: 
fp@2285: 	if (hw->mac.type == e1000_82571) {
fp@2285: 		/* Install any alternate MAC address into RAR0 */
fp@2285: 		ret_val = e1000_check_alt_mac_addr_generic(hw);
fp@2285: 		if (ret_val)
fp@2285: 			return ret_val;
fp@2285: 
fp@2285: 		e1000e_set_laa_state_82571(hw, true);
fp@2285: 	}
fp@2285: 
fp@2285: 	/* Reinitialize the 82571 serdes link state machine */
fp@2285: 	if (hw->phy.media_type == e1000_media_type_internal_serdes)
fp@2285: 		hw->mac.serdes_link_state = e1000_serdes_link_down;
fp@2285: 
fp@2285: 	return 0;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_init_hw_82571 - Initialize hardware
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  This inits the hardware readying it for operation.
fp@2285:  **/
fp@2285: static s32 e1000_init_hw_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	struct e1000_mac_info *mac = &hw->mac;
fp@2285: 	u32 reg_data;
fp@2285: 	s32 ret_val;
fp@2285: 	u16 i, rar_count = mac->rar_entry_count;
fp@2285: 
fp@2285: 	e1000_initialize_hw_bits_82571(hw);
fp@2285: 
fp@2285: 	/* Initialize identification LED */
fp@2285: 	ret_val = e1000e_id_led_init(hw);
fp@2285: 	if (ret_val)
fp@2285: 		e_dbg("Error initializing identification LED\n");
fp@2285: 		/* This is not fatal and we should not stop init due to this */
fp@2285: 
fp@2285: 	/* Disabling VLAN filtering */
fp@2285: 	e_dbg("Initializing the IEEE VLAN\n");
fp@2285: 	mac->ops.clear_vfta(hw);
fp@2285: 
fp@2285: 	/* Setup the receive address. */
fp@2285: 	/*
fp@2285: 	 * If, however, a locally administered address was assigned to the
fp@2285: 	 * 82571, we must reserve a RAR for it to work around an issue where
fp@2285: 	 * resetting one port will reload the MAC on the other port.
fp@2285: 	 */
fp@2285: 	if (e1000e_get_laa_state_82571(hw))
fp@2285: 		rar_count--;
fp@2285: 	e1000e_init_rx_addrs(hw, rar_count);
fp@2285: 
fp@2285: 	/* Zero out the Multicast HASH table */
fp@2285: 	e_dbg("Zeroing the MTA\n");
fp@2285: 	for (i = 0; i < mac->mta_reg_count; i++)
fp@2285: 		E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
fp@2285: 
fp@2285: 	/* Setup link and flow control */
fp@2285: 	ret_val = e1000_setup_link_82571(hw);
fp@2285: 
fp@2285: 	/* Set the transmit descriptor write-back policy */
fp@2285: 	reg_data = er32(TXDCTL(0));
fp@2285: 	reg_data = (reg_data & ~E1000_TXDCTL_WTHRESH) |
fp@2285: 		   E1000_TXDCTL_FULL_TX_DESC_WB |
fp@2285: 		   E1000_TXDCTL_COUNT_DESC;
fp@2285: 	ew32(TXDCTL(0), reg_data);
fp@2285: 
fp@2285: 	/* ...for both queues. */
fp@2285: 	switch (mac->type) {
fp@2285: 	case e1000_82573:
fp@2285: 		e1000e_enable_tx_pkt_filtering(hw);
fp@2285: 		/* fall through */
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		reg_data = er32(GCR);
fp@2285: 		reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
fp@2285: 		ew32(GCR, reg_data);
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		reg_data = er32(TXDCTL(1));
fp@2285: 		reg_data = (reg_data & ~E1000_TXDCTL_WTHRESH) |
fp@2285: 			   E1000_TXDCTL_FULL_TX_DESC_WB |
fp@2285: 			   E1000_TXDCTL_COUNT_DESC;
fp@2285: 		ew32(TXDCTL(1), reg_data);
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	/*
fp@2285: 	 * Clear all of the statistics registers (clear on read).  It is
fp@2285: 	 * important that we do this after we have tried to establish link
fp@2285: 	 * because the symbol error count will increment wildly if there
fp@2285: 	 * is no link.
fp@2285: 	 */
fp@2285: 	e1000_clear_hw_cntrs_82571(hw);
fp@2285: 
fp@2285: 	return ret_val;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_initialize_hw_bits_82571 - Initialize hardware-dependent bits
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Initializes required hardware-dependent bits needed for normal operation.
fp@2285:  **/
fp@2285: static void e1000_initialize_hw_bits_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	u32 reg;
fp@2285: 
fp@2285: 	/* Transmit Descriptor Control 0 */
fp@2285: 	reg = er32(TXDCTL(0));
fp@2285: 	reg |= (1 << 22);
fp@2285: 	ew32(TXDCTL(0), reg);
fp@2285: 
fp@2285: 	/* Transmit Descriptor Control 1 */
fp@2285: 	reg = er32(TXDCTL(1));
fp@2285: 	reg |= (1 << 22);
fp@2285: 	ew32(TXDCTL(1), reg);
fp@2285: 
fp@2285: 	/* Transmit Arbitration Control 0 */
fp@2285: 	reg = er32(TARC(0));
fp@2285: 	reg &= ~(0xF << 27); /* 30:27 */
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82571:
fp@2285: 	case e1000_82572:
fp@2285: 		reg |= (1 << 23) | (1 << 24) | (1 << 25) | (1 << 26);
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		break;
fp@2285: 	}
fp@2285: 	ew32(TARC(0), reg);
fp@2285: 
fp@2285: 	/* Transmit Arbitration Control 1 */
fp@2285: 	reg = er32(TARC(1));
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82571:
fp@2285: 	case e1000_82572:
fp@2285: 		reg &= ~((1 << 29) | (1 << 30));
fp@2285: 		reg |= (1 << 22) | (1 << 24) | (1 << 25) | (1 << 26);
fp@2285: 		if (er32(TCTL) & E1000_TCTL_MULR)
fp@2285: 			reg &= ~(1 << 28);
fp@2285: 		else
fp@2285: 			reg |= (1 << 28);
fp@2285: 		ew32(TARC(1), reg);
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	/* Device Control */
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82573:
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		reg = er32(CTRL);
fp@2285: 		reg &= ~(1 << 29);
fp@2285: 		ew32(CTRL, reg);
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	/* Extended Device Control */
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82573:
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		reg = er32(CTRL_EXT);
fp@2285: 		reg &= ~(1 << 23);
fp@2285: 		reg |= (1 << 22);
fp@2285: 		ew32(CTRL_EXT, reg);
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	if (hw->mac.type == e1000_82571) {
fp@2285: 		reg = er32(PBA_ECC);
fp@2285: 		reg |= E1000_PBA_ECC_CORR_EN;
fp@2285: 		ew32(PBA_ECC, reg);
fp@2285: 	}
fp@2285: 	/*
fp@2285: 	 * Workaround for hardware errata.
fp@2285: 	 * Ensure that DMA Dynamic Clock gating is disabled on 82571 and 82572
fp@2285: 	 */
fp@2285: 
fp@2285:         if ((hw->mac.type == e1000_82571) ||
fp@2285:            (hw->mac.type == e1000_82572)) {
fp@2285:                 reg = er32(CTRL_EXT);
fp@2285:                 reg &= ~E1000_CTRL_EXT_DMA_DYN_CLK_EN;
fp@2285:                 ew32(CTRL_EXT, reg);
fp@2285:         }
fp@2285: 
fp@2285: 
fp@2285: 	/* PCI-Ex Control Registers */
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		reg = er32(GCR);
fp@2285: 		reg |= (1 << 22);
fp@2285: 		ew32(GCR, reg);
fp@2285: 
fp@2285: 		/*
fp@2285: 		 * Workaround for hardware errata.
fp@2285: 		 * apply workaround for hardware errata documented in errata
fp@2285: 		 * docs Fixes issue where some error prone or unreliable PCIe
fp@2285: 		 * completions are occurring, particularly with ASPM enabled.
fp@2285: 		 * Without fix, issue can cause tx timeouts.
fp@2285: 		 */
fp@2285: 		reg = er32(GCR2);
fp@2285: 		reg |= 1;
fp@2285: 		ew32(GCR2, reg);
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		break;
fp@2285: 	}
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_clear_vfta_82571 - Clear VLAN filter table
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Clears the register array which contains the VLAN filter table by
fp@2285:  *  setting all the values to 0.
fp@2285:  **/
fp@2285: static void e1000_clear_vfta_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	u32 offset;
fp@2285: 	u32 vfta_value = 0;
fp@2285: 	u32 vfta_offset = 0;
fp@2285: 	u32 vfta_bit_in_reg = 0;
fp@2285: 
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82573:
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		if (hw->mng_cookie.vlan_id != 0) {
fp@2285: 			/*
fp@2285: 			 * The VFTA is a 4096b bit-field, each identifying
fp@2285: 			 * a single VLAN ID.  The following operations
fp@2285: 			 * determine which 32b entry (i.e. offset) into the
fp@2285: 			 * array we want to set the VLAN ID (i.e. bit) of
fp@2285: 			 * the manageability unit.
fp@2285: 			 */
fp@2285: 			vfta_offset = (hw->mng_cookie.vlan_id >>
fp@2285: 				       E1000_VFTA_ENTRY_SHIFT) &
fp@2285: 				      E1000_VFTA_ENTRY_MASK;
fp@2285: 			vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
fp@2285: 					       E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
fp@2285: 		}
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		break;
fp@2285: 	}
fp@2285: 	for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
fp@2285: 		/*
fp@2285: 		 * If the offset we want to clear is the same offset of the
fp@2285: 		 * manageability VLAN ID, then clear all bits except that of
fp@2285: 		 * the manageability unit.
fp@2285: 		 */
fp@2285: 		vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
fp@2285: 		E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, vfta_value);
fp@2285: 		e1e_flush();
fp@2285: 	}
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_check_mng_mode_82574 - Check manageability is enabled
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Reads the NVM Initialization Control Word 2 and returns true
fp@2285:  *  (>0) if any manageability is enabled, else false (0).
fp@2285:  **/
fp@2285: static bool e1000_check_mng_mode_82574(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	u16 data;
fp@2285: 
fp@2285: 	e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &data);
fp@2285: 	return (data & E1000_NVM_INIT_CTRL2_MNGM) != 0;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_led_on_82574 - Turn LED on
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Turn LED on.
fp@2285:  **/
fp@2285: static s32 e1000_led_on_82574(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	u32 ctrl;
fp@2285: 	u32 i;
fp@2285: 
fp@2285: 	ctrl = hw->mac.ledctl_mode2;
fp@2285: 	if (!(E1000_STATUS_LU & er32(STATUS))) {
fp@2285: 		/*
fp@2285: 		 * If no link, then turn LED on by setting the invert bit
fp@2285: 		 * for each LED that's "on" (0x0E) in ledctl_mode2.
fp@2285: 		 */
fp@2285: 		for (i = 0; i < 4; i++)
fp@2285: 			if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
fp@2285: 			    E1000_LEDCTL_MODE_LED_ON)
fp@2285: 				ctrl |= (E1000_LEDCTL_LED0_IVRT << (i * 8));
fp@2285: 	}
fp@2285: 	ew32(LEDCTL, ctrl);
fp@2285: 
fp@2285: 	return 0;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_setup_link_82571 - Setup flow control and link settings
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Determines which flow control settings to use, then configures flow
fp@2285:  *  control.  Calls the appropriate media-specific link configuration
fp@2285:  *  function.  Assuming the adapter has a valid link partner, a valid link
fp@2285:  *  should be established.  Assumes the hardware has previously been reset
fp@2285:  *  and the transmitter and receiver are not enabled.
fp@2285:  **/
fp@2285: static s32 e1000_setup_link_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	/*
fp@2285: 	 * 82573 does not have a word in the NVM to determine
fp@2285: 	 * the default flow control setting, so we explicitly
fp@2285: 	 * set it to full.
fp@2285: 	 */
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82573:
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		if (hw->fc.requested_mode == e1000_fc_default)
fp@2285: 			hw->fc.requested_mode = e1000_fc_full;
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	return e1000e_setup_link(hw);
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_setup_copper_link_82571 - Configure copper link settings
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Configures the link for auto-neg or forced speed and duplex.  Then we check
fp@2285:  *  for link, once link is established calls to configure collision distance
fp@2285:  *  and flow control are called.
fp@2285:  **/
fp@2285: static s32 e1000_setup_copper_link_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	u32 ctrl;
fp@2285: 	s32 ret_val;
fp@2285: 
fp@2285: 	ctrl = er32(CTRL);
fp@2285: 	ctrl |= E1000_CTRL_SLU;
fp@2285: 	ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
fp@2285: 	ew32(CTRL, ctrl);
fp@2285: 
fp@2285: 	switch (hw->phy.type) {
fp@2285: 	case e1000_phy_m88:
fp@2285: 	case e1000_phy_bm:
fp@2285: 		ret_val = e1000e_copper_link_setup_m88(hw);
fp@2285: 		break;
fp@2285: 	case e1000_phy_igp_2:
fp@2285: 		ret_val = e1000e_copper_link_setup_igp(hw);
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		return -E1000_ERR_PHY;
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	if (ret_val)
fp@2285: 		return ret_val;
fp@2285: 
fp@2285: 	ret_val = e1000e_setup_copper_link(hw);
fp@2285: 
fp@2285: 	return ret_val;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_setup_fiber_serdes_link_82571 - Setup link for fiber/serdes
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Configures collision distance and flow control for fiber and serdes links.
fp@2285:  *  Upon successful setup, poll for link.
fp@2285:  **/
fp@2285: static s32 e1000_setup_fiber_serdes_link_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82571:
fp@2285: 	case e1000_82572:
fp@2285: 		/*
fp@2285: 		 * If SerDes loopback mode is entered, there is no form
fp@2285: 		 * of reset to take the adapter out of that mode.  So we
fp@2285: 		 * have to explicitly take the adapter out of loopback
fp@2285: 		 * mode.  This prevents drivers from twiddling their thumbs
fp@2285: 		 * if another tool failed to take it out of loopback mode.
fp@2285: 		 */
fp@2285: 		ew32(SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	return e1000e_setup_fiber_serdes_link(hw);
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_check_for_serdes_link_82571 - Check for link (Serdes)
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Reports the link state as up or down.
fp@2285:  *
fp@2285:  *  If autonegotiation is supported by the link partner, the link state is
fp@2285:  *  determined by the result of autonegotiation. This is the most likely case.
fp@2285:  *  If autonegotiation is not supported by the link partner, and the link
fp@2285:  *  has a valid signal, force the link up.
fp@2285:  *
fp@2285:  *  The link state is represented internally here by 4 states:
fp@2285:  *
fp@2285:  *  1) down
fp@2285:  *  2) autoneg_progress
fp@2285:  *  3) autoneg_complete (the link successfully autonegotiated)
fp@2285:  *  4) forced_up (the link has been forced up, it did not autonegotiate)
fp@2285:  *
fp@2285:  **/
fp@2285: static s32 e1000_check_for_serdes_link_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	struct e1000_mac_info *mac = &hw->mac;
fp@2285: 	u32 rxcw;
fp@2285: 	u32 ctrl;
fp@2285: 	u32 status;
fp@2285: 	s32 ret_val = 0;
fp@2285: 
fp@2285: 	ctrl = er32(CTRL);
fp@2285: 	status = er32(STATUS);
fp@2285: 	rxcw = er32(RXCW);
fp@2285: 
fp@2285: 	if ((rxcw & E1000_RXCW_SYNCH) && !(rxcw & E1000_RXCW_IV)) {
fp@2285: 
fp@2285: 		/* Receiver is synchronized with no invalid bits.  */
fp@2285: 		switch (mac->serdes_link_state) {
fp@2285: 		case e1000_serdes_link_autoneg_complete:
fp@2285: 			if (!(status & E1000_STATUS_LU)) {
fp@2285: 				/*
fp@2285: 				 * We have lost link, retry autoneg before
fp@2285: 				 * reporting link failure
fp@2285: 				 */
fp@2285: 				mac->serdes_link_state =
fp@2285: 				    e1000_serdes_link_autoneg_progress;
fp@2285: 				mac->serdes_has_link = false;
fp@2285: 				e_dbg("AN_UP     -> AN_PROG\n");
fp@2285: 			}
fp@2285: 		break;
fp@2285: 
fp@2285: 		case e1000_serdes_link_forced_up:
fp@2285: 			/*
fp@2285: 			 * If we are receiving /C/ ordered sets, re-enable
fp@2285: 			 * auto-negotiation in the TXCW register and disable
fp@2285: 			 * forced link in the Device Control register in an
fp@2285: 			 * attempt to auto-negotiate with our link partner.
fp@2285: 			 */
fp@2285: 			if (rxcw & E1000_RXCW_C) {
fp@2285: 				/* Enable autoneg, and unforce link up */
fp@2285: 				ew32(TXCW, mac->txcw);
fp@2285: 				ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
fp@2285: 				mac->serdes_link_state =
fp@2285: 				    e1000_serdes_link_autoneg_progress;
fp@2285: 				mac->serdes_has_link = false;
fp@2285: 				e_dbg("FORCED_UP -> AN_PROG\n");
fp@2285: 			}
fp@2285: 			break;
fp@2285: 
fp@2285: 		case e1000_serdes_link_autoneg_progress:
fp@2285: 			if (rxcw & E1000_RXCW_C) {
fp@2285: 				/*
fp@2285: 				 * We received /C/ ordered sets, meaning the
fp@2285: 				 * link partner has autonegotiated, and we can
fp@2285: 				 * trust the Link Up (LU) status bit.
fp@2285: 				 */
fp@2285: 				if (status & E1000_STATUS_LU) {
fp@2285: 					mac->serdes_link_state =
fp@2285: 					    e1000_serdes_link_autoneg_complete;
fp@2285: 					e_dbg("AN_PROG   -> AN_UP\n");
fp@2285: 					mac->serdes_has_link = true;
fp@2285: 				} else {
fp@2285: 					/* Autoneg completed, but failed. */
fp@2285: 					mac->serdes_link_state =
fp@2285: 					    e1000_serdes_link_down;
fp@2285: 					e_dbg("AN_PROG   -> DOWN\n");
fp@2285: 				}
fp@2285: 			} else {
fp@2285: 				/*
fp@2285: 				 * The link partner did not autoneg.
fp@2285: 				 * Force link up and full duplex, and change
fp@2285: 				 * state to forced.
fp@2285: 				 */
fp@2285: 				ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE));
fp@2285: 				ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
fp@2285: 				ew32(CTRL, ctrl);
fp@2285: 
fp@2285: 				/* Configure Flow Control after link up. */
fp@2285: 				ret_val = e1000e_config_fc_after_link_up(hw);
fp@2285: 				if (ret_val) {
fp@2285: 					e_dbg("Error config flow control\n");
fp@2285: 					break;
fp@2285: 				}
fp@2285: 				mac->serdes_link_state =
fp@2285: 				    e1000_serdes_link_forced_up;
fp@2285: 				mac->serdes_has_link = true;
fp@2285: 				e_dbg("AN_PROG   -> FORCED_UP\n");
fp@2285: 			}
fp@2285: 			break;
fp@2285: 
fp@2285: 		case e1000_serdes_link_down:
fp@2285: 		default:
fp@2285: 			/*
fp@2285: 			 * The link was down but the receiver has now gained
fp@2285: 			 * valid sync, so lets see if we can bring the link
fp@2285: 			 * up.
fp@2285: 			 */
fp@2285: 			ew32(TXCW, mac->txcw);
fp@2285: 			ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
fp@2285: 			mac->serdes_link_state =
fp@2285: 			    e1000_serdes_link_autoneg_progress;
fp@2285: 			e_dbg("DOWN      -> AN_PROG\n");
fp@2285: 			break;
fp@2285: 		}
fp@2285: 	} else {
fp@2285: 		if (!(rxcw & E1000_RXCW_SYNCH)) {
fp@2285: 			mac->serdes_has_link = false;
fp@2285: 			mac->serdes_link_state = e1000_serdes_link_down;
fp@2285: 			e_dbg("ANYSTATE  -> DOWN\n");
fp@2285: 		} else {
fp@2285: 			/*
fp@2285: 			 * We have sync, and can tolerate one invalid (IV)
fp@2285: 			 * codeword before declaring link down, so reread
fp@2285: 			 * to look again.
fp@2285: 			 */
fp@2285: 			udelay(10);
fp@2285: 			rxcw = er32(RXCW);
fp@2285: 			if (rxcw & E1000_RXCW_IV) {
fp@2285: 				mac->serdes_link_state = e1000_serdes_link_down;
fp@2285: 				mac->serdes_has_link = false;
fp@2285: 				e_dbg("ANYSTATE  -> DOWN\n");
fp@2285: 			}
fp@2285: 		}
fp@2285: 	}
fp@2285: 
fp@2285: 	return ret_val;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_valid_led_default_82571 - Verify a valid default LED config
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *  @data: pointer to the NVM (EEPROM)
fp@2285:  *
fp@2285:  *  Read the EEPROM for the current default LED configuration.  If the
fp@2285:  *  LED configuration is not valid, set to a valid LED configuration.
fp@2285:  **/
fp@2285: static s32 e1000_valid_led_default_82571(struct e1000_hw *hw, u16 *data)
fp@2285: {
fp@2285: 	s32 ret_val;
fp@2285: 
fp@2285: 	ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
fp@2285: 	if (ret_val) {
fp@2285: 		e_dbg("NVM Read Error\n");
fp@2285: 		return ret_val;
fp@2285: 	}
fp@2285: 
fp@2285: 	switch (hw->mac.type) {
fp@2285: 	case e1000_82573:
fp@2285: 	case e1000_82574:
fp@2285: 	case e1000_82583:
fp@2285: 		if (*data == ID_LED_RESERVED_F746)
fp@2285: 			*data = ID_LED_DEFAULT_82573;
fp@2285: 		break;
fp@2285: 	default:
fp@2285: 		if (*data == ID_LED_RESERVED_0000 ||
fp@2285: 		    *data == ID_LED_RESERVED_FFFF)
fp@2285: 			*data = ID_LED_DEFAULT;
fp@2285: 		break;
fp@2285: 	}
fp@2285: 
fp@2285: 	return 0;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000e_get_laa_state_82571 - Get locally administered address state
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Retrieve and return the current locally administered address state.
fp@2285:  **/
fp@2285: bool e1000e_get_laa_state_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	if (hw->mac.type != e1000_82571)
fp@2285: 		return false;
fp@2285: 
fp@2285: 	return hw->dev_spec.e82571.laa_is_present;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000e_set_laa_state_82571 - Set locally administered address state
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *  @state: enable/disable locally administered address
fp@2285:  *
fp@2285:  *  Enable/Disable the current locally administered address state.
fp@2285:  **/
fp@2285: void e1000e_set_laa_state_82571(struct e1000_hw *hw, bool state)
fp@2285: {
fp@2285: 	if (hw->mac.type != e1000_82571)
fp@2285: 		return;
fp@2285: 
fp@2285: 	hw->dev_spec.e82571.laa_is_present = state;
fp@2285: 
fp@2285: 	/* If workaround is activated... */
fp@2285: 	if (state)
fp@2285: 		/*
fp@2285: 		 * Hold a copy of the LAA in RAR[14] This is done so that
fp@2285: 		 * between the time RAR[0] gets clobbered and the time it
fp@2285: 		 * gets fixed, the actual LAA is in one of the RARs and no
fp@2285: 		 * incoming packets directed to this port are dropped.
fp@2285: 		 * Eventually the LAA will be in RAR[0] and RAR[14].
fp@2285: 		 */
fp@2285: 		e1000e_rar_set(hw, hw->mac.addr, hw->mac.rar_entry_count - 1);
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_fix_nvm_checksum_82571 - Fix EEPROM checksum
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Verifies that the EEPROM has completed the update.  After updating the
fp@2285:  *  EEPROM, we need to check bit 15 in work 0x23 for the checksum fix.  If
fp@2285:  *  the checksum fix is not implemented, we need to set the bit and update
fp@2285:  *  the checksum.  Otherwise, if bit 15 is set and the checksum is incorrect,
fp@2285:  *  we need to return bad checksum.
fp@2285:  **/
fp@2285: static s32 e1000_fix_nvm_checksum_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	struct e1000_nvm_info *nvm = &hw->nvm;
fp@2285: 	s32 ret_val;
fp@2285: 	u16 data;
fp@2285: 
fp@2285: 	if (nvm->type != e1000_nvm_flash_hw)
fp@2285: 		return 0;
fp@2285: 
fp@2285: 	/*
fp@2285: 	 * Check bit 4 of word 10h.  If it is 0, firmware is done updating
fp@2285: 	 * 10h-12h.  Checksum may need to be fixed.
fp@2285: 	 */
fp@2285: 	ret_val = e1000_read_nvm(hw, 0x10, 1, &data);
fp@2285: 	if (ret_val)
fp@2285: 		return ret_val;
fp@2285: 
fp@2285: 	if (!(data & 0x10)) {
fp@2285: 		/*
fp@2285: 		 * Read 0x23 and check bit 15.  This bit is a 1
fp@2285: 		 * when the checksum has already been fixed.  If
fp@2285: 		 * the checksum is still wrong and this bit is a
fp@2285: 		 * 1, we need to return bad checksum.  Otherwise,
fp@2285: 		 * we need to set this bit to a 1 and update the
fp@2285: 		 * checksum.
fp@2285: 		 */
fp@2285: 		ret_val = e1000_read_nvm(hw, 0x23, 1, &data);
fp@2285: 		if (ret_val)
fp@2285: 			return ret_val;
fp@2285: 
fp@2285: 		if (!(data & 0x8000)) {
fp@2285: 			data |= 0x8000;
fp@2285: 			ret_val = e1000_write_nvm(hw, 0x23, 1, &data);
fp@2285: 			if (ret_val)
fp@2285: 				return ret_val;
fp@2285: 			ret_val = e1000e_update_nvm_checksum(hw);
fp@2285: 		}
fp@2285: 	}
fp@2285: 
fp@2285: 	return 0;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_read_mac_addr_82571 - Read device MAC address
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  **/
fp@2285: static s32 e1000_read_mac_addr_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	s32 ret_val = 0;
fp@2285: 
fp@2285: 	if (hw->mac.type == e1000_82571) {
fp@2285: 		/*
fp@2285: 		 * If there's an alternate MAC address place it in RAR0
fp@2285: 		 * so that it will override the Si installed default perm
fp@2285: 		 * address.
fp@2285: 		 */
fp@2285: 		ret_val = e1000_check_alt_mac_addr_generic(hw);
fp@2285: 		if (ret_val)
fp@2285: 			goto out;
fp@2285: 	}
fp@2285: 
fp@2285: 	ret_val = e1000_read_mac_addr_generic(hw);
fp@2285: 
fp@2285: out:
fp@2285: 	return ret_val;
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  * e1000_power_down_phy_copper_82571 - Remove link during PHY power down
fp@2285:  * @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  * In the case of a PHY power down to save power, or to turn off link during a
fp@2285:  * driver unload, or wake on lan is not enabled, remove the link.
fp@2285:  **/
fp@2285: static void e1000_power_down_phy_copper_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	struct e1000_phy_info *phy = &hw->phy;
fp@2285: 	struct e1000_mac_info *mac = &hw->mac;
fp@2285: 
fp@2285: 	if (!(phy->ops.check_reset_block))
fp@2285: 		return;
fp@2285: 
fp@2285: 	/* If the management interface is not enabled, then power down */
fp@2285: 	if (!(mac->ops.check_mng_mode(hw) || phy->ops.check_reset_block(hw)))
fp@2285: 		e1000_power_down_phy_copper(hw);
fp@2285: }
fp@2285: 
fp@2285: /**
fp@2285:  *  e1000_clear_hw_cntrs_82571 - Clear device specific hardware counters
fp@2285:  *  @hw: pointer to the HW structure
fp@2285:  *
fp@2285:  *  Clears the hardware counters by reading the counter registers.
fp@2285:  **/
fp@2285: static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw)
fp@2285: {
fp@2285: 	e1000e_clear_hw_cntrs_base(hw);
fp@2285: 
fp@2285: 	er32(PRC64);
fp@2285: 	er32(PRC127);
fp@2285: 	er32(PRC255);
fp@2285: 	er32(PRC511);
fp@2285: 	er32(PRC1023);
fp@2285: 	er32(PRC1522);
fp@2285: 	er32(PTC64);
fp@2285: 	er32(PTC127);
fp@2285: 	er32(PTC255);
fp@2285: 	er32(PTC511);
fp@2285: 	er32(PTC1023);
fp@2285: 	er32(PTC1522);
fp@2285: 
fp@2285: 	er32(ALGNERRC);
fp@2285: 	er32(RXERRC);
fp@2285: 	er32(TNCRS);
fp@2285: 	er32(CEXTERR);
fp@2285: 	er32(TSCTC);
fp@2285: 	er32(TSCTFC);
fp@2285: 
fp@2285: 	er32(MGTPRC);
fp@2285: 	er32(MGTPDC);
fp@2285: 	er32(MGTPTC);
fp@2285: 
fp@2285: 	er32(IAC);
fp@2285: 	er32(ICRXOC);
fp@2285: 
fp@2285: 	er32(ICRXPTC);
fp@2285: 	er32(ICRXATC);
fp@2285: 	er32(ICTXPTC);
fp@2285: 	er32(ICTXATC);
fp@2285: 	er32(ICTXQEC);
fp@2285: 	er32(ICTXQMTC);
fp@2285: 	er32(ICRXDMTC);
fp@2285: }
fp@2285: 
fp@2285: static struct e1000_mac_operations e82571_mac_ops = {
fp@2285: 	/* .check_mng_mode: mac type dependent */
fp@2285: 	/* .check_for_link: media type dependent */
fp@2285: 	.id_led_init		= e1000e_id_led_init,
fp@2285: 	.cleanup_led		= e1000e_cleanup_led_generic,
fp@2285: 	.clear_hw_cntrs		= e1000_clear_hw_cntrs_82571,
fp@2285: 	.get_bus_info		= e1000e_get_bus_info_pcie,
fp@2285: 	.set_lan_id		= e1000_set_lan_id_multi_port_pcie,
fp@2285: 	/* .get_link_up_info: media type dependent */
fp@2285: 	/* .led_on: mac type dependent */
fp@2285: 	.led_off		= e1000e_led_off_generic,
fp@2285: 	.update_mc_addr_list	= e1000e_update_mc_addr_list_generic,
fp@2285: 	.write_vfta		= e1000_write_vfta_generic,
fp@2285: 	.clear_vfta		= e1000_clear_vfta_82571,
fp@2285: 	.reset_hw		= e1000_reset_hw_82571,
fp@2285: 	.init_hw		= e1000_init_hw_82571,
fp@2285: 	.setup_link		= e1000_setup_link_82571,
fp@2285: 	/* .setup_physical_interface: media type dependent */
fp@2285: 	.setup_led		= e1000e_setup_led_generic,
fp@2285: 	.read_mac_addr		= e1000_read_mac_addr_82571,
fp@2285: };
fp@2285: 
fp@2285: static struct e1000_phy_operations e82_phy_ops_igp = {
fp@2285: 	.acquire		= e1000_get_hw_semaphore_82571,
fp@2285: 	.check_polarity		= e1000_check_polarity_igp,
fp@2285: 	.check_reset_block	= e1000e_check_reset_block_generic,
fp@2285: 	.commit			= NULL,
fp@2285: 	.force_speed_duplex	= e1000e_phy_force_speed_duplex_igp,
fp@2285: 	.get_cfg_done		= e1000_get_cfg_done_82571,
fp@2285: 	.get_cable_length	= e1000e_get_cable_length_igp_2,
fp@2285: 	.get_info		= e1000e_get_phy_info_igp,
fp@2285: 	.read_reg		= e1000e_read_phy_reg_igp,
fp@2285: 	.release		= e1000_put_hw_semaphore_82571,
fp@2285: 	.reset			= e1000e_phy_hw_reset_generic,
fp@2285: 	.set_d0_lplu_state	= e1000_set_d0_lplu_state_82571,
fp@2285: 	.set_d3_lplu_state	= e1000e_set_d3_lplu_state,
fp@2285: 	.write_reg		= e1000e_write_phy_reg_igp,
fp@2285: 	.cfg_on_link_up      	= NULL,
fp@2285: };
fp@2285: 
fp@2285: static struct e1000_phy_operations e82_phy_ops_m88 = {
fp@2285: 	.acquire		= e1000_get_hw_semaphore_82571,
fp@2285: 	.check_polarity		= e1000_check_polarity_m88,
fp@2285: 	.check_reset_block	= e1000e_check_reset_block_generic,
fp@2285: 	.commit			= e1000e_phy_sw_reset,
fp@2285: 	.force_speed_duplex	= e1000e_phy_force_speed_duplex_m88,
fp@2285: 	.get_cfg_done		= e1000e_get_cfg_done,
fp@2285: 	.get_cable_length	= e1000e_get_cable_length_m88,
fp@2285: 	.get_info		= e1000e_get_phy_info_m88,
fp@2285: 	.read_reg		= e1000e_read_phy_reg_m88,
fp@2285: 	.release		= e1000_put_hw_semaphore_82571,
fp@2285: 	.reset			= e1000e_phy_hw_reset_generic,
fp@2285: 	.set_d0_lplu_state	= e1000_set_d0_lplu_state_82571,
fp@2285: 	.set_d3_lplu_state	= e1000e_set_d3_lplu_state,
fp@2285: 	.write_reg		= e1000e_write_phy_reg_m88,
fp@2285: 	.cfg_on_link_up      	= NULL,
fp@2285: };
fp@2285: 
fp@2285: static struct e1000_phy_operations e82_phy_ops_bm = {
fp@2285: 	.acquire		= e1000_get_hw_semaphore_82571,
fp@2285: 	.check_polarity		= e1000_check_polarity_m88,
fp@2285: 	.check_reset_block	= e1000e_check_reset_block_generic,
fp@2285: 	.commit			= e1000e_phy_sw_reset,
fp@2285: 	.force_speed_duplex	= e1000e_phy_force_speed_duplex_m88,
fp@2285: 	.get_cfg_done		= e1000e_get_cfg_done,
fp@2285: 	.get_cable_length	= e1000e_get_cable_length_m88,
fp@2285: 	.get_info		= e1000e_get_phy_info_m88,
fp@2285: 	.read_reg		= e1000e_read_phy_reg_bm2,
fp@2285: 	.release		= e1000_put_hw_semaphore_82571,
fp@2285: 	.reset			= e1000e_phy_hw_reset_generic,
fp@2285: 	.set_d0_lplu_state	= e1000_set_d0_lplu_state_82571,
fp@2285: 	.set_d3_lplu_state	= e1000e_set_d3_lplu_state,
fp@2285: 	.write_reg		= e1000e_write_phy_reg_bm2,
fp@2285: 	.cfg_on_link_up      	= NULL,
fp@2285: };
fp@2285: 
fp@2285: static struct e1000_nvm_operations e82571_nvm_ops = {
fp@2285: 	.acquire		= e1000_acquire_nvm_82571,
fp@2285: 	.read			= e1000e_read_nvm_eerd,
fp@2285: 	.release		= e1000_release_nvm_82571,
fp@2285: 	.update			= e1000_update_nvm_checksum_82571,
fp@2285: 	.valid_led_default	= e1000_valid_led_default_82571,
fp@2285: 	.validate		= e1000_validate_nvm_checksum_82571,
fp@2285: 	.write			= e1000_write_nvm_82571,
fp@2285: };
fp@2285: 
fp@2285: struct e1000_info e1000_82571_info = {
fp@2285: 	.mac			= e1000_82571,
fp@2285: 	.flags			= FLAG_HAS_HW_VLAN_FILTER
fp@2285: 				  | FLAG_HAS_JUMBO_FRAMES
fp@2285: 				  | FLAG_HAS_WOL
fp@2285: 				  | FLAG_APME_IN_CTRL3
fp@2285: 				  | FLAG_RX_CSUM_ENABLED
fp@2285: 				  | FLAG_HAS_CTRLEXT_ON_LOAD
fp@2285: 				  | FLAG_HAS_SMART_POWER_DOWN
fp@2285: 				  | FLAG_RESET_OVERWRITES_LAA /* errata */
fp@2285: 				  | FLAG_TARC_SPEED_MODE_BIT /* errata */
fp@2285: 				  | FLAG_APME_CHECK_PORT_B,
fp@2285: 	.flags2			= FLAG2_DISABLE_ASPM_L1, /* errata 13 */
fp@2285: 	.pba			= 38,
fp@2285: 	.max_hw_frame_size	= DEFAULT_JUMBO,
fp@2285: 	.get_variants		= e1000_get_variants_82571,
fp@2285: 	.mac_ops		= &e82571_mac_ops,
fp@2285: 	.phy_ops		= &e82_phy_ops_igp,
fp@2285: 	.nvm_ops		= &e82571_nvm_ops,
fp@2285: };
fp@2285: 
fp@2285: struct e1000_info e1000_82572_info = {
fp@2285: 	.mac			= e1000_82572,
fp@2285: 	.flags			= FLAG_HAS_HW_VLAN_FILTER
fp@2285: 				  | FLAG_HAS_JUMBO_FRAMES
fp@2285: 				  | FLAG_HAS_WOL
fp@2285: 				  | FLAG_APME_IN_CTRL3
fp@2285: 				  | FLAG_RX_CSUM_ENABLED
fp@2285: 				  | FLAG_HAS_CTRLEXT_ON_LOAD
fp@2285: 				  | FLAG_TARC_SPEED_MODE_BIT, /* errata */
fp@2285: 	.flags2			= FLAG2_DISABLE_ASPM_L1, /* errata 13 */
fp@2285: 	.pba			= 38,
fp@2285: 	.max_hw_frame_size	= DEFAULT_JUMBO,
fp@2285: 	.get_variants		= e1000_get_variants_82571,
fp@2285: 	.mac_ops		= &e82571_mac_ops,
fp@2285: 	.phy_ops		= &e82_phy_ops_igp,
fp@2285: 	.nvm_ops		= &e82571_nvm_ops,
fp@2285: };
fp@2285: 
fp@2285: struct e1000_info e1000_82573_info = {
fp@2285: 	.mac			= e1000_82573,
fp@2285: 	.flags			= FLAG_HAS_HW_VLAN_FILTER
fp@2285: 				  | FLAG_HAS_WOL
fp@2285: 				  | FLAG_APME_IN_CTRL3
fp@2285: 				  | FLAG_RX_CSUM_ENABLED
fp@2285: 				  | FLAG_HAS_SMART_POWER_DOWN
fp@2285: 				  | FLAG_HAS_AMT
fp@2285: 				  | FLAG_HAS_SWSM_ON_LOAD,
fp@2285: 	.flags2			= FLAG2_DISABLE_ASPM_L1,
fp@2285: 	.pba			= 20,
fp@2285: 	.max_hw_frame_size	= ETH_FRAME_LEN + ETH_FCS_LEN,
fp@2285: 	.get_variants		= e1000_get_variants_82571,
fp@2285: 	.mac_ops		= &e82571_mac_ops,
fp@2285: 	.phy_ops		= &e82_phy_ops_m88,
fp@2285: 	.nvm_ops		= &e82571_nvm_ops,
fp@2285: };
fp@2285: 
fp@2285: struct e1000_info e1000_82574_info = {
fp@2285: 	.mac			= e1000_82574,
fp@2285: 	.flags			= FLAG_HAS_HW_VLAN_FILTER
fp@2285: 				  | FLAG_HAS_MSIX
fp@2285: 				  | FLAG_HAS_JUMBO_FRAMES
fp@2285: 				  | FLAG_HAS_WOL
fp@2285: 				  | FLAG_APME_IN_CTRL3
fp@2285: 				  | FLAG_RX_CSUM_ENABLED
fp@2285: 				  | FLAG_HAS_SMART_POWER_DOWN
fp@2285: 				  | FLAG_HAS_AMT
fp@2285: 				  | FLAG_HAS_CTRLEXT_ON_LOAD,
fp@2285: 	.pba			= 36,
fp@2285: 	.max_hw_frame_size	= DEFAULT_JUMBO,
fp@2285: 	.get_variants		= e1000_get_variants_82571,
fp@2285: 	.mac_ops		= &e82571_mac_ops,
fp@2285: 	.phy_ops		= &e82_phy_ops_bm,
fp@2285: 	.nvm_ops		= &e82571_nvm_ops,
fp@2285: };
fp@2285: 
fp@2285: struct e1000_info e1000_82583_info = {
fp@2285: 	.mac			= e1000_82583,
fp@2285: 	.flags			= FLAG_HAS_HW_VLAN_FILTER
fp@2285: 				  | FLAG_HAS_WOL
fp@2285: 				  | FLAG_APME_IN_CTRL3
fp@2285: 				  | FLAG_RX_CSUM_ENABLED
fp@2285: 				  | FLAG_HAS_SMART_POWER_DOWN
fp@2285: 				  | FLAG_HAS_AMT
fp@2285: 				  | FLAG_HAS_CTRLEXT_ON_LOAD,
fp@2285: 	.pba			= 36,
fp@2285: 	.max_hw_frame_size	= ETH_FRAME_LEN + ETH_FCS_LEN,
fp@2285: 	.get_variants		= e1000_get_variants_82571,
fp@2285: 	.mac_ops		= &e82571_mac_ops,
fp@2285: 	.phy_ops		= &e82_phy_ops_bm,
fp@2285: 	.nvm_ops		= &e82571_nvm_ops,
fp@2285: };
fp@2285: