netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices
@ 2015-07-13  3:35 Punnaiah Choudary Kalluri
  2015-07-13  3:35 ` [RFC PATCH] " Punnaiah Choudary Kalluri
  2015-07-13  3:35 ` [RFC PATCH 2/2] net: macb: Add support for single mac managing more than one phy Punnaiah Choudary Kalluri
  0 siblings, 2 replies; 14+ messages in thread
From: Punnaiah Choudary Kalluri @ 2015-07-13  3:35 UTC (permalink / raw)
  To: nicolas.ferre, michals, anirudh, davem
  Cc: harinik, kpc528, kalluripunnaiahchoudary, netdev,
	Punnaiah Choudary Kalluri

This patch is to add support for the design that has multiple ethernet
mac controllers and single mdio bus connected to multiple phy devices.
i.e mdio lines are connected to any of the ethernet mac controller and
all the phy devices will be accessed using the phy maintenance interface
in that mac controller.

 ______                   _____
|      |                 |PHY0 |
| MAC0 |-----------------|     |
|______|       |         |_____|
               |           
 ______        |          _____
|      |       |         |     |
| MAC1 |       |_________|PHY1 | 
|______|                 |____ |

So, i come up with two implementations for addressing the above configuration.

Implementation 1:
 Have separate driver for mdio bus
 Create a DT node for all the PHY devices connected to the mdio bus
 This driver will share the register space of the mac controller that has
 mdio bus connected.  

Implementation 2:
 Add new property "has-mdio" and it should be 1 for the mac that has mdio bus
 connected.
 Create the mdio bus only when the has-mdio property is 1

Please review the two implementations and suggest which one is better to proceed
further. In my opinion implementation 1 will be the ideal one.

Currently i have tested the patches with single mac and single phy
configuration. I need to take care of few more cases before releasing the final patch
but before that i would like to have your opinion on the above implementations
and finalize one implementation. so that i can enhance it further.

Punnaiah Choudary Kalluri (1):
  net: macb: Add mdio driver for accessing multiple phy devices
  net: macb: Add support for single mac managing more than one phy


 drivers/net/ethernet/cadence/Makefile    |    2 +-
 drivers/net/ethernet/cadence/macb.c      |   93 +-------------
 drivers/net/ethernet/cadence/macb.h      |    3 +-
 drivers/net/ethernet/cadence/macb_mdio.c |  204 ++++++++++++++++++++++++++++++
 4 files changed, 211 insertions(+), 91 deletions(-)
 create mode 100644 drivers/net/ethernet/cadence/macb_mdio.c

-- 
1.7.4

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [RFC PATCH] net: macb: Add mdio driver for accessing multiple phy devices
  2015-07-13  3:35 [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices Punnaiah Choudary Kalluri
@ 2015-07-13  3:35 ` Punnaiah Choudary Kalluri
  2015-07-13  4:47   ` Punnaiah Choudary Kalluri
  2015-07-13  3:35 ` [RFC PATCH 2/2] net: macb: Add support for single mac managing more than one phy Punnaiah Choudary Kalluri
  1 sibling, 1 reply; 14+ messages in thread
From: Punnaiah Choudary Kalluri @ 2015-07-13  3:35 UTC (permalink / raw)
  To: nicolas.ferre, michals, anirudh, davem
  Cc: harinik, kpc528, kalluripunnaiahchoudary, netdev,
	Punnaiah Choudary Kalluri

This patch is to add spoort for the design that has multiple ethernet
mac controllers and single mdio bus connected to multiple phy devices.
i.e mdio lines are connected to any of the ethernet mac controller and
all the phy devices will be accessed using the phy maintainance interface
in that mac controller.

Signed-off-by: Punnaiah Choudary Kalluri <punnaia@xilinx.com>
---
 drivers/net/ethernet/cadence/Makefile    |    2 +-
 drivers/net/ethernet/cadence/macb.c      |   93 +-------------
 drivers/net/ethernet/cadence/macb.h      |    3 +-
 drivers/net/ethernet/cadence/macb_mdio.c |  204 ++++++++++++++++++++++++++++++
 4 files changed, 211 insertions(+), 91 deletions(-)
 create mode 100644 drivers/net/ethernet/cadence/macb_mdio.c

diff --git a/drivers/net/ethernet/cadence/Makefile b/drivers/net/ethernet/cadence/Makefile
index 9068b83..73504f4 100644
--- a/drivers/net/ethernet/cadence/Makefile
+++ b/drivers/net/ethernet/cadence/Makefile
@@ -3,4 +3,4 @@
 #
 
 obj-$(CONFIG_ARM_AT91_ETHER) += at91_ether.o
-obj-$(CONFIG_MACB) += macb.o
+obj-$(CONFIG_MACB) += macb.o macb_mdio.o
diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index 4833ba1..df1b928 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -320,7 +320,7 @@ static int macb_mii_probe(struct net_device *dev)
 	int phy_irq;
 	int ret;
 
-	phydev = phy_find_first(bp->mii_bus);
+	phydev = of_phy_find_device(bp->phy_node);
 	if (!phydev) {
 		netdev_err(dev, "no PHY found\n");
 		return -ENXIO;
@@ -359,89 +359,6 @@ static int macb_mii_probe(struct net_device *dev)
 	return 0;
 }
 
-int macb_mii_init(struct macb *bp)
-{
-	struct macb_platform_data *pdata;
-	struct device_node *np;
-	int err = -ENXIO, i;
-
-	/* Enable management port */
-	macb_writel(bp, NCR, MACB_BIT(MPE));
-
-	bp->mii_bus = mdiobus_alloc();
-	if (bp->mii_bus == NULL) {
-		err = -ENOMEM;
-		goto err_out;
-	}
-
-	bp->mii_bus->name = "MACB_mii_bus";
-	bp->mii_bus->read = &macb_mdio_read;
-	bp->mii_bus->write = &macb_mdio_write;
-	snprintf(bp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
-		bp->pdev->name, bp->pdev->id);
-	bp->mii_bus->priv = bp;
-	bp->mii_bus->parent = &bp->dev->dev;
-	pdata = dev_get_platdata(&bp->pdev->dev);
-
-	bp->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
-	if (!bp->mii_bus->irq) {
-		err = -ENOMEM;
-		goto err_out_free_mdiobus;
-	}
-
-	dev_set_drvdata(&bp->dev->dev, bp->mii_bus);
-
-	np = bp->pdev->dev.of_node;
-	if (np) {
-		/* try dt phy registration */
-		err = of_mdiobus_register(bp->mii_bus, np);
-
-		/* fallback to standard phy registration if no phy were
-		   found during dt phy registration */
-		if (!err && !phy_find_first(bp->mii_bus)) {
-			for (i = 0; i < PHY_MAX_ADDR; i++) {
-				struct phy_device *phydev;
-
-				phydev = mdiobus_scan(bp->mii_bus, i);
-				if (IS_ERR(phydev)) {
-					err = PTR_ERR(phydev);
-					break;
-				}
-			}
-
-			if (err)
-				goto err_out_unregister_bus;
-		}
-	} else {
-		for (i = 0; i < PHY_MAX_ADDR; i++)
-			bp->mii_bus->irq[i] = PHY_POLL;
-
-		if (pdata)
-			bp->mii_bus->phy_mask = pdata->phy_mask;
-
-		err = mdiobus_register(bp->mii_bus);
-	}
-
-	if (err)
-		goto err_out_free_mdio_irq;
-
-	err = macb_mii_probe(bp->dev);
-	if (err)
-		goto err_out_unregister_bus;
-
-	return 0;
-
-err_out_unregister_bus:
-	mdiobus_unregister(bp->mii_bus);
-err_out_free_mdio_irq:
-	kfree(bp->mii_bus->irq);
-err_out_free_mdiobus:
-	mdiobus_free(bp->mii_bus);
-err_out:
-	return err;
-}
-EXPORT_SYMBOL_GPL(macb_mii_init);
-
 static void macb_update_stats(struct macb *bp)
 {
 	u32 __iomem *reg = bp->regs + MACB_PFR;
@@ -2480,7 +2397,10 @@ static int macb_probe(struct platform_device *pdev)
 		goto err_out_free_netdev;
 	}
 
-	err = macb_mii_init(bp);
+	bp->phy_node = of_parse_phandle(bp->pdev->dev.of_node,
+						"phy-handle", 0);
+
+	err = macb_mii_probe(bp->dev);
 	if (err)
 		goto err_out_unregister_netdev;
 
@@ -2524,9 +2444,6 @@ static int macb_remove(struct platform_device *pdev)
 		bp = netdev_priv(dev);
 		if (bp->phy_dev)
 			phy_disconnect(bp->phy_dev);
-		mdiobus_unregister(bp->mii_bus);
-		kfree(bp->mii_bus->irq);
-		mdiobus_free(bp->mii_bus);
 		unregister_netdev(dev);
 		if (!IS_ERR(bp->tx_clk))
 			clk_disable_unprepare(bp->tx_clk);
diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
index f0aa177..ba515ab 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -825,13 +825,12 @@ struct macb {
 	unsigned int		rx_frm_len_mask;
 	unsigned int		jumbo_max_len;
 	bool			isjumbo;
-
+	struct device_node *phy_node;
 	u64			ethtool_stats[GEM_STATS_LEN];
 };
 
 extern const struct ethtool_ops macb_ethtool_ops;
 
-int macb_mii_init(struct macb *bp);
 int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 struct net_device_stats *macb_get_stats(struct net_device *dev);
 void macb_set_rx_mode(struct net_device *dev);
diff --git a/drivers/net/ethernet/cadence/macb_mdio.c b/drivers/net/ethernet/cadence/macb_mdio.c
new file mode 100644
index 0000000..563ac52
--- /dev/null
+++ b/drivers/net/ethernet/cadence/macb_mdio.c
@@ -0,0 +1,204 @@
+/*
+ * Cadence Macb mdio controller driver
+ *
+ * Copyright (C) 2014 - 2015 Xilinx, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/netdevice.h>
+#include <linux/of_address.h>
+#include <linux/of_mdio.h>
+#include <linux/phy.h>
+#include <linux/platform_device.h>
+#include "macb.h"
+
+struct macb_mdio_data {
+	void __iomem *regs;
+	struct clk *pclk;
+	struct clk *hclk;
+};
+
+static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
+{
+	struct macb_mdio_data *bp = bus->priv;
+	int value;
+
+	macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
+			      | MACB_BF(RW, MACB_MAN_READ)
+			      | MACB_BF(PHYA, mii_id)
+			      | MACB_BF(REGA, regnum)
+			      | MACB_BF(CODE, MACB_MAN_CODE)));
+
+	/* wait for end of transfer */
+	while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
+		cpu_relax();
+
+	value = MACB_BFEXT(DATA, macb_readl(bp, MAN));
+
+	return value;
+}
+
+static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
+			   u16 value)
+{
+	struct macb_mdio_data *bp = bus->priv;
+
+	macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
+			      | MACB_BF(RW, MACB_MAN_WRITE)
+			      | MACB_BF(PHYA, mii_id)
+			      | MACB_BF(REGA, regnum)
+			      | MACB_BF(CODE, MACB_MAN_CODE)
+			      | MACB_BF(DATA, value)));
+
+	/* wait for end of transfer */
+	while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
+		cpu_relax();
+
+	return 0;
+}
+
+static u32 gem_mdc_clk_div(struct macb_mdio_data *bp)
+{
+	u32 config;
+	unsigned long pclk_hz = clk_get_rate(bp->pclk);
+
+	if (pclk_hz <= 20000000)
+		config = GEM_BF(CLK, GEM_CLK_DIV8);
+	else if (pclk_hz <= 40000000)
+		config = GEM_BF(CLK, GEM_CLK_DIV16);
+	else if (pclk_hz <= 80000000)
+		config = GEM_BF(CLK, GEM_CLK_DIV32);
+	else if (pclk_hz <= 120000000)
+		config = GEM_BF(CLK, GEM_CLK_DIV48);
+	else if (pclk_hz <= 160000000)
+		config = GEM_BF(CLK, GEM_CLK_DIV64);
+	else
+		config = GEM_BF(CLK, GEM_CLK_DIV96);
+
+	return config;
+}
+
+static int macb_mdio_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct mii_bus *bus;
+	struct macb_mdio_data *bp;
+	struct resource *res;
+	int ret;
+	u32 config, i;
+
+	bus = mdiobus_alloc_size(sizeof(*bp));
+	if (!bus)
+		return -ENOMEM;
+
+	bus->name = "macb_mii_bus";
+	bus->read = &macb_mdio_read;
+	bus->write = &macb_mdio_write;
+	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(&pdev->dev));
+	bus->parent = &pdev->dev;
+	bus->irq = devm_kzalloc(&pdev->dev, sizeof(int) * PHY_MAX_ADDR,
+				GFP_KERNEL);
+	if (!bus->irq) {
+		ret = -ENOMEM;
+		goto err_out_free_mdiobus;
+	}
+
+	for (i = 0; i < PHY_MAX_ADDR; i++)
+		bus->irq[i] = PHY_POLL;
+
+	bp = bus->priv;
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	bp->regs = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(bp->regs)) {
+		ret = PTR_ERR(bp->regs);
+		goto err_out_free_mdiobus;
+	}
+
+	bp->pclk = devm_clk_get(&pdev->dev, "pclk");
+	if (IS_ERR(bp->pclk)) {
+		ret = PTR_ERR(bp->pclk);
+		dev_err(&pdev->dev, "failed to get macb_clk (%u)\n", ret);
+		goto err_out_free_mdiobus;
+	}
+
+	bp->hclk = devm_clk_get(&pdev->dev, "hclk");
+	if (IS_ERR(bp->hclk)) {
+		ret = PTR_ERR(bp->hclk);
+		dev_err(&pdev->dev, "failed to get hclk (%u)\n", ret);
+		goto err_out_free_mdiobus;
+	}
+
+	ret = clk_prepare_enable(bp->pclk);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to enable pclk (%u)\n", ret);
+		goto err_out_free_mdiobus;
+	}
+
+	ret = clk_prepare_enable(bp->hclk);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to enable hclk (%u)\n", ret);
+		goto err_disable_pclk;
+	}
+
+	/* Enable management port */
+	macb_writel(bp, NCR, MACB_BIT(MPE));
+	config = gem_mdc_clk_div(bp);
+	macb_writel(bp, NCFGR, config);
+
+	ret = of_mdiobus_register(bus, np);
+	if (ret < 0)
+		goto err_out_free_mdiobus;
+
+	platform_set_drvdata(pdev, bus);
+
+	return 0;
+
+err_disable_pclk:
+	clk_disable_unprepare(bp->pclk);
+
+err_out_free_mdiobus:
+	mdiobus_free(bus);
+	return ret;
+}
+
+static int macb_mdio_remove(struct platform_device *pdev)
+{
+	struct mii_bus *bus = platform_get_drvdata(pdev);
+	struct macb_mdio_data *bp = bus->priv;
+
+	mdiobus_unregister(bus);
+	clk_disable_unprepare(bp->hclk);
+	clk_disable_unprepare(bp->pclk);
+	mdiobus_free(bus);
+
+	return 0;
+}
+
+static const struct of_device_id macb_mdio_dt_ids[] = {
+	{ .compatible = "cdns,macb-mdio" },
+
+};
+MODULE_DEVICE_TABLE(of, macb_mdio_dt_ids);
+
+static struct platform_driver macb_mdio_driver = {
+	.probe = macb_mdio_probe,
+	.remove = macb_mdio_remove,
+	.driver = {
+		.name = "macb-mdio",
+		.of_match_table = macb_mdio_dt_ids,
+	},
+};
+
+module_platform_driver(macb_mdio_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Cadence MACB/GEM Ethernet driver");
+MODULE_AUTHOR("Xilinx");
-- 
1.7.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [RFC PATCH 2/2] net: macb: Add support for single mac managing more than one phy
  2015-07-13  3:35 [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices Punnaiah Choudary Kalluri
  2015-07-13  3:35 ` [RFC PATCH] " Punnaiah Choudary Kalluri
@ 2015-07-13  3:35 ` Punnaiah Choudary Kalluri
  1 sibling, 0 replies; 14+ messages in thread
From: Punnaiah Choudary Kalluri @ 2015-07-13  3:35 UTC (permalink / raw)
  To: nicolas.ferre, michals, anirudh, davem
  Cc: harinik, kpc528, kalluripunnaiahchoudary, netdev,
	Punnaiah Choudary Kalluri

Added support for single mac managing more than one phy

Signed-off-by: Punnaiah Choudary Kalluri <punnaia@xilinx.com>
---
 drivers/net/ethernet/cadence/macb.c |   25 ++++++++++++++++++++-----
 drivers/net/ethernet/cadence/macb.h |    4 +++-
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index 4833ba1..6d36b76 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -171,6 +171,7 @@ static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
 	struct macb *bp = bus->priv;
 	int value;
 
+	spin_lock(&bp->mdio_lock);
 	macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
 			      | MACB_BF(RW, MACB_MAN_READ)
 			      | MACB_BF(PHYA, mii_id)
@@ -182,6 +183,7 @@ static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
 		cpu_relax();
 
 	value = MACB_BFEXT(DATA, macb_readl(bp, MAN));
+	spin_unlock(&bp->mdio_lock);
 
 	return value;
 }
@@ -191,6 +193,7 @@ static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
 {
 	struct macb *bp = bus->priv;
 
+	spin_lock(&bp->mdio_lock);
 	macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
 			      | MACB_BF(RW, MACB_MAN_WRITE)
 			      | MACB_BF(PHYA, mii_id)
@@ -201,6 +204,7 @@ static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
 	/* wait for end of transfer */
 	while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
 		cpu_relax();
+	spin_unlock(&bp->mdio_lock);
 
 	return 0;
 }
@@ -320,7 +324,7 @@ static int macb_mii_probe(struct net_device *dev)
 	int phy_irq;
 	int ret;
 
-	phydev = phy_find_first(bp->mii_bus);
+	phydev = of_phy_find_device(bp->phy_node);
 	if (!phydev) {
 		netdev_err(dev, "no PHY found\n");
 		return -ENXIO;
@@ -365,8 +369,14 @@ int macb_mii_init(struct macb *bp)
 	struct device_node *np;
 	int err = -ENXIO, i;
 
+	bp->phy_node = of_parse_phandle(bp->pdev->dev.of_node,
+						"phy-handle", 0);
+	np = of_get_parent(bp->phy_node);
 	/* Enable management port */
 	macb_writel(bp, NCR, MACB_BIT(MPE));
+	bp->mii_bus = of_mdio_find_bus(np);
+	if (!bp->has_mdio && bp->mii_bus)
+		goto mii_probe;
 
 	bp->mii_bus = mdiobus_alloc();
 	if (bp->mii_bus == NULL) {
@@ -425,6 +435,7 @@ int macb_mii_init(struct macb *bp)
 	if (err)
 		goto err_out_free_mdio_irq;
 
+mii_probe:
 	err = macb_mii_probe(bp->dev);
 	if (err)
 		goto err_out_unregister_bus;
@@ -2356,6 +2367,7 @@ static int macb_probe(struct platform_device *pdev)
 	bp->isjumbo = of_property_read_bool(pdev->dev.of_node,
 					    "jumbo-supported");
 	spin_lock_init(&bp->lock);
+	spin_lock_init(&bp->mdio_lock);
 
 	/* set the queue register mapping once for all: queue0 has a special
 	 * register mapping but we don't want to test the queue index then
@@ -2479,7 +2491,8 @@ static int macb_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "Cannot register net device, aborting.\n");
 		goto err_out_free_netdev;
 	}
-
+	err = of_property_read_u32(bp->pdev->dev.of_node, "has-mdio",
+							&bp->has_mdio);
 	err = macb_mii_init(bp);
 	if (err)
 		goto err_out_unregister_netdev;
@@ -2524,9 +2537,11 @@ static int macb_remove(struct platform_device *pdev)
 		bp = netdev_priv(dev);
 		if (bp->phy_dev)
 			phy_disconnect(bp->phy_dev);
-		mdiobus_unregister(bp->mii_bus);
-		kfree(bp->mii_bus->irq);
-		mdiobus_free(bp->mii_bus);
+		if (bp->has_mdio) {
+			mdiobus_unregister(bp->mii_bus);
+			kfree(bp->mii_bus->irq);
+			mdiobus_free(bp->mii_bus);
+		}
 		unregister_netdev(dev);
 		if (!IS_ERR(bp->tx_clk))
 			clk_disable_unprepare(bp->tx_clk);
diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
index f0aa177..0f99f2a 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -825,7 +825,9 @@ struct macb {
 	unsigned int		rx_frm_len_mask;
 	unsigned int		jumbo_max_len;
 	bool			isjumbo;
-
+	unsigned int has_mdio;
+	spinlock_t mdio_lock;
+	struct device_node *phy_node;
 	u64			ethtool_stats[GEM_STATS_LEN];
 };
 
-- 
1.7.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* RE: [RFC PATCH] net: macb: Add mdio driver for accessing multiple phy devices
  2015-07-13  3:35 ` [RFC PATCH] " Punnaiah Choudary Kalluri
@ 2015-07-13  4:47   ` Punnaiah Choudary Kalluri
  0 siblings, 0 replies; 14+ messages in thread
From: Punnaiah Choudary Kalluri @ 2015-07-13  4:47 UTC (permalink / raw)
  To: Punnaiah Choudary Kalluri, nicolas.ferre, Michal Simek,
	Anirudha Sarangi, davem
  Cc: Harini Katakam, kpc528, kalluripunnaiahchoudary, netdev

Please ignore this patch series.

Regards,
Punnaiah

> -----Original Message-----
> From: Punnaiah Choudary Kalluri
> [mailto:punnaiah.choudary.kalluri@xilinx.com]
> Sent: Monday, July 13, 2015 9:06 AM
> To: nicolas.ferre@atmel.com; Michal Simek; Anirudha Sarangi;
> davem@davemloft.net
> Cc: Harini Katakam; kpc528@gmail.com;
> kalluripunnaiahchoudary@gmail.com; netdev@vger.kernel.org; Punnaiah
> Choudary Kalluri
> Subject: [RFC PATCH] net: macb: Add mdio driver for accessing multiple phy
> devices
> 
> This patch is to add spoort for the design that has multiple ethernet
> mac controllers and single mdio bus connected to multiple phy devices.
> i.e mdio lines are connected to any of the ethernet mac controller and
> all the phy devices will be accessed using the phy maintainance interface
> in that mac controller.
> 
> Signed-off-by: Punnaiah Choudary Kalluri <punnaia@xilinx.com>
> ---
>  drivers/net/ethernet/cadence/Makefile    |    2 +-
>  drivers/net/ethernet/cadence/macb.c      |   93 +-------------
>  drivers/net/ethernet/cadence/macb.h      |    3 +-
>  drivers/net/ethernet/cadence/macb_mdio.c |  204
> ++++++++++++++++++++++++++++++
>  4 files changed, 211 insertions(+), 91 deletions(-)
>  create mode 100644 drivers/net/ethernet/cadence/macb_mdio.c
> 
> diff --git a/drivers/net/ethernet/cadence/Makefile
> b/drivers/net/ethernet/cadence/Makefile
> index 9068b83..73504f4 100644
> --- a/drivers/net/ethernet/cadence/Makefile
> +++ b/drivers/net/ethernet/cadence/Makefile
> @@ -3,4 +3,4 @@
>  #
> 
>  obj-$(CONFIG_ARM_AT91_ETHER) += at91_ether.o
> -obj-$(CONFIG_MACB) += macb.o
> +obj-$(CONFIG_MACB) += macb.o macb_mdio.o
> diff --git a/drivers/net/ethernet/cadence/macb.c
> b/drivers/net/ethernet/cadence/macb.c
> index 4833ba1..df1b928 100644
> --- a/drivers/net/ethernet/cadence/macb.c
> +++ b/drivers/net/ethernet/cadence/macb.c
> @@ -320,7 +320,7 @@ static int macb_mii_probe(struct net_device *dev)
>  	int phy_irq;
>  	int ret;
> 
> -	phydev = phy_find_first(bp->mii_bus);
> +	phydev = of_phy_find_device(bp->phy_node);
>  	if (!phydev) {
>  		netdev_err(dev, "no PHY found\n");
>  		return -ENXIO;
> @@ -359,89 +359,6 @@ static int macb_mii_probe(struct net_device *dev)
>  	return 0;
>  }
> 
> -int macb_mii_init(struct macb *bp)
> -{
> -	struct macb_platform_data *pdata;
> -	struct device_node *np;
> -	int err = -ENXIO, i;
> -
> -	/* Enable management port */
> -	macb_writel(bp, NCR, MACB_BIT(MPE));
> -
> -	bp->mii_bus = mdiobus_alloc();
> -	if (bp->mii_bus == NULL) {
> -		err = -ENOMEM;
> -		goto err_out;
> -	}
> -
> -	bp->mii_bus->name = "MACB_mii_bus";
> -	bp->mii_bus->read = &macb_mdio_read;
> -	bp->mii_bus->write = &macb_mdio_write;
> -	snprintf(bp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
> -		bp->pdev->name, bp->pdev->id);
> -	bp->mii_bus->priv = bp;
> -	bp->mii_bus->parent = &bp->dev->dev;
> -	pdata = dev_get_platdata(&bp->pdev->dev);
> -
> -	bp->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR,
> GFP_KERNEL);
> -	if (!bp->mii_bus->irq) {
> -		err = -ENOMEM;
> -		goto err_out_free_mdiobus;
> -	}
> -
> -	dev_set_drvdata(&bp->dev->dev, bp->mii_bus);
> -
> -	np = bp->pdev->dev.of_node;
> -	if (np) {
> -		/* try dt phy registration */
> -		err = of_mdiobus_register(bp->mii_bus, np);
> -
> -		/* fallback to standard phy registration if no phy were
> -		   found during dt phy registration */
> -		if (!err && !phy_find_first(bp->mii_bus)) {
> -			for (i = 0; i < PHY_MAX_ADDR; i++) {
> -				struct phy_device *phydev;
> -
> -				phydev = mdiobus_scan(bp->mii_bus, i);
> -				if (IS_ERR(phydev)) {
> -					err = PTR_ERR(phydev);
> -					break;
> -				}
> -			}
> -
> -			if (err)
> -				goto err_out_unregister_bus;
> -		}
> -	} else {
> -		for (i = 0; i < PHY_MAX_ADDR; i++)
> -			bp->mii_bus->irq[i] = PHY_POLL;
> -
> -		if (pdata)
> -			bp->mii_bus->phy_mask = pdata->phy_mask;
> -
> -		err = mdiobus_register(bp->mii_bus);
> -	}
> -
> -	if (err)
> -		goto err_out_free_mdio_irq;
> -
> -	err = macb_mii_probe(bp->dev);
> -	if (err)
> -		goto err_out_unregister_bus;
> -
> -	return 0;
> -
> -err_out_unregister_bus:
> -	mdiobus_unregister(bp->mii_bus);
> -err_out_free_mdio_irq:
> -	kfree(bp->mii_bus->irq);
> -err_out_free_mdiobus:
> -	mdiobus_free(bp->mii_bus);
> -err_out:
> -	return err;
> -}
> -EXPORT_SYMBOL_GPL(macb_mii_init);
> -
>  static void macb_update_stats(struct macb *bp)
>  {
>  	u32 __iomem *reg = bp->regs + MACB_PFR;
> @@ -2480,7 +2397,10 @@ static int macb_probe(struct platform_device
> *pdev)
>  		goto err_out_free_netdev;
>  	}
> 
> -	err = macb_mii_init(bp);
> +	bp->phy_node = of_parse_phandle(bp->pdev->dev.of_node,
> +						"phy-handle", 0);
> +
> +	err = macb_mii_probe(bp->dev);
>  	if (err)
>  		goto err_out_unregister_netdev;
> 
> @@ -2524,9 +2444,6 @@ static int macb_remove(struct platform_device
> *pdev)
>  		bp = netdev_priv(dev);
>  		if (bp->phy_dev)
>  			phy_disconnect(bp->phy_dev);
> -		mdiobus_unregister(bp->mii_bus);
> -		kfree(bp->mii_bus->irq);
> -		mdiobus_free(bp->mii_bus);
>  		unregister_netdev(dev);
>  		if (!IS_ERR(bp->tx_clk))
>  			clk_disable_unprepare(bp->tx_clk);
> diff --git a/drivers/net/ethernet/cadence/macb.h
> b/drivers/net/ethernet/cadence/macb.h
> index f0aa177..ba515ab 100644
> --- a/drivers/net/ethernet/cadence/macb.h
> +++ b/drivers/net/ethernet/cadence/macb.h
> @@ -825,13 +825,12 @@ struct macb {
>  	unsigned int		rx_frm_len_mask;
>  	unsigned int		jumbo_max_len;
>  	bool			isjumbo;
> -
> +	struct device_node *phy_node;
>  	u64			ethtool_stats[GEM_STATS_LEN];
>  };
> 
>  extern const struct ethtool_ops macb_ethtool_ops;
> 
> -int macb_mii_init(struct macb *bp);
>  int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
>  struct net_device_stats *macb_get_stats(struct net_device *dev);
>  void macb_set_rx_mode(struct net_device *dev);
> diff --git a/drivers/net/ethernet/cadence/macb_mdio.c
> b/drivers/net/ethernet/cadence/macb_mdio.c
> new file mode 100644
> index 0000000..563ac52
> --- /dev/null
> +++ b/drivers/net/ethernet/cadence/macb_mdio.c
> @@ -0,0 +1,204 @@
> +/*
> + * Cadence Macb mdio controller driver
> + *
> + * Copyright (C) 2014 - 2015 Xilinx, Inc.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> under
> + * the terms of the GNU General Public License version 2 as published by
> the
> + * Free Software Foundation; either version 2 of the License, or (at your
> + * option) any later version.
> + */
> +#include <linux/clk.h>
> +#include <linux/delay.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/netdevice.h>
> +#include <linux/of_address.h>
> +#include <linux/of_mdio.h>
> +#include <linux/phy.h>
> +#include <linux/platform_device.h>
> +#include "macb.h"
> +
> +struct macb_mdio_data {
> +	void __iomem *regs;
> +	struct clk *pclk;
> +	struct clk *hclk;
> +};
> +
> +static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
> +{
> +	struct macb_mdio_data *bp = bus->priv;
> +	int value;
> +
> +	macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
> +			      | MACB_BF(RW, MACB_MAN_READ)
> +			      | MACB_BF(PHYA, mii_id)
> +			      | MACB_BF(REGA, regnum)
> +			      | MACB_BF(CODE, MACB_MAN_CODE)));
> +
> +	/* wait for end of transfer */
> +	while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
> +		cpu_relax();
> +
> +	value = MACB_BFEXT(DATA, macb_readl(bp, MAN));
> +
> +	return value;
> +}
> +
> +static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
> +			   u16 value)
> +{
> +	struct macb_mdio_data *bp = bus->priv;
> +
> +	macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
> +			      | MACB_BF(RW, MACB_MAN_WRITE)
> +			      | MACB_BF(PHYA, mii_id)
> +			      | MACB_BF(REGA, regnum)
> +			      | MACB_BF(CODE, MACB_MAN_CODE)
> +			      | MACB_BF(DATA, value)));
> +
> +	/* wait for end of transfer */
> +	while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
> +		cpu_relax();
> +
> +	return 0;
> +}
> +
> +static u32 gem_mdc_clk_div(struct macb_mdio_data *bp)
> +{
> +	u32 config;
> +	unsigned long pclk_hz = clk_get_rate(bp->pclk);
> +
> +	if (pclk_hz <= 20000000)
> +		config = GEM_BF(CLK, GEM_CLK_DIV8);
> +	else if (pclk_hz <= 40000000)
> +		config = GEM_BF(CLK, GEM_CLK_DIV16);
> +	else if (pclk_hz <= 80000000)
> +		config = GEM_BF(CLK, GEM_CLK_DIV32);
> +	else if (pclk_hz <= 120000000)
> +		config = GEM_BF(CLK, GEM_CLK_DIV48);
> +	else if (pclk_hz <= 160000000)
> +		config = GEM_BF(CLK, GEM_CLK_DIV64);
> +	else
> +		config = GEM_BF(CLK, GEM_CLK_DIV96);
> +
> +	return config;
> +}
> +
> +static int macb_mdio_probe(struct platform_device *pdev)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	struct mii_bus *bus;
> +	struct macb_mdio_data *bp;
> +	struct resource *res;
> +	int ret;
> +	u32 config, i;
> +
> +	bus = mdiobus_alloc_size(sizeof(*bp));
> +	if (!bus)
> +		return -ENOMEM;
> +
> +	bus->name = "macb_mii_bus";
> +	bus->read = &macb_mdio_read;
> +	bus->write = &macb_mdio_write;
> +	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(&pdev-
> >dev));
> +	bus->parent = &pdev->dev;
> +	bus->irq = devm_kzalloc(&pdev->dev, sizeof(int) * PHY_MAX_ADDR,
> +				GFP_KERNEL);
> +	if (!bus->irq) {
> +		ret = -ENOMEM;
> +		goto err_out_free_mdiobus;
> +	}
> +
> +	for (i = 0; i < PHY_MAX_ADDR; i++)
> +		bus->irq[i] = PHY_POLL;
> +
> +	bp = bus->priv;
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	bp->regs = devm_ioremap_resource(&pdev->dev, res);
> +	if (IS_ERR(bp->regs)) {
> +		ret = PTR_ERR(bp->regs);
> +		goto err_out_free_mdiobus;
> +	}
> +
> +	bp->pclk = devm_clk_get(&pdev->dev, "pclk");
> +	if (IS_ERR(bp->pclk)) {
> +		ret = PTR_ERR(bp->pclk);
> +		dev_err(&pdev->dev, "failed to get macb_clk (%u)\n", ret);
> +		goto err_out_free_mdiobus;
> +	}
> +
> +	bp->hclk = devm_clk_get(&pdev->dev, "hclk");
> +	if (IS_ERR(bp->hclk)) {
> +		ret = PTR_ERR(bp->hclk);
> +		dev_err(&pdev->dev, "failed to get hclk (%u)\n", ret);
> +		goto err_out_free_mdiobus;
> +	}
> +
> +	ret = clk_prepare_enable(bp->pclk);
> +	if (ret) {
> +		dev_err(&pdev->dev, "failed to enable pclk (%u)\n", ret);
> +		goto err_out_free_mdiobus;
> +	}
> +
> +	ret = clk_prepare_enable(bp->hclk);
> +	if (ret) {
> +		dev_err(&pdev->dev, "failed to enable hclk (%u)\n", ret);
> +		goto err_disable_pclk;
> +	}
> +
> +	/* Enable management port */
> +	macb_writel(bp, NCR, MACB_BIT(MPE));
> +	config = gem_mdc_clk_div(bp);
> +	macb_writel(bp, NCFGR, config);
> +
> +	ret = of_mdiobus_register(bus, np);
> +	if (ret < 0)
> +		goto err_out_free_mdiobus;
> +
> +	platform_set_drvdata(pdev, bus);
> +
> +	return 0;
> +
> +err_disable_pclk:
> +	clk_disable_unprepare(bp->pclk);
> +
> +err_out_free_mdiobus:
> +	mdiobus_free(bus);
> +	return ret;
> +}
> +
> +static int macb_mdio_remove(struct platform_device *pdev)
> +{
> +	struct mii_bus *bus = platform_get_drvdata(pdev);
> +	struct macb_mdio_data *bp = bus->priv;
> +
> +	mdiobus_unregister(bus);
> +	clk_disable_unprepare(bp->hclk);
> +	clk_disable_unprepare(bp->pclk);
> +	mdiobus_free(bus);
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id macb_mdio_dt_ids[] = {
> +	{ .compatible = "cdns,macb-mdio" },
> +
> +};
> +MODULE_DEVICE_TABLE(of, macb_mdio_dt_ids);
> +
> +static struct platform_driver macb_mdio_driver = {
> +	.probe = macb_mdio_probe,
> +	.remove = macb_mdio_remove,
> +	.driver = {
> +		.name = "macb-mdio",
> +		.of_match_table = macb_mdio_dt_ids,
> +	},
> +};
> +
> +module_platform_driver(macb_mdio_driver);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_DESCRIPTION("Cadence MACB/GEM Ethernet driver");
> +MODULE_AUTHOR("Xilinx");
> --
> 1.7.4

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices
  2015-07-31 21:53       ` Nathan Sullivan
@ 2015-08-03  6:01         ` Michal Simek
  0 siblings, 0 replies; 14+ messages in thread
From: Michal Simek @ 2015-08-03  6:01 UTC (permalink / raw)
  To: Nathan Sullivan, Punnaiah Choudary Kalluri
  Cc: Nicolas Ferre, Anirudha Sarangi, davem, Florian Fainelli, andrew,
	Harini Katakam, kpc528, kalluripunnaiahchoudary, netdev

Hi,

On 07/31/2015 11:53 PM, Nathan Sullivan wrote:
> On Tue, Jul 28, 2015 at 03:34:51AM +0000, Punnaiah Choudary Kalluri wrote:
>> Ok. I will send you updated patch for mdio support soon and we will finalize next
>> Course of actions if it doesn't break the existing flow. 
>>
>> Thanks,
>> Punnaiah
> 
> Just a heads up, when mdio no longer turns off when macb goes down, the micrel
> 9031 phy will have an issue with interrupts getting disabling during phy
> suspend.  I have a patch to correct this issue here:
> 
> https://patchwork.ozlabs.org/patch/502189/
> 
> Would you mind including this patch in your set?

You should resend the patch again and you got one more argument why this
patch should go it. But it should go in own direction out of this patch.

Thanks,
Michal

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices
  2015-07-28  3:34     ` Punnaiah Choudary Kalluri
  2015-07-31 21:53       ` Nathan Sullivan
@ 2015-07-31 21:58       ` Nathan Sullivan
  1 sibling, 0 replies; 14+ messages in thread
From: Nathan Sullivan @ 2015-07-31 21:58 UTC (permalink / raw)
  To: Punnaiah Choudary Kalluri
  Cc: Nicolas Ferre, Michal Simek, Anirudha Sarangi, davem,
	Florian Fainelli, andrew, Harini Katakam, kpc528,
	kalluripunnaiahchoudary, netdev

On Tue, Jul 28, 2015 at 03:34:51AM +0000, Punnaiah Choudary Kalluri wrote:
> 
> Ok. I will send you updated patch for mdio support soon and we will finalize next
> Course of actions if it doesn't break the existing flow. 
> 
> Thanks,
> Punnaiah

When you submit this patch and mdio is seperate from the cadence macb driver,
it will likely cause problems with the ksz9031 phy due to it turning interrupts
off when suspended.  Currently, this is not a problem because taking macb down
turns the management port off.  I have a patch to correct this here:

https://patchwork.ozlabs.org/patch/502189/

Would you mind including this patch in your set?

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices
  2015-07-28  3:34     ` Punnaiah Choudary Kalluri
@ 2015-07-31 21:53       ` Nathan Sullivan
  2015-08-03  6:01         ` Michal Simek
  2015-07-31 21:58       ` Nathan Sullivan
  1 sibling, 1 reply; 14+ messages in thread
From: Nathan Sullivan @ 2015-07-31 21:53 UTC (permalink / raw)
  To: Punnaiah Choudary Kalluri
  Cc: Nicolas Ferre, Michal Simek, Anirudha Sarangi, davem,
	Florian Fainelli, andrew, Harini Katakam, kpc528,
	kalluripunnaiahchoudary, netdev

On Tue, Jul 28, 2015 at 03:34:51AM +0000, Punnaiah Choudary Kalluri wrote:
> Ok. I will send you updated patch for mdio support soon and we will finalize next
> Course of actions if it doesn't break the existing flow. 
> 
> Thanks,
> Punnaiah

Just a heads up, when mdio no longer turns off when macb goes down, the micrel
9031 phy will have an issue with interrupts getting disabling during phy
suspend.  I have a patch to correct this issue here:

https://patchwork.ozlabs.org/patch/502189/

Would you mind including this patch in your set?

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices
  2015-07-27  7:37   ` Nicolas Ferre
@ 2015-07-28  3:34     ` Punnaiah Choudary Kalluri
  2015-07-31 21:53       ` Nathan Sullivan
  2015-07-31 21:58       ` Nathan Sullivan
  0 siblings, 2 replies; 14+ messages in thread
From: Punnaiah Choudary Kalluri @ 2015-07-28  3:34 UTC (permalink / raw)
  To: Nicolas Ferre, Michal Simek, Anirudha Sarangi, davem,
	Florian Fainelli, andrew
  Cc: Harini Katakam, kpc528, kalluripunnaiahchoudary, netdev

Hi Nicolas,

> -----Original Message-----
> From: Nicolas Ferre [mailto:nicolas.ferre@atmel.com]
> Sent: Monday, July 27, 2015 1:07 PM
> To: Michal Simek; Punnaiah Choudary Kalluri; Anirudha Sarangi;
> davem@davemloft.net; Florian Fainelli; andrew@lunn.ch
> Cc: Harini Katakam; kpc528@gmail.com;
> kalluripunnaiahchoudary@gmail.com; netdev@vger.kernel.org; Punnaiah
> Choudary Kalluri
> Subject: Re: [RFC PATCH 0/2] net: macb: Add mdio driver for accessing
> multiple phy devices
> 
> Le 20/07/2015 15:30, Michal Simek a écrit :
> > Hi Nicolas,
> >
> > have you had a time to look at this?
> 
> Michal,
> 
> Sorry for the delay.
> 
> With the insight of Florian and Andrew, I do agree to move to your
> "Implementation 1" and a separate driver for mdio bus.
> 
> The only thing that worries me it that the architecture AVR32 which we
> are sharing this driver with doesn't have support for device tree (and
> may never have). So, it would be good to make sure to keep compatibility
> with it.
> 
> Another point to take into account is the transition period: we have
> several SoC .dtsi/dts that will need to be converted and we'll need to
> add this mdio support before that it's integrated in netdev: we have to
> think about it in advance.

Ok. I will send you updated patch for mdio support soon and we will finalize next
Course of actions if it doesn't break the existing flow. 

Thanks,
Punnaiah
> 
> Thanks, bye.
> 
> 
> > On 07/13/2015 06:48 AM, Punnaiah Choudary Kalluri wrote:
> >> This patch is to add support for the design that has multiple ethernet
> >> mac controllers and single mdio bus connected to multiple phy devices.
> >> i.e mdio lines are connected to any of the ethernet mac controller and
> >> all the phy devices will be accessed using the phy maintenance interface
> >> in that mac controller.
> >>
> >>  ______                   _____
> >> |      |                 |PHY0 |
> >> | MAC0 |-----------------|     |
> >> |______|       |         |_____|
> >>                |
> >>  ______        |          _____
> >> |      |       |         |     |
> >> | MAC1 |       |_________|PHY1 |
> >> |______|                 |____ |
> >>
> >> So, i come up with two implementations for addressing the above
> configuration.
> >>
> >> Implementation 1:
> >>  Have separate driver for mdio bus
> >>  Create a DT node for all the PHY devices connected to the mdio bus
> >>  This driver will share the register space of the mac controller that has
> >>  mdio bus connected.
> >>
> >> Implementation 2:
> >>  Add new property "has-mdio" and it should be 1 for the mac that has
> mdio bus
> >>  connected.
> >>  Create the mdio bus only when the has-mdio property is 1
> >>
> >> Please review the two implementations and suggest which one is better
> to proceed
> >> further. In my opinion implementation 1 will be the ideal one.
> >>
> >> Currently i have tested the patches with single mac and single phy
> >> configuration. I need to take care of few more cases before releasing the
> final patch
> >> but before that i would like to have your opinion on the above
> implementations
> >> and finalize one implementation. so that i can enhance it further.
> >>
> >> Punnaiah Choudary Kalluri (1):
> >>   net: macb: Add mdio driver for accessing multiple phy devices
> >>   net: macb: Add support for single mac managing more than one phy
> >>
> >>
> >>  drivers/net/ethernet/cadence/Makefile    |    2 +-
> >>  drivers/net/ethernet/cadence/macb.c      |   93 +-------------
> >>  drivers/net/ethernet/cadence/macb.h      |    3 +-
> >>  drivers/net/ethernet/cadence/macb_mdio.c |  204
> ++++++++++++++++++++++++++++++
> >>  4 files changed, 211 insertions(+), 91 deletions(-)
> >>  create mode 100644 drivers/net/ethernet/cadence/macb_mdio.c
> >>
> >
> >
> >
> 
> 
> --
> Nicolas Ferre

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices
  2015-07-20 13:30 ` Michal Simek
  2015-07-20 16:23   ` Andrew Lunn
@ 2015-07-27  7:37   ` Nicolas Ferre
  2015-07-28  3:34     ` Punnaiah Choudary Kalluri
  1 sibling, 1 reply; 14+ messages in thread
From: Nicolas Ferre @ 2015-07-27  7:37 UTC (permalink / raw)
  To: Michal Simek, Punnaiah Choudary Kalluri, anirudh, davem,
	Florian Fainelli, andrew
  Cc: harinik, kpc528, kalluripunnaiahchoudary, netdev,
	Punnaiah Choudary Kalluri

Le 20/07/2015 15:30, Michal Simek a écrit :
> Hi Nicolas,
> 
> have you had a time to look at this?

Michal,

Sorry for the delay.

With the insight of Florian and Andrew, I do agree to move to your
"Implementation 1" and a separate driver for mdio bus.

The only thing that worries me it that the architecture AVR32 which we
are sharing this driver with doesn't have support for device tree (and
may never have). So, it would be good to make sure to keep compatibility
with it.

Another point to take into account is the transition period: we have
several SoC .dtsi/dts that will need to be converted and we'll need to
add this mdio support before that it's integrated in netdev: we have to
think about it in advance.

Thanks, bye.


> On 07/13/2015 06:48 AM, Punnaiah Choudary Kalluri wrote:
>> This patch is to add support for the design that has multiple ethernet
>> mac controllers and single mdio bus connected to multiple phy devices.
>> i.e mdio lines are connected to any of the ethernet mac controller and
>> all the phy devices will be accessed using the phy maintenance interface
>> in that mac controller.
>>
>>  ______                   _____
>> |      |                 |PHY0 |
>> | MAC0 |-----------------|     |
>> |______|       |         |_____|
>>                |           
>>  ______        |          _____
>> |      |       |         |     |
>> | MAC1 |       |_________|PHY1 | 
>> |______|                 |____ |
>>
>> So, i come up with two implementations for addressing the above configuration.
>>
>> Implementation 1:
>>  Have separate driver for mdio bus
>>  Create a DT node for all the PHY devices connected to the mdio bus
>>  This driver will share the register space of the mac controller that has
>>  mdio bus connected.  
>>
>> Implementation 2:
>>  Add new property "has-mdio" and it should be 1 for the mac that has mdio bus
>>  connected.
>>  Create the mdio bus only when the has-mdio property is 1
>>
>> Please review the two implementations and suggest which one is better to proceed
>> further. In my opinion implementation 1 will be the ideal one.
>>
>> Currently i have tested the patches with single mac and single phy
>> configuration. I need to take care of few more cases before releasing the final patch
>> but before that i would like to have your opinion on the above implementations
>> and finalize one implementation. so that i can enhance it further.
>>
>> Punnaiah Choudary Kalluri (1):
>>   net: macb: Add mdio driver for accessing multiple phy devices
>>   net: macb: Add support for single mac managing more than one phy
>>
>>
>>  drivers/net/ethernet/cadence/Makefile    |    2 +-
>>  drivers/net/ethernet/cadence/macb.c      |   93 +-------------
>>  drivers/net/ethernet/cadence/macb.h      |    3 +-
>>  drivers/net/ethernet/cadence/macb_mdio.c |  204 ++++++++++++++++++++++++++++++
>>  4 files changed, 211 insertions(+), 91 deletions(-)
>>  create mode 100644 drivers/net/ethernet/cadence/macb_mdio.c
>>
> 
> 
> 


-- 
Nicolas Ferre

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices
  2015-07-20 13:30 ` Michal Simek
@ 2015-07-20 16:23   ` Andrew Lunn
  2015-07-27  7:37   ` Nicolas Ferre
  1 sibling, 0 replies; 14+ messages in thread
From: Andrew Lunn @ 2015-07-20 16:23 UTC (permalink / raw)
  To: Michal Simek
  Cc: Punnaiah Choudary Kalluri, nicolas.ferre, anirudh, davem,
	harinik, kpc528, kalluripunnaiahchoudary, netdev,
	Punnaiah Choudary Kalluri

On Mon, Jul 20, 2015 at 03:30:36PM +0200, Michal Simek wrote:
> Hi Nicolas,
> 
> have you had a time to look at this?
> 
> Thanks,
> Michal
> 
> On 07/13/2015 06:48 AM, Punnaiah Choudary Kalluri wrote:
> > This patch is to add support for the design that has multiple ethernet
> > mac controllers and single mdio bus connected to multiple phy devices.
> > i.e mdio lines are connected to any of the ethernet mac controller and
> > all the phy devices will be accessed using the phy maintenance interface
> > in that mac controller.
> > 
> >  ______                   _____
> > |      |                 |PHY0 |
> > | MAC0 |-----------------|     |
> > |______|       |         |_____|
> >                |           
> >  ______        |          _____
> > |      |       |         |     |
> > | MAC1 |       |_________|PHY1 | 
> > |______|                 |____ |
> > 
> > So, i come up with two implementations for addressing the above configuration.
> > 
> > Implementation 1:
> >  Have separate driver for mdio bus
> >  Create a DT node for all the PHY devices connected to the mdio bus
> >  This driver will share the register space of the mac controller that has
> >  mdio bus connected.  
> > 

Hi Michal

The above it what Marvell, Freescale FEC and probably others do. It is
well defined in Documentation/devicetree/bindings/net/ethernet.txt
that you can have a phy-handle property containing a phandle to the
actual phy device on some random MDIO bus.

     Andrew

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices
  2015-07-13  4:48 [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices Punnaiah Choudary Kalluri
  2015-07-13 18:43 ` Florian Fainelli
@ 2015-07-20 13:30 ` Michal Simek
  2015-07-20 16:23   ` Andrew Lunn
  2015-07-27  7:37   ` Nicolas Ferre
  1 sibling, 2 replies; 14+ messages in thread
From: Michal Simek @ 2015-07-20 13:30 UTC (permalink / raw)
  To: Punnaiah Choudary Kalluri, nicolas.ferre, anirudh, davem
  Cc: harinik, kpc528, kalluripunnaiahchoudary, netdev,
	Punnaiah Choudary Kalluri

Hi Nicolas,

have you had a time to look at this?

Thanks,
Michal

On 07/13/2015 06:48 AM, Punnaiah Choudary Kalluri wrote:
> This patch is to add support for the design that has multiple ethernet
> mac controllers and single mdio bus connected to multiple phy devices.
> i.e mdio lines are connected to any of the ethernet mac controller and
> all the phy devices will be accessed using the phy maintenance interface
> in that mac controller.
> 
>  ______                   _____
> |      |                 |PHY0 |
> | MAC0 |-----------------|     |
> |______|       |         |_____|
>                |           
>  ______        |          _____
> |      |       |         |     |
> | MAC1 |       |_________|PHY1 | 
> |______|                 |____ |
> 
> So, i come up with two implementations for addressing the above configuration.
> 
> Implementation 1:
>  Have separate driver for mdio bus
>  Create a DT node for all the PHY devices connected to the mdio bus
>  This driver will share the register space of the mac controller that has
>  mdio bus connected.  
> 
> Implementation 2:
>  Add new property "has-mdio" and it should be 1 for the mac that has mdio bus
>  connected.
>  Create the mdio bus only when the has-mdio property is 1
> 
> Please review the two implementations and suggest which one is better to proceed
> further. In my opinion implementation 1 will be the ideal one.
> 
> Currently i have tested the patches with single mac and single phy
> configuration. I need to take care of few more cases before releasing the final patch
> but before that i would like to have your opinion on the above implementations
> and finalize one implementation. so that i can enhance it further.
> 
> Punnaiah Choudary Kalluri (1):
>   net: macb: Add mdio driver for accessing multiple phy devices
>   net: macb: Add support for single mac managing more than one phy
> 
> 
>  drivers/net/ethernet/cadence/Makefile    |    2 +-
>  drivers/net/ethernet/cadence/macb.c      |   93 +-------------
>  drivers/net/ethernet/cadence/macb.h      |    3 +-
>  drivers/net/ethernet/cadence/macb_mdio.c |  204 ++++++++++++++++++++++++++++++
>  4 files changed, 211 insertions(+), 91 deletions(-)
>  create mode 100644 drivers/net/ethernet/cadence/macb_mdio.c
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices
  2015-07-13 18:43 ` Florian Fainelli
@ 2015-07-14  3:02   ` punnaiah choudary kalluri
  0 siblings, 0 replies; 14+ messages in thread
From: punnaiah choudary kalluri @ 2015-07-14  3:02 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Punnaiah Choudary Kalluri, nicolas.ferre, michals, anirudh,
	davem, harinik, Punnaiah Choudary, netdev

On Tue, Jul 14, 2015 at 12:13 AM, Florian Fainelli <f.fainelli@gmail.com> wrote:
> On 12/07/15 21:48, Punnaiah Choudary Kalluri wrote:
>> This patch is to add support for the design that has multiple ethernet
>> mac controllers and single mdio bus connected to multiple phy devices.
>> i.e mdio lines are connected to any of the ethernet mac controller and
>> all the phy devices will be accessed using the phy maintenance interface
>> in that mac controller.
>>
>>  ______                   _____
>> |      |                 |PHY0 |
>> | MAC0 |-----------------|     |
>> |______|       |         |_____|
>>                |
>>  ______        |          _____
>> |      |       |         |     |
>> | MAC1 |       |_________|PHY1 |
>> |______|                 |____ |
>>
>> So, i come up with two implementations for addressing the above configuration.
>>
>> Implementation 1:
>>  Have separate driver for mdio bus
>>  Create a DT node for all the PHY devices connected to the mdio bus
>>  This driver will share the register space of the mac controller that has
>>  mdio bus connected.
>
> That is the best design implementation, MDIO in itself is a sub-piece of
> your Ethernet MAC controller the fact that it is within the Ethernet MAC
> core is just coincidental, but there is no reason why it could not be
> taken apart and made a separate block in itself.

Thanks Florian for suggesting this.
No idea on why the mdio block was not made a separate block.

regards,
Punnaiah

>
>>
>> Implementation 2:
>>  Add new property "has-mdio" and it should be 1 for the mac that has mdio bus
>>  connected.
>>  Create the mdio bus only when the has-mdio property is 1
>>
>> Please review the two implementations and suggest which one is better to proceed
>> further. In my opinion implementation 1 will be the ideal one.
>
> Agreed.
>
>>
>> Currently i have tested the patches with single mac and single phy
>> configuration. I need to take care of few more cases before releasing the final patch
>> but before that i would like to have your opinion on the above implementations
>> and finalize one implementation. so that i can enhance it further.
>>
>> Punnaiah Choudary Kalluri (1):
>>   net: macb: Add mdio driver for accessing multiple phy devices
>>   net: macb: Add support for single mac managing more than one phy
>>
>>
>>  drivers/net/ethernet/cadence/Makefile    |    2 +-
>>  drivers/net/ethernet/cadence/macb.c      |   93 +-------------
>>  drivers/net/ethernet/cadence/macb.h      |    3 +-
>>  drivers/net/ethernet/cadence/macb_mdio.c |  204 ++++++++++++++++++++++++++++++
>>  4 files changed, 211 insertions(+), 91 deletions(-)
>>  create mode 100644 drivers/net/ethernet/cadence/macb_mdio.c
>>
>
>
> --
> Florian

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices
  2015-07-13  4:48 [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices Punnaiah Choudary Kalluri
@ 2015-07-13 18:43 ` Florian Fainelli
  2015-07-14  3:02   ` punnaiah choudary kalluri
  2015-07-20 13:30 ` Michal Simek
  1 sibling, 1 reply; 14+ messages in thread
From: Florian Fainelli @ 2015-07-13 18:43 UTC (permalink / raw)
  To: Punnaiah Choudary Kalluri, nicolas.ferre, michals, anirudh, davem
  Cc: harinik, kpc528, kalluripunnaiahchoudary, netdev,
	Punnaiah Choudary Kalluri

On 12/07/15 21:48, Punnaiah Choudary Kalluri wrote:
> This patch is to add support for the design that has multiple ethernet
> mac controllers and single mdio bus connected to multiple phy devices.
> i.e mdio lines are connected to any of the ethernet mac controller and
> all the phy devices will be accessed using the phy maintenance interface
> in that mac controller.
> 
>  ______                   _____
> |      |                 |PHY0 |
> | MAC0 |-----------------|     |
> |______|       |         |_____|
>                |           
>  ______        |          _____
> |      |       |         |     |
> | MAC1 |       |_________|PHY1 | 
> |______|                 |____ |
> 
> So, i come up with two implementations for addressing the above configuration.
> 
> Implementation 1:
>  Have separate driver for mdio bus
>  Create a DT node for all the PHY devices connected to the mdio bus
>  This driver will share the register space of the mac controller that has
>  mdio bus connected.

That is the best design implementation, MDIO in itself is a sub-piece of
your Ethernet MAC controller the fact that it is within the Ethernet MAC
core is just coincidental, but there is no reason why it could not be
taken apart and made a separate block in itself.

> 
> Implementation 2:
>  Add new property "has-mdio" and it should be 1 for the mac that has mdio bus
>  connected.
>  Create the mdio bus only when the has-mdio property is 1
> 
> Please review the two implementations and suggest which one is better to proceed
> further. In my opinion implementation 1 will be the ideal one.

Agreed.

> 
> Currently i have tested the patches with single mac and single phy
> configuration. I need to take care of few more cases before releasing the final patch
> but before that i would like to have your opinion on the above implementations
> and finalize one implementation. so that i can enhance it further.
> 
> Punnaiah Choudary Kalluri (1):
>   net: macb: Add mdio driver for accessing multiple phy devices
>   net: macb: Add support for single mac managing more than one phy
> 
> 
>  drivers/net/ethernet/cadence/Makefile    |    2 +-
>  drivers/net/ethernet/cadence/macb.c      |   93 +-------------
>  drivers/net/ethernet/cadence/macb.h      |    3 +-
>  drivers/net/ethernet/cadence/macb_mdio.c |  204 ++++++++++++++++++++++++++++++
>  4 files changed, 211 insertions(+), 91 deletions(-)
>  create mode 100644 drivers/net/ethernet/cadence/macb_mdio.c
> 


-- 
Florian

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices
@ 2015-07-13  4:48 Punnaiah Choudary Kalluri
  2015-07-13 18:43 ` Florian Fainelli
  2015-07-20 13:30 ` Michal Simek
  0 siblings, 2 replies; 14+ messages in thread
From: Punnaiah Choudary Kalluri @ 2015-07-13  4:48 UTC (permalink / raw)
  To: nicolas.ferre, michals, anirudh, davem
  Cc: harinik, kpc528, kalluripunnaiahchoudary, netdev,
	Punnaiah Choudary Kalluri

This patch is to add support for the design that has multiple ethernet
mac controllers and single mdio bus connected to multiple phy devices.
i.e mdio lines are connected to any of the ethernet mac controller and
all the phy devices will be accessed using the phy maintenance interface
in that mac controller.

 ______                   _____
|      |                 |PHY0 |
| MAC0 |-----------------|     |
|______|       |         |_____|
               |           
 ______        |          _____
|      |       |         |     |
| MAC1 |       |_________|PHY1 | 
|______|                 |____ |

So, i come up with two implementations for addressing the above configuration.

Implementation 1:
 Have separate driver for mdio bus
 Create a DT node for all the PHY devices connected to the mdio bus
 This driver will share the register space of the mac controller that has
 mdio bus connected.  

Implementation 2:
 Add new property "has-mdio" and it should be 1 for the mac that has mdio bus
 connected.
 Create the mdio bus only when the has-mdio property is 1

Please review the two implementations and suggest which one is better to proceed
further. In my opinion implementation 1 will be the ideal one.

Currently i have tested the patches with single mac and single phy
configuration. I need to take care of few more cases before releasing the final patch
but before that i would like to have your opinion on the above implementations
and finalize one implementation. so that i can enhance it further.

Punnaiah Choudary Kalluri (1):
  net: macb: Add mdio driver for accessing multiple phy devices
  net: macb: Add support for single mac managing more than one phy


 drivers/net/ethernet/cadence/Makefile    |    2 +-
 drivers/net/ethernet/cadence/macb.c      |   93 +-------------
 drivers/net/ethernet/cadence/macb.h      |    3 +-
 drivers/net/ethernet/cadence/macb_mdio.c |  204 ++++++++++++++++++++++++++++++
 4 files changed, 211 insertions(+), 91 deletions(-)
 create mode 100644 drivers/net/ethernet/cadence/macb_mdio.c

-- 
1.7.4

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-08-03  6:35 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-13  3:35 [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices Punnaiah Choudary Kalluri
2015-07-13  3:35 ` [RFC PATCH] " Punnaiah Choudary Kalluri
2015-07-13  4:47   ` Punnaiah Choudary Kalluri
2015-07-13  3:35 ` [RFC PATCH 2/2] net: macb: Add support for single mac managing more than one phy Punnaiah Choudary Kalluri
2015-07-13  4:48 [RFC PATCH 0/2] net: macb: Add mdio driver for accessing multiple phy devices Punnaiah Choudary Kalluri
2015-07-13 18:43 ` Florian Fainelli
2015-07-14  3:02   ` punnaiah choudary kalluri
2015-07-20 13:30 ` Michal Simek
2015-07-20 16:23   ` Andrew Lunn
2015-07-27  7:37   ` Nicolas Ferre
2015-07-28  3:34     ` Punnaiah Choudary Kalluri
2015-07-31 21:53       ` Nathan Sullivan
2015-08-03  6:01         ` Michal Simek
2015-07-31 21:58       ` Nathan Sullivan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).