2020-11-13 16:54:37

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 00/18] net: phy: add support for shared interrupts (part 2)

From: Ioana Ciornei <[email protected]>

This patch set aims to actually add support for shared interrupts in
phylib and not only for multi-PHY devices. While we are at it,
streamline the interrupt handling in phylib.

For a bit of context, at the moment, there are multiple phy_driver ops
that deal with this subject:

- .config_intr() - Enable/disable the interrupt line.

- .ack_interrupt() - Should quiesce any interrupts that may have been
fired. It's also used by phylib in conjunction with .config_intr() to
clear any pending interrupts after the line was disabled, and before
it is going to be enabled.

- .did_interrupt() - Intended for multi-PHY devices with a shared IRQ
line and used by phylib to discern which PHY from the package was the
one that actually fired the interrupt.

- .handle_interrupt() - Completely overrides the default interrupt
handling logic from phylib. The PHY driver is responsible for checking
if any interrupt was fired by the respective PHY and choose
accordingly if it's the one that should trigger the link state machine.

From my point of view, the interrupt handling in phylib has become
somewhat confusing with all these callbacks that actually read the same
PHY register - the interrupt status. A more streamlined approach would
be to just move the responsibility to write an interrupt handler to the
driver (as any other device driver does) and make .handle_interrupt()
the only way to deal with interrupts.

Another advantage with this approach would be that phylib would gain
support for shared IRQs between different PHY (not just multi-PHY
devices), something which at the moment would require extending every
PHY driver anyway in order to implement their .did_interrupt() callback
and duplicate the same logic as in .ack_interrupt(). The disadvantage
of making .did_interrupt() mandatory would be that we are slightly
changing the semantics of the phylib API and that would increase
confusion instead of reducing it.

What I am proposing is the following:

- As a first step, make the .ack_interrupt() callback optional so that
we do not break any PHY driver amid the transition.

- Every PHY driver gains a .handle_interrupt() implementation that, for
the most part, would look like below:

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

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

phy_trigger_machine(phydev);

return IRQ_HANDLED;

- Remove each PHY driver's implementation of the .ack_interrupt() by
actually taking care of quiescing any pending interrupts before
enabling/after disabling the interrupt line.

- Finally, after all drivers have been ported, remove the
.ack_interrupt() and .did_interrupt() callbacks from phy_driver.

This patch set is part 2 of the entire change set and it addresses the
changes needed in 9 PHY drivers. The rest can be found on my Github
branch here:
https://github.com/IoanaCiornei/linux/commits/phylib-shared-irq

I do not have access to most of these PHY's, therefore I Cc-ed the
latest contributors to the individual PHY drivers in order to have
access, hopefully, to more regression testing.

Ioana Ciornei (18):
net: phy: vitesse: implement generic .handle_interrupt() callback
net: phy: vitesse: remove the use of .ack_interrupt()
net: phy: microchip: implement generic .handle_interrupt() callback
net: phy: microchip: remove the use of .ack_interrupt()
net: phy: marvell: implement generic .handle_interrupt() callback
net: phy: marvell: remove the use of .ack_interrupt()
net: phy: lxt: implement generic .handle_interrupt() callback
net: phy: lxt: remove the use of .ack_interrupt()
net: phy: nxp-tja11xx: implement generic .handle_interrupt() callback
net: phy: nxp-tja11xx: remove the use of .ack_interrupt()
net: phy: amd: implement generic .handle_interrupt() callback
net: phy: amd: remove the use of .ack_interrupt()
net: phy: smsc: implement generic .handle_interrupt() callback
net: phy: smsc: remove the use of .ack_interrupt()
net: phy: ste10Xp: implement generic .handle_interrupt() callback
net: phy: ste10Xp: remove the use of .ack_interrupt()
net: phy: adin: implement generic .handle_interrupt() callback
net: phy: adin: remove the use of the .ack_interrupt()

drivers/net/phy/adin.c | 45 +++++++++++++---
drivers/net/phy/amd.c | 37 +++++++++++--
drivers/net/phy/lxt.c | 94 ++++++++++++++++++++++++++++++----
drivers/net/phy/marvell.c | 88 ++++++++++++++++---------------
drivers/net/phy/microchip.c | 24 +++++++--
drivers/net/phy/microchip_t1.c | 28 +++++++---
drivers/net/phy/nxp-tja11xx.c | 42 +++++++++++++--
drivers/net/phy/smsc.c | 55 ++++++++++++++++----
drivers/net/phy/ste10Xp.c | 53 +++++++++++++------
drivers/net/phy/vitesse.c | 61 ++++++++++++++--------
10 files changed, 405 insertions(+), 122 deletions(-)

Cc: Alexandru Ardelean <[email protected]>
Cc: Andre Edich <[email protected]>
Cc: Baruch Siach <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: Kavya Sree Kotagiri <[email protected]>
Cc: Linus Walleij <[email protected]>
Cc: Marco Felsch <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Maxim Kochetkov <[email protected]>
Cc: Nisar Sayed <[email protected]>
Cc: Oleksij Rempel <[email protected]>
Cc: Robert Hancock <[email protected]>
Cc: Yuiko Oshino <[email protected]>

--
2.28.0


2020-11-13 16:54:50

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 02/18] net: phy: vitesse: remove the use of .ack_interrupt()

From: Ioana Ciornei <[email protected]>

In preparation of removing the .ack_interrupt() callback, we must replace
its occurrences (aka phy_clear_interrupt), from the 2 places where it is
called from (phy_enable_interrupts and phy_disable_interrupts), with
equivalent functionality.

This means that clearing interrupts now becomes something that the PHY
driver is responsible of doing, before enabling interrupts and after
clearing them. Make this driver follow the new contract.

Cc: Kavya Sree Kotagiri <[email protected]>
Cc: Linus Walleij <[email protected]>
Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/vitesse.c | 24 +++---------------------
1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/drivers/net/phy/vitesse.c b/drivers/net/phy/vitesse.c
index 9f6cd6ec9747..16704e243162 100644
--- a/drivers/net/phy/vitesse.c
+++ b/drivers/net/phy/vitesse.c
@@ -275,25 +275,14 @@ static int vsc8601_config_init(struct phy_device *phydev)
return 0;
}

-static int vsc824x_ack_interrupt(struct phy_device *phydev)
-{
- int err = 0;
-
- /* Don't bother to ACK the interrupts if interrupts
- * are disabled. The 824x cannot clear the interrupts
- * if they are disabled.
- */
- if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
- err = phy_read(phydev, MII_VSC8244_ISTAT);
-
- return (err < 0) ? err : 0;
-}
-
static int vsc82xx_config_intr(struct phy_device *phydev)
{
int err;

if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
+ /* Don't bother to ACK the interrupts since the 824x cannot
+ * clear the interrupts if they are disabled.
+ */
err = phy_write(phydev, MII_VSC8244_IMASK,
(phydev->drv->phy_id == PHY_ID_VSC8234 ||
phydev->drv->phy_id == PHY_ID_VSC8244 ||
@@ -420,7 +409,6 @@ static struct phy_driver vsc82xx_driver[] = {
/* PHY_GBIT_FEATURES */
.config_init = &vsc824x_config_init,
.config_aneg = &vsc82x4_config_aneg,
- .ack_interrupt = &vsc824x_ack_interrupt,
.config_intr = &vsc82xx_config_intr,
.handle_interrupt = &vsc82xx_handle_interrupt,
}, {
@@ -430,7 +418,6 @@ static struct phy_driver vsc82xx_driver[] = {
/* PHY_GBIT_FEATURES */
.config_init = &vsc824x_config_init,
.config_aneg = &vsc82x4_config_aneg,
- .ack_interrupt = &vsc824x_ack_interrupt,
.config_intr = &vsc82xx_config_intr,
.handle_interrupt = &vsc82xx_handle_interrupt,
}, {
@@ -440,7 +427,6 @@ static struct phy_driver vsc82xx_driver[] = {
/* PHY_GBIT_FEATURES */
.config_init = &vsc824x_config_init,
.config_aneg = &vsc82x4_config_aneg,
- .ack_interrupt = &vsc824x_ack_interrupt,
.config_intr = &vsc82xx_config_intr,
.handle_interrupt = &vsc82xx_handle_interrupt,
}, {
@@ -449,7 +435,6 @@ static struct phy_driver vsc82xx_driver[] = {
.phy_id_mask = 0x000ffff0,
/* PHY_GBIT_FEATURES */
.config_init = &vsc8601_config_init,
- .ack_interrupt = &vsc824x_ack_interrupt,
.config_intr = &vsc82xx_config_intr,
.handle_interrupt = &vsc82xx_handle_interrupt,
}, {
@@ -495,7 +480,6 @@ static struct phy_driver vsc82xx_driver[] = {
/* PHY_GBIT_FEATURES */
.config_init = &vsc824x_config_init,
.config_aneg = &vsc82x4_config_aneg,
- .ack_interrupt = &vsc824x_ack_interrupt,
.config_intr = &vsc82xx_config_intr,
.handle_interrupt = &vsc82xx_handle_interrupt,
}, {
@@ -505,7 +489,6 @@ static struct phy_driver vsc82xx_driver[] = {
.name = "Vitesse VSC8221",
/* PHY_GBIT_FEATURES */
.config_init = &vsc8221_config_init,
- .ack_interrupt = &vsc824x_ack_interrupt,
.config_intr = &vsc82xx_config_intr,
.handle_interrupt = &vsc82xx_handle_interrupt,
}, {
@@ -515,7 +498,6 @@ static struct phy_driver vsc82xx_driver[] = {
.name = "Vitesse VSC8211",
/* PHY_GBIT_FEATURES */
.config_init = &vsc8221_config_init,
- .ack_interrupt = &vsc824x_ack_interrupt,
.config_intr = &vsc82xx_config_intr,
.handle_interrupt = &vsc82xx_handle_interrupt,
} };
--
2.28.0

2020-11-13 16:54:54

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 03/18] net: phy: microchip: implement generic .handle_interrupt() callback

From: Ioana Ciornei <[email protected]>

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: Nisar Sayed <[email protected]>
Cc: Yuiko Oshino <[email protected]>
Signed-off-by: Ioana Ciornei <[email protected]>
---
For the lan87xx_handle_interrupt() implementation, I do not know which
exact bits denote a link change status (since I do not have access to a
datasheet), so only in this driver's case, the phy state machine is
triggered if any bit is asserted in the Interrupt status register.

drivers/net/phy/microchip.c | 19 +++++++++++++++++++
drivers/net/phy/microchip_t1.c | 19 +++++++++++++++++++
2 files changed, 38 insertions(+)

diff --git a/drivers/net/phy/microchip.c b/drivers/net/phy/microchip.c
index a644e8e5071c..b472a2149f08 100644
--- a/drivers/net/phy/microchip.c
+++ b/drivers/net/phy/microchip.c
@@ -56,6 +56,24 @@ static int lan88xx_phy_ack_interrupt(struct phy_device *phydev)
return rc < 0 ? rc : 0;
}

+static irqreturn_t lan88xx_handle_interrupt(struct phy_device *phydev)
+{
+ int irq_status;
+
+ irq_status = phy_read(phydev, LAN88XX_INT_STS);
+ if (irq_status < 0) {
+ phy_error(phydev);
+ return IRQ_NONE;
+ }
+
+ if (!(irq_status & LAN88XX_INT_STS_LINK_CHANGE_))
+ return IRQ_NONE;
+
+ phy_trigger_machine(phydev);
+
+ return IRQ_HANDLED;
+}
+
static int lan88xx_suspend(struct phy_device *phydev)
{
struct lan88xx_priv *priv = phydev->priv;
@@ -342,6 +360,7 @@ static struct phy_driver microchip_phy_driver[] = {

.ack_interrupt = lan88xx_phy_ack_interrupt,
.config_intr = lan88xx_phy_config_intr,
+ .handle_interrupt = lan88xx_handle_interrupt,

.suspend = lan88xx_suspend,
.resume = genphy_resume,
diff --git a/drivers/net/phy/microchip_t1.c b/drivers/net/phy/microchip_t1.c
index 1c9900162619..04cda8865deb 100644
--- a/drivers/net/phy/microchip_t1.c
+++ b/drivers/net/phy/microchip_t1.c
@@ -203,6 +203,24 @@ static int lan87xx_phy_ack_interrupt(struct phy_device *phydev)
return rc < 0 ? rc : 0;
}

+static irqreturn_t lan87xx_handle_interrupt(struct phy_device *phydev)
+{
+ int irq_status;
+
+ irq_status = phy_read(phydev, LAN87XX_INTERRUPT_SOURCE);
+ if (irq_status < 0) {
+ phy_error(phydev);
+ return IRQ_NONE;
+ }
+
+ if (irq_status == 0)
+ return IRQ_NONE;
+
+ phy_trigger_machine(phydev);
+
+ return IRQ_HANDLED;
+}
+
static int lan87xx_config_init(struct phy_device *phydev)
{
int rc = lan87xx_phy_init(phydev);
@@ -222,6 +240,7 @@ static struct phy_driver microchip_t1_phy_driver[] = {

.ack_interrupt = lan87xx_phy_ack_interrupt,
.config_intr = lan87xx_phy_config_intr,
+ .handle_interrupt = lan87xx_handle_interrupt,

.suspend = genphy_suspend,
.resume = genphy_resume,
--
2.28.0

2020-11-13 16:55:02

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 07/18] net: phy: lxt: implement generic .handle_interrupt() callback

From: Ioana Ciornei <[email protected]>

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: Christophe Leroy <[email protected]>
Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/lxt.c | 50 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)

diff --git a/drivers/net/phy/lxt.c b/drivers/net/phy/lxt.c
index fec58ad69e02..716d9936bc90 100644
--- a/drivers/net/phy/lxt.c
+++ b/drivers/net/phy/lxt.c
@@ -37,6 +37,8 @@

#define MII_LXT970_ISR 18 /* Interrupt Status Register */

+#define MII_LXT970_IRS_MINT BIT(15)
+
#define MII_LXT970_CONFIG 19 /* Configuration Register */

/* ------------------------------------------------------------------------- */
@@ -47,6 +49,7 @@
#define MII_LXT971_IER_IEN 0x00f2

#define MII_LXT971_ISR 19 /* Interrupt Status Register */
+#define MII_LXT971_ISR_MASK 0x00f0

/* register definitions for the 973 */
#define MII_LXT973_PCR 16 /* Port Configuration Register */
@@ -81,6 +84,33 @@ static int lxt970_config_intr(struct phy_device *phydev)
return phy_write(phydev, MII_LXT970_IER, 0);
}

+static irqreturn_t lxt970_handle_interrupt(struct phy_device *phydev)
+{
+ int irq_status;
+
+ /* The interrupt status register is cleared by reading BMSR
+ * followed by MII_LXT970_ISR
+ */
+ irq_status = phy_read(phydev, MII_BMSR);
+ if (irq_status < 0) {
+ phy_error(phydev);
+ return IRQ_NONE;
+ }
+
+ irq_status = phy_read(phydev, MII_LXT970_ISR);
+ if (irq_status < 0) {
+ phy_error(phydev);
+ return IRQ_NONE;
+ }
+
+ if (!(irq_status & MII_LXT970_IRS_MINT))
+ return IRQ_NONE;
+
+ phy_trigger_machine(phydev);
+
+ return IRQ_HANDLED;
+}
+
static int lxt970_config_init(struct phy_device *phydev)
{
return phy_write(phydev, MII_LXT970_CONFIG, 0);
@@ -105,6 +135,24 @@ static int lxt971_config_intr(struct phy_device *phydev)
return phy_write(phydev, MII_LXT971_IER, 0);
}

+static irqreturn_t lxt971_handle_interrupt(struct phy_device *phydev)
+{
+ int irq_status;
+
+ irq_status = phy_read(phydev, MII_LXT971_ISR);
+ if (irq_status < 0) {
+ phy_error(phydev);
+ return IRQ_NONE;
+ }
+
+ if (!(irq_status & MII_LXT971_ISR_MASK))
+ return IRQ_NONE;
+
+ phy_trigger_machine(phydev);
+
+ return IRQ_HANDLED;
+}
+
/*
* A2 version of LXT973 chip has an ERRATA: it randomly return the contents
* of the previous even register when you read a odd register regularly
@@ -239,6 +287,7 @@ static struct phy_driver lxt97x_driver[] = {
.config_init = lxt970_config_init,
.ack_interrupt = lxt970_ack_interrupt,
.config_intr = lxt970_config_intr,
+ .handle_interrupt = lxt970_handle_interrupt,
}, {
.phy_id = 0x001378e0,
.name = "LXT971",
@@ -246,6 +295,7 @@ static struct phy_driver lxt97x_driver[] = {
/* PHY_BASIC_FEATURES */
.ack_interrupt = lxt971_ack_interrupt,
.config_intr = lxt971_config_intr,
+ .handle_interrupt = lxt971_handle_interrupt,
.suspend = genphy_suspend,
.resume = genphy_resume,
}, {
--
2.28.0

2020-11-13 16:55:08

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 10/18] net: phy: nxp-tja11xx: remove the use of .ack_interrupt()

From: Ioana Ciornei <[email protected]>

In preparation of removing the .ack_interrupt() callback, we must replace
its occurrences (aka phy_clear_interrupt), from the 2 places where it is
called from (phy_enable_interrupts and phy_disable_interrupts), with
equivalent functionality.

This means that clearing interrupts now becomes something that the PHY
driver is responsible of doing, before enabling interrupts and after
clearing them. Make this driver follow the new contract.

Cc: Marek Vasut <[email protected]>
Cc: Oleksij Rempel <[email protected]>
Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/nxp-tja11xx.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/drivers/net/phy/nxp-tja11xx.c b/drivers/net/phy/nxp-tja11xx.c
index 1c4c5c267fe6..afd7afa1f498 100644
--- a/drivers/net/phy/nxp-tja11xx.c
+++ b/drivers/net/phy/nxp-tja11xx.c
@@ -600,11 +600,24 @@ static int tja11xx_ack_interrupt(struct phy_device *phydev)
static int tja11xx_config_intr(struct phy_device *phydev)
{
int value = 0;
+ int err;
+
+ if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
+ err = tja11xx_ack_interrupt(phydev);
+ if (err)
+ return err;

- if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
value = MII_INTEN_LINK_FAIL | MII_INTEN_LINK_UP;
+ err = phy_write(phydev, MII_INTEN, value);
+ } else {
+ err = phy_write(phydev, MII_INTEN, value);
+ if (err)
+ return err;
+
+ err = tja11xx_ack_interrupt(phydev);
+ }

- return phy_write(phydev, MII_INTEN, value);
+ return err;
}

static irqreturn_t tja11xx_handle_interrupt(struct phy_device *phydev)
@@ -768,7 +781,6 @@ static struct phy_driver tja11xx_driver[] = {
.get_sset_count = tja11xx_get_sset_count,
.get_strings = tja11xx_get_strings,
.get_stats = tja11xx_get_stats,
- .ack_interrupt = tja11xx_ack_interrupt,
.config_intr = tja11xx_config_intr,
.handle_interrupt = tja11xx_handle_interrupt,
.cable_test_start = tja11xx_cable_test_start,
@@ -792,7 +804,6 @@ static struct phy_driver tja11xx_driver[] = {
.get_sset_count = tja11xx_get_sset_count,
.get_strings = tja11xx_get_strings,
.get_stats = tja11xx_get_stats,
- .ack_interrupt = tja11xx_ack_interrupt,
.config_intr = tja11xx_config_intr,
.handle_interrupt = tja11xx_handle_interrupt,
.cable_test_start = tja11xx_cable_test_start,
--
2.28.0

2020-11-13 16:55:22

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 12/18] net: phy: amd: remove the use of .ack_interrupt()

From: Ioana Ciornei <[email protected]>

In preparation of removing the .ack_interrupt() callback, we must replace
its occurrences (aka phy_clear_interrupt), from the 2 places where it is
called from (phy_enable_interrupts and phy_disable_interrupts), with
equivalent functionality.

This means that clearing interrupts now becomes something that the PHY
driver is responsible of doing, before enabling interrupts and after
clearing them. Make this driver follow the new contract.

Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/amd.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/net/phy/amd.c b/drivers/net/phy/amd.c
index ae75d95c398c..001bb6d8bfce 100644
--- a/drivers/net/phy/amd.c
+++ b/drivers/net/phy/amd.c
@@ -52,10 +52,19 @@ static int am79c_config_intr(struct phy_device *phydev)
{
int err;

- if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
+ if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
+ err = am79c_ack_interrupt(phydev);
+ if (err)
+ return err;
+
err = phy_write(phydev, MII_AM79C_IR, MII_AM79C_IR_IMASK_INIT);
- else
+ } else {
err = phy_write(phydev, MII_AM79C_IR, 0);
+ if (err)
+ return err;
+
+ err = am79c_ack_interrupt(phydev);
+ }

return err;
}
@@ -84,7 +93,6 @@ static struct phy_driver am79c_driver[] = { {
.phy_id_mask = 0xfffffff0,
/* PHY_BASIC_FEATURES */
.config_init = am79c_config_init,
- .ack_interrupt = am79c_ack_interrupt,
.config_intr = am79c_config_intr,
.handle_interrupt = am79c_handle_interrupt,
} };
--
2.28.0

2020-11-13 16:55:31

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 17/18] net: phy: adin: implement generic .handle_interrupt() callback

From: Ioana Ciornei <[email protected]>

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: Alexandru Ardelean <[email protected]>
Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/adin.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/drivers/net/phy/adin.c b/drivers/net/phy/adin.c
index 3727b38addf7..ba24434b867d 100644
--- a/drivers/net/phy/adin.c
+++ b/drivers/net/phy/adin.c
@@ -479,6 +479,24 @@ static int adin_phy_config_intr(struct phy_device *phydev)
ADIN1300_INT_MASK_EN);
}

+static irqreturn_t adin_phy_handle_interrupt(struct phy_device *phydev)
+{
+ int irq_status;
+
+ irq_status = phy_read(phydev, ADIN1300_INT_STATUS_REG);
+ if (irq_status < 0) {
+ phy_error(phydev);
+ return IRQ_NONE;
+ }
+
+ if (!(irq_status & ADIN1300_INT_LINK_STAT_CHNG_EN))
+ return IRQ_NONE;
+
+ phy_trigger_machine(phydev);
+
+ return IRQ_HANDLED;
+}
+
static int adin_cl45_to_adin_reg(struct phy_device *phydev, int devad,
u16 cl45_regnum)
{
@@ -879,6 +897,7 @@ static struct phy_driver adin_driver[] = {
.set_tunable = adin_set_tunable,
.ack_interrupt = adin_phy_ack_intr,
.config_intr = adin_phy_config_intr,
+ .handle_interrupt = adin_phy_handle_interrupt,
.get_sset_count = adin_get_sset_count,
.get_strings = adin_get_strings,
.get_stats = adin_get_stats,
@@ -902,6 +921,7 @@ static struct phy_driver adin_driver[] = {
.set_tunable = adin_set_tunable,
.ack_interrupt = adin_phy_ack_intr,
.config_intr = adin_phy_config_intr,
+ .handle_interrupt = adin_phy_handle_interrupt,
.get_sset_count = adin_get_sset_count,
.get_strings = adin_get_strings,
.get_stats = adin_get_stats,
--
2.28.0

2020-11-13 16:55:33

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 15/18] net: phy: ste10Xp: implement generic .handle_interrupt() callback

From: Ioana Ciornei <[email protected]>

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.

Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/ste10Xp.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/drivers/net/phy/ste10Xp.c b/drivers/net/phy/ste10Xp.c
index d735a01380ed..9f315332e0f2 100644
--- a/drivers/net/phy/ste10Xp.c
+++ b/drivers/net/phy/ste10Xp.c
@@ -76,6 +76,24 @@ static int ste10Xp_ack_interrupt(struct phy_device *phydev)
return 0;
}

+static irqreturn_t ste10Xp_handle_interrupt(struct phy_device *phydev)
+{
+ int irq_status;
+
+ irq_status = phy_read(phydev, MII_XCIIS);
+ if (irq_status < 0) {
+ phy_error(phydev);
+ return IRQ_NONE;
+ }
+
+ if (!(irq_status & MII_XIE_DEFAULT_MASK))
+ return IRQ_NONE;
+
+ phy_trigger_machine(phydev);
+
+ return IRQ_HANDLED;
+}
+
static struct phy_driver ste10xp_pdriver[] = {
{
.phy_id = STE101P_PHY_ID,
@@ -85,6 +103,7 @@ static struct phy_driver ste10xp_pdriver[] = {
.config_init = ste10Xp_config_init,
.ack_interrupt = ste10Xp_ack_interrupt,
.config_intr = ste10Xp_config_intr,
+ .handle_interrupt = ste10Xp_handle_interrupt,
.suspend = genphy_suspend,
.resume = genphy_resume,
}, {
@@ -95,6 +114,7 @@ static struct phy_driver ste10xp_pdriver[] = {
.config_init = ste10Xp_config_init,
.ack_interrupt = ste10Xp_ack_interrupt,
.config_intr = ste10Xp_config_intr,
+ .handle_interrupt = ste10Xp_handle_interrupt,
.suspend = genphy_suspend,
.resume = genphy_resume,
} };
--
2.28.0

2020-11-13 16:55:48

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 18/18] net: phy: adin: remove the use of the .ack_interrupt()

From: Ioana Ciornei <[email protected]>

In preparation of removing the .ack_interrupt() callback, we must replace
its occurrences (aka phy_clear_interrupt), from the 2 places where it is
called from (phy_enable_interrupts and phy_disable_interrupts), with
equivalent functionality.

This means that clearing interrupts now becomes something that the PHY
driver is responsible of doing, before enabling interrupts and after
clearing them. Make this driver follow the new contract.

Cc: Alexandru Ardelean <[email protected]>
Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/adin.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/net/phy/adin.c b/drivers/net/phy/adin.c
index ba24434b867d..55a0b91816e2 100644
--- a/drivers/net/phy/adin.c
+++ b/drivers/net/phy/adin.c
@@ -471,12 +471,25 @@ static int adin_phy_ack_intr(struct phy_device *phydev)

static int adin_phy_config_intr(struct phy_device *phydev)
{
- if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
- return phy_set_bits(phydev, ADIN1300_INT_MASK_REG,
- ADIN1300_INT_MASK_EN);
+ int err;
+
+ if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
+ err = adin_phy_ack_intr(phydev);
+ if (err)
+ return err;
+
+ err = phy_set_bits(phydev, ADIN1300_INT_MASK_REG,
+ ADIN1300_INT_MASK_EN);
+ } else {
+ err = phy_clear_bits(phydev, ADIN1300_INT_MASK_REG,
+ ADIN1300_INT_MASK_EN);
+ if (err)
+ return err;
+
+ err = adin_phy_ack_intr(phydev);
+ }

- return phy_clear_bits(phydev, ADIN1300_INT_MASK_REG,
- ADIN1300_INT_MASK_EN);
+ return err;
}

static irqreturn_t adin_phy_handle_interrupt(struct phy_device *phydev)
@@ -895,7 +908,6 @@ static struct phy_driver adin_driver[] = {
.read_status = adin_read_status,
.get_tunable = adin_get_tunable,
.set_tunable = adin_set_tunable,
- .ack_interrupt = adin_phy_ack_intr,
.config_intr = adin_phy_config_intr,
.handle_interrupt = adin_phy_handle_interrupt,
.get_sset_count = adin_get_sset_count,
@@ -919,7 +931,6 @@ static struct phy_driver adin_driver[] = {
.read_status = adin_read_status,
.get_tunable = adin_get_tunable,
.set_tunable = adin_set_tunable,
- .ack_interrupt = adin_phy_ack_intr,
.config_intr = adin_phy_config_intr,
.handle_interrupt = adin_phy_handle_interrupt,
.get_sset_count = adin_get_sset_count,
--
2.28.0

2020-11-13 16:56:00

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 14/18] net: phy: smsc: remove the use of .ack_interrupt()

From: Ioana Ciornei <[email protected]>

In preparation of removing the .ack_interrupt() callback, we must replace
its occurrences (aka phy_clear_interrupt), from the 2 places where it is
called from (phy_enable_interrupts and phy_disable_interrupts), with
equivalent functionality.

This means that clearing interrupts now becomes something that the PHY
driver is responsible of doing, before enabling interrupts and after
clearing them. Make this driver follow the new contract.

Cc: Andre Edich <[email protected]>
Cc: Marco Felsch <[email protected]>
Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/smsc.c | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
index 8d9eb1b3d2df..bc05a4a9d10a 100644
--- a/drivers/net/phy/smsc.c
+++ b/drivers/net/phy/smsc.c
@@ -48,6 +48,13 @@ struct smsc_phy_priv {
struct clk *refclk;
};

+static int smsc_phy_ack_interrupt(struct phy_device *phydev)
+{
+ int rc = phy_read(phydev, MII_LAN83C185_ISF);
+
+ return rc < 0 ? rc : 0;
+}
+
static int smsc_phy_config_intr(struct phy_device *phydev)
{
struct smsc_phy_priv *priv = phydev->priv;
@@ -55,19 +62,21 @@ static int smsc_phy_config_intr(struct phy_device *phydev)
int rc;

if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
+ rc = smsc_phy_ack_interrupt(phydev);
+ if (rc)
+ return rc;
+
intmask = MII_LAN83C185_ISF_INT4 | MII_LAN83C185_ISF_INT6;
if (priv->energy_enable)
intmask |= MII_LAN83C185_ISF_INT7;
- }
-
- rc = phy_write(phydev, MII_LAN83C185_IM, intmask);
-
- return rc < 0 ? rc : 0;
-}
+ rc = phy_write(phydev, MII_LAN83C185_IM, intmask);
+ } else {
+ rc = phy_write(phydev, MII_LAN83C185_IM, intmask);
+ if (rc)
+ return rc;

-static int smsc_phy_ack_interrupt(struct phy_device *phydev)
-{
- int rc = phy_read (phydev, MII_LAN83C185_ISF);
+ rc = smsc_phy_ack_interrupt(phydev);
+ }

return rc < 0 ? rc : 0;
}
@@ -336,7 +345,6 @@ static struct phy_driver smsc_phy_driver[] = {
.soft_reset = smsc_phy_reset,

/* IRQ related */
- .ack_interrupt = smsc_phy_ack_interrupt,
.config_intr = smsc_phy_config_intr,
.handle_interrupt = smsc_phy_handle_interrupt,

@@ -356,7 +364,6 @@ static struct phy_driver smsc_phy_driver[] = {
.soft_reset = smsc_phy_reset,

/* IRQ related */
- .ack_interrupt = smsc_phy_ack_interrupt,
.config_intr = smsc_phy_config_intr,
.handle_interrupt = smsc_phy_handle_interrupt,

@@ -386,7 +393,6 @@ static struct phy_driver smsc_phy_driver[] = {
.config_aneg = lan87xx_config_aneg,

/* IRQ related */
- .ack_interrupt = smsc_phy_ack_interrupt,
.config_intr = smsc_phy_config_intr,
.handle_interrupt = smsc_phy_handle_interrupt,

@@ -410,7 +416,6 @@ static struct phy_driver smsc_phy_driver[] = {
.config_init = lan911x_config_init,

/* IRQ related */
- .ack_interrupt = smsc_phy_ack_interrupt,
.config_intr = smsc_phy_config_intr,
.handle_interrupt = smsc_phy_handle_interrupt,

@@ -436,7 +441,6 @@ static struct phy_driver smsc_phy_driver[] = {
.config_aneg = lan87xx_config_aneg_ext,

/* IRQ related */
- .ack_interrupt = smsc_phy_ack_interrupt,
.config_intr = smsc_phy_config_intr,
.handle_interrupt = smsc_phy_handle_interrupt,

@@ -463,7 +467,6 @@ static struct phy_driver smsc_phy_driver[] = {
.soft_reset = smsc_phy_reset,

/* IRQ related */
- .ack_interrupt = smsc_phy_ack_interrupt,
.config_intr = smsc_phy_config_intr,
.handle_interrupt = smsc_phy_handle_interrupt,

--
2.28.0

2020-11-13 16:56:28

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 09/18] net: phy: nxp-tja11xx: implement generic .handle_interrupt() callback

From: Ioana Ciornei <[email protected]>

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: Marek Vasut <[email protected]>
Cc: Oleksij Rempel <[email protected]>
Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/nxp-tja11xx.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)

diff --git a/drivers/net/phy/nxp-tja11xx.c b/drivers/net/phy/nxp-tja11xx.c
index a72fa0d2e7c7..1c4c5c267fe6 100644
--- a/drivers/net/phy/nxp-tja11xx.c
+++ b/drivers/net/phy/nxp-tja11xx.c
@@ -44,6 +44,9 @@
#define MII_CFG2_SLEEP_REQUEST_TO_16MS 0x3

#define MII_INTSRC 21
+#define MII_INTSRC_LINK_FAIL BIT(10)
+#define MII_INTSRC_LINK_UP BIT(9)
+#define MII_INTSRC_MASK (MII_INTSRC_LINK_FAIL | MII_INTSRC_LINK_UP)
#define MII_INTSRC_TEMP_ERR BIT(1)
#define MII_INTSRC_UV_ERR BIT(3)

@@ -604,6 +607,24 @@ static int tja11xx_config_intr(struct phy_device *phydev)
return phy_write(phydev, MII_INTEN, value);
}

+static irqreturn_t tja11xx_handle_interrupt(struct phy_device *phydev)
+{
+ int irq_status;
+
+ irq_status = phy_read(phydev, MII_INTSRC);
+ if (irq_status < 0) {
+ phy_error(phydev);
+ return IRQ_NONE;
+ }
+
+ if (!(irq_status & MII_INTSRC_MASK))
+ return IRQ_NONE;
+
+ phy_trigger_machine(phydev);
+
+ return IRQ_HANDLED;
+}
+
static int tja11xx_cable_test_start(struct phy_device *phydev)
{
int ret;
@@ -749,6 +770,7 @@ static struct phy_driver tja11xx_driver[] = {
.get_stats = tja11xx_get_stats,
.ack_interrupt = tja11xx_ack_interrupt,
.config_intr = tja11xx_config_intr,
+ .handle_interrupt = tja11xx_handle_interrupt,
.cable_test_start = tja11xx_cable_test_start,
.cable_test_get_status = tja11xx_cable_test_get_status,
}, {
@@ -772,6 +794,7 @@ static struct phy_driver tja11xx_driver[] = {
.get_stats = tja11xx_get_stats,
.ack_interrupt = tja11xx_ack_interrupt,
.config_intr = tja11xx_config_intr,
+ .handle_interrupt = tja11xx_handle_interrupt,
.cable_test_start = tja11xx_cable_test_start,
.cable_test_get_status = tja11xx_cable_test_get_status,
}
--
2.28.0

2020-11-13 16:56:36

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 05/18] net: phy: marvell: implement generic .handle_interrupt() callback

From: Ioana Ciornei <[email protected]>

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: Maxim Kochetkov <[email protected]>
Cc: Baruch Siach <[email protected]>
Cc: Robert Hancock <[email protected]>
Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/marvell.c | 57 ++++++++++++++++++++++++---------------
1 file changed, 36 insertions(+), 21 deletions(-)

diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index 2563526bf4a6..bb843b960436 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -327,6 +327,24 @@ static int marvell_config_intr(struct phy_device *phydev)
return err;
}

+static irqreturn_t marvell_handle_interrupt(struct phy_device *phydev)
+{
+ int irq_status;
+
+ irq_status = phy_read(phydev, MII_M1011_IEVENT);
+ if (irq_status < 0) {
+ phy_error(phydev);
+ return IRQ_NONE;
+ }
+
+ if (!(irq_status & MII_M1011_IMASK_INIT))
+ return IRQ_NONE;
+
+ phy_trigger_machine(phydev);
+
+ return IRQ_HANDLED;
+}
+
static int marvell_set_polarity(struct phy_device *phydev, int polarity)
{
int reg;
@@ -1659,18 +1677,6 @@ static int marvell_aneg_done(struct phy_device *phydev)
return (retval < 0) ? retval : (retval & MII_M1011_PHY_STATUS_RESOLVED);
}

-static int m88e1121_did_interrupt(struct phy_device *phydev)
-{
- int imask;
-
- imask = phy_read(phydev, MII_M1011_IEVENT);
-
- if (imask & MII_M1011_IMASK_INIT)
- return 1;
-
- return 0;
-}
-
static void m88e1318_get_wol(struct phy_device *phydev,
struct ethtool_wolinfo *wol)
{
@@ -2699,6 +2705,7 @@ static struct phy_driver marvell_drivers[] = {
.config_aneg = m88e1101_config_aneg,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
+ .handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
.suspend = genphy_suspend,
.read_page = marvell_read_page,
@@ -2717,6 +2724,7 @@ static struct phy_driver marvell_drivers[] = {
.config_aneg = marvell_config_aneg,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
+ .handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
.suspend = genphy_suspend,
.read_page = marvell_read_page,
@@ -2738,6 +2746,7 @@ static struct phy_driver marvell_drivers[] = {
.read_status = marvell_read_status,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
+ .handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
.suspend = genphy_suspend,
.read_page = marvell_read_page,
@@ -2759,6 +2768,7 @@ static struct phy_driver marvell_drivers[] = {
.read_status = marvell_read_status,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
+ .handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
.suspend = genphy_suspend,
.read_page = marvell_read_page,
@@ -2779,6 +2789,7 @@ static struct phy_driver marvell_drivers[] = {
.config_aneg = m88e1118_config_aneg,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
+ .handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
.suspend = genphy_suspend,
.read_page = marvell_read_page,
@@ -2798,7 +2809,7 @@ static struct phy_driver marvell_drivers[] = {
.read_status = marvell_read_status,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
- .did_interrupt = m88e1121_did_interrupt,
+ .handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
.suspend = genphy_suspend,
.read_page = marvell_read_page,
@@ -2820,7 +2831,7 @@ static struct phy_driver marvell_drivers[] = {
.read_status = marvell_read_status,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
- .did_interrupt = m88e1121_did_interrupt,
+ .handle_interrupt = marvell_handle_interrupt,
.get_wol = m88e1318_get_wol,
.set_wol = m88e1318_set_wol,
.resume = genphy_resume,
@@ -2842,6 +2853,7 @@ static struct phy_driver marvell_drivers[] = {
.read_status = genphy_read_status,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
+ .handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
.suspend = genphy_suspend,
.read_page = marvell_read_page,
@@ -2862,6 +2874,7 @@ static struct phy_driver marvell_drivers[] = {
.config_aneg = m88e1118_config_aneg,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
+ .handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
.suspend = genphy_suspend,
.read_page = marvell_read_page,
@@ -2880,6 +2893,7 @@ static struct phy_driver marvell_drivers[] = {
.config_aneg = marvell_config_aneg,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
+ .handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
.suspend = genphy_suspend,
.read_page = marvell_read_page,
@@ -2897,6 +2911,7 @@ static struct phy_driver marvell_drivers[] = {
.config_init = m88e1116r_config_init,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
+ .handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
.suspend = genphy_suspend,
.read_page = marvell_read_page,
@@ -2919,7 +2934,7 @@ static struct phy_driver marvell_drivers[] = {
.read_status = marvell_read_status,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
- .did_interrupt = m88e1121_did_interrupt,
+ .handle_interrupt = marvell_handle_interrupt,
.get_wol = m88e1318_get_wol,
.set_wol = m88e1318_set_wol,
.resume = marvell_resume,
@@ -2948,7 +2963,7 @@ static struct phy_driver marvell_drivers[] = {
.read_status = marvell_read_status,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
- .did_interrupt = m88e1121_did_interrupt,
+ .handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
.suspend = genphy_suspend,
.read_page = marvell_read_page,
@@ -2974,7 +2989,7 @@ static struct phy_driver marvell_drivers[] = {
.read_status = marvell_read_status,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
- .did_interrupt = m88e1121_did_interrupt,
+ .handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
.suspend = genphy_suspend,
.read_page = marvell_read_page,
@@ -2999,7 +3014,7 @@ static struct phy_driver marvell_drivers[] = {
.read_status = marvell_read_status,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
- .did_interrupt = m88e1121_did_interrupt,
+ .handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
.suspend = genphy_suspend,
.read_page = marvell_read_page,
@@ -3020,7 +3035,7 @@ static struct phy_driver marvell_drivers[] = {
.read_status = marvell_read_status,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
- .did_interrupt = m88e1121_did_interrupt,
+ .handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
.suspend = genphy_suspend,
.read_page = marvell_read_page,
@@ -3045,7 +3060,7 @@ static struct phy_driver marvell_drivers[] = {
.read_status = marvell_read_status,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
- .did_interrupt = m88e1121_did_interrupt,
+ .handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
.suspend = genphy_suspend,
.read_page = marvell_read_page,
@@ -3067,7 +3082,7 @@ static struct phy_driver marvell_drivers[] = {
.read_status = marvell_read_status,
.ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
- .did_interrupt = m88e1121_did_interrupt,
+ .handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
.suspend = genphy_suspend,
.read_page = marvell_read_page,
--
2.28.0

2020-11-13 16:56:54

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 11/18] net: phy: amd: implement generic .handle_interrupt() callback

From: Ioana Ciornei <[email protected]>

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.

Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/amd.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)

diff --git a/drivers/net/phy/amd.c b/drivers/net/phy/amd.c
index eef35f8c8d45..ae75d95c398c 100644
--- a/drivers/net/phy/amd.c
+++ b/drivers/net/phy/amd.c
@@ -20,6 +20,10 @@
#define MII_AM79C_IR_EN_ANEG 0x0100 /* IR enable Aneg Complete */
#define MII_AM79C_IR_IMASK_INIT (MII_AM79C_IR_EN_LINK | MII_AM79C_IR_EN_ANEG)

+#define MII_AM79C_IR_LINK_DOWN BIT(2)
+#define MII_AM79C_IR_ANEG_DONE BIT(0)
+#define MII_AM79C_IR_IMASK_STAT (MII_AM79C_IR_LINK_DOWN | MII_AM79C_IR_ANEG_DONE)
+
MODULE_DESCRIPTION("AMD PHY driver");
MODULE_AUTHOR("Heiko Schocher <[email protected]>");
MODULE_LICENSE("GPL");
@@ -56,6 +60,24 @@ static int am79c_config_intr(struct phy_device *phydev)
return err;
}

+static irqreturn_t am79c_handle_interrupt(struct phy_device *phydev)
+{
+ int irq_status;
+
+ irq_status = phy_read(phydev, MII_AM79C_IR);
+ if (irq_status < 0) {
+ phy_error(phydev);
+ return IRQ_NONE;
+ }
+
+ if (!(irq_status & MII_AM79C_IR_IMASK_STAT))
+ return IRQ_NONE;
+
+ phy_trigger_machine(phydev);
+
+ return IRQ_HANDLED;
+}
+
static struct phy_driver am79c_driver[] = { {
.phy_id = PHY_ID_AM79C874,
.name = "AM79C874",
@@ -64,6 +86,7 @@ static struct phy_driver am79c_driver[] = { {
.config_init = am79c_config_init,
.ack_interrupt = am79c_ack_interrupt,
.config_intr = am79c_config_intr,
+ .handle_interrupt = am79c_handle_interrupt,
} };

module_phy_driver(am79c_driver);
--
2.28.0

2020-11-13 16:56:58

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 06/18] net: phy: marvell: remove the use of .ack_interrupt()

From: Ioana Ciornei <[email protected]>

In preparation of removing the .ack_interrupt() callback, we must replace
its occurrences (aka phy_clear_interrupt), from the 2 places where it is
called from (phy_enable_interrupts and phy_disable_interrupts), with
equivalent functionality.

This means that clearing interrupts now becomes something that the PHY
driver is responsible of doing, before enabling interrupts and after
clearing them. Make this driver follow the new contract.

Cc: Maxim Kochetkov <[email protected]>
Cc: Baruch Siach <[email protected]>
Cc: Robert Hancock <[email protected]>
Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/marvell.c | 31 +++++++++++--------------------
1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index bb843b960436..587930a7f48b 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -317,12 +317,21 @@ static int marvell_config_intr(struct phy_device *phydev)
{
int err;

- if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
+ if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
+ err = marvell_ack_interrupt(phydev);
+ if (err)
+ return err;
+
err = phy_write(phydev, MII_M1011_IMASK,
MII_M1011_IMASK_INIT);
- else
+ } else {
err = phy_write(phydev, MII_M1011_IMASK,
MII_M1011_IMASK_CLEAR);
+ if (err)
+ return err;
+
+ err = marvell_ack_interrupt(phydev);
+ }

return err;
}
@@ -2703,7 +2712,6 @@ static struct phy_driver marvell_drivers[] = {
.probe = marvell_probe,
.config_init = marvell_config_init,
.config_aneg = m88e1101_config_aneg,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
@@ -2722,7 +2730,6 @@ static struct phy_driver marvell_drivers[] = {
.probe = marvell_probe,
.config_init = m88e1111_config_init,
.config_aneg = marvell_config_aneg,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
@@ -2744,7 +2751,6 @@ static struct phy_driver marvell_drivers[] = {
.config_init = m88e1111_config_init,
.config_aneg = m88e1111_config_aneg,
.read_status = marvell_read_status,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
@@ -2766,7 +2772,6 @@ static struct phy_driver marvell_drivers[] = {
.config_init = m88e1111_config_init,
.config_aneg = m88e1111_config_aneg,
.read_status = marvell_read_status,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
@@ -2787,7 +2792,6 @@ static struct phy_driver marvell_drivers[] = {
.probe = marvell_probe,
.config_init = m88e1118_config_init,
.config_aneg = m88e1118_config_aneg,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
@@ -2807,7 +2811,6 @@ static struct phy_driver marvell_drivers[] = {
.config_init = marvell_config_init,
.config_aneg = m88e1121_config_aneg,
.read_status = marvell_read_status,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
@@ -2829,7 +2832,6 @@ static struct phy_driver marvell_drivers[] = {
.config_init = m88e1318_config_init,
.config_aneg = m88e1318_config_aneg,
.read_status = marvell_read_status,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.get_wol = m88e1318_get_wol,
@@ -2851,7 +2853,6 @@ static struct phy_driver marvell_drivers[] = {
.config_init = m88e1145_config_init,
.config_aneg = m88e1101_config_aneg,
.read_status = genphy_read_status,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
@@ -2872,7 +2873,6 @@ static struct phy_driver marvell_drivers[] = {
.probe = marvell_probe,
.config_init = m88e1149_config_init,
.config_aneg = m88e1118_config_aneg,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
@@ -2891,7 +2891,6 @@ static struct phy_driver marvell_drivers[] = {
.probe = marvell_probe,
.config_init = m88e1111_config_init,
.config_aneg = marvell_config_aneg,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
@@ -2909,7 +2908,6 @@ static struct phy_driver marvell_drivers[] = {
/* PHY_GBIT_FEATURES */
.probe = marvell_probe,
.config_init = m88e1116r_config_init,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
@@ -2932,7 +2930,6 @@ static struct phy_driver marvell_drivers[] = {
.config_init = m88e1510_config_init,
.config_aneg = m88e1510_config_aneg,
.read_status = marvell_read_status,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.get_wol = m88e1318_get_wol,
@@ -2961,7 +2958,6 @@ static struct phy_driver marvell_drivers[] = {
.config_init = marvell_config_init,
.config_aneg = m88e1510_config_aneg,
.read_status = marvell_read_status,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
@@ -2987,7 +2983,6 @@ static struct phy_driver marvell_drivers[] = {
.config_init = marvell_config_init,
.config_aneg = m88e1510_config_aneg,
.read_status = marvell_read_status,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
@@ -3012,7 +3007,6 @@ static struct phy_driver marvell_drivers[] = {
.config_init = m88e3016_config_init,
.aneg_done = marvell_aneg_done,
.read_status = marvell_read_status,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
@@ -3033,7 +3027,6 @@ static struct phy_driver marvell_drivers[] = {
.config_init = marvell_config_init,
.config_aneg = m88e6390_config_aneg,
.read_status = marvell_read_status,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
@@ -3058,7 +3051,6 @@ static struct phy_driver marvell_drivers[] = {
.config_init = marvell_config_init,
.config_aneg = m88e1510_config_aneg,
.read_status = marvell_read_status,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
@@ -3080,7 +3072,6 @@ static struct phy_driver marvell_drivers[] = {
.config_init = marvell_config_init,
.config_aneg = m88e1510_config_aneg,
.read_status = marvell_read_status,
- .ack_interrupt = marvell_ack_interrupt,
.config_intr = marvell_config_intr,
.handle_interrupt = marvell_handle_interrupt,
.resume = genphy_resume,
--
2.28.0

2020-11-13 16:57:41

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 16/18] net: phy: ste10Xp: remove the use of .ack_interrupt()

From: Ioana Ciornei <[email protected]>

In preparation of removing the .ack_interrupt() callback, we must replace
its occurrences (aka phy_clear_interrupt), from the 2 places where it is
called from (phy_enable_interrupts and phy_disable_interrupts), with
equivalent functionality.

This means that clearing interrupts now becomes something that the PHY
driver is responsible of doing, before enabling interrupts and after
clearing them. Make this driver follow the new contract.

Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/ste10Xp.c | 41 +++++++++++++++++++++------------------
1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/drivers/net/phy/ste10Xp.c b/drivers/net/phy/ste10Xp.c
index 9f315332e0f2..431fe5e0ce31 100644
--- a/drivers/net/phy/ste10Xp.c
+++ b/drivers/net/phy/ste10Xp.c
@@ -48,32 +48,37 @@ static int ste10Xp_config_init(struct phy_device *phydev)
return 0;
}

+static int ste10Xp_ack_interrupt(struct phy_device *phydev)
+{
+ int err = phy_read(phydev, MII_XCIIS);
+
+ if (err < 0)
+ return err;
+
+ return 0;
+}
+
static int ste10Xp_config_intr(struct phy_device *phydev)
{
- int err, value;
+ int err;

if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
+ /* clear any pending interrupts */
+ err = ste10Xp_ack_interrupt(phydev);
+ if (err)
+ return err;
+
/* Enable all STe101P interrupts (PR12) */
err = phy_write(phydev, MII_XIE, MII_XIE_DEFAULT_MASK);
- /* clear any pending interrupts */
- if (err == 0) {
- value = phy_read(phydev, MII_XCIIS);
- if (value < 0)
- err = value;
- }
- } else
+ } else {
err = phy_write(phydev, MII_XIE, 0);
+ if (err)
+ return err;

- return err;
-}
-
-static int ste10Xp_ack_interrupt(struct phy_device *phydev)
-{
- int err = phy_read(phydev, MII_XCIIS);
- if (err < 0)
- return err;
+ err = ste10Xp_ack_interrupt(phydev);
+ }

- return 0;
+ return err;
}

static irqreturn_t ste10Xp_handle_interrupt(struct phy_device *phydev)
@@ -101,7 +106,6 @@ static struct phy_driver ste10xp_pdriver[] = {
.name = "STe101p",
/* PHY_BASIC_FEATURES */
.config_init = ste10Xp_config_init,
- .ack_interrupt = ste10Xp_ack_interrupt,
.config_intr = ste10Xp_config_intr,
.handle_interrupt = ste10Xp_handle_interrupt,
.suspend = genphy_suspend,
@@ -112,7 +116,6 @@ static struct phy_driver ste10xp_pdriver[] = {
.name = "STe100p",
/* PHY_BASIC_FEATURES */
.config_init = ste10Xp_config_init,
- .ack_interrupt = ste10Xp_ack_interrupt,
.config_intr = ste10Xp_config_intr,
.handle_interrupt = ste10Xp_handle_interrupt,
.suspend = genphy_suspend,
--
2.28.0

2020-11-13 16:58:05

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 13/18] net: phy: smsc: implement generic .handle_interrupt() callback

From: Ioana Ciornei <[email protected]>

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: Andre Edich <[email protected]>
Cc: Marco Felsch <[email protected]>
Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/smsc.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)

diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
index ec97669be5c2..8d9eb1b3d2df 100644
--- a/drivers/net/phy/smsc.c
+++ b/drivers/net/phy/smsc.c
@@ -72,6 +72,30 @@ static int smsc_phy_ack_interrupt(struct phy_device *phydev)
return rc < 0 ? rc : 0;
}

+static irqreturn_t smsc_phy_handle_interrupt(struct phy_device *phydev)
+{
+ int irq_status, irq_enabled;
+
+ irq_enabled = phy_read(phydev, MII_LAN83C185_IM);
+ if (irq_enabled < 0) {
+ phy_error(phydev);
+ return IRQ_NONE;
+ }
+
+ irq_status = phy_read(phydev, MII_LAN83C185_ISF);
+ if (irq_status < 0) {
+ phy_error(phydev);
+ return IRQ_NONE;
+ }
+
+ if (!(irq_status & irq_enabled))
+ return IRQ_NONE;
+
+ phy_trigger_machine(phydev);
+
+ return IRQ_HANDLED;
+}
+
static int smsc_phy_config_init(struct phy_device *phydev)
{
struct smsc_phy_priv *priv = phydev->priv;
@@ -314,6 +338,7 @@ static struct phy_driver smsc_phy_driver[] = {
/* IRQ related */
.ack_interrupt = smsc_phy_ack_interrupt,
.config_intr = smsc_phy_config_intr,
+ .handle_interrupt = smsc_phy_handle_interrupt,

.suspend = genphy_suspend,
.resume = genphy_resume,
@@ -333,6 +358,7 @@ static struct phy_driver smsc_phy_driver[] = {
/* IRQ related */
.ack_interrupt = smsc_phy_ack_interrupt,
.config_intr = smsc_phy_config_intr,
+ .handle_interrupt = smsc_phy_handle_interrupt,

/* Statistics */
.get_sset_count = smsc_get_sset_count,
@@ -362,6 +388,7 @@ static struct phy_driver smsc_phy_driver[] = {
/* IRQ related */
.ack_interrupt = smsc_phy_ack_interrupt,
.config_intr = smsc_phy_config_intr,
+ .handle_interrupt = smsc_phy_handle_interrupt,

/* Statistics */
.get_sset_count = smsc_get_sset_count,
@@ -385,6 +412,7 @@ static struct phy_driver smsc_phy_driver[] = {
/* IRQ related */
.ack_interrupt = smsc_phy_ack_interrupt,
.config_intr = smsc_phy_config_intr,
+ .handle_interrupt = smsc_phy_handle_interrupt,

.suspend = genphy_suspend,
.resume = genphy_resume,
@@ -410,6 +438,7 @@ static struct phy_driver smsc_phy_driver[] = {
/* IRQ related */
.ack_interrupt = smsc_phy_ack_interrupt,
.config_intr = smsc_phy_config_intr,
+ .handle_interrupt = smsc_phy_handle_interrupt,

/* Statistics */
.get_sset_count = smsc_get_sset_count,
@@ -436,6 +465,7 @@ static struct phy_driver smsc_phy_driver[] = {
/* IRQ related */
.ack_interrupt = smsc_phy_ack_interrupt,
.config_intr = smsc_phy_config_intr,
+ .handle_interrupt = smsc_phy_handle_interrupt,

/* Statistics */
.get_sset_count = smsc_get_sset_count,
--
2.28.0

2020-11-13 16:58:40

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 08/18] net: phy: lxt: remove the use of .ack_interrupt()

From: Ioana Ciornei <[email protected]>

In preparation of removing the .ack_interrupt() callback, we must replace
its occurrences (aka phy_clear_interrupt), from the 2 places where it is
called from (phy_enable_interrupts and phy_disable_interrupts), with
equivalent functionality.

This means that clearing interrupts now becomes something that the PHY
driver is responsible of doing, before enabling interrupts and after
clearing them. Make this driver follow the new contract.

Cc: Christophe Leroy <[email protected]>
Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/lxt.c | 44 +++++++++++++++++++++++++++++++++----------
1 file changed, 34 insertions(+), 10 deletions(-)

diff --git a/drivers/net/phy/lxt.c b/drivers/net/phy/lxt.c
index 716d9936bc90..0ee23d29c0d4 100644
--- a/drivers/net/phy/lxt.c
+++ b/drivers/net/phy/lxt.c
@@ -78,10 +78,23 @@ static int lxt970_ack_interrupt(struct phy_device *phydev)

static int lxt970_config_intr(struct phy_device *phydev)
{
- if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
- return phy_write(phydev, MII_LXT970_IER, MII_LXT970_IER_IEN);
- else
- return phy_write(phydev, MII_LXT970_IER, 0);
+ int err;
+
+ if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
+ err = lxt970_ack_interrupt(phydev);
+ if (err)
+ return err;
+
+ err = phy_write(phydev, MII_LXT970_IER, MII_LXT970_IER_IEN);
+ } else {
+ err = phy_write(phydev, MII_LXT970_IER, 0);
+ if (err)
+ return err;
+
+ err = lxt970_ack_interrupt(phydev);
+ }
+
+ return err;
}

static irqreturn_t lxt970_handle_interrupt(struct phy_device *phydev)
@@ -129,10 +142,23 @@ static int lxt971_ack_interrupt(struct phy_device *phydev)

static int lxt971_config_intr(struct phy_device *phydev)
{
- if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
- return phy_write(phydev, MII_LXT971_IER, MII_LXT971_IER_IEN);
- else
- return phy_write(phydev, MII_LXT971_IER, 0);
+ int err;
+
+ if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
+ err = lxt971_ack_interrupt(phydev);
+ if (err)
+ return err;
+
+ err = phy_write(phydev, MII_LXT971_IER, MII_LXT971_IER_IEN);
+ } else {
+ err = phy_write(phydev, MII_LXT971_IER, 0);
+ if (err)
+ return err;
+
+ err = lxt971_ack_interrupt(phydev);
+ }
+
+ return err;
}

static irqreturn_t lxt971_handle_interrupt(struct phy_device *phydev)
@@ -285,7 +311,6 @@ static struct phy_driver lxt97x_driver[] = {
.phy_id_mask = 0xfffffff0,
/* PHY_BASIC_FEATURES */
.config_init = lxt970_config_init,
- .ack_interrupt = lxt970_ack_interrupt,
.config_intr = lxt970_config_intr,
.handle_interrupt = lxt970_handle_interrupt,
}, {
@@ -293,7 +318,6 @@ static struct phy_driver lxt97x_driver[] = {
.name = "LXT971",
.phy_id_mask = 0xfffffff0,
/* PHY_BASIC_FEATURES */
- .ack_interrupt = lxt971_ack_interrupt,
.config_intr = lxt971_config_intr,
.handle_interrupt = lxt971_handle_interrupt,
.suspend = genphy_suspend,
--
2.28.0

2020-11-13 16:58:50

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 01/18] net: phy: vitesse: implement generic .handle_interrupt() callback

From: Ioana Ciornei <[email protected]>

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: Kavya Sree Kotagiri <[email protected]>
Cc: Linus Walleij <[email protected]>
Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/vitesse.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)

diff --git a/drivers/net/phy/vitesse.c b/drivers/net/phy/vitesse.c
index bb680352708a..9f6cd6ec9747 100644
--- a/drivers/net/phy/vitesse.c
+++ b/drivers/net/phy/vitesse.c
@@ -40,6 +40,11 @@
#define MII_VSC8244_ISTAT_SPEED 0x4000
#define MII_VSC8244_ISTAT_LINK 0x2000
#define MII_VSC8244_ISTAT_DUPLEX 0x1000
+#define MII_VSC8244_ISTAT_MASK (MII_VSC8244_ISTAT_SPEED | \
+ MII_VSC8244_ISTAT_LINK | \
+ MII_VSC8244_ISTAT_DUPLEX)
+
+#define MII_VSC8221_ISTAT_MASK MII_VSC8244_ISTAT_LINK

/* Vitesse Auxiliary Control/Status Register */
#define MII_VSC8244_AUX_CONSTAT 0x1c
@@ -311,6 +316,31 @@ static int vsc82xx_config_intr(struct phy_device *phydev)
return err;
}

+static irqreturn_t vsc82xx_handle_interrupt(struct phy_device *phydev)
+{
+ int irq_status, irq_mask;
+
+ if (phydev->drv->phy_id == PHY_ID_VSC8244 ||
+ phydev->drv->phy_id == PHY_ID_VSC8572 ||
+ phydev->drv->phy_id == PHY_ID_VSC8601)
+ irq_mask = MII_VSC8244_ISTAT_MASK;
+ else
+ irq_mask = MII_VSC8221_ISTAT_MASK;
+
+ irq_status = phy_read(phydev, MII_VSC8244_ISTAT);
+ if (irq_status < 0) {
+ phy_error(phydev);
+ return IRQ_NONE;
+ }
+
+ if (!(irq_status & irq_mask))
+ return IRQ_NONE;
+
+ phy_trigger_machine(phydev);
+
+ return IRQ_HANDLED;
+}
+
static int vsc8221_config_init(struct phy_device *phydev)
{
int err;
@@ -392,6 +422,7 @@ static struct phy_driver vsc82xx_driver[] = {
.config_aneg = &vsc82x4_config_aneg,
.ack_interrupt = &vsc824x_ack_interrupt,
.config_intr = &vsc82xx_config_intr,
+ .handle_interrupt = &vsc82xx_handle_interrupt,
}, {
.phy_id = PHY_ID_VSC8244,
.name = "Vitesse VSC8244",
@@ -401,6 +432,7 @@ static struct phy_driver vsc82xx_driver[] = {
.config_aneg = &vsc82x4_config_aneg,
.ack_interrupt = &vsc824x_ack_interrupt,
.config_intr = &vsc82xx_config_intr,
+ .handle_interrupt = &vsc82xx_handle_interrupt,
}, {
.phy_id = PHY_ID_VSC8572,
.name = "Vitesse VSC8572",
@@ -410,6 +442,7 @@ static struct phy_driver vsc82xx_driver[] = {
.config_aneg = &vsc82x4_config_aneg,
.ack_interrupt = &vsc824x_ack_interrupt,
.config_intr = &vsc82xx_config_intr,
+ .handle_interrupt = &vsc82xx_handle_interrupt,
}, {
.phy_id = PHY_ID_VSC8601,
.name = "Vitesse VSC8601",
@@ -418,6 +451,7 @@ static struct phy_driver vsc82xx_driver[] = {
.config_init = &vsc8601_config_init,
.ack_interrupt = &vsc824x_ack_interrupt,
.config_intr = &vsc82xx_config_intr,
+ .handle_interrupt = &vsc82xx_handle_interrupt,
}, {
.phy_id = PHY_ID_VSC7385,
.name = "Vitesse VSC7385",
@@ -463,6 +497,7 @@ static struct phy_driver vsc82xx_driver[] = {
.config_aneg = &vsc82x4_config_aneg,
.ack_interrupt = &vsc824x_ack_interrupt,
.config_intr = &vsc82xx_config_intr,
+ .handle_interrupt = &vsc82xx_handle_interrupt,
}, {
/* Vitesse 8221 */
.phy_id = PHY_ID_VSC8221,
@@ -472,6 +507,7 @@ static struct phy_driver vsc82xx_driver[] = {
.config_init = &vsc8221_config_init,
.ack_interrupt = &vsc824x_ack_interrupt,
.config_intr = &vsc82xx_config_intr,
+ .handle_interrupt = &vsc82xx_handle_interrupt,
}, {
/* Vitesse 8211 */
.phy_id = PHY_ID_VSC8211,
@@ -481,6 +517,7 @@ static struct phy_driver vsc82xx_driver[] = {
.config_init = &vsc8221_config_init,
.ack_interrupt = &vsc824x_ack_interrupt,
.config_intr = &vsc82xx_config_intr,
+ .handle_interrupt = &vsc82xx_handle_interrupt,
} };

module_phy_driver(vsc82xx_driver);
--
2.28.0

2020-11-13 16:58:51

by Ioana Ciornei

[permalink] [raw]
Subject: [PATCH RESEND net-next 04/18] net: phy: microchip: remove the use of .ack_interrupt()

From: Ioana Ciornei <[email protected]>

In preparation of removing the .ack_interrupt() callback, we must replace
its occurrences (aka phy_clear_interrupt), from the 2 places where it is
called from (phy_enable_interrupts and phy_disable_interrupts), with
equivalent functionality.

This means that clearing interrupts now becomes something that the PHY
driver is responsible of doing, before enabling interrupts and after
clearing them. Make this driver follow the new contract.

Cc: Nisar Sayed <[email protected]>
Cc: Yuiko Oshino <[email protected]>
Signed-off-by: Ioana Ciornei <[email protected]>
---
drivers/net/phy/microchip.c | 13 +++++--------
drivers/net/phy/microchip_t1.c | 17 +++++++----------
2 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/drivers/net/phy/microchip.c b/drivers/net/phy/microchip.c
index b472a2149f08..9f1f2b6c97d4 100644
--- a/drivers/net/phy/microchip.c
+++ b/drivers/net/phy/microchip.c
@@ -44,14 +44,12 @@ static int lan88xx_phy_config_intr(struct phy_device *phydev)
LAN88XX_INT_MASK_LINK_CHANGE_);
} else {
rc = phy_write(phydev, LAN88XX_INT_MASK, 0);
- }
-
- return rc < 0 ? rc : 0;
-}
+ if (rc)
+ return rc;

-static int lan88xx_phy_ack_interrupt(struct phy_device *phydev)
-{
- int rc = phy_read(phydev, LAN88XX_INT_STS);
+ /* Ack interrupts after they have been disabled */
+ rc = phy_read(phydev, LAN88XX_INT_STS);
+ }

return rc < 0 ? rc : 0;
}
@@ -358,7 +356,6 @@ static struct phy_driver microchip_phy_driver[] = {
.config_init = lan88xx_config_init,
.config_aneg = lan88xx_config_aneg,

- .ack_interrupt = lan88xx_phy_ack_interrupt,
.config_intr = lan88xx_phy_config_intr,
.handle_interrupt = lan88xx_handle_interrupt,

diff --git a/drivers/net/phy/microchip_t1.c b/drivers/net/phy/microchip_t1.c
index 04cda8865deb..4dc00bd5a8d2 100644
--- a/drivers/net/phy/microchip_t1.c
+++ b/drivers/net/phy/microchip_t1.c
@@ -189,16 +189,14 @@ static int lan87xx_phy_config_intr(struct phy_device *phydev)
rc = phy_write(phydev, LAN87XX_INTERRUPT_MASK, 0x7FFF);
rc = phy_read(phydev, LAN87XX_INTERRUPT_SOURCE);
val = LAN87XX_MASK_LINK_UP | LAN87XX_MASK_LINK_DOWN;
- }
-
- rc = phy_write(phydev, LAN87XX_INTERRUPT_MASK, val);
-
- return rc < 0 ? rc : 0;
-}
+ rc = phy_write(phydev, LAN87XX_INTERRUPT_MASK, val);
+ } else {
+ rc = phy_write(phydev, LAN87XX_INTERRUPT_MASK, val);
+ if (rc)
+ return rc;

-static int lan87xx_phy_ack_interrupt(struct phy_device *phydev)
-{
- int rc = phy_read(phydev, LAN87XX_INTERRUPT_SOURCE);
+ rc = phy_read(phydev, LAN87XX_INTERRUPT_SOURCE);
+ }

return rc < 0 ? rc : 0;
}
@@ -238,7 +236,6 @@ static struct phy_driver microchip_t1_phy_driver[] = {

.config_init = lan87xx_config_init,

- .ack_interrupt = lan87xx_phy_ack_interrupt,
.config_intr = lan87xx_phy_config_intr,
.handle_interrupt = lan87xx_handle_interrupt,

--
2.28.0

2020-11-14 06:42:18

by Alexandru Ardelean

[permalink] [raw]
Subject: RE: [PATCH RESEND net-next 17/18] net: phy: adin: implement generic .handle_interrupt() callback



> -----Original Message-----
> From: Ioana Ciornei <[email protected]>
> Sent: Friday, November 13, 2020 6:52 PM
> To: Andrew Lunn <[email protected]>; Heiner Kallweit <[email protected]>;
> Russell King <[email protected]>; Florian Fainelli <[email protected]>;
> Jakub Kicinski <[email protected]>; [email protected]; linux-
> [email protected]
> Cc: Ioana Ciornei <[email protected]>; Ardelean, Alexandru
> <[email protected]>
> Subject: [PATCH RESEND net-next 17/18] net: phy: adin: implement generic
> .handle_interrupt() callback
>
> [External]
>
> From: Ioana Ciornei <[email protected]>
>
> 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.
>

Acked-by: Alexandru Ardelean <[email protected]>

> Cc: Alexandru Ardelean <[email protected]>
> Signed-off-by: Ioana Ciornei <[email protected]>
> ---
> drivers/net/phy/adin.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/drivers/net/phy/adin.c b/drivers/net/phy/adin.c index
> 3727b38addf7..ba24434b867d 100644
> --- a/drivers/net/phy/adin.c
> +++ b/drivers/net/phy/adin.c
> @@ -479,6 +479,24 @@ static int adin_phy_config_intr(struct phy_device
> *phydev)
> ADIN1300_INT_MASK_EN);
> }
>
> +static irqreturn_t adin_phy_handle_interrupt(struct phy_device *phydev)
> +{
> + int irq_status;
> +
> + irq_status = phy_read(phydev, ADIN1300_INT_STATUS_REG);
> + if (irq_status < 0) {
> + phy_error(phydev);
> + return IRQ_NONE;
> + }
> +
> + if (!(irq_status & ADIN1300_INT_LINK_STAT_CHNG_EN))
> + return IRQ_NONE;
> +
> + phy_trigger_machine(phydev);
> +
> + return IRQ_HANDLED;
> +}
> +
> static int adin_cl45_to_adin_reg(struct phy_device *phydev, int devad,
> u16 cl45_regnum)
> {
> @@ -879,6 +897,7 @@ static struct phy_driver adin_driver[] = {
> .set_tunable = adin_set_tunable,
> .ack_interrupt = adin_phy_ack_intr,
> .config_intr = adin_phy_config_intr,
> + .handle_interrupt = adin_phy_handle_interrupt,
> .get_sset_count = adin_get_sset_count,
> .get_strings = adin_get_strings,
> .get_stats = adin_get_stats,
> @@ -902,6 +921,7 @@ static struct phy_driver adin_driver[] = {
> .set_tunable = adin_set_tunable,
> .ack_interrupt = adin_phy_ack_intr,
> .config_intr = adin_phy_config_intr,
> + .handle_interrupt = adin_phy_handle_interrupt,
> .get_sset_count = adin_get_sset_count,
> .get_strings = adin_get_strings,
> .get_stats = adin_get_stats,
> --
> 2.28.0

2020-11-14 06:44:50

by Alexandru Ardelean

[permalink] [raw]
Subject: RE: [PATCH RESEND net-next 18/18] net: phy: adin: remove the use of the .ack_interrupt()



> -----Original Message-----
> From: Ioana Ciornei <[email protected]>
> Sent: Friday, November 13, 2020 6:52 PM
> To: Andrew Lunn <[email protected]>; Heiner Kallweit <[email protected]>;
> Russell King <[email protected]>; Florian Fainelli <[email protected]>;
> Jakub Kicinski <[email protected]>; [email protected]; linux-
> [email protected]
> Cc: Ioana Ciornei <[email protected]>; Ardelean, Alexandru
> <[email protected]>
> Subject: [PATCH RESEND net-next 18/18] net: phy: adin: remove the use of the
> .ack_interrupt()
>
> [External]
>
> From: Ioana Ciornei <[email protected]>
>
> In preparation of removing the .ack_interrupt() callback, we must replace its
> occurrences (aka phy_clear_interrupt), from the 2 places where it is called from
> (phy_enable_interrupts and phy_disable_interrupts), with equivalent
> functionality.
>
> This means that clearing interrupts now becomes something that the PHY driver
> is responsible of doing, before enabling interrupts and after clearing them. Make
> this driver follow the new contract.
>

Acked-by: Alexandru Ardelean <[email protected]>

> Cc: Alexandru Ardelean <[email protected]>
> Signed-off-by: Ioana Ciornei <[email protected]>
> ---
> drivers/net/phy/adin.c | 25 ++++++++++++++++++-------
> 1 file changed, 18 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/net/phy/adin.c b/drivers/net/phy/adin.c index
> ba24434b867d..55a0b91816e2 100644
> --- a/drivers/net/phy/adin.c
> +++ b/drivers/net/phy/adin.c
> @@ -471,12 +471,25 @@ static int adin_phy_ack_intr(struct phy_device
> *phydev)
>
> static int adin_phy_config_intr(struct phy_device *phydev) {
> - if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
> - return phy_set_bits(phydev, ADIN1300_INT_MASK_REG,
> - ADIN1300_INT_MASK_EN);
> + int err;
> +
> + if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
> + err = adin_phy_ack_intr(phydev);
> + if (err)
> + return err;
> +
> + err = phy_set_bits(phydev, ADIN1300_INT_MASK_REG,
> + ADIN1300_INT_MASK_EN);
> + } else {
> + err = phy_clear_bits(phydev, ADIN1300_INT_MASK_REG,
> + ADIN1300_INT_MASK_EN);
> + if (err)
> + return err;
> +
> + err = adin_phy_ack_intr(phydev);
> + }
>
> - return phy_clear_bits(phydev, ADIN1300_INT_MASK_REG,
> - ADIN1300_INT_MASK_EN);
> + return err;
> }
>
> static irqreturn_t adin_phy_handle_interrupt(struct phy_device *phydev) @@ -
> 895,7 +908,6 @@ static struct phy_driver adin_driver[] = {
> .read_status = adin_read_status,
> .get_tunable = adin_get_tunable,
> .set_tunable = adin_set_tunable,
> - .ack_interrupt = adin_phy_ack_intr,
> .config_intr = adin_phy_config_intr,
> .handle_interrupt = adin_phy_handle_interrupt,
> .get_sset_count = adin_get_sset_count,
> @@ -919,7 +931,6 @@ static struct phy_driver adin_driver[] = {
> .read_status = adin_read_status,
> .get_tunable = adin_get_tunable,
> .set_tunable = adin_set_tunable,
> - .ack_interrupt = adin_phy_ack_intr,
> .config_intr = adin_phy_config_intr,
> .handle_interrupt = adin_phy_handle_interrupt,
> .get_sset_count = adin_get_sset_count,
> --
> 2.28.0

2020-11-15 21:39:09

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH RESEND net-next 06/18] net: phy: marvell: remove the use of .ack_interrupt()

On Fri, Nov 13, 2020 at 06:52:14PM +0200, Ioana Ciornei wrote:
> From: Ioana Ciornei <[email protected]>
>
> In preparation of removing the .ack_interrupt() callback, we must replace
> its occurrences (aka phy_clear_interrupt), from the 2 places where it is
> called from (phy_enable_interrupts and phy_disable_interrupts), with
> equivalent functionality.
>
> This means that clearing interrupts now becomes something that the PHY
> driver is responsible of doing, before enabling interrupts and after
> clearing them. Make this driver follow the new contract.
>
> Cc: Maxim Kochetkov <[email protected]>
> Cc: Baruch Siach <[email protected]>
> Cc: Robert Hancock <[email protected]>
> Signed-off-by: Ioana Ciornei <[email protected]>

Hi Ioana

I tested this series on a couple of Marvell Ethernet switches with
integrated PHYs using interrupts. Please feel free to add

Tested-by: Andrew Lunn <[email protected]>

to this and the previous patch.

Andrew

2020-11-17 19:42:42

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH RESEND net-next 00/18] net: phy: add support for shared interrupts (part 2)

Hello:

This series was applied to netdev/net-next.git (refs/heads/master):

On Fri, 13 Nov 2020 18:52:08 +0200 you wrote:
> From: Ioana Ciornei <[email protected]>
>
> This patch set aims to actually add support for shared interrupts in
> phylib and not only for multi-PHY devices. While we are at it,
> streamline the interrupt handling in phylib.
>
> For a bit of context, at the moment, there are multiple phy_driver ops
> that deal with this subject:
>
> [...]

Here is the summary with links:
- [RESEND,net-next,01/18] net: phy: vitesse: implement generic .handle_interrupt() callback
https://git.kernel.org/netdev/net-next/c/b606ad8fa283
- [RESEND,net-next,02/18] net: phy: vitesse: remove the use of .ack_interrupt()
https://git.kernel.org/netdev/net-next/c/e96a0d977464
- [RESEND,net-next,03/18] net: phy: microchip: implement generic .handle_interrupt() callback
https://git.kernel.org/netdev/net-next/c/e01a3feb8f69
- [RESEND,net-next,04/18] net: phy: microchip: remove the use of .ack_interrupt()
https://git.kernel.org/netdev/net-next/c/cf499391982d
- [RESEND,net-next,05/18] net: phy: marvell: implement generic .handle_interrupt() callback
https://git.kernel.org/netdev/net-next/c/a0723b375f93
- [RESEND,net-next,06/18] net: phy: marvell: remove the use of .ack_interrupt()
https://git.kernel.org/netdev/net-next/c/1f6d0f267a14
- [RESEND,net-next,07/18] net: phy: lxt: implement generic .handle_interrupt() callback
https://git.kernel.org/netdev/net-next/c/01c4a00bf347
- [RESEND,net-next,08/18] net: phy: lxt: remove the use of .ack_interrupt()
https://git.kernel.org/netdev/net-next/c/9a12dd6f186c
- [RESEND,net-next,09/18] net: phy: nxp-tja11xx: implement generic .handle_interrupt() callback
https://git.kernel.org/netdev/net-next/c/52b1984a88ac
- [RESEND,net-next,10/18] net: phy: nxp-tja11xx: remove the use of .ack_interrupt()
https://git.kernel.org/netdev/net-next/c/45f52f123851
- [RESEND,net-next,11/18] net: phy: amd: implement generic .handle_interrupt() callback
https://git.kernel.org/netdev/net-next/c/d995a36b7e96
- [RESEND,net-next,12/18] net: phy: amd: remove the use of .ack_interrupt()
https://git.kernel.org/netdev/net-next/c/347917c7e06a
- [RESEND,net-next,13/18] net: phy: smsc: implement generic .handle_interrupt() callback
https://git.kernel.org/netdev/net-next/c/36b25c26e2ca
- [RESEND,net-next,14/18] net: phy: smsc: remove the use of .ack_interrupt()
https://git.kernel.org/netdev/net-next/c/824ef51f0871
- [RESEND,net-next,15/18] net: phy: ste10Xp: implement generic .handle_interrupt() callback
https://git.kernel.org/netdev/net-next/c/80ca9ee741da
- [RESEND,net-next,16/18] net: phy: ste10Xp: remove the use of .ack_interrupt()
https://git.kernel.org/netdev/net-next/c/e1bc534df855
- [RESEND,net-next,17/18] net: phy: adin: implement generic .handle_interrupt() callback
https://git.kernel.org/netdev/net-next/c/66d7439e8360
- [RESEND,net-next,18/18] net: phy: adin: remove the use of the .ack_interrupt()
https://git.kernel.org/netdev/net-next/c/1d8300d3ce9d

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html