From patchwork Wed Jun 7 08:38:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 9770969 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 4CDC360350 for ; Wed, 7 Jun 2017 08:51:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 305C2284B5 for ; Wed, 7 Jun 2017 08:51:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24EE628520; Wed, 7 Jun 2017 08:51:46 +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 6F990284B5 for ; Wed, 7 Jun 2017 08:51:45 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=HuLa0xqnXO4DWWCuoyelkGw5oeqHO9bhe4OeWvnbo5A=; b=KCf6tCV/cmeVPeOdZWOKCMbNlx YZndVCY8E/ngxnz0Ceiz/2+e9RNoBR91lMIk/1Mq/cu3aQsCXsS26dDjVf+pSD9rbNAywTX/ZRIF+ 4TWjI7MGF05EQSDYW6Toe0lEbq2dg8UHXIt1KwvsJENkQu7LmJpG794fR0xs3OX+EFM+64a4dHlPD cqzNosR8kCW7fEKOKFrVWfjzIJh1zAi9OoN1ttfysPlI7Px4YRPrP+tWrX/rb2IhGZY56TcTs+TH3 x6vMVhz+RLDjQy6D89/TQcgm/PqagYHd+lFC9SoGiPqxmTLM6r6x1uibyiuVoExWOPr7Tjr0mojAo lcWakJSw==; 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 1dIWgg-0002CC-AB; Wed, 07 Jun 2017 08:51:34 +0000 Received: from mail.free-electrons.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dIWVR-0007Ee-PB for linux-arm-kernel@lists.infradead.org; Wed, 07 Jun 2017 08:40:09 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id 4650121D34; Wed, 7 Jun 2017 10:39:13 +0200 (CEST) Received: from localhost (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 190B621D36; Wed, 7 Jun 2017 10:39:03 +0200 (CEST) From: Antoine Tenart To: davem@davemloft.net, jason@lakedaemon.net, andrew@lunn.ch, gregory.clement@free-electrons.com, sebastian.hesselbarth@gmail.com, f.fainelli@gmail.com Subject: [PATCH 7/9] net: mvmdio: add xmdio support Date: Wed, 7 Jun 2017 10:38:08 +0200 Message-Id: <20170607083810.30922-8-antoine.tenart@free-electrons.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607083810.30922-1-antoine.tenart@free-electrons.com> References: <20170607083810.30922-1-antoine.tenart@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170607_013958_362300_6A4B162E X-CRM114-Status: GOOD ( 17.03 ) 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, netdev@vger.kernel.org, Antoine Tenart , linux@armlinux.org.uk, mw@semihalf.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 This patch adds the xMDIO interface support in the mvmdio driver. This interface is used in Ethernet controllers on Marvell 370, 7k and 8k (as of now). The xSMI interface supported by this driver complies with the IEEE 802.3 clause 45 (while the SMI interface complies with the clause 22). The xSMI interface is used by 10GbE devices. Signed-off-by: Antoine Tenart --- drivers/net/ethernet/marvell/Kconfig | 6 +- drivers/net/ethernet/marvell/mvmdio.c | 121 ++++++++++++++++++++++++++++------ 2 files changed, 104 insertions(+), 23 deletions(-) diff --git a/drivers/net/ethernet/marvell/Kconfig b/drivers/net/ethernet/marvell/Kconfig index da6fb825afea..205bb7e683b7 100644 --- a/drivers/net/ethernet/marvell/Kconfig +++ b/drivers/net/ethernet/marvell/Kconfig @@ -35,9 +35,9 @@ config MVMDIO depends on HAS_IOMEM select PHYLIB ---help--- - This driver supports the MDIO interface found in the network - interface units of the Marvell EBU SoCs (Kirkwood, Orion5x, - Dove, Armada 370 and Armada XP). + This driver supports the MDIO and xMDIO interfaces found in + the network interface units of the Marvell EBU SoCs (Kirkwood, + Orion5x, Dove, Armada 370, Armada XP, Armada 7k and Armada 8k). This driver is used by the MV643XX_ETH and MVNETA drivers. diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/marvell/mvmdio.c index 3cb3dd3331d8..13b198aca5c1 100644 --- a/drivers/net/ethernet/marvell/mvmdio.c +++ b/drivers/net/ethernet/marvell/mvmdio.c @@ -41,6 +41,15 @@ #define MVMDIO_ERR_INT_SMI_DONE 0x00000010 #define MVMDIO_ERR_INT_MASK 0x0080 +#define MVMDIO_XSMI_MGNT_REG 0x0 +#define MVMDIO_XSMI_READ_VALID BIT(29) +#define MVMDIO_XSMI_BUSY BIT(30) +#define MVMDIO_XSMI_ADDR_REG 0x8 +#define MVMDIO_XSMI_PHYADDR_SHIFT 16 +#define MVMDIO_XSMI_DEVADDR_SHIFT 21 +#define MVMDIO_XSMI_READ_OPERATION (0x7 << 26) +#define MVMDIO_XSMI_WRITE_OPERATION (0x5 << 27) + /* * SMI Timeout measurements: * - Kirkwood 88F6281 (Globalscale Dreamplug): 45us to 95us (Interrupt) @@ -50,6 +59,9 @@ #define MVMDIO_SMI_POLL_INTERVAL_MIN 45 #define MVMDIO_SMI_POLL_INTERVAL_MAX 55 +#define MVMDIO_XSMI_POLL_INTERVAL_MIN 150 +#define MVMDIO_XSMI_POLL_INTERVAL_MAX 160 + struct orion_mdio_dev { struct mutex lock; void __iomem *regs; @@ -76,18 +88,19 @@ struct orion_mdio_ops { void (*write)(struct orion_mdio_dev *, int, int, u16); }; -static int orion_mdio_smi_is_done(struct orion_mdio_dev *dev) +/* smi */ +static int 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) +static int smi_is_read_valid(struct orion_mdio_dev *dev) { return !(readl(dev->regs) & MVMDIO_SMI_READ_VALID); } -static void orion_mdio_start_read_op(struct orion_mdio_dev *dev, int mii_id, - int regnum) +static void 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) | @@ -95,13 +108,13 @@ static void orion_mdio_start_read_op(struct orion_mdio_dev *dev, int mii_id, dev->regs); } -static u16 orion_mdio_read_op(struct orion_mdio_dev *dev) +static u16 smi_read_op(struct orion_mdio_dev *dev) { return readl(dev->regs) & GENMASK(15,0); } -static void orion_mdio_write_op(struct orion_mdio_dev *dev, int mii_id, - int regnum, u16 value) +static void 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) | @@ -110,6 +123,47 @@ static void orion_mdio_write_op(struct orion_mdio_dev *dev, int mii_id, dev->regs); } +/* xsmi */ +static int xsmi_is_done(struct orion_mdio_dev *dev) +{ + return !(readl(dev->regs + MVMDIO_XSMI_MGNT_REG) & MVMDIO_XSMI_BUSY); +} + +static int xsmi_is_read_valid(struct orion_mdio_dev *dev) +{ + return !(readl(dev->regs + MVMDIO_XSMI_MGNT_REG) & + MVMDIO_XSMI_READ_VALID); +} + +static void xsmi_start_read_op(struct orion_mdio_dev *dev, int mii_id, + int regnum) +{ + u16 dev_addr = regnum >> 16; + + 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 xsmi_read_op(struct orion_mdio_dev *dev) +{ + return readl(dev->regs + MVMDIO_XSMI_MGNT_REG) & GENMASK(15,0); +} + +static void xsmi_write_op(struct orion_mdio_dev *dev, int mii_id, + int regnum, u16 value) +{ + u16 dev_addr = regnum >> 16; + + 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); +} + /* Wait for the SMI unit to be ready for another operation */ static int orion_mdio_wait_ready(struct mii_bus *bus) @@ -213,12 +267,47 @@ static irqreturn_t orion_mdio_err_irq(int irq, void *dev_id) return IRQ_NONE; } +static int orion_mdio_populate_ops(struct platform_device *pdev, + struct orion_mdio_dev *dev) +{ + struct orion_mdio_ops *ops; + struct device_node *np = pdev->dev.of_node; + + ops = devm_kzalloc(&pdev->dev, sizeof(*ops), GFP_KERNEL); + if (!ops) + return -ENOMEM; + + if (of_device_is_compatible(np, "marvell,orion-mdio")) { + ops->is_done = smi_is_done; + ops->is_read_valid = smi_is_read_valid; + ops->start_read = smi_start_read_op; + ops->read = smi_read_op; + ops->write = smi_write_op; + + dev->poll_interval_min = MVMDIO_SMI_POLL_INTERVAL_MIN; + dev->poll_interval_max = MVMDIO_SMI_POLL_INTERVAL_MAX; + } else if (of_device_is_compatible(np, "marvell,xmdio")) { + ops->is_done = xsmi_is_done; + ops->is_read_valid = xsmi_is_read_valid; + ops->start_read = xsmi_start_read_op; + ops->read = xsmi_read_op; + ops->write = xsmi_write_op; + + dev->poll_interval_min = MVMDIO_XSMI_POLL_INTERVAL_MIN; + dev->poll_interval_max = MVMDIO_XSMI_POLL_INTERVAL_MAX; + } else { + return -EINVAL; + } + + dev->ops = ops; + return 0; +} + static int orion_mdio_probe(struct platform_device *pdev) { struct resource *r; struct mii_bus *bus; struct orion_mdio_dev *dev; - struct orion_mdio_ops *ops; int i, ret; r = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -278,18 +367,9 @@ static int orion_mdio_probe(struct platform_device *pdev) mutex_init(&dev->lock); - ops = devm_kzalloc(&pdev->dev, sizeof(*ops), GFP_KERNEL); - if (!ops) - return -ENOMEM; - - dev->poll_interval_min = MVMDIO_SMI_POLL_INTERVAL_MIN; - dev->poll_interval_max = MVMDIO_SMI_POLL_INTERVAL_MAX; - ops->is_done = orion_mdio_smi_is_done; - ops->is_read_valid = orion_mdio_smi_is_read_valid; - ops->start_read = orion_mdio_start_read_op; - ops->read = orion_mdio_read_op; - ops->write = orion_mdio_write_op; - dev->ops = ops; + ret = orion_mdio_populate_ops(pdev, dev); + if (ret) + return ret; if (pdev->dev.of_node) ret = of_mdiobus_register(bus, pdev->dev.of_node); @@ -340,6 +420,7 @@ static int orion_mdio_remove(struct platform_device *pdev) static const struct of_device_id orion_mdio_match[] = { { .compatible = "marvell,orion-mdio" }, + { .compatible = "marvell,xmdio" }, { } }; MODULE_DEVICE_TABLE(of, orion_mdio_match);