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