fp@2585: /*******************************************************************************
fp@2585: 
fp@2585:   Intel PRO/1000 Linux driver
fp@2585:   Copyright(c) 1999 - 2013 Intel Corporation.
fp@2585: 
fp@2585:   This program is free software; you can redistribute it and/or modify it
fp@2585:   under the terms and conditions of the GNU General Public License,
fp@2585:   version 2, as published by the Free Software Foundation.
fp@2585: 
fp@2585:   This program is distributed in the hope it will be useful, but WITHOUT
fp@2585:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fp@2585:   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
fp@2585:   more details.
fp@2585: 
fp@2585:   You should have received a copy of the GNU General Public License along with
fp@2585:   this program; if not, write to the Free Software Foundation, Inc.,
fp@2585:   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
fp@2585: 
fp@2585:   The full GNU General Public License is included in this distribution in
fp@2585:   the file called "COPYING".
fp@2585: 
fp@2585:   Contact Information:
fp@2585:   Linux NICS <linux.nics@intel.com>
fp@2585:   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
fp@2585:   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
fp@2585: 
fp@2585: *******************************************************************************/
fp@2585: 
fp@2585: /* ethtool support for e1000 */
fp@2585: 
fp@2585: #include <linux/netdevice.h>
fp@2585: #include <linux/interrupt.h>
fp@2585: #include <linux/ethtool.h>
fp@2585: #include <linux/pci.h>
fp@2585: #include <linux/slab.h>
fp@2585: #include <linux/delay.h>
fp@2585: #include <linux/vmalloc.h>
fp@2585: #include <linux/pm_runtime.h>
fp@2585: 
fp@2585: #include "e1000.h"
fp@2585: 
fp@2585: enum { NETDEV_STATS, E1000_STATS };
fp@2585: 
fp@2585: struct e1000_stats {
fp@2585: 	char stat_string[ETH_GSTRING_LEN];
fp@2585: 	int type;
fp@2585: 	int sizeof_stat;
fp@2585: 	int stat_offset;
fp@2585: };
fp@2585: 
fp@2585: #define E1000_STAT(str, m) { \
fp@2585: 		.stat_string = str, \
fp@2585: 		.type = E1000_STATS, \
fp@2585: 		.sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
fp@2585: 		.stat_offset = offsetof(struct e1000_adapter, m) }
fp@2585: #define E1000_NETDEV_STAT(str, m) { \
fp@2585: 		.stat_string = str, \
fp@2585: 		.type = NETDEV_STATS, \
fp@2585: 		.sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \
fp@2585: 		.stat_offset = offsetof(struct rtnl_link_stats64, m) }
fp@2585: 
fp@2585: static const struct e1000_stats e1000_gstrings_stats[] = {
fp@2585: 	E1000_STAT("rx_packets", stats.gprc),
fp@2585: 	E1000_STAT("tx_packets", stats.gptc),
fp@2585: 	E1000_STAT("rx_bytes", stats.gorc),
fp@2585: 	E1000_STAT("tx_bytes", stats.gotc),
fp@2585: 	E1000_STAT("rx_broadcast", stats.bprc),
fp@2585: 	E1000_STAT("tx_broadcast", stats.bptc),
fp@2585: 	E1000_STAT("rx_multicast", stats.mprc),
fp@2585: 	E1000_STAT("tx_multicast", stats.mptc),
fp@2585: 	E1000_NETDEV_STAT("rx_errors", rx_errors),
fp@2585: 	E1000_NETDEV_STAT("tx_errors", tx_errors),
fp@2585: 	E1000_NETDEV_STAT("tx_dropped", tx_dropped),
fp@2585: 	E1000_STAT("multicast", stats.mprc),
fp@2585: 	E1000_STAT("collisions", stats.colc),
fp@2585: 	E1000_NETDEV_STAT("rx_length_errors", rx_length_errors),
fp@2585: 	E1000_NETDEV_STAT("rx_over_errors", rx_over_errors),
fp@2585: 	E1000_STAT("rx_crc_errors", stats.crcerrs),
fp@2585: 	E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
fp@2585: 	E1000_STAT("rx_no_buffer_count", stats.rnbc),
fp@2585: 	E1000_STAT("rx_missed_errors", stats.mpc),
fp@2585: 	E1000_STAT("tx_aborted_errors", stats.ecol),
fp@2585: 	E1000_STAT("tx_carrier_errors", stats.tncrs),
fp@2585: 	E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
fp@2585: 	E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
fp@2585: 	E1000_STAT("tx_window_errors", stats.latecol),
fp@2585: 	E1000_STAT("tx_abort_late_coll", stats.latecol),
fp@2585: 	E1000_STAT("tx_deferred_ok", stats.dc),
fp@2585: 	E1000_STAT("tx_single_coll_ok", stats.scc),
fp@2585: 	E1000_STAT("tx_multi_coll_ok", stats.mcc),
fp@2585: 	E1000_STAT("tx_timeout_count", tx_timeout_count),
fp@2585: 	E1000_STAT("tx_restart_queue", restart_queue),
fp@2585: 	E1000_STAT("rx_long_length_errors", stats.roc),
fp@2585: 	E1000_STAT("rx_short_length_errors", stats.ruc),
fp@2585: 	E1000_STAT("rx_align_errors", stats.algnerrc),
fp@2585: 	E1000_STAT("tx_tcp_seg_good", stats.tsctc),
fp@2585: 	E1000_STAT("tx_tcp_seg_failed", stats.tsctfc),
fp@2585: 	E1000_STAT("rx_flow_control_xon", stats.xonrxc),
fp@2585: 	E1000_STAT("rx_flow_control_xoff", stats.xoffrxc),
fp@2585: 	E1000_STAT("tx_flow_control_xon", stats.xontxc),
fp@2585: 	E1000_STAT("tx_flow_control_xoff", stats.xofftxc),
fp@2585: 	E1000_STAT("rx_csum_offload_good", hw_csum_good),
fp@2585: 	E1000_STAT("rx_csum_offload_errors", hw_csum_err),
fp@2585: 	E1000_STAT("rx_header_split", rx_hdr_split),
fp@2585: 	E1000_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),
fp@2585: 	E1000_STAT("tx_smbus", stats.mgptc),
fp@2585: 	E1000_STAT("rx_smbus", stats.mgprc),
fp@2585: 	E1000_STAT("dropped_smbus", stats.mgpdc),
fp@2585: 	E1000_STAT("rx_dma_failed", rx_dma_failed),
fp@2585: 	E1000_STAT("tx_dma_failed", tx_dma_failed),
fp@2585: 	E1000_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
fp@2585: 	E1000_STAT("uncorr_ecc_errors", uncorr_errors),
fp@2585: 	E1000_STAT("corr_ecc_errors", corr_errors),
fp@2585: };
fp@2585: 
fp@2585: #define E1000_GLOBAL_STATS_LEN	ARRAY_SIZE(e1000_gstrings_stats)
fp@2585: #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
fp@2585: static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
fp@2585: 	"Register test  (offline)", "Eeprom test    (offline)",
fp@2585: 	"Interrupt test (offline)", "Loopback test  (offline)",
fp@2585: 	"Link test   (on/offline)"
fp@2585: };
fp@2585: 
fp@2585: #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
fp@2585: 
fp@2585: static int e1000_get_settings(struct net_device *netdev,
fp@2585: 			      struct ethtool_cmd *ecmd)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 	u32 speed;
fp@2585: 
fp@2585: 	if (hw->phy.media_type == e1000_media_type_copper) {
fp@2585: 		ecmd->supported = (SUPPORTED_10baseT_Half |
fp@2585: 				   SUPPORTED_10baseT_Full |
fp@2585: 				   SUPPORTED_100baseT_Half |
fp@2585: 				   SUPPORTED_100baseT_Full |
fp@2585: 				   SUPPORTED_1000baseT_Full |
fp@2585: 				   SUPPORTED_Autoneg |
fp@2585: 				   SUPPORTED_TP);
fp@2585: 		if (hw->phy.type == e1000_phy_ife)
fp@2585: 			ecmd->supported &= ~SUPPORTED_1000baseT_Full;
fp@2585: 		ecmd->advertising = ADVERTISED_TP;
fp@2585: 
fp@2585: 		if (hw->mac.autoneg == 1) {
fp@2585: 			ecmd->advertising |= ADVERTISED_Autoneg;
fp@2585: 			/* the e1000 autoneg seems to match ethtool nicely */
fp@2585: 			ecmd->advertising |= hw->phy.autoneg_advertised;
fp@2585: 		}
fp@2585: 
fp@2585: 		ecmd->port = PORT_TP;
fp@2585: 		ecmd->phy_address = hw->phy.addr;
fp@2585: 		ecmd->transceiver = XCVR_INTERNAL;
fp@2585: 
fp@2585: 	} else {
fp@2585: 		ecmd->supported   = (SUPPORTED_1000baseT_Full |
fp@2585: 				     SUPPORTED_FIBRE |
fp@2585: 				     SUPPORTED_Autoneg);
fp@2585: 
fp@2585: 		ecmd->advertising = (ADVERTISED_1000baseT_Full |
fp@2585: 				     ADVERTISED_FIBRE |
fp@2585: 				     ADVERTISED_Autoneg);
fp@2585: 
fp@2585: 		ecmd->port = PORT_FIBRE;
fp@2585: 		ecmd->transceiver = XCVR_EXTERNAL;
fp@2585: 	}
fp@2585: 
fp@2585: 	speed = -1;
fp@2585: 	ecmd->duplex = -1;
fp@2585: 
fp@2585: 	if (netif_running(netdev)) {
fp@2585: 		if (netif_carrier_ok(netdev)) {
fp@2585: 			speed = adapter->link_speed;
fp@2585: 			ecmd->duplex = adapter->link_duplex - 1;
fp@2585: 		}
fp@2585: 	} else {
fp@2585: 		u32 status = er32(STATUS);
fp@2585: 		if (status & E1000_STATUS_LU) {
fp@2585: 			if (status & E1000_STATUS_SPEED_1000)
fp@2585: 				speed = SPEED_1000;
fp@2585: 			else if (status & E1000_STATUS_SPEED_100)
fp@2585: 				speed = SPEED_100;
fp@2585: 			else
fp@2585: 				speed = SPEED_10;
fp@2585: 
fp@2585: 			if (status & E1000_STATUS_FD)
fp@2585: 				ecmd->duplex = DUPLEX_FULL;
fp@2585: 			else
fp@2585: 				ecmd->duplex = DUPLEX_HALF;
fp@2585: 		}
fp@2585: 	}
fp@2585: 
fp@2585: 	ethtool_cmd_speed_set(ecmd, speed);
fp@2585: 	ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
fp@2585: 			 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
fp@2585: 
fp@2585: 	/* MDI-X => 2; MDI =>1; Invalid =>0 */
fp@2585: 	if ((hw->phy.media_type == e1000_media_type_copper) &&
fp@2585: 	    netif_carrier_ok(netdev))
fp@2585: 		ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X : ETH_TP_MDI;
fp@2585: 	else
fp@2585: 		ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
fp@2585: 
fp@2585: 	if (hw->phy.mdix == AUTO_ALL_MODES)
fp@2585: 		ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
fp@2585: 	else
fp@2585: 		ecmd->eth_tp_mdix_ctrl = hw->phy.mdix;
fp@2585: 
fp@2585: 	return 0;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
fp@2585: {
fp@2585: 	struct e1000_mac_info *mac = &adapter->hw.mac;
fp@2585: 
fp@2585: 	mac->autoneg = 0;
fp@2585: 
fp@2585: 	/* Make sure dplx is at most 1 bit and lsb of speed is not set
fp@2585: 	 * for the switch() below to work
fp@2585: 	 */
fp@2585: 	if ((spd & 1) || (dplx & ~1))
fp@2585: 		goto err_inval;
fp@2585: 
fp@2585: 	/* Fiber NICs only allow 1000 gbps Full duplex */
fp@2585: 	if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
fp@2585: 	    (spd != SPEED_1000) && (dplx != DUPLEX_FULL)) {
fp@2585: 		goto err_inval;
fp@2585: 	}
fp@2585: 
fp@2585: 	switch (spd + dplx) {
fp@2585: 	case SPEED_10 + DUPLEX_HALF:
fp@2585: 		mac->forced_speed_duplex = ADVERTISE_10_HALF;
fp@2585: 		break;
fp@2585: 	case SPEED_10 + DUPLEX_FULL:
fp@2585: 		mac->forced_speed_duplex = ADVERTISE_10_FULL;
fp@2585: 		break;
fp@2585: 	case SPEED_100 + DUPLEX_HALF:
fp@2585: 		mac->forced_speed_duplex = ADVERTISE_100_HALF;
fp@2585: 		break;
fp@2585: 	case SPEED_100 + DUPLEX_FULL:
fp@2585: 		mac->forced_speed_duplex = ADVERTISE_100_FULL;
fp@2585: 		break;
fp@2585: 	case SPEED_1000 + DUPLEX_FULL:
fp@2585: 		mac->autoneg = 1;
fp@2585: 		adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
fp@2585: 		break;
fp@2585: 	case SPEED_1000 + DUPLEX_HALF: /* not supported */
fp@2585: 	default:
fp@2585: 		goto err_inval;
fp@2585: 	}
fp@2585: 
fp@2585: 	/* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
fp@2585: 	adapter->hw.phy.mdix = AUTO_ALL_MODES;
fp@2585: 
fp@2585: 	return 0;
fp@2585: 
fp@2585: err_inval:
fp@2585: 	e_err("Unsupported Speed/Duplex configuration\n");
fp@2585: 	return -EINVAL;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_set_settings(struct net_device *netdev,
fp@2585: 			      struct ethtool_cmd *ecmd)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 
fp@2585: 	/* When SoL/IDER sessions are active, autoneg/speed/duplex
fp@2585: 	 * cannot be changed
fp@2585: 	 */
fp@2585: 	if (hw->phy.ops.check_reset_block &&
fp@2585: 	    hw->phy.ops.check_reset_block(hw)) {
fp@2585: 		e_err("Cannot change link characteristics when SoL/IDER is active.\n");
fp@2585: 		return -EINVAL;
fp@2585: 	}
fp@2585: 
fp@2585: 	/* MDI setting is only allowed when autoneg enabled because
fp@2585: 	 * some hardware doesn't allow MDI setting when speed or
fp@2585: 	 * duplex is forced.
fp@2585: 	 */
fp@2585: 	if (ecmd->eth_tp_mdix_ctrl) {
fp@2585: 		if (hw->phy.media_type != e1000_media_type_copper)
fp@2585: 			return -EOPNOTSUPP;
fp@2585: 
fp@2585: 		if ((ecmd->eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) &&
fp@2585: 		    (ecmd->autoneg != AUTONEG_ENABLE)) {
fp@2585: 			e_err("forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
fp@2585: 			return -EINVAL;
fp@2585: 		}
fp@2585: 	}
fp@2585: 
fp@2585: 	while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
fp@2585: 		usleep_range(1000, 2000);
fp@2585: 
fp@2585: 	if (ecmd->autoneg == AUTONEG_ENABLE) {
fp@2585: 		hw->mac.autoneg = 1;
fp@2585: 		if (hw->phy.media_type == e1000_media_type_fiber)
fp@2585: 			hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
fp@2585: 			    ADVERTISED_FIBRE | ADVERTISED_Autoneg;
fp@2585: 		else
fp@2585: 			hw->phy.autoneg_advertised = ecmd->advertising |
fp@2585: 			    ADVERTISED_TP | ADVERTISED_Autoneg;
fp@2585: 		ecmd->advertising = hw->phy.autoneg_advertised;
fp@2585: 		if (adapter->fc_autoneg)
fp@2585: 			hw->fc.requested_mode = e1000_fc_default;
fp@2585: 	} else {
fp@2585: 		u32 speed = ethtool_cmd_speed(ecmd);
fp@2585: 		/* calling this overrides forced MDI setting */
fp@2585: 		if (e1000_set_spd_dplx(adapter, speed, ecmd->duplex)) {
fp@2585: 			clear_bit(__E1000_RESETTING, &adapter->state);
fp@2585: 			return -EINVAL;
fp@2585: 		}
fp@2585: 	}
fp@2585: 
fp@2585: 	/* MDI-X => 2; MDI => 1; Auto => 3 */
fp@2585: 	if (ecmd->eth_tp_mdix_ctrl) {
fp@2585: 		/* fix up the value for auto (3 => 0) as zero is mapped
fp@2585: 		 * internally to auto
fp@2585: 		 */
fp@2585: 		if (ecmd->eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
fp@2585: 			hw->phy.mdix = AUTO_ALL_MODES;
fp@2585: 		else
fp@2585: 			hw->phy.mdix = ecmd->eth_tp_mdix_ctrl;
fp@2585: 	}
fp@2585: 
fp@2585: 	/* reset the link */
fp@2585: 	if (netif_running(adapter->netdev)) {
fp@2585: 		e1000e_down(adapter);
fp@2585: 		e1000e_up(adapter);
fp@2585: 	} else {
fp@2585: 		e1000e_reset(adapter);
fp@2585: 	}
fp@2585: 
fp@2585: 	clear_bit(__E1000_RESETTING, &adapter->state);
fp@2585: 	return 0;
fp@2585: }
fp@2585: 
fp@2585: static void e1000_get_pauseparam(struct net_device *netdev,
fp@2585: 				 struct ethtool_pauseparam *pause)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 
fp@2585: 	pause->autoneg =
fp@2585: 	    (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
fp@2585: 
fp@2585: 	if (hw->fc.current_mode == e1000_fc_rx_pause) {
fp@2585: 		pause->rx_pause = 1;
fp@2585: 	} else if (hw->fc.current_mode == e1000_fc_tx_pause) {
fp@2585: 		pause->tx_pause = 1;
fp@2585: 	} else if (hw->fc.current_mode == e1000_fc_full) {
fp@2585: 		pause->rx_pause = 1;
fp@2585: 		pause->tx_pause = 1;
fp@2585: 	}
fp@2585: }
fp@2585: 
fp@2585: static int e1000_set_pauseparam(struct net_device *netdev,
fp@2585: 				struct ethtool_pauseparam *pause)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 	int retval = 0;
fp@2585: 
fp@2585: 	adapter->fc_autoneg = pause->autoneg;
fp@2585: 
fp@2585: 	while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
fp@2585: 		usleep_range(1000, 2000);
fp@2585: 
fp@2585: 	if (adapter->fc_autoneg == AUTONEG_ENABLE) {
fp@2585: 		hw->fc.requested_mode = e1000_fc_default;
fp@2585: 		if (netif_running(adapter->netdev)) {
fp@2585: 			e1000e_down(adapter);
fp@2585: 			e1000e_up(adapter);
fp@2585: 		} else {
fp@2585: 			e1000e_reset(adapter);
fp@2585: 		}
fp@2585: 	} else {
fp@2585: 		if (pause->rx_pause && pause->tx_pause)
fp@2585: 			hw->fc.requested_mode = e1000_fc_full;
fp@2585: 		else if (pause->rx_pause && !pause->tx_pause)
fp@2585: 			hw->fc.requested_mode = e1000_fc_rx_pause;
fp@2585: 		else if (!pause->rx_pause && pause->tx_pause)
fp@2585: 			hw->fc.requested_mode = e1000_fc_tx_pause;
fp@2585: 		else if (!pause->rx_pause && !pause->tx_pause)
fp@2585: 			hw->fc.requested_mode = e1000_fc_none;
fp@2585: 
fp@2585: 		hw->fc.current_mode = hw->fc.requested_mode;
fp@2585: 
fp@2585: 		if (hw->phy.media_type == e1000_media_type_fiber) {
fp@2585: 			retval = hw->mac.ops.setup_link(hw);
fp@2585: 			/* implicit goto out */
fp@2585: 		} else {
fp@2585: 			retval = e1000e_force_mac_fc(hw);
fp@2585: 			if (retval)
fp@2585: 				goto out;
fp@2585: 			e1000e_set_fc_watermarks(hw);
fp@2585: 		}
fp@2585: 	}
fp@2585: 
fp@2585: out:
fp@2585: 	clear_bit(__E1000_RESETTING, &adapter->state);
fp@2585: 	return retval;
fp@2585: }
fp@2585: 
fp@2585: static u32 e1000_get_msglevel(struct net_device *netdev)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	return adapter->msg_enable;
fp@2585: }
fp@2585: 
fp@2585: static void e1000_set_msglevel(struct net_device *netdev, u32 data)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	adapter->msg_enable = data;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_get_regs_len(struct net_device __always_unused *netdev)
fp@2585: {
fp@2585: #define E1000_REGS_LEN 32 /* overestimate */
fp@2585: 	return E1000_REGS_LEN * sizeof(u32);
fp@2585: }
fp@2585: 
fp@2585: static void e1000_get_regs(struct net_device *netdev,
fp@2585: 			   struct ethtool_regs *regs, void *p)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 	u32 *regs_buff = p;
fp@2585: 	u16 phy_data;
fp@2585: 
fp@2585: 	memset(p, 0, E1000_REGS_LEN * sizeof(u32));
fp@2585: 
fp@2585: 	regs->version = (1 << 24) | (adapter->pdev->revision << 16) |
fp@2585: 	    adapter->pdev->device;
fp@2585: 
fp@2585: 	regs_buff[0]  = er32(CTRL);
fp@2585: 	regs_buff[1]  = er32(STATUS);
fp@2585: 
fp@2585: 	regs_buff[2]  = er32(RCTL);
fp@2585: 	regs_buff[3]  = er32(RDLEN(0));
fp@2585: 	regs_buff[4]  = er32(RDH(0));
fp@2585: 	regs_buff[5]  = er32(RDT(0));
fp@2585: 	regs_buff[6]  = er32(RDTR);
fp@2585: 
fp@2585: 	regs_buff[7]  = er32(TCTL);
fp@2585: 	regs_buff[8]  = er32(TDLEN(0));
fp@2585: 	regs_buff[9]  = er32(TDH(0));
fp@2585: 	regs_buff[10] = er32(TDT(0));
fp@2585: 	regs_buff[11] = er32(TIDV);
fp@2585: 
fp@2585: 	regs_buff[12] = adapter->hw.phy.type;  /* PHY type (IGP=1, M88=0) */
fp@2585: 
fp@2585: 	/* ethtool doesn't use anything past this point, so all this
fp@2585: 	 * code is likely legacy junk for apps that may or may not exist
fp@2585: 	 */
fp@2585: 	if (hw->phy.type == e1000_phy_m88) {
fp@2585: 		e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
fp@2585: 		regs_buff[13] = (u32)phy_data; /* cable length */
fp@2585: 		regs_buff[14] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
fp@2585: 		regs_buff[15] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
fp@2585: 		regs_buff[16] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
fp@2585: 		e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
fp@2585: 		regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
fp@2585: 		regs_buff[18] = regs_buff[13]; /* cable polarity */
fp@2585: 		regs_buff[19] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
fp@2585: 		regs_buff[20] = regs_buff[17]; /* polarity correction */
fp@2585: 		/* phy receive errors */
fp@2585: 		regs_buff[22] = adapter->phy_stats.receive_errors;
fp@2585: 		regs_buff[23] = regs_buff[13]; /* mdix mode */
fp@2585: 	}
fp@2585: 	regs_buff[21] = 0;	/* was idle_errors */
fp@2585: 	e1e_rphy(hw, MII_STAT1000, &phy_data);
fp@2585: 	regs_buff[24] = (u32)phy_data;	/* phy local receiver status */
fp@2585: 	regs_buff[25] = regs_buff[24];	/* phy remote receiver status */
fp@2585: }
fp@2585: 
fp@2585: static int e1000_get_eeprom_len(struct net_device *netdev)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	return adapter->hw.nvm.word_size * 2;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_get_eeprom(struct net_device *netdev,
fp@2585: 			    struct ethtool_eeprom *eeprom, u8 *bytes)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 	u16 *eeprom_buff;
fp@2585: 	int first_word;
fp@2585: 	int last_word;
fp@2585: 	int ret_val = 0;
fp@2585: 	u16 i;
fp@2585: 
fp@2585: 	if (eeprom->len == 0)
fp@2585: 		return -EINVAL;
fp@2585: 
fp@2585: 	eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
fp@2585: 
fp@2585: 	first_word = eeprom->offset >> 1;
fp@2585: 	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
fp@2585: 
fp@2585: 	eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
fp@2585: 			      GFP_KERNEL);
fp@2585: 	if (!eeprom_buff)
fp@2585: 		return -ENOMEM;
fp@2585: 
fp@2585: 	if (hw->nvm.type == e1000_nvm_eeprom_spi) {
fp@2585: 		ret_val = e1000_read_nvm(hw, first_word,
fp@2585: 					 last_word - first_word + 1,
fp@2585: 					 eeprom_buff);
fp@2585: 	} else {
fp@2585: 		for (i = 0; i < last_word - first_word + 1; i++) {
fp@2585: 			ret_val = e1000_read_nvm(hw, first_word + i, 1,
fp@2585: 						 &eeprom_buff[i]);
fp@2585: 			if (ret_val)
fp@2585: 				break;
fp@2585: 		}
fp@2585: 	}
fp@2585: 
fp@2585: 	if (ret_val) {
fp@2585: 		/* a read error occurred, throw away the result */
fp@2585: 		memset(eeprom_buff, 0xff, sizeof(u16) *
fp@2585: 		       (last_word - first_word + 1));
fp@2585: 	} else {
fp@2585: 		/* Device's eeprom is always little-endian, word addressable */
fp@2585: 		for (i = 0; i < last_word - first_word + 1; i++)
fp@2585: 			le16_to_cpus(&eeprom_buff[i]);
fp@2585: 	}
fp@2585: 
fp@2585: 	memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
fp@2585: 	kfree(eeprom_buff);
fp@2585: 
fp@2585: 	return ret_val;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_set_eeprom(struct net_device *netdev,
fp@2585: 			    struct ethtool_eeprom *eeprom, u8 *bytes)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 	u16 *eeprom_buff;
fp@2585: 	void *ptr;
fp@2585: 	int max_len;
fp@2585: 	int first_word;
fp@2585: 	int last_word;
fp@2585: 	int ret_val = 0;
fp@2585: 	u16 i;
fp@2585: 
fp@2585: 	if (eeprom->len == 0)
fp@2585: 		return -EOPNOTSUPP;
fp@2585: 
fp@2585: 	if (eeprom->magic !=
fp@2585: 	    (adapter->pdev->vendor | (adapter->pdev->device << 16)))
fp@2585: 		return -EFAULT;
fp@2585: 
fp@2585: 	if (adapter->flags & FLAG_READ_ONLY_NVM)
fp@2585: 		return -EINVAL;
fp@2585: 
fp@2585: 	max_len = hw->nvm.word_size * 2;
fp@2585: 
fp@2585: 	first_word = eeprom->offset >> 1;
fp@2585: 	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
fp@2585: 	eeprom_buff = kmalloc(max_len, GFP_KERNEL);
fp@2585: 	if (!eeprom_buff)
fp@2585: 		return -ENOMEM;
fp@2585: 
fp@2585: 	ptr = (void *)eeprom_buff;
fp@2585: 
fp@2585: 	if (eeprom->offset & 1) {
fp@2585: 		/* need read/modify/write of first changed EEPROM word */
fp@2585: 		/* only the second byte of the word is being modified */
fp@2585: 		ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
fp@2585: 		ptr++;
fp@2585: 	}
fp@2585: 	if (((eeprom->offset + eeprom->len) & 1) && (!ret_val))
fp@2585: 		/* need read/modify/write of last changed EEPROM word */
fp@2585: 		/* only the first byte of the word is being modified */
fp@2585: 		ret_val = e1000_read_nvm(hw, last_word, 1,
fp@2585: 					 &eeprom_buff[last_word - first_word]);
fp@2585: 
fp@2585: 	if (ret_val)
fp@2585: 		goto out;
fp@2585: 
fp@2585: 	/* Device's eeprom is always little-endian, word addressable */
fp@2585: 	for (i = 0; i < last_word - first_word + 1; i++)
fp@2585: 		le16_to_cpus(&eeprom_buff[i]);
fp@2585: 
fp@2585: 	memcpy(ptr, bytes, eeprom->len);
fp@2585: 
fp@2585: 	for (i = 0; i < last_word - first_word + 1; i++)
fp@2585: 		cpu_to_le16s(&eeprom_buff[i]);
fp@2585: 
fp@2585: 	ret_val = e1000_write_nvm(hw, first_word,
fp@2585: 				  last_word - first_word + 1, eeprom_buff);
fp@2585: 
fp@2585: 	if (ret_val)
fp@2585: 		goto out;
fp@2585: 
fp@2585: 	/* Update the checksum over the first part of the EEPROM if needed
fp@2585: 	 * and flush shadow RAM for applicable controllers
fp@2585: 	 */
fp@2585: 	if ((first_word <= NVM_CHECKSUM_REG) ||
fp@2585: 	    (hw->mac.type == e1000_82583) ||
fp@2585: 	    (hw->mac.type == e1000_82574) ||
fp@2585: 	    (hw->mac.type == e1000_82573))
fp@2585: 		ret_val = e1000e_update_nvm_checksum(hw);
fp@2585: 
fp@2585: out:
fp@2585: 	kfree(eeprom_buff);
fp@2585: 	return ret_val;
fp@2585: }
fp@2585: 
fp@2585: static void e1000_get_drvinfo(struct net_device *netdev,
fp@2585: 			      struct ethtool_drvinfo *drvinfo)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 
fp@2585: 	strlcpy(drvinfo->driver, e1000e_driver_name, sizeof(drvinfo->driver));
fp@2585: 	strlcpy(drvinfo->version, e1000e_driver_version,
fp@2585: 		sizeof(drvinfo->version));
fp@2585: 
fp@2585: 	/* EEPROM image version # is reported as firmware version # for
fp@2585: 	 * PCI-E controllers
fp@2585: 	 */
fp@2585: 	snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
fp@2585: 		 "%d.%d-%d",
fp@2585: 		 (adapter->eeprom_vers & 0xF000) >> 12,
fp@2585: 		 (adapter->eeprom_vers & 0x0FF0) >> 4,
fp@2585: 		 (adapter->eeprom_vers & 0x000F));
fp@2585: 
fp@2585: 	strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
fp@2585: 		sizeof(drvinfo->bus_info));
fp@2585: 	drvinfo->regdump_len = e1000_get_regs_len(netdev);
fp@2585: 	drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
fp@2585: }
fp@2585: 
fp@2585: static void e1000_get_ringparam(struct net_device *netdev,
fp@2585: 				struct ethtool_ringparam *ring)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 
fp@2585: 	ring->rx_max_pending = E1000_MAX_RXD;
fp@2585: 	ring->tx_max_pending = E1000_MAX_TXD;
fp@2585: 	ring->rx_pending = adapter->rx_ring_count;
fp@2585: 	ring->tx_pending = adapter->tx_ring_count;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_set_ringparam(struct net_device *netdev,
fp@2585: 			       struct ethtool_ringparam *ring)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	struct e1000_ring *temp_tx = NULL, *temp_rx = NULL;
fp@2585: 	int err = 0, size = sizeof(struct e1000_ring);
fp@2585: 	bool set_tx = false, set_rx = false;
fp@2585: 	u16 new_rx_count, new_tx_count;
fp@2585: 
fp@2585: 	if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
fp@2585: 		return -EINVAL;
fp@2585: 
fp@2585: 	new_rx_count = clamp_t(u32, ring->rx_pending, E1000_MIN_RXD,
fp@2585: 			       E1000_MAX_RXD);
fp@2585: 	new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
fp@2585: 
fp@2585: 	new_tx_count = clamp_t(u32, ring->tx_pending, E1000_MIN_TXD,
fp@2585: 			       E1000_MAX_TXD);
fp@2585: 	new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
fp@2585: 
fp@2585: 	if ((new_tx_count == adapter->tx_ring_count) &&
fp@2585: 	    (new_rx_count == adapter->rx_ring_count))
fp@2585: 		/* nothing to do */
fp@2585: 		return 0;
fp@2585: 
fp@2585: 	while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
fp@2585: 		usleep_range(1000, 2000);
fp@2585: 
fp@2585: 	if (!netif_running(adapter->netdev)) {
fp@2585: 		/* Set counts now and allocate resources during open() */
fp@2585: 		adapter->tx_ring->count = new_tx_count;
fp@2585: 		adapter->rx_ring->count = new_rx_count;
fp@2585: 		adapter->tx_ring_count = new_tx_count;
fp@2585: 		adapter->rx_ring_count = new_rx_count;
fp@2585: 		goto clear_reset;
fp@2585: 	}
fp@2585: 
fp@2585: 	set_tx = (new_tx_count != adapter->tx_ring_count);
fp@2585: 	set_rx = (new_rx_count != adapter->rx_ring_count);
fp@2585: 
fp@2585: 	/* Allocate temporary storage for ring updates */
fp@2585: 	if (set_tx) {
fp@2585: 		temp_tx = vmalloc(size);
fp@2585: 		if (!temp_tx) {
fp@2585: 			err = -ENOMEM;
fp@2585: 			goto free_temp;
fp@2585: 		}
fp@2585: 	}
fp@2585: 	if (set_rx) {
fp@2585: 		temp_rx = vmalloc(size);
fp@2585: 		if (!temp_rx) {
fp@2585: 			err = -ENOMEM;
fp@2585: 			goto free_temp;
fp@2585: 		}
fp@2585: 	}
fp@2585: 
fp@2585: 	e1000e_down(adapter);
fp@2585: 
fp@2585: 	/* We can't just free everything and then setup again, because the
fp@2585: 	 * ISRs in MSI-X mode get passed pointers to the Tx and Rx ring
fp@2585: 	 * structs.  First, attempt to allocate new resources...
fp@2585: 	 */
fp@2585: 	if (set_tx) {
fp@2585: 		memcpy(temp_tx, adapter->tx_ring, size);
fp@2585: 		temp_tx->count = new_tx_count;
fp@2585: 		err = e1000e_setup_tx_resources(temp_tx);
fp@2585: 		if (err)
fp@2585: 			goto err_setup;
fp@2585: 	}
fp@2585: 	if (set_rx) {
fp@2585: 		memcpy(temp_rx, adapter->rx_ring, size);
fp@2585: 		temp_rx->count = new_rx_count;
fp@2585: 		err = e1000e_setup_rx_resources(temp_rx);
fp@2585: 		if (err)
fp@2585: 			goto err_setup_rx;
fp@2585: 	}
fp@2585: 
fp@2585: 	/* ...then free the old resources and copy back any new ring data */
fp@2585: 	if (set_tx) {
fp@2585: 		e1000e_free_tx_resources(adapter->tx_ring);
fp@2585: 		memcpy(adapter->tx_ring, temp_tx, size);
fp@2585: 		adapter->tx_ring_count = new_tx_count;
fp@2585: 	}
fp@2585: 	if (set_rx) {
fp@2585: 		e1000e_free_rx_resources(adapter->rx_ring);
fp@2585: 		memcpy(adapter->rx_ring, temp_rx, size);
fp@2585: 		adapter->rx_ring_count = new_rx_count;
fp@2585: 	}
fp@2585: 
fp@2585: err_setup_rx:
fp@2585: 	if (err && set_tx)
fp@2585: 		e1000e_free_tx_resources(temp_tx);
fp@2585: err_setup:
fp@2585: 	e1000e_up(adapter);
fp@2585: free_temp:
fp@2585: 	vfree(temp_tx);
fp@2585: 	vfree(temp_rx);
fp@2585: clear_reset:
fp@2585: 	clear_bit(__E1000_RESETTING, &adapter->state);
fp@2585: 	return err;
fp@2585: }
fp@2585: 
fp@2585: static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
fp@2585: 			     int reg, int offset, u32 mask, u32 write)
fp@2585: {
fp@2585: 	u32 pat, val;
fp@2585: 	static const u32 test[] = {
fp@2585: 		0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF
fp@2585: 	};
fp@2585: 	for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
fp@2585: 		E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
fp@2585: 				      (test[pat] & write));
fp@2585: 		val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
fp@2585: 		if (val != (test[pat] & write & mask)) {
fp@2585: 			e_err("pattern test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
fp@2585: 			      reg + (offset << 2), val,
fp@2585: 			      (test[pat] & write & mask));
fp@2585: 			*data = reg;
fp@2585: 			return 1;
fp@2585: 		}
fp@2585: 	}
fp@2585: 	return 0;
fp@2585: }
fp@2585: 
fp@2585: static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
fp@2585: 			      int reg, u32 mask, u32 write)
fp@2585: {
fp@2585: 	u32 val;
fp@2585: 	__ew32(&adapter->hw, reg, write & mask);
fp@2585: 	val = __er32(&adapter->hw, reg);
fp@2585: 	if ((write & mask) != (val & mask)) {
fp@2585: 		e_err("set/check test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
fp@2585: 		      reg, (val & mask), (write & mask));
fp@2585: 		*data = reg;
fp@2585: 		return 1;
fp@2585: 	}
fp@2585: 	return 0;
fp@2585: }
fp@2585: 
fp@2585: #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write)                       \
fp@2585: 	do {                                                                   \
fp@2585: 		if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
fp@2585: 			return 1;                                              \
fp@2585: 	} while (0)
fp@2585: #define REG_PATTERN_TEST(reg, mask, write)                                     \
fp@2585: 	REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
fp@2585: 
fp@2585: #define REG_SET_AND_CHECK(reg, mask, write)                                    \
fp@2585: 	do {                                                                   \
fp@2585: 		if (reg_set_and_check(adapter, data, reg, mask, write))        \
fp@2585: 			return 1;                                              \
fp@2585: 	} while (0)
fp@2585: 
fp@2585: static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
fp@2585: {
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 	struct e1000_mac_info *mac = &adapter->hw.mac;
fp@2585: 	u32 value;
fp@2585: 	u32 before;
fp@2585: 	u32 after;
fp@2585: 	u32 i;
fp@2585: 	u32 toggle;
fp@2585: 	u32 mask;
fp@2585: 	u32 wlock_mac = 0;
fp@2585: 
fp@2585: 	/* The status register is Read Only, so a write should fail.
fp@2585: 	 * Some bits that get toggled are ignored.  There are several bits
fp@2585: 	 * on newer hardware that are r/w.
fp@2585: 	 */
fp@2585: 	switch (mac->type) {
fp@2585: 	case e1000_82571:
fp@2585: 	case e1000_82572:
fp@2585: 	case e1000_80003es2lan:
fp@2585: 		toggle = 0x7FFFF3FF;
fp@2585: 		break;
fp@2585: 	default:
fp@2585: 		toggle = 0x7FFFF033;
fp@2585: 		break;
fp@2585: 	}
fp@2585: 
fp@2585: 	before = er32(STATUS);
fp@2585: 	value = (er32(STATUS) & toggle);
fp@2585: 	ew32(STATUS, toggle);
fp@2585: 	after = er32(STATUS) & toggle;
fp@2585: 	if (value != after) {
fp@2585: 		e_err("failed STATUS register test got: 0x%08X expected: 0x%08X\n",
fp@2585: 		      after, value);
fp@2585: 		*data = 1;
fp@2585: 		return 1;
fp@2585: 	}
fp@2585: 	/* restore previous status */
fp@2585: 	ew32(STATUS, before);
fp@2585: 
fp@2585: 	if (!(adapter->flags & FLAG_IS_ICH)) {
fp@2585: 		REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
fp@2585: 		REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
fp@2585: 		REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
fp@2585: 		REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
fp@2585: 	}
fp@2585: 
fp@2585: 	REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
fp@2585: 	REG_PATTERN_TEST(E1000_RDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
fp@2585: 	REG_PATTERN_TEST(E1000_RDLEN(0), 0x000FFF80, 0x000FFFFF);
fp@2585: 	REG_PATTERN_TEST(E1000_RDH(0), 0x0000FFFF, 0x0000FFFF);
fp@2585: 	REG_PATTERN_TEST(E1000_RDT(0), 0x0000FFFF, 0x0000FFFF);
fp@2585: 	REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
fp@2585: 	REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
fp@2585: 	REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
fp@2585: 	REG_PATTERN_TEST(E1000_TDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
fp@2585: 	REG_PATTERN_TEST(E1000_TDLEN(0), 0x000FFF80, 0x000FFFFF);
fp@2585: 
fp@2585: 	REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
fp@2585: 
fp@2585: 	before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
fp@2585: 	REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
fp@2585: 	REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
fp@2585: 
fp@2585: 	REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
fp@2585: 	REG_PATTERN_TEST(E1000_RDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
fp@2585: 	if (!(adapter->flags & FLAG_IS_ICH))
fp@2585: 		REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
fp@2585: 	REG_PATTERN_TEST(E1000_TDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
fp@2585: 	REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
fp@2585: 	mask = 0x8003FFFF;
fp@2585: 	switch (mac->type) {
fp@2585: 	case e1000_ich10lan:
fp@2585: 	case e1000_pchlan:
fp@2585: 	case e1000_pch2lan:
fp@2585: 	case e1000_pch_lpt:
fp@2585: 		mask |= (1 << 18);
fp@2585: 		break;
fp@2585: 	default:
fp@2585: 		break;
fp@2585: 	}
fp@2585: 
fp@2585: 	if (mac->type == e1000_pch_lpt)
fp@2585: 		wlock_mac = (er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK) >>
fp@2585: 		    E1000_FWSM_WLOCK_MAC_SHIFT;
fp@2585: 
fp@2585: 	for (i = 0; i < mac->rar_entry_count; i++) {
fp@2585: 		if (mac->type == e1000_pch_lpt) {
fp@2585: 			/* Cannot test write-protected SHRAL[n] registers */
fp@2585: 			if ((wlock_mac == 1) || (wlock_mac && (i > wlock_mac)))
fp@2585: 				continue;
fp@2585: 
fp@2585: 			/* SHRAH[9] different than the others */
fp@2585: 			if (i == 10)
fp@2585: 				mask |= (1 << 30);
fp@2585: 			else
fp@2585: 				mask &= ~(1 << 30);
fp@2585: 		}
fp@2585: 
fp@2585: 		REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1), mask,
fp@2585: 				       0xFFFFFFFF);
fp@2585: 	}
fp@2585: 
fp@2585: 	for (i = 0; i < mac->mta_reg_count; i++)
fp@2585: 		REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
fp@2585: 
fp@2585: 	*data = 0;
fp@2585: 
fp@2585: 	return 0;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
fp@2585: {
fp@2585: 	u16 temp;
fp@2585: 	u16 checksum = 0;
fp@2585: 	u16 i;
fp@2585: 
fp@2585: 	*data = 0;
fp@2585: 	/* Read and add up the contents of the EEPROM */
fp@2585: 	for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
fp@2585: 		if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
fp@2585: 			*data = 1;
fp@2585: 			return *data;
fp@2585: 		}
fp@2585: 		checksum += temp;
fp@2585: 	}
fp@2585: 
fp@2585: 	/* If Checksum is not Correct return error else test passed */
fp@2585: 	if ((checksum != (u16)NVM_SUM) && !(*data))
fp@2585: 		*data = 2;
fp@2585: 
fp@2585: 	return *data;
fp@2585: }
fp@2585: 
fp@2585: static irqreturn_t e1000_test_intr(int __always_unused irq, void *data)
fp@2585: {
fp@2585: 	struct net_device *netdev = (struct net_device *)data;
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 
fp@2585: 	adapter->test_icr |= er32(ICR);
fp@2585: 
fp@2585: 	return IRQ_HANDLED;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
fp@2585: {
fp@2585: 	struct net_device *netdev = adapter->netdev;
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 	u32 mask;
fp@2585: 	u32 shared_int = 1;
fp@2585: 	u32 irq = adapter->pdev->irq;
fp@2585: 	int i;
fp@2585: 	int ret_val = 0;
fp@2585: 	int int_mode = E1000E_INT_MODE_LEGACY;
fp@2585: 
fp@2585: 	*data = 0;
fp@2585: 
fp@2585: 	/* NOTE: we don't test MSI/MSI-X interrupts here, yet */
fp@2585: 	if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
fp@2585: 		int_mode = adapter->int_mode;
fp@2585: 		e1000e_reset_interrupt_capability(adapter);
fp@2585: 		adapter->int_mode = E1000E_INT_MODE_LEGACY;
fp@2585: 		e1000e_set_interrupt_capability(adapter);
fp@2585: 	}
fp@2585: 	/* Hook up test interrupt handler just for this test */
fp@2585: 	if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
fp@2585: 			 netdev)) {
fp@2585: 		shared_int = 0;
fp@2585: 	} else if (request_irq(irq, e1000_test_intr, IRQF_SHARED, netdev->name,
fp@2585: 			       netdev)) {
fp@2585: 		*data = 1;
fp@2585: 		ret_val = -1;
fp@2585: 		goto out;
fp@2585: 	}
fp@2585: 	e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
fp@2585: 
fp@2585: 	/* Disable all the interrupts */
fp@2585: 	ew32(IMC, 0xFFFFFFFF);
fp@2585: 	e1e_flush();
fp@2585: 	usleep_range(10000, 20000);
fp@2585: 
fp@2585: 	/* Test each interrupt */
fp@2585: 	for (i = 0; i < 10; i++) {
fp@2585: 		/* Interrupt to test */
fp@2585: 		mask = 1 << i;
fp@2585: 
fp@2585: 		if (adapter->flags & FLAG_IS_ICH) {
fp@2585: 			switch (mask) {
fp@2585: 			case E1000_ICR_RXSEQ:
fp@2585: 				continue;
fp@2585: 			case 0x00000100:
fp@2585: 				if (adapter->hw.mac.type == e1000_ich8lan ||
fp@2585: 				    adapter->hw.mac.type == e1000_ich9lan)
fp@2585: 					continue;
fp@2585: 				break;
fp@2585: 			default:
fp@2585: 				break;
fp@2585: 			}
fp@2585: 		}
fp@2585: 
fp@2585: 		if (!shared_int) {
fp@2585: 			/* Disable the interrupt to be reported in
fp@2585: 			 * the cause register and then force the same
fp@2585: 			 * interrupt and see if one gets posted.  If
fp@2585: 			 * an interrupt was posted to the bus, the
fp@2585: 			 * test failed.
fp@2585: 			 */
fp@2585: 			adapter->test_icr = 0;
fp@2585: 			ew32(IMC, mask);
fp@2585: 			ew32(ICS, mask);
fp@2585: 			e1e_flush();
fp@2585: 			usleep_range(10000, 20000);
fp@2585: 
fp@2585: 			if (adapter->test_icr & mask) {
fp@2585: 				*data = 3;
fp@2585: 				break;
fp@2585: 			}
fp@2585: 		}
fp@2585: 
fp@2585: 		/* Enable the interrupt to be reported in
fp@2585: 		 * the cause register and then force the same
fp@2585: 		 * interrupt and see if one gets posted.  If
fp@2585: 		 * an interrupt was not posted to the bus, the
fp@2585: 		 * test failed.
fp@2585: 		 */
fp@2585: 		adapter->test_icr = 0;
fp@2585: 		ew32(IMS, mask);
fp@2585: 		ew32(ICS, mask);
fp@2585: 		e1e_flush();
fp@2585: 		usleep_range(10000, 20000);
fp@2585: 
fp@2585: 		if (!(adapter->test_icr & mask)) {
fp@2585: 			*data = 4;
fp@2585: 			break;
fp@2585: 		}
fp@2585: 
fp@2585: 		if (!shared_int) {
fp@2585: 			/* Disable the other interrupts to be reported in
fp@2585: 			 * the cause register and then force the other
fp@2585: 			 * interrupts and see if any get posted.  If
fp@2585: 			 * an interrupt was posted to the bus, the
fp@2585: 			 * test failed.
fp@2585: 			 */
fp@2585: 			adapter->test_icr = 0;
fp@2585: 			ew32(IMC, ~mask & 0x00007FFF);
fp@2585: 			ew32(ICS, ~mask & 0x00007FFF);
fp@2585: 			e1e_flush();
fp@2585: 			usleep_range(10000, 20000);
fp@2585: 
fp@2585: 			if (adapter->test_icr) {
fp@2585: 				*data = 5;
fp@2585: 				break;
fp@2585: 			}
fp@2585: 		}
fp@2585: 	}
fp@2585: 
fp@2585: 	/* Disable all the interrupts */
fp@2585: 	ew32(IMC, 0xFFFFFFFF);
fp@2585: 	e1e_flush();
fp@2585: 	usleep_range(10000, 20000);
fp@2585: 
fp@2585: 	/* Unhook test interrupt handler */
fp@2585: 	free_irq(irq, netdev);
fp@2585: 
fp@2585: out:
fp@2585: 	if (int_mode == E1000E_INT_MODE_MSIX) {
fp@2585: 		e1000e_reset_interrupt_capability(adapter);
fp@2585: 		adapter->int_mode = int_mode;
fp@2585: 		e1000e_set_interrupt_capability(adapter);
fp@2585: 	}
fp@2585: 
fp@2585: 	return ret_val;
fp@2585: }
fp@2585: 
fp@2585: static void e1000_free_desc_rings(struct e1000_adapter *adapter)
fp@2585: {
fp@2585: 	struct e1000_ring *tx_ring = &adapter->test_tx_ring;
fp@2585: 	struct e1000_ring *rx_ring = &adapter->test_rx_ring;
fp@2585: 	struct pci_dev *pdev = adapter->pdev;
fp@2585: 	struct e1000_buffer *buffer_info;
fp@2585: 	int i;
fp@2585: 
fp@2585: 	if (tx_ring->desc && tx_ring->buffer_info) {
fp@2585: 		for (i = 0; i < tx_ring->count; i++) {
fp@2585: 			buffer_info = &tx_ring->buffer_info[i];
fp@2585: 
fp@2585: 			if (buffer_info->dma)
fp@2585: 				dma_unmap_single(&pdev->dev,
fp@2585: 						 buffer_info->dma,
fp@2585: 						 buffer_info->length,
fp@2585: 						 DMA_TO_DEVICE);
fp@2585: 			if (buffer_info->skb)
fp@2585: 				dev_kfree_skb(buffer_info->skb);
fp@2585: 		}
fp@2585: 	}
fp@2585: 
fp@2585: 	if (rx_ring->desc && rx_ring->buffer_info) {
fp@2585: 		for (i = 0; i < rx_ring->count; i++) {
fp@2585: 			buffer_info = &rx_ring->buffer_info[i];
fp@2585: 
fp@2585: 			if (buffer_info->dma)
fp@2585: 				dma_unmap_single(&pdev->dev,
fp@2585: 						 buffer_info->dma,
fp@2585: 						 2048, DMA_FROM_DEVICE);
fp@2585: 			if (buffer_info->skb)
fp@2585: 				dev_kfree_skb(buffer_info->skb);
fp@2585: 		}
fp@2585: 	}
fp@2585: 
fp@2585: 	if (tx_ring->desc) {
fp@2585: 		dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
fp@2585: 				  tx_ring->dma);
fp@2585: 		tx_ring->desc = NULL;
fp@2585: 	}
fp@2585: 	if (rx_ring->desc) {
fp@2585: 		dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
fp@2585: 				  rx_ring->dma);
fp@2585: 		rx_ring->desc = NULL;
fp@2585: 	}
fp@2585: 
fp@2585: 	kfree(tx_ring->buffer_info);
fp@2585: 	tx_ring->buffer_info = NULL;
fp@2585: 	kfree(rx_ring->buffer_info);
fp@2585: 	rx_ring->buffer_info = NULL;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
fp@2585: {
fp@2585: 	struct e1000_ring *tx_ring = &adapter->test_tx_ring;
fp@2585: 	struct e1000_ring *rx_ring = &adapter->test_rx_ring;
fp@2585: 	struct pci_dev *pdev = adapter->pdev;
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 	u32 rctl;
fp@2585: 	int i;
fp@2585: 	int ret_val;
fp@2585: 
fp@2585: 	/* Setup Tx descriptor ring and Tx buffers */
fp@2585: 
fp@2585: 	if (!tx_ring->count)
fp@2585: 		tx_ring->count = E1000_DEFAULT_TXD;
fp@2585: 
fp@2585: 	tx_ring->buffer_info = kcalloc(tx_ring->count,
fp@2585: 				       sizeof(struct e1000_buffer), GFP_KERNEL);
fp@2585: 	if (!tx_ring->buffer_info) {
fp@2585: 		ret_val = 1;
fp@2585: 		goto err_nomem;
fp@2585: 	}
fp@2585: 
fp@2585: 	tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
fp@2585: 	tx_ring->size = ALIGN(tx_ring->size, 4096);
fp@2585: 	tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
fp@2585: 					   &tx_ring->dma, GFP_KERNEL);
fp@2585: 	if (!tx_ring->desc) {
fp@2585: 		ret_val = 2;
fp@2585: 		goto err_nomem;
fp@2585: 	}
fp@2585: 	tx_ring->next_to_use = 0;
fp@2585: 	tx_ring->next_to_clean = 0;
fp@2585: 
fp@2585: 	ew32(TDBAL(0), ((u64)tx_ring->dma & 0x00000000FFFFFFFF));
fp@2585: 	ew32(TDBAH(0), ((u64)tx_ring->dma >> 32));
fp@2585: 	ew32(TDLEN(0), tx_ring->count * sizeof(struct e1000_tx_desc));
fp@2585: 	ew32(TDH(0), 0);
fp@2585: 	ew32(TDT(0), 0);
fp@2585: 	ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
fp@2585: 	     E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
fp@2585: 	     E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
fp@2585: 
fp@2585: 	for (i = 0; i < tx_ring->count; i++) {
fp@2585: 		struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
fp@2585: 		struct sk_buff *skb;
fp@2585: 		unsigned int skb_size = 1024;
fp@2585: 
fp@2585: 		skb = alloc_skb(skb_size, GFP_KERNEL);
fp@2585: 		if (!skb) {
fp@2585: 			ret_val = 3;
fp@2585: 			goto err_nomem;
fp@2585: 		}
fp@2585: 		skb_put(skb, skb_size);
fp@2585: 		tx_ring->buffer_info[i].skb = skb;
fp@2585: 		tx_ring->buffer_info[i].length = skb->len;
fp@2585: 		tx_ring->buffer_info[i].dma =
fp@2585: 		    dma_map_single(&pdev->dev, skb->data, skb->len,
fp@2585: 				   DMA_TO_DEVICE);
fp@2585: 		if (dma_mapping_error(&pdev->dev,
fp@2585: 				      tx_ring->buffer_info[i].dma)) {
fp@2585: 			ret_val = 4;
fp@2585: 			goto err_nomem;
fp@2585: 		}
fp@2585: 		tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
fp@2585: 		tx_desc->lower.data = cpu_to_le32(skb->len);
fp@2585: 		tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
fp@2585: 						   E1000_TXD_CMD_IFCS |
fp@2585: 						   E1000_TXD_CMD_RS);
fp@2585: 		tx_desc->upper.data = 0;
fp@2585: 	}
fp@2585: 
fp@2585: 	/* Setup Rx descriptor ring and Rx buffers */
fp@2585: 
fp@2585: 	if (!rx_ring->count)
fp@2585: 		rx_ring->count = E1000_DEFAULT_RXD;
fp@2585: 
fp@2585: 	rx_ring->buffer_info = kcalloc(rx_ring->count,
fp@2585: 				       sizeof(struct e1000_buffer), GFP_KERNEL);
fp@2585: 	if (!rx_ring->buffer_info) {
fp@2585: 		ret_val = 5;
fp@2585: 		goto err_nomem;
fp@2585: 	}
fp@2585: 
fp@2585: 	rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
fp@2585: 	rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
fp@2585: 					   &rx_ring->dma, GFP_KERNEL);
fp@2585: 	if (!rx_ring->desc) {
fp@2585: 		ret_val = 6;
fp@2585: 		goto err_nomem;
fp@2585: 	}
fp@2585: 	rx_ring->next_to_use = 0;
fp@2585: 	rx_ring->next_to_clean = 0;
fp@2585: 
fp@2585: 	rctl = er32(RCTL);
fp@2585: 	if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
fp@2585: 		ew32(RCTL, rctl & ~E1000_RCTL_EN);
fp@2585: 	ew32(RDBAL(0), ((u64)rx_ring->dma & 0xFFFFFFFF));
fp@2585: 	ew32(RDBAH(0), ((u64)rx_ring->dma >> 32));
fp@2585: 	ew32(RDLEN(0), rx_ring->size);
fp@2585: 	ew32(RDH(0), 0);
fp@2585: 	ew32(RDT(0), 0);
fp@2585: 	rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
fp@2585: 	    E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
fp@2585: 	    E1000_RCTL_SBP | E1000_RCTL_SECRC |
fp@2585: 	    E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
fp@2585: 	    (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
fp@2585: 	ew32(RCTL, rctl);
fp@2585: 
fp@2585: 	for (i = 0; i < rx_ring->count; i++) {
fp@2585: 		union e1000_rx_desc_extended *rx_desc;
fp@2585: 		struct sk_buff *skb;
fp@2585: 
fp@2585: 		skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
fp@2585: 		if (!skb) {
fp@2585: 			ret_val = 7;
fp@2585: 			goto err_nomem;
fp@2585: 		}
fp@2585: 		skb_reserve(skb, NET_IP_ALIGN);
fp@2585: 		rx_ring->buffer_info[i].skb = skb;
fp@2585: 		rx_ring->buffer_info[i].dma =
fp@2585: 		    dma_map_single(&pdev->dev, skb->data, 2048,
fp@2585: 				   DMA_FROM_DEVICE);
fp@2585: 		if (dma_mapping_error(&pdev->dev,
fp@2585: 				      rx_ring->buffer_info[i].dma)) {
fp@2585: 			ret_val = 8;
fp@2585: 			goto err_nomem;
fp@2585: 		}
fp@2585: 		rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
fp@2585: 		rx_desc->read.buffer_addr =
fp@2585: 		    cpu_to_le64(rx_ring->buffer_info[i].dma);
fp@2585: 		memset(skb->data, 0x00, skb->len);
fp@2585: 	}
fp@2585: 
fp@2585: 	return 0;
fp@2585: 
fp@2585: err_nomem:
fp@2585: 	e1000_free_desc_rings(adapter);
fp@2585: 	return ret_val;
fp@2585: }
fp@2585: 
fp@2585: static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
fp@2585: {
fp@2585: 	/* Write out to PHY registers 29 and 30 to disable the Receiver. */
fp@2585: 	e1e_wphy(&adapter->hw, 29, 0x001F);
fp@2585: 	e1e_wphy(&adapter->hw, 30, 0x8FFC);
fp@2585: 	e1e_wphy(&adapter->hw, 29, 0x001A);
fp@2585: 	e1e_wphy(&adapter->hw, 30, 0x8FF0);
fp@2585: }
fp@2585: 
fp@2585: static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
fp@2585: {
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 	u32 ctrl_reg = 0;
fp@2585: 	u16 phy_reg = 0;
fp@2585: 	s32 ret_val = 0;
fp@2585: 
fp@2585: 	hw->mac.autoneg = 0;
fp@2585: 
fp@2585: 	if (hw->phy.type == e1000_phy_ife) {
fp@2585: 		/* force 100, set loopback */
fp@2585: 		e1e_wphy(hw, MII_BMCR, 0x6100);
fp@2585: 
fp@2585: 		/* Now set up the MAC to the same speed/duplex as the PHY. */
fp@2585: 		ctrl_reg = er32(CTRL);
fp@2585: 		ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
fp@2585: 		ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
fp@2585: 			     E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
fp@2585: 			     E1000_CTRL_SPD_100 |/* Force Speed to 100 */
fp@2585: 			     E1000_CTRL_FD);	 /* Force Duplex to FULL */
fp@2585: 
fp@2585: 		ew32(CTRL, ctrl_reg);
fp@2585: 		e1e_flush();
fp@2585: 		usleep_range(500, 1000);
fp@2585: 
fp@2585: 		return 0;
fp@2585: 	}
fp@2585: 
fp@2585: 	/* Specific PHY configuration for loopback */
fp@2585: 	switch (hw->phy.type) {
fp@2585: 	case e1000_phy_m88:
fp@2585: 		/* Auto-MDI/MDIX Off */
fp@2585: 		e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
fp@2585: 		/* reset to update Auto-MDI/MDIX */
fp@2585: 		e1e_wphy(hw, MII_BMCR, 0x9140);
fp@2585: 		/* autoneg off */
fp@2585: 		e1e_wphy(hw, MII_BMCR, 0x8140);
fp@2585: 		break;
fp@2585: 	case e1000_phy_gg82563:
fp@2585: 		e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
fp@2585: 		break;
fp@2585: 	case e1000_phy_bm:
fp@2585: 		/* Set Default MAC Interface speed to 1GB */
fp@2585: 		e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
fp@2585: 		phy_reg &= ~0x0007;
fp@2585: 		phy_reg |= 0x006;
fp@2585: 		e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
fp@2585: 		/* Assert SW reset for above settings to take effect */
fp@2585: 		hw->phy.ops.commit(hw);
fp@2585: 		usleep_range(1000, 2000);
fp@2585: 		/* Force Full Duplex */
fp@2585: 		e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
fp@2585: 		e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
fp@2585: 		/* Set Link Up (in force link) */
fp@2585: 		e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
fp@2585: 		e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
fp@2585: 		/* Force Link */
fp@2585: 		e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
fp@2585: 		e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
fp@2585: 		/* Set Early Link Enable */
fp@2585: 		e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
fp@2585: 		e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
fp@2585: 		break;
fp@2585: 	case e1000_phy_82577:
fp@2585: 	case e1000_phy_82578:
fp@2585: 		/* Workaround: K1 must be disabled for stable 1Gbps operation */
fp@2585: 		ret_val = hw->phy.ops.acquire(hw);
fp@2585: 		if (ret_val) {
fp@2585: 			e_err("Cannot setup 1Gbps loopback.\n");
fp@2585: 			return ret_val;
fp@2585: 		}
fp@2585: 		e1000_configure_k1_ich8lan(hw, false);
fp@2585: 		hw->phy.ops.release(hw);
fp@2585: 		break;
fp@2585: 	case e1000_phy_82579:
fp@2585: 		/* Disable PHY energy detect power down */
fp@2585: 		e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
fp@2585: 		e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
fp@2585: 		/* Disable full chip energy detect */
fp@2585: 		e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
fp@2585: 		e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
fp@2585: 		/* Enable loopback on the PHY */
fp@2585: 		e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
fp@2585: 		break;
fp@2585: 	default:
fp@2585: 		break;
fp@2585: 	}
fp@2585: 
fp@2585: 	/* force 1000, set loopback */
fp@2585: 	e1e_wphy(hw, MII_BMCR, 0x4140);
fp@2585: 	msleep(250);
fp@2585: 
fp@2585: 	/* Now set up the MAC to the same speed/duplex as the PHY. */
fp@2585: 	ctrl_reg = er32(CTRL);
fp@2585: 	ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
fp@2585: 	ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
fp@2585: 		     E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
fp@2585: 		     E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
fp@2585: 		     E1000_CTRL_FD);	 /* Force Duplex to FULL */
fp@2585: 
fp@2585: 	if (adapter->flags & FLAG_IS_ICH)
fp@2585: 		ctrl_reg |= E1000_CTRL_SLU;	/* Set Link Up */
fp@2585: 
fp@2585: 	if (hw->phy.media_type == e1000_media_type_copper &&
fp@2585: 	    hw->phy.type == e1000_phy_m88) {
fp@2585: 		ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
fp@2585: 	} else {
fp@2585: 		/* Set the ILOS bit on the fiber Nic if half duplex link is
fp@2585: 		 * detected.
fp@2585: 		 */
fp@2585: 		if ((er32(STATUS) & E1000_STATUS_FD) == 0)
fp@2585: 			ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
fp@2585: 	}
fp@2585: 
fp@2585: 	ew32(CTRL, ctrl_reg);
fp@2585: 
fp@2585: 	/* Disable the receiver on the PHY so when a cable is plugged in, the
fp@2585: 	 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
fp@2585: 	 */
fp@2585: 	if (hw->phy.type == e1000_phy_m88)
fp@2585: 		e1000_phy_disable_receiver(adapter);
fp@2585: 
fp@2585: 	usleep_range(500, 1000);
fp@2585: 
fp@2585: 	return 0;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
fp@2585: {
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 	u32 ctrl = er32(CTRL);
fp@2585: 	int link;
fp@2585: 
fp@2585: 	/* special requirements for 82571/82572 fiber adapters */
fp@2585: 
fp@2585: 	/* jump through hoops to make sure link is up because serdes
fp@2585: 	 * link is hardwired up
fp@2585: 	 */
fp@2585: 	ctrl |= E1000_CTRL_SLU;
fp@2585: 	ew32(CTRL, ctrl);
fp@2585: 
fp@2585: 	/* disable autoneg */
fp@2585: 	ctrl = er32(TXCW);
fp@2585: 	ctrl &= ~(1 << 31);
fp@2585: 	ew32(TXCW, ctrl);
fp@2585: 
fp@2585: 	link = (er32(STATUS) & E1000_STATUS_LU);
fp@2585: 
fp@2585: 	if (!link) {
fp@2585: 		/* set invert loss of signal */
fp@2585: 		ctrl = er32(CTRL);
fp@2585: 		ctrl |= E1000_CTRL_ILOS;
fp@2585: 		ew32(CTRL, ctrl);
fp@2585: 	}
fp@2585: 
fp@2585: 	/* special write to serdes control register to enable SerDes analog
fp@2585: 	 * loopback
fp@2585: 	 */
fp@2585: 	ew32(SCTL, E1000_SCTL_ENABLE_SERDES_LOOPBACK);
fp@2585: 	e1e_flush();
fp@2585: 	usleep_range(10000, 20000);
fp@2585: 
fp@2585: 	return 0;
fp@2585: }
fp@2585: 
fp@2585: /* only call this for fiber/serdes connections to es2lan */
fp@2585: static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
fp@2585: {
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 	u32 ctrlext = er32(CTRL_EXT);
fp@2585: 	u32 ctrl = er32(CTRL);
fp@2585: 
fp@2585: 	/* save CTRL_EXT to restore later, reuse an empty variable (unused
fp@2585: 	 * on mac_type 80003es2lan)
fp@2585: 	 */
fp@2585: 	adapter->tx_fifo_head = ctrlext;
fp@2585: 
fp@2585: 	/* clear the serdes mode bits, putting the device into mac loopback */
fp@2585: 	ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
fp@2585: 	ew32(CTRL_EXT, ctrlext);
fp@2585: 
fp@2585: 	/* force speed to 1000/FD, link up */
fp@2585: 	ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
fp@2585: 	ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
fp@2585: 		 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
fp@2585: 	ew32(CTRL, ctrl);
fp@2585: 
fp@2585: 	/* set mac loopback */
fp@2585: 	ctrl = er32(RCTL);
fp@2585: 	ctrl |= E1000_RCTL_LBM_MAC;
fp@2585: 	ew32(RCTL, ctrl);
fp@2585: 
fp@2585: 	/* set testing mode parameters (no need to reset later) */
fp@2585: #define KMRNCTRLSTA_OPMODE (0x1F << 16)
fp@2585: #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
fp@2585: 	ew32(KMRNCTRLSTA,
fp@2585: 	     (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
fp@2585: 
fp@2585: 	return 0;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
fp@2585: {
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 	u32 rctl;
fp@2585: 
fp@2585: 	if (hw->phy.media_type == e1000_media_type_fiber ||
fp@2585: 	    hw->phy.media_type == e1000_media_type_internal_serdes) {
fp@2585: 		switch (hw->mac.type) {
fp@2585: 		case e1000_80003es2lan:
fp@2585: 			return e1000_set_es2lan_mac_loopback(adapter);
fp@2585: 			break;
fp@2585: 		case e1000_82571:
fp@2585: 		case e1000_82572:
fp@2585: 			return e1000_set_82571_fiber_loopback(adapter);
fp@2585: 			break;
fp@2585: 		default:
fp@2585: 			rctl = er32(RCTL);
fp@2585: 			rctl |= E1000_RCTL_LBM_TCVR;
fp@2585: 			ew32(RCTL, rctl);
fp@2585: 			return 0;
fp@2585: 		}
fp@2585: 	} else if (hw->phy.media_type == e1000_media_type_copper) {
fp@2585: 		return e1000_integrated_phy_loopback(adapter);
fp@2585: 	}
fp@2585: 
fp@2585: 	return 7;
fp@2585: }
fp@2585: 
fp@2585: static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
fp@2585: {
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 	u32 rctl;
fp@2585: 	u16 phy_reg;
fp@2585: 
fp@2585: 	rctl = er32(RCTL);
fp@2585: 	rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
fp@2585: 	ew32(RCTL, rctl);
fp@2585: 
fp@2585: 	switch (hw->mac.type) {
fp@2585: 	case e1000_80003es2lan:
fp@2585: 		if (hw->phy.media_type == e1000_media_type_fiber ||
fp@2585: 		    hw->phy.media_type == e1000_media_type_internal_serdes) {
fp@2585: 			/* restore CTRL_EXT, stealing space from tx_fifo_head */
fp@2585: 			ew32(CTRL_EXT, adapter->tx_fifo_head);
fp@2585: 			adapter->tx_fifo_head = 0;
fp@2585: 		}
fp@2585: 		/* fall through */
fp@2585: 	case e1000_82571:
fp@2585: 	case e1000_82572:
fp@2585: 		if (hw->phy.media_type == e1000_media_type_fiber ||
fp@2585: 		    hw->phy.media_type == e1000_media_type_internal_serdes) {
fp@2585: 			ew32(SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
fp@2585: 			e1e_flush();
fp@2585: 			usleep_range(10000, 20000);
fp@2585: 			break;
fp@2585: 		}
fp@2585: 		/* Fall Through */
fp@2585: 	default:
fp@2585: 		hw->mac.autoneg = 1;
fp@2585: 		if (hw->phy.type == e1000_phy_gg82563)
fp@2585: 			e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
fp@2585: 		e1e_rphy(hw, MII_BMCR, &phy_reg);
fp@2585: 		if (phy_reg & BMCR_LOOPBACK) {
fp@2585: 			phy_reg &= ~BMCR_LOOPBACK;
fp@2585: 			e1e_wphy(hw, MII_BMCR, phy_reg);
fp@2585: 			if (hw->phy.ops.commit)
fp@2585: 				hw->phy.ops.commit(hw);
fp@2585: 		}
fp@2585: 		break;
fp@2585: 	}
fp@2585: }
fp@2585: 
fp@2585: static void e1000_create_lbtest_frame(struct sk_buff *skb,
fp@2585: 				      unsigned int frame_size)
fp@2585: {
fp@2585: 	memset(skb->data, 0xFF, frame_size);
fp@2585: 	frame_size &= ~1;
fp@2585: 	memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
fp@2585: 	memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
fp@2585: 	memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
fp@2585: }
fp@2585: 
fp@2585: static int e1000_check_lbtest_frame(struct sk_buff *skb,
fp@2585: 				    unsigned int frame_size)
fp@2585: {
fp@2585: 	frame_size &= ~1;
fp@2585: 	if (*(skb->data + 3) == 0xFF)
fp@2585: 		if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
fp@2585: 		    (*(skb->data + frame_size / 2 + 12) == 0xAF))
fp@2585: 			return 0;
fp@2585: 	return 13;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_run_loopback_test(struct e1000_adapter *adapter)
fp@2585: {
fp@2585: 	struct e1000_ring *tx_ring = &adapter->test_tx_ring;
fp@2585: 	struct e1000_ring *rx_ring = &adapter->test_rx_ring;
fp@2585: 	struct pci_dev *pdev = adapter->pdev;
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 	struct e1000_buffer *buffer_info;
fp@2585: 	int i, j, k, l;
fp@2585: 	int lc;
fp@2585: 	int good_cnt;
fp@2585: 	int ret_val = 0;
fp@2585: 	unsigned long time;
fp@2585: 
fp@2585: 	ew32(RDT(0), rx_ring->count - 1);
fp@2585: 
fp@2585: 	/* Calculate the loop count based on the largest descriptor ring
fp@2585: 	 * The idea is to wrap the largest ring a number of times using 64
fp@2585: 	 * send/receive pairs during each loop
fp@2585: 	 */
fp@2585: 
fp@2585: 	if (rx_ring->count <= tx_ring->count)
fp@2585: 		lc = ((tx_ring->count / 64) * 2) + 1;
fp@2585: 	else
fp@2585: 		lc = ((rx_ring->count / 64) * 2) + 1;
fp@2585: 
fp@2585: 	k = 0;
fp@2585: 	l = 0;
fp@2585: 	/* loop count loop */
fp@2585: 	for (j = 0; j <= lc; j++) {
fp@2585: 		/* send the packets */
fp@2585: 		for (i = 0; i < 64; i++) {
fp@2585: 			buffer_info = &tx_ring->buffer_info[k];
fp@2585: 
fp@2585: 			e1000_create_lbtest_frame(buffer_info->skb, 1024);
fp@2585: 			dma_sync_single_for_device(&pdev->dev,
fp@2585: 						   buffer_info->dma,
fp@2585: 						   buffer_info->length,
fp@2585: 						   DMA_TO_DEVICE);
fp@2585: 			k++;
fp@2585: 			if (k == tx_ring->count)
fp@2585: 				k = 0;
fp@2585: 		}
fp@2585: 		ew32(TDT(0), k);
fp@2585: 		e1e_flush();
fp@2585: 		msleep(200);
fp@2585: 		time = jiffies; /* set the start time for the receive */
fp@2585: 		good_cnt = 0;
fp@2585: 		/* receive the sent packets */
fp@2585: 		do {
fp@2585: 			buffer_info = &rx_ring->buffer_info[l];
fp@2585: 
fp@2585: 			dma_sync_single_for_cpu(&pdev->dev,
fp@2585: 						buffer_info->dma, 2048,
fp@2585: 						DMA_FROM_DEVICE);
fp@2585: 
fp@2585: 			ret_val = e1000_check_lbtest_frame(buffer_info->skb,
fp@2585: 							   1024);
fp@2585: 			if (!ret_val)
fp@2585: 				good_cnt++;
fp@2585: 			l++;
fp@2585: 			if (l == rx_ring->count)
fp@2585: 				l = 0;
fp@2585: 			/* time + 20 msecs (200 msecs on 2.4) is more than
fp@2585: 			 * enough time to complete the receives, if it's
fp@2585: 			 * exceeded, break and error off
fp@2585: 			 */
fp@2585: 		} while ((good_cnt < 64) && !time_after(jiffies, time + 20));
fp@2585: 		if (good_cnt != 64) {
fp@2585: 			ret_val = 13; /* ret_val is the same as mis-compare */
fp@2585: 			break;
fp@2585: 		}
fp@2585: 		if (jiffies >= (time + 20)) {
fp@2585: 			ret_val = 14; /* error code for time out error */
fp@2585: 			break;
fp@2585: 		}
fp@2585: 	}
fp@2585: 	return ret_val;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
fp@2585: {
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 
fp@2585: 	/* PHY loopback cannot be performed if SoL/IDER sessions are active */
fp@2585: 	if (hw->phy.ops.check_reset_block &&
fp@2585: 	    hw->phy.ops.check_reset_block(hw)) {
fp@2585: 		e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
fp@2585: 		*data = 0;
fp@2585: 		goto out;
fp@2585: 	}
fp@2585: 
fp@2585: 	*data = e1000_setup_desc_rings(adapter);
fp@2585: 	if (*data)
fp@2585: 		goto out;
fp@2585: 
fp@2585: 	*data = e1000_setup_loopback_test(adapter);
fp@2585: 	if (*data)
fp@2585: 		goto err_loopback;
fp@2585: 
fp@2585: 	*data = e1000_run_loopback_test(adapter);
fp@2585: 	e1000_loopback_cleanup(adapter);
fp@2585: 
fp@2585: err_loopback:
fp@2585: 	e1000_free_desc_rings(adapter);
fp@2585: out:
fp@2585: 	return *data;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
fp@2585: {
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 
fp@2585: 	*data = 0;
fp@2585: 	if (hw->phy.media_type == e1000_media_type_internal_serdes) {
fp@2585: 		int i = 0;
fp@2585: 		hw->mac.serdes_has_link = false;
fp@2585: 
fp@2585: 		/* On some blade server designs, link establishment
fp@2585: 		 * could take as long as 2-3 minutes
fp@2585: 		 */
fp@2585: 		do {
fp@2585: 			hw->mac.ops.check_for_link(hw);
fp@2585: 			if (hw->mac.serdes_has_link)
fp@2585: 				return *data;
fp@2585: 			msleep(20);
fp@2585: 		} while (i++ < 3750);
fp@2585: 
fp@2585: 		*data = 1;
fp@2585: 	} else {
fp@2585: 		hw->mac.ops.check_for_link(hw);
fp@2585: 		if (hw->mac.autoneg)
fp@2585: 			/* On some Phy/switch combinations, link establishment
fp@2585: 			 * can take a few seconds more than expected.
fp@2585: 			 */
fp@2585: 			msleep_interruptible(5000);
fp@2585: 
fp@2585: 		if (!(er32(STATUS) & E1000_STATUS_LU))
fp@2585: 			*data = 1;
fp@2585: 	}
fp@2585: 	return *data;
fp@2585: }
fp@2585: 
fp@2585: static int e1000e_get_sset_count(struct net_device __always_unused *netdev,
fp@2585: 				 int sset)
fp@2585: {
fp@2585: 	switch (sset) {
fp@2585: 	case ETH_SS_TEST:
fp@2585: 		return E1000_TEST_LEN;
fp@2585: 	case ETH_SS_STATS:
fp@2585: 		return E1000_STATS_LEN;
fp@2585: 	default:
fp@2585: 		return -EOPNOTSUPP;
fp@2585: 	}
fp@2585: }
fp@2585: 
fp@2585: static void e1000_diag_test(struct net_device *netdev,
fp@2585: 			    struct ethtool_test *eth_test, u64 *data)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	u16 autoneg_advertised;
fp@2585: 	u8 forced_speed_duplex;
fp@2585: 	u8 autoneg;
fp@2585: 	bool if_running = netif_running(netdev);
fp@2585: 
fp@2585: 	set_bit(__E1000_TESTING, &adapter->state);
fp@2585: 
fp@2585: 	if (!if_running) {
fp@2585: 		/* Get control of and reset hardware */
fp@2585: 		if (adapter->flags & FLAG_HAS_AMT)
fp@2585: 			e1000e_get_hw_control(adapter);
fp@2585: 
fp@2585: 		e1000e_power_up_phy(adapter);
fp@2585: 
fp@2585: 		adapter->hw.phy.autoneg_wait_to_complete = 1;
fp@2585: 		e1000e_reset(adapter);
fp@2585: 		adapter->hw.phy.autoneg_wait_to_complete = 0;
fp@2585: 	}
fp@2585: 
fp@2585: 	if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
fp@2585: 		/* Offline tests */
fp@2585: 
fp@2585: 		/* save speed, duplex, autoneg settings */
fp@2585: 		autoneg_advertised = adapter->hw.phy.autoneg_advertised;
fp@2585: 		forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
fp@2585: 		autoneg = adapter->hw.mac.autoneg;
fp@2585: 
fp@2585: 		e_info("offline testing starting\n");
fp@2585: 
fp@2585: 		if (if_running)
fp@2585: 			/* indicate we're in test mode */
fp@2585: 			dev_close(netdev);
fp@2585: 
fp@2585: 		if (e1000_reg_test(adapter, &data[0]))
fp@2585: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2585: 
fp@2585: 		e1000e_reset(adapter);
fp@2585: 		if (e1000_eeprom_test(adapter, &data[1]))
fp@2585: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2585: 
fp@2585: 		e1000e_reset(adapter);
fp@2585: 		if (e1000_intr_test(adapter, &data[2]))
fp@2585: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2585: 
fp@2585: 		e1000e_reset(adapter);
fp@2585: 		if (e1000_loopback_test(adapter, &data[3]))
fp@2585: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2585: 
fp@2585: 		/* force this routine to wait until autoneg complete/timeout */
fp@2585: 		adapter->hw.phy.autoneg_wait_to_complete = 1;
fp@2585: 		e1000e_reset(adapter);
fp@2585: 		adapter->hw.phy.autoneg_wait_to_complete = 0;
fp@2585: 
fp@2585: 		if (e1000_link_test(adapter, &data[4]))
fp@2585: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2585: 
fp@2585: 		/* restore speed, duplex, autoneg settings */
fp@2585: 		adapter->hw.phy.autoneg_advertised = autoneg_advertised;
fp@2585: 		adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
fp@2585: 		adapter->hw.mac.autoneg = autoneg;
fp@2585: 		e1000e_reset(adapter);
fp@2585: 
fp@2585: 		clear_bit(__E1000_TESTING, &adapter->state);
fp@2585: 		if (if_running)
fp@2585: 			dev_open(netdev);
fp@2585: 	} else {
fp@2585: 		/* Online tests */
fp@2585: 
fp@2585: 		e_info("online testing starting\n");
fp@2585: 
fp@2585: 		/* register, eeprom, intr and loopback tests not run online */
fp@2585: 		data[0] = 0;
fp@2585: 		data[1] = 0;
fp@2585: 		data[2] = 0;
fp@2585: 		data[3] = 0;
fp@2585: 
fp@2585: 		if (e1000_link_test(adapter, &data[4]))
fp@2585: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2585: 
fp@2585: 		clear_bit(__E1000_TESTING, &adapter->state);
fp@2585: 	}
fp@2585: 
fp@2585: 	if (!if_running) {
fp@2585: 		e1000e_reset(adapter);
fp@2585: 
fp@2585: 		if (adapter->flags & FLAG_HAS_AMT)
fp@2585: 			e1000e_release_hw_control(adapter);
fp@2585: 	}
fp@2585: 
fp@2585: 	msleep_interruptible(4 * 1000);
fp@2585: }
fp@2585: 
fp@2585: static void e1000_get_wol(struct net_device *netdev,
fp@2585: 			  struct ethtool_wolinfo *wol)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 
fp@2585: 	wol->supported = 0;
fp@2585: 	wol->wolopts = 0;
fp@2585: 
fp@2585: 	if (!(adapter->flags & FLAG_HAS_WOL) ||
fp@2585: 	    !device_can_wakeup(&adapter->pdev->dev))
fp@2585: 		return;
fp@2585: 
fp@2585: 	wol->supported = WAKE_UCAST | WAKE_MCAST |
fp@2585: 	    WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
fp@2585: 
fp@2585: 	/* apply any specific unsupported masks here */
fp@2585: 	if (adapter->flags & FLAG_NO_WAKE_UCAST) {
fp@2585: 		wol->supported &= ~WAKE_UCAST;
fp@2585: 
fp@2585: 		if (adapter->wol & E1000_WUFC_EX)
fp@2585: 			e_err("Interface does not support directed (unicast) frame wake-up packets\n");
fp@2585: 	}
fp@2585: 
fp@2585: 	if (adapter->wol & E1000_WUFC_EX)
fp@2585: 		wol->wolopts |= WAKE_UCAST;
fp@2585: 	if (adapter->wol & E1000_WUFC_MC)
fp@2585: 		wol->wolopts |= WAKE_MCAST;
fp@2585: 	if (adapter->wol & E1000_WUFC_BC)
fp@2585: 		wol->wolopts |= WAKE_BCAST;
fp@2585: 	if (adapter->wol & E1000_WUFC_MAG)
fp@2585: 		wol->wolopts |= WAKE_MAGIC;
fp@2585: 	if (adapter->wol & E1000_WUFC_LNKC)
fp@2585: 		wol->wolopts |= WAKE_PHY;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 
fp@2585: 	if (!(adapter->flags & FLAG_HAS_WOL) ||
fp@2585: 	    !device_can_wakeup(&adapter->pdev->dev) ||
fp@2585: 	    (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
fp@2585: 			      WAKE_MAGIC | WAKE_PHY)))
fp@2585: 		return -EOPNOTSUPP;
fp@2585: 
fp@2585: 	/* these settings will always override what we currently have */
fp@2585: 	adapter->wol = 0;
fp@2585: 
fp@2585: 	if (wol->wolopts & WAKE_UCAST)
fp@2585: 		adapter->wol |= E1000_WUFC_EX;
fp@2585: 	if (wol->wolopts & WAKE_MCAST)
fp@2585: 		adapter->wol |= E1000_WUFC_MC;
fp@2585: 	if (wol->wolopts & WAKE_BCAST)
fp@2585: 		adapter->wol |= E1000_WUFC_BC;
fp@2585: 	if (wol->wolopts & WAKE_MAGIC)
fp@2585: 		adapter->wol |= E1000_WUFC_MAG;
fp@2585: 	if (wol->wolopts & WAKE_PHY)
fp@2585: 		adapter->wol |= E1000_WUFC_LNKC;
fp@2585: 
fp@2585: 	device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
fp@2585: 
fp@2585: 	return 0;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_set_phys_id(struct net_device *netdev,
fp@2585: 			     enum ethtool_phys_id_state state)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 
fp@2585: 	switch (state) {
fp@2585: 	case ETHTOOL_ID_ACTIVE:
fp@2585: 		if (!hw->mac.ops.blink_led)
fp@2585: 			return 2;	/* cycle on/off twice per second */
fp@2585: 
fp@2585: 		hw->mac.ops.blink_led(hw);
fp@2585: 		break;
fp@2585: 
fp@2585: 	case ETHTOOL_ID_INACTIVE:
fp@2585: 		if (hw->phy.type == e1000_phy_ife)
fp@2585: 			e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
fp@2585: 		hw->mac.ops.led_off(hw);
fp@2585: 		hw->mac.ops.cleanup_led(hw);
fp@2585: 		break;
fp@2585: 
fp@2585: 	case ETHTOOL_ID_ON:
fp@2585: 		hw->mac.ops.led_on(hw);
fp@2585: 		break;
fp@2585: 
fp@2585: 	case ETHTOOL_ID_OFF:
fp@2585: 		hw->mac.ops.led_off(hw);
fp@2585: 		break;
fp@2585: 	}
fp@2585: 	return 0;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_get_coalesce(struct net_device *netdev,
fp@2585: 			      struct ethtool_coalesce *ec)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 
fp@2585: 	if (adapter->itr_setting <= 4)
fp@2585: 		ec->rx_coalesce_usecs = adapter->itr_setting;
fp@2585: 	else
fp@2585: 		ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
fp@2585: 
fp@2585: 	return 0;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_set_coalesce(struct net_device *netdev,
fp@2585: 			      struct ethtool_coalesce *ec)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 
fp@2585: 	if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
fp@2585: 	    ((ec->rx_coalesce_usecs > 4) &&
fp@2585: 	     (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
fp@2585: 	    (ec->rx_coalesce_usecs == 2))
fp@2585: 		return -EINVAL;
fp@2585: 
fp@2585: 	if (ec->rx_coalesce_usecs == 4) {
fp@2585: 		adapter->itr_setting = 4;
fp@2585: 		adapter->itr = adapter->itr_setting;
fp@2585: 	} else if (ec->rx_coalesce_usecs <= 3) {
fp@2585: 		adapter->itr = 20000;
fp@2585: 		adapter->itr_setting = ec->rx_coalesce_usecs;
fp@2585: 	} else {
fp@2585: 		adapter->itr = (1000000 / ec->rx_coalesce_usecs);
fp@2585: 		adapter->itr_setting = adapter->itr & ~3;
fp@2585: 	}
fp@2585: 
fp@2585: 	if (adapter->itr_setting != 0)
fp@2585: 		e1000e_write_itr(adapter, adapter->itr);
fp@2585: 	else
fp@2585: 		e1000e_write_itr(adapter, 0);
fp@2585: 
fp@2585: 	return 0;
fp@2585: }
fp@2585: 
fp@2585: static int e1000_nway_reset(struct net_device *netdev)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 
fp@2585: 	if (!netif_running(netdev))
fp@2585: 		return -EAGAIN;
fp@2585: 
fp@2585: 	if (!adapter->hw.mac.autoneg)
fp@2585: 		return -EINVAL;
fp@2585: 
fp@2585: 	e1000e_reinit_locked(adapter);
fp@2585: 
fp@2585: 	return 0;
fp@2585: }
fp@2585: 
fp@2585: static void e1000_get_ethtool_stats(struct net_device *netdev,
fp@2585: 				    struct ethtool_stats __always_unused *stats,
fp@2585: 				    u64 *data)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	struct rtnl_link_stats64 net_stats;
fp@2585: 	int i;
fp@2585: 	char *p = NULL;
fp@2585: 
fp@2585: 	e1000e_get_stats64(netdev, &net_stats);
fp@2585: 	for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
fp@2585: 		switch (e1000_gstrings_stats[i].type) {
fp@2585: 		case NETDEV_STATS:
fp@2585: 			p = (char *)&net_stats +
fp@2585: 			    e1000_gstrings_stats[i].stat_offset;
fp@2585: 			break;
fp@2585: 		case E1000_STATS:
fp@2585: 			p = (char *)adapter +
fp@2585: 			    e1000_gstrings_stats[i].stat_offset;
fp@2585: 			break;
fp@2585: 		default:
fp@2585: 			data[i] = 0;
fp@2585: 			continue;
fp@2585: 		}
fp@2585: 
fp@2585: 		data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
fp@2585: 			   sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
fp@2585: 	}
fp@2585: }
fp@2585: 
fp@2585: static void e1000_get_strings(struct net_device __always_unused *netdev,
fp@2585: 			      u32 stringset, u8 *data)
fp@2585: {
fp@2585: 	u8 *p = data;
fp@2585: 	int i;
fp@2585: 
fp@2585: 	switch (stringset) {
fp@2585: 	case ETH_SS_TEST:
fp@2585: 		memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
fp@2585: 		break;
fp@2585: 	case ETH_SS_STATS:
fp@2585: 		for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
fp@2585: 			memcpy(p, e1000_gstrings_stats[i].stat_string,
fp@2585: 			       ETH_GSTRING_LEN);
fp@2585: 			p += ETH_GSTRING_LEN;
fp@2585: 		}
fp@2585: 		break;
fp@2585: 	}
fp@2585: }
fp@2585: 
fp@2585: static int e1000_get_rxnfc(struct net_device *netdev,
fp@2585: 			   struct ethtool_rxnfc *info,
fp@2585: 			   u32 __always_unused *rule_locs)
fp@2585: {
fp@2585: 	info->data = 0;
fp@2585: 
fp@2585: 	switch (info->cmd) {
fp@2585: 	case ETHTOOL_GRXFH: {
fp@2585: 		struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 		struct e1000_hw *hw = &adapter->hw;
fp@2585: 		u32 mrqc = er32(MRQC);
fp@2585: 
fp@2585: 		if (!(mrqc & E1000_MRQC_RSS_FIELD_MASK))
fp@2585: 			return 0;
fp@2585: 
fp@2585: 		switch (info->flow_type) {
fp@2585: 		case TCP_V4_FLOW:
fp@2585: 			if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP)
fp@2585: 				info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
fp@2585: 			/* fall through */
fp@2585: 		case UDP_V4_FLOW:
fp@2585: 		case SCTP_V4_FLOW:
fp@2585: 		case AH_ESP_V4_FLOW:
fp@2585: 		case IPV4_FLOW:
fp@2585: 			if (mrqc & E1000_MRQC_RSS_FIELD_IPV4)
fp@2585: 				info->data |= RXH_IP_SRC | RXH_IP_DST;
fp@2585: 			break;
fp@2585: 		case TCP_V6_FLOW:
fp@2585: 			if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP)
fp@2585: 				info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
fp@2585: 			/* fall through */
fp@2585: 		case UDP_V6_FLOW:
fp@2585: 		case SCTP_V6_FLOW:
fp@2585: 		case AH_ESP_V6_FLOW:
fp@2585: 		case IPV6_FLOW:
fp@2585: 			if (mrqc & E1000_MRQC_RSS_FIELD_IPV6)
fp@2585: 				info->data |= RXH_IP_SRC | RXH_IP_DST;
fp@2585: 			break;
fp@2585: 		default:
fp@2585: 			break;
fp@2585: 		}
fp@2585: 		return 0;
fp@2585: 	}
fp@2585: 	default:
fp@2585: 		return -EOPNOTSUPP;
fp@2585: 	}
fp@2585: }
fp@2585: 
fp@2585: static int e1000e_get_eee(struct net_device *netdev, struct ethtool_eee *edata)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 	u16 cap_addr, lpa_addr, pcs_stat_addr, phy_data;
fp@2585: 	u32 ret_val;
fp@2585: 
fp@2585: 	if (!(adapter->flags2 & FLAG2_HAS_EEE))
fp@2585: 		return -EOPNOTSUPP;
fp@2585: 
fp@2585: 	switch (hw->phy.type) {
fp@2585: 	case e1000_phy_82579:
fp@2585: 		cap_addr = I82579_EEE_CAPABILITY;
fp@2585: 		lpa_addr = I82579_EEE_LP_ABILITY;
fp@2585: 		pcs_stat_addr = I82579_EEE_PCS_STATUS;
fp@2585: 		break;
fp@2585: 	case e1000_phy_i217:
fp@2585: 		cap_addr = I217_EEE_CAPABILITY;
fp@2585: 		lpa_addr = I217_EEE_LP_ABILITY;
fp@2585: 		pcs_stat_addr = I217_EEE_PCS_STATUS;
fp@2585: 		break;
fp@2585: 	default:
fp@2585: 		return -EOPNOTSUPP;
fp@2585: 	}
fp@2585: 
fp@2585: 	ret_val = hw->phy.ops.acquire(hw);
fp@2585: 	if (ret_val)
fp@2585: 		return -EBUSY;
fp@2585: 
fp@2585: 	/* EEE Capability */
fp@2585: 	ret_val = e1000_read_emi_reg_locked(hw, cap_addr, &phy_data);
fp@2585: 	if (ret_val)
fp@2585: 		goto release;
fp@2585: 	edata->supported = mmd_eee_cap_to_ethtool_sup_t(phy_data);
fp@2585: 
fp@2585: 	/* EEE Advertised */
fp@2585: 	edata->advertised = mmd_eee_adv_to_ethtool_adv_t(adapter->eee_advert);
fp@2585: 
fp@2585: 	/* EEE Link Partner Advertised */
fp@2585: 	ret_val = e1000_read_emi_reg_locked(hw, lpa_addr, &phy_data);
fp@2585: 	if (ret_val)
fp@2585: 		goto release;
fp@2585: 	edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
fp@2585: 
fp@2585: 	/* EEE PCS Status */
fp@2585: 	ret_val = e1000_read_emi_reg_locked(hw, pcs_stat_addr, &phy_data);
fp@2585: 	if (hw->phy.type == e1000_phy_82579)
fp@2585: 		phy_data <<= 8;
fp@2585: 
fp@2585: release:
fp@2585: 	hw->phy.ops.release(hw);
fp@2585: 	if (ret_val)
fp@2585: 		return -ENODATA;
fp@2585: 
fp@2585: 	/* Result of the EEE auto negotiation - there is no register that
fp@2585: 	 * has the status of the EEE negotiation so do a best-guess based
fp@2585: 	 * on whether Tx or Rx LPI indications have been received.
fp@2585: 	 */
fp@2585: 	if (phy_data & (E1000_EEE_TX_LPI_RCVD | E1000_EEE_RX_LPI_RCVD))
fp@2585: 		edata->eee_active = true;
fp@2585: 
fp@2585: 	edata->eee_enabled = !hw->dev_spec.ich8lan.eee_disable;
fp@2585: 	edata->tx_lpi_enabled = true;
fp@2585: 	edata->tx_lpi_timer = er32(LPIC) >> E1000_LPIC_LPIET_SHIFT;
fp@2585: 
fp@2585: 	return 0;
fp@2585: }
fp@2585: 
fp@2585: static int e1000e_set_eee(struct net_device *netdev, struct ethtool_eee *edata)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 	struct e1000_hw *hw = &adapter->hw;
fp@2585: 	struct ethtool_eee eee_curr;
fp@2585: 	s32 ret_val;
fp@2585: 
fp@2585: 	ret_val = e1000e_get_eee(netdev, &eee_curr);
fp@2585: 	if (ret_val)
fp@2585: 		return ret_val;
fp@2585: 
fp@2585: 	if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
fp@2585: 		e_err("Setting EEE tx-lpi is not supported\n");
fp@2585: 		return -EINVAL;
fp@2585: 	}
fp@2585: 
fp@2585: 	if (eee_curr.tx_lpi_timer != edata->tx_lpi_timer) {
fp@2585: 		e_err("Setting EEE Tx LPI timer is not supported\n");
fp@2585: 		return -EINVAL;
fp@2585: 	}
fp@2585: 
fp@2585: 	if (edata->advertised & ~(ADVERTISE_100_FULL | ADVERTISE_1000_FULL)) {
fp@2585: 		e_err("EEE advertisement supports only 100TX and/or 1000T full-duplex\n");
fp@2585: 		return -EINVAL;
fp@2585: 	}
fp@2585: 
fp@2585: 	adapter->eee_advert = ethtool_adv_to_mmd_eee_adv_t(edata->advertised);
fp@2585: 
fp@2585: 	hw->dev_spec.ich8lan.eee_disable = !edata->eee_enabled;
fp@2585: 
fp@2585: 	/* reset the link */
fp@2585: 	if (netif_running(netdev))
fp@2585: 		e1000e_reinit_locked(adapter);
fp@2585: 	else
fp@2585: 		e1000e_reset(adapter);
fp@2585: 
fp@2585: 	return 0;
fp@2585: }
fp@2585: 
fp@2585: static int e1000e_get_ts_info(struct net_device *netdev,
fp@2585: 			      struct ethtool_ts_info *info)
fp@2585: {
fp@2585: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2585: 
fp@2585: 	ethtool_op_get_ts_info(netdev, info);
fp@2585: 
fp@2585: 	if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
fp@2585: 		return 0;
fp@2585: 
fp@2585: 	info->so_timestamping |= (SOF_TIMESTAMPING_TX_HARDWARE |
fp@2585: 				  SOF_TIMESTAMPING_RX_HARDWARE |
fp@2585: 				  SOF_TIMESTAMPING_RAW_HARDWARE);
fp@2585: 
fp@2585: 	info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
fp@2585: 
fp@2585: 	info->rx_filters = ((1 << HWTSTAMP_FILTER_NONE) |
fp@2585: 			    (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
fp@2585: 			    (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
fp@2585: 			    (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
fp@2585: 			    (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
fp@2585: 			    (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
fp@2585: 			    (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
fp@2585: 			    (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
fp@2585: 			    (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
fp@2585: 			    (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
fp@2585: 			    (1 << HWTSTAMP_FILTER_ALL));
fp@2585: 
fp@2585: 	if (adapter->ptp_clock)
fp@2585: 		info->phc_index = ptp_clock_index(adapter->ptp_clock);
fp@2585: 
fp@2585: 	return 0;
fp@2585: }
fp@2585: 
fp@2585: static int e1000e_ethtool_begin(struct net_device *netdev)
fp@2585: {
fp@2585: 	return pm_runtime_get_sync(netdev->dev.parent);
fp@2585: }
fp@2585: 
fp@2585: static void e1000e_ethtool_complete(struct net_device *netdev)
fp@2585: {
fp@2585: 	pm_runtime_put_sync(netdev->dev.parent);
fp@2585: }
fp@2585: 
fp@2585: static const struct ethtool_ops e1000_ethtool_ops = {
fp@2585: 	.begin			= e1000e_ethtool_begin,
fp@2585: 	.complete		= e1000e_ethtool_complete,
fp@2585: 	.get_settings		= e1000_get_settings,
fp@2585: 	.set_settings		= e1000_set_settings,
fp@2585: 	.get_drvinfo		= e1000_get_drvinfo,
fp@2585: 	.get_regs_len		= e1000_get_regs_len,
fp@2585: 	.get_regs		= e1000_get_regs,
fp@2585: 	.get_wol		= e1000_get_wol,
fp@2585: 	.set_wol		= e1000_set_wol,
fp@2585: 	.get_msglevel		= e1000_get_msglevel,
fp@2585: 	.set_msglevel		= e1000_set_msglevel,
fp@2585: 	.nway_reset		= e1000_nway_reset,
fp@2585: 	.get_link		= ethtool_op_get_link,
fp@2585: 	.get_eeprom_len		= e1000_get_eeprom_len,
fp@2585: 	.get_eeprom		= e1000_get_eeprom,
fp@2585: 	.set_eeprom		= e1000_set_eeprom,
fp@2585: 	.get_ringparam		= e1000_get_ringparam,
fp@2585: 	.set_ringparam		= e1000_set_ringparam,
fp@2585: 	.get_pauseparam		= e1000_get_pauseparam,
fp@2585: 	.set_pauseparam		= e1000_set_pauseparam,
fp@2585: 	.self_test		= e1000_diag_test,
fp@2585: 	.get_strings		= e1000_get_strings,
fp@2585: 	.set_phys_id		= e1000_set_phys_id,
fp@2585: 	.get_ethtool_stats	= e1000_get_ethtool_stats,
fp@2585: 	.get_sset_count		= e1000e_get_sset_count,
fp@2585: 	.get_coalesce		= e1000_get_coalesce,
fp@2585: 	.set_coalesce		= e1000_set_coalesce,
fp@2585: 	.get_rxnfc		= e1000_get_rxnfc,
fp@2585: 	.get_ts_info		= e1000e_get_ts_info,
fp@2585: 	.get_eee		= e1000e_get_eee,
fp@2585: 	.set_eee		= e1000e_set_eee,
fp@2585: };
fp@2585: 
fp@2585: void e1000e_set_ethtool_ops(struct net_device *netdev)
fp@2585: {
fp@2585: 	SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
fp@2585: }