Skip to content

Commit fe55b1d

Browse files
oleremPaolo Abeni
authored andcommitted
ethtool: linkstate: migrate linkstate functions to support multi-PHY setups
Adapt linkstate_get_sqi() and linkstate_get_sqi_max() to take a phy_device argument directly, enabling support for setups with multiple PHYs. The previous assumption of a single PHY attached to a net_device no longer holds. Use ethnl_req_get_phydev() to identify the appropriate PHY device for the operation. Update linkstate_prepare_data() and related logic to accommodate this change, ensuring compatibility with multi-PHY configurations. Signed-off-by: Oleksij Rempel <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 6a46e3e commit fe55b1d

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

net/ethtool/linkstate.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ const struct nla_policy ethnl_linkstate_get_policy[] = {
2626
NLA_POLICY_NESTED(ethnl_header_policy_stats),
2727
};
2828

29-
static int linkstate_get_sqi(struct net_device *dev)
29+
static int linkstate_get_sqi(struct phy_device *phydev)
3030
{
31-
struct phy_device *phydev = dev->phydev;
3231
int ret;
3332

3433
if (!phydev)
@@ -46,9 +45,8 @@ static int linkstate_get_sqi(struct net_device *dev)
4645
return ret;
4746
}
4847

49-
static int linkstate_get_sqi_max(struct net_device *dev)
48+
static int linkstate_get_sqi_max(struct phy_device *phydev)
5049
{
51-
struct phy_device *phydev = dev->phydev;
5250
int ret;
5351

5452
if (!phydev)
@@ -100,19 +98,28 @@ static int linkstate_prepare_data(const struct ethnl_req_info *req_base,
10098
{
10199
struct linkstate_reply_data *data = LINKSTATE_REPDATA(reply_base);
102100
struct net_device *dev = reply_base->dev;
101+
struct nlattr **tb = info->attrs;
102+
struct phy_device *phydev;
103103
int ret;
104104

105+
phydev = ethnl_req_get_phydev(req_base, tb[ETHTOOL_A_LINKSTATE_HEADER],
106+
info->extack);
107+
if (IS_ERR(phydev)) {
108+
ret = PTR_ERR(phydev);
109+
goto out;
110+
}
111+
105112
ret = ethnl_ops_begin(dev);
106113
if (ret < 0)
107114
return ret;
108115
data->link = __ethtool_get_link(dev);
109116

110-
ret = linkstate_get_sqi(dev);
117+
ret = linkstate_get_sqi(phydev);
111118
if (linkstate_sqi_critical_error(ret))
112119
goto out;
113120
data->sqi = ret;
114121

115-
ret = linkstate_get_sqi_max(dev);
122+
ret = linkstate_get_sqi_max(phydev);
116123
if (linkstate_sqi_critical_error(ret))
117124
goto out;
118125
data->sqi_max = ret;
@@ -127,9 +134,9 @@ static int linkstate_prepare_data(const struct ethnl_req_info *req_base,
127134
sizeof(data->link_stats) / 8);
128135

129136
if (req_base->flags & ETHTOOL_FLAG_STATS) {
130-
if (dev->phydev)
137+
if (phydev)
131138
data->link_stats.link_down_events =
132-
READ_ONCE(dev->phydev->link_down_events);
139+
READ_ONCE(phydev->link_down_events);
133140

134141
if (dev->ethtool_ops->get_link_ext_stats)
135142
dev->ethtool_ops->get_link_ext_stats(dev,

0 commit comments

Comments
 (0)