1f09ea6fbSJakub Kicinski // SPDX-License-Identifier: GPL-2.0-only
2f09ea6fbSJakub Kicinski
3f09ea6fbSJakub Kicinski #include "netlink.h"
4f09ea6fbSJakub Kicinski #include "common.h"
5f09ea6fbSJakub Kicinski #include "bitset.h"
6f09ea6fbSJakub Kicinski
7f09ea6fbSJakub Kicinski struct stats_req_info {
8f09ea6fbSJakub Kicinski struct ethnl_req_info base;
9f09ea6fbSJakub Kicinski DECLARE_BITMAP(stat_mask, __ETHTOOL_STATS_CNT);
1004692c90SVladimir Oltean enum ethtool_mac_stats_src src;
11f09ea6fbSJakub Kicinski };
12f09ea6fbSJakub Kicinski
13f09ea6fbSJakub Kicinski #define STATS_REQINFO(__req_base) \
14f09ea6fbSJakub Kicinski container_of(__req_base, struct stats_req_info, base)
15f09ea6fbSJakub Kicinski
16f09ea6fbSJakub Kicinski struct stats_reply_data {
17f09ea6fbSJakub Kicinski struct ethnl_reply_data base;
18812ad3d2SKees Cook struct_group(stats,
19f09ea6fbSJakub Kicinski struct ethtool_eth_phy_stats phy_stats;
20ca224454SJakub Kicinski struct ethtool_eth_mac_stats mac_stats;
21bfad2b97SJakub Kicinski struct ethtool_eth_ctrl_stats ctrl_stats;
22a8b06e9dSJakub Kicinski struct ethtool_rmon_stats rmon_stats;
23812ad3d2SKees Cook );
24a8b06e9dSJakub Kicinski const struct ethtool_rmon_hist_range *rmon_ranges;
25f09ea6fbSJakub Kicinski };
26f09ea6fbSJakub Kicinski
27f09ea6fbSJakub Kicinski #define STATS_REPDATA(__reply_base) \
28f09ea6fbSJakub Kicinski container_of(__reply_base, struct stats_reply_data, base)
29f09ea6fbSJakub Kicinski
30f09ea6fbSJakub Kicinski const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN] = {
31f09ea6fbSJakub Kicinski [ETHTOOL_STATS_ETH_PHY] = "eth-phy",
32ca224454SJakub Kicinski [ETHTOOL_STATS_ETH_MAC] = "eth-mac",
33bfad2b97SJakub Kicinski [ETHTOOL_STATS_ETH_CTRL] = "eth-ctrl",
34a8b06e9dSJakub Kicinski [ETHTOOL_STATS_RMON] = "rmon",
35f09ea6fbSJakub Kicinski };
36f09ea6fbSJakub Kicinski
37f09ea6fbSJakub Kicinski const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN] = {
38f09ea6fbSJakub Kicinski [ETHTOOL_A_STATS_ETH_PHY_5_SYM_ERR] = "SymbolErrorDuringCarrier",
39f09ea6fbSJakub Kicinski };
40f09ea6fbSJakub Kicinski
41ca224454SJakub Kicinski const char stats_eth_mac_names[__ETHTOOL_A_STATS_ETH_MAC_CNT][ETH_GSTRING_LEN] = {
42ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_2_TX_PKT] = "FramesTransmittedOK",
43ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_3_SINGLE_COL] = "SingleCollisionFrames",
44ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_4_MULTI_COL] = "MultipleCollisionFrames",
45ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_5_RX_PKT] = "FramesReceivedOK",
46ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_6_FCS_ERR] = "FrameCheckSequenceErrors",
47ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_7_ALIGN_ERR] = "AlignmentErrors",
48ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_8_TX_BYTES] = "OctetsTransmittedOK",
49ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_9_TX_DEFER] = "FramesWithDeferredXmissions",
50ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_10_LATE_COL] = "LateCollisions",
51ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_11_XS_COL] = "FramesAbortedDueToXSColls",
52ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_12_TX_INT_ERR] = "FramesLostDueToIntMACXmitError",
53ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_13_CS_ERR] = "CarrierSenseErrors",
54ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_14_RX_BYTES] = "OctetsReceivedOK",
55ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_15_RX_INT_ERR] = "FramesLostDueToIntMACRcvError",
56ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_18_TX_MCAST] = "MulticastFramesXmittedOK",
57ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_19_TX_BCAST] = "BroadcastFramesXmittedOK",
58ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_20_XS_DEFER] = "FramesWithExcessiveDeferral",
59ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_21_RX_MCAST] = "MulticastFramesReceivedOK",
60ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_22_RX_BCAST] = "BroadcastFramesReceivedOK",
61ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_23_IR_LEN_ERR] = "InRangeLengthErrors",
62ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_24_OOR_LEN] = "OutOfRangeLengthField",
63ca224454SJakub Kicinski [ETHTOOL_A_STATS_ETH_MAC_25_TOO_LONG_ERR] = "FrameTooLongErrors",
64ca224454SJakub Kicinski };
65ca224454SJakub Kicinski
66bfad2b97SJakub Kicinski const char stats_eth_ctrl_names[__ETHTOOL_A_STATS_ETH_CTRL_CNT][ETH_GSTRING_LEN] = {
67bfad2b97SJakub Kicinski [ETHTOOL_A_STATS_ETH_CTRL_3_TX] = "MACControlFramesTransmitted",
68bfad2b97SJakub Kicinski [ETHTOOL_A_STATS_ETH_CTRL_4_RX] = "MACControlFramesReceived",
69bfad2b97SJakub Kicinski [ETHTOOL_A_STATS_ETH_CTRL_5_RX_UNSUP] = "UnsupportedOpcodesReceived",
70bfad2b97SJakub Kicinski };
71bfad2b97SJakub Kicinski
72a8b06e9dSJakub Kicinski const char stats_rmon_names[__ETHTOOL_A_STATS_RMON_CNT][ETH_GSTRING_LEN] = {
73a8b06e9dSJakub Kicinski [ETHTOOL_A_STATS_RMON_UNDERSIZE] = "etherStatsUndersizePkts",
74a8b06e9dSJakub Kicinski [ETHTOOL_A_STATS_RMON_OVERSIZE] = "etherStatsOversizePkts",
75a8b06e9dSJakub Kicinski [ETHTOOL_A_STATS_RMON_FRAG] = "etherStatsFragments",
76a8b06e9dSJakub Kicinski [ETHTOOL_A_STATS_RMON_JABBER] = "etherStatsJabbers",
77a8b06e9dSJakub Kicinski };
78a8b06e9dSJakub Kicinski
7904692c90SVladimir Oltean const struct nla_policy ethnl_stats_get_policy[ETHTOOL_A_STATS_SRC + 1] = {
80f09ea6fbSJakub Kicinski [ETHTOOL_A_STATS_HEADER] =
81f09ea6fbSJakub Kicinski NLA_POLICY_NESTED(ethnl_header_policy),
82f09ea6fbSJakub Kicinski [ETHTOOL_A_STATS_GROUPS] = { .type = NLA_NESTED },
8304692c90SVladimir Oltean [ETHTOOL_A_STATS_SRC] =
8404692c90SVladimir Oltean NLA_POLICY_MAX(NLA_U32, ETHTOOL_MAC_STATS_SRC_PMAC),
85f09ea6fbSJakub Kicinski };
86f09ea6fbSJakub Kicinski
stats_parse_request(struct ethnl_req_info * req_base,struct nlattr ** tb,struct netlink_ext_ack * extack)87f09ea6fbSJakub Kicinski static int stats_parse_request(struct ethnl_req_info *req_base,
88f09ea6fbSJakub Kicinski struct nlattr **tb,
89f09ea6fbSJakub Kicinski struct netlink_ext_ack *extack)
90f09ea6fbSJakub Kicinski {
9104692c90SVladimir Oltean enum ethtool_mac_stats_src src = ETHTOOL_MAC_STATS_SRC_AGGREGATE;
92f09ea6fbSJakub Kicinski struct stats_req_info *req_info = STATS_REQINFO(req_base);
93f09ea6fbSJakub Kicinski bool mod = false;
94f09ea6fbSJakub Kicinski int err;
95f09ea6fbSJakub Kicinski
96f09ea6fbSJakub Kicinski err = ethnl_update_bitset(req_info->stat_mask, __ETHTOOL_STATS_CNT,
97f09ea6fbSJakub Kicinski tb[ETHTOOL_A_STATS_GROUPS], stats_std_names,
98f09ea6fbSJakub Kicinski extack, &mod);
99f09ea6fbSJakub Kicinski if (err)
100f09ea6fbSJakub Kicinski return err;
101f09ea6fbSJakub Kicinski
102f09ea6fbSJakub Kicinski if (!mod) {
103f09ea6fbSJakub Kicinski NL_SET_ERR_MSG(extack, "no stats requested");
104f09ea6fbSJakub Kicinski return -EINVAL;
105f09ea6fbSJakub Kicinski }
106f09ea6fbSJakub Kicinski
10704692c90SVladimir Oltean if (tb[ETHTOOL_A_STATS_SRC])
10804692c90SVladimir Oltean src = nla_get_u32(tb[ETHTOOL_A_STATS_SRC]);
10904692c90SVladimir Oltean
11004692c90SVladimir Oltean req_info->src = src;
11104692c90SVladimir Oltean
112f09ea6fbSJakub Kicinski return 0;
113f09ea6fbSJakub Kicinski }
114f09ea6fbSJakub Kicinski
stats_prepare_data(const struct ethnl_req_info * req_base,struct ethnl_reply_data * reply_base,const struct genl_info * info)115f09ea6fbSJakub Kicinski static int stats_prepare_data(const struct ethnl_req_info *req_base,
116f09ea6fbSJakub Kicinski struct ethnl_reply_data *reply_base,
117*f946270dSJakub Kicinski const struct genl_info *info)
118f09ea6fbSJakub Kicinski {
119f09ea6fbSJakub Kicinski const struct stats_req_info *req_info = STATS_REQINFO(req_base);
120f09ea6fbSJakub Kicinski struct stats_reply_data *data = STATS_REPDATA(reply_base);
12104692c90SVladimir Oltean enum ethtool_mac_stats_src src = req_info->src;
122f09ea6fbSJakub Kicinski struct net_device *dev = reply_base->dev;
123f09ea6fbSJakub Kicinski int ret;
124f09ea6fbSJakub Kicinski
125f09ea6fbSJakub Kicinski ret = ethnl_ops_begin(dev);
126f09ea6fbSJakub Kicinski if (ret < 0)
127f09ea6fbSJakub Kicinski return ret;
128f09ea6fbSJakub Kicinski
12904692c90SVladimir Oltean if ((src == ETHTOOL_MAC_STATS_SRC_EMAC ||
13004692c90SVladimir Oltean src == ETHTOOL_MAC_STATS_SRC_PMAC) &&
13104692c90SVladimir Oltean !__ethtool_dev_mm_supported(dev)) {
132*f946270dSJakub Kicinski NL_SET_ERR_MSG_MOD(info->extack,
13304692c90SVladimir Oltean "Device does not support MAC merge layer");
13404692c90SVladimir Oltean ethnl_ops_complete(dev);
13504692c90SVladimir Oltean return -EOPNOTSUPP;
13604692c90SVladimir Oltean }
13704692c90SVladimir Oltean
138d1f0a5e1SJakub Kicinski /* Mark all stats as unset (see ETHTOOL_STAT_NOT_SET) to prevent them
139d1f0a5e1SJakub Kicinski * from being reported to user space in case driver did not set them.
140d1f0a5e1SJakub Kicinski */
141812ad3d2SKees Cook memset(&data->stats, 0xff, sizeof(data->stats));
142f09ea6fbSJakub Kicinski
14304692c90SVladimir Oltean data->phy_stats.src = src;
14404692c90SVladimir Oltean data->mac_stats.src = src;
14504692c90SVladimir Oltean data->ctrl_stats.src = src;
14604692c90SVladimir Oltean data->rmon_stats.src = src;
14704692c90SVladimir Oltean
148f09ea6fbSJakub Kicinski if (test_bit(ETHTOOL_STATS_ETH_PHY, req_info->stat_mask) &&
149f09ea6fbSJakub Kicinski dev->ethtool_ops->get_eth_phy_stats)
150f09ea6fbSJakub Kicinski dev->ethtool_ops->get_eth_phy_stats(dev, &data->phy_stats);
151ca224454SJakub Kicinski if (test_bit(ETHTOOL_STATS_ETH_MAC, req_info->stat_mask) &&
152ca224454SJakub Kicinski dev->ethtool_ops->get_eth_mac_stats)
153ca224454SJakub Kicinski dev->ethtool_ops->get_eth_mac_stats(dev, &data->mac_stats);
154bfad2b97SJakub Kicinski if (test_bit(ETHTOOL_STATS_ETH_CTRL, req_info->stat_mask) &&
155bfad2b97SJakub Kicinski dev->ethtool_ops->get_eth_ctrl_stats)
156bfad2b97SJakub Kicinski dev->ethtool_ops->get_eth_ctrl_stats(dev, &data->ctrl_stats);
157a8b06e9dSJakub Kicinski if (test_bit(ETHTOOL_STATS_RMON, req_info->stat_mask) &&
158a8b06e9dSJakub Kicinski dev->ethtool_ops->get_rmon_stats)
159a8b06e9dSJakub Kicinski dev->ethtool_ops->get_rmon_stats(dev, &data->rmon_stats,
160a8b06e9dSJakub Kicinski &data->rmon_ranges);
161f09ea6fbSJakub Kicinski
162f09ea6fbSJakub Kicinski ethnl_ops_complete(dev);
163f09ea6fbSJakub Kicinski return 0;
164f09ea6fbSJakub Kicinski }
165f09ea6fbSJakub Kicinski
stats_reply_size(const struct ethnl_req_info * req_base,const struct ethnl_reply_data * reply_base)166f09ea6fbSJakub Kicinski static int stats_reply_size(const struct ethnl_req_info *req_base,
167f09ea6fbSJakub Kicinski const struct ethnl_reply_data *reply_base)
168f09ea6fbSJakub Kicinski {
169f09ea6fbSJakub Kicinski const struct stats_req_info *req_info = STATS_REQINFO(req_base);
170f09ea6fbSJakub Kicinski unsigned int n_grps = 0, n_stats = 0;
171f09ea6fbSJakub Kicinski int len = 0;
172f09ea6fbSJakub Kicinski
17304692c90SVladimir Oltean len += nla_total_size(sizeof(u32)); /* _STATS_SRC */
17404692c90SVladimir Oltean
175f09ea6fbSJakub Kicinski if (test_bit(ETHTOOL_STATS_ETH_PHY, req_info->stat_mask)) {
176f09ea6fbSJakub Kicinski n_stats += sizeof(struct ethtool_eth_phy_stats) / sizeof(u64);
177f09ea6fbSJakub Kicinski n_grps++;
178f09ea6fbSJakub Kicinski }
179ca224454SJakub Kicinski if (test_bit(ETHTOOL_STATS_ETH_MAC, req_info->stat_mask)) {
180ca224454SJakub Kicinski n_stats += sizeof(struct ethtool_eth_mac_stats) / sizeof(u64);
181ca224454SJakub Kicinski n_grps++;
182ca224454SJakub Kicinski }
183bfad2b97SJakub Kicinski if (test_bit(ETHTOOL_STATS_ETH_CTRL, req_info->stat_mask)) {
184bfad2b97SJakub Kicinski n_stats += sizeof(struct ethtool_eth_ctrl_stats) / sizeof(u64);
185bfad2b97SJakub Kicinski n_grps++;
186bfad2b97SJakub Kicinski }
187a8b06e9dSJakub Kicinski if (test_bit(ETHTOOL_STATS_RMON, req_info->stat_mask)) {
188a8b06e9dSJakub Kicinski n_stats += sizeof(struct ethtool_rmon_stats) / sizeof(u64);
189a8b06e9dSJakub Kicinski n_grps++;
190a8b06e9dSJakub Kicinski /* Above includes the space for _A_STATS_GRP_HIST_VALs */
191a8b06e9dSJakub Kicinski
192a8b06e9dSJakub Kicinski len += (nla_total_size(0) + /* _A_STATS_GRP_HIST */
193a8b06e9dSJakub Kicinski nla_total_size(4) + /* _A_STATS_GRP_HIST_BKT_LOW */
194a8b06e9dSJakub Kicinski nla_total_size(4)) * /* _A_STATS_GRP_HIST_BKT_HI */
195a8b06e9dSJakub Kicinski ETHTOOL_RMON_HIST_MAX * 2;
196a8b06e9dSJakub Kicinski }
197f09ea6fbSJakub Kicinski
198f09ea6fbSJakub Kicinski len += n_grps * (nla_total_size(0) + /* _A_STATS_GRP */
199f09ea6fbSJakub Kicinski nla_total_size(4) + /* _A_STATS_GRP_ID */
200f09ea6fbSJakub Kicinski nla_total_size(4)); /* _A_STATS_GRP_SS_ID */
201f09ea6fbSJakub Kicinski len += n_stats * (nla_total_size(0) + /* _A_STATS_GRP_STAT */
202f09ea6fbSJakub Kicinski nla_total_size_64bit(sizeof(u64)));
203f09ea6fbSJakub Kicinski
204f09ea6fbSJakub Kicinski return len;
205f09ea6fbSJakub Kicinski }
206f09ea6fbSJakub Kicinski
stat_put(struct sk_buff * skb,u16 attrtype,u64 val)207f09ea6fbSJakub Kicinski static int stat_put(struct sk_buff *skb, u16 attrtype, u64 val)
208f09ea6fbSJakub Kicinski {
209f09ea6fbSJakub Kicinski struct nlattr *nest;
210f09ea6fbSJakub Kicinski int ret;
211f09ea6fbSJakub Kicinski
212f09ea6fbSJakub Kicinski if (val == ETHTOOL_STAT_NOT_SET)
213f09ea6fbSJakub Kicinski return 0;
214f09ea6fbSJakub Kicinski
215f09ea6fbSJakub Kicinski /* We want to start stats attr types from 0, so we don't have a type
216f09ea6fbSJakub Kicinski * for pad inside ETHTOOL_A_STATS_GRP_STAT. Pad things on the outside
217f09ea6fbSJakub Kicinski * of ETHTOOL_A_STATS_GRP_STAT. Since we're one nest away from the
218f09ea6fbSJakub Kicinski * actual attr we're 4B off - nla_need_padding_for_64bit() & co.
219f09ea6fbSJakub Kicinski * can't be used.
220f09ea6fbSJakub Kicinski */
221f09ea6fbSJakub Kicinski #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
222f09ea6fbSJakub Kicinski if (!IS_ALIGNED((unsigned long)skb_tail_pointer(skb), 8))
223f09ea6fbSJakub Kicinski if (!nla_reserve(skb, ETHTOOL_A_STATS_GRP_PAD, 0))
224f09ea6fbSJakub Kicinski return -EMSGSIZE;
225f09ea6fbSJakub Kicinski #endif
226f09ea6fbSJakub Kicinski
227f09ea6fbSJakub Kicinski nest = nla_nest_start(skb, ETHTOOL_A_STATS_GRP_STAT);
228f09ea6fbSJakub Kicinski if (!nest)
229f09ea6fbSJakub Kicinski return -EMSGSIZE;
230f09ea6fbSJakub Kicinski
231f09ea6fbSJakub Kicinski ret = nla_put_u64_64bit(skb, attrtype, val, -1 /* not used */);
232f09ea6fbSJakub Kicinski if (ret) {
233f09ea6fbSJakub Kicinski nla_nest_cancel(skb, nest);
234f09ea6fbSJakub Kicinski return ret;
235f09ea6fbSJakub Kicinski }
236f09ea6fbSJakub Kicinski
237f09ea6fbSJakub Kicinski nla_nest_end(skb, nest);
238f09ea6fbSJakub Kicinski return 0;
239f09ea6fbSJakub Kicinski }
240f09ea6fbSJakub Kicinski
stats_put_phy_stats(struct sk_buff * skb,const struct stats_reply_data * data)241f09ea6fbSJakub Kicinski static int stats_put_phy_stats(struct sk_buff *skb,
242f09ea6fbSJakub Kicinski const struct stats_reply_data *data)
243f09ea6fbSJakub Kicinski {
244f09ea6fbSJakub Kicinski if (stat_put(skb, ETHTOOL_A_STATS_ETH_PHY_5_SYM_ERR,
245f09ea6fbSJakub Kicinski data->phy_stats.SymbolErrorDuringCarrier))
246f09ea6fbSJakub Kicinski return -EMSGSIZE;
247f09ea6fbSJakub Kicinski return 0;
248f09ea6fbSJakub Kicinski }
249f09ea6fbSJakub Kicinski
stats_put_mac_stats(struct sk_buff * skb,const struct stats_reply_data * data)250ca224454SJakub Kicinski static int stats_put_mac_stats(struct sk_buff *skb,
251ca224454SJakub Kicinski const struct stats_reply_data *data)
252ca224454SJakub Kicinski {
253ca224454SJakub Kicinski if (stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_2_TX_PKT,
254ca224454SJakub Kicinski data->mac_stats.FramesTransmittedOK) ||
255ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_3_SINGLE_COL,
256ca224454SJakub Kicinski data->mac_stats.SingleCollisionFrames) ||
257ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_4_MULTI_COL,
258ca224454SJakub Kicinski data->mac_stats.MultipleCollisionFrames) ||
259ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_5_RX_PKT,
260ca224454SJakub Kicinski data->mac_stats.FramesReceivedOK) ||
261ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_6_FCS_ERR,
262ca224454SJakub Kicinski data->mac_stats.FrameCheckSequenceErrors) ||
263ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_7_ALIGN_ERR,
264ca224454SJakub Kicinski data->mac_stats.AlignmentErrors) ||
265ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_8_TX_BYTES,
266ca224454SJakub Kicinski data->mac_stats.OctetsTransmittedOK) ||
267ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_9_TX_DEFER,
268ca224454SJakub Kicinski data->mac_stats.FramesWithDeferredXmissions) ||
269ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_10_LATE_COL,
270ca224454SJakub Kicinski data->mac_stats.LateCollisions) ||
271ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_11_XS_COL,
272ca224454SJakub Kicinski data->mac_stats.FramesAbortedDueToXSColls) ||
273ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_12_TX_INT_ERR,
274ca224454SJakub Kicinski data->mac_stats.FramesLostDueToIntMACXmitError) ||
275ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_13_CS_ERR,
276ca224454SJakub Kicinski data->mac_stats.CarrierSenseErrors) ||
277ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_14_RX_BYTES,
278ca224454SJakub Kicinski data->mac_stats.OctetsReceivedOK) ||
279ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_15_RX_INT_ERR,
280ca224454SJakub Kicinski data->mac_stats.FramesLostDueToIntMACRcvError) ||
281ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_18_TX_MCAST,
282ca224454SJakub Kicinski data->mac_stats.MulticastFramesXmittedOK) ||
283ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_19_TX_BCAST,
284ca224454SJakub Kicinski data->mac_stats.BroadcastFramesXmittedOK) ||
285ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_20_XS_DEFER,
286ca224454SJakub Kicinski data->mac_stats.FramesWithExcessiveDeferral) ||
287ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_21_RX_MCAST,
288ca224454SJakub Kicinski data->mac_stats.MulticastFramesReceivedOK) ||
289ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_22_RX_BCAST,
290ca224454SJakub Kicinski data->mac_stats.BroadcastFramesReceivedOK) ||
291ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_23_IR_LEN_ERR,
292ca224454SJakub Kicinski data->mac_stats.InRangeLengthErrors) ||
293ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_24_OOR_LEN,
294ca224454SJakub Kicinski data->mac_stats.OutOfRangeLengthField) ||
295ca224454SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_25_TOO_LONG_ERR,
296ca224454SJakub Kicinski data->mac_stats.FrameTooLongErrors))
297ca224454SJakub Kicinski return -EMSGSIZE;
298ca224454SJakub Kicinski return 0;
299ca224454SJakub Kicinski }
300ca224454SJakub Kicinski
stats_put_ctrl_stats(struct sk_buff * skb,const struct stats_reply_data * data)301bfad2b97SJakub Kicinski static int stats_put_ctrl_stats(struct sk_buff *skb,
302bfad2b97SJakub Kicinski const struct stats_reply_data *data)
303bfad2b97SJakub Kicinski {
304bfad2b97SJakub Kicinski if (stat_put(skb, ETHTOOL_A_STATS_ETH_CTRL_3_TX,
305bfad2b97SJakub Kicinski data->ctrl_stats.MACControlFramesTransmitted) ||
306bfad2b97SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_CTRL_4_RX,
307bfad2b97SJakub Kicinski data->ctrl_stats.MACControlFramesReceived) ||
308bfad2b97SJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_ETH_CTRL_5_RX_UNSUP,
309bfad2b97SJakub Kicinski data->ctrl_stats.UnsupportedOpcodesReceived))
310bfad2b97SJakub Kicinski return -EMSGSIZE;
311bfad2b97SJakub Kicinski return 0;
312bfad2b97SJakub Kicinski }
313bfad2b97SJakub Kicinski
stats_put_rmon_hist(struct sk_buff * skb,u32 attr,const u64 * hist,const struct ethtool_rmon_hist_range * ranges)314a8b06e9dSJakub Kicinski static int stats_put_rmon_hist(struct sk_buff *skb, u32 attr, const u64 *hist,
315a8b06e9dSJakub Kicinski const struct ethtool_rmon_hist_range *ranges)
316a8b06e9dSJakub Kicinski {
317a8b06e9dSJakub Kicinski struct nlattr *nest;
318a8b06e9dSJakub Kicinski int i;
319a8b06e9dSJakub Kicinski
320a8b06e9dSJakub Kicinski if (!ranges)
321a8b06e9dSJakub Kicinski return 0;
322a8b06e9dSJakub Kicinski
323a8b06e9dSJakub Kicinski for (i = 0; i < ETHTOOL_RMON_HIST_MAX; i++) {
324a8b06e9dSJakub Kicinski if (!ranges[i].low && !ranges[i].high)
325a8b06e9dSJakub Kicinski break;
326a8b06e9dSJakub Kicinski if (hist[i] == ETHTOOL_STAT_NOT_SET)
327a8b06e9dSJakub Kicinski continue;
328a8b06e9dSJakub Kicinski
329a8b06e9dSJakub Kicinski nest = nla_nest_start(skb, attr);
330a8b06e9dSJakub Kicinski if (!nest)
331a8b06e9dSJakub Kicinski return -EMSGSIZE;
332a8b06e9dSJakub Kicinski
333a8b06e9dSJakub Kicinski if (nla_put_u32(skb, ETHTOOL_A_STATS_GRP_HIST_BKT_LOW,
334a8b06e9dSJakub Kicinski ranges[i].low) ||
335a8b06e9dSJakub Kicinski nla_put_u32(skb, ETHTOOL_A_STATS_GRP_HIST_BKT_HI,
336a8b06e9dSJakub Kicinski ranges[i].high) ||
337a8b06e9dSJakub Kicinski nla_put_u64_64bit(skb, ETHTOOL_A_STATS_GRP_HIST_VAL,
338a8b06e9dSJakub Kicinski hist[i], ETHTOOL_A_STATS_GRP_PAD))
339a8b06e9dSJakub Kicinski goto err_cancel_hist;
340a8b06e9dSJakub Kicinski
341a8b06e9dSJakub Kicinski nla_nest_end(skb, nest);
342a8b06e9dSJakub Kicinski }
343a8b06e9dSJakub Kicinski
344a8b06e9dSJakub Kicinski return 0;
345a8b06e9dSJakub Kicinski
346a8b06e9dSJakub Kicinski err_cancel_hist:
347a8b06e9dSJakub Kicinski nla_nest_cancel(skb, nest);
348a8b06e9dSJakub Kicinski return -EMSGSIZE;
349a8b06e9dSJakub Kicinski }
350a8b06e9dSJakub Kicinski
stats_put_rmon_stats(struct sk_buff * skb,const struct stats_reply_data * data)351a8b06e9dSJakub Kicinski static int stats_put_rmon_stats(struct sk_buff *skb,
352a8b06e9dSJakub Kicinski const struct stats_reply_data *data)
353a8b06e9dSJakub Kicinski {
354a8b06e9dSJakub Kicinski if (stats_put_rmon_hist(skb, ETHTOOL_A_STATS_GRP_HIST_RX,
355a8b06e9dSJakub Kicinski data->rmon_stats.hist, data->rmon_ranges) ||
356a8b06e9dSJakub Kicinski stats_put_rmon_hist(skb, ETHTOOL_A_STATS_GRP_HIST_TX,
357a8b06e9dSJakub Kicinski data->rmon_stats.hist_tx, data->rmon_ranges))
358a8b06e9dSJakub Kicinski return -EMSGSIZE;
359a8b06e9dSJakub Kicinski
360a8b06e9dSJakub Kicinski if (stat_put(skb, ETHTOOL_A_STATS_RMON_UNDERSIZE,
361a8b06e9dSJakub Kicinski data->rmon_stats.undersize_pkts) ||
362a8b06e9dSJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_RMON_OVERSIZE,
363a8b06e9dSJakub Kicinski data->rmon_stats.oversize_pkts) ||
364a8b06e9dSJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_RMON_FRAG,
365a8b06e9dSJakub Kicinski data->rmon_stats.fragments) ||
366a8b06e9dSJakub Kicinski stat_put(skb, ETHTOOL_A_STATS_RMON_JABBER,
367a8b06e9dSJakub Kicinski data->rmon_stats.jabbers))
368a8b06e9dSJakub Kicinski return -EMSGSIZE;
369a8b06e9dSJakub Kicinski
370a8b06e9dSJakub Kicinski return 0;
371a8b06e9dSJakub Kicinski }
372a8b06e9dSJakub Kicinski
stats_put_stats(struct sk_buff * skb,const struct stats_reply_data * data,u32 id,u32 ss_id,int (* cb)(struct sk_buff * skb,const struct stats_reply_data * data))373f09ea6fbSJakub Kicinski static int stats_put_stats(struct sk_buff *skb,
374f09ea6fbSJakub Kicinski const struct stats_reply_data *data,
375f09ea6fbSJakub Kicinski u32 id, u32 ss_id,
376f09ea6fbSJakub Kicinski int (*cb)(struct sk_buff *skb,
377f09ea6fbSJakub Kicinski const struct stats_reply_data *data))
378f09ea6fbSJakub Kicinski {
379f09ea6fbSJakub Kicinski struct nlattr *nest;
380f09ea6fbSJakub Kicinski
381f09ea6fbSJakub Kicinski nest = nla_nest_start(skb, ETHTOOL_A_STATS_GRP);
382f09ea6fbSJakub Kicinski if (!nest)
383f09ea6fbSJakub Kicinski return -EMSGSIZE;
384f09ea6fbSJakub Kicinski
385f09ea6fbSJakub Kicinski if (nla_put_u32(skb, ETHTOOL_A_STATS_GRP_ID, id) ||
386f09ea6fbSJakub Kicinski nla_put_u32(skb, ETHTOOL_A_STATS_GRP_SS_ID, ss_id))
387f09ea6fbSJakub Kicinski goto err_cancel;
388f09ea6fbSJakub Kicinski
389f09ea6fbSJakub Kicinski if (cb(skb, data))
390f09ea6fbSJakub Kicinski goto err_cancel;
391f09ea6fbSJakub Kicinski
392f09ea6fbSJakub Kicinski nla_nest_end(skb, nest);
393f09ea6fbSJakub Kicinski return 0;
394f09ea6fbSJakub Kicinski
395f09ea6fbSJakub Kicinski err_cancel:
396f09ea6fbSJakub Kicinski nla_nest_cancel(skb, nest);
397f09ea6fbSJakub Kicinski return -EMSGSIZE;
398f09ea6fbSJakub Kicinski }
399f09ea6fbSJakub Kicinski
stats_fill_reply(struct sk_buff * skb,const struct ethnl_req_info * req_base,const struct ethnl_reply_data * reply_base)400f09ea6fbSJakub Kicinski static int stats_fill_reply(struct sk_buff *skb,
401f09ea6fbSJakub Kicinski const struct ethnl_req_info *req_base,
402f09ea6fbSJakub Kicinski const struct ethnl_reply_data *reply_base)
403f09ea6fbSJakub Kicinski {
404f09ea6fbSJakub Kicinski const struct stats_req_info *req_info = STATS_REQINFO(req_base);
405f09ea6fbSJakub Kicinski const struct stats_reply_data *data = STATS_REPDATA(reply_base);
406f09ea6fbSJakub Kicinski int ret = 0;
407f09ea6fbSJakub Kicinski
40804692c90SVladimir Oltean if (nla_put_u32(skb, ETHTOOL_A_STATS_SRC, req_info->src))
40904692c90SVladimir Oltean return -EMSGSIZE;
41004692c90SVladimir Oltean
411f09ea6fbSJakub Kicinski if (!ret && test_bit(ETHTOOL_STATS_ETH_PHY, req_info->stat_mask))
412f09ea6fbSJakub Kicinski ret = stats_put_stats(skb, data, ETHTOOL_STATS_ETH_PHY,
413f09ea6fbSJakub Kicinski ETH_SS_STATS_ETH_PHY,
414f09ea6fbSJakub Kicinski stats_put_phy_stats);
415ca224454SJakub Kicinski if (!ret && test_bit(ETHTOOL_STATS_ETH_MAC, req_info->stat_mask))
416ca224454SJakub Kicinski ret = stats_put_stats(skb, data, ETHTOOL_STATS_ETH_MAC,
417ca224454SJakub Kicinski ETH_SS_STATS_ETH_MAC,
418ca224454SJakub Kicinski stats_put_mac_stats);
419bfad2b97SJakub Kicinski if (!ret && test_bit(ETHTOOL_STATS_ETH_CTRL, req_info->stat_mask))
420bfad2b97SJakub Kicinski ret = stats_put_stats(skb, data, ETHTOOL_STATS_ETH_CTRL,
421bfad2b97SJakub Kicinski ETH_SS_STATS_ETH_CTRL,
422bfad2b97SJakub Kicinski stats_put_ctrl_stats);
423a8b06e9dSJakub Kicinski if (!ret && test_bit(ETHTOOL_STATS_RMON, req_info->stat_mask))
424a8b06e9dSJakub Kicinski ret = stats_put_stats(skb, data, ETHTOOL_STATS_RMON,
425a8b06e9dSJakub Kicinski ETH_SS_STATS_RMON, stats_put_rmon_stats);
426f09ea6fbSJakub Kicinski
427f09ea6fbSJakub Kicinski return ret;
428f09ea6fbSJakub Kicinski }
429f09ea6fbSJakub Kicinski
430f09ea6fbSJakub Kicinski const struct ethnl_request_ops ethnl_stats_request_ops = {
431f09ea6fbSJakub Kicinski .request_cmd = ETHTOOL_MSG_STATS_GET,
432f09ea6fbSJakub Kicinski .reply_cmd = ETHTOOL_MSG_STATS_GET_REPLY,
433f09ea6fbSJakub Kicinski .hdr_attr = ETHTOOL_A_STATS_HEADER,
434f09ea6fbSJakub Kicinski .req_info_size = sizeof(struct stats_req_info),
435f09ea6fbSJakub Kicinski .reply_data_size = sizeof(struct stats_reply_data),
436f09ea6fbSJakub Kicinski
437f09ea6fbSJakub Kicinski .parse_request = stats_parse_request,
438f09ea6fbSJakub Kicinski .prepare_data = stats_prepare_data,
439f09ea6fbSJakub Kicinski .reply_size = stats_reply_size,
440f09ea6fbSJakub Kicinski .fill_reply = stats_fill_reply,
441f09ea6fbSJakub Kicinski };
442449c5459SVladimir Oltean
ethtool_stats_sum(u64 a,u64 b)443449c5459SVladimir Oltean static u64 ethtool_stats_sum(u64 a, u64 b)
444449c5459SVladimir Oltean {
445449c5459SVladimir Oltean if (a == ETHTOOL_STAT_NOT_SET)
446449c5459SVladimir Oltean return b;
447449c5459SVladimir Oltean if (b == ETHTOOL_STAT_NOT_SET)
448449c5459SVladimir Oltean return a;
449449c5459SVladimir Oltean return a + b;
450449c5459SVladimir Oltean }
451449c5459SVladimir Oltean
452449c5459SVladimir Oltean /* Avoid modifying the aggregation procedure every time a new counter is added
453449c5459SVladimir Oltean * by treating the structures as an array of u64 statistics.
454449c5459SVladimir Oltean */
ethtool_aggregate_stats(void * aggr_stats,const void * emac_stats,const void * pmac_stats,size_t stats_size,size_t stats_offset)455449c5459SVladimir Oltean static void ethtool_aggregate_stats(void *aggr_stats, const void *emac_stats,
456449c5459SVladimir Oltean const void *pmac_stats, size_t stats_size,
457449c5459SVladimir Oltean size_t stats_offset)
458449c5459SVladimir Oltean {
459449c5459SVladimir Oltean size_t num_stats = stats_size / sizeof(u64);
460449c5459SVladimir Oltean const u64 *s1 = emac_stats + stats_offset;
461449c5459SVladimir Oltean const u64 *s2 = pmac_stats + stats_offset;
462449c5459SVladimir Oltean u64 *s = aggr_stats + stats_offset;
463449c5459SVladimir Oltean int i;
464449c5459SVladimir Oltean
465449c5459SVladimir Oltean for (i = 0; i < num_stats; i++)
466449c5459SVladimir Oltean s[i] = ethtool_stats_sum(s1[i], s2[i]);
467449c5459SVladimir Oltean }
468449c5459SVladimir Oltean
ethtool_aggregate_mac_stats(struct net_device * dev,struct ethtool_eth_mac_stats * mac_stats)469449c5459SVladimir Oltean void ethtool_aggregate_mac_stats(struct net_device *dev,
470449c5459SVladimir Oltean struct ethtool_eth_mac_stats *mac_stats)
471449c5459SVladimir Oltean {
472449c5459SVladimir Oltean const struct ethtool_ops *ops = dev->ethtool_ops;
473449c5459SVladimir Oltean struct ethtool_eth_mac_stats pmac, emac;
474449c5459SVladimir Oltean
475449c5459SVladimir Oltean memset(&emac, 0xff, sizeof(emac));
476449c5459SVladimir Oltean memset(&pmac, 0xff, sizeof(pmac));
477449c5459SVladimir Oltean emac.src = ETHTOOL_MAC_STATS_SRC_EMAC;
478449c5459SVladimir Oltean pmac.src = ETHTOOL_MAC_STATS_SRC_PMAC;
479449c5459SVladimir Oltean
480449c5459SVladimir Oltean ops->get_eth_mac_stats(dev, &emac);
481449c5459SVladimir Oltean ops->get_eth_mac_stats(dev, &pmac);
482449c5459SVladimir Oltean
483449c5459SVladimir Oltean ethtool_aggregate_stats(mac_stats, &emac, &pmac,
484449c5459SVladimir Oltean sizeof(mac_stats->stats),
485449c5459SVladimir Oltean offsetof(struct ethtool_eth_mac_stats, stats));
486449c5459SVladimir Oltean }
487449c5459SVladimir Oltean EXPORT_SYMBOL(ethtool_aggregate_mac_stats);
488449c5459SVladimir Oltean
ethtool_aggregate_phy_stats(struct net_device * dev,struct ethtool_eth_phy_stats * phy_stats)489449c5459SVladimir Oltean void ethtool_aggregate_phy_stats(struct net_device *dev,
490449c5459SVladimir Oltean struct ethtool_eth_phy_stats *phy_stats)
491449c5459SVladimir Oltean {
492449c5459SVladimir Oltean const struct ethtool_ops *ops = dev->ethtool_ops;
493449c5459SVladimir Oltean struct ethtool_eth_phy_stats pmac, emac;
494449c5459SVladimir Oltean
495449c5459SVladimir Oltean memset(&emac, 0xff, sizeof(emac));
496449c5459SVladimir Oltean memset(&pmac, 0xff, sizeof(pmac));
497449c5459SVladimir Oltean emac.src = ETHTOOL_MAC_STATS_SRC_EMAC;
498449c5459SVladimir Oltean pmac.src = ETHTOOL_MAC_STATS_SRC_PMAC;
499449c5459SVladimir Oltean
500449c5459SVladimir Oltean ops->get_eth_phy_stats(dev, &emac);
501449c5459SVladimir Oltean ops->get_eth_phy_stats(dev, &pmac);
502449c5459SVladimir Oltean
503449c5459SVladimir Oltean ethtool_aggregate_stats(phy_stats, &emac, &pmac,
504449c5459SVladimir Oltean sizeof(phy_stats->stats),
505449c5459SVladimir Oltean offsetof(struct ethtool_eth_phy_stats, stats));
506449c5459SVladimir Oltean }
507449c5459SVladimir Oltean EXPORT_SYMBOL(ethtool_aggregate_phy_stats);
508449c5459SVladimir Oltean
ethtool_aggregate_ctrl_stats(struct net_device * dev,struct ethtool_eth_ctrl_stats * ctrl_stats)509449c5459SVladimir Oltean void ethtool_aggregate_ctrl_stats(struct net_device *dev,
510449c5459SVladimir Oltean struct ethtool_eth_ctrl_stats *ctrl_stats)
511449c5459SVladimir Oltean {
512449c5459SVladimir Oltean const struct ethtool_ops *ops = dev->ethtool_ops;
513449c5459SVladimir Oltean struct ethtool_eth_ctrl_stats pmac, emac;
514449c5459SVladimir Oltean
515449c5459SVladimir Oltean memset(&emac, 0xff, sizeof(emac));
516449c5459SVladimir Oltean memset(&pmac, 0xff, sizeof(pmac));
517449c5459SVladimir Oltean emac.src = ETHTOOL_MAC_STATS_SRC_EMAC;
518449c5459SVladimir Oltean pmac.src = ETHTOOL_MAC_STATS_SRC_PMAC;
519449c5459SVladimir Oltean
520449c5459SVladimir Oltean ops->get_eth_ctrl_stats(dev, &emac);
521449c5459SVladimir Oltean ops->get_eth_ctrl_stats(dev, &pmac);
522449c5459SVladimir Oltean
523449c5459SVladimir Oltean ethtool_aggregate_stats(ctrl_stats, &emac, &pmac,
524449c5459SVladimir Oltean sizeof(ctrl_stats->stats),
525449c5459SVladimir Oltean offsetof(struct ethtool_eth_ctrl_stats, stats));
526449c5459SVladimir Oltean }
527449c5459SVladimir Oltean EXPORT_SYMBOL(ethtool_aggregate_ctrl_stats);
528449c5459SVladimir Oltean
ethtool_aggregate_pause_stats(struct net_device * dev,struct ethtool_pause_stats * pause_stats)529449c5459SVladimir Oltean void ethtool_aggregate_pause_stats(struct net_device *dev,
530449c5459SVladimir Oltean struct ethtool_pause_stats *pause_stats)
531449c5459SVladimir Oltean {
532449c5459SVladimir Oltean const struct ethtool_ops *ops = dev->ethtool_ops;
533449c5459SVladimir Oltean struct ethtool_pause_stats pmac, emac;
534449c5459SVladimir Oltean
535449c5459SVladimir Oltean memset(&emac, 0xff, sizeof(emac));
536449c5459SVladimir Oltean memset(&pmac, 0xff, sizeof(pmac));
537449c5459SVladimir Oltean emac.src = ETHTOOL_MAC_STATS_SRC_EMAC;
538449c5459SVladimir Oltean pmac.src = ETHTOOL_MAC_STATS_SRC_PMAC;
539449c5459SVladimir Oltean
540449c5459SVladimir Oltean ops->get_pause_stats(dev, &emac);
541449c5459SVladimir Oltean ops->get_pause_stats(dev, &pmac);
542449c5459SVladimir Oltean
543449c5459SVladimir Oltean ethtool_aggregate_stats(pause_stats, &emac, &pmac,
544449c5459SVladimir Oltean sizeof(pause_stats->stats),
545449c5459SVladimir Oltean offsetof(struct ethtool_pause_stats, stats));
546449c5459SVladimir Oltean }
547449c5459SVladimir Oltean EXPORT_SYMBOL(ethtool_aggregate_pause_stats);
548449c5459SVladimir Oltean
ethtool_aggregate_rmon_stats(struct net_device * dev,struct ethtool_rmon_stats * rmon_stats)549449c5459SVladimir Oltean void ethtool_aggregate_rmon_stats(struct net_device *dev,
550449c5459SVladimir Oltean struct ethtool_rmon_stats *rmon_stats)
551449c5459SVladimir Oltean {
552449c5459SVladimir Oltean const struct ethtool_ops *ops = dev->ethtool_ops;
553449c5459SVladimir Oltean const struct ethtool_rmon_hist_range *dummy;
554449c5459SVladimir Oltean struct ethtool_rmon_stats pmac, emac;
555449c5459SVladimir Oltean
556449c5459SVladimir Oltean memset(&emac, 0xff, sizeof(emac));
557449c5459SVladimir Oltean memset(&pmac, 0xff, sizeof(pmac));
558449c5459SVladimir Oltean emac.src = ETHTOOL_MAC_STATS_SRC_EMAC;
559449c5459SVladimir Oltean pmac.src = ETHTOOL_MAC_STATS_SRC_PMAC;
560449c5459SVladimir Oltean
561449c5459SVladimir Oltean ops->get_rmon_stats(dev, &emac, &dummy);
562449c5459SVladimir Oltean ops->get_rmon_stats(dev, &pmac, &dummy);
563449c5459SVladimir Oltean
564449c5459SVladimir Oltean ethtool_aggregate_stats(rmon_stats, &emac, &pmac,
565449c5459SVladimir Oltean sizeof(rmon_stats->stats),
566449c5459SVladimir Oltean offsetof(struct ethtool_rmon_stats, stats));
567449c5459SVladimir Oltean }
568449c5459SVladimir Oltean EXPORT_SYMBOL(ethtool_aggregate_rmon_stats);
569