Home | History | Annotate | Line # | Download | only in ixgbe
ixgbe_phy.c revision 1.4
      1  1.1    dyoung /******************************************************************************
      2  1.1    dyoung 
      3  1.3   msaitoh   Copyright (c) 2001-2012, Intel Corporation
      4  1.1    dyoung   All rights reserved.
      5  1.1    dyoung 
      6  1.1    dyoung   Redistribution and use in source and binary forms, with or without
      7  1.1    dyoung   modification, are permitted provided that the following conditions are met:
      8  1.1    dyoung 
      9  1.1    dyoung    1. Redistributions of source code must retain the above copyright notice,
     10  1.1    dyoung       this list of conditions and the following disclaimer.
     11  1.1    dyoung 
     12  1.1    dyoung    2. Redistributions in binary form must reproduce the above copyright
     13  1.1    dyoung       notice, this list of conditions and the following disclaimer in the
     14  1.1    dyoung       documentation and/or other materials provided with the distribution.
     15  1.1    dyoung 
     16  1.1    dyoung    3. Neither the name of the Intel Corporation nor the names of its
     17  1.1    dyoung       contributors may be used to endorse or promote products derived from
     18  1.1    dyoung       this software without specific prior written permission.
     19  1.1    dyoung 
     20  1.1    dyoung   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     21  1.1    dyoung   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22  1.1    dyoung   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23  1.1    dyoung   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     24  1.1    dyoung   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  1.1    dyoung   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  1.1    dyoung   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  1.1    dyoung   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  1.1    dyoung   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  1.1    dyoung   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  1.1    dyoung   POSSIBILITY OF SUCH DAMAGE.
     31  1.1    dyoung 
     32  1.1    dyoung ******************************************************************************/
     33  1.4   msaitoh /*$FreeBSD: head/sys/dev/ixgbe/ixgbe_phy.c 238149 2012-07-05 20:51:44Z jfv $*/
     34  1.3   msaitoh /*$NetBSD: ixgbe_phy.c,v 1.4 2015/04/02 09:26:55 msaitoh Exp $*/
     35  1.1    dyoung 
     36  1.1    dyoung #include "ixgbe_api.h"
     37  1.1    dyoung #include "ixgbe_common.h"
     38  1.1    dyoung #include "ixgbe_phy.h"
     39  1.1    dyoung 
     40  1.1    dyoung static void ixgbe_i2c_start(struct ixgbe_hw *hw);
     41  1.1    dyoung static void ixgbe_i2c_stop(struct ixgbe_hw *hw);
     42  1.1    dyoung static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data);
     43  1.1    dyoung static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data);
     44  1.1    dyoung static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw);
     45  1.1    dyoung static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data);
     46  1.1    dyoung static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data);
     47  1.3   msaitoh static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
     48  1.1    dyoung static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
     49  1.1    dyoung static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data);
     50  1.1    dyoung static bool ixgbe_get_i2c_data(u32 *i2cctl);
     51  1.1    dyoung 
     52  1.1    dyoung /**
     53  1.1    dyoung  *  ixgbe_init_phy_ops_generic - Inits PHY function ptrs
     54  1.1    dyoung  *  @hw: pointer to the hardware structure
     55  1.1    dyoung  *
     56  1.1    dyoung  *  Initialize the function pointers.
     57  1.1    dyoung  **/
     58  1.1    dyoung s32 ixgbe_init_phy_ops_generic(struct ixgbe_hw *hw)
     59  1.1    dyoung {
     60  1.1    dyoung 	struct ixgbe_phy_info *phy = &hw->phy;
     61  1.1    dyoung 
     62  1.1    dyoung 	DEBUGFUNC("ixgbe_init_phy_ops_generic");
     63  1.1    dyoung 
     64  1.1    dyoung 	/* PHY */
     65  1.1    dyoung 	phy->ops.identify = &ixgbe_identify_phy_generic;
     66  1.1    dyoung 	phy->ops.reset = &ixgbe_reset_phy_generic;
     67  1.1    dyoung 	phy->ops.read_reg = &ixgbe_read_phy_reg_generic;
     68  1.1    dyoung 	phy->ops.write_reg = &ixgbe_write_phy_reg_generic;
     69  1.1    dyoung 	phy->ops.setup_link = &ixgbe_setup_phy_link_generic;
     70  1.1    dyoung 	phy->ops.setup_link_speed = &ixgbe_setup_phy_link_speed_generic;
     71  1.1    dyoung 	phy->ops.check_link = NULL;
     72  1.1    dyoung 	phy->ops.get_firmware_version = ixgbe_get_phy_firmware_version_generic;
     73  1.1    dyoung 	phy->ops.read_i2c_byte = &ixgbe_read_i2c_byte_generic;
     74  1.1    dyoung 	phy->ops.write_i2c_byte = &ixgbe_write_i2c_byte_generic;
     75  1.1    dyoung 	phy->ops.read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic;
     76  1.1    dyoung 	phy->ops.write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic;
     77  1.1    dyoung 	phy->ops.i2c_bus_clear = &ixgbe_i2c_bus_clear;
     78  1.3   msaitoh 	phy->ops.identify_sfp = &ixgbe_identify_module_generic;
     79  1.1    dyoung 	phy->sfp_type = ixgbe_sfp_type_unknown;
     80  1.1    dyoung 	phy->ops.check_overtemp = &ixgbe_tn_check_overtemp;
     81  1.1    dyoung 	return IXGBE_SUCCESS;
     82  1.1    dyoung }
     83  1.1    dyoung 
     84  1.1    dyoung /**
     85  1.1    dyoung  *  ixgbe_identify_phy_generic - Get physical layer module
     86  1.1    dyoung  *  @hw: pointer to hardware structure
     87  1.1    dyoung  *
     88  1.1    dyoung  *  Determines the physical layer module found on the current adapter.
     89  1.1    dyoung  **/
     90  1.1    dyoung s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
     91  1.1    dyoung {
     92  1.1    dyoung 	s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
     93  1.1    dyoung 	u32 phy_addr;
     94  1.1    dyoung 	u16 ext_ability = 0;
     95  1.1    dyoung 
     96  1.1    dyoung 	DEBUGFUNC("ixgbe_identify_phy_generic");
     97  1.1    dyoung 
     98  1.1    dyoung 	if (hw->phy.type == ixgbe_phy_unknown) {
     99  1.1    dyoung 		for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
    100  1.1    dyoung 			if (ixgbe_validate_phy_addr(hw, phy_addr)) {
    101  1.1    dyoung 				hw->phy.addr = phy_addr;
    102  1.1    dyoung 				ixgbe_get_phy_id(hw);
    103  1.1    dyoung 				hw->phy.type =
    104  1.3   msaitoh 					ixgbe_get_phy_type_from_id(hw->phy.id);
    105  1.1    dyoung 
    106  1.1    dyoung 				if (hw->phy.type == ixgbe_phy_unknown) {
    107  1.1    dyoung 					hw->phy.ops.read_reg(hw,
    108  1.1    dyoung 						  IXGBE_MDIO_PHY_EXT_ABILITY,
    109  1.3   msaitoh 						  IXGBE_MDIO_PMA_PMD_DEV_TYPE,
    110  1.3   msaitoh 						  &ext_ability);
    111  1.1    dyoung 					if (ext_ability &
    112  1.1    dyoung 					    (IXGBE_MDIO_PHY_10GBASET_ABILITY |
    113  1.1    dyoung 					     IXGBE_MDIO_PHY_1000BASET_ABILITY))
    114  1.1    dyoung 						hw->phy.type =
    115  1.3   msaitoh 							 ixgbe_phy_cu_unknown;
    116  1.1    dyoung 					else
    117  1.1    dyoung 						hw->phy.type =
    118  1.3   msaitoh 							 ixgbe_phy_generic;
    119  1.1    dyoung 				}
    120  1.1    dyoung 
    121  1.1    dyoung 				status = IXGBE_SUCCESS;
    122  1.1    dyoung 				break;
    123  1.1    dyoung 			}
    124  1.1    dyoung 		}
    125  1.1    dyoung 		/* clear value if nothing found */
    126  1.1    dyoung 		if (status != IXGBE_SUCCESS)
    127  1.1    dyoung 			hw->phy.addr = 0;
    128  1.1    dyoung 	} else {
    129  1.1    dyoung 		status = IXGBE_SUCCESS;
    130  1.1    dyoung 	}
    131  1.1    dyoung 
    132  1.1    dyoung 	return status;
    133  1.1    dyoung }
    134  1.1    dyoung 
    135  1.1    dyoung /**
    136  1.1    dyoung  *  ixgbe_validate_phy_addr - Determines phy address is valid
    137  1.1    dyoung  *  @hw: pointer to hardware structure
    138  1.1    dyoung  *
    139  1.1    dyoung  **/
    140  1.1    dyoung bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr)
    141  1.1    dyoung {
    142  1.1    dyoung 	u16 phy_id = 0;
    143  1.1    dyoung 	bool valid = FALSE;
    144  1.1    dyoung 
    145  1.1    dyoung 	DEBUGFUNC("ixgbe_validate_phy_addr");
    146  1.1    dyoung 
    147  1.1    dyoung 	hw->phy.addr = phy_addr;
    148  1.1    dyoung 	hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
    149  1.3   msaitoh 			     IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_id);
    150  1.1    dyoung 
    151  1.1    dyoung 	if (phy_id != 0xFFFF && phy_id != 0x0)
    152  1.1    dyoung 		valid = TRUE;
    153  1.1    dyoung 
    154  1.1    dyoung 	return valid;
    155  1.1    dyoung }
    156  1.1    dyoung 
    157  1.1    dyoung /**
    158  1.1    dyoung  *  ixgbe_get_phy_id - Get the phy type
    159  1.1    dyoung  *  @hw: pointer to hardware structure
    160  1.1    dyoung  *
    161  1.1    dyoung  **/
    162  1.1    dyoung s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
    163  1.1    dyoung {
    164  1.1    dyoung 	u32 status;
    165  1.1    dyoung 	u16 phy_id_high = 0;
    166  1.1    dyoung 	u16 phy_id_low = 0;
    167  1.1    dyoung 
    168  1.1    dyoung 	DEBUGFUNC("ixgbe_get_phy_id");
    169  1.1    dyoung 
    170  1.1    dyoung 	status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
    171  1.3   msaitoh 				      IXGBE_MDIO_PMA_PMD_DEV_TYPE,
    172  1.3   msaitoh 				      &phy_id_high);
    173  1.1    dyoung 
    174  1.1    dyoung 	if (status == IXGBE_SUCCESS) {
    175  1.1    dyoung 		hw->phy.id = (u32)(phy_id_high << 16);
    176  1.1    dyoung 		status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_LOW,
    177  1.3   msaitoh 					      IXGBE_MDIO_PMA_PMD_DEV_TYPE,
    178  1.3   msaitoh 					      &phy_id_low);
    179  1.1    dyoung 		hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
    180  1.1    dyoung 		hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
    181  1.1    dyoung 	}
    182  1.1    dyoung 	return status;
    183  1.1    dyoung }
    184  1.1    dyoung 
    185  1.1    dyoung /**
    186  1.1    dyoung  *  ixgbe_get_phy_type_from_id - Get the phy type
    187  1.1    dyoung  *  @hw: pointer to hardware structure
    188  1.1    dyoung  *
    189  1.1    dyoung  **/
    190  1.1    dyoung enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
    191  1.1    dyoung {
    192  1.1    dyoung 	enum ixgbe_phy_type phy_type;
    193  1.1    dyoung 
    194  1.1    dyoung 	DEBUGFUNC("ixgbe_get_phy_type_from_id");
    195  1.1    dyoung 
    196  1.1    dyoung 	switch (phy_id) {
    197  1.1    dyoung 	case TN1010_PHY_ID:
    198  1.1    dyoung 		phy_type = ixgbe_phy_tn;
    199  1.1    dyoung 		break;
    200  1.3   msaitoh 	case X540_PHY_ID:
    201  1.1    dyoung 		phy_type = ixgbe_phy_aq;
    202  1.1    dyoung 		break;
    203  1.1    dyoung 	case QT2022_PHY_ID:
    204  1.1    dyoung 		phy_type = ixgbe_phy_qt;
    205  1.1    dyoung 		break;
    206  1.1    dyoung 	case ATH_PHY_ID:
    207  1.1    dyoung 		phy_type = ixgbe_phy_nl;
    208  1.1    dyoung 		break;
    209  1.1    dyoung 	default:
    210  1.1    dyoung 		phy_type = ixgbe_phy_unknown;
    211  1.1    dyoung 		break;
    212  1.1    dyoung 	}
    213  1.1    dyoung 
    214  1.1    dyoung 	DEBUGOUT1("phy type found is %d\n", phy_type);
    215  1.1    dyoung 	return phy_type;
    216  1.1    dyoung }
    217  1.1    dyoung 
    218  1.1    dyoung /**
    219  1.1    dyoung  *  ixgbe_reset_phy_generic - Performs a PHY reset
    220  1.1    dyoung  *  @hw: pointer to hardware structure
    221  1.1    dyoung  **/
    222  1.1    dyoung s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
    223  1.1    dyoung {
    224  1.1    dyoung 	u32 i;
    225  1.1    dyoung 	u16 ctrl = 0;
    226  1.1    dyoung 	s32 status = IXGBE_SUCCESS;
    227  1.1    dyoung 
    228  1.1    dyoung 	DEBUGFUNC("ixgbe_reset_phy_generic");
    229  1.1    dyoung 
    230  1.1    dyoung 	if (hw->phy.type == ixgbe_phy_unknown)
    231  1.1    dyoung 		status = ixgbe_identify_phy_generic(hw);
    232  1.1    dyoung 
    233  1.1    dyoung 	if (status != IXGBE_SUCCESS || hw->phy.type == ixgbe_phy_none)
    234  1.1    dyoung 		goto out;
    235  1.1    dyoung 
    236  1.1    dyoung 	/* Don't reset PHY if it's shut down due to overtemp. */
    237  1.1    dyoung 	if (!hw->phy.reset_if_overtemp &&
    238  1.1    dyoung 	    (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
    239  1.1    dyoung 		goto out;
    240  1.1    dyoung 
    241  1.1    dyoung 	/*
    242  1.1    dyoung 	 * Perform soft PHY reset to the PHY_XS.
    243  1.1    dyoung 	 * This will cause a soft reset to the PHY
    244  1.1    dyoung 	 */
    245  1.1    dyoung 	hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
    246  1.3   msaitoh 			      IXGBE_MDIO_PHY_XS_DEV_TYPE,
    247  1.3   msaitoh 			      IXGBE_MDIO_PHY_XS_RESET);
    248  1.1    dyoung 
    249  1.1    dyoung 	/*
    250  1.1    dyoung 	 * Poll for reset bit to self-clear indicating reset is complete.
    251  1.1    dyoung 	 * Some PHYs could take up to 3 seconds to complete and need about
    252  1.1    dyoung 	 * 1.7 usec delay after the reset is complete.
    253  1.1    dyoung 	 */
    254  1.1    dyoung 	for (i = 0; i < 30; i++) {
    255  1.1    dyoung 		msec_delay(100);
    256  1.1    dyoung 		hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
    257  1.3   msaitoh 				     IXGBE_MDIO_PHY_XS_DEV_TYPE, &ctrl);
    258  1.1    dyoung 		if (!(ctrl & IXGBE_MDIO_PHY_XS_RESET)) {
    259  1.1    dyoung 			usec_delay(2);
    260  1.1    dyoung 			break;
    261  1.1    dyoung 		}
    262  1.1    dyoung 	}
    263  1.1    dyoung 
    264  1.1    dyoung 	if (ctrl & IXGBE_MDIO_PHY_XS_RESET) {
    265  1.1    dyoung 		status = IXGBE_ERR_RESET_FAILED;
    266  1.1    dyoung 		DEBUGOUT("PHY reset polling failed to complete.\n");
    267  1.1    dyoung 	}
    268  1.1    dyoung 
    269  1.1    dyoung out:
    270  1.1    dyoung 	return status;
    271  1.1    dyoung }
    272  1.1    dyoung 
    273  1.1    dyoung /**
    274  1.1    dyoung  *  ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
    275  1.1    dyoung  *  @hw: pointer to hardware structure
    276  1.1    dyoung  *  @reg_addr: 32 bit address of PHY register to read
    277  1.1    dyoung  *  @phy_data: Pointer to read data from PHY register
    278  1.1    dyoung  **/
    279  1.1    dyoung s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
    280  1.3   msaitoh 			       u32 device_type, u16 *phy_data)
    281  1.1    dyoung {
    282  1.1    dyoung 	u32 command;
    283  1.1    dyoung 	u32 i;
    284  1.1    dyoung 	u32 data;
    285  1.1    dyoung 	s32 status = IXGBE_SUCCESS;
    286  1.1    dyoung 	u16 gssr;
    287  1.1    dyoung 
    288  1.1    dyoung 	DEBUGFUNC("ixgbe_read_phy_reg_generic");
    289  1.1    dyoung 
    290  1.1    dyoung 	if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
    291  1.1    dyoung 		gssr = IXGBE_GSSR_PHY1_SM;
    292  1.1    dyoung 	else
    293  1.1    dyoung 		gssr = IXGBE_GSSR_PHY0_SM;
    294  1.1    dyoung 
    295  1.3   msaitoh 	if (hw->mac.ops.acquire_swfw_sync(hw, gssr) != IXGBE_SUCCESS)
    296  1.1    dyoung 		status = IXGBE_ERR_SWFW_SYNC;
    297  1.1    dyoung 
    298  1.1    dyoung 	if (status == IXGBE_SUCCESS) {
    299  1.1    dyoung 		/* Setup and write the address cycle command */
    300  1.1    dyoung 		command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT)  |
    301  1.3   msaitoh 			   (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
    302  1.3   msaitoh 			   (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
    303  1.3   msaitoh 			   (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
    304  1.1    dyoung 
    305  1.1    dyoung 		IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
    306  1.1    dyoung 
    307  1.1    dyoung 		/*
    308  1.1    dyoung 		 * Check every 10 usec to see if the address cycle completed.
    309  1.1    dyoung 		 * The MDI Command bit will clear when the operation is
    310  1.1    dyoung 		 * complete
    311  1.1    dyoung 		 */
    312  1.1    dyoung 		for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
    313  1.1    dyoung 			usec_delay(10);
    314  1.1    dyoung 
    315  1.1    dyoung 			command = IXGBE_READ_REG(hw, IXGBE_MSCA);
    316  1.1    dyoung 
    317  1.1    dyoung 			if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
    318  1.1    dyoung 				break;
    319  1.1    dyoung 		}
    320  1.1    dyoung 
    321  1.1    dyoung 		if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
    322  1.1    dyoung 			DEBUGOUT("PHY address command did not complete.\n");
    323  1.1    dyoung 			status = IXGBE_ERR_PHY;
    324  1.1    dyoung 		}
    325  1.1    dyoung 
    326  1.1    dyoung 		if (status == IXGBE_SUCCESS) {
    327  1.1    dyoung 			/*
    328  1.1    dyoung 			 * Address cycle complete, setup and write the read
    329  1.1    dyoung 			 * command
    330  1.1    dyoung 			 */
    331  1.1    dyoung 			command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT)  |
    332  1.3   msaitoh 				   (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
    333  1.3   msaitoh 				   (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
    334  1.3   msaitoh 				   (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
    335  1.1    dyoung 
    336  1.1    dyoung 			IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
    337  1.1    dyoung 
    338  1.1    dyoung 			/*
    339  1.1    dyoung 			 * Check every 10 usec to see if the address cycle
    340  1.1    dyoung 			 * completed. The MDI Command bit will clear when the
    341  1.1    dyoung 			 * operation is complete
    342  1.1    dyoung 			 */
    343  1.1    dyoung 			for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
    344  1.1    dyoung 				usec_delay(10);
    345  1.1    dyoung 
    346  1.1    dyoung 				command = IXGBE_READ_REG(hw, IXGBE_MSCA);
    347  1.1    dyoung 
    348  1.1    dyoung 				if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
    349  1.1    dyoung 					break;
    350  1.1    dyoung 			}
    351  1.1    dyoung 
    352  1.1    dyoung 			if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
    353  1.1    dyoung 				DEBUGOUT("PHY read command didn't complete\n");
    354  1.1    dyoung 				status = IXGBE_ERR_PHY;
    355  1.1    dyoung 			} else {
    356  1.1    dyoung 				/*
    357  1.1    dyoung 				 * Read operation is complete.  Get the data
    358  1.1    dyoung 				 * from MSRWD
    359  1.1    dyoung 				 */
    360  1.1    dyoung 				data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
    361  1.1    dyoung 				data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
    362  1.1    dyoung 				*phy_data = (u16)(data);
    363  1.1    dyoung 			}
    364  1.1    dyoung 		}
    365  1.1    dyoung 
    366  1.3   msaitoh 		hw->mac.ops.release_swfw_sync(hw, gssr);
    367  1.1    dyoung 	}
    368  1.1    dyoung 
    369  1.1    dyoung 	return status;
    370  1.1    dyoung }
    371  1.1    dyoung 
    372  1.1    dyoung /**
    373  1.1    dyoung  *  ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
    374  1.1    dyoung  *  @hw: pointer to hardware structure
    375  1.1    dyoung  *  @reg_addr: 32 bit PHY register to write
    376  1.1    dyoung  *  @device_type: 5 bit device type
    377  1.1    dyoung  *  @phy_data: Data to write to the PHY register
    378  1.1    dyoung  **/
    379  1.1    dyoung s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
    380  1.3   msaitoh 				u32 device_type, u16 phy_data)
    381  1.1    dyoung {
    382  1.1    dyoung 	u32 command;
    383  1.1    dyoung 	u32 i;
    384  1.1    dyoung 	s32 status = IXGBE_SUCCESS;
    385  1.1    dyoung 	u16 gssr;
    386  1.1    dyoung 
    387  1.1    dyoung 	DEBUGFUNC("ixgbe_write_phy_reg_generic");
    388  1.1    dyoung 
    389  1.1    dyoung 	if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
    390  1.1    dyoung 		gssr = IXGBE_GSSR_PHY1_SM;
    391  1.1    dyoung 	else
    392  1.1    dyoung 		gssr = IXGBE_GSSR_PHY0_SM;
    393  1.1    dyoung 
    394  1.3   msaitoh 	if (hw->mac.ops.acquire_swfw_sync(hw, gssr) != IXGBE_SUCCESS)
    395  1.1    dyoung 		status = IXGBE_ERR_SWFW_SYNC;
    396  1.1    dyoung 
    397  1.1    dyoung 	if (status == IXGBE_SUCCESS) {
    398  1.1    dyoung 		/* Put the data in the MDI single read and write data register*/
    399  1.1    dyoung 		IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
    400  1.1    dyoung 
    401  1.1    dyoung 		/* Setup and write the address cycle command */
    402  1.1    dyoung 		command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT)  |
    403  1.3   msaitoh 			   (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
    404  1.3   msaitoh 			   (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
    405  1.3   msaitoh 			   (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
    406  1.1    dyoung 
    407  1.1    dyoung 		IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
    408  1.1    dyoung 
    409  1.1    dyoung 		/*
    410  1.1    dyoung 		 * Check every 10 usec to see if the address cycle completed.
    411  1.1    dyoung 		 * The MDI Command bit will clear when the operation is
    412  1.1    dyoung 		 * complete
    413  1.1    dyoung 		 */
    414  1.1    dyoung 		for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
    415  1.1    dyoung 			usec_delay(10);
    416  1.1    dyoung 
    417  1.1    dyoung 			command = IXGBE_READ_REG(hw, IXGBE_MSCA);
    418  1.1    dyoung 
    419  1.1    dyoung 			if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
    420  1.1    dyoung 				break;
    421  1.1    dyoung 		}
    422  1.1    dyoung 
    423  1.1    dyoung 		if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
    424  1.1    dyoung 			DEBUGOUT("PHY address cmd didn't complete\n");
    425  1.1    dyoung 			status = IXGBE_ERR_PHY;
    426  1.1    dyoung 		}
    427  1.1    dyoung 
    428  1.1    dyoung 		if (status == IXGBE_SUCCESS) {
    429  1.1    dyoung 			/*
    430  1.1    dyoung 			 * Address cycle complete, setup and write the write
    431  1.1    dyoung 			 * command
    432  1.1    dyoung 			 */
    433  1.1    dyoung 			command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT)  |
    434  1.3   msaitoh 				   (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
    435  1.3   msaitoh 				   (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
    436  1.3   msaitoh 				   (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
    437  1.1    dyoung 
    438  1.1    dyoung 			IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
    439  1.1    dyoung 
    440  1.1    dyoung 			/*
    441  1.1    dyoung 			 * Check every 10 usec to see if the address cycle
    442  1.1    dyoung 			 * completed. The MDI Command bit will clear when the
    443  1.1    dyoung 			 * operation is complete
    444  1.1    dyoung 			 */
    445  1.1    dyoung 			for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
    446  1.1    dyoung 				usec_delay(10);
    447  1.1    dyoung 
    448  1.1    dyoung 				command = IXGBE_READ_REG(hw, IXGBE_MSCA);
    449  1.1    dyoung 
    450  1.1    dyoung 				if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
    451  1.1    dyoung 					break;
    452  1.1    dyoung 			}
    453  1.1    dyoung 
    454  1.1    dyoung 			if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
    455  1.1    dyoung 				DEBUGOUT("PHY address cmd didn't complete\n");
    456  1.1    dyoung 				status = IXGBE_ERR_PHY;
    457  1.1    dyoung 			}
    458  1.1    dyoung 		}
    459  1.1    dyoung 
    460  1.3   msaitoh 		hw->mac.ops.release_swfw_sync(hw, gssr);
    461  1.1    dyoung 	}
    462  1.1    dyoung 
    463  1.1    dyoung 	return status;
    464  1.1    dyoung }
    465  1.1    dyoung 
    466  1.1    dyoung /**
    467  1.1    dyoung  *  ixgbe_setup_phy_link_generic - Set and restart autoneg
    468  1.1    dyoung  *  @hw: pointer to hardware structure
    469  1.1    dyoung  *
    470  1.1    dyoung  *  Restart autonegotiation and PHY and waits for completion.
    471  1.1    dyoung  **/
    472  1.1    dyoung s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
    473  1.1    dyoung {
    474  1.1    dyoung 	s32 status = IXGBE_SUCCESS;
    475  1.1    dyoung 	u32 time_out;
    476  1.1    dyoung 	u32 max_time_out = 10;
    477  1.1    dyoung 	u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
    478  1.1    dyoung 	bool autoneg = FALSE;
    479  1.1    dyoung 	ixgbe_link_speed speed;
    480  1.1    dyoung 
    481  1.1    dyoung 	DEBUGFUNC("ixgbe_setup_phy_link_generic");
    482  1.1    dyoung 
    483  1.1    dyoung 	ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
    484  1.1    dyoung 
    485  1.1    dyoung 	if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
    486  1.1    dyoung 		/* Set or unset auto-negotiation 10G advertisement */
    487  1.1    dyoung 		hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
    488  1.3   msaitoh 				     IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    489  1.3   msaitoh 				     &autoneg_reg);
    490  1.1    dyoung 
    491  1.1    dyoung 		autoneg_reg &= ~IXGBE_MII_10GBASE_T_ADVERTISE;
    492  1.1    dyoung 		if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
    493  1.1    dyoung 			autoneg_reg |= IXGBE_MII_10GBASE_T_ADVERTISE;
    494  1.1    dyoung 
    495  1.1    dyoung 		hw->phy.ops.write_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
    496  1.3   msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    497  1.3   msaitoh 				      autoneg_reg);
    498  1.1    dyoung 	}
    499  1.1    dyoung 
    500  1.1    dyoung 	if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
    501  1.1    dyoung 		/* Set or unset auto-negotiation 1G advertisement */
    502  1.1    dyoung 		hw->phy.ops.read_reg(hw,
    503  1.3   msaitoh 				     IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
    504  1.3   msaitoh 				     IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    505  1.3   msaitoh 				     &autoneg_reg);
    506  1.1    dyoung 
    507  1.1    dyoung 		autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
    508  1.1    dyoung 		if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
    509  1.1    dyoung 			autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
    510  1.1    dyoung 
    511  1.1    dyoung 		hw->phy.ops.write_reg(hw,
    512  1.3   msaitoh 				      IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
    513  1.3   msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    514  1.3   msaitoh 				      autoneg_reg);
    515  1.1    dyoung 	}
    516  1.1    dyoung 
    517  1.1    dyoung 	if (speed & IXGBE_LINK_SPEED_100_FULL) {
    518  1.1    dyoung 		/* Set or unset auto-negotiation 100M advertisement */
    519  1.1    dyoung 		hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
    520  1.3   msaitoh 				     IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    521  1.3   msaitoh 				     &autoneg_reg);
    522  1.1    dyoung 
    523  1.3   msaitoh 		autoneg_reg &= ~(IXGBE_MII_100BASE_T_ADVERTISE |
    524  1.3   msaitoh 				 IXGBE_MII_100BASE_T_ADVERTISE_HALF);
    525  1.1    dyoung 		if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
    526  1.1    dyoung 			autoneg_reg |= IXGBE_MII_100BASE_T_ADVERTISE;
    527  1.1    dyoung 
    528  1.1    dyoung 		hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
    529  1.3   msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    530  1.3   msaitoh 				      autoneg_reg);
    531  1.1    dyoung 	}
    532  1.1    dyoung 
    533  1.1    dyoung 	/* Restart PHY autonegotiation and wait for completion */
    534  1.1    dyoung 	hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
    535  1.3   msaitoh 			     IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
    536  1.1    dyoung 
    537  1.1    dyoung 	autoneg_reg |= IXGBE_MII_RESTART;
    538  1.1    dyoung 
    539  1.1    dyoung 	hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
    540  1.3   msaitoh 			      IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
    541  1.1    dyoung 
    542  1.1    dyoung 	/* Wait for autonegotiation to finish */
    543  1.1    dyoung 	for (time_out = 0; time_out < max_time_out; time_out++) {
    544  1.1    dyoung 		usec_delay(10);
    545  1.1    dyoung 		/* Restart PHY autonegotiation and wait for completion */
    546  1.1    dyoung 		status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
    547  1.3   msaitoh 					      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    548  1.3   msaitoh 					      &autoneg_reg);
    549  1.1    dyoung 
    550  1.1    dyoung 		autoneg_reg &= IXGBE_MII_AUTONEG_COMPLETE;
    551  1.3   msaitoh 		if (autoneg_reg == IXGBE_MII_AUTONEG_COMPLETE)
    552  1.1    dyoung 			break;
    553  1.1    dyoung 	}
    554  1.1    dyoung 
    555  1.1    dyoung 	if (time_out == max_time_out) {
    556  1.1    dyoung 		status = IXGBE_ERR_LINK_SETUP;
    557  1.1    dyoung 		DEBUGOUT("ixgbe_setup_phy_link_generic: time out");
    558  1.1    dyoung 	}
    559  1.1    dyoung 
    560  1.1    dyoung 	return status;
    561  1.1    dyoung }
    562  1.1    dyoung 
    563  1.1    dyoung /**
    564  1.1    dyoung  *  ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
    565  1.1    dyoung  *  @hw: pointer to hardware structure
    566  1.1    dyoung  *  @speed: new link speed
    567  1.1    dyoung  *  @autoneg: TRUE if autonegotiation enabled
    568  1.1    dyoung  **/
    569  1.1    dyoung s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
    570  1.3   msaitoh 				       ixgbe_link_speed speed,
    571  1.3   msaitoh 				       bool autoneg,
    572  1.3   msaitoh 				       bool autoneg_wait_to_complete)
    573  1.1    dyoung {
    574  1.3   msaitoh 	UNREFERENCED_2PARAMETER(autoneg, autoneg_wait_to_complete);
    575  1.1    dyoung 
    576  1.1    dyoung 	DEBUGFUNC("ixgbe_setup_phy_link_speed_generic");
    577  1.1    dyoung 
    578  1.1    dyoung 	/*
    579  1.1    dyoung 	 * Clear autoneg_advertised and set new values based on input link
    580  1.1    dyoung 	 * speed.
    581  1.1    dyoung 	 */
    582  1.1    dyoung 	hw->phy.autoneg_advertised = 0;
    583  1.1    dyoung 
    584  1.1    dyoung 	if (speed & IXGBE_LINK_SPEED_10GB_FULL)
    585  1.1    dyoung 		hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
    586  1.1    dyoung 
    587  1.1    dyoung 	if (speed & IXGBE_LINK_SPEED_1GB_FULL)
    588  1.1    dyoung 		hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
    589  1.1    dyoung 
    590  1.1    dyoung 	if (speed & IXGBE_LINK_SPEED_100_FULL)
    591  1.1    dyoung 		hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
    592  1.1    dyoung 
    593  1.1    dyoung 	/* Setup link based on the new speed settings */
    594  1.1    dyoung 	hw->phy.ops.setup_link(hw);
    595  1.1    dyoung 
    596  1.1    dyoung 	return IXGBE_SUCCESS;
    597  1.1    dyoung }
    598  1.1    dyoung 
    599  1.1    dyoung /**
    600  1.1    dyoung  *  ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
    601  1.1    dyoung  *  @hw: pointer to hardware structure
    602  1.1    dyoung  *  @speed: pointer to link speed
    603  1.1    dyoung  *  @autoneg: boolean auto-negotiation value
    604  1.1    dyoung  *
    605  1.1    dyoung  *  Determines the link capabilities by reading the AUTOC register.
    606  1.1    dyoung  **/
    607  1.1    dyoung s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
    608  1.3   msaitoh 					       ixgbe_link_speed *speed,
    609  1.3   msaitoh 					       bool *autoneg)
    610  1.1    dyoung {
    611  1.1    dyoung 	s32 status = IXGBE_ERR_LINK_SETUP;
    612  1.1    dyoung 	u16 speed_ability;
    613  1.1    dyoung 
    614  1.1    dyoung 	DEBUGFUNC("ixgbe_get_copper_link_capabilities_generic");
    615  1.1    dyoung 
    616  1.1    dyoung 	*speed = 0;
    617  1.1    dyoung 	*autoneg = TRUE;
    618  1.1    dyoung 
    619  1.1    dyoung 	status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_SPEED_ABILITY,
    620  1.3   msaitoh 				      IXGBE_MDIO_PMA_PMD_DEV_TYPE,
    621  1.3   msaitoh 				      &speed_ability);
    622  1.1    dyoung 
    623  1.1    dyoung 	if (status == IXGBE_SUCCESS) {
    624  1.1    dyoung 		if (speed_ability & IXGBE_MDIO_PHY_SPEED_10G)
    625  1.1    dyoung 			*speed |= IXGBE_LINK_SPEED_10GB_FULL;
    626  1.1    dyoung 		if (speed_ability & IXGBE_MDIO_PHY_SPEED_1G)
    627  1.1    dyoung 			*speed |= IXGBE_LINK_SPEED_1GB_FULL;
    628  1.1    dyoung 		if (speed_ability & IXGBE_MDIO_PHY_SPEED_100M)
    629  1.1    dyoung 			*speed |= IXGBE_LINK_SPEED_100_FULL;
    630  1.1    dyoung 	}
    631  1.1    dyoung 
    632  1.1    dyoung 	return status;
    633  1.1    dyoung }
    634  1.1    dyoung 
    635  1.1    dyoung /**
    636  1.1    dyoung  *  ixgbe_check_phy_link_tnx - Determine link and speed status
    637  1.1    dyoung  *  @hw: pointer to hardware structure
    638  1.1    dyoung  *
    639  1.1    dyoung  *  Reads the VS1 register to determine if link is up and the current speed for
    640  1.1    dyoung  *  the PHY.
    641  1.1    dyoung  **/
    642  1.1    dyoung s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
    643  1.3   msaitoh 			     bool *link_up)
    644  1.1    dyoung {
    645  1.1    dyoung 	s32 status = IXGBE_SUCCESS;
    646  1.1    dyoung 	u32 time_out;
    647  1.1    dyoung 	u32 max_time_out = 10;
    648  1.1    dyoung 	u16 phy_link = 0;
    649  1.1    dyoung 	u16 phy_speed = 0;
    650  1.1    dyoung 	u16 phy_data = 0;
    651  1.1    dyoung 
    652  1.1    dyoung 	DEBUGFUNC("ixgbe_check_phy_link_tnx");
    653  1.1    dyoung 
    654  1.1    dyoung 	/* Initialize speed and link to default case */
    655  1.1    dyoung 	*link_up = FALSE;
    656  1.1    dyoung 	*speed = IXGBE_LINK_SPEED_10GB_FULL;
    657  1.1    dyoung 
    658  1.1    dyoung 	/*
    659  1.1    dyoung 	 * Check current speed and link status of the PHY register.
    660  1.1    dyoung 	 * This is a vendor specific register and may have to
    661  1.1    dyoung 	 * be changed for other copper PHYs.
    662  1.1    dyoung 	 */
    663  1.1    dyoung 	for (time_out = 0; time_out < max_time_out; time_out++) {
    664  1.1    dyoung 		usec_delay(10);
    665  1.1    dyoung 		status = hw->phy.ops.read_reg(hw,
    666  1.3   msaitoh 					IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
    667  1.3   msaitoh 					IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
    668  1.3   msaitoh 					&phy_data);
    669  1.3   msaitoh 		phy_link = phy_data & IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
    670  1.1    dyoung 		phy_speed = phy_data &
    671  1.3   msaitoh 				 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
    672  1.1    dyoung 		if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
    673  1.1    dyoung 			*link_up = TRUE;
    674  1.1    dyoung 			if (phy_speed ==
    675  1.1    dyoung 			    IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
    676  1.1    dyoung 				*speed = IXGBE_LINK_SPEED_1GB_FULL;
    677  1.1    dyoung 			break;
    678  1.1    dyoung 		}
    679  1.1    dyoung 	}
    680  1.1    dyoung 
    681  1.1    dyoung 	return status;
    682  1.1    dyoung }
    683  1.1    dyoung 
    684  1.1    dyoung /**
    685  1.1    dyoung  *	ixgbe_setup_phy_link_tnx - Set and restart autoneg
    686  1.1    dyoung  *	@hw: pointer to hardware structure
    687  1.1    dyoung  *
    688  1.1    dyoung  *	Restart autonegotiation and PHY and waits for completion.
    689  1.1    dyoung  **/
    690  1.1    dyoung s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
    691  1.1    dyoung {
    692  1.1    dyoung 	s32 status = IXGBE_SUCCESS;
    693  1.1    dyoung 	u32 time_out;
    694  1.1    dyoung 	u32 max_time_out = 10;
    695  1.1    dyoung 	u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
    696  1.1    dyoung 	bool autoneg = FALSE;
    697  1.1    dyoung 	ixgbe_link_speed speed;
    698  1.1    dyoung 
    699  1.1    dyoung 	DEBUGFUNC("ixgbe_setup_phy_link_tnx");
    700  1.1    dyoung 
    701  1.1    dyoung 	ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
    702  1.1    dyoung 
    703  1.1    dyoung 	if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
    704  1.1    dyoung 		/* Set or unset auto-negotiation 10G advertisement */
    705  1.1    dyoung 		hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
    706  1.3   msaitoh 				     IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    707  1.3   msaitoh 				     &autoneg_reg);
    708  1.1    dyoung 
    709  1.1    dyoung 		autoneg_reg &= ~IXGBE_MII_10GBASE_T_ADVERTISE;
    710  1.1    dyoung 		if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
    711  1.1    dyoung 			autoneg_reg |= IXGBE_MII_10GBASE_T_ADVERTISE;
    712  1.1    dyoung 
    713  1.1    dyoung 		hw->phy.ops.write_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
    714  1.3   msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    715  1.3   msaitoh 				      autoneg_reg);
    716  1.1    dyoung 	}
    717  1.1    dyoung 
    718  1.1    dyoung 	if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
    719  1.1    dyoung 		/* Set or unset auto-negotiation 1G advertisement */
    720  1.1    dyoung 		hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
    721  1.3   msaitoh 				     IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    722  1.3   msaitoh 				     &autoneg_reg);
    723  1.1    dyoung 
    724  1.1    dyoung 		autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
    725  1.1    dyoung 		if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
    726  1.1    dyoung 			autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
    727  1.1    dyoung 
    728  1.1    dyoung 		hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
    729  1.3   msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    730  1.3   msaitoh 				      autoneg_reg);
    731  1.1    dyoung 	}
    732  1.1    dyoung 
    733  1.1    dyoung 	if (speed & IXGBE_LINK_SPEED_100_FULL) {
    734  1.1    dyoung 		/* Set or unset auto-negotiation 100M advertisement */
    735  1.1    dyoung 		hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
    736  1.3   msaitoh 				     IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    737  1.3   msaitoh 				     &autoneg_reg);
    738  1.1    dyoung 
    739  1.1    dyoung 		autoneg_reg &= ~IXGBE_MII_100BASE_T_ADVERTISE;
    740  1.1    dyoung 		if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
    741  1.1    dyoung 			autoneg_reg |= IXGBE_MII_100BASE_T_ADVERTISE;
    742  1.1    dyoung 
    743  1.1    dyoung 		hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
    744  1.3   msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    745  1.3   msaitoh 				      autoneg_reg);
    746  1.1    dyoung 	}
    747  1.1    dyoung 
    748  1.1    dyoung 	/* Restart PHY autonegotiation and wait for completion */
    749  1.1    dyoung 	hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
    750  1.3   msaitoh 			     IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
    751  1.1    dyoung 
    752  1.1    dyoung 	autoneg_reg |= IXGBE_MII_RESTART;
    753  1.1    dyoung 
    754  1.1    dyoung 	hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
    755  1.3   msaitoh 			      IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
    756  1.1    dyoung 
    757  1.1    dyoung 	/* Wait for autonegotiation to finish */
    758  1.1    dyoung 	for (time_out = 0; time_out < max_time_out; time_out++) {
    759  1.1    dyoung 		usec_delay(10);
    760  1.1    dyoung 		/* Restart PHY autonegotiation and wait for completion */
    761  1.1    dyoung 		status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
    762  1.3   msaitoh 					      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    763  1.3   msaitoh 					      &autoneg_reg);
    764  1.1    dyoung 
    765  1.1    dyoung 		autoneg_reg &= IXGBE_MII_AUTONEG_COMPLETE;
    766  1.3   msaitoh 		if (autoneg_reg == IXGBE_MII_AUTONEG_COMPLETE)
    767  1.1    dyoung 			break;
    768  1.1    dyoung 	}
    769  1.1    dyoung 
    770  1.1    dyoung 	if (time_out == max_time_out) {
    771  1.1    dyoung 		status = IXGBE_ERR_LINK_SETUP;
    772  1.1    dyoung 		DEBUGOUT("ixgbe_setup_phy_link_tnx: time out");
    773  1.1    dyoung 	}
    774  1.1    dyoung 
    775  1.1    dyoung 	return status;
    776  1.1    dyoung }
    777  1.1    dyoung 
    778  1.1    dyoung /**
    779  1.1    dyoung  *  ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
    780  1.1    dyoung  *  @hw: pointer to hardware structure
    781  1.1    dyoung  *  @firmware_version: pointer to the PHY Firmware Version
    782  1.1    dyoung  **/
    783  1.1    dyoung s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
    784  1.3   msaitoh 				       u16 *firmware_version)
    785  1.1    dyoung {
    786  1.1    dyoung 	s32 status = IXGBE_SUCCESS;
    787  1.1    dyoung 
    788  1.1    dyoung 	DEBUGFUNC("ixgbe_get_phy_firmware_version_tnx");
    789  1.1    dyoung 
    790  1.1    dyoung 	status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
    791  1.3   msaitoh 				      IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
    792  1.3   msaitoh 				      firmware_version);
    793  1.1    dyoung 
    794  1.1    dyoung 	return status;
    795  1.1    dyoung }
    796  1.1    dyoung 
    797  1.1    dyoung /**
    798  1.1    dyoung  *  ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
    799  1.1    dyoung  *  @hw: pointer to hardware structure
    800  1.1    dyoung  *  @firmware_version: pointer to the PHY Firmware Version
    801  1.1    dyoung  **/
    802  1.1    dyoung s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
    803  1.3   msaitoh 					   u16 *firmware_version)
    804  1.1    dyoung {
    805  1.1    dyoung 	s32 status = IXGBE_SUCCESS;
    806  1.1    dyoung 
    807  1.1    dyoung 	DEBUGFUNC("ixgbe_get_phy_firmware_version_generic");
    808  1.1    dyoung 
    809  1.1    dyoung 	status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
    810  1.3   msaitoh 				      IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
    811  1.3   msaitoh 				      firmware_version);
    812  1.1    dyoung 
    813  1.1    dyoung 	return status;
    814  1.1    dyoung }
    815  1.1    dyoung 
    816  1.1    dyoung /**
    817  1.1    dyoung  *  ixgbe_reset_phy_nl - Performs a PHY reset
    818  1.1    dyoung  *  @hw: pointer to hardware structure
    819  1.1    dyoung  **/
    820  1.1    dyoung s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
    821  1.1    dyoung {
    822  1.1    dyoung 	u16 phy_offset, control, eword, edata, block_crc;
    823  1.1    dyoung 	bool end_data = FALSE;
    824  1.1    dyoung 	u16 list_offset, data_offset;
    825  1.1    dyoung 	u16 phy_data = 0;
    826  1.1    dyoung 	s32 ret_val = IXGBE_SUCCESS;
    827  1.1    dyoung 	u32 i;
    828  1.1    dyoung 
    829  1.1    dyoung 	DEBUGFUNC("ixgbe_reset_phy_nl");
    830  1.1    dyoung 
    831  1.1    dyoung 	hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
    832  1.3   msaitoh 			     IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
    833  1.1    dyoung 
    834  1.1    dyoung 	/* reset the PHY and poll for completion */
    835  1.1    dyoung 	hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
    836  1.3   msaitoh 			      IXGBE_MDIO_PHY_XS_DEV_TYPE,
    837  1.3   msaitoh 			      (phy_data | IXGBE_MDIO_PHY_XS_RESET));
    838  1.1    dyoung 
    839  1.1    dyoung 	for (i = 0; i < 100; i++) {
    840  1.1    dyoung 		hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
    841  1.3   msaitoh 				     IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
    842  1.1    dyoung 		if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) == 0)
    843  1.1    dyoung 			break;
    844  1.1    dyoung 		msec_delay(10);
    845  1.1    dyoung 	}
    846  1.1    dyoung 
    847  1.1    dyoung 	if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) != 0) {
    848  1.1    dyoung 		DEBUGOUT("PHY reset did not complete.\n");
    849  1.1    dyoung 		ret_val = IXGBE_ERR_PHY;
    850  1.1    dyoung 		goto out;
    851  1.1    dyoung 	}
    852  1.1    dyoung 
    853  1.1    dyoung 	/* Get init offsets */
    854  1.1    dyoung 	ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
    855  1.3   msaitoh 						      &data_offset);
    856  1.1    dyoung 	if (ret_val != IXGBE_SUCCESS)
    857  1.1    dyoung 		goto out;
    858  1.1    dyoung 
    859  1.1    dyoung 	ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
    860  1.1    dyoung 	data_offset++;
    861  1.1    dyoung 	while (!end_data) {
    862  1.1    dyoung 		/*
    863  1.1    dyoung 		 * Read control word from PHY init contents offset
    864  1.1    dyoung 		 */
    865  1.1    dyoung 		ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
    866  1.1    dyoung 		control = (eword & IXGBE_CONTROL_MASK_NL) >>
    867  1.3   msaitoh 			   IXGBE_CONTROL_SHIFT_NL;
    868  1.1    dyoung 		edata = eword & IXGBE_DATA_MASK_NL;
    869  1.1    dyoung 		switch (control) {
    870  1.1    dyoung 		case IXGBE_DELAY_NL:
    871  1.1    dyoung 			data_offset++;
    872  1.1    dyoung 			DEBUGOUT1("DELAY: %d MS\n", edata);
    873  1.1    dyoung 			msec_delay(edata);
    874  1.1    dyoung 			break;
    875  1.1    dyoung 		case IXGBE_DATA_NL:
    876  1.3   msaitoh 			DEBUGOUT("DATA:\n");
    877  1.1    dyoung 			data_offset++;
    878  1.1    dyoung 			hw->eeprom.ops.read(hw, data_offset++,
    879  1.3   msaitoh 					    &phy_offset);
    880  1.1    dyoung 			for (i = 0; i < edata; i++) {
    881  1.1    dyoung 				hw->eeprom.ops.read(hw, data_offset, &eword);
    882  1.1    dyoung 				hw->phy.ops.write_reg(hw, phy_offset,
    883  1.3   msaitoh 						      IXGBE_TWINAX_DEV, eword);
    884  1.1    dyoung 				DEBUGOUT2("Wrote %4.4x to %4.4x\n", eword,
    885  1.3   msaitoh 					  phy_offset);
    886  1.1    dyoung 				data_offset++;
    887  1.1    dyoung 				phy_offset++;
    888  1.1    dyoung 			}
    889  1.1    dyoung 			break;
    890  1.1    dyoung 		case IXGBE_CONTROL_NL:
    891  1.1    dyoung 			data_offset++;
    892  1.3   msaitoh 			DEBUGOUT("CONTROL:\n");
    893  1.1    dyoung 			if (edata == IXGBE_CONTROL_EOL_NL) {
    894  1.1    dyoung 				DEBUGOUT("EOL\n");
    895  1.1    dyoung 				end_data = TRUE;
    896  1.1    dyoung 			} else if (edata == IXGBE_CONTROL_SOL_NL) {
    897  1.1    dyoung 				DEBUGOUT("SOL\n");
    898  1.1    dyoung 			} else {
    899  1.1    dyoung 				DEBUGOUT("Bad control value\n");
    900  1.1    dyoung 				ret_val = IXGBE_ERR_PHY;
    901  1.1    dyoung 				goto out;
    902  1.1    dyoung 			}
    903  1.1    dyoung 			break;
    904  1.1    dyoung 		default:
    905  1.1    dyoung 			DEBUGOUT("Bad control type\n");
    906  1.1    dyoung 			ret_val = IXGBE_ERR_PHY;
    907  1.1    dyoung 			goto out;
    908  1.1    dyoung 		}
    909  1.1    dyoung 	}
    910  1.1    dyoung 
    911  1.1    dyoung out:
    912  1.1    dyoung 	return ret_val;
    913  1.1    dyoung }
    914  1.1    dyoung 
    915  1.1    dyoung /**
    916  1.3   msaitoh  *  ixgbe_identify_module_generic - Identifies module type
    917  1.3   msaitoh  *  @hw: pointer to hardware structure
    918  1.3   msaitoh  *
    919  1.3   msaitoh  *  Determines HW type and calls appropriate function.
    920  1.3   msaitoh  **/
    921  1.3   msaitoh s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
    922  1.3   msaitoh {
    923  1.3   msaitoh 	s32 status = IXGBE_ERR_SFP_NOT_PRESENT;
    924  1.3   msaitoh 
    925  1.3   msaitoh 	DEBUGFUNC("ixgbe_identify_module_generic");
    926  1.3   msaitoh 
    927  1.3   msaitoh 	switch (hw->mac.ops.get_media_type(hw)) {
    928  1.3   msaitoh 	case ixgbe_media_type_fiber:
    929  1.3   msaitoh 		status = ixgbe_identify_sfp_module_generic(hw);
    930  1.3   msaitoh 		break;
    931  1.3   msaitoh 
    932  1.3   msaitoh 
    933  1.3   msaitoh 	default:
    934  1.3   msaitoh 		hw->phy.sfp_type = ixgbe_sfp_type_not_present;
    935  1.3   msaitoh 		status = IXGBE_ERR_SFP_NOT_PRESENT;
    936  1.3   msaitoh 		break;
    937  1.3   msaitoh 	}
    938  1.3   msaitoh 
    939  1.3   msaitoh 	return status;
    940  1.3   msaitoh }
    941  1.3   msaitoh 
    942  1.3   msaitoh /**
    943  1.1    dyoung  *  ixgbe_identify_sfp_module_generic - Identifies SFP modules
    944  1.1    dyoung  *  @hw: pointer to hardware structure
    945  1.1    dyoung  *
    946  1.1    dyoung  *  Searches for and identifies the SFP module and assigns appropriate PHY type.
    947  1.1    dyoung  **/
    948  1.1    dyoung s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
    949  1.1    dyoung {
    950  1.1    dyoung 	s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
    951  1.1    dyoung 	u32 vendor_oui = 0;
    952  1.1    dyoung 	enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
    953  1.1    dyoung 	u8 identifier = 0;
    954  1.1    dyoung 	u8 comp_codes_1g = 0;
    955  1.1    dyoung 	u8 comp_codes_10g = 0;
    956  1.1    dyoung 	u8 oui_bytes[3] = {0, 0, 0};
    957  1.1    dyoung 	u8 cable_tech = 0;
    958  1.1    dyoung 	u8 cable_spec = 0;
    959  1.1    dyoung 	u16 enforce_sfp = 0;
    960  1.1    dyoung 
    961  1.1    dyoung 	DEBUGFUNC("ixgbe_identify_sfp_module_generic");
    962  1.1    dyoung 
    963  1.1    dyoung 	if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
    964  1.1    dyoung 		hw->phy.sfp_type = ixgbe_sfp_type_not_present;
    965  1.1    dyoung 		status = IXGBE_ERR_SFP_NOT_PRESENT;
    966  1.1    dyoung 		goto out;
    967  1.1    dyoung 	}
    968  1.1    dyoung 
    969  1.1    dyoung 	status = hw->phy.ops.read_i2c_eeprom(hw,
    970  1.3   msaitoh 					     IXGBE_SFF_IDENTIFIER,
    971  1.3   msaitoh 					     &identifier);
    972  1.1    dyoung 
    973  1.1    dyoung 	if (status == IXGBE_ERR_SWFW_SYNC ||
    974  1.1    dyoung 	    status == IXGBE_ERR_I2C ||
    975  1.1    dyoung 	    status == IXGBE_ERR_SFP_NOT_PRESENT)
    976  1.1    dyoung 		goto err_read_i2c_eeprom;
    977  1.1    dyoung 
    978  1.1    dyoung 	/* LAN ID is needed for sfp_type determination */
    979  1.1    dyoung 	hw->mac.ops.set_lan_id(hw);
    980  1.1    dyoung 
    981  1.1    dyoung 	if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
    982  1.1    dyoung 		hw->phy.type = ixgbe_phy_sfp_unsupported;
    983  1.1    dyoung 		status = IXGBE_ERR_SFP_NOT_SUPPORTED;
    984  1.1    dyoung 	} else {
    985  1.1    dyoung 		status = hw->phy.ops.read_i2c_eeprom(hw,
    986  1.3   msaitoh 						     IXGBE_SFF_1GBE_COMP_CODES,
    987  1.3   msaitoh 						     &comp_codes_1g);
    988  1.1    dyoung 
    989  1.1    dyoung 		if (status == IXGBE_ERR_SWFW_SYNC ||
    990  1.1    dyoung 		    status == IXGBE_ERR_I2C ||
    991  1.1    dyoung 		    status == IXGBE_ERR_SFP_NOT_PRESENT)
    992  1.1    dyoung 			goto err_read_i2c_eeprom;
    993  1.1    dyoung 
    994  1.1    dyoung 		status = hw->phy.ops.read_i2c_eeprom(hw,
    995  1.3   msaitoh 						     IXGBE_SFF_10GBE_COMP_CODES,
    996  1.3   msaitoh 						     &comp_codes_10g);
    997  1.1    dyoung 
    998  1.1    dyoung 		if (status == IXGBE_ERR_SWFW_SYNC ||
    999  1.1    dyoung 		    status == IXGBE_ERR_I2C ||
   1000  1.1    dyoung 		    status == IXGBE_ERR_SFP_NOT_PRESENT)
   1001  1.1    dyoung 			goto err_read_i2c_eeprom;
   1002  1.1    dyoung 		status = hw->phy.ops.read_i2c_eeprom(hw,
   1003  1.3   msaitoh 						     IXGBE_SFF_CABLE_TECHNOLOGY,
   1004  1.3   msaitoh 						     &cable_tech);
   1005  1.1    dyoung 
   1006  1.1    dyoung 		if (status == IXGBE_ERR_SWFW_SYNC ||
   1007  1.1    dyoung 		    status == IXGBE_ERR_I2C ||
   1008  1.1    dyoung 		    status == IXGBE_ERR_SFP_NOT_PRESENT)
   1009  1.1    dyoung 			goto err_read_i2c_eeprom;
   1010  1.1    dyoung 
   1011  1.1    dyoung 		 /* ID Module
   1012  1.1    dyoung 		  * =========
   1013  1.1    dyoung 		  * 0   SFP_DA_CU
   1014  1.1    dyoung 		  * 1   SFP_SR
   1015  1.1    dyoung 		  * 2   SFP_LR
   1016  1.1    dyoung 		  * 3   SFP_DA_CORE0 - 82599-specific
   1017  1.1    dyoung 		  * 4   SFP_DA_CORE1 - 82599-specific
   1018  1.1    dyoung 		  * 5   SFP_SR/LR_CORE0 - 82599-specific
   1019  1.1    dyoung 		  * 6   SFP_SR/LR_CORE1 - 82599-specific
   1020  1.1    dyoung 		  * 7   SFP_act_lmt_DA_CORE0 - 82599-specific
   1021  1.1    dyoung 		  * 8   SFP_act_lmt_DA_CORE1 - 82599-specific
   1022  1.1    dyoung 		  * 9   SFP_1g_cu_CORE0 - 82599-specific
   1023  1.1    dyoung 		  * 10  SFP_1g_cu_CORE1 - 82599-specific
   1024  1.4   msaitoh 		  * 11  SFP_1g_sx_CORE0 - 82599-specific
   1025  1.4   msaitoh 		  * 12  SFP_1g_sx_CORE1 - 82599-specific
   1026  1.1    dyoung 		  */
   1027  1.1    dyoung 		if (hw->mac.type == ixgbe_mac_82598EB) {
   1028  1.1    dyoung 			if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
   1029  1.1    dyoung 				hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
   1030  1.1    dyoung 			else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
   1031  1.1    dyoung 				hw->phy.sfp_type = ixgbe_sfp_type_sr;
   1032  1.1    dyoung 			else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
   1033  1.1    dyoung 				hw->phy.sfp_type = ixgbe_sfp_type_lr;
   1034  1.1    dyoung 			else
   1035  1.1    dyoung 				hw->phy.sfp_type = ixgbe_sfp_type_unknown;
   1036  1.1    dyoung 		} else if (hw->mac.type == ixgbe_mac_82599EB) {
   1037  1.1    dyoung 			if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
   1038  1.1    dyoung 				if (hw->bus.lan_id == 0)
   1039  1.1    dyoung 					hw->phy.sfp_type =
   1040  1.3   msaitoh 						     ixgbe_sfp_type_da_cu_core0;
   1041  1.1    dyoung 				else
   1042  1.1    dyoung 					hw->phy.sfp_type =
   1043  1.3   msaitoh 						     ixgbe_sfp_type_da_cu_core1;
   1044  1.1    dyoung 			} else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
   1045  1.1    dyoung 				hw->phy.ops.read_i2c_eeprom(
   1046  1.1    dyoung 						hw, IXGBE_SFF_CABLE_SPEC_COMP,
   1047  1.1    dyoung 						&cable_spec);
   1048  1.1    dyoung 				if (cable_spec &
   1049  1.1    dyoung 				    IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
   1050  1.1    dyoung 					if (hw->bus.lan_id == 0)
   1051  1.1    dyoung 						hw->phy.sfp_type =
   1052  1.1    dyoung 						ixgbe_sfp_type_da_act_lmt_core0;
   1053  1.1    dyoung 					else
   1054  1.1    dyoung 						hw->phy.sfp_type =
   1055  1.1    dyoung 						ixgbe_sfp_type_da_act_lmt_core1;
   1056  1.1    dyoung 				} else {
   1057  1.1    dyoung 					hw->phy.sfp_type =
   1058  1.3   msaitoh 							ixgbe_sfp_type_unknown;
   1059  1.1    dyoung 				}
   1060  1.1    dyoung 			} else if (comp_codes_10g &
   1061  1.1    dyoung 				   (IXGBE_SFF_10GBASESR_CAPABLE |
   1062  1.1    dyoung 				    IXGBE_SFF_10GBASELR_CAPABLE)) {
   1063  1.1    dyoung 				if (hw->bus.lan_id == 0)
   1064  1.1    dyoung 					hw->phy.sfp_type =
   1065  1.3   msaitoh 						      ixgbe_sfp_type_srlr_core0;
   1066  1.1    dyoung 				else
   1067  1.1    dyoung 					hw->phy.sfp_type =
   1068  1.3   msaitoh 						      ixgbe_sfp_type_srlr_core1;
   1069  1.1    dyoung 			} else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
   1070  1.1    dyoung 				if (hw->bus.lan_id == 0)
   1071  1.1    dyoung 					hw->phy.sfp_type =
   1072  1.1    dyoung 						ixgbe_sfp_type_1g_cu_core0;
   1073  1.1    dyoung 				else
   1074  1.1    dyoung 					hw->phy.sfp_type =
   1075  1.1    dyoung 						ixgbe_sfp_type_1g_cu_core1;
   1076  1.4   msaitoh 			} else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
   1077  1.4   msaitoh 				if (hw->bus.lan_id == 0)
   1078  1.4   msaitoh 					hw->phy.sfp_type =
   1079  1.4   msaitoh 						ixgbe_sfp_type_1g_sx_core0;
   1080  1.4   msaitoh 				else
   1081  1.4   msaitoh 					hw->phy.sfp_type =
   1082  1.4   msaitoh 						ixgbe_sfp_type_1g_sx_core1;
   1083  1.1    dyoung 			} else {
   1084  1.1    dyoung 				hw->phy.sfp_type = ixgbe_sfp_type_unknown;
   1085  1.1    dyoung 			}
   1086  1.1    dyoung 		}
   1087  1.1    dyoung 
   1088  1.1    dyoung 		if (hw->phy.sfp_type != stored_sfp_type)
   1089  1.1    dyoung 			hw->phy.sfp_setup_needed = TRUE;
   1090  1.1    dyoung 
   1091  1.1    dyoung 		/* Determine if the SFP+ PHY is dual speed or not. */
   1092  1.1    dyoung 		hw->phy.multispeed_fiber = FALSE;
   1093  1.1    dyoung 		if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
   1094  1.1    dyoung 		   (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
   1095  1.1    dyoung 		   ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
   1096  1.1    dyoung 		   (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
   1097  1.1    dyoung 			hw->phy.multispeed_fiber = TRUE;
   1098  1.1    dyoung 
   1099  1.1    dyoung 		/* Determine PHY vendor */
   1100  1.1    dyoung 		if (hw->phy.type != ixgbe_phy_nl) {
   1101  1.1    dyoung 			hw->phy.id = identifier;
   1102  1.1    dyoung 			status = hw->phy.ops.read_i2c_eeprom(hw,
   1103  1.3   msaitoh 						    IXGBE_SFF_VENDOR_OUI_BYTE0,
   1104  1.3   msaitoh 						    &oui_bytes[0]);
   1105  1.1    dyoung 
   1106  1.1    dyoung 			if (status == IXGBE_ERR_SWFW_SYNC ||
   1107  1.1    dyoung 			    status == IXGBE_ERR_I2C ||
   1108  1.1    dyoung 			    status == IXGBE_ERR_SFP_NOT_PRESENT)
   1109  1.1    dyoung 				goto err_read_i2c_eeprom;
   1110  1.1    dyoung 
   1111  1.1    dyoung 			status = hw->phy.ops.read_i2c_eeprom(hw,
   1112  1.3   msaitoh 						    IXGBE_SFF_VENDOR_OUI_BYTE1,
   1113  1.3   msaitoh 						    &oui_bytes[1]);
   1114  1.1    dyoung 
   1115  1.1    dyoung 			if (status == IXGBE_ERR_SWFW_SYNC ||
   1116  1.1    dyoung 			    status == IXGBE_ERR_I2C ||
   1117  1.1    dyoung 			    status == IXGBE_ERR_SFP_NOT_PRESENT)
   1118  1.1    dyoung 				goto err_read_i2c_eeprom;
   1119  1.1    dyoung 
   1120  1.1    dyoung 			status = hw->phy.ops.read_i2c_eeprom(hw,
   1121  1.3   msaitoh 						    IXGBE_SFF_VENDOR_OUI_BYTE2,
   1122  1.3   msaitoh 						    &oui_bytes[2]);
   1123  1.1    dyoung 
   1124  1.1    dyoung 			if (status == IXGBE_ERR_SWFW_SYNC ||
   1125  1.1    dyoung 			    status == IXGBE_ERR_I2C ||
   1126  1.1    dyoung 			    status == IXGBE_ERR_SFP_NOT_PRESENT)
   1127  1.1    dyoung 				goto err_read_i2c_eeprom;
   1128  1.1    dyoung 
   1129  1.1    dyoung 			vendor_oui =
   1130  1.1    dyoung 			  ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
   1131  1.1    dyoung 			   (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
   1132  1.1    dyoung 			   (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
   1133  1.1    dyoung 
   1134  1.1    dyoung 			switch (vendor_oui) {
   1135  1.1    dyoung 			case IXGBE_SFF_VENDOR_OUI_TYCO:
   1136  1.1    dyoung 				if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
   1137  1.1    dyoung 					hw->phy.type =
   1138  1.3   msaitoh 						    ixgbe_phy_sfp_passive_tyco;
   1139  1.1    dyoung 				break;
   1140  1.1    dyoung 			case IXGBE_SFF_VENDOR_OUI_FTL:
   1141  1.1    dyoung 				if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
   1142  1.1    dyoung 					hw->phy.type = ixgbe_phy_sfp_ftl_active;
   1143  1.1    dyoung 				else
   1144  1.1    dyoung 					hw->phy.type = ixgbe_phy_sfp_ftl;
   1145  1.1    dyoung 				break;
   1146  1.1    dyoung 			case IXGBE_SFF_VENDOR_OUI_AVAGO:
   1147  1.1    dyoung 				hw->phy.type = ixgbe_phy_sfp_avago;
   1148  1.1    dyoung 				break;
   1149  1.1    dyoung 			case IXGBE_SFF_VENDOR_OUI_INTEL:
   1150  1.1    dyoung 				hw->phy.type = ixgbe_phy_sfp_intel;
   1151  1.1    dyoung 				break;
   1152  1.1    dyoung 			default:
   1153  1.1    dyoung 				if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
   1154  1.1    dyoung 					hw->phy.type =
   1155  1.3   msaitoh 						 ixgbe_phy_sfp_passive_unknown;
   1156  1.1    dyoung 				else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
   1157  1.1    dyoung 					hw->phy.type =
   1158  1.1    dyoung 						ixgbe_phy_sfp_active_unknown;
   1159  1.1    dyoung 				else
   1160  1.1    dyoung 					hw->phy.type = ixgbe_phy_sfp_unknown;
   1161  1.1    dyoung 				break;
   1162  1.1    dyoung 			}
   1163  1.1    dyoung 		}
   1164  1.1    dyoung 
   1165  1.1    dyoung 		/* Allow any DA cable vendor */
   1166  1.1    dyoung 		if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
   1167  1.1    dyoung 		    IXGBE_SFF_DA_ACTIVE_CABLE)) {
   1168  1.1    dyoung 			status = IXGBE_SUCCESS;
   1169  1.1    dyoung 			goto out;
   1170  1.1    dyoung 		}
   1171  1.1    dyoung 
   1172  1.1    dyoung 		/* Verify supported 1G SFP modules */
   1173  1.1    dyoung 		if (comp_codes_10g == 0 &&
   1174  1.1    dyoung 		    !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
   1175  1.4   msaitoh 		      hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
   1176  1.4   msaitoh 		      hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0  ||
   1177  1.4   msaitoh 		      hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
   1178  1.1    dyoung 			hw->phy.type = ixgbe_phy_sfp_unsupported;
   1179  1.1    dyoung 			status = IXGBE_ERR_SFP_NOT_SUPPORTED;
   1180  1.1    dyoung 			goto out;
   1181  1.1    dyoung 		}
   1182  1.1    dyoung 
   1183  1.1    dyoung 		/* Anything else 82598-based is supported */
   1184  1.1    dyoung 		if (hw->mac.type == ixgbe_mac_82598EB) {
   1185  1.1    dyoung 			status = IXGBE_SUCCESS;
   1186  1.1    dyoung 			goto out;
   1187  1.1    dyoung 		}
   1188  1.1    dyoung 
   1189  1.1    dyoung 		ixgbe_get_device_caps(hw, &enforce_sfp);
   1190  1.1    dyoung 		if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
   1191  1.1    dyoung 		    !((hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0) ||
   1192  1.4   msaitoh 		      (hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1) ||
   1193  1.4   msaitoh 		      (hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0)  ||
   1194  1.4   msaitoh 		      (hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1))) {
   1195  1.1    dyoung 			/* Make sure we're a supported PHY type */
   1196  1.1    dyoung 			if (hw->phy.type == ixgbe_phy_sfp_intel) {
   1197  1.1    dyoung 				status = IXGBE_SUCCESS;
   1198  1.1    dyoung 			} else {
   1199  1.4   msaitoh 				if (hw->allow_unsupported_sfp == TRUE) {
   1200  1.4   msaitoh 					EWARN(hw, "WARNING: Intel (R) Network "
   1201  1.4   msaitoh 					      "Connections are quality tested "
   1202  1.4   msaitoh 					      "using Intel (R) Ethernet Optics."
   1203  1.4   msaitoh 					      " Using untested modules is not "
   1204  1.4   msaitoh 					      "supported and may cause unstable"
   1205  1.4   msaitoh 					      " operation or damage to the "
   1206  1.4   msaitoh 					      "module or the adapter. Intel "
   1207  1.4   msaitoh 					      "Corporation is not responsible "
   1208  1.4   msaitoh 					      "for any harm caused by using "
   1209  1.4   msaitoh 					      "untested modules.\n", status);
   1210  1.4   msaitoh 					status = IXGBE_SUCCESS;
   1211  1.4   msaitoh 				} else {
   1212  1.4   msaitoh 					DEBUGOUT("SFP+ module not supported\n");
   1213  1.4   msaitoh 					hw->phy.type =
   1214  1.4   msaitoh 						ixgbe_phy_sfp_unsupported;
   1215  1.4   msaitoh 					status = IXGBE_ERR_SFP_NOT_SUPPORTED;
   1216  1.4   msaitoh 				}
   1217  1.1    dyoung 			}
   1218  1.1    dyoung 		} else {
   1219  1.1    dyoung 			status = IXGBE_SUCCESS;
   1220  1.1    dyoung 		}
   1221  1.1    dyoung 	}
   1222  1.1    dyoung 
   1223  1.1    dyoung out:
   1224  1.1    dyoung 	return status;
   1225  1.1    dyoung 
   1226  1.1    dyoung err_read_i2c_eeprom:
   1227  1.1    dyoung 	hw->phy.sfp_type = ixgbe_sfp_type_not_present;
   1228  1.1    dyoung 	if (hw->phy.type != ixgbe_phy_nl) {
   1229  1.1    dyoung 		hw->phy.id = 0;
   1230  1.1    dyoung 		hw->phy.type = ixgbe_phy_unknown;
   1231  1.1    dyoung 	}
   1232  1.1    dyoung 	return IXGBE_ERR_SFP_NOT_PRESENT;
   1233  1.1    dyoung }
   1234  1.1    dyoung 
   1235  1.3   msaitoh 
   1236  1.3   msaitoh 
   1237  1.1    dyoung /**
   1238  1.1    dyoung  *  ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
   1239  1.1    dyoung  *  @hw: pointer to hardware structure
   1240  1.1    dyoung  *  @list_offset: offset to the SFP ID list
   1241  1.1    dyoung  *  @data_offset: offset to the SFP data block
   1242  1.1    dyoung  *
   1243  1.1    dyoung  *  Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
   1244  1.1    dyoung  *  so it returns the offsets to the phy init sequence block.
   1245  1.1    dyoung  **/
   1246  1.1    dyoung s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
   1247  1.3   msaitoh 					u16 *list_offset,
   1248  1.3   msaitoh 					u16 *data_offset)
   1249  1.1    dyoung {
   1250  1.1    dyoung 	u16 sfp_id;
   1251  1.1    dyoung 	u16 sfp_type = hw->phy.sfp_type;
   1252  1.1    dyoung 
   1253  1.1    dyoung 	DEBUGFUNC("ixgbe_get_sfp_init_sequence_offsets");
   1254  1.1    dyoung 
   1255  1.1    dyoung 	if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
   1256  1.1    dyoung 		return IXGBE_ERR_SFP_NOT_SUPPORTED;
   1257  1.1    dyoung 
   1258  1.1    dyoung 	if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
   1259  1.1    dyoung 		return IXGBE_ERR_SFP_NOT_PRESENT;
   1260  1.1    dyoung 
   1261  1.1    dyoung 	if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
   1262  1.1    dyoung 	    (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
   1263  1.1    dyoung 		return IXGBE_ERR_SFP_NOT_SUPPORTED;
   1264  1.1    dyoung 
   1265  1.1    dyoung 	/*
   1266  1.1    dyoung 	 * Limiting active cables and 1G Phys must be initialized as
   1267  1.1    dyoung 	 * SR modules
   1268  1.1    dyoung 	 */
   1269  1.1    dyoung 	if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
   1270  1.4   msaitoh 	    sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
   1271  1.4   msaitoh 	    sfp_type == ixgbe_sfp_type_1g_sx_core0)
   1272  1.1    dyoung 		sfp_type = ixgbe_sfp_type_srlr_core0;
   1273  1.1    dyoung 	else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
   1274  1.4   msaitoh 		 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
   1275  1.4   msaitoh 		 sfp_type == ixgbe_sfp_type_1g_sx_core1)
   1276  1.1    dyoung 		sfp_type = ixgbe_sfp_type_srlr_core1;
   1277  1.1    dyoung 
   1278  1.1    dyoung 	/* Read offset to PHY init contents */
   1279  1.1    dyoung 	hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset);
   1280  1.1    dyoung 
   1281  1.1    dyoung 	if ((!*list_offset) || (*list_offset == 0xFFFF))
   1282  1.1    dyoung 		return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
   1283  1.1    dyoung 
   1284  1.1    dyoung 	/* Shift offset to first ID word */
   1285  1.1    dyoung 	(*list_offset)++;
   1286  1.1    dyoung 
   1287  1.1    dyoung 	/*
   1288  1.1    dyoung 	 * Find the matching SFP ID in the EEPROM
   1289  1.1    dyoung 	 * and program the init sequence
   1290  1.1    dyoung 	 */
   1291  1.1    dyoung 	hw->eeprom.ops.read(hw, *list_offset, &sfp_id);
   1292  1.1    dyoung 
   1293  1.1    dyoung 	while (sfp_id != IXGBE_PHY_INIT_END_NL) {
   1294  1.1    dyoung 		if (sfp_id == sfp_type) {
   1295  1.1    dyoung 			(*list_offset)++;
   1296  1.1    dyoung 			hw->eeprom.ops.read(hw, *list_offset, data_offset);
   1297  1.1    dyoung 			if ((!*data_offset) || (*data_offset == 0xFFFF)) {
   1298  1.1    dyoung 				DEBUGOUT("SFP+ module not supported\n");
   1299  1.1    dyoung 				return IXGBE_ERR_SFP_NOT_SUPPORTED;
   1300  1.1    dyoung 			} else {
   1301  1.1    dyoung 				break;
   1302  1.1    dyoung 			}
   1303  1.1    dyoung 		} else {
   1304  1.1    dyoung 			(*list_offset) += 2;
   1305  1.1    dyoung 			if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
   1306  1.1    dyoung 				return IXGBE_ERR_PHY;
   1307  1.1    dyoung 		}
   1308  1.1    dyoung 	}
   1309  1.1    dyoung 
   1310  1.1    dyoung 	if (sfp_id == IXGBE_PHY_INIT_END_NL) {
   1311  1.1    dyoung 		DEBUGOUT("No matching SFP+ module found\n");
   1312  1.1    dyoung 		return IXGBE_ERR_SFP_NOT_SUPPORTED;
   1313  1.1    dyoung 	}
   1314  1.1    dyoung 
   1315  1.1    dyoung 	return IXGBE_SUCCESS;
   1316  1.1    dyoung }
   1317  1.1    dyoung 
   1318  1.1    dyoung /**
   1319  1.1    dyoung  *  ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
   1320  1.1    dyoung  *  @hw: pointer to hardware structure
   1321  1.1    dyoung  *  @byte_offset: EEPROM byte offset to read
   1322  1.1    dyoung  *  @eeprom_data: value read
   1323  1.1    dyoung  *
   1324  1.1    dyoung  *  Performs byte read operation to SFP module's EEPROM over I2C interface.
   1325  1.1    dyoung  **/
   1326  1.1    dyoung s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
   1327  1.3   msaitoh 				  u8 *eeprom_data)
   1328  1.1    dyoung {
   1329  1.1    dyoung 	DEBUGFUNC("ixgbe_read_i2c_eeprom_generic");
   1330  1.1    dyoung 
   1331  1.1    dyoung 	return hw->phy.ops.read_i2c_byte(hw, byte_offset,
   1332  1.3   msaitoh 					 IXGBE_I2C_EEPROM_DEV_ADDR,
   1333  1.3   msaitoh 					 eeprom_data);
   1334  1.1    dyoung }
   1335  1.1    dyoung 
   1336  1.1    dyoung /**
   1337  1.1    dyoung  *  ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
   1338  1.1    dyoung  *  @hw: pointer to hardware structure
   1339  1.1    dyoung  *  @byte_offset: EEPROM byte offset to write
   1340  1.1    dyoung  *  @eeprom_data: value to write
   1341  1.1    dyoung  *
   1342  1.1    dyoung  *  Performs byte write operation to SFP module's EEPROM over I2C interface.
   1343  1.1    dyoung  **/
   1344  1.1    dyoung s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
   1345  1.3   msaitoh 				   u8 eeprom_data)
   1346  1.1    dyoung {
   1347  1.1    dyoung 	DEBUGFUNC("ixgbe_write_i2c_eeprom_generic");
   1348  1.1    dyoung 
   1349  1.1    dyoung 	return hw->phy.ops.write_i2c_byte(hw, byte_offset,
   1350  1.3   msaitoh 					  IXGBE_I2C_EEPROM_DEV_ADDR,
   1351  1.3   msaitoh 					  eeprom_data);
   1352  1.1    dyoung }
   1353  1.1    dyoung 
   1354  1.1    dyoung /**
   1355  1.1    dyoung  *  ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
   1356  1.1    dyoung  *  @hw: pointer to hardware structure
   1357  1.1    dyoung  *  @byte_offset: byte offset to read
   1358  1.1    dyoung  *  @data: value read
   1359  1.1    dyoung  *
   1360  1.1    dyoung  *  Performs byte read operation to SFP module's EEPROM over I2C interface at
   1361  1.3   msaitoh  *  a specified device address.
   1362  1.1    dyoung  **/
   1363  1.1    dyoung s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
   1364  1.3   msaitoh 				u8 dev_addr, u8 *data)
   1365  1.1    dyoung {
   1366  1.1    dyoung 	s32 status = IXGBE_SUCCESS;
   1367  1.1    dyoung 	u32 max_retry = 10;
   1368  1.1    dyoung 	u32 retry = 0;
   1369  1.1    dyoung 	u16 swfw_mask = 0;
   1370  1.1    dyoung 	bool nack = 1;
   1371  1.3   msaitoh 	*data = 0;
   1372  1.1    dyoung 
   1373  1.1    dyoung 	DEBUGFUNC("ixgbe_read_i2c_byte_generic");
   1374  1.1    dyoung 
   1375  1.1    dyoung 	if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
   1376  1.1    dyoung 		swfw_mask = IXGBE_GSSR_PHY1_SM;
   1377  1.1    dyoung 	else
   1378  1.1    dyoung 		swfw_mask = IXGBE_GSSR_PHY0_SM;
   1379  1.1    dyoung 
   1380  1.1    dyoung 	do {
   1381  1.3   msaitoh 		if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask)
   1382  1.3   msaitoh 		    != IXGBE_SUCCESS) {
   1383  1.1    dyoung 			status = IXGBE_ERR_SWFW_SYNC;
   1384  1.1    dyoung 			goto read_byte_out;
   1385  1.1    dyoung 		}
   1386  1.1    dyoung 
   1387  1.1    dyoung 		ixgbe_i2c_start(hw);
   1388  1.1    dyoung 
   1389  1.1    dyoung 		/* Device Address and write indication */
   1390  1.1    dyoung 		status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
   1391  1.1    dyoung 		if (status != IXGBE_SUCCESS)
   1392  1.1    dyoung 			goto fail;
   1393  1.1    dyoung 
   1394  1.1    dyoung 		status = ixgbe_get_i2c_ack(hw);
   1395  1.1    dyoung 		if (status != IXGBE_SUCCESS)
   1396  1.1    dyoung 			goto fail;
   1397  1.1    dyoung 
   1398  1.1    dyoung 		status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
   1399  1.1    dyoung 		if (status != IXGBE_SUCCESS)
   1400  1.1    dyoung 			goto fail;
   1401  1.1    dyoung 
   1402  1.1    dyoung 		status = ixgbe_get_i2c_ack(hw);
   1403  1.1    dyoung 		if (status != IXGBE_SUCCESS)
   1404  1.1    dyoung 			goto fail;
   1405  1.1    dyoung 
   1406  1.1    dyoung 		ixgbe_i2c_start(hw);
   1407  1.1    dyoung 
   1408  1.1    dyoung 		/* Device Address and read indication */
   1409  1.1    dyoung 		status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
   1410  1.1    dyoung 		if (status != IXGBE_SUCCESS)
   1411  1.1    dyoung 			goto fail;
   1412  1.1    dyoung 
   1413  1.1    dyoung 		status = ixgbe_get_i2c_ack(hw);
   1414  1.1    dyoung 		if (status != IXGBE_SUCCESS)
   1415  1.1    dyoung 			goto fail;
   1416  1.1    dyoung 
   1417  1.1    dyoung 		status = ixgbe_clock_in_i2c_byte(hw, data);
   1418  1.1    dyoung 		if (status != IXGBE_SUCCESS)
   1419  1.1    dyoung 			goto fail;
   1420  1.1    dyoung 
   1421  1.1    dyoung 		status = ixgbe_clock_out_i2c_bit(hw, nack);
   1422  1.1    dyoung 		if (status != IXGBE_SUCCESS)
   1423  1.1    dyoung 			goto fail;
   1424  1.1    dyoung 
   1425  1.1    dyoung 		ixgbe_i2c_stop(hw);
   1426  1.1    dyoung 		break;
   1427  1.1    dyoung 
   1428  1.1    dyoung fail:
   1429  1.3   msaitoh 		hw->mac.ops.release_swfw_sync(hw, swfw_mask);
   1430  1.1    dyoung 		msec_delay(100);
   1431  1.1    dyoung 		ixgbe_i2c_bus_clear(hw);
   1432  1.1    dyoung 		retry++;
   1433  1.1    dyoung 		if (retry < max_retry)
   1434  1.1    dyoung 			DEBUGOUT("I2C byte read error - Retrying.\n");
   1435  1.1    dyoung 		else
   1436  1.1    dyoung 			DEBUGOUT("I2C byte read error.\n");
   1437  1.1    dyoung 
   1438  1.1    dyoung 	} while (retry < max_retry);
   1439  1.1    dyoung 
   1440  1.3   msaitoh 	hw->mac.ops.release_swfw_sync(hw, swfw_mask);
   1441  1.1    dyoung 
   1442  1.1    dyoung read_byte_out:
   1443  1.1    dyoung 	return status;
   1444  1.1    dyoung }
   1445  1.1    dyoung 
   1446  1.1    dyoung /**
   1447  1.1    dyoung  *  ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
   1448  1.1    dyoung  *  @hw: pointer to hardware structure
   1449  1.1    dyoung  *  @byte_offset: byte offset to write
   1450  1.1    dyoung  *  @data: value to write
   1451  1.1    dyoung  *
   1452  1.1    dyoung  *  Performs byte write operation to SFP module's EEPROM over I2C interface at
   1453  1.1    dyoung  *  a specified device address.
   1454  1.1    dyoung  **/
   1455  1.1    dyoung s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
   1456  1.3   msaitoh 				 u8 dev_addr, u8 data)
   1457  1.1    dyoung {
   1458  1.1    dyoung 	s32 status = IXGBE_SUCCESS;
   1459  1.2  christos 	u32 max_retry = 2;
   1460  1.1    dyoung 	u32 retry = 0;
   1461  1.1    dyoung 	u16 swfw_mask = 0;
   1462  1.1    dyoung 
   1463  1.1    dyoung 	DEBUGFUNC("ixgbe_write_i2c_byte_generic");
   1464  1.1    dyoung 
   1465  1.1    dyoung 	if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
   1466  1.1    dyoung 		swfw_mask = IXGBE_GSSR_PHY1_SM;
   1467  1.1    dyoung 	else
   1468  1.1    dyoung 		swfw_mask = IXGBE_GSSR_PHY0_SM;
   1469  1.1    dyoung 
   1470  1.3   msaitoh 	if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != IXGBE_SUCCESS) {
   1471  1.1    dyoung 		status = IXGBE_ERR_SWFW_SYNC;
   1472  1.1    dyoung 		goto write_byte_out;
   1473  1.1    dyoung 	}
   1474  1.1    dyoung 
   1475  1.1    dyoung 	do {
   1476  1.1    dyoung 		ixgbe_i2c_start(hw);
   1477  1.1    dyoung 
   1478  1.1    dyoung 		status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
   1479  1.1    dyoung 		if (status != IXGBE_SUCCESS)
   1480  1.1    dyoung 			goto fail;
   1481  1.1    dyoung 
   1482  1.1    dyoung 		status = ixgbe_get_i2c_ack(hw);
   1483  1.1    dyoung 		if (status != IXGBE_SUCCESS)
   1484  1.1    dyoung 			goto fail;
   1485  1.1    dyoung 
   1486  1.1    dyoung 		status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
   1487  1.1    dyoung 		if (status != IXGBE_SUCCESS)
   1488  1.1    dyoung 			goto fail;
   1489  1.1    dyoung 
   1490  1.1    dyoung 		status = ixgbe_get_i2c_ack(hw);
   1491  1.1    dyoung 		if (status != IXGBE_SUCCESS)
   1492  1.1    dyoung 			goto fail;
   1493  1.1    dyoung 
   1494  1.1    dyoung 		status = ixgbe_clock_out_i2c_byte(hw, data);
   1495  1.1    dyoung 		if (status != IXGBE_SUCCESS)
   1496  1.1    dyoung 			goto fail;
   1497  1.1    dyoung 
   1498  1.1    dyoung 		status = ixgbe_get_i2c_ack(hw);
   1499  1.1    dyoung 		if (status != IXGBE_SUCCESS)
   1500  1.1    dyoung 			goto fail;
   1501  1.1    dyoung 
   1502  1.1    dyoung 		ixgbe_i2c_stop(hw);
   1503  1.1    dyoung 		break;
   1504  1.1    dyoung 
   1505  1.1    dyoung fail:
   1506  1.1    dyoung 		ixgbe_i2c_bus_clear(hw);
   1507  1.1    dyoung 		retry++;
   1508  1.1    dyoung 		if (retry < max_retry)
   1509  1.1    dyoung 			DEBUGOUT("I2C byte write error - Retrying.\n");
   1510  1.1    dyoung 		else
   1511  1.1    dyoung 			DEBUGOUT("I2C byte write error.\n");
   1512  1.1    dyoung 	} while (retry < max_retry);
   1513  1.1    dyoung 
   1514  1.3   msaitoh 	hw->mac.ops.release_swfw_sync(hw, swfw_mask);
   1515  1.1    dyoung 
   1516  1.1    dyoung write_byte_out:
   1517  1.1    dyoung 	return status;
   1518  1.1    dyoung }
   1519  1.1    dyoung 
   1520  1.1    dyoung /**
   1521  1.1    dyoung  *  ixgbe_i2c_start - Sets I2C start condition
   1522  1.1    dyoung  *  @hw: pointer to hardware structure
   1523  1.1    dyoung  *
   1524  1.1    dyoung  *  Sets I2C start condition (High -> Low on SDA while SCL is High)
   1525  1.1    dyoung  **/
   1526  1.1    dyoung static void ixgbe_i2c_start(struct ixgbe_hw *hw)
   1527  1.1    dyoung {
   1528  1.1    dyoung 	u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
   1529  1.1    dyoung 
   1530  1.1    dyoung 	DEBUGFUNC("ixgbe_i2c_start");
   1531  1.1    dyoung 
   1532  1.1    dyoung 	/* Start condition must begin with data and clock high */
   1533  1.1    dyoung 	ixgbe_set_i2c_data(hw, &i2cctl, 1);
   1534  1.1    dyoung 	ixgbe_raise_i2c_clk(hw, &i2cctl);
   1535  1.1    dyoung 
   1536  1.1    dyoung 	/* Setup time for start condition (4.7us) */
   1537  1.1    dyoung 	usec_delay(IXGBE_I2C_T_SU_STA);
   1538  1.1    dyoung 
   1539  1.1    dyoung 	ixgbe_set_i2c_data(hw, &i2cctl, 0);
   1540  1.1    dyoung 
   1541  1.1    dyoung 	/* Hold time for start condition (4us) */
   1542  1.1    dyoung 	usec_delay(IXGBE_I2C_T_HD_STA);
   1543  1.1    dyoung 
   1544  1.1    dyoung 	ixgbe_lower_i2c_clk(hw, &i2cctl);
   1545  1.1    dyoung 
   1546  1.1    dyoung 	/* Minimum low period of clock is 4.7 us */
   1547  1.1    dyoung 	usec_delay(IXGBE_I2C_T_LOW);
   1548  1.1    dyoung 
   1549  1.1    dyoung }
   1550  1.1    dyoung 
   1551  1.1    dyoung /**
   1552  1.1    dyoung  *  ixgbe_i2c_stop - Sets I2C stop condition
   1553  1.1    dyoung  *  @hw: pointer to hardware structure
   1554  1.1    dyoung  *
   1555  1.1    dyoung  *  Sets I2C stop condition (Low -> High on SDA while SCL is High)
   1556  1.1    dyoung  **/
   1557  1.1    dyoung static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
   1558  1.1    dyoung {
   1559  1.1    dyoung 	u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
   1560  1.1    dyoung 
   1561  1.1    dyoung 	DEBUGFUNC("ixgbe_i2c_stop");
   1562  1.1    dyoung 
   1563  1.1    dyoung 	/* Stop condition must begin with data low and clock high */
   1564  1.1    dyoung 	ixgbe_set_i2c_data(hw, &i2cctl, 0);
   1565  1.1    dyoung 	ixgbe_raise_i2c_clk(hw, &i2cctl);
   1566  1.1    dyoung 
   1567  1.1    dyoung 	/* Setup time for stop condition (4us) */
   1568  1.1    dyoung 	usec_delay(IXGBE_I2C_T_SU_STO);
   1569  1.1    dyoung 
   1570  1.1    dyoung 	ixgbe_set_i2c_data(hw, &i2cctl, 1);
   1571  1.1    dyoung 
   1572  1.1    dyoung 	/* bus free time between stop and start (4.7us)*/
   1573  1.1    dyoung 	usec_delay(IXGBE_I2C_T_BUF);
   1574  1.1    dyoung }
   1575  1.1    dyoung 
   1576  1.1    dyoung /**
   1577  1.1    dyoung  *  ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
   1578  1.1    dyoung  *  @hw: pointer to hardware structure
   1579  1.1    dyoung  *  @data: data byte to clock in
   1580  1.1    dyoung  *
   1581  1.1    dyoung  *  Clocks in one byte data via I2C data/clock
   1582  1.1    dyoung  **/
   1583  1.1    dyoung static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
   1584  1.1    dyoung {
   1585  1.1    dyoung 	s32 i;
   1586  1.1    dyoung 	bool bit = 0;
   1587  1.1    dyoung 
   1588  1.1    dyoung 	DEBUGFUNC("ixgbe_clock_in_i2c_byte");
   1589  1.1    dyoung 
   1590  1.1    dyoung 	for (i = 7; i >= 0; i--) {
   1591  1.3   msaitoh 		ixgbe_clock_in_i2c_bit(hw, &bit);
   1592  1.1    dyoung 		*data |= bit << i;
   1593  1.1    dyoung 	}
   1594  1.1    dyoung 
   1595  1.3   msaitoh 	return IXGBE_SUCCESS;
   1596  1.1    dyoung }
   1597  1.1    dyoung 
   1598  1.1    dyoung /**
   1599  1.1    dyoung  *  ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
   1600  1.1    dyoung  *  @hw: pointer to hardware structure
   1601  1.1    dyoung  *  @data: data byte clocked out
   1602  1.1    dyoung  *
   1603  1.1    dyoung  *  Clocks out one byte data via I2C data/clock
   1604  1.1    dyoung  **/
   1605  1.1    dyoung static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
   1606  1.1    dyoung {
   1607  1.1    dyoung 	s32 status = IXGBE_SUCCESS;
   1608  1.1    dyoung 	s32 i;
   1609  1.1    dyoung 	u32 i2cctl;
   1610  1.1    dyoung 	bool bit = 0;
   1611  1.1    dyoung 
   1612  1.1    dyoung 	DEBUGFUNC("ixgbe_clock_out_i2c_byte");
   1613  1.1    dyoung 
   1614  1.1    dyoung 	for (i = 7; i >= 0; i--) {
   1615  1.1    dyoung 		bit = (data >> i) & 0x1;
   1616  1.1    dyoung 		status = ixgbe_clock_out_i2c_bit(hw, bit);
   1617  1.1    dyoung 
   1618  1.1    dyoung 		if (status != IXGBE_SUCCESS)
   1619  1.1    dyoung 			break;
   1620  1.1    dyoung 	}
   1621  1.1    dyoung 
   1622  1.1    dyoung 	/* Release SDA line (set high) */
   1623  1.1    dyoung 	i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
   1624  1.1    dyoung 	i2cctl |= IXGBE_I2C_DATA_OUT;
   1625  1.1    dyoung 	IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
   1626  1.3   msaitoh 	IXGBE_WRITE_FLUSH(hw);
   1627  1.1    dyoung 
   1628  1.1    dyoung 	return status;
   1629  1.1    dyoung }
   1630  1.1    dyoung 
   1631  1.1    dyoung /**
   1632  1.1    dyoung  *  ixgbe_get_i2c_ack - Polls for I2C ACK
   1633  1.1    dyoung  *  @hw: pointer to hardware structure
   1634  1.1    dyoung  *
   1635  1.1    dyoung  *  Clocks in/out one bit via I2C data/clock
   1636  1.1    dyoung  **/
   1637  1.1    dyoung static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
   1638  1.1    dyoung {
   1639  1.3   msaitoh 	s32 status = IXGBE_SUCCESS;
   1640  1.1    dyoung 	u32 i = 0;
   1641  1.1    dyoung 	u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
   1642  1.1    dyoung 	u32 timeout = 10;
   1643  1.1    dyoung 	bool ack = 1;
   1644  1.1    dyoung 
   1645  1.1    dyoung 	DEBUGFUNC("ixgbe_get_i2c_ack");
   1646  1.1    dyoung 
   1647  1.3   msaitoh 	ixgbe_raise_i2c_clk(hw, &i2cctl);
   1648  1.1    dyoung 
   1649  1.1    dyoung 
   1650  1.1    dyoung 	/* Minimum high period of clock is 4us */
   1651  1.1    dyoung 	usec_delay(IXGBE_I2C_T_HIGH);
   1652  1.1    dyoung 
   1653  1.1    dyoung 	/* Poll for ACK.  Note that ACK in I2C spec is
   1654  1.1    dyoung 	 * transition from 1 to 0 */
   1655  1.1    dyoung 	for (i = 0; i < timeout; i++) {
   1656  1.1    dyoung 		i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
   1657  1.1    dyoung 		ack = ixgbe_get_i2c_data(&i2cctl);
   1658  1.1    dyoung 
   1659  1.1    dyoung 		usec_delay(1);
   1660  1.1    dyoung 		if (ack == 0)
   1661  1.1    dyoung 			break;
   1662  1.1    dyoung 	}
   1663  1.1    dyoung 
   1664  1.1    dyoung 	if (ack == 1) {
   1665  1.1    dyoung 		DEBUGOUT("I2C ack was not received.\n");
   1666  1.1    dyoung 		status = IXGBE_ERR_I2C;
   1667  1.1    dyoung 	}
   1668  1.1    dyoung 
   1669  1.1    dyoung 	ixgbe_lower_i2c_clk(hw, &i2cctl);
   1670  1.1    dyoung 
   1671  1.1    dyoung 	/* Minimum low period of clock is 4.7 us */
   1672  1.1    dyoung 	usec_delay(IXGBE_I2C_T_LOW);
   1673  1.1    dyoung 
   1674  1.1    dyoung 	return status;
   1675  1.1    dyoung }
   1676  1.1    dyoung 
   1677  1.1    dyoung /**
   1678  1.1    dyoung  *  ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
   1679  1.1    dyoung  *  @hw: pointer to hardware structure
   1680  1.1    dyoung  *  @data: read data value
   1681  1.1    dyoung  *
   1682  1.1    dyoung  *  Clocks in one bit via I2C data/clock
   1683  1.1    dyoung  **/
   1684  1.1    dyoung static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
   1685  1.1    dyoung {
   1686  1.1    dyoung 	u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
   1687  1.1    dyoung 
   1688  1.1    dyoung 	DEBUGFUNC("ixgbe_clock_in_i2c_bit");
   1689  1.1    dyoung 
   1690  1.3   msaitoh 	ixgbe_raise_i2c_clk(hw, &i2cctl);
   1691  1.1    dyoung 
   1692  1.1    dyoung 	/* Minimum high period of clock is 4us */
   1693  1.1    dyoung 	usec_delay(IXGBE_I2C_T_HIGH);
   1694  1.1    dyoung 
   1695  1.1    dyoung 	i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
   1696  1.1    dyoung 	*data = ixgbe_get_i2c_data(&i2cctl);
   1697  1.1    dyoung 
   1698  1.1    dyoung 	ixgbe_lower_i2c_clk(hw, &i2cctl);
   1699  1.1    dyoung 
   1700  1.1    dyoung 	/* Minimum low period of clock is 4.7 us */
   1701  1.1    dyoung 	usec_delay(IXGBE_I2C_T_LOW);
   1702  1.1    dyoung 
   1703  1.3   msaitoh 	return IXGBE_SUCCESS;
   1704  1.1    dyoung }
   1705  1.1    dyoung 
   1706  1.1    dyoung /**
   1707  1.1    dyoung  *  ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
   1708  1.1    dyoung  *  @hw: pointer to hardware structure
   1709  1.1    dyoung  *  @data: data value to write
   1710  1.1    dyoung  *
   1711  1.1    dyoung  *  Clocks out one bit via I2C data/clock
   1712  1.1    dyoung  **/
   1713  1.1    dyoung static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
   1714  1.1    dyoung {
   1715  1.1    dyoung 	s32 status;
   1716  1.1    dyoung 	u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
   1717  1.1    dyoung 
   1718  1.1    dyoung 	DEBUGFUNC("ixgbe_clock_out_i2c_bit");
   1719  1.1    dyoung 
   1720  1.1    dyoung 	status = ixgbe_set_i2c_data(hw, &i2cctl, data);
   1721  1.1    dyoung 	if (status == IXGBE_SUCCESS) {
   1722  1.3   msaitoh 		ixgbe_raise_i2c_clk(hw, &i2cctl);
   1723  1.1    dyoung 
   1724  1.1    dyoung 		/* Minimum high period of clock is 4us */
   1725  1.1    dyoung 		usec_delay(IXGBE_I2C_T_HIGH);
   1726  1.1    dyoung 
   1727  1.1    dyoung 		ixgbe_lower_i2c_clk(hw, &i2cctl);
   1728  1.1    dyoung 
   1729  1.1    dyoung 		/* Minimum low period of clock is 4.7 us.
   1730  1.1    dyoung 		 * This also takes care of the data hold time.
   1731  1.1    dyoung 		 */
   1732  1.1    dyoung 		usec_delay(IXGBE_I2C_T_LOW);
   1733  1.1    dyoung 	} else {
   1734  1.1    dyoung 		status = IXGBE_ERR_I2C;
   1735  1.1    dyoung 		DEBUGOUT1("I2C data was not set to %X\n", data);
   1736  1.1    dyoung 	}
   1737  1.1    dyoung 
   1738  1.1    dyoung 	return status;
   1739  1.1    dyoung }
   1740  1.1    dyoung /**
   1741  1.1    dyoung  *  ixgbe_raise_i2c_clk - Raises the I2C SCL clock
   1742  1.1    dyoung  *  @hw: pointer to hardware structure
   1743  1.1    dyoung  *  @i2cctl: Current value of I2CCTL register
   1744  1.1    dyoung  *
   1745  1.1    dyoung  *  Raises the I2C clock line '0'->'1'
   1746  1.1    dyoung  **/
   1747  1.3   msaitoh static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
   1748  1.1    dyoung {
   1749  1.4   msaitoh 	u32 i = 0;
   1750  1.4   msaitoh 	u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
   1751  1.4   msaitoh 	u32 i2cctl_r = 0;
   1752  1.4   msaitoh 
   1753  1.1    dyoung 	DEBUGFUNC("ixgbe_raise_i2c_clk");
   1754  1.1    dyoung 
   1755  1.4   msaitoh 	for (i = 0; i < timeout; i++) {
   1756  1.4   msaitoh 		*i2cctl |= IXGBE_I2C_CLK_OUT;
   1757  1.1    dyoung 
   1758  1.4   msaitoh 		IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
   1759  1.4   msaitoh 		IXGBE_WRITE_FLUSH(hw);
   1760  1.4   msaitoh 		/* SCL rise time (1000ns) */
   1761  1.4   msaitoh 		usec_delay(IXGBE_I2C_T_RISE);
   1762  1.1    dyoung 
   1763  1.4   msaitoh 		i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
   1764  1.4   msaitoh 		if (i2cctl_r & IXGBE_I2C_CLK_IN)
   1765  1.4   msaitoh 			break;
   1766  1.4   msaitoh 	}
   1767  1.1    dyoung }
   1768  1.1    dyoung 
   1769  1.1    dyoung /**
   1770  1.1    dyoung  *  ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
   1771  1.1    dyoung  *  @hw: pointer to hardware structure
   1772  1.1    dyoung  *  @i2cctl: Current value of I2CCTL register
   1773  1.1    dyoung  *
   1774  1.1    dyoung  *  Lowers the I2C clock line '1'->'0'
   1775  1.1    dyoung  **/
   1776  1.1    dyoung static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
   1777  1.1    dyoung {
   1778  1.1    dyoung 
   1779  1.1    dyoung 	DEBUGFUNC("ixgbe_lower_i2c_clk");
   1780  1.1    dyoung 
   1781  1.1    dyoung 	*i2cctl &= ~IXGBE_I2C_CLK_OUT;
   1782  1.1    dyoung 
   1783  1.1    dyoung 	IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
   1784  1.3   msaitoh 	IXGBE_WRITE_FLUSH(hw);
   1785  1.1    dyoung 
   1786  1.1    dyoung 	/* SCL fall time (300ns) */
   1787  1.1    dyoung 	usec_delay(IXGBE_I2C_T_FALL);
   1788  1.1    dyoung }
   1789  1.1    dyoung 
   1790  1.1    dyoung /**
   1791  1.1    dyoung  *  ixgbe_set_i2c_data - Sets the I2C data bit
   1792  1.1    dyoung  *  @hw: pointer to hardware structure
   1793  1.1    dyoung  *  @i2cctl: Current value of I2CCTL register
   1794  1.1    dyoung  *  @data: I2C data value (0 or 1) to set
   1795  1.1    dyoung  *
   1796  1.1    dyoung  *  Sets the I2C data bit
   1797  1.1    dyoung  **/
   1798  1.1    dyoung static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
   1799  1.1    dyoung {
   1800  1.1    dyoung 	s32 status = IXGBE_SUCCESS;
   1801  1.1    dyoung 
   1802  1.1    dyoung 	DEBUGFUNC("ixgbe_set_i2c_data");
   1803  1.1    dyoung 
   1804  1.1    dyoung 	if (data)
   1805  1.1    dyoung 		*i2cctl |= IXGBE_I2C_DATA_OUT;
   1806  1.1    dyoung 	else
   1807  1.1    dyoung 		*i2cctl &= ~IXGBE_I2C_DATA_OUT;
   1808  1.1    dyoung 
   1809  1.1    dyoung 	IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
   1810  1.3   msaitoh 	IXGBE_WRITE_FLUSH(hw);
   1811  1.1    dyoung 
   1812  1.1    dyoung 	/* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
   1813  1.1    dyoung 	usec_delay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
   1814  1.1    dyoung 
   1815  1.1    dyoung 	/* Verify data was set correctly */
   1816  1.1    dyoung 	*i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
   1817  1.1    dyoung 	if (data != ixgbe_get_i2c_data(i2cctl)) {
   1818  1.1    dyoung 		status = IXGBE_ERR_I2C;
   1819  1.1    dyoung 		DEBUGOUT1("Error - I2C data was not set to %X.\n", data);
   1820  1.1    dyoung 	}
   1821  1.1    dyoung 
   1822  1.1    dyoung 	return status;
   1823  1.1    dyoung }
   1824  1.1    dyoung 
   1825  1.1    dyoung /**
   1826  1.1    dyoung  *  ixgbe_get_i2c_data - Reads the I2C SDA data bit
   1827  1.1    dyoung  *  @hw: pointer to hardware structure
   1828  1.1    dyoung  *  @i2cctl: Current value of I2CCTL register
   1829  1.1    dyoung  *
   1830  1.1    dyoung  *  Returns the I2C data bit value
   1831  1.1    dyoung  **/
   1832  1.1    dyoung static bool ixgbe_get_i2c_data(u32 *i2cctl)
   1833  1.1    dyoung {
   1834  1.1    dyoung 	bool data;
   1835  1.1    dyoung 
   1836  1.1    dyoung 	DEBUGFUNC("ixgbe_get_i2c_data");
   1837  1.1    dyoung 
   1838  1.1    dyoung 	if (*i2cctl & IXGBE_I2C_DATA_IN)
   1839  1.1    dyoung 		data = 1;
   1840  1.1    dyoung 	else
   1841  1.1    dyoung 		data = 0;
   1842  1.1    dyoung 
   1843  1.1    dyoung 	return data;
   1844  1.1    dyoung }
   1845  1.1    dyoung 
   1846  1.1    dyoung /**
   1847  1.1    dyoung  *  ixgbe_i2c_bus_clear - Clears the I2C bus
   1848  1.1    dyoung  *  @hw: pointer to hardware structure
   1849  1.1    dyoung  *
   1850  1.1    dyoung  *  Clears the I2C bus by sending nine clock pulses.
   1851  1.1    dyoung  *  Used when data line is stuck low.
   1852  1.1    dyoung  **/
   1853  1.1    dyoung void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
   1854  1.1    dyoung {
   1855  1.1    dyoung 	u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
   1856  1.1    dyoung 	u32 i;
   1857  1.1    dyoung 
   1858  1.1    dyoung 	DEBUGFUNC("ixgbe_i2c_bus_clear");
   1859  1.1    dyoung 
   1860  1.1    dyoung 	ixgbe_i2c_start(hw);
   1861  1.1    dyoung 
   1862  1.1    dyoung 	ixgbe_set_i2c_data(hw, &i2cctl, 1);
   1863  1.1    dyoung 
   1864  1.1    dyoung 	for (i = 0; i < 9; i++) {
   1865  1.1    dyoung 		ixgbe_raise_i2c_clk(hw, &i2cctl);
   1866  1.1    dyoung 
   1867  1.1    dyoung 		/* Min high period of clock is 4us */
   1868  1.1    dyoung 		usec_delay(IXGBE_I2C_T_HIGH);
   1869  1.1    dyoung 
   1870  1.1    dyoung 		ixgbe_lower_i2c_clk(hw, &i2cctl);
   1871  1.1    dyoung 
   1872  1.1    dyoung 		/* Min low period of clock is 4.7us*/
   1873  1.1    dyoung 		usec_delay(IXGBE_I2C_T_LOW);
   1874  1.1    dyoung 	}
   1875  1.1    dyoung 
   1876  1.1    dyoung 	ixgbe_i2c_start(hw);
   1877  1.1    dyoung 
   1878  1.1    dyoung 	/* Put the i2c bus back to default state */
   1879  1.1    dyoung 	ixgbe_i2c_stop(hw);
   1880  1.1    dyoung }
   1881  1.1    dyoung 
   1882  1.1    dyoung /**
   1883  1.4   msaitoh  *  ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
   1884  1.1    dyoung  *  @hw: pointer to hardware structure
   1885  1.1    dyoung  *
   1886  1.1    dyoung  *  Checks if the LASI temp alarm status was triggered due to overtemp
   1887  1.1    dyoung  **/
   1888  1.1    dyoung s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
   1889  1.1    dyoung {
   1890  1.1    dyoung 	s32 status = IXGBE_SUCCESS;
   1891  1.1    dyoung 	u16 phy_data = 0;
   1892  1.1    dyoung 
   1893  1.1    dyoung 	DEBUGFUNC("ixgbe_tn_check_overtemp");
   1894  1.1    dyoung 
   1895  1.1    dyoung 	if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
   1896  1.1    dyoung 		goto out;
   1897  1.1    dyoung 
   1898  1.1    dyoung 	/* Check that the LASI temp alarm status was triggered */
   1899  1.1    dyoung 	hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
   1900  1.1    dyoung 			     IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_data);
   1901  1.1    dyoung 
   1902  1.1    dyoung 	if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
   1903  1.1    dyoung 		goto out;
   1904  1.1    dyoung 
   1905  1.1    dyoung 	status = IXGBE_ERR_OVERTEMP;
   1906  1.1    dyoung out:
   1907  1.1    dyoung 	return status;
   1908  1.1    dyoung }
   1909