net: lan743x: implement ndo_hwtstamp_get()
authorVladimir Oltean <vladimir.oltean@nxp.com>
Wed, 14 May 2025 15:19:30 +0000 (18:19 +0300)
committerJakub Kicinski <kuba@kernel.org>
Fri, 16 May 2025 00:56:38 +0000 (17:56 -0700)
Permit programs such as "hwtstamp_ctl -i eth0" to retrieve the current
timestamping configuration of the NIC, rather than returning "Device
driver does not have support for non-destructive SIOCGHWTSTAMP."

The driver configures all channels with the same timestamping settings.
On TX, retrieve the settings of the first channel, those should be
representative for the entire NIC. On RX, save the filter settings in a
new adapter field.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Gerhard Engleder <gerhard@engleder-embedded.com>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Link: https://patch.msgid.link/20250514151931.1988047-2-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/microchip/lan743x_main.c
drivers/net/ethernet/microchip/lan743x_main.h
drivers/net/ethernet/microchip/lan743x_ptp.c
drivers/net/ethernet/microchip/lan743x_ptp.h

index b01695b..8806810 100644 (file)
@@ -1729,6 +1729,7 @@ int lan743x_rx_set_tstamp_mode(struct lan743x_adapter *adapter,
        default:
                        return -ERANGE;
        }
+       adapter->rx_tstamp_filter = rx_filter;
        return 0;
 }
 
@@ -3445,6 +3446,7 @@ static const struct net_device_ops lan743x_netdev_ops = {
        .ndo_change_mtu         = lan743x_netdev_change_mtu,
        .ndo_get_stats64        = lan743x_netdev_get_stats64,
        .ndo_set_mac_address    = lan743x_netdev_set_mac_address,
+       .ndo_hwtstamp_get       = lan743x_ptp_hwtstamp_get,
        .ndo_hwtstamp_set       = lan743x_ptp_hwtstamp_set,
 };
 
index db5fc73..02a28b7 100644 (file)
@@ -1087,6 +1087,7 @@ struct lan743x_adapter {
        phy_interface_t         phy_interface;
        struct phylink          *phylink;
        struct phylink_config   phylink_config;
+       int                     rx_tstamp_filter;
 };
 
 #define LAN743X_COMPONENT_FLAG_RX(channel)  BIT(20 + (channel))
index 026d166..a3b4838 100644 (file)
@@ -1736,6 +1736,24 @@ void lan743x_ptp_tx_timestamp_skb(struct lan743x_adapter *adapter,
        lan743x_ptp_tx_ts_complete(adapter);
 }
 
+int lan743x_ptp_hwtstamp_get(struct net_device *netdev,
+                            struct kernel_hwtstamp_config *config)
+{
+       struct lan743x_adapter *adapter = netdev_priv(netdev);
+       struct lan743x_tx *tx = &adapter->tx[0];
+
+       if (tx->ts_flags & TX_TS_FLAG_ONE_STEP_SYNC)
+               config->tx_type = HWTSTAMP_TX_ONESTEP_SYNC;
+       else if (tx->ts_flags & TX_TS_FLAG_TIMESTAMPING_ENABLED)
+               config->tx_type = HWTSTAMP_TX_ON;
+       else
+               config->tx_type = HWTSTAMP_TX_OFF;
+
+       config->rx_filter = adapter->rx_tstamp_filter;
+
+       return 0;
+}
+
 int lan743x_ptp_hwtstamp_set(struct net_device *netdev,
                             struct kernel_hwtstamp_config *config,
                             struct netlink_ext_ack *extack)
index 9581a79..e8d073b 100644 (file)
@@ -51,7 +51,8 @@ int lan743x_ptp_open(struct lan743x_adapter *adapter);
 void lan743x_ptp_close(struct lan743x_adapter *adapter);
 void lan743x_ptp_update_latency(struct lan743x_adapter *adapter,
                                u32 link_speed);
-
+int lan743x_ptp_hwtstamp_get(struct net_device *netdev,
+                            struct kernel_hwtstamp_config *config);
 int lan743x_ptp_hwtstamp_set(struct net_device *netdev,
                             struct kernel_hwtstamp_config *config,
                             struct netlink_ext_ack *extack);