diff mbox series

[net-next,v12,09/15] net: stmmac: dwmac-loongson: Add phy_interface for Loongson GMAC

Message ID d0ca47778a424a142abbfa7947d8413dfbffc104.1714046812.git.siyanteng@loongson.cn (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series stmmac: Add Loongson platform support | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
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: 926 this patch: 926
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 6 maintainers not CCed: pabeni@redhat.com edumazet@google.com linux-stm32@st-md-mailman.stormreply.com linux-arm-kernel@lists.infradead.org kuba@kernel.org mcoquelin.stm32@gmail.com
netdev/build_clang success Errors and warnings before: 937 this patch: 937
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: 937 this patch: 937
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 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

Yanteng Si April 25, 2024, 1:06 p.m. UTC
The mac_interface of gmac is PHY_INTERFACE_MODE_RGMII_ID.

Signed-off-by: Feiyang Chen <chenfeiyang@loongson.cn>
Signed-off-by: Yinggang Gu <guyinggang@loongson.cn>
Signed-off-by: Yanteng Si <siyanteng@loongson.cn>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Russell King (Oracle) April 25, 2024, 2:36 p.m. UTC | #1
On Thu, Apr 25, 2024 at 09:06:12PM +0800, Yanteng Si wrote:
> The mac_interface of gmac is PHY_INTERFACE_MODE_RGMII_ID.

No it isn't!

> +	plat->phy_interface = PHY_INTERFACE_MODE_RGMII_ID;

You don't touch mac_interface here. Please read the big comment I put
in include/linux/stmmac.h above these fields in struct
plat_stmmacenet_data to indicate what the difference between
mac_interface and phy_interface are, and then correct which-ever
of the above needs to be corrected.

Thanks.
Yanteng Si April 26, 2024, 10:16 a.m. UTC | #2
Hi Russell,

在 2024/4/25 22:36, Russell King (Oracle) 写道:
>> The mac_interface of gmac is PHY_INTERFACE_MODE_RGMII_ID.
> No it isn't!
Ok, that's a typo.
>
>> +	plat->phy_interface = PHY_INTERFACE_MODE_RGMII_ID;
> You don't touch mac_interface here. Please read the big comment I put
> in include/linux/stmmac.h above these fields in struct
> plat_stmmacenet_data to indicate what the difference between
> mac_interface and phy_interface are, and then correct which-ever
> of the above needs to be corrected.

Copy your big comment here:

     int phy_addr;
     /* MAC ----- optional PCS ----- SerDes ----- optional PHY ----- Media
      *       ^                               ^
      * mac_interface                   phy_interface
      *
      * mac_interface is the MAC-side interface, which may be the same
      * as phy_interface if there is no intervening PCS. If there is a
      * PCS, then mac_interface describes the interface mode between the
      * MAC and PCS, and phy_interface describes the interface mode
      * between the PCS and PHY.
      */
     phy_interface_t mac_interface;
     /* phy_interface is the PHY-side interface - the interface used by
      * an attached PHY.
      */

Our hardware engineer said we don't support pcs, and if I understand

your comment correctly, our mac_interface and phy_interface should

be the same, right?


Thanks,

Yanteng
Russell King (Oracle) April 26, 2024, 11 a.m. UTC | #3
On Fri, Apr 26, 2024 at 06:16:42PM +0800, Yanteng Si wrote:
> Hi Russell,
> 
> 在 2024/4/25 22:36, Russell King (Oracle) 写道:
> > > The mac_interface of gmac is PHY_INTERFACE_MODE_RGMII_ID.
> > No it isn't!
> Ok, that's a typo.
> > 
> > > +	plat->phy_interface = PHY_INTERFACE_MODE_RGMII_ID;
> > You don't touch mac_interface here. Please read the big comment I put
> > in include/linux/stmmac.h above these fields in struct
> > plat_stmmacenet_data to indicate what the difference between
> > mac_interface and phy_interface are, and then correct which-ever
> > of the above needs to be corrected.
> 
> Copy your big comment here:
> 
>     int phy_addr;
>     /* MAC ----- optional PCS ----- SerDes ----- optional PHY ----- Media
>      *       ^                               ^
>      * mac_interface                   phy_interface
>      *
>      * mac_interface is the MAC-side interface, which may be the same
>      * as phy_interface if there is no intervening PCS. If there is a
>      * PCS, then mac_interface describes the interface mode between the
>      * MAC and PCS, and phy_interface describes the interface mode
>      * between the PCS and PHY.
>      */
>     phy_interface_t mac_interface;
>     /* phy_interface is the PHY-side interface - the interface used by
>      * an attached PHY.
>      */
> 
> Our hardware engineer said we don't support pcs, and if I understand
> 
> your comment correctly, our mac_interface and phy_interface should
> 
> be the same, right?

It only matters to the core code if priv->dma_cap.pcs is set true.
If it isn't, then mac_interface doesn't seem to be relevent (it
does get used by a truck load of platform specific code though
which I haven't looked at to answer this.)

I would suggest that if priv->dma_cap.pcs is false, then setting
mac_interface to PHY_INTERFACE_MODE_NA to make it explicit that
it's not used would be a good idea.

While looking at this, however, I've come across the fact that
stmmac manipulates the netif carrier via netif_carrier_off() and
netif_carrier_on(), which is a _big_ no no when using phylink.
Phylink manages the carrier for the driver, and its part of
phylink's state. Fiddling with the carrier totally breaks the
guarantee that phylink will make calls to mac_link_down() and
mac_link_up().

If a driver wants to fiddle with the netif carrier, it must NOT
use phylink. If it wants to use phylink, it must NOT fiddle with
the netif carrier state. The two are mutually exclusive.

stmmac is quickly becoming a driver I don't care about whether my
changes to phylink end up breaking it or not because of abuses
like this.
Serge Semin May 3, 2024, 9:01 p.m. UTC | #4
On Fri, Apr 26, 2024 at 12:00:25PM +0100, Russell King (Oracle) wrote:
> On Fri, Apr 26, 2024 at 06:16:42PM +0800, Yanteng Si wrote:
> > Hi Russell,
> > 
> > 在 2024/4/25 22:36, Russell King (Oracle) 写道:
> > > > The mac_interface of gmac is PHY_INTERFACE_MODE_RGMII_ID.
> > > No it isn't!
> > Ok, that's a typo.
> > > 
> > > > +	plat->phy_interface = PHY_INTERFACE_MODE_RGMII_ID;
> > > You don't touch mac_interface here. Please read the big comment I put
> > > in include/linux/stmmac.h above these fields in struct
> > > plat_stmmacenet_data to indicate what the difference between
> > > mac_interface and phy_interface are, and then correct which-ever
> > > of the above needs to be corrected.
> > 
> > Copy your big comment here:
> > 
> >     int phy_addr;
> >     /* MAC ----- optional PCS ----- SerDes ----- optional PHY ----- Media
> >      *       ^                               ^
> >      * mac_interface                   phy_interface
> >      *
> >      * mac_interface is the MAC-side interface, which may be the same
> >      * as phy_interface if there is no intervening PCS. If there is a
> >      * PCS, then mac_interface describes the interface mode between the
> >      * MAC and PCS, and phy_interface describes the interface mode
> >      * between the PCS and PHY.
> >      */
> >     phy_interface_t mac_interface;
> >     /* phy_interface is the PHY-side interface - the interface used by
> >      * an attached PHY.
> >      */
> > 
> > Our hardware engineer said we don't support pcs, and if I understand
> > 
> > your comment correctly, our mac_interface and phy_interface should
> > 
> > be the same, right?
> 

> It only matters to the core code if priv->dma_cap.pcs is set true.
> If it isn't, then mac_interface doesn't seem to be relevent

Absolutely correct. Moreover AFAICS from the databooks the PCS module
is only available for the DW GMACs with the TBI, RTBI and SGMII
interfaces. So the STMMAC_PCS_RGMII PCS flag seems misleading. The only
info about the link state that could be runtime detected on the MAC
side is: link speed, duplex mode and link status. It's done by means
of the RGMII in-band status signals. That's what is implemented in the
dwmac1000_rgsmii() method. I've checked it works as soon as the
GMAC_INT_DISABLE_RGMII IRQ is unmask. But the RGMII-capable DW GMACs
don't support the Auto-negotiation feature, because it has no PCS
inside. Thus what has been implemented for the RGMII case in
stmmac_ethtool_get_link_ksettings() and
stmmac_ethtool_set_link_ksettings() seems incorrect to me.

> (it
> does get used by a truck load of platform specific code though
> which I haven't looked at to answer this.)

IMO the most of them are using the plat_stmmacenet_data::mac_interface
field as just an additional storage of the PHY-interface type. The
only cases which I would consider as validly using the field are the
ones with the SGMII interface support (and TBI/RTBI).

BTW I see the "mac-mode" DT-property support was introduced in 2019 by
the commit 0060c8783330 ("net: stmmac: implement support for passive
mode converters via dt"). The commit didn't touch any of the platform
drivers, but merely changed the plat_stmmacenet_data::mac_interface
semantics to containing the intermediate interface type if the
property was specified. So IMO all the platform drivers which had been
available by the time the change was introduced can be converted to
using the plat_stmmacenet_data::phy_interface field with a small
probability to break things.

I can't help but notice that since that commit there have been no any
DW MAC DT-node introduced with the "mac-mode" property specified. So
all of that makes me thinking that the code implemented around the
mac_interface data has been mainly unused and most likely was needless
overcomplication. Sigh...

> 
> I would suggest that if priv->dma_cap.pcs is false, then setting
> mac_interface to PHY_INTERFACE_MODE_NA to make it explicit that
> it's not used would be a good idea.

I bet it will be false. But Yanteng, could you please double check
that?

If it is could you convert this patch to setting
plat_stmmacenet_data::mac_interface with PHY_INTERFACE_MODE_NA by
default for all your device and setting the
plat_stmmacenet_data::phy_interface with PHY_INTERFACE_MODE_RGMII_ID
for the Loongson GMAC devices?

BTW Yanteng, are you sure it's supposed to
PHY_INTERFACE_MODE_RGMII_ID? AFAICS from the Loongson DTS files
(loongson64-2k1000.dtsi, ls7a-pch.dtsi) the phy-mode is just
PHY_INTERFACE_MODE_RGMII with no internal delays.

-Serge(y)

> 
> While looking at this, however, I've come across the fact that
> stmmac manipulates the netif carrier via netif_carrier_off() and
> netif_carrier_on(), which is a _big_ no no when using phylink.
> Phylink manages the carrier for the driver, and its part of
> phylink's state. Fiddling with the carrier totally breaks the
> guarantee that phylink will make calls to mac_link_down() and
> mac_link_up().
> 
> If a driver wants to fiddle with the netif carrier, it must NOT
> use phylink. If it wants to use phylink, it must NOT fiddle with
> the netif carrier state. The two are mutually exclusive.
> 
> stmmac is quickly becoming a driver I don't care about whether my
> changes to phylink end up breaking it or not because of abuses
> like this.
> 
> -- 
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Russell King (Oracle) May 7, 2024, 8:22 a.m. UTC | #5
On Sat, May 04, 2024 at 12:01:42AM +0300, Serge Semin wrote:
> Absolutely correct. Moreover AFAICS from the databooks the PCS module
> is only available for the DW GMACs with the TBI, RTBI and SGMII
> interfaces. So the STMMAC_PCS_RGMII PCS flag seems misleading. The only
> info about the link state that could be runtime detected on the MAC
> side is: link speed, duplex mode and link status. It's done by means
> of the RGMII in-band status signals. That's what is implemented in the
> dwmac1000_rgsmii() method.

... which you've now made me look at, look at the whole
pcs_link/pcs_speed/pcs_duplex and made me wonder why the hell stmmac
is making this so figgin difficult, messing with the carrier behind
phylink's back (which is a no-no), and why it needs to have separate
paths for this.

It doesn't.

Just because it doesn't have something called an official "PCS" does
not mean you _can't_ use a phylink_pcs to represent something that
has PCS-like properties - such as the RGMII in-band status which is
no different to what Cisco SGMII does.

This isn't something new... this is something that mvneta has
supported since before phylink was a thing, and so phylink had to
allow it as well.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
index f7618edf4a3a..e989cb835340 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
@@ -49,6 +49,7 @@  static int loongson_gmac_data(struct plat_stmmacenet_data *plat)
 	loongson_default_data(plat);
 
 	plat->mdio_bus_data->phy_mask = 0;
+	plat->phy_interface = PHY_INTERFACE_MODE_RGMII_ID;
 
 	return 0;
 }