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