From: "Bastien Curutchet (Schneider Electric)" <bastien.curutchet@bootlin.com>
To: Woojung Huh <woojung.huh@microchip.com>,
UNGLinuxDriver@microchip.com, Andrew Lunn <andrew@lunn.ch>,
Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Richard Cochran <richardcochran@gmail.com>,
Christian Eggers <ceggers@arri.de>,
Arun Ramadoss <arun.ramadoss@microchip.com>
Cc: "Pascal Eberhard" <pascal.eberhard@se.com>,
"Miquèl Raynal" <miquel.raynal@bootlin.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org,
"Bastien Curutchet (Schneider Electric)"
<bastien.curutchet@bootlin.com>
Subject: [PATCH net v2] net: dsa: microchip: save the periodic output request
Date: Thu, 17 Sep 2026 10:39:04 +0200 [thread overview]
Message-ID: <20260917-fix-perout-v2-1-d8acf3eea6f7@bootlin.com> (raw)
When a periodic output is initialized, only the start and the period are
stored, not the flags nor the pin index. So when the periodic output is
restarted, the request flags and index are always set to 0. So if a pin
other than the first one was used, or if a flag was set in the request
that triggered the periodic output, it is lost when the output is
restarted.
Save the full request when the periodic output is initialized.
Use the saved request when the periodic output is reset
Cc: stable@vger.kernel.org
Fixes: 1f12ae5b6760 ("net: dsa: microchip: ptp: add periodic output signal")
Signed-off-by: Bastien Curutchet (Schneider Electric) <bastien.curutchet@bootlin.com>
---
Changes in v2:
- Save the full request insead of only flags and index.
- Link to v1: https://lore.kernel.org/r/20260914-fix-perout-v1-1-9f45531a7585@bootlin.com
---
drivers/net/dsa/microchip/ksz_ptp.c | 30 ++++++++++++++++--------------
drivers/net/dsa/microchip/ksz_ptp.h | 3 +--
2 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c
index 39cc70d65900..0979b6e04d1e 100644
--- a/drivers/net/dsa/microchip/ksz_ptp.c
+++ b/drivers/net/dsa/microchip/ksz_ptp.c
@@ -189,6 +189,7 @@ static int ksz_ptp_enable_perout(struct ksz_device *dev,
{
struct ksz_ptp_data *ptp_data = &dev->ptp_data;
u64 req_pulse_width_ns;
+ struct timespec64 tmp;
u64 cycle_width_ns;
u64 pulse_width_ns;
int pin = 0;
@@ -222,13 +223,11 @@ static int ksz_ptp_enable_perout(struct ksz_device *dev,
return 0;
}
- ptp_data->perout_target_time_first.tv_sec = request->start.sec;
- ptp_data->perout_target_time_first.tv_nsec = request->start.nsec;
+ memcpy(&ptp_data->perout_request, request, sizeof(struct ptp_perout_request));
- ptp_data->perout_period.tv_sec = request->period.sec;
- ptp_data->perout_period.tv_nsec = request->period.nsec;
-
- cycle_width_ns = timespec64_to_ns(&ptp_data->perout_period);
+ tmp.tv_sec = ptp_data->perout_request.period.sec;
+ tmp.tv_nsec = ptp_data->perout_request.period.nsec;
+ cycle_width_ns = timespec64_to_ns(&tmp);
if ((cycle_width_ns & TRIG_CYCLE_WIDTH_M) != cycle_width_ns)
return -EINVAL;
@@ -249,9 +248,10 @@ static int ksz_ptp_enable_perout(struct ksz_device *dev,
if (ret)
return ret;
+ tmp.tv_sec = ptp_data->perout_request.start.sec;
+ tmp.tv_nsec = ptp_data->perout_request.start.nsec;
ret = ksz_ptp_configure_perout(dev, cycle_width_ns, pulse_width_ns,
- &ptp_data->perout_target_time_first,
- pin);
+ &tmp, pin);
if (ret)
return ret;
@@ -763,6 +763,7 @@ static int ksz_ptp_restart_perout(struct ksz_device *dev)
struct ptp_perout_request request;
struct timespec64 next;
struct timespec64 now;
+ struct timespec64 tmp;
unsigned int count;
int ret;
@@ -773,10 +774,14 @@ static int ksz_ptp_restart_perout(struct ksz_device *dev)
return ret;
now_ns = timespec64_to_ns(&now);
- first_ns = timespec64_to_ns(&ptp_data->perout_target_time_first);
+ tmp.tv_sec = ptp_data->perout_request.start.sec;
+ tmp.tv_nsec = ptp_data->perout_request.start.nsec;
+ first_ns = timespec64_to_ns(&tmp);
/* Calculate next perout event based on start time and period */
- period_ns = timespec64_to_ns(&ptp_data->perout_period);
+ tmp.tv_sec = ptp_data->perout_request.period.sec;
+ tmp.tv_nsec = ptp_data->perout_request.period.nsec;
+ period_ns = timespec64_to_ns(&tmp);
if (first_ns < now_ns) {
count = div_u64(now_ns - first_ns, period_ns);
@@ -791,12 +796,9 @@ static int ksz_ptp_restart_perout(struct ksz_device *dev)
/* Restart periodic output signal */
next = ns_to_timespec64(next_ns);
+ memcpy(&request, &ptp_data->perout_request, sizeof(struct ptp_perout_request));
request.start.sec = next.tv_sec;
request.start.nsec = next.tv_nsec;
- request.period.sec = ptp_data->perout_period.tv_sec;
- request.period.nsec = ptp_data->perout_period.tv_nsec;
- request.index = 0;
- request.flags = 0;
return ksz_ptp_enable_perout(dev, &request, 1);
}
diff --git a/drivers/net/dsa/microchip/ksz_ptp.h b/drivers/net/dsa/microchip/ksz_ptp.h
index 7067ec9bd1e6..eb3827203b96 100644
--- a/drivers/net/dsa/microchip/ksz_ptp.h
+++ b/drivers/net/dsa/microchip/ksz_ptp.h
@@ -29,8 +29,7 @@ struct ksz_ptp_data {
spinlock_t clock_lock;
struct timespec64 clock_time;
enum ksz_ptp_tou_mode tou_mode;
- struct timespec64 perout_target_time_first; /* start of first pulse */
- struct timespec64 perout_period;
+ struct ptp_perout_request perout_request;
};
int ksz_ptp_clock_register(struct dsa_switch *ds);
---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260914-fix-perout-c8c972b89d7f
Best regards,
--
Bastien Curutchet (Schneider Electric) <bastien.curutchet@bootlin.com>
reply other threads:[~2026-09-17 8:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260917-fix-perout-v2-1-d8acf3eea6f7@bootlin.com \
--to=bastien.curutchet@bootlin.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew@lunn.ch \
--cc=arun.ramadoss@microchip.com \
--cc=ceggers@arri.de \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miquel.raynal@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=pascal.eberhard@se.com \
--cc=richardcochran@gmail.com \
--cc=stable@vger.kernel.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=woojung.huh@microchip.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®