From: Birger Koblitz <mail@birger-koblitz.de>
To: 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,
Birger Koblitz <mail@birger-koblitz.de>
Subject: [PATCH net-next 3/3] net: usb: ax88179: Enable PTP
Date: Sun, 29 Nov 2026 10:29:52 +0100 [thread overview]
Message-ID: <20261129-ptp-v1-3-8148c402beaf@birger-koblitz.de> (raw)
In-Reply-To: <20261129-ptp-v1-0-8148c402beaf@birger-koblitz.de>
Adds a module parameter ptp_enable which allows to enable PTP
support in the module. The default is not to enable PTP as PTP
is not compatible with segmentation offload on the AX88179A.
Add PTP configuration when the module binds and when the link
comes up. Add ax88179a_get_ts_info() to show PTP support
in ethtool.
Add hooks into the TX and RX path to handle timestamps.
Signed-off-by: Birger Koblitz <mail@birger-koblitz.de>
---
drivers/net/usb/ax88179a_devices.c | 149 +++++++++++++++++++++++++++++++++++--
1 file changed, 141 insertions(+), 8 deletions(-)
diff --git a/drivers/net/usb/ax88179a_devices.c b/drivers/net/usb/ax88179a_devices.c
index 69095110e70435806a99274c50d79e86016ec9a0..994e749ffaa2b5e2d7c1e1ec362bd55b9c882a86 100644
--- a/drivers/net/usb/ax88179a_devices.c
+++ b/drivers/net/usb/ax88179a_devices.c
@@ -4,16 +4,21 @@
#include <linux/phylink.h>
#include <linux/if_vlan.h>
#include "ax88179_lib.h"
+#include "ax88179a_ptp.h"
static int ax88179a_reset(struct usbnet *dev);
#define AX88279_EEPROM_LEN 0x4000
#define AX88179A_EEPROM_LEN (32 * 20)
+static bool ptp_enable;
+module_param(ptp_enable, bool, 0);
+MODULE_PARM_DESC(ptp_enable, "Enable PTP hardware timestamping");
+
enum ax_bulk_in_speeds {
BULK_IN_SPEED_2G5 = 0,
BULK_IN_SPEED_1G_SS = 1,
- BULK_IN_SPEED_1G_HS = 2,
+ BULK_IN_SPEED_1G_HS = 2,
BULK_IN_SPEED_100_FULL_SS = 3,
BULK_IN_SPEED_100_HALF_SS = 4,
BULK_IN_SPEED_100_FULL_HS = 5,
@@ -137,6 +142,9 @@ static int ax88179a_suspend(struct usb_interface *intf, pm_message_t message)
int ret;
priv = dev->driver_priv;
+ if (netif_running(dev->net))
+ ax88179a_ptp_kill_urbs(dev);
+
ax88179_set_pm_mode(dev, true);
if (netif_running(dev->net)) {
@@ -182,6 +190,7 @@ static int ax88179a_suspend(struct usb_interface *intf, pm_message_t message)
}
ax88179_set_pm_mode(dev, false);
+
return 0;
}
@@ -213,7 +222,8 @@ static int ax88179a_resume(struct usb_interface *intf)
ax88179_write_cmd(dev, AX88179A_PHY_POWER, 0, 0, 1, ®8);
msleep(250);
}
- ax88179_write_cmd(dev, AX_FW_MODE, AX_FW_MODE_179A, 0, 0, NULL);
+ ax88179_write_cmd(dev, AX_FW_MODE, AX_FW_MODE_179A,
+ ax179_data->ptp ? AX_USB_EP4_EN : 0, 0, NULL);
/* Now, that AX_FW_MODE_179A is enabled, the PHY needs a power-cycle.
* PHY-power is re-enabled in ax88179a_reset()
@@ -232,6 +242,11 @@ static int ax88179a_resume(struct usb_interface *intf)
ax88179_set_pm_mode(dev, false);
+ if (netif_running(dev->net) &&
+ ax179_data->chip_version == AX_VERSION_AX88279 && ax179_data->ptp) {
+ ax179_data->ptp->ptp_read_ts(dev);
+ }
+
return usbnet_resume(intf);
}
@@ -353,6 +368,42 @@ static int ax88179a_set_eee(struct net_device *net, struct ethtool_keee *edata)
return phylink_ethtool_set_eee(ax179_data->phylink, edata);
}
+static int ax88179a_get_ts_info(struct net_device *net,
+ struct kernel_ethtool_ts_info *info)
+{
+ struct ax88179_data *ax179_data = netdev2data(net);
+
+ if (!ax179_data->ptp)
+ return ethtool_op_get_ts_info(net, info);
+
+ info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
+ SOF_TIMESTAMPING_RX_SOFTWARE |
+ SOF_TIMESTAMPING_SOFTWARE |
+ SOF_TIMESTAMPING_TX_HARDWARE |
+ SOF_TIMESTAMPING_RX_HARDWARE |
+ SOF_TIMESTAMPING_RAW_HARDWARE;
+
+ info->phc_index = ax179_data->ptp->phc_index;
+
+ info->tx_types = BIT(HWTSTAMP_TX_OFF) |
+ BIT(HWTSTAMP_TX_ON) |
+ BIT(HWTSTAMP_TX_ONESTEP_SYNC) |
+ BIT(HWTSTAMP_TX_ONESTEP_P2P);
+
+ info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
+ BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
+ BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
+ BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
+ BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
+ BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
+ BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
+ BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
+ BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
+ BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
+
+ return 0;
+}
+
static const struct ethtool_ops ax88179a_ethtool_ops = {
.get_drvinfo = ax88179a_get_drvinfo,
.get_link = ethtool_op_get_link,
@@ -370,7 +421,7 @@ static const struct ethtool_ops ax88179a_ethtool_ops = {
.set_link_ksettings = ax88179a_set_link_ksettings,
.get_pauseparam = ax88179a_get_pauseparam,
.set_pauseparam = ax88179a_set_pauseparam,
- .get_ts_info = ethtool_op_get_ts_info,
+ .get_ts_info = ax88179a_get_ts_info,
};
static int ax88179a_vlan_rx_kill_vid(struct net_device *net, __be16 proto, u16 vid)
@@ -496,7 +547,19 @@ static void ax88179a_mac_config(struct phylink_config *config, unsigned int mode
static void ax88179a_mac_link_down(struct phylink_config *config,
unsigned int mode, phy_interface_t interface)
{
- /* Nothing to do */
+ struct usbnet *dev = netdev_priv(to_net_dev(config->dev));
+ struct ax88179_data *ax179_data = dev->driver_priv;
+
+ if (ax179_data->ptp) {
+ if (ax179_data->chip_version == AX_VERSION_AX88279) {
+ if (ax179_data->ptp->urb)
+ usb_kill_urb(ax179_data->ptp->urb);
+ }
+ if (ax179_data->ptp && ax179_data->chip_version == AX_VERSION_AX88179A)
+ cancel_work_sync(&ax179_data->ptp->req_tx_timestamp);
+
+ ax179_data->ptp->pps_ctrl(dev, false);
+ }
}
static void ax88179a_mac_link_up(struct phylink_config *config,
@@ -511,6 +574,9 @@ static void ax88179a_mac_link_up(struct phylink_config *config,
u8 bulk_config_speed = 0;
u16 mode;
+ if (ax179_data->ptp)
+ ax179_data->ptp->pps_ctrl(dev, true);
+
/* Stop RX/TX for link configuration */
ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, AX_RX_CTL_STOP);
ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_PATH, 1, 0);
@@ -606,6 +672,11 @@ static void ax88179a_mac_link_up(struct phylink_config *config,
ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_PATH, 1,
AX_MAC_RX_PATH_READY | AX_MAC_TX_PATH_READY);
+
+ if (ax179_data->ptp) {
+ ax179_data->ptp->ptp_config(dev, speed);
+ ax179_data->ptp->ptp_read_ts(dev);
+ }
}
static void ax88179a_mac_disable_tx_lpi(struct phylink_config *config)
@@ -797,6 +868,8 @@ static const struct net_device_ops ax88179a_netdev_ops = {
.ndo_set_features = ax88179a_set_features,
.ndo_vlan_rx_add_vid = ax88179a_vlan_rx_add_vid,
.ndo_vlan_rx_kill_vid = ax88179a_vlan_rx_kill_vid,
+ .ndo_hwtstamp_get = ax88179a_hwtstamp_get,
+ .ndo_hwtstamp_set = ax88179a_hwtstamp_set,
};
static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf)
@@ -896,8 +969,11 @@ static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf)
netif_set_tso_max_size(dev->net, 16384);
- /* Enable Transmission of Link Speed byte in interrupt URB */
- ax88179_write_cmd(dev, AX_FW_MODE, AX_FW_MODE_179A, 0, 0, NULL);
+ /* Enable Transmission of Link Speed byte in interrupt URB
+ * and optionally PTP functionality
+ */
+ ax88179_write_cmd(dev, AX_FW_MODE, AX_FW_MODE_179A,
+ ptp_enable ? AX_USB_EP4_EN : 0, 0, NULL);
ax88179_write_cmd(dev, AX_RELOAD_EEPROM_EFUSE, 0, 0, 0, NULL);
/* Read MAC address from DTB or ASIX chip */
@@ -927,6 +1003,30 @@ static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf)
*/
pm_runtime_get_noresume(&intf->dev);
+ if (!ptp_enable)
+ return 0;
+
+ ret = ax88179a_ptp_register(dev);
+ if (ret < 0) {
+ netdev_warn(dev->net, "Failed to register PHC device. (%d)\n", ret);
+ netdev_warn(dev->net, "PTP disabled\n");
+ /* Disable PTP functionality again and cycle PHY to take effect */
+ ax88179_write_cmd(dev, AX_FW_MODE, AX_FW_MODE_179A, 0, 0, NULL);
+ ax88179_write_u8(dev, AX88179A_PHY_POWER, 0, 0, 0);
+ msleep(50);
+ return 0;
+ }
+
+ if (ax179_data->ptp && ax179_data->chip_version == AX_VERSION_AX88179A) {
+ ax179_data->ptp->ptp_config(dev, SPEED_UNKNOWN);
+
+ /* Power cycle PHY to make PTP settings take effect,
+ * reset() will power on the PHY again
+ */
+ ax88179_write_u8(dev, AX88179A_PHY_POWER, 0, 0, 0);
+ msleep(50);
+ }
+
return 0;
initphy_err:
@@ -946,6 +1046,8 @@ static void ax88179a_unbind(struct usbnet *dev, struct usb_interface *intf)
/* Configure RX control register => stop operation */
ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, AX_RX_CTL_STOP);
+ ax88179a_ptp_kill_urbs(dev);
+ ax88179a_ptp_unregister(dev);
rtnl_lock();
phylink_disconnect_phy(ax179_data->phylink);
@@ -1017,8 +1119,10 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
hdr_off = FIELD_GET(AX179A_RX_DH_DESC_OFFSET, rx_hdr);
pkt_cnt = rx_hdr & AX179A_RX_DH_PKT_CNT_MASK;
- /* Consistency check header position */
- if (hdr_off != skb->len - (pkt_cnt * sizeof(rx_hdr)))
+ /* Consistency check header position, frames with PTP timestamps
+ * have longer headers than normal frames, so check for minimum size
+ */
+ if (hdr_off > skb->len - (pkt_cnt * sizeof(rx_hdr)))
goto err;
/* Make sure that the bounds of the metadata array are inside the SKB
@@ -1075,6 +1179,13 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
__vlan_hwaccel_put_tag(ax_skb, htons(ETH_P_8021Q), vlan_tag);
}
+ if (pkt_desc & AX179A_RX_PD_PTP) {
+ u64 ts_l = get_unaligned_le64(++pkt_desc_ptr);
+ u64 ts_h = get_unaligned_le64(++pkt_desc_ptr);
+
+ ax88179a_process_rx_ts(ax_skb, ts_l, ts_h);
+ }
+
usbnet_skb_return(dev, ax_skb);
skb_pull(skb, pkt_len_plus_padd);
@@ -1090,6 +1201,7 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
static struct sk_buff *ax88179a_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
{
+ struct ax88179_data *ax179_data = dev->driver_priv;
u64 tx_desc = skb->len & AX179A_TX_DESC_LEN_MASK;
int frame_size = dev->maxpacket;
struct sk_buff *ax_skb;
@@ -1132,6 +1244,24 @@ static struct sk_buff *ax88179a_tx_fixup(struct usbnet *dev, struct sk_buff *skb
}
if (padding_size != 0)
skb_put_zero(skb, padding_size);
+
+ if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && ax179_data->ptp) {
+ struct sk_buff *ptp_skb;
+
+ /* Keep the original SKB owned by the socket in our
+ * queue with PTP SKBs, while continuing TX with a
+ * clone, so that skb_tstamp_tx() can later return
+ * the TX timestamp via the socket's error channel.
+ */
+ skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
+ ptp_skb = skb_clone(skb, GFP_ATOMIC);
+ skb_queue_tail(&ax179_data->ptp->tx_skbs, skb);
+ skb = ptp_skb;
+ // Get the TX timestamp
+ if (ax179_data->chip_version == AX_VERSION_AX88179A)
+ schedule_work(&ax179_data->ptp->req_tx_timestamp);
+ }
+
/* Copy TX header */
tx_desc_ptr = skb_push(skb, sizeof(tx_desc));
put_unaligned_le64(tx_desc, tx_desc_ptr);
@@ -1261,6 +1391,9 @@ static int ax88179a_stop(struct usbnet *dev)
struct ax88179_data *ax179_data = dev->driver_priv;
u16 reg16 = 0;
+ if (ax179_data->ptp && ax179_data->chip_version == AX_VERSION_AX88179A)
+ cancel_work_sync(&ax179_data->ptp->req_tx_timestamp);
+
phylink_stop(ax179_data->phylink);
ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, 2, ®16);
--
2.47.3
next prev parent reply other threads:[~2026-11-29 9:30 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
2026-11-29 9:29 ` Birger Koblitz [this message]
2026-11-29 15:48 ` [PATCH net-next 3/3] net: usb: ax88179: Enable PTP 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=20261129-ptp-v1-3-8148c402beaf@birger-koblitz.de \
--to=mail@birger-koblitz.de \
--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=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®