Netdev List
 help / color / mirror / Atom feed
From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
To: Sagi Maimon <maimon.sagi@gmail.com>, netdev@vger.kernel.org
Cc: richardcochran@gmail.com, jiri@resnulli.us,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	willemb@google.com, corbet@lwn.net, skhan@linuxfoundation.org,
	rdunlap@infradead.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH net-next] ptp: ocp: add support for the ADVA TimeCard X2
Date: Thu, 3 Dec 2026 11:45:21 +0000	[thread overview]
Message-ID: <096aeb5e-951a-4e66-a664-520c70b67b93@linux.dev> (raw)
In-Reply-To: <20261130143150.326311-1-maimon.sagi@gmail.com>

On 30/11/2026 14:31, Sagi Maimon wrote:
> The ADVA TimeCard X2 (PCI ID ad5a:0420) keeps the PPS timestamper, the
> NMEA serial port, the I2C controller with the board EEPROMs and the TAP
> CPLD of the X1.  It has no signal generators or frequency counters, its
> firmware rather than the host keeps the clock's time of day on GNSS, its
> FPGA image is not updated from the host, and its two SMA connectors are
> internal to the card, out of the user's reach.
> 
> Add a resource table for it on top of ptp_ocp_adva_board_init(), with:
> 
>   - no TOD block, since the firmware sets the time of day;
>   - no SMA op, since there are no connectors to configure;
>   - no SPI flash, since there is no FPGA image to write;
>   - a reduced attribute group: serial number, GNSS sync and CPLD status;
>   - has_cpld set, so the CPLD is identified and can be flashed through
>     devlink as on the X1.
>   - osa_version set: the image version register carries the release
>     and build of the card's OSA software instead of the X1 layout -
>     bit 31 marks the loader, bits 23:16 hold the release and bits 15:0
>     the build - and devlink reports it as <release>.<build>.
> 
> Every board so far has a TOD block, SMA connectors and an FPGA flash, so
> allow all three to be absent.  ptp_ocp_tod_init() dereferenced bp->tod
> unconditionally; it now returns early when there is no TOD block.  When
> sma_op is unset, ptp_ocp_adva_board_init() sets up no PTP pins and no
> SMA state, probe registers the dpll device without pins, and the debugfs
> summary neither prints SMA lines nor names an SMA as a signal source.
> When there is no SPI flash, a devlink flash update without a component
> fails with -EOPNOTSUPP, rather than letting ptp_ocp_find_flash() walk
> the children of an invalid pointer derived from the NULL spi_flash.  The
> CPLD component is unaffected, and all other boards have all three and
> are unaffected.
> 
> Update the devlink documentation to match: the CPLD versions and the
> fw.cpld component now apply to the X2 as well, a flash update without
> a component is not supported there, and the fw version is the OSA
> software release and build.
> 
> The card also carries an AXI Ethernet MAC, which is added separately.
> 
> Tested on an ADVA TimeCard X2 with FPGA image 136.1089: the card
> probes, devlink reports the board, firmware and CPLD versions, read
> from the EEPROMs and the CPLD, and phc2sys tracks its PTP clock.
> 
> Assisted-by: LLM sparse
> Signed-off-by: Sagi Maimon <maimon.sagi@gmail.com>
> ---
>   Documentation/networking/devlink/ptp_ocp.rst |  30 +--
>   drivers/ptp/ptp_ocp.c                        | 182 ++++++++++++++++---
>   2 files changed, 172 insertions(+), 40 deletions(-)
> 
> diff --git a/Documentation/networking/devlink/ptp_ocp.rst b/Documentation/networking/devlink/ptp_ocp.rst
> index f94b759d9cd6..36c4104662cf 100644
> --- a/Documentation/networking/devlink/ptp_ocp.rst
> +++ b/Documentation/networking/devlink/ptp_ocp.rst
> @@ -21,15 +21,17 @@ The ``ptp_ocp`` driver reports the following versions
>      * - ``fw``
>        - running
>        - Version of the firmware running on the card.  Reported as ``loader``
> -       instead when the card is running the firmware loader.
> +       instead when the card is running the firmware loader.  On ADVA
> +       TimeCard X2 boards it is the release and build of the card's OSA
> +       software, as ``<release>.<build>``.
>      * - ``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
> +       Only present on ADVA TimeCard X1 and X2 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
> @@ -54,17 +56,19 @@ selected with the component name.
>        - Description
>      * - (none)
>        - The card's own flash, written through the SPI controller the driver
> -       exposes.  The card runs the new image after its next reset.
> +       exposes.  The card runs the new image after its next reset.  Not
> +       supported on ADVA TimeCard X2 boards, whose FPGA image is not
> +       updated from the host; the request fails with ``EOPNOTSUPP``.
>      * - ``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.
> +     - The configuration flash of the TAP CPLD on ADVA TimeCard X1 and X2
> +       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
> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index decc56892059..f88939a3e932 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -41,6 +41,7 @@
>   #define PCI_VENDOR_ID_ADVA			0xad5a
>   #define PCI_DEVICE_ID_ADVA_TIMECARD		0x0400
>   #define PCI_DEVICE_ID_ADVA_TIMECARD_X1		0x0410
> +#define PCI_DEVICE_ID_ADVA_TIMECARD_X2		0x0420
>   
>   static struct class timecard_class = {
>   	.name		= "timecard",
> @@ -81,7 +82,7 @@ struct ptp_ocp_servo_conf {
>   /*
>    * Combined servo + board-variant parameters for ADVA boards.
>    * Embedded in the resource table .extra so a single ptp_ocp_adva_board_init()
> - * can handle both ADVA and ADVA-X1 without per-variant init functions.
> + * can handle ADVA, ADVA-X1 and ADVA-X2 without per-variant init functions.
>    */
>   struct ptp_ocp_adva_info {
>   	struct ptp_ocp_servo_conf	servo;
> @@ -92,6 +93,8 @@ struct ptp_ocp_adva_info {
>   	const struct ocp_attr_group	*attr_groups;
>   	/* x1: TAP CPLD present */
>   	bool				has_cpld;
> +	/* x2: image version in the OSA software format */
> +	bool				osa_version;
>   };
>   
>   #define OCP_CTRL_ENABLE		BIT(0)
> @@ -170,7 +173,7 @@ struct gpio_reg {
>   	u32	gpio1;
>   	u32	__pad0;
>   	u32	gpio2;
> -	/* adva_x1: I2C bus ownership register; reserved on other variants */
> +	/* adva_x1/x2: I2C bus ownership register; reserved on other variants */
>   	u32	i2c_bus_ctrl;
>   };
>   
> @@ -499,6 +502,7 @@ static const struct ocp_attr_group art_timecard_groups[];
>   static const struct ocp_attr_group adva_timecard_groups[];
>   
>   static const struct ocp_attr_group adva_timecard_x1_groups[];
> +static const struct ocp_attr_group adva_timecard_x2_groups[];
>   
>   struct ptp_ocp_eeprom_map {
>   	u16	off;
> @@ -1319,12 +1323,91 @@ static struct ocp_resource ocp_adva_x1_resource[] = {
>   	{ }
>   };
>   
> +static struct ocp_resource ocp_adva_x2_resource[] = {
> +	{
> +		OCP_MEM_RESOURCE(reg),
> +		.offset = 0x01000000, .size = 0x10000,
> +	},
> +	{
> +		OCP_MEM_RESOURCE(pps_to_clk),
> +		.offset = 0x01040000, .size = 0x10000,
> +	},
> +	{
> +		/*
> +		 * PPS timestamper.  X2 exposes no external timestampers, but
> +		 * this block is what raises the per-second interrupt behind
> +		 * PTP_ENABLE_PPS, so /dev/ppsN stays silent without it.
> +		 */
> +		OCP_EXT_RESOURCE(pps),
> +		.offset = 0x010C0000, .size = 0x10000, .irq_vec = 0,
> +		.extra = &(struct ptp_ocp_ext_info) {
> +			.index = 5,
> +			.irq_fcn = ptp_ocp_ts_irq,
> +			.enable = ptp_ocp_ts_enable,
> +		},
> +	},
> +	{
> +		OCP_MEM_RESOURCE(image),
> +		.offset = 0x00020000, .size = 0x1000,
> +	},
> +	{
> +		/*
> +		 * The gpio_reg block.  X2 has no SMA routing to configure, but
> +		 * the window's i2c_bus_ctrl word carries the MicroBlaze I2C
> +		 * bus-ownership handshake that CPLD access needs; see
> +		 * adva_x1_bus_claim().  The X2 FPGA places it at 0x70000
> +		 * rather than at 0x130000 as on the other ADVA boards.
> +		 */
> +		OCP_MEM_RESOURCE(pps_select),
> +		.offset = 0x00070000, .size = 0x1000,
> +	},
> +	{
> +		OCP_SERIAL_RESOURCE(port[PORT_NMEA]),
> +		.offset = 0x00190000 + 0x1000, .irq_vec = 10,
> +	},
> +	{
> +		OCP_I2C_RESOURCE(i2c_ctrl),
> +		.offset = 0x00150000, .size = 0x10000, .irq_vec = 7,
> +		.extra = &(struct ptp_ocp_i2c_info) {
> +			.name = "xiic-i2c",
> +			.fixed_rate = 50000000,
> +			.data_size = sizeof(struct xiic_i2c_platform_data),
> +			.data = &(struct xiic_i2c_platform_data) {
> +				.num_devices = 2,
> +				.devices = (struct i2c_board_info[]) {
> +					{ I2C_BOARD_INFO("24c02", 0x50) },
> +					{ I2C_BOARD_INFO("24mac402", 0x58),
> +					  .platform_data = "mac" },
> +				},
> +			},
> +		},
> +	},
> +	{
> +		.setup = ptp_ocp_adva_board_init,
> +		.extra = &(struct ptp_ocp_adva_info) {
> +			.servo = {
> +				.servo_offset_p = 0xc000,
> +				.servo_offset_i = 0x1000,
> +				.servo_drift_p = 0,
> +				.servo_drift_i = 0,
> +			},
> +			.signals_nr   = 0,
> +			.freq_in_nr   = 0,
> +			.attr_groups  = adva_timecard_x2_groups,
> +			.has_cpld     = true,
> +			.osa_version  = true,
> +		},
> +	},
> +	{ }
> +};
> +
>   static const struct pci_device_id ptp_ocp_pcidev_id[] = {
>   	{ PCI_DEVICE_DATA(META, TIMECARD, &ocp_fb_resource) },
>   	{ PCI_DEVICE_DATA(CELESTICA, TIMECARD, &ocp_fb_resource) },
>   	{ PCI_DEVICE_DATA(OROLIA, ARTCARD, &ocp_art_resource) },
>   	{ PCI_DEVICE_DATA(ADVA, TIMECARD, &ocp_adva_resource) },
>   	{ PCI_DEVICE_DATA(ADVA, TIMECARD_X1, &ocp_adva_x1_resource) },
> +	{ PCI_DEVICE_DATA(ADVA, TIMECARD_X2, &ocp_adva_x2_resource) },
>   	{ }
>   };
>   MODULE_DEVICE_TABLE(pci, ptp_ocp_pcidev_id);
> @@ -1933,6 +2016,12 @@ ptp_ocp_tod_init(struct ptp_ocp *bp)
>   {
>   	u32 ctrl, reg;
>   
> +	/* The X2 maps no TOD block: its firmware keeps the clock's time of
> +	 * day on GNSS.
> +	 */
> +	if (!bp->tod)
> +		return;
> +
>   	ctrl = ioread32(&bp->tod->ctrl);
>   	ctrl |= TOD_CTRL_PROTOCOL | TOD_CTRL_ENABLE;
>   	ctrl &= ~(TOD_CTRL_DISABLE_FMT_A | TOD_CTRL_DISABLE_FMT_B);
> @@ -2189,6 +2278,11 @@ ptp_ocp_devlink_flash_update(struct devlink *devlink,
>   		return err;
>   	}
>   
> +	if (!bp->spi_flash) {
> +		NL_SET_ERR_MSG_MOD(extack, "FPGA image update not supported");
> +		return -EOPNOTSUPP;
> +	}
> +
>   	dev = ptp_ocp_find_flash(bp);
>   	if (!dev) {
>   		dev_err(&bp->pdev->dev, "Can't find Flash SPI adapter\n");
> @@ -3271,13 +3365,20 @@ ptp_ocp_adva_board_init(struct ptp_ocp *bp, struct ocp_resource *r)
>   	bp->freq_in_nr  = info->freq_in_nr;
>   
>   	version = ioread32(&bp->image->version);
> -	/* if lower 16 bits are empty, this is the fw loader. */
> -	if ((version & 0xffff) == 0) {
> -		version = version >> 16;
> -		bp->fw_loader = true;
> +	if (info->osa_version) {
> +		/* OSA: bit 31 loader, bits 23:16 release, bits 15:0 build */
> +		bp->fw_loader  = !!(version & BIT(31));
> +		bp->fw_tag     = (version >> 16) & 0xff;

originally, the idea was to use fw_tag as non-iterleaving manufacturing
release version. with this change you make it variable and possibly 
clashing with previous versions. please, keep it static, either 3 or 4
as it's a new board.

> +		bp->fw_version = version & 0xffff;
> +	} else {
> +		/* if lower 16 bits are empty, this is the fw loader. */
> +		if ((version & 0xffff) == 0) {
> +			version = version >> 16;
> +			bp->fw_loader = true;
> +		}
> +		bp->fw_tag     = 3;
> +		bp->fw_version = version & 0xffff;
>   	}
> -	bp->fw_tag     = 3;
> -	bp->fw_version = version & 0xffff;
>   	bp->fw_cap     = OCP_CAP_BASIC | OCP_CAP_SIGNAL | OCP_CAP_FREQ;

you have to change capabilities as well as new board doesn't have signal
generators (OCP_CAP_SIGNAL)

>   
>   	ptp_ocp_tod_init(bp);
> @@ -3288,10 +3389,13 @@ ptp_ocp_adva_board_init(struct ptp_ocp *bp, struct ocp_resource *r)
>   	if (err)
>   		return err;
>   
> -	err = ptp_ocp_set_pins(bp);
> -	if (err)
> -		return err;
> -	ptp_ocp_sma_init(bp);
> +	/* boards without user-accessible SMA connectors have no sma_op */
> +	if (bp->sma_op) {
> +		err = ptp_ocp_set_pins(bp);
> +		if (err)
> +			return err;
> +		ptp_ocp_sma_init(bp);
> +	}
>   
>   	bp->has_cpld = info->has_cpld;
>   
> @@ -5180,13 +5284,35 @@ static const struct ocp_attr_group adva_timecard_x1_groups[] = {
>   	{ },
>   };
>   
> +/*
> + * X2 exposes the basic identity attributes plus the TAP CPLD status.  It
> + * has no user-accessible SMA connectors, signal generators or frequency
> + * inputs, so none of the SMA, signal or freq groups apply.
> + */
> +static struct attribute *adva_timecard_x2_attrs[] = {
> +	&dev_attr_serialnum.attr,
> +	&dev_attr_gnss_sync.attr,
> +	&dev_attr_cpld_status.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group adva_timecard_x2_group = {
> +	.attrs = adva_timecard_x2_attrs,
> +};
> +
> +static const struct ocp_attr_group adva_timecard_x2_groups[] = {
> +	{ .cap = OCP_CAP_BASIC,	    .group = &adva_timecard_x2_group },
> +	{ .cap = OCP_CAP_BASIC,	    .group = &ptp_ocp_timecard_tty_group },
> +	{ },
> +};
> +
>   static void
>   gpio_input_map(char *buf, struct ptp_ocp *bp, u16 map[][2], u16 bit,
>   	       const char *def)
>   {
>   	int i;
>   
> -	for (i = 0; i < 4; i++) {
> +	for (i = 0; bp->sma_op && i < 4; i++) {

I would prefer early exit based on sma_op pointer rather than useless
iterations
>   		if (bp->sma[i].mode != SMA_MODE_IN)
>   			continue;
>   		if (map[i][0] & (1 << bit)) {
> @@ -5206,7 +5332,7 @@ gpio_output_map(char *buf, struct ptp_ocp *bp, u16 map[][2], u16 bit)
>   	int i;
>   
>   	strcpy(ans, "----");
> -	for (i = 0; i < 4; i++) {
> +	for (i = 0; bp->sma_op && i < 4; i++) {
>   		if (bp->sma[i].mode != SMA_MODE_OUT)
>   			continue;
>   		if (map[i][1] & (1 << bit))
> @@ -5316,21 +5442,23 @@ ptp_ocp_summary_show(struct seq_file *s, void *data)
>   		sma_val[1][1] = reg >> 16;
>   	}
>   
> -	sma1_show(dev, NULL, buf);
> -	seq_printf(s, "   sma1: %04x,%04x %s",
> -		   sma_val[0][0], sma_val[0][1], buf);
> +	if (bp->sma_op) {
> +		sma1_show(dev, NULL, buf);
> +		seq_printf(s, "   sma1: %04x,%04x %s",
> +			   sma_val[0][0], sma_val[0][1], buf);
>   
> -	sma2_show(dev, NULL, buf);
> -	seq_printf(s, "   sma2: %04x,%04x %s",
> -		   sma_val[1][0], sma_val[1][1], buf);
> +		sma2_show(dev, NULL, buf);
> +		seq_printf(s, "   sma2: %04x,%04x %s",
> +			   sma_val[1][0], sma_val[1][1], buf);
>   
> -	sma3_show(dev, NULL, buf);
> -	seq_printf(s, "   sma3: %04x,%04x %s",
> -		   sma_val[2][0], sma_val[2][1], buf);
> +		sma3_show(dev, NULL, buf);
> +		seq_printf(s, "   sma3: %04x,%04x %s",
> +			   sma_val[2][0], sma_val[2][1], buf);
>   
> -	sma4_show(dev, NULL, buf);
> -	seq_printf(s, "   sma4: %04x,%04x %s",
> -		   sma_val[3][0], sma_val[3][1], buf);
> +		sma4_show(dev, NULL, buf);
> +		seq_printf(s, "   sma4: %04x,%04x %s",
> +			   sma_val[3][0], sma_val[3][1], buf);
> +	}
>   
>   	if (bp->ts0) {
>   		ts_reg = bp->ts0->mem;
> @@ -6032,7 +6160,7 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>   	if (err)
>   		goto out_dpll_put;
>   
> -	for (i = 0; i < OCP_SMA_NUM; i++) {
> +	for (i = 0; bp->sma_op && i < OCP_SMA_NUM; i++) {

here as well

>   		bp->sma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE,
>   						   &bp->sma[i].dpll_prop,
>   						   &bp->sma[i].tracker);
> 
> base-commit: 02e8a63b4685a4321c60d562edabecc097f4a0d9


---
pw-bot: cr

      reply	other threads:[~2026-12-03 11:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 14:31 [PATCH net-next] ptp: ocp: add support for the ADVA TimeCard X2 Sagi Maimon
2026-12-03 11:45 ` Vadim Fedorenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=096aeb5e-951a-4e66-a664-520c70b67b93@linux.dev \
    --to=vadim.fedorenko@linux.dev \
    --cc=andrew+netdev@lunn.ch \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=maimon.sagi@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=richardcochran@gmail.com \
    --cc=skhan@linuxfoundation.org \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox