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