31 #include <linux/netdevice.h>
33 #include <linux/ethtool.h>
34 #include <linux/pci.h>
35 #include <linux/slab.h>
50 #define E1000_STAT(str, m) { \
52 .type = E1000_STATS, \
53 .sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
54 .stat_offset = offsetof(struct e1000_adapter, m) }
55 #define E1000_NETDEV_STAT(str, m) { \
57 .type = NETDEV_STATS, \
58 .sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \
59 .stat_offset = offsetof(struct rtnl_link_stats64, m) }
61 static const struct e1000_stats e1000_gstrings_stats[] = {
90 E1000_STAT(
"tx_timeout_count", tx_timeout_count),
102 E1000_STAT(
"rx_csum_offload_good", hw_csum_good),
103 E1000_STAT(
"rx_csum_offload_errors", hw_csum_err),
105 E1000_STAT(
"alloc_rx_buff_failed", alloc_rx_buff_failed),
113 #define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
114 #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
116 "Register test (offline)",
"Eeprom test (offline)",
117 "Interrupt test (offline)",
"Loopback test (offline)",
118 "Link test (on/offline)"
120 #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
122 static int e1000_get_settings(
struct net_device *netdev,
142 if (hw->
mac.autoneg == 1) {
168 if (netif_running(netdev)) {
169 if (netif_carrier_ok(netdev)) {
190 ethtool_cmd_speed_set(ecmd, speed);
196 netif_carrier_ok(netdev))
218 if ((spd & 1) || (dplx & ~1))
228 switch (spd + dplx) {
256 e_err(
"Unsupported Speed/Duplex configuration\n");
260 static int e1000_set_settings(
struct net_device *netdev,
270 if (hw->
phy.ops.check_reset_block &&
271 hw->
phy.ops.check_reset_block(hw)) {
272 e_err(
"Cannot change link characteristics when SoL/IDER is active.\n");
287 e_err(
"forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
309 u32 speed = ethtool_cmd_speed(ecmd);
331 if (netif_running(adapter->
netdev)) {
341 static void e1000_get_pauseparam(
struct net_device *netdev,
360 static int e1000_set_pauseparam(
struct net_device *netdev,
374 if (netif_running(adapter->
netdev)) {
390 hw->
fc.current_mode = hw->
fc.requested_mode;
393 retval = hw->
mac.ops.setup_link(hw);
420 static int e1000_get_regs_len(
struct net_device *netdev)
422 #define E1000_REGS_LEN 32
426 static void e1000_get_regs(
struct net_device *netdev,
434 memset(p, 0, E1000_REGS_LEN *
sizeof(
u32));
436 regs->
version = (1 << 24) | (adapter->
pdev->revision << 16) |
437 adapter->
pdev->device;
442 regs_buff[2] =
er32(RCTL);
443 regs_buff[3] =
er32(RDLEN(0));
444 regs_buff[4] =
er32(RDH(0));
445 regs_buff[5] =
er32(RDT(0));
446 regs_buff[6] =
er32(RDTR);
449 regs_buff[8] =
er32(TDLEN(0));
450 regs_buff[9] =
er32(TDH(0));
451 regs_buff[10] =
er32(TDT(0));
452 regs_buff[11] =
er32(TIDV);
454 regs_buff[12] = adapter->
hw.phy.type;
461 regs_buff[13] = (
u32)phy_data;
466 regs_buff[17] = (
u32)phy_data;
467 regs_buff[18] = regs_buff[13];
469 regs_buff[20] = regs_buff[17];
471 regs_buff[22] = adapter->
phy_stats.receive_errors;
472 regs_buff[23] = regs_buff[13];
476 regs_buff[24] = (
u32)phy_data;
477 regs_buff[25] = regs_buff[24];
480 static int e1000_get_eeprom_len(
struct net_device *netdev)
483 return adapter->
hw.nvm.word_size * 2;
486 static int e1000_get_eeprom(
struct net_device *netdev,
497 if (eeprom->
len == 0)
500 eeprom->
magic = adapter->
pdev->vendor | (adapter->
pdev->device << 16);
502 first_word = eeprom->
offset >> 1;
503 last_word = (eeprom->
offset + eeprom->
len - 1) >> 1;
511 ret_val = e1000_read_nvm(hw, first_word,
512 last_word - first_word + 1,
515 for (i = 0; i < last_word - first_word + 1; i++) {
516 ret_val = e1000_read_nvm(hw, first_word + i, 1,
526 (last_word - first_word + 1));
529 for (i = 0; i < last_word - first_word + 1; i++)
539 static int e1000_set_eeprom(
struct net_device *netdev,
552 if (eeprom->
len == 0)
555 if (eeprom->
magic != (adapter->
pdev->vendor | (adapter->
pdev->device << 16)))
561 max_len = hw->
nvm.word_size * 2;
563 first_word = eeprom->
offset >> 1;
564 last_word = (eeprom->
offset + eeprom->
len - 1) >> 1;
569 ptr = (
void *)eeprom_buff;
574 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
577 if (((eeprom->
offset + eeprom->
len) & 1) && (!ret_val))
580 ret_val = e1000_read_nvm(hw, last_word, 1,
581 &eeprom_buff[last_word - first_word]);
587 for (i = 0; i < last_word - first_word + 1; i++)
592 for (i = 0; i < last_word - first_word + 1; i++)
595 ret_val = e1000_write_nvm(hw, first_word,
596 last_word - first_word + 1, eeprom_buff);
609 ret_val = e1000e_update_nvm_checksum(hw);
616 static void e1000_get_drvinfo(
struct net_device *netdev,
639 drvinfo->
eedump_len = e1000_get_eeprom_len(netdev);
642 static void e1000_get_ringparam(
struct net_device *netdev,
653 static int e1000_set_ringparam(
struct net_device *netdev,
659 bool set_tx =
false, set_rx =
false;
660 u16 new_rx_count, new_tx_count;
681 if (!netif_running(adapter->
netdev)) {
683 adapter->
tx_ring->count = new_tx_count;
684 adapter->
rx_ring->count = new_rx_count;
718 temp_tx->
count = new_tx_count;
725 temp_rx->count = new_rx_count;
761 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
762 for (pat = 0; pat <
ARRAY_SIZE(test); pat++) {
764 (test[pat] & write));
766 if (val != (test[pat] & write & mask)) {
767 e_err(
"pattern test reg %04X failed: got 0x%08X expected 0x%08X\n",
768 reg + offset, val, (test[pat] & write & mask));
777 int reg,
u32 mask,
u32 write)
780 __ew32(&adapter->
hw, reg, write & mask);
781 val = __er32(&adapter->
hw, reg);
782 if ((write & mask) != (val & mask)) {
783 e_err(
"set/check reg %04X test failed: got 0x%08X expected 0x%08X\n",
784 reg, (val & mask), (write & mask));
790 #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
792 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
795 #define REG_PATTERN_TEST(reg, mask, write) \
796 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
798 #define REG_SET_AND_CHECK(reg, mask, write) \
800 if (reg_set_and_check(adapter, data, reg, mask, write)) \
836 if (value != after) {
837 e_err(
"failed STATUS register test got: 0x%08X expected: 0x%08X\n",
893 if ((wlock_mac == 1) || (wlock_mac && (i > wlock_mac)))
917 if ((e1000_read_nvm(&adapter->
hw, i, 1, &temp)) < 0) {
931 static irqreturn_t e1000_test_intr(
int irq,
void *data)
967 netdev->
name, netdev)) {
972 e_info(
"testing %s interrupt\n", (shared_int ?
"shared" :
"unshared"));
980 for (i = 0; i < 10; i++) {
1045 ew32(
IMC, ~mask & 0x00007FFF);
1046 ew32(
ICS, ~mask & 0x00007FFF);
1075 static void e1000_free_desc_rings(
struct e1000_adapter *adapter)
1083 for (i = 0; i < tx_ring->
count; i++) {
1095 for (i = 0; i < rx_ring->
count; i++) {
1105 if (tx_ring->
desc) {
1110 if (rx_ring->
desc) {
1122 static int e1000_setup_desc_rings(
struct e1000_adapter *adapter)
1134 if (!tx_ring->
count)
1149 if (!tx_ring->
desc) {
1156 ew32(TDBAL(0), ((
u64) tx_ring->
dma & 0x00000000FFFFFFFF));
1165 for (i = 0; i < tx_ring->
count; i++) {
1168 unsigned int skb_size = 1024;
1196 if (!rx_ring->
count)
1210 if (!rx_ring->
desc) {
1220 ew32(RDBAL(0), ((
u64) rx_ring->
dma & 0xFFFFFFFF));
1232 for (i = 0; i < rx_ring->
count; i++) {
1252 rx_desc->
read.buffer_addr =
1260 e1000_free_desc_rings(adapter);
1264 static void e1000_phy_disable_receiver(
struct e1000_adapter *adapter)
1267 e1e_wphy(&adapter->
hw, 29, 0x001F);
1268 e1e_wphy(&adapter->
hw, 30, 0x8FFC);
1269 e1e_wphy(&adapter->
hw, 29, 0x001A);
1270 e1e_wphy(&adapter->
hw, 30, 0x8FF0);
1273 static int e1000_integrated_phy_loopback(
struct e1000_adapter *adapter)
1280 hw->
mac.autoneg = 0;
1302 switch (hw->
phy.type) {
1316 e1e_rphy(hw,
PHY_REG(2, 21), &phy_reg);
1319 e1e_wphy(hw,
PHY_REG(2, 21), phy_reg);
1324 e1e_rphy(hw,
PHY_REG(769, 16), &phy_reg);
1325 e1e_wphy(hw,
PHY_REG(769, 16), phy_reg | 0x000C);
1327 e1e_rphy(hw,
PHY_REG(776, 16), &phy_reg);
1328 e1e_wphy(hw,
PHY_REG(776, 16), phy_reg | 0x0040);
1330 e1e_rphy(hw,
PHY_REG(769, 16), &phy_reg);
1331 e1e_wphy(hw,
PHY_REG(769, 16), phy_reg | 0x0040);
1333 e1e_rphy(hw,
PHY_REG(769, 20), &phy_reg);
1334 e1e_wphy(hw,
PHY_REG(769, 20), phy_reg | 0x0400);
1339 ret_val = hw->
phy.ops.acquire(hw);
1341 e_err(
"Cannot setup 1Gbps loopback.\n");
1345 hw->
phy.ops.release(hw);
1349 e1e_rphy(hw,
PHY_REG(0, 21), &phy_reg);
1350 e1e_wphy(hw,
PHY_REG(0, 21), phy_reg & ~(1 << 3));
1352 e1e_rphy(hw,
PHY_REG(776, 18), &phy_reg);
1353 e1e_wphy(hw,
PHY_REG(776, 18), phy_reg | 1);
1355 #define I82577_PHY_LBK_CTRL 19
1356 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1396 e1000_phy_disable_receiver(adapter);
1403 static int e1000_set_82571_fiber_loopback(
struct e1000_adapter *adapter)
1436 #define E1000_SERDES_LB_ON 0x410
1437 ew32(SCTL, E1000_SERDES_LB_ON);
1445 static int e1000_set_es2lan_mac_loopback(
struct e1000_adapter *adapter)
1459 ew32(CTRL_EXT, ctrlext);
1473 #define KMRNCTRLSTA_OPMODE (0x1F << 16)
1474 #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1476 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
1481 static int e1000_setup_loopback_test(
struct e1000_adapter *adapter)
1488 switch (hw->
mac.type) {
1490 return e1000_set_es2lan_mac_loopback(adapter);
1494 return e1000_set_82571_fiber_loopback(adapter);
1503 return e1000_integrated_phy_loopback(adapter);
1509 static void e1000_loopback_cleanup(
struct e1000_adapter *adapter)
1519 switch (hw->
mac.type) {
1532 #define E1000_SERDES_LB_OFF 0x400
1533 ew32(SCTL, E1000_SERDES_LB_OFF);
1540 hw->
mac.autoneg = 1;
1545 phy_reg &= ~MII_CR_LOOPBACK;
1553 static void e1000_create_lbtest_frame(
struct sk_buff *skb,
1554 unsigned int frame_size)
1558 memset(&skb->
data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1559 memset(&skb->
data[frame_size / 2 + 10], 0xBE, 1);
1560 memset(&skb->
data[frame_size / 2 + 12], 0xAF, 1);
1563 static int e1000_check_lbtest_frame(
struct sk_buff *skb,
1564 unsigned int frame_size)
1567 if (*(skb->
data + 3) == 0xFF)
1568 if ((*(skb->
data + frame_size / 2 + 10) == 0xBE) &&
1569 (*(skb->
data + frame_size / 2 + 12) == 0xAF))
1574 static int e1000_run_loopback_test(
struct e1000_adapter *adapter)
1595 lc = ((tx_ring->
count / 64) * 2) + 1;
1597 lc = ((rx_ring->
count / 64) * 2) + 1;
1601 for (j = 0; j <=
lc; j++) {
1602 for (i = 0; i < 64; i++) {
1603 e1000_create_lbtest_frame(tx_ring->
buffer_info[k].skb,
1610 if (k == tx_ring->
count)
1623 ret_val = e1000_check_lbtest_frame(
1628 if (l == rx_ring->
count)
1635 }
while ((good_cnt < 64) && !
time_after(jiffies, time + 20));
1636 if (good_cnt != 64) {
1640 if (jiffies >= (time + 20)) {
1656 if (hw->
phy.ops.check_reset_block &&
1657 hw->
phy.ops.check_reset_block(hw)) {
1658 e_err(
"Cannot do PHY loopback test when SoL/IDER is active.\n");
1663 *data = e1000_setup_desc_rings(adapter);
1667 *data = e1000_setup_loopback_test(adapter);
1671 *data = e1000_run_loopback_test(adapter);
1672 e1000_loopback_cleanup(adapter);
1675 e1000_free_desc_rings(adapter);
1687 hw->
mac.serdes_has_link =
false;
1694 hw->
mac.ops.check_for_link(hw);
1695 if (hw->
mac.serdes_has_link)
1698 }
while (i++ < 3750);
1702 hw->
mac.ops.check_for_link(hw);
1703 if (hw->
mac.autoneg)
1716 static int e1000e_get_sset_count(
struct net_device *netdev,
int sset)
1728 static void e1000_diag_test(
struct net_device *netdev,
1732 u16 autoneg_advertised;
1733 u8 forced_speed_duplex;
1735 bool if_running = netif_running(netdev);
1746 adapter->
hw.phy.autoneg_wait_to_complete = 1;
1748 adapter->
hw.phy.autoneg_wait_to_complete = 0;
1755 autoneg_advertised = adapter->
hw.phy.autoneg_advertised;
1756 forced_speed_duplex = adapter->
hw.mac.forced_speed_duplex;
1757 autoneg = adapter->
hw.mac.autoneg;
1759 e_info(
"offline testing starting\n");
1765 if (e1000_reg_test(adapter, &data[0]))
1769 if (e1000_eeprom_test(adapter, &data[1]))
1773 if (e1000_intr_test(adapter, &data[2]))
1777 if (e1000_loopback_test(adapter, &data[3]))
1781 adapter->
hw.phy.autoneg_wait_to_complete = 1;
1783 adapter->
hw.phy.autoneg_wait_to_complete = 0;
1785 if (e1000_link_test(adapter, &data[4]))
1789 adapter->
hw.phy.autoneg_advertised = autoneg_advertised;
1790 adapter->
hw.mac.forced_speed_duplex = forced_speed_duplex;
1800 e_info(
"online testing starting\n");
1808 if (e1000_link_test(adapter, &data[4]))
1824 static void e1000_get_wol(
struct net_device *netdev,
1833 !device_can_wakeup(&adapter->
pdev->dev))
1844 e_err(
"Interface does not support directed (unicast) frame wake-up packets\n");
1864 !device_can_wakeup(&adapter->
pdev->dev) ||
1888 static int e1000_set_phys_id(
struct net_device *netdev,
1896 if (!hw->
mac.ops.blink_led)
1899 hw->
mac.ops.blink_led(hw);
1905 hw->
mac.ops.led_off(hw);
1906 hw->
mac.ops.cleanup_led(hw);
1910 hw->
mac.ops.led_on(hw);
1914 hw->
mac.ops.led_off(hw);
1920 static int e1000_get_coalesce(
struct net_device *netdev,
1933 static int e1000_set_coalesce(
struct net_device *netdev,
1948 adapter->
itr = 20000;
1963 static int e1000_nway_reset(
struct net_device *netdev)
1967 if (!netif_running(netdev))
1970 if (!adapter->
hw.mac.autoneg)
1978 static void e1000_get_ethtool_stats(
struct net_device *netdev,
1989 switch (e1000_gstrings_stats[i].
type) {
1991 p = (
char *) &net_stats +
1992 e1000_gstrings_stats[i].stat_offset;
1995 p = (
char *) adapter +
1996 e1000_gstrings_stats[i].stat_offset;
2008 static void e1000_get_strings(
struct net_device *netdev,
u32 stringset,
2014 switch (stringset) {
2016 memcpy(data, e1000_gstrings_test,
sizeof(e1000_gstrings_test));
2020 memcpy(p, e1000_gstrings_stats[i].stat_string,
2028 static int e1000_get_rxnfc(
struct net_device *netdev,
2033 switch (info->
cmd) {
2075 static const struct ethtool_ops e1000_ethtool_ops = {
2076 .get_settings = e1000_get_settings,
2077 .set_settings = e1000_set_settings,
2078 .get_drvinfo = e1000_get_drvinfo,
2079 .get_regs_len = e1000_get_regs_len,
2080 .get_regs = e1000_get_regs,
2081 .get_wol = e1000_get_wol,
2082 .set_wol = e1000_set_wol,
2083 .get_msglevel = e1000_get_msglevel,
2084 .set_msglevel = e1000_set_msglevel,
2085 .nway_reset = e1000_nway_reset,
2087 .get_eeprom_len = e1000_get_eeprom_len,
2088 .get_eeprom = e1000_get_eeprom,
2089 .set_eeprom = e1000_set_eeprom,
2090 .get_ringparam = e1000_get_ringparam,
2091 .set_ringparam = e1000_set_ringparam,
2092 .get_pauseparam = e1000_get_pauseparam,
2093 .set_pauseparam = e1000_set_pauseparam,
2094 .self_test = e1000_diag_test,
2095 .get_strings = e1000_get_strings,
2096 .set_phys_id = e1000_set_phys_id,
2097 .get_ethtool_stats = e1000_get_ethtool_stats,
2098 .get_sset_count = e1000e_get_sset_count,
2099 .get_coalesce = e1000_get_coalesce,
2100 .set_coalesce = e1000_set_coalesce,
2101 .get_rxnfc = e1000_get_rxnfc,