diff mbox series

net: dsa: b53: add support for BCM63xx RGMIIs

Message ID 20230319183330.761251-1-noltari@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: b53: add support for BCM63xx RGMIIs | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 18 this patch: 18
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 18 this patch: 18
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 61 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Álvaro Fernández Rojas March 19, 2023, 6:33 p.m. UTC
BCM63xx RGMII ports require additional configuration in order to work.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 drivers/net/dsa/b53/b53_common.c | 36 ++++++++++++++++++++++++++++++++
 drivers/net/dsa/b53/b53_priv.h   |  1 +
 2 files changed, 37 insertions(+)

Comments

Andrew Lunn March 19, 2023, 6:50 p.m. UTC | #1
> +static void b53_adjust_63xx_rgmii(struct dsa_switch *ds, int port,
> +				  phy_interface_t interface)
> +{
> +	struct b53_device *dev = ds->priv;
> +	u8 rgmii_ctrl = 0, off;
> +
> +	if (port == dev->imp_port)
> +		off = B53_RGMII_CTRL_IMP;
> +	else
> +		off = B53_RGMII_CTRL_P(port);
> +
> +	b53_read8(dev, B53_CTRL_PAGE, off, &rgmii_ctrl);
> +
> +	rgmii_ctrl &= ~(RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC);
> +	if (interface == PHY_INTERFACE_MODE_RGMII_ID)
> +		rgmii_ctrl |= (RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC);
> +	else if (interface == PHY_INTERFACE_MODE_RGMII_RXID)
> +		rgmii_ctrl |= RGMII_CTRL_DLL_RXC;
> +	else if (interface == PHY_INTERFACE_MODE_RGMII_TXID)
> +		rgmii_ctrl |= RGMII_CTRL_DLL_TXC;

Please change this to a switch statement. Then i would suggest having
a case PHY_INTERFACE_MODE_RGMII: to make it clear you are handling
that as well, removing all delays. You do look to be handling it, so
it is not a big problem, but in the past we have had code where one of
the RGMII modes has been ignored resulting in some horrible problems
later. So it is something i now always look for, and like to be obvious.

> +
> +	if (port != dev->imp_port)
> +		rgmii_ctrl |= RGMII_CTRL_ENABLE_GMII;
> +
> +	b53_write8(dev, B53_CTRL_PAGE, off, rgmii_ctrl);
> +
> +	dev_info(ds->dev, "Configured port %d for %s\n", port,
> +		 phy_modes(interface));

dev_dbg().

	Andrew
diff mbox series

Patch

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 59cdfc51ce06..378327add363 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -1209,6 +1209,36 @@  static void b53_force_port_config(struct b53_device *dev, int port,
 	b53_write8(dev, B53_CTRL_PAGE, off, reg);
 }
 
+static void b53_adjust_63xx_rgmii(struct dsa_switch *ds, int port,
+				  phy_interface_t interface)
+{
+	struct b53_device *dev = ds->priv;
+	u8 rgmii_ctrl = 0, off;
+
+	if (port == dev->imp_port)
+		off = B53_RGMII_CTRL_IMP;
+	else
+		off = B53_RGMII_CTRL_P(port);
+
+	b53_read8(dev, B53_CTRL_PAGE, off, &rgmii_ctrl);
+
+	rgmii_ctrl &= ~(RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC);
+	if (interface == PHY_INTERFACE_MODE_RGMII_ID)
+		rgmii_ctrl |= (RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC);
+	else if (interface == PHY_INTERFACE_MODE_RGMII_RXID)
+		rgmii_ctrl |= RGMII_CTRL_DLL_RXC;
+	else if (interface == PHY_INTERFACE_MODE_RGMII_TXID)
+		rgmii_ctrl |= RGMII_CTRL_DLL_TXC;
+
+	if (port != dev->imp_port)
+		rgmii_ctrl |= RGMII_CTRL_ENABLE_GMII;
+
+	b53_write8(dev, B53_CTRL_PAGE, off, rgmii_ctrl);
+
+	dev_info(ds->dev, "Configured port %d for %s\n", port,
+		 phy_modes(interface));
+}
+
 static void b53_adjust_link(struct dsa_switch *ds, int port,
 			    struct phy_device *phydev)
 {
@@ -1235,6 +1265,9 @@  static void b53_adjust_link(struct dsa_switch *ds, int port,
 			      tx_pause, rx_pause);
 	b53_force_link(dev, port, phydev->link);
 
+	if (is63xx(dev) && port >= B53_63XX_RGMII0)
+		b53_adjust_63xx_rgmii(ds, port, phydev->interface);
+
 	if (is531x5(dev) && phy_interface_is_rgmii(phydev)) {
 		if (port == dev->imp_port)
 			off = B53_RGMII_CTRL_IMP;
@@ -1402,6 +1435,9 @@  void b53_phylink_mac_link_up(struct dsa_switch *ds, int port,
 {
 	struct b53_device *dev = ds->priv;
 
+	if (is63xx(dev) && port >= B53_63XX_RGMII0)
+		b53_adjust_63xx_rgmii(ds, port, interface);
+
 	if (mode == MLO_AN_PHY)
 		return;
 
diff --git a/drivers/net/dsa/b53/b53_priv.h b/drivers/net/dsa/b53/b53_priv.h
index 795cbffd5c2b..4cf9f540696e 100644
--- a/drivers/net/dsa/b53/b53_priv.h
+++ b/drivers/net/dsa/b53/b53_priv.h
@@ -211,6 +211,7 @@  static inline int is58xx(struct b53_device *dev)
 		dev->chip_id == BCM7278_DEVICE_ID;
 }
 
+#define B53_63XX_RGMII0	4
 #define B53_CPU_PORT_25	5
 #define B53_CPU_PORT	8