All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] net: phy: aquantia: add downshift support
@ 2019-03-20 21:15 Heiner Kallweit
  2019-03-20 21:27 ` Florian Fainelli
  2019-03-21  8:38 ` Andrew Lunn
  0 siblings, 2 replies; 6+ messages in thread
From: Heiner Kallweit @ 2019-03-20 21:15 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli, David Miller; +Cc: netdev

Aquantia PHY's of the AQR107 family support the downshift feature.
Add support for it as standard PHY tunable so that it can be controlled
via ethtool.
The AQCS109 supports a proprietary 2-pair 1Gbps mode. If two such PHY's
are connected to each other with a 2-pair cable, they may not be able
to establish a link if both advertise modes >= 1Gbps. Therefore enable
downshift per default on this model.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/aquantia_main.c | 73 ++++++++++++++++++++++++++++++++-
 1 file changed, 72 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/aquantia_main.c b/drivers/net/phy/aquantia_main.c
index 034b82d41..86000c044 100644
--- a/drivers/net/phy/aquantia_main.c
+++ b/drivers/net/phy/aquantia_main.c
@@ -33,6 +33,9 @@
 #define MDIO_AN_VEND_PROV			0xc400
 #define MDIO_AN_VEND_PROV_1000BASET_FULL	BIT(15)
 #define MDIO_AN_VEND_PROV_1000BASET_HALF	BIT(14)
+#define MDIO_AN_VEND_PROV_DOWNSHIFT_EN		BIT(4)
+#define MDIO_AN_VEND_PROV_DOWNSHIFT_MASK	GENMASK(3, 0)
+#define MDIO_AN_VEND_PROV_DOWNSHIFT_DFLT	4
 
 #define MDIO_AN_TX_VEND_STATUS1			0xc800
 #define MDIO_AN_TX_VEND_STATUS1_10BASET		(0x0 << 1)
@@ -220,6 +223,61 @@ static int aqr107_read_status(struct phy_device *phydev)
 	return 0;
 }
 
+static int aqr107_get_downshift(struct phy_device *phydev, u8 *data)
+{
+	int val, cnt, enable;
+
+	val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_VEND_PROV);
+	if (val < 0)
+		return val;
+
+	enable = FIELD_GET(MDIO_AN_VEND_PROV_DOWNSHIFT_EN, val);
+	cnt = FIELD_GET(MDIO_AN_VEND_PROV_DOWNSHIFT_MASK, val);
+
+	*data = enable && cnt ? cnt : DOWNSHIFT_DEV_DISABLE;
+
+	return 0;
+}
+
+static int aqr107_set_downshift(struct phy_device *phydev, u8 cnt)
+{
+	int val = 0;
+
+	if (!FIELD_FIT(MDIO_AN_VEND_PROV_DOWNSHIFT_MASK, cnt))
+		return -E2BIG;
+
+	if (cnt != DOWNSHIFT_DEV_DISABLE) {
+		val = MDIO_AN_VEND_PROV_DOWNSHIFT_EN;
+		val |= FIELD_PREP(MDIO_AN_VEND_PROV_DOWNSHIFT_MASK, cnt);
+	}
+
+	return phy_modify_mmd(phydev, MDIO_MMD_AN, MDIO_AN_VEND_PROV,
+			      MDIO_AN_VEND_PROV_DOWNSHIFT_EN |
+			      MDIO_AN_VEND_PROV_DOWNSHIFT_MASK, val);
+}
+
+static int aqr107_get_tunable(struct phy_device *phydev,
+			      struct ethtool_tunable *tuna, void *data)
+{
+	switch (tuna->id) {
+	case ETHTOOL_PHY_DOWNSHIFT:
+		return aqr107_get_downshift(phydev, data);
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int aqr107_set_tunable(struct phy_device *phydev,
+			      struct ethtool_tunable *tuna, const void *data)
+{
+	switch (tuna->id) {
+	case ETHTOOL_PHY_DOWNSHIFT:
+		return aqr107_set_downshift(phydev, *(const u8 *)data);
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
 static int aqr107_config_init(struct phy_device *phydev)
 {
 	/* Check that the PHY interface type is compatible */
@@ -233,6 +291,8 @@ static int aqr107_config_init(struct phy_device *phydev)
 
 static int aqcs109_config_init(struct phy_device *phydev)
 {
+	int ret;
+
 	/* Check that the PHY interface type is compatible */
 	if (phydev->interface != PHY_INTERFACE_MODE_SGMII &&
 	    phydev->interface != PHY_INTERFACE_MODE_2500BASEX)
@@ -242,7 +302,14 @@ static int aqcs109_config_init(struct phy_device *phydev)
 	 * PMA speed ability bits are the same for all members of the family,
 	 * AQCS109 however supports speeds up to 2.5G only.
 	 */
-	return phy_set_max_speed(phydev, SPEED_2500);
+	ret = phy_set_max_speed(phydev, SPEED_2500);
+	if (ret)
+		return ret;
+
+	/* AQCS109 supports a proprietary 2-pair 1Gbps mode, therefore enable
+	 * downshift per default.
+	 */
+	return aqr107_set_downshift(phydev, MDIO_AN_VEND_PROV_DOWNSHIFT_DFLT);
 }
 
 static struct phy_driver aqr_driver[] = {
@@ -285,6 +352,8 @@ static struct phy_driver aqr_driver[] = {
 	.config_intr	= aqr_config_intr,
 	.ack_interrupt	= aqr_ack_interrupt,
 	.read_status	= aqr_read_status,
+	.get_tunable    = aqr107_get_tunable,
+	.set_tunable    = aqr107_set_tunable,
 },
 {
 	PHY_ID_MATCH_MODEL(PHY_ID_AQR107),
@@ -319,6 +388,8 @@ static struct phy_driver aqr_driver[] = {
 	.config_intr	= aqr_config_intr,
 	.ack_interrupt	= aqr_ack_interrupt,
 	.read_status	= aqr_read_status,
+	.get_tunable    = aqr107_get_tunable,
+	.set_tunable    = aqr107_set_tunable,
 },
 };
 
-- 
2.21.0


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

* Re: [PATCH net-next] net: phy: aquantia: add downshift support
  2019-03-20 21:15 [PATCH net-next] net: phy: aquantia: add downshift support Heiner Kallweit
@ 2019-03-20 21:27 ` Florian Fainelli
  2019-03-21  8:38 ` Andrew Lunn
  1 sibling, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2019-03-20 21:27 UTC (permalink / raw)
  To: Heiner Kallweit, Andrew Lunn, David Miller; +Cc: netdev

On 3/20/19 2:15 PM, Heiner Kallweit wrote:
> Aquantia PHY's of the AQR107 family support the downshift feature.
> Add support for it as standard PHY tunable so that it can be controlled
> via ethtool.
> The AQCS109 supports a proprietary 2-pair 1Gbps mode. If two such PHY's
> are connected to each other with a 2-pair cable, they may not be able
> to establish a link if both advertise modes >= 1Gbps. Therefore enable
> downshift per default on this model.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>

Nice and clean!
-- 
Florian

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

* Re: [PATCH net-next] net: phy: aquantia: add downshift support
  2019-03-20 21:15 [PATCH net-next] net: phy: aquantia: add downshift support Heiner Kallweit
  2019-03-20 21:27 ` Florian Fainelli
@ 2019-03-21  8:38 ` Andrew Lunn
  2019-03-21 16:30   ` David Miller
  2019-03-21 18:49   ` Heiner Kallweit
  1 sibling, 2 replies; 6+ messages in thread
From: Andrew Lunn @ 2019-03-21  8:38 UTC (permalink / raw)
  To: Heiner Kallweit; +Cc: Florian Fainelli, David Miller, netdev

On Wed, Mar 20, 2019 at 10:15:10PM +0100, Heiner Kallweit wrote:
> Aquantia PHY's of the AQR107 family support the downshift feature.
> Add support for it as standard PHY tunable so that it can be controlled
> via ethtool.
> The AQCS109 supports a proprietary 2-pair 1Gbps mode. If two such PHY's
> are connected to each other with a 2-pair cable, they may not be able
> to establish a link if both advertise modes >= 1Gbps. Therefore enable
> downshift per default on this model.

Hi Heiner

Is there any way to know it has done a downshift?

Florian said the Intel drivers print a message when they downshift. It
could be interesting to know, especially when a PHY goes from 1G to
100M.

Even for a downshift to 1000Base-T2, i'm guessing for most use cases,
this means the cable is partially broken, and it serves as an early
warning it needs replacing.

	Andrew

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

* Re: [PATCH net-next] net: phy: aquantia: add downshift support
  2019-03-21  8:38 ` Andrew Lunn
@ 2019-03-21 16:30   ` David Miller
  2019-03-21 16:36     ` Florian Fainelli
  2019-03-21 18:49   ` Heiner Kallweit
  1 sibling, 1 reply; 6+ messages in thread
From: David Miller @ 2019-03-21 16:30 UTC (permalink / raw)
  To: andrew; +Cc: hkallweit1, f.fainelli, netdev

From: Andrew Lunn <andrew@lunn.ch>
Date: Thu, 21 Mar 2019 09:38:27 +0100

> Even for a downshift to 1000Base-T2, i'm guessing for most use cases,
> this means the cable is partially broken, and it serves as an early
> warning it needs replacing.

+1

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

* Re: [PATCH net-next] net: phy: aquantia: add downshift support
  2019-03-21 16:30   ` David Miller
@ 2019-03-21 16:36     ` Florian Fainelli
  0 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2019-03-21 16:36 UTC (permalink / raw)
  To: David Miller, andrew; +Cc: hkallweit1, netdev

On 3/21/19 9:30 AM, David Miller wrote:
> From: Andrew Lunn <andrew@lunn.ch>
> Date: Thu, 21 Mar 2019 09:38:27 +0100
> 
>> Even for a downshift to 1000Base-T2, i'm guessing for most use cases,
>> this means the cable is partially broken, and it serves as an early
>> warning it needs replacing.
> 
> +1

Maybe something that we can add to Petr' link up/down with message
indication?
-- 
Florian

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

* Re: [PATCH net-next] net: phy: aquantia: add downshift support
  2019-03-21  8:38 ` Andrew Lunn
  2019-03-21 16:30   ` David Miller
@ 2019-03-21 18:49   ` Heiner Kallweit
  1 sibling, 0 replies; 6+ messages in thread
From: Heiner Kallweit @ 2019-03-21 18:49 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: Florian Fainelli, David Miller, netdev

On 21.03.2019 09:38, Andrew Lunn wrote:
> On Wed, Mar 20, 2019 at 10:15:10PM +0100, Heiner Kallweit wrote:
>> Aquantia PHY's of the AQR107 family support the downshift feature.
>> Add support for it as standard PHY tunable so that it can be controlled
>> via ethtool.
>> The AQCS109 supports a proprietary 2-pair 1Gbps mode. If two such PHY's
>> are connected to each other with a 2-pair cable, they may not be able
>> to establish a link if both advertise modes >= 1Gbps. Therefore enable
>> downshift per default on this model.
> 
> Hi Heiner
> 
> Is there any way to know it has done a downshift?
> 
> Florian said the Intel drivers print a message when they downshift. It
> could be interesting to know, especially when a PHY goes from 1G to
> 100M.
> 
> Even for a downshift to 1000Base-T2, i'm guessing for most use cases,
> this means the cable is partially broken, and it serves as an early
> warning it needs replacing.
> 
Good point, after a brief look at the datasheet this should be possible.

> 	Andrew
> .
> 
Heiner

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

end of thread, other threads:[~2019-03-21 18:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-20 21:15 [PATCH net-next] net: phy: aquantia: add downshift support Heiner Kallweit
2019-03-20 21:27 ` Florian Fainelli
2019-03-21  8:38 ` Andrew Lunn
2019-03-21 16:30   ` David Miller
2019-03-21 16:36     ` Florian Fainelli
2019-03-21 18:49   ` Heiner Kallweit

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.