Skip to contentSkip to conversation

ptp: ocp: support the WiWi production Time Card

PATCH Superseded Ahmad Byagowi 2 participants 8 messages Nov 12 – Nov 16

Subsystems (8)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover ptp: ocp: support the WiWi production Time Card

The WiWi Time Card (2163:1008, subsystem 10ee:0007) uses a Celestica-compatible register map behind LitePCIe. Its bridge does not support the subword MMIO used by the XIIC driver. Add an opt-in word access mode, exercise both modes with KUnit, and enable ptp_ocp on the revision 02 interface. Other cards retain their existing access modes. The series does not enable WiWi flash updates or change LED policy.

Patch 3 uses the platform-data field from patch 1. Could the I2C maintainers review patches 1 and 2 for an Ack to take the series through net-next?

Changes since v1:
- 1/3: Drop five explicit inline annotations in the C file and shorten the platform-data comment. No access semantics change.
- 2/3: Wrap the offsets and expectations flagged by checkpatch. The four test modes, register offsets and expected values are unchanged.
- 3/3: Follow NetTimeLogic's PCI revision convention. Replace the exact image ID and per-core version checks with a revision 02 gate. Reject unknown revisions before FPGA MMIO and retain the BAR/MSI-X checks. Report the full build ID in devlink; select capabilities by interface revision. Update the documentation and wrap overlength lines.

The revision 02 driver was tested on a physical card running build 0x0000800f under Secure Boot. It bound with 64 MSI-X vectors; the PHC advanced 3.000441080 s over three one-second sleeps. SPI NOR and both EEPROM clients bound. The PHC was UNSYNCED at probe; this test does not establish PPS lock or valid UTC. Only that firmware build was tested on hardware. Subsequent edits to the tested drivers remove inline hints or change formatting and comments.

On the rebased v2, the XIIC and ptp_ocp objects built on x86-64 with W=1 under allmodconfig and allyesconfig. Four XIIC KUnit cases passed in an isolated x86-64 QEMU boot. Fixtures exercised all 256 PCI revisions, bad PCI layouts and multiple image IDs. These are not additional hardware tests. No full allmodconfig or allyesconfig build is claimed for v2.

Codex assisted with the changes, tests and changelogs using the board layout, machine-check evidence, vendor revision rule and v1 CI reports.

v1: https://lore.kernel.org/netdev/[email protected]/

Ahmad Byagowi (3):
i2c: xiic: allow platforms to require 32-bit register accesses
i2c: xiic: add KUnit coverage for register access modes
ptp: ocp: support the WiWi revision 02 Time Card

 Documentation/networking/devlink/ptp_ocp.rst |  36 +++-
 MAINTAINERS                                  |   1 +
 drivers/i2c/busses/Kconfig                   |  14 ++
 drivers/i2c/busses/i2c-xiic.c                |  60 +++++--
 drivers/i2c/busses/tests/i2c_xiic_kunit.c    |  91 +++++++++++
 drivers/ptp/ptp_ocp.c                        | 163 ++++++++++++++++++-
 include/linux/platform_data/i2c-xiic.h       |   3 +
 7 files changed, 341 insertions(+), 27 deletions(-)
 create mode 100644 drivers/i2c/busses/tests/i2c_xiic_kunit.c

base-commit: 368fbf5d82da9ebce309449c74fc0b128f7d0219

#1 lore raw

PATCH v2 1/3 i2c: xiic: allow platforms to require 32-bit register accesses

The LitePCIe bridge in the WiWi Time Card production image cannot safely service subword MMIO accesses. Bringing up its AXI IIC controller with the existing byte accessors caused a fatal machine check. Two crash dumps placed the faulting access in ioread8(), called by xiic_clear_rx_fifo() during xiic_reinit(). The affected register was the IIC status register.

Add a platform-data flag to use aligned 32-bit accesses for registers carrying byte or halfword values. Keep the detected register endianness and use a single transaction, not read-modify-write, for FIFO accesses. Platforms that do not request this mode retain their existing accessors.

With these accessors on a WiWi card, the controller probed and at24 registered the board and MAC EEPROMs. Repeated EEPROM reads and I2C interrupt delivery were tested separately on an earlier Ubuntu port.

Tool-origin disclosure, as required by generated-content.rst: Codex was used to analyze the supplied crash evidence, implement the accessors, prepare tests and draft this changelog. The request was to support the WiWi card while retaining the existing behavior on other platforms.

---
 drivers/i2c/busses/i2c-xiic.c          | 56 +++++++++++++++++---------
 include/linux/platform_data/i2c-xiic.h |  3 ++
 2 files changed, 41 insertions(+), 18 deletions(-)
drivers/i2c/busses/i2c-xiic.c +38 -18
index ba560462d..8425a540f 100644
@@ -66,6 +66,7 @@ enum i2c_scl_freq {
  * @rx_msg: Current RX message
  * @rx_pos: Position within current RX message
  * @endianness: big/little-endian byte order
+ * @force_32bit_access: Bridge requires aligned 32-bit register accesses
  * @clk: Pointer to AXI4-lite input clock
  * @irq: Interrupt number
  * @state: See STATE_
@@ -95,6 +96,7 @@ struct xiic_i2c {
 	struct i2c_msg *rx_msg;
 	int rx_pos;
 	enum xiic_endian endianness;
+	bool force_32bit_access;
 	struct clk *clk;
 	int irq;
 	enum xilinx_i2c_state state;
@@ -282,52 +284,68 @@ static int xiic_i2c_runtime_resume(struct device *dev)
  * Only the least significant byte [doublet] of the register are ever
  * accessed. This requires an offset of 3 [2] from the base address for
  * big-endian systems.
+ * Some bridges only support aligned 32-bit accesses. For these, access the
+ * entire register in its detected byte order, without a read-modify-write:
+ * reading or writing a FIFO register must perform exactly one transaction.
  */
 
-static inline void xiic_setreg8(struct xiic_i2c *i2c, int reg, u8 value)
+static void xiic_setreg32(struct xiic_i2c *i2c, int reg, int value)
 {
 	if (i2c->endianness == LITTLE)
-		iowrite8(value, i2c->base + reg);
+		iowrite32(value, i2c->base + reg);
 	else
-		iowrite8(value, i2c->base + reg + 3);
+		iowrite32be(value, i2c->base + reg);
 }
 
-static inline u8 xiic_getreg8(struct xiic_i2c *i2c, int reg)
+static int xiic_getreg32(struct xiic_i2c *i2c, int reg)
 {
-	u8 ret;
+	u32 ret;
 
 	if (i2c->endianness == LITTLE)
-		ret = ioread8(i2c->base + reg);
+		ret = ioread32(i2c->base + reg);
 	else
-		ret = ioread8(i2c->base + reg + 3);
+		ret = ioread32be(i2c->base + reg);
 	return ret;
 }
 
-static inline void xiic_setreg16(struct xiic_i2c *i2c, int reg, u16 value)
+static void xiic_setreg8(struct xiic_i2c *i2c, int reg, u8 value)
 {
+	if (i2c->force_32bit_access) {
+		xiic_setreg32(i2c, reg, value);
+		return;
+	}
+
 	if (i2c->endianness == LITTLE)
-		iowrite16(value, i2c->base + reg);
+		iowrite8(value, i2c->base + reg);
 	else
-		iowrite16be(value, i2c->base + reg + 2);
+		iowrite8(value, i2c->base + reg + 3);
 }
 
-static inline void xiic_setreg32(struct xiic_i2c *i2c, int reg, int value)
+static u8 xiic_getreg8(struct xiic_i2c *i2c, int reg)
 {
+	u8 ret;
+
+	if (i2c->force_32bit_access)
+		return xiic_getreg32(i2c, reg);
+
 	if (i2c->endianness == LITTLE)
-		iowrite32(value, i2c->base + reg);
+		ret = ioread8(i2c->base + reg);
 	else
-		iowrite32be(value, i2c->base + reg);
+		ret = ioread8(i2c->base + reg + 3);
+	return ret;
 }
 
-static inline int xiic_getreg32(struct xiic_i2c *i2c, int reg)
+static void xiic_setreg16(struct xiic_i2c *i2c, int reg, u16 value)
 {
-	u32 ret;
+	if (i2c->force_32bit_access) {
+		xiic_setreg32(i2c, reg, value);
+		return;
+	}
 
 	if (i2c->endianness == LITTLE)
-		ret = ioread32(i2c->base + reg);
+		iowrite16(value, i2c->base + reg);
 	else
-		ret = ioread32be(i2c->base + reg);
-	return ret;
+		iowrite16be(value, i2c->base + reg + 2);
 }
 
 static inline void xiic_irq_dis(struct xiic_i2c *i2c, u32 mask)
@@ -1480,6 +1498,8 @@ static int xiic_i2c_probe(struct platform_device *pdev)
 		return irq;
 
 	pdata = dev_get_platdata(dev);
+	if (pdata)
+		i2c->force_32bit_access = pdata->force_32bit_access;
 
 	/* hook up driver to tree */
 	platform_set_drvdata(pdev, i2c);
include/linux/platform_data/i2c-xiic.h +3 -0
index 2e3683c23..afad9a49c 100644
@@ -16,6 +16,8 @@
  * @num_devices:	Number of devices that shall be added when the driver
  *			is probed.
  * @devices:		The actuall devices to add.
+ * @force_32bit_access:	Use aligned 32-bit accesses even for byte and
+ *			halfword payloads on bridges without subword I/O.
  *
  * This purpose of this platform data struct is to be able to provide a number
  * of devices that should be added to the I2C bus. The reason is that sometimes
@@ -26,6 +28,7 @@
 struct xiic_i2c_platform_data {
 	u8				num_devices;
 	struct i2c_board_info const	*devices;
+	bool				force_32bit_access;
 };
 
 #endif /* _LINUX_I2C_XIIC_H */
#2 lore raw

PATCH v2 2/3 i2c: xiic: add KUnit coverage for register access modes

In reply to Ahmad Byagowi

Exercise the driver's private register accessors with memory-backed registers instead of physical hardware. Cover native byte/halfword and forced 32-bit accesses in both register byte orders, across 22 register offsets. Check payload truncation, high-bit values and neighboring sentinels. These tests do not validate physical bus transaction widths or hardware interrupt behavior.

Include the tests in the driver translation unit so no accessors need to become exported interfaces. Require built-in KUnit to avoid a built-in driver depending on a modular test framework. The tests follow the driver into either its built-in image or module.

The four parameterized cases passed in an isolated x86-64 QEMU boot with networking disabled and no physical-device passthrough.

Tool-origin disclosure, as required by generated-content.rst: Codex was used to implement this test suite, run the KUnit build/boot and draft this changelog, in response to a request for upstream-quality testing.

---
 MAINTAINERS                               |  1 +
 drivers/i2c/busses/Kconfig                | 14 ++++
 drivers/i2c/busses/i2c-xiic.c             |  4 +
 drivers/i2c/busses/tests/i2c_xiic_kunit.c | 91 +++++++++++++++++++++++
 4 files changed, 110 insertions(+)
 create mode 100644 drivers/i2c/busses/tests/i2c_xiic_kunit.c
MAINTAINERS +1 -0
index 893b0670a..64fa74c40 100644
@@ -4018,6 +4018,7 @@ F:	drivers/cpuidle/cpuidle-zynq.c
 F:	drivers/edac/synopsys_edac.c
 F:	drivers/i2c/busses/i2c-cadence.c
 F:	drivers/i2c/busses/i2c-xiic.c
+F:	drivers/i2c/busses/tests/i2c_xiic_kunit.c
 F:	drivers/mmc/host/sdhci-of-arasan.c
 N:	zynq
 N:	xilinx
drivers/i2c/busses/Kconfig +14 -0
index 275aaa7f3..014281fa2 100644
@@ -1322,6 +1322,20 @@ config I2C_XILINX
 	  This driver can also be built as a module.  If so, the module
 	  will be called xilinx_i2c.
 
+config I2C_XILINX_KUNIT_TEST
+	bool "KUnit tests for Xilinx I2C register accesses" if !KUNIT_ALL_TESTS
+	depends on I2C_XILINX && KUNIT=y
+	default KUNIT_ALL_TESTS
+	help
+	  Test the Xilinx I2C driver's register accessors with both byte orders
+	  and with native-width or forced 32-bit accesses. KUnit is a kernel
+	  unit testing framework. These tests use memory-backed registers and
+	  do not require an I2C controller.
+
+	  The tests are compiled into the driver to exercise its private
+	  accessors, and follow the driver's built-in or module configuration.
+	  If unsure, say N.
+
 config I2C_XLP9XX
 	tristate "Cavium ThunderX2 I2C support"
 	depends on ARCH_THUNDER2 || COMPILE_TEST
drivers/i2c/busses/i2c-xiic.c +4 -0
index 8425a540f..6c0f04aaa 100644
@@ -1650,3 +1650,7 @@ MODULE_ALIAS("platform:" DRIVER_NAME);
 MODULE_AUTHOR("[email protected]");
 MODULE_DESCRIPTION("Xilinx I2C bus driver");
 MODULE_LICENSE("GPL v2");
+
+#if IS_ENABLED(CONFIG_I2C_XILINX_KUNIT_TEST)
+#include "tests/i2c_xiic_kunit.c"
+#endif
drivers/i2c/busses/tests/i2c_xiic_kunit.c new file +91 -0

91 lines not on this page · raw message

#3 lore raw

Re: [PATCH net-next v2 2/3] i2c: xiic: add KUnit coverage for register access modes

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

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

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

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] The new KUnit test in drivers/i2c/busses/tests/i2c_xiic_kunit.c (xiic_register_access(),…

--

i2c: xiic: add KUnit coverage for register access modes

This commit adds a KUnit suite that runs the xiic driver's private xiic_setreg*() and xiic_getreg*() accessors against kmalloc-backed memory instead of MMIO. It covers both byte orders, with native-width and forced 32-bit access. The test file is included directly into i2c-xiic.c and is enabled by a new I2C_XILINX_KUNIT_TEST bool option that requires built-in KUnit.

Quoted 17 lines
drivers/i2c/busses/Kconfig +9 -0
index 275aaa7f35833..014281fa2be5c 100644
@@ -1322,6 +1322,20 @@ config I2C_XILINX
 	  This driver can also be built as a module.  If so, the module
 	  will be called xilinx_i2c.
 
+config I2C_XILINX_KUNIT_TEST
+	bool "KUnit tests for Xilinx I2C register accesses" if !KUNIT_ALL_TESTS
+	depends on I2C_XILINX && KUNIT=y
+	default KUNIT_ALL_TESTS
+	help
+	  Test the Xilinx I2C driver's register accessors with both byte orders
+	  and with native-width or forced 32-bit accesses. KUnit is a kernel
+	  unit testing framework. These tests use memory-backed registers and
+	  do not require an I2C controller.

[ ... ]

Quoted 5 lines
drivers/i2c/busses/tests/i2c_xiic_kunit.c new file +0 -0
new file mode 100644
index 0000000000000..b4c818d8bac78

[ ... ]

Quoted 2 lines
drivers/i2c/busses/tests/i2c_xiic_kunit.c new file +2 -0
+static void xiic_register_access(struct kunit *test)
+{

[ ... ]

drivers/i2c/busses/tests/i2c_xiic_kunit.c line 46

Quoted 6 lines
drivers/i2c/busses/tests/i2c_xiic_kunit.c new file +6 -0
+	i2c = kunit_kzalloc(test, sizeof(*i2c), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, i2c);
+	mem = kunit_kmalloc(test, 0x200, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, mem);
+	/* Aligned RAM stands in for MMIO. No hardware is accessed. */
+	i2c->base = (void __force __iomem *)(mem + sizeof(u32));

[Severity: Medium]
Is it safe to push kmalloc memory through ioread*() and iowrite*() here? xiic_setreg32(), xiic_getreg32() and the 8/16-bit helpers call iowrite32(), ioread32be() and similar directly on i2c->base. Those accessors are only required to work on cookies returned by ioremap() or pci_iomap().

On x86-64 this works, because the generic iomap code treats these addresses as plain MMIO. But I2C_XILINX_KUNIT_TEST only depends on I2C_XILINX && KUNIT=y and defaults to KUNIT_ALL_TESTS, and I2C_XILINX only needs HAS_IOMEM. As a result, the option can be enabled on architectures where RAM can't be accessed this way.

On UML, tools/testing/kunit/configs/arch_uml.config sets CONFIG_KUNIT_UML_PCI=y. That pulls in UML_PCI -> UML_IOMEM_EMULATION -> INDIRECT_IOMEM and enables HAS_IOMEM. The accessors then end up in lib/logic_iomem.c:

lib/logic_iomem.c:get_area() {
    ...
	if (WARN_ON((a & IOREMAP_MASK) != IOREMAP_BIAS))
		return NULL;
    ...
}

INDIRECT_IOMEM_FALLBACK is never selected, so the fallback real_raw_read*() and real_raw_write*() helpers WARN a second time, return ~0 and drop the writes.

Wouldn't that mean two WARNs per accessor call? Across 22 offsets and 4 parameters that is about 2100 WARNs per run. Every expectation would fail, and with panic_on_warn=1 the kernel would panic. A plain kunit.py run with --kconfig_add CONFIG_I2C_XILINX=y looks like it would hit this.

On s390 with PCI, __raw_readl() and __raw_writel() map to zpci_read_u32() and zpci_write_u32(). The test would then issue real zPCI load and store instructions on a heap address. Without MIO, the address is decoded as an iomap index plus a PCI offset:

arch/s390/pci/pci_insn.c:zpci_load_fh() {
    ...
	struct zpci_iomap_entry *entry = &zpci_iomap_start[ZPCI_IDX(addr)];
	u64 req = ZPCI_CREATE_REQ(READ_ONCE(entry->fh), entry->bar, len);
	return __zpci_load(data, req, ZPCI_OFFSET(addr));
}

Could this fail with zpci errors, or reach an unrelated function's BAR if an iomap entry happens to match?

On sparc64, __raw_readl() in arch/sparc/include/asm/io_64.h uses lduwa with ASI_PHYS_BYPASS_EC_E. That treats the kernel virtual pointer as a physical address and bypasses the caches.

Because of this, the "No hardware is accessed" comment, the "memory-backed registers" Kconfig help text and the changelog only hold on architectures like x86-64. The rest of the series doesn't seem to change this Kconfig entry or the test file.

There seem to be two ways to fix this. One is to restrict the option by architecture, for example depends on !UML && !S390 && !SPARC64, or an allow-list. The other is to route register access through a hook that the test can replace with a memory-backed implementation. With either one, the comment and help text should be updated to match.

Quoted 2 lines
drivers/i2c/busses/tests/i2c_xiic_kunit.c new file +2 -0
+	i2c->endianness = param->endianness;
+	i2c->force_32bit_access = param->force_32bit_access;

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112163333.12523-1-ahmadexp%40gmail.com
#4 lore raw

Re: [PATCH net-next v2 2/3] i2c: xiic: add KUnit coverage for register access modes

Agreed. A RAM buffer is not a portable MMIO mapping. The proposed v3 enables the RAM-backed test only on X86_64 with neither UML nor INDIRECT_IOMEM. The XIIC driver itself gains no architecture restriction. All four cases passed in an x86-64 QEMU guest. With XIIC and KUNIT_ALL_TESTS enabled, explicitly requesting the test on arm64, s390, SPARC64 and 64-bit UML with indirect I/O left it disabled.

pw-bot: cr

#5 lore raw

PATCH v2 3/3 ptp: ocp: support the WiWi revision 02 Time Card

In reply to Ahmad Byagowi

Match WiWi 2163:1008, subsystem 10ee:0007. NetTimeLogic uses the PCI Revision ID for incompatible interface changes. Revision 02 identifies the LitePCIe/MSI-X interface; the Xilinx subsystem ID and FPGA build number do not identify the register interface. Reject unknown revisions and check BAR0 and the MSI-X layout before accessing FPGA registers. Do not probe a CoreList or require exact versions of individual cores.

Report the full 32-bit image ID as the running firmware build. Derive signal and frequency capabilities from the supported revision, not the legacy FB build-number thresholds. Retain legacy version behavior on other cards.

Translate a copy of each peripheral resource by 0x02000000 and its interrupt input by 32. Use aligned 32-bit UART and XIIC register I/O. Leave GNSS2 unregistered: it is not wired on the tested production image. Do not change other cards' resource tables or access modes.

Open the UART, I2C and SPI inputs before probing children: SPI NOR identification can wait for an interrupt. Enable timing inputs after registering the PHC and its consumers. Keep unused inputs masked and leave child interrupts available through removal.

Reject WiWi devlink flash updates before looking up or modifying MTD. The flash header differs from Celestica and the vendor update path requires a modified spi-xilinx. Device recognition is not validation of an update path.

Thomas Schaub of NetTimeLogic described the production register layout and interrupt gate on 10 November 2026 and the PCI revision convention on 11 November.

On a revision 02 production card, devlink reported build 0x0000800f. The driver allocated 64 MSI-X vectors, registered the PHC, PPS and three UARTs, and exposed four generator and four frequency-counter groups. SPI NOR and both at24 devices bound. The PHC advanced 3.000441080 s over three one-second sleeps, with each delta inside the host monotonic bounds. PCIe AER counters did not change. The clock reported UNSYNCED at probe; the test did not establish PPS lock or UTC.

Tool-origin disclosure: Codex assisted with the driver changes, tests and changelog using the supplied hardware evidence and revision rule.

---
 Documentation/networking/devlink/ptp_ocp.rst |  36 +++-
 drivers/ptp/ptp_ocp.c                        | 163 ++++++++++++++++++-
 2 files changed, 190 insertions(+), 9 deletions(-)
Documentation/networking/devlink/ptp_ocp.rst +35 -1
index f94b759d9..2515dcccd 100644
@@ -54,7 +54,8 @@ selected with the component name.
      - Description
    * - (none)
      - The card's own flash, written through the SPI controller the driver
-       exposes.  The card runs the new image after its next reset.
+       exposes. Not supported on WiWi. The card runs the new image after
+       its next reset.
    * - ``fw.cpld``
      - The configuration flash of the TAP CPLD on ADVA TimeCard X1 boards,
        programmed over I2C with the MachXO3 in-system programming commands
@@ -73,3 +74,36 @@ with the standard devlink status notifications.
 Example::
 
     $ devlink dev flash pci/0000:02:00.0 file adva-cpld.bin component fw.cpld
+
+WiWi production firmware
+========================
+
+WiWi Time Cards with PCI ID ``2163:1008`` and subsystem ID ``10ee:0007``
+use the PCI Revision ID to identify the register interface. The driver
+supports revision ``02`` (LitePCIe/MSI-X) and rejects unknown revisions
+before accessing FPGA registers. Incompatible interface changes require
+a new revision. The driver also checks the BAR and MSI-X layout before
+initializing the card.
+
+The image ID at BAR0 offset ``0x02020000`` identifies a firmware build,
+not the register interface. The running ``fw`` version in devlink reports
+the full image ID, for example ``0x0000800f``. Compatible builds need not
+have the same image ID or individual core versions. PCIe access to the
+CoreList is not required.
+
+The image uses the Celestica LitePCIe production map: add ``0x02000000``
+to the peripheral offsets and use aligned 32-bit MMIO. Interrupt input
+``n`` uses MSI-X vector ``n + 32``. The per-input enable mask is at BAR0
+offset ``0x1800``. The driver enables the SPI interrupt before probing
+the flash and defers timing interrupts until the PHC is ready. GNSS2 is
+not wired to pins on the tested image; no second GNSS port is registered.
+The separate EEPROM and RGB I2C inputs (17 and 18) have no handlers in
+this driver and stay masked; these are distinct from its I2C input 7.
+
+WiWi firmware updates through ``devlink dev flash`` are not supported.
+The WiWi image has a different flash header from the Celestica image.
+The golden image at flash offset zero boots the update image via MultiBoot
+with watchdog fallback. The vendor's programming path requires a modified
+``spi-xilinx`` driver. Recognizing the SPI NOR does not validate that path
+or the image header. Successful clock registration does not establish
+GNSS synchronization or valid UTC.
drivers/ptp/ptp_ocp.c +155 -8

282 lines not on this page · raw message

#6 lore raw

Re: [PATCH net-next v2 3/3] ptp: ocp: support the WiWi revision 02 Time Card

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The patch blocks only one write path to WiWi flash.
- [Low] The submission says the PCI Revision ID alone defines the WiWi register interface ('the Xilinx subsystem ID and FPGA build number do…
- [Low] The patch defines WiWi identity three different ways.
- [Low] The generic 'fw' row in Documentation/networking/devlink/ptp_ocp.rst still says the running…
- [Low] In ptp_ocp_wiwi_validate(), the revision-rejection message uses "Unsupported WiWi PCI revision %#02x\n".
- [Low] The WiWi documentation says GNSS2 is not wired to pins, and ptp_ocp_register_resources() skips the GNSS2 UART on WiWi.
- [Low] ptp_ocp_i2c_bus() casts info->data to struct xiic_i2c_platform_data whenever bp->wiwi is true.

--

ptp: ocp: support the WiWi revision 02 Time Card

This adds support for the WiWi 2163:1008 Time Card (subsystem 10ee:0007), PCI revision 02. It reuses the FB resource table, adds 0x02000000 to the MMIO offsets and 32 to the interrupt inputs, and gates interrupts through a LiteX enable mask. It validates the revision, BAR0 and MSI-X layout, reports the full image ID through devlink, and rejects devlink flash updates on WiWi.

Quoted 4 lines
drivers/ptp/ptp_ocp.c +0 -0
index 625a85b2dc7e5..10ad2fbeb9675 100644

[ ... ]

drivers/ptp/ptp_ocp.c static struct ocp_resource ocp_adva_x1_resource[] = { · line 1350

Quoted 11 lines
drivers/ptp/ptp_ocp.c +7 -0
@@ -1321,6 +1341,13 @@ static struct ocp_resource ocp_adva_x1_resource[] = {
 static const struct pci_device_id ptp_ocp_pcidev_id[] = {
 	{ PCI_DEVICE_DATA(META, TIMECARD, &ocp_fb_resource) },
 	{ PCI_DEVICE_DATA(CELESTICA, TIMECARD, &ocp_fb_resource) },
+	{
+		PCI_DEVICE_SUB(PCI_VENDOR_ID_WIWI, PCI_DEVICE_ID_WIWI_TIMECARD,
+			       PCI_VENDOR_ID_XILINX, 0x0007),
+		.class = PCI_CLASS_MEMORY_OTHER << 8,
+		.class_mask = 0xffffff,
+		.driver_data = (kernel_ulong_t)ocp_fb_resource,
+	},

[Severity: Low]
The new documentation describes WiWi cards by PCI ID 2163:1008 and subsystem 10ee:0007, and says unknown revisions are rejected. This entry also requires class 0x058000 with a full class_mask, so prog-if must be 0 as well.

Is the extra class requirement intended? A card with the documented IDs but a different class code or prog-if never reaches ptp_ocp_probe(). It stays unbound and never logs "Unsupported WiWi PCI revision".

In the other direction, ptp_ocp_probe() sets:

	bp->wiwi = pdev->vendor == PCI_VENDOR_ID_WIWI &&
		   pdev->device == PCI_DEVICE_ID_WIWI_TIMECARD;

This ignores the subsystem and class that the table requires. Could both places use the same identity rule, for example by carrying a WiWi flag in driver_data? Otherwise a device bound through new_id gets WiWi handling without matching this entry.

[ ... ]

drivers/ptp/ptp_ocp.c ptp_ocp_devlink_flash_update(struct devlink *devlink, · line 2208

Quoted 10 lines
drivers/ptp/ptp_ocp.c +6 -0
@@ -2173,6 +2200,12 @@ ptp_ocp_devlink_flash_update(struct devlink *devlink,
 	const char *msg;
 	int err;
 
+	if (bp->wiwi) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "WiWi flash updates are not supported");
+		return -EOPNOTSUPP;
+	}
+

[Severity: Low]
This rejects devlink flash on WiWi. The commit message says "Device recognition is not validation of an update path". Can the same flash still be written through raw MTD?

ptp_ocp_register_resources() still registers the ocp_fb_resource spi_flash entry on WiWi. Its IRQ moves to input 9 + 32 and is unmasked before the children probe. The board info for that entry is only:

	.devices = &(struct spi_board_info) {
		.modalias = "spi-nor",
	},

It has no partitions and no read-only marking. So spi-nor registers one writable MTD device that covers the whole flash, including the golden image at offset zero. The commit message confirms "SPI NOR ... bound".

Writes through /dev/mtdN (flashcp, mtd_debug, existing Time Card update scripts) then go through the stock spi-xilinx driver. The new documentation says the vendor's programming path needs a modified spi-xilinx.

Could a privileged user erase the golden fallback image this way? Should the flash be registered read-only on WiWi, or should this exposure at least be documented next to the devlink restriction?

[ ... ]

Quoted 8 lines
drivers/ptp/ptp_ocp.c +2 -1
@@ -2331,20 +2367,29 @@ ptp_ocp_register_spi(struct ptp_ocp *bp, struct ocp_resource *r)
 }
 
 static struct platform_device *
-ptp_ocp_i2c_bus(struct pci_dev *pdev, struct ocp_resource *r, int id)
+ptp_ocp_i2c_bus(struct ptp_ocp *bp, struct ocp_resource *r, int id)
 {
+	struct xiic_i2c_platform_data wiwi_data;

[ ... ]

Quoted 6 lines
drivers/ptp/ptp_ocp.c +5 -0
 	info = r->extra;
+	data = info->data;
+	if (bp->wiwi) {
+		wiwi_data = *(struct xiic_i2c_platform_data *)info->data;
+		wiwi_data.force_32bit_access = true;
+		data = &wiwi_data;

drivers/ptp/ptp_ocp.c ptp_ocp_register_spi(struct ptp_ocp *bp, struct ocp_resource *r) · line 2393

Quoted 10 lines
drivers/ptp/ptp_ocp.c +2 -1
+	}
 	start = pci_resource_start(pdev, 0) + r->offset;
 	res[0] = DEFINE_RES_MEM(start, r->size);
 	res[1] = DEFINE_RES_IRQ(pci_irq_vector(pdev, r->irq_vec));
 
 	return platform_device_register_resndata(&pdev->dev, info->name,
 						 id, res, ARRAY_SIZE(res),
-						 info->data, info->data_size);
+						 data, info->data_size);
 }

[Severity: Low]
Whenever bp->wiwi is set, this casts info->data to struct xiic_i2c_platform_data without checking that the resource is an xiic controller. platform_device_register_resndata() then copies info->data_size bytes from the stack copy.

ptp_ocp_probe() sets bp->wiwi from vendor and device only, not from id->driver_data. The static table always pairs WiWi with ocp_fb_resource (xiic-i2c). However, new_id_store() accepts any driver_data that matches an existing table entry, such as ocp_adva_resource or ocp_art_resource. Their i2c entries are "ocores-i2c", with data_size set to sizeof(struct ocores_i2c_platform_data), which is 32 bytes on 64-bit.

Suppose a revision 02 WiWi card is bound that way. Would this overwrite the ocores big_endian field with force_32bit_access? Would kmemdup() then read 32 bytes from the 24-byte wiwi_data on the stack? The extra 8 bytes would become the ocores devices pointer, which i2c-ocores dereferences.

This needs root and a dynamic ID. Could the override check info->data_size == sizeof(wiwi_data) or the xiic name first, or could the WiWi flag come from driver_data?

[ ... ]

Quoted 4 lines
drivers/ptp/ptp_ocp.c +0 -0
@@ -3036,6 +3081,13 @@ ptp_ocp_fb_set_version(struct ptp_ocp *bp)
 
 	version = ioread32(&bp->image->version);
 

drivers/ptp/ptp_ocp.c ptp_ocp_fb_set_version(struct ptp_ocp *bp) · line 3093

Quoted 10 lines
drivers/ptp/ptp_ocp.c +7 -0
+	if (bp->wiwi) {
+		/* Revision 02 defines capabilities; report the build ID. */
+		bp->wiwi_image_id = version;
+		bp->fw_cap = OCP_CAP_BASIC | OCP_CAP_SIGNAL | OCP_CAP_FREQ;
+		return;
+	}
+
 	/* if lower 16 bits are empty, this is the fw loader. */
 	if ((version & 0xffff) == 0) {
 		version = version >> 16;

[Severity: Low]
This early return skips the loader check below it. As a result, bp->fw_loader is never set on WiWi, and ptp_ocp_devlink_info_get() always picks "fw":

	fw_image = bp->fw_loader ? "loader" : "fw";

The fw row in Documentation/networking/devlink/ptp_ocp.rst still says the version is reported as "loader" when the card runs the firmware loader. It has no WiWi exception.

The new WiWi section describes a golden image at flash offset zero with MultiBoot and watchdog fallback. If the card is running that fallback image, would devlink report it as normal running "fw"? Should the documentation say how that state is reported on WiWi, or should the generic row note the exception?

[ ... ]

Quoted 5 lines
drivers/ptp/ptp_ocp.c +0 -1
@@ -3109,7 +3160,26 @@ ptp_ocp_register_resources(struct ptp_ocp *bp, kernel_ulong_t driver_data)
 	int err = 0;
 
 	table = (struct ocp_resource *)driver_data;
-	for (r = table; r->setup; r++) {

drivers/ptp/ptp_ocp.c ptp_ocp_register_resources(struct ptp_ocp *bp, kernel_ulong_t driver_data) · line 3172

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+	for (; table->setup; table++) {
+		struct ocp_resource translated = *table;
+
+		r = table;
+		if (bp->wiwi) {
+			/* GNSS2 is instantiated but not routed to FPGA pins. */
+			if (r->setup == ptp_ocp_register_serial &&
+			    r->bp_offset == offsetof(struct ptp_ocp,
+						    port[PORT_GNSS2]))
+				continue;

[Severity: Low]
The commit message says the PCI revision alone identifies the register interface, and that "the Xilinx subsystem ID and FPGA build number do not identify the register interface".

This skip applies to every revision 02 device. The only reason given is "it is not wired on the tested production image", which is a single build (0x0000800f).

If GNSS2 routing can differ between revision 02 builds, would a build that does route it lose the GNSS2 tty without any log message or override? If GNSS2 is never routed on revision 02, could the commit message and documentation say so, instead of referring to the tested image?

[Severity: Low]
Only the GNSS2 UART is suppressed here. WiWi still uses ocp_fb_sma_op with the shared ptp_ocp_sma_out table, which offers this as a selectable SMA output source through sysfs and DPLL:

	{ .name = "GNSS2",	.value = 0x0008,  .frequency = 1 },

The debugfs summary also still decodes the MAC PPS2 source against it:

	gpio_input_map(buf, bp, sma_val, 1, "GNSS2");

The new documentation says GNSS2 "is not wired to pins". Can userspace on WiWi select an SMA output source that has nothing behind it? Should GNSS2 also be removed from the WiWi SMA output choices?

[ ... ]

Quoted 1 line
drivers/ptp/ptp_ocp.c +0 -0
@@ -5951,6 +6027,49 @@ ptp_ocp_sync_work(struct work_struct *work)

[ ... ]

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

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+/* The PCI revision identifies the register interface, not the FPGA build. */
+static int ptp_ocp_wiwi_validate(struct pci_dev *pdev)
+{
+	u32 table, pba;
+	int cap;
+
+	if (pdev->revision != 0x02)
+		return dev_err_probe(&pdev->dev, -ENODEV,
+				     "Unsupported WiWi PCI revision %#02x\n",
+				     pdev->revision);

[Severity: Low]
Was "%#04x" or "0x%02x" intended here? With the # flag, the 0x prefix counts toward the field width, so a width of 2 never pads. Revision 0x01 prints as 0x1, which differs from the two-digit form (02) used in the documentation.

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112163333.12523-1-ahmadexp%40gmail.com
#7 lore raw

Re: [PATCH net-next v2 3/3] ptp: ocp: support the WiWi revision 02 Time Card

Thanks for catching the second path to the flash. Blocking devlink alone was not enough. In the proposed v3, ptp_ocp does not register the WiWi SPI controller or enable its interrupt. That means no spi-nor or raw MTD for this card through ptp_ocp, including no MTD reads. Devlink continues to reject the operation. The existing boards retain their flash devices.

The static board match is 2163:1008, subsystem 10ee:0007. The class and programming interface are not part of that match. Probe resolves WiWi against the static table, so a dynamic ID cannot select a different resource layout. PCI revision 02 identifies the register interface; we still validate BAR and MSI-X geometry before touching the FPGA. The WiWi XIIC child now has typed platform data and its own matching size. No cast of another controller's data or stack copy is involved.

I cannot infer GNSS2 wiring from the PCI revision. The proposed driver therefore exposes neither a second UART nor a GNSS2 SMA output on this board. It no longer prints GNSS2 as a fallback MAC PPS2 source. The independent external SMA PPS2 input is still selectable. This is a supported-feature policy, not a statement about untested builds.

I also clarified that devlink reports the build ID as fw and does not distinguish an active image from a fallback boot. Unknown revisions are logged with two hex digits. The revised objects compile and the board/flash policy checks pass; this revision has not been run on the card.

v3:
https://lore.kernel.org/r/[email protected]