Re: [RFC PATCH v2 2/2] net: phy: at803x: add PTP support for AR8031
From: Richard Cochran <richardcochran@gmail.com>
Date: 2020-03-01 12:22:17
Also in:
lkml
On Fri, Feb 28, 2020 at 07:02:26PM +0100, Michael Walle wrote:
+static int at8031_rtc_adjust(struct phy_device *phydev, s64 delta)
+{
+ struct timespec64 ts = ns_to_timespec64(delta);
+ int ret;Here the 'ts' is written in multiple steps,
+ ret = phy_write_mmd(phydev, MDIO_MMD_PCS, + AT8031_MMD3_RTC_OFFSET_SEC_2, + (ts.tv_sec >> 32) & 0xffff); + if (ret) + return ret; + + ret = phy_write_mmd(phydev, MDIO_MMD_PCS, + AT8031_MMD3_RTC_OFFSET_SEC_1, + (ts.tv_sec >> 16) & 0xffff); + if (ret) + return ret; + + ret = phy_write_mmd(phydev, MDIO_MMD_PCS, + AT8031_MMD3_RTC_OFFSET_SEC_0, + ts.tv_sec & 0xffff); + if (ret) + return ret; + + ret = phy_write_mmd(phydev, MDIO_MMD_PCS, + AT8031_MMD3_RTC_OFFSET_NSEC_1, + (ts.tv_nsec >> 16) & 0xffff); + if (ret) + return ret; + + ret = phy_write_mmd(phydev, MDIO_MMD_PCS, + AT8031_MMD3_RTC_OFFSET_NSEC_0, + ts.tv_nsec & 0xffff); + if (ret) + return ret; + + return phy_write_mmd(phydev, MDIO_MMD_PCS, AT8031_MMD3_RTC_ADJUST, + AT8031_RTC_ADJUST); +}
...
+static int at8031_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
+{
+ struct at803x_priv *priv =
+ container_of(ptp, struct at803x_priv, ptp_info);
+ struct phy_device *phydev = priv->phydev;
+
+ return at8031_rtc_adjust(phydev, delta);
+}... and here there is no locking. You would need a mutex here and elsewhere to prevent multiple readers/writers from accessing the device registers asynchronously. (I know this is a just a RFC and that there are bigger problems with the HW, but just saying.) Thanks, Richard