Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3705528pxb; Mon, 24 Jan 2022 15:54:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJy0MVyr5niv0a1MNQoIGxamau1DtN2s5rfXzz6WnoAs3u8BqEGzhsAkSoO5wYo7uKd9uWw0 X-Received: by 2002:a17:90b:3e8e:: with SMTP id rj14mr607450pjb.207.1643068468576; Mon, 24 Jan 2022 15:54:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643068468; cv=none; d=google.com; s=arc-20160816; b=mAElklVi4X7tCDWJwVPfCadEIzoAIhbCjjHw6i/l9luGRYANBg1jjj43Mp86XTkcBC ujnKl+59vI5B0z6pBZAO0YzQxiHOvi03UBjEuAsBYeHGOoxmr37BXYlUfjUXHv/8MXdP yG7w41YebsE5E06s29hcFaBZFOpIDfNbEHyja2B9Xk7J+LzWns1yFE5bl4ZpYAWks3S7 ukzw5TPpf6q+DlFlsI4fYisnuNDYxgjzT/eiigdMho7QmrlKsJUNeqAgH3R79QQgFJ3a WsY5ZCiAenGLcN/5Wl37LWCcOJ3jDAm+9MCQKh7kIAUjwK0vr0GK+tzZer0i5Oj1vA4c x3zQ== 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=UdZsoN010jM0kGjGx94wC79/lYmyMZ5OhTptBqPopIQ=; b=zgj3dm6VI+YJvGpChHQqZRNMpVKMBNTPR4kAloXQcvNJ+wfeh7OGqJlmxrItu+EO40 dvyOn2/+XYYxkOQ6FmUbD9SLlbMJxYavfPxRSY4HMhNNeYXp3Ky6kiJWqojjtaB8VQ1+ 55KVl5n6KKa2q5CR5ZyT4/WIVm7MB0vpuwVRWPMU8ImyhRvnXJsZwIxFFJd+QuuELPm1 PUlhUEuc/pNob+Kb2vdwcuBBfGgcO4yGiXQV4/KPzv3OfKPXXmkbYHbpvsIqyT5e9ETv RFe6g7D1Mik14k6XpcAv510BH6kr78dEeNv3Nr9Xoo9qtgVl/HCJUDV297SOt451NnBU llcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="YzRyBZR/"; 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 i6si14700495pgq.608.2022.01.24.15.54.16; Mon, 24 Jan 2022 15:54:28 -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="YzRyBZR/"; 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 S2362295AbiAXXmJ (ORCPT + 99 others); Mon, 24 Jan 2022 18:42:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1841093AbiAXW5g (ORCPT ); Mon, 24 Jan 2022 17:57:36 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17FE9C055ABD; Mon, 24 Jan 2022 13:11:51 -0800 (PST) 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 D55EAB8121C; Mon, 24 Jan 2022 21:11:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4F6FC340E8; Mon, 24 Jan 2022 21:11:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058708; bh=50E6Rx/1hjD8ce3GLxo312lfRaJ+k/VnmDjEgimOyp8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YzRyBZR/aZlM+3FYFPcDckYcClD3Vz4I2PNT4Yph8Z7SpFhvXwCR1pU1pXTzq8rsV TO43SSbwfX3+nfbB6GYSP7XEzfJhrppAdHaH4bdhr32PHQvhL+shOvYKohKOBD6YHt GIPFXiwVlX2HJo2eH8vo1u2BCy0lUrM22Sf9JafY= 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.16 0369/1039] net: ethernet: mtk_eth_soc: fix return values and refactor MDIO ops Date: Mon, 24 Jan 2022 19:35:58 +0100 Message-Id: <20220124184137.699085044@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 75d67d1b5f6b2..ab023d3ca81f9 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