From patchwork Tue Aug 6 15:51:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nevo Hed X-Patchwork-Id: 1142901 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=starry.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=starry.com header.i=@starry.com header.b="ZduG9xTh"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 462zhc1np8z9s7T for ; Wed, 7 Aug 2019 01:54:08 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 035B6C21DC1; Tue, 6 Aug 2019 15:52:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 2FF94C21EFF; Tue, 6 Aug 2019 15:52:13 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7E19DC21E3B; Tue, 6 Aug 2019 15:52:05 +0000 (UTC) Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by lists.denx.de (Postfix) with ESMTPS id 2DC28C21E79 for ; Tue, 6 Aug 2019 15:52:05 +0000 (UTC) Received: by mail-qt1-f193.google.com with SMTP id h21so84960000qtn.13 for ; Tue, 06 Aug 2019 08:52:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=starry.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I18dLX49uMb2yNSavLXWgHQWd/A4wAeTmVisMKG2p58=; b=ZduG9xThJPKv8QwSrVYbualn4k9UwzEp2jXSWdMfuHAWTTZwbC2Lyd0gc8/b1lYlzU WgOvzHQ6gvIrMzbMt9gRf2p6aHgLYdWZ18VrDY7bwTtblvmRrdHZIR2vJ89cSRz2j1SM 5b4zq+3S1gJmS8jYWWqpJla6Map63QVPwmCHk= 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=I18dLX49uMb2yNSavLXWgHQWd/A4wAeTmVisMKG2p58=; b=fhjjQv2NmIKe6CSsq8Kr8P8eYdxr4KPLRZ6/sat2LDqAcLhvFWYZdikawgSabLWI/n umicLqgihR2P1+V/yEfqWvExifsiXede3KMvTjs4ndbGnAP/afmv1Pi8DivcYCRc01p7 4D3Dtu65miV+uHrfLM6sfTN6RxRrPb22lYEbutIcGgPkrpUZ/JG+q/n6WIgCh1zo4+kx LORPWhAaQdJ/DUouJjemAtpi9E0GW6OPormM22FK7HCsBb6wqH00544heU7P3leqHqpl qnT0ITX3qJeqVkKTLTuw/gMIsyI9Mm6BsZ0impCe6eZiFJqImAiqE6mSNV7qb5UDVWeU 5Jyg== X-Gm-Message-State: APjAAAUqEEqJX5/m+NiN66P3AeJ8FUK+1L6sArjSXVRw9d2r3fBMkJ1J Y24wgrT2+EIKLP510TYrXq0MfA== X-Google-Smtp-Source: APXvYqw+spyZEr43EKNWC6CE3oaAS9dr/eOEU+BOvZV6ys7XSplnzlMf5qF4nvgoRG2LohIkfzFtzg== X-Received: by 2002:a0c:9807:: with SMTP id c7mr3695741qvd.26.1565106724009; Tue, 06 Aug 2019 08:52:04 -0700 (PDT) Received: from nhed-lt1 (205-201-16-55.starry-inc.net. [205.201.16.55]) by smtp.gmail.com with ESMTPSA id l8sm1928421qtr.38.2019.08.06.08.52.03 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Aug 2019 08:52:03 -0700 (PDT) From: nhed+uboot@starry.com To: u-boot@lists.denx.de Date: Tue, 6 Aug 2019 11:51:39 -0400 Message-Id: <20190806155144.19301-3-nhed+uboot@starry.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190806155144.19301-1-nhed+uboot@starry.com> References: <20190806155144.19301-1-nhed+uboot@starry.com> MIME-Version: 1.0 Cc: make@marvell.com, Nevo Hed Subject: [U-Boot] [PATCH v3 2/7] net: mvpp2: Replace SMI implementation with marvell MDIO API X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Ken Ma The availability of the marvell MDIO driver enables us to eliminate the SMI function implementation within the mvpp2 driver. This replacement also fixes 2 old issues: 1. Each pp2 port device now has its own mdio bus field member since some pp2 ports may use SMI mdio bus while some other pp2 ports may use XSMI mdio bus, but the old mvpp2_base device has a shared bus for all its pp2 ports; this patch moves mdio bus field member from struct mvpp2 to struct mvpp2_port; 2. Old code uses mvpp2_base device name as mdio bus name; but for Armada80x0, cp0 ethernet device and cp1 ethernet device have the same device name - "ethernet@0"; and because mdio_register() checks unique name, then the second probed mvpp2_base device fails to register mdio bus; since new marvell MDIO driver has resolved the unique name issue - different mdio names can be set in fdt and if a mdio name is not set, the default mdio name is generated from the mdio bus base address, so this issue is fixed by this replacement. Signed-off-by: Ken Ma Reviewed-by: Igal Liberman Tested-by: Igal Liberman Signed-off-by: Nevo Hed Reviewed-By: Ramon Fried --- drivers/net/mvpp2.c | 158 ++++---------------------------------------- 1 file changed, 12 insertions(+), 146 deletions(-) diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c index f36c8236b1..b6dfed5c54 100644 --- a/drivers/net/mvpp2.c +++ b/drivers/net/mvpp2.c @@ -32,6 +32,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -62,8 +63,6 @@ do { \ #define MTU 1500 #define RX_BUFFER_SIZE (ALIGN(MTU + WRAP, ARCH_DMA_MINALIGN)) -#define MVPP2_SMI_TIMEOUT 10000 - /* RX Fifo Registers */ #define MVPP2_RX_DATA_FIFO_SIZE_REG(port) (0x00 + 4 * (port)) #define MVPP2_RX_ATTR_FIFO_SIZE_REG(port) (0x20 + 4 * (port)) @@ -490,23 +489,8 @@ do { \ #define MVPP2_QUEUE_NEXT_DESC(q, index) \ (((index) < (q)->last_desc) ? ((index) + 1) : 0) -/* SMI: 0xc0054 -> offset 0x54 to lms_base */ -#define MVPP21_SMI 0x0054 /* PP2.2: SMI: 0x12a200 -> offset 0x1200 to iface_base */ #define MVPP22_SMI 0x1200 -#define MVPP2_PHY_REG_MASK 0x1f -/* SMI register fields */ -#define MVPP2_SMI_DATA_OFFS 0 /* Data */ -#define MVPP2_SMI_DATA_MASK (0xffff << MVPP2_SMI_DATA_OFFS) -#define MVPP2_SMI_DEV_ADDR_OFFS 16 /* PHY device address */ -#define MVPP2_SMI_REG_ADDR_OFFS 21 /* PHY device reg addr*/ -#define MVPP2_SMI_OPCODE_OFFS 26 /* Write/Read opcode */ -#define MVPP2_SMI_OPCODE_READ (1 << MVPP2_SMI_OPCODE_OFFS) -#define MVPP2_SMI_READ_VALID (1 << 27) /* Read Valid */ -#define MVPP2_SMI_BUSY (1 << 28) /* Busy */ - -#define MVPP2_PHY_ADDR_MASK 0x1f -#define MVPP2_PHY_REG_MASK 0x1f /* Additional PPv2.2 offsets */ #define MVPP22_MPCS 0x007000 @@ -973,7 +957,6 @@ struct mvpp2_port { struct phy_device *phy_dev; phy_interface_t phy_interface; - int phy_node; int phyaddr; struct mii_dev *bus; #ifdef CONFIG_DM_GPIO @@ -4562,7 +4545,7 @@ static int mvpp2_open(struct udevice *dev, struct mvpp2_port *port) return err; } - if (port->phy_node) { + if (port->phyaddr < PHY_MAX_ADDR) { mvpp2_phy_connect(dev, port); mvpp2_link_event(port); } else { @@ -4701,6 +4684,7 @@ static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port) u32 id; u32 phyaddr = 0; int phy_mode = -1; + int ret; /* Default mdio_base from the same eth base */ if (port->priv->hw_version == MVPP21) @@ -4719,17 +4703,12 @@ static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port) dev_err(&pdev->dev, "could not find phy address\n"); return -1; } - - phy_ofnode = ofnode_get_parent(offset_to_ofnode(phy_node)); - phy_base = ofnode_get_addr(phy_ofnode); - port->mdio_base = (void *)phy_base; - - if (port->mdio_base < 0) { - dev_err(&pdev->dev, "could not find mdio base address\n"); - return -1; - } + ret = mdio_mii_bus_get_from_phy(phy_node, &port->bus); + if (ret) + return ret; } else { - phy_node = 0; + /* phy_addr is set to invalid value */ + phyaddr = PHY_MAX_ADDR; } phy_mode_str = fdt_getprop(gd->fdt_blob, port_node, "phy-mode", NULL); @@ -4767,7 +4746,6 @@ static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port) port->first_rxq = port->id * rxq_number; else port->first_rxq = port->id * port->priv->max_port_rxqs; - port->phy_node = phy_node; port->phy_interface = phy_mode; port->phyaddr = phyaddr; @@ -5044,119 +5022,7 @@ static int mvpp2_init(struct udevice *dev, struct mvpp2 *priv) return 0; } -/* SMI / MDIO functions */ - -static int smi_wait_ready(struct mvpp2_port *priv) -{ - u32 timeout = MVPP2_SMI_TIMEOUT; - u32 smi_reg; - - /* wait till the SMI is not busy */ - do { - /* read smi register */ - smi_reg = readl(priv->mdio_base); - if (timeout-- == 0) { - printf("Error: SMI busy timeout\n"); - return -EFAULT; - } - } while (smi_reg & MVPP2_SMI_BUSY); - - return 0; -} - -/* - * mpp2_mdio_read - miiphy_read callback function. - * - * Returns 16bit phy register value, or 0xffff on error - */ -static int mpp2_mdio_read(struct mii_dev *bus, int addr, int devad, int reg) -{ - struct mvpp2_port *priv = bus->priv; - u32 smi_reg; - u32 timeout; - - /* check parameters */ - if (addr > MVPP2_PHY_ADDR_MASK) { - printf("Error: Invalid PHY address %d\n", addr); - return -EFAULT; - } - - if (reg > MVPP2_PHY_REG_MASK) { - printf("Err: Invalid register offset %d\n", reg); - return -EFAULT; - } - - /* wait till the SMI is not busy */ - if (smi_wait_ready(priv) < 0) - return -EFAULT; - - /* fill the phy address and regiser offset and read opcode */ - smi_reg = (addr << MVPP2_SMI_DEV_ADDR_OFFS) - | (reg << MVPP2_SMI_REG_ADDR_OFFS) - | MVPP2_SMI_OPCODE_READ; - - /* write the smi register */ - writel(smi_reg, priv->mdio_base); - - /* wait till read value is ready */ - timeout = MVPP2_SMI_TIMEOUT; - - do { - /* read smi register */ - smi_reg = readl(priv->mdio_base); - if (timeout-- == 0) { - printf("Err: SMI read ready timeout\n"); - return -EFAULT; - } - } while (!(smi_reg & MVPP2_SMI_READ_VALID)); - - /* Wait for the data to update in the SMI register */ - for (timeout = 0; timeout < MVPP2_SMI_TIMEOUT; timeout++) - ; - - return readl(priv->mdio_base) & MVPP2_SMI_DATA_MASK; -} - -/* - * mpp2_mdio_write - miiphy_write callback function. - * - * Returns 0 if write succeed, -EINVAL on bad parameters - * -ETIME on timeout - */ -static int mpp2_mdio_write(struct mii_dev *bus, int addr, int devad, int reg, - u16 value) -{ - struct mvpp2_port *priv = bus->priv; - u32 smi_reg; - - /* check parameters */ - if (addr > MVPP2_PHY_ADDR_MASK) { - printf("Error: Invalid PHY address %d\n", addr); - return -EFAULT; - } - - if (reg > MVPP2_PHY_REG_MASK) { - printf("Err: Invalid register offset %d\n", reg); - return -EFAULT; - } - - /* wait till the SMI is not busy */ - if (smi_wait_ready(priv) < 0) - return -EFAULT; - - /* fill the phy addr and reg offset and write opcode and data */ - smi_reg = value << MVPP2_SMI_DATA_OFFS; - smi_reg |= (addr << MVPP2_SMI_DEV_ADDR_OFFS) - | (reg << MVPP2_SMI_REG_ADDR_OFFS); - smi_reg &= ~MVPP2_SMI_OPCODE_READ; - - /* write the smi register */ - writel(smi_reg, priv->mdio_base); - - return 0; -} - -static int mvpp2_recv(struct udevice *dev, int flags, uchar **packetp) +int mvpp2_recv(struct udevice *dev, int flags, uchar **packetp) { struct mvpp2_port *port = dev_get_priv(dev); struct mvpp2_rx_desc *rx_desc; @@ -5168,7 +5034,7 @@ static int mvpp2_recv(struct udevice *dev, int flags, uchar **packetp) struct mvpp2_rx_queue *rxq; u8 *data; - if (port->phy_node) + if (port->phyaddr < PHY_MAX_ADDR) if (!port->phy_dev->link) return 0; @@ -5237,7 +5103,7 @@ static int mvpp2_send(struct udevice *dev, void *packet, int length) int tx_done; int timeout; - if (port->phy_node) + if (port->phyaddr < PHY_MAX_ADDR) if (!port->phy_dev->link) return 0; @@ -5474,7 +5340,7 @@ static int mvpp2_probe(struct udevice *dev) port->gop_id * MVPP22_PORT_OFFSET; /* Set phy address of the port */ - if(port->phy_node) + if (port->phyaddr < PHY_MAX_ADDR) mvpp22_smi_phy_addr_cfg(port); /* GoP Init */