net: mvpp2: tai: add refcount for ptp worker
Subsystems (3)
RFC PATCH 1/1 net: mvpp2: tai: add refcount for ptp worker
From bd7fb292219e6b64a650a6c79d09822dbef662d3 Mon Sep 17 00:00:00 2001
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.
timestamping")
--- drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c | 8 ++++++++ 1 file changed, 8 insertions(+)
(quoted diff) +0 -0
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c index 95862aff49f1..1b57573dd866 100644
drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c +0 -0
@@ -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)
@@ -372,6 +373,10 @@ void mvpp22_tai_start(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);
@@ -379,6 +384,9 @@ void mvpp22_tai_start(struct mvpp2_tai *tai)
void mvpp22_tai_stop(struct mvpp2_tai *tai) {
+ tai->poll_worker_refcount--;
+ if (tai->poll_worker_refcount)
+ return;
ptp_cancel_worker_sync(tai->ptp_clock);
}
Signature · 1 line
2.40.0
drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
Quoted 11 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c +0
-0@@ -61,6 +61,7 @@ struct mvpp2_tai {u64 period;// nanosecond period in 32.32 fixed point
drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c +1
-0/* This timestamp is updated every two seconds */ struct timespec64 stamp; +u16 poll_worker_refcount;
What lock is protecting this? It would be nice to comment in the commit message why it is safe to use a simple u16.
Andrew
Quoted 15 lines · Andrew Lunn
Quoted 9 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c +0
-0@@ -61,6 +61,7 @@ struct mvpp2_tai {u64 period;// nanosecond period in 32.32 fixed point
Quoted 3 lines
/* This timestamp is updated every two seconds */ struct timespec64 stamp;+ u16
poll_worker_refcount;What lock is protecting this? It would be nice to comment in the commit message why it is safe to use a simple u16.
Hi Andrew,
thanks for your response. In theory, the only code path to these functions (mvpp22_tai_start and mvpp22_tai_stop) is ioctl (mvpp2_ioctl -> mvpp2_set_ts_config) which should lock rtnl. However,
It would probably be a good idea to also lock mvpp2_tai->lock too.
As for the integer size, it will be increased once per ethernet device on that CP, which currently has only maximum of 3 ethernet ports. I gave it u16 just to be futureproof. However, I can change it to a more appropriate type if it looks more appropriate to you.
Quoted 2 lines
Andrew
Quoted 17 lines · Shmuel Hazan
Quoted 15 lines · Andrew Lunn
Quoted 9 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c +0
-0@@ -61,6 +61,7 @@ struct mvpp2_tai {u64 period;// nanosecond period in 32.32 fixed point
Quoted 3 lines
/* This timestamp is updated every two seconds */ struct timespec64 stamp;+ u16
poll_worker_refcount;What lock is protecting this? It would be nice to comment in the commit message why it is safe to use a simple u16.
Quoted 7 lines
Hi Andrew,
thanks for your response. In theory, the only code path to these functions (
mvpp22_tai_startandmvpp22_tai_stop) is ioctl (mvpp2_ioctl->mvpp2_set_ts_config) which should lock rtnl. However,
It would probably be a good idea to also lockmvpp2_tai->locktoo.
I cannot comment on what locks should be used, i don't know the code.
Which is why as a reviewer, i just want some indication you have thought about locking, and you think it is safe, given that there are not obvious locks in the code.
Andrew
Russell King (Oracle)
maintainerQuoted 26 lines · Andrew Lunn
Quoted 17 lines · Shmuel Hazan
Quoted 15 lines · Andrew Lunn
Quoted 9 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c +0
-0@@ -61,6 +61,7 @@ struct mvpp2_tai {u64 period;// nanosecond period in 32.32 fixed point
Quoted 3 lines
/* This timestamp is updated every two seconds */ struct timespec64 stamp;+ u16
poll_worker_refcount;What lock is protecting this? It would be nice to comment in the commit message why it is safe to use a simple u16.
Quoted 7 lines
Hi Andrew,
thanks for your response. In theory, the only code path to these functions (
mvpp22_tai_startandmvpp22_tai_stop) is ioctl (mvpp2_ioctl->mvpp2_set_ts_config) which should lock rtnl. However,
It would probably be a good idea to also lockmvpp2_tai->locktoo.
Quoted 5 lines
I cannot comment on what locks should be used, i don't know the code.
Which is why as a reviewer, i just want some indication you have thought about locking, and you think it is safe, given that there are not obvious locks in the code.
... and probably is a good idea to place a comment in the code stating what the locking for it is.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!