mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
ethtool: linkstate: add a statistic for PHY down events
The previous attempt to augment carrier_down (see Link) was not met with much enthusiasm so let's do the simple thing of exposing what some devices already maintain. Add a common ethtool statistic for link going down. Currently users have to maintain per-driver mapping to extract the right stat from the vendor-specific ethtool -S stats. carrier_down does not fit the bill because it counts a lot of software related false positives. Add the statistic to the extended link state API to steer vendors towards implementing all of it. Implement for bnxt and all Linux-controlled PHYs. mlx5 and (possibly) enic also have a counter for this but I leave the implementation to their maintainers. Link: https://lore.kernel.org/r/20220520004500.2250674-1-kuba@kernel.org Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Reviewed-by: Michael Chan <michael.chan@broadcom.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Link: https://lore.kernel.org/r/20221104190125.684910-1-kuba@kernel.org Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
committed by
Paolo Abeni
parent
91c596cc8d
commit
9a0f830f80
@@ -13,6 +13,7 @@ struct linkstate_reply_data {
|
||||
int link;
|
||||
int sqi;
|
||||
int sqi_max;
|
||||
struct ethtool_link_ext_stats link_stats;
|
||||
bool link_ext_state_provided;
|
||||
struct ethtool_link_ext_state_info ethtool_link_ext_state_info;
|
||||
};
|
||||
@@ -22,7 +23,7 @@ struct linkstate_reply_data {
|
||||
|
||||
const struct nla_policy ethnl_linkstate_get_policy[] = {
|
||||
[ETHTOOL_A_LINKSTATE_HEADER] =
|
||||
NLA_POLICY_NESTED(ethnl_header_policy),
|
||||
NLA_POLICY_NESTED(ethnl_header_policy_stats),
|
||||
};
|
||||
|
||||
static int linkstate_get_sqi(struct net_device *dev)
|
||||
@@ -107,6 +108,19 @@ static int linkstate_prepare_data(const struct ethnl_req_info *req_base,
|
||||
goto out;
|
||||
}
|
||||
|
||||
ethtool_stats_init((u64 *)&data->link_stats,
|
||||
sizeof(data->link_stats) / 8);
|
||||
|
||||
if (req_base->flags & ETHTOOL_FLAG_STATS) {
|
||||
if (dev->phydev)
|
||||
data->link_stats.link_down_events =
|
||||
READ_ONCE(dev->phydev->link_down_events);
|
||||
|
||||
if (dev->ethtool_ops->get_link_ext_stats)
|
||||
dev->ethtool_ops->get_link_ext_stats(dev,
|
||||
&data->link_stats);
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
out:
|
||||
ethnl_ops_complete(dev);
|
||||
@@ -134,6 +148,9 @@ static int linkstate_reply_size(const struct ethnl_req_info *req_base,
|
||||
if (data->ethtool_link_ext_state_info.__link_ext_substate)
|
||||
len += nla_total_size(sizeof(u8)); /* LINKSTATE_EXT_SUBSTATE */
|
||||
|
||||
if (data->link_stats.link_down_events != ETHTOOL_STAT_NOT_SET)
|
||||
len += nla_total_size(sizeof(u32));
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
@@ -166,6 +183,11 @@ static int linkstate_fill_reply(struct sk_buff *skb,
|
||||
return -EMSGSIZE;
|
||||
}
|
||||
|
||||
if (data->link_stats.link_down_events != ETHTOOL_STAT_NOT_SET)
|
||||
if (nla_put_u32(skb, ETHTOOL_A_LINKSTATE_EXT_DOWN_CNT,
|
||||
data->link_stats.link_down_events))
|
||||
return -EMSGSIZE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user