Re: [PATCH net-next 2/3] net: usb: ax88179: Add PTP Implementation

From: Manuel Ebner

Date: Sun Nov 29 2026 - 13:31:43 EST


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@xxxxxxxxxxxxxxxxx>
> ---
>  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@xxxxxxxxxxx>

Thanks
Manuel

> [...]