Commit 2c7b4921 authored by Florian Fainelli's avatar Florian Fainelli Committed by David S. Miller

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: default avatarThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 45e98341
...@@ -682,7 +682,7 @@ void phy_stop(struct phy_device *phydev) ...@@ -682,7 +682,7 @@ void phy_stop(struct phy_device *phydev)
if (PHY_HALTED == phydev->state) if (PHY_HALTED == phydev->state)
goto out_unlock; goto out_unlock;
if (phydev->irq != PHY_POLL) { if (phy_interrupt_is_valid(phydev)) {
/* Disable PHY Interrupts */ /* Disable PHY Interrupts */
phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED); phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED);
...@@ -828,8 +828,9 @@ void phy_state_machine(struct work_struct *work) ...@@ -828,8 +828,9 @@ void phy_state_machine(struct work_struct *work)
break; break;
case PHY_RUNNING: case PHY_RUNNING:
/* Only register a CHANGE if we are /* Only register a CHANGE if we are
* polling */ * polling or ignoring interrupts
if (PHY_POLL == phydev->irq) */
if (!phy_interrupt_is_valid(phydev))
phydev->state = PHY_CHANGELINK; phydev->state = PHY_CHANGELINK;
break; break;
case PHY_CHANGELINK: case PHY_CHANGELINK:
...@@ -848,7 +849,7 @@ void phy_state_machine(struct work_struct *work) ...@@ -848,7 +849,7 @@ void phy_state_machine(struct work_struct *work)
phydev->adjust_link(phydev->attached_dev); phydev->adjust_link(phydev->attached_dev);
if (PHY_POLL != phydev->irq) if (phy_interrupt_is_valid(phydev))
err = phy_config_interrupt(phydev, err = phy_config_interrupt(phydev,
PHY_INTERRUPT_ENABLED); PHY_INTERRUPT_ENABLED);
break; break;
......
...@@ -1009,8 +1009,11 @@ static int phy_probe(struct device *dev) ...@@ -1009,8 +1009,11 @@ static int phy_probe(struct device *dev)
phydrv = to_phy_driver(drv); phydrv = to_phy_driver(drv);
phydev->drv = phydrv; phydev->drv = phydrv;
/* Disable the interrupt if the PHY doesn't support it */ /* Disable the interrupt if the PHY doesn't support it
if (!(phydrv->flags & PHY_HAS_INTERRUPT)) * but the interrupt is still a valid one
*/
if (!(phydrv->flags & PHY_HAS_INTERRUPT) &&
phy_interrupt_is_valid(phydev))
phydev->irq = PHY_POLL; phydev->irq = PHY_POLL;
mutex_lock(&phydev->lock); mutex_lock(&phydev->lock);
......
...@@ -508,6 +508,18 @@ static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val) ...@@ -508,6 +508,18 @@ static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val)
return mdiobus_write(phydev->bus, phydev->addr, regnum, val); return mdiobus_write(phydev->bus, phydev->addr, regnum, val);
} }
/**
* phy_interrupt_is_valid - Convenience function for testing a given PHY irq
* @phydev: the phy_device struct
*
* NOTE: must be kept in sync with addition/removal of PHY_POLL and
* PHY_IGNORE_INTERRUPT
*/
static inline bool phy_interrupt_is_valid(struct phy_device *phydev)
{
return phydev->irq != PHY_POLL && phydev->irq != PHY_IGNORE_INTERRUPT;
}
struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id, struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
bool is_c45, struct phy_c45_device_ids *c45_ids); bool is_c45, struct phy_c45_device_ids *c45_ids);
struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45); struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment