Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2937678lqp; Mon, 25 Mar 2024 13:45:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXqeEbAxETJeNL/JX2+VY7fGsQdLweSFDl5qePUtbBzszj92cVj1fr1nXwBs62Z2YjOXHKQDljRwoRp3LJmGCOv299omOECTx02IXfITQ== X-Google-Smtp-Source: AGHT+IEv/fMl+U3WajGJsdKf+BgMND51tIZfjXDNKn7A3YIHjHOKh0UKc1sOT79qGPJLHIEhmowp X-Received: by 2002:a17:906:b786:b0:a47:4145:3598 with SMTP id dt6-20020a170906b78600b00a4741453598mr5674727ejb.20.1711399504078; Mon, 25 Mar 2024 13:45:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711399504; cv=pass; d=google.com; s=arc-20160816; b=DmK4hZDXx6hJNhI0zADFIfVOcbi2i5/Qz3YD+5bYE/5L28QKkZ1w3Ms1s5ZABwpOJq 3MTjPxC167No2P268pQwq5FUfAxt08OrVoAZuXPgMpgH5J+SqSj/x/Geojhlmu8tQA6+ uzTOgeykQCcSPtItkLy3OHk4K2vDe29LYUBKcQRroksZyzW00GGKy4c46U131mLbQqpr dqhbMBLUhrGRRqXlVzrP1qt/SymHv1eYccloEz0LmtN16m84yiBE3j+7FNqXIskAVE9T ECF8CJp/6UvpK0LLOU6kQuiHZSF2WGCoCP7hetESwf5pULcm+a5RIMiAmLkK18wpfadf JHWg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=C0F/8H7Tcr8axVcQTcIq59S1STUD5wziimqr+zfEnTo=; fh=iHdvkynWgMlbwLDiY4vPO238ogaPNl4hs4M/LjCjSLo=; b=grOxSLWdMa0I88MHMY460ryHco7AAw8N8L8R+QLNCLYZSd8fmMR7rVlySn+F/X7L21 l9ZDi19t4G6gw6qESqFar8bJWZgBD79YC9VVj/8hO7UxNcDVjD2tMTcsM/KNZiRg9H2T MBRK4pPqVCdSjvu0GU7hLqH5/hTW7Dryl/LsRzxJglad/oaTv1/hBvxGTCia+GrUM5zP JyV8nhgl3VfTxpK4RUh1TH8GsOnYz3pPHubSGlkbksjR6hWMrETe53a+qLkBFiOgycvl o/RxE2OwNcfm1rtaxwbX2Nr2qj3Z51TQUIjttsEhbDgDbKVKYKjoQ60vlQy8XTlDUBoJ USqw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LdEggiPn; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-117961-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117961-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u4-20020aa7db84000000b0056bbf8ca1d7si2833066edt.491.2024.03.25.13.45.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:45:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117961-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LdEggiPn; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-117961-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117961-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CAF0C1F2BA24 for ; Mon, 25 Mar 2024 20:45:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D4265E099; Mon, 25 Mar 2024 20:44:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LdEggiPn" Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B489F5C901; Mon, 25 Mar 2024 20:44:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399479; cv=none; b=F/ADb6NDFN1P45jX2qSDECaLXsOQBzh9T9zHS/8+aNWAY7b3NaBFEOXFc7D2HIsk/yEVGVWL5Y7tE3XJnLEeNqM4enyDehvGTE7zaKF1ccyjVW1k6RI2dIMutmx+mKlAYTWpcKR2VeentmDOkREwMa7snhGzQWbOeS0wNFNp7Lg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399479; c=relaxed/simple; bh=GlSUQz1tJAfco/7YWHdhANQ0v28uxyKkDF7xpgAQN8I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RrN7nzhKk08SWEoTiRqASkXBQ/18s/ljkMP4JVETDQvH6uy0dDPqsZPoepW1dyR1ESBkZTKr0Kye9DfpE7V8Jj+NGUXXTAHxL48pu6hA3wpciJ21g3oWk3hksQ8skdf/LOGekiQqytrLVIKejefqO0xFMaYUEO8QGzsUnbZKpoc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LdEggiPn; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-56c147205b9so1998145a12.0; Mon, 25 Mar 2024 13:44:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399476; x=1712004276; darn=vger.kernel.org; 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=C0F/8H7Tcr8axVcQTcIq59S1STUD5wziimqr+zfEnTo=; b=LdEggiPn9o7OWcWAVgupPuORmSLz5BJJQUOwb87LBDTf8r7n/xPA/TZGTPaLXADaiR PWUlxok1LWjkdamOcxzjzaNQ5OEowzoS3/V3L+CbhcuxYWElviLjHJQrKPjJxURFQsWq JUlCgIiK/MHLmoWx5usmMeCImiHa1hEo37wngsk44KeKskplt29NM4lPt/R7d6zr/OsS Gc0xDNCGnuiBM7Omu78JChkruMC2tz9TGPvTwfT2lxp8wol9NdHDvpTOwXSqibqmrd/j ASDnnl54HsYTA/H/kpUazbORffcooEFi0s0lWs5rZPohm74sIOlkac3j8Q6lvqD+F4q4 0DDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399476; x=1712004276; 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=C0F/8H7Tcr8axVcQTcIq59S1STUD5wziimqr+zfEnTo=; b=CAorOGcuFtSFusEu/UwlkemVxNBMbygHqdxLL5HVYTR+/zgVNoP+8TUzkDIC0tuvgi 6JgRmi1pKIX4hXBM0anPWRUkJkCoFgwdhjv/hX+8r6oc/IB3kkydFCm8K0ghFwDB96eo QHMcPEC6xC7k7prLK26y4ebH+AVPFmWPpkeX6VVtXaA9K21O2h08UnQ675vRUHH0tGcL dP2p/kZpPNGbLE3Xdop8fu6O7r6tGa8QiuJ8VCeKl7+jsc6NQ49iqciqF+0ReFoiJgKp Y2aVE/rzPs5LOwkLc7ajLcYi2inW9fqu7ZeRz+E9g8ylHzXn6lcBynat0cBw1EuJENzN Xsow== X-Forwarded-Encrypted: i=1; AJvYcCXMj9MLrfDigk9SxWpSQeVYUuZx9nOR4CWhClj8mwrMPGGyPlZH0TyZtHvjT96N3tuW5ZTmy9sHcdmMSKFzk4IYu0rsl39MQ5wTmiX5 X-Gm-Message-State: AOJu0YzQfAu/uiHw7j04fsO+dWJvE/y/tOw5NsoXFYDnPs/93ekRDo9Z eLtsFe2L5emfewW9HTE+nAM6hxr9Eh2GSEiR78YXP4sC9C0gL+1ivFo/57y5c5c= X-Received: by 2002:a50:8753:0:b0:568:aced:e5a0 with SMTP id 19-20020a508753000000b00568acede5a0mr7058709edv.14.1711399475594; Mon, 25 Mar 2024 13:44:35 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:44:34 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , Pawel Dembicki , Russell King , Andrew Lunn , Florian Fainelli , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, linux-kernel@vger.kernel.org Subject: [PATCH net-next v7 01/16] net: dsa: vsc73xx: use read_poll_timeout instead delay loop Date: Mon, 25 Mar 2024 21:43:26 +0100 Message-Id: <20240325204344.2298241-2-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Switch the delay loop during the Arbiter empty check from vsc73xx_adjust_link() to use read_poll_timeout(). Functionally, one msleep() call is eliminated at the end of the loop in the timeout case. As Russell King suggested: "This [change] avoids the issue that on the last iteration, the code reads the register, tests it, finds the condition that's being waiting for is false, _then_ waits and end up printing the error message - that last wait is rather useless, and as the arbiter state isn't checked after waiting, it could be that we had success during the last wait." Suggested-by: Russell King Reviewed-by: Andrew Lunn Reviewed-by: Linus Walleij Reviewed-by: Florian Fainelli Signed-off-by: Pawel Dembicki --- v7,v6: - resend only v5: - improved commit description - added two defines instead magic numbers - added include with iopoll.h v4: - resend patch v3: - added "Reviewed-by" to commit message only v2: - introduced patch drivers/net/dsa/vitesse-vsc73xx-core.c | 30 ++++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index ae70eac3be28..ab5771d4d828 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -268,6 +269,9 @@ #define IS_7398(a) ((a)->chipid == VSC73XX_CHIPID_ID_7398) #define IS_739X(a) (IS_7395(a) || IS_7398(a)) +#define VSC73XX_POLL_SLEEP_US 1000 +#define VSC73XX_POLL_TIMEOUT_US 10000 + struct vsc73xx_counter { u8 counter; const char *name; @@ -779,7 +783,7 @@ static void vsc73xx_adjust_link(struct dsa_switch *ds, int port, * after a PHY or the CPU port comes up or down. */ if (!phydev->link) { - int maxloop = 10; + int ret, err; dev_dbg(vsc->dev, "port %d: went down\n", port); @@ -794,19 +798,17 @@ static void vsc73xx_adjust_link(struct dsa_switch *ds, int port, VSC73XX_ARBDISC, BIT(port), BIT(port)); /* Wait until queue is empty */ - vsc73xx_read(vsc, VSC73XX_BLOCK_ARBITER, 0, - VSC73XX_ARBEMPTY, &val); - while (!(val & BIT(port))) { - msleep(1); - vsc73xx_read(vsc, VSC73XX_BLOCK_ARBITER, 0, - VSC73XX_ARBEMPTY, &val); - if (--maxloop == 0) { - dev_err(vsc->dev, - "timeout waiting for block arbiter\n"); - /* Continue anyway */ - break; - } - } + ret = read_poll_timeout(vsc73xx_read, err, + err < 0 || (val & BIT(port)), + VSC73XX_POLL_SLEEP_US, + VSC73XX_POLL_TIMEOUT_US, false, + vsc, VSC73XX_BLOCK_ARBITER, 0, + VSC73XX_ARBEMPTY, &val); + if (ret) + dev_err(vsc->dev, + "timeout waiting for block arbiter\n"); + else if (err < 0) + dev_err(vsc->dev, "error reading arbiter\n"); /* Put this port into reset */ vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG, -- 2.34.1