Skip to contentSkip to conversation

net/phy: Improvements to Cavium Thunder MDIO code.

PATCH In review David Daney 4 participants 11 messages Mar 11, 2016 – Mar 16, 2016

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover net/phy: Improvements to Cavium Thunder MDIO code.

From: David Daney <[email protected]>

Changes from v1:

- In 1/3 Add back check for non-OF objects in bgx_init_of_phy(). It is probably not necessary, but better safe than sorry...

The firmware on many Cavium Thunder systems configures the MDIO bus hardware to be probed as a PCI device. In order to use the MDIO bus drivers in this configuration, we must add PCI probing to the driver.

There are two parts to this set of three patches:

1) Cleanup the PHY probing code in thunder_bgx.c to handle the case where there is no PHY attached to a port, as well as being more robust in the face of driver loading order by use of -EPROBE_DEFER.

2) Split mdio-octeon.c into two drivers, one with platform probing, and the other with PCI probing. Common code is shared between the two.

Tested on several different Thunder and OCTEON systems, also compile tested on x86_64.

David Daney (3):
net: thunderx: Cleanup PHY probing code.
phy: mdio-octeon: Refactor into two files/modules
phy: mdio-thunder: Add driver for Cavium Thunder SoC MDIO buses.

 .../devicetree/bindings/net/cavium-mdio.txt        |  61 ++++-
 drivers/net/ethernet/cavium/thunder/thunder_bgx.c  |  29 ++-
 drivers/net/phy/Kconfig                            |  22 +-
 drivers/net/phy/Makefile                           |   2 +
 drivers/net/phy/mdio-cavium.c                      | 149 +++++++++++
 drivers/net/phy/mdio-cavium.h                      | 119 +++++++++
 drivers/net/phy/mdio-octeon.c                      | 280 ++-------------------
 drivers/net/phy/mdio-thunder.c                     | 154 ++++++++++++
 8 files changed, 535 insertions(+), 281 deletions(-)
 create mode 100644 drivers/net/phy/mdio-cavium.c
 create mode 100644 drivers/net/phy/mdio-cavium.h
 create mode 100644 drivers/net/phy/mdio-thunder.c
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH v2 1/3 net: thunderx: Cleanup PHY probing code.

From: David Daney <[email protected]>

Remove the call to force the octeon-mdio driver to be loaded. Allow the standard driver loading mechanisms to load the PHY drivers, and use -EPROBE_DEFER to cause the BGX driver to be probed only after the PHY drivers are available.

Reorder the setting of MAC addresses and PHY probing to allow BGX LMACs with no attached PHY to still be assigned a MAC address.

---
 drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 29 ++++++++++++++---------
 1 file changed, 18 insertions(+), 11 deletions(-)
drivers/net/ethernet/cavium/thunder/thunder_bgx.c +18 -11
index f8abdff..feed231 100644
@@ -978,27 +978,37 @@ static int bgx_init_of_phy(struct bgx *bgx)
 	const char *mac;
 
 	device_for_each_child_node(&bgx->pdev->dev, fwn) {
+		struct phy_device *pd;
 		struct device_node *phy_np;
 		struct device_node *node = to_of_node(fwn);
 
-		/* If it is not an OF node we cannot handle it yet, so
-		 * exit the loop.
+		/* Should always be an OF node.  But if it is not, we
+		 * cannot handle it, so exit the loop.
 		 */
 		if (!node)
 			break;
 
-		phy_np = of_parse_phandle(node, "phy-handle", 0);
-		if (!phy_np)
-			continue;
-
-		bgx->lmac[lmac].phydev = of_phy_find_device(phy_np);
-
 		mac = of_get_mac_address(node);
 		if (mac)
 			ether_addr_copy(bgx->lmac[lmac].mac, mac);
 
 		SET_NETDEV_DEV(&bgx->lmac[lmac].netdev, &bgx->pdev->dev);
 		bgx->lmac[lmac].lmacid = lmac;
+
+		phy_np = of_parse_phandle(node, "phy-handle", 0);
+		/* If there is no phy or defective firmware presents
+		 * this cortina phy, for which there is no driver
+		 * support, ignore it.
+		 */
+		if (phy_np &&
+		    !of_device_is_compatible(phy_np, "cortina,cs4223-slice")) {
+			/* Wait until the phy drivers are available */
+			pd = of_phy_find_device(phy_np);
+			if (!pd)
+				return -EPROBE_DEFER;
+			bgx->lmac[lmac].phydev = pd;
+		}
+
 		lmac++;
 		if (lmac == MAX_LMAC_PER_BGX) {
 			of_node_put(node);
@@ -1032,9 +1042,6 @@ static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	struct bgx *bgx = NULL;
 	u8 lmac;
 
-	/* Load octeon mdio driver */
-	octeon_mdiobus_force_mod_depencency();
-
 	bgx = devm_kzalloc(dev, sizeof(*bgx), GFP_KERNEL);
 	if (!bgx)
 		return -ENOMEM;
Signature · 1 line
1.7.11.7
#2 lore raw

PATCH v2 2/3 phy: mdio-octeon: Refactor into two files/modules

In reply to David Daney

From: David Daney <[email protected]>

A follow-on patch uses PCI probing to find the Thunder MDIO hardware. In preparation for this, split out the common code into a new file mdio-cavium.c, which will be used by both the existing OCTEON driver, and the new Thunder PCI based driver.

As part of the refactoring simplify the struct cavium_mdiobus by removing fields that are only ever used in the probe function and can just as well be local variables.

Use readq/writeq in preference to readq_relaxed/writeq_relaxed as the relaxed form was an optimization for an early chip revision, and the MDIO drivers are not performance bottlenecks that need optimization in the first place.

---
 drivers/net/phy/Kconfig       |  11 +-
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/mdio-cavium.c | 149 ++++++++++++++++++++++
 drivers/net/phy/mdio-cavium.h | 119 ++++++++++++++++++
 drivers/net/phy/mdio-octeon.c | 280 +++---------------------------------------
 5 files changed, 292 insertions(+), 268 deletions(-)
 create mode 100644 drivers/net/phy/mdio-cavium.c
 create mode 100644 drivers/net/phy/mdio-cavium.h
drivers/net/phy/Kconfig +7 -4
index f0a7702..40faec9 100644
@@ -183,15 +183,18 @@ config MDIO_GPIO
 	  To compile this driver as a module, choose M here: the module
 	  will be called mdio-gpio.
 
+config MDIO_CAVIUM
+	tristate
+
 config MDIO_OCTEON
-	tristate "Support for MDIO buses on Octeon and ThunderX SOCs"
+	tristate "Support for MDIO buses on Octeon and some ThunderX SOCs"
 	depends on 64BIT
 	depends on HAS_IOMEM
+	select MDIO_CAVIUM
 	help
-
 	  This module provides a driver for the Octeon and ThunderX MDIO
-	  busses. It is required by the Octeon and ThunderX ethernet device
-	  drivers.
+	  buses. It is required by the Octeon and ThunderX ethernet device
+	  drivers on some systems.
 
 config MDIO_SUN4I
 	tristate "Allwinner sun4i MDIO interface support"
drivers/net/phy/Makefile +1 -0
index 680e88f9..041b3d9 100644
@@ -31,6 +31,7 @@ obj-$(CONFIG_DP83867_PHY)	+= dp83867.o
 obj-$(CONFIG_STE10XP)		+= ste10Xp.o
 obj-$(CONFIG_MICREL_PHY)	+= micrel.o
 obj-$(CONFIG_MDIO_OCTEON)	+= mdio-octeon.o
+obj-$(CONFIG_MDIO_CAVIUM)	+= mdio-cavium.o
 obj-$(CONFIG_MICREL_KS8995MA)	+= spi_ks8995.o
 obj-$(CONFIG_AT803X_PHY)	+= at803x.o
 obj-$(CONFIG_AMD_PHY)		+= amd.o
drivers/net/phy/mdio-cavium.c new file +149 -0

149 lines not on this page · raw message

drivers/net/phy/mdio-cavium.h new file +119 -0

119 lines not on this page · raw message

drivers/net/phy/mdio-octeon.c +16 -264

346 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#3 lore raw

PATCH v2 3/3 phy: mdio-thunder: Add driver for Cavium Thunder SoC MDIO buses.

In reply to David Daney

From: David Daney <[email protected]>

The Cavium Thunder SoCs have multiple MIDO buses that are part of a single PCI device. To model this in the device tree we call the PCI parent device a "cavium,thunder-8890-mdio-nexus", it has several children, one for each MDIO bus.

The MDIO bus hardware is identical to that found in the OCTEON SoCs, so we use that code for things that are not part of the PCI driver probe/remove

---
 .../devicetree/bindings/net/cavium-mdio.txt        |  61 +++++++-
 drivers/net/phy/Kconfig                            |  11 ++
 drivers/net/phy/Makefile                           |   1 +
 drivers/net/phy/mdio-thunder.c                     | 154 +++++++++++++++++++++
 4 files changed, 225 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/phy/mdio-thunder.c
Documentation/devicetree/bindings/net/cavium-mdio.txt +59 -2
index 04cb749..020df08 100644
@@ -1,9 +1,12 @@
 * System Management Interface (SMI) / MDIO
 
 Properties:
-- compatible: "cavium,octeon-3860-mdio"
+- compatible: One of:
 
-  Compatibility with all cn3XXX, cn5XXX and cn6XXX SOCs.
+   "cavium,octeon-3860-mdio": Compatibility with all cn3XXX, cn5XXX
+                       and cn6XXX SOCs.
+
+   "cavium,thunder-8890-mdio": Compatibility with all cn8XXX SOCs.
 
 - reg: The base address of the MDIO bus controller register bank.
 
@@ -25,3 +28,57 @@ Example:
 			reg = <0>;
 		};
 	};
+
+
+* System Management Interface (SMI) / MDIO Nexus
+
+  Several mdio buses may be gathered as children of a single PCI
+  device, this PCI device is the nexus of the buses.
+
+Properties:
+
+- compatible: "cavium,thunder-8890-mdio-nexus";
+
+- reg: The PCI device and function numbers of the nexus device.
+
+- #address-cells: Must be <2>.
+
+- #size-cells: Must be <2>.
+
+- ranges: As needed for mapping of the MDIO bus device registers.
+
+- assigned-addresses: As needed for mapping of the MDIO bus device registers.
+
+Example:
+
+        mdio-nexus at 1,3 {
+                compatible = "cavium,thunder-8890-mdio-nexus";
+                #address-cells = <2>;
+                #size-cells = <2>;
+                reg = <0x0b00 0 0 0 0>; /* DEVFN = 0x0b (1:3) */
+                assigned-addresses = <0x03000000 0x87e0 0x05000000 0x0 0x800000>;
+                ranges = <0x87e0 0x05000000 0x03000000 0x87e0 0x05000000 0x0 0x800000>;
+
+                mdio0 at 87e0,05003800 {
+                        compatible = "cavium,thunder-8890-mdio";
+                        #address-cells = <1>;
+                        #size-cells = <0>;
+                        reg = <0x87e0 0x05003800 0x0 0x30>;
+
+                        ethernet-phy at 0 {
+                                ...
+                                reg = <0>;
+                        };
+                };
+                mdio0 at 87e0,05003880 {
+                        compatible = "cavium,thunder-8890-mdio";
+                        #address-cells = <1>;
+                        #size-cells = <0>;
+                        reg = <0x87e0 0x05003880 0x0 0x30>;
+
+                        ethernet-phy at 0 {
+                                ...
+                                reg = <0>;
+                        };
+                };
+        };
drivers/net/phy/Kconfig +11 -0
index 40faec9..075a4cc 100644
@@ -196,6 +196,17 @@ config MDIO_OCTEON
 	  buses. It is required by the Octeon and ThunderX ethernet device
 	  drivers on some systems.
 
+config MDIO_THUNDER
+	tristate "Support for MDIO buses on on ThunderX SOCs"
+	depends on 64BIT
+	depends on PCI
+	select MDIO_CAVIUM
+	help
+	  This driver supports the MDIO interfaces found on Cavium
+	  ThunderX SoCs when the MDIO bus device appears on as a PCI
+	  device.
+
+
 config MDIO_SUN4I
 	tristate "Allwinner sun4i MDIO interface support"
 	depends on ARCH_SUNXI
drivers/net/phy/Makefile +1 -0
index 041b3d9..fcdbb92 100644
@@ -31,6 +31,7 @@ obj-$(CONFIG_DP83867_PHY)	+= dp83867.o
 obj-$(CONFIG_STE10XP)		+= ste10Xp.o
 obj-$(CONFIG_MICREL_PHY)	+= micrel.o
 obj-$(CONFIG_MDIO_OCTEON)	+= mdio-octeon.o
+obj-$(CONFIG_MDIO_THUNDER)	+= mdio-thunder.o
 obj-$(CONFIG_MDIO_CAVIUM)	+= mdio-cavium.o
 obj-$(CONFIG_MICREL_KS8995MA)	+= spi_ks8995.o
 obj-$(CONFIG_AT803X_PHY)	+= at803x.o
drivers/net/phy/mdio-thunder.c new file +154 -0

154 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#4 lore raw

Re: [PATCH v2 3/3] phy: mdio-thunder: Add driver for Cavium Thunder SoC MDIO buses.

Hi,

Am 11.03.2016 um 18:53 schrieb David Daney:

drivers/net/phy/Kconfig config MDIO_OCTEON · line 200

Quoted 10 lines
drivers/net/phy/Kconfig +2 -0
index 40faec9..075a4cc 100644
@@ -196,6 +196,17 @@ config MDIO_OCTEON
 	  buses. It is required by the Octeon and ThunderX ethernet device
 	  drivers on some systems.
 
+config MDIO_THUNDER
+	tristate "Support for MDIO buses on on ThunderX SOCs"

Double "on", spotted in next-20160316.

drivers/net/phy/Kconfig config MDIO_OCTEON · line 207

Quoted 7 lines
drivers/net/phy/Kconfig +7 -0
+	depends on 64BIT
+	depends on PCI
+	select MDIO_CAVIUM
+	help
+	  This driver supports the MDIO interfaces found on Cavium
+	  ThunderX SoCs when the MDIO bus device appears on as a PCI
+	  device.

While at it, this sentence sounds weird. Did you mean s/as/is/? Or is there another verb missing in there?

Regards,
Andreas

Quoted 5 lines
drivers/net/phy/Kconfig +2 -0
+
+
 config MDIO_SUN4I
 	tristate "Allwinner sun4i MDIO interface support"
 	depends on ARCH_SUNXI

[snip]

Signature · 2 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 N?rnberg, Germany
GF: Felix Imend?rffer, Jane Smithard, Graham Norton; HRB 21284 (AG N?rnberg)
#5 lore raw

Re: [PATCH v2 3/3] phy: mdio-thunder: Add driver for Cavium Thunder SoC MDIO buses.

Quoted 16 lines · Andreas F?rber

Hi,

Am 11.03.2016 um 18:53 schrieb David Daney:

drivers/net/phy/Kconfig config MDIO_OCTEON · line 200

Quoted 10 lines
drivers/net/phy/Kconfig +2 -0
index 40faec9..075a4cc 100644
@@ -196,6 +196,17 @@ config MDIO_OCTEON
  	  buses. It is required by the Octeon and ThunderX ethernet device
  	  drivers on some systems.
 
+config MDIO_THUNDER
+	tristate "Support for MDIO buses on on ThunderX SOCs"

Double "on", spotted in next-20160316.

Quoted 10 lines

drivers/net/phy/Kconfig config MDIO_OCTEON · line 207

Quoted 7 lines
drivers/net/phy/Kconfig +7 -0
+	depends on 64BIT
+	depends on PCI
+	select MDIO_CAVIUM
+	help
+	  This driver supports the MDIO interfaces found on Cavium
+	  ThunderX SoCs when the MDIO bus device appears on as a PCI
+	  device.

While at it, this sentence sounds weird. Did you mean s/as/is/? Or is there another verb missing in there?

Should be "... appears as a PCI device."

davem already merged the patch, so this would have to be fixed as a follow-on patch.

Since you found this, do you want to send the patch?

Thanks,
David Daney

Quoted 11 lines

Regards,
Andreas

Quoted 5 lines
drivers/net/phy/Kconfig +2 -0
+
+
  config MDIO_SUN4I
  	tristate "Allwinner sun4i MDIO interface support"
  	depends on ARCH_SUNXI

[snip]

#6 lore raw

Re: [PATCH v2 3/3] phy: mdio-thunder: Add driver for Cavium Thunder SoC MDIO buses.

Am 16.03.2016 um 23:54 schrieb David Daney:

Quoted 26 lines · Andreas F?rber
Quoted 22 lines

Am 11.03.2016 um 18:53 schrieb David Daney:

drivers/net/phy/Kconfig config MDIO_OCTEON · line 200

Quoted 10 lines
drivers/net/phy/Kconfig +2 -0
index 40faec9..075a4cc 100644
@@ -196,6 +196,17 @@ config MDIO_OCTEON
        buses. It is required by the Octeon and ThunderX ethernet device
        drivers on some systems.
 
+config MDIO_THUNDER
+    tristate "Support for MDIO buses on on ThunderX SOCs"

Double "on", spotted in next-20160316.

drivers/net/phy/Kconfig config MDIO_OCTEON · line 207

Quoted 7 lines
drivers/net/phy/Kconfig +7 -0
+    depends on 64BIT
+    depends on PCI
+    select MDIO_CAVIUM
+    help
+      This driver supports the MDIO interfaces found on Cavium
+      ThunderX SoCs when the MDIO bus device appears on as a PCI
+      device.
Quoted 2 lines

While at it, this sentence sounds weird. Did you mean s/as/is/? Or is there another verb missing in there?

Quoted 6 lines

Should be "... appears as a PCI device."

davem already merged the patch, so this would have to be fixed as a follow-on patch.

Since you found this, do you want to send the patch?

Done.

Cheers,
Andreas

Signature · 2 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 N?rnberg, Germany
GF: Felix Imend?rffer, Jane Smithard, Graham Norton; HRB 21284 (AG N?rnberg)
#7 lore raw
In reply to David Daney

I am going to send a new version of this set.

David Daney

Quoted 43 lines · David Daney

From: David Daney <[email protected]>

Changes from v1:

- In 1/3 Add back check for non-OF objects in bgx_init_of_phy(). It is probably not necessary, but better safe than sorry...

The firmware on many Cavium Thunder systems configures the MDIO bus hardware to be probed as a PCI device. In order to use the MDIO bus drivers in this configuration, we must add PCI probing to the driver.

There are two parts to this set of three patches:

1) Cleanup the PHY probing code in thunder_bgx.c to handle the case where there is no PHY attached to a port, as well as being more robust in the face of driver loading order by use of -EPROBE_DEFER.

2) Split mdio-octeon.c into two drivers, one with platform probing, and the other with PCI probing. Common code is shared between the two.

Tested on several different Thunder and OCTEON systems, also compile tested on x86_64.

David Daney (3):
net: thunderx: Cleanup PHY probing code.
phy: mdio-octeon: Refactor into two files/modules
phy: mdio-thunder: Add driver for Cavium Thunder SoC MDIO buses.

  .../devicetree/bindings/net/cavium-mdio.txt        |  61 ++++-
  drivers/net/ethernet/cavium/thunder/thunder_bgx.c  |  29 ++-
  drivers/net/phy/Kconfig                            |  22 +-
  drivers/net/phy/Makefile                           |   2 +
  drivers/net/phy/mdio-cavium.c                      | 149 +++++++++++
  drivers/net/phy/mdio-cavium.h                      | 119 +++++++++
  drivers/net/phy/mdio-octeon.c                      | 280 ++-------------------
  drivers/net/phy/mdio-thunder.c                     | 154 ++++++++++++
  8 files changed, 535 insertions(+), 281 deletions(-)

create mode 100644 drivers/net/phy/mdio-cavium.c create mode 100644 drivers/net/phy/mdio-cavium.h create mode 100644 drivers/net/phy/mdio-thunder.c

maintainer
#8 lore raw
In reply to David Daney

From: David Daney <[email protected]>
Date: Fri, 11 Mar 2016 09:53:08 -0800

Quoted 16 lines

Changes from v1:

- In 1/3 Add back check for non-OF objects in bgx_init_of_phy(). It is probably not necessary, but better safe than sorry...

The firmware on many Cavium Thunder systems configures the MDIO bus hardware to be probed as a PCI device. In order to use the MDIO bus drivers in this configuration, we must add PCI probing to the driver.

There are two parts to this set of three patches:

1) Cleanup the PHY probing code in thunder_bgx.c to handle the case where there is no PHY attached to a port, as well as being more robust in the face of driver loading order by use of -EPROBE_DEFER.

Quoted 6 lines

2) Split mdio-octeon.c into two drivers, one with platform probing, and the other with PCI probing. Common code is shared between the two.

Tested on several different Thunder and OCTEON systems, also compile tested on x86_64.

Series applied, thanks David.

#9 lore raw
Quoted 19 lines · David Miller

From: David Daney <[email protected]>
Date: Fri, 11 Mar 2016 09:53:08 -0800

Quoted 16 lines

Changes from v1:

- In 1/3 Add back check for non-OF objects in bgx_init_of_phy(). It is probably not necessary, but better safe than sorry...

The firmware on many Cavium Thunder systems configures the MDIO bus hardware to be probed as a PCI device. In order to use the MDIO bus drivers in this configuration, we must add PCI probing to the driver.

There are two parts to this set of three patches:

1) Cleanup the PHY probing code in thunder_bgx.c to handle the case where there is no PHY attached to a port, as well as being more robust in the face of driver loading order by use of -EPROBE_DEFER.

Quoted 8 lines
Quoted 6 lines

2) Split mdio-octeon.c into two drivers, one with platform probing, and the other with PCI probing. Common code is shared between the two.

Tested on several different Thunder and OCTEON systems, also compile tested on x86_64.

Series applied, thanks David.

Thanks, but ... I was going to send another revision.

See: https://lkml.org/lkml/2016/3/11/721

There were a couple of items I wanted to fix.

1) Missing MODULE_LICENSE() in new common code source file results in
taint warnings.

2) Fix device reference counts for -EPROBE_DEFER case.

At this point, I think the best path forward is for me to rebase against net-next and send you a small fixup set to what was merged.

What do you think?

David Daney

maintainer
#10 lore raw

From: David Daney <[email protected]>
Date: Mon, 14 Mar 2016 13:12:53 -0700

Quoted 4 lines

At this point, I think the best path forward is for me to rebase against net-next and send you a small fixup set to what was merged.

What do you think?

That is in fact the one and only option.