Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4275041rwe; Mon, 17 Apr 2023 10:12:23 -0700 (PDT) X-Google-Smtp-Source: AKy350Zt1AifIbNRXzxYrsxzhC1WOM3JFNfQexgRKLFP9IC5hxFHyBu6j7EiTgSjnopPKHpixP+7 X-Received: by 2002:a17:903:40c7:b0:1a6:52f9:d4c7 with SMTP id t7-20020a17090340c700b001a652f9d4c7mr12685720pld.60.1681751542929; Mon, 17 Apr 2023 10:12:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681751542; cv=none; d=google.com; s=arc-20160816; b=GpLiEwi02+VZ6rzshtiuQ1IL0mJ+3BT3rFNL8uVZEmkyrnjpDgtmztma5Gfq6mYhNg 1AVW9mNbjNfsO0vqy/psLfAap7snYh3n0mOxj7c6B744tSEecipwGHLqN9yoPBkCvzfz q4RRl0Yt3iKlqh4IOpJximVG3eEL0ptXyGVn5VuX5VyPUKsOu97KnvlUFRan8A7c8cdl bW7h+EEyarAzeuuZsqcHe3wBEJ5h/INQzGGYg0yKqNpKVef3RiK0Q+i4ICFeRSjUGsg5 8uVN3eiqcJVQPhruVfkwLGA5u0gzvULcblZY2fsMGY3uMvGjwy4C3ObSQTIw6ApIux6K C1Kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4ltlFYwrfcRM1MkeXooZMSatFCMZ6AMIfDbSI6hCJcw=; b=fuMwutRO5B8hngEVNKv5ndVv2ubNdyfMLuvu7Mp6MHrhAScAZ4cufdMpYheN5Urj7x 3lWZ5nFEB+RUpvROQCb4ScidNAbju4+x0wujFTJ8PTr9eagONOluwcNC5YlltXXaLG4g Uze43KOtnfB0Zu0tx5uu4jlxneIE1Dh7gWwbNewiqfeLkEuqktAYU4l5BqUnYcy6yzUw FNbBvbJVQqA36UB3wBq1dZKfRgZjjr8DQW0YkH7IdivI9p+wNiLmALPBjHbhrA/5oJUP 4h2vqKHnLlAfgrGX2wXu42ZKwcCutkTl1qZSr5GJB4DtHzAbY4C/OOQZ8IVNRLzUYEbH xw5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j5-20020a170902c08500b001a6f49761c6si792025pld.433.2023.04.17.10.12.10; Mon, 17 Apr 2023 10:12:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229894AbjDQRIE (ORCPT + 99 others); Mon, 17 Apr 2023 13:08:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229800AbjDQRID (ORCPT ); Mon, 17 Apr 2023 13:08:03 -0400 Received: from synguard (unknown [212.29.212.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03BE546AE; Mon, 17 Apr 2023 10:08:01 -0700 (PDT) Received: from T14.siklu.local (unknown [192.168.42.162]) by synguard (Postfix) with ESMTP id 0D2CE4DE99; Mon, 17 Apr 2023 20:08:00 +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, Shmuel Hazan Subject: [PATCH v2 1/3] net: mvpp2: tai: add refcount for ptp worker Date: Mon, 17 Apr 2023 20:07:39 +0300 Message-Id: <20230417170741.1714310-2-shmuel.h@siklu.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230417170741.1714310-1-shmuel.h@siklu.com> References: <20230417170741.1714310-1-shmuel.h@siklu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,FSL_HELO_NON_FQDN_1, HELO_NO_DOMAIN,RDNS_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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/ethernet/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; }; 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 tstamp, hwtstamp->hwtstamp = timespec64_to_ktime(ts); } +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; - delay = mvpp22_tai_aux_work(&tai->caps); + spin_lock_irqsave(&tai->lock, flags); + mvpp22_tai_start_unlocked(tai); + spin_unlock_irqrestore(&tai->lock, flags); +} - 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); } 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); } static void mvpp22_tai_remove(void *priv) -- 2.40.0