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