diff mbox series

[net] net: phy: nxp-c45-tja11xx: fix the PTP interrupt enabling/disabling

Message ID 20230410124856.287753-1-radu-nicolae.pirea@oss.nxp.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net] net: phy: nxp-c45-tja11xx: fix the PTP interrupt enabling/disabling | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 18 this patch: 18
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 18 this patch: 18
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 26 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Radu Pirea (NXP OSS) April 10, 2023, 12:48 p.m. UTC
.config_intr() handles only the link event interrupt and should also
disable/enable the PTP interrupt.

Even if the PTP irqs bit is toggled unconditionally, it is safe. This
interrupt acts as a global switch for all PTP irqs. By default, this bit
is set.

Fixes: 514def5dd339 ("phy: nxp-c45-tja11xx: add timestamping support")
CC: stable@vger.kernel.org # 5.15+
Signed-off-by: Radu Pirea (OSS) <radu-nicolae.pirea@oss.nxp.com>
---
 drivers/net/phy/nxp-c45-tja11xx.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Jakub Kicinski April 13, 2023, 3:44 a.m. UTC | #1
On Mon, 10 Apr 2023 15:48:56 +0300 Radu Pirea (OSS) wrote:
> -	if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
> +	if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
> +		phy_set_bits_mmd(phydev, MDIO_MMD_VEND1, PTP_IRQS, PTP_IRQS);

Isn't the third argument supposed to be the address?
Am I missing something or this patch was no tested properly?

Also why ignore the return value?

>  		return phy_set_bits_mmd(phydev, MDIO_MMD_VEND1,
>  					VEND1_PHY_IRQ_EN, PHY_IRQ_LINK_EVENT);
> -	else
> +	} else {
> +		phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1, PTP_IRQS, PTP_IRQS);
>  		return phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1,
>  					  VEND1_PHY_IRQ_EN, PHY_IRQ_LINK_EVENT);
> +	}
Radu Pirea (NXP OSS) April 24, 2023, 9:08 a.m. UTC | #2
On 13.04.2023 06:44, Jakub Kicinski wrote:
> On Mon, 10 Apr 2023 15:48:56 +0300 Radu Pirea (OSS) wrote:
>> -	if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
>> +	if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
>> +		phy_set_bits_mmd(phydev, MDIO_MMD_VEND1, PTP_IRQS, PTP_IRQS);
> 
> Isn't the third argument supposed to be the address?
> Am I missing something or this patch was no tested properly?
Yes, you are right. Thank you for this catch. I discovered this fix 
based on a driver code review and it did not trigger any issues. I just 
wanted to be sure if the PTP irqs are left in an inconsistent state, 
they are disabled from the kill switch.

I will send a v2.

> 
> Also why ignore the return value?
This register might not be present on every PHY, that's why the return 
value is ignored.

Radu P.

[...]
Andrew Lunn April 24, 2023, 11:56 a.m. UTC | #3
> > Also why ignore the return value?
> This register might not be present on every PHY, that's why the return value
> is ignored.

Please document that, otherwise you might see people add code to check
the return value. Or better, still, differentiate between the
different versions, and only touch it when it does exist.

	  Andtrew
diff mbox series

Patch

diff --git a/drivers/net/phy/nxp-c45-tja11xx.c b/drivers/net/phy/nxp-c45-tja11xx.c
index 5813b07242ce..4d7f4cb05f89 100644
--- a/drivers/net/phy/nxp-c45-tja11xx.c
+++ b/drivers/net/phy/nxp-c45-tja11xx.c
@@ -63,6 +63,9 @@ 
 #define VEND1_PORT_ABILITIES		0x8046
 #define PTP_ABILITY			BIT(3)
 
+#define VEND1_PORT_FUNC_IRQ_EN		0x807A
+#define PTP_IRQS			BIT(3)
+
 #define VEND1_PORT_INFRA_CONTROL	0xAC00
 #define PORT_INFRA_CONTROL_EN		BIT(14)
 
@@ -890,12 +893,15 @@  static int nxp_c45_start_op(struct phy_device *phydev)
 
 static int nxp_c45_config_intr(struct phy_device *phydev)
 {
-	if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
+	if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
+		phy_set_bits_mmd(phydev, MDIO_MMD_VEND1, PTP_IRQS, PTP_IRQS);
 		return phy_set_bits_mmd(phydev, MDIO_MMD_VEND1,
 					VEND1_PHY_IRQ_EN, PHY_IRQ_LINK_EVENT);
-	else
+	} else {
+		phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1, PTP_IRQS, PTP_IRQS);
 		return phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1,
 					  VEND1_PHY_IRQ_EN, PHY_IRQ_LINK_EVENT);
+	}
 }
 
 static irqreturn_t nxp_c45_handle_interrupt(struct phy_device *phydev)