usb: gadget: bcm63xx UDC driver
PATCH v3 1/1 usb: gadget: bcm63xx UDC driver
Driver for the "USB20D" / "USBD" block on BCM6328, BCM6368, BCM6816, BCM6362, BCM3383, and others.
The hardware block was designed to support networking applications (direct connection of a home router to a PC), and the endpoint configuration is fixed.
--- drivers/usb/gadget/Kconfig | 12 + drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/bcm63xx_udc.c | 2456 +++++++++++++++++++++++++++++++++++++ drivers/usb/gadget/gadget_chips.h | 3 + 4 files changed, 2472 insertions(+) create mode 100644 drivers/usb/gadget/bcm63xx_udc.c
V3 changes:
Fix dynamic linking verbiage in Kconfig help text Abort gracefully if platform data is missing
Change ep0 logic to use a workqueue again
Rename update_* functions to bcm63xx_update_*
Fix handling of soft connect events sent from the wrong state Add delays to prevent EMI warnings on host
drivers/usb/gadget/Kconfig +12 -0
@@ -160,6 +160,18 @@ config USB_ATMEL_USBA USBA is the integrated high-speed USB Device controller on the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel. +config USB_BCM63XX_UDC + tristate "Broadcom BCM63xx Peripheral Controller" + select USB_GADGET_DUALSPEED + depends on BCM63XX + help + Many Broadcom BCM63xx chipsets (such as the BCM6328) have a + high speed USB Device Port with support for four fixed endpoints + (plus endpoint zero). + + Say "y" to link the driver statically, or "m" to build a + dynamically linked module called "bcm63xx_udc". + config USB_FSL_USB2 tristate "Freescale Highspeed USB DR Peripheral Controller" depends on FSL_SOC || ARCH_MXC
drivers/usb/gadget/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_USB_OMAP) += omap_udc.o obj-$(CONFIG_USB_S3C2410) += s3c2410_udc.o obj-$(CONFIG_USB_AT91) += at91_udc.o obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o +obj-$(CONFIG_USB_BCM63XX_UDC) += bcm63xx_udc.o obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o fsl_usb2_udc-y := fsl_udc_core.o fsl_usb2_udc-$(CONFIG_ARCH_MXC) += fsl_mxc_udc.o
drivers/usb/gadget/bcm63xx_udc.c new file +2456 -0
2,456 lines not on this page · raw message
drivers/usb/gadget/gadget_chips.h +3 -0
@@ -28,6 +28,7 @@#define gadget_is_amd5536udc (g) (!strcmp("amd5536udc", (g)->name))#define gadget_is_at91 (g) (!strcmp("at91_udc", (g)->name))#define gadget_is_atmel_usba (g) (!strcmp("atmel_usba_udc", (g)->name)) +#define gadget_is_bcm63xx (g) (!strcmp("bcm63xx_udc", (g)->name))#define gadget_is_ci13xxx_msm (g) (!strcmp("ci13xxx_msm", (g)->name))#define gadget_is_ci13xxx_pci (g) (!strcmp("ci13xxx_pci", (g)->name))#define gadget_is_dummy (g) (!strcmp("dummy_udc", (g)->name))
@@ -121,6 +122,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)return 0x32 ; else if (gadget_is_lpc32xx(gadget)) return 0x33; + else if (gadget_is_bcm63xx(gadget)) + return 0x34;return -ENOENT ; }
Signature · 1 line
1.7.11.1
On Tue, Aug 21, 2012 at 06:22:35PM -0700, Kevin Cernekee wrote:
Just one thing that bit while I was sleeping:
The HW acks SetConfig on its own. Once you notice this, you set ->ep0_req_set_cfg and set state in bcm63xx_ep0_do_idle() to EP0_IN_FAKE_STATUS_PHASE. This is I guess the workaround for mass_storage's hold with DELAYED_STATUS and continues with a zero packet.
Now two questions:
- If a gadget descides not NAK / stall the SetConfig requests. What happens here?
- What happens if the host is faster than the UDC. SetConfig returns in usb-storage with "DELAYED_STATUS". HW Acks this. Could the Host send another request before the gadget queues the ep0 request?
Sebastian
Quoted 5 lines · Sebastian Andrzej Siewior
Just one thing that bit while I was sleeping:
The HW acks SetConfig on its own. Once you notice this, you set ->ep0_req_set_cfg and set state inbcm63xx_ep0_do_idle()toEP0_IN_FAKE_STATUS_PHASE. This is I guess the workaround for mass_storage's hold withDELAYED_STATUSand continues with a zero packet.
EP0_IN_FAKE_STATUS_PHASE is there for the general case of: setup() callback returned >= 0 after a spoofed setup packet, and we're waiting for the gadget driver to send the 0-byte status reply so we can silently discard it and move on.
When bcm63xx_udc is in EP0_IN_FAKE_STATUS_PHASE, it won't issue any more setup() callbacks until the 0-byte reply arrives from the gadget driver. If the host sends a setup request, the callback will be held off until after the (unused) status reply. This keeps the gadget driver from getting confused by out-of-sequence events.
Quoted 3 lines
Now two questions:
- If a gadget descides not NAK / stall the SetConfig requests. What happens here?
If the return value from the setup() callback was negative, bcm63xx_udc should just return to EP0_IDLE as the gadget driver will never send a 0-byte reply.
I have added a new check for this condition, verified that it works as intended, and posted V4.
I am hoping that these invalid SET_CONFIGURATION / SET_INTERFACE requests are uncommon. In what sorts of situations will a host request a configuration that isn't advertised in the device's descriptors? I had trouble just convincing usb_set_interface() / usb_driver_set_configuration() to send such a request because they honor bInterfaceNumber / bConfigurationValue from the descriptors.
Quoted 3 lines
- What happens if the host is faster than the UDC. SetConfig returns in usb-storage with "
DELAYED_STATUS". HW Acks this. Could the Host send another request before the gadget queues the ep0 request?
Could you please clarify if this is the sequence of events you are describing:
1) Host sends a valid SET_CONFIGURATION request to a mass storage gadget
2) Hardware instantly auto-acks the request, completing the status phase and allowing the host to proceed with another ep0 request
3) bcm63xx_udc sends a spoofed SET_CONFIGURATION setup packet to the gadget driver
4) setup() callback returns USB_GADGET_DELAYED_STATUS (0x7fff) but doesn't queue up a reply
5) Host sends another setup packet before usb_composite_setup_continue() is called to send the 0-byte status reply
If so, the next steps should look like:
6) bcm63xx_udc takes a data IRQ, and sets ep0_req_completed
7) bcm63xx_udc stays in EP0_IN_FAKE_STATUS_PHASE until the 0-byte reply is received from usb_composite_setup_continue()
8) usb_composite_setup_continue() eventually sends the 0-byte reply
9) bcm63xx_udc returns to EP0_IDLE and notices that ep0_req_completed is now set
10) bcm63xx_ep0_do_setup() looks at the new request, and performs the setup() callback for the new setup request
11) Data/status phases are handled as usual
Quoted 6 lines · Kevin Cernekee
I am hoping that these invalid
SET_CONFIGURATION/SET_INTERFACErequests are uncommon. In what sorts of situations will a host request a configuration that isn't advertised in the device's descriptors? I had trouble just convincingusb_set_interface()/usb_driver_set_configuration()to send such a request because they honor bInterfaceNumber / bConfigurationValue from the descriptors.
A request doesn't have to be invalid to fail. Valid requests can fail for all sorts of reasons. -ENOMEM is the prototypical example.
Alan Stern
Quoted 5 lines · Kevin Cernekee
When
bcm63xx_udcis inEP0_IN_FAKE_STATUS_PHASE, it won't issue any moresetup()callbacks until the 0-byte reply arrives from the gadget driver. If the host sends a setup request, the callback will be held off until after the (unused) status reply. This keeps the gadget driver from getting confused by out-of-sequence events.
Okay. Then it works as requested :)
Quoted 14 lines
Quoted 3 lines
- What happens if the host is faster than the UDC. SetConfig returns in usb-storage with "
DELAYED_STATUS". HW Acks this. Could the Host send another request before the gadget queues the ep0 request?Could you please clarify if this is the sequence of events you are describing:
1) Host sends a valid
SET_CONFIGURATIONrequest to a mass storage gadget2) Hardware instantly auto-acks the request, completing the status phase and allowing the host to proceed with another ep0 request
3)
bcm63xx_udcsends a spoofedSET_CONFIGURATIONsetup packet to the gadget driver
Quoted 6 lines
4)
setup()callback returnsUSB_GADGET_DELAYED_STATUS(0x7fff) but doesn't queue up a reply5) Host sends another setup packet before
usb_composite_setup_continue()is called to send the 0-byte status reply
exactly
Quoted 7 lines
If so, the next steps should look like:
6)
bcm63xx_udctakes a data IRQ, and setsep0_req_completed7)
bcm63xx_udcstays inEP0_IN_FAKE_STATUS_PHASEuntil the 0-byte reply is received fromusb_composite_setup_continue()
Quoted 6 lines
8)
usb_composite_setup_continue()eventually sends the 0-byte reply9)
bcm63xx_udcreturns toEP0_IDLEand notices thatep0_req_completedis now set10)
bcm63xx_ep0_do_setup()looks at the new request, and performs thesetup()callback for the new setup request
Okay. This sounds good.
Quoted 1 line
11) Data/status phases are handled as usual
Please tell you HW vendor that this auto ack feature is complete non sense unless you already have :)
Sebastian