30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32 #include <linux/types.h>
33 #include <linux/module.h>
34 #include <linux/slab.h>
35 #include <linux/pci.h>
36 #include <linux/netdevice.h>
37 #include <linux/ethtool.h>
39 #include <linux/if_vlan.h>
44 #define IXGBE_ALL_RAR_ENTRIES 16
54 #define IXGBEVF_STAT(m, b, r) sizeof(((struct ixgbevf_adapter *)0)->m), \
55 offsetof(struct ixgbevf_adapter, m), \
56 offsetof(struct ixgbevf_adapter, b), \
57 offsetof(struct ixgbevf_adapter, r)
59 static const struct ixgbe_stats ixgbe_gstrings_stats[] = {
61 stats.saved_reset_vfgprc)},
63 stats.saved_reset_vfgptc)},
65 stats.saved_reset_vfgorc)},
67 stats.saved_reset_vfgotc)},
70 stats.saved_reset_vfmprc)},
71 {
"rx_csum_offload_good",
IXGBEVF_STAT(hw_csum_rx_good, zero_base,
73 {
"rx_csum_offload_errors",
IXGBEVF_STAT(hw_csum_rx_error, zero_base,
75 {
"tx_csum_offload_ctxt",
IXGBEVF_STAT(hw_csum_tx_good, zero_base,
79 #define IXGBE_QUEUE_STATS_LEN 0
80 #define IXGBE_GLOBAL_STATS_LEN ARRAY_SIZE(ixgbe_gstrings_stats)
82 #define IXGBEVF_STATS_LEN (IXGBE_GLOBAL_STATS_LEN + IXGBE_QUEUE_STATS_LEN)
84 "Register test (offline)",
85 "Link test (on/offline)"
87 #define IXGBE_TEST_LEN (sizeof(ixgbe_gstrings_test) / ETH_GSTRING_LEN)
89 static int ixgbevf_get_settings(
struct net_device *netdev,
102 hw->
mac.ops.check_link(hw, &link_speed, &link_up,
false);
106 switch (link_speed) {
118 ethtool_cmd_speed_set(ecmd, speed);
121 ethtool_cmd_speed_set(ecmd, -1);
140 #define IXGBE_GET_STAT(_A_, _R_) (_A_->stats._R_)
142 static char *ixgbevf_reg_names[] = {
196 static void ixgbevf_get_regs(
struct net_device *netdev,
203 u32 regs_len = ixgbevf_get_regs_len(netdev);
231 for (i = 0; i < 2; i++)
233 for (i = 0; i < 2; i++)
235 for (i = 0; i < 2; i++)
237 for (i = 0; i < 2; i++)
239 for (i = 0; i < 2; i++)
241 for (i = 0; i < 2; i++)
243 for (i = 0; i < 2; i++)
250 for (i = 0; i < 2; i++)
252 for (i = 0; i < 2; i++)
254 for (i = 0; i < 2; i++)
256 for (i = 0; i < 2; i++)
258 for (i = 0; i < 2; i++)
260 for (i = 0; i < 2; i++)
262 for (i = 0; i < 2; i++)
264 for (i = 0; i < 2; i++)
267 for (i = 0; i <
ARRAY_SIZE(ixgbevf_reg_names); i++)
268 hw_dbg(hw,
"%s\t%8.8x\n", ixgbevf_reg_names[i], regs_buff[i]);
271 static void ixgbevf_get_drvinfo(
struct net_device *netdev,
283 static void ixgbevf_get_ringparam(
struct net_device *netdev,
294 static int ixgbevf_set_ringparam(
struct net_device *netdev,
299 u32 new_rx_count, new_tx_count;
321 if (!netif_running(adapter->
netdev)) {
323 adapter->
tx_ring[i].count = new_tx_count;
325 adapter->
rx_ring[i].count = new_rx_count;
341 tx_ring[
i].
count = new_tx_count;
367 rx_ring[
i].count = new_rx_count;
427 static int ixgbevf_get_sset_count(
struct net_device *
dev,
int stringset)
439 static void ixgbevf_get_ethtool_stats(
struct net_device *netdev,
447 char *p = (
char *)adapter +
448 ixgbe_gstrings_stats[i].stat_offset;
449 char *
b = (
char *)adapter +
450 ixgbe_gstrings_stats[i].base_stat_offset;
451 char *
r = (
char *)adapter +
452 ixgbe_gstrings_stats[i].saved_reset_offset;
455 ((ixgbe_gstrings_stats[i].sizeof_stat ==
462 static void ixgbevf_get_strings(
struct net_device *netdev,
u32 stringset,
465 char *p = (
char *)data;
470 memcpy(data, *ixgbe_gstrings_test,
475 memcpy(p, ixgbe_gstrings_stats[i].stat_string,
490 hw->
mac.ops.check_link(hw, &link_speed, &link_up,
true);
516 #define PATTERN_TEST 1
517 #define SET_READ_TEST 2
518 #define WRITE_NO_TEST 3
519 #define TABLE32_TEST 4
520 #define TABLE64_TEST_LO 5
521 #define TABLE64_TEST_HI 6
537 static const u32 register_test_patterns[] = {
538 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF
541 #define REG_PATTERN_TEST(R, M, W) \
543 u32 pat, val, before; \
544 for (pat = 0; pat < ARRAY_SIZE(register_test_patterns); pat++) { \
545 before = readl(adapter->hw.hw_addr + R); \
546 writel((register_test_patterns[pat] & W), \
547 (adapter->hw.hw_addr + R)); \
548 val = readl(adapter->hw.hw_addr + R); \
549 if (val != (register_test_patterns[pat] & W & M)) { \
550 hw_dbg(&adapter->hw, \
551 "pattern test reg %04X failed: got " \
552 "0x%08X expected 0x%08X\n", \
553 R, val, (register_test_patterns[pat] & W & M)); \
555 writel(before, adapter->hw.hw_addr + R); \
558 writel(before, adapter->hw.hw_addr + R); \
562 #define REG_SET_AND_CHECK(R, M, W) \
565 before = readl(adapter->hw.hw_addr + R); \
566 writel((W & M), (adapter->hw.hw_addr + R)); \
567 val = readl(adapter->hw.hw_addr + R); \
568 if ((W & M) != (val & M)) { \
569 pr_err("set/check reg %04X test failed: got 0x%08X expected " \
570 "0x%08X\n", R, (val & M), (W & M)); \
572 writel(before, (adapter->hw.hw_addr + R)); \
575 writel(before, (adapter->hw.hw_addr + R)); \
604 (adapter->
hw.hw_addr + test->
reg)
631 static void ixgbevf_diag_test(
struct net_device *netdev,
635 bool if_running = netif_running(netdev);
641 hw_dbg(&adapter->
hw,
"offline testing starting\n");
645 if (ixgbevf_link_test(adapter, &data[1]))
654 hw_dbg(&adapter->
hw,
"register testing starting\n");
664 hw_dbg(&adapter->
hw,
"online testing starting\n");
666 if (ixgbevf_link_test(adapter, &data[1]))
677 static int ixgbevf_nway_reset(
struct net_device *netdev)
681 if (netif_running(netdev))
687 static const struct ethtool_ops ixgbevf_ethtool_ops = {
688 .get_settings = ixgbevf_get_settings,
689 .get_drvinfo = ixgbevf_get_drvinfo,
690 .get_regs_len = ixgbevf_get_regs_len,
691 .get_regs = ixgbevf_get_regs,
692 .nway_reset = ixgbevf_nway_reset,
694 .get_ringparam = ixgbevf_get_ringparam,
695 .set_ringparam = ixgbevf_set_ringparam,
696 .get_msglevel = ixgbevf_get_msglevel,
697 .set_msglevel = ixgbevf_set_msglevel,
698 .self_test = ixgbevf_diag_test,
699 .get_sset_count = ixgbevf_get_sset_count,
700 .get_strings = ixgbevf_get_strings,
701 .get_ethtool_stats = ixgbevf_get_ethtool_stats,