netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: netdev <netdev@vger.kernel.org>
Cc: Sean Anderson <sean.anderson@seco.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Russell King <linux@armlinux.org.uk>
Subject: [PATCH net-next] net: phy: swphy: Support all normal speeds when link down
Date: Sun,  4 Dec 2022 18:41:03 +0100	[thread overview]
Message-ID: <20221204174103.1033005-1-andrew@lunn.ch> (raw)

The software PHY emulator validation function is happy to accept any
link speed if the link is down. swphy_read_reg() however triggers a
WARN_ON(). Change this to report all the standard 1G link speeds are
supported. Once the speed is known the supported link modes will
change, which is a bit odd, but for emulation is probably O.K.

Suggested-by: Russell King (Oracle) <linux@armlinux.org.uk>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---

Hi Sean

Does this fix your problem?

drivers/net/phy/swphy.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/drivers/net/phy/swphy.c b/drivers/net/phy/swphy.c
index 59f1ba4d49bc..63bd98217092 100644
--- a/drivers/net/phy/swphy.c
+++ b/drivers/net/phy/swphy.c
@@ -29,8 +29,10 @@ enum {
 	SWMII_SPEED_10 = 0,
 	SWMII_SPEED_100,
 	SWMII_SPEED_1000,
+	SWMII_SPEED_UNKNOWN,
 	SWMII_DUPLEX_HALF = 0,
 	SWMII_DUPLEX_FULL,
+	SWMII_DUPLEX_UNKNOWN,
 };
 
 /*
@@ -51,6 +53,11 @@ static const struct swmii_regs speed[] = {
 		.lpagb = LPA_1000FULL | LPA_1000HALF,
 		.estat = ESTATUS_1000_TFULL | ESTATUS_1000_THALF,
 	},
+	[SWMII_SPEED_UNKNOWN] = {
+		.bmsr  = BMSR_ESTATEN | BMSR_100FULL | BMSR_100HALF |
+			 BMSR_10FULL | BMSR_10HALF,
+		.estat = ESTATUS_1000_TFULL | ESTATUS_1000_THALF,
+	},
 };
 
 static const struct swmii_regs duplex[] = {
@@ -66,6 +73,11 @@ static const struct swmii_regs duplex[] = {
 		.lpagb = LPA_1000FULL,
 		.estat = ESTATUS_1000_TFULL,
 	},
+	[SWMII_DUPLEX_UNKNOWN] = {
+		.bmsr  = BMSR_ESTATEN | BMSR_100FULL | BMSR_100HALF |
+			 BMSR_10FULL | BMSR_10HALF,
+		.estat = ESTATUS_1000_TFULL | ESTATUS_1000_THALF,
+	},
 };
 
 static int swphy_decode_speed(int speed)
@@ -87,8 +99,9 @@ static int swphy_decode_speed(int speed)
  * @state: software phy status
  *
  * This checks that we can represent the state stored in @state can be
- * represented in the emulated MII registers.  Returns 0 if it can,
- * otherwise returns -EINVAL.
+ * represented in the emulated MII registers. Invalid speed is allowed
+ * when the link is down, but the speed must be valid when the link is
+ * up. Returns 0 if it can, otherwise returns -EINVAL.
  */
 int swphy_validate_state(const struct fixed_phy_status *state)
 {
@@ -123,11 +136,14 @@ int swphy_read_reg(int reg, const struct fixed_phy_status *state)
 	if (reg > MII_REGS_NUM)
 		return -1;
 
-	speed_index = swphy_decode_speed(state->speed);
-	if (WARN_ON(speed_index < 0))
-		return 0;
-
-	duplex_index = state->duplex ? SWMII_DUPLEX_FULL : SWMII_DUPLEX_HALF;
+	if (state->link) {
+		speed_index = swphy_decode_speed(state->speed);
+		duplex_index = state->duplex ? SWMII_DUPLEX_FULL :
+			SWMII_DUPLEX_HALF;
+	} else {
+		speed_index = SWMII_SPEED_UNKNOWN;
+		duplex_index = SWMII_DUPLEX_UNKNOWN;
+	}
 
 	bmsr |= speed[speed_index].bmsr & duplex[duplex_index].bmsr;
 	estat |= speed[speed_index].estat & duplex[duplex_index].estat;
-- 
2.38.1


             reply	other threads:[~2022-12-04 17:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-04 17:41 Andrew Lunn [this message]
2022-12-05 15:28 ` [PATCH net-next] net: phy: swphy: Support all normal speeds when link down Sean Anderson
2022-12-05 16:04 ` Russell King (Oracle)
2022-12-05 16:44   ` Andrew Lunn
2022-12-05 16:50     ` Russell King (Oracle)

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=20221204174103.1033005-1-andrew@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=hkallweit1@gmail.com \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=sean.anderson@seco.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).