From: Andre Werner <andre.werner@systec-electronic.com>
To: andrew@lunn.ch, hkallweit1@gmail.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com
Cc: linux@armlinux.org.uk, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
Andre Werner <andre.werner@systec-electronic.com>
Subject: [PATCH] net: phy: adin1100: Fix nullptr exception for phy interrupts
Date: Thu, 18 Jan 2024 11:43:41 +0100 [thread overview]
Message-ID: <20240118104341.10832-1-andre.werner@systec-electronic.com> (raw)
If using ADIN1100 as an external phy, e.g. in combination with
"smsc95xx", we ran into nullptr exception by creating a link.
In our case the "smsc95xx" does not check for an available interrupt handler
on external phy driver to use poll instead of interrupts if no handler is
available. So we decide to implement a small handler in the phy driver
to support other MACs as well.
I update the driver to add an interrupt handler because libphy
does not check if their is a interrupt handler available either.
There are several interrupts maskable at the phy, but only link change interrupts
are handled by the driver yet.
We tested the combination "smsc95xx" and "adin1100" with Linux Kernel 6.6.9
and Linux Kernel 6.1.0, respectively.
Signed-off-by: Andre Werner <andre.werner@systec-electronic.com>
---
drivers/net/phy/adin1100.c | 58 ++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/drivers/net/phy/adin1100.c b/drivers/net/phy/adin1100.c
index 7619d6185801..ed8a7e6250cf 100644
--- a/drivers/net/phy/adin1100.c
+++ b/drivers/net/phy/adin1100.c
@@ -18,6 +18,12 @@
#define PHY_ID_ADIN1110 0x0283bc91
#define PHY_ID_ADIN2111 0x0283bca1
+#define ADIN_PHY_SUBSYS_IRQ_MASK 0x0021
+#define ADIN_LINK_STAT_CHNG_IRQ_EN BIT(1)
+
+#define ADIN_PHY_SUBSYS_IRQ_STATUS 0x0011
+#define ADIN_LINK_STAT_CHNG BIT(1)
+
#define ADIN_FORCED_MODE 0x8000
#define ADIN_FORCED_MODE_EN BIT(0)
@@ -136,6 +142,56 @@ static int adin_config_aneg(struct phy_device *phydev)
return genphy_c45_config_aneg(phydev);
}
+static int adin_phy_ack_intr(struct phy_device *phydev)
+{
+ /* Clear pending interrupts */
+ int rc = phy_read_mmd(phydev, MDIO_MMD_VEND2, ADIN_PHY_SUBSYS_IRQ_STATUS);
+
+ return rc < 0 ? rc : 0;
+}
+
+static int adin_config_intr(struct phy_device *phydev)
+{
+ int ret, regval;
+
+ ret = adin_phy_ack_intr(phydev);
+
+ if (ret)
+ return ret;
+
+ regval = phy_read_mmd(phydev, MDIO_MMD_VEND2, ADIN_PHY_SUBSYS_IRQ_MASK);
+ if (regval < 0)
+ return regval;
+
+ if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
+ regval |= ADIN_LINK_STAT_CHNG_IRQ_EN;
+ else
+ regval &= ~ADIN_LINK_STAT_CHNG_IRQ_EN;
+
+ ret = phy_write_mmd(phydev, MDIO_MMD_VEND2,
+ ADIN_PHY_SUBSYS_IRQ_MASK,
+ regval);
+ return ret;
+}
+
+static irqreturn_t adin_phy_handle_interrupt(struct phy_device *phydev)
+{
+ int irq_status;
+
+ irq_status = phy_read_mmd(phydev, MDIO_MMD_VEND2, ADIN_PHY_SUBSYS_IRQ_STATUS);
+ if (irq_status < 0) {
+ phy_error(phydev);
+ return IRQ_NONE;
+ }
+
+ if (!(irq_status & ADIN_LINK_STAT_CHNG))
+ return IRQ_NONE;
+
+ phy_trigger_machine(phydev);
+
+ return IRQ_HANDLED;
+}
+
static int adin_set_powerdown_mode(struct phy_device *phydev, bool en)
{
int ret;
@@ -275,6 +331,8 @@ static struct phy_driver adin_driver[] = {
.probe = adin_probe,
.config_aneg = adin_config_aneg,
.read_status = adin_read_status,
+ .config_intr = adin_config_intr,
+ .handle_interrupt = adin_phy_handle_interrupt,
.set_loopback = adin_set_loopback,
.suspend = adin_suspend,
.resume = adin_resume,
--
2.43.0
next reply other threads:[~2024-01-18 10:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-18 10:43 Andre Werner [this message]
2024-01-18 16:53 ` Andrew Lunn
2024-01-18 17:36 ` Heiner Kallweit
2024-01-18 20:09 ` Andrew Lunn
2024-01-18 21:24 ` Heiner Kallweit
2024-01-18 23:34 ` Russell King (Oracle)
2024-01-19 6:30 ` Andre Werner
2024-01-18 17:20 ` Russell King (Oracle)
2024-01-19 3:05 ` Andre Werner
2024-01-19 9:56 ` Russell King (Oracle)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240118104341.10832-1-andre.werner@systec-electronic.com \
--to=andre.werner@systec-electronic.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®