From 39e953886e9a4c66bd70315ae6c27699b0af31d4 Mon Sep 17 00:00:00 2001 From: Qosmio Date: Sat, 10 Sep 2022 01:53:36 -0400 Subject: [PATCH] nss-gmac: add timestamping feature and extra logging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit requires an entry in dts: example: qcom,tstamp-enabled; use ethtool to enable: root@R7800 ~ ➤ ethtool --set-priv-flags eth1 tstamp on [Sat Sep 10 01:24:22 2022] ipq8064-mdio 37000000.mdio eth0: nss_gmac_ts_enable: Timestamp enabled [Sat Sep 10 01:24:22 2022] ipq8064-mdio 37000000.mdio eth0: nss_gmac_set_priv_flags: Enabled 'Timestamp' flag (needed_headroom: 32) root@R7800 ~ ➤ cat /sys/devices/platform/soc/37000000.mdio/net/eth*/tstamp sec:1084 nsec:752452290 time-of-day: 1662789199.391664 sec:1087 nsec:309864290 time-of-day: 1662789199.391799 --- a/ipq806x/include/nss_gmac_dev.h +++ b/ipq806x/include/nss_gmac_dev.h @@ -1342,6 +1342,9 @@ void nss_gmac_disable_rx_chksum_offload( void nss_gmac_rx_tcpip_chksum_drop_enable(struct nss_gmac_dev *gmacdev); void nss_gmac_rx_tcpip_chksum_drop_disable(struct nss_gmac_dev *gmacdev); +void nss_gmac_tstamp_sysfs_create(struct net_device *dev); +void nss_gmac_tstamp_sysfs_remove(struct net_device *dev); + /** * The check summ offload engine is enabled to do complete checksum computation. * Hardware computes the tcp ip checksum including the pseudo header checksum. --- a/ipq806x/nss_gmac_ctrl.c +++ b/ipq806x/nss_gmac_ctrl.c @@ -651,7 +651,7 @@ static DEVICE_ATTR(fadj, 0220, NULL, nss static DEVICE_ATTR(mtnp, 0444, nss_gmac_mtnp_show, NULL); static DEVICE_ATTR(tstamp, 0444, nss_gmac_tstamp_show, NULL); -static void nss_gmac_tstamp_sysfs_create(struct net_device *dev) +void nss_gmac_tstamp_sysfs_create(struct net_device *dev) { if (device_create_file(&(dev->dev), &dev_attr_slam) || device_create_file(&(dev->dev), &dev_attr_cadj) || @@ -662,7 +662,7 @@ static void nss_gmac_tstamp_sysfs_create return; } -static void nss_gmac_tstamp_sysfs_remove(struct net_device *dev) +void nss_gmac_tstamp_sysfs_remove(struct net_device *dev) { device_remove_file(&(dev->dev), &dev_attr_slam); device_remove_file(&(dev->dev), &dev_attr_cadj); --- a/ipq806x/nss_gmac_ethtool.c +++ b/ipq806x/nss_gmac_ethtool.c @@ -559,6 +559,49 @@ static int32_t nss_gmac_set_priv_flags(s } /* + * Set timestamp + */ + if (changed & NSS_GMAC_PRIV_FLAG(TSTAMP)) { + if (flags & NSS_GMAC_PRIV_FLAG(TSTAMP)) { + if (!test_bit(__NSS_GMAC_TSTAMP, &gmacdev->flags)) { + /* + * Increase headroom for PTP/NTP timestamps + */ + netdev->needed_headroom += 32; + + /* + * Create sysfs entries for timestamp registers + */ + nss_gmac_tstamp_sysfs_create(netdev); + + if (nss_gmac_ts_enable(gmacdev)) { + netdev_info(netdev, "%s: Reg write error. Cannot enable Timestamping \n", __func__); + return -EINVAL; + } + + gmacdev->drv_flags |= NSS_GMAC_PRIV_FLAG(TSTAMP); + netdev_info(netdev, "%s: Enabled 'Timestamp' flag (needed_headroom: %dx)", __func__, netdev->needed_headroom); + } else { + netdev_warn(netdev, "%s: Already enabled 'Timestamp' flag", __func__); + } + } else { + /* + * Disable Timestamping if not already disabled + */ + if (!test_bit(__NSS_GMAC_TSTAMP, &gmacdev->flags)) { + netdev_warn(netdev, "%s: Timestamp is already disabled \n", __func__); + return -EINVAL; + } + + nss_gmac_ts_disable(gmacdev); + gmacdev->drv_flags &= ~NSS_GMAC_PRIV_FLAG(TSTAMP); + nss_gmac_tstamp_sysfs_remove(gmacdev->netdev); + // netdev->needed_headroom -= 32; + netdev_info(netdev, "%s: Disabled 'Timestamp' flag (needed_headroom: %dx)", __func__, netdev->needed_headroom); + } + } + + /* * Set ignore rx csum flag */ if (changed & NSS_GMAC_PRIV_FLAG(IGNORE_RX_CSUM_ERR)) {