From nobody Sun Feb 8 04:31:04 2026 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 CA147396D36 for ; Wed, 14 Jan 2026 11:49:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768391389; cv=none; b=jnLTFus8hBbUXD0n1uVp77JK6yU+jN1jfJLk8aTBtPgb9sFXKpvvqECz7N8L7jiuETiOANikmBGF2PtoiZmK/6uwe6hoWA/jlovKrSDHkOTRVzGjUf5jD1uBqy6zdpvOnJSzi/APycEk/TqvEsXxLQtvS0JnwFXTZ9OfjdLYBE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768391389; c=relaxed/simple; bh=mHd5/FDiQ86yScP8/xKWBTcg+ow54G9KDtNwccSg1Uk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nML01sHrRdLP4X6LdXjNYP4RWz9pMCTVnli5FWfkddkebhVDB08fzmco6/M0Ac4+wcwqHBeWqVSrNv/Xz0/rummBc9HUbk0Lx1sJauTZJPYEEVlRXF625ze3j4UqgOpoRXGDqSlM/xDcmwMbc508DbX+qit7VoxyF0k5qgu/d/g= 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=UPbIsKw9; arc=none smtp.client-ip=209.85.215.171 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UPbIsKw9" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-bc274b8b15bso5524392a12.1 for ; Wed, 14 Jan 2026 03:49:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768391386; x=1768996186; 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=qykhmziqocBs83eOMsCXS+riegj3dQCRKqwsythsgqI=; b=UPbIsKw9rTGrJ0YchZMoe5YB2dExA6jg3yz2G6T3KOPpdUTSX2E9sGfj/qJWoPfdkB /14NyQ0ejiJfMQZm/pvMaxKeoeu6O+9C0codz1OJF9iCsx1cD4b4+7FstdYC16t+pQon vpasjHat4RoGVmqHeNwG/VuP1yrvwJbdamnP03I1E14RP4XpNuImMUv2ri17pJLwbm9X 1vr0uobR0ORSTQwIMwGWbsl6Px6OZV2uimQLHKb6RWexwAFqjNq+MaP81yzNKw9YcwXr kNa1+t/tdEDB4hszdxaZqwP1j6k3FJO8NCmlnHrpLl3edwx2bdZ4MiG0g9q736ho8T7W 8LdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768391386; x=1768996186; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=qykhmziqocBs83eOMsCXS+riegj3dQCRKqwsythsgqI=; b=IPzDyp4fUFa/zz0i/dQS8PJKA1fdte1wigZG3ithlHBtygWHGdzrHO9N6yE9eIsb6Y v1HGeWpgoBqL4TgPUOq3kKQbfhgTGhNoQPnBTsGricjmh3k5RiBiZ2pqA1nkPgWrAkhv Nxf1CpJtqrqr/EEQ9LiAhjH/GD5BJvWPs+ITnl4icnR+anxHmuCD9xGUwaevMosjzbul ysu4ujz0VtUI2SUraMNuFnSnnfGH35RPWCLCztr5RlgkejaVFMpVgsiPhjpPpTlynZ9t V6uV27VUUfSh9DE3V+0TqWkf6jtLPtGvTfIZAOonre4SW3uWdZ9SFnrkP601szGGGFuJ MuSQ== X-Forwarded-Encrypted: i=1; AJvYcCVsJXmqt1lJq/cyG7f7ygjtfQaGpI5yzZ839duDNAR6bPgfPZuwJdiWkYmk2rz7Qcsq6/3shkomRGHmiQ4=@vger.kernel.org X-Gm-Message-State: AOJu0YxWohbdVH15dtdkt6KtnAXxrYt641+OQUienFSOf3n8csdP6VxI qZH8kiiJUtSZ3LdAiOtbIt61dTiUs0HE2r2EgeEUyqN2qp20XV59iZQc X-Gm-Gg: AY/fxX7jXHOcxGgu3HGLBj2SQhAp+g1kxYFxECBM+MXzFaS7H5VV0H+l1cAH0hr0Lbx 2PlNJe8fVeAXYgyrPw2IVL/5fccUUVXsoBj8IU030ThxxgI83wzeXmmCcWWcJTZY501wQUCuYTQ rQtKkfTkuzBhjGIremeRTOkl1CFU/c0SRJvANeYWzK8gfBX84kHw56ycfJhof9QARQJhIH7+Lif lheRmEjQfScxJd4/c5aoFYDWNfLkjJjnv7uNtBi5TlY6oqVeqGOzQxmSP8gV/KyPvJekZ1958G1 mwKv7pJgfN7Dsaz4vonzjNoTb80/O+yAgohzovy3uw31cNMomGox+NpdbFyfrogmpwbY/Ap0QHq mcMWsDM6IEs2jlzzyK0UzgE+jDrBuSS7aVPhzpQCd8eqP27lSOvSkt64J6Oo6Ft7KHOf0FMt/YI y07ICZrfci3wKh8+Tb+CywkKaunO6KaXq59wNbTB1GgG9vemU/NE1g+g== X-Received: by 2002:a05:6a20:3d0e:b0:35f:84c7:4031 with SMTP id adf61e73a8af0-38bed1f3939mr2523103637.55.1768391386021; Wed, 14 Jan 2026 03:49:46 -0800 (PST) Received: from d.home.mmyangfl.tk ([2001:19f0:8001:1644:5400:5ff:fe3e:12b1]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c4cbf28f678sm22632123a12.3.2026.01.14.03.49.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jan 2026 03:49:45 -0800 (PST) From: David Yang To: netdev@vger.kernel.org Cc: David Yang , Andrew Lunn , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org, Dan Carpenter , David Laight Subject: [PATCH net-next v5 1/2] net: dsa: yt921x: Fix MIB overflow wraparound routine Date: Wed, 14 Jan 2026 19:47:41 +0800 Message-ID: <20260114114745.213252-2-mmyangfl@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260114114745.213252-1-mmyangfl@gmail.com> References: <20260114114745.213252-1-mmyangfl@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: quoted-printable Content-Type: text/plain; charset="utf-8" Reported by the following Smatch static checker warning: drivers/net/dsa/yt921x.c:702 yt921x_read_mib() warn: was expecting a 64 bit value instead of '(~0)' Fixes: 186623f4aa72 ("net: dsa: yt921x: Add support for Motorcomm YT921x") Reported-by: Dan Carpenter Closes: https://lore.kernel.org/netdev/aPsjYKQMzpY0nSXm@stanley.mountain/ Suggested-by: David Laight Signed-off-by: David Yang --- drivers/net/dsa/yt921x.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/net/dsa/yt921x.c b/drivers/net/dsa/yt921x.c index 0b3df732c0d1..5e4e8093ba16 100644 --- a/drivers/net/dsa/yt921x.c +++ b/drivers/net/dsa/yt921x.c @@ -682,21 +682,22 @@ static int yt921x_read_mib(struct yt921x_priv *priv, = int port) const struct yt921x_mib_desc *desc =3D &yt921x_mib_descs[i]; u32 reg =3D YT921X_MIBn_DATA0(port) + desc->offset; u64 *valp =3D &((u64 *)mib)[i]; - u64 val =3D *valp; u32 val0; - u32 val1; + u64 val; =20 res =3D yt921x_reg_read(priv, reg, &val0); if (res) break; =20 if (desc->size <=3D 1) { - if (val < (u32)val) - /* overflow */ - val +=3D (u64)U32_MAX + 1; - val &=3D ~U32_MAX; - val |=3D val0; + u64 old_val =3D *valp; + + val =3D (old_val & ~(u64)U32_MAX) | val0; + if (val < old_val) + val +=3D 1ull << 32; } else { + u32 val1; + res =3D yt921x_reg_read(priv, reg + 4, &val1); if (res) break; --=20 2.51.0 From nobody Sun Feb 8 04:31:04 2026 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 DBB67397AC5 for ; Wed, 14 Jan 2026 11:49:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768391393; cv=none; b=ML4veunXqpTw4l6ghZPb5e6Pe44YLjmIyWyKO/dB8HSPchJgMNfm5uzUiIGITQUbNqyctJJc41mJxtYx8fUw00Ej5BnTqOPRNKkGfPMNERUQLzc/AFeiwjxCWynmzPMEVLXanXv4/3+MODF6UQh/JDSEub1A7jM26XxXsJbOEh8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768391393; c=relaxed/simple; bh=GgMRinYhSKgSDyAcjoNF1p47gTdiShIaJazaao5MQ9o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hYHL6RBpu2T0Rh3d6C8n0iQhEz8CLUCQx6Qhzr7L8Wdazzk6xpKrJAJgBxOIOy/R6p/dombiKvz2AsZ+zQLDxJ59RWkGNso8/azxbnvH/K2ZNDgks6dROXVUc/lnlSoRKq2/nblqk0WPYrONPiKEgQW0aFiz5Kyx+cBRkerlxeI= 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=QsvrmFuO; arc=none smtp.client-ip=209.85.210.176 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QsvrmFuO" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-81f478e5283so3315907b3a.2 for ; Wed, 14 Jan 2026 03:49:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768391390; x=1768996190; 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=+BjgVDa7czL64FxA+Zx+xW3I48p8/maMtuczUJsQ/hc=; b=QsvrmFuO2UyVjFV5LzjXSvwH/3lDBHJeqvj333HCem8dR0NbrWxnVmFjBUGYUC1DSo n7T2Gte/TmF9nj+T8m/TvhquXFafvyKyXmO11nylgyBH198p7GDGLlhxGC7XQFm3OX2p +1h09/sd/P2tl9CN+/av1x/XnFPY8txlxmtsFKPC9gy/Jze18WSN9o/H/XLMg4DTmNXg FzM7cSeS+nUnpiJoAvasoXHVAsQlhZ0Kl9zIkXo1otwqYqNjgHujXmPHWvZ3DCjbclUC 4qR2P8LGnz4qeOPYkPndphI0aJ0d4p0kwPj1enad9niUwgrOX9gZ2EvCu2o/+9xP86ci iFUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768391390; x=1768996190; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+BjgVDa7czL64FxA+Zx+xW3I48p8/maMtuczUJsQ/hc=; b=UiuYO8JPoeipfNThkeLZquU8Dk0F/cKMl+xqQ80X3SSmEZsn3ATQJbwZCC30iXX690 ofbDfo2eVUBASwcDRqC7gjOV1oyMnB1RdbkDzDkSqyP5a9vyy+ctT+zrbyYN84mmvvay PZ68nTBMCd11rOu7NBgavhID2TOLZRehe7xRwwbM7fesfMtxMaZotmVfyppgVabMnNWV Z1X+v4wFto/DoiCmax5dWjIfyAcAtdCc9hhiEn9GhFkbnQ+bI2Pz9UjwHFijAu39DUJN 2KaPPb1Pbv52eleYEfq9RD4RUOwJNTM6iXaDprIyvVujQD+oJZjMfKFVryzw6dM49JYU R3pA== X-Forwarded-Encrypted: i=1; AJvYcCXaOchxKO7FBloW4DrBZZexryDZISSNvZN32dX+4Fvib4VsM6wRYcB5lQOyHolAKE710JpJ/stRxSj+I9Y=@vger.kernel.org X-Gm-Message-State: AOJu0YxWbSybfCqMB69IzQjqESSCvCmLLlnjhB+haZ+f95zl968qysRC G0jkRxiSVxdfS0gqU8352I+zPc7UEtRqzIx2UNBFIX+HIf2mG1VEAGfW X-Gm-Gg: AY/fxX7+PjVbBm2Z4878XlRadf7mX494TyzAMQW+x5otHb0EnKBWBQr56EwmjAoFjyX sc75wj9jSW8zV9B7rTTK+eOYGYZP/JmehVDovDeyEYC+3s5Vh0doegLtSi4utOoskSLtmOnJahT r980FnP03i+lFor6OCCEdEEQBnKq88qHK1/ZM8a/IhX5Vz8+WhP7s9fRIT1e7JLeMD6D5S7FB/Z csk88bWZjgA4ehI8Al8jXTH7U+TEb1TFU68m54rLBXWsKU6p/fCFkeS0hsBcfpv5ZjJYK+d4RLZ tRqsj2zgOUHKdH66TbjMuaTd1Y81DZRnaCM9njX7rma0MYz8aVfVYJy0H5F2tFuBq8yJJLsV3P6 pEUx4KUN4jUxTKSOURTTEfPZBCqIpMz35xn1p8f0+zkdvR2GZjmZAO4Uif7Lwb2UrwcMjW90N2m ZO8cNmKtJT7LbdAuAdFZgWyKYtNZxIm8x4g23ic2Airj+vfSTWvNQFLg== X-Received: by 2002:a05:6a20:5483:b0:361:4b9d:b9a8 with SMTP id adf61e73a8af0-38befad8ac9mr1831275637.20.1768391389937; Wed, 14 Jan 2026 03:49:49 -0800 (PST) Received: from d.home.mmyangfl.tk ([2001:19f0:8001:1644:5400:5ff:fe3e:12b1]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c4cbf28f678sm22632123a12.3.2026.01.14.03.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jan 2026 03:49:49 -0800 (PST) From: David Yang To: netdev@vger.kernel.org Cc: David Yang , Andrew Lunn , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 2/2] net: dsa: yt921x: Use u64_stats_t for MIB stats Date: Wed, 14 Jan 2026 19:47:42 +0800 Message-ID: <20260114114745.213252-3-mmyangfl@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260114114745.213252-1-mmyangfl@gmail.com> References: <20260114114745.213252-1-mmyangfl@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: quoted-printable Content-Type: text/plain; charset="utf-8" 64-bit variables might not be atomic on 32-bit architectures, thus cannot be unconditionally made lock-free. Use u64_stats_t so it would still be lock-free on 64-bit architectures. Signed-off-by: David Yang --- drivers/net/dsa/yt921x.c | 245 +++++++++++++++++++++++---------------- drivers/net/dsa/yt921x.h | 108 +++++++++-------- 2 files changed, 205 insertions(+), 148 deletions(-) diff --git a/drivers/net/dsa/yt921x.c b/drivers/net/dsa/yt921x.c index 5e4e8093ba16..e1887d107008 100644 --- a/drivers/net/dsa/yt921x.c +++ b/drivers/net/dsa/yt921x.c @@ -18,6 +18,7 @@ #include #include #include +#include =20 #include =20 @@ -666,22 +667,20 @@ yt921x_mbus_ext_init(struct yt921x_priv *priv, struct= device_node *mnp) static int yt921x_read_mib(struct yt921x_priv *priv, int port) { struct yt921x_port *pp =3D &priv->ports[port]; + struct yt921x_mib *mib_new =3D &pp->mib_new; struct device *dev =3D to_device(priv); struct yt921x_mib *mib =3D &pp->mib; + u64 rx_frames; + u64 tx_frames; int res =3D 0; =20 - /* Reading of yt921x_port::mib is not protected by a lock and it's vain - * to keep its consistency, since we have to read registers one by one - * and there is no way to make a snapshot of MIB stats. - * - * Writing (by this function only) is and should be protected by - * reg_lock. + /* u64_stats_read/set is redundant for mib_new, but I don't want to + * declare a plain u64 yt921x_mib variant. */ =20 for (size_t i =3D 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) { const struct yt921x_mib_desc *desc =3D &yt921x_mib_descs[i]; u32 reg =3D YT921X_MIBn_DATA0(port) + desc->offset; - u64 *valp =3D &((u64 *)mib)[i]; u32 val0; u64 val; =20 @@ -690,7 +689,7 @@ static int yt921x_read_mib(struct yt921x_priv *priv, in= t port) break; =20 if (desc->size <=3D 1) { - u64 old_val =3D *valp; + u64 old_val =3D u64_stats_read(&((u64_stats_t *)mib)[i]); =20 val =3D (old_val & ~(u64)U32_MAX) | val0; if (val < old_val) @@ -704,22 +703,40 @@ static int yt921x_read_mib(struct yt921x_priv *priv, = int port) val =3D ((u64)val1 << 32) | val0; } =20 - WRITE_ONCE(*valp, val); + u64_stats_set(&((u64_stats_t *)mib_new)[i], val); } =20 - pp->rx_frames =3D mib->rx_64byte + mib->rx_65_127byte + - mib->rx_128_255byte + mib->rx_256_511byte + - mib->rx_512_1023byte + mib->rx_1024_1518byte + - mib->rx_jumbo; - pp->tx_frames =3D mib->tx_64byte + mib->tx_65_127byte + - mib->tx_128_255byte + mib->tx_256_511byte + - mib->tx_512_1023byte + mib->tx_1024_1518byte + - mib->tx_jumbo; - - if (res) + if (res) { dev_err(dev, "Failed to %s port %d: %i\n", "read stats for", port, res); - return res; + return res; + } + + rx_frames =3D u64_stats_read(&mib_new->rx_64byte) + + u64_stats_read(&mib_new->rx_65_127byte) + + u64_stats_read(&mib_new->rx_128_255byte) + + u64_stats_read(&mib_new->rx_256_511byte) + + u64_stats_read(&mib_new->rx_512_1023byte) + + u64_stats_read(&mib_new->rx_1024_1518byte) + + u64_stats_read(&mib_new->rx_jumbo); + tx_frames =3D u64_stats_read(&mib_new->tx_64byte) + + u64_stats_read(&mib_new->tx_65_127byte) + + u64_stats_read(&mib_new->tx_128_255byte) + + u64_stats_read(&mib_new->tx_256_511byte) + + u64_stats_read(&mib_new->tx_512_1023byte) + + u64_stats_read(&mib_new->tx_1024_1518byte) + + u64_stats_read(&mib_new->tx_jumbo); + + u64_stats_update_begin(&pp->syncp); + for (size_t i =3D 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) { + u64_stats_set(&((u64_stats_t *)mib)[i], + u64_stats_read(&((u64_stats_t *)mib_new)[i])); + } + u64_stats_set(&pp->rx_frames, rx_frames); + u64_stats_set(&pp->tx_frames, tx_frames); + u64_stats_update_end(&pp->syncp); + + return 0; } =20 static void yt921x_poll_mib(struct work_struct *work) @@ -762,22 +779,27 @@ yt921x_dsa_get_ethtool_stats(struct dsa_switch *ds, i= nt port, uint64_t *data) struct yt921x_priv *priv =3D to_yt921x_priv(ds); struct yt921x_port *pp =3D &priv->ports[port]; struct yt921x_mib *mib =3D &pp->mib; + unsigned int start; size_t j; =20 mutex_lock(&priv->reg_lock); yt921x_read_mib(priv, port); mutex_unlock(&priv->reg_lock); =20 - j =3D 0; - for (size_t i =3D 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) { - const struct yt921x_mib_desc *desc =3D &yt921x_mib_descs[i]; + do { + start =3D u64_stats_fetch_begin(&pp->syncp); =20 - if (!desc->name) - continue; + j =3D 0; + for (size_t i =3D 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) { + const struct yt921x_mib_desc *desc =3D &yt921x_mib_descs[i]; =20 - data[j] =3D ((u64 *)mib)[i]; - j++; - } + if (!desc->name) + continue; + + data[j] =3D u64_stats_read(&((u64_stats_t *)mib)[i]); + j++; + } + } while (u64_stats_fetch_retry(&pp->syncp, start)); } =20 static int yt921x_dsa_get_sset_count(struct dsa_switch *ds, int port, int = sset) @@ -804,33 +826,38 @@ yt921x_dsa_get_eth_mac_stats(struct dsa_switch *ds, i= nt port, struct yt921x_priv *priv =3D to_yt921x_priv(ds); struct yt921x_port *pp =3D &priv->ports[port]; struct yt921x_mib *mib =3D &pp->mib; + unsigned int start; =20 mutex_lock(&priv->reg_lock); yt921x_read_mib(priv, port); mutex_unlock(&priv->reg_lock); =20 - mac_stats->FramesTransmittedOK =3D pp->tx_frames; - mac_stats->SingleCollisionFrames =3D mib->tx_single_collisions; - mac_stats->MultipleCollisionFrames =3D mib->tx_multiple_collisions; - mac_stats->FramesReceivedOK =3D pp->rx_frames; - mac_stats->FrameCheckSequenceErrors =3D mib->rx_crc_errors; - mac_stats->AlignmentErrors =3D mib->rx_alignment_errors; - mac_stats->OctetsTransmittedOK =3D mib->tx_good_bytes; - mac_stats->FramesWithDeferredXmissions =3D mib->tx_deferred; - mac_stats->LateCollisions =3D mib->tx_late_collisions; - mac_stats->FramesAbortedDueToXSColls =3D mib->tx_aborted_errors; - /* mac_stats->FramesLostDueToIntMACXmitError */ - /* mac_stats->CarrierSenseErrors */ - mac_stats->OctetsReceivedOK =3D mib->rx_good_bytes; - /* mac_stats->FramesLostDueToIntMACRcvError */ - mac_stats->MulticastFramesXmittedOK =3D mib->tx_multicast; - mac_stats->BroadcastFramesXmittedOK =3D mib->tx_broadcast; - /* mac_stats->FramesWithExcessiveDeferral */ - mac_stats->MulticastFramesReceivedOK =3D mib->rx_multicast; - mac_stats->BroadcastFramesReceivedOK =3D mib->rx_broadcast; - /* mac_stats->InRangeLengthErrors */ - /* mac_stats->OutOfRangeLengthField */ - mac_stats->FrameTooLongErrors =3D mib->rx_oversize_errors; + do { + start =3D u64_stats_fetch_begin(&pp->syncp); + + mac_stats->FramesTransmittedOK =3D u64_stats_read(&pp->tx_frames); + mac_stats->SingleCollisionFrames =3D u64_stats_read(&mib->tx_single_coll= isions); + mac_stats->MultipleCollisionFrames =3D u64_stats_read(&mib->tx_multiple_= collisions); + mac_stats->FramesReceivedOK =3D u64_stats_read(&pp->rx_frames); + mac_stats->FrameCheckSequenceErrors =3D u64_stats_read(&mib->rx_crc_erro= rs); + mac_stats->AlignmentErrors =3D u64_stats_read(&mib->rx_alignment_errors); + mac_stats->OctetsTransmittedOK =3D u64_stats_read(&mib->tx_good_bytes); + mac_stats->FramesWithDeferredXmissions =3D u64_stats_read(&mib->tx_defer= red); + mac_stats->LateCollisions =3D u64_stats_read(&mib->tx_late_collisions); + mac_stats->FramesAbortedDueToXSColls =3D u64_stats_read(&mib->tx_aborted= _errors); + /* mac_stats->FramesLostDueToIntMACXmitError */ + /* mac_stats->CarrierSenseErrors */ + mac_stats->OctetsReceivedOK =3D u64_stats_read(&mib->rx_good_bytes); + /* mac_stats->FramesLostDueToIntMACRcvError */ + mac_stats->MulticastFramesXmittedOK =3D u64_stats_read(&mib->tx_multicas= t); + mac_stats->BroadcastFramesXmittedOK =3D u64_stats_read(&mib->tx_broadcas= t); + /* mac_stats->FramesWithExcessiveDeferral */ + mac_stats->MulticastFramesReceivedOK =3D u64_stats_read(&mib->rx_multica= st); + mac_stats->BroadcastFramesReceivedOK =3D u64_stats_read(&mib->rx_broadca= st); + /* mac_stats->InRangeLengthErrors */ + /* mac_stats->OutOfRangeLengthField */ + mac_stats->FrameTooLongErrors =3D u64_stats_read(&mib->rx_oversize_error= s); + } while (u64_stats_fetch_retry(&pp->syncp, start)); } =20 static void @@ -840,14 +867,19 @@ yt921x_dsa_get_eth_ctrl_stats(struct dsa_switch *ds, = int port, struct yt921x_priv *priv =3D to_yt921x_priv(ds); struct yt921x_port *pp =3D &priv->ports[port]; struct yt921x_mib *mib =3D &pp->mib; + unsigned int start; =20 mutex_lock(&priv->reg_lock); yt921x_read_mib(priv, port); mutex_unlock(&priv->reg_lock); =20 - ctrl_stats->MACControlFramesTransmitted =3D mib->tx_pause; - ctrl_stats->MACControlFramesReceived =3D mib->rx_pause; - /* ctrl_stats->UnsupportedOpcodesReceived */ + do { + start =3D u64_stats_fetch_begin(&pp->syncp); + + ctrl_stats->MACControlFramesTransmitted =3D u64_stats_read(&mib->tx_paus= e); + ctrl_stats->MACControlFramesReceived =3D u64_stats_read(&mib->rx_pause); + /* ctrl_stats->UnsupportedOpcodesReceived */ + } while (u64_stats_fetch_retry(&pp->syncp, start)); } =20 static const struct ethtool_rmon_hist_range yt921x_rmon_ranges[] =3D { @@ -869,6 +901,7 @@ yt921x_dsa_get_rmon_stats(struct dsa_switch *ds, int po= rt, struct yt921x_priv *priv =3D to_yt921x_priv(ds); struct yt921x_port *pp =3D &priv->ports[port]; struct yt921x_mib *mib =3D &pp->mib; + unsigned int start; =20 mutex_lock(&priv->reg_lock); yt921x_read_mib(priv, port); @@ -876,26 +909,30 @@ yt921x_dsa_get_rmon_stats(struct dsa_switch *ds, int = port, =20 *ranges =3D yt921x_rmon_ranges; =20 - rmon_stats->undersize_pkts =3D mib->rx_undersize_errors; - rmon_stats->oversize_pkts =3D mib->rx_oversize_errors; - rmon_stats->fragments =3D mib->rx_alignment_errors; - /* rmon_stats->jabbers */ - - rmon_stats->hist[0] =3D mib->rx_64byte; - rmon_stats->hist[1] =3D mib->rx_65_127byte; - rmon_stats->hist[2] =3D mib->rx_128_255byte; - rmon_stats->hist[3] =3D mib->rx_256_511byte; - rmon_stats->hist[4] =3D mib->rx_512_1023byte; - rmon_stats->hist[5] =3D mib->rx_1024_1518byte; - rmon_stats->hist[6] =3D mib->rx_jumbo; - - rmon_stats->hist_tx[0] =3D mib->tx_64byte; - rmon_stats->hist_tx[1] =3D mib->tx_65_127byte; - rmon_stats->hist_tx[2] =3D mib->tx_128_255byte; - rmon_stats->hist_tx[3] =3D mib->tx_256_511byte; - rmon_stats->hist_tx[4] =3D mib->tx_512_1023byte; - rmon_stats->hist_tx[5] =3D mib->tx_1024_1518byte; - rmon_stats->hist_tx[6] =3D mib->tx_jumbo; + do { + start =3D u64_stats_fetch_begin(&pp->syncp); + + rmon_stats->undersize_pkts =3D u64_stats_read(&mib->rx_undersize_errors); + rmon_stats->oversize_pkts =3D u64_stats_read(&mib->rx_oversize_errors); + rmon_stats->fragments =3D u64_stats_read(&mib->rx_alignment_errors); + /* rmon_stats->jabbers */ + + rmon_stats->hist[0] =3D u64_stats_read(&mib->rx_64byte); + rmon_stats->hist[1] =3D u64_stats_read(&mib->rx_65_127byte); + rmon_stats->hist[2] =3D u64_stats_read(&mib->rx_128_255byte); + rmon_stats->hist[3] =3D u64_stats_read(&mib->rx_256_511byte); + rmon_stats->hist[4] =3D u64_stats_read(&mib->rx_512_1023byte); + rmon_stats->hist[5] =3D u64_stats_read(&mib->rx_1024_1518byte); + rmon_stats->hist[6] =3D u64_stats_read(&mib->rx_jumbo); + + rmon_stats->hist_tx[0] =3D u64_stats_read(&mib->tx_64byte); + rmon_stats->hist_tx[1] =3D u64_stats_read(&mib->tx_65_127byte); + rmon_stats->hist_tx[2] =3D u64_stats_read(&mib->tx_128_255byte); + rmon_stats->hist_tx[3] =3D u64_stats_read(&mib->tx_256_511byte); + rmon_stats->hist_tx[4] =3D u64_stats_read(&mib->tx_512_1023byte); + rmon_stats->hist_tx[5] =3D u64_stats_read(&mib->tx_1024_1518byte); + rmon_stats->hist_tx[6] =3D u64_stats_read(&mib->tx_jumbo); + } while (u64_stats_fetch_retry(&pp->syncp, start)); } =20 static void @@ -905,33 +942,41 @@ yt921x_dsa_get_stats64(struct dsa_switch *ds, int por= t, struct yt921x_priv *priv =3D to_yt921x_priv(ds); struct yt921x_port *pp =3D &priv->ports[port]; struct yt921x_mib *mib =3D &pp->mib; + unsigned int start; + + do { + start =3D u64_stats_fetch_begin(&pp->syncp); + + stats->rx_length_errors =3D u64_stats_read(&mib->rx_undersize_errors) + + u64_stats_read(&mib->rx_fragment_errors); + stats->rx_over_errors =3D u64_stats_read(&mib->rx_oversize_errors); + stats->rx_crc_errors =3D u64_stats_read(&mib->rx_crc_errors); + stats->rx_frame_errors =3D u64_stats_read(&mib->rx_alignment_errors); + /* stats->rx_fifo_errors */ + /* stats->rx_missed_errors */ + + stats->tx_aborted_errors =3D u64_stats_read(&mib->tx_aborted_errors); + /* stats->tx_carrier_errors */ + stats->tx_fifo_errors =3D u64_stats_read(&mib->tx_undersize_errors); + /* stats->tx_heartbeat_errors */ + stats->tx_window_errors =3D u64_stats_read(&mib->tx_late_collisions); + + stats->rx_packets =3D u64_stats_read(&pp->rx_frames); + stats->tx_packets =3D u64_stats_read(&pp->tx_frames); + stats->rx_bytes =3D u64_stats_read(&mib->rx_good_bytes) - + ETH_FCS_LEN * stats->rx_packets; + stats->tx_bytes =3D u64_stats_read(&mib->tx_good_bytes) - + ETH_FCS_LEN * stats->tx_packets; + stats->rx_dropped =3D u64_stats_read(&mib->rx_dropped); + /* stats->tx_dropped */ + stats->multicast =3D u64_stats_read(&mib->rx_multicast); + stats->collisions =3D u64_stats_read(&mib->tx_collisions); + } while (u64_stats_fetch_retry(&pp->syncp, start)); =20 - stats->rx_length_errors =3D mib->rx_undersize_errors + - mib->rx_fragment_errors; - stats->rx_over_errors =3D mib->rx_oversize_errors; - stats->rx_crc_errors =3D mib->rx_crc_errors; - stats->rx_frame_errors =3D mib->rx_alignment_errors; - /* stats->rx_fifo_errors */ - /* stats->rx_missed_errors */ - - stats->tx_aborted_errors =3D mib->tx_aborted_errors; - /* stats->tx_carrier_errors */ - stats->tx_fifo_errors =3D mib->tx_undersize_errors; - /* stats->tx_heartbeat_errors */ - stats->tx_window_errors =3D mib->tx_late_collisions; - - stats->rx_packets =3D pp->rx_frames; - stats->tx_packets =3D pp->tx_frames; - stats->rx_bytes =3D mib->rx_good_bytes - ETH_FCS_LEN * stats->rx_packets; - stats->tx_bytes =3D mib->tx_good_bytes - ETH_FCS_LEN * stats->tx_packets; stats->rx_errors =3D stats->rx_length_errors + stats->rx_over_errors + stats->rx_crc_errors + stats->rx_frame_errors; stats->tx_errors =3D stats->tx_aborted_errors + stats->tx_fifo_errors + stats->tx_window_errors; - stats->rx_dropped =3D mib->rx_dropped; - /* stats->tx_dropped */ - stats->multicast =3D mib->rx_multicast; - stats->collisions =3D mib->tx_collisions; } =20 static void @@ -941,13 +986,18 @@ yt921x_dsa_get_pause_stats(struct dsa_switch *ds, int= port, struct yt921x_priv *priv =3D to_yt921x_priv(ds); struct yt921x_port *pp =3D &priv->ports[port]; struct yt921x_mib *mib =3D &pp->mib; + unsigned int start; =20 mutex_lock(&priv->reg_lock); yt921x_read_mib(priv, port); mutex_unlock(&priv->reg_lock); =20 - pause_stats->tx_pause_frames =3D mib->tx_pause; - pause_stats->rx_pause_frames =3D mib->rx_pause; + do { + start =3D u64_stats_fetch_begin(&pp->syncp); + + pause_stats->tx_pause_frames =3D u64_stats_read(&mib->tx_pause); + pause_stats->rx_pause_frames =3D u64_stats_read(&mib->rx_pause); + } while (u64_stats_fetch_retry(&pp->syncp, start)); } =20 static int @@ -2968,6 +3018,7 @@ static int yt921x_mdio_probe(struct mdio_device *mdio= dev) =20 pp->index =3D i; INIT_DELAYED_WORK(&pp->mib_read, yt921x_poll_mib); + u64_stats_init(&pp->syncp); } =20 ds =3D &priv->ds; diff --git a/drivers/net/dsa/yt921x.h b/drivers/net/dsa/yt921x.h index 61bb0ab3b09a..17fee83952c2 100644 --- a/drivers/net/dsa/yt921x.h +++ b/drivers/net/dsa/yt921x.h @@ -6,6 +6,8 @@ #ifndef __YT921X_H #define __YT921X_H =20 +#include + #include =20 #define YT921X_SMI_SWITCHID_M GENMASK(3, 2) @@ -475,55 +477,55 @@ enum yt921x_fdb_entry_status { #define yt921x_port_is_external(port) (8 <=3D (port) && (port) < 9) =20 struct yt921x_mib { - u64 rx_broadcast; - u64 rx_pause; - u64 rx_multicast; - u64 rx_crc_errors; - - u64 rx_alignment_errors; - u64 rx_undersize_errors; - u64 rx_fragment_errors; - u64 rx_64byte; - - u64 rx_65_127byte; - u64 rx_128_255byte; - u64 rx_256_511byte; - u64 rx_512_1023byte; - - u64 rx_1024_1518byte; - u64 rx_jumbo; - u64 rx_good_bytes; - - u64 rx_bad_bytes; - u64 rx_oversize_errors; - - u64 rx_dropped; - u64 tx_broadcast; - u64 tx_pause; - u64 tx_multicast; - - u64 tx_undersize_errors; - u64 tx_64byte; - u64 tx_65_127byte; - u64 tx_128_255byte; - - u64 tx_256_511byte; - u64 tx_512_1023byte; - u64 tx_1024_1518byte; - u64 tx_jumbo; - - u64 tx_good_bytes; - u64 tx_collisions; - - u64 tx_aborted_errors; - u64 tx_multiple_collisions; - u64 tx_single_collisions; - u64 tx_good; - - u64 tx_deferred; - u64 tx_late_collisions; - u64 rx_oam; - u64 tx_oam; + u64_stats_t rx_broadcast; + u64_stats_t rx_pause; + u64_stats_t rx_multicast; + u64_stats_t rx_crc_errors; + + u64_stats_t rx_alignment_errors; + u64_stats_t rx_undersize_errors; + u64_stats_t rx_fragment_errors; + u64_stats_t rx_64byte; + + u64_stats_t rx_65_127byte; + u64_stats_t rx_128_255byte; + u64_stats_t rx_256_511byte; + u64_stats_t rx_512_1023byte; + + u64_stats_t rx_1024_1518byte; + u64_stats_t rx_jumbo; + u64_stats_t rx_good_bytes; + + u64_stats_t rx_bad_bytes; + u64_stats_t rx_oversize_errors; + + u64_stats_t rx_dropped; + u64_stats_t tx_broadcast; + u64_stats_t tx_pause; + u64_stats_t tx_multicast; + + u64_stats_t tx_undersize_errors; + u64_stats_t tx_64byte; + u64_stats_t tx_65_127byte; + u64_stats_t tx_128_255byte; + + u64_stats_t tx_256_511byte; + u64_stats_t tx_512_1023byte; + u64_stats_t tx_1024_1518byte; + u64_stats_t tx_jumbo; + + u64_stats_t tx_good_bytes; + u64_stats_t tx_collisions; + + u64_stats_t tx_aborted_errors; + u64_stats_t tx_multiple_collisions; + u64_stats_t tx_single_collisions; + u64_stats_t tx_good; + + u64_stats_t tx_deferred; + u64_stats_t tx_late_collisions; + u64_stats_t rx_oam; + u64_stats_t tx_oam; }; =20 struct yt921x_port { @@ -533,9 +535,13 @@ struct yt921x_port { bool isolated; =20 struct delayed_work mib_read; + struct u64_stats_sync syncp; struct yt921x_mib mib; - u64 rx_frames; - u64 tx_frames; + u64_stats_t rx_frames; + u64_stats_t tx_frames; + + /* only used by read routine to avoid huge allocations on the stack */ + struct yt921x_mib mib_new; }; =20 struct yt921x_reg_ops { --=20 2.51.0