Skip to content

Commit

Permalink
net: phy: realtek: implement generic .handle_interrupt() callback
Browse files Browse the repository at this point in the history
In an attempt to actually support shared IRQs in phylib, we now move the
responsibility of triggering the phylib state machine or just returning
IRQ_NONE, based on the IRQ status register, to the PHY driver. Having
3 different IRQ handling callbacks (.handle_interrupt(),
.did_interrupt() and .ack_interrupt() ) is confusing so let the PHY
driver implement directly an IRQ handler like any other device driver.
Make this driver follow the new convention.

Cc: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Cc: Willy Liu <willy.liu@realtek.com>
Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Ioana Ciornei authored and Jakub Kicinski committed Nov 6, 2020
1 parent 87de1f0 commit 0382916
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions drivers/net/phy/realtek.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
#define RTL8211E_RX_DELAY BIT(11)

#define RTL8201F_ISR 0x1e
#define RTL8201F_ISR_ANERR BIT(15)
#define RTL8201F_ISR_DUPLEX BIT(13)
#define RTL8201F_ISR_LINK BIT(11)
#define RTL8201F_ISR_MASK (RTL8201F_ISR_ANERR | \
RTL8201F_ISR_DUPLEX | \
RTL8201F_ISR_LINK)
#define RTL8201F_IER 0x13

#define RTL8366RB_POWER_SAVE 0x15
Expand Down Expand Up @@ -149,6 +155,66 @@ static int rtl8211f_config_intr(struct phy_device *phydev)
return phy_write_paged(phydev, 0xa42, RTL821x_INER, val);
}

static irqreturn_t rtl8201_handle_interrupt(struct phy_device *phydev)
{
int irq_status;

irq_status = phy_read(phydev, RTL8201F_ISR);
if (irq_status < 0) {
phy_error(phydev);
return IRQ_NONE;
}

if (!(irq_status & RTL8201F_ISR_MASK))
return IRQ_NONE;

phy_trigger_machine(phydev);

return IRQ_HANDLED;
}

static irqreturn_t rtl821x_handle_interrupt(struct phy_device *phydev)
{
int irq_status, irq_enabled;

irq_status = phy_read(phydev, RTL821x_INSR);
if (irq_status < 0) {
phy_error(phydev);
return IRQ_NONE;
}

irq_enabled = phy_read(phydev, RTL821x_INER);
if (irq_enabled < 0) {
phy_error(phydev);
return IRQ_NONE;
}

if (!(irq_status & irq_enabled))
return IRQ_NONE;

phy_trigger_machine(phydev);

return IRQ_HANDLED;
}

static irqreturn_t rtl8211f_handle_interrupt(struct phy_device *phydev)
{
int irq_status;

irq_status = phy_read_paged(phydev, 0xa43, RTL8211F_INSR);
if (irq_status < 0) {
phy_error(phydev);
return IRQ_NONE;
}

if (!(irq_status & RTL8211F_INER_LINK_STATUS))
return IRQ_NONE;

phy_trigger_machine(phydev);

return IRQ_HANDLED;
}

static int rtl8211_config_aneg(struct phy_device *phydev)
{
int ret;
Expand Down Expand Up @@ -556,6 +622,7 @@ static struct phy_driver realtek_drvs[] = {
.name = "RTL8201F Fast Ethernet",
.ack_interrupt = &rtl8201_ack_interrupt,
.config_intr = &rtl8201_config_intr,
.handle_interrupt = rtl8201_handle_interrupt,
.suspend = genphy_suspend,
.resume = genphy_resume,
.read_page = rtl821x_read_page,
Expand All @@ -582,6 +649,7 @@ static struct phy_driver realtek_drvs[] = {
.name = "RTL8211B Gigabit Ethernet",
.ack_interrupt = &rtl821x_ack_interrupt,
.config_intr = &rtl8211b_config_intr,
.handle_interrupt = rtl821x_handle_interrupt,
.read_mmd = &genphy_read_mmd_unsupported,
.write_mmd = &genphy_write_mmd_unsupported,
.suspend = rtl8211b_suspend,
Expand All @@ -601,6 +669,7 @@ static struct phy_driver realtek_drvs[] = {
.name = "RTL8211DN Gigabit Ethernet",
.ack_interrupt = rtl821x_ack_interrupt,
.config_intr = rtl8211e_config_intr,
.handle_interrupt = rtl821x_handle_interrupt,
.suspend = genphy_suspend,
.resume = genphy_resume,
.read_page = rtl821x_read_page,
Expand All @@ -611,6 +680,7 @@ static struct phy_driver realtek_drvs[] = {
.config_init = &rtl8211e_config_init,
.ack_interrupt = &rtl821x_ack_interrupt,
.config_intr = &rtl8211e_config_intr,
.handle_interrupt = rtl821x_handle_interrupt,
.suspend = genphy_suspend,
.resume = genphy_resume,
.read_page = rtl821x_read_page,
Expand All @@ -621,6 +691,7 @@ static struct phy_driver realtek_drvs[] = {
.config_init = &rtl8211f_config_init,
.ack_interrupt = &rtl8211f_ack_interrupt,
.config_intr = &rtl8211f_config_intr,
.handle_interrupt = rtl8211f_handle_interrupt,
.suspend = genphy_suspend,
.resume = genphy_resume,
.read_page = rtl821x_read_page,
Expand Down Expand Up @@ -710,6 +781,7 @@ static struct phy_driver realtek_drvs[] = {
*/
.ack_interrupt = genphy_no_ack_interrupt,
.config_intr = genphy_no_config_intr,
.handle_interrupt = genphy_handle_interrupt_no_ack,
.suspend = genphy_suspend,
.resume = genphy_resume,
},
Expand Down

0 comments on commit 0382916

Please sign in to comment.