Skip to contentSkip to conversation

dsa: lan9303: Move to PHYLINK

PATCH Superseded Jerry Ray 2 participants 5 messages Dec 2, 2022 – Dec 6, 2022

Subsystems (3)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Jerry Ray

author
#0 lore raw

v2 cover dsa: lan9303: Move to PHYLINK

This patch series moves the lan9303 driver to use the phylink api away from phylib.

1) adds port_max_mtu api support.
2) Replace .adjust_link with .phylink_get_caps dsa api

At this point, I do not see anything this driver needs from the other phylink APIs.

---
v1-> v2:
corrected the reported mtu size, removing ETH_HLEN and ETH_FCS_LEN

 drivers/net/dsa/lan9303-core.c | 93 ++++++++++++--------
 1 file changed, 56 insertions(+), 37 deletions(-)
author
#1 lore raw

PATCH v2 1/2 dsa: lan9303: Add port_max_mtu API

Adding in support for reporting the max mtu for a given port.

---
 drivers/net/dsa/lan9303-core.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/dsa/lan9303-core.c +20 -0
index 80f07bd20593..baa336bb9d15 100644
@@ -1279,6 +1279,25 @@ static int lan9303_port_mdb_del(struct dsa_switch *ds, int port,
 	return 0;
 }
 
+/* For non-cpu ports, the max frame size is 1518.
+ * The CPU port supports a max frame size of 1522.
+ * There is a JUMBO flag to make the max size 2048, but this driver
+ * presently does not support using it.
+ */
+static int lan9303_port_max_mtu(struct dsa_switch *ds, int port)
+{
+	struct net_device *p = dsa_port_to_master(dsa_to_port(ds, port));
+	struct lan9303 *chip = ds->priv;
+
+	dev_dbg(chip->dev, "%s(%d) entered. NET max_mtu is %d",
+		__func__, port, p->max_mtu);
+
+	if (dsa_port_is_cpu(dsa_to_port(ds, port)))
+		return 1522 - ETH_HLEN - ETH_FCS_LEN;
+	else
+		return 1518 - ETH_HLEN - ETH_FCS_LEN;
+}
+
 static const struct dsa_switch_ops lan9303_switch_ops = {
 	.get_tag_protocol = lan9303_get_tag_protocol,
 	.setup = lan9303_setup,
@@ -1299,6 +1318,7 @@ static const struct dsa_switch_ops lan9303_switch_ops = {
 	.port_fdb_dump          = lan9303_port_fdb_dump,
 	.port_mdb_add           = lan9303_port_mdb_add,
 	.port_mdb_del           = lan9303_port_mdb_del,
+	.port_max_mtu		= lan9303_port_max_mtu,
 };
 
 static int lan9303_register_switch(struct lan9303 *chip)
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH v2 2/2 dsa: lan9303: Move to PHYLINK

In reply to Jerry Ray

This patch replaces the .adjust_link api with the .phylink_get_caps api.

---
 drivers/net/dsa/lan9303-core.c | 73 +++++++++++++++++-----------------
 1 file changed, 36 insertions(+), 37 deletions(-)
drivers/net/dsa/lan9303-core.c +36 -37
index baa336bb9d15..2baf6ae7e0a0 100644
@@ -1047,42 +1047,6 @@ static int lan9303_phy_write(struct dsa_switch *ds, int phy, int regnum,
 	return chip->ops->phy_write(chip, phy, regnum, val);
 }
 
-static void lan9303_adjust_link(struct dsa_switch *ds, int port,
-				struct phy_device *phydev)
-{
-	struct lan9303 *chip = ds->priv;
-	int ctl;
-
-	if (!phy_is_pseudo_fixed_link(phydev))
-		return;
-
-	ctl = lan9303_phy_read(ds, port, MII_BMCR);
-
-	ctl &= ~BMCR_ANENABLE;
-
-	if (phydev->speed == SPEED_100)
-		ctl |= BMCR_SPEED100;
-	else if (phydev->speed == SPEED_10)
-		ctl &= ~BMCR_SPEED100;
-	else
-		dev_err(ds->dev, "unsupported speed: %d\n", phydev->speed);
-
-	if (phydev->duplex == DUPLEX_FULL)
-		ctl |= BMCR_FULLDPLX;
-	else
-		ctl &= ~BMCR_FULLDPLX;
-
-	lan9303_phy_write(ds, port, MII_BMCR, ctl);
-
-	if (port == chip->phy_addr_base) {
-		/* Virtual Phy: Remove Turbo 200Mbit mode */
-		lan9303_read(chip->regmap, LAN9303_VIRT_SPECIAL_CTRL, &ctl);
-
-		ctl &= ~LAN9303_VIRT_SPECIAL_TURBO;
-		regmap_write(chip->regmap, LAN9303_VIRT_SPECIAL_CTRL, ctl);
-	}
-}
-
 static int lan9303_port_enable(struct dsa_switch *ds, int port,
 			       struct phy_device *phy)
 {
@@ -1279,6 +1243,41 @@ static int lan9303_port_mdb_del(struct dsa_switch *ds, int port,
 	return 0;
 }
 
+static void lan9303_phylink_get_caps(struct dsa_switch *ds, int port,
+				     struct phylink_config *config)
+{
+	struct lan9303 *chip = ds->priv;
+
+	dev_dbg(chip->dev, "%s(%d) entered.", __func__, port);
+
+	config->mac_capabilities = MAC_10 | MAC_100 | MAC_ASYM_PAUSE |
+				   MAC_SYM_PAUSE;
+
+	if (dsa_port_is_cpu(dsa_to_port(ds, port))) {
+		/* cpu port */
+		phy_interface_empty(config->supported_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_RMII,
+			  config->supported_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_MII,
+			  config->supported_interfaces);
+	} else {
+		/* internal ports */
+		__set_bit(PHY_INTERFACE_MODE_INTERNAL,
+			  config->supported_interfaces);
+		/* Compatibility for phylib's default interface type when the
+		 * phy-mode property is absent
+		 */
+		__set_bit(PHY_INTERFACE_MODE_GMII,
+			  config->supported_interfaces);
+	}
+
+	/* This driver does not make use of the speed, duplex, pause or the
+	 * advertisement in its mac_config, so it is safe to mark this driver
+	 * as non-legacy.
+	 */
+	config->legacy_pre_march2020 = false;
+}
+
 /* For non-cpu ports, the max frame size is 1518.
  * The CPU port supports a max frame size of 1522.
  * There is a JUMBO flag to make the max size 2048, but this driver
@@ -1304,7 +1303,7 @@ static const struct dsa_switch_ops lan9303_switch_ops = {
 	.get_strings = lan9303_get_strings,
 	.phy_read = lan9303_phy_read,
 	.phy_write = lan9303_phy_write,
-	.adjust_link = lan9303_adjust_link,
+	.phylink_get_caps	= lan9303_phylink_get_caps,
 	.get_ethtool_stats = lan9303_get_ethtool_stats,
 	.get_sset_count = lan9303_get_sset_count,
 	.port_enable = lan9303_port_enable,
Signature · 1 line
2.17.1
#3 lore raw

Hi Jerry,

Quoted 25 lines · Jerry Ray
drivers/net/dsa/lan9303-core.c +0 -25
-static void lan9303_adjust_link(struct dsa_switch *ds, int port,
-				struct phy_device *phydev)
-{
-	struct lan9303 *chip = ds->priv;
-	int ctl;
-
-	if (!phy_is_pseudo_fixed_link(phydev))
-		return;
-
-	ctl = lan9303_phy_read(ds, port, MII_BMCR);
-
-	ctl &= ~BMCR_ANENABLE;
-
-	if (phydev->speed == SPEED_100)
-		ctl |= BMCR_SPEED100;
-	else if (phydev->speed == SPEED_10)
-		ctl &= ~BMCR_SPEED100;
-	else
-		dev_err(ds->dev, "unsupported speed: %d\n", phydev->speed);
-
-	if (phydev->duplex == DUPLEX_FULL)
-		ctl |= BMCR_FULLDPLX;
-	else
-		ctl &= ~BMCR_FULLDPLX;
-

drivers/net/dsa/lan9303-core.c static int lan9303_phy_write(struct dsa_switch *ds, int phy, int regnum, · line 1084

Quoted 10 lines
drivers/net/dsa/lan9303-core.c +0 -10
-	lan9303_phy_write(ds, port, MII_BMCR, ctl);
-
-	if (port == chip->phy_addr_base) {
-		/* Virtual Phy: Remove Turbo 200Mbit mode */
-		lan9303_read(chip->regmap, LAN9303_VIRT_SPECIAL_CTRL, &ctl);
-
-		ctl &= ~LAN9303_VIRT_SPECIAL_TURBO;
-		regmap_write(chip->regmap, LAN9303_VIRT_SPECIAL_CTRL, ctl);
-	}
-}

Is this functionality no longer necessary? For example, I don't see anywhere else in the driver that this turbo mode is disabled.

I'm guessing the above code writing MII_BMCR is to force the configuration of integrated PHYs to be the fixed-link settings? How is that dealt with after the removal of the above code?

Quoted 11 lines
drivers/net/dsa/lan9303-core.c +3 -1
-
 static int lan9303_port_enable(struct dsa_switch *ds, int port,
 			       struct phy_device *phy)
 {
@@ -1279,6 +1243,41 @@ static int lan9303_port_mdb_del(struct dsa_switch *ds, int port,
 	return 0;
 }
 
+static void lan9303_phylink_get_caps(struct dsa_switch *ds, int port,
+				     struct phylink_config *config)
+{

drivers/net/dsa/lan9303-core.c static int lan9303_port_mdb_del(struct dsa_switch *ds, int port, · line 1258

Quoted 10 lines
drivers/net/dsa/lan9303-core.c +10 -0
+	struct lan9303 *chip = ds->priv;
+
+	dev_dbg(chip->dev, "%s(%d) entered.", __func__, port);
+
+	config->mac_capabilities = MAC_10 | MAC_100 | MAC_ASYM_PAUSE |
+				   MAC_SYM_PAUSE;
+
+	if (dsa_port_is_cpu(dsa_to_port(ds, port))) {
+		/* cpu port */
+		phy_interface_empty(config->supported_interfaces);

This should not be necessary - the supported_interfaces member should already be zero.

Thanks.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
#4 lore raw
Quoted 39 lines
Quoted 25 lines
drivers/net/dsa/lan9303-core.c +0 -25
-static void lan9303_adjust_link(struct dsa_switch *ds, int port,
-                             struct phy_device *phydev)
-{
-     struct lan9303 *chip = ds->priv;
-     int ctl;
-
-     if (!phy_is_pseudo_fixed_link(phydev))
-             return;
-
-     ctl = lan9303_phy_read(ds, port, MII_BMCR);
-
-     ctl &= ~BMCR_ANENABLE;
-
-     if (phydev->speed == SPEED_100)
-             ctl |= BMCR_SPEED100;
-     else if (phydev->speed == SPEED_10)
-             ctl &= ~BMCR_SPEED100;
-     else
-             dev_err(ds->dev, "unsupported speed: %d\n", phydev->speed);
-
-     if (phydev->duplex == DUPLEX_FULL)
-             ctl |= BMCR_FULLDPLX;
-     else
-             ctl &= ~BMCR_FULLDPLX;
-

drivers/net/dsa/lan9303-core.c static int lan9303_phy_write(struct dsa_switch *ds, int phy, int regnum, · line 1084

Quoted 10 lines
drivers/net/dsa/lan9303-core.c +0 -10
-     lan9303_phy_write(ds, port, MII_BMCR, ctl);
-
-     if (port == chip->phy_addr_base) {
-             /* Virtual Phy: Remove Turbo 200Mbit mode */
-             lan9303_read(chip->regmap, LAN9303_VIRT_SPECIAL_CTRL, &ctl);
-
-             ctl &= ~LAN9303_VIRT_SPECIAL_TURBO;
-             regmap_write(chip->regmap, LAN9303_VIRT_SPECIAL_CTRL, ctl);
-     }
-}

Is this functionality no longer necessary? For example, I don't see anywhere else in the driver that this turbo mode is disabled.

Quoted 4 lines

I'm guessing the above code writing MII_BMCR is to force the configuration of integrated PHYs to be the fixed-link settings? How is that dealt with after the removal of the above code?

While it should be disabled by the HW config strap settings, I'll add disabling Turbo Mode into the initialization sequence to keep the driver operation consistent.

Quoted 25 lines
Quoted 11 lines
drivers/net/dsa/lan9303-core.c +3 -1
-
 static int lan9303_port_enable(struct dsa_switch *ds, int port,
                             struct phy_device *phy)
 {
@@ -1279,6 +1243,41 @@ static int lan9303_port_mdb_del(struct dsa_switch *ds, int port,
      return 0;
 }
 
+static void lan9303_phylink_get_caps(struct dsa_switch *ds, int port,
+                                  struct phylink_config *config)
+{

drivers/net/dsa/lan9303-core.c static int lan9303_port_mdb_del(struct dsa_switch *ds, int port, · line 1258

Quoted 10 lines
drivers/net/dsa/lan9303-core.c +10 -0
+     struct lan9303 *chip = ds->priv;
+
+     dev_dbg(chip->dev, "%s(%d) entered.", __func__, port);
+
+     config->mac_capabilities = MAC_10 | MAC_100 | MAC_ASYM_PAUSE |
+                                MAC_SYM_PAUSE;
+
+     if (dsa_port_is_cpu(dsa_to_port(ds, port))) {
+             /* cpu port */
+             phy_interface_empty(config->supported_interfaces);

This should not be necessary - the supported_interfaces member should already be zero.

Quoted 2 lines

Thanks.

Yes, I agree. I'll remove it.

Regards,
J.