From: Heiner Kallweit <hkallweit1@gmail.com>
To: Maxime Chevallier <maxime.chevallier@bootlin.com>, davem@davemloft.net
Cc: 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>,
"Vladimir Oltean" <vladimir.oltean@nxp.com>,
"Köry Maincent" <kory.maincent@bootlin.com>,
"Jesse Brandeburg" <jesse.brandeburg@intel.com>,
"Marek Behún" <kabel@kernel.org>,
"Piergiorgio Beruto" <piergiorgio.beruto@gmail.com>,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
"Nicolò Veronese" <nicveronese@gmail.com>,
"Simon Horman" <horms@kernel.org>,
mwojtas@chromium.org, "Nathan Chancellor" <nathan@kernel.org>,
"Antoine Tenart" <atenart@kernel.org>
Subject: Re: [PATCH net-next 1/2] net: phy: phy_link_topology: Pass netdevice to phy_link_topo helpers
Date: Wed, 8 May 2024 07:43:43 +0200 [thread overview]
Message-ID: <b1ef50ce-40e5-453a-a78a-55e373ad36db@gmail.com> (raw)
In-Reply-To: <20240507102822.2023826-2-maxime.chevallier@bootlin.com>
On 07.05.2024 12:28, Maxime Chevallier wrote:
> The phy link topology's main goal is to better track which PHYs are
> connected to a given netdevice. Make so that the helpers take the
> netdevice as a parameter directly.
>
The commit message should explain what the issue is that you're fixing,
and how this patch fixes it.
> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> Fixes: 6916e461e793 ("net: phy: Introduce ethernet link topology representation")
> Closes: https://lore.kernel.org/netdev/2e11b89d-100f-49e7-9c9a-834cc0b82f97@gmail.com/
> Closes: https://lore.kernel.org/netdev/20240409201553.GA4124869@dev-arch.thelio-3990X/
> ---
> drivers/net/phy/phy_device.c | 25 ++++++++-----------------
> drivers/net/phy/phy_link_topology.c | 13 ++++++++++---
> include/linux/phy_link_topology.h | 21 +++++++++++++--------
> net/ethtool/netlink.c | 2 +-
> 4 files changed, 32 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 616bd7ba46cb..111434201545 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -277,14 +277,6 @@ static void phy_mdio_device_remove(struct mdio_device *mdiodev)
>
> static struct phy_driver genphy_driver;
>
> -static struct phy_link_topology *phy_get_link_topology(struct phy_device *phydev)
> -{
> - if (phydev->attached_dev)
> - return phydev->attached_dev->link_topo;
> -
> - return NULL;
> -}
> -
> static LIST_HEAD(phy_fixup_list);
> static DEFINE_MUTEX(phy_fixup_lock);
>
> @@ -1389,10 +1381,10 @@ static DEVICE_ATTR_RO(phy_standalone);
> int phy_sfp_connect_phy(void *upstream, struct phy_device *phy)
> {
> struct phy_device *phydev = upstream;
> - struct phy_link_topology *topo = phy_get_link_topology(phydev);
> + struct net_device *dev = phydev->attached_dev;
>
> - if (topo)
> - return phy_link_topo_add_phy(topo, phy, PHY_UPSTREAM_PHY, phydev);
> + if (dev)
> + return phy_link_topo_add_phy(dev, phy, PHY_UPSTREAM_PHY, phydev);
>
> return 0;
> }
> @@ -1411,10 +1403,10 @@ EXPORT_SYMBOL(phy_sfp_connect_phy);
> void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy)
> {
> struct phy_device *phydev = upstream;
> - struct phy_link_topology *topo = phy_get_link_topology(phydev);
> + struct net_device *dev = phydev->attached_dev;
>
> - if (topo)
> - phy_link_topo_del_phy(topo, phy);
> + if (dev)
> + phy_link_topo_del_phy(dev, phy);
> }
> EXPORT_SYMBOL(phy_sfp_disconnect_phy);
>
> @@ -1561,8 +1553,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
> if (phydev->sfp_bus_attached)
> dev->sfp_bus = phydev->sfp_bus;
>
> - err = phy_link_topo_add_phy(dev->link_topo, phydev,
> - PHY_UPSTREAM_MAC, dev);
> + err = phy_link_topo_add_phy(dev, phydev, PHY_UPSTREAM_MAC, dev);
> if (err)
> goto error;
> }
> @@ -1992,7 +1983,7 @@ void phy_detach(struct phy_device *phydev)
> if (dev) {
> phydev->attached_dev->phydev = NULL;
> phydev->attached_dev = NULL;
> - phy_link_topo_del_phy(dev->link_topo, phydev);
> + phy_link_topo_del_phy(dev, phydev);
> }
> phydev->phylink = NULL;
>
> diff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link_topology.c
> index 985941c5c558..0e36bd7c15dc 100644
> --- a/drivers/net/phy/phy_link_topology.c
> +++ b/drivers/net/phy/phy_link_topology.c
> @@ -35,10 +35,11 @@ void phy_link_topo_destroy(struct phy_link_topology *topo)
> kfree(topo);
> }
>
> -int phy_link_topo_add_phy(struct phy_link_topology *topo,
> +int phy_link_topo_add_phy(struct net_device *dev,
> struct phy_device *phy,
> enum phy_upstream upt, void *upstream)
> {
> + struct phy_link_topology *topo = dev->link_topo;
> struct phy_device_node *pdn;
> int ret;
>
> @@ -90,10 +91,16 @@ int phy_link_topo_add_phy(struct phy_link_topology *topo,
> }
> EXPORT_SYMBOL_GPL(phy_link_topo_add_phy);
>
> -void phy_link_topo_del_phy(struct phy_link_topology *topo,
> +void phy_link_topo_del_phy(struct net_device *dev,
> struct phy_device *phy)
> {
> - struct phy_device_node *pdn = xa_erase(&topo->phys, phy->phyindex);
> + struct phy_link_topology *topo = dev->link_topo;
> + struct phy_device_node *pdn;
> +
> + if (!topo)
> + return;
> +
> + pdn = xa_erase(&topo->phys, phy->phyindex);
>
> /* We delete the PHY from the topology, however we don't re-set the
> * phy->phyindex field. If the PHY isn't gone, we can re-assign it the
> diff --git a/include/linux/phy_link_topology.h b/include/linux/phy_link_topology.h
> index 6b79feb607e7..166a01710aa2 100644
> --- a/include/linux/phy_link_topology.h
> +++ b/include/linux/phy_link_topology.h
> @@ -12,11 +12,11 @@
> #define __PHY_LINK_TOPOLOGY_H
>
> #include <linux/ethtool.h>
> +#include <linux/netdevice.h>
> #include <linux/phy_link_topology_core.h>
>
> struct xarray;
> struct phy_device;
> -struct net_device;
> struct sfp_bus;
>
> struct phy_device_node {
> @@ -37,11 +37,16 @@ struct phy_link_topology {
> u32 next_phy_index;
> };
>
> -static inline struct phy_device *
> -phy_link_topo_get_phy(struct phy_link_topology *topo, u32 phyindex)
> +static inline struct phy_device
> +*phy_link_topo_get_phy(struct net_device *dev, u32 phyindex)
> {
> - struct phy_device_node *pdn = xa_load(&topo->phys, phyindex);
> + struct phy_link_topology *topo = dev->link_topo;
> + struct phy_device_node *pdn;
>
> + if (!topo)
> + return NULL;
> +
> + pdn = xa_load(&topo->phys, phyindex);
> if (pdn)
> return pdn->phy;
>
> @@ -49,21 +54,21 @@ phy_link_topo_get_phy(struct phy_link_topology *topo, u32 phyindex)
> }
>
> #if IS_REACHABLE(CONFIG_PHYLIB)
> -int phy_link_topo_add_phy(struct phy_link_topology *topo,
> +int phy_link_topo_add_phy(struct net_device *dev,
> struct phy_device *phy,
> enum phy_upstream upt, void *upstream);
>
> -void phy_link_topo_del_phy(struct phy_link_topology *lt, struct phy_device *phy);
> +void phy_link_topo_del_phy(struct net_device *dev, struct phy_device *phy);
>
> #else
> -static inline int phy_link_topo_add_phy(struct phy_link_topology *topo,
> +static inline int phy_link_topo_add_phy(struct net_device *dev,
> struct phy_device *phy,
> enum phy_upstream upt, void *upstream)
> {
> return 0;
> }
>
> -static inline void phy_link_topo_del_phy(struct phy_link_topology *topo,
> +static inline void phy_link_topo_del_phy(struct net_device *dev,
> struct phy_device *phy)
> {
> }
> diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c
> index 563e94e0cbd8..f5b4adf324bc 100644
> --- a/net/ethtool/netlink.c
> +++ b/net/ethtool/netlink.c
> @@ -170,7 +170,7 @@ int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info,
> struct nlattr *phy_id;
>
> phy_id = tb[ETHTOOL_A_HEADER_PHY_INDEX];
> - phydev = phy_link_topo_get_phy(dev->link_topo,
> + phydev = phy_link_topo_get_phy(dev,
> nla_get_u32(phy_id));
> if (!phydev) {
> NL_SET_BAD_ATTR(extack, phy_id);
next prev parent reply other threads:[~2024-05-08 5:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-07 10:28 [PATCH net-next 0/2] Fix phy_link_topology initialization Maxime Chevallier
2024-05-07 10:28 ` [PATCH net-next 1/2] net: phy: phy_link_topology: Pass netdevice to phy_link_topo helpers Maxime Chevallier
2024-05-08 5:43 ` Heiner Kallweit [this message]
2024-05-07 10:28 ` [PATCH net-next 2/2] net: phy: phy_link_topology: Lazy-initialize the link topology Maxime Chevallier
2024-05-07 23:08 ` kernel test robot
2024-05-08 5:44 ` Heiner Kallweit
2024-05-13 7:30 ` Maxime Chevallier
2024-05-13 8:07 ` Maxime Chevallier
2024-05-13 8:15 ` Maxime Chevallier
2024-05-13 6:36 ` [PATCH net-next 0/2] Fix phy_link_topology initialization Nathan Chancellor
2024-05-13 9:15 ` Russell King (Oracle)
2024-05-13 15:11 ` Jakub Kicinski
2024-05-14 6:46 ` Maxime Chevallier
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=b1ef50ce-40e5-453a-a78a-55e373ad36db@gmail.com \
--to=hkallweit1@gmail.com \
--cc=andrew@lunn.ch \
--cc=atenart@kernel.org \
--cc=christophe.leroy@csgroup.eu \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=herve.codina@bootlin.com \
--cc=horms@kernel.org \
--cc=jesse.brandeburg@intel.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=maxime.chevallier@bootlin.com \
--cc=mwojtas@chromium.org \
--cc=nathan@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nicveronese@gmail.com \
--cc=o.rempel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=piergiorgio.beruto@gmail.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).