aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/mt7621-eth
diff options
context:
space:
mode:
authorKamal Heib <kamalheib1@gmail.com>2018-05-12 23:40:03 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-05-14 14:05:49 +0200
commitd84c7b304b04d869bce0444cf0c808294c08908b (patch)
tree1690aac7f7e0c8a4505f221f0a2940f8eb33f7d7 /drivers/staging/mt7621-eth
parentstaging: wilc1000: refactor host_int_parse_assoc_resp_info() to remove unused code (diff)
downloadlinux-dev-d84c7b304b04d869bce0444cf0c808294c08908b.tar.xz
linux-dev-d84c7b304b04d869bce0444cf0c808294c08908b.zip
staging: mt7621-eth: Refactor ethtool stats
This patch removes the ugly macro hack to make sure hw_stats and ethtool strings are consisten, instead define a new struct which will hold the stat string and his index within the hw_stats struct. Signed-off-by: Kamal Heib <kamalheib1@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/mt7621-eth')
-rw-r--r--drivers/staging/mt7621-eth/ethtool.c49
-rw-r--r--drivers/staging/mt7621-eth/mtk_eth_soc.h29
2 files changed, 48 insertions, 30 deletions
diff --git a/drivers/staging/mt7621-eth/ethtool.c b/drivers/staging/mt7621-eth/ethtool.c
index 8270fea30cb3..40a7d47be913 100644
--- a/drivers/staging/mt7621-eth/ethtool.c
+++ b/drivers/staging/mt7621-eth/ethtool.c
@@ -15,12 +15,33 @@
#include "mtk_eth_soc.h"
#include "ethtool.h"
-static const char mtk_gdma_str[][ETH_GSTRING_LEN] = {
-#define _FE(x...) # x,
-MTK_STAT_REG_DECLARE
-#undef _FE
+struct mtk_stat {
+ char name[ETH_GSTRING_LEN];
+ unsigned int idx;
};
+#define MTK_HW_STAT(stat) { \
+ .name = #stat, \
+ .idx = offsetof(struct mtk_hw_stats, stat) / sizeof(u64) \
+}
+
+static const struct mtk_stat mtk_ethtool_hw_stats[] = {
+ MTK_HW_STAT(tx_bytes),
+ MTK_HW_STAT(tx_packets),
+ MTK_HW_STAT(tx_skip),
+ MTK_HW_STAT(tx_collisions),
+ MTK_HW_STAT(rx_bytes),
+ MTK_HW_STAT(rx_packets),
+ MTK_HW_STAT(rx_overflow),
+ MTK_HW_STAT(rx_fcs_errors),
+ MTK_HW_STAT(rx_short_errors),
+ MTK_HW_STAT(rx_long_errors),
+ MTK_HW_STAT(rx_checksum_errors),
+ MTK_HW_STAT(rx_flow_control_packets),
+};
+
+#define MTK_HW_STATS_LEN ARRAY_SIZE(mtk_ethtool_hw_stats)
+
static int mtk_get_link_ksettings(struct net_device *dev,
struct ethtool_link_ksettings *cmd)
{
@@ -76,7 +97,7 @@ static void mtk_get_drvinfo(struct net_device *dev,
strlcpy(info->bus_info, dev_name(mac->hw->dev), sizeof(info->bus_info));
if (soc->reg_table[MTK_REG_MTK_COUNTER_BASE])
- info->n_stats = ARRAY_SIZE(mtk_gdma_str);
+ info->n_stats = MTK_HW_STATS_LEN;
}
static u32 mtk_get_msglevel(struct net_device *dev)
@@ -155,9 +176,15 @@ static void mtk_get_ringparam(struct net_device *dev,
static void mtk_get_strings(struct net_device *dev, u32 stringset, u8 *data)
{
+ int i;
+
switch (stringset) {
case ETH_SS_STATS:
- memcpy(data, *mtk_gdma_str, sizeof(mtk_gdma_str));
+ for (i = 0; i < MTK_HW_STATS_LEN; i++) {
+ memcpy(data, mtk_ethtool_hw_stats[i].name,
+ ETH_GSTRING_LEN);
+ data += ETH_GSTRING_LEN;
+ }
break;
}
}
@@ -166,7 +193,7 @@ static int mtk_get_sset_count(struct net_device *dev, int sset)
{
switch (sset) {
case ETH_SS_STATS:
- return ARRAY_SIZE(mtk_gdma_str);
+ return MTK_HW_STATS_LEN;
default:
return -EOPNOTSUPP;
}
@@ -177,7 +204,6 @@ static void mtk_get_ethtool_stats(struct net_device *dev,
{
struct mtk_mac *mac = netdev_priv(dev);
struct mtk_hw_stats *hwstats = mac->hw_stats;
- u64 *data_src, *data_dst;
unsigned int start;
int i;
@@ -189,12 +215,9 @@ static void mtk_get_ethtool_stats(struct net_device *dev,
}
do {
- data_src = &hwstats->tx_bytes;
- data_dst = data;
start = u64_stats_fetch_begin_irq(&hwstats->syncp);
-
- for (i = 0; i < ARRAY_SIZE(mtk_gdma_str); i++)
- *data_dst++ = *data_src++;
+ for (i = 0; i < MTK_HW_STATS_LEN; i++)
+ data[i] = ((u64 *)hwstats)[mtk_ethtool_hw_stats[i].idx];
} while (u64_stats_fetch_retry_irq(&hwstats->syncp, start));
}
diff --git a/drivers/staging/mt7621-eth/mtk_eth_soc.h b/drivers/staging/mt7621-eth/mtk_eth_soc.h
index d3389b6e0366..e6ed80433f49 100644
--- a/drivers/staging/mt7621-eth/mtk_eth_soc.h
+++ b/drivers/staging/mt7621-eth/mtk_eth_soc.h
@@ -501,21 +501,7 @@ struct mtk_soc_data {
u32 has_switch:1;
};
-/* ugly macro hack to make sure hw_stats and ethtool strings are consistent */
#define MTK_STAT_OFFSET 0x40
-#define MTK_STAT_REG_DECLARE \
- _FE(tx_bytes) \
- _FE(tx_packets) \
- _FE(tx_skip) \
- _FE(tx_collisions) \
- _FE(rx_bytes) \
- _FE(rx_packets) \
- _FE(rx_overflow) \
- _FE(rx_fcs_errors) \
- _FE(rx_short_errors) \
- _FE(rx_long_errors) \
- _FE(rx_checksum_errors) \
- _FE(rx_flow_control_packets)
/* struct mtk_hw_stats - the structure that holds the traffic statistics.
* @stats_lock: make sure that stats operations are atomic
@@ -531,9 +517,18 @@ struct mtk_hw_stats {
u32 reg_offset;
struct u64_stats_sync syncp;
-#define _FE(x) u64 x;
- MTK_STAT_REG_DECLARE
-#undef _FE
+ u64 tx_bytes;
+ u64 tx_packets;
+ u64 tx_skip;
+ u64 tx_collisions;
+ u64 rx_bytes;
+ u64 rx_packets;
+ u64 rx_overflow;
+ u64 rx_fcs_errors;
+ u64 rx_short_errors;
+ u64 rx_long_errors;
+ u64 rx_checksum_errors;
+ u64 rx_flow_control_packets;
};
/* PDMA descriptor can point at 1-2 segments. This enum allows us to track how