mbox series

[net-next,0/4] net: Introduce QUSGMII phy mode

Message ID 20220728145252.439201-1-maxime.chevallier@bootlin.com
Headers show
Series net: Introduce QUSGMII phy mode | expand

Message

Maxime Chevallier July 28, 2022, 2:52 p.m. UTC
Hello everyone,

This is the V2 of a previous series [1] initially aimed at introducing
inband extensions, with modes like QUSGMII. This mode allows passing
info in the ethernet preamble between the MAC and the PHY, such s
timestamps.

This series has now become a preliminary series, that simply introduces
the new interface mode, without support for inband extensions, that will
come later.

The reasonning is that work will need to be done in the networking
subsystem, but also in the generic phy driver subsystem to allow serdes
configuration for qusgmii.

This series add the mode, the relevant binding changes, adds support for
it in the lan966x driver, and also introduces a small helper to get the
number of links a given phy mode can carry (think 1 for SGMII and 4 for
QSGMII). This allows for better readability and will prove useful
when (if) we support PSGMII (5 links on 1 interface) and OUSGMII (8
links on one interface).

Best regards,

Maxime

[1] : https://lore.kernel.org/netdev/20220519135647.465653-1-maxime.chevallier@bootlin.com/

Maxime Chevallier (4):
  net: phy: Introduce QUSGMII PHY mode
  dt-bindings: net: ethernet-controller: add QUSGMII mode
  net: phy: Add helper to derive the number of ports from a phy mode
  net: lan966x: Add QUSGMII support for lan966x

 .../bindings/net/ethernet-controller.yaml     |  1 +
 Documentation/networking/phy.rst              |  9 ++++
 .../ethernet/microchip/lan966x/lan966x_main.c |  2 +
 .../microchip/lan966x/lan966x_phylink.c       |  3 +-
 .../ethernet/microchip/lan966x/lan966x_port.c | 22 +++++---
 .../ethernet/microchip/lan966x/lan966x_regs.h |  6 +++
 drivers/net/phy/phy-core.c                    | 52 +++++++++++++++++++
 drivers/net/phy/phylink.c                     |  3 ++
 include/linux/phy.h                           |  5 ++
 9 files changed, 96 insertions(+), 7 deletions(-)

Comments

Andrew Lunn July 28, 2022, 9:23 p.m. UTC | #1
> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 87638c55d844..6b96b810a4d8 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -152,6 +152,7 @@ typedef enum {
>  	PHY_INTERFACE_MODE_USXGMII,
>  	/* 10GBASE-KR - with Clause 73 AN */
>  	PHY_INTERFACE_MODE_10GKR,
> +	PHY_INTERFACE_MODE_QUSGMII,
>  	PHY_INTERFACE_MODE_MAX,
>  } phy_interface_t;

I _think_ this will give you a kerneldoc warning about
PHY_INTERFACE_MODE_QUSGMII not having any documentation?

	   Andrew
Andrew Lunn July 28, 2022, 9:32 p.m. UTC | #2
> +int phy_interface_num_ports(phy_interface_t interface)
> +{
> +	switch (interface) {
> +	case PHY_INTERFACE_MODE_NA:
> +	case PHY_INTERFACE_MODE_INTERNAL:
> +		return 0;

I've not yet looked at how this is used. Returning 0 could have
interesting effects i guess? INTERNAL clearly does have some sort of
path between the MAC and the PHY, so i think 1 would be a better
value. NA is less clear, it generally means Don't touch. But again,
there still needs to be a path between the MAC and PHY, otherwise
there would not be any to touch.

Why did you pick 0?

> +
> +	case PHY_INTERFACE_MODE_MII:
> +	case PHY_INTERFACE_MODE_GMII:
> +	case PHY_INTERFACE_MODE_TBI:
> +	case PHY_INTERFACE_MODE_REVMII:
> +	case PHY_INTERFACE_MODE_RMII:
> +	case PHY_INTERFACE_MODE_REVRMII:
> +	case PHY_INTERFACE_MODE_RGMII:
> +	case PHY_INTERFACE_MODE_RGMII_ID:
> +	case PHY_INTERFACE_MODE_RGMII_RXID:
> +	case PHY_INTERFACE_MODE_RGMII_TXID:
> +	case PHY_INTERFACE_MODE_RTBI:
> +	case PHY_INTERFACE_MODE_XGMII:
> +	case PHY_INTERFACE_MODE_XLGMII:
> +	case PHY_INTERFACE_MODE_MOCA:
> +	case PHY_INTERFACE_MODE_TRGMII:
> +	case PHY_INTERFACE_MODE_USXGMII:
> +	case PHY_INTERFACE_MODE_SGMII:
> +	case PHY_INTERFACE_MODE_SMII:
> +	case PHY_INTERFACE_MODE_1000BASEX:
> +	case PHY_INTERFACE_MODE_2500BASEX:
> +	case PHY_INTERFACE_MODE_5GBASER:
> +	case PHY_INTERFACE_MODE_10GBASER:
> +	case PHY_INTERFACE_MODE_25GBASER:
> +	case PHY_INTERFACE_MODE_10GKR:
> +	case PHY_INTERFACE_MODE_100BASEX:
> +	case PHY_INTERFACE_MODE_RXAUI:
> +	case PHY_INTERFACE_MODE_XAUI:
> +		return 1;
> +	case PHY_INTERFACE_MODE_QSGMII:
> +	case PHY_INTERFACE_MODE_QUSGMII:
> +		return 4;
> +
> +	default:
> +		return 0;
> +	}
> +}

Have you tried without a default: ? I _think_ gcc will then warn about
missing enum values, which will help future developers when they add
further values to the enum.

	Andrew
Florian Fainelli July 28, 2022, 9:44 p.m. UTC | #3
On 7/28/22 14:32, Andrew Lunn wrote:
>> +int phy_interface_num_ports(phy_interface_t interface)
>> +{
>> +	switch (interface) {
>> +	case PHY_INTERFACE_MODE_NA:
>> +	case PHY_INTERFACE_MODE_INTERNAL:
>> +		return 0;
> 
> I've not yet looked at how this is used. Returning 0 could have
> interesting effects i guess? INTERNAL clearly does have some sort of
> path between the MAC and the PHY, so i think 1 would be a better
> value. NA is less clear, it generally means Don't touch. But again,
> there still needs to be a path between the MAC and PHY, otherwise
> there would not be any to touch.
> 
> Why did you pick 0?

I would agree that returning 1 is a more sensible default to avoid breaking users of that function. However this makes me wonder, in what case will we break the following common meaning:

- Q -> quad
- P -> penta
- O -> octal

Is the helper really needed in the sense that the phy_interface_t enumeration is explicit enough thanks to or because of its name?
--
Florian
Maxime Chevallier July 29, 2022, 6:50 a.m. UTC | #4
Hello Florian, Andrew,

On Thu, 28 Jul 2022 14:44:47 -0700
Florian Fainelli <f.fainelli@gmail.com> wrote:

> On 7/28/22 14:32, Andrew Lunn wrote:
> >> +int phy_interface_num_ports(phy_interface_t interface)
> >> +{
> >> +	switch (interface) {
> >> +	case PHY_INTERFACE_MODE_NA:
> >> +	case PHY_INTERFACE_MODE_INTERNAL:
> >> +		return 0;  
> > 
> > I've not yet looked at how this is used. Returning 0 could have
> > interesting effects i guess? INTERNAL clearly does have some sort of
> > path between the MAC and the PHY, so i think 1 would be a better
> > value. NA is less clear, it generally means Don't touch. But again,
> > there still needs to be a path between the MAC and PHY, otherwise
> > there would not be any to touch.
> > 
> > Why did you pick 0?  

My reasonning was that PHY_INTERNAL is likely a custom solution to link
IPs existing on the same die, so nothing prevents vendors from
multiplexing links on that interface. But it's a far-fetched
reasonning, so 1 can be good, as other interfaces that are meant to be
used on-die like XGMII.

> I would agree that returning 1 is a more sensible default to avoid
> breaking users of that function. However this makes me wonder, in
> what case will we break the following common meaning:
> 
> - Q -> quad
> - P -> penta
> - O -> octal
> 
> Is the helper really needed in the sense that the phy_interface_t
> enumeration is explicit enough thanks to or because of its name? --
> Florian

Good question actually ! It started as a point from Russell proposing a
helper to get the number of serdes lanes for a given interface, but
this sisn't quite fit the use-case, which was simply to simplify

	if (interface == PHY_INTERFACE_MODE_QSGMII ||
	    interface == PHY_INTERFACE_MODE_QUSGMII)

into

	if (phy_interface_num_ports(interface) == 4)

But this a slim simplification at the cost of a new helper to maintain,
so I can repove that if you want.

Thanks for the reviews,

Maxime
Maxime Chevallier July 29, 2022, 7:32 a.m. UTC | #5
On Thu, 28 Jul 2022 23:32:36 +0200
Andrew Lunn <andrew@lunn.ch> wrote:

> > +int phy_interface_num_ports(phy_interface_t interface)
> > +{
> > +	switch (interface) {
> > +	case PHY_INTERFACE_MODE_NA:
> > +	case PHY_INTERFACE_MODE_INTERNAL:
> > +		return 0;  
> 
> I've not yet looked at how this is used. Returning 0 could have
> interesting effects i guess? INTERNAL clearly does have some sort of
> path between the MAC and the PHY, so i think 1 would be a better
> value. NA is less clear, it generally means Don't touch. But again,
> there still needs to be a path between the MAC and PHY, otherwise
> there would not be any to touch.
> 
> Why did you pick 0?
> 
> > +
> > +	case PHY_INTERFACE_MODE_MII:
> > +	case PHY_INTERFACE_MODE_GMII:
> > +	case PHY_INTERFACE_MODE_TBI:
> > +	case PHY_INTERFACE_MODE_REVMII:
> > +	case PHY_INTERFACE_MODE_RMII:
> > +	case PHY_INTERFACE_MODE_REVRMII:
> > +	case PHY_INTERFACE_MODE_RGMII:
> > +	case PHY_INTERFACE_MODE_RGMII_ID:
> > +	case PHY_INTERFACE_MODE_RGMII_RXID:
> > +	case PHY_INTERFACE_MODE_RGMII_TXID:
> > +	case PHY_INTERFACE_MODE_RTBI:
> > +	case PHY_INTERFACE_MODE_XGMII:
> > +	case PHY_INTERFACE_MODE_XLGMII:
> > +	case PHY_INTERFACE_MODE_MOCA:
> > +	case PHY_INTERFACE_MODE_TRGMII:
> > +	case PHY_INTERFACE_MODE_USXGMII:
> > +	case PHY_INTERFACE_MODE_SGMII:
> > +	case PHY_INTERFACE_MODE_SMII:
> > +	case PHY_INTERFACE_MODE_1000BASEX:
> > +	case PHY_INTERFACE_MODE_2500BASEX:
> > +	case PHY_INTERFACE_MODE_5GBASER:
> > +	case PHY_INTERFACE_MODE_10GBASER:
> > +	case PHY_INTERFACE_MODE_25GBASER:
> > +	case PHY_INTERFACE_MODE_10GKR:
> > +	case PHY_INTERFACE_MODE_100BASEX:
> > +	case PHY_INTERFACE_MODE_RXAUI:
> > +	case PHY_INTERFACE_MODE_XAUI:
> > +		return 1;
> > +	case PHY_INTERFACE_MODE_QSGMII:
> > +	case PHY_INTERFACE_MODE_QUSGMII:
> > +		return 4;
> > +
> > +	default:
> > +		return 0;
> > +	}
> > +}  
> 
> Have you tried without a default: ? I _think_ gcc will then warn about
> missing enum values, which will help future developers when they add
> further values to the enum.

Without the default clause, I get an error about the missing
PHY_INTERFACE_MODE_MAX case, which I don't think belongs here...

Too bad :/

> 	Andrew
Andrew Lunn July 29, 2022, 1 p.m. UTC | #6
On Fri, Jul 29, 2022 at 09:32:52AM +0200, Maxime Chevallier wrote:
> On Thu, 28 Jul 2022 23:32:36 +0200
> Andrew Lunn <andrew@lunn.ch> wrote:
> 
> > > +int phy_interface_num_ports(phy_interface_t interface)
> > > +{
> > > +	switch (interface) {
> > > +	case PHY_INTERFACE_MODE_NA:
> > > +	case PHY_INTERFACE_MODE_INTERNAL:
> > > +		return 0;  
> > 
> > I've not yet looked at how this is used. Returning 0 could have
> > interesting effects i guess? INTERNAL clearly does have some sort of
> > path between the MAC and the PHY, so i think 1 would be a better
> > value. NA is less clear, it generally means Don't touch. But again,
> > there still needs to be a path between the MAC and PHY, otherwise
> > there would not be any to touch.
> > 
> > Why did you pick 0?
> > 
> > > +
> > > +	case PHY_INTERFACE_MODE_MII:
> > > +	case PHY_INTERFACE_MODE_GMII:
> > > +	case PHY_INTERFACE_MODE_TBI:
> > > +	case PHY_INTERFACE_MODE_REVMII:
> > > +	case PHY_INTERFACE_MODE_RMII:
> > > +	case PHY_INTERFACE_MODE_REVRMII:
> > > +	case PHY_INTERFACE_MODE_RGMII:
> > > +	case PHY_INTERFACE_MODE_RGMII_ID:
> > > +	case PHY_INTERFACE_MODE_RGMII_RXID:
> > > +	case PHY_INTERFACE_MODE_RGMII_TXID:
> > > +	case PHY_INTERFACE_MODE_RTBI:
> > > +	case PHY_INTERFACE_MODE_XGMII:
> > > +	case PHY_INTERFACE_MODE_XLGMII:
> > > +	case PHY_INTERFACE_MODE_MOCA:
> > > +	case PHY_INTERFACE_MODE_TRGMII:
> > > +	case PHY_INTERFACE_MODE_USXGMII:
> > > +	case PHY_INTERFACE_MODE_SGMII:
> > > +	case PHY_INTERFACE_MODE_SMII:
> > > +	case PHY_INTERFACE_MODE_1000BASEX:
> > > +	case PHY_INTERFACE_MODE_2500BASEX:
> > > +	case PHY_INTERFACE_MODE_5GBASER:
> > > +	case PHY_INTERFACE_MODE_10GBASER:
> > > +	case PHY_INTERFACE_MODE_25GBASER:
> > > +	case PHY_INTERFACE_MODE_10GKR:
> > > +	case PHY_INTERFACE_MODE_100BASEX:
> > > +	case PHY_INTERFACE_MODE_RXAUI:
> > > +	case PHY_INTERFACE_MODE_XAUI:
> > > +		return 1;
> > > +	case PHY_INTERFACE_MODE_QSGMII:
> > > +	case PHY_INTERFACE_MODE_QUSGMII:
> > > +		return 4;
> > > +
> > > +	default:
> > > +		return 0;
> > > +	}
> > > +}  
> > 
> > Have you tried without a default: ? I _think_ gcc will then warn about
> > missing enum values, which will help future developers when they add
> > further values to the enum.
> 
> Without the default clause, I get an error about the missing
> PHY_INTERFACE_MODE_MAX case, which I don't think belongs here...

  case PHY_INTERFACE_MODE_MAX:
	WARN_ONCE()
	return 0;
	break;

Being passed PHY_INTERFACE_MODE_MAX is a bug in itself, so warning
seems sensible.

      Andrew