usb: gadget: Add UDC driver for Aeroflex Gaisler GRUSBDC
PATCH v3 1/1 usb: gadget: Add UDC driver for Aeroflex Gaisler GRUSBDC
This adds an UDC driver for GRUSBDC USB Device Controller cores available in the GRLIB VHDL IP core library. The driver only supports DMA mode.
---
Differences since v1:
- Use hexprint for debug printoutes instead of homemade equivalent
- Use the dev_* printk variants over the board
- Get rid of unnecessary casts and includes
- Use USB_STATE_NOTATTACHED instead of USB_STATE_ATTACHED for clarity
- Get rid of commented out VERBOSE_DEBUG definition
- Do not devm-allocate any requests
- Get rid of unnecessary resqueduling of the workqueue handler
- Make sure that gadget setup function is called with interrupts disabled Differences since v2:
- Fixed an error printout
- Got rid of the work queue in favor of threaded interrupts
drivers/usb/gadget/Kconfig | 7 + drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/gr_udc.c | 2240 +++++++++++++++++++++++++++++++++++++++++++ drivers/usb/gadget/gr_udc.h | 220 +++++ 4 files changed, 2468 insertions(+) create mode 100644 drivers/usb/gadget/gr_udc.c create mode 100644 drivers/usb/gadget/gr_udc.h
drivers/usb/gadget/Kconfig +7 -0
@@ -216,6 +216,13 @@ config USB_FOTG210_UDC Say "y" to link the driver statically, or "m" to build a dynamically linked module called "fotg210_udc". +config USB_GR_UDC + tristate "Aeroflex Gaisler GRUSBDC USB Peripheral Controller Driver" + depends on OF && HAS_DMA + help + Select this to support Aeroflex Gaisler GRUSBDC cores from the GRLIB + VHDL IP core library. + config USB_OMAP tristate "OMAP USB Device Controller" depends on ARCH_OMAP1
drivers/usb/gadget/Makefile +1 -0
@@ -35,6 +35,7 @@ mv_udc-y := mv_udc_core.o obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o +obj-$(CONFIG_USB_GR_UDC) += gr_udc.o # USB Functions usb_f_acm-y := f_acm.o
drivers/usb/gadget/gr_udc.c new file +2240 -0
2,240 lines not on this page · raw message
drivers/usb/gadget/gr_udc.h new file +220 -0
220 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Hi,
Quoted 32 lines · Andreas Larsson
drivers/usb/gadget/gr_udc.c new file +32
-0+static void gr_finish_request (struct gr_ep *ep,struct gr_request *req, +int status) +{ +struct gr_udc *dev; + +list_del_init (&req->queue); + +if (likely (req->req.status == -EINPROGRESS )) + req->req.status = status; +else + status = req->req.status; + + dev = ep->dev; +usb_gadget_unmap_request (&dev->gadget, &req->req, ep->is_in); +gr_free_dma_desc_chain (dev, req); + +if (ep->is_in)/* For OUT, actual gets updated bit by bit */ + req->req.actual = req->req.length; + +if (!status) { +if (ep->is_in) +gr_dbgprint_request ("SENT" , ep, req); +else +gr_dbgprint_request ("RECV" , ep, req); + } + +/* Prevent changes to ep->queue during callback */ + ep->callback =1 ; +if (req == dev->ep0reqo && !status) { +if (req->setup) +gr_ep0_setup (dev, req); +else
drivers/usb/gadget/gr_udc.c line 350
Quoted 10 lines
drivers/usb/gadget/gr_udc.c new file +10
-0+dev_err (dev->dev, +"Unexpected non setup packet on ep0in\n" ); + }else if (req->req.complete) { +unsigned long flags; + +/* +* Complete should be called with interrupts disabled according +* to the contract of struct usb_request +*/ +local_irq_save (flags);
sorry but this driver isn't ready for inclusion. local_irq_save() is a pretty good hint that there's something wrong in the driver. Consider the fact that local_irq_save() will disable preemption even when CONFIG_PREEMPT_FULL is enabled and you have a bit a problem.
Also, the way you're using thread IRQs is quite wrong. I can't let that pass and get merged upstream, sorry.
Signature · 1 line
balbi
Quoted 42 lines · Felipe Balbi
Hi,
Quoted 39 lines · Andreas Larsson
drivers/usb/gadget/gr_udc.c new file +39
-0+static void gr_finish_request (struct gr_ep *ep,struct gr_request *req, +int status) +{ +struct gr_udc *dev; + +list_del_init (&req->queue); + +if (likely (req->req.status == -EINPROGRESS )) + req->req.status = status; +else + status = req->req.status; + + dev = ep->dev; +usb_gadget_unmap_request (&dev->gadget, &req->req, ep->is_in); +gr_free_dma_desc_chain (dev, req); + +if (ep->is_in)/* For OUT, actual gets updated bit by bit */ + req->req.actual = req->req.length; + +if (!status) { +if (ep->is_in) +gr_dbgprint_request ("SENT" , ep, req); +else +gr_dbgprint_request ("RECV" , ep, req); + } + +/* Prevent changes to ep->queue during callback */ + ep->callback =1 ; +if (req == dev->ep0reqo && !status) { +if (req->setup) +gr_ep0_setup (dev, req); +else +dev_err (dev->dev, +"Unexpected non setup packet on ep0in\n" ); + }else if (req->req.complete) { +unsigned long flags; + +/* +* Complete should be called with interrupts disabled according
Quoted 8 lines
drivers/usb/gadget/gr_udc.c line 350
Quoted 3 lines
drivers/usb/gadget/gr_udc.c new file +3
-0+* to the contract of struct usb_request +*/ +local_irq_save (flags);sorry but this driver isn't ready for inclusion.
local_irq_save()is a pretty good hint that there's something wrong in the driver. Consider the fact thatlocal_irq_save()will disable preemption even whenCONFIG_PREEMPT_FULLis enabled and you have a bit a problem.
This connection between local_irq_save and CONFIG_PREEMPT_RT_FULL was unknown to me. Sure, I can disable interrupts right at spin lock time.
Quoted 2 lines
Also, the way you're using thread IRQs is quite wrong. I can't let that pass and get merged upstream, sorry.
What is quite wrong? What is it that I need to fix?
Best regards,
Andreas Larsson
Hi,
Quoted 49 lines · Andreas Larsson
Quoted 40 lines · Andreas Larsson
Quoted 39 lines
drivers/usb/gadget/gr_udc.c new file +39
-0+static void gr_finish_request (struct gr_ep *ep,struct gr_request *req, +int status) +{ +struct gr_udc *dev; + +list_del_init (&req->queue); + +if (likely (req->req.status == -EINPROGRESS )) + req->req.status = status; +else + status = req->req.status; + + dev = ep->dev; +usb_gadget_unmap_request (&dev->gadget, &req->req, ep->is_in); +gr_free_dma_desc_chain (dev, req); + +if (ep->is_in)/* For OUT, actual gets updated bit by bit */ + req->req.actual = req->req.length; + +if (!status) { +if (ep->is_in) +gr_dbgprint_request ("SENT" , ep, req); +else +gr_dbgprint_request ("RECV" , ep, req); + } + +/* Prevent changes to ep->queue during callback */ + ep->callback =1 ; +if (req == dev->ep0reqo && !status) { +if (req->setup) +gr_ep0_setup (dev, req); +else +dev_err (dev->dev, +"Unexpected non setup packet on ep0in\n" ); + }else if (req->req.complete) { +unsigned long flags; + +/* +* Complete should be called with interrupts disabled according Quoted 8 lines
drivers/usb/gadget/gr_udc.c line 350
Quoted 3 lines
drivers/usb/gadget/gr_udc.c new file +3
-0+* to the contract of struct usb_request +*/ +local_irq_save (flags);sorry but this driver isn't ready for inclusion.
local_irq_save()is a pretty good hint that there's something wrong in the driver. Consider the fact thatlocal_irq_save()will disable preemption even whenCONFIG_PREEMPT_FULLis enabled and you have a bit a problem.
Quoted 3 lines
This connection between
local_irq_saveandCONFIG_PREEMPT_RT_FULLwas unknown to me. Sure, I can disable interrupts right at spin lock time.
that's better.
Quoted 4 lines
Quoted 2 lines
Also, the way you're using thread IRQs is quite wrong. I can't let that pass and get merged upstream, sorry.
What is quite wrong? What is it that I need to fix?
Ideally the hardirq handler should be usually to actually check if $this_device generated the IRQ, that should involve reading a IRQSTATUS register of some sort.
Sure, check that IRQs are actually enabled, but you also need to read STATUS register before waking the thread up.
Signature · 1 line
balbi
Quoted 52 lines · Felipe Balbi
Hi,
Quoted 49 lines · Andreas Larsson
Quoted 48 lines · Andreas Larsson
Quoted 32 lines
drivers/usb/gadget/gr_udc.c new file +32
-0+static void gr_finish_request (struct gr_ep *ep,struct gr_request *req, +int status) +{ +struct gr_udc *dev; + +list_del_init (&req->queue); + +if (likely (req->req.status == -EINPROGRESS )) + req->req.status = status; +else + status = req->req.status; + + dev = ep->dev; +usb_gadget_unmap_request (&dev->gadget, &req->req, ep->is_in); +gr_free_dma_desc_chain (dev, req); + +if (ep->is_in)/* For OUT, actual gets updated bit by bit */ + req->req.actual = req->req.length; + +if (!status) { +if (ep->is_in) +gr_dbgprint_request ("SENT" , ep, req); +else +gr_dbgprint_request ("RECV" , ep, req); + } + +/* Prevent changes to ep->queue during callback */ + ep->callback =1 ; +if (req == dev->ep0reqo && !status) { +if (req->setup) +gr_ep0_setup (dev, req); +else drivers/usb/gadget/gr_udc.c line 350
Quoted 10 lines
drivers/usb/gadget/gr_udc.c new file +10
-0+dev_err (dev->dev, +"Unexpected non setup packet on ep0in\n" ); + }else if (req->req.complete) { +unsigned long flags; + +/* +* Complete should be called with interrupts disabled according +* to the contract of struct usb_request +*/ +local_irq_save (flags);sorry but this driver isn't ready for inclusion.
local_irq_save()is a pretty good hint that there's something wrong in the driver. Consider the fact thatlocal_irq_save()will disable preemption even whenCONFIG_PREEMPT_FULLis enabled and you have a bit a problem.
Quoted 5 lines
Quoted 3 lines
This connection between
local_irq_saveandCONFIG_PREEMPT_RT_FULLwas unknown to me. Sure, I can disable interrupts right at spin lock time.that's better.
Alright, I'll put this in v4.
Quoted 11 lines
Quoted 4 lines
Quoted 2 lines
Also, the way you're using thread IRQs is quite wrong. I can't let that pass and get merged upstream, sorry.
What is quite wrong? What is it that I need to fix?
Ideally the hardirq handler should be usually to actually check if $this_device generated the IRQ, that should involve reading a IRQSTATUS register of some sort.
Sure, check that IRQs are actually enabled, but you also need to read STATUS register before waking the thread up.
I agree that that would be preferable. Unfortunately, the hardware lacks status register bits that indicates whether interrupts has been generated or not. That is why the only check is if interrupts are disabled, because that is the only sure way to know that the softirq handler does not need to go through everything.
Best regards,
Andreas Larsson
--
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
Hi,
Quoted 9 lines · Andreas Larsson
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
Also, the way you're using thread IRQs is quite wrong. I can't let that pass and get merged upstream, sorry.
What is quite wrong? What is it that I need to fix?
Ideally the hardirq handler should be usually to actually check if $this_device generated the IRQ, that should involve reading a IRQSTATUS register of some sort.
Quoted 8 lines
Quoted 2 lines
Sure, check that IRQs are actually enabled, but you also need to read STATUS register before waking the thread up.
I agree that that would be preferable. Unfortunately, the hardware lacks status register bits that indicates whether interrupts has been generated or not. That is why the only check is if interrupts are disabled, because that is the only sure way to know that the softirq handler does not need to go through everything.
so it seems, fair enough then. Keep it the way it is.
cheers
Signature · 1 line
balbi