fp@2171: /*******************************************************************************
fp@2171: 
fp@2171:   Intel PRO/1000 Linux driver
fp@2171:   Copyright(c) 1999 - 2006 Intel Corporation.
fp@2171: 
fp@2171:   This program is free software; you can redistribute it and/or modify it
fp@2171:   under the terms and conditions of the GNU General Public License,
fp@2171:   version 2, as published by the Free Software Foundation.
fp@2171: 
fp@2171:   This program is distributed in the hope it will be useful, but WITHOUT
fp@2171:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fp@2171:   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
fp@2171:   more details.
fp@2171: 
fp@2171:   You should have received a copy of the GNU General Public License along with
fp@2171:   this program; if not, write to the Free Software Foundation, Inc.,
fp@2171:   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
fp@2171: 
fp@2171:   The full GNU General Public License is included in this distribution in
fp@2171:   the file called "COPYING".
fp@2171: 
fp@2171:   Contact Information:
fp@2171:   Linux NICS <linux.nics@intel.com>
fp@2171:   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
fp@2171:   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
fp@2171: 
fp@2171: *******************************************************************************/
fp@2171: 
fp@2171: /* ethtool support for e1000 */
fp@2171: 
fp@2171: #include "e1000-2.6.32-ethercat.h"
fp@2171: #include <asm/uaccess.h>
fp@2171: 
fp@2171: struct e1000_stats {
fp@2171: 	char stat_string[ETH_GSTRING_LEN];
fp@2171: 	int sizeof_stat;
fp@2171: 	int stat_offset;
fp@2171: };
fp@2171: 
fp@2171: #define E1000_STAT(m) FIELD_SIZEOF(struct e1000_adapter, m), \
fp@2171: 		      offsetof(struct e1000_adapter, m)
fp@2171: static const struct e1000_stats e1000_gstrings_stats[] = {
fp@2171: 	{ "rx_packets", E1000_STAT(stats.gprc) },
fp@2171: 	{ "tx_packets", E1000_STAT(stats.gptc) },
fp@2171: 	{ "rx_bytes", E1000_STAT(stats.gorcl) },
fp@2171: 	{ "tx_bytes", E1000_STAT(stats.gotcl) },
fp@2171: 	{ "rx_broadcast", E1000_STAT(stats.bprc) },
fp@2171: 	{ "tx_broadcast", E1000_STAT(stats.bptc) },
fp@2171: 	{ "rx_multicast", E1000_STAT(stats.mprc) },
fp@2171: 	{ "tx_multicast", E1000_STAT(stats.mptc) },
fp@2171: 	{ "rx_errors", E1000_STAT(stats.rxerrc) },
fp@2171: 	{ "tx_errors", E1000_STAT(stats.txerrc) },
fp@2171: 	{ "tx_dropped", E1000_STAT(net_stats.tx_dropped) },
fp@2171: 	{ "multicast", E1000_STAT(stats.mprc) },
fp@2171: 	{ "collisions", E1000_STAT(stats.colc) },
fp@2171: 	{ "rx_length_errors", E1000_STAT(stats.rlerrc) },
fp@2171: 	{ "rx_over_errors", E1000_STAT(net_stats.rx_over_errors) },
fp@2171: 	{ "rx_crc_errors", E1000_STAT(stats.crcerrs) },
fp@2171: 	{ "rx_frame_errors", E1000_STAT(net_stats.rx_frame_errors) },
fp@2171: 	{ "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
fp@2171: 	{ "rx_missed_errors", E1000_STAT(stats.mpc) },
fp@2171: 	{ "tx_aborted_errors", E1000_STAT(stats.ecol) },
fp@2171: 	{ "tx_carrier_errors", E1000_STAT(stats.tncrs) },
fp@2171: 	{ "tx_fifo_errors", E1000_STAT(net_stats.tx_fifo_errors) },
fp@2171: 	{ "tx_heartbeat_errors", E1000_STAT(net_stats.tx_heartbeat_errors) },
fp@2171: 	{ "tx_window_errors", E1000_STAT(stats.latecol) },
fp@2171: 	{ "tx_abort_late_coll", E1000_STAT(stats.latecol) },
fp@2171: 	{ "tx_deferred_ok", E1000_STAT(stats.dc) },
fp@2171: 	{ "tx_single_coll_ok", E1000_STAT(stats.scc) },
fp@2171: 	{ "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
fp@2171: 	{ "tx_timeout_count", E1000_STAT(tx_timeout_count) },
fp@2171: 	{ "tx_restart_queue", E1000_STAT(restart_queue) },
fp@2171: 	{ "rx_long_length_errors", E1000_STAT(stats.roc) },
fp@2171: 	{ "rx_short_length_errors", E1000_STAT(stats.ruc) },
fp@2171: 	{ "rx_align_errors", E1000_STAT(stats.algnerrc) },
fp@2171: 	{ "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
fp@2171: 	{ "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
fp@2171: 	{ "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
fp@2171: 	{ "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
fp@2171: 	{ "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
fp@2171: 	{ "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
fp@2171: 	{ "rx_long_byte_count", E1000_STAT(stats.gorcl) },
fp@2171: 	{ "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
fp@2171: 	{ "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
fp@2171: 	{ "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
fp@2171: 	{ "tx_smbus", E1000_STAT(stats.mgptc) },
fp@2171: 	{ "rx_smbus", E1000_STAT(stats.mgprc) },
fp@2171: 	{ "dropped_smbus", E1000_STAT(stats.mgpdc) },
fp@2171: };
fp@2171: 
fp@2171: #define E1000_QUEUE_STATS_LEN 0
fp@2171: #define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
fp@2171: #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN + E1000_QUEUE_STATS_LEN)
fp@2171: static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
fp@2171: 	"Register test  (offline)", "Eeprom test    (offline)",
fp@2171: 	"Interrupt test (offline)", "Loopback test  (offline)",
fp@2171: 	"Link test   (on/offline)"
fp@2171: };
fp@2171: #define E1000_TEST_LEN	ARRAY_SIZE(e1000_gstrings_test)
fp@2171: 
fp@2171: static int e1000_get_settings(struct net_device *netdev,
fp@2171: 			      struct ethtool_cmd *ecmd)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 
fp@2171: 	if (hw->media_type == e1000_media_type_copper) {
fp@2171: 
fp@2171: 		ecmd->supported = (SUPPORTED_10baseT_Half |
fp@2171: 		                   SUPPORTED_10baseT_Full |
fp@2171: 		                   SUPPORTED_100baseT_Half |
fp@2171: 		                   SUPPORTED_100baseT_Full |
fp@2171: 		                   SUPPORTED_1000baseT_Full|
fp@2171: 		                   SUPPORTED_Autoneg |
fp@2171: 		                   SUPPORTED_TP);
fp@2171: 		ecmd->advertising = ADVERTISED_TP;
fp@2171: 
fp@2171: 		if (hw->autoneg == 1) {
fp@2171: 			ecmd->advertising |= ADVERTISED_Autoneg;
fp@2171: 			/* the e1000 autoneg seems to match ethtool nicely */
fp@2171: 			ecmd->advertising |= hw->autoneg_advertised;
fp@2171: 		}
fp@2171: 
fp@2171: 		ecmd->port = PORT_TP;
fp@2171: 		ecmd->phy_address = hw->phy_addr;
fp@2171: 
fp@2171: 		if (hw->mac_type == e1000_82543)
fp@2171: 			ecmd->transceiver = XCVR_EXTERNAL;
fp@2171: 		else
fp@2171: 			ecmd->transceiver = XCVR_INTERNAL;
fp@2171: 
fp@2171: 	} else {
fp@2171: 		ecmd->supported   = (SUPPORTED_1000baseT_Full |
fp@2171: 				     SUPPORTED_FIBRE |
fp@2171: 				     SUPPORTED_Autoneg);
fp@2171: 
fp@2171: 		ecmd->advertising = (ADVERTISED_1000baseT_Full |
fp@2171: 				     ADVERTISED_FIBRE |
fp@2171: 				     ADVERTISED_Autoneg);
fp@2171: 
fp@2171: 		ecmd->port = PORT_FIBRE;
fp@2171: 
fp@2171: 		if (hw->mac_type >= e1000_82545)
fp@2171: 			ecmd->transceiver = XCVR_INTERNAL;
fp@2171: 		else
fp@2171: 			ecmd->transceiver = XCVR_EXTERNAL;
fp@2171: 	}
fp@2171: 
fp@2171: 	if (er32(STATUS) & E1000_STATUS_LU) {
fp@2171: 
fp@2171: 		e1000_get_speed_and_duplex(hw, &adapter->link_speed,
fp@2171: 		                                   &adapter->link_duplex);
fp@2171: 		ecmd->speed = adapter->link_speed;
fp@2171: 
fp@2171: 		/* unfortunatly FULL_DUPLEX != DUPLEX_FULL
fp@2171: 		 *          and HALF_DUPLEX != DUPLEX_HALF */
fp@2171: 
fp@2171: 		if (adapter->link_duplex == FULL_DUPLEX)
fp@2171: 			ecmd->duplex = DUPLEX_FULL;
fp@2171: 		else
fp@2171: 			ecmd->duplex = DUPLEX_HALF;
fp@2171: 	} else {
fp@2171: 		ecmd->speed = -1;
fp@2171: 		ecmd->duplex = -1;
fp@2171: 	}
fp@2171: 
fp@2171: 	ecmd->autoneg = ((hw->media_type == e1000_media_type_fiber) ||
fp@2171: 			 hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
fp@2171: 	return 0;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_set_settings(struct net_device *netdev,
fp@2171: 			      struct ethtool_cmd *ecmd)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 
fp@2171: 	if (adapter->ecdev)
fp@2171: 		return -EBUSY;
fp@2171: 
fp@2171: 	while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
fp@2171: 		msleep(1);
fp@2171: 
fp@2171: 	if (ecmd->autoneg == AUTONEG_ENABLE) {
fp@2171: 		hw->autoneg = 1;
fp@2171: 		if (hw->media_type == e1000_media_type_fiber)
fp@2171: 			hw->autoneg_advertised = ADVERTISED_1000baseT_Full |
fp@2171: 				     ADVERTISED_FIBRE |
fp@2171: 				     ADVERTISED_Autoneg;
fp@2171: 		else
fp@2171: 			hw->autoneg_advertised = ecmd->advertising |
fp@2171: 			                         ADVERTISED_TP |
fp@2171: 			                         ADVERTISED_Autoneg;
fp@2171: 		ecmd->advertising = hw->autoneg_advertised;
fp@2171: 	} else
fp@2171: 		if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
fp@2171: 			clear_bit(__E1000_RESETTING, &adapter->flags);
fp@2171: 			return -EINVAL;
fp@2171: 		}
fp@2171: 
fp@2171: 	/* reset the link */
fp@2171: 
fp@2171: 	if (netif_running(adapter->netdev)) {
fp@2171: 		e1000_down(adapter);
fp@2171: 		e1000_up(adapter);
fp@2171: 	} else
fp@2171: 		e1000_reset(adapter);
fp@2171: 
fp@2171: 	clear_bit(__E1000_RESETTING, &adapter->flags);
fp@2171: 	return 0;
fp@2171: }
fp@2171: 
fp@2171: static void e1000_get_pauseparam(struct net_device *netdev,
fp@2171: 				 struct ethtool_pauseparam *pause)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 
fp@2171: 	pause->autoneg =
fp@2171: 		(adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
fp@2171: 
fp@2171: 	if (hw->fc == E1000_FC_RX_PAUSE)
fp@2171: 		pause->rx_pause = 1;
fp@2171: 	else if (hw->fc == E1000_FC_TX_PAUSE)
fp@2171: 		pause->tx_pause = 1;
fp@2171: 	else if (hw->fc == E1000_FC_FULL) {
fp@2171: 		pause->rx_pause = 1;
fp@2171: 		pause->tx_pause = 1;
fp@2171: 	}
fp@2171: }
fp@2171: 
fp@2171: static int e1000_set_pauseparam(struct net_device *netdev,
fp@2171: 				struct ethtool_pauseparam *pause)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	int retval = 0;
fp@2171: 
fp@2171: 	if (adapter->ecdev)
fp@2171: 		return -EBUSY;
fp@2171: 
fp@2171: 	adapter->fc_autoneg = pause->autoneg;
fp@2171: 
fp@2171: 	while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
fp@2171: 		msleep(1);
fp@2171: 
fp@2171: 	if (pause->rx_pause && pause->tx_pause)
fp@2171: 		hw->fc = E1000_FC_FULL;
fp@2171: 	else if (pause->rx_pause && !pause->tx_pause)
fp@2171: 		hw->fc = E1000_FC_RX_PAUSE;
fp@2171: 	else if (!pause->rx_pause && pause->tx_pause)
fp@2171: 		hw->fc = E1000_FC_TX_PAUSE;
fp@2171: 	else if (!pause->rx_pause && !pause->tx_pause)
fp@2171: 		hw->fc = E1000_FC_NONE;
fp@2171: 
fp@2171: 	hw->original_fc = hw->fc;
fp@2171: 
fp@2171: 	if (adapter->fc_autoneg == AUTONEG_ENABLE) {
fp@2171: 		if (netif_running(adapter->netdev)) {
fp@2171: 			e1000_down(adapter);
fp@2171: 			e1000_up(adapter);
fp@2171: 		} else
fp@2171: 			e1000_reset(adapter);
fp@2171: 	} else
fp@2171: 		retval = ((hw->media_type == e1000_media_type_fiber) ?
fp@2171: 			  e1000_setup_link(hw) : e1000_force_mac_fc(hw));
fp@2171: 
fp@2171: 	clear_bit(__E1000_RESETTING, &adapter->flags);
fp@2171: 	return retval;
fp@2171: }
fp@2171: 
fp@2171: static u32 e1000_get_rx_csum(struct net_device *netdev)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	return adapter->rx_csum;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 
fp@2171: 	if (adapter->ecdev)
fp@2171: 		return -EBUSY;
fp@2171: 
fp@2171: 	adapter->rx_csum = data;
fp@2171: 
fp@2171: 	if (netif_running(netdev))
fp@2171: 		e1000_reinit_locked(adapter);
fp@2171: 	else
fp@2171: 		e1000_reset(adapter);
fp@2171: 	return 0;
fp@2171: }
fp@2171: 
fp@2171: static u32 e1000_get_tx_csum(struct net_device *netdev)
fp@2171: {
fp@2171: 	return (netdev->features & NETIF_F_HW_CSUM) != 0;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 
fp@2171: 	if (hw->mac_type < e1000_82543) {
fp@2171: 		if (!data)
fp@2171: 			return -EINVAL;
fp@2171: 		return 0;
fp@2171: 	}
fp@2171: 
fp@2171: 	if (data)
fp@2171: 		netdev->features |= NETIF_F_HW_CSUM;
fp@2171: 	else
fp@2171: 		netdev->features &= ~NETIF_F_HW_CSUM;
fp@2171: 
fp@2171: 	return 0;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_set_tso(struct net_device *netdev, u32 data)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 
fp@2171: 	if ((hw->mac_type < e1000_82544) ||
fp@2171: 	    (hw->mac_type == e1000_82547))
fp@2171: 		return data ? -EINVAL : 0;
fp@2171: 
fp@2171: 	if (data)
fp@2171: 		netdev->features |= NETIF_F_TSO;
fp@2171: 	else
fp@2171: 		netdev->features &= ~NETIF_F_TSO;
fp@2171: 
fp@2171: 	netdev->features &= ~NETIF_F_TSO6;
fp@2171: 
fp@2171: 	DPRINTK(PROBE, INFO, "TSO is %s\n", data ? "Enabled" : "Disabled");
fp@2171: 	adapter->tso_force = true;
fp@2171: 	return 0;
fp@2171: }
fp@2171: 
fp@2171: static u32 e1000_get_msglevel(struct net_device *netdev)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	return adapter->msg_enable;
fp@2171: }
fp@2171: 
fp@2171: static void e1000_set_msglevel(struct net_device *netdev, u32 data)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	adapter->msg_enable = data;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_get_regs_len(struct net_device *netdev)
fp@2171: {
fp@2171: #define E1000_REGS_LEN 32
fp@2171: 	return E1000_REGS_LEN * sizeof(u32);
fp@2171: }
fp@2171: 
fp@2171: static void e1000_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
fp@2171: 			   void *p)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	u32 *regs_buff = p;
fp@2171: 	u16 phy_data;
fp@2171: 
fp@2171: 	memset(p, 0, E1000_REGS_LEN * sizeof(u32));
fp@2171: 
fp@2171: 	regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
fp@2171: 
fp@2171: 	regs_buff[0]  = er32(CTRL);
fp@2171: 	regs_buff[1]  = er32(STATUS);
fp@2171: 
fp@2171: 	regs_buff[2]  = er32(RCTL);
fp@2171: 	regs_buff[3]  = er32(RDLEN);
fp@2171: 	regs_buff[4]  = er32(RDH);
fp@2171: 	regs_buff[5]  = er32(RDT);
fp@2171: 	regs_buff[6]  = er32(RDTR);
fp@2171: 
fp@2171: 	regs_buff[7]  = er32(TCTL);
fp@2171: 	regs_buff[8]  = er32(TDLEN);
fp@2171: 	regs_buff[9]  = er32(TDH);
fp@2171: 	regs_buff[10] = er32(TDT);
fp@2171: 	regs_buff[11] = er32(TIDV);
fp@2171: 
fp@2171: 	regs_buff[12] = hw->phy_type;  /* PHY type (IGP=1, M88=0) */
fp@2171: 	if (hw->phy_type == e1000_phy_igp) {
fp@2171: 		e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
fp@2171: 				    IGP01E1000_PHY_AGC_A);
fp@2171: 		e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A &
fp@2171: 				   IGP01E1000_PHY_PAGE_SELECT, &phy_data);
fp@2171: 		regs_buff[13] = (u32)phy_data; /* cable length */
fp@2171: 		e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
fp@2171: 				    IGP01E1000_PHY_AGC_B);
fp@2171: 		e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B &
fp@2171: 				   IGP01E1000_PHY_PAGE_SELECT, &phy_data);
fp@2171: 		regs_buff[14] = (u32)phy_data; /* cable length */
fp@2171: 		e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
fp@2171: 				    IGP01E1000_PHY_AGC_C);
fp@2171: 		e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C &
fp@2171: 				   IGP01E1000_PHY_PAGE_SELECT, &phy_data);
fp@2171: 		regs_buff[15] = (u32)phy_data; /* cable length */
fp@2171: 		e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
fp@2171: 				    IGP01E1000_PHY_AGC_D);
fp@2171: 		e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D &
fp@2171: 				   IGP01E1000_PHY_PAGE_SELECT, &phy_data);
fp@2171: 		regs_buff[16] = (u32)phy_data; /* cable length */
fp@2171: 		regs_buff[17] = 0; /* extended 10bt distance (not needed) */
fp@2171: 		e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
fp@2171: 		e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS &
fp@2171: 				   IGP01E1000_PHY_PAGE_SELECT, &phy_data);
fp@2171: 		regs_buff[18] = (u32)phy_data; /* cable polarity */
fp@2171: 		e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
fp@2171: 				    IGP01E1000_PHY_PCS_INIT_REG);
fp@2171: 		e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG &
fp@2171: 				   IGP01E1000_PHY_PAGE_SELECT, &phy_data);
fp@2171: 		regs_buff[19] = (u32)phy_data; /* cable polarity */
fp@2171: 		regs_buff[20] = 0; /* polarity correction enabled (always) */
fp@2171: 		regs_buff[22] = 0; /* phy receive errors (unavailable) */
fp@2171: 		regs_buff[23] = regs_buff[18]; /* mdix mode */
fp@2171: 		e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
fp@2171: 	} else {
fp@2171: 		e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
fp@2171: 		regs_buff[13] = (u32)phy_data; /* cable length */
fp@2171: 		regs_buff[14] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
fp@2171: 		regs_buff[15] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
fp@2171: 		regs_buff[16] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
fp@2171: 		e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
fp@2171: 		regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
fp@2171: 		regs_buff[18] = regs_buff[13]; /* cable polarity */
fp@2171: 		regs_buff[19] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
fp@2171: 		regs_buff[20] = regs_buff[17]; /* polarity correction */
fp@2171: 		/* phy receive errors */
fp@2171: 		regs_buff[22] = adapter->phy_stats.receive_errors;
fp@2171: 		regs_buff[23] = regs_buff[13]; /* mdix mode */
fp@2171: 	}
fp@2171: 	regs_buff[21] = adapter->phy_stats.idle_errors;  /* phy idle errors */
fp@2171: 	e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
fp@2171: 	regs_buff[24] = (u32)phy_data;  /* phy local receiver status */
fp@2171: 	regs_buff[25] = regs_buff[24];  /* phy remote receiver status */
fp@2171: 	if (hw->mac_type >= e1000_82540 &&
fp@2171: 	    hw->media_type == e1000_media_type_copper) {
fp@2171: 		regs_buff[26] = er32(MANC);
fp@2171: 	}
fp@2171: }
fp@2171: 
fp@2171: static int e1000_get_eeprom_len(struct net_device *netdev)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 
fp@2171: 	return hw->eeprom.word_size * 2;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_get_eeprom(struct net_device *netdev,
fp@2171: 			    struct ethtool_eeprom *eeprom, u8 *bytes)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	u16 *eeprom_buff;
fp@2171: 	int first_word, last_word;
fp@2171: 	int ret_val = 0;
fp@2171: 	u16 i;
fp@2171: 
fp@2171: 	if (eeprom->len == 0)
fp@2171: 		return -EINVAL;
fp@2171: 
fp@2171: 	eeprom->magic = hw->vendor_id | (hw->device_id << 16);
fp@2171: 
fp@2171: 	first_word = eeprom->offset >> 1;
fp@2171: 	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
fp@2171: 
fp@2171: 	eeprom_buff = kmalloc(sizeof(u16) *
fp@2171: 			(last_word - first_word + 1), GFP_KERNEL);
fp@2171: 	if (!eeprom_buff)
fp@2171: 		return -ENOMEM;
fp@2171: 
fp@2171: 	if (hw->eeprom.type == e1000_eeprom_spi)
fp@2171: 		ret_val = e1000_read_eeprom(hw, first_word,
fp@2171: 					    last_word - first_word + 1,
fp@2171: 					    eeprom_buff);
fp@2171: 	else {
fp@2171: 		for (i = 0; i < last_word - first_word + 1; i++) {
fp@2171: 			ret_val = e1000_read_eeprom(hw, first_word + i, 1,
fp@2171: 						    &eeprom_buff[i]);
fp@2171: 			if (ret_val)
fp@2171: 				break;
fp@2171: 		}
fp@2171: 	}
fp@2171: 
fp@2171: 	/* Device's eeprom is always little-endian, word addressable */
fp@2171: 	for (i = 0; i < last_word - first_word + 1; i++)
fp@2171: 		le16_to_cpus(&eeprom_buff[i]);
fp@2171: 
fp@2171: 	memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
fp@2171: 			eeprom->len);
fp@2171: 	kfree(eeprom_buff);
fp@2171: 
fp@2171: 	return ret_val;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_set_eeprom(struct net_device *netdev,
fp@2171: 			    struct ethtool_eeprom *eeprom, u8 *bytes)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	u16 *eeprom_buff;
fp@2171: 	void *ptr;
fp@2171: 	int max_len, first_word, last_word, ret_val = 0;
fp@2171: 	u16 i;
fp@2171: 
fp@2171: 	if (eeprom->len == 0)
fp@2171: 		return -EOPNOTSUPP;
fp@2171: 
fp@2171: 	if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
fp@2171: 		return -EFAULT;
fp@2171: 
fp@2171: 	max_len = hw->eeprom.word_size * 2;
fp@2171: 
fp@2171: 	first_word = eeprom->offset >> 1;
fp@2171: 	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
fp@2171: 	eeprom_buff = kmalloc(max_len, GFP_KERNEL);
fp@2171: 	if (!eeprom_buff)
fp@2171: 		return -ENOMEM;
fp@2171: 
fp@2171: 	ptr = (void *)eeprom_buff;
fp@2171: 
fp@2171: 	if (eeprom->offset & 1) {
fp@2171: 		/* need read/modify/write of first changed EEPROM word */
fp@2171: 		/* only the second byte of the word is being modified */
fp@2171: 		ret_val = e1000_read_eeprom(hw, first_word, 1,
fp@2171: 					    &eeprom_buff[0]);
fp@2171: 		ptr++;
fp@2171: 	}
fp@2171: 	if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
fp@2171: 		/* need read/modify/write of last changed EEPROM word */
fp@2171: 		/* only the first byte of the word is being modified */
fp@2171: 		ret_val = e1000_read_eeprom(hw, last_word, 1,
fp@2171: 		                  &eeprom_buff[last_word - first_word]);
fp@2171: 	}
fp@2171: 
fp@2171: 	/* Device's eeprom is always little-endian, word addressable */
fp@2171: 	for (i = 0; i < last_word - first_word + 1; i++)
fp@2171: 		le16_to_cpus(&eeprom_buff[i]);
fp@2171: 
fp@2171: 	memcpy(ptr, bytes, eeprom->len);
fp@2171: 
fp@2171: 	for (i = 0; i < last_word - first_word + 1; i++)
fp@2171: 		eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
fp@2171: 
fp@2171: 	ret_val = e1000_write_eeprom(hw, first_word,
fp@2171: 				     last_word - first_word + 1, eeprom_buff);
fp@2171: 
fp@2171: 	/* Update the checksum over the first part of the EEPROM if needed */
fp@2171: 	if ((ret_val == 0) && (first_word <= EEPROM_CHECKSUM_REG))
fp@2171: 		e1000_update_eeprom_checksum(hw);
fp@2171: 
fp@2171: 	kfree(eeprom_buff);
fp@2171: 	return ret_val;
fp@2171: }
fp@2171: 
fp@2171: static void e1000_get_drvinfo(struct net_device *netdev,
fp@2171: 			      struct ethtool_drvinfo *drvinfo)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	char firmware_version[32];
fp@2171: 
fp@2171: 	strncpy(drvinfo->driver,  e1000_driver_name, 32);
fp@2171: 	strncpy(drvinfo->version, e1000_driver_version, 32);
fp@2171: 
fp@2171: 	sprintf(firmware_version, "N/A");
fp@2171: 	strncpy(drvinfo->fw_version, firmware_version, 32);
fp@2171: 	strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
fp@2171: 	drvinfo->regdump_len = e1000_get_regs_len(netdev);
fp@2171: 	drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
fp@2171: }
fp@2171: 
fp@2171: static void e1000_get_ringparam(struct net_device *netdev,
fp@2171: 				struct ethtool_ringparam *ring)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	e1000_mac_type mac_type = hw->mac_type;
fp@2171: 	struct e1000_tx_ring *txdr = adapter->tx_ring;
fp@2171: 	struct e1000_rx_ring *rxdr = adapter->rx_ring;
fp@2171: 
fp@2171: 	ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
fp@2171: 		E1000_MAX_82544_RXD;
fp@2171: 	ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD :
fp@2171: 		E1000_MAX_82544_TXD;
fp@2171: 	ring->rx_mini_max_pending = 0;
fp@2171: 	ring->rx_jumbo_max_pending = 0;
fp@2171: 	ring->rx_pending = rxdr->count;
fp@2171: 	ring->tx_pending = txdr->count;
fp@2171: 	ring->rx_mini_pending = 0;
fp@2171: 	ring->rx_jumbo_pending = 0;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_set_ringparam(struct net_device *netdev,
fp@2171: 			       struct ethtool_ringparam *ring)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	e1000_mac_type mac_type = hw->mac_type;
fp@2171: 	struct e1000_tx_ring *txdr, *tx_old;
fp@2171: 	struct e1000_rx_ring *rxdr, *rx_old;
fp@2171: 	int i, err;
fp@2171: 
fp@2171: 	if (adapter->ecdev)
fp@2171: 		return -EBUSY;
fp@2171: 
fp@2171: 	if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
fp@2171: 		return -EINVAL;
fp@2171: 
fp@2171: 	while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
fp@2171: 		msleep(1);
fp@2171: 
fp@2171: 	if (netif_running(adapter->netdev))
fp@2171: 		e1000_down(adapter);
fp@2171: 
fp@2171: 	tx_old = adapter->tx_ring;
fp@2171: 	rx_old = adapter->rx_ring;
fp@2171: 
fp@2171: 	err = -ENOMEM;
fp@2171: 	txdr = kcalloc(adapter->num_tx_queues, sizeof(struct e1000_tx_ring), GFP_KERNEL);
fp@2171: 	if (!txdr)
fp@2171: 		goto err_alloc_tx;
fp@2171: 
fp@2171: 	rxdr = kcalloc(adapter->num_rx_queues, sizeof(struct e1000_rx_ring), GFP_KERNEL);
fp@2171: 	if (!rxdr)
fp@2171: 		goto err_alloc_rx;
fp@2171: 
fp@2171: 	adapter->tx_ring = txdr;
fp@2171: 	adapter->rx_ring = rxdr;
fp@2171: 
fp@2171: 	rxdr->count = max(ring->rx_pending,(u32)E1000_MIN_RXD);
fp@2171: 	rxdr->count = min(rxdr->count,(u32)(mac_type < e1000_82544 ?
fp@2171: 		E1000_MAX_RXD : E1000_MAX_82544_RXD));
fp@2171: 	rxdr->count = ALIGN(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE);
fp@2171: 
fp@2171: 	txdr->count = max(ring->tx_pending,(u32)E1000_MIN_TXD);
fp@2171: 	txdr->count = min(txdr->count,(u32)(mac_type < e1000_82544 ?
fp@2171: 		E1000_MAX_TXD : E1000_MAX_82544_TXD));
fp@2171: 	txdr->count = ALIGN(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
fp@2171: 
fp@2171: 	for (i = 0; i < adapter->num_tx_queues; i++)
fp@2171: 		txdr[i].count = txdr->count;
fp@2171: 	for (i = 0; i < adapter->num_rx_queues; i++)
fp@2171: 		rxdr[i].count = rxdr->count;
fp@2171: 
fp@2171: 	if (netif_running(adapter->netdev)) {
fp@2171: 		/* Try to get new resources before deleting old */
fp@2171: 		err = e1000_setup_all_rx_resources(adapter);
fp@2171: 		if (err)
fp@2171: 			goto err_setup_rx;
fp@2171: 		err = e1000_setup_all_tx_resources(adapter);
fp@2171: 		if (err)
fp@2171: 			goto err_setup_tx;
fp@2171: 
fp@2171: 		/* save the new, restore the old in order to free it,
fp@2171: 		 * then restore the new back again */
fp@2171: 
fp@2171: 		adapter->rx_ring = rx_old;
fp@2171: 		adapter->tx_ring = tx_old;
fp@2171: 		e1000_free_all_rx_resources(adapter);
fp@2171: 		e1000_free_all_tx_resources(adapter);
fp@2171: 		kfree(tx_old);
fp@2171: 		kfree(rx_old);
fp@2171: 		adapter->rx_ring = rxdr;
fp@2171: 		adapter->tx_ring = txdr;
fp@2171: 		err = e1000_up(adapter);
fp@2171: 		if (err)
fp@2171: 			goto err_setup;
fp@2171: 	}
fp@2171: 
fp@2171: 	clear_bit(__E1000_RESETTING, &adapter->flags);
fp@2171: 	return 0;
fp@2171: err_setup_tx:
fp@2171: 	e1000_free_all_rx_resources(adapter);
fp@2171: err_setup_rx:
fp@2171: 	adapter->rx_ring = rx_old;
fp@2171: 	adapter->tx_ring = tx_old;
fp@2171: 	kfree(rxdr);
fp@2171: err_alloc_rx:
fp@2171: 	kfree(txdr);
fp@2171: err_alloc_tx:
fp@2171: 	e1000_up(adapter);
fp@2171: err_setup:
fp@2171: 	clear_bit(__E1000_RESETTING, &adapter->flags);
fp@2171: 	return err;
fp@2171: }
fp@2171: 
fp@2171: static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data, int reg,
fp@2171: 			     u32 mask, u32 write)
fp@2171: {
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	static const u32 test[] =
fp@2171: 		{0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
fp@2171: 	u8 __iomem *address = hw->hw_addr + reg;
fp@2171: 	u32 read;
fp@2171: 	int i;
fp@2171: 
fp@2171: 	for (i = 0; i < ARRAY_SIZE(test); i++) {
fp@2171: 		writel(write & test[i], address);
fp@2171: 		read = readl(address);
fp@2171: 		if (read != (write & test[i] & mask)) {
fp@2171: 			DPRINTK(DRV, ERR, "pattern test reg %04X failed: "
fp@2171: 				"got 0x%08X expected 0x%08X\n",
fp@2171: 				reg, read, (write & test[i] & mask));
fp@2171: 			*data = reg;
fp@2171: 			return true;
fp@2171: 		}
fp@2171: 	}
fp@2171: 	return false;
fp@2171: }
fp@2171: 
fp@2171: static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data, int reg,
fp@2171: 			      u32 mask, u32 write)
fp@2171: {
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	u8 __iomem *address = hw->hw_addr + reg;
fp@2171: 	u32 read;
fp@2171: 
fp@2171: 	writel(write & mask, address);
fp@2171: 	read = readl(address);
fp@2171: 	if ((read & mask) != (write & mask)) {
fp@2171: 		DPRINTK(DRV, ERR, "set/check reg %04X test failed: "
fp@2171: 			"got 0x%08X expected 0x%08X\n",
fp@2171: 			reg, (read & mask), (write & mask));
fp@2171: 		*data = reg;
fp@2171: 		return true;
fp@2171: 	}
fp@2171: 	return false;
fp@2171: }
fp@2171: 
fp@2171: #define REG_PATTERN_TEST(reg, mask, write)			     \
fp@2171: 	do {							     \
fp@2171: 		if (reg_pattern_test(adapter, data,		     \
fp@2171: 			     (hw->mac_type >= e1000_82543)   \
fp@2171: 			     ? E1000_##reg : E1000_82542_##reg,	     \
fp@2171: 			     mask, write))			     \
fp@2171: 			return 1;				     \
fp@2171: 	} while (0)
fp@2171: 
fp@2171: #define REG_SET_AND_CHECK(reg, mask, write)			     \
fp@2171: 	do {							     \
fp@2171: 		if (reg_set_and_check(adapter, data,		     \
fp@2171: 			      (hw->mac_type >= e1000_82543)  \
fp@2171: 			      ? E1000_##reg : E1000_82542_##reg,     \
fp@2171: 			      mask, write))			     \
fp@2171: 			return 1;				     \
fp@2171: 	} while (0)
fp@2171: 
fp@2171: static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
fp@2171: {
fp@2171: 	u32 value, before, after;
fp@2171: 	u32 i, toggle;
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 
fp@2171: 	/* The status register is Read Only, so a write should fail.
fp@2171: 	 * Some bits that get toggled are ignored.
fp@2171: 	 */
fp@2171: 
fp@2171: 	/* there are several bits on newer hardware that are r/w */
fp@2171: 	toggle = 0xFFFFF833;
fp@2171: 
fp@2171: 	before = er32(STATUS);
fp@2171: 	value = (er32(STATUS) & toggle);
fp@2171: 	ew32(STATUS, toggle);
fp@2171: 	after = er32(STATUS) & toggle;
fp@2171: 	if (value != after) {
fp@2171: 		DPRINTK(DRV, ERR, "failed STATUS register test got: "
fp@2171: 		        "0x%08X expected: 0x%08X\n", after, value);
fp@2171: 		*data = 1;
fp@2171: 		return 1;
fp@2171: 	}
fp@2171: 	/* restore previous status */
fp@2171: 	ew32(STATUS, before);
fp@2171: 
fp@2171: 	REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
fp@2171: 	REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
fp@2171: 	REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF);
fp@2171: 	REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF);
fp@2171: 
fp@2171: 	REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF);
fp@2171: 	REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
fp@2171: 	REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF);
fp@2171: 	REG_PATTERN_TEST(RDH, 0x0000FFFF, 0x0000FFFF);
fp@2171: 	REG_PATTERN_TEST(RDT, 0x0000FFFF, 0x0000FFFF);
fp@2171: 	REG_PATTERN_TEST(FCRTH, 0x0000FFF8, 0x0000FFF8);
fp@2171: 	REG_PATTERN_TEST(FCTTV, 0x0000FFFF, 0x0000FFFF);
fp@2171: 	REG_PATTERN_TEST(TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
fp@2171: 	REG_PATTERN_TEST(TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
fp@2171: 	REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF);
fp@2171: 
fp@2171: 	REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000);
fp@2171: 
fp@2171: 	before = 0x06DFB3FE;
fp@2171: 	REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB);
fp@2171: 	REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);
fp@2171: 
fp@2171: 	if (hw->mac_type >= e1000_82543) {
fp@2171: 
fp@2171: 		REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF);
fp@2171: 		REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
fp@2171: 		REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF);
fp@2171: 		REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
fp@2171: 		REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
fp@2171: 		value = E1000_RAR_ENTRIES;
fp@2171: 		for (i = 0; i < value; i++) {
fp@2171: 			REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF,
fp@2171: 			                 0xFFFFFFFF);
fp@2171: 		}
fp@2171: 
fp@2171: 	} else {
fp@2171: 
fp@2171: 		REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF);
fp@2171: 		REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF);
fp@2171: 		REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF);
fp@2171: 		REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF);
fp@2171: 
fp@2171: 	}
fp@2171: 
fp@2171: 	value = E1000_MC_TBL_SIZE;
fp@2171: 	for (i = 0; i < value; i++)
fp@2171: 		REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
fp@2171: 
fp@2171: 	*data = 0;
fp@2171: 	return 0;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
fp@2171: {
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	u16 temp;
fp@2171: 	u16 checksum = 0;
fp@2171: 	u16 i;
fp@2171: 
fp@2171: 	*data = 0;
fp@2171: 	/* Read and add up the contents of the EEPROM */
fp@2171: 	for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
fp@2171: 		if ((e1000_read_eeprom(hw, i, 1, &temp)) < 0) {
fp@2171: 			*data = 1;
fp@2171: 			break;
fp@2171: 		}
fp@2171: 		checksum += temp;
fp@2171: 	}
fp@2171: 
fp@2171: 	/* If Checksum is not Correct return error else test passed */
fp@2171: 	if ((checksum != (u16)EEPROM_SUM) && !(*data))
fp@2171: 		*data = 2;
fp@2171: 
fp@2171: 	return *data;
fp@2171: }
fp@2171: 
fp@2171: static irqreturn_t e1000_test_intr(int irq, void *data)
fp@2171: {
fp@2171: 	struct net_device *netdev = (struct net_device *)data;
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 
fp@2171: 	adapter->test_icr |= er32(ICR);
fp@2171: 
fp@2171: 	return IRQ_HANDLED;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
fp@2171: {
fp@2171: 	struct net_device *netdev = adapter->netdev;
fp@2171: 	u32 mask, i = 0;
fp@2171: 	bool shared_int = true;
fp@2171: 	u32 irq = adapter->pdev->irq;
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 
fp@2171: 	*data = 0;
fp@2171: 
fp@2171: 	/* NOTE: we don't test MSI interrupts here, yet */
fp@2171: 	/* Hook up test interrupt handler just for this test */
fp@2171: 	if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
fp@2171: 	                 netdev))
fp@2171: 		shared_int = false;
fp@2171: 	else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED,
fp@2171: 	         netdev->name, netdev)) {
fp@2171: 		*data = 1;
fp@2171: 		return -1;
fp@2171: 	}
fp@2171: 	DPRINTK(HW, INFO, "testing %s interrupt\n",
fp@2171: 	        (shared_int ? "shared" : "unshared"));
fp@2171: 
fp@2171: 	/* Disable all the interrupts */
fp@2171: 	ew32(IMC, 0xFFFFFFFF);
fp@2171: 	msleep(10);
fp@2171: 
fp@2171: 	/* Test each interrupt */
fp@2171: 	for (; i < 10; i++) {
fp@2171: 
fp@2171: 		/* Interrupt to test */
fp@2171: 		mask = 1 << i;
fp@2171: 
fp@2171: 		if (!shared_int) {
fp@2171: 			/* Disable the interrupt to be reported in
fp@2171: 			 * the cause register and then force the same
fp@2171: 			 * interrupt and see if one gets posted.  If
fp@2171: 			 * an interrupt was posted to the bus, the
fp@2171: 			 * test failed.
fp@2171: 			 */
fp@2171: 			adapter->test_icr = 0;
fp@2171: 			ew32(IMC, mask);
fp@2171: 			ew32(ICS, mask);
fp@2171: 			msleep(10);
fp@2171: 
fp@2171: 			if (adapter->test_icr & mask) {
fp@2171: 				*data = 3;
fp@2171: 				break;
fp@2171: 			}
fp@2171: 		}
fp@2171: 
fp@2171: 		/* Enable the interrupt to be reported in
fp@2171: 		 * the cause register and then force the same
fp@2171: 		 * interrupt and see if one gets posted.  If
fp@2171: 		 * an interrupt was not posted to the bus, the
fp@2171: 		 * test failed.
fp@2171: 		 */
fp@2171: 		adapter->test_icr = 0;
fp@2171: 		ew32(IMS, mask);
fp@2171: 		ew32(ICS, mask);
fp@2171: 		msleep(10);
fp@2171: 
fp@2171: 		if (!(adapter->test_icr & mask)) {
fp@2171: 			*data = 4;
fp@2171: 			break;
fp@2171: 		}
fp@2171: 
fp@2171: 		if (!shared_int) {
fp@2171: 			/* Disable the other interrupts to be reported in
fp@2171: 			 * the cause register and then force the other
fp@2171: 			 * interrupts and see if any get posted.  If
fp@2171: 			 * an interrupt was posted to the bus, the
fp@2171: 			 * test failed.
fp@2171: 			 */
fp@2171: 			adapter->test_icr = 0;
fp@2171: 			ew32(IMC, ~mask & 0x00007FFF);
fp@2171: 			ew32(ICS, ~mask & 0x00007FFF);
fp@2171: 			msleep(10);
fp@2171: 
fp@2171: 			if (adapter->test_icr) {
fp@2171: 				*data = 5;
fp@2171: 				break;
fp@2171: 			}
fp@2171: 		}
fp@2171: 	}
fp@2171: 
fp@2171: 	/* Disable all the interrupts */
fp@2171: 	ew32(IMC, 0xFFFFFFFF);
fp@2171: 	msleep(10);
fp@2171: 
fp@2171: 	/* Unhook test interrupt handler */
fp@2171: 	free_irq(irq, netdev);
fp@2171: 
fp@2171: 	return *data;
fp@2171: }
fp@2171: 
fp@2171: static void e1000_free_desc_rings(struct e1000_adapter *adapter)
fp@2171: {
fp@2171: 	struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
fp@2171: 	struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
fp@2171: 	struct pci_dev *pdev = adapter->pdev;
fp@2171: 	int i;
fp@2171: 
fp@2171: 	if (txdr->desc && txdr->buffer_info) {
fp@2171: 		for (i = 0; i < txdr->count; i++) {
fp@2171: 			if (txdr->buffer_info[i].dma)
fp@2171: 				pci_unmap_single(pdev, txdr->buffer_info[i].dma,
fp@2171: 						 txdr->buffer_info[i].length,
fp@2171: 						 PCI_DMA_TODEVICE);
fp@2171: 			if (txdr->buffer_info[i].skb)
fp@2171: 				dev_kfree_skb(txdr->buffer_info[i].skb);
fp@2171: 		}
fp@2171: 	}
fp@2171: 
fp@2171: 	if (rxdr->desc && rxdr->buffer_info) {
fp@2171: 		for (i = 0; i < rxdr->count; i++) {
fp@2171: 			if (rxdr->buffer_info[i].dma)
fp@2171: 				pci_unmap_single(pdev, rxdr->buffer_info[i].dma,
fp@2171: 						 rxdr->buffer_info[i].length,
fp@2171: 						 PCI_DMA_FROMDEVICE);
fp@2171: 			if (rxdr->buffer_info[i].skb)
fp@2171: 				dev_kfree_skb(rxdr->buffer_info[i].skb);
fp@2171: 		}
fp@2171: 	}
fp@2171: 
fp@2171: 	if (txdr->desc) {
fp@2171: 		pci_free_consistent(pdev, txdr->size, txdr->desc, txdr->dma);
fp@2171: 		txdr->desc = NULL;
fp@2171: 	}
fp@2171: 	if (rxdr->desc) {
fp@2171: 		pci_free_consistent(pdev, rxdr->size, rxdr->desc, rxdr->dma);
fp@2171: 		rxdr->desc = NULL;
fp@2171: 	}
fp@2171: 
fp@2171: 	kfree(txdr->buffer_info);
fp@2171: 	txdr->buffer_info = NULL;
fp@2171: 	kfree(rxdr->buffer_info);
fp@2171: 	rxdr->buffer_info = NULL;
fp@2171: 
fp@2171: 	return;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
fp@2171: {
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
fp@2171: 	struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
fp@2171: 	struct pci_dev *pdev = adapter->pdev;
fp@2171: 	u32 rctl;
fp@2171: 	int i, ret_val;
fp@2171: 
fp@2171: 	/* Setup Tx descriptor ring and Tx buffers */
fp@2171: 
fp@2171: 	if (!txdr->count)
fp@2171: 		txdr->count = E1000_DEFAULT_TXD;
fp@2171: 
fp@2171: 	txdr->buffer_info = kcalloc(txdr->count, sizeof(struct e1000_buffer),
fp@2171: 				    GFP_KERNEL);
fp@2171: 	if (!txdr->buffer_info) {
fp@2171: 		ret_val = 1;
fp@2171: 		goto err_nomem;
fp@2171: 	}
fp@2171: 
fp@2171: 	txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
fp@2171: 	txdr->size = ALIGN(txdr->size, 4096);
fp@2171: 	txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
fp@2171: 	if (!txdr->desc) {
fp@2171: 		ret_val = 2;
fp@2171: 		goto err_nomem;
fp@2171: 	}
fp@2171: 	memset(txdr->desc, 0, txdr->size);
fp@2171: 	txdr->next_to_use = txdr->next_to_clean = 0;
fp@2171: 
fp@2171: 	ew32(TDBAL, ((u64)txdr->dma & 0x00000000FFFFFFFF));
fp@2171: 	ew32(TDBAH, ((u64)txdr->dma >> 32));
fp@2171: 	ew32(TDLEN, txdr->count * sizeof(struct e1000_tx_desc));
fp@2171: 	ew32(TDH, 0);
fp@2171: 	ew32(TDT, 0);
fp@2171: 	ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN |
fp@2171: 	     E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
fp@2171: 	     E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
fp@2171: 
fp@2171: 	for (i = 0; i < txdr->count; i++) {
fp@2171: 		struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i);
fp@2171: 		struct sk_buff *skb;
fp@2171: 		unsigned int size = 1024;
fp@2171: 
fp@2171: 		skb = alloc_skb(size, GFP_KERNEL);
fp@2171: 		if (!skb) {
fp@2171: 			ret_val = 3;
fp@2171: 			goto err_nomem;
fp@2171: 		}
fp@2171: 		skb_put(skb, size);
fp@2171: 		txdr->buffer_info[i].skb = skb;
fp@2171: 		txdr->buffer_info[i].length = skb->len;
fp@2171: 		txdr->buffer_info[i].dma =
fp@2171: 			pci_map_single(pdev, skb->data, skb->len,
fp@2171: 				       PCI_DMA_TODEVICE);
fp@2171: 		tx_desc->buffer_addr = cpu_to_le64(txdr->buffer_info[i].dma);
fp@2171: 		tx_desc->lower.data = cpu_to_le32(skb->len);
fp@2171: 		tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
fp@2171: 						   E1000_TXD_CMD_IFCS |
fp@2171: 						   E1000_TXD_CMD_RPS);
fp@2171: 		tx_desc->upper.data = 0;
fp@2171: 	}
fp@2171: 
fp@2171: 	/* Setup Rx descriptor ring and Rx buffers */
fp@2171: 
fp@2171: 	if (!rxdr->count)
fp@2171: 		rxdr->count = E1000_DEFAULT_RXD;
fp@2171: 
fp@2171: 	rxdr->buffer_info = kcalloc(rxdr->count, sizeof(struct e1000_buffer),
fp@2171: 				    GFP_KERNEL);
fp@2171: 	if (!rxdr->buffer_info) {
fp@2171: 		ret_val = 4;
fp@2171: 		goto err_nomem;
fp@2171: 	}
fp@2171: 
fp@2171: 	rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
fp@2171: 	rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
fp@2171: 	if (!rxdr->desc) {
fp@2171: 		ret_val = 5;
fp@2171: 		goto err_nomem;
fp@2171: 	}
fp@2171: 	memset(rxdr->desc, 0, rxdr->size);
fp@2171: 	rxdr->next_to_use = rxdr->next_to_clean = 0;
fp@2171: 
fp@2171: 	rctl = er32(RCTL);
fp@2171: 	ew32(RCTL, rctl & ~E1000_RCTL_EN);
fp@2171: 	ew32(RDBAL, ((u64)rxdr->dma & 0xFFFFFFFF));
fp@2171: 	ew32(RDBAH, ((u64)rxdr->dma >> 32));
fp@2171: 	ew32(RDLEN, rxdr->size);
fp@2171: 	ew32(RDH, 0);
fp@2171: 	ew32(RDT, 0);
fp@2171: 	rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
fp@2171: 		E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
fp@2171: 		(hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
fp@2171: 	ew32(RCTL, rctl);
fp@2171: 
fp@2171: 	for (i = 0; i < rxdr->count; i++) {
fp@2171: 		struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i);
fp@2171: 		struct sk_buff *skb;
fp@2171: 
fp@2171: 		skb = alloc_skb(E1000_RXBUFFER_2048 + NET_IP_ALIGN, GFP_KERNEL);
fp@2171: 		if (!skb) {
fp@2171: 			ret_val = 6;
fp@2171: 			goto err_nomem;
fp@2171: 		}
fp@2171: 		skb_reserve(skb, NET_IP_ALIGN);
fp@2171: 		rxdr->buffer_info[i].skb = skb;
fp@2171: 		rxdr->buffer_info[i].length = E1000_RXBUFFER_2048;
fp@2171: 		rxdr->buffer_info[i].dma =
fp@2171: 			pci_map_single(pdev, skb->data, E1000_RXBUFFER_2048,
fp@2171: 				       PCI_DMA_FROMDEVICE);
fp@2171: 		rx_desc->buffer_addr = cpu_to_le64(rxdr->buffer_info[i].dma);
fp@2171: 		memset(skb->data, 0x00, skb->len);
fp@2171: 	}
fp@2171: 
fp@2171: 	return 0;
fp@2171: 
fp@2171: err_nomem:
fp@2171: 	e1000_free_desc_rings(adapter);
fp@2171: 	return ret_val;
fp@2171: }
fp@2171: 
fp@2171: static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
fp@2171: {
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 
fp@2171: 	/* Write out to PHY registers 29 and 30 to disable the Receiver. */
fp@2171: 	e1000_write_phy_reg(hw, 29, 0x001F);
fp@2171: 	e1000_write_phy_reg(hw, 30, 0x8FFC);
fp@2171: 	e1000_write_phy_reg(hw, 29, 0x001A);
fp@2171: 	e1000_write_phy_reg(hw, 30, 0x8FF0);
fp@2171: }
fp@2171: 
fp@2171: static void e1000_phy_reset_clk_and_crs(struct e1000_adapter *adapter)
fp@2171: {
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	u16 phy_reg;
fp@2171: 
fp@2171: 	/* Because we reset the PHY above, we need to re-force TX_CLK in the
fp@2171: 	 * Extended PHY Specific Control Register to 25MHz clock.  This
fp@2171: 	 * value defaults back to a 2.5MHz clock when the PHY is reset.
fp@2171: 	 */
fp@2171: 	e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
fp@2171: 	phy_reg |= M88E1000_EPSCR_TX_CLK_25;
fp@2171: 	e1000_write_phy_reg(hw,
fp@2171: 		M88E1000_EXT_PHY_SPEC_CTRL, phy_reg);
fp@2171: 
fp@2171: 	/* In addition, because of the s/w reset above, we need to enable
fp@2171: 	 * CRS on TX.  This must be set for both full and half duplex
fp@2171: 	 * operation.
fp@2171: 	 */
fp@2171: 	e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
fp@2171: 	phy_reg |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
fp@2171: 	e1000_write_phy_reg(hw,
fp@2171: 		M88E1000_PHY_SPEC_CTRL, phy_reg);
fp@2171: }
fp@2171: 
fp@2171: static int e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter)
fp@2171: {
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	u32 ctrl_reg;
fp@2171: 	u16 phy_reg;
fp@2171: 
fp@2171: 	/* Setup the Device Control Register for PHY loopback test. */
fp@2171: 
fp@2171: 	ctrl_reg = er32(CTRL);
fp@2171: 	ctrl_reg |= (E1000_CTRL_ILOS |		/* Invert Loss-Of-Signal */
fp@2171: 		     E1000_CTRL_FRCSPD |	/* Set the Force Speed Bit */
fp@2171: 		     E1000_CTRL_FRCDPX |	/* Set the Force Duplex Bit */
fp@2171: 		     E1000_CTRL_SPD_1000 |	/* Force Speed to 1000 */
fp@2171: 		     E1000_CTRL_FD);		/* Force Duplex to FULL */
fp@2171: 
fp@2171: 	ew32(CTRL, ctrl_reg);
fp@2171: 
fp@2171: 	/* Read the PHY Specific Control Register (0x10) */
fp@2171: 	e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
fp@2171: 
fp@2171: 	/* Clear Auto-Crossover bits in PHY Specific Control Register
fp@2171: 	 * (bits 6:5).
fp@2171: 	 */
fp@2171: 	phy_reg &= ~M88E1000_PSCR_AUTO_X_MODE;
fp@2171: 	e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_reg);
fp@2171: 
fp@2171: 	/* Perform software reset on the PHY */
fp@2171: 	e1000_phy_reset(hw);
fp@2171: 
fp@2171: 	/* Have to setup TX_CLK and TX_CRS after software reset */
fp@2171: 	e1000_phy_reset_clk_and_crs(adapter);
fp@2171: 
fp@2171: 	e1000_write_phy_reg(hw, PHY_CTRL, 0x8100);
fp@2171: 
fp@2171: 	/* Wait for reset to complete. */
fp@2171: 	udelay(500);
fp@2171: 
fp@2171: 	/* Have to setup TX_CLK and TX_CRS after software reset */
fp@2171: 	e1000_phy_reset_clk_and_crs(adapter);
fp@2171: 
fp@2171: 	/* Write out to PHY registers 29 and 30 to disable the Receiver. */
fp@2171: 	e1000_phy_disable_receiver(adapter);
fp@2171: 
fp@2171: 	/* Set the loopback bit in the PHY control register. */
fp@2171: 	e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
fp@2171: 	phy_reg |= MII_CR_LOOPBACK;
fp@2171: 	e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
fp@2171: 
fp@2171: 	/* Setup TX_CLK and TX_CRS one more time. */
fp@2171: 	e1000_phy_reset_clk_and_crs(adapter);
fp@2171: 
fp@2171: 	/* Check Phy Configuration */
fp@2171: 	e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
fp@2171: 	if (phy_reg != 0x4100)
fp@2171: 		 return 9;
fp@2171: 
fp@2171: 	e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
fp@2171: 	if (phy_reg != 0x0070)
fp@2171: 		return 10;
fp@2171: 
fp@2171: 	e1000_read_phy_reg(hw, 29, &phy_reg);
fp@2171: 	if (phy_reg != 0x001A)
fp@2171: 		return 11;
fp@2171: 
fp@2171: 	return 0;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
fp@2171: {
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	u32 ctrl_reg = 0;
fp@2171: 	u32 stat_reg = 0;
fp@2171: 
fp@2171: 	hw->autoneg = false;
fp@2171: 
fp@2171: 	if (hw->phy_type == e1000_phy_m88) {
fp@2171: 		/* Auto-MDI/MDIX Off */
fp@2171: 		e1000_write_phy_reg(hw,
fp@2171: 				    M88E1000_PHY_SPEC_CTRL, 0x0808);
fp@2171: 		/* reset to update Auto-MDI/MDIX */
fp@2171: 		e1000_write_phy_reg(hw, PHY_CTRL, 0x9140);
fp@2171: 		/* autoneg off */
fp@2171: 		e1000_write_phy_reg(hw, PHY_CTRL, 0x8140);
fp@2171: 	}
fp@2171: 
fp@2171: 	ctrl_reg = er32(CTRL);
fp@2171: 
fp@2171: 	/* force 1000, set loopback */
fp@2171: 	e1000_write_phy_reg(hw, PHY_CTRL, 0x4140);
fp@2171: 
fp@2171: 	/* Now set up the MAC to the same speed/duplex as the PHY. */
fp@2171: 	ctrl_reg = er32(CTRL);
fp@2171: 	ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
fp@2171: 	ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
fp@2171: 			E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
fp@2171: 			E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
fp@2171: 			E1000_CTRL_FD);	 /* Force Duplex to FULL */
fp@2171: 
fp@2171: 	if (hw->media_type == e1000_media_type_copper &&
fp@2171: 	   hw->phy_type == e1000_phy_m88)
fp@2171: 		ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
fp@2171: 	else {
fp@2171: 		/* Set the ILOS bit on the fiber Nic is half
fp@2171: 		 * duplex link is detected. */
fp@2171: 		stat_reg = er32(STATUS);
fp@2171: 		if ((stat_reg & E1000_STATUS_FD) == 0)
fp@2171: 			ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
fp@2171: 	}
fp@2171: 
fp@2171: 	ew32(CTRL, ctrl_reg);
fp@2171: 
fp@2171: 	/* Disable the receiver on the PHY so when a cable is plugged in, the
fp@2171: 	 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
fp@2171: 	 */
fp@2171: 	if (hw->phy_type == e1000_phy_m88)
fp@2171: 		e1000_phy_disable_receiver(adapter);
fp@2171: 
fp@2171: 	udelay(500);
fp@2171: 
fp@2171: 	return 0;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_set_phy_loopback(struct e1000_adapter *adapter)
fp@2171: {
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	u16 phy_reg = 0;
fp@2171: 	u16 count = 0;
fp@2171: 
fp@2171: 	switch (hw->mac_type) {
fp@2171: 	case e1000_82543:
fp@2171: 		if (hw->media_type == e1000_media_type_copper) {
fp@2171: 			/* Attempt to setup Loopback mode on Non-integrated PHY.
fp@2171: 			 * Some PHY registers get corrupted at random, so
fp@2171: 			 * attempt this 10 times.
fp@2171: 			 */
fp@2171: 			while (e1000_nonintegrated_phy_loopback(adapter) &&
fp@2171: 			      count++ < 10);
fp@2171: 			if (count < 11)
fp@2171: 				return 0;
fp@2171: 		}
fp@2171: 		break;
fp@2171: 
fp@2171: 	case e1000_82544:
fp@2171: 	case e1000_82540:
fp@2171: 	case e1000_82545:
fp@2171: 	case e1000_82545_rev_3:
fp@2171: 	case e1000_82546:
fp@2171: 	case e1000_82546_rev_3:
fp@2171: 	case e1000_82541:
fp@2171: 	case e1000_82541_rev_2:
fp@2171: 	case e1000_82547:
fp@2171: 	case e1000_82547_rev_2:
fp@2171: 		return e1000_integrated_phy_loopback(adapter);
fp@2171: 		break;
fp@2171: 	default:
fp@2171: 		/* Default PHY loopback work is to read the MII
fp@2171: 		 * control register and assert bit 14 (loopback mode).
fp@2171: 		 */
fp@2171: 		e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
fp@2171: 		phy_reg |= MII_CR_LOOPBACK;
fp@2171: 		e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
fp@2171: 		return 0;
fp@2171: 		break;
fp@2171: 	}
fp@2171: 
fp@2171: 	return 8;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
fp@2171: {
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	u32 rctl;
fp@2171: 
fp@2171: 	if (hw->media_type == e1000_media_type_fiber ||
fp@2171: 	    hw->media_type == e1000_media_type_internal_serdes) {
fp@2171: 		switch (hw->mac_type) {
fp@2171: 		case e1000_82545:
fp@2171: 		case e1000_82546:
fp@2171: 		case e1000_82545_rev_3:
fp@2171: 		case e1000_82546_rev_3:
fp@2171: 			return e1000_set_phy_loopback(adapter);
fp@2171: 			break;
fp@2171: 		default:
fp@2171: 			rctl = er32(RCTL);
fp@2171: 			rctl |= E1000_RCTL_LBM_TCVR;
fp@2171: 			ew32(RCTL, rctl);
fp@2171: 			return 0;
fp@2171: 		}
fp@2171: 	} else if (hw->media_type == e1000_media_type_copper)
fp@2171: 		return e1000_set_phy_loopback(adapter);
fp@2171: 
fp@2171: 	return 7;
fp@2171: }
fp@2171: 
fp@2171: static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
fp@2171: {
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	u32 rctl;
fp@2171: 	u16 phy_reg;
fp@2171: 
fp@2171: 	rctl = er32(RCTL);
fp@2171: 	rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
fp@2171: 	ew32(RCTL, rctl);
fp@2171: 
fp@2171: 	switch (hw->mac_type) {
fp@2171: 	case e1000_82545:
fp@2171: 	case e1000_82546:
fp@2171: 	case e1000_82545_rev_3:
fp@2171: 	case e1000_82546_rev_3:
fp@2171: 	default:
fp@2171: 		hw->autoneg = true;
fp@2171: 		e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
fp@2171: 		if (phy_reg & MII_CR_LOOPBACK) {
fp@2171: 			phy_reg &= ~MII_CR_LOOPBACK;
fp@2171: 			e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
fp@2171: 			e1000_phy_reset(hw);
fp@2171: 		}
fp@2171: 		break;
fp@2171: 	}
fp@2171: }
fp@2171: 
fp@2171: static void e1000_create_lbtest_frame(struct sk_buff *skb,
fp@2171: 				      unsigned int frame_size)
fp@2171: {
fp@2171: 	memset(skb->data, 0xFF, frame_size);
fp@2171: 	frame_size &= ~1;
fp@2171: 	memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
fp@2171: 	memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
fp@2171: 	memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
fp@2171: }
fp@2171: 
fp@2171: static int e1000_check_lbtest_frame(struct sk_buff *skb,
fp@2171: 				    unsigned int frame_size)
fp@2171: {
fp@2171: 	frame_size &= ~1;
fp@2171: 	if (*(skb->data + 3) == 0xFF) {
fp@2171: 		if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
fp@2171: 		   (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
fp@2171: 			return 0;
fp@2171: 		}
fp@2171: 	}
fp@2171: 	return 13;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_run_loopback_test(struct e1000_adapter *adapter)
fp@2171: {
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
fp@2171: 	struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
fp@2171: 	struct pci_dev *pdev = adapter->pdev;
fp@2171: 	int i, j, k, l, lc, good_cnt, ret_val=0;
fp@2171: 	unsigned long time;
fp@2171: 
fp@2171: 	ew32(RDT, rxdr->count - 1);
fp@2171: 
fp@2171: 	/* Calculate the loop count based on the largest descriptor ring
fp@2171: 	 * The idea is to wrap the largest ring a number of times using 64
fp@2171: 	 * send/receive pairs during each loop
fp@2171: 	 */
fp@2171: 
fp@2171: 	if (rxdr->count <= txdr->count)
fp@2171: 		lc = ((txdr->count / 64) * 2) + 1;
fp@2171: 	else
fp@2171: 		lc = ((rxdr->count / 64) * 2) + 1;
fp@2171: 
fp@2171: 	k = l = 0;
fp@2171: 	for (j = 0; j <= lc; j++) { /* loop count loop */
fp@2171: 		for (i = 0; i < 64; i++) { /* send the packets */
fp@2171: 			e1000_create_lbtest_frame(txdr->buffer_info[i].skb,
fp@2171: 					1024);
fp@2171: 			pci_dma_sync_single_for_device(pdev,
fp@2171: 					txdr->buffer_info[k].dma,
fp@2171: 				    	txdr->buffer_info[k].length,
fp@2171: 				    	PCI_DMA_TODEVICE);
fp@2171: 			if (unlikely(++k == txdr->count)) k = 0;
fp@2171: 		}
fp@2171: 		ew32(TDT, k);
fp@2171: 		msleep(200);
fp@2171: 		time = jiffies; /* set the start time for the receive */
fp@2171: 		good_cnt = 0;
fp@2171: 		do { /* receive the sent packets */
fp@2171: 			pci_dma_sync_single_for_cpu(pdev,
fp@2171: 					rxdr->buffer_info[l].dma,
fp@2171: 				    	rxdr->buffer_info[l].length,
fp@2171: 				    	PCI_DMA_FROMDEVICE);
fp@2171: 
fp@2171: 			ret_val = e1000_check_lbtest_frame(
fp@2171: 					rxdr->buffer_info[l].skb,
fp@2171: 				   	1024);
fp@2171: 			if (!ret_val)
fp@2171: 				good_cnt++;
fp@2171: 			if (unlikely(++l == rxdr->count)) l = 0;
fp@2171: 			/* time + 20 msecs (200 msecs on 2.4) is more than
fp@2171: 			 * enough time to complete the receives, if it's
fp@2171: 			 * exceeded, break and error off
fp@2171: 			 */
fp@2171: 		} while (good_cnt < 64 && jiffies < (time + 20));
fp@2171: 		if (good_cnt != 64) {
fp@2171: 			ret_val = 13; /* ret_val is the same as mis-compare */
fp@2171: 			break;
fp@2171: 		}
fp@2171: 		if (jiffies >= (time + 2)) {
fp@2171: 			ret_val = 14; /* error code for time out error */
fp@2171: 			break;
fp@2171: 		}
fp@2171: 	} /* end loop count loop */
fp@2171: 	return ret_val;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
fp@2171: {
fp@2171: 	*data = e1000_setup_desc_rings(adapter);
fp@2171: 	if (*data)
fp@2171: 		goto out;
fp@2171: 	*data = e1000_setup_loopback_test(adapter);
fp@2171: 	if (*data)
fp@2171: 		goto err_loopback;
fp@2171: 	*data = e1000_run_loopback_test(adapter);
fp@2171: 	e1000_loopback_cleanup(adapter);
fp@2171: 
fp@2171: err_loopback:
fp@2171: 	e1000_free_desc_rings(adapter);
fp@2171: out:
fp@2171: 	return *data;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
fp@2171: {
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	*data = 0;
fp@2171: 	if (hw->media_type == e1000_media_type_internal_serdes) {
fp@2171: 		int i = 0;
fp@2171: 		hw->serdes_has_link = false;
fp@2171: 
fp@2171: 		/* On some blade server designs, link establishment
fp@2171: 		 * could take as long as 2-3 minutes */
fp@2171: 		do {
fp@2171: 			e1000_check_for_link(hw);
fp@2171: 			if (hw->serdes_has_link)
fp@2171: 				return *data;
fp@2171: 			msleep(20);
fp@2171: 		} while (i++ < 3750);
fp@2171: 
fp@2171: 		*data = 1;
fp@2171: 	} else {
fp@2171: 		e1000_check_for_link(hw);
fp@2171: 		if (hw->autoneg)  /* if auto_neg is set wait for it */
fp@2171: 			msleep(4000);
fp@2171: 
fp@2171: 		if (!(er32(STATUS) & E1000_STATUS_LU)) {
fp@2171: 			*data = 1;
fp@2171: 		}
fp@2171: 	}
fp@2171: 	return *data;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_get_sset_count(struct net_device *netdev, int sset)
fp@2171: {
fp@2171: 	switch (sset) {
fp@2171: 	case ETH_SS_TEST:
fp@2171: 		return E1000_TEST_LEN;
fp@2171: 	case ETH_SS_STATS:
fp@2171: 		return E1000_STATS_LEN;
fp@2171: 	default:
fp@2171: 		return -EOPNOTSUPP;
fp@2171: 	}
fp@2171: }
fp@2171: 
fp@2171: static void e1000_diag_test(struct net_device *netdev,
fp@2171: 			    struct ethtool_test *eth_test, u64 *data)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	bool if_running;
fp@2171: 
fp@2171: 	if (adapter->ecdev)
fp@2171: 		return;
fp@2171: 
fp@2171: 	if_running = netif_running(netdev);
fp@2171: 
fp@2171: 	set_bit(__E1000_TESTING, &adapter->flags);
fp@2171: 	if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
fp@2171: 		/* Offline tests */
fp@2171: 
fp@2171: 		/* save speed, duplex, autoneg settings */
fp@2171: 		u16 autoneg_advertised = hw->autoneg_advertised;
fp@2171: 		u8 forced_speed_duplex = hw->forced_speed_duplex;
fp@2171: 		u8 autoneg = hw->autoneg;
fp@2171: 
fp@2171: 		DPRINTK(HW, INFO, "offline testing starting\n");
fp@2171: 
fp@2171: 		/* Link test performed before hardware reset so autoneg doesn't
fp@2171: 		 * interfere with test result */
fp@2171: 		if (e1000_link_test(adapter, &data[4]))
fp@2171: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2171: 
fp@2171: 		if (if_running)
fp@2171: 			/* indicate we're in test mode */
fp@2171: 			dev_close(netdev);
fp@2171: 		else
fp@2171: 			e1000_reset(adapter);
fp@2171: 
fp@2171: 		if (e1000_reg_test(adapter, &data[0]))
fp@2171: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2171: 
fp@2171: 		e1000_reset(adapter);
fp@2171: 		if (e1000_eeprom_test(adapter, &data[1]))
fp@2171: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2171: 
fp@2171: 		e1000_reset(adapter);
fp@2171: 		if (e1000_intr_test(adapter, &data[2]))
fp@2171: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2171: 
fp@2171: 		e1000_reset(adapter);
fp@2171: 		/* make sure the phy is powered up */
fp@2171: 		e1000_power_up_phy(adapter);
fp@2171: 		if (e1000_loopback_test(adapter, &data[3]))
fp@2171: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2171: 
fp@2171: 		/* restore speed, duplex, autoneg settings */
fp@2171: 		hw->autoneg_advertised = autoneg_advertised;
fp@2171: 		hw->forced_speed_duplex = forced_speed_duplex;
fp@2171: 		hw->autoneg = autoneg;
fp@2171: 
fp@2171: 		e1000_reset(adapter);
fp@2171: 		clear_bit(__E1000_TESTING, &adapter->flags);
fp@2171: 		if (if_running)
fp@2171: 			dev_open(netdev);
fp@2171: 	} else {
fp@2171: 		DPRINTK(HW, INFO, "online testing starting\n");
fp@2171: 		/* Online tests */
fp@2171: 		if (e1000_link_test(adapter, &data[4]))
fp@2171: 			eth_test->flags |= ETH_TEST_FL_FAILED;
fp@2171: 
fp@2171: 		/* Online tests aren't run; pass by default */
fp@2171: 		data[0] = 0;
fp@2171: 		data[1] = 0;
fp@2171: 		data[2] = 0;
fp@2171: 		data[3] = 0;
fp@2171: 
fp@2171: 		clear_bit(__E1000_TESTING, &adapter->flags);
fp@2171: 	}
fp@2171: 	msleep_interruptible(4 * 1000);
fp@2171: }
fp@2171: 
fp@2171: static int e1000_wol_exclusion(struct e1000_adapter *adapter,
fp@2171: 			       struct ethtool_wolinfo *wol)
fp@2171: {
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 	int retval = 1; /* fail by default */
fp@2171: 
fp@2171: 	switch (hw->device_id) {
fp@2171: 	case E1000_DEV_ID_82542:
fp@2171: 	case E1000_DEV_ID_82543GC_FIBER:
fp@2171: 	case E1000_DEV_ID_82543GC_COPPER:
fp@2171: 	case E1000_DEV_ID_82544EI_FIBER:
fp@2171: 	case E1000_DEV_ID_82546EB_QUAD_COPPER:
fp@2171: 	case E1000_DEV_ID_82545EM_FIBER:
fp@2171: 	case E1000_DEV_ID_82545EM_COPPER:
fp@2171: 	case E1000_DEV_ID_82546GB_QUAD_COPPER:
fp@2171: 	case E1000_DEV_ID_82546GB_PCIE:
fp@2171: 		/* these don't support WoL at all */
fp@2171: 		wol->supported = 0;
fp@2171: 		break;
fp@2171: 	case E1000_DEV_ID_82546EB_FIBER:
fp@2171: 	case E1000_DEV_ID_82546GB_FIBER:
fp@2171: 		/* Wake events not supported on port B */
fp@2171: 		if (er32(STATUS) & E1000_STATUS_FUNC_1) {
fp@2171: 			wol->supported = 0;
fp@2171: 			break;
fp@2171: 		}
fp@2171: 		/* return success for non excluded adapter ports */
fp@2171: 		retval = 0;
fp@2171: 		break;
fp@2171: 	case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
fp@2171: 		/* quad port adapters only support WoL on port A */
fp@2171: 		if (!adapter->quad_port_a) {
fp@2171: 			wol->supported = 0;
fp@2171: 			break;
fp@2171: 		}
fp@2171: 		/* return success for non excluded adapter ports */
fp@2171: 		retval = 0;
fp@2171: 		break;
fp@2171: 	default:
fp@2171: 		/* dual port cards only support WoL on port A from now on
fp@2171: 		 * unless it was enabled in the eeprom for port B
fp@2171: 		 * so exclude FUNC_1 ports from having WoL enabled */
fp@2171: 		if (er32(STATUS) & E1000_STATUS_FUNC_1 &&
fp@2171: 		    !adapter->eeprom_wol) {
fp@2171: 			wol->supported = 0;
fp@2171: 			break;
fp@2171: 		}
fp@2171: 
fp@2171: 		retval = 0;
fp@2171: 	}
fp@2171: 
fp@2171: 	return retval;
fp@2171: }
fp@2171: 
fp@2171: static void e1000_get_wol(struct net_device *netdev,
fp@2171: 			  struct ethtool_wolinfo *wol)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 
fp@2171: 	wol->supported = WAKE_UCAST | WAKE_MCAST |
fp@2171: 	                 WAKE_BCAST | WAKE_MAGIC;
fp@2171: 	wol->wolopts = 0;
fp@2171: 
fp@2171: 	/* this function will set ->supported = 0 and return 1 if wol is not
fp@2171: 	 * supported by this hardware */
fp@2171: 	if (e1000_wol_exclusion(adapter, wol) ||
fp@2171: 	    !device_can_wakeup(&adapter->pdev->dev))
fp@2171: 		return;
fp@2171: 
fp@2171: 	/* apply any specific unsupported masks here */
fp@2171: 	switch (hw->device_id) {
fp@2171: 	case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
fp@2171: 		/* KSP3 does not suppport UCAST wake-ups */
fp@2171: 		wol->supported &= ~WAKE_UCAST;
fp@2171: 
fp@2171: 		if (adapter->wol & E1000_WUFC_EX)
fp@2171: 			DPRINTK(DRV, ERR, "Interface does not support "
fp@2171: 		        "directed (unicast) frame wake-up packets\n");
fp@2171: 		break;
fp@2171: 	default:
fp@2171: 		break;
fp@2171: 	}
fp@2171: 
fp@2171: 	if (adapter->wol & E1000_WUFC_EX)
fp@2171: 		wol->wolopts |= WAKE_UCAST;
fp@2171: 	if (adapter->wol & E1000_WUFC_MC)
fp@2171: 		wol->wolopts |= WAKE_MCAST;
fp@2171: 	if (adapter->wol & E1000_WUFC_BC)
fp@2171: 		wol->wolopts |= WAKE_BCAST;
fp@2171: 	if (adapter->wol & E1000_WUFC_MAG)
fp@2171: 		wol->wolopts |= WAKE_MAGIC;
fp@2171: 
fp@2171: 	return;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 
fp@2171: 	if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
fp@2171: 		return -EOPNOTSUPP;
fp@2171: 
fp@2171: 	if (e1000_wol_exclusion(adapter, wol) ||
fp@2171: 	    !device_can_wakeup(&adapter->pdev->dev))
fp@2171: 		return wol->wolopts ? -EOPNOTSUPP : 0;
fp@2171: 
fp@2171: 	switch (hw->device_id) {
fp@2171: 	case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
fp@2171: 		if (wol->wolopts & WAKE_UCAST) {
fp@2171: 			DPRINTK(DRV, ERR, "Interface does not support "
fp@2171: 		        "directed (unicast) frame wake-up packets\n");
fp@2171: 			return -EOPNOTSUPP;
fp@2171: 		}
fp@2171: 		break;
fp@2171: 	default:
fp@2171: 		break;
fp@2171: 	}
fp@2171: 
fp@2171: 	/* these settings will always override what we currently have */
fp@2171: 	adapter->wol = 0;
fp@2171: 
fp@2171: 	if (wol->wolopts & WAKE_UCAST)
fp@2171: 		adapter->wol |= E1000_WUFC_EX;
fp@2171: 	if (wol->wolopts & WAKE_MCAST)
fp@2171: 		adapter->wol |= E1000_WUFC_MC;
fp@2171: 	if (wol->wolopts & WAKE_BCAST)
fp@2171: 		adapter->wol |= E1000_WUFC_BC;
fp@2171: 	if (wol->wolopts & WAKE_MAGIC)
fp@2171: 		adapter->wol |= E1000_WUFC_MAG;
fp@2171: 
fp@2171: 	device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
fp@2171: 
fp@2171: 	return 0;
fp@2171: }
fp@2171: 
fp@2171: /* toggle LED 4 times per second = 2 "blinks" per second */
fp@2171: #define E1000_ID_INTERVAL	(HZ/4)
fp@2171: 
fp@2171: /* bit defines for adapter->led_status */
fp@2171: #define E1000_LED_ON		0
fp@2171: 
fp@2171: static void e1000_led_blink_callback(unsigned long data)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = (struct e1000_adapter *) data;
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 
fp@2171: 	if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
fp@2171: 		e1000_led_off(hw);
fp@2171: 	else
fp@2171: 		e1000_led_on(hw);
fp@2171: 
fp@2171: 	mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
fp@2171: }
fp@2171: 
fp@2171: static int e1000_phys_id(struct net_device *netdev, u32 data)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 
fp@2171: 	if (!data)
fp@2171: 		data = INT_MAX;
fp@2171: 
fp@2171: 	if (!adapter->blink_timer.function) {
fp@2171: 		init_timer(&adapter->blink_timer);
fp@2171: 		adapter->blink_timer.function = e1000_led_blink_callback;
fp@2171: 		adapter->blink_timer.data = (unsigned long)adapter;
fp@2171: 	}
fp@2171: 	e1000_setup_led(hw);
fp@2171: 	mod_timer(&adapter->blink_timer, jiffies);
fp@2171: 	msleep_interruptible(data * 1000);
fp@2171: 	del_timer_sync(&adapter->blink_timer);
fp@2171: 
fp@2171: 	e1000_led_off(hw);
fp@2171: 	clear_bit(E1000_LED_ON, &adapter->led_status);
fp@2171: 	e1000_cleanup_led(hw);
fp@2171: 
fp@2171: 	return 0;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_get_coalesce(struct net_device *netdev,
fp@2171: 			      struct ethtool_coalesce *ec)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 
fp@2171: 	if (adapter->hw.mac_type < e1000_82545)
fp@2171: 		return -EOPNOTSUPP;
fp@2171: 
fp@2171: 	if (adapter->itr_setting <= 3)
fp@2171: 		ec->rx_coalesce_usecs = adapter->itr_setting;
fp@2171: 	else
fp@2171: 		ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
fp@2171: 
fp@2171: 	return 0;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_set_coalesce(struct net_device *netdev,
fp@2171: 			      struct ethtool_coalesce *ec)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	struct e1000_hw *hw = &adapter->hw;
fp@2171: 
fp@2171: 	if (hw->mac_type < e1000_82545)
fp@2171: 		return -EOPNOTSUPP;
fp@2171: 
fp@2171: 	if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
fp@2171: 	    ((ec->rx_coalesce_usecs > 3) &&
fp@2171: 	     (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
fp@2171: 	    (ec->rx_coalesce_usecs == 2))
fp@2171: 		return -EINVAL;
fp@2171: 
fp@2171: 	if (ec->rx_coalesce_usecs <= 3) {
fp@2171: 		adapter->itr = 20000;
fp@2171: 		adapter->itr_setting = ec->rx_coalesce_usecs;
fp@2171: 	} else {
fp@2171: 		adapter->itr = (1000000 / ec->rx_coalesce_usecs);
fp@2171: 		adapter->itr_setting = adapter->itr & ~3;
fp@2171: 	}
fp@2171: 
fp@2171: 	if (adapter->itr_setting != 0)
fp@2171: 		ew32(ITR, 1000000000 / (adapter->itr * 256));
fp@2171: 	else
fp@2171: 		ew32(ITR, 0);
fp@2171: 
fp@2171: 	return 0;
fp@2171: }
fp@2171: 
fp@2171: static int e1000_nway_reset(struct net_device *netdev)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 
fp@2171: 	if (adapter->ecdev)
fp@2171: 		return -EBUSY;
fp@2171: 
fp@2171: 	if (netif_running(netdev))
fp@2171: 		e1000_reinit_locked(adapter);
fp@2171: 	return 0;
fp@2171: }
fp@2171: 
fp@2171: static void e1000_get_ethtool_stats(struct net_device *netdev,
fp@2171: 				    struct ethtool_stats *stats, u64 *data)
fp@2171: {
fp@2171: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@2171: 	int i;
fp@2171: 
fp@2171: 	e1000_update_stats(adapter);
fp@2171: 	for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
fp@2171: 		char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
fp@2171: 		data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
fp@2171: 			sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
fp@2171: 	}
fp@2171: /*	BUG_ON(i != E1000_STATS_LEN); */
fp@2171: }
fp@2171: 
fp@2171: static void e1000_get_strings(struct net_device *netdev, u32 stringset,
fp@2171: 			      u8 *data)
fp@2171: {
fp@2171: 	u8 *p = data;
fp@2171: 	int i;
fp@2171: 
fp@2171: 	switch (stringset) {
fp@2171: 	case ETH_SS_TEST:
fp@2171: 		memcpy(data, *e1000_gstrings_test,
fp@2171: 			sizeof(e1000_gstrings_test));
fp@2171: 		break;
fp@2171: 	case ETH_SS_STATS:
fp@2171: 		for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
fp@2171: 			memcpy(p, e1000_gstrings_stats[i].stat_string,
fp@2171: 			       ETH_GSTRING_LEN);
fp@2171: 			p += ETH_GSTRING_LEN;
fp@2171: 		}
fp@2171: /*		BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */
fp@2171: 		break;
fp@2171: 	}
fp@2171: }
fp@2171: 
fp@2171: static const struct ethtool_ops e1000_ethtool_ops = {
fp@2171: 	.get_settings           = e1000_get_settings,
fp@2171: 	.set_settings           = e1000_set_settings,
fp@2171: 	.get_drvinfo            = e1000_get_drvinfo,
fp@2171: 	.get_regs_len           = e1000_get_regs_len,
fp@2171: 	.get_regs               = e1000_get_regs,
fp@2171: 	.get_wol                = e1000_get_wol,
fp@2171: 	.set_wol                = e1000_set_wol,
fp@2171: 	.get_msglevel           = e1000_get_msglevel,
fp@2171: 	.set_msglevel           = e1000_set_msglevel,
fp@2171: 	.nway_reset             = e1000_nway_reset,
fp@2171: 	.get_link               = ethtool_op_get_link,
fp@2171: 	.get_eeprom_len         = e1000_get_eeprom_len,
fp@2171: 	.get_eeprom             = e1000_get_eeprom,
fp@2171: 	.set_eeprom             = e1000_set_eeprom,
fp@2171: 	.get_ringparam          = e1000_get_ringparam,
fp@2171: 	.set_ringparam          = e1000_set_ringparam,
fp@2171: 	.get_pauseparam         = e1000_get_pauseparam,
fp@2171: 	.set_pauseparam         = e1000_set_pauseparam,
fp@2171: 	.get_rx_csum            = e1000_get_rx_csum,
fp@2171: 	.set_rx_csum            = e1000_set_rx_csum,
fp@2171: 	.get_tx_csum            = e1000_get_tx_csum,
fp@2171: 	.set_tx_csum            = e1000_set_tx_csum,
fp@2171: 	.set_sg                 = ethtool_op_set_sg,
fp@2171: 	.set_tso                = e1000_set_tso,
fp@2171: 	.self_test              = e1000_diag_test,
fp@2171: 	.get_strings            = e1000_get_strings,
fp@2171: 	.phys_id                = e1000_phys_id,
fp@2171: 	.get_ethtool_stats      = e1000_get_ethtool_stats,
fp@2171: 	.get_sset_count         = e1000_get_sset_count,
fp@2171: 	.get_coalesce           = e1000_get_coalesce,
fp@2171: 	.set_coalesce           = e1000_set_coalesce,
fp@2171: };
fp@2171: 
fp@2171: void e1000_set_ethtool_ops(struct net_device *netdev)
fp@2171: {
fp@2171: 	SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
fp@2171: }