Skip to contentSkip to conversation

Add support for PIC64-HPSC/HX MDIO controller

PATCH Superseded Charles Perry 4 participants 12 messages Mar 31 – Apr 7

Subsystems (5)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Charles Perry

author maintainer
#0 lore raw

v3 cover Add support for PIC64-HPSC/HX MDIO controller

Hello,

This series adds a driver for the two MDIO controllers of PIC64-HPSC/HX. The hardware supports C22 and C45 but only C22 is implemented for now.

This MDIO hardware is based on a Microsemi design supported in Linux by mdio-mscc-miim.c. However, The register interface is completely different with pic64hpsc, hence the need for a separate driver.

The documentation recommends an input clock of 156.25MHz and a prescaler of 39, which yields an MDIO clock of 1.95MHz.

This was tested on Microchip HB1301 evalkit which has a VSC8574 and a VSC8541 with clock frequencies of 0.6, 1.95 and 2.5 MHz.

Thanks,
Charles

Changes in v3:
- 2/2: Add a MAINTAINERS entry (Jakub)

Changes in v2:
- 1/2: Make "clocks" and "interrupts" required (Andrew)
- 1/2: Add a default value to "clock-frequency" (Andrew)
- 2/2: Remove #define for unused registers (Maxime)
- 2/2: Add "c22" to clause 22 read/write ops (Maxime)
- 2/2: Remove the call to platform_set_drvdata() (Andrew)
- 2/2: Make the clock mandatory (Andrew)
- 2/2: Use 2.5MHz if no clock-frequency was specified (Andrew)
- 2/2: Change the error message for bad clock-frequency (Andrew)
- 2/2: Fix a use without initialization on bus_freq (Andrew)

CC Andrew Lunn <[email protected]>
CC "David S. Miller" <[email protected]>
CC Eric Dumazet <[email protected]>
CC Jakub Kicinski <[email protected]>
CC Paolo Abeni <[email protected]>
CC Rob Herring <[email protected]>
CC Krzysztof Kozlowski <[email protected]>
CC Conor Dooley <[email protected]>
CC Heiner Kallweit <[email protected]>
CC Russell King <[email protected]>

Charles Perry (2):
dt-bindings: net: document Microchip PIC64-HPSC/HX MDIO controller
net: mdio: add a driver for PIC64-HPSC/HX MDIO controller

 .../net/microchip,pic64hpsc-mdio.yaml         |  68 +++++++
 MAINTAINERS                                   |   6 +
 drivers/net/mdio/Kconfig                      |   7 +
 drivers/net/mdio/Makefile                     |   1 +
 drivers/net/mdio/mdio-pic64hpsc.c             | 192 ++++++++++++++++++
 5 files changed, 274 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/microchip,pic64hpsc-mdio.yaml
 create mode 100644 drivers/net/mdio/mdio-pic64hpsc.c
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH v3 1/2 dt-bindings: net: document Microchip PIC64-HPSC/HX MDIO controller

This MDIO hardware is based on a Microsemi design supported in Linux by mdio-mscc-miim.c. However, The register interface is completely different with pic64hpsc, hence the need for separate documentation.

The hardware supports C22 and C45.

The documentation recommends an input clock of 156.25MHz and a prescaler of 39, which yields an MDIO clock of 1.95MHz.

The hardware supports an interrupt pin to signal transaction completion which is not strictly needed as the software can also poll a "TRIGGER" bit for this.

---

Notes:
Changes in v3: none

Changes in v2:
- Make "clocks" and "interrupts" required (Andrew)
- Add a default value to "clock-frequency" (Andrew)

 .../net/microchip,pic64hpsc-mdio.yaml         | 68 +++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/microchip,pic64hpsc-mdio.yaml
Documentation/devicetree/bindings/net/microchip,pic64hpsc-mdio.yaml new file +68 -0
new file mode 100644
index 000000000000..d690afe3d3cf
@@ -0,0 +1,68 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/microchip,pic64hpsc-mdio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Microchip PIC64-HPSC/HX MDIO controller
+
+maintainers:
+  - Charles Perry <[email protected]>
+
+description: |
+  Microchip PIC64-HPSC/HX SoCs have two MDIO bus controller. This MDIO bus
+  controller supports C22 and C45 register access. It is named "MDIO Initiator"
+  in the documentation.
+
+allOf:
+  - $ref: mdio.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - const: microchip,pic64hpsc-mdio
+      - items:
+          - const: microchip,pic64hx-mdio
+          - const: microchip,pic64hpsc-mdio
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  clock-frequency:
+    default: 2500000
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - interrupts
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    bus {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        mdio@4000C21E000 {
+            compatible = "microchip,pic64hpsc-mdio";
+            reg = <0x400 0x0C21E000 0x0 0x1000>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            clocks = <&svc_clk>;
+            interrupt-parent = <&saplic0>;
+            interrupts = <168 IRQ_TYPE_LEVEL_HIGH>;
+
+            phy0: ethernet-phy@0 {
+                reg = <0>;
+            };
+        };
+    };
Signature · 1 line
2.47.3
author maintainer
#3 lore raw

PATCH v3 2/2 net: mdio: add a driver for PIC64-HPSC/HX MDIO controller

In reply to Charles Perry

This adds an MDIO driver for PIC64-HPSC/HX. The hardware supports C22 and C45 but only C22 is implemented in this commit.

This MDIO hardware is based on a Microsemi design supported in Linux by mdio-mscc-miim.c. However, The register interface is completely different with pic64hpsc, hence the need for a separate driver.

The documentation recommends an input clock of 156.25MHz and a prescaler of 39, which yields an MDIO clock of 1.95MHz.

The hardware supports an interrupt pin or a "TRIGGER" bit that can be polled to signal transaction completion. This commit uses polling.

This was tested on Microchip HB1301 evalkit with a VSC8574 and a VSC8541.

---

Notes:
Changes in v3:
- Add a MAINTAINERS entry (Jakub)

Changes in v2:
- Remove #define for unused registers (Maxime)
- Add "c22" to clause 22 read/write ops (Maxime)
- Remove the call to platform_set_drvdata() (Andrew)
- Make the clock mandatory (Andrew)
- Use 2.5MHz if no clock-frequency was specified (Andrew)
- Change the error message for bad clock-frequency (Andrew)
- Fix a use without initialization on bus_freq (Andrew)

 MAINTAINERS                       |   6 +
 drivers/net/mdio/Kconfig          |   7 ++
 drivers/net/mdio/Makefile         |   1 +
 drivers/net/mdio/mdio-pic64hpsc.c | 192 ++++++++++++++++++++++++++++++
 4 files changed, 206 insertions(+)
 create mode 100644 drivers/net/mdio/mdio-pic64hpsc.c
MAINTAINERS +6 -0
index e08767323763..9297c46dba91 100644
@@ -17216,6 +17216,12 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/tty/serial/8250/8250_pci1xxxx.c
 
+MICROCHIP PIC64-HPSC/HX DRIVERS
+M:	Charles Perry <[email protected]>
+S:	Supported
+F:	Documentation/devicetree/bindings/net/microchip,pic64hpsc-mdio.yaml
+F:	drivers/net/mdio/mdio-pic64hpsc.c
+
 MICROCHIP POLARFIRE FPGA DRIVERS
 M:	Conor Dooley <[email protected]>
 L:	[email protected]
drivers/net/mdio/Kconfig +7 -0
index 44380378911b..7bdba8c3ddef 100644
@@ -146,6 +146,13 @@ config MDIO_OCTEON
 	  buses. It is required by the Octeon and ThunderX ethernet device
 	  drivers on some systems.
 
+config MDIO_PIC64HPSC
+	tristate "PIC64-HPSC/HX MDIO interface support"
+	depends on HAS_IOMEM && OF_MDIO
+	help
+	  This driver supports the MDIO interface found on the PIC64-HPSC/HX
+	  SoCs.
+
 config MDIO_IPQ4019
 	tristate "Qualcomm IPQ4019 MDIO interface support"
 	depends on HAS_IOMEM && OF_MDIO
drivers/net/mdio/Makefile +1 -0
index fbec636700e7..048586746026 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_MDIO_MOXART)		+= mdio-moxart.o
 obj-$(CONFIG_MDIO_MSCC_MIIM)		+= mdio-mscc-miim.o
 obj-$(CONFIG_MDIO_MVUSB)		+= mdio-mvusb.o
 obj-$(CONFIG_MDIO_OCTEON)		+= mdio-octeon.o
+obj-$(CONFIG_MDIO_PIC64HPSC)		+= mdio-pic64hpsc.o
 obj-$(CONFIG_MDIO_REALTEK_RTL9300)	+= mdio-realtek-rtl9300.o
 obj-$(CONFIG_MDIO_REGMAP)		+= mdio-regmap.o
 obj-$(CONFIG_MDIO_SUN4I)		+= mdio-sun4i.o
drivers/net/mdio/mdio-pic64hpsc.c new file +192 -0

192 lines not on this page · raw message

Signature · 1 line
2.47.3
maintainer Reviewed-by on v3 2/2
#4 lore raw

Re: [PATCH net-next v3 2/2] net: mdio: add a driver for PIC64-HPSC/HX MDIO controller

Quoted 10 lines · Charles Perry

This adds an MDIO driver for PIC64-HPSC/HX. The hardware supports C22 and C45 but only C22 is implemented in this commit.

This MDIO hardware is based on a Microsemi design supported in Linux by mdio-mscc-miim.c. However, The register interface is completely different with pic64hpsc, hence the need for a separate driver.

The documentation recommends an input clock of 156.25MHz and a prescaler of 39, which yields an MDIO clock of 1.95MHz.

Quoted 8 lines

The hardware supports an interrupt pin or a "TRIGGER" bit that can be polled to signal transaction completion. This commit uses polling.

This was tested on Microchip HB1301 evalkit with a VSC8574 and a VSC8541.

Andrew

#5 lore raw

Re: [PATCH net-next v3 2/2] net: mdio: add a driver for PIC64-HPSC/HX MDIO controller

In reply to Charles Perry

drivers/net/mdio/mdio-pic64hpsc.c line 94

Quoted 9 lines · Charles Perry
drivers/net/mdio/mdio-pic64hpsc.c new file +9 -0
+	if (!(bus->phy_ignore_ta_mask & 1 << mii_id) &&
+	    !FIELD_GET(MDIO_READOK_BIT, val)) {
+		dev_dbg(&bus->dev, "READOK bit cleared\n");
+		return -EIO;
+	}
+
+	ret = FIELD_GET(MDIO_RDATA_MASK, val);
+
+	return ret;

You don't need "ret" here, this can simply be:

	return FIELD_GET(MDIO_RDATA_MASK, val);

...

drivers/net/mdio/mdio-pic64hpsc.c line 114

Quoted 5 lines
drivers/net/mdio/mdio-pic64hpsc.c new file +5 -0
+	writel(MDIO_TRIGGER_BIT | FIELD_PREP(MDIO_REG_DEV_ADDR_MASK, regnum) |
+		       FIELD_PREP(MDIO_PHY_PRT_ADDR_MASK, mii_id) |
+		       FIELD_PREP(MDIO_OPERATION_MASK, MDIO_OPERATION_WRITE) |
+		       FIELD_PREP(MDIO_START_OF_FRAME_MASK, 1),
+	       priv->regs + MDIO_REG_FRAME_CFG_2);

Shouldn't this wait for the write to complete?

Thanks.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
author maintainer
#6 lore raw

Re: [PATCH net-next v3 2/2] net: mdio: add a driver for PIC64-HPSC/HX MDIO controller

Quoted 13 lines · Russell King (Oracle)

drivers/net/mdio/mdio-pic64hpsc.c line 94

Quoted 9 lines · Charles Perry
drivers/net/mdio/mdio-pic64hpsc.c new file +9 -0
+	if (!(bus->phy_ignore_ta_mask & 1 << mii_id) &&
+	    !FIELD_GET(MDIO_READOK_BIT, val)) {
+		dev_dbg(&bus->dev, "READOK bit cleared\n");
+		return -EIO;
+	}
+
+	ret = FIELD_GET(MDIO_RDATA_MASK, val);
+
+	return ret;

You don't need "ret" here, this can simply be:

Quoted 1 line
	return FIELD_GET(MDIO_RDATA_MASK, val);

Ok

Quoted 11 lines

...

drivers/net/mdio/mdio-pic64hpsc.c line 114

Quoted 5 lines
drivers/net/mdio/mdio-pic64hpsc.c new file +5 -0
+	writel(MDIO_TRIGGER_BIT | FIELD_PREP(MDIO_REG_DEV_ADDR_MASK, regnum) |
+		       FIELD_PREP(MDIO_PHY_PRT_ADDR_MASK, mii_id) |
+		       FIELD_PREP(MDIO_OPERATION_MASK, MDIO_OPERATION_WRITE) |
+		       FIELD_PREP(MDIO_START_OF_FRAME_MASK, 1),
+	       priv->regs + MDIO_REG_FRAME_CFG_2);

Shouldn't this wait for the write to complete?

As it is, the write transaction has NOT finished when the function returns, because there's no call to pic64hpsc_mdio_wait_trigger().

It works because there's a pic64hpsc_mdio_wait_trigger() at the beginning of ->read() and ->write(), so the completion will be waited for on the next read or write. I've taken this from mdio-mscc-miim.c.

I don't know if there's any value in waiting for write completion here as write completion doesn't mean that the effects of the write are available right now. I also didn't run into any issues in my testing. Let me know if you know of a use case where this wouldn't work.

I can add a wait for transaction completion if that's expected by phylib.

Thanks,
Charles

Quoted 5 lines

Thanks.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#7 lore raw

Re: [PATCH net-next v3 2/2] net: mdio: add a driver for PIC64-HPSC/HX MDIO controller

Quoted 6 lines · Charles Perry

I don't know if there's any value in waiting for write completion here as write completion doesn't mean that the effects of the write are available right now. I also didn't run into any issues in my testing. Let me know if you know of a use case where this wouldn't work.

I can add a wait for transaction completion if that's expected by phylib.

Consider a PHY using a shared interrupt line, and the interrupt being disabled in at the PHY before being torn down... wouldn't we want the write to the register which enables interrupts to complete before we unregister the interrupt handler for the particular PHY?

I do notice that other MDIO drivers don't wait. Some PHY drivers don't access the PHY after the write to disable interrupts either. So, maybe phy_free_interrupt() should read-back from the PHY before calling free_irq() to guarantee that the write has completed?

Andrew?

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
maintainer
#8 lore raw

Re: [PATCH net-next v3 2/2] net: mdio: add a driver for PIC64-HPSC/HX MDIO controller

Quoted 13 lines · Russell King (Oracle)
Quoted 6 lines · Charles Perry

I don't know if there's any value in waiting for write completion here as write completion doesn't mean that the effects of the write are available right now. I also didn't run into any issues in my testing. Let me know if you know of a use case where this wouldn't work.

I can add a wait for transaction completion if that's expected by phylib.

Consider a PHY using a shared interrupt line, and the interrupt being disabled in at the PHY before being torn down... wouldn't we want the write to the register which enables interrupts to complete before we unregister the interrupt handler for the particular PHY?

Quoted 6 lines

I do notice that other MDIO drivers don't wait. Some PHY drivers don't access the PHY after the write to disable interrupts either. So, maybe phy_free_interrupt() should read-back from the PHY before calling free_irq() to guarantee that the write has completed?

Andrew?

The general pattern is to not wait on write.

Interrupts is not a case i've thought about. Yes, a read to flush the write would make sense, maybe in phy_disable_interrupts().

Andrew

author maintainer
#9 lore raw

Re: [PATCH net-next v3 2/2] net: mdio: add a driver for PIC64-HPSC/HX MDIO controller

Quoted 14 lines · Andrew Lunn
Quoted 13 lines · Russell King (Oracle)
Quoted 6 lines · Charles Perry

I don't know if there's any value in waiting for write completion here as write completion doesn't mean that the effects of the write are available right now. I also didn't run into any issues in my testing. Let me know if you know of a use case where this wouldn't work.

I can add a wait for transaction completion if that's expected by phylib.

Consider a PHY using a shared interrupt line, and the interrupt being disabled in at the PHY before being torn down... wouldn't we want the write to the register which enables interrupts to complete before we unregister the interrupt handler for the particular PHY?

Quoted 8 lines
Quoted 6 lines

I do notice that other MDIO drivers don't wait. Some PHY drivers don't access the PHY after the write to disable interrupts either. So, maybe phy_free_interrupt() should read-back from the PHY before calling free_irq() to guarantee that the write has completed?

Andrew?

The general pattern is to not wait on write.

Ok, then it's status quo for this.

I'll send a v4 later this week for the other return issue.

Thanks,
Charles

#10 lore raw

Re: [PATCH net-next v3 2/2] net: mdio: add a driver for PIC64-HPSC/HX MDIO controller

Quoted 20 lines · Charles Perry
Quoted 19 lines · Andrew Lunn
Quoted 18 lines · Russell King (Oracle)
Quoted 6 lines · Charles Perry

I don't know if there's any value in waiting for write completion here as write completion doesn't mean that the effects of the write are available right now. I also didn't run into any issues in my testing. Let me know if you know of a use case where this wouldn't work.

I can add a wait for transaction completion if that's expected by phylib.

Consider a PHY using a shared interrupt line, and the interrupt being disabled in at the PHY before being torn down... wouldn't we want the write to the register which enables interrupts to complete before we unregister the interrupt handler for the particular PHY?

I do notice that other MDIO drivers don't wait. Some PHY drivers don't access the PHY after the write to disable interrupts either. So, maybe phy_free_interrupt() should read-back from the PHY before calling free_irq() to guarantee that the write has completed?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Andrew?

The general pattern is to not wait on write.

Ok, then it's status quo for this.

Except someone needs to add that read-back - don't look at me, I generate too many patches for netdev, so have no capacity for yet more patches.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
maintainer
#11 lore raw

Re: [PATCH net-next v3 2/2] net: mdio: add a driver for PIC64-HPSC/HX MDIO controller

In reply to Charles Perry
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Andrew?

The general pattern is to not wait on write.

Ok, then it's status quo for this.

I'll send a v4 later this week for the other return issue.

Please consider adding a one line patch to phy_disable_interrupts to read register MII_PHYSID1 and throw away the result.

Andrew