Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3602952pxb; Mon, 24 Jan 2022 13:16:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzfTxzBEgiRPcrPbkLE6FBdW40ruxptGvnrlXIW2PQxaqaLHfvkfBNBywR5QHj3dp/MhnKY X-Received: by 2002:a63:ad0e:: with SMTP id g14mr12818207pgf.408.1643059017187; Mon, 24 Jan 2022 13:16:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643059017; cv=none; d=google.com; s=arc-20160816; b=n1yNsvO9YO5WArHmTzhy+w0GXfuCfEm1SiZGu2K6+fv0BjCQpG6Wvgo7ZeAsIEzgzK JXqI3bRh1KlF/1d3Jh0aRzTC21PsK9aSy5cij8fsBkf4ksQV0HTm83EA2xrkDNzLu9f+ lwsPf812fL49gdZ+Q6XvtQICSgbH+x69YdqYVrZT1JXOb2faaXVnI4oQSqaYB7azL9ce sNv2cQC5gBQ6PTW1rEa521Lu9RVYwZ4l9htg1cIVFFtNEcOAeENR8sOEhxJSZ/GIplpo 5hJLYg2i10UEAEdkD4dRtPmh+3ubwu7/7ZKywel6+4ckARsjJ4vzSPWcEuQIv+h3HnxG doSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8SWivXiPBpkXdMH8dg8qJmqoQjJWNly9aRl2JF5aLEg=; b=nKSOUEmHAXynubq8TG9/2lpbiozT8P2whn6aMQ/yg2cjg4zwvbgNeh+LsOkusK9kM1 TKYuf0ZpCL0KkeAp0Jr2nrLRnd+kagwp6Va065O735Nlc5aYOYgbK9vz9Or16LUHVhMV S2aSdHGXuzw1AsX7xjWRqo7vQNdeD42fC9JnPF8/FjAZYIhR9qThfyY7fqYm3g3RZtfF R1aJRv6by/frBcE2qSzcpwWy3SxXvgmvqM4BtTBTho5i1d1LNLWAKhp7p5wNt5NHum8V GwmiyPzcBa+qVWOfxNdGmV5VpAPz+XvZDDFpYC0mfueSDD2AUIMuzYUeNJW2oW3x5ExT q6mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="uFeggJW/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l190si8324792pge.482.2022.01.24.13.16.44; Mon, 24 Jan 2022 13:16:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="uFeggJW/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358204AbiAXUn6 (ORCPT + 99 others); Mon, 24 Jan 2022 15:43:58 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:59238 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382039AbiAXUZJ (ORCPT ); Mon, 24 Jan 2022 15:25:09 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2BF6CB8121A; Mon, 24 Jan 2022 20:25:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85392C340E5; Mon, 24 Jan 2022 20:25:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055906; bh=xdgjS3mVQChhF70ldCsToTvWsLdPLVKFsZ1ngsqTNhA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uFeggJW/ZUZHkxK6jsIkQ5mgAYbw1daSsqLvBKE72dxXiGUqxO4Pl73qrzoWN//zX HbqD3sdejx7x9fmVNvyxSMa5r2LyqVxXSL4nKOCgtSq7EbNTamL2m1FtBly2PIrDEk Wk/76wCaGGJkHM7x4A6DJuCX+p29L2iyNbjkuFkg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Golle , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 306/846] net: ethernet: mtk_eth_soc: fix return values and refactor MDIO ops Date: Mon, 24 Jan 2022 19:37:03 +0100 Message-Id: <20220124184111.466072787@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Golle [ Upstream commit eda80b249df7bbc7b3dd13907343a3e59bfc57fd ] Instead of returning -1 (-EPERM) when MDIO bus is stuck busy while writing or 0xffff if it happens while reading, return the appropriate -ETIMEDOUT. Also fix return type to int instead of u32. Refactor functions to use bitfield helpers instead of having various masking and shifting constants in the code, which also results in the register definitions in the header file being more obviously related to what is stated in the MediaTek's Reference Manual. Fixes: 656e705243fd0 ("net-next: mediatek: add support for MT7623 ethernet") Signed-off-by: Daniel Golle Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 53 ++++++++++++--------- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 16 +++++-- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index 398c23cec8151..9e7a872426fc4 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -91,46 +91,53 @@ static int mtk_mdio_busy_wait(struct mtk_eth *eth) } dev_err(eth->dev, "mdio: MDIO timeout\n"); - return -1; + return -ETIMEDOUT; } -static u32 _mtk_mdio_write(struct mtk_eth *eth, u32 phy_addr, - u32 phy_register, u32 write_data) +static int _mtk_mdio_write(struct mtk_eth *eth, u32 phy_addr, u32 phy_reg, + u32 write_data) { - if (mtk_mdio_busy_wait(eth)) - return -1; + int ret; - write_data &= 0xffff; + ret = mtk_mdio_busy_wait(eth); + if (ret < 0) + return ret; - mtk_w32(eth, PHY_IAC_ACCESS | PHY_IAC_START | PHY_IAC_WRITE | - (phy_register << PHY_IAC_REG_SHIFT) | - (phy_addr << PHY_IAC_ADDR_SHIFT) | write_data, + mtk_w32(eth, PHY_IAC_ACCESS | + PHY_IAC_START_C22 | + PHY_IAC_CMD_WRITE | + PHY_IAC_REG(phy_reg) | + PHY_IAC_ADDR(phy_addr) | + PHY_IAC_DATA(write_data), MTK_PHY_IAC); - if (mtk_mdio_busy_wait(eth)) - return -1; + ret = mtk_mdio_busy_wait(eth); + if (ret < 0) + return ret; return 0; } -static u32 _mtk_mdio_read(struct mtk_eth *eth, int phy_addr, int phy_reg) +static int _mtk_mdio_read(struct mtk_eth *eth, u32 phy_addr, u32 phy_reg) { - u32 d; + int ret; - if (mtk_mdio_busy_wait(eth)) - return 0xffff; + ret = mtk_mdio_busy_wait(eth); + if (ret < 0) + return ret; - mtk_w32(eth, PHY_IAC_ACCESS | PHY_IAC_START | PHY_IAC_READ | - (phy_reg << PHY_IAC_REG_SHIFT) | - (phy_addr << PHY_IAC_ADDR_SHIFT), + mtk_w32(eth, PHY_IAC_ACCESS | + PHY_IAC_START_C22 | + PHY_IAC_CMD_C22_READ | + PHY_IAC_REG(phy_reg) | + PHY_IAC_ADDR(phy_addr), MTK_PHY_IAC); - if (mtk_mdio_busy_wait(eth)) - return 0xffff; - - d = mtk_r32(eth, MTK_PHY_IAC) & 0xffff; + ret = mtk_mdio_busy_wait(eth); + if (ret < 0) + return ret; - return d; + return mtk_r32(eth, MTK_PHY_IAC) & PHY_IAC_DATA_MASK; } static int mtk_mdio_write(struct mii_bus *bus, int phy_addr, diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h index 5ef70dd8b49c6..f2d90639d7ed1 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h @@ -341,11 +341,17 @@ /* PHY Indirect Access Control registers */ #define MTK_PHY_IAC 0x10004 #define PHY_IAC_ACCESS BIT(31) -#define PHY_IAC_READ BIT(19) -#define PHY_IAC_WRITE BIT(18) -#define PHY_IAC_START BIT(16) -#define PHY_IAC_ADDR_SHIFT 20 -#define PHY_IAC_REG_SHIFT 25 +#define PHY_IAC_REG_MASK GENMASK(29, 25) +#define PHY_IAC_REG(x) FIELD_PREP(PHY_IAC_REG_MASK, (x)) +#define PHY_IAC_ADDR_MASK GENMASK(24, 20) +#define PHY_IAC_ADDR(x) FIELD_PREP(PHY_IAC_ADDR_MASK, (x)) +#define PHY_IAC_CMD_MASK GENMASK(19, 18) +#define PHY_IAC_CMD_WRITE FIELD_PREP(PHY_IAC_CMD_MASK, 1) +#define PHY_IAC_CMD_C22_READ FIELD_PREP(PHY_IAC_CMD_MASK, 2) +#define PHY_IAC_START_MASK GENMASK(17, 16) +#define PHY_IAC_START_C22 FIELD_PREP(PHY_IAC_START_MASK, 1) +#define PHY_IAC_DATA_MASK GENMASK(15, 0) +#define PHY_IAC_DATA(x) FIELD_PREP(PHY_IAC_DATA_MASK, (x)) #define PHY_IAC_TIMEOUT HZ #define MTK_MAC_MISC 0x1000c -- 2.34.1