From patchwork Sat Jul 23 20:53:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hoffmann X-Patchwork-Id: 1659983 X-Patchwork-Delegate: daniel@makrotopia.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=AVJWqWTk; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=3e8.eu header.i=@3e8.eu header.a=rsa-sha256 header.s=mail20211217 header.b=f7lsgBxc; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lqzdp4YD0z9sGp for ; Sun, 24 Jul 2022 07:17:02 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SrCK4pNRfmudlvexfODy2UOgTUQOt7t+//QnodR29PE=; b=AVJWqWTk9bZv1w bqsUmFa3kaSIok0E1JNgRygW7V83CpOcSv2dZZRiDcVjkPqfN2QdImFfdlgAd9Ko6Wy28+CcTbPQf 0LWY5ZzkB9G2X7QKjpa0ULSN7WqzZNsH3j7Rc4BiNN5BSB6ObCLl3cFfIljqOqqm/g/wuHmkYjJ4X Uqx+mTzUWlwxaq6sACoDlPjvBdOwqFODsveNg3WrEotvN2YoAoi8kyawXZMXDF0kM+SdEasPwL6M9 YAGgER4+pGm4c7FRXF0C0P1Z8wa9DoiPC8MjXZdY6J/TwJlo8+AKov4K0MAoSS2VkP/BW8SQ4NYvx o7hGGGnjJxdCwVmAOD1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFMSe-007OJi-Db; Sat, 23 Jul 2022 21:14:56 +0000 Received: from srv4.3e8.eu ([193.25.101.238]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFM83-007Dcr-Rz for openwrt-devel@lists.openwrt.org; Sat, 23 Jul 2022 20:53:42 +0000 Received: from localhost.localdomain (p200300c6cf1309a09555e5d92b92c48c.dip0.t-ipconnect.de [IPv6:2003:c6:cf13:9a0:9555:e5d9:2b92:c48c]) (using TLSv1.3 with cipher TLS_CHACHA20_POLY1305_SHA256 (256/256 bits)) (No client certificate requested) by srv4.3e8.eu (Postfix) with ESMTPSA id 6AAD760213; Sat, 23 Jul 2022 22:53:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=3e8.eu; s=mail20211217; t=1658609618; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7cmKGO6pYUohrUWwYUQ9912hkOZ8G+s1RwR3b4Kmb4E=; b=f7lsgBxcFPPeBbl1szeLzOyZwTR4HEJDjbneZSDOavFji2nytZsMWY6+CJGCPv7bA7fczy e2wb40KDGJLymyVUkvDD16lZD2z+MZ6OpR+1Os3bCA4Kze+XEM25wonta2gzUfWD1Swcd+ phPFQv/Y4b78K+102MQZdtiA8cfNdszppORUnqPE5dw8Y/ov8aT042/rMNnatwqjJ8GSYt /yzxbQjItkf7yA9Fm9iOjq+VifIxVh/SH0mt/Tn2YFpnWtC8/8dVQhOdNvN/E6sn3BSjop mAy1A1VFhdza/KaC8TD9uZ3UgP1WtcR1zvYkq8Ni8QGhDLMnI+rbvKAHMhUoOg== From: Jan Hoffmann To: openwrt-devel@lists.openwrt.org Cc: Birger Koblitz , Sander Vanheule , Jan Hoffmann Subject: [PATCH 4/7] realtek: clean up rtl838x MDIO busy wait loop Date: Sat, 23 Jul 2022 22:53:16 +0200 Message-Id: <20220723205319.3326374-5-jan@3e8.eu> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220723205319.3326374-1-jan@3e8.eu> References: <20220723205319.3326374-1-jan@3e8.eu> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220723_135340_337865_D4D0E92E X-CRM114-Status: GOOD ( 12.14 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Don't use udelay to allow other kernel tasks to execute if the kernel has been built without preemption. Also determine the timeout based on jiffies instead of loop iterations. This is especially important on devices containing a watchdog with a short timeout. Without this change, the watchdog is not serviced during PHY patching which can take multiple seconds. Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Don't use udelay to allow other kernel tasks to execute if the kernel has been built without preemption. Also determine the timeout based on jiffies instead of loop iterations. This is especially important on devices containing a watchdog with a short timeout. Without this change, the watchdog is not serviced during PHY patching which can take multiple seconds. Signed-off-by: Jan Hoffmann --- .../drivers/net/dsa/rtl83xx/rtl838x.c | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c index cdf176677805..524594d725fc 100644 --- a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c +++ b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c @@ -1805,13 +1805,20 @@ irqreturn_t rtl838x_switch_irq(int irq, void *dev_id) int rtl838x_smi_wait_op(int timeout) { - do { - timeout--; - udelay(10); - } while ((sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_1) & 0x1) && (timeout >= 0)); - if (timeout <= 0) - return -1; - return 0; + unsigned long end = jiffies + usecs_to_jiffies(timeout); + + while (1) { + if (!(sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_1) & 0x1)) + return 0; + + if (time_after(jiffies, end)) + break; + + usleep_range(10, 20); + } + + pr_err("rtl838x_smi_wait_op: timeout\n"); + return -1; } /* @@ -1832,7 +1839,7 @@ int rtl838x_read_phy(u32 port, u32 page, u32 reg, u32 *val) mutex_lock(&smi_lock); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; sw_w32_mask(0xffff0000, port << 16, RTL838X_SMI_ACCESS_PHY_CTRL_2); @@ -1842,7 +1849,7 @@ int rtl838x_read_phy(u32 port, u32 page, u32 reg, u32 *val) sw_w32(v | park_page, RTL838X_SMI_ACCESS_PHY_CTRL_1); sw_w32_mask(0, 1, RTL838X_SMI_ACCESS_PHY_CTRL_1); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; *val = sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_2) & 0xffff; @@ -1868,7 +1875,7 @@ int rtl838x_write_phy(u32 port, u32 page, u32 reg, u32 val) return -ENOTSUPP; mutex_lock(&smi_lock); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; sw_w32(BIT(port), RTL838X_SMI_ACCESS_PHY_CTRL_0); @@ -1881,7 +1888,7 @@ int rtl838x_write_phy(u32 port, u32 page, u32 reg, u32 val) sw_w32(v | park_page, RTL838X_SMI_ACCESS_PHY_CTRL_1); sw_w32_mask(0, 1, RTL838X_SMI_ACCESS_PHY_CTRL_1); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; mutex_unlock(&smi_lock); @@ -1901,7 +1908,7 @@ int rtl838x_read_mmd_phy(u32 port, u32 addr, u32 reg, u32 *val) mutex_lock(&smi_lock); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; sw_w32(1 << port, RTL838X_SMI_ACCESS_PHY_CTRL_0); @@ -1916,7 +1923,7 @@ int rtl838x_read_mmd_phy(u32 port, u32 addr, u32 reg, u32 *val) v = 1 << 1 | 0 << 2 | 1; sw_w32(v, RTL838X_SMI_ACCESS_PHY_CTRL_1); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; *val = sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_2) & 0xffff; @@ -1940,7 +1947,7 @@ int rtl838x_write_mmd_phy(u32 port, u32 addr, u32 reg, u32 val) val &= 0xffff; mutex_lock(&smi_lock); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; sw_w32(1 << port, RTL838X_SMI_ACCESS_PHY_CTRL_0); @@ -1954,7 +1961,7 @@ int rtl838x_write_mmd_phy(u32 port, u32 addr, u32 reg, u32 val) v = 1 << 1 | 1 << 2 | 1; sw_w32(v, RTL838X_SMI_ACCESS_PHY_CTRL_1); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; mutex_unlock(&smi_lock);