Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: ethtool: pse-pd: Target the command to the requested PHY

PSE and PD configuration is a PHY-specific command. Instead of targeting
the command towards dev->phydev, use the request to pick the targeted
PHY device.

As we don't get the PHY directly from the netdev's attached phydev, also
adjust the error messages.

Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Tested-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Maxime Chevallier and committed by
David S. Miller
31748765 02180fb5

+19 -12
+19 -12
net/ethtool/pse-pd.c
··· 28 28 /* PSE_GET */ 29 29 30 30 const struct nla_policy ethnl_pse_get_policy[ETHTOOL_A_PSE_HEADER + 1] = { 31 - [ETHTOOL_A_PSE_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy), 31 + [ETHTOOL_A_PSE_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy_phy), 32 32 }; 33 33 34 - static int pse_get_pse_attributes(struct net_device *dev, 34 + static int pse_get_pse_attributes(struct phy_device *phydev, 35 35 struct netlink_ext_ack *extack, 36 36 struct pse_reply_data *data) 37 37 { 38 - struct phy_device *phydev = dev->phydev; 39 - 40 38 if (!phydev) { 41 - NL_SET_ERR_MSG(extack, "No PHY is attached"); 39 + NL_SET_ERR_MSG(extack, "No PHY found"); 42 40 return -EOPNOTSUPP; 43 41 } 44 42 ··· 56 58 { 57 59 struct pse_reply_data *data = PSE_REPDATA(reply_base); 58 60 struct net_device *dev = reply_base->dev; 61 + struct nlattr **tb = info->attrs; 62 + struct phy_device *phydev; 59 63 int ret; 60 64 61 65 ret = ethnl_ops_begin(dev); 62 66 if (ret < 0) 63 67 return ret; 64 68 65 - ret = pse_get_pse_attributes(dev, info->extack, data); 69 + phydev = ethnl_req_get_phydev(req_base, tb[ETHTOOL_A_PSE_HEADER], 70 + info->extack); 71 + if (IS_ERR(phydev)) 72 + return -ENODEV; 73 + 74 + ret = pse_get_pse_attributes(phydev, info->extack, data); 66 75 67 76 ethnl_ops_complete(dev); 68 77 ··· 211 206 /* PSE_SET */ 212 207 213 208 const struct nla_policy ethnl_pse_set_policy[ETHTOOL_A_PSE_MAX + 1] = { 214 - [ETHTOOL_A_PSE_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy), 209 + [ETHTOOL_A_PSE_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy_phy), 215 210 [ETHTOOL_A_PODL_PSE_ADMIN_CONTROL] = 216 211 NLA_POLICY_RANGE(NLA_U32, ETHTOOL_PODL_PSE_ADMIN_STATE_DISABLED, 217 212 ETHTOOL_PODL_PSE_ADMIN_STATE_ENABLED), ··· 224 219 static int 225 220 ethnl_set_pse_validate(struct ethnl_req_info *req_info, struct genl_info *info) 226 221 { 227 - struct net_device *dev = req_info->dev; 228 222 struct nlattr **tb = info->attrs; 229 223 struct phy_device *phydev; 230 224 231 - phydev = dev->phydev; 232 - if (!phydev) { 225 + phydev = ethnl_req_get_phydev(req_info, tb[ETHTOOL_A_PSE_HEADER], 226 + info->extack); 227 + if (IS_ERR_OR_NULL(phydev)) { 233 228 NL_SET_ERR_MSG(info->extack, "No PHY is attached"); 234 229 return -EOPNOTSUPP; 235 230 } ··· 260 255 static int 261 256 ethnl_set_pse(struct ethnl_req_info *req_info, struct genl_info *info) 262 257 { 263 - struct net_device *dev = req_info->dev; 264 258 struct nlattr **tb = info->attrs; 265 259 struct phy_device *phydev; 266 260 int ret = 0; 267 261 268 - phydev = dev->phydev; 262 + phydev = ethnl_req_get_phydev(req_info, tb[ETHTOOL_A_PSE_HEADER], 263 + info->extack); 264 + if (IS_ERR_OR_NULL(phydev)) 265 + return -ENODEV; 269 266 270 267 if (tb[ETHTOOL_A_C33_PSE_AVAIL_PW_LIMIT]) { 271 268 unsigned int pw_limit;