Home | History | Annotate | Line # | Download | only in ixgbe
ixgbe_x540.c revision 1.2
      1  1.1  msaitoh /******************************************************************************
      2  1.1  msaitoh 
      3  1.1  msaitoh   Copyright (c) 2001-2012, Intel Corporation
      4  1.1  msaitoh   All rights reserved.
      5  1.1  msaitoh 
      6  1.1  msaitoh   Redistribution and use in source and binary forms, with or without
      7  1.1  msaitoh   modification, are permitted provided that the following conditions are met:
      8  1.1  msaitoh 
      9  1.1  msaitoh    1. Redistributions of source code must retain the above copyright notice,
     10  1.1  msaitoh       this list of conditions and the following disclaimer.
     11  1.1  msaitoh 
     12  1.1  msaitoh    2. Redistributions in binary form must reproduce the above copyright
     13  1.1  msaitoh       notice, this list of conditions and the following disclaimer in the
     14  1.1  msaitoh       documentation and/or other materials provided with the distribution.
     15  1.1  msaitoh 
     16  1.1  msaitoh    3. Neither the name of the Intel Corporation nor the names of its
     17  1.1  msaitoh       contributors may be used to endorse or promote products derived from
     18  1.1  msaitoh       this software without specific prior written permission.
     19  1.1  msaitoh 
     20  1.1  msaitoh   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     21  1.1  msaitoh   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22  1.1  msaitoh   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23  1.1  msaitoh   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     24  1.1  msaitoh   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  1.1  msaitoh   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  1.1  msaitoh   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  1.1  msaitoh   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  1.1  msaitoh   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  1.1  msaitoh   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  1.1  msaitoh   POSSIBILITY OF SUCH DAMAGE.
     31  1.1  msaitoh 
     32  1.1  msaitoh ******************************************************************************/
     33  1.2  msaitoh /*$FreeBSD: head/sys/dev/ixgbe/ixgbe_x540.c 238149 2012-07-05 20:51:44Z jfv $*/
     34  1.1  msaitoh 
     35  1.1  msaitoh #include "ixgbe_x540.h"
     36  1.1  msaitoh #include "ixgbe_type.h"
     37  1.1  msaitoh #include "ixgbe_api.h"
     38  1.1  msaitoh #include "ixgbe_common.h"
     39  1.1  msaitoh #include "ixgbe_phy.h"
     40  1.1  msaitoh 
     41  1.1  msaitoh static s32 ixgbe_update_flash_X540(struct ixgbe_hw *hw);
     42  1.1  msaitoh static s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw);
     43  1.1  msaitoh static s32 ixgbe_get_swfw_sync_semaphore(struct ixgbe_hw *hw);
     44  1.1  msaitoh static void ixgbe_release_swfw_sync_semaphore(struct ixgbe_hw *hw);
     45  1.1  msaitoh 
     46  1.1  msaitoh /**
     47  1.1  msaitoh  *  ixgbe_init_ops_X540 - Inits func ptrs and MAC type
     48  1.1  msaitoh  *  @hw: pointer to hardware structure
     49  1.1  msaitoh  *
     50  1.1  msaitoh  *  Initialize the function pointers and assign the MAC type for X540.
     51  1.1  msaitoh  *  Does not touch the hardware.
     52  1.1  msaitoh  **/
     53  1.1  msaitoh s32 ixgbe_init_ops_X540(struct ixgbe_hw *hw)
     54  1.1  msaitoh {
     55  1.1  msaitoh 	struct ixgbe_mac_info *mac = &hw->mac;
     56  1.1  msaitoh 	struct ixgbe_phy_info *phy = &hw->phy;
     57  1.1  msaitoh 	struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
     58  1.1  msaitoh 	s32 ret_val;
     59  1.1  msaitoh 
     60  1.1  msaitoh 	DEBUGFUNC("ixgbe_init_ops_X540");
     61  1.1  msaitoh 
     62  1.1  msaitoh 	ret_val = ixgbe_init_phy_ops_generic(hw);
     63  1.1  msaitoh 	ret_val = ixgbe_init_ops_generic(hw);
     64  1.1  msaitoh 
     65  1.1  msaitoh 
     66  1.1  msaitoh 	/* EEPROM */
     67  1.1  msaitoh 	eeprom->ops.init_params = &ixgbe_init_eeprom_params_X540;
     68  1.1  msaitoh 	eeprom->ops.read = &ixgbe_read_eerd_X540;
     69  1.1  msaitoh 	eeprom->ops.read_buffer = &ixgbe_read_eerd_buffer_X540;
     70  1.1  msaitoh 	eeprom->ops.write = &ixgbe_write_eewr_X540;
     71  1.1  msaitoh 	eeprom->ops.write_buffer = &ixgbe_write_eewr_buffer_X540;
     72  1.1  msaitoh 	eeprom->ops.update_checksum = &ixgbe_update_eeprom_checksum_X540;
     73  1.1  msaitoh 	eeprom->ops.validate_checksum = &ixgbe_validate_eeprom_checksum_X540;
     74  1.1  msaitoh 	eeprom->ops.calc_checksum = &ixgbe_calc_eeprom_checksum_X540;
     75  1.1  msaitoh 
     76  1.1  msaitoh 	/* PHY */
     77  1.1  msaitoh 	phy->ops.init = &ixgbe_init_phy_ops_generic;
     78  1.1  msaitoh 	phy->ops.reset = NULL;
     79  1.1  msaitoh 
     80  1.1  msaitoh 	/* MAC */
     81  1.1  msaitoh 	mac->ops.reset_hw = &ixgbe_reset_hw_X540;
     82  1.1  msaitoh 	mac->ops.enable_relaxed_ordering = &ixgbe_enable_relaxed_ordering_gen2;
     83  1.1  msaitoh 	mac->ops.get_media_type = &ixgbe_get_media_type_X540;
     84  1.1  msaitoh 	mac->ops.get_supported_physical_layer =
     85  1.1  msaitoh 				    &ixgbe_get_supported_physical_layer_X540;
     86  1.1  msaitoh 	mac->ops.read_analog_reg8 = NULL;
     87  1.1  msaitoh 	mac->ops.write_analog_reg8 = NULL;
     88  1.1  msaitoh 	mac->ops.start_hw = &ixgbe_start_hw_X540;
     89  1.1  msaitoh 	mac->ops.get_san_mac_addr = &ixgbe_get_san_mac_addr_generic;
     90  1.1  msaitoh 	mac->ops.set_san_mac_addr = &ixgbe_set_san_mac_addr_generic;
     91  1.1  msaitoh 	mac->ops.get_device_caps = &ixgbe_get_device_caps_generic;
     92  1.1  msaitoh 	mac->ops.get_wwn_prefix = &ixgbe_get_wwn_prefix_generic;
     93  1.1  msaitoh 	mac->ops.get_fcoe_boot_status = &ixgbe_get_fcoe_boot_status_generic;
     94  1.1  msaitoh 	mac->ops.acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X540;
     95  1.1  msaitoh 	mac->ops.release_swfw_sync = &ixgbe_release_swfw_sync_X540;
     96  1.1  msaitoh 	mac->ops.disable_sec_rx_path = &ixgbe_disable_sec_rx_path_generic;
     97  1.1  msaitoh 	mac->ops.enable_sec_rx_path = &ixgbe_enable_sec_rx_path_generic;
     98  1.1  msaitoh 
     99  1.1  msaitoh 	/* RAR, Multicast, VLAN */
    100  1.1  msaitoh 	mac->ops.set_vmdq = &ixgbe_set_vmdq_generic;
    101  1.2  msaitoh 	mac->ops.set_vmdq_san_mac = &ixgbe_set_vmdq_san_mac_generic;
    102  1.1  msaitoh 	mac->ops.clear_vmdq = &ixgbe_clear_vmdq_generic;
    103  1.1  msaitoh 	mac->ops.insert_mac_addr = &ixgbe_insert_mac_addr_generic;
    104  1.1  msaitoh 	mac->rar_highwater = 1;
    105  1.1  msaitoh 	mac->ops.set_vfta = &ixgbe_set_vfta_generic;
    106  1.1  msaitoh 	mac->ops.set_vlvf = &ixgbe_set_vlvf_generic;
    107  1.1  msaitoh 	mac->ops.clear_vfta = &ixgbe_clear_vfta_generic;
    108  1.1  msaitoh 	mac->ops.init_uta_tables = &ixgbe_init_uta_tables_generic;
    109  1.1  msaitoh 	mac->ops.set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing;
    110  1.1  msaitoh 	mac->ops.set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing;
    111  1.1  msaitoh 
    112  1.1  msaitoh 	/* Link */
    113  1.1  msaitoh 	mac->ops.get_link_capabilities =
    114  1.1  msaitoh 				&ixgbe_get_copper_link_capabilities_generic;
    115  1.1  msaitoh 	mac->ops.setup_link = &ixgbe_setup_mac_link_X540;
    116  1.1  msaitoh 	mac->ops.setup_rxpba = &ixgbe_set_rxpba_generic;
    117  1.1  msaitoh 	mac->ops.check_link = &ixgbe_check_mac_link_generic;
    118  1.1  msaitoh 
    119  1.1  msaitoh 	mac->mcft_size		= 128;
    120  1.1  msaitoh 	mac->vft_size		= 128;
    121  1.1  msaitoh 	mac->num_rar_entries	= 128;
    122  1.1  msaitoh 	mac->rx_pb_size		= 384;
    123  1.1  msaitoh 	mac->max_tx_queues	= 128;
    124  1.1  msaitoh 	mac->max_rx_queues	= 128;
    125  1.1  msaitoh 	mac->max_msix_vectors	= ixgbe_get_pcie_msix_count_generic(hw);
    126  1.1  msaitoh 
    127  1.1  msaitoh 	/*
    128  1.1  msaitoh 	 * FWSM register
    129  1.1  msaitoh 	 * ARC supported; valid only if manageability features are
    130  1.1  msaitoh 	 * enabled.
    131  1.1  msaitoh 	 */
    132  1.1  msaitoh 	mac->arc_subsystem_valid = (IXGBE_READ_REG(hw, IXGBE_FWSM) &
    133  1.1  msaitoh 				   IXGBE_FWSM_MODE_MASK) ? TRUE : FALSE;
    134  1.1  msaitoh 
    135  1.1  msaitoh 	hw->mbx.ops.init_params = ixgbe_init_mbx_params_pf;
    136  1.1  msaitoh 
    137  1.1  msaitoh 	/* LEDs */
    138  1.1  msaitoh 	mac->ops.blink_led_start = ixgbe_blink_led_start_X540;
    139  1.1  msaitoh 	mac->ops.blink_led_stop = ixgbe_blink_led_stop_X540;
    140  1.1  msaitoh 
    141  1.1  msaitoh 	/* Manageability interface */
    142  1.1  msaitoh 	mac->ops.set_fw_drv_ver = &ixgbe_set_fw_drv_ver_generic;
    143  1.1  msaitoh 
    144  1.1  msaitoh 	return ret_val;
    145  1.1  msaitoh }
    146  1.1  msaitoh 
    147  1.1  msaitoh /**
    148  1.1  msaitoh  *  ixgbe_get_link_capabilities_X540 - Determines link capabilities
    149  1.1  msaitoh  *  @hw: pointer to hardware structure
    150  1.1  msaitoh  *  @speed: pointer to link speed
    151  1.1  msaitoh  *  @autoneg: TRUE when autoneg or autotry is enabled
    152  1.1  msaitoh  *
    153  1.1  msaitoh  *  Determines the link capabilities by reading the AUTOC register.
    154  1.1  msaitoh  **/
    155  1.1  msaitoh s32 ixgbe_get_link_capabilities_X540(struct ixgbe_hw *hw,
    156  1.1  msaitoh 				     ixgbe_link_speed *speed,
    157  1.1  msaitoh 				     bool *autoneg)
    158  1.1  msaitoh {
    159  1.1  msaitoh 	ixgbe_get_copper_link_capabilities_generic(hw, speed, autoneg);
    160  1.1  msaitoh 
    161  1.1  msaitoh 	return IXGBE_SUCCESS;
    162  1.1  msaitoh }
    163  1.1  msaitoh 
    164  1.1  msaitoh /**
    165  1.1  msaitoh  *  ixgbe_get_media_type_X540 - Get media type
    166  1.1  msaitoh  *  @hw: pointer to hardware structure
    167  1.1  msaitoh  *
    168  1.1  msaitoh  *  Returns the media type (fiber, copper, backplane)
    169  1.1  msaitoh  **/
    170  1.1  msaitoh enum ixgbe_media_type ixgbe_get_media_type_X540(struct ixgbe_hw *hw)
    171  1.1  msaitoh {
    172  1.1  msaitoh 	UNREFERENCED_1PARAMETER(hw);
    173  1.1  msaitoh 	return ixgbe_media_type_copper;
    174  1.1  msaitoh }
    175  1.1  msaitoh 
    176  1.1  msaitoh /**
    177  1.1  msaitoh  *  ixgbe_setup_mac_link_X540 - Sets the auto advertised capabilities
    178  1.1  msaitoh  *  @hw: pointer to hardware structure
    179  1.1  msaitoh  *  @speed: new link speed
    180  1.1  msaitoh  *  @autoneg: TRUE if autonegotiation enabled
    181  1.1  msaitoh  *  @autoneg_wait_to_complete: TRUE when waiting for completion is needed
    182  1.1  msaitoh  **/
    183  1.1  msaitoh s32 ixgbe_setup_mac_link_X540(struct ixgbe_hw *hw,
    184  1.1  msaitoh 			      ixgbe_link_speed speed, bool autoneg,
    185  1.1  msaitoh 			      bool autoneg_wait_to_complete)
    186  1.1  msaitoh {
    187  1.1  msaitoh 	DEBUGFUNC("ixgbe_setup_mac_link_X540");
    188  1.1  msaitoh 	return hw->phy.ops.setup_link_speed(hw, speed, autoneg,
    189  1.1  msaitoh 					    autoneg_wait_to_complete);
    190  1.1  msaitoh }
    191  1.1  msaitoh 
    192  1.1  msaitoh /**
    193  1.1  msaitoh  *  ixgbe_reset_hw_X540 - Perform hardware reset
    194  1.1  msaitoh  *  @hw: pointer to hardware structure
    195  1.1  msaitoh  *
    196  1.1  msaitoh  *  Resets the hardware by resetting the transmit and receive units, masks
    197  1.1  msaitoh  *  and clears all interrupts, and perform a reset.
    198  1.1  msaitoh  **/
    199  1.1  msaitoh s32 ixgbe_reset_hw_X540(struct ixgbe_hw *hw)
    200  1.1  msaitoh {
    201  1.1  msaitoh 	s32 status;
    202  1.1  msaitoh 	u32 ctrl, i;
    203  1.1  msaitoh 
    204  1.1  msaitoh 	DEBUGFUNC("ixgbe_reset_hw_X540");
    205  1.1  msaitoh 
    206  1.1  msaitoh 	/* Call adapter stop to disable tx/rx and clear interrupts */
    207  1.1  msaitoh 	status = hw->mac.ops.stop_adapter(hw);
    208  1.1  msaitoh 	if (status != IXGBE_SUCCESS)
    209  1.1  msaitoh 		goto reset_hw_out;
    210  1.1  msaitoh 
    211  1.1  msaitoh 	/* flush pending Tx transactions */
    212  1.1  msaitoh 	ixgbe_clear_tx_pending(hw);
    213  1.1  msaitoh 
    214  1.1  msaitoh mac_reset_top:
    215  1.1  msaitoh 	ctrl = IXGBE_CTRL_RST;
    216  1.1  msaitoh 	ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
    217  1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
    218  1.1  msaitoh 	IXGBE_WRITE_FLUSH(hw);
    219  1.1  msaitoh 
    220  1.1  msaitoh 	/* Poll for reset bit to self-clear indicating reset is complete */
    221  1.1  msaitoh 	for (i = 0; i < 10; i++) {
    222  1.1  msaitoh 		usec_delay(1);
    223  1.1  msaitoh 		ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
    224  1.1  msaitoh 		if (!(ctrl & IXGBE_CTRL_RST_MASK))
    225  1.1  msaitoh 			break;
    226  1.1  msaitoh 	}
    227  1.1  msaitoh 
    228  1.1  msaitoh 	if (ctrl & IXGBE_CTRL_RST_MASK) {
    229  1.1  msaitoh 		status = IXGBE_ERR_RESET_FAILED;
    230  1.1  msaitoh 		DEBUGOUT("Reset polling failed to complete.\n");
    231  1.1  msaitoh 	}
    232  1.1  msaitoh 	msec_delay(100);
    233  1.1  msaitoh 
    234  1.1  msaitoh 	/*
    235  1.1  msaitoh 	 * Double resets are required for recovery from certain error
    236  1.1  msaitoh 	 * conditions.  Between resets, it is necessary to stall to allow time
    237  1.1  msaitoh 	 * for any pending HW events to complete.
    238  1.1  msaitoh 	 */
    239  1.1  msaitoh 	if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
    240  1.1  msaitoh 		hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
    241  1.1  msaitoh 		goto mac_reset_top;
    242  1.1  msaitoh 	}
    243  1.1  msaitoh 
    244  1.1  msaitoh 	/* Set the Rx packet buffer size. */
    245  1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0), 384 << IXGBE_RXPBSIZE_SHIFT);
    246  1.1  msaitoh 
    247  1.1  msaitoh 	/* Store the permanent mac address */
    248  1.1  msaitoh 	hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
    249  1.1  msaitoh 
    250  1.1  msaitoh 	/*
    251  1.1  msaitoh 	 * Store MAC address from RAR0, clear receive address registers, and
    252  1.1  msaitoh 	 * clear the multicast table.  Also reset num_rar_entries to 128,
    253  1.1  msaitoh 	 * since we modify this value when programming the SAN MAC address.
    254  1.1  msaitoh 	 */
    255  1.1  msaitoh 	hw->mac.num_rar_entries = 128;
    256  1.1  msaitoh 	hw->mac.ops.init_rx_addrs(hw);
    257  1.1  msaitoh 
    258  1.1  msaitoh 	/* Store the permanent SAN mac address */
    259  1.1  msaitoh 	hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr);
    260  1.1  msaitoh 
    261  1.1  msaitoh 	/* Add the SAN MAC address to the RAR only if it's a valid address */
    262  1.1  msaitoh 	if (ixgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
    263  1.1  msaitoh 		hw->mac.ops.set_rar(hw, hw->mac.num_rar_entries - 1,
    264  1.1  msaitoh 				    hw->mac.san_addr, 0, IXGBE_RAH_AV);
    265  1.1  msaitoh 
    266  1.2  msaitoh 		/* Save the SAN MAC RAR index */
    267  1.2  msaitoh 		hw->mac.san_mac_rar_index = hw->mac.num_rar_entries - 1;
    268  1.2  msaitoh 
    269  1.1  msaitoh 		/* Reserve the last RAR for the SAN MAC address */
    270  1.1  msaitoh 		hw->mac.num_rar_entries--;
    271  1.1  msaitoh 	}
    272  1.1  msaitoh 
    273  1.1  msaitoh 	/* Store the alternative WWNN/WWPN prefix */
    274  1.1  msaitoh 	hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
    275  1.1  msaitoh 				   &hw->mac.wwpn_prefix);
    276  1.1  msaitoh 
    277  1.1  msaitoh reset_hw_out:
    278  1.1  msaitoh 	return status;
    279  1.1  msaitoh }
    280  1.1  msaitoh 
    281  1.1  msaitoh /**
    282  1.1  msaitoh  *  ixgbe_start_hw_X540 - Prepare hardware for Tx/Rx
    283  1.1  msaitoh  *  @hw: pointer to hardware structure
    284  1.1  msaitoh  *
    285  1.1  msaitoh  *  Starts the hardware using the generic start_hw function
    286  1.1  msaitoh  *  and the generation start_hw function.
    287  1.1  msaitoh  *  Then performs revision-specific operations, if any.
    288  1.1  msaitoh  **/
    289  1.1  msaitoh s32 ixgbe_start_hw_X540(struct ixgbe_hw *hw)
    290  1.1  msaitoh {
    291  1.1  msaitoh 	s32 ret_val = IXGBE_SUCCESS;
    292  1.1  msaitoh 
    293  1.1  msaitoh 	DEBUGFUNC("ixgbe_start_hw_X540");
    294  1.1  msaitoh 
    295  1.1  msaitoh 	ret_val = ixgbe_start_hw_generic(hw);
    296  1.1  msaitoh 	if (ret_val != IXGBE_SUCCESS)
    297  1.1  msaitoh 		goto out;
    298  1.1  msaitoh 
    299  1.1  msaitoh 	ret_val = ixgbe_start_hw_gen2(hw);
    300  1.1  msaitoh 
    301  1.1  msaitoh out:
    302  1.1  msaitoh 	return ret_val;
    303  1.1  msaitoh }
    304  1.1  msaitoh 
    305  1.1  msaitoh /**
    306  1.1  msaitoh  *  ixgbe_get_supported_physical_layer_X540 - Returns physical layer type
    307  1.1  msaitoh  *  @hw: pointer to hardware structure
    308  1.1  msaitoh  *
    309  1.1  msaitoh  *  Determines physical layer capabilities of the current configuration.
    310  1.1  msaitoh  **/
    311  1.1  msaitoh u32 ixgbe_get_supported_physical_layer_X540(struct ixgbe_hw *hw)
    312  1.1  msaitoh {
    313  1.1  msaitoh 	u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
    314  1.1  msaitoh 	u16 ext_ability = 0;
    315  1.1  msaitoh 
    316  1.1  msaitoh 	DEBUGFUNC("ixgbe_get_supported_physical_layer_X540");
    317  1.1  msaitoh 
    318  1.1  msaitoh 	hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_EXT_ABILITY,
    319  1.1  msaitoh 	IXGBE_MDIO_PMA_PMD_DEV_TYPE, &ext_ability);
    320  1.1  msaitoh 	if (ext_ability & IXGBE_MDIO_PHY_10GBASET_ABILITY)
    321  1.1  msaitoh 		physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
    322  1.1  msaitoh 	if (ext_ability & IXGBE_MDIO_PHY_1000BASET_ABILITY)
    323  1.1  msaitoh 		physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
    324  1.1  msaitoh 	if (ext_ability & IXGBE_MDIO_PHY_100BASETX_ABILITY)
    325  1.1  msaitoh 		physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
    326  1.1  msaitoh 
    327  1.1  msaitoh 	return physical_layer;
    328  1.1  msaitoh }
    329  1.1  msaitoh 
    330  1.1  msaitoh /**
    331  1.1  msaitoh  *  ixgbe_init_eeprom_params_X540 - Initialize EEPROM params
    332  1.1  msaitoh  *  @hw: pointer to hardware structure
    333  1.1  msaitoh  *
    334  1.1  msaitoh  *  Initializes the EEPROM parameters ixgbe_eeprom_info within the
    335  1.1  msaitoh  *  ixgbe_hw struct in order to set up EEPROM access.
    336  1.1  msaitoh  **/
    337  1.1  msaitoh s32 ixgbe_init_eeprom_params_X540(struct ixgbe_hw *hw)
    338  1.1  msaitoh {
    339  1.1  msaitoh 	struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
    340  1.1  msaitoh 	u32 eec;
    341  1.1  msaitoh 	u16 eeprom_size;
    342  1.1  msaitoh 
    343  1.1  msaitoh 	DEBUGFUNC("ixgbe_init_eeprom_params_X540");
    344  1.1  msaitoh 
    345  1.1  msaitoh 	if (eeprom->type == ixgbe_eeprom_uninitialized) {
    346  1.1  msaitoh 		eeprom->semaphore_delay = 10;
    347  1.1  msaitoh 		eeprom->type = ixgbe_flash;
    348  1.1  msaitoh 
    349  1.1  msaitoh 		eec = IXGBE_READ_REG(hw, IXGBE_EEC);
    350  1.1  msaitoh 		eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
    351  1.1  msaitoh 				    IXGBE_EEC_SIZE_SHIFT);
    352  1.1  msaitoh 		eeprom->word_size = 1 << (eeprom_size +
    353  1.1  msaitoh 					  IXGBE_EEPROM_WORD_SIZE_SHIFT);
    354  1.1  msaitoh 
    355  1.1  msaitoh 		DEBUGOUT2("Eeprom params: type = %d, size = %d\n",
    356  1.1  msaitoh 			  eeprom->type, eeprom->word_size);
    357  1.1  msaitoh 	}
    358  1.1  msaitoh 
    359  1.1  msaitoh 	return IXGBE_SUCCESS;
    360  1.1  msaitoh }
    361  1.1  msaitoh 
    362  1.1  msaitoh /**
    363  1.1  msaitoh  *  ixgbe_read_eerd_X540- Read EEPROM word using EERD
    364  1.1  msaitoh  *  @hw: pointer to hardware structure
    365  1.1  msaitoh  *  @offset: offset of  word in the EEPROM to read
    366  1.1  msaitoh  *  @data: word read from the EEPROM
    367  1.1  msaitoh  *
    368  1.1  msaitoh  *  Reads a 16 bit word from the EEPROM using the EERD register.
    369  1.1  msaitoh  **/
    370  1.1  msaitoh s32 ixgbe_read_eerd_X540(struct ixgbe_hw *hw, u16 offset, u16 *data)
    371  1.1  msaitoh {
    372  1.1  msaitoh 	s32 status = IXGBE_SUCCESS;
    373  1.1  msaitoh 
    374  1.1  msaitoh 	DEBUGFUNC("ixgbe_read_eerd_X540");
    375  1.1  msaitoh 	if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
    376  1.1  msaitoh 	    IXGBE_SUCCESS)
    377  1.1  msaitoh 		status = ixgbe_read_eerd_generic(hw, offset, data);
    378  1.1  msaitoh 	else
    379  1.1  msaitoh 		status = IXGBE_ERR_SWFW_SYNC;
    380  1.1  msaitoh 
    381  1.1  msaitoh 	hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
    382  1.1  msaitoh 	return status;
    383  1.1  msaitoh }
    384  1.1  msaitoh 
    385  1.1  msaitoh /**
    386  1.1  msaitoh  *  ixgbe_read_eerd_buffer_X540- Read EEPROM word(s) using EERD
    387  1.1  msaitoh  *  @hw: pointer to hardware structure
    388  1.1  msaitoh  *  @offset: offset of  word in the EEPROM to read
    389  1.1  msaitoh  *  @words: number of words
    390  1.1  msaitoh  *  @data: word(s) read from the EEPROM
    391  1.1  msaitoh  *
    392  1.1  msaitoh  *  Reads a 16 bit word(s) from the EEPROM using the EERD register.
    393  1.1  msaitoh  **/
    394  1.1  msaitoh s32 ixgbe_read_eerd_buffer_X540(struct ixgbe_hw *hw,
    395  1.1  msaitoh 				u16 offset, u16 words, u16 *data)
    396  1.1  msaitoh {
    397  1.1  msaitoh 	s32 status = IXGBE_SUCCESS;
    398  1.1  msaitoh 
    399  1.1  msaitoh 	DEBUGFUNC("ixgbe_read_eerd_buffer_X540");
    400  1.1  msaitoh 	if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
    401  1.1  msaitoh 	    IXGBE_SUCCESS)
    402  1.1  msaitoh 		status = ixgbe_read_eerd_buffer_generic(hw, offset,
    403  1.1  msaitoh 							words, data);
    404  1.1  msaitoh 	else
    405  1.1  msaitoh 		status = IXGBE_ERR_SWFW_SYNC;
    406  1.1  msaitoh 
    407  1.1  msaitoh 	hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
    408  1.1  msaitoh 	return status;
    409  1.1  msaitoh }
    410  1.1  msaitoh 
    411  1.1  msaitoh /**
    412  1.1  msaitoh  *  ixgbe_write_eewr_X540 - Write EEPROM word using EEWR
    413  1.1  msaitoh  *  @hw: pointer to hardware structure
    414  1.1  msaitoh  *  @offset: offset of  word in the EEPROM to write
    415  1.1  msaitoh  *  @data: word write to the EEPROM
    416  1.1  msaitoh  *
    417  1.1  msaitoh  *  Write a 16 bit word to the EEPROM using the EEWR register.
    418  1.1  msaitoh  **/
    419  1.1  msaitoh s32 ixgbe_write_eewr_X540(struct ixgbe_hw *hw, u16 offset, u16 data)
    420  1.1  msaitoh {
    421  1.1  msaitoh 	s32 status = IXGBE_SUCCESS;
    422  1.1  msaitoh 
    423  1.1  msaitoh 	DEBUGFUNC("ixgbe_write_eewr_X540");
    424  1.1  msaitoh 	if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
    425  1.1  msaitoh 	    IXGBE_SUCCESS)
    426  1.1  msaitoh 		status = ixgbe_write_eewr_generic(hw, offset, data);
    427  1.1  msaitoh 	else
    428  1.1  msaitoh 		status = IXGBE_ERR_SWFW_SYNC;
    429  1.1  msaitoh 
    430  1.1  msaitoh 	hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
    431  1.1  msaitoh 	return status;
    432  1.1  msaitoh }
    433  1.1  msaitoh 
    434  1.1  msaitoh /**
    435  1.1  msaitoh  *  ixgbe_write_eewr_buffer_X540 - Write EEPROM word(s) using EEWR
    436  1.1  msaitoh  *  @hw: pointer to hardware structure
    437  1.1  msaitoh  *  @offset: offset of  word in the EEPROM to write
    438  1.1  msaitoh  *  @words: number of words
    439  1.1  msaitoh  *  @data: word(s) write to the EEPROM
    440  1.1  msaitoh  *
    441  1.1  msaitoh  *  Write a 16 bit word(s) to the EEPROM using the EEWR register.
    442  1.1  msaitoh  **/
    443  1.1  msaitoh s32 ixgbe_write_eewr_buffer_X540(struct ixgbe_hw *hw,
    444  1.1  msaitoh 				 u16 offset, u16 words, u16 *data)
    445  1.1  msaitoh {
    446  1.1  msaitoh 	s32 status = IXGBE_SUCCESS;
    447  1.1  msaitoh 
    448  1.1  msaitoh 	DEBUGFUNC("ixgbe_write_eewr_buffer_X540");
    449  1.1  msaitoh 	if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
    450  1.1  msaitoh 	    IXGBE_SUCCESS)
    451  1.1  msaitoh 		status = ixgbe_write_eewr_buffer_generic(hw, offset,
    452  1.1  msaitoh 							 words, data);
    453  1.1  msaitoh 	else
    454  1.1  msaitoh 		status = IXGBE_ERR_SWFW_SYNC;
    455  1.1  msaitoh 
    456  1.1  msaitoh 	hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
    457  1.1  msaitoh 	return status;
    458  1.1  msaitoh }
    459  1.1  msaitoh 
    460  1.1  msaitoh /**
    461  1.1  msaitoh  *  ixgbe_calc_eeprom_checksum_X540 - Calculates and returns the checksum
    462  1.1  msaitoh  *
    463  1.1  msaitoh  *  This function does not use synchronization for EERD and EEWR. It can
    464  1.1  msaitoh  *  be used internally by function which utilize ixgbe_acquire_swfw_sync_X540.
    465  1.1  msaitoh  *
    466  1.1  msaitoh  *  @hw: pointer to hardware structure
    467  1.1  msaitoh  **/
    468  1.1  msaitoh u16 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw)
    469  1.1  msaitoh {
    470  1.1  msaitoh 	u16 i;
    471  1.1  msaitoh 	u16 j;
    472  1.1  msaitoh 	u16 checksum = 0;
    473  1.1  msaitoh 	u16 length = 0;
    474  1.1  msaitoh 	u16 pointer = 0;
    475  1.1  msaitoh 	u16 word = 0;
    476  1.1  msaitoh 
    477  1.1  msaitoh 	/*
    478  1.1  msaitoh 	 * Do not use hw->eeprom.ops.read because we do not want to take
    479  1.1  msaitoh 	 * the synchronization semaphores here. Instead use
    480  1.1  msaitoh 	 * ixgbe_read_eerd_generic
    481  1.1  msaitoh 	 */
    482  1.1  msaitoh 
    483  1.1  msaitoh 	DEBUGFUNC("ixgbe_calc_eeprom_checksum_X540");
    484  1.1  msaitoh 
    485  1.1  msaitoh 	/* Include 0x0-0x3F in the checksum */
    486  1.1  msaitoh 	for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
    487  1.1  msaitoh 		if (ixgbe_read_eerd_generic(hw, i, &word) != IXGBE_SUCCESS) {
    488  1.1  msaitoh 			DEBUGOUT("EEPROM read failed\n");
    489  1.1  msaitoh 			break;
    490  1.1  msaitoh 		}
    491  1.1  msaitoh 		checksum += word;
    492  1.1  msaitoh 	}
    493  1.1  msaitoh 
    494  1.1  msaitoh 	/*
    495  1.1  msaitoh 	 * Include all data from pointers 0x3, 0x6-0xE.  This excludes the
    496  1.1  msaitoh 	 * FW, PHY module, and PCIe Expansion/Option ROM pointers.
    497  1.1  msaitoh 	 */
    498  1.1  msaitoh 	for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
    499  1.1  msaitoh 		if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
    500  1.1  msaitoh 			continue;
    501  1.1  msaitoh 
    502  1.1  msaitoh 		if (ixgbe_read_eerd_generic(hw, i, &pointer) != IXGBE_SUCCESS) {
    503  1.1  msaitoh 			DEBUGOUT("EEPROM read failed\n");
    504  1.1  msaitoh 			break;
    505  1.1  msaitoh 		}
    506  1.1  msaitoh 
    507  1.1  msaitoh 		/* Skip pointer section if the pointer is invalid. */
    508  1.1  msaitoh 		if (pointer == 0xFFFF || pointer == 0 ||
    509  1.1  msaitoh 		    pointer >= hw->eeprom.word_size)
    510  1.1  msaitoh 			continue;
    511  1.1  msaitoh 
    512  1.1  msaitoh 		if (ixgbe_read_eerd_generic(hw, pointer, &length) !=
    513  1.1  msaitoh 		    IXGBE_SUCCESS) {
    514  1.1  msaitoh 			DEBUGOUT("EEPROM read failed\n");
    515  1.1  msaitoh 			break;
    516  1.1  msaitoh 		}
    517  1.1  msaitoh 
    518  1.1  msaitoh 		/* Skip pointer section if length is invalid. */
    519  1.1  msaitoh 		if (length == 0xFFFF || length == 0 ||
    520  1.1  msaitoh 		    (pointer + length) >= hw->eeprom.word_size)
    521  1.1  msaitoh 			continue;
    522  1.1  msaitoh 
    523  1.1  msaitoh 		for (j = pointer+1; j <= pointer+length; j++) {
    524  1.1  msaitoh 			if (ixgbe_read_eerd_generic(hw, j, &word) !=
    525  1.1  msaitoh 			    IXGBE_SUCCESS) {
    526  1.1  msaitoh 				DEBUGOUT("EEPROM read failed\n");
    527  1.1  msaitoh 				break;
    528  1.1  msaitoh 			}
    529  1.1  msaitoh 			checksum += word;
    530  1.1  msaitoh 		}
    531  1.1  msaitoh 	}
    532  1.1  msaitoh 
    533  1.1  msaitoh 	checksum = (u16)IXGBE_EEPROM_SUM - checksum;
    534  1.1  msaitoh 
    535  1.1  msaitoh 	return checksum;
    536  1.1  msaitoh }
    537  1.1  msaitoh 
    538  1.1  msaitoh /**
    539  1.1  msaitoh  *  ixgbe_validate_eeprom_checksum_X540 - Validate EEPROM checksum
    540  1.1  msaitoh  *  @hw: pointer to hardware structure
    541  1.1  msaitoh  *  @checksum_val: calculated checksum
    542  1.1  msaitoh  *
    543  1.1  msaitoh  *  Performs checksum calculation and validates the EEPROM checksum.  If the
    544  1.1  msaitoh  *  caller does not need checksum_val, the value can be NULL.
    545  1.1  msaitoh  **/
    546  1.1  msaitoh s32 ixgbe_validate_eeprom_checksum_X540(struct ixgbe_hw *hw,
    547  1.1  msaitoh 					u16 *checksum_val)
    548  1.1  msaitoh {
    549  1.1  msaitoh 	s32 status;
    550  1.1  msaitoh 	u16 checksum;
    551  1.1  msaitoh 	u16 read_checksum = 0;
    552  1.1  msaitoh 
    553  1.1  msaitoh 	DEBUGFUNC("ixgbe_validate_eeprom_checksum_X540");
    554  1.1  msaitoh 
    555  1.1  msaitoh 	/*
    556  1.1  msaitoh 	 * Read the first word from the EEPROM. If this times out or fails, do
    557  1.1  msaitoh 	 * not continue or we could be in for a very long wait while every
    558  1.1  msaitoh 	 * EEPROM read fails
    559  1.1  msaitoh 	 */
    560  1.1  msaitoh 	status = hw->eeprom.ops.read(hw, 0, &checksum);
    561  1.1  msaitoh 
    562  1.1  msaitoh 	if (status != IXGBE_SUCCESS) {
    563  1.1  msaitoh 		DEBUGOUT("EEPROM read failed\n");
    564  1.1  msaitoh 		goto out;
    565  1.1  msaitoh 	}
    566  1.1  msaitoh 
    567  1.1  msaitoh 	if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
    568  1.1  msaitoh 	    IXGBE_SUCCESS) {
    569  1.1  msaitoh 		checksum = hw->eeprom.ops.calc_checksum(hw);
    570  1.1  msaitoh 
    571  1.1  msaitoh 		/*
    572  1.1  msaitoh 		 * Do not use hw->eeprom.ops.read because we do not want to take
    573  1.1  msaitoh 		 * the synchronization semaphores twice here.
    574  1.1  msaitoh 		*/
    575  1.1  msaitoh 		ixgbe_read_eerd_generic(hw, IXGBE_EEPROM_CHECKSUM,
    576  1.1  msaitoh 					&read_checksum);
    577  1.1  msaitoh 
    578  1.1  msaitoh 		/*
    579  1.1  msaitoh 		 * Verify read checksum from EEPROM is the same as
    580  1.1  msaitoh 		 * calculated checksum
    581  1.1  msaitoh 		 */
    582  1.1  msaitoh 		if (read_checksum != checksum)
    583  1.1  msaitoh 			status = IXGBE_ERR_EEPROM_CHECKSUM;
    584  1.1  msaitoh 
    585  1.1  msaitoh 		/* If the user cares, return the calculated checksum */
    586  1.1  msaitoh 		if (checksum_val)
    587  1.1  msaitoh 			*checksum_val = checksum;
    588  1.1  msaitoh 	} else {
    589  1.1  msaitoh 		status = IXGBE_ERR_SWFW_SYNC;
    590  1.1  msaitoh 	}
    591  1.1  msaitoh 
    592  1.1  msaitoh 	hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
    593  1.1  msaitoh out:
    594  1.1  msaitoh 	return status;
    595  1.1  msaitoh }
    596  1.1  msaitoh 
    597  1.1  msaitoh /**
    598  1.1  msaitoh  * ixgbe_update_eeprom_checksum_X540 - Updates the EEPROM checksum and flash
    599  1.1  msaitoh  * @hw: pointer to hardware structure
    600  1.1  msaitoh  *
    601  1.1  msaitoh  * After writing EEPROM to shadow RAM using EEWR register, software calculates
    602  1.1  msaitoh  * checksum and updates the EEPROM and instructs the hardware to update
    603  1.1  msaitoh  * the flash.
    604  1.1  msaitoh  **/
    605  1.1  msaitoh s32 ixgbe_update_eeprom_checksum_X540(struct ixgbe_hw *hw)
    606  1.1  msaitoh {
    607  1.1  msaitoh 	s32 status;
    608  1.1  msaitoh 	u16 checksum;
    609  1.1  msaitoh 
    610  1.1  msaitoh 	DEBUGFUNC("ixgbe_update_eeprom_checksum_X540");
    611  1.1  msaitoh 
    612  1.1  msaitoh 	/*
    613  1.1  msaitoh 	 * Read the first word from the EEPROM. If this times out or fails, do
    614  1.1  msaitoh 	 * not continue or we could be in for a very long wait while every
    615  1.1  msaitoh 	 * EEPROM read fails
    616  1.1  msaitoh 	 */
    617  1.1  msaitoh 	status = hw->eeprom.ops.read(hw, 0, &checksum);
    618  1.1  msaitoh 
    619  1.1  msaitoh 	if (status != IXGBE_SUCCESS)
    620  1.1  msaitoh 		DEBUGOUT("EEPROM read failed\n");
    621  1.1  msaitoh 
    622  1.1  msaitoh 	if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
    623  1.1  msaitoh 	    IXGBE_SUCCESS) {
    624  1.1  msaitoh 		checksum = hw->eeprom.ops.calc_checksum(hw);
    625  1.1  msaitoh 
    626  1.1  msaitoh 		/*
    627  1.1  msaitoh 		 * Do not use hw->eeprom.ops.write because we do not want to
    628  1.1  msaitoh 		 * take the synchronization semaphores twice here.
    629  1.1  msaitoh 		*/
    630  1.1  msaitoh 		status = ixgbe_write_eewr_generic(hw, IXGBE_EEPROM_CHECKSUM,
    631  1.1  msaitoh 						  checksum);
    632  1.1  msaitoh 
    633  1.1  msaitoh 	if (status == IXGBE_SUCCESS)
    634  1.1  msaitoh 		status = ixgbe_update_flash_X540(hw);
    635  1.1  msaitoh 	else
    636  1.1  msaitoh 		status = IXGBE_ERR_SWFW_SYNC;
    637  1.1  msaitoh 	}
    638  1.1  msaitoh 
    639  1.1  msaitoh 	hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
    640  1.1  msaitoh 
    641  1.1  msaitoh 	return status;
    642  1.1  msaitoh }
    643  1.1  msaitoh 
    644  1.1  msaitoh /**
    645  1.1  msaitoh  *  ixgbe_update_flash_X540 - Instruct HW to copy EEPROM to Flash device
    646  1.1  msaitoh  *  @hw: pointer to hardware structure
    647  1.1  msaitoh  *
    648  1.1  msaitoh  *  Set FLUP (bit 23) of the EEC register to instruct Hardware to copy
    649  1.1  msaitoh  *  EEPROM from shadow RAM to the flash device.
    650  1.1  msaitoh  **/
    651  1.1  msaitoh static s32 ixgbe_update_flash_X540(struct ixgbe_hw *hw)
    652  1.1  msaitoh {
    653  1.1  msaitoh 	u32 flup;
    654  1.1  msaitoh 	s32 status = IXGBE_ERR_EEPROM;
    655  1.1  msaitoh 
    656  1.1  msaitoh 	DEBUGFUNC("ixgbe_update_flash_X540");
    657  1.1  msaitoh 
    658  1.1  msaitoh 	status = ixgbe_poll_flash_update_done_X540(hw);
    659  1.1  msaitoh 	if (status == IXGBE_ERR_EEPROM) {
    660  1.1  msaitoh 		DEBUGOUT("Flash update time out\n");
    661  1.1  msaitoh 		goto out;
    662  1.1  msaitoh 	}
    663  1.1  msaitoh 
    664  1.1  msaitoh 	flup = IXGBE_READ_REG(hw, IXGBE_EEC) | IXGBE_EEC_FLUP;
    665  1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_EEC, flup);
    666  1.1  msaitoh 
    667  1.1  msaitoh 	status = ixgbe_poll_flash_update_done_X540(hw);
    668  1.1  msaitoh 	if (status == IXGBE_SUCCESS)
    669  1.1  msaitoh 		DEBUGOUT("Flash update complete\n");
    670  1.1  msaitoh 	else
    671  1.1  msaitoh 		DEBUGOUT("Flash update time out\n");
    672  1.1  msaitoh 
    673  1.1  msaitoh 	if (hw->revision_id == 0) {
    674  1.1  msaitoh 		flup = IXGBE_READ_REG(hw, IXGBE_EEC);
    675  1.1  msaitoh 
    676  1.1  msaitoh 		if (flup & IXGBE_EEC_SEC1VAL) {
    677  1.1  msaitoh 			flup |= IXGBE_EEC_FLUP;
    678  1.1  msaitoh 			IXGBE_WRITE_REG(hw, IXGBE_EEC, flup);
    679  1.1  msaitoh 		}
    680  1.1  msaitoh 
    681  1.1  msaitoh 		status = ixgbe_poll_flash_update_done_X540(hw);
    682  1.1  msaitoh 		if (status == IXGBE_SUCCESS)
    683  1.1  msaitoh 			DEBUGOUT("Flash update complete\n");
    684  1.1  msaitoh 		else
    685  1.1  msaitoh 			DEBUGOUT("Flash update time out\n");
    686  1.1  msaitoh 	}
    687  1.1  msaitoh out:
    688  1.1  msaitoh 	return status;
    689  1.1  msaitoh }
    690  1.1  msaitoh 
    691  1.1  msaitoh /**
    692  1.1  msaitoh  *  ixgbe_poll_flash_update_done_X540 - Poll flash update status
    693  1.1  msaitoh  *  @hw: pointer to hardware structure
    694  1.1  msaitoh  *
    695  1.1  msaitoh  *  Polls the FLUDONE (bit 26) of the EEC Register to determine when the
    696  1.1  msaitoh  *  flash update is done.
    697  1.1  msaitoh  **/
    698  1.1  msaitoh static s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw)
    699  1.1  msaitoh {
    700  1.1  msaitoh 	u32 i;
    701  1.1  msaitoh 	u32 reg;
    702  1.1  msaitoh 	s32 status = IXGBE_ERR_EEPROM;
    703  1.1  msaitoh 
    704  1.1  msaitoh 	DEBUGFUNC("ixgbe_poll_flash_update_done_X540");
    705  1.1  msaitoh 
    706  1.1  msaitoh 	for (i = 0; i < IXGBE_FLUDONE_ATTEMPTS; i++) {
    707  1.1  msaitoh 		reg = IXGBE_READ_REG(hw, IXGBE_EEC);
    708  1.1  msaitoh 		if (reg & IXGBE_EEC_FLUDONE) {
    709  1.1  msaitoh 			status = IXGBE_SUCCESS;
    710  1.1  msaitoh 			break;
    711  1.1  msaitoh 		}
    712  1.1  msaitoh 		usec_delay(5);
    713  1.1  msaitoh 	}
    714  1.1  msaitoh 	return status;
    715  1.1  msaitoh }
    716  1.1  msaitoh 
    717  1.1  msaitoh /**
    718  1.1  msaitoh  *  ixgbe_acquire_swfw_sync_X540 - Acquire SWFW semaphore
    719  1.1  msaitoh  *  @hw: pointer to hardware structure
    720  1.1  msaitoh  *  @mask: Mask to specify which semaphore to acquire
    721  1.1  msaitoh  *
    722  1.1  msaitoh  *  Acquires the SWFW semaphore thought the SW_FW_SYNC register for
    723  1.1  msaitoh  *  the specified function (CSR, PHY0, PHY1, NVM, Flash)
    724  1.1  msaitoh  **/
    725  1.1  msaitoh s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask)
    726  1.1  msaitoh {
    727  1.1  msaitoh 	u32 swfw_sync;
    728  1.1  msaitoh 	u32 swmask = mask;
    729  1.1  msaitoh 	u32 fwmask = mask << 5;
    730  1.1  msaitoh 	u32 hwmask = 0;
    731  1.1  msaitoh 	u32 timeout = 200;
    732  1.1  msaitoh 	u32 i;
    733  1.1  msaitoh 	s32 ret_val = IXGBE_SUCCESS;
    734  1.1  msaitoh 
    735  1.1  msaitoh 	DEBUGFUNC("ixgbe_acquire_swfw_sync_X540");
    736  1.1  msaitoh 
    737  1.1  msaitoh 	if (swmask == IXGBE_GSSR_EEP_SM)
    738  1.1  msaitoh 		hwmask = IXGBE_GSSR_FLASH_SM;
    739  1.1  msaitoh 
    740  1.1  msaitoh 	/* SW only mask doesn't have FW bit pair */
    741  1.1  msaitoh 	if (swmask == IXGBE_GSSR_SW_MNG_SM)
    742  1.1  msaitoh 		fwmask = 0;
    743  1.1  msaitoh 
    744  1.1  msaitoh 	for (i = 0; i < timeout; i++) {
    745  1.1  msaitoh 		/*
    746  1.1  msaitoh 		 * SW NVM semaphore bit is used for access to all
    747  1.1  msaitoh 		 * SW_FW_SYNC bits (not just NVM)
    748  1.1  msaitoh 		 */
    749  1.1  msaitoh 		if (ixgbe_get_swfw_sync_semaphore(hw)) {
    750  1.1  msaitoh 			ret_val = IXGBE_ERR_SWFW_SYNC;
    751  1.1  msaitoh 			goto out;
    752  1.1  msaitoh 		}
    753  1.1  msaitoh 
    754  1.1  msaitoh 		swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
    755  1.1  msaitoh 		if (!(swfw_sync & (fwmask | swmask | hwmask))) {
    756  1.1  msaitoh 			swfw_sync |= swmask;
    757  1.1  msaitoh 			IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
    758  1.1  msaitoh 			ixgbe_release_swfw_sync_semaphore(hw);
    759  1.1  msaitoh 			msec_delay(5);
    760  1.1  msaitoh 			goto out;
    761  1.1  msaitoh 		} else {
    762  1.1  msaitoh 			/*
    763  1.1  msaitoh 			 * Firmware currently using resource (fwmask), hardware
    764  1.1  msaitoh 			 * currently using resource (hwmask), or other software
    765  1.1  msaitoh 			 * thread currently using resource (swmask)
    766  1.1  msaitoh 			 */
    767  1.1  msaitoh 			ixgbe_release_swfw_sync_semaphore(hw);
    768  1.1  msaitoh 			msec_delay(5);
    769  1.1  msaitoh 		}
    770  1.1  msaitoh 	}
    771  1.1  msaitoh 
    772  1.1  msaitoh 	/* Failed to get SW only semaphore */
    773  1.1  msaitoh 	if (swmask == IXGBE_GSSR_SW_MNG_SM) {
    774  1.1  msaitoh 		ret_val = IXGBE_ERR_SWFW_SYNC;
    775  1.1  msaitoh 		goto out;
    776  1.1  msaitoh 	}
    777  1.1  msaitoh 
    778  1.1  msaitoh 	/* If the resource is not released by the FW/HW the SW can assume that
    779  1.1  msaitoh 	 * the FW/HW malfunctions. In that case the SW should sets the SW bit(s)
    780  1.1  msaitoh 	 * of the requested resource(s) while ignoring the corresponding FW/HW
    781  1.1  msaitoh 	 * bits in the SW_FW_SYNC register.
    782  1.1  msaitoh 	 */
    783  1.1  msaitoh 	swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
    784  1.1  msaitoh 	if (swfw_sync & (fwmask | hwmask)) {
    785  1.1  msaitoh 		if (ixgbe_get_swfw_sync_semaphore(hw)) {
    786  1.1  msaitoh 			ret_val = IXGBE_ERR_SWFW_SYNC;
    787  1.1  msaitoh 			goto out;
    788  1.1  msaitoh 		}
    789  1.1  msaitoh 
    790  1.1  msaitoh 		swfw_sync |= swmask;
    791  1.1  msaitoh 		IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
    792  1.1  msaitoh 		ixgbe_release_swfw_sync_semaphore(hw);
    793  1.1  msaitoh 		msec_delay(5);
    794  1.1  msaitoh 	}
    795  1.1  msaitoh 
    796  1.1  msaitoh out:
    797  1.1  msaitoh 	return ret_val;
    798  1.1  msaitoh }
    799  1.1  msaitoh 
    800  1.1  msaitoh /**
    801  1.1  msaitoh  *  ixgbe_release_swfw_sync_X540 - Release SWFW semaphore
    802  1.1  msaitoh  *  @hw: pointer to hardware structure
    803  1.1  msaitoh  *  @mask: Mask to specify which semaphore to release
    804  1.1  msaitoh  *
    805  1.2  msaitoh  *  Releases the SWFW semaphore through the SW_FW_SYNC register
    806  1.1  msaitoh  *  for the specified function (CSR, PHY0, PHY1, EVM, Flash)
    807  1.1  msaitoh  **/
    808  1.1  msaitoh void ixgbe_release_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask)
    809  1.1  msaitoh {
    810  1.1  msaitoh 	u32 swfw_sync;
    811  1.1  msaitoh 	u32 swmask = mask;
    812  1.1  msaitoh 
    813  1.1  msaitoh 	DEBUGFUNC("ixgbe_release_swfw_sync_X540");
    814  1.1  msaitoh 
    815  1.1  msaitoh 	ixgbe_get_swfw_sync_semaphore(hw);
    816  1.1  msaitoh 
    817  1.1  msaitoh 	swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
    818  1.1  msaitoh 	swfw_sync &= ~swmask;
    819  1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
    820  1.1  msaitoh 
    821  1.1  msaitoh 	ixgbe_release_swfw_sync_semaphore(hw);
    822  1.1  msaitoh 	msec_delay(5);
    823  1.1  msaitoh }
    824  1.1  msaitoh 
    825  1.1  msaitoh /**
    826  1.1  msaitoh  *  ixgbe_get_nvm_semaphore - Get hardware semaphore
    827  1.1  msaitoh  *  @hw: pointer to hardware structure
    828  1.1  msaitoh  *
    829  1.1  msaitoh  *  Sets the hardware semaphores so SW/FW can gain control of shared resources
    830  1.1  msaitoh  **/
    831  1.1  msaitoh static s32 ixgbe_get_swfw_sync_semaphore(struct ixgbe_hw *hw)
    832  1.1  msaitoh {
    833  1.1  msaitoh 	s32 status = IXGBE_ERR_EEPROM;
    834  1.1  msaitoh 	u32 timeout = 2000;
    835  1.1  msaitoh 	u32 i;
    836  1.1  msaitoh 	u32 swsm;
    837  1.1  msaitoh 
    838  1.1  msaitoh 	DEBUGFUNC("ixgbe_get_swfw_sync_semaphore");
    839  1.1  msaitoh 
    840  1.1  msaitoh 	/* Get SMBI software semaphore between device drivers first */
    841  1.1  msaitoh 	for (i = 0; i < timeout; i++) {
    842  1.1  msaitoh 		/*
    843  1.1  msaitoh 		 * If the SMBI bit is 0 when we read it, then the bit will be
    844  1.1  msaitoh 		 * set and we have the semaphore
    845  1.1  msaitoh 		 */
    846  1.1  msaitoh 		swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
    847  1.1  msaitoh 		if (!(swsm & IXGBE_SWSM_SMBI)) {
    848  1.1  msaitoh 			status = IXGBE_SUCCESS;
    849  1.1  msaitoh 			break;
    850  1.1  msaitoh 		}
    851  1.1  msaitoh 		usec_delay(50);
    852  1.1  msaitoh 	}
    853  1.1  msaitoh 
    854  1.1  msaitoh 	/* Now get the semaphore between SW/FW through the REGSMP bit */
    855  1.1  msaitoh 	if (status == IXGBE_SUCCESS) {
    856  1.1  msaitoh 		for (i = 0; i < timeout; i++) {
    857  1.1  msaitoh 			swsm = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
    858  1.1  msaitoh 			if (!(swsm & IXGBE_SWFW_REGSMP))
    859  1.1  msaitoh 				break;
    860  1.1  msaitoh 
    861  1.1  msaitoh 			usec_delay(50);
    862  1.1  msaitoh 		}
    863  1.1  msaitoh 
    864  1.1  msaitoh 		/*
    865  1.1  msaitoh 		 * Release semaphores and return error if SW NVM semaphore
    866  1.1  msaitoh 		 * was not granted because we don't have access to the EEPROM
    867  1.1  msaitoh 		 */
    868  1.1  msaitoh 		if (i >= timeout) {
    869  1.1  msaitoh 			DEBUGOUT("REGSMP Software NVM semaphore not "
    870  1.1  msaitoh 				 "granted.\n");
    871  1.1  msaitoh 			ixgbe_release_swfw_sync_semaphore(hw);
    872  1.1  msaitoh 			status = IXGBE_ERR_EEPROM;
    873  1.1  msaitoh 		}
    874  1.1  msaitoh 	} else {
    875  1.1  msaitoh 		DEBUGOUT("Software semaphore SMBI between device drivers "
    876  1.1  msaitoh 			 "not granted.\n");
    877  1.1  msaitoh 	}
    878  1.1  msaitoh 
    879  1.1  msaitoh 	return status;
    880  1.1  msaitoh }
    881  1.1  msaitoh 
    882  1.1  msaitoh /**
    883  1.1  msaitoh  *  ixgbe_release_nvm_semaphore - Release hardware semaphore
    884  1.1  msaitoh  *  @hw: pointer to hardware structure
    885  1.1  msaitoh  *
    886  1.1  msaitoh  *  This function clears hardware semaphore bits.
    887  1.1  msaitoh  **/
    888  1.1  msaitoh static void ixgbe_release_swfw_sync_semaphore(struct ixgbe_hw *hw)
    889  1.1  msaitoh {
    890  1.1  msaitoh 	u32 swsm;
    891  1.1  msaitoh 
    892  1.1  msaitoh 	DEBUGFUNC("ixgbe_release_swfw_sync_semaphore");
    893  1.1  msaitoh 
    894  1.1  msaitoh 	/* Release both semaphores by writing 0 to the bits REGSMP and SMBI */
    895  1.1  msaitoh 
    896  1.1  msaitoh 	swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
    897  1.1  msaitoh 	swsm &= ~IXGBE_SWSM_SMBI;
    898  1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
    899  1.1  msaitoh 
    900  1.1  msaitoh 	swsm = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
    901  1.1  msaitoh 	swsm &= ~IXGBE_SWFW_REGSMP;
    902  1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swsm);
    903  1.1  msaitoh 
    904  1.1  msaitoh 	IXGBE_WRITE_FLUSH(hw);
    905  1.1  msaitoh }
    906  1.1  msaitoh 
    907  1.1  msaitoh /**
    908  1.1  msaitoh  * ixgbe_blink_led_start_X540 - Blink LED based on index.
    909  1.1  msaitoh  * @hw: pointer to hardware structure
    910  1.1  msaitoh  * @index: led number to blink
    911  1.1  msaitoh  *
    912  1.1  msaitoh  * Devices that implement the version 2 interface:
    913  1.1  msaitoh  *   X540
    914  1.1  msaitoh  **/
    915  1.1  msaitoh s32 ixgbe_blink_led_start_X540(struct ixgbe_hw *hw, u32 index)
    916  1.1  msaitoh {
    917  1.1  msaitoh 	u32 macc_reg;
    918  1.1  msaitoh 	u32 ledctl_reg;
    919  1.1  msaitoh 	ixgbe_link_speed speed;
    920  1.1  msaitoh 	bool link_up;
    921  1.1  msaitoh 
    922  1.1  msaitoh 	DEBUGFUNC("ixgbe_blink_led_start_X540");
    923  1.1  msaitoh 
    924  1.1  msaitoh 	/*
    925  1.1  msaitoh 	 * Link should be up in order for the blink bit in the LED control
    926  1.1  msaitoh 	 * register to work. Force link and speed in the MAC if link is down.
    927  1.1  msaitoh 	 * This will be reversed when we stop the blinking.
    928  1.1  msaitoh 	 */
    929  1.1  msaitoh 	hw->mac.ops.check_link(hw, &speed, &link_up, FALSE);
    930  1.1  msaitoh 	if (link_up == FALSE) {
    931  1.1  msaitoh 		macc_reg = IXGBE_READ_REG(hw, IXGBE_MACC);
    932  1.1  msaitoh 		macc_reg |= IXGBE_MACC_FLU | IXGBE_MACC_FSV_10G | IXGBE_MACC_FS;
    933  1.1  msaitoh 		IXGBE_WRITE_REG(hw, IXGBE_MACC, macc_reg);
    934  1.1  msaitoh 	}
    935  1.1  msaitoh 	/* Set the LED to LINK_UP + BLINK. */
    936  1.1  msaitoh 	ledctl_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
    937  1.1  msaitoh 	ledctl_reg &= ~IXGBE_LED_MODE_MASK(index);
    938  1.1  msaitoh 	ledctl_reg |= IXGBE_LED_BLINK(index);
    939  1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, ledctl_reg);
    940  1.1  msaitoh 	IXGBE_WRITE_FLUSH(hw);
    941  1.1  msaitoh 
    942  1.1  msaitoh 	return IXGBE_SUCCESS;
    943  1.1  msaitoh }
    944  1.1  msaitoh 
    945  1.1  msaitoh /**
    946  1.1  msaitoh  * ixgbe_blink_led_stop_X540 - Stop blinking LED based on index.
    947  1.1  msaitoh  * @hw: pointer to hardware structure
    948  1.1  msaitoh  * @index: led number to stop blinking
    949  1.1  msaitoh  *
    950  1.1  msaitoh  * Devices that implement the version 2 interface:
    951  1.1  msaitoh  *   X540
    952  1.1  msaitoh  **/
    953  1.1  msaitoh s32 ixgbe_blink_led_stop_X540(struct ixgbe_hw *hw, u32 index)
    954  1.1  msaitoh {
    955  1.1  msaitoh 	u32 macc_reg;
    956  1.1  msaitoh 	u32 ledctl_reg;
    957  1.1  msaitoh 
    958  1.1  msaitoh 	DEBUGFUNC("ixgbe_blink_led_stop_X540");
    959  1.1  msaitoh 
    960  1.1  msaitoh 	/* Restore the LED to its default value. */
    961  1.1  msaitoh 	ledctl_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
    962  1.1  msaitoh 	ledctl_reg &= ~IXGBE_LED_MODE_MASK(index);
    963  1.1  msaitoh 	ledctl_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
    964  1.1  msaitoh 	ledctl_reg &= ~IXGBE_LED_BLINK(index);
    965  1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, ledctl_reg);
    966  1.1  msaitoh 
    967  1.1  msaitoh 	/* Unforce link and speed in the MAC. */
    968  1.1  msaitoh 	macc_reg = IXGBE_READ_REG(hw, IXGBE_MACC);
    969  1.1  msaitoh 	macc_reg &= ~(IXGBE_MACC_FLU | IXGBE_MACC_FSV_10G | IXGBE_MACC_FS);
    970  1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_MACC, macc_reg);
    971  1.1  msaitoh 	IXGBE_WRITE_FLUSH(hw);
    972  1.1  msaitoh 
    973  1.1  msaitoh 	return IXGBE_SUCCESS;
    974  1.1  msaitoh }
    975  1.1  msaitoh 
    976