Commit 3688ff30 authored by Maxime Chevallier's avatar Maxime Chevallier Committed by David S. Miller

net: ethtool: cable-test: Target the command to the requested PHY

Cable testing is a PHY-specific command. Instead of targeting the command
towards dev->phydev, use the request to pick the targeted PHY.
Signed-off-by: default avatarMaxime Chevallier <maxime.chevallier@bootlin.com>
Reviewed-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
Tested-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 31748765
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
const struct nla_policy ethnl_cable_test_act_policy[] = { const struct nla_policy ethnl_cable_test_act_policy[] = {
[ETHTOOL_A_CABLE_TEST_HEADER] = [ETHTOOL_A_CABLE_TEST_HEADER] =
NLA_POLICY_NESTED(ethnl_header_policy), NLA_POLICY_NESTED(ethnl_header_policy_phy),
}; };
static int ethnl_cable_test_started(struct phy_device *phydev, u8 cmd) static int ethnl_cable_test_started(struct phy_device *phydev, u8 cmd)
...@@ -58,6 +58,7 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info) ...@@ -58,6 +58,7 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info)
struct ethnl_req_info req_info = {}; struct ethnl_req_info req_info = {};
const struct ethtool_phy_ops *ops; const struct ethtool_phy_ops *ops;
struct nlattr **tb = info->attrs; struct nlattr **tb = info->attrs;
struct phy_device *phydev;
struct net_device *dev; struct net_device *dev;
int ret; int ret;
...@@ -69,12 +70,16 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info) ...@@ -69,12 +70,16 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info)
return ret; return ret;
dev = req_info.dev; dev = req_info.dev;
if (!dev->phydev) {
rtnl_lock();
phydev = ethnl_req_get_phydev(&req_info,
tb[ETHTOOL_A_CABLE_TEST_HEADER],
info->extack);
if (IS_ERR_OR_NULL(phydev)) {
ret = -EOPNOTSUPP; ret = -EOPNOTSUPP;
goto out_dev_put; goto out_dev_put;
} }
rtnl_lock();
ops = ethtool_phy_ops; ops = ethtool_phy_ops;
if (!ops || !ops->start_cable_test) { if (!ops || !ops->start_cable_test) {
ret = -EOPNOTSUPP; ret = -EOPNOTSUPP;
...@@ -85,13 +90,12 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info) ...@@ -85,13 +90,12 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info)
if (ret < 0) if (ret < 0)
goto out_rtnl; goto out_rtnl;
ret = ops->start_cable_test(dev->phydev, info->extack); ret = ops->start_cable_test(phydev, info->extack);
ethnl_ops_complete(dev); ethnl_ops_complete(dev);
if (!ret) if (!ret)
ethnl_cable_test_started(dev->phydev, ethnl_cable_test_started(phydev, ETHTOOL_MSG_CABLE_TEST_NTF);
ETHTOOL_MSG_CABLE_TEST_NTF);
out_rtnl: out_rtnl:
rtnl_unlock(); rtnl_unlock();
...@@ -216,7 +220,7 @@ static const struct nla_policy cable_test_tdr_act_cfg_policy[] = { ...@@ -216,7 +220,7 @@ static const struct nla_policy cable_test_tdr_act_cfg_policy[] = {
const struct nla_policy ethnl_cable_test_tdr_act_policy[] = { const struct nla_policy ethnl_cable_test_tdr_act_policy[] = {
[ETHTOOL_A_CABLE_TEST_TDR_HEADER] = [ETHTOOL_A_CABLE_TEST_TDR_HEADER] =
NLA_POLICY_NESTED(ethnl_header_policy), NLA_POLICY_NESTED(ethnl_header_policy_phy),
[ETHTOOL_A_CABLE_TEST_TDR_CFG] = { .type = NLA_NESTED }, [ETHTOOL_A_CABLE_TEST_TDR_CFG] = { .type = NLA_NESTED },
}; };
...@@ -305,6 +309,7 @@ int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info) ...@@ -305,6 +309,7 @@ int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info)
struct ethnl_req_info req_info = {}; struct ethnl_req_info req_info = {};
const struct ethtool_phy_ops *ops; const struct ethtool_phy_ops *ops;
struct nlattr **tb = info->attrs; struct nlattr **tb = info->attrs;
struct phy_device *phydev;
struct phy_tdr_config cfg; struct phy_tdr_config cfg;
struct net_device *dev; struct net_device *dev;
int ret; int ret;
...@@ -317,10 +322,6 @@ int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info) ...@@ -317,10 +322,6 @@ int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info)
return ret; return ret;
dev = req_info.dev; dev = req_info.dev;
if (!dev->phydev) {
ret = -EOPNOTSUPP;
goto out_dev_put;
}
ret = ethnl_act_cable_test_tdr_cfg(tb[ETHTOOL_A_CABLE_TEST_TDR_CFG], ret = ethnl_act_cable_test_tdr_cfg(tb[ETHTOOL_A_CABLE_TEST_TDR_CFG],
info, &cfg); info, &cfg);
...@@ -328,6 +329,14 @@ int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info) ...@@ -328,6 +329,14 @@ int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info)
goto out_dev_put; goto out_dev_put;
rtnl_lock(); rtnl_lock();
phydev = ethnl_req_get_phydev(&req_info,
tb[ETHTOOL_A_CABLE_TEST_TDR_HEADER],
info->extack);
if (!IS_ERR_OR_NULL(phydev)) {
ret = -EOPNOTSUPP;
goto out_dev_put;
}
ops = ethtool_phy_ops; ops = ethtool_phy_ops;
if (!ops || !ops->start_cable_test_tdr) { if (!ops || !ops->start_cable_test_tdr) {
ret = -EOPNOTSUPP; ret = -EOPNOTSUPP;
...@@ -338,12 +347,12 @@ int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info) ...@@ -338,12 +347,12 @@ int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info)
if (ret < 0) if (ret < 0)
goto out_rtnl; goto out_rtnl;
ret = ops->start_cable_test_tdr(dev->phydev, info->extack, &cfg); ret = ops->start_cable_test_tdr(phydev, info->extack, &cfg);
ethnl_ops_complete(dev); ethnl_ops_complete(dev);
if (!ret) if (!ret)
ethnl_cable_test_started(dev->phydev, ethnl_cable_test_started(phydev,
ETHTOOL_MSG_CABLE_TEST_TDR_NTF); ETHTOOL_MSG_CABLE_TEST_TDR_NTF);
out_rtnl: out_rtnl:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment