Skip to contentSkip to conversation

Add support for SFPs behind PHYs

PATCH Superseded Russell King - ARM Linux admin 4 participants 14 messages Nov 10, 2019 – Nov 11, 2019

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add support for SFPs behind PHYs

This series adds partial support for SFP cages connected to PHYs, specifically optical SFPs.

We add core infrastructure to phylib for this, and arrange for minimal code in the PHY driver - currently, this is code to verify that the module is one that we can support for Marvell 10G PHYs.

 drivers/net/phy/marvell10g.c | 25 ++++++++++++++++-
 drivers/net/phy/phy.c        |  7 +++++
 drivers/net/phy/phy_device.c | 66 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/phy.h          | 11 ++++++++
 4 files changed, 108 insertions(+), 1 deletion(-)
Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
#1 lore raw

PATCH 1/2 net: phy: add core phylib sfp support

Add core phylib help for supporting SFP sockets on PHYs. This provides a mechanism to inform the SFP layer about PHY up/down events, and also unregister the SFP bus when the PHY is going away.

---
 drivers/net/phy/phy.c        |  7 ++++
 drivers/net/phy/phy_device.c | 66 ++++++++++++++++++++++++++++++++++++
 include/linux/phy.h          | 11 ++++++
 3 files changed, 84 insertions(+)
drivers/net/phy/phy.c +7 -0
index 0a314cf45408..cb9ab24ee898 100644
@@ -23,6 +23,7 @@
 #include <linux/ethtool.h>
 #include <linux/phy.h>
 #include <linux/phy_led_triggers.h>
+#include <linux/sfp.h>
 #include <linux/workqueue.h>
 #include <linux/mdio.h>
 #include <linux/io.h>
@@ -866,6 +867,9 @@ void phy_stop(struct phy_device *phydev)
 
 	mutex_lock(&phydev->lock);
 
+	if (phydev->sfp_bus)
+		sfp_upstream_stop(phydev->sfp_bus);
+
 	phydev->state = PHY_HALTED;
 
 	mutex_unlock(&phydev->lock);
@@ -900,6 +904,9 @@ void phy_start(struct phy_device *phydev)
 		goto out;
 	}
 
+	if (phydev->sfp_bus)
+		sfp_upstream_start(phydev->sfp_bus);
+
 	/* if phy was suspended, bring the physical link up again */
 	__phy_resume(phydev);
 
drivers/net/phy/phy_device.c +66 -0

90 lines not on this page · raw message

include/linux/phy.h +11 -0
index 1f9a141ccfb4..9753d9f28d73 100644
@@ -203,6 +203,8 @@ static inline const char *phy_modes(phy_interface_t interface)
 
 struct device;
 struct phylink;
+struct sfp_bus;
+struct sfp_upstream_ops;
 struct sk_buff;
 
 /*
@@ -342,6 +344,8 @@ struct phy_c45_device_ids {
  * dev_flags: Device-specific flags used by the PHY driver.
  * irq: IRQ number of the PHY's interrupt (-1 if none)
  * phy_timer: The timer for handling the state machine
+ * sfp_bus_attached: flag indicating whether the SFP bus has been attached
+ * sfp_bus: SFP bus attached to this PHY's fiber port
  * attached_dev: The attached enet driver's device instance ptr
  * adjust_link: Callback for the enet controller to respond to
  * changes in the link state.
@@ -430,6 +434,9 @@ struct phy_device {
 
 	struct mutex lock;
 
+	/* This may be modified under the rtnl lock */
+	bool sfp_bus_attached;
+	struct sfp_bus *sfp_bus;
 	struct phylink *phylink;
 	struct net_device *attached_dev;
 
@@ -1015,6 +1022,10 @@ int phy_suspend(struct phy_device *phydev);
 int phy_resume(struct phy_device *phydev);
 int __phy_resume(struct phy_device *phydev);
 int phy_loopback(struct phy_device *phydev, bool enable);
+void phy_sfp_attach(void *upstream, struct sfp_bus *bus);
+void phy_sfp_detach(void *upstream, struct sfp_bus *bus);
+int phy_sfp_probe(struct phy_device *phydev,
+	          const struct sfp_upstream_ops *ops);
 struct phy_device *phy_attach(struct net_device *dev, const char *bus_id,
 			      phy_interface_t interface);
 struct phy_device *phy_find_first(struct mii_bus *bus);
Signature · 1 line
2.20.1
maintainer
#2 lore raw

Re: [PATCH net-next 1/2] net: phy: add core phylib sfp support

Quoted 3 lines · Russell King

Add core phylib help for supporting SFP sockets on PHYs. This provides a mechanism to inform the SFP layer about PHY up/down events, and also unregister the SFP bus when the PHY is going away.

Hi Russell

What does the device tree binding look like? I think you have SFP proprieties in the PHYs node?

Thanks
Andrew

#3 lore raw

Re: [PATCH net-next 1/2] net: phy: add core phylib sfp support

Quoted 9 lines · Andrew Lunn
Quoted 3 lines · Russell King

Add core phylib help for supporting SFP sockets on PHYs. This provides a mechanism to inform the SFP layer about PHY up/down events, and also unregister the SFP bus when the PHY is going away.

Hi Russell

What does the device tree binding look like? I think you have SFP proprieties in the PHYs node?

Correct, just the same as network devices. Hmm, however, neither are documented... oh dear, it looks like I need to figure out how this yaml stuff works. :(

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

Re: [PATCH net-next 1/2] net: phy: add core phylib sfp support

Quoted 6 lines · Russell King - ARM Linux admin
Quoted 5 lines · Andrew Lunn
Quoted 3 lines · Russell King

Add core phylib help for supporting SFP sockets on PHYs. This provides a mechanism to inform the SFP layer about PHY up/down events, and also unregister the SFP bus when the PHY is going away.

Quoted 8 lines
Quoted 4 lines

Hi Russell

What does the device tree binding look like? I think you have SFP proprieties in the PHYs node?

Correct, just the same as network devices. Hmm, however, neither are documented... oh dear, it looks like I need to figure out how this yaml stuff works. :(

Yes, that would be good. I also assume you have at least one DT patch for one of the Marvell boards? Seeing that would also help.

FYI: It is good to see this feature added. It has been blocked for a long time, but this implementation is actually nice and simple.

Thanks
Andrew

#5 lore raw

Re: [PATCH net-next 1/2] net: phy: add core phylib sfp support

Quoted 12 lines · Andrew Lunn
Quoted 11 lines · Russell King - ARM Linux admin
Quoted 9 lines · Andrew Lunn
Quoted 3 lines · Russell King

Add core phylib help for supporting SFP sockets on PHYs. This provides a mechanism to inform the SFP layer about PHY up/down events, and also unregister the SFP bus when the PHY is going away.

Hi Russell

What does the device tree binding look like? I think you have SFP proprieties in the PHYs node?

Quoted 6 lines
Quoted 3 lines

Correct, just the same as network devices. Hmm, however, neither are documented... oh dear, it looks like I need to figure out how this yaml stuff works. :(

Yes, that would be good. I also assume you have at least one DT patch for one of the Marvell boards? Seeing that would also help.

There's no need, it was already added by bootlin back in May 2018.

arch/arm64/boot/dts/marvell/armada-8040-mcbin.dts

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

Re: [PATCH net-next 1/2] net: phy: add core phylib sfp support

Quoted 13 lines · Russell King - ARM Linux admin
Quoted 12 lines · Andrew Lunn
Quoted 11 lines · Russell King - ARM Linux admin
Quoted 9 lines · Andrew Lunn
Quoted 3 lines · Russell King

Add core phylib help for supporting SFP sockets on PHYs. This provides a mechanism to inform the SFP layer about PHY up/down events, and also unregister the SFP bus when the PHY is going away.

Hi Russell

What does the device tree binding look like? I think you have SFP proprieties in the PHYs node?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Correct, just the same as network devices. Hmm, however, neither are documented... oh dear, it looks like I need to figure out how this yaml stuff works. :(

Yes, that would be good. I also assume you have at least one DT patch for one of the Marvell boards? Seeing that would also help.

There's no need, it was already added by bootlin back in May 2018.

Ah. Lucky for them the binding works :-)

Andrew

#7 lore raw

Re: [PATCH net-next 1/2] net: phy: add core phylib sfp support

In reply to Andrew Lunn
Quoted 12 lines · Andrew Lunn
Quoted 11 lines · Russell King - ARM Linux admin
Quoted 9 lines · Andrew Lunn
Quoted 3 lines · Russell King

Add core phylib help for supporting SFP sockets on PHYs. This provides a mechanism to inform the SFP layer about PHY up/down events, and also unregister the SFP bus when the PHY is going away.

Hi Russell

What does the device tree binding look like? I think you have SFP proprieties in the PHYs node?

Quoted 6 lines
Quoted 3 lines

Correct, just the same as network devices. Hmm, however, neither are documented... oh dear, it looks like I need to figure out how this yaml stuff works. :(

Yes, that would be good. I also assume you have at least one DT patch for one of the Marvell boards? Seeing that would also help.

So, how does one make sure that the .yaml files are correct?

The obvious thing is to use the "dtbs_check" target, described by Documentation/devicetree/writing-schema.md, but that's far from trivial.

First it complained about lack of libyaml development, which is easy to solve. Having given it that, "dtbs_check" now complains:

/bin/sh: 1: dt-doc-validate: not found
/bin/sh: 1: dt-mk-schema: not foundmake[2]: *** [...Documentation/devicetree/bindings/Makefile:12:
Documentation/devicetree/bindings/arm/stm32/stm32.example.dts] Error 127

(spot the lack of newline character - which is obviously an entirely different problem...)

# apt search dt-doc-validate
Sorting... Done
Full Text Search... Done
# apt search dt-mk-schema
Sorting... Done
Full Text Search... Done

Searching google, it appears it needs another git repository
(https://github.com/robherring/dt-schema/) from Rob Herring to use this stuff, which is totally undocumented in the kernel tree.

Rob, can we have some _decent_ documentation on how to use this stuff please, particularly something that describes what the external dependencies are and where to get the necessary code from - it's rather unfair to make documentation of DT properties a requirement for integration into the kernel, convert the documentation to .yaml format, and not tell people how they can sensibly validate it. Thanks.

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

Re: [PATCH net-next 1/2] net: phy: add core phylib sfp support

Quoted 24 lines · Russell King - ARM Linux admin

So, how does one make sure that the .yaml files are correct?

The obvious thing is to use the "dtbs_check" target, described by Documentation/devicetree/writing-schema.md, but that's far from trivial.

First it complained about lack of libyaml development, which is easy to solve. Having given it that, "dtbs_check" now complains:

/bin/sh: 1: dt-doc-validate: not found
/bin/sh: 1: dt-mk-schema: not foundmake[2]: *** [...Documentation/devicetree/bindings/Makefile:12:
Documentation/devicetree/bindings/arm/stm32/stm32.example.dts] Error 127

(spot the lack of newline character - which is obviously an entirely different problem...)

# apt search dt-doc-validate
Sorting... Done
Full Text Search... Done
# apt search dt-mk-schema
Sorting... Done
Full Text Search... Done
Quoted 3 lines

Searching google, it appears it needs another git repository
(https://github.com/robherring/dt-schema/) from Rob Herring to use this stuff, which is totally undocumented in the kernel tree.

Okay, that just seems to be "examples" rather than something which is installable to provide the necessary commands.

So, I'm afraid I've no idea how I can change any of the .yaml files and know that the changes are in fact correct. Given that, I think we need to drop the rule that DT bindings are documented prior to being merged into the kernel until there is some decent and full documentation.

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

Re: [PATCH net-next 1/2] net: phy: add core phylib sfp support

In reply to Russell King - ARM Linux admin
Quoted 18 lines · Russell King - ARM Linux admin
Quoted 16 lines · Andrew Lunn
Quoted 14 lines · Russell King - ARM Linux admin
Quoted 9 lines · Andrew Lunn
Quoted 3 lines · Russell King

Add core phylib help for supporting SFP sockets on PHYs. This provides a mechanism to inform the SFP layer about PHY up/down events, and also unregister the SFP bus when the PHY is going away.

Hi Russell

What does the device tree binding look like? I think you have SFP proprieties in the PHYs node?

Correct, just the same as network devices. Hmm, however, neither are documented... oh dear, it looks like I need to figure out how this yaml stuff works. :(

Quoted 8 lines
Quoted 2 lines

Yes, that would be good. I also assume you have at least one DT patch for one of the Marvell boards? Seeing that would also help.

So, how does one make sure that the .yaml files are correct?

The obvious thing is to use the "dtbs_check" target, described by Documentation/devicetree/writing-schema.md, but that's far from trivial.

'dt_binding_check' will check just the bindings. 'dtbs_check' is pretty slow given we have so many dts files and it generates lots of warnings.

Quoted 18 lines

First it complained about lack of libyaml development, which is easy to solve. Having given it that, "dtbs_check" now complains:

/bin/sh: 1: dt-doc-validate: not found
/bin/sh: 1: dt-mk-schema: not foundmake[2]: *** [...Documentation/devicetree/bindings/Makefile:12:
Documentation/devicetree/bindings/arm/stm32/stm32.example.dts] Error 127

(spot the lack of newline character - which is obviously an entirely different problem...)

# apt search dt-doc-validate
Sorting... Done
Full Text Search... Done
# apt search dt-mk-schema
Sorting... Done
Full Text Search... Done
Quoted 3 lines

Searching google, it appears it needs another git repository
(https://github.com/robherring/dt-schema/) from Rob Herring to use this stuff, which is totally undocumented in the kernel tree.

The dependencies are all documented in writing-schema.rst (formerly .md) in the 'Dependencies' section.

TL;DR: pip3 install git+https://github.com/devicetree-org/dt-schema.git@master

Rob

#10 lore raw

Re: [PATCH net-next 1/2] net: phy: add core phylib sfp support

Quoted 51 lines · Rob Herring
Quoted 18 lines · Russell King - ARM Linux admin
Quoted 16 lines · Andrew Lunn
Quoted 14 lines · Russell King - ARM Linux admin
Quoted 9 lines · Andrew Lunn
Quoted 3 lines · Russell King

Add core phylib help for supporting SFP sockets on PHYs. This provides a mechanism to inform the SFP layer about PHY up/down events, and also unregister the SFP bus when the PHY is going away.

Hi Russell

What does the device tree binding look like? I think you have SFP proprieties in the PHYs node?

Correct, just the same as network devices. Hmm, however, neither are documented... oh dear, it looks like I need to figure out how this yaml stuff works. :(

Quoted 8 lines
Quoted 2 lines

Yes, that would be good. I also assume you have at least one DT patch for one of the Marvell boards? Seeing that would also help.

So, how does one make sure that the .yaml files are correct?

The obvious thing is to use the "dtbs_check" target, described by Documentation/devicetree/writing-schema.md, but that's far from trivial.

'dt_binding_check' will check just the bindings. 'dtbs_check' is pretty slow given we have so many dts files and it generates lots of warnings.

Quoted 18 lines

First it complained about lack of libyaml development, which is easy to solve. Having given it that, "dtbs_check" now complains:

/bin/sh: 1: dt-doc-validate: not found
/bin/sh: 1: dt-mk-schema: not foundmake[2]: *** [...Documentation/devicetree/bindings/Makefile:12:
Documentation/devicetree/bindings/arm/stm32/stm32.example.dts] Error 127

(spot the lack of newline character - which is obviously an entirely different problem...)

# apt search dt-doc-validate
Sorting... Done
Full Text Search... Done
# apt search dt-mk-schema
Sorting... Done
Full Text Search... Done
Quoted 8 lines
Quoted 3 lines

Searching google, it appears it needs another git repository
(https://github.com/robherring/dt-schema/) from Rob Herring to use this stuff, which is totally undocumented in the kernel tree.

The dependencies are all documented in writing-schema.rst (formerly .md) in the 'Dependencies' section.

TL;DR: pip3 install git+https://github.com/devicetree-org/dt-schema.git@master

What is pip3, and where do I get it from (I'm running Debian stable).

# apt search pip3
Sorting... Done
Full Text Search... Done

Don't expect people know python.

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

Re: [PATCH net-next 1/2] net: phy: add core phylib sfp support

Quoted 57 lines · Russell King - ARM Linux admin
Quoted 55 lines · Rob Herring
Quoted 18 lines · Russell King - ARM Linux admin
Quoted 16 lines · Andrew Lunn
Quoted 14 lines · Russell King - ARM Linux admin
Quoted 9 lines · Andrew Lunn
Quoted 3 lines · Russell King

Add core phylib help for supporting SFP sockets on PHYs. This provides a mechanism to inform the SFP layer about PHY up/down events, and also unregister the SFP bus when the PHY is going away.

Hi Russell

What does the device tree binding look like? I think you have SFP proprieties in the PHYs node?

Correct, just the same as network devices. Hmm, however, neither are documented... oh dear, it looks like I need to figure out how this yaml stuff works. :(

Quoted 8 lines
Quoted 2 lines

Yes, that would be good. I also assume you have at least one DT patch for one of the Marvell boards? Seeing that would also help.

So, how does one make sure that the .yaml files are correct?

The obvious thing is to use the "dtbs_check" target, described by Documentation/devicetree/writing-schema.md, but that's far from trivial.

'dt_binding_check' will check just the bindings. 'dtbs_check' is pretty slow given we have so many dts files and it generates lots of warnings.

Quoted 21 lines

First it complained about lack of libyaml development, which is easy to solve. Having given it that, "dtbs_check" now complains:

/bin/sh: 1: dt-doc-validate: not found
/bin/sh: 1: dt-mk-schema: not foundmake[2]: *** [...Documentation/devicetree/bindings/Makefile:12:
Documentation/devicetree/bindings/arm/stm32/stm32.example.dts] Error 127

(spot the lack of newline character - which is obviously an entirely different problem...)

# apt search dt-doc-validate
Sorting... Done
Full Text Search... Done
# apt search dt-mk-schema
Sorting... Done
Full Text Search... Done

Searching google, it appears it needs another git repository
(https://github.com/robherring/dt-schema/) from Rob Herring to use this stuff, which is totally undocumented in the kernel tree.

Quoted 6 lines
Quoted 4 lines

The dependencies are all documented in writing-schema.rst (formerly .md) in the 'Dependencies' section.

TL;DR: pip3 install git+https://github.com/devicetree-org/dt-schema.git@master

What is pip3, and where do I get it from (I'm running Debian stable).

apt install python3-pip

This is not in the documentation because it is distro specific.

Quoted 5 lines
# apt search pip3
Sorting... Done
Full Text Search... Done

Don't expect people know python.

How about rewording:

'The DT schema project can be installed with pip:'

to this:

'The DT schema project is a Python project and is most easily installed using the Python package manager "pip":

pip3 install git+https://github.com/devicetree-org/dt-schema.git@master

It is also possible to install by cloning the git repository and running "setup.py".
'

Googling 'python pip' or 'setup.py' should get folks the rest of the way if 'pip' or 'setup.py' is new to them.

Rob

#12 lore raw

Re: [PATCH net-next 1/2] net: phy: add core phylib sfp support

In reply to Rob Herring
Quoted 4 lines · Rob Herring

The dependencies are all documented in writing-schema.rst (formerly .md) in the 'Dependencies' section.

TL;DR: pip3 install git+https://github.com/devicetree-org/dt-schema.git@master

I've mentioned it in a few IRC forums, and it seems that I'm not the only one who has trouble with this - so, this DT schema stuff totally fails the "keep it simple" approach, which is bad news if you want people to use it. It's a blocker when you have to do something with these .yaml files - or take the approach that you'd write something that looks write and hope that someone else checks it.

So, to help people, please consider adding to that section information such as:

8<====
For debian stable (buster), you will need to install:

- python3-pip

for the pip3 tool.

You do not need other python3 packages, as the pip3 tool will install the latest versions of any dependent packages into your ~/.local directory. However, note that these will not be kept up to date by your distribution.
8<====

It may be useful if the instructions for other distros are also added.

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

PATCH 2/2 net: phy: marvell10g: add SFP+ support

In reply to Russell King - ARM Linux admin

Add support for SFP+ cages to the Marvell 10G PHY driver. This is slightly complicated by the way phylib works in that we need to use a multi-step process to attach the SFP bus, and we also need to track the phylink state machine to know when the module's transmit disable signal should change state.

With appropriate DT changes, this allows the SFP+ canges on the Macchiatobin platform to be functional.

---
 drivers/net/phy/marvell10g.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/net/phy/marvell10g.c +24 -1
index 3b99882692e3..1bf13017d288 100644
@@ -26,6 +26,7 @@
 #include <linux/hwmon.h>
 #include <linux/marvell_phy.h>
 #include <linux/phy.h>
+#include <linux/sfp.h>
 
 #define MV_PHY_ALASKA_NBT_QUIRK_MASK	0xfffffffe
 #define MV_PHY_ALASKA_NBT_QUIRK_REV	(MARVELL_PHY_ID_88X3310 | 0xa)
@@ -206,6 +207,28 @@ static int mv3310_hwmon_probe(struct phy_device *phydev)
 }
 #endif
 
+static int mv3310_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
+{
+	struct phy_device *phydev = upstream;
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(support) = { 0, };
+	phy_interface_t iface;
+
+	sfp_parse_support(phydev->sfp_bus, id, support);
+	iface = sfp_select_interface(phydev->sfp_bus, id, support);
+
+	if (iface != PHY_INTERFACE_MODE_10GKR) {
+		dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n");
+		return -EINVAL;
+	}
+	return 0;
+}
+
+static const struct sfp_upstream_ops mv3310_sfp_ops = {
+	.attach = phy_sfp_attach,
+	.detach = phy_sfp_detach,
+	.module_insert = mv3310_sfp_insert,
+};
+
 static int mv3310_probe(struct phy_device *phydev)
 {
 	struct mv3310_priv *priv;
@@ -236,7 +259,7 @@ static int mv3310_probe(struct phy_device *phydev)
 	if (ret)
 		return ret;
 
-	return 0;
+	return phy_sfp_probe(phydev, &mv3310_sfp_ops);
 }
 
 static int mv3310_suspend(struct phy_device *phydev)
Signature · 1 line
2.20.1