usb: gadget: gr_udc: OF and ep.maxpacket_limit improvements and fix of GFP_KERNEL in atomic context
Subsystems (2)
v2 cover usb: gadget: gr_udc: OF and ep.maxpacket_limit improvements and fix of GFP_KERNEL in atomic context
This patchset:
- Adds some OF related improvements suggested by Mark Rutland.
- Adds ep.maxpacket_limit to the debugfs file and adds a check if gr_ep_enable is called with a maxpacket value greater than ep.maxpacket_limit.
- Fixes a bug where GFP_KERNEL was used in atomic context
Andreas Larsson (7):
usb: gadget: gr_udc: Make struct platform_device variable name
clearer and use platform_set/get_drvdata
usb: gadget: gr_udc: Expand devicetree documentation
usb: gadget: gr_udc: Use platform_get_irq instead of
irq_of_parse_and_map
usb: gadget: gr_udc: Use of_property_read_u32_index to access arrays
usb: gadget: gr_udc: Add ep.maxpacket_limit to debugfs information
usb: gadget: gr_udc: Return error code when trying to set
ep.maxpacket > ep.maxpacket_limit
usb: gadget: gr_udc: Use GFP_ATOMIC when allocating under help
spinlock
Documentation/devicetree/bindings/usb/gr-udc.txt | 22 +++++---- drivers/usb/gadget/gr_udc.c | 53 ++++++++++++---------- 2 files changed, 42 insertions(+), 33 deletions(-)
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 1/7 usb: gadget: gr_udc: Make struct platform_device variable name clearer and use platform_set/get_drvdata
Rename struct platform_device pointers from ofdev to pdev for clarity. Suggested by Mark Rutland.
---
Differences since v1: use platform_set/get_drvdata
drivers/usb/gadget/gr_udc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/usb/gadget/gr_udc.c +9 -9
@@ -2065,9 +2065,9 @@ static int gr_udc_init(struct gr_udc *dev)return 0 ; } -static int gr_remove (struct platform_device *ofdev) +static int gr_remove (struct platform_device *pdev) { -struct gr_udc *dev =dev_get_drvdata (&ofdev->dev); +struct gr_udc *dev =platform_get_drvdata (pdev);if (dev->added)usb_del_gadget_udc (&dev->gadget);/* Shuts everything down */
@@ -2077,7 +2077,7 @@ static int gr_remove(struct platform_device *ofdev)gr_dfs_delete (dev);if (dev->desc_pool)dma_pool_destroy (dev->desc_pool); -dev_set_drvdata (&ofdev->dev,NULL ); +platform_set_drvdata (pdev,NULL );gr_free_request (&dev->epi[0 ].ep, &dev->ep0reqi->req);gr_free_request (&dev->epo[0 ].ep, &dev->ep0reqo->req);
@@ -2090,7 +2090,7 @@ static int gr_request_irq(struct gr_udc *dev, int irq) IRQF_SHARED, driver_name, dev); } -static int gr_probe (struct platform_device *ofdev) +static int gr_probe (struct platform_device *pdev) {struct gr_udc *dev;struct resource *res;
@@ -2098,12 +2098,12 @@ static int gr_probe(struct platform_device *ofdev)int retval;u32 status; - dev =devm_kzalloc (&ofdev->dev,sizeof (*dev),GFP_KERNEL ); + dev =devm_kzalloc (&pdev->dev,sizeof (*dev),GFP_KERNEL );if (!dev)return -ENOMEM ; - dev->dev = &ofdev->dev; + dev->dev = &pdev->dev; - res =platform_get_resource (ofdev,IORESOURCE_MEM ,0 ); + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); regs =devm_ioremap_resource (dev->dev, res);if (IS_ERR (regs))return PTR_ERR (regs);
@@ -2132,7 +2132,7 @@ static int gr_probe(struct platform_device *ofdev)spin_lock_init (&dev->lock); dev->regs = regs; -dev_set_drvdata (&ofdev->dev, dev); +platform_set_drvdata (pdev, dev);/* Determine number of endpoints and data interface mode */ status =gr_read32 (&dev->regs->status);
@@ -2204,7 +2204,7 @@ out:spin_unlock (&dev->lock);if (retval) -gr_remove (ofdev); +gr_remove (pdev);return retval; }
Signature · 1 line
1.7.10.4
PATCH v2 2/7 usb: gadget: gr_udc: Expand devicetree documentation
In reply to Andreas LarssonProvide more information on the two different interrupt cases and more information of endpoint buffer sizes. Suggested by Mark Rutland.
---
Differences since v1: none
Documentation/devicetree/bindings/usb/gr-udc.txt | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
Documentation/devicetree/bindings/usb/gr-udc.txt +14 -8
@@ -12,17 +12,23 @@ Required properties: - reg : Address and length of the register set for the device -- interrupts : Interrupt numbers for this device +- interrupts : Interrupt numbers for this device. Either one interrupt number + for all interrupts, or one for status related interrupts, one for IN + endpoint related interrupts and one for OUT endpoint related interrupts. Optional properties: -- epobufsizes : An array of buffer sizes for OUT endpoints. If the property is - not present, or for endpoints outside of the array, 1024 is assumed by - the driver. - -- epibufsizes : An array of buffer sizes for IN endpoints. If the property is - not present, or for endpoints outside of the array, 1024 is assumed by - the driver. +- epobufsizes : Array of buffer sizes for OUT endpoints when they differ + from the default size of 1024. The array is indexed by the OUT endpoint + number. If the property is present it typically contains one entry for + each OUT endpoint of the core. Fewer entries overrides the default sizes + only for as many endpoints as the array contains. + +- epibufsizes : Array of buffer sizes for IN endpoints when they differ + from the default size of 1024. The array is indexed by the IN endpoint + number. If the property is present it typically contains one entry for + each IN endpoint of the core. Fewer entries overrides the default sizes + only for as many endpoints as the array contains. For further information look in the documentation for the GLIB IP core library: http://www.gaisler.com/products/grlib/grip.pdf
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 3/7 usb: gadget: gr_udc: Use platform_get_irq instead of irq_of_parse_and_map
In reply to Andreas LarssonUse platform_get_irq as no mapping needs to be done. No functional difference for SPARC which is the typical environment for the driver though. Suggested by Mark Rutland.
---
Differences since v1: none
drivers/usb/gadget/gr_udc.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/usb/gadget/gr_udc.c +8 -6
@@ -2108,20 +2108,22 @@ static int gr_probe(struct platform_device *pdev)if (IS_ERR (regs))return PTR_ERR (regs); - dev->irq =irq_of_parse_and_map (dev->dev->of_node,0 ); -if (!dev->irq) { + dev->irq =platform_get_irq (pdev,0 ); +if (dev->irq <=0 ) {dev_err (dev->dev,"No irq found\n" );return -ENODEV ; }/* Some core configurations has separate irqs for IN and OUT events */ - dev->irqi =irq_of_parse_and_map (dev->dev->of_node,1 ); -if (dev->irqi) { - dev->irqo =irq_of_parse_and_map (dev->dev->of_node,2 ); -if (!dev->irqo) { + dev->irqi =platform_get_irq (pdev,1 ); +if (dev->irqi >0 ) { + dev->irqo =platform_get_irq (pdev,2 ); +if (dev->irqo <=0 ) {dev_err (dev->dev,"Found irqi but not irqo\n" );return -ENODEV ; } + }else { + dev->irqi =0 ; } dev->gadget.name = driver_name;
Signature · 1 line
1.7.10.4
PATCH v2 4/7 usb: gadget: gr_udc: Use of_property_read_u32_index to access arrays
In reply to Andreas LarssonUse an appropriate accessor function for property arrays to make the code nicer and make the code correct if it would ever run on little endian architectures. Suggested by Mark Rutland.
---
Differences since v1: none
drivers/usb/gadget/gr_udc.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/usb/gadget/gr_udc.c +4 -8
@@ -2020,9 +2020,7 @@ static int gr_udc_init(struct gr_udc *dev)u32 dmactrl_val;int i;int ret =0 ; -u32 *bufsizes;u32 bufsize; -int len;gr_set_address (dev,0 );
@@ -2033,19 +2031,17 @@ static int gr_udc_init(struct gr_udc *dev)INIT_LIST_HEAD (&dev->ep_list);gr_set_ep0state (dev,GR_EP0_DISCONNECT ); - bufsizes = (u32 *)of_get_property (np,"epobufsizes" , &len); - len /=sizeof (u32);for (i =0 ; i < dev->nepo; i++) { - bufsize = (bufsizes && i < len) ? bufsizes[i] :1024 ; +if (of_property_read_u32_index (np,"epobufsizes" , i, &bufsize)) + bufsize =1024 ; ret =gr_ep_init (dev, i,0 , bufsize);if (ret)return ret; } - bufsizes = (u32 *)of_get_property (np,"epibufsizes" , &len); - len /=sizeof (u32);for (i =0 ; i < dev->nepi; i++) { - bufsize = (bufsizes && i < len) ? bufsizes[i] :1024 ; +if (of_property_read_u32_index (np,"epibufsizes" , i, &bufsize)) + bufsize =1024 ; ret =gr_ep_init (dev, i,1 , bufsize);if (ret)return ret;
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 5/7 usb: gadget: gr_udc: Add ep.maxpacket_limit to debugfs information
In reply to Andreas LarssonAdd information on ep.maxpacket_limit for each endpoint in the debugfs information.
---
Differences since v1: none
drivers/usb/gadget/gr_udc.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/gadget/gr_udc.c +1 -0
@@ -143,6 +143,7 @@ static void gr_seq_ep_show(struct seq_file *seq, struct gr_ep *ep)seq_printf (seq," wedged = %d\n" , ep->wedged);seq_printf (seq," callback = %d\n" , ep->callback);seq_printf (seq," maxpacket = %d\n" , ep->ep.maxpacket); +seq_printf (seq," maxpacket_limit = %d\n" , ep->ep.maxpacket_limit);seq_printf (seq," bytes_per_buffer = %d\n" , ep->bytes_per_buffer);if (mode ==1 || mode ==3 ) seq_printf(seq, " nt = %d\n",
Signature · 1 line
1.7.10.4
PATCH v2 6/7 usb: gadget: gr_udc: Return error code when trying to set ep.maxpacket > ep.maxpacket_limit
In reply to Andreas LarssonMake gr_ep_enable fail properly when a call requests a larger ep.maxpacket than ep.maxpacket_limit.
---
Differences since v1: none
drivers/usb/gadget/gr_udc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/gadget/gr_udc.c +4 -0
@@ -1542,6 +1542,10 @@ static int gr_ep_enable(struct usb_ep *_ep, }else if (max ==0 ) {dev_err (dev->dev,"Max payload cannot be set to 0\n" );return -EINVAL ; + }else if (max > ep->ep.maxpacket_limit) { +dev_err (dev->dev,"Requested max payload %d > limit %d\n" , + max, ep->ep.maxpacket_limit); +return -EINVAL ; }spin_lock (&ep->dev->lock);
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 7/7 usb: gadget: gr_udc: Use GFP_ATOMIC when allocating under help spinlock
In reply to Andreas LarssonAs gr_ep_init must be called with dev->lock held, GFP_KERNEL must not be used.
---
New patch but needs patch 1/7 to apply
drivers/usb/gadget/gr_udc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/gr_udc.c +2 -2
@@ -1990,8 +1990,8 @@ static int gr_ep_init(struct gr_udc *dev, int num, int is_in, u32 maxplimit)INIT_LIST_HEAD (&ep->queue);if (num ==0 ) { - _req =gr_alloc_request (&ep->ep,GFP_KERNEL ); - buf =devm_kzalloc (dev->dev,PAGE_SIZE ,GFP_DMA |GFP_KERNEL ); + _req =gr_alloc_request (&ep->ep,GFP_ATOMIC ); + buf =devm_kzalloc (dev->dev,PAGE_SIZE ,GFP_DMA |GFP_ATOMIC );if (!_req || !buf) {/* possible _req freed by gr_probe via gr_remove */ return -ENOMEM ;
Signature · 1 line
1.7.10.4
PATCH v2 7/7 usb: gadget: gr_udc: Use GFP_ATOMIC when allocating under held spinlock
As gr_ep_init must be called with dev->lock held, GFP_KERNEL must not be used.
---
Differences since v1: Fixed typo in commit message
drivers/usb/gadget/gr_udc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/gr_udc.c +2 -2
@@ -1990,8 +1990,8 @@ static int gr_ep_init(struct gr_udc *dev, int num, int is_in, u32 maxplimit)INIT_LIST_HEAD (&ep->queue);if (num ==0 ) { - _req =gr_alloc_request (&ep->ep,GFP_KERNEL ); - buf =devm_kzalloc (dev->dev,PAGE_SIZE ,GFP_DMA |GFP_KERNEL ); + _req =gr_alloc_request (&ep->ep,GFP_ATOMIC ); + buf =devm_kzalloc (dev->dev,PAGE_SIZE ,GFP_DMA |GFP_ATOMIC );if (!_req || !buf) {/* possible _req freed by gr_probe via gr_remove */ return -ENOMEM ;
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 21 lines · Andreas Larsson
This patchset:
- Adds some OF related improvements suggested by Mark Rutland.
- Adds ep.maxpacket_limit to the debugfs file and adds a check ifgr_ep_enableis called with a maxpacket value greater than ep.maxpacket_limit.
- Fixes a bug whereGFP_KERNELwas used in atomic contextAndreas Larsson (7):
usb: gadget:gr_udc: Make structplatform_devicevariable name
clearer and use platform_set/get_drvdata
usb: gadget:gr_udc: Expand devicetree documentation
usb: gadget:gr_udc: Useplatform_get_irqinstead of
irq_of_parse_and_map
usb: gadget:gr_udc: Useof_property_read_u32_indexto access arrays
usb: gadget:gr_udc: Add ep.maxpacket_limit to debugfs information
usb: gadget:gr_udc: Return error code when trying to set
ep.maxpacket > ep.maxpacket_limit
usb: gadget:gr_udc: UseGFP_ATOMICwhen allocating under help
spinlock
Quoted 3 lines
Documentation/devicetree/bindings/usb/gr-udc.txt | 22 +++++---- drivers/usb/gadget/gr_udc.c | 53 ++++++++++++---------- 2 files changed, 42 insertions(+), 33 deletions(-)
Anyone got feedback or reasons this cannot be accepted?
Best regards,
Andreas Larsson
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html