The driver was adjusting stored values independently of what was actually supported and configured. Improve logic to store values once all checks are passing Signed-off-by: Vadim Fedorenko --- drivers/net/phy/micrel.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 05de68b9f719..1ada05dd305c 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -3157,9 +3157,6 @@ static int lan8814_hwtstamp_set(struct mii_timestamper *mii_ts, int txcfg = 0, rxcfg = 0; int pkt_ts_enable; - ptp_priv->hwts_tx_type = config->tx_type; - ptp_priv->rx_filter = config->rx_filter; - switch (config->rx_filter) { case HWTSTAMP_FILTER_NONE: ptp_priv->layer = 0; @@ -3187,6 +3184,18 @@ static int lan8814_hwtstamp_set(struct mii_timestamper *mii_ts, return -ERANGE; } + switch (config->rx_filter) { + case HWTSTAMP_TX_OFF: + case HWTSTAMP_TX_ON: + case HWTSTAMP_TX_ONESTEP_SYNC: + break; + default: + return -ERANGE; + } + + ptp_priv->hwts_tx_type = config->tx_type; + ptp_priv->rx_filter = config->rx_filter; + if (ptp_priv->layer & PTP_CLASS_L2) { rxcfg = PTP_RX_PARSE_CONFIG_LAYER2_EN_; txcfg = PTP_TX_PARSE_CONFIG_LAYER2_EN_; @@ -5051,9 +5060,6 @@ static int lan8841_hwtstamp_set(struct mii_timestamper *mii_ts, int txcfg = 0, rxcfg = 0; int pkt_ts_enable; - ptp_priv->hwts_tx_type = config->tx_type; - ptp_priv->rx_filter = config->rx_filter; - switch (config->rx_filter) { case HWTSTAMP_FILTER_NONE: ptp_priv->layer = 0; @@ -5081,6 +5087,9 @@ static int lan8841_hwtstamp_set(struct mii_timestamper *mii_ts, return -ERANGE; } + ptp_priv->hwts_tx_type = config->tx_type; + ptp_priv->rx_filter = config->rx_filter; + /* Setup parsing of the frames and enable the timestamping for ptp * frames */ -- 2.47.3 The driver stores HW timestamping configuration and can technically report it. Add callback to do it. Signed-off-by: Vadim Fedorenko --- drivers/net/phy/micrel.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 1ada05dd305c..b48553edbfa4 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -3147,6 +3147,18 @@ static void lan8814_flush_fifo(struct phy_device *phydev, bool egress) lanphy_read_page_reg(phydev, LAN8814_PAGE_PORT_REGS, PTP_TSU_INT_STS); } +static int lan8814_hwtstamp_get(struct mii_timestamper *mii_ts, + struct kernel_hwtstamp_config *config) +{ + struct kszphy_ptp_priv *ptp_priv = + container_of(mii_ts, struct kszphy_ptp_priv, mii_ts); + + config->tx_type = ptp_priv->hwts_tx_type; + config->rx_filter = ptp_priv->rx_filter; + + return 0; +} + static int lan8814_hwtstamp_set(struct mii_timestamper *mii_ts, struct kernel_hwtstamp_config *config, struct netlink_ext_ack *extack) @@ -4399,6 +4411,7 @@ static void lan8814_ptp_init(struct phy_device *phydev) ptp_priv->mii_ts.rxtstamp = lan8814_rxtstamp; ptp_priv->mii_ts.txtstamp = lan8814_txtstamp; ptp_priv->mii_ts.hwtstamp_set = lan8814_hwtstamp_set; + ptp_priv->mii_ts.hwtstamp_get = lan8814_hwtstamp_get; ptp_priv->mii_ts.ts_info = lan8814_ts_info; phydev->mii_ts = &ptp_priv->mii_ts; @@ -5934,6 +5947,7 @@ static int lan8841_probe(struct phy_device *phydev) ptp_priv->mii_ts.rxtstamp = lan8841_rxtstamp; ptp_priv->mii_ts.txtstamp = lan8814_txtstamp; ptp_priv->mii_ts.hwtstamp_set = lan8841_hwtstamp_set; + ptp_priv->mii_ts.hwtstamp_get = lan8814_hwtstamp_get; ptp_priv->mii_ts.ts_info = lan8841_ts_info; phydev->mii_ts = &ptp_priv->mii_ts; -- 2.47.3 The driver stores new HW timestamping configuration values unconditionally and may create inconsistency with what is actually configured in case of error. Improve the logic to store new values only once everything is configured. Signed-off-by: Vadim Fedorenko --- drivers/net/phy/microchip_rds_ptp.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/microchip_rds_ptp.c b/drivers/net/phy/microchip_rds_ptp.c index 4c6326b0ceaf..6a7a0bb95301 100644 --- a/drivers/net/phy/microchip_rds_ptp.c +++ b/drivers/net/phy/microchip_rds_ptp.c @@ -488,9 +488,6 @@ static int mchp_rds_ptp_hwtstamp_set(struct mii_timestamper *mii_ts, unsigned long flags; int rc; - clock->hwts_tx_type = config->tx_type; - clock->rx_filter = config->rx_filter; - switch (config->rx_filter) { case HWTSTAMP_FILTER_NONE: clock->layer = 0; @@ -518,6 +515,15 @@ static int mchp_rds_ptp_hwtstamp_set(struct mii_timestamper *mii_ts, return -ERANGE; } + switch (config->rx_filter) { + case HWTSTAMP_TX_ONESTEP_SYNC: + case HWTSTAMP_TX_ON: + case HWTSTAMP_TX_OFF: + break; + default: + return -ERANGE; + } + /* Setup parsing of the frames and enable the timestamping for ptp * frames */ @@ -553,7 +559,7 @@ static int mchp_rds_ptp_hwtstamp_set(struct mii_timestamper *mii_ts, if (rc < 0) return rc; - if (clock->hwts_tx_type == HWTSTAMP_TX_ONESTEP_SYNC) + if (config->tx_type == HWTSTAMP_TX_ONESTEP_SYNC) /* Enable / disable of the TX timestamp in the SYNC frames */ rc = mchp_rds_phy_modify_mmd(clock, MCHP_RDS_PTP_TX_MOD, MCHP_RDS_PTP_PORT, @@ -587,8 +593,13 @@ static int mchp_rds_ptp_hwtstamp_set(struct mii_timestamper *mii_ts, /* Now enable the timestamping interrupts */ rc = mchp_rds_ptp_config_intr(clock, config->rx_filter != HWTSTAMP_FILTER_NONE); + if (rc < 0) + return rc; - return rc < 0 ? rc : 0; + clock->hwts_tx_type = config->tx_type; + clock->rx_filter = config->rx_filter; + + return 0; } static int mchp_rds_ptp_ts_info(struct mii_timestamper *mii_ts, -- 2.47.3 The driver stores HW timestamping configuration and can technically report it. Add callback to do it. Reviewed-by: Kory Maincent Signed-off-by: Vadim Fedorenko --- drivers/net/phy/microchip_rds_ptp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/net/phy/microchip_rds_ptp.c b/drivers/net/phy/microchip_rds_ptp.c index 6a7a0bb95301..ad066d66a467 100644 --- a/drivers/net/phy/microchip_rds_ptp.c +++ b/drivers/net/phy/microchip_rds_ptp.c @@ -476,6 +476,18 @@ static bool mchp_rds_ptp_rxtstamp(struct mii_timestamper *mii_ts, return true; } +static int mchp_rds_ptp_hwtstamp_get(struct mii_timestamper *mii_ts, + struct kernel_hwtstamp_config *config) +{ + struct mchp_rds_ptp_clock *clock = + container_of(mii_ts, struct mchp_rds_ptp_clock, + mii_ts); + config->tx_type = clock->hwts_tx_type; + config->rx_filter = clock->rx_filter; + + return 0; +} + static int mchp_rds_ptp_hwtstamp_set(struct mii_timestamper *mii_ts, struct kernel_hwtstamp_config *config, struct netlink_ext_ack *extack) @@ -1293,6 +1305,7 @@ struct mchp_rds_ptp_clock *mchp_rds_ptp_probe(struct phy_device *phydev, u8 mmd, clock->mii_ts.rxtstamp = mchp_rds_ptp_rxtstamp; clock->mii_ts.txtstamp = mchp_rds_ptp_txtstamp; clock->mii_ts.hwtstamp_set = mchp_rds_ptp_hwtstamp_set; + clock->mii_ts.hwtstamp_get = mchp_rds_ptp_hwtstamp_get; clock->mii_ts.ts_info = mchp_rds_ptp_ts_info; phydev->mii_ts = &clock->mii_ts; -- 2.47.3