* [PATCH net-next v3 0/3] ptp: ocp: support the WiWi production Time Card
@ 2026-11-16 18:20 Ahmad Byagowi
2026-11-16 18:20 ` [PATCH net-next v3 1/3] i2c: xiic: allow platforms to require 32-bit register accesses Ahmad Byagowi
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Ahmad Byagowi @ 2026-11-16 18:20 UTC (permalink / raw)
To: netdev, vadim.fedorenko, andi.shyti
Cc: andrew+netdev, corbet, davem, edumazet, horms, jiri, kuba,
linux-arm-kernel, linux-doc, linux-i2c, linux-kernel,
michal.simek, pabeni, rdunlap, richardcochran, skhan
The WiWi Time Card (2163:1008, subsystem 10ee:0007) presents its timing
peripherals behind a LitePCIe interface that requires aligned word MMIO.
Add an opt-in access mode for XIIC, test both access modes, and support
the revision 02 PCI interface in ptp_ocp. Patch 3 consumes patch 1.
Could the I2C maintainers review patches 1 and 2 for an Ack to take
them through net-next?
Changes since v2:
- 1/3: Identify patch 3's WiWi XIIC child as the first user.
- 2/3: Restrict the RAM-backed test to direct x86-64 MMIO. Exclude
UML and indirect I/O; do not restrict the driver.
- 3/3: Match the board by its PCI IDs, validate revision and geometry
separately, and select typed XIIC data from the static board match.
Do not expose the SPI flash through MTD or devlink. Omit unsupported
GNSS2 interfaces, preserve external PPS2, and clarify firmware build
reporting. Refuse timing enables until the interrupt gate is open.
Distinguish WiWi's PCI interface from legacy Celestica.
The driver objects build for x86-64 allmodconfig with W=1. All four
XIIC KUnit cases passed on x86-64 QEMU with the same two I2C patches.
An earlier revision of the driver on a revision 02 card confirmed
64 MSI-X vectors and an advancing PHC. The new board policy and timing
guard have not been run on that card. No claim of PPS lock, UTC accuracy
or masked-event replay is made.
Codex assisted with implementation, tests and changelogs using the
board evidence, vendor revision rule and mailing-list feedback.
v2: https://lore.kernel.org/netdev/20261112163333.12523-1-ahmadexp@gmail.com/
v1: https://lore.kernel.org/netdev/20261111041904.48916-1-ahmadexp@gmail.com/
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 | 47 +++-
MAINTAINERS | 1 +
drivers/i2c/busses/Kconfig | 15 ++
drivers/i2c/busses/i2c-xiic.c | 60 +++--
drivers/i2c/busses/tests/i2c_xiic_kunit.c | 91 +++++++
drivers/ptp/ptp_ocp.c | 242 +++++++++++++++++--
include/linux/platform_data/i2c-xiic.h | 3 +
7 files changed, 422 insertions(+), 37 deletions(-)
create mode 100644 drivers/i2c/busses/tests/i2c_xiic_kunit.c
base-commit: 6964ff21c5d8b75649211a52dbfd92753e605649
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH net-next v3 1/3] i2c: xiic: allow platforms to require 32-bit register accesses 2026-11-16 18:20 [PATCH net-next v3 0/3] ptp: ocp: support the WiWi production Time Card Ahmad Byagowi @ 2026-11-16 18:20 ` Ahmad Byagowi 2026-11-18 18:22 ` netdev-bot+sashiko 2026-11-16 18:20 ` [PATCH net-next v3 2/3] i2c: xiic: add KUnit coverage for register access modes Ahmad Byagowi 2026-11-16 18:20 ` [PATCH net-next v3 3/3] ptp: ocp: support the WiWi revision 02 Time Card Ahmad Byagowi 2 siblings, 1 reply; 10+ messages in thread From: Ahmad Byagowi @ 2026-11-16 18:20 UTC (permalink / raw) To: netdev, vadim.fedorenko, andi.shyti Cc: linux-arm-kernel, linux-i2c, linux-kernel, michal.simek, richardcochran 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. The WiWi ptp_ocp change later in this series is the first user: it sets the flag in the platform data for the card's XIIC child. 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. Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com> --- drivers/i2c/busses/i2c-xiic.c | 56 +++++++++++++++++--------- include/linux/platform_data/i2c-xiic.h | 3 ++ 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index ab7916745..edb5e271c 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -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); diff --git a/include/linux/platform_data/i2c-xiic.h b/include/linux/platform_data/i2c-xiic.h index 2e3683c23..afad9a49c 100644 --- a/include/linux/platform_data/i2c-xiic.h +++ b/include/linux/platform_data/i2c-xiic.h @@ -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 */ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v3 1/3] i2c: xiic: allow platforms to require 32-bit register accesses 2026-11-16 18:20 ` [PATCH net-next v3 1/3] i2c: xiic: allow platforms to require 32-bit register accesses Ahmad Byagowi @ 2026-11-18 18:22 ` netdev-bot+sashiko 2026-11-18 20:05 ` Ahmad Byagowi 0 siblings, 1 reply; 10+ messages in thread From: netdev-bot+sashiko @ 2026-11-18 18:22 UTC (permalink / raw) To: ahmadexp Cc: netdev, vadim.fedorenko, andi.shyti, andrew+netdev, corbet, davem, edumazet, horms, jiri, kuba, linux-doc, linux-i2c, linux-kernel, pabeni, rdunlap, richardcochran, skhan 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] In drivers/i2c/busses/i2c-xiic.c, this patch extends the block comment above the register accessors (lines 281-290), but the… -- i2c: xiic: allow platforms to require 32-bit register accesses This patch adds a force_32bit_access flag to the xiic platform data. When the flag is set, the byte and halfword register accessors issue aligned 32-bit accesses, still in the detected endianness. The first user is the WiWi Time Card, whose LitePCIe bridge cannot handle subword MMIO. > diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c > index ab7916745ad39..edb5e271c8cde 100644 > --- a/drivers/i2c/busses/i2c-xiic.c > +++ b/drivers/i2c/busses/i2c-xiic.c [ ... ] > @@ -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. > */ [Severity: Low] This isn't a bug, but the first sentence of this comment now contradicts the new mode. It still says only the least significant byte [doublet] is "ever accessed", using a +3 [+2] offset on big-endian. When i2c->force_32bit_access is set, xiic_setreg8() and xiic_setreg16() zero-extend the value and write the whole 32-bit register at the base offset, with no +3/+2 adjustment: if (i2c->force_32bit_access) { xiic_setreg32(i2c, reg, value); return; } In the same mode, xiic_getreg8() reads the full register through xiic_getreg32() and truncates the result. Could the first sentence be changed so it only describes the default accessors? The comment also doesn't say what the new mode relies on. The registers written through xiic_setreg8() and xiic_setreg16() (XIIC_CR_REG_OFFSET, XIIC_RFD_REG_OFFSET, XIIC_DTR_REG_OFFSET) now get zeros in their upper bits. Should the comment note that those upper bits must be reserved or ignored on write? [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-wiwi-v3-87afa10a8-0-ahmadexp%40gmail.com ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v3 1/3] i2c: xiic: allow platforms to require 32-bit register accesses 2026-11-18 18:22 ` netdev-bot+sashiko @ 2026-11-18 20:05 ` Ahmad Byagowi 0 siblings, 0 replies; 10+ messages in thread From: Ahmad Byagowi @ 2026-11-18 20:05 UTC (permalink / raw) To: netdev-bot+sashiko Cc: andi.shyti, andrew+netdev, corbet, davem, edumazet, horms, jiri, kuba, linux-doc, linux-i2c, linux-kernel, netdev, pabeni, rdunlap, richardcochran, skhan, vadim.fedorenko Thanks. I have clarified the comment in the v4 draft: the subword offsets describe the default access mode, not the forced-word mode. The latter requires unused upper bits in CR, RFD and DTR to accept zero on writes. It still performs one transaction, without read-modify-write, for FIFO accesses. Patch 3 remains the first user of this flag. Other platforms keep their existing access mode. The revised objects and accessor tests pass; this revision has not been tested on the physical card. ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next v3 2/3] i2c: xiic: add KUnit coverage for register access modes 2026-11-16 18:20 [PATCH net-next v3 0/3] ptp: ocp: support the WiWi production Time Card Ahmad Byagowi 2026-11-16 18:20 ` [PATCH net-next v3 1/3] i2c: xiic: allow platforms to require 32-bit register accesses Ahmad Byagowi @ 2026-11-16 18:20 ` Ahmad Byagowi 2026-11-18 18:22 ` netdev-bot+sashiko 2026-11-16 18:20 ` [PATCH net-next v3 3/3] ptp: ocp: support the WiWi revision 02 Time Card Ahmad Byagowi 2 siblings, 1 reply; 10+ messages in thread From: Ahmad Byagowi @ 2026-11-16 18:20 UTC (permalink / raw) To: netdev, vadim.fedorenko, andi.shyti Cc: linux-arm-kernel, linux-i2c, linux-kernel, michal.simek 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. An allocated RAM address is not a portable I/O cookie. Limit the test to the direct x86-64 MMIO implementation, which uses ordinary memory loads and stores at these addresses. Exclude UML (which can also set X86_64) and indirect I/O. KUNIT_ALL_TESTS cannot enable the suite on other architectures. This restriction does not apply to the driver. 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. Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com> --- MAINTAINERS | 1 + drivers/i2c/busses/Kconfig | 15 ++++ drivers/i2c/busses/i2c-xiic.c | 4 + drivers/i2c/busses/tests/i2c_xiic_kunit.c | 91 +++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 drivers/i2c/busses/tests/i2c_xiic_kunit.c diff --git a/MAINTAINERS b/MAINTAINERS index 0cf311e6c..4588569e7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -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 diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 275aaa7f3..0a7a2aeb7 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -1322,6 +1322,21 @@ 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 + depends on X86_64 && !UML && !INDIRECT_IOMEM + 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. The tests use + allocated RAM in place of registers. This relies on the direct + x86-64 MMIO accessor implementation; no controller is required. + + 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 diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index edb5e271c..7e2ed61c6 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -1650,3 +1650,7 @@ MODULE_ALIAS("platform:" DRIVER_NAME); MODULE_AUTHOR("info@mocean-labs.com"); 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 diff --git a/drivers/i2c/busses/tests/i2c_xiic_kunit.c b/drivers/i2c/busses/tests/i2c_xiic_kunit.c new file mode 100644 index 000000000..1b691de7e --- /dev/null +++ b/drivers/i2c/busses/tests/i2c_xiic_kunit.c @@ -0,0 +1,91 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Included by i2c-xiic.c to exercise the driver's private accessors. */ +#include <kunit/test.h> + +struct xiic_access_param { + const char *name; + enum xiic_endian endianness; + bool force_32bit_access; +}; + +static const struct xiic_access_param xiic_access_params[] = { + { "native_little_endian", LITTLE, false }, + { "native_big_endian", BIG, false }, + { "word_little_endian", LITTLE, true }, + { "word_big_endian", BIG, true }, +}; + +KUNIT_ARRAY_PARAM_DESC(xiic_access, xiic_access_params, name); + +static void xiic_register_access(struct kunit *test) +{ + static const int offsets[] = { + XIIC_DGIER_OFFSET, XIIC_IISR_OFFSET, XIIC_IIER_OFFSET, + XIIC_RESETR_OFFSET, XIIC_CR_REG_OFFSET, XIIC_SR_REG_OFFSET, + XIIC_DTR_REG_OFFSET, XIIC_DRR_REG_OFFSET, XIIC_ADR_REG_OFFSET, + XIIC_TFO_REG_OFFSET, XIIC_RFO_REG_OFFSET, XIIC_TBA_REG_OFFSET, + XIIC_RFD_REG_OFFSET, XIIC_GPO_REG_OFFSET, + XIIC_TSUSTA_REG_OFFSET, XIIC_TSUSTO_REG_OFFSET, + XIIC_THDSTA_REG_OFFSET, + XIIC_TSUDAT_REG_OFFSET, XIIC_TBUF_REG_OFFSET, + XIIC_THIGH_REG_OFFSET, XIIC_TLOW_REG_OFFSET, + XIIC_THDDAT_REG_OFFSET, + }; + const struct xiic_access_param *param = test->param_value; + struct xiic_i2c *i2c; + u32 expected; + u8 *mem; + size_t i; + int reg; + + 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); + /* Only built for direct x86-64 MMIO, which accepts this RAM address. */ + i2c->base = (void __force __iomem *)(mem + sizeof(u32)); + i2c->endianness = param->endianness; + i2c->force_32bit_access = param->force_32bit_access; + + for (i = 0; i < ARRAY_SIZE(offsets); i++) { + reg = offsets[i]; + memset(mem, 0xa5, 0x200); + + xiic_setreg8(i2c, reg, 0xc0); + expected = param->force_32bit_access ? 0xc0 : 0xa5a5a5c0; + KUNIT_EXPECT_EQ(test, (u32)xiic_getreg32(i2c, reg), expected); + KUNIT_EXPECT_EQ(test, xiic_getreg8(i2c, reg), (u8)0xc0); + + xiic_setreg16(i2c, reg, 0x03ff); + expected = param->force_32bit_access ? 0x03ff : 0xa5a503ff; + KUNIT_EXPECT_EQ(test, (u32)xiic_getreg32(i2c, reg), expected); + KUNIT_EXPECT_EQ(test, xiic_getreg8(i2c, reg), (u8)0xff); + + xiic_setreg32(i2c, reg, 0x12345678); + KUNIT_EXPECT_EQ(test, (u32)xiic_getreg32(i2c, reg), + 0x12345678U); + KUNIT_EXPECT_EQ(test, xiic_getreg8(i2c, reg), (u8)0x78); + KUNIT_EXPECT_EQ(test, mem[reg + sizeof(u32)], + (u8)(param->endianness == BIG ? 0x12 : 0x78)); + KUNIT_EXPECT_EQ(test, mem[reg + sizeof(u32) + 3], + (u8)(param->endianness == BIG ? 0x78 : 0x12)); + xiic_setreg32(i2c, reg, 0x89abcdefU); + KUNIT_EXPECT_EQ(test, (u32)xiic_getreg32(i2c, reg), + 0x89abcdefU); + KUNIT_EXPECT_EQ(test, xiic_getreg8(i2c, reg), (u8)0xef); + KUNIT_EXPECT_EQ(test, mem[reg + sizeof(u32) - 1], (u8)0xa5); + KUNIT_EXPECT_EQ(test, mem[reg + 2 * sizeof(u32)], (u8)0xa5); + } +} + +static struct kunit_case xiic_access_test_cases[] = { + KUNIT_CASE_PARAM(xiic_register_access, xiic_access_gen_params), + {} +}; + +static struct kunit_suite xiic_access_test_suite = { + .name = "i2c_xiic", + .test_cases = xiic_access_test_cases, +}; + +kunit_test_suite(xiic_access_test_suite); ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v3 2/3] i2c: xiic: add KUnit coverage for register access modes 2026-11-16 18:20 ` [PATCH net-next v3 2/3] i2c: xiic: add KUnit coverage for register access modes Ahmad Byagowi @ 2026-11-18 18:22 ` netdev-bot+sashiko 2026-11-18 20:05 ` Ahmad Byagowi 0 siblings, 1 reply; 10+ messages in thread From: netdev-bot+sashiko @ 2026-11-18 18:22 UTC (permalink / raw) To: ahmadexp Cc: netdev, vadim.fedorenko, andi.shyti, andrew+netdev, corbet, davem, edumazet, horms, jiri, kuba, linux-doc, linux-i2c, linux-kernel, pabeni, rdunlap, richardcochran, skhan 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 new KUnit suite cannot catch a regression in the forced 32-bit read path of xiic_getreg8(). -- i2c: xiic: add KUnit coverage for register access modes This adds a KUnit suite that is compiled into i2c-xiic.c and tests the driver's private register accessors against RAM-backed registers. It covers native and forced 32-bit accesses in both byte orders across 22 register offsets. It only builds on direct x86-64 MMIO. > diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig > index 275aaa7f35833..0a7a2aeb78909 100644 > --- a/drivers/i2c/busses/Kconfig > +++ b/drivers/i2c/busses/Kconfig > @@ -1322,6 +1322,21 @@ config I2C_XILINX [ ... ] > +config I2C_XILINX_KUNIT_TEST > + bool "KUnit tests for Xilinx I2C register accesses" if !KUNIT_ALL_TESTS > + depends on I2C_XILINX && KUNIT=y > + depends on X86_64 && !UML && !INDIRECT_IOMEM > + 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. The tests use > + allocated RAM in place of registers. This relies on the direct > + x86-64 MMIO accessor implementation; no controller is required. [ ... ] > diff --git a/drivers/i2c/busses/tests/i2c_xiic_kunit.c b/drivers/i2c/busses/tests/i2c_xiic_kunit.c > new file mode 100644 > index 0000000000000..1b691de7e9250 > --- /dev/null > +++ b/drivers/i2c/busses/tests/i2c_xiic_kunit.c > @@ -0,0 +1,91 @@ [ ... ] > + for (i = 0; i < ARRAY_SIZE(offsets); i++) { > + reg = offsets[i]; > + memset(mem, 0xa5, 0x200); > + > + xiic_setreg8(i2c, reg, 0xc0); > + expected = param->force_32bit_access ? 0xc0 : 0xa5a5a5c0; > + KUNIT_EXPECT_EQ(test, (u32)xiic_getreg32(i2c, reg), expected); > + KUNIT_EXPECT_EQ(test, xiic_getreg8(i2c, reg), (u8)0xc0); [Severity: Low] Would this check, or any of the other xiic_getreg8() checks in xiic_register_access(), catch a regression in the forced 32-bit read path? In xiic_getreg8(), the forced path is: if (i2c->force_32bit_access) return xiic_getreg32(i2c, reg); Without it, the function does ioread8(base + reg) for LITTLE and ioread8(base + reg + 3) for BIG. In the word_little_endian and word_big_endian cases, every value is first stored as a zero-extended 32-bit word. With RAM-backed registers, the byte at reg + 0 (LE) or reg + 3 (BE) is always the low byte of that word. The native 8-bit read and the truncated 32-bit read therefore return the same value (0xc0, 0xff, 0x78, 0xef). So it looks like the force_32bit_access branch could be removed from xiic_getreg8() and all four parameterized cases would still pass. The write side is covered, because the upper bytes (0xc0 vs 0xa5a5a5c0) would catch a subword store. The read side is the one behind the machine check from ioread8() in xiic_clear_rx_fifo(). That machine check is what motivated "i2c: xiic: allow platforms to require 32-bit register accesses". The changelog says "These tests do not validate physical bus transaction widths". The Kconfig help text above, however, says the accessors are tested "with native-width or forced 32-bit accesses", and does not mention that read width can't be observed. Could that limit be documented in the Kconfig help or in a test comment? Alternatively, the accessor could be instrumented so the read width can be checked. -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-wiwi-v3-87afa10a8-0-ahmadexp%40gmail.com ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v3 2/3] i2c: xiic: add KUnit coverage for register access modes 2026-11-18 18:22 ` netdev-bot+sashiko @ 2026-11-18 20:05 ` Ahmad Byagowi 0 siblings, 0 replies; 10+ messages in thread From: Ahmad Byagowi @ 2026-11-18 20:05 UTC (permalink / raw) To: netdev-bot+sashiko Cc: andi.shyti, andrew+netdev, corbet, davem, edumazet, horms, jiri, kuba, linux-doc, linux-i2c, linux-kernel, netdev, pabeni, rdunlap, richardcochran, skhan, vadim.fedorenko Agreed. RAM cannot distinguish a byte read from a truncated word read returning the same value. I have stated that explicitly in the Kconfig help and test comment, and retained the direct-x86-64 restriction. All four KUnit cases pass in x86-64 QEMU. Separately, the source-derived accessor fixture records which I/O accessor was called, including its width and address. Removing the forced-word read branch makes that fixture fail. This is software accessor coverage, not a measurement of PCIe transaction widths, and I have not added runtime indirection to the driver just for testing. ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next v3 3/3] ptp: ocp: support the WiWi revision 02 Time Card 2026-11-16 18:20 [PATCH net-next v3 0/3] ptp: ocp: support the WiWi production Time Card Ahmad Byagowi 2026-11-16 18:20 ` [PATCH net-next v3 1/3] i2c: xiic: allow platforms to require 32-bit register accesses Ahmad Byagowi 2026-11-16 18:20 ` [PATCH net-next v3 2/3] i2c: xiic: add KUnit coverage for register access modes Ahmad Byagowi @ 2026-11-16 18:20 ` Ahmad Byagowi 2026-11-18 18:22 ` netdev-bot+sashiko 2 siblings, 1 reply; 10+ messages in thread From: Ahmad Byagowi @ 2026-11-16 18:20 UTC (permalink / raw) To: netdev, vadim.fedorenko, andi.shyti Cc: andrew+netdev, corbet, davem, edumazet, horms, jiri, kuba, linux-doc, linux-i2c, linux-kernel, pabeni, rdunlap, richardcochran, skhan Match WiWi 2163:1008, subsystem 10ee:0007, without a class filter. Resolve WiWi devices against the static PCI table so a dynamic ID cannot substitute an unrelated resource layout. 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. This ID does not identify the boot slot. Retain legacy version reporting on other cards. WiWi shares the peripheral resource table used by the existing Celestica entry (18d4:1008), not its PCI addressing and interrupt scheme. For WiWi only, translate peripheral offsets by 0x02000000 and interrupt inputs by 32. Use aligned 32-bit UART I/O and typed XIIC platform data, sharing the EEPROM list but not casting another controller's data. Do not expose an unvalidated second GNSS UART or PPS output source. Keep the external SMA PPS2 input. The PCI revision identifies the host interface, not optional board wiring. Use hardware selector values for WiWi DPLL routing; preserve the existing behavior on other boards. Enable the three UART and XIIC inputs during probe. Reject attempts to arm a timestamper or generator with -EAGAIN until the timing gate write has been flushed. This avoids relying on FPGA replay of a pulse caused by a userspace request made while the gate was closed. Do not register the WiWi SPI flash controller or enable its interrupt. This prevents the driver from exposing raw MTD access to the golden image. Reject devlink flash as well. The update format and controller support are not validated; read access via MTD is intentionally lost. Thomas Schaub of NetTimeLogic described the production register layout and interrupt gate on 10 November 2026 and the PCI revision convention on 11 November. An earlier driver on revision 02, build 0x0000800f, registered 64 MSI-X vectors, the PHC and three UARTs; both at24 devices bound and the PHC advanced. That run did not test this revision's flash policy, GNSS2 routing policy or interrupt-readiness guard. No PPS lock, UTC accuracy or replay of masked events is claimed. Tool-origin disclosure: Codex assisted with the driver changes, tests and changelog using the hardware evidence, revision rule and netdev review. Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com> --- Documentation/networking/devlink/ptp_ocp.rst | 47 +++- drivers/ptp/ptp_ocp.c | 242 +++++++++++++++++-- 2 files changed, 270 insertions(+), 19 deletions(-) diff --git a/Documentation/networking/devlink/ptp_ocp.rst b/Documentation/networking/devlink/ptp_ocp.rst index f94b759d9..f7e228570 100644 --- a/Documentation/networking/devlink/ptp_ocp.rst +++ b/Documentation/networking/devlink/ptp_ocp.rst @@ -20,8 +20,10 @@ The ``ptp_ocp`` driver reports the following versions - Description * - ``fw`` - running - - Version of the firmware running on the card. Reported as ``loader`` - instead when the card is running the firmware loader. + - Version of the firmware running on the card. Where the driver can + distinguish a firmware loader, it reports ``loader`` instead. + WiWi reports the raw build ID as ``fw``; it does not identify the + boot slot or distinguish a fallback boot. * - ``board.id`` - fixed - Board identifier, read from the on-card EEPROM. @@ -54,7 +56,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 +76,41 @@ 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. + +WiWi reuses the peripheral layout described by the driver's shared +resource table. Its PCI interface is distinct from that of the existing +Celestica entry (``18d4:1008``). Only the WiWi match adds ``0x02000000`` +to peripheral offsets and requires aligned 32-bit MMIO. Interrupt input +``n`` uses MSI-X vector ``n + 32``. The per-input enable mask is at BAR0 +offset ``0x1800``. Until the timing gate is open, attempts to arm a +timestamp, PPS or signal generator return ``-EAGAIN`` and can be retried. +The driver exposes neither a second GNSS serial port nor a GNSS2 SMA +output source on this board. Neither is a supported capability inferred +from revision 02. This does not disable the external SMA PPS2 input. +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. + +The driver does not register the WiWi SPI flash controller, so there is +no raw MTD device for this flash, even for reads. Its IRQ remains masked. +WiWi firmware updates through ``devlink dev flash`` are also rejected. +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. Successful clock registration does not establish +GNSS synchronization or valid UTC. diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c index decc56892..df40dac98 100644 --- a/drivers/ptp/ptp_ocp.c +++ b/drivers/ptp/ptp_ocp.c @@ -35,6 +35,22 @@ #define PCI_VENDOR_ID_CELESTICA 0x18d4 #define PCI_DEVICE_ID_CELESTICA_TIMECARD 0x1008 +#define PCI_VENDOR_ID_WIWI 0x2163 +#define PCI_DEVICE_ID_WIWI_TIMECARD 0x1008 + +/* WiWi rev 02 translates shared peripheral offsets and interrupt inputs. */ +#define OCP_WIWI_MMIO_OFFSET 0x02000000 +#define OCP_WIWI_IRQ_OFFSET 32 +#define OCP_WIWI_MSI_ENABLE 0x1800 +/* Upper 32 bits: the three UARTs and XIIC can interrupt during probe. */ +#define OCP_WIWI_PERIPHERAL_IRQS (BIT(3) | BIT(5) | BIT(7) | BIT(10)) +/* PPS/TS0/TS1, TS2, GEN1-4 and TS3/TS4. */ +#define OCP_WIWI_TIMING_IRQS (GENMASK(2, 0) | BIT(6) | \ + GENMASK(16, 11)) +/* Do not unmask unused inputs, including the flash controller (9). */ +#define OCP_WIWI_IRQS (OCP_WIWI_PERIPHERAL_IRQS | \ + OCP_WIWI_TIMING_IRQS) + #define PCI_VENDOR_ID_OROLIA 0x1ad7 #define PCI_DEVICE_ID_OROLIA_ARTCARD 0xa000 @@ -405,6 +421,10 @@ struct ptp_ocp { struct delayed_work sync_work; int id; int n_irqs; + bool wiwi; + bool wiwi_timing_ready; + u32 wiwi_image_id; + void __iomem *wiwi_msi; struct ptp_ocp_serial_port port[__PORT_COUNT]; bool fw_loader; u8 fw_tag; @@ -578,6 +598,22 @@ static struct ptp_ocp_eeprom_map art_eeprom_map[] = { * 15: Orolia TS4 */ +static struct i2c_board_info ocp_fb_i2c_devices[] = { + { I2C_BOARD_INFO("24c02", 0x50) }, + { I2C_BOARD_INFO("24mac402", 0x58), .platform_data = "mac" }, +}; + +static struct ptp_ocp_i2c_info ocp_wiwi_i2c = { + .name = "xiic-i2c", + .fixed_rate = 50000000, + .data_size = sizeof(struct xiic_i2c_platform_data), + .data = &(struct xiic_i2c_platform_data) { + .num_devices = ARRAY_SIZE(ocp_fb_i2c_devices), + .devices = ocp_fb_i2c_devices, + .force_32bit_access = true, + }, +}; + static struct ocp_resource ocp_fb_resource[] = { { OCP_MEM_RESOURCE(reg), @@ -730,12 +766,8 @@ static struct ocp_resource ocp_fb_resource[] = { .fixed_rate = 50000000, .data_size = sizeof(struct xiic_i2c_platform_data), .data = &(struct xiic_i2c_platform_data) { - .num_devices = 2, - .devices = (struct i2c_board_info[]) { - { I2C_BOARD_INFO("24c02", 0x50) }, - { I2C_BOARD_INFO("24mac402", 0x58), - .platform_data = "mac" }, - }, + .num_devices = ARRAY_SIZE(ocp_fb_i2c_devices), + .devices = ocp_fb_i2c_devices, }, }, }, @@ -1322,6 +1354,11 @@ 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), + .driver_data = (kernel_ulong_t)ocp_fb_resource, + }, { PCI_DEVICE_DATA(OROLIA, ARTCARD, &ocp_art_resource) }, { PCI_DEVICE_DATA(ADVA, TIMECARD, &ocp_adva_resource) }, { PCI_DEVICE_DATA(ADVA, TIMECARD_X1, &ocp_adva_x1_resource) }, @@ -1384,6 +1421,23 @@ static const struct ocp_selector ptp_ocp_sma_out[] = { { } }; +/* No validated second receiver on the supported WiWi board. */ +static const struct ocp_selector ptp_ocp_wiwi_sma_out[] = { + { .name = "10Mhz", .value = 0x0000, .frequency = 10000000 }, + { .name = "PHC", .value = 0x0001, .frequency = 1 }, + { .name = "MAC", .value = 0x0002, .frequency = 1 }, + { .name = "GNSS1", .value = 0x0004, .frequency = 1 }, + { .name = "IRIG", .value = 0x0010, .frequency = 10000 }, + { .name = "DCF", .value = 0x0020, .frequency = 77000 }, + { .name = "GEN1", .value = 0x0040 }, + { .name = "GEN2", .value = 0x0080 }, + { .name = "GEN3", .value = 0x0100 }, + { .name = "GEN4", .value = 0x0200 }, + { .name = "GND", .value = 0x2000 }, + { .name = "VCC", .value = 0x4000 }, + { } +}; + static const struct ocp_selector ptp_ocp_art_sma_in[] = { { .name = "PPS1", .value = 0x0001, .frequency = 1 }, { .name = "10Mhz", .value = 0x0008, .frequency = 1000000 }, @@ -2174,6 +2228,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; + } + if (params->component) { if (!bp->has_cpld || strcmp(params->component, ADVA_CPLD_COMPONENT)) { @@ -2220,7 +2280,10 @@ ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req, u32 id; fw_image = bp->fw_loader ? "loader" : "fw"; - sprintf(buf, "%d.%d", bp->fw_tag, bp->fw_version); + if (bp->wiwi) + snprintf(buf, sizeof(buf), "0x%08x", bp->wiwi_image_id); + else + sprintf(buf, "%d.%d", bp->fw_tag, bp->fw_version); err = devlink_info_version_running_put(req, fw_image, buf); if (err) return err; @@ -2470,6 +2533,12 @@ ptp_ocp_signal_from_perout(struct ptp_ocp *bp, int gen, return ptp_ocp_signal_set(bp, gen, &s); } +static bool ptp_ocp_timing_ready(struct ptp_ocp *bp) +{ + /* Pair with probe's publication after the gate readback. */ + return !bp->wiwi || smp_load_acquire(&bp->wiwi_timing_ready); +} + static int ptp_ocp_signal_enable(void *priv, u32 req, bool enable) { @@ -2479,6 +2548,9 @@ ptp_ocp_signal_enable(void *priv, u32 req, bool enable) struct timespec64 ts; int gen; + if (enable && !ptp_ocp_timing_ready(bp)) + return -EAGAIN; + gen = ext->info->index - 1; iowrite32(0, ®->intr_mask); @@ -2552,6 +2624,9 @@ ptp_ocp_ts_enable(void *priv, u32 req, bool enable) struct ts_reg __iomem *reg = ext->mem; struct ptp_ocp *bp = ext->bp; + if (enable && !ptp_ocp_timing_ready(bp)) + return -EAGAIN; + if (ext == bp->pps) { u32 old_map = bp->pps_req_map; @@ -2641,7 +2716,7 @@ ptp_ocp_serial_line(struct ptp_ocp *bp, struct ocp_resource *r) */ memset(&uart, 0, sizeof(uart)); uart.port.dev = &pdev->dev; - uart.port.iotype = UPIO_MEM; + uart.port.iotype = bp->wiwi ? UPIO_MEM32 : UPIO_MEM; uart.port.regshift = 2; uart.port.mapbase = pci_resource_start(pdev, 0) + r->offset; uart.port.irq = pci_irq_vector(pdev, r->irq_vec); @@ -2944,6 +3019,14 @@ static const struct ocp_sma_op ocp_fb_sma_op = { .set_output = ptp_ocp_sma_fb_set_output, }; +static const struct ocp_sma_op ocp_wiwi_sma_op = { + .tbl = { ptp_ocp_sma_in, ptp_ocp_wiwi_sma_out }, + .init = ptp_ocp_sma_fb_init, + .get = ptp_ocp_sma_fb_get, + .set_inputs = ptp_ocp_sma_fb_set_inputs, + .set_output = ptp_ocp_sma_fb_set_output, +}; + static int ptp_ocp_sma_adva_set_output(struct ptp_ocp *bp, int sma_nr, u32 val) { @@ -3037,6 +3120,13 @@ ptp_ocp_fb_set_version(struct ptp_ocp *bp) version = ioread32(&bp->image->version); + 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; @@ -3069,8 +3159,7 @@ ptp_ocp_fb_board_init(struct ptp_ocp *bp, struct ocp_resource *r) bp->flash_start = 1024 * 4096; bp->eeprom_map = fb_eeprom_map; - bp->fw_version = ioread32(&bp->image->version); - bp->sma_op = &ocp_fb_sma_op; + bp->sma_op = bp->wiwi ? &ocp_wiwi_sma_op : &ocp_fb_sma_op; bp->signals_nr = 4; bp->freq_in_nr = 4; @@ -3110,7 +3199,30 @@ 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++) { + for (; table->setup; table++) { + struct ocp_resource translated = *table; + + r = table; + if (bp->wiwi) { + /* Do not expose the flash through raw MTD, either. */ + if (r->setup == ptp_ocp_register_spi) + continue; + /* The supported board has no validated GNSS2 port. */ + if (r->setup == ptp_ocp_register_serial && + r->bp_offset == offsetof(struct ptp_ocp, + port[PORT_GNSS2])) + continue; + /* Leave the shared resource table unchanged. */ + if (translated.offset) + translated.offset += OCP_WIWI_MMIO_OFFSET; + if (r->setup == ptp_ocp_register_i2c) + translated.extra = &ocp_wiwi_i2c; + if (r->setup == ptp_ocp_register_ext || + r->setup == ptp_ocp_register_serial || + r->setup == ptp_ocp_register_i2c) + translated.irq_vec += OCP_WIWI_IRQ_OFFSET; + r = &translated; + } if (!ptp_ocp_allow_irq(bp, r)) continue; err = r->setup(bp, r); @@ -3394,6 +3506,8 @@ ptp_ocp_sma_show(struct ptp_ocp *bp, int sma_nr, char *buf, return ptp_ocp_show_inputs(tbl[0], val, buf, default_in_val); } + if (bp->wiwi && !ptp_ocp_select_name_from_val(tbl[1], val)) + return sysfs_emit(buf, "OUT: unavailable\n"); return ptp_ocp_show_output(tbl[1], val, buf, default_out_val); } @@ -5455,7 +5569,7 @@ ptp_ocp_summary_show(struct seq_file *s, void *data) } seq_printf(s, "MAC PPS1 src: %s\n", mac_src); - gpio_input_map(buf, bp, sma_val, 1, "GNSS2"); + gpio_input_map(buf, bp, sma_val, 1, bp->wiwi ? NULL : "GNSS2"); seq_printf(s, "MAC PPS2 src: %s\n", buf); /* assumes automatic switchover/selection */ @@ -5787,6 +5901,12 @@ ptp_ocp_detach(struct ptp_ocp *bp) platform_device_unregister(bp->i2c_ctrl); if (bp->i2c_clk) clk_hw_unregister_fixed_rate(bp->i2c_clk); + /* Keep child interrupts available until the children are gone. */ + if (bp->wiwi_msi) { + iowrite32(0, bp->wiwi_msi); + iowrite32(0, bp->wiwi_msi + 4); + ioread32(bp->wiwi_msi); + } if (bp->n_irqs) pci_free_irq_vectors(bp->pdev); mutex_destroy(&bp->cpld_lock); @@ -5881,9 +6001,14 @@ static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin, return -EOPNOTSUPP; tbl = bp->sma_op->tbl[sma->mode]; - for (i = 0; tbl[i].name; i++) - if (tbl[i].frequency == frequency) - return ptp_ocp_sma_store_val(bp, i, sma->mode, sma_nr + 1); + for (i = 0; tbl[i].name; i++) { + if (tbl[i].frequency == frequency) { + int val = bp->wiwi ? tbl[i].value : i; + + return ptp_ocp_sma_store_val(bp, val, sma->mode, + sma_nr + 1); + } + } return -EINVAL; } @@ -5901,6 +6026,8 @@ static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin, int i; val = bp->sma_op->get(bp, sma_nr + 1); + if (bp->wiwi) + val &= SMA_SELECT_MASK; tbl = bp->sma_op->tbl[sma->mode]; for (i = 0; tbl[i].name; i++) if (val == tbl[i].value) { @@ -5952,6 +6079,49 @@ ptp_ocp_sync_work(struct work_struct *work) queue_delayed_work(system_power_efficient_wq, &bp->sync_work, HZ); } +/* 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 0x%02x\n", + pdev->revision); + + cap = pci_find_capability(pdev, PCI_CAP_ID_MSIX); + if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) || + pci_resource_len(pdev, 0) != 0x04000000 || !cap || + pci_msix_vec_count(pdev) != 64 || + pci_read_config_dword(pdev, cap + PCI_MSIX_TABLE, &table) || + pci_read_config_dword(pdev, cap + PCI_MSIX_PBA, &pba) || + table != 0x2000 || pba != 0x1808) + return dev_err_probe(&pdev->dev, -ENODEV, + "Unsupported WiWi PCI layout\n"); + + return 0; +} + +static int ptp_ocp_wiwi_irq_init(struct ptp_ocp *bp) +{ + void __iomem *msi; + + msi = __ptp_ocp_get_mem(bp, pci_resource_start(bp->pdev, 0) + + OCP_WIWI_MSI_ENABLE, 8); + if (IS_ERR(msi)) + return PTR_ERR(msi); + bp->wiwi_msi = msi; + + /* LiteX stores bits 63:32 before bits 31:0, as little-endian words. */ + iowrite32(0, msi); + iowrite32(0, msi + 4); + if (ioread32(msi) || ioread32(msi + 4)) + return -EIO; + + return 0; +} + static int ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) { @@ -5960,6 +6130,13 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) int err, i; u64 clkid; + /* Dynamic IDs must not override the WiWi board's resource table. */ + if (pdev->vendor == PCI_VENDOR_ID_WIWI) { + id = pci_match_id(ptp_ocp_pcidev_id, pdev); + if (!id) + return -ENODEV; + } + devlink = devlink_alloc(&ptp_ocp_devlink_ops, sizeof(*bp), &pdev->dev); if (!devlink) { dev_err(&pdev->dev, "devlink_alloc failed\n"); @@ -5973,6 +6150,13 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) } bp = devlink_priv(devlink); + bp->wiwi = id->vendor == PCI_VENDOR_ID_WIWI; + if (bp->wiwi) { + /* Validate before IRQ setup, bus mastering or FPGA writes. */ + err = ptp_ocp_wiwi_validate(pdev); + if (err) + goto out_disable; + } err = ptp_ocp_device_init(bp, pdev); if (err) goto out_disable; @@ -5988,18 +6172,33 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) INIT_DELAYED_WORK(&bp->sync_work, ptp_ocp_sync_work); + if (bp->wiwi) { + err = ptp_ocp_wiwi_irq_init(bp); + if (err) + goto out; + } + /* compat mode. * Older FPGA firmware only returns 2 irq's. * allow this - if not all of the IRQ's are returned, skip the * extra devices and just register the clock. */ - err = pci_alloc_irq_vectors(pdev, 1, 17, PCI_IRQ_MSI | PCI_IRQ_MSIX); + if (bp->wiwi) + err = pci_alloc_irq_vectors(pdev, 49, 64, PCI_IRQ_MSIX); + else + err = pci_alloc_irq_vectors(pdev, 1, 17, + PCI_IRQ_MSI | PCI_IRQ_MSIX); if (err < 0) { dev_err(&pdev->dev, "alloc_irq_vectors err: %d\n", err); goto out; } bp->n_irqs = err; pci_set_master(pdev); + /* Only the UART and XIIC inputs may interrupt during probe. */ + if (bp->wiwi_msi) { + iowrite32(OCP_WIWI_PERIPHERAL_IRQS, bp->wiwi_msi); + ioread32(bp->wiwi_msi); + } err = ptp_ocp_register_resources(bp, id->driver_data); if (err) @@ -6048,6 +6247,17 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto out_dpll; } } + /* All handlers and the PHC are ready for timestamp interrupts. */ + if (bp->wiwi_msi) { + iowrite32(OCP_WIWI_IRQS, bp->wiwi_msi); + if (ioread32(bp->wiwi_msi) != OCP_WIWI_IRQS) { + err = dev_err_probe(&pdev->dev, -EIO, + "WiWi interrupt gate did not open\n"); + goto out_dpll; + } + /* Publish readiness to the timestamp and generator enablers. */ + smp_store_release(&bp->wiwi_timing_ready, true); + } queue_delayed_work(system_power_efficient_wq, &bp->sync_work, HZ); return 0; ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v3 3/3] ptp: ocp: support the WiWi revision 02 Time Card 2026-11-16 18:20 ` [PATCH net-next v3 3/3] ptp: ocp: support the WiWi revision 02 Time Card Ahmad Byagowi @ 2026-11-18 18:22 ` netdev-bot+sashiko 2026-11-18 20:05 ` Ahmad Byagowi 0 siblings, 1 reply; 10+ messages in thread From: netdev-bot+sashiko @ 2026-11-18 18:22 UTC (permalink / raw) To: ahmadexp Cc: netdev, vadim.fedorenko, andi.shyti, andrew+netdev, corbet, davem, edumazet, horms, jiri, kuba, linux-doc, linux-i2c, linux-kernel, pabeni, rdunlap, richardcochran, skhan Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider. Critical: 0 · High: 1 (1) · Medium: 3 · Low: 1 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] The patch fixes the DPLL selector bugs for WiWi only. - [Medium] The new ptp_ocp_wiwi_sma_out table gives DCF a frequency of 77000. - [Medium] On WiWi the patch removes GNSS2 (0x0008) from the SMA output table but never clears that selection in the output mux. - [Medium] ptp: ocp: disabled WiWi SMA input reported as 10 MHz in ptp_ocp_dpll_frequency_get() - [Low] On WiWi, ptp_ocp_sma_show() prints "OUT: unavailable\n" when the output selector holds a value missing from ptp_ocp_wiwi_sma_out, such… Pre-existing issues: - [High] This problem wasn't introduced by this patch, but there is a remove-vs-ioctl race in ptp_ocp_detach() that can lead to a use-after-… -- ptp: ocp: support the WiWi revision 02 Time Card This adds support for the WiWi revision 02 Time Card (2163:1008, subsystem 10ee:0007). It reuses the FB resource table with WiWi-specific MMIO and MSI-X offsets, adds a WiWi SMA output table without GNSS2, and drives an MSI enable gate at BAR0 0x1800. On WiWi it also rejects devlink flash, skips the SPI flash and GNSS2 UART, and blocks timestamper and generator arming until probe has opened the interrupt gate. > diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c > index decc56892059b..df40dac982213 100644 > --- a/drivers/ptp/ptp_ocp.c > +++ b/drivers/ptp/ptp_ocp.c [ ... ] > @@ -1384,6 +1421,23 @@ static const struct ocp_selector ptp_ocp_sma_out[] = { > { } > }; > > +/* No validated second receiver on the supported WiWi board. */ > +static const struct ocp_selector ptp_ocp_wiwi_sma_out[] = { > + { .name = "10Mhz", .value = 0x0000, .frequency = 10000000 }, > + { .name = "PHC", .value = 0x0001, .frequency = 1 }, > + { .name = "MAC", .value = 0x0002, .frequency = 1 }, > + { .name = "GNSS1", .value = 0x0004, .frequency = 1 }, > + { .name = "IRIG", .value = 0x0010, .frequency = 10000 }, > + { .name = "DCF", .value = 0x0020, .frequency = 77000 }, [Severity: Medium] Should this be 77500? The SMA DPLL pins advertise DPLL_PIN_FREQUENCY_DCF77 (77.5 kHz) in ptp_ocp_sma_freq[], and ptp_ocp_sma_in already uses 77500 for DCF. For WiWi, ptp_ocp_dpll_frequency_set() now picks the hardware value with tbl[i].frequency == frequency. A 77500 Hz request on an output SMA matches nothing in ptp_ocp_wiwi_sma_out, so it returns -EINVAL. In the other direction, ptp_ocp_dpll_frequency_get() would report 77000 Hz for a DCF-routed output, and that frequency is not in the pin's supported list. The value was copied from ptp_ocp_sma_out, but this table and its value-based DPLL path are new in this patch. [ ... ] > @@ -2944,6 +3019,14 @@ static const struct ocp_sma_op ocp_fb_sma_op = { > .set_output = ptp_ocp_sma_fb_set_output, > }; > > +static const struct ocp_sma_op ocp_wiwi_sma_op = { > + .tbl = { ptp_ocp_sma_in, ptp_ocp_wiwi_sma_out }, > + .init = ptp_ocp_sma_fb_init, > + .get = ptp_ocp_sma_fb_get, > + .set_inputs = ptp_ocp_sma_fb_set_inputs, > + .set_output = ptp_ocp_sma_fb_set_output, > +}; [Severity: Medium] GNSS2 (0x0008) is dropped from ptp_ocp_wiwi_sma_out, but the output mux is never reprogrammed. ocp_wiwi_sma_op reuses ptp_ocp_sma_fb_init(), which only reads sma_map1/sma_map2 to work out the pin direction: reg = ioread32(&bp->sma_map1->gpio2); bp->sma[2].mode = reg & BIT(15) ? SMA_MODE_OUT : SMA_MODE_IN; Suppose an output selector already holds GNSS2 at bind time. That could come from the FPGA default or from a previous kernel. It could also come from the earlier driver build mentioned in the commit message, which used the FB table with GNSS2. The CSR is not reset on driver reload. In that case, will the SMA keep driving the GNSS2 PPS net? In that state ptp_ocp_sma_show() prints "OUT: unavailable". ptp_ocp_dpll_frequency_get() finds no match and returns -EINVAL, which makes the DPLL pin dump fail. The commit message says: "Do not expose an unvalidated second GNSS UART or PPS output source." Should the WiWi SMA init replace any output selection that is missing from ptp_ocp_wiwi_sma_out with the pin's default_fcn? [ ... ] > @@ -3394,6 +3506,8 @@ ptp_ocp_sma_show(struct ptp_ocp *bp, int sma_nr, char *buf, > return ptp_ocp_show_inputs(tbl[0], val, buf, default_in_val); > } > > + if (bp->wiwi && !ptp_ocp_select_name_from_val(tbl[1], val)) > + return sysfs_emit(buf, "OUT: unavailable\n"); > return ptp_ocp_show_output(tbl[1], val, buf, default_out_val); > } [Severity: Low] Is "OUT: unavailable" meant to be part of the sysfs ABI? Documentation/ABI/testing/sysfs-timecard describes the smaN read format this way: The display format of the attribute is a space separated list of signals, prefixed by the input/output direction. It also says output values come from available_sma_outputs, and "unavailable" is not one of them. Writing the displayed value back fails with -EINVAL, because sma_parse_inputs()->ptp_ocp_select_val_from_name() finds no match. Should the sysfs ABI document be updated along with the devlink rst? [ ... ] > @@ -5787,6 +5901,12 @@ ptp_ocp_detach(struct ptp_ocp *bp) > platform_device_unregister(bp->i2c_ctrl); > if (bp->i2c_clk) > clk_hw_unregister_fixed_rate(bp->i2c_clk); > + /* Keep child interrupts available until the children are gone. */ > + if (bp->wiwi_msi) { > + iowrite32(0, bp->wiwi_msi); > + iowrite32(0, bp->wiwi_msi + 4); > + ioread32(bp->wiwi_msi); > + } > if (bp->n_irqs) > pci_free_irq_vectors(bp->pdev); [Severity: High] This is a pre-existing issue and was not introduced by this patch, but the new wiwi_timing_ready flag looks like it could close it. ptp_ocp_detach() disables the timestampers before it unregisters the clock: if (bp->pps) ptp_ocp_ts_enable(bp->pps, ~0, false); if (bp->ptp) ptp_clock_unregister(bp->ptp); Until posix_clock_unregister() runs, can userspace still issue PTP_EXTTS_REQUEST and reach ptp_ocp_enable()->ptp_ocp_ts_enable() with enable=true, which re-arms the timestamper? On WiWi, ptp_ocp_timing_ready() still returns true at this point, because wiwi_timing_ready is never cleared. ptp_disable_all_events() only disables EXTTS on pins whose func is PTP_PF_EXTTS. ptp_ocp_set_pins() leaves func at PTP_PF_NONE, so a re-armed channel stays enabled. The MSI vector stays requested until ptp_ocp_unregister_ext() runs. The WiWi gate at 0x1800 also stays open until the children have been freed. If the fd that armed EXTTS has been closed, put_device() in ptp_clock_unregister() frees the ptp_clock. An external edge would then run this on freed memory: ptp_ocp_ts_irq() ptp_clock_event(ext->bp->ptp, &ev) spin_lock_irqsave(&ptp->tsevqs_lock, ...) Would it help to clear wiwi_timing_ready with smp_store_release(..., false) or to mask OCP_WIWI_TIMING_IRQS before the disable loop? [ ... ] > @@ -5881,9 +6001,14 @@ static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin, > return -EOPNOTSUPP; > > tbl = bp->sma_op->tbl[sma->mode]; > - for (i = 0; tbl[i].name; i++) > - if (tbl[i].frequency == frequency) > - return ptp_ocp_sma_store_val(bp, i, sma->mode, sma_nr + 1); > + for (i = 0; tbl[i].name; i++) { > + if (tbl[i].frequency == frequency) { > + int val = bp->wiwi ? tbl[i].value : i; > + > + return ptp_ocp_sma_store_val(bp, val, sma->mode, > + sma_nr + 1); > + } > + } > return -EINVAL; > } > > @@ -5901,6 +6026,8 @@ static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin, > int i; > > val = bp->sma_op->get(bp, sma_nr + 1); > + if (bp->wiwi) > + val &= SMA_SELECT_MASK; > tbl = bp->sma_op->tbl[sma->mode]; [Severity: Medium] When an SMA input is disabled, ptp_ocp_sma_store_val() sets sma->disabled and writes 0 to the mux field, which also clears SMA_ENABLE. With the new masking, ptp_ocp_dpll_frequency_get() then looks up 0x0000 in ptp_ocp_sma_in and matches the 10Mhz entry. Doesn't that make a disabled WiWi input report 10 MHz over DPLL netlink? ptp_ocp_sma_show() avoids this collision by substituting SMA_DISABLE before the table lookup: if (sma->disabled) val = SMA_DISABLE; So sysfs shows "IN: None" for a pin that DPLL reports as 10 MHz. The wrong readback also gets in the way of re-enabling the pin. dpll_pin_freq_set() calls frequency_get first. If the requested frequency matches the current one, it returns 0 without calling frequency_set. A 10 MHz request on the disabled input is therefore a silent no-op. ptp_ocp_dpll_frequency_set() never runs and sma->disabled stays set, yet the request still reports success. Should ptp_ocp_dpll_frequency_get() check sma->disabled the same way, so the lookup hits the "None" entry and reports 0 Hz? Or is there a better way to report a disabled pin here? A disabled pin also reads back 0 on the other boards that use ptp_ocp_sma_fb_get(), so the check may belong in the common path rather than only under bp->wiwi. [Severity: High] WiWi now uses the hardware selector value here. Non-WiWi boards still pass the table index i to ptp_ocp_sma_store_val(), so don't they keep the same bug? ptp_ocp_sma_store_val() expects a selector bitmask. The sysfs path ptp_ocp_sma_store() passes it the value from sma_parse_inputs(), and ptp_ocp_sma_store_val() ORs in SMA_ENABLE before writing the mux. With ptp_ocp_sma_out (Meta, Celestica, ADVA), a 10 kHz request on an output SMA matches IRIG at index 5. It writes 0x5 | SMA_ENABLE, which selects PHC|GNSS1 instead of 0x10. With ptp_ocp_sma_in, a 10 kHz request writes 0x5 (PPS1|TS1) instead of IRIG (0x10). A 77500 Hz request writes 0x6 (PPS2|TS1) instead of DCF (0x20). On ART, a 1 Hz request writes 0, which ptp_ocp_art_sma_set() rejects. ptp_ocp_dpll_frequency_get() has the same split. ptp_ocp_sma_fb_get() returns the raw 16-bit field: return (ioread32(gpio) >> shift) & 0xffff; On FB/ADVA pins whose direction can change, SMA_ENABLE (BIT(15)) is set, so no table entry matches and the callback returns -EINVAL. dpll_msg_add_pin_freq() in drivers/dpll/dpll_netlink.c passes that error on, so the DPLL pin get/dump fails for that pin. By comparison, ptp_ocp_sma_show() masks with SMA_SELECT_MASK on every board. The commit message says: "Use hardware selector values for WiWi DPLL routing; preserve the existing behavior on other boards." Could tbl[i].value and the SMA_SELECT_MASK masking be applied on every board instead, as a separate fix with Fixes: 09eeb3aecc6c ("ptp_ocp: implement DPLL ops"), rather than only for WiWi? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-wiwi-v3-87afa10a8-0-ahmadexp%40gmail.com ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v3 3/3] ptp: ocp: support the WiWi revision 02 Time Card 2026-11-18 18:22 ` netdev-bot+sashiko @ 2026-11-18 20:05 ` Ahmad Byagowi 0 siblings, 0 replies; 10+ messages in thread From: Ahmad Byagowi @ 2026-11-18 20:05 UTC (permalink / raw) To: netdev-bot+sashiko Cc: andi.shyti, andrew+netdev, corbet, davem, edumazet, horms, jiri, kuba, linux-doc, linux-i2c, linux-kernel, netdev, pabeni, rdunlap, richardcochran, skhan, vadim.fedorenko Thanks. I have prepared separate common-driver fixes and a WiWi v4 draft. The common fixes use tbl[i].value for all boards, mask SMA_ENABLE on frequency readback, report disabled inputs through the None/0 Hz entry, and correct the common DCF output frequency to 77500 Hz. The selector, disabled-input and frequency fixes carry Fixes: 09eeb3aecc6c. The WiWi table also uses 77500 Hz. Its new init replaces unsupported output selections, including GNSS2, with the connector's default output. It leaves valid outputs, inputs, directions and neighboring mux fields alone. The normal sysfs read therefore names a supported signal. If an unsupported output value appears later outside the driver, the read returns -EIO; the ABI document describes this instead of adding the unwritable "unavailable" token. The removal concern is real at the source level. An EXTTS request can rearm a channel after detach disables it but before the POSIX clock is revoked, without assigning a PTP_PF_EXTTS pin. Clearing readiness alone does not serialize an enable that has already passed the check. The separate teardown fix uses a mutex shared by timestamp enable and disable. Detach sets a permanent stopping flag under that mutex, then disables and synchronizes all timestamp IRQs before unregistering the clock. New enables return -ENODEV; an enable already in progress must finish before stopping is published. Disables remain available to the PTP core. The IRQ handler does not acquire the mutex. This is a common fix with Fixes: 627366c51145, not a WiWi-only gate change. A source-derived pthread/MMIO harness reproduces the rearm window with the old code. The revised code passes late-enable, in-flight-enable and active-IRQ-drain cases for timestamps and combined PPS/EXTTS requests. The tests run under ASan/UBSan; DPLL and routing tests also pass, including negative controls. Both driver objects compile with W=1 and -Werror. These are software tests with stubbed I/O, not an in-kernel UAF or a physical removal test. The card is currently reserved for Windows HLK. I have sent the four common fixes to net as a separate series: https://lore.kernel.org/r/20261118-timecard-common-301f823ddd-0-ahmadexp@gmail.com WiWi v4 remains unsent. I will rebase it after the fixes reach net-next, so the feature series will not duplicate them. pw-bot: changes-requested ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-11-18 20:05 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-16 18:20 [PATCH net-next v3 0/3] ptp: ocp: support the WiWi production Time Card Ahmad Byagowi 2026-11-16 18:20 ` [PATCH net-next v3 1/3] i2c: xiic: allow platforms to require 32-bit register accesses Ahmad Byagowi 2026-11-18 18:22 ` netdev-bot+sashiko 2026-11-18 20:05 ` Ahmad Byagowi 2026-11-16 18:20 ` [PATCH net-next v3 2/3] i2c: xiic: add KUnit coverage for register access modes Ahmad Byagowi 2026-11-18 18:22 ` netdev-bot+sashiko 2026-11-18 20:05 ` Ahmad Byagowi 2026-11-16 18:20 ` [PATCH net-next v3 3/3] ptp: ocp: support the WiWi revision 02 Time Card Ahmad Byagowi 2026-11-18 18:22 ` netdev-bot+sashiko 2026-11-18 20:05 ` Ahmad Byagowi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®