Home | History | Annotate | Line # | Download | only in ixgbe
ixgbe_x550.c revision 1.13
      1   1.1  msaitoh /******************************************************************************
      2   1.1  msaitoh 
      3   1.6  msaitoh   Copyright (c) 2001-2017, Intel Corporation
      4   1.1  msaitoh   All rights reserved.
      5   1.6  msaitoh 
      6   1.6  msaitoh   Redistribution and use in source and binary forms, with or without
      7   1.1  msaitoh   modification, are permitted provided that the following conditions are met:
      8   1.6  msaitoh 
      9   1.6  msaitoh    1. Redistributions of source code must retain the above copyright notice,
     10   1.1  msaitoh       this list of conditions and the following disclaimer.
     11   1.6  msaitoh 
     12   1.6  msaitoh    2. Redistributions in binary form must reproduce the above copyright
     13   1.6  msaitoh       notice, this list of conditions and the following disclaimer in the
     14   1.1  msaitoh       documentation and/or other materials provided with the distribution.
     15   1.6  msaitoh 
     16   1.6  msaitoh    3. Neither the name of the Intel Corporation nor the names of its
     17   1.6  msaitoh       contributors may be used to endorse or promote products derived from
     18   1.1  msaitoh       this software without specific prior written permission.
     19   1.6  msaitoh 
     20   1.1  msaitoh   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     21   1.6  msaitoh   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22   1.6  msaitoh   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23   1.6  msaitoh   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     24   1.6  msaitoh   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25   1.6  msaitoh   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26   1.6  msaitoh   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27   1.6  msaitoh   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28   1.6  msaitoh   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29   1.1  msaitoh   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30   1.1  msaitoh   POSSIBILITY OF SUCH DAMAGE.
     31   1.1  msaitoh 
     32   1.1  msaitoh ******************************************************************************/
     33  1.12  msaitoh /*$FreeBSD: head/sys/dev/ixgbe/ixgbe_x550.c 331224 2018-03-19 20:55:05Z erj $*/
     34   1.1  msaitoh 
     35   1.1  msaitoh #include "ixgbe_x550.h"
     36   1.1  msaitoh #include "ixgbe_x540.h"
     37   1.1  msaitoh #include "ixgbe_type.h"
     38   1.1  msaitoh #include "ixgbe_api.h"
     39   1.1  msaitoh #include "ixgbe_common.h"
     40   1.1  msaitoh #include "ixgbe_phy.h"
     41   1.7  msaitoh #include <dev/mii/mii.h>
     42   1.1  msaitoh 
     43   1.1  msaitoh static s32 ixgbe_setup_ixfi_x550em(struct ixgbe_hw *hw, ixgbe_link_speed *speed);
     44  1.10  msaitoh static s32 ixgbe_setup_mac_link_sfp_x550a(struct ixgbe_hw *hw,
     45  1.10  msaitoh 				    ixgbe_link_speed speed,
     46  1.10  msaitoh 				    bool autoneg_wait_to_complete);
     47   1.6  msaitoh static s32 ixgbe_acquire_swfw_sync_X550a(struct ixgbe_hw *, u32 mask);
     48   1.6  msaitoh static void ixgbe_release_swfw_sync_X550a(struct ixgbe_hw *, u32 mask);
     49   1.6  msaitoh static s32 ixgbe_read_mng_if_sel_x550em(struct ixgbe_hw *hw);
     50   1.1  msaitoh 
     51   1.1  msaitoh /**
     52   1.1  msaitoh  *  ixgbe_init_ops_X550 - Inits func ptrs and MAC type
     53   1.1  msaitoh  *  @hw: pointer to hardware structure
     54   1.1  msaitoh  *
     55   1.1  msaitoh  *  Initialize the function pointers and assign the MAC type for X550.
     56   1.1  msaitoh  *  Does not touch the hardware.
     57   1.1  msaitoh  **/
     58   1.1  msaitoh s32 ixgbe_init_ops_X550(struct ixgbe_hw *hw)
     59   1.1  msaitoh {
     60   1.1  msaitoh 	struct ixgbe_mac_info *mac = &hw->mac;
     61   1.1  msaitoh 	struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
     62   1.1  msaitoh 	s32 ret_val;
     63   1.1  msaitoh 
     64   1.1  msaitoh 	DEBUGFUNC("ixgbe_init_ops_X550");
     65   1.1  msaitoh 
     66   1.1  msaitoh 	ret_val = ixgbe_init_ops_X540(hw);
     67   1.1  msaitoh 	mac->ops.dmac_config = ixgbe_dmac_config_X550;
     68   1.1  msaitoh 	mac->ops.dmac_config_tcs = ixgbe_dmac_config_tcs_X550;
     69   1.1  msaitoh 	mac->ops.dmac_update_tcs = ixgbe_dmac_update_tcs_X550;
     70   1.6  msaitoh 	mac->ops.setup_eee = NULL;
     71   1.1  msaitoh 	mac->ops.set_source_address_pruning =
     72   1.1  msaitoh 			ixgbe_set_source_address_pruning_X550;
     73   1.1  msaitoh 	mac->ops.set_ethertype_anti_spoofing =
     74   1.1  msaitoh 			ixgbe_set_ethertype_anti_spoofing_X550;
     75   1.1  msaitoh 
     76   1.1  msaitoh 	mac->ops.get_rtrup2tc = ixgbe_dcb_get_rtrup2tc_generic;
     77   1.1  msaitoh 	eeprom->ops.init_params = ixgbe_init_eeprom_params_X550;
     78   1.1  msaitoh 	eeprom->ops.calc_checksum = ixgbe_calc_eeprom_checksum_X550;
     79   1.1  msaitoh 	eeprom->ops.read = ixgbe_read_ee_hostif_X550;
     80   1.1  msaitoh 	eeprom->ops.read_buffer = ixgbe_read_ee_hostif_buffer_X550;
     81   1.1  msaitoh 	eeprom->ops.write = ixgbe_write_ee_hostif_X550;
     82   1.1  msaitoh 	eeprom->ops.write_buffer = ixgbe_write_ee_hostif_buffer_X550;
     83   1.1  msaitoh 	eeprom->ops.update_checksum = ixgbe_update_eeprom_checksum_X550;
     84   1.1  msaitoh 	eeprom->ops.validate_checksum = ixgbe_validate_eeprom_checksum_X550;
     85   1.1  msaitoh 
     86   1.1  msaitoh 	mac->ops.disable_mdd = ixgbe_disable_mdd_X550;
     87   1.1  msaitoh 	mac->ops.enable_mdd = ixgbe_enable_mdd_X550;
     88   1.1  msaitoh 	mac->ops.mdd_event = ixgbe_mdd_event_X550;
     89   1.1  msaitoh 	mac->ops.restore_mdd_vf = ixgbe_restore_mdd_vf_X550;
     90   1.1  msaitoh 	mac->ops.disable_rx = ixgbe_disable_rx_x550;
     91   1.6  msaitoh 	/* Manageability interface */
     92   1.6  msaitoh 	mac->ops.set_fw_drv_ver = ixgbe_set_fw_drv_ver_x550;
     93   1.6  msaitoh 	switch (hw->device_id) {
     94   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_X_1G_T:
     95   1.6  msaitoh 		hw->mac.ops.led_on = NULL;
     96   1.6  msaitoh 		hw->mac.ops.led_off = NULL;
     97   1.6  msaitoh 		break;
     98   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_X_10G_T:
     99   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_10G_T:
    100   1.1  msaitoh 		hw->mac.ops.led_on = ixgbe_led_on_t_X550em;
    101   1.1  msaitoh 		hw->mac.ops.led_off = ixgbe_led_off_t_X550em;
    102   1.6  msaitoh 		break;
    103   1.6  msaitoh 	default:
    104   1.6  msaitoh 		break;
    105   1.1  msaitoh 	}
    106   1.1  msaitoh 	return ret_val;
    107   1.1  msaitoh }
    108   1.1  msaitoh 
    109   1.1  msaitoh /**
    110   1.1  msaitoh  * ixgbe_read_cs4227 - Read CS4227 register
    111   1.1  msaitoh  * @hw: pointer to hardware structure
    112   1.1  msaitoh  * @reg: register number to write
    113   1.1  msaitoh  * @value: pointer to receive value read
    114   1.1  msaitoh  *
    115   1.1  msaitoh  * Returns status code
    116   1.1  msaitoh  **/
    117   1.1  msaitoh static s32 ixgbe_read_cs4227(struct ixgbe_hw *hw, u16 reg, u16 *value)
    118   1.1  msaitoh {
    119   1.6  msaitoh 	return hw->link.ops.read_link_unlocked(hw, hw->link.addr, reg, value);
    120   1.1  msaitoh }
    121   1.1  msaitoh 
    122   1.1  msaitoh /**
    123   1.1  msaitoh  * ixgbe_write_cs4227 - Write CS4227 register
    124   1.1  msaitoh  * @hw: pointer to hardware structure
    125   1.1  msaitoh  * @reg: register number to write
    126   1.1  msaitoh  * @value: value to write to register
    127   1.1  msaitoh  *
    128   1.1  msaitoh  * Returns status code
    129   1.1  msaitoh  **/
    130   1.1  msaitoh static s32 ixgbe_write_cs4227(struct ixgbe_hw *hw, u16 reg, u16 value)
    131   1.1  msaitoh {
    132   1.6  msaitoh 	return hw->link.ops.write_link_unlocked(hw, hw->link.addr, reg, value);
    133   1.1  msaitoh }
    134   1.1  msaitoh 
    135   1.1  msaitoh /**
    136   1.1  msaitoh  * ixgbe_read_pe - Read register from port expander
    137   1.1  msaitoh  * @hw: pointer to hardware structure
    138   1.1  msaitoh  * @reg: register number to read
    139   1.1  msaitoh  * @value: pointer to receive read value
    140   1.1  msaitoh  *
    141   1.1  msaitoh  * Returns status code
    142   1.1  msaitoh  **/
    143   1.1  msaitoh static s32 ixgbe_read_pe(struct ixgbe_hw *hw, u8 reg, u8 *value)
    144   1.1  msaitoh {
    145   1.1  msaitoh 	s32 status;
    146   1.1  msaitoh 
    147   1.1  msaitoh 	status = ixgbe_read_i2c_byte_unlocked(hw, reg, IXGBE_PE, value);
    148   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
    149   1.1  msaitoh 		ERROR_REPORT2(IXGBE_ERROR_CAUTION,
    150   1.1  msaitoh 			      "port expander access failed with %d\n", status);
    151   1.1  msaitoh 	return status;
    152   1.1  msaitoh }
    153   1.1  msaitoh 
    154   1.1  msaitoh /**
    155   1.1  msaitoh  * ixgbe_write_pe - Write register to port expander
    156   1.1  msaitoh  * @hw: pointer to hardware structure
    157   1.1  msaitoh  * @reg: register number to write
    158   1.1  msaitoh  * @value: value to write
    159   1.1  msaitoh  *
    160   1.1  msaitoh  * Returns status code
    161   1.1  msaitoh  **/
    162   1.1  msaitoh static s32 ixgbe_write_pe(struct ixgbe_hw *hw, u8 reg, u8 value)
    163   1.1  msaitoh {
    164   1.1  msaitoh 	s32 status;
    165   1.1  msaitoh 
    166   1.1  msaitoh 	status = ixgbe_write_i2c_byte_unlocked(hw, reg, IXGBE_PE, value);
    167   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
    168   1.1  msaitoh 		ERROR_REPORT2(IXGBE_ERROR_CAUTION,
    169   1.1  msaitoh 			      "port expander access failed with %d\n", status);
    170   1.1  msaitoh 	return status;
    171   1.1  msaitoh }
    172   1.1  msaitoh 
    173   1.1  msaitoh /**
    174   1.1  msaitoh  * ixgbe_reset_cs4227 - Reset CS4227 using port expander
    175   1.1  msaitoh  * @hw: pointer to hardware structure
    176   1.1  msaitoh  *
    177   1.2  msaitoh  * This function assumes that the caller has acquired the proper semaphore.
    178   1.1  msaitoh  * Returns error code
    179   1.1  msaitoh  **/
    180   1.1  msaitoh static s32 ixgbe_reset_cs4227(struct ixgbe_hw *hw)
    181   1.1  msaitoh {
    182   1.1  msaitoh 	s32 status;
    183   1.2  msaitoh 	u32 retry;
    184   1.2  msaitoh 	u16 value;
    185   1.1  msaitoh 	u8 reg;
    186   1.1  msaitoh 
    187   1.2  msaitoh 	/* Trigger hard reset. */
    188   1.1  msaitoh 	status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, &reg);
    189   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
    190   1.1  msaitoh 		return status;
    191   1.1  msaitoh 	reg |= IXGBE_PE_BIT1;
    192   1.1  msaitoh 	status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
    193   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
    194   1.1  msaitoh 		return status;
    195   1.1  msaitoh 
    196   1.1  msaitoh 	status = ixgbe_read_pe(hw, IXGBE_PE_CONFIG, &reg);
    197   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
    198   1.1  msaitoh 		return status;
    199   1.1  msaitoh 	reg &= ~IXGBE_PE_BIT1;
    200   1.1  msaitoh 	status = ixgbe_write_pe(hw, IXGBE_PE_CONFIG, reg);
    201   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
    202   1.1  msaitoh 		return status;
    203   1.1  msaitoh 
    204   1.1  msaitoh 	status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, &reg);
    205   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
    206   1.1  msaitoh 		return status;
    207   1.1  msaitoh 	reg &= ~IXGBE_PE_BIT1;
    208   1.1  msaitoh 	status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
    209   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
    210   1.1  msaitoh 		return status;
    211   1.1  msaitoh 
    212   1.1  msaitoh 	usec_delay(IXGBE_CS4227_RESET_HOLD);
    213   1.1  msaitoh 
    214   1.1  msaitoh 	status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, &reg);
    215   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
    216   1.1  msaitoh 		return status;
    217   1.1  msaitoh 	reg |= IXGBE_PE_BIT1;
    218   1.1  msaitoh 	status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
    219   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
    220   1.1  msaitoh 		return status;
    221   1.1  msaitoh 
    222   1.2  msaitoh 	/* Wait for the reset to complete. */
    223   1.1  msaitoh 	msec_delay(IXGBE_CS4227_RESET_DELAY);
    224   1.2  msaitoh 	for (retry = 0; retry < IXGBE_CS4227_RETRIES; retry++) {
    225   1.2  msaitoh 		status = ixgbe_read_cs4227(hw, IXGBE_CS4227_EFUSE_STATUS,
    226   1.2  msaitoh 					   &value);
    227   1.2  msaitoh 		if (status == IXGBE_SUCCESS &&
    228   1.2  msaitoh 		    value == IXGBE_CS4227_EEPROM_LOAD_OK)
    229   1.2  msaitoh 			break;
    230   1.2  msaitoh 		msec_delay(IXGBE_CS4227_CHECK_DELAY);
    231   1.2  msaitoh 	}
    232   1.2  msaitoh 	if (retry == IXGBE_CS4227_RETRIES) {
    233   1.2  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_INVALID_STATE,
    234   1.2  msaitoh 			"CS4227 reset did not complete.");
    235   1.2  msaitoh 		return IXGBE_ERR_PHY;
    236   1.2  msaitoh 	}
    237   1.2  msaitoh 
    238   1.2  msaitoh 	status = ixgbe_read_cs4227(hw, IXGBE_CS4227_EEPROM_STATUS, &value);
    239   1.2  msaitoh 	if (status != IXGBE_SUCCESS ||
    240   1.2  msaitoh 	    !(value & IXGBE_CS4227_EEPROM_LOAD_OK)) {
    241   1.2  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_INVALID_STATE,
    242   1.2  msaitoh 			"CS4227 EEPROM did not load successfully.");
    243   1.2  msaitoh 		return IXGBE_ERR_PHY;
    244   1.2  msaitoh 	}
    245   1.1  msaitoh 
    246   1.1  msaitoh 	return IXGBE_SUCCESS;
    247   1.1  msaitoh }
    248   1.1  msaitoh 
    249   1.1  msaitoh /**
    250   1.1  msaitoh  * ixgbe_check_cs4227 - Check CS4227 and reset as needed
    251   1.1  msaitoh  * @hw: pointer to hardware structure
    252   1.1  msaitoh  **/
    253   1.1  msaitoh static void ixgbe_check_cs4227(struct ixgbe_hw *hw)
    254   1.1  msaitoh {
    255   1.2  msaitoh 	s32 status = IXGBE_SUCCESS;
    256   1.1  msaitoh 	u32 swfw_mask = hw->phy.phy_semaphore_mask;
    257   1.2  msaitoh 	u16 value = 0;
    258   1.1  msaitoh 	u8 retry;
    259   1.1  msaitoh 
    260   1.1  msaitoh 	for (retry = 0; retry < IXGBE_CS4227_RETRIES; retry++) {
    261   1.1  msaitoh 		status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
    262   1.1  msaitoh 		if (status != IXGBE_SUCCESS) {
    263   1.1  msaitoh 			ERROR_REPORT2(IXGBE_ERROR_CAUTION,
    264   1.2  msaitoh 				"semaphore failed with %d", status);
    265   1.2  msaitoh 			msec_delay(IXGBE_CS4227_CHECK_DELAY);
    266   1.2  msaitoh 			continue;
    267   1.1  msaitoh 		}
    268   1.2  msaitoh 
    269   1.2  msaitoh 		/* Get status of reset flow. */
    270   1.2  msaitoh 		status = ixgbe_read_cs4227(hw, IXGBE_CS4227_SCRATCH, &value);
    271   1.2  msaitoh 
    272   1.2  msaitoh 		if (status == IXGBE_SUCCESS &&
    273   1.2  msaitoh 		    value == IXGBE_CS4227_RESET_COMPLETE)
    274   1.2  msaitoh 			goto out;
    275   1.2  msaitoh 
    276   1.2  msaitoh 		if (status != IXGBE_SUCCESS ||
    277   1.2  msaitoh 		    value != IXGBE_CS4227_RESET_PENDING)
    278   1.2  msaitoh 			break;
    279   1.2  msaitoh 
    280   1.2  msaitoh 		/* Reset is pending. Wait and check again. */
    281   1.2  msaitoh 		hw->mac.ops.release_swfw_sync(hw, swfw_mask);
    282   1.2  msaitoh 		msec_delay(IXGBE_CS4227_CHECK_DELAY);
    283   1.2  msaitoh 	}
    284   1.2  msaitoh 
    285   1.2  msaitoh 	/* If still pending, assume other instance failed. */
    286   1.2  msaitoh 	if (retry == IXGBE_CS4227_RETRIES) {
    287   1.2  msaitoh 		status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
    288   1.2  msaitoh 		if (status != IXGBE_SUCCESS) {
    289   1.2  msaitoh 			ERROR_REPORT2(IXGBE_ERROR_CAUTION,
    290   1.2  msaitoh 				      "semaphore failed with %d", status);
    291   1.1  msaitoh 			return;
    292   1.1  msaitoh 		}
    293   1.1  msaitoh 	}
    294   1.2  msaitoh 
    295   1.2  msaitoh 	/* Reset the CS4227. */
    296   1.2  msaitoh 	status = ixgbe_reset_cs4227(hw);
    297   1.2  msaitoh 	if (status != IXGBE_SUCCESS) {
    298   1.2  msaitoh 		ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
    299   1.2  msaitoh 			"CS4227 reset failed: %d", status);
    300   1.2  msaitoh 		goto out;
    301   1.2  msaitoh 	}
    302   1.2  msaitoh 
    303   1.2  msaitoh 	/* Reset takes so long, temporarily release semaphore in case the
    304   1.2  msaitoh 	 * other driver instance is waiting for the reset indication.
    305   1.2  msaitoh 	 */
    306   1.2  msaitoh 	ixgbe_write_cs4227(hw, IXGBE_CS4227_SCRATCH,
    307   1.2  msaitoh 			   IXGBE_CS4227_RESET_PENDING);
    308   1.2  msaitoh 	hw->mac.ops.release_swfw_sync(hw, swfw_mask);
    309   1.2  msaitoh 	msec_delay(10);
    310   1.2  msaitoh 	status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
    311   1.2  msaitoh 	if (status != IXGBE_SUCCESS) {
    312   1.2  msaitoh 		ERROR_REPORT2(IXGBE_ERROR_CAUTION,
    313   1.2  msaitoh 			"semaphore failed with %d", status);
    314   1.2  msaitoh 		return;
    315   1.2  msaitoh 	}
    316   1.2  msaitoh 
    317   1.2  msaitoh 	/* Record completion for next time. */
    318   1.2  msaitoh 	status = ixgbe_write_cs4227(hw, IXGBE_CS4227_SCRATCH,
    319   1.2  msaitoh 		IXGBE_CS4227_RESET_COMPLETE);
    320   1.2  msaitoh 
    321   1.2  msaitoh out:
    322   1.2  msaitoh 	hw->mac.ops.release_swfw_sync(hw, swfw_mask);
    323   1.2  msaitoh 	msec_delay(hw->eeprom.semaphore_delay);
    324   1.1  msaitoh }
    325   1.1  msaitoh 
    326   1.1  msaitoh /**
    327   1.1  msaitoh  * ixgbe_setup_mux_ctl - Setup ESDP register for I2C mux control
    328   1.1  msaitoh  * @hw: pointer to hardware structure
    329   1.1  msaitoh  **/
    330   1.1  msaitoh static void ixgbe_setup_mux_ctl(struct ixgbe_hw *hw)
    331   1.1  msaitoh {
    332   1.1  msaitoh 	u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
    333   1.1  msaitoh 
    334   1.1  msaitoh 	if (hw->bus.lan_id) {
    335   1.1  msaitoh 		esdp &= ~(IXGBE_ESDP_SDP1_NATIVE | IXGBE_ESDP_SDP1);
    336   1.1  msaitoh 		esdp |= IXGBE_ESDP_SDP1_DIR;
    337   1.1  msaitoh 	}
    338   1.1  msaitoh 	esdp &= ~(IXGBE_ESDP_SDP0_NATIVE | IXGBE_ESDP_SDP0_DIR);
    339   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
    340   1.1  msaitoh 	IXGBE_WRITE_FLUSH(hw);
    341   1.1  msaitoh }
    342   1.1  msaitoh 
    343   1.1  msaitoh /**
    344   1.6  msaitoh  * ixgbe_read_phy_reg_mdi_22 - Read from a clause 22 PHY register without lock
    345   1.6  msaitoh  * @hw: pointer to hardware structure
    346   1.6  msaitoh  * @reg_addr: 32 bit address of PHY register to read
    347   1.6  msaitoh  * @dev_type: always unused
    348   1.6  msaitoh  * @phy_data: Pointer to read data from PHY register
    349   1.6  msaitoh  */
    350   1.6  msaitoh static s32 ixgbe_read_phy_reg_mdi_22(struct ixgbe_hw *hw, u32 reg_addr,
    351   1.6  msaitoh 				     u32 dev_type, u16 *phy_data)
    352   1.6  msaitoh {
    353   1.6  msaitoh 	u32 i, data, command;
    354   1.6  msaitoh 	UNREFERENCED_1PARAMETER(dev_type);
    355   1.6  msaitoh 
    356   1.6  msaitoh 	/* Setup and write the read command */
    357   1.6  msaitoh 	command = (reg_addr << IXGBE_MSCA_DEV_TYPE_SHIFT) |
    358   1.6  msaitoh 		  (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
    359   1.6  msaitoh 		  IXGBE_MSCA_OLD_PROTOCOL | IXGBE_MSCA_READ_AUTOINC |
    360   1.6  msaitoh 		  IXGBE_MSCA_MDI_COMMAND;
    361   1.6  msaitoh 
    362   1.6  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
    363   1.6  msaitoh 
    364   1.6  msaitoh 	/* Check every 10 usec to see if the access completed.
    365   1.6  msaitoh 	 * The MDI Command bit will clear when the operation is
    366   1.6  msaitoh 	 * complete
    367   1.6  msaitoh 	 */
    368   1.6  msaitoh 	for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
    369   1.6  msaitoh 		usec_delay(10);
    370   1.6  msaitoh 
    371   1.6  msaitoh 		command = IXGBE_READ_REG(hw, IXGBE_MSCA);
    372   1.6  msaitoh 		if (!(command & IXGBE_MSCA_MDI_COMMAND))
    373   1.6  msaitoh 			break;
    374   1.6  msaitoh 	}
    375   1.6  msaitoh 
    376   1.6  msaitoh 	if (command & IXGBE_MSCA_MDI_COMMAND) {
    377   1.6  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_POLLING,
    378   1.6  msaitoh 			      "PHY read command did not complete.\n");
    379   1.6  msaitoh 		return IXGBE_ERR_PHY;
    380   1.6  msaitoh 	}
    381   1.6  msaitoh 
    382   1.6  msaitoh 	/* Read operation is complete.  Get the data from MSRWD */
    383   1.6  msaitoh 	data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
    384   1.6  msaitoh 	data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
    385   1.6  msaitoh 	*phy_data = (u16)data;
    386   1.6  msaitoh 
    387   1.6  msaitoh 	return IXGBE_SUCCESS;
    388   1.6  msaitoh }
    389   1.6  msaitoh 
    390   1.6  msaitoh /**
    391   1.6  msaitoh  * ixgbe_write_phy_reg_mdi_22 - Write to a clause 22 PHY register without lock
    392   1.6  msaitoh  * @hw: pointer to hardware structure
    393   1.6  msaitoh  * @reg_addr: 32 bit PHY register to write
    394   1.6  msaitoh  * @dev_type: always unused
    395   1.6  msaitoh  * @phy_data: Data to write to the PHY register
    396   1.6  msaitoh  */
    397   1.6  msaitoh static s32 ixgbe_write_phy_reg_mdi_22(struct ixgbe_hw *hw, u32 reg_addr,
    398   1.6  msaitoh 				      u32 dev_type, u16 phy_data)
    399   1.6  msaitoh {
    400   1.6  msaitoh 	u32 i, command;
    401   1.6  msaitoh 	UNREFERENCED_1PARAMETER(dev_type);
    402   1.6  msaitoh 
    403   1.6  msaitoh 	/* Put the data in the MDI single read and write data register*/
    404   1.6  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
    405   1.6  msaitoh 
    406   1.6  msaitoh 	/* Setup and write the write command */
    407   1.6  msaitoh 	command = (reg_addr << IXGBE_MSCA_DEV_TYPE_SHIFT) |
    408   1.6  msaitoh 		  (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
    409   1.6  msaitoh 		  IXGBE_MSCA_OLD_PROTOCOL | IXGBE_MSCA_WRITE |
    410   1.6  msaitoh 		  IXGBE_MSCA_MDI_COMMAND;
    411   1.6  msaitoh 
    412   1.6  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
    413   1.6  msaitoh 
    414   1.6  msaitoh 	/* Check every 10 usec to see if the access completed.
    415   1.6  msaitoh 	 * The MDI Command bit will clear when the operation is
    416   1.6  msaitoh 	 * complete
    417   1.6  msaitoh 	 */
    418   1.6  msaitoh 	for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
    419   1.6  msaitoh 		usec_delay(10);
    420   1.6  msaitoh 
    421   1.6  msaitoh 		command = IXGBE_READ_REG(hw, IXGBE_MSCA);
    422   1.6  msaitoh 		if (!(command & IXGBE_MSCA_MDI_COMMAND))
    423   1.6  msaitoh 			break;
    424   1.6  msaitoh 	}
    425   1.6  msaitoh 
    426   1.6  msaitoh 	if (command & IXGBE_MSCA_MDI_COMMAND) {
    427   1.6  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_POLLING,
    428   1.6  msaitoh 			      "PHY write cmd didn't complete\n");
    429   1.6  msaitoh 		return IXGBE_ERR_PHY;
    430   1.6  msaitoh 	}
    431   1.6  msaitoh 
    432   1.6  msaitoh 	return IXGBE_SUCCESS;
    433   1.6  msaitoh }
    434   1.6  msaitoh 
    435   1.6  msaitoh /**
    436   1.1  msaitoh  * ixgbe_identify_phy_x550em - Get PHY type based on device id
    437   1.1  msaitoh  * @hw: pointer to hardware structure
    438   1.1  msaitoh  *
    439   1.1  msaitoh  * Returns error code
    440   1.1  msaitoh  */
    441   1.1  msaitoh static s32 ixgbe_identify_phy_x550em(struct ixgbe_hw *hw)
    442   1.1  msaitoh {
    443   1.6  msaitoh 	hw->mac.ops.set_lan_id(hw);
    444   1.6  msaitoh 
    445   1.6  msaitoh 	ixgbe_read_mng_if_sel_x550em(hw);
    446   1.6  msaitoh 
    447   1.1  msaitoh 	switch (hw->device_id) {
    448   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_SFP:
    449   1.6  msaitoh 		return ixgbe_identify_module_generic(hw);
    450   1.1  msaitoh 	case IXGBE_DEV_ID_X550EM_X_SFP:
    451   1.1  msaitoh 		/* set up for CS4227 usage */
    452   1.1  msaitoh 		ixgbe_setup_mux_ctl(hw);
    453   1.1  msaitoh 		ixgbe_check_cs4227(hw);
    454   1.6  msaitoh 		/* Fallthrough */
    455   1.1  msaitoh 
    456   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_SFP_N:
    457   1.1  msaitoh 		return ixgbe_identify_module_generic(hw);
    458   1.1  msaitoh 		break;
    459   1.1  msaitoh 	case IXGBE_DEV_ID_X550EM_X_KX4:
    460   1.1  msaitoh 		hw->phy.type = ixgbe_phy_x550em_kx4;
    461   1.1  msaitoh 		break;
    462   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_X_XFI:
    463   1.6  msaitoh 		hw->phy.type = ixgbe_phy_x550em_xfi;
    464   1.6  msaitoh 		break;
    465   1.1  msaitoh 	case IXGBE_DEV_ID_X550EM_X_KR:
    466   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_KR:
    467   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_KR_L:
    468   1.1  msaitoh 		hw->phy.type = ixgbe_phy_x550em_kr;
    469   1.1  msaitoh 		break;
    470   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_10G_T:
    471   1.1  msaitoh 	case IXGBE_DEV_ID_X550EM_X_10G_T:
    472   1.1  msaitoh 		return ixgbe_identify_phy_generic(hw);
    473   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_X_1G_T:
    474   1.6  msaitoh 		hw->phy.type = ixgbe_phy_ext_1g_t;
    475   1.6  msaitoh 		break;
    476   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_1G_T:
    477   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_1G_T_L:
    478   1.6  msaitoh 		hw->phy.type = ixgbe_phy_fw;
    479   1.6  msaitoh 		if (hw->bus.lan_id)
    480   1.6  msaitoh 			hw->phy.phy_semaphore_mask |= IXGBE_GSSR_PHY1_SM;
    481   1.6  msaitoh 		else
    482   1.6  msaitoh 			hw->phy.phy_semaphore_mask |= IXGBE_GSSR_PHY0_SM;
    483   1.6  msaitoh 		break;
    484   1.1  msaitoh 	default:
    485   1.1  msaitoh 		break;
    486   1.1  msaitoh 	}
    487   1.1  msaitoh 	return IXGBE_SUCCESS;
    488   1.1  msaitoh }
    489   1.1  msaitoh 
    490   1.6  msaitoh /**
    491   1.6  msaitoh  * ixgbe_fw_phy_activity - Perform an activity on a PHY
    492   1.6  msaitoh  * @hw: pointer to hardware structure
    493   1.6  msaitoh  * @activity: activity to perform
    494   1.6  msaitoh  * @data: Pointer to 4 32-bit words of data
    495   1.6  msaitoh  */
    496   1.6  msaitoh s32 ixgbe_fw_phy_activity(struct ixgbe_hw *hw, u16 activity,
    497   1.6  msaitoh 			  u32 (*data)[FW_PHY_ACT_DATA_COUNT])
    498   1.6  msaitoh {
    499   1.6  msaitoh 	union {
    500   1.6  msaitoh 		struct ixgbe_hic_phy_activity_req cmd;
    501   1.6  msaitoh 		struct ixgbe_hic_phy_activity_resp rsp;
    502   1.6  msaitoh 	} hic;
    503   1.6  msaitoh 	u16 retries = FW_PHY_ACT_RETRIES;
    504   1.6  msaitoh 	s32 rc;
    505   1.6  msaitoh 	u16 i;
    506   1.6  msaitoh 
    507   1.6  msaitoh 	do {
    508   1.6  msaitoh 		memset(&hic, 0, sizeof(hic));
    509   1.6  msaitoh 		hic.cmd.hdr.cmd = FW_PHY_ACT_REQ_CMD;
    510   1.6  msaitoh 		hic.cmd.hdr.buf_len = FW_PHY_ACT_REQ_LEN;
    511   1.6  msaitoh 		hic.cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
    512   1.6  msaitoh 		hic.cmd.port_number = hw->bus.lan_id;
    513   1.6  msaitoh 		hic.cmd.activity_id = IXGBE_CPU_TO_LE16(activity);
    514   1.6  msaitoh 		for (i = 0; i < FW_PHY_ACT_DATA_COUNT; ++i)
    515   1.6  msaitoh 			hic.cmd.data[i] = IXGBE_CPU_TO_BE32((*data)[i]);
    516   1.6  msaitoh 
    517   1.6  msaitoh 		rc = ixgbe_host_interface_command(hw, (u32 *)&hic.cmd,
    518   1.6  msaitoh 						  sizeof(hic.cmd),
    519   1.6  msaitoh 						  IXGBE_HI_COMMAND_TIMEOUT,
    520   1.6  msaitoh 						  TRUE);
    521   1.6  msaitoh 		if (rc != IXGBE_SUCCESS)
    522   1.6  msaitoh 			return rc;
    523   1.6  msaitoh 		if (hic.rsp.hdr.cmd_or_resp.ret_status ==
    524   1.6  msaitoh 		    FW_CEM_RESP_STATUS_SUCCESS) {
    525   1.6  msaitoh 			for (i = 0; i < FW_PHY_ACT_DATA_COUNT; ++i)
    526   1.6  msaitoh 				(*data)[i] = IXGBE_BE32_TO_CPU(hic.rsp.data[i]);
    527   1.6  msaitoh 			return IXGBE_SUCCESS;
    528   1.6  msaitoh 		}
    529   1.6  msaitoh 		usec_delay(20);
    530   1.6  msaitoh 		--retries;
    531   1.6  msaitoh 	} while (retries > 0);
    532   1.6  msaitoh 
    533   1.6  msaitoh 	return IXGBE_ERR_HOST_INTERFACE_COMMAND;
    534   1.6  msaitoh }
    535   1.6  msaitoh 
    536   1.6  msaitoh static const struct {
    537   1.6  msaitoh 	u16 fw_speed;
    538   1.6  msaitoh 	ixgbe_link_speed phy_speed;
    539   1.6  msaitoh } ixgbe_fw_map[] = {
    540   1.6  msaitoh 	{ FW_PHY_ACT_LINK_SPEED_10, IXGBE_LINK_SPEED_10_FULL },
    541   1.6  msaitoh 	{ FW_PHY_ACT_LINK_SPEED_100, IXGBE_LINK_SPEED_100_FULL },
    542   1.6  msaitoh 	{ FW_PHY_ACT_LINK_SPEED_1G, IXGBE_LINK_SPEED_1GB_FULL },
    543   1.6  msaitoh 	{ FW_PHY_ACT_LINK_SPEED_2_5G, IXGBE_LINK_SPEED_2_5GB_FULL },
    544   1.6  msaitoh 	{ FW_PHY_ACT_LINK_SPEED_5G, IXGBE_LINK_SPEED_5GB_FULL },
    545   1.6  msaitoh 	{ FW_PHY_ACT_LINK_SPEED_10G, IXGBE_LINK_SPEED_10GB_FULL },
    546   1.6  msaitoh };
    547   1.6  msaitoh 
    548   1.6  msaitoh /**
    549   1.6  msaitoh  * ixgbe_get_phy_id_fw - Get the phy ID via firmware command
    550   1.6  msaitoh  * @hw: pointer to hardware structure
    551   1.6  msaitoh  *
    552   1.6  msaitoh  * Returns error code
    553   1.6  msaitoh  */
    554   1.6  msaitoh static s32 ixgbe_get_phy_id_fw(struct ixgbe_hw *hw)
    555   1.6  msaitoh {
    556   1.6  msaitoh 	u32 info[FW_PHY_ACT_DATA_COUNT] = { 0 };
    557   1.6  msaitoh 	u16 phy_speeds;
    558   1.6  msaitoh 	u16 phy_id_lo;
    559   1.6  msaitoh 	s32 rc;
    560   1.6  msaitoh 	u16 i;
    561   1.6  msaitoh 
    562   1.6  msaitoh 	rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_GET_PHY_INFO, &info);
    563   1.6  msaitoh 	if (rc)
    564   1.6  msaitoh 		return rc;
    565   1.6  msaitoh 
    566   1.6  msaitoh 	hw->phy.speeds_supported = 0;
    567   1.6  msaitoh 	phy_speeds = info[0] & FW_PHY_INFO_SPEED_MASK;
    568   1.6  msaitoh 	for (i = 0; i < sizeof(ixgbe_fw_map) / sizeof(ixgbe_fw_map[0]); ++i) {
    569   1.6  msaitoh 		if (phy_speeds & ixgbe_fw_map[i].fw_speed)
    570   1.6  msaitoh 			hw->phy.speeds_supported |= ixgbe_fw_map[i].phy_speed;
    571   1.6  msaitoh 	}
    572  1.11  msaitoh 
    573  1.11  msaitoh #if 0
    574  1.11  msaitoh 	/*
    575  1.11  msaitoh 	 *  Don't set autoneg_advertised here to not to be inconsistent with
    576  1.11  msaitoh 	 * if_media value.
    577  1.11  msaitoh 	 */
    578   1.6  msaitoh 	if (!hw->phy.autoneg_advertised)
    579   1.6  msaitoh 		hw->phy.autoneg_advertised = hw->phy.speeds_supported;
    580  1.11  msaitoh #endif
    581   1.6  msaitoh 
    582   1.6  msaitoh 	hw->phy.id = info[0] & FW_PHY_INFO_ID_HI_MASK;
    583   1.6  msaitoh 	phy_id_lo = info[1] & FW_PHY_INFO_ID_LO_MASK;
    584   1.6  msaitoh 	hw->phy.id |= phy_id_lo & IXGBE_PHY_REVISION_MASK;
    585   1.6  msaitoh 	hw->phy.revision = phy_id_lo & ~IXGBE_PHY_REVISION_MASK;
    586   1.6  msaitoh 	if (!hw->phy.id || hw->phy.id == IXGBE_PHY_REVISION_MASK)
    587   1.6  msaitoh 		return IXGBE_ERR_PHY_ADDR_INVALID;
    588   1.6  msaitoh 	return IXGBE_SUCCESS;
    589   1.6  msaitoh }
    590   1.6  msaitoh 
    591   1.6  msaitoh /**
    592   1.6  msaitoh  * ixgbe_identify_phy_fw - Get PHY type based on firmware command
    593   1.6  msaitoh  * @hw: pointer to hardware structure
    594   1.6  msaitoh  *
    595   1.6  msaitoh  * Returns error code
    596   1.6  msaitoh  */
    597   1.6  msaitoh static s32 ixgbe_identify_phy_fw(struct ixgbe_hw *hw)
    598   1.6  msaitoh {
    599   1.6  msaitoh 	if (hw->bus.lan_id)
    600   1.6  msaitoh 		hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
    601   1.6  msaitoh 	else
    602   1.6  msaitoh 		hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
    603   1.6  msaitoh 
    604   1.6  msaitoh 	hw->phy.type = ixgbe_phy_fw;
    605   1.6  msaitoh 	hw->phy.ops.read_reg = NULL;
    606   1.6  msaitoh 	hw->phy.ops.write_reg = NULL;
    607   1.6  msaitoh 	return ixgbe_get_phy_id_fw(hw);
    608   1.6  msaitoh }
    609   1.6  msaitoh 
    610   1.6  msaitoh /**
    611   1.6  msaitoh  * ixgbe_shutdown_fw_phy - Shutdown a firmware-controlled PHY
    612   1.6  msaitoh  * @hw: pointer to hardware structure
    613   1.6  msaitoh  *
    614   1.6  msaitoh  * Returns error code
    615   1.6  msaitoh  */
    616   1.6  msaitoh s32 ixgbe_shutdown_fw_phy(struct ixgbe_hw *hw)
    617   1.6  msaitoh {
    618   1.6  msaitoh 	u32 setup[FW_PHY_ACT_DATA_COUNT] = { 0 };
    619   1.6  msaitoh 
    620   1.6  msaitoh 	setup[0] = FW_PHY_ACT_FORCE_LINK_DOWN_OFF;
    621   1.6  msaitoh 	return ixgbe_fw_phy_activity(hw, FW_PHY_ACT_FORCE_LINK_DOWN, &setup);
    622   1.6  msaitoh }
    623   1.6  msaitoh 
    624   1.1  msaitoh static s32 ixgbe_read_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr,
    625   1.1  msaitoh 				     u32 device_type, u16 *phy_data)
    626   1.1  msaitoh {
    627   1.1  msaitoh 	UNREFERENCED_4PARAMETER(*hw, reg_addr, device_type, *phy_data);
    628   1.1  msaitoh 	return IXGBE_NOT_IMPLEMENTED;
    629   1.1  msaitoh }
    630   1.1  msaitoh 
    631   1.1  msaitoh static s32 ixgbe_write_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr,
    632   1.1  msaitoh 				      u32 device_type, u16 phy_data)
    633   1.1  msaitoh {
    634   1.1  msaitoh 	UNREFERENCED_4PARAMETER(*hw, reg_addr, device_type, phy_data);
    635   1.1  msaitoh 	return IXGBE_NOT_IMPLEMENTED;
    636   1.1  msaitoh }
    637   1.1  msaitoh 
    638   1.1  msaitoh /**
    639   1.6  msaitoh  * ixgbe_read_i2c_combined_generic - Perform I2C read combined operation
    640   1.6  msaitoh  * @hw: pointer to the hardware structure
    641   1.6  msaitoh  * @addr: I2C bus address to read from
    642   1.6  msaitoh  * @reg: I2C device register to read from
    643   1.6  msaitoh  * @val: pointer to location to receive read value
    644   1.6  msaitoh  *
    645   1.6  msaitoh  * Returns an error code on error.
    646   1.6  msaitoh  **/
    647   1.6  msaitoh static s32 ixgbe_read_i2c_combined_generic(struct ixgbe_hw *hw, u8 addr,
    648   1.6  msaitoh 					   u16 reg, u16 *val)
    649   1.6  msaitoh {
    650   1.6  msaitoh 	return ixgbe_read_i2c_combined_generic_int(hw, addr, reg, val, TRUE);
    651   1.6  msaitoh }
    652   1.6  msaitoh 
    653   1.6  msaitoh /**
    654   1.6  msaitoh  * ixgbe_read_i2c_combined_generic_unlocked - Do I2C read combined operation
    655   1.6  msaitoh  * @hw: pointer to the hardware structure
    656   1.6  msaitoh  * @addr: I2C bus address to read from
    657   1.6  msaitoh  * @reg: I2C device register to read from
    658   1.6  msaitoh  * @val: pointer to location to receive read value
    659   1.6  msaitoh  *
    660   1.6  msaitoh  * Returns an error code on error.
    661   1.6  msaitoh  **/
    662   1.6  msaitoh static s32
    663   1.6  msaitoh ixgbe_read_i2c_combined_generic_unlocked(struct ixgbe_hw *hw, u8 addr,
    664   1.6  msaitoh 					 u16 reg, u16 *val)
    665   1.6  msaitoh {
    666   1.6  msaitoh 	return ixgbe_read_i2c_combined_generic_int(hw, addr, reg, val, FALSE);
    667   1.6  msaitoh }
    668   1.6  msaitoh 
    669   1.6  msaitoh /**
    670   1.6  msaitoh  * ixgbe_write_i2c_combined_generic - Perform I2C write combined operation
    671   1.6  msaitoh  * @hw: pointer to the hardware structure
    672   1.6  msaitoh  * @addr: I2C bus address to write to
    673   1.6  msaitoh  * @reg: I2C device register to write to
    674   1.6  msaitoh  * @val: value to write
    675   1.6  msaitoh  *
    676   1.6  msaitoh  * Returns an error code on error.
    677   1.6  msaitoh  **/
    678   1.6  msaitoh static s32 ixgbe_write_i2c_combined_generic(struct ixgbe_hw *hw,
    679   1.6  msaitoh 					    u8 addr, u16 reg, u16 val)
    680   1.6  msaitoh {
    681   1.6  msaitoh 	return ixgbe_write_i2c_combined_generic_int(hw, addr, reg, val, TRUE);
    682   1.6  msaitoh }
    683   1.6  msaitoh 
    684   1.6  msaitoh /**
    685   1.6  msaitoh  * ixgbe_write_i2c_combined_generic_unlocked - Do I2C write combined operation
    686   1.6  msaitoh  * @hw: pointer to the hardware structure
    687   1.6  msaitoh  * @addr: I2C bus address to write to
    688   1.6  msaitoh  * @reg: I2C device register to write to
    689   1.6  msaitoh  * @val: value to write
    690   1.6  msaitoh  *
    691   1.6  msaitoh  * Returns an error code on error.
    692   1.6  msaitoh  **/
    693   1.6  msaitoh static s32
    694   1.6  msaitoh ixgbe_write_i2c_combined_generic_unlocked(struct ixgbe_hw *hw,
    695   1.6  msaitoh 					  u8 addr, u16 reg, u16 val)
    696   1.6  msaitoh {
    697   1.6  msaitoh 	return ixgbe_write_i2c_combined_generic_int(hw, addr, reg, val, FALSE);
    698   1.6  msaitoh }
    699   1.6  msaitoh 
    700   1.6  msaitoh /**
    701   1.1  msaitoh *  ixgbe_init_ops_X550EM - Inits func ptrs and MAC type
    702   1.1  msaitoh *  @hw: pointer to hardware structure
    703   1.1  msaitoh *
    704   1.1  msaitoh *  Initialize the function pointers and for MAC type X550EM.
    705   1.1  msaitoh *  Does not touch the hardware.
    706   1.1  msaitoh **/
    707   1.1  msaitoh s32 ixgbe_init_ops_X550EM(struct ixgbe_hw *hw)
    708   1.1  msaitoh {
    709   1.1  msaitoh 	struct ixgbe_mac_info *mac = &hw->mac;
    710   1.1  msaitoh 	struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
    711   1.1  msaitoh 	struct ixgbe_phy_info *phy = &hw->phy;
    712   1.1  msaitoh 	s32 ret_val;
    713   1.1  msaitoh 
    714   1.1  msaitoh 	DEBUGFUNC("ixgbe_init_ops_X550EM");
    715   1.1  msaitoh 
    716   1.1  msaitoh 	/* Similar to X550 so start there. */
    717   1.1  msaitoh 	ret_val = ixgbe_init_ops_X550(hw);
    718   1.1  msaitoh 
    719   1.1  msaitoh 	/* Since this function eventually calls
    720   1.1  msaitoh 	 * ixgbe_init_ops_540 by design, we are setting
    721   1.1  msaitoh 	 * the pointers to NULL explicitly here to overwrite
    722   1.1  msaitoh 	 * the values being set in the x540 function.
    723   1.1  msaitoh 	 */
    724   1.1  msaitoh 
    725   1.6  msaitoh 	/* Bypass not supported in x550EM */
    726   1.6  msaitoh 	mac->ops.bypass_rw = NULL;
    727   1.6  msaitoh 	mac->ops.bypass_valid_rd = NULL;
    728   1.6  msaitoh 	mac->ops.bypass_set = NULL;
    729   1.6  msaitoh 	mac->ops.bypass_rd_eep = NULL;
    730   1.6  msaitoh 
    731   1.1  msaitoh 	/* FCOE not supported in x550EM */
    732   1.1  msaitoh 	mac->ops.get_san_mac_addr = NULL;
    733   1.1  msaitoh 	mac->ops.set_san_mac_addr = NULL;
    734   1.1  msaitoh 	mac->ops.get_wwn_prefix = NULL;
    735   1.1  msaitoh 	mac->ops.get_fcoe_boot_status = NULL;
    736   1.1  msaitoh 
    737   1.1  msaitoh 	/* IPsec not supported in x550EM */
    738   1.1  msaitoh 	mac->ops.disable_sec_rx_path = NULL;
    739   1.1  msaitoh 	mac->ops.enable_sec_rx_path = NULL;
    740   1.1  msaitoh 
    741   1.1  msaitoh 	/* AUTOC register is not present in x550EM. */
    742   1.1  msaitoh 	mac->ops.prot_autoc_read = NULL;
    743   1.1  msaitoh 	mac->ops.prot_autoc_write = NULL;
    744   1.1  msaitoh 
    745   1.1  msaitoh 	/* X550EM bus type is internal*/
    746   1.1  msaitoh 	hw->bus.type = ixgbe_bus_type_internal;
    747   1.1  msaitoh 	mac->ops.get_bus_info = ixgbe_get_bus_info_X550em;
    748   1.1  msaitoh 
    749   1.2  msaitoh 
    750   1.1  msaitoh 	mac->ops.get_media_type = ixgbe_get_media_type_X550em;
    751   1.1  msaitoh 	mac->ops.setup_sfp = ixgbe_setup_sfp_modules_X550em;
    752   1.1  msaitoh 	mac->ops.get_link_capabilities = ixgbe_get_link_capabilities_X550em;
    753   1.1  msaitoh 	mac->ops.reset_hw = ixgbe_reset_hw_X550em;
    754   1.1  msaitoh 	mac->ops.get_supported_physical_layer =
    755   1.1  msaitoh 				    ixgbe_get_supported_physical_layer_X550em;
    756   1.1  msaitoh 
    757   1.1  msaitoh 	if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper)
    758   1.1  msaitoh 		mac->ops.setup_fc = ixgbe_setup_fc_generic;
    759   1.1  msaitoh 	else
    760   1.1  msaitoh 		mac->ops.setup_fc = ixgbe_setup_fc_X550em;
    761   1.1  msaitoh 
    762   1.1  msaitoh 	/* PHY */
    763   1.1  msaitoh 	phy->ops.init = ixgbe_init_phy_ops_X550em;
    764   1.6  msaitoh 	switch (hw->device_id) {
    765   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_1G_T:
    766   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_1G_T_L:
    767   1.6  msaitoh 		mac->ops.setup_fc = NULL;
    768   1.6  msaitoh 		phy->ops.identify = ixgbe_identify_phy_fw;
    769   1.6  msaitoh 		phy->ops.set_phy_power = NULL;
    770   1.6  msaitoh 		phy->ops.get_firmware_version = NULL;
    771   1.6  msaitoh 		break;
    772   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_X_1G_T:
    773   1.6  msaitoh 		mac->ops.setup_fc = NULL;
    774   1.6  msaitoh 		phy->ops.identify = ixgbe_identify_phy_x550em;
    775   1.6  msaitoh 		phy->ops.set_phy_power = NULL;
    776   1.6  msaitoh 		break;
    777   1.6  msaitoh 	default:
    778   1.6  msaitoh 		phy->ops.identify = ixgbe_identify_phy_x550em;
    779   1.6  msaitoh 	}
    780   1.6  msaitoh 
    781   1.1  msaitoh 	if (mac->ops.get_media_type(hw) != ixgbe_media_type_copper)
    782   1.1  msaitoh 		phy->ops.set_phy_power = NULL;
    783   1.1  msaitoh 
    784   1.1  msaitoh 
    785   1.1  msaitoh 	/* EEPROM */
    786   1.1  msaitoh 	eeprom->ops.init_params = ixgbe_init_eeprom_params_X540;
    787   1.1  msaitoh 	eeprom->ops.read = ixgbe_read_ee_hostif_X550;
    788   1.1  msaitoh 	eeprom->ops.read_buffer = ixgbe_read_ee_hostif_buffer_X550;
    789   1.1  msaitoh 	eeprom->ops.write = ixgbe_write_ee_hostif_X550;
    790   1.1  msaitoh 	eeprom->ops.write_buffer = ixgbe_write_ee_hostif_buffer_X550;
    791   1.1  msaitoh 	eeprom->ops.update_checksum = ixgbe_update_eeprom_checksum_X550;
    792   1.1  msaitoh 	eeprom->ops.validate_checksum = ixgbe_validate_eeprom_checksum_X550;
    793   1.1  msaitoh 	eeprom->ops.calc_checksum = ixgbe_calc_eeprom_checksum_X550;
    794   1.1  msaitoh 
    795   1.1  msaitoh 	return ret_val;
    796   1.1  msaitoh }
    797   1.1  msaitoh 
    798   1.7  msaitoh #define IXGBE_DENVERTON_WA 1
    799   1.7  msaitoh 
    800   1.1  msaitoh /**
    801   1.6  msaitoh  * ixgbe_setup_fw_link - Setup firmware-controlled PHYs
    802   1.6  msaitoh  * @hw: pointer to hardware structure
    803   1.6  msaitoh  */
    804   1.6  msaitoh static s32 ixgbe_setup_fw_link(struct ixgbe_hw *hw)
    805   1.6  msaitoh {
    806   1.6  msaitoh 	u32 setup[FW_PHY_ACT_DATA_COUNT] = { 0 };
    807   1.6  msaitoh 	s32 rc;
    808   1.7  msaitoh #ifdef IXGBE_DENVERTON_WA
    809   1.7  msaitoh 	s32 ret_val;
    810   1.7  msaitoh 	u16 phydata;
    811   1.7  msaitoh #endif
    812   1.6  msaitoh 	u16 i;
    813   1.6  msaitoh 
    814   1.6  msaitoh 	if (hw->phy.reset_disable || ixgbe_check_reset_blocked(hw))
    815   1.6  msaitoh 		return 0;
    816   1.6  msaitoh 
    817   1.6  msaitoh 	if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
    818   1.6  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_UNSUPPORTED,
    819   1.6  msaitoh 			      "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
    820   1.6  msaitoh 		return IXGBE_ERR_INVALID_LINK_SETTINGS;
    821   1.6  msaitoh 	}
    822   1.6  msaitoh 
    823   1.6  msaitoh 	switch (hw->fc.requested_mode) {
    824   1.6  msaitoh 	case ixgbe_fc_full:
    825   1.6  msaitoh 		setup[0] |= FW_PHY_ACT_SETUP_LINK_PAUSE_RXTX <<
    826   1.6  msaitoh 			    FW_PHY_ACT_SETUP_LINK_PAUSE_SHIFT;
    827   1.6  msaitoh 		break;
    828   1.6  msaitoh 	case ixgbe_fc_rx_pause:
    829   1.6  msaitoh 		setup[0] |= FW_PHY_ACT_SETUP_LINK_PAUSE_RX <<
    830   1.6  msaitoh 			    FW_PHY_ACT_SETUP_LINK_PAUSE_SHIFT;
    831   1.6  msaitoh 		break;
    832   1.6  msaitoh 	case ixgbe_fc_tx_pause:
    833   1.6  msaitoh 		setup[0] |= FW_PHY_ACT_SETUP_LINK_PAUSE_TX <<
    834   1.6  msaitoh 			    FW_PHY_ACT_SETUP_LINK_PAUSE_SHIFT;
    835   1.6  msaitoh 		break;
    836   1.6  msaitoh 	default:
    837   1.6  msaitoh 		break;
    838   1.6  msaitoh 	}
    839   1.6  msaitoh 
    840   1.6  msaitoh 	for (i = 0; i < sizeof(ixgbe_fw_map) / sizeof(ixgbe_fw_map[0]); ++i) {
    841   1.6  msaitoh 		if (hw->phy.autoneg_advertised & ixgbe_fw_map[i].phy_speed)
    842   1.6  msaitoh 			setup[0] |= ixgbe_fw_map[i].fw_speed;
    843   1.6  msaitoh 	}
    844   1.6  msaitoh 	setup[0] |= FW_PHY_ACT_SETUP_LINK_HP | FW_PHY_ACT_SETUP_LINK_AN;
    845   1.6  msaitoh 
    846   1.6  msaitoh 	if (hw->phy.eee_speeds_advertised)
    847   1.6  msaitoh 		setup[0] |= FW_PHY_ACT_SETUP_LINK_EEE;
    848   1.6  msaitoh 
    849   1.7  msaitoh #ifdef IXGBE_DENVERTON_WA
    850  1.13  msaitoh 	if ((hw->phy.force_10_100_autonego == false)
    851  1.13  msaitoh 	    && ((hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_100_FULL)
    852  1.13  msaitoh 		|| (hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_10_FULL))) {
    853  1.13  msaitoh 		/* Don't use auto-nego for 10/100Mbps */
    854   1.7  msaitoh 		setup[0] &= ~FW_PHY_ACT_SETUP_LINK_AN;
    855   1.7  msaitoh 		setup[0] &= ~FW_PHY_ACT_SETUP_LINK_EEE;
    856   1.7  msaitoh 		setup[0] &= ~(FW_PHY_ACT_SETUP_LINK_PAUSE_RXTX
    857   1.7  msaitoh 		    << FW_PHY_ACT_SETUP_LINK_PAUSE_SHIFT);
    858   1.7  msaitoh 	}
    859   1.7  msaitoh #endif
    860   1.7  msaitoh 
    861   1.6  msaitoh 	rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_SETUP_LINK, &setup);
    862   1.6  msaitoh 	if (rc)
    863   1.6  msaitoh 		return rc;
    864   1.7  msaitoh 
    865   1.7  msaitoh #ifdef IXGBE_DENVERTON_WA
    866  1.13  msaitoh 	if (hw->phy.force_10_100_autonego == true)
    867  1.13  msaitoh 		goto out;
    868  1.13  msaitoh 
    869   1.7  msaitoh 	ret_val = ixgbe_read_phy_reg_x550a(hw, MII_BMCR, 0, &phydata);
    870   1.7  msaitoh 	if (ret_val != 0)
    871   1.7  msaitoh 		goto out;
    872   1.7  msaitoh 
    873   1.7  msaitoh 	/*
    874   1.7  msaitoh 	 *  Broken firmware sets BMCR register incorrectly if
    875   1.7  msaitoh 	 * FW_PHY_ACT_SETUP_LINK_AN isn't set.
    876   1.7  msaitoh 	 * a) FDX may not be set.
    877   1.7  msaitoh 	 * b) BMCR_SPEED1 (bit 6) is always cleard.
    878   1.7  msaitoh 	 * + -------+------+-----------+-----+--------------------------+
    879   1.7  msaitoh 	 * |request | BMCR | BMCR spd | BMCR |                          |
    880   1.7  msaitoh 	 * |        | (HEX)| (in bits)|  FDX |                          |
    881   1.7  msaitoh 	 * +--------+------+----------+------+--------------------------+
    882   1.7  msaitoh 	 * |   10M  | 0000 |  10M(00) |    0 |                          |
    883   1.7  msaitoh 	 * |   10M  | 2000 | 100M(01) |    0 |(I've never observed this)|
    884   1.7  msaitoh 	 * |   10M  | 2100 | 100M(01) |    1 |                          |
    885   1.7  msaitoh 	 * |  100M  | 0000 |  10M(00) |    0 |                          |
    886   1.7  msaitoh 	 * |  100M  | 0100 |  10M(00) |    1 |                          |
    887   1.7  msaitoh 	 * +--------------------------+------+--------------------------+
    888   1.7  msaitoh 	 */
    889   1.7  msaitoh 	if (((hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_100_FULL)
    890   1.7  msaitoh 		&& (((phydata & BMCR_FDX) == 0) || (BMCR_SPEED(phydata) == 0)))
    891   1.7  msaitoh 	    || ((hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_10_FULL)
    892   1.7  msaitoh 		&& (((phydata & BMCR_FDX) == 0)
    893   1.7  msaitoh 		    || (BMCR_SPEED(phydata) != BMCR_S10)))) {
    894   1.7  msaitoh 		phydata = BMCR_FDX;
    895   1.7  msaitoh 		switch (hw->phy.autoneg_advertised) {
    896   1.7  msaitoh 		case IXGBE_LINK_SPEED_10_FULL:
    897   1.7  msaitoh 			phydata |= BMCR_S10;
    898   1.7  msaitoh 			break;
    899   1.7  msaitoh 		case IXGBE_LINK_SPEED_100_FULL:
    900   1.7  msaitoh 			phydata |= BMCR_S100;
    901   1.7  msaitoh 			break;
    902   1.7  msaitoh 		case IXGBE_LINK_SPEED_1GB_FULL:
    903   1.7  msaitoh 			panic("%s: 1GB_FULL is set", __func__);
    904   1.7  msaitoh 			break;
    905   1.7  msaitoh 		default:
    906   1.7  msaitoh 			break;
    907   1.7  msaitoh 		}
    908   1.7  msaitoh 		ret_val = ixgbe_write_phy_reg_x550a(hw, MII_BMCR, 0, phydata);
    909   1.7  msaitoh 		if (ret_val != 0)
    910   1.7  msaitoh 			return ret_val;
    911   1.7  msaitoh 	}
    912   1.7  msaitoh out:
    913   1.7  msaitoh #endif
    914   1.6  msaitoh 	if (setup[0] == FW_PHY_ACT_SETUP_LINK_RSP_DOWN)
    915   1.6  msaitoh 		return IXGBE_ERR_OVERTEMP;
    916   1.6  msaitoh 	return IXGBE_SUCCESS;
    917   1.6  msaitoh }
    918   1.6  msaitoh 
    919   1.6  msaitoh /**
    920   1.6  msaitoh  * ixgbe_fc_autoneg_fw _ Set up flow control for FW-controlled PHYs
    921   1.6  msaitoh  * @hw: pointer to hardware structure
    922   1.6  msaitoh  *
    923   1.6  msaitoh  *  Called at init time to set up flow control.
    924   1.6  msaitoh  */
    925   1.6  msaitoh static s32 ixgbe_fc_autoneg_fw(struct ixgbe_hw *hw)
    926   1.6  msaitoh {
    927   1.6  msaitoh 	if (hw->fc.requested_mode == ixgbe_fc_default)
    928   1.6  msaitoh 		hw->fc.requested_mode = ixgbe_fc_full;
    929   1.6  msaitoh 
    930   1.6  msaitoh 	return ixgbe_setup_fw_link(hw);
    931   1.6  msaitoh }
    932   1.6  msaitoh 
    933   1.6  msaitoh /**
    934   1.6  msaitoh  * ixgbe_setup_eee_fw - Enable/disable EEE support
    935   1.6  msaitoh  * @hw: pointer to the HW structure
    936   1.6  msaitoh  * @enable_eee: boolean flag to enable EEE
    937   1.6  msaitoh  *
    938   1.6  msaitoh  * Enable/disable EEE based on enable_eee flag.
    939   1.6  msaitoh  * This function controls EEE for firmware-based PHY implementations.
    940   1.6  msaitoh  */
    941   1.6  msaitoh static s32 ixgbe_setup_eee_fw(struct ixgbe_hw *hw, bool enable_eee)
    942   1.6  msaitoh {
    943   1.6  msaitoh 	if (!!hw->phy.eee_speeds_advertised == enable_eee)
    944   1.6  msaitoh 		return IXGBE_SUCCESS;
    945   1.6  msaitoh 	if (enable_eee)
    946   1.6  msaitoh 		hw->phy.eee_speeds_advertised = hw->phy.eee_speeds_supported;
    947   1.6  msaitoh 	else
    948   1.6  msaitoh 		hw->phy.eee_speeds_advertised = 0;
    949   1.6  msaitoh 	return hw->phy.ops.setup_link(hw);
    950   1.6  msaitoh }
    951   1.6  msaitoh 
    952   1.6  msaitoh /**
    953   1.6  msaitoh *  ixgbe_init_ops_X550EM_a - Inits func ptrs and MAC type
    954   1.6  msaitoh *  @hw: pointer to hardware structure
    955   1.6  msaitoh *
    956   1.6  msaitoh *  Initialize the function pointers and for MAC type X550EM_a.
    957   1.6  msaitoh *  Does not touch the hardware.
    958   1.6  msaitoh **/
    959   1.6  msaitoh s32 ixgbe_init_ops_X550EM_a(struct ixgbe_hw *hw)
    960   1.6  msaitoh {
    961   1.6  msaitoh 	struct ixgbe_mac_info *mac = &hw->mac;
    962   1.6  msaitoh 	s32 ret_val;
    963   1.6  msaitoh 
    964   1.6  msaitoh 	DEBUGFUNC("ixgbe_init_ops_X550EM_a");
    965   1.6  msaitoh 
    966   1.6  msaitoh 	/* Start with generic X550EM init */
    967   1.6  msaitoh 	ret_val = ixgbe_init_ops_X550EM(hw);
    968   1.6  msaitoh 
    969   1.6  msaitoh 	if (hw->device_id == IXGBE_DEV_ID_X550EM_A_SGMII ||
    970   1.6  msaitoh 	    hw->device_id == IXGBE_DEV_ID_X550EM_A_SGMII_L) {
    971   1.6  msaitoh 		mac->ops.read_iosf_sb_reg = ixgbe_read_iosf_sb_reg_x550;
    972   1.6  msaitoh 		mac->ops.write_iosf_sb_reg = ixgbe_write_iosf_sb_reg_x550;
    973   1.6  msaitoh 	} else {
    974   1.6  msaitoh 		mac->ops.read_iosf_sb_reg = ixgbe_read_iosf_sb_reg_x550a;
    975   1.6  msaitoh 		mac->ops.write_iosf_sb_reg = ixgbe_write_iosf_sb_reg_x550a;
    976   1.6  msaitoh 	}
    977   1.6  msaitoh 	mac->ops.acquire_swfw_sync = ixgbe_acquire_swfw_sync_X550a;
    978   1.6  msaitoh 	mac->ops.release_swfw_sync = ixgbe_release_swfw_sync_X550a;
    979   1.6  msaitoh 
    980   1.6  msaitoh 	switch (mac->ops.get_media_type(hw)) {
    981   1.6  msaitoh 	case ixgbe_media_type_fiber:
    982   1.6  msaitoh 		mac->ops.setup_fc = NULL;
    983   1.6  msaitoh 		mac->ops.fc_autoneg = ixgbe_fc_autoneg_fiber_x550em_a;
    984   1.6  msaitoh 		break;
    985   1.6  msaitoh 	case ixgbe_media_type_backplane:
    986   1.6  msaitoh 		mac->ops.fc_autoneg = ixgbe_fc_autoneg_backplane_x550em_a;
    987   1.6  msaitoh 		mac->ops.setup_fc = ixgbe_setup_fc_backplane_x550em_a;
    988   1.6  msaitoh 		break;
    989   1.6  msaitoh 	default:
    990   1.6  msaitoh 		break;
    991   1.6  msaitoh 	}
    992   1.6  msaitoh 
    993   1.6  msaitoh 	switch (hw->device_id) {
    994   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_1G_T:
    995   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_1G_T_L:
    996   1.6  msaitoh 		mac->ops.fc_autoneg = ixgbe_fc_autoneg_sgmii_x550em_a;
    997   1.6  msaitoh 		mac->ops.setup_fc = ixgbe_fc_autoneg_fw;
    998   1.6  msaitoh 		mac->ops.setup_eee = ixgbe_setup_eee_fw;
    999   1.6  msaitoh 		hw->phy.eee_speeds_supported = IXGBE_LINK_SPEED_100_FULL |
   1000   1.6  msaitoh 					       IXGBE_LINK_SPEED_1GB_FULL;
   1001   1.6  msaitoh 		hw->phy.eee_speeds_advertised = hw->phy.eee_speeds_supported;
   1002   1.6  msaitoh 		break;
   1003   1.6  msaitoh 	default:
   1004   1.6  msaitoh 		break;
   1005   1.6  msaitoh 	}
   1006   1.6  msaitoh 
   1007   1.6  msaitoh 	return ret_val;
   1008   1.6  msaitoh }
   1009   1.6  msaitoh 
   1010   1.6  msaitoh /**
   1011   1.6  msaitoh *  ixgbe_init_ops_X550EM_x - Inits func ptrs and MAC type
   1012   1.6  msaitoh *  @hw: pointer to hardware structure
   1013   1.6  msaitoh *
   1014   1.6  msaitoh *  Initialize the function pointers and for MAC type X550EM_x.
   1015   1.6  msaitoh *  Does not touch the hardware.
   1016   1.6  msaitoh **/
   1017   1.6  msaitoh s32 ixgbe_init_ops_X550EM_x(struct ixgbe_hw *hw)
   1018   1.6  msaitoh {
   1019   1.6  msaitoh 	struct ixgbe_mac_info *mac = &hw->mac;
   1020   1.6  msaitoh 	struct ixgbe_link_info *link = &hw->link;
   1021   1.6  msaitoh 	s32 ret_val;
   1022   1.6  msaitoh 
   1023   1.6  msaitoh 	DEBUGFUNC("ixgbe_init_ops_X550EM_x");
   1024   1.6  msaitoh 
   1025   1.6  msaitoh 	/* Start with generic X550EM init */
   1026   1.6  msaitoh 	ret_val = ixgbe_init_ops_X550EM(hw);
   1027   1.6  msaitoh 
   1028   1.6  msaitoh 	mac->ops.read_iosf_sb_reg = ixgbe_read_iosf_sb_reg_x550;
   1029   1.6  msaitoh 	mac->ops.write_iosf_sb_reg = ixgbe_write_iosf_sb_reg_x550;
   1030   1.6  msaitoh 	mac->ops.acquire_swfw_sync = ixgbe_acquire_swfw_sync_X550em;
   1031   1.6  msaitoh 	mac->ops.release_swfw_sync = ixgbe_release_swfw_sync_X550em;
   1032   1.6  msaitoh 	link->ops.read_link = ixgbe_read_i2c_combined_generic;
   1033   1.6  msaitoh 	link->ops.read_link_unlocked = ixgbe_read_i2c_combined_generic_unlocked;
   1034   1.6  msaitoh 	link->ops.write_link = ixgbe_write_i2c_combined_generic;
   1035   1.6  msaitoh 	link->ops.write_link_unlocked =
   1036   1.6  msaitoh 				      ixgbe_write_i2c_combined_generic_unlocked;
   1037   1.6  msaitoh 	link->addr = IXGBE_CS4227;
   1038   1.6  msaitoh 
   1039   1.6  msaitoh 	if (hw->device_id == IXGBE_DEV_ID_X550EM_X_1G_T) {
   1040   1.6  msaitoh 		mac->ops.setup_fc = NULL;
   1041   1.6  msaitoh 		mac->ops.setup_eee = NULL;
   1042   1.6  msaitoh 		mac->ops.init_led_link_act = NULL;
   1043   1.6  msaitoh 	}
   1044   1.6  msaitoh 
   1045   1.6  msaitoh 	return ret_val;
   1046   1.6  msaitoh }
   1047   1.6  msaitoh 
   1048   1.6  msaitoh /**
   1049   1.1  msaitoh  *  ixgbe_dmac_config_X550
   1050   1.1  msaitoh  *  @hw: pointer to hardware structure
   1051   1.1  msaitoh  *
   1052   1.1  msaitoh  *  Configure DMA coalescing. If enabling dmac, dmac is activated.
   1053   1.1  msaitoh  *  When disabling dmac, dmac enable dmac bit is cleared.
   1054   1.1  msaitoh  **/
   1055   1.1  msaitoh s32 ixgbe_dmac_config_X550(struct ixgbe_hw *hw)
   1056   1.1  msaitoh {
   1057   1.1  msaitoh 	u32 reg, high_pri_tc;
   1058   1.1  msaitoh 
   1059   1.1  msaitoh 	DEBUGFUNC("ixgbe_dmac_config_X550");
   1060   1.1  msaitoh 
   1061   1.1  msaitoh 	/* Disable DMA coalescing before configuring */
   1062   1.1  msaitoh 	reg = IXGBE_READ_REG(hw, IXGBE_DMACR);
   1063   1.1  msaitoh 	reg &= ~IXGBE_DMACR_DMAC_EN;
   1064   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_DMACR, reg);
   1065   1.1  msaitoh 
   1066   1.1  msaitoh 	/* Disable DMA Coalescing if the watchdog timer is 0 */
   1067   1.1  msaitoh 	if (!hw->mac.dmac_config.watchdog_timer)
   1068   1.1  msaitoh 		goto out;
   1069   1.1  msaitoh 
   1070   1.1  msaitoh 	ixgbe_dmac_config_tcs_X550(hw);
   1071   1.1  msaitoh 
   1072   1.1  msaitoh 	/* Configure DMA Coalescing Control Register */
   1073   1.1  msaitoh 	reg = IXGBE_READ_REG(hw, IXGBE_DMACR);
   1074   1.1  msaitoh 
   1075   1.1  msaitoh 	/* Set the watchdog timer in units of 40.96 usec */
   1076   1.1  msaitoh 	reg &= ~IXGBE_DMACR_DMACWT_MASK;
   1077   1.1  msaitoh 	reg |= (hw->mac.dmac_config.watchdog_timer * 100) / 4096;
   1078   1.1  msaitoh 
   1079   1.1  msaitoh 	reg &= ~IXGBE_DMACR_HIGH_PRI_TC_MASK;
   1080   1.1  msaitoh 	/* If fcoe is enabled, set high priority traffic class */
   1081   1.1  msaitoh 	if (hw->mac.dmac_config.fcoe_en) {
   1082   1.1  msaitoh 		high_pri_tc = 1 << hw->mac.dmac_config.fcoe_tc;
   1083   1.1  msaitoh 		reg |= ((high_pri_tc << IXGBE_DMACR_HIGH_PRI_TC_SHIFT) &
   1084   1.1  msaitoh 			IXGBE_DMACR_HIGH_PRI_TC_MASK);
   1085   1.1  msaitoh 	}
   1086   1.1  msaitoh 	reg |= IXGBE_DMACR_EN_MNG_IND;
   1087   1.1  msaitoh 
   1088   1.1  msaitoh 	/* Enable DMA coalescing after configuration */
   1089   1.1  msaitoh 	reg |= IXGBE_DMACR_DMAC_EN;
   1090   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_DMACR, reg);
   1091   1.1  msaitoh 
   1092   1.1  msaitoh out:
   1093   1.1  msaitoh 	return IXGBE_SUCCESS;
   1094   1.1  msaitoh }
   1095   1.1  msaitoh 
   1096   1.1  msaitoh /**
   1097   1.1  msaitoh  *  ixgbe_dmac_config_tcs_X550
   1098   1.1  msaitoh  *  @hw: pointer to hardware structure
   1099   1.1  msaitoh  *
   1100   1.1  msaitoh  *  Configure DMA coalescing threshold per TC. The dmac enable bit must
   1101   1.1  msaitoh  *  be cleared before configuring.
   1102   1.1  msaitoh  **/
   1103   1.1  msaitoh s32 ixgbe_dmac_config_tcs_X550(struct ixgbe_hw *hw)
   1104   1.1  msaitoh {
   1105   1.1  msaitoh 	u32 tc, reg, pb_headroom, rx_pb_size, maxframe_size_kb;
   1106   1.1  msaitoh 
   1107   1.1  msaitoh 	DEBUGFUNC("ixgbe_dmac_config_tcs_X550");
   1108   1.1  msaitoh 
   1109   1.1  msaitoh 	/* Configure DMA coalescing enabled */
   1110   1.1  msaitoh 	switch (hw->mac.dmac_config.link_speed) {
   1111   1.6  msaitoh 	case IXGBE_LINK_SPEED_10_FULL:
   1112   1.1  msaitoh 	case IXGBE_LINK_SPEED_100_FULL:
   1113   1.1  msaitoh 		pb_headroom = IXGBE_DMACRXT_100M;
   1114   1.1  msaitoh 		break;
   1115   1.1  msaitoh 	case IXGBE_LINK_SPEED_1GB_FULL:
   1116   1.1  msaitoh 		pb_headroom = IXGBE_DMACRXT_1G;
   1117   1.1  msaitoh 		break;
   1118   1.1  msaitoh 	default:
   1119   1.1  msaitoh 		pb_headroom = IXGBE_DMACRXT_10G;
   1120   1.1  msaitoh 		break;
   1121   1.1  msaitoh 	}
   1122   1.1  msaitoh 
   1123   1.1  msaitoh 	maxframe_size_kb = ((IXGBE_READ_REG(hw, IXGBE_MAXFRS) >>
   1124   1.1  msaitoh 			     IXGBE_MHADD_MFS_SHIFT) / 1024);
   1125   1.1  msaitoh 
   1126   1.1  msaitoh 	/* Set the per Rx packet buffer receive threshold */
   1127   1.1  msaitoh 	for (tc = 0; tc < IXGBE_DCB_MAX_TRAFFIC_CLASS; tc++) {
   1128   1.1  msaitoh 		reg = IXGBE_READ_REG(hw, IXGBE_DMCTH(tc));
   1129   1.1  msaitoh 		reg &= ~IXGBE_DMCTH_DMACRXT_MASK;
   1130   1.1  msaitoh 
   1131   1.1  msaitoh 		if (tc < hw->mac.dmac_config.num_tcs) {
   1132   1.1  msaitoh 			/* Get Rx PB size */
   1133   1.1  msaitoh 			rx_pb_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(tc));
   1134   1.1  msaitoh 			rx_pb_size = (rx_pb_size & IXGBE_RXPBSIZE_MASK) >>
   1135   1.1  msaitoh 				IXGBE_RXPBSIZE_SHIFT;
   1136   1.1  msaitoh 
   1137   1.1  msaitoh 			/* Calculate receive buffer threshold in kilobytes */
   1138   1.1  msaitoh 			if (rx_pb_size > pb_headroom)
   1139   1.1  msaitoh 				rx_pb_size = rx_pb_size - pb_headroom;
   1140   1.1  msaitoh 			else
   1141   1.1  msaitoh 				rx_pb_size = 0;
   1142   1.1  msaitoh 
   1143   1.1  msaitoh 			/* Minimum of MFS shall be set for DMCTH */
   1144   1.1  msaitoh 			reg |= (rx_pb_size > maxframe_size_kb) ?
   1145   1.1  msaitoh 				rx_pb_size : maxframe_size_kb;
   1146   1.1  msaitoh 		}
   1147   1.1  msaitoh 		IXGBE_WRITE_REG(hw, IXGBE_DMCTH(tc), reg);
   1148   1.1  msaitoh 	}
   1149   1.1  msaitoh 	return IXGBE_SUCCESS;
   1150   1.1  msaitoh }
   1151   1.1  msaitoh 
   1152   1.1  msaitoh /**
   1153   1.1  msaitoh  *  ixgbe_dmac_update_tcs_X550
   1154   1.1  msaitoh  *  @hw: pointer to hardware structure
   1155   1.1  msaitoh  *
   1156   1.1  msaitoh  *  Disables dmac, updates per TC settings, and then enables dmac.
   1157   1.1  msaitoh  **/
   1158   1.1  msaitoh s32 ixgbe_dmac_update_tcs_X550(struct ixgbe_hw *hw)
   1159   1.1  msaitoh {
   1160   1.1  msaitoh 	u32 reg;
   1161   1.1  msaitoh 
   1162   1.1  msaitoh 	DEBUGFUNC("ixgbe_dmac_update_tcs_X550");
   1163   1.1  msaitoh 
   1164   1.1  msaitoh 	/* Disable DMA coalescing before configuring */
   1165   1.1  msaitoh 	reg = IXGBE_READ_REG(hw, IXGBE_DMACR);
   1166   1.1  msaitoh 	reg &= ~IXGBE_DMACR_DMAC_EN;
   1167   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_DMACR, reg);
   1168   1.1  msaitoh 
   1169   1.1  msaitoh 	ixgbe_dmac_config_tcs_X550(hw);
   1170   1.1  msaitoh 
   1171   1.1  msaitoh 	/* Enable DMA coalescing after configuration */
   1172   1.1  msaitoh 	reg = IXGBE_READ_REG(hw, IXGBE_DMACR);
   1173   1.1  msaitoh 	reg |= IXGBE_DMACR_DMAC_EN;
   1174   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_DMACR, reg);
   1175   1.1  msaitoh 
   1176   1.1  msaitoh 	return IXGBE_SUCCESS;
   1177   1.1  msaitoh }
   1178   1.1  msaitoh 
   1179   1.1  msaitoh /**
   1180   1.1  msaitoh  *  ixgbe_init_eeprom_params_X550 - Initialize EEPROM params
   1181   1.1  msaitoh  *  @hw: pointer to hardware structure
   1182   1.1  msaitoh  *
   1183   1.1  msaitoh  *  Initializes the EEPROM parameters ixgbe_eeprom_info within the
   1184   1.1  msaitoh  *  ixgbe_hw struct in order to set up EEPROM access.
   1185   1.1  msaitoh  **/
   1186   1.1  msaitoh s32 ixgbe_init_eeprom_params_X550(struct ixgbe_hw *hw)
   1187   1.1  msaitoh {
   1188   1.1  msaitoh 	struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
   1189   1.1  msaitoh 	u32 eec;
   1190   1.1  msaitoh 	u16 eeprom_size;
   1191   1.1  msaitoh 
   1192   1.1  msaitoh 	DEBUGFUNC("ixgbe_init_eeprom_params_X550");
   1193   1.1  msaitoh 
   1194   1.1  msaitoh 	if (eeprom->type == ixgbe_eeprom_uninitialized) {
   1195   1.1  msaitoh 		eeprom->semaphore_delay = 10;
   1196   1.1  msaitoh 		eeprom->type = ixgbe_flash;
   1197   1.1  msaitoh 
   1198   1.1  msaitoh 		eec = IXGBE_READ_REG(hw, IXGBE_EEC);
   1199   1.1  msaitoh 		eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
   1200   1.1  msaitoh 				    IXGBE_EEC_SIZE_SHIFT);
   1201   1.1  msaitoh 		eeprom->word_size = 1 << (eeprom_size +
   1202   1.1  msaitoh 					  IXGBE_EEPROM_WORD_SIZE_SHIFT);
   1203   1.1  msaitoh 
   1204   1.1  msaitoh 		DEBUGOUT2("Eeprom params: type = %d, size = %d\n",
   1205   1.1  msaitoh 			  eeprom->type, eeprom->word_size);
   1206   1.1  msaitoh 	}
   1207   1.1  msaitoh 
   1208   1.1  msaitoh 	return IXGBE_SUCCESS;
   1209   1.1  msaitoh }
   1210   1.1  msaitoh 
   1211   1.1  msaitoh /**
   1212   1.6  msaitoh  * ixgbe_set_source_address_pruning_X550 - Enable/Disbale source address pruning
   1213   1.6  msaitoh  * @hw: pointer to hardware structure
   1214   1.6  msaitoh  * @enable: enable or disable source address pruning
   1215   1.6  msaitoh  * @pool: Rx pool to set source address pruning for
   1216   1.1  msaitoh  **/
   1217   1.6  msaitoh void ixgbe_set_source_address_pruning_X550(struct ixgbe_hw *hw, bool enable,
   1218   1.6  msaitoh 					   unsigned int pool)
   1219   1.1  msaitoh {
   1220   1.6  msaitoh 	u64 pfflp;
   1221   1.1  msaitoh 
   1222   1.6  msaitoh 	/* max rx pool is 63 */
   1223   1.6  msaitoh 	if (pool > 63)
   1224   1.6  msaitoh 		return;
   1225   1.1  msaitoh 
   1226   1.6  msaitoh 	pfflp = (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPL);
   1227   1.1  msaitoh 	pfflp |= (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPH) << 32;
   1228   1.1  msaitoh 
   1229   1.1  msaitoh 	if (enable)
   1230   1.1  msaitoh 		pfflp |= (1ULL << pool);
   1231   1.1  msaitoh 	else
   1232   1.1  msaitoh 		pfflp &= ~(1ULL << pool);
   1233   1.1  msaitoh 
   1234   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_PFFLPL, (u32)pfflp);
   1235   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_PFFLPH, (u32)(pfflp >> 32));
   1236   1.1  msaitoh }
   1237   1.1  msaitoh 
   1238   1.1  msaitoh /**
   1239   1.1  msaitoh  *  ixgbe_set_ethertype_anti_spoofing_X550 - Enable/Disable Ethertype anti-spoofing
   1240   1.1  msaitoh  *  @hw: pointer to hardware structure
   1241   1.1  msaitoh  *  @enable: enable or disable switch for Ethertype anti-spoofing
   1242   1.1  msaitoh  *  @vf: Virtual Function pool - VF Pool to set for Ethertype anti-spoofing
   1243   1.1  msaitoh  *
   1244   1.1  msaitoh  **/
   1245   1.1  msaitoh void ixgbe_set_ethertype_anti_spoofing_X550(struct ixgbe_hw *hw,
   1246   1.1  msaitoh 		bool enable, int vf)
   1247   1.1  msaitoh {
   1248   1.1  msaitoh 	int vf_target_reg = vf >> 3;
   1249   1.1  msaitoh 	int vf_target_shift = vf % 8 + IXGBE_SPOOF_ETHERTYPEAS_SHIFT;
   1250   1.1  msaitoh 	u32 pfvfspoof;
   1251   1.1  msaitoh 
   1252   1.1  msaitoh 	DEBUGFUNC("ixgbe_set_ethertype_anti_spoofing_X550");
   1253   1.1  msaitoh 
   1254   1.1  msaitoh 	pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
   1255   1.1  msaitoh 	if (enable)
   1256   1.1  msaitoh 		pfvfspoof |= (1 << vf_target_shift);
   1257   1.1  msaitoh 	else
   1258   1.1  msaitoh 		pfvfspoof &= ~(1 << vf_target_shift);
   1259   1.1  msaitoh 
   1260   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
   1261   1.1  msaitoh }
   1262   1.1  msaitoh 
   1263   1.1  msaitoh /**
   1264   1.1  msaitoh  * ixgbe_iosf_wait - Wait for IOSF command completion
   1265   1.1  msaitoh  * @hw: pointer to hardware structure
   1266   1.1  msaitoh  * @ctrl: pointer to location to receive final IOSF control value
   1267   1.1  msaitoh  *
   1268   1.1  msaitoh  * Returns failing status on timeout
   1269   1.1  msaitoh  *
   1270   1.1  msaitoh  * Note: ctrl can be NULL if the IOSF control register value is not needed
   1271   1.1  msaitoh  **/
   1272   1.1  msaitoh static s32 ixgbe_iosf_wait(struct ixgbe_hw *hw, u32 *ctrl)
   1273   1.1  msaitoh {
   1274   1.1  msaitoh 	u32 i, command = 0;
   1275   1.1  msaitoh 
   1276   1.1  msaitoh 	/* Check every 10 usec to see if the address cycle completed.
   1277   1.1  msaitoh 	 * The SB IOSF BUSY bit will clear when the operation is
   1278   1.1  msaitoh 	 * complete
   1279   1.1  msaitoh 	 */
   1280   1.1  msaitoh 	for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
   1281   1.1  msaitoh 		command = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL);
   1282   1.1  msaitoh 		if ((command & IXGBE_SB_IOSF_CTRL_BUSY) == 0)
   1283   1.1  msaitoh 			break;
   1284   1.1  msaitoh 		usec_delay(10);
   1285   1.1  msaitoh 	}
   1286   1.1  msaitoh 	if (ctrl)
   1287   1.1  msaitoh 		*ctrl = command;
   1288   1.1  msaitoh 	if (i == IXGBE_MDIO_COMMAND_TIMEOUT) {
   1289   1.1  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_POLLING, "Wait timed out\n");
   1290   1.1  msaitoh 		return IXGBE_ERR_PHY;
   1291   1.1  msaitoh 	}
   1292   1.1  msaitoh 
   1293   1.1  msaitoh 	return IXGBE_SUCCESS;
   1294   1.1  msaitoh }
   1295   1.1  msaitoh 
   1296   1.1  msaitoh /**
   1297   1.6  msaitoh  *  ixgbe_write_iosf_sb_reg_x550 - Writes a value to specified register
   1298   1.6  msaitoh  *  of the IOSF device
   1299   1.1  msaitoh  *  @hw: pointer to hardware structure
   1300   1.1  msaitoh  *  @reg_addr: 32 bit PHY register to write
   1301   1.1  msaitoh  *  @device_type: 3 bit device type
   1302   1.1  msaitoh  *  @data: Data to write to the register
   1303   1.1  msaitoh  **/
   1304   1.1  msaitoh s32 ixgbe_write_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
   1305   1.1  msaitoh 			    u32 device_type, u32 data)
   1306   1.1  msaitoh {
   1307   1.1  msaitoh 	u32 gssr = IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_PHY0_SM;
   1308   1.1  msaitoh 	u32 command, error __unused;
   1309   1.1  msaitoh 	s32 ret;
   1310   1.1  msaitoh 
   1311   1.1  msaitoh 	ret = ixgbe_acquire_swfw_semaphore(hw, gssr);
   1312   1.1  msaitoh 	if (ret != IXGBE_SUCCESS)
   1313   1.1  msaitoh 		return ret;
   1314   1.1  msaitoh 
   1315   1.1  msaitoh 	ret = ixgbe_iosf_wait(hw, NULL);
   1316   1.1  msaitoh 	if (ret != IXGBE_SUCCESS)
   1317   1.1  msaitoh 		goto out;
   1318   1.1  msaitoh 
   1319   1.1  msaitoh 	command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
   1320   1.1  msaitoh 		   (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
   1321   1.1  msaitoh 
   1322   1.1  msaitoh 	/* Write IOSF control register */
   1323   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
   1324   1.1  msaitoh 
   1325   1.1  msaitoh 	/* Write IOSF data register */
   1326   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA, data);
   1327   1.1  msaitoh 
   1328   1.1  msaitoh 	ret = ixgbe_iosf_wait(hw, &command);
   1329   1.1  msaitoh 
   1330   1.1  msaitoh 	if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
   1331   1.1  msaitoh 		error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
   1332   1.1  msaitoh 			 IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
   1333   1.1  msaitoh 		ERROR_REPORT2(IXGBE_ERROR_POLLING,
   1334   1.1  msaitoh 			      "Failed to write, error %x\n", error);
   1335   1.1  msaitoh 		ret = IXGBE_ERR_PHY;
   1336   1.1  msaitoh 	}
   1337   1.1  msaitoh 
   1338   1.1  msaitoh out:
   1339   1.1  msaitoh 	ixgbe_release_swfw_semaphore(hw, gssr);
   1340   1.1  msaitoh 	return ret;
   1341   1.1  msaitoh }
   1342   1.1  msaitoh 
   1343   1.1  msaitoh /**
   1344   1.6  msaitoh  *  ixgbe_read_iosf_sb_reg_x550 - Reads specified register of the IOSF device
   1345   1.1  msaitoh  *  @hw: pointer to hardware structure
   1346   1.1  msaitoh  *  @reg_addr: 32 bit PHY register to write
   1347   1.1  msaitoh  *  @device_type: 3 bit device type
   1348   1.6  msaitoh  *  @data: Pointer to read data from the register
   1349   1.1  msaitoh  **/
   1350   1.1  msaitoh s32 ixgbe_read_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
   1351   1.1  msaitoh 			   u32 device_type, u32 *data)
   1352   1.1  msaitoh {
   1353   1.1  msaitoh 	u32 gssr = IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_PHY0_SM;
   1354   1.1  msaitoh 	u32 command, error __unused;
   1355   1.1  msaitoh 	s32 ret;
   1356   1.1  msaitoh 
   1357   1.1  msaitoh 	ret = ixgbe_acquire_swfw_semaphore(hw, gssr);
   1358   1.1  msaitoh 	if (ret != IXGBE_SUCCESS)
   1359   1.1  msaitoh 		return ret;
   1360   1.1  msaitoh 
   1361   1.1  msaitoh 	ret = ixgbe_iosf_wait(hw, NULL);
   1362   1.1  msaitoh 	if (ret != IXGBE_SUCCESS)
   1363   1.1  msaitoh 		goto out;
   1364   1.1  msaitoh 
   1365   1.1  msaitoh 	command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
   1366   1.1  msaitoh 		   (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
   1367   1.1  msaitoh 
   1368   1.1  msaitoh 	/* Write IOSF control register */
   1369   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
   1370   1.1  msaitoh 
   1371   1.1  msaitoh 	ret = ixgbe_iosf_wait(hw, &command);
   1372   1.1  msaitoh 
   1373   1.1  msaitoh 	if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
   1374   1.1  msaitoh 		error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
   1375   1.1  msaitoh 			 IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
   1376   1.1  msaitoh 		ERROR_REPORT2(IXGBE_ERROR_POLLING,
   1377   1.1  msaitoh 				"Failed to read, error %x\n", error);
   1378   1.1  msaitoh 		ret = IXGBE_ERR_PHY;
   1379   1.1  msaitoh 	}
   1380   1.1  msaitoh 
   1381   1.1  msaitoh 	if (ret == IXGBE_SUCCESS)
   1382   1.1  msaitoh 		*data = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA);
   1383   1.1  msaitoh 
   1384   1.1  msaitoh out:
   1385   1.1  msaitoh 	ixgbe_release_swfw_semaphore(hw, gssr);
   1386   1.1  msaitoh 	return ret;
   1387   1.1  msaitoh }
   1388   1.1  msaitoh 
   1389   1.1  msaitoh /**
   1390   1.6  msaitoh  * ixgbe_get_phy_token - Get the token for shared phy access
   1391   1.6  msaitoh  * @hw: Pointer to hardware structure
   1392   1.6  msaitoh  */
   1393   1.6  msaitoh 
   1394   1.6  msaitoh s32 ixgbe_get_phy_token(struct ixgbe_hw *hw)
   1395   1.6  msaitoh {
   1396   1.6  msaitoh 	struct ixgbe_hic_phy_token_req token_cmd;
   1397   1.6  msaitoh 	s32 status;
   1398   1.6  msaitoh 
   1399   1.6  msaitoh 	token_cmd.hdr.cmd = FW_PHY_TOKEN_REQ_CMD;
   1400   1.6  msaitoh 	token_cmd.hdr.buf_len = FW_PHY_TOKEN_REQ_LEN;
   1401   1.6  msaitoh 	token_cmd.hdr.cmd_or_resp.cmd_resv = 0;
   1402   1.6  msaitoh 	token_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
   1403   1.6  msaitoh 	token_cmd.port_number = hw->bus.lan_id;
   1404   1.6  msaitoh 	token_cmd.command_type = FW_PHY_TOKEN_REQ;
   1405   1.6  msaitoh 	token_cmd.pad = 0;
   1406   1.6  msaitoh 	status = ixgbe_host_interface_command(hw, (u32 *)&token_cmd,
   1407   1.6  msaitoh 					      sizeof(token_cmd),
   1408   1.6  msaitoh 					      IXGBE_HI_COMMAND_TIMEOUT,
   1409   1.6  msaitoh 					      TRUE);
   1410   1.6  msaitoh 	if (status) {
   1411   1.6  msaitoh 		DEBUGOUT1("Issuing host interface command failed with Status = %d\n",
   1412   1.6  msaitoh 			  status);
   1413   1.6  msaitoh 		return status;
   1414   1.6  msaitoh 	}
   1415   1.6  msaitoh 	if (token_cmd.hdr.cmd_or_resp.ret_status == FW_PHY_TOKEN_OK)
   1416   1.6  msaitoh 		return IXGBE_SUCCESS;
   1417   1.6  msaitoh 	if (token_cmd.hdr.cmd_or_resp.ret_status != FW_PHY_TOKEN_RETRY) {
   1418   1.6  msaitoh 		DEBUGOUT1("Host interface command returned 0x%08x , returning IXGBE_ERR_FW_RESP_INVALID\n",
   1419   1.6  msaitoh 			  token_cmd.hdr.cmd_or_resp.ret_status);
   1420   1.6  msaitoh 		return IXGBE_ERR_FW_RESP_INVALID;
   1421   1.6  msaitoh 	}
   1422   1.6  msaitoh 
   1423   1.6  msaitoh 	DEBUGOUT("Returning  IXGBE_ERR_TOKEN_RETRY\n");
   1424   1.6  msaitoh 	return IXGBE_ERR_TOKEN_RETRY;
   1425   1.6  msaitoh }
   1426   1.6  msaitoh 
   1427   1.6  msaitoh /**
   1428   1.6  msaitoh  * ixgbe_put_phy_token - Put the token for shared phy access
   1429   1.6  msaitoh  * @hw: Pointer to hardware structure
   1430   1.6  msaitoh  */
   1431   1.6  msaitoh 
   1432   1.6  msaitoh s32 ixgbe_put_phy_token(struct ixgbe_hw *hw)
   1433   1.6  msaitoh {
   1434   1.6  msaitoh 	struct ixgbe_hic_phy_token_req token_cmd;
   1435   1.6  msaitoh 	s32 status;
   1436   1.6  msaitoh 
   1437   1.6  msaitoh 	token_cmd.hdr.cmd = FW_PHY_TOKEN_REQ_CMD;
   1438   1.6  msaitoh 	token_cmd.hdr.buf_len = FW_PHY_TOKEN_REQ_LEN;
   1439   1.6  msaitoh 	token_cmd.hdr.cmd_or_resp.cmd_resv = 0;
   1440   1.6  msaitoh 	token_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
   1441   1.6  msaitoh 	token_cmd.port_number = hw->bus.lan_id;
   1442   1.6  msaitoh 	token_cmd.command_type = FW_PHY_TOKEN_REL;
   1443   1.6  msaitoh 	token_cmd.pad = 0;
   1444   1.6  msaitoh 	status = ixgbe_host_interface_command(hw, (u32 *)&token_cmd,
   1445   1.6  msaitoh 					      sizeof(token_cmd),
   1446   1.6  msaitoh 					      IXGBE_HI_COMMAND_TIMEOUT,
   1447   1.6  msaitoh 					      TRUE);
   1448   1.6  msaitoh 	if (status)
   1449   1.6  msaitoh 		return status;
   1450   1.6  msaitoh 	if (token_cmd.hdr.cmd_or_resp.ret_status == FW_PHY_TOKEN_OK)
   1451   1.6  msaitoh 		return IXGBE_SUCCESS;
   1452   1.6  msaitoh 
   1453   1.6  msaitoh 	DEBUGOUT("Put PHY Token host interface command failed");
   1454   1.6  msaitoh 	return IXGBE_ERR_FW_RESP_INVALID;
   1455   1.6  msaitoh }
   1456   1.6  msaitoh 
   1457   1.6  msaitoh /**
   1458   1.6  msaitoh  *  ixgbe_write_iosf_sb_reg_x550a - Writes a value to specified register
   1459   1.6  msaitoh  *  of the IOSF device
   1460   1.6  msaitoh  *  @hw: pointer to hardware structure
   1461   1.6  msaitoh  *  @reg_addr: 32 bit PHY register to write
   1462   1.6  msaitoh  *  @device_type: 3 bit device type
   1463   1.6  msaitoh  *  @data: Data to write to the register
   1464   1.6  msaitoh  **/
   1465   1.6  msaitoh s32 ixgbe_write_iosf_sb_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
   1466   1.6  msaitoh 				  u32 device_type, u32 data)
   1467   1.6  msaitoh {
   1468   1.6  msaitoh 	struct ixgbe_hic_internal_phy_req write_cmd;
   1469   1.6  msaitoh 	s32 status;
   1470   1.6  msaitoh 	UNREFERENCED_1PARAMETER(device_type);
   1471   1.6  msaitoh 
   1472   1.6  msaitoh 	memset(&write_cmd, 0, sizeof(write_cmd));
   1473   1.6  msaitoh 	write_cmd.hdr.cmd = FW_INT_PHY_REQ_CMD;
   1474   1.6  msaitoh 	write_cmd.hdr.buf_len = FW_INT_PHY_REQ_LEN;
   1475   1.6  msaitoh 	write_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
   1476   1.6  msaitoh 	write_cmd.port_number = hw->bus.lan_id;
   1477   1.6  msaitoh 	write_cmd.command_type = FW_INT_PHY_REQ_WRITE;
   1478   1.6  msaitoh 	write_cmd.address = IXGBE_CPU_TO_BE16(reg_addr);
   1479   1.6  msaitoh 	write_cmd.write_data = IXGBE_CPU_TO_BE32(data);
   1480   1.6  msaitoh 
   1481   1.6  msaitoh 	status = ixgbe_host_interface_command(hw, (u32 *)&write_cmd,
   1482   1.6  msaitoh 					      sizeof(write_cmd),
   1483   1.6  msaitoh 					      IXGBE_HI_COMMAND_TIMEOUT, FALSE);
   1484   1.6  msaitoh 
   1485   1.6  msaitoh 	return status;
   1486   1.6  msaitoh }
   1487   1.6  msaitoh 
   1488   1.6  msaitoh /**
   1489   1.6  msaitoh  *  ixgbe_read_iosf_sb_reg_x550a - Reads specified register of the IOSF device
   1490   1.6  msaitoh  *  @hw: pointer to hardware structure
   1491   1.6  msaitoh  *  @reg_addr: 32 bit PHY register to write
   1492   1.6  msaitoh  *  @device_type: 3 bit device type
   1493   1.6  msaitoh  *  @data: Pointer to read data from the register
   1494   1.6  msaitoh  **/
   1495   1.6  msaitoh s32 ixgbe_read_iosf_sb_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
   1496   1.6  msaitoh 				 u32 device_type, u32 *data)
   1497   1.6  msaitoh {
   1498   1.6  msaitoh 	union {
   1499   1.6  msaitoh 		struct ixgbe_hic_internal_phy_req cmd;
   1500   1.6  msaitoh 		struct ixgbe_hic_internal_phy_resp rsp;
   1501   1.6  msaitoh 	} hic;
   1502   1.6  msaitoh 	s32 status;
   1503   1.6  msaitoh 	UNREFERENCED_1PARAMETER(device_type);
   1504   1.6  msaitoh 
   1505   1.6  msaitoh 	memset(&hic, 0, sizeof(hic));
   1506   1.6  msaitoh 	hic.cmd.hdr.cmd = FW_INT_PHY_REQ_CMD;
   1507   1.6  msaitoh 	hic.cmd.hdr.buf_len = FW_INT_PHY_REQ_LEN;
   1508   1.6  msaitoh 	hic.cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
   1509   1.6  msaitoh 	hic.cmd.port_number = hw->bus.lan_id;
   1510   1.6  msaitoh 	hic.cmd.command_type = FW_INT_PHY_REQ_READ;
   1511   1.6  msaitoh 	hic.cmd.address = IXGBE_CPU_TO_BE16(reg_addr);
   1512   1.6  msaitoh 
   1513   1.6  msaitoh 	status = ixgbe_host_interface_command(hw, (u32 *)&hic.cmd,
   1514   1.6  msaitoh 					      sizeof(hic.cmd),
   1515   1.6  msaitoh 					      IXGBE_HI_COMMAND_TIMEOUT, TRUE);
   1516   1.6  msaitoh 
   1517   1.6  msaitoh 	/* Extract the register value from the response. */
   1518   1.6  msaitoh 	*data = IXGBE_BE32_TO_CPU(hic.rsp.read_data);
   1519   1.6  msaitoh 
   1520   1.6  msaitoh 	return status;
   1521   1.6  msaitoh }
   1522   1.6  msaitoh 
   1523   1.6  msaitoh /**
   1524   1.1  msaitoh  *  ixgbe_disable_mdd_X550
   1525   1.1  msaitoh  *  @hw: pointer to hardware structure
   1526   1.1  msaitoh  *
   1527   1.1  msaitoh  *  Disable malicious driver detection
   1528   1.1  msaitoh  **/
   1529   1.1  msaitoh void ixgbe_disable_mdd_X550(struct ixgbe_hw *hw)
   1530   1.1  msaitoh {
   1531   1.1  msaitoh 	u32 reg;
   1532   1.1  msaitoh 
   1533   1.1  msaitoh 	DEBUGFUNC("ixgbe_disable_mdd_X550");
   1534   1.1  msaitoh 
   1535   1.1  msaitoh 	/* Disable MDD for TX DMA and interrupt */
   1536   1.1  msaitoh 	reg = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
   1537   1.1  msaitoh 	reg &= ~(IXGBE_DMATXCTL_MDP_EN | IXGBE_DMATXCTL_MBINTEN);
   1538   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg);
   1539   1.1  msaitoh 
   1540   1.1  msaitoh 	/* Disable MDD for RX and interrupt */
   1541   1.1  msaitoh 	reg = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
   1542   1.1  msaitoh 	reg &= ~(IXGBE_RDRXCTL_MDP_EN | IXGBE_RDRXCTL_MBINTEN);
   1543   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, reg);
   1544   1.1  msaitoh }
   1545   1.1  msaitoh 
   1546   1.1  msaitoh /**
   1547   1.1  msaitoh  *  ixgbe_enable_mdd_X550
   1548   1.1  msaitoh  *  @hw: pointer to hardware structure
   1549   1.1  msaitoh  *
   1550   1.1  msaitoh  *  Enable malicious driver detection
   1551   1.1  msaitoh  **/
   1552   1.1  msaitoh void ixgbe_enable_mdd_X550(struct ixgbe_hw *hw)
   1553   1.1  msaitoh {
   1554   1.1  msaitoh 	u32 reg;
   1555   1.1  msaitoh 
   1556   1.1  msaitoh 	DEBUGFUNC("ixgbe_enable_mdd_X550");
   1557   1.1  msaitoh 
   1558   1.1  msaitoh 	/* Enable MDD for TX DMA and interrupt */
   1559   1.1  msaitoh 	reg = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
   1560   1.1  msaitoh 	reg |= (IXGBE_DMATXCTL_MDP_EN | IXGBE_DMATXCTL_MBINTEN);
   1561   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg);
   1562   1.1  msaitoh 
   1563   1.1  msaitoh 	/* Enable MDD for RX and interrupt */
   1564   1.1  msaitoh 	reg = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
   1565   1.1  msaitoh 	reg |= (IXGBE_RDRXCTL_MDP_EN | IXGBE_RDRXCTL_MBINTEN);
   1566   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, reg);
   1567   1.1  msaitoh }
   1568   1.1  msaitoh 
   1569   1.1  msaitoh /**
   1570   1.1  msaitoh  *  ixgbe_restore_mdd_vf_X550
   1571   1.1  msaitoh  *  @hw: pointer to hardware structure
   1572   1.1  msaitoh  *  @vf: vf index
   1573   1.1  msaitoh  *
   1574   1.1  msaitoh  *  Restore VF that was disabled during malicious driver detection event
   1575   1.1  msaitoh  **/
   1576   1.1  msaitoh void ixgbe_restore_mdd_vf_X550(struct ixgbe_hw *hw, u32 vf)
   1577   1.1  msaitoh {
   1578   1.1  msaitoh 	u32 idx, reg, num_qs, start_q, bitmask;
   1579   1.1  msaitoh 
   1580   1.1  msaitoh 	DEBUGFUNC("ixgbe_restore_mdd_vf_X550");
   1581   1.1  msaitoh 
   1582   1.1  msaitoh 	/* Map VF to queues */
   1583   1.1  msaitoh 	reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
   1584   1.1  msaitoh 	switch (reg & IXGBE_MRQC_MRQE_MASK) {
   1585   1.1  msaitoh 	case IXGBE_MRQC_VMDQRT8TCEN:
   1586   1.1  msaitoh 		num_qs = 8;  /* 16 VFs / pools */
   1587   1.1  msaitoh 		bitmask = 0x000000FF;
   1588   1.1  msaitoh 		break;
   1589   1.1  msaitoh 	case IXGBE_MRQC_VMDQRSS32EN:
   1590   1.1  msaitoh 	case IXGBE_MRQC_VMDQRT4TCEN:
   1591   1.1  msaitoh 		num_qs = 4;  /* 32 VFs / pools */
   1592   1.1  msaitoh 		bitmask = 0x0000000F;
   1593   1.1  msaitoh 		break;
   1594   1.6  msaitoh 	default:            /* 64 VFs / pools */
   1595   1.1  msaitoh 		num_qs = 2;
   1596   1.1  msaitoh 		bitmask = 0x00000003;
   1597   1.1  msaitoh 		break;
   1598   1.1  msaitoh 	}
   1599   1.1  msaitoh 	start_q = vf * num_qs;
   1600   1.1  msaitoh 
   1601   1.1  msaitoh 	/* Release vf's queues by clearing WQBR_TX and WQBR_RX (RW1C) */
   1602   1.1  msaitoh 	idx = start_q / 32;
   1603   1.1  msaitoh 	reg = 0;
   1604   1.1  msaitoh 	reg |= (bitmask << (start_q % 32));
   1605   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_WQBR_TX(idx), reg);
   1606   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_WQBR_RX(idx), reg);
   1607   1.1  msaitoh }
   1608   1.1  msaitoh 
   1609   1.1  msaitoh /**
   1610   1.1  msaitoh  *  ixgbe_mdd_event_X550
   1611   1.1  msaitoh  *  @hw: pointer to hardware structure
   1612   1.1  msaitoh  *  @vf_bitmap: vf bitmap of malicious vfs
   1613   1.1  msaitoh  *
   1614   1.1  msaitoh  *  Handle malicious driver detection event.
   1615   1.1  msaitoh  **/
   1616   1.1  msaitoh void ixgbe_mdd_event_X550(struct ixgbe_hw *hw, u32 *vf_bitmap)
   1617   1.1  msaitoh {
   1618   1.1  msaitoh 	u32 wqbr;
   1619   1.1  msaitoh 	u32 i, j, reg, q, shift, vf, idx;
   1620   1.1  msaitoh 
   1621   1.1  msaitoh 	DEBUGFUNC("ixgbe_mdd_event_X550");
   1622   1.1  msaitoh 
   1623   1.1  msaitoh 	/* figure out pool size for mapping to vf's */
   1624   1.1  msaitoh 	reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
   1625   1.1  msaitoh 	switch (reg & IXGBE_MRQC_MRQE_MASK) {
   1626   1.1  msaitoh 	case IXGBE_MRQC_VMDQRT8TCEN:
   1627   1.1  msaitoh 		shift = 3;  /* 16 VFs / pools */
   1628   1.1  msaitoh 		break;
   1629   1.1  msaitoh 	case IXGBE_MRQC_VMDQRSS32EN:
   1630   1.1  msaitoh 	case IXGBE_MRQC_VMDQRT4TCEN:
   1631   1.1  msaitoh 		shift = 2;  /* 32 VFs / pools */
   1632   1.1  msaitoh 		break;
   1633   1.1  msaitoh 	default:
   1634   1.1  msaitoh 		shift = 1;  /* 64 VFs / pools */
   1635   1.1  msaitoh 		break;
   1636   1.1  msaitoh 	}
   1637   1.1  msaitoh 
   1638   1.1  msaitoh 	/* Read WQBR_TX and WQBR_RX and check for malicious queues */
   1639   1.1  msaitoh 	for (i = 0; i < 4; i++) {
   1640   1.1  msaitoh 		wqbr = IXGBE_READ_REG(hw, IXGBE_WQBR_TX(i));
   1641   1.1  msaitoh 		wqbr |= IXGBE_READ_REG(hw, IXGBE_WQBR_RX(i));
   1642   1.1  msaitoh 
   1643   1.1  msaitoh 		if (!wqbr)
   1644   1.1  msaitoh 			continue;
   1645   1.1  msaitoh 
   1646   1.1  msaitoh 		/* Get malicious queue */
   1647   1.1  msaitoh 		for (j = 0; j < 32 && wqbr; j++) {
   1648   1.1  msaitoh 
   1649   1.1  msaitoh 			if (!(wqbr & (1 << j)))
   1650   1.1  msaitoh 				continue;
   1651   1.1  msaitoh 
   1652   1.1  msaitoh 			/* Get queue from bitmask */
   1653   1.1  msaitoh 			q = j + (i * 32);
   1654   1.1  msaitoh 
   1655   1.1  msaitoh 			/* Map queue to vf */
   1656   1.1  msaitoh 			vf = (q >> shift);
   1657   1.1  msaitoh 
   1658   1.1  msaitoh 			/* Set vf bit in vf_bitmap */
   1659   1.1  msaitoh 			idx = vf / 32;
   1660   1.1  msaitoh 			vf_bitmap[idx] |= (1 << (vf % 32));
   1661   1.1  msaitoh 			wqbr &= ~(1 << j);
   1662   1.1  msaitoh 		}
   1663   1.1  msaitoh 	}
   1664   1.1  msaitoh }
   1665   1.1  msaitoh 
   1666   1.1  msaitoh /**
   1667   1.1  msaitoh  *  ixgbe_get_media_type_X550em - Get media type
   1668   1.1  msaitoh  *  @hw: pointer to hardware structure
   1669   1.1  msaitoh  *
   1670   1.1  msaitoh  *  Returns the media type (fiber, copper, backplane)
   1671   1.1  msaitoh  */
   1672   1.1  msaitoh enum ixgbe_media_type ixgbe_get_media_type_X550em(struct ixgbe_hw *hw)
   1673   1.1  msaitoh {
   1674   1.1  msaitoh 	enum ixgbe_media_type media_type;
   1675   1.1  msaitoh 
   1676   1.1  msaitoh 	DEBUGFUNC("ixgbe_get_media_type_X550em");
   1677   1.1  msaitoh 
   1678   1.1  msaitoh 	/* Detect if there is a copper PHY attached. */
   1679   1.1  msaitoh 	switch (hw->device_id) {
   1680   1.1  msaitoh 	case IXGBE_DEV_ID_X550EM_X_KR:
   1681   1.1  msaitoh 	case IXGBE_DEV_ID_X550EM_X_KX4:
   1682   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_X_XFI:
   1683   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_KR:
   1684   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_KR_L:
   1685   1.1  msaitoh 		media_type = ixgbe_media_type_backplane;
   1686   1.1  msaitoh 		break;
   1687   1.1  msaitoh 	case IXGBE_DEV_ID_X550EM_X_SFP:
   1688   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_SFP:
   1689   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_SFP_N:
   1690   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_QSFP:
   1691   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_QSFP_N:
   1692   1.1  msaitoh 		media_type = ixgbe_media_type_fiber;
   1693   1.1  msaitoh 		break;
   1694   1.1  msaitoh 	case IXGBE_DEV_ID_X550EM_X_1G_T:
   1695   1.1  msaitoh 	case IXGBE_DEV_ID_X550EM_X_10G_T:
   1696   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_10G_T:
   1697   1.6  msaitoh 		media_type = ixgbe_media_type_copper;
   1698   1.6  msaitoh 		break;
   1699   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_SGMII:
   1700   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_SGMII_L:
   1701   1.6  msaitoh 		media_type = ixgbe_media_type_backplane;
   1702   1.6  msaitoh 		hw->phy.type = ixgbe_phy_sgmii;
   1703   1.6  msaitoh 		break;
   1704   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_1G_T:
   1705   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_1G_T_L:
   1706   1.1  msaitoh 		media_type = ixgbe_media_type_copper;
   1707   1.1  msaitoh 		break;
   1708   1.1  msaitoh 	default:
   1709   1.1  msaitoh 		media_type = ixgbe_media_type_unknown;
   1710   1.1  msaitoh 		break;
   1711   1.1  msaitoh 	}
   1712   1.1  msaitoh 	return media_type;
   1713   1.1  msaitoh }
   1714   1.1  msaitoh 
   1715   1.1  msaitoh /**
   1716   1.1  msaitoh  *  ixgbe_supported_sfp_modules_X550em - Check if SFP module type is supported
   1717   1.1  msaitoh  *  @hw: pointer to hardware structure
   1718   1.1  msaitoh  *  @linear: TRUE if SFP module is linear
   1719   1.1  msaitoh  */
   1720   1.1  msaitoh static s32 ixgbe_supported_sfp_modules_X550em(struct ixgbe_hw *hw, bool *linear)
   1721   1.1  msaitoh {
   1722   1.1  msaitoh 	DEBUGFUNC("ixgbe_supported_sfp_modules_X550em");
   1723   1.1  msaitoh 
   1724   1.1  msaitoh 	switch (hw->phy.sfp_type) {
   1725   1.1  msaitoh 	case ixgbe_sfp_type_not_present:
   1726   1.1  msaitoh 		return IXGBE_ERR_SFP_NOT_PRESENT;
   1727   1.1  msaitoh 	case ixgbe_sfp_type_da_cu_core0:
   1728   1.1  msaitoh 	case ixgbe_sfp_type_da_cu_core1:
   1729   1.1  msaitoh 		*linear = TRUE;
   1730   1.1  msaitoh 		break;
   1731   1.1  msaitoh 	case ixgbe_sfp_type_srlr_core0:
   1732   1.1  msaitoh 	case ixgbe_sfp_type_srlr_core1:
   1733   1.1  msaitoh 	case ixgbe_sfp_type_da_act_lmt_core0:
   1734   1.1  msaitoh 	case ixgbe_sfp_type_da_act_lmt_core1:
   1735   1.1  msaitoh 	case ixgbe_sfp_type_1g_sx_core0:
   1736   1.1  msaitoh 	case ixgbe_sfp_type_1g_sx_core1:
   1737   1.1  msaitoh 	case ixgbe_sfp_type_1g_lx_core0:
   1738   1.1  msaitoh 	case ixgbe_sfp_type_1g_lx_core1:
   1739   1.1  msaitoh 		*linear = FALSE;
   1740   1.1  msaitoh 		break;
   1741   1.1  msaitoh 	case ixgbe_sfp_type_unknown:
   1742   1.1  msaitoh 	case ixgbe_sfp_type_1g_cu_core0:
   1743   1.1  msaitoh 	case ixgbe_sfp_type_1g_cu_core1:
   1744   1.1  msaitoh 	default:
   1745   1.1  msaitoh 		return IXGBE_ERR_SFP_NOT_SUPPORTED;
   1746   1.1  msaitoh 	}
   1747   1.1  msaitoh 
   1748   1.1  msaitoh 	return IXGBE_SUCCESS;
   1749   1.1  msaitoh }
   1750   1.1  msaitoh 
   1751   1.1  msaitoh /**
   1752   1.1  msaitoh  *  ixgbe_identify_sfp_module_X550em - Identifies SFP modules
   1753   1.1  msaitoh  *  @hw: pointer to hardware structure
   1754   1.1  msaitoh  *
   1755   1.1  msaitoh  *  Searches for and identifies the SFP module and assigns appropriate PHY type.
   1756   1.1  msaitoh  **/
   1757   1.1  msaitoh s32 ixgbe_identify_sfp_module_X550em(struct ixgbe_hw *hw)
   1758   1.1  msaitoh {
   1759   1.1  msaitoh 	s32 status;
   1760   1.1  msaitoh 	bool linear;
   1761   1.1  msaitoh 
   1762   1.1  msaitoh 	DEBUGFUNC("ixgbe_identify_sfp_module_X550em");
   1763   1.1  msaitoh 
   1764   1.1  msaitoh 	status = ixgbe_identify_module_generic(hw);
   1765   1.1  msaitoh 
   1766   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   1767   1.1  msaitoh 		return status;
   1768   1.1  msaitoh 
   1769   1.1  msaitoh 	/* Check if SFP module is supported */
   1770   1.1  msaitoh 	status = ixgbe_supported_sfp_modules_X550em(hw, &linear);
   1771   1.1  msaitoh 
   1772   1.1  msaitoh 	return status;
   1773   1.1  msaitoh }
   1774   1.1  msaitoh 
   1775   1.1  msaitoh /**
   1776   1.1  msaitoh  *  ixgbe_setup_sfp_modules_X550em - Setup MAC link ops
   1777   1.1  msaitoh  *  @hw: pointer to hardware structure
   1778   1.1  msaitoh  */
   1779   1.1  msaitoh s32 ixgbe_setup_sfp_modules_X550em(struct ixgbe_hw *hw)
   1780   1.1  msaitoh {
   1781   1.1  msaitoh 	s32 status;
   1782   1.1  msaitoh 	bool linear;
   1783   1.1  msaitoh 
   1784   1.1  msaitoh 	DEBUGFUNC("ixgbe_setup_sfp_modules_X550em");
   1785   1.1  msaitoh 
   1786   1.1  msaitoh 	/* Check if SFP module is supported */
   1787   1.1  msaitoh 	status = ixgbe_supported_sfp_modules_X550em(hw, &linear);
   1788   1.1  msaitoh 
   1789   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   1790   1.1  msaitoh 		return status;
   1791   1.1  msaitoh 
   1792   1.1  msaitoh 	ixgbe_init_mac_link_ops_X550em(hw);
   1793   1.1  msaitoh 	hw->phy.ops.reset = NULL;
   1794   1.1  msaitoh 
   1795   1.1  msaitoh 	return IXGBE_SUCCESS;
   1796   1.1  msaitoh }
   1797   1.1  msaitoh 
   1798   1.1  msaitoh /**
   1799   1.6  msaitoh *  ixgbe_restart_an_internal_phy_x550em - restart autonegotiation for the
   1800   1.6  msaitoh *  internal PHY
   1801   1.6  msaitoh *  @hw: pointer to hardware structure
   1802   1.6  msaitoh **/
   1803   1.6  msaitoh static s32 ixgbe_restart_an_internal_phy_x550em(struct ixgbe_hw *hw)
   1804   1.6  msaitoh {
   1805   1.6  msaitoh 	s32 status;
   1806   1.6  msaitoh 	u32 link_ctrl;
   1807   1.6  msaitoh 
   1808   1.6  msaitoh 	/* Restart auto-negotiation. */
   1809   1.6  msaitoh 	status = hw->mac.ops.read_iosf_sb_reg(hw,
   1810   1.6  msaitoh 				       IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
   1811   1.6  msaitoh 				       IXGBE_SB_IOSF_TARGET_KR_PHY, &link_ctrl);
   1812   1.6  msaitoh 
   1813   1.6  msaitoh 	if (status) {
   1814   1.6  msaitoh 		DEBUGOUT("Auto-negotiation did not complete\n");
   1815   1.6  msaitoh 		return status;
   1816   1.6  msaitoh 	}
   1817   1.6  msaitoh 
   1818   1.6  msaitoh 	link_ctrl |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART;
   1819   1.6  msaitoh 	status = hw->mac.ops.write_iosf_sb_reg(hw,
   1820   1.6  msaitoh 					IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
   1821   1.6  msaitoh 					IXGBE_SB_IOSF_TARGET_KR_PHY, link_ctrl);
   1822   1.6  msaitoh 
   1823   1.6  msaitoh 	if (hw->mac.type == ixgbe_mac_X550EM_a) {
   1824   1.6  msaitoh 		u32 flx_mask_st20;
   1825   1.6  msaitoh 
   1826   1.6  msaitoh 		/* Indicate to FW that AN restart has been asserted */
   1827   1.6  msaitoh 		status = hw->mac.ops.read_iosf_sb_reg(hw,
   1828   1.6  msaitoh 				IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
   1829   1.6  msaitoh 				IXGBE_SB_IOSF_TARGET_KR_PHY, &flx_mask_st20);
   1830   1.6  msaitoh 
   1831   1.6  msaitoh 		if (status) {
   1832   1.6  msaitoh 			DEBUGOUT("Auto-negotiation did not complete\n");
   1833   1.6  msaitoh 			return status;
   1834   1.6  msaitoh 		}
   1835   1.6  msaitoh 
   1836   1.6  msaitoh 		flx_mask_st20 |= IXGBE_KRM_PMD_FLX_MASK_ST20_FW_AN_RESTART;
   1837   1.6  msaitoh 		status = hw->mac.ops.write_iosf_sb_reg(hw,
   1838   1.6  msaitoh 				IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
   1839   1.6  msaitoh 				IXGBE_SB_IOSF_TARGET_KR_PHY, flx_mask_st20);
   1840   1.6  msaitoh 	}
   1841   1.6  msaitoh 
   1842   1.6  msaitoh 	return status;
   1843   1.6  msaitoh }
   1844   1.6  msaitoh 
   1845   1.6  msaitoh /**
   1846   1.6  msaitoh  * ixgbe_setup_sgmii - Set up link for sgmii
   1847   1.6  msaitoh  * @hw: pointer to hardware structure
   1848  1.12  msaitoh  * @speed: new link speed
   1849  1.12  msaitoh  * @autoneg_wait: TRUE when waiting for completion is needed
   1850   1.6  msaitoh  */
   1851   1.6  msaitoh static s32 ixgbe_setup_sgmii(struct ixgbe_hw *hw, ixgbe_link_speed speed,
   1852   1.6  msaitoh 			     bool autoneg_wait)
   1853   1.6  msaitoh {
   1854   1.6  msaitoh 	struct ixgbe_mac_info *mac = &hw->mac;
   1855   1.6  msaitoh 	u32 lval, sval, flx_val;
   1856   1.6  msaitoh 	s32 rc;
   1857   1.6  msaitoh 
   1858   1.6  msaitoh 	rc = mac->ops.read_iosf_sb_reg(hw,
   1859   1.6  msaitoh 				       IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
   1860   1.6  msaitoh 				       IXGBE_SB_IOSF_TARGET_KR_PHY, &lval);
   1861   1.6  msaitoh 	if (rc)
   1862   1.6  msaitoh 		return rc;
   1863   1.6  msaitoh 
   1864   1.6  msaitoh 	lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
   1865   1.6  msaitoh 	lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
   1866   1.6  msaitoh 	lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_SGMII_EN;
   1867   1.6  msaitoh 	lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CLAUSE_37_EN;
   1868   1.6  msaitoh 	lval |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
   1869   1.6  msaitoh 	rc = mac->ops.write_iosf_sb_reg(hw,
   1870   1.6  msaitoh 					IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
   1871   1.6  msaitoh 					IXGBE_SB_IOSF_TARGET_KR_PHY, lval);
   1872   1.6  msaitoh 	if (rc)
   1873   1.6  msaitoh 		return rc;
   1874   1.6  msaitoh 
   1875   1.6  msaitoh 	rc = mac->ops.read_iosf_sb_reg(hw,
   1876   1.6  msaitoh 				       IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
   1877   1.6  msaitoh 				       IXGBE_SB_IOSF_TARGET_KR_PHY, &sval);
   1878   1.6  msaitoh 	if (rc)
   1879   1.6  msaitoh 		return rc;
   1880   1.6  msaitoh 
   1881   1.6  msaitoh 	sval |= IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_10_D;
   1882   1.6  msaitoh 	sval |= IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_100_D;
   1883   1.6  msaitoh 	rc = mac->ops.write_iosf_sb_reg(hw,
   1884   1.6  msaitoh 					IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
   1885   1.6  msaitoh 					IXGBE_SB_IOSF_TARGET_KR_PHY, sval);
   1886   1.6  msaitoh 	if (rc)
   1887   1.6  msaitoh 		return rc;
   1888   1.6  msaitoh 
   1889   1.6  msaitoh 	rc = mac->ops.read_iosf_sb_reg(hw,
   1890   1.6  msaitoh 				    IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
   1891   1.6  msaitoh 				    IXGBE_SB_IOSF_TARGET_KR_PHY, &flx_val);
   1892   1.6  msaitoh 	if (rc)
   1893   1.6  msaitoh 		return rc;
   1894   1.6  msaitoh 
   1895   1.6  msaitoh 	flx_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_MASK;
   1896   1.6  msaitoh 	flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_1G;
   1897   1.6  msaitoh 	flx_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN_EN;
   1898   1.6  msaitoh 	flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SGMII_EN;
   1899   1.6  msaitoh 	flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_AN37_EN;
   1900   1.6  msaitoh 
   1901   1.6  msaitoh 	rc = mac->ops.write_iosf_sb_reg(hw,
   1902   1.6  msaitoh 				    IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
   1903   1.6  msaitoh 				    IXGBE_SB_IOSF_TARGET_KR_PHY, flx_val);
   1904   1.6  msaitoh 	if (rc)
   1905   1.6  msaitoh 		return rc;
   1906   1.6  msaitoh 
   1907   1.6  msaitoh 	rc = ixgbe_restart_an_internal_phy_x550em(hw);
   1908   1.6  msaitoh 	if (rc)
   1909   1.6  msaitoh 		return rc;
   1910   1.6  msaitoh 
   1911   1.6  msaitoh 	return hw->phy.ops.setup_link_speed(hw, speed, autoneg_wait);
   1912   1.6  msaitoh }
   1913   1.6  msaitoh 
   1914   1.6  msaitoh /**
   1915   1.8  msaitoh  * ixgbe_setup_sgmii_fw - Set up link for internal PHY SGMII auto-negotiation
   1916   1.6  msaitoh  * @hw: pointer to hardware structure
   1917  1.12  msaitoh  * @speed: new link speed
   1918  1.12  msaitoh  * @autoneg_wait: TRUE when waiting for completion is needed
   1919   1.6  msaitoh  */
   1920   1.6  msaitoh static s32 ixgbe_setup_sgmii_fw(struct ixgbe_hw *hw, ixgbe_link_speed speed,
   1921   1.6  msaitoh 				bool autoneg_wait)
   1922   1.6  msaitoh {
   1923   1.6  msaitoh 	struct ixgbe_mac_info *mac = &hw->mac;
   1924   1.6  msaitoh 	u32 lval, sval, flx_val;
   1925   1.6  msaitoh 	s32 rc;
   1926   1.6  msaitoh 
   1927   1.6  msaitoh 	rc = mac->ops.read_iosf_sb_reg(hw,
   1928   1.6  msaitoh 				       IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
   1929   1.6  msaitoh 				       IXGBE_SB_IOSF_TARGET_KR_PHY, &lval);
   1930   1.6  msaitoh 	if (rc)
   1931   1.6  msaitoh 		return rc;
   1932   1.6  msaitoh 
   1933   1.6  msaitoh 	lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
   1934   1.6  msaitoh 	lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
   1935   1.6  msaitoh 	lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_SGMII_EN;
   1936   1.6  msaitoh 	lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CLAUSE_37_EN;
   1937   1.6  msaitoh 	lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
   1938   1.6  msaitoh 	rc = mac->ops.write_iosf_sb_reg(hw,
   1939   1.6  msaitoh 					IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
   1940   1.6  msaitoh 					IXGBE_SB_IOSF_TARGET_KR_PHY, lval);
   1941   1.6  msaitoh 	if (rc)
   1942   1.6  msaitoh 		return rc;
   1943   1.6  msaitoh 
   1944   1.6  msaitoh 	rc = mac->ops.read_iosf_sb_reg(hw,
   1945   1.6  msaitoh 				       IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
   1946   1.6  msaitoh 				       IXGBE_SB_IOSF_TARGET_KR_PHY, &sval);
   1947   1.6  msaitoh 	if (rc)
   1948   1.6  msaitoh 		return rc;
   1949   1.6  msaitoh 
   1950   1.6  msaitoh 	sval &= ~IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_10_D;
   1951   1.6  msaitoh 	sval &= ~IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_100_D;
   1952   1.6  msaitoh 	rc = mac->ops.write_iosf_sb_reg(hw,
   1953   1.6  msaitoh 					IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
   1954   1.6  msaitoh 					IXGBE_SB_IOSF_TARGET_KR_PHY, sval);
   1955   1.6  msaitoh 	if (rc)
   1956   1.6  msaitoh 		return rc;
   1957   1.6  msaitoh 
   1958   1.6  msaitoh 	rc = mac->ops.write_iosf_sb_reg(hw,
   1959   1.6  msaitoh 					IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
   1960   1.6  msaitoh 					IXGBE_SB_IOSF_TARGET_KR_PHY, lval);
   1961   1.6  msaitoh 	if (rc)
   1962   1.6  msaitoh 		return rc;
   1963   1.6  msaitoh 
   1964   1.6  msaitoh 	rc = mac->ops.read_iosf_sb_reg(hw,
   1965   1.6  msaitoh 				    IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
   1966   1.6  msaitoh 				    IXGBE_SB_IOSF_TARGET_KR_PHY, &flx_val);
   1967   1.6  msaitoh 	if (rc)
   1968   1.6  msaitoh 		return rc;
   1969   1.6  msaitoh 
   1970   1.6  msaitoh 	flx_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_MASK;
   1971   1.6  msaitoh 	flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_AN;
   1972   1.6  msaitoh 	flx_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN_EN;
   1973   1.6  msaitoh 	flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SGMII_EN;
   1974   1.6  msaitoh 	flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_AN37_EN;
   1975   1.6  msaitoh 
   1976   1.6  msaitoh 	rc = mac->ops.write_iosf_sb_reg(hw,
   1977   1.6  msaitoh 				    IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
   1978   1.6  msaitoh 				    IXGBE_SB_IOSF_TARGET_KR_PHY, flx_val);
   1979   1.6  msaitoh 	if (rc)
   1980   1.6  msaitoh 		return rc;
   1981   1.6  msaitoh 
   1982   1.6  msaitoh 	rc = ixgbe_restart_an_internal_phy_x550em(hw);
   1983   1.6  msaitoh 
   1984   1.6  msaitoh 	return hw->phy.ops.setup_link_speed(hw, speed, autoneg_wait);
   1985   1.6  msaitoh }
   1986   1.6  msaitoh 
   1987   1.6  msaitoh /**
   1988   1.1  msaitoh  *  ixgbe_init_mac_link_ops_X550em - init mac link function pointers
   1989   1.1  msaitoh  *  @hw: pointer to hardware structure
   1990   1.1  msaitoh  */
   1991   1.1  msaitoh void ixgbe_init_mac_link_ops_X550em(struct ixgbe_hw *hw)
   1992   1.1  msaitoh {
   1993   1.1  msaitoh 	struct ixgbe_mac_info *mac = &hw->mac;
   1994   1.1  msaitoh 
   1995   1.1  msaitoh 	DEBUGFUNC("ixgbe_init_mac_link_ops_X550em");
   1996   1.1  msaitoh 
   1997   1.6  msaitoh 	switch (hw->mac.ops.get_media_type(hw)) {
   1998   1.6  msaitoh 	case ixgbe_media_type_fiber:
   1999   1.1  msaitoh 		/* CS4227 does not support autoneg, so disable the laser control
   2000   1.1  msaitoh 		 * functions for SFP+ fiber
   2001   1.1  msaitoh 		 */
   2002   1.1  msaitoh 		mac->ops.disable_tx_laser = NULL;
   2003   1.1  msaitoh 		mac->ops.enable_tx_laser = NULL;
   2004   1.1  msaitoh 		mac->ops.flap_tx_laser = NULL;
   2005   1.1  msaitoh 		mac->ops.setup_link = ixgbe_setup_mac_link_multispeed_fiber;
   2006   1.1  msaitoh 		mac->ops.set_rate_select_speed =
   2007   1.1  msaitoh 					ixgbe_set_soft_rate_select_speed;
   2008   1.6  msaitoh 
   2009   1.6  msaitoh 		if ((hw->device_id == IXGBE_DEV_ID_X550EM_A_SFP_N) ||
   2010   1.6  msaitoh 		    (hw->device_id == IXGBE_DEV_ID_X550EM_A_SFP))
   2011   1.6  msaitoh 			mac->ops.setup_mac_link =
   2012   1.6  msaitoh 						ixgbe_setup_mac_link_sfp_x550a;
   2013   1.6  msaitoh 		else
   2014   1.6  msaitoh 			mac->ops.setup_mac_link =
   2015   1.6  msaitoh 						ixgbe_setup_mac_link_sfp_x550em;
   2016   1.1  msaitoh 		break;
   2017   1.1  msaitoh 	case ixgbe_media_type_copper:
   2018   1.6  msaitoh 		if (hw->device_id == IXGBE_DEV_ID_X550EM_X_1G_T)
   2019   1.6  msaitoh 			break;
   2020   1.6  msaitoh 		if (hw->mac.type == ixgbe_mac_X550EM_a) {
   2021   1.6  msaitoh 			if (hw->device_id == IXGBE_DEV_ID_X550EM_A_1G_T ||
   2022   1.6  msaitoh 			    hw->device_id == IXGBE_DEV_ID_X550EM_A_1G_T_L) {
   2023   1.6  msaitoh 				mac->ops.setup_link = ixgbe_setup_sgmii_fw;
   2024   1.6  msaitoh 				mac->ops.check_link =
   2025   1.6  msaitoh 						   ixgbe_check_mac_link_generic;
   2026   1.6  msaitoh 			} else {
   2027   1.6  msaitoh 				mac->ops.setup_link =
   2028   1.6  msaitoh 						  ixgbe_setup_mac_link_t_X550em;
   2029   1.6  msaitoh 			}
   2030   1.6  msaitoh 		} else {
   2031   1.6  msaitoh 			mac->ops.setup_link = ixgbe_setup_mac_link_t_X550em;
   2032   1.6  msaitoh 			mac->ops.check_link = ixgbe_check_link_t_X550em;
   2033   1.6  msaitoh 		}
   2034   1.6  msaitoh 		break;
   2035   1.6  msaitoh 	case ixgbe_media_type_backplane:
   2036   1.6  msaitoh 		if (hw->device_id == IXGBE_DEV_ID_X550EM_A_SGMII ||
   2037   1.6  msaitoh 		    hw->device_id == IXGBE_DEV_ID_X550EM_A_SGMII_L)
   2038   1.6  msaitoh 			mac->ops.setup_link = ixgbe_setup_sgmii;
   2039   1.1  msaitoh 		break;
   2040   1.1  msaitoh 	default:
   2041   1.1  msaitoh 		break;
   2042   1.6  msaitoh 	}
   2043   1.1  msaitoh }
   2044   1.1  msaitoh 
   2045   1.1  msaitoh /**
   2046   1.1  msaitoh  *  ixgbe_get_link_capabilities_x550em - Determines link capabilities
   2047   1.1  msaitoh  *  @hw: pointer to hardware structure
   2048   1.1  msaitoh  *  @speed: pointer to link speed
   2049   1.1  msaitoh  *  @autoneg: TRUE when autoneg or autotry is enabled
   2050   1.1  msaitoh  */
   2051   1.1  msaitoh s32 ixgbe_get_link_capabilities_X550em(struct ixgbe_hw *hw,
   2052   1.1  msaitoh 				       ixgbe_link_speed *speed,
   2053   1.1  msaitoh 				       bool *autoneg)
   2054   1.1  msaitoh {
   2055   1.1  msaitoh 	DEBUGFUNC("ixgbe_get_link_capabilities_X550em");
   2056   1.1  msaitoh 
   2057   1.6  msaitoh 
   2058   1.6  msaitoh 	if (hw->phy.type == ixgbe_phy_fw) {
   2059   1.6  msaitoh 		*autoneg = TRUE;
   2060   1.6  msaitoh 		*speed = hw->phy.speeds_supported;
   2061   1.6  msaitoh 		return 0;
   2062   1.6  msaitoh 	}
   2063   1.6  msaitoh 
   2064   1.1  msaitoh 	/* SFP */
   2065   1.1  msaitoh 	if (hw->phy.media_type == ixgbe_media_type_fiber) {
   2066   1.1  msaitoh 
   2067   1.1  msaitoh 		/* CS4227 SFP must not enable auto-negotiation */
   2068   1.1  msaitoh 		*autoneg = FALSE;
   2069   1.1  msaitoh 
   2070   1.1  msaitoh 		/* Check if 1G SFP module. */
   2071   1.1  msaitoh 		if (hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
   2072   1.1  msaitoh 		    hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1
   2073   1.1  msaitoh 		    || hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
   2074   1.1  msaitoh 		    hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1) {
   2075   1.1  msaitoh 			*speed = IXGBE_LINK_SPEED_1GB_FULL;
   2076   1.1  msaitoh 			return IXGBE_SUCCESS;
   2077   1.1  msaitoh 		}
   2078   1.1  msaitoh 
   2079   1.1  msaitoh 		/* Link capabilities are based on SFP */
   2080   1.1  msaitoh 		if (hw->phy.multispeed_fiber)
   2081   1.1  msaitoh 			*speed = IXGBE_LINK_SPEED_10GB_FULL |
   2082   1.1  msaitoh 				 IXGBE_LINK_SPEED_1GB_FULL;
   2083   1.1  msaitoh 		else
   2084   1.1  msaitoh 			*speed = IXGBE_LINK_SPEED_10GB_FULL;
   2085   1.1  msaitoh 	} else {
   2086   1.6  msaitoh 		switch (hw->phy.type) {
   2087   1.6  msaitoh 		case ixgbe_phy_ext_1g_t:
   2088   1.6  msaitoh 		case ixgbe_phy_sgmii:
   2089   1.6  msaitoh 			*speed = IXGBE_LINK_SPEED_1GB_FULL;
   2090   1.6  msaitoh 			break;
   2091   1.6  msaitoh 		case ixgbe_phy_x550em_kr:
   2092   1.6  msaitoh 			if (hw->mac.type == ixgbe_mac_X550EM_a) {
   2093   1.6  msaitoh 				/* check different backplane modes */
   2094   1.6  msaitoh 				if (hw->phy.nw_mng_if_sel &
   2095   1.6  msaitoh 					   IXGBE_NW_MNG_IF_SEL_PHY_SPEED_2_5G) {
   2096   1.6  msaitoh 					*speed = IXGBE_LINK_SPEED_2_5GB_FULL;
   2097   1.6  msaitoh 					break;
   2098   1.6  msaitoh 				} else if (hw->device_id ==
   2099   1.6  msaitoh 						   IXGBE_DEV_ID_X550EM_A_KR_L) {
   2100   1.6  msaitoh 					*speed = IXGBE_LINK_SPEED_1GB_FULL;
   2101   1.6  msaitoh 					break;
   2102   1.6  msaitoh 				}
   2103   1.6  msaitoh 			}
   2104   1.6  msaitoh 			/* fall through */
   2105   1.6  msaitoh 		default:
   2106   1.6  msaitoh 			*speed = IXGBE_LINK_SPEED_10GB_FULL |
   2107   1.6  msaitoh 			    IXGBE_LINK_SPEED_1GB_FULL;
   2108   1.6  msaitoh 			break;
   2109   1.6  msaitoh 		}
   2110   1.1  msaitoh 		*autoneg = TRUE;
   2111   1.1  msaitoh 	}
   2112   1.1  msaitoh 
   2113   1.1  msaitoh 	return IXGBE_SUCCESS;
   2114   1.1  msaitoh }
   2115   1.1  msaitoh 
   2116   1.1  msaitoh /**
   2117   1.1  msaitoh  * ixgbe_get_lasi_ext_t_x550em - Determime external Base T PHY interrupt cause
   2118   1.1  msaitoh  * @hw: pointer to hardware structure
   2119   1.1  msaitoh  * @lsc: pointer to boolean flag which indicates whether external Base T
   2120   1.1  msaitoh  *       PHY interrupt is lsc
   2121   1.1  msaitoh  *
   2122   1.1  msaitoh  * Determime if external Base T PHY interrupt cause is high temperature
   2123   1.1  msaitoh  * failure alarm or link status change.
   2124   1.1  msaitoh  *
   2125   1.1  msaitoh  * Return IXGBE_ERR_OVERTEMP if interrupt is high temperature
   2126   1.1  msaitoh  * failure alarm, else return PHY access status.
   2127   1.1  msaitoh  */
   2128   1.1  msaitoh static s32 ixgbe_get_lasi_ext_t_x550em(struct ixgbe_hw *hw, bool *lsc)
   2129   1.1  msaitoh {
   2130   1.1  msaitoh 	u32 status;
   2131   1.1  msaitoh 	u16 reg;
   2132   1.1  msaitoh 
   2133   1.1  msaitoh 	*lsc = FALSE;
   2134   1.1  msaitoh 
   2135   1.1  msaitoh 	/* Vendor alarm triggered */
   2136   1.1  msaitoh 	status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_CHIP_STD_INT_FLAG,
   2137   1.1  msaitoh 				      IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   2138   1.1  msaitoh 				      &reg);
   2139   1.1  msaitoh 
   2140   1.1  msaitoh 	if (status != IXGBE_SUCCESS ||
   2141   1.1  msaitoh 	    !(reg & IXGBE_MDIO_GLOBAL_VEN_ALM_INT_EN))
   2142   1.1  msaitoh 		return status;
   2143   1.1  msaitoh 
   2144   1.1  msaitoh 	/* Vendor Auto-Neg alarm triggered or Global alarm 1 triggered */
   2145   1.1  msaitoh 	status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_FLAG,
   2146   1.1  msaitoh 				      IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   2147   1.1  msaitoh 				      &reg);
   2148   1.1  msaitoh 
   2149   1.1  msaitoh 	if (status != IXGBE_SUCCESS ||
   2150   1.1  msaitoh 	    !(reg & (IXGBE_MDIO_GLOBAL_AN_VEN_ALM_INT_EN |
   2151   1.1  msaitoh 	    IXGBE_MDIO_GLOBAL_ALARM_1_INT)))
   2152   1.1  msaitoh 		return status;
   2153   1.1  msaitoh 
   2154   1.3  msaitoh 	/* Global alarm triggered */
   2155   1.1  msaitoh 	status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_ALARM_1,
   2156   1.1  msaitoh 				      IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   2157   1.1  msaitoh 				      &reg);
   2158   1.1  msaitoh 
   2159   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   2160   1.1  msaitoh 		return status;
   2161   1.1  msaitoh 
   2162   1.1  msaitoh 	/* If high temperature failure, then return over temp error and exit */
   2163   1.1  msaitoh 	if (reg & IXGBE_MDIO_GLOBAL_ALM_1_HI_TMP_FAIL) {
   2164   1.1  msaitoh 		/* power down the PHY in case the PHY FW didn't already */
   2165   1.1  msaitoh 		ixgbe_set_copper_phy_power(hw, FALSE);
   2166   1.1  msaitoh 		return IXGBE_ERR_OVERTEMP;
   2167   1.3  msaitoh 	} else if (reg & IXGBE_MDIO_GLOBAL_ALM_1_DEV_FAULT) {
   2168   1.3  msaitoh 		/*  device fault alarm triggered */
   2169   1.3  msaitoh 		status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_FAULT_MSG,
   2170   1.3  msaitoh 					  IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   2171   1.3  msaitoh 					  &reg);
   2172   1.3  msaitoh 
   2173   1.3  msaitoh 		if (status != IXGBE_SUCCESS)
   2174   1.3  msaitoh 			return status;
   2175   1.3  msaitoh 
   2176   1.3  msaitoh 		/* if device fault was due to high temp alarm handle and exit */
   2177   1.3  msaitoh 		if (reg == IXGBE_MDIO_GLOBAL_FAULT_MSG_HI_TMP) {
   2178   1.3  msaitoh 			/* power down the PHY in case the PHY FW didn't */
   2179   1.3  msaitoh 			ixgbe_set_copper_phy_power(hw, FALSE);
   2180   1.3  msaitoh 			return IXGBE_ERR_OVERTEMP;
   2181   1.3  msaitoh 		}
   2182   1.1  msaitoh 	}
   2183   1.1  msaitoh 
   2184   1.1  msaitoh 	/* Vendor alarm 2 triggered */
   2185   1.1  msaitoh 	status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_CHIP_STD_INT_FLAG,
   2186   1.1  msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &reg);
   2187   1.1  msaitoh 
   2188   1.1  msaitoh 	if (status != IXGBE_SUCCESS ||
   2189   1.1  msaitoh 	    !(reg & IXGBE_MDIO_GLOBAL_STD_ALM2_INT))
   2190   1.1  msaitoh 		return status;
   2191   1.1  msaitoh 
   2192   1.1  msaitoh 	/* link connect/disconnect event occurred */
   2193   1.1  msaitoh 	status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_TX_ALARM2,
   2194   1.1  msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &reg);
   2195   1.1  msaitoh 
   2196   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   2197   1.1  msaitoh 		return status;
   2198   1.1  msaitoh 
   2199   1.1  msaitoh 	/* Indicate LSC */
   2200   1.1  msaitoh 	if (reg & IXGBE_MDIO_AUTO_NEG_VEN_LSC)
   2201   1.1  msaitoh 		*lsc = TRUE;
   2202   1.1  msaitoh 
   2203   1.1  msaitoh 	return IXGBE_SUCCESS;
   2204   1.1  msaitoh }
   2205   1.1  msaitoh 
   2206   1.1  msaitoh /**
   2207   1.1  msaitoh  * ixgbe_enable_lasi_ext_t_x550em - Enable external Base T PHY interrupts
   2208   1.1  msaitoh  * @hw: pointer to hardware structure
   2209   1.1  msaitoh  *
   2210   1.1  msaitoh  * Enable link status change and temperature failure alarm for the external
   2211   1.1  msaitoh  * Base T PHY
   2212   1.1  msaitoh  *
   2213   1.1  msaitoh  * Returns PHY access status
   2214   1.1  msaitoh  */
   2215   1.1  msaitoh static s32 ixgbe_enable_lasi_ext_t_x550em(struct ixgbe_hw *hw)
   2216   1.1  msaitoh {
   2217   1.1  msaitoh 	u32 status;
   2218   1.1  msaitoh 	u16 reg;
   2219   1.1  msaitoh 	bool lsc;
   2220   1.1  msaitoh 
   2221   1.1  msaitoh 	/* Clear interrupt flags */
   2222   1.1  msaitoh 	status = ixgbe_get_lasi_ext_t_x550em(hw, &lsc);
   2223   1.1  msaitoh 
   2224   1.1  msaitoh 	/* Enable link status change alarm */
   2225   1.6  msaitoh 
   2226   1.6  msaitoh 	/* Enable the LASI interrupts on X552 devices to receive notifications
   2227   1.6  msaitoh 	 * of the link configurations of the external PHY and correspondingly
   2228   1.6  msaitoh 	 * support the configuration of the internal iXFI link, since iXFI does
   2229   1.6  msaitoh 	 * not support auto-negotiation. This is not required for X553 devices
   2230   1.6  msaitoh 	 * having KR support, which performs auto-negotiations and which is used
   2231   1.6  msaitoh 	 * as the internal link to the external PHY. Hence adding a check here
   2232   1.6  msaitoh 	 * to avoid enabling LASI interrupts for X553 devices.
   2233   1.6  msaitoh 	 */
   2234   1.6  msaitoh 	if (hw->mac.type != ixgbe_mac_X550EM_a) {
   2235   1.6  msaitoh 		status = hw->phy.ops.read_reg(hw,
   2236   1.6  msaitoh 					IXGBE_MDIO_PMA_TX_VEN_LASI_INT_MASK,
   2237   1.1  msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &reg);
   2238   1.1  msaitoh 
   2239   1.6  msaitoh 		if (status != IXGBE_SUCCESS)
   2240   1.6  msaitoh 			return status;
   2241   1.1  msaitoh 
   2242   1.6  msaitoh 		reg |= IXGBE_MDIO_PMA_TX_VEN_LASI_INT_EN;
   2243   1.1  msaitoh 
   2244   1.6  msaitoh 		status = hw->phy.ops.write_reg(hw,
   2245   1.6  msaitoh 					IXGBE_MDIO_PMA_TX_VEN_LASI_INT_MASK,
   2246   1.1  msaitoh 				       IXGBE_MDIO_AUTO_NEG_DEV_TYPE, reg);
   2247   1.1  msaitoh 
   2248   1.6  msaitoh 		if (status != IXGBE_SUCCESS)
   2249   1.6  msaitoh 			return status;
   2250   1.6  msaitoh 	}
   2251   1.1  msaitoh 
   2252   1.6  msaitoh 	/* Enable high temperature failure and global fault alarms */
   2253   1.1  msaitoh 	status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_MASK,
   2254   1.1  msaitoh 				      IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   2255   1.1  msaitoh 				      &reg);
   2256   1.1  msaitoh 
   2257   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   2258   1.1  msaitoh 		return status;
   2259   1.1  msaitoh 
   2260   1.6  msaitoh 	reg |= (IXGBE_MDIO_GLOBAL_INT_HI_TEMP_EN |
   2261   1.6  msaitoh 		IXGBE_MDIO_GLOBAL_INT_DEV_FAULT_EN);
   2262   1.1  msaitoh 
   2263   1.1  msaitoh 	status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_MASK,
   2264   1.1  msaitoh 				       IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   2265   1.1  msaitoh 				       reg);
   2266   1.1  msaitoh 
   2267   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   2268   1.1  msaitoh 		return status;
   2269   1.1  msaitoh 
   2270   1.1  msaitoh 	/* Enable vendor Auto-Neg alarm and Global Interrupt Mask 1 alarm */
   2271   1.1  msaitoh 	status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_MASK,
   2272   1.1  msaitoh 				      IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   2273   1.1  msaitoh 				      &reg);
   2274   1.1  msaitoh 
   2275   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   2276   1.1  msaitoh 		return status;
   2277   1.1  msaitoh 
   2278   1.1  msaitoh 	reg |= (IXGBE_MDIO_GLOBAL_AN_VEN_ALM_INT_EN |
   2279   1.1  msaitoh 		IXGBE_MDIO_GLOBAL_ALARM_1_INT);
   2280   1.1  msaitoh 
   2281   1.1  msaitoh 	status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_MASK,
   2282   1.1  msaitoh 				       IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   2283   1.1  msaitoh 				       reg);
   2284   1.1  msaitoh 
   2285   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   2286   1.1  msaitoh 		return status;
   2287   1.1  msaitoh 
   2288   1.1  msaitoh 	/* Enable chip-wide vendor alarm */
   2289   1.1  msaitoh 	status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_STD_MASK,
   2290   1.1  msaitoh 				      IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   2291   1.1  msaitoh 				      &reg);
   2292   1.1  msaitoh 
   2293   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   2294   1.1  msaitoh 		return status;
   2295   1.1  msaitoh 
   2296   1.1  msaitoh 	reg |= IXGBE_MDIO_GLOBAL_VEN_ALM_INT_EN;
   2297   1.1  msaitoh 
   2298   1.1  msaitoh 	status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_STD_MASK,
   2299   1.1  msaitoh 				       IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   2300   1.1  msaitoh 				       reg);
   2301   1.1  msaitoh 
   2302   1.1  msaitoh 	return status;
   2303   1.1  msaitoh }
   2304   1.1  msaitoh 
   2305   1.1  msaitoh /**
   2306   1.1  msaitoh  *  ixgbe_setup_kr_speed_x550em - Configure the KR PHY for link speed.
   2307   1.1  msaitoh  *  @hw: pointer to hardware structure
   2308   1.1  msaitoh  *  @speed: link speed
   2309   1.1  msaitoh  *
   2310   1.1  msaitoh  *  Configures the integrated KR PHY.
   2311   1.1  msaitoh  **/
   2312   1.1  msaitoh static s32 ixgbe_setup_kr_speed_x550em(struct ixgbe_hw *hw,
   2313   1.1  msaitoh 				       ixgbe_link_speed speed)
   2314   1.1  msaitoh {
   2315   1.1  msaitoh 	s32 status;
   2316   1.1  msaitoh 	u32 reg_val;
   2317   1.1  msaitoh 
   2318   1.6  msaitoh 	status = hw->mac.ops.read_iosf_sb_reg(hw,
   2319   1.1  msaitoh 		IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
   2320   1.1  msaitoh 		IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
   2321   1.1  msaitoh 	if (status)
   2322   1.1  msaitoh 		return status;
   2323   1.1  msaitoh 
   2324   1.1  msaitoh 	reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
   2325   1.1  msaitoh 	reg_val &= ~(IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR |
   2326   1.1  msaitoh 		     IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX);
   2327   1.1  msaitoh 
   2328   1.1  msaitoh 	/* Advertise 10G support. */
   2329   1.1  msaitoh 	if (speed & IXGBE_LINK_SPEED_10GB_FULL)
   2330   1.1  msaitoh 		reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR;
   2331   1.1  msaitoh 
   2332   1.1  msaitoh 	/* Advertise 1G support. */
   2333   1.1  msaitoh 	if (speed & IXGBE_LINK_SPEED_1GB_FULL)
   2334   1.1  msaitoh 		reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX;
   2335   1.1  msaitoh 
   2336   1.6  msaitoh 	status = hw->mac.ops.write_iosf_sb_reg(hw,
   2337   1.1  msaitoh 		IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
   2338   1.1  msaitoh 		IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
   2339   1.1  msaitoh 
   2340   1.6  msaitoh 	if (hw->mac.type == ixgbe_mac_X550EM_a) {
   2341   1.6  msaitoh 		/* Set lane mode  to KR auto negotiation */
   2342   1.6  msaitoh 		status = hw->mac.ops.read_iosf_sb_reg(hw,
   2343   1.6  msaitoh 				    IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
   2344   1.6  msaitoh 				    IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
   2345   1.6  msaitoh 
   2346   1.6  msaitoh 		if (status)
   2347   1.6  msaitoh 			return status;
   2348   1.6  msaitoh 
   2349   1.6  msaitoh 		reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_MASK;
   2350   1.6  msaitoh 		reg_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_AN;
   2351   1.6  msaitoh 		reg_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_AN_EN;
   2352   1.6  msaitoh 		reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN37_EN;
   2353   1.6  msaitoh 		reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SGMII_EN;
   2354   1.6  msaitoh 
   2355   1.6  msaitoh 		status = hw->mac.ops.write_iosf_sb_reg(hw,
   2356   1.6  msaitoh 				    IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
   2357   1.6  msaitoh 				    IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
   2358   1.6  msaitoh 	}
   2359   1.6  msaitoh 
   2360   1.6  msaitoh 	return ixgbe_restart_an_internal_phy_x550em(hw);
   2361   1.6  msaitoh }
   2362   1.6  msaitoh 
   2363   1.6  msaitoh /**
   2364   1.6  msaitoh  * ixgbe_reset_phy_fw - Reset firmware-controlled PHYs
   2365   1.6  msaitoh  * @hw: pointer to hardware structure
   2366   1.6  msaitoh  */
   2367   1.6  msaitoh static s32 ixgbe_reset_phy_fw(struct ixgbe_hw *hw)
   2368   1.6  msaitoh {
   2369   1.6  msaitoh 	u32 store[FW_PHY_ACT_DATA_COUNT] = { 0 };
   2370   1.6  msaitoh 	s32 rc;
   2371   1.6  msaitoh 
   2372   1.6  msaitoh 	if (hw->phy.reset_disable || ixgbe_check_reset_blocked(hw))
   2373   1.6  msaitoh 		return IXGBE_SUCCESS;
   2374   1.6  msaitoh 
   2375   1.6  msaitoh 	rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_PHY_SW_RESET, &store);
   2376   1.6  msaitoh 	if (rc)
   2377   1.6  msaitoh 		return rc;
   2378   1.6  msaitoh 	memset(store, 0, sizeof(store));
   2379   1.6  msaitoh 
   2380   1.6  msaitoh 	rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_INIT_PHY, &store);
   2381   1.6  msaitoh 	if (rc)
   2382   1.6  msaitoh 		return rc;
   2383   1.6  msaitoh 
   2384   1.6  msaitoh 	return ixgbe_setup_fw_link(hw);
   2385   1.6  msaitoh }
   2386   1.6  msaitoh 
   2387   1.6  msaitoh /**
   2388   1.6  msaitoh  * ixgbe_check_overtemp_fw - Check firmware-controlled PHYs for overtemp
   2389   1.6  msaitoh  * @hw: pointer to hardware structure
   2390   1.6  msaitoh  */
   2391   1.6  msaitoh static s32 ixgbe_check_overtemp_fw(struct ixgbe_hw *hw)
   2392   1.6  msaitoh {
   2393   1.6  msaitoh 	u32 store[FW_PHY_ACT_DATA_COUNT] = { 0 };
   2394   1.6  msaitoh 	s32 rc;
   2395   1.6  msaitoh 
   2396   1.6  msaitoh 	rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_GET_LINK_INFO, &store);
   2397   1.6  msaitoh 	if (rc)
   2398   1.6  msaitoh 		return rc;
   2399   1.6  msaitoh 
   2400   1.6  msaitoh 	if (store[0] & FW_PHY_ACT_GET_LINK_INFO_TEMP) {
   2401   1.6  msaitoh 		ixgbe_shutdown_fw_phy(hw);
   2402   1.6  msaitoh 		return IXGBE_ERR_OVERTEMP;
   2403   1.6  msaitoh 	}
   2404   1.6  msaitoh 	return IXGBE_SUCCESS;
   2405   1.6  msaitoh }
   2406   1.6  msaitoh 
   2407   1.6  msaitoh /**
   2408   1.6  msaitoh  *  ixgbe_read_mng_if_sel_x550em - Read NW_MNG_IF_SEL register
   2409   1.6  msaitoh  *  @hw: pointer to hardware structure
   2410   1.6  msaitoh  *
   2411   1.6  msaitoh  *  Read NW_MNG_IF_SEL register and save field values, and check for valid field
   2412   1.6  msaitoh  *  values.
   2413   1.6  msaitoh  **/
   2414   1.6  msaitoh static s32 ixgbe_read_mng_if_sel_x550em(struct ixgbe_hw *hw)
   2415   1.6  msaitoh {
   2416   1.6  msaitoh 	/* Save NW management interface connected on board. This is used
   2417   1.6  msaitoh 	 * to determine internal PHY mode.
   2418   1.6  msaitoh 	 */
   2419   1.6  msaitoh 	hw->phy.nw_mng_if_sel = IXGBE_READ_REG(hw, IXGBE_NW_MNG_IF_SEL);
   2420   1.6  msaitoh 
   2421   1.6  msaitoh 	/* If X552 (X550EM_a) and MDIO is connected to external PHY, then set
   2422   1.6  msaitoh 	 * PHY address. This register field was has only been used for X552.
   2423   1.6  msaitoh 	 */
   2424   1.6  msaitoh 	if (hw->mac.type == ixgbe_mac_X550EM_a &&
   2425   1.6  msaitoh 	    hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_MDIO_ACT) {
   2426   1.6  msaitoh 		hw->phy.addr = (hw->phy.nw_mng_if_sel &
   2427   1.6  msaitoh 				IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD) >>
   2428   1.6  msaitoh 			       IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD_SHIFT;
   2429   1.6  msaitoh 	}
   2430   1.6  msaitoh 
   2431   1.6  msaitoh 	return IXGBE_SUCCESS;
   2432   1.1  msaitoh }
   2433   1.1  msaitoh 
   2434   1.1  msaitoh /**
   2435   1.1  msaitoh  *  ixgbe_init_phy_ops_X550em - PHY/SFP specific init
   2436   1.1  msaitoh  *  @hw: pointer to hardware structure
   2437   1.1  msaitoh  *
   2438   1.1  msaitoh  *  Initialize any function pointers that were not able to be
   2439   1.1  msaitoh  *  set during init_shared_code because the PHY/SFP type was
   2440   1.1  msaitoh  *  not known.  Perform the SFP init if necessary.
   2441   1.1  msaitoh  */
   2442   1.1  msaitoh s32 ixgbe_init_phy_ops_X550em(struct ixgbe_hw *hw)
   2443   1.1  msaitoh {
   2444   1.1  msaitoh 	struct ixgbe_phy_info *phy = &hw->phy;
   2445   1.1  msaitoh 	s32 ret_val;
   2446   1.1  msaitoh 
   2447   1.1  msaitoh 	DEBUGFUNC("ixgbe_init_phy_ops_X550em");
   2448   1.1  msaitoh 
   2449   1.1  msaitoh 	hw->mac.ops.set_lan_id(hw);
   2450   1.6  msaitoh 	ixgbe_read_mng_if_sel_x550em(hw);
   2451   1.1  msaitoh 
   2452   1.1  msaitoh 	if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) {
   2453   1.1  msaitoh 		phy->phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
   2454   1.1  msaitoh 		ixgbe_setup_mux_ctl(hw);
   2455   1.6  msaitoh 		phy->ops.identify_sfp = ixgbe_identify_sfp_module_X550em;
   2456   1.6  msaitoh 	}
   2457   1.1  msaitoh 
   2458   1.6  msaitoh 	switch (hw->device_id) {
   2459   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_1G_T:
   2460   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_1G_T_L:
   2461   1.6  msaitoh 		phy->ops.read_reg_mdi = ixgbe_read_phy_reg_mdi_22;
   2462   1.6  msaitoh 		phy->ops.write_reg_mdi = ixgbe_write_phy_reg_mdi_22;
   2463   1.6  msaitoh 		hw->phy.ops.read_reg = ixgbe_read_phy_reg_x550a;
   2464   1.6  msaitoh 		hw->phy.ops.write_reg = ixgbe_write_phy_reg_x550a;
   2465   1.6  msaitoh 		phy->ops.check_overtemp = ixgbe_check_overtemp_fw;
   2466   1.6  msaitoh 		if (hw->bus.lan_id)
   2467   1.6  msaitoh 			hw->phy.phy_semaphore_mask |= IXGBE_GSSR_PHY1_SM;
   2468   1.6  msaitoh 		else
   2469   1.6  msaitoh 			hw->phy.phy_semaphore_mask |= IXGBE_GSSR_PHY0_SM;
   2470   1.6  msaitoh 
   2471   1.6  msaitoh 		break;
   2472   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_10G_T:
   2473   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_SFP:
   2474   1.6  msaitoh 		hw->phy.ops.read_reg = ixgbe_read_phy_reg_x550a;
   2475   1.6  msaitoh 		hw->phy.ops.write_reg = ixgbe_write_phy_reg_x550a;
   2476   1.6  msaitoh 		if (hw->bus.lan_id)
   2477   1.6  msaitoh 			hw->phy.phy_semaphore_mask |= IXGBE_GSSR_PHY1_SM;
   2478   1.6  msaitoh 		else
   2479   1.6  msaitoh 			hw->phy.phy_semaphore_mask |= IXGBE_GSSR_PHY0_SM;
   2480   1.6  msaitoh 		break;
   2481   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_X_SFP:
   2482   1.6  msaitoh 		/* set up for CS4227 usage */
   2483   1.6  msaitoh 		hw->phy.phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
   2484   1.6  msaitoh 		break;
   2485   1.8  msaitoh 	case IXGBE_DEV_ID_X550EM_X_1G_T:
   2486   1.8  msaitoh 		phy->ops.read_reg_mdi = NULL;
   2487   1.8  msaitoh 		phy->ops.write_reg_mdi = NULL;
   2488   1.8  msaitoh 		break;
   2489   1.6  msaitoh 	default:
   2490   1.6  msaitoh 		break;
   2491   1.1  msaitoh 	}
   2492   1.1  msaitoh 
   2493   1.1  msaitoh 	/* Identify the PHY or SFP module */
   2494   1.1  msaitoh 	ret_val = phy->ops.identify(hw);
   2495   1.6  msaitoh 	if (ret_val == IXGBE_ERR_SFP_NOT_SUPPORTED ||
   2496   1.6  msaitoh 	    ret_val == IXGBE_ERR_PHY_ADDR_INVALID)
   2497   1.1  msaitoh 		return ret_val;
   2498   1.1  msaitoh 
   2499   1.1  msaitoh 	/* Setup function pointers based on detected hardware */
   2500   1.1  msaitoh 	ixgbe_init_mac_link_ops_X550em(hw);
   2501   1.1  msaitoh 	if (phy->sfp_type != ixgbe_sfp_type_unknown)
   2502   1.1  msaitoh 		phy->ops.reset = NULL;
   2503   1.1  msaitoh 
   2504   1.1  msaitoh 	/* Set functions pointers based on phy type */
   2505   1.1  msaitoh 	switch (hw->phy.type) {
   2506   1.1  msaitoh 	case ixgbe_phy_x550em_kx4:
   2507   1.2  msaitoh 		phy->ops.setup_link = NULL;
   2508   1.1  msaitoh 		phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
   2509   1.1  msaitoh 		phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
   2510   1.1  msaitoh 		break;
   2511   1.1  msaitoh 	case ixgbe_phy_x550em_kr:
   2512   1.1  msaitoh 		phy->ops.setup_link = ixgbe_setup_kr_x550em;
   2513   1.1  msaitoh 		phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
   2514   1.1  msaitoh 		phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
   2515   1.1  msaitoh 		break;
   2516   1.6  msaitoh 	case ixgbe_phy_ext_1g_t:
   2517   1.6  msaitoh 		/* link is managed by FW */
   2518   1.6  msaitoh 		phy->ops.setup_link = NULL;
   2519   1.6  msaitoh 		phy->ops.reset = NULL;
   2520   1.6  msaitoh 		break;
   2521   1.6  msaitoh 	case ixgbe_phy_x550em_xfi:
   2522   1.6  msaitoh 		/* link is managed by HW */
   2523   1.6  msaitoh 		phy->ops.setup_link = NULL;
   2524   1.6  msaitoh 		phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
   2525   1.6  msaitoh 		phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
   2526   1.6  msaitoh 		break;
   2527   1.1  msaitoh 	case ixgbe_phy_x550em_ext_t:
   2528   1.1  msaitoh 		/* If internal link mode is XFI, then setup iXFI internal link,
   2529   1.1  msaitoh 		 * else setup KR now.
   2530   1.1  msaitoh 		 */
   2531   1.6  msaitoh 		phy->ops.setup_internal_link =
   2532   1.1  msaitoh 					      ixgbe_setup_internal_phy_t_x550em;
   2533   1.1  msaitoh 
   2534   1.6  msaitoh 		/* setup SW LPLU only for first revision of X550EM_x */
   2535   1.6  msaitoh 		if ((hw->mac.type == ixgbe_mac_X550EM_x) &&
   2536   1.6  msaitoh 		    !(IXGBE_FUSES0_REV_MASK &
   2537   1.6  msaitoh 		      IXGBE_READ_REG(hw, IXGBE_FUSES0_GROUP(0))))
   2538   1.2  msaitoh 			phy->ops.enter_lplu = ixgbe_enter_lplu_t_x550em;
   2539   1.2  msaitoh 
   2540   1.1  msaitoh 		phy->ops.handle_lasi = ixgbe_handle_lasi_ext_t_x550em;
   2541   1.1  msaitoh 		phy->ops.reset = ixgbe_reset_phy_t_X550em;
   2542   1.1  msaitoh 		break;
   2543   1.6  msaitoh 	case ixgbe_phy_sgmii:
   2544   1.6  msaitoh 		phy->ops.setup_link = NULL;
   2545   1.6  msaitoh 		break;
   2546   1.6  msaitoh 	case ixgbe_phy_fw:
   2547   1.6  msaitoh 		phy->ops.setup_link = ixgbe_setup_fw_link;
   2548   1.6  msaitoh 		phy->ops.reset = ixgbe_reset_phy_fw;
   2549   1.6  msaitoh 		break;
   2550   1.1  msaitoh 	default:
   2551   1.1  msaitoh 		break;
   2552   1.1  msaitoh 	}
   2553   1.1  msaitoh 	return ret_val;
   2554   1.1  msaitoh }
   2555   1.1  msaitoh 
   2556   1.1  msaitoh /**
   2557   1.6  msaitoh  * ixgbe_set_mdio_speed - Set MDIO clock speed
   2558   1.6  msaitoh  *  @hw: pointer to hardware structure
   2559   1.6  msaitoh  */
   2560   1.6  msaitoh static void ixgbe_set_mdio_speed(struct ixgbe_hw *hw)
   2561   1.6  msaitoh {
   2562   1.6  msaitoh 	u32 hlreg0;
   2563   1.6  msaitoh 
   2564   1.6  msaitoh 	switch (hw->device_id) {
   2565   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_X_10G_T:
   2566   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_SGMII:
   2567   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_SGMII_L:
   2568   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_10G_T:
   2569   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_SFP:
   2570   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_QSFP:
   2571   1.6  msaitoh 		/* Config MDIO clock speed before the first MDIO PHY access */
   2572   1.6  msaitoh 		hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
   2573   1.6  msaitoh 		hlreg0 &= ~IXGBE_HLREG0_MDCSPD;
   2574   1.6  msaitoh 		IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
   2575   1.6  msaitoh 		break;
   2576   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_1G_T:
   2577   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_1G_T_L:
   2578   1.6  msaitoh 		/* Select fast MDIO clock speed for these devices */
   2579   1.6  msaitoh 		hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
   2580   1.6  msaitoh 		hlreg0 |= IXGBE_HLREG0_MDCSPD;
   2581   1.6  msaitoh 		IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
   2582   1.6  msaitoh 		break;
   2583   1.6  msaitoh 	default:
   2584   1.6  msaitoh 		break;
   2585   1.6  msaitoh 	}
   2586   1.6  msaitoh }
   2587   1.6  msaitoh 
   2588   1.6  msaitoh /**
   2589   1.6  msaitoh  *  ixgbe_reset_hw_X550em - Perform hardware reset
   2590   1.1  msaitoh  *  @hw: pointer to hardware structure
   2591   1.1  msaitoh  *
   2592   1.1  msaitoh  *  Resets the hardware by resetting the transmit and receive units, masks
   2593   1.1  msaitoh  *  and clears all interrupts, perform a PHY reset, and perform a link (MAC)
   2594   1.1  msaitoh  *  reset.
   2595   1.1  msaitoh  */
   2596   1.1  msaitoh s32 ixgbe_reset_hw_X550em(struct ixgbe_hw *hw)
   2597   1.1  msaitoh {
   2598   1.1  msaitoh 	ixgbe_link_speed link_speed;
   2599   1.1  msaitoh 	s32 status;
   2600   1.1  msaitoh 	u32 ctrl = 0;
   2601   1.1  msaitoh 	u32 i;
   2602   1.1  msaitoh 	bool link_up = FALSE;
   2603   1.6  msaitoh 	u32 swfw_mask = hw->phy.phy_semaphore_mask;
   2604   1.1  msaitoh 
   2605   1.1  msaitoh 	DEBUGFUNC("ixgbe_reset_hw_X550em");
   2606   1.1  msaitoh 
   2607   1.1  msaitoh 	/* Call adapter stop to disable Tx/Rx and clear interrupts */
   2608   1.1  msaitoh 	status = hw->mac.ops.stop_adapter(hw);
   2609   1.6  msaitoh 	if (status != IXGBE_SUCCESS) {
   2610   1.6  msaitoh 		DEBUGOUT1("Failed to stop adapter, STATUS = %d\n", status);
   2611   1.1  msaitoh 		return status;
   2612   1.6  msaitoh 	}
   2613   1.1  msaitoh 	/* flush pending Tx transactions */
   2614   1.1  msaitoh 	ixgbe_clear_tx_pending(hw);
   2615   1.1  msaitoh 
   2616   1.6  msaitoh 	ixgbe_set_mdio_speed(hw);
   2617   1.2  msaitoh 
   2618   1.1  msaitoh 	/* PHY ops must be identified and initialized prior to reset */
   2619   1.1  msaitoh 	status = hw->phy.ops.init(hw);
   2620   1.1  msaitoh 
   2621   1.6  msaitoh 	if (status)
   2622   1.6  msaitoh 		DEBUGOUT1("Failed to initialize PHY ops, STATUS = %d\n",
   2623   1.6  msaitoh 			  status);
   2624   1.6  msaitoh 
   2625   1.8  msaitoh 	if (status == IXGBE_ERR_SFP_NOT_SUPPORTED ||
   2626   1.8  msaitoh 	    status == IXGBE_ERR_PHY_ADDR_INVALID) {
   2627   1.6  msaitoh 		DEBUGOUT("Returning from reset HW due to PHY init failure\n");
   2628   1.1  msaitoh 		return status;
   2629   1.6  msaitoh 	}
   2630   1.1  msaitoh 
   2631   1.1  msaitoh 	/* start the external PHY */
   2632   1.1  msaitoh 	if (hw->phy.type == ixgbe_phy_x550em_ext_t) {
   2633   1.1  msaitoh 		status = ixgbe_init_ext_t_x550em(hw);
   2634   1.6  msaitoh 		if (status) {
   2635   1.6  msaitoh 			DEBUGOUT1("Failed to start the external PHY, STATUS = %d\n",
   2636   1.6  msaitoh 				  status);
   2637   1.1  msaitoh 			return status;
   2638   1.6  msaitoh 		}
   2639   1.1  msaitoh 	}
   2640   1.1  msaitoh 
   2641   1.1  msaitoh 	/* Setup SFP module if there is one present. */
   2642   1.1  msaitoh 	if (hw->phy.sfp_setup_needed) {
   2643   1.1  msaitoh 		status = hw->mac.ops.setup_sfp(hw);
   2644   1.1  msaitoh 		hw->phy.sfp_setup_needed = FALSE;
   2645   1.1  msaitoh 	}
   2646   1.1  msaitoh 
   2647   1.1  msaitoh 	if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
   2648   1.1  msaitoh 		return status;
   2649   1.1  msaitoh 
   2650   1.1  msaitoh 	/* Reset PHY */
   2651   1.6  msaitoh 	if (!hw->phy.reset_disable && hw->phy.ops.reset) {
   2652   1.6  msaitoh 		if (hw->phy.ops.reset(hw) == IXGBE_ERR_OVERTEMP)
   2653   1.6  msaitoh 			return IXGBE_ERR_OVERTEMP;
   2654   1.6  msaitoh 	}
   2655   1.1  msaitoh 
   2656   1.1  msaitoh mac_reset_top:
   2657   1.1  msaitoh 	/* Issue global reset to the MAC.  Needs to be SW reset if link is up.
   2658   1.1  msaitoh 	 * If link reset is used when link is up, it might reset the PHY when
   2659   1.1  msaitoh 	 * mng is using it.  If link is down or the flag to force full link
   2660   1.1  msaitoh 	 * reset is set, then perform link reset.
   2661   1.1  msaitoh 	 */
   2662   1.1  msaitoh 	ctrl = IXGBE_CTRL_LNK_RST;
   2663   1.1  msaitoh 	if (!hw->force_full_reset) {
   2664   1.1  msaitoh 		hw->mac.ops.check_link(hw, &link_speed, &link_up, FALSE);
   2665   1.1  msaitoh 		if (link_up)
   2666   1.1  msaitoh 			ctrl = IXGBE_CTRL_RST;
   2667   1.1  msaitoh 	}
   2668   1.1  msaitoh 
   2669   1.6  msaitoh 	status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
   2670   1.6  msaitoh 	if (status != IXGBE_SUCCESS) {
   2671   1.6  msaitoh 		ERROR_REPORT2(IXGBE_ERROR_CAUTION,
   2672   1.6  msaitoh 			"semaphore failed with %d", status);
   2673   1.6  msaitoh 		return IXGBE_ERR_SWFW_SYNC;
   2674   1.6  msaitoh 	}
   2675   1.1  msaitoh 	ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
   2676   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
   2677   1.1  msaitoh 	IXGBE_WRITE_FLUSH(hw);
   2678   1.6  msaitoh 	hw->mac.ops.release_swfw_sync(hw, swfw_mask);
   2679   1.1  msaitoh 
   2680   1.1  msaitoh 	/* Poll for reset bit to self-clear meaning reset is complete */
   2681   1.1  msaitoh 	for (i = 0; i < 10; i++) {
   2682   1.1  msaitoh 		usec_delay(1);
   2683   1.1  msaitoh 		ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
   2684   1.1  msaitoh 		if (!(ctrl & IXGBE_CTRL_RST_MASK))
   2685   1.1  msaitoh 			break;
   2686   1.1  msaitoh 	}
   2687   1.1  msaitoh 
   2688   1.1  msaitoh 	if (ctrl & IXGBE_CTRL_RST_MASK) {
   2689   1.1  msaitoh 		status = IXGBE_ERR_RESET_FAILED;
   2690   1.1  msaitoh 		DEBUGOUT("Reset polling failed to complete.\n");
   2691   1.1  msaitoh 	}
   2692   1.1  msaitoh 
   2693   1.1  msaitoh 	msec_delay(50);
   2694   1.1  msaitoh 
   2695   1.1  msaitoh 	/* Double resets are required for recovery from certain error
   2696   1.1  msaitoh 	 * conditions.  Between resets, it is necessary to stall to
   2697   1.1  msaitoh 	 * allow time for any pending HW events to complete.
   2698   1.1  msaitoh 	 */
   2699   1.1  msaitoh 	if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
   2700   1.1  msaitoh 		hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
   2701   1.1  msaitoh 		goto mac_reset_top;
   2702   1.1  msaitoh 	}
   2703   1.1  msaitoh 
   2704   1.1  msaitoh 	/* Store the permanent mac address */
   2705   1.1  msaitoh 	hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
   2706   1.1  msaitoh 
   2707   1.1  msaitoh 	/* Store MAC address from RAR0, clear receive address registers, and
   2708   1.1  msaitoh 	 * clear the multicast table.  Also reset num_rar_entries to 128,
   2709   1.1  msaitoh 	 * since we modify this value when programming the SAN MAC address.
   2710   1.1  msaitoh 	 */
   2711   1.1  msaitoh 	hw->mac.num_rar_entries = 128;
   2712   1.1  msaitoh 	hw->mac.ops.init_rx_addrs(hw);
   2713   1.1  msaitoh 
   2714   1.6  msaitoh 	ixgbe_set_mdio_speed(hw);
   2715   1.6  msaitoh 
   2716   1.1  msaitoh 	if (hw->device_id == IXGBE_DEV_ID_X550EM_X_SFP)
   2717   1.1  msaitoh 		ixgbe_setup_mux_ctl(hw);
   2718   1.1  msaitoh 
   2719   1.6  msaitoh 	if (status != IXGBE_SUCCESS)
   2720   1.6  msaitoh 		DEBUGOUT1("Reset HW failed, STATUS = %d\n", status);
   2721   1.6  msaitoh 
   2722   1.1  msaitoh 	return status;
   2723   1.1  msaitoh }
   2724   1.1  msaitoh 
   2725   1.1  msaitoh /**
   2726   1.1  msaitoh  * ixgbe_init_ext_t_x550em - Start (unstall) the external Base T PHY.
   2727   1.1  msaitoh  * @hw: pointer to hardware structure
   2728   1.1  msaitoh  */
   2729   1.1  msaitoh s32 ixgbe_init_ext_t_x550em(struct ixgbe_hw *hw)
   2730   1.1  msaitoh {
   2731   1.1  msaitoh 	u32 status;
   2732   1.1  msaitoh 	u16 reg;
   2733   1.1  msaitoh 
   2734   1.1  msaitoh 	status = hw->phy.ops.read_reg(hw,
   2735   1.1  msaitoh 				      IXGBE_MDIO_TX_VENDOR_ALARMS_3,
   2736   1.1  msaitoh 				      IXGBE_MDIO_PMA_PMD_DEV_TYPE,
   2737   1.1  msaitoh 				      &reg);
   2738   1.1  msaitoh 
   2739   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   2740   1.1  msaitoh 		return status;
   2741   1.1  msaitoh 
   2742   1.1  msaitoh 	/* If PHY FW reset completed bit is set then this is the first
   2743   1.1  msaitoh 	 * SW instance after a power on so the PHY FW must be un-stalled.
   2744   1.1  msaitoh 	 */
   2745   1.1  msaitoh 	if (reg & IXGBE_MDIO_TX_VENDOR_ALARMS_3_RST_MASK) {
   2746   1.1  msaitoh 		status = hw->phy.ops.read_reg(hw,
   2747   1.1  msaitoh 					IXGBE_MDIO_GLOBAL_RES_PR_10,
   2748   1.1  msaitoh 					IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   2749   1.1  msaitoh 					&reg);
   2750   1.1  msaitoh 
   2751   1.1  msaitoh 		if (status != IXGBE_SUCCESS)
   2752   1.1  msaitoh 			return status;
   2753   1.1  msaitoh 
   2754   1.1  msaitoh 		reg &= ~IXGBE_MDIO_POWER_UP_STALL;
   2755   1.1  msaitoh 
   2756   1.1  msaitoh 		status = hw->phy.ops.write_reg(hw,
   2757   1.1  msaitoh 					IXGBE_MDIO_GLOBAL_RES_PR_10,
   2758   1.1  msaitoh 					IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
   2759   1.1  msaitoh 					reg);
   2760   1.1  msaitoh 
   2761   1.1  msaitoh 		if (status != IXGBE_SUCCESS)
   2762   1.1  msaitoh 			return status;
   2763   1.1  msaitoh 	}
   2764   1.1  msaitoh 
   2765   1.1  msaitoh 	return status;
   2766   1.1  msaitoh }
   2767   1.1  msaitoh 
   2768   1.1  msaitoh /**
   2769   1.1  msaitoh  *  ixgbe_setup_kr_x550em - Configure the KR PHY.
   2770   1.1  msaitoh  *  @hw: pointer to hardware structure
   2771   1.1  msaitoh  **/
   2772   1.1  msaitoh s32 ixgbe_setup_kr_x550em(struct ixgbe_hw *hw)
   2773   1.1  msaitoh {
   2774   1.6  msaitoh 	/* leave link alone for 2.5G */
   2775   1.6  msaitoh 	if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_2_5GB_FULL)
   2776   1.6  msaitoh 		return IXGBE_SUCCESS;
   2777   1.6  msaitoh 
   2778   1.6  msaitoh 	if (ixgbe_check_reset_blocked(hw))
   2779   1.6  msaitoh 		return 0;
   2780   1.6  msaitoh 
   2781   1.1  msaitoh 	return ixgbe_setup_kr_speed_x550em(hw, hw->phy.autoneg_advertised);
   2782   1.1  msaitoh }
   2783   1.1  msaitoh 
   2784   1.1  msaitoh /**
   2785   1.1  msaitoh  *  ixgbe_setup_mac_link_sfp_x550em - Setup internal/external the PHY for SFP
   2786   1.1  msaitoh  *  @hw: pointer to hardware structure
   2787  1.12  msaitoh  *  @speed: new link speed
   2788  1.12  msaitoh  *  @autoneg_wait_to_complete: unused
   2789   1.1  msaitoh  *
   2790   1.1  msaitoh  *  Configure the external PHY and the integrated KR PHY for SFP support.
   2791   1.1  msaitoh  **/
   2792   1.1  msaitoh s32 ixgbe_setup_mac_link_sfp_x550em(struct ixgbe_hw *hw,
   2793   1.1  msaitoh 				    ixgbe_link_speed speed,
   2794   1.1  msaitoh 				    bool autoneg_wait_to_complete)
   2795   1.1  msaitoh {
   2796   1.1  msaitoh 	s32 ret_val;
   2797   1.1  msaitoh 	u16 reg_slice, reg_val;
   2798   1.1  msaitoh 	bool setup_linear = FALSE;
   2799   1.1  msaitoh 	UNREFERENCED_1PARAMETER(autoneg_wait_to_complete);
   2800   1.1  msaitoh 
   2801   1.1  msaitoh 	/* Check if SFP module is supported and linear */
   2802   1.1  msaitoh 	ret_val = ixgbe_supported_sfp_modules_X550em(hw, &setup_linear);
   2803   1.1  msaitoh 
   2804   1.1  msaitoh 	/* If no SFP module present, then return success. Return success since
   2805   1.1  msaitoh 	 * there is no reason to configure CS4227 and SFP not present error is
   2806   1.1  msaitoh 	 * not excepted in the setup MAC link flow.
   2807   1.1  msaitoh 	 */
   2808   1.1  msaitoh 	if (ret_val == IXGBE_ERR_SFP_NOT_PRESENT)
   2809   1.1  msaitoh 		return IXGBE_SUCCESS;
   2810   1.1  msaitoh 
   2811   1.1  msaitoh 	if (ret_val != IXGBE_SUCCESS)
   2812   1.1  msaitoh 		return ret_val;
   2813   1.1  msaitoh 
   2814   1.6  msaitoh 	/* Configure internal PHY for KR/KX. */
   2815   1.6  msaitoh 	ixgbe_setup_kr_speed_x550em(hw, speed);
   2816   1.2  msaitoh 
   2817   1.6  msaitoh 	/* Configure CS4227 LINE side to proper mode. */
   2818   1.6  msaitoh 	reg_slice = IXGBE_CS4227_LINE_SPARE24_LSB +
   2819   1.6  msaitoh 		    (hw->bus.lan_id << 12);
   2820   1.6  msaitoh 	if (setup_linear)
   2821   1.6  msaitoh 		reg_val = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 0x1;
   2822   1.6  msaitoh 	else
   2823   1.1  msaitoh 		reg_val = (IXGBE_CS4227_EDC_MODE_SR << 1) | 0x1;
   2824   1.6  msaitoh 	ret_val = hw->link.ops.write_link(hw, hw->link.addr, reg_slice,
   2825   1.6  msaitoh 					  reg_val);
   2826   1.1  msaitoh 	return ret_val;
   2827   1.1  msaitoh }
   2828   1.1  msaitoh 
   2829   1.1  msaitoh /**
   2830   1.6  msaitoh  *  ixgbe_setup_sfi_x550a - Configure the internal PHY for native SFI mode
   2831   1.1  msaitoh  *  @hw: pointer to hardware structure
   2832   1.1  msaitoh  *  @speed: the link speed to force
   2833   1.1  msaitoh  *
   2834   1.6  msaitoh  *  Configures the integrated PHY for native SFI mode. Used to connect the
   2835   1.6  msaitoh  *  internal PHY directly to an SFP cage, without autonegotiation.
   2836   1.1  msaitoh  **/
   2837   1.6  msaitoh static s32 ixgbe_setup_sfi_x550a(struct ixgbe_hw *hw, ixgbe_link_speed *speed)
   2838   1.1  msaitoh {
   2839   1.6  msaitoh 	struct ixgbe_mac_info *mac = &hw->mac;
   2840   1.1  msaitoh 	s32 status;
   2841   1.1  msaitoh 	u32 reg_val;
   2842   1.1  msaitoh 
   2843   1.6  msaitoh 	/* Disable all AN and force speed to 10G Serial. */
   2844   1.6  msaitoh 	status = mac->ops.read_iosf_sb_reg(hw,
   2845   1.6  msaitoh 				IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
   2846   1.1  msaitoh 					IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
   2847   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   2848   1.1  msaitoh 		return status;
   2849   1.1  msaitoh 
   2850   1.6  msaitoh 	reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN_EN;
   2851   1.6  msaitoh 	reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN37_EN;
   2852   1.6  msaitoh 	reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SGMII_EN;
   2853   1.6  msaitoh 	reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_MASK;
   2854   1.1  msaitoh 
   2855   1.1  msaitoh 	/* Select forced link speed for internal PHY. */
   2856   1.1  msaitoh 	switch (*speed) {
   2857   1.1  msaitoh 	case IXGBE_LINK_SPEED_10GB_FULL:
   2858   1.6  msaitoh 		reg_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_10G;
   2859   1.1  msaitoh 		break;
   2860   1.1  msaitoh 	case IXGBE_LINK_SPEED_1GB_FULL:
   2861   1.6  msaitoh 		reg_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_1G;
   2862   1.1  msaitoh 		break;
   2863  1.10  msaitoh 	case 0:
   2864  1.10  msaitoh 		/* media none (linkdown) */
   2865  1.10  msaitoh 		break;
   2866   1.1  msaitoh 	default:
   2867   1.6  msaitoh 		/* Other link speeds are not supported by internal PHY. */
   2868   1.1  msaitoh 		return IXGBE_ERR_LINK_SETUP;
   2869   1.1  msaitoh 	}
   2870   1.1  msaitoh 
   2871   1.6  msaitoh 	status = mac->ops.write_iosf_sb_reg(hw,
   2872   1.6  msaitoh 				IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
   2873   1.1  msaitoh 					IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
   2874   1.6  msaitoh 
   2875   1.6  msaitoh 	/* Toggle port SW reset by AN reset. */
   2876   1.6  msaitoh 	status = ixgbe_restart_an_internal_phy_x550em(hw);
   2877   1.6  msaitoh 
   2878   1.6  msaitoh 	return status;
   2879   1.6  msaitoh }
   2880   1.6  msaitoh 
   2881   1.6  msaitoh /**
   2882   1.6  msaitoh  *  ixgbe_setup_mac_link_sfp_x550a - Setup internal PHY for SFP
   2883   1.6  msaitoh  *  @hw: pointer to hardware structure
   2884  1.12  msaitoh  *  @speed: new link speed
   2885  1.12  msaitoh  *  @autoneg_wait_to_complete: unused
   2886   1.6  msaitoh  *
   2887   1.6  msaitoh  *  Configure the the integrated PHY for SFP support.
   2888   1.6  msaitoh  **/
   2889  1.10  msaitoh static s32 ixgbe_setup_mac_link_sfp_x550a(struct ixgbe_hw *hw,
   2890   1.6  msaitoh 				    ixgbe_link_speed speed,
   2891   1.6  msaitoh 				    bool autoneg_wait_to_complete)
   2892   1.6  msaitoh {
   2893   1.6  msaitoh 	s32 ret_val;
   2894   1.6  msaitoh 	u16 reg_phy_ext;
   2895   1.6  msaitoh 	bool setup_linear = FALSE;
   2896   1.6  msaitoh 	u32 reg_slice, reg_phy_int, slice_offset;
   2897   1.6  msaitoh 
   2898   1.6  msaitoh 	UNREFERENCED_1PARAMETER(autoneg_wait_to_complete);
   2899   1.6  msaitoh 
   2900   1.6  msaitoh 	/* Check if SFP module is supported and linear */
   2901   1.6  msaitoh 	ret_val = ixgbe_supported_sfp_modules_X550em(hw, &setup_linear);
   2902   1.6  msaitoh 
   2903   1.6  msaitoh 	/* If no SFP module present, then return success. Return success since
   2904   1.6  msaitoh 	 * SFP not present error is not excepted in the setup MAC link flow.
   2905   1.6  msaitoh 	 */
   2906   1.6  msaitoh 	if (ret_val == IXGBE_ERR_SFP_NOT_PRESENT)
   2907   1.6  msaitoh 		return IXGBE_SUCCESS;
   2908   1.6  msaitoh 
   2909   1.6  msaitoh 	if (ret_val != IXGBE_SUCCESS)
   2910   1.6  msaitoh 		return ret_val;
   2911   1.6  msaitoh 
   2912   1.6  msaitoh 	if (hw->device_id == IXGBE_DEV_ID_X550EM_A_SFP_N) {
   2913   1.6  msaitoh 		/* Configure internal PHY for native SFI based on module type */
   2914   1.6  msaitoh 		ret_val = hw->mac.ops.read_iosf_sb_reg(hw,
   2915   1.6  msaitoh 				   IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
   2916   1.6  msaitoh 				   IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_phy_int);
   2917   1.6  msaitoh 
   2918   1.6  msaitoh 		if (ret_val != IXGBE_SUCCESS)
   2919   1.6  msaitoh 			return ret_val;
   2920   1.6  msaitoh 
   2921   1.6  msaitoh 		reg_phy_int &= IXGBE_KRM_PMD_FLX_MASK_ST20_SFI_10G_DA;
   2922   1.6  msaitoh 		if (!setup_linear)
   2923   1.6  msaitoh 			reg_phy_int |= IXGBE_KRM_PMD_FLX_MASK_ST20_SFI_10G_SR;
   2924   1.6  msaitoh 
   2925   1.6  msaitoh 		ret_val = hw->mac.ops.write_iosf_sb_reg(hw,
   2926   1.6  msaitoh 				   IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
   2927   1.6  msaitoh 				   IXGBE_SB_IOSF_TARGET_KR_PHY, reg_phy_int);
   2928   1.6  msaitoh 
   2929   1.6  msaitoh 		if (ret_val != IXGBE_SUCCESS)
   2930   1.6  msaitoh 			return ret_val;
   2931   1.6  msaitoh 
   2932   1.6  msaitoh 		/* Setup SFI internal link. */
   2933   1.6  msaitoh 		ret_val = ixgbe_setup_sfi_x550a(hw, &speed);
   2934   1.6  msaitoh 	} else {
   2935   1.6  msaitoh 		/* Configure internal PHY for KR/KX. */
   2936   1.6  msaitoh 		ixgbe_setup_kr_speed_x550em(hw, speed);
   2937   1.6  msaitoh 
   2938   1.6  msaitoh 		if (hw->phy.addr == 0x0 || hw->phy.addr == 0xFFFF) {
   2939   1.6  msaitoh 			/* Find Address */
   2940   1.6  msaitoh 			DEBUGOUT("Invalid NW_MNG_IF_SEL.MDIO_PHY_ADD value\n");
   2941   1.6  msaitoh 			return IXGBE_ERR_PHY_ADDR_INVALID;
   2942   1.6  msaitoh 		}
   2943   1.6  msaitoh 
   2944   1.6  msaitoh 		/* Get external PHY SKU id */
   2945   1.6  msaitoh 		ret_val = hw->phy.ops.read_reg(hw, IXGBE_CS4227_EFUSE_PDF_SKU,
   2946   1.6  msaitoh 					IXGBE_MDIO_ZERO_DEV_TYPE, &reg_phy_ext);
   2947   1.6  msaitoh 
   2948   1.6  msaitoh 		if (ret_val != IXGBE_SUCCESS)
   2949   1.6  msaitoh 			return ret_val;
   2950   1.6  msaitoh 
   2951   1.6  msaitoh 		/* When configuring quad port CS4223, the MAC instance is part
   2952   1.6  msaitoh 		 * of the slice offset.
   2953   1.6  msaitoh 		 */
   2954   1.6  msaitoh 		if (reg_phy_ext == IXGBE_CS4223_SKU_ID)
   2955   1.6  msaitoh 			slice_offset = (hw->bus.lan_id +
   2956   1.6  msaitoh 					(hw->bus.instance_id << 1)) << 12;
   2957   1.6  msaitoh 		else
   2958   1.6  msaitoh 			slice_offset = hw->bus.lan_id << 12;
   2959   1.6  msaitoh 
   2960   1.6  msaitoh 		/* Configure CS4227/CS4223 LINE side to proper mode. */
   2961   1.6  msaitoh 		reg_slice = IXGBE_CS4227_LINE_SPARE24_LSB + slice_offset;
   2962   1.6  msaitoh 
   2963   1.6  msaitoh 		ret_val = hw->phy.ops.read_reg(hw, reg_slice,
   2964   1.6  msaitoh 					IXGBE_MDIO_ZERO_DEV_TYPE, &reg_phy_ext);
   2965   1.6  msaitoh 
   2966   1.6  msaitoh 		if (ret_val != IXGBE_SUCCESS)
   2967   1.6  msaitoh 			return ret_val;
   2968   1.6  msaitoh 
   2969   1.6  msaitoh 		reg_phy_ext &= ~((IXGBE_CS4227_EDC_MODE_CX1 << 1) |
   2970   1.6  msaitoh 				 (IXGBE_CS4227_EDC_MODE_SR << 1));
   2971   1.6  msaitoh 
   2972   1.6  msaitoh 		if (setup_linear)
   2973   1.9  msaitoh 			reg_phy_ext |= (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 0x1;
   2974   1.6  msaitoh 		else
   2975   1.9  msaitoh 			reg_phy_ext |= (IXGBE_CS4227_EDC_MODE_SR << 1) | 0x1;
   2976   1.6  msaitoh 		ret_val = hw->phy.ops.write_reg(hw, reg_slice,
   2977   1.6  msaitoh 					 IXGBE_MDIO_ZERO_DEV_TYPE, reg_phy_ext);
   2978   1.6  msaitoh 
   2979   1.6  msaitoh 		/* Flush previous write with a read */
   2980   1.6  msaitoh 		ret_val = hw->phy.ops.read_reg(hw, reg_slice,
   2981   1.6  msaitoh 					IXGBE_MDIO_ZERO_DEV_TYPE, &reg_phy_ext);
   2982   1.6  msaitoh 	}
   2983   1.6  msaitoh 	return ret_val;
   2984   1.6  msaitoh }
   2985   1.6  msaitoh 
   2986   1.6  msaitoh /**
   2987   1.6  msaitoh  *  ixgbe_setup_ixfi_x550em_x - MAC specific iXFI configuration
   2988   1.6  msaitoh  *  @hw: pointer to hardware structure
   2989   1.6  msaitoh  *
   2990   1.6  msaitoh  *  iXfI configuration needed for ixgbe_mac_X550EM_x devices.
   2991   1.6  msaitoh  **/
   2992   1.6  msaitoh static s32 ixgbe_setup_ixfi_x550em_x(struct ixgbe_hw *hw)
   2993   1.6  msaitoh {
   2994   1.6  msaitoh 	struct ixgbe_mac_info *mac = &hw->mac;
   2995   1.6  msaitoh 	s32 status;
   2996   1.6  msaitoh 	u32 reg_val;
   2997   1.1  msaitoh 
   2998   1.1  msaitoh 	/* Disable training protocol FSM. */
   2999   1.6  msaitoh 	status = mac->ops.read_iosf_sb_reg(hw,
   3000   1.1  msaitoh 				IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
   3001   1.1  msaitoh 				IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
   3002   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3003   1.1  msaitoh 		return status;
   3004   1.1  msaitoh 	reg_val |= IXGBE_KRM_RX_TRN_LINKUP_CTRL_CONV_WO_PROTOCOL;
   3005   1.6  msaitoh 	status = mac->ops.write_iosf_sb_reg(hw,
   3006   1.1  msaitoh 				IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
   3007   1.1  msaitoh 				IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
   3008   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3009   1.1  msaitoh 		return status;
   3010   1.1  msaitoh 
   3011   1.1  msaitoh 	/* Disable Flex from training TXFFE. */
   3012   1.6  msaitoh 	status = mac->ops.read_iosf_sb_reg(hw,
   3013   1.1  msaitoh 				IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
   3014   1.1  msaitoh 				IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
   3015   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3016   1.1  msaitoh 		return status;
   3017   1.1  msaitoh 	reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
   3018   1.1  msaitoh 	reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
   3019   1.1  msaitoh 	reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
   3020   1.6  msaitoh 	status = mac->ops.write_iosf_sb_reg(hw,
   3021   1.1  msaitoh 				IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
   3022   1.1  msaitoh 				IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
   3023   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3024   1.1  msaitoh 		return status;
   3025   1.6  msaitoh 	status = mac->ops.read_iosf_sb_reg(hw,
   3026   1.1  msaitoh 				IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
   3027   1.1  msaitoh 				IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
   3028   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3029   1.1  msaitoh 		return status;
   3030   1.1  msaitoh 	reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
   3031   1.1  msaitoh 	reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
   3032   1.1  msaitoh 	reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
   3033   1.6  msaitoh 	status = mac->ops.write_iosf_sb_reg(hw,
   3034   1.1  msaitoh 				IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
   3035   1.1  msaitoh 				IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
   3036   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3037   1.1  msaitoh 		return status;
   3038   1.1  msaitoh 
   3039   1.1  msaitoh 	/* Enable override for coefficients. */
   3040   1.6  msaitoh 	status = mac->ops.read_iosf_sb_reg(hw,
   3041   1.1  msaitoh 				IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
   3042   1.1  msaitoh 				IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
   3043   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3044   1.1  msaitoh 		return status;
   3045   1.1  msaitoh 	reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_OVRRD_EN;
   3046   1.1  msaitoh 	reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CZERO_EN;
   3047   1.1  msaitoh 	reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CPLUS1_OVRRD_EN;
   3048   1.1  msaitoh 	reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CMINUS1_OVRRD_EN;
   3049   1.6  msaitoh 	status = mac->ops.write_iosf_sb_reg(hw,
   3050   1.1  msaitoh 				IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
   3051   1.1  msaitoh 				IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
   3052   1.6  msaitoh 	return status;
   3053   1.6  msaitoh }
   3054   1.6  msaitoh 
   3055   1.6  msaitoh /**
   3056   1.6  msaitoh  *  ixgbe_setup_ixfi_x550em - Configure the KR PHY for iXFI mode.
   3057   1.6  msaitoh  *  @hw: pointer to hardware structure
   3058   1.6  msaitoh  *  @speed: the link speed to force
   3059   1.6  msaitoh  *
   3060   1.6  msaitoh  *  Configures the integrated KR PHY to use iXFI mode. Used to connect an
   3061   1.6  msaitoh  *  internal and external PHY at a specific speed, without autonegotiation.
   3062   1.6  msaitoh  **/
   3063   1.6  msaitoh static s32 ixgbe_setup_ixfi_x550em(struct ixgbe_hw *hw, ixgbe_link_speed *speed)
   3064   1.6  msaitoh {
   3065   1.6  msaitoh 	struct ixgbe_mac_info *mac = &hw->mac;
   3066   1.6  msaitoh 	s32 status;
   3067   1.6  msaitoh 	u32 reg_val;
   3068   1.6  msaitoh 
   3069   1.6  msaitoh 	/* iXFI is only supported with X552 */
   3070   1.6  msaitoh 	if (mac->type != ixgbe_mac_X550EM_x)
   3071   1.6  msaitoh 		return IXGBE_ERR_LINK_SETUP;
   3072   1.1  msaitoh 
   3073   1.6  msaitoh 	/* Disable AN and force speed to 10G Serial. */
   3074   1.6  msaitoh 	status = mac->ops.read_iosf_sb_reg(hw,
   3075   1.1  msaitoh 					IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
   3076   1.1  msaitoh 					IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
   3077   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3078   1.1  msaitoh 		return status;
   3079   1.6  msaitoh 
   3080   1.6  msaitoh 	reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
   3081   1.6  msaitoh 	reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
   3082   1.6  msaitoh 
   3083   1.6  msaitoh 	/* Select forced link speed for internal PHY. */
   3084   1.6  msaitoh 	switch (*speed) {
   3085   1.6  msaitoh 	case IXGBE_LINK_SPEED_10GB_FULL:
   3086   1.6  msaitoh 		reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_10G;
   3087   1.6  msaitoh 		break;
   3088   1.6  msaitoh 	case IXGBE_LINK_SPEED_1GB_FULL:
   3089   1.6  msaitoh 		reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
   3090   1.6  msaitoh 		break;
   3091   1.6  msaitoh 	default:
   3092   1.6  msaitoh 		/* Other link speeds are not supported by internal KR PHY. */
   3093   1.6  msaitoh 		return IXGBE_ERR_LINK_SETUP;
   3094   1.6  msaitoh 	}
   3095   1.6  msaitoh 
   3096   1.6  msaitoh 	status = mac->ops.write_iosf_sb_reg(hw,
   3097   1.1  msaitoh 					IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
   3098   1.1  msaitoh 					IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
   3099   1.6  msaitoh 	if (status != IXGBE_SUCCESS)
   3100   1.6  msaitoh 		return status;
   3101   1.6  msaitoh 
   3102   1.6  msaitoh 	/* Additional configuration needed for x550em_x */
   3103   1.6  msaitoh 	if (hw->mac.type == ixgbe_mac_X550EM_x) {
   3104   1.6  msaitoh 		status = ixgbe_setup_ixfi_x550em_x(hw);
   3105   1.6  msaitoh 		if (status != IXGBE_SUCCESS)
   3106   1.6  msaitoh 			return status;
   3107   1.6  msaitoh 	}
   3108   1.6  msaitoh 
   3109   1.6  msaitoh 	/* Toggle port SW reset by AN reset. */
   3110   1.6  msaitoh 	status = ixgbe_restart_an_internal_phy_x550em(hw);
   3111   1.1  msaitoh 
   3112   1.1  msaitoh 	return status;
   3113   1.1  msaitoh }
   3114   1.1  msaitoh 
   3115   1.1  msaitoh /**
   3116   1.1  msaitoh  * ixgbe_ext_phy_t_x550em_get_link - Get ext phy link status
   3117   1.1  msaitoh  * @hw: address of hardware structure
   3118   1.1  msaitoh  * @link_up: address of boolean to indicate link status
   3119   1.1  msaitoh  *
   3120   1.1  msaitoh  * Returns error code if unable to get link status.
   3121   1.1  msaitoh  */
   3122   1.1  msaitoh static s32 ixgbe_ext_phy_t_x550em_get_link(struct ixgbe_hw *hw, bool *link_up)
   3123   1.1  msaitoh {
   3124   1.1  msaitoh 	u32 ret;
   3125   1.1  msaitoh 	u16 autoneg_status;
   3126   1.1  msaitoh 
   3127   1.1  msaitoh 	*link_up = FALSE;
   3128   1.1  msaitoh 
   3129   1.1  msaitoh 	/* read this twice back to back to indicate current status */
   3130   1.1  msaitoh 	ret = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
   3131   1.1  msaitoh 				   IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
   3132   1.1  msaitoh 				   &autoneg_status);
   3133   1.1  msaitoh 	if (ret != IXGBE_SUCCESS)
   3134   1.1  msaitoh 		return ret;
   3135   1.1  msaitoh 
   3136   1.1  msaitoh 	ret = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
   3137   1.1  msaitoh 				   IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
   3138   1.1  msaitoh 				   &autoneg_status);
   3139   1.1  msaitoh 	if (ret != IXGBE_SUCCESS)
   3140   1.1  msaitoh 		return ret;
   3141   1.1  msaitoh 
   3142   1.1  msaitoh 	*link_up = !!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS);
   3143   1.1  msaitoh 
   3144   1.1  msaitoh 	return IXGBE_SUCCESS;
   3145   1.1  msaitoh }
   3146   1.1  msaitoh 
   3147   1.1  msaitoh /**
   3148   1.1  msaitoh  * ixgbe_setup_internal_phy_t_x550em - Configure KR PHY to X557 link
   3149   1.1  msaitoh  * @hw: point to hardware structure
   3150   1.1  msaitoh  *
   3151   1.1  msaitoh  * Configures the link between the integrated KR PHY and the external X557 PHY
   3152   1.1  msaitoh  * The driver will call this function when it gets a link status change
   3153   1.1  msaitoh  * interrupt from the X557 PHY. This function configures the link speed
   3154   1.1  msaitoh  * between the PHYs to match the link speed of the BASE-T link.
   3155   1.1  msaitoh  *
   3156   1.1  msaitoh  * A return of a non-zero value indicates an error, and the base driver should
   3157   1.1  msaitoh  * not report link up.
   3158   1.1  msaitoh  */
   3159   1.1  msaitoh s32 ixgbe_setup_internal_phy_t_x550em(struct ixgbe_hw *hw)
   3160   1.1  msaitoh {
   3161   1.1  msaitoh 	ixgbe_link_speed force_speed;
   3162   1.1  msaitoh 	bool link_up;
   3163   1.1  msaitoh 	u32 status;
   3164   1.1  msaitoh 	u16 speed;
   3165   1.1  msaitoh 
   3166   1.1  msaitoh 	if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
   3167   1.1  msaitoh 		return IXGBE_ERR_CONFIG;
   3168   1.1  msaitoh 
   3169   1.6  msaitoh 	if (hw->mac.type == ixgbe_mac_X550EM_x &&
   3170   1.6  msaitoh 	    !(hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE)) {
   3171   1.6  msaitoh 		/* If link is down, there is no setup necessary so return  */
   3172   1.6  msaitoh 		status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
   3173   1.6  msaitoh 		if (status != IXGBE_SUCCESS)
   3174   1.6  msaitoh 			return status;
   3175   1.1  msaitoh 
   3176   1.6  msaitoh 		if (!link_up)
   3177   1.6  msaitoh 			return IXGBE_SUCCESS;
   3178   1.1  msaitoh 
   3179   1.6  msaitoh 		status = hw->phy.ops.read_reg(hw,
   3180   1.6  msaitoh 					      IXGBE_MDIO_AUTO_NEG_VENDOR_STAT,
   3181   1.1  msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
   3182   1.1  msaitoh 				      &speed);
   3183   1.6  msaitoh 		if (status != IXGBE_SUCCESS)
   3184   1.6  msaitoh 			return status;
   3185   1.6  msaitoh 
   3186   1.6  msaitoh 		/* If link is still down - no setup is required so return */
   3187   1.6  msaitoh 		status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
   3188   1.6  msaitoh 		if (status != IXGBE_SUCCESS)
   3189   1.6  msaitoh 			return status;
   3190   1.6  msaitoh 		if (!link_up)
   3191   1.6  msaitoh 			return IXGBE_SUCCESS;
   3192   1.1  msaitoh 
   3193   1.6  msaitoh 		/* clear everything but the speed and duplex bits */
   3194   1.6  msaitoh 		speed &= IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_MASK;
   3195   1.1  msaitoh 
   3196   1.6  msaitoh 		switch (speed) {
   3197   1.6  msaitoh 		case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB_FULL:
   3198   1.6  msaitoh 			force_speed = IXGBE_LINK_SPEED_10GB_FULL;
   3199   1.6  msaitoh 			break;
   3200   1.6  msaitoh 		case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB_FULL:
   3201   1.6  msaitoh 			force_speed = IXGBE_LINK_SPEED_1GB_FULL;
   3202   1.6  msaitoh 			break;
   3203   1.6  msaitoh 		default:
   3204   1.6  msaitoh 			/* Internal PHY does not support anything else */
   3205   1.6  msaitoh 			return IXGBE_ERR_INVALID_LINK_SETTINGS;
   3206   1.6  msaitoh 		}
   3207   1.1  msaitoh 
   3208   1.6  msaitoh 		return ixgbe_setup_ixfi_x550em(hw, &force_speed);
   3209   1.6  msaitoh 	} else {
   3210   1.6  msaitoh 		speed = IXGBE_LINK_SPEED_10GB_FULL |
   3211   1.6  msaitoh 		    IXGBE_LINK_SPEED_1GB_FULL;
   3212   1.6  msaitoh 		return ixgbe_setup_kr_speed_x550em(hw, speed);
   3213   1.1  msaitoh 	}
   3214   1.1  msaitoh }
   3215   1.1  msaitoh 
   3216   1.1  msaitoh /**
   3217   1.1  msaitoh  *  ixgbe_setup_phy_loopback_x550em - Configure the KR PHY for loopback.
   3218   1.1  msaitoh  *  @hw: pointer to hardware structure
   3219   1.1  msaitoh  *
   3220   1.1  msaitoh  *  Configures the integrated KR PHY to use internal loopback mode.
   3221   1.1  msaitoh  **/
   3222   1.1  msaitoh s32 ixgbe_setup_phy_loopback_x550em(struct ixgbe_hw *hw)
   3223   1.1  msaitoh {
   3224   1.1  msaitoh 	s32 status;
   3225   1.1  msaitoh 	u32 reg_val;
   3226   1.1  msaitoh 
   3227   1.1  msaitoh 	/* Disable AN and force speed to 10G Serial. */
   3228   1.6  msaitoh 	status = hw->mac.ops.read_iosf_sb_reg(hw,
   3229   1.1  msaitoh 		IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
   3230   1.1  msaitoh 		IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
   3231   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3232   1.1  msaitoh 		return status;
   3233   1.1  msaitoh 	reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
   3234   1.1  msaitoh 	reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
   3235   1.1  msaitoh 	reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_10G;
   3236   1.6  msaitoh 	status = hw->mac.ops.write_iosf_sb_reg(hw,
   3237   1.1  msaitoh 		IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
   3238   1.1  msaitoh 		IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
   3239   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3240   1.1  msaitoh 		return status;
   3241   1.1  msaitoh 
   3242   1.1  msaitoh 	/* Set near-end loopback clocks. */
   3243   1.6  msaitoh 	status = hw->mac.ops.read_iosf_sb_reg(hw,
   3244   1.1  msaitoh 		IXGBE_KRM_PORT_CAR_GEN_CTRL(hw->bus.lan_id),
   3245   1.1  msaitoh 		IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
   3246   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3247   1.1  msaitoh 		return status;
   3248   1.1  msaitoh 	reg_val |= IXGBE_KRM_PORT_CAR_GEN_CTRL_NELB_32B;
   3249   1.1  msaitoh 	reg_val |= IXGBE_KRM_PORT_CAR_GEN_CTRL_NELB_KRPCS;
   3250   1.6  msaitoh 	status = hw->mac.ops.write_iosf_sb_reg(hw,
   3251   1.1  msaitoh 		IXGBE_KRM_PORT_CAR_GEN_CTRL(hw->bus.lan_id),
   3252   1.1  msaitoh 		IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
   3253   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3254   1.1  msaitoh 		return status;
   3255   1.1  msaitoh 
   3256   1.1  msaitoh 	/* Set loopback enable. */
   3257   1.6  msaitoh 	status = hw->mac.ops.read_iosf_sb_reg(hw,
   3258   1.1  msaitoh 		IXGBE_KRM_PMD_DFX_BURNIN(hw->bus.lan_id),
   3259   1.1  msaitoh 		IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
   3260   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3261   1.1  msaitoh 		return status;
   3262   1.1  msaitoh 	reg_val |= IXGBE_KRM_PMD_DFX_BURNIN_TX_RX_KR_LB_MASK;
   3263   1.6  msaitoh 	status = hw->mac.ops.write_iosf_sb_reg(hw,
   3264   1.1  msaitoh 		IXGBE_KRM_PMD_DFX_BURNIN(hw->bus.lan_id),
   3265   1.1  msaitoh 		IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
   3266   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3267   1.1  msaitoh 		return status;
   3268   1.1  msaitoh 
   3269   1.1  msaitoh 	/* Training bypass. */
   3270   1.6  msaitoh 	status = hw->mac.ops.read_iosf_sb_reg(hw,
   3271   1.1  msaitoh 		IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
   3272   1.1  msaitoh 		IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
   3273   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3274   1.1  msaitoh 		return status;
   3275   1.1  msaitoh 	reg_val |= IXGBE_KRM_RX_TRN_LINKUP_CTRL_PROTOCOL_BYPASS;
   3276   1.6  msaitoh 	status = hw->mac.ops.write_iosf_sb_reg(hw,
   3277   1.1  msaitoh 		IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
   3278   1.1  msaitoh 		IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
   3279   1.1  msaitoh 
   3280   1.1  msaitoh 	return status;
   3281   1.1  msaitoh }
   3282   1.1  msaitoh 
   3283   1.1  msaitoh /**
   3284   1.1  msaitoh  *  ixgbe_read_ee_hostif_X550 - Read EEPROM word using a host interface command
   3285   1.1  msaitoh  *  assuming that the semaphore is already obtained.
   3286   1.1  msaitoh  *  @hw: pointer to hardware structure
   3287   1.1  msaitoh  *  @offset: offset of  word in the EEPROM to read
   3288   1.1  msaitoh  *  @data: word read from the EEPROM
   3289   1.1  msaitoh  *
   3290   1.1  msaitoh  *  Reads a 16 bit word from the EEPROM using the hostif.
   3291   1.1  msaitoh  **/
   3292   1.6  msaitoh s32 ixgbe_read_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset, u16 *data)
   3293   1.1  msaitoh {
   3294   1.6  msaitoh 	const u32 mask = IXGBE_GSSR_SW_MNG_SM | IXGBE_GSSR_EEP_SM;
   3295   1.6  msaitoh 	struct ixgbe_hic_read_shadow_ram buffer;
   3296   1.1  msaitoh 	s32 status;
   3297   1.1  msaitoh 
   3298   1.1  msaitoh 	DEBUGFUNC("ixgbe_read_ee_hostif_X550");
   3299   1.6  msaitoh 	buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
   3300   1.6  msaitoh 	buffer.hdr.req.buf_lenh = 0;
   3301   1.6  msaitoh 	buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
   3302   1.6  msaitoh 	buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
   3303   1.6  msaitoh 
   3304   1.6  msaitoh 	/* convert offset from words to bytes */
   3305   1.6  msaitoh 	buffer.address = IXGBE_CPU_TO_BE32(offset * 2);
   3306   1.6  msaitoh 	/* one word */
   3307   1.6  msaitoh 	buffer.length = IXGBE_CPU_TO_BE16(sizeof(u16));
   3308   1.8  msaitoh 	buffer.pad2 = 0;
   3309   1.8  msaitoh 	buffer.pad3 = 0;
   3310   1.6  msaitoh 
   3311   1.6  msaitoh 	status = hw->mac.ops.acquire_swfw_sync(hw, mask);
   3312   1.6  msaitoh 	if (status)
   3313   1.6  msaitoh 		return status;
   3314   1.1  msaitoh 
   3315   1.6  msaitoh 	status = ixgbe_hic_unlocked(hw, (u32 *)&buffer, sizeof(buffer),
   3316   1.6  msaitoh 				    IXGBE_HI_COMMAND_TIMEOUT);
   3317   1.6  msaitoh 	if (!status) {
   3318   1.6  msaitoh 		*data = (u16)IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG,
   3319   1.6  msaitoh 						  FW_NVM_DATA_OFFSET);
   3320   1.1  msaitoh 	}
   3321   1.1  msaitoh 
   3322   1.6  msaitoh 	hw->mac.ops.release_swfw_sync(hw, mask);
   3323   1.1  msaitoh 	return status;
   3324   1.1  msaitoh }
   3325   1.1  msaitoh 
   3326   1.1  msaitoh /**
   3327   1.1  msaitoh  *  ixgbe_read_ee_hostif_buffer_X550- Read EEPROM word(s) using hostif
   3328   1.1  msaitoh  *  @hw: pointer to hardware structure
   3329   1.1  msaitoh  *  @offset: offset of  word in the EEPROM to read
   3330   1.1  msaitoh  *  @words: number of words
   3331   1.1  msaitoh  *  @data: word(s) read from the EEPROM
   3332   1.1  msaitoh  *
   3333   1.1  msaitoh  *  Reads a 16 bit word(s) from the EEPROM using the hostif.
   3334   1.1  msaitoh  **/
   3335   1.1  msaitoh s32 ixgbe_read_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
   3336   1.1  msaitoh 				     u16 offset, u16 words, u16 *data)
   3337   1.1  msaitoh {
   3338   1.6  msaitoh 	const u32 mask = IXGBE_GSSR_SW_MNG_SM | IXGBE_GSSR_EEP_SM;
   3339   1.1  msaitoh 	struct ixgbe_hic_read_shadow_ram buffer;
   3340   1.1  msaitoh 	u32 current_word = 0;
   3341   1.1  msaitoh 	u16 words_to_read;
   3342   1.1  msaitoh 	s32 status;
   3343   1.1  msaitoh 	u32 i;
   3344   1.1  msaitoh 
   3345   1.1  msaitoh 	DEBUGFUNC("ixgbe_read_ee_hostif_buffer_X550");
   3346   1.1  msaitoh 
   3347   1.1  msaitoh 	/* Take semaphore for the entire operation. */
   3348   1.6  msaitoh 	status = hw->mac.ops.acquire_swfw_sync(hw, mask);
   3349   1.1  msaitoh 	if (status) {
   3350   1.1  msaitoh 		DEBUGOUT("EEPROM read buffer - semaphore failed\n");
   3351   1.1  msaitoh 		return status;
   3352   1.1  msaitoh 	}
   3353   1.6  msaitoh 
   3354   1.1  msaitoh 	while (words) {
   3355   1.1  msaitoh 		if (words > FW_MAX_READ_BUFFER_SIZE / 2)
   3356   1.1  msaitoh 			words_to_read = FW_MAX_READ_BUFFER_SIZE / 2;
   3357   1.1  msaitoh 		else
   3358   1.1  msaitoh 			words_to_read = words;
   3359   1.1  msaitoh 
   3360   1.1  msaitoh 		buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
   3361   1.1  msaitoh 		buffer.hdr.req.buf_lenh = 0;
   3362   1.1  msaitoh 		buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
   3363   1.1  msaitoh 		buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
   3364   1.1  msaitoh 
   3365   1.1  msaitoh 		/* convert offset from words to bytes */
   3366   1.1  msaitoh 		buffer.address = IXGBE_CPU_TO_BE32((offset + current_word) * 2);
   3367   1.1  msaitoh 		buffer.length = IXGBE_CPU_TO_BE16(words_to_read * 2);
   3368   1.8  msaitoh 		buffer.pad2 = 0;
   3369   1.8  msaitoh 		buffer.pad3 = 0;
   3370   1.1  msaitoh 
   3371   1.6  msaitoh 		status = ixgbe_hic_unlocked(hw, (u32 *)&buffer, sizeof(buffer),
   3372   1.6  msaitoh 					    IXGBE_HI_COMMAND_TIMEOUT);
   3373   1.1  msaitoh 
   3374   1.1  msaitoh 		if (status) {
   3375   1.1  msaitoh 			DEBUGOUT("Host interface command failed\n");
   3376   1.1  msaitoh 			goto out;
   3377   1.1  msaitoh 		}
   3378   1.1  msaitoh 
   3379   1.1  msaitoh 		for (i = 0; i < words_to_read; i++) {
   3380   1.1  msaitoh 			u32 reg = IXGBE_FLEX_MNG + (FW_NVM_DATA_OFFSET << 2) +
   3381   1.1  msaitoh 				  2 * i;
   3382   1.1  msaitoh 			u32 value = IXGBE_READ_REG(hw, reg);
   3383   1.1  msaitoh 
   3384   1.1  msaitoh 			data[current_word] = (u16)(value & 0xffff);
   3385   1.1  msaitoh 			current_word++;
   3386   1.1  msaitoh 			i++;
   3387   1.1  msaitoh 			if (i < words_to_read) {
   3388   1.1  msaitoh 				value >>= 16;
   3389   1.1  msaitoh 				data[current_word] = (u16)(value & 0xffff);
   3390   1.1  msaitoh 				current_word++;
   3391   1.1  msaitoh 			}
   3392   1.1  msaitoh 		}
   3393   1.1  msaitoh 		words -= words_to_read;
   3394   1.1  msaitoh 	}
   3395   1.1  msaitoh 
   3396   1.1  msaitoh out:
   3397   1.6  msaitoh 	hw->mac.ops.release_swfw_sync(hw, mask);
   3398   1.1  msaitoh 	return status;
   3399   1.1  msaitoh }
   3400   1.1  msaitoh 
   3401   1.1  msaitoh /**
   3402   1.1  msaitoh  *  ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif
   3403   1.1  msaitoh  *  @hw: pointer to hardware structure
   3404   1.1  msaitoh  *  @offset: offset of  word in the EEPROM to write
   3405   1.1  msaitoh  *  @data: word write to the EEPROM
   3406   1.1  msaitoh  *
   3407   1.1  msaitoh  *  Write a 16 bit word to the EEPROM using the hostif.
   3408   1.1  msaitoh  **/
   3409   1.1  msaitoh s32 ixgbe_write_ee_hostif_data_X550(struct ixgbe_hw *hw, u16 offset,
   3410   1.1  msaitoh 				    u16 data)
   3411   1.1  msaitoh {
   3412   1.1  msaitoh 	s32 status;
   3413   1.1  msaitoh 	struct ixgbe_hic_write_shadow_ram buffer;
   3414   1.1  msaitoh 
   3415   1.1  msaitoh 	DEBUGFUNC("ixgbe_write_ee_hostif_data_X550");
   3416   1.1  msaitoh 
   3417   1.1  msaitoh 	buffer.hdr.req.cmd = FW_WRITE_SHADOW_RAM_CMD;
   3418   1.1  msaitoh 	buffer.hdr.req.buf_lenh = 0;
   3419   1.1  msaitoh 	buffer.hdr.req.buf_lenl = FW_WRITE_SHADOW_RAM_LEN;
   3420   1.1  msaitoh 	buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
   3421   1.1  msaitoh 
   3422   1.1  msaitoh 	 /* one word */
   3423   1.1  msaitoh 	buffer.length = IXGBE_CPU_TO_BE16(sizeof(u16));
   3424   1.1  msaitoh 	buffer.data = data;
   3425   1.1  msaitoh 	buffer.address = IXGBE_CPU_TO_BE32(offset * 2);
   3426   1.1  msaitoh 
   3427   1.1  msaitoh 	status = ixgbe_host_interface_command(hw, (u32 *)&buffer,
   3428   1.1  msaitoh 					      sizeof(buffer),
   3429   1.1  msaitoh 					      IXGBE_HI_COMMAND_TIMEOUT, FALSE);
   3430   1.1  msaitoh 
   3431   1.1  msaitoh 	return status;
   3432   1.1  msaitoh }
   3433   1.1  msaitoh 
   3434   1.1  msaitoh /**
   3435   1.1  msaitoh  *  ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif
   3436   1.1  msaitoh  *  @hw: pointer to hardware structure
   3437   1.1  msaitoh  *  @offset: offset of  word in the EEPROM to write
   3438   1.1  msaitoh  *  @data: word write to the EEPROM
   3439   1.1  msaitoh  *
   3440   1.1  msaitoh  *  Write a 16 bit word to the EEPROM using the hostif.
   3441   1.1  msaitoh  **/
   3442   1.1  msaitoh s32 ixgbe_write_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset,
   3443   1.1  msaitoh 			       u16 data)
   3444   1.1  msaitoh {
   3445   1.1  msaitoh 	s32 status = IXGBE_SUCCESS;
   3446   1.1  msaitoh 
   3447   1.1  msaitoh 	DEBUGFUNC("ixgbe_write_ee_hostif_X550");
   3448   1.1  msaitoh 
   3449   1.1  msaitoh 	if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
   3450   1.1  msaitoh 	    IXGBE_SUCCESS) {
   3451   1.1  msaitoh 		status = ixgbe_write_ee_hostif_data_X550(hw, offset, data);
   3452   1.1  msaitoh 		hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
   3453   1.1  msaitoh 	} else {
   3454   1.1  msaitoh 		DEBUGOUT("write ee hostif failed to get semaphore");
   3455   1.1  msaitoh 		status = IXGBE_ERR_SWFW_SYNC;
   3456   1.1  msaitoh 	}
   3457   1.1  msaitoh 
   3458   1.1  msaitoh 	return status;
   3459   1.1  msaitoh }
   3460   1.1  msaitoh 
   3461   1.1  msaitoh /**
   3462   1.1  msaitoh  *  ixgbe_write_ee_hostif_buffer_X550 - Write EEPROM word(s) using hostif
   3463   1.1  msaitoh  *  @hw: pointer to hardware structure
   3464   1.1  msaitoh  *  @offset: offset of  word in the EEPROM to write
   3465   1.1  msaitoh  *  @words: number of words
   3466   1.1  msaitoh  *  @data: word(s) write to the EEPROM
   3467   1.1  msaitoh  *
   3468   1.1  msaitoh  *  Write a 16 bit word(s) to the EEPROM using the hostif.
   3469   1.1  msaitoh  **/
   3470   1.1  msaitoh s32 ixgbe_write_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
   3471   1.1  msaitoh 				      u16 offset, u16 words, u16 *data)
   3472   1.1  msaitoh {
   3473   1.1  msaitoh 	s32 status = IXGBE_SUCCESS;
   3474   1.1  msaitoh 	u32 i = 0;
   3475   1.1  msaitoh 
   3476   1.1  msaitoh 	DEBUGFUNC("ixgbe_write_ee_hostif_buffer_X550");
   3477   1.1  msaitoh 
   3478   1.1  msaitoh 	/* Take semaphore for the entire operation. */
   3479   1.1  msaitoh 	status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
   3480   1.1  msaitoh 	if (status != IXGBE_SUCCESS) {
   3481   1.1  msaitoh 		DEBUGOUT("EEPROM write buffer - semaphore failed\n");
   3482   1.1  msaitoh 		goto out;
   3483   1.1  msaitoh 	}
   3484   1.1  msaitoh 
   3485   1.1  msaitoh 	for (i = 0; i < words; i++) {
   3486   1.1  msaitoh 		status = ixgbe_write_ee_hostif_data_X550(hw, offset + i,
   3487   1.1  msaitoh 							 data[i]);
   3488   1.1  msaitoh 
   3489   1.1  msaitoh 		if (status != IXGBE_SUCCESS) {
   3490   1.1  msaitoh 			DEBUGOUT("Eeprom buffered write failed\n");
   3491   1.1  msaitoh 			break;
   3492   1.1  msaitoh 		}
   3493   1.1  msaitoh 	}
   3494   1.1  msaitoh 
   3495   1.1  msaitoh 	hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
   3496   1.1  msaitoh out:
   3497   1.1  msaitoh 
   3498   1.1  msaitoh 	return status;
   3499   1.1  msaitoh }
   3500   1.1  msaitoh 
   3501   1.1  msaitoh /**
   3502   1.1  msaitoh  * ixgbe_checksum_ptr_x550 - Checksum one pointer region
   3503   1.1  msaitoh  * @hw: pointer to hardware structure
   3504   1.1  msaitoh  * @ptr: pointer offset in eeprom
   3505   1.1  msaitoh  * @size: size of section pointed by ptr, if 0 first word will be used as size
   3506   1.1  msaitoh  * @csum: address of checksum to update
   3507  1.12  msaitoh  * @buffer: pointer to buffer containing calculated checksum
   3508  1.12  msaitoh  * @buffer_size: size of buffer
   3509   1.1  msaitoh  *
   3510   1.1  msaitoh  * Returns error status for any failure
   3511   1.1  msaitoh  */
   3512   1.1  msaitoh static s32 ixgbe_checksum_ptr_x550(struct ixgbe_hw *hw, u16 ptr,
   3513   1.1  msaitoh 				   u16 size, u16 *csum, u16 *buffer,
   3514   1.1  msaitoh 				   u32 buffer_size)
   3515   1.1  msaitoh {
   3516   1.1  msaitoh 	u16 buf[256];
   3517   1.1  msaitoh 	s32 status;
   3518   1.1  msaitoh 	u16 length, bufsz, i, start;
   3519   1.1  msaitoh 	u16 *local_buffer;
   3520   1.1  msaitoh 
   3521   1.1  msaitoh 	bufsz = sizeof(buf) / sizeof(buf[0]);
   3522   1.1  msaitoh 
   3523   1.1  msaitoh 	/* Read a chunk at the pointer location */
   3524   1.1  msaitoh 	if (!buffer) {
   3525   1.1  msaitoh 		status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr, bufsz, buf);
   3526   1.1  msaitoh 		if (status) {
   3527   1.1  msaitoh 			DEBUGOUT("Failed to read EEPROM image\n");
   3528   1.1  msaitoh 			return status;
   3529   1.1  msaitoh 		}
   3530   1.1  msaitoh 		local_buffer = buf;
   3531   1.1  msaitoh 	} else {
   3532   1.1  msaitoh 		if (buffer_size < ptr)
   3533   1.1  msaitoh 			return  IXGBE_ERR_PARAM;
   3534   1.1  msaitoh 		local_buffer = &buffer[ptr];
   3535   1.1  msaitoh 	}
   3536   1.1  msaitoh 
   3537   1.1  msaitoh 	if (size) {
   3538   1.1  msaitoh 		start = 0;
   3539   1.1  msaitoh 		length = size;
   3540   1.1  msaitoh 	} else {
   3541   1.1  msaitoh 		start = 1;
   3542   1.1  msaitoh 		length = local_buffer[0];
   3543   1.1  msaitoh 
   3544   1.1  msaitoh 		/* Skip pointer section if length is invalid. */
   3545   1.1  msaitoh 		if (length == 0xFFFF || length == 0 ||
   3546   1.1  msaitoh 		    (ptr + length) >= hw->eeprom.word_size)
   3547   1.1  msaitoh 			return IXGBE_SUCCESS;
   3548   1.1  msaitoh 	}
   3549   1.1  msaitoh 
   3550   1.1  msaitoh 	if (buffer && ((u32)start + (u32)length > buffer_size))
   3551   1.1  msaitoh 		return IXGBE_ERR_PARAM;
   3552   1.1  msaitoh 
   3553   1.1  msaitoh 	for (i = start; length; i++, length--) {
   3554   1.1  msaitoh 		if (i == bufsz && !buffer) {
   3555   1.1  msaitoh 			ptr += bufsz;
   3556   1.1  msaitoh 			i = 0;
   3557   1.1  msaitoh 			if (length < bufsz)
   3558   1.1  msaitoh 				bufsz = length;
   3559   1.1  msaitoh 
   3560   1.1  msaitoh 			/* Read a chunk at the pointer location */
   3561   1.1  msaitoh 			status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr,
   3562   1.1  msaitoh 								  bufsz, buf);
   3563   1.1  msaitoh 			if (status) {
   3564   1.1  msaitoh 				DEBUGOUT("Failed to read EEPROM image\n");
   3565   1.1  msaitoh 				return status;
   3566   1.1  msaitoh 			}
   3567   1.1  msaitoh 		}
   3568   1.1  msaitoh 		*csum += local_buffer[i];
   3569   1.1  msaitoh 	}
   3570   1.1  msaitoh 	return IXGBE_SUCCESS;
   3571   1.1  msaitoh }
   3572   1.1  msaitoh 
   3573   1.1  msaitoh /**
   3574   1.1  msaitoh  *  ixgbe_calc_checksum_X550 - Calculates and returns the checksum
   3575   1.1  msaitoh  *  @hw: pointer to hardware structure
   3576   1.1  msaitoh  *  @buffer: pointer to buffer containing calculated checksum
   3577   1.1  msaitoh  *  @buffer_size: size of buffer
   3578   1.1  msaitoh  *
   3579   1.1  msaitoh  *  Returns a negative error code on error, or the 16-bit checksum
   3580   1.1  msaitoh  **/
   3581   1.1  msaitoh s32 ixgbe_calc_checksum_X550(struct ixgbe_hw *hw, u16 *buffer, u32 buffer_size)
   3582   1.1  msaitoh {
   3583   1.1  msaitoh 	u16 eeprom_ptrs[IXGBE_EEPROM_LAST_WORD + 1];
   3584   1.1  msaitoh 	u16 *local_buffer;
   3585   1.1  msaitoh 	s32 status;
   3586   1.1  msaitoh 	u16 checksum = 0;
   3587   1.1  msaitoh 	u16 pointer, i, size;
   3588   1.1  msaitoh 
   3589   1.1  msaitoh 	DEBUGFUNC("ixgbe_calc_eeprom_checksum_X550");
   3590   1.1  msaitoh 
   3591   1.1  msaitoh 	hw->eeprom.ops.init_params(hw);
   3592   1.1  msaitoh 
   3593   1.1  msaitoh 	if (!buffer) {
   3594   1.1  msaitoh 		/* Read pointer area */
   3595   1.1  msaitoh 		status = ixgbe_read_ee_hostif_buffer_X550(hw, 0,
   3596   1.1  msaitoh 						     IXGBE_EEPROM_LAST_WORD + 1,
   3597   1.1  msaitoh 						     eeprom_ptrs);
   3598   1.1  msaitoh 		if (status) {
   3599   1.1  msaitoh 			DEBUGOUT("Failed to read EEPROM image\n");
   3600   1.1  msaitoh 			return status;
   3601   1.1  msaitoh 		}
   3602   1.1  msaitoh 		local_buffer = eeprom_ptrs;
   3603   1.1  msaitoh 	} else {
   3604   1.1  msaitoh 		if (buffer_size < IXGBE_EEPROM_LAST_WORD)
   3605   1.1  msaitoh 			return IXGBE_ERR_PARAM;
   3606   1.1  msaitoh 		local_buffer = buffer;
   3607   1.1  msaitoh 	}
   3608   1.1  msaitoh 
   3609   1.1  msaitoh 	/*
   3610   1.1  msaitoh 	 * For X550 hardware include 0x0-0x41 in the checksum, skip the
   3611   1.1  msaitoh 	 * checksum word itself
   3612   1.1  msaitoh 	 */
   3613   1.1  msaitoh 	for (i = 0; i <= IXGBE_EEPROM_LAST_WORD; i++)
   3614   1.1  msaitoh 		if (i != IXGBE_EEPROM_CHECKSUM)
   3615   1.1  msaitoh 			checksum += local_buffer[i];
   3616   1.1  msaitoh 
   3617   1.1  msaitoh 	/*
   3618   1.1  msaitoh 	 * Include all data from pointers 0x3, 0x6-0xE.  This excludes the
   3619   1.1  msaitoh 	 * FW, PHY module, and PCIe Expansion/Option ROM pointers.
   3620   1.1  msaitoh 	 */
   3621   1.1  msaitoh 	for (i = IXGBE_PCIE_ANALOG_PTR_X550; i < IXGBE_FW_PTR; i++) {
   3622   1.1  msaitoh 		if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
   3623   1.1  msaitoh 			continue;
   3624   1.1  msaitoh 
   3625   1.1  msaitoh 		pointer = local_buffer[i];
   3626   1.1  msaitoh 
   3627   1.1  msaitoh 		/* Skip pointer section if the pointer is invalid. */
   3628   1.1  msaitoh 		if (pointer == 0xFFFF || pointer == 0 ||
   3629   1.1  msaitoh 		    pointer >= hw->eeprom.word_size)
   3630   1.1  msaitoh 			continue;
   3631   1.1  msaitoh 
   3632   1.1  msaitoh 		switch (i) {
   3633   1.1  msaitoh 		case IXGBE_PCIE_GENERAL_PTR:
   3634   1.1  msaitoh 			size = IXGBE_IXGBE_PCIE_GENERAL_SIZE;
   3635   1.1  msaitoh 			break;
   3636   1.1  msaitoh 		case IXGBE_PCIE_CONFIG0_PTR:
   3637   1.1  msaitoh 		case IXGBE_PCIE_CONFIG1_PTR:
   3638   1.1  msaitoh 			size = IXGBE_PCIE_CONFIG_SIZE;
   3639   1.1  msaitoh 			break;
   3640   1.1  msaitoh 		default:
   3641   1.1  msaitoh 			size = 0;
   3642   1.1  msaitoh 			break;
   3643   1.1  msaitoh 		}
   3644   1.1  msaitoh 
   3645   1.1  msaitoh 		status = ixgbe_checksum_ptr_x550(hw, pointer, size, &checksum,
   3646   1.1  msaitoh 						buffer, buffer_size);
   3647   1.1  msaitoh 		if (status)
   3648   1.1  msaitoh 			return status;
   3649   1.1  msaitoh 	}
   3650   1.1  msaitoh 
   3651   1.1  msaitoh 	checksum = (u16)IXGBE_EEPROM_SUM - checksum;
   3652   1.1  msaitoh 
   3653   1.1  msaitoh 	return (s32)checksum;
   3654   1.1  msaitoh }
   3655   1.1  msaitoh 
   3656   1.1  msaitoh /**
   3657   1.1  msaitoh  *  ixgbe_calc_eeprom_checksum_X550 - Calculates and returns the checksum
   3658   1.1  msaitoh  *  @hw: pointer to hardware structure
   3659   1.1  msaitoh  *
   3660   1.1  msaitoh  *  Returns a negative error code on error, or the 16-bit checksum
   3661   1.1  msaitoh  **/
   3662   1.1  msaitoh s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw)
   3663   1.1  msaitoh {
   3664   1.1  msaitoh 	return ixgbe_calc_checksum_X550(hw, NULL, 0);
   3665   1.1  msaitoh }
   3666   1.1  msaitoh 
   3667   1.1  msaitoh /**
   3668   1.1  msaitoh  *  ixgbe_validate_eeprom_checksum_X550 - Validate EEPROM checksum
   3669   1.1  msaitoh  *  @hw: pointer to hardware structure
   3670   1.1  msaitoh  *  @checksum_val: calculated checksum
   3671   1.1  msaitoh  *
   3672   1.1  msaitoh  *  Performs checksum calculation and validates the EEPROM checksum.  If the
   3673   1.1  msaitoh  *  caller does not need checksum_val, the value can be NULL.
   3674   1.1  msaitoh  **/
   3675   1.1  msaitoh s32 ixgbe_validate_eeprom_checksum_X550(struct ixgbe_hw *hw, u16 *checksum_val)
   3676   1.1  msaitoh {
   3677   1.1  msaitoh 	s32 status;
   3678   1.1  msaitoh 	u16 checksum;
   3679   1.1  msaitoh 	u16 read_checksum = 0;
   3680   1.1  msaitoh 
   3681   1.1  msaitoh 	DEBUGFUNC("ixgbe_validate_eeprom_checksum_X550");
   3682   1.1  msaitoh 
   3683   1.1  msaitoh 	/* Read the first word from the EEPROM. If this times out or fails, do
   3684   1.1  msaitoh 	 * not continue or we could be in for a very long wait while every
   3685   1.1  msaitoh 	 * EEPROM read fails
   3686   1.1  msaitoh 	 */
   3687   1.1  msaitoh 	status = hw->eeprom.ops.read(hw, 0, &checksum);
   3688   1.1  msaitoh 	if (status) {
   3689   1.1  msaitoh 		DEBUGOUT("EEPROM read failed\n");
   3690   1.1  msaitoh 		return status;
   3691   1.1  msaitoh 	}
   3692   1.1  msaitoh 
   3693   1.1  msaitoh 	status = hw->eeprom.ops.calc_checksum(hw);
   3694   1.1  msaitoh 	if (status < 0)
   3695   1.1  msaitoh 		return status;
   3696   1.1  msaitoh 
   3697   1.1  msaitoh 	checksum = (u16)(status & 0xffff);
   3698   1.1  msaitoh 
   3699   1.1  msaitoh 	status = ixgbe_read_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
   3700   1.1  msaitoh 					   &read_checksum);
   3701   1.1  msaitoh 	if (status)
   3702   1.1  msaitoh 		return status;
   3703   1.1  msaitoh 
   3704   1.1  msaitoh 	/* Verify read checksum from EEPROM is the same as
   3705   1.1  msaitoh 	 * calculated checksum
   3706   1.1  msaitoh 	 */
   3707   1.1  msaitoh 	if (read_checksum != checksum) {
   3708   1.1  msaitoh 		status = IXGBE_ERR_EEPROM_CHECKSUM;
   3709   1.1  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_INVALID_STATE,
   3710   1.1  msaitoh 			     "Invalid EEPROM checksum");
   3711   1.1  msaitoh 	}
   3712   1.1  msaitoh 
   3713   1.1  msaitoh 	/* If the user cares, return the calculated checksum */
   3714   1.1  msaitoh 	if (checksum_val)
   3715   1.1  msaitoh 		*checksum_val = checksum;
   3716   1.1  msaitoh 
   3717   1.1  msaitoh 	return status;
   3718   1.1  msaitoh }
   3719   1.1  msaitoh 
   3720   1.1  msaitoh /**
   3721   1.1  msaitoh  * ixgbe_update_eeprom_checksum_X550 - Updates the EEPROM checksum and flash
   3722   1.1  msaitoh  * @hw: pointer to hardware structure
   3723   1.1  msaitoh  *
   3724   1.1  msaitoh  * After writing EEPROM to shadow RAM using EEWR register, software calculates
   3725   1.1  msaitoh  * checksum and updates the EEPROM and instructs the hardware to update
   3726   1.1  msaitoh  * the flash.
   3727   1.1  msaitoh  **/
   3728   1.1  msaitoh s32 ixgbe_update_eeprom_checksum_X550(struct ixgbe_hw *hw)
   3729   1.1  msaitoh {
   3730   1.1  msaitoh 	s32 status;
   3731   1.1  msaitoh 	u16 checksum = 0;
   3732   1.1  msaitoh 
   3733   1.1  msaitoh 	DEBUGFUNC("ixgbe_update_eeprom_checksum_X550");
   3734   1.1  msaitoh 
   3735   1.1  msaitoh 	/* Read the first word from the EEPROM. If this times out or fails, do
   3736   1.1  msaitoh 	 * not continue or we could be in for a very long wait while every
   3737   1.1  msaitoh 	 * EEPROM read fails
   3738   1.1  msaitoh 	 */
   3739   1.1  msaitoh 	status = ixgbe_read_ee_hostif_X550(hw, 0, &checksum);
   3740   1.1  msaitoh 	if (status) {
   3741   1.1  msaitoh 		DEBUGOUT("EEPROM read failed\n");
   3742   1.1  msaitoh 		return status;
   3743   1.1  msaitoh 	}
   3744   1.1  msaitoh 
   3745   1.1  msaitoh 	status = ixgbe_calc_eeprom_checksum_X550(hw);
   3746   1.1  msaitoh 	if (status < 0)
   3747   1.1  msaitoh 		return status;
   3748   1.1  msaitoh 
   3749   1.1  msaitoh 	checksum = (u16)(status & 0xffff);
   3750   1.1  msaitoh 
   3751   1.1  msaitoh 	status = ixgbe_write_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
   3752   1.1  msaitoh 					    checksum);
   3753   1.1  msaitoh 	if (status)
   3754   1.1  msaitoh 		return status;
   3755   1.1  msaitoh 
   3756   1.1  msaitoh 	status = ixgbe_update_flash_X550(hw);
   3757   1.1  msaitoh 
   3758   1.1  msaitoh 	return status;
   3759   1.1  msaitoh }
   3760   1.1  msaitoh 
   3761   1.1  msaitoh /**
   3762   1.1  msaitoh  *  ixgbe_update_flash_X550 - Instruct HW to copy EEPROM to Flash device
   3763   1.1  msaitoh  *  @hw: pointer to hardware structure
   3764   1.1  msaitoh  *
   3765   1.1  msaitoh  *  Issue a shadow RAM dump to FW to copy EEPROM from shadow RAM to the flash.
   3766   1.1  msaitoh  **/
   3767   1.1  msaitoh s32 ixgbe_update_flash_X550(struct ixgbe_hw *hw)
   3768   1.1  msaitoh {
   3769   1.1  msaitoh 	s32 status = IXGBE_SUCCESS;
   3770   1.1  msaitoh 	union ixgbe_hic_hdr2 buffer;
   3771   1.1  msaitoh 
   3772   1.1  msaitoh 	DEBUGFUNC("ixgbe_update_flash_X550");
   3773   1.1  msaitoh 
   3774   1.1  msaitoh 	buffer.req.cmd = FW_SHADOW_RAM_DUMP_CMD;
   3775   1.1  msaitoh 	buffer.req.buf_lenh = 0;
   3776   1.1  msaitoh 	buffer.req.buf_lenl = FW_SHADOW_RAM_DUMP_LEN;
   3777   1.1  msaitoh 	buffer.req.checksum = FW_DEFAULT_CHECKSUM;
   3778   1.1  msaitoh 
   3779   1.1  msaitoh 	status = ixgbe_host_interface_command(hw, (u32 *)&buffer,
   3780   1.1  msaitoh 					      sizeof(buffer),
   3781   1.1  msaitoh 					      IXGBE_HI_COMMAND_TIMEOUT, FALSE);
   3782   1.1  msaitoh 
   3783   1.1  msaitoh 	return status;
   3784   1.1  msaitoh }
   3785   1.1  msaitoh 
   3786   1.1  msaitoh /**
   3787   1.1  msaitoh  *  ixgbe_get_supported_physical_layer_X550em - Returns physical layer type
   3788   1.1  msaitoh  *  @hw: pointer to hardware structure
   3789   1.1  msaitoh  *
   3790   1.1  msaitoh  *  Determines physical layer capabilities of the current configuration.
   3791   1.1  msaitoh  **/
   3792   1.6  msaitoh u64 ixgbe_get_supported_physical_layer_X550em(struct ixgbe_hw *hw)
   3793   1.1  msaitoh {
   3794   1.6  msaitoh 	u64 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
   3795   1.1  msaitoh 	u16 ext_ability = 0;
   3796   1.1  msaitoh 
   3797   1.1  msaitoh 	DEBUGFUNC("ixgbe_get_supported_physical_layer_X550em");
   3798   1.1  msaitoh 
   3799   1.1  msaitoh 	hw->phy.ops.identify(hw);
   3800   1.1  msaitoh 
   3801   1.1  msaitoh 	switch (hw->phy.type) {
   3802   1.1  msaitoh 	case ixgbe_phy_x550em_kr:
   3803   1.6  msaitoh 		if (hw->mac.type == ixgbe_mac_X550EM_a) {
   3804   1.6  msaitoh 			if (hw->phy.nw_mng_if_sel &
   3805   1.6  msaitoh 			    IXGBE_NW_MNG_IF_SEL_PHY_SPEED_2_5G) {
   3806   1.6  msaitoh 				physical_layer =
   3807   1.6  msaitoh 					IXGBE_PHYSICAL_LAYER_2500BASE_KX;
   3808   1.6  msaitoh 				break;
   3809   1.6  msaitoh 			} else if (hw->device_id ==
   3810   1.6  msaitoh 				   IXGBE_DEV_ID_X550EM_A_KR_L) {
   3811   1.6  msaitoh 				physical_layer =
   3812   1.6  msaitoh 					IXGBE_PHYSICAL_LAYER_1000BASE_KX;
   3813   1.6  msaitoh 				break;
   3814   1.6  msaitoh 			}
   3815   1.6  msaitoh 		}
   3816   1.6  msaitoh 		/* fall through */
   3817   1.6  msaitoh 	case ixgbe_phy_x550em_xfi:
   3818   1.1  msaitoh 		physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KR |
   3819   1.1  msaitoh 				 IXGBE_PHYSICAL_LAYER_1000BASE_KX;
   3820   1.1  msaitoh 		break;
   3821   1.1  msaitoh 	case ixgbe_phy_x550em_kx4:
   3822   1.1  msaitoh 		physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KX4 |
   3823   1.1  msaitoh 				 IXGBE_PHYSICAL_LAYER_1000BASE_KX;
   3824   1.1  msaitoh 		break;
   3825   1.1  msaitoh 	case ixgbe_phy_x550em_ext_t:
   3826   1.1  msaitoh 		hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_EXT_ABILITY,
   3827   1.1  msaitoh 				     IXGBE_MDIO_PMA_PMD_DEV_TYPE,
   3828   1.1  msaitoh 				     &ext_ability);
   3829   1.1  msaitoh 		if (ext_ability & IXGBE_MDIO_PHY_10GBASET_ABILITY)
   3830   1.1  msaitoh 			physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
   3831   1.1  msaitoh 		if (ext_ability & IXGBE_MDIO_PHY_1000BASET_ABILITY)
   3832   1.1  msaitoh 			physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
   3833   1.1  msaitoh 		break;
   3834   1.6  msaitoh 	case ixgbe_phy_fw:
   3835   1.6  msaitoh 		if (hw->phy.speeds_supported & IXGBE_LINK_SPEED_1GB_FULL)
   3836   1.6  msaitoh 			physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
   3837   1.6  msaitoh 		if (hw->phy.speeds_supported & IXGBE_LINK_SPEED_100_FULL)
   3838   1.6  msaitoh 			physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
   3839   1.6  msaitoh 		if (hw->phy.speeds_supported & IXGBE_LINK_SPEED_10_FULL)
   3840   1.6  msaitoh 			physical_layer |= IXGBE_PHYSICAL_LAYER_10BASE_T;
   3841   1.6  msaitoh 		break;
   3842   1.6  msaitoh 	case ixgbe_phy_sgmii:
   3843   1.6  msaitoh 		physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_KX;
   3844   1.6  msaitoh 		break;
   3845   1.6  msaitoh 	case ixgbe_phy_ext_1g_t:
   3846   1.6  msaitoh 		physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_T;
   3847   1.6  msaitoh 		break;
   3848   1.1  msaitoh 	default:
   3849   1.1  msaitoh 		break;
   3850   1.1  msaitoh 	}
   3851   1.1  msaitoh 
   3852   1.1  msaitoh 	if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber)
   3853   1.1  msaitoh 		physical_layer = ixgbe_get_supported_phy_sfp_layer_generic(hw);
   3854   1.1  msaitoh 
   3855   1.1  msaitoh 	return physical_layer;
   3856   1.1  msaitoh }
   3857   1.1  msaitoh 
   3858   1.1  msaitoh /**
   3859   1.1  msaitoh  * ixgbe_get_bus_info_x550em - Set PCI bus info
   3860   1.1  msaitoh  * @hw: pointer to hardware structure
   3861   1.1  msaitoh  *
   3862   1.1  msaitoh  * Sets bus link width and speed to unknown because X550em is
   3863   1.1  msaitoh  * not a PCI device.
   3864   1.1  msaitoh  **/
   3865   1.1  msaitoh s32 ixgbe_get_bus_info_X550em(struct ixgbe_hw *hw)
   3866   1.1  msaitoh {
   3867   1.1  msaitoh 
   3868   1.1  msaitoh 	DEBUGFUNC("ixgbe_get_bus_info_x550em");
   3869   1.1  msaitoh 
   3870   1.1  msaitoh 	hw->bus.width = ixgbe_bus_width_unknown;
   3871   1.1  msaitoh 	hw->bus.speed = ixgbe_bus_speed_unknown;
   3872   1.1  msaitoh 
   3873   1.1  msaitoh 	hw->mac.ops.set_lan_id(hw);
   3874   1.1  msaitoh 
   3875   1.1  msaitoh 	return IXGBE_SUCCESS;
   3876   1.1  msaitoh }
   3877   1.1  msaitoh 
   3878   1.1  msaitoh /**
   3879   1.1  msaitoh  * ixgbe_disable_rx_x550 - Disable RX unit
   3880  1.12  msaitoh  * @hw: pointer to hardware structure
   3881   1.1  msaitoh  *
   3882   1.1  msaitoh  * Enables the Rx DMA unit for x550
   3883   1.1  msaitoh  **/
   3884   1.1  msaitoh void ixgbe_disable_rx_x550(struct ixgbe_hw *hw)
   3885   1.1  msaitoh {
   3886   1.1  msaitoh 	u32 rxctrl, pfdtxgswc;
   3887   1.1  msaitoh 	s32 status;
   3888   1.1  msaitoh 	struct ixgbe_hic_disable_rxen fw_cmd;
   3889   1.1  msaitoh 
   3890   1.4  msaitoh 	DEBUGFUNC("ixgbe_disable_rx_dma_x550");
   3891   1.1  msaitoh 
   3892   1.1  msaitoh 	rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
   3893   1.1  msaitoh 	if (rxctrl & IXGBE_RXCTRL_RXEN) {
   3894   1.1  msaitoh 		pfdtxgswc = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC);
   3895   1.1  msaitoh 		if (pfdtxgswc & IXGBE_PFDTXGSWC_VT_LBEN) {
   3896   1.1  msaitoh 			pfdtxgswc &= ~IXGBE_PFDTXGSWC_VT_LBEN;
   3897   1.1  msaitoh 			IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, pfdtxgswc);
   3898   1.1  msaitoh 			hw->mac.set_lben = TRUE;
   3899   1.1  msaitoh 		} else {
   3900   1.1  msaitoh 			hw->mac.set_lben = FALSE;
   3901   1.1  msaitoh 		}
   3902   1.1  msaitoh 
   3903   1.1  msaitoh 		fw_cmd.hdr.cmd = FW_DISABLE_RXEN_CMD;
   3904   1.1  msaitoh 		fw_cmd.hdr.buf_len = FW_DISABLE_RXEN_LEN;
   3905   1.1  msaitoh 		fw_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
   3906   1.1  msaitoh 		fw_cmd.port_number = (u8)hw->bus.lan_id;
   3907   1.1  msaitoh 
   3908   1.1  msaitoh 		status = ixgbe_host_interface_command(hw, (u32 *)&fw_cmd,
   3909   1.1  msaitoh 					sizeof(struct ixgbe_hic_disable_rxen),
   3910   1.1  msaitoh 					IXGBE_HI_COMMAND_TIMEOUT, TRUE);
   3911   1.1  msaitoh 
   3912   1.1  msaitoh 		/* If we fail - disable RX using register write */
   3913   1.1  msaitoh 		if (status) {
   3914   1.1  msaitoh 			rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
   3915   1.1  msaitoh 			if (rxctrl & IXGBE_RXCTRL_RXEN) {
   3916   1.1  msaitoh 				rxctrl &= ~IXGBE_RXCTRL_RXEN;
   3917   1.1  msaitoh 				IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl);
   3918   1.1  msaitoh 			}
   3919   1.1  msaitoh 		}
   3920   1.1  msaitoh 	}
   3921   1.1  msaitoh }
   3922   1.1  msaitoh 
   3923   1.1  msaitoh /**
   3924   1.1  msaitoh  * ixgbe_enter_lplu_x550em - Transition to low power states
   3925   1.1  msaitoh  *  @hw: pointer to hardware structure
   3926   1.1  msaitoh  *
   3927   1.1  msaitoh  * Configures Low Power Link Up on transition to low power states
   3928   1.1  msaitoh  * (from D0 to non-D0). Link is required to enter LPLU so avoid resetting the
   3929   1.1  msaitoh  * X557 PHY immediately prior to entering LPLU.
   3930   1.1  msaitoh  **/
   3931   1.1  msaitoh s32 ixgbe_enter_lplu_t_x550em(struct ixgbe_hw *hw)
   3932   1.1  msaitoh {
   3933   1.1  msaitoh 	u16 an_10g_cntl_reg, autoneg_reg, speed;
   3934   1.1  msaitoh 	s32 status;
   3935   1.1  msaitoh 	ixgbe_link_speed lcd_speed;
   3936   1.1  msaitoh 	u32 save_autoneg;
   3937   1.1  msaitoh 	bool link_up;
   3938   1.1  msaitoh 
   3939   1.2  msaitoh 	/* SW LPLU not required on later HW revisions. */
   3940   1.6  msaitoh 	if ((hw->mac.type == ixgbe_mac_X550EM_x) &&
   3941   1.6  msaitoh 	    (IXGBE_FUSES0_REV_MASK &
   3942   1.6  msaitoh 	     IXGBE_READ_REG(hw, IXGBE_FUSES0_GROUP(0))))
   3943   1.2  msaitoh 		return IXGBE_SUCCESS;
   3944   1.2  msaitoh 
   3945   1.1  msaitoh 	/* If blocked by MNG FW, then don't restart AN */
   3946   1.1  msaitoh 	if (ixgbe_check_reset_blocked(hw))
   3947   1.1  msaitoh 		return IXGBE_SUCCESS;
   3948   1.1  msaitoh 
   3949   1.1  msaitoh 	status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
   3950   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3951   1.1  msaitoh 		return status;
   3952   1.1  msaitoh 
   3953   1.1  msaitoh 	status = ixgbe_read_eeprom(hw, NVM_INIT_CTRL_3, &hw->eeprom.ctrl_word_3);
   3954   1.1  msaitoh 
   3955   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3956   1.1  msaitoh 		return status;
   3957   1.1  msaitoh 
   3958   1.1  msaitoh 	/* If link is down, LPLU disabled in NVM, WoL disabled, or manageability
   3959   1.1  msaitoh 	 * disabled, then force link down by entering low power mode.
   3960   1.1  msaitoh 	 */
   3961   1.1  msaitoh 	if (!link_up || !(hw->eeprom.ctrl_word_3 & NVM_INIT_CTRL_3_LPLU) ||
   3962   1.1  msaitoh 	    !(hw->wol_enabled || ixgbe_mng_present(hw)))
   3963   1.1  msaitoh 		return ixgbe_set_copper_phy_power(hw, FALSE);
   3964   1.1  msaitoh 
   3965   1.1  msaitoh 	/* Determine LCD */
   3966   1.1  msaitoh 	status = ixgbe_get_lcd_t_x550em(hw, &lcd_speed);
   3967   1.1  msaitoh 
   3968   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3969   1.1  msaitoh 		return status;
   3970   1.1  msaitoh 
   3971   1.1  msaitoh 	/* If no valid LCD link speed, then force link down and exit. */
   3972   1.1  msaitoh 	if (lcd_speed == IXGBE_LINK_SPEED_UNKNOWN)
   3973   1.1  msaitoh 		return ixgbe_set_copper_phy_power(hw, FALSE);
   3974   1.1  msaitoh 
   3975   1.1  msaitoh 	status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_STAT,
   3976   1.1  msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
   3977   1.1  msaitoh 				      &speed);
   3978   1.1  msaitoh 
   3979   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3980   1.1  msaitoh 		return status;
   3981   1.1  msaitoh 
   3982   1.1  msaitoh 	/* If no link now, speed is invalid so take link down */
   3983   1.1  msaitoh 	status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
   3984   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   3985   1.1  msaitoh 		return ixgbe_set_copper_phy_power(hw, FALSE);
   3986   1.1  msaitoh 
   3987   1.1  msaitoh 	/* clear everything but the speed bits */
   3988   1.1  msaitoh 	speed &= IXGBE_MDIO_AUTO_NEG_VEN_STAT_SPEED_MASK;
   3989   1.1  msaitoh 
   3990   1.1  msaitoh 	/* If current speed is already LCD, then exit. */
   3991   1.1  msaitoh 	if (((speed == IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB) &&
   3992   1.1  msaitoh 	     (lcd_speed == IXGBE_LINK_SPEED_1GB_FULL)) ||
   3993   1.1  msaitoh 	    ((speed == IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB) &&
   3994   1.1  msaitoh 	     (lcd_speed == IXGBE_LINK_SPEED_10GB_FULL)))
   3995   1.1  msaitoh 		return status;
   3996   1.1  msaitoh 
   3997   1.1  msaitoh 	/* Clear AN completed indication */
   3998   1.1  msaitoh 	status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_TX_ALARM,
   3999   1.1  msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
   4000   1.1  msaitoh 				      &autoneg_reg);
   4001   1.1  msaitoh 
   4002   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   4003   1.1  msaitoh 		return status;
   4004   1.1  msaitoh 
   4005   1.1  msaitoh 	status = hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
   4006   1.1  msaitoh 			     IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
   4007   1.1  msaitoh 			     &an_10g_cntl_reg);
   4008   1.1  msaitoh 
   4009   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   4010   1.1  msaitoh 		return status;
   4011   1.1  msaitoh 
   4012   1.1  msaitoh 	status = hw->phy.ops.read_reg(hw,
   4013   1.1  msaitoh 			     IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
   4014   1.1  msaitoh 			     IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
   4015   1.1  msaitoh 			     &autoneg_reg);
   4016   1.1  msaitoh 
   4017   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   4018   1.1  msaitoh 		return status;
   4019   1.1  msaitoh 
   4020   1.1  msaitoh 	save_autoneg = hw->phy.autoneg_advertised;
   4021   1.1  msaitoh 
   4022   1.1  msaitoh 	/* Setup link at least common link speed */
   4023   1.1  msaitoh 	status = hw->mac.ops.setup_link(hw, lcd_speed, FALSE);
   4024   1.1  msaitoh 
   4025   1.1  msaitoh 	/* restore autoneg from before setting lplu speed */
   4026   1.1  msaitoh 	hw->phy.autoneg_advertised = save_autoneg;
   4027   1.1  msaitoh 
   4028   1.1  msaitoh 	return status;
   4029   1.1  msaitoh }
   4030   1.1  msaitoh 
   4031   1.1  msaitoh /**
   4032   1.1  msaitoh  * ixgbe_get_lcd_x550em - Determine lowest common denominator
   4033   1.1  msaitoh  *  @hw: pointer to hardware structure
   4034   1.1  msaitoh  *  @lcd_speed: pointer to lowest common link speed
   4035   1.1  msaitoh  *
   4036   1.1  msaitoh  * Determine lowest common link speed with link partner.
   4037   1.1  msaitoh  **/
   4038   1.1  msaitoh s32 ixgbe_get_lcd_t_x550em(struct ixgbe_hw *hw, ixgbe_link_speed *lcd_speed)
   4039   1.1  msaitoh {
   4040   1.1  msaitoh 	u16 an_lp_status;
   4041   1.1  msaitoh 	s32 status;
   4042   1.1  msaitoh 	u16 word = hw->eeprom.ctrl_word_3;
   4043   1.1  msaitoh 
   4044   1.1  msaitoh 	*lcd_speed = IXGBE_LINK_SPEED_UNKNOWN;
   4045   1.1  msaitoh 
   4046   1.1  msaitoh 	status = hw->phy.ops.read_reg(hw, IXGBE_AUTO_NEG_LP_STATUS,
   4047   1.1  msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
   4048   1.1  msaitoh 				      &an_lp_status);
   4049   1.1  msaitoh 
   4050   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   4051   1.1  msaitoh 		return status;
   4052   1.1  msaitoh 
   4053   1.1  msaitoh 	/* If link partner advertised 1G, return 1G */
   4054   1.1  msaitoh 	if (an_lp_status & IXGBE_AUTO_NEG_LP_1000BASE_CAP) {
   4055   1.1  msaitoh 		*lcd_speed = IXGBE_LINK_SPEED_1GB_FULL;
   4056   1.1  msaitoh 		return status;
   4057   1.1  msaitoh 	}
   4058   1.1  msaitoh 
   4059   1.1  msaitoh 	/* If 10G disabled for LPLU via NVM D10GMP, then return no valid LCD */
   4060   1.1  msaitoh 	if ((hw->bus.lan_id && (word & NVM_INIT_CTRL_3_D10GMP_PORT1)) ||
   4061   1.1  msaitoh 	    (word & NVM_INIT_CTRL_3_D10GMP_PORT0))
   4062   1.1  msaitoh 		return status;
   4063   1.1  msaitoh 
   4064   1.1  msaitoh 	/* Link partner not capable of lower speeds, return 10G */
   4065   1.1  msaitoh 	*lcd_speed = IXGBE_LINK_SPEED_10GB_FULL;
   4066   1.1  msaitoh 	return status;
   4067   1.1  msaitoh }
   4068   1.1  msaitoh 
   4069   1.1  msaitoh /**
   4070   1.1  msaitoh  *  ixgbe_setup_fc_X550em - Set up flow control
   4071   1.1  msaitoh  *  @hw: pointer to hardware structure
   4072   1.1  msaitoh  *
   4073   1.1  msaitoh  *  Called at init time to set up flow control.
   4074   1.1  msaitoh  **/
   4075   1.1  msaitoh s32 ixgbe_setup_fc_X550em(struct ixgbe_hw *hw)
   4076   1.1  msaitoh {
   4077   1.1  msaitoh 	s32 ret_val = IXGBE_SUCCESS;
   4078   1.1  msaitoh 	u32 pause, asm_dir, reg_val;
   4079   1.1  msaitoh 
   4080   1.1  msaitoh 	DEBUGFUNC("ixgbe_setup_fc_X550em");
   4081   1.1  msaitoh 
   4082   1.1  msaitoh 	/* Validate the requested mode */
   4083   1.1  msaitoh 	if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
   4084   1.1  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_UNSUPPORTED,
   4085   1.1  msaitoh 			"ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
   4086   1.1  msaitoh 		ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
   4087   1.1  msaitoh 		goto out;
   4088   1.1  msaitoh 	}
   4089   1.1  msaitoh 
   4090   1.1  msaitoh 	/* 10gig parts do not have a word in the EEPROM to determine the
   4091   1.1  msaitoh 	 * default flow control setting, so we explicitly set it to full.
   4092   1.1  msaitoh 	 */
   4093   1.1  msaitoh 	if (hw->fc.requested_mode == ixgbe_fc_default)
   4094   1.1  msaitoh 		hw->fc.requested_mode = ixgbe_fc_full;
   4095   1.1  msaitoh 
   4096   1.1  msaitoh 	/* Determine PAUSE and ASM_DIR bits. */
   4097   1.1  msaitoh 	switch (hw->fc.requested_mode) {
   4098   1.1  msaitoh 	case ixgbe_fc_none:
   4099   1.1  msaitoh 		pause = 0;
   4100   1.1  msaitoh 		asm_dir = 0;
   4101   1.1  msaitoh 		break;
   4102   1.1  msaitoh 	case ixgbe_fc_tx_pause:
   4103   1.1  msaitoh 		pause = 0;
   4104   1.1  msaitoh 		asm_dir = 1;
   4105   1.1  msaitoh 		break;
   4106   1.1  msaitoh 	case ixgbe_fc_rx_pause:
   4107   1.1  msaitoh 		/* Rx Flow control is enabled and Tx Flow control is
   4108   1.1  msaitoh 		 * disabled by software override. Since there really
   4109   1.1  msaitoh 		 * isn't a way to advertise that we are capable of RX
   4110   1.1  msaitoh 		 * Pause ONLY, we will advertise that we support both
   4111   1.1  msaitoh 		 * symmetric and asymmetric Rx PAUSE, as such we fall
   4112   1.1  msaitoh 		 * through to the fc_full statement.  Later, we will
   4113   1.1  msaitoh 		 * disable the adapter's ability to send PAUSE frames.
   4114   1.1  msaitoh 		 */
   4115   1.1  msaitoh 	case ixgbe_fc_full:
   4116   1.1  msaitoh 		pause = 1;
   4117   1.1  msaitoh 		asm_dir = 1;
   4118   1.1  msaitoh 		break;
   4119   1.1  msaitoh 	default:
   4120   1.1  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_ARGUMENT,
   4121   1.1  msaitoh 			"Flow control param set incorrectly\n");
   4122   1.1  msaitoh 		ret_val = IXGBE_ERR_CONFIG;
   4123   1.1  msaitoh 		goto out;
   4124   1.1  msaitoh 	}
   4125   1.1  msaitoh 
   4126   1.6  msaitoh 	switch (hw->device_id) {
   4127   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_X_KR:
   4128   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_KR:
   4129   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_A_KR_L:
   4130   1.6  msaitoh 		ret_val = hw->mac.ops.read_iosf_sb_reg(hw,
   4131   1.1  msaitoh 			IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
   4132   1.1  msaitoh 			IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
   4133   1.1  msaitoh 		if (ret_val != IXGBE_SUCCESS)
   4134   1.1  msaitoh 			goto out;
   4135   1.1  msaitoh 		reg_val &= ~(IXGBE_KRM_AN_CNTL_1_SYM_PAUSE |
   4136   1.1  msaitoh 			IXGBE_KRM_AN_CNTL_1_ASM_PAUSE);
   4137   1.1  msaitoh 		if (pause)
   4138   1.1  msaitoh 			reg_val |= IXGBE_KRM_AN_CNTL_1_SYM_PAUSE;
   4139   1.1  msaitoh 		if (asm_dir)
   4140   1.1  msaitoh 			reg_val |= IXGBE_KRM_AN_CNTL_1_ASM_PAUSE;
   4141   1.6  msaitoh 		ret_val = hw->mac.ops.write_iosf_sb_reg(hw,
   4142   1.1  msaitoh 			IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
   4143   1.1  msaitoh 			IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
   4144   1.1  msaitoh 
   4145   1.2  msaitoh 		/* This device does not fully support AN. */
   4146   1.2  msaitoh 		hw->fc.disable_fc_autoneg = TRUE;
   4147   1.6  msaitoh 		break;
   4148   1.6  msaitoh 	case IXGBE_DEV_ID_X550EM_X_XFI:
   4149   1.6  msaitoh 		hw->fc.disable_fc_autoneg = TRUE;
   4150   1.6  msaitoh 		break;
   4151   1.6  msaitoh 	default:
   4152   1.6  msaitoh 		break;
   4153   1.1  msaitoh 	}
   4154   1.1  msaitoh 
   4155   1.1  msaitoh out:
   4156   1.1  msaitoh 	return ret_val;
   4157   1.1  msaitoh }
   4158   1.1  msaitoh 
   4159   1.1  msaitoh /**
   4160   1.6  msaitoh  *  ixgbe_fc_autoneg_backplane_x550em_a - Enable flow control IEEE clause 37
   4161   1.6  msaitoh  *  @hw: pointer to hardware structure
   4162   1.6  msaitoh  *
   4163   1.6  msaitoh  *  Enable flow control according to IEEE clause 37.
   4164   1.6  msaitoh  **/
   4165   1.6  msaitoh void ixgbe_fc_autoneg_backplane_x550em_a(struct ixgbe_hw *hw)
   4166   1.6  msaitoh {
   4167   1.6  msaitoh 	u32 link_s1, lp_an_page_low, an_cntl_1;
   4168   1.6  msaitoh 	s32 status = IXGBE_ERR_FC_NOT_NEGOTIATED;
   4169   1.6  msaitoh 	ixgbe_link_speed speed;
   4170   1.6  msaitoh 	bool link_up;
   4171   1.6  msaitoh 
   4172   1.6  msaitoh 	/* AN should have completed when the cable was plugged in.
   4173   1.6  msaitoh 	 * Look for reasons to bail out.  Bail out if:
   4174   1.6  msaitoh 	 * - FC autoneg is disabled, or if
   4175   1.6  msaitoh 	 * - link is not up.
   4176   1.6  msaitoh 	 */
   4177   1.6  msaitoh 	if (hw->fc.disable_fc_autoneg) {
   4178   1.6  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_UNSUPPORTED,
   4179   1.6  msaitoh 			     "Flow control autoneg is disabled");
   4180   1.6  msaitoh 		goto out;
   4181   1.6  msaitoh 	}
   4182   1.6  msaitoh 
   4183   1.6  msaitoh 	hw->mac.ops.check_link(hw, &speed, &link_up, FALSE);
   4184   1.6  msaitoh 	if (!link_up) {
   4185   1.6  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_SOFTWARE, "The link is down");
   4186   1.6  msaitoh 		goto out;
   4187   1.6  msaitoh 	}
   4188   1.6  msaitoh 
   4189   1.6  msaitoh 	/* Check at auto-negotiation has completed */
   4190   1.6  msaitoh 	status = hw->mac.ops.read_iosf_sb_reg(hw,
   4191   1.6  msaitoh 					IXGBE_KRM_LINK_S1(hw->bus.lan_id),
   4192   1.6  msaitoh 					IXGBE_SB_IOSF_TARGET_KR_PHY, &link_s1);
   4193   1.6  msaitoh 
   4194   1.6  msaitoh 	if (status != IXGBE_SUCCESS ||
   4195   1.6  msaitoh 	    (link_s1 & IXGBE_KRM_LINK_S1_MAC_AN_COMPLETE) == 0) {
   4196   1.6  msaitoh 		DEBUGOUT("Auto-Negotiation did not complete\n");
   4197   1.6  msaitoh 		status = IXGBE_ERR_FC_NOT_NEGOTIATED;
   4198   1.6  msaitoh 		goto out;
   4199   1.6  msaitoh 	}
   4200   1.6  msaitoh 
   4201   1.6  msaitoh 	/* Read the 10g AN autoc and LP ability registers and resolve
   4202   1.6  msaitoh 	 * local flow control settings accordingly
   4203   1.6  msaitoh 	 */
   4204   1.6  msaitoh 	status = hw->mac.ops.read_iosf_sb_reg(hw,
   4205   1.6  msaitoh 				IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
   4206   1.6  msaitoh 				IXGBE_SB_IOSF_TARGET_KR_PHY, &an_cntl_1);
   4207   1.6  msaitoh 
   4208   1.6  msaitoh 	if (status != IXGBE_SUCCESS) {
   4209   1.6  msaitoh 		DEBUGOUT("Auto-Negotiation did not complete\n");
   4210   1.6  msaitoh 		goto out;
   4211   1.6  msaitoh 	}
   4212   1.6  msaitoh 
   4213   1.6  msaitoh 	status = hw->mac.ops.read_iosf_sb_reg(hw,
   4214   1.6  msaitoh 				IXGBE_KRM_LP_BASE_PAGE_HIGH(hw->bus.lan_id),
   4215   1.6  msaitoh 				IXGBE_SB_IOSF_TARGET_KR_PHY, &lp_an_page_low);
   4216   1.6  msaitoh 
   4217   1.6  msaitoh 	if (status != IXGBE_SUCCESS) {
   4218   1.6  msaitoh 		DEBUGOUT("Auto-Negotiation did not complete\n");
   4219   1.6  msaitoh 		goto out;
   4220   1.6  msaitoh 	}
   4221   1.6  msaitoh 
   4222   1.6  msaitoh 	status = ixgbe_negotiate_fc(hw, an_cntl_1, lp_an_page_low,
   4223   1.6  msaitoh 				    IXGBE_KRM_AN_CNTL_1_SYM_PAUSE,
   4224   1.6  msaitoh 				    IXGBE_KRM_AN_CNTL_1_ASM_PAUSE,
   4225   1.6  msaitoh 				    IXGBE_KRM_LP_BASE_PAGE_HIGH_SYM_PAUSE,
   4226   1.6  msaitoh 				    IXGBE_KRM_LP_BASE_PAGE_HIGH_ASM_PAUSE);
   4227   1.6  msaitoh 
   4228   1.6  msaitoh out:
   4229   1.6  msaitoh 	if (status == IXGBE_SUCCESS) {
   4230   1.6  msaitoh 		hw->fc.fc_was_autonegged = TRUE;
   4231   1.6  msaitoh 	} else {
   4232   1.6  msaitoh 		hw->fc.fc_was_autonegged = FALSE;
   4233   1.6  msaitoh 		hw->fc.current_mode = hw->fc.requested_mode;
   4234   1.6  msaitoh 	}
   4235   1.6  msaitoh }
   4236   1.6  msaitoh 
   4237   1.6  msaitoh /**
   4238   1.6  msaitoh  *  ixgbe_fc_autoneg_fiber_x550em_a - passthrough FC settings
   4239   1.6  msaitoh  *  @hw: pointer to hardware structure
   4240   1.6  msaitoh  *
   4241   1.6  msaitoh  **/
   4242   1.6  msaitoh void ixgbe_fc_autoneg_fiber_x550em_a(struct ixgbe_hw *hw)
   4243   1.6  msaitoh {
   4244   1.6  msaitoh 	hw->fc.fc_was_autonegged = FALSE;
   4245   1.6  msaitoh 	hw->fc.current_mode = hw->fc.requested_mode;
   4246   1.6  msaitoh }
   4247   1.6  msaitoh 
   4248   1.6  msaitoh /**
   4249   1.6  msaitoh  *  ixgbe_fc_autoneg_sgmii_x550em_a - Enable flow control IEEE clause 37
   4250   1.6  msaitoh  *  @hw: pointer to hardware structure
   4251   1.6  msaitoh  *
   4252   1.6  msaitoh  *  Enable flow control according to IEEE clause 37.
   4253   1.6  msaitoh  **/
   4254   1.6  msaitoh void ixgbe_fc_autoneg_sgmii_x550em_a(struct ixgbe_hw *hw)
   4255   1.6  msaitoh {
   4256   1.6  msaitoh 	s32 status = IXGBE_ERR_FC_NOT_NEGOTIATED;
   4257   1.6  msaitoh 	u32 info[FW_PHY_ACT_DATA_COUNT] = { 0 };
   4258   1.6  msaitoh 	ixgbe_link_speed speed;
   4259   1.6  msaitoh 	bool link_up;
   4260   1.6  msaitoh 
   4261   1.6  msaitoh 	/* AN should have completed when the cable was plugged in.
   4262   1.6  msaitoh 	 * Look for reasons to bail out.  Bail out if:
   4263   1.6  msaitoh 	 * - FC autoneg is disabled, or if
   4264   1.6  msaitoh 	 * - link is not up.
   4265   1.6  msaitoh 	 */
   4266   1.6  msaitoh 	if (hw->fc.disable_fc_autoneg) {
   4267   1.6  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_UNSUPPORTED,
   4268   1.6  msaitoh 			     "Flow control autoneg is disabled");
   4269   1.6  msaitoh 		goto out;
   4270   1.6  msaitoh 	}
   4271   1.6  msaitoh 
   4272   1.6  msaitoh 	hw->mac.ops.check_link(hw, &speed, &link_up, FALSE);
   4273   1.6  msaitoh 	if (!link_up) {
   4274   1.6  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_SOFTWARE, "The link is down");
   4275   1.6  msaitoh 		goto out;
   4276   1.6  msaitoh 	}
   4277   1.6  msaitoh 
   4278   1.6  msaitoh 	/* Check if auto-negotiation has completed */
   4279   1.6  msaitoh 	status = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_GET_LINK_INFO, &info);
   4280   1.6  msaitoh 	if (status != IXGBE_SUCCESS ||
   4281   1.6  msaitoh 	    !(info[0] & FW_PHY_ACT_GET_LINK_INFO_AN_COMPLETE)) {
   4282   1.6  msaitoh 		DEBUGOUT("Auto-Negotiation did not complete\n");
   4283   1.6  msaitoh 		status = IXGBE_ERR_FC_NOT_NEGOTIATED;
   4284   1.6  msaitoh 		goto out;
   4285   1.6  msaitoh 	}
   4286   1.6  msaitoh 
   4287   1.6  msaitoh 	/* Negotiate the flow control */
   4288   1.6  msaitoh 	status = ixgbe_negotiate_fc(hw, info[0], info[0],
   4289   1.6  msaitoh 				    FW_PHY_ACT_GET_LINK_INFO_FC_RX,
   4290   1.6  msaitoh 				    FW_PHY_ACT_GET_LINK_INFO_FC_TX,
   4291   1.6  msaitoh 				    FW_PHY_ACT_GET_LINK_INFO_LP_FC_RX,
   4292   1.6  msaitoh 				    FW_PHY_ACT_GET_LINK_INFO_LP_FC_TX);
   4293   1.6  msaitoh 
   4294   1.6  msaitoh out:
   4295   1.6  msaitoh 	if (status == IXGBE_SUCCESS) {
   4296   1.6  msaitoh 		hw->fc.fc_was_autonegged = TRUE;
   4297   1.6  msaitoh 	} else {
   4298   1.6  msaitoh 		hw->fc.fc_was_autonegged = FALSE;
   4299   1.6  msaitoh 		hw->fc.current_mode = hw->fc.requested_mode;
   4300   1.6  msaitoh 	}
   4301   1.6  msaitoh }
   4302   1.6  msaitoh 
   4303   1.6  msaitoh /**
   4304   1.6  msaitoh  *  ixgbe_setup_fc_backplane_x550em_a - Set up flow control
   4305   1.6  msaitoh  *  @hw: pointer to hardware structure
   4306   1.6  msaitoh  *
   4307   1.6  msaitoh  *  Called at init time to set up flow control.
   4308   1.6  msaitoh  **/
   4309   1.6  msaitoh s32 ixgbe_setup_fc_backplane_x550em_a(struct ixgbe_hw *hw)
   4310   1.6  msaitoh {
   4311   1.6  msaitoh 	s32 status = IXGBE_SUCCESS;
   4312   1.6  msaitoh 	u32 an_cntl = 0;
   4313   1.6  msaitoh 
   4314   1.6  msaitoh 	DEBUGFUNC("ixgbe_setup_fc_backplane_x550em_a");
   4315   1.6  msaitoh 
   4316   1.6  msaitoh 	/* Validate the requested mode */
   4317   1.6  msaitoh 	if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
   4318   1.6  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_UNSUPPORTED,
   4319   1.6  msaitoh 			      "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
   4320   1.6  msaitoh 		return IXGBE_ERR_INVALID_LINK_SETTINGS;
   4321   1.6  msaitoh 	}
   4322   1.6  msaitoh 
   4323   1.6  msaitoh 	if (hw->fc.requested_mode == ixgbe_fc_default)
   4324   1.6  msaitoh 		hw->fc.requested_mode = ixgbe_fc_full;
   4325   1.6  msaitoh 
   4326   1.6  msaitoh 	/* Set up the 1G and 10G flow control advertisement registers so the
   4327   1.6  msaitoh 	 * HW will be able to do FC autoneg once the cable is plugged in.  If
   4328   1.6  msaitoh 	 * we link at 10G, the 1G advertisement is harmless and vice versa.
   4329   1.6  msaitoh 	 */
   4330   1.6  msaitoh 	status = hw->mac.ops.read_iosf_sb_reg(hw,
   4331   1.6  msaitoh 					IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
   4332   1.6  msaitoh 					IXGBE_SB_IOSF_TARGET_KR_PHY, &an_cntl);
   4333   1.6  msaitoh 
   4334   1.6  msaitoh 	if (status != IXGBE_SUCCESS) {
   4335   1.6  msaitoh 		DEBUGOUT("Auto-Negotiation did not complete\n");
   4336   1.6  msaitoh 		return status;
   4337   1.6  msaitoh 	}
   4338   1.6  msaitoh 
   4339   1.6  msaitoh 	/* The possible values of fc.requested_mode are:
   4340   1.6  msaitoh 	 * 0: Flow control is completely disabled
   4341   1.6  msaitoh 	 * 1: Rx flow control is enabled (we can receive pause frames,
   4342   1.6  msaitoh 	 *    but not send pause frames).
   4343   1.6  msaitoh 	 * 2: Tx flow control is enabled (we can send pause frames but
   4344   1.6  msaitoh 	 *    we do not support receiving pause frames).
   4345   1.6  msaitoh 	 * 3: Both Rx and Tx flow control (symmetric) are enabled.
   4346   1.6  msaitoh 	 * other: Invalid.
   4347   1.6  msaitoh 	 */
   4348   1.6  msaitoh 	switch (hw->fc.requested_mode) {
   4349   1.6  msaitoh 	case ixgbe_fc_none:
   4350   1.6  msaitoh 		/* Flow control completely disabled by software override. */
   4351   1.6  msaitoh 		an_cntl &= ~(IXGBE_KRM_AN_CNTL_1_SYM_PAUSE |
   4352   1.6  msaitoh 			     IXGBE_KRM_AN_CNTL_1_ASM_PAUSE);
   4353   1.6  msaitoh 		break;
   4354   1.6  msaitoh 	case ixgbe_fc_tx_pause:
   4355   1.6  msaitoh 		/* Tx Flow control is enabled, and Rx Flow control is
   4356   1.6  msaitoh 		 * disabled by software override.
   4357   1.6  msaitoh 		 */
   4358   1.6  msaitoh 		an_cntl |= IXGBE_KRM_AN_CNTL_1_ASM_PAUSE;
   4359   1.6  msaitoh 		an_cntl &= ~IXGBE_KRM_AN_CNTL_1_SYM_PAUSE;
   4360   1.6  msaitoh 		break;
   4361   1.6  msaitoh 	case ixgbe_fc_rx_pause:
   4362   1.6  msaitoh 		/* Rx Flow control is enabled and Tx Flow control is
   4363   1.6  msaitoh 		 * disabled by software override. Since there really
   4364   1.6  msaitoh 		 * isn't a way to advertise that we are capable of RX
   4365   1.6  msaitoh 		 * Pause ONLY, we will advertise that we support both
   4366   1.6  msaitoh 		 * symmetric and asymmetric Rx PAUSE, as such we fall
   4367   1.6  msaitoh 		 * through to the fc_full statement.  Later, we will
   4368   1.6  msaitoh 		 * disable the adapter's ability to send PAUSE frames.
   4369   1.6  msaitoh 		 */
   4370   1.6  msaitoh 	case ixgbe_fc_full:
   4371   1.6  msaitoh 		/* Flow control (both Rx and Tx) is enabled by SW override. */
   4372   1.6  msaitoh 		an_cntl |= IXGBE_KRM_AN_CNTL_1_SYM_PAUSE |
   4373   1.6  msaitoh 			   IXGBE_KRM_AN_CNTL_1_ASM_PAUSE;
   4374   1.6  msaitoh 		break;
   4375   1.6  msaitoh 	default:
   4376   1.6  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_ARGUMENT,
   4377   1.6  msaitoh 			      "Flow control param set incorrectly\n");
   4378   1.6  msaitoh 		return IXGBE_ERR_CONFIG;
   4379   1.6  msaitoh 	}
   4380   1.6  msaitoh 
   4381   1.6  msaitoh 	status = hw->mac.ops.write_iosf_sb_reg(hw,
   4382   1.6  msaitoh 					IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
   4383   1.6  msaitoh 					IXGBE_SB_IOSF_TARGET_KR_PHY, an_cntl);
   4384   1.6  msaitoh 
   4385   1.6  msaitoh 	/* Restart auto-negotiation. */
   4386   1.6  msaitoh 	status = ixgbe_restart_an_internal_phy_x550em(hw);
   4387   1.6  msaitoh 
   4388   1.6  msaitoh 	return status;
   4389   1.6  msaitoh }
   4390   1.6  msaitoh 
   4391   1.6  msaitoh /**
   4392   1.1  msaitoh  * ixgbe_set_mux - Set mux for port 1 access with CS4227
   4393   1.1  msaitoh  * @hw: pointer to hardware structure
   4394   1.1  msaitoh  * @state: set mux if 1, clear if 0
   4395   1.1  msaitoh  */
   4396   1.1  msaitoh static void ixgbe_set_mux(struct ixgbe_hw *hw, u8 state)
   4397   1.1  msaitoh {
   4398   1.1  msaitoh 	u32 esdp;
   4399   1.1  msaitoh 
   4400   1.1  msaitoh 	if (!hw->bus.lan_id)
   4401   1.1  msaitoh 		return;
   4402   1.1  msaitoh 	esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
   4403   1.1  msaitoh 	if (state)
   4404   1.1  msaitoh 		esdp |= IXGBE_ESDP_SDP1;
   4405   1.1  msaitoh 	else
   4406   1.1  msaitoh 		esdp &= ~IXGBE_ESDP_SDP1;
   4407   1.1  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
   4408   1.1  msaitoh 	IXGBE_WRITE_FLUSH(hw);
   4409   1.1  msaitoh }
   4410   1.1  msaitoh 
   4411   1.1  msaitoh /**
   4412   1.1  msaitoh  *  ixgbe_acquire_swfw_sync_X550em - Acquire SWFW semaphore
   4413   1.1  msaitoh  *  @hw: pointer to hardware structure
   4414   1.1  msaitoh  *  @mask: Mask to specify which semaphore to acquire
   4415   1.1  msaitoh  *
   4416   1.1  msaitoh  *  Acquires the SWFW semaphore and sets the I2C MUX
   4417   1.1  msaitoh  **/
   4418   1.1  msaitoh s32 ixgbe_acquire_swfw_sync_X550em(struct ixgbe_hw *hw, u32 mask)
   4419   1.1  msaitoh {
   4420   1.1  msaitoh 	s32 status;
   4421   1.1  msaitoh 
   4422   1.1  msaitoh 	DEBUGFUNC("ixgbe_acquire_swfw_sync_X550em");
   4423   1.1  msaitoh 
   4424   1.1  msaitoh 	status = ixgbe_acquire_swfw_sync_X540(hw, mask);
   4425   1.1  msaitoh 	if (status)
   4426   1.1  msaitoh 		return status;
   4427   1.1  msaitoh 
   4428   1.1  msaitoh 	if (mask & IXGBE_GSSR_I2C_MASK)
   4429   1.1  msaitoh 		ixgbe_set_mux(hw, 1);
   4430   1.1  msaitoh 
   4431   1.1  msaitoh 	return IXGBE_SUCCESS;
   4432   1.1  msaitoh }
   4433   1.1  msaitoh 
   4434   1.1  msaitoh /**
   4435   1.1  msaitoh  *  ixgbe_release_swfw_sync_X550em - Release SWFW semaphore
   4436   1.1  msaitoh  *  @hw: pointer to hardware structure
   4437   1.1  msaitoh  *  @mask: Mask to specify which semaphore to release
   4438   1.1  msaitoh  *
   4439   1.1  msaitoh  *  Releases the SWFW semaphore and sets the I2C MUX
   4440   1.1  msaitoh  **/
   4441   1.1  msaitoh void ixgbe_release_swfw_sync_X550em(struct ixgbe_hw *hw, u32 mask)
   4442   1.1  msaitoh {
   4443   1.1  msaitoh 	DEBUGFUNC("ixgbe_release_swfw_sync_X550em");
   4444   1.1  msaitoh 
   4445   1.1  msaitoh 	if (mask & IXGBE_GSSR_I2C_MASK)
   4446   1.1  msaitoh 		ixgbe_set_mux(hw, 0);
   4447   1.1  msaitoh 
   4448   1.1  msaitoh 	ixgbe_release_swfw_sync_X540(hw, mask);
   4449   1.1  msaitoh }
   4450   1.1  msaitoh 
   4451   1.1  msaitoh /**
   4452   1.6  msaitoh  *  ixgbe_acquire_swfw_sync_X550a - Acquire SWFW semaphore
   4453   1.6  msaitoh  *  @hw: pointer to hardware structure
   4454   1.6  msaitoh  *  @mask: Mask to specify which semaphore to acquire
   4455   1.6  msaitoh  *
   4456   1.6  msaitoh  *  Acquires the SWFW semaphore and get the shared phy token as needed
   4457   1.6  msaitoh  */
   4458   1.6  msaitoh static s32 ixgbe_acquire_swfw_sync_X550a(struct ixgbe_hw *hw, u32 mask)
   4459   1.6  msaitoh {
   4460   1.6  msaitoh 	u32 hmask = mask & ~IXGBE_GSSR_TOKEN_SM;
   4461   1.6  msaitoh 	int retries = FW_PHY_TOKEN_RETRIES;
   4462   1.6  msaitoh 	s32 status = IXGBE_SUCCESS;
   4463   1.6  msaitoh 
   4464   1.6  msaitoh 	DEBUGFUNC("ixgbe_acquire_swfw_sync_X550a");
   4465   1.6  msaitoh 
   4466   1.6  msaitoh 	while (--retries) {
   4467   1.6  msaitoh 		status = IXGBE_SUCCESS;
   4468   1.6  msaitoh 		if (hmask)
   4469   1.6  msaitoh 			status = ixgbe_acquire_swfw_sync_X540(hw, hmask);
   4470   1.6  msaitoh 		if (status) {
   4471   1.6  msaitoh 			DEBUGOUT1("Could not acquire SWFW semaphore, Status = %d\n",
   4472   1.6  msaitoh 				  status);
   4473   1.6  msaitoh 			return status;
   4474   1.6  msaitoh 		}
   4475   1.6  msaitoh 		if (!(mask & IXGBE_GSSR_TOKEN_SM))
   4476   1.6  msaitoh 			return IXGBE_SUCCESS;
   4477   1.6  msaitoh 
   4478   1.6  msaitoh 		status = ixgbe_get_phy_token(hw);
   4479   1.6  msaitoh 		if (status == IXGBE_ERR_TOKEN_RETRY)
   4480   1.6  msaitoh 			DEBUGOUT1("Could not acquire PHY token, Status = %d\n",
   4481   1.6  msaitoh 				  status);
   4482   1.6  msaitoh 
   4483   1.6  msaitoh 		if (status == IXGBE_SUCCESS)
   4484   1.6  msaitoh 			return IXGBE_SUCCESS;
   4485   1.6  msaitoh 
   4486   1.6  msaitoh 		if (hmask)
   4487   1.6  msaitoh 			ixgbe_release_swfw_sync_X540(hw, hmask);
   4488   1.6  msaitoh 
   4489   1.6  msaitoh 		if (status != IXGBE_ERR_TOKEN_RETRY) {
   4490   1.6  msaitoh 			DEBUGOUT1("Unable to retry acquiring the PHY token, Status = %d\n",
   4491   1.6  msaitoh 				  status);
   4492   1.6  msaitoh 			return status;
   4493   1.6  msaitoh 		}
   4494   1.6  msaitoh 	}
   4495   1.6  msaitoh 
   4496   1.6  msaitoh 	DEBUGOUT1("Semaphore acquisition retries failed!: PHY ID = 0x%08X\n",
   4497   1.6  msaitoh 		  hw->phy.id);
   4498   1.6  msaitoh 	return status;
   4499   1.6  msaitoh }
   4500   1.6  msaitoh 
   4501   1.6  msaitoh /**
   4502   1.6  msaitoh  *  ixgbe_release_swfw_sync_X550a - Release SWFW semaphore
   4503   1.6  msaitoh  *  @hw: pointer to hardware structure
   4504   1.6  msaitoh  *  @mask: Mask to specify which semaphore to release
   4505   1.6  msaitoh  *
   4506   1.6  msaitoh  *  Releases the SWFW semaphore and puts the shared phy token as needed
   4507   1.6  msaitoh  */
   4508   1.6  msaitoh static void ixgbe_release_swfw_sync_X550a(struct ixgbe_hw *hw, u32 mask)
   4509   1.6  msaitoh {
   4510   1.6  msaitoh 	u32 hmask = mask & ~IXGBE_GSSR_TOKEN_SM;
   4511   1.6  msaitoh 
   4512   1.6  msaitoh 	DEBUGFUNC("ixgbe_release_swfw_sync_X550a");
   4513   1.6  msaitoh 
   4514   1.6  msaitoh 	if (mask & IXGBE_GSSR_TOKEN_SM)
   4515   1.6  msaitoh 		ixgbe_put_phy_token(hw);
   4516   1.6  msaitoh 
   4517   1.6  msaitoh 	if (hmask)
   4518   1.6  msaitoh 		ixgbe_release_swfw_sync_X540(hw, hmask);
   4519   1.6  msaitoh }
   4520   1.6  msaitoh 
   4521   1.6  msaitoh /**
   4522   1.6  msaitoh  *  ixgbe_read_phy_reg_x550a  - Reads specified PHY register
   4523   1.6  msaitoh  *  @hw: pointer to hardware structure
   4524   1.6  msaitoh  *  @reg_addr: 32 bit address of PHY register to read
   4525  1.12  msaitoh  *  @device_type: 5 bit device type
   4526   1.6  msaitoh  *  @phy_data: Pointer to read data from PHY register
   4527   1.6  msaitoh  *
   4528   1.6  msaitoh  *  Reads a value from a specified PHY register using the SWFW lock and PHY
   4529   1.6  msaitoh  *  Token. The PHY Token is needed since the MDIO is shared between to MAC
   4530   1.6  msaitoh  *  instances.
   4531   1.6  msaitoh  **/
   4532   1.6  msaitoh s32 ixgbe_read_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
   4533   1.6  msaitoh 			       u32 device_type, u16 *phy_data)
   4534   1.6  msaitoh {
   4535   1.6  msaitoh 	s32 status;
   4536   1.6  msaitoh 	u32 mask = hw->phy.phy_semaphore_mask | IXGBE_GSSR_TOKEN_SM;
   4537   1.6  msaitoh 
   4538   1.6  msaitoh 	DEBUGFUNC("ixgbe_read_phy_reg_x550a");
   4539   1.6  msaitoh 
   4540   1.6  msaitoh 	if (hw->mac.ops.acquire_swfw_sync(hw, mask))
   4541   1.6  msaitoh 		return IXGBE_ERR_SWFW_SYNC;
   4542   1.6  msaitoh 
   4543   1.6  msaitoh 	status = hw->phy.ops.read_reg_mdi(hw, reg_addr, device_type, phy_data);
   4544   1.6  msaitoh 
   4545   1.6  msaitoh 	hw->mac.ops.release_swfw_sync(hw, mask);
   4546   1.6  msaitoh 
   4547   1.6  msaitoh 	return status;
   4548   1.6  msaitoh }
   4549   1.6  msaitoh 
   4550   1.6  msaitoh /**
   4551   1.6  msaitoh  *  ixgbe_write_phy_reg_x550a - Writes specified PHY register
   4552   1.6  msaitoh  *  @hw: pointer to hardware structure
   4553   1.6  msaitoh  *  @reg_addr: 32 bit PHY register to write
   4554   1.6  msaitoh  *  @device_type: 5 bit device type
   4555   1.6  msaitoh  *  @phy_data: Data to write to the PHY register
   4556   1.6  msaitoh  *
   4557   1.6  msaitoh  *  Writes a value to specified PHY register using the SWFW lock and PHY Token.
   4558   1.6  msaitoh  *  The PHY Token is needed since the MDIO is shared between to MAC instances.
   4559   1.6  msaitoh  **/
   4560   1.6  msaitoh s32 ixgbe_write_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
   4561   1.6  msaitoh 				u32 device_type, u16 phy_data)
   4562   1.6  msaitoh {
   4563   1.6  msaitoh 	s32 status;
   4564   1.6  msaitoh 	u32 mask = hw->phy.phy_semaphore_mask | IXGBE_GSSR_TOKEN_SM;
   4565   1.6  msaitoh 
   4566   1.6  msaitoh 	DEBUGFUNC("ixgbe_write_phy_reg_x550a");
   4567   1.6  msaitoh 
   4568   1.6  msaitoh 	if (hw->mac.ops.acquire_swfw_sync(hw, mask) == IXGBE_SUCCESS) {
   4569   1.6  msaitoh 		status = hw->phy.ops.write_reg_mdi(hw, reg_addr, device_type,
   4570   1.6  msaitoh 						 phy_data);
   4571   1.6  msaitoh 		hw->mac.ops.release_swfw_sync(hw, mask);
   4572   1.6  msaitoh 	} else {
   4573   1.6  msaitoh 		status = IXGBE_ERR_SWFW_SYNC;
   4574   1.6  msaitoh 	}
   4575   1.6  msaitoh 
   4576   1.6  msaitoh 	return status;
   4577   1.6  msaitoh }
   4578   1.6  msaitoh 
   4579   1.6  msaitoh /**
   4580   1.1  msaitoh  * ixgbe_handle_lasi_ext_t_x550em - Handle external Base T PHY interrupt
   4581   1.1  msaitoh  * @hw: pointer to hardware structure
   4582   1.1  msaitoh  *
   4583   1.1  msaitoh  * Handle external Base T PHY interrupt. If high temperature
   4584   1.1  msaitoh  * failure alarm then return error, else if link status change
   4585   1.1  msaitoh  * then setup internal/external PHY link
   4586   1.1  msaitoh  *
   4587   1.1  msaitoh  * Return IXGBE_ERR_OVERTEMP if interrupt is high temperature
   4588   1.1  msaitoh  * failure alarm, else return PHY access status.
   4589   1.1  msaitoh  */
   4590   1.1  msaitoh s32 ixgbe_handle_lasi_ext_t_x550em(struct ixgbe_hw *hw)
   4591   1.1  msaitoh {
   4592   1.1  msaitoh 	bool lsc;
   4593   1.1  msaitoh 	u32 status;
   4594   1.1  msaitoh 
   4595   1.1  msaitoh 	status = ixgbe_get_lasi_ext_t_x550em(hw, &lsc);
   4596   1.1  msaitoh 
   4597   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   4598   1.1  msaitoh 		return status;
   4599   1.1  msaitoh 
   4600   1.1  msaitoh 	if (lsc)
   4601   1.1  msaitoh 		return ixgbe_setup_internal_phy(hw);
   4602   1.1  msaitoh 
   4603   1.1  msaitoh 	return IXGBE_SUCCESS;
   4604   1.1  msaitoh }
   4605   1.1  msaitoh 
   4606   1.1  msaitoh /**
   4607   1.1  msaitoh  * ixgbe_setup_mac_link_t_X550em - Sets the auto advertised link speed
   4608   1.1  msaitoh  * @hw: pointer to hardware structure
   4609   1.1  msaitoh  * @speed: new link speed
   4610   1.1  msaitoh  * @autoneg_wait_to_complete: TRUE when waiting for completion is needed
   4611   1.1  msaitoh  *
   4612   1.1  msaitoh  * Setup internal/external PHY link speed based on link speed, then set
   4613   1.1  msaitoh  * external PHY auto advertised link speed.
   4614   1.1  msaitoh  *
   4615   1.1  msaitoh  * Returns error status for any failure
   4616   1.1  msaitoh  **/
   4617   1.1  msaitoh s32 ixgbe_setup_mac_link_t_X550em(struct ixgbe_hw *hw,
   4618   1.1  msaitoh 				  ixgbe_link_speed speed,
   4619   1.1  msaitoh 				  bool autoneg_wait_to_complete)
   4620   1.1  msaitoh {
   4621   1.1  msaitoh 	s32 status;
   4622   1.1  msaitoh 	ixgbe_link_speed force_speed;
   4623   1.1  msaitoh 
   4624   1.1  msaitoh 	DEBUGFUNC("ixgbe_setup_mac_link_t_X550em");
   4625   1.1  msaitoh 
   4626   1.1  msaitoh 	/* Setup internal/external PHY link speed to iXFI (10G), unless
   4627   1.1  msaitoh 	 * only 1G is auto advertised then setup KX link.
   4628   1.1  msaitoh 	 */
   4629   1.1  msaitoh 	if (speed & IXGBE_LINK_SPEED_10GB_FULL)
   4630   1.1  msaitoh 		force_speed = IXGBE_LINK_SPEED_10GB_FULL;
   4631   1.1  msaitoh 	else
   4632   1.1  msaitoh 		force_speed = IXGBE_LINK_SPEED_1GB_FULL;
   4633   1.1  msaitoh 
   4634   1.6  msaitoh 	/* If X552 and internal link mode is XFI, then setup XFI internal link.
   4635   1.6  msaitoh 	 */
   4636   1.6  msaitoh 	if (hw->mac.type == ixgbe_mac_X550EM_x &&
   4637   1.6  msaitoh 	    !(hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE)) {
   4638   1.1  msaitoh 		status = ixgbe_setup_ixfi_x550em(hw, &force_speed);
   4639   1.1  msaitoh 
   4640   1.1  msaitoh 		if (status != IXGBE_SUCCESS)
   4641   1.1  msaitoh 			return status;
   4642   1.1  msaitoh 	}
   4643   1.1  msaitoh 
   4644   1.1  msaitoh 	return hw->phy.ops.setup_link_speed(hw, speed, autoneg_wait_to_complete);
   4645   1.1  msaitoh }
   4646   1.1  msaitoh 
   4647   1.1  msaitoh /**
   4648   1.1  msaitoh  * ixgbe_check_link_t_X550em - Determine link and speed status
   4649   1.1  msaitoh  * @hw: pointer to hardware structure
   4650   1.1  msaitoh  * @speed: pointer to link speed
   4651   1.1  msaitoh  * @link_up: TRUE when link is up
   4652   1.1  msaitoh  * @link_up_wait_to_complete: bool used to wait for link up or not
   4653   1.1  msaitoh  *
   4654   1.1  msaitoh  * Check that both the MAC and X557 external PHY have link.
   4655   1.1  msaitoh  **/
   4656   1.1  msaitoh s32 ixgbe_check_link_t_X550em(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
   4657   1.1  msaitoh 			      bool *link_up, bool link_up_wait_to_complete)
   4658   1.1  msaitoh {
   4659   1.1  msaitoh 	u32 status;
   4660   1.6  msaitoh 	u16 i, autoneg_status = 0;
   4661   1.1  msaitoh 
   4662   1.1  msaitoh 	if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
   4663   1.1  msaitoh 		return IXGBE_ERR_CONFIG;
   4664   1.1  msaitoh 
   4665   1.1  msaitoh 	status = ixgbe_check_mac_link_generic(hw, speed, link_up,
   4666   1.1  msaitoh 					      link_up_wait_to_complete);
   4667   1.1  msaitoh 
   4668   1.1  msaitoh 	/* If check link fails or MAC link is not up, then return */
   4669   1.1  msaitoh 	if (status != IXGBE_SUCCESS || !(*link_up))
   4670   1.1  msaitoh 		return status;
   4671   1.1  msaitoh 
   4672   1.1  msaitoh 	/* MAC link is up, so check external PHY link.
   4673   1.6  msaitoh 	 * X557 PHY. Link status is latching low, and can only be used to detect
   4674   1.6  msaitoh 	 * link drop, and not the current status of the link without performing
   4675   1.6  msaitoh 	 * back-to-back reads.
   4676   1.1  msaitoh 	 */
   4677   1.6  msaitoh 	for (i = 0; i < 2; i++) {
   4678   1.6  msaitoh 		status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
   4679   1.1  msaitoh 				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
   4680   1.1  msaitoh 				      &autoneg_status);
   4681   1.1  msaitoh 
   4682   1.6  msaitoh 		if (status != IXGBE_SUCCESS)
   4683   1.6  msaitoh 			return status;
   4684   1.6  msaitoh 	}
   4685   1.1  msaitoh 
   4686   1.1  msaitoh 	/* If external PHY link is not up, then indicate link not up */
   4687   1.1  msaitoh 	if (!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS))
   4688   1.1  msaitoh 		*link_up = FALSE;
   4689   1.1  msaitoh 
   4690   1.1  msaitoh 	return IXGBE_SUCCESS;
   4691   1.1  msaitoh }
   4692   1.1  msaitoh 
   4693   1.1  msaitoh /**
   4694   1.1  msaitoh  *  ixgbe_reset_phy_t_X550em - Performs X557 PHY reset and enables LASI
   4695   1.1  msaitoh  *  @hw: pointer to hardware structure
   4696   1.1  msaitoh  **/
   4697   1.1  msaitoh s32 ixgbe_reset_phy_t_X550em(struct ixgbe_hw *hw)
   4698   1.1  msaitoh {
   4699   1.1  msaitoh 	s32 status;
   4700   1.1  msaitoh 
   4701   1.1  msaitoh 	status = ixgbe_reset_phy_generic(hw);
   4702   1.1  msaitoh 
   4703   1.1  msaitoh 	if (status != IXGBE_SUCCESS)
   4704   1.1  msaitoh 		return status;
   4705   1.1  msaitoh 
   4706   1.1  msaitoh 	/* Configure Link Status Alarm and Temperature Threshold interrupts */
   4707   1.1  msaitoh 	return ixgbe_enable_lasi_ext_t_x550em(hw);
   4708   1.1  msaitoh }
   4709   1.1  msaitoh 
   4710   1.1  msaitoh /**
   4711   1.1  msaitoh  *  ixgbe_led_on_t_X550em - Turns on the software controllable LEDs.
   4712   1.1  msaitoh  *  @hw: pointer to hardware structure
   4713   1.1  msaitoh  *  @led_idx: led number to turn on
   4714   1.1  msaitoh  **/
   4715   1.1  msaitoh s32 ixgbe_led_on_t_X550em(struct ixgbe_hw *hw, u32 led_idx)
   4716   1.1  msaitoh {
   4717   1.1  msaitoh 	u16 phy_data;
   4718   1.1  msaitoh 
   4719   1.1  msaitoh 	DEBUGFUNC("ixgbe_led_on_t_X550em");
   4720   1.1  msaitoh 
   4721   1.1  msaitoh 	if (led_idx >= IXGBE_X557_MAX_LED_INDEX)
   4722   1.1  msaitoh 		return IXGBE_ERR_PARAM;
   4723   1.1  msaitoh 
   4724   1.1  msaitoh 	/* To turn on the LED, set mode to ON. */
   4725   1.1  msaitoh 	ixgbe_read_phy_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
   4726   1.1  msaitoh 			   IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, &phy_data);
   4727   1.1  msaitoh 	phy_data |= IXGBE_X557_LED_MANUAL_SET_MASK;
   4728   1.1  msaitoh 	ixgbe_write_phy_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
   4729   1.1  msaitoh 			    IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, phy_data);
   4730   1.1  msaitoh 
   4731   1.6  msaitoh 	/* Some designs have the LEDs wired to the MAC */
   4732   1.6  msaitoh 	return ixgbe_led_on_generic(hw, led_idx);
   4733   1.1  msaitoh }
   4734   1.1  msaitoh 
   4735   1.1  msaitoh /**
   4736   1.1  msaitoh  *  ixgbe_led_off_t_X550em - Turns off the software controllable LEDs.
   4737   1.1  msaitoh  *  @hw: pointer to hardware structure
   4738   1.1  msaitoh  *  @led_idx: led number to turn off
   4739   1.1  msaitoh  **/
   4740   1.1  msaitoh s32 ixgbe_led_off_t_X550em(struct ixgbe_hw *hw, u32 led_idx)
   4741   1.1  msaitoh {
   4742   1.1  msaitoh 	u16 phy_data;
   4743   1.1  msaitoh 
   4744   1.1  msaitoh 	DEBUGFUNC("ixgbe_led_off_t_X550em");
   4745   1.1  msaitoh 
   4746   1.1  msaitoh 	if (led_idx >= IXGBE_X557_MAX_LED_INDEX)
   4747   1.1  msaitoh 		return IXGBE_ERR_PARAM;
   4748   1.1  msaitoh 
   4749   1.1  msaitoh 	/* To turn on the LED, set mode to ON. */
   4750   1.1  msaitoh 	ixgbe_read_phy_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
   4751   1.1  msaitoh 			   IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, &phy_data);
   4752   1.1  msaitoh 	phy_data &= ~IXGBE_X557_LED_MANUAL_SET_MASK;
   4753   1.1  msaitoh 	ixgbe_write_phy_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
   4754   1.1  msaitoh 			    IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, phy_data);
   4755   1.1  msaitoh 
   4756   1.6  msaitoh 	/* Some designs have the LEDs wired to the MAC */
   4757   1.6  msaitoh 	return ixgbe_led_off_generic(hw, led_idx);
   4758   1.1  msaitoh }
   4759   1.1  msaitoh 
   4760   1.6  msaitoh /**
   4761   1.6  msaitoh  *  ixgbe_set_fw_drv_ver_x550 - Sends driver version to firmware
   4762   1.6  msaitoh  *  @hw: pointer to the HW structure
   4763   1.6  msaitoh  *  @maj: driver version major number
   4764   1.6  msaitoh  *  @min: driver version minor number
   4765   1.6  msaitoh  *  @build: driver version build number
   4766   1.6  msaitoh  *  @sub: driver version sub build number
   4767   1.6  msaitoh  *  @len: length of driver_ver string
   4768   1.6  msaitoh  *  @driver_ver: driver string
   4769   1.6  msaitoh  *
   4770   1.6  msaitoh  *  Sends driver version number to firmware through the manageability
   4771   1.6  msaitoh  *  block.  On success return IXGBE_SUCCESS
   4772   1.6  msaitoh  *  else returns IXGBE_ERR_SWFW_SYNC when encountering an error acquiring
   4773   1.6  msaitoh  *  semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
   4774   1.6  msaitoh  **/
   4775   1.6  msaitoh s32 ixgbe_set_fw_drv_ver_x550(struct ixgbe_hw *hw, u8 maj, u8 min,
   4776   1.6  msaitoh 			      u8 build, u8 sub, u16 len, const char *driver_ver)
   4777   1.6  msaitoh {
   4778   1.6  msaitoh 	struct ixgbe_hic_drv_info2 fw_cmd;
   4779   1.6  msaitoh 	s32 ret_val = IXGBE_SUCCESS;
   4780   1.6  msaitoh 	int i;
   4781   1.6  msaitoh 
   4782   1.6  msaitoh 	DEBUGFUNC("ixgbe_set_fw_drv_ver_x550");
   4783   1.6  msaitoh 
   4784   1.6  msaitoh 	if ((len == 0) || (driver_ver == NULL) ||
   4785   1.6  msaitoh 	   (len > sizeof(fw_cmd.driver_string)))
   4786   1.6  msaitoh 		return IXGBE_ERR_INVALID_ARGUMENT;
   4787   1.6  msaitoh 
   4788   1.6  msaitoh 	fw_cmd.hdr.cmd = FW_CEM_CMD_DRIVER_INFO;
   4789   1.6  msaitoh 	fw_cmd.hdr.buf_len = FW_CEM_CMD_DRIVER_INFO_LEN + len;
   4790   1.6  msaitoh 	fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED;
   4791   1.6  msaitoh 	fw_cmd.port_num = (u8)hw->bus.func;
   4792   1.6  msaitoh 	fw_cmd.ver_maj = maj;
   4793   1.6  msaitoh 	fw_cmd.ver_min = min;
   4794   1.6  msaitoh 	fw_cmd.ver_build = build;
   4795   1.6  msaitoh 	fw_cmd.ver_sub = sub;
   4796   1.6  msaitoh 	fw_cmd.hdr.checksum = 0;
   4797   1.6  msaitoh 	memcpy(fw_cmd.driver_string, driver_ver, len);
   4798   1.6  msaitoh 	fw_cmd.hdr.checksum = ixgbe_calculate_checksum((u8 *)&fw_cmd,
   4799   1.6  msaitoh 				(FW_CEM_HDR_LEN + fw_cmd.hdr.buf_len));
   4800   1.6  msaitoh 
   4801   1.6  msaitoh 	for (i = 0; i <= FW_CEM_MAX_RETRIES; i++) {
   4802   1.6  msaitoh 		ret_val = ixgbe_host_interface_command(hw, (u32 *)&fw_cmd,
   4803   1.6  msaitoh 						       sizeof(fw_cmd),
   4804   1.6  msaitoh 						       IXGBE_HI_COMMAND_TIMEOUT,
   4805   1.6  msaitoh 						       TRUE);
   4806   1.6  msaitoh 		if (ret_val != IXGBE_SUCCESS)
   4807   1.6  msaitoh 			continue;
   4808   1.6  msaitoh 
   4809   1.6  msaitoh 		if (fw_cmd.hdr.cmd_or_resp.ret_status ==
   4810   1.6  msaitoh 		    FW_CEM_RESP_STATUS_SUCCESS)
   4811   1.6  msaitoh 			ret_val = IXGBE_SUCCESS;
   4812   1.6  msaitoh 		else
   4813   1.6  msaitoh 			ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
   4814   1.6  msaitoh 
   4815   1.6  msaitoh 		break;
   4816   1.6  msaitoh 	}
   4817   1.6  msaitoh 
   4818   1.6  msaitoh 	return ret_val;
   4819   1.6  msaitoh }
   4820