2023-04-17 16:24:16

by Shmuel Hazan

[permalink] [raw]
Subject: [PATCH 1/3] net: mvpp2: tai: add refcount for ptp worker

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 <[email protected]>
---
.../net/ethernet/marvell/mvpp2/mvpp2_tai.c | 30 +++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
index 95862aff49f1..9c0d50a924d9 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,20 +369,45 @@ void mvpp22_tai_tstamp(struct mvpp2_tai *tai, u32 tstamp,
hwtstamp->hwtstamp = timespec64_to_ktime(ts);
}

-void mvpp22_tai_start(struct mvpp2_tai *tai)
+static void mvpp22_tai_start_unlocked(struct mvpp2_tai *tai)
{
long delay;

+ tai->poll_worker_refcount++;
+ if (tai->poll_worker_refcount > 1)
+ return;
+
delay = mvpp22_tai_aux_work(&tai->caps);

ptp_schedule_worker(tai->ptp_clock, delay);
}

-void mvpp22_tai_stop(struct mvpp2_tai *tai)
+void mvpp22_tai_start(struct mvpp2_tai *tai)
{
+ unsigned long flags;
+
+ spin_lock_irqsave(&tai->lock, flags);
+ mvpp22_tai_start_unlocked(tai);
+ spin_unlock_irqrestore(&tai->lock, flags);
+}
+
+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)
+{
+ 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)
{
struct mvpp2_tai *tai = priv;
--
2.40.0


2023-04-18 00:20:45

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH 1/3] net: mvpp2: tai: add refcount for ptp worker

On Mon, Apr 17, 2023 at 07:01:49PM +0300, Shmuel Hazan wrote:
> 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.

This is version 2, so you should add that to the subject line. You
should also indicate what changed since the previous version.

Please read https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

You have added Fixes: tags, so you think this is a fix for stable? You
then should indicate this on the Subject line.

> Fixes: ce3497e2072e ("net: mvpp2: ptp: add support for receive timestamping")
> Signed-off-by: Shmuel Hazan <[email protected]>

Reviewed-by: Andrew Lunn <[email protected]>

Andrew