Commit 04692c90 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller
Browse files

net: ethtool: netlink: retrieve stats from multiple sources (eMAC, pMAC)



IEEE 802.3-2018 clause 99 defines a MAC Merge sublayer which contains an
Express MAC and a Preemptible MAC. Both MACs are hidden to higher and
lower layers and visible as a single MAC (packet classification to eMAC
or pMAC on TX is done based on priority; classification on RX is done
based on SFD).

For devices which support a MAC Merge sublayer, it is desirable to
retrieve individual packet counters from the eMAC and the pMAC, as well
as aggregate statistics (their sum).

Introduce a new ETHTOOL_A_STATS_SRC attribute which is part of the
policy of ETHTOOL_MSG_STATS_GET and, and an ETHTOOL_A_PAUSE_STATS_SRC
which is part of the policy of ETHTOOL_MSG_PAUSE_GET (accepted when
ETHTOOL_FLAG_STATS is set in the common ethtool header). Both of these
take values from enum ethtool_mac_stats_src, defaulting to "aggregate"
in the absence of the attribute.

Existing drivers do not need to pay attention to this enum which was
added to all driver-facing structures, just the ones which report the
MAC merge layer as supported.

Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 37000004
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -311,6 +311,7 @@ static inline void ethtool_stats_init(u64 *stats, unsigned int n)
 * via a more targeted API.
 */
struct ethtool_eth_mac_stats {
	enum ethtool_mac_stats_src src;
	u64 FramesTransmittedOK;
	u64 SingleCollisionFrames;
	u64 MultipleCollisionFrames;
@@ -339,6 +340,7 @@ struct ethtool_eth_mac_stats {
 * via a more targeted API.
 */
struct ethtool_eth_phy_stats {
	enum ethtool_mac_stats_src src;
	u64 SymbolErrorDuringCarrier;
};

@@ -346,6 +348,7 @@ struct ethtool_eth_phy_stats {
 * via a more targeted API.
 */
struct ethtool_eth_ctrl_stats {
	enum ethtool_mac_stats_src src;
	u64 MACControlFramesTransmitted;
	u64 MACControlFramesReceived;
	u64 UnsupportedOpcodesReceived;
@@ -353,6 +356,8 @@ struct ethtool_eth_ctrl_stats {

/**
 * struct ethtool_pause_stats - statistics for IEEE 802.3x pause frames
 * @src: input field denoting whether stats should be queried from the eMAC or
 *	pMAC (if the MM layer is supported). To be ignored otherwise.
 * @tx_pause_frames: transmitted pause frame count. Reported to user space
 *	as %ETHTOOL_A_PAUSE_STAT_TX_FRAMES.
 *
@@ -366,6 +371,7 @@ struct ethtool_eth_ctrl_stats {
 *	from the standard.
 */
struct ethtool_pause_stats {
	enum ethtool_mac_stats_src src;
	u64 tx_pause_frames;
	u64 rx_pause_frames;
};
@@ -417,6 +423,8 @@ struct ethtool_rmon_hist_range {

/**
 * struct ethtool_rmon_stats - selected RMON (RFC 2819) statistics
 * @src: input field denoting whether stats should be queried from the eMAC or
 *	pMAC (if the MM layer is supported). To be ignored otherwise.
 * @undersize_pkts: Equivalent to `etherStatsUndersizePkts` from the RFC.
 * @oversize_pkts: Equivalent to `etherStatsOversizePkts` from the RFC.
 * @fragments: Equivalent to `etherStatsFragments` from the RFC.
@@ -432,6 +440,7 @@ struct ethtool_rmon_hist_range {
 * ranges is left to the driver.
 */
struct ethtool_rmon_stats {
	enum ethtool_mac_stats_src src;
	u64 undersize_pkts;
	u64 oversize_pkts;
	u64 fragments;
+18 −0
Original line number Diff line number Diff line
@@ -711,6 +711,24 @@ enum ethtool_stringset {
	ETH_SS_COUNT
};

/**
 * enum ethtool_mac_stats_src - source of ethtool MAC statistics
 * @ETHTOOL_MAC_STATS_SRC_AGGREGATE:
 *	if device supports a MAC merge layer, this retrieves the aggregate
 *	statistics of the eMAC and pMAC. Otherwise, it retrieves just the
 *	statistics of the single (express) MAC.
 * @ETHTOOL_MAC_STATS_SRC_EMAC:
 *	if device supports a MM layer, this retrieves the eMAC statistics.
 *	Otherwise, it retrieves the statistics of the single (express) MAC.
 * @ETHTOOL_MAC_STATS_SRC_PMAC:
 *	if device supports a MM layer, this retrieves the pMAC statistics.
 */
enum ethtool_mac_stats_src {
	ETHTOOL_MAC_STATS_SRC_AGGREGATE,
	ETHTOOL_MAC_STATS_SRC_EMAC,
	ETHTOOL_MAC_STATS_SRC_PMAC,
};

/**
 * enum ethtool_module_power_mode_policy - plug-in module power mode policy
 * @ETHTOOL_MODULE_POWER_MODE_POLICY_HIGH: Module is always in high power mode.
+3 −0
Original line number Diff line number Diff line
@@ -428,6 +428,7 @@ enum {
	ETHTOOL_A_PAUSE_RX,				/* u8 */
	ETHTOOL_A_PAUSE_TX,				/* u8 */
	ETHTOOL_A_PAUSE_STATS,				/* nest - _PAUSE_STAT_* */
	ETHTOOL_A_PAUSE_STATS_SRC,			/* u32 */

	/* add new constants above here */
	__ETHTOOL_A_PAUSE_CNT,
@@ -744,6 +745,8 @@ enum {

	ETHTOOL_A_STATS_GRP,			/* nest - _A_STATS_GRP_* */

	ETHTOOL_A_STATS_SRC,			/* u32 */

	/* add new constants above here */
	__ETHTOOL_A_STATS_CNT,
	ETHTOOL_A_STATS_MAX = (__ETHTOOL_A_STATS_CNT - 1)
+2 −0
Original line number Diff line number Diff line
@@ -54,4 +54,6 @@ int ethtool_get_module_info_call(struct net_device *dev,
int ethtool_get_module_eeprom_call(struct net_device *dev,
				   struct ethtool_eeprom *ee, u8 *data);

bool __ethtool_dev_mm_supported(struct net_device *dev);

#endif /* _ETHTOOL_COMMON_H */
+16 −0
Original line number Diff line number Diff line
@@ -253,3 +253,19 @@ int ethnl_set_mm(struct sk_buff *skb, struct genl_info *info)
	ethnl_parse_header_dev_put(&req_info);
	return ret;
}

/* Returns whether a given device supports the MAC merge layer
 * (has an eMAC and a pMAC). Must be called under rtnl_lock() and
 * ethnl_ops_begin().
 */
bool __ethtool_dev_mm_supported(struct net_device *dev)
{
	const struct ethtool_ops *ops = dev->ethtool_ops;
	struct ethtool_mm_state state = {};
	int ret = -EOPNOTSUPP;

	if (ops && ops->get_mm)
		ret = ops->get_mm(dev, &state);

	return !!ret;
}
Loading