Message ID | 20220729153356.581444-4-maxime.chevallier@bootlin.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | net: Introduce QUSGMII phy mode | expand |
On 7/29/22 08:33, Maxime Chevallier wrote: > Some phy modes such as QSGMII multiplex several MAC<->PHY links on one > single physical interface. QSGMII used to be the only one supported, but > other modes such as QUSGMII also carry multiple links. > > This helper allows getting the number of links that are multiplexed > on a given interface. > > Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com> > --- > V1->V2 : New patch > V2->V3 : Made PHY_INTERFACE_MODE_INTERNAL 1 port, and added the MAX > case. > > drivers/net/phy/phy-core.c | 52 ++++++++++++++++++++++++++++++++++++++ > include/linux/phy.h | 2 ++ > 2 files changed, 54 insertions(+) > > diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c > index 1f2531a1a876..f8ec12d3d6ae 100644 > --- a/drivers/net/phy/phy-core.c > +++ b/drivers/net/phy/phy-core.c > @@ -74,6 +74,58 @@ const char *phy_duplex_to_str(unsigned int duplex) > } > EXPORT_SYMBOL_GPL(phy_duplex_to_str); > > +/** > + * phy_interface_num_ports - Return the number of links that can be carried by > + * a given MAC-PHY physical link. Returns 0 if this is > + * unknown, the number of links else. > + * > + * @interface: The interface mode we want to get the number of ports > + */ > +int phy_interface_num_ports(phy_interface_t interface) > +{ > + switch (interface) { > + case PHY_INTERFACE_MODE_NA: > + return 0; > + case PHY_INTERFACE_MODE_INTERNAL: Maybe this was covered in the previous iteration, but cannot the default case return 1, and all of the cases that need an explicit non-1 return value are handled? Enumeration all of those that do need to return 1 does not really scale.
> > +int phy_interface_num_ports(phy_interface_t interface) > > +{ > > + switch (interface) { > > + case PHY_INTERFACE_MODE_NA: > > + return 0; > > + case PHY_INTERFACE_MODE_INTERNAL: > > Maybe this was covered in the previous iteration, but cannot the > default case return 1, and all of the cases that need an explicit > non-1 return value are handled? Enumeration all of those that do > need to return 1 does not really scale. It is a trade off. In the current form, when somebody adds a new enum value, gcc will give a warning if they forget to add it here. If we default to 1, new values are probably going to be missed here, and could end up with the incorrect return value. I think the compiler warning actually does make it scale. And the generated code probably very similar either way. Andrew
diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index 1f2531a1a876..f8ec12d3d6ae 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -74,6 +74,58 @@ const char *phy_duplex_to_str(unsigned int duplex) } EXPORT_SYMBOL_GPL(phy_duplex_to_str); +/** + * phy_interface_num_ports - Return the number of links that can be carried by + * a given MAC-PHY physical link. Returns 0 if this is + * unknown, the number of links else. + * + * @interface: The interface mode we want to get the number of ports + */ +int phy_interface_num_ports(phy_interface_t interface) +{ + switch (interface) { + case PHY_INTERFACE_MODE_NA: + return 0; + case PHY_INTERFACE_MODE_INTERNAL: + 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; + case PHY_INTERFACE_MODE_MAX: + WARN_ONCE(1, "PHY_INTERFACE_MODE_MAX isn't a valid interface mode"); + return 0; + } + return 0; +} +EXPORT_SYMBOL_GPL(phy_interface_num_ports); + /* A mapping of all SUPPORTED settings to speed/duplex. This table * must be grouped by speed and sorted in descending match priority * - iow, descending speed. diff --git a/include/linux/phy.h b/include/linux/phy.h index 9eeab9b9a74c..7c49ab95441b 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -968,6 +968,8 @@ struct phy_fixup { const char *phy_speed_to_str(int speed); const char *phy_duplex_to_str(unsigned int duplex); +int phy_interface_num_ports(phy_interface_t interface); + /* A structure for mapping a particular speed and duplex * combination to a particular SUPPORTED and ADVERTISED value */
Some phy modes such as QSGMII multiplex several MAC<->PHY links on one single physical interface. QSGMII used to be the only one supported, but other modes such as QUSGMII also carry multiple links. This helper allows getting the number of links that are multiplexed on a given interface. Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com> --- V1->V2 : New patch V2->V3 : Made PHY_INTERFACE_MODE_INTERNAL 1 port, and added the MAX case. drivers/net/phy/phy-core.c | 52 ++++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 2 ++ 2 files changed, 54 insertions(+)