From patchwork Mon Jun 12 10:42:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 9780731 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6998860212 for ; Mon, 12 Jun 2017 10:43:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58311285A4 for ; Mon, 12 Jun 2017 10:43:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A8352858B; Mon, 12 Jun 2017 10:43:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 652DA2858B for ; Mon, 12 Jun 2017 10:43:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WBfFtmGnPTFc6dLMbujtLVsnMUyoH1gPl6ekAQZSunc=; b=kaY73c/kEuauGw epRNyejRiZ5naawrK9zLq+wGCjlc/L0IqIpQ1+XYdZIYWr8nWRUXkBcISur1jYxHCE2uxiBlgJWND 2IO3/vuxOZpZyieBppcrALvlkmH9A1M1kvdXUrQfC6MqPven2iEO87ezs0syqs6tHnkECcTChv+cz D9lodNPIdhz7qotK8UVehAR8T9PseivGztTC0CcTcILtQJEwlnvsWnunZeJMthrt+H/eWenVYl8GN KmdgurYrp3U/kaAjAG/DcDK93oPr64k2XtjS67oVN0aB7I8+UBkmkXLSBwurq5WdP2ta8+zWJSVTa Dho58NSTrmtvAs+i6+vA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dKMor-00008I-0Z; Mon, 12 Jun 2017 10:43:37 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:1be6]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dKMom-0008Ka-8t for linux-arm-kernel@lists.infradead.org; Mon, 12 Jun 2017 10:43:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=3+AUpsFB5uabfCNiI9rMcJNnACxKS64pLtocXFyXV3E=; b=KgvV2KXZv2wqp8XZCM0pgW9Yx/B81nN32To/ubPpJPN8wNchHZXHo06TksgOOnP0/2u8CyiDj7GGBK3CVD8fn3vg/+ya5RPxlYIoPjPG8SSo8y8YPKuhxuR6MR6LWYsOXN4OUKfO6eQr0Zk9KRl1/5EyTAuGejhh9mM+oDMInB4=; Received: from n2100.armlinux.org.uk ([2002:4e20:1eda:1:214:fdff:fe10:4f86]:49885) by pandora.armlinux.org.uk with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1dKMo9-0000JZ-Qw; Mon, 12 Jun 2017 11:42:54 +0100 Received: from linux by n2100.armlinux.org.uk with local (Exim 4.76) (envelope-from ) id 1dKMo6-0002fl-Ti; Mon, 12 Jun 2017 11:42:50 +0100 Date: Mon, 12 Jun 2017 11:42:50 +0100 From: Russell King - ARM Linux To: Antoine Tenart Subject: Re: [PATCH v3 7/9] net: mvmdio: add xmdio xsmi support Message-ID: <20170612104250.GB10223@n2100.armlinux.org.uk> References: <20170612095745.11300-1-antoine.tenart@free-electrons.com> <20170612095745.11300-8-antoine.tenart@free-electrons.com> <20170612101739.GA4902@n2100.armlinux.org.uk> <20170612104126.GB4902@n2100.armlinux.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170612104126.GB4902@n2100.armlinux.org.uk> User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170612_034332_827759_BDF26A60 X-CRM114-Status: GOOD ( 20.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thomas.petazzoni@free-electrons.com, andrew@lunn.ch, f.fainelli@gmail.com, jason@lakedaemon.net, netdev@vger.kernel.org, nadavh@marvell.com, gregory.clement@free-electrons.com, mw@semihalf.com, davem@davemloft.net, linux-arm-kernel@lists.infradead.org, sebastian.hesselbarth@gmail.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Russell King Subject: [PATCH 2/2] net: mvmdio: get rid of fine-grained ops MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" The fine-grained ops makes the driver less readable, so let's instead implement two pairs of read/write mii_bus ops, one for SMI and the other for XSMI. Signed-off-by: Russell King --- drivers/net/ethernet/marvell/mvmdio.c | 268 ++++++++++++++++------------------ 1 file changed, 124 insertions(+), 144 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/marvell/mvmdio.c index d6770217965e..d04022db8619 100644 --- a/drivers/net/ethernet/marvell/mvmdio.c +++ b/drivers/net/ethernet/marvell/mvmdio.c @@ -84,123 +84,11 @@ struct orion_mdio_dev { struct orion_mdio_ops { int (*is_done)(struct orion_mdio_dev *); - int (*is_read_valid)(struct orion_mdio_dev *); - void (*start_read)(struct orion_mdio_dev *, int, int); - u16 (*read)(struct orion_mdio_dev *); - void (*write)(struct orion_mdio_dev *, int, int, u16); unsigned int poll_interval_min; unsigned int poll_interval_max; }; -/* mdio smi */ -static int orion_mdio_smi_is_done(struct orion_mdio_dev *dev) -{ - return !(readl(dev->regs) & MVMDIO_SMI_BUSY); -} - -static int orion_mdio_smi_is_read_valid(struct orion_mdio_dev *dev) -{ - return readl(dev->regs) & MVMDIO_SMI_READ_VALID; -} - -static void orion_mdio_smi_start_read_op(struct orion_mdio_dev *dev, int mii_id, - int regnum) -{ - writel(((mii_id << MVMDIO_SMI_PHY_ADDR_SHIFT) | - (regnum << MVMDIO_SMI_PHY_REG_SHIFT) | - MVMDIO_SMI_READ_OPERATION), - dev->regs); -} - -static u16 orion_mdio_smi_read_op(struct orion_mdio_dev *dev) -{ - return readl(dev->regs) & GENMASK(15, 0); -} - -static void orion_mdio_smi_write_op(struct orion_mdio_dev *dev, int mii_id, - int regnum, u16 value) -{ - writel(((mii_id << MVMDIO_SMI_PHY_ADDR_SHIFT) | - (regnum << MVMDIO_SMI_PHY_REG_SHIFT) | - MVMDIO_SMI_WRITE_OPERATION | - (value << MVMDIO_SMI_DATA_SHIFT)), - dev->regs); -} - -static const struct orion_mdio_ops orion_mdio_smi_ops = { - .is_done = orion_mdio_smi_is_done, - .is_read_valid = orion_mdio_smi_is_read_valid, - .start_read = orion_mdio_smi_start_read_op, - .read = orion_mdio_smi_read_op, - .write = orion_mdio_smi_write_op, - - .poll_interval_min = MVMDIO_SMI_POLL_INTERVAL_MIN, - .poll_interval_max = MVMDIO_SMI_POLL_INTERVAL_MAX, -}; - -/* xmdio xsmi */ -static int orion_mdio_xsmi_is_done(struct orion_mdio_dev *dev) -{ - return !(readl(dev->regs + MVMDIO_XSMI_MGNT_REG) & MVMDIO_XSMI_BUSY); -} - -static int orion_mdio_xsmi_is_read_valid(struct orion_mdio_dev *dev) -{ - return readl(dev->regs + MVMDIO_XSMI_MGNT_REG) & MVMDIO_XSMI_READ_VALID; -} - -static void orion_mdio_xsmi_start_read_op(struct orion_mdio_dev *dev, - int mii_id, int regnum) -{ - u16 dev_addr = (regnum >> 16) & GENMASK(4, 0); - - writel(regnum & GENMASK(15, 0), dev->regs + MVMDIO_XSMI_ADDR_REG); - writel((mii_id << MVMDIO_XSMI_PHYADDR_SHIFT) | - (dev_addr << MVMDIO_XSMI_DEVADDR_SHIFT) | - MVMDIO_XSMI_READ_OPERATION, - dev->regs + MVMDIO_XSMI_MGNT_REG); -} - -static u16 orion_mdio_xsmi_read_op(struct orion_mdio_dev *dev) -{ - return readl(dev->regs + MVMDIO_XSMI_MGNT_REG) & GENMASK(15, 0); -} - -static void orion_mdio_xsmi_write_op(struct orion_mdio_dev *dev, int mii_id, - int regnum, u16 value) -{ - u16 dev_addr = (regnum >> 16) & GENMASK(4, 0); - - writel(regnum & GENMASK(15, 0), dev->regs + MVMDIO_XSMI_ADDR_REG); - writel((mii_id << MVMDIO_XSMI_PHYADDR_SHIFT) | - (dev_addr << MVMDIO_XSMI_DEVADDR_SHIFT) | - MVMDIO_XSMI_WRITE_OPERATION | value, - dev->regs + MVMDIO_XSMI_MGNT_REG); -} - -static const struct orion_mdio_ops orion_mdio_xsmi_ops = { - .is_done = orion_mdio_xsmi_is_done, - .is_read_valid = orion_mdio_xsmi_is_read_valid, - .start_read = orion_mdio_xsmi_start_read_op, - .read = orion_mdio_xsmi_read_op, - .write = orion_mdio_xsmi_write_op, - - .poll_interval_min = MVMDIO_XSMI_POLL_INTERVAL_MIN, - .poll_interval_max = MVMDIO_XSMI_POLL_INTERVAL_MAX, -}; - -static const struct orion_mdio_ops *orion_mdio_get_ops(struct orion_mdio_dev *dev, - int regnum) -{ - if (dev->bus_type == BUS_TYPE_XSMI && (regnum & MII_ADDR_C45)) - return &orion_mdio_xsmi_ops; - else if (dev->bus_type == BUS_TYPE_SMI) - return &orion_mdio_smi_ops; - - return ERR_PTR(-EOPNOTSUPP); -} - /* Wait for the SMI unit to be ready for another operation */ static int orion_mdio_wait_ready(const struct orion_mdio_ops *ops, @@ -241,57 +129,138 @@ static int orion_mdio_wait_ready(const struct orion_mdio_ops *ops, return -ETIMEDOUT; } -static int orion_mdio_read(struct mii_bus *bus, int mii_id, - int regnum) +/* mdio smi */ +static int orion_mdio_smi_is_done(struct orion_mdio_dev *dev) +{ + return !(readl(dev->regs) & MVMDIO_SMI_BUSY); +} + +static const struct orion_mdio_ops orion_mdio_smi_ops = { + .is_done = orion_mdio_smi_is_done, + + .poll_interval_min = MVMDIO_SMI_POLL_INTERVAL_MIN, + .poll_interval_max = MVMDIO_SMI_POLL_INTERVAL_MAX, +}; + +static int orion_mdio_smi_read(struct mii_bus *bus, int mii_id, + int regnum) { struct orion_mdio_dev *dev = bus->priv; - const struct orion_mdio_ops *ops; int ret; - ops = orion_mdio_get_ops(dev, regnum); - if (IS_ERR(ops)) - return PTR_ERR(ops); + if (regnum & MII_ADDR_C45) + return -EOPNOTSUPP; - ret = orion_mdio_wait_ready(ops, bus); + ret = orion_mdio_wait_ready(&orion_mdio_smi_ops, bus); if (ret < 0) - goto out; + return ret; - ops->start_read(dev, mii_id, regnum); + writel(((mii_id << MVMDIO_SMI_PHY_ADDR_SHIFT) | + (regnum << MVMDIO_SMI_PHY_REG_SHIFT) | + MVMDIO_SMI_READ_OPERATION), + dev->regs); - ret = orion_mdio_wait_ready(ops, bus); + ret = orion_mdio_wait_ready(&orion_mdio_smi_ops, bus); if (ret < 0) - goto out; + return ret; - if (!ops->is_read_valid(dev)) { + if (!(readl(dev->regs) & MVMDIO_SMI_READ_VALID)) { dev_err(bus->parent, "SMI bus read not valid\n"); - ret = -ENODEV; - goto out; + return -ENODEV; } - ret = ops->read(dev); -out: - return ret; + return readl(dev->regs) & GENMASK(15, 0); } -static int orion_mdio_write(struct mii_bus *bus, int mii_id, - int regnum, u16 value) +static int orion_mdio_smi_write(struct mii_bus *bus, int mii_id, + int regnum, u16 value) { struct orion_mdio_dev *dev = bus->priv; - const struct orion_mdio_ops *ops; int ret; - ops = orion_mdio_get_ops(dev, regnum); - if (IS_ERR(ops)) - return PTR_ERR(ops); + if (regnum & MII_ADDR_C45) + return -EOPNOTSUPP; - ret = orion_mdio_wait_ready(ops, bus); + ret = orion_mdio_wait_ready(&orion_mdio_smi_ops, bus); if (ret < 0) - goto out; + return ret; + + writel(((mii_id << MVMDIO_SMI_PHY_ADDR_SHIFT) | + (regnum << MVMDIO_SMI_PHY_REG_SHIFT) | + MVMDIO_SMI_WRITE_OPERATION | + (value << MVMDIO_SMI_DATA_SHIFT)), + dev->regs); - ops->write(dev, mii_id, regnum, value); + return 0; +} -out: - return ret; +/* xmdio xsmi */ +static int orion_mdio_xsmi_is_done(struct orion_mdio_dev *dev) +{ + return !(readl(dev->regs + MVMDIO_XSMI_MGNT_REG) & MVMDIO_XSMI_BUSY); +} + +static const struct orion_mdio_ops orion_mdio_xsmi_ops = { + .is_done = orion_mdio_xsmi_is_done, + + .poll_interval_min = MVMDIO_XSMI_POLL_INTERVAL_MIN, + .poll_interval_max = MVMDIO_XSMI_POLL_INTERVAL_MAX, +}; + +static int orion_mdio_xsmi_read(struct mii_bus *bus, int mii_id, + int regnum) +{ + struct orion_mdio_dev *dev = bus->priv; + u16 dev_addr = (regnum >> 16) & GENMASK(4, 0); + int ret; + + if (!(regnum & MII_ADDR_C45)) + return -EOPNOTSUPP; + + ret = orion_mdio_wait_ready(&orion_mdio_xsmi_ops, bus); + if (ret < 0) + return ret; + + writel(regnum & GENMASK(15, 0), dev->regs + MVMDIO_XSMI_ADDR_REG); + writel((mii_id << MVMDIO_XSMI_PHYADDR_SHIFT) | + (dev_addr << MVMDIO_XSMI_DEVADDR_SHIFT) | + MVMDIO_XSMI_READ_OPERATION, + dev->regs + MVMDIO_XSMI_MGNT_REG); + + ret = orion_mdio_wait_ready(&orion_mdio_xsmi_ops, bus); + if (ret < 0) + return ret; + + if (!(readl(dev->regs + MVMDIO_XSMI_MGNT_REG) & + MVMDIO_XSMI_READ_VALID)) { + dev_err(bus->parent, "XSMI bus read not valid\n"); + return -ENODEV; + } + + return readl(dev->regs + MVMDIO_XSMI_MGNT_REG) & GENMASK(15, 0); +} + +static int orion_mdio_xsmi_write(struct mii_bus *bus, int mii_id, + int regnum, u16 value) +{ + struct orion_mdio_dev *dev = bus->priv; + u16 dev_addr = (regnum >> 16) & GENMASK(4, 0); + int ret; + + if (!(regnum & MII_ADDR_C45)) + return -EOPNOTSUPP; + + ret = orion_mdio_wait_ready(&orion_mdio_xsmi_ops, bus); + if (ret < 0) + return ret; + + writel(regnum & GENMASK(15, 0), dev->regs + MVMDIO_XSMI_ADDR_REG); + writel((mii_id << MVMDIO_XSMI_PHYADDR_SHIFT) | + (dev_addr << MVMDIO_XSMI_DEVADDR_SHIFT) | + MVMDIO_XSMI_WRITE_OPERATION | value, + dev->regs + MVMDIO_XSMI_MGNT_REG); + + return 0; } static irqreturn_t orion_mdio_err_irq(int irq, void *dev_id) @@ -311,11 +280,14 @@ static irqreturn_t orion_mdio_err_irq(int irq, void *dev_id) static int orion_mdio_probe(struct platform_device *pdev) { + enum orion_mdio_bus_type type; struct resource *r; struct mii_bus *bus; struct orion_mdio_dev *dev; int i, ret; + type = (enum orion_mdio_bus_type)of_device_get_match_data(&pdev->dev); + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!r) { dev_err(&pdev->dev, "No SMI register address given\n"); @@ -328,8 +300,17 @@ static int orion_mdio_probe(struct platform_device *pdev) return -ENOMEM; bus->name = "orion_mdio_bus"; - bus->read = orion_mdio_read; - bus->write = orion_mdio_write; + + switch (type) { + case BUS_TYPE_SMI: + bus->read = orion_mdio_smi_read; + bus->write = orion_mdio_smi_write; + break; + case BUS_TYPE_XSMI: + bus->read = orion_mdio_xsmi_read; + bus->write = orion_mdio_xsmi_write; + break; + } snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(&pdev->dev)); bus->parent = &pdev->dev; @@ -371,8 +352,7 @@ static int orion_mdio_probe(struct platform_device *pdev) return -EPROBE_DEFER; } - dev->bus_type = - (enum orion_mdio_bus_type)of_device_get_match_data(&pdev->dev); + dev->bus_type = type; if (pdev->dev.of_node) ret = of_mdiobus_register(bus, pdev->dev.of_node);