From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: davem@davemloft.net
Cc: "Maxime Chevallier" <maxime.chevallier@bootlin.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
thomas.petazzoni@bootlin.com, "Andrew Lunn" <andrew@lunn.ch>,
"Jakub Kicinski" <kuba@kernel.org>,
"Eric Dumazet" <edumazet@google.com>,
"Paolo Abeni" <pabeni@redhat.com>,
"Russell King" <linux@armlinux.org.uk>,
linux-arm-kernel@lists.infradead.org,
"Christophe Leroy" <christophe.leroy@csgroup.eu>,
"Herve Codina" <herve.codina@bootlin.com>,
"Florian Fainelli" <f.fainelli@gmail.com>,
"Heiner Kallweit" <hkallweit1@gmail.com>,
"Vladimir Oltean" <vladimir.oltean@nxp.com>,
"Marek Behún" <kabel@kernel.org>,
"Köry Maincent" <kory.maincent@bootlin.com>,
"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: [PATCH net-next 6/7] net: ethtool: phy: allow reporting and setting the phy isolate status
Date: Wed, 11 Sep 2024 23:27:10 +0200 [thread overview]
Message-ID: <20240911212713.2178943-7-maxime.chevallier@bootlin.com> (raw)
In-Reply-To: <20240911212713.2178943-1-maxime.chevallier@bootlin.com>
Add the isolate and loopback status information to the ETHTOOL_PHY_GET
netlink command attributes, and allow changing these parameters from a
newly-introduced ETHTOOL_PHY_SET command.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
Documentation/networking/ethtool-netlink.rst | 2 +
include/uapi/linux/ethtool_netlink.h | 3 +
net/ethtool/netlink.c | 8 +++
net/ethtool/netlink.h | 1 +
net/ethtool/phy.c | 75 ++++++++++++++++++++
5 files changed, 89 insertions(+)
diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst
index ba90457b8b2d..bbd4ca8b9dbd 100644
--- a/Documentation/networking/ethtool-netlink.rst
+++ b/Documentation/networking/ethtool-netlink.rst
@@ -2234,6 +2234,8 @@ Kernel response contents:
bus, the name of this sfp bus
``ETHTOOL_A_PHY_DOWNSTREAM_SFP_NAME`` string if the phy controls an sfp bus,
the name of the sfp bus
+ ``ETHTOOL_A_PHY_ISOLATE`` u8 The PHY Isolate status
+ ``ETHTOOL_A_PHY_LOOPBACK`` u8 The PHY Loopback status
===================================== ====== ===============================
When ``ETHTOOL_A_PHY_UPSTREAM_TYPE`` is PHY_UPSTREAM_PHY, the PHY's parent is
diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h
index 283305f6b063..070565dcf497 100644
--- a/include/uapi/linux/ethtool_netlink.h
+++ b/include/uapi/linux/ethtool_netlink.h
@@ -59,6 +59,7 @@ enum {
ETHTOOL_MSG_MM_SET,
ETHTOOL_MSG_MODULE_FW_FLASH_ACT,
ETHTOOL_MSG_PHY_GET,
+ ETHTOOL_MSG_PHY_SET,
/* add new constants above here */
__ETHTOOL_MSG_USER_CNT,
@@ -1079,6 +1080,8 @@ enum {
ETHTOOL_A_PHY_UPSTREAM_INDEX, /* u32 */
ETHTOOL_A_PHY_UPSTREAM_SFP_NAME, /* string */
ETHTOOL_A_PHY_DOWNSTREAM_SFP_NAME, /* string */
+ ETHTOOL_A_PHY_ISOLATE, /* u8 */
+ ETHTOOL_A_PHY_LOOPBACK, /* u8 */
/* add new constants above here */
__ETHTOOL_A_PHY_CNT,
diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c
index e3f0ef6b851b..26982f47a934 100644
--- a/net/ethtool/netlink.c
+++ b/net/ethtool/netlink.c
@@ -394,6 +394,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = {
[ETHTOOL_MSG_PLCA_GET_STATUS] = ðnl_plca_status_request_ops,
[ETHTOOL_MSG_MM_GET] = ðnl_mm_request_ops,
[ETHTOOL_MSG_MM_SET] = ðnl_mm_request_ops,
+ [ETHTOOL_MSG_PHY_SET] = ðnl_phy_request_ops,
};
static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)
@@ -1243,6 +1244,13 @@ static const struct genl_ops ethtool_genl_ops[] = {
.policy = ethnl_phy_get_policy,
.maxattr = ARRAY_SIZE(ethnl_phy_get_policy) - 1,
},
+ {
+ .cmd = ETHTOOL_MSG_PHY_SET,
+ .flags = GENL_UNS_ADMIN_PERM,
+ .doit = ethnl_default_set_doit,
+ .policy = ethnl_phy_set_policy,
+ .maxattr = ARRAY_SIZE(ethnl_phy_set_policy) - 1,
+ },
};
static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h
index 203b08eb6c6f..7ae73e2eab32 100644
--- a/net/ethtool/netlink.h
+++ b/net/ethtool/netlink.h
@@ -485,6 +485,7 @@ extern const struct nla_policy ethnl_mm_get_policy[ETHTOOL_A_MM_HEADER + 1];
extern const struct nla_policy ethnl_mm_set_policy[ETHTOOL_A_MM_MAX + 1];
extern const struct nla_policy ethnl_module_fw_flash_act_policy[ETHTOOL_A_MODULE_FW_FLASH_PASSWORD + 1];
extern const struct nla_policy ethnl_phy_get_policy[ETHTOOL_A_PHY_HEADER + 1];
+extern const struct nla_policy ethnl_phy_set_policy[ETHTOOL_A_PHY_MAX + 1];
int ethnl_set_features(struct sk_buff *skb, struct genl_info *info);
int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info);
diff --git a/net/ethtool/phy.c b/net/ethtool/phy.c
index 99d2a8b6144c..cc1dc45a6264 100644
--- a/net/ethtool/phy.c
+++ b/net/ethtool/phy.c
@@ -30,10 +30,13 @@ ethnl_phy_reply_size(const struct ethnl_req_info *req_base,
struct phy_req_info *req_info = PHY_REQINFO(req_base);
struct phy_device_node *pdn = req_info->pdn;
struct phy_device *phydev = pdn->phy;
+ const struct ethtool_phy_ops *ops;
size_t size = 0;
ASSERT_RTNL();
+ ops = ethtool_phy_ops;
+
/* ETHTOOL_A_PHY_INDEX */
size += nla_total_size(sizeof(u32));
@@ -66,6 +69,14 @@ ethnl_phy_reply_size(const struct ethnl_req_info *req_base,
size += nla_total_size(strlen(sfp_name) + 1);
}
+ if (ops && ops->get_config) {
+ /* ETHTOOL_A_PHY_ISOLATE */
+ size += nla_total_size(sizeof(u8));
+
+ /* ETHTOOL_A_PHY_LOOPBACK */
+ size += nla_total_size(sizeof(u8));
+ }
+
return size;
}
@@ -75,10 +86,20 @@ ethnl_phy_fill_reply(const struct ethnl_req_info *req_base, struct sk_buff *skb)
struct phy_req_info *req_info = PHY_REQINFO(req_base);
struct phy_device_node *pdn = req_info->pdn;
struct phy_device *phydev = pdn->phy;
+ const struct ethtool_phy_ops *ops;
+ struct phy_device_config cfg;
enum phy_upstream ptype;
+ int ret;
ptype = pdn->upstream_type;
+ ops = ethtool_phy_ops;
+ if (ops && ops->get_config) {
+ ret = ops->get_config(phydev, &cfg);
+ if (ret)
+ return ret;
+ }
+
if (nla_put_u32(skb, ETHTOOL_A_PHY_INDEX, phydev->phyindex) ||
nla_put_string(skb, ETHTOOL_A_PHY_NAME, dev_name(&phydev->mdio.dev)) ||
nla_put_u32(skb, ETHTOOL_A_PHY_UPSTREAM_TYPE, ptype))
@@ -114,6 +135,14 @@ ethnl_phy_fill_reply(const struct ethnl_req_info *req_base, struct sk_buff *skb)
return -EMSGSIZE;
}
+ /* Append PHY configuration, if possible */
+ if (!ops || !ops->get_config)
+ return 0;
+
+ if (nla_put_u8(skb, ETHTOOL_A_PHY_ISOLATE, cfg.isolate) ||
+ nla_put_u8(skb, ETHTOOL_A_PHY_LOOPBACK, cfg.loopback))
+ return -EMSGSIZE;
+
return 0;
}
@@ -311,3 +340,49 @@ int ethnl_phy_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
return ret;
}
+
+const struct nla_policy ethnl_phy_set_policy[] = {
+ [ETHTOOL_A_PHY_HEADER] =
+ NLA_POLICY_NESTED(ethnl_header_policy_phy),
+ [ETHTOOL_A_PHY_ISOLATE] = NLA_POLICY_MAX(NLA_U8, 1),
+ [ETHTOOL_A_PHY_LOOPBACK] = NLA_POLICY_MAX(NLA_U8, 1),
+};
+
+static int ethnl_set_phy(struct ethnl_req_info *req_info, struct genl_info *info)
+{
+ struct netlink_ext_ack *extack = info->extack;
+ const struct ethtool_phy_ops *ops;
+ struct nlattr **tb = info->attrs;
+ struct phy_device_config cfg;
+ struct phy_device *phydev;
+ bool mod = false;
+ int ret;
+
+ ops = ethtool_phy_ops;
+ if (!ops || !ops->set_config || !ops->get_config)
+ return -EOPNOTSUPP;
+
+ /* We're running under rtnl */
+ phydev = ethnl_req_get_phydev(req_info, tb[ETHTOOL_A_PHY_HEADER],
+ extack);
+ if (IS_ERR_OR_NULL(phydev))
+ return -ENODEV;
+
+ ret = ops->get_config(phydev, &cfg);
+ if (ret)
+ return ret;
+
+ ethnl_update_bool(&cfg.isolate, tb[ETHTOOL_A_PHY_ISOLATE], &mod);
+ ethnl_update_bool(&cfg.loopback, tb[ETHTOOL_A_PHY_LOOPBACK], &mod);
+
+ if (!mod)
+ return 0;
+
+ /* Returning 0 is fine as we don't have a notification */
+ return ops->set_config(phydev, &cfg, extack);
+}
+
+const struct ethnl_request_ops ethnl_phy_request_ops = {
+ .hdr_attr = ETHTOOL_A_PHY_HEADER,
+ .set = ethnl_set_phy,
+};
--
2.46.0
next prev parent reply other threads:[~2024-09-11 21:33 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-11 21:27 [PATCH net-next 0/7] Allow controlling PHY loopback and isolate modes Maxime Chevallier
2024-09-11 21:27 ` [PATCH net-next 1/7] net: phy: allow isolating PHY devices Maxime Chevallier
2024-09-12 18:30 ` Florian Fainelli
2024-09-13 7:43 ` Maxime Chevallier
2024-09-11 21:27 ` [PATCH net-next 2/7] net: phy: Allow flagging PHY devices that can't isolate their MII Maxime Chevallier
2024-09-11 21:27 ` [PATCH net-next 3/7] net: phy: lxt: Mark LXT973 PHYs as having a broken isolate mode Maxime Chevallier
2024-09-12 12:24 ` Simon Horman
2024-09-12 12:56 ` Maxime Chevallier
2024-09-13 5:29 ` kernel test robot
2024-09-11 21:27 ` [PATCH net-next 4/7] net: phy: marvell10g: 88x3310 and 88x3340 don't support " Maxime Chevallier
2024-09-11 21:27 ` [PATCH net-next 5/7] net: phy: introduce ethtool_phy_ops to get and set phy configuration Maxime Chevallier
2024-09-12 4:46 ` Oleksij Rempel
2024-09-12 8:17 ` Maxime Chevallier
2024-09-11 21:27 ` Maxime Chevallier [this message]
2024-09-11 21:27 ` [PATCH net-next 7/7] netlink: specs: introduce phy-set command along with configurable attributes Maxime Chevallier
2024-09-12 8:15 ` [PATCH net-next 0/7] Allow controlling PHY loopback and isolate modes Maxime Chevallier
2024-09-12 18:21 ` Andrew Lunn
2024-09-12 18:26 ` Florian Fainelli
2024-09-13 7:34 ` Maxime Chevallier
2024-09-13 13:40 ` Andrew Lunn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240911212713.2178943-7-maxime.chevallier@bootlin.com \
--to=maxime.chevallier@bootlin.com \
--cc=andrew@lunn.ch \
--cc=christophe.leroy@csgroup.eu \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=herve.codina@bootlin.com \
--cc=hkallweit1@gmail.com \
--cc=kabel@kernel.org \
--cc=kory.maincent@bootlin.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vladimir.oltean@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).