[PATCH net-next v5 1/9] net: dsa: microchip: Add support for KSZ8463 global irq

Bastien Curutchet (Schneider Electric) posted 9 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH net-next v5 1/9] net: dsa: microchip: Add support for KSZ8463 global irq
Posted by Bastien Curutchet (Schneider Electric) 1 month, 1 week ago
KSZ8463's interrupt scheme differs from the others KSZ swicthes. Its
global interrupt handling is done through an 'enable irq' register
instead of a 'mask irq' one, so the bit logic to enable/disable
interrupt is reversed. Also its interrupts registers are 16-bits
registers and don't have the same address.

Add ksz8463-specific global interrupt setup function that still relies
on the ksz_irq_common_setup().
Add a check on the device type in the irq_chip operations to adjust the
bit logic for KSZ8463

Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: Bastien Curutchet (Schneider Electric) <bastien.curutchet@bootlin.com>
---
 drivers/net/dsa/microchip/ksz_common.c | 40 +++++++++++++++++++++++++++++-----
 drivers/net/dsa/microchip/ksz_common.h |  3 +++
 2 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index c517478cc47677544b6523faee113ece036c9ed9..0102b950e09df7d33c8e429d9b34f51375e0ef73 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -2817,14 +2817,20 @@ static void ksz_irq_mask(struct irq_data *d)
 {
 	struct ksz_irq *kirq = irq_data_get_irq_chip_data(d);
 
-	kirq->masked |= BIT(d->hwirq);
+	if (ksz_is_ksz8463(kirq->dev))
+		kirq->masked &= ~BIT(d->hwirq);
+	else
+		kirq->masked |= BIT(d->hwirq);
 }
 
 static void ksz_irq_unmask(struct irq_data *d)
 {
 	struct ksz_irq *kirq = irq_data_get_irq_chip_data(d);
 
-	kirq->masked &= ~BIT(d->hwirq);
+	if (ksz_is_ksz8463(kirq->dev))
+		kirq->masked |= BIT(d->hwirq);
+	else
+		kirq->masked &= ~BIT(d->hwirq);
 }
 
 static void ksz_irq_bus_lock(struct irq_data *d)
@@ -2840,7 +2846,10 @@ static void ksz_irq_bus_sync_unlock(struct irq_data *d)
 	struct ksz_device *dev = kirq->dev;
 	int ret;
 
-	ret = ksz_write8(dev, kirq->reg_mask, kirq->masked);
+	if (ksz_is_ksz8463(dev))
+		ret = ksz_write16(dev, kirq->reg_mask, kirq->masked);
+	else
+		ret = ksz_write8(dev, kirq->reg_mask, kirq->masked);
 	if (ret)
 		dev_err(dev->dev, "failed to change IRQ mask\n");
 
@@ -2890,14 +2899,14 @@ static irqreturn_t ksz_irq_thread_fn(int irq, void *dev_id)
 	unsigned int nhandled = 0;
 	struct ksz_device *dev;
 	unsigned int sub_irq;
-	u8 data;
+	u16 data;
 	int ret;
 	u8 n;
 
 	dev = kirq->dev;
 
 	/* Read interrupt status register */
-	ret = ksz_read8(dev, kirq->reg_status, &data);
+	ret = ksz_read16(dev, kirq->reg_status, &data);
 	if (ret)
 		goto out;
 
@@ -2939,6 +2948,22 @@ static int ksz_irq_common_setup(struct ksz_device *dev, struct ksz_irq *kirq)
 	return ret;
 }
 
+static int ksz8463_girq_setup(struct dsa_switch *ds)
+{
+	struct ksz_device *dev = ds->priv;
+	struct ksz_irq *girq = &dev->girq;
+
+	girq->nirqs = 15;
+	girq->reg_mask = KSZ8463_REG_IER;
+	girq->reg_status = KSZ8463_REG_ISR;
+	girq->masked = 0;
+	snprintf(girq->name, sizeof(girq->name), "global_irq");
+
+	girq->irq_num = dev->irq;
+
+	return ksz_irq_common_setup(dev, girq);
+}
+
 static int ksz_girq_setup(struct ksz_device *dev)
 {
 	struct ksz_irq *girq = &dev->girq;
@@ -3044,7 +3069,10 @@ static int ksz_setup(struct dsa_switch *ds)
 	p->learning = true;
 
 	if (dev->irq > 0) {
-		ret = ksz_girq_setup(dev);
+		if (ksz_is_ksz8463(dev))
+			ret = ksz8463_girq_setup(ds);
+		else
+			ret = ksz_girq_setup(dev);
 		if (ret)
 			return ret;
 
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 929aff4c55de5254defdc1afb52b224b3898233b..67a488a3b5787f93f9e2a9266ce04f6611b56bf8 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -839,6 +839,9 @@ static inline bool ksz_is_sgmii_port(struct ksz_device *dev, int port)
 #define KSZ87XX_INT_PME_MASK		BIT(4)
 
 /* Interrupt */
+#define KSZ8463_REG_ISR			0x190
+#define KSZ8463_REG_IER			0x192
+
 #define REG_SW_PORT_INT_STATUS__1	0x001B
 #define REG_SW_PORT_INT_MASK__1		0x001F
 

-- 
2.53.0
Re: [PATCH net-next v5 1/9] net: dsa: microchip: Add support for KSZ8463 global irq
Posted by Jakub Kicinski 1 month, 1 week ago
On Thu, 26 Feb 2026 17:41:48 +0100 Bastien Curutchet (Schneider
Electric) wrote:
>  	/* Read interrupt status register */
> -	ret = ksz_read8(dev, kirq->reg_status, &data);
> +	ret = ksz_read16(dev, kirq->reg_status, &data);
>  	if (ret)
>  		goto out;

I think you promised to extend this comment to indicate that the
over-read is safe?

https://lore.kernel.org/netdev/c9cb204b-e079-4f5b-b670-dcce14101390@bootlin.com/

Also could you go thru the series and check for cases where the lines
are unnecessarily long? In netdev we still prefer 80 chars.
Not a hard requirement, of course, sometimes wrapping hurts readability.
But plenty of examples in here of this which could be trivially wrapped:

WARNING: line length of 96 exceeds 80 columns
#166: FILE: drivers/net/dsa/microchip/ksz_ptp.c:1138:
+static int ksz8463_ptp_port_irq_setup(struct ksz_irq *ptpirq, struct ksz_port *port, int hw_irq)

WARNING: line length of 82 exceeds 80 columns
#207: FILE: drivers/net/dsa/microchip/ksz_ptp.c:1179:
+	ptpirq->irq_num = irq_find_mapping(dev->girq.domain, KSZ8463_SRC_PTP_INT);

WARNING: line length of 86 exceeds 80 columns
#218: FILE: drivers/net/dsa/microchip/ksz_ptp.c:1190:
+	ptpirq->domain = irq_domain_create_linear(dev_fwnode(dev->dev), ptpirq->nirqs,

WARNING: line length of 83 exceeds 80 columns
#219: FILE: drivers/net/dsa/microchip/ksz_ptp.c:1191:
+						  &ksz_ptp_irq_domain_ops, ptpirq);

... etc..
-- 
pw-bot: cr
Re: [PATCH net-next v5 1/9] net: dsa: microchip: Add support for KSZ8463 global irq
Posted by Bastien Curutchet 1 month ago
Hi Jakub,

On 2/28/26 11:16 PM, Jakub Kicinski wrote:
> On Thu, 26 Feb 2026 17:41:48 +0100 Bastien Curutchet (Schneider
> Electric) wrote:
>>   	/* Read interrupt status register */
>> -	ret = ksz_read8(dev, kirq->reg_status, &data);
>> +	ret = ksz_read16(dev, kirq->reg_status, &data);
>>   	if (ret)
>>   		goto out;
> 
> I think you promised to extend this comment to indicate that the
> over-read is safe?
> 
> https://lore.kernel.org/netdev/c9cb204b-e079-4f5b-b670-dcce14101390@bootlin.com/
> 

You're right, I forgot about this one, sorry about that.

> Also could you go thru the series and check for cases where the lines
> are unnecessarily long? In netdev we still prefer 80 chars.
> Not a hard requirement, of course, sometimes wrapping hurts readability.
> But plenty of examples in here of this which could be trivially wrapped:
> 
> WARNING: line length of 96 exceeds 80 columns
> #166: FILE: drivers/net/dsa/microchip/ksz_ptp.c:1138:
> +static int ksz8463_ptp_port_irq_setup(struct ksz_irq *ptpirq, struct ksz_port *port, int hw_irq)
> 
> WARNING: line length of 82 exceeds 80 columns
> #207: FILE: drivers/net/dsa/microchip/ksz_ptp.c:1179:
> +	ptpirq->irq_num = irq_find_mapping(dev->girq.domain, KSZ8463_SRC_PTP_INT);
> 
> WARNING: line length of 86 exceeds 80 columns
> #218: FILE: drivers/net/dsa/microchip/ksz_ptp.c:1190:
> +	ptpirq->domain = irq_domain_create_linear(dev_fwnode(dev->dev), ptpirq->nirqs,
> 
> WARNING: line length of 83 exceeds 80 columns
> #219: FILE: drivers/net/dsa/microchip/ksz_ptp.c:1191:
> +						  &ksz_ptp_irq_domain_ops, ptpirq);
> 
> ... etc..

Sure I'll take a look at it.



Best regards,
Bastien