Skip to contentSkip to conversation

Convert Felix DSA switch to PHYLINK

RFC PATCH Superseded Vladimir Oltean 6 participants 21 messages Dec 17, 2019 – Dec 19, 2019

Subsystems (8)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Vladimir Oltean

author maintainer
#0 lore raw

v2 cover Convert Felix DSA switch to PHYLINK

From: Vladimir Oltean <[email protected]>

Unlike most other conversions, and unlike this series' own v1 [0] from which it is radically different, this conversion is not by far a trivial one, and should be seen as "Layerscape PCS meets PHYLINK". Depending on the feedback received, the PCS driver from felix_vsc9959 can in fact be generalized to cover most of the Layerscape devices, or we can scrap the idea. Actually, the PCS doesn't need a lot of hand-holding and most of our other devices 'just work' (this one included) without any sort of operating system awareness, just an initialization procedure done typically in the bootloader.

The PCS is not specific to the Vitesse / Microsemi / Microchip switching core at all. Variations of this SerDes/PCS design can also be found on DPAA1 and DPAA2 hardware.

The main idea of the abstraction provided is that the PCS looks so much like a PHY device, that we model it as an actual PHY device and run the generic PHY functions on it, where appropriate.

The 4xSGMII, QSGMII and QSXGMII modes are fairly straightforward.

The SerDes protocol which the driver calls 2500Base-X mode (a misnomer) is more interesting. There is a description of how it works and what can be done with it in patch 8/8 (in a comment above vsc9959_pcs_init_2500basex). In short, it is a fixed speed protocol with no auto-negotiation whatsoever. From my research of the SGMII-2500 patent [1], it has nothing to do with SGMII-2500. That one:
* does not define any change to the AN base page compared to plain 10/100/1000 SGMII. This implies that the 2500 speed is not negotiable, but the other speeds are. In our case, when the SerDes is configured for this protocol it's configured for good, there's no going back to SGMII.
* runs at a higher base frequency than regular SGMII. So SGMII-2500 operating at 1000 Mbps wouldn't interoperate with plain SGMII at 1000 Mbps. Strange, but ok..
* Emulates lower link speeds than 2500 by duplicating the codewords twice, then thrice, then twice again etc (2.5/25/250 times on average). The Layerscape PCS doesn't do that (it is fixed at 2500 Mbaud).

But on the other hand it isn't Base-X either, since it doesn't do 802.3z / clause 37 auto negotiation (flow control, local/remote fault etc).

So it is a protocol in its own right (a rather fixed one). If reviewers think it should have its own phy-mode, different than 2500base-x, I'm in favor of that. It's just that I couldn't find a suitable name for it. quarter-xaui? 3125mhz-8b10b?

When inter-operating with the Aquantia AQR112 and AQR412 PHYs in this mode (for which the PHY uses a proprietary name "OCSGMII"), we do still need to support the lower link speeds negotiated by the PHY on copper side. So what we typically do is we enable rate adaptation in the PHY firmware, with pause frames and a fixed link speed on the system side. Raising this as a discussion item to understand how we can model this quirky operating mode in Linux without imposing limitations on others (we have some downstream patches on the Aquantia PHY driver as well).

Another item to discuss is whether we should be able to disable AN in the PCS independently of whether we have a PHY as a peer or not. With an SGMII PHY-less connection, there may be no auto-negotiation master so the link partners will bounce for a while and then they'll settle on 10 Mbps as link speed. For those connections (such as an SGMII link to a downstream switch) we need to disable AN in the PCS and force the speed to 1000.
So:
* If we have a PHY we want to do auto-neg
* If we don't have a PHY, maybe we want AN, maybe we don't
* In the 2500Base-X mode, we can't do AN because the hardware doesn't support it

I have found the 'managed = "in-band-status"' DTS binding to somewhat address this concern, but I am a bit reluctant to disable SGMII AN if it isn't set. We have boards with device trees that need to be migrated from PHYLIB and I am concerned that changing the behavior w.r.t. in-band AN (when the "in-band-status" property is not present) is not going to be pleasant. I do understand that the "in-band-status" property is primarily intended to be used with PHY-less setups, and it looks like the fact it does work with PHYs as well is more of an oversight (as patch 2/8 shows). So I'm not sure who else really uses it with a phy-handle.

There are some more open questions in patch 8/8.

I dropped the Ocelot PHYLINK conversion because:
* I don't have VSC7514 hardware anyway
* The hardware is so different in this regard that there's almost nothing to share anyway.

[0]: https://www.spinics.net/lists/netdev/msg613869.html
[1]: https://patents.google.com/patent/US7356047B1/en

Claudiu Manoil (1):
enetc: Make MDIO accessors more generic and export to
include/linux/fsl

Vladimir Oltean (7):
mii: Add helpers for parsing SGMII auto-negotiation
net: phylink: make QSGMII a valid PHY mode for in-band AN
net: phylink: call mac_an_restart for SGMII/QSGMII inband interfaces
too
enetc: Set MDIO_CFG_HOLD to the recommended value of 2
net: mscc: ocelot: make phy_mode a member of the common struct
ocelot_port
net: mscc: ocelot: export ANA, DEV and QSYS registers to
include/soc/mscc
net: dsa: felix: Add PCS operations for PHYLINK

 drivers/net/dsa/ocelot/Kconfig                     |   1 +
 drivers/net/dsa/ocelot/felix.c                     | 260 ++++++++-
 drivers/net/dsa/ocelot/felix.h                     |  16 +-
 drivers/net/dsa/ocelot/felix_vsc9959.c             | 475 +++++++++++++++-
 drivers/net/ethernet/freescale/enetc/enetc_hw.h    |   1 +
 drivers/net/ethernet/freescale/enetc/enetc_mdio.c  |  88 ++-
 drivers/net/ethernet/freescale/enetc/enetc_mdio.h  |  12 -
 .../net/ethernet/freescale/enetc/enetc_pci_mdio.c  |  43 +-
 drivers/net/ethernet/mscc/ocelot.c                 |   7 +-
 drivers/net/ethernet/mscc/ocelot.h                 |   7 +-
 drivers/net/ethernet/mscc/ocelot_ana.h             | 625 ---------------------
 drivers/net/ethernet/mscc/ocelot_board.c           |   4 +-
 drivers/net/ethernet/mscc/ocelot_dev.h             | 275 ---------
 drivers/net/ethernet/mscc/ocelot_qsys.h            | 270 ---------
 drivers/net/phy/phylink.c                          |   5 +-
 include/linux/fsl/enetc_mdio.h                     |  34 ++
 include/linux/mii.h                                |  50 ++
 include/soc/mscc/ocelot.h                          |   2 +
 include/soc/mscc/ocelot_ana.h                      | 625 +++++++++++++++++++++
 include/soc/mscc/ocelot_dev.h                      | 275 +++++++++
 include/soc/mscc/ocelot_qsys.h                     | 270 +++++++++
 include/uapi/linux/mii.h                           |  10 +
 22 files changed, 2100 insertions(+), 1255 deletions(-)
 delete mode 100644 drivers/net/ethernet/freescale/enetc/enetc_mdio.h
 delete mode 100644 drivers/net/ethernet/mscc/ocelot_ana.h
 delete mode 100644 drivers/net/ethernet/mscc/ocelot_dev.h
 delete mode 100644 drivers/net/ethernet/mscc/ocelot_qsys.h
 create mode 100644 include/linux/fsl/enetc_mdio.h
 create mode 100644 include/soc/mscc/ocelot_ana.h
 create mode 100644 include/soc/mscc/ocelot_dev.h
 create mode 100644 include/soc/mscc/ocelot_qsys.h
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

RFC PATCH v2 1/8 mii: Add helpers for parsing SGMII auto-negotiation

From: Vladimir Oltean <[email protected]>

Typically a MAC PCS auto-configures itself after it receives the negotiated copper-side link settings from the PHY, but some MAC devices are more special and need manual interpretation of the SGMII AN result.

In other cases, the PCS exposes the entire tx_config_reg base page as it is transmitted on the wire during auto-negotiation, so it makes sense to be able to decode the equivalent lp_advertised bit mask from the raw u16 (of course, "lp" considering the PCS to be the local PHY).

Therefore, add the bit definitions for the SGMII registers 4 and 5 (local device ability, link partner ability), as well as a link_mode conversion helper that can be used to feed the AN results into phy_resolve_aneg_linkmode.

---
 include/linux/mii.h      | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/mii.h | 10 ++++++++++
 2 files changed, 60 insertions(+)
include/linux/mii.h +50 -0
index 4ce8901a1af6..18c6208f56fc 100644
@@ -373,6 +373,56 @@ static inline u32 mii_lpa_to_ethtool_lpa_x(u32 lpa)
 }
 
 /**
+ * mii_lpa_mod_linkmode_adv_sgmii
+ * @lp_advertising: pointer to destination link mode.
+ * @lpa: value of the MII_LPA register
+ *
+ * A small helper function that translates MII_LPA bits to
+ * linkmode advertisement settings for SGMII.
+ * Leaves other bits unchanged.
+ */
+static inline void
+mii_lpa_mod_linkmode_lpa_sgmii(unsigned long *lp_advertising, u32 lpa)
+{
+	u32 speed_duplex = lpa & LPA_SGMII_DPX_SPD_MASK;
+
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, lp_advertising,
+			 speed_duplex == LPA_SGMII_1000HALF);
+
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, lp_advertising,
+			 speed_duplex == LPA_SGMII_1000FULL);
+
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, lp_advertising,
+			 speed_duplex == LPA_SGMII_100HALF);
+
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, lp_advertising,
+			 speed_duplex == LPA_SGMII_100FULL);
+
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, lp_advertising,
+			 speed_duplex == LPA_SGMII_10HALF);
+
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, lp_advertising,
+			 speed_duplex == LPA_SGMII_10FULL);
+}
+
+/**
+ * mii_lpa_to_linkmode_adv_sgmii
+ * @advertising: pointer to destination link mode.
+ * @lpa: value of the MII_LPA register
+ *
+ * A small helper function that translates MII_ADVERTISE bits
+ * to linkmode advertisement settings when in SGMII mode.
+ * Clears the old value of advertising.
+ */
+static inline void mii_lpa_to_linkmode_lpa_sgmii(unsigned long *lp_advertising,
+						 u32 lpa)
+{
+	linkmode_zero(lp_advertising);
+
+	mii_lpa_mod_linkmode_lpa_sgmii(lp_advertising, lpa);
+}
+
+/**
  * mii_adv_mod_linkmode_adv_t
  * @advertising:pointer to destination link mode.
  * @adv: value of the MII_ADVERTISE register
include/uapi/linux/mii.h +10 -0
index 51b48e4be1f2..dc3b5d635beb 100644
@@ -71,6 +71,7 @@
 /* Advertisement control register. */
 #define ADVERTISE_SLCT		0x001f	/* Selector bits               */
 #define ADVERTISE_CSMA		0x0001	/* Only selector supported     */
+#define ADVERTISE_SGMII		0x0001	/* Can do SGMII                */
 #define ADVERTISE_10HALF	0x0020	/* Try for 10mbps half-duplex  */
 #define ADVERTISE_1000XFULL	0x0020	/* Try for 1000BASE-X full-duplex */
 #define ADVERTISE_10FULL	0x0040	/* Try for 10mbps full-duplex  */
@@ -94,6 +95,7 @@
 
 /* Link partner ability register. */
 #define LPA_SLCT		0x001f	/* Same as advertise selector  */
+#define LPA_SGMII		0x0001	/* Can do SGMII                */
 #define LPA_10HALF		0x0020	/* Can do 10mbps half-duplex   */
 #define LPA_1000XFULL		0x0020	/* Can do 1000BASE-X full-duplex */
 #define LPA_10FULL		0x0040	/* Can do 10mbps full-duplex   */
@@ -104,11 +106,19 @@
 #define LPA_1000XPAUSE_ASYM	0x0100	/* Can do 1000BASE-X pause asym*/
 #define LPA_100BASE4		0x0200	/* Can do 100mbps 4k packets   */
 #define LPA_PAUSE_CAP		0x0400	/* Can pause                   */
+#define LPA_SGMII_DPX_SPD_MASK	0x1C00	/* SGMII duplex and speed bits */
+#define LPA_SGMII_10HALF	0x0000	/* Can do SGMII 10mbps half-duplex */
+#define LPA_SGMII_10FULL	0x1000	/* Can do SGMII 10mbps full-duplex */
+#define LPA_SGMII_100HALF	0x0400	/* Can do SGMII 100mbps half-duplex */
+#define LPA_SGMII_100FULL	0x1400	/* Can do SGMII 100mbps full-duplex */
 #define LPA_PAUSE_ASYM		0x0800	/* Can pause asymetrically     */
+#define LPA_SGMII_1000HALF	0x0800	/* Can do SGMII 1000mbps half-duplex */
+#define LPA_SGMII_1000FULL	0x1800	/* Can do SGMII 1000mbps full-duplex */
 #define LPA_RESV		0x1000	/* Unused...                   */
 #define LPA_RFAULT		0x2000	/* Link partner faulted        */
 #define LPA_LPACK		0x4000	/* Link partner acked us       */
 #define LPA_NPAGE		0x8000	/* Next page bit               */
+#define LPA_SGMII_LINK		0x8000	/* Link partner has link       */
 
 #define LPA_DUPLEX		(LPA_10FULL | LPA_100FULL)
 #define LPA_100			(LPA_100FULL | LPA_100HALF | LPA_100BASE4)
Signature · 1 line
2.7.4
#2 lore raw

Re: [RFC PATCH v2 1/8] mii: Add helpers for parsing SGMII auto-negotiation

Quoted 110 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

Typically a MAC PCS auto-configures itself after it receives the negotiated copper-side link settings from the PHY, but some MAC devices are more special and need manual interpretation of the SGMII AN result.

In other cases, the PCS exposes the entire tx_config_reg base page as it is transmitted on the wire during auto-negotiation, so it makes sense to be able to decode the equivalent lp_advertised bit mask from the raw u16 (of course, "lp" considering the PCS to be the local PHY).

Therefore, add the bit definitions for the SGMII registers 4 and 5 (local device ability, link partner ability), as well as a link_mode conversion helper that can be used to feed the AN results into phy_resolve_aneg_linkmode.

---
 include/linux/mii.h      | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/mii.h | 10 ++++++++++
 2 files changed, 60 insertions(+)
include/linux/mii.h +50 -0
index 4ce8901a1af6..18c6208f56fc 100644
@@ -373,6 +373,56 @@ static inline u32 mii_lpa_to_ethtool_lpa_x(u32 lpa)
 }
 
 /**
+ * mii_lpa_mod_linkmode_adv_sgmii
+ * @lp_advertising: pointer to destination link mode.
+ * @lpa: value of the MII_LPA register
+ *
+ * A small helper function that translates MII_LPA bits to
+ * linkmode advertisement settings for SGMII.
+ * Leaves other bits unchanged.
+ */
+static inline void
+mii_lpa_mod_linkmode_lpa_sgmii(unsigned long *lp_advertising, u32 lpa)
+{
+	u32 speed_duplex = lpa & LPA_SGMII_DPX_SPD_MASK;
+
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, lp_advertising,
+			 speed_duplex == LPA_SGMII_1000HALF);
+
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, lp_advertising,
+			 speed_duplex == LPA_SGMII_1000FULL);
+
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, lp_advertising,
+			 speed_duplex == LPA_SGMII_100HALF);
+
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, lp_advertising,
+			 speed_duplex == LPA_SGMII_100FULL);
+
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, lp_advertising,
+			 speed_duplex == LPA_SGMII_10HALF);
+
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, lp_advertising,
+			 speed_duplex == LPA_SGMII_10FULL);
+}
+
+/**
+ * mii_lpa_to_linkmode_adv_sgmii
+ * @advertising: pointer to destination link mode.
+ * @lpa: value of the MII_LPA register
+ *
+ * A small helper function that translates MII_ADVERTISE bits
+ * to linkmode advertisement settings when in SGMII mode.
+ * Clears the old value of advertising.
+ */
+static inline void mii_lpa_to_linkmode_lpa_sgmii(unsigned long *lp_advertising,
+						 u32 lpa)
+{
+	linkmode_zero(lp_advertising);
+
+	mii_lpa_mod_linkmode_lpa_sgmii(lp_advertising, lpa);
+}
+
+/**
  * mii_adv_mod_linkmode_adv_t
  * @advertising:pointer to destination link mode.
  * @adv: value of the MII_ADVERTISE register
include/uapi/linux/mii.h +5 -0
index 51b48e4be1f2..dc3b5d635beb 100644
@@ -71,6 +71,7 @@
 /* Advertisement control register. */
 #define ADVERTISE_SLCT		0x001f	/* Selector bits               */
 #define ADVERTISE_CSMA		0x0001	/* Only selector supported     */
+#define ADVERTISE_SGMII		0x0001	/* Can do SGMII                */
 #define ADVERTISE_10HALF	0x0020	/* Try for 10mbps half-duplex  */
 #define ADVERTISE_1000XFULL	0x0020	/* Try for 1000BASE-X full-duplex */
 #define ADVERTISE_10FULL	0x0040	/* Try for 10mbps full-duplex  */
@@ -94,6 +95,7 @@
 
 /* Link partner ability register. */
 #define LPA_SLCT		0x001f	/* Same as advertise selector  */
+#define LPA_SGMII		0x0001	/* Can do SGMII                */
 #define LPA_10HALF		0x0020	/* Can do 10mbps half-duplex   */
 #define LPA_1000XFULL		0x0020	/* Can do 1000BASE-X full-duplex */
 #define LPA_10FULL		0x0040	/* Can do 10mbps full-duplex   */
@@ -104,11 +106,19 @@
 #define LPA_1000XPAUSE_ASYM	0x0100	/* Can do 1000BASE-X pause asym*/
 #define LPA_100BASE4		0x0200	/* Can do 100mbps 4k packets   */
 #define LPA_PAUSE_CAP		0x0400	/* Can pause                   */
+#define LPA_SGMII_DPX_SPD_MASK	0x1C00	/* SGMII duplex and speed bits */
+#define LPA_SGMII_10HALF	0x0000	/* Can do SGMII 10mbps half-duplex */
+#define LPA_SGMII_10FULL	0x1000	/* Can do SGMII 10mbps full-duplex */

include/uapi/linux/mii.h line 121

Quoted 10 lines
include/uapi/linux/mii.h +5 -0
+#define LPA_SGMII_100HALF	0x0400	/* Can do SGMII 100mbps half-duplex */
+#define LPA_SGMII_100FULL	0x1400	/* Can do SGMII 100mbps full-duplex */
 #define LPA_PAUSE_ASYM		0x0800	/* Can pause asymetrically     */
+#define LPA_SGMII_1000HALF	0x0800	/* Can do SGMII 1000mbps half-duplex */
+#define LPA_SGMII_1000FULL	0x1800	/* Can do SGMII 1000mbps full-duplex */
 #define LPA_RESV		0x1000	/* Unused...                   */
 #define LPA_RFAULT		0x2000	/* Link partner faulted        */
 #define LPA_LPACK		0x4000	/* Link partner acked us       */
 #define LPA_NPAGE		0x8000	/* Next page bit               */
+#define LPA_SGMII_LINK		0x8000	/* Link partner has link       */

I wonder whether mixing these definitions together is really such a good idea, or whether separately grouping them would be better.

I already find the mixture of Clause 37 and Clause 22 definitions to be a little difficult to spot which are which.

Quoted 7 lines
include/uapi/linux/mii.h +0 -0
 #define LPA_DUPLEX		(LPA_10FULL | LPA_100FULL)
 #define LPA_100			(LPA_100FULL | LPA_100HALF | LPA_100BASE4)
Signature · 1 line
2.7.4
Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
maintainer
#3 lore raw

Re: [RFC PATCH v2 1/8] mii: Add helpers for parsing SGMII auto-negotiation

Quoted 32 lines
Quoted 32 lines
include/uapi/linux/mii.h +9 -0
index 51b48e4be1f2..dc3b5d635beb 100644
@@ -71,6 +71,7 @@
 /* Advertisement control register. */
 #define ADVERTISE_SLCT		0x001f	/* Selector bits               */
 #define ADVERTISE_CSMA		0x0001	/* Only selector supported     */
+#define ADVERTISE_SGMII		0x0001	/* Can do SGMII                */
 #define ADVERTISE_10HALF	0x0020	/* Try for 10mbps half-duplex  */
 #define ADVERTISE_1000XFULL	0x0020	/* Try for 1000BASE-X full-duplex */
 #define ADVERTISE_10FULL	0x0040	/* Try for 10mbps full-duplex  */
@@ -94,6 +95,7 @@
 
 /* Link partner ability register. */
 #define LPA_SLCT		0x001f	/* Same as advertise selector  */
+#define LPA_SGMII		0x0001	/* Can do SGMII                */
 #define LPA_10HALF		0x0020	/* Can do 10mbps half-duplex   */
 #define LPA_1000XFULL		0x0020	/* Can do 1000BASE-X full-duplex */
 #define LPA_10FULL		0x0040	/* Can do 10mbps full-duplex   */
@@ -104,11 +106,19 @@
 #define LPA_1000XPAUSE_ASYM	0x0100	/* Can do 1000BASE-X pause asym*/
 #define LPA_100BASE4		0x0200	/* Can do 100mbps 4k packets   */
 #define LPA_PAUSE_CAP		0x0400	/* Can pause                   */
+#define LPA_SGMII_DPX_SPD_MASK	0x1C00	/* SGMII duplex and speed bits */
+#define LPA_SGMII_10HALF	0x0000	/* Can do SGMII 10mbps half-duplex */
+#define LPA_SGMII_10FULL	0x1000	/* Can do SGMII 10mbps full-duplex */
+#define LPA_SGMII_100HALF	0x0400	/* Can do SGMII 100mbps half-duplex */
+#define LPA_SGMII_100FULL	0x1400	/* Can do SGMII 100mbps full-duplex */
 #define LPA_PAUSE_ASYM		0x0800	/* Can pause asymetrically     */
+#define LPA_SGMII_1000HALF	0x0800	/* Can do SGMII 1000mbps half-duplex */
+#define LPA_SGMII_1000FULL	0x1800	/* Can do SGMII 1000mbps full-duplex */
Quoted 8 lines

include/uapi/linux/mii.h line 121

Quoted 5 lines
include/uapi/linux/mii.h +1 -0
 #define LPA_RESV		0x1000	/* Unused...                   */
 #define LPA_RFAULT		0x2000	/* Link partner faulted        */
 #define LPA_LPACK		0x4000	/* Link partner acked us       */
 #define LPA_NPAGE		0x8000	/* Next page bit               */
+#define LPA_SGMII_LINK		0x8000	/* Link partner has link       */

I wonder whether mixing these definitions together is really such a good idea, or whether separately grouping them would be better.

I think i prefer a seperate grouping.

Andrew

author maintainer
#4 lore raw

RFC PATCH v2 2/8 net: phylink: make QSGMII a valid PHY mode for in-band AN

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

QSGMII is a SerDes protocol clocked at 5 Gbaud (4 times higher than SGMII which is clocked at 1.25 Gbaud), with the same 8b/10b encoding and some extra symbols for synchronization. Logically it offers 4 SGMII interfaces multiplexed onto the same physical lanes. Each MAC PCS has its own in-band AN process with the system side of the QSGMII PHY, which is identical to the regular SGMII AN process.

So allow QSGMII as a valid in-band AN mode, since it is no different from software perspective from regular SGMII.

---
 drivers/net/phy/phylink.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/phy/phylink.c +1 -0
index 1e0e32c466ee..f9ad794cfee1 100644
@@ -281,6 +281,7 @@ static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode)
 
 		switch (pl->link_config.interface) {
 		case PHY_INTERFACE_MODE_SGMII:
+		case PHY_INTERFACE_MODE_QSGMII:
 			phylink_set(pl->supported, 10baseT_Half);
 			phylink_set(pl->supported, 10baseT_Full);
 			phylink_set(pl->supported, 100baseT_Half);
Signature · 1 line
2.7.4
author maintainer
#5 lore raw

RFC PATCH v2 3/8 net: phylink: call mac_an_restart for SGMII/QSGMII inband interfaces too

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

It doesn't quite make sense why restarting the AN process should be unique to 802.3z (1000Base-X) modes. It is valid to put an SGMII PCS in in-band AN mode, therefore also make PHYLINK re-trigger an auto-negotiation if needed.

---
 drivers/net/phy/phylink.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/phy/phylink.c +3 -1
index f9ad794cfee1..0e563c22d725 100644
@@ -358,7 +358,9 @@ static void phylink_mac_config_up(struct phylink *pl,
 static void phylink_mac_an_restart(struct phylink *pl)
 {
 	if (pl->link_config.an_enabled &&
-	    phy_interface_mode_is_8023z(pl->link_config.interface))
+	    (phy_interface_mode_is_8023z(pl->link_config.interface) ||
+	     pl->link_config.interface == PHY_INTERFACE_MODE_SGMII ||
+	     pl->link_config.interface == PHY_INTERFACE_MODE_QSGMII))
 		pl->ops->mac_an_restart(pl->config);
 }
 
Signature · 1 line
2.7.4
#6 lore raw

Re: [RFC PATCH v2 3/8] net: phylink: call mac_an_restart for SGMII/QSGMII inband interfaces too

Quoted 6 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

It doesn't quite make sense why restarting the AN process should be unique to 802.3z (1000Base-X) modes. It is valid to put an SGMII PCS in in-band AN mode, therefore also make PHYLINK re-trigger an auto-negotiation if needed.

The question I'd ask is how is that actually achieved on the link?

It makes sense for 1000base-X because either end can drop the ACK bit to cause a renegotiation to occur, but it makes no sense for SGMII.

In SGMII:
1) there is no advertisement from the MAC to the PHY
2) the PHY is merely informing the MAC of the results of negotiation

Attempting to trigger a renegotiation at the MAC end does nothing useful for SGMII, it doesn't cause the PHY to renegotiate with its link partner.

The whole point of SGMII over 1000base-X is that the PHY informs the MAC using in-band signalling what the results of negotiation were on the media side of the PHY. SGMII provides no way to control the advertisement.

Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
author maintainer
#7 lore raw

RFC PATCH v2 4/8 enetc: Make MDIO accessors more generic and export to include/linux/fsl

In reply to Vladimir Oltean

From: Claudiu Manoil <[email protected]>

Within the LS1028A SoC, the register map for the ENETC MDIO controller is instantiated a few times: for the central (external) MDIO controller, for the internal bus of each standalone ENETC port, and for the internal bus of the Felix switch.

Refactoring is needed to support multiple MDIO buses from multiple drivers. The enetc_hw structure is made an opaque type and a smaller enetc_mdio_priv is created.

'mdio_base' - MDIO registers base address - is being parameterized, to be able to work with different MDIO register bases.

Some includes get cleaned up in the process.

---
 drivers/net/ethernet/freescale/enetc/enetc_hw.h    |  1 +
 drivers/net/ethernet/freescale/enetc/enetc_mdio.c  | 78 ++++++++++++++--------
 drivers/net/ethernet/freescale/enetc/enetc_mdio.h  | 12 ----
 .../net/ethernet/freescale/enetc/enetc_pci_mdio.c  | 43 +++++++-----
 include/linux/fsl/enetc_mdio.h                     | 34 ++++++++++
 5 files changed, 113 insertions(+), 55 deletions(-)
 delete mode 100644 drivers/net/ethernet/freescale/enetc/enetc_mdio.h
 create mode 100644 include/linux/fsl/enetc_mdio.h
drivers/net/ethernet/freescale/enetc/enetc_hw.h +1 -0
index 51f543ef37a8..7df4482af1b7 100644
@@ -200,6 +200,7 @@ enum enetc_bdr_type {TX, RX};
 #define ENETC_PFPMR		0x1900
 #define ENETC_PFPMR_PMACE	BIT(1)
 #define ENETC_PFPMR_MWLM	BIT(0)
+#define ENETC_EMDIO_BASE	0x1c00
 #define ENETC_PSIUMHFR0(n, err)	(((err) ? 0x1d08 : 0x1d00) + (n) * 0x10)
 #define ENETC_PSIUMHFR1(n)	(0x1d04 + (n) * 0x10)
 #define ENETC_PSIMMHFR0(n, err)	(((err) ? 0x1d00 : 0x1d08) + (n) * 0x10)
drivers/net/ethernet/freescale/enetc/enetc_mdio.c +52 -26

179 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc_mdio.h deleted +0 -12
deleted file mode 100644
index 60c9a3889824..000000000000
@@ -1,12 +0,0 @@
-/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
-/* Copyright 2019 NXP */
-
-#include <linux/phy.h>
-#include "enetc_pf.h"
-
-struct enetc_mdio_priv {
-	struct enetc_hw *hw;
-};
-
-int enetc_mdio_write(struct mii_bus *bus, int phy_id, int regnum, u16 value);
-int enetc_mdio_read(struct mii_bus *bus, int phy_id, int regnum);
drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c +26 -17

88 lines not on this page · raw message

include/linux/fsl/enetc_mdio.h new file +34 -0
new file mode 100644
index 000000000000..8a1127b79243
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
+/* Copyright 2019 NXP */
+
+#include <linux/phy.h>
+
+/* PCS registers */
+#define ENETC_PCS_LINK_TIMER1			0x12
+#define ENETC_PCS_LINK_TIMER1_VAL		0x06a0
+#define ENETC_PCS_LINK_TIMER2			0x13
+#define ENETC_PCS_LINK_TIMER2_VAL		0x0003
+#define ENETC_PCS_IF_MODE			0x14
+#define ENETC_PCS_IF_MODE_SGMII_EN		BIT(0)
+#define ENETC_PCS_IF_MODE_USE_SGMII_AN		BIT(1)
+#define ENETC_PCS_IF_MODE_SGMII_SPEED(x)	(((x) << 2) & GENMASK(3, 2))
+
+/* Not a mistake, the SerDes PLL needs to be set at 3.125 GHz by Reset
+ * Configuration Word (RCW, outside Linux control) for 2.5G SGMII mode. The PCS
+ * still thinks it's at gigabit.
+ */
+enum enetc_pcs_speed {
+	ENETC_PCS_SPEED_10	= 0,
+	ENETC_PCS_SPEED_100	= 1,
+	ENETC_PCS_SPEED_1000	= 2,
+	ENETC_PCS_SPEED_2500	= 2,
+};
+
+struct enetc_mdio_priv {
+	struct enetc_hw *hw;
+	int mdio_base;
+};
+
+int enetc_mdio_write(struct mii_bus *bus, int phy_id, int regnum, u16 value);
+int enetc_mdio_read(struct mii_bus *bus, int phy_id, int regnum);
+struct enetc_hw *enetc_hw_alloc(struct device *dev, void __iomem *port_regs);
Signature · 1 line
2.7.4
#8 lore raw

Re: [RFC PATCH v2 4/8] enetc: Make MDIO accessors more generic and export to include/linux/fsl

Quoted 7 lines · Vladimir Oltean

From: Claudiu Manoil <[email protected]>

Within the LS1028A SoC, the register map for the ENETC MDIO controller is instantiated a few times: for the central (external) MDIO controller, for the internal bus of each standalone ENETC port, and for the internal bus of the Felix switch.

Quoted 6 lines

Refactoring is needed to support multiple MDIO buses from multiple drivers. The enetc_hw structure is made an opaque type and a smaller enetc_mdio_priv is created.

'mdio_base' - MDIO registers base address - is being parameterized, to be able to work with different MDIO register bases.

I'm getting these on a W=1 C=1 allmodconfig build:

WARNING: drivers/net/ethernet/freescale/enetc/fsl-enetc-mdio: 'enetc_mdio_write' exported twice. Previous export was in drivers/net/ethernet/freescale/enetc/fsl-enetc.ko
WARNING: drivers/net/ethernet/freescale/enetc/fsl-enetc-mdio: 'enetc_mdio_read' exported twice. Previous export was in drivers/net/ethernet/freescale/enetc/fsl-enetc.ko
WARNING: drivers/net/ethernet/freescale/enetc/fsl-enetc-mdio: 'enetc_hw_alloc' exported twice. Previous export was in drivers/net/ethernet/freescale/enetc/fsl-enetc.ko

drivers/net/ethernet/freescale/enetc/enetc_mdio.c line 20

Quoted 9 lines
drivers/net/ethernet/freescale/enetc/enetc_mdio.c +4 -5
-#define enetc_mdio_rd(hw, off) \
-	enetc_port_rd(hw, ENETC_##off + ENETC_MDIO_REG_OFFSET)
-#define enetc_mdio_wr(hw, off, val) \
-	enetc_port_wr(hw, ENETC_##off + ENETC_MDIO_REG_OFFSET, val)
-#define enetc_mdio_rd_reg(off)	enetc_mdio_rd(hw, off)
+static inline u32 _enetc_mdio_rd(struct enetc_mdio_priv *mdio_priv, int off)
+{
+	return enetc_port_rd(mdio_priv->hw, mdio_priv->mdio_base + off);
+}

Please no static inline in source files. Compiler will know to inline this.

author maintainer
#9 lore raw

RFC PATCH v2 5/8 enetc: Set MDIO_CFG_HOLD to the recommended value of 2

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

This increases the MDIO hold time to 5 enet_clk cycles from the previous value of 0. This is actually the out-of-reset value, that the driver was previously overwriting with 0. Zero worked for the external MDIO, but breaks communication with the internal MDIO buses on which the PCS of ENETC SI's and Felix switch are found.

---
 drivers/net/ethernet/freescale/enetc/enetc_mdio.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_mdio.c +8 -4
index 6f6e31492b1c..ebe4b635421f 100644
@@ -31,15 +31,19 @@ static inline void _enetc_mdio_wr(struct enetc_mdio_priv *mdio_priv, int off,
 	_enetc_mdio_wr(mdio_priv, ENETC_##off, val)
 #define enetc_mdio_rd_reg(off)	enetc_mdio_rd(mdio_priv, off)
 
-#define ENETC_MDC_DIV		258
-
 #define MDIO_CFG_CLKDIV(x)	((((x) >> 1) & 0xff) << 8)
 #define MDIO_CFG_BSY		BIT(0)
 #define MDIO_CFG_RD_ER		BIT(1)
+#define MDIO_CFG_HOLD(x)	(((x) << 2) & GENMASK(4, 2))
 #define MDIO_CFG_ENC45		BIT(6)
  /* external MDIO only - driven on neg MDC edge */
 #define MDIO_CFG_NEG		BIT(23)
 
+#define ENETC_EMDIO_CFG \
+	(MDIO_CFG_HOLD(2) | \
+	 MDIO_CFG_CLKDIV(258) | \
+	 MDIO_CFG_NEG)
+
 #define MDIO_CTL_DEV_ADDR(x)	((x) & 0x1f)
 #define MDIO_CTL_PORT_ADDR(x)	(((x) & 0x1f) << 5)
 #define MDIO_CTL_READ		BIT(15)
@@ -61,7 +65,7 @@ int enetc_mdio_write(struct mii_bus *bus, int phy_id, int regnum, u16 value)
 	u16 dev_addr;
 	int ret;
 
-	mdio_cfg = MDIO_CFG_CLKDIV(ENETC_MDC_DIV) | MDIO_CFG_NEG;
+	mdio_cfg = ENETC_EMDIO_CFG;
 	if (regnum & MII_ADDR_C45) {
 		dev_addr = (regnum >> 16) & 0x1f;
 		mdio_cfg |= MDIO_CFG_ENC45;
@@ -108,7 +112,7 @@ int enetc_mdio_read(struct mii_bus *bus, int phy_id, int regnum)
 	u16 dev_addr, value;
 	int ret;
 
-	mdio_cfg = MDIO_CFG_CLKDIV(ENETC_MDC_DIV) | MDIO_CFG_NEG;
+	mdio_cfg = ENETC_EMDIO_CFG;
 	if (regnum & MII_ADDR_C45) {
 		dev_addr = (regnum >> 16) & 0x1f;
 		mdio_cfg |= MDIO_CFG_ENC45;
Signature · 1 line
2.7.4
author maintainer
#10 lore raw

RFC PATCH v2 6/8 net: mscc: ocelot: make phy_mode a member of the common struct ocelot_port

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

The Ocelot switchdev driver and the Felix DSA one need it for different reasons. Felix (or at least the VSC9959 instantiation in NXP LS1028A) is integrated with the traditional NXP Layerscape PCS design which does not support runtime configuration of SerDes protocol. So it needs to pre-validate the phy-mode from the device tree and prevent PHYLINK from attempting to change it. For this, it needs to cache it in a private variable.

---
 drivers/net/ethernet/mscc/ocelot.c       | 7 ++++---
 drivers/net/ethernet/mscc/ocelot.h       | 1 -
 drivers/net/ethernet/mscc/ocelot_board.c | 4 ++--
 include/soc/mscc/ocelot.h                | 2 ++
 4 files changed, 8 insertions(+), 6 deletions(-)
drivers/net/ethernet/mscc/ocelot.c +4 -3
index 985b46d7e3d1..86d543ab1ab9 100644
@@ -500,13 +500,14 @@ EXPORT_SYMBOL(ocelot_port_enable);
 static int ocelot_port_open(struct net_device *dev)
 {
 	struct ocelot_port_private *priv = netdev_priv(dev);
-	struct ocelot *ocelot = priv->port.ocelot;
+	struct ocelot_port *ocelot_port = &priv->port;
+	struct ocelot *ocelot = ocelot_port->ocelot;
 	int port = priv->chip_port;
 	int err;
 
 	if (priv->serdes) {
 		err = phy_set_mode_ext(priv->serdes, PHY_MODE_ETHERNET,
-				       priv->phy_mode);
+				       ocelot_port->phy_mode);
 		if (err) {
 			netdev_err(dev, "Could not set mode of SerDes\n");
 			return err;
@@ -514,7 +515,7 @@ static int ocelot_port_open(struct net_device *dev)
 	}
 
 	err = phy_connect_direct(dev, priv->phy, &ocelot_port_adjust_link,
-				 priv->phy_mode);
+				 ocelot_port->phy_mode);
 	if (err) {
 		netdev_err(dev, "Could not attach to PHY\n");
 		return err;
drivers/net/ethernet/mscc/ocelot.h +0 -1
index c259114c48fd..7b77d44ed7cf 100644
@@ -68,7 +68,6 @@ struct ocelot_port_private {
 
 	u8 vlan_aware;
 
-	phy_interface_t phy_mode;
 	struct phy *serdes;
 
 	struct ocelot_port_tc tc;
drivers/net/ethernet/mscc/ocelot_board.c +2 -2
index 2da8eee27e98..b38820849faa 100644
@@ -402,9 +402,9 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
 
 		of_get_phy_mode(portnp, &phy_mode);
 
-		priv->phy_mode = phy_mode;
+		ocelot_port->phy_mode = phy_mode;
 
-		switch (priv->phy_mode) {
+		switch (ocelot_port->phy_mode) {
 		case PHY_INTERFACE_MODE_NA:
 			continue;
 		case PHY_INTERFACE_MODE_SGMII:
include/soc/mscc/ocelot.h +2 -0
index 64cbbbe74a36..068f96b1a83e 100644
@@ -420,6 +420,8 @@ struct ocelot_port {
 	u8				ptp_cmd;
 	struct sk_buff_head		tx_skbs;
 	u8				ts_id;
+
+	phy_interface_t			phy_mode;
 };
 
 struct ocelot {
Signature · 1 line
2.7.4
author maintainer
#11 lore raw

RFC PATCH v2 7/8 net: mscc: ocelot: export ANA, DEV and QSYS registers to include/soc/mscc

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

Since the Felix DSA driver is implementing its own PHYLINK instance due to SoC differences, it needs access to the few registers that are common, mainly for flow control.

---
 drivers/net/ethernet/mscc/ocelot.h      |   6 +-
 drivers/net/ethernet/mscc/ocelot_ana.h  | 625 --------------------------------
 drivers/net/ethernet/mscc/ocelot_dev.h  | 275 --------------
 drivers/net/ethernet/mscc/ocelot_qsys.h | 270 --------------
 include/soc/mscc/ocelot_ana.h           | 625 ++++++++++++++++++++++++++++++++
 include/soc/mscc/ocelot_dev.h           | 275 ++++++++++++++
 include/soc/mscc/ocelot_qsys.h          | 270 ++++++++++++++
 7 files changed, 1173 insertions(+), 1173 deletions(-)
 delete mode 100644 drivers/net/ethernet/mscc/ocelot_ana.h
 delete mode 100644 drivers/net/ethernet/mscc/ocelot_dev.h
 delete mode 100644 drivers/net/ethernet/mscc/ocelot_qsys.h
 create mode 100644 include/soc/mscc/ocelot_ana.h
 create mode 100644 include/soc/mscc/ocelot_dev.h
 create mode 100644 include/soc/mscc/ocelot_qsys.h
drivers/net/ethernet/mscc/ocelot.h +3 -3
index 7b77d44ed7cf..04372ba72fec 100644
@@ -18,11 +18,11 @@
 #include <linux/ptp_clock_kernel.h>
 #include <linux/regmap.h>
 
+#include <soc/mscc/ocelot_qsys.h>
 #include <soc/mscc/ocelot_sys.h>
+#include <soc/mscc/ocelot_dev.h>
+#include <soc/mscc/ocelot_ana.h>
 #include <soc/mscc/ocelot.h>
-#include "ocelot_ana.h"
-#include "ocelot_dev.h"
-#include "ocelot_qsys.h"
 #include "ocelot_rew.h"
 #include "ocelot_qs.h"
 #include "ocelot_tc.h"
drivers/net/ethernet/mscc/ocelot_ana.h deleted +0 -625

625 lines not on this page · raw message

drivers/net/ethernet/mscc/ocelot_dev.h deleted +0 -275

275 lines not on this page · raw message

drivers/net/ethernet/mscc/ocelot_qsys.h deleted +0 -270

270 lines not on this page · raw message

include/soc/mscc/ocelot_ana.h new file +625 -0

625 lines not on this page · raw message

include/soc/mscc/ocelot_dev.h new file +275 -0

275 lines not on this page · raw message

include/soc/mscc/ocelot_qsys.h new file +270 -0

270 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#12 lore raw

RFC PATCH v2 8/8 net: dsa: felix: Add PCS operations for PHYLINK

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

Layerscape SoCs traditionally expose the SerDes configuration/status for Ethernet protocols (PCS for SGMII/XFI/USXGMII etc etc) in a register format that is compatible with clause 22 or clause 45 (depending on SerDes protocol). Each MAC has its own internal MDIO bus on which there is one or more of these PCS's, responding to commands at a configurable PHY address. The per-port internal MDIO bus (which is just for PCSs) is totally separate and has nothing to do with the dedicated external MDIO controller (which is just for PHYs), but the register map for the MDIO controller is the same.

The VSC9959 (Felix) switch instantiated in the LS1028A is integrated in hardware with the ENETC PCS of its DSA master, and reuses its MDIO controller driver, so Felix has been made to depend on it in Kconfig.

+------------------------------------------------------------------------+
|                   +--------+ GMII (typically disabled via RCW)         |
| ENETC PCI         |  ENETC |--------------------------+                |
| Root Complex      | port 3 |-----------------------+  |                |
| Integrated        +--------+                       |  |                |
| Endpoint                                           |  |                |
|                   +--------+ 2.5G GMII             |  |                |
|                   |  ENETC |--------------+        |  |                |
|                   | port 2 |-----------+  |        |  |                |
|                   +--------+           |  |        |  |                |
|                                     +--------+  +--------+             |
|                                     |  Felix |  |  Felix |             |
|                                     | port 4 |  | port 5 |             |
|                                     +--------+  +--------+             |
|                                                                        |
| +--------+  +--------+  +--------+  +--------+  +--------+  +--------+ |
| |  ENETC |  |  ENETC |  |  Felix |  |  Felix |  |  Felix |  |  Felix | |
| | port 0 |  | port 1 |  | port 0 |  | port 1 |  | port 2 |  | port 3 | |
+------------------------------------------------------------------------+
|    ||||  SerDes |          ||||        ||||        ||||        ||||    |
| +--------+block |       +--------------------------------------------+ |
| |  ENETC |      |       |       ENETC port 2 internal MDIO bus       | |
| | port 0 |      |       |  PCS         PCS          PCS        PCS   | |
| |   PCS  |      |       |   0           1            2          3    | |
+-----------------|------------------------------------------------------+
       v          v           v           v            v          v
    SGMII/      RGMII    QSGMII/QSXGMII/4xSGMII/4x100Base-X/4x2500Base-X
   USXGMII/   (bypasses
 1000Base-X/   SerDes)

2500Base-X

In the LS1028A SoC described above, the VSC9959 Felix switch is PF5 of the ENETC root complex, and has 2 BARs:
- BAR 4: the switch's effective registers
- BAR 0: the MDIO controller register map lended from ENETC port 2 (PF2), for accessing its associated PCS's.

This explanation is necessary because the patch does some renaming "pci_bar" -> "switch_pci_bar" for clarity, which would otherwise appear a bit obtuse.

The fact that the internal MDIO bus is "borrowed" is relevant because the register map is found in PF5 (the switch) but it triggers an access fault if PF2 (the ENETC DSA master) is not enabled. This is not treated in any way (and I don't think it can be treated).

All of this is so SoC-specific, that it was contained as much as possible in the platform-integration file felix_vsc9959.c.

We need to parse and pre-validate the device tree because of 2 reasons:
- The PHY mode (SerDes protocol) cannot change at runtime due to SoC design.
- There is a circular dependency in that we need to know what clause the PCS speaks in order to find it on the internal MDIO bus. But the clause of the PCS depends on what phy-mode it is configured for.

The goal of this patch is to make steps towards removing the bootloader dependency for SGMII PCS pre-configuration, as well as to add support for monitoring the in-band SGMII AN between the PCS and the system-side link partner (PHY or other MAC).

In practice the bootloader dependency is not completely removed. U-Boot pre-programs the PHY address at which each PCS can be found on the internal MDIO bus (MDEV_PORT). This is needed because the PCS of each port has the same out-of-reset PHY address of zero. The SerDes register for changing MDEV_PORT is pretty deep in the SoC (outside the addresses of the ENETC PCI BARs) and therefore inaccessible to us from here.

Felix VSC9959 and Ocelot VSC7514 are integrated very differently in their respective SoCs, and for that reason Felix does not use the Ocelot core library for PHYLINK. On one hand we don't want to impose the fixed phy-mode limitation to Ocelot, and on the other hand Felix doesn't need to force the MAC link speed the way Ocelot does, since the MAC is connected to the PCS through a fixed GMII, and the PCS is the one who does the rate adaptation at lower link speeds, which the MAC does not even need to know about. In fact changing the GMII speed for Felix irrecoverably breaks transmission through that port until a reset.

Yet another reason for wanting to convert Felix to PHYLINK is to configure the MAC of port 5 (the one that is typically disabled, in the setup with ENETC 2 as DSA master it doesn't support tagging so when it's enabled it is a regular fixed-link slave port, something that DSA PHYLIB doesn't control with .adjust_link).

---
 drivers/net/dsa/ocelot/Kconfig         |   1 +
 drivers/net/dsa/ocelot/felix.c         | 260 ++++++++++++++++--
 drivers/net/dsa/ocelot/felix.h         |  16 +-
 drivers/net/dsa/ocelot/felix_vsc9959.c | 475 ++++++++++++++++++++++++++++++++-
 4 files changed, 735 insertions(+), 17 deletions(-)
drivers/net/dsa/ocelot/Kconfig +1 -0
index 0031ca814346..03794d2a7fd5 100644
@@ -4,6 +4,7 @@ config NET_DSA_MSCC_FELIX
 	depends on NET_DSA && PCI
 	select MSCC_OCELOT_SWITCH
 	select NET_DSA_TAG_OCELOT
+	select FSL_ENETC_MDIO
 	help
 	  This driver supports the VSC9959 network switch, which is a member of
 	  the Vitesse / Microsemi / Microchip Ocelot family of switching cores.
drivers/net/dsa/ocelot/felix.c +245 -15

349 lines not on this page · raw message

drivers/net/dsa/ocelot/felix.h +15 -1
index 204296e51d0c..3a7580015b62 100644
@@ -10,6 +10,7 @@
 struct felix_info {
 	struct resource			*target_io_res;
 	struct resource			*port_io_res;
+	struct resource			*imdio_res;
 	const struct reg_field		*regfields;
 	const u32 *const		*map;
 	const struct ocelot_ops		*ops;
@@ -17,7 +18,18 @@ struct felix_info {
 	const struct ocelot_stat_layout	*stats_layout;
 	unsigned int			num_stats;
 	int				num_ports;
-	int				pci_bar;
+	int				switch_pci_bar;
+	int				imdio_pci_bar;
+	int	(*mdio_bus_alloc)(struct ocelot *ocelot);
+	void	(*mdio_bus_free)(struct ocelot *ocelot);
+	void	(*pcs_init)(struct ocelot *ocelot, int port,
+			    unsigned int link_an_mode,
+			    const struct phylink_link_state *state);
+	void	(*pcs_an_restart)(struct ocelot *ocelot, int port);
+	void	(*pcs_link_state)(struct ocelot *ocelot, int port,
+				  struct phylink_link_state *state);
+	int	(*prevalidate_phy_mode)(struct ocelot *ocelot, int port,
+					phy_interface_t phy_mode);
 };
 
 extern struct felix_info		felix_info_vsc9959;
@@ -32,6 +44,8 @@ struct felix {
 	struct pci_dev			*pdev;
 	struct felix_info		*info;
 	struct ocelot			ocelot;
+	struct mii_bus			*imdio;
+	struct phy_device		**pcs;
 };
 
 #endif
drivers/net/dsa/ocelot/felix_vsc9959.c +474 -1

510 lines not on this page · raw message

Signature · 1 line
2.7.4
#13 lore raw
In reply to Vladimir Oltean
Quoted 17 lines · Vladimir Oltean

The SerDes protocol which the driver calls 2500Base-X mode (a misnomer) is more interesting. There is a description of how it works and what can be done with it in patch 8/8 (in a comment above vsc9959_pcs_init_2500basex). In short, it is a fixed speed protocol with no auto-negotiation whatsoever. From my research of the SGMII-2500 patent [1], it has nothing to do with SGMII-2500. That one:
* does not define any change to the AN base page compared to plain 10/100/1000 SGMII. This implies that the 2500 speed is not negotiable, but the other speeds are. In our case, when the SerDes is configured for this protocol it's configured for good, there's no going back to SGMII.
* runs at a higher base frequency than regular SGMII. So SGMII-2500 operating at 1000 Mbps wouldn't interoperate with plain SGMII at 1000 Mbps. Strange, but ok..
* Emulates lower link speeds than 2500 by duplicating the codewords twice, then thrice, then twice again etc (2.5/25/250 times on average). The Layerscape PCS doesn't do that (it is fixed at 2500 Mbaud).

Quoted 2 lines

But on the other hand it isn't Base-X either, since it doesn't do 802.3z / clause 37 auto negotiation (flow control, local/remote fault etc).

Most documentation I've seen for these 2.5Gbps modes from a few vendors suggests that every vendor has its own ideas.

With Marvell, for example, whether the gigabit MAC is operating at 1G or 2.5G is controlled by the serdes "comphy" block, and from what I can tell merely increases the clocking rate by 2.5x when 2.5G mode is selected.

I suspect all the features of conventional 1G mode are also available when running at this higher speed, but many don't make sense. For example, if the MAC (there's no distinction of the PCS there) was configured for 100Mbps, but the comphy was configured for 2.5G, we'd end up with 250Mbps by 10x replication on the link. This has never been tested though.

Whether in-band AN is enabled or not is separately configurable, although the Marvell Armada 370 documentation states that when the port is configured for 1000Base-X, in-band AN must be enabled. I suspect the same is stated for later devices. However, practical testing seems to suggest that it will work without in-band AN enabled if the other side doesn't want in-band AN.

Quoted 4 lines

So it is a protocol in its own right (a rather fixed one). If reviewers think it should have its own phy-mode, different than 2500base-x, I'm in favor of that. It's just that I couldn't find a suitable name for it. quarter-xaui? 3125mhz-8b10b?

I think just call it 2500base-x without in-band negotiation.

Quoted 9 lines

When inter-operating with the Aquantia AQR112 and AQR412 PHYs in this mode (for which the PHY uses a proprietary name "OCSGMII"), we do still need to support the lower link speeds negotiated by the PHY on copper side. So what we typically do is we enable rate adaptation in the PHY firmware, with pause frames and a fixed link speed on the system side. Raising this as a discussion item to understand how we can model this quirky operating mode in Linux without imposing limitations on others (we have some downstream patches on the Aquantia PHY driver as well).

Quoted 6 lines

Another item to discuss is whether we should be able to disable AN in the PCS independently of whether we have a PHY as a peer or not. With an SGMII PHY-less connection, there may be no auto-negotiation master so the link partners will bounce for a while and then they'll settle on 10 Mbps as link speed. For those connections (such as an SGMII link to a downstream switch) we need to disable AN in the PCS and force the speed to 1000.

With Marvell, there's the in-band AN enable bit, but there's also an in-band AN bypass bit, which allows the in-band AN to time out when the 16-bit configuration word is not received after a certain period of time after the link has been established.

As for disabling AN... see below.

Quoted 7 lines

So:
* If we have a PHY we want to do auto-neg
* If we don't have a PHY, maybe we want AN, maybe we don't
* In the 2500Base-X mode, we can't do AN because the hardware doesn't support it

I have found the 'managed = "in-band-status"' DTS binding to somewhat address this concern, but I am a bit reluctant to disable SGMII AN if it isn't set.

I believe the in-band-status thing came from mvneta prior to phylink. mvneta supports operating in SGMII with no in-band AN, and the default setup that the driver adopted in SGMII mode was without in-band AN enabled. When in-band AN was required, that's when this DT property came about.

mvneta was the basis for phylink creation (as it was the first platform I had that we needed to support SFPs). Compatibility with mvneta had to be maintained to avoid regressions, so that got built-in to phylink.

When we are not operating in in-band AN mode, then yes, we do disable in-band AN at the MAC for mvneta and mvpp2. What others do, I haven't delved into. However, it is important - I have a SFP that uses a Broadcom PHY that does not provide any in-band AN when in SGMII mode. It is SGMII mode, because it supports the symbol replication for 100 and 10Mbps - but Broadcom's expectation is that the MAC is forced to the appropriate speed after reading the PHY registers.

I think the reason it does this is because it's a NBASE-T PHY, and you have to read the PHY registers to know what protocol its using on the serdes lane, which could be one of 10GBASE-R, 5000BASE-X, 2500BASE-X or SGMII at 1G, 100M or 10M depending on the copper side negotiation results.

This works with mvneta and mvpp2 since, when operating in fixed or phy mode in phylink, we disable in-band AN and force the MAC settings.

Keeping this consistent across drivers (where possible) would be my preference to avoid different behaviours and surprises.

Quoted 7 lines

We have boards with device trees that need to be migrated from PHYLIB and I am concerned that changing the behavior w.r.t. in-band AN (when the "in-band-status" property is not present) is not going to be pleasant. I do understand that the "in-band-status" property is primarily intended to be used with PHY-less setups, and it looks like the fact it does work with PHYs as well is more of an oversight (as patch 2/8 shows). So I'm not sure who else really uses it with a phy-handle.

That partly depends on the PHY. Given what I've said above, some PHYs require in-band AN to complete before they will pass data, other MACs will not establish a link if in-band AN is enabled but there is no in-band control word, even if the bypass bit is enabled.

Using in-band AN with a PHY results in faster link establishment, and also has the advantage that when the link goes down, the MAC responds a lot quicker than the 1sec phylib poll to stop transmitting.

I tend to run my boards with in-band AN enabled even for on-board PHYs although I've not pushed those patches upstream. Most PHYs on these boards come up with in-band AN bypass enabled, so it doesn't matter whether in-band AN is enabled or disabled.

Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
author maintainer
#14 lore raw

Hi Russell,

Quoted 44 lines · Russell King - ARM Linux admin
Quoted 17 lines · Vladimir Oltean

The SerDes protocol which the driver calls 2500Base-X mode (a misnomer) is more interesting. There is a description of how it works and what can be done with it in patch 8/8 (in a comment above vsc9959_pcs_init_2500basex). In short, it is a fixed speed protocol with no auto-negotiation whatsoever. From my research of the SGMII-2500 patent [1], it has nothing to do with SGMII-2500. That one:
* does not define any change to the AN base page compared to plain 10/100/1000 SGMII. This implies that the 2500 speed is not negotiable, but the other speeds are. In our case, when the SerDes is configured for this protocol it's configured for good, there's no going back to SGMII.
* runs at a higher base frequency than regular SGMII. So SGMII-2500 operating at 1000 Mbps wouldn't interoperate with plain SGMII at 1000 Mbps. Strange, but ok..
* Emulates lower link speeds than 2500 by duplicating the codewords twice, then thrice, then twice again etc (2.5/25/250 times on average). The Layerscape PCS doesn't do that (it is fixed at 2500 Mbaud).

Quoted 2 lines

But on the other hand it isn't Base-X either, since it doesn't do 802.3z / clause 37 auto negotiation (flow control, local/remote fault etc).

Most documentation I've seen for these 2.5Gbps modes from a few vendors suggests that every vendor has its own ideas.

With Marvell, for example, whether the gigabit MAC is operating at 1G or 2.5G is controlled by the serdes "comphy" block, and from what I can tell merely increases the clocking rate by 2.5x when 2.5G mode is selected.

I suspect all the features of conventional 1G mode are also available when running at this higher speed, but many don't make sense. For example, if the MAC (there's no distinction of the PCS there) was configured for 100Mbps, but the comphy was configured for 2.5G, we'd end up with 250Mbps by 10x replication on the link. This has never been tested though.

Whether in-band AN is enabled or not is separately configurable, although the Marvell Armada 370 documentation states that when the port is configured for 1000Base-X, in-band AN must be enabled. I suspect the same is stated for later devices. However, practical testing seems to suggest that it will work without in-band AN enabled if the other side doesn't want in-band AN.

Quoted 7 lines
Quoted 4 lines

So it is a protocol in its own right (a rather fixed one). If reviewers think it should have its own phy-mode, different than 2500base-x, I'm in favor of that. It's just that I couldn't find a suitable name for it. quarter-xaui? 3125mhz-8b10b?

I think just call it 2500base-x without in-band negotiation.

Ok, I already have the check in vsc9959_pcs_init_2500basex for link_an_mode == MLO_AN_INBAND, so I guess that should be fine.

Quoted 70 lines
Quoted 9 lines

When inter-operating with the Aquantia AQR112 and AQR412 PHYs in this mode (for which the PHY uses a proprietary name "OCSGMII"), we do still need to support the lower link speeds negotiated by the PHY on copper side. So what we typically do is we enable rate adaptation in the PHY firmware, with pause frames and a fixed link speed on the system side. Raising this as a discussion item to understand how we can model this quirky operating mode in Linux without imposing limitations on others (we have some downstream patches on the Aquantia PHY driver as well).

Quoted 6 lines

Another item to discuss is whether we should be able to disable AN in the PCS independently of whether we have a PHY as a peer or not. With an SGMII PHY-less connection, there may be no auto-negotiation master so the link partners will bounce for a while and then they'll settle on 10 Mbps as link speed. For those connections (such as an SGMII link to a downstream switch) we need to disable AN in the PCS and force the speed to 1000.

With Marvell, there's the in-band AN enable bit, but there's also an in-band AN bypass bit, which allows the in-band AN to time out when the 16-bit configuration word is not received after a certain period of time after the link has been established.

As for disabling AN... see below.

Quoted 7 lines

So:
* If we have a PHY we want to do auto-neg
* If we don't have a PHY, maybe we want AN, maybe we don't
* In the 2500Base-X mode, we can't do AN because the hardware doesn't support it

I have found the 'managed = "in-band-status"' DTS binding to somewhat address this concern, but I am a bit reluctant to disable SGMII AN if it isn't set.

I believe the in-band-status thing came from mvneta prior to phylink. mvneta supports operating in SGMII with no in-band AN, and the default setup that the driver adopted in SGMII mode was without in-band AN enabled. When in-band AN was required, that's when this DT property came about.

mvneta was the basis for phylink creation (as it was the first platform I had that we needed to support SFPs). Compatibility with mvneta had to be maintained to avoid regressions, so that got built-in to phylink.

When we are not operating in in-band AN mode, then yes, we do disable in-band AN at the MAC for mvneta and mvpp2. What others do, I haven't delved into. However, it is important - I have a SFP that uses a Broadcom PHY that does not provide any in-band AN when in SGMII mode. It is SGMII mode, because it supports the symbol replication for 100 and 10Mbps - but Broadcom's expectation is that the MAC is forced to the appropriate speed after reading the PHY registers.

I think the reason it does this is because it's a NBASE-T PHY, and you have to read the PHY registers to know what protocol its using on the serdes lane, which could be one of 10GBASE-R, 5000BASE-X, 2500BASE-X or SGMII at 1G, 100M or 10M depending on the copper side negotiation results.

This works with mvneta and mvpp2 since, when operating in fixed or phy mode in phylink, we disable in-band AN and force the MAC settings.

Keeping this consistent across drivers (where possible) would be my preference to avoid different behaviours and surprises.

Quoted 7 lines

We have boards with device trees that need to be migrated from PHYLIB and I am concerned that changing the behavior w.r.t. in-band AN (when the "in-band-status" property is not present) is not going to be pleasant. I do understand that the "in-band-status" property is primarily intended to be used with PHY-less setups, and it looks like the fact it does work with PHYs as well is more of an oversight (as patch 2/8 shows). So I'm not sure who else really uses it with a phy-handle.

Quoted 5 lines

That partly depends on the PHY. Given what I've said above, some PHYs require in-band AN to complete before they will pass data, other MACs will not establish a link if in-band AN is enabled but there is no in-band control word, even if the bypass bit is enabled.

I think the Layerscape PCS falls to 10 Mbps if AN is enabled but no config word is received. At least that's how it behaves when it is put in loopback mode. Naturally traffic doesn't pass through the PHY if that has negotiated a gigabit link on copper side.

Quoted 9 lines

Using in-band AN with a PHY results in faster link establishment, and also has the advantage that when the link goes down, the MAC responds a lot quicker than the 1sec phylib poll to stop transmitting.

I tend to run my boards with in-band AN enabled even for on-board PHYs although I've not pushed those patches upstream. Most PHYs on these boards come up with in-band AN bypass enabled, so it doesn't matter whether in-band AN is enabled or disabled.

Ok, makes some sense. We discussed a little bit internally and the conclusion, as Alex put it, is that it takes two to AN.
Perhaps I would be more confident about this if the PHY driver had awareness of the PHYLINK link_an_mode, in order to coordinate its settings with what the PCS expects, and vice-versa.
On the LS1028A-RDB board we have 2 issues related to SGMII AN at the moment:

- The at803x.c driver explicitly checks for the ACK from the MAC PCS, and prints "SGMII link is not ok" otherwise, and refuses to bring the link up. This hurts us in 4.19 because I think the check is a bit misplaced in the .aneg_done callback. To be precise, what we observe is that this function is not called by the state machine a second, third time etc to recheck if the AN has completed in the meantime. In current net-next, as far as I could figure out, at803x_aneg_done is dead code. What is ironic about the commit f62265b53ef3 ("at803x:
double check SGMII side autoneg") that introduced this function is that it's for the gianfar driver (Freescale eTSEC), a MAC that has never supported reprogramming itself based on the in-band config word. In fact, if you look at gfar_configure_serdes, it even configures its register 0x4 with an advertisement for 1000Base-X, not SGMII (0x4001). So I really wonder if there is any real purpose to this check in at803x_aneg_done, and if not, I would respectfully remove it.

- The vsc8514 PHY driver configures SerDes AN in U-Boot, but not in Linux. So we observe that if we disable PHY configuration in U-Boot, in-band AN breaks in Linux. We are actually wondering how we should fix this: from what you wrote above, it seems ok to hardcode SGMII AN in the PHY driver, and just ignore it in the PCS if managed = "in-band-status" is not set with PHYLINK. But as you said, in the general case maybe not all PHYs work until they haven't received the ACK from the MAC PCS, which makes this insufficient as a general solution.

But the 2 cases above illustrate the lack of consistency among PHY drivers w.r.t. in-band aneg.

Quoted 4 lines

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up

Thanks,
-Vladimir

#15 lore raw
Quoted 7 lines · Vladimir Oltean

- The at803x.c driver explicitly checks for the ACK from the MAC PCS, and prints "SGMII link is not ok" otherwise, and refuses to bring the link up. This hurts us in 4.19 because I think the check is a bit misplaced in the .aneg_done callback. To be precise, what we observe is that this function is not called by the state machine a second, third time etc to recheck if the AN has completed in the meantime. In current net-next, as far as I could figure out, at803x_aneg_done is

Quoted 8 lines

dead code. What is ironic about the commit f62265b53ef3 ("at803x:
double check SGMII side autoneg") that introduced this function is that it's for the gianfar driver (Freescale eTSEC), a MAC that has never supported reprogramming itself based on the in-band config word. In fact, if you look at gfar_configure_serdes, it even configures its register 0x4 with an advertisement for 1000Base-X, not SGMII (0x4001). So I really wonder if there is any real purpose to this check in at803x_aneg_done, and if not, I would respectfully remove it.

Please check whether at803x will pass data if the SGMII config exchange has not completed - I'm aware of some PHYs that, although link comes up on the copper side, if AN does not complete on the SGMII side, they will not pass data, even if the MAC side is forced up.

I don't see any configuration bits in the 8031 that suggest the SGMII config exchange can be bypassed.

Quoted 10 lines

- The vsc8514 PHY driver configures SerDes AN in U-Boot, but not in Linux. So we observe that if we disable PHY configuration in U-Boot, in-band AN breaks in Linux. We are actually wondering how we should fix this: from what you wrote above, it seems ok to hardcode SGMII AN in the PHY driver, and just ignore it in the PCS if managed = "in-band-status" is not set with PHYLINK. But as you said, in the general case maybe not all PHYs work until they haven't received the ACK from the MAC PCS, which makes this insufficient as a general solution.

Quoted 2 lines

But the 2 cases above illustrate the lack of consistency among PHY drivers w.r.t. in-band aneg.

Indeed - it's something of a mine field at the moment, because we aren't quite sure whether "SGMII" means that the PHY requires in-band AN or doesn't provide it. For the Broadcom case I mentioned, when it's used on a SFP, I've had to add a quirk to phylink to work around it.

The problem is, it's not a case that the MAC can demand that the PHY provides in-band config - some PHYs are incapable of doing so. Whatever solution we come up with needs to be a "negotiation" between the PHY driver and the MAC driver for it to work well in the known scenarios - like the case with the Broadcom PHY on a SFP that can be plugged into any SFP supporting network interface...

Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
#16 lore raw
Quoted 43 lines · Russell King - ARM Linux admin
Quoted 7 lines · Vladimir Oltean

- The at803x.c driver explicitly checks for the ACK from the MAC PCS, and prints "SGMII link is not ok" otherwise, and refuses to bring the link up. This hurts us in 4.19 because I think the check is a bit misplaced in the .aneg_done callback. To be precise, what we observe is that this function is not called by the state machine a second, third time etc to recheck if the AN has completed in the meantime. In current net-next, as far as I could figure out, at803x_aneg_done is

Quoted 8 lines

dead code. What is ironic about the commit f62265b53ef3 ("at803x:
double check SGMII side autoneg") that introduced this function is that it's for the gianfar driver (Freescale eTSEC), a MAC that has never supported reprogramming itself based on the in-band config word. In fact, if you look at gfar_configure_serdes, it even configures its register 0x4 with an advertisement for 1000Base-X, not SGMII (0x4001). So I really wonder if there is any real purpose to this check in at803x_aneg_done, and if not, I would respectfully remove it.

Please check whether at803x will pass data if the SGMII config exchange has not completed - I'm aware of some PHYs that, although link comes up on the copper side, if AN does not complete on the SGMII side, they will not pass data, even if the MAC side is forced up.

I don't see any configuration bits in the 8031 that suggest the SGMII config exchange can be bypassed.

Quoted 10 lines

- The vsc8514 PHY driver configures SerDes AN in U-Boot, but not in Linux. So we observe that if we disable PHY configuration in U-Boot, in-band AN breaks in Linux. We are actually wondering how we should fix this: from what you wrote above, it seems ok to hardcode SGMII AN in the PHY driver, and just ignore it in the PCS if managed = "in-band-status" is not set with PHYLINK. But as you said, in the general case maybe not all PHYs work until they haven't received the ACK from the MAC PCS, which makes this insufficient as a general solution.

Quoted 2 lines

But the 2 cases above illustrate the lack of consistency among PHY drivers w.r.t. in-band aneg.

Indeed - it's something of a mine field at the moment, because we aren't quite sure whether "SGMII" means that the PHY requires in-band AN or doesn't provide it. For the Broadcom case I mentioned, when it's used on a SFP, I've had to add a quirk to phylink to work around it.

Quoted 6 lines

The problem is, it's not a case that the MAC can demand that the PHY provides in-band config - some PHYs are incapable of doing so. Whatever solution we come up with needs to be a "negotiation" between the PHY driver and the MAC driver for it to work well in the known scenarios - like the case with the Broadcom PHY on a SFP that can be plugged into any SFP supporting network interface...

Some sort of capability negotiation does seem to be the proper solution. We can have a new capabilities field in phydev for system interface capabilities and match that with MAC capabilities, configuration, factor in the quirks. The result would tell if a solution is possible, especially with quirky PHYs, and if PHY drivers need to enable AN.

Until we have that in place, any recommended approach for PHY drivers, is it acceptable to hardcode system side AN on as a short term fix? I've just tested VSC8514 and it doesn't allow traffic through if SI AN is enabled but does not complete. We do use it with AN on on NXP systems, and it only works because U-Boot sets things up that way, but relying on U-Boot isn't great.
Aquantia PHYs we use also require AN to complete if enabled. For them Linux depends on U-Boot or on PHY firmware to enable AN. I don't know if anyone out there uses these PHYs with AN off. Would a patch that hardcodes AN on for any of these PHYs be acceptable?

Thanks!
Alex

#17 lore raw
Quoted 57 lines · Alexandru Marginean
Quoted 43 lines · Russell King - ARM Linux admin
Quoted 7 lines · Vladimir Oltean

- The at803x.c driver explicitly checks for the ACK from the MAC PCS, and prints "SGMII link is not ok" otherwise, and refuses to bring the link up. This hurts us in 4.19 because I think the check is a bit misplaced in the .aneg_done callback. To be precise, what we observe is that this function is not called by the state machine a second, third time etc to recheck if the AN has completed in the meantime. In current net-next, as far as I could figure out, at803x_aneg_done is

Quoted 8 lines

dead code. What is ironic about the commit f62265b53ef3 ("at803x:
double check SGMII side autoneg") that introduced this function is that it's for the gianfar driver (Freescale eTSEC), a MAC that has never supported reprogramming itself based on the in-band config word. In fact, if you look at gfar_configure_serdes, it even configures its register 0x4 with an advertisement for 1000Base-X, not SGMII (0x4001). So I really wonder if there is any real purpose to this check in at803x_aneg_done, and if not, I would respectfully remove it.

Please check whether at803x will pass data if the SGMII config exchange has not completed - I'm aware of some PHYs that, although link comes up on the copper side, if AN does not complete on the SGMII side, they will not pass data, even if the MAC side is forced up.

I don't see any configuration bits in the 8031 that suggest the SGMII config exchange can be bypassed.

Quoted 10 lines

- The vsc8514 PHY driver configures SerDes AN in U-Boot, but not in Linux. So we observe that if we disable PHY configuration in U-Boot, in-band AN breaks in Linux. We are actually wondering how we should fix this: from what you wrote above, it seems ok to hardcode SGMII AN in the PHY driver, and just ignore it in the PCS if managed = "in-band-status" is not set with PHYLINK. But as you said, in the general case maybe not all PHYs work until they haven't received the ACK from the MAC PCS, which makes this insufficient as a general solution.

Quoted 2 lines

But the 2 cases above illustrate the lack of consistency among PHY drivers w.r.t. in-band aneg.

Indeed - it's something of a mine field at the moment, because we aren't quite sure whether "SGMII" means that the PHY requires in-band AN or doesn't provide it. For the Broadcom case I mentioned, when it's used on a SFP, I've had to add a quirk to phylink to work around it.

Quoted 6 lines

The problem is, it's not a case that the MAC can demand that the PHY provides in-band config - some PHYs are incapable of doing so. Whatever solution we come up with needs to be a "negotiation" between the PHY driver and the MAC driver for it to work well in the known scenarios - like the case with the Broadcom PHY on a SFP that can be plugged into any SFP supporting network interface...

Some sort of capability negotiation does seem to be the proper solution. We can have a new capabilities field in phydev for system interface capabilities and match that with MAC capabilities, configuration, factor in the quirks. The result would tell if a solution is possible, especially with quirky PHYs, and if PHY drivers need to enable AN.

Quoted 10 lines

Until we have that in place, any recommended approach for PHY drivers, is it acceptable to hardcode system side AN on as a short term fix? I've just tested VSC8514 and it doesn't allow traffic through if SI AN is enabled but does not complete. We do use it with AN on on NXP systems, and it only works because U-Boot sets things up that way, but relying on U-Boot isn't great.
Aquantia PHYs we use also require AN to complete if enabled. For them Linux depends on U-Boot or on PHY firmware to enable AN. I don't know if anyone out there uses these PHYs with AN off. Would a patch that hardcodes AN on for any of these PHYs be acceptable?

I'm not sure why you're talking about hard-coding anything. As I've already mentioned, phylink allows you to specify today whether you want to use in-band AN or not, provided the MAC implements it as is done with mvneta and mvpp2.

Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
#18 lore raw
Quoted 69 lines · Russell King - ARM Linux admin
Quoted 57 lines · Alexandru Marginean
Quoted 43 lines · Russell King - ARM Linux admin
Quoted 7 lines · Vladimir Oltean

- The at803x.c driver explicitly checks for the ACK from the MAC PCS, and prints "SGMII link is not ok" otherwise, and refuses to bring the link up. This hurts us in 4.19 because I think the check is a bit misplaced in the .aneg_done callback. To be precise, what we observe is that this function is not called by the state machine a second, third time etc to recheck if the AN has completed in the meantime. In current net-next, as far as I could figure out, at803x_aneg_done is

Quoted 8 lines

dead code. What is ironic about the commit f62265b53ef3 ("at803x:
double check SGMII side autoneg") that introduced this function is that it's for the gianfar driver (Freescale eTSEC), a MAC that has never supported reprogramming itself based on the in-band config word. In fact, if you look at gfar_configure_serdes, it even configures its register 0x4 with an advertisement for 1000Base-X, not SGMII (0x4001). So I really wonder if there is any real purpose to this check in at803x_aneg_done, and if not, I would respectfully remove it.

Please check whether at803x will pass data if the SGMII config exchange has not completed - I'm aware of some PHYs that, although link comes up on the copper side, if AN does not complete on the SGMII side, they will not pass data, even if the MAC side is forced up.

I don't see any configuration bits in the 8031 that suggest the SGMII config exchange can be bypassed.

Quoted 10 lines

- The vsc8514 PHY driver configures SerDes AN in U-Boot, but not in Linux. So we observe that if we disable PHY configuration in U-Boot, in-band AN breaks in Linux. We are actually wondering how we should fix this: from what you wrote above, it seems ok to hardcode SGMII AN in the PHY driver, and just ignore it in the PCS if managed = "in-band-status" is not set with PHYLINK. But as you said, in the general case maybe not all PHYs work until they haven't received the ACK from the MAC PCS, which makes this insufficient as a general solution.

Quoted 2 lines

But the 2 cases above illustrate the lack of consistency among PHY drivers w.r.t. in-band aneg.

Indeed - it's something of a mine field at the moment, because we aren't quite sure whether "SGMII" means that the PHY requires in-band AN or doesn't provide it. For the Broadcom case I mentioned, when it's used on a SFP, I've had to add a quirk to phylink to work around it.

Quoted 6 lines

The problem is, it's not a case that the MAC can demand that the PHY provides in-band config - some PHYs are incapable of doing so. Whatever solution we come up with needs to be a "negotiation" between the PHY driver and the MAC driver for it to work well in the known scenarios - like the case with the Broadcom PHY on a SFP that can be plugged into any SFP supporting network interface...

Some sort of capability negotiation does seem to be the proper solution. We can have a new capabilities field in phydev for system interface capabilities and match that with MAC capabilities, configuration, factor in the quirks. The result would tell if a solution is possible, especially with quirky PHYs, and if PHY drivers need to enable AN.

Quoted 10 lines

Until we have that in place, any recommended approach for PHY drivers, is it acceptable to hardcode system side AN on as a short term fix? I've just tested VSC8514 and it doesn't allow traffic through if SI AN is enabled but does not complete. We do use it with AN on on NXP systems, and it only works because U-Boot sets things up that way, but relying on U-Boot isn't great.
Aquantia PHYs we use also require AN to complete if enabled. For them Linux depends on U-Boot or on PHY firmware to enable AN. I don't know if anyone out there uses these PHYs with AN off. Would a patch that hardcodes AN on for any of these PHYs be acceptable?

Quoted 4 lines

I'm not sure why you're talking about hard-coding anything. As I've already mentioned, phylink allows you to specify today whether you want to use in-band AN or not, provided the MAC implements it as is done with mvneta and mvpp2.

I was asking about PHY drivers, not MAC, in the meantime I noticed phy_device carries a pointer to phylink. I assume it's OK if PHY drivers check link_an_mode and set up PHY system interface based on it.

Thanks!
Alex

#19 lore raw
Quoted 70 lines · Alexandru Marginean
Quoted 69 lines · Russell King - ARM Linux admin
Quoted 67 lines · Alexandru Marginean
Quoted 43 lines · Russell King - ARM Linux admin
Quoted 7 lines · Vladimir Oltean

- The at803x.c driver explicitly checks for the ACK from the MAC PCS, and prints "SGMII link is not ok" otherwise, and refuses to bring the link up. This hurts us in 4.19 because I think the check is a bit misplaced in the .aneg_done callback. To be precise, what we observe is that this function is not called by the state machine a second, third time etc to recheck if the AN has completed in the meantime. In current net-next, as far as I could figure out, at803x_aneg_done is

Quoted 8 lines

dead code. What is ironic about the commit f62265b53ef3 ("at803x:
double check SGMII side autoneg") that introduced this function is that it's for the gianfar driver (Freescale eTSEC), a MAC that has never supported reprogramming itself based on the in-band config word. In fact, if you look at gfar_configure_serdes, it even configures its register 0x4 with an advertisement for 1000Base-X, not SGMII (0x4001). So I really wonder if there is any real purpose to this check in at803x_aneg_done, and if not, I would respectfully remove it.

Please check whether at803x will pass data if the SGMII config exchange has not completed - I'm aware of some PHYs that, although link comes up on the copper side, if AN does not complete on the SGMII side, they will not pass data, even if the MAC side is forced up.

I don't see any configuration bits in the 8031 that suggest the SGMII config exchange can be bypassed.

Quoted 10 lines

- The vsc8514 PHY driver configures SerDes AN in U-Boot, but not in Linux. So we observe that if we disable PHY configuration in U-Boot, in-band AN breaks in Linux. We are actually wondering how we should fix this: from what you wrote above, it seems ok to hardcode SGMII AN in the PHY driver, and just ignore it in the PCS if managed = "in-band-status" is not set with PHYLINK. But as you said, in the general case maybe not all PHYs work until they haven't received the ACK from the MAC PCS, which makes this insufficient as a general solution.

Quoted 2 lines

But the 2 cases above illustrate the lack of consistency among PHY drivers w.r.t. in-band aneg.

Indeed - it's something of a mine field at the moment, because we aren't quite sure whether "SGMII" means that the PHY requires in-band AN or doesn't provide it. For the Broadcom case I mentioned, when it's used on a SFP, I've had to add a quirk to phylink to work around it.

Quoted 6 lines

The problem is, it's not a case that the MAC can demand that the PHY provides in-band config - some PHYs are incapable of doing so. Whatever solution we come up with needs to be a "negotiation" between the PHY driver and the MAC driver for it to work well in the known scenarios - like the case with the Broadcom PHY on a SFP that can be plugged into any SFP supporting network interface...

Some sort of capability negotiation does seem to be the proper solution. We can have a new capabilities field in phydev for system interface capabilities and match that with MAC capabilities, configuration, factor in the quirks. The result would tell if a solution is possible, especially with quirky PHYs, and if PHY drivers need to enable AN.

Until we have that in place, any recommended approach for PHY drivers, is it acceptable to hardcode system side AN on as a short term fix? I've just tested VSC8514 and it doesn't allow traffic through if SI AN is enabled but does not complete. We do use it with AN on on NXP systems, and it only works because U-Boot sets things up that way, but relying on U-Boot isn't great.
Aquantia PHYs we use also require AN to complete if enabled. For them Linux depends on U-Boot or on PHY firmware to enable AN. I don't know if anyone out there uses these PHYs with AN off. Would a patch that hardcodes AN on for any of these PHYs be acceptable?

Quoted 8 lines
Quoted 4 lines

I'm not sure why you're talking about hard-coding anything. As I've already mentioned, phylink allows you to specify today whether you want to use in-band AN or not, provided the MAC implements it as is done with mvneta and mvpp2.

I was asking about PHY drivers, not MAC, in the meantime I noticed phy_device carries a pointer to phylink. I assume it's OK if PHY drivers check link_an_mode and set up PHY system interface based on it.

Definitely not on several counts:

1. it's an opaque structure to everything but phylink itself (you may notice that it's defined in phylink.c, and that is why - it is unsafe to go poking about in it.) Lessons should've been learnt from phylib allowing MAC drivers to go poking about in phylib internal state (which I hear phylib maintainers regret allowing.) This is an intentional design choice on my part to ensure that we do not fall into the same trap.

2. phylink really needs to know what the PHY properties are before the driver goes poking about in phylink - the current phylink state at a particular point in time may not be the operating state ultimately chosen for the PHY.

3. phylib may not be used with phylink, and we need phylib to continue to work in phylink-less systems.

(2) is the killer, because it's useless trying to look at the phylink state when the PHY is "attached" (and hence config_init is called.)

To see why we need PHY property information earlier, look at phylink.c in net-next, specifically:

1. phylink_bringup_phy(), where we have a special case for Clause 45 PHYs that switch their interface modes.

2. phylink_phy_no_inband() and phylink_sfp_connect_phy() which special-cases the Broadcom PHY that provides no in-band AN. That is particularly relevant to my point (2) above.

3. phylink_sfp_connect_phy() needing to know the capabilities of the PHY before the PHY driver has been attached, so that we can select a particular interface mode that is suitable for the PHY to co-operate with the MAC.

Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
#20 lore raw
Quoted 95 lines · Russell King - ARM Linux admin
Quoted 70 lines · Alexandru Marginean
Quoted 69 lines · Russell King - ARM Linux admin
Quoted 67 lines · Alexandru Marginean
Quoted 43 lines · Russell King - ARM Linux admin
Quoted 7 lines · Vladimir Oltean

- The at803x.c driver explicitly checks for the ACK from the MAC PCS, and prints "SGMII link is not ok" otherwise, and refuses to bring the link up. This hurts us in 4.19 because I think the check is a bit misplaced in the .aneg_done callback. To be precise, what we observe is that this function is not called by the state machine a second, third time etc to recheck if the AN has completed in the meantime. In current net-next, as far as I could figure out, at803x_aneg_done is

Quoted 8 lines

dead code. What is ironic about the commit f62265b53ef3 ("at803x:
double check SGMII side autoneg") that introduced this function is that it's for the gianfar driver (Freescale eTSEC), a MAC that has never supported reprogramming itself based on the in-band config word. In fact, if you look at gfar_configure_serdes, it even configures its register 0x4 with an advertisement for 1000Base-X, not SGMII (0x4001). So I really wonder if there is any real purpose to this check in at803x_aneg_done, and if not, I would respectfully remove it.

Please check whether at803x will pass data if the SGMII config exchange has not completed - I'm aware of some PHYs that, although link comes up on the copper side, if AN does not complete on the SGMII side, they will not pass data, even if the MAC side is forced up.

I don't see any configuration bits in the 8031 that suggest the SGMII config exchange can be bypassed.

Quoted 10 lines

- The vsc8514 PHY driver configures SerDes AN in U-Boot, but not in Linux. So we observe that if we disable PHY configuration in U-Boot, in-band AN breaks in Linux. We are actually wondering how we should fix this: from what you wrote above, it seems ok to hardcode SGMII AN in the PHY driver, and just ignore it in the PCS if managed = "in-band-status" is not set with PHYLINK. But as you said, in the general case maybe not all PHYs work until they haven't received the ACK from the MAC PCS, which makes this insufficient as a general solution.

Quoted 2 lines

But the 2 cases above illustrate the lack of consistency among PHY drivers w.r.t. in-band aneg.

Indeed - it's something of a mine field at the moment, because we aren't quite sure whether "SGMII" means that the PHY requires in-band AN or doesn't provide it. For the Broadcom case I mentioned, when it's used on a SFP, I've had to add a quirk to phylink to work around it.

Quoted 6 lines

The problem is, it's not a case that the MAC can demand that the PHY provides in-band config - some PHYs are incapable of doing so. Whatever solution we come up with needs to be a "negotiation" between the PHY driver and the MAC driver for it to work well in the known scenarios - like the case with the Broadcom PHY on a SFP that can be plugged into any SFP supporting network interface...

Some sort of capability negotiation does seem to be the proper solution. We can have a new capabilities field in phydev for system interface capabilities and match that with MAC capabilities, configuration, factor in the quirks. The result would tell if a solution is possible, especially with quirky PHYs, and if PHY drivers need to enable AN.

Until we have that in place, any recommended approach for PHY drivers, is it acceptable to hardcode system side AN on as a short term fix? I've just tested VSC8514 and it doesn't allow traffic through if SI AN is enabled but does not complete. We do use it with AN on on NXP systems, and it only works because U-Boot sets things up that way, but relying on U-Boot isn't great.
Aquantia PHYs we use also require AN to complete if enabled. For them Linux depends on U-Boot or on PHY firmware to enable AN. I don't know if anyone out there uses these PHYs with AN off. Would a patch that hardcodes AN on for any of these PHYs be acceptable?

Quoted 8 lines
Quoted 4 lines

I'm not sure why you're talking about hard-coding anything. As I've already mentioned, phylink allows you to specify today whether you want to use in-band AN or not, provided the MAC implements it as is done with mvneta and mvpp2.

I was asking about PHY drivers, not MAC, in the meantime I noticed phy_device carries a pointer to phylink. I assume it's OK if PHY drivers check link_an_mode and set up PHY system interface based on it.

Definitely not on several counts:

1. it's an opaque structure to everything but phylink itself (you may notice that it's defined in phylink.c, and that is why - it is unsafe to go poking about in it.) Lessons should've been learnt from phylib allowing MAC drivers to go poking about in phylib internal state (which I hear phylib maintainers regret allowing.) This is an intentional design choice on my part to ensure that we do not fall into the same trap.

2. phylink really needs to know what the PHY properties are before the driver goes poking about in phylink - the current phylink state at a particular point in time may not be the operating state ultimately chosen for the PHY.

Quoted 5 lines

3. phylib may not be used with phylink, and we need phylib to continue to work in phylink-less systems.

(2) is the killer, because it's useless trying to look at the phylink state when the PHY is "attached" (and hence config_init is called.)

My bad, I just assumed without checking that phylink is more like phylib than it actually is. (3) is probably less of a problem, phy drivers could check if phylink pointers is NULL, but it doesn't matter anyway, since the phylink structure is opaque.

Quoted 6 lines

To see why we need PHY property information earlier, look at phylink.c in net-next, specifically:

1. phylink_bringup_phy(), where we have a special case for Clause 45 PHYs that switch their interface modes.

Quoted 9 lines

2. phylink_phy_no_inband() and phylink_sfp_connect_phy() which special-cases the Broadcom PHY that provides no in-band AN. That is particularly relevant to my point (2) above.

3. phylink_sfp_connect_phy() needing to know the capabilities of the PHY before the PHY driver has been attached, so that we can select a particular interface mode that is suitable for the PHY to co-operate with the MAC.

This is all fair and I'm not arguing against a proper solution that involves a capability exchange between PHY and MAC.

Until we have that in place, or if phylib is used, PHY drivers should probably apply a recommended configuration in config_init based on information available to them at that time. For phy-mode = "sgmii" or "qsgmii" I think PHY drivers should enable AN on system side by default if that's an option in the PHY hardware. Currently some seem to do it, other don't. In that context vsc8514 config_init could hardcode enabling of AN, phy-mode wouldn't even matter as the PHY only supports qsgmii.

This kind of change does not address the overall problem but at least makes PHYs more uniform and predictable.

In the proper solution phylink could later determine what the PHY configuration should be based on MAC capabilities and configuration and re-apply it using a new op, potentially turning off system side AN in vsc8514 case. Does this look reasonable?

Thanks!
Alex