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

net: ethtool: plca: Target the command to the requested PHY

PLCA is a PHY-specific command. Instead of targeting the command
towards dev->phydev, use the request to pick the targeted PHY.

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
02180fb5 d3d9a3e4

+20 -10
+20 -10
net/ethtool/plca.c
··· 25 25 26 26 const struct nla_policy ethnl_plca_get_cfg_policy[] = { 27 27 [ETHTOOL_A_PLCA_HEADER] = 28 - NLA_POLICY_NESTED(ethnl_header_policy), 28 + NLA_POLICY_NESTED(ethnl_header_policy_phy), 29 29 }; 30 30 31 31 static void plca_update_sint(int *dst, struct nlattr **tb, u32 attrid, ··· 58 58 struct plca_reply_data *data = PLCA_REPDATA(reply_base); 59 59 struct net_device *dev = reply_base->dev; 60 60 const struct ethtool_phy_ops *ops; 61 + struct nlattr **tb = info->attrs; 62 + struct phy_device *phydev; 61 63 int ret; 62 64 65 + phydev = ethnl_req_get_phydev(req_base, tb[ETHTOOL_A_PLCA_HEADER], 66 + info->extack); 63 67 // check that the PHY device is available and connected 64 - if (!dev->phydev) { 68 + if (IS_ERR_OR_NULL(phydev)) { 65 69 ret = -EOPNOTSUPP; 66 70 goto out; 67 71 } ··· 84 80 memset(&data->plca_cfg, 0xff, 85 81 sizeof_field(struct plca_reply_data, plca_cfg)); 86 82 87 - ret = ops->get_plca_cfg(dev->phydev, &data->plca_cfg); 83 + ret = ops->get_plca_cfg(phydev, &data->plca_cfg); 88 84 ethnl_ops_complete(dev); 89 85 90 86 out: ··· 133 129 134 130 const struct nla_policy ethnl_plca_set_cfg_policy[] = { 135 131 [ETHTOOL_A_PLCA_HEADER] = 136 - NLA_POLICY_NESTED(ethnl_header_policy), 132 + NLA_POLICY_NESTED(ethnl_header_policy_phy), 137 133 [ETHTOOL_A_PLCA_ENABLED] = NLA_POLICY_MAX(NLA_U8, 1), 138 134 [ETHTOOL_A_PLCA_NODE_ID] = NLA_POLICY_MAX(NLA_U32, 255), 139 135 [ETHTOOL_A_PLCA_NODE_CNT] = NLA_POLICY_RANGE(NLA_U32, 1, 255), ··· 145 141 static int 146 142 ethnl_set_plca(struct ethnl_req_info *req_info, struct genl_info *info) 147 143 { 148 - struct net_device *dev = req_info->dev; 149 144 const struct ethtool_phy_ops *ops; 150 145 struct nlattr **tb = info->attrs; 151 146 struct phy_plca_cfg plca_cfg; 147 + struct phy_device *phydev; 152 148 bool mod = false; 153 149 int ret; 154 150 151 + phydev = ethnl_req_get_phydev(req_info, tb[ETHTOOL_A_PLCA_HEADER], 152 + info->extack); 155 153 // check that the PHY device is available and connected 156 - if (!dev->phydev) 154 + if (IS_ERR_OR_NULL(phydev)) 157 155 return -EOPNOTSUPP; 158 156 159 157 ops = ethtool_phy_ops; ··· 174 168 if (!mod) 175 169 return 0; 176 170 177 - ret = ops->set_plca_cfg(dev->phydev, &plca_cfg, info->extack); 171 + ret = ops->set_plca_cfg(phydev, &plca_cfg, info->extack); 178 172 return ret < 0 ? ret : 1; 179 173 } 180 174 ··· 197 191 198 192 const struct nla_policy ethnl_plca_get_status_policy[] = { 199 193 [ETHTOOL_A_PLCA_HEADER] = 200 - NLA_POLICY_NESTED(ethnl_header_policy), 194 + NLA_POLICY_NESTED(ethnl_header_policy_phy), 201 195 }; 202 196 203 197 static int plca_get_status_prepare_data(const struct ethnl_req_info *req_base, ··· 207 201 struct plca_reply_data *data = PLCA_REPDATA(reply_base); 208 202 struct net_device *dev = reply_base->dev; 209 203 const struct ethtool_phy_ops *ops; 204 + struct nlattr **tb = info->attrs; 205 + struct phy_device *phydev; 210 206 int ret; 211 207 208 + phydev = ethnl_req_get_phydev(req_base, tb[ETHTOOL_A_PLCA_HEADER], 209 + info->extack); 212 210 // check that the PHY device is available and connected 213 - if (!dev->phydev) { 211 + if (IS_ERR_OR_NULL(phydev)) { 214 212 ret = -EOPNOTSUPP; 215 213 goto out; 216 214 } ··· 233 223 memset(&data->plca_st, 0xff, 234 224 sizeof_field(struct plca_reply_data, plca_st)); 235 225 236 - ret = ops->get_plca_status(dev->phydev, &data->plca_st); 226 + ret = ops->get_plca_status(phydev, &data->plca_st); 237 227 ethnl_ops_complete(dev); 238 228 out: 239 229 return ret;