Skip to content

Commit

Permalink
Merge branch 'net-phy-add-support-for-shared-interrupts-part-2'
Browse files Browse the repository at this point in the history
Ioana Ciornei says:

====================
net: phy: add support for shared interrupts (part 2)

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
====================

Link: https://lore.kernel.org/r/20201113165226.561153-1-ciorneiioana@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Nov 17, 2020
2 parents 97f53a0 + 1d8300d commit 0676a4e
Show file tree
Hide file tree
Showing 10 changed files with 405 additions and 122 deletions.
45 changes: 38 additions & 7 deletions drivers/net/phy/adin.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,43 @@ 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 err;
}

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 phy_clear_bits(phydev, ADIN1300_INT_MASK_REG,
ADIN1300_INT_MASK_EN);
return IRQ_HANDLED;
}

static int adin_cl45_to_adin_reg(struct phy_device *phydev, int devad,
Expand Down Expand Up @@ -877,8 +908,8 @@ 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,
.get_strings = adin_get_strings,
.get_stats = adin_get_stats,
Expand All @@ -900,8 +931,8 @@ 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,
.get_strings = adin_get_strings,
.get_stats = adin_get_stats,
Expand Down
37 changes: 34 additions & 3 deletions drivers/net/phy/amd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <hs@denx.de>");
MODULE_LICENSE("GPL");
Expand Down Expand Up @@ -48,22 +52,49 @@ 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;
}

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",
.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,
} };

module_phy_driver(am79c_driver);
Expand Down
94 changes: 84 additions & 10 deletions drivers/net/phy/lxt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

/* ------------------------------------------------------------------------- */
Expand All @@ -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 */
Expand Down Expand Up @@ -75,10 +78,50 @@ 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)
{
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)
Expand All @@ -99,10 +142,41 @@ 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)
{
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;
}

/*
Expand Down Expand Up @@ -237,15 +311,15 @@ 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,
}, {
.phy_id = 0x001378e0,
.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,
.resume = genphy_resume,
}, {
Expand Down
Loading

0 comments on commit 0676a4e

Please sign in to comment.