netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: Russell King - ARM Linux admin <linux@armlinux.org.uk>
Cc: netdev@vger.kernel.org, "Andrew Lunn" <andrew@lunn.ch>,
	"Marek Behún" <kabel@kernel.org>
Subject: [PATCH russell-kings-net-queue v2 2/3] net: phy: sfp: add support for multigig RollBall modules
Date: Tue, 20 Oct 2020 17:06:14 +0200	[thread overview]
Message-ID: <20201020150615.11969-3-kabel@kernel.org> (raw)
In-Reply-To: <20201020150615.11969-1-kabel@kernel.org>

This adds support for multigig copper SFP modules from RollBall/Hilink.
These modules have a specific way to access clause 45 registers of the
internal PHY.

We also need to wait at least 25 seconds after deasserting TX disable
before accessing the PHY. The code waits for 30 seconds just to be sure.

Signed-off-by: Marek Behún <kabel@kernel.org>
---
 drivers/net/phy/sfp.c | 69 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 63 insertions(+), 6 deletions(-)

diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 4e47c8e8a529..37b1a9f57ce1 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -167,6 +167,7 @@ static const enum gpiod_flags gpio_flags[] = {
  * on board (for a copper SFP) time to initialise.
  */
 #define T_WAIT			msecs_to_jiffies(50)
+#define T_WAIT_LONG_PHY		msecs_to_jiffies(30000)
 #define T_START_UP		msecs_to_jiffies(300)
 #define T_START_UP_BAD_GPON	msecs_to_jiffies(60000)
 #define T_START_UP_COOLED	msecs_to_jiffies(90000)
@@ -207,8 +208,11 @@ static const enum gpiod_flags gpio_flags[] = {
 
 /* SFP modules appear to always have their PHY configured for bus address
  * 0x56 (which with mdio-i2c, translates to a PHY address of 22).
+ * RollBall SFPs access phy via SFP Enhanced Digital Diagnostic Interface
+ * via address 0x51 (mdio-i2c will use RollBall protocol on this address).
  */
-#define SFP_PHY_ADDR	22
+#define SFP_PHY_ADDR		22
+#define SFP_PHY_ADDR_ROLLBALL	17
 
 struct sff_data {
 	unsigned int gpios;
@@ -223,6 +227,7 @@ struct sfp {
 	struct phy_device *mod_phy;
 	const struct sff_data *type;
 	u32 max_power_mW;
+	int phy_addr;
 
 	unsigned int (*get_state)(struct sfp *);
 	void (*set_state)(struct sfp *, unsigned int);
@@ -251,6 +256,7 @@ struct sfp {
 	struct sfp_eeprom_id id;
 	unsigned int module_power_mW;
 	unsigned int module_t_start_up;
+	unsigned int module_t_wait;
 
 #if IS_ENABLED(CONFIG_HWMON)
 	struct sfp_diag diag;
@@ -1594,7 +1600,7 @@ static int sfp_sm_probe_phy(struct sfp *sfp, bool is_c45)
 	struct phy_device *phy;
 	int err;
 
-	phy = get_phy_device(sfp->i2c_mii, SFP_PHY_ADDR, is_c45);
+	phy = get_phy_device(sfp->i2c_mii, sfp->phy_addr, is_c45);
 	if (phy == ERR_PTR(-ENODEV))
 		return PTR_ERR(phy);
 	if (IS_ERR(phy)) {
@@ -1931,12 +1937,40 @@ static void sfp_print_module_info(struct sfp *sfp, const struct sfp_eeprom_id *i
 			      id->ext.enhopts));
 }
 
+static int sfp_rollball_init_mdio(struct sfp *sfp)
+{
+	u8 page, password[4];
+	int err;
+
+	page = 3;
+
+	err = sfp_write(sfp, true, SFP_PAGE, &page, 1);
+	if (err != 1) {
+		dev_err(sfp->dev, "Failed to set SFP page for RollBall MDIO access: %d\n", err);
+		return err;
+	}
+
+	password[0] = 0xff;
+	password[1] = 0xff;
+	password[2] = 0xff;
+	password[3] = 0xff;
+
+	err = sfp_write(sfp, true, 0x7b, password, 4);
+	if (err != 4) {
+		dev_err(sfp->dev, "Failed to write password for RollBall MDIO access; %d\n", err);
+		return err;
+	}
+
+	return 0;
+}
+
 static int sfp_sm_mod_probe(struct sfp *sfp, bool report)
 {
 	/* SFP module inserted - read I2C data */
 	struct sfp_eeprom_id id;
 	bool cotsworks_sfbg;
 	bool cotsworks;
+	bool rollball;
 	u8 check;
 	int ret;
 
@@ -2006,6 +2040,23 @@ static int sfp_sm_mod_probe(struct sfp *sfp, bool report)
 
 	sfp->id = id;
 
+	sfp->phy_addr = SFP_PHY_ADDR;
+
+	rollball = ((!memcmp(id.base.vendor_name, "OEM             ", 16) ||
+		     !memcmp(id.base.vendor_name, "Turris          ", 16)) &&
+		    (!memcmp(id.base.vendor_pn, "SFP-10G-T       ", 16) ||
+		     !memcmp(id.base.vendor_pn, "RTSFP-10", 8)));
+	if (rollball) {
+		sfp->phy_addr = SFP_PHY_ADDR_ROLLBALL;
+		ret = sfp_rollball_init_mdio(sfp);
+		if (ret < 0)
+			return ret;
+
+		/* RollBall SFPs may have wrong (zero) extended compliacne code burned in EEPROM.
+		 * To try to probe for PHY we need the correct one */
+		id.base.extended_cc = SFF8024_ECC_10GBASE_T_SFI;
+	}
+
 	/* Check whether we support this module */
 	if (!sfp->type->module_supported(&id)) {
 		dev_err(sfp->dev,
@@ -2032,6 +2083,11 @@ static int sfp_sm_mod_probe(struct sfp *sfp, bool report)
 	else
 		sfp->module_t_start_up = T_START_UP;
 
+	if (rollball)
+		sfp->module_t_wait = T_WAIT_LONG_PHY;
+	else
+		sfp->module_t_wait = T_WAIT;
+
 	return 0;
 }
 
@@ -2225,9 +2281,10 @@ static void sfp_sm_main(struct sfp *sfp, unsigned int event)
 
 		/* We need to check the TX_FAULT state, which is not defined
 		 * while TX_DISABLE is asserted. The earliest we want to do
-		 * anything (such as probe for a PHY) is 50ms.
+		 * anything (such as probe for a PHY) is 50ms (or more on
+		 * specific modules).
 		 */
-		sfp_sm_next(sfp, SFP_S_WAIT, T_WAIT);
+		sfp_sm_next(sfp, SFP_S_WAIT, sfp->module_t_wait);
 		break;
 
 	case SFP_S_WAIT:
@@ -2241,8 +2298,8 @@ static void sfp_sm_main(struct sfp *sfp, unsigned int event)
 			 * indicated by TX_FAULT deasserting.
 			 */
 			timeout = sfp->module_t_start_up;
-			if (timeout > T_WAIT)
-				timeout -= T_WAIT;
+			if (timeout > sfp->module_t_wait)
+				timeout -= sfp->module_t_wait;
 			else
 				timeout = 1;
 
-- 
2.26.2


  parent reply	other threads:[~2020-10-20 15:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-20 15:06 [PATCH russell-kings-net-queue v2 0/3] Support for RollBall 10G copper SFP modules Marek Behún
2020-10-20 15:06 ` [PATCH russell-kings-net-queue v2 1/3] net: phy: mdio-i2c: support I2C MDIO protocol for RollBall " Marek Behún
2020-10-20 16:00   ` Andrew Lunn
2020-10-20 16:15     ` Marek Behún
2020-10-20 15:06 ` Marek Behún [this message]
2020-10-20 15:51   ` [PATCH russell-kings-net-queue v2 2/3] net: phy: sfp: add support for multigig RollBall modules Andrew Lunn
2020-10-20 16:14     ` Marek Behún
2020-10-20 15:06 ` [PATCH russell-kings-net-queue v2 3/3] net: phylink: don't fail attaching phy on 1000base-x/2500base-x mode Marek Behún

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=20201020150615.11969-3-kabel@kernel.org \
    --to=kabel@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    /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).