From patchwork Fri Dec 16 16:17:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 33997 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp1059650wrn; Fri, 16 Dec 2022 08:18:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf4gh5lKBx4zNZXIOCTv3fEHWLbhin2M5Fukh4vnI4ndUwiW7qriscdOwxHopRuwyl2VlvgF X-Received: by 2002:a17:906:868f:b0:7c0:d88b:1695 with SMTP id g15-20020a170906868f00b007c0d88b1695mr30082230ejx.55.1671207528290; Fri, 16 Dec 2022 08:18:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671207528; cv=none; d=google.com; s=arc-20160816; b=Ja9p3JKdNGD6hSK8knx5dT+mSK0jhU9M4RAtPuSF6z05eegD7wAueIBVxIvaOh7mOX Uj+Z3VT1zOYDtl5ItAhtZq2x2hsoLFocQCwdF3t5JepoQyOFQLoXcBS4qXhYSWohTy+y 0dTfva+Fdt+lZTqcA9jwcXbKgKsYUxaes0eiYItYKfEJY2JbO0SbH82gilfITg2ATJ+N n6i/RJh73FdphkGHLN/TE/MZq8ThiOTFfhc0Mq4duDS9tjYmf6bCwF4K3dVWkSEoDWf5 8p1WTNoGBGwaHLKvDK6nzE7aHom/oUa8XYf+VPdkiLfOpkiLhnzU6C9ECtGtRCaQk261 PDtw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RkJKVUgt9KZftJMXu3IPRrd/BPLaQPA4lfamAmDQzlQ=; b=A0kOBj6GJ35dBVDthLvX4ObXIWxJXINxhB+CJ7++twdrtQUsKs3nyo3l0xJArlgxOx 5kbZnLQQ5a6vmdYGvFRHASsuninyaSb3FY4ZZqY1/2l25VkjO7Irf6BDjA6/OnlkADnE wUz+nbmAfSi5mcqi8ZY7bUk03bXph8eMHZzUTbQ2V58uLmwZKtFoOUifgqxLT9+GyFvz rv9iuRZGYeFM5W3+5/uy32+dfWhV17Ejptmc0oBrijWkO+VFNg4AsLQxR+9BiywvTcSt 4WU0sd5fBMFzbfdt7V4rxILRSQfJg4hTcH9lHoRV3+TYiB2WKS/LBrND0l4HyzxeZRtS DO6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AK9QygFP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id tc10-20020a1709078d0a00b007c18d5fe285si2253329ejc.713.2022.12.16.08.18.23; Fri, 16 Dec 2022 08:18:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AK9QygFP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231648AbiLPQSI (ORCPT + 99 others); Fri, 16 Dec 2022 11:18:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231869AbiLPQRz (ORCPT ); Fri, 16 Dec 2022 11:17:55 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AE6BDEED; Fri, 16 Dec 2022 08:17:54 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id i7so2990618wrv.8; Fri, 16 Dec 2022 08:17:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RkJKVUgt9KZftJMXu3IPRrd/BPLaQPA4lfamAmDQzlQ=; b=AK9QygFPw664p8EF3uhWnlPwjpUzVf4TDrYoH5xjrfvCbNbrSNdx5kzTv0T1BbcEEn j/PRTQ/xnnl22n6uttVGyvnvivcmqrcCVDr4UBk9NhwI1xLwndXG8ahep+qc5jdZmwlq YJnevGVZyq7OPmNrfc0fHuiyixORl6z2W7vrdAyx654IqDyMiSU8h5dK11bTc1E1sTYe q2NLXxXWvlGY5Of/5NU8d1jnT4HcNO4mctMy78+bljbdDXoD6y8iLuD7ogSRWAegTCpR ODa0bM8s4OydJ4SISwUpPL0I5drLTrY0fe6fVudnobLOGKezN/aB7ntDFTmoC+/9Klnc y7fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RkJKVUgt9KZftJMXu3IPRrd/BPLaQPA4lfamAmDQzlQ=; b=EFGK2jNKQPAfisPXxYVzHvIT73U5RUz7lG7UkiTiuG0fgRaTMqCO9b/xQhZZ44v3Mu reAz0OEhJZJtwAwlgh8Fead8z7nEjcB162QMXxK/DLKPvraxJI47xp97JXbiaPNpcP5f NS8YlMsyqBjjwG8+8xoITDv8MB5tobAHNQEwurHfi2n6t8TmO5YnLo/lCDBZydqZOvBu JakYzLbWnCgYFkaMUuCfF/UkRgfJYKhB7ubgZouq0ahfMcDUh0Q+XL5/7zjWStbArsVE F+rd+b/TexUbF1d4qlxq+v5aZZzu6vWyaOTd67LpG6oqnLU/akHygl20E2RhyQf5AJZl X6bA== X-Gm-Message-State: ANoB5pmHaf+7syUkX3i2VT2G+0i9oEqR3/UT6jsDmpJmKFjdTgU+fdmY 15Q11vk7MySBxE3eyvjg8C8= X-Received: by 2002:adf:d84f:0:b0:242:219b:614 with SMTP id k15-20020adfd84f000000b00242219b0614mr19476258wrl.65.1671207472981; Fri, 16 Dec 2022 08:17:52 -0800 (PST) Received: from localhost.localdomain (93-42-71-18.ip85.fastwebnet.it. [93.42.71.18]) by smtp.googlemail.com with ESMTPSA id bj19-20020a0560001e1300b002238ea5750csm3079720wrb.72.2022.12.16.08.17.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 08:17:52 -0800 (PST) From: Christian Marangi To: Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , "Russell King (Oracle)" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ronald Wahl , stable@vger.kernel.org Subject: [net PATCH 3/5] Revert "net: dsa: qca8k: cache lo and hi for mdio write" Date: Fri, 16 Dec 2022 17:17:19 +0100 Message-Id: <20221216161721.23863-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221216161721.23863-1-ansuelsmth@gmail.com> References: <20221216161721.23863-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752388104865966491?= X-GMAIL-MSGID: =?utf-8?q?1752388104865966491?= This reverts commit 2481d206fae7884cd07014fd1318e63af35e99eb. The Documentation is very confusing about the topic. The cache logic for hi and lo is wrong and actually miss some regs to be actually written. What the Docuemntation actually intended was that it's possible to skip writing hi OR lo if half of the reg is not needed to be written or read. Revert the change in favor of a better and correct implementation. Reported-by: Ronald Wahl Signed-off-by: Christian Marangi Cc: stable@vger.kernel.org # v5.18+ --- drivers/net/dsa/qca/qca8k-8xxx.c | 61 +++++++------------------------- drivers/net/dsa/qca/qca8k.h | 5 --- 2 files changed, 12 insertions(+), 54 deletions(-) diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c index 46151320b2a8..fbcd5c2b13ae 100644 --- a/drivers/net/dsa/qca/qca8k-8xxx.c +++ b/drivers/net/dsa/qca/qca8k-8xxx.c @@ -36,44 +36,6 @@ qca8k_split_addr(u32 regaddr, u16 *r1, u16 *r2, u16 *page) *page = regaddr & 0x3ff; } -static int -qca8k_set_lo(struct qca8k_priv *priv, int phy_id, u32 regnum, u16 lo) -{ - u16 *cached_lo = &priv->mdio_cache.lo; - struct mii_bus *bus = priv->bus; - int ret; - - if (lo == *cached_lo) - return 0; - - ret = bus->write(bus, phy_id, regnum, lo); - if (ret < 0) - dev_err_ratelimited(&bus->dev, - "failed to write qca8k 32bit lo register\n"); - - *cached_lo = lo; - return 0; -} - -static int -qca8k_set_hi(struct qca8k_priv *priv, int phy_id, u32 regnum, u16 hi) -{ - u16 *cached_hi = &priv->mdio_cache.hi; - struct mii_bus *bus = priv->bus; - int ret; - - if (hi == *cached_hi) - return 0; - - ret = bus->write(bus, phy_id, regnum, hi); - if (ret < 0) - dev_err_ratelimited(&bus->dev, - "failed to write qca8k 32bit hi register\n"); - - *cached_hi = hi; - return 0; -} - static int qca8k_mii_read32(struct mii_bus *bus, int phy_id, u32 regnum, u32 *val) { @@ -97,7 +59,7 @@ qca8k_mii_read32(struct mii_bus *bus, int phy_id, u32 regnum, u32 *val) } static void -qca8k_mii_write32(struct qca8k_priv *priv, int phy_id, u32 regnum, u32 val) +qca8k_mii_write32(struct mii_bus *bus, int phy_id, u32 regnum, u32 val) { u16 lo, hi; int ret; @@ -105,9 +67,12 @@ qca8k_mii_write32(struct qca8k_priv *priv, int phy_id, u32 regnum, u32 val) lo = val & 0xffff; hi = (u16)(val >> 16); - ret = qca8k_set_lo(priv, phy_id, regnum, lo); + ret = bus->write(bus, phy_id, regnum, lo); if (ret >= 0) - ret = qca8k_set_hi(priv, phy_id, regnum + 1, hi); + ret = bus->write(bus, phy_id, regnum + 1, hi); + if (ret < 0) + dev_err_ratelimited(&bus->dev, + "failed to write qca8k 32bit register\n"); } static int @@ -442,7 +407,7 @@ qca8k_regmap_write(void *ctx, uint32_t reg, uint32_t val) if (ret < 0) goto exit; - qca8k_mii_write32(priv, 0x10 | r2, r1, val); + qca8k_mii_write32(bus, 0x10 | r2, r1, val); exit: mutex_unlock(&bus->mdio_lock); @@ -475,7 +440,7 @@ qca8k_regmap_update_bits(void *ctx, uint32_t reg, uint32_t mask, uint32_t write_ val &= ~mask; val |= write_val; - qca8k_mii_write32(priv, 0x10 | r2, r1, val); + qca8k_mii_write32(bus, 0x10 | r2, r1, val); exit: mutex_unlock(&bus->mdio_lock); @@ -750,14 +715,14 @@ qca8k_mdio_write(struct qca8k_priv *priv, int phy, int regnum, u16 data) if (ret) goto exit; - qca8k_mii_write32(priv, 0x10 | r2, r1, val); + qca8k_mii_write32(bus, 0x10 | r2, r1, val); ret = qca8k_mdio_busy_wait(bus, QCA8K_MDIO_MASTER_CTRL, QCA8K_MDIO_MASTER_BUSY); exit: /* even if the busy_wait timeouts try to clear the MASTER_EN */ - qca8k_mii_write32(priv, 0x10 | r2, r1, 0); + qca8k_mii_write32(bus, 0x10 | r2, r1, 0); mutex_unlock(&bus->mdio_lock); @@ -787,7 +752,7 @@ qca8k_mdio_read(struct qca8k_priv *priv, int phy, int regnum) if (ret) goto exit; - qca8k_mii_write32(priv, 0x10 | r2, r1, val); + qca8k_mii_write32(bus, 0x10 | r2, r1, val); ret = qca8k_mdio_busy_wait(bus, QCA8K_MDIO_MASTER_CTRL, QCA8K_MDIO_MASTER_BUSY); @@ -798,7 +763,7 @@ qca8k_mdio_read(struct qca8k_priv *priv, int phy, int regnum) exit: /* even if the busy_wait timeouts try to clear the MASTER_EN */ - qca8k_mii_write32(priv, 0x10 | r2, r1, 0); + qca8k_mii_write32(bus, 0x10 | r2, r1, 0); mutex_unlock(&bus->mdio_lock); @@ -1968,8 +1933,6 @@ qca8k_sw_probe(struct mdio_device *mdiodev) } priv->mdio_cache.page = 0xffff; - priv->mdio_cache.lo = 0xffff; - priv->mdio_cache.hi = 0xffff; /* Check the detected switch id */ ret = qca8k_read_switch_id(priv); diff --git a/drivers/net/dsa/qca/qca8k.h b/drivers/net/dsa/qca/qca8k.h index 0b7a5cb12321..03514f7a20be 100644 --- a/drivers/net/dsa/qca/qca8k.h +++ b/drivers/net/dsa/qca/qca8k.h @@ -375,11 +375,6 @@ struct qca8k_mdio_cache { * mdio writes */ u16 page; -/* lo and hi can also be cached and from Documentation we can skip one - * extra mdio write if lo or hi is didn't change. - */ - u16 lo; - u16 hi; }; struct qca8k_pcs {