Add support for PIC64-HPSC/HX MDIO controller
Subsystems (5)
Charles Perry
maintainerv4 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.
This series also adds a PHY write barrier when disabling PHY interrupts as discussed in [1].
Thanks,
Charles
[1]: https://lore.kernel.org/all/[email protected]/
Changes in v4:
- 3/3: Add the PHY barrier patch (Russell, Andrew)
- 2/3: return FIELD_GET() directly instead of using "ret" (Russell)
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)
Charles Perry (3):
dt-bindings: net: document Microchip PIC64-HPSC/HX MDIO controller
net: mdio: add a driver for PIC64-HPSC/HX MDIO controller
net: phy: add a PHY write barrier when disabling interrupts
.../net/microchip,pic64hpsc-mdio.yaml | 68 +++++++ MAINTAINERS | 6 + drivers/net/mdio/Kconfig | 7 + drivers/net/mdio/Makefile | 1 + drivers/net/mdio/mdio-pic64hpsc.c | 190 ++++++++++++++++++ drivers/net/phy/phy.c | 27 ++- 6 files changed, 298 insertions(+), 1 deletion(-) 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
Charles Perry
maintainerPATCH v4 1/3 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 v4: none
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
@@ -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
Charles Perry
maintainerPATCH v4 2/3 net: mdio: add a driver for PIC64-HPSC/HX MDIO controller
In reply to Charles PerryThis 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 v4:
- read: return FIELD_GET() directly instead of using "ret" (Russell)
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 | 190 ++++++++++++++++++++++++++++++ 4 files changed, 204 insertions(+) create mode 100644 drivers/net/mdio/mdio-pic64hpsc.c
MAINTAINERS +6 -0
@@ -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
@@ -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
@@ -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 +190 -0
190 lines not on this page · raw message
Signature · 1 line
2.47.3
Charles Perry
maintainerPATCH v4 3/3 net: phy: add a PHY write barrier when disabling interrupts
In reply to Charles PerryMDIO bus controllers are not required to wait for write transactions to complete before returning as synchronization is often achieved by polling status bits.
This can cause issues when disabling interrupts since an interrupt could fire before the interrupt handler is unregistered and there's no status bit to poll.
Add a phy_write_barrier() function and use it in phy_disable_interrupts() to fix this issue. The write barrier just reads an MII register and discards the value, which is enough to guarantee that previous writes have completed.
---
Notes:
Changes in v4:
- Add this patch (Russell, Andrew)
drivers/net/phy/phy.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
drivers/net/phy/phy.c +26 -1
@@ -1368,14 +1368,39 @@ void phy_error(struct phy_device *phydev) }EXPORT_SYMBOL (phy_error); +/** +* phy_write_barrier - ensure the last write completed for this PHY device +* @phydev: target phy_device struct +* +* MDIO bus controllers are not required to wait for write transactions to +* complete before returning. Calling this function ensures that the previous +* write has completed. +*/ +static int phy_write_barrier (struct phy_device *phydev) +{ +int err; + + err =phy_read (phydev,MII_PHYSID1 ); +if (err <0 ) +return err; + +return 0 ; +} +/** * phy_disable_interrupts - Disable the PHY interrupts from the PHY side * @phydev: target phy_device struct */ int phy_disable_interrupts (struct phy_device *phydev) { +int err; +/* Disable PHY interrupts */ -return phy_config_interrupt (phydev,PHY_INTERRUPT_DISABLED ); + err =phy_config_interrupt (phydev,PHY_INTERRUPT_DISABLED ); +if (err) +return err; + +return phy_write_barrier (phydev); }/**
Signature · 1 line
2.47.3
Andrew Lunn
maintainerRe: [PATCH net-next v4 3/3] net: phy: add a PHY write barrier when disabling interrupts
drivers/net/phy/phy.c void phy_error(struct phy_device *phydev) · line 1385
Quoted 7 lines
drivers/net/phy/phy.c +7
-0+static int phy_write_barrier (struct phy_device *phydev) +{ +int err; + + err =phy_read (phydev,MII_PHYSID1 ); +if (err <0 ) +return err;
There are a small number of MDIO busses which don't implement C22, only C45. You are likely to get -EIO or maybe ENODEV, -EOPNOTSUPP, -EINVAL for such a read. Returning the error than makes phy_disable_interrupts() fail, etc.
This is why i suggested throwing away the return value.
Maybe call phydev_info() if there is an error, but i suggest making this a void function.
Andrew
---
pw-bot: cr
Charles Perry
maintainerRe: [PATCH net-next v4 3/3] net: phy: add a PHY write barrier when disabling interrupts
Quoted 4 lines · Andrew Lunn
Quoted 4 lines
drivers/net/phy/phy.c +4
-0+static int phy_write_barrier (struct phy_device *phydev) +{ +int err; +
Quoted 8 lines
drivers/net/phy/phy.c void phy_error(struct phy_device *phydev) · line 1385
Quoted 3 lines
drivers/net/phy/phy.c +3
-0+ err =phy_read (phydev,MII_PHYSID1 ); +if (err <0 ) +return err;There are a small number of MDIO busses which don't implement C22, only C45. You are likely to get
-EIOor maybe ENODEV,-EOPNOTSUPP,-EINVALfor such a read. Returning the error than makesphy_disable_interrupts()fail, etc.
Ok, I didn't know about this. Do you think there's any merit in handling the case where phydev->mdio.bus->read is NULL and doing a C45 access in that case?
Quoted 2 lines
This is why i suggested throwing away the return value.
Ok
Thanks,
Charles
Quoted 8 lines
Maybe call
phydev_info()if there is an error, but i suggest making this a void function.Andrew
---
pw-bot: cr
Russell King (Oracle)
reviewerRe: [PATCH net-next v4 3/3] net: phy: add a PHY write barrier when disabling interrupts
In reply to Andrew LunnQuoted 4 lines · Andrew Lunn
Quoted 4 lines
drivers/net/phy/phy.c +4
-0+static int phy_write_barrier (struct phy_device *phydev) +{ +int err; +
Quoted 8 lines
drivers/net/phy/phy.c void phy_error(struct phy_device *phydev) · line 1385
Quoted 3 lines
drivers/net/phy/phy.c +3
-0+ err =phy_read (phydev,MII_PHYSID1 ); +if (err <0 ) +return err;There are a small number of MDIO busses which don't implement C22, only C45. You are likely to get
-EIOor maybe ENODEV,-EOPNOTSUPP,-EINVALfor such a read. Returning the error than makesphy_disable_interrupts()fail, etc.
If it returns -EOPNOTSUPP (meaning, at least, that bus->read is not implemented), do we want to issue a C45 read instead?
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!
Andrew Lunn
maintainerRe: [PATCH net-next v4 3/3] net: phy: add a PHY write barrier when disabling interrupts
Quoted 14 lines · Russell King (Oracle)
Quoted 4 lines · Andrew Lunn
Quoted 4 lines
drivers/net/phy/phy.c +4
-0+static int phy_write_barrier (struct phy_device *phydev) +{ +int err; +Quoted 8 lines
drivers/net/phy/phy.c void phy_error(struct phy_device *phydev) · line 1385
Quoted 3 lines
drivers/net/phy/phy.c +3
-0+ err =phy_read (phydev,MII_PHYSID1 ); +if (err <0 ) +return err;There are a small number of MDIO busses which don't implement C22, only C45. You are likely to get
-EIOor maybe ENODEV,-EOPNOTSUPP,-EINVALfor such a read. Returning the error than makesphy_disable_interrupts()fail, etc.
Quoted 2 lines
If it returns
-EOPNOTSUPP(meaning, at least, thatbus->readis not implemented), do we want to issue a C45 read instead?
Maybe.
get_phy_c45_ids() first reads MDIO_MMD_PMAPMD : MII_PHYSID1. That seems like a safe option.
Andrew
Charles Perry
maintainerRe: [PATCH net-next v4 3/3] net: phy: add a PHY write barrier when disabling interrupts
Quoted 15 lines · Andrew Lunn
Quoted 14 lines · Russell King (Oracle)
Quoted 12 lines · Andrew Lunn
drivers/net/phy/phy.c void phy_error(struct phy_device *phydev) · line 1385
Quoted 7 lines
drivers/net/phy/phy.c +7
-0+static int phy_write_barrier (struct phy_device *phydev) +{ +int err; + + err =phy_read (phydev,MII_PHYSID1 ); +if (err <0 ) +return err;There are a small number of MDIO busses which don't implement C22, only C45. You are likely to get
-EIOor maybe ENODEV,-EOPNOTSUPP,-EINVALfor such a read. Returning the error than makesphy_disable_interrupts()fail, etc.
Quoted 7 lines
Quoted 2 lines
If it returns
-EOPNOTSUPP(meaning, at least, thatbus->readis not implemented), do we want to issue a C45 read instead?Maybe.
get_phy_c45_ids()first readsMDIO_MMD_PMAPMD:MII_PHYSID1. That seems like a safe option.
Here's where I'm at with this:
static void phy_write_barrier(struct phy_device *phydev)
{
int err;
err = mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, MII_PHYSID1);
if (err == -EOPNOTSUPP)
mdiobus_c45_read(phydev->mdio.bus, phydev->mdio.addr,
__ffs(phydev->c45_ids.mmds_present),
MII_PHYSID1);
}In part inspired by phylink_phy_read() in phylink.c
Do you think there's any way I can test this on my VSC8574 or VSC8541? It supports some C45 registers for EEE but not the device discovery part.
Thanks,
Charles
Andrew Lunn
maintainerRe: [PATCH net-next v4 3/3] net: phy: add a PHY write barrier when disabling interrupts
Quoted 10 lines
static void
phy_write_barrier(struct phy_device *phydev){ int err; err = mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, MII_PHYSID1); if (err == -EOPNOTSUPP) mdiobus_c45_read(phydev->mdio.bus, phydev->mdio.addr, __ffs(phydev->c45_ids.mmds_present), MII_PHYSID1); }
Using __ffs() is maybe more complex than needed.
All you are trying to do is ensure the last write happened, by doing a read. Any read should work, even if the device does not respond. We just need to be careful not to read a register which might clear on read, such as an interrupt status register, or the link status, which latches. MII_PHYID1 is safe. Since we throw away the value, we don't care if the MMD is not present, the read will still flush the previous write. So i would replace the _ffs() with a hard coded value. KISS.
Quoted 2 lines
Do you think there's any way I can test this on my VSC8574 or VSC8541? It supports some C45 registers for EEE but not the device discovery part.
It is not so easy to do. You need to hack the C22 read so that is returns EOPNOTSUPP, but you also need the first few reads to return a valid value otherwise the probe will fail.
I think this is one of the cases that if the reviewers thinks its looks O.K, we can accept it without extensive testing.
Andrew
Charles Perry
maintainerRe: [PATCH net-next v4 3/3] net: phy: add a PHY write barrier when disabling interrupts
Quoted 13 lines · Andrew Lunn
Quoted 10 lines
static void
phy_write_barrier(struct phy_device *phydev){ int err; err = mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, MII_PHYSID1); if (err == -EOPNOTSUPP) mdiobus_c45_read(phydev->mdio.bus, phydev->mdio.addr, __ffs(phydev->c45_ids.mmds_present), MII_PHYSID1); }Using
__ffs()is maybe more complex than needed.
Quoted 7 lines
All you are trying to do is ensure the last write happened, by doing a read. Any read should work, even if the device does not respond. We just need to be careful not to read a register which might clear on read, such as an interrupt status register, or the link status, which latches.
MII_PHYID1is safe. Since we throw away the value, we don't care if the MMD is not present, the read will still flush the previous write. So i would replace the_ffs()with a hard coded value. KISS.
Ok, I'll use device 1 (MDIO_MMD_PMAPMD).
Thanks for the explanations.
Quoted 11 lines
Quoted 3 lines
Do you think there's any way I can test this on my VSC8574 or VSC8541? It supports some C45 registers for EEE but not the device discovery part.
It is not so easy to do. You need to hack the C22 read so that is returns EOPNOTSUPP, but you also need the first few reads to return a valid value otherwise the probe will fail.
I think this is one of the cases that if the reviewers thinks its looks O.K, we can accept it without extensive testing.
Ok
Thanks,
Charles