From nobody Wed Dec 17 15:14:06 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D78DAC77B7C for ; Wed, 19 Apr 2023 15:24:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232893AbjDSPYK (ORCPT ); Wed, 19 Apr 2023 11:24:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232651AbjDSPYI (ORCPT ); Wed, 19 Apr 2023 11:24:08 -0400 Received: from synguard (unknown [212.29.212.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA0BC901D; Wed, 19 Apr 2023 08:23:31 -0700 (PDT) Received: from dali.siklu.local (dali.siklu.local [192.168.42.30]) by synguard (Postfix) with ESMTP id 571014DFC6; Wed, 19 Apr 2023 18:14:59 +0300 (IDT) From: Shmuel Hazan To: Russell King Cc: Marcin Wojtas , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , horatiu.vultur@microchip.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, Shmuel Hazan Subject: [PATCH v3 1/3] net: mvpp2: tai: add refcount for ptp worker Date: Wed, 19 Apr 2023 18:14:55 +0300 Message-Id: <20230419151457.22411-2-shmuel.h@siklu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230419151457.22411-1-shmuel.h@siklu.com> References: <20230419151457.22411-1-shmuel.h@siklu.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In some configurations, a single TAI can be responsible for multiple mvpp2 interfaces. However, the mvpp2 driver will call mvpp22_tai_stop and mvpp22_tai_start per interface RX timestamp disable/enable. As a result, disabling timestamping for one interface would stop the worker and corrupt the other interface's RX timestamps. This commit solves the issue by introducing a simpler ref count for each TAI instance. Due to the ref count, we need now to lock tai->lock before doing anything, as a result, we can't update the current ts using mvpp22_tai_gettimex64 as it will cause a deadlock. Therefore, we will just schedule the worker to start immediately. Fixes: ce3497e2072e ("net: mvpp2: ptp: add support for receive timestamping= ") Signed-off-by: Shmuel Hazan --- .../net/ethernet/marvell/mvpp2/mvpp2_tai.c | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c b/drivers/net/e= thernet/marvell/mvpp2/mvpp2_tai.c index 95862aff49f1..2e3d43b1bac1 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c @@ -61,6 +61,7 @@ struct mvpp2_tai { u64 period; // nanosecond period in 32.32 fixed point /* This timestamp is updated every two seconds */ struct timespec64 stamp; + u16 poll_worker_refcount; }; =20 static void mvpp2_tai_modify(void __iomem *reg, u32 mask, u32 set) @@ -368,18 +369,39 @@ void mvpp22_tai_tstamp(struct mvpp2_tai *tai, u32 tst= amp, hwtstamp->hwtstamp =3D timespec64_to_ktime(ts); } =20 +static void mvpp22_tai_start_unlocked(struct mvpp2_tai *tai) +{ + tai->poll_worker_refcount++; + if (tai->poll_worker_refcount > 1) + return; + + ptp_schedule_worker(tai->ptp_clock, 0); +} + void mvpp22_tai_start(struct mvpp2_tai *tai) { - long delay; + unsigned long flags; =20 - delay =3D mvpp22_tai_aux_work(&tai->caps); + spin_lock_irqsave(&tai->lock, flags); + mvpp22_tai_start_unlocked(tai); + spin_unlock_irqrestore(&tai->lock, flags); +} =20 - ptp_schedule_worker(tai->ptp_clock, delay); +static void mvpp22_tai_stop_unlocked(struct mvpp2_tai *tai) +{ + tai->poll_worker_refcount--; + if (tai->poll_worker_refcount) + return; + ptp_cancel_worker_sync(tai->ptp_clock); } =20 void mvpp22_tai_stop(struct mvpp2_tai *tai) { - ptp_cancel_worker_sync(tai->ptp_clock); + unsigned long flags; + + spin_lock_irqsave(&tai->lock, flags); + mvpp22_tai_stop_unlocked(tai); + spin_unlock_irqrestore(&tai->lock, flags); } =20 static void mvpp22_tai_remove(void *priv) --=20 2.40.0