Skip to contentSkip to conversation

Convert Felix DSA switch to PHYLINK

PATCH In review Vladimir Oltean 4 participants 17 messages Jan 6, 2020 – Jan 8, 2020

Subsystems (9)
lore
Share & tools
lore

Vladimir Oltean

author maintainer
#0 lore raw

v5 cover Convert Felix DSA switch to PHYLINK

From: Vladimir Oltean <[email protected]>

Unlike most other conversions, this one is not by far a trivial one, and should be seen as "Layerscape PCS meets PHYLINK". 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.
Our issues start when the PCS stops from "just working", and that is where PHYLINK comes in handy.

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 9/9 (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 completely compatible with Base-X either, since it doesn't do 802.3z / clause 37 auto negotiation (flow control, local/remote fault etc). It is compatible with 2500Base-X without in-band AN, and that is exactly how we decided to expose it (this is actually similar to what others do).

For SGMII and USXGMII, the driver is using the PHYLINK 'managed = "in-band-status"' DTS binding to figure out whether in-band AN is expected to be enabled in the PCS or not. It is expected that the attached PHY follows suite, but there is a gap here: the PHY driver does not react to this setting, so only one of "AN on" and "AN off" works on any particular PHY, even though that PHY might support bypassing the SGMII AN process, as is the case on the VSC8514 PHY present on the LS1028A-RDB board. A separate series will be sent to propose a way to deal with that.

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.

Changes in v5:

- Added the register write to DEV_CLOCK_CFG back in felix_phylink_mac_config in patch 9/9.

Changes in v4:

- This is mostly a resend of v3, with the only notable change that I've dropped the PHY core patches for in_band_autoneg and I'll propose them independently.

v1 series:
https://www.spinics.net/lists/netdev/msg613869.html

RFC v2 series:
https://www.spinics.net/lists/netdev/msg620128.html

v3 series:
https://www.spinics.net/lists/netdev/msg622060.html

v4 series:
https://www.spinics.net/lists/netdev/msg622606.html

[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 (8):
mii: Add helpers for parsing SGMII auto-negotiation
net: phylink: make QSGMII a valid PHY mode for in-band AN
net: phylink: add support for polling MAC PCS
net: dsa: Pass pcs_poll flag from driver to PHYLINK
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

 Documentation/networking/sfp-phylink.rst      |   3 +-
 drivers/net/dsa/ocelot/Kconfig                |   2 +
 drivers/net/dsa/ocelot/felix.c                | 265 ++++++++-
 drivers/net/dsa/ocelot/felix.h                |  16 +-
 drivers/net/dsa/ocelot/felix_vsc9959.c        | 501 +++++++++++++++++-
 drivers/net/ethernet/freescale/enetc/Kconfig  |   1 +
 drivers/net/ethernet/freescale/enetc/Makefile |   2 +-
 .../net/ethernet/freescale/enetc/enetc_hw.h   |   1 +
 .../net/ethernet/freescale/enetc/enetc_mdio.c | 120 ++---
 .../net/ethernet/freescale/enetc/enetc_mdio.h |  12 -
 .../ethernet/freescale/enetc/enetc_pci_mdio.c |  43 +-
 .../net/ethernet/freescale/enetc/enetc_pf.c   |  47 ++
 .../net/ethernet/freescale/enetc/enetc_pf.h   |   4 -
 drivers/net/ethernet/mscc/ocelot.c            |   7 +-
 drivers/net/ethernet/mscc/ocelot.h            |   7 +-
 drivers/net/ethernet/mscc/ocelot_board.c      |   4 +-
 drivers/net/phy/phylink.c                     |   4 +-
 include/linux/fsl/enetc_mdio.h                |  55 ++
 include/linux/mii.h                           |  50 ++
 include/linux/phylink.h                       |   2 +
 include/net/dsa.h                             |   5 +
 include/soc/mscc/ocelot.h                     |   2 +
 .../soc}/mscc/ocelot_ana.h                    |   0
 .../soc}/mscc/ocelot_dev.h                    |   0
 .../soc}/mscc/ocelot_qsys.h                   |   0
 include/uapi/linux/mii.h                      |  12 +
 net/dsa/port.c                                |   1 +
 27 files changed, 1036 insertions(+), 130 deletions(-)
 delete mode 100644 drivers/net/ethernet/freescale/enetc/enetc_mdio.h
 create mode 100644 include/linux/fsl/enetc_mdio.h
 rename {drivers/net/ethernet => include/soc}/mscc/ocelot_ana.h (100%)
 rename {drivers/net/ethernet => include/soc}/mscc/ocelot_dev.h (100%)
 rename {drivers/net/ethernet => include/soc}/mscc/ocelot_qsys.h (100%)
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH v5 1/9 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.

---
Changes in v5:
- None.

Changes in v4:
- None.

Changes in v3:
- Moved the LPA_* and ADVERTISE_* bits for SGMII to a separate group of defines.

 include/linux/mii.h      | 50 ++++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/mii.h | 12 ++++++++++
 2 files changed, 62 insertions(+)
include/linux/mii.h +50 -0
index 4ce8901a1af6..18c6208f56fc 100644
@@ -372,6 +372,56 @@ static inline u32 mii_lpa_to_ethtool_lpa_x(u32 lpa)
 	return result | mii_adv_to_ethtool_adv_x(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.
include/uapi/linux/mii.h +12 -0
index 51b48e4be1f2..0b9c3beda345 100644
@@ -131,6 +131,18 @@
 #define NWAYTEST_LOOPBACK	0x0100	/* Enable loopback for N-way   */
 #define NWAYTEST_RESV2		0xfe00	/* Unused...                   */
 
+/* MAC and PHY tx_config_Reg[15:0] for SGMII in-band auto-negotiation.*/
+#define ADVERTISE_SGMII		0x0001	/* MAC can do SGMII            */
+#define LPA_SGMII		0x0001	/* PHY can do SGMII            */
+#define LPA_SGMII_DPX_SPD_MASK	0x1C00	/* SGMII duplex and speed bits */
+#define LPA_SGMII_10HALF	0x0000	/* Can do 10mbps half-duplex   */
+#define LPA_SGMII_10FULL	0x1000	/* Can do 10mbps full-duplex   */
+#define LPA_SGMII_100HALF	0x0400	/* Can do 100mbps half-duplex  */
+#define LPA_SGMII_100FULL	0x1400	/* Can do 100mbps full-duplex  */
+#define LPA_SGMII_1000HALF	0x0800	/* Can do 1000mbps half-duplex */
+#define LPA_SGMII_1000FULL	0x1800	/* Can do 1000mbps full-duplex */
+#define LPA_SGMII_LINK		0x8000	/* PHY link with copper-side partner */
+
 /* 1000BASE-T Control register */
 #define ADVERTISE_1000FULL	0x0200  /* Advertise 1000BASE-T full duplex */
 #define ADVERTISE_1000HALF	0x0100  /* Advertise 1000BASE-T half duplex */
Signature · 1 line
2.17.1
author maintainer
#2 lore raw

PATCH v5 2/9 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.

---
Changes in v5:
- None.

Changes in v4:
- None.

Changes in v3:
- None.

Changes in v2:
- None.

 drivers/net/phy/phylink.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/phy/phylink.c +1 -0
index 1edca9725370..88686e0f9ae1 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.17.1
author maintainer
#3 lore raw

PATCH v5 3/9 net: phylink: add support for polling MAC PCS

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

Some MAC PCS blocks are unable to provide interrupts when their status changes. As we already have support in phylink for polling status, use this to provide a hook for MACs to enable polling mode.

The patch idea was picked up from Russell King's suggestion on the macb phylink patch thread here [0] but the implementation was changed. Instead of introducing a new phylink_start_poll() function, which would make the implementation cumbersome for common PHYLINK implementations for multiple types of devices, like DSA, just add a boolean property to the phylink_config structure, which is just as backwards-compatible.

https://lkml.org/lkml/2019/12/16/603

---
Changes in v5:
- None.

Changes in v4:
- None.

Changes in v3:
- Patch is new.

 Documentation/networking/sfp-phylink.rst | 3 ++-
 drivers/net/phy/phylink.c                | 3 ++-
 include/linux/phylink.h                  | 2 ++
 3 files changed, 6 insertions(+), 2 deletions(-)
Documentation/networking/sfp-phylink.rst +2 -1
index a5e00a159d21..d753a309f9d1 100644
@@ -251,7 +251,8 @@ this documentation.
 	phylink_mac_change(priv->phylink, link_is_up);
 
     where ``link_is_up`` is true if the link is currently up or false
-    otherwise.
+    otherwise. If a MAC is unable to provide these interrupts, then
+    it should set ``priv->phylink_config.pcs_poll = true;`` in step 9.
 
 11. Verify that the driver does not call::
 
drivers/net/phy/phylink.c +2 -1
index 88686e0f9ae1..af914a8842bd 100644
@@ -1022,7 +1022,8 @@ void phylink_start(struct phylink *pl)
 		if (irq <= 0)
 			mod_timer(&pl->link_poll, jiffies + HZ);
 	}
-	if (pl->cfg_link_an_mode == MLO_AN_FIXED && pl->get_fixed_state)
+	if ((pl->cfg_link_an_mode == MLO_AN_FIXED && pl->get_fixed_state) ||
+	    pl->config->pcs_poll)
 		mod_timer(&pl->link_poll, jiffies + HZ);
 	if (pl->phydev)
 		phy_start(pl->phydev);
include/linux/phylink.h +2 -0
index fed5488e3c75..523209e70947 100644
@@ -63,10 +63,12 @@ enum phylink_op_type {
  * struct phylink_config - PHYLINK configuration structure
  * @dev: a pointer to a struct device associated with the MAC
  * @type: operation type of PHYLINK instance
+ * @pcs_poll: MAC PCS cannot provide link change interrupt
  */
 struct phylink_config {
 	struct device *dev;
 	enum phylink_op_type type;
+	bool pcs_poll;
 };
 
 /**
Signature · 1 line
2.17.1
author maintainer
#4 lore raw

PATCH v5 4/9 net: dsa: Pass pcs_poll flag from driver to PHYLINK

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

The DSA drivers that implement .phylink_mac_link_state should normally register an interrupt for the PCS, from which they should call phylink_mac_change(). However not all switches implement this, and those who don't should set this flag in dsa_switch in the .setup callback, so that PHYLINK will poll for a few ms until the in-band AN link timer expires and the PCS state settles.

---
Changes in v5:
- None.

Changes in v4:
- None.

Changes in v3:
- Patch is new.

 include/net/dsa.h | 5 +++++
 net/dsa/port.c    | 1 +
 2 files changed, 6 insertions(+)
include/net/dsa.h +5 -0
index 23b1c58656d4..0c39fed8cd99 100644
@@ -279,6 +279,11 @@ struct dsa_switch {
 	 */
 	bool			vlan_filtering;
 
+	/* MAC PCS does not provide link state change interrupt, and requires
+	 * polling. Flag passed on to PHYLINK.
+	 */
+	bool			pcs_poll;
+
 	size_t num_ports;
 };
 
net/dsa/port.c +1 -0
index ffb5601f7ed6..774facb8d547 100644
@@ -599,6 +599,7 @@ static int dsa_port_phylink_register(struct dsa_port *dp)
 
 	dp->pl_config.dev = ds->dev;
 	dp->pl_config.type = PHYLINK_DEV;
+	dp->pl_config.pcs_poll = ds->pcs_poll;
 
 	dp->pl = phylink_create(&dp->pl_config, of_fwnode_handle(port_dn),
 				mode, &dsa_port_phylink_mac_ops);
Signature · 1 line
2.17.1
author maintainer
#5 lore raw

PATCH v5 5/9 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.

The ENETC MDIO bus operations are exported from the fsl-enetc-mdio kernel object, the same that registers the central MDIO controller (the dedicated PF). The ENETC main driver has been changed to select it, and use its exported helpers to further register its private MDIO bus. The DSA Felix driver will do the same.

---
Changes in v5:
- None.

Changes in v4:
- None.

Changes in v3:
- Removed enetc_mdio.o from fsl-enetc.o, which caused a build error in the previous series, because enetc_mdio_read and enetc_mdio_write were exported from 2 different kernel objects.
- Some associated code movement from enetc_mdio.c to enetc_pf.c

 drivers/net/ethernet/freescale/enetc/Kconfig  |   1 +
 drivers/net/ethernet/freescale/enetc/Makefile |   2 +-
 .../net/ethernet/freescale/enetc/enetc_hw.h   |   1 +
 .../net/ethernet/freescale/enetc/enetc_mdio.c | 110 +++++++-----------
 .../net/ethernet/freescale/enetc/enetc_mdio.h |  12 --
 .../ethernet/freescale/enetc/enetc_pci_mdio.c |  43 ++++---
 .../net/ethernet/freescale/enetc/enetc_pf.c   |  47 ++++++++
 .../net/ethernet/freescale/enetc/enetc_pf.h   |   4 -
 include/linux/fsl/enetc_mdio.h                |  55 +++++++++
 9 files changed, 176 insertions(+), 99 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/Kconfig +1 -0
index edad4ca46327..fe942de19597 100644
@@ -2,6 +2,7 @@
 config FSL_ENETC
 	tristate "ENETC PF driver"
 	depends on PCI && PCI_MSI && (ARCH_LAYERSCAPE || COMPILE_TEST)
+	select FSL_ENETC_MDIO
 	select PHYLIB
 	help
 	  This driver supports NXP ENETC gigabit ethernet controller PCIe
drivers/net/ethernet/freescale/enetc/Makefile +1 -1
index d0db33e5b6b7..74f7ac253b8b 100644
@@ -3,7 +3,7 @@
 common-objs := enetc.o enetc_cbdr.o enetc_ethtool.o
 
 obj-$(CONFIG_FSL_ENETC) += fsl-enetc.o
-fsl-enetc-y := enetc_pf.o enetc_mdio.o $(common-objs)
+fsl-enetc-y := enetc_pf.o $(common-objs)
 fsl-enetc-$(CONFIG_PCI_IOV) += enetc_msg.o
 fsl-enetc-$(CONFIG_FSL_ENETC_QOS) += enetc_qos.o
 
drivers/net/ethernet/freescale/enetc/enetc_hw.h +1 -0
index 8375cd886dba..62554f28ce07 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 +45 -65

208 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

drivers/net/ethernet/freescale/enetc/enetc_pf.c +47 -0

59 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc_pf.h +0 -4
index 10dd1b53bb08..59e65a6f6c3e 100644
@@ -49,7 +49,3 @@ struct enetc_pf {
 int enetc_msg_psi_init(struct enetc_pf *pf);
 void enetc_msg_psi_free(struct enetc_pf *pf);
 void enetc_msg_handle_rxmsg(struct enetc_pf *pf, int mbox_id, u16 *status);
-
-/* MDIO */
-int enetc_mdio_probe(struct enetc_pf *pf);
-void enetc_mdio_remove(struct enetc_pf *pf);
include/linux/fsl/enetc_mdio.h new file +55 -0

55 lines not on this page · raw message

Signature · 1 line
2.17.1
#6 lore raw

Re: [PATCH v5 net-next 5/9] enetc: Make MDIO accessors more generic and export to include/linux/fsl

Quoted 11 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.

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.

Quoted 8 lines

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

The ENETC MDIO bus operations are exported from the fsl-enetc-mdio kernel object, the same that registers the central MDIO controller (the dedicated PF). The ENETC main driver has been changed to select it, and use its exported helpers to further register its private MDIO bus. The DSA Felix driver will do the same.

This series has already been applied so this may be food for thought at this point, but why was not the solution to create a standalone mii_bus driver and have all consumers be pointed it?

It is not uncommon for MDIO controllers to be re-used and integrated within a larger block and when that happens whoever owns the largest address space, say the Ethernet MAC can request the large resource region and the MDIO bus controler can work on that premise, that's what we did with genet/bcmmii.c and mdio-bcm-unimac.c for instance (so we only do an ioremap, not request_mem_region + ioremap).

Your commit message does not provide a justification for why this abstraction (mii_bus) was not suitable or considered here. Do you think that could be changed?

Thanks!

Signature · 1 line
Florian
author maintainer
#7 lore raw

Re: [PATCH v5 net-next 5/9] enetc: Make MDIO accessors more generic and export to include/linux/fsl

Hi Florian,

Quoted 22 lines · Florian Fainelli
Quoted 11 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.

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.

Quoted 8 lines

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

The ENETC MDIO bus operations are exported from the fsl-enetc-mdio kernel object, the same that registers the central MDIO controller (the dedicated PF). The ENETC main driver has been changed to select it, and use its exported helpers to further register its private MDIO bus. The DSA Felix driver will do the same.

Quoted 4 lines

This series has already been applied so this may be food for thought at this point, but why was not the solution to create a standalone mii_bus driver and have all consumers be pointed it?

I have no real opinion on this.

To be honest, the reason is that the existing "culture" of Freescale MDIO drivers wasn't to put them in drivers/net/phy/mdio-*.c, and I just didn't look past the fence.

But what is the benefit? What gets passed between bcmgenet and mdio-bcm-unimac with struct bcmgenet_platform_data is equivalent with what gets passed between vsc9959 and enetc_mdio with the manual population of struct mii_bus and struct enetc_mdio_priv, no? I'm not even sure there is a net reduction in code size. And I am not really sure that I want an of_node for the MDIO bus platform device anyway. Whereas genet seems to be instantiating a port-private MDIO bus for the _real_ (but nonetheless embedded) PHY, the MDIO bus we have here is for the MAC PCS, which is more akin to the custom device tree binding "pcsphy-handle" that the DPAA1 driver is using (see arch/arm64/boot/dts/qoriq-fman3-0-10g-0.dtsi for example). So there is no requirement to run the PHY state machine on it, it's just locally driven, so I don't want to add a dependency on device tree where it's really not needed. (By the way I am further confused by the undocumented/unused "brcm,40nm-ephy" compatible string that these device tree bindings for genet have).

Quoted 7 lines

It is not uncommon for MDIO controllers to be re-used and integrated within a larger block and when that happens whoever owns the largest address space, say the Ethernet MAC can request the large resource region and the MDIO bus controler can work on that premise, that's what we did with genet/bcmmii.c and mdio-bcm-unimac.c for instance (so we only do an ioremap, not request_mem_region + ioremap).

I don't really understand this. In arch/mips/boot/dts, for all of bcm73xx and bcm74xx SoCs, you have a single Ethernet port DT node, and a single MDIO bus as a child beneath it, where is this reuse that you mention?
And because I don't really understand what you've said, my following comment maybe makes no sense, but I think what you mean by "MDIO controller reuse" is that there are multiple instantiations of the register map, but ultimately every transaction ends up on the same MDIO/MDC pair of wires and the same electrical bus.
We do have some of that with the ENETC, but not with the switch, whose internal MDIO bus has no connection to the outside world, it just holds the PCS front-ends for the SerDes.
I also don't understand the reference to request_mem_region, perhaps it would help if you could show some code.

Quoted 4 lines

Your commit message does not provide a justification for why this abstraction (mii_bus) was not suitable or considered here. Do you think that could be changed?

I'm sorry, was the mii_bus abstraction really not considered here? Based on the stuff exported in this patch, an mii_bus is exactly what I'm registering in 9/9, no?

Quoted 3 lines

Thanks!
--
Florian

Regards,
-Vladimir

#8 lore raw

Re: [PATCH v5 net-next 5/9] enetc: Make MDIO accessors more generic and export to include/linux/fsl

Quoted 36 lines · Vladimir Oltean

Hi Florian,

Quoted 22 lines · Florian Fainelli
Quoted 11 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.

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.

Quoted 8 lines

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

The ENETC MDIO bus operations are exported from the fsl-enetc-mdio kernel object, the same that registers the central MDIO controller (the dedicated PF). The ENETC main driver has been changed to select it, and use its exported helpers to further register its private MDIO bus. The DSA Felix driver will do the same.

Quoted 4 lines

This series has already been applied so this may be food for thought at this point, but why was not the solution to create a standalone mii_bus driver and have all consumers be pointed it?

I have no real opinion on this.

To be honest, the reason is that the existing "culture" of Freescale MDIO drivers wasn't to put them in drivers/net/phy/mdio-*.c, and I just didn't look past the fence.

Quoted 16 lines

But what is the benefit? What gets passed between bcmgenet and mdio-bcm-unimac with struct bcmgenet_platform_data is equivalent with what gets passed between vsc9959 and enetc_mdio with the manual population of struct mii_bus and struct enetc_mdio_priv, no? I'm not even sure there is a net reduction in code size. And I am not really sure that I want an of_node for the MDIO bus platform device anyway. Whereas genet seems to be instantiating a port-private MDIO bus for the _real_ (but nonetheless embedded) PHY, the MDIO bus we have here is for the MAC PCS, which is more akin to the custom device tree binding "pcsphy-handle" that the DPAA1 driver is using (see arch/arm64/boot/dts/qoriq-fman3-0-10g-0.dtsi for example). So there is no requirement to run the PHY state machine on it, it's just locally driven, so I don't want to add a dependency on device tree where it's really not needed. (By the way I am further confused by the undocumented/unused "brcm,40nm-ephy" compatible string that these device tree bindings for genet have).

That compatibility string should not have been defined, but the DTS were imported from our Device Tree auto-generation tool that did produce those, when my TODO list empty, I might send an update to remove those, unless someone thinks it's ABI and it would break something (which I can swear won't).

Quoted 9 lines
Quoted 8 lines

It is not uncommon for MDIO controllers to be re-used and integrated within a larger block and when that happens whoever owns the largest address space, say the Ethernet MAC can request the large resource region and the MDIO bus controler can work on that premise, that's what we did with genet/bcmmii.c and mdio-bcm-unimac.c for instance (so we only do an ioremap, not request_mem_region + ioremap).

Quoted 14 lines

I don't really understand this. In arch/mips/boot/dts, for all of bcm73xx and bcm74xx SoCs, you have a single Ethernet port DT node, and a single MDIO bus as a child beneath it, where is this reuse that you mention?
And because I don't really understand what you've said, my following comment maybe makes no sense, but I think what you mean by "MDIO controller reuse" is that there are multiple instantiations of the register map, but ultimately every transaction ends up on the same MDIO/MDC pair of wires and the same electrical bus.
We do have some of that with the ENETC, but not with the switch, whose internal MDIO bus has no connection to the outside world, it just holds the PCS front-ends for the SerDes.
I also don't understand the reference to request_mem_region, perhaps it would help if you could show some code.

What I forgot telling you about is that the same MDIO bus controller is used internally by each GENET instance to "talk" to both external and internal PHYs, but also by the bcm_sf2.c driver which is why it made sense to have a standalone MDIO bus driver that could either be instantiated on its own (as is the case with bcm_sf2) or as part of a larger block within GENET. The request_mem_region() + ioremap() comment is because you cannot have two resources that overlap be used with request_mem_region(), since the MDIO bus driver is embedded into a larger block, it simply does an ioremap. If that confused you, then you can just discard that comment, is it not particularly relevant.

Quoted 9 lines
Quoted 5 lines

Your commit message does not provide a justification for why this abstraction (mii_bus) was not suitable or considered here. Do you think that could be changed?

I'm sorry, was the mii_bus abstraction really not considered here? Based on the stuff exported in this patch, an mii_bus is exactly what I'm registering in 9/9, no?

I meat in the commit message, there is no justification why this was not considered or used, by asking you ended up providing one, that is typically what one would expect to find to explain why something was/was not considered. It's fine, the code is merge, I won't object or require you to use a mii_bus abstraction.

Signature · 1 line
Florian
author maintainer
#9 lore raw

Re: [PATCH v5 net-next 5/9] enetc: Make MDIO accessors more generic and export to include/linux/fsl

Quoted 87 lines · Florian Fainelli
Quoted 36 lines · Vladimir Oltean

Hi Florian,

Quoted 22 lines · Florian Fainelli
Quoted 11 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.

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.

Quoted 8 lines

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

The ENETC MDIO bus operations are exported from the fsl-enetc-mdio kernel object, the same that registers the central MDIO controller (the dedicated PF). The ENETC main driver has been changed to select it, and use its exported helpers to further register its private MDIO bus. The DSA Felix driver will do the same.

Quoted 4 lines

This series has already been applied so this may be food for thought at this point, but why was not the solution to create a standalone mii_bus driver and have all consumers be pointed it?

I have no real opinion on this.

To be honest, the reason is that the existing "culture" of Freescale MDIO drivers wasn't to put them in drivers/net/phy/mdio-*.c, and I just didn't look past the fence.

Quoted 16 lines

But what is the benefit? What gets passed between bcmgenet and mdio-bcm-unimac with struct bcmgenet_platform_data is equivalent with what gets passed between vsc9959 and enetc_mdio with the manual population of struct mii_bus and struct enetc_mdio_priv, no? I'm not even sure there is a net reduction in code size. And I am not really sure that I want an of_node for the MDIO bus platform device anyway. Whereas genet seems to be instantiating a port-private MDIO bus for the _real_ (but nonetheless embedded) PHY, the MDIO bus we have here is for the MAC PCS, which is more akin to the custom device tree binding "pcsphy-handle" that the DPAA1 driver is using (see arch/arm64/boot/dts/qoriq-fman3-0-10g-0.dtsi for example). So there is no requirement to run the PHY state machine on it, it's just locally driven, so I don't want to add a dependency on device tree where it's really not needed. (By the way I am further confused by the undocumented/unused "brcm,40nm-ephy" compatible string that these device tree bindings for genet have).

That compatibility string should not have been defined, but the DTS were imported from our Device Tree auto-generation tool that did produce those, when my TODO list empty, I might send an update to remove those, unless someone thinks it's ABI and it would break something (which I can swear won't).

Quoted 9 lines
Quoted 8 lines

It is not uncommon for MDIO controllers to be re-used and integrated within a larger block and when that happens whoever owns the largest address space, say the Ethernet MAC can request the large resource region and the MDIO bus controler can work on that premise, that's what we did with genet/bcmmii.c and mdio-bcm-unimac.c for instance (so we only do an ioremap, not request_mem_region + ioremap).

Quoted 14 lines

I don't really understand this. In arch/mips/boot/dts, for all of bcm73xx and bcm74xx SoCs, you have a single Ethernet port DT node, and a single MDIO bus as a child beneath it, where is this reuse that you mention?
And because I don't really understand what you've said, my following comment maybe makes no sense, but I think what you mean by "MDIO controller reuse" is that there are multiple instantiations of the register map, but ultimately every transaction ends up on the same MDIO/MDC pair of wires and the same electrical bus.
We do have some of that with the ENETC, but not with the switch, whose internal MDIO bus has no connection to the outside world, it just holds the PCS front-ends for the SerDes.
I also don't understand the reference to request_mem_region, perhaps it would help if you could show some code.

Quoted 11 lines

What I forgot telling you about is that the same MDIO bus controller is used internally by each GENET instance to "talk" to both external and internal PHYs, but also by the bcm_sf2.c driver which is why it made sense to have a standalone MDIO bus driver that could either be instantiated on its own (as is the case with bcm_sf2) or as part of a larger block within GENET. The request_mem_region() + ioremap() comment is because you cannot have two resources that overlap be used with request_mem_region(), since the MDIO bus driver is embedded into a larger block, it simply does an ioremap. If that confused you, then you can just discard that comment, is it not particularly relevant.

So we don't typically have the external MDIO controller be part of the memory map of an Ethernet port, it has its own region in the SoC. But this is not an external MDIO controller, and it's a completely separate hardware instance with its own memory region not shared with anybody else.

And I think your need for registering the slave MDIO bus in the Starfighter 2 switch driver, on top of the same memory region as the GENET's MDIO bus, is just to work around the fact that the switch pseudo-PHY MDIO address is fixed at 30 on some chips, and you need to intercept those transactions by wrapping the mii_bus->read and mii_bus->write methods of the master, otherwise none of this would have been needed.
If I understand correctly, couldn't you have just overridden the mii_bus->read and mii_bus->write ops of the master MDIO bus, without registering another one?

Quoted 10 lines
Quoted 9 lines
Quoted 5 lines

Your commit message does not provide a justification for why this abstraction (mii_bus) was not suitable or considered here. Do you think that could be changed?

I'm sorry, was the mii_bus abstraction really not considered here? Based on the stuff exported in this patch, an mii_bus is exactly what I'm registering in 9/9, no?

Quoted 5 lines

I meat in the commit message, there is no justification why this was not considered or used, by asking you ended up providing one, that is typically what one would expect to find to explain why something was/was not considered. It's fine, the code is merge, I won't object or require you to use a mii_bus abstraction.

So I answered your question? If so, it was by mistake, because I still don't exactly understand your point (although I would like to). The difference is that we don't register a new platform device for the mii_bus (we use mii_bus->dev = ocelot->dev), and that it's not in drivers/net/phy/mdio-fsl-enetc.c, although it could be, but I don't see a clear benefit.

Quoted 2 lines

--
Florian

Regards,
-Vladimir

#10 lore raw

Re: [PATCH v5 net-next 5/9] enetc: Make MDIO accessors more generic and export to include/linux/fsl

Quoted 6 lines · Vladimir Oltean

So we don't typically have the external MDIO controller be part of the memory map of an Ethernet port, it has its own region in the SoC. But this is not an external MDIO controller, and it's a completely separate hardware instance with its own memory region not shared with anybody else.

OK, I do not think I managed to express myself correctly, by external MDIO controller I meant a controller that is used to interface with off-chip (and sometimes on-chip, too) MDIO devices. That is an on-chip MDIO controller technically, pardon me for not expressing myself more clearly here.

Quoted 8 lines

And I think your need for registering the slave MDIO bus in the Starfighter 2 switch driver, on top of the same memory region as the GENET's MDIO bus, is just to work around the fact that the switch pseudo-PHY MDIO address is fixed at 30 on some chips, and you need to intercept those transactions by wrapping the mii_bus->read and mii_bus->write methods of the master, otherwise none of this would have been needed.

You are conflating two things that are not related to the point being discussed. The SF2 switch used on 7445 and 7278 has some wrapping around the Roboswitch original IP. The roboswitch has an internal MDIO controller which is managed through the register space within the switch. We added a MDIO controller to interface with both our internal Gigabit PHYs as well as external MDIO devices would such thing exist. The binding show the MDIO node as part of "switch_top" but not being part of "core":
Documentation/devicetree/bindings/net/brcm,bcm7445-switch-v4.0.txt.

The same IP used as the MDIO controller (those two 32-bit words with CFG and CMD) are the same as those that are used on GENET, hence the desire to re-use the same piece of driver.

Quoted 3 lines

If I understand correctly, couldn't you have just overridden the mii_bus->read and mii_bus->write ops of the master MDIO bus, without registering another one?

Yes maybe, I do not think this is particularly relevant to this discussion though.

Quoted 17 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

Your commit message does not provide a justification for why this abstraction (mii_bus) was not suitable or considered here. Do you think that could be changed?

I'm sorry, was the mii_bus abstraction really not considered here? Based on the stuff exported in this patch, an mii_bus is exactly what I'm registering in 9/9, no?

Quoted 5 lines

I meat in the commit message, there is no justification why this was not considered or used, by asking you ended up providing one, that is typically what one would expect to find to explain why something was/was not considered. It's fine, the code is merge, I won't object or require you to use a mii_bus abstraction.

Quoted 6 lines

So I answered your question? If so, it was by mistake, because I still don't exactly understand your point (although I would like to). The difference is that we don't register a new platform device for the mii_bus (we use mii_bus->dev = ocelot->dev), and that it's not in drivers/net/phy/mdio-fsl-enetc.c, although it could be, but I don't see a clear benefit.

To go back to the original point, I suppose the answer is no: we did not consider using a mii_bus abstraction and in hindsight, we do not see the point but it was interesting you brought that up. Case closed from my side, thank you.

Signature · 1 line
Florian
author maintainer
#11 lore raw

PATCH v5 6/9 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.

---
Changes in v5:
- None.

Changes in v4:
- None.

Changes in v3:
- None.

 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 18c68e048d43..48c32a171afa 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.17.1
author maintainer
#12 lore raw

PATCH v5 7/9 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.

---
Changes in v5:
- None.

Changes in v4:
- None.

Changes in v3:
- None.

 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.17.1
author maintainer
#13 lore raw

PATCH v5 8/9 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.

---
Changes in v5:
- None.

Changes in v4:
- None.

Changes in v3:
- None.

 drivers/net/ethernet/mscc/ocelot.h                       | 6 +++---
 {drivers/net/ethernet => include/soc}/mscc/ocelot_ana.h  | 0
 {drivers/net/ethernet => include/soc}/mscc/ocelot_dev.h  | 0
 {drivers/net/ethernet => include/soc}/mscc/ocelot_qsys.h | 0
 4 files changed, 3 insertions(+), 3 deletions(-)
 rename {drivers/net/ethernet => include/soc}/mscc/ocelot_ana.h (100%)
 rename {drivers/net/ethernet => include/soc}/mscc/ocelot_dev.h (100%)
 rename {drivers/net/ethernet => include/soc}/mscc/ocelot_qsys.h (100%)
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"
include/soc/mscc/ocelot_ana.h renamed from drivers/net/ethernet/mscc/ocelot_ana.h +0 -0
similarity index 100%
rename from drivers/net/ethernet/mscc/ocelot_ana.h
rename to include/soc/mscc/ocelot_ana.h
include/soc/mscc/ocelot_dev.h renamed from drivers/net/ethernet/mscc/ocelot_dev.h +0 -0
similarity index 100%
rename from drivers/net/ethernet/mscc/ocelot_dev.h
rename to include/soc/mscc/ocelot_dev.h
include/soc/mscc/ocelot_qsys.h renamed from drivers/net/ethernet/mscc/ocelot_qsys.h +0 -0
similarity index 100%
rename from drivers/net/ethernet/mscc/ocelot_qsys.h
rename to include/soc/mscc/ocelot_qsys.h
Signature · 1 line
2.17.1
author maintainer
#14 lore raw

PATCH v5 9/9 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/USXGMII/10GBase-R 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/4x1000Base-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.

The pair with ENETC port 3 and Felix port 5 is optional and doesn't support tagging. When we enable it, swp5 is a regular slave port, albeit an internal one. The trouble is that it doesn't work, and that is because the DSA PHYLIB adaptation layer doesn't treat fixed-link slave ports. So that is yet another reason for wanting to convert Felix to the native PHYLINK API.

---
Changes in v5:
- Turns out not all register writes were unneeded (DEV_CLOCK_CFG was, tested with traffic). Put it back, which also fixes an unused variable warning for struct ocelot_port, which had been left over after the overzealous 'cleanup' in v4.

Changes in v4:
- Some cleanup of unneeded register writes in felix_phylink_mac_config, inherited from ocelot.

Changes in v3:
- Made a few tweaks to vsc9959_pcs_init_sgmii so that it works without MLO_AN_INBAND with the VSC8514 PHY.
- Added proper dependencies on ENETC MDIO (re: "depends on NET_VENDOR_FREESCALE": yes, I know, the hardware really is a Frankenstein, can't do much about it).
- Dropped the polling from vsc9959_pcs_link_state and let PHYLINK do its timer thing.

 drivers/net/dsa/ocelot/Kconfig         |   2 +
 drivers/net/dsa/ocelot/felix.c         | 265 ++++++++++++-
 drivers/net/dsa/ocelot/felix.h         |  16 +-
 drivers/net/dsa/ocelot/felix_vsc9959.c | 501 ++++++++++++++++++++++++-
 4 files changed, 767 insertions(+), 17 deletions(-)
drivers/net/dsa/ocelot/Kconfig +2 -0
index 6f9804093150..a5b7cca03d09 100644
@@ -3,8 +3,10 @@ config NET_DSA_MSCC_FELIX
 	tristate "Ocelot / Felix Ethernet switch support"
 	depends on NET_DSA && PCI
 	depends on NET_VENDOR_MICROSEMI
+	depends on NET_VENDOR_FREESCALE
 	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 +250 -15

360 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 +500 -1

536 lines not on this page · raw message

Signature · 1 line
2.17.1
#15 lore raw

Re: [PATCH v5 net-next 9/9] net: dsa: felix: Add PCS operations for PHYLINK

Quoted 12 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

Layerscape SoCs traditionally expose the SerDes configuration/status for Ethernet protocols (PCS for SGMII/USXGMII/10GBase-R 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.

I get randconfig build failures after this patch:

drivers/net/dsa/ocelot/felix_vsc9959.o: In function `vsc9959_mdio_bus_alloc':
felix_vsc9959.c:(.text+0x19c): undefined reference to enetc_hw_alloc' felix_vsc9959.c:(.text+0x1d1): undefined reference to enetc_mdio_read' felix_vsc9959.c:(.text+0x1d8): undefined reference to `enetc_mdio_write'

I'll send a patch after a bit more testing

Arnd

maintainer
#16 lore raw
In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>
Date: Mon, 6 Jan 2020 03:34:08 +0200

Quoted 7 lines

Unlike most other conversions, this one is not by far a trivial one, and should be seen as "Layerscape PCS meets PHYLINK". 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.
Our issues start when the PCS stops from "just working", and that is where PHYLINK comes in handy.

...

Series applied, thanks Vladimir.