mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Manuel Ebner <manuelebnerli@mailbox.org>
To: Birger Koblitz <mail@birger-koblitz.de>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	 "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Richard Cochran <richardcochran@gmail.com>,
	Russell King	 <linux@armlinux.org.uk>
Cc: netdev@vger.kernel.org, linux-usb@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 2/3] net: usb: ax88179: Add PTP Implementation
Date: Sun, 29 Nov 2026 19:31:25 +0100	[thread overview]
Message-ID: <b566b5c43c755cb5316fcf004795ad483395011c.camel@mailbox.org> (raw)
In-Reply-To: <20261129-ptp-v1-2-8148c402beaf@birger-koblitz.de>

On Sun, 2026-11-29 at 10:29 +0100, Birger Koblitz wrote:
> Adds support to match TX timestamps for packets for which TX timestamps
> are requested against TX timestamps received separately by the host and
> processing of the hardware timestamps inserted in received frames.
> 
> For both AX88179A and AX88279 support for a PTP clock with adjfine(),
> adjtime(), gettime64() and settime64() is added.
> 
> AX88179A and AX88279 implement reception of the TX timestamp information
> differently: the AX279A uses USB bulk requests, whereas the AX88179A uses
> a control transfer read. Since the control transfer reads via usbnet are
> synchronous (in contrast to the AX88279A bulk reads), they are handled as
> work items.
> 
> TX frames for which a timestamp is requested are copied to a separate
> ptp->tx_skbs queue and matched in a delayed work against received TX
> timestamps.
> 
> Signed-off-by: Birger Koblitz <mail@birger-koblitz.de>
> ---
>  drivers/net/usb/Kconfig        |   1 +
>  drivers/net/usb/Makefile       |   2 +-
>  drivers/net/usb/ax88179a_ptp.c | 845 +++++++++++++++++++++++++++++++++++++++++
>  drivers/net/usb/ax88179a_ptp.h | 249 ++++++++++++
>  4 files changed, 1096 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
> index cc8f2e150339915908fe1c28dea82e1103bbf17d..2a811116d34dc1a5d2225d947662b983dac7ddfe 100644
> --- a/drivers/net/usb/Kconfig
> +++ b/drivers/net/usb/Kconfig
> @@ -166,6 +166,7 @@ config USB_USBNET
>  config USB_NET_AX8817X
>  	tristate "ASIX AX88xxx Based USB 2.0 Ethernet Adapters"
>  	depends on USB_USBNET
> +	depends on PTP_1588_CLOCK_OPTIONAL
>  	select CRC32
>  	select PHYLINK
>  	select AX88796B_PHY
> diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
> index 4026f19ecb826a6465de38f1d9bb0e4c0af80421..812adcf839dc4061d4d6ef27025a26723bd51927 100644
> --- a/drivers/net/usb/Makefile
> +++ b/drivers/net/usb/Makefile
> @@ -13,7 +13,7 @@ obj-$(CONFIG_USB_LAN78XX)	+= lan78xx.o
>  obj-$(CONFIG_USB_NET_AX8817X)	+= asix.o
>  asix-y := asix_devices.o asix_common.o ax88172a.o
>  obj-$(CONFIG_USB_NET_AX88179)      += ax88179.o
> -ax88179-y := ax88179_178a.o ax88179a_devices.o ax88179_lib.o
> +ax88179-y := ax88179_178a.o ax88179a_devices.o ax88179_lib.o ax88179a_ptp.o
>  obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o
>  obj-$(CONFIG_USB_NET_CDC_EEM)	+= cdc_eem.o
>  obj-$(CONFIG_USB_NET_DM9601)	+= dm9601.o
> diff --git a/drivers/net/usb/ax88179a_ptp.c b/drivers/net/usb/ax88179a_ptp.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..9a04a93e509523436ccd19895b2a6cb6a819aea0
> --- /dev/null
> +++ b/drivers/net/usb/ax88179a_ptp.c
> @@ -0,0 +1,845 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +
> +#include <linux/ptp_clock_kernel.h>
> +#include <linux/net_tstamp.h>

Sort headers alphabetically. 

> +#include <linux/ptp_classify.h>
> +#include "ax88179_lib.h"
> +#include "ax88179a_ptp.h"
> +
> +#define ptp_to_dev(ptp) container_of(ptp, struct ax88179a_ptp, ptp_ci)
> +
> +static int ax88279_ptp_pbus_write(struct usbnet *dev, u16 offset,
> +				  u16 len, void *data)
> +{
> +	int ret;
> +
> +	ret = ax88179_write_cmd(dev, AX88279_PBUS_A32, offset,
> +				AX88279_PTP_REG_BASE_ADDR_HI, len, data);
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;
> +}
> +
> +static int ax88279_ptp_pbus_write_u32(struct usbnet *dev, u16 offset, u32 data)
> +{
> +	u32 buf = data;
> +
> +	return ax88279_ptp_pbus_write(dev, offset, 4, &buf);
> +}
> +
> +static int ax88279_ptp_clk_read(struct usbnet *dev, u16 offset, u16 len, void *data)
> +{
> +	int ret;
> +
> +	ret = ax88179_read_cmd(dev, AX_PTP_CLK, 0x0002, offset, len, data);
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;
> +}
> +
> +static int ax88279_ptp_clk_write(struct usbnet *dev, u16 offset, u16 len, void *data)
> +{
> +	int ret;
> +
> +	ret = ax88179_write_cmd(dev, AX88279_PBUS_A32, offset,
> +				AX88279_PTP_REG_BASE_ADDR_HI, len, data);
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;
> +}
> +
> +void ax88179a_process_rx_ts(struct sk_buff *skb, u64 timestamp_l, u64 timestamp_h)
> +{
> +	struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb);
> +	u64 time64;
> +
> +	timestamp_h <<= 32;
> +	timestamp_h |= (timestamp_l >> 32) & 0xFFFFFFFF;
> +	time64 = (timestamp_h * NSEC_PER_SEC);
> +	time64 += (timestamp_l & 0xFFFFFFFF);
> +
> +	memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps));
> +
> +	shhwtstamps->hwtstamp = ktime_sub_ns(ns_to_ktime(time64), 0);
> +}
> +
> +static int ax88179a_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
> +{
> +	long ppb = scaled_ppm_to_ppb(scaled_ppm);
> +	struct ax88179a_ptp *ax88179a_ptp;
> +	struct ax88179_data *ax179_data;
> +	bool neg_adj = false;
> +	u32 new_addend_val;
> +	u64 adjust_val;
> +	int ret = 0;
> +
> +	ax88179a_ptp = ptp_to_dev(ptp);
> +	ax179_data  = ax88179a_ptp->ax179_data;
Here's a double" "^^.

Reviewed-by: Manuel Ebner <manuelebnerli@mailbox.org>

Thanks
 Manuel

> [...]

  reply	other threads:[~2026-11-29 18:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  9:29 [PATCH net-next 0/3] net: usb: ax88179: Add support for PTP Birger Koblitz
2026-11-29  9:29 ` [PATCH net-next 1/3] net: usb: ax88179: Add PTP data structures and definitions Birger Koblitz
2026-11-29  9:29 ` [PATCH net-next 2/3] net: usb: ax88179: Add PTP Implementation Birger Koblitz
2026-11-29 18:31   ` Manuel Ebner [this message]
2026-11-29  9:29 ` [PATCH net-next 3/3] net: usb: ax88179: Enable PTP Birger Koblitz
2026-11-29 15:48   ` Andrew Lunn
2026-11-29 17:24     ` Birger Koblitz
2026-11-29 21:09       ` Andrew Lunn
2026-11-29 21:18   ` kernel test robot

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=b566b5c43c755cb5316fcf004795ad483395011c.camel@mailbox.org \
    --to=manuelebnerli@mailbox.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mail@birger-koblitz.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.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

all inboxes | Powered by JetHome®