Skip to contentSkip to conversation

net: phy: Add xilinx gmiitorgmii converter support

PATCH In review Kedareswara rao Appana 4 participants 8 messages Aug 10, 2016 – Aug 18, 2016

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

v6 cover net: phy: Add xilinx gmiitorgmii converter support

The Gigabit Media Independent Interface (GMII) to Reduced Gigabit Media Independent Interface (RGMII) core provides the RGMII between RGMII-compliant Ethernet physical media devices (PHY) and the Gigabit Ethernet controller. This core can be used in all three modes of operation(10/100/1000 Mb/s). The Management Data Input/Output (MDIO) interface is used to configure the Speed of operation. This core can switch dynamically between the three Different speed modes by configuring the conveter register through mdio write.

The conveter sits b/w the MAC and external phy like below

MACB <==> GMII2RGMII <==> RGMII_PHY

        MDIO    <========> GMII2RGMII
MCAB <=======>
                <========> RGMII

Using MAC MDIO bus we can access both the converter and the external PHY. We need to program the line speed of the converter during run time based On the external phy negotiated speed.

This patch series does the below
---> Add mask for Control register 10Mbps speed. ---> Add support for xilinx gmiitorgmii converter.

Kedareswara rao Appana (3):
net: Add mask for Control register 10Mbps speed
Documentation: DT: net: Add Xilinx gmiitorgmii converter device tree
binding documentation
net: phy: Add gmiitorgmii converter support

 .../devicetree/bindings/net/xilinx_gmii2rgmii.txt  |  35 +++++++
 drivers/net/phy/Kconfig                            |   7 ++
 drivers/net/phy/Makefile                           |   1 +
 drivers/net/phy/xilinx_gmii2rgmii.c                | 109 +++++++++++++++++++++
 include/uapi/linux/mii.h                           |   1 +
 5 files changed, 153 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt
 create mode 100644 drivers/net/phy/xilinx_gmii2rgmii.c
Signature · 1 line
2.1.2
#1 lore raw

PATCH v6 1/3 net: Add mask for Control register 10Mbps speed

This patch adds mask for the Control register
10Mbps speed.

---
Changes for v6:
- None.
Changes for v5:
- New patch.

 include/uapi/linux/mii.h | 1 +
 1 file changed, 1 insertion(+)
include/uapi/linux/mii.h +1 -0
index 237fac4..15d8510 100644
@@ -48,6 +48,7 @@
 #define BMCR_SPEED100		0x2000	/* Select 100Mbps              */
 #define BMCR_LOOPBACK		0x4000	/* TXD loopback bits           */
 #define BMCR_RESET		0x8000	/* Reset to default state      */
+#define BMCR_SPEED10		0x0000	/* Select 10Mbps               */
 
 /* Basic mode status register. */
 #define BMSR_ERCAP		0x0001	/* Ext-reg capability          */
Signature · 1 line
2.1.2
#2 lore raw

PATCH v6 2/3 Documentation: DT: net: Add Xilinx gmiitorgmii converter device tree binding documentation

In reply to Kedareswara rao Appana

Device-tree binding documentation for xilinx gmiitorgmii converter.

---
Changes for v6:
---> Removed mdio description as suggested by Florian. Changes for v5:
---> Fixed Indentation in the example as suggested by Michal. Changes for v4:
--> Modified compatible as suggested by Rob.
--> Removed underscores from the converter node name as suggested by Rob. Changes for v3:
--> None.
Changes for v2:
--> New patch

 .../devicetree/bindings/net/xilinx_gmii2rgmii.txt  | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt
Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt new file +35 -0
new file mode 100644
index 0000000..038dda4
@@ -0,0 +1,35 @@
+XILINX GMIITORGMII Converter Driver Device Tree Bindings
+--------------------------------------------------------
+
+The Gigabit Media Independent Interface (GMII) to Reduced Gigabit Media
+Independent Interface (RGMII) core provides the RGMII between RGMII-compliant
+Ethernet physical media devices (PHY) and the Gigabit Ethernet controller.
+This core can be used in all three modes of operation(10/100/1000 Mb/s).
+The Management Data Input/Output (MDIO) interface is used to configure the
+Speed of operation. This core can switch dynamically between the three
+Different speed modes by configuring the conveter register through mdio write.
+
+This converter sits between the ethernet MAC and the external phy.
+MAC <==> GMII2RGMII <==> RGMII_PHY
+
+For more details about mdio please refer phy.txt file in the same directory.
+
+Required properties:
+- compatible	: Should be "xlnx,gmii-to-rgmii-1.0"
+- reg		: The ID number for the phy, usually a small integer
+- phy-handle	: Should point to the external phy device.
+		  See ethernet.txt file in the same directory.
+
+Example:
+	mdio {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		phy: ethernet-phy at 0 {
+			......
+		};
+		gmiitorgmii: gmiitorgmii at 8 {
+			compatible = "xlnx,gmii-to-rgmii-1.0";
+			reg = <8>;
+			phy-handle = <&phy>;
+		};
+	};
Signature · 1 line
2.1.2
maintainer Acked-by on v6 2/3
#3 lore raw

Re: [PATCH v6 2/3] Documentation: DT: net: Add Xilinx gmiitorgmii converter device tree binding documentation

Quoted 16 lines · Kedareswara rao Appana

Device-tree binding documentation for xilinx gmiitorgmii converter.

---
Changes for v6:
---> Removed mdio description as suggested by Florian. Changes for v5:
---> Fixed Indentation in the example as suggested by Michal. Changes for v4:
--> Modified compatible as suggested by Rob.
--> Removed underscores from the converter node name as suggested by Rob. Changes for v3:
--> None.
Changes for v2:
--> New patch

Quoted 3 lines
 .../devicetree/bindings/net/xilinx_gmii2rgmii.txt  | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt
#4 lore raw

PATCH v6 3/3 net: phy: Add gmiitorgmii converter support

In reply to Kedareswara rao Appana

This patch adds support for gmiitorgmii converter.

The GMII to RGMII IP core provides the Reduced Gigabit Media Independent Interface (RGMII) between Ethernet physical media Devices and the Gigabit Ethernet controller. This core can Switch dynamically between the three different speed modes of Operation by configuring the converter register through mdio write.

MDIO interface is used to set operating speed of Ethernet MAC.

This converter sits between the MAC and the external phy MAC <==> GMII2RGMII <==> RGMII_PHY

---
Thanks a lot Andrew for your inputs.
Changes for v6:
--> Don't force phy to default enabled as suggested by Florian. --> Fix Mask value as suggested by Florian.
--> Used mdio_module_driver as suggested by Florian. --> Remove switch case and used if-else conditions for phy speed
checking as suggested by Florian.
Changes for v5:
--> Fixed return values in the probe as suggested by punnaiah. --> Added a mask for the converter speed as suggested by punnaiah. Changes for v4:
--> Updated phydev speed for all 3 speeds as suggested by zhuyj. Changes for v3:
--> Updated the driver as suggested by Andrew.
Changes for v2:
--> Passed struct xphy pointer directly to the fix_mac_speed API as suggested by the Florian.
--> Added checks for the phy-node fail case as suggested by the Florian

 drivers/net/phy/Kconfig             |   7 +++
 drivers/net/phy/Makefile            |   1 +
 drivers/net/phy/xilinx_gmii2rgmii.c | 109 ++++++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+)
 create mode 100644 drivers/net/phy/xilinx_gmii2rgmii.c
drivers/net/phy/Kconfig +7 -0
index 1b534ea..d66133bf 100644
@@ -312,6 +312,13 @@ config MICROSEMI_PHY
     ---help---
       Currently supports the VSC8531 and VSC8541 PHYs
 
+config XILINX_GMII2RGMII
+       tristate "Xilinx GMII2RGMII converter driver"
+       ---help---
+         This driver support xilinx GMII to RGMII IP core it provides
+         the Reduced Gigabit Media Independent Interface(RGMII) between
+         Ethernet physical media devices and the Gigabit Ethernet controller.
+
 endif # PHYLIB
 
 config MICREL_KS8995MA
drivers/net/phy/Makefile +1 -0
index a713bd4..73d65ce 100644
@@ -50,3 +50,4 @@ obj-$(CONFIG_MDIO_BCM_IPROC)	+= mdio-bcm-iproc.o
 obj-$(CONFIG_INTEL_XWAY_PHY)	+= intel-xway.o
 obj-$(CONFIG_MDIO_HISI_FEMAC)	+= mdio-hisi-femac.o
 obj-$(CONFIG_MDIO_XGENE)	+= mdio-xgene.o
+obj-$(CONFIG_XILINX_GMII2RGMII) += xilinx_gmii2rgmii.o
drivers/net/phy/xilinx_gmii2rgmii.c new file +109 -0

109 lines not on this page · raw message

Signature · 1 line
2.1.2
maintainer
#5 lore raw

Re: [PATCH v6 3/3] net: phy: Add gmiitorgmii converter support

drivers/net/phy/xilinx_gmii2rgmii.c line 42

Quoted 6 lines
drivers/net/phy/xilinx_gmii2rgmii.c new file +6 -0
+static int xgmiitorgmii_read_status(struct phy_device *phydev)
+{
+	struct gmii2rgmii *priv = phydev->priv;
+	u16 val = 0;
+
+	priv->phy_drv->read_status(phydev);

This can return an error, in which case phydev->speed should not be trusted.

I've not thought locking all the way through yet. I don't think you need a lock here, but i need to think about it.

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	val = mdiobus_read(phydev->mdio.bus, priv->addr, XILINX_GMII2RGMII_REG);

You should check for an error here.

drivers/net/phy/xilinx_gmii2rgmii.c line 52

Quoted 8 lines
drivers/net/phy/xilinx_gmii2rgmii.c new file +8 -0
+	val &= XILINX_GMII2RGMII_SPEED_MASK;
+
+	if (phydev->speed == SPEED_1000)
+		val |= BMCR_SPEED1000;
+	else if (phydev->speed == SPEED_100)
+		val |= BMCR_SPEED100;
+	else
+		val |= BMCR_SPEED10;

What happens if for example the PHY is an aquantia and has negotiated SPEED_2500? Some Marvell PHYs can also do odd speeds, like 200Mbps. You probably want to return an error, rather than silently have things go wrong.

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	mdiobus_write(phydev->mdio.bus, priv->addr, XILINX_GMII2RGMII_REG, val);

This can also return an error.

Quoted 22 lines
drivers/net/phy/xilinx_gmii2rgmii.c new file +22 -0
+	return 0;
+}
+
+int xgmiitorgmii_probe(struct mdio_device *mdiodev)
+{
+	struct device *dev = &mdiodev->dev;
+	struct device_node *np = dev->of_node, *phy_node;
+	struct gmii2rgmii *priv;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	phy_node = of_parse_phandle(np, "phy-handle", 0);
+	if (IS_ERR(phy_node)) {
+		dev_err(dev, "Couldn't parse phy-handle\n");
+		return -ENODEV;
+	}
+
+	priv->phy_dev = of_phy_find_device(phy_node);
+	if (!priv->phy_dev) {
+		dev_info(dev, "Couldn't find phydev\n");

drivers/net/phy/xilinx_gmii2rgmii.c line 87

Quoted 10 lines
drivers/net/phy/xilinx_gmii2rgmii.c new file +10 -0
+		return -EPROBE_DEFER;
+	}
+
+	priv->addr = mdiodev->addr;
+	priv->phy_drv = priv->phy_dev->drv;
+	memcpy(&priv->conv_phy_drv, priv->phy_dev->drv,
+	       sizeof(struct phy_driver));
+	priv->conv_phy_drv.read_status = xgmiitorgmii_read_status;
+	priv->phy_dev->priv = priv;
+	priv->phy_dev->drv = &priv->conv_phy_drv;

So from this point onward, the phy driver depends on the memory allocated by this driver. If this driver goes away, freeing its memory, the next call to read_status() is going to have a problem.

Also, i think this assignment should take the phy lock, just to be safe.

There also needs to be some thought into what happens if the phy driver is unloaded. Should this driver take a reference on the phy driver to prevent that?

Andrew

#6 lore raw

RE: [PATCH v6 3/3] net: phy: Add gmiitorgmii converter support

Hi Andrew,

Thanks for the review...

Quoted 8 lines

drivers/net/phy/xilinx_gmii2rgmii.c line 42

Quoted 6 lines
drivers/net/phy/xilinx_gmii2rgmii.c new file +5 -0
+static int xgmiitorgmii_read_status(struct phy_device *phydev) {
+	struct gmii2rgmii *priv = phydev->priv;
+	u16 val = 0;
+
+	priv->phy_drv->read_status(phydev);

This can return an error, in which case phydev->speed should not be trusted.

Will fix...

Quoted 3 lines

I've not thought locking all the way through yet. I don't think you need a lock here, but i need to think about it.

Ok...

Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +3 -0
+
+	val = mdiobus_read(phydev->mdio.bus, priv->addr,
+XILINX_GMII2RGMII_REG);

You should check for an error here.

Quoted 12 lines

drivers/net/phy/xilinx_gmii2rgmii.c line 52

Quoted 8 lines
drivers/net/phy/xilinx_gmii2rgmii.c new file +8 -0
+	val &= XILINX_GMII2RGMII_SPEED_MASK;
+
+	if (phydev->speed == SPEED_1000)
+		val |= BMCR_SPEED1000;
+	else if (phydev->speed == SPEED_100)
+		val |= BMCR_SPEED100;
+	else
+		val |= BMCR_SPEED10;

What happens if for example the PHY is an aquantia and has negotiated SPEED_2500? Some Marvell PHYs can also do odd speeds, like 200Mbps. You probably want to return an error, rather than silently have things go wrong.

Will fix...

Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+
+	mdiobus_write(phydev->mdio.bus, priv->addr,

XILINX_GMII2RGMII_REG,

Quoted 1 line

+val);

This can also return an error.

Will fix...

Quoted 37 lines
Quoted 22 lines
drivers/net/phy/xilinx_gmii2rgmii.c new file +21 -0
+	return 0;
+}
+
+int xgmiitorgmii_probe(struct mdio_device *mdiodev) {
+	struct device *dev = &mdiodev->dev;
+	struct device_node *np = dev->of_node, *phy_node;
+	struct gmii2rgmii *priv;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	phy_node = of_parse_phandle(np, "phy-handle", 0);
+	if (IS_ERR(phy_node)) {
+		dev_err(dev, "Couldn't parse phy-handle\n");
+		return -ENODEV;
+	}
+
+	priv->phy_dev = of_phy_find_device(phy_node);
+	if (!priv->phy_dev) {
+		dev_info(dev, "Couldn't find phydev\n");

drivers/net/phy/xilinx_gmii2rgmii.c line 87

Quoted 10 lines
drivers/net/phy/xilinx_gmii2rgmii.c new file +10 -0
+		return -EPROBE_DEFER;
+	}
+
+	priv->addr = mdiodev->addr;
+	priv->phy_drv = priv->phy_dev->drv;
+	memcpy(&priv->conv_phy_drv, priv->phy_dev->drv,
+	       sizeof(struct phy_driver));
+	priv->conv_phy_drv.read_status = xgmiitorgmii_read_status;
+	priv->phy_dev->priv = priv;
+	priv->phy_dev->drv = &priv->conv_phy_drv;

So from this point onward, the phy driver depends on the memory allocated by this driver. If this driver goes away, freeing its memory, the next call to read_status() is going to have a problem.

Quoted 1 line

Also, i think this assignment should take the phy lock, just to be safe.

Ok will fix....

Quoted 3 lines

There also needs to be some thought into what happens if the phy driver is unloaded. Should this driver take a reference on the phy driver to prevent that?

Ok will increment the reference count of the external phy device...

Regards,
Kedar.

Quoted 2 lines

Andrew

maintainer
#7 lore raw
In reply to Kedareswara rao Appana

From: Kedareswara rao Appana <[email protected]>
Date: Wed, 10 Aug 2016 11:20:05 +0530

Quoted 16 lines

The Gigabit Media Independent Interface (GMII) to Reduced Gigabit Media Independent Interface (RGMII) core provides the RGMII between RGMII-compliant Ethernet physical media devices (PHY) and the Gigabit Ethernet controller. This core can be used in all three modes of operation(10/100/1000 Mb/s). The Management Data Input/Output (MDIO) interface is used to configure the Speed of operation. This core can switch dynamically between the three Different speed modes by configuring the conveter register through mdio write.

The conveter sits b/w the MAC and external phy like below

MACB <==> GMII2RGMII <==> RGMII_PHY

        MDIO    <========> GMII2RGMII
MCAB <=======>
                <========> RGMII
Quoted 7 lines

Using MAC MDIO bus we can access both the converter and the external PHY. We need to program the line speed of the converter during run time based On the external phy negotiated speed.

This patch series does the below
---> Add mask for Control register 10Mbps speed. ---> Add support for xilinx gmiitorgmii converter.

Series applied, thanks.