Skip to contentSkip to conversation

net: lan969x: skew the core clock by 200 ppm

PATCH Applied Daniel Machon 3 participants 8 messages Nov 13 – Nov 17

Subsystems (4)
lore
Share & tools
lore

Daniel Machon

author maintainer
#0 lore raw

cover net: lan969x: skew the core clock by 200 ppm

At its 328.125 MHz default, the lan969x core clock is too close to the line clock frequencies for the high accuracy phase detectors to work as intended, which degrades PTP accuracy. The core clock should therefore be skewed about 200 ppm up. The PTP time of day (TOD) increment is already set up for the skewed rate, but the driver leaves the core PLL at its default, so the TOD and the clock that drives the scheduler run 200 ppm apart.

This series programs the core PLL to the skewed rate, and reworks the PTP frequency adjustment to scale the nominal increment directly. It is not a fix as such, but an improvement: nothing breaks at the default rate, and this moves lan969x to the core clock configuration recommended for PTP.

The difference can be seen with taprio: timestamping the frames released by a schedule with a 1 ms cycle time shows the gates opening about every 1000.2 us instead of every 1000 us.

Patch 1 adds the CHIP_TOP registers and maps the target.

Patch 2 enables the switch core only after the core clock is configured, so the PLL is not reprogrammed underneath a running queue system.

Patch 3 programs the core PLL.

Patch 4 makes the PTP frequency adjustment scale the nominal increment instead of using a separate one ppm table.

Tested on lan969x and sparx5.

---
Daniel Machon (4):
net: lan969x: add the core PLL registers
net: sparx5/lan969x: enable the switch core after clock setup
net: lan969x: configure the core PLL
net: sparx5/lan969x: scale the nominal TOD increment in adjfine

 .../ethernet/microchip/sparx5/lan969x/lan969x.c    |   1 +
 .../net/ethernet/microchip/sparx5/sparx5_main.c    | 123 ++++++++++++++++++++-
 .../net/ethernet/microchip/sparx5/sparx5_main.h    |   7 ++
 .../ethernet/microchip/sparx5/sparx5_main_regs.h   |  82 ++++++++++++++
 drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c |  54 +--------
 5 files changed, 217 insertions(+), 50 deletions(-)

---
base-commit: 676f3aace662fbbc180b3898b190a372fa2a516b
change-id: 20261022-lan969x-core-skew-ff5155ead4be

Best regards,

Signature · 1 line
Daniel Machon <[email protected]>
author maintainer
#1 lore raw

PATCH 1/4 net: lan969x: add the core PLL registers

Add the CHIP_TOP registers required to configure the lan969x core PLL, and map the CHIP_TOP target. They are used in a later patch of this series.

---
 .../ethernet/microchip/sparx5/lan969x/lan969x.c    |  1 +
 .../ethernet/microchip/sparx5/sparx5_main_regs.h   | 82 ++++++++++++++++++++++
 2 files changed, 83 insertions(+)
drivers/net/ethernet/microchip/sparx5/lan969x/lan969x.c +1 -0
index c02499d1b297a..df211e608056a 100644
@@ -13,6 +13,7 @@ static const struct sparx5_main_io_resource lan969x_main_iomap[] =  {
 	{ TARGET_CPU,                   0xc0000, 0 }, /* 0xe00c0000 */
 	{ TARGET_FDMA,                  0xc0400, 0 }, /* 0xe00c0400 */
 	{ TARGET_GCB,                 0x2010000, 1 }, /* 0xe2010000 */
+	{ TARGET_CHIP_TOP,            0x2020000, 1 }, /* 0xe2020000 */
 	{ TARGET_QS,                  0x2030000, 1 }, /* 0xe2030000 */
 	{ TARGET_PTP,                 0x2040000, 1 }, /* 0xe2040000 */
 	{ TARGET_ANA_ACL,             0x2050000, 1 }, /* 0xe2050000 */
drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h +82 -0

94 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH 2/4 net: sparx5/lan969x: enable the switch core after clock setup

In reply to Daniel Machon

sparx5_init_switchcore() ends by setting HSCH_RESET_CFG.CORE_ENA, so the switch core and queue system are already running when sparx5_init_coreclock() configures the core clock afterwards. That is fine for the dividers it sets on sparx5, but a later patch makes it also program the lan969x core PLL, which should be done before the queue system is enabled.

Move the CORE_ENA write to mchp_sparx5_probe(), right after sparx5_init_coreclock(), so the core is enabled once its clock is set up.

CORE_ENA also tells sparx5_init_switchcore() that the switch memories are already initialized. The switch is only reset once, when the reset controller probes, so after an unbind and bind CORE_ENA is still set and the core clock is configured with the queue system running.

---
 drivers/net/ethernet/microchip/sparx5/sparx5_main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +3 -3
index 68c80c63f9087..93a7cb89493c4 100644
@@ -471,9 +471,6 @@ static int sparx5_init_switchcore(struct sparx5 *sparx5)
 	spx5_wr(ANA_AC_STAT_RESET_RESET_SET(1), sparx5, ANA_AC_STAT_RESET);
 	spx5_wr(ASM_STAT_CFG_STAT_CNT_CLR_SHOT_SET(1), sparx5, ASM_STAT_CFG);
 
-	/* Enable switch-core and queue system */
-	spx5_wr(HSCH_RESET_CFG_CORE_ENA_SET(1), sparx5, HSCH_RESET_CFG);
-
 	return 0;
 }
 
@@ -928,6 +925,9 @@ static int mchp_sparx5_probe(struct platform_device *pdev)
 		goto cleanup_config;
 	}
 
+	/* Enable switch-core and queue system */
+	spx5_wr(HSCH_RESET_CFG_CORE_ENA_SET(1), sparx5, HSCH_RESET_CFG);
+
 	for (idx = 0; idx < sparx5->port_count; ++idx) {
 		config = &configs[idx];
 		if (!config->node)
Signature · 1 line
2.34.1
author maintainer
#3 lore raw

PATCH 3/4 net: lan969x: configure the core PLL

In reply to Daniel Machon

The lan969x core PLL is left at its 328.125 MHz default, while the PTP time of day (TOD) increment from sparx5_ptp_get_nominal_value() assumes a core clock skewed about 200 ppm up, as recommended for the high accuracy phase detectors. The TOD and the clock that drives the scheduler therefore run 200 ppm apart: a 1 ms taprio cycle takes about 1000.2 us.

Program the core PLL to the skewed rate from sparx5_init_coreclock(), using the glitch free divider change documented for CORE_PLL_CFG.

Select the dividers, and the matching TOD increment, from the reference clock read from the strapping pin. Leave the PLL alone if it is already configured, and disable the register configuration again if the change fails.

---
 .../net/ethernet/microchip/sparx5/sparx5_main.c    | 119 +++++++++++++++++++++
 .../net/ethernet/microchip/sparx5/sparx5_main.h    |   7 ++
 drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c |   5 +-
 3 files changed, 130 insertions(+), 1 deletion(-)
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +119 -0
index 93a7cb89493c4..244974ffe496b 100644
@@ -474,10 +474,120 @@ static int sparx5_init_switchcore(struct sparx5 *sparx5)
 	return 0;
 }
 
+struct lan969x_core_pll_dividers {
+	u32 divfi;
+	u32 divff;
+	u32 divr;
+	u32 divq;
+};
+
+static const struct lan969x_core_pll_dividers lan969x_core_pll_328mhz[] = {
+	[SPX5_CORE_CLOCK_REF_25MHZ] = {
+		.divfi = 64, .divff = 0xa36076, .divr = 3, .divq = 10,
+	},
+	[SPX5_CORE_CLOCK_REF_39MHZ] = {
+		.divfi = 72, .divff = 0x83c361, .divr = 6, .divq = 10,
+	},
+};
+
+static int lan969x_init_core_pll(struct sparx5 *sparx5)
+{
+	const struct lan969x_core_pll_dividers *div;
+	u32 hw_stat, pll_cfg, freq_cfg;
+	enum sparx5_core_clockref ref;
+	int err;
+
+	hw_stat = spx5_rd(sparx5, CHIP_TOP_HW_STAT);
+	ref = CHIP_TOP_HW_STAT_REFCLK_SEL_GET(hw_stat) ?
+		SPX5_CORE_CLOCK_REF_39MHZ : SPX5_CORE_CLOCK_REF_25MHZ;
+	div = &lan969x_core_pll_328mhz[ref];
+	sparx5->coreclockref = ref;
+
+	/* Already configured by an earlier probe? */
+	pll_cfg = spx5_rd(sparx5, CHIP_TOP_CORE_PLL_CFG);
+	freq_cfg = spx5_rd(sparx5, CHIP_TOP_CORE_PLL_FREQ_CFG);
+	if (CHIP_TOP_CORE_PLL_CFG_ENA_CFG_GET(pll_cfg) &&
+	    CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFI_GET(freq_cfg) == div->divfi &&
+	    CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFF_GET(freq_cfg) == div->divff)
+		return 0;
+
+	spx5_rmw(CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFI_SET(div->divfi) |
+		 CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFF_SET(div->divff),
+		 CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFI |
+		 CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFF,
+		 sparx5, CHIP_TOP_CORE_PLL_FREQ_CFG);
+
+	/* Set the reference and output dividers, select the reference clock
+	 * from the strapping pin and use fractional mode.
+	 */
+	spx5_rmw(CHIP_TOP_CORE_PLL_CFG_DIVQ_SET(div->divq) |
+		 CHIP_TOP_CORE_PLL_CFG_DIVR_SET(div->divr) |
+		 CHIP_TOP_CORE_PLL_CFG_REF_CLK_SEL_SET(0) |
+		 CHIP_TOP_CORE_PLL_CFG_FILTER_RANGE_SET(0),
+		 CHIP_TOP_CORE_PLL_CFG_DIVQ |
+		 CHIP_TOP_CORE_PLL_CFG_DIVR |
+		 CHIP_TOP_CORE_PLL_CFG_REF_CLK_SEL |
+		 CHIP_TOP_CORE_PLL_CFG_FILTER_RANGE,
+		 sparx5, CHIP_TOP_CORE_PLL_CFG);
+
+	/* Switch the PLL from its reset defaults to the register settings */
+	spx5_rmw(CHIP_TOP_CORE_PLL_CFG_ENA_CFG_SET(1),
+		 CHIP_TOP_CORE_PLL_CFG_ENA_CFG,
+		 sparx5, CHIP_TOP_CORE_PLL_CFG);
+
+	spx5_rmw(CHIP_TOP_CORE_PLL_CFG_NEWDIV_SET(1),
+		 CHIP_TOP_CORE_PLL_CFG_NEWDIV,
+		 sparx5, CHIP_TOP_CORE_PLL_CFG);
+
+	err = read_poll_timeout(spx5_rd,
+				pll_cfg,
+				CHIP_TOP_CORE_PLL_CFG_DIVACK_GET(pll_cfg),
+				100,
+				10000,
+				false,
+				sparx5,
+				CHIP_TOP_CORE_PLL_CFG);
+
+	spx5_rmw(CHIP_TOP_CORE_PLL_CFG_NEWDIV_SET(0),
+		 CHIP_TOP_CORE_PLL_CFG_NEWDIV,
+		 sparx5, CHIP_TOP_CORE_PLL_CFG);
+
+	if (err) {
+		dev_err(sparx5->dev,
+			"Failed to change the core PLL dividers\n");
+		goto err_disable;
+	}
+
+	/* LOCK_STAT resets to 1, so sleep before the first read */
+	err = read_poll_timeout(spx5_rd,
+				pll_cfg,
+				CHIP_TOP_CORE_PLL_CFG_LOCK_STAT_GET(pll_cfg),
+				100,
+				10000,
+				true,
+				sparx5,
+				CHIP_TOP_CORE_PLL_CFG);
+	if (err) {
+		dev_err(sparx5->dev, "Failed to lock the core PLL\n");
+		goto err_disable;
+	}
+
+	return 0;
+
+err_disable:
+	/* Make the next probe redo the change */
+	spx5_rmw(CHIP_TOP_CORE_PLL_CFG_ENA_CFG_SET(0),
+		 CHIP_TOP_CORE_PLL_CFG_ENA_CFG,
+		 sparx5, CHIP_TOP_CORE_PLL_CFG);
+
+	return err;
+}
+
 static int sparx5_init_coreclock(struct sparx5 *sparx5)
 {
 	enum sparx5_core_clockfreq freq = sparx5->coreclock;
 	u32 clk_div, clk_period, pol_upd_int, idx;
+	int err;
 
 	/* Verify if core clock frequency is supported on target.
 	 * If 'VTSS_CORE_CLOCK_DEFAULT' then the highest supported
@@ -573,6 +683,15 @@ static int sparx5_init_coreclock(struct sparx5 *sparx5)
 			 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_CLK_ENA,
 			 sparx5, CLKGEN_LCPLL1_CORE_CLK_CFG);
 	} else {
+		if (freq != SPX5_CORE_CLOCK_328MHZ) {
+			dev_err(sparx5->dev,
+				"%d coreclock not supported\n",
+				freq);
+			return -EINVAL;
+		}
+		err = lan969x_init_core_pll(sparx5);
+		if (err)
+			return err;
 		pol_upd_int = 820; // SPX5_CORE_CLOCK_328MHZ
 	}
 
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +7 -0
index ad29db91ce91e..f6316086e6ecb 100644
@@ -266,6 +266,12 @@ struct sparx5_port {
 	} tas_lists[SPX5_TAS_ENTRIES_PER_PORT];
 };
 
+/* lan969x core PLL reference clock, from CHIP_TOP:HW_STAT.REFCLK_SEL */
+enum sparx5_core_clockref {
+	SPX5_CORE_CLOCK_REF_25MHZ,
+	SPX5_CORE_CLOCK_REF_39MHZ,
+};
+
 enum sparx5_core_clockfreq {
 	SPX5_CORE_CLOCK_DEFAULT,  /* Defaults to the highest supported frequency */
 	SPX5_CORE_CLOCK_250MHZ,   /* 250MHZ core clock frequency */
@@ -415,6 +421,7 @@ struct sparx5 {
 	/* port structures are in net device */
 	struct sparx5_port *ports[SPX5_PORTS];
 	enum sparx5_core_clockfreq coreclock;
+	enum sparx5_core_clockref coreclockref;
 	/* Statistics */
 	u32 num_stats;
 	u32 num_ethtool_stats;
drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c +4 -1
index 9f61692b243b7..544e9513a9a53 100644
@@ -62,7 +62,10 @@ static u64 sparx5_ptp_get_nominal_value(struct sparx5 *sparx5)
 		res = 0x1FF0000000000000;
 		break;
 	case SPX5_CORE_CLOCK_328MHZ:
-		res = 0x18604697DD0F9B5B;
+		if (sparx5->coreclockref == SPX5_CORE_CLOCK_REF_25MHZ)
+			res = 0x186044FEF1EA9C10;
+		else
+			res = 0x18604697DD0F9B5B;
 		break;
 	case SPX5_CORE_CLOCK_500MHZ:
 		res = 0x0FF8000000000000;
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH net-next 3/4] net: lan969x: configure the core PLL

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 5

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] In lan969x_init_core_pll() the new DIVFI/DIVFF (FREQ_CFG, line
514) and DIVQ/DIVR/REF_CLK_SEL/FILTER_RANGE (line 523) values are…
- [Low] The commit fixes a bug that users can see on every lan969x board, but it has no Fixes: tag.
- [Low] In lan969x_init_core_pll() (drivers/net/ethernet/microchip/sparx5/sparx5_main.c, lines 506-512),…
- [Low] The patch makes a core PLL failure abort the whole switch probe on lan969x, and the commit message does not say so.
- [Low] In lan969x_init_core_pll() (lines 520-531), the comment says the CORE_PLL_CFG write will "select the reference clock from the strapping…
- [Low] The LOCK_STAT check in lan969x_init_core_pll() (lines 561-569) may pass without proving anything.

--

net: lan969x: configure the core PLL

This commit programs the lan969x core PLL to a rate about 200 ppm above 328.125 MHz. That is the rate the PTP TOD increment in sparx5_ptp_get_nominal_value() already assumes. The dividers and the TOD increment are chosen from the reference clock strapping (25 MHz or 39 MHz), and the divider change uses the NEWDIV/DIVACK handshake in CORE_PLL_CFG.

Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +0 -0
index 93a7cb89493c4..244974ffe496b 100644
@@ -474,10 +474,120 @@ static int sparx5_init_switchcore(struct sparx5 *sparx5)

[ ... ]

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +10 -0
+static int lan969x_init_core_pll(struct sparx5 *sparx5)
+{
+	const struct lan969x_core_pll_dividers *div;
+	u32 hw_stat, pll_cfg, freq_cfg;
+	enum sparx5_core_clockref ref;
+	int err;
+
+	hw_stat = spx5_rd(sparx5, CHIP_TOP_HW_STAT);
+	ref = CHIP_TOP_HW_STAT_REFCLK_SEL_GET(hw_stat) ?
+		SPX5_CORE_CLOCK_REF_39MHZ : SPX5_CORE_CLOCK_REF_25MHZ;

drivers/net/ethernet/microchip/sparx5/sparx5_main.c static int sparx5_init_switchcore(struct sparx5 *sparx5) · line 512

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +10 -0
+	div = &lan969x_core_pll_328mhz[ref];
+	sparx5->coreclockref = ref;
+
+	/* Already configured by an earlier probe? */
+	pll_cfg = spx5_rd(sparx5, CHIP_TOP_CORE_PLL_CFG);
+	freq_cfg = spx5_rd(sparx5, CHIP_TOP_CORE_PLL_FREQ_CFG);
+	if (CHIP_TOP_CORE_PLL_CFG_ENA_CFG_GET(pll_cfg) &&
+	    CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFI_GET(freq_cfg) == div->divfi &&
+	    CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFF_GET(freq_cfg) == div->divff)
+		return 0;

[Severity: Low]
Is this check strict enough to conclude that the PLL already runs at the skewed rate?

It checks only ENA_CFG, DIVFI and DIVFF. The function also programs DIVR, DIVQ, REF_CLK_SEL and FILTER_RANGE, and it depends on the NEWDIV/DIVACK handshake and on LOCK_STAT. None of those are checked before the early return.

sparx5->coreclockref is set just above. That means sparx5_ptp_get_nominal_value() always picks the skewed TOD increment for the detected reference, whether or not the PLL produces that rate.

The err_disable path clears ENA_CFG, so a completed run of this driver should not leave such a state behind. There are two other ways it could happen. A bootloader or firmware could set ENA_CFG with these DIVFI/DIVFF values but different DIVR/DIVQ/REF_CLK_SEL. Or a probe could be interrupted between the ENA_CFG=1 write and the end of the lock poll, since CHIP_TOP state persists across unbind/bind.

In either case the reprogramming and the checks are skipped without a message. Would it make sense to also compare DIVR, DIVQ and REF_CLK_SEL, and to check LOCK_STAT and that NEWDIV is clear?

Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +9 -0
+
+	spx5_rmw(CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFI_SET(div->divfi) |
+		 CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFF_SET(div->divff),
+		 CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFI |
+		 CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFF,
+		 sparx5, CHIP_TOP_CORE_PLL_FREQ_CFG);
+
+	/* Set the reference and output dividers, select the reference clock
+	 * from the strapping pin and use fractional mode.

drivers/net/ethernet/microchip/sparx5/sparx5_main.c static int sparx5_init_switchcore(struct sparx5 *sparx5) · line 531

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +10 -0
+	 */
+	spx5_rmw(CHIP_TOP_CORE_PLL_CFG_DIVQ_SET(div->divq) |
+		 CHIP_TOP_CORE_PLL_CFG_DIVR_SET(div->divr) |
+		 CHIP_TOP_CORE_PLL_CFG_REF_CLK_SEL_SET(0) |
+		 CHIP_TOP_CORE_PLL_CFG_FILTER_RANGE_SET(0),
+		 CHIP_TOP_CORE_PLL_CFG_DIVQ |
+		 CHIP_TOP_CORE_PLL_CFG_DIVR |
+		 CHIP_TOP_CORE_PLL_CFG_REF_CLK_SEL |
+		 CHIP_TOP_CORE_PLL_CFG_FILTER_RANGE,
+		 sparx5, CHIP_TOP_CORE_PLL_CFG);

[Severity: Low]
Which write here selects fractional mode?

This rmw touches only DIVQ, DIVR, REF_CLK_SEL (written as 0) and FILTER_RANGE (written as 0). In sparx5_main_regs.h, neither CHIP_TOP_CORE_PLL_CFG nor CHIP_TOP_CORE_PLL_FREQ_CFG defines a fractional mode or DSM enable field. The only extra setting is FILTER_RANGE, and the comment does not mention it.

Is the comment just inaccurate, or is a fractional enable missing? Both TOD increments in sparx5_ptp_get_nominal_value() depend on DIVFF taking effect. With only the integer part, the core clock would be about 325 MHz instead of about 328.19 MHz.

drivers/net/ethernet/microchip/sparx5/sparx5_main.c static int sparx5_init_switchcore(struct sparx5 *sparx5) · line 540

Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +9 -0
+
+	/* Switch the PLL from its reset defaults to the register settings */
+	spx5_rmw(CHIP_TOP_CORE_PLL_CFG_ENA_CFG_SET(1),
+		 CHIP_TOP_CORE_PLL_CFG_ENA_CFG,
+		 sparx5, CHIP_TOP_CORE_PLL_CFG);
+
+	spx5_rmw(CHIP_TOP_CORE_PLL_CFG_NEWDIV_SET(1),
+		 CHIP_TOP_CORE_PLL_CFG_NEWDIV,
+		 sparx5, CHIP_TOP_CORE_PLL_CFG);

[Severity: Medium]
Does the switch from reset defaults to the register settings happen at the ENA_CFG write, before the NEWDIV/DIVACK handshake starts?

If the comment above is accurate, the PLL takes the new DIVFI/DIVFF, DIVR, DIVQ and REF_CLK_SEL values at the ENA_CFG=1 write. The commit message describes the handshake as "the glitch free divider change documented for CORE_PLL_CFG", but this switch happens outside it. The handshake would then cover only what NEWDIV latches afterwards.

The core clock also changes after sparx5_init_switchcore() has already done the EACL force init, RAM init and counter reset:

mchp_sparx5_probe()

    sparx5_init_switchcore()
    sparx5_init_coreclock()
        lan969x_init_core_pll()

The reset controller is optional. A core left enabled by a bootloader could still be running while its clock source changes.

The err_disable path raises the same question in reverse. Clearing ENA_CFG there goes back to the reset defaults without a handshake, and the function returns without waiting for relock.

Could the ENA_CFG versus NEWDIV ordering be checked against the CORE_PLL_CFG datasheet?

Quoted 2 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +2 -0
+
+	err = read_poll_timeout(spx5_rd,

[ ... ]

drivers/net/ethernet/microchip/sparx5/sparx5_main.c static int sparx5_init_switchcore(struct sparx5 *sparx5) · line 569

Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +9 -0
+	/* LOCK_STAT resets to 1, so sleep before the first read */
+	err = read_poll_timeout(spx5_rd,
+				pll_cfg,
+				CHIP_TOP_CORE_PLL_CFG_LOCK_STAT_GET(pll_cfg),
+				100,
+				10000,
+				true,
+				sparx5,
+				CHIP_TOP_CORE_PLL_CFG);

[Severity: Low]
Can this poll confirm that the PLL relocked?

According to the comment, LOCK_STAT already reads 1 before the change. With sleep_us = 100 and sleep_before_read = true, poll_timeout_us() in include/linux/iopoll.h does:

	if ((sleep_before_op) && __sleep_us) \
		usleep_range((__sleep_us >> 2) + 1, __sleep_us); \

So the first read can happen only about 26 us after NEWDIV is cleared. If the DIVACK poll succeeded on its first read, which has no sleep, that is also very soon after the ENA_CFG/NEWDIV writes.

If the lock detector has not deasserted by then, the first read returns 1. The function then reports success whether or not the PLL has settled.

Is this delay based on a documented minimum lock detector response time? Could the poll instead wait for LOCK_STAT to drop and then come back?

Quoted 15 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +15 -0
+	if (err) {
+		dev_err(sparx5->dev, "Failed to lock the core PLL\n");
+		goto err_disable;
+	}
+
+	return 0;
+
+err_disable:
+	/* Make the next probe redo the change */
+	spx5_rmw(CHIP_TOP_CORE_PLL_CFG_ENA_CFG_SET(0),
+		 CHIP_TOP_CORE_PLL_CFG_ENA_CFG,
+		 sparx5, CHIP_TOP_CORE_PLL_CFG);
+
+	return err;
+}

[ ... ]

drivers/net/ethernet/microchip/sparx5/sparx5_main.c static int sparx5_init_coreclock(struct sparx5 *sparx5) · line 694

Quoted 13 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +9 -0
@@ -573,6 +683,15 @@ static int sparx5_init_coreclock(struct sparx5 *sparx5)
 			 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_CLK_ENA,
 			 sparx5, CLKGEN_LCPLL1_CORE_CLK_CFG);
 	} else {
+		if (freq != SPX5_CORE_CLOCK_328MHZ) {
+			dev_err(sparx5->dev,
+				"%d coreclock not supported\n",
+				freq);
+			return -EINVAL;
+		}
+		err = lan969x_init_core_pll(sparx5);
+		if (err)
+			return err;

[Severity: Low]
Before this patch, the lan969x branch of sparx5_init_coreclock() could not fail for a supported target. Now a DIVACK or LOCK_STAT timeout makes the whole switch probe fail:

mchp_sparx5_probe()

    sparx5_init_coreclock()
        lan969x_init_core_pll()
            read_poll_timeout() returns -ETIMEDOUT
            goto err_disable
    dev_err(sparx5->dev, "LC-PLL initialization error\n");
    goto cleanup_config;

The commit message says:

Leave the PLL alone if it is already
configured, and disable the register configuration again if the change fails.

That reads like a fallback to the default clock. In fact the PLL is reverted and the device no longer probes. A board that used to probe and forward traffic, with the 200 ppm skew, would end up with no networking.

Is the probe failure intended? If so, could the commit message say so?

Quoted 2 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +0 -0
 		pol_upd_int = 820; // SPX5_CORE_CLOCK_328MHZ
 	}

[ ... ]

Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c +0 -0
index 9f61692b243b7..544e9513a9a53 100644

drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c static u64 sparx5_ptp_get_nominal_value(struct sparx5 *sparx5) · line 69

Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c +4 -1
@@ -62,7 +62,10 @@ static u64 sparx5_ptp_get_nominal_value(struct sparx5 *sparx5)
 		res = 0x1FF0000000000000;
 		break;
 	case SPX5_CORE_CLOCK_328MHZ:
-		res = 0x18604697DD0F9B5B;
+		if (sparx5->coreclockref == SPX5_CORE_CLOCK_REF_25MHZ)
+			res = 0x186044FEF1EA9C10;
+		else
+			res = 0x18604697DD0F9B5B;
 		break;

[Severity: Low]
Should this commit have a Fixes: tag?

Commit 1ebaa5e18915 ("net: sparx5: add support for lan969x targets and core clock") added the 0x18604697DD0F9B5B increment, a period of about 3.04701 ns against the nominal 3.047619 ns. It did not program the PLL to the matching rate. As the commit message describes, TOD and the scheduler clock have run 200 ppm apart on lan969x since then.

Something like:

Fixes 1ebaa5e18915 ("net: sparx5: add support for lan969x targets and core clock")

would give stable and backport tooling a pointer. This fix also depends on two earlier patches in the series: "net: lan969x: add the core PLL registers" and "net: sparx5/lan969x: enable the switch core after clock setup". Could the commit message note that dependency, or say whether the series is meant for net-next only?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-lan969x-core-skew-v1-0-b9b02b863d38%40microchip.com
author maintainer
#5 lore raw

Re: [PATCH net-next 3/4] net: lan969x: configure the core PLL

Quoted 152 lines

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 5

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] In lan969x_init_core_pll() the new DIVFI/DIVFF (FREQ_CFG, line
514) and DIVQ/DIVR/REF_CLK_SEL/FILTER_RANGE (line 523) values are…
- [Low] The commit fixes a bug that users can see on every lan969x board, but it has no Fixes: tag.
- [Low] In lan969x_init_core_pll() (drivers/net/ethernet/microchip/sparx5/sparx5_main.c, lines 506-512),…
- [Low] The patch makes a core PLL failure abort the whole switch probe on lan969x, and the commit message does not say so.
- [Low] In lan969x_init_core_pll() (lines 520-531), the comment says the CORE_PLL_CFG write will "select the reference clock from the strapping…
- [Low] The LOCK_STAT check in lan969x_init_core_pll() (lines 561-569) may pass without proving anything.

--

net: lan969x: configure the core PLL

This commit programs the lan969x core PLL to a rate about 200 ppm above 328.125 MHz. That is the rate the PTP TOD increment in sparx5_ptp_get_nominal_value() already assumes. The dividers and the TOD increment are chosen from the reference clock strapping (25 MHz or 39 MHz), and the divider change uses the NEWDIV/DIVACK handshake in CORE_PLL_CFG.

Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +0 -0
index 93a7cb89493c4..244974ffe496b 100644
@@ -474,10 +474,120 @@ static int sparx5_init_switchcore(struct sparx5 *sparx5)

[ ... ]

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +10 -0
+static int lan969x_init_core_pll(struct sparx5 *sparx5)
+{
+	const struct lan969x_core_pll_dividers *div;
+	u32 hw_stat, pll_cfg, freq_cfg;
+	enum sparx5_core_clockref ref;
+	int err;
+
+	hw_stat = spx5_rd(sparx5, CHIP_TOP_HW_STAT);
+	ref = CHIP_TOP_HW_STAT_REFCLK_SEL_GET(hw_stat) ?
+		SPX5_CORE_CLOCK_REF_39MHZ : SPX5_CORE_CLOCK_REF_25MHZ;

drivers/net/ethernet/microchip/sparx5/sparx5_main.c static int sparx5_init_switchcore(struct sparx5 *sparx5) · line 512

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +10 -0
+	div = &lan969x_core_pll_328mhz[ref];
+	sparx5->coreclockref = ref;
+
+	/* Already configured by an earlier probe? */
+	pll_cfg = spx5_rd(sparx5, CHIP_TOP_CORE_PLL_CFG);
+	freq_cfg = spx5_rd(sparx5, CHIP_TOP_CORE_PLL_FREQ_CFG);
+	if (CHIP_TOP_CORE_PLL_CFG_ENA_CFG_GET(pll_cfg) &&
+	    CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFI_GET(freq_cfg) == div->divfi &&
+	    CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFF_GET(freq_cfg) == div->divff)
+		return 0;

[Severity: Low]
Is this check strict enough to conclude that the PLL already runs at the skewed rate?

It checks only ENA_CFG, DIVFI and DIVFF. The function also programs DIVR, DIVQ, REF_CLK_SEL and FILTER_RANGE, and it depends on the NEWDIV/DIVACK handshake and on LOCK_STAT. None of those are checked before the early return.

sparx5->coreclockref is set just above. That means sparx5_ptp_get_nominal_value() always picks the skewed TOD increment for the detected reference, whether or not the PLL produces that rate.

The err_disable path clears ENA_CFG, so a completed run of this driver should not leave such a state behind. There are two other ways it could happen. A bootloader or firmware could set ENA_CFG with these DIVFI/DIVFF values but different DIVR/DIVQ/REF_CLK_SEL. Or a probe could be interrupted between the ENA_CFG=1 write and the end of the lock poll, since CHIP_TOP state persists across unbind/bind.

In either case the reprogramming and the checks are skipped without a message. Would it make sense to also compare DIVR, DIVQ and REF_CLK_SEL, and to check LOCK_STAT and that NEWDIV is clear?

Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +9 -0
+
+	spx5_rmw(CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFI_SET(div->divfi) |
+		 CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFF_SET(div->divff),
+		 CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFI |
+		 CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFF,
+		 sparx5, CHIP_TOP_CORE_PLL_FREQ_CFG);
+
+	/* Set the reference and output dividers, select the reference clock
+	 * from the strapping pin and use fractional mode.

drivers/net/ethernet/microchip/sparx5/sparx5_main.c static int sparx5_init_switchcore(struct sparx5 *sparx5) · line 531

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +10 -0
+	 */
+	spx5_rmw(CHIP_TOP_CORE_PLL_CFG_DIVQ_SET(div->divq) |
+		 CHIP_TOP_CORE_PLL_CFG_DIVR_SET(div->divr) |
+		 CHIP_TOP_CORE_PLL_CFG_REF_CLK_SEL_SET(0) |
+		 CHIP_TOP_CORE_PLL_CFG_FILTER_RANGE_SET(0),
+		 CHIP_TOP_CORE_PLL_CFG_DIVQ |
+		 CHIP_TOP_CORE_PLL_CFG_DIVR |
+		 CHIP_TOP_CORE_PLL_CFG_REF_CLK_SEL |
+		 CHIP_TOP_CORE_PLL_CFG_FILTER_RANGE,
+		 sparx5, CHIP_TOP_CORE_PLL_CFG);

[Severity: Low]
Which write here selects fractional mode?

This rmw touches only DIVQ, DIVR, REF_CLK_SEL (written as 0) and FILTER_RANGE (written as 0). In sparx5_main_regs.h, neither CHIP_TOP_CORE_PLL_CFG nor CHIP_TOP_CORE_PLL_FREQ_CFG defines a fractional mode or DSM enable field. The only extra setting is FILTER_RANGE, and the comment does not mention it.

Is the comment just inaccurate, or is a fractional enable missing? Both TOD increments in sparx5_ptp_get_nominal_value() depend on DIVFF taking effect. With only the integer part, the core clock would be about 325 MHz instead of about 328.19 MHz.

drivers/net/ethernet/microchip/sparx5/sparx5_main.c static int sparx5_init_switchcore(struct sparx5 *sparx5) · line 540

Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +9 -0
+
+	/* Switch the PLL from its reset defaults to the register settings */
+	spx5_rmw(CHIP_TOP_CORE_PLL_CFG_ENA_CFG_SET(1),
+		 CHIP_TOP_CORE_PLL_CFG_ENA_CFG,
+		 sparx5, CHIP_TOP_CORE_PLL_CFG);
+
+	spx5_rmw(CHIP_TOP_CORE_PLL_CFG_NEWDIV_SET(1),
+		 CHIP_TOP_CORE_PLL_CFG_NEWDIV,
+		 sparx5, CHIP_TOP_CORE_PLL_CFG);

[Severity: Medium]
Does the switch from reset defaults to the register settings happen at the ENA_CFG write, before the NEWDIV/DIVACK handshake starts?

If the comment above is accurate, the PLL takes the new DIVFI/DIVFF, DIVR, DIVQ and REF_CLK_SEL values at the ENA_CFG=1 write. The commit message describes the handshake as "the glitch free divider change documented for CORE_PLL_CFG", but this switch happens outside it. The handshake would then cover only what NEWDIV latches afterwards.

The core clock also changes after sparx5_init_switchcore() has already done the EACL force init, RAM init and counter reset:

mchp_sparx5_probe()

    sparx5_init_switchcore()
    sparx5_init_coreclock()
        lan969x_init_core_pll()

The reset controller is optional. A core left enabled by a bootloader could still be running while its clock source changes.

Quoted 6 lines

The err_disable path raises the same question in reverse. Clearing ENA_CFG there goes back to the reset defaults without a handshake, and the function returns without waiting for relock.

Could the ENA_CFG versus NEWDIV ordering be checked against the CORE_PLL_CFG datasheet?

This is the frequency change procedure described in the datasheet for CORE_PLL_CFG, and the patch follows it step by step.

On the first probe the switch comes out of reset with the queue system disabled, and patch 2/4 keeps it that way until the core clock is set up. On a rebind the PLL is already configured and is left alone.

The err_disable path only runs if the PLL never acknowledges the change or never locks. Probe then fails, and the next probe redoes the change and waits for lock. Waiting for relock on the error path would not buy anything.

Quoted 134 lines
Quoted 3 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +2 -0
+
+	err = read_poll_timeout(spx5_rd,

[ ... ]

drivers/net/ethernet/microchip/sparx5/sparx5_main.c static int sparx5_init_switchcore(struct sparx5 *sparx5) · line 569

Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +9 -0
+	/* LOCK_STAT resets to 1, so sleep before the first read */
+	err = read_poll_timeout(spx5_rd,
+				pll_cfg,
+				CHIP_TOP_CORE_PLL_CFG_LOCK_STAT_GET(pll_cfg),
+				100,
+				10000,
+				true,
+				sparx5,
+				CHIP_TOP_CORE_PLL_CFG);

[Severity: Low]
Can this poll confirm that the PLL relocked?

According to the comment, LOCK_STAT already reads 1 before the change. With sleep_us = 100 and sleep_before_read = true, poll_timeout_us() in include/linux/iopoll.h does:

	if ((sleep_before_op) && __sleep_us) \
		usleep_range((__sleep_us >> 2) + 1, __sleep_us); \

So the first read can happen only about 26 us after NEWDIV is cleared. If the DIVACK poll succeeded on its first read, which has no sleep, that is also very soon after the ENA_CFG/NEWDIV writes.

If the lock detector has not deasserted by then, the first read returns 1. The function then reports success whether or not the PLL has settled.

Is this delay based on a documented minimum lock detector response time? Could the poll instead wait for LOCK_STAT to drop and then come back?

Quoted 15 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +15 -0
+	if (err) {
+		dev_err(sparx5->dev, "Failed to lock the core PLL\n");
+		goto err_disable;
+	}
+
+	return 0;
+
+err_disable:
+	/* Make the next probe redo the change */
+	spx5_rmw(CHIP_TOP_CORE_PLL_CFG_ENA_CFG_SET(0),
+		 CHIP_TOP_CORE_PLL_CFG_ENA_CFG,
+		 sparx5, CHIP_TOP_CORE_PLL_CFG);
+
+	return err;
+}

[ ... ]

drivers/net/ethernet/microchip/sparx5/sparx5_main.c static int sparx5_init_coreclock(struct sparx5 *sparx5) · line 694

Quoted 13 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +9 -0
@@ -573,6 +683,15 @@ static int sparx5_init_coreclock(struct sparx5 *sparx5)
 			 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_CLK_ENA,
 			 sparx5, CLKGEN_LCPLL1_CORE_CLK_CFG);
 	} else {
+		if (freq != SPX5_CORE_CLOCK_328MHZ) {
+			dev_err(sparx5->dev,
+				"%d coreclock not supported\n",
+				freq);
+			return -EINVAL;
+		}
+		err = lan969x_init_core_pll(sparx5);
+		if (err)
+			return err;

[Severity: Low]
Before this patch, the lan969x branch of sparx5_init_coreclock() could not fail for a supported target. Now a DIVACK or LOCK_STAT timeout makes the whole switch probe fail:

mchp_sparx5_probe()

    sparx5_init_coreclock()
        lan969x_init_core_pll()
            read_poll_timeout() returns -ETIMEDOUT
            goto err_disable
    dev_err(sparx5->dev, "LC-PLL initialization error\n");
    goto cleanup_config;

The commit message says:

Leave the PLL alone if it is already
configured, and disable the register configuration again if the change fails.

That reads like a fallback to the default clock. In fact the PLL is reverted and the device no longer probes. A board that used to probe and forward traffic, with the 200 ppm skew, would end up with no networking.

Is the probe failure intended? If so, could the commit message say so?

Quoted 2 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +0 -0
 		pol_upd_int = 820; // SPX5_CORE_CLOCK_328MHZ
 	}

[ ... ]

Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c +0 -0
index 9f61692b243b7..544e9513a9a53 100644

drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c static u64 sparx5_ptp_get_nominal_value(struct sparx5 *sparx5) · line 69

Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c +4 -1
@@ -62,7 +62,10 @@ static u64 sparx5_ptp_get_nominal_value(struct sparx5 *sparx5)
 		res = 0x1FF0000000000000;
 		break;
 	case SPX5_CORE_CLOCK_328MHZ:
-		res = 0x18604697DD0F9B5B;
+		if (sparx5->coreclockref == SPX5_CORE_CLOCK_REF_25MHZ)
+			res = 0x186044FEF1EA9C10;
+		else
+			res = 0x18604697DD0F9B5B;
 		break;

[Severity: Low]
Should this commit have a Fixes: tag?

Commit 1ebaa5e18915 ("net: sparx5: add support for lan969x targets and core clock") added the 0x18604697DD0F9B5B increment, a period of about 3.04701 ns against the nominal 3.047619 ns. It did not program the PLL to the matching rate. As the commit message describes, TOD and the scheduler clock have run 200 ppm apart on lan969x since then.

Something like:

Fixes 1ebaa5e18915 ("net: sparx5: add support for lan969x targets and core clock")

would give stable and backport tooling a pointer. This fix also depends on two earlier patches in the series: "net: lan969x: add the core PLL registers" and "net: sparx5/lan969x: enable the switch core after clock setup". Could the commit message note that dependency, or say whether the series is meant for net-next only?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-lan969x-core-skew-v1-0-b9b02b863d38%40microchip.com
author maintainer
#6 lore raw

PATCH 4/4 net: sparx5/lan969x: scale the nominal TOD increment in adjfine

In reply to Daniel Machon

sparx5_ptp_adjfine() builds the new TOD increment from two tables: the nominal increment from sparx5_ptp_get_nominal_value(), and a one ppm step from sparx5_ptp_get_1ppm(), which it multiplies by the requested ppm. Nothing ties the two tables together, so they can get out of step.

They already are for the lan969x 328 MHz core clock: the nominal increment is derived from the skewed rate, the one ppm step from the 328.125 MHz default. A 1 ppm request therefore moves the increment by 1.0002 ppm.

Drop sparx5_ptp_get_1ppm() and scale the nominal increment directly with adjust_by_scaled_ppm(). The sparx5 core clocks are unchanged, as their two tables agree.

---
 drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c | 49 +---------------------
 1 file changed, 2 insertions(+), 47 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c +2 -47
index 544e9513a9a53..e37635e8fd730 100644
@@ -22,37 +22,6 @@ enum {
 	PTP_PIN_ACTION_TOD
 };
 
-static u64 sparx5_ptp_get_1ppm(struct sparx5 *sparx5)
-{
-	/* Represents 1ppm adjustment in 2^59 format with 1.59687500000(625)
-	 * 1.99609375000(500), 3.99218750000(250) as reference
-	 * The value is calculated as following:
-	 * (1/1000000)/((2^-59)/X)
-	 */
-
-	u64 res = 0;
-
-	switch (sparx5->coreclock) {
-	case SPX5_CORE_CLOCK_250MHZ:
-		res = 2301339409586;
-		break;
-	case SPX5_CORE_CLOCK_328MHZ:
-		res = 1756832768924;
-		break;
-	case SPX5_CORE_CLOCK_500MHZ:
-		res = 1150669704793;
-		break;
-	case SPX5_CORE_CLOCK_625MHZ:
-		res =  920535763834;
-		break;
-	default:
-		WARN(1, "Invalid core clock");
-		break;
-	}
-
-	return res;
-}
-
 static u64 sparx5_ptp_get_nominal_value(struct sparx5 *sparx5)
 {
 	u64 res = 0;
@@ -407,27 +376,13 @@ static int sparx5_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
 	struct sparx5_phc *phc = container_of(ptp, struct sparx5_phc, info);
 	struct sparx5 *sparx5 = phc->sparx5;
 	unsigned long flags;
-	bool neg_adj = 0;
 	u64 tod_inc;
-	u64 ref;
 
 	if (!scaled_ppm)
 		return 0;
 
-	if (scaled_ppm < 0) {
-		neg_adj = 1;
-		scaled_ppm = -scaled_ppm;
-	}
-
-	tod_inc = sparx5_ptp_get_nominal_value(sparx5);
-
-	/* The multiplication is split in 2 separate additions because of
-	 * overflow issues. If scaled_ppm with 16bit fractional part was bigger
-	 * than 20ppm then we got overflow.
-	 */
-	ref = sparx5_ptp_get_1ppm(sparx5) * (scaled_ppm >> 16);
-	ref += (sparx5_ptp_get_1ppm(sparx5) * (0xffff & scaled_ppm)) >> 16;
-	tod_inc = neg_adj ? tod_inc - ref : tod_inc + ref;
+	tod_inc = adjust_by_scaled_ppm(sparx5_ptp_get_nominal_value(sparx5),
+				       scaled_ppm);
 
 	spin_lock_irqsave(&sparx5->ptp_clock_lock, flags);
 
Signature · 1 line
2.34.1
#7 lore raw
In reply to Daniel Machon
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Fri, 13 Nov 2026 11:19:39 +0100 you wrote:

At its 328.125 MHz default, the lan969x core clock is too close to the line clock frequencies for the high accuracy phase detectors to work as intended, which degrades PTP accuracy. The core clock should therefore be skewed about 200 ppm up. The PTP time of day (TOD) increment is already set up for the skewed rate, but the driver leaves the core PLL at its default, so the TOD and the clock that drives the scheduler run 200 ppm apart.

[...]

Here is the summary with links:
- [net-next,1/4] net: lan969x: add the core PLL registers

    https://git.kernel.org/netdev/net-next/c/5f8d69a43e72
  - [net-next,2/4] net: sparx5/lan969x: enable the switch core after clock setup
    https://git.kernel.org/netdev/net-next/c/ae590854818f
  - [net-next,3/4] net: lan969x: configure the core PLL
    https://git.kernel.org/netdev/net-next/c/39d5dff49d71
  - [net-next,4/4] net: sparx5/lan969x: scale the nominal TOD increment in adjfine
    https://git.kernel.org/netdev/net-next/c/7e8651f87504

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html