* [PATCH net 1/3] net: mscc: ocelot: don't report that RX timestamping is enabled by default
2023-06-26 15:40 [PATCH net 0/3] Fix PTP packet drops with ocelot-8021q DSA tag protocol Vladimir Oltean
@ 2023-06-26 15:40 ` Vladimir Oltean
2023-06-26 15:40 ` [PATCH net 2/3] net: mscc: ocelot: don't keep PTP configuration of all ports in single structure Vladimir Oltean
2023-06-26 15:40 ` [PATCH net 3/3] net: dsa: felix: don't drop PTP frames with tag_8021q when RX timestamping is disabled Vladimir Oltean
2 siblings, 0 replies; 9+ messages in thread
From: Vladimir Oltean @ 2023-06-26 15:40 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, Florian Fainelli, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Claudiu Manoil, Alexandre Belloni,
UNGLinuxDriver, Xiaoliang Yang, Richard Cochran, Antoine Tenart,
linux-kernel
PTP RX timestamping should be enabled when the user requests it, not by
default. If it is enabled by default, it can be problematic when the
ocelot driver is a DSA master, and it sidesteps what DSA tries to avoid
through __dsa_master_hwtstamp_validate().
Additionally, after the change which made ocelot trap PTP packets only
to the CPU at ocelot_hwtstamp_set() time, it is no longer even true that
RX timestamping is enabled by default, because until ocelot_hwtstamp_set()
is called, the PTP traps are actually not set up. So the rx_filter field
of ocelot->hwtstamp_config reflects an incorrect reality.
Fixes: 96ca08c05838 ("net: mscc: ocelot: set up traps for PTP packets")
Fixes: 4e3b0468e6d7 ("net: mscc: PTP Hardware Clock (PHC) support")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/ethernet/mscc/ocelot_ptp.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/drivers/net/ethernet/mscc/ocelot_ptp.c b/drivers/net/ethernet/mscc/ocelot_ptp.c
index 2180ae94c744..673bfd70867a 100644
--- a/drivers/net/ethernet/mscc/ocelot_ptp.c
+++ b/drivers/net/ethernet/mscc/ocelot_ptp.c
@@ -824,11 +824,6 @@ int ocelot_init_timestamp(struct ocelot *ocelot,
ocelot_write(ocelot, PTP_CFG_MISC_PTP_EN, PTP_CFG_MISC);
- /* There is no device reconfiguration, PTP Rx stamping is always
- * enabled.
- */
- ocelot->hwtstamp_config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
-
return 0;
}
EXPORT_SYMBOL(ocelot_init_timestamp);
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH net 2/3] net: mscc: ocelot: don't keep PTP configuration of all ports in single structure
2023-06-26 15:40 [PATCH net 0/3] Fix PTP packet drops with ocelot-8021q DSA tag protocol Vladimir Oltean
2023-06-26 15:40 ` [PATCH net 1/3] net: mscc: ocelot: don't report that RX timestamping is enabled by default Vladimir Oltean
@ 2023-06-26 15:40 ` Vladimir Oltean
2023-06-26 15:40 ` [PATCH net 3/3] net: dsa: felix: don't drop PTP frames with tag_8021q when RX timestamping is disabled Vladimir Oltean
2 siblings, 0 replies; 9+ messages in thread
From: Vladimir Oltean @ 2023-06-26 15:40 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, Florian Fainelli, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Claudiu Manoil, Alexandre Belloni,
UNGLinuxDriver, Xiaoliang Yang, Richard Cochran, Antoine Tenart,
linux-kernel
In a future change, the driver will need to determine whether PTP RX
timestamping is enabled on a port (including whether traps were set up
on that port in particular) and that is currently not possible.
The driver supports different RX filters (L2, L4) and kinds of TX
timestamping (one-step, two-step) on its ports, but it saves all
configuration in a single struct hwtstamp_config that is global to the
switch. So, the latest timestamping configuration on one port
(including a request to disable timestamping) affects what gets reported
for all ports, even though the configuration itself is still individual
to each port.
The port timestamping configurations are only coupled because of the
common structure, so replace the hwtstamp_config with a ptp_rx_filter
saved per port. We also have the ptp_cmd to distinguish between one-step
and two-step PTP timestamping, so with those 2 bits of information we
can fully reconstruct a descriptive struct hwtstamp_config for each
port, during the SIOCGHWTSTAMP ioctl.
Fixes: 4e3b0468e6d7 ("net: mscc: PTP Hardware Clock (PHC) support")
Fixes: 96ca08c05838 ("net: mscc: ocelot: set up traps for PTP packets")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/ethernet/mscc/ocelot.c | 1 -
drivers/net/ethernet/mscc/ocelot_ptp.c | 30 +++++++++++++++++---------
include/soc/mscc/ocelot.h | 5 ++---
3 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c
index 1f5f00b30441..2fa833d041ba 100644
--- a/drivers/net/ethernet/mscc/ocelot.c
+++ b/drivers/net/ethernet/mscc/ocelot.c
@@ -2925,7 +2925,6 @@ int ocelot_init(struct ocelot *ocelot)
}
}
- mutex_init(&ocelot->ptp_lock);
mutex_init(&ocelot->mact_lock);
mutex_init(&ocelot->fwd_domain_lock);
mutex_init(&ocelot->tas_lock);
diff --git a/drivers/net/ethernet/mscc/ocelot_ptp.c b/drivers/net/ethernet/mscc/ocelot_ptp.c
index 673bfd70867a..d37637744bd3 100644
--- a/drivers/net/ethernet/mscc/ocelot_ptp.c
+++ b/drivers/net/ethernet/mscc/ocelot_ptp.c
@@ -476,8 +476,24 @@ static int ocelot_setup_ptp_traps(struct ocelot *ocelot, int port,
int ocelot_hwstamp_get(struct ocelot *ocelot, int port, struct ifreq *ifr)
{
- return copy_to_user(ifr->ifr_data, &ocelot->hwtstamp_config,
- sizeof(ocelot->hwtstamp_config)) ? -EFAULT : 0;
+ struct ocelot_port *ocelot_port = ocelot->ports[port];
+ struct hwtstamp_config cfg = {};
+
+ switch (ocelot_port->ptp_cmd) {
+ case IFH_REW_OP_TWO_STEP_PTP:
+ cfg.tx_type = HWTSTAMP_TX_ON;
+ break;
+ case IFH_REW_OP_ORIGIN_PTP:
+ cfg.tx_type = HWTSTAMP_TX_ONESTEP_SYNC;
+ break;
+ default:
+ cfg.tx_type = HWTSTAMP_TX_OFF;
+ break;
+ }
+
+ cfg.rx_filter = ocelot_port->ptp_rx_filter;
+
+ return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
}
EXPORT_SYMBOL(ocelot_hwstamp_get);
@@ -509,8 +525,6 @@ int ocelot_hwstamp_set(struct ocelot *ocelot, int port, struct ifreq *ifr)
return -ERANGE;
}
- mutex_lock(&ocelot->ptp_lock);
-
switch (cfg.rx_filter) {
case HWTSTAMP_FILTER_NONE:
break;
@@ -531,15 +545,12 @@ int ocelot_hwstamp_set(struct ocelot *ocelot, int port, struct ifreq *ifr)
l4 = true;
break;
default:
- mutex_unlock(&ocelot->ptp_lock);
return -ERANGE;
}
err = ocelot_setup_ptp_traps(ocelot, port, l2, l4);
- if (err) {
- mutex_unlock(&ocelot->ptp_lock);
+ if (err)
return err;
- }
if (l2 && l4)
cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
@@ -551,8 +562,7 @@ int ocelot_hwstamp_set(struct ocelot *ocelot, int port, struct ifreq *ifr)
cfg.rx_filter = HWTSTAMP_FILTER_NONE;
/* Commit back the result & save it */
- memcpy(&ocelot->hwtstamp_config, &cfg, sizeof(cfg));
- mutex_unlock(&ocelot->ptp_lock);
+ ocelot_port->ptp_rx_filter = cfg.rx_filter;
return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
}
diff --git a/include/soc/mscc/ocelot.h b/include/soc/mscc/ocelot.h
index cb8fbb241879..8fc6a07ab966 100644
--- a/include/soc/mscc/ocelot.h
+++ b/include/soc/mscc/ocelot.h
@@ -775,6 +775,8 @@ struct ocelot_port {
unsigned int ptp_skbs_in_flight;
struct sk_buff_head tx_skbs;
+ int ptp_rx_filter;
+
u16 mrp_ring_id;
u8 ptp_cmd;
@@ -868,12 +870,9 @@ struct ocelot {
u8 mm_supported:1;
struct ptp_clock *ptp_clock;
struct ptp_clock_info ptp_info;
- struct hwtstamp_config hwtstamp_config;
unsigned int ptp_skbs_in_flight;
/* Protects the 2-step TX timestamp ID logic */
spinlock_t ts_id_lock;
- /* Protects the PTP interface state */
- struct mutex ptp_lock;
/* Protects the PTP clock */
spinlock_t ptp_clock_lock;
struct ptp_pin_desc ptp_pins[OCELOT_PTP_PINS_NUM];
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH net 3/3] net: dsa: felix: don't drop PTP frames with tag_8021q when RX timestamping is disabled
2023-06-26 15:40 [PATCH net 0/3] Fix PTP packet drops with ocelot-8021q DSA tag protocol Vladimir Oltean
2023-06-26 15:40 ` [PATCH net 1/3] net: mscc: ocelot: don't report that RX timestamping is enabled by default Vladimir Oltean
2023-06-26 15:40 ` [PATCH net 2/3] net: mscc: ocelot: don't keep PTP configuration of all ports in single structure Vladimir Oltean
@ 2023-06-26 15:40 ` Vladimir Oltean
2023-06-27 15:12 ` Vladimir Oltean
2 siblings, 1 reply; 9+ messages in thread
From: Vladimir Oltean @ 2023-06-26 15:40 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, Florian Fainelli, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Claudiu Manoil, Alexandre Belloni,
UNGLinuxDriver, Xiaoliang Yang, Richard Cochran, Antoine Tenart,
linux-kernel
The driver implements a workaround for the fact that it doesn't have an
IRQ source to tell it whether PTP frames are available through the
extraction registers, for those frames to be processed and passed
towards the network stack. That workaround is to configure the switch,
through felix_hwtstamp_set() -> felix_update_trapping_destinations(),
to create two copies of PTP packets: one sent over Ethernet to the DSA
master, and one to be consumed through the aforementioned CPU extraction
queue registers.
The reason why we want PTP packets to be consumed through the CPU
extraction registers in the first place is because we want to see their
hardware RX timestamp. With tag_8021q, that is only visible that way,
and it isn't visible with the copy of the packet that's transmitted over
Ethernet.
The problem with the workaround implementation is that it drops the
packet received over Ethernet, in expectation of its copy being present
in the CPU extraction registers. However, if felix_hwtstamp_set() hasn't
run (aka PTP RX timestamping is disabled), the driver will drop the
original PTP frame and there will be no copy of it in the CPU extraction
registers. So, the network stack will simply not see any PTP frame.
Look at the port's ptp_rx_filter to see whether the driver has
previously enabled the CPU extraction registers. If it hasn't, just
don't RX timestamp the frame and let it be passed up the stack by DSA,
which is absolutely perfectly fine.
Fixes: 0a6f17c6ae21 ("net: dsa: tag_ocelot_8021q: add support for PTP timestamping")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/dsa/ocelot/felix.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c
index 80861ac090ae..7b494d975073 100644
--- a/drivers/net/dsa/ocelot/felix.c
+++ b/drivers/net/dsa/ocelot/felix.c
@@ -1725,6 +1725,9 @@ static bool felix_rxtstamp(struct dsa_switch *ds, int port,
u32 tstamp_hi;
u64 tstamp;
+ if (ocelot->ports[port]->ptp_rx_filter == HWTSTAMP_FILTER_NONE)
+ return false;
+
/* If the "no XTR IRQ" workaround is in use, tell DSA to defer this skb
* for RX timestamping. Then free it, and poll for its copy through
* MMIO in the CPU port module, and inject that into the stack from
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH net 3/3] net: dsa: felix: don't drop PTP frames with tag_8021q when RX timestamping is disabled
2023-06-26 15:40 ` [PATCH net 3/3] net: dsa: felix: don't drop PTP frames with tag_8021q when RX timestamping is disabled Vladimir Oltean
@ 2023-06-27 15:12 ` Vladimir Oltean
2023-06-27 15:46 ` Jakub Kicinski
0 siblings, 1 reply; 9+ messages in thread
From: Vladimir Oltean @ 2023-06-27 15:12 UTC (permalink / raw)
To: Vladimir Oltean
Cc: netdev, Andrew Lunn, Florian Fainelli, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Claudiu Manoil,
Alexandre Belloni, UNGLinuxDriver, Xiaoliang Yang,
Richard Cochran, Antoine Tenart, linux-kernel
On Mon, Jun 26, 2023 at 06:40:03PM +0300, Vladimir Oltean wrote:
> drivers/net/dsa/ocelot/felix.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c
> index 80861ac090ae..7b494d975073 100644
> --- a/drivers/net/dsa/ocelot/felix.c
> +++ b/drivers/net/dsa/ocelot/felix.c
> @@ -1725,6 +1725,9 @@ static bool felix_rxtstamp(struct dsa_switch *ds, int port,
> u32 tstamp_hi;
> u64 tstamp;
>
> + if (ocelot->ports[port]->ptp_rx_filter == HWTSTAMP_FILTER_NONE)
> + return false;
> +
> /* If the "no XTR IRQ" workaround is in use, tell DSA to defer this skb
> * for RX timestamping. Then free it, and poll for its copy through
> * MMIO in the CPU port module, and inject that into the stack from
> --
> 2.34.1
>
>
This is still not as good as I had wanted it, because simply checking
for HWTSTAMP_FILTER_NONE does not distinguish between L2 and L4
timestamping filters, and a port configured just with L2 traps will
still drop L4 PTP packets.
Preparing a v2.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net 3/3] net: dsa: felix: don't drop PTP frames with tag_8021q when RX timestamping is disabled
2023-06-27 15:12 ` Vladimir Oltean
@ 2023-06-27 15:46 ` Jakub Kicinski
2023-06-27 15:51 ` Vladimir Oltean
0 siblings, 1 reply; 9+ messages in thread
From: Jakub Kicinski @ 2023-06-27 15:46 UTC (permalink / raw)
To: Vladimir Oltean
Cc: Vladimir Oltean, netdev, Andrew Lunn, Florian Fainelli,
David S. Miller, Eric Dumazet, Paolo Abeni, Claudiu Manoil,
Alexandre Belloni, UNGLinuxDriver, Xiaoliang Yang,
Richard Cochran, Antoine Tenart, linux-kernel
On Tue, 27 Jun 2023 18:12:22 +0300 Vladimir Oltean wrote:
> This is still not as good as I had wanted it, because simply checking
> for HWTSTAMP_FILTER_NONE does not distinguish between L2 and L4
> timestamping filters, and a port configured just with L2 traps will
> still drop L4 PTP packets.
Out of curiosity - quick survey on why your reply does not contain:
pw-bot: changes-requested
a) your email address is different and the bot doesn't understand
aliases
b) commands are hard to remember
c) don't care about patchwork
d) laziness
e) other
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH net 3/3] net: dsa: felix: don't drop PTP frames with tag_8021q when RX timestamping is disabled
2023-06-27 15:46 ` Jakub Kicinski
@ 2023-06-27 15:51 ` Vladimir Oltean
2023-06-27 15:53 ` Jakub Kicinski
0 siblings, 1 reply; 9+ messages in thread
From: Vladimir Oltean @ 2023-06-27 15:51 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Vladimir Oltean, netdev, Andrew Lunn, Florian Fainelli,
David S. Miller, Eric Dumazet, Paolo Abeni, Claudiu Manoil,
Alexandre Belloni, UNGLinuxDriver, Xiaoliang Yang,
Richard Cochran, Antoine Tenart, linux-kernel
On Tue, Jun 27, 2023 at 08:46:51AM -0700, Jakub Kicinski wrote:
> On Tue, 27 Jun 2023 18:12:22 +0300 Vladimir Oltean wrote:
> > This is still not as good as I had wanted it, because simply checking
> > for HWTSTAMP_FILTER_NONE does not distinguish between L2 and L4
> > timestamping filters, and a port configured just with L2 traps will
> > still drop L4 PTP packets.
>
> Out of curiosity - quick survey on why your reply does not contain:
>
> pw-bot: changes-requested
>
> a) your email address is different and the bot doesn't understand
> aliases
> b) commands are hard to remember
> c) don't care about patchwork
> d) laziness
> e) other
hmm, I'll tick e) unslept...
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net 3/3] net: dsa: felix: don't drop PTP frames with tag_8021q when RX timestamping is disabled
2023-06-27 15:51 ` Vladimir Oltean
@ 2023-06-27 15:53 ` Jakub Kicinski
2023-06-27 15:57 ` Vladimir Oltean
0 siblings, 1 reply; 9+ messages in thread
From: Jakub Kicinski @ 2023-06-27 15:53 UTC (permalink / raw)
To: Vladimir Oltean
Cc: Vladimir Oltean, netdev, Andrew Lunn, Florian Fainelli,
David S. Miller, Eric Dumazet, Paolo Abeni, Claudiu Manoil,
Alexandre Belloni, UNGLinuxDriver, Xiaoliang Yang,
Richard Cochran, Antoine Tenart, linux-kernel
On Tue, 27 Jun 2023 18:51:47 +0300 Vladimir Oltean wrote:
> > pw-bot: changes-requested
> >
> > a) your email address is different and the bot doesn't understand
> > aliases
> > b) commands are hard to remember
> > c) don't care about patchwork
> > d) laziness
> > e) other
>
> hmm, I'll tick e) unslept...
Ah, good, I was worried it was the aliases and I don't have a great
plan yet for how to deal with that :)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net 3/3] net: dsa: felix: don't drop PTP frames with tag_8021q when RX timestamping is disabled
2023-06-27 15:53 ` Jakub Kicinski
@ 2023-06-27 15:57 ` Vladimir Oltean
0 siblings, 0 replies; 9+ messages in thread
From: Vladimir Oltean @ 2023-06-27 15:57 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Vladimir Oltean, netdev, Andrew Lunn, Florian Fainelli,
David S. Miller, Eric Dumazet, Paolo Abeni, Claudiu Manoil,
Alexandre Belloni, UNGLinuxDriver, Xiaoliang Yang,
Richard Cochran, Antoine Tenart, linux-kernel
On Tue, Jun 27, 2023 at 08:53:33AM -0700, Jakub Kicinski wrote:
> On Tue, 27 Jun 2023 18:51:47 +0300 Vladimir Oltean wrote:
> > > pw-bot: changes-requested
> > >
> > > a) your email address is different and the bot doesn't understand
> > > aliases
> > > b) commands are hard to remember
> > > c) don't care about patchwork
> > > d) laziness
> > > e) other
> >
> > hmm, I'll tick e) unslept...
>
> Ah, good, I was worried it was the aliases and I don't have a great
> plan yet for how to deal with that :)
No, I can easily switch to the work email, I just wasn't paying enough
attention to which screen I was looking at.
^ permalink raw reply [flat|nested] 9+ messages in thread