[PATCH net-next v6 2/9] net: dsa: microchip: Decorrelate IRQ domain from port

Bastien Curutchet (Schneider Electric) posted 9 patches 4 weeks, 1 day ago
[PATCH net-next v6 2/9] net: dsa: microchip: Decorrelate IRQ domain from port
Posted by Bastien Curutchet (Schneider Electric) 4 weeks, 1 day ago
KSZ8463 has one register holding interrupt bits from both port 1 and 2.
So it has to use one IRQ domain for both of its ports. This conflicts
with the current initialization procedure that ties one IRQ domain to
each port.

Decorrelate IRQ domain from port so a port can use an IRQ domain not
directly related to itself.

Signed-off-by: Bastien Curutchet (Schneider Electric) <bastien.curutchet@bootlin.com>
---
 drivers/net/dsa/microchip/ksz_ptp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c
index 4a2cc57a628f97bd51fcb11057bc4effda9205dd..64afe92a3479ec87b5afc66e489b92787a0fc715 100644
--- a/drivers/net/dsa/microchip/ksz_ptp.c
+++ b/drivers/net/dsa/microchip/ksz_ptp.c
@@ -1099,18 +1099,18 @@ static void ksz_ptp_msg_irq_free(struct ksz_port *port, u8 n)
 	irq_dispose_mapping(ptpmsg_irq->num);
 }
 
-static int ksz_ptp_msg_irq_setup(struct ksz_port *port, u8 n)
+static int ksz_ptp_msg_irq_setup(struct irq_domain *domain,
+				 struct ksz_port *port, u8 n)
 {
 	u16 ts_reg[] = {REG_PTP_PORT_PDRESP_TS, REG_PTP_PORT_XDELAY_TS,
 			REG_PTP_PORT_SYNC_TS};
 	static const char * const name[] = {"pdresp-msg", "xdreq-msg",
 					    "sync-msg"};
 	const struct ksz_dev_ops *ops = port->ksz_dev->dev_ops;
-	struct ksz_irq *ptpirq = &port->ptpirq;
 	struct ksz_ptp_irq *ptpmsg_irq;
 
 	ptpmsg_irq = &port->ptpmsg_irq[n];
-	ptpmsg_irq->num = irq_create_mapping(ptpirq->domain, n);
+	ptpmsg_irq->num = irq_create_mapping(domain, n);
 	if (!ptpmsg_irq->num)
 		return -EINVAL;
 
@@ -1162,7 +1162,7 @@ int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p)
 		goto out;
 
 	for (irq = 0; irq < ptpirq->nirqs; irq++) {
-		ret = ksz_ptp_msg_irq_setup(port, irq);
+		ret = ksz_ptp_msg_irq_setup(ptpirq->domain, port, irq);
 		if (ret)
 			goto out_ptp_msg;
 	}

-- 
2.53.0
Re: [PATCH net-next v6 2/9] net: dsa: microchip: Decorrelate IRQ domain from port
Posted by Vladimir Oltean 4 weeks ago
On Wed, Mar 04, 2026 at 11:18:53AM +0100, Bastien Curutchet (Schneider Electric) wrote:
> KSZ8463 has one register holding interrupt bits from both port 1 and 2.
> So it has to use one IRQ domain for both of its ports. This conflicts
> with the current initialization procedure that ties one IRQ domain to
> each port.
> 
> Decorrelate IRQ domain from port so a port can use an IRQ domain not
> directly related to itself.
> 
> Signed-off-by: Bastien Curutchet (Schneider Electric) <bastien.curutchet@bootlin.com>
> ---
>  drivers/net/dsa/microchip/ksz_ptp.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c
> index 4a2cc57a628f97bd51fcb11057bc4effda9205dd..64afe92a3479ec87b5afc66e489b92787a0fc715 100644
> --- a/drivers/net/dsa/microchip/ksz_ptp.c
> +++ b/drivers/net/dsa/microchip/ksz_ptp.c
> @@ -1099,18 +1099,18 @@ static void ksz_ptp_msg_irq_free(struct ksz_port *port, u8 n)
>  	irq_dispose_mapping(ptpmsg_irq->num);
>  }
>  
> -static int ksz_ptp_msg_irq_setup(struct ksz_port *port, u8 n)
> +static int ksz_ptp_msg_irq_setup(struct irq_domain *domain,
> +				 struct ksz_port *port, u8 n)
>  {
>  	u16 ts_reg[] = {REG_PTP_PORT_PDRESP_TS, REG_PTP_PORT_XDELAY_TS,
>  			REG_PTP_PORT_SYNC_TS};
>  	static const char * const name[] = {"pdresp-msg", "xdreq-msg",
>  					    "sync-msg"};
>  	const struct ksz_dev_ops *ops = port->ksz_dev->dev_ops;
> -	struct ksz_irq *ptpirq = &port->ptpirq;
>  	struct ksz_ptp_irq *ptpmsg_irq;
>  
>  	ptpmsg_irq = &port->ptpmsg_irq[n];
> -	ptpmsg_irq->num = irq_create_mapping(ptpirq->domain, n);
> +	ptpmsg_irq->num = irq_create_mapping(domain, n);

Looking at this function, I think there's a pre-existing bug.
If request_threaded_irq() later fails, irq_dispose_mapping() needs to be
called, because ksz_ptp_msg_irq_free() only frees the IRQ domains that
were already successfully set up.

>  	if (!ptpmsg_irq->num)
>  		return -EINVAL;
>  
> @@ -1162,7 +1162,7 @@ int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p)
>  		goto out;
>  
>  	for (irq = 0; irq < ptpirq->nirqs; irq++) {
> -		ret = ksz_ptp_msg_irq_setup(port, irq);
> +		ret = ksz_ptp_msg_irq_setup(ptpirq->domain, port, irq);
>  		if (ret)
>  			goto out_ptp_msg;
>  	}
> 
> -- 
> 2.53.0
>
Re: [PATCH net-next v6 2/9] net: dsa: microchip: Decorrelate IRQ domain from port
Posted by Bastien Curutchet 3 weeks, 6 days ago
Hi Vladimir,

On 3/5/26 11:07 AM, Vladimir Oltean wrote:
> On Wed, Mar 04, 2026 at 11:18:53AM +0100, Bastien Curutchet (Schneider Electric) wrote:
>> KSZ8463 has one register holding interrupt bits from both port 1 and 2.
>> So it has to use one IRQ domain for both of its ports. This conflicts
>> with the current initialization procedure that ties one IRQ domain to
>> each port.
>>
>> Decorrelate IRQ domain from port so a port can use an IRQ domain not
>> directly related to itself.
>>
>> Signed-off-by: Bastien Curutchet (Schneider Electric) <bastien.curutchet@bootlin.com>
>> ---
>>   drivers/net/dsa/microchip/ksz_ptp.c | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c
>> index 4a2cc57a628f97bd51fcb11057bc4effda9205dd..64afe92a3479ec87b5afc66e489b92787a0fc715 100644
>> --- a/drivers/net/dsa/microchip/ksz_ptp.c
>> +++ b/drivers/net/dsa/microchip/ksz_ptp.c
>> @@ -1099,18 +1099,18 @@ static void ksz_ptp_msg_irq_free(struct ksz_port *port, u8 n)
>>   	irq_dispose_mapping(ptpmsg_irq->num);
>>   }
>>   
>> -static int ksz_ptp_msg_irq_setup(struct ksz_port *port, u8 n)
>> +static int ksz_ptp_msg_irq_setup(struct irq_domain *domain,
>> +				 struct ksz_port *port, u8 n)
>>   {
>>   	u16 ts_reg[] = {REG_PTP_PORT_PDRESP_TS, REG_PTP_PORT_XDELAY_TS,
>>   			REG_PTP_PORT_SYNC_TS};
>>   	static const char * const name[] = {"pdresp-msg", "xdreq-msg",
>>   					    "sync-msg"};
>>   	const struct ksz_dev_ops *ops = port->ksz_dev->dev_ops;
>> -	struct ksz_irq *ptpirq = &port->ptpirq;
>>   	struct ksz_ptp_irq *ptpmsg_irq;
>>   
>>   	ptpmsg_irq = &port->ptpmsg_irq[n];
>> -	ptpmsg_irq->num = irq_create_mapping(ptpirq->domain, n);
>> +	ptpmsg_irq->num = irq_create_mapping(domain, n);
> 
> Looking at this function, I think there's a pre-existing bug.
> If request_threaded_irq() later fails, irq_dispose_mapping() needs to be
> called, because ksz_ptp_msg_irq_free() only frees the IRQ domains that
> were already successfully set up.
I think you're right, I'll send a fix for this.


Best regards,
Bastien