netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/4] introduce mii_bmcr_encode_fixed()
@ 2022-06-18 10:00 Russell King (Oracle)
  2022-06-18 10:28 ` [PATCH net-next 1/4] net: mii: add mii_bmcr_encode_fixed() Russell King (Oracle)
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Russell King (Oracle) @ 2022-06-18 10:00 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Jose Abreu,
	netdev, Paolo Abeni

Hi,

While converting the mv88e6xxx driver to phylink pcs, it has been
noticed that we've started to have repeated cases where we convert a
speed and duplex to a BMCR value.

Rather than open coding this in multiple locations, let's provide a
helper for this - in linux/mii.h. This helper not only takes care of
the standard 10, 100 and 1000Mbps encodings, but also includes
2500Mbps (which is the same as 1000Mbps) for those users who require
that encoding as well. Unknown speeds will be encoded to 10Mbps, and
non-full duplexes will be encoded as half duplex.

This series converts the existing users to the new helper, and the
mv88e6xxx conversion will add further users in the 6352 and 639x PCS
code.

 drivers/net/pcs/pcs-xpcs.c   | 18 +-----------------
 drivers/net/phy/marvell.c    | 10 ++--------
 drivers/net/phy/phy_device.c | 18 +++---------------
 include/linux/mii.h          | 35 +++++++++++++++++++++++++++++++++++
 4 files changed, 41 insertions(+), 40 deletions(-)

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net-next 1/4] net: mii: add mii_bmcr_encode_fixed()
  2022-06-18 10:00 [PATCH net-next 0/4] introduce mii_bmcr_encode_fixed() Russell King (Oracle)
@ 2022-06-18 10:28 ` Russell King (Oracle)
  2022-06-18 10:28 ` [PATCH net-next 2/4] net: phy: use mii_bmcr_encode_fixed() Russell King (Oracle)
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Russell King (Oracle) @ 2022-06-18 10:28 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Jose Abreu,
	netdev, Paolo Abeni

Add a function to encode a fixed speed/duplex to a BMCR value.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 include/linux/mii.h | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/include/linux/mii.h b/include/linux/mii.h
index 5ee13083cec7..d5a959ce4877 100644
--- a/include/linux/mii.h
+++ b/include/linux/mii.h
@@ -545,4 +545,39 @@ static inline u8 mii_resolve_flowctrl_fdx(u16 lcladv, u16 rmtadv)
 	return cap;
 }
 
+/**
+ * mii_bmcr_encode_fixed - encode fixed speed/duplex settings to a BMCR value
+ * @speed: a SPEED_* value
+ * @duplex: a DUPLEX_* value
+ *
+ * Encode the speed and duplex to a BMCR value. 2500, 1000, 100 and 10 Mbps are
+ * supported. 2500Mbps is encoded to 1000Mbps. Other speeds are encoded as 10
+ * Mbps. Unknown duplex values are encoded to half-duplex.
+ */
+static inline u16 mii_bmcr_encode_fixed(int speed, int duplex)
+{
+	u16 bmcr;
+
+	switch (speed) {
+	case SPEED_2500:
+	case SPEED_1000:
+		bmcr = BMCR_SPEED1000;
+		break;
+
+	case SPEED_100:
+		bmcr = BMCR_SPEED100;
+		break;
+
+	case SPEED_10:
+	default:
+		bmcr = BMCR_SPEED10;
+		break;
+	}
+
+	if (duplex == DUPLEX_FULL)
+		bmcr |= BMCR_FULLDPLX;
+
+	return bmcr;
+}
+
 #endif /* __LINUX_MII_H__ */
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 2/4] net: phy: use mii_bmcr_encode_fixed()
  2022-06-18 10:00 [PATCH net-next 0/4] introduce mii_bmcr_encode_fixed() Russell King (Oracle)
  2022-06-18 10:28 ` [PATCH net-next 1/4] net: mii: add mii_bmcr_encode_fixed() Russell King (Oracle)
@ 2022-06-18 10:28 ` Russell King (Oracle)
  2022-06-18 10:28 ` [PATCH net-next 3/4] net: phy: marvell: " Russell King (Oracle)
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Russell King (Oracle) @ 2022-06-18 10:28 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Jose Abreu,
	netdev, Paolo Abeni

phylib can make use of the newly introduced mii_bmcr_encode_fixed()
macro, so let's convert it over.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/phy/phy_device.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 431a8719c635..7885bceff773 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -2001,18 +2001,12 @@ EXPORT_SYMBOL(genphy_config_eee_advert);
  */
 int genphy_setup_forced(struct phy_device *phydev)
 {
-	u16 ctl = 0;
+	u16 ctl;
 
 	phydev->pause = 0;
 	phydev->asym_pause = 0;
 
-	if (SPEED_1000 == phydev->speed)
-		ctl |= BMCR_SPEED1000;
-	else if (SPEED_100 == phydev->speed)
-		ctl |= BMCR_SPEED100;
-
-	if (DUPLEX_FULL == phydev->duplex)
-		ctl |= BMCR_FULLDPLX;
+	ctl = mii_bmcr_encode_fixed(phydev->speed, phydev->duplex);
 
 	return phy_modify(phydev, MII_BMCR,
 			  ~(BMCR_LOOPBACK | BMCR_ISOLATE | BMCR_PDOWN), ctl);
@@ -2614,13 +2608,7 @@ int genphy_loopback(struct phy_device *phydev, bool enable)
 		u16 val, ctl = BMCR_LOOPBACK;
 		int ret;
 
-		if (phydev->speed == SPEED_1000)
-			ctl |= BMCR_SPEED1000;
-		else if (phydev->speed == SPEED_100)
-			ctl |= BMCR_SPEED100;
-
-		if (phydev->duplex == DUPLEX_FULL)
-			ctl |= BMCR_FULLDPLX;
+		ctl |= mii_bmcr_encode_fixed(phydev->speed, phydev->duplex);
 
 		phy_modify(phydev, MII_BMCR, ~0, ctl);
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 3/4] net: phy: marvell: use mii_bmcr_encode_fixed()
  2022-06-18 10:00 [PATCH net-next 0/4] introduce mii_bmcr_encode_fixed() Russell King (Oracle)
  2022-06-18 10:28 ` [PATCH net-next 1/4] net: mii: add mii_bmcr_encode_fixed() Russell King (Oracle)
  2022-06-18 10:28 ` [PATCH net-next 2/4] net: phy: use mii_bmcr_encode_fixed() Russell King (Oracle)
@ 2022-06-18 10:28 ` Russell King (Oracle)
  2022-06-18 10:28 ` [PATCH net-next 4/4] net: pcs: pcs-xpcs: " Russell King (Oracle)
  2022-06-19  9:50 ` [PATCH net-next 0/4] introduce mii_bmcr_encode_fixed() patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Russell King (Oracle) @ 2022-06-18 10:28 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Jose Abreu,
	netdev, Paolo Abeni

Make use of the newly introduced mii_bmcr_encode_fixed() to get the
BMCR value when setting loopback mode for the 88e1510.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/phy/marvell.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index d777c8851ed6..a714150f5e8c 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -1991,15 +1991,9 @@ static int m88e1510_loopback(struct phy_device *phydev, bool enable)
 	int err;
 
 	if (enable) {
-		u16 bmcr_ctl = 0, mscr2_ctl = 0;
+		u16 bmcr_ctl, mscr2_ctl = 0;
 
-		if (phydev->speed == SPEED_1000)
-			bmcr_ctl = BMCR_SPEED1000;
-		else if (phydev->speed == SPEED_100)
-			bmcr_ctl = BMCR_SPEED100;
-
-		if (phydev->duplex == DUPLEX_FULL)
-			bmcr_ctl |= BMCR_FULLDPLX;
+		bmcr_ctl = mii_bmcr_encode_fixed(phydev->speed, phydev->duplex);
 
 		err = phy_write(phydev, MII_BMCR, bmcr_ctl);
 		if (err < 0)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 4/4] net: pcs: pcs-xpcs: use mii_bmcr_encode_fixed()
  2022-06-18 10:00 [PATCH net-next 0/4] introduce mii_bmcr_encode_fixed() Russell King (Oracle)
                   ` (2 preceding siblings ...)
  2022-06-18 10:28 ` [PATCH net-next 3/4] net: phy: marvell: " Russell King (Oracle)
@ 2022-06-18 10:28 ` Russell King (Oracle)
  2022-06-19  9:50 ` [PATCH net-next 0/4] introduce mii_bmcr_encode_fixed() patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Russell King (Oracle) @ 2022-06-18 10:28 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Jose Abreu,
	netdev, Paolo Abeni

Use the newly introduced mii_bmcr_encode_fixed() for the xpcs driver.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/pcs/pcs-xpcs.c | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c
index a5d520e34ea3..ab0af1d2531f 100644
--- a/drivers/net/pcs/pcs-xpcs.c
+++ b/drivers/net/pcs/pcs-xpcs.c
@@ -1081,23 +1081,7 @@ static void xpcs_link_up_sgmii(struct dw_xpcs *xpcs, unsigned int mode,
 	if (phylink_autoneg_inband(mode))
 		return;
 
-	switch (speed) {
-	case SPEED_1000:
-		val = BMCR_SPEED1000;
-		break;
-	case SPEED_100:
-		val = BMCR_SPEED100;
-		break;
-	case SPEED_10:
-		val = BMCR_SPEED10;
-		break;
-	default:
-		return;
-	}
-
-	if (duplex == DUPLEX_FULL)
-		val |= BMCR_FULLDPLX;
-
+	val = mii_bmcr_encode_fixed(speed, duplex);
 	ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1, val);
 	if (ret)
 		pr_err("%s: xpcs_write returned %pe\n", __func__, ERR_PTR(ret));
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 0/4] introduce mii_bmcr_encode_fixed()
  2022-06-18 10:00 [PATCH net-next 0/4] introduce mii_bmcr_encode_fixed() Russell King (Oracle)
                   ` (3 preceding siblings ...)
  2022-06-18 10:28 ` [PATCH net-next 4/4] net: pcs: pcs-xpcs: " Russell King (Oracle)
@ 2022-06-19  9:50 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-06-19  9:50 UTC (permalink / raw)
  To: Russell King
  Cc: andrew, hkallweit1, davem, edumazet, kuba, Jose.Abreu, netdev, pabeni

Hello:

This series was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Sat, 18 Jun 2022 11:00:18 +0100 you wrote:
> Hi,
> 
> While converting the mv88e6xxx driver to phylink pcs, it has been
> noticed that we've started to have repeated cases where we convert a
> speed and duplex to a BMCR value.
> 
> Rather than open coding this in multiple locations, let's provide a
> helper for this - in linux/mii.h. This helper not only takes care of
> the standard 10, 100 and 1000Mbps encodings, but also includes
> 2500Mbps (which is the same as 1000Mbps) for those users who require
> that encoding as well. Unknown speeds will be encoded to 10Mbps, and
> non-full duplexes will be encoded as half duplex.
> 
> [...]

Here is the summary with links:
  - [net-next,1/4] net: mii: add mii_bmcr_encode_fixed()
    https://git.kernel.org/netdev/net-next/c/bdb6cfe7512f
  - [net-next,2/4] net: phy: use mii_bmcr_encode_fixed()
    https://git.kernel.org/netdev/net-next/c/f28a602b285e
  - [net-next,3/4] net: phy: marvell: use mii_bmcr_encode_fixed()
    https://git.kernel.org/netdev/net-next/c/e62dbaff4bc2
  - [net-next,4/4] net: pcs: pcs-xpcs: use mii_bmcr_encode_fixed()
    https://git.kernel.org/netdev/net-next/c/449b7a15200a

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-06-19  9:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-18 10:00 [PATCH net-next 0/4] introduce mii_bmcr_encode_fixed() Russell King (Oracle)
2022-06-18 10:28 ` [PATCH net-next 1/4] net: mii: add mii_bmcr_encode_fixed() Russell King (Oracle)
2022-06-18 10:28 ` [PATCH net-next 2/4] net: phy: use mii_bmcr_encode_fixed() Russell King (Oracle)
2022-06-18 10:28 ` [PATCH net-next 3/4] net: phy: marvell: " Russell King (Oracle)
2022-06-18 10:28 ` [PATCH net-next 4/4] net: pcs: pcs-xpcs: " Russell King (Oracle)
2022-06-19  9:50 ` [PATCH net-next 0/4] introduce mii_bmcr_encode_fixed() patchwork-bot+netdevbpf

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).