diff mbox series

[net-next] net: mvpp2: add support for mii

Message ID 20231206160125.2383281-1-eichest@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: mvpp2: add support for mii | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
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: 1171 this patch: 1171
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 1142 this patch: 1142
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: 1199 this patch: 1199
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 51 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Stefan Eichenberger Dec. 6, 2023, 4:01 p.m. UTC
Currently, mvpp2 only supports RGMII. This commit adds support for MII.
The description in Marvell's functional specification seems to be wrong.
To enable MII, we need to set GENCONF_CTRL0_PORT3_RGMII, while for RGMII
we need to clear it. This is also how U-Boot handles it.

Signed-off-by: Stefan Eichenberger <eichest@gmail.com>
---
 .../net/ethernet/marvell/mvpp2/mvpp2_main.c   | 24 ++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

Comments

Maxime Chevallier Dec. 6, 2023, 5:27 p.m. UTC | #1
Hello Stefan,

On Wed,  6 Dec 2023 17:01:25 +0100
Stefan Eichenberger <eichest@gmail.com> wrote:

> Currently, mvpp2 only supports RGMII. This commit adds support for MII.
> The description in Marvell's functional specification seems to be wrong.
> To enable MII, we need to set GENCONF_CTRL0_PORT3_RGMII, while for RGMII
> we need to clear it. This is also how U-Boot handles it.
> 
> Signed-off-by: Stefan Eichenberger <eichest@gmail.com>
> ---
>  .../net/ethernet/marvell/mvpp2/mvpp2_main.c   | 24 ++++++++++++++++---
>  1 file changed, 21 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
> index 93137606869e..6f136f42e2bf 100644
> --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
> +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
> @@ -1513,10 +1513,21 @@ static void mvpp22_gop_init_rgmii(struct mvpp2_port *port)
>  	regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL0, val);
>  
>  	regmap_read(priv->sysctrl_base, GENCONF_CTRL0, &val);
> -	if (port->gop_id == 2)
> +	if (port->gop_id == 2) {
>  		val |= GENCONF_CTRL0_PORT2_RGMII;
> -	else if (port->gop_id == 3)
> +	} else if (port->gop_id == 3) {
>  		val |= GENCONF_CTRL0_PORT3_RGMII_MII;
> +
> +		/* According to the specification, GENCONF_CTRL0_PORT3_RGMII
> +		 * should be set to 1 for RGMII and 0 for MII. However, tests
> +		 * show that it is the other way around. This is also what
> +		 * U-Boot does for mvpp2, so it is assumed to be correct.
> +		 */
> +		if (port->phy_interface == PHY_INTERFACE_MODE_MII)
> +			val |= GENCONF_CTRL0_PORT3_RGMII;
> +		else
> +			val &= ~GENCONF_CTRL0_PORT3_RGMII;
> +	}
>  	regmap_write(priv->sysctrl_base, GENCONF_CTRL0, val);
>  }
>  
> @@ -1615,6 +1626,7 @@ static int mvpp22_gop_init(struct mvpp2_port *port, phy_interface_t interface)
>  		return 0;
>  
>  	switch (interface) {
> +	case PHY_INTERFACE_MODE_MII:
>  	case PHY_INTERFACE_MODE_RGMII:
>  	case PHY_INTERFACE_MODE_RGMII_ID:
>  	case PHY_INTERFACE_MODE_RGMII_RXID:
> @@ -6948,8 +6960,11 @@ static int mvpp2_port_probe(struct platform_device *pdev,
>  					MAC_10000FD;
>  		}
>  
> -		if (mvpp2_port_supports_rgmii(port))
> +		if (mvpp2_port_supports_rgmii(port)) {
>  			phy_interface_set_rgmii(port->phylink_config.supported_interfaces);
> +			__set_bit(PHY_INTERFACE_MODE_MII,
> +				  port->phylink_config.supported_interfaces);
> +		}
>  
>  		if (comphy) {
>  			/* If a COMPHY is present, we can support any of the
> @@ -6973,6 +6988,9 @@ static int mvpp2_port_probe(struct platform_device *pdev,
>  				  port->phylink_config.supported_interfaces);
>  			__set_bit(PHY_INTERFACE_MODE_SGMII,
>  				  port->phylink_config.supported_interfaces);
> +		} else if (phy_mode == PHY_INTERFACE_MODE_MII) {
> +			__set_bit(PHY_INTERFACE_MODE_100BASEX,
> +				  port->phylink_config.supported_interfaces);

Can you explain that part ? I don't understand why 100BaseX is being
reported as a supported mode here. This whole section of the function
is about detecting what can be reported based on the presence or not of
a comphy driver / hardcoded comphy config. I don't think the comphy
here has anything to do with MII / 100BaseX

If 100BaseX can be carried on MII (which I don't know), shouldn't it be
reported no matter what ?

Thanks,

Maxime
Stefan Eichenberger Dec. 7, 2023, 9:01 a.m. UTC | #2
Hi Maxime,

On Wed, Dec 06, 2023 at 06:27:05PM +0100, Maxime Chevallier wrote:
> > @@ -6973,6 +6988,9 @@ static int mvpp2_port_probe(struct platform_device *pdev,
> >  				  port->phylink_config.supported_interfaces);
> >  			__set_bit(PHY_INTERFACE_MODE_SGMII,
> >  				  port->phylink_config.supported_interfaces);
> > +		} else if (phy_mode == PHY_INTERFACE_MODE_MII) {
> > +			__set_bit(PHY_INTERFACE_MODE_100BASEX,
> > +				  port->phylink_config.supported_interfaces);
> 
> Can you explain that part ? I don't understand why 100BaseX is being
> reported as a supported mode here. This whole section of the function
> is about detecting what can be reported based on the presence or not of
> a comphy driver / hardcoded comphy config. I don't think the comphy
> here has anything to do with MII / 100BaseX
> 
> If 100BaseX can be carried on MII (which I don't know), shouldn't it be
> reported no matter what ?

I missunderstood that part, I thought it is a translation from interface
type to speed but it is obviously not. I already verfied that everything
works without this part and will remove it in version 2 of the patch.
Thanks a lot for the review!

Regards,
Stefan
Maxime Chevallier Dec. 7, 2023, 11:27 a.m. UTC | #3
Hello Stefan,

On Thu, 7 Dec 2023 10:01:08 +0100
Stefan Eichenberger <eichest@gmail.com> wrote:

> Hi Maxime,
> 
> On Wed, Dec 06, 2023 at 06:27:05PM +0100, Maxime Chevallier wrote:
> > > @@ -6973,6 +6988,9 @@ static int mvpp2_port_probe(struct platform_device *pdev,
> > >  				  port->phylink_config.supported_interfaces);
> > >  			__set_bit(PHY_INTERFACE_MODE_SGMII,
> > >  				  port->phylink_config.supported_interfaces);
> > > +		} else if (phy_mode == PHY_INTERFACE_MODE_MII) {
> > > +			__set_bit(PHY_INTERFACE_MODE_100BASEX,
> > > +				  port->phylink_config.supported_interfaces);  
> > 
> > Can you explain that part ? I don't understand why 100BaseX is being
> > reported as a supported mode here. This whole section of the function
> > is about detecting what can be reported based on the presence or not of
> > a comphy driver / hardcoded comphy config. I don't think the comphy
> > here has anything to do with MII / 100BaseX
> > 
> > If 100BaseX can be carried on MII (which I don't know), shouldn't it be
> > reported no matter what ?  
> 
> I missunderstood that part, I thought it is a translation from interface
> type to speed but it is obviously not. I already verfied that everything
> works without this part and will remove it in version 2 of the patch.
> Thanks a lot for the review!

No problem, thanks for the patch :)

Maxime
diff mbox series

Patch

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 93137606869e..6f136f42e2bf 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -1513,10 +1513,21 @@  static void mvpp22_gop_init_rgmii(struct mvpp2_port *port)
 	regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL0, val);
 
 	regmap_read(priv->sysctrl_base, GENCONF_CTRL0, &val);
-	if (port->gop_id == 2)
+	if (port->gop_id == 2) {
 		val |= GENCONF_CTRL0_PORT2_RGMII;
-	else if (port->gop_id == 3)
+	} else if (port->gop_id == 3) {
 		val |= GENCONF_CTRL0_PORT3_RGMII_MII;
+
+		/* According to the specification, GENCONF_CTRL0_PORT3_RGMII
+		 * should be set to 1 for RGMII and 0 for MII. However, tests
+		 * show that it is the other way around. This is also what
+		 * U-Boot does for mvpp2, so it is assumed to be correct.
+		 */
+		if (port->phy_interface == PHY_INTERFACE_MODE_MII)
+			val |= GENCONF_CTRL0_PORT3_RGMII;
+		else
+			val &= ~GENCONF_CTRL0_PORT3_RGMII;
+	}
 	regmap_write(priv->sysctrl_base, GENCONF_CTRL0, val);
 }
 
@@ -1615,6 +1626,7 @@  static int mvpp22_gop_init(struct mvpp2_port *port, phy_interface_t interface)
 		return 0;
 
 	switch (interface) {
+	case PHY_INTERFACE_MODE_MII:
 	case PHY_INTERFACE_MODE_RGMII:
 	case PHY_INTERFACE_MODE_RGMII_ID:
 	case PHY_INTERFACE_MODE_RGMII_RXID:
@@ -6948,8 +6960,11 @@  static int mvpp2_port_probe(struct platform_device *pdev,
 					MAC_10000FD;
 		}
 
-		if (mvpp2_port_supports_rgmii(port))
+		if (mvpp2_port_supports_rgmii(port)) {
 			phy_interface_set_rgmii(port->phylink_config.supported_interfaces);
+			__set_bit(PHY_INTERFACE_MODE_MII,
+				  port->phylink_config.supported_interfaces);
+		}
 
 		if (comphy) {
 			/* If a COMPHY is present, we can support any of the
@@ -6973,6 +6988,9 @@  static int mvpp2_port_probe(struct platform_device *pdev,
 				  port->phylink_config.supported_interfaces);
 			__set_bit(PHY_INTERFACE_MODE_SGMII,
 				  port->phylink_config.supported_interfaces);
+		} else if (phy_mode == PHY_INTERFACE_MODE_MII) {
+			__set_bit(PHY_INTERFACE_MODE_100BASEX,
+				  port->phylink_config.supported_interfaces);
 		}
 
 		phylink = phylink_create(&port->phylink_config, port_fwnode,