Skip to contentSkip to conversation

ptp: ocp: add TAP CPLD support for ADVA TimeCard X1

PATCH Applied Sagi Maimon 4 participants 11 messages Sep 16 – Sep 22

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v15 cover ptp: ocp: add TAP CPLD support for ADVA TimeCard X1

The ADVA TimeCard X1 (PCI device 0x0410) carries a Lattice MachXO3 CPLD on the TMC I2C bus. This series adds access to it and an update path through devlink flash.

The card has two I2C controllers. Linux registers only the one at 0x00150000, normally routed to the config EEPROMs; the one at 0x00120000 belongs to the on-card MicroBlaze and is routed to the TMC or M.2 bus as its firmware selects. A request/grant handshake re-routes the host controller onto the TMC bus, where the PCA9548 and the CPLD behind its channel 0 live. Everything here is built on that handshake.

Patches 1 and 2 are pre-existing probe-error-path bugs that were buried in the feature commit in v13; they are split out with Fixes: tags. Patch 1 is also a prerequisite: patch 3 adds a mutex that ptp_ocp_detach() destroys, so devlink has to be unregistered first. Patch 3 adds the bus arbitration and the read-only interfaces, patch 4 the flashing.

v14: https://lore.kernel.org/netdev/[email protected]/T/#u

Changes since v14 - all from the automated review of v14:

- The hand-back never waited. MBLAZE_GRANTED contains the host's own request bits, which the release write clears first, so the poll could not iterate and the adapter was unlocked while the controller was still on the TMC bus. It now tests the firmware-owned grant field. Measured on the card: the register reads 0x00000012 once the segment is handed back, ~670 ms after the release write - so the wait is real and a "read 0" test would never have exited. Patch 3.
- adva_x1_mblaze_release() and adva_x1_bus_release() return the failure instead of only logging it, so an operation over a bus that may still be mis-routed fails rather than reporting success. The adapter is still unlocked, since holding the root lock would stall every other user with no way out. Patch 3.
- fw.cpld is reported for every board that has the part, not only once its USERCODE has been read. devlink resolves the component name from ->info_get(), so gating it on the cached identity made a part holding a bad image - which answers neither read - impossible to reflash. The value is "unknown" until the read succeeds. Patch 4.
- The cached identity is dropped right after ERASE completes rather than only after every later check passed, so a failure part-way through no longer leaves the pre-flash cpld.id and fw.cpld published. Patch 4.
- The one-shot ID bookkeeping moved inside adva_x1_cpld_read_id(), under cpld_lock, where a flash that resets it cannot have it overwritten by the worker afterwards. Patch 3.
- A failing USERCODE read no longer discards the device ID that was just read, and the value/validity pair is published with smp_store_release()/smp_load_acquire() rather than bare WRITE_ONCE(). Patch 4.
- The flash now confirms the part actually entered configuration mode (status ENAB) after EN_CFG_TP. An enable frame that does not latch leaves an idle part reporting neither BUSY nor FAILED, the erase and page writes are ignored and DONE is still set from the old image, so every later check passed and the update was reported successful with the flash untouched. Patch 4.
- adva_x1_cpld_exit_config() gates the flag on the wait it was already doing and retries, instead of recording an exit that may not have happened; the flash also retries the exit on entry, so a part left latched by an earlier failure is recovered. Patch 4.
- An upper bound on the image and a fatal-signal check in the page loop:
both cpld_lock and the i2c root lock are held for the whole image, so the duration was caller-chosen and uninterruptible. Patch 4.
- cpld_i2c_adap_nr is serialised against the i2c bus notifier, and the lookup runs from the worker rather than once from probe: device_add() notifies before linking the device to its parent, so with asynchronous probing both writers could miss the same adapter. A number that fails the parent check in adva_x1_bus_claim() is now forgotten so the lookup runs again. Patch 3.
- A mux channel select reported as failed may still have been ACKed, so the deselect runs on that path too rather than handing the mux back with a channel possibly open; a failed deselect is no longer silently dropped. Patches 3 and 4.
- The CPLD component reports a terminal "Flash complete"/"Flash error" status like the SPI path, and the pre-refresh DONE check logs and sets extack like the post-refresh one. Patch 4.
- linux/iopoll.h and linux/firmware.h moved to patch 4, where their first users are. Comments no longer describe an upload path that only exists in the later patch, and the documentation no longer claims .jed containers are rejected - only the page-multiple length is checked.
- Documentation no longer says the identification read happens once: a successful update re-arms it.

Tested on an ADVA TimeCard X1: a full erase/program/refresh cycle of a 6526-page image through "devlink dev flash ... component fw.cpld", cpld_status reading done afterwards and across a reboot, and the rejection paths for a .jed image and an unknown component name.

Sagi Maimon (4):
ptp: ocp: unregister devlink before detach on probe error
ptp: ocp: fix dpll cleanup on probe error
ptp: ocp: add TAP CPLD access for ADVA TimeCard X1
ptp: ocp: add TAP CPLD flashing via devlink

 Documentation/ABI/testing/sysfs-timecard     |  29 +
 Documentation/networking/devlink/index.rst   |   1 +
 Documentation/networking/devlink/ptp_ocp.rst |  75 ++
 MAINTAINERS                                  |   1 +
 drivers/ptp/ptp_ocp.c                        | 939 ++++++++++++++++++-
 5 files changed, 1039 insertions(+), 6 deletions(-)
 create mode 100644 Documentation/networking/devlink/ptp_ocp.rst

base-commit: 87b80c2f6b05cad9f0ff9136709c62a0f59923e3

Signature · 1 line
2.47.0
#1 lore raw

PATCH v15 1/4 ptp: ocp: unregister devlink before detach on probe error

From: Sagi Maimon <[email protected]>

devlink_register() runs before the dpll setup in ptp_ocp_probe(), but the failure paths after it went straight to ptp_ocp_detach() and then devlink_free(), which opens with ASSERT_DEVLINK_NOT_REGISTERED(devlink). Any dpll failure during probe therefore freed a devlink instance that was still registered.

Route those paths through a new out_devlink label that unregisters first, matching the order ptp_ocp_remove() already uses.

Fixes 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
---
 drivers/ptp/ptp_ocp.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/ptp/ptp_ocp.c +4 -2
index 3d26ec1f7b9e..401b04f12d2b 100644
@@ -5119,12 +5119,12 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (IS_ERR(bp->dpll)) {
 		err = PTR_ERR(bp->dpll);
 		dev_err(&pdev->dev, "dpll_device_alloc failed\n");
-		goto out;
+		goto out_devlink;
 	}
 
 	err = dpll_device_register(bp->dpll, DPLL_TYPE_PPS, &dpll_ops, bp);
 	if (err)
-		goto out;
+		goto out_devlink;
 
 	for (i = 0; i < OCP_SMA_NUM; i++) {
 		bp->sma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE,
@@ -5151,6 +5151,8 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		dpll_pin_put(bp->sma[i].dpll_pin, &bp->sma[i].tracker);
 	}
 	dpll_device_put(bp->dpll, &bp->tracker);
+out_devlink:
+	devlink_unregister(devlink);
 out:
 	ptp_ocp_detach(bp);
 out_disable:
Signature · 1 line
2.47.0
#2 lore raw

PATCH v15 2/4 ptp: ocp: fix dpll cleanup on probe error

In reply to Sagi Maimon

From: Sagi Maimon <[email protected]>

Two problems on the dpll error paths in ptp_ocp_probe().

dpll_device_register() takes a second reference and stores bp as the registration private data, and only dpll_device_unregister() drops it. out_dpll dropped bp->tracker but never unregistered, so a dpll_pin_get() or dpll_pin_register() failure left the device registered and visible to userspace with a priv pointer into the storage devlink_free() releases a few lines later, as well as leaking the registration object.

A failing dpll_device_register() jumped to the same label as the failing dpll_device_get(), so the reference taken by dpll_device_get() was never dropped either. Give that case its own label.

Fixes 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
---
 drivers/ptp/ptp_ocp.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/ptp/ptp_ocp.c +7 -1
index 401b04f12d2b..f4299878c27c 100644
@@ -5124,7 +5124,7 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	err = dpll_device_register(bp->dpll, DPLL_TYPE_PPS, &dpll_ops, bp);
 	if (err)
-		goto out_devlink;
+		goto out_dpll_put;
 
 	for (i = 0; i < OCP_SMA_NUM; i++) {
 		bp->sma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE,
@@ -5150,6 +5150,12 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]);
 		dpll_pin_put(bp->sma[i].dpll_pin, &bp->sma[i].tracker);
 	}
+	/* dpll_device_register() takes a second reference and stores bp; only
+	 * dpll_device_unregister() drops it.  Without this the device stays
+	 * visible with a priv pointer into storage devlink_free() will release.
+	 */
+	dpll_device_unregister(bp->dpll, &dpll_ops, bp);
+out_dpll_put:
 	dpll_device_put(bp->dpll, &bp->tracker);
 out_devlink:
 	devlink_unregister(devlink);
Signature · 1 line
2.47.0
#3 lore raw

PATCH v15 3/4 ptp: ocp: add TAP CPLD access for ADVA TimeCard X1

In reply to Sagi Maimon

From: Sagi Maimon <[email protected]>

The ADVA TimeCard X1 carries a Lattice MachXO3 CPLD on its TMC I2C bus. Reaching it means taking that bus from the on-card MicroBlaze first.

The card has two I2C controllers. Linux registers only the one at 0x00150000, normally routed to the config EEPROMs; the one at 0x00120000 belongs to the MicroBlaze and is routed to the TMC or M.2 bus as its firmware selects. A request/grant handshake re-routes the host controller onto the TMC bus, where the PCA9548 and the CPLD behind its channel 0 live. An operation takes the i2c core adapter lock for the whole grant window and uses __i2c_transfer() internally; without that, a concurrent transfer from ptp_ocp_read_eeprom(), from the nvmem attributes or from the at24 sysfs files would be issued onto the TMC bus instead of to the EEPROM. The hand-back waits for the firmware to drop the grant before the adapter lock is released, for the same reason.

On top of the arbitration this adds two read-only interfaces: a root-only cpld_status attribute reporting the flags in the CPLD status register, and the Lattice device ID as the fixed devlink version cpld.id. Reading the ID claims the bus, so it must not sit on DEVLINK_CMD_INFO_GET, which carries no GENL_ADMIN_PERM; the driver reads it once from its own worker, as soon as the i2c adapter has registered, and info_get() reports the cached value.

---
 Documentation/ABI/testing/sysfs-timecard     |  24 +
 Documentation/networking/devlink/index.rst   |   1 +
 Documentation/networking/devlink/ptp_ocp.rst |  35 ++
 MAINTAINERS                                  |   1 +
 drivers/ptp/ptp_ocp.c                        | 514 ++++++++++++++++++-
 5 files changed, 571 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/networking/devlink/ptp_ocp.rst
Documentation/ABI/testing/sysfs-timecard +24 -0
index 3ae41b7634ac..e58824e0cdcd 100644
@@ -11,6 +11,30 @@ Contact:	Jonathan Lemon <[email protected]>
 Description:	This directory contains the attributes of the Nth timecard
 		registered.
 
+What:		/sys/class/timecard/ocpN/cpld_status
+Date:		July 2026
+Contact:	Sagi Maimon <[email protected]>
+Description:	(RO, root only) The flags set in the status register of the
+		TAP CPLD, space separated, or an empty line when none is
+		set.  Only present on ADVA x1 TAP boards (PCI ID
+		0xad5a:0x0410).
+
+		==========  ================================================
+		done        the configuration flash holds a valid image and
+			    it is active
+		busy        an internal operation is in progress
+		failed      the last ISC operation failed
+		==========  ================================================
+
+		For example "busy" while an operation runs, or "busy failed"
+		if a failure is latched while another one is in progress.
+
+		A read arbitrates for the shared I2C bus and reprograms the
+		on-card mux, so it is restricted to root.  The Lattice device
+		ID of the CPLD is read once by the driver, shortly after
+		probe, and reported from that cached value as the fixed
+		"cpld.id" version by devlink dev info.
+
 What:		/sys/class/timecard/ocpN/available_clock_sources
 Date:		September 2021
 Contact:	Jonathan Lemon <[email protected]>
Documentation/networking/devlink/index.rst +1 -0
index d4a83fdcff7f..1af780c811ee 100644
@@ -99,6 +99,7 @@ parameters, info versions, and other features it supports.
    nfp
    octeontx2
    prestera
+   ptp_ocp
    qed
    sfc
    stmmac
Documentation/networking/devlink/ptp_ocp.rst new file +35 -0
new file mode 100644
index 000000000000..3f997cd9f3a3
@@ -0,0 +1,35 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+========================
+ptp_ocp devlink support
+========================
+
+This document describes the devlink features implemented by the ``ptp_ocp``
+device driver.
+
+Info versions
+=============
+
+The ``ptp_ocp`` driver reports the following versions
+
+.. list-table:: devlink info versions implemented
+   :widths: 5 5 90
+
+   * - Name
+     - Type
+     - Description
+   * - ``fw``
+     - running
+     - Version of the firmware running on the card.  Reported as ``loader``
+       instead when the card is running the firmware loader.
+   * - ``board.id``
+     - fixed
+     - Board identifier, read from the on-card EEPROM.
+   * - ``cpld.id``
+     - fixed
+     - Lattice device ID (IDCODE) of the TAP CPLD, formatted as ``0x%08x``.
+       Only present on ADVA TimeCard X1 boards, which are the only ones
+       carrying that CPLD.  Reading it claims the shared I2C bus and
+       reprograms the on-card mux, so the driver does that once from its
+       own worker and reports the cached value here; the version is
+       omitted until that read has succeeded.
MAINTAINERS +1 -0
index 0e04d92d1b09..113f31434617 100644
@@ -20479,6 +20479,7 @@ OPENCOMPUTE PTP CLOCK DRIVER
 M:	Vadim Fedorenko <[email protected]>
 L:	[email protected]
 S:	Maintained
+F:	Documentation/networking/devlink/ptp_ocp.rst
 F:	drivers/ptp/ptp_ocp.c
 
 OPENCORES I2C BUS DRIVER
drivers/ptp/ptp_ocp.c +510 -4

612 lines not on this page · raw message

Signature · 1 line
2.47.0
#4 lore raw

Re: [PATCH net-next v15 3/4] ptp: ocp: add TAP CPLD access for ADVA TimeCard X1

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

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

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

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).

- [High] adva_x1_bus_release() drops the i2c root-adapter lock and forgets the claim even when adva_x1_mblaze_release() returned…
- [Medium] The one-shot CPLD ID read is executed from ptp_ocp_sync_work(), the driver's 1 Hz in-sync status poller.
- [Low] On an acquire timeout the MicroBlaze hand-back handshake is executed twice: adva_x1_mblaze_acquire() already writes MBLAZE_RELEASE…
- [Low] adva_x1_bus_claim() returns -ENODEV when i2c_get_adapter() finds nothing for the cached number, without clearing bp->cpld_i2c_adap_nr.
- [Low] The new struct ptp_ocp member comments overstate the locking:
cpld_i2c_adap_nr is documented as 'Under cpld_adap_lock' and…

--

ptp: ocp: add TAP CPLD access for ADVA TimeCard X1

This adds a request/grant handshake that re-routes the registered x1 I2C controller from the config EEPROMs onto the TMC bus, so the PCA9548 and the Lattice CPLD behind its channel 0 can be reached. On top of that it adds a root-only cpld_status attribute and reports the Lattice device ID as the fixed devlink version cpld.id, read once from the driver's sync worker.

A few questions about the new arbitration and its bookkeeping below.

Quoted 4 lines
drivers/ptp/ptp_ocp.c +0 -0
index f4299878c27ce..998ea9c6b3817 100644

[ ... ]

drivers/ptp/ptp_ocp.c struct ptp_ocp { · line 430

Quoted 11 lines
drivers/ptp/ptp_ocp.c +7 -0
@@ -416,6 +421,25 @@ struct ptp_ocp {
 	dpll_tracker tracker;
 	int signals_nr;
 	int freq_in_nr;
+	/* adva_x1 CPLD I2C (internal use only) */
+	/* serialises CPLD operations */
+	struct mutex		cpld_lock;
+	/* guards cpld_i2c_adap_nr against the bus notifier */
+	spinlock_t		cpld_adap_lock;
+	/* I2C adapter nr; -1 if absent.  Under cpld_adap_lock */
+	int			cpld_i2c_adap_nr;

[Severity: Low]
This isn't a bug, but do these member comments match the code? The field is documented as "Under cpld_adap_lock", yet all three readers take no lock:

	adva_x1_cache_i2c_adap()
		if (!bp->has_cpld || !bp->i2c_ctrl ||
		    READ_ONCE(bp->cpld_i2c_adap_nr) >= 0)

	adva_x1_bus_claim()
		adap = i2c_get_adapter(READ_ONCE(bp->cpld_i2c_adap_nr));

	ptp_ocp_sync_work()
		if (bp->has_cpld && !READ_ONCE(bp->cpld_id_tried) &&
		    READ_ONCE(bp->cpld_i2c_adap_nr) >= 0)

The same applies to cpld_id_tried, documented as "under cpld_lock" and read lockless in ptp_ocp_sync_work(). Would it be clearer to describe the actual design, that writes are serialised while readers may observe a stale value and re-validate it on the parent check?

Quoted 13 lines
drivers/ptp/ptp_ocp.c +12 -0
+	/* claimed adapter; valid under cpld_lock */
+	struct i2c_adapter	*cpld_adap;
+	/* scratch, write half then read half; valid under cpld_lock */
+	u8			*cpld_buf;
+	/* Lattice device ID; 0 if unread */
+	u32			cpld_id;
+	/* one-shot ID read finished, successfully or not; under cpld_lock */
+	bool			cpld_id_tried;
+	/* failed ID read attempts so far; under cpld_lock */
+	unsigned int		cpld_id_attempts;
+	/* x1 TAP CPLD present */
+	bool			has_cpld;
 };

[ ... ]

Quoted 1 line
drivers/ptp/ptp_ocp.c +0 -0
@@ -4226,6 +4266,434 @@ static const struct ocp_attr_group art_timecard_groups[] = {

[ ... ]

Quoted 53 lines
drivers/ptp/ptp_ocp.c +53 -0
+/* Hand the segment back, and wait for the firmware to drop the grant before
+ * the caller unlocks the adapter: a transfer queued behind us would
+ * otherwise be clocked out while the controller is still on the TMC bus,
+ * which is what holding the adapter lock across the grant exists to stop.
+ */
+static int adva_x1_mblaze_release(struct ptp_ocp *bp)
+{
+	u32 val = 0;
+	int i;
+
+	if (!bp->pps_select)
+		return 0;
+
+	iowrite32(MBLAZE_RELEASE, &bp->pps_select->i2c_bus_ctrl);
+	/* Flush the posted write, as the acquire path does. */
+	ioread32(&bp->pps_select->i2c_bus_ctrl);
+
+	for (i = 0; i < MBLAZE_RETRIES; i++) {
+		val = ioread32(&bp->pps_select->i2c_bus_ctrl);
+		if ((val & MBLAZE_GRANT_MASK) != MBLAZE_GRANT)
+			return 0;
+		usleep_range(MBLAZE_RETRY_US, MBLAZE_RETRY_US + 1000);
+	}
+
+	dev_err(&bp->pdev->dev,
+		"TMC bus still granted after release, i2c_bus_ctrl 0x%08x\n",
+		val);
+
+	return -ETIMEDOUT;
+}
+
+/* Acquire the shared I2C bus from the MicroBlaze firmware.  Returns with no
+ * request outstanding on failure, so the firmware is never left granting a
+ * segment to a host that has given up waiting for it.
+ */
+static int adva_x1_mblaze_acquire(struct ptp_ocp *bp)
+{
+	u32 val;
+	int i;
+
+	if (!bp->pps_select)
+		return -ENODEV;
+
+	/* Drop a request left by a caller that died mid-sequence; cpld_lock
+	 * keeps live ones out.  The read back only flushes the posted write.
+	 */
+	iowrite32(0, &bp->pps_select->i2c_bus_ctrl);
+	ioread32(&bp->pps_select->i2c_bus_ctrl);
+
+	iowrite32(MBLAZE_REQUEST, &bp->pps_select->i2c_bus_ctrl);
+	for (i = 0; i < MBLAZE_RETRIES; i++) {
+		usleep_range(MBLAZE_RETRY_US, MBLAZE_RETRY_US + 1000);
+		val = ioread32(&bp->pps_select->i2c_bus_ctrl);

drivers/ptp/ptp_ocp.c static const struct ocp_attr_group art_timecard_groups[] = { · line 4442

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+		if (val == MBLAZE_GRANTED)
+			return 0;
+	}
+
+	/* Drop the request we gave up on.  Any error from the hand-back is
+	 * subsumed by the -ETIMEDOUT we are already returning.
+	 */
+	adva_x1_mblaze_release(bp);
+	return -ETIMEDOUT;
+}

[Severity: Low]
Is the hand-back run twice for a single failed acquire? This path already writes MBLAZE_RELEASE and runs the full poll loop, and then adva_x1_bus_claim() calls it again for the same error:

	ret = adva_x1_mblaze_acquire(bp);
	if (ret)
		adva_x1_bus_release(bp);	/* keeps the acquire error */

Both run with the i2c root-adapter lock held, and each loop is MBLAZE_RETRIES x MBLAZE_RETRY_US, so when the firmware keeps the grant asserted a single failed claim can hold the shared adapter lock for roughly half again as long and log "TMC bus still granted after release" twice. Is one of the two hand-backs superfluous?

Quoted 17 lines
drivers/ptp/ptp_ocp.c +17 -0
+
+/* Route the host controller back to the EEPROMs and release the adapter.
+ * Safe after a failed claim: it also clears a request that was never granted.
+ *
+ * The adapter is unlocked even when the hand-back timed out: keeping the
+ * root lock would stall every other user of the controller for good, with
+ * no way to recover it.  The error is returned instead, so the operation
+ * that held the claim fails rather than reporting success over a bus that
+ * may still be routed to the TMC segment.
+ */
+static int adva_x1_bus_release(struct ptp_ocp *bp)
+{
+	struct i2c_adapter *adap = bp->cpld_adap;
+	int err;
+
+	if (!adap)
+		return 0;

drivers/ptp/ptp_ocp.c static const struct ocp_attr_group art_timecard_groups[] = { · line 4469

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+
+	err = adva_x1_mblaze_release(bp);
+	bp->cpld_adap = NULL;
+	kfree(bp->cpld_buf);
+	bp->cpld_buf = NULL;
+	i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER);
+	i2c_put_adapter(adap);
+
+	return err;
+}

[Severity: High]
Can this leave the shared controller routed to the TMC segment with nothing holding later users off it?

When adva_x1_mblaze_release() returns -ETIMEDOUT the grant field still reads MBLAZE_GRANT, so the firmware has not taken the segment back. This function nevertheless drops the claim and unlocks unconditionally. For a plain (non-mux) adapter both lock levels are the same rt_mutex:

drivers/i2c/i2c-core-base.c

	static void i2c_adapter_unlock_bus(struct i2c_adapter *adapter,
					   unsigned int flags)
	{
		rt_mutex_unlock(&adapter->bus_lock);
	}

so every waiter resumes immediately, and only the errno reaches the CPLD operation that held the claim. Nothing latches the "routing unknown" state, re-drives the hand-back, or gates the next transfer.

The commit message says a transfer issued in that window "would be issued onto the TMC bus instead of to the EEPROM". ptp_ocp_read_eeprom() then caches whatever came back with no validation:

		ret = nvmem_device_read(nvmem, map->off, map->len,
					BP_MAP_ENTRY_ADDR(bp, map));
		if (ret != map->len)
			goto fail;
	}

	bp->has_eeprom_data = true;

and that becomes bp->serial / bp->board_id, republished over the unprivileged DEVLINK_CMD_INFO_GET path. An nvmem or at24 write in the same window would be delivered to whatever answers 0x50/0x58 on the TMC bus.

The comment argues that keeping the lock forever is worse, which is fair, but should a sticky flag (or a retried hand-back) fence later transfers until the grant is confirmed dropped, instead of only returning the errno to the CPLD caller?

[ ... ]

Quoted 5 lines
drivers/ptp/ptp_ocp.c +5 -0
+/*
+ * Claim the TMC bus.  The adapter lock is held across the handshake to keep
+ * the EEPROM, nvmem and at24 paths off the controller while it is routed
+ * away from the EEPROMs; an EEPROM read blocks until the claim is dropped.
+ */

drivers/ptp/ptp_ocp.c static const struct ocp_attr_group art_timecard_groups[] = { · line 4528

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+static int adva_x1_bus_claim(struct ptp_ocp *bp)
+{
+	struct i2c_adapter *adap;
+	int ret;
+
+	lockdep_assert_held(&bp->cpld_lock);
+
+	adap = i2c_get_adapter(READ_ONCE(bp->cpld_i2c_adap_nr));
+	if (!adap)
+		return -ENODEV;

[Severity: Low]
Should this path also forget the cached number? When the lookup fails, bp->cpld_i2c_adap_nr stays >= 0, so adva_x1_cache_i2c_adap() bails out at its first test and never re-resolves the adapter, while every ptp_ocp_sync_work() tick burns one retry until cpld_id_tried is set for good in adva_x1_cpld_read_id():

	if (!ret || ++bp->cpld_id_attempts >= CPLD_ID_MAX_ATTEMPTS)
		bp->cpld_id_tried = true;

A stale number can be published in the first place because adva_x1_cache_i2c_adap() only re-tests cpld_i2c_adap_nr < 0 after device_find_child() has returned, so a delete notification for that adapter in the same window still ends up cached.

And a re-added adapter updates the number but resets neither flag:

		if (bp->i2c_ctrl && adap->dev.parent == &bp->i2c_ctrl->dev) {
			scoped_guard(spinlock, &bp->cpld_adap_lock)
				bp->cpld_i2c_adap_nr = adap->nr;
		}

so cpld.id is then absent for the lifetime of the binding. The comment above the parent check below states that a bad number is rejected "on the parent check and forgets it, and the next tick looks again" - does that hold when i2c_get_adapter() returns NULL rather than a mismatched adapter?

Quoted 14 lines
drivers/ptp/ptp_ocp.c +14 -0
+
+	/* The number is freed before the notifier clears it, so it can
+	 * already be another adapter's.  Check this is still ours, and drop
+	 * a number that is not: otherwise every later claim fails the same
+	 * way, where forgetting it lets the worker look the adapter up again.
+	 */
+	if (!bp->i2c_ctrl || adap->dev.parent != &bp->i2c_ctrl->dev) {
+		scoped_guard(spinlock, &bp->cpld_adap_lock) {
+			if (bp->cpld_i2c_adap_nr == adap->nr)
+				bp->cpld_i2c_adap_nr = -1;
+		}
+		i2c_put_adapter(adap);
+		return -ENODEV;
+	}

[ ... ]

Quoted 7 lines
drivers/ptp/ptp_ocp.c +3 -0
@@ -5052,6 +5522,17 @@ ptp_ocp_sync_work(struct work_struct *work)
 
 	bp->sync = sync;
 
+	/* Resolve the adapter here rather than once in probe, where it can
+	 * race the adapter's own registration, and read the ID as soon as it
+	 * turns up.  A claim can fail transiently - the firmware may not

drivers/ptp/ptp_ocp.c ptp_ocp_sync_work(struct work_struct *work) · line 5537

Quoted 10 lines
drivers/ptp/ptp_ocp.c +8 -0
+	 * grant the segment straight after power-up - so adva_x1_cpld_read_id()
+	 * retries a bounded number of times before giving up.
+	 */
+	adva_x1_cache_i2c_adap(bp);
+	if (bp->has_cpld && !READ_ONCE(bp->cpld_id_tried) &&
+	    READ_ONCE(bp->cpld_i2c_adap_nr) >= 0)
+		adva_x1_cpld_read_id(bp);
+
 	queue_delayed_work(system_power_efficient_wq, &bp->sync_work, HZ);
 }

[Severity: Medium]
Is the 1 Hz sync poller the right place for a claim that can block for seconds? adva_x1_mblaze_acquire() sleeps MBLAZE_RETRIES x MBLAZE_RETRY_US (200 x 10 ms), and on the timeout path the hand-back poll loop runs too, so one failed attempt can occupy this work item for several seconds, repeated once per tick until CPLD_ID_MAX_ATTEMPTS is reached.

Does that delay the bp->sync update and the dpll change notification by the same amount? ptp_ocp_remove() and .shutdown start with cancel_delayed_work_sync(&bp->sync_work), so unbind and reboot would block for the duration as well.

Once cpld_id_attempts reaches 10, cpld_id_tried stays set for the lifetime of the binding and cpld.id is silently absent, with both new interfaces read-only and no way to retrigger the read. Would it be worth mentioning these effects in the commit message, or moving the read to its own work item?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260916153242.157171-1-sagi.maimon%40adtran.com
#5 lore raw

Re: [PATCH net-next v15 3/4] ptp: ocp: add TAP CPLD access for ADVA TimeCard X1

Quoted 2 lines · On Sun, 20 Sep 2026 15:01:21 +0000 [email protected] wrote:

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

All five are fair and all five are fixed. The series is already applied to net-next, so this is answered with an incremental series rather than a respin; no "pw-bot: cr".

https://lore.kernel.org/netdev/[email protected]/T/#u

Quoted 2 lines

[High] adva_x1_bus_release() drops the i2c root-adapter lock and forgets the claim even when adva_x1_mblaze_release() returned -ETIMEDOUT

The consequence you spell out is the part I had not thought through:
ptp_ocp_read_eeprom() stores what it reads without validating it, and those values go out over the unprivileged info path.

Unlocking unconditionally stays - keeping the root lock after the firmware has stopped answering would wedge every other user of the controller with no way back - but the driver now records that the routing is unknown and refuses to cache an EEPROM read while it is, so it cannot publish TMC bus contents as the serial and board id. A later claim that the firmware grants clears it.

This does not fence the at24 and nvmem sysfs paths. Those do not go through the driver and I do not see a way to gate them from here; the fix is limited to not publishing the result myself.

Quoted 2 lines

[Medium] The one-shot CPLD ID read is executed from ptp_ocp_sync_work(), the driver's 1 Hz in-sync status poller.

Agreed, including the unbind and shutdown consequence - ptp_ocp_remove() is also the .shutdown handler. The read has its own delayed work now, queued only on boards with the part and rescheduled only until the one-shot read settles.

Quoted 2 lines

[Low] On an acquire timeout the MicroBlaze hand-back handshake is executed twice

Fixed. The acquire path no longer does its own hand-back, since the claim already calls the release path for that error.

Quoted 2 lines

[Low] adva_x1_bus_claim() returns -ENODEV when i2c_get_adapter() finds nothing for the cached number, without clearing bp->cpld_i2c_adap_nr.

Correct, and the comment there claiming the number is forgotten was only true for the mismatched-adapter case. Both paths go through one helper now. A newly cached adapter also re-arms the one-shot read, which otherwise stayed latched for the rest of the binding.

Quoted 1 line

[Low] The new struct ptp_ocp member comments overstate the locking

Yes. The design is that the writers are serialised and the readers re-validate what they got, which is not what the comments said. Reworded, and the cpld_id_tried stores are marked to match its unlocked readers.

The series is tested on an ADVA TimeCard X1. None of it changes what the driver puts on the I2C wire - the ISP command sequence, the frame contents and the arbitration timing are untouched.

Thanks for the review,
Sagi

#6 lore raw

PATCH v15 4/4 ptp: ocp: add TAP CPLD flashing via devlink

In reply to Sagi Maimon

From: Sagi Maimon <[email protected]>

The Lattice MachXO3 CPLD on the ADVA TimeCard X1 is programmed over I2C using in-system programming (ISP). Build on the TMC bus arbitration added previously and expose the update path as a devlink flash component, next to the card flash the driver already writes through devlink.

The component is named fw.cpld and reported as a running version, so ->info_get() both publishes the USERCODE of the image currently in the part and lets the core accept the name:

devlink dev flash pci/0000:02:00.0 file adva-cpld.bin component fw.cpld

Flashing acquires the bus, erases the configuration flash, programs the image page by page and activates it with the MachXO3 REFRESH command, reporting progress with the standard devlink notifications. The CPLD is required to come back with DONE set, not busy and no error code before the update is called successful, as drivers/fpga/machxo2-spi.c does.

The whole sequence runs under cpld_lock and the i2c adapter lock, so an EEPROM read blocks for as long as programming takes; the alternative is reading the TMC bus instead. Flashing is privileged:
DEVLINK_CMD_FLASH_UPDATE carries GENL_ADMIN_PERM.

---
 Documentation/ABI/testing/sysfs-timecard     |  11 +-
 Documentation/networking/devlink/ptp_ocp.rst |  48 +-
 drivers/ptp/ptp_ocp.c                        | 441 ++++++++++++++++++-
 3 files changed, 479 insertions(+), 21 deletions(-)
Documentation/ABI/testing/sysfs-timecard +8 -3
index e58824e0cdcd..4ba45c6ee4a3 100644
@@ -31,9 +31,14 @@ Description:	(RO, root only) The flags set in the status register of the
 
 		A read arbitrates for the shared I2C bus and reprograms the
 		on-card mux, so it is restricted to root.  The Lattice device
-		ID of the CPLD is read once by the driver, shortly after
-		probe, and reported from that cached value as the fixed
-		"cpld.id" version by devlink dev info.
+		ID of the CPLD is read by the driver shortly after probe,
+		and again after a successful CPLD update, and reported from
+		that cached value as the fixed "cpld.id" version by
+		devlink dev info.
+
+		New CPLD firmware is programmed with devlink dev flash,
+		selecting the "fw.cpld" component; see
+		Documentation/networking/devlink/ptp_ocp.rst.
 
 What:		/sys/class/timecard/ocpN/available_clock_sources
 Date:		September 2021
Documentation/networking/devlink/ptp_ocp.rst +44 -4

57 lines not on this page · raw message

drivers/ptp/ptp_ocp.c +427 -14

527 lines not on this page · raw message

Signature · 1 line
2.47.0
#7 lore raw

Re: [PATCH net-next v15 4/4] ptp: ocp: add TAP CPLD flashing via devlink

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

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

Critical: 0 · High: 0 · Medium: 6 · Low: 3

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] ptp_ocp_devlink_info_get() publishes the literal string "unknown" as the devlink *running version* value for the fw.cpld…
- [Medium] adva_x1_cpld_flash() invalidates the cached CPLD identity (WRITE_ONCE(bp->cpld_id, 0), WRITE_ONCE(bp->cpld_usercode_ok, false),…
- [Medium] In adva_x1_cpld_flash() the first status wait after EN_CFG_TP uses adva_x1_cpld_wait_ready() (drivers/ptp/ptp_ocp.c:4958-4962),…
- [Medium] adva_x1_cpld_flash() invalidates the cached CPLD identity only after *both* the ERASE write and its completion wait succeed…
- [Medium] adva_x1_cpld_flash() holds bp->cpld_lock (mutex_lock() at drivers/ptp/ptp_ocp.c:4933) and the I2C root adapter lock (taken by…
- [Medium] The driver clears its configuration-mode bookkeeping from an I2C ACK alone, and its post-REFRESH success predicate cannot detect a…
- [Low] Documentation/networking/devlink/ptp_ocp.rst states for fw.cpld:
"The only check the driver makes is that its length is a non-zero…
- [Low] The periodic progress notification in adva_x1_cpld_flash()'s page loop is emitted *after* the page at fw->data + offset has been written…
- [Low] adva_x1_cpld_flash() resets the ID-read bookkeeping with plain stores (bp->cpld_id_tried = false; bp->cpld_id_attempts = 0; at…

--

ptp: ocp: add TAP CPLD flashing via devlink

This adds a second devlink flash target to ptp_ocp: the "fw.cpld" component programs the Lattice MachXO3 configuration flash on ADVA TimeCard X1 boards over I2C and activates it with a REFRESH. ->info_get() now also reports the CPLD USERCODE as a running version, which is what lets the core accept the component name.

A few questions about the new code and the documentation added with it.

Quoted 5 lines
Documentation/ABI/testing/sysfs-timecard +0 -0
index e58824e0cdcdf..4ba45c6ee4a36 100644

Documentation/ABI/testing/sysfs-timecard Description: (RO, root only) The flags set in the status register of the · line 37

Quoted 10 lines
Documentation/ABI/testing/sysfs-timecard +4 -3
@@ -31,9 +31,14 @@ Description:	(RO, root only) The flags set in the status register of the
 
 		A read arbitrates for the shared I2C bus and reprograms the
 		on-card mux, so it is restricted to root.  The Lattice device
-		ID of the CPLD is read once by the driver, shortly after
-		probe, and reported from that cached value as the fixed
-		"cpld.id" version by devlink dev info.
+		ID of the CPLD is read by the driver shortly after probe,
+		and again after a successful CPLD update, and reported from
+		that cached value as the fixed "cpld.id" version by
+		devlink dev info.

[Severity: Medium]
Does the code match "again after a successful CPLD update"?

adva_x1_cpld_flash() drops the cached identity as soon as the erase wait returns, on every attempt that gets that far:

	WRITE_ONCE(bp->cpld_id, 0);
	WRITE_ONCE(bp->cpld_usercode_ok, false);
	bp->cpld_id_tried = false;
	bp->cpld_id_attempts = 0;

Any later failure - a page write error, the new -EINTR abort, SET_DONE or REFRESH failing - still returns an error, but cpld.id is already gone from devlink dev info.

Recovery then depends on adva_x1_cpld_read_id() succeeding within CPLD_ID_MAX_ATTEMPTS sync_work ticks, after which cpld_id_tried latches and the worker stops trying.

Since the Lattice IDCODE cannot change when the configuration flash is erased, should cpld.id survive a failed update, or should the documentation say the identity is dropped on any attempt that reaches the erase?

Quoted 11 lines
Documentation/ABI/testing/sysfs-timecard +4 -0
+
+		New CPLD firmware is programmed with devlink dev flash,
+		selecting the "fw.cpld" component; see
+		Documentation/networking/devlink/ptp_ocp.rst.
 
 What:		/sys/class/timecard/ocpN/available_clock_sources
 Date:		September 2021
Documentation/networking/devlink/ptp_ocp.rst +0 -0
index 3f997cd9f3a3f..f94b759d9cd65 100644

[ ... ]

Quoted 17 lines
Documentation/networking/devlink/ptp_ocp.rst +10 -3
@@ -30,6 +30,46 @@ The ``ptp_ocp`` driver reports the following versions
      - Lattice device ID (IDCODE) of the TAP CPLD, formatted as ``0x%08x``.
        Only present on ADVA TimeCard X1 boards, which are the only ones
        carrying that CPLD.  Reading it claims the shared I2C bus and
-       reprograms the on-card mux, so the driver does that once from its
-       own worker and reports the cached value here; the version is
-       omitted until that read has succeeded.
+       reprograms the on-card mux, so the driver does that from its own
+       worker and reports the cached value here; the version is omitted
+       until that read has succeeded.  The read is made once per binding
+       and again after a successful CPLD update.
+   * - ``fw.cpld``
+     - running
+     - USERCODE of the image programmed into the TAP CPLD, formatted as
+       ``0x%08x``.  Read together with ``cpld.id`` and reported the same
+       way.  This is the component name to pass to ``devlink dev flash``
+       to update the CPLD.

[ ... ]

Documentation/networking/devlink/ptp_ocp.rst The ``ptp_ocp`` driver reports the following versions · line 67

Quoted 10 lines
Documentation/networking/devlink/ptp_ocp.rst +10 -0
+   * - ``fw.cpld``
+     - The configuration flash of the TAP CPLD on ADVA TimeCard X1 boards,
+       programmed over I2C with the MachXO3 in-system programming commands
+       and activated with a REFRESH, so the new image runs immediately.
+       The image is the raw configuration bitstream.  The only check the
+       driver makes is that its length is a non-zero multiple of the
+       16-byte page size, so a container such as ``.jed`` has to be
+       converted first rather than passed through - one whose length
+       happens to be a multiple of 16 would be programmed as if it were
+       a bitstream.

[Severity: Low]
Is "the only check the driver makes" accurate? adva_x1_cpld_flash() also rejects large images:

	if (fw->size > CPLD_MAX_IMAGE_SZ) {
		NL_SET_ERR_MSG_MOD(extack, "image too large for this part");
		return -EINVAL;
	}

with CPLD_MAX_IMAGE_SZ being 256 KiB.

Should the failure semantics be documented here as well? After the erase the configuration flash is blank, so any mid-sequence failure - including the new fatal_signal_pending() abort, whose own comment says "The part is left unconfigured" - leaves the CPLD unconfigured until a valid image is written again.

Quoted 4 lines
drivers/ptp/ptp_ocp.c +0 -0
index 998ea9c6b3817..2802989e84947 100644

[ ... ]

Quoted 5 lines
drivers/ptp/ptp_ocp.c +4 -0
@@ -2192,14 +2224,35 @@ ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
+		/* The flashable component.  Naming it here is what lets
+		 * "devlink dev flash ... component fw.cpld" through, as the
+		 * core matches the name against the versions reported here,
+		 * so it is reported for every board that has the part and not

drivers/ptp/ptp_ocp.c ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req, · line 2237

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+		 * only once its USERCODE has been read: a part left holding a
+		 * bad image answers neither, and gating the component on the
+		 * read would make that state unrecoverable.
+		 */
+		if (smp_load_acquire(&bp->cpld_usercode_ok))
+			sprintf(buf, "0x%08x", READ_ONCE(bp->cpld_usercode));
+		else
+			strscpy(buf, "unknown", sizeof(buf));
+		err = devlink_info_version_running_put_ext(req, "fw.cpld", buf,
+							   ver_type);

[Severity: Medium]
Should the string "unknown" be published as a devlink running version value?

The changelog says ->info_get() "publishes the USERCODE of the image currently in the part", and the .rst entry added by this patch says fw.cpld is the "USERCODE ... formatted as ``0x%08x``. Read together with ``cpld.id`` and reported the same way" - and cpld.id is skipped entirely while unread.

The window is not narrow: every devlink dev info between probe and the first successful worker read, and permanently after a flash that erased but did not finish, since adva_x1_cpld_flash() clears cpld_usercode_ok and the worker gives up after CPLD_ID_MAX_ATTEMPTS.

Does naming the component actually need a value? In devlink_info_version_put() the callback runs before the empty-value early-out:

net/devlink/dev.c:devlink_info_version_put() {
	...
	if (req->version_cb)
		req->version_cb(version_name, version_type,
				req->version_cb_priv);

	if (!req->msg || !*version_value)
		return 0;
	...
}

so passing "" would still register the name for devlink_flash_component_get() while emitting no version attribute, which is the behaviour the .rst describes.

[ ... ]

Quoted 30 lines
drivers/ptp/ptp_ocp.c +26 -0
@@ -4596,11 +4720,86 @@ static int adva_x1_cpld_read_status(struct ptp_ocp *bp, u32 *status)
 	return 0;
 }
 
+/* Poll the status register until the CPLD goes idle, or @max_ms elapses.
+ * The deadline is on wall time, so the I2C transactions count against it,
+ * and the status is read once more after it expires before giving up.
+ */
+static int adva_x1_cpld_wait_ready(struct ptp_ocp *bp, unsigned int max_ms)
+{
+	u32 status = 0;
+	int err = 0, ret;
+
+	ret = read_poll_timeout(adva_x1_cpld_read_status, err,
+				err || (status & CPLD_STATUS_FAILED) ||
+				!(status & CPLD_STATUS_BUSY),
+				CPLD_POLL_US, max_ms * USEC_PER_MSEC, false,
+				bp, &status);
+	if (ret)
+		return ret;
+	/* Keep the transport errno so it reaches userspace as-is; -EIO is
+	 * reserved for the CPLD itself reporting FAILED.
+	 */
+	if (err)
+		return err;
+	if (status & CPLD_STATUS_FAILED)
+		return -EIO;
+
+	return 0;
+}

[ ... ]

Quoted 19 lines
drivers/ptp/ptp_ocp.c +19 -0
+static void adva_x1_cpld_exit_config(struct ptp_ocp *bp)
+{
+	int err, i;
+
+	if (!bp->cpld_in_config_mode)
+		return;
+
+	for (i = 0; i < CPLD_EXIT_CFG_TRIES; i++) {
+		err = adva_x1_cpld_wait_idle(bp, CPLD_ERASE_MS);
+		if (!err)
+			err = adva_x1_cpld_write(bp, CPLD_CMD_DIS_CFG);
+		if (!err) {
+			bp->cpld_in_config_mode = false;
+			return;
+		}
+	}
+
+	dev_err(&bp->pdev->dev, "CPLD left in configuration mode: %d\n", err);
+}

[ ... ]

Quoted 14 lines
drivers/ptp/ptp_ocp.c +10 -0
@@ -4694,6 +4906,207 @@ cpld_status_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_ADMIN_RO(cpld_status);
 
+/*
+ * Program the CPLD configuration flash from @fw and activate it.  Selected
+ * by the "fw.cpld" flash component; the SPI flash keeps the default path.
+ * Runs under cpld_lock with the i2c adapter lock held, so an EEPROM read
+ * blocks for as long as programming takes.
+ */
+static int adva_x1_cpld_flash(struct ptp_ocp *bp, struct devlink *devlink,
+			      const struct firmware *fw,
+			      struct netlink_ext_ack *extack)
+{

[ ... ]

drivers/ptp/ptp_ocp.c cpld_status_show(struct device *dev, struct device_attribute *attr, · line 4937

Quoted 5 lines
drivers/ptp/ptp_ocp.c +5 -0
+	mutex_lock(&bp->cpld_lock);
+
+	err = adva_x1_bus_claim(bp);
+	if (err)
+		goto unlock;

[Severity: Medium]
Can this trip the hung-task detector for other users of the adapter?

adva_x1_bus_claim() takes the root adapter lock with i2c_lock_bus(adap, I2C_LOCK_ROOT_ADAPTER), which is an uninterruptible, non-killable acquisition for everyone else, and it is held here together with cpld_lock for the whole cycle:

EN_CFG wait 5 s
ERASE wait CPLD_ERASE_MS (15 s)
page loop 100 ms per 16-byte page, up to

				CPLD_MAX_IMAGE_SZ / 16 = 16384 pages

SET_DONE wait 1 s
msleep(1500) + mux poll 1.5 s + 3 s
post-REFRESH wait 3 s
failure path CPLD_EXIT_CFG_TRIES * CPLD_ERASE_MS (45 s)

Meanwhile the at24/nvmem EEPROM read reached from ptp_ocp_read_eeprom() (also called from the unprivileged ptp_ocp_devlink_info_get() path) and any other client of that adapter waits in i2c_lock_bus() and cannot be killed.

The changelog does say "an EEPROM read blocks for as long as programming takes", but with the worst case above that exceeds the 120 s hung-task threshold. Would releasing the bus between phases, or bounding the total hold, be preferable to the size cap whose comment claims it "Bounds how long a claim can hold the i2c root lock"?

The new fatal_signal_pending() check only helps the flashing task, not the waiters - is that the intent?

[ ... ]

drivers/ptp/ptp_ocp.c cpld_status_show(struct device *dev, struct device_attribute *attr, · line 4962

Quoted 5 lines
drivers/ptp/ptp_ocp.c +5 -0
+	err = adva_x1_cpld_write(bp, CPLD_CMD_EN_CFG_TP);
+	if (!err)
+		err = adva_x1_cpld_wait_ready(bp, 5000);
+	if (err)
+		goto exit_config;

[Severity: Medium]
Is adva_x1_cpld_wait_ready() the right wait for the enable step?

It turns a set CPLD_STATUS_FAILED into -EIO, and the driver's own comment above adva_x1_cpld_wait_idle() says FAILED is latched across operations ("an ISC command issued while the part is still erasing or programming may not latch, so the operation has to be waited out whatever its outcome").

Nothing in the driver clears it: the failure path
adva_x1_cpld_exit_config() only sends DIS_CFG.

So if FAILED survives a DIS_CFG plus a fresh EN_CFG_TP, does every later devlink dev flash ... component fw.cpld return -EIO here, before reaching the ERASE/REFRESH that would put the part back into a defined state? That would contradict the comment in the page loop saying the state "is
recoverable: fw.cpld stays advertised so the image can be written again".

For comparison, machxo2_write_init() in drivers/fpga/machxo2-spi.c tests FAIL only after ISC_ENABLE and ISC_ERASE, and machxo2_cleanup() recovers with ISC_ERASE followed by LSC_REFRESH.

[ ... ]

drivers/ptp/ptp_ocp.c cpld_status_show(struct device *dev, struct device_attribute *attr, · line 4989

Quoted 7 lines
drivers/ptp/ptp_ocp.c +7 -0
+	devlink_flash_update_status_notify(devlink, "Erasing",
+					   ADVA_CPLD_COMPONENT, 0, 0);
+	err = adva_x1_cpld_write(bp, CPLD_CMD_ERASE);
+	if (!err)
+		err = adva_x1_cpld_wait_ready(bp, CPLD_ERASE_MS);
+	if (err)
+		goto exit_config;

[Severity: Medium]
Does this leave stale identity published when the erase is under way but the wait fails?

If adva_x1_cpld_write(CPLD_CMD_ERASE) is ACKed, the erase is running in hardware. If adva_x1_cpld_wait_ready() then returns -ETIMEDOUT, -EIO for a latched FAILED, or a transport errno, this goto skips the invalidation below entirely.

bp->cpld_id keeps its old value, cpld_usercode_ok stays true, and cpld_id_tried stays true from the probe-time read, so the !READ_ONCE(bp->cpld_id_tried) gate in ptp_ocp_sync_work() never re-reads. ptp_ocp_devlink_info_get() then keeps publishing cpld.id and an fw.cpld USERCODE for an image that is no longer in the part, for the rest of the binding.

Would invalidating before issuing the ERASE (or right after the write returns 0) match the comment below, "stop reporting its identity even if the rest of the sequence fails"?

drivers/ptp/ptp_ocp.c cpld_status_show(struct device *dev, struct device_attribute *attr, · line 4999

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+
+	/* The old image is gone from here on, so stop reporting its
+	 * identity even if the rest of the sequence fails.  Written under
+	 * cpld_lock, which adva_x1_cpld_read_id() also holds across its own
+	 * bookkeeping, so the worker cannot resurrect any of it.
+	 */
+	WRITE_ONCE(bp->cpld_id, 0);
+	WRITE_ONCE(bp->cpld_usercode_ok, false);
+	bp->cpld_id_tried = false;
+	bp->cpld_id_attempts = 0;

[Severity: Low]
Should these two be WRITE_ONCE() as well?

ptp_ocp_sync_work() reads the flag without cpld_lock:

	if (bp->has_cpld && !READ_ONCE(bp->cpld_id_tried) &&
	    READ_ONCE(bp->cpld_i2c_adap_nr) >= 0)
		adva_x1_cpld_read_id(bp);

so the writer holds cpld_lock and the reader holds nothing, which is a plain-store versus marked-load pair that KCSAN would report.

The comment here says "Written under cpld_lock, which adva_x1_cpld_read_id() also holds across its own bookkeeping, so the worker cannot resurrect any of it", and the struct field comment says "under cpld_lock", but neither covers the worker's unlocked gate. The effect looks benign, since the racing read_id() attempt just gets -EBUSY from mutex_trylock().

[ ... ]

drivers/ptp/ptp_ocp.c cpld_status_show(struct device *dev, struct device_attribute *attr, · line 5030

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+		if (!err)
+			err = adva_x1_cpld_wait_ready(bp, 100);
+		if (err)
+			goto exit_config;
+
+		if (!(offset % (CPLD_PAGE_SIZE * 64)))
+			devlink_flash_update_status_notify(devlink,
+							   "Programming",
+							   ADVA_CPLD_COMPONENT,
+							   offset, fw->size);

[Severity: Low]
Should this report offset + CPLD_PAGE_SIZE?

The page at fw->data + offset has already been written and waited for at this point, so the first notification says 0 bytes done and each periodic one is a page behind. Moving the notify above the page write would work too.

[ ... ]

drivers/ptp/ptp_ocp.c cpld_status_show(struct device *dev, struct device_attribute *attr, · line 5062

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+	devlink_flash_update_status_notify(devlink, "Activating",
+					   ADVA_CPLD_COMPONENT, 0, 0);
+	err = adva_x1_cpld_write(bp, CPLD_CMD_REFRESH);
+	if (err)
+		goto exit_config;
+
+	/* REFRESH reboots the CPLD out of configuration mode, so the exit
+	 * path must not send DIS_CFG afterwards even if a check below fails.
+	 */
+	bp->cpld_in_config_mode = false;

[Severity: Medium]
Can an ACKed but unlatched REFRESH be reported as a successful update?

The I2C ACK alone clears cpld_in_config_mode here, and the final check after the reselect only looks at:

	if (!(st & CPLD_STATUS_DONE) || (st & CPLD_STATUS_BUSY) ||
	    (st & CPLD_STATUS_ERR)) {

Those three conditions are already satisfied by the state left by SET_DONE, so if the REFRESH frame does not latch, the part stays in configuration mode running the old image and devlink dev flash still returns 0 - while the .rst says "the new image runs immediately".

CPLD_STATUS_ENAB is defined by this patch and tested after EN_CFG_TP, but never after REFRESH. Would checking ENAB here (and retrying REFRESH, as machxo2_write_complete() does up to MACHXO2_MAX_REFRESH_LOOP times) be worthwhile?

The same question applies to adva_x1_cpld_exit_config(), which clears cpld_in_config_mode as soon as the DIS_CFG write is ACKed without reading ENAB back. Since the recovery call at the start of adva_x1_cpld_flash() is gated on that flag, does one false-positive exit make a part stuck in configuration mode unreachable by that recovery?

Quoted 6 lines
drivers/ptp/ptp_ocp.c +6 -0
+
+	/* The new image is already running, so a segment that is not back
+	 * yet must not be reported as a failed update: retry the reselect
+	 * rather than sampling the mux once at a fixed delay.
+	 */
+	msleep(1500);

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260916153242.157171-1-sagi.maimon%40adtran.com
#8 lore raw

Re: [PATCH net-next v15 4/4] ptp: ocp: add TAP CPLD flashing via devlink

Quoted 2 lines · On Sun, 20 Sep 2026 15:01:22 +0000 [email protected] wrote:

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

Five of the six Medium findings are fixed in the follow-up series I am posting alongside this; the sixth I have answered below rather than changed. All three Low ones are fixed. The series is already applied to net-next, so this is incremental rather than a respin; no "pw-bot: cr".

https://lore.kernel.org/netdev/[email protected]/T/#u

Quoted 6 lines

[Medium] ptp_ocp_devlink_info_get() publishes the literal string "unknown" as the devlink *running version* value for the fw.cpld component
(...)
so passing "" would still register the name for devlink_flash_component_get() while emitting no version attribute

Thank you - that is better than what I had, and I had not spotted that version_cb runs ahead of the empty-value early-out. The placeholder existed only because naming the component is what makes it flashable, and a part left holding a bad image answers neither READ_ID nor READ_USERCODE, so gating the name on a successful read would have made exactly that state unrecoverable. An empty value keeps that property without publishing a version nobody can use. Changed, with a Suggested-by.

Quoted 2 lines

[Medium] adva_x1_cpld_flash() invalidates the cached CPLD identity only after *both* the ERASE write and its completion wait succeed

Right. An ACKed ERASE is running in the part whatever the wait then returns, so the invalidation has to happen before the ERASE is issued, not after it is confirmed. Moved.

Quoted 2 lines

Since the Lattice IDCODE cannot change when the configuration flash is erased, should cpld.id survive a failed update

It should, and this is the better half of that finding. cpld.id was being dropped along with the USERCODE, so a failed update hid information that was still correct and made recovery depend on a re-read that might not succeed. Only the USERCODE is dropped now. The ABI and .rst text claiming the identification is re-read "after a successful CPLD update" never matched the code either; both now describe what is actually dropped and restored.

Quoted 2 lines

[Medium] In adva_x1_cpld_flash() the first status wait after EN_CFG_TP uses adva_x1_cpld_wait_ready()

This is the most useful finding in the set. FAILED is latched and nothing in the driver clears it, so a part that had failed once would return -EIO at the enable step of every later flash, before reaching the ERASE and REFRESH that would put it back into a defined state - directly contradicting the "recoverable, fw.cpld stays advertised so the image can be written again" comment in the page loop. The enable step uses adva_x1_cpld_wait_idle() now, and the ENAB check that follows decides whether the part entered configuration mode, which is also what machxo2_write_init() does.

Quoted 3 lines

[Medium] The driver clears its configuration-mode bookkeeping from an I2C ACK alone, and its post-REFRESH success predicate cannot detect a REFRESH that was ACKed but never latched

Correct, and the reason is exactly the one you give: DONE set, BUSY clear and no error code are already true of the state SET_DONE leaves behind, so they cannot separate the two cases. The check now also requires ENAB to be clear, since leaving configuration mode is the one thing only a REFRESH does, and cpld_in_config_mode is put back when it is not, so the exit path and the recovery at the start of the next flash act on the real state instead of an ACK.

I have not added the REFRESH retry loop machxo2_write_complete() uses. With the ENAB test in place a REFRESH that does not latch is now reported as a failure rather than a success, which is the part that mattered; a retry would change what goes on the wire for a case I have not been able to produce on the part. Happy to add it if you would rather have it.

Quoted 2 lines

[Medium] adva_x1_cpld_flash() holds bp->cpld_lock and the I2C root adapter lock (...) can this trip the hung-task detector?

This is the one I have not changed, and I would rather say why than guess at a fix I cannot verify.

The 100 ms in the page loop is a timeout, not a per-page cost: a real 6526-page image programs in well under a minute, and the hand-back that follows was measured at about 670 ms against its 2 s budget. The worst case you add up is reachable only if the part stops answering at every step, in which case the sequence is failing anyway.

Releasing the bus between phases is not safe here: the whole point of holding the root lock across the claim is that the controller is routed away from the EEPROMs for the duration, so dropping it mid-sequence would let an EEPROM read land on the TMC segment - the problem patch 2 of the follow-up exists to prevent. Bounding the total hold would mean abandoning a part mid-erase, which is worse than waiting.

Lowering CPLD_MAX_IMAGE_SZ would shrink the arithmetic without changing the real behaviour, so I have left the cap where it is rather than pretend it is a fix. If you would rather see the phases split or the cap tightened, say so and I will do it.

Quoted 1 line

[Low] Is "the only check the driver makes" accurate?

No - the size cap arrived after that sentence was written. Corrected, and the .rst now also says what state a failure part-way leaves the part in, and that the component stays available to write a valid image again.

Quoted 1 line

[Low] Should this report offset + CPLD_PAGE_SIZE?

Yes; it was a page behind and never reached fw->size from inside the loop. Fixed.

Quoted 1 line

[Low] Should these two be WRITE_ONCE() as well?

Yes. Done, and the struct comments that claimed a lock the readers do not take are reworded.

The series is tested on an ADVA TimeCard X1: the CPLD still programs and activates with all of it applied, so the two checks that decide whether an operation is believed - ENAB after EN_CFG_TP, and ENAB clear after REFRESH
- agree with the part rather than just with my reading of the datasheet.

Thanks for the review - the enable-step and REFRESH findings were real false-success paths and I would not have found them on my own.

Sagi

maintainer
#9 lore raw
In reply to Sagi Maimon
Quoted 3 lines · On Wed, 16 Sep 2026 18:32:38 +0300 Sagi Maimon wrote:

The ADVA TimeCard X1 (PCI device 0x0410) carries a Lattice MachXO3 CPLD on the TMC I2C bus. This series adds access to it and an update path through devlink flash.

Good enough for me, please post incremental follow up on any of the AI nit picks if necessary

#10 lore raw
In reply to Sagi Maimon
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 4 lines · On Wed, 16 Sep 2026 18:32:38 +0300 you wrote:

The ADVA TimeCard X1 (PCI device 0x0410) carries a Lattice MachXO3 CPLD on the TMC I2C bus. This series adds access to it and an update path through devlink flash.

Quoted 8 lines

The card has two I2C controllers. Linux registers only the one at 0x00150000, normally routed to the config EEPROMs; the one at 0x00120000 belongs to the on-card MicroBlaze and is routed to the TMC or M.2 bus as its firmware selects. A request/grant handshake re-routes the host controller onto the TMC bus, where the PCA9548 and the CPLD behind its channel 0 live. Everything here is built on that handshake.

[...]

Here is the summary with links:
- [net-next,v15,1/4] ptp: ocp: unregister devlink before detach on probe error

    https://git.kernel.org/netdev/net-next/c/a2bd6c17665f
  - [net-next,v15,2/4] ptp: ocp: fix dpll cleanup on probe error
    https://git.kernel.org/netdev/net-next/c/65ca1f70c4df
  - [net-next,v15,3/4] ptp: ocp: add TAP CPLD access for ADVA TimeCard X1
    https://git.kernel.org/netdev/net-next/c/3b815e29966f
  - [net-next,v15,4/4] ptp: ocp: add TAP CPLD flashing via devlink
    https://git.kernel.org/netdev/net-next/c/a4b7c15aa78f

You are awesome, thank you!

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