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