Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp578923lqg; Fri, 1 Mar 2024 14:17:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWoG3MYNBBfD6U0aZlg05LpKvtlhJeKvtffhdzhV3M8yv5Gy1Ldf8c7p7FnlhfQvaoTJfo7zQIrXXWeUx4B/j0kB2tarb6/dsFcmfq1Gw== X-Google-Smtp-Source: AGHT+IH//I58iAUbnAsxn9OBLFLMSX7zXODhk9L6vIXFuaCBvCh8Au1WA1++ljwvkbWHIIoeiIcB X-Received: by 2002:a17:902:f68f:b0:1dc:51b5:f9b3 with SMTP id l15-20020a170902f68f00b001dc51b5f9b3mr3307283plg.67.1709331479151; Fri, 01 Mar 2024 14:17:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709331479; cv=pass; d=google.com; s=arc-20160816; b=Q7s1Pd9cT+43+pVVtcWauXMWhKKab6hOxvHH3eUV8Z+0j4YKVDn9knaDJgDGTVDlh0 Tcy4RHZEREWIeT78+S+u4E+/BxRfgxcDK0jKz9LLxfeIFmEySF5dpVp/xyTvWF7VMS1p BKDKKUfttH0NA0M8XtGaPfNIkOZKaLLMSJlzin4rOWhCq9p2VgMdTEHutJC+29CuMAEy O9OOaWXFfLZOck22Pnmdu0IrUepxIYt98WOKu6ZWSdVCayR6zxackQDBxlKAgAV8q/Lg YrJIdYaT39ARf8NGqJ5I0FuNX2ROyuxgJvEVR0U1ssNjPp1byq7z7KlQKqc4DcDfXaf/ TqMw== 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=Dqe39XKaGE46c6cFjGmEYyL944xkhI+5L3MWmcenajs=; fh=lY5ALUgdAk9nHW2MQkj6oRTqbAI/0NWw6WiuJHKbwLo=; b=O9gvgvo7ahUNV+ob7uKrh3DHwtdK54lltvU6gwp2ZNBr6MW5x/Aql2hHTGmD4Sz7EM 7kxdAfeKmfgbSPx+2JKCCv4W4OrHkq9Av8M79Njj8IXJLbfA+Bfauz2/aKaFmMieBKuX 2EWbOwW8f8C8IV7hLDkDACaYqIvlEbR9dYinpUuFhwf8utwT7Gk4Pe3/aEW6Wasj1SHq c1XleB9mhBIARzsX+adrQGbE6LXv1UQP+oScOl+qQa3Mgn5yWaZIAK/1GnzZxaKx2WXG d/VNlwNpkLHtmLQLV4g5FH6eB9vWANsIcteA4iYISPwbPHTXLo4vgGWkSLAPCjNlp+OC HEIw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nYBkTV71; 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-89176-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89176-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p23-20020a1709027ed700b001dcf90d62f7si216206plb.16.2024.03.01.14.17.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 14:17:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89176-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nYBkTV71; 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-89176-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89176-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C614728349C for ; Fri, 1 Mar 2024 22:17:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 338C259B7C; Fri, 1 Mar 2024 22:17:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nYBkTV71" Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 940F859B52; Fri, 1 Mar 2024 22:17:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709331454; cv=none; b=HZPZt4JvsYRyM1xX+/7YhiL0D/mTgMnVuTVgDSO9xv+oQrzUKnL3NSylNL+WzoaXHfP3/L+crUz0zwegDrUWMX04DiGh051phdI2YKDSoSSt+J02W5Zqx9yL8m8QvYZSLZHvOJ3W4W4TFeiE6X5j0zuF3XhJiwsJq7SAmEHEue4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709331454; c=relaxed/simple; bh=ZwzIRjxKo4W2uHrdDhdnCy++0skBBDr3Vzf96PWE78g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WtrgSQMTuvSDK+xntLBrE27fat3sgdu0Iz6A5gVYnd1SzfLU1i4kTtQWhN02n3YDVesL/G98qeVjjhffynncx8ap2Wqa170T+YctKu1kpuDluffJcMNZ0tEvkWAWbTt0GzwYOQjB3FQvys0dF0c+2dFwDgeM/IhVWJ7uGvh5C2Y= 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=nYBkTV71; arc=none smtp.client-ip=209.85.208.53 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-f53.google.com with SMTP id 4fb4d7f45d1cf-563d56ee65cso4331933a12.2; Fri, 01 Mar 2024 14:17:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709331450; x=1709936250; 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=Dqe39XKaGE46c6cFjGmEYyL944xkhI+5L3MWmcenajs=; b=nYBkTV71Q/xwc1U2RCt8IFi44aTLECFpL6F8AeGdjE75kD1YwPSQPlCC3wCsSVkgWn 4jaAN1M2i8OhxwVTxDdqo6n8pkIvn7uJTW0DWxmPfOApZuJgbwDbb1A29PcUz3C6Wl08 phJJjaQ9Y3zdpwy5CfdJIMUPxZ/GDCa+S2auHzmnYJOnMyETSZUNu+8YwYU0hWNxVjvZ BVJsRmnueK4WZpyq0c6xIWZxpbj+U7IcXbaPx2V6LKoPCsQdINp9ju7CNL/mUXZPNEPE d5Xm/VCFQrudKmwUcggOBBV1pq1lV2t87jzmMLG1LfgjuN+JLX2LZcWQGrBPNuS1QSt7 2AbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709331450; x=1709936250; 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=Dqe39XKaGE46c6cFjGmEYyL944xkhI+5L3MWmcenajs=; b=o0/bx6mphJw6Oybiv38U20DdSSfEBnbm/wgdMBCOGz9atYmhz+lp7De75IBvmdO2dI iYZKDFYmMgyWmRei91v6b+kWZXEuue7PbR4/wuAI+0NG7BAxCX/zw1M9MI9ROanpG9k0 bJYn7+4uFpcLRkJ6kzzdjrhHcwrfm1pjGJ9pILTm/gvp/aC1TM9R8uuO8ZnSTGfWVYiX vjoiJUbN/v4VcjwX5GevWxskS/Htt9iOEVXzU336U8gApNVi66DbEWhjIEdC5jn8qGEY rJQFSbJXMqOaAoPa1A2Monr5+S+elNFjVDCNmg3wTbTEZ24sNxvB5YI/o7Iod0dHVl/z W25w== X-Forwarded-Encrypted: i=1; AJvYcCWeRGS4zaqOzLkTO6tNDP7JGkDMqMEbeOgmLBpr2zzdX1j3B194IMBhNKYJvMuS5U2wsqW2SxMIwXrAS0SHCiA0DYYwjJSN2qEugxTg X-Gm-Message-State: AOJu0YxDvQm9W3YV6f+/X8yqxBqvXEMcaRpNYJ3Ktno43w96tAlWHfIU gRHX5QqIJvq9JiokMed0QlelB2fhD/fXZG8zzfMLv0diSuTimO8C0SblIwddz1s= X-Received: by 2002:a17:906:ad85:b0:a44:9a2f:dabb with SMTP id la5-20020a170906ad8500b00a449a2fdabbmr1799076ejb.20.1709331450464; Fri, 01 Mar 2024 14:17:30 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id g16-20020a17090613d000b00a3f480154a3sm2091122ejc.65.2024.03.01.14.17.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 14:17:30 -0800 (PST) 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 v6 01/16] net: dsa: vsc73xx: use read_poll_timeout instead delay loop Date: Fri, 1 Mar 2024 23:16:23 +0100 Message-Id: <20240301221641.159542-2-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301221641.159542-1-paweldembicki@gmail.com> References: <20240301221641.159542-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 --- 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