All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/8] Xscale IXP4xx ethernet refurbishing
@ 2019-05-24 16:20 Linus Walleij
  2019-05-24 16:20 ` [PATCH 1/8] net: ethernet: ixp4xx: Standard module init Linus Walleij
                   ` (7 more replies)
  0 siblings, 8 replies; 18+ messages in thread
From: Linus Walleij @ 2019-05-24 16:20 UTC (permalink / raw)
  To: netdev, David S . Miller; +Cc: Krzysztof Halasa, Linus Walleij

We are switching the IXP4xx architecture to use device tree
so this patch set makes is possible to probe the ethernet from
the device tree.

We will delete the non-devicetree code path once all peripherals
are working with device tree and all boards are converted
over.

Linus Walleij (8):
  net: ethernet: ixp4xx: Standard module init
  net: ethernet: ixp4xx: Use distinct local variable
  net: ehernet: ixp4xx: Use devm_alloc_etherdev()
  ARM/net: ixp4xx: Pass ethernet physical base as resource
  net: ethernet: ixp4xx: Get port ID from base address
  net: ethernet: ixp4xx: Use parent dev for DMA pool
  net: ethernet: ixp4xx: Add DT bindings
  net: ethernet: ixp4xx: Support device tree probing

 .../bindings/net/intel,ixp4xx-ethernet.yaml   |  53 ++++
 arch/arm/mach-ixp4xx/fsg-setup.c              |  20 ++
 arch/arm/mach-ixp4xx/goramo_mlr.c             |  20 ++
 arch/arm/mach-ixp4xx/ixdp425-setup.c          |  20 ++
 arch/arm/mach-ixp4xx/nas100d-setup.c          |  10 +
 arch/arm/mach-ixp4xx/nslu2-setup.c            |  10 +
 arch/arm/mach-ixp4xx/omixp-setup.c            |  20 ++
 arch/arm/mach-ixp4xx/vulcan-setup.c           |  20 ++
 drivers/net/ethernet/xscale/ixp4xx_eth.c      | 245 +++++++++++-------
 9 files changed, 321 insertions(+), 97 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/intel,ixp4xx-ethernet.yaml

-- 
2.20.1


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

* [PATCH 1/8] net: ethernet: ixp4xx: Standard module init
  2019-05-24 16:20 [PATCH 0/8] Xscale IXP4xx ethernet refurbishing Linus Walleij
@ 2019-05-24 16:20 ` Linus Walleij
  2019-05-24 19:46   ` Andrew Lunn
  2019-05-24 16:20 ` [PATCH 2/8] net: ethernet: ixp4xx: Use distinct local variable Linus Walleij
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Linus Walleij @ 2019-05-24 16:20 UTC (permalink / raw)
  To: netdev, David S . Miller; +Cc: Krzysztof Halasa, Linus Walleij

The IXP4xx driver was initializing the MDIO bus before even
probing, in the callbacks supposed to be used for setting up
the module itself, and with the side effect of trying to
register the MDIO bus as soon as this module was loaded or
compiled into the kernel whether the device was discovered
or not.

This does not work with multiplatform environments.

To get rid of this: set up the MDIO bus from the probe()
callback and remove it in the remove() callback. Rename
the probe() and remove() calls to reflect the most common
conventions.

Since there is a bit of checking for the ethernet feature
to be present in the MDIO registering function, making the
whole module not even be registered if we can't find an
MDIO bus, we need something similar: register the MDIO
bus when the corresponding ethernet is probed, and
return -EPROBE_DEFER on the other interfaces until this
happens. If no MDIO bus is present on any of the
registered interfaces we will eventually bail out.

None of the platforms I've seen has e.g. MDIO on EthB
and only uses EthC, there is always a Ethernet hardware
on the NPE (B, C) that has the MDIO bus, we just might
have to wait for it.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/net/ethernet/xscale/ixp4xx_eth.c | 82 ++++++++++++------------
 1 file changed, 40 insertions(+), 42 deletions(-)

diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
index 319db3ece263..ae69836d0080 100644
--- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
+++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
@@ -521,25 +521,14 @@ static int ixp4xx_mdio_write(struct mii_bus *bus, int phy_id, int location,
 	return ret;
 }
 
-static int ixp4xx_mdio_register(void)
+static int ixp4xx_mdio_register(struct eth_regs __iomem *regs)
 {
 	int err;
 
 	if (!(mdio_bus = mdiobus_alloc()))
 		return -ENOMEM;
 
-	if (cpu_is_ixp43x()) {
-		/* IXP43x lacks NPE-B and uses NPE-C for MII PHY access */
-		if (!(ixp4xx_read_feature_bits() & IXP4XX_FEATURE_NPEC_ETH))
-			return -ENODEV;
-		mdio_regs = (struct eth_regs __iomem *)IXP4XX_EthC_BASE_VIRT;
-	} else {
-		/* All MII PHY accesses use NPE-B Ethernet registers */
-		if (!(ixp4xx_read_feature_bits() & IXP4XX_FEATURE_NPEB_ETH0))
-			return -ENODEV;
-		mdio_regs = (struct eth_regs __iomem *)IXP4XX_EthB_BASE_VIRT;
-	}
-
+	mdio_regs = regs;
 	__raw_writel(DEFAULT_CORE_CNTRL, &mdio_regs->core_control);
 	spin_lock_init(&mdio_lock);
 	mdio_bus->name = "IXP4xx MII Bus";
@@ -1378,7 +1367,7 @@ static const struct net_device_ops ixp4xx_netdev_ops = {
 	.ndo_validate_addr = eth_validate_addr,
 };
 
-static int eth_init_one(struct platform_device *pdev)
+static int ixp4xx_eth_probe(struct platform_device *pdev)
 {
 	struct port *port;
 	struct net_device *dev;
@@ -1398,14 +1387,46 @@ static int eth_init_one(struct platform_device *pdev)
 
 	switch (port->id) {
 	case IXP4XX_ETH_NPEA:
+		/* If the MDIO bus is not up yet, defer probe */
+		if (!mdio_bus)
+			return -EPROBE_DEFER;
 		port->regs = (struct eth_regs __iomem *)IXP4XX_EthA_BASE_VIRT;
 		regs_phys  = IXP4XX_EthA_BASE_PHYS;
 		break;
 	case IXP4XX_ETH_NPEB:
+		/*
+		 * On all except IXP43x, NPE-B is used for the MDIO bus.
+		 * If there is no NPE-B in the feature set, bail out, else
+		 * register the MDIO bus.
+		 */
+		if (!cpu_is_ixp43x()) {
+			if (!(ixp4xx_read_feature_bits() &
+			      IXP4XX_FEATURE_NPEB_ETH0))
+				return -ENODEV;
+			/* Else register the MDIO bus on NPE-B */
+			if ((err = ixp4xx_mdio_register(IXP4XX_EthC_BASE_VIRT)))
+				return err;
+		}
+		if (!mdio_bus)
+			return -EPROBE_DEFER;
 		port->regs = (struct eth_regs __iomem *)IXP4XX_EthB_BASE_VIRT;
 		regs_phys  = IXP4XX_EthB_BASE_PHYS;
 		break;
 	case IXP4XX_ETH_NPEC:
+		/*
+		 * IXP43x lacks NPE-B and uses NPE-C for the MDIO bus access,
+		 * of there is no NPE-C, no bus, nothing works, so bail out.
+		 */
+		if (cpu_is_ixp43x()) {
+			if (!(ixp4xx_read_feature_bits() &
+			      IXP4XX_FEATURE_NPEC_ETH))
+				return -ENODEV;
+			/* Else register the MDIO bus on NPE-C */
+			if ((err = ixp4xx_mdio_register(IXP4XX_EthC_BASE_VIRT)))
+				return err;
+		}
+		if (!mdio_bus)
+			return -EPROBE_DEFER;
 		port->regs = (struct eth_regs __iomem *)IXP4XX_EthC_BASE_VIRT;
 		regs_phys  = IXP4XX_EthC_BASE_PHYS;
 		break;
@@ -1474,7 +1495,7 @@ static int eth_init_one(struct platform_device *pdev)
 	return err;
 }
 
-static int eth_remove_one(struct platform_device *pdev)
+static int ixp4xx_eth_remove(struct platform_device *pdev)
 {
 	struct net_device *dev = platform_get_drvdata(pdev);
 	struct phy_device *phydev = dev->phydev;
@@ -1482,6 +1503,7 @@ static int eth_remove_one(struct platform_device *pdev)
 
 	unregister_netdev(dev);
 	phy_disconnect(phydev);
+	ixp4xx_mdio_remove();
 	npe_port_tab[NPE_ID(port->id)] = NULL;
 	npe_release(port->npe);
 	release_resource(port->mem_res);
@@ -1491,36 +1513,12 @@ static int eth_remove_one(struct platform_device *pdev)
 
 static struct platform_driver ixp4xx_eth_driver = {
 	.driver.name	= DRV_NAME,
-	.probe		= eth_init_one,
-	.remove		= eth_remove_one,
+	.probe		= ixp4xx_eth_probe,
+	.remove		= ixp4xx_eth_remove,
 };
-
-static int __init eth_init_module(void)
-{
-	int err;
-
-	/*
-	 * FIXME: we bail out on device tree boot but this really needs
-	 * to be fixed in a nicer way: this registers the MDIO bus before
-	 * even matching the driver infrastructure, we should only probe
-	 * detected hardware.
-	 */
-	if (of_have_populated_dt())
-		return -ENODEV;
-	if ((err = ixp4xx_mdio_register()))
-		return err;
-	return platform_driver_register(&ixp4xx_eth_driver);
-}
-
-static void __exit eth_cleanup_module(void)
-{
-	platform_driver_unregister(&ixp4xx_eth_driver);
-	ixp4xx_mdio_remove();
-}
+module_platform_driver(ixp4xx_eth_driver);
 
 MODULE_AUTHOR("Krzysztof Halasa");
 MODULE_DESCRIPTION("Intel IXP4xx Ethernet driver");
 MODULE_LICENSE("GPL v2");
 MODULE_ALIAS("platform:ixp4xx_eth");
-module_init(eth_init_module);
-module_exit(eth_cleanup_module);
-- 
2.20.1


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

* [PATCH 2/8] net: ethernet: ixp4xx: Use distinct local variable
  2019-05-24 16:20 [PATCH 0/8] Xscale IXP4xx ethernet refurbishing Linus Walleij
  2019-05-24 16:20 ` [PATCH 1/8] net: ethernet: ixp4xx: Standard module init Linus Walleij
@ 2019-05-24 16:20 ` Linus Walleij
  2019-05-24 16:20 ` [PATCH 3/8] net: ehernet: ixp4xx: Use devm_alloc_etherdev() Linus Walleij
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Linus Walleij @ 2019-05-24 16:20 UTC (permalink / raw)
  To: netdev, David S . Miller; +Cc: Krzysztof Halasa, Linus Walleij

Use "ndev" for the struct net_device and "dev" for the
struct device in probe() and remove(). Add the local
"dev" pointer for later use in refactoring.

Take this opportunity to fix inverse christmas tree
coding style.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/net/ethernet/xscale/ixp4xx_eth.c | 51 +++++++++++++-----------
 1 file changed, 27 insertions(+), 24 deletions(-)

diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
index ae69836d0080..a0c02458f456 100644
--- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
+++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
@@ -1369,20 +1369,23 @@ static const struct net_device_ops ixp4xx_netdev_ops = {
 
 static int ixp4xx_eth_probe(struct platform_device *pdev)
 {
-	struct port *port;
-	struct net_device *dev;
-	struct eth_plat_info *plat = dev_get_platdata(&pdev->dev);
+	char phy_id[MII_BUS_ID_SIZE + 3];
 	struct phy_device *phydev = NULL;
+	struct device *dev = &pdev->dev;
+	struct eth_plat_info *plat;
+	struct net_device *ndev;
+	struct port *port;
 	u32 regs_phys;
-	char phy_id[MII_BUS_ID_SIZE + 3];
 	int err;
 
-	if (!(dev = alloc_etherdev(sizeof(struct port))))
+	plat = dev_get_platdata(dev);
+
+	if (!(ndev = alloc_etherdev(sizeof(struct port))))
 		return -ENOMEM;
 
-	SET_NETDEV_DEV(dev, &pdev->dev);
-	port = netdev_priv(dev);
-	port->netdev = dev;
+	SET_NETDEV_DEV(ndev, dev);
+	port = netdev_priv(ndev);
+	port->netdev = ndev;
 	port->id = pdev->id;
 
 	switch (port->id) {
@@ -1435,18 +1438,18 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 		goto err_free;
 	}
 
-	dev->netdev_ops = &ixp4xx_netdev_ops;
-	dev->ethtool_ops = &ixp4xx_ethtool_ops;
-	dev->tx_queue_len = 100;
+	ndev->netdev_ops = &ixp4xx_netdev_ops;
+	ndev->ethtool_ops = &ixp4xx_ethtool_ops;
+	ndev->tx_queue_len = 100;
 
-	netif_napi_add(dev, &port->napi, eth_poll, NAPI_WEIGHT);
+	netif_napi_add(ndev, &port->napi, eth_poll, NAPI_WEIGHT);
 
 	if (!(port->npe = npe_request(NPE_ID(port->id)))) {
 		err = -EIO;
 		goto err_free;
 	}
 
-	port->mem_res = request_mem_region(regs_phys, REGS_SIZE, dev->name);
+	port->mem_res = request_mem_region(regs_phys, REGS_SIZE, ndev->name);
 	if (!port->mem_res) {
 		err = -EBUSY;
 		goto err_npe_rel;
@@ -1454,9 +1457,9 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 
 	port->plat = plat;
 	npe_port_tab[NPE_ID(port->id)] = port;
-	memcpy(dev->dev_addr, plat->hwaddr, ETH_ALEN);
+	memcpy(ndev->dev_addr, plat->hwaddr, ETH_ALEN);
 
-	platform_set_drvdata(pdev, dev);
+	platform_set_drvdata(pdev, ndev);
 
 	__raw_writel(DEFAULT_CORE_CNTRL | CORE_RESET,
 		     &port->regs->core_control);
@@ -1466,7 +1469,7 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 
 	snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT,
 		mdio_bus->id, plat->phy);
-	phydev = phy_connect(dev, phy_id, &ixp4xx_adjust_link,
+	phydev = phy_connect(ndev, phy_id, &ixp4xx_adjust_link,
 			     PHY_INTERFACE_MODE_MII);
 	if (IS_ERR(phydev)) {
 		err = PTR_ERR(phydev);
@@ -1475,10 +1478,10 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 
 	phydev->irq = PHY_POLL;
 
-	if ((err = register_netdev(dev)))
+	if ((err = register_netdev(ndev)))
 		goto err_phy_dis;
 
-	printk(KERN_INFO "%s: MII PHY %i on %s\n", dev->name, plat->phy,
+	printk(KERN_INFO "%s: MII PHY %i on %s\n", ndev->name, plat->phy,
 	       npe_name(port->npe));
 
 	return 0;
@@ -1491,23 +1494,23 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 err_npe_rel:
 	npe_release(port->npe);
 err_free:
-	free_netdev(dev);
+	free_netdev(ndev);
 	return err;
 }
 
 static int ixp4xx_eth_remove(struct platform_device *pdev)
 {
-	struct net_device *dev = platform_get_drvdata(pdev);
-	struct phy_device *phydev = dev->phydev;
-	struct port *port = netdev_priv(dev);
+	struct net_device *ndev = platform_get_drvdata(pdev);
+	struct phy_device *phydev = ndev->phydev;
+	struct port *port = netdev_priv(ndev);
 
-	unregister_netdev(dev);
+	unregister_netdev(ndev);
 	phy_disconnect(phydev);
 	ixp4xx_mdio_remove();
 	npe_port_tab[NPE_ID(port->id)] = NULL;
 	npe_release(port->npe);
 	release_resource(port->mem_res);
-	free_netdev(dev);
+	free_netdev(ndev);
 	return 0;
 }
 
-- 
2.20.1


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

* [PATCH 3/8] net: ehernet: ixp4xx: Use devm_alloc_etherdev()
  2019-05-24 16:20 [PATCH 0/8] Xscale IXP4xx ethernet refurbishing Linus Walleij
  2019-05-24 16:20 ` [PATCH 1/8] net: ethernet: ixp4xx: Standard module init Linus Walleij
  2019-05-24 16:20 ` [PATCH 2/8] net: ethernet: ixp4xx: Use distinct local variable Linus Walleij
@ 2019-05-24 16:20 ` Linus Walleij
  2019-05-24 19:52   ` Andrew Lunn
  2019-05-24 16:20 ` [PATCH 4/8] ARM/net: ixp4xx: Pass ethernet physical base as resource Linus Walleij
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Linus Walleij @ 2019-05-24 16:20 UTC (permalink / raw)
  To: netdev, David S . Miller; +Cc: Krzysztof Halasa, Linus Walleij

Using the devm_alloc_etherdev() function simplifies the error
path. I also patch the message to use dev_info().

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/net/ethernet/xscale/ixp4xx_eth.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
index a0c02458f456..064ff0886cc3 100644
--- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
+++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
@@ -1380,7 +1380,7 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 
 	plat = dev_get_platdata(dev);
 
-	if (!(ndev = alloc_etherdev(sizeof(struct port))))
+	if (!(ndev = devm_alloc_etherdev(dev, sizeof(struct port))))
 		return -ENOMEM;
 
 	SET_NETDEV_DEV(ndev, dev);
@@ -1434,8 +1434,7 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 		regs_phys  = IXP4XX_EthC_BASE_PHYS;
 		break;
 	default:
-		err = -ENODEV;
-		goto err_free;
+		return -ENODEV;
 	}
 
 	ndev->netdev_ops = &ixp4xx_netdev_ops;
@@ -1444,10 +1443,8 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 
 	netif_napi_add(ndev, &port->napi, eth_poll, NAPI_WEIGHT);
 
-	if (!(port->npe = npe_request(NPE_ID(port->id)))) {
-		err = -EIO;
-		goto err_free;
-	}
+	if (!(port->npe = npe_request(NPE_ID(port->id))))
+		return -EIO;
 
 	port->mem_res = request_mem_region(regs_phys, REGS_SIZE, ndev->name);
 	if (!port->mem_res) {
@@ -1481,8 +1478,8 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 	if ((err = register_netdev(ndev)))
 		goto err_phy_dis;
 
-	printk(KERN_INFO "%s: MII PHY %i on %s\n", ndev->name, plat->phy,
-	       npe_name(port->npe));
+	dev_info(dev, "%s: MII PHY %i on %s\n", ndev->name, plat->phy,
+		 npe_name(port->npe));
 
 	return 0;
 
@@ -1493,8 +1490,6 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 	release_resource(port->mem_res);
 err_npe_rel:
 	npe_release(port->npe);
-err_free:
-	free_netdev(ndev);
 	return err;
 }
 
@@ -1510,7 +1505,6 @@ static int ixp4xx_eth_remove(struct platform_device *pdev)
 	npe_port_tab[NPE_ID(port->id)] = NULL;
 	npe_release(port->npe);
 	release_resource(port->mem_res);
-	free_netdev(ndev);
 	return 0;
 }
 
-- 
2.20.1


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

* [PATCH 4/8] ARM/net: ixp4xx: Pass ethernet physical base as resource
  2019-05-24 16:20 [PATCH 0/8] Xscale IXP4xx ethernet refurbishing Linus Walleij
                   ` (2 preceding siblings ...)
  2019-05-24 16:20 ` [PATCH 3/8] net: ehernet: ixp4xx: Use devm_alloc_etherdev() Linus Walleij
@ 2019-05-24 16:20 ` Linus Walleij
  2019-05-24 20:00   ` Andrew Lunn
  2019-05-24 16:20 ` [PATCH 5/8] net: ethernet: ixp4xx: Get port ID from base address Linus Walleij
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Linus Walleij @ 2019-05-24 16:20 UTC (permalink / raw)
  To: netdev, David S . Miller; +Cc: Krzysztof Halasa, Linus Walleij

In order to probe this ethernet interface from the device tree
all physical MMIO regions must be passed as resources. Begin
this rewrite by first passing the port base address as a
resource for all platforms using this driver, remap it in
the driver and avoid using any reference of the statically
mapped virtual address in the driver.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/mach-ixp4xx/fsg-setup.c         | 20 ++++++++++++++++++++
 arch/arm/mach-ixp4xx/goramo_mlr.c        | 20 ++++++++++++++++++++
 arch/arm/mach-ixp4xx/ixdp425-setup.c     | 20 ++++++++++++++++++++
 arch/arm/mach-ixp4xx/nas100d-setup.c     | 10 ++++++++++
 arch/arm/mach-ixp4xx/nslu2-setup.c       | 10 ++++++++++
 arch/arm/mach-ixp4xx/omixp-setup.c       | 20 ++++++++++++++++++++
 arch/arm/mach-ixp4xx/vulcan-setup.c      | 20 ++++++++++++++++++++
 drivers/net/ethernet/xscale/ixp4xx_eth.c | 20 +++++++++++---------
 8 files changed, 131 insertions(+), 9 deletions(-)

diff --git a/arch/arm/mach-ixp4xx/fsg-setup.c b/arch/arm/mach-ixp4xx/fsg-setup.c
index 648932d8d7a8..507ee3878769 100644
--- a/arch/arm/mach-ixp4xx/fsg-setup.c
+++ b/arch/arm/mach-ixp4xx/fsg-setup.c
@@ -132,6 +132,22 @@ static struct platform_device fsg_leds = {
 };
 
 /* Built-in 10/100 Ethernet MAC interfaces */
+static struct resource fsg_eth_npeb_resources[] = {
+	{
+		.start		= IXP4XX_EthB_BASE_PHYS,
+		.end		= IXP4XX_EthB_BASE_PHYS + 0x0fff,
+		.flags		= IORESOURCE_MEM,
+	},
+};
+
+static struct resource fsg_eth_npec_resources[] = {
+	{
+		.start		= IXP4XX_EthC_BASE_PHYS,
+		.end		= IXP4XX_EthC_BASE_PHYS + 0x0fff,
+		.flags		= IORESOURCE_MEM,
+	},
+};
+
 static struct eth_plat_info fsg_plat_eth[] = {
 	{
 		.phy		= 5,
@@ -151,12 +167,16 @@ static struct platform_device fsg_eth[] = {
 		.dev = {
 			.platform_data	= fsg_plat_eth,
 		},
+		.num_resources	= ARRAY_SIZE(fsg_eth_npeb_resources),
+		.resource	= fsg_eth_npeb_resources,
 	}, {
 		.name			= "ixp4xx_eth",
 		.id			= IXP4XX_ETH_NPEC,
 		.dev = {
 			.platform_data	= fsg_plat_eth + 1,
 		},
+		.num_resources	= ARRAY_SIZE(fsg_eth_npec_resources),
+		.resource	= fsg_eth_npec_resources,
 	}
 };
 
diff --git a/arch/arm/mach-ixp4xx/goramo_mlr.c b/arch/arm/mach-ixp4xx/goramo_mlr.c
index 4d805080020e..7db396cc4353 100644
--- a/arch/arm/mach-ixp4xx/goramo_mlr.c
+++ b/arch/arm/mach-ixp4xx/goramo_mlr.c
@@ -270,6 +270,22 @@ static struct platform_device device_uarts = {
 
 
 /* Built-in 10/100 Ethernet MAC interfaces */
+static struct resource eth_npeb_resources[] = {
+	{
+		.start		= IXP4XX_EthB_BASE_PHYS,
+		.end		= IXP4XX_EthB_BASE_PHYS + 0x0fff,
+		.flags		= IORESOURCE_MEM,
+	},
+};
+
+static struct resource eth_npec_resources[] = {
+	{
+		.start		= IXP4XX_EthC_BASE_PHYS,
+		.end		= IXP4XX_EthC_BASE_PHYS + 0x0fff,
+		.flags		= IORESOURCE_MEM,
+	},
+};
+
 static struct eth_plat_info eth_plat[] = {
 	{
 		.phy		= 0,
@@ -287,10 +303,14 @@ static struct platform_device device_eth_tab[] = {
 		.name			= "ixp4xx_eth",
 		.id			= IXP4XX_ETH_NPEB,
 		.dev.platform_data	= eth_plat,
+		.num_resources		= ARRAY_SIZE(eth_npeb_resources),
+		.resource		= eth_npeb_resources,
 	}, {
 		.name			= "ixp4xx_eth",
 		.id			= IXP4XX_ETH_NPEC,
 		.dev.platform_data	= eth_plat + 1,
+		.num_resources		= ARRAY_SIZE(eth_npec_resources),
+		.resource		= eth_npec_resources,
 	}
 };
 
diff --git a/arch/arm/mach-ixp4xx/ixdp425-setup.c b/arch/arm/mach-ixp4xx/ixdp425-setup.c
index 6f0f7ed18ea8..45d5b720ded6 100644
--- a/arch/arm/mach-ixp4xx/ixdp425-setup.c
+++ b/arch/arm/mach-ixp4xx/ixdp425-setup.c
@@ -187,6 +187,22 @@ static struct platform_device ixdp425_uart = {
 };
 
 /* Built-in 10/100 Ethernet MAC interfaces */
+static struct resource ixp425_npeb_resources[] = {
+	{
+		.start		= IXP4XX_EthB_BASE_PHYS,
+		.end		= IXP4XX_EthB_BASE_PHYS + 0x0fff,
+		.flags		= IORESOURCE_MEM,
+	},
+};
+
+static struct resource ixp425_npec_resources[] = {
+	{
+		.start		= IXP4XX_EthC_BASE_PHYS,
+		.end		= IXP4XX_EthC_BASE_PHYS + 0x0fff,
+		.flags		= IORESOURCE_MEM,
+	},
+};
+
 static struct eth_plat_info ixdp425_plat_eth[] = {
 	{
 		.phy		= 0,
@@ -204,10 +220,14 @@ static struct platform_device ixdp425_eth[] = {
 		.name			= "ixp4xx_eth",
 		.id			= IXP4XX_ETH_NPEB,
 		.dev.platform_data	= ixdp425_plat_eth,
+		.num_resources		= ARRAY_SIZE(ixp425_npeb_resources),
+		.resource		= ixp425_npeb_resources,
 	}, {
 		.name			= "ixp4xx_eth",
 		.id			= IXP4XX_ETH_NPEC,
 		.dev.platform_data	= ixdp425_plat_eth + 1,
+		.num_resources		= ARRAY_SIZE(ixp425_npec_resources),
+		.resource		= ixp425_npec_resources,
 	}
 };
 
diff --git a/arch/arm/mach-ixp4xx/nas100d-setup.c b/arch/arm/mach-ixp4xx/nas100d-setup.c
index c142cfa8c5d6..6959ad2e3aec 100644
--- a/arch/arm/mach-ixp4xx/nas100d-setup.c
+++ b/arch/arm/mach-ixp4xx/nas100d-setup.c
@@ -165,6 +165,14 @@ static struct platform_device nas100d_uart = {
 };
 
 /* Built-in 10/100 Ethernet MAC interfaces */
+static struct resource nas100d_eth_resources[] = {
+	{
+		.start		= IXP4XX_EthB_BASE_PHYS,
+		.end		= IXP4XX_EthB_BASE_PHYS + 0x0fff,
+		.flags		= IORESOURCE_MEM,
+	},
+};
+
 static struct eth_plat_info nas100d_plat_eth[] = {
 	{
 		.phy		= 0,
@@ -178,6 +186,8 @@ static struct platform_device nas100d_eth[] = {
 		.name			= "ixp4xx_eth",
 		.id			= IXP4XX_ETH_NPEB,
 		.dev.platform_data	= nas100d_plat_eth,
+		.num_resources		= ARRAY_SIZE(nas100d_eth_resources),
+		.resource		= nas100d_eth_resources,
 	}
 };
 
diff --git a/arch/arm/mach-ixp4xx/nslu2-setup.c b/arch/arm/mach-ixp4xx/nslu2-setup.c
index ee1877fcfafe..a428bb918703 100644
--- a/arch/arm/mach-ixp4xx/nslu2-setup.c
+++ b/arch/arm/mach-ixp4xx/nslu2-setup.c
@@ -185,6 +185,14 @@ static struct platform_device nslu2_uart = {
 };
 
 /* Built-in 10/100 Ethernet MAC interfaces */
+static struct resource nslu2_eth_resources[] = {
+	{
+		.start		= IXP4XX_EthB_BASE_PHYS,
+		.end		= IXP4XX_EthB_BASE_PHYS + 0x0fff,
+		.flags		= IORESOURCE_MEM,
+	},
+};
+
 static struct eth_plat_info nslu2_plat_eth[] = {
 	{
 		.phy		= 1,
@@ -198,6 +206,8 @@ static struct platform_device nslu2_eth[] = {
 		.name			= "ixp4xx_eth",
 		.id			= IXP4XX_ETH_NPEB,
 		.dev.platform_data	= nslu2_plat_eth,
+		.num_resources		= ARRAY_SIZE(nslu2_eth_resources),
+		.resource		= nslu2_eth_resources,
 	}
 };
 
diff --git a/arch/arm/mach-ixp4xx/omixp-setup.c b/arch/arm/mach-ixp4xx/omixp-setup.c
index 2d494b454376..6f86c27b725e 100644
--- a/arch/arm/mach-ixp4xx/omixp-setup.c
+++ b/arch/arm/mach-ixp4xx/omixp-setup.c
@@ -171,6 +171,22 @@ static struct platform_device mic256_leds = {
 };
 
 /* Built-in 10/100 Ethernet MAC interfaces */
+static struct resource ixp425_npeb_resources[] = {
+	{
+		.start		= IXP4XX_EthB_BASE_PHYS,
+		.end		= IXP4XX_EthB_BASE_PHYS + 0x0fff,
+		.flags		= IORESOURCE_MEM,
+	},
+};
+
+static struct resource ixp425_npec_resources[] = {
+	{
+		.start		= IXP4XX_EthC_BASE_PHYS,
+		.end		= IXP4XX_EthC_BASE_PHYS + 0x0fff,
+		.flags		= IORESOURCE_MEM,
+	},
+};
+
 static struct eth_plat_info ixdp425_plat_eth[] = {
 	{
 		.phy		= 0,
@@ -188,10 +204,14 @@ static struct platform_device ixdp425_eth[] = {
 		.name			= "ixp4xx_eth",
 		.id			= IXP4XX_ETH_NPEB,
 		.dev.platform_data	= ixdp425_plat_eth,
+		.num_resources		= ARRAY_SIZE(ixp425_npeb_resources),
+		.resource		= ixp425_npeb_resources,
 	}, {
 		.name			= "ixp4xx_eth",
 		.id			= IXP4XX_ETH_NPEC,
 		.dev.platform_data	= ixdp425_plat_eth + 1,
+		.num_resources		= ARRAY_SIZE(ixp425_npec_resources),
+		.resource		= ixp425_npec_resources,
 	},
 };
 
diff --git a/arch/arm/mach-ixp4xx/vulcan-setup.c b/arch/arm/mach-ixp4xx/vulcan-setup.c
index 2c03d2f6b647..783c291f8f4c 100644
--- a/arch/arm/mach-ixp4xx/vulcan-setup.c
+++ b/arch/arm/mach-ixp4xx/vulcan-setup.c
@@ -122,6 +122,22 @@ static struct platform_device vulcan_uart = {
 	.num_resources		= ARRAY_SIZE(vulcan_uart_resources),
 };
 
+static struct resource vulcan_npeb_resources[] = {
+	{
+		.start		= IXP4XX_EthB_BASE_PHYS,
+		.end		= IXP4XX_EthB_BASE_PHYS + 0x0fff,
+		.flags		= IORESOURCE_MEM,
+	},
+};
+
+static struct resource vulcan_npec_resources[] = {
+	{
+		.start		= IXP4XX_EthC_BASE_PHYS,
+		.end		= IXP4XX_EthC_BASE_PHYS + 0x0fff,
+		.flags		= IORESOURCE_MEM,
+	},
+};
+
 static struct eth_plat_info vulcan_plat_eth[] = {
 	[0] = {
 		.phy		= 0,
@@ -142,6 +158,8 @@ static struct platform_device vulcan_eth[] = {
 		.dev = {
 			.platform_data	= &vulcan_plat_eth[0],
 		},
+		.num_resources		= ARRAY_SIZE(vulcan_npeb_resources),
+		.resource		= vulcan_npeb_resources,
 	},
 	[1] = {
 		.name			= "ixp4xx_eth",
@@ -149,6 +167,8 @@ static struct platform_device vulcan_eth[] = {
 		.dev = {
 			.platform_data	= &vulcan_plat_eth[1],
 		},
+		.num_resources		= ARRAY_SIZE(vulcan_npec_resources),
+		.resource		= vulcan_npec_resources,
 	},
 };
 
diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
index 064ff0886cc3..17d3291d79b4 100644
--- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
+++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
@@ -1373,9 +1373,10 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 	struct phy_device *phydev = NULL;
 	struct device *dev = &pdev->dev;
 	struct eth_plat_info *plat;
+	resource_size_t regs_phys;
 	struct net_device *ndev;
+	struct resource *res;
 	struct port *port;
-	u32 regs_phys;
 	int err;
 
 	plat = dev_get_platdata(dev);
@@ -1388,13 +1389,18 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 	port->netdev = ndev;
 	port->id = pdev->id;
 
+	/* Get the port resource and remap */
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -ENODEV;
+	regs_phys = res->start;
+	port->regs = devm_ioremap_resource(dev, res);
+
 	switch (port->id) {
 	case IXP4XX_ETH_NPEA:
 		/* If the MDIO bus is not up yet, defer probe */
 		if (!mdio_bus)
 			return -EPROBE_DEFER;
-		port->regs = (struct eth_regs __iomem *)IXP4XX_EthA_BASE_VIRT;
-		regs_phys  = IXP4XX_EthA_BASE_PHYS;
 		break;
 	case IXP4XX_ETH_NPEB:
 		/*
@@ -1407,13 +1413,11 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 			      IXP4XX_FEATURE_NPEB_ETH0))
 				return -ENODEV;
 			/* Else register the MDIO bus on NPE-B */
-			if ((err = ixp4xx_mdio_register(IXP4XX_EthC_BASE_VIRT)))
+			if ((err = ixp4xx_mdio_register(port->regs)))
 				return err;
 		}
 		if (!mdio_bus)
 			return -EPROBE_DEFER;
-		port->regs = (struct eth_regs __iomem *)IXP4XX_EthB_BASE_VIRT;
-		regs_phys  = IXP4XX_EthB_BASE_PHYS;
 		break;
 	case IXP4XX_ETH_NPEC:
 		/*
@@ -1425,13 +1429,11 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 			      IXP4XX_FEATURE_NPEC_ETH))
 				return -ENODEV;
 			/* Else register the MDIO bus on NPE-C */
-			if ((err = ixp4xx_mdio_register(IXP4XX_EthC_BASE_VIRT)))
+			if ((err = ixp4xx_mdio_register(port->regs)))
 				return err;
 		}
 		if (!mdio_bus)
 			return -EPROBE_DEFER;
-		port->regs = (struct eth_regs __iomem *)IXP4XX_EthC_BASE_VIRT;
-		regs_phys  = IXP4XX_EthC_BASE_PHYS;
 		break;
 	default:
 		return -ENODEV;
-- 
2.20.1


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

* [PATCH 5/8] net: ethernet: ixp4xx: Get port ID from base address
  2019-05-24 16:20 [PATCH 0/8] Xscale IXP4xx ethernet refurbishing Linus Walleij
                   ` (3 preceding siblings ...)
  2019-05-24 16:20 ` [PATCH 4/8] ARM/net: ixp4xx: Pass ethernet physical base as resource Linus Walleij
@ 2019-05-24 16:20 ` Linus Walleij
  2019-05-24 16:20 ` [PATCH 6/8] net: ethernet: ixp4xx: Use parent dev for DMA pool Linus Walleij
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Linus Walleij @ 2019-05-24 16:20 UTC (permalink / raw)
  To: netdev, David S . Miller; +Cc: Krzysztof Halasa, Linus Walleij

The port->id was picked from the platform device .id field,
but this is not supposed to be used for passing around
random numbers in hardware. Identify the port ID number
from the base address instead.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/net/ethernet/xscale/ixp4xx_eth.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
index 17d3291d79b4..600f62e95fb0 100644
--- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
+++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
@@ -1387,7 +1387,6 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 	SET_NETDEV_DEV(ndev, dev);
 	port = netdev_priv(ndev);
 	port->netdev = ndev;
-	port->id = pdev->id;
 
 	/* Get the port resource and remap */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1396,13 +1395,15 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 	regs_phys = res->start;
 	port->regs = devm_ioremap_resource(dev, res);
 
-	switch (port->id) {
-	case IXP4XX_ETH_NPEA:
+	switch (res->start) {
+	case 0xc800c000:
+		port->id = IXP4XX_ETH_NPEA;
 		/* If the MDIO bus is not up yet, defer probe */
 		if (!mdio_bus)
 			return -EPROBE_DEFER;
 		break;
-	case IXP4XX_ETH_NPEB:
+	case 0xc8009000:
+		port->id = IXP4XX_ETH_NPEB;
 		/*
 		 * On all except IXP43x, NPE-B is used for the MDIO bus.
 		 * If there is no NPE-B in the feature set, bail out, else
@@ -1419,7 +1420,8 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 		if (!mdio_bus)
 			return -EPROBE_DEFER;
 		break;
-	case IXP4XX_ETH_NPEC:
+	case 0xc800a000:
+		port->id = IXP4XX_ETH_NPEC;
 		/*
 		 * IXP43x lacks NPE-B and uses NPE-C for the MDIO bus access,
 		 * of there is no NPE-C, no bus, nothing works, so bail out.
-- 
2.20.1


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

* [PATCH 6/8] net: ethernet: ixp4xx: Use parent dev for DMA pool
  2019-05-24 16:20 [PATCH 0/8] Xscale IXP4xx ethernet refurbishing Linus Walleij
                   ` (4 preceding siblings ...)
  2019-05-24 16:20 ` [PATCH 5/8] net: ethernet: ixp4xx: Get port ID from base address Linus Walleij
@ 2019-05-24 16:20 ` Linus Walleij
  2019-05-24 16:20 ` [PATCH 7/8] net: ethernet: ixp4xx: Add DT bindings Linus Walleij
  2019-05-24 16:20 ` [PATCH 8/8] net: ethernet: ixp4xx: Support device tree probing Linus Walleij
  7 siblings, 0 replies; 18+ messages in thread
From: Linus Walleij @ 2019-05-24 16:20 UTC (permalink / raw)
  To: netdev, David S . Miller; +Cc: Krzysztof Halasa, Linus Walleij

Use the netdevice struct device .parent field when calling
dma_pool_create(): the .dma_coherent_mask and .dma_mask
pertains to the bus device on the hardware (platform)
bus in this case, not the struct device inside the network
device. This makes the pool allocation work.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/net/ethernet/xscale/ixp4xx_eth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
index 600f62e95fb0..8b883563a3d3 100644
--- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
+++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
@@ -1092,7 +1092,7 @@ static int init_queues(struct port *port)
 	int i;
 
 	if (!ports_open) {
-		dma_pool = dma_pool_create(DRV_NAME, &port->netdev->dev,
+		dma_pool = dma_pool_create(DRV_NAME, port->netdev->dev.parent,
 					   POOL_ALLOC_SIZE, 32, 0);
 		if (!dma_pool)
 			return -ENOMEM;
-- 
2.20.1


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

* [PATCH 7/8] net: ethernet: ixp4xx: Add DT bindings
  2019-05-24 16:20 [PATCH 0/8] Xscale IXP4xx ethernet refurbishing Linus Walleij
                   ` (5 preceding siblings ...)
  2019-05-24 16:20 ` [PATCH 6/8] net: ethernet: ixp4xx: Use parent dev for DMA pool Linus Walleij
@ 2019-05-24 16:20 ` Linus Walleij
  2019-05-24 20:06   ` Andrew Lunn
  2019-05-24 16:20 ` [PATCH 8/8] net: ethernet: ixp4xx: Support device tree probing Linus Walleij
  7 siblings, 1 reply; 18+ messages in thread
From: Linus Walleij @ 2019-05-24 16:20 UTC (permalink / raw)
  To: netdev, David S . Miller; +Cc: Krzysztof Halasa, Linus Walleij

This adds device tree bindings for the IXP4xx ethernet.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 .../bindings/net/intel,ixp4xx-ethernet.yaml   | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/intel,ixp4xx-ethernet.yaml

diff --git a/Documentation/devicetree/bindings/net/intel,ixp4xx-ethernet.yaml b/Documentation/devicetree/bindings/net/intel,ixp4xx-ethernet.yaml
new file mode 100644
index 000000000000..4575a7e5aa4a
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/intel,ixp4xx-ethernet.yaml
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright 2018 Linaro Ltd.
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/net/intel-ixp4xx-ethernet.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: Intel IXP4xx ethernet
+
+maintainers:
+  - Linus Walleij <linus.walleij@linaro.org>
+
+description: |
+  The Intel IXP4xx ethernet makes use of the IXP4xx NPE (Network
+  Processing Engine) and the IXP4xx Queue Mangager to process
+  the ethernet frames. It can optionally contain an MDIO bus to
+  talk to PHYs.
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+        - const: intel,ixp4xx-ethernet
+
+  reg:
+    maxItems: 1
+    description: Ethernet MMIO address range
+
+  queue-rx:
+    $ref: '/schemas/types.yaml#/definitions/phandle-array'
+    maxItems: 1
+    description: phandle to the RX queue on the NPE
+
+  queue-txready:
+    $ref: '/schemas/types.yaml#/definitions/phandle-array'
+    maxItems: 1
+    description: phandle to the TX READY queue on the NPE
+
+required:
+  - compatible
+  - reg
+  - queue-rx
+  - queue-txready
+
+examples:
+  - |
+    ethernet@c8009000 {
+        compatible = "intel,ixp4xx-ethernet";
+        reg = <0xc8009000 0x1000>;
+        status = "disabled";
+        queue-rx = <&qmgr 3>;
+        queue-txready = <&qmgr 20>;
+    };
-- 
2.20.1


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

* [PATCH 8/8] net: ethernet: ixp4xx: Support device tree probing
  2019-05-24 16:20 [PATCH 0/8] Xscale IXP4xx ethernet refurbishing Linus Walleij
                   ` (6 preceding siblings ...)
  2019-05-24 16:20 ` [PATCH 7/8] net: ethernet: ixp4xx: Add DT bindings Linus Walleij
@ 2019-05-24 16:20 ` Linus Walleij
  2019-05-24 20:21   ` Andrew Lunn
  7 siblings, 1 reply; 18+ messages in thread
From: Linus Walleij @ 2019-05-24 16:20 UTC (permalink / raw)
  To: netdev, David S . Miller; +Cc: Krzysztof Halasa, Linus Walleij

This adds device tree probing to the IXP4xx ethernet
driver.

We need to drop the memory region request as part of
this since the OF core will request the memory for the
device.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/net/ethernet/xscale/ixp4xx_eth.c | 80 +++++++++++++++++++-----
 1 file changed, 66 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
index 8b883563a3d3..65fdc82d45a4 100644
--- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
+++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
@@ -167,7 +167,6 @@ struct eth_regs {
 };
 
 struct port {
-	struct resource *mem_res;
 	struct eth_regs __iomem *regs;
 	struct npe *npe;
 	struct net_device *netdev;
@@ -1367,19 +1366,72 @@ static const struct net_device_ops ixp4xx_netdev_ops = {
 	.ndo_validate_addr = eth_validate_addr,
 };
 
+#ifdef CONFIG_OF
+static struct eth_plat_info *ixp4xx_of_get_platdata(struct device *dev)
+{
+	struct device_node *np = dev->of_node;
+	struct of_phandle_args queue_spec;
+	struct eth_plat_info *plat;
+	u32 val;
+	int ret;
+
+	plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL);
+	if (!plat)
+		return NULL;
+
+	/* FIXME: get from MDIO handle */
+	ret = of_property_read_u32(np, "phy", &val);
+	if (ret) {
+		dev_err(dev, "no phy\n");
+		return NULL;
+	}
+	plat->phy = val;
+
+	/* Get the rx queue as a resource from queue manager */
+	ret = of_parse_phandle_with_fixed_args(np, "queue-rx", 1, 0,
+					       &queue_spec);
+	if (ret) {
+		dev_err(dev, "no rx queue phandle\n");
+		return NULL;
+	}
+	plat->rxq = queue_spec.args[0];
+
+	/* Get the txready queue as resource from queue manager */
+	ret = of_parse_phandle_with_fixed_args(np, "queue-txready", 1, 0,
+					       &queue_spec);
+	if (ret) {
+		dev_err(dev, "no txready queue phandle\n");
+		return NULL;
+	}
+	plat->txreadyq = queue_spec.args[0];
+
+	return plat;
+}
+#else
+static struct eth_plat_info *ixp4xx_of_get_platdata(struct device *dev)
+{
+	return NULL;
+}
+#endif
+
 static int ixp4xx_eth_probe(struct platform_device *pdev)
 {
 	char phy_id[MII_BUS_ID_SIZE + 3];
 	struct phy_device *phydev = NULL;
 	struct device *dev = &pdev->dev;
 	struct eth_plat_info *plat;
-	resource_size_t regs_phys;
 	struct net_device *ndev;
 	struct resource *res;
 	struct port *port;
 	int err;
 
-	plat = dev_get_platdata(dev);
+	if (dev->of_node)
+		plat = ixp4xx_of_get_platdata(dev);
+	else
+		plat = dev_get_platdata(dev);
+
+	if (!plat)
+		return -ENODEV;
 
 	if (!(ndev = devm_alloc_etherdev(dev, sizeof(struct port))))
 		return -ENOMEM;
@@ -1392,7 +1444,6 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res)
 		return -ENODEV;
-	regs_phys = res->start;
 	port->regs = devm_ioremap_resource(dev, res);
 
 	switch (res->start) {
@@ -1450,12 +1501,6 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 	if (!(port->npe = npe_request(NPE_ID(port->id))))
 		return -EIO;
 
-	port->mem_res = request_mem_region(regs_phys, REGS_SIZE, ndev->name);
-	if (!port->mem_res) {
-		err = -EBUSY;
-		goto err_npe_rel;
-	}
-
 	port->plat = plat;
 	npe_port_tab[NPE_ID(port->id)] = port;
 	memcpy(ndev->dev_addr, plat->hwaddr, ETH_ALEN);
@@ -1491,8 +1536,6 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
 	phy_disconnect(phydev);
 err_free_mem:
 	npe_port_tab[NPE_ID(port->id)] = NULL;
-	release_resource(port->mem_res);
-err_npe_rel:
 	npe_release(port->npe);
 	return err;
 }
@@ -1508,12 +1551,21 @@ static int ixp4xx_eth_remove(struct platform_device *pdev)
 	ixp4xx_mdio_remove();
 	npe_port_tab[NPE_ID(port->id)] = NULL;
 	npe_release(port->npe);
-	release_resource(port->mem_res);
 	return 0;
 }
 
+static const struct of_device_id ixp4xx_eth_of_match[] = {
+	{
+		.compatible = "intel,ixp4xx-ethernet",
+	},
+	{ },
+};
+
 static struct platform_driver ixp4xx_eth_driver = {
-	.driver.name	= DRV_NAME,
+	.driver = {
+		.name = DRV_NAME,
+		.of_match_table = of_match_ptr(ixp4xx_eth_of_match),
+	},
 	.probe		= ixp4xx_eth_probe,
 	.remove		= ixp4xx_eth_remove,
 };
-- 
2.20.1


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

* Re: [PATCH 1/8] net: ethernet: ixp4xx: Standard module init
  2019-05-24 16:20 ` [PATCH 1/8] net: ethernet: ixp4xx: Standard module init Linus Walleij
@ 2019-05-24 19:46   ` Andrew Lunn
  2019-05-29  7:10     ` Linus Walleij
  0 siblings, 1 reply; 18+ messages in thread
From: Andrew Lunn @ 2019-05-24 19:46 UTC (permalink / raw)
  To: Linus Walleij; +Cc: netdev, David S . Miller, Krzysztof Halasa

On Fri, May 24, 2019 at 06:20:16PM +0200, Linus Walleij wrote:
> The IXP4xx driver was initializing the MDIO bus before even
> probing, in the callbacks supposed to be used for setting up
> the module itself, and with the side effect of trying to
> register the MDIO bus as soon as this module was loaded or
> compiled into the kernel whether the device was discovered
> or not.

Hi Linus

What is the address space like? Could the mdio driver be pull out into
a standalone driver?

  Andrew

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

* Re: [PATCH 3/8] net: ehernet: ixp4xx: Use devm_alloc_etherdev()
  2019-05-24 16:20 ` [PATCH 3/8] net: ehernet: ixp4xx: Use devm_alloc_etherdev() Linus Walleij
@ 2019-05-24 19:52   ` Andrew Lunn
  0 siblings, 0 replies; 18+ messages in thread
From: Andrew Lunn @ 2019-05-24 19:52 UTC (permalink / raw)
  To: Linus Walleij; +Cc: netdev, David S . Miller, Krzysztof Halasa

> @@ -1481,8 +1478,8 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
>  	if ((err = register_netdev(ndev)))
>  		goto err_phy_dis;
>  
> -	printk(KERN_INFO "%s: MII PHY %i on %s\n", ndev->name, plat->phy,
> -	       npe_name(port->npe));
> +	dev_info(dev, "%s: MII PHY %i on %s\n", ndev->name, plat->phy,
> +		 npe_name(port->npe));

Hi Linus

If you get here, the interface has been registered. So you could use
netdev_info(ndev, ...). You can also call it before register_netdev,
but since the name as not yet been determined, it is not so
informative as dev_err() which will give you the bus address or
something.

	Andrew

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

* Re: [PATCH 4/8] ARM/net: ixp4xx: Pass ethernet physical base as resource
  2019-05-24 16:20 ` [PATCH 4/8] ARM/net: ixp4xx: Pass ethernet physical base as resource Linus Walleij
@ 2019-05-24 20:00   ` Andrew Lunn
  2019-05-25  9:14     ` Sergei Shtylyov
  0 siblings, 1 reply; 18+ messages in thread
From: Andrew Lunn @ 2019-05-24 20:00 UTC (permalink / raw)
  To: Linus Walleij; +Cc: netdev, David S . Miller, Krzysztof Halasa

On Fri, May 24, 2019 at 06:20:19PM +0200, Linus Walleij wrote:
> In order to probe this ethernet interface from the device tree
> all physical MMIO regions must be passed as resources. Begin
> this rewrite by first passing the port base address as a
> resource for all platforms using this driver, remap it in
> the driver and avoid using any reference of the statically
> mapped virtual address in the driver.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  arch/arm/mach-ixp4xx/fsg-setup.c         | 20 ++++++++++++++++++++
>  arch/arm/mach-ixp4xx/goramo_mlr.c        | 20 ++++++++++++++++++++
>  arch/arm/mach-ixp4xx/ixdp425-setup.c     | 20 ++++++++++++++++++++
>  arch/arm/mach-ixp4xx/nas100d-setup.c     | 10 ++++++++++
>  arch/arm/mach-ixp4xx/nslu2-setup.c       | 10 ++++++++++
>  arch/arm/mach-ixp4xx/omixp-setup.c       | 20 ++++++++++++++++++++
>  arch/arm/mach-ixp4xx/vulcan-setup.c      | 20 ++++++++++++++++++++
>  drivers/net/ethernet/xscale/ixp4xx_eth.c | 20 +++++++++++---------
>  8 files changed, 131 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/arm/mach-ixp4xx/fsg-setup.c b/arch/arm/mach-ixp4xx/fsg-setup.c
> index 648932d8d7a8..507ee3878769 100644
> --- a/arch/arm/mach-ixp4xx/fsg-setup.c
> +++ b/arch/arm/mach-ixp4xx/fsg-setup.c
> @@ -132,6 +132,22 @@ static struct platform_device fsg_leds = {
>  };
>  
>  /* Built-in 10/100 Ethernet MAC interfaces */
> +static struct resource fsg_eth_npeb_resources[] = {
> +	{
> +		.start		= IXP4XX_EthB_BASE_PHYS,
> +		.end		= IXP4XX_EthB_BASE_PHYS + 0x0fff,

Hi Linus

It is a long time since i did resources. But i was always told to use
the SZ_ macros, so SZ_4K. I also think 0xfff is wrong, it should be
0x1000.

	Andrew

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

* Re: [PATCH 7/8] net: ethernet: ixp4xx: Add DT bindings
  2019-05-24 16:20 ` [PATCH 7/8] net: ethernet: ixp4xx: Add DT bindings Linus Walleij
@ 2019-05-24 20:06   ` Andrew Lunn
  2019-05-29  7:13     ` Linus Walleij
  0 siblings, 1 reply; 18+ messages in thread
From: Andrew Lunn @ 2019-05-24 20:06 UTC (permalink / raw)
  To: Linus Walleij; +Cc: netdev, David S . Miller, Krzysztof Halasa

> +description: |
> +  The Intel IXP4xx ethernet makes use of the IXP4xx NPE (Network
> +  Processing Engine) and the IXP4xx Queue Mangager to process
> +  the ethernet frames. It can optionally contain an MDIO bus to
> +  talk to PHYs.

Hi Linus

You mention MDIO and PHYs, but the code is not there yet. When you do
add the needed code, it is a good idea to place the PHY nodes inside a
container node:

    ethernet@c8009000 {
        compatible = "intel,ixp4xx-ethernet";
        reg = <0xc8009000 0x1000>;
        status = "disabled";
        queue-rx = <&qmgr 3>;
        queue-txready = <&qmgr 20>;

        mdio {
		phy0: phy@0 {
		      reg = <0>;
		};
	};
    };

    Andrew

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

* Re: [PATCH 8/8] net: ethernet: ixp4xx: Support device tree probing
  2019-05-24 16:20 ` [PATCH 8/8] net: ethernet: ixp4xx: Support device tree probing Linus Walleij
@ 2019-05-24 20:21   ` Andrew Lunn
  0 siblings, 0 replies; 18+ messages in thread
From: Andrew Lunn @ 2019-05-24 20:21 UTC (permalink / raw)
  To: Linus Walleij; +Cc: netdev, David S . Miller, Krzysztof Halasa

> +	/* FIXME: get from MDIO handle */
> +	ret = of_property_read_u32(np, "phy", &val);
> +	if (ret) {
> +		dev_err(dev, "no phy\n");
> +		return NULL;
> +	}
> +	plat->phy = val;

Hi Linus

You might want to work on the MDIO code first. It is O.K. to do
something like:

np = NULL;

if (dev->of_node)
	np = of_get_child_by_name(dev->of_node, "mdio");

of_mdiobus_register(np, mdio_bus)

If np is NULL, it will fall back to mdiobus_register().

Then here you can do the correct

priv->phy_node = of_parse_phandle(dev->of_node, "phy-handle", 0);

and later call 

       phy = of_phy_connect(ndev, priv->phy_node, &ixp4xx_adjust_link,
                           PHY_INTERFACE_MODE_MII);

You just need to watch out for the -EPROBE_DEFFERED.

    Andrew

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

* Re: [PATCH 4/8] ARM/net: ixp4xx: Pass ethernet physical base as resource
  2019-05-24 20:00   ` Andrew Lunn
@ 2019-05-25  9:14     ` Sergei Shtylyov
  2019-05-28 13:21       ` Andrew Lunn
  0 siblings, 1 reply; 18+ messages in thread
From: Sergei Shtylyov @ 2019-05-25  9:14 UTC (permalink / raw)
  To: Andrew Lunn, Linus Walleij; +Cc: netdev, David S . Miller, Krzysztof Halasa

Hello!

On 24.05.2019 23:00, Andrew Lunn wrote:

>> In order to probe this ethernet interface from the device tree
>> all physical MMIO regions must be passed as resources. Begin
>> this rewrite by first passing the port base address as a
>> resource for all platforms using this driver, remap it in
>> the driver and avoid using any reference of the statically
>> mapped virtual address in the driver.
>>
>> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
>> ---
>>   arch/arm/mach-ixp4xx/fsg-setup.c         | 20 ++++++++++++++++++++
>>   arch/arm/mach-ixp4xx/goramo_mlr.c        | 20 ++++++++++++++++++++
>>   arch/arm/mach-ixp4xx/ixdp425-setup.c     | 20 ++++++++++++++++++++
>>   arch/arm/mach-ixp4xx/nas100d-setup.c     | 10 ++++++++++
>>   arch/arm/mach-ixp4xx/nslu2-setup.c       | 10 ++++++++++
>>   arch/arm/mach-ixp4xx/omixp-setup.c       | 20 ++++++++++++++++++++
>>   arch/arm/mach-ixp4xx/vulcan-setup.c      | 20 ++++++++++++++++++++
>>   drivers/net/ethernet/xscale/ixp4xx_eth.c | 20 +++++++++++---------
>>   8 files changed, 131 insertions(+), 9 deletions(-)
>>
>> diff --git a/arch/arm/mach-ixp4xx/fsg-setup.c b/arch/arm/mach-ixp4xx/fsg-setup.c
>> index 648932d8d7a8..507ee3878769 100644
>> --- a/arch/arm/mach-ixp4xx/fsg-setup.c
>> +++ b/arch/arm/mach-ixp4xx/fsg-setup.c
>> @@ -132,6 +132,22 @@ static struct platform_device fsg_leds = {
>>   };
>>   
>>   /* Built-in 10/100 Ethernet MAC interfaces */
>> +static struct resource fsg_eth_npeb_resources[] = {
>> +	{
>> +		.start		= IXP4XX_EthB_BASE_PHYS,
>> +		.end		= IXP4XX_EthB_BASE_PHYS + 0x0fff,
> 
> Hi Linus
> 
> It is a long time since i did resources. But i was always told to use
> the SZ_ macros, so SZ_4K. I also think 0xfff is wrong, it should be
> 0x1000.

    No, 0x0fff is correct there, 0x1000 is not...

> 	Andrew

MBR, Sergei

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

* Re: [PATCH 4/8] ARM/net: ixp4xx: Pass ethernet physical base as resource
  2019-05-25  9:14     ` Sergei Shtylyov
@ 2019-05-28 13:21       ` Andrew Lunn
  0 siblings, 0 replies; 18+ messages in thread
From: Andrew Lunn @ 2019-05-28 13:21 UTC (permalink / raw)
  To: Sergei Shtylyov; +Cc: Linus Walleij, netdev, David S . Miller, Krzysztof Halasa

> >>  /* Built-in 10/100 Ethernet MAC interfaces */
> >>+static struct resource fsg_eth_npeb_resources[] = {
> >>+	{
> >>+		.start		= IXP4XX_EthB_BASE_PHYS,
> >>+		.end		= IXP4XX_EthB_BASE_PHYS + 0x0fff,
> >
> >Hi Linus
> >
> >It is a long time since i did resources. But i was always told to use
> >the SZ_ macros, so SZ_4K. I also think 0xfff is wrong, it should be
> >0x1000.
> 
>    No, 0x0fff is correct there, 0x1000 is not...

Yes, the DEFINE_RES_* macros make this clear. The code should be
changed to use them, and then SZ_ macros can be used, since
DEFINE_RES_NAMED() does a - 1.

	Andrew

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

* Re: [PATCH 1/8] net: ethernet: ixp4xx: Standard module init
  2019-05-24 19:46   ` Andrew Lunn
@ 2019-05-29  7:10     ` Linus Walleij
  0 siblings, 0 replies; 18+ messages in thread
From: Linus Walleij @ 2019-05-29  7:10 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: netdev, David S . Miller, Krzysztof Halasa

On Fri, May 24, 2019 at 9:46 PM Andrew Lunn <andrew@lunn.ch> wrote:

> What is the address space like? Could the mdio driver be pull out into
> a standalone driver?

The IXP4xx actually has a peculiar structure.

Both the MDIO and ethernet goes out through the NPE (network
processing engine) and MDIO in particular is just talking to some
mailbox on the NPE. The ethernet has dedicated registers but appear
as dependent on the NPE.

Only NPE B (second) has MDIO.

I guess I should try to make the MDIO a child of the NPE.
I try to improve the legacy code little by little.

Yours,
Linus Walleij

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

* Re: [PATCH 7/8] net: ethernet: ixp4xx: Add DT bindings
  2019-05-24 20:06   ` Andrew Lunn
@ 2019-05-29  7:13     ` Linus Walleij
  0 siblings, 0 replies; 18+ messages in thread
From: Linus Walleij @ 2019-05-29  7:13 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: netdev, David S . Miller, Krzysztof Halasa

On Fri, May 24, 2019 at 10:06 PM Andrew Lunn <andrew@lunn.ch> wrote:

> > +description: |
> > +  The Intel IXP4xx ethernet makes use of the IXP4xx NPE (Network
> > +  Processing Engine) and the IXP4xx Queue Mangager to process
> > +  the ethernet frames. It can optionally contain an MDIO bus to
> > +  talk to PHYs.
>
> Hi Linus
>
> You mention MDIO and PHYs, but the code is not there yet. When you do
> add the needed code, it is a good idea to place the PHY nodes inside a
> container node:

Actually I think the MDIO needs to go into the NPE (network processing
engine) node, that is where it actually is implemented.

It coincides with having to rewrite the code in Linux to split that off into
its own device as you pointed out on patch 1, hm a bit of work ahead
here...

Yours,
Linus Walleij

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

end of thread, other threads:[~2019-05-29  7:14 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-24 16:20 [PATCH 0/8] Xscale IXP4xx ethernet refurbishing Linus Walleij
2019-05-24 16:20 ` [PATCH 1/8] net: ethernet: ixp4xx: Standard module init Linus Walleij
2019-05-24 19:46   ` Andrew Lunn
2019-05-29  7:10     ` Linus Walleij
2019-05-24 16:20 ` [PATCH 2/8] net: ethernet: ixp4xx: Use distinct local variable Linus Walleij
2019-05-24 16:20 ` [PATCH 3/8] net: ehernet: ixp4xx: Use devm_alloc_etherdev() Linus Walleij
2019-05-24 19:52   ` Andrew Lunn
2019-05-24 16:20 ` [PATCH 4/8] ARM/net: ixp4xx: Pass ethernet physical base as resource Linus Walleij
2019-05-24 20:00   ` Andrew Lunn
2019-05-25  9:14     ` Sergei Shtylyov
2019-05-28 13:21       ` Andrew Lunn
2019-05-24 16:20 ` [PATCH 5/8] net: ethernet: ixp4xx: Get port ID from base address Linus Walleij
2019-05-24 16:20 ` [PATCH 6/8] net: ethernet: ixp4xx: Use parent dev for DMA pool Linus Walleij
2019-05-24 16:20 ` [PATCH 7/8] net: ethernet: ixp4xx: Add DT bindings Linus Walleij
2019-05-24 20:06   ` Andrew Lunn
2019-05-29  7:13     ` Linus Walleij
2019-05-24 16:20 ` [PATCH 8/8] net: ethernet: ixp4xx: Support device tree probing Linus Walleij
2019-05-24 20:21   ` Andrew Lunn

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.