#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)
{
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)
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;
}
}
{
switch (sset) {
case ETH_SS_STATS:
- return ARRAY_SIZE(mtk_gdma_str);
+ return MTK_HW_STATS_LEN;
default:
return -EOPNOTSUPP;
}
{
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;
}
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));
}
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
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