Home | History | Annotate | Line # | Download | only in ixgbe
ixgbe_phy.c revision 1.24
      1  1.24   msaitoh /* $NetBSD: ixgbe_phy.c,v 1.24 2021/04/30 06:55:32 msaitoh Exp $ */
      2  1.12   msaitoh 
      3   1.1    dyoung /******************************************************************************
      4  1.14   msaitoh   SPDX-License-Identifier: BSD-3-Clause
      5   1.1    dyoung 
      6  1.12   msaitoh   Copyright (c) 2001-2017, Intel Corporation
      7   1.1    dyoung   All rights reserved.
      8  1.12   msaitoh 
      9  1.12   msaitoh   Redistribution and use in source and binary forms, with or without
     10   1.1    dyoung   modification, are permitted provided that the following conditions are met:
     11  1.12   msaitoh 
     12  1.12   msaitoh    1. Redistributions of source code must retain the above copyright notice,
     13   1.1    dyoung       this list of conditions and the following disclaimer.
     14  1.12   msaitoh 
     15  1.12   msaitoh    2. Redistributions in binary form must reproduce the above copyright
     16  1.12   msaitoh       notice, this list of conditions and the following disclaimer in the
     17   1.1    dyoung       documentation and/or other materials provided with the distribution.
     18  1.12   msaitoh 
     19  1.12   msaitoh    3. Neither the name of the Intel Corporation nor the names of its
     20  1.12   msaitoh       contributors may be used to endorse or promote products derived from
     21   1.1    dyoung       this software without specific prior written permission.
     22  1.12   msaitoh 
     23   1.1    dyoung   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     24  1.12   msaitoh   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.12   msaitoh   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.12   msaitoh   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     27  1.12   msaitoh   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28  1.12   msaitoh   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29  1.12   msaitoh   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30  1.12   msaitoh   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31  1.12   msaitoh   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32   1.1    dyoung   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33   1.1    dyoung   POSSIBILITY OF SUCH DAMAGE.
     34   1.1    dyoung 
     35   1.1    dyoung ******************************************************************************/
     36  1.17   msaitoh /*$FreeBSD: head/sys/dev/ixgbe/ixgbe_phy.c 331224 2018-03-19 20:55:05Z erj $*/
     37   1.1    dyoung 
     38  1.24   msaitoh #include <sys/cdefs.h>
     39  1.24   msaitoh __KERNEL_RCSID(0, "$NetBSD: ixgbe_phy.c,v 1.24 2021/04/30 06:55:32 msaitoh Exp $");
     40  1.24   msaitoh 
     41   1.1    dyoung #include "ixgbe_api.h"
     42   1.1    dyoung #include "ixgbe_common.h"
     43   1.1    dyoung #include "ixgbe_phy.h"
     44   1.1    dyoung 
     45  1.13   msaitoh #include <dev/mii/mdio.h>
     46  1.13   msaitoh 
     47   1.1    dyoung static void ixgbe_i2c_start(struct ixgbe_hw *hw);
     48   1.1    dyoung static void ixgbe_i2c_stop(struct ixgbe_hw *hw);
     49   1.1    dyoung static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data);
     50   1.1    dyoung static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data);
     51   1.1    dyoung static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw);
     52   1.1    dyoung static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data);
     53   1.1    dyoung static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data);
     54   1.3   msaitoh static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
     55   1.1    dyoung static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
     56   1.1    dyoung static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data);
     57   1.7   msaitoh static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl);
     58   1.5   msaitoh static s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
     59   1.5   msaitoh 					  u8 *sff8472_data);
     60   1.1    dyoung 
     61   1.1    dyoung /**
     62   1.7   msaitoh  * ixgbe_out_i2c_byte_ack - Send I2C byte with ack
     63   1.7   msaitoh  * @hw: pointer to the hardware structure
     64   1.7   msaitoh  * @byte: byte to send
     65   1.7   msaitoh  *
     66   1.7   msaitoh  * Returns an error code on error.
     67   1.7   msaitoh  */
     68   1.7   msaitoh static s32 ixgbe_out_i2c_byte_ack(struct ixgbe_hw *hw, u8 byte)
     69   1.7   msaitoh {
     70   1.7   msaitoh 	s32 status;
     71   1.7   msaitoh 
     72   1.7   msaitoh 	status = ixgbe_clock_out_i2c_byte(hw, byte);
     73   1.7   msaitoh 	if (status)
     74   1.7   msaitoh 		return status;
     75   1.7   msaitoh 	return ixgbe_get_i2c_ack(hw);
     76   1.7   msaitoh }
     77   1.7   msaitoh 
     78   1.7   msaitoh /**
     79   1.7   msaitoh  * ixgbe_in_i2c_byte_ack - Receive an I2C byte and send ack
     80   1.7   msaitoh  * @hw: pointer to the hardware structure
     81   1.7   msaitoh  * @byte: pointer to a u8 to receive the byte
     82   1.7   msaitoh  *
     83   1.7   msaitoh  * Returns an error code on error.
     84   1.7   msaitoh  */
     85   1.7   msaitoh static s32 ixgbe_in_i2c_byte_ack(struct ixgbe_hw *hw, u8 *byte)
     86   1.7   msaitoh {
     87   1.7   msaitoh 	s32 status;
     88   1.7   msaitoh 
     89   1.7   msaitoh 	status = ixgbe_clock_in_i2c_byte(hw, byte);
     90   1.7   msaitoh 	if (status)
     91   1.7   msaitoh 		return status;
     92   1.7   msaitoh 	/* ACK */
     93   1.7   msaitoh 	return ixgbe_clock_out_i2c_bit(hw, FALSE);
     94   1.7   msaitoh }
     95   1.7   msaitoh 
     96   1.7   msaitoh /**
     97   1.7   msaitoh  * ixgbe_ones_comp_byte_add - Perform one's complement addition
     98  1.17   msaitoh  * @add1: addend 1
     99  1.17   msaitoh  * @add2: addend 2
    100   1.7   msaitoh  *
    101   1.7   msaitoh  * Returns one's complement 8-bit sum.
    102   1.7   msaitoh  */
    103   1.7   msaitoh static u8 ixgbe_ones_comp_byte_add(u8 add1, u8 add2)
    104   1.7   msaitoh {
    105   1.7   msaitoh 	u16 sum = add1 + add2;
    106   1.7   msaitoh 
    107   1.7   msaitoh 	sum = (sum & 0xFF) + (sum >> 8);
    108   1.7   msaitoh 	return sum & 0xFF;
    109   1.7   msaitoh }
    110   1.7   msaitoh 
    111   1.7   msaitoh /**
    112   1.8   msaitoh  * ixgbe_read_i2c_combined_generic_int - Perform I2C read combined operation
    113   1.7   msaitoh  * @hw: pointer to the hardware structure
    114   1.7   msaitoh  * @addr: I2C bus address to read from
    115   1.7   msaitoh  * @reg: I2C device register to read from
    116   1.7   msaitoh  * @val: pointer to location to receive read value
    117   1.8   msaitoh  * @lock: TRUE if to take and release semaphore
    118   1.7   msaitoh  *
    119   1.7   msaitoh  * Returns an error code on error.
    120   1.7   msaitoh  */
    121  1.12   msaitoh s32 ixgbe_read_i2c_combined_generic_int(struct ixgbe_hw *hw, u8 addr, u16 reg,
    122  1.12   msaitoh 					u16 *val, bool lock)
    123   1.7   msaitoh {
    124   1.7   msaitoh 	u32 swfw_mask = hw->phy.phy_semaphore_mask;
    125  1.12   msaitoh 	int max_retry = 3;
    126   1.7   msaitoh 	int retry = 0;
    127   1.7   msaitoh 	u8 csum_byte;
    128   1.7   msaitoh 	u8 high_bits;
    129   1.7   msaitoh 	u8 low_bits;
    130   1.7   msaitoh 	u8 reg_high;
    131   1.7   msaitoh 	u8 csum;
    132   1.7   msaitoh 
    133   1.7   msaitoh 	reg_high = ((reg >> 7) & 0xFE) | 1;	/* Indicate read combined */
    134   1.7   msaitoh 	csum = ixgbe_ones_comp_byte_add(reg_high, reg & 0xFF);
    135   1.7   msaitoh 	csum = ~csum;
    136   1.7   msaitoh 	do {
    137   1.8   msaitoh 		if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
    138   1.7   msaitoh 			return IXGBE_ERR_SWFW_SYNC;
    139   1.7   msaitoh 		ixgbe_i2c_start(hw);
    140   1.7   msaitoh 		/* Device Address and write indication */
    141   1.7   msaitoh 		if (ixgbe_out_i2c_byte_ack(hw, addr))
    142   1.7   msaitoh 			goto fail;
    143   1.7   msaitoh 		/* Write bits 14:8 */
    144   1.7   msaitoh 		if (ixgbe_out_i2c_byte_ack(hw, reg_high))
    145   1.7   msaitoh 			goto fail;
    146   1.7   msaitoh 		/* Write bits 7:0 */
    147   1.7   msaitoh 		if (ixgbe_out_i2c_byte_ack(hw, reg & 0xFF))
    148   1.7   msaitoh 			goto fail;
    149   1.7   msaitoh 		/* Write csum */
    150   1.7   msaitoh 		if (ixgbe_out_i2c_byte_ack(hw, csum))
    151   1.7   msaitoh 			goto fail;
    152   1.7   msaitoh 		/* Re-start condition */
    153   1.7   msaitoh 		ixgbe_i2c_start(hw);
    154   1.7   msaitoh 		/* Device Address and read indication */
    155   1.7   msaitoh 		if (ixgbe_out_i2c_byte_ack(hw, addr | 1))
    156   1.7   msaitoh 			goto fail;
    157   1.7   msaitoh 		/* Get upper bits */
    158   1.7   msaitoh 		if (ixgbe_in_i2c_byte_ack(hw, &high_bits))
    159   1.7   msaitoh 			goto fail;
    160   1.7   msaitoh 		/* Get low bits */
    161   1.7   msaitoh 		if (ixgbe_in_i2c_byte_ack(hw, &low_bits))
    162   1.7   msaitoh 			goto fail;
    163   1.7   msaitoh 		/* Get csum */
    164   1.7   msaitoh 		if (ixgbe_clock_in_i2c_byte(hw, &csum_byte))
    165   1.7   msaitoh 			goto fail;
    166   1.7   msaitoh 		/* NACK */
    167   1.7   msaitoh 		if (ixgbe_clock_out_i2c_bit(hw, FALSE))
    168   1.7   msaitoh 			goto fail;
    169   1.7   msaitoh 		ixgbe_i2c_stop(hw);
    170   1.8   msaitoh 		if (lock)
    171   1.8   msaitoh 			hw->mac.ops.release_swfw_sync(hw, swfw_mask);
    172   1.7   msaitoh 		*val = (high_bits << 8) | low_bits;
    173   1.7   msaitoh 		return 0;
    174   1.7   msaitoh 
    175   1.7   msaitoh fail:
    176   1.7   msaitoh 		ixgbe_i2c_bus_clear(hw);
    177   1.8   msaitoh 		if (lock)
    178   1.8   msaitoh 			hw->mac.ops.release_swfw_sync(hw, swfw_mask);
    179   1.7   msaitoh 		retry++;
    180   1.7   msaitoh 		if (retry < max_retry)
    181   1.7   msaitoh 			DEBUGOUT("I2C byte read combined error - Retrying.\n");
    182   1.7   msaitoh 		else
    183   1.7   msaitoh 			DEBUGOUT("I2C byte read combined error.\n");
    184   1.7   msaitoh 	} while (retry < max_retry);
    185   1.7   msaitoh 
    186   1.7   msaitoh 	return IXGBE_ERR_I2C;
    187   1.7   msaitoh }
    188   1.7   msaitoh 
    189   1.7   msaitoh /**
    190   1.8   msaitoh  * ixgbe_write_i2c_combined_generic_int - Perform I2C write combined operation
    191   1.7   msaitoh  * @hw: pointer to the hardware structure
    192   1.7   msaitoh  * @addr: I2C bus address to write to
    193   1.7   msaitoh  * @reg: I2C device register to write to
    194   1.7   msaitoh  * @val: value to write
    195   1.8   msaitoh  * @lock: TRUE if to take and release semaphore
    196   1.7   msaitoh  *
    197   1.7   msaitoh  * Returns an error code on error.
    198   1.7   msaitoh  */
    199  1.12   msaitoh s32 ixgbe_write_i2c_combined_generic_int(struct ixgbe_hw *hw, u8 addr, u16 reg,
    200  1.12   msaitoh 					 u16 val, bool lock)
    201   1.7   msaitoh {
    202   1.8   msaitoh 	u32 swfw_mask = hw->phy.phy_semaphore_mask;
    203   1.7   msaitoh 	int max_retry = 1;
    204   1.7   msaitoh 	int retry = 0;
    205   1.7   msaitoh 	u8 reg_high;
    206   1.7   msaitoh 	u8 csum;
    207   1.7   msaitoh 
    208   1.7   msaitoh 	reg_high = (reg >> 7) & 0xFE;	/* Indicate write combined */
    209   1.7   msaitoh 	csum = ixgbe_ones_comp_byte_add(reg_high, reg & 0xFF);
    210   1.7   msaitoh 	csum = ixgbe_ones_comp_byte_add(csum, val >> 8);
    211   1.7   msaitoh 	csum = ixgbe_ones_comp_byte_add(csum, val & 0xFF);
    212   1.7   msaitoh 	csum = ~csum;
    213   1.7   msaitoh 	do {
    214   1.8   msaitoh 		if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
    215   1.8   msaitoh 			return IXGBE_ERR_SWFW_SYNC;
    216   1.7   msaitoh 		ixgbe_i2c_start(hw);
    217   1.7   msaitoh 		/* Device Address and write indication */
    218   1.7   msaitoh 		if (ixgbe_out_i2c_byte_ack(hw, addr))
    219   1.7   msaitoh 			goto fail;
    220   1.7   msaitoh 		/* Write bits 14:8 */
    221   1.7   msaitoh 		if (ixgbe_out_i2c_byte_ack(hw, reg_high))
    222   1.7   msaitoh 			goto fail;
    223   1.7   msaitoh 		/* Write bits 7:0 */
    224   1.7   msaitoh 		if (ixgbe_out_i2c_byte_ack(hw, reg & 0xFF))
    225   1.7   msaitoh 			goto fail;
    226   1.7   msaitoh 		/* Write data 15:8 */
    227   1.7   msaitoh 		if (ixgbe_out_i2c_byte_ack(hw, val >> 8))
    228   1.7   msaitoh 			goto fail;
    229   1.7   msaitoh 		/* Write data 7:0 */
    230   1.7   msaitoh 		if (ixgbe_out_i2c_byte_ack(hw, val & 0xFF))
    231   1.7   msaitoh 			goto fail;
    232   1.7   msaitoh 		/* Write csum */
    233   1.7   msaitoh 		if (ixgbe_out_i2c_byte_ack(hw, csum))
    234   1.7   msaitoh 			goto fail;
    235   1.7   msaitoh 		ixgbe_i2c_stop(hw);
    236   1.8   msaitoh 		if (lock)
    237   1.8   msaitoh 			hw->mac.ops.release_swfw_sync(hw, swfw_mask);
    238   1.7   msaitoh 		return 0;
    239   1.7   msaitoh 
    240   1.7   msaitoh fail:
    241   1.7   msaitoh 		ixgbe_i2c_bus_clear(hw);
    242   1.8   msaitoh 		if (lock)
    243   1.8   msaitoh 			hw->mac.ops.release_swfw_sync(hw, swfw_mask);
    244   1.7   msaitoh 		retry++;
    245   1.7   msaitoh 		if (retry < max_retry)
    246   1.7   msaitoh 			DEBUGOUT("I2C byte write combined error - Retrying.\n");
    247   1.7   msaitoh 		else
    248   1.7   msaitoh 			DEBUGOUT("I2C byte write combined error.\n");
    249   1.7   msaitoh 	} while (retry < max_retry);
    250   1.7   msaitoh 
    251   1.7   msaitoh 	return IXGBE_ERR_I2C;
    252   1.7   msaitoh }
    253   1.7   msaitoh 
    254   1.7   msaitoh /**
    255   1.1    dyoung  *  ixgbe_init_phy_ops_generic - Inits PHY function ptrs
    256   1.1    dyoung  *  @hw: pointer to the hardware structure
    257   1.1    dyoung  *
    258   1.1    dyoung  *  Initialize the function pointers.
    259   1.1    dyoung  **/
    260   1.1    dyoung s32 ixgbe_init_phy_ops_generic(struct ixgbe_hw *hw)
    261   1.1    dyoung {
    262   1.1    dyoung 	struct ixgbe_phy_info *phy = &hw->phy;
    263   1.1    dyoung 
    264   1.1    dyoung 	DEBUGFUNC("ixgbe_init_phy_ops_generic");
    265   1.1    dyoung 
    266   1.1    dyoung 	/* PHY */
    267   1.7   msaitoh 	phy->ops.identify = ixgbe_identify_phy_generic;
    268   1.7   msaitoh 	phy->ops.reset = ixgbe_reset_phy_generic;
    269   1.7   msaitoh 	phy->ops.read_reg = ixgbe_read_phy_reg_generic;
    270   1.7   msaitoh 	phy->ops.write_reg = ixgbe_write_phy_reg_generic;
    271   1.7   msaitoh 	phy->ops.read_reg_mdi = ixgbe_read_phy_reg_mdi;
    272   1.7   msaitoh 	phy->ops.write_reg_mdi = ixgbe_write_phy_reg_mdi;
    273   1.7   msaitoh 	phy->ops.setup_link = ixgbe_setup_phy_link_generic;
    274   1.7   msaitoh 	phy->ops.setup_link_speed = ixgbe_setup_phy_link_speed_generic;
    275   1.1    dyoung 	phy->ops.check_link = NULL;
    276   1.1    dyoung 	phy->ops.get_firmware_version = ixgbe_get_phy_firmware_version_generic;
    277   1.7   msaitoh 	phy->ops.read_i2c_byte = ixgbe_read_i2c_byte_generic;
    278   1.7   msaitoh 	phy->ops.write_i2c_byte = ixgbe_write_i2c_byte_generic;
    279   1.7   msaitoh 	phy->ops.read_i2c_sff8472 = ixgbe_read_i2c_sff8472_generic;
    280   1.7   msaitoh 	phy->ops.read_i2c_eeprom = ixgbe_read_i2c_eeprom_generic;
    281   1.7   msaitoh 	phy->ops.write_i2c_eeprom = ixgbe_write_i2c_eeprom_generic;
    282   1.7   msaitoh 	phy->ops.i2c_bus_clear = ixgbe_i2c_bus_clear;
    283   1.7   msaitoh 	phy->ops.identify_sfp = ixgbe_identify_module_generic;
    284   1.1    dyoung 	phy->sfp_type = ixgbe_sfp_type_unknown;
    285   1.8   msaitoh 	phy->ops.read_i2c_byte_unlocked = ixgbe_read_i2c_byte_generic_unlocked;
    286   1.8   msaitoh 	phy->ops.write_i2c_byte_unlocked =
    287   1.8   msaitoh 				ixgbe_write_i2c_byte_generic_unlocked;
    288   1.7   msaitoh 	phy->ops.check_overtemp = ixgbe_tn_check_overtemp;
    289   1.1    dyoung 	return IXGBE_SUCCESS;
    290   1.1    dyoung }
    291   1.1    dyoung 
    292   1.1    dyoung /**
    293  1.12   msaitoh  * ixgbe_probe_phy - Probe a single address for a PHY
    294  1.12   msaitoh  * @hw: pointer to hardware structure
    295  1.12   msaitoh  * @phy_addr: PHY address to probe
    296  1.12   msaitoh  *
    297  1.12   msaitoh  * Returns TRUE if PHY found
    298  1.12   msaitoh  */
    299  1.12   msaitoh static bool ixgbe_probe_phy(struct ixgbe_hw *hw, u16 phy_addr)
    300  1.12   msaitoh {
    301  1.12   msaitoh 	u16 ext_ability = 0;
    302  1.12   msaitoh 
    303  1.12   msaitoh 	if (!ixgbe_validate_phy_addr(hw, phy_addr)) {
    304  1.12   msaitoh 		DEBUGOUT1("Unable to validate PHY address 0x%04X\n",
    305  1.12   msaitoh 			phy_addr);
    306  1.12   msaitoh 		return FALSE;
    307  1.12   msaitoh 	}
    308  1.12   msaitoh 
    309  1.12   msaitoh 	if (ixgbe_get_phy_id(hw))
    310  1.12   msaitoh 		return FALSE;
    311  1.12   msaitoh 
    312  1.12   msaitoh 	hw->phy.type = ixgbe_get_phy_type_from_id(hw->phy.id);
    313  1.12   msaitoh 
    314  1.12   msaitoh 	if (hw->phy.type == ixgbe_phy_unknown) {
    315  1.12   msaitoh 		hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_EXT_ABILITY,
    316  1.12   msaitoh 				     IXGBE_MDIO_PMA_PMD_DEV_TYPE, &ext_ability);
    317  1.12   msaitoh 		if (ext_ability &
    318  1.12   msaitoh 		    (IXGBE_MDIO_PHY_10GBASET_ABILITY |
    319  1.12   msaitoh 		     IXGBE_MDIO_PHY_1000BASET_ABILITY))
    320  1.12   msaitoh 			hw->phy.type = ixgbe_phy_cu_unknown;
    321  1.12   msaitoh 		else
    322  1.12   msaitoh 			hw->phy.type = ixgbe_phy_generic;
    323  1.12   msaitoh 	}
    324  1.12   msaitoh 
    325  1.12   msaitoh 	return TRUE;
    326  1.12   msaitoh }
    327  1.12   msaitoh 
    328  1.12   msaitoh /**
    329   1.1    dyoung  *  ixgbe_identify_phy_generic - Get physical layer module
    330   1.1    dyoung  *  @hw: pointer to hardware structure
    331   1.1    dyoung  *
    332   1.1    dyoung  *  Determines the physical layer module found on the current adapter.
    333   1.1    dyoung  **/
    334   1.1    dyoung s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
    335   1.1    dyoung {
    336   1.1    dyoung 	s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
    337  1.12   msaitoh 	u16 phy_addr;
    338   1.1    dyoung 
    339   1.1    dyoung 	DEBUGFUNC("ixgbe_identify_phy_generic");
    340   1.1    dyoung 
    341   1.7   msaitoh 	if (!hw->phy.phy_semaphore_mask) {
    342   1.7   msaitoh 		if (hw->bus.lan_id)
    343   1.7   msaitoh 			hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
    344   1.7   msaitoh 		else
    345   1.7   msaitoh 			hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
    346   1.7   msaitoh 	}
    347   1.7   msaitoh 
    348  1.12   msaitoh 	if (hw->phy.type != ixgbe_phy_unknown)
    349  1.12   msaitoh 		return IXGBE_SUCCESS;
    350   1.1    dyoung 
    351  1.12   msaitoh 	if (hw->phy.nw_mng_if_sel) {
    352  1.12   msaitoh 		phy_addr = (hw->phy.nw_mng_if_sel &
    353  1.12   msaitoh 			    IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD) >>
    354  1.12   msaitoh 			   IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD_SHIFT;
    355  1.12   msaitoh 		if (ixgbe_probe_phy(hw, phy_addr))
    356  1.12   msaitoh 			return IXGBE_SUCCESS;
    357  1.12   msaitoh 		else
    358  1.12   msaitoh 			return IXGBE_ERR_PHY_ADDR_INVALID;
    359  1.12   msaitoh 	}
    360   1.7   msaitoh 
    361  1.12   msaitoh 	for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
    362  1.12   msaitoh 		if (ixgbe_probe_phy(hw, phy_addr)) {
    363  1.12   msaitoh 			status = IXGBE_SUCCESS;
    364  1.12   msaitoh 			break;
    365   1.6   msaitoh 		}
    366   1.1    dyoung 	}
    367   1.1    dyoung 
    368  1.12   msaitoh 	/* Certain media types do not have a phy so an address will not
    369  1.12   msaitoh 	 * be found and the code will take this path.  Caller has to
    370  1.12   msaitoh 	 * decide if it is an error or not.
    371  1.12   msaitoh 	 */
    372  1.12   msaitoh 	if (status != IXGBE_SUCCESS)
    373  1.12   msaitoh 		hw->phy.addr = 0;
    374  1.12   msaitoh 
    375   1.1    dyoung 	return status;
    376   1.1    dyoung }
    377   1.1    dyoung 
    378   1.1    dyoung /**
    379   1.7   msaitoh  * ixgbe_check_reset_blocked - check status of MNG FW veto bit
    380   1.7   msaitoh  * @hw: pointer to the hardware structure
    381   1.7   msaitoh  *
    382   1.7   msaitoh  * This function checks the MMNGC.MNG_VETO bit to see if there are
    383   1.7   msaitoh  * any constraints on link from manageability.  For MAC's that don't
    384   1.7   msaitoh  * have this bit just return faluse since the link can not be blocked
    385   1.7   msaitoh  * via this method.
    386   1.7   msaitoh  **/
    387   1.7   msaitoh s32 ixgbe_check_reset_blocked(struct ixgbe_hw *hw)
    388   1.7   msaitoh {
    389   1.7   msaitoh 	u32 mmngc;
    390   1.7   msaitoh 
    391   1.7   msaitoh 	DEBUGFUNC("ixgbe_check_reset_blocked");
    392   1.7   msaitoh 
    393   1.7   msaitoh 	/* If we don't have this bit, it can't be blocking */
    394   1.7   msaitoh 	if (hw->mac.type == ixgbe_mac_82598EB)
    395   1.7   msaitoh 		return FALSE;
    396   1.7   msaitoh 
    397   1.7   msaitoh 	mmngc = IXGBE_READ_REG(hw, IXGBE_MMNGC);
    398   1.7   msaitoh 	if (mmngc & IXGBE_MMNGC_MNG_VETO) {
    399   1.7   msaitoh 		ERROR_REPORT1(IXGBE_ERROR_SOFTWARE,
    400   1.7   msaitoh 			      "MNG_VETO bit detected.\n");
    401   1.7   msaitoh 		return TRUE;
    402   1.7   msaitoh 	}
    403   1.7   msaitoh 
    404   1.7   msaitoh 	return FALSE;
    405   1.7   msaitoh }
    406   1.7   msaitoh 
    407   1.7   msaitoh /**
    408   1.1    dyoung  *  ixgbe_validate_phy_addr - Determines phy address is valid
    409   1.1    dyoung  *  @hw: pointer to hardware structure
    410  1.17   msaitoh  *  @phy_addr: PHY address
    411   1.1    dyoung  *
    412   1.1    dyoung  **/
    413   1.1    dyoung bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr)
    414   1.1    dyoung {
    415   1.1    dyoung 	u16 phy_id = 0;
    416   1.1    dyoung 	bool valid = FALSE;
    417   1.1    dyoung 
    418   1.1    dyoung 	DEBUGFUNC("ixgbe_validate_phy_addr");
    419   1.1    dyoung 
    420   1.1    dyoung 	hw->phy.addr = phy_addr;
    421   1.1    dyoung 	hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
    422   1.3   msaitoh 			     IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_id);
    423   1.1    dyoung 
    424   1.1    dyoung 	if (phy_id != 0xFFFF && phy_id != 0x0)
    425   1.1    dyoung 		valid = TRUE;
    426   1.1    dyoung 
    427  1.12   msaitoh 	DEBUGOUT1("PHY ID HIGH is 0x%04X\n", phy_id);
    428  1.12   msaitoh 
    429   1.1    dyoung 	return valid;
    430   1.1    dyoung }
    431   1.1    dyoung 
    432   1.1    dyoung /**
    433   1.1    dyoung  *  ixgbe_get_phy_id - Get the phy type
    434   1.1    dyoung  *  @hw: pointer to hardware structure
    435   1.1    dyoung  *
    436   1.1    dyoung  **/
    437   1.1    dyoung s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
    438   1.1    dyoung {
    439   1.1    dyoung 	u32 status;
    440   1.1    dyoung 	u16 phy_id_high = 0;
    441   1.1    dyoung 	u16 phy_id_low = 0;
    442   1.1    dyoung 
    443   1.1    dyoung 	DEBUGFUNC("ixgbe_get_phy_id");
    444   1.1    dyoung 
    445   1.1    dyoung 	status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
    446   1.3   msaitoh 				      IXGBE_MDIO_PMA_PMD_DEV_TYPE,
    447   1.3   msaitoh 				      &phy_id_high);
    448   1.1    dyoung 
    449   1.1    dyoung 	if (status == IXGBE_SUCCESS) {
    450   1.1    dyoung 		hw->phy.id = (u32)(phy_id_high << 16);
    451   1.1    dyoung 		status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_LOW,
    452   1.3   msaitoh 					      IXGBE_MDIO_PMA_PMD_DEV_TYPE,
    453   1.3   msaitoh 					      &phy_id_low);
    454   1.1    dyoung 		hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
    455   1.1    dyoung 		hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
    456   1.1    dyoung 	}
    457  1.12   msaitoh 	DEBUGOUT2("PHY_ID_HIGH 0x%04X, PHY_ID_LOW 0x%04X\n",
    458  1.12   msaitoh 		  phy_id_high, phy_id_low);
    459  1.12   msaitoh 
    460   1.1    dyoung 	return status;
    461   1.1    dyoung }
    462   1.1    dyoung 
    463   1.1    dyoung /**
    464   1.1    dyoung  *  ixgbe_get_phy_type_from_id - Get the phy type
    465  1.12   msaitoh  *  @phy_id: PHY ID information
    466   1.1    dyoung  *
    467   1.1    dyoung  **/
    468   1.1    dyoung enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
    469   1.1    dyoung {
    470   1.1    dyoung 	enum ixgbe_phy_type phy_type;
    471   1.1    dyoung 
    472   1.1    dyoung 	DEBUGFUNC("ixgbe_get_phy_type_from_id");
    473   1.1    dyoung 
    474   1.1    dyoung 	switch (phy_id) {
    475   1.1    dyoung 	case TN1010_PHY_ID:
    476   1.1    dyoung 		phy_type = ixgbe_phy_tn;
    477   1.1    dyoung 		break;
    478   1.9   msaitoh 	case X550_PHY_ID2:
    479   1.9   msaitoh 	case X550_PHY_ID3:
    480   1.3   msaitoh 	case X540_PHY_ID:
    481   1.1    dyoung 		phy_type = ixgbe_phy_aq;
    482   1.1    dyoung 		break;
    483   1.1    dyoung 	case QT2022_PHY_ID:
    484   1.1    dyoung 		phy_type = ixgbe_phy_qt;
    485   1.1    dyoung 		break;
    486   1.1    dyoung 	case ATH_PHY_ID:
    487   1.1    dyoung 		phy_type = ixgbe_phy_nl;
    488   1.1    dyoung 		break;
    489   1.7   msaitoh 	case X557_PHY_ID:
    490  1.12   msaitoh 	case X557_PHY_ID2:
    491   1.7   msaitoh 		phy_type = ixgbe_phy_x550em_ext_t;
    492   1.7   msaitoh 		break;
    493  1.12   msaitoh 	case IXGBE_M88E1500_E_PHY_ID:
    494  1.12   msaitoh 	case IXGBE_M88E1543_E_PHY_ID:
    495  1.12   msaitoh 		phy_type = ixgbe_phy_ext_1g_t;
    496  1.12   msaitoh 		break;
    497   1.1    dyoung 	default:
    498   1.1    dyoung 		phy_type = ixgbe_phy_unknown;
    499   1.1    dyoung 		break;
    500   1.1    dyoung 	}
    501   1.1    dyoung 	return phy_type;
    502   1.1    dyoung }
    503   1.1    dyoung 
    504   1.1    dyoung /**
    505   1.1    dyoung  *  ixgbe_reset_phy_generic - Performs a PHY reset
    506   1.1    dyoung  *  @hw: pointer to hardware structure
    507   1.1    dyoung  **/
    508   1.1    dyoung s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
    509   1.1    dyoung {
    510   1.1    dyoung 	u32 i;
    511   1.1    dyoung 	u16 ctrl = 0;
    512   1.1    dyoung 	s32 status = IXGBE_SUCCESS;
    513   1.1    dyoung 
    514   1.1    dyoung 	DEBUGFUNC("ixgbe_reset_phy_generic");
    515   1.1    dyoung 
    516   1.1    dyoung 	if (hw->phy.type == ixgbe_phy_unknown)
    517   1.1    dyoung 		status = ixgbe_identify_phy_generic(hw);
    518   1.1    dyoung 
    519   1.1    dyoung 	if (status != IXGBE_SUCCESS || hw->phy.type == ixgbe_phy_none)
    520   1.1    dyoung 		goto out;
    521   1.1    dyoung 
    522   1.1    dyoung 	/* Don't reset PHY if it's shut down due to overtemp. */
    523   1.1    dyoung 	if (!hw->phy.reset_if_overtemp &&
    524   1.1    dyoung 	    (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
    525   1.1    dyoung 		goto out;
    526   1.1    dyoung 
    527   1.7   msaitoh 	/* Blocked by MNG FW so bail */
    528   1.7   msaitoh 	if (ixgbe_check_reset_blocked(hw))
    529   1.7   msaitoh 		goto out;
    530   1.7   msaitoh 
    531   1.1    dyoung 	/*
    532   1.1    dyoung 	 * Perform soft PHY reset to the PHY_XS.
    533   1.1    dyoung 	 * This will cause a soft reset to the PHY
    534   1.1    dyoung 	 */
    535   1.1    dyoung 	hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
    536   1.3   msaitoh 			      IXGBE_MDIO_PHY_XS_DEV_TYPE,
    537   1.3   msaitoh 			      IXGBE_MDIO_PHY_XS_RESET);
    538   1.1    dyoung 
    539   1.1    dyoung 	/*
    540   1.1    dyoung 	 * Poll for reset bit to self-clear indicating reset is complete.
    541   1.1    dyoung 	 * Some PHYs could take up to 3 seconds to complete and need about
    542   1.1    dyoung 	 * 1.7 usec delay after the reset is complete.
    543   1.1    dyoung 	 */
    544   1.1    dyoung 	for (i = 0; i < 30; i++) {
    545   1.1    dyoung 		msec_delay(100);
    546  1.12   msaitoh 		if (hw->phy.type == ixgbe_phy_x550em_ext_t) {
    547  1.12   msaitoh 			status = hw->phy.ops.read_reg(hw,
    548  1.12   msaitoh 						  IXGBE_MDIO_TX_VENDOR_ALARMS_3,
    549  1.12   msaitoh 						  IXGBE_MDIO_PMA_PMD_DEV_TYPE,
    550  1.12   msaitoh 						  &ctrl);
    551  1.12   msaitoh 			if (status != IXGBE_SUCCESS)
    552  1.12   msaitoh 				return status;
    553  1.12   msaitoh 
    554  1.12   msaitoh 			if (ctrl & IXGBE_MDIO_TX_VENDOR_ALARMS_3_RST_MASK) {
    555  1.12   msaitoh 				usec_delay(2);
    556  1.12   msaitoh 				break;
    557  1.12   msaitoh 			}
    558  1.12   msaitoh 		} else {
    559  1.12   msaitoh 			status = hw->phy.ops.read_reg(hw,
    560  1.12   msaitoh 						     IXGBE_MDIO_PHY_XS_CONTROL,
    561  1.12   msaitoh 						     IXGBE_MDIO_PHY_XS_DEV_TYPE,
    562  1.12   msaitoh 						     &ctrl);
    563  1.12   msaitoh 			if (status != IXGBE_SUCCESS)
    564  1.12   msaitoh 				return status;
    565  1.12   msaitoh 
    566  1.12   msaitoh 			if (!(ctrl & IXGBE_MDIO_PHY_XS_RESET)) {
    567  1.12   msaitoh 				usec_delay(2);
    568  1.12   msaitoh 				break;
    569  1.12   msaitoh 			}
    570   1.1    dyoung 		}
    571   1.1    dyoung 	}
    572   1.1    dyoung 
    573   1.1    dyoung 	if (ctrl & IXGBE_MDIO_PHY_XS_RESET) {
    574   1.1    dyoung 		status = IXGBE_ERR_RESET_FAILED;
    575   1.6   msaitoh 		ERROR_REPORT1(IXGBE_ERROR_POLLING,
    576   1.6   msaitoh 			     "PHY reset polling failed to complete.\n");
    577   1.1    dyoung 	}
    578   1.1    dyoung 
    579   1.1    dyoung out:
    580   1.1    dyoung 	return status;
    581   1.1    dyoung }
    582   1.1    dyoung 
    583   1.1    dyoung /**
    584   1.6   msaitoh  *  ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
    585   1.6   msaitoh  *  the SWFW lock
    586   1.6   msaitoh  *  @hw: pointer to hardware structure
    587   1.6   msaitoh  *  @reg_addr: 32 bit address of PHY register to read
    588  1.17   msaitoh  *  @device_type: 5 bit device type
    589   1.6   msaitoh  *  @phy_data: Pointer to read data from PHY register
    590   1.6   msaitoh  **/
    591   1.6   msaitoh s32 ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
    592  1.12   msaitoh 			   u16 *phy_data)
    593   1.6   msaitoh {
    594   1.6   msaitoh 	u32 i, data, command;
    595   1.6   msaitoh 
    596   1.6   msaitoh 	/* Setup and write the address cycle command */
    597   1.6   msaitoh 	command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT)  |
    598   1.6   msaitoh 		   (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
    599   1.6   msaitoh 		   (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
    600   1.6   msaitoh 		   (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
    601   1.6   msaitoh 
    602   1.6   msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
    603   1.6   msaitoh 
    604   1.6   msaitoh 	/*
    605   1.6   msaitoh 	 * Check every 10 usec to see if the address cycle completed.
    606   1.6   msaitoh 	 * The MDI Command bit will clear when the operation is
    607   1.6   msaitoh 	 * complete
    608   1.6   msaitoh 	 */
    609   1.6   msaitoh 	for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
    610   1.6   msaitoh 		usec_delay(10);
    611   1.6   msaitoh 
    612   1.6   msaitoh 		command = IXGBE_READ_REG(hw, IXGBE_MSCA);
    613   1.6   msaitoh 		if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
    614  1.12   msaitoh 			break;
    615   1.6   msaitoh 	}
    616   1.6   msaitoh 
    617   1.6   msaitoh 
    618   1.6   msaitoh 	if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
    619   1.6   msaitoh 		ERROR_REPORT1(IXGBE_ERROR_POLLING, "PHY address command did not complete.\n");
    620  1.12   msaitoh 		DEBUGOUT("PHY address command did not complete, returning IXGBE_ERR_PHY\n");
    621   1.6   msaitoh 		return IXGBE_ERR_PHY;
    622   1.6   msaitoh 	}
    623   1.6   msaitoh 
    624   1.6   msaitoh 	/*
    625   1.6   msaitoh 	 * Address cycle complete, setup and write the read
    626   1.6   msaitoh 	 * command
    627   1.6   msaitoh 	 */
    628   1.6   msaitoh 	command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT)  |
    629   1.6   msaitoh 		   (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
    630   1.6   msaitoh 		   (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
    631   1.6   msaitoh 		   (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
    632   1.6   msaitoh 
    633   1.6   msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
    634   1.6   msaitoh 
    635   1.6   msaitoh 	/*
    636   1.6   msaitoh 	 * Check every 10 usec to see if the address cycle
    637   1.6   msaitoh 	 * completed. The MDI Command bit will clear when the
    638   1.6   msaitoh 	 * operation is complete
    639   1.6   msaitoh 	 */
    640   1.6   msaitoh 	for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
    641   1.6   msaitoh 		usec_delay(10);
    642   1.6   msaitoh 
    643   1.6   msaitoh 		command = IXGBE_READ_REG(hw, IXGBE_MSCA);
    644   1.6   msaitoh 		if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
    645   1.6   msaitoh 			break;
    646   1.6   msaitoh 	}
    647   1.6   msaitoh 
    648   1.6   msaitoh 	if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
    649   1.6   msaitoh 		ERROR_REPORT1(IXGBE_ERROR_POLLING, "PHY read command didn't complete\n");
    650  1.12   msaitoh 		DEBUGOUT("PHY read command didn't complete, returning IXGBE_ERR_PHY\n");
    651   1.6   msaitoh 		return IXGBE_ERR_PHY;
    652   1.6   msaitoh 	}
    653   1.6   msaitoh 
    654   1.6   msaitoh 	/*
    655   1.6   msaitoh 	 * Read operation is complete.  Get the data
    656   1.6   msaitoh 	 * from MSRWD
    657   1.6   msaitoh 	 */
    658   1.6   msaitoh 	data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
    659   1.6   msaitoh 	data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
    660   1.6   msaitoh 	*phy_data = (u16)(data);
    661   1.6   msaitoh 
    662   1.6   msaitoh 	return IXGBE_SUCCESS;
    663   1.6   msaitoh }
    664   1.6   msaitoh 
    665   1.6   msaitoh /**
    666   1.1    dyoung  *  ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
    667   1.6   msaitoh  *  using the SWFW lock - this function is needed in most cases
    668   1.1    dyoung  *  @hw: pointer to hardware structure
    669   1.1    dyoung  *  @reg_addr: 32 bit address of PHY register to read
    670  1.17   msaitoh  *  @device_type: 5 bit device type
    671   1.1    dyoung  *  @phy_data: Pointer to read data from PHY register
    672   1.1    dyoung  **/
    673   1.1    dyoung s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
    674   1.3   msaitoh 			       u32 device_type, u16 *phy_data)
    675   1.1    dyoung {
    676   1.6   msaitoh 	s32 status;
    677   1.7   msaitoh 	u32 gssr = hw->phy.phy_semaphore_mask;
    678   1.1    dyoung 
    679   1.1    dyoung 	DEBUGFUNC("ixgbe_read_phy_reg_generic");
    680   1.1    dyoung 
    681  1.12   msaitoh 	if (hw->mac.ops.acquire_swfw_sync(hw, gssr))
    682  1.12   msaitoh 		return IXGBE_ERR_SWFW_SYNC;
    683  1.12   msaitoh 
    684  1.12   msaitoh 	status = hw->phy.ops.read_reg_mdi(hw, reg_addr, device_type, phy_data);
    685  1.12   msaitoh 
    686  1.12   msaitoh 	hw->mac.ops.release_swfw_sync(hw, gssr);
    687   1.6   msaitoh 
    688   1.6   msaitoh 	return status;
    689   1.6   msaitoh }
    690   1.6   msaitoh 
    691   1.6   msaitoh /**
    692   1.6   msaitoh  *  ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
    693   1.6   msaitoh  *  without SWFW lock
    694   1.6   msaitoh  *  @hw: pointer to hardware structure
    695   1.6   msaitoh  *  @reg_addr: 32 bit PHY register to write
    696   1.6   msaitoh  *  @device_type: 5 bit device type
    697   1.6   msaitoh  *  @phy_data: Data to write to the PHY register
    698   1.6   msaitoh  **/
    699   1.6   msaitoh s32 ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr,
    700   1.6   msaitoh 				u32 device_type, u16 phy_data)
    701   1.6   msaitoh {
    702   1.6   msaitoh 	u32 i, command;
    703   1.1    dyoung 
    704   1.6   msaitoh 	/* Put the data in the MDI single read and write data register*/
    705   1.6   msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
    706   1.1    dyoung 
    707   1.6   msaitoh 	/* Setup and write the address cycle command */
    708   1.6   msaitoh 	command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT)  |
    709   1.6   msaitoh 		   (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
    710   1.6   msaitoh 		   (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
    711   1.6   msaitoh 		   (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
    712   1.1    dyoung 
    713   1.6   msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
    714   1.1    dyoung 
    715   1.6   msaitoh 	/*
    716   1.6   msaitoh 	 * Check every 10 usec to see if the address cycle completed.
    717   1.6   msaitoh 	 * The MDI Command bit will clear when the operation is
    718   1.6   msaitoh 	 * complete
    719   1.6   msaitoh 	 */
    720   1.6   msaitoh 	for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
    721   1.6   msaitoh 		usec_delay(10);
    722   1.1    dyoung 
    723   1.6   msaitoh 		command = IXGBE_READ_REG(hw, IXGBE_MSCA);
    724   1.6   msaitoh 		if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
    725   1.6   msaitoh 			break;
    726   1.6   msaitoh 	}
    727   1.1    dyoung 
    728   1.6   msaitoh 	if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
    729   1.6   msaitoh 		ERROR_REPORT1(IXGBE_ERROR_POLLING, "PHY address cmd didn't complete\n");
    730   1.6   msaitoh 		return IXGBE_ERR_PHY;
    731   1.6   msaitoh 	}
    732   1.1    dyoung 
    733   1.6   msaitoh 	/*
    734   1.6   msaitoh 	 * Address cycle complete, setup and write the write
    735   1.6   msaitoh 	 * command
    736   1.6   msaitoh 	 */
    737   1.6   msaitoh 	command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT)  |
    738   1.6   msaitoh 		   (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
    739   1.6   msaitoh 		   (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
    740   1.6   msaitoh 		   (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
    741   1.1    dyoung 
    742   1.6   msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
    743   1.1    dyoung 
    744   1.6   msaitoh 	/*
    745   1.6   msaitoh 	 * Check every 10 usec to see if the address cycle
    746   1.6   msaitoh 	 * completed. The MDI Command bit will clear when the
    747   1.6   msaitoh 	 * operation is complete
    748   1.6   msaitoh 	 */
    749   1.6   msaitoh 	for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
    750   1.6   msaitoh 		usec_delay(10);
    751   1.1    dyoung 
    752   1.6   msaitoh 		command = IXGBE_READ_REG(hw, IXGBE_MSCA);
    753   1.6   msaitoh 		if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
    754   1.6   msaitoh 			break;
    755   1.6   msaitoh 	}
    756   1.1    dyoung 
    757   1.6   msaitoh 	if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
    758   1.6   msaitoh 		ERROR_REPORT1(IXGBE_ERROR_POLLING, "PHY write cmd didn't complete\n");
    759   1.6   msaitoh 		return IXGBE_ERR_PHY;
    760   1.1    dyoung 	}
    761   1.1    dyoung 
    762   1.6   msaitoh 	return IXGBE_SUCCESS;
    763   1.1    dyoung }
    764   1.1    dyoung 
    765   1.1    dyoung /**
    766   1.1    dyoung  *  ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
    767   1.6   msaitoh  *  using SWFW lock- this function is needed in most cases
    768   1.1    dyoung  *  @hw: pointer to hardware structure
    769   1.1    dyoung  *  @reg_addr: 32 bit PHY register to write
    770   1.1    dyoung  *  @device_type: 5 bit device type
    771   1.1    dyoung  *  @phy_data: Data to write to the PHY register
    772   1.1    dyoung  **/
    773   1.1    dyoung s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
    774   1.3   msaitoh 				u32 device_type, u16 phy_data)
    775   1.1    dyoung {
    776   1.6   msaitoh 	s32 status;
    777   1.7   msaitoh 	u32 gssr = hw->phy.phy_semaphore_mask;
    778   1.1    dyoung 
    779   1.1    dyoung 	DEBUGFUNC("ixgbe_write_phy_reg_generic");
    780   1.1    dyoung 
    781   1.6   msaitoh 	if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == IXGBE_SUCCESS) {
    782  1.12   msaitoh 		status = hw->phy.ops.write_reg_mdi(hw, reg_addr, device_type,
    783   1.6   msaitoh 						 phy_data);
    784   1.6   msaitoh 		hw->mac.ops.release_swfw_sync(hw, gssr);
    785   1.6   msaitoh 	} else {
    786   1.1    dyoung 		status = IXGBE_ERR_SWFW_SYNC;
    787   1.1    dyoung 	}
    788   1.1    dyoung 
    789   1.1    dyoung 	return status;
    790   1.1    dyoung }
    791   1.1    dyoung 
    792   1.1    dyoung /**
    793   1.7   msaitoh  *  ixgbe_setup_phy_link_generic - Set and restart auto-neg
    794   1.1    dyoung  *  @hw: pointer to hardware structure
    795   1.1    dyoung  *
    796   1.7   msaitoh  *  Restart auto-negotiation and PHY and waits for completion.
    797   1.1    dyoung  **/
    798   1.1    dyoung s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
    799   1.1    dyoung {
    800   1.1    dyoung 	s32 status = IXGBE_SUCCESS;
    801   1.1    dyoung 	u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
    802   1.1    dyoung 	bool autoneg = FALSE;
    803   1.1    dyoung 	ixgbe_link_speed speed;
    804   1.1    dyoung 
    805   1.1    dyoung 	DEBUGFUNC("ixgbe_setup_phy_link_generic");
    806   1.1    dyoung 
    807   1.1    dyoung 	ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
    808   1.1    dyoung 
    809  1.12   msaitoh 	/* Set or unset auto-negotiation 10G advertisement */
    810  1.12   msaitoh 	hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
    811  1.12   msaitoh 			     IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    812  1.12   msaitoh 			     &autoneg_reg);
    813  1.12   msaitoh 
    814  1.12   msaitoh 	autoneg_reg &= ~IXGBE_MII_10GBASE_T_ADVERTISE;
    815  1.12   msaitoh 	if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL) &&
    816  1.12   msaitoh 	    (speed & IXGBE_LINK_SPEED_10GB_FULL))
    817  1.12   msaitoh 		autoneg_reg |= IXGBE_MII_10GBASE_T_ADVERTISE;
    818  1.12   msaitoh 
    819  1.12   msaitoh 	hw->phy.ops.write_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
    820  1.12   msaitoh 			      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    821  1.12   msaitoh 			      autoneg_reg);
    822  1.12   msaitoh 
    823  1.12   msaitoh 	hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
    824  1.12   msaitoh 			     IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    825  1.12   msaitoh 			     &autoneg_reg);
    826   1.1    dyoung 
    827   1.7   msaitoh 	if (hw->mac.type == ixgbe_mac_X550) {
    828  1.12   msaitoh 		/* Set or unset auto-negotiation 5G advertisement */
    829  1.12   msaitoh 		autoneg_reg &= ~IXGBE_MII_5GBASE_T_ADVERTISE;
    830  1.12   msaitoh 		if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_5GB_FULL) &&
    831  1.12   msaitoh 		    (speed & IXGBE_LINK_SPEED_5GB_FULL))
    832  1.12   msaitoh 			autoneg_reg |= IXGBE_MII_5GBASE_T_ADVERTISE;
    833  1.12   msaitoh 
    834  1.12   msaitoh 		/* Set or unset auto-negotiation 2.5G advertisement */
    835  1.12   msaitoh 		autoneg_reg &= ~IXGBE_MII_2_5GBASE_T_ADVERTISE;
    836  1.12   msaitoh 		if ((hw->phy.autoneg_advertised &
    837  1.12   msaitoh 		     IXGBE_LINK_SPEED_2_5GB_FULL) &&
    838  1.12   msaitoh 		    (speed & IXGBE_LINK_SPEED_2_5GB_FULL))
    839  1.12   msaitoh 			autoneg_reg |= IXGBE_MII_2_5GBASE_T_ADVERTISE;
    840  1.12   msaitoh 	}
    841  1.12   msaitoh 
    842  1.12   msaitoh 	/* Set or unset auto-negotiation 1G advertisement */
    843  1.12   msaitoh 	autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
    844  1.12   msaitoh 	if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL) &&
    845  1.12   msaitoh 	    (speed & IXGBE_LINK_SPEED_1GB_FULL))
    846  1.12   msaitoh 		autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
    847  1.12   msaitoh 
    848  1.12   msaitoh 	hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
    849  1.12   msaitoh 			      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    850  1.12   msaitoh 			      autoneg_reg);
    851  1.12   msaitoh 
    852  1.12   msaitoh 	/* Set or unset auto-negotiation 100M advertisement */
    853  1.12   msaitoh 	hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
    854  1.12   msaitoh 			     IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    855  1.12   msaitoh 			     &autoneg_reg);
    856  1.12   msaitoh 
    857  1.12   msaitoh 	autoneg_reg &= ~(IXGBE_MII_100BASE_T_ADVERTISE |
    858  1.12   msaitoh 			 IXGBE_MII_100BASE_T_ADVERTISE_HALF);
    859  1.12   msaitoh 	if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL) &&
    860  1.12   msaitoh 	    (speed & IXGBE_LINK_SPEED_100_FULL))
    861  1.12   msaitoh 		autoneg_reg |= IXGBE_MII_100BASE_T_ADVERTISE;
    862  1.12   msaitoh 
    863  1.12   msaitoh 	hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
    864  1.12   msaitoh 			      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    865  1.12   msaitoh 			      autoneg_reg);
    866   1.1    dyoung 
    867  1.13   msaitoh 	if (hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_100_FULL) {
    868  1.13   msaitoh 		u16 ctrl;
    869  1.13   msaitoh 
    870  1.13   msaitoh 		/* Force 100Mbps */
    871  1.13   msaitoh 		hw->phy.ops.read_reg(hw, MDIO_PMAPMD_CTRL1, MDIO_MMD_PMAPMD,
    872  1.13   msaitoh 		    &ctrl);
    873  1.13   msaitoh 		ctrl &= ~PMAPMD_CTRL1_SPEED_MASK;
    874  1.13   msaitoh 		ctrl |= PMAPMD_CTRL1_SPEED_100;
    875  1.13   msaitoh 		hw->phy.ops.write_reg(hw, MDIO_PMAPMD_CTRL1,MDIO_MMD_PMAPMD,
    876  1.13   msaitoh 		    ctrl);
    877   1.7   msaitoh 
    878  1.13   msaitoh 		/* Don't use auto-nego for 100Mbps */
    879  1.13   msaitoh 		hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
    880   1.3   msaitoh 			     IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
    881   1.1    dyoung 
    882  1.19   msaitoh 		autoneg_reg &= ~AN_CTRL1_AUTOEN;
    883   1.1    dyoung 
    884  1.13   msaitoh 		hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
    885   1.3   msaitoh 			      IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
    886  1.13   msaitoh 	} else {
    887  1.13   msaitoh 		/* Blocked by MNG FW so don't reset PHY */
    888  1.13   msaitoh 		if (ixgbe_check_reset_blocked(hw))
    889  1.13   msaitoh 			return status;
    890  1.13   msaitoh 
    891  1.13   msaitoh 		/* Restart PHY auto-negotiation. */
    892  1.13   msaitoh 		hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
    893  1.13   msaitoh 		    IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
    894  1.13   msaitoh 
    895  1.13   msaitoh 		autoneg_reg |= IXGBE_MII_RESTART | AN_CTRL1_AUTOEN;
    896  1.13   msaitoh 
    897  1.13   msaitoh 		hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
    898  1.13   msaitoh 		    IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
    899  1.13   msaitoh 	}
    900   1.1    dyoung 
    901   1.1    dyoung 	return status;
    902   1.1    dyoung }
    903   1.1    dyoung 
    904   1.1    dyoung /**
    905   1.1    dyoung  *  ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
    906   1.1    dyoung  *  @hw: pointer to hardware structure
    907   1.1    dyoung  *  @speed: new link speed
    908  1.17   msaitoh  *  @autoneg_wait_to_complete: unused
    909   1.1    dyoung  **/
    910   1.1    dyoung s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
    911   1.3   msaitoh 				       ixgbe_link_speed speed,
    912   1.3   msaitoh 				       bool autoneg_wait_to_complete)
    913   1.1    dyoung {
    914   1.5   msaitoh 	UNREFERENCED_1PARAMETER(autoneg_wait_to_complete);
    915   1.1    dyoung 
    916   1.1    dyoung 	DEBUGFUNC("ixgbe_setup_phy_link_speed_generic");
    917   1.1    dyoung 
    918   1.1    dyoung 	/*
    919   1.1    dyoung 	 * Clear autoneg_advertised and set new values based on input link
    920   1.1    dyoung 	 * speed.
    921   1.1    dyoung 	 */
    922   1.1    dyoung 	hw->phy.autoneg_advertised = 0;
    923   1.1    dyoung 
    924   1.1    dyoung 	if (speed & IXGBE_LINK_SPEED_10GB_FULL)
    925   1.1    dyoung 		hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
    926   1.1    dyoung 
    927   1.7   msaitoh 	if (speed & IXGBE_LINK_SPEED_5GB_FULL)
    928   1.7   msaitoh 		hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_5GB_FULL;
    929   1.7   msaitoh 
    930   1.7   msaitoh 	if (speed & IXGBE_LINK_SPEED_2_5GB_FULL)
    931   1.7   msaitoh 		hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_2_5GB_FULL;
    932   1.7   msaitoh 
    933   1.1    dyoung 	if (speed & IXGBE_LINK_SPEED_1GB_FULL)
    934   1.1    dyoung 		hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
    935   1.1    dyoung 
    936   1.1    dyoung 	if (speed & IXGBE_LINK_SPEED_100_FULL)
    937   1.1    dyoung 		hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
    938   1.1    dyoung 
    939  1.12   msaitoh 	if (speed & IXGBE_LINK_SPEED_10_FULL)
    940  1.12   msaitoh 		hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10_FULL;
    941  1.12   msaitoh 
    942   1.1    dyoung 	/* Setup link based on the new speed settings */
    943   1.9   msaitoh 	ixgbe_setup_phy_link(hw);
    944   1.1    dyoung 
    945   1.1    dyoung 	return IXGBE_SUCCESS;
    946   1.1    dyoung }
    947   1.1    dyoung 
    948   1.1    dyoung /**
    949   1.9   msaitoh  * ixgbe_get_copper_speeds_supported - Get copper link speeds from phy
    950   1.9   msaitoh  * @hw: pointer to hardware structure
    951   1.9   msaitoh  *
    952   1.9   msaitoh  * Determines the supported link capabilities by reading the PHY auto
    953   1.9   msaitoh  * negotiation register.
    954   1.9   msaitoh  **/
    955   1.9   msaitoh static s32 ixgbe_get_copper_speeds_supported(struct ixgbe_hw *hw)
    956   1.9   msaitoh {
    957   1.9   msaitoh 	s32 status;
    958   1.9   msaitoh 	u16 speed_ability;
    959   1.9   msaitoh 
    960   1.9   msaitoh 	status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_SPEED_ABILITY,
    961   1.9   msaitoh 				      IXGBE_MDIO_PMA_PMD_DEV_TYPE,
    962   1.9   msaitoh 				      &speed_ability);
    963   1.9   msaitoh 	if (status)
    964   1.9   msaitoh 		return status;
    965   1.9   msaitoh 
    966   1.9   msaitoh 	if (speed_ability & IXGBE_MDIO_PHY_SPEED_10G)
    967   1.9   msaitoh 		hw->phy.speeds_supported |= IXGBE_LINK_SPEED_10GB_FULL;
    968   1.9   msaitoh 	if (speed_ability & IXGBE_MDIO_PHY_SPEED_1G)
    969   1.9   msaitoh 		hw->phy.speeds_supported |= IXGBE_LINK_SPEED_1GB_FULL;
    970   1.9   msaitoh 	if (speed_ability & IXGBE_MDIO_PHY_SPEED_100M)
    971   1.9   msaitoh 		hw->phy.speeds_supported |= IXGBE_LINK_SPEED_100_FULL;
    972   1.9   msaitoh 
    973   1.9   msaitoh 	switch (hw->mac.type) {
    974   1.9   msaitoh 	case ixgbe_mac_X550:
    975   1.9   msaitoh 		hw->phy.speeds_supported |= IXGBE_LINK_SPEED_2_5GB_FULL;
    976   1.9   msaitoh 		hw->phy.speeds_supported |= IXGBE_LINK_SPEED_5GB_FULL;
    977   1.9   msaitoh 		break;
    978   1.9   msaitoh 	case ixgbe_mac_X550EM_x:
    979  1.12   msaitoh 	case ixgbe_mac_X550EM_a:
    980   1.9   msaitoh 		hw->phy.speeds_supported &= ~IXGBE_LINK_SPEED_100_FULL;
    981   1.9   msaitoh 		break;
    982   1.9   msaitoh 	default:
    983   1.9   msaitoh 		break;
    984   1.9   msaitoh 	}
    985   1.9   msaitoh 
    986   1.9   msaitoh 	return status;
    987   1.9   msaitoh }
    988   1.9   msaitoh 
    989   1.9   msaitoh /**
    990   1.1    dyoung  *  ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
    991   1.1    dyoung  *  @hw: pointer to hardware structure
    992   1.1    dyoung  *  @speed: pointer to link speed
    993   1.1    dyoung  *  @autoneg: boolean auto-negotiation value
    994   1.1    dyoung  **/
    995   1.1    dyoung s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
    996   1.3   msaitoh 					       ixgbe_link_speed *speed,
    997   1.3   msaitoh 					       bool *autoneg)
    998   1.1    dyoung {
    999   1.9   msaitoh 	s32 status = IXGBE_SUCCESS;
   1000   1.1    dyoung 
   1001   1.1    dyoung 	DEBUGFUNC("ixgbe_get_copper_link_capabilities_generic");
   1002   1.1    dyoung 
   1003   1.1    dyoung 	*autoneg = TRUE;
   1004   1.9   msaitoh 	if (!hw->phy.speeds_supported)
   1005   1.9   msaitoh 		status = ixgbe_get_copper_speeds_supported(hw);
   1006   1.1    dyoung 
   1007   1.9   msaitoh 	*speed = hw->phy.speeds_supported;
   1008   1.1    dyoung 	return status;
   1009   1.1    dyoung }
   1010   1.1    dyoung 
   1011   1.1    dyoung /**
   1012   1.1    dyoung  *  ixgbe_check_phy_link_tnx - Determine link and speed status
   1013   1.1    dyoung  *  @hw: pointer to hardware structure
   1014  1.17   msaitoh  *  @speed: current link speed
   1015  1.17   msaitoh  *  @link_up: TRUE is link is up, FALSE otherwise
   1016   1.1    dyoung  *
   1017   1.1    dyoung  *  Reads the VS1 register to determine if link is up and the current speed for
   1018   1.1    dyoung  *  the PHY.
   1019   1.1    dyoung  **/
   1020   1.1    dyoung s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
   1021   1.3   msaitoh 			     bool *link_up)
   1022   1.1    dyoung {
   1023   1.1    dyoung 	s32 status = IXGBE_SUCCESS;
   1024   1.1    dyoung 	u32 time_out;
   1025   1.1    dyoung 	u32 max_time_out = 10;
   1026   1.1    dyoung 	u16 phy_link = 0;
   1027   1.1    dyoung 	u16 phy_speed = 0;
   1028   1.1    dyoung 	u16 phy_data = 0;
   1029   1.1    dyoung 
   1030   1.1    dyoung 	DEBUGFUNC("ixgbe_check_phy_link_tnx");
   1031   1.1    dyoung 
   1032   1.1    dyoung 	/* Initialize speed and link to default case */
   1033   1.1    dyoung 	*link_up = FALSE;
   1034   1.1    dyoung 	*speed = IXGBE_LINK_SPEED_10GB_FULL;
   1035   1.1    dyoung 
   1036   1.1    dyoung 	/*
   1037   1.1    dyoung 	 * Check current speed and link status of the PHY register.
   1038   1.1    dyoung 	 * This is a vendor specific register and may have to
   1039   1.1    dyoung 	 * be changed for other copper PHYs.
   1040   1.1    dyoung 	 */
   1041   1.1    dyoung 	for (time_out = 0; time_out < max_time_out; time_out++) {
   1042   1.1    dyoung 		usec_delay(10);
   1043   1.1    dyoung 		status = hw->phy.ops.read_reg(hw,
   1044   1.3   msaitoh 					IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
   1045   1.3   msaitoh 					IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   1046   1.3   msaitoh 					&phy_data);
   1047   1.3   msaitoh 		phy_link = phy_data & IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
   1048   1.1    dyoung 		phy_speed = phy_data &
   1049   1.3   msaitoh 				 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
   1050   1.1    dyoung 		if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
   1051   1.1    dyoung 			*link_up = TRUE;
   1052   1.1    dyoung 			if (phy_speed ==
   1053   1.1    dyoung 			    IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
   1054   1.1    dyoung 				*speed = IXGBE_LINK_SPEED_1GB_FULL;
   1055   1.1    dyoung 			break;
   1056   1.1    dyoung 		}
   1057   1.1    dyoung 	}
   1058   1.1    dyoung 
   1059   1.1    dyoung 	return status;
   1060   1.1    dyoung }
   1061   1.1    dyoung 
   1062   1.1    dyoung /**
   1063   1.7   msaitoh  *	ixgbe_setup_phy_link_tnx - Set and restart auto-neg
   1064   1.1    dyoung  *	@hw: pointer to hardware structure
   1065   1.1    dyoung  *
   1066   1.7   msaitoh  *	Restart auto-negotiation and PHY and waits for completion.
   1067   1.1    dyoung  **/
   1068   1.1    dyoung s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
   1069   1.1    dyoung {
   1070   1.1    dyoung 	s32 status = IXGBE_SUCCESS;
   1071   1.1    dyoung 	u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
   1072   1.1    dyoung 	bool autoneg = FALSE;
   1073   1.1    dyoung 	ixgbe_link_speed speed;
   1074   1.1    dyoung 
   1075   1.1    dyoung 	DEBUGFUNC("ixgbe_setup_phy_link_tnx");
   1076   1.1    dyoung 
   1077   1.1    dyoung 	ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
   1078   1.1    dyoung 
   1079   1.1    dyoung 	if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
   1080   1.1    dyoung 		/* Set or unset auto-negotiation 10G advertisement */
   1081   1.1    dyoung 		hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
   1082   1.3   msaitoh 				     IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
   1083   1.3   msaitoh 				     &autoneg_reg);
   1084   1.1    dyoung 
   1085   1.1    dyoung 		autoneg_reg &= ~IXGBE_MII_10GBASE_T_ADVERTISE;
   1086   1.1    dyoung 		if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
   1087   1.1    dyoung 			autoneg_reg |= IXGBE_MII_10GBASE_T_ADVERTISE;
   1088   1.1    dyoung 
   1089   1.1    dyoung 		hw->phy.ops.write_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
   1090   1.3   msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
   1091   1.3   msaitoh 				      autoneg_reg);
   1092   1.1    dyoung 	}
   1093   1.1    dyoung 
   1094   1.1    dyoung 	if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
   1095   1.1    dyoung 		/* Set or unset auto-negotiation 1G advertisement */
   1096   1.1    dyoung 		hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
   1097   1.3   msaitoh 				     IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
   1098   1.3   msaitoh 				     &autoneg_reg);
   1099   1.1    dyoung 
   1100   1.1    dyoung 		autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
   1101   1.1    dyoung 		if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
   1102   1.1    dyoung 			autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
   1103   1.1    dyoung 
   1104   1.1    dyoung 		hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
   1105   1.3   msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
   1106   1.3   msaitoh 				      autoneg_reg);
   1107   1.1    dyoung 	}
   1108   1.1    dyoung 
   1109   1.1    dyoung 	if (speed & IXGBE_LINK_SPEED_100_FULL) {
   1110   1.1    dyoung 		/* Set or unset auto-negotiation 100M advertisement */
   1111   1.1    dyoung 		hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
   1112   1.3   msaitoh 				     IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
   1113   1.3   msaitoh 				     &autoneg_reg);
   1114   1.1    dyoung 
   1115   1.1    dyoung 		autoneg_reg &= ~IXGBE_MII_100BASE_T_ADVERTISE;
   1116   1.1    dyoung 		if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
   1117   1.1    dyoung 			autoneg_reg |= IXGBE_MII_100BASE_T_ADVERTISE;
   1118   1.1    dyoung 
   1119   1.1    dyoung 		hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
   1120   1.3   msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
   1121   1.3   msaitoh 				      autoneg_reg);
   1122   1.1    dyoung 	}
   1123   1.1    dyoung 
   1124   1.7   msaitoh 	/* Blocked by MNG FW so don't reset PHY */
   1125   1.7   msaitoh 	if (ixgbe_check_reset_blocked(hw))
   1126   1.7   msaitoh 		return status;
   1127   1.7   msaitoh 
   1128   1.7   msaitoh 	/* Restart PHY auto-negotiation. */
   1129   1.1    dyoung 	hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
   1130   1.3   msaitoh 			     IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
   1131   1.1    dyoung 
   1132   1.1    dyoung 	autoneg_reg |= IXGBE_MII_RESTART;
   1133   1.1    dyoung 
   1134   1.1    dyoung 	hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
   1135   1.3   msaitoh 			      IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
   1136   1.1    dyoung 
   1137   1.1    dyoung 	return status;
   1138   1.1    dyoung }
   1139   1.1    dyoung 
   1140   1.1    dyoung /**
   1141   1.1    dyoung  *  ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
   1142   1.1    dyoung  *  @hw: pointer to hardware structure
   1143   1.1    dyoung  *  @firmware_version: pointer to the PHY Firmware Version
   1144   1.1    dyoung  **/
   1145   1.1    dyoung s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
   1146   1.3   msaitoh 				       u16 *firmware_version)
   1147   1.1    dyoung {
   1148   1.7   msaitoh 	s32 status;
   1149   1.1    dyoung 
   1150   1.1    dyoung 	DEBUGFUNC("ixgbe_get_phy_firmware_version_tnx");
   1151   1.1    dyoung 
   1152   1.1    dyoung 	status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
   1153   1.3   msaitoh 				      IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   1154   1.3   msaitoh 				      firmware_version);
   1155   1.1    dyoung 
   1156   1.1    dyoung 	return status;
   1157   1.1    dyoung }
   1158   1.1    dyoung 
   1159   1.1    dyoung /**
   1160   1.1    dyoung  *  ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
   1161   1.1    dyoung  *  @hw: pointer to hardware structure
   1162   1.1    dyoung  *  @firmware_version: pointer to the PHY Firmware Version
   1163   1.1    dyoung  **/
   1164   1.1    dyoung s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
   1165   1.3   msaitoh 					   u16 *firmware_version)
   1166   1.1    dyoung {
   1167   1.7   msaitoh 	s32 status;
   1168   1.1    dyoung 
   1169   1.1    dyoung 	DEBUGFUNC("ixgbe_get_phy_firmware_version_generic");
   1170   1.1    dyoung 
   1171   1.1    dyoung 	status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
   1172   1.3   msaitoh 				      IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   1173   1.3   msaitoh 				      firmware_version);
   1174   1.1    dyoung 
   1175   1.1    dyoung 	return status;
   1176   1.1    dyoung }
   1177   1.1    dyoung 
   1178   1.1    dyoung /**
   1179   1.1    dyoung  *  ixgbe_reset_phy_nl - Performs a PHY reset
   1180   1.1    dyoung  *  @hw: pointer to hardware structure
   1181   1.1    dyoung  **/
   1182   1.1    dyoung s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
   1183   1.1    dyoung {
   1184   1.1    dyoung 	u16 phy_offset, control, eword, edata, block_crc;
   1185   1.1    dyoung 	bool end_data = FALSE;
   1186   1.1    dyoung 	u16 list_offset, data_offset;
   1187   1.1    dyoung 	u16 phy_data = 0;
   1188   1.1    dyoung 	s32 ret_val = IXGBE_SUCCESS;
   1189   1.1    dyoung 	u32 i;
   1190   1.1    dyoung 
   1191   1.1    dyoung 	DEBUGFUNC("ixgbe_reset_phy_nl");
   1192   1.1    dyoung 
   1193   1.7   msaitoh 	/* Blocked by MNG FW so bail */
   1194   1.7   msaitoh 	if (ixgbe_check_reset_blocked(hw))
   1195   1.7   msaitoh 		goto out;
   1196   1.7   msaitoh 
   1197   1.1    dyoung 	hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
   1198   1.3   msaitoh 			     IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
   1199   1.1    dyoung 
   1200   1.1    dyoung 	/* reset the PHY and poll for completion */
   1201   1.1    dyoung 	hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
   1202   1.3   msaitoh 			      IXGBE_MDIO_PHY_XS_DEV_TYPE,
   1203   1.3   msaitoh 			      (phy_data | IXGBE_MDIO_PHY_XS_RESET));
   1204   1.1    dyoung 
   1205   1.1    dyoung 	for (i = 0; i < 100; i++) {
   1206   1.1    dyoung 		hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
   1207   1.3   msaitoh 				     IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
   1208   1.1    dyoung 		if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) == 0)
   1209   1.1    dyoung 			break;
   1210   1.1    dyoung 		msec_delay(10);
   1211   1.1    dyoung 	}
   1212   1.1    dyoung 
   1213   1.1    dyoung 	if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) != 0) {
   1214   1.1    dyoung 		DEBUGOUT("PHY reset did not complete.\n");
   1215   1.1    dyoung 		ret_val = IXGBE_ERR_PHY;
   1216   1.1    dyoung 		goto out;
   1217   1.1    dyoung 	}
   1218   1.1    dyoung 
   1219   1.1    dyoung 	/* Get init offsets */
   1220   1.1    dyoung 	ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
   1221   1.3   msaitoh 						      &data_offset);
   1222   1.1    dyoung 	if (ret_val != IXGBE_SUCCESS)
   1223   1.1    dyoung 		goto out;
   1224   1.1    dyoung 
   1225   1.1    dyoung 	ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
   1226   1.1    dyoung 	data_offset++;
   1227   1.1    dyoung 	while (!end_data) {
   1228   1.1    dyoung 		/*
   1229   1.1    dyoung 		 * Read control word from PHY init contents offset
   1230   1.1    dyoung 		 */
   1231   1.1    dyoung 		ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
   1232   1.6   msaitoh 		if (ret_val)
   1233   1.6   msaitoh 			goto err_eeprom;
   1234   1.1    dyoung 		control = (eword & IXGBE_CONTROL_MASK_NL) >>
   1235   1.3   msaitoh 			   IXGBE_CONTROL_SHIFT_NL;
   1236   1.1    dyoung 		edata = eword & IXGBE_DATA_MASK_NL;
   1237   1.1    dyoung 		switch (control) {
   1238   1.1    dyoung 		case IXGBE_DELAY_NL:
   1239   1.1    dyoung 			data_offset++;
   1240   1.1    dyoung 			DEBUGOUT1("DELAY: %d MS\n", edata);
   1241   1.1    dyoung 			msec_delay(edata);
   1242   1.1    dyoung 			break;
   1243   1.1    dyoung 		case IXGBE_DATA_NL:
   1244   1.3   msaitoh 			DEBUGOUT("DATA:\n");
   1245   1.1    dyoung 			data_offset++;
   1246   1.6   msaitoh 			ret_val = hw->eeprom.ops.read(hw, data_offset,
   1247   1.6   msaitoh 						      &phy_offset);
   1248   1.6   msaitoh 			if (ret_val)
   1249   1.6   msaitoh 				goto err_eeprom;
   1250   1.6   msaitoh 			data_offset++;
   1251   1.1    dyoung 			for (i = 0; i < edata; i++) {
   1252   1.6   msaitoh 				ret_val = hw->eeprom.ops.read(hw, data_offset,
   1253   1.6   msaitoh 							      &eword);
   1254   1.6   msaitoh 				if (ret_val)
   1255   1.6   msaitoh 					goto err_eeprom;
   1256   1.1    dyoung 				hw->phy.ops.write_reg(hw, phy_offset,
   1257   1.3   msaitoh 						      IXGBE_TWINAX_DEV, eword);
   1258   1.1    dyoung 				DEBUGOUT2("Wrote %4.4x to %4.4x\n", eword,
   1259   1.3   msaitoh 					  phy_offset);
   1260   1.1    dyoung 				data_offset++;
   1261   1.1    dyoung 				phy_offset++;
   1262   1.1    dyoung 			}
   1263   1.1    dyoung 			break;
   1264   1.1    dyoung 		case IXGBE_CONTROL_NL:
   1265   1.1    dyoung 			data_offset++;
   1266   1.3   msaitoh 			DEBUGOUT("CONTROL:\n");
   1267   1.1    dyoung 			if (edata == IXGBE_CONTROL_EOL_NL) {
   1268   1.1    dyoung 				DEBUGOUT("EOL\n");
   1269   1.1    dyoung 				end_data = TRUE;
   1270   1.1    dyoung 			} else if (edata == IXGBE_CONTROL_SOL_NL) {
   1271   1.1    dyoung 				DEBUGOUT("SOL\n");
   1272   1.1    dyoung 			} else {
   1273   1.1    dyoung 				DEBUGOUT("Bad control value\n");
   1274   1.1    dyoung 				ret_val = IXGBE_ERR_PHY;
   1275   1.1    dyoung 				goto out;
   1276   1.1    dyoung 			}
   1277   1.1    dyoung 			break;
   1278   1.1    dyoung 		default:
   1279   1.1    dyoung 			DEBUGOUT("Bad control type\n");
   1280   1.1    dyoung 			ret_val = IXGBE_ERR_PHY;
   1281   1.1    dyoung 			goto out;
   1282   1.1    dyoung 		}
   1283   1.1    dyoung 	}
   1284   1.1    dyoung 
   1285   1.1    dyoung out:
   1286   1.1    dyoung 	return ret_val;
   1287   1.6   msaitoh 
   1288   1.6   msaitoh err_eeprom:
   1289   1.6   msaitoh 	ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
   1290   1.6   msaitoh 		      "eeprom read at offset %d failed", data_offset);
   1291   1.6   msaitoh 	return IXGBE_ERR_PHY;
   1292   1.1    dyoung }
   1293   1.1    dyoung 
   1294  1.23   msaitoh /************************************************************************
   1295  1.23   msaitoh  * ixgbe_sfp_cage_full
   1296  1.23   msaitoh  *
   1297  1.23   msaitoh  *   Determine if an SFP+ module is inserted to the cage.
   1298  1.23   msaitoh  ************************************************************************/
   1299  1.23   msaitoh bool
   1300  1.23   msaitoh ixgbe_sfp_cage_full(struct ixgbe_hw *hw)
   1301  1.23   msaitoh {
   1302  1.23   msaitoh 	uint32_t mask;
   1303  1.23   msaitoh 	int rv;
   1304  1.23   msaitoh 
   1305  1.23   msaitoh 	KASSERT(hw->mac.type != ixgbe_mac_82598EB);
   1306  1.23   msaitoh 
   1307  1.23   msaitoh 	if (hw->mac.type >= ixgbe_mac_X540)
   1308  1.23   msaitoh 		mask = IXGBE_ESDP_SDP0;
   1309  1.23   msaitoh 	else
   1310  1.23   msaitoh 		mask = IXGBE_ESDP_SDP2;
   1311  1.23   msaitoh 
   1312  1.23   msaitoh 	rv = IXGBE_READ_REG(hw, IXGBE_ESDP) & mask;
   1313  1.23   msaitoh 	if ((hw->quirks & IXGBE_QUIRK_MOD_ABS_INVERT) != 0)
   1314  1.23   msaitoh 		rv = !rv;
   1315  1.23   msaitoh 
   1316  1.23   msaitoh 	if (hw->mac.type == ixgbe_mac_X550EM_a) {
   1317  1.23   msaitoh 		/* X550EM_a's SDP0 is inverted than others. */
   1318  1.23   msaitoh 		return !rv;
   1319  1.23   msaitoh 	}
   1320  1.23   msaitoh 
   1321  1.23   msaitoh 	return rv;
   1322  1.23   msaitoh } /* ixgbe_sfp_cage_full */
   1323  1.23   msaitoh 
   1324   1.1    dyoung /**
   1325   1.3   msaitoh  *  ixgbe_identify_module_generic - Identifies module type
   1326   1.3   msaitoh  *  @hw: pointer to hardware structure
   1327   1.3   msaitoh  *
   1328   1.3   msaitoh  *  Determines HW type and calls appropriate function.
   1329   1.3   msaitoh  **/
   1330   1.3   msaitoh s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
   1331   1.3   msaitoh {
   1332   1.3   msaitoh 	s32 status = IXGBE_ERR_SFP_NOT_PRESENT;
   1333   1.3   msaitoh 
   1334   1.3   msaitoh 	DEBUGFUNC("ixgbe_identify_module_generic");
   1335   1.3   msaitoh 
   1336  1.23   msaitoh 	/* Lightweight way to check if the cage is not full. */
   1337  1.23   msaitoh 	if (hw->mac.type != ixgbe_mac_82598EB) {
   1338  1.23   msaitoh 		if (!ixgbe_sfp_cage_full(hw)) {
   1339  1.23   msaitoh 			hw->phy.sfp_type = ixgbe_sfp_type_not_present;
   1340  1.23   msaitoh 			return IXGBE_ERR_SFP_NOT_PRESENT;
   1341  1.23   msaitoh 		}
   1342  1.23   msaitoh 	}
   1343  1.23   msaitoh 
   1344   1.3   msaitoh 	switch (hw->mac.ops.get_media_type(hw)) {
   1345   1.3   msaitoh 	case ixgbe_media_type_fiber:
   1346   1.3   msaitoh 		status = ixgbe_identify_sfp_module_generic(hw);
   1347   1.3   msaitoh 		break;
   1348   1.3   msaitoh 
   1349   1.7   msaitoh 	case ixgbe_media_type_fiber_qsfp:
   1350   1.7   msaitoh 		status = ixgbe_identify_qsfp_module_generic(hw);
   1351   1.7   msaitoh 		break;
   1352   1.3   msaitoh 
   1353   1.3   msaitoh 	default:
   1354   1.3   msaitoh 		hw->phy.sfp_type = ixgbe_sfp_type_not_present;
   1355   1.3   msaitoh 		status = IXGBE_ERR_SFP_NOT_PRESENT;
   1356   1.3   msaitoh 		break;
   1357   1.3   msaitoh 	}
   1358   1.3   msaitoh 
   1359   1.3   msaitoh 	return status;
   1360   1.3   msaitoh }
   1361   1.3   msaitoh 
   1362   1.3   msaitoh /**
   1363   1.1    dyoung  *  ixgbe_identify_sfp_module_generic - Identifies SFP modules
   1364   1.1    dyoung  *  @hw: pointer to hardware structure
   1365   1.1    dyoung  *
   1366   1.1    dyoung  *  Searches for and identifies the SFP module and assigns appropriate PHY type.
   1367   1.1    dyoung  **/
   1368   1.1    dyoung s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
   1369   1.1    dyoung {
   1370   1.1    dyoung 	s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
   1371   1.1    dyoung 	u32 vendor_oui = 0;
   1372   1.1    dyoung 	enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
   1373   1.1    dyoung 	u8 identifier = 0;
   1374   1.1    dyoung 	u8 comp_codes_1g = 0;
   1375   1.1    dyoung 	u8 comp_codes_10g = 0;
   1376   1.1    dyoung 	u8 oui_bytes[3] = {0, 0, 0};
   1377   1.1    dyoung 	u8 cable_tech = 0;
   1378   1.1    dyoung 	u8 cable_spec = 0;
   1379   1.1    dyoung 	u16 enforce_sfp = 0;
   1380   1.1    dyoung 
   1381   1.1    dyoung 	DEBUGFUNC("ixgbe_identify_sfp_module_generic");
   1382   1.1    dyoung 
   1383   1.1    dyoung 	if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
   1384   1.1    dyoung 		hw->phy.sfp_type = ixgbe_sfp_type_not_present;
   1385   1.1    dyoung 		status = IXGBE_ERR_SFP_NOT_PRESENT;
   1386   1.1    dyoung 		goto out;
   1387   1.1    dyoung 	}
   1388   1.1    dyoung 
   1389   1.7   msaitoh 	/* LAN ID is needed for I2C access */
   1390   1.7   msaitoh 	hw->mac.ops.set_lan_id(hw);
   1391   1.7   msaitoh 
   1392   1.1    dyoung 	status = hw->phy.ops.read_i2c_eeprom(hw,
   1393   1.3   msaitoh 					     IXGBE_SFF_IDENTIFIER,
   1394   1.3   msaitoh 					     &identifier);
   1395   1.1    dyoung 
   1396   1.5   msaitoh 	if (status != IXGBE_SUCCESS)
   1397   1.1    dyoung 		goto err_read_i2c_eeprom;
   1398   1.1    dyoung 
   1399   1.1    dyoung 	if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
   1400  1.22   msaitoh 		if (hw->phy.type != ixgbe_phy_nl)
   1401  1.22   msaitoh 			hw->phy.type = ixgbe_phy_sfp_unsupported;
   1402   1.1    dyoung 		status = IXGBE_ERR_SFP_NOT_SUPPORTED;
   1403   1.1    dyoung 	} else {
   1404   1.1    dyoung 		status = hw->phy.ops.read_i2c_eeprom(hw,
   1405   1.3   msaitoh 						     IXGBE_SFF_1GBE_COMP_CODES,
   1406   1.3   msaitoh 						     &comp_codes_1g);
   1407   1.1    dyoung 
   1408   1.5   msaitoh 		if (status != IXGBE_SUCCESS)
   1409   1.1    dyoung 			goto err_read_i2c_eeprom;
   1410   1.1    dyoung 
   1411   1.1    dyoung 		status = hw->phy.ops.read_i2c_eeprom(hw,
   1412   1.3   msaitoh 						     IXGBE_SFF_10GBE_COMP_CODES,
   1413   1.3   msaitoh 						     &comp_codes_10g);
   1414   1.1    dyoung 
   1415   1.5   msaitoh 		if (status != IXGBE_SUCCESS)
   1416   1.1    dyoung 			goto err_read_i2c_eeprom;
   1417   1.1    dyoung 		status = hw->phy.ops.read_i2c_eeprom(hw,
   1418   1.3   msaitoh 						     IXGBE_SFF_CABLE_TECHNOLOGY,
   1419   1.3   msaitoh 						     &cable_tech);
   1420   1.1    dyoung 
   1421   1.5   msaitoh 		if (status != IXGBE_SUCCESS)
   1422   1.1    dyoung 			goto err_read_i2c_eeprom;
   1423   1.1    dyoung 
   1424   1.1    dyoung 		 /* ID Module
   1425   1.1    dyoung 		  * =========
   1426   1.1    dyoung 		  * 0   SFP_DA_CU
   1427   1.1    dyoung 		  * 1   SFP_SR
   1428   1.1    dyoung 		  * 2   SFP_LR
   1429   1.1    dyoung 		  * 3   SFP_DA_CORE0 - 82599-specific
   1430   1.1    dyoung 		  * 4   SFP_DA_CORE1 - 82599-specific
   1431   1.1    dyoung 		  * 5   SFP_SR/LR_CORE0 - 82599-specific
   1432   1.1    dyoung 		  * 6   SFP_SR/LR_CORE1 - 82599-specific
   1433   1.1    dyoung 		  * 7   SFP_act_lmt_DA_CORE0 - 82599-specific
   1434   1.1    dyoung 		  * 8   SFP_act_lmt_DA_CORE1 - 82599-specific
   1435   1.1    dyoung 		  * 9   SFP_1g_cu_CORE0 - 82599-specific
   1436   1.1    dyoung 		  * 10  SFP_1g_cu_CORE1 - 82599-specific
   1437   1.4   msaitoh 		  * 11  SFP_1g_sx_CORE0 - 82599-specific
   1438   1.4   msaitoh 		  * 12  SFP_1g_sx_CORE1 - 82599-specific
   1439   1.1    dyoung 		  */
   1440   1.1    dyoung 		if (hw->mac.type == ixgbe_mac_82598EB) {
   1441   1.1    dyoung 			if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
   1442   1.1    dyoung 				hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
   1443   1.1    dyoung 			else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
   1444   1.1    dyoung 				hw->phy.sfp_type = ixgbe_sfp_type_sr;
   1445   1.1    dyoung 			else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
   1446   1.1    dyoung 				hw->phy.sfp_type = ixgbe_sfp_type_lr;
   1447   1.1    dyoung 			else
   1448   1.1    dyoung 				hw->phy.sfp_type = ixgbe_sfp_type_unknown;
   1449   1.7   msaitoh 		} else {
   1450   1.1    dyoung 			if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
   1451   1.1    dyoung 				if (hw->bus.lan_id == 0)
   1452   1.1    dyoung 					hw->phy.sfp_type =
   1453   1.3   msaitoh 						     ixgbe_sfp_type_da_cu_core0;
   1454   1.1    dyoung 				else
   1455   1.1    dyoung 					hw->phy.sfp_type =
   1456   1.3   msaitoh 						     ixgbe_sfp_type_da_cu_core1;
   1457   1.1    dyoung 			} else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
   1458   1.1    dyoung 				hw->phy.ops.read_i2c_eeprom(
   1459   1.1    dyoung 						hw, IXGBE_SFF_CABLE_SPEC_COMP,
   1460   1.1    dyoung 						&cable_spec);
   1461   1.1    dyoung 				if (cable_spec &
   1462   1.1    dyoung 				    IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
   1463   1.1    dyoung 					if (hw->bus.lan_id == 0)
   1464   1.1    dyoung 						hw->phy.sfp_type =
   1465   1.1    dyoung 						ixgbe_sfp_type_da_act_lmt_core0;
   1466   1.1    dyoung 					else
   1467   1.1    dyoung 						hw->phy.sfp_type =
   1468   1.1    dyoung 						ixgbe_sfp_type_da_act_lmt_core1;
   1469   1.1    dyoung 				} else {
   1470   1.1    dyoung 					hw->phy.sfp_type =
   1471   1.3   msaitoh 							ixgbe_sfp_type_unknown;
   1472   1.1    dyoung 				}
   1473   1.1    dyoung 			} else if (comp_codes_10g &
   1474   1.1    dyoung 				   (IXGBE_SFF_10GBASESR_CAPABLE |
   1475   1.1    dyoung 				    IXGBE_SFF_10GBASELR_CAPABLE)) {
   1476   1.1    dyoung 				if (hw->bus.lan_id == 0)
   1477   1.1    dyoung 					hw->phy.sfp_type =
   1478   1.3   msaitoh 						      ixgbe_sfp_type_srlr_core0;
   1479   1.1    dyoung 				else
   1480   1.1    dyoung 					hw->phy.sfp_type =
   1481   1.3   msaitoh 						      ixgbe_sfp_type_srlr_core1;
   1482   1.1    dyoung 			} else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
   1483   1.1    dyoung 				if (hw->bus.lan_id == 0)
   1484   1.1    dyoung 					hw->phy.sfp_type =
   1485   1.1    dyoung 						ixgbe_sfp_type_1g_cu_core0;
   1486   1.1    dyoung 				else
   1487   1.1    dyoung 					hw->phy.sfp_type =
   1488   1.1    dyoung 						ixgbe_sfp_type_1g_cu_core1;
   1489   1.4   msaitoh 			} else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
   1490   1.4   msaitoh 				if (hw->bus.lan_id == 0)
   1491   1.4   msaitoh 					hw->phy.sfp_type =
   1492   1.4   msaitoh 						ixgbe_sfp_type_1g_sx_core0;
   1493   1.4   msaitoh 				else
   1494   1.4   msaitoh 					hw->phy.sfp_type =
   1495   1.4   msaitoh 						ixgbe_sfp_type_1g_sx_core1;
   1496   1.8   msaitoh 			} else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
   1497   1.8   msaitoh 				if (hw->bus.lan_id == 0)
   1498   1.8   msaitoh 					hw->phy.sfp_type =
   1499   1.8   msaitoh 						ixgbe_sfp_type_1g_lx_core0;
   1500   1.8   msaitoh 				else
   1501   1.8   msaitoh 					hw->phy.sfp_type =
   1502   1.8   msaitoh 						ixgbe_sfp_type_1g_lx_core1;
   1503   1.1    dyoung 			} else {
   1504   1.1    dyoung 				hw->phy.sfp_type = ixgbe_sfp_type_unknown;
   1505   1.1    dyoung 			}
   1506   1.1    dyoung 		}
   1507   1.1    dyoung 
   1508   1.1    dyoung 		if (hw->phy.sfp_type != stored_sfp_type)
   1509   1.1    dyoung 			hw->phy.sfp_setup_needed = TRUE;
   1510   1.1    dyoung 
   1511   1.1    dyoung 		/* Determine if the SFP+ PHY is dual speed or not. */
   1512   1.1    dyoung 		hw->phy.multispeed_fiber = FALSE;
   1513   1.1    dyoung 		if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
   1514   1.1    dyoung 		   (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
   1515   1.1    dyoung 		   ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
   1516   1.1    dyoung 		   (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
   1517   1.1    dyoung 			hw->phy.multispeed_fiber = TRUE;
   1518   1.1    dyoung 
   1519   1.1    dyoung 		/* Determine PHY vendor */
   1520   1.1    dyoung 		if (hw->phy.type != ixgbe_phy_nl) {
   1521   1.1    dyoung 			hw->phy.id = identifier;
   1522   1.1    dyoung 			status = hw->phy.ops.read_i2c_eeprom(hw,
   1523   1.3   msaitoh 						    IXGBE_SFF_VENDOR_OUI_BYTE0,
   1524   1.3   msaitoh 						    &oui_bytes[0]);
   1525   1.1    dyoung 
   1526   1.5   msaitoh 			if (status != IXGBE_SUCCESS)
   1527   1.1    dyoung 				goto err_read_i2c_eeprom;
   1528   1.1    dyoung 
   1529   1.1    dyoung 			status = hw->phy.ops.read_i2c_eeprom(hw,
   1530   1.3   msaitoh 						    IXGBE_SFF_VENDOR_OUI_BYTE1,
   1531   1.3   msaitoh 						    &oui_bytes[1]);
   1532   1.1    dyoung 
   1533   1.5   msaitoh 			if (status != IXGBE_SUCCESS)
   1534   1.1    dyoung 				goto err_read_i2c_eeprom;
   1535   1.1    dyoung 
   1536   1.1    dyoung 			status = hw->phy.ops.read_i2c_eeprom(hw,
   1537   1.3   msaitoh 						    IXGBE_SFF_VENDOR_OUI_BYTE2,
   1538   1.3   msaitoh 						    &oui_bytes[2]);
   1539   1.1    dyoung 
   1540   1.5   msaitoh 			if (status != IXGBE_SUCCESS)
   1541   1.1    dyoung 				goto err_read_i2c_eeprom;
   1542   1.1    dyoung 
   1543   1.1    dyoung 			vendor_oui =
   1544   1.1    dyoung 			  ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
   1545   1.1    dyoung 			   (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
   1546   1.1    dyoung 			   (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
   1547   1.1    dyoung 
   1548   1.1    dyoung 			switch (vendor_oui) {
   1549   1.1    dyoung 			case IXGBE_SFF_VENDOR_OUI_TYCO:
   1550   1.1    dyoung 				if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
   1551   1.1    dyoung 					hw->phy.type =
   1552   1.3   msaitoh 						    ixgbe_phy_sfp_passive_tyco;
   1553   1.1    dyoung 				break;
   1554   1.1    dyoung 			case IXGBE_SFF_VENDOR_OUI_FTL:
   1555   1.1    dyoung 				if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
   1556   1.1    dyoung 					hw->phy.type = ixgbe_phy_sfp_ftl_active;
   1557   1.1    dyoung 				else
   1558   1.1    dyoung 					hw->phy.type = ixgbe_phy_sfp_ftl;
   1559   1.1    dyoung 				break;
   1560   1.1    dyoung 			case IXGBE_SFF_VENDOR_OUI_AVAGO:
   1561   1.1    dyoung 				hw->phy.type = ixgbe_phy_sfp_avago;
   1562   1.1    dyoung 				break;
   1563   1.1    dyoung 			case IXGBE_SFF_VENDOR_OUI_INTEL:
   1564   1.1    dyoung 				hw->phy.type = ixgbe_phy_sfp_intel;
   1565   1.1    dyoung 				break;
   1566   1.1    dyoung 			default:
   1567  1.15   msaitoh 				hw->phy.type = ixgbe_phy_sfp_unknown;
   1568   1.1    dyoung 				break;
   1569   1.1    dyoung 			}
   1570   1.1    dyoung 		}
   1571   1.1    dyoung 
   1572   1.1    dyoung 		/* Allow any DA cable vendor */
   1573   1.1    dyoung 		if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
   1574  1.22   msaitoh 		    IXGBE_SFF_DA_ACTIVE_CABLE)) {
   1575  1.22   msaitoh 			status = IXGBE_SUCCESS;
   1576  1.22   msaitoh 
   1577  1.22   msaitoh 			/* Keep phy.type for ixgbe_phy_nl */
   1578  1.22   msaitoh 			if (hw->phy.type == ixgbe_phy_nl)
   1579  1.22   msaitoh 				goto out;
   1580  1.22   msaitoh 
   1581  1.15   msaitoh 			if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
   1582  1.15   msaitoh 				hw->phy.type = ixgbe_phy_sfp_passive_unknown;
   1583  1.15   msaitoh 			else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
   1584  1.15   msaitoh 				hw->phy.type = ixgbe_phy_sfp_active_unknown;
   1585   1.1    dyoung 			goto out;
   1586   1.1    dyoung 		}
   1587   1.1    dyoung 
   1588   1.1    dyoung 		/* Verify supported 1G SFP modules */
   1589   1.1    dyoung 		if (comp_codes_10g == 0 &&
   1590   1.1    dyoung 		    !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
   1591   1.4   msaitoh 		      hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
   1592   1.8   msaitoh 		      hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
   1593   1.8   msaitoh 		      hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
   1594   1.6   msaitoh 		      hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
   1595   1.4   msaitoh 		      hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
   1596  1.22   msaitoh 			if (hw->phy.type != ixgbe_phy_nl)
   1597  1.22   msaitoh 				hw->phy.type = ixgbe_phy_sfp_unsupported;
   1598   1.1    dyoung 			status = IXGBE_ERR_SFP_NOT_SUPPORTED;
   1599   1.1    dyoung 			goto out;
   1600   1.1    dyoung 		}
   1601   1.1    dyoung 
   1602   1.1    dyoung 		/* Anything else 82598-based is supported */
   1603   1.1    dyoung 		if (hw->mac.type == ixgbe_mac_82598EB) {
   1604   1.1    dyoung 			status = IXGBE_SUCCESS;
   1605   1.1    dyoung 			goto out;
   1606   1.1    dyoung 		}
   1607   1.1    dyoung 
   1608   1.1    dyoung 		ixgbe_get_device_caps(hw, &enforce_sfp);
   1609   1.1    dyoung 		if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
   1610   1.6   msaitoh 		    !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
   1611   1.6   msaitoh 		      hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
   1612   1.8   msaitoh 		      hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
   1613   1.8   msaitoh 		      hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
   1614   1.6   msaitoh 		      hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
   1615   1.6   msaitoh 		      hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
   1616   1.1    dyoung 			/* Make sure we're a supported PHY type */
   1617   1.1    dyoung 			if (hw->phy.type == ixgbe_phy_sfp_intel) {
   1618   1.1    dyoung 				status = IXGBE_SUCCESS;
   1619   1.1    dyoung 			} else {
   1620   1.4   msaitoh 				if (hw->allow_unsupported_sfp == TRUE) {
   1621  1.12   msaitoh 					EWARN(hw, "WARNING: Intel (R) Network Connections are quality tested using Intel (R) Ethernet Optics. Using untested modules is not supported and may cause unstable operation or damage to the module or the adapter. Intel Corporation is not responsible for any harm caused by using untested modules.\n");
   1622   1.4   msaitoh 					status = IXGBE_SUCCESS;
   1623   1.4   msaitoh 				} else {
   1624   1.4   msaitoh 					DEBUGOUT("SFP+ module not supported\n");
   1625  1.22   msaitoh 					if (hw->phy.type != ixgbe_phy_nl)
   1626  1.22   msaitoh 						hw->phy.type =
   1627  1.22   msaitoh 						    ixgbe_phy_sfp_unsupported;
   1628   1.4   msaitoh 					status = IXGBE_ERR_SFP_NOT_SUPPORTED;
   1629   1.4   msaitoh 				}
   1630   1.1    dyoung 			}
   1631   1.1    dyoung 		} else {
   1632   1.1    dyoung 			status = IXGBE_SUCCESS;
   1633   1.1    dyoung 		}
   1634   1.1    dyoung 	}
   1635   1.1    dyoung 
   1636   1.1    dyoung out:
   1637  1.22   msaitoh 	if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
   1638  1.20   msaitoh 		hw->need_unsupported_sfp_recovery = true;
   1639   1.1    dyoung 	return status;
   1640   1.1    dyoung 
   1641   1.1    dyoung err_read_i2c_eeprom:
   1642   1.1    dyoung 	hw->phy.sfp_type = ixgbe_sfp_type_not_present;
   1643   1.1    dyoung 	if (hw->phy.type != ixgbe_phy_nl) {
   1644   1.1    dyoung 		hw->phy.id = 0;
   1645   1.1    dyoung 		hw->phy.type = ixgbe_phy_unknown;
   1646   1.1    dyoung 	}
   1647   1.1    dyoung 	return IXGBE_ERR_SFP_NOT_PRESENT;
   1648   1.1    dyoung }
   1649   1.1    dyoung 
   1650   1.7   msaitoh /**
   1651   1.7   msaitoh  *  ixgbe_get_supported_phy_sfp_layer_generic - Returns physical layer type
   1652   1.7   msaitoh  *  @hw: pointer to hardware structure
   1653   1.7   msaitoh  *
   1654   1.7   msaitoh  *  Determines physical layer capabilities of the current SFP.
   1655   1.7   msaitoh  */
   1656  1.12   msaitoh u64 ixgbe_get_supported_phy_sfp_layer_generic(struct ixgbe_hw *hw)
   1657   1.7   msaitoh {
   1658  1.12   msaitoh 	u64 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
   1659   1.7   msaitoh 	u8 comp_codes_10g = 0;
   1660   1.7   msaitoh 	u8 comp_codes_1g = 0;
   1661   1.7   msaitoh 
   1662   1.7   msaitoh 	DEBUGFUNC("ixgbe_get_supported_phy_sfp_layer_generic");
   1663   1.7   msaitoh 
   1664   1.7   msaitoh 	hw->phy.ops.identify_sfp(hw);
   1665   1.7   msaitoh 	if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
   1666   1.7   msaitoh 		return physical_layer;
   1667   1.7   msaitoh 
   1668   1.7   msaitoh 	switch (hw->phy.type) {
   1669   1.7   msaitoh 	case ixgbe_phy_sfp_passive_tyco:
   1670   1.7   msaitoh 	case ixgbe_phy_sfp_passive_unknown:
   1671   1.7   msaitoh 	case ixgbe_phy_qsfp_passive_unknown:
   1672   1.7   msaitoh 		physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
   1673   1.7   msaitoh 		break;
   1674   1.7   msaitoh 	case ixgbe_phy_sfp_ftl_active:
   1675   1.7   msaitoh 	case ixgbe_phy_sfp_active_unknown:
   1676   1.7   msaitoh 	case ixgbe_phy_qsfp_active_unknown:
   1677   1.7   msaitoh 		physical_layer = IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA;
   1678   1.7   msaitoh 		break;
   1679   1.7   msaitoh 	case ixgbe_phy_sfp_avago:
   1680   1.7   msaitoh 	case ixgbe_phy_sfp_ftl:
   1681   1.7   msaitoh 	case ixgbe_phy_sfp_intel:
   1682   1.7   msaitoh 	case ixgbe_phy_sfp_unknown:
   1683   1.7   msaitoh 		hw->phy.ops.read_i2c_eeprom(hw,
   1684   1.7   msaitoh 		      IXGBE_SFF_1GBE_COMP_CODES, &comp_codes_1g);
   1685   1.7   msaitoh 		hw->phy.ops.read_i2c_eeprom(hw,
   1686   1.7   msaitoh 		      IXGBE_SFF_10GBE_COMP_CODES, &comp_codes_10g);
   1687   1.7   msaitoh 		if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
   1688   1.7   msaitoh 			physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
   1689   1.7   msaitoh 		else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
   1690   1.7   msaitoh 			physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
   1691   1.7   msaitoh 		else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE)
   1692   1.7   msaitoh 			physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_T;
   1693   1.7   msaitoh 		else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE)
   1694   1.7   msaitoh 			physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_SX;
   1695   1.7   msaitoh 		break;
   1696   1.7   msaitoh 	case ixgbe_phy_qsfp_intel:
   1697   1.7   msaitoh 	case ixgbe_phy_qsfp_unknown:
   1698   1.7   msaitoh 		hw->phy.ops.read_i2c_eeprom(hw,
   1699   1.7   msaitoh 		      IXGBE_SFF_QSFP_10GBE_COMP, &comp_codes_10g);
   1700   1.7   msaitoh 		if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
   1701   1.7   msaitoh 			physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
   1702   1.7   msaitoh 		else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
   1703   1.7   msaitoh 			physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
   1704   1.7   msaitoh 		break;
   1705   1.7   msaitoh 	default:
   1706   1.7   msaitoh 		break;
   1707   1.7   msaitoh 	}
   1708   1.7   msaitoh 
   1709   1.7   msaitoh 	return physical_layer;
   1710   1.7   msaitoh }
   1711   1.7   msaitoh 
   1712   1.7   msaitoh /**
   1713   1.7   msaitoh  *  ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
   1714   1.7   msaitoh  *  @hw: pointer to hardware structure
   1715   1.7   msaitoh  *
   1716   1.7   msaitoh  *  Searches for and identifies the QSFP module and assigns appropriate PHY type
   1717   1.7   msaitoh  **/
   1718   1.7   msaitoh s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
   1719   1.7   msaitoh {
   1720   1.7   msaitoh 	s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
   1721   1.7   msaitoh 	u32 vendor_oui = 0;
   1722   1.7   msaitoh 	enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
   1723   1.7   msaitoh 	u8 identifier = 0;
   1724   1.7   msaitoh 	u8 comp_codes_1g = 0;
   1725   1.7   msaitoh 	u8 comp_codes_10g = 0;
   1726   1.7   msaitoh 	u8 oui_bytes[3] = {0, 0, 0};
   1727   1.7   msaitoh 	u16 enforce_sfp = 0;
   1728   1.7   msaitoh 	u8 connector = 0;
   1729   1.7   msaitoh 	u8 cable_length = 0;
   1730   1.7   msaitoh 	u8 device_tech = 0;
   1731   1.7   msaitoh 	bool active_cable = FALSE;
   1732   1.7   msaitoh 
   1733   1.7   msaitoh 	DEBUGFUNC("ixgbe_identify_qsfp_module_generic");
   1734   1.7   msaitoh 
   1735   1.7   msaitoh 	if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
   1736   1.7   msaitoh 		hw->phy.sfp_type = ixgbe_sfp_type_not_present;
   1737   1.7   msaitoh 		status = IXGBE_ERR_SFP_NOT_PRESENT;
   1738   1.7   msaitoh 		goto out;
   1739   1.7   msaitoh 	}
   1740   1.7   msaitoh 
   1741   1.8   msaitoh 	/* LAN ID is needed for I2C access */
   1742   1.8   msaitoh 	hw->mac.ops.set_lan_id(hw);
   1743   1.8   msaitoh 
   1744   1.7   msaitoh 	status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
   1745   1.7   msaitoh 					     &identifier);
   1746   1.7   msaitoh 
   1747   1.7   msaitoh 	if (status != IXGBE_SUCCESS)
   1748   1.7   msaitoh 		goto err_read_i2c_eeprom;
   1749   1.7   msaitoh 
   1750   1.7   msaitoh 	if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
   1751   1.7   msaitoh 		hw->phy.type = ixgbe_phy_sfp_unsupported;
   1752   1.7   msaitoh 		status = IXGBE_ERR_SFP_NOT_SUPPORTED;
   1753   1.7   msaitoh 		goto out;
   1754   1.7   msaitoh 	}
   1755   1.7   msaitoh 
   1756   1.7   msaitoh 	hw->phy.id = identifier;
   1757   1.7   msaitoh 
   1758   1.7   msaitoh 	status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
   1759   1.7   msaitoh 					     &comp_codes_10g);
   1760   1.7   msaitoh 
   1761   1.7   msaitoh 	if (status != IXGBE_SUCCESS)
   1762   1.7   msaitoh 		goto err_read_i2c_eeprom;
   1763   1.7   msaitoh 
   1764   1.7   msaitoh 	status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
   1765   1.7   msaitoh 					     &comp_codes_1g);
   1766   1.7   msaitoh 
   1767   1.7   msaitoh 	if (status != IXGBE_SUCCESS)
   1768   1.7   msaitoh 		goto err_read_i2c_eeprom;
   1769   1.7   msaitoh 
   1770   1.7   msaitoh 	if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
   1771   1.7   msaitoh 		hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
   1772   1.7   msaitoh 		if (hw->bus.lan_id == 0)
   1773   1.7   msaitoh 			hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
   1774   1.7   msaitoh 		else
   1775   1.7   msaitoh 			hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
   1776   1.7   msaitoh 	} else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
   1777   1.7   msaitoh 				     IXGBE_SFF_10GBASELR_CAPABLE)) {
   1778   1.7   msaitoh 		if (hw->bus.lan_id == 0)
   1779   1.7   msaitoh 			hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
   1780   1.7   msaitoh 		else
   1781   1.7   msaitoh 			hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
   1782   1.7   msaitoh 	} else {
   1783   1.7   msaitoh 		if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
   1784   1.7   msaitoh 			active_cable = TRUE;
   1785   1.7   msaitoh 
   1786   1.7   msaitoh 		if (!active_cable) {
   1787   1.7   msaitoh 			/* check for active DA cables that pre-date
   1788   1.7   msaitoh 			 * SFF-8436 v3.6 */
   1789   1.7   msaitoh 			hw->phy.ops.read_i2c_eeprom(hw,
   1790   1.7   msaitoh 					IXGBE_SFF_QSFP_CONNECTOR,
   1791   1.7   msaitoh 					&connector);
   1792   1.7   msaitoh 
   1793   1.7   msaitoh 			hw->phy.ops.read_i2c_eeprom(hw,
   1794   1.7   msaitoh 					IXGBE_SFF_QSFP_CABLE_LENGTH,
   1795   1.7   msaitoh 					&cable_length);
   1796   1.7   msaitoh 
   1797   1.7   msaitoh 			hw->phy.ops.read_i2c_eeprom(hw,
   1798   1.7   msaitoh 					IXGBE_SFF_QSFP_DEVICE_TECH,
   1799   1.7   msaitoh 					&device_tech);
   1800   1.7   msaitoh 
   1801   1.7   msaitoh 			if ((connector ==
   1802   1.7   msaitoh 				     IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
   1803   1.7   msaitoh 			    (cable_length > 0) &&
   1804   1.7   msaitoh 			    ((device_tech >> 4) ==
   1805   1.7   msaitoh 				     IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
   1806   1.7   msaitoh 				active_cable = TRUE;
   1807   1.7   msaitoh 		}
   1808   1.7   msaitoh 
   1809   1.7   msaitoh 		if (active_cable) {
   1810   1.7   msaitoh 			hw->phy.type = ixgbe_phy_qsfp_active_unknown;
   1811   1.7   msaitoh 			if (hw->bus.lan_id == 0)
   1812   1.7   msaitoh 				hw->phy.sfp_type =
   1813   1.7   msaitoh 						ixgbe_sfp_type_da_act_lmt_core0;
   1814   1.7   msaitoh 			else
   1815   1.7   msaitoh 				hw->phy.sfp_type =
   1816   1.7   msaitoh 						ixgbe_sfp_type_da_act_lmt_core1;
   1817   1.7   msaitoh 		} else {
   1818   1.7   msaitoh 			/* unsupported module type */
   1819   1.7   msaitoh 			hw->phy.type = ixgbe_phy_sfp_unsupported;
   1820   1.7   msaitoh 			status = IXGBE_ERR_SFP_NOT_SUPPORTED;
   1821   1.7   msaitoh 			goto out;
   1822   1.7   msaitoh 		}
   1823   1.7   msaitoh 	}
   1824   1.7   msaitoh 
   1825   1.7   msaitoh 	if (hw->phy.sfp_type != stored_sfp_type)
   1826   1.7   msaitoh 		hw->phy.sfp_setup_needed = TRUE;
   1827   1.7   msaitoh 
   1828   1.7   msaitoh 	/* Determine if the QSFP+ PHY is dual speed or not. */
   1829   1.7   msaitoh 	hw->phy.multispeed_fiber = FALSE;
   1830   1.7   msaitoh 	if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
   1831   1.7   msaitoh 	   (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
   1832   1.7   msaitoh 	   ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
   1833   1.7   msaitoh 	   (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
   1834   1.7   msaitoh 		hw->phy.multispeed_fiber = TRUE;
   1835   1.7   msaitoh 
   1836   1.7   msaitoh 	/* Determine PHY vendor for optical modules */
   1837   1.7   msaitoh 	if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
   1838  1.21   msaitoh 			      IXGBE_SFF_10GBASELR_CAPABLE)) {
   1839   1.7   msaitoh 		status = hw->phy.ops.read_i2c_eeprom(hw,
   1840   1.7   msaitoh 					    IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
   1841   1.7   msaitoh 					    &oui_bytes[0]);
   1842   1.7   msaitoh 
   1843   1.7   msaitoh 		if (status != IXGBE_SUCCESS)
   1844   1.7   msaitoh 			goto err_read_i2c_eeprom;
   1845   1.7   msaitoh 
   1846   1.7   msaitoh 		status = hw->phy.ops.read_i2c_eeprom(hw,
   1847   1.7   msaitoh 					    IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
   1848   1.7   msaitoh 					    &oui_bytes[1]);
   1849   1.7   msaitoh 
   1850   1.7   msaitoh 		if (status != IXGBE_SUCCESS)
   1851   1.7   msaitoh 			goto err_read_i2c_eeprom;
   1852   1.7   msaitoh 
   1853   1.7   msaitoh 		status = hw->phy.ops.read_i2c_eeprom(hw,
   1854   1.7   msaitoh 					    IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
   1855   1.7   msaitoh 					    &oui_bytes[2]);
   1856   1.7   msaitoh 
   1857   1.7   msaitoh 		if (status != IXGBE_SUCCESS)
   1858   1.7   msaitoh 			goto err_read_i2c_eeprom;
   1859   1.7   msaitoh 
   1860   1.7   msaitoh 		vendor_oui =
   1861   1.7   msaitoh 		  ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
   1862   1.7   msaitoh 		   (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
   1863   1.7   msaitoh 		   (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
   1864   1.7   msaitoh 
   1865   1.7   msaitoh 		if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
   1866   1.7   msaitoh 			hw->phy.type = ixgbe_phy_qsfp_intel;
   1867   1.7   msaitoh 		else
   1868   1.7   msaitoh 			hw->phy.type = ixgbe_phy_qsfp_unknown;
   1869   1.7   msaitoh 
   1870   1.7   msaitoh 		ixgbe_get_device_caps(hw, &enforce_sfp);
   1871   1.7   msaitoh 		if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
   1872   1.7   msaitoh 			/* Make sure we're a supported PHY type */
   1873   1.7   msaitoh 			if (hw->phy.type == ixgbe_phy_qsfp_intel) {
   1874   1.7   msaitoh 				status = IXGBE_SUCCESS;
   1875   1.7   msaitoh 			} else {
   1876   1.7   msaitoh 				if (hw->allow_unsupported_sfp == TRUE) {
   1877  1.12   msaitoh 					EWARN(hw, "WARNING: Intel (R) Network Connections are quality tested using Intel (R) Ethernet Optics. Using untested modules is not supported and may cause unstable operation or damage to the module or the adapter. Intel Corporation is not responsible for any harm caused by using untested modules.\n");
   1878   1.7   msaitoh 					status = IXGBE_SUCCESS;
   1879   1.7   msaitoh 				} else {
   1880   1.7   msaitoh 					DEBUGOUT("QSFP module not supported\n");
   1881   1.7   msaitoh 					hw->phy.type =
   1882   1.7   msaitoh 						ixgbe_phy_sfp_unsupported;
   1883   1.7   msaitoh 					status = IXGBE_ERR_SFP_NOT_SUPPORTED;
   1884   1.7   msaitoh 				}
   1885   1.7   msaitoh 			}
   1886   1.7   msaitoh 		} else {
   1887   1.7   msaitoh 			status = IXGBE_SUCCESS;
   1888   1.7   msaitoh 		}
   1889   1.7   msaitoh 	}
   1890   1.7   msaitoh 
   1891   1.7   msaitoh out:
   1892  1.20   msaitoh 	if (hw->phy.type == ixgbe_phy_sfp_unsupported)
   1893  1.20   msaitoh 		hw->need_unsupported_sfp_recovery = true;
   1894   1.7   msaitoh 	return status;
   1895   1.7   msaitoh 
   1896   1.7   msaitoh err_read_i2c_eeprom:
   1897   1.7   msaitoh 	hw->phy.sfp_type = ixgbe_sfp_type_not_present;
   1898   1.7   msaitoh 	hw->phy.id = 0;
   1899   1.7   msaitoh 	hw->phy.type = ixgbe_phy_unknown;
   1900   1.7   msaitoh 
   1901   1.7   msaitoh 	return IXGBE_ERR_SFP_NOT_PRESENT;
   1902   1.7   msaitoh }
   1903   1.3   msaitoh 
   1904   1.1    dyoung /**
   1905   1.1    dyoung  *  ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
   1906   1.1    dyoung  *  @hw: pointer to hardware structure
   1907   1.1    dyoung  *  @list_offset: offset to the SFP ID list
   1908   1.1    dyoung  *  @data_offset: offset to the SFP data block
   1909   1.1    dyoung  *
   1910   1.1    dyoung  *  Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
   1911   1.1    dyoung  *  so it returns the offsets to the phy init sequence block.
   1912   1.1    dyoung  **/
   1913   1.1    dyoung s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
   1914   1.3   msaitoh 					u16 *list_offset,
   1915   1.3   msaitoh 					u16 *data_offset)
   1916   1.1    dyoung {
   1917   1.1    dyoung 	u16 sfp_id;
   1918   1.1    dyoung 	u16 sfp_type = hw->phy.sfp_type;
   1919   1.1    dyoung 
   1920   1.1    dyoung 	DEBUGFUNC("ixgbe_get_sfp_init_sequence_offsets");
   1921   1.1    dyoung 
   1922   1.1    dyoung 	if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
   1923   1.1    dyoung 		return IXGBE_ERR_SFP_NOT_SUPPORTED;
   1924   1.1    dyoung 
   1925   1.1    dyoung 	if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
   1926   1.1    dyoung 		return IXGBE_ERR_SFP_NOT_PRESENT;
   1927   1.1    dyoung 
   1928   1.1    dyoung 	if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
   1929   1.1    dyoung 	    (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
   1930   1.1    dyoung 		return IXGBE_ERR_SFP_NOT_SUPPORTED;
   1931   1.1    dyoung 
   1932   1.1    dyoung 	/*
   1933   1.1    dyoung 	 * Limiting active cables and 1G Phys must be initialized as
   1934   1.1    dyoung 	 * SR modules
   1935   1.1    dyoung 	 */
   1936   1.1    dyoung 	if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
   1937   1.8   msaitoh 	    sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
   1938   1.4   msaitoh 	    sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
   1939   1.4   msaitoh 	    sfp_type == ixgbe_sfp_type_1g_sx_core0)
   1940   1.1    dyoung 		sfp_type = ixgbe_sfp_type_srlr_core0;
   1941   1.1    dyoung 	else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
   1942   1.8   msaitoh 		 sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
   1943   1.4   msaitoh 		 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
   1944   1.4   msaitoh 		 sfp_type == ixgbe_sfp_type_1g_sx_core1)
   1945   1.1    dyoung 		sfp_type = ixgbe_sfp_type_srlr_core1;
   1946   1.1    dyoung 
   1947   1.1    dyoung 	/* Read offset to PHY init contents */
   1948   1.6   msaitoh 	if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
   1949   1.6   msaitoh 		ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
   1950   1.6   msaitoh 			      "eeprom read at offset %d failed",
   1951   1.6   msaitoh 			      IXGBE_PHY_INIT_OFFSET_NL);
   1952   1.6   msaitoh 		return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
   1953   1.6   msaitoh 	}
   1954   1.1    dyoung 
   1955   1.1    dyoung 	if ((!*list_offset) || (*list_offset == 0xFFFF))
   1956   1.1    dyoung 		return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
   1957   1.1    dyoung 
   1958   1.1    dyoung 	/* Shift offset to first ID word */
   1959   1.1    dyoung 	(*list_offset)++;
   1960   1.1    dyoung 
   1961   1.1    dyoung 	/*
   1962   1.1    dyoung 	 * Find the matching SFP ID in the EEPROM
   1963   1.1    dyoung 	 * and program the init sequence
   1964   1.1    dyoung 	 */
   1965   1.6   msaitoh 	if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
   1966   1.6   msaitoh 		goto err_phy;
   1967   1.1    dyoung 
   1968   1.1    dyoung 	while (sfp_id != IXGBE_PHY_INIT_END_NL) {
   1969   1.1    dyoung 		if (sfp_id == sfp_type) {
   1970   1.1    dyoung 			(*list_offset)++;
   1971   1.6   msaitoh 			if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
   1972   1.6   msaitoh 				goto err_phy;
   1973   1.1    dyoung 			if ((!*data_offset) || (*data_offset == 0xFFFF)) {
   1974   1.1    dyoung 				DEBUGOUT("SFP+ module not supported\n");
   1975   1.1    dyoung 				return IXGBE_ERR_SFP_NOT_SUPPORTED;
   1976   1.1    dyoung 			} else {
   1977   1.1    dyoung 				break;
   1978   1.1    dyoung 			}
   1979   1.1    dyoung 		} else {
   1980   1.1    dyoung 			(*list_offset) += 2;
   1981   1.1    dyoung 			if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
   1982   1.6   msaitoh 				goto err_phy;
   1983   1.1    dyoung 		}
   1984   1.1    dyoung 	}
   1985   1.1    dyoung 
   1986   1.1    dyoung 	if (sfp_id == IXGBE_PHY_INIT_END_NL) {
   1987   1.1    dyoung 		DEBUGOUT("No matching SFP+ module found\n");
   1988   1.1    dyoung 		return IXGBE_ERR_SFP_NOT_SUPPORTED;
   1989   1.1    dyoung 	}
   1990   1.1    dyoung 
   1991   1.1    dyoung 	return IXGBE_SUCCESS;
   1992   1.6   msaitoh 
   1993   1.6   msaitoh err_phy:
   1994   1.6   msaitoh 	ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
   1995   1.6   msaitoh 		      "eeprom read at offset %d failed", *list_offset);
   1996   1.6   msaitoh 	return IXGBE_ERR_PHY;
   1997   1.1    dyoung }
   1998   1.1    dyoung 
   1999   1.1    dyoung /**
   2000   1.1    dyoung  *  ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
   2001   1.1    dyoung  *  @hw: pointer to hardware structure
   2002   1.1    dyoung  *  @byte_offset: EEPROM byte offset to read
   2003   1.1    dyoung  *  @eeprom_data: value read
   2004   1.1    dyoung  *
   2005   1.1    dyoung  *  Performs byte read operation to SFP module's EEPROM over I2C interface.
   2006   1.1    dyoung  **/
   2007   1.1    dyoung s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
   2008   1.3   msaitoh 				  u8 *eeprom_data)
   2009   1.1    dyoung {
   2010   1.1    dyoung 	DEBUGFUNC("ixgbe_read_i2c_eeprom_generic");
   2011   1.1    dyoung 
   2012   1.1    dyoung 	return hw->phy.ops.read_i2c_byte(hw, byte_offset,
   2013   1.3   msaitoh 					 IXGBE_I2C_EEPROM_DEV_ADDR,
   2014   1.3   msaitoh 					 eeprom_data);
   2015   1.1    dyoung }
   2016   1.1    dyoung 
   2017   1.1    dyoung /**
   2018   1.5   msaitoh  *  ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
   2019   1.5   msaitoh  *  @hw: pointer to hardware structure
   2020   1.5   msaitoh  *  @byte_offset: byte offset at address 0xA2
   2021  1.17   msaitoh  *  @sff8472_data: value read
   2022   1.5   msaitoh  *
   2023   1.5   msaitoh  *  Performs byte read operation to SFP module's SFF-8472 data over I2C
   2024   1.5   msaitoh  **/
   2025   1.5   msaitoh static s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
   2026   1.5   msaitoh 					  u8 *sff8472_data)
   2027   1.5   msaitoh {
   2028   1.5   msaitoh 	return hw->phy.ops.read_i2c_byte(hw, byte_offset,
   2029   1.5   msaitoh 					 IXGBE_I2C_EEPROM_DEV_ADDR2,
   2030   1.5   msaitoh 					 sff8472_data);
   2031   1.5   msaitoh }
   2032   1.5   msaitoh 
   2033   1.5   msaitoh /**
   2034   1.1    dyoung  *  ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
   2035   1.1    dyoung  *  @hw: pointer to hardware structure
   2036   1.1    dyoung  *  @byte_offset: EEPROM byte offset to write
   2037   1.1    dyoung  *  @eeprom_data: value to write
   2038   1.1    dyoung  *
   2039   1.1    dyoung  *  Performs byte write operation to SFP module's EEPROM over I2C interface.
   2040   1.1    dyoung  **/
   2041   1.1    dyoung s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
   2042   1.3   msaitoh 				   u8 eeprom_data)
   2043   1.1    dyoung {
   2044   1.1    dyoung 	DEBUGFUNC("ixgbe_write_i2c_eeprom_generic");
   2045   1.1    dyoung 
   2046   1.1    dyoung 	return hw->phy.ops.write_i2c_byte(hw, byte_offset,
   2047   1.3   msaitoh 					  IXGBE_I2C_EEPROM_DEV_ADDR,
   2048   1.3   msaitoh 					  eeprom_data);
   2049   1.1    dyoung }
   2050   1.1    dyoung 
   2051   1.1    dyoung /**
   2052   1.7   msaitoh  * ixgbe_is_sfp_probe - Returns TRUE if SFP is being detected
   2053   1.7   msaitoh  * @hw: pointer to hardware structure
   2054   1.7   msaitoh  * @offset: eeprom offset to be read
   2055   1.7   msaitoh  * @addr: I2C address to be read
   2056   1.7   msaitoh  */
   2057   1.7   msaitoh static bool ixgbe_is_sfp_probe(struct ixgbe_hw *hw, u8 offset, u8 addr)
   2058   1.7   msaitoh {
   2059   1.7   msaitoh 	if (addr == IXGBE_I2C_EEPROM_DEV_ADDR &&
   2060   1.7   msaitoh 	    offset == IXGBE_SFF_IDENTIFIER &&
   2061   1.7   msaitoh 	    hw->phy.sfp_type == ixgbe_sfp_type_not_present)
   2062   1.7   msaitoh 		return TRUE;
   2063   1.7   msaitoh 	return FALSE;
   2064   1.7   msaitoh }
   2065   1.7   msaitoh 
   2066   1.7   msaitoh /**
   2067   1.8   msaitoh  *  ixgbe_read_i2c_byte_generic_int - Reads 8 bit word over I2C
   2068   1.1    dyoung  *  @hw: pointer to hardware structure
   2069   1.1    dyoung  *  @byte_offset: byte offset to read
   2070  1.17   msaitoh  *  @dev_addr: address to read from
   2071   1.1    dyoung  *  @data: value read
   2072   1.8   msaitoh  *  @lock: TRUE if to take and release semaphore
   2073   1.1    dyoung  *
   2074   1.1    dyoung  *  Performs byte read operation to SFP module's EEPROM over I2C interface at
   2075   1.3   msaitoh  *  a specified device address.
   2076   1.1    dyoung  **/
   2077   1.8   msaitoh static s32 ixgbe_read_i2c_byte_generic_int(struct ixgbe_hw *hw, u8 byte_offset,
   2078   1.8   msaitoh 					   u8 dev_addr, u8 *data, bool lock)
   2079   1.1    dyoung {
   2080   1.7   msaitoh 	s32 status;
   2081   1.1    dyoung 	u32 max_retry = 10;
   2082   1.1    dyoung 	u32 retry = 0;
   2083   1.7   msaitoh 	u32 swfw_mask = hw->phy.phy_semaphore_mask;
   2084   1.1    dyoung 	bool nack = 1;
   2085   1.3   msaitoh 	*data = 0;
   2086   1.1    dyoung 
   2087   1.1    dyoung 	DEBUGFUNC("ixgbe_read_i2c_byte_generic");
   2088   1.1    dyoung 
   2089   1.8   msaitoh 	if (hw->mac.type >= ixgbe_mac_X550)
   2090   1.8   msaitoh 		max_retry = 3;
   2091   1.7   msaitoh 	if (ixgbe_is_sfp_probe(hw, byte_offset, dev_addr))
   2092   1.7   msaitoh 		max_retry = IXGBE_SFP_DETECT_RETRIES;
   2093   1.1    dyoung 
   2094   1.1    dyoung 	do {
   2095   1.8   msaitoh 		if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
   2096   1.7   msaitoh 			return IXGBE_ERR_SWFW_SYNC;
   2097   1.1    dyoung 
   2098   1.1    dyoung 		ixgbe_i2c_start(hw);
   2099   1.1    dyoung 
   2100   1.1    dyoung 		/* Device Address and write indication */
   2101   1.1    dyoung 		status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
   2102   1.1    dyoung 		if (status != IXGBE_SUCCESS)
   2103   1.1    dyoung 			goto fail;
   2104   1.1    dyoung 
   2105   1.1    dyoung 		status = ixgbe_get_i2c_ack(hw);
   2106   1.1    dyoung 		if (status != IXGBE_SUCCESS)
   2107   1.1    dyoung 			goto fail;
   2108   1.1    dyoung 
   2109   1.1    dyoung 		status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
   2110   1.1    dyoung 		if (status != IXGBE_SUCCESS)
   2111   1.1    dyoung 			goto fail;
   2112   1.1    dyoung 
   2113   1.1    dyoung 		status = ixgbe_get_i2c_ack(hw);
   2114   1.1    dyoung 		if (status != IXGBE_SUCCESS)
   2115   1.1    dyoung 			goto fail;
   2116   1.1    dyoung 
   2117   1.1    dyoung 		ixgbe_i2c_start(hw);
   2118   1.1    dyoung 
   2119   1.1    dyoung 		/* Device Address and read indication */
   2120   1.1    dyoung 		status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
   2121   1.1    dyoung 		if (status != IXGBE_SUCCESS)
   2122   1.1    dyoung 			goto fail;
   2123   1.1    dyoung 
   2124   1.1    dyoung 		status = ixgbe_get_i2c_ack(hw);
   2125   1.1    dyoung 		if (status != IXGBE_SUCCESS)
   2126   1.1    dyoung 			goto fail;
   2127   1.1    dyoung 
   2128   1.1    dyoung 		status = ixgbe_clock_in_i2c_byte(hw, data);
   2129   1.1    dyoung 		if (status != IXGBE_SUCCESS)
   2130   1.1    dyoung 			goto fail;
   2131   1.1    dyoung 
   2132   1.1    dyoung 		status = ixgbe_clock_out_i2c_bit(hw, nack);
   2133   1.1    dyoung 		if (status != IXGBE_SUCCESS)
   2134   1.1    dyoung 			goto fail;
   2135   1.1    dyoung 
   2136   1.1    dyoung 		ixgbe_i2c_stop(hw);
   2137   1.8   msaitoh 		if (lock)
   2138   1.8   msaitoh 			hw->mac.ops.release_swfw_sync(hw, swfw_mask);
   2139   1.7   msaitoh 		return IXGBE_SUCCESS;
   2140   1.1    dyoung 
   2141   1.1    dyoung fail:
   2142   1.5   msaitoh 		ixgbe_i2c_bus_clear(hw);
   2143   1.8   msaitoh 		if (lock) {
   2144   1.8   msaitoh 			hw->mac.ops.release_swfw_sync(hw, swfw_mask);
   2145   1.8   msaitoh 			msec_delay(100);
   2146   1.8   msaitoh 		}
   2147   1.1    dyoung 		retry++;
   2148   1.1    dyoung 		if (retry < max_retry)
   2149   1.1    dyoung 			DEBUGOUT("I2C byte read error - Retrying.\n");
   2150   1.1    dyoung 		else
   2151   1.1    dyoung 			DEBUGOUT("I2C byte read error.\n");
   2152   1.1    dyoung 
   2153   1.1    dyoung 	} while (retry < max_retry);
   2154   1.1    dyoung 
   2155   1.1    dyoung 	return status;
   2156   1.1    dyoung }
   2157   1.1    dyoung 
   2158   1.1    dyoung /**
   2159   1.8   msaitoh  *  ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
   2160   1.8   msaitoh  *  @hw: pointer to hardware structure
   2161   1.8   msaitoh  *  @byte_offset: byte offset to read
   2162  1.17   msaitoh  *  @dev_addr: address to read from
   2163   1.8   msaitoh  *  @data: value read
   2164   1.8   msaitoh  *
   2165   1.8   msaitoh  *  Performs byte read operation to SFP module's EEPROM over I2C interface at
   2166   1.8   msaitoh  *  a specified device address.
   2167   1.8   msaitoh  **/
   2168   1.8   msaitoh s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
   2169   1.8   msaitoh 				u8 dev_addr, u8 *data)
   2170   1.8   msaitoh {
   2171   1.8   msaitoh 	return ixgbe_read_i2c_byte_generic_int(hw, byte_offset, dev_addr,
   2172   1.8   msaitoh 					       data, TRUE);
   2173   1.8   msaitoh }
   2174   1.8   msaitoh 
   2175   1.8   msaitoh /**
   2176   1.8   msaitoh  *  ixgbe_read_i2c_byte_generic_unlocked - Reads 8 bit word over I2C
   2177   1.8   msaitoh  *  @hw: pointer to hardware structure
   2178   1.8   msaitoh  *  @byte_offset: byte offset to read
   2179  1.17   msaitoh  *  @dev_addr: address to read from
   2180   1.8   msaitoh  *  @data: value read
   2181   1.8   msaitoh  *
   2182   1.8   msaitoh  *  Performs byte read operation to SFP module's EEPROM over I2C interface at
   2183   1.8   msaitoh  *  a specified device address.
   2184   1.8   msaitoh  **/
   2185   1.8   msaitoh s32 ixgbe_read_i2c_byte_generic_unlocked(struct ixgbe_hw *hw, u8 byte_offset,
   2186   1.8   msaitoh 					 u8 dev_addr, u8 *data)
   2187   1.8   msaitoh {
   2188   1.8   msaitoh 	return ixgbe_read_i2c_byte_generic_int(hw, byte_offset, dev_addr,
   2189   1.8   msaitoh 					       data, FALSE);
   2190   1.8   msaitoh }
   2191   1.8   msaitoh 
   2192   1.8   msaitoh /**
   2193   1.8   msaitoh  *  ixgbe_write_i2c_byte_generic_int - Writes 8 bit word over I2C
   2194   1.1    dyoung  *  @hw: pointer to hardware structure
   2195   1.1    dyoung  *  @byte_offset: byte offset to write
   2196  1.17   msaitoh  *  @dev_addr: address to write to
   2197   1.1    dyoung  *  @data: value to write
   2198   1.8   msaitoh  *  @lock: TRUE if to take and release semaphore
   2199   1.1    dyoung  *
   2200   1.1    dyoung  *  Performs byte write operation to SFP module's EEPROM over I2C interface at
   2201   1.1    dyoung  *  a specified device address.
   2202   1.1    dyoung  **/
   2203   1.8   msaitoh static s32 ixgbe_write_i2c_byte_generic_int(struct ixgbe_hw *hw, u8 byte_offset,
   2204   1.8   msaitoh 					    u8 dev_addr, u8 data, bool lock)
   2205   1.1    dyoung {
   2206   1.8   msaitoh 	s32 status;
   2207   1.2  christos 	u32 max_retry = 2;
   2208   1.1    dyoung 	u32 retry = 0;
   2209   1.7   msaitoh 	u32 swfw_mask = hw->phy.phy_semaphore_mask;
   2210   1.1    dyoung 
   2211   1.1    dyoung 	DEBUGFUNC("ixgbe_write_i2c_byte_generic");
   2212   1.1    dyoung 
   2213   1.8   msaitoh 	if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) !=
   2214   1.8   msaitoh 	    IXGBE_SUCCESS)
   2215   1.8   msaitoh 		return IXGBE_ERR_SWFW_SYNC;
   2216   1.1    dyoung 
   2217   1.1    dyoung 	do {
   2218   1.1    dyoung 		ixgbe_i2c_start(hw);
   2219   1.1    dyoung 
   2220   1.1    dyoung 		status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
   2221   1.1    dyoung 		if (status != IXGBE_SUCCESS)
   2222   1.1    dyoung 			goto fail;
   2223   1.1    dyoung 
   2224   1.1    dyoung 		status = ixgbe_get_i2c_ack(hw);
   2225   1.1    dyoung 		if (status != IXGBE_SUCCESS)
   2226   1.1    dyoung 			goto fail;
   2227   1.1    dyoung 
   2228   1.1    dyoung 		status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
   2229   1.1    dyoung 		if (status != IXGBE_SUCCESS)
   2230   1.1    dyoung 			goto fail;
   2231   1.1    dyoung 
   2232   1.1    dyoung 		status = ixgbe_get_i2c_ack(hw);
   2233   1.1    dyoung 		if (status != IXGBE_SUCCESS)
   2234   1.1    dyoung 			goto fail;
   2235   1.1    dyoung 
   2236   1.1    dyoung 		status = ixgbe_clock_out_i2c_byte(hw, data);
   2237   1.1    dyoung 		if (status != IXGBE_SUCCESS)
   2238   1.1    dyoung 			goto fail;
   2239   1.1    dyoung 
   2240   1.1    dyoung 		status = ixgbe_get_i2c_ack(hw);
   2241   1.1    dyoung 		if (status != IXGBE_SUCCESS)
   2242   1.1    dyoung 			goto fail;
   2243   1.1    dyoung 
   2244   1.1    dyoung 		ixgbe_i2c_stop(hw);
   2245   1.8   msaitoh 		if (lock)
   2246   1.8   msaitoh 			hw->mac.ops.release_swfw_sync(hw, swfw_mask);
   2247   1.7   msaitoh 		return IXGBE_SUCCESS;
   2248   1.1    dyoung 
   2249   1.1    dyoung fail:
   2250   1.1    dyoung 		ixgbe_i2c_bus_clear(hw);
   2251   1.1    dyoung 		retry++;
   2252   1.1    dyoung 		if (retry < max_retry)
   2253   1.1    dyoung 			DEBUGOUT("I2C byte write error - Retrying.\n");
   2254   1.1    dyoung 		else
   2255   1.1    dyoung 			DEBUGOUT("I2C byte write error.\n");
   2256   1.1    dyoung 	} while (retry < max_retry);
   2257   1.1    dyoung 
   2258   1.8   msaitoh 	if (lock)
   2259   1.8   msaitoh 		hw->mac.ops.release_swfw_sync(hw, swfw_mask);
   2260   1.1    dyoung 
   2261   1.1    dyoung 	return status;
   2262   1.1    dyoung }
   2263   1.1    dyoung 
   2264   1.1    dyoung /**
   2265   1.8   msaitoh  *  ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
   2266   1.8   msaitoh  *  @hw: pointer to hardware structure
   2267   1.8   msaitoh  *  @byte_offset: byte offset to write
   2268  1.17   msaitoh  *  @dev_addr: address to write to
   2269   1.8   msaitoh  *  @data: value to write
   2270   1.8   msaitoh  *
   2271   1.8   msaitoh  *  Performs byte write operation to SFP module's EEPROM over I2C interface at
   2272   1.8   msaitoh  *  a specified device address.
   2273   1.8   msaitoh  **/
   2274   1.8   msaitoh s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
   2275   1.8   msaitoh 				 u8 dev_addr, u8 data)
   2276   1.8   msaitoh {
   2277   1.8   msaitoh 	return ixgbe_write_i2c_byte_generic_int(hw, byte_offset, dev_addr,
   2278   1.8   msaitoh 						data, TRUE);
   2279   1.8   msaitoh }
   2280   1.8   msaitoh 
   2281   1.8   msaitoh /**
   2282   1.8   msaitoh  *  ixgbe_write_i2c_byte_generic_unlocked - Writes 8 bit word over I2C
   2283   1.8   msaitoh  *  @hw: pointer to hardware structure
   2284   1.8   msaitoh  *  @byte_offset: byte offset to write
   2285  1.17   msaitoh  *  @dev_addr: address to write to
   2286   1.8   msaitoh  *  @data: value to write
   2287   1.8   msaitoh  *
   2288   1.8   msaitoh  *  Performs byte write operation to SFP module's EEPROM over I2C interface at
   2289   1.8   msaitoh  *  a specified device address.
   2290   1.8   msaitoh  **/
   2291   1.8   msaitoh s32 ixgbe_write_i2c_byte_generic_unlocked(struct ixgbe_hw *hw, u8 byte_offset,
   2292   1.8   msaitoh 					  u8 dev_addr, u8 data)
   2293   1.8   msaitoh {
   2294   1.8   msaitoh 	return ixgbe_write_i2c_byte_generic_int(hw, byte_offset, dev_addr,
   2295   1.8   msaitoh 						data, FALSE);
   2296   1.8   msaitoh }
   2297   1.8   msaitoh 
   2298   1.8   msaitoh /**
   2299   1.1    dyoung  *  ixgbe_i2c_start - Sets I2C start condition
   2300   1.1    dyoung  *  @hw: pointer to hardware structure
   2301   1.1    dyoung  *
   2302   1.1    dyoung  *  Sets I2C start condition (High -> Low on SDA while SCL is High)
   2303   1.7   msaitoh  *  Set bit-bang mode on X550 hardware.
   2304   1.1    dyoung  **/
   2305   1.1    dyoung static void ixgbe_i2c_start(struct ixgbe_hw *hw)
   2306   1.1    dyoung {
   2307   1.7   msaitoh 	u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
   2308   1.1    dyoung 
   2309   1.1    dyoung 	DEBUGFUNC("ixgbe_i2c_start");
   2310   1.1    dyoung 
   2311   1.7   msaitoh 	i2cctl |= IXGBE_I2C_BB_EN_BY_MAC(hw);
   2312   1.7   msaitoh 
   2313   1.1    dyoung 	/* Start condition must begin with data and clock high */
   2314   1.1    dyoung 	ixgbe_set_i2c_data(hw, &i2cctl, 1);
   2315   1.1    dyoung 	ixgbe_raise_i2c_clk(hw, &i2cctl);
   2316   1.1    dyoung 
   2317   1.1    dyoung 	/* Setup time for start condition (4.7us) */
   2318   1.1    dyoung 	usec_delay(IXGBE_I2C_T_SU_STA);
   2319   1.1    dyoung 
   2320   1.1    dyoung 	ixgbe_set_i2c_data(hw, &i2cctl, 0);
   2321   1.1    dyoung 
   2322   1.1    dyoung 	/* Hold time for start condition (4us) */
   2323   1.1    dyoung 	usec_delay(IXGBE_I2C_T_HD_STA);
   2324   1.1    dyoung 
   2325   1.1    dyoung 	ixgbe_lower_i2c_clk(hw, &i2cctl);
   2326   1.1    dyoung 
   2327   1.1    dyoung 	/* Minimum low period of clock is 4.7 us */
   2328   1.1    dyoung 	usec_delay(IXGBE_I2C_T_LOW);
   2329   1.1    dyoung 
   2330   1.1    dyoung }
   2331   1.1    dyoung 
   2332   1.1    dyoung /**
   2333   1.1    dyoung  *  ixgbe_i2c_stop - Sets I2C stop condition
   2334   1.1    dyoung  *  @hw: pointer to hardware structure
   2335   1.1    dyoung  *
   2336   1.1    dyoung  *  Sets I2C stop condition (Low -> High on SDA while SCL is High)
   2337   1.7   msaitoh  *  Disables bit-bang mode and negates data output enable on X550
   2338   1.7   msaitoh  *  hardware.
   2339   1.1    dyoung  **/
   2340   1.1    dyoung static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
   2341   1.1    dyoung {
   2342   1.7   msaitoh 	u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
   2343   1.7   msaitoh 	u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
   2344   1.7   msaitoh 	u32 clk_oe_bit = IXGBE_I2C_CLK_OE_N_EN_BY_MAC(hw);
   2345   1.7   msaitoh 	u32 bb_en_bit = IXGBE_I2C_BB_EN_BY_MAC(hw);
   2346   1.1    dyoung 
   2347   1.1    dyoung 	DEBUGFUNC("ixgbe_i2c_stop");
   2348   1.1    dyoung 
   2349   1.1    dyoung 	/* Stop condition must begin with data low and clock high */
   2350   1.1    dyoung 	ixgbe_set_i2c_data(hw, &i2cctl, 0);
   2351   1.1    dyoung 	ixgbe_raise_i2c_clk(hw, &i2cctl);
   2352   1.1    dyoung 
   2353   1.1    dyoung 	/* Setup time for stop condition (4us) */
   2354   1.1    dyoung 	usec_delay(IXGBE_I2C_T_SU_STO);
   2355   1.1    dyoung 
   2356   1.1    dyoung 	ixgbe_set_i2c_data(hw, &i2cctl, 1);
   2357   1.1    dyoung 
   2358   1.1    dyoung 	/* bus free time between stop and start (4.7us)*/
   2359   1.1    dyoung 	usec_delay(IXGBE_I2C_T_BUF);
   2360   1.7   msaitoh 
   2361   1.7   msaitoh 	if (bb_en_bit || data_oe_bit || clk_oe_bit) {
   2362   1.7   msaitoh 		i2cctl &= ~bb_en_bit;
   2363   1.7   msaitoh 		i2cctl |= data_oe_bit | clk_oe_bit;
   2364   1.7   msaitoh 		IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), i2cctl);
   2365   1.7   msaitoh 		IXGBE_WRITE_FLUSH(hw);
   2366   1.7   msaitoh 	}
   2367   1.1    dyoung }
   2368   1.1    dyoung 
   2369   1.1    dyoung /**
   2370   1.1    dyoung  *  ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
   2371   1.1    dyoung  *  @hw: pointer to hardware structure
   2372   1.1    dyoung  *  @data: data byte to clock in
   2373   1.1    dyoung  *
   2374   1.1    dyoung  *  Clocks in one byte data via I2C data/clock
   2375   1.1    dyoung  **/
   2376   1.1    dyoung static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
   2377   1.1    dyoung {
   2378   1.1    dyoung 	s32 i;
   2379   1.1    dyoung 	bool bit = 0;
   2380   1.1    dyoung 
   2381   1.1    dyoung 	DEBUGFUNC("ixgbe_clock_in_i2c_byte");
   2382   1.1    dyoung 
   2383   1.7   msaitoh 	*data = 0;
   2384   1.1    dyoung 	for (i = 7; i >= 0; i--) {
   2385   1.3   msaitoh 		ixgbe_clock_in_i2c_bit(hw, &bit);
   2386   1.1    dyoung 		*data |= bit << i;
   2387   1.1    dyoung 	}
   2388   1.1    dyoung 
   2389   1.3   msaitoh 	return IXGBE_SUCCESS;
   2390   1.1    dyoung }
   2391   1.1    dyoung 
   2392   1.1    dyoung /**
   2393   1.1    dyoung  *  ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
   2394   1.1    dyoung  *  @hw: pointer to hardware structure
   2395   1.1    dyoung  *  @data: data byte clocked out
   2396   1.1    dyoung  *
   2397   1.1    dyoung  *  Clocks out one byte data via I2C data/clock
   2398   1.1    dyoung  **/
   2399   1.1    dyoung static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
   2400   1.1    dyoung {
   2401   1.1    dyoung 	s32 status = IXGBE_SUCCESS;
   2402   1.1    dyoung 	s32 i;
   2403   1.1    dyoung 	u32 i2cctl;
   2404   1.7   msaitoh 	bool bit;
   2405   1.1    dyoung 
   2406   1.1    dyoung 	DEBUGFUNC("ixgbe_clock_out_i2c_byte");
   2407   1.1    dyoung 
   2408   1.1    dyoung 	for (i = 7; i >= 0; i--) {
   2409   1.1    dyoung 		bit = (data >> i) & 0x1;
   2410   1.1    dyoung 		status = ixgbe_clock_out_i2c_bit(hw, bit);
   2411   1.1    dyoung 
   2412   1.1    dyoung 		if (status != IXGBE_SUCCESS)
   2413   1.1    dyoung 			break;
   2414   1.1    dyoung 	}
   2415   1.1    dyoung 
   2416   1.1    dyoung 	/* Release SDA line (set high) */
   2417   1.7   msaitoh 	i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
   2418   1.7   msaitoh 	i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
   2419   1.7   msaitoh 	i2cctl |= IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
   2420   1.7   msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), i2cctl);
   2421   1.3   msaitoh 	IXGBE_WRITE_FLUSH(hw);
   2422   1.1    dyoung 
   2423   1.1    dyoung 	return status;
   2424   1.1    dyoung }
   2425   1.1    dyoung 
   2426   1.1    dyoung /**
   2427   1.1    dyoung  *  ixgbe_get_i2c_ack - Polls for I2C ACK
   2428   1.1    dyoung  *  @hw: pointer to hardware structure
   2429   1.1    dyoung  *
   2430   1.1    dyoung  *  Clocks in/out one bit via I2C data/clock
   2431   1.1    dyoung  **/
   2432   1.1    dyoung static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
   2433   1.1    dyoung {
   2434   1.7   msaitoh 	u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
   2435   1.3   msaitoh 	s32 status = IXGBE_SUCCESS;
   2436   1.1    dyoung 	u32 i = 0;
   2437   1.7   msaitoh 	u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
   2438   1.1    dyoung 	u32 timeout = 10;
   2439   1.1    dyoung 	bool ack = 1;
   2440   1.1    dyoung 
   2441   1.1    dyoung 	DEBUGFUNC("ixgbe_get_i2c_ack");
   2442   1.1    dyoung 
   2443   1.7   msaitoh 	if (data_oe_bit) {
   2444   1.7   msaitoh 		i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
   2445   1.7   msaitoh 		i2cctl |= data_oe_bit;
   2446   1.7   msaitoh 		IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), i2cctl);
   2447   1.7   msaitoh 		IXGBE_WRITE_FLUSH(hw);
   2448   1.7   msaitoh 	}
   2449   1.3   msaitoh 	ixgbe_raise_i2c_clk(hw, &i2cctl);
   2450   1.1    dyoung 
   2451   1.1    dyoung 	/* Minimum high period of clock is 4us */
   2452   1.1    dyoung 	usec_delay(IXGBE_I2C_T_HIGH);
   2453   1.1    dyoung 
   2454   1.1    dyoung 	/* Poll for ACK.  Note that ACK in I2C spec is
   2455   1.1    dyoung 	 * transition from 1 to 0 */
   2456   1.1    dyoung 	for (i = 0; i < timeout; i++) {
   2457   1.7   msaitoh 		i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
   2458   1.7   msaitoh 		ack = ixgbe_get_i2c_data(hw, &i2cctl);
   2459   1.1    dyoung 
   2460   1.1    dyoung 		usec_delay(1);
   2461   1.7   msaitoh 		if (!ack)
   2462   1.1    dyoung 			break;
   2463   1.1    dyoung 	}
   2464   1.1    dyoung 
   2465   1.7   msaitoh 	if (ack) {
   2466   1.7   msaitoh 		DEBUGOUT("I2C ack was not received.\n");
   2467   1.1    dyoung 		status = IXGBE_ERR_I2C;
   2468   1.1    dyoung 	}
   2469   1.1    dyoung 
   2470   1.1    dyoung 	ixgbe_lower_i2c_clk(hw, &i2cctl);
   2471   1.1    dyoung 
   2472   1.1    dyoung 	/* Minimum low period of clock is 4.7 us */
   2473   1.1    dyoung 	usec_delay(IXGBE_I2C_T_LOW);
   2474   1.1    dyoung 
   2475   1.1    dyoung 	return status;
   2476   1.1    dyoung }
   2477   1.1    dyoung 
   2478   1.1    dyoung /**
   2479   1.1    dyoung  *  ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
   2480   1.1    dyoung  *  @hw: pointer to hardware structure
   2481   1.1    dyoung  *  @data: read data value
   2482   1.1    dyoung  *
   2483   1.1    dyoung  *  Clocks in one bit via I2C data/clock
   2484   1.1    dyoung  **/
   2485   1.1    dyoung static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
   2486   1.1    dyoung {
   2487   1.7   msaitoh 	u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
   2488   1.7   msaitoh 	u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
   2489   1.1    dyoung 
   2490   1.1    dyoung 	DEBUGFUNC("ixgbe_clock_in_i2c_bit");
   2491   1.1    dyoung 
   2492   1.7   msaitoh 	if (data_oe_bit) {
   2493   1.7   msaitoh 		i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
   2494   1.7   msaitoh 		i2cctl |= data_oe_bit;
   2495   1.7   msaitoh 		IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), i2cctl);
   2496   1.7   msaitoh 		IXGBE_WRITE_FLUSH(hw);
   2497   1.7   msaitoh 	}
   2498   1.3   msaitoh 	ixgbe_raise_i2c_clk(hw, &i2cctl);
   2499   1.1    dyoung 
   2500   1.1    dyoung 	/* Minimum high period of clock is 4us */
   2501   1.1    dyoung 	usec_delay(IXGBE_I2C_T_HIGH);
   2502   1.1    dyoung 
   2503   1.7   msaitoh 	i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
   2504   1.7   msaitoh 	*data = ixgbe_get_i2c_data(hw, &i2cctl);
   2505   1.1    dyoung 
   2506   1.1    dyoung 	ixgbe_lower_i2c_clk(hw, &i2cctl);
   2507   1.1    dyoung 
   2508   1.1    dyoung 	/* Minimum low period of clock is 4.7 us */
   2509   1.1    dyoung 	usec_delay(IXGBE_I2C_T_LOW);
   2510   1.1    dyoung 
   2511   1.3   msaitoh 	return IXGBE_SUCCESS;
   2512   1.1    dyoung }
   2513   1.1    dyoung 
   2514   1.1    dyoung /**
   2515   1.1    dyoung  *  ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
   2516   1.1    dyoung  *  @hw: pointer to hardware structure
   2517   1.1    dyoung  *  @data: data value to write
   2518   1.1    dyoung  *
   2519   1.1    dyoung  *  Clocks out one bit via I2C data/clock
   2520   1.1    dyoung  **/
   2521   1.1    dyoung static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
   2522   1.1    dyoung {
   2523   1.1    dyoung 	s32 status;
   2524   1.7   msaitoh 	u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
   2525   1.1    dyoung 
   2526   1.1    dyoung 	DEBUGFUNC("ixgbe_clock_out_i2c_bit");
   2527   1.1    dyoung 
   2528   1.1    dyoung 	status = ixgbe_set_i2c_data(hw, &i2cctl, data);
   2529   1.1    dyoung 	if (status == IXGBE_SUCCESS) {
   2530   1.3   msaitoh 		ixgbe_raise_i2c_clk(hw, &i2cctl);
   2531   1.1    dyoung 
   2532   1.1    dyoung 		/* Minimum high period of clock is 4us */
   2533   1.1    dyoung 		usec_delay(IXGBE_I2C_T_HIGH);
   2534   1.1    dyoung 
   2535   1.1    dyoung 		ixgbe_lower_i2c_clk(hw, &i2cctl);
   2536   1.1    dyoung 
   2537   1.1    dyoung 		/* Minimum low period of clock is 4.7 us.
   2538   1.1    dyoung 		 * This also takes care of the data hold time.
   2539   1.1    dyoung 		 */
   2540   1.1    dyoung 		usec_delay(IXGBE_I2C_T_LOW);
   2541   1.1    dyoung 	} else {
   2542   1.1    dyoung 		status = IXGBE_ERR_I2C;
   2543   1.6   msaitoh 		ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
   2544   1.6   msaitoh 			     "I2C data was not set to %X\n", data);
   2545   1.1    dyoung 	}
   2546   1.1    dyoung 
   2547   1.1    dyoung 	return status;
   2548   1.1    dyoung }
   2549   1.7   msaitoh 
   2550   1.1    dyoung /**
   2551   1.1    dyoung  *  ixgbe_raise_i2c_clk - Raises the I2C SCL clock
   2552   1.1    dyoung  *  @hw: pointer to hardware structure
   2553   1.1    dyoung  *  @i2cctl: Current value of I2CCTL register
   2554   1.1    dyoung  *
   2555   1.1    dyoung  *  Raises the I2C clock line '0'->'1'
   2556   1.7   msaitoh  *  Negates the I2C clock output enable on X550 hardware.
   2557   1.1    dyoung  **/
   2558   1.3   msaitoh static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
   2559   1.1    dyoung {
   2560   1.7   msaitoh 	u32 clk_oe_bit = IXGBE_I2C_CLK_OE_N_EN_BY_MAC(hw);
   2561   1.4   msaitoh 	u32 i = 0;
   2562   1.4   msaitoh 	u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
   2563   1.4   msaitoh 	u32 i2cctl_r = 0;
   2564   1.4   msaitoh 
   2565   1.1    dyoung 	DEBUGFUNC("ixgbe_raise_i2c_clk");
   2566   1.1    dyoung 
   2567   1.7   msaitoh 	if (clk_oe_bit) {
   2568   1.7   msaitoh 		*i2cctl |= clk_oe_bit;
   2569   1.7   msaitoh 		IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
   2570   1.7   msaitoh 	}
   2571   1.7   msaitoh 
   2572   1.4   msaitoh 	for (i = 0; i < timeout; i++) {
   2573   1.7   msaitoh 		*i2cctl |= IXGBE_I2C_CLK_OUT_BY_MAC(hw);
   2574   1.1    dyoung 
   2575   1.7   msaitoh 		IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
   2576   1.4   msaitoh 		IXGBE_WRITE_FLUSH(hw);
   2577   1.4   msaitoh 		/* SCL rise time (1000ns) */
   2578   1.4   msaitoh 		usec_delay(IXGBE_I2C_T_RISE);
   2579   1.1    dyoung 
   2580   1.7   msaitoh 		i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
   2581   1.7   msaitoh 		if (i2cctl_r & IXGBE_I2C_CLK_IN_BY_MAC(hw))
   2582   1.4   msaitoh 			break;
   2583   1.4   msaitoh 	}
   2584   1.1    dyoung }
   2585   1.1    dyoung 
   2586   1.1    dyoung /**
   2587   1.1    dyoung  *  ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
   2588   1.1    dyoung  *  @hw: pointer to hardware structure
   2589   1.1    dyoung  *  @i2cctl: Current value of I2CCTL register
   2590   1.1    dyoung  *
   2591   1.1    dyoung  *  Lowers the I2C clock line '1'->'0'
   2592   1.7   msaitoh  *  Asserts the I2C clock output enable on X550 hardware.
   2593   1.1    dyoung  **/
   2594   1.1    dyoung static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
   2595   1.1    dyoung {
   2596   1.1    dyoung 	DEBUGFUNC("ixgbe_lower_i2c_clk");
   2597   1.1    dyoung 
   2598   1.7   msaitoh 	*i2cctl &= ~(IXGBE_I2C_CLK_OUT_BY_MAC(hw));
   2599   1.7   msaitoh 	*i2cctl &= ~IXGBE_I2C_CLK_OE_N_EN_BY_MAC(hw);
   2600   1.1    dyoung 
   2601   1.7   msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
   2602   1.3   msaitoh 	IXGBE_WRITE_FLUSH(hw);
   2603   1.1    dyoung 
   2604   1.1    dyoung 	/* SCL fall time (300ns) */
   2605   1.1    dyoung 	usec_delay(IXGBE_I2C_T_FALL);
   2606   1.1    dyoung }
   2607   1.1    dyoung 
   2608   1.1    dyoung /**
   2609   1.1    dyoung  *  ixgbe_set_i2c_data - Sets the I2C data bit
   2610   1.1    dyoung  *  @hw: pointer to hardware structure
   2611   1.1    dyoung  *  @i2cctl: Current value of I2CCTL register
   2612   1.1    dyoung  *  @data: I2C data value (0 or 1) to set
   2613   1.1    dyoung  *
   2614   1.1    dyoung  *  Sets the I2C data bit
   2615   1.7   msaitoh  *  Asserts the I2C data output enable on X550 hardware.
   2616   1.1    dyoung  **/
   2617   1.1    dyoung static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
   2618   1.1    dyoung {
   2619   1.7   msaitoh 	u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
   2620   1.1    dyoung 	s32 status = IXGBE_SUCCESS;
   2621   1.1    dyoung 
   2622   1.1    dyoung 	DEBUGFUNC("ixgbe_set_i2c_data");
   2623   1.1    dyoung 
   2624   1.1    dyoung 	if (data)
   2625   1.7   msaitoh 		*i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
   2626   1.1    dyoung 	else
   2627   1.7   msaitoh 		*i2cctl &= ~(IXGBE_I2C_DATA_OUT_BY_MAC(hw));
   2628   1.7   msaitoh 	*i2cctl &= ~data_oe_bit;
   2629   1.1    dyoung 
   2630   1.7   msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
   2631   1.3   msaitoh 	IXGBE_WRITE_FLUSH(hw);
   2632   1.1    dyoung 
   2633   1.1    dyoung 	/* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
   2634   1.1    dyoung 	usec_delay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
   2635   1.1    dyoung 
   2636   1.7   msaitoh 	if (!data)	/* Can't verify data in this case */
   2637   1.7   msaitoh 		return IXGBE_SUCCESS;
   2638   1.7   msaitoh 	if (data_oe_bit) {
   2639   1.7   msaitoh 		*i2cctl |= data_oe_bit;
   2640   1.7   msaitoh 		IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
   2641   1.7   msaitoh 		IXGBE_WRITE_FLUSH(hw);
   2642   1.7   msaitoh 	}
   2643   1.7   msaitoh 
   2644   1.1    dyoung 	/* Verify data was set correctly */
   2645   1.7   msaitoh 	*i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
   2646   1.7   msaitoh 	if (data != ixgbe_get_i2c_data(hw, i2cctl)) {
   2647   1.1    dyoung 		status = IXGBE_ERR_I2C;
   2648   1.6   msaitoh 		ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
   2649   1.6   msaitoh 			     "Error - I2C data was not set to %X.\n",
   2650   1.6   msaitoh 			     data);
   2651   1.1    dyoung 	}
   2652   1.1    dyoung 
   2653   1.1    dyoung 	return status;
   2654   1.1    dyoung }
   2655   1.1    dyoung 
   2656   1.1    dyoung /**
   2657   1.1    dyoung  *  ixgbe_get_i2c_data - Reads the I2C SDA data bit
   2658   1.1    dyoung  *  @hw: pointer to hardware structure
   2659   1.1    dyoung  *  @i2cctl: Current value of I2CCTL register
   2660   1.1    dyoung  *
   2661   1.1    dyoung  *  Returns the I2C data bit value
   2662   1.7   msaitoh  *  Negates the I2C data output enable on X550 hardware.
   2663   1.1    dyoung  **/
   2664   1.7   msaitoh static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl)
   2665   1.1    dyoung {
   2666   1.7   msaitoh 	u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
   2667   1.1    dyoung 	bool data;
   2668   1.1    dyoung 
   2669   1.1    dyoung 	DEBUGFUNC("ixgbe_get_i2c_data");
   2670   1.1    dyoung 
   2671   1.7   msaitoh 	if (data_oe_bit) {
   2672   1.7   msaitoh 		*i2cctl |= data_oe_bit;
   2673   1.7   msaitoh 		IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
   2674   1.7   msaitoh 		IXGBE_WRITE_FLUSH(hw);
   2675   1.7   msaitoh 		usec_delay(IXGBE_I2C_T_FALL);
   2676   1.7   msaitoh 	}
   2677   1.7   msaitoh 
   2678   1.7   msaitoh 	if (*i2cctl & IXGBE_I2C_DATA_IN_BY_MAC(hw))
   2679   1.1    dyoung 		data = 1;
   2680   1.1    dyoung 	else
   2681   1.1    dyoung 		data = 0;
   2682   1.1    dyoung 
   2683   1.1    dyoung 	return data;
   2684   1.1    dyoung }
   2685   1.1    dyoung 
   2686   1.1    dyoung /**
   2687   1.1    dyoung  *  ixgbe_i2c_bus_clear - Clears the I2C bus
   2688   1.1    dyoung  *  @hw: pointer to hardware structure
   2689   1.1    dyoung  *
   2690   1.1    dyoung  *  Clears the I2C bus by sending nine clock pulses.
   2691   1.1    dyoung  *  Used when data line is stuck low.
   2692   1.1    dyoung  **/
   2693   1.1    dyoung void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
   2694   1.1    dyoung {
   2695   1.7   msaitoh 	u32 i2cctl;
   2696   1.1    dyoung 	u32 i;
   2697   1.1    dyoung 
   2698   1.1    dyoung 	DEBUGFUNC("ixgbe_i2c_bus_clear");
   2699   1.1    dyoung 
   2700   1.1    dyoung 	ixgbe_i2c_start(hw);
   2701   1.7   msaitoh 	i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
   2702   1.1    dyoung 
   2703   1.1    dyoung 	ixgbe_set_i2c_data(hw, &i2cctl, 1);
   2704   1.1    dyoung 
   2705   1.1    dyoung 	for (i = 0; i < 9; i++) {
   2706   1.1    dyoung 		ixgbe_raise_i2c_clk(hw, &i2cctl);
   2707   1.1    dyoung 
   2708   1.1    dyoung 		/* Min high period of clock is 4us */
   2709   1.1    dyoung 		usec_delay(IXGBE_I2C_T_HIGH);
   2710   1.1    dyoung 
   2711   1.1    dyoung 		ixgbe_lower_i2c_clk(hw, &i2cctl);
   2712   1.1    dyoung 
   2713   1.1    dyoung 		/* Min low period of clock is 4.7us*/
   2714   1.1    dyoung 		usec_delay(IXGBE_I2C_T_LOW);
   2715   1.1    dyoung 	}
   2716   1.1    dyoung 
   2717   1.1    dyoung 	ixgbe_i2c_start(hw);
   2718   1.1    dyoung 
   2719   1.1    dyoung 	/* Put the i2c bus back to default state */
   2720   1.1    dyoung 	ixgbe_i2c_stop(hw);
   2721   1.1    dyoung }
   2722   1.1    dyoung 
   2723   1.1    dyoung /**
   2724   1.4   msaitoh  *  ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
   2725   1.1    dyoung  *  @hw: pointer to hardware structure
   2726   1.1    dyoung  *
   2727   1.1    dyoung  *  Checks if the LASI temp alarm status was triggered due to overtemp
   2728   1.1    dyoung  **/
   2729   1.1    dyoung s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
   2730   1.1    dyoung {
   2731   1.1    dyoung 	s32 status = IXGBE_SUCCESS;
   2732   1.1    dyoung 	u16 phy_data = 0;
   2733   1.1    dyoung 
   2734   1.1    dyoung 	DEBUGFUNC("ixgbe_tn_check_overtemp");
   2735   1.1    dyoung 
   2736   1.1    dyoung 	if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
   2737   1.1    dyoung 		goto out;
   2738   1.1    dyoung 
   2739   1.1    dyoung 	/* Check that the LASI temp alarm status was triggered */
   2740   1.1    dyoung 	hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
   2741   1.1    dyoung 			     IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_data);
   2742   1.1    dyoung 
   2743   1.1    dyoung 	if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
   2744   1.1    dyoung 		goto out;
   2745   1.1    dyoung 
   2746   1.1    dyoung 	status = IXGBE_ERR_OVERTEMP;
   2747   1.6   msaitoh 	ERROR_REPORT1(IXGBE_ERROR_CAUTION, "Device over temperature");
   2748   1.1    dyoung out:
   2749   1.1    dyoung 	return status;
   2750   1.1    dyoung }
   2751   1.7   msaitoh 
   2752   1.7   msaitoh /**
   2753   1.7   msaitoh  * ixgbe_set_copper_phy_power - Control power for copper phy
   2754   1.7   msaitoh  * @hw: pointer to hardware structure
   2755   1.7   msaitoh  * @on: TRUE for on, FALSE for off
   2756   1.7   msaitoh  */
   2757   1.7   msaitoh s32 ixgbe_set_copper_phy_power(struct ixgbe_hw *hw, bool on)
   2758   1.7   msaitoh {
   2759   1.7   msaitoh 	u32 status;
   2760   1.7   msaitoh 	u16 reg;
   2761   1.7   msaitoh 
   2762  1.10   msaitoh 	if (!on && ixgbe_mng_present(hw))
   2763  1.10   msaitoh 		return 0;
   2764  1.10   msaitoh 
   2765   1.7   msaitoh 	status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
   2766   1.7   msaitoh 				      IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   2767   1.7   msaitoh 				      &reg);
   2768   1.7   msaitoh 	if (status)
   2769   1.7   msaitoh 		return status;
   2770   1.7   msaitoh 
   2771   1.7   msaitoh 	if (on) {
   2772   1.7   msaitoh 		reg &= ~IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
   2773   1.7   msaitoh 	} else {
   2774   1.7   msaitoh 		if (ixgbe_check_reset_blocked(hw))
   2775   1.7   msaitoh 			return 0;
   2776   1.7   msaitoh 		reg |= IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
   2777   1.7   msaitoh 	}
   2778   1.7   msaitoh 
   2779   1.7   msaitoh 	status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
   2780   1.7   msaitoh 				       IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   2781   1.7   msaitoh 				       reg);
   2782   1.7   msaitoh 	return status;
   2783   1.7   msaitoh }
   2784