Netdev List
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: sukhdeeps@marvell.com
Cc: Jakub Kicinski <kuba@kernel.org>,
	netdev@vger.kernel.org, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
	linux-kernel@vger.kernel.org, horms@kernel.org,
	vadim.fedorenko@linux.dev
Subject: Re: [PATCH net-next v3 10/12] net: atlantic: add AQC113 PTP hardware ops in hw_atl2
Date: Fri, 22 May 2026 18:25:02 -0700	[thread overview]
Message-ID: <20260523012502.1823591-1-kuba@kernel.org> (raw)
In-Reply-To: <20260520141046.2151-11-sukhdeeps@marvell.com>

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
net: atlantic: add AQC113 PTP hardware ops in hw_atl2

This commit adds the hardware-layer PTP implementation for AQC113 (Antigua).
It includes TSG clock programming, RX/TX timestamping mechanisms, and PPS
output generation via the TSG pulse generator.

> diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c
> index 39d84576ca519..d6a97a1ec5c65 100644
> --- a/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c
> +++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c
[ ... ]
> @@ -888,6 +924,151 @@ static struct aq_stats_s *hw_atl2_utils_get_hw_stats(struct aq_hw_s *self)
[ ... ]
> +static u64 hw_atl2_hw_ring_tx_ptp_get_ts(struct aq_ring_s *ring)
> +{
> +	struct hw_atl2_txts_s *txts;
> +	u32 ctrl;
> +
> +	txts = (struct hw_atl2_txts_s *)&ring->dx_ring[ring->sw_head *
> +						HW_ATL2_TXD_SIZE];
> +	/* DD + TS_VALID */
> +	ctrl = READ_ONCE(txts->ctrl);
> +	if ((ctrl & HW_ATL2_TXTS_DD) && (ctrl & HW_ATL2_TXTS_TS_VALID)) {

[Severity: High]
Will this fail to recognize valid TX timestamps on big-endian architectures?

The struct hw_atl2_txts_s is a hardware DMA structure, and the ctrl field
is defined as a native u32. When reading it via READ_ONCE(txts->ctrl) on a
big-endian system, the little-endian word is loaded into the CPU register
natively without byte-swapping, so ctrl & HW_ATL2_TXTS_DD will test the
wrong bit.

Should this field be defined as __le32 and accessed with le32_to_cpu()
instead?

> +		dma_rmb();
> +		return le64_to_cpu(txts->ts);
> +	}
> +
> +	return 0;
> +}
[ ... ]
> +static int hw_atl2_adj_sys_clock(struct aq_hw_s *self, s64 delta)
> +{
> +	s8 clk_sel = READ_ONCE(self->clk_select);
> +
> +	if (clk_sel < 0)
> +		return -ENODEV;
> +	if (delta >= 0)
> +		hw_atl2_tsg_clock_add(self, clk_sel, (u64)delta);
> +	else
> +		hw_atl2_tsg_clock_sub(self, clk_sel, (u64)(-delta));
> +
> +	return 0;
> +}
> +
> +static int hw_atl2_adj_clock_freq(struct aq_hw_s *self, s32 ppb)
> +{
> +	u32 freq = AQ2_HW_PTP_COUNTER_HZ;
> +	u64 divisor = 0, base_ns;
> +	u32 nsi_frac = 0, nsi;
> +	u32 nsi_rem;
> +	s8 clk_sel;
> +
> +	base_ns = div_u64((u64)((s64)ppb + NSEC_PER_SEC) * NSEC_PER_SEC, freq);
> +	nsi = (u32)div_u64_rem(base_ns, NSEC_PER_SEC, &nsi_rem);
> +	if (nsi_rem != 0) {
> +		divisor = div_u64(mul_u32_u32(NSEC_PER_SEC, NSEC_PER_SEC),
> +				  nsi_rem);
> +		nsi_frac = (u32)div64_u64(AQ_FRAC_PER_NS * NSEC_PER_SEC,
> +					  divisor);
> +	}
> +
> +	clk_sel = READ_ONCE(self->clk_select);
> +	if (clk_sel < 0)
> +		return -ENODEV;
> +	hw_atl2_tsg_clock_increment_set(self, clk_sel, nsi, nsi_frac);

[Severity: High]
Could these two clock adjustment functions race when writing to the hardware
command registers?

The core PTP operations execute adjfine holding
mutex_lock(&aq_nic->fwreq_mutex) and execute adjtime holding
spin_lock_irqsave(&aq_ptp->ptp_lock). Since hw_atl2_adj_sys_clock()
and hw_atl2_adj_clock_freq() are protected by different locks, can
concurrent calls from userspace interleave writes to the same
CLOCK_MODIF_CTRL hardware register and corrupt the PTP hardware clock state?

> +
> +	return 0;
> +}
[ ... ]
> diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils.h b/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils.h
> index c84955bc14ae4..ee7f444f6d07d 100644
> --- a/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils.h
> +++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils.h
> @@ -8,6 +8,16 @@
>  
>  #include "aq_hw.h"
>  
> +/* Hardware tx launch time descriptor */
> +struct hw_atl2_txts_s {
> +	__le64 ts;
> +	u32 ctrl;

[Severity: High]
Does this ctrl field need to be __le32? Since this is a hardware DMA
structure, declaring it as a native u32 causes endianness issues when read
on big-endian systems, as mentioned in the hw_atl2_hw_ring_tx_ptp_get_ts()
function above.

> +	u32 reserved;
> +};

  reply	other threads:[~2026-05-23  1:25 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-20 14:10 [PATCH net-next v3 0/12] net: atlantic: add PTP support for AQC113 (Antigua) sukhdeeps
2026-05-20 14:10 ` [PATCH net-next v3 1/12] net: atlantic: correct L3L4 filter flow_type masking and IPv6 handling sukhdeeps
2026-05-20 14:10 ` [PATCH net-next v3 2/12] net: atlantic: move active_ipv4/ipv6 bitmap updates after HW write sukhdeeps
2026-05-20 14:10 ` [PATCH net-next v3 3/12] net: atlantic: decouple aq_set_data_fl3l4() from driver internals sukhdeeps
2026-05-20 14:10 ` [PATCH net-next v3 4/12] net: atlantic: add AQC113 hardware register definitions and accessors sukhdeeps
2026-05-20 14:10 ` [PATCH net-next v3 5/12] net: atlantic: add AQC113 filter data structures and firmware query sukhdeeps
2026-05-20 14:10 ` [PATCH net-next v3 6/12] net: atlantic: fix AQC113 HW init: ART sections, L2 filter slot, MAC address sukhdeeps
2026-05-23  1:19   ` Jakub Kicinski
2026-05-20 14:10 ` [PATCH net-next v3 7/12] net: atlantic: implement AQC113 L2/L3/L4 RX filter ops sukhdeeps
2026-05-20 14:10 ` [PATCH net-next v3 8/12] net: atlantic: add AQC113 PTP traffic class and TX path setup sukhdeeps
2026-05-20 14:10 ` [PATCH net-next v3 9/12] net: atlantic: extend hw_ops and TX descriptor for AQC113 PTP sukhdeeps
2026-05-20 14:10 ` [PATCH net-next v3 10/12] net: atlantic: add AQC113 PTP hardware ops in hw_atl2 sukhdeeps
2026-05-23  1:25   ` Jakub Kicinski [this message]
2026-05-20 14:10 ` [PATCH net-next v3 11/12] net: atlantic: add AQC113 TX timestamp polling and PTP TX classification sukhdeeps
2026-05-23  1:25   ` Jakub Kicinski
2026-05-20 14:10 ` [PATCH net-next v3 12/12] net: atlantic: add AQC113 PTP support in aq_ptp and driver core sukhdeeps
2026-05-23  1:25   ` Jakub Kicinski

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=20260523012502.1823591-1-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sukhdeeps@marvell.com \
    --cc=vadim.fedorenko@linux.dev \
    /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