1 // SPDX-License-Identifier: GPL-2.0-only
7 struct stats_req_info {
8 struct ethnl_req_info base;
9 DECLARE_BITMAP(stat_mask, __ETHTOOL_STATS_CNT);
10 enum ethtool_mac_stats_src src;
13 #define STATS_REQINFO(__req_base) \
14 container_of(__req_base, struct stats_req_info, base)
16 struct stats_reply_data {
17 struct ethnl_reply_data base;
19 struct ethtool_eth_phy_stats phy_stats;
20 struct ethtool_eth_mac_stats mac_stats;
21 struct ethtool_eth_ctrl_stats ctrl_stats;
22 struct ethtool_rmon_stats rmon_stats;
24 const struct ethtool_rmon_hist_range *rmon_ranges;
27 #define STATS_REPDATA(__reply_base) \
28 container_of(__reply_base, struct stats_reply_data, base)
30 const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN] = {
31 [ETHTOOL_STATS_ETH_PHY] = "eth-phy",
32 [ETHTOOL_STATS_ETH_MAC] = "eth-mac",
33 [ETHTOOL_STATS_ETH_CTRL] = "eth-ctrl",
34 [ETHTOOL_STATS_RMON] = "rmon",
37 const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN] = {
38 [ETHTOOL_A_STATS_ETH_PHY_5_SYM_ERR] = "SymbolErrorDuringCarrier",
41 const char stats_eth_mac_names[__ETHTOOL_A_STATS_ETH_MAC_CNT][ETH_GSTRING_LEN] = {
42 [ETHTOOL_A_STATS_ETH_MAC_2_TX_PKT] = "FramesTransmittedOK",
43 [ETHTOOL_A_STATS_ETH_MAC_3_SINGLE_COL] = "SingleCollisionFrames",
44 [ETHTOOL_A_STATS_ETH_MAC_4_MULTI_COL] = "MultipleCollisionFrames",
45 [ETHTOOL_A_STATS_ETH_MAC_5_RX_PKT] = "FramesReceivedOK",
46 [ETHTOOL_A_STATS_ETH_MAC_6_FCS_ERR] = "FrameCheckSequenceErrors",
47 [ETHTOOL_A_STATS_ETH_MAC_7_ALIGN_ERR] = "AlignmentErrors",
48 [ETHTOOL_A_STATS_ETH_MAC_8_TX_BYTES] = "OctetsTransmittedOK",
49 [ETHTOOL_A_STATS_ETH_MAC_9_TX_DEFER] = "FramesWithDeferredXmissions",
50 [ETHTOOL_A_STATS_ETH_MAC_10_LATE_COL] = "LateCollisions",
51 [ETHTOOL_A_STATS_ETH_MAC_11_XS_COL] = "FramesAbortedDueToXSColls",
52 [ETHTOOL_A_STATS_ETH_MAC_12_TX_INT_ERR] = "FramesLostDueToIntMACXmitError",
53 [ETHTOOL_A_STATS_ETH_MAC_13_CS_ERR] = "CarrierSenseErrors",
54 [ETHTOOL_A_STATS_ETH_MAC_14_RX_BYTES] = "OctetsReceivedOK",
55 [ETHTOOL_A_STATS_ETH_MAC_15_RX_INT_ERR] = "FramesLostDueToIntMACRcvError",
56 [ETHTOOL_A_STATS_ETH_MAC_18_TX_MCAST] = "MulticastFramesXmittedOK",
57 [ETHTOOL_A_STATS_ETH_MAC_19_TX_BCAST] = "BroadcastFramesXmittedOK",
58 [ETHTOOL_A_STATS_ETH_MAC_20_XS_DEFER] = "FramesWithExcessiveDeferral",
59 [ETHTOOL_A_STATS_ETH_MAC_21_RX_MCAST] = "MulticastFramesReceivedOK",
60 [ETHTOOL_A_STATS_ETH_MAC_22_RX_BCAST] = "BroadcastFramesReceivedOK",
61 [ETHTOOL_A_STATS_ETH_MAC_23_IR_LEN_ERR] = "InRangeLengthErrors",
62 [ETHTOOL_A_STATS_ETH_MAC_24_OOR_LEN] = "OutOfRangeLengthField",
63 [ETHTOOL_A_STATS_ETH_MAC_25_TOO_LONG_ERR] = "FrameTooLongErrors",
66 const char stats_eth_ctrl_names[__ETHTOOL_A_STATS_ETH_CTRL_CNT][ETH_GSTRING_LEN] = {
67 [ETHTOOL_A_STATS_ETH_CTRL_3_TX] = "MACControlFramesTransmitted",
68 [ETHTOOL_A_STATS_ETH_CTRL_4_RX] = "MACControlFramesReceived",
69 [ETHTOOL_A_STATS_ETH_CTRL_5_RX_UNSUP] = "UnsupportedOpcodesReceived",
72 const char stats_rmon_names[__ETHTOOL_A_STATS_RMON_CNT][ETH_GSTRING_LEN] = {
73 [ETHTOOL_A_STATS_RMON_UNDERSIZE] = "etherStatsUndersizePkts",
74 [ETHTOOL_A_STATS_RMON_OVERSIZE] = "etherStatsOversizePkts",
75 [ETHTOOL_A_STATS_RMON_FRAG] = "etherStatsFragments",
76 [ETHTOOL_A_STATS_RMON_JABBER] = "etherStatsJabbers",
79 const struct nla_policy ethnl_stats_get_policy[ETHTOOL_A_STATS_SRC + 1] = {
80 [ETHTOOL_A_STATS_HEADER] =
81 NLA_POLICY_NESTED(ethnl_header_policy),
82 [ETHTOOL_A_STATS_GROUPS] = { .type = NLA_NESTED },
83 [ETHTOOL_A_STATS_SRC] =
84 NLA_POLICY_MAX(NLA_U32, ETHTOOL_MAC_STATS_SRC_PMAC),
87 static int stats_parse_request(struct ethnl_req_info *req_base,
89 struct netlink_ext_ack *extack)
91 enum ethtool_mac_stats_src src = ETHTOOL_MAC_STATS_SRC_AGGREGATE;
92 struct stats_req_info *req_info = STATS_REQINFO(req_base);
96 err = ethnl_update_bitset(req_info->stat_mask, __ETHTOOL_STATS_CNT,
97 tb[ETHTOOL_A_STATS_GROUPS], stats_std_names,
103 NL_SET_ERR_MSG(extack, "no stats requested");
107 if (tb[ETHTOOL_A_STATS_SRC])
108 src = nla_get_u32(tb[ETHTOOL_A_STATS_SRC]);
115 static int stats_prepare_data(const struct ethnl_req_info *req_base,
116 struct ethnl_reply_data *reply_base,
117 struct genl_info *info)
119 const struct stats_req_info *req_info = STATS_REQINFO(req_base);
120 struct netlink_ext_ack *extack = info ? info->extack : NULL;
121 struct stats_reply_data *data = STATS_REPDATA(reply_base);
122 enum ethtool_mac_stats_src src = req_info->src;
123 struct net_device *dev = reply_base->dev;
126 ret = ethnl_ops_begin(dev);
130 if ((src == ETHTOOL_MAC_STATS_SRC_EMAC ||
131 src == ETHTOOL_MAC_STATS_SRC_PMAC) &&
132 !__ethtool_dev_mm_supported(dev)) {
133 NL_SET_ERR_MSG_MOD(extack,
134 "Device does not support MAC merge layer");
135 ethnl_ops_complete(dev);
139 /* Mark all stats as unset (see ETHTOOL_STAT_NOT_SET) to prevent them
140 * from being reported to user space in case driver did not set them.
142 memset(&data->stats, 0xff, sizeof(data->stats));
144 data->phy_stats.src = src;
145 data->mac_stats.src = src;
146 data->ctrl_stats.src = src;
147 data->rmon_stats.src = src;
149 if (test_bit(ETHTOOL_STATS_ETH_PHY, req_info->stat_mask) &&
150 dev->ethtool_ops->get_eth_phy_stats)
151 dev->ethtool_ops->get_eth_phy_stats(dev, &data->phy_stats);
152 if (test_bit(ETHTOOL_STATS_ETH_MAC, req_info->stat_mask) &&
153 dev->ethtool_ops->get_eth_mac_stats)
154 dev->ethtool_ops->get_eth_mac_stats(dev, &data->mac_stats);
155 if (test_bit(ETHTOOL_STATS_ETH_CTRL, req_info->stat_mask) &&
156 dev->ethtool_ops->get_eth_ctrl_stats)
157 dev->ethtool_ops->get_eth_ctrl_stats(dev, &data->ctrl_stats);
158 if (test_bit(ETHTOOL_STATS_RMON, req_info->stat_mask) &&
159 dev->ethtool_ops->get_rmon_stats)
160 dev->ethtool_ops->get_rmon_stats(dev, &data->rmon_stats,
163 ethnl_ops_complete(dev);
167 static int stats_reply_size(const struct ethnl_req_info *req_base,
168 const struct ethnl_reply_data *reply_base)
170 const struct stats_req_info *req_info = STATS_REQINFO(req_base);
171 unsigned int n_grps = 0, n_stats = 0;
174 len += nla_total_size(sizeof(u32)); /* _STATS_SRC */
176 if (test_bit(ETHTOOL_STATS_ETH_PHY, req_info->stat_mask)) {
177 n_stats += sizeof(struct ethtool_eth_phy_stats) / sizeof(u64);
180 if (test_bit(ETHTOOL_STATS_ETH_MAC, req_info->stat_mask)) {
181 n_stats += sizeof(struct ethtool_eth_mac_stats) / sizeof(u64);
184 if (test_bit(ETHTOOL_STATS_ETH_CTRL, req_info->stat_mask)) {
185 n_stats += sizeof(struct ethtool_eth_ctrl_stats) / sizeof(u64);
188 if (test_bit(ETHTOOL_STATS_RMON, req_info->stat_mask)) {
189 n_stats += sizeof(struct ethtool_rmon_stats) / sizeof(u64);
191 /* Above includes the space for _A_STATS_GRP_HIST_VALs */
193 len += (nla_total_size(0) + /* _A_STATS_GRP_HIST */
194 nla_total_size(4) + /* _A_STATS_GRP_HIST_BKT_LOW */
195 nla_total_size(4)) * /* _A_STATS_GRP_HIST_BKT_HI */
196 ETHTOOL_RMON_HIST_MAX * 2;
199 len += n_grps * (nla_total_size(0) + /* _A_STATS_GRP */
200 nla_total_size(4) + /* _A_STATS_GRP_ID */
201 nla_total_size(4)); /* _A_STATS_GRP_SS_ID */
202 len += n_stats * (nla_total_size(0) + /* _A_STATS_GRP_STAT */
203 nla_total_size_64bit(sizeof(u64)));
208 static int stat_put(struct sk_buff *skb, u16 attrtype, u64 val)
213 if (val == ETHTOOL_STAT_NOT_SET)
216 /* We want to start stats attr types from 0, so we don't have a type
217 * for pad inside ETHTOOL_A_STATS_GRP_STAT. Pad things on the outside
218 * of ETHTOOL_A_STATS_GRP_STAT. Since we're one nest away from the
219 * actual attr we're 4B off - nla_need_padding_for_64bit() & co.
222 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
223 if (!IS_ALIGNED((unsigned long)skb_tail_pointer(skb), 8))
224 if (!nla_reserve(skb, ETHTOOL_A_STATS_GRP_PAD, 0))
228 nest = nla_nest_start(skb, ETHTOOL_A_STATS_GRP_STAT);
232 ret = nla_put_u64_64bit(skb, attrtype, val, -1 /* not used */);
234 nla_nest_cancel(skb, nest);
238 nla_nest_end(skb, nest);
242 static int stats_put_phy_stats(struct sk_buff *skb,
243 const struct stats_reply_data *data)
245 if (stat_put(skb, ETHTOOL_A_STATS_ETH_PHY_5_SYM_ERR,
246 data->phy_stats.SymbolErrorDuringCarrier))
251 static int stats_put_mac_stats(struct sk_buff *skb,
252 const struct stats_reply_data *data)
254 if (stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_2_TX_PKT,
255 data->mac_stats.FramesTransmittedOK) ||
256 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_3_SINGLE_COL,
257 data->mac_stats.SingleCollisionFrames) ||
258 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_4_MULTI_COL,
259 data->mac_stats.MultipleCollisionFrames) ||
260 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_5_RX_PKT,
261 data->mac_stats.FramesReceivedOK) ||
262 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_6_FCS_ERR,
263 data->mac_stats.FrameCheckSequenceErrors) ||
264 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_7_ALIGN_ERR,
265 data->mac_stats.AlignmentErrors) ||
266 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_8_TX_BYTES,
267 data->mac_stats.OctetsTransmittedOK) ||
268 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_9_TX_DEFER,
269 data->mac_stats.FramesWithDeferredXmissions) ||
270 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_10_LATE_COL,
271 data->mac_stats.LateCollisions) ||
272 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_11_XS_COL,
273 data->mac_stats.FramesAbortedDueToXSColls) ||
274 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_12_TX_INT_ERR,
275 data->mac_stats.FramesLostDueToIntMACXmitError) ||
276 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_13_CS_ERR,
277 data->mac_stats.CarrierSenseErrors) ||
278 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_14_RX_BYTES,
279 data->mac_stats.OctetsReceivedOK) ||
280 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_15_RX_INT_ERR,
281 data->mac_stats.FramesLostDueToIntMACRcvError) ||
282 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_18_TX_MCAST,
283 data->mac_stats.MulticastFramesXmittedOK) ||
284 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_19_TX_BCAST,
285 data->mac_stats.BroadcastFramesXmittedOK) ||
286 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_20_XS_DEFER,
287 data->mac_stats.FramesWithExcessiveDeferral) ||
288 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_21_RX_MCAST,
289 data->mac_stats.MulticastFramesReceivedOK) ||
290 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_22_RX_BCAST,
291 data->mac_stats.BroadcastFramesReceivedOK) ||
292 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_23_IR_LEN_ERR,
293 data->mac_stats.InRangeLengthErrors) ||
294 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_24_OOR_LEN,
295 data->mac_stats.OutOfRangeLengthField) ||
296 stat_put(skb, ETHTOOL_A_STATS_ETH_MAC_25_TOO_LONG_ERR,
297 data->mac_stats.FrameTooLongErrors))
302 static int stats_put_ctrl_stats(struct sk_buff *skb,
303 const struct stats_reply_data *data)
305 if (stat_put(skb, ETHTOOL_A_STATS_ETH_CTRL_3_TX,
306 data->ctrl_stats.MACControlFramesTransmitted) ||
307 stat_put(skb, ETHTOOL_A_STATS_ETH_CTRL_4_RX,
308 data->ctrl_stats.MACControlFramesReceived) ||
309 stat_put(skb, ETHTOOL_A_STATS_ETH_CTRL_5_RX_UNSUP,
310 data->ctrl_stats.UnsupportedOpcodesReceived))
315 static int stats_put_rmon_hist(struct sk_buff *skb, u32 attr, const u64 *hist,
316 const struct ethtool_rmon_hist_range *ranges)
324 for (i = 0; i < ETHTOOL_RMON_HIST_MAX; i++) {
325 if (!ranges[i].low && !ranges[i].high)
327 if (hist[i] == ETHTOOL_STAT_NOT_SET)
330 nest = nla_nest_start(skb, attr);
334 if (nla_put_u32(skb, ETHTOOL_A_STATS_GRP_HIST_BKT_LOW,
336 nla_put_u32(skb, ETHTOOL_A_STATS_GRP_HIST_BKT_HI,
338 nla_put_u64_64bit(skb, ETHTOOL_A_STATS_GRP_HIST_VAL,
339 hist[i], ETHTOOL_A_STATS_GRP_PAD))
340 goto err_cancel_hist;
342 nla_nest_end(skb, nest);
348 nla_nest_cancel(skb, nest);
352 static int stats_put_rmon_stats(struct sk_buff *skb,
353 const struct stats_reply_data *data)
355 if (stats_put_rmon_hist(skb, ETHTOOL_A_STATS_GRP_HIST_RX,
356 data->rmon_stats.hist, data->rmon_ranges) ||
357 stats_put_rmon_hist(skb, ETHTOOL_A_STATS_GRP_HIST_TX,
358 data->rmon_stats.hist_tx, data->rmon_ranges))
361 if (stat_put(skb, ETHTOOL_A_STATS_RMON_UNDERSIZE,
362 data->rmon_stats.undersize_pkts) ||
363 stat_put(skb, ETHTOOL_A_STATS_RMON_OVERSIZE,
364 data->rmon_stats.oversize_pkts) ||
365 stat_put(skb, ETHTOOL_A_STATS_RMON_FRAG,
366 data->rmon_stats.fragments) ||
367 stat_put(skb, ETHTOOL_A_STATS_RMON_JABBER,
368 data->rmon_stats.jabbers))
374 static int stats_put_stats(struct sk_buff *skb,
375 const struct stats_reply_data *data,
377 int (*cb)(struct sk_buff *skb,
378 const struct stats_reply_data *data))
382 nest = nla_nest_start(skb, ETHTOOL_A_STATS_GRP);
386 if (nla_put_u32(skb, ETHTOOL_A_STATS_GRP_ID, id) ||
387 nla_put_u32(skb, ETHTOOL_A_STATS_GRP_SS_ID, ss_id))
393 nla_nest_end(skb, nest);
397 nla_nest_cancel(skb, nest);
401 static int stats_fill_reply(struct sk_buff *skb,
402 const struct ethnl_req_info *req_base,
403 const struct ethnl_reply_data *reply_base)
405 const struct stats_req_info *req_info = STATS_REQINFO(req_base);
406 const struct stats_reply_data *data = STATS_REPDATA(reply_base);
409 if (nla_put_u32(skb, ETHTOOL_A_STATS_SRC, req_info->src))
412 if (!ret && test_bit(ETHTOOL_STATS_ETH_PHY, req_info->stat_mask))
413 ret = stats_put_stats(skb, data, ETHTOOL_STATS_ETH_PHY,
414 ETH_SS_STATS_ETH_PHY,
415 stats_put_phy_stats);
416 if (!ret && test_bit(ETHTOOL_STATS_ETH_MAC, req_info->stat_mask))
417 ret = stats_put_stats(skb, data, ETHTOOL_STATS_ETH_MAC,
418 ETH_SS_STATS_ETH_MAC,
419 stats_put_mac_stats);
420 if (!ret && test_bit(ETHTOOL_STATS_ETH_CTRL, req_info->stat_mask))
421 ret = stats_put_stats(skb, data, ETHTOOL_STATS_ETH_CTRL,
422 ETH_SS_STATS_ETH_CTRL,
423 stats_put_ctrl_stats);
424 if (!ret && test_bit(ETHTOOL_STATS_RMON, req_info->stat_mask))
425 ret = stats_put_stats(skb, data, ETHTOOL_STATS_RMON,
426 ETH_SS_STATS_RMON, stats_put_rmon_stats);
431 const struct ethnl_request_ops ethnl_stats_request_ops = {
432 .request_cmd = ETHTOOL_MSG_STATS_GET,
433 .reply_cmd = ETHTOOL_MSG_STATS_GET_REPLY,
434 .hdr_attr = ETHTOOL_A_STATS_HEADER,
435 .req_info_size = sizeof(struct stats_req_info),
436 .reply_data_size = sizeof(struct stats_reply_data),
438 .parse_request = stats_parse_request,
439 .prepare_data = stats_prepare_data,
440 .reply_size = stats_reply_size,
441 .fill_reply = stats_fill_reply,
444 static u64 ethtool_stats_sum(u64 a, u64 b)
446 if (a == ETHTOOL_STAT_NOT_SET)
448 if (b == ETHTOOL_STAT_NOT_SET)
453 /* Avoid modifying the aggregation procedure every time a new counter is added
454 * by treating the structures as an array of u64 statistics.
456 static void ethtool_aggregate_stats(void *aggr_stats, const void *emac_stats,
457 const void *pmac_stats, size_t stats_size,
460 size_t num_stats = stats_size / sizeof(u64);
461 const u64 *s1 = emac_stats + stats_offset;
462 const u64 *s2 = pmac_stats + stats_offset;
463 u64 *s = aggr_stats + stats_offset;
466 for (i = 0; i < num_stats; i++)
467 s[i] = ethtool_stats_sum(s1[i], s2[i]);
470 void ethtool_aggregate_mac_stats(struct net_device *dev,
471 struct ethtool_eth_mac_stats *mac_stats)
473 const struct ethtool_ops *ops = dev->ethtool_ops;
474 struct ethtool_eth_mac_stats pmac, emac;
476 memset(&emac, 0xff, sizeof(emac));
477 memset(&pmac, 0xff, sizeof(pmac));
478 emac.src = ETHTOOL_MAC_STATS_SRC_EMAC;
479 pmac.src = ETHTOOL_MAC_STATS_SRC_PMAC;
481 ops->get_eth_mac_stats(dev, &emac);
482 ops->get_eth_mac_stats(dev, &pmac);
484 ethtool_aggregate_stats(mac_stats, &emac, &pmac,
485 sizeof(mac_stats->stats),
486 offsetof(struct ethtool_eth_mac_stats, stats));
488 EXPORT_SYMBOL(ethtool_aggregate_mac_stats);
490 void ethtool_aggregate_phy_stats(struct net_device *dev,
491 struct ethtool_eth_phy_stats *phy_stats)
493 const struct ethtool_ops *ops = dev->ethtool_ops;
494 struct ethtool_eth_phy_stats pmac, emac;
496 memset(&emac, 0xff, sizeof(emac));
497 memset(&pmac, 0xff, sizeof(pmac));
498 emac.src = ETHTOOL_MAC_STATS_SRC_EMAC;
499 pmac.src = ETHTOOL_MAC_STATS_SRC_PMAC;
501 ops->get_eth_phy_stats(dev, &emac);
502 ops->get_eth_phy_stats(dev, &pmac);
504 ethtool_aggregate_stats(phy_stats, &emac, &pmac,
505 sizeof(phy_stats->stats),
506 offsetof(struct ethtool_eth_phy_stats, stats));
508 EXPORT_SYMBOL(ethtool_aggregate_phy_stats);
510 void ethtool_aggregate_ctrl_stats(struct net_device *dev,
511 struct ethtool_eth_ctrl_stats *ctrl_stats)
513 const struct ethtool_ops *ops = dev->ethtool_ops;
514 struct ethtool_eth_ctrl_stats pmac, emac;
516 memset(&emac, 0xff, sizeof(emac));
517 memset(&pmac, 0xff, sizeof(pmac));
518 emac.src = ETHTOOL_MAC_STATS_SRC_EMAC;
519 pmac.src = ETHTOOL_MAC_STATS_SRC_PMAC;
521 ops->get_eth_ctrl_stats(dev, &emac);
522 ops->get_eth_ctrl_stats(dev, &pmac);
524 ethtool_aggregate_stats(ctrl_stats, &emac, &pmac,
525 sizeof(ctrl_stats->stats),
526 offsetof(struct ethtool_eth_ctrl_stats, stats));
528 EXPORT_SYMBOL(ethtool_aggregate_ctrl_stats);
530 void ethtool_aggregate_pause_stats(struct net_device *dev,
531 struct ethtool_pause_stats *pause_stats)
533 const struct ethtool_ops *ops = dev->ethtool_ops;
534 struct ethtool_pause_stats pmac, emac;
536 memset(&emac, 0xff, sizeof(emac));
537 memset(&pmac, 0xff, sizeof(pmac));
538 emac.src = ETHTOOL_MAC_STATS_SRC_EMAC;
539 pmac.src = ETHTOOL_MAC_STATS_SRC_PMAC;
541 ops->get_pause_stats(dev, &emac);
542 ops->get_pause_stats(dev, &pmac);
544 ethtool_aggregate_stats(pause_stats, &emac, &pmac,
545 sizeof(pause_stats->stats),
546 offsetof(struct ethtool_pause_stats, stats));
548 EXPORT_SYMBOL(ethtool_aggregate_pause_stats);
550 void ethtool_aggregate_rmon_stats(struct net_device *dev,
551 struct ethtool_rmon_stats *rmon_stats)
553 const struct ethtool_ops *ops = dev->ethtool_ops;
554 const struct ethtool_rmon_hist_range *dummy;
555 struct ethtool_rmon_stats pmac, emac;
557 memset(&emac, 0xff, sizeof(emac));
558 memset(&pmac, 0xff, sizeof(pmac));
559 emac.src = ETHTOOL_MAC_STATS_SRC_EMAC;
560 pmac.src = ETHTOOL_MAC_STATS_SRC_PMAC;
562 ops->get_rmon_stats(dev, &emac, &dummy);
563 ops->get_rmon_stats(dev, &pmac, &dummy);
565 ethtool_aggregate_stats(rmon_stats, &emac, &pmac,
566 sizeof(rmon_stats->stats),
567 offsetof(struct ethtool_rmon_stats, stats));
569 EXPORT_SYMBOL(ethtool_aggregate_rmon_stats);