Skip to content

Commit 2c7b492

Browse files
ffainellidavem330
authored andcommitted
phy: fix the use of PHY_IGNORE_INTERRUPT
When a PHY device is registered with the special IRQ value PHY_IGNORE_INTERRUPT (-2) it will not properly be handled by the PHY library: - it continues to poll its register, while we do not want this because such PHY link events or register changes are serviced by an Ethernet MAC - it will still try to configure PHY interrupts at the PHY level, such interrupts do not exist at the PHY but at the MAC level - the state machine only handles PHY_POLL, but should also handle PHY_IGNORE_INTERRUPT similarly This patch updates the PHY state machine and initialization paths to account for the specific PHY_IGNORE_INTERRUPT. Based on an earlier patch by Thomas Petazzoni, and reworked to add the missing bits. Add a helper phy_interrupt_is_valid() which specifically tests for a PHY interrupt not to be PHY_POLL or PHY_IGNORE_INTERRUPT and use it throughout the code. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 45e9834 commit 2c7b492

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

drivers/net/phy/phy.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ void phy_stop(struct phy_device *phydev)
682682
if (PHY_HALTED == phydev->state)
683683
goto out_unlock;
684684

685-
if (phydev->irq != PHY_POLL) {
685+
if (phy_interrupt_is_valid(phydev)) {
686686
/* Disable PHY Interrupts */
687687
phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED);
688688

@@ -828,8 +828,9 @@ void phy_state_machine(struct work_struct *work)
828828
break;
829829
case PHY_RUNNING:
830830
/* Only register a CHANGE if we are
831-
* polling */
832-
if (PHY_POLL == phydev->irq)
831+
* polling or ignoring interrupts
832+
*/
833+
if (!phy_interrupt_is_valid(phydev))
833834
phydev->state = PHY_CHANGELINK;
834835
break;
835836
case PHY_CHANGELINK:
@@ -848,7 +849,7 @@ void phy_state_machine(struct work_struct *work)
848849

849850
phydev->adjust_link(phydev->attached_dev);
850851

851-
if (PHY_POLL != phydev->irq)
852+
if (phy_interrupt_is_valid(phydev))
852853
err = phy_config_interrupt(phydev,
853854
PHY_INTERRUPT_ENABLED);
854855
break;

drivers/net/phy/phy_device.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,8 +1009,11 @@ static int phy_probe(struct device *dev)
10091009
phydrv = to_phy_driver(drv);
10101010
phydev->drv = phydrv;
10111011

1012-
/* Disable the interrupt if the PHY doesn't support it */
1013-
if (!(phydrv->flags & PHY_HAS_INTERRUPT))
1012+
/* Disable the interrupt if the PHY doesn't support it
1013+
* but the interrupt is still a valid one
1014+
*/
1015+
if (!(phydrv->flags & PHY_HAS_INTERRUPT) &&
1016+
phy_interrupt_is_valid(phydev))
10141017
phydev->irq = PHY_POLL;
10151018

10161019
mutex_lock(&phydev->lock);

include/linux/phy.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,18 @@ static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val)
508508
return mdiobus_write(phydev->bus, phydev->addr, regnum, val);
509509
}
510510

511+
/**
512+
* phy_interrupt_is_valid - Convenience function for testing a given PHY irq
513+
* @phydev: the phy_device struct
514+
*
515+
* NOTE: must be kept in sync with addition/removal of PHY_POLL and
516+
* PHY_IGNORE_INTERRUPT
517+
*/
518+
static inline bool phy_interrupt_is_valid(struct phy_device *phydev)
519+
{
520+
return phydev->irq != PHY_POLL && phydev->irq != PHY_IGNORE_INTERRUPT;
521+
}
522+
511523
struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
512524
bool is_c45, struct phy_c45_device_ids *c45_ids);
513525
struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);

0 commit comments

Comments
 (0)