fp@2092: /*******************************************************************************
fp@2092: 
fp@2092:   Intel PRO/1000 Linux driver
fp@2092:   Copyright(c) 1999 - 2010 Intel Corporation.
fp@2092: 
fp@2092:   This program is free software; you can redistribute it and/or modify it
fp@2092:   under the terms and conditions of the GNU General Public License,
fp@2092:   version 2, as published by the Free Software Foundation.
fp@2092: 
fp@2092:   This program is distributed in the hope it will be useful, but WITHOUT
fp@2092:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fp@2092:   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
fp@2092:   more details.
fp@2092: 
fp@2092:   You should have received a copy of the GNU General Public License along with
fp@2092:   this program; if not, write to the Free Software Foundation, Inc.,
fp@2092:   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
fp@2092: 
fp@2092:   The full GNU General Public License is included in this distribution in
fp@2092:   the file called "COPYING".
fp@2092: 
fp@2092:   Contact Information:
fp@2092:   Linux NICS <linux.nics@intel.com>
fp@2092:   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
fp@2092:   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
fp@2092: 
fp@2092: *******************************************************************************/
fp@2092: 
fp@2092: /* ethtool support for e1000 */
fp@2092: 
fp@2092: #include <linux/netdevice.h>
fp@2092: #include <linux/ethtool.h>
fp@2092: #include <linux/pci.h>
fp@2092: #include <linux/slab.h>
fp@2092: #include <linux/delay.h>
fp@2092: 
fp@2092: #include "e1000.h"
fp@2092: 
fp@2092: enum {NETDEV_STATS, E1000_STATS};
fp@2092: 
fp@2092: struct e1000_stats {
fp@2092: 	char stat_string[ETH_GSTRING_LEN];
fp@2092: 	int type;
fp@2092: 	int sizeof_stat;
fp@2092: 	int stat_offset;
fp@2092: };
fp@2092: 
fp@2092: #define E1000_STAT(m)		E1000_STATS, \
fp@2092: 				sizeof(((struct e1000_adapter *)0)->m), \
fp@2092: 		      		offsetof(struct e1000_adapter, m)
fp@2092: #define E1000_NETDEV_STAT(m)	NETDEV_STATS, \
fp@2092: 				sizeof(((struct net_device *)0)->m), \
fp@2092: 				offsetof(struct net_device, m)
fp@2092: 
fp@2092: static const struct e1000_stats e1000_gstrings_stats[] = {
fp@2092: 	{ "rx_packets", E1000_STAT(stats.gprc) },
fp@2092: 	{ "tx_packets", E1000_STAT(stats.gptc) },
fp@2092: 	{ "rx_bytes", E1000_STAT(stats.gorc) },
fp@2092: 	{ "tx_bytes", E1000_STAT(stats.gotc) },
fp@2092: 	{ "rx_broadcast", E1000_STAT(stats.bprc) },
fp@2092: 	{ "tx_broadcast", E1000_STAT(stats.bptc) },
fp@2092: 	{ "rx_multicast", E1000_STAT(stats.mprc) },
fp@2092: 	{ "tx_multicast", E1000_STAT(stats.mptc) },
fp@2092: 	{ "rx_errors", E1000_NETDEV_STAT(stats.rx_errors) },
fp@2092: 	{ "tx_errors", E1000_NETDEV_STAT(stats.tx_errors) },
fp@2092: 	{ "tx_dropped", E1000_NETDEV_STAT(stats.tx_dropped) },
fp@2092: 	{ "multicast", E1000_STAT(stats.mprc) },
fp@2092: 	{ "collisions", E1000_STAT(stats.colc) },
fp@2092: 	{ "rx_length_errors", E1000_NETDEV_STAT(stats.rx_length_errors) },
fp@2092: 	{ "rx_over_errors", E1000_NETDEV_STAT(stats.rx_over_errors) },
fp@2092: 	{ "rx_crc_errors", E1000_STAT(stats.crcerrs) },
fp@2092: 	{ "rx_frame_errors", E1000_NETDEV_STAT(stats.rx_frame_errors) },
fp@2092: 	{ "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
fp@2092: 	{ "rx_missed_errors", E1000_STAT(stats.mpc) },
fp@2092: 	{ "tx_aborted_errors", E1000_STAT(stats.ecol) },
fp@2092: 	{ "tx_carrier_errors", E1000_STAT(stats.tncrs) },
fp@2092: 	{ "tx_fifo_errors", E1000_NETDEV_STAT(stats.tx_fifo_errors) },
fp@2092: 	{ "tx_heartbeat_errors", E1000_NETDEV_STAT(stats.tx_heartbeat_errors) },
fp@2092: 	{ "tx_window_errors", E1000_STAT(stats.latecol) },
fp@2092: 	{ "tx_abort_late_coll", E1000_STAT(stats.latecol) },
fp@2092: 	{ "tx_deferred_ok", E1000_STAT(stats.dc) },
fp@2092: 	{ "tx_single_coll_ok", E1000_STAT(stats.scc) },
fp@2092: 	{ "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
fp@2092: 	{ "tx_timeout_count", E1000_STAT(tx_timeout_count) },
fp@2092: 	{ "tx_restart_queue", E1000_STAT(restart_queue) },
fp@2092: 	{ "rx_long_length_errors", E1000_STAT(stats.roc) },
fp@2092: 	{ "rx_short_length_errors", E1000_STAT(stats.ruc) },
fp@2092: 	{ "rx_align_errors", E1000_STAT(stats.algnerrc) },
fp@2092: 	{ "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
fp@2092: 	{ "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
fp@2092: 	{ "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
fp@2092: 	{ "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
fp@2092: 	{ "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
fp@2092: 	{ "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
fp@2092: 	{ "rx_long_byte_count", E1000_STAT(stats.gorc) },
fp@2092: 	{ "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
fp@2092: 	{ "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
fp@2092: 	{ "rx_header_split", E1000_STAT(rx_hdr_split) },
fp@2092: 	{ "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
fp@2092: 	{ "tx_smbus", E1000_STAT(stats.mgptc) },
fp@2092: 	{ "rx_smbus", E1000_STAT(stats.mgprc) },
fp@2092: 	{ "dropped_smbus", E1000_STAT(stats.mgpdc) },
fp@2092: 	{ "rx_dma_failed", E1000_STAT(rx_dma_failed) },
fp@2092: 	{ "tx_dma_failed", E1000_STAT(tx_dma_failed) },
fp@2092: };
fp@2092: 
fp@2092: #define E1000_GLOBAL_STATS_LEN	ARRAY_SIZE(e1000_gstrings_stats)
fp@2092: #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
fp@2092: static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
fp@2092: 	"Register test  (offline)", "Eeprom test    (offline)",
fp@2092: 	"Interrupt test (offline)", "Loopback test  (offline)",
fp@2092: 	"Link test   (on/offline)"
fp@2092: };
fp@2092: #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
fp@2092: 
fp@2092: static int e1000_get_settings(struct net_device *netdev,
fp@2092: 			      struct ethtool_cmd *ecmd)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 
fp@2092: 	if (hw->phy.media_type == e1000_media_type_copper) {
fp@2092: 
fp@2092: 		ecmd->supported = (SUPPORTED_10baseT_Half |
fp@2092: 				   SUPPORTED_10baseT_Full |
fp@2092: 				   SUPPORTED_100baseT_Half |
fp@2092: 				   SUPPORTED_100baseT_Full |
fp@2092: 				   SUPPORTED_1000baseT_Full |
fp@2092: 				   SUPPORTED_Autoneg |
fp@2092: 				   SUPPORTED_TP);
fp@2092: 		if (hw->phy.type == e1000_phy_ife)
fp@2092: 			ecmd->supported &= ~SUPPORTED_1000baseT_Full;
fp@2092: 		ecmd->advertising = ADVERTISED_TP;
fp@2092: 
fp@2092: 		if (hw->mac.autoneg == 1) {
fp@2092: 			ecmd->advertising |= ADVERTISED_Autoneg;
fp@2092: 			/* the e1000 autoneg seems to match ethtool nicely */
fp@2092: 			ecmd->advertising |= hw->phy.autoneg_advertised;
fp@2092: 		}
fp@2092: 
fp@2092: 		ecmd->port = PORT_TP;
fp@2092: 		ecmd->phy_address = hw->phy.addr;
fp@2092: 		ecmd->transceiver = XCVR_INTERNAL;
fp@2092: 
fp@2092: 	} else {
fp@2092: 		ecmd->supported   = (SUPPORTED_1000baseT_Full |
fp@2092: 				     SUPPORTED_FIBRE |
fp@2092: 				     SUPPORTED_Autoneg);
fp@2092: 
fp@2092: 		ecmd->advertising = (ADVERTISED_1000baseT_Full |
fp@2092: 				     ADVERTISED_FIBRE |
fp@2092: 				     ADVERTISED_Autoneg);
fp@2092: 
fp@2092: 		ecmd->port = PORT_FIBRE;
fp@2092: 		ecmd->transceiver = XCVR_EXTERNAL;
fp@2092: 	}
fp@2092: 
fp@2092: 	ecmd->speed = -1;
fp@2092: 	ecmd->duplex = -1;
fp@2092: 
fp@2092: 	if (netif_running(netdev)) {
fp@2092: 		if (netif_carrier_ok(netdev)) {
fp@2092: 			ecmd->speed = adapter->link_speed;
fp@2092: 			ecmd->duplex = adapter->link_duplex - 1;
fp@2092: 		}
fp@2092: 	} else {
fp@2092: 		u32 status = er32(STATUS);
fp@2092: 		if (status & E1000_STATUS_LU) {
fp@2092: 			if (status & E1000_STATUS_SPEED_1000)
fp@2092: 				ecmd->speed = 1000;
fp@2092: 			else if (status & E1000_STATUS_SPEED_100)
fp@2092: 				ecmd->speed = 100;
fp@2092: 			else
fp@2092: 				ecmd->speed = 10;
fp@2092: 
fp@2092: 			if (status & E1000_STATUS_FD)
fp@2092: 				ecmd->duplex = DUPLEX_FULL;
fp@2092: 			else
fp@2092: 				ecmd->duplex = DUPLEX_HALF;
fp@2092: 		}
fp@2092: 	}
fp@2092: 
fp@2092: 	ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
fp@2092: 			 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
fp@2092: 
fp@2092: 	/* MDI-X => 2; MDI =>1; Invalid =>0 */
fp@2092: 	if ((hw->phy.media_type == e1000_media_type_copper) &&
fp@2092: 	    netif_carrier_ok(netdev))
fp@2092: 		ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
fp@2092: 		                                      ETH_TP_MDI;
fp@2092: 	else
fp@2092: 		ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
fp@2092: 
fp@2092: 	return 0;
fp@2092: }
fp@2092: 
fp@2092: static u32 e1000_get_link(struct net_device *netdev)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 
fp@2092: 	/*
fp@2092: 	 * Avoid touching hardware registers when possible, otherwise
fp@2092: 	 * link negotiation can get messed up when user-level scripts
fp@2092: 	 * are rapidly polling the driver to see if link is up.
fp@2092: 	 */
fp@2092: 	return netif_running(netdev) ? netif_carrier_ok(netdev) :
fp@2092: 	    !!(er32(STATUS) & E1000_STATUS_LU);
fp@2092: }
fp@2092: 
fp@2092: static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
fp@2092: {
fp@2092: 	struct e1000_mac_info *mac = &adapter->hw.mac;
fp@2092: 
fp@2092: 	mac->autoneg = 0;
fp@2092: 
fp@2092: 	/* Fiber NICs only allow 1000 gbps Full duplex */
fp@2092: 	if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
fp@2092: 		spddplx != (SPEED_1000 + DUPLEX_FULL)) {
fp@2092: 		e_err("Unsupported Speed/Duplex configuration\n");
fp@2092: 		return -EINVAL;
fp@2092: 	}
fp@2092: 
fp@2092: 	switch (spddplx) {
fp@2092: 	case SPEED_10 + DUPLEX_HALF:
fp@2092: 		mac->forced_speed_duplex = ADVERTISE_10_HALF;
fp@2092: 		break;
fp@2092: 	case SPEED_10 + DUPLEX_FULL:
fp@2092: 		mac->forced_speed_duplex = ADVERTISE_10_FULL;
fp@2092: 		break;
fp@2092: 	case SPEED_100 + DUPLEX_HALF:
fp@2092: 		mac->forced_speed_duplex = ADVERTISE_100_HALF;
fp@2092: 		break;
fp@2092: 	case SPEED_100 + DUPLEX_FULL:
fp@2092: 		mac->forced_speed_duplex = ADVERTISE_100_FULL;
fp@2092: 		break;
fp@2092: 	case SPEED_1000 + DUPLEX_FULL:
fp@2092: 		mac->autoneg = 1;
fp@2092: 		adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
fp@2092: 		break;
fp@2092: 	case SPEED_1000 + DUPLEX_HALF: /* not supported */
fp@2092: 	default:
fp@2092: 		e_err("Unsupported Speed/Duplex configuration\n");
fp@2092: 		return -EINVAL;
fp@2092: 	}
fp@2092: 	return 0;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_set_settings(struct net_device *netdev,
fp@2092: 			      struct ethtool_cmd *ecmd)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 
fp@2092: 	/*
fp@2092: 	 * When SoL/IDER sessions are active, autoneg/speed/duplex
fp@2092: 	 * cannot be changed
fp@2092: 	 */
fp@2092: 	if (e1000_check_reset_block(hw)) {
fp@2092: 		e_err("Cannot change link characteristics when SoL/IDER is "
fp@2092: 		      "active.\n");
fp@2092: 		return -EINVAL;
fp@2092: 	}
fp@2092: 
fp@2092: 	while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
fp@2092: 		msleep(1);
fp@2092: 
fp@2092: 	if (ecmd->autoneg == AUTONEG_ENABLE) {
fp@2092: 		hw->mac.autoneg = 1;
fp@2092: 		if (hw->phy.media_type == e1000_media_type_fiber)
fp@2092: 			hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
fp@2092: 						     ADVERTISED_FIBRE |
fp@2092: 						     ADVERTISED_Autoneg;
fp@2092: 		else
fp@2092: 			hw->phy.autoneg_advertised = ecmd->advertising |
fp@2092: 						     ADVERTISED_TP |
fp@2092: 						     ADVERTISED_Autoneg;
fp@2092: 		ecmd->advertising = hw->phy.autoneg_advertised;
fp@2092: 		if (adapter->fc_autoneg)
fp@2092: 			hw->fc.requested_mode = e1000_fc_default;
fp@2092: 	} else {
fp@2092: 		if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
fp@2092: 			clear_bit(__E1000_RESETTING, &adapter->state);
fp@2092: 			return -EINVAL;
fp@2092: 		}
fp@2092: 	}
fp@2092: 
fp@2092: 	/* reset the link */
fp@2092: 
fp@2092: 	if (netif_running(adapter->netdev)) {
fp@2092: 		e1000e_down(adapter);
fp@2092: 		e1000e_up(adapter);
fp@2092: 	} else {
fp@2092: 		e1000e_reset(adapter);
fp@2092: 	}
fp@2092: 
fp@2092: 	clear_bit(__E1000_RESETTING, &adapter->state);
fp@2092: 	return 0;
fp@2092: }
fp@2092: 
fp@2092: static void e1000_get_pauseparam(struct net_device *netdev,
fp@2092: 				 struct ethtool_pauseparam *pause)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 
fp@2092: 	pause->autoneg =
fp@2092: 		(adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
fp@2092: 
fp@2092: 	if (hw->fc.current_mode == e1000_fc_rx_pause) {
fp@2092: 		pause->rx_pause = 1;
fp@2092: 	} else if (hw->fc.current_mode == e1000_fc_tx_pause) {
fp@2092: 		pause->tx_pause = 1;
fp@2092: 	} else if (hw->fc.current_mode == e1000_fc_full) {
fp@2092: 		pause->rx_pause = 1;
fp@2092: 		pause->tx_pause = 1;
fp@2092: 	}
fp@2092: }
fp@2092: 
fp@2092: static int e1000_set_pauseparam(struct net_device *netdev,
fp@2092: 				struct ethtool_pauseparam *pause)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 	int retval = 0;
fp@2092: 
fp@2092: 	adapter->fc_autoneg = pause->autoneg;
fp@2092: 
fp@2092: 	while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
fp@2092: 		msleep(1);
fp@2092: 
fp@2092: 	if (adapter->fc_autoneg == AUTONEG_ENABLE) {
fp@2092: 		hw->fc.requested_mode = e1000_fc_default;
fp@2092: 		if (netif_running(adapter->netdev)) {
fp@2092: 			e1000e_down(adapter);
fp@2092: 			e1000e_up(adapter);
fp@2092: 		} else {
fp@2092: 			e1000e_reset(adapter);
fp@2092: 		}
fp@2092: 	} else {
fp@2092: 		if (pause->rx_pause && pause->tx_pause)
fp@2092: 			hw->fc.requested_mode = e1000_fc_full;
fp@2092: 		else if (pause->rx_pause && !pause->tx_pause)
fp@2092: 			hw->fc.requested_mode = e1000_fc_rx_pause;
fp@2092: 		else if (!pause->rx_pause && pause->tx_pause)
fp@2092: 			hw->fc.requested_mode = e1000_fc_tx_pause;
fp@2092: 		else if (!pause->rx_pause && !pause->tx_pause)
fp@2092: 			hw->fc.requested_mode = e1000_fc_none;
fp@2092: 
fp@2092: 		hw->fc.current_mode = hw->fc.requested_mode;
fp@2092: 
fp@2092: 		if (hw->phy.media_type == e1000_media_type_fiber) {
fp@2092: 			retval = hw->mac.ops.setup_link(hw);
fp@2092: 			/* implicit goto out */
fp@2092: 		} else {
fp@2092: 			retval = e1000e_force_mac_fc(hw);
fp@2092: 			if (retval)
fp@2092: 				goto out;
fp@2092: 			e1000e_set_fc_watermarks(hw);
fp@2092: 		}
fp@2092: 	}
fp@2092: 
fp@2092: out:
fp@2092: 	clear_bit(__E1000_RESETTING, &adapter->state);
fp@2092: 	return retval;
fp@2092: }
fp@2092: 
fp@2092: static u32 e1000_get_rx_csum(struct net_device *netdev)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	return adapter->flags & FLAG_RX_CSUM_ENABLED;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 
fp@2092: 	if (data)
fp@2092: 		adapter->flags |= FLAG_RX_CSUM_ENABLED;
fp@2092: 	else
fp@2092: 		adapter->flags &= ~FLAG_RX_CSUM_ENABLED;
fp@2092: 
fp@2092: 	if (netif_running(netdev))
fp@2092: 		e1000e_reinit_locked(adapter);
fp@2092: 	else
fp@2092: 		e1000e_reset(adapter);
fp@2092: 	return 0;
fp@2092: }
fp@2092: 
fp@2092: static u32 e1000_get_tx_csum(struct net_device *netdev)
fp@2092: {
fp@2092: 	return (netdev->features & NETIF_F_HW_CSUM) != 0;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
fp@2092: {
fp@2092: 	if (data)
fp@2092: 		netdev->features |= NETIF_F_HW_CSUM;
fp@2092: 	else
fp@2092: 		netdev->features &= ~NETIF_F_HW_CSUM;
fp@2092: 
fp@2092: 	return 0;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_set_tso(struct net_device *netdev, u32 data)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 
fp@2092: 	if (data) {
fp@2092: 		netdev->features |= NETIF_F_TSO;
fp@2092: 		netdev->features |= NETIF_F_TSO6;
fp@2092: 	} else {
fp@2092: 		netdev->features &= ~NETIF_F_TSO;
fp@2092: 		netdev->features &= ~NETIF_F_TSO6;
fp@2092: 	}
fp@2092: 
fp@2092: 	adapter->flags |= FLAG_TSO_FORCE;
fp@2092: 	return 0;
fp@2092: }
fp@2092: 
fp@2092: static u32 e1000_get_msglevel(struct net_device *netdev)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	return adapter->msg_enable;
fp@2092: }
fp@2092: 
fp@2092: static void e1000_set_msglevel(struct net_device *netdev, u32 data)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	adapter->msg_enable = data;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_get_regs_len(struct net_device *netdev)
fp@2092: {
fp@2092: #define E1000_REGS_LEN 32 /* overestimate */
fp@2092: 	return E1000_REGS_LEN * sizeof(u32);
fp@2092: }
fp@2092: 
fp@2092: static void e1000_get_regs(struct net_device *netdev,
fp@2092: 			   struct ethtool_regs *regs, void *p)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 	u32 *regs_buff = p;
fp@2092: 	u16 phy_data;
fp@2092: 	u8 revision_id;
fp@2092: 
fp@2092: 	memset(p, 0, E1000_REGS_LEN * sizeof(u32));
fp@2092: 
fp@2092: 	pci_read_config_byte(adapter->pdev, PCI_REVISION_ID, &revision_id);
fp@2092: 
fp@2092: 	regs->version = (1 << 24) | (revision_id << 16) | adapter->pdev->device;
fp@2092: 
fp@2092: 	regs_buff[0]  = er32(CTRL);
fp@2092: 	regs_buff[1]  = er32(STATUS);
fp@2092: 
fp@2092: 	regs_buff[2]  = er32(RCTL);
fp@2092: 	regs_buff[3]  = er32(RDLEN);
fp@2092: 	regs_buff[4]  = er32(RDH);
fp@2092: 	regs_buff[5]  = er32(RDT);
fp@2092: 	regs_buff[6]  = er32(RDTR);
fp@2092: 
fp@2092: 	regs_buff[7]  = er32(TCTL);
fp@2092: 	regs_buff[8]  = er32(TDLEN);
fp@2092: 	regs_buff[9]  = er32(TDH);
fp@2092: 	regs_buff[10] = er32(TDT);
fp@2092: 	regs_buff[11] = er32(TIDV);
fp@2092: 
fp@2092: 	regs_buff[12] = adapter->hw.phy.type;  /* PHY type (IGP=1, M88=0) */
fp@2092: 
fp@2092: 	/* ethtool doesn't use anything past this point, so all this
fp@2092: 	 * code is likely legacy junk for apps that may or may not
fp@2092: 	 * exist */
fp@2092: 	if (hw->phy.type == e1000_phy_m88) {
fp@2092: 		e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
fp@2092: 		regs_buff[13] = (u32)phy_data; /* cable length */
fp@2092: 		regs_buff[14] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
fp@2092: 		regs_buff[15] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
fp@2092: 		regs_buff[16] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
fp@2092: 		e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
fp@2092: 		regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
fp@2092: 		regs_buff[18] = regs_buff[13]; /* cable polarity */
fp@2092: 		regs_buff[19] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
fp@2092: 		regs_buff[20] = regs_buff[17]; /* polarity correction */
fp@2092: 		/* phy receive errors */
fp@2092: 		regs_buff[22] = adapter->phy_stats.receive_errors;
fp@2092: 		regs_buff[23] = regs_buff[13]; /* mdix mode */
fp@2092: 	}
fp@2092: 	regs_buff[21] = 0; /* was idle_errors */
fp@2092: 	e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
fp@2092: 	regs_buff[24] = (u32)phy_data;  /* phy local receiver status */
fp@2092: 	regs_buff[25] = regs_buff[24];  /* phy remote receiver status */
fp@2092: }
fp@2092: 
fp@2092: static int e1000_get_eeprom_len(struct net_device *netdev)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	return adapter->hw.nvm.word_size * 2;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_get_eeprom(struct net_device *netdev,
fp@2092: 			    struct ethtool_eeprom *eeprom, u8 *bytes)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 	u16 *eeprom_buff;
fp@2092: 	int first_word;
fp@2092: 	int last_word;
fp@2092: 	int ret_val = 0;
fp@2092: 	u16 i;
fp@2092: 
fp@2092: 	if (eeprom->len == 0)
fp@2092: 		return -EINVAL;
fp@2092: 
fp@2092: 	eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
fp@2092: 
fp@2092: 	first_word = eeprom->offset >> 1;
fp@2092: 	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
fp@2092: 
fp@2092: 	eeprom_buff = kmalloc(sizeof(u16) *
fp@2092: 			(last_word - first_word + 1), GFP_KERNEL);
fp@2092: 	if (!eeprom_buff)
fp@2092: 		return -ENOMEM;
fp@2092: 
fp@2092: 	if (hw->nvm.type == e1000_nvm_eeprom_spi) {
fp@2092: 		ret_val = e1000_read_nvm(hw, first_word,
fp@2092: 					 last_word - first_word + 1,
fp@2092: 					 eeprom_buff);
fp@2092: 	} else {
fp@2092: 		for (i = 0; i < last_word - first_word + 1; i++) {
fp@2092: 			ret_val = e1000_read_nvm(hw, first_word + i, 1,
fp@2092: 						      &eeprom_buff[i]);
fp@2092: 			if (ret_val)
fp@2092: 				break;
fp@2092: 		}
fp@2092: 	}
fp@2092: 
fp@2092: 	if (ret_val) {
fp@2092: 		/* a read error occurred, throw away the result */
fp@2092: 		memset(eeprom_buff, 0xff, sizeof(u16) *
fp@2092: 		       (last_word - first_word + 1));
fp@2092: 	} else {
fp@2092: 		/* Device's eeprom is always little-endian, word addressable */
fp@2092: 		for (i = 0; i < last_word - first_word + 1; i++)
fp@2092: 			le16_to_cpus(&eeprom_buff[i]);
fp@2092: 	}
fp@2092: 
fp@2092: 	memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
fp@2092: 	kfree(eeprom_buff);
fp@2092: 
fp@2092: 	return ret_val;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_set_eeprom(struct net_device *netdev,
fp@2092: 			    struct ethtool_eeprom *eeprom, u8 *bytes)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 	u16 *eeprom_buff;
fp@2092: 	void *ptr;
fp@2092: 	int max_len;
fp@2092: 	int first_word;
fp@2092: 	int last_word;
fp@2092: 	int ret_val = 0;
fp@2092: 	u16 i;
fp@2092: 
fp@2092: 	if (eeprom->len == 0)
fp@2092: 		return -EOPNOTSUPP;
fp@2092: 
fp@2092: 	if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
fp@2092: 		return -EFAULT;
fp@2092: 
fp@2092: 	if (adapter->flags & FLAG_READ_ONLY_NVM)
fp@2092: 		return -EINVAL;
fp@2092: 
fp@2092: 	max_len = hw->nvm.word_size * 2;
fp@2092: 
fp@2092: 	first_word = eeprom->offset >> 1;
fp@2092: 	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
fp@2092: 	eeprom_buff = kmalloc(max_len, GFP_KERNEL);
fp@2092: 	if (!eeprom_buff)
fp@2092: 		return -ENOMEM;
fp@2092: 
fp@2092: 	ptr = (void *)eeprom_buff;
fp@2092: 
fp@2092: 	if (eeprom->offset & 1) {
fp@2092: 		/* need read/modify/write of first changed EEPROM word */
fp@2092: 		/* only the second byte of the word is being modified */
fp@2092: 		ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
fp@2092: 		ptr++;
fp@2092: 	}
fp@2092: 	if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0))
fp@2092: 		/* need read/modify/write of last changed EEPROM word */
fp@2092: 		/* only the first byte of the word is being modified */
fp@2092: 		ret_val = e1000_read_nvm(hw, last_word, 1,
fp@2092: 				  &eeprom_buff[last_word - first_word]);
fp@2092: 
fp@2092: 	if (ret_val)
fp@2092: 		goto out;
fp@2092: 
fp@2092: 	/* Device's eeprom is always little-endian, word addressable */
fp@2092: 	for (i = 0; i < last_word - first_word + 1; i++)
fp@2092: 		le16_to_cpus(&eeprom_buff[i]);
fp@2092: 
fp@2092: 	memcpy(ptr, bytes, eeprom->len);
fp@2092: 
fp@2092: 	for (i = 0; i < last_word - first_word + 1; i++)
fp@2092: 		eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
fp@2092: 
fp@2092: 	ret_val = e1000_write_nvm(hw, first_word,
fp@2092: 				  last_word - first_word + 1, eeprom_buff);
fp@2092: 
fp@2092: 	if (ret_val)
fp@2092: 		goto out;
fp@2092: 
fp@2092: 	/*
fp@2092: 	 * Update the checksum over the first part of the EEPROM if needed
fp@2092: 	 * and flush shadow RAM for applicable controllers
fp@2092: 	 */
fp@2092: 	if ((first_word <= NVM_CHECKSUM_REG) ||
fp@2092: 	    (hw->mac.type == e1000_82583) ||
fp@2092: 	    (hw->mac.type == e1000_82574) ||
fp@2092: 	    (hw->mac.type == e1000_82573))
fp@2092: 		ret_val = e1000e_update_nvm_checksum(hw);
fp@2092: 
fp@2092: out:
fp@2092: 	kfree(eeprom_buff);
fp@2092: 	return ret_val;
fp@2092: }
fp@2092: 
fp@2092: static void e1000_get_drvinfo(struct net_device *netdev,
fp@2092: 			      struct ethtool_drvinfo *drvinfo)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	char firmware_version[32];
fp@2092: 
fp@2092: 	strncpy(drvinfo->driver,  e1000e_driver_name, 32);
fp@2092: 	strncpy(drvinfo->version, e1000e_driver_version, 32);
fp@2092: 
fp@2092: 	/*
fp@2092: 	 * EEPROM image version # is reported as firmware version # for
fp@2092: 	 * PCI-E controllers
fp@2092: 	 */
fp@2092: 	sprintf(firmware_version, "%d.%d-%d",
fp@2092: 		(adapter->eeprom_vers & 0xF000) >> 12,
fp@2092: 		(adapter->eeprom_vers & 0x0FF0) >> 4,
fp@2092: 		(adapter->eeprom_vers & 0x000F));
fp@2092: 
fp@2092: 	strncpy(drvinfo->fw_version, firmware_version, 32);
fp@2092: 	strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
fp@2092: 	drvinfo->regdump_len = e1000_get_regs_len(netdev);
fp@2092: 	drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
fp@2092: }
fp@2092: 
fp@2092: static void e1000_get_ringparam(struct net_device *netdev,
fp@2092: 				struct ethtool_ringparam *ring)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	struct e1000_ring *tx_ring = adapter->tx_ring;
fp@2092: 	struct e1000_ring *rx_ring = adapter->rx_ring;
fp@2092: 
fp@2092: 	ring->rx_max_pending = E1000_MAX_RXD;
fp@2092: 	ring->tx_max_pending = E1000_MAX_TXD;
fp@2092: 	ring->rx_mini_max_pending = 0;
fp@2092: 	ring->rx_jumbo_max_pending = 0;
fp@2092: 	ring->rx_pending = rx_ring->count;
fp@2092: 	ring->tx_pending = tx_ring->count;
fp@2092: 	ring->rx_mini_pending = 0;
fp@2092: 	ring->rx_jumbo_pending = 0;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_set_ringparam(struct net_device *netdev,
fp@2092: 			       struct ethtool_ringparam *ring)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	struct e1000_ring *tx_ring, *tx_old;
fp@2092: 	struct e1000_ring *rx_ring, *rx_old;
fp@2092: 	int err;
fp@2092: 
fp@2092: 	if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
fp@2092: 		return -EINVAL;
fp@2092: 
fp@2092: 	while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
fp@2092: 		msleep(1);
fp@2092: 
fp@2092: 	if (netif_running(adapter->netdev))
fp@2092: 		e1000e_down(adapter);
fp@2092: 
fp@2092: 	tx_old = adapter->tx_ring;
fp@2092: 	rx_old = adapter->rx_ring;
fp@2092: 
fp@2092: 	err = -ENOMEM;
fp@2092: 	tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
fp@2092: 	if (!tx_ring)
fp@2092: 		goto err_alloc_tx;
fp@2092: 	/*
fp@2092: 	 * use a memcpy to save any previously configured
fp@2092: 	 * items like napi structs from having to be
fp@2092: 	 * reinitialized
fp@2092: 	 */
fp@2092: 	memcpy(tx_ring, tx_old, sizeof(struct e1000_ring));
fp@2092: 
fp@2092: 	rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
fp@2092: 	if (!rx_ring)
fp@2092: 		goto err_alloc_rx;
fp@2092: 	memcpy(rx_ring, rx_old, sizeof(struct e1000_ring));
fp@2092: 
fp@2092: 	adapter->tx_ring = tx_ring;
fp@2092: 	adapter->rx_ring = rx_ring;
fp@2092: 
fp@2092: 	rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
fp@2092: 	rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD));
fp@2092: 	rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
fp@2092: 
fp@2092: 	tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
fp@2092: 	tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
fp@2092: 	tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
fp@2092: 
fp@2092: 	if (netif_running(adapter->netdev)) {
fp@2092: 		/* Try to get new resources before deleting old */
fp@2092: 		err = e1000e_setup_rx_resources(adapter);
fp@2092: 		if (err)
fp@2092: 			goto err_setup_rx;
fp@2092: 		err = e1000e_setup_tx_resources(adapter);
fp@2092: 		if (err)
fp@2092: 			goto err_setup_tx;
fp@2092: 
fp@2092: 		/*
fp@2092: 		 * restore the old in order to free it,
fp@2092: 		 * then add in the new
fp@2092: 		 */
fp@2092: 		adapter->rx_ring = rx_old;
fp@2092: 		adapter->tx_ring = tx_old;
fp@2092: 		e1000e_free_rx_resources(adapter);
fp@2092: 		e1000e_free_tx_resources(adapter);
fp@2092: 		kfree(tx_old);
fp@2092: 		kfree(rx_old);
fp@2092: 		adapter->rx_ring = rx_ring;
fp@2092: 		adapter->tx_ring = tx_ring;
fp@2092: 		err = e1000e_up(adapter);
fp@2092: 		if (err)
fp@2092: 			goto err_setup;
fp@2092: 	}
fp@2092: 
fp@2092: 	clear_bit(__E1000_RESETTING, &adapter->state);
fp@2092: 	return 0;
fp@2092: err_setup_tx:
fp@2092: 	e1000e_free_rx_resources(adapter);
fp@2092: err_setup_rx:
fp@2092: 	adapter->rx_ring = rx_old;
fp@2092: 	adapter->tx_ring = tx_old;
fp@2092: 	kfree(rx_ring);
fp@2092: err_alloc_rx:
fp@2092: 	kfree(tx_ring);
fp@2092: err_alloc_tx:
fp@2092: 	e1000e_up(adapter);
fp@2092: err_setup:
fp@2092: 	clear_bit(__E1000_RESETTING, &adapter->state);
fp@2092: 	return err;
fp@2092: }
fp@2092: 
fp@2092: static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
fp@2092: 			     int reg, int offset, u32 mask, u32 write)
fp@2092: {
fp@2092: 	u32 pat, val;
fp@2092: 	static const u32 test[] =
fp@2092: 		{0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
fp@2092: 	for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
fp@2092: 		E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
fp@2092: 				      (test[pat] & write));
fp@2092: 		val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
fp@2092: 		if (val != (test[pat] & write & mask)) {
fp@2092: 			e_err("pattern test reg %04X failed: got 0x%08X "
fp@2092: 			      "expected 0x%08X\n", reg + offset, val,
fp@2092: 			      (test[pat] & write & mask));
fp@2092: 			*data = reg;
fp@2092: 			return 1;
fp@2092: 		}
fp@2092: 	}
fp@2092: 	return 0;
fp@2092: }
fp@2092: 
fp@2092: static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
fp@2092: 			      int reg, u32 mask, u32 write)
fp@2092: {
fp@2092: 	u32 val;
fp@2092: 	__ew32(&adapter->hw, reg, write & mask);
fp@2092: 	val = __er32(&adapter->hw, reg);
fp@2092: 	if ((write & mask) != (val & mask)) {
fp@2092: 		e_err("set/check reg %04X test failed: got 0x%08X "
fp@2092: 		      "expected 0x%08X\n", reg, (val & mask), (write & mask));
fp@2092: 		*data = reg;
fp@2092: 		return 1;
fp@2092: 	}
fp@2092: 	return 0;
fp@2092: }
fp@2092: #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write)                       \
fp@2092: 	do {                                                                   \
fp@2092: 		if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
fp@2092: 			return 1;                                              \
fp@2092: 	} while (0)
fp@2092: #define REG_PATTERN_TEST(reg, mask, write)                                     \
fp@2092: 	REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
fp@2092: 
fp@2092: #define REG_SET_AND_CHECK(reg, mask, write)                                    \
fp@2092: 	do {                                                                   \
fp@2092: 		if (reg_set_and_check(adapter, data, reg, mask, write))        \
fp@2092: 			return 1;                                              \
fp@2092: 	} while (0)
fp@2092: 
fp@2092: static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
fp@2092: {
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 	struct e1000_mac_info *mac = &adapter->hw.mac;
fp@2092: 	u32 value;
fp@2092: 	u32 before;
fp@2092: 	u32 after;
fp@2092: 	u32 i;
fp@2092: 	u32 toggle;
fp@2092: 	u32 mask;
fp@2092: 
fp@2092: 	/*
fp@2092: 	 * The status register is Read Only, so a write should fail.
fp@2092: 	 * Some bits that get toggled are ignored.
fp@2092: 	 */
fp@2092: 	switch (mac->type) {
fp@2092: 	/* there are several bits on newer hardware that are r/w */
fp@2092: 	case e1000_82571:
fp@2092: 	case e1000_82572:
fp@2092: 	case e1000_80003es2lan:
fp@2092: 		toggle = 0x7FFFF3FF;
fp@2092: 		break;
fp@2092:         default:
fp@2092: 		toggle = 0x7FFFF033;
fp@2092: 		break;
fp@2092: 	}
fp@2092: 
fp@2092: 	before = er32(STATUS);
fp@2092: 	value = (er32(STATUS) & toggle);
fp@2092: 	ew32(STATUS, toggle);
fp@2092: 	after = er32(STATUS) & toggle;
fp@2092: 	if (value != after) {
fp@2092: 		e_err("failed STATUS register test got: 0x%08X expected: "
fp@2092: 		      "0x%08X\n", after, value);
fp@2092: 		*data = 1;
fp@2092: 		return 1;
fp@2092: 	}
fp@2092: 	/* restore previous status */
fp@2092: 	ew32(STATUS, before);
fp@2092: 
fp@2092: 	if (!(adapter->flags & FLAG_IS_ICH)) {
fp@2092: 		REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
fp@2092: 		REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
fp@2092: 		REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
fp@2092: 		REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
fp@2092: 	}
fp@2092: 
fp@2092: 	REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
fp@2092: 	REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
fp@2092: 	REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF);
fp@2092: 	REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF);
fp@2092: 	REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF);
fp@2092: 	REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
fp@2092: 	REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
fp@2092: 	REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
fp@2092: 	REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
fp@2092: 	REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF);
fp@2092: 
fp@2092: 	REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
fp@2092: 
fp@2092: 	before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
fp@2092: 	REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
fp@2092: 	REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
fp@2092: 
fp@2092: 	REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
fp@2092: 	REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
fp@2092: 	if (!(adapter->flags & FLAG_IS_ICH))
fp@2092: 		REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
fp@2092: 	REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
fp@2092: 	REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
fp@2092: 	mask = 0x8003FFFF;
fp@2092: 	switch (mac->type) {
fp@2092: 	case e1000_ich10lan:
fp@2092: 	case e1000_pchlan:
fp@2092: 	case e1000_pch2lan:
fp@2092: 		mask |= (1 << 18);
fp@2092: 		break;
fp@2092: 	default:
fp@2092: 		break;
fp@2092: 	}
fp@2092: 	for (i = 0; i < mac->rar_entry_count; i++)
fp@2092: 		REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
fp@2092: 		                       mask, 0xFFFFFFFF);
fp@2092: 
fp@2092: 	for (i = 0; i < mac->mta_reg_count; i++)
fp@2092: 		REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
fp@2092: 
fp@2092: 	*data = 0;
fp@2092: 	return 0;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
fp@2092: {
fp@2092: 	u16 temp;
fp@2092: 	u16 checksum = 0;
fp@2092: 	u16 i;
fp@2092: 
fp@2092: 	*data = 0;
fp@2092: 	/* Read and add up the contents of the EEPROM */
fp@2092: 	for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
fp@2092: 		if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
fp@2092: 			*data = 1;
fp@2092: 			return *data;
fp@2092: 		}
fp@2092: 		checksum += temp;
fp@2092: 	}
fp@2092: 
fp@2092: 	/* If Checksum is not Correct return error else test passed */
fp@2092: 	if ((checksum != (u16) NVM_SUM) && !(*data))
fp@2092: 		*data = 2;
fp@2092: 
fp@2092: 	return *data;
fp@2092: }
fp@2092: 
fp@2092: static irqreturn_t e1000_test_intr(int irq, void *data)
fp@2092: {
fp@2092: 	struct net_device *netdev = (struct net_device *) data;
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 
fp@2092: 	adapter->test_icr |= er32(ICR);
fp@2092: 
fp@2092: 	return IRQ_HANDLED;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
fp@2092: {
fp@2092: 	struct net_device *netdev = adapter->netdev;
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 	u32 mask;
fp@2092: 	u32 shared_int = 1;
fp@2092: 	u32 irq = adapter->pdev->irq;
fp@2092: 	int i;
fp@2092: 	int ret_val = 0;
fp@2092: 	int int_mode = E1000E_INT_MODE_LEGACY;
fp@2092: 
fp@2092: 	*data = 0;
fp@2092: 
fp@2092: 	/* NOTE: we don't test MSI/MSI-X interrupts here, yet */
fp@2092: 	if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
fp@2092: 		int_mode = adapter->int_mode;
fp@2092: 		e1000e_reset_interrupt_capability(adapter);
fp@2092: 		adapter->int_mode = E1000E_INT_MODE_LEGACY;
fp@2092: 		e1000e_set_interrupt_capability(adapter);
fp@2092: 	}
fp@2092: 	/* Hook up test interrupt handler just for this test */
fp@2092: 	if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
fp@2092: 			 netdev)) {
fp@2092: 		shared_int = 0;
fp@2092: 	} else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
fp@2092: 		 netdev->name, netdev)) {
fp@2092: 		*data = 1;
fp@2092: 		ret_val = -1;
fp@2092: 		goto out;
fp@2092: 	}
fp@2092: 	e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
fp@2092: 
fp@2092: 	/* Disable all the interrupts */
fp@2092: 	ew32(IMC, 0xFFFFFFFF);
fp@2092: 	msleep(10);
fp@2092: 
fp@2092: 	/* Test each interrupt */
fp@2092: 	for (i = 0; i < 10; i++) {
fp@2092: 		/* Interrupt to test */
fp@2092: 		mask = 1 << i;
fp@2092: 
fp@2092: 		if (adapter->flags & FLAG_IS_ICH) {
fp@2092: 			switch (mask) {
fp@2092: 			case E1000_ICR_RXSEQ:
fp@2092: 				continue;
fp@2092: 			case 0x00000100:
fp@2092: 				if (adapter->hw.mac.type == e1000_ich8lan ||
fp@2092: 				    adapter->hw.mac.type == e1000_ich9lan)
fp@2092: 					continue;
fp@2092: 				break;
fp@2092: 			default:
fp@2092: 				break;
fp@2092: 			}
fp@2092: 		}
fp@2092: 
fp@2092: 		if (!shared_int) {
fp@2092: 			/*
fp@2092: 			 * Disable the interrupt to be reported in
fp@2092: 			 * the cause register and then force the same
fp@2092: 			 * interrupt and see if one gets posted.  If
fp@2092: 			 * an interrupt was posted to the bus, the
fp@2092: 			 * test failed.
fp@2092: 			 */
fp@2092: 			adapter->test_icr = 0;
fp@2092: 			ew32(IMC, mask);
fp@2092: 			ew32(ICS, mask);
fp@2092: 			msleep(10);
fp@2092: 
fp@2092: 			if (adapter->test_icr & mask) {
fp@2092: 				*data = 3;
fp@2092: 				break;
fp@2092: 			}
fp@2092: 		}
fp@2092: 
fp@2092: 		/*
fp@2092: 		 * Enable the interrupt to be reported in
fp@2092: 		 * the cause register and then force the same
fp@2092: 		 * interrupt and see if one gets posted.  If
fp@2092: 		 * an interrupt was not posted to the bus, the
fp@2092: 		 * test failed.
fp@2092: 		 */
fp@2092: 		adapter->test_icr = 0;
fp@2092: 		ew32(IMS, mask);
fp@2092: 		ew32(ICS, mask);
fp@2092: 		msleep(10);
fp@2092: 
fp@2092: 		if (!(adapter->test_icr & mask)) {
fp@2092: 			*data = 4;
fp@2092: 			break;
fp@2092: 		}
fp@2092: 
fp@2092: 		if (!shared_int) {
fp@2092: 			/*
fp@2092: 			 * Disable the other interrupts to be reported in
fp@2092: 			 * the cause register and then force the other
fp@2092: 			 * interrupts and see if any get posted.  If
fp@2092: 			 * an interrupt was posted to the bus, the
fp@2092: 			 * test failed.
fp@2092: 			 */
fp@2092: 			adapter->test_icr = 0;
fp@2092: 			ew32(IMC, ~mask & 0x00007FFF);
fp@2092: 			ew32(ICS, ~mask & 0x00007FFF);
fp@2092: 			msleep(10);
fp@2092: 
fp@2092: 			if (adapter->test_icr) {
fp@2092: 				*data = 5;
fp@2092: 				break;
fp@2092: 			}
fp@2092: 		}
fp@2092: 	}
fp@2092: 
fp@2092: 	/* Disable all the interrupts */
fp@2092: 	ew32(IMC, 0xFFFFFFFF);
fp@2092: 	msleep(10);
fp@2092: 
fp@2092: 	/* Unhook test interrupt handler */
fp@2092: 	free_irq(irq, netdev);
fp@2092: 
fp@2092: out:
fp@2092: 	if (int_mode == E1000E_INT_MODE_MSIX) {
fp@2092: 		e1000e_reset_interrupt_capability(adapter);
fp@2092: 		adapter->int_mode = int_mode;
fp@2092: 		e1000e_set_interrupt_capability(adapter);
fp@2092: 	}
fp@2092: 
fp@2092: 	return ret_val;
fp@2092: }
fp@2092: 
fp@2092: static void e1000_free_desc_rings(struct e1000_adapter *adapter)
fp@2092: {
fp@2092: 	struct e1000_ring *tx_ring = &adapter->test_tx_ring;
fp@2092: 	struct e1000_ring *rx_ring = &adapter->test_rx_ring;
fp@2092: 	struct pci_dev *pdev = adapter->pdev;
fp@2092: 	int i;
fp@2092: 
fp@2092: 	if (tx_ring->desc && tx_ring->buffer_info) {
fp@2092: 		for (i = 0; i < tx_ring->count; i++) {
fp@2092: 			if (tx_ring->buffer_info[i].dma)
fp@2092: 				dma_unmap_single(&pdev->dev,
fp@2092: 					tx_ring->buffer_info[i].dma,
fp@2092: 					tx_ring->buffer_info[i].length,
fp@2092: 					DMA_TO_DEVICE);
fp@2092: 			if (tx_ring->buffer_info[i].skb)
fp@2092: 				dev_kfree_skb(tx_ring->buffer_info[i].skb);
fp@2092: 		}
fp@2092: 	}
fp@2092: 
fp@2092: 	if (rx_ring->desc && rx_ring->buffer_info) {
fp@2092: 		for (i = 0; i < rx_ring->count; i++) {
fp@2092: 			if (rx_ring->buffer_info[i].dma)
fp@2092: 				dma_unmap_single(&pdev->dev,
fp@2092: 					rx_ring->buffer_info[i].dma,
fp@2092: 					2048, DMA_FROM_DEVICE);
fp@2092: 			if (rx_ring->buffer_info[i].skb)
fp@2092: 				dev_kfree_skb(rx_ring->buffer_info[i].skb);
fp@2092: 		}
fp@2092: 	}
fp@2092: 
fp@2092: 	if (tx_ring->desc) {
fp@2092: 		dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
fp@2092: 				  tx_ring->dma);
fp@2092: 		tx_ring->desc = NULL;
fp@2092: 	}
fp@2092: 	if (rx_ring->desc) {
fp@2092: 		dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
fp@2092: 				  rx_ring->dma);
fp@2092: 		rx_ring->desc = NULL;
fp@2092: 	}
fp@2092: 
fp@2092: 	kfree(tx_ring->buffer_info);
fp@2092: 	tx_ring->buffer_info = NULL;
fp@2092: 	kfree(rx_ring->buffer_info);
fp@2092: 	rx_ring->buffer_info = NULL;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
fp@2092: {
fp@2092: 	struct e1000_ring *tx_ring = &adapter->test_tx_ring;
fp@2092: 	struct e1000_ring *rx_ring = &adapter->test_rx_ring;
fp@2092: 	struct pci_dev *pdev = adapter->pdev;
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 	u32 rctl;
fp@2092: 	int i;
fp@2092: 	int ret_val;
fp@2092: 
fp@2092: 	/* Setup Tx descriptor ring and Tx buffers */
fp@2092: 
fp@2092: 	if (!tx_ring->count)
fp@2092: 		tx_ring->count = E1000_DEFAULT_TXD;
fp@2092: 
fp@2092: 	tx_ring->buffer_info = kcalloc(tx_ring->count,
fp@2092: 				       sizeof(struct e1000_buffer),
fp@2092: 				       GFP_KERNEL);
fp@2092: 	if (!(tx_ring->buffer_info)) {
fp@2092: 		ret_val = 1;
fp@2092: 		goto err_nomem;
fp@2092: 	}
fp@2092: 
fp@2092: 	tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
fp@2092: 	tx_ring->size = ALIGN(tx_ring->size, 4096);
fp@2092: 	tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
fp@2092: 					   &tx_ring->dma, GFP_KERNEL);
fp@2092: 	if (!tx_ring->desc) {
fp@2092: 		ret_val = 2;
fp@2092: 		goto err_nomem;
fp@2092: 	}
fp@2092: 	tx_ring->next_to_use = 0;
fp@2092: 	tx_ring->next_to_clean = 0;
fp@2092: 
fp@2092: 	ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
fp@2092: 	ew32(TDBAH, ((u64) tx_ring->dma >> 32));
fp@2092: 	ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc));
fp@2092: 	ew32(TDH, 0);
fp@2092: 	ew32(TDT, 0);
fp@2092: 	ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
fp@2092: 	     E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
fp@2092: 	     E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
fp@2092: 
fp@2092: 	for (i = 0; i < tx_ring->count; i++) {
fp@2092: 		struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
fp@2092: 		struct sk_buff *skb;
fp@2092: 		unsigned int skb_size = 1024;
fp@2092: 
fp@2092: 		skb = alloc_skb(skb_size, GFP_KERNEL);
fp@2092: 		if (!skb) {
fp@2092: 			ret_val = 3;
fp@2092: 			goto err_nomem;
fp@2092: 		}
fp@2092: 		skb_put(skb, skb_size);
fp@2092: 		tx_ring->buffer_info[i].skb = skb;
fp@2092: 		tx_ring->buffer_info[i].length = skb->len;
fp@2092: 		tx_ring->buffer_info[i].dma =
fp@2092: 			dma_map_single(&pdev->dev, skb->data, skb->len,
fp@2092: 				       DMA_TO_DEVICE);
fp@2092: 		if (dma_mapping_error(&pdev->dev,
fp@2092: 				      tx_ring->buffer_info[i].dma)) {
fp@2092: 			ret_val = 4;
fp@2092: 			goto err_nomem;
fp@2092: 		}
fp@2092: 		tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
fp@2092: 		tx_desc->lower.data = cpu_to_le32(skb->len);
fp@2092: 		tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
fp@2092: 						   E1000_TXD_CMD_IFCS |
fp@2092: 						   E1000_TXD_CMD_RS);
fp@2092: 		tx_desc->upper.data = 0;
fp@2092: 	}
fp@2092: 
fp@2092: 	/* Setup Rx descriptor ring and Rx buffers */
fp@2092: 
fp@2092: 	if (!rx_ring->count)
fp@2092: 		rx_ring->count = E1000_DEFAULT_RXD;
fp@2092: 
fp@2092: 	rx_ring->buffer_info = kcalloc(rx_ring->count,
fp@2092: 				       sizeof(struct e1000_buffer),
fp@2092: 				       GFP_KERNEL);
fp@2092: 	if (!(rx_ring->buffer_info)) {
fp@2092: 		ret_val = 5;
fp@2092: 		goto err_nomem;
fp@2092: 	}
fp@2092: 
fp@2092: 	rx_ring->size = rx_ring->count * sizeof(struct e1000_rx_desc);
fp@2092: 	rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
fp@2092: 					   &rx_ring->dma, GFP_KERNEL);
fp@2092: 	if (!rx_ring->desc) {
fp@2092: 		ret_val = 6;
fp@2092: 		goto err_nomem;
fp@2092: 	}
fp@2092: 	rx_ring->next_to_use = 0;
fp@2092: 	rx_ring->next_to_clean = 0;
fp@2092: 
fp@2092: 	rctl = er32(RCTL);
fp@2092: 	ew32(RCTL, rctl & ~E1000_RCTL_EN);
fp@2092: 	ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
fp@2092: 	ew32(RDBAH, ((u64) rx_ring->dma >> 32));
fp@2092: 	ew32(RDLEN, rx_ring->size);
fp@2092: 	ew32(RDH, 0);
fp@2092: 	ew32(RDT, 0);
fp@2092: 	rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
fp@2092: 		E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
fp@2092: 		E1000_RCTL_SBP | E1000_RCTL_SECRC |
fp@2092: 		E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
fp@2092: 		(adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
fp@2092: 	ew32(RCTL, rctl);
fp@2092: 
fp@2092: 	for (i = 0; i < rx_ring->count; i++) {
fp@2092: 		struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
fp@2092: 		struct sk_buff *skb;
fp@2092: 
fp@2092: 		skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
fp@2092: 		if (!skb) {
fp@2092: 			ret_val = 7;
fp@2092: 			goto err_nomem;
fp@2092: 		}
fp@2092: 		skb_reserve(skb, NET_IP_ALIGN);
fp@2092: 		rx_ring->buffer_info[i].skb = skb;
fp@2092: 		rx_ring->buffer_info[i].dma =
fp@2092: 			dma_map_single(&pdev->dev, skb->data, 2048,
fp@2092: 				       DMA_FROM_DEVICE);
fp@2092: 		if (dma_mapping_error(&pdev->dev,
fp@2092: 				      rx_ring->buffer_info[i].dma)) {
fp@2092: 			ret_val = 8;
fp@2092: 			goto err_nomem;
fp@2092: 		}
fp@2092: 		rx_desc->buffer_addr =
fp@2092: 			cpu_to_le64(rx_ring->buffer_info[i].dma);
fp@2092: 		memset(skb->data, 0x00, skb->len);
fp@2092: 	}
fp@2092: 
fp@2092: 	return 0;
fp@2092: 
fp@2092: err_nomem:
fp@2092: 	e1000_free_desc_rings(adapter);
fp@2092: 	return ret_val;
fp@2092: }
fp@2092: 
fp@2092: static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
fp@2092: {
fp@2092: 	/* Write out to PHY registers 29 and 30 to disable the Receiver. */
fp@2092: 	e1e_wphy(&adapter->hw, 29, 0x001F);
fp@2092: 	e1e_wphy(&adapter->hw, 30, 0x8FFC);
fp@2092: 	e1e_wphy(&adapter->hw, 29, 0x001A);
fp@2092: 	e1e_wphy(&adapter->hw, 30, 0x8FF0);
fp@2092: }
fp@2092: 
fp@2092: static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
fp@2092: {
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 	u32 ctrl_reg = 0;
fp@2092: 	u32 stat_reg = 0;
fp@2092: 	u16 phy_reg = 0;
fp@2092: 
fp@2092: 	hw->mac.autoneg = 0;
fp@2092: 
fp@2092: 	if (hw->phy.type == e1000_phy_ife) {
fp@2092: 		/* force 100, set loopback */
fp@2092: 		e1e_wphy(hw, PHY_CONTROL, 0x6100);
fp@2092: 
fp@2092: 		/* Now set up the MAC to the same speed/duplex as the PHY. */
fp@2092: 		ctrl_reg = er32(CTRL);
fp@2092: 		ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
fp@2092: 		ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
fp@2092: 			     E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
fp@2092: 			     E1000_CTRL_SPD_100 |/* Force Speed to 100 */
fp@2092: 			     E1000_CTRL_FD);	 /* Force Duplex to FULL */
fp@2092: 
fp@2092: 		ew32(CTRL, ctrl_reg);
fp@2092: 		udelay(500);
fp@2092: 
fp@2092: 		return 0;
fp@2092: 	}
fp@2092: 
fp@2092: 	/* Specific PHY configuration for loopback */
fp@2092: 	switch (hw->phy.type) {
fp@2092: 	case e1000_phy_m88:
fp@2092: 		/* Auto-MDI/MDIX Off */
fp@2092: 		e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
fp@2092: 		/* reset to update Auto-MDI/MDIX */
fp@2092: 		e1e_wphy(hw, PHY_CONTROL, 0x9140);
fp@2092: 		/* autoneg off */
fp@2092: 		e1e_wphy(hw, PHY_CONTROL, 0x8140);
fp@2092: 		break;
fp@2092: 	case e1000_phy_gg82563:
fp@2092: 		e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
fp@2092: 		break;
fp@2092: 	case e1000_phy_bm:
fp@2092: 		/* Set Default MAC Interface speed to 1GB */
fp@2092: 		e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
fp@2092: 		phy_reg &= ~0x0007;
fp@2092: 		phy_reg |= 0x006;
fp@2092: 		e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
fp@2092: 		/* Assert SW reset for above settings to take effect */
fp@2092: 		e1000e_commit_phy(hw);
fp@2092: 		mdelay(1);
fp@2092: 		/* Force Full Duplex */
fp@2092: 		e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
fp@2092: 		e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
fp@2092: 		/* Set Link Up (in force link) */
fp@2092: 		e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
fp@2092: 		e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
fp@2092: 		/* Force Link */
fp@2092: 		e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
fp@2092: 		e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
fp@2092: 		/* Set Early Link Enable */
fp@2092: 		e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
fp@2092: 		e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
fp@2092: 		break;
fp@2092: 	case e1000_phy_82577:
fp@2092: 	case e1000_phy_82578:
fp@2092: 		/* Workaround: K1 must be disabled for stable 1Gbps operation */
fp@2092: 		e1000_configure_k1_ich8lan(hw, false);
fp@2092: 		break;
fp@2092: 	case e1000_phy_82579:
fp@2092: 		/* Disable PHY energy detect power down */
fp@2092: 		e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
fp@2092: 		e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
fp@2092: 		/* Disable full chip energy detect */
fp@2092: 		e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
fp@2092: 		e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
fp@2092: 		/* Enable loopback on the PHY */
fp@2092: #define I82577_PHY_LBK_CTRL          19
fp@2092: 		e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
fp@2092: 		break;
fp@2092: 	default:
fp@2092: 		break;
fp@2092: 	}
fp@2092: 
fp@2092: 	/* force 1000, set loopback */
fp@2092: 	e1e_wphy(hw, PHY_CONTROL, 0x4140);
fp@2092: 	mdelay(250);
fp@2092: 
fp@2092: 	/* Now set up the MAC to the same speed/duplex as the PHY. */
fp@2092: 	ctrl_reg = er32(CTRL);
fp@2092: 	ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
fp@2092: 	ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
fp@2092: 		     E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
fp@2092: 		     E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
fp@2092: 		     E1000_CTRL_FD);	 /* Force Duplex to FULL */
fp@2092: 
fp@2092: 	if (adapter->flags & FLAG_IS_ICH)
fp@2092: 		ctrl_reg |= E1000_CTRL_SLU;	/* Set Link Up */
fp@2092: 
fp@2092: 	if (hw->phy.media_type == e1000_media_type_copper &&
fp@2092: 	    hw->phy.type == e1000_phy_m88) {
fp@2092: 		ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
fp@2092: 	} else {
fp@2092: 		/*
fp@2092: 		 * Set the ILOS bit on the fiber Nic if half duplex link is
fp@2092: 		 * detected.
fp@2092: 		 */
fp@2092: 		stat_reg = er32(STATUS);
fp@2092: 		if ((stat_reg & E1000_STATUS_FD) == 0)
fp@2092: 			ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
fp@2092: 	}
fp@2092: 
fp@2092: 	ew32(CTRL, ctrl_reg);
fp@2092: 
fp@2092: 	/*
fp@2092: 	 * Disable the receiver on the PHY so when a cable is plugged in, the
fp@2092: 	 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
fp@2092: 	 */
fp@2092: 	if (hw->phy.type == e1000_phy_m88)
fp@2092: 		e1000_phy_disable_receiver(adapter);
fp@2092: 
fp@2092: 	udelay(500);
fp@2092: 
fp@2092: 	return 0;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
fp@2092: {
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 	u32 ctrl = er32(CTRL);
fp@2092: 	int link = 0;
fp@2092: 
fp@2092: 	/* special requirements for 82571/82572 fiber adapters */
fp@2092: 
fp@2092: 	/*
fp@2092: 	 * jump through hoops to make sure link is up because serdes
fp@2092: 	 * link is hardwired up
fp@2092: 	 */
fp@2092: 	ctrl |= E1000_CTRL_SLU;
fp@2092: 	ew32(CTRL, ctrl);
fp@2092: 
fp@2092: 	/* disable autoneg */
fp@2092: 	ctrl = er32(TXCW);
fp@2092: 	ctrl &= ~(1 << 31);
fp@2092: 	ew32(TXCW, ctrl);
fp@2092: 
fp@2092: 	link = (er32(STATUS) & E1000_STATUS_LU);
fp@2092: 
fp@2092: 	if (!link) {
fp@2092: 		/* set invert loss of signal */
fp@2092: 		ctrl = er32(CTRL);
fp@2092: 		ctrl |= E1000_CTRL_ILOS;
fp@2092: 		ew32(CTRL, ctrl);
fp@2092: 	}
fp@2092: 
fp@2092: 	/*
fp@2092: 	 * special write to serdes control register to enable SerDes analog
fp@2092: 	 * loopback
fp@2092: 	 */
fp@2092: #define E1000_SERDES_LB_ON 0x410
fp@2092: 	ew32(SCTL, E1000_SERDES_LB_ON);
fp@2092: 	msleep(10);
fp@2092: 
fp@2092: 	return 0;
fp@2092: }
fp@2092: 
fp@2092: /* only call this for fiber/serdes connections to es2lan */
fp@2092: static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
fp@2092: {
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 	u32 ctrlext = er32(CTRL_EXT);
fp@2092: 	u32 ctrl = er32(CTRL);
fp@2092: 
fp@2092: 	/*
fp@2092: 	 * save CTRL_EXT to restore later, reuse an empty variable (unused
fp@2092: 	 * on mac_type 80003es2lan)
fp@2092: 	 */
fp@2092: 	adapter->tx_fifo_head = ctrlext;
fp@2092: 
fp@2092: 	/* clear the serdes mode bits, putting the device into mac loopback */
fp@2092: 	ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
fp@2092: 	ew32(CTRL_EXT, ctrlext);
fp@2092: 
fp@2092: 	/* force speed to 1000/FD, link up */
fp@2092: 	ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
fp@2092: 	ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
fp@2092: 		 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
fp@2092: 	ew32(CTRL, ctrl);
fp@2092: 
fp@2092: 	/* set mac loopback */
fp@2092: 	ctrl = er32(RCTL);
fp@2092: 	ctrl |= E1000_RCTL_LBM_MAC;
fp@2092: 	ew32(RCTL, ctrl);
fp@2092: 
fp@2092: 	/* set testing mode parameters (no need to reset later) */
fp@2092: #define KMRNCTRLSTA_OPMODE (0x1F << 16)
fp@2092: #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
fp@2092: 	ew32(KMRNCTRLSTA,
fp@2092: 	     (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
fp@2092: 
fp@2092: 	return 0;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
fp@2092: {
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 	u32 rctl;
fp@2092: 
fp@2092: 	if (hw->phy.media_type == e1000_media_type_fiber ||
fp@2092: 	    hw->phy.media_type == e1000_media_type_internal_serdes) {
fp@2092: 		switch (hw->mac.type) {
fp@2092: 		case e1000_80003es2lan:
fp@2092: 			return e1000_set_es2lan_mac_loopback(adapter);
fp@2092: 			break;
fp@2092: 		case e1000_82571:
fp@2092: 		case e1000_82572:
fp@2092: 			return e1000_set_82571_fiber_loopback(adapter);
fp@2092: 			break;
fp@2092: 		default:
fp@2092: 			rctl = er32(RCTL);
fp@2092: 			rctl |= E1000_RCTL_LBM_TCVR;
fp@2092: 			ew32(RCTL, rctl);
fp@2092: 			return 0;
fp@2092: 		}
fp@2092: 	} else if (hw->phy.media_type == e1000_media_type_copper) {
fp@2092: 		return e1000_integrated_phy_loopback(adapter);
fp@2092: 	}
fp@2092: 
fp@2092: 	return 7;
fp@2092: }
fp@2092: 
fp@2092: static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
fp@2092: {
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 	u32 rctl;
fp@2092: 	u16 phy_reg;
fp@2092: 
fp@2092: 	rctl = er32(RCTL);
fp@2092: 	rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
fp@2092: 	ew32(RCTL, rctl);
fp@2092: 
fp@2092: 	switch (hw->mac.type) {
fp@2092: 	case e1000_80003es2lan:
fp@2092: 		if (hw->phy.media_type == e1000_media_type_fiber ||
fp@2092: 		    hw->phy.media_type == e1000_media_type_internal_serdes) {
fp@2092: 			/* restore CTRL_EXT, stealing space from tx_fifo_head */
fp@2092: 			ew32(CTRL_EXT, adapter->tx_fifo_head);
fp@2092: 			adapter->tx_fifo_head = 0;
fp@2092: 		}
fp@2092: 		/* fall through */
fp@2092: 	case e1000_82571:
fp@2092: 	case e1000_82572:
fp@2092: 		if (hw->phy.media_type == e1000_media_type_fiber ||
fp@2092: 		    hw->phy.media_type == e1000_media_type_internal_serdes) {
fp@2092: #define E1000_SERDES_LB_OFF 0x400
fp@2092: 			ew32(SCTL, E1000_SERDES_LB_OFF);
fp@2092: 			msleep(10);
fp@2092: 			break;
fp@2092: 		}
fp@2092: 		/* Fall Through */
fp@2092: 	default:
fp@2092: 		hw->mac.autoneg = 1;
fp@2092: 		if (hw->phy.type == e1000_phy_gg82563)
fp@2092: 			e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
fp@2092: 		e1e_rphy(hw, PHY_CONTROL, &phy_reg);
fp@2092: 		if (phy_reg & MII_CR_LOOPBACK) {
fp@2092: 			phy_reg &= ~MII_CR_LOOPBACK;
fp@2092: 			e1e_wphy(hw, PHY_CONTROL, phy_reg);
fp@2092: 			e1000e_commit_phy(hw);
fp@2092: 		}
fp@2092: 		break;
fp@2092: 	}
fp@2092: }
fp@2092: 
fp@2092: static void e1000_create_lbtest_frame(struct sk_buff *skb,
fp@2092: 				      unsigned int frame_size)
fp@2092: {
fp@2092: 	memset(skb->data, 0xFF, frame_size);
fp@2092: 	frame_size &= ~1;
fp@2092: 	memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
fp@2092: 	memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
fp@2092: 	memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
fp@2092: }
fp@2092: 
fp@2092: static int e1000_check_lbtest_frame(struct sk_buff *skb,
fp@2092: 				    unsigned int frame_size)
fp@2092: {
fp@2092: 	frame_size &= ~1;
fp@2092: 	if (*(skb->data + 3) == 0xFF)
fp@2092: 		if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
fp@2092: 		   (*(skb->data + frame_size / 2 + 12) == 0xAF))
fp@2092: 			return 0;
fp@2092: 	return 13;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_run_loopback_test(struct e1000_adapter *adapter)
fp@2092: {
fp@2092: 	struct e1000_ring *tx_ring = &adapter->test_tx_ring;
fp@2092: 	struct e1000_ring *rx_ring = &adapter->test_rx_ring;
fp@2092: 	struct pci_dev *pdev = adapter->pdev;
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 	int i, j, k, l;
fp@2092: 	int lc;
fp@2092: 	int good_cnt;
fp@2092: 	int ret_val = 0;
fp@2092: 	unsigned long time;
fp@2092: 
fp@2092: 	ew32(RDT, rx_ring->count - 1);
fp@2092: 
fp@2092: 	/*
fp@2092: 	 * Calculate the loop count based on the largest descriptor ring
fp@2092: 	 * The idea is to wrap the largest ring a number of times using 64
fp@2092: 	 * send/receive pairs during each loop
fp@2092: 	 */
fp@2092: 
fp@2092: 	if (rx_ring->count <= tx_ring->count)
fp@2092: 		lc = ((tx_ring->count / 64) * 2) + 1;
fp@2092: 	else
fp@2092: 		lc = ((rx_ring->count / 64) * 2) + 1;
fp@2092: 
fp@2092: 	k = 0;
fp@2092: 	l = 0;
fp@2092: 	for (j = 0; j <= lc; j++) { /* loop count loop */
fp@2092: 		for (i = 0; i < 64; i++) { /* send the packets */
fp@2092: 			e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
fp@2092: 						  1024);
fp@2092: 			dma_sync_single_for_device(&pdev->dev,
fp@2092: 					tx_ring->buffer_info[k].dma,
fp@2092: 					tx_ring->buffer_info[k].length,
fp@2092: 					DMA_TO_DEVICE);
fp@2092: 			k++;
fp@2092: 			if (k == tx_ring->count)
fp@2092: 				k = 0;
fp@2092: 		}
fp@2092: 		ew32(TDT, k);
fp@2092: 		msleep(200);
fp@2092: 		time = jiffies; /* set the start time for the receive */
fp@2092: 		good_cnt = 0;
fp@2092: 		do { /* receive the sent packets */
fp@2092: 			dma_sync_single_for_cpu(&pdev->dev,
fp@2092: 					rx_ring->buffer_info[l].dma, 2048,
fp@2092: 					DMA_FROM_DEVICE);
fp@2092: 
fp@2092: 			ret_val = e1000_check_lbtest_frame(
fp@2092: 					rx_ring->buffer_info[l].skb, 1024);
fp@2092: 			if (!ret_val)
fp@2092: 				good_cnt++;
fp@2092: 			l++;
fp@2092: 			if (l == rx_ring->count)
fp@2092: 				l = 0;
fp@2092: 			/*
fp@2092: 			 * time + 20 msecs (200 msecs on 2.4) is more than
fp@2092: 			 * enough time to complete the receives, if it's
fp@2092: 			 * exceeded, break and error off
fp@2092: 			 */
fp@2092: 		} while ((good_cnt < 64) && !time_after(jiffies, time + 20));
fp@2092: 		if (good_cnt != 64) {
fp@2092: 			ret_val = 13; /* ret_val is the same as mis-compare */
fp@2092: 			break;
fp@2092: 		}
fp@2092: 		if (jiffies >= (time + 20)) {
fp@2092: 			ret_val = 14; /* error code for time out error */
fp@2092: 			break;
fp@2092: 		}
fp@2092: 	} /* end loop count loop */
fp@2092: 	return ret_val;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
fp@2092: {
fp@2092: 	/*
fp@2092: 	 * PHY loopback cannot be performed if SoL/IDER
fp@2092: 	 * sessions are active
fp@2092: 	 */
fp@2092: 	if (e1000_check_reset_block(&adapter->hw)) {
fp@2092: 		e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
fp@2092: 		*data = 0;
fp@2092: 		goto out;
fp@2092: 	}
fp@2092: 
fp@2092: 	*data = e1000_setup_desc_rings(adapter);
fp@2092: 	if (*data)
fp@2092: 		goto out;
fp@2092: 
fp@2092: 	*data = e1000_setup_loopback_test(adapter);
fp@2092: 	if (*data)
fp@2092: 		goto err_loopback;
fp@2092: 
fp@2092: 	*data = e1000_run_loopback_test(adapter);
fp@2092: 	e1000_loopback_cleanup(adapter);
fp@2092: 
fp@2092: err_loopback:
fp@2092: 	e1000_free_desc_rings(adapter);
fp@2092: out:
fp@2092: 	return *data;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
fp@2092: {
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 
fp@2092: 	*data = 0;
fp@2092: 	if (hw->phy.media_type == e1000_media_type_internal_serdes) {
fp@2092: 		int i = 0;
fp@2092: 		hw->mac.serdes_has_link = false;
fp@2092: 
fp@2092: 		/*
fp@2092: 		 * On some blade server designs, link establishment
fp@2092: 		 * could take as long as 2-3 minutes
fp@2092: 		 */
fp@2092: 		do {
fp@2092: 			hw->mac.ops.check_for_link(hw);
fp@2092: 			if (hw->mac.serdes_has_link)
fp@2092: 				return *data;
fp@2092: 			msleep(20);
fp@2092: 		} while (i++ < 3750);
fp@2092: 
fp@2092: 		*data = 1;
fp@2092: 	} else {
fp@2092: 		hw->mac.ops.check_for_link(hw);
fp@2092: 		if (hw->mac.autoneg)
fp@2092: 			msleep(4000);
fp@2092: 
fp@2092: 		if (!(er32(STATUS) &
fp@2092: 		      E1000_STATUS_LU))
fp@2092: 			*data = 1;
fp@2092: 	}
fp@2092: 	return *data;
fp@2092: }
fp@2092: 
fp@2092: static int e1000e_get_sset_count(struct net_device *netdev, int sset)
fp@2092: {
fp@2092: 	switch (sset) {
fp@2092: 	case ETH_SS_TEST:
fp@2092: 		return E1000_TEST_LEN;
fp@2092: 	case ETH_SS_STATS:
fp@2092: 		return E1000_STATS_LEN;
fp@2092: 	default:
fp@2092: 		return -EOPNOTSUPP;
fp@2092: 	}
fp@2092: }
fp@2092: 
fp@2092: static void e1000_diag_test(struct net_device *netdev,
fp@2092: 			    struct ethtool_test *eth_test, u64 *data)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	u16 autoneg_advertised;
fp@2092: 	u8 forced_speed_duplex;
fp@2092: 	u8 autoneg;
fp@2092: 	bool if_running = netif_running(netdev);
fp@2092: 
fp@2092: 	set_bit(__E1000_TESTING, &adapter->state);
fp@2092: 	if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
fp@2092: 		/* Offline tests */
fp@2092: 
fp@2092: 		/* save speed, duplex, autoneg settings */
fp@2092: 		autoneg_advertised = adapter->hw.phy.autoneg_advertised;
fp@2092: 		forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
fp@2092: 		autoneg = adapter->hw.mac.autoneg;
fp@2092: 
fp@2092: 		e_info("offline testing starting\n");
fp@2092: 
fp@2092: 		if (if_running)
fp@2092: 			/* indicate we're in test mode */
fp@2092: 			dev_close(netdev);
fp@2092: 		else
fp@2092: 			e1000e_reset(adapter);
fp@2092: 
fp@2092: 		if (e1000_reg_test(adapter, &data[0]))
fp@2092: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2092: 
fp@2092: 		e1000e_reset(adapter);
fp@2092: 		if (e1000_eeprom_test(adapter, &data[1]))
fp@2092: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2092: 
fp@2092: 		e1000e_reset(adapter);
fp@2092: 		if (e1000_intr_test(adapter, &data[2]))
fp@2092: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2092: 
fp@2092: 		e1000e_reset(adapter);
fp@2092: 		/* make sure the phy is powered up */
fp@2092: 		e1000e_power_up_phy(adapter);
fp@2092: 		if (e1000_loopback_test(adapter, &data[3]))
fp@2092: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2092: 
fp@2092: 		/* force this routine to wait until autoneg complete/timeout */
fp@2092: 		adapter->hw.phy.autoneg_wait_to_complete = 1;
fp@2092: 		e1000e_reset(adapter);
fp@2092: 		adapter->hw.phy.autoneg_wait_to_complete = 0;
fp@2092: 
fp@2092: 		if (e1000_link_test(adapter, &data[4]))
fp@2092: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2092: 
fp@2092: 		/* restore speed, duplex, autoneg settings */
fp@2092: 		adapter->hw.phy.autoneg_advertised = autoneg_advertised;
fp@2092: 		adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
fp@2092: 		adapter->hw.mac.autoneg = autoneg;
fp@2092: 		e1000e_reset(adapter);
fp@2092: 
fp@2092: 		clear_bit(__E1000_TESTING, &adapter->state);
fp@2092: 		if (if_running)
fp@2092: 			dev_open(netdev);
fp@2092: 	} else {
fp@2092: 		if (!if_running && (adapter->flags & FLAG_HAS_AMT)) {
fp@2092: 			clear_bit(__E1000_TESTING, &adapter->state);
fp@2092: 			dev_open(netdev);
fp@2092: 			set_bit(__E1000_TESTING, &adapter->state);
fp@2092: 		}
fp@2092: 
fp@2092: 		e_info("online testing starting\n");
fp@2092: 		/* Online tests */
fp@2092: 		if (e1000_link_test(adapter, &data[4]))
fp@2092: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2092: 
fp@2092: 		/* Online tests aren't run; pass by default */
fp@2092: 		data[0] = 0;
fp@2092: 		data[1] = 0;
fp@2092: 		data[2] = 0;
fp@2092: 		data[3] = 0;
fp@2092: 
fp@2092: 		if (!if_running && (adapter->flags & FLAG_HAS_AMT))
fp@2092: 			dev_close(netdev);
fp@2092: 
fp@2092: 		clear_bit(__E1000_TESTING, &adapter->state);
fp@2092: 	}
fp@2092: 	msleep_interruptible(4 * 1000);
fp@2092: }
fp@2092: 
fp@2092: static void e1000_get_wol(struct net_device *netdev,
fp@2092: 			  struct ethtool_wolinfo *wol)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 
fp@2092: 	wol->supported = 0;
fp@2092: 	wol->wolopts = 0;
fp@2092: 
fp@2092: 	if (!(adapter->flags & FLAG_HAS_WOL) ||
fp@2092: 	    !device_can_wakeup(&adapter->pdev->dev))
fp@2092: 		return;
fp@2092: 
fp@2092: 	wol->supported = WAKE_UCAST | WAKE_MCAST |
fp@2092: 	                 WAKE_BCAST | WAKE_MAGIC |
fp@2092: 	                 WAKE_PHY | WAKE_ARP;
fp@2092: 
fp@2092: 	/* apply any specific unsupported masks here */
fp@2092: 	if (adapter->flags & FLAG_NO_WAKE_UCAST) {
fp@2092: 		wol->supported &= ~WAKE_UCAST;
fp@2092: 
fp@2092: 		if (adapter->wol & E1000_WUFC_EX)
fp@2092: 			e_err("Interface does not support directed (unicast) "
fp@2092: 			      "frame wake-up packets\n");
fp@2092: 	}
fp@2092: 
fp@2092: 	if (adapter->wol & E1000_WUFC_EX)
fp@2092: 		wol->wolopts |= WAKE_UCAST;
fp@2092: 	if (adapter->wol & E1000_WUFC_MC)
fp@2092: 		wol->wolopts |= WAKE_MCAST;
fp@2092: 	if (adapter->wol & E1000_WUFC_BC)
fp@2092: 		wol->wolopts |= WAKE_BCAST;
fp@2092: 	if (adapter->wol & E1000_WUFC_MAG)
fp@2092: 		wol->wolopts |= WAKE_MAGIC;
fp@2092: 	if (adapter->wol & E1000_WUFC_LNKC)
fp@2092: 		wol->wolopts |= WAKE_PHY;
fp@2092: 	if (adapter->wol & E1000_WUFC_ARP)
fp@2092: 		wol->wolopts |= WAKE_ARP;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_set_wol(struct net_device *netdev,
fp@2092: 			 struct ethtool_wolinfo *wol)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 
fp@2092: 	if (!(adapter->flags & FLAG_HAS_WOL) ||
fp@2092: 	    !device_can_wakeup(&adapter->pdev->dev) ||
fp@2092: 	    (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
fp@2092: 	                      WAKE_MAGIC | WAKE_PHY | WAKE_ARP)))
fp@2092: 		return -EOPNOTSUPP;
fp@2092: 
fp@2092: 	/* these settings will always override what we currently have */
fp@2092: 	adapter->wol = 0;
fp@2092: 
fp@2092: 	if (wol->wolopts & WAKE_UCAST)
fp@2092: 		adapter->wol |= E1000_WUFC_EX;
fp@2092: 	if (wol->wolopts & WAKE_MCAST)
fp@2092: 		adapter->wol |= E1000_WUFC_MC;
fp@2092: 	if (wol->wolopts & WAKE_BCAST)
fp@2092: 		adapter->wol |= E1000_WUFC_BC;
fp@2092: 	if (wol->wolopts & WAKE_MAGIC)
fp@2092: 		adapter->wol |= E1000_WUFC_MAG;
fp@2092: 	if (wol->wolopts & WAKE_PHY)
fp@2092: 		adapter->wol |= E1000_WUFC_LNKC;
fp@2092: 	if (wol->wolopts & WAKE_ARP)
fp@2092: 		adapter->wol |= E1000_WUFC_ARP;
fp@2092: 
fp@2092: 	device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
fp@2092: 
fp@2092: 	return 0;
fp@2092: }
fp@2092: 
fp@2092: /* toggle LED 4 times per second = 2 "blinks" per second */
fp@2092: #define E1000_ID_INTERVAL	(HZ/4)
fp@2092: 
fp@2092: /* bit defines for adapter->led_status */
fp@2092: #define E1000_LED_ON		0
fp@2092: 
fp@2092: static void e1000e_led_blink_task(struct work_struct *work)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = container_of(work,
fp@2092: 	                                struct e1000_adapter, led_blink_task);
fp@2092: 
fp@2092: 	if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
fp@2092: 		adapter->hw.mac.ops.led_off(&adapter->hw);
fp@2092: 	else
fp@2092: 		adapter->hw.mac.ops.led_on(&adapter->hw);
fp@2092: }
fp@2092: 
fp@2092: static void e1000_led_blink_callback(unsigned long data)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = (struct e1000_adapter *) data;
fp@2092: 
fp@2092: 	schedule_work(&adapter->led_blink_task);
fp@2092: 	mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
fp@2092: }
fp@2092: 
fp@2092: static int e1000_phys_id(struct net_device *netdev, u32 data)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 
fp@2092: 	if (!data)
fp@2092: 		data = INT_MAX;
fp@2092: 
fp@2092: 	if ((hw->phy.type == e1000_phy_ife) ||
fp@2092: 	    (hw->mac.type == e1000_pchlan) ||
fp@2092: 	    (hw->mac.type == e1000_pch2lan) ||
fp@2092: 	    (hw->mac.type == e1000_82583) ||
fp@2092: 	    (hw->mac.type == e1000_82574)) {
fp@2092: 		INIT_WORK(&adapter->led_blink_task, e1000e_led_blink_task);
fp@2092: 		if (!adapter->blink_timer.function) {
fp@2092: 			init_timer(&adapter->blink_timer);
fp@2092: 			adapter->blink_timer.function =
fp@2092: 				e1000_led_blink_callback;
fp@2092: 			adapter->blink_timer.data = (unsigned long) adapter;
fp@2092: 		}
fp@2092: 		mod_timer(&adapter->blink_timer, jiffies);
fp@2092: 		msleep_interruptible(data * 1000);
fp@2092: 		del_timer_sync(&adapter->blink_timer);
fp@2092: 		if (hw->phy.type == e1000_phy_ife)
fp@2092: 			e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
fp@2092: 	} else {
fp@2092: 		e1000e_blink_led(hw);
fp@2092: 		msleep_interruptible(data * 1000);
fp@2092: 	}
fp@2092: 
fp@2092: 	hw->mac.ops.led_off(hw);
fp@2092: 	clear_bit(E1000_LED_ON, &adapter->led_status);
fp@2092: 	hw->mac.ops.cleanup_led(hw);
fp@2092: 
fp@2092: 	return 0;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_get_coalesce(struct net_device *netdev,
fp@2092: 			      struct ethtool_coalesce *ec)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 
fp@2092: 	if (adapter->itr_setting <= 4)
fp@2092: 		ec->rx_coalesce_usecs = adapter->itr_setting;
fp@2092: 	else
fp@2092: 		ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
fp@2092: 
fp@2092: 	return 0;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_set_coalesce(struct net_device *netdev,
fp@2092: 			      struct ethtool_coalesce *ec)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	struct e1000_hw *hw = &adapter->hw;
fp@2092: 
fp@2092: 	if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
fp@2092: 	    ((ec->rx_coalesce_usecs > 4) &&
fp@2092: 	     (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
fp@2092: 	    (ec->rx_coalesce_usecs == 2))
fp@2092: 		return -EINVAL;
fp@2092: 
fp@2092: 	if (ec->rx_coalesce_usecs == 4) {
fp@2092: 		adapter->itr = adapter->itr_setting = 4;
fp@2092: 	} else if (ec->rx_coalesce_usecs <= 3) {
fp@2092: 		adapter->itr = 20000;
fp@2092: 		adapter->itr_setting = ec->rx_coalesce_usecs;
fp@2092: 	} else {
fp@2092: 		adapter->itr = (1000000 / ec->rx_coalesce_usecs);
fp@2092: 		adapter->itr_setting = adapter->itr & ~3;
fp@2092: 	}
fp@2092: 
fp@2092: 	if (adapter->itr_setting != 0)
fp@2092: 		ew32(ITR, 1000000000 / (adapter->itr * 256));
fp@2092: 	else
fp@2092: 		ew32(ITR, 0);
fp@2092: 
fp@2092: 	return 0;
fp@2092: }
fp@2092: 
fp@2092: static int e1000_nway_reset(struct net_device *netdev)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	if (netif_running(netdev))
fp@2092: 		e1000e_reinit_locked(adapter);
fp@2092: 	return 0;
fp@2092: }
fp@2092: 
fp@2092: static void e1000_get_ethtool_stats(struct net_device *netdev,
fp@2092: 				    struct ethtool_stats *stats,
fp@2092: 				    u64 *data)
fp@2092: {
fp@2092: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2092: 	int i;
fp@2092: 	char *p = NULL;
fp@2092: 
fp@2092: 	e1000e_update_stats(adapter);
fp@2092: 	for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
fp@2092: 		switch (e1000_gstrings_stats[i].type) {
fp@2092: 		case NETDEV_STATS:
fp@2092: 			p = (char *) netdev +
fp@2092: 					e1000_gstrings_stats[i].stat_offset;
fp@2092: 			break;
fp@2092: 		case E1000_STATS:
fp@2092: 			p = (char *) adapter +
fp@2092: 					e1000_gstrings_stats[i].stat_offset;
fp@2092: 			break;
fp@2092: 		}
fp@2092: 
fp@2092: 		data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
fp@2092: 			sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
fp@2092: 	}
fp@2092: }
fp@2092: 
fp@2092: static void e1000_get_strings(struct net_device *netdev, u32 stringset,
fp@2092: 			      u8 *data)
fp@2092: {
fp@2092: 	u8 *p = data;
fp@2092: 	int i;
fp@2092: 
fp@2092: 	switch (stringset) {
fp@2092: 	case ETH_SS_TEST:
fp@2092: 		memcpy(data, *e1000_gstrings_test, sizeof(e1000_gstrings_test));
fp@2092: 		break;
fp@2092: 	case ETH_SS_STATS:
fp@2092: 		for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
fp@2092: 			memcpy(p, e1000_gstrings_stats[i].stat_string,
fp@2092: 			       ETH_GSTRING_LEN);
fp@2092: 			p += ETH_GSTRING_LEN;
fp@2092: 		}
fp@2092: 		break;
fp@2092: 	}
fp@2092: }
fp@2092: 
fp@2092: static const struct ethtool_ops e1000_ethtool_ops = {
fp@2092: 	.get_settings		= e1000_get_settings,
fp@2092: 	.set_settings		= e1000_set_settings,
fp@2092: 	.get_drvinfo		= e1000_get_drvinfo,
fp@2092: 	.get_regs_len		= e1000_get_regs_len,
fp@2092: 	.get_regs		= e1000_get_regs,
fp@2092: 	.get_wol		= e1000_get_wol,
fp@2092: 	.set_wol		= e1000_set_wol,
fp@2092: 	.get_msglevel		= e1000_get_msglevel,
fp@2092: 	.set_msglevel		= e1000_set_msglevel,
fp@2092: 	.nway_reset		= e1000_nway_reset,
fp@2092: 	.get_link		= e1000_get_link,
fp@2092: 	.get_eeprom_len		= e1000_get_eeprom_len,
fp@2092: 	.get_eeprom		= e1000_get_eeprom,
fp@2092: 	.set_eeprom		= e1000_set_eeprom,
fp@2092: 	.get_ringparam		= e1000_get_ringparam,
fp@2092: 	.set_ringparam		= e1000_set_ringparam,
fp@2092: 	.get_pauseparam		= e1000_get_pauseparam,
fp@2092: 	.set_pauseparam		= e1000_set_pauseparam,
fp@2092: 	.get_rx_csum		= e1000_get_rx_csum,
fp@2092: 	.set_rx_csum		= e1000_set_rx_csum,
fp@2092: 	.get_tx_csum		= e1000_get_tx_csum,
fp@2092: 	.set_tx_csum		= e1000_set_tx_csum,
fp@2092: 	.get_sg			= ethtool_op_get_sg,
fp@2092: 	.set_sg			= ethtool_op_set_sg,
fp@2092: 	.get_tso		= ethtool_op_get_tso,
fp@2092: 	.set_tso		= e1000_set_tso,
fp@2092: 	.self_test		= e1000_diag_test,
fp@2092: 	.get_strings		= e1000_get_strings,
fp@2092: 	.phys_id		= e1000_phys_id,
fp@2092: 	.get_ethtool_stats	= e1000_get_ethtool_stats,
fp@2092: 	.get_sset_count		= e1000e_get_sset_count,
fp@2092: 	.get_coalesce		= e1000_get_coalesce,
fp@2092: 	.set_coalesce		= e1000_set_coalesce,
fp@2092: 	.get_flags		= ethtool_op_get_flags,
fp@2092: };
fp@2092: 
fp@2092: void e1000e_set_ethtool_ops(struct net_device *netdev)
fp@2092: {
fp@2092: 	SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
fp@2092: }