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