usb: gadget: aspeed: improve vhub port irq handling
Subsystems (2)
PATCH v2 1/1 usb: gadget: aspeed: improve vhub port irq handling
From: Tao Ren <[email protected]>
This patch evaluates vhub ports' irq mask before going through per-port irq handling one by one, which helps to speed up irq handling in case there is no port interrupt.
---
Changes in v2:
- use "for_each_set_bit" to speed up port irq handling.
drivers/usb/gadget/udc/aspeed-vhub/core.c | 11 ++++++++--- drivers/usb/gadget/udc/aspeed-vhub/vhub.h | 8 +++----- 2 files changed, 11 insertions(+), 8 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/core.c +8 -3
@@ -134,11 +134,14 @@ static irqreturn_t ast_vhub_irq(int irq, void *data) }/* Handle device interrupts */ -for (i =0 ; i < vhub->max_ports; i++) { -u32 dev_mask =VHUB_IRQ_DEVICE1 << i; +if (istat & vhub->port_irq_mask) { +int offset =VHUB_IRQ_DEV1_BIT ; +int size =VHUB_IRQ_DEV1_BIT + vhub->max_ports; -if (istat & dev_mask) +for_each_set_bit_from (offset, (unsigned long *)&istat, size) { + i = offset -VHUB_IRQ_DEV1_BIT ;ast_vhub_dev_irq (&vhub->ports[i].dev); + } }/* Handle top-level vHub EP0 interrupts */
@@ -332,6 +335,8 @@ static int ast_vhub_probe(struct platform_device *pdev)spin_lock_init (&vhub->lock); vhub->pdev = pdev; + vhub->port_irq_mask =GENMASK (VHUB_IRQ_DEV1_BIT + vhub->max_ports -1 , +VHUB_IRQ_DEV1_BIT ); res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); vhub->regs =devm_ioremap_resource (&pdev->dev, res);
drivers/usb/gadget/udc/aspeed-vhub/vhub.h +3 -5
@@ -51,14 +51,11 @@#define VHUB_CTRL_UPSTREAM_CONNECT (1 << 0)/* IER & ISR */ +#define VHUB_IRQ_DEV1_BIT 9#define VHUB_IRQ_USB_CMD_DEADLOCK (1 << 18)#define VHUB_IRQ_EP_POOL_NAK (1 << 17)#define VHUB_IRQ_EP_POOL_ACK_STALL (1 << 16) -#define VHUB_IRQ_DEVICE5 (1 << 13) -#define VHUB_IRQ_DEVICE4 (1 << 12) -#define VHUB_IRQ_DEVICE3 (1 << 11) -#define VHUB_IRQ_DEVICE2 (1 << 10) -#define VHUB_IRQ_DEVICE1 (1 << 9) +#define VHUB_IRQ_DEVICE1 (1 << (VHUB_IRQ_DEV1_BIT))#define VHUB_IRQ_BUS_RESUME (1 << 8)#define VHUB_IRQ_BUS_SUSPEND (1 << 7)#define VHUB_IRQ_BUS_RESET (1 << 6)
@@ -402,6 +399,7 @@ struct ast_vhub {/* Per-port info */ struct ast_vhub_port *ports;u32 max_ports; +u32 port_irq_mask;/* Generic EP data structures */ struct ast_vhub_ep *epns;
Signature · 1 line
2.17.1
Quoted 21 lines · rentao.bupt at gmail.com
From: Tao Ren <[email protected]>
This patch evaluates vhub ports' irq mask before going through per-port irq handling one by one, which helps to speed up irq handling in case there is no port interrupt.
Signed-off-by Tao Ren <[email protected]>---
Changes in v2:
- use "for_each_set_bit" to speed up port irq handling.drivers/usb/gadget/udc/aspeed-vhub/core.c | 11 ++++++++--- drivers/usb/gadget/udc/aspeed-vhub/vhub.h | 8 +++----- 2 files changed, 11 insertions(+), 8 deletions(-)drivers/usb/gadget/udc/aspeed-vhub/core.c +0
-0@@ -134,11 +134,14 @@ static irqreturn_t ast_vhub_irq(int irq, void *data) }
drivers/usb/gadget/udc/aspeed-vhub/core.c static irqreturn_t ast_vhub_irq(int irq, void *data) · line 141
Quoted 10 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c +4
-3/* Handle device interrupts */ -for (i =0 ; i < vhub->max_ports; i++) { -u32 dev_mask =VHUB_IRQ_DEVICE1 << i; +if (istat & vhub->port_irq_mask) { +int offset =VHUB_IRQ_DEV1_BIT ; +int size =VHUB_IRQ_DEV1_BIT + vhub->max_ports; -if (istat & dev_mask) +for_each_set_bit_from (offset, (unsigned long *)&istat, size)
That type cast is very bad. It will not work on big endian for example (yes this driver isn't used on big endian today but still).
Please assign istat to an unsigned long (or make it unsigned long to begin with).
Quoted 44 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c +4
-0+ i = offset -VHUB_IRQ_DEV1_BIT ;ast_vhub_dev_irq (&vhub->ports[i].dev); + } }/* Handle top-level vHub EP0 interrupts */ @@ -332,6 +335,8 @@ static int ast_vhub_probe(struct platform_device *pdev)spin_lock_init (&vhub->lock); vhub->pdev = pdev; + vhub->port_irq_mask =GENMASK (VHUB_IRQ_DEV1_BIT + vhub->max_ports -1 , +VHUB_IRQ_DEV1_BIT ); res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); vhub->regs =devm_ioremap_resource (&pdev->dev, res);drivers/usb/gadget/udc/aspeed-vhub/vhub.h +3
-5@@ -51,14 +51,11 @@#define VHUB_CTRL_UPSTREAM_CONNECT (1 << 0)/* IER & ISR */ +#define VHUB_IRQ_DEV1_BIT 9#define VHUB_IRQ_USB_CMD_DEADLOCK (1 << 18)#define VHUB_IRQ_EP_POOL_NAK (1 << 17)#define VHUB_IRQ_EP_POOL_ACK_STALL (1 << 16) -#define VHUB_IRQ_DEVICE5 (1 << 13) -#define VHUB_IRQ_DEVICE4 (1 << 12) -#define VHUB_IRQ_DEVICE3 (1 << 11) -#define VHUB_IRQ_DEVICE2 (1 << 10) -#define VHUB_IRQ_DEVICE1 (1 << 9) +#define VHUB_IRQ_DEVICE1 (1 << (VHUB_IRQ_DEV1_BIT))#define VHUB_IRQ_BUS_RESUME (1 << 8)#define VHUB_IRQ_BUS_SUSPEND (1 << 7)#define VHUB_IRQ_BUS_RESET (1 << 6)@@ -402,6 +399,7 @@ struct ast_vhub {/* Per-port info */ struct ast_vhub_port *ports;u32 max_ports; +u32 port_irq_mask;/* Generic EP data structures */ struct ast_vhub_ep *epns;
Hi Ben,
Quoted 30 lines · Benjamin Herrenschmidt
Quoted 29 lines · rentao.bupt at gmail.com
From: Tao Ren <[email protected]>
This patch evaluates vhub ports' irq mask before going through per-port irq handling one by one, which helps to speed up irq handling in case there is no port interrupt.
Signed-off-by Tao Ren <[email protected]>---
Changes in v2:
- use "for_each_set_bit" to speed up port irq handling.drivers/usb/gadget/udc/aspeed-vhub/core.c | 11 ++++++++--- drivers/usb/gadget/udc/aspeed-vhub/vhub.h | 8 +++----- 2 files changed, 11 insertions(+), 8 deletions(-)drivers/usb/gadget/udc/aspeed-vhub/core.c +3
-2@@ -134,11 +134,14 @@ static irqreturn_t ast_vhub_irq(int irq, void *data) }/* Handle device interrupts */ -for (i =0 ; i < vhub->max_ports; i++) { -u32 dev_mask =VHUB_IRQ_DEVICE1 << i; +if (istat & vhub->port_irq_mask) { +int offset =VHUB_IRQ_DEV1_BIT ; +int size =VHUB_IRQ_DEV1_BIT + vhub->max_ports;
Quoted 8 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c static irqreturn_t ast_vhub_irq(int irq, void *data) · line 141
Quoted 2 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c +1
-1-if (istat & dev_mask) +for_each_set_bit_from (offset, (unsigned long *)&istat, size)That type cast is very bad. It will not work on big endian for example (yes this driver isn't used on big endian today but still).
Please assign istat to an unsigned long (or make it unsigned long to begin with).
Thanks for pointing it out. Will fix it in v3.
Cheers,
Tao