History

ethtool: add interface to read standard MAC Ctrl stats

Number of devices maintains the standard-based MAC control counters for control frames. Add a API for those.

Jakub Kicinski committed 5 years ago

Commit bfad2b91 parent ca224456 files · +67 −0Browse files

Unified · Split

6 files
  1. include/linux/ethtool.h +12 −0
  2. include/uapi/linux/ethtool.h +2 −0
  3. include/uapi/linux/ethtool_netlink.h +14 −0
  4. net/ethtool/netlink.h +1 −0
  5. net/ethtool/stats.c +33 −0
  6. net/ethtool/strset.c +5 −0
include/linux/ethtool.h+12−0
@@ -285,6 +285,15 @@ struct ethtool_eth_phy_stats { · 284 unmodified lines
285285 u64 SymbolErrorDuringCarrier;
286286 };
287287
288+/* Basic IEEE 802.3 MAC Ctrl statistics (30.3.3.*), not otherwise exposed
289+ * via a more targeted API.
290+ */
291+struct ethtool_eth_ctrl_stats {
292+ u64 MACControlFramesTransmitted;
293+ u64 MACControlFramesReceived;
294+ u64 UnsupportedOpcodesReceived;
295+};
296+
288297 /**
289298 * struct ethtool_pause_stats - statistics for IEEE 802.3x pause frames
290299 * @tx_pause_frames: transmitted pause frame count. Reported to user space
@@ -524,6 +533,7 @@ struct ethtool_module_eeprom { · 233 unmodified lines
524533 * read.
525534 * @get_eth_phy_stats: Query some of the IEEE 802.3 PHY statistics.
526535 * @get_eth_mac_stats: Query some of the IEEE 802.3 MAC statistics.
536+ * @get_eth_ctrl_stats: Query some of the IEEE 802.3 MAC Ctrl statistics.
527537 *
528538 * All operations are optional (i.e. the function pointer may be set
529539 * to %NULL) and callers must take this into account. Callers must
@@ -638,6 +648,8 @@ struct ethtool_ops { · 108 unmodified lines
638648 struct ethtool_eth_phy_stats *phy_stats);
639649 void (*get_eth_mac_stats)(struct net_device *dev,
640650 struct ethtool_eth_mac_stats *mac_stats);
651+ void (*get_eth_ctrl_stats)(struct net_device *dev,
652+ struct ethtool_eth_ctrl_stats *ctrl_stats);
641653 };
642654
643655 int ethtool_check_ops(const struct ethtool_ops *ops);
include/uapi/linux/ethtool.h+2−0
@@ -672,6 +672,7 @@ enum ethtool_link_ext_substate_cable_issue { · 671 unmodified lines
672672 * @ETH_SS_STATS_STD: standardized stats
673673 * @ETH_SS_STATS_ETH_PHY: names of IEEE 802.3 PHY statistics
674674 * @ETH_SS_STATS_ETH_MAC: names of IEEE 802.3 MAC statistics
675+ * @ETH_SS_STATS_ETH_CTRL: names of IEEE 802.3 MAC Control statistics
675676 *
676677 * @ETH_SS_COUNT: number of defined string sets
677678 */
@@ -695,6 +696,7 @@ enum ethtool_stringset { · 17 unmodified lines
695696 ETH_SS_STATS_STD,
696697 ETH_SS_STATS_ETH_PHY,
697698 ETH_SS_STATS_ETH_MAC,
699+ ETH_SS_STATS_ETH_CTRL,
698700
699701 /* add new constants above here */
700702 ETH_SS_COUNT
include/uapi/linux/ethtool_netlink.h+14−0
@@ -699,6 +699,7 @@ enum { · 698 unmodified lines
699699 enum {
700700 ETHTOOL_STATS_ETH_PHY,
701701 ETHTOOL_STATS_ETH_MAC,
702+ ETHTOOL_STATS_ETH_CTRL,
702703
703704 /* add new constants above here */
704705 __ETHTOOL_STATS_CNT
@@ -779,6 +780,19 @@ enum { · 74 unmodified lines
779780 ETHTOOL_A_STATS_ETH_MAC_MAX = (__ETHTOOL_A_STATS_ETH_MAC_CNT - 1)
780781 };
781782
783+enum {
784+ /* 30.3.3.3 aMACControlFramesTransmitted */
785+ ETHTOOL_A_STATS_ETH_CTRL_3_TX,
786+ /* 30.3.3.4 aMACControlFramesReceived */
787+ ETHTOOL_A_STATS_ETH_CTRL_4_RX,
788+ /* 30.3.3.5 aUnsupportedOpcodesReceived */
789+ ETHTOOL_A_STATS_ETH_CTRL_5_RX_UNSUP,
790+
791+ /* add new constants above here */
792+ __ETHTOOL_A_STATS_ETH_CTRL_CNT,
793+ ETHTOOL_A_STATS_ETH_CTRL_MAX = (__ETHTOOL_A_STATS_ETH_CTRL_CNT - 1)
794+};
795+
782796 /* generic netlink info */
783797 #define ETHTOOL_GENL_NAME "ethtool"
784798 #define ETHTOOL_GENL_VERSION 1
net/ethtool/netlink.h+1−0
@@ -404,5 +404,6 @@ int ethnl_set_fec(struct sk_buff *skb, struct genl_info *info); · 403 unmodified lines
404404 extern const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN];
405405 extern const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN];
406406 extern const char stats_eth_mac_names[__ETHTOOL_A_STATS_ETH_MAC_CNT][ETH_GSTRING_LEN];
407+extern const char stats_eth_ctrl_names[__ETHTOOL_A_STATS_ETH_CTRL_CNT][ETH_GSTRING_LEN];
407408
408409 #endif /* _NET_ETHTOOL_NETLINK_H */
net/ethtool/stats.c+33−0
@@ -16,6 +16,7 @@ struct stats_reply_data { · 15 unmodified lines
1616 struct ethnl_reply_data base;
1717 struct ethtool_eth_phy_stats phy_stats;
1818 struct ethtool_eth_mac_stats mac_stats;
19+ struct ethtool_eth_ctrl_stats ctrl_stats;
1920 };
2021
2122 #define STATS_REPDATA(__reply_base) \
@@ -24,6 +25,7 @@ struct stats_reply_data { · 2 unmodified lines
2425 const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN] = {
2526 [ETHTOOL_STATS_ETH_PHY] = "eth-phy",
2627 [ETHTOOL_STATS_ETH_MAC] = "eth-mac",
28+ [ETHTOOL_STATS_ETH_CTRL] = "eth-ctrl",
2729 };
2830
2931 const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN] = {
@@ -55,6 +57,12 @@ const char stats_eth_mac_names[__ETHTOOL_A_STATS_ETH_MAC_CNT][ETH_GSTRING_LEN] = · 25 unmodified lines
5557 [ETHTOOL_A_STATS_ETH_MAC_25_TOO_LONG_ERR] = "FrameTooLongErrors",
5658 };
5759
60+const char stats_eth_ctrl_names[__ETHTOOL_A_STATS_ETH_CTRL_CNT][ETH_GSTRING_LEN] = {
61+ [ETHTOOL_A_STATS_ETH_CTRL_3_TX] = "MACControlFramesTransmitted",
62+ [ETHTOOL_A_STATS_ETH_CTRL_4_RX] = "MACControlFramesReceived",
63+ [ETHTOOL_A_STATS_ETH_CTRL_5_RX_UNSUP] = "UnsupportedOpcodesReceived",
64+};
65+
5866 const struct nla_policy ethnl_stats_get_policy[ETHTOOL_A_STATS_GROUPS + 1] = {
5967 [ETHTOOL_A_STATS_HEADER] =
6068 NLA_POLICY_NESTED(ethnl_header_policy),
@@ -98,6 +106,7 @@ static int stats_prepare_data(const struct ethnl_req_info *req_base, · 37 unmodified lines
98106
99107 memset(&data->phy_stats, 0xff, sizeof(data->phy_stats));
100108 memset(&data->mac_stats, 0xff, sizeof(data->mac_stats));
109+ memset(&data->ctrl_stats, 0xff, sizeof(data->mac_stats));
101110
102111 if (test_bit(ETHTOOL_STATS_ETH_PHY, req_info->stat_mask) &&
103112 dev->ethtool_ops->get_eth_phy_stats)
@@ -105,6 +114,9 @@ static int stats_prepare_data(const struct ethnl_req_info *req_base, · 1 unmodified line
105114 if (test_bit(ETHTOOL_STATS_ETH_MAC, req_info->stat_mask) &&
106115 dev->ethtool_ops->get_eth_mac_stats)
107116 dev->ethtool_ops->get_eth_mac_stats(dev, &data->mac_stats);
117+ if (test_bit(ETHTOOL_STATS_ETH_CTRL, req_info->stat_mask) &&
118+ dev->ethtool_ops->get_eth_ctrl_stats)
119+ dev->ethtool_ops->get_eth_ctrl_stats(dev, &data->ctrl_stats);
108120
109121 ethnl_ops_complete(dev);
110122 return 0;
@@ -125,6 +137,10 @@ static int stats_reply_size(const struct ethnl_req_info *req_base, · 14 unmodified lines
125137 n_stats += sizeof(struct ethtool_eth_mac_stats) / sizeof(u64);
126138 n_grps++;
127139 }
140+ if (test_bit(ETHTOOL_STATS_ETH_CTRL, req_info->stat_mask)) {
141+ n_stats += sizeof(struct ethtool_eth_ctrl_stats) / sizeof(u64);
142+ n_grps++;
143+ }
128144
129145 len += n_grps * (nla_total_size(0) + /* _A_STATS_GRP */
130146 nla_total_size(4) + /* _A_STATS_GRP_ID */
@@ -229,6 +245,19 @@ static int stats_put_mac_stats(struct sk_buff *skb, · 98 unmodified lines
229245 return 0;
230246 }
231247
248+static int stats_put_ctrl_stats(struct sk_buff *skb,
249+ const struct stats_reply_data *data)
250+{
251+ if (stat_put(skb, ETHTOOL_A_STATS_ETH_CTRL_3_TX,
252+ data->ctrl_stats.MACControlFramesTransmitted) ||
253+ stat_put(skb, ETHTOOL_A_STATS_ETH_CTRL_4_RX,
254+ data->ctrl_stats.MACControlFramesReceived) ||
255+ stat_put(skb, ETHTOOL_A_STATS_ETH_CTRL_5_RX_UNSUP,
256+ data->ctrl_stats.UnsupportedOpcodesReceived))
257+ return -EMSGSIZE;
258+ return 0;
259+}
260+
232261 static int stats_put_stats(struct sk_buff *skb,
233262 const struct stats_reply_data *data,
234263 u32 id, u32 ss_id,
@@ -272,6 +301,10 @@ static int stats_fill_reply(struct sk_buff *skb, · 37 unmodified lines
272301 ret = stats_put_stats(skb, data, ETHTOOL_STATS_ETH_MAC,
273302 ETH_SS_STATS_ETH_MAC,
274303 stats_put_mac_stats);
304+ if (!ret && test_bit(ETHTOOL_STATS_ETH_CTRL, req_info->stat_mask))
305+ ret = stats_put_stats(skb, data, ETHTOOL_STATS_ETH_CTRL,
306+ ETH_SS_STATS_ETH_CTRL,
307+ stats_put_ctrl_stats);
275308
276309 return ret;
277310 }
net/ethtool/strset.c+5−0
@@ -95,6 +95,11 @@ static const struct strset_info info_template[] = { · 94 unmodified lines
9595 .count = __ETHTOOL_A_STATS_ETH_MAC_CNT,
9696 .strings = stats_eth_mac_names,
9797 },
98+ [ETH_SS_STATS_ETH_CTRL] = {
99+ .per_dev = false,
100+ .count = __ETHTOOL_A_STATS_ETH_CTRL_CNT,
101+ .strings = stats_eth_ctrl_names,
102+ },
98103 };
99104
100105 struct strset_req_info {