18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/* Copyright(c) 2007 - 2018 Intel Corporation. */
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci/* e1000_82575
58c2ecf20Sopenharmony_ci * e1000_82576
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/types.h>
118c2ecf20Sopenharmony_ci#include <linux/if_ether.h>
128c2ecf20Sopenharmony_ci#include <linux/i2c.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include "e1000_mac.h"
158c2ecf20Sopenharmony_ci#include "e1000_82575.h"
168c2ecf20Sopenharmony_ci#include "e1000_i210.h"
178c2ecf20Sopenharmony_ci#include "igb.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistatic s32  igb_get_invariants_82575(struct e1000_hw *);
208c2ecf20Sopenharmony_cistatic s32  igb_acquire_phy_82575(struct e1000_hw *);
218c2ecf20Sopenharmony_cistatic void igb_release_phy_82575(struct e1000_hw *);
228c2ecf20Sopenharmony_cistatic s32  igb_acquire_nvm_82575(struct e1000_hw *);
238c2ecf20Sopenharmony_cistatic void igb_release_nvm_82575(struct e1000_hw *);
248c2ecf20Sopenharmony_cistatic s32  igb_check_for_link_82575(struct e1000_hw *);
258c2ecf20Sopenharmony_cistatic s32  igb_get_cfg_done_82575(struct e1000_hw *);
268c2ecf20Sopenharmony_cistatic s32  igb_init_hw_82575(struct e1000_hw *);
278c2ecf20Sopenharmony_cistatic s32  igb_phy_hw_reset_sgmii_82575(struct e1000_hw *);
288c2ecf20Sopenharmony_cistatic s32  igb_read_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16 *);
298c2ecf20Sopenharmony_cistatic s32  igb_reset_hw_82575(struct e1000_hw *);
308c2ecf20Sopenharmony_cistatic s32  igb_reset_hw_82580(struct e1000_hw *);
318c2ecf20Sopenharmony_cistatic s32  igb_set_d0_lplu_state_82575(struct e1000_hw *, bool);
328c2ecf20Sopenharmony_cistatic s32  igb_set_d0_lplu_state_82580(struct e1000_hw *, bool);
338c2ecf20Sopenharmony_cistatic s32  igb_set_d3_lplu_state_82580(struct e1000_hw *, bool);
348c2ecf20Sopenharmony_cistatic s32  igb_setup_copper_link_82575(struct e1000_hw *);
358c2ecf20Sopenharmony_cistatic s32  igb_setup_serdes_link_82575(struct e1000_hw *);
368c2ecf20Sopenharmony_cistatic s32  igb_write_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16);
378c2ecf20Sopenharmony_cistatic void igb_clear_hw_cntrs_82575(struct e1000_hw *);
388c2ecf20Sopenharmony_cistatic s32  igb_acquire_swfw_sync_82575(struct e1000_hw *, u16);
398c2ecf20Sopenharmony_cistatic s32  igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *, u16 *,
408c2ecf20Sopenharmony_ci						 u16 *);
418c2ecf20Sopenharmony_cistatic s32  igb_get_phy_id_82575(struct e1000_hw *);
428c2ecf20Sopenharmony_cistatic void igb_release_swfw_sync_82575(struct e1000_hw *, u16);
438c2ecf20Sopenharmony_cistatic bool igb_sgmii_active_82575(struct e1000_hw *);
448c2ecf20Sopenharmony_cistatic s32  igb_reset_init_script_82575(struct e1000_hw *);
458c2ecf20Sopenharmony_cistatic s32  igb_read_mac_addr_82575(struct e1000_hw *);
468c2ecf20Sopenharmony_cistatic s32  igb_set_pcie_completion_timeout(struct e1000_hw *hw);
478c2ecf20Sopenharmony_cistatic s32  igb_reset_mdicnfg_82580(struct e1000_hw *hw);
488c2ecf20Sopenharmony_cistatic s32  igb_validate_nvm_checksum_82580(struct e1000_hw *hw);
498c2ecf20Sopenharmony_cistatic s32  igb_update_nvm_checksum_82580(struct e1000_hw *hw);
508c2ecf20Sopenharmony_cistatic s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw);
518c2ecf20Sopenharmony_cistatic s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw);
528c2ecf20Sopenharmony_cistatic const u16 e1000_82580_rxpbs_table[] = {
538c2ecf20Sopenharmony_ci	36, 72, 144, 1, 2, 4, 8, 16, 35, 70, 140 };
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/* Due to a hw errata, if the host tries to  configure the VFTA register
568c2ecf20Sopenharmony_ci * while performing queries from the BMC or DMA, then the VFTA in some
578c2ecf20Sopenharmony_ci * cases won't be written.
588c2ecf20Sopenharmony_ci */
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/**
618c2ecf20Sopenharmony_ci *  igb_write_vfta_i350 - Write value to VLAN filter table
628c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
638c2ecf20Sopenharmony_ci *  @offset: register offset in VLAN filter table
648c2ecf20Sopenharmony_ci *  @value: register value written to VLAN filter table
658c2ecf20Sopenharmony_ci *
668c2ecf20Sopenharmony_ci *  Writes value at the given offset in the register array which stores
678c2ecf20Sopenharmony_ci *  the VLAN filter table.
688c2ecf20Sopenharmony_ci **/
698c2ecf20Sopenharmony_cistatic void igb_write_vfta_i350(struct e1000_hw *hw, u32 offset, u32 value)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	struct igb_adapter *adapter = hw->back;
728c2ecf20Sopenharmony_ci	int i;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	for (i = 10; i--;)
758c2ecf20Sopenharmony_ci		array_wr32(E1000_VFTA, offset, value);
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	wrfl();
788c2ecf20Sopenharmony_ci	adapter->shadow_vfta[offset] = value;
798c2ecf20Sopenharmony_ci}
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/**
828c2ecf20Sopenharmony_ci *  igb_sgmii_uses_mdio_82575 - Determine if I2C pins are for external MDIO
838c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
848c2ecf20Sopenharmony_ci *
858c2ecf20Sopenharmony_ci *  Called to determine if the I2C pins are being used for I2C or as an
868c2ecf20Sopenharmony_ci *  external MDIO interface since the two options are mutually exclusive.
878c2ecf20Sopenharmony_ci **/
888c2ecf20Sopenharmony_cistatic bool igb_sgmii_uses_mdio_82575(struct e1000_hw *hw)
898c2ecf20Sopenharmony_ci{
908c2ecf20Sopenharmony_ci	u32 reg = 0;
918c2ecf20Sopenharmony_ci	bool ext_mdio = false;
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	switch (hw->mac.type) {
948c2ecf20Sopenharmony_ci	case e1000_82575:
958c2ecf20Sopenharmony_ci	case e1000_82576:
968c2ecf20Sopenharmony_ci		reg = rd32(E1000_MDIC);
978c2ecf20Sopenharmony_ci		ext_mdio = !!(reg & E1000_MDIC_DEST);
988c2ecf20Sopenharmony_ci		break;
998c2ecf20Sopenharmony_ci	case e1000_82580:
1008c2ecf20Sopenharmony_ci	case e1000_i350:
1018c2ecf20Sopenharmony_ci	case e1000_i354:
1028c2ecf20Sopenharmony_ci	case e1000_i210:
1038c2ecf20Sopenharmony_ci	case e1000_i211:
1048c2ecf20Sopenharmony_ci		reg = rd32(E1000_MDICNFG);
1058c2ecf20Sopenharmony_ci		ext_mdio = !!(reg & E1000_MDICNFG_EXT_MDIO);
1068c2ecf20Sopenharmony_ci		break;
1078c2ecf20Sopenharmony_ci	default:
1088c2ecf20Sopenharmony_ci		break;
1098c2ecf20Sopenharmony_ci	}
1108c2ecf20Sopenharmony_ci	return ext_mdio;
1118c2ecf20Sopenharmony_ci}
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/**
1148c2ecf20Sopenharmony_ci *  igb_check_for_link_media_swap - Check which M88E1112 interface linked
1158c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
1168c2ecf20Sopenharmony_ci *
1178c2ecf20Sopenharmony_ci *  Poll the M88E1112 interfaces to see which interface achieved link.
1188c2ecf20Sopenharmony_ci */
1198c2ecf20Sopenharmony_cistatic s32 igb_check_for_link_media_swap(struct e1000_hw *hw)
1208c2ecf20Sopenharmony_ci{
1218c2ecf20Sopenharmony_ci	struct e1000_phy_info *phy = &hw->phy;
1228c2ecf20Sopenharmony_ci	s32 ret_val;
1238c2ecf20Sopenharmony_ci	u16 data;
1248c2ecf20Sopenharmony_ci	u8 port = 0;
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	/* Check the copper medium. */
1278c2ecf20Sopenharmony_ci	ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
1288c2ecf20Sopenharmony_ci	if (ret_val)
1298c2ecf20Sopenharmony_ci		return ret_val;
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
1328c2ecf20Sopenharmony_ci	if (ret_val)
1338c2ecf20Sopenharmony_ci		return ret_val;
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	if (data & E1000_M88E1112_STATUS_LINK)
1368c2ecf20Sopenharmony_ci		port = E1000_MEDIA_PORT_COPPER;
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	/* Check the other medium. */
1398c2ecf20Sopenharmony_ci	ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 1);
1408c2ecf20Sopenharmony_ci	if (ret_val)
1418c2ecf20Sopenharmony_ci		return ret_val;
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci	ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
1448c2ecf20Sopenharmony_ci	if (ret_val)
1458c2ecf20Sopenharmony_ci		return ret_val;
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	if (data & E1000_M88E1112_STATUS_LINK)
1498c2ecf20Sopenharmony_ci		port = E1000_MEDIA_PORT_OTHER;
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	/* Determine if a swap needs to happen. */
1528c2ecf20Sopenharmony_ci	if (port && (hw->dev_spec._82575.media_port != port)) {
1538c2ecf20Sopenharmony_ci		hw->dev_spec._82575.media_port = port;
1548c2ecf20Sopenharmony_ci		hw->dev_spec._82575.media_changed = true;
1558c2ecf20Sopenharmony_ci	}
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	if (port == E1000_MEDIA_PORT_COPPER) {
1588c2ecf20Sopenharmony_ci		/* reset page to 0 */
1598c2ecf20Sopenharmony_ci		ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
1608c2ecf20Sopenharmony_ci		if (ret_val)
1618c2ecf20Sopenharmony_ci			return ret_val;
1628c2ecf20Sopenharmony_ci		igb_check_for_link_82575(hw);
1638c2ecf20Sopenharmony_ci	} else {
1648c2ecf20Sopenharmony_ci		igb_check_for_link_82575(hw);
1658c2ecf20Sopenharmony_ci		/* reset page to 0 */
1668c2ecf20Sopenharmony_ci		ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
1678c2ecf20Sopenharmony_ci		if (ret_val)
1688c2ecf20Sopenharmony_ci			return ret_val;
1698c2ecf20Sopenharmony_ci	}
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	return 0;
1728c2ecf20Sopenharmony_ci}
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci/**
1758c2ecf20Sopenharmony_ci *  igb_init_phy_params_82575 - Init PHY func ptrs.
1768c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
1778c2ecf20Sopenharmony_ci **/
1788c2ecf20Sopenharmony_cistatic s32 igb_init_phy_params_82575(struct e1000_hw *hw)
1798c2ecf20Sopenharmony_ci{
1808c2ecf20Sopenharmony_ci	struct e1000_phy_info *phy = &hw->phy;
1818c2ecf20Sopenharmony_ci	s32 ret_val = 0;
1828c2ecf20Sopenharmony_ci	u32 ctrl_ext;
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci	if (hw->phy.media_type != e1000_media_type_copper) {
1858c2ecf20Sopenharmony_ci		phy->type = e1000_phy_none;
1868c2ecf20Sopenharmony_ci		goto out;
1878c2ecf20Sopenharmony_ci	}
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	phy->autoneg_mask	= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1908c2ecf20Sopenharmony_ci	phy->reset_delay_us	= 100;
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci	ctrl_ext = rd32(E1000_CTRL_EXT);
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci	if (igb_sgmii_active_82575(hw)) {
1958c2ecf20Sopenharmony_ci		phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
1968c2ecf20Sopenharmony_ci		ctrl_ext |= E1000_CTRL_I2C_ENA;
1978c2ecf20Sopenharmony_ci	} else {
1988c2ecf20Sopenharmony_ci		phy->ops.reset = igb_phy_hw_reset;
1998c2ecf20Sopenharmony_ci		ctrl_ext &= ~E1000_CTRL_I2C_ENA;
2008c2ecf20Sopenharmony_ci	}
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci	wr32(E1000_CTRL_EXT, ctrl_ext);
2038c2ecf20Sopenharmony_ci	igb_reset_mdicnfg_82580(hw);
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	if (igb_sgmii_active_82575(hw) && !igb_sgmii_uses_mdio_82575(hw)) {
2068c2ecf20Sopenharmony_ci		phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
2078c2ecf20Sopenharmony_ci		phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
2088c2ecf20Sopenharmony_ci	} else {
2098c2ecf20Sopenharmony_ci		switch (hw->mac.type) {
2108c2ecf20Sopenharmony_ci		case e1000_82580:
2118c2ecf20Sopenharmony_ci		case e1000_i350:
2128c2ecf20Sopenharmony_ci		case e1000_i354:
2138c2ecf20Sopenharmony_ci		case e1000_i210:
2148c2ecf20Sopenharmony_ci		case e1000_i211:
2158c2ecf20Sopenharmony_ci			phy->ops.read_reg = igb_read_phy_reg_82580;
2168c2ecf20Sopenharmony_ci			phy->ops.write_reg = igb_write_phy_reg_82580;
2178c2ecf20Sopenharmony_ci			break;
2188c2ecf20Sopenharmony_ci		default:
2198c2ecf20Sopenharmony_ci			phy->ops.read_reg = igb_read_phy_reg_igp;
2208c2ecf20Sopenharmony_ci			phy->ops.write_reg = igb_write_phy_reg_igp;
2218c2ecf20Sopenharmony_ci		}
2228c2ecf20Sopenharmony_ci	}
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci	/* set lan id */
2258c2ecf20Sopenharmony_ci	hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
2268c2ecf20Sopenharmony_ci			E1000_STATUS_FUNC_SHIFT;
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci	/* Set phy->phy_addr and phy->id. */
2298c2ecf20Sopenharmony_ci	ret_val = igb_get_phy_id_82575(hw);
2308c2ecf20Sopenharmony_ci	if (ret_val)
2318c2ecf20Sopenharmony_ci		return ret_val;
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci	/* Verify phy id and set remaining function pointers */
2348c2ecf20Sopenharmony_ci	switch (phy->id) {
2358c2ecf20Sopenharmony_ci	case M88E1543_E_PHY_ID:
2368c2ecf20Sopenharmony_ci	case M88E1512_E_PHY_ID:
2378c2ecf20Sopenharmony_ci	case I347AT4_E_PHY_ID:
2388c2ecf20Sopenharmony_ci	case M88E1112_E_PHY_ID:
2398c2ecf20Sopenharmony_ci	case M88E1111_I_PHY_ID:
2408c2ecf20Sopenharmony_ci		phy->type		= e1000_phy_m88;
2418c2ecf20Sopenharmony_ci		phy->ops.check_polarity	= igb_check_polarity_m88;
2428c2ecf20Sopenharmony_ci		phy->ops.get_phy_info	= igb_get_phy_info_m88;
2438c2ecf20Sopenharmony_ci		if (phy->id != M88E1111_I_PHY_ID)
2448c2ecf20Sopenharmony_ci			phy->ops.get_cable_length =
2458c2ecf20Sopenharmony_ci					 igb_get_cable_length_m88_gen2;
2468c2ecf20Sopenharmony_ci		else
2478c2ecf20Sopenharmony_ci			phy->ops.get_cable_length = igb_get_cable_length_m88;
2488c2ecf20Sopenharmony_ci		phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
2498c2ecf20Sopenharmony_ci		/* Check if this PHY is configured for media swap. */
2508c2ecf20Sopenharmony_ci		if (phy->id == M88E1112_E_PHY_ID) {
2518c2ecf20Sopenharmony_ci			u16 data;
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci			ret_val = phy->ops.write_reg(hw,
2548c2ecf20Sopenharmony_ci						     E1000_M88E1112_PAGE_ADDR,
2558c2ecf20Sopenharmony_ci						     2);
2568c2ecf20Sopenharmony_ci			if (ret_val)
2578c2ecf20Sopenharmony_ci				goto out;
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci			ret_val = phy->ops.read_reg(hw,
2608c2ecf20Sopenharmony_ci						    E1000_M88E1112_MAC_CTRL_1,
2618c2ecf20Sopenharmony_ci						    &data);
2628c2ecf20Sopenharmony_ci			if (ret_val)
2638c2ecf20Sopenharmony_ci				goto out;
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci			data = (data & E1000_M88E1112_MAC_CTRL_1_MODE_MASK) >>
2668c2ecf20Sopenharmony_ci			       E1000_M88E1112_MAC_CTRL_1_MODE_SHIFT;
2678c2ecf20Sopenharmony_ci			if (data == E1000_M88E1112_AUTO_COPPER_SGMII ||
2688c2ecf20Sopenharmony_ci			    data == E1000_M88E1112_AUTO_COPPER_BASEX)
2698c2ecf20Sopenharmony_ci				hw->mac.ops.check_for_link =
2708c2ecf20Sopenharmony_ci						igb_check_for_link_media_swap;
2718c2ecf20Sopenharmony_ci		}
2728c2ecf20Sopenharmony_ci		if (phy->id == M88E1512_E_PHY_ID) {
2738c2ecf20Sopenharmony_ci			ret_val = igb_initialize_M88E1512_phy(hw);
2748c2ecf20Sopenharmony_ci			if (ret_val)
2758c2ecf20Sopenharmony_ci				goto out;
2768c2ecf20Sopenharmony_ci		}
2778c2ecf20Sopenharmony_ci		if (phy->id == M88E1543_E_PHY_ID) {
2788c2ecf20Sopenharmony_ci			ret_val = igb_initialize_M88E1543_phy(hw);
2798c2ecf20Sopenharmony_ci			if (ret_val)
2808c2ecf20Sopenharmony_ci				goto out;
2818c2ecf20Sopenharmony_ci		}
2828c2ecf20Sopenharmony_ci		break;
2838c2ecf20Sopenharmony_ci	case IGP03E1000_E_PHY_ID:
2848c2ecf20Sopenharmony_ci		phy->type = e1000_phy_igp_3;
2858c2ecf20Sopenharmony_ci		phy->ops.get_phy_info = igb_get_phy_info_igp;
2868c2ecf20Sopenharmony_ci		phy->ops.get_cable_length = igb_get_cable_length_igp_2;
2878c2ecf20Sopenharmony_ci		phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
2888c2ecf20Sopenharmony_ci		phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
2898c2ecf20Sopenharmony_ci		phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
2908c2ecf20Sopenharmony_ci		break;
2918c2ecf20Sopenharmony_ci	case I82580_I_PHY_ID:
2928c2ecf20Sopenharmony_ci	case I350_I_PHY_ID:
2938c2ecf20Sopenharmony_ci		phy->type = e1000_phy_82580;
2948c2ecf20Sopenharmony_ci		phy->ops.force_speed_duplex =
2958c2ecf20Sopenharmony_ci					 igb_phy_force_speed_duplex_82580;
2968c2ecf20Sopenharmony_ci		phy->ops.get_cable_length = igb_get_cable_length_82580;
2978c2ecf20Sopenharmony_ci		phy->ops.get_phy_info = igb_get_phy_info_82580;
2988c2ecf20Sopenharmony_ci		phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
2998c2ecf20Sopenharmony_ci		phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
3008c2ecf20Sopenharmony_ci		break;
3018c2ecf20Sopenharmony_ci	case I210_I_PHY_ID:
3028c2ecf20Sopenharmony_ci		phy->type		= e1000_phy_i210;
3038c2ecf20Sopenharmony_ci		phy->ops.check_polarity	= igb_check_polarity_m88;
3048c2ecf20Sopenharmony_ci		phy->ops.get_cfg_done	= igb_get_cfg_done_i210;
3058c2ecf20Sopenharmony_ci		phy->ops.get_phy_info	= igb_get_phy_info_m88;
3068c2ecf20Sopenharmony_ci		phy->ops.get_cable_length = igb_get_cable_length_m88_gen2;
3078c2ecf20Sopenharmony_ci		phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
3088c2ecf20Sopenharmony_ci		phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
3098c2ecf20Sopenharmony_ci		phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
3108c2ecf20Sopenharmony_ci		break;
3118c2ecf20Sopenharmony_ci	case BCM54616_E_PHY_ID:
3128c2ecf20Sopenharmony_ci		phy->type = e1000_phy_bcm54616;
3138c2ecf20Sopenharmony_ci		break;
3148c2ecf20Sopenharmony_ci	default:
3158c2ecf20Sopenharmony_ci		ret_val = -E1000_ERR_PHY;
3168c2ecf20Sopenharmony_ci		goto out;
3178c2ecf20Sopenharmony_ci	}
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ciout:
3208c2ecf20Sopenharmony_ci	return ret_val;
3218c2ecf20Sopenharmony_ci}
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci/**
3248c2ecf20Sopenharmony_ci *  igb_init_nvm_params_82575 - Init NVM func ptrs.
3258c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
3268c2ecf20Sopenharmony_ci **/
3278c2ecf20Sopenharmony_cistatic s32 igb_init_nvm_params_82575(struct e1000_hw *hw)
3288c2ecf20Sopenharmony_ci{
3298c2ecf20Sopenharmony_ci	struct e1000_nvm_info *nvm = &hw->nvm;
3308c2ecf20Sopenharmony_ci	u32 eecd = rd32(E1000_EECD);
3318c2ecf20Sopenharmony_ci	u16 size;
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci	size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
3348c2ecf20Sopenharmony_ci		     E1000_EECD_SIZE_EX_SHIFT);
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci	/* Added to a constant, "size" becomes the left-shift value
3378c2ecf20Sopenharmony_ci	 * for setting word_size.
3388c2ecf20Sopenharmony_ci	 */
3398c2ecf20Sopenharmony_ci	size += NVM_WORD_SIZE_BASE_SHIFT;
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci	/* Just in case size is out of range, cap it to the largest
3428c2ecf20Sopenharmony_ci	 * EEPROM size supported
3438c2ecf20Sopenharmony_ci	 */
3448c2ecf20Sopenharmony_ci	if (size > 15)
3458c2ecf20Sopenharmony_ci		size = 15;
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	nvm->word_size = BIT(size);
3488c2ecf20Sopenharmony_ci	nvm->opcode_bits = 8;
3498c2ecf20Sopenharmony_ci	nvm->delay_usec = 1;
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	switch (nvm->override) {
3528c2ecf20Sopenharmony_ci	case e1000_nvm_override_spi_large:
3538c2ecf20Sopenharmony_ci		nvm->page_size = 32;
3548c2ecf20Sopenharmony_ci		nvm->address_bits = 16;
3558c2ecf20Sopenharmony_ci		break;
3568c2ecf20Sopenharmony_ci	case e1000_nvm_override_spi_small:
3578c2ecf20Sopenharmony_ci		nvm->page_size = 8;
3588c2ecf20Sopenharmony_ci		nvm->address_bits = 8;
3598c2ecf20Sopenharmony_ci		break;
3608c2ecf20Sopenharmony_ci	default:
3618c2ecf20Sopenharmony_ci		nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
3628c2ecf20Sopenharmony_ci		nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ?
3638c2ecf20Sopenharmony_ci				    16 : 8;
3648c2ecf20Sopenharmony_ci		break;
3658c2ecf20Sopenharmony_ci	}
3668c2ecf20Sopenharmony_ci	if (nvm->word_size == BIT(15))
3678c2ecf20Sopenharmony_ci		nvm->page_size = 128;
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci	nvm->type = e1000_nvm_eeprom_spi;
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	/* NVM Function Pointers */
3728c2ecf20Sopenharmony_ci	nvm->ops.acquire = igb_acquire_nvm_82575;
3738c2ecf20Sopenharmony_ci	nvm->ops.release = igb_release_nvm_82575;
3748c2ecf20Sopenharmony_ci	nvm->ops.write = igb_write_nvm_spi;
3758c2ecf20Sopenharmony_ci	nvm->ops.validate = igb_validate_nvm_checksum;
3768c2ecf20Sopenharmony_ci	nvm->ops.update = igb_update_nvm_checksum;
3778c2ecf20Sopenharmony_ci	if (nvm->word_size < BIT(15))
3788c2ecf20Sopenharmony_ci		nvm->ops.read = igb_read_nvm_eerd;
3798c2ecf20Sopenharmony_ci	else
3808c2ecf20Sopenharmony_ci		nvm->ops.read = igb_read_nvm_spi;
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci	/* override generic family function pointers for specific descendants */
3838c2ecf20Sopenharmony_ci	switch (hw->mac.type) {
3848c2ecf20Sopenharmony_ci	case e1000_82580:
3858c2ecf20Sopenharmony_ci		nvm->ops.validate = igb_validate_nvm_checksum_82580;
3868c2ecf20Sopenharmony_ci		nvm->ops.update = igb_update_nvm_checksum_82580;
3878c2ecf20Sopenharmony_ci		break;
3888c2ecf20Sopenharmony_ci	case e1000_i354:
3898c2ecf20Sopenharmony_ci	case e1000_i350:
3908c2ecf20Sopenharmony_ci		nvm->ops.validate = igb_validate_nvm_checksum_i350;
3918c2ecf20Sopenharmony_ci		nvm->ops.update = igb_update_nvm_checksum_i350;
3928c2ecf20Sopenharmony_ci		break;
3938c2ecf20Sopenharmony_ci	default:
3948c2ecf20Sopenharmony_ci		break;
3958c2ecf20Sopenharmony_ci	}
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	return 0;
3988c2ecf20Sopenharmony_ci}
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci/**
4018c2ecf20Sopenharmony_ci *  igb_init_mac_params_82575 - Init MAC func ptrs.
4028c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
4038c2ecf20Sopenharmony_ci **/
4048c2ecf20Sopenharmony_cistatic s32 igb_init_mac_params_82575(struct e1000_hw *hw)
4058c2ecf20Sopenharmony_ci{
4068c2ecf20Sopenharmony_ci	struct e1000_mac_info *mac = &hw->mac;
4078c2ecf20Sopenharmony_ci	struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ci	/* Set mta register count */
4108c2ecf20Sopenharmony_ci	mac->mta_reg_count = 128;
4118c2ecf20Sopenharmony_ci	/* Set uta register count */
4128c2ecf20Sopenharmony_ci	mac->uta_reg_count = (hw->mac.type == e1000_82575) ? 0 : 128;
4138c2ecf20Sopenharmony_ci	/* Set rar entry count */
4148c2ecf20Sopenharmony_ci	switch (mac->type) {
4158c2ecf20Sopenharmony_ci	case e1000_82576:
4168c2ecf20Sopenharmony_ci		mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
4178c2ecf20Sopenharmony_ci		break;
4188c2ecf20Sopenharmony_ci	case e1000_82580:
4198c2ecf20Sopenharmony_ci		mac->rar_entry_count = E1000_RAR_ENTRIES_82580;
4208c2ecf20Sopenharmony_ci		break;
4218c2ecf20Sopenharmony_ci	case e1000_i350:
4228c2ecf20Sopenharmony_ci	case e1000_i354:
4238c2ecf20Sopenharmony_ci		mac->rar_entry_count = E1000_RAR_ENTRIES_I350;
4248c2ecf20Sopenharmony_ci		break;
4258c2ecf20Sopenharmony_ci	default:
4268c2ecf20Sopenharmony_ci		mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
4278c2ecf20Sopenharmony_ci		break;
4288c2ecf20Sopenharmony_ci	}
4298c2ecf20Sopenharmony_ci	/* reset */
4308c2ecf20Sopenharmony_ci	if (mac->type >= e1000_82580)
4318c2ecf20Sopenharmony_ci		mac->ops.reset_hw = igb_reset_hw_82580;
4328c2ecf20Sopenharmony_ci	else
4338c2ecf20Sopenharmony_ci		mac->ops.reset_hw = igb_reset_hw_82575;
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci	if (mac->type >= e1000_i210) {
4368c2ecf20Sopenharmony_ci		mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_i210;
4378c2ecf20Sopenharmony_ci		mac->ops.release_swfw_sync = igb_release_swfw_sync_i210;
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci	} else {
4408c2ecf20Sopenharmony_ci		mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_82575;
4418c2ecf20Sopenharmony_ci		mac->ops.release_swfw_sync = igb_release_swfw_sync_82575;
4428c2ecf20Sopenharmony_ci	}
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci	if ((hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i354))
4458c2ecf20Sopenharmony_ci		mac->ops.write_vfta = igb_write_vfta_i350;
4468c2ecf20Sopenharmony_ci	else
4478c2ecf20Sopenharmony_ci		mac->ops.write_vfta = igb_write_vfta;
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci	/* Set if part includes ASF firmware */
4508c2ecf20Sopenharmony_ci	mac->asf_firmware_present = true;
4518c2ecf20Sopenharmony_ci	/* Set if manageability features are enabled. */
4528c2ecf20Sopenharmony_ci	mac->arc_subsystem_valid =
4538c2ecf20Sopenharmony_ci		(rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
4548c2ecf20Sopenharmony_ci			? true : false;
4558c2ecf20Sopenharmony_ci	/* enable EEE on i350 parts and later parts */
4568c2ecf20Sopenharmony_ci	if (mac->type >= e1000_i350)
4578c2ecf20Sopenharmony_ci		dev_spec->eee_disable = false;
4588c2ecf20Sopenharmony_ci	else
4598c2ecf20Sopenharmony_ci		dev_spec->eee_disable = true;
4608c2ecf20Sopenharmony_ci	/* Allow a single clear of the SW semaphore on I210 and newer */
4618c2ecf20Sopenharmony_ci	if (mac->type >= e1000_i210)
4628c2ecf20Sopenharmony_ci		dev_spec->clear_semaphore_once = true;
4638c2ecf20Sopenharmony_ci	/* physical interface link setup */
4648c2ecf20Sopenharmony_ci	mac->ops.setup_physical_interface =
4658c2ecf20Sopenharmony_ci		(hw->phy.media_type == e1000_media_type_copper)
4668c2ecf20Sopenharmony_ci			? igb_setup_copper_link_82575
4678c2ecf20Sopenharmony_ci			: igb_setup_serdes_link_82575;
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_ci	if (mac->type == e1000_82580 || mac->type == e1000_i350) {
4708c2ecf20Sopenharmony_ci		switch (hw->device_id) {
4718c2ecf20Sopenharmony_ci		/* feature not supported on these id's */
4728c2ecf20Sopenharmony_ci		case E1000_DEV_ID_DH89XXCC_SGMII:
4738c2ecf20Sopenharmony_ci		case E1000_DEV_ID_DH89XXCC_SERDES:
4748c2ecf20Sopenharmony_ci		case E1000_DEV_ID_DH89XXCC_BACKPLANE:
4758c2ecf20Sopenharmony_ci		case E1000_DEV_ID_DH89XXCC_SFP:
4768c2ecf20Sopenharmony_ci			break;
4778c2ecf20Sopenharmony_ci		default:
4788c2ecf20Sopenharmony_ci			hw->dev_spec._82575.mas_capable = true;
4798c2ecf20Sopenharmony_ci			break;
4808c2ecf20Sopenharmony_ci		}
4818c2ecf20Sopenharmony_ci	}
4828c2ecf20Sopenharmony_ci	return 0;
4838c2ecf20Sopenharmony_ci}
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci/**
4868c2ecf20Sopenharmony_ci *  igb_set_sfp_media_type_82575 - derives SFP module media type.
4878c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
4888c2ecf20Sopenharmony_ci *
4898c2ecf20Sopenharmony_ci *  The media type is chosen based on SFP module.
4908c2ecf20Sopenharmony_ci *  compatibility flags retrieved from SFP ID EEPROM.
4918c2ecf20Sopenharmony_ci **/
4928c2ecf20Sopenharmony_cistatic s32 igb_set_sfp_media_type_82575(struct e1000_hw *hw)
4938c2ecf20Sopenharmony_ci{
4948c2ecf20Sopenharmony_ci	s32 ret_val = E1000_ERR_CONFIG;
4958c2ecf20Sopenharmony_ci	u32 ctrl_ext = 0;
4968c2ecf20Sopenharmony_ci	struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
4978c2ecf20Sopenharmony_ci	struct e1000_sfp_flags *eth_flags = &dev_spec->eth_flags;
4988c2ecf20Sopenharmony_ci	u8 tranceiver_type = 0;
4998c2ecf20Sopenharmony_ci	s32 timeout = 3;
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_ci	/* Turn I2C interface ON and power on sfp cage */
5028c2ecf20Sopenharmony_ci	ctrl_ext = rd32(E1000_CTRL_EXT);
5038c2ecf20Sopenharmony_ci	ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
5048c2ecf20Sopenharmony_ci	wr32(E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_I2C_ENA);
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_ci	wrfl();
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_ci	/* Read SFP module data */
5098c2ecf20Sopenharmony_ci	while (timeout) {
5108c2ecf20Sopenharmony_ci		ret_val = igb_read_sfp_data_byte(hw,
5118c2ecf20Sopenharmony_ci			E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_IDENTIFIER_OFFSET),
5128c2ecf20Sopenharmony_ci			&tranceiver_type);
5138c2ecf20Sopenharmony_ci		if (ret_val == 0)
5148c2ecf20Sopenharmony_ci			break;
5158c2ecf20Sopenharmony_ci		msleep(100);
5168c2ecf20Sopenharmony_ci		timeout--;
5178c2ecf20Sopenharmony_ci	}
5188c2ecf20Sopenharmony_ci	if (ret_val != 0)
5198c2ecf20Sopenharmony_ci		goto out;
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci	ret_val = igb_read_sfp_data_byte(hw,
5228c2ecf20Sopenharmony_ci			E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_ETH_FLAGS_OFFSET),
5238c2ecf20Sopenharmony_ci			(u8 *)eth_flags);
5248c2ecf20Sopenharmony_ci	if (ret_val != 0)
5258c2ecf20Sopenharmony_ci		goto out;
5268c2ecf20Sopenharmony_ci
5278c2ecf20Sopenharmony_ci	/* Check if there is some SFP module plugged and powered */
5288c2ecf20Sopenharmony_ci	if ((tranceiver_type == E1000_SFF_IDENTIFIER_SFP) ||
5298c2ecf20Sopenharmony_ci	    (tranceiver_type == E1000_SFF_IDENTIFIER_SFF)) {
5308c2ecf20Sopenharmony_ci		dev_spec->module_plugged = true;
5318c2ecf20Sopenharmony_ci		if (eth_flags->e1000_base_lx || eth_flags->e1000_base_sx) {
5328c2ecf20Sopenharmony_ci			hw->phy.media_type = e1000_media_type_internal_serdes;
5338c2ecf20Sopenharmony_ci		} else if (eth_flags->e100_base_fx || eth_flags->e100_base_lx) {
5348c2ecf20Sopenharmony_ci			dev_spec->sgmii_active = true;
5358c2ecf20Sopenharmony_ci			hw->phy.media_type = e1000_media_type_internal_serdes;
5368c2ecf20Sopenharmony_ci		} else if (eth_flags->e1000_base_t) {
5378c2ecf20Sopenharmony_ci			dev_spec->sgmii_active = true;
5388c2ecf20Sopenharmony_ci			hw->phy.media_type = e1000_media_type_copper;
5398c2ecf20Sopenharmony_ci		} else {
5408c2ecf20Sopenharmony_ci			hw->phy.media_type = e1000_media_type_unknown;
5418c2ecf20Sopenharmony_ci			hw_dbg("PHY module has not been recognized\n");
5428c2ecf20Sopenharmony_ci			goto out;
5438c2ecf20Sopenharmony_ci		}
5448c2ecf20Sopenharmony_ci	} else {
5458c2ecf20Sopenharmony_ci		hw->phy.media_type = e1000_media_type_unknown;
5468c2ecf20Sopenharmony_ci	}
5478c2ecf20Sopenharmony_ci	ret_val = 0;
5488c2ecf20Sopenharmony_ciout:
5498c2ecf20Sopenharmony_ci	/* Restore I2C interface setting */
5508c2ecf20Sopenharmony_ci	wr32(E1000_CTRL_EXT, ctrl_ext);
5518c2ecf20Sopenharmony_ci	return ret_val;
5528c2ecf20Sopenharmony_ci}
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_cistatic s32 igb_get_invariants_82575(struct e1000_hw *hw)
5558c2ecf20Sopenharmony_ci{
5568c2ecf20Sopenharmony_ci	struct e1000_mac_info *mac = &hw->mac;
5578c2ecf20Sopenharmony_ci	struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
5588c2ecf20Sopenharmony_ci	s32 ret_val;
5598c2ecf20Sopenharmony_ci	u32 ctrl_ext = 0;
5608c2ecf20Sopenharmony_ci	u32 link_mode = 0;
5618c2ecf20Sopenharmony_ci
5628c2ecf20Sopenharmony_ci	switch (hw->device_id) {
5638c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82575EB_COPPER:
5648c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82575EB_FIBER_SERDES:
5658c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82575GB_QUAD_COPPER:
5668c2ecf20Sopenharmony_ci		mac->type = e1000_82575;
5678c2ecf20Sopenharmony_ci		break;
5688c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82576:
5698c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82576_NS:
5708c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82576_NS_SERDES:
5718c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82576_FIBER:
5728c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82576_SERDES:
5738c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82576_QUAD_COPPER:
5748c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
5758c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82576_SERDES_QUAD:
5768c2ecf20Sopenharmony_ci		mac->type = e1000_82576;
5778c2ecf20Sopenharmony_ci		break;
5788c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82580_COPPER:
5798c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82580_FIBER:
5808c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82580_QUAD_FIBER:
5818c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82580_SERDES:
5828c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82580_SGMII:
5838c2ecf20Sopenharmony_ci	case E1000_DEV_ID_82580_COPPER_DUAL:
5848c2ecf20Sopenharmony_ci	case E1000_DEV_ID_DH89XXCC_SGMII:
5858c2ecf20Sopenharmony_ci	case E1000_DEV_ID_DH89XXCC_SERDES:
5868c2ecf20Sopenharmony_ci	case E1000_DEV_ID_DH89XXCC_BACKPLANE:
5878c2ecf20Sopenharmony_ci	case E1000_DEV_ID_DH89XXCC_SFP:
5888c2ecf20Sopenharmony_ci		mac->type = e1000_82580;
5898c2ecf20Sopenharmony_ci		break;
5908c2ecf20Sopenharmony_ci	case E1000_DEV_ID_I350_COPPER:
5918c2ecf20Sopenharmony_ci	case E1000_DEV_ID_I350_FIBER:
5928c2ecf20Sopenharmony_ci	case E1000_DEV_ID_I350_SERDES:
5938c2ecf20Sopenharmony_ci	case E1000_DEV_ID_I350_SGMII:
5948c2ecf20Sopenharmony_ci		mac->type = e1000_i350;
5958c2ecf20Sopenharmony_ci		break;
5968c2ecf20Sopenharmony_ci	case E1000_DEV_ID_I210_COPPER:
5978c2ecf20Sopenharmony_ci	case E1000_DEV_ID_I210_FIBER:
5988c2ecf20Sopenharmony_ci	case E1000_DEV_ID_I210_SERDES:
5998c2ecf20Sopenharmony_ci	case E1000_DEV_ID_I210_SGMII:
6008c2ecf20Sopenharmony_ci	case E1000_DEV_ID_I210_COPPER_FLASHLESS:
6018c2ecf20Sopenharmony_ci	case E1000_DEV_ID_I210_SERDES_FLASHLESS:
6028c2ecf20Sopenharmony_ci		mac->type = e1000_i210;
6038c2ecf20Sopenharmony_ci		break;
6048c2ecf20Sopenharmony_ci	case E1000_DEV_ID_I211_COPPER:
6058c2ecf20Sopenharmony_ci		mac->type = e1000_i211;
6068c2ecf20Sopenharmony_ci		break;
6078c2ecf20Sopenharmony_ci	case E1000_DEV_ID_I354_BACKPLANE_1GBPS:
6088c2ecf20Sopenharmony_ci	case E1000_DEV_ID_I354_SGMII:
6098c2ecf20Sopenharmony_ci	case E1000_DEV_ID_I354_BACKPLANE_2_5GBPS:
6108c2ecf20Sopenharmony_ci		mac->type = e1000_i354;
6118c2ecf20Sopenharmony_ci		break;
6128c2ecf20Sopenharmony_ci	default:
6138c2ecf20Sopenharmony_ci		return -E1000_ERR_MAC_INIT;
6148c2ecf20Sopenharmony_ci	}
6158c2ecf20Sopenharmony_ci
6168c2ecf20Sopenharmony_ci	/* Set media type */
6178c2ecf20Sopenharmony_ci	/* The 82575 uses bits 22:23 for link mode. The mode can be changed
6188c2ecf20Sopenharmony_ci	 * based on the EEPROM. We cannot rely upon device ID. There
6198c2ecf20Sopenharmony_ci	 * is no distinguishable difference between fiber and internal
6208c2ecf20Sopenharmony_ci	 * SerDes mode on the 82575. There can be an external PHY attached
6218c2ecf20Sopenharmony_ci	 * on the SGMII interface. For this, we'll set sgmii_active to true.
6228c2ecf20Sopenharmony_ci	 */
6238c2ecf20Sopenharmony_ci	hw->phy.media_type = e1000_media_type_copper;
6248c2ecf20Sopenharmony_ci	dev_spec->sgmii_active = false;
6258c2ecf20Sopenharmony_ci	dev_spec->module_plugged = false;
6268c2ecf20Sopenharmony_ci
6278c2ecf20Sopenharmony_ci	ctrl_ext = rd32(E1000_CTRL_EXT);
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_ci	link_mode = ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK;
6308c2ecf20Sopenharmony_ci	switch (link_mode) {
6318c2ecf20Sopenharmony_ci	case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
6328c2ecf20Sopenharmony_ci		hw->phy.media_type = e1000_media_type_internal_serdes;
6338c2ecf20Sopenharmony_ci		break;
6348c2ecf20Sopenharmony_ci	case E1000_CTRL_EXT_LINK_MODE_SGMII:
6358c2ecf20Sopenharmony_ci		/* Get phy control interface type set (MDIO vs. I2C)*/
6368c2ecf20Sopenharmony_ci		if (igb_sgmii_uses_mdio_82575(hw)) {
6378c2ecf20Sopenharmony_ci			hw->phy.media_type = e1000_media_type_copper;
6388c2ecf20Sopenharmony_ci			dev_spec->sgmii_active = true;
6398c2ecf20Sopenharmony_ci			break;
6408c2ecf20Sopenharmony_ci		}
6418c2ecf20Sopenharmony_ci		fallthrough; /* for I2C based SGMII */
6428c2ecf20Sopenharmony_ci	case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
6438c2ecf20Sopenharmony_ci		/* read media type from SFP EEPROM */
6448c2ecf20Sopenharmony_ci		ret_val = igb_set_sfp_media_type_82575(hw);
6458c2ecf20Sopenharmony_ci		if ((ret_val != 0) ||
6468c2ecf20Sopenharmony_ci		    (hw->phy.media_type == e1000_media_type_unknown)) {
6478c2ecf20Sopenharmony_ci			/* If media type was not identified then return media
6488c2ecf20Sopenharmony_ci			 * type defined by the CTRL_EXT settings.
6498c2ecf20Sopenharmony_ci			 */
6508c2ecf20Sopenharmony_ci			hw->phy.media_type = e1000_media_type_internal_serdes;
6518c2ecf20Sopenharmony_ci
6528c2ecf20Sopenharmony_ci			if (link_mode == E1000_CTRL_EXT_LINK_MODE_SGMII) {
6538c2ecf20Sopenharmony_ci				hw->phy.media_type = e1000_media_type_copper;
6548c2ecf20Sopenharmony_ci				dev_spec->sgmii_active = true;
6558c2ecf20Sopenharmony_ci			}
6568c2ecf20Sopenharmony_ci
6578c2ecf20Sopenharmony_ci			break;
6588c2ecf20Sopenharmony_ci		}
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_ci		/* change current link mode setting */
6618c2ecf20Sopenharmony_ci		ctrl_ext &= ~E1000_CTRL_EXT_LINK_MODE_MASK;
6628c2ecf20Sopenharmony_ci
6638c2ecf20Sopenharmony_ci		if (dev_spec->sgmii_active)
6648c2ecf20Sopenharmony_ci			ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_SGMII;
6658c2ecf20Sopenharmony_ci		else
6668c2ecf20Sopenharmony_ci			ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_ci		wr32(E1000_CTRL_EXT, ctrl_ext);
6698c2ecf20Sopenharmony_ci
6708c2ecf20Sopenharmony_ci		break;
6718c2ecf20Sopenharmony_ci	default:
6728c2ecf20Sopenharmony_ci		break;
6738c2ecf20Sopenharmony_ci	}
6748c2ecf20Sopenharmony_ci
6758c2ecf20Sopenharmony_ci	/* mac initialization and operations */
6768c2ecf20Sopenharmony_ci	ret_val = igb_init_mac_params_82575(hw);
6778c2ecf20Sopenharmony_ci	if (ret_val)
6788c2ecf20Sopenharmony_ci		goto out;
6798c2ecf20Sopenharmony_ci
6808c2ecf20Sopenharmony_ci	/* NVM initialization */
6818c2ecf20Sopenharmony_ci	ret_val = igb_init_nvm_params_82575(hw);
6828c2ecf20Sopenharmony_ci	switch (hw->mac.type) {
6838c2ecf20Sopenharmony_ci	case e1000_i210:
6848c2ecf20Sopenharmony_ci	case e1000_i211:
6858c2ecf20Sopenharmony_ci		ret_val = igb_init_nvm_params_i210(hw);
6868c2ecf20Sopenharmony_ci		break;
6878c2ecf20Sopenharmony_ci	default:
6888c2ecf20Sopenharmony_ci		break;
6898c2ecf20Sopenharmony_ci	}
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_ci	if (ret_val)
6928c2ecf20Sopenharmony_ci		goto out;
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_ci	/* if part supports SR-IOV then initialize mailbox parameters */
6958c2ecf20Sopenharmony_ci	switch (mac->type) {
6968c2ecf20Sopenharmony_ci	case e1000_82576:
6978c2ecf20Sopenharmony_ci	case e1000_i350:
6988c2ecf20Sopenharmony_ci		igb_init_mbx_params_pf(hw);
6998c2ecf20Sopenharmony_ci		break;
7008c2ecf20Sopenharmony_ci	default:
7018c2ecf20Sopenharmony_ci		break;
7028c2ecf20Sopenharmony_ci	}
7038c2ecf20Sopenharmony_ci
7048c2ecf20Sopenharmony_ci	/* setup PHY parameters */
7058c2ecf20Sopenharmony_ci	ret_val = igb_init_phy_params_82575(hw);
7068c2ecf20Sopenharmony_ci
7078c2ecf20Sopenharmony_ciout:
7088c2ecf20Sopenharmony_ci	return ret_val;
7098c2ecf20Sopenharmony_ci}
7108c2ecf20Sopenharmony_ci
7118c2ecf20Sopenharmony_ci/**
7128c2ecf20Sopenharmony_ci *  igb_acquire_phy_82575 - Acquire rights to access PHY
7138c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
7148c2ecf20Sopenharmony_ci *
7158c2ecf20Sopenharmony_ci *  Acquire access rights to the correct PHY.  This is a
7168c2ecf20Sopenharmony_ci *  function pointer entry point called by the api module.
7178c2ecf20Sopenharmony_ci **/
7188c2ecf20Sopenharmony_cistatic s32 igb_acquire_phy_82575(struct e1000_hw *hw)
7198c2ecf20Sopenharmony_ci{
7208c2ecf20Sopenharmony_ci	u16 mask = E1000_SWFW_PHY0_SM;
7218c2ecf20Sopenharmony_ci
7228c2ecf20Sopenharmony_ci	if (hw->bus.func == E1000_FUNC_1)
7238c2ecf20Sopenharmony_ci		mask = E1000_SWFW_PHY1_SM;
7248c2ecf20Sopenharmony_ci	else if (hw->bus.func == E1000_FUNC_2)
7258c2ecf20Sopenharmony_ci		mask = E1000_SWFW_PHY2_SM;
7268c2ecf20Sopenharmony_ci	else if (hw->bus.func == E1000_FUNC_3)
7278c2ecf20Sopenharmony_ci		mask = E1000_SWFW_PHY3_SM;
7288c2ecf20Sopenharmony_ci
7298c2ecf20Sopenharmony_ci	return hw->mac.ops.acquire_swfw_sync(hw, mask);
7308c2ecf20Sopenharmony_ci}
7318c2ecf20Sopenharmony_ci
7328c2ecf20Sopenharmony_ci/**
7338c2ecf20Sopenharmony_ci *  igb_release_phy_82575 - Release rights to access PHY
7348c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
7358c2ecf20Sopenharmony_ci *
7368c2ecf20Sopenharmony_ci *  A wrapper to release access rights to the correct PHY.  This is a
7378c2ecf20Sopenharmony_ci *  function pointer entry point called by the api module.
7388c2ecf20Sopenharmony_ci **/
7398c2ecf20Sopenharmony_cistatic void igb_release_phy_82575(struct e1000_hw *hw)
7408c2ecf20Sopenharmony_ci{
7418c2ecf20Sopenharmony_ci	u16 mask = E1000_SWFW_PHY0_SM;
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_ci	if (hw->bus.func == E1000_FUNC_1)
7448c2ecf20Sopenharmony_ci		mask = E1000_SWFW_PHY1_SM;
7458c2ecf20Sopenharmony_ci	else if (hw->bus.func == E1000_FUNC_2)
7468c2ecf20Sopenharmony_ci		mask = E1000_SWFW_PHY2_SM;
7478c2ecf20Sopenharmony_ci	else if (hw->bus.func == E1000_FUNC_3)
7488c2ecf20Sopenharmony_ci		mask = E1000_SWFW_PHY3_SM;
7498c2ecf20Sopenharmony_ci
7508c2ecf20Sopenharmony_ci	hw->mac.ops.release_swfw_sync(hw, mask);
7518c2ecf20Sopenharmony_ci}
7528c2ecf20Sopenharmony_ci
7538c2ecf20Sopenharmony_ci/**
7548c2ecf20Sopenharmony_ci *  igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
7558c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
7568c2ecf20Sopenharmony_ci *  @offset: register offset to be read
7578c2ecf20Sopenharmony_ci *  @data: pointer to the read data
7588c2ecf20Sopenharmony_ci *
7598c2ecf20Sopenharmony_ci *  Reads the PHY register at offset using the serial gigabit media independent
7608c2ecf20Sopenharmony_ci *  interface and stores the retrieved information in data.
7618c2ecf20Sopenharmony_ci **/
7628c2ecf20Sopenharmony_cistatic s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
7638c2ecf20Sopenharmony_ci					  u16 *data)
7648c2ecf20Sopenharmony_ci{
7658c2ecf20Sopenharmony_ci	s32 ret_val = -E1000_ERR_PARAM;
7668c2ecf20Sopenharmony_ci
7678c2ecf20Sopenharmony_ci	if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
7688c2ecf20Sopenharmony_ci		hw_dbg("PHY Address %u is out of range\n", offset);
7698c2ecf20Sopenharmony_ci		goto out;
7708c2ecf20Sopenharmony_ci	}
7718c2ecf20Sopenharmony_ci
7728c2ecf20Sopenharmony_ci	ret_val = hw->phy.ops.acquire(hw);
7738c2ecf20Sopenharmony_ci	if (ret_val)
7748c2ecf20Sopenharmony_ci		goto out;
7758c2ecf20Sopenharmony_ci
7768c2ecf20Sopenharmony_ci	ret_val = igb_read_phy_reg_i2c(hw, offset, data);
7778c2ecf20Sopenharmony_ci
7788c2ecf20Sopenharmony_ci	hw->phy.ops.release(hw);
7798c2ecf20Sopenharmony_ci
7808c2ecf20Sopenharmony_ciout:
7818c2ecf20Sopenharmony_ci	return ret_val;
7828c2ecf20Sopenharmony_ci}
7838c2ecf20Sopenharmony_ci
7848c2ecf20Sopenharmony_ci/**
7858c2ecf20Sopenharmony_ci *  igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
7868c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
7878c2ecf20Sopenharmony_ci *  @offset: register offset to write to
7888c2ecf20Sopenharmony_ci *  @data: data to write at register offset
7898c2ecf20Sopenharmony_ci *
7908c2ecf20Sopenharmony_ci *  Writes the data to PHY register at the offset using the serial gigabit
7918c2ecf20Sopenharmony_ci *  media independent interface.
7928c2ecf20Sopenharmony_ci **/
7938c2ecf20Sopenharmony_cistatic s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
7948c2ecf20Sopenharmony_ci					   u16 data)
7958c2ecf20Sopenharmony_ci{
7968c2ecf20Sopenharmony_ci	s32 ret_val = -E1000_ERR_PARAM;
7978c2ecf20Sopenharmony_ci
7988c2ecf20Sopenharmony_ci
7998c2ecf20Sopenharmony_ci	if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
8008c2ecf20Sopenharmony_ci		hw_dbg("PHY Address %d is out of range\n", offset);
8018c2ecf20Sopenharmony_ci		goto out;
8028c2ecf20Sopenharmony_ci	}
8038c2ecf20Sopenharmony_ci
8048c2ecf20Sopenharmony_ci	ret_val = hw->phy.ops.acquire(hw);
8058c2ecf20Sopenharmony_ci	if (ret_val)
8068c2ecf20Sopenharmony_ci		goto out;
8078c2ecf20Sopenharmony_ci
8088c2ecf20Sopenharmony_ci	ret_val = igb_write_phy_reg_i2c(hw, offset, data);
8098c2ecf20Sopenharmony_ci
8108c2ecf20Sopenharmony_ci	hw->phy.ops.release(hw);
8118c2ecf20Sopenharmony_ci
8128c2ecf20Sopenharmony_ciout:
8138c2ecf20Sopenharmony_ci	return ret_val;
8148c2ecf20Sopenharmony_ci}
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci/**
8178c2ecf20Sopenharmony_ci *  igb_get_phy_id_82575 - Retrieve PHY addr and id
8188c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
8198c2ecf20Sopenharmony_ci *
8208c2ecf20Sopenharmony_ci *  Retrieves the PHY address and ID for both PHY's which do and do not use
8218c2ecf20Sopenharmony_ci *  sgmi interface.
8228c2ecf20Sopenharmony_ci **/
8238c2ecf20Sopenharmony_cistatic s32 igb_get_phy_id_82575(struct e1000_hw *hw)
8248c2ecf20Sopenharmony_ci{
8258c2ecf20Sopenharmony_ci	struct e1000_phy_info *phy = &hw->phy;
8268c2ecf20Sopenharmony_ci	s32  ret_val = 0;
8278c2ecf20Sopenharmony_ci	u16 phy_id;
8288c2ecf20Sopenharmony_ci	u32 ctrl_ext;
8298c2ecf20Sopenharmony_ci	u32 mdic;
8308c2ecf20Sopenharmony_ci
8318c2ecf20Sopenharmony_ci	/* Extra read required for some PHY's on i354 */
8328c2ecf20Sopenharmony_ci	if (hw->mac.type == e1000_i354)
8338c2ecf20Sopenharmony_ci		igb_get_phy_id(hw);
8348c2ecf20Sopenharmony_ci
8358c2ecf20Sopenharmony_ci	/* For SGMII PHYs, we try the list of possible addresses until
8368c2ecf20Sopenharmony_ci	 * we find one that works.  For non-SGMII PHYs
8378c2ecf20Sopenharmony_ci	 * (e.g. integrated copper PHYs), an address of 1 should
8388c2ecf20Sopenharmony_ci	 * work.  The result of this function should mean phy->phy_addr
8398c2ecf20Sopenharmony_ci	 * and phy->id are set correctly.
8408c2ecf20Sopenharmony_ci	 */
8418c2ecf20Sopenharmony_ci	if (!(igb_sgmii_active_82575(hw))) {
8428c2ecf20Sopenharmony_ci		phy->addr = 1;
8438c2ecf20Sopenharmony_ci		ret_val = igb_get_phy_id(hw);
8448c2ecf20Sopenharmony_ci		goto out;
8458c2ecf20Sopenharmony_ci	}
8468c2ecf20Sopenharmony_ci
8478c2ecf20Sopenharmony_ci	if (igb_sgmii_uses_mdio_82575(hw)) {
8488c2ecf20Sopenharmony_ci		switch (hw->mac.type) {
8498c2ecf20Sopenharmony_ci		case e1000_82575:
8508c2ecf20Sopenharmony_ci		case e1000_82576:
8518c2ecf20Sopenharmony_ci			mdic = rd32(E1000_MDIC);
8528c2ecf20Sopenharmony_ci			mdic &= E1000_MDIC_PHY_MASK;
8538c2ecf20Sopenharmony_ci			phy->addr = mdic >> E1000_MDIC_PHY_SHIFT;
8548c2ecf20Sopenharmony_ci			break;
8558c2ecf20Sopenharmony_ci		case e1000_82580:
8568c2ecf20Sopenharmony_ci		case e1000_i350:
8578c2ecf20Sopenharmony_ci		case e1000_i354:
8588c2ecf20Sopenharmony_ci		case e1000_i210:
8598c2ecf20Sopenharmony_ci		case e1000_i211:
8608c2ecf20Sopenharmony_ci			mdic = rd32(E1000_MDICNFG);
8618c2ecf20Sopenharmony_ci			mdic &= E1000_MDICNFG_PHY_MASK;
8628c2ecf20Sopenharmony_ci			phy->addr = mdic >> E1000_MDICNFG_PHY_SHIFT;
8638c2ecf20Sopenharmony_ci			break;
8648c2ecf20Sopenharmony_ci		default:
8658c2ecf20Sopenharmony_ci			ret_val = -E1000_ERR_PHY;
8668c2ecf20Sopenharmony_ci			goto out;
8678c2ecf20Sopenharmony_ci		}
8688c2ecf20Sopenharmony_ci		ret_val = igb_get_phy_id(hw);
8698c2ecf20Sopenharmony_ci		goto out;
8708c2ecf20Sopenharmony_ci	}
8718c2ecf20Sopenharmony_ci
8728c2ecf20Sopenharmony_ci	/* Power on sgmii phy if it is disabled */
8738c2ecf20Sopenharmony_ci	ctrl_ext = rd32(E1000_CTRL_EXT);
8748c2ecf20Sopenharmony_ci	wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
8758c2ecf20Sopenharmony_ci	wrfl();
8768c2ecf20Sopenharmony_ci	msleep(300);
8778c2ecf20Sopenharmony_ci
8788c2ecf20Sopenharmony_ci	/* The address field in the I2CCMD register is 3 bits and 0 is invalid.
8798c2ecf20Sopenharmony_ci	 * Therefore, we need to test 1-7
8808c2ecf20Sopenharmony_ci	 */
8818c2ecf20Sopenharmony_ci	for (phy->addr = 1; phy->addr < 8; phy->addr++) {
8828c2ecf20Sopenharmony_ci		ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
8838c2ecf20Sopenharmony_ci		if (ret_val == 0) {
8848c2ecf20Sopenharmony_ci			hw_dbg("Vendor ID 0x%08X read at address %u\n",
8858c2ecf20Sopenharmony_ci			       phy_id, phy->addr);
8868c2ecf20Sopenharmony_ci			/* At the time of this writing, The M88 part is
8878c2ecf20Sopenharmony_ci			 * the only supported SGMII PHY product.
8888c2ecf20Sopenharmony_ci			 */
8898c2ecf20Sopenharmony_ci			if (phy_id == M88_VENDOR)
8908c2ecf20Sopenharmony_ci				break;
8918c2ecf20Sopenharmony_ci		} else {
8928c2ecf20Sopenharmony_ci			hw_dbg("PHY address %u was unreadable\n", phy->addr);
8938c2ecf20Sopenharmony_ci		}
8948c2ecf20Sopenharmony_ci	}
8958c2ecf20Sopenharmony_ci
8968c2ecf20Sopenharmony_ci	/* A valid PHY type couldn't be found. */
8978c2ecf20Sopenharmony_ci	if (phy->addr == 8) {
8988c2ecf20Sopenharmony_ci		phy->addr = 0;
8998c2ecf20Sopenharmony_ci		ret_val = -E1000_ERR_PHY;
9008c2ecf20Sopenharmony_ci		goto out;
9018c2ecf20Sopenharmony_ci	} else {
9028c2ecf20Sopenharmony_ci		ret_val = igb_get_phy_id(hw);
9038c2ecf20Sopenharmony_ci	}
9048c2ecf20Sopenharmony_ci
9058c2ecf20Sopenharmony_ci	/* restore previous sfp cage power state */
9068c2ecf20Sopenharmony_ci	wr32(E1000_CTRL_EXT, ctrl_ext);
9078c2ecf20Sopenharmony_ci
9088c2ecf20Sopenharmony_ciout:
9098c2ecf20Sopenharmony_ci	return ret_val;
9108c2ecf20Sopenharmony_ci}
9118c2ecf20Sopenharmony_ci
9128c2ecf20Sopenharmony_ci/**
9138c2ecf20Sopenharmony_ci *  igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
9148c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
9158c2ecf20Sopenharmony_ci *
9168c2ecf20Sopenharmony_ci *  Resets the PHY using the serial gigabit media independent interface.
9178c2ecf20Sopenharmony_ci **/
9188c2ecf20Sopenharmony_cistatic s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
9198c2ecf20Sopenharmony_ci{
9208c2ecf20Sopenharmony_ci	struct e1000_phy_info *phy = &hw->phy;
9218c2ecf20Sopenharmony_ci	s32 ret_val;
9228c2ecf20Sopenharmony_ci
9238c2ecf20Sopenharmony_ci	/* This isn't a true "hard" reset, but is the only reset
9248c2ecf20Sopenharmony_ci	 * available to us at this time.
9258c2ecf20Sopenharmony_ci	 */
9268c2ecf20Sopenharmony_ci
9278c2ecf20Sopenharmony_ci	hw_dbg("Soft resetting SGMII attached PHY...\n");
9288c2ecf20Sopenharmony_ci
9298c2ecf20Sopenharmony_ci	/* SFP documentation requires the following to configure the SPF module
9308c2ecf20Sopenharmony_ci	 * to work on SGMII.  No further documentation is given.
9318c2ecf20Sopenharmony_ci	 */
9328c2ecf20Sopenharmony_ci	ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
9338c2ecf20Sopenharmony_ci	if (ret_val)
9348c2ecf20Sopenharmony_ci		goto out;
9358c2ecf20Sopenharmony_ci
9368c2ecf20Sopenharmony_ci	ret_val = igb_phy_sw_reset(hw);
9378c2ecf20Sopenharmony_ci	if (ret_val)
9388c2ecf20Sopenharmony_ci		goto out;
9398c2ecf20Sopenharmony_ci
9408c2ecf20Sopenharmony_ci	if (phy->id == M88E1512_E_PHY_ID)
9418c2ecf20Sopenharmony_ci		ret_val = igb_initialize_M88E1512_phy(hw);
9428c2ecf20Sopenharmony_ci	if (phy->id == M88E1543_E_PHY_ID)
9438c2ecf20Sopenharmony_ci		ret_val = igb_initialize_M88E1543_phy(hw);
9448c2ecf20Sopenharmony_ciout:
9458c2ecf20Sopenharmony_ci	return ret_val;
9468c2ecf20Sopenharmony_ci}
9478c2ecf20Sopenharmony_ci
9488c2ecf20Sopenharmony_ci/**
9498c2ecf20Sopenharmony_ci *  igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
9508c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
9518c2ecf20Sopenharmony_ci *  @active: true to enable LPLU, false to disable
9528c2ecf20Sopenharmony_ci *
9538c2ecf20Sopenharmony_ci *  Sets the LPLU D0 state according to the active flag.  When
9548c2ecf20Sopenharmony_ci *  activating LPLU this function also disables smart speed
9558c2ecf20Sopenharmony_ci *  and vice versa.  LPLU will not be activated unless the
9568c2ecf20Sopenharmony_ci *  device autonegotiation advertisement meets standards of
9578c2ecf20Sopenharmony_ci *  either 10 or 10/100 or 10/100/1000 at all duplexes.
9588c2ecf20Sopenharmony_ci *  This is a function pointer entry point only called by
9598c2ecf20Sopenharmony_ci *  PHY setup routines.
9608c2ecf20Sopenharmony_ci **/
9618c2ecf20Sopenharmony_cistatic s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
9628c2ecf20Sopenharmony_ci{
9638c2ecf20Sopenharmony_ci	struct e1000_phy_info *phy = &hw->phy;
9648c2ecf20Sopenharmony_ci	s32 ret_val;
9658c2ecf20Sopenharmony_ci	u16 data;
9668c2ecf20Sopenharmony_ci
9678c2ecf20Sopenharmony_ci	ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
9688c2ecf20Sopenharmony_ci	if (ret_val)
9698c2ecf20Sopenharmony_ci		goto out;
9708c2ecf20Sopenharmony_ci
9718c2ecf20Sopenharmony_ci	if (active) {
9728c2ecf20Sopenharmony_ci		data |= IGP02E1000_PM_D0_LPLU;
9738c2ecf20Sopenharmony_ci		ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
9748c2ecf20Sopenharmony_ci						 data);
9758c2ecf20Sopenharmony_ci		if (ret_val)
9768c2ecf20Sopenharmony_ci			goto out;
9778c2ecf20Sopenharmony_ci
9788c2ecf20Sopenharmony_ci		/* When LPLU is enabled, we should disable SmartSpeed */
9798c2ecf20Sopenharmony_ci		ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
9808c2ecf20Sopenharmony_ci						&data);
9818c2ecf20Sopenharmony_ci		data &= ~IGP01E1000_PSCFR_SMART_SPEED;
9828c2ecf20Sopenharmony_ci		ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
9838c2ecf20Sopenharmony_ci						 data);
9848c2ecf20Sopenharmony_ci		if (ret_val)
9858c2ecf20Sopenharmony_ci			goto out;
9868c2ecf20Sopenharmony_ci	} else {
9878c2ecf20Sopenharmony_ci		data &= ~IGP02E1000_PM_D0_LPLU;
9888c2ecf20Sopenharmony_ci		ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
9898c2ecf20Sopenharmony_ci						 data);
9908c2ecf20Sopenharmony_ci		/* LPLU and SmartSpeed are mutually exclusive.  LPLU is used
9918c2ecf20Sopenharmony_ci		 * during Dx states where the power conservation is most
9928c2ecf20Sopenharmony_ci		 * important.  During driver activity we should enable
9938c2ecf20Sopenharmony_ci		 * SmartSpeed, so performance is maintained.
9948c2ecf20Sopenharmony_ci		 */
9958c2ecf20Sopenharmony_ci		if (phy->smart_speed == e1000_smart_speed_on) {
9968c2ecf20Sopenharmony_ci			ret_val = phy->ops.read_reg(hw,
9978c2ecf20Sopenharmony_ci					IGP01E1000_PHY_PORT_CONFIG, &data);
9988c2ecf20Sopenharmony_ci			if (ret_val)
9998c2ecf20Sopenharmony_ci				goto out;
10008c2ecf20Sopenharmony_ci
10018c2ecf20Sopenharmony_ci			data |= IGP01E1000_PSCFR_SMART_SPEED;
10028c2ecf20Sopenharmony_ci			ret_val = phy->ops.write_reg(hw,
10038c2ecf20Sopenharmony_ci					IGP01E1000_PHY_PORT_CONFIG, data);
10048c2ecf20Sopenharmony_ci			if (ret_val)
10058c2ecf20Sopenharmony_ci				goto out;
10068c2ecf20Sopenharmony_ci		} else if (phy->smart_speed == e1000_smart_speed_off) {
10078c2ecf20Sopenharmony_ci			ret_val = phy->ops.read_reg(hw,
10088c2ecf20Sopenharmony_ci					IGP01E1000_PHY_PORT_CONFIG, &data);
10098c2ecf20Sopenharmony_ci			if (ret_val)
10108c2ecf20Sopenharmony_ci				goto out;
10118c2ecf20Sopenharmony_ci
10128c2ecf20Sopenharmony_ci			data &= ~IGP01E1000_PSCFR_SMART_SPEED;
10138c2ecf20Sopenharmony_ci			ret_val = phy->ops.write_reg(hw,
10148c2ecf20Sopenharmony_ci					IGP01E1000_PHY_PORT_CONFIG, data);
10158c2ecf20Sopenharmony_ci			if (ret_val)
10168c2ecf20Sopenharmony_ci				goto out;
10178c2ecf20Sopenharmony_ci		}
10188c2ecf20Sopenharmony_ci	}
10198c2ecf20Sopenharmony_ci
10208c2ecf20Sopenharmony_ciout:
10218c2ecf20Sopenharmony_ci	return ret_val;
10228c2ecf20Sopenharmony_ci}
10238c2ecf20Sopenharmony_ci
10248c2ecf20Sopenharmony_ci/**
10258c2ecf20Sopenharmony_ci *  igb_set_d0_lplu_state_82580 - Set Low Power Linkup D0 state
10268c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
10278c2ecf20Sopenharmony_ci *  @active: true to enable LPLU, false to disable
10288c2ecf20Sopenharmony_ci *
10298c2ecf20Sopenharmony_ci *  Sets the LPLU D0 state according to the active flag.  When
10308c2ecf20Sopenharmony_ci *  activating LPLU this function also disables smart speed
10318c2ecf20Sopenharmony_ci *  and vice versa.  LPLU will not be activated unless the
10328c2ecf20Sopenharmony_ci *  device autonegotiation advertisement meets standards of
10338c2ecf20Sopenharmony_ci *  either 10 or 10/100 or 10/100/1000 at all duplexes.
10348c2ecf20Sopenharmony_ci *  This is a function pointer entry point only called by
10358c2ecf20Sopenharmony_ci *  PHY setup routines.
10368c2ecf20Sopenharmony_ci **/
10378c2ecf20Sopenharmony_cistatic s32 igb_set_d0_lplu_state_82580(struct e1000_hw *hw, bool active)
10388c2ecf20Sopenharmony_ci{
10398c2ecf20Sopenharmony_ci	struct e1000_phy_info *phy = &hw->phy;
10408c2ecf20Sopenharmony_ci	u16 data;
10418c2ecf20Sopenharmony_ci
10428c2ecf20Sopenharmony_ci	data = rd32(E1000_82580_PHY_POWER_MGMT);
10438c2ecf20Sopenharmony_ci
10448c2ecf20Sopenharmony_ci	if (active) {
10458c2ecf20Sopenharmony_ci		data |= E1000_82580_PM_D0_LPLU;
10468c2ecf20Sopenharmony_ci
10478c2ecf20Sopenharmony_ci		/* When LPLU is enabled, we should disable SmartSpeed */
10488c2ecf20Sopenharmony_ci		data &= ~E1000_82580_PM_SPD;
10498c2ecf20Sopenharmony_ci	} else {
10508c2ecf20Sopenharmony_ci		data &= ~E1000_82580_PM_D0_LPLU;
10518c2ecf20Sopenharmony_ci
10528c2ecf20Sopenharmony_ci		/* LPLU and SmartSpeed are mutually exclusive.  LPLU is used
10538c2ecf20Sopenharmony_ci		 * during Dx states where the power conservation is most
10548c2ecf20Sopenharmony_ci		 * important.  During driver activity we should enable
10558c2ecf20Sopenharmony_ci		 * SmartSpeed, so performance is maintained.
10568c2ecf20Sopenharmony_ci		 */
10578c2ecf20Sopenharmony_ci		if (phy->smart_speed == e1000_smart_speed_on)
10588c2ecf20Sopenharmony_ci			data |= E1000_82580_PM_SPD;
10598c2ecf20Sopenharmony_ci		else if (phy->smart_speed == e1000_smart_speed_off)
10608c2ecf20Sopenharmony_ci			data &= ~E1000_82580_PM_SPD; }
10618c2ecf20Sopenharmony_ci
10628c2ecf20Sopenharmony_ci	wr32(E1000_82580_PHY_POWER_MGMT, data);
10638c2ecf20Sopenharmony_ci	return 0;
10648c2ecf20Sopenharmony_ci}
10658c2ecf20Sopenharmony_ci
10668c2ecf20Sopenharmony_ci/**
10678c2ecf20Sopenharmony_ci *  igb_set_d3_lplu_state_82580 - Sets low power link up state for D3
10688c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
10698c2ecf20Sopenharmony_ci *  @active: boolean used to enable/disable lplu
10708c2ecf20Sopenharmony_ci *
10718c2ecf20Sopenharmony_ci *  Success returns 0, Failure returns 1
10728c2ecf20Sopenharmony_ci *
10738c2ecf20Sopenharmony_ci *  The low power link up (lplu) state is set to the power management level D3
10748c2ecf20Sopenharmony_ci *  and SmartSpeed is disabled when active is true, else clear lplu for D3
10758c2ecf20Sopenharmony_ci *  and enable Smartspeed.  LPLU and Smartspeed are mutually exclusive.  LPLU
10768c2ecf20Sopenharmony_ci *  is used during Dx states where the power conservation is most important.
10778c2ecf20Sopenharmony_ci *  During driver activity, SmartSpeed should be enabled so performance is
10788c2ecf20Sopenharmony_ci *  maintained.
10798c2ecf20Sopenharmony_ci **/
10808c2ecf20Sopenharmony_cistatic s32 igb_set_d3_lplu_state_82580(struct e1000_hw *hw, bool active)
10818c2ecf20Sopenharmony_ci{
10828c2ecf20Sopenharmony_ci	struct e1000_phy_info *phy = &hw->phy;
10838c2ecf20Sopenharmony_ci	u16 data;
10848c2ecf20Sopenharmony_ci
10858c2ecf20Sopenharmony_ci	data = rd32(E1000_82580_PHY_POWER_MGMT);
10868c2ecf20Sopenharmony_ci
10878c2ecf20Sopenharmony_ci	if (!active) {
10888c2ecf20Sopenharmony_ci		data &= ~E1000_82580_PM_D3_LPLU;
10898c2ecf20Sopenharmony_ci		/* LPLU and SmartSpeed are mutually exclusive.  LPLU is used
10908c2ecf20Sopenharmony_ci		 * during Dx states where the power conservation is most
10918c2ecf20Sopenharmony_ci		 * important.  During driver activity we should enable
10928c2ecf20Sopenharmony_ci		 * SmartSpeed, so performance is maintained.
10938c2ecf20Sopenharmony_ci		 */
10948c2ecf20Sopenharmony_ci		if (phy->smart_speed == e1000_smart_speed_on)
10958c2ecf20Sopenharmony_ci			data |= E1000_82580_PM_SPD;
10968c2ecf20Sopenharmony_ci		else if (phy->smart_speed == e1000_smart_speed_off)
10978c2ecf20Sopenharmony_ci			data &= ~E1000_82580_PM_SPD;
10988c2ecf20Sopenharmony_ci	} else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
10998c2ecf20Sopenharmony_ci		   (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
11008c2ecf20Sopenharmony_ci		   (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
11018c2ecf20Sopenharmony_ci		data |= E1000_82580_PM_D3_LPLU;
11028c2ecf20Sopenharmony_ci		/* When LPLU is enabled, we should disable SmartSpeed */
11038c2ecf20Sopenharmony_ci		data &= ~E1000_82580_PM_SPD;
11048c2ecf20Sopenharmony_ci	}
11058c2ecf20Sopenharmony_ci
11068c2ecf20Sopenharmony_ci	wr32(E1000_82580_PHY_POWER_MGMT, data);
11078c2ecf20Sopenharmony_ci	return 0;
11088c2ecf20Sopenharmony_ci}
11098c2ecf20Sopenharmony_ci
11108c2ecf20Sopenharmony_ci/**
11118c2ecf20Sopenharmony_ci *  igb_acquire_nvm_82575 - Request for access to EEPROM
11128c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
11138c2ecf20Sopenharmony_ci *
11148c2ecf20Sopenharmony_ci *  Acquire the necessary semaphores for exclusive access to the EEPROM.
11158c2ecf20Sopenharmony_ci *  Set the EEPROM access request bit and wait for EEPROM access grant bit.
11168c2ecf20Sopenharmony_ci *  Return successful if access grant bit set, else clear the request for
11178c2ecf20Sopenharmony_ci *  EEPROM access and return -E1000_ERR_NVM (-1).
11188c2ecf20Sopenharmony_ci **/
11198c2ecf20Sopenharmony_cistatic s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
11208c2ecf20Sopenharmony_ci{
11218c2ecf20Sopenharmony_ci	s32 ret_val;
11228c2ecf20Sopenharmony_ci
11238c2ecf20Sopenharmony_ci	ret_val = hw->mac.ops.acquire_swfw_sync(hw, E1000_SWFW_EEP_SM);
11248c2ecf20Sopenharmony_ci	if (ret_val)
11258c2ecf20Sopenharmony_ci		goto out;
11268c2ecf20Sopenharmony_ci
11278c2ecf20Sopenharmony_ci	ret_val = igb_acquire_nvm(hw);
11288c2ecf20Sopenharmony_ci
11298c2ecf20Sopenharmony_ci	if (ret_val)
11308c2ecf20Sopenharmony_ci		hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
11318c2ecf20Sopenharmony_ci
11328c2ecf20Sopenharmony_ciout:
11338c2ecf20Sopenharmony_ci	return ret_val;
11348c2ecf20Sopenharmony_ci}
11358c2ecf20Sopenharmony_ci
11368c2ecf20Sopenharmony_ci/**
11378c2ecf20Sopenharmony_ci *  igb_release_nvm_82575 - Release exclusive access to EEPROM
11388c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
11398c2ecf20Sopenharmony_ci *
11408c2ecf20Sopenharmony_ci *  Stop any current commands to the EEPROM and clear the EEPROM request bit,
11418c2ecf20Sopenharmony_ci *  then release the semaphores acquired.
11428c2ecf20Sopenharmony_ci **/
11438c2ecf20Sopenharmony_cistatic void igb_release_nvm_82575(struct e1000_hw *hw)
11448c2ecf20Sopenharmony_ci{
11458c2ecf20Sopenharmony_ci	igb_release_nvm(hw);
11468c2ecf20Sopenharmony_ci	hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
11478c2ecf20Sopenharmony_ci}
11488c2ecf20Sopenharmony_ci
11498c2ecf20Sopenharmony_ci/**
11508c2ecf20Sopenharmony_ci *  igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
11518c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
11528c2ecf20Sopenharmony_ci *  @mask: specifies which semaphore to acquire
11538c2ecf20Sopenharmony_ci *
11548c2ecf20Sopenharmony_ci *  Acquire the SW/FW semaphore to access the PHY or NVM.  The mask
11558c2ecf20Sopenharmony_ci *  will also specify which port we're acquiring the lock for.
11568c2ecf20Sopenharmony_ci **/
11578c2ecf20Sopenharmony_cistatic s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
11588c2ecf20Sopenharmony_ci{
11598c2ecf20Sopenharmony_ci	u32 swfw_sync;
11608c2ecf20Sopenharmony_ci	u32 swmask = mask;
11618c2ecf20Sopenharmony_ci	u32 fwmask = mask << 16;
11628c2ecf20Sopenharmony_ci	s32 ret_val = 0;
11638c2ecf20Sopenharmony_ci	s32 i = 0, timeout = 200;
11648c2ecf20Sopenharmony_ci
11658c2ecf20Sopenharmony_ci	while (i < timeout) {
11668c2ecf20Sopenharmony_ci		if (igb_get_hw_semaphore(hw)) {
11678c2ecf20Sopenharmony_ci			ret_val = -E1000_ERR_SWFW_SYNC;
11688c2ecf20Sopenharmony_ci			goto out;
11698c2ecf20Sopenharmony_ci		}
11708c2ecf20Sopenharmony_ci
11718c2ecf20Sopenharmony_ci		swfw_sync = rd32(E1000_SW_FW_SYNC);
11728c2ecf20Sopenharmony_ci		if (!(swfw_sync & (fwmask | swmask)))
11738c2ecf20Sopenharmony_ci			break;
11748c2ecf20Sopenharmony_ci
11758c2ecf20Sopenharmony_ci		/* Firmware currently using resource (fwmask)
11768c2ecf20Sopenharmony_ci		 * or other software thread using resource (swmask)
11778c2ecf20Sopenharmony_ci		 */
11788c2ecf20Sopenharmony_ci		igb_put_hw_semaphore(hw);
11798c2ecf20Sopenharmony_ci		mdelay(5);
11808c2ecf20Sopenharmony_ci		i++;
11818c2ecf20Sopenharmony_ci	}
11828c2ecf20Sopenharmony_ci
11838c2ecf20Sopenharmony_ci	if (i == timeout) {
11848c2ecf20Sopenharmony_ci		hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
11858c2ecf20Sopenharmony_ci		ret_val = -E1000_ERR_SWFW_SYNC;
11868c2ecf20Sopenharmony_ci		goto out;
11878c2ecf20Sopenharmony_ci	}
11888c2ecf20Sopenharmony_ci
11898c2ecf20Sopenharmony_ci	swfw_sync |= swmask;
11908c2ecf20Sopenharmony_ci	wr32(E1000_SW_FW_SYNC, swfw_sync);
11918c2ecf20Sopenharmony_ci
11928c2ecf20Sopenharmony_ci	igb_put_hw_semaphore(hw);
11938c2ecf20Sopenharmony_ci
11948c2ecf20Sopenharmony_ciout:
11958c2ecf20Sopenharmony_ci	return ret_val;
11968c2ecf20Sopenharmony_ci}
11978c2ecf20Sopenharmony_ci
11988c2ecf20Sopenharmony_ci/**
11998c2ecf20Sopenharmony_ci *  igb_release_swfw_sync_82575 - Release SW/FW semaphore
12008c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
12018c2ecf20Sopenharmony_ci *  @mask: specifies which semaphore to acquire
12028c2ecf20Sopenharmony_ci *
12038c2ecf20Sopenharmony_ci *  Release the SW/FW semaphore used to access the PHY or NVM.  The mask
12048c2ecf20Sopenharmony_ci *  will also specify which port we're releasing the lock for.
12058c2ecf20Sopenharmony_ci **/
12068c2ecf20Sopenharmony_cistatic void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
12078c2ecf20Sopenharmony_ci{
12088c2ecf20Sopenharmony_ci	u32 swfw_sync;
12098c2ecf20Sopenharmony_ci
12108c2ecf20Sopenharmony_ci	while (igb_get_hw_semaphore(hw) != 0)
12118c2ecf20Sopenharmony_ci		; /* Empty */
12128c2ecf20Sopenharmony_ci
12138c2ecf20Sopenharmony_ci	swfw_sync = rd32(E1000_SW_FW_SYNC);
12148c2ecf20Sopenharmony_ci	swfw_sync &= ~mask;
12158c2ecf20Sopenharmony_ci	wr32(E1000_SW_FW_SYNC, swfw_sync);
12168c2ecf20Sopenharmony_ci
12178c2ecf20Sopenharmony_ci	igb_put_hw_semaphore(hw);
12188c2ecf20Sopenharmony_ci}
12198c2ecf20Sopenharmony_ci
12208c2ecf20Sopenharmony_ci/**
12218c2ecf20Sopenharmony_ci *  igb_get_cfg_done_82575 - Read config done bit
12228c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
12238c2ecf20Sopenharmony_ci *
12248c2ecf20Sopenharmony_ci *  Read the management control register for the config done bit for
12258c2ecf20Sopenharmony_ci *  completion status.  NOTE: silicon which is EEPROM-less will fail trying
12268c2ecf20Sopenharmony_ci *  to read the config done bit, so an error is *ONLY* logged and returns
12278c2ecf20Sopenharmony_ci *  0.  If we were to return with error, EEPROM-less silicon
12288c2ecf20Sopenharmony_ci *  would not be able to be reset or change link.
12298c2ecf20Sopenharmony_ci **/
12308c2ecf20Sopenharmony_cistatic s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
12318c2ecf20Sopenharmony_ci{
12328c2ecf20Sopenharmony_ci	s32 timeout = PHY_CFG_TIMEOUT;
12338c2ecf20Sopenharmony_ci	u32 mask = E1000_NVM_CFG_DONE_PORT_0;
12348c2ecf20Sopenharmony_ci
12358c2ecf20Sopenharmony_ci	if (hw->bus.func == 1)
12368c2ecf20Sopenharmony_ci		mask = E1000_NVM_CFG_DONE_PORT_1;
12378c2ecf20Sopenharmony_ci	else if (hw->bus.func == E1000_FUNC_2)
12388c2ecf20Sopenharmony_ci		mask = E1000_NVM_CFG_DONE_PORT_2;
12398c2ecf20Sopenharmony_ci	else if (hw->bus.func == E1000_FUNC_3)
12408c2ecf20Sopenharmony_ci		mask = E1000_NVM_CFG_DONE_PORT_3;
12418c2ecf20Sopenharmony_ci
12428c2ecf20Sopenharmony_ci	while (timeout) {
12438c2ecf20Sopenharmony_ci		if (rd32(E1000_EEMNGCTL) & mask)
12448c2ecf20Sopenharmony_ci			break;
12458c2ecf20Sopenharmony_ci		usleep_range(1000, 2000);
12468c2ecf20Sopenharmony_ci		timeout--;
12478c2ecf20Sopenharmony_ci	}
12488c2ecf20Sopenharmony_ci	if (!timeout)
12498c2ecf20Sopenharmony_ci		hw_dbg("MNG configuration cycle has not completed.\n");
12508c2ecf20Sopenharmony_ci
12518c2ecf20Sopenharmony_ci	/* If EEPROM is not marked present, init the PHY manually */
12528c2ecf20Sopenharmony_ci	if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
12538c2ecf20Sopenharmony_ci	    (hw->phy.type == e1000_phy_igp_3))
12548c2ecf20Sopenharmony_ci		igb_phy_init_script_igp3(hw);
12558c2ecf20Sopenharmony_ci
12568c2ecf20Sopenharmony_ci	return 0;
12578c2ecf20Sopenharmony_ci}
12588c2ecf20Sopenharmony_ci
12598c2ecf20Sopenharmony_ci/**
12608c2ecf20Sopenharmony_ci *  igb_get_link_up_info_82575 - Get link speed/duplex info
12618c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
12628c2ecf20Sopenharmony_ci *  @speed: stores the current speed
12638c2ecf20Sopenharmony_ci *  @duplex: stores the current duplex
12648c2ecf20Sopenharmony_ci *
12658c2ecf20Sopenharmony_ci *  This is a wrapper function, if using the serial gigabit media independent
12668c2ecf20Sopenharmony_ci *  interface, use PCS to retrieve the link speed and duplex information.
12678c2ecf20Sopenharmony_ci *  Otherwise, use the generic function to get the link speed and duplex info.
12688c2ecf20Sopenharmony_ci **/
12698c2ecf20Sopenharmony_cistatic s32 igb_get_link_up_info_82575(struct e1000_hw *hw, u16 *speed,
12708c2ecf20Sopenharmony_ci					u16 *duplex)
12718c2ecf20Sopenharmony_ci{
12728c2ecf20Sopenharmony_ci	s32 ret_val;
12738c2ecf20Sopenharmony_ci
12748c2ecf20Sopenharmony_ci	if (hw->phy.media_type != e1000_media_type_copper)
12758c2ecf20Sopenharmony_ci		ret_val = igb_get_pcs_speed_and_duplex_82575(hw, speed,
12768c2ecf20Sopenharmony_ci							       duplex);
12778c2ecf20Sopenharmony_ci	else
12788c2ecf20Sopenharmony_ci		ret_val = igb_get_speed_and_duplex_copper(hw, speed,
12798c2ecf20Sopenharmony_ci								    duplex);
12808c2ecf20Sopenharmony_ci
12818c2ecf20Sopenharmony_ci	return ret_val;
12828c2ecf20Sopenharmony_ci}
12838c2ecf20Sopenharmony_ci
12848c2ecf20Sopenharmony_ci/**
12858c2ecf20Sopenharmony_ci *  igb_check_for_link_82575 - Check for link
12868c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
12878c2ecf20Sopenharmony_ci *
12888c2ecf20Sopenharmony_ci *  If sgmii is enabled, then use the pcs register to determine link, otherwise
12898c2ecf20Sopenharmony_ci *  use the generic interface for determining link.
12908c2ecf20Sopenharmony_ci **/
12918c2ecf20Sopenharmony_cistatic s32 igb_check_for_link_82575(struct e1000_hw *hw)
12928c2ecf20Sopenharmony_ci{
12938c2ecf20Sopenharmony_ci	s32 ret_val;
12948c2ecf20Sopenharmony_ci	u16 speed, duplex;
12958c2ecf20Sopenharmony_ci
12968c2ecf20Sopenharmony_ci	if (hw->phy.media_type != e1000_media_type_copper) {
12978c2ecf20Sopenharmony_ci		ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
12988c2ecf20Sopenharmony_ci							     &duplex);
12998c2ecf20Sopenharmony_ci		/* Use this flag to determine if link needs to be checked or
13008c2ecf20Sopenharmony_ci		 * not.  If  we have link clear the flag so that we do not
13018c2ecf20Sopenharmony_ci		 * continue to check for link.
13028c2ecf20Sopenharmony_ci		 */
13038c2ecf20Sopenharmony_ci		hw->mac.get_link_status = !hw->mac.serdes_has_link;
13048c2ecf20Sopenharmony_ci
13058c2ecf20Sopenharmony_ci		/* Configure Flow Control now that Auto-Neg has completed.
13068c2ecf20Sopenharmony_ci		 * First, we need to restore the desired flow control
13078c2ecf20Sopenharmony_ci		 * settings because we may have had to re-autoneg with a
13088c2ecf20Sopenharmony_ci		 * different link partner.
13098c2ecf20Sopenharmony_ci		 */
13108c2ecf20Sopenharmony_ci		ret_val = igb_config_fc_after_link_up(hw);
13118c2ecf20Sopenharmony_ci		if (ret_val)
13128c2ecf20Sopenharmony_ci			hw_dbg("Error configuring flow control\n");
13138c2ecf20Sopenharmony_ci	} else {
13148c2ecf20Sopenharmony_ci		ret_val = igb_check_for_copper_link(hw);
13158c2ecf20Sopenharmony_ci	}
13168c2ecf20Sopenharmony_ci
13178c2ecf20Sopenharmony_ci	return ret_val;
13188c2ecf20Sopenharmony_ci}
13198c2ecf20Sopenharmony_ci
13208c2ecf20Sopenharmony_ci/**
13218c2ecf20Sopenharmony_ci *  igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown
13228c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
13238c2ecf20Sopenharmony_ci **/
13248c2ecf20Sopenharmony_civoid igb_power_up_serdes_link_82575(struct e1000_hw *hw)
13258c2ecf20Sopenharmony_ci{
13268c2ecf20Sopenharmony_ci	u32 reg;
13278c2ecf20Sopenharmony_ci
13288c2ecf20Sopenharmony_ci
13298c2ecf20Sopenharmony_ci	if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
13308c2ecf20Sopenharmony_ci	    !igb_sgmii_active_82575(hw))
13318c2ecf20Sopenharmony_ci		return;
13328c2ecf20Sopenharmony_ci
13338c2ecf20Sopenharmony_ci	/* Enable PCS to turn on link */
13348c2ecf20Sopenharmony_ci	reg = rd32(E1000_PCS_CFG0);
13358c2ecf20Sopenharmony_ci	reg |= E1000_PCS_CFG_PCS_EN;
13368c2ecf20Sopenharmony_ci	wr32(E1000_PCS_CFG0, reg);
13378c2ecf20Sopenharmony_ci
13388c2ecf20Sopenharmony_ci	/* Power up the laser */
13398c2ecf20Sopenharmony_ci	reg = rd32(E1000_CTRL_EXT);
13408c2ecf20Sopenharmony_ci	reg &= ~E1000_CTRL_EXT_SDP3_DATA;
13418c2ecf20Sopenharmony_ci	wr32(E1000_CTRL_EXT, reg);
13428c2ecf20Sopenharmony_ci
13438c2ecf20Sopenharmony_ci	/* flush the write to verify completion */
13448c2ecf20Sopenharmony_ci	wrfl();
13458c2ecf20Sopenharmony_ci	usleep_range(1000, 2000);
13468c2ecf20Sopenharmony_ci}
13478c2ecf20Sopenharmony_ci
13488c2ecf20Sopenharmony_ci/**
13498c2ecf20Sopenharmony_ci *  igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
13508c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
13518c2ecf20Sopenharmony_ci *  @speed: stores the current speed
13528c2ecf20Sopenharmony_ci *  @duplex: stores the current duplex
13538c2ecf20Sopenharmony_ci *
13548c2ecf20Sopenharmony_ci *  Using the physical coding sub-layer (PCS), retrieve the current speed and
13558c2ecf20Sopenharmony_ci *  duplex, then store the values in the pointers provided.
13568c2ecf20Sopenharmony_ci **/
13578c2ecf20Sopenharmony_cistatic s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
13588c2ecf20Sopenharmony_ci						u16 *duplex)
13598c2ecf20Sopenharmony_ci{
13608c2ecf20Sopenharmony_ci	struct e1000_mac_info *mac = &hw->mac;
13618c2ecf20Sopenharmony_ci	u32 pcs, status;
13628c2ecf20Sopenharmony_ci
13638c2ecf20Sopenharmony_ci	/* Set up defaults for the return values of this function */
13648c2ecf20Sopenharmony_ci	mac->serdes_has_link = false;
13658c2ecf20Sopenharmony_ci	*speed = 0;
13668c2ecf20Sopenharmony_ci	*duplex = 0;
13678c2ecf20Sopenharmony_ci
13688c2ecf20Sopenharmony_ci	/* Read the PCS Status register for link state. For non-copper mode,
13698c2ecf20Sopenharmony_ci	 * the status register is not accurate. The PCS status register is
13708c2ecf20Sopenharmony_ci	 * used instead.
13718c2ecf20Sopenharmony_ci	 */
13728c2ecf20Sopenharmony_ci	pcs = rd32(E1000_PCS_LSTAT);
13738c2ecf20Sopenharmony_ci
13748c2ecf20Sopenharmony_ci	/* The link up bit determines when link is up on autoneg. The sync ok
13758c2ecf20Sopenharmony_ci	 * gets set once both sides sync up and agree upon link. Stable link
13768c2ecf20Sopenharmony_ci	 * can be determined by checking for both link up and link sync ok
13778c2ecf20Sopenharmony_ci	 */
13788c2ecf20Sopenharmony_ci	if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
13798c2ecf20Sopenharmony_ci		mac->serdes_has_link = true;
13808c2ecf20Sopenharmony_ci
13818c2ecf20Sopenharmony_ci		/* Detect and store PCS speed */
13828c2ecf20Sopenharmony_ci		if (pcs & E1000_PCS_LSTS_SPEED_1000)
13838c2ecf20Sopenharmony_ci			*speed = SPEED_1000;
13848c2ecf20Sopenharmony_ci		else if (pcs & E1000_PCS_LSTS_SPEED_100)
13858c2ecf20Sopenharmony_ci			*speed = SPEED_100;
13868c2ecf20Sopenharmony_ci		else
13878c2ecf20Sopenharmony_ci			*speed = SPEED_10;
13888c2ecf20Sopenharmony_ci
13898c2ecf20Sopenharmony_ci		/* Detect and store PCS duplex */
13908c2ecf20Sopenharmony_ci		if (pcs & E1000_PCS_LSTS_DUPLEX_FULL)
13918c2ecf20Sopenharmony_ci			*duplex = FULL_DUPLEX;
13928c2ecf20Sopenharmony_ci		else
13938c2ecf20Sopenharmony_ci			*duplex = HALF_DUPLEX;
13948c2ecf20Sopenharmony_ci
13958c2ecf20Sopenharmony_ci	/* Check if it is an I354 2.5Gb backplane connection. */
13968c2ecf20Sopenharmony_ci		if (mac->type == e1000_i354) {
13978c2ecf20Sopenharmony_ci			status = rd32(E1000_STATUS);
13988c2ecf20Sopenharmony_ci			if ((status & E1000_STATUS_2P5_SKU) &&
13998c2ecf20Sopenharmony_ci			    !(status & E1000_STATUS_2P5_SKU_OVER)) {
14008c2ecf20Sopenharmony_ci				*speed = SPEED_2500;
14018c2ecf20Sopenharmony_ci				*duplex = FULL_DUPLEX;
14028c2ecf20Sopenharmony_ci				hw_dbg("2500 Mbs, ");
14038c2ecf20Sopenharmony_ci				hw_dbg("Full Duplex\n");
14048c2ecf20Sopenharmony_ci			}
14058c2ecf20Sopenharmony_ci		}
14068c2ecf20Sopenharmony_ci
14078c2ecf20Sopenharmony_ci	}
14088c2ecf20Sopenharmony_ci
14098c2ecf20Sopenharmony_ci	return 0;
14108c2ecf20Sopenharmony_ci}
14118c2ecf20Sopenharmony_ci
14128c2ecf20Sopenharmony_ci/**
14138c2ecf20Sopenharmony_ci *  igb_shutdown_serdes_link_82575 - Remove link during power down
14148c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
14158c2ecf20Sopenharmony_ci *
14168c2ecf20Sopenharmony_ci *  In the case of fiber serdes, shut down optics and PCS on driver unload
14178c2ecf20Sopenharmony_ci *  when management pass thru is not enabled.
14188c2ecf20Sopenharmony_ci **/
14198c2ecf20Sopenharmony_civoid igb_shutdown_serdes_link_82575(struct e1000_hw *hw)
14208c2ecf20Sopenharmony_ci{
14218c2ecf20Sopenharmony_ci	u32 reg;
14228c2ecf20Sopenharmony_ci
14238c2ecf20Sopenharmony_ci	if (hw->phy.media_type != e1000_media_type_internal_serdes &&
14248c2ecf20Sopenharmony_ci	    igb_sgmii_active_82575(hw))
14258c2ecf20Sopenharmony_ci		return;
14268c2ecf20Sopenharmony_ci
14278c2ecf20Sopenharmony_ci	if (!igb_enable_mng_pass_thru(hw)) {
14288c2ecf20Sopenharmony_ci		/* Disable PCS to turn off link */
14298c2ecf20Sopenharmony_ci		reg = rd32(E1000_PCS_CFG0);
14308c2ecf20Sopenharmony_ci		reg &= ~E1000_PCS_CFG_PCS_EN;
14318c2ecf20Sopenharmony_ci		wr32(E1000_PCS_CFG0, reg);
14328c2ecf20Sopenharmony_ci
14338c2ecf20Sopenharmony_ci		/* shutdown the laser */
14348c2ecf20Sopenharmony_ci		reg = rd32(E1000_CTRL_EXT);
14358c2ecf20Sopenharmony_ci		reg |= E1000_CTRL_EXT_SDP3_DATA;
14368c2ecf20Sopenharmony_ci		wr32(E1000_CTRL_EXT, reg);
14378c2ecf20Sopenharmony_ci
14388c2ecf20Sopenharmony_ci		/* flush the write to verify completion */
14398c2ecf20Sopenharmony_ci		wrfl();
14408c2ecf20Sopenharmony_ci		usleep_range(1000, 2000);
14418c2ecf20Sopenharmony_ci	}
14428c2ecf20Sopenharmony_ci}
14438c2ecf20Sopenharmony_ci
14448c2ecf20Sopenharmony_ci/**
14458c2ecf20Sopenharmony_ci *  igb_reset_hw_82575 - Reset hardware
14468c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
14478c2ecf20Sopenharmony_ci *
14488c2ecf20Sopenharmony_ci *  This resets the hardware into a known state.  This is a
14498c2ecf20Sopenharmony_ci *  function pointer entry point called by the api module.
14508c2ecf20Sopenharmony_ci **/
14518c2ecf20Sopenharmony_cistatic s32 igb_reset_hw_82575(struct e1000_hw *hw)
14528c2ecf20Sopenharmony_ci{
14538c2ecf20Sopenharmony_ci	u32 ctrl;
14548c2ecf20Sopenharmony_ci	s32 ret_val;
14558c2ecf20Sopenharmony_ci
14568c2ecf20Sopenharmony_ci	/* Prevent the PCI-E bus from sticking if there is no TLP connection
14578c2ecf20Sopenharmony_ci	 * on the last TLP read/write transaction when MAC is reset.
14588c2ecf20Sopenharmony_ci	 */
14598c2ecf20Sopenharmony_ci	ret_val = igb_disable_pcie_master(hw);
14608c2ecf20Sopenharmony_ci	if (ret_val)
14618c2ecf20Sopenharmony_ci		hw_dbg("PCI-E Master disable polling has failed.\n");
14628c2ecf20Sopenharmony_ci
14638c2ecf20Sopenharmony_ci	/* set the completion timeout for interface */
14648c2ecf20Sopenharmony_ci	ret_val = igb_set_pcie_completion_timeout(hw);
14658c2ecf20Sopenharmony_ci	if (ret_val)
14668c2ecf20Sopenharmony_ci		hw_dbg("PCI-E Set completion timeout has failed.\n");
14678c2ecf20Sopenharmony_ci
14688c2ecf20Sopenharmony_ci	hw_dbg("Masking off all interrupts\n");
14698c2ecf20Sopenharmony_ci	wr32(E1000_IMC, 0xffffffff);
14708c2ecf20Sopenharmony_ci
14718c2ecf20Sopenharmony_ci	wr32(E1000_RCTL, 0);
14728c2ecf20Sopenharmony_ci	wr32(E1000_TCTL, E1000_TCTL_PSP);
14738c2ecf20Sopenharmony_ci	wrfl();
14748c2ecf20Sopenharmony_ci
14758c2ecf20Sopenharmony_ci	usleep_range(10000, 20000);
14768c2ecf20Sopenharmony_ci
14778c2ecf20Sopenharmony_ci	ctrl = rd32(E1000_CTRL);
14788c2ecf20Sopenharmony_ci
14798c2ecf20Sopenharmony_ci	hw_dbg("Issuing a global reset to MAC\n");
14808c2ecf20Sopenharmony_ci	wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
14818c2ecf20Sopenharmony_ci
14828c2ecf20Sopenharmony_ci	ret_val = igb_get_auto_rd_done(hw);
14838c2ecf20Sopenharmony_ci	if (ret_val) {
14848c2ecf20Sopenharmony_ci		/* When auto config read does not complete, do not
14858c2ecf20Sopenharmony_ci		 * return with an error. This can happen in situations
14868c2ecf20Sopenharmony_ci		 * where there is no eeprom and prevents getting link.
14878c2ecf20Sopenharmony_ci		 */
14888c2ecf20Sopenharmony_ci		hw_dbg("Auto Read Done did not complete\n");
14898c2ecf20Sopenharmony_ci	}
14908c2ecf20Sopenharmony_ci
14918c2ecf20Sopenharmony_ci	/* If EEPROM is not present, run manual init scripts */
14928c2ecf20Sopenharmony_ci	if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
14938c2ecf20Sopenharmony_ci		igb_reset_init_script_82575(hw);
14948c2ecf20Sopenharmony_ci
14958c2ecf20Sopenharmony_ci	/* Clear any pending interrupt events. */
14968c2ecf20Sopenharmony_ci	wr32(E1000_IMC, 0xffffffff);
14978c2ecf20Sopenharmony_ci	rd32(E1000_ICR);
14988c2ecf20Sopenharmony_ci
14998c2ecf20Sopenharmony_ci	/* Install any alternate MAC address into RAR0 */
15008c2ecf20Sopenharmony_ci	ret_val = igb_check_alt_mac_addr(hw);
15018c2ecf20Sopenharmony_ci
15028c2ecf20Sopenharmony_ci	return ret_val;
15038c2ecf20Sopenharmony_ci}
15048c2ecf20Sopenharmony_ci
15058c2ecf20Sopenharmony_ci/**
15068c2ecf20Sopenharmony_ci *  igb_init_hw_82575 - Initialize hardware
15078c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
15088c2ecf20Sopenharmony_ci *
15098c2ecf20Sopenharmony_ci *  This inits the hardware readying it for operation.
15108c2ecf20Sopenharmony_ci **/
15118c2ecf20Sopenharmony_cistatic s32 igb_init_hw_82575(struct e1000_hw *hw)
15128c2ecf20Sopenharmony_ci{
15138c2ecf20Sopenharmony_ci	struct e1000_mac_info *mac = &hw->mac;
15148c2ecf20Sopenharmony_ci	s32 ret_val;
15158c2ecf20Sopenharmony_ci	u16 i, rar_count = mac->rar_entry_count;
15168c2ecf20Sopenharmony_ci
15178c2ecf20Sopenharmony_ci	if ((hw->mac.type >= e1000_i210) &&
15188c2ecf20Sopenharmony_ci	    !(igb_get_flash_presence_i210(hw))) {
15198c2ecf20Sopenharmony_ci		ret_val = igb_pll_workaround_i210(hw);
15208c2ecf20Sopenharmony_ci		if (ret_val)
15218c2ecf20Sopenharmony_ci			return ret_val;
15228c2ecf20Sopenharmony_ci	}
15238c2ecf20Sopenharmony_ci
15248c2ecf20Sopenharmony_ci	/* Initialize identification LED */
15258c2ecf20Sopenharmony_ci	ret_val = igb_id_led_init(hw);
15268c2ecf20Sopenharmony_ci	if (ret_val) {
15278c2ecf20Sopenharmony_ci		hw_dbg("Error initializing identification LED\n");
15288c2ecf20Sopenharmony_ci		/* This is not fatal and we should not stop init due to this */
15298c2ecf20Sopenharmony_ci	}
15308c2ecf20Sopenharmony_ci
15318c2ecf20Sopenharmony_ci	/* Disabling VLAN filtering */
15328c2ecf20Sopenharmony_ci	hw_dbg("Initializing the IEEE VLAN\n");
15338c2ecf20Sopenharmony_ci	igb_clear_vfta(hw);
15348c2ecf20Sopenharmony_ci
15358c2ecf20Sopenharmony_ci	/* Setup the receive address */
15368c2ecf20Sopenharmony_ci	igb_init_rx_addrs(hw, rar_count);
15378c2ecf20Sopenharmony_ci
15388c2ecf20Sopenharmony_ci	/* Zero out the Multicast HASH table */
15398c2ecf20Sopenharmony_ci	hw_dbg("Zeroing the MTA\n");
15408c2ecf20Sopenharmony_ci	for (i = 0; i < mac->mta_reg_count; i++)
15418c2ecf20Sopenharmony_ci		array_wr32(E1000_MTA, i, 0);
15428c2ecf20Sopenharmony_ci
15438c2ecf20Sopenharmony_ci	/* Zero out the Unicast HASH table */
15448c2ecf20Sopenharmony_ci	hw_dbg("Zeroing the UTA\n");
15458c2ecf20Sopenharmony_ci	for (i = 0; i < mac->uta_reg_count; i++)
15468c2ecf20Sopenharmony_ci		array_wr32(E1000_UTA, i, 0);
15478c2ecf20Sopenharmony_ci
15488c2ecf20Sopenharmony_ci	/* Setup link and flow control */
15498c2ecf20Sopenharmony_ci	ret_val = igb_setup_link(hw);
15508c2ecf20Sopenharmony_ci
15518c2ecf20Sopenharmony_ci	/* Clear all of the statistics registers (clear on read).  It is
15528c2ecf20Sopenharmony_ci	 * important that we do this after we have tried to establish link
15538c2ecf20Sopenharmony_ci	 * because the symbol error count will increment wildly if there
15548c2ecf20Sopenharmony_ci	 * is no link.
15558c2ecf20Sopenharmony_ci	 */
15568c2ecf20Sopenharmony_ci	igb_clear_hw_cntrs_82575(hw);
15578c2ecf20Sopenharmony_ci	return ret_val;
15588c2ecf20Sopenharmony_ci}
15598c2ecf20Sopenharmony_ci
15608c2ecf20Sopenharmony_ci/**
15618c2ecf20Sopenharmony_ci *  igb_setup_copper_link_82575 - Configure copper link settings
15628c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
15638c2ecf20Sopenharmony_ci *
15648c2ecf20Sopenharmony_ci *  Configures the link for auto-neg or forced speed and duplex.  Then we check
15658c2ecf20Sopenharmony_ci *  for link, once link is established calls to configure collision distance
15668c2ecf20Sopenharmony_ci *  and flow control are called.
15678c2ecf20Sopenharmony_ci **/
15688c2ecf20Sopenharmony_cistatic s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
15698c2ecf20Sopenharmony_ci{
15708c2ecf20Sopenharmony_ci	u32 ctrl;
15718c2ecf20Sopenharmony_ci	s32  ret_val;
15728c2ecf20Sopenharmony_ci	u32 phpm_reg;
15738c2ecf20Sopenharmony_ci
15748c2ecf20Sopenharmony_ci	ctrl = rd32(E1000_CTRL);
15758c2ecf20Sopenharmony_ci	ctrl |= E1000_CTRL_SLU;
15768c2ecf20Sopenharmony_ci	ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
15778c2ecf20Sopenharmony_ci	wr32(E1000_CTRL, ctrl);
15788c2ecf20Sopenharmony_ci
15798c2ecf20Sopenharmony_ci	/* Clear Go Link Disconnect bit on supported devices */
15808c2ecf20Sopenharmony_ci	switch (hw->mac.type) {
15818c2ecf20Sopenharmony_ci	case e1000_82580:
15828c2ecf20Sopenharmony_ci	case e1000_i350:
15838c2ecf20Sopenharmony_ci	case e1000_i210:
15848c2ecf20Sopenharmony_ci	case e1000_i211:
15858c2ecf20Sopenharmony_ci		phpm_reg = rd32(E1000_82580_PHY_POWER_MGMT);
15868c2ecf20Sopenharmony_ci		phpm_reg &= ~E1000_82580_PM_GO_LINKD;
15878c2ecf20Sopenharmony_ci		wr32(E1000_82580_PHY_POWER_MGMT, phpm_reg);
15888c2ecf20Sopenharmony_ci		break;
15898c2ecf20Sopenharmony_ci	default:
15908c2ecf20Sopenharmony_ci		break;
15918c2ecf20Sopenharmony_ci	}
15928c2ecf20Sopenharmony_ci
15938c2ecf20Sopenharmony_ci	ret_val = igb_setup_serdes_link_82575(hw);
15948c2ecf20Sopenharmony_ci	if (ret_val)
15958c2ecf20Sopenharmony_ci		goto out;
15968c2ecf20Sopenharmony_ci
15978c2ecf20Sopenharmony_ci	if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
15988c2ecf20Sopenharmony_ci		/* allow time for SFP cage time to power up phy */
15998c2ecf20Sopenharmony_ci		msleep(300);
16008c2ecf20Sopenharmony_ci
16018c2ecf20Sopenharmony_ci		ret_val = hw->phy.ops.reset(hw);
16028c2ecf20Sopenharmony_ci		if (ret_val) {
16038c2ecf20Sopenharmony_ci			hw_dbg("Error resetting the PHY.\n");
16048c2ecf20Sopenharmony_ci			goto out;
16058c2ecf20Sopenharmony_ci		}
16068c2ecf20Sopenharmony_ci	}
16078c2ecf20Sopenharmony_ci	switch (hw->phy.type) {
16088c2ecf20Sopenharmony_ci	case e1000_phy_i210:
16098c2ecf20Sopenharmony_ci	case e1000_phy_m88:
16108c2ecf20Sopenharmony_ci		switch (hw->phy.id) {
16118c2ecf20Sopenharmony_ci		case I347AT4_E_PHY_ID:
16128c2ecf20Sopenharmony_ci		case M88E1112_E_PHY_ID:
16138c2ecf20Sopenharmony_ci		case M88E1543_E_PHY_ID:
16148c2ecf20Sopenharmony_ci		case M88E1512_E_PHY_ID:
16158c2ecf20Sopenharmony_ci		case I210_I_PHY_ID:
16168c2ecf20Sopenharmony_ci			ret_val = igb_copper_link_setup_m88_gen2(hw);
16178c2ecf20Sopenharmony_ci			break;
16188c2ecf20Sopenharmony_ci		default:
16198c2ecf20Sopenharmony_ci			ret_val = igb_copper_link_setup_m88(hw);
16208c2ecf20Sopenharmony_ci			break;
16218c2ecf20Sopenharmony_ci		}
16228c2ecf20Sopenharmony_ci		break;
16238c2ecf20Sopenharmony_ci	case e1000_phy_igp_3:
16248c2ecf20Sopenharmony_ci		ret_val = igb_copper_link_setup_igp(hw);
16258c2ecf20Sopenharmony_ci		break;
16268c2ecf20Sopenharmony_ci	case e1000_phy_82580:
16278c2ecf20Sopenharmony_ci		ret_val = igb_copper_link_setup_82580(hw);
16288c2ecf20Sopenharmony_ci		break;
16298c2ecf20Sopenharmony_ci	case e1000_phy_bcm54616:
16308c2ecf20Sopenharmony_ci		ret_val = 0;
16318c2ecf20Sopenharmony_ci		break;
16328c2ecf20Sopenharmony_ci	default:
16338c2ecf20Sopenharmony_ci		ret_val = -E1000_ERR_PHY;
16348c2ecf20Sopenharmony_ci		break;
16358c2ecf20Sopenharmony_ci	}
16368c2ecf20Sopenharmony_ci
16378c2ecf20Sopenharmony_ci	if (ret_val)
16388c2ecf20Sopenharmony_ci		goto out;
16398c2ecf20Sopenharmony_ci
16408c2ecf20Sopenharmony_ci	ret_val = igb_setup_copper_link(hw);
16418c2ecf20Sopenharmony_ciout:
16428c2ecf20Sopenharmony_ci	return ret_val;
16438c2ecf20Sopenharmony_ci}
16448c2ecf20Sopenharmony_ci
16458c2ecf20Sopenharmony_ci/**
16468c2ecf20Sopenharmony_ci *  igb_setup_serdes_link_82575 - Setup link for serdes
16478c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
16488c2ecf20Sopenharmony_ci *
16498c2ecf20Sopenharmony_ci *  Configure the physical coding sub-layer (PCS) link.  The PCS link is
16508c2ecf20Sopenharmony_ci *  used on copper connections where the serialized gigabit media independent
16518c2ecf20Sopenharmony_ci *  interface (sgmii), or serdes fiber is being used.  Configures the link
16528c2ecf20Sopenharmony_ci *  for auto-negotiation or forces speed/duplex.
16538c2ecf20Sopenharmony_ci **/
16548c2ecf20Sopenharmony_cistatic s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
16558c2ecf20Sopenharmony_ci{
16568c2ecf20Sopenharmony_ci	u32 ctrl_ext, ctrl_reg, reg, anadv_reg;
16578c2ecf20Sopenharmony_ci	bool pcs_autoneg;
16588c2ecf20Sopenharmony_ci	s32 ret_val = 0;
16598c2ecf20Sopenharmony_ci	u16 data;
16608c2ecf20Sopenharmony_ci
16618c2ecf20Sopenharmony_ci	if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
16628c2ecf20Sopenharmony_ci	    !igb_sgmii_active_82575(hw))
16638c2ecf20Sopenharmony_ci		return ret_val;
16648c2ecf20Sopenharmony_ci
16658c2ecf20Sopenharmony_ci
16668c2ecf20Sopenharmony_ci	/* On the 82575, SerDes loopback mode persists until it is
16678c2ecf20Sopenharmony_ci	 * explicitly turned off or a power cycle is performed.  A read to
16688c2ecf20Sopenharmony_ci	 * the register does not indicate its status.  Therefore, we ensure
16698c2ecf20Sopenharmony_ci	 * loopback mode is disabled during initialization.
16708c2ecf20Sopenharmony_ci	 */
16718c2ecf20Sopenharmony_ci	wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
16728c2ecf20Sopenharmony_ci
16738c2ecf20Sopenharmony_ci	/* power on the sfp cage if present and turn on I2C */
16748c2ecf20Sopenharmony_ci	ctrl_ext = rd32(E1000_CTRL_EXT);
16758c2ecf20Sopenharmony_ci	ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
16768c2ecf20Sopenharmony_ci	ctrl_ext |= E1000_CTRL_I2C_ENA;
16778c2ecf20Sopenharmony_ci	wr32(E1000_CTRL_EXT, ctrl_ext);
16788c2ecf20Sopenharmony_ci
16798c2ecf20Sopenharmony_ci	ctrl_reg = rd32(E1000_CTRL);
16808c2ecf20Sopenharmony_ci	ctrl_reg |= E1000_CTRL_SLU;
16818c2ecf20Sopenharmony_ci
16828c2ecf20Sopenharmony_ci	if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
16838c2ecf20Sopenharmony_ci		/* set both sw defined pins */
16848c2ecf20Sopenharmony_ci		ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
16858c2ecf20Sopenharmony_ci
16868c2ecf20Sopenharmony_ci		/* Set switch control to serdes energy detect */
16878c2ecf20Sopenharmony_ci		reg = rd32(E1000_CONNSW);
16888c2ecf20Sopenharmony_ci		reg |= E1000_CONNSW_ENRGSRC;
16898c2ecf20Sopenharmony_ci		wr32(E1000_CONNSW, reg);
16908c2ecf20Sopenharmony_ci	}
16918c2ecf20Sopenharmony_ci
16928c2ecf20Sopenharmony_ci	reg = rd32(E1000_PCS_LCTL);
16938c2ecf20Sopenharmony_ci
16948c2ecf20Sopenharmony_ci	/* default pcs_autoneg to the same setting as mac autoneg */
16958c2ecf20Sopenharmony_ci	pcs_autoneg = hw->mac.autoneg;
16968c2ecf20Sopenharmony_ci
16978c2ecf20Sopenharmony_ci	switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
16988c2ecf20Sopenharmony_ci	case E1000_CTRL_EXT_LINK_MODE_SGMII:
16998c2ecf20Sopenharmony_ci		/* sgmii mode lets the phy handle forcing speed/duplex */
17008c2ecf20Sopenharmony_ci		pcs_autoneg = true;
17018c2ecf20Sopenharmony_ci		/* autoneg time out should be disabled for SGMII mode */
17028c2ecf20Sopenharmony_ci		reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
17038c2ecf20Sopenharmony_ci		break;
17048c2ecf20Sopenharmony_ci	case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
17058c2ecf20Sopenharmony_ci		/* disable PCS autoneg and support parallel detect only */
17068c2ecf20Sopenharmony_ci		pcs_autoneg = false;
17078c2ecf20Sopenharmony_ci		fallthrough;
17088c2ecf20Sopenharmony_ci	default:
17098c2ecf20Sopenharmony_ci		if (hw->mac.type == e1000_82575 ||
17108c2ecf20Sopenharmony_ci		    hw->mac.type == e1000_82576) {
17118c2ecf20Sopenharmony_ci			ret_val = hw->nvm.ops.read(hw, NVM_COMPAT, 1, &data);
17128c2ecf20Sopenharmony_ci			if (ret_val) {
17138c2ecf20Sopenharmony_ci				hw_dbg(KERN_DEBUG "NVM Read Error\n\n");
17148c2ecf20Sopenharmony_ci				return ret_val;
17158c2ecf20Sopenharmony_ci			}
17168c2ecf20Sopenharmony_ci
17178c2ecf20Sopenharmony_ci			if (data & E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT)
17188c2ecf20Sopenharmony_ci				pcs_autoneg = false;
17198c2ecf20Sopenharmony_ci		}
17208c2ecf20Sopenharmony_ci
17218c2ecf20Sopenharmony_ci		/* non-SGMII modes only supports a speed of 1000/Full for the
17228c2ecf20Sopenharmony_ci		 * link so it is best to just force the MAC and let the pcs
17238c2ecf20Sopenharmony_ci		 * link either autoneg or be forced to 1000/Full
17248c2ecf20Sopenharmony_ci		 */
17258c2ecf20Sopenharmony_ci		ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
17268c2ecf20Sopenharmony_ci				E1000_CTRL_FD | E1000_CTRL_FRCDPX;
17278c2ecf20Sopenharmony_ci
17288c2ecf20Sopenharmony_ci		/* set speed of 1000/Full if speed/duplex is forced */
17298c2ecf20Sopenharmony_ci		reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL;
17308c2ecf20Sopenharmony_ci		break;
17318c2ecf20Sopenharmony_ci	}
17328c2ecf20Sopenharmony_ci
17338c2ecf20Sopenharmony_ci	wr32(E1000_CTRL, ctrl_reg);
17348c2ecf20Sopenharmony_ci
17358c2ecf20Sopenharmony_ci	/* New SerDes mode allows for forcing speed or autonegotiating speed
17368c2ecf20Sopenharmony_ci	 * at 1gb. Autoneg should be default set by most drivers. This is the
17378c2ecf20Sopenharmony_ci	 * mode that will be compatible with older link partners and switches.
17388c2ecf20Sopenharmony_ci	 * However, both are supported by the hardware and some drivers/tools.
17398c2ecf20Sopenharmony_ci	 */
17408c2ecf20Sopenharmony_ci	reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
17418c2ecf20Sopenharmony_ci		E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
17428c2ecf20Sopenharmony_ci
17438c2ecf20Sopenharmony_ci	if (pcs_autoneg) {
17448c2ecf20Sopenharmony_ci		/* Set PCS register for autoneg */
17458c2ecf20Sopenharmony_ci		reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
17468c2ecf20Sopenharmony_ci		       E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
17478c2ecf20Sopenharmony_ci
17488c2ecf20Sopenharmony_ci		/* Disable force flow control for autoneg */
17498c2ecf20Sopenharmony_ci		reg &= ~E1000_PCS_LCTL_FORCE_FCTRL;
17508c2ecf20Sopenharmony_ci
17518c2ecf20Sopenharmony_ci		/* Configure flow control advertisement for autoneg */
17528c2ecf20Sopenharmony_ci		anadv_reg = rd32(E1000_PCS_ANADV);
17538c2ecf20Sopenharmony_ci		anadv_reg &= ~(E1000_TXCW_ASM_DIR | E1000_TXCW_PAUSE);
17548c2ecf20Sopenharmony_ci		switch (hw->fc.requested_mode) {
17558c2ecf20Sopenharmony_ci		case e1000_fc_full:
17568c2ecf20Sopenharmony_ci		case e1000_fc_rx_pause:
17578c2ecf20Sopenharmony_ci			anadv_reg |= E1000_TXCW_ASM_DIR;
17588c2ecf20Sopenharmony_ci			anadv_reg |= E1000_TXCW_PAUSE;
17598c2ecf20Sopenharmony_ci			break;
17608c2ecf20Sopenharmony_ci		case e1000_fc_tx_pause:
17618c2ecf20Sopenharmony_ci			anadv_reg |= E1000_TXCW_ASM_DIR;
17628c2ecf20Sopenharmony_ci			break;
17638c2ecf20Sopenharmony_ci		default:
17648c2ecf20Sopenharmony_ci			break;
17658c2ecf20Sopenharmony_ci		}
17668c2ecf20Sopenharmony_ci		wr32(E1000_PCS_ANADV, anadv_reg);
17678c2ecf20Sopenharmony_ci
17688c2ecf20Sopenharmony_ci		hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg);
17698c2ecf20Sopenharmony_ci	} else {
17708c2ecf20Sopenharmony_ci		/* Set PCS register for forced link */
17718c2ecf20Sopenharmony_ci		reg |= E1000_PCS_LCTL_FSD;        /* Force Speed */
17728c2ecf20Sopenharmony_ci
17738c2ecf20Sopenharmony_ci		/* Force flow control for forced link */
17748c2ecf20Sopenharmony_ci		reg |= E1000_PCS_LCTL_FORCE_FCTRL;
17758c2ecf20Sopenharmony_ci
17768c2ecf20Sopenharmony_ci		hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg);
17778c2ecf20Sopenharmony_ci	}
17788c2ecf20Sopenharmony_ci
17798c2ecf20Sopenharmony_ci	wr32(E1000_PCS_LCTL, reg);
17808c2ecf20Sopenharmony_ci
17818c2ecf20Sopenharmony_ci	if (!pcs_autoneg && !igb_sgmii_active_82575(hw))
17828c2ecf20Sopenharmony_ci		igb_force_mac_fc(hw);
17838c2ecf20Sopenharmony_ci
17848c2ecf20Sopenharmony_ci	return ret_val;
17858c2ecf20Sopenharmony_ci}
17868c2ecf20Sopenharmony_ci
17878c2ecf20Sopenharmony_ci/**
17888c2ecf20Sopenharmony_ci *  igb_sgmii_active_82575 - Return sgmii state
17898c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
17908c2ecf20Sopenharmony_ci *
17918c2ecf20Sopenharmony_ci *  82575 silicon has a serialized gigabit media independent interface (sgmii)
17928c2ecf20Sopenharmony_ci *  which can be enabled for use in the embedded applications.  Simply
17938c2ecf20Sopenharmony_ci *  return the current state of the sgmii interface.
17948c2ecf20Sopenharmony_ci **/
17958c2ecf20Sopenharmony_cistatic bool igb_sgmii_active_82575(struct e1000_hw *hw)
17968c2ecf20Sopenharmony_ci{
17978c2ecf20Sopenharmony_ci	struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
17988c2ecf20Sopenharmony_ci	return dev_spec->sgmii_active;
17998c2ecf20Sopenharmony_ci}
18008c2ecf20Sopenharmony_ci
18018c2ecf20Sopenharmony_ci/**
18028c2ecf20Sopenharmony_ci *  igb_reset_init_script_82575 - Inits HW defaults after reset
18038c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
18048c2ecf20Sopenharmony_ci *
18058c2ecf20Sopenharmony_ci *  Inits recommended HW defaults after a reset when there is no EEPROM
18068c2ecf20Sopenharmony_ci *  detected. This is only for the 82575.
18078c2ecf20Sopenharmony_ci **/
18088c2ecf20Sopenharmony_cistatic s32 igb_reset_init_script_82575(struct e1000_hw *hw)
18098c2ecf20Sopenharmony_ci{
18108c2ecf20Sopenharmony_ci	if (hw->mac.type == e1000_82575) {
18118c2ecf20Sopenharmony_ci		hw_dbg("Running reset init script for 82575\n");
18128c2ecf20Sopenharmony_ci		/* SerDes configuration via SERDESCTRL */
18138c2ecf20Sopenharmony_ci		igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
18148c2ecf20Sopenharmony_ci		igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
18158c2ecf20Sopenharmony_ci		igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
18168c2ecf20Sopenharmony_ci		igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
18178c2ecf20Sopenharmony_ci
18188c2ecf20Sopenharmony_ci		/* CCM configuration via CCMCTL register */
18198c2ecf20Sopenharmony_ci		igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
18208c2ecf20Sopenharmony_ci		igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
18218c2ecf20Sopenharmony_ci
18228c2ecf20Sopenharmony_ci		/* PCIe lanes configuration */
18238c2ecf20Sopenharmony_ci		igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
18248c2ecf20Sopenharmony_ci		igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
18258c2ecf20Sopenharmony_ci		igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
18268c2ecf20Sopenharmony_ci		igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
18278c2ecf20Sopenharmony_ci
18288c2ecf20Sopenharmony_ci		/* PCIe PLL Configuration */
18298c2ecf20Sopenharmony_ci		igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
18308c2ecf20Sopenharmony_ci		igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
18318c2ecf20Sopenharmony_ci		igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
18328c2ecf20Sopenharmony_ci	}
18338c2ecf20Sopenharmony_ci
18348c2ecf20Sopenharmony_ci	return 0;
18358c2ecf20Sopenharmony_ci}
18368c2ecf20Sopenharmony_ci
18378c2ecf20Sopenharmony_ci/**
18388c2ecf20Sopenharmony_ci *  igb_read_mac_addr_82575 - Read device MAC address
18398c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
18408c2ecf20Sopenharmony_ci **/
18418c2ecf20Sopenharmony_cistatic s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
18428c2ecf20Sopenharmony_ci{
18438c2ecf20Sopenharmony_ci	s32 ret_val = 0;
18448c2ecf20Sopenharmony_ci
18458c2ecf20Sopenharmony_ci	/* If there's an alternate MAC address place it in RAR0
18468c2ecf20Sopenharmony_ci	 * so that it will override the Si installed default perm
18478c2ecf20Sopenharmony_ci	 * address.
18488c2ecf20Sopenharmony_ci	 */
18498c2ecf20Sopenharmony_ci	ret_val = igb_check_alt_mac_addr(hw);
18508c2ecf20Sopenharmony_ci	if (ret_val)
18518c2ecf20Sopenharmony_ci		goto out;
18528c2ecf20Sopenharmony_ci
18538c2ecf20Sopenharmony_ci	ret_val = igb_read_mac_addr(hw);
18548c2ecf20Sopenharmony_ci
18558c2ecf20Sopenharmony_ciout:
18568c2ecf20Sopenharmony_ci	return ret_val;
18578c2ecf20Sopenharmony_ci}
18588c2ecf20Sopenharmony_ci
18598c2ecf20Sopenharmony_ci/**
18608c2ecf20Sopenharmony_ci * igb_power_down_phy_copper_82575 - Remove link during PHY power down
18618c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure
18628c2ecf20Sopenharmony_ci *
18638c2ecf20Sopenharmony_ci * In the case of a PHY power down to save power, or to turn off link during a
18648c2ecf20Sopenharmony_ci * driver unload, or wake on lan is not enabled, remove the link.
18658c2ecf20Sopenharmony_ci **/
18668c2ecf20Sopenharmony_civoid igb_power_down_phy_copper_82575(struct e1000_hw *hw)
18678c2ecf20Sopenharmony_ci{
18688c2ecf20Sopenharmony_ci	/* If the management interface is not enabled, then power down */
18698c2ecf20Sopenharmony_ci	if (!(igb_enable_mng_pass_thru(hw) || igb_check_reset_block(hw)))
18708c2ecf20Sopenharmony_ci		igb_power_down_phy_copper(hw);
18718c2ecf20Sopenharmony_ci}
18728c2ecf20Sopenharmony_ci
18738c2ecf20Sopenharmony_ci/**
18748c2ecf20Sopenharmony_ci *  igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
18758c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
18768c2ecf20Sopenharmony_ci *
18778c2ecf20Sopenharmony_ci *  Clears the hardware counters by reading the counter registers.
18788c2ecf20Sopenharmony_ci **/
18798c2ecf20Sopenharmony_cistatic void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
18808c2ecf20Sopenharmony_ci{
18818c2ecf20Sopenharmony_ci	igb_clear_hw_cntrs_base(hw);
18828c2ecf20Sopenharmony_ci
18838c2ecf20Sopenharmony_ci	rd32(E1000_PRC64);
18848c2ecf20Sopenharmony_ci	rd32(E1000_PRC127);
18858c2ecf20Sopenharmony_ci	rd32(E1000_PRC255);
18868c2ecf20Sopenharmony_ci	rd32(E1000_PRC511);
18878c2ecf20Sopenharmony_ci	rd32(E1000_PRC1023);
18888c2ecf20Sopenharmony_ci	rd32(E1000_PRC1522);
18898c2ecf20Sopenharmony_ci	rd32(E1000_PTC64);
18908c2ecf20Sopenharmony_ci	rd32(E1000_PTC127);
18918c2ecf20Sopenharmony_ci	rd32(E1000_PTC255);
18928c2ecf20Sopenharmony_ci	rd32(E1000_PTC511);
18938c2ecf20Sopenharmony_ci	rd32(E1000_PTC1023);
18948c2ecf20Sopenharmony_ci	rd32(E1000_PTC1522);
18958c2ecf20Sopenharmony_ci
18968c2ecf20Sopenharmony_ci	rd32(E1000_ALGNERRC);
18978c2ecf20Sopenharmony_ci	rd32(E1000_RXERRC);
18988c2ecf20Sopenharmony_ci	rd32(E1000_TNCRS);
18998c2ecf20Sopenharmony_ci	rd32(E1000_CEXTERR);
19008c2ecf20Sopenharmony_ci	rd32(E1000_TSCTC);
19018c2ecf20Sopenharmony_ci	rd32(E1000_TSCTFC);
19028c2ecf20Sopenharmony_ci
19038c2ecf20Sopenharmony_ci	rd32(E1000_MGTPRC);
19048c2ecf20Sopenharmony_ci	rd32(E1000_MGTPDC);
19058c2ecf20Sopenharmony_ci	rd32(E1000_MGTPTC);
19068c2ecf20Sopenharmony_ci
19078c2ecf20Sopenharmony_ci	rd32(E1000_IAC);
19088c2ecf20Sopenharmony_ci	rd32(E1000_ICRXOC);
19098c2ecf20Sopenharmony_ci
19108c2ecf20Sopenharmony_ci	rd32(E1000_ICRXPTC);
19118c2ecf20Sopenharmony_ci	rd32(E1000_ICRXATC);
19128c2ecf20Sopenharmony_ci	rd32(E1000_ICTXPTC);
19138c2ecf20Sopenharmony_ci	rd32(E1000_ICTXATC);
19148c2ecf20Sopenharmony_ci	rd32(E1000_ICTXQEC);
19158c2ecf20Sopenharmony_ci	rd32(E1000_ICTXQMTC);
19168c2ecf20Sopenharmony_ci	rd32(E1000_ICRXDMTC);
19178c2ecf20Sopenharmony_ci
19188c2ecf20Sopenharmony_ci	rd32(E1000_CBTMPC);
19198c2ecf20Sopenharmony_ci	rd32(E1000_HTDPMC);
19208c2ecf20Sopenharmony_ci	rd32(E1000_CBRMPC);
19218c2ecf20Sopenharmony_ci	rd32(E1000_RPTHC);
19228c2ecf20Sopenharmony_ci	rd32(E1000_HGPTC);
19238c2ecf20Sopenharmony_ci	rd32(E1000_HTCBDPC);
19248c2ecf20Sopenharmony_ci	rd32(E1000_HGORCL);
19258c2ecf20Sopenharmony_ci	rd32(E1000_HGORCH);
19268c2ecf20Sopenharmony_ci	rd32(E1000_HGOTCL);
19278c2ecf20Sopenharmony_ci	rd32(E1000_HGOTCH);
19288c2ecf20Sopenharmony_ci	rd32(E1000_LENERRS);
19298c2ecf20Sopenharmony_ci
19308c2ecf20Sopenharmony_ci	/* This register should not be read in copper configurations */
19318c2ecf20Sopenharmony_ci	if (hw->phy.media_type == e1000_media_type_internal_serdes ||
19328c2ecf20Sopenharmony_ci	    igb_sgmii_active_82575(hw))
19338c2ecf20Sopenharmony_ci		rd32(E1000_SCVPC);
19348c2ecf20Sopenharmony_ci}
19358c2ecf20Sopenharmony_ci
19368c2ecf20Sopenharmony_ci/**
19378c2ecf20Sopenharmony_ci *  igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
19388c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
19398c2ecf20Sopenharmony_ci *
19408c2ecf20Sopenharmony_ci *  After rx enable if manageability is enabled then there is likely some
19418c2ecf20Sopenharmony_ci *  bad data at the start of the fifo and possibly in the DMA fifo. This
19428c2ecf20Sopenharmony_ci *  function clears the fifos and flushes any packets that came in as rx was
19438c2ecf20Sopenharmony_ci *  being enabled.
19448c2ecf20Sopenharmony_ci **/
19458c2ecf20Sopenharmony_civoid igb_rx_fifo_flush_82575(struct e1000_hw *hw)
19468c2ecf20Sopenharmony_ci{
19478c2ecf20Sopenharmony_ci	u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
19488c2ecf20Sopenharmony_ci	int i, ms_wait;
19498c2ecf20Sopenharmony_ci
19508c2ecf20Sopenharmony_ci	/* disable IPv6 options as per hardware errata */
19518c2ecf20Sopenharmony_ci	rfctl = rd32(E1000_RFCTL);
19528c2ecf20Sopenharmony_ci	rfctl |= E1000_RFCTL_IPV6_EX_DIS;
19538c2ecf20Sopenharmony_ci	wr32(E1000_RFCTL, rfctl);
19548c2ecf20Sopenharmony_ci
19558c2ecf20Sopenharmony_ci	if (hw->mac.type != e1000_82575 ||
19568c2ecf20Sopenharmony_ci	    !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
19578c2ecf20Sopenharmony_ci		return;
19588c2ecf20Sopenharmony_ci
19598c2ecf20Sopenharmony_ci	/* Disable all RX queues */
19608c2ecf20Sopenharmony_ci	for (i = 0; i < 4; i++) {
19618c2ecf20Sopenharmony_ci		rxdctl[i] = rd32(E1000_RXDCTL(i));
19628c2ecf20Sopenharmony_ci		wr32(E1000_RXDCTL(i),
19638c2ecf20Sopenharmony_ci		     rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
19648c2ecf20Sopenharmony_ci	}
19658c2ecf20Sopenharmony_ci	/* Poll all queues to verify they have shut down */
19668c2ecf20Sopenharmony_ci	for (ms_wait = 0; ms_wait < 10; ms_wait++) {
19678c2ecf20Sopenharmony_ci		usleep_range(1000, 2000);
19688c2ecf20Sopenharmony_ci		rx_enabled = 0;
19698c2ecf20Sopenharmony_ci		for (i = 0; i < 4; i++)
19708c2ecf20Sopenharmony_ci			rx_enabled |= rd32(E1000_RXDCTL(i));
19718c2ecf20Sopenharmony_ci		if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
19728c2ecf20Sopenharmony_ci			break;
19738c2ecf20Sopenharmony_ci	}
19748c2ecf20Sopenharmony_ci
19758c2ecf20Sopenharmony_ci	if (ms_wait == 10)
19768c2ecf20Sopenharmony_ci		hw_dbg("Queue disable timed out after 10ms\n");
19778c2ecf20Sopenharmony_ci
19788c2ecf20Sopenharmony_ci	/* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
19798c2ecf20Sopenharmony_ci	 * incoming packets are rejected.  Set enable and wait 2ms so that
19808c2ecf20Sopenharmony_ci	 * any packet that was coming in as RCTL.EN was set is flushed
19818c2ecf20Sopenharmony_ci	 */
19828c2ecf20Sopenharmony_ci	wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
19838c2ecf20Sopenharmony_ci
19848c2ecf20Sopenharmony_ci	rlpml = rd32(E1000_RLPML);
19858c2ecf20Sopenharmony_ci	wr32(E1000_RLPML, 0);
19868c2ecf20Sopenharmony_ci
19878c2ecf20Sopenharmony_ci	rctl = rd32(E1000_RCTL);
19888c2ecf20Sopenharmony_ci	temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
19898c2ecf20Sopenharmony_ci	temp_rctl |= E1000_RCTL_LPE;
19908c2ecf20Sopenharmony_ci
19918c2ecf20Sopenharmony_ci	wr32(E1000_RCTL, temp_rctl);
19928c2ecf20Sopenharmony_ci	wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
19938c2ecf20Sopenharmony_ci	wrfl();
19948c2ecf20Sopenharmony_ci	usleep_range(2000, 3000);
19958c2ecf20Sopenharmony_ci
19968c2ecf20Sopenharmony_ci	/* Enable RX queues that were previously enabled and restore our
19978c2ecf20Sopenharmony_ci	 * previous state
19988c2ecf20Sopenharmony_ci	 */
19998c2ecf20Sopenharmony_ci	for (i = 0; i < 4; i++)
20008c2ecf20Sopenharmony_ci		wr32(E1000_RXDCTL(i), rxdctl[i]);
20018c2ecf20Sopenharmony_ci	wr32(E1000_RCTL, rctl);
20028c2ecf20Sopenharmony_ci	wrfl();
20038c2ecf20Sopenharmony_ci
20048c2ecf20Sopenharmony_ci	wr32(E1000_RLPML, rlpml);
20058c2ecf20Sopenharmony_ci	wr32(E1000_RFCTL, rfctl);
20068c2ecf20Sopenharmony_ci
20078c2ecf20Sopenharmony_ci	/* Flush receive errors generated by workaround */
20088c2ecf20Sopenharmony_ci	rd32(E1000_ROC);
20098c2ecf20Sopenharmony_ci	rd32(E1000_RNBC);
20108c2ecf20Sopenharmony_ci	rd32(E1000_MPC);
20118c2ecf20Sopenharmony_ci}
20128c2ecf20Sopenharmony_ci
20138c2ecf20Sopenharmony_ci/**
20148c2ecf20Sopenharmony_ci *  igb_set_pcie_completion_timeout - set pci-e completion timeout
20158c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
20168c2ecf20Sopenharmony_ci *
20178c2ecf20Sopenharmony_ci *  The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
20188c2ecf20Sopenharmony_ci *  however the hardware default for these parts is 500us to 1ms which is less
20198c2ecf20Sopenharmony_ci *  than the 10ms recommended by the pci-e spec.  To address this we need to
20208c2ecf20Sopenharmony_ci *  increase the value to either 10ms to 200ms for capability version 1 config,
20218c2ecf20Sopenharmony_ci *  or 16ms to 55ms for version 2.
20228c2ecf20Sopenharmony_ci **/
20238c2ecf20Sopenharmony_cistatic s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
20248c2ecf20Sopenharmony_ci{
20258c2ecf20Sopenharmony_ci	u32 gcr = rd32(E1000_GCR);
20268c2ecf20Sopenharmony_ci	s32 ret_val = 0;
20278c2ecf20Sopenharmony_ci	u16 pcie_devctl2;
20288c2ecf20Sopenharmony_ci
20298c2ecf20Sopenharmony_ci	/* only take action if timeout value is defaulted to 0 */
20308c2ecf20Sopenharmony_ci	if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
20318c2ecf20Sopenharmony_ci		goto out;
20328c2ecf20Sopenharmony_ci
20338c2ecf20Sopenharmony_ci	/* if capabilities version is type 1 we can write the
20348c2ecf20Sopenharmony_ci	 * timeout of 10ms to 200ms through the GCR register
20358c2ecf20Sopenharmony_ci	 */
20368c2ecf20Sopenharmony_ci	if (!(gcr & E1000_GCR_CAP_VER2)) {
20378c2ecf20Sopenharmony_ci		gcr |= E1000_GCR_CMPL_TMOUT_10ms;
20388c2ecf20Sopenharmony_ci		goto out;
20398c2ecf20Sopenharmony_ci	}
20408c2ecf20Sopenharmony_ci
20418c2ecf20Sopenharmony_ci	/* for version 2 capabilities we need to write the config space
20428c2ecf20Sopenharmony_ci	 * directly in order to set the completion timeout value for
20438c2ecf20Sopenharmony_ci	 * 16ms to 55ms
20448c2ecf20Sopenharmony_ci	 */
20458c2ecf20Sopenharmony_ci	ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
20468c2ecf20Sopenharmony_ci					&pcie_devctl2);
20478c2ecf20Sopenharmony_ci	if (ret_val)
20488c2ecf20Sopenharmony_ci		goto out;
20498c2ecf20Sopenharmony_ci
20508c2ecf20Sopenharmony_ci	pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
20518c2ecf20Sopenharmony_ci
20528c2ecf20Sopenharmony_ci	ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
20538c2ecf20Sopenharmony_ci					 &pcie_devctl2);
20548c2ecf20Sopenharmony_ciout:
20558c2ecf20Sopenharmony_ci	/* disable completion timeout resend */
20568c2ecf20Sopenharmony_ci	gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
20578c2ecf20Sopenharmony_ci
20588c2ecf20Sopenharmony_ci	wr32(E1000_GCR, gcr);
20598c2ecf20Sopenharmony_ci	return ret_val;
20608c2ecf20Sopenharmony_ci}
20618c2ecf20Sopenharmony_ci
20628c2ecf20Sopenharmony_ci/**
20638c2ecf20Sopenharmony_ci *  igb_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
20648c2ecf20Sopenharmony_ci *  @hw: pointer to the hardware struct
20658c2ecf20Sopenharmony_ci *  @enable: state to enter, either enabled or disabled
20668c2ecf20Sopenharmony_ci *  @pf: Physical Function pool - do not set anti-spoofing for the PF
20678c2ecf20Sopenharmony_ci *
20688c2ecf20Sopenharmony_ci *  enables/disables L2 switch anti-spoofing functionality.
20698c2ecf20Sopenharmony_ci **/
20708c2ecf20Sopenharmony_civoid igb_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
20718c2ecf20Sopenharmony_ci{
20728c2ecf20Sopenharmony_ci	u32 reg_val, reg_offset;
20738c2ecf20Sopenharmony_ci
20748c2ecf20Sopenharmony_ci	switch (hw->mac.type) {
20758c2ecf20Sopenharmony_ci	case e1000_82576:
20768c2ecf20Sopenharmony_ci		reg_offset = E1000_DTXSWC;
20778c2ecf20Sopenharmony_ci		break;
20788c2ecf20Sopenharmony_ci	case e1000_i350:
20798c2ecf20Sopenharmony_ci	case e1000_i354:
20808c2ecf20Sopenharmony_ci		reg_offset = E1000_TXSWC;
20818c2ecf20Sopenharmony_ci		break;
20828c2ecf20Sopenharmony_ci	default:
20838c2ecf20Sopenharmony_ci		return;
20848c2ecf20Sopenharmony_ci	}
20858c2ecf20Sopenharmony_ci
20868c2ecf20Sopenharmony_ci	reg_val = rd32(reg_offset);
20878c2ecf20Sopenharmony_ci	if (enable) {
20888c2ecf20Sopenharmony_ci		reg_val |= (E1000_DTXSWC_MAC_SPOOF_MASK |
20898c2ecf20Sopenharmony_ci			     E1000_DTXSWC_VLAN_SPOOF_MASK);
20908c2ecf20Sopenharmony_ci		/* The PF can spoof - it has to in order to
20918c2ecf20Sopenharmony_ci		 * support emulation mode NICs
20928c2ecf20Sopenharmony_ci		 */
20938c2ecf20Sopenharmony_ci		reg_val ^= (BIT(pf) | BIT(pf + MAX_NUM_VFS));
20948c2ecf20Sopenharmony_ci	} else {
20958c2ecf20Sopenharmony_ci		reg_val &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
20968c2ecf20Sopenharmony_ci			     E1000_DTXSWC_VLAN_SPOOF_MASK);
20978c2ecf20Sopenharmony_ci	}
20988c2ecf20Sopenharmony_ci	wr32(reg_offset, reg_val);
20998c2ecf20Sopenharmony_ci}
21008c2ecf20Sopenharmony_ci
21018c2ecf20Sopenharmony_ci/**
21028c2ecf20Sopenharmony_ci *  igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
21038c2ecf20Sopenharmony_ci *  @hw: pointer to the hardware struct
21048c2ecf20Sopenharmony_ci *  @enable: state to enter, either enabled or disabled
21058c2ecf20Sopenharmony_ci *
21068c2ecf20Sopenharmony_ci *  enables/disables L2 switch loopback functionality.
21078c2ecf20Sopenharmony_ci **/
21088c2ecf20Sopenharmony_civoid igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
21098c2ecf20Sopenharmony_ci{
21108c2ecf20Sopenharmony_ci	u32 dtxswc;
21118c2ecf20Sopenharmony_ci
21128c2ecf20Sopenharmony_ci	switch (hw->mac.type) {
21138c2ecf20Sopenharmony_ci	case e1000_82576:
21148c2ecf20Sopenharmony_ci		dtxswc = rd32(E1000_DTXSWC);
21158c2ecf20Sopenharmony_ci		if (enable)
21168c2ecf20Sopenharmony_ci			dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
21178c2ecf20Sopenharmony_ci		else
21188c2ecf20Sopenharmony_ci			dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
21198c2ecf20Sopenharmony_ci		wr32(E1000_DTXSWC, dtxswc);
21208c2ecf20Sopenharmony_ci		break;
21218c2ecf20Sopenharmony_ci	case e1000_i354:
21228c2ecf20Sopenharmony_ci	case e1000_i350:
21238c2ecf20Sopenharmony_ci		dtxswc = rd32(E1000_TXSWC);
21248c2ecf20Sopenharmony_ci		if (enable)
21258c2ecf20Sopenharmony_ci			dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
21268c2ecf20Sopenharmony_ci		else
21278c2ecf20Sopenharmony_ci			dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
21288c2ecf20Sopenharmony_ci		wr32(E1000_TXSWC, dtxswc);
21298c2ecf20Sopenharmony_ci		break;
21308c2ecf20Sopenharmony_ci	default:
21318c2ecf20Sopenharmony_ci		/* Currently no other hardware supports loopback */
21328c2ecf20Sopenharmony_ci		break;
21338c2ecf20Sopenharmony_ci	}
21348c2ecf20Sopenharmony_ci
21358c2ecf20Sopenharmony_ci}
21368c2ecf20Sopenharmony_ci
21378c2ecf20Sopenharmony_ci/**
21388c2ecf20Sopenharmony_ci *  igb_vmdq_set_replication_pf - enable or disable vmdq replication
21398c2ecf20Sopenharmony_ci *  @hw: pointer to the hardware struct
21408c2ecf20Sopenharmony_ci *  @enable: state to enter, either enabled or disabled
21418c2ecf20Sopenharmony_ci *
21428c2ecf20Sopenharmony_ci *  enables/disables replication of packets across multiple pools.
21438c2ecf20Sopenharmony_ci **/
21448c2ecf20Sopenharmony_civoid igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
21458c2ecf20Sopenharmony_ci{
21468c2ecf20Sopenharmony_ci	u32 vt_ctl = rd32(E1000_VT_CTL);
21478c2ecf20Sopenharmony_ci
21488c2ecf20Sopenharmony_ci	if (enable)
21498c2ecf20Sopenharmony_ci		vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
21508c2ecf20Sopenharmony_ci	else
21518c2ecf20Sopenharmony_ci		vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
21528c2ecf20Sopenharmony_ci
21538c2ecf20Sopenharmony_ci	wr32(E1000_VT_CTL, vt_ctl);
21548c2ecf20Sopenharmony_ci}
21558c2ecf20Sopenharmony_ci
21568c2ecf20Sopenharmony_ci/**
21578c2ecf20Sopenharmony_ci *  igb_read_phy_reg_82580 - Read 82580 MDI control register
21588c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
21598c2ecf20Sopenharmony_ci *  @offset: register offset to be read
21608c2ecf20Sopenharmony_ci *  @data: pointer to the read data
21618c2ecf20Sopenharmony_ci *
21628c2ecf20Sopenharmony_ci *  Reads the MDI control register in the PHY at offset and stores the
21638c2ecf20Sopenharmony_ci *  information read to data.
21648c2ecf20Sopenharmony_ci **/
21658c2ecf20Sopenharmony_cis32 igb_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
21668c2ecf20Sopenharmony_ci{
21678c2ecf20Sopenharmony_ci	s32 ret_val;
21688c2ecf20Sopenharmony_ci
21698c2ecf20Sopenharmony_ci	ret_val = hw->phy.ops.acquire(hw);
21708c2ecf20Sopenharmony_ci	if (ret_val)
21718c2ecf20Sopenharmony_ci		goto out;
21728c2ecf20Sopenharmony_ci
21738c2ecf20Sopenharmony_ci	ret_val = igb_read_phy_reg_mdic(hw, offset, data);
21748c2ecf20Sopenharmony_ci
21758c2ecf20Sopenharmony_ci	hw->phy.ops.release(hw);
21768c2ecf20Sopenharmony_ci
21778c2ecf20Sopenharmony_ciout:
21788c2ecf20Sopenharmony_ci	return ret_val;
21798c2ecf20Sopenharmony_ci}
21808c2ecf20Sopenharmony_ci
21818c2ecf20Sopenharmony_ci/**
21828c2ecf20Sopenharmony_ci *  igb_write_phy_reg_82580 - Write 82580 MDI control register
21838c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
21848c2ecf20Sopenharmony_ci *  @offset: register offset to write to
21858c2ecf20Sopenharmony_ci *  @data: data to write to register at offset
21868c2ecf20Sopenharmony_ci *
21878c2ecf20Sopenharmony_ci *  Writes data to MDI control register in the PHY at offset.
21888c2ecf20Sopenharmony_ci **/
21898c2ecf20Sopenharmony_cis32 igb_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
21908c2ecf20Sopenharmony_ci{
21918c2ecf20Sopenharmony_ci	s32 ret_val;
21928c2ecf20Sopenharmony_ci
21938c2ecf20Sopenharmony_ci
21948c2ecf20Sopenharmony_ci	ret_val = hw->phy.ops.acquire(hw);
21958c2ecf20Sopenharmony_ci	if (ret_val)
21968c2ecf20Sopenharmony_ci		goto out;
21978c2ecf20Sopenharmony_ci
21988c2ecf20Sopenharmony_ci	ret_val = igb_write_phy_reg_mdic(hw, offset, data);
21998c2ecf20Sopenharmony_ci
22008c2ecf20Sopenharmony_ci	hw->phy.ops.release(hw);
22018c2ecf20Sopenharmony_ci
22028c2ecf20Sopenharmony_ciout:
22038c2ecf20Sopenharmony_ci	return ret_val;
22048c2ecf20Sopenharmony_ci}
22058c2ecf20Sopenharmony_ci
22068c2ecf20Sopenharmony_ci/**
22078c2ecf20Sopenharmony_ci *  igb_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
22088c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
22098c2ecf20Sopenharmony_ci *
22108c2ecf20Sopenharmony_ci *  This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
22118c2ecf20Sopenharmony_ci *  the values found in the EEPROM.  This addresses an issue in which these
22128c2ecf20Sopenharmony_ci *  bits are not restored from EEPROM after reset.
22138c2ecf20Sopenharmony_ci **/
22148c2ecf20Sopenharmony_cistatic s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw)
22158c2ecf20Sopenharmony_ci{
22168c2ecf20Sopenharmony_ci	s32 ret_val = 0;
22178c2ecf20Sopenharmony_ci	u32 mdicnfg;
22188c2ecf20Sopenharmony_ci	u16 nvm_data = 0;
22198c2ecf20Sopenharmony_ci
22208c2ecf20Sopenharmony_ci	if (hw->mac.type != e1000_82580)
22218c2ecf20Sopenharmony_ci		goto out;
22228c2ecf20Sopenharmony_ci	if (!igb_sgmii_active_82575(hw))
22238c2ecf20Sopenharmony_ci		goto out;
22248c2ecf20Sopenharmony_ci
22258c2ecf20Sopenharmony_ci	ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
22268c2ecf20Sopenharmony_ci				   NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
22278c2ecf20Sopenharmony_ci				   &nvm_data);
22288c2ecf20Sopenharmony_ci	if (ret_val) {
22298c2ecf20Sopenharmony_ci		hw_dbg("NVM Read Error\n");
22308c2ecf20Sopenharmony_ci		goto out;
22318c2ecf20Sopenharmony_ci	}
22328c2ecf20Sopenharmony_ci
22338c2ecf20Sopenharmony_ci	mdicnfg = rd32(E1000_MDICNFG);
22348c2ecf20Sopenharmony_ci	if (nvm_data & NVM_WORD24_EXT_MDIO)
22358c2ecf20Sopenharmony_ci		mdicnfg |= E1000_MDICNFG_EXT_MDIO;
22368c2ecf20Sopenharmony_ci	if (nvm_data & NVM_WORD24_COM_MDIO)
22378c2ecf20Sopenharmony_ci		mdicnfg |= E1000_MDICNFG_COM_MDIO;
22388c2ecf20Sopenharmony_ci	wr32(E1000_MDICNFG, mdicnfg);
22398c2ecf20Sopenharmony_ciout:
22408c2ecf20Sopenharmony_ci	return ret_val;
22418c2ecf20Sopenharmony_ci}
22428c2ecf20Sopenharmony_ci
22438c2ecf20Sopenharmony_ci/**
22448c2ecf20Sopenharmony_ci *  igb_reset_hw_82580 - Reset hardware
22458c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
22468c2ecf20Sopenharmony_ci *
22478c2ecf20Sopenharmony_ci *  This resets function or entire device (all ports, etc.)
22488c2ecf20Sopenharmony_ci *  to a known state.
22498c2ecf20Sopenharmony_ci **/
22508c2ecf20Sopenharmony_cistatic s32 igb_reset_hw_82580(struct e1000_hw *hw)
22518c2ecf20Sopenharmony_ci{
22528c2ecf20Sopenharmony_ci	s32 ret_val = 0;
22538c2ecf20Sopenharmony_ci	/* BH SW mailbox bit in SW_FW_SYNC */
22548c2ecf20Sopenharmony_ci	u16 swmbsw_mask = E1000_SW_SYNCH_MB;
22558c2ecf20Sopenharmony_ci	u32 ctrl;
22568c2ecf20Sopenharmony_ci	bool global_device_reset = hw->dev_spec._82575.global_device_reset;
22578c2ecf20Sopenharmony_ci
22588c2ecf20Sopenharmony_ci	hw->dev_spec._82575.global_device_reset = false;
22598c2ecf20Sopenharmony_ci
22608c2ecf20Sopenharmony_ci	/* due to hw errata, global device reset doesn't always
22618c2ecf20Sopenharmony_ci	 * work on 82580
22628c2ecf20Sopenharmony_ci	 */
22638c2ecf20Sopenharmony_ci	if (hw->mac.type == e1000_82580)
22648c2ecf20Sopenharmony_ci		global_device_reset = false;
22658c2ecf20Sopenharmony_ci
22668c2ecf20Sopenharmony_ci	/* Get current control state. */
22678c2ecf20Sopenharmony_ci	ctrl = rd32(E1000_CTRL);
22688c2ecf20Sopenharmony_ci
22698c2ecf20Sopenharmony_ci	/* Prevent the PCI-E bus from sticking if there is no TLP connection
22708c2ecf20Sopenharmony_ci	 * on the last TLP read/write transaction when MAC is reset.
22718c2ecf20Sopenharmony_ci	 */
22728c2ecf20Sopenharmony_ci	ret_val = igb_disable_pcie_master(hw);
22738c2ecf20Sopenharmony_ci	if (ret_val)
22748c2ecf20Sopenharmony_ci		hw_dbg("PCI-E Master disable polling has failed.\n");
22758c2ecf20Sopenharmony_ci
22768c2ecf20Sopenharmony_ci	hw_dbg("Masking off all interrupts\n");
22778c2ecf20Sopenharmony_ci	wr32(E1000_IMC, 0xffffffff);
22788c2ecf20Sopenharmony_ci	wr32(E1000_RCTL, 0);
22798c2ecf20Sopenharmony_ci	wr32(E1000_TCTL, E1000_TCTL_PSP);
22808c2ecf20Sopenharmony_ci	wrfl();
22818c2ecf20Sopenharmony_ci
22828c2ecf20Sopenharmony_ci	usleep_range(10000, 11000);
22838c2ecf20Sopenharmony_ci
22848c2ecf20Sopenharmony_ci	/* Determine whether or not a global dev reset is requested */
22858c2ecf20Sopenharmony_ci	if (global_device_reset &&
22868c2ecf20Sopenharmony_ci		hw->mac.ops.acquire_swfw_sync(hw, swmbsw_mask))
22878c2ecf20Sopenharmony_ci			global_device_reset = false;
22888c2ecf20Sopenharmony_ci
22898c2ecf20Sopenharmony_ci	if (global_device_reset &&
22908c2ecf20Sopenharmony_ci		!(rd32(E1000_STATUS) & E1000_STAT_DEV_RST_SET))
22918c2ecf20Sopenharmony_ci		ctrl |= E1000_CTRL_DEV_RST;
22928c2ecf20Sopenharmony_ci	else
22938c2ecf20Sopenharmony_ci		ctrl |= E1000_CTRL_RST;
22948c2ecf20Sopenharmony_ci
22958c2ecf20Sopenharmony_ci	wr32(E1000_CTRL, ctrl);
22968c2ecf20Sopenharmony_ci	wrfl();
22978c2ecf20Sopenharmony_ci
22988c2ecf20Sopenharmony_ci	/* Add delay to insure DEV_RST has time to complete */
22998c2ecf20Sopenharmony_ci	if (global_device_reset)
23008c2ecf20Sopenharmony_ci		usleep_range(5000, 6000);
23018c2ecf20Sopenharmony_ci
23028c2ecf20Sopenharmony_ci	ret_val = igb_get_auto_rd_done(hw);
23038c2ecf20Sopenharmony_ci	if (ret_val) {
23048c2ecf20Sopenharmony_ci		/* When auto config read does not complete, do not
23058c2ecf20Sopenharmony_ci		 * return with an error. This can happen in situations
23068c2ecf20Sopenharmony_ci		 * where there is no eeprom and prevents getting link.
23078c2ecf20Sopenharmony_ci		 */
23088c2ecf20Sopenharmony_ci		hw_dbg("Auto Read Done did not complete\n");
23098c2ecf20Sopenharmony_ci	}
23108c2ecf20Sopenharmony_ci
23118c2ecf20Sopenharmony_ci	/* clear global device reset status bit */
23128c2ecf20Sopenharmony_ci	wr32(E1000_STATUS, E1000_STAT_DEV_RST_SET);
23138c2ecf20Sopenharmony_ci
23148c2ecf20Sopenharmony_ci	/* Clear any pending interrupt events. */
23158c2ecf20Sopenharmony_ci	wr32(E1000_IMC, 0xffffffff);
23168c2ecf20Sopenharmony_ci	rd32(E1000_ICR);
23178c2ecf20Sopenharmony_ci
23188c2ecf20Sopenharmony_ci	ret_val = igb_reset_mdicnfg_82580(hw);
23198c2ecf20Sopenharmony_ci	if (ret_val)
23208c2ecf20Sopenharmony_ci		hw_dbg("Could not reset MDICNFG based on EEPROM\n");
23218c2ecf20Sopenharmony_ci
23228c2ecf20Sopenharmony_ci	/* Install any alternate MAC address into RAR0 */
23238c2ecf20Sopenharmony_ci	ret_val = igb_check_alt_mac_addr(hw);
23248c2ecf20Sopenharmony_ci
23258c2ecf20Sopenharmony_ci	/* Release semaphore */
23268c2ecf20Sopenharmony_ci	if (global_device_reset)
23278c2ecf20Sopenharmony_ci		hw->mac.ops.release_swfw_sync(hw, swmbsw_mask);
23288c2ecf20Sopenharmony_ci
23298c2ecf20Sopenharmony_ci	return ret_val;
23308c2ecf20Sopenharmony_ci}
23318c2ecf20Sopenharmony_ci
23328c2ecf20Sopenharmony_ci/**
23338c2ecf20Sopenharmony_ci *  igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size
23348c2ecf20Sopenharmony_ci *  @data: data received by reading RXPBS register
23358c2ecf20Sopenharmony_ci *
23368c2ecf20Sopenharmony_ci *  The 82580 uses a table based approach for packet buffer allocation sizes.
23378c2ecf20Sopenharmony_ci *  This function converts the retrieved value into the correct table value
23388c2ecf20Sopenharmony_ci *     0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
23398c2ecf20Sopenharmony_ci *  0x0 36  72 144   1   2   4   8  16
23408c2ecf20Sopenharmony_ci *  0x8 35  70 140 rsv rsv rsv rsv rsv
23418c2ecf20Sopenharmony_ci */
23428c2ecf20Sopenharmony_ciu16 igb_rxpbs_adjust_82580(u32 data)
23438c2ecf20Sopenharmony_ci{
23448c2ecf20Sopenharmony_ci	u16 ret_val = 0;
23458c2ecf20Sopenharmony_ci
23468c2ecf20Sopenharmony_ci	if (data < ARRAY_SIZE(e1000_82580_rxpbs_table))
23478c2ecf20Sopenharmony_ci		ret_val = e1000_82580_rxpbs_table[data];
23488c2ecf20Sopenharmony_ci
23498c2ecf20Sopenharmony_ci	return ret_val;
23508c2ecf20Sopenharmony_ci}
23518c2ecf20Sopenharmony_ci
23528c2ecf20Sopenharmony_ci/**
23538c2ecf20Sopenharmony_ci *  igb_validate_nvm_checksum_with_offset - Validate EEPROM
23548c2ecf20Sopenharmony_ci *  checksum
23558c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
23568c2ecf20Sopenharmony_ci *  @offset: offset in words of the checksum protected region
23578c2ecf20Sopenharmony_ci *
23588c2ecf20Sopenharmony_ci *  Calculates the EEPROM checksum by reading/adding each word of the EEPROM
23598c2ecf20Sopenharmony_ci *  and then verifies that the sum of the EEPROM is equal to 0xBABA.
23608c2ecf20Sopenharmony_ci **/
23618c2ecf20Sopenharmony_cistatic s32 igb_validate_nvm_checksum_with_offset(struct e1000_hw *hw,
23628c2ecf20Sopenharmony_ci						 u16 offset)
23638c2ecf20Sopenharmony_ci{
23648c2ecf20Sopenharmony_ci	s32 ret_val = 0;
23658c2ecf20Sopenharmony_ci	u16 checksum = 0;
23668c2ecf20Sopenharmony_ci	u16 i, nvm_data;
23678c2ecf20Sopenharmony_ci
23688c2ecf20Sopenharmony_ci	for (i = offset; i < ((NVM_CHECKSUM_REG + offset) + 1); i++) {
23698c2ecf20Sopenharmony_ci		ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
23708c2ecf20Sopenharmony_ci		if (ret_val) {
23718c2ecf20Sopenharmony_ci			hw_dbg("NVM Read Error\n");
23728c2ecf20Sopenharmony_ci			goto out;
23738c2ecf20Sopenharmony_ci		}
23748c2ecf20Sopenharmony_ci		checksum += nvm_data;
23758c2ecf20Sopenharmony_ci	}
23768c2ecf20Sopenharmony_ci
23778c2ecf20Sopenharmony_ci	if (checksum != (u16) NVM_SUM) {
23788c2ecf20Sopenharmony_ci		hw_dbg("NVM Checksum Invalid\n");
23798c2ecf20Sopenharmony_ci		ret_val = -E1000_ERR_NVM;
23808c2ecf20Sopenharmony_ci		goto out;
23818c2ecf20Sopenharmony_ci	}
23828c2ecf20Sopenharmony_ci
23838c2ecf20Sopenharmony_ciout:
23848c2ecf20Sopenharmony_ci	return ret_val;
23858c2ecf20Sopenharmony_ci}
23868c2ecf20Sopenharmony_ci
23878c2ecf20Sopenharmony_ci/**
23888c2ecf20Sopenharmony_ci *  igb_update_nvm_checksum_with_offset - Update EEPROM
23898c2ecf20Sopenharmony_ci *  checksum
23908c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
23918c2ecf20Sopenharmony_ci *  @offset: offset in words of the checksum protected region
23928c2ecf20Sopenharmony_ci *
23938c2ecf20Sopenharmony_ci *  Updates the EEPROM checksum by reading/adding each word of the EEPROM
23948c2ecf20Sopenharmony_ci *  up to the checksum.  Then calculates the EEPROM checksum and writes the
23958c2ecf20Sopenharmony_ci *  value to the EEPROM.
23968c2ecf20Sopenharmony_ci **/
23978c2ecf20Sopenharmony_cistatic s32 igb_update_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
23988c2ecf20Sopenharmony_ci{
23998c2ecf20Sopenharmony_ci	s32 ret_val;
24008c2ecf20Sopenharmony_ci	u16 checksum = 0;
24018c2ecf20Sopenharmony_ci	u16 i, nvm_data;
24028c2ecf20Sopenharmony_ci
24038c2ecf20Sopenharmony_ci	for (i = offset; i < (NVM_CHECKSUM_REG + offset); i++) {
24048c2ecf20Sopenharmony_ci		ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
24058c2ecf20Sopenharmony_ci		if (ret_val) {
24068c2ecf20Sopenharmony_ci			hw_dbg("NVM Read Error while updating checksum.\n");
24078c2ecf20Sopenharmony_ci			goto out;
24088c2ecf20Sopenharmony_ci		}
24098c2ecf20Sopenharmony_ci		checksum += nvm_data;
24108c2ecf20Sopenharmony_ci	}
24118c2ecf20Sopenharmony_ci	checksum = (u16) NVM_SUM - checksum;
24128c2ecf20Sopenharmony_ci	ret_val = hw->nvm.ops.write(hw, (NVM_CHECKSUM_REG + offset), 1,
24138c2ecf20Sopenharmony_ci				&checksum);
24148c2ecf20Sopenharmony_ci	if (ret_val)
24158c2ecf20Sopenharmony_ci		hw_dbg("NVM Write Error while updating checksum.\n");
24168c2ecf20Sopenharmony_ci
24178c2ecf20Sopenharmony_ciout:
24188c2ecf20Sopenharmony_ci	return ret_val;
24198c2ecf20Sopenharmony_ci}
24208c2ecf20Sopenharmony_ci
24218c2ecf20Sopenharmony_ci/**
24228c2ecf20Sopenharmony_ci *  igb_validate_nvm_checksum_82580 - Validate EEPROM checksum
24238c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
24248c2ecf20Sopenharmony_ci *
24258c2ecf20Sopenharmony_ci *  Calculates the EEPROM section checksum by reading/adding each word of
24268c2ecf20Sopenharmony_ci *  the EEPROM and then verifies that the sum of the EEPROM is
24278c2ecf20Sopenharmony_ci *  equal to 0xBABA.
24288c2ecf20Sopenharmony_ci **/
24298c2ecf20Sopenharmony_cistatic s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw)
24308c2ecf20Sopenharmony_ci{
24318c2ecf20Sopenharmony_ci	s32 ret_val = 0;
24328c2ecf20Sopenharmony_ci	u16 eeprom_regions_count = 1;
24338c2ecf20Sopenharmony_ci	u16 j, nvm_data;
24348c2ecf20Sopenharmony_ci	u16 nvm_offset;
24358c2ecf20Sopenharmony_ci
24368c2ecf20Sopenharmony_ci	ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
24378c2ecf20Sopenharmony_ci	if (ret_val) {
24388c2ecf20Sopenharmony_ci		hw_dbg("NVM Read Error\n");
24398c2ecf20Sopenharmony_ci		goto out;
24408c2ecf20Sopenharmony_ci	}
24418c2ecf20Sopenharmony_ci
24428c2ecf20Sopenharmony_ci	if (nvm_data & NVM_COMPATIBILITY_BIT_MASK) {
24438c2ecf20Sopenharmony_ci		/* if checksums compatibility bit is set validate checksums
24448c2ecf20Sopenharmony_ci		 * for all 4 ports.
24458c2ecf20Sopenharmony_ci		 */
24468c2ecf20Sopenharmony_ci		eeprom_regions_count = 4;
24478c2ecf20Sopenharmony_ci	}
24488c2ecf20Sopenharmony_ci
24498c2ecf20Sopenharmony_ci	for (j = 0; j < eeprom_regions_count; j++) {
24508c2ecf20Sopenharmony_ci		nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
24518c2ecf20Sopenharmony_ci		ret_val = igb_validate_nvm_checksum_with_offset(hw,
24528c2ecf20Sopenharmony_ci								nvm_offset);
24538c2ecf20Sopenharmony_ci		if (ret_val != 0)
24548c2ecf20Sopenharmony_ci			goto out;
24558c2ecf20Sopenharmony_ci	}
24568c2ecf20Sopenharmony_ci
24578c2ecf20Sopenharmony_ciout:
24588c2ecf20Sopenharmony_ci	return ret_val;
24598c2ecf20Sopenharmony_ci}
24608c2ecf20Sopenharmony_ci
24618c2ecf20Sopenharmony_ci/**
24628c2ecf20Sopenharmony_ci *  igb_update_nvm_checksum_82580 - Update EEPROM checksum
24638c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
24648c2ecf20Sopenharmony_ci *
24658c2ecf20Sopenharmony_ci *  Updates the EEPROM section checksums for all 4 ports by reading/adding
24668c2ecf20Sopenharmony_ci *  each word of the EEPROM up to the checksum.  Then calculates the EEPROM
24678c2ecf20Sopenharmony_ci *  checksum and writes the value to the EEPROM.
24688c2ecf20Sopenharmony_ci **/
24698c2ecf20Sopenharmony_cistatic s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw)
24708c2ecf20Sopenharmony_ci{
24718c2ecf20Sopenharmony_ci	s32 ret_val;
24728c2ecf20Sopenharmony_ci	u16 j, nvm_data;
24738c2ecf20Sopenharmony_ci	u16 nvm_offset;
24748c2ecf20Sopenharmony_ci
24758c2ecf20Sopenharmony_ci	ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
24768c2ecf20Sopenharmony_ci	if (ret_val) {
24778c2ecf20Sopenharmony_ci		hw_dbg("NVM Read Error while updating checksum compatibility bit.\n");
24788c2ecf20Sopenharmony_ci		goto out;
24798c2ecf20Sopenharmony_ci	}
24808c2ecf20Sopenharmony_ci
24818c2ecf20Sopenharmony_ci	if ((nvm_data & NVM_COMPATIBILITY_BIT_MASK) == 0) {
24828c2ecf20Sopenharmony_ci		/* set compatibility bit to validate checksums appropriately */
24838c2ecf20Sopenharmony_ci		nvm_data = nvm_data | NVM_COMPATIBILITY_BIT_MASK;
24848c2ecf20Sopenharmony_ci		ret_val = hw->nvm.ops.write(hw, NVM_COMPATIBILITY_REG_3, 1,
24858c2ecf20Sopenharmony_ci					&nvm_data);
24868c2ecf20Sopenharmony_ci		if (ret_val) {
24878c2ecf20Sopenharmony_ci			hw_dbg("NVM Write Error while updating checksum compatibility bit.\n");
24888c2ecf20Sopenharmony_ci			goto out;
24898c2ecf20Sopenharmony_ci		}
24908c2ecf20Sopenharmony_ci	}
24918c2ecf20Sopenharmony_ci
24928c2ecf20Sopenharmony_ci	for (j = 0; j < 4; j++) {
24938c2ecf20Sopenharmony_ci		nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
24948c2ecf20Sopenharmony_ci		ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
24958c2ecf20Sopenharmony_ci		if (ret_val)
24968c2ecf20Sopenharmony_ci			goto out;
24978c2ecf20Sopenharmony_ci	}
24988c2ecf20Sopenharmony_ci
24998c2ecf20Sopenharmony_ciout:
25008c2ecf20Sopenharmony_ci	return ret_val;
25018c2ecf20Sopenharmony_ci}
25028c2ecf20Sopenharmony_ci
25038c2ecf20Sopenharmony_ci/**
25048c2ecf20Sopenharmony_ci *  igb_validate_nvm_checksum_i350 - Validate EEPROM checksum
25058c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
25068c2ecf20Sopenharmony_ci *
25078c2ecf20Sopenharmony_ci *  Calculates the EEPROM section checksum by reading/adding each word of
25088c2ecf20Sopenharmony_ci *  the EEPROM and then verifies that the sum of the EEPROM is
25098c2ecf20Sopenharmony_ci *  equal to 0xBABA.
25108c2ecf20Sopenharmony_ci **/
25118c2ecf20Sopenharmony_cistatic s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw)
25128c2ecf20Sopenharmony_ci{
25138c2ecf20Sopenharmony_ci	s32 ret_val = 0;
25148c2ecf20Sopenharmony_ci	u16 j;
25158c2ecf20Sopenharmony_ci	u16 nvm_offset;
25168c2ecf20Sopenharmony_ci
25178c2ecf20Sopenharmony_ci	for (j = 0; j < 4; j++) {
25188c2ecf20Sopenharmony_ci		nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
25198c2ecf20Sopenharmony_ci		ret_val = igb_validate_nvm_checksum_with_offset(hw,
25208c2ecf20Sopenharmony_ci								nvm_offset);
25218c2ecf20Sopenharmony_ci		if (ret_val != 0)
25228c2ecf20Sopenharmony_ci			goto out;
25238c2ecf20Sopenharmony_ci	}
25248c2ecf20Sopenharmony_ci
25258c2ecf20Sopenharmony_ciout:
25268c2ecf20Sopenharmony_ci	return ret_val;
25278c2ecf20Sopenharmony_ci}
25288c2ecf20Sopenharmony_ci
25298c2ecf20Sopenharmony_ci/**
25308c2ecf20Sopenharmony_ci *  igb_update_nvm_checksum_i350 - Update EEPROM checksum
25318c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
25328c2ecf20Sopenharmony_ci *
25338c2ecf20Sopenharmony_ci *  Updates the EEPROM section checksums for all 4 ports by reading/adding
25348c2ecf20Sopenharmony_ci *  each word of the EEPROM up to the checksum.  Then calculates the EEPROM
25358c2ecf20Sopenharmony_ci *  checksum and writes the value to the EEPROM.
25368c2ecf20Sopenharmony_ci **/
25378c2ecf20Sopenharmony_cistatic s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw)
25388c2ecf20Sopenharmony_ci{
25398c2ecf20Sopenharmony_ci	s32 ret_val = 0;
25408c2ecf20Sopenharmony_ci	u16 j;
25418c2ecf20Sopenharmony_ci	u16 nvm_offset;
25428c2ecf20Sopenharmony_ci
25438c2ecf20Sopenharmony_ci	for (j = 0; j < 4; j++) {
25448c2ecf20Sopenharmony_ci		nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
25458c2ecf20Sopenharmony_ci		ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
25468c2ecf20Sopenharmony_ci		if (ret_val != 0)
25478c2ecf20Sopenharmony_ci			goto out;
25488c2ecf20Sopenharmony_ci	}
25498c2ecf20Sopenharmony_ci
25508c2ecf20Sopenharmony_ciout:
25518c2ecf20Sopenharmony_ci	return ret_val;
25528c2ecf20Sopenharmony_ci}
25538c2ecf20Sopenharmony_ci
25548c2ecf20Sopenharmony_ci/**
25558c2ecf20Sopenharmony_ci *  __igb_access_emi_reg - Read/write EMI register
25568c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
25578c2ecf20Sopenharmony_ci *  @address: EMI address to program
25588c2ecf20Sopenharmony_ci *  @data: pointer to value to read/write from/to the EMI address
25598c2ecf20Sopenharmony_ci *  @read: boolean flag to indicate read or write
25608c2ecf20Sopenharmony_ci **/
25618c2ecf20Sopenharmony_cistatic s32 __igb_access_emi_reg(struct e1000_hw *hw, u16 address,
25628c2ecf20Sopenharmony_ci				  u16 *data, bool read)
25638c2ecf20Sopenharmony_ci{
25648c2ecf20Sopenharmony_ci	s32 ret_val = 0;
25658c2ecf20Sopenharmony_ci
25668c2ecf20Sopenharmony_ci	ret_val = hw->phy.ops.write_reg(hw, E1000_EMIADD, address);
25678c2ecf20Sopenharmony_ci	if (ret_val)
25688c2ecf20Sopenharmony_ci		return ret_val;
25698c2ecf20Sopenharmony_ci
25708c2ecf20Sopenharmony_ci	if (read)
25718c2ecf20Sopenharmony_ci		ret_val = hw->phy.ops.read_reg(hw, E1000_EMIDATA, data);
25728c2ecf20Sopenharmony_ci	else
25738c2ecf20Sopenharmony_ci		ret_val = hw->phy.ops.write_reg(hw, E1000_EMIDATA, *data);
25748c2ecf20Sopenharmony_ci
25758c2ecf20Sopenharmony_ci	return ret_val;
25768c2ecf20Sopenharmony_ci}
25778c2ecf20Sopenharmony_ci
25788c2ecf20Sopenharmony_ci/**
25798c2ecf20Sopenharmony_ci *  igb_read_emi_reg - Read Extended Management Interface register
25808c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
25818c2ecf20Sopenharmony_ci *  @addr: EMI address to program
25828c2ecf20Sopenharmony_ci *  @data: value to be read from the EMI address
25838c2ecf20Sopenharmony_ci **/
25848c2ecf20Sopenharmony_cis32 igb_read_emi_reg(struct e1000_hw *hw, u16 addr, u16 *data)
25858c2ecf20Sopenharmony_ci{
25868c2ecf20Sopenharmony_ci	return __igb_access_emi_reg(hw, addr, data, true);
25878c2ecf20Sopenharmony_ci}
25888c2ecf20Sopenharmony_ci
25898c2ecf20Sopenharmony_ci/**
25908c2ecf20Sopenharmony_ci *  igb_set_eee_i350 - Enable/disable EEE support
25918c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
25928c2ecf20Sopenharmony_ci *  @adv1G: boolean flag enabling 1G EEE advertisement
25938c2ecf20Sopenharmony_ci *  @adv100M: boolean flag enabling 100M EEE advertisement
25948c2ecf20Sopenharmony_ci *
25958c2ecf20Sopenharmony_ci *  Enable/disable EEE based on setting in dev_spec structure.
25968c2ecf20Sopenharmony_ci *
25978c2ecf20Sopenharmony_ci **/
25988c2ecf20Sopenharmony_cis32 igb_set_eee_i350(struct e1000_hw *hw, bool adv1G, bool adv100M)
25998c2ecf20Sopenharmony_ci{
26008c2ecf20Sopenharmony_ci	u32 ipcnfg, eeer;
26018c2ecf20Sopenharmony_ci
26028c2ecf20Sopenharmony_ci	if ((hw->mac.type < e1000_i350) ||
26038c2ecf20Sopenharmony_ci	    (hw->phy.media_type != e1000_media_type_copper))
26048c2ecf20Sopenharmony_ci		goto out;
26058c2ecf20Sopenharmony_ci	ipcnfg = rd32(E1000_IPCNFG);
26068c2ecf20Sopenharmony_ci	eeer = rd32(E1000_EEER);
26078c2ecf20Sopenharmony_ci
26088c2ecf20Sopenharmony_ci	/* enable or disable per user setting */
26098c2ecf20Sopenharmony_ci	if (!(hw->dev_spec._82575.eee_disable)) {
26108c2ecf20Sopenharmony_ci		u32 eee_su = rd32(E1000_EEE_SU);
26118c2ecf20Sopenharmony_ci
26128c2ecf20Sopenharmony_ci		if (adv100M)
26138c2ecf20Sopenharmony_ci			ipcnfg |= E1000_IPCNFG_EEE_100M_AN;
26148c2ecf20Sopenharmony_ci		else
26158c2ecf20Sopenharmony_ci			ipcnfg &= ~E1000_IPCNFG_EEE_100M_AN;
26168c2ecf20Sopenharmony_ci
26178c2ecf20Sopenharmony_ci		if (adv1G)
26188c2ecf20Sopenharmony_ci			ipcnfg |= E1000_IPCNFG_EEE_1G_AN;
26198c2ecf20Sopenharmony_ci		else
26208c2ecf20Sopenharmony_ci			ipcnfg &= ~E1000_IPCNFG_EEE_1G_AN;
26218c2ecf20Sopenharmony_ci
26228c2ecf20Sopenharmony_ci		eeer |= (E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
26238c2ecf20Sopenharmony_ci			E1000_EEER_LPI_FC);
26248c2ecf20Sopenharmony_ci
26258c2ecf20Sopenharmony_ci		/* This bit should not be set in normal operation. */
26268c2ecf20Sopenharmony_ci		if (eee_su & E1000_EEE_SU_LPI_CLK_STP)
26278c2ecf20Sopenharmony_ci			hw_dbg("LPI Clock Stop Bit should not be set!\n");
26288c2ecf20Sopenharmony_ci
26298c2ecf20Sopenharmony_ci	} else {
26308c2ecf20Sopenharmony_ci		ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN |
26318c2ecf20Sopenharmony_ci			E1000_IPCNFG_EEE_100M_AN);
26328c2ecf20Sopenharmony_ci		eeer &= ~(E1000_EEER_TX_LPI_EN |
26338c2ecf20Sopenharmony_ci			E1000_EEER_RX_LPI_EN |
26348c2ecf20Sopenharmony_ci			E1000_EEER_LPI_FC);
26358c2ecf20Sopenharmony_ci	}
26368c2ecf20Sopenharmony_ci	wr32(E1000_IPCNFG, ipcnfg);
26378c2ecf20Sopenharmony_ci	wr32(E1000_EEER, eeer);
26388c2ecf20Sopenharmony_ci	rd32(E1000_IPCNFG);
26398c2ecf20Sopenharmony_ci	rd32(E1000_EEER);
26408c2ecf20Sopenharmony_ciout:
26418c2ecf20Sopenharmony_ci
26428c2ecf20Sopenharmony_ci	return 0;
26438c2ecf20Sopenharmony_ci}
26448c2ecf20Sopenharmony_ci
26458c2ecf20Sopenharmony_ci/**
26468c2ecf20Sopenharmony_ci *  igb_set_eee_i354 - Enable/disable EEE support
26478c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
26488c2ecf20Sopenharmony_ci *  @adv1G: boolean flag enabling 1G EEE advertisement
26498c2ecf20Sopenharmony_ci *  @adv100M: boolean flag enabling 100M EEE advertisement
26508c2ecf20Sopenharmony_ci *
26518c2ecf20Sopenharmony_ci *  Enable/disable EEE legacy mode based on setting in dev_spec structure.
26528c2ecf20Sopenharmony_ci *
26538c2ecf20Sopenharmony_ci **/
26548c2ecf20Sopenharmony_cis32 igb_set_eee_i354(struct e1000_hw *hw, bool adv1G, bool adv100M)
26558c2ecf20Sopenharmony_ci{
26568c2ecf20Sopenharmony_ci	struct e1000_phy_info *phy = &hw->phy;
26578c2ecf20Sopenharmony_ci	s32 ret_val = 0;
26588c2ecf20Sopenharmony_ci	u16 phy_data;
26598c2ecf20Sopenharmony_ci
26608c2ecf20Sopenharmony_ci	if ((hw->phy.media_type != e1000_media_type_copper) ||
26618c2ecf20Sopenharmony_ci	    ((phy->id != M88E1543_E_PHY_ID) &&
26628c2ecf20Sopenharmony_ci	     (phy->id != M88E1512_E_PHY_ID)))
26638c2ecf20Sopenharmony_ci		goto out;
26648c2ecf20Sopenharmony_ci
26658c2ecf20Sopenharmony_ci	if (!hw->dev_spec._82575.eee_disable) {
26668c2ecf20Sopenharmony_ci		/* Switch to PHY page 18. */
26678c2ecf20Sopenharmony_ci		ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 18);
26688c2ecf20Sopenharmony_ci		if (ret_val)
26698c2ecf20Sopenharmony_ci			goto out;
26708c2ecf20Sopenharmony_ci
26718c2ecf20Sopenharmony_ci		ret_val = phy->ops.read_reg(hw, E1000_M88E1543_EEE_CTRL_1,
26728c2ecf20Sopenharmony_ci					    &phy_data);
26738c2ecf20Sopenharmony_ci		if (ret_val)
26748c2ecf20Sopenharmony_ci			goto out;
26758c2ecf20Sopenharmony_ci
26768c2ecf20Sopenharmony_ci		phy_data |= E1000_M88E1543_EEE_CTRL_1_MS;
26778c2ecf20Sopenharmony_ci		ret_val = phy->ops.write_reg(hw, E1000_M88E1543_EEE_CTRL_1,
26788c2ecf20Sopenharmony_ci					     phy_data);
26798c2ecf20Sopenharmony_ci		if (ret_val)
26808c2ecf20Sopenharmony_ci			goto out;
26818c2ecf20Sopenharmony_ci
26828c2ecf20Sopenharmony_ci		/* Return the PHY to page 0. */
26838c2ecf20Sopenharmony_ci		ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
26848c2ecf20Sopenharmony_ci		if (ret_val)
26858c2ecf20Sopenharmony_ci			goto out;
26868c2ecf20Sopenharmony_ci
26878c2ecf20Sopenharmony_ci		/* Turn on EEE advertisement. */
26888c2ecf20Sopenharmony_ci		ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
26898c2ecf20Sopenharmony_ci					     E1000_EEE_ADV_DEV_I354,
26908c2ecf20Sopenharmony_ci					     &phy_data);
26918c2ecf20Sopenharmony_ci		if (ret_val)
26928c2ecf20Sopenharmony_ci			goto out;
26938c2ecf20Sopenharmony_ci
26948c2ecf20Sopenharmony_ci		if (adv100M)
26958c2ecf20Sopenharmony_ci			phy_data |= E1000_EEE_ADV_100_SUPPORTED;
26968c2ecf20Sopenharmony_ci		else
26978c2ecf20Sopenharmony_ci			phy_data &= ~E1000_EEE_ADV_100_SUPPORTED;
26988c2ecf20Sopenharmony_ci
26998c2ecf20Sopenharmony_ci		if (adv1G)
27008c2ecf20Sopenharmony_ci			phy_data |= E1000_EEE_ADV_1000_SUPPORTED;
27018c2ecf20Sopenharmony_ci		else
27028c2ecf20Sopenharmony_ci			phy_data &= ~E1000_EEE_ADV_1000_SUPPORTED;
27038c2ecf20Sopenharmony_ci
27048c2ecf20Sopenharmony_ci		ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
27058c2ecf20Sopenharmony_ci						E1000_EEE_ADV_DEV_I354,
27068c2ecf20Sopenharmony_ci						phy_data);
27078c2ecf20Sopenharmony_ci	} else {
27088c2ecf20Sopenharmony_ci		/* Turn off EEE advertisement. */
27098c2ecf20Sopenharmony_ci		ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
27108c2ecf20Sopenharmony_ci					     E1000_EEE_ADV_DEV_I354,
27118c2ecf20Sopenharmony_ci					     &phy_data);
27128c2ecf20Sopenharmony_ci		if (ret_val)
27138c2ecf20Sopenharmony_ci			goto out;
27148c2ecf20Sopenharmony_ci
27158c2ecf20Sopenharmony_ci		phy_data &= ~(E1000_EEE_ADV_100_SUPPORTED |
27168c2ecf20Sopenharmony_ci			      E1000_EEE_ADV_1000_SUPPORTED);
27178c2ecf20Sopenharmony_ci		ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
27188c2ecf20Sopenharmony_ci					      E1000_EEE_ADV_DEV_I354,
27198c2ecf20Sopenharmony_ci					      phy_data);
27208c2ecf20Sopenharmony_ci	}
27218c2ecf20Sopenharmony_ci
27228c2ecf20Sopenharmony_ciout:
27238c2ecf20Sopenharmony_ci	return ret_val;
27248c2ecf20Sopenharmony_ci}
27258c2ecf20Sopenharmony_ci
27268c2ecf20Sopenharmony_ci/**
27278c2ecf20Sopenharmony_ci *  igb_get_eee_status_i354 - Get EEE status
27288c2ecf20Sopenharmony_ci *  @hw: pointer to the HW structure
27298c2ecf20Sopenharmony_ci *  @status: EEE status
27308c2ecf20Sopenharmony_ci *
27318c2ecf20Sopenharmony_ci *  Get EEE status by guessing based on whether Tx or Rx LPI indications have
27328c2ecf20Sopenharmony_ci *  been received.
27338c2ecf20Sopenharmony_ci **/
27348c2ecf20Sopenharmony_cis32 igb_get_eee_status_i354(struct e1000_hw *hw, bool *status)
27358c2ecf20Sopenharmony_ci{
27368c2ecf20Sopenharmony_ci	struct e1000_phy_info *phy = &hw->phy;
27378c2ecf20Sopenharmony_ci	s32 ret_val = 0;
27388c2ecf20Sopenharmony_ci	u16 phy_data;
27398c2ecf20Sopenharmony_ci
27408c2ecf20Sopenharmony_ci	/* Check if EEE is supported on this device. */
27418c2ecf20Sopenharmony_ci	if ((hw->phy.media_type != e1000_media_type_copper) ||
27428c2ecf20Sopenharmony_ci	    ((phy->id != M88E1543_E_PHY_ID) &&
27438c2ecf20Sopenharmony_ci	     (phy->id != M88E1512_E_PHY_ID)))
27448c2ecf20Sopenharmony_ci		goto out;
27458c2ecf20Sopenharmony_ci
27468c2ecf20Sopenharmony_ci	ret_val = igb_read_xmdio_reg(hw, E1000_PCS_STATUS_ADDR_I354,
27478c2ecf20Sopenharmony_ci				     E1000_PCS_STATUS_DEV_I354,
27488c2ecf20Sopenharmony_ci				     &phy_data);
27498c2ecf20Sopenharmony_ci	if (ret_val)
27508c2ecf20Sopenharmony_ci		goto out;
27518c2ecf20Sopenharmony_ci
27528c2ecf20Sopenharmony_ci	*status = phy_data & (E1000_PCS_STATUS_TX_LPI_RCVD |
27538c2ecf20Sopenharmony_ci			      E1000_PCS_STATUS_RX_LPI_RCVD) ? true : false;
27548c2ecf20Sopenharmony_ci
27558c2ecf20Sopenharmony_ciout:
27568c2ecf20Sopenharmony_ci	return ret_val;
27578c2ecf20Sopenharmony_ci}
27588c2ecf20Sopenharmony_ci
27598c2ecf20Sopenharmony_cistatic const u8 e1000_emc_temp_data[4] = {
27608c2ecf20Sopenharmony_ci	E1000_EMC_INTERNAL_DATA,
27618c2ecf20Sopenharmony_ci	E1000_EMC_DIODE1_DATA,
27628c2ecf20Sopenharmony_ci	E1000_EMC_DIODE2_DATA,
27638c2ecf20Sopenharmony_ci	E1000_EMC_DIODE3_DATA
27648c2ecf20Sopenharmony_ci};
27658c2ecf20Sopenharmony_cistatic const u8 e1000_emc_therm_limit[4] = {
27668c2ecf20Sopenharmony_ci	E1000_EMC_INTERNAL_THERM_LIMIT,
27678c2ecf20Sopenharmony_ci	E1000_EMC_DIODE1_THERM_LIMIT,
27688c2ecf20Sopenharmony_ci	E1000_EMC_DIODE2_THERM_LIMIT,
27698c2ecf20Sopenharmony_ci	E1000_EMC_DIODE3_THERM_LIMIT
27708c2ecf20Sopenharmony_ci};
27718c2ecf20Sopenharmony_ci
27728c2ecf20Sopenharmony_ci#ifdef CONFIG_IGB_HWMON
27738c2ecf20Sopenharmony_ci/**
27748c2ecf20Sopenharmony_ci *  igb_get_thermal_sensor_data_generic - Gathers thermal sensor data
27758c2ecf20Sopenharmony_ci *  @hw: pointer to hardware structure
27768c2ecf20Sopenharmony_ci *
27778c2ecf20Sopenharmony_ci *  Updates the temperatures in mac.thermal_sensor_data
27788c2ecf20Sopenharmony_ci **/
27798c2ecf20Sopenharmony_cistatic s32 igb_get_thermal_sensor_data_generic(struct e1000_hw *hw)
27808c2ecf20Sopenharmony_ci{
27818c2ecf20Sopenharmony_ci	u16 ets_offset;
27828c2ecf20Sopenharmony_ci	u16 ets_cfg;
27838c2ecf20Sopenharmony_ci	u16 ets_sensor;
27848c2ecf20Sopenharmony_ci	u8  num_sensors;
27858c2ecf20Sopenharmony_ci	u8  sensor_index;
27868c2ecf20Sopenharmony_ci	u8  sensor_location;
27878c2ecf20Sopenharmony_ci	u8  i;
27888c2ecf20Sopenharmony_ci	struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
27898c2ecf20Sopenharmony_ci
27908c2ecf20Sopenharmony_ci	if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
27918c2ecf20Sopenharmony_ci		return E1000_NOT_IMPLEMENTED;
27928c2ecf20Sopenharmony_ci
27938c2ecf20Sopenharmony_ci	data->sensor[0].temp = (rd32(E1000_THMJT) & 0xFF);
27948c2ecf20Sopenharmony_ci
27958c2ecf20Sopenharmony_ci	/* Return the internal sensor only if ETS is unsupported */
27968c2ecf20Sopenharmony_ci	hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
27978c2ecf20Sopenharmony_ci	if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
27988c2ecf20Sopenharmony_ci		return 0;
27998c2ecf20Sopenharmony_ci
28008c2ecf20Sopenharmony_ci	hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
28018c2ecf20Sopenharmony_ci	if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
28028c2ecf20Sopenharmony_ci	    != NVM_ETS_TYPE_EMC)
28038c2ecf20Sopenharmony_ci		return E1000_NOT_IMPLEMENTED;
28048c2ecf20Sopenharmony_ci
28058c2ecf20Sopenharmony_ci	num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
28068c2ecf20Sopenharmony_ci	if (num_sensors > E1000_MAX_SENSORS)
28078c2ecf20Sopenharmony_ci		num_sensors = E1000_MAX_SENSORS;
28088c2ecf20Sopenharmony_ci
28098c2ecf20Sopenharmony_ci	for (i = 1; i < num_sensors; i++) {
28108c2ecf20Sopenharmony_ci		hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
28118c2ecf20Sopenharmony_ci		sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
28128c2ecf20Sopenharmony_ci				NVM_ETS_DATA_INDEX_SHIFT);
28138c2ecf20Sopenharmony_ci		sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
28148c2ecf20Sopenharmony_ci				   NVM_ETS_DATA_LOC_SHIFT);
28158c2ecf20Sopenharmony_ci
28168c2ecf20Sopenharmony_ci		if (sensor_location != 0)
28178c2ecf20Sopenharmony_ci			hw->phy.ops.read_i2c_byte(hw,
28188c2ecf20Sopenharmony_ci					e1000_emc_temp_data[sensor_index],
28198c2ecf20Sopenharmony_ci					E1000_I2C_THERMAL_SENSOR_ADDR,
28208c2ecf20Sopenharmony_ci					&data->sensor[i].temp);
28218c2ecf20Sopenharmony_ci	}
28228c2ecf20Sopenharmony_ci	return 0;
28238c2ecf20Sopenharmony_ci}
28248c2ecf20Sopenharmony_ci
28258c2ecf20Sopenharmony_ci/**
28268c2ecf20Sopenharmony_ci *  igb_init_thermal_sensor_thresh_generic - Sets thermal sensor thresholds
28278c2ecf20Sopenharmony_ci *  @hw: pointer to hardware structure
28288c2ecf20Sopenharmony_ci *
28298c2ecf20Sopenharmony_ci *  Sets the thermal sensor thresholds according to the NVM map
28308c2ecf20Sopenharmony_ci *  and save off the threshold and location values into mac.thermal_sensor_data
28318c2ecf20Sopenharmony_ci **/
28328c2ecf20Sopenharmony_cistatic s32 igb_init_thermal_sensor_thresh_generic(struct e1000_hw *hw)
28338c2ecf20Sopenharmony_ci{
28348c2ecf20Sopenharmony_ci	u16 ets_offset;
28358c2ecf20Sopenharmony_ci	u16 ets_cfg;
28368c2ecf20Sopenharmony_ci	u16 ets_sensor;
28378c2ecf20Sopenharmony_ci	u8  low_thresh_delta;
28388c2ecf20Sopenharmony_ci	u8  num_sensors;
28398c2ecf20Sopenharmony_ci	u8  sensor_index;
28408c2ecf20Sopenharmony_ci	u8  sensor_location;
28418c2ecf20Sopenharmony_ci	u8  therm_limit;
28428c2ecf20Sopenharmony_ci	u8  i;
28438c2ecf20Sopenharmony_ci	struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
28448c2ecf20Sopenharmony_ci
28458c2ecf20Sopenharmony_ci	if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
28468c2ecf20Sopenharmony_ci		return E1000_NOT_IMPLEMENTED;
28478c2ecf20Sopenharmony_ci
28488c2ecf20Sopenharmony_ci	memset(data, 0, sizeof(struct e1000_thermal_sensor_data));
28498c2ecf20Sopenharmony_ci
28508c2ecf20Sopenharmony_ci	data->sensor[0].location = 0x1;
28518c2ecf20Sopenharmony_ci	data->sensor[0].caution_thresh =
28528c2ecf20Sopenharmony_ci		(rd32(E1000_THHIGHTC) & 0xFF);
28538c2ecf20Sopenharmony_ci	data->sensor[0].max_op_thresh =
28548c2ecf20Sopenharmony_ci		(rd32(E1000_THLOWTC) & 0xFF);
28558c2ecf20Sopenharmony_ci
28568c2ecf20Sopenharmony_ci	/* Return the internal sensor only if ETS is unsupported */
28578c2ecf20Sopenharmony_ci	hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
28588c2ecf20Sopenharmony_ci	if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
28598c2ecf20Sopenharmony_ci		return 0;
28608c2ecf20Sopenharmony_ci
28618c2ecf20Sopenharmony_ci	hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
28628c2ecf20Sopenharmony_ci	if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
28638c2ecf20Sopenharmony_ci	    != NVM_ETS_TYPE_EMC)
28648c2ecf20Sopenharmony_ci		return E1000_NOT_IMPLEMENTED;
28658c2ecf20Sopenharmony_ci
28668c2ecf20Sopenharmony_ci	low_thresh_delta = ((ets_cfg & NVM_ETS_LTHRES_DELTA_MASK) >>
28678c2ecf20Sopenharmony_ci			    NVM_ETS_LTHRES_DELTA_SHIFT);
28688c2ecf20Sopenharmony_ci	num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
28698c2ecf20Sopenharmony_ci
28708c2ecf20Sopenharmony_ci	for (i = 1; i <= num_sensors; i++) {
28718c2ecf20Sopenharmony_ci		hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
28728c2ecf20Sopenharmony_ci		sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
28738c2ecf20Sopenharmony_ci				NVM_ETS_DATA_INDEX_SHIFT);
28748c2ecf20Sopenharmony_ci		sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
28758c2ecf20Sopenharmony_ci				   NVM_ETS_DATA_LOC_SHIFT);
28768c2ecf20Sopenharmony_ci		therm_limit = ets_sensor & NVM_ETS_DATA_HTHRESH_MASK;
28778c2ecf20Sopenharmony_ci
28788c2ecf20Sopenharmony_ci		hw->phy.ops.write_i2c_byte(hw,
28798c2ecf20Sopenharmony_ci			e1000_emc_therm_limit[sensor_index],
28808c2ecf20Sopenharmony_ci			E1000_I2C_THERMAL_SENSOR_ADDR,
28818c2ecf20Sopenharmony_ci			therm_limit);
28828c2ecf20Sopenharmony_ci
28838c2ecf20Sopenharmony_ci		if ((i < E1000_MAX_SENSORS) && (sensor_location != 0)) {
28848c2ecf20Sopenharmony_ci			data->sensor[i].location = sensor_location;
28858c2ecf20Sopenharmony_ci			data->sensor[i].caution_thresh = therm_limit;
28868c2ecf20Sopenharmony_ci			data->sensor[i].max_op_thresh = therm_limit -
28878c2ecf20Sopenharmony_ci							low_thresh_delta;
28888c2ecf20Sopenharmony_ci		}
28898c2ecf20Sopenharmony_ci	}
28908c2ecf20Sopenharmony_ci	return 0;
28918c2ecf20Sopenharmony_ci}
28928c2ecf20Sopenharmony_ci
28938c2ecf20Sopenharmony_ci#endif
28948c2ecf20Sopenharmony_cistatic struct e1000_mac_operations e1000_mac_ops_82575 = {
28958c2ecf20Sopenharmony_ci	.init_hw              = igb_init_hw_82575,
28968c2ecf20Sopenharmony_ci	.check_for_link       = igb_check_for_link_82575,
28978c2ecf20Sopenharmony_ci	.rar_set              = igb_rar_set,
28988c2ecf20Sopenharmony_ci	.read_mac_addr        = igb_read_mac_addr_82575,
28998c2ecf20Sopenharmony_ci	.get_speed_and_duplex = igb_get_link_up_info_82575,
29008c2ecf20Sopenharmony_ci#ifdef CONFIG_IGB_HWMON
29018c2ecf20Sopenharmony_ci	.get_thermal_sensor_data = igb_get_thermal_sensor_data_generic,
29028c2ecf20Sopenharmony_ci	.init_thermal_sensor_thresh = igb_init_thermal_sensor_thresh_generic,
29038c2ecf20Sopenharmony_ci#endif
29048c2ecf20Sopenharmony_ci};
29058c2ecf20Sopenharmony_ci
29068c2ecf20Sopenharmony_cistatic const struct e1000_phy_operations e1000_phy_ops_82575 = {
29078c2ecf20Sopenharmony_ci	.acquire              = igb_acquire_phy_82575,
29088c2ecf20Sopenharmony_ci	.get_cfg_done         = igb_get_cfg_done_82575,
29098c2ecf20Sopenharmony_ci	.release              = igb_release_phy_82575,
29108c2ecf20Sopenharmony_ci	.write_i2c_byte       = igb_write_i2c_byte,
29118c2ecf20Sopenharmony_ci	.read_i2c_byte        = igb_read_i2c_byte,
29128c2ecf20Sopenharmony_ci};
29138c2ecf20Sopenharmony_ci
29148c2ecf20Sopenharmony_cistatic struct e1000_nvm_operations e1000_nvm_ops_82575 = {
29158c2ecf20Sopenharmony_ci	.acquire              = igb_acquire_nvm_82575,
29168c2ecf20Sopenharmony_ci	.read                 = igb_read_nvm_eerd,
29178c2ecf20Sopenharmony_ci	.release              = igb_release_nvm_82575,
29188c2ecf20Sopenharmony_ci	.write                = igb_write_nvm_spi,
29198c2ecf20Sopenharmony_ci};
29208c2ecf20Sopenharmony_ci
29218c2ecf20Sopenharmony_ciconst struct e1000_info e1000_82575_info = {
29228c2ecf20Sopenharmony_ci	.get_invariants = igb_get_invariants_82575,
29238c2ecf20Sopenharmony_ci	.mac_ops = &e1000_mac_ops_82575,
29248c2ecf20Sopenharmony_ci	.phy_ops = &e1000_phy_ops_82575,
29258c2ecf20Sopenharmony_ci	.nvm_ops = &e1000_nvm_ops_82575,
29268c2ecf20Sopenharmony_ci};
29278c2ecf20Sopenharmony_ci
2928