From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: netdev@vger.kernel.org
Cc: Antoine Tenart <atenart@kernel.org>,
Quentin Schulz <quentin.schulz@bootlin.com>,
Michael Walle <michael@walle.cc>,
Heiner Kallweit <hkallweit1@gmail.com>,
Andrew Lunn <andrew@lunn.ch>,
Florian Fainelli <f.fainelli@gmail.com>,
Russell King - ARM Linux admin <linux@armlinux.org.uk>,
Ioana Ciornei <ioana.ciornei@nxp.com>,
Maxim Kochetkov <fido_max@inbox.ru>,
Bjarni Jonasson <bjarni.jonasson@microchip.com>,
Steen Hegelund <steen.hegelund@microchip.com>,
UNGLinuxDriver@microchip.com,
bcm-kernel-feedback-list@broadcom.com
Subject: [RFC PATCH v2 net-next 1/5] net: phylink: pass the phy argument to phylink_sfp_config
Date: Mon, 30 Aug 2021 18:52:46 +0300 [thread overview]
Message-ID: <20210830155250.4029923-2-vladimir.oltean@nxp.com> (raw)
In-Reply-To: <20210830155250.4029923-1-vladimir.oltean@nxp.com>
Problem statement: I would like to move the phy_no_inband() check inside
phylink_sfp_config(), right _after_ the PHY mode was determined by
sfp_select_interface(). But phylink_sfp_config() does not take the "phy"
as argument, only one of its callers (phylink_sfp_connect_phy) does.
phylink_sfp_config is called from:
- phylink_sfp_module_insert, if we know that the SFP module may not have
a PHY
- phylink_sfp_module_start, if the SFP module may have a PHY but it is
not available here (otherwise the "if (pl->phydev)" check right above
would have triggered)
- phylink_sfp_connect_phy, which by definition has a PHY
So of all 3 callers, 2 are certain there is no PHY at that particular
moment, and 1 is certain there is one.
After further analysis, the "mode" is assumed to be MLO_AN_INBAND unless
there is a PHY, and that PHY has broken inband capabilities. So if we
pass the PHY pointer (be it NULL), we can drop the "mode" argument and
deduce it locally.
To avoid a forward-declaration, this change also moves phylink_phy_no_inband
above phylink_sfp_config.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/phy/phylink.c | 39 +++++++++++++++++++--------------------
1 file changed, 19 insertions(+), 20 deletions(-)
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 2cdf9f989dec..28edb3665ee9 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -2035,6 +2035,15 @@ int phylink_speed_up(struct phylink *pl)
}
EXPORT_SYMBOL_GPL(phylink_speed_up);
+/* The Broadcom BCM84881 in the Methode DM7052 is unable to provide a SGMII
+ * or 802.3z control word, so inband will not work.
+ */
+static bool phylink_phy_no_inband(struct phy_device *phy)
+{
+ return phy->is_c45 &&
+ (phy->c45_ids.device_ids[1] & 0xfffffff0) == 0xae025150;
+}
+
static void phylink_sfp_attach(void *upstream, struct sfp_bus *bus)
{
struct phylink *pl = upstream;
@@ -2049,7 +2058,7 @@ static void phylink_sfp_detach(void *upstream, struct sfp_bus *bus)
pl->netdev->sfp_bus = NULL;
}
-static int phylink_sfp_config(struct phylink *pl, u8 mode,
+static int phylink_sfp_config(struct phylink *pl, struct phy_device *phy,
const unsigned long *supported,
const unsigned long *advertising)
{
@@ -2057,6 +2066,7 @@ static int phylink_sfp_config(struct phylink *pl, u8 mode,
__ETHTOOL_DECLARE_LINK_MODE_MASK(support);
struct phylink_link_state config;
phy_interface_t iface;
+ unsigned int mode;
bool changed;
int ret;
@@ -2086,6 +2096,11 @@ static int phylink_sfp_config(struct phylink *pl, u8 mode,
return -EINVAL;
}
+ if (phy && phylink_phy_no_inband(phy))
+ mode = MLO_AN_PHY;
+ else
+ mode = MLO_AN_INBAND;
+
config.interface = iface;
linkmode_copy(support1, support);
ret = phylink_validate(pl, support1, &config);
@@ -2148,7 +2163,7 @@ static int phylink_sfp_module_insert(void *upstream,
if (pl->sfp_may_have_phy)
return 0;
- return phylink_sfp_config(pl, MLO_AN_INBAND, support, support);
+ return phylink_sfp_config(pl, NULL, support, support);
}
static int phylink_sfp_module_start(void *upstream)
@@ -2167,8 +2182,7 @@ static int phylink_sfp_module_start(void *upstream)
if (!pl->sfp_may_have_phy)
return 0;
- return phylink_sfp_config(pl, MLO_AN_INBAND,
- pl->sfp_support, pl->sfp_support);
+ return phylink_sfp_config(pl, NULL, pl->sfp_support, pl->sfp_support);
}
static void phylink_sfp_module_stop(void *upstream)
@@ -2199,20 +2213,10 @@ static void phylink_sfp_link_up(void *upstream)
phylink_run_resolve(pl);
}
-/* The Broadcom BCM84881 in the Methode DM7052 is unable to provide a SGMII
- * or 802.3z control word, so inband will not work.
- */
-static bool phylink_phy_no_inband(struct phy_device *phy)
-{
- return phy->is_c45 &&
- (phy->c45_ids.device_ids[1] & 0xfffffff0) == 0xae025150;
-}
-
static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy)
{
struct phylink *pl = upstream;
phy_interface_t interface;
- u8 mode;
int ret;
/*
@@ -2224,13 +2228,8 @@ static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy)
*/
phy_support_asym_pause(phy);
- if (phylink_phy_no_inband(phy))
- mode = MLO_AN_PHY;
- else
- mode = MLO_AN_INBAND;
-
/* Do the initial configuration */
- ret = phylink_sfp_config(pl, mode, phy->supported, phy->advertising);
+ ret = phylink_sfp_config(pl, phy, phy->supported, phy->advertising);
if (ret < 0)
return ret;
--
2.25.1
next prev parent reply other threads:[~2021-08-30 15:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-30 15:52 [RFC PATCH v2 net-next 0/5] Let phylink manage in-band AN for the PHY Vladimir Oltean
2021-08-30 15:52 ` Vladimir Oltean [this message]
2021-08-30 15:52 ` [RFC PATCH v2 net-next 2/5] net: phylink: introduce a generic method for querying PHY in-band autoneg capability Vladimir Oltean
2021-08-30 15:52 ` [RFC PATCH v2 net-next 3/5] net: phy: bcm84881: move the in-band capability check where it belongs Vladimir Oltean
2021-08-30 15:52 ` [RFC PATCH v2 net-next 4/5] net: phylink: explicitly configure in-band autoneg for PHYs that support it Vladimir Oltean
2021-08-30 15:52 ` [RFC PATCH v2 net-next 5/5] net: phy: mscc: configure in-band auto-negotiation for VSC8514 Vladimir Oltean
2021-08-30 18:30 ` [RFC PATCH v2 net-next 0/5] Let phylink manage in-band AN for the PHY Russell King (Oracle)
2021-08-30 18:36 ` Vladimir Oltean
2021-09-16 13:09 ` Vladimir Oltean
2021-09-16 13:51 ` Michael Walle
2021-09-16 13:54 ` Vladimir Oltean
2021-09-16 14:05 ` Michael Walle
2021-09-16 14:07 ` Vladimir Oltean
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=20210830155250.4029923-2-vladimir.oltean@nxp.com \
--to=vladimir.oltean@nxp.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew@lunn.ch \
--cc=atenart@kernel.org \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bjarni.jonasson@microchip.com \
--cc=f.fainelli@gmail.com \
--cc=fido_max@inbox.ru \
--cc=hkallweit1@gmail.com \
--cc=ioana.ciornei@nxp.com \
--cc=linux@armlinux.org.uk \
--cc=michael@walle.cc \
--cc=netdev@vger.kernel.org \
--cc=quentin.schulz@bootlin.com \
--cc=steen.hegelund@microchip.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