From patchwork Fri May 24 16:20:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 165128 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3806448ili; Fri, 24 May 2019 09:20:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqy64ybVtuQP5wypmTfy2i1NE0fKVHrZjte/4rhzKX1a8mfMNlwhPLMp4JXXKpgoqH0SBy3E X-Received: by 2002:a62:14d6:: with SMTP id 205mr114094432pfu.4.1558714842767; Fri, 24 May 2019 09:20:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558714842; cv=none; d=google.com; s=arc-20160816; b=fJr2zSnGzIaJLxuGxfCNAgLnD1Bmw/iuOk8HY0NJhr7UYQlbug0SvXKX+/3c+1zjE3 6mE/CXFw1zpLHFvIUxqL+RU+wk0pxP3xuwcr6iWKAPQCW4O4jx9kTmdv+TtQqSxC388v sDga7DyDtKZbu3oJUlZe9PD2EcfLQG/YazKHYGQuBiG8zn7pY/1G1vAYA25hyBA0RRMR 73BDiyg2bW5cDAJvH1ANT8PnYa4vuKSuMQST0JSJVaTi0C6su50GFAXiS6xSm7mx2dKd MgdpJv4WkNdQmO0dZ4wHnwdJMppt2W0VnllAS8zcYQLVKeVuf9v6sb29cCApmLETCbk3 z1Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LoimZJhuiC3VDcIUaJDNR8VzM40c8PjtWlQoyk09Hqw=; b=wiGx+c892y7kArz6XWY1UAgrlvznmi61jYjYAhr/cwo7L8XhReSrlJCndm8QRAJQWY JE1MwhycGvaIZHAy2ISYjCFv/Ot1BJt2hjSYj3+OlmyG1JaxMcJ3jK5wGWyA2UPeozL4 Ont6B2MQnxxtxbriddphnf97JUlzHvInyTGzKJrLolH/2nVpgtfrhj3pIl0EhmDVvMwG cZPi+FuEvG4Og9uR4pLV6VstsJ55E02d3izSFlyI2KE/+SLh8syrwyzoRJBXBOj4bVEU yYELjHQ4vBKk6ent4vfad9kwjoxoZYFEMbfo90CY2lTpwmWWVgJBgYWv+hk1x2NxZYYG c1PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=plEXrYIt; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m14si5204608pgj.377.2019.05.24.09.20.41; Fri, 24 May 2019 09:20:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=plEXrYIt; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390834AbfEXQUl (ORCPT + 9 others); Fri, 24 May 2019 12:20:41 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:39049 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390662AbfEXQUk (ORCPT ); Fri, 24 May 2019 12:20:40 -0400 Received: by mail-lf1-f66.google.com with SMTP id f1so7571186lfl.6 for ; Fri, 24 May 2019 09:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LoimZJhuiC3VDcIUaJDNR8VzM40c8PjtWlQoyk09Hqw=; b=plEXrYItN9TO/ik5u5tUB8RWHButrQ51yNOT5f7KnUxjmK4Rxk3qM6qh8r8ax5tGfw NtoJjyC8BM1nwS92a0ziPMwQZ2TxaHNz4Mvsqd4z7Rw9rArHGR3URX6i8fcBPbE+8WtM EvNohZtlaCxuoqZv9P4KfU3TukeCctqASewL66ptLjY+s2fKTj3NSzo8dYfyLaxvHRpj GnFwVRLoHCaFNJjHyiMcLXV/F3En0TXHAWCx17AsD0pj9uKFASY15bfQJhtjrBYSZqrd mq+zYtJvUrNhN+dLh3UVkFiJOVLaNMbEPY0ELUUP6cDzqOZEVkul5QmIssxP/O/mGYl+ MxhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LoimZJhuiC3VDcIUaJDNR8VzM40c8PjtWlQoyk09Hqw=; b=G0mxvF3TU/QOzBxI0wDeUm4kJ1xe+XEPsqDHBD4Jd323gw9ujiPMH+wijzI0Q+Hidh +2ZRQwSnC9fIwbbGczgLy51FDf5NlhyztPe6jZmq4h0HAEJAJtSiBnp23bdm0pzyh4mZ ECiA7c6w8wTQRkJ18DBAIDExsTgEI44H11be4TOAW8036znopQXOtNnlJjhbYT6FE9pe sYelnw1X/en9Q6sH9r2B7tRKB0Z+OAiGyoV2GHwpkKRL7fl8EgYN5+jvNJoWTJ13bUPY IQsTzzoxc8LiHS6GlAJq0HbKdOyfRa8tfoyWjM8/3ifupGOjzcbfIGXM9k0Daa72DMaK JfKA== X-Gm-Message-State: APjAAAXYXPD8E6gpP0j8E1BylnO2iCpeHiF1DTWhduwe9r5Tbhkk2+bz bz39IfZo9V6c83t43iIZnxqaOSbELUQ= X-Received: by 2002:ac2:4312:: with SMTP id l18mr39444415lfh.139.1558714837493; Fri, 24 May 2019 09:20:37 -0700 (PDT) Received: from localhost.bredbandsbolaget (c-d2cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.210]) by smtp.gmail.com with ESMTPSA id y4sm618075lje.24.2019.05.24.09.20.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 May 2019 09:20:36 -0700 (PDT) From: Linus Walleij To: netdev@vger.kernel.org, "David S . Miller" Cc: Krzysztof Halasa , Linus Walleij Subject: [PATCH 1/8] net: ethernet: ixp4xx: Standard module init Date: Fri, 24 May 2019 18:20:16 +0200 Message-Id: <20190524162023.9115-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190524162023.9115-1-linus.walleij@linaro.org> References: <20190524162023.9115-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- drivers/net/ethernet/xscale/ixp4xx_eth.c | 82 ++++++++++++------------ 1 file changed, 40 insertions(+), 42 deletions(-) -- 2.20.1 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);