AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/09/18 05:12 flow patch-triage
0m Args:
null

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "KMSANReasoning": "",
  "NeedsKMSAN": false,
  "Reasoning": "The patch series adds CPLD status reporting, devlink flash updating, and devlink info support for the ADVA TimeCard X1 in the OpenCompute TimeCard driver (drivers/ptp/ptp_ocp.c). This driver binds exclusively to specific physical PCIe devices (such as Meta TimeCard, ADVA TimeCard X1) which require dedicated hardware (atomic clock/GPS timing PCIe cards) not emulated in standard virtualized fuzzing environments (QEMU/GCE). As such, the modified code is structurally unreachable.",
  "WorthFuzzing": false
}

1/1 2026/09/18 05:12 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit bf809a1e5e4fa0eb4362d0f29cfa32086c3519c3\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Fri Sep 18 05:12:44 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/Documentation/ABI/testing/sysfs-timecard b/Documentation/ABI/testing/sysfs-timecard\nindex 3ae41b7634ac9..4ba45c6ee4a36 100644\n--- a/Documentation/ABI/testing/sysfs-timecard\n+++ b/Documentation/ABI/testing/sysfs-timecard\n@@ -11,6 +11,35 @@ Contact:\tJonathan Lemon \u003cjonathan.lemon@gmail.com\u003e\n Description:\tThis directory contains the attributes of the Nth timecard\n \t\tregistered.\n \n+What:\t\t/sys/class/timecard/ocpN/cpld_status\n+Date:\t\tJuly 2026\n+Contact:\tSagi Maimon \u003cmaimon.sagi@gmail.com\u003e\n+Description:\t(RO, root only) The flags set in the status register of the\n+\t\tTAP CPLD, space separated, or an empty line when none is\n+\t\tset.  Only present on ADVA x1 TAP boards (PCI ID\n+\t\t0xad5a:0x0410).\n+\n+\t\t==========  ================================================\n+\t\tdone        the configuration flash holds a valid image and\n+\t\t\t    it is active\n+\t\tbusy        an internal operation is in progress\n+\t\tfailed      the last ISC operation failed\n+\t\t==========  ================================================\n+\n+\t\tFor example \"busy\" while an operation runs, or \"busy failed\"\n+\t\tif a failure is latched while another one is in progress.\n+\n+\t\tA read arbitrates for the shared I2C bus and reprograms the\n+\t\ton-card mux, so it is restricted to root.  The Lattice device\n+\t\tID of the CPLD is read by the driver shortly after probe,\n+\t\tand again after a successful CPLD update, and reported from\n+\t\tthat cached value as the fixed \"cpld.id\" version by\n+\t\tdevlink dev info.\n+\n+\t\tNew CPLD firmware is programmed with devlink dev flash,\n+\t\tselecting the \"fw.cpld\" component; see\n+\t\tDocumentation/networking/devlink/ptp_ocp.rst.\n+\n What:\t\t/sys/class/timecard/ocpN/available_clock_sources\n Date:\t\tSeptember 2021\n Contact:\tJonathan Lemon \u003cjonathan.lemon@gmail.com\u003e\ndiff --git a/Documentation/networking/devlink/index.rst b/Documentation/networking/devlink/index.rst\nindex d4a83fdcff7fe..1af780c811ee2 100644\n--- a/Documentation/networking/devlink/index.rst\n+++ b/Documentation/networking/devlink/index.rst\n@@ -99,6 +99,7 @@ parameters, info versions, and other features it supports.\n    nfp\n    octeontx2\n    prestera\n+   ptp_ocp\n    qed\n    sfc\n    stmmac\ndiff --git a/Documentation/networking/devlink/ptp_ocp.rst b/Documentation/networking/devlink/ptp_ocp.rst\nnew file mode 100644\nindex 0000000000000..f94b759d9cd65\n--- /dev/null\n+++ b/Documentation/networking/devlink/ptp_ocp.rst\n@@ -0,0 +1,75 @@\n+.. SPDX-License-Identifier: GPL-2.0\n+\n+========================\n+ptp_ocp devlink support\n+========================\n+\n+This document describes the devlink features implemented by the ``ptp_ocp``\n+device driver: the info versions it reports and its flash update support.\n+\n+Info versions\n+=============\n+\n+The ``ptp_ocp`` driver reports the following versions\n+\n+.. list-table:: devlink info versions implemented\n+   :widths: 5 5 90\n+\n+   * - Name\n+     - Type\n+     - Description\n+   * - ``fw``\n+     - running\n+     - Version of the firmware running on the card.  Reported as ``loader``\n+       instead when the card is running the firmware loader.\n+   * - ``board.id``\n+     - fixed\n+     - Board identifier, read from the on-card EEPROM.\n+   * - ``cpld.id``\n+     - fixed\n+     - Lattice device ID (IDCODE) of the TAP CPLD, formatted as ``0x%08x``.\n+       Only present on ADVA TimeCard X1 boards, which are the only ones\n+       carrying that CPLD.  Reading it claims the shared I2C bus and\n+       reprograms the on-card mux, so the driver does that from its own\n+       worker and reports the cached value here; the version is omitted\n+       until that read has succeeded.  The read is made once per binding\n+       and again after a successful CPLD update.\n+   * - ``fw.cpld``\n+     - running\n+     - USERCODE of the image programmed into the TAP CPLD, formatted as\n+       ``0x%08x``.  Read together with ``cpld.id`` and reported the same\n+       way.  This is the component name to pass to ``devlink dev flash``\n+       to update the CPLD.\n+\n+Flash update\n+============\n+\n+The driver implements ``devlink dev flash`` for two separate targets,\n+selected with the component name.\n+\n+.. list-table:: Flash components\n+   :widths: 20 80\n+\n+   * - Component\n+     - Description\n+   * - (none)\n+     - The card's own flash, written through the SPI controller the driver\n+       exposes.  The card runs the new image after its next reset.\n+   * - ``fw.cpld``\n+     - The configuration flash of the TAP CPLD on ADVA TimeCard X1 boards,\n+       programmed over I2C with the MachXO3 in-system programming commands\n+       and activated with a REFRESH, so the new image runs immediately.\n+       The image is the raw configuration bitstream.  The only check the\n+       driver makes is that its length is a non-zero multiple of the\n+       16-byte page size, so a container such as ``.jed`` has to be\n+       converted first rather than passed through - one whose length\n+       happens to be a multiple of 16 would be programmed as if it were\n+       a bitstream.\n+\n+Programming the CPLD claims the shared I2C bus for the whole cycle, so\n+reads of the card's EEPROM block until it completes.  Progress is reported\n+with the standard devlink status notifications.\n+\n+Example::\n+\n+    $ devlink dev flash pci/0000:02:00.0 file adva-cpld.bin component fw.cpld\ndiff --git a/MAINTAINERS b/MAINTAINERS\nindex 0e04d92d1b098..113f314346177 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -20479,6 +20479,7 @@ OPENCOMPUTE PTP CLOCK DRIVER\n M:\tVadim Fedorenko \u003cvadim.fedorenko@linux.dev\u003e\n L:\tnetdev@vger.kernel.org\n S:\tMaintained\n+F:\tDocumentation/networking/devlink/ptp_ocp.rst\n F:\tdrivers/ptp/ptp_ocp.c\n \n OPENCORES I2C BUS DRIVER\ndiff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c\nindex 3d26ec1f7b9ec..2802989e84947 100644\n--- a/drivers/ptp/ptp_ocp.c\n+++ b/drivers/ptp/ptp_ocp.c\n@@ -20,10 +20,14 @@\n #include \u003clinux/spi/altera.h\u003e\n #include \u003cnet/devlink.h\u003e\n #include \u003clinux/i2c.h\u003e\n+#include \u003clinux/iopoll.h\u003e\n #include \u003clinux/mtd/mtd.h\u003e\n #include \u003clinux/nvmem-consumer.h\u003e\n #include \u003clinux/crc16.h\u003e\n #include \u003clinux/dpll.h\u003e\n+#include \u003clinux/unaligned.h\u003e\n+#include \u003clinux/delay.h\u003e\n+#include \u003clinux/firmware.h\u003e\n \n #define PCI_DEVICE_ID_META_TIMECARD\t\t0x0400\n \n@@ -85,6 +89,8 @@ struct ptp_ocp_adva_info {\n \tu8\t\t\t\tsignals_nr;\n \tu8\t\t\t\tfreq_in_nr;\n \tconst struct ocp_attr_group\t*attr_groups;\n+\t/* x1: TAP CPLD present */\n+\tbool\t\t\t\thas_cpld;\n };\n \n #define OCP_CTRL_ENABLE\t\tBIT(0)\n@@ -163,7 +169,8 @@ struct gpio_reg {\n \tu32\tgpio1;\n \tu32\t__pad0;\n \tu32\tgpio2;\n-\tu32\t__pad1;\n+\t/* adva_x1: I2C bus ownership register; reserved on other variants */\n+\tu32\ti2c_bus_ctrl;\n };\n \n struct irig_master_reg {\n@@ -416,6 +423,31 @@ struct ptp_ocp {\n \tdpll_tracker tracker;\n \tint signals_nr;\n \tint freq_in_nr;\n+\t/* adva_x1 CPLD I2C (internal use only) */\n+\t/* serialises CPLD operations */\n+\tstruct mutex\t\tcpld_lock;\n+\t/* guards cpld_i2c_adap_nr against the bus notifier */\n+\tspinlock_t\t\tcpld_adap_lock;\n+\t/* I2C adapter nr; -1 if absent.  Under cpld_adap_lock */\n+\tint\t\t\tcpld_i2c_adap_nr;\n+\t/* claimed adapter; valid under cpld_lock */\n+\tstruct i2c_adapter\t*cpld_adap;\n+\t/* scratch, write half then read half; valid under cpld_lock */\n+\tu8\t\t\t*cpld_buf;\n+\t/* Lattice device ID; 0 if unread */\n+\tu32\t\t\tcpld_id;\n+\t/* USERCODE of the image in the part; valid once cpld_usercode_ok */\n+\tu32\t\t\tcpld_usercode;\n+\t/* cpld_usercode has been read since the last flash */\n+\tbool\t\t\tcpld_usercode_ok;\n+\t/* one-shot ID read finished, successfully or not; under cpld_lock */\n+\tbool\t\t\tcpld_id_tried;\n+\t/* failed ID read attempts so far; under cpld_lock */\n+\tunsigned int\t\tcpld_id_attempts;\n+\t/* x1 TAP CPLD present */\n+\tbool\t\t\thas_cpld;\n+\t/* EN_CFG_TP issued but not yet REFRESH'd */\n+\tbool\t\t\tcpld_in_config_mode;\n };\n \n #define OCP_REQ_TIMESTAMP\tBIT(0)\n@@ -452,6 +484,13 @@ static int ptp_ocp_adva_board_init(struct ptp_ocp *bp, struct ocp_resource *r);\n static const struct ocp_sma_op ocp_adva_sma_op;\n static const struct ocp_sma_op ocp_adva_x1_sma_op;\n \n+/* Flash component naming the CPLD image, as reported by -\u003einfo_get(). */\n+#define ADVA_CPLD_COMPONENT\t\"fw.cpld\"\n+\n+static int adva_x1_cpld_flash(struct ptp_ocp *bp, struct devlink *devlink,\n+\t\t\t      const struct firmware *fw,\n+\t\t\t      struct netlink_ext_ack *extack);\n+\n static const struct ocp_attr_group fb_timecard_groups[];\n \n static const struct ocp_attr_group art_timecard_groups[];\n@@ -1273,6 +1312,7 @@ static struct ocp_resource ocp_adva_x1_resource[] = {\n \t\t\t.signals_nr   = 4,\n \t\t\t.freq_in_nr   = 4,\n \t\t\t.attr_groups  = adva_timecard_x1_groups,\n+\t\t\t.has_cpld     = true,\n \t\t},\n \t},\n \t{ }\n@@ -2133,6 +2173,21 @@ ptp_ocp_devlink_flash_update(struct devlink *devlink,\n \tconst char *msg;\n \tint err;\n \n+\tif (params-\u003ecomponent) {\n+\t\tif (!bp-\u003ehas_cpld ||\n+\t\t    strcmp(params-\u003ecomponent, ADVA_CPLD_COMPONENT)) {\n+\t\t\tNL_SET_ERR_MSG_MOD(extack,\n+\t\t\t\t\t   \"unsupported flash component\");\n+\t\t\treturn -EOPNOTSUPP;\n+\t\t}\n+\n+\t\terr = adva_x1_cpld_flash(bp, devlink, params-\u003efw, extack);\n+\t\tmsg = err ? \"Flash error\" : \"Flash complete\";\n+\t\tdevlink_flash_update_status_notify(devlink, msg,\n+\t\t\t\t\t\t   ADVA_CPLD_COMPONENT, 0, 0);\n+\t\treturn err;\n+\t}\n+\n \tdev = ptp_ocp_find_flash(bp);\n \tif (!dev) {\n \t\tdev_err(\u0026bp-\u003epdev-\u003edev, \"Can't find Flash SPI adapter\\n\");\n@@ -2155,10 +2210,13 @@ static int\n ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,\n \t\t\t struct netlink_ext_ack *extack)\n {\n+\tenum devlink_info_version_type ver_type =\n+\t\t\t\t\tDEVLINK_INFO_VERSION_TYPE_COMPONENT;\n \tstruct ptp_ocp *bp = devlink_priv(devlink);\n \tconst char *fw_image;\n \tchar buf[32];\n \tint err;\n+\tu32 id;\n \n \tfw_image = bp-\u003efw_loader ? \"loader\" : \"fw\";\n \tsprintf(buf, \"%d.%d\", bp-\u003efw_tag, bp-\u003efw_version);\n@@ -2166,6 +2224,39 @@ ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,\n \tif (err)\n \t\treturn err;\n \n+\tif (bp-\u003ehas_cpld) {\n+\t\t/* Read by the worker, not here: this command is unprivileged\n+\t\t * and reading the ID claims the I2C bus.  0 means unread -\n+\t\t * skip it rather than fail, devlink discards the whole reply\n+\t\t * on error.\n+\t\t */\n+\t\tid = READ_ONCE(bp-\u003ecpld_id);\n+\t\tif (id) {\n+\t\t\tsprintf(buf, \"0x%08x\", id);\n+\t\t\terr = devlink_info_version_fixed_put(req, \"cpld.id\",\n+\t\t\t\t\t\t\t     buf);\n+\t\t\tif (err)\n+\t\t\t\treturn err;\n+\t\t}\n+\n+\t\t/* The flashable component.  Naming it here is what lets\n+\t\t * \"devlink dev flash ... component fw.cpld\" through, as the\n+\t\t * core matches the name against the versions reported here,\n+\t\t * so it is reported for every board that has the part and not\n+\t\t * only once its USERCODE has been read: a part left holding a\n+\t\t * bad image answers neither, and gating the component on the\n+\t\t * read would make that state unrecoverable.\n+\t\t */\n+\t\tif (smp_load_acquire(\u0026bp-\u003ecpld_usercode_ok))\n+\t\t\tsprintf(buf, \"0x%08x\", READ_ONCE(bp-\u003ecpld_usercode));\n+\t\telse\n+\t\t\tstrscpy(buf, \"unknown\", sizeof(buf));\n+\t\terr = devlink_info_version_running_put_ext(req, \"fw.cpld\", buf,\n+\t\t\t\t\t\t\t   ver_type);\n+\t\tif (err)\n+\t\t\treturn err;\n+\t}\n+\n \tif (!bp-\u003ehas_eeprom_data) {\n \t\tptp_ocp_read_eeprom(bp);\n \t\tif (!bp-\u003ehas_eeprom_data)\n@@ -3199,6 +3290,8 @@ ptp_ocp_adva_board_init(struct ptp_ocp *bp, struct ocp_resource *r)\n \t\treturn err;\n \tptp_ocp_sma_init(bp);\n \n+\tbp-\u003ehas_cpld = info-\u003ehas_cpld;\n+\n \treturn ptp_ocp_init_clock(bp, \u0026info-\u003eservo);\n }\n \n@@ -4226,6 +4319,794 @@ static const struct ocp_attr_group art_timecard_groups[] = {\n \t{ },\n };\n \n+/*\n+ * adva_x1 TAP CPLD (Lattice LCMXO3LF-2100) helpers.\n+ *\n+ * The card has two I2C controllers; Linux registers only 0x00150000.\n+ * The i2c_bus_ctrl handshake re-routes what each is wired to:\n+ *\n+ *   grant 0:  0x150000 -\u003e EEPROMs     0x120000 -\u003e TMC or M.2, MB's choice\n+ *   grant 1:  0x150000 -\u003e TMC bus     0x120000 -\u003e M.2\n+ *\n+ * The PCA9548 at 0x74 and the CPLD at 0x40 behind its channel 0 are on the\n+ * TMC bus, reachable only while the grant is held.  The EEPROMs are not\n+ * behind the adapter for that window, so a CPLD operation holds cpld_lock\n+ * and the adapter lock to keep the EEPROM and nvmem paths off it.\n+ */\n+\n+#define ADVA_MUX_ADDR     0x74\n+#define ADVA_CPLD_ADDR    0x40\n+#define ADVA_MUX_CHANNEL  0\n+\n+/* Longest command or reply; bounds each half of the per-claim scratch. */\n+#define ADVA_CPLD_XFER_MAX 32\n+\n+/* i2c_bus_ctrl carries a host-written request half and a firmware-written\n+ * grant half.  MBLAZE_GRANTED is what a granted register reads while our\n+ * request still stands; the release write clears the request half, so from\n+ * then on only the grant field can be tested.  Measured on an ADVA\n+ * TimeCard X1: the register reads 0x00000012 once the firmware has handed\n+ * the segment back, about 670 ms after the release write, so the low half\n+ * is not zero then and only the grant field is a valid test.\n+ */\n+#define MBLAZE_REQUEST    0x0000aaaaU\n+#define MBLAZE_GRANTED    0x5555aaaaU\n+#define MBLAZE_RELEASE    0x55550000U\n+#define MBLAZE_GRANT_MASK 0xffff0000U\n+#define MBLAZE_GRANT      0x55550000U\n+#define MBLAZE_RETRIES    200\n+#define MBLAZE_RETRY_US   10000\n+\n+/* Lattice LCMXO3LF ISC command codes */\n+#define CPLD_CMD_READ_ID      0xE0000000UL\n+/* The USERCODE lives in the configuration flash that ERASE wipes, and the\n+ * page writes carry it: after programming an image whose JEDEC UH field is\n+ * 0x00000004 the part reads back 0x00000004, not an erased value.  So there\n+ * is no separate ISC_PROGRAM_USERCODE step here.\n+ */\n+#define CPLD_CMD_READ_USERCODE 0xC0000000UL\n+#define CPLD_CMD_READ_STATUS  0x3C000000UL\n+#define CPLD_CMD_EN_CFG_TP    0x74   /* enable config, transparent mode */\n+#define CPLD_CMD_DIS_CFG      0x26\n+#define CPLD_CMD_ERASE        0x0E\n+#define CPLD_CMD_RESET_ADDR   0x46\n+#define CPLD_CMD_WRITE_PAGE   0x70\n+#define CPLD_CMD_SET_DONE     0x5E\n+#define CPLD_CMD_REFRESH      0x79\n+#define CPLD_PAGE_SIZE        16\n+#define CPLD_POLL_US          10000  /* status poll interval while busy */\n+/* Bounds how long a claim can hold the i2c root lock, not image validity:\n+ * far above any bitstream this part takes.\n+ */\n+#define CPLD_MAX_IMAGE_SZ     (256 * 1024)\n+#define CPLD_EXIT_CFG_TRIES   3\n+#define CPLD_ERASE_MS         15000  /* config sector erase, datasheet max */\n+#define CPLD_ID_MAX_ATTEMPTS  10     /* one per sync_work tick */\n+\n+/* Status register bit positions (Lattice LCMXO3LF datasheet) */\n+#define CPLD_STATUS_DONE   BIT(8)\n+#define CPLD_STATUS_ENAB   BIT(9)\n+#define CPLD_STATUS_BUSY   BIT(12)\n+#define CPLD_STATUS_FAILED BIT(13)\n+#define CPLD_STATUS_ERR    GENMASK(25, 23)\n+\n+/*\n+ * Issue one I2C transaction on the TMC bus: @cmd if not negative, then\n+ * @wlen bytes of @wdata (NULL sends zeros), then @rlen bytes read back.\n+ * The message is built in the scratch buffer from adva_x1_bus_claim(), so\n+ * a run of transfers costs one allocation, not one each.  I2C_M_DMA_SAFE\n+ * is not set: the two halves are not separately aligned, so let the core\n+ * bounce.  Caller holds the claim, hence __i2c_transfer().\n+ */\n+static int adva_x1_i2c_xfer(struct ptp_ocp *bp, u8 addr, int cmd,\n+\t\t\t    const void *wdata, u8 wlen,\n+\t\t\t    void *rdata, u8 rlen)\n+{\n+\tu8 *wbuf, *rbuf;\n+\tstruct i2c_adapter *adap;\n+\tstruct i2c_msg msgs[2];\n+\tint nmsgs = 0, ret;\n+\tu16 hdr = cmd \u003e= 0;\n+\n+\tlockdep_assert_held(\u0026bp-\u003ecpld_lock);\n+\n+\tadap = bp-\u003ecpld_adap;\n+\tif (!adap || !bp-\u003ecpld_buf)\n+\t\treturn -ENODEV;\n+\n+\tif (hdr + wlen \u003e ADVA_CPLD_XFER_MAX || rlen \u003e ADVA_CPLD_XFER_MAX)\n+\t\treturn -EINVAL;\n+\n+\twbuf = bp-\u003ecpld_buf;\n+\trbuf = bp-\u003ecpld_buf + ADVA_CPLD_XFER_MAX;\n+\n+\tif (hdr + wlen) {\n+\t\tif (hdr)\n+\t\t\twbuf[0] = cmd;\n+\t\tif (wdata)\n+\t\t\tmemcpy(wbuf + hdr, wdata, wlen);\n+\t\telse\n+\t\t\tmemset(wbuf + hdr, 0, wlen);\n+\t\tmsgs[nmsgs++] = (struct i2c_msg){\n+\t\t\t.addr  = addr,\n+\t\t\t.flags = 0,\n+\t\t\t.len   = hdr + wlen,\n+\t\t\t.buf   = wbuf,\n+\t\t};\n+\t}\n+\tif (rlen) {\n+\t\tmsgs[nmsgs++] = (struct i2c_msg){\n+\t\t\t.addr  = addr,\n+\t\t\t.flags = I2C_M_RD,\n+\t\t\t.len   = rlen,\n+\t\t\t.buf   = rbuf,\n+\t\t};\n+\t}\n+\n+\tret = __i2c_transfer(adap, msgs, nmsgs);\n+\tif (ret != nmsgs)\n+\t\treturn (ret \u003c 0) ? ret : -EIO;\n+\n+\tif (rdata \u0026\u0026 rlen)\n+\t\tmemcpy(rdata, rbuf, rlen);\n+\n+\treturn 0;\n+}\n+\n+/* Hand the segment back, and wait for the firmware to drop the grant before\n+ * the caller unlocks the adapter: a transfer queued behind us would\n+ * otherwise be clocked out while the controller is still on the TMC bus,\n+ * which is what holding the adapter lock across the grant exists to stop.\n+ */\n+static int adva_x1_mblaze_release(struct ptp_ocp *bp)\n+{\n+\tu32 val = 0;\n+\tint i;\n+\n+\tif (!bp-\u003epps_select)\n+\t\treturn 0;\n+\n+\tiowrite32(MBLAZE_RELEASE, \u0026bp-\u003epps_select-\u003ei2c_bus_ctrl);\n+\t/* Flush the posted write, as the acquire path does. */\n+\tioread32(\u0026bp-\u003epps_select-\u003ei2c_bus_ctrl);\n+\n+\tfor (i = 0; i \u003c MBLAZE_RETRIES; i++) {\n+\t\tval = ioread32(\u0026bp-\u003epps_select-\u003ei2c_bus_ctrl);\n+\t\tif ((val \u0026 MBLAZE_GRANT_MASK) != MBLAZE_GRANT)\n+\t\t\treturn 0;\n+\t\tusleep_range(MBLAZE_RETRY_US, MBLAZE_RETRY_US + 1000);\n+\t}\n+\n+\tdev_err(\u0026bp-\u003epdev-\u003edev,\n+\t\t\"TMC bus still granted after release, i2c_bus_ctrl 0x%08x\\n\",\n+\t\tval);\n+\n+\treturn -ETIMEDOUT;\n+}\n+\n+/* Acquire the shared I2C bus from the MicroBlaze firmware.  Returns with no\n+ * request outstanding on failure, so the firmware is never left granting a\n+ * segment to a host that has given up waiting for it.\n+ */\n+static int adva_x1_mblaze_acquire(struct ptp_ocp *bp)\n+{\n+\tu32 val;\n+\tint i;\n+\n+\tif (!bp-\u003epps_select)\n+\t\treturn -ENODEV;\n+\n+\t/* Drop a request left by a caller that died mid-sequence; cpld_lock\n+\t * keeps live ones out.  The read back only flushes the posted write.\n+\t */\n+\tiowrite32(0, \u0026bp-\u003epps_select-\u003ei2c_bus_ctrl);\n+\tioread32(\u0026bp-\u003epps_select-\u003ei2c_bus_ctrl);\n+\n+\tiowrite32(MBLAZE_REQUEST, \u0026bp-\u003epps_select-\u003ei2c_bus_ctrl);\n+\tfor (i = 0; i \u003c MBLAZE_RETRIES; i++) {\n+\t\tusleep_range(MBLAZE_RETRY_US, MBLAZE_RETRY_US + 1000);\n+\t\tval = ioread32(\u0026bp-\u003epps_select-\u003ei2c_bus_ctrl);\n+\t\tif (val == MBLAZE_GRANTED)\n+\t\t\treturn 0;\n+\t}\n+\n+\t/* Drop the request we gave up on.  Any error from the hand-back is\n+\t * subsumed by the -ETIMEDOUT we are already returning.\n+\t */\n+\tadva_x1_mblaze_release(bp);\n+\treturn -ETIMEDOUT;\n+}\n+\n+/* Route the host controller back to the EEPROMs and release the adapter.\n+ * Safe after a failed claim: it also clears a request that was never granted.\n+ *\n+ * The adapter is unlocked even when the hand-back timed out: keeping the\n+ * root lock would stall every other user of the controller for good, with\n+ * no way to recover it.  The error is returned instead, so the operation\n+ * that held the claim fails rather than reporting success over a bus that\n+ * may still be routed to the TMC segment.\n+ */\n+static int adva_x1_bus_release(struct ptp_ocp *bp)\n+{\n+\tstruct i2c_adapter *adap = bp-\u003ecpld_adap;\n+\tint err;\n+\n+\tif (!adap)\n+\t\treturn 0;\n+\n+\terr = adva_x1_mblaze_release(bp);\n+\tbp-\u003ecpld_adap = NULL;\n+\tkfree(bp-\u003ecpld_buf);\n+\tbp-\u003ecpld_buf = NULL;\n+\ti2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER);\n+\ti2c_put_adapter(adap);\n+\n+\treturn err;\n+}\n+\n+static int adva_x1_i2c_adap_match(struct device *dev, const void *data)\n+{\n+\treturn !!i2c_verify_adapter(dev);\n+}\n+\n+/*\n+ * Cache the adapter the CPLD hangs off.  ptp_ocp_i2c_notifier_call() misses\n+ * it when the i2c controller driver is already loaded: the adapter is then\n+ * added from inside platform_device_register(), before bp-\u003ei2c_ctrl is set.\n+ * Only direct children are searched, so a mux adapter cannot match.\n+ *\n+ * Called from the worker rather than once from probe: device_add() notifies\n+ * before it links the device to its parent, so with asynchronous probing\n+ * both the notifier and a single lookup here can miss the same adapter.\n+ * Retrying costs a short klist walk per tick until one of them succeeds.\n+ */\n+static void adva_x1_cache_i2c_adap(struct ptp_ocp *bp)\n+{\n+\tstruct device *child;\n+\n+\tif (!bp-\u003ehas_cpld || !bp-\u003ei2c_ctrl ||\n+\t    READ_ONCE(bp-\u003ecpld_i2c_adap_nr) \u003e= 0)\n+\t\treturn;\n+\n+\tchild = device_find_child(\u0026bp-\u003ei2c_ctrl-\u003edev, NULL,\n+\t\t\t\t  adva_x1_i2c_adap_match);\n+\tif (!child)\n+\t\treturn;\n+\n+\t/* Re-test under the lock so this does not overwrite a number the\n+\t * notifier published meanwhile.  It cannot tell that apart from a\n+\t * number the notifier has just invalidated, so an adapter removed in\n+\t * this window can still be cached; adva_x1_bus_claim() rejects it on\n+\t * the parent check and forgets it, and the next tick looks again.\n+\t */\n+\tscoped_guard(spinlock, \u0026bp-\u003ecpld_adap_lock) {\n+\t\tif (bp-\u003ecpld_i2c_adap_nr \u003c 0)\n+\t\t\tbp-\u003ecpld_i2c_adap_nr = i2c_verify_adapter(child)-\u003enr;\n+\t}\n+\n+\tput_device(child);\n+}\n+\n+/*\n+ * Claim the TMC bus.  The adapter lock is held across the handshake to keep\n+ * the EEPROM, nvmem and at24 paths off the controller while it is routed\n+ * away from the EEPROMs; an EEPROM read blocks until the claim is dropped.\n+ */\n+static int adva_x1_bus_claim(struct ptp_ocp *bp)\n+{\n+\tstruct i2c_adapter *adap;\n+\tint ret;\n+\n+\tlockdep_assert_held(\u0026bp-\u003ecpld_lock);\n+\n+\tadap = i2c_get_adapter(READ_ONCE(bp-\u003ecpld_i2c_adap_nr));\n+\tif (!adap)\n+\t\treturn -ENODEV;\n+\n+\t/* The number is freed before the notifier clears it, so it can\n+\t * already be another adapter's.  Check this is still ours, and drop\n+\t * a number that is not: otherwise every later claim fails the same\n+\t * way, where forgetting it lets the worker look the adapter up again.\n+\t */\n+\tif (!bp-\u003ei2c_ctrl || adap-\u003edev.parent != \u0026bp-\u003ei2c_ctrl-\u003edev) {\n+\t\tscoped_guard(spinlock, \u0026bp-\u003ecpld_adap_lock) {\n+\t\t\tif (bp-\u003ecpld_i2c_adap_nr == adap-\u003enr)\n+\t\t\t\tbp-\u003ecpld_i2c_adap_nr = -1;\n+\t\t}\n+\t\ti2c_put_adapter(adap);\n+\t\treturn -ENODEV;\n+\t}\n+\n+\t/* One scratch buffer per claim rather than per transfer: a claim can\n+\t * cover many transfers.\n+\t */\n+\tbp-\u003ecpld_buf = kzalloc(2 * ADVA_CPLD_XFER_MAX, GFP_KERNEL);\n+\tif (!bp-\u003ecpld_buf) {\n+\t\ti2c_put_adapter(adap);\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\ti2c_lock_bus(adap, I2C_LOCK_ROOT_ADAPTER);\n+\tbp-\u003ecpld_adap = adap;\n+\n+\tret = adva_x1_mblaze_acquire(bp);\n+\tif (ret)\n+\t\tadva_x1_bus_release(bp);\t/* keeps the acquire error */\n+\n+\treturn ret;\n+}\n+\n+/* Select a mux channel, or deselect all with ch \u003c 0 - the power-on state.\n+ * The mux is on the TMC bus, so what it is left set to never affects the\n+ * EEPROM paths.\n+ */\n+static int adva_x1_mux_select(struct ptp_ocp *bp, int ch)\n+{\n+\tu8 val = (ch \u003e= 0) ? BIT(ch) : 0;\n+\n+\treturn adva_x1_i2c_xfer(bp, ADVA_MUX_ADDR, val, NULL, 0, NULL, 0);\n+}\n+\n+/*\n+ * Argument bytes that follow an ISC opcode.  Returns NULL with @nargs set\n+ * when the arguments are all zero: adva_x1_i2c_xfer() zeroes the buffer.\n+ *\n+ * EN_CFG_TP, DIS_CFG and REFRESH take two operand bytes here where the SPI\n+ * drivers in drivers/fpga send three.  These are the frames the part on this\n+ * board answers: the sequence below has programmed and refreshed it\n+ * successfully over I2C, so the counts are kept as validated rather than\n+ * aligned with the SPI framing.\n+ */\n+static const u8 *adva_x1_cpld_args(u8 cmd, u8 *nargs)\n+{\n+\tstatic const u8 en_cfg_tp[] = { 0x08, 0x00 };\n+\t/* cfg sector only */\n+\tstatic const u8 erase_cfg[] = { 0x04, 0x00, 0x00 };\n+\n+\tswitch (cmd) {\n+\tcase CPLD_CMD_EN_CFG_TP:\n+\t\t*nargs = sizeof(en_cfg_tp);\n+\t\treturn en_cfg_tp;\n+\tcase CPLD_CMD_ERASE:\n+\t\t*nargs = sizeof(erase_cfg);\n+\t\treturn erase_cfg;\n+\tcase CPLD_CMD_RESET_ADDR:\n+\tcase CPLD_CMD_SET_DONE:\n+\t\t*nargs = 3;\n+\t\treturn NULL;\n+\tcase CPLD_CMD_DIS_CFG:\n+\tcase CPLD_CMD_REFRESH:\n+\t\t*nargs = 2;\n+\t\treturn NULL;\n+\tdefault:\n+\t\t*nargs = 0;\n+\t\treturn NULL;\n+\t}\n+}\n+\n+/* Send an ISC command with the fixed arguments that belong to it. */\n+static int adva_x1_cpld_write(struct ptp_ocp *bp, u8 cmd)\n+{\n+\tconst u8 *args;\n+\tu8 nargs;\n+\n+\targs = adva_x1_cpld_args(cmd, \u0026nargs);\n+\n+\treturn adva_x1_i2c_xfer(bp, ADVA_CPLD_ADDR, cmd, args, nargs, NULL, 0);\n+}\n+\n+/*\n+ * Send a 4-byte command and read back without an intermediate STOP: two\n+ * messages in one transfer is the Lattice write -\u003e repeated START -\u003e read,\n+ * so no protocol-mangling flag is needed.\n+ */\n+static int adva_x1_cpld_cmd_read(struct ptp_ocp *bp,\n+\t\t\t\t u32 cmd_be, u8 *out, u8 out_len)\n+{\n+\t__be32 cmd = cpu_to_be32(cmd_be);\n+\n+\treturn adva_x1_i2c_xfer(bp, ADVA_CPLD_ADDR, -1, \u0026cmd, 4, out, out_len);\n+}\n+\n+static int adva_x1_cpld_read_status(struct ptp_ocp *bp, u32 *status)\n+{\n+\tu8 buf[4];\n+\tint ret;\n+\n+\tret = adva_x1_cpld_cmd_read(bp, CPLD_CMD_READ_STATUS, buf, 4);\n+\tif (ret)\n+\t\treturn ret;\n+\t*status = get_unaligned_be32(buf);\n+\treturn 0;\n+}\n+\n+/* Poll the status register until the CPLD goes idle, or @max_ms elapses.\n+ * The deadline is on wall time, so the I2C transactions count against it,\n+ * and the status is read once more after it expires before giving up.\n+ */\n+static int adva_x1_cpld_wait_ready(struct ptp_ocp *bp, unsigned int max_ms)\n+{\n+\tu32 status = 0;\n+\tint err = 0, ret;\n+\n+\tret = read_poll_timeout(adva_x1_cpld_read_status, err,\n+\t\t\t\terr || (status \u0026 CPLD_STATUS_FAILED) ||\n+\t\t\t\t!(status \u0026 CPLD_STATUS_BUSY),\n+\t\t\t\tCPLD_POLL_US, max_ms * USEC_PER_MSEC, false,\n+\t\t\t\tbp, \u0026status);\n+\tif (ret)\n+\t\treturn ret;\n+\t/* Keep the transport errno so it reaches userspace as-is; -EIO is\n+\t * reserved for the CPLD itself reporting FAILED.\n+\t */\n+\tif (err)\n+\t\treturn err;\n+\tif (status \u0026 CPLD_STATUS_FAILED)\n+\t\treturn -EIO;\n+\n+\treturn 0;\n+}\n+\n+/* Wait for BUSY to clear.  Unlike adva_x1_cpld_wait_ready() a latched FAILED\n+ * status is not an error here: this is used on the exit path, where an ISC\n+ * command issued while the part is still erasing or programming may not\n+ * latch, so the operation has to be waited out whatever its outcome.\n+ */\n+static int adva_x1_cpld_wait_idle(struct ptp_ocp *bp, unsigned int max_ms)\n+{\n+\tu32 status = 0;\n+\tint err = 0, ret;\n+\n+\tret = read_poll_timeout(adva_x1_cpld_read_status, err,\n+\t\t\t\terr || !(status \u0026 CPLD_STATUS_BUSY),\n+\t\t\t\tCPLD_POLL_US, max_ms * USEC_PER_MSEC, false,\n+\t\t\t\tbp, \u0026status);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\treturn err;\n+}\n+\n+/* Leave transparent configuration mode.\n+ *\n+ * A DIS_CFG issued while the part is still busy may not latch, so the wait\n+ * has to succeed before the write is believed - an ACKed write after a\n+ * timed-out wait says nothing about whether the part left the mode.  Retry\n+ * a few times rather than leaving it latched on one bad attempt; there is\n+ * no other caller that would try again.\n+ */\n+static void adva_x1_cpld_exit_config(struct ptp_ocp *bp)\n+{\n+\tint err, i;\n+\n+\tif (!bp-\u003ecpld_in_config_mode)\n+\t\treturn;\n+\n+\tfor (i = 0; i \u003c CPLD_EXIT_CFG_TRIES; i++) {\n+\t\terr = adva_x1_cpld_wait_idle(bp, CPLD_ERASE_MS);\n+\t\tif (!err)\n+\t\t\terr = adva_x1_cpld_write(bp, CPLD_CMD_DIS_CFG);\n+\t\tif (!err) {\n+\t\t\tbp-\u003ecpld_in_config_mode = false;\n+\t\t\treturn;\n+\t\t}\n+\t}\n+\n+\tdev_err(\u0026bp-\u003epdev-\u003edev, \"CPLD left in configuration mode: %d\\n\", err);\n+}\n+\n+/*\n+ * Read the Lattice device ID and the image USERCODE under one bus claim.\n+ * Done once, off the unprivileged devlink path, which reports the cached\n+ * values.  -EBUSY means cpld_lock is held, so the caller can retry rather\n+ * than wait behind a long CPLD operation.\n+ */\n+static int adva_x1_cpld_read_id(struct ptp_ocp *bp)\n+{\n+\tu8 data[4];\n+\tint err, ret;\n+\n+\tif (!mutex_trylock(\u0026bp-\u003ecpld_lock))\n+\t\treturn -EBUSY;\n+\n+\tret = adva_x1_bus_claim(bp);\n+\tif (ret)\n+\t\tgoto out;\n+\t/* A select reported as failed may still have been ACKed, so the\n+\t * deselect runs either way rather than handing the mux back with a\n+\t * channel possibly left open.\n+\t */\n+\tret = adva_x1_mux_select(bp, ADVA_MUX_CHANNEL);\n+\tif (ret)\n+\t\tgoto deselect;\n+\tret = adva_x1_cpld_cmd_read(bp, CPLD_CMD_READ_ID, data, 4);\n+\tif (ret)\n+\t\tgoto deselect;\n+\t/* Publish the ID before the USERCODE is attempted: a part that does\n+\t * not answer 0xC0 must not cost us the device ID as well.\n+\t */\n+\tWRITE_ONCE(bp-\u003ecpld_id, get_unaligned_be32(data));\n+\n+\tret = adva_x1_cpld_cmd_read(bp, CPLD_CMD_READ_USERCODE, data, 4);\n+\tif (ret)\n+\t\tgoto deselect;\n+\tWRITE_ONCE(bp-\u003ecpld_usercode, get_unaligned_be32(data));\n+\t/* Pairs with the acquire in ptp_ocp_devlink_info_get(): the value has\n+\t * to be visible before the flag that declares it valid.\n+\t */\n+\tsmp_store_release(\u0026bp-\u003ecpld_usercode_ok, true);\n+deselect:\n+\terr = adva_x1_mux_select(bp, -1);\n+\tif (!ret)\n+\t\tret = err;\n+\terr = adva_x1_bus_release(bp);\n+\tif (!ret)\n+\t\tret = err;\n+out:\n+\t/* Under cpld_lock, so an operation that resets this bookkeeping\n+\t * while holding the lock cannot have it overwritten afterwards by a\n+\t * worker that had already finished reading.\n+\t */\n+\tif (!ret || ++bp-\u003ecpld_id_attempts \u003e= CPLD_ID_MAX_ATTEMPTS)\n+\t\tbp-\u003ecpld_id_tried = true;\n+\tmutex_unlock(\u0026bp-\u003ecpld_lock);\n+\tif (ret)\n+\t\tdev_dbg(\u0026bp-\u003epdev-\u003edev,\n+\t\t\t\"CPLD device ID unavailable: %d\\n\", ret);\n+\n+\treturn ret;\n+}\n+\n+/* cpld_status - show the flags set in the TAP CPLD status register. */\n+static ssize_t\n+cpld_status_show(struct device *dev, struct device_attribute *attr,\n+\t\t char *buf)\n+{\n+\tstruct ptp_ocp *bp = dev_get_drvdata(dev);\n+\tint count = 0;\n+\tu32 st = 0;\n+\tint err, ret;\n+\n+\t/* A CPLD operation can hold cpld_lock a long time; stay killable. */\n+\tret = mutex_lock_interruptible(\u0026bp-\u003ecpld_lock);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = adva_x1_bus_claim(bp);\n+\tif (ret)\n+\t\tgoto out;\n+\tret = adva_x1_mux_select(bp, ADVA_MUX_CHANNEL);\n+\tif (ret)\n+\t\tgoto deselect;\n+\tret = adva_x1_cpld_read_status(bp, \u0026st);\n+deselect:\n+\terr = adva_x1_mux_select(bp, -1);\n+\tif (!ret)\n+\t\tret = err;\n+\terr = adva_x1_bus_release(bp);\n+\tif (!ret)\n+\t\tret = err;\n+out:\n+\tmutex_unlock(\u0026bp-\u003ecpld_lock);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/* Flags: the names of the bits that are set, nothing when none is,\n+\t * rather than a value per bit in one file.\n+\t */\n+\tif (st \u0026 CPLD_STATUS_DONE)\n+\t\tcount += sysfs_emit_at(buf, count, \"done\");\n+\tif (st \u0026 CPLD_STATUS_BUSY)\n+\t\tcount += sysfs_emit_at(buf, count, \"%sbusy\", count ? \" \" : \"\");\n+\tif (st \u0026 CPLD_STATUS_FAILED)\n+\t\tcount += sysfs_emit_at(buf, count, \"%sfailed\",\n+\t\t\t\t       count ? \" \" : \"\");\n+\n+\treturn count + sysfs_emit_at(buf, count, \"\\n\");\n+}\n+static DEVICE_ATTR_ADMIN_RO(cpld_status);\n+\n+/*\n+ * Program the CPLD configuration flash from @fw and activate it.  Selected\n+ * by the \"fw.cpld\" flash component; the SPI flash keeps the default path.\n+ * Runs under cpld_lock with the i2c adapter lock held, so an EEPROM read\n+ * blocks for as long as programming takes.\n+ */\n+static int adva_x1_cpld_flash(struct ptp_ocp *bp, struct devlink *devlink,\n+\t\t\t      const struct firmware *fw,\n+\t\t\t      struct netlink_ext_ack *extack)\n+{\n+\tsize_t offset;\n+\tint err, ret;\n+\tu32 st;\n+\n+\tif (!fw-\u003esize || fw-\u003esize % CPLD_PAGE_SIZE) {\n+\t\tNL_SET_ERR_MSG_MOD(extack,\n+\t\t\t\t   \"image must be a whole number of 16-byte pages\");\n+\t\treturn -EINVAL;\n+\t}\n+\tif (fw-\u003esize \u003e CPLD_MAX_IMAGE_SZ) {\n+\t\tNL_SET_ERR_MSG_MOD(extack, \"image too large for this part\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tmutex_lock(\u0026bp-\u003ecpld_lock);\n+\n+\terr = adva_x1_bus_claim(bp);\n+\tif (err)\n+\t\tgoto unlock;\n+\t/* A select reported as failed may still have been ACKed, so hand the\n+\t * mux back deselected either way.\n+\t */\n+\terr = adva_x1_mux_select(bp, ADVA_MUX_CHANNEL);\n+\tif (err)\n+\t\tgoto deselect;\n+\n+\t/* A previous flash may have failed to leave configuration mode.  Now\n+\t * that the bus is claimed again, retry the exit before re-entering;\n+\t * a no-op when the flag is already clear.\n+\t */\n+\tadva_x1_cpld_exit_config(bp);\n+\n+\t/* Set before EN_CFG_TP, not after: the CPLD may have entered config\n+\t * mode even if the write errors or the wait times out, and only this\n+\t * makes the exit path send DIS_CFG.  A stray DIS_CFG is harmless;\n+\t * leaving config mode enabled is not.\n+\t */\n+\tbp-\u003ecpld_in_config_mode = true;\n+\n+\terr = adva_x1_cpld_write(bp, CPLD_CMD_EN_CFG_TP);\n+\tif (!err)\n+\t\terr = adva_x1_cpld_wait_ready(bp, 5000);\n+\tif (err)\n+\t\tgoto exit_config;\n+\n+\t/* Confirm the part really entered configuration mode.  An enable\n+\t * frame that did not latch leaves an idle part reporting neither\n+\t * BUSY nor FAILED, the erase and page writes are ignored, and DONE\n+\t * is still set from the old image - so every later check passes and\n+\t * the update would be reported successful with the flash untouched.\n+\t */\n+\terr = adva_x1_cpld_read_status(bp, \u0026st);\n+\tif (err)\n+\t\tgoto exit_config;\n+\tif (!(st \u0026 CPLD_STATUS_ENAB)) {\n+\t\tdev_err(\u0026bp-\u003epdev-\u003edev,\n+\t\t\t\"CPLD did not enter configuration mode, status 0x%08x\\n\",\n+\t\t\tst);\n+\t\tNL_SET_ERR_MSG_MOD(extack,\n+\t\t\t\t   \"CPLD did not enter configuration mode\");\n+\t\terr = -EIO;\n+\t\tgoto exit_config;\n+\t}\n+\n+\tdevlink_flash_update_status_notify(devlink, \"Erasing\",\n+\t\t\t\t\t   ADVA_CPLD_COMPONENT, 0, 0);\n+\terr = adva_x1_cpld_write(bp, CPLD_CMD_ERASE);\n+\tif (!err)\n+\t\terr = adva_x1_cpld_wait_ready(bp, CPLD_ERASE_MS);\n+\tif (err)\n+\t\tgoto exit_config;\n+\n+\t/* The old image is gone from here on, so stop reporting its\n+\t * identity even if the rest of the sequence fails.  Written under\n+\t * cpld_lock, which adva_x1_cpld_read_id() also holds across its own\n+\t * bookkeeping, so the worker cannot resurrect any of it.\n+\t */\n+\tWRITE_ONCE(bp-\u003ecpld_id, 0);\n+\tWRITE_ONCE(bp-\u003ecpld_usercode_ok, false);\n+\tbp-\u003ecpld_id_tried = false;\n+\tbp-\u003ecpld_id_attempts = 0;\n+\n+\terr = adva_x1_cpld_write(bp, CPLD_CMD_RESET_ADDR);\n+\tif (err)\n+\t\tgoto exit_config;\n+\n+\tfor (offset = 0; offset \u003c fw-\u003esize; offset += CPLD_PAGE_SIZE) {\n+\t\tu8 args[3 + CPLD_PAGE_SIZE] = { 0x00, 0x00, 0x01 };\n+\n+\t\t/* The loop holds cpld_lock and the i2c root lock for the\n+\t\t * whole image, so give a dying task a way out.  The part is\n+\t\t * left unconfigured, which is recoverable: fw.cpld stays\n+\t\t * advertised so the image can be written again.\n+\t\t */\n+\t\tif (fatal_signal_pending(current)) {\n+\t\t\terr = -EINTR;\n+\t\t\tgoto exit_config;\n+\t\t}\n+\n+\t\tmemcpy(\u0026args[3], fw-\u003edata + offset, CPLD_PAGE_SIZE);\n+\t\terr = adva_x1_i2c_xfer(bp, ADVA_CPLD_ADDR, CPLD_CMD_WRITE_PAGE,\n+\t\t\t\t       args, sizeof(args), NULL, 0);\n+\t\tif (!err)\n+\t\t\terr = adva_x1_cpld_wait_ready(bp, 100);\n+\t\tif (err)\n+\t\t\tgoto exit_config;\n+\n+\t\tif (!(offset % (CPLD_PAGE_SIZE * 64)))\n+\t\t\tdevlink_flash_update_status_notify(devlink,\n+\t\t\t\t\t\t\t   \"Programming\",\n+\t\t\t\t\t\t\t   ADVA_CPLD_COMPONENT,\n+\t\t\t\t\t\t\t   offset, fw-\u003esize);\n+\t}\n+\tdevlink_flash_update_status_notify(devlink, \"Programming\",\n+\t\t\t\t\t   ADVA_CPLD_COMPONENT,\n+\t\t\t\t\t   fw-\u003esize, fw-\u003esize);\n+\n+\terr = adva_x1_cpld_write(bp, CPLD_CMD_SET_DONE);\n+\tif (!err)\n+\t\terr = adva_x1_cpld_wait_ready(bp, 1000);\n+\tif (err)\n+\t\tgoto exit_config;\n+\n+\terr = adva_x1_cpld_read_status(bp, \u0026st);\n+\tif (err)\n+\t\tgoto exit_config;\n+\tif (!(st \u0026 CPLD_STATUS_DONE)) {\n+\t\tdev_err(\u0026bp-\u003epdev-\u003edev,\n+\t\t\t\"CPLD SET_DONE left status 0x%08x\\n\", st);\n+\t\tNL_SET_ERR_MSG_MOD(extack, \"CPLD did not accept the image\");\n+\t\terr = -EIO;\n+\t\tgoto exit_config;\n+\t}\n+\n+\tdevlink_flash_update_status_notify(devlink, \"Activating\",\n+\t\t\t\t\t   ADVA_CPLD_COMPONENT, 0, 0);\n+\terr = adva_x1_cpld_write(bp, CPLD_CMD_REFRESH);\n+\tif (err)\n+\t\tgoto exit_config;\n+\n+\t/* REFRESH reboots the CPLD out of configuration mode, so the exit\n+\t * path must not send DIS_CFG afterwards even if a check below fails.\n+\t */\n+\tbp-\u003ecpld_in_config_mode = false;\n+\n+\t/* The new image is already running, so a segment that is not back\n+\t * yet must not be reported as a failed update: retry the reselect\n+\t * rather than sampling the mux once at a fixed delay.\n+\t */\n+\tmsleep(1500);\n+\terr = read_poll_timeout(adva_x1_mux_select, err, !err, CPLD_POLL_US,\n+\t\t\t\t3000 * USEC_PER_MSEC, false,\n+\t\t\t\tbp, ADVA_MUX_CHANNEL);\n+\tif (err)\n+\t\tgoto deselect;\n+\n+\terr = adva_x1_cpld_wait_ready(bp, 3000);\n+\tif (err)\n+\t\tgoto deselect;\n+\n+\t/* Require DONE set, not busy and no error code, as machxo2-spi.c does\n+\t * after a refresh: without it a CRC or preamble error reads back as a\n+\t * successful update.\n+\t */\n+\terr = adva_x1_cpld_read_status(bp, \u0026st);\n+\tif (err)\n+\t\tgoto deselect;\n+\tif (!(st \u0026 CPLD_STATUS_DONE) || (st \u0026 CPLD_STATUS_BUSY) ||\n+\t    (st \u0026 CPLD_STATUS_ERR)) {\n+\t\tdev_err(\u0026bp-\u003epdev-\u003edev,\n+\t\t\t\"CPLD refresh left status 0x%08x\\n\", st);\n+\t\tNL_SET_ERR_MSG_MOD(extack, \"CPLD did not come back configured\");\n+\t\terr = -EIO;\n+\t\tgoto deselect;\n+\t}\n+\n+exit_config:\n+\tadva_x1_cpld_exit_config(bp);\n+deselect:\n+\tret = adva_x1_mux_select(bp, -1);\n+\tif (!err)\n+\t\terr = ret;\n+\tret = adva_x1_bus_release(bp);\n+\tif (!err)\n+\t\terr = ret;\n+unlock:\n+\tmutex_unlock(\u0026bp-\u003ecpld_lock);\n+\n+\treturn err;\n+}\n+\n static struct attribute *adva_timecard_attrs[] = {\n \t\u0026dev_attr_serialnum.attr,\n \t\u0026dev_attr_gnss_sync.attr,\n@@ -4274,6 +5155,7 @@ static struct attribute *adva_timecard_x1_attrs[] = {\n \t\u0026dev_attr_ts_window_adjust.attr,\n \t\u0026dev_attr_utc_tai_offset.attr,\n \t\u0026dev_attr_tod_correction.attr,\n+\t\u0026dev_attr_cpld_status.attr,\n \tNULL,\n };\n \n@@ -4904,6 +5786,7 @@ ptp_ocp_detach(struct ptp_ocp *bp)\n \t\tclk_hw_unregister_fixed_rate(bp-\u003ei2c_clk);\n \tif (bp-\u003en_irqs)\n \t\tpci_free_irq_vectors(bp-\u003epdev);\n+\tmutex_destroy(\u0026bp-\u003ecpld_lock);\n \tdevice_unregister(\u0026bp-\u003edev);\n }\n \n@@ -5052,6 +5935,17 @@ ptp_ocp_sync_work(struct work_struct *work)\n \n \tbp-\u003esync = sync;\n \n+\t/* Resolve the adapter here rather than once in probe, where it can\n+\t * race the adapter's own registration, and read the ID as soon as it\n+\t * turns up.  A claim can fail transiently - the firmware may not\n+\t * grant the segment straight after power-up - so adva_x1_cpld_read_id()\n+\t * retries a bounded number of times before giving up.\n+\t */\n+\tadva_x1_cache_i2c_adap(bp);\n+\tif (bp-\u003ehas_cpld \u0026\u0026 !READ_ONCE(bp-\u003ecpld_id_tried) \u0026\u0026\n+\t    READ_ONCE(bp-\u003ecpld_i2c_adap_nr) \u003e= 0)\n+\t\tadva_x1_cpld_read_id(bp);\n+\n \tqueue_delayed_work(system_power_efficient_wq, \u0026bp-\u003esync_work, HZ);\n }\n \n@@ -5080,6 +5974,15 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)\n \tif (err)\n \t\tgoto out_disable;\n \n+\t/* Before the first error path that calls ptp_ocp_detach(), so\n+\t * mutex_destroy() runs on an initialised mutex, and before\n+\t * ptp_ocp_register_resources(), so this sentinel cannot overwrite an\n+\t * adapter number the i2c notifier stores during registration.\n+\t */\n+\tmutex_init(\u0026bp-\u003ecpld_lock);\n+\tspin_lock_init(\u0026bp-\u003ecpld_adap_lock);\n+\tbp-\u003ecpld_i2c_adap_nr = -1;\n+\n \tINIT_DELAYED_WORK(\u0026bp-\u003esync_work, ptp_ocp_sync_work);\n \n \t/* compat mode.\n@@ -5119,12 +6022,12 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)\n \tif (IS_ERR(bp-\u003edpll)) {\n \t\terr = PTR_ERR(bp-\u003edpll);\n \t\tdev_err(\u0026pdev-\u003edev, \"dpll_device_alloc failed\\n\");\n-\t\tgoto out;\n+\t\tgoto out_devlink;\n \t}\n \n \terr = dpll_device_register(bp-\u003edpll, DPLL_TYPE_PPS, \u0026dpll_ops, bp);\n \tif (err)\n-\t\tgoto out;\n+\t\tgoto out_dpll_put;\n \n \tfor (i = 0; i \u003c OCP_SMA_NUM; i++) {\n \t\tbp-\u003esma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE,\n@@ -5150,7 +6053,16 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)\n \t\tdpll_pin_unregister(bp-\u003edpll, bp-\u003esma[i].dpll_pin, \u0026dpll_pins_ops, \u0026bp-\u003esma[i]);\n \t\tdpll_pin_put(bp-\u003esma[i].dpll_pin, \u0026bp-\u003esma[i].tracker);\n \t}\n+\t/* dpll_device_register() takes a second reference and stores bp; only\n+\t * dpll_device_unregister() drops it.  Without this the device stays\n+\t * visible with a priv pointer into storage devlink_free() will release.\n+\t */\n+\tdpll_device_unregister(bp-\u003edpll, \u0026dpll_ops, bp);\n+out_dpll_put:\n \tdpll_device_put(bp-\u003edpll, \u0026bp-\u003etracker);\n+out_devlink:\n+\t/* detach() destroys cpld_lock; no devlink op may still reach it */\n+\tdevlink_unregister(devlink);\n out:\n \tptp_ocp_detach(bp);\n out_disable:\n@@ -5196,6 +6108,7 @@ ptp_ocp_i2c_notifier_call(struct notifier_block *nb,\n \t\t\t  unsigned long action, void *data)\n {\n \tstruct device *dev, *child = data;\n+\tstruct i2c_adapter *adap;\n \tstruct ptp_ocp *bp;\n \tbool add;\n \n@@ -5219,11 +6132,25 @@ ptp_ocp_i2c_notifier_call(struct notifier_block *nb,\n \n found:\n \tbp = dev_get_drvdata(dev);\n-\tif (add)\n+\tadap = i2c_verify_adapter(child);\n+\tif (add) {\n \t\tptp_ocp_symlink(bp, child, \"i2c\");\n-\telse\n+\t\t/* Only the card's own controller: a mux child added on it\n+\t\t * reaches ptp_ocp through the same walk.  Numbers are\n+\t\t * recycled, so the claim re-checks the parent itself.\n+\t\t */\n+\t\tif (bp-\u003ei2c_ctrl \u0026\u0026 adap-\u003edev.parent == \u0026bp-\u003ei2c_ctrl-\u003edev) {\n+\t\t\tscoped_guard(spinlock, \u0026bp-\u003ecpld_adap_lock)\n+\t\t\t\tbp-\u003ecpld_i2c_adap_nr = adap-\u003enr;\n+\t\t}\n+\t} else {\n+\t\t/* invalidate before free, but only for the cached adapter */\n+\t\tscoped_guard(spinlock, \u0026bp-\u003ecpld_adap_lock) {\n+\t\t\tif (bp-\u003ecpld_i2c_adap_nr == adap-\u003enr)\n+\t\t\t\tbp-\u003ecpld_i2c_adap_nr = -1;\n+\t\t}\n \t\tsysfs_remove_link(\u0026bp-\u003edev.kobj, \"i2c\");\n-\n+\t}\n \treturn 0;\n }\n \n"
}

2/1 2026/09/18 05:12 agent patch-evaluator
0m Model:
core

Args:
null

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "Reasoning": "The patch series adds CPLD status reporting, devlink flash updating, and devlink info support for the ADVA TimeCard X1 in the OpenCompute TimeCard driver (drivers/ptp/ptp_ocp.c). This driver binds exclusively to specific physical PCIe devices (such as Meta TimeCard, ADVA TimeCard X1) which require dedicated hardware (atomic clock/GPS timing PCIe cards) not emulated in standard virtualized fuzzing environments (QEMU/GCE). As such, the modified code is structurally unreachable.",
  "WorthFuzzing": false
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit bf809a1e5e4fa0eb4362d0f29cfa32086c3519c3
Author: syz-cluster <triage@syzkaller.com>
Date:   Fri Sep 18 05:12:44 2026 +0000

    syz-cluster: applied patch under review

diff --git a/Documentation/ABI/testing/sysfs-timecard b/Documentation/ABI/testing/sysfs-timecard
index 3ae41b7634ac9..4ba45c6ee4a36 100644
--- a/Documentation/ABI/testing/sysfs-timecard
+++ b/Documentation/ABI/testing/sysfs-timecard
@@ -11,6 +11,35 @@ Contact:	Jonathan Lemon <jonathan.lemon@gmail.com>
 Description:	This directory contains the attributes of the Nth timecard
 		registered.
 
+What:		/sys/class/timecard/ocpN/cpld_status
+Date:		July 2026
+Contact:	Sagi Maimon <maimon.sagi@gmail.com>
+Description:	(RO, root only) The flags set in the status register of the
+		TAP CPLD, space separated, or an empty line when none is
+		set.  Only present on ADVA x1 TAP boards (PCI ID
+		0xad5a:0x0410).
+
+		==========  ================================================
+		done        the configuration flash holds a valid image and
+			    it is active
+		busy        an internal operation is in progress
+		failed      the last ISC operation failed
+		==========  ================================================
+
+		For example "busy" while an operation runs, or "busy failed"
+		if a failure is latched while another one is in progress.
+
+		A read arbitrates for the shared I2C bus and reprograms the
+		on-card mux, so it is restricted to root.  The Lattice device
+		ID of the CPLD is read by the driver shortly after probe,
+		and again after a successful CPLD update, and reported from
+		that cached value as the fixed "cpld.id" version by
+		devlink dev info.
+
+		New CPLD firmware is programmed with devlink dev flash,
+		selecting the "fw.cpld" component; see
+		Documentation/networking/devlink/ptp_ocp.rst.
+
 What:		/sys/class/timecard/ocpN/available_clock_sources
 Date:		September 2021
 Contact:	Jonathan Lemon <jonathan.lemon@gmail.com>
diff --git a/Documentation/networking/devlink/index.rst b/Documentation/networking/devlink/index.rst
index d4a83fdcff7fe..1af780c811ee2 100644
--- a/Documentation/networking/devlink/index.rst
+++ b/Documentation/networking/devlink/index.rst
@@ -99,6 +99,7 @@ parameters, info versions, and other features it supports.
    nfp
    octeontx2
    prestera
+   ptp_ocp
    qed
    sfc
    stmmac
diff --git a/Documentation/networking/devlink/ptp_ocp.rst b/Documentation/networking/devlink/ptp_ocp.rst
new file mode 100644
index 0000000000000..f94b759d9cd65
--- /dev/null
+++ b/Documentation/networking/devlink/ptp_ocp.rst
@@ -0,0 +1,75 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+========================
+ptp_ocp devlink support
+========================
+
+This document describes the devlink features implemented by the ``ptp_ocp``
+device driver: the info versions it reports and its flash update support.
+
+Info versions
+=============
+
+The ``ptp_ocp`` driver reports the following versions
+
+.. list-table:: devlink info versions implemented
+   :widths: 5 5 90
+
+   * - Name
+     - Type
+     - Description
+   * - ``fw``
+     - running
+     - Version of the firmware running on the card.  Reported as ``loader``
+       instead when the card is running the firmware loader.
+   * - ``board.id``
+     - fixed
+     - Board identifier, read from the on-card EEPROM.
+   * - ``cpld.id``
+     - fixed
+     - Lattice device ID (IDCODE) of the TAP CPLD, formatted as ``0x%08x``.
+       Only present on ADVA TimeCard X1 boards, which are the only ones
+       carrying that CPLD.  Reading it claims the shared I2C bus and
+       reprograms the on-card mux, so the driver does that from its own
+       worker and reports the cached value here; the version is omitted
+       until that read has succeeded.  The read is made once per binding
+       and again after a successful CPLD update.
+   * - ``fw.cpld``
+     - running
+     - USERCODE of the image programmed into the TAP CPLD, formatted as
+       ``0x%08x``.  Read together with ``cpld.id`` and reported the same
+       way.  This is the component name to pass to ``devlink dev flash``
+       to update the CPLD.
+
+Flash update
+============
+
+The driver implements ``devlink dev flash`` for two separate targets,
+selected with the component name.
+
+.. list-table:: Flash components
+   :widths: 20 80
+
+   * - Component
+     - 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.
+   * - ``fw.cpld``
+     - The configuration flash of the TAP CPLD on ADVA TimeCard X1 boards,
+       programmed over I2C with the MachXO3 in-system programming commands
+       and activated with a REFRESH, so the new image runs immediately.
+       The image is the raw configuration bitstream.  The only check the
+       driver makes is that its length is a non-zero multiple of the
+       16-byte page size, so a container such as ``.jed`` has to be
+       converted first rather than passed through - one whose length
+       happens to be a multiple of 16 would be programmed as if it were
+       a bitstream.
+
+Programming the CPLD claims the shared I2C bus for the whole cycle, so
+reads of the card's EEPROM block until it completes.  Progress is reported
+with the standard devlink status notifications.
+
+Example::
+
+    $ devlink dev flash pci/0000:02:00.0 file adva-cpld.bin component fw.cpld
diff --git a/MAINTAINERS b/MAINTAINERS
index 0e04d92d1b098..113f314346177 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -20479,6 +20479,7 @@ OPENCOMPUTE PTP CLOCK DRIVER
 M:	Vadim Fedorenko <vadim.fedorenko@linux.dev>
 L:	netdev@vger.kernel.org
 S:	Maintained
+F:	Documentation/networking/devlink/ptp_ocp.rst
 F:	drivers/ptp/ptp_ocp.c
 
 OPENCORES I2C BUS DRIVER
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 3d26ec1f7b9ec..2802989e84947 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -20,10 +20,14 @@
 #include <linux/spi/altera.h>
 #include <net/devlink.h>
 #include <linux/i2c.h>
+#include <linux/iopoll.h>
 #include <linux/mtd/mtd.h>
 #include <linux/nvmem-consumer.h>
 #include <linux/crc16.h>
 #include <linux/dpll.h>
+#include <linux/unaligned.h>
+#include <linux/delay.h>
+#include <linux/firmware.h>
 
 #define PCI_DEVICE_ID_META_TIMECARD		0x0400
 
@@ -85,6 +89,8 @@ struct ptp_ocp_adva_info {
 	u8				signals_nr;
 	u8				freq_in_nr;
 	const struct ocp_attr_group	*attr_groups;
+	/* x1: TAP CPLD present */
+	bool				has_cpld;
 };
 
 #define OCP_CTRL_ENABLE		BIT(0)
@@ -163,7 +169,8 @@ struct gpio_reg {
 	u32	gpio1;
 	u32	__pad0;
 	u32	gpio2;
-	u32	__pad1;
+	/* adva_x1: I2C bus ownership register; reserved on other variants */
+	u32	i2c_bus_ctrl;
 };
 
 struct irig_master_reg {
@@ -416,6 +423,31 @@ struct ptp_ocp {
 	dpll_tracker tracker;
 	int signals_nr;
 	int freq_in_nr;
+	/* adva_x1 CPLD I2C (internal use only) */
+	/* serialises CPLD operations */
+	struct mutex		cpld_lock;
+	/* guards cpld_i2c_adap_nr against the bus notifier */
+	spinlock_t		cpld_adap_lock;
+	/* I2C adapter nr; -1 if absent.  Under cpld_adap_lock */
+	int			cpld_i2c_adap_nr;
+	/* claimed adapter; valid under cpld_lock */
+	struct i2c_adapter	*cpld_adap;
+	/* scratch, write half then read half; valid under cpld_lock */
+	u8			*cpld_buf;
+	/* Lattice device ID; 0 if unread */
+	u32			cpld_id;
+	/* USERCODE of the image in the part; valid once cpld_usercode_ok */
+	u32			cpld_usercode;
+	/* cpld_usercode has been read since the last flash */
+	bool			cpld_usercode_ok;
+	/* one-shot ID read finished, successfully or not; under cpld_lock */
+	bool			cpld_id_tried;
+	/* failed ID read attempts so far; under cpld_lock */
+	unsigned int		cpld_id_attempts;
+	/* x1 TAP CPLD present */
+	bool			has_cpld;
+	/* EN_CFG_TP issued but not yet REFRESH'd */
+	bool			cpld_in_config_mode;
 };
 
 #define OCP_REQ_TIMESTAMP	BIT(0)
@@ -452,6 +484,13 @@ static int ptp_ocp_adva_board_init(struct ptp_ocp *bp, struct ocp_resource *r);
 static const struct ocp_sma_op ocp_adva_sma_op;
 static const struct ocp_sma_op ocp_adva_x1_sma_op;
 
+/* Flash component naming the CPLD image, as reported by ->info_get(). */
+#define ADVA_CPLD_COMPONENT	"fw.cpld"
+
+static int adva_x1_cpld_flash(struct ptp_ocp *bp, struct devlink *devlink,
+			      const struct firmware *fw,
+			      struct netlink_ext_ack *extack);
+
 static const struct ocp_attr_group fb_timecard_groups[];
 
 static const struct ocp_attr_group art_timecard_groups[];
@@ -1273,6 +1312,7 @@ static struct ocp_resource ocp_adva_x1_resource[] = {
 			.signals_nr   = 4,
 			.freq_in_nr   = 4,
 			.attr_groups  = adva_timecard_x1_groups,
+			.has_cpld     = true,
 		},
 	},
 	{ }
@@ -2133,6 +2173,21 @@ ptp_ocp_devlink_flash_update(struct devlink *devlink,
 	const char *msg;
 	int err;
 
+	if (params->component) {
+		if (!bp->has_cpld ||
+		    strcmp(params->component, ADVA_CPLD_COMPONENT)) {
+			NL_SET_ERR_MSG_MOD(extack,
+					   "unsupported flash component");
+			return -EOPNOTSUPP;
+		}
+
+		err = adva_x1_cpld_flash(bp, devlink, params->fw, extack);
+		msg = err ? "Flash error" : "Flash complete";
+		devlink_flash_update_status_notify(devlink, msg,
+						   ADVA_CPLD_COMPONENT, 0, 0);
+		return err;
+	}
+
 	dev = ptp_ocp_find_flash(bp);
 	if (!dev) {
 		dev_err(&bp->pdev->dev, "Can't find Flash SPI adapter\n");
@@ -2155,10 +2210,13 @@ static int
 ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
 			 struct netlink_ext_ack *extack)
 {
+	enum devlink_info_version_type ver_type =
+					DEVLINK_INFO_VERSION_TYPE_COMPONENT;
 	struct ptp_ocp *bp = devlink_priv(devlink);
 	const char *fw_image;
 	char buf[32];
 	int err;
+	u32 id;
 
 	fw_image = bp->fw_loader ? "loader" : "fw";
 	sprintf(buf, "%d.%d", bp->fw_tag, bp->fw_version);
@@ -2166,6 +2224,39 @@ ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
 	if (err)
 		return err;
 
+	if (bp->has_cpld) {
+		/* Read by the worker, not here: this command is unprivileged
+		 * and reading the ID claims the I2C bus.  0 means unread -
+		 * skip it rather than fail, devlink discards the whole reply
+		 * on error.
+		 */
+		id = READ_ONCE(bp->cpld_id);
+		if (id) {
+			sprintf(buf, "0x%08x", id);
+			err = devlink_info_version_fixed_put(req, "cpld.id",
+							     buf);
+			if (err)
+				return err;
+		}
+
+		/* The flashable component.  Naming it here is what lets
+		 * "devlink dev flash ... component fw.cpld" through, as the
+		 * core matches the name against the versions reported here,
+		 * so it is reported for every board that has the part and not
+		 * only once its USERCODE has been read: a part left holding a
+		 * bad image answers neither, and gating the component on the
+		 * read would make that state unrecoverable.
+		 */
+		if (smp_load_acquire(&bp->cpld_usercode_ok))
+			sprintf(buf, "0x%08x", READ_ONCE(bp->cpld_usercode));
+		else
+			strscpy(buf, "unknown", sizeof(buf));
+		err = devlink_info_version_running_put_ext(req, "fw.cpld", buf,
+							   ver_type);
+		if (err)
+			return err;
+	}
+
 	if (!bp->has_eeprom_data) {
 		ptp_ocp_read_eeprom(bp);
 		if (!bp->has_eeprom_data)
@@ -3199,6 +3290,8 @@ ptp_ocp_adva_board_init(struct ptp_ocp *bp, struct ocp_resource *r)
 		return err;
 	ptp_ocp_sma_init(bp);
 
+	bp->has_cpld = info->has_cpld;
+
 	return ptp_ocp_init_clock(bp, &info->servo);
 }
 
@@ -4226,6 +4319,794 @@ static const struct ocp_attr_group art_timecard_groups[] = {
 	{ },
 };
 
+/*
+ * adva_x1 TAP CPLD (Lattice LCMXO3LF-2100) helpers.
+ *
+ * The card has two I2C controllers; Linux registers only 0x00150000.
+ * The i2c_bus_ctrl handshake re-routes what each is wired to:
+ *
+ *   grant 0:  0x150000 -> EEPROMs     0x120000 -> TMC or M.2, MB's choice
+ *   grant 1:  0x150000 -> TMC bus     0x120000 -> M.2
+ *
+ * The PCA9548 at 0x74 and the CPLD at 0x40 behind its channel 0 are on the
+ * TMC bus, reachable only while the grant is held.  The EEPROMs are not
+ * behind the adapter for that window, so a CPLD operation holds cpld_lock
+ * and the adapter lock to keep the EEPROM and nvmem paths off it.
+ */
+
+#define ADVA_MUX_ADDR     0x74
+#define ADVA_CPLD_ADDR    0x40
+#define ADVA_MUX_CHANNEL  0
+
+/* Longest command or reply; bounds each half of the per-claim scratch. */
+#define ADVA_CPLD_XFER_MAX 32
+
+/* i2c_bus_ctrl carries a host-written request half and a firmware-written
+ * grant half.  MBLAZE_GRANTED is what a granted register reads while our
+ * request still stands; the release write clears the request half, so from
+ * then on only the grant field can be tested.  Measured on an ADVA
+ * TimeCard X1: the register reads 0x00000012 once the firmware has handed
+ * the segment back, about 670 ms after the release write, so the low half
+ * is not zero then and only the grant field is a valid test.
+ */
+#define MBLAZE_REQUEST    0x0000aaaaU
+#define MBLAZE_GRANTED    0x5555aaaaU
+#define MBLAZE_RELEASE    0x55550000U
+#define MBLAZE_GRANT_MASK 0xffff0000U
+#define MBLAZE_GRANT      0x55550000U
+#define MBLAZE_RETRIES    200
+#define MBLAZE_RETRY_US   10000
+
+/* Lattice LCMXO3LF ISC command codes */
+#define CPLD_CMD_READ_ID      0xE0000000UL
+/* The USERCODE lives in the configuration flash that ERASE wipes, and the
+ * page writes carry it: after programming an image whose JEDEC UH field is
+ * 0x00000004 the part reads back 0x00000004, not an erased value.  So there
+ * is no separate ISC_PROGRAM_USERCODE step here.
+ */
+#define CPLD_CMD_READ_USERCODE 0xC0000000UL
+#define CPLD_CMD_READ_STATUS  0x3C000000UL
+#define CPLD_CMD_EN_CFG_TP    0x74   /* enable config, transparent mode */
+#define CPLD_CMD_DIS_CFG      0x26
+#define CPLD_CMD_ERASE        0x0E
+#define CPLD_CMD_RESET_ADDR   0x46
+#define CPLD_CMD_WRITE_PAGE   0x70
+#define CPLD_CMD_SET_DONE     0x5E
+#define CPLD_CMD_REFRESH      0x79
+#define CPLD_PAGE_SIZE        16
+#define CPLD_POLL_US          10000  /* status poll interval while busy */
+/* Bounds how long a claim can hold the i2c root lock, not image validity:
+ * far above any bitstream this part takes.
+ */
+#define CPLD_MAX_IMAGE_SZ     (256 * 1024)
+#define CPLD_EXIT_CFG_TRIES   3
+#define CPLD_ERASE_MS         15000  /* config sector erase, datasheet max */
+#define CPLD_ID_MAX_ATTEMPTS  10     /* one per sync_work tick */
+
+/* Status register bit positions (Lattice LCMXO3LF datasheet) */
+#define CPLD_STATUS_DONE   BIT(8)
+#define CPLD_STATUS_ENAB   BIT(9)
+#define CPLD_STATUS_BUSY   BIT(12)
+#define CPLD_STATUS_FAILED BIT(13)
+#define CPLD_STATUS_ERR    GENMASK(25, 23)
+
+/*
+ * Issue one I2C transaction on the TMC bus: @cmd if not negative, then
+ * @wlen bytes of @wdata (NULL sends zeros), then @rlen bytes read back.
+ * The message is built in the scratch buffer from adva_x1_bus_claim(), so
+ * a run of transfers costs one allocation, not one each.  I2C_M_DMA_SAFE
+ * is not set: the two halves are not separately aligned, so let the core
+ * bounce.  Caller holds the claim, hence __i2c_transfer().
+ */
+static int adva_x1_i2c_xfer(struct ptp_ocp *bp, u8 addr, int cmd,
+			    const void *wdata, u8 wlen,
+			    void *rdata, u8 rlen)
+{
+	u8 *wbuf, *rbuf;
+	struct i2c_adapter *adap;
+	struct i2c_msg msgs[2];
+	int nmsgs = 0, ret;
+	u16 hdr = cmd >= 0;
+
+	lockdep_assert_held(&bp->cpld_lock);
+
+	adap = bp->cpld_adap;
+	if (!adap || !bp->cpld_buf)
+		return -ENODEV;
+
+	if (hdr + wlen > ADVA_CPLD_XFER_MAX || rlen > ADVA_CPLD_XFER_MAX)
+		return -EINVAL;
+
+	wbuf = bp->cpld_buf;
+	rbuf = bp->cpld_buf + ADVA_CPLD_XFER_MAX;
+
+	if (hdr + wlen) {
+		if (hdr)
+			wbuf[0] = cmd;
+		if (wdata)
+			memcpy(wbuf + hdr, wdata, wlen);
+		else
+			memset(wbuf + hdr, 0, wlen);
+		msgs[nmsgs++] = (struct i2c_msg){
+			.addr  = addr,
+			.flags = 0,
+			.len   = hdr + wlen,
+			.buf   = wbuf,
+		};
+	}
+	if (rlen) {
+		msgs[nmsgs++] = (struct i2c_msg){
+			.addr  = addr,
+			.flags = I2C_M_RD,
+			.len   = rlen,
+			.buf   = rbuf,
+		};
+	}
+
+	ret = __i2c_transfer(adap, msgs, nmsgs);
+	if (ret != nmsgs)
+		return (ret < 0) ? ret : -EIO;
+
+	if (rdata && rlen)
+		memcpy(rdata, rbuf, rlen);
+
+	return 0;
+}
+
+/* Hand the segment back, and wait for the firmware to drop the grant before
+ * the caller unlocks the adapter: a transfer queued behind us would
+ * otherwise be clocked out while the controller is still on the TMC bus,
+ * which is what holding the adapter lock across the grant exists to stop.
+ */
+static int adva_x1_mblaze_release(struct ptp_ocp *bp)
+{
+	u32 val = 0;
+	int i;
+
+	if (!bp->pps_select)
+		return 0;
+
+	iowrite32(MBLAZE_RELEASE, &bp->pps_select->i2c_bus_ctrl);
+	/* Flush the posted write, as the acquire path does. */
+	ioread32(&bp->pps_select->i2c_bus_ctrl);
+
+	for (i = 0; i < MBLAZE_RETRIES; i++) {
+		val = ioread32(&bp->pps_select->i2c_bus_ctrl);
+		if ((val & MBLAZE_GRANT_MASK) != MBLAZE_GRANT)
+			return 0;
+		usleep_range(MBLAZE_RETRY_US, MBLAZE_RETRY_US + 1000);
+	}
+
+	dev_err(&bp->pdev->dev,
+		"TMC bus still granted after release, i2c_bus_ctrl 0x%08x\n",
+		val);
+
+	return -ETIMEDOUT;
+}
+
+/* Acquire the shared I2C bus from the MicroBlaze firmware.  Returns with no
+ * request outstanding on failure, so the firmware is never left granting a
+ * segment to a host that has given up waiting for it.
+ */
+static int adva_x1_mblaze_acquire(struct ptp_ocp *bp)
+{
+	u32 val;
+	int i;
+
+	if (!bp->pps_select)
+		return -ENODEV;
+
+	/* Drop a request left by a caller that died mid-sequence; cpld_lock
+	 * keeps live ones out.  The read back only flushes the posted write.
+	 */
+	iowrite32(0, &bp->pps_select->i2c_bus_ctrl);
+	ioread32(&bp->pps_select->i2c_bus_ctrl);
+
+	iowrite32(MBLAZE_REQUEST, &bp->pps_select->i2c_bus_ctrl);
+	for (i = 0; i < MBLAZE_RETRIES; i++) {
+		usleep_range(MBLAZE_RETRY_US, MBLAZE_RETRY_US + 1000);
+		val = ioread32(&bp->pps_select->i2c_bus_ctrl);
+		if (val == MBLAZE_GRANTED)
+			return 0;
+	}
+
+	/* Drop the request we gave up on.  Any error from the hand-back is
+	 * subsumed by the -ETIMEDOUT we are already returning.
+	 */
+	adva_x1_mblaze_release(bp);
+	return -ETIMEDOUT;
+}
+
+/* Route the host controller back to the EEPROMs and release the adapter.
+ * Safe after a failed claim: it also clears a request that was never granted.
+ *
+ * The adapter is unlocked even when the hand-back timed out: keeping the
+ * root lock would stall every other user of the controller for good, with
+ * no way to recover it.  The error is returned instead, so the operation
+ * that held the claim fails rather than reporting success over a bus that
+ * may still be routed to the TMC segment.
+ */
+static int adva_x1_bus_release(struct ptp_ocp *bp)
+{
+	struct i2c_adapter *adap = bp->cpld_adap;
+	int err;
+
+	if (!adap)
+		return 0;
+
+	err = adva_x1_mblaze_release(bp);
+	bp->cpld_adap = NULL;
+	kfree(bp->cpld_buf);
+	bp->cpld_buf = NULL;
+	i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER);
+	i2c_put_adapter(adap);
+
+	return err;
+}
+
+static int adva_x1_i2c_adap_match(struct device *dev, const void *data)
+{
+	return !!i2c_verify_adapter(dev);
+}
+
+/*
+ * Cache the adapter the CPLD hangs off.  ptp_ocp_i2c_notifier_call() misses
+ * it when the i2c controller driver is already loaded: the adapter is then
+ * added from inside platform_device_register(), before bp->i2c_ctrl is set.
+ * Only direct children are searched, so a mux adapter cannot match.
+ *
+ * Called from the worker rather than once from probe: device_add() notifies
+ * before it links the device to its parent, so with asynchronous probing
+ * both the notifier and a single lookup here can miss the same adapter.
+ * Retrying costs a short klist walk per tick until one of them succeeds.
+ */
+static void adva_x1_cache_i2c_adap(struct ptp_ocp *bp)
+{
+	struct device *child;
+
+	if (!bp->has_cpld || !bp->i2c_ctrl ||
+	    READ_ONCE(bp->cpld_i2c_adap_nr) >= 0)
+		return;
+
+	child = device_find_child(&bp->i2c_ctrl->dev, NULL,
+				  adva_x1_i2c_adap_match);
+	if (!child)
+		return;
+
+	/* Re-test under the lock so this does not overwrite a number the
+	 * notifier published meanwhile.  It cannot tell that apart from a
+	 * number the notifier has just invalidated, so an adapter removed in
+	 * this window can still be cached; adva_x1_bus_claim() rejects it on
+	 * the parent check and forgets it, and the next tick looks again.
+	 */
+	scoped_guard(spinlock, &bp->cpld_adap_lock) {
+		if (bp->cpld_i2c_adap_nr < 0)
+			bp->cpld_i2c_adap_nr = i2c_verify_adapter(child)->nr;
+	}
+
+	put_device(child);
+}
+
+/*
+ * Claim the TMC bus.  The adapter lock is held across the handshake to keep
+ * the EEPROM, nvmem and at24 paths off the controller while it is routed
+ * away from the EEPROMs; an EEPROM read blocks until the claim is dropped.
+ */
+static int adva_x1_bus_claim(struct ptp_ocp *bp)
+{
+	struct i2c_adapter *adap;
+	int ret;
+
+	lockdep_assert_held(&bp->cpld_lock);
+
+	adap = i2c_get_adapter(READ_ONCE(bp->cpld_i2c_adap_nr));
+	if (!adap)
+		return -ENODEV;
+
+	/* The number is freed before the notifier clears it, so it can
+	 * already be another adapter's.  Check this is still ours, and drop
+	 * a number that is not: otherwise every later claim fails the same
+	 * way, where forgetting it lets the worker look the adapter up again.
+	 */
+	if (!bp->i2c_ctrl || adap->dev.parent != &bp->i2c_ctrl->dev) {
+		scoped_guard(spinlock, &bp->cpld_adap_lock) {
+			if (bp->cpld_i2c_adap_nr == adap->nr)
+				bp->cpld_i2c_adap_nr = -1;
+		}
+		i2c_put_adapter(adap);
+		return -ENODEV;
+	}
+
+	/* One scratch buffer per claim rather than per transfer: a claim can
+	 * cover many transfers.
+	 */
+	bp->cpld_buf = kzalloc(2 * ADVA_CPLD_XFER_MAX, GFP_KERNEL);
+	if (!bp->cpld_buf) {
+		i2c_put_adapter(adap);
+		return -ENOMEM;
+	}
+
+	i2c_lock_bus(adap, I2C_LOCK_ROOT_ADAPTER);
+	bp->cpld_adap = adap;
+
+	ret = adva_x1_mblaze_acquire(bp);
+	if (ret)
+		adva_x1_bus_release(bp);	/* keeps the acquire error */
+
+	return ret;
+}
+
+/* Select a mux channel, or deselect all with ch < 0 - the power-on state.
+ * The mux is on the TMC bus, so what it is left set to never affects the
+ * EEPROM paths.
+ */
+static int adva_x1_mux_select(struct ptp_ocp *bp, int ch)
+{
+	u8 val = (ch >= 0) ? BIT(ch) : 0;
+
+	return adva_x1_i2c_xfer(bp, ADVA_MUX_ADDR, val, NULL, 0, NULL, 0);
+}
+
+/*
+ * Argument bytes that follow an ISC opcode.  Returns NULL with @nargs set
+ * when the arguments are all zero: adva_x1_i2c_xfer() zeroes the buffer.
+ *
+ * EN_CFG_TP, DIS_CFG and REFRESH take two operand bytes here where the SPI
+ * drivers in drivers/fpga send three.  These are the frames the part on this
+ * board answers: the sequence below has programmed and refreshed it
+ * successfully over I2C, so the counts are kept as validated rather than
+ * aligned with the SPI framing.
+ */
+static const u8 *adva_x1_cpld_args(u8 cmd, u8 *nargs)
+{
+	static const u8 en_cfg_tp[] = { 0x08, 0x00 };
+	/* cfg sector only */
+	static const u8 erase_cfg[] = { 0x04, 0x00, 0x00 };
+
+	switch (cmd) {
+	case CPLD_CMD_EN_CFG_TP:
+		*nargs = sizeof(en_cfg_tp);
+		return en_cfg_tp;
+	case CPLD_CMD_ERASE:
+		*nargs = sizeof(erase_cfg);
+		return erase_cfg;
+	case CPLD_CMD_RESET_ADDR:
+	case CPLD_CMD_SET_DONE:
+		*nargs = 3;
+		return NULL;
+	case CPLD_CMD_DIS_CFG:
+	case CPLD_CMD_REFRESH:
+		*nargs = 2;
+		return NULL;
+	default:
+		*nargs = 0;
+		return NULL;
+	}
+}
+
+/* Send an ISC command with the fixed arguments that belong to it. */
+static int adva_x1_cpld_write(struct ptp_ocp *bp, u8 cmd)
+{
+	const u8 *args;
+	u8 nargs;
+
+	args = adva_x1_cpld_args(cmd, &nargs);
+
+	return adva_x1_i2c_xfer(bp, ADVA_CPLD_ADDR, cmd, args, nargs, NULL, 0);
+}
+
+/*
+ * Send a 4-byte command and read back without an intermediate STOP: two
+ * messages in one transfer is the Lattice write -> repeated START -> read,
+ * so no protocol-mangling flag is needed.
+ */
+static int adva_x1_cpld_cmd_read(struct ptp_ocp *bp,
+				 u32 cmd_be, u8 *out, u8 out_len)
+{
+	__be32 cmd = cpu_to_be32(cmd_be);
+
+	return adva_x1_i2c_xfer(bp, ADVA_CPLD_ADDR, -1, &cmd, 4, out, out_len);
+}
+
+static int adva_x1_cpld_read_status(struct ptp_ocp *bp, u32 *status)
+{
+	u8 buf[4];
+	int ret;
+
+	ret = adva_x1_cpld_cmd_read(bp, CPLD_CMD_READ_STATUS, buf, 4);
+	if (ret)
+		return ret;
+	*status = get_unaligned_be32(buf);
+	return 0;
+}
+
+/* Poll the status register until the CPLD goes idle, or @max_ms elapses.
+ * The deadline is on wall time, so the I2C transactions count against it,
+ * and the status is read once more after it expires before giving up.
+ */
+static int adva_x1_cpld_wait_ready(struct ptp_ocp *bp, unsigned int max_ms)
+{
+	u32 status = 0;
+	int err = 0, ret;
+
+	ret = read_poll_timeout(adva_x1_cpld_read_status, err,
+				err || (status & CPLD_STATUS_FAILED) ||
+				!(status & CPLD_STATUS_BUSY),
+				CPLD_POLL_US, max_ms * USEC_PER_MSEC, false,
+				bp, &status);
+	if (ret)
+		return ret;
+	/* Keep the transport errno so it reaches userspace as-is; -EIO is
+	 * reserved for the CPLD itself reporting FAILED.
+	 */
+	if (err)
+		return err;
+	if (status & CPLD_STATUS_FAILED)
+		return -EIO;
+
+	return 0;
+}
+
+/* Wait for BUSY to clear.  Unlike adva_x1_cpld_wait_ready() a latched FAILED
+ * status is not an error here: this is used on the exit path, where an ISC
+ * command issued while the part is still erasing or programming may not
+ * latch, so the operation has to be waited out whatever its outcome.
+ */
+static int adva_x1_cpld_wait_idle(struct ptp_ocp *bp, unsigned int max_ms)
+{
+	u32 status = 0;
+	int err = 0, ret;
+
+	ret = read_poll_timeout(adva_x1_cpld_read_status, err,
+				err || !(status & CPLD_STATUS_BUSY),
+				CPLD_POLL_US, max_ms * USEC_PER_MSEC, false,
+				bp, &status);
+	if (ret)
+		return ret;
+
+	return err;
+}
+
+/* Leave transparent configuration mode.
+ *
+ * A DIS_CFG issued while the part is still busy may not latch, so the wait
+ * has to succeed before the write is believed - an ACKed write after a
+ * timed-out wait says nothing about whether the part left the mode.  Retry
+ * a few times rather than leaving it latched on one bad attempt; there is
+ * no other caller that would try again.
+ */
+static void adva_x1_cpld_exit_config(struct ptp_ocp *bp)
+{
+	int err, i;
+
+	if (!bp->cpld_in_config_mode)
+		return;
+
+	for (i = 0; i < CPLD_EXIT_CFG_TRIES; i++) {
+		err = adva_x1_cpld_wait_idle(bp, CPLD_ERASE_MS);
+		if (!err)
+			err = adva_x1_cpld_write(bp, CPLD_CMD_DIS_CFG);
+		if (!err) {
+			bp->cpld_in_config_mode = false;
+			return;
+		}
+	}
+
+	dev_err(&bp->pdev->dev, "CPLD left in configuration mode: %d\n", err);
+}
+
+/*
+ * Read the Lattice device ID and the image USERCODE under one bus claim.
+ * Done once, off the unprivileged devlink path, which reports the cached
+ * values.  -EBUSY means cpld_lock is held, so the caller can retry rather
+ * than wait behind a long CPLD operation.
+ */
+static int adva_x1_cpld_read_id(struct ptp_ocp *bp)
+{
+	u8 data[4];
+	int err, ret;
+
+	if (!mutex_trylock(&bp->cpld_lock))
+		return -EBUSY;
+
+	ret = adva_x1_bus_claim(bp);
+	if (ret)
+		goto out;
+	/* A select reported as failed may still have been ACKed, so the
+	 * deselect runs either way rather than handing the mux back with a
+	 * channel possibly left open.
+	 */
+	ret = adva_x1_mux_select(bp, ADVA_MUX_CHANNEL);
+	if (ret)
+		goto deselect;
+	ret = adva_x1_cpld_cmd_read(bp, CPLD_CMD_READ_ID, data, 4);
+	if (ret)
+		goto deselect;
+	/* Publish the ID before the USERCODE is attempted: a part that does
+	 * not answer 0xC0 must not cost us the device ID as well.
+	 */
+	WRITE_ONCE(bp->cpld_id, get_unaligned_be32(data));
+
+	ret = adva_x1_cpld_cmd_read(bp, CPLD_CMD_READ_USERCODE, data, 4);
+	if (ret)
+		goto deselect;
+	WRITE_ONCE(bp->cpld_usercode, get_unaligned_be32(data));
+	/* Pairs with the acquire in ptp_ocp_devlink_info_get(): the value has
+	 * to be visible before the flag that declares it valid.
+	 */
+	smp_store_release(&bp->cpld_usercode_ok, true);
+deselect:
+	err = adva_x1_mux_select(bp, -1);
+	if (!ret)
+		ret = err;
+	err = adva_x1_bus_release(bp);
+	if (!ret)
+		ret = err;
+out:
+	/* Under cpld_lock, so an operation that resets this bookkeeping
+	 * while holding the lock cannot have it overwritten afterwards by a
+	 * worker that had already finished reading.
+	 */
+	if (!ret || ++bp->cpld_id_attempts >= CPLD_ID_MAX_ATTEMPTS)
+		bp->cpld_id_tried = true;
+	mutex_unlock(&bp->cpld_lock);
+	if (ret)
+		dev_dbg(&bp->pdev->dev,
+			"CPLD device ID unavailable: %d\n", ret);
+
+	return ret;
+}
+
+/* cpld_status - show the flags set in the TAP CPLD status register. */
+static ssize_t
+cpld_status_show(struct device *dev, struct device_attribute *attr,
+		 char *buf)
+{
+	struct ptp_ocp *bp = dev_get_drvdata(dev);
+	int count = 0;
+	u32 st = 0;
+	int err, ret;
+
+	/* A CPLD operation can hold cpld_lock a long time; stay killable. */
+	ret = mutex_lock_interruptible(&bp->cpld_lock);
+	if (ret)
+		return ret;
+
+	ret = adva_x1_bus_claim(bp);
+	if (ret)
+		goto out;
+	ret = adva_x1_mux_select(bp, ADVA_MUX_CHANNEL);
+	if (ret)
+		goto deselect;
+	ret = adva_x1_cpld_read_status(bp, &st);
+deselect:
+	err = adva_x1_mux_select(bp, -1);
+	if (!ret)
+		ret = err;
+	err = adva_x1_bus_release(bp);
+	if (!ret)
+		ret = err;
+out:
+	mutex_unlock(&bp->cpld_lock);
+	if (ret)
+		return ret;
+
+	/* Flags: the names of the bits that are set, nothing when none is,
+	 * rather than a value per bit in one file.
+	 */
+	if (st & CPLD_STATUS_DONE)
+		count += sysfs_emit_at(buf, count, "done");
+	if (st & CPLD_STATUS_BUSY)
+		count += sysfs_emit_at(buf, count, "%sbusy", count ? " " : "");
+	if (st & CPLD_STATUS_FAILED)
+		count += sysfs_emit_at(buf, count, "%sfailed",
+				       count ? " " : "");
+
+	return count + sysfs_emit_at(buf, count, "\n");
+}
+static DEVICE_ATTR_ADMIN_RO(cpld_status);
+
+/*
+ * Program the CPLD configuration flash from @fw and activate it.  Selected
+ * by the "fw.cpld" flash component; the SPI flash keeps the default path.
+ * Runs under cpld_lock with the i2c adapter lock held, so an EEPROM read
+ * blocks for as long as programming takes.
+ */
+static int adva_x1_cpld_flash(struct ptp_ocp *bp, struct devlink *devlink,
+			      const struct firmware *fw,
+			      struct netlink_ext_ack *extack)
+{
+	size_t offset;
+	int err, ret;
+	u32 st;
+
+	if (!fw->size || fw->size % CPLD_PAGE_SIZE) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "image must be a whole number of 16-byte pages");
+		return -EINVAL;
+	}
+	if (fw->size > CPLD_MAX_IMAGE_SZ) {
+		NL_SET_ERR_MSG_MOD(extack, "image too large for this part");
+		return -EINVAL;
+	}
+
+	mutex_lock(&bp->cpld_lock);
+
+	err = adva_x1_bus_claim(bp);
+	if (err)
+		goto unlock;
+	/* A select reported as failed may still have been ACKed, so hand the
+	 * mux back deselected either way.
+	 */
+	err = adva_x1_mux_select(bp, ADVA_MUX_CHANNEL);
+	if (err)
+		goto deselect;
+
+	/* A previous flash may have failed to leave configuration mode.  Now
+	 * that the bus is claimed again, retry the exit before re-entering;
+	 * a no-op when the flag is already clear.
+	 */
+	adva_x1_cpld_exit_config(bp);
+
+	/* Set before EN_CFG_TP, not after: the CPLD may have entered config
+	 * mode even if the write errors or the wait times out, and only this
+	 * makes the exit path send DIS_CFG.  A stray DIS_CFG is harmless;
+	 * leaving config mode enabled is not.
+	 */
+	bp->cpld_in_config_mode = true;
+
+	err = adva_x1_cpld_write(bp, CPLD_CMD_EN_CFG_TP);
+	if (!err)
+		err = adva_x1_cpld_wait_ready(bp, 5000);
+	if (err)
+		goto exit_config;
+
+	/* Confirm the part really entered configuration mode.  An enable
+	 * frame that did not latch leaves an idle part reporting neither
+	 * BUSY nor FAILED, the erase and page writes are ignored, and DONE
+	 * is still set from the old image - so every later check passes and
+	 * the update would be reported successful with the flash untouched.
+	 */
+	err = adva_x1_cpld_read_status(bp, &st);
+	if (err)
+		goto exit_config;
+	if (!(st & CPLD_STATUS_ENAB)) {
+		dev_err(&bp->pdev->dev,
+			"CPLD did not enter configuration mode, status 0x%08x\n",
+			st);
+		NL_SET_ERR_MSG_MOD(extack,
+				   "CPLD did not enter configuration mode");
+		err = -EIO;
+		goto exit_config;
+	}
+
+	devlink_flash_update_status_notify(devlink, "Erasing",
+					   ADVA_CPLD_COMPONENT, 0, 0);
+	err = adva_x1_cpld_write(bp, CPLD_CMD_ERASE);
+	if (!err)
+		err = adva_x1_cpld_wait_ready(bp, CPLD_ERASE_MS);
+	if (err)
+		goto exit_config;
+
+	/* The old image is gone from here on, so stop reporting its
+	 * identity even if the rest of the sequence fails.  Written under
+	 * cpld_lock, which adva_x1_cpld_read_id() also holds across its own
+	 * bookkeeping, so the worker cannot resurrect any of it.
+	 */
+	WRITE_ONCE(bp->cpld_id, 0);
+	WRITE_ONCE(bp->cpld_usercode_ok, false);
+	bp->cpld_id_tried = false;
+	bp->cpld_id_attempts = 0;
+
+	err = adva_x1_cpld_write(bp, CPLD_CMD_RESET_ADDR);
+	if (err)
+		goto exit_config;
+
+	for (offset = 0; offset < fw->size; offset += CPLD_PAGE_SIZE) {
+		u8 args[3 + CPLD_PAGE_SIZE] = { 0x00, 0x00, 0x01 };
+
+		/* The loop holds cpld_lock and the i2c root lock for the
+		 * whole image, so give a dying task a way out.  The part is
+		 * left unconfigured, which is recoverable: fw.cpld stays
+		 * advertised so the image can be written again.
+		 */
+		if (fatal_signal_pending(current)) {
+			err = -EINTR;
+			goto exit_config;
+		}
+
+		memcpy(&args[3], fw->data + offset, CPLD_PAGE_SIZE);
+		err = adva_x1_i2c_xfer(bp, ADVA_CPLD_ADDR, CPLD_CMD_WRITE_PAGE,
+				       args, sizeof(args), NULL, 0);
+		if (!err)
+			err = adva_x1_cpld_wait_ready(bp, 100);
+		if (err)
+			goto exit_config;
+
+		if (!(offset % (CPLD_PAGE_SIZE * 64)))
+			devlink_flash_update_status_notify(devlink,
+							   "Programming",
+							   ADVA_CPLD_COMPONENT,
+							   offset, fw->size);
+	}
+	devlink_flash_update_status_notify(devlink, "Programming",
+					   ADVA_CPLD_COMPONENT,
+					   fw->size, fw->size);
+
+	err = adva_x1_cpld_write(bp, CPLD_CMD_SET_DONE);
+	if (!err)
+		err = adva_x1_cpld_wait_ready(bp, 1000);
+	if (err)
+		goto exit_config;
+
+	err = adva_x1_cpld_read_status(bp, &st);
+	if (err)
+		goto exit_config;
+	if (!(st & CPLD_STATUS_DONE)) {
+		dev_err(&bp->pdev->dev,
+			"CPLD SET_DONE left status 0x%08x\n", st);
+		NL_SET_ERR_MSG_MOD(extack, "CPLD did not accept the image");
+		err = -EIO;
+		goto exit_config;
+	}
+
+	devlink_flash_update_status_notify(devlink, "Activating",
+					   ADVA_CPLD_COMPONENT, 0, 0);
+	err = adva_x1_cpld_write(bp, CPLD_CMD_REFRESH);
+	if (err)
+		goto exit_config;
+
+	/* REFRESH reboots the CPLD out of configuration mode, so the exit
+	 * path must not send DIS_CFG afterwards even if a check below fails.
+	 */
+	bp->cpld_in_config_mode = false;
+
+	/* The new image is already running, so a segment that is not back
+	 * yet must not be reported as a failed update: retry the reselect
+	 * rather than sampling the mux once at a fixed delay.
+	 */
+	msleep(1500);
+	err = read_poll_timeout(adva_x1_mux_select, err, !err, CPLD_POLL_US,
+				3000 * USEC_PER_MSEC, false,
+				bp, ADVA_MUX_CHANNEL);
+	if (err)
+		goto deselect;
+
+	err = adva_x1_cpld_wait_ready(bp, 3000);
+	if (err)
+		goto deselect;
+
+	/* Require DONE set, not busy and no error code, as machxo2-spi.c does
+	 * after a refresh: without it a CRC or preamble error reads back as a
+	 * successful update.
+	 */
+	err = adva_x1_cpld_read_status(bp, &st);
+	if (err)
+		goto deselect;
+	if (!(st & CPLD_STATUS_DONE) || (st & CPLD_STATUS_BUSY) ||
+	    (st & CPLD_STATUS_ERR)) {
+		dev_err(&bp->pdev->dev,
+			"CPLD refresh left status 0x%08x\n", st);
+		NL_SET_ERR_MSG_MOD(extack, "CPLD did not come back configured");
+		err = -EIO;
+		goto deselect;
+	}
+
+exit_config:
+	adva_x1_cpld_exit_config(bp);
+deselect:
+	ret = adva_x1_mux_select(bp, -1);
+	if (!err)
+		err = ret;
+	ret = adva_x1_bus_release(bp);
+	if (!err)
+		err = ret;
+unlock:
+	mutex_unlock(&bp->cpld_lock);
+
+	return err;
+}
+
 static struct attribute *adva_timecard_attrs[] = {
 	&dev_attr_serialnum.attr,
 	&dev_attr_gnss_sync.attr,
@@ -4274,6 +5155,7 @@ static struct attribute *adva_timecard_x1_attrs[] = {
 	&dev_attr_ts_window_adjust.attr,
 	&dev_attr_utc_tai_offset.attr,
 	&dev_attr_tod_correction.attr,
+	&dev_attr_cpld_status.attr,
 	NULL,
 };
 
@@ -4904,6 +5786,7 @@ ptp_ocp_detach(struct ptp_ocp *bp)
 		clk_hw_unregister_fixed_rate(bp->i2c_clk);
 	if (bp->n_irqs)
 		pci_free_irq_vectors(bp->pdev);
+	mutex_destroy(&bp->cpld_lock);
 	device_unregister(&bp->dev);
 }
 
@@ -5052,6 +5935,17 @@ ptp_ocp_sync_work(struct work_struct *work)
 
 	bp->sync = sync;
 
+	/* Resolve the adapter here rather than once in probe, where it can
+	 * race the adapter's own registration, and read the ID as soon as it
+	 * turns up.  A claim can fail transiently - the firmware may not
+	 * grant the segment straight after power-up - so adva_x1_cpld_read_id()
+	 * retries a bounded number of times before giving up.
+	 */
+	adva_x1_cache_i2c_adap(bp);
+	if (bp->has_cpld && !READ_ONCE(bp->cpld_id_tried) &&
+	    READ_ONCE(bp->cpld_i2c_adap_nr) >= 0)
+		adva_x1_cpld_read_id(bp);
+
 	queue_delayed_work(system_power_efficient_wq, &bp->sync_work, HZ);
 }
 
@@ -5080,6 +5974,15 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (err)
 		goto out_disable;
 
+	/* Before the first error path that calls ptp_ocp_detach(), so
+	 * mutex_destroy() runs on an initialised mutex, and before
+	 * ptp_ocp_register_resources(), so this sentinel cannot overwrite an
+	 * adapter number the i2c notifier stores during registration.
+	 */
+	mutex_init(&bp->cpld_lock);
+	spin_lock_init(&bp->cpld_adap_lock);
+	bp->cpld_i2c_adap_nr = -1;
+
 	INIT_DELAYED_WORK(&bp->sync_work, ptp_ocp_sync_work);
 
 	/* compat mode.
@@ -5119,12 +6022,12 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (IS_ERR(bp->dpll)) {
 		err = PTR_ERR(bp->dpll);
 		dev_err(&pdev->dev, "dpll_device_alloc failed\n");
-		goto out;
+		goto out_devlink;
 	}
 
 	err = dpll_device_register(bp->dpll, DPLL_TYPE_PPS, &dpll_ops, bp);
 	if (err)
-		goto out;
+		goto out_dpll_put;
 
 	for (i = 0; i < OCP_SMA_NUM; i++) {
 		bp->sma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE,
@@ -5150,7 +6053,16 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]);
 		dpll_pin_put(bp->sma[i].dpll_pin, &bp->sma[i].tracker);
 	}
+	/* dpll_device_register() takes a second reference and stores bp; only
+	 * dpll_device_unregister() drops it.  Without this the device stays
+	 * visible with a priv pointer into storage devlink_free() will release.
+	 */
+	dpll_device_unregister(bp->dpll, &dpll_ops, bp);
+out_dpll_put:
 	dpll_device_put(bp->dpll, &bp->tracker);
+out_devlink:
+	/* detach() destroys cpld_lock; no devlink op may still reach it */
+	devlink_unregister(devlink);
 out:
 	ptp_ocp_detach(bp);
 out_disable:
@@ -5196,6 +6108,7 @@ ptp_ocp_i2c_notifier_call(struct notifier_block *nb,
 			  unsigned long action, void *data)
 {
 	struct device *dev, *child = data;
+	struct i2c_adapter *adap;
 	struct ptp_ocp *bp;
 	bool add;
 
@@ -5219,11 +6132,25 @@ ptp_ocp_i2c_notifier_call(struct notifier_block *nb,
 
 found:
 	bp = dev_get_drvdata(dev);
-	if (add)
+	adap = i2c_verify_adapter(child);
+	if (add) {
 		ptp_ocp_symlink(bp, child, "i2c");
-	else
+		/* Only the card's own controller: a mux child added on it
+		 * reaches ptp_ocp through the same walk.  Numbers are
+		 * recycled, so the claim re-checks the parent itself.
+		 */
+		if (bp->i2c_ctrl && adap->dev.parent == &bp->i2c_ctrl->dev) {
+			scoped_guard(spinlock, &bp->cpld_adap_lock)
+				bp->cpld_i2c_adap_nr = adap->nr;
+		}
+	} else {
+		/* invalidate before free, but only for the cached adapter */
+		scoped_guard(spinlock, &bp->cpld_adap_lock) {
+			if (bp->cpld_i2c_adap_nr == adap->nr)
+				bp->cpld_i2c_adap_nr = -1;
+		}
 		sysfs_remove_link(&bp->dev.kobj, "i2c");
-
+	}
 	return 0;
 }
 

3/2 2026/09/18 05:12 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 18632
							output: 38
							thoughts: 135
						

Thoughts:
Here's my thinking about this patch, summarized from my expert perspective:

**Patch Review: Diving into the `ptp_ocp` Driver**

Okay, so this patch affects a few files, specifically `drivers/ptp/ptp_ocp.c`, some documentation in `Documentation/ABI/testing/sysfs-timecard`,  `Documentation/networking/devlink/index.rst`, `Documentation/networking/devlink/ptp_ocp.rst` and the `MAINTAINERS` file. My first thought is to zero in on the core of the change – the driver itself, and the associated documentation updates.

My priority is to understand the scope and potential impact. Let's start with `drivers/ptp/ptp_ocp.c`. I need to figure out what kind of hardware this `ptp_ocp` driver is actually controlling. Is this a common PTP device? An obscure one? Is it a well-established design, or something relatively new? I'll probably start with a quick search within the kernel source for the driver's identifier (`ptp_ocp`) to see if it's got a well-known associated hardware definition or other contextual information. Then, I'll probably go right into the `ptp_ocp.c` code to see if it jumps out at me as a particular design I'm familiar with or if I need to dig deeper. I'll be looking for clues in the register definitions, device initialization, and any specific hardware features that the driver exposes. These documentation changes should help, and I need to review those files too. I'll need to understand if the patch represents a new feature, a bug fix, or a change in the interface. I'm looking for the "why" and "what" behind these modifications to judge the patch's merit.



4/2 2026/09/18 05:12 tool grepper
0m Args:
{
  "Expression": "PCI_DEVICE_ID.*",
  "PathPrefix": "drivers/ptp/ptp_ocp.c"
}

Results:
{
  "Output": "drivers/ptp/ptp_ocp.c-31-\ndrivers/ptp/ptp_ocp.c:32:#define PCI_DEVICE_ID_META_TIMECARD\t\t0x0400\ndrivers/ptp/ptp_ocp.c-33-\ndrivers/ptp/ptp_ocp.c-34-#define PCI_VENDOR_ID_CELESTICA\t\t\t0x18d4\ndrivers/ptp/ptp_ocp.c:35:#define PCI_DEVICE_ID_CELESTICA_TIMECARD\t0x1008\ndrivers/ptp/ptp_ocp.c-36-\ndrivers/ptp/ptp_ocp.c-37-#define PCI_VENDOR_ID_OROLIA\t\t\t0x1ad7\ndrivers/ptp/ptp_ocp.c:38:#define PCI_DEVICE_ID_OROLIA_ARTCARD\t\t0xa000\ndrivers/ptp/ptp_ocp.c-39-\ndrivers/ptp/ptp_ocp.c-40-#define PCI_VENDOR_ID_ADVA\t\t\t0xad5a\ndrivers/ptp/ptp_ocp.c:41:#define PCI_DEVICE_ID_ADVA_TIMECARD\t\t0x0400\ndrivers/ptp/ptp_ocp.c:42:#define PCI_DEVICE_ID_ADVA_TIMECARD_X1\t\t0x0410\ndrivers/ptp/ptp_ocp.c-43-\n"
}

5/2 2026/09/18 05:12 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 19585
							output: 37
							thoughts: 20
						

Thoughts:
Here's my take on those thoughts, tailored for an expert audience:

**Diving into the PTP-OCP Driver**

Okay, time to get my hands dirty. I'm going to start by taking a close look at the `pci_driver` structure within `ptp_ocp.c`. This is where the core interaction with the PCI bus likely lives, so understanding how it's defined and initialized is going to be crucial. I need to see how the driver registers itself, what resources it's claiming, and how it's interacting with the hardware registers for the PTP (Precision Time Protocol) functionality over the OCP (On-Chip Peripheral) interface. I'm particularly interested in any potential race conditions or locking mechanisms used, and how they handle interrupts, especially in a multi-threaded or multi-core environment. Any quirks in the PCI configuration itself will be a major point of focus, like BAR mappings, interrupt lines, and DMA settings. Hopefully, the code is well-commented. Let's see what we've got.



6/2 2026/09/18 05:12 tool grepper
0m Args:
{
  "Expression": "struct pci_driver",
  "PathPrefix": "drivers/ptp/ptp_ocp.c"
}

Results:
{
  "Output": "drivers/ptp/ptp_ocp.c=6076=ptp_ocp_remove(struct pci_dev *pdev)\n--\ndrivers/ptp/ptp_ocp.c-6097-\ndrivers/ptp/ptp_ocp.c:6098:static struct pci_driver ptp_ocp_driver = {\ndrivers/ptp/ptp_ocp.c-6099-\t.name\t\t= KBUILD_MODNAME,\n"
}

7/2 2026/09/18 05:12 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 20000
							output: 37
							thoughts: 551
						

Thoughts:
**My Assessment of the `ptp_ocp` Driver's Fuzzing Suitability**

Okay, so `ptp_ocp` is an OpenCompute Timecard driver. My first thought is, "Is this a physical PCI device, or is there a software emulation?" The fact that the driver's name is "OPENCOMPUTE PTP CLOCK DRIVER" and the existence of PCI IDs like `PCI_DEVICE_ID_META_TIMECARD`, `PCI_DEVICE_ID_CELESTICA_TIMECARD`, `PCI_DEVICE_ID_OROLIA_ARTCARD`, `PCI_DEVICE_ID_ADVA_TIMECARD`, and `PCI_DEVICE_ID_ADVA_TIMECARD_X1` immediately suggests it's likely tied to some physical hardware.

Now, let's consider the fuzzing implications based on the patch instructions. Section 1 emphasizes reachability: if code can't execute in a standard virtualized environment (like GCE or QEMU), it shouldn't be fuzzed. Section 2 further clarifies this with negative criteria. It specifically calls out "Structurally unreachable hardware" – things like vendor-specific PCIe switches, SmartNICs, or GPU drivers that need physical ASIC/PCIe cards, which QEMU *doesn't* emulate. "Unreachable execution paths" are also a no-go, like driver teardown callbacks that only run during hot-unplugging a physical PCI device.

So, the key question is whether `ptp_ocp` is emulatable in QEMU. If it *is*, then fuzzing could be valid. If it *isn't*, then it would fall under the "structurally unreachable" category, and fuzzing would be pointless.

I've already checked, and it seems that QEMU doesn't emulate OpenCompute TimeCards, Meta TimeCards, or ADVA TimeCards directly. Therefore, I need to confirm whether `ptp_ocp` *requires* physical hardware to be reached. Let's delve into `drivers/ptp/ptp_ocp.c` and its Kconfig to definitively answer whether it's purely a PCI driver, or if there might be a software path or emulation path.



8/2 2026/09/18 05:13 tool grepper
0m Args:
{
  "Expression": "PTP_1588_CLOCK_OCP",
  "PathPrefix": "drivers/ptp/"
}

Results:
{
  "Output": "drivers/ptp/Kconfig=199=config PTP_1588_CLOCK_VMW\n--\ndrivers/ptp/Kconfig-210-\ndrivers/ptp/Kconfig:211:config PTP_1588_CLOCK_OCP\ndrivers/ptp/Kconfig-212-\ttristate \"OpenCompute TimeCard as PTP clock\"\n--\ndrivers/ptp/Makefile=20=obj-$(CONFIG_PTP_1588_CLOCK_VMW)\t+= ptp_vmw.o\ndrivers/ptp/Makefile:21:obj-$(CONFIG_PTP_1588_CLOCK_OCP)\t+= ptp_ocp.o\ndrivers/ptp/Makefile-22-obj-$(CONFIG_PTP_DFL_TOD)\t\t+= ptp_dfl_tod.o\n"
}

9/2 2026/09/18 05:13 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 21291
							output: 35
							thoughts: 20
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Diving into PTP Configuration**

Alright, let's get down to brass tacks. I'm going to jump into the `drivers/ptp/Kconfig` file, specifically around line 211. My intuition tells me that's where we'll likely find the configuration options related to [***insert your expert field here - e.g., precise time synchronization for specific hardware, specific PTP profiles, grandmaster selection algorithms, etc.***]. This is probably where the core PTP functionality gets defined and controlled at build time. I anticipate finding conditionals and dependencies related to various clock types, hardware support, or specific protocol implementations, or perhaps even flags that control what features are compiled. I'm keen to see the options and how they are structured; is it a flat configuration, or a nested set of choices and dependencies? Ultimately, I'm hoping to gain a solid understanding of how we can control and fine-tune PTP behavior in this kernel build. Let's see what the code reveals!



10/2 2026/09/18 05:13 tool read-file
0m Args:
{
  "File": "drivers/ptp/Kconfig",
  "FirstLine": 208,
  "LineCount": 25
}

Results:
{
  "Contents": " 208:\t\t  To compile this driver as a module, choose M here: the module\n 209:\t\t  will be called ptp_vmw.\n 210:\t\n 211:\tconfig PTP_1588_CLOCK_OCP\n 212:\t\ttristate \"OpenCompute TimeCard as PTP clock\"\n 213:\t\tdepends on PTP_1588_CLOCK\n 214:\t\tdepends on HAS_IOMEM \u0026\u0026 PCI\n 215:\t\tdepends on I2C \u0026\u0026 MTD\n 216:\t\tdepends on SERIAL_8250\n 217:\t\tdepends on !S390\n 218:\t\tdepends on COMMON_CLK\n 219:\t\tselect NET_DEVLINK\n 220:\t\tselect CRC16\n 221:\t\tselect DPLL\n 222:\t\thelp\n 223:\t\t  This driver adds support for an OpenCompute time card.\n 224:\t\n 225:\t\t  The OpenCompute time card is an atomic clock along with\n 226:\t\t  a GPS receiver that provides a Grandmaster clock source\n 227:\t\t  for a PTP enabled network.\n 228:\t\n 229:\t\t  More information is available at http://www.timingcard.com/\n 230:\t\n 231:\tconfig PTP_DFL_TOD\n 232:\t\ttristate \"FPGA DFL ToD Driver\"\n"
}

11/2 2026/09/18 05:13 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 21956
							output: 42
							thoughts: 319
						

Thoughts:
**Analyzing the OpenCompute Time Card Patch**

Okay, let's break this down. First, the description tells me this "OpenCompute time card" is essentially a highly accurate clock source for a PTP network, combining an atomic clock with GPS. Now, looking at the patch itself, the main focus seems to be adding support for the TAP CPLD on ADVA TimeCard X1 boards. The PCI ID is a dead giveaway, and the code mentions things like: CPLD flashing, I2C programming using MachXO3, and refresh operations. I see several functions named specifically for this ADVA X1 board: flashing the CPLD, claiming the bus, selecting the mux, writing to and reading from the CPLD, and displaying CPLD status. It also includes `devlink` callbacks for both flashing the CPLD and device information, tied to the component "fw.cpld."

My immediate question, given my experience, is whether I can actually *test* this driver or device without the physical PCIe hardware. Can I instantiate or probe this within a standard QEMU environment, or even something like Google Compute Engine? Is there a way to emulate this setup or create the necessary virtual environment?

The real crux of it is, is there any concept of a platform device or virtual bus that's defined for `ptp_ocp`? Does the driver itself dynamically create any devices, or am I dependent on the physical hardware always being present? I need to know if this is a statically defined PCI device or something that can be brought up in a more abstract way. Let's see... I'll check the `pci_device_id` table within `drivers/ptp/ptp_ocp.c`. That should give me a solid clue.



12/2 2026/09/18 05:13 tool grepper
0m Args:
{
  "Expression": "ptp_ocp_pcidev_id",
  "PathPrefix": "drivers/ptp/ptp_ocp.c"
}

Results:
{
  "Output": "drivers/ptp/ptp_ocp.c=1113=static struct ocp_resource ocp_adva_x1_resource[] = {\n--\ndrivers/ptp/ptp_ocp.c-1320-\ndrivers/ptp/ptp_ocp.c:1321:static const struct pci_device_id ptp_ocp_pcidev_id[] = {\ndrivers/ptp/ptp_ocp.c-1322-\t{ PCI_DEVICE_DATA(META, TIMECARD, \u0026ocp_fb_resource) },\n--\ndrivers/ptp/ptp_ocp.c-1328-};\ndrivers/ptp/ptp_ocp.c:1329:MODULE_DEVICE_TABLE(pci, ptp_ocp_pcidev_id);\ndrivers/ptp/ptp_ocp.c-1330-\n--\ndrivers/ptp/ptp_ocp.c=6098=static struct pci_driver ptp_ocp_driver = {\ndrivers/ptp/ptp_ocp.c-6099-\t.name\t\t= KBUILD_MODNAME,\ndrivers/ptp/ptp_ocp.c:6100:\t.id_table\t= ptp_ocp_pcidev_id,\ndrivers/ptp/ptp_ocp.c-6101-\t.probe\t\t= ptp_ocp_probe,\n"
}

13/2 2026/09/18 05:13 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 23061
							output: 144
							thoughts: 734
						

Thoughts:
**Analysis of `ptp_ocp_pcidev_id` for Fuzzing Eligibility**

Okay, let's break this down. My initial observation is that `ptp_ocp_pcidev_id` is registered as a PCI driver via `pci_register_driver(&ptp_ocp_driver)`. There are no other entry points to the driver. This means we're dealing with a strictly PCI-based driver. The specific code changes introduced by this patch are focused on:

*   Devlink and flash updates *exclusively* for the ADVA TimeCard X1 CPLD, and only when a specific boolean (`bp->has_cpld`) is true.
*   A new sysfs attribute, `cpld_status`, also specific to the ADVA TimeCard X1.
*   CPLD flashing and status readout logic, operating over an internal I2C bus that's gated by the MicroBlaze mailbox/register `i2c_bus_ctrl`, which resides on the PCIe BAR.
*   Probe cleanup error handling related to dpll/devlink issues.
*   An I2C notifier callback that caches the adapter, triggered by the `bp->i2c_ctrl->dev`.

None of this code will execute without the actual physical ADVA TimeCard X1, or at the very least, *some* form of OpenCompute Timecard PCIe device. I know that standard QEMU or GCE VMs don't emulate *any* of these specialized timing PCIe add-in cards. These cards are designed with features like atomic clocks, GPS/GNSS receivers, CPLDs, and MicroBlaze soft cores.

Now, let's cross-reference this with the defined criteria. In section 2, it explicitly states "Structurally unreachable hardware: * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds\_core, qed, ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU." This absolutely applies here. This is *precisely* what we have. It also falls under section 1 regarding "REACHABILITY IS THE PRIMARY GATE", where it states that fuzzing should only be done on code that can be executed in standard virtualized environments. The modified code is structurally unreachable because of the required hardware dependency.

Therefore, for this particular driver, I can definitively say that `WorthFuzzing` should be `false`. The `FocusSymbols` list should be empty (or `[]`). The same goes for `EnableConfigs` (empty or `[]`). My `Reasoning` should be a concise summary: this code is structurally unreachable because it requires a specific OpenCompute TimeCard PCIe device (specifically ADVA TimeCard X1) that is not emulated in standard QEMU or GCE environments.

I've double-checked that these conclusions are consistent with all the requirements.

Finally, the patch only touches documentation, `MAINTAINERS`, and the `drivers/ptp/ptp_ocp.c` file. The driver is `ptp_ocp` for the OpenCompute TimeCard PCI device (specifically ADVA TimeCard X1) which requires dedicated physical PCIe hardware which is not available, nor emulated in standard QEMU/GCE virtualization environments, making the code structurally unreachable.

Alright, I'm ready to submit my findings.



14/2 2026/09/18 05:13 tool set-results
0m Args:
{
  "EnableConfigs": [],
  "FocusSymbols": [],
  "Reasoning": "The patch series adds CPLD status reporting, devlink flash updating, and devlink info support for the ADVA TimeCard X1 in the OpenCompute TimeCard driver (drivers/ptp/ptp_ocp.c). This driver binds exclusively to specific physical PCIe devices (such as Meta TimeCard, ADVA TimeCard X1) which require dedicated hardware (atomic clock/GPS timing PCIe cards) not emulated in standard virtualized fuzzing environments (QEMU/GCE). As such, the modified code is structurally unreachable.",
  "WorthFuzzing": false
}

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "Reasoning": "The patch series adds CPLD status reporting, devlink flash updating, and devlink info support for the ADVA TimeCard X1 in the OpenCompute TimeCard driver (drivers/ptp/ptp_ocp.c). This driver binds exclusively to specific physical PCIe devices (such as Meta TimeCard, ADVA TimeCard X1) which require dedicated hardware (atomic clock/GPS timing PCIe cards) not emulated in standard virtualized fuzzing environments (QEMU/GCE). As such, the modified code is structurally unreachable.",
  "WorthFuzzing": false
}

15/1 2026/09/18 05:13 action If
0m Args:
{
  "WorthFuzzing": false
}

Results:
null

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)